@mcurcio/patchbay 0.4.0 → 0.6.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.
- package/README.md +8 -7
- package/dist/composites.css +1 -1
- package/dist/composites.js +573 -53
- package/dist/composites.js.map +1 -1
- package/dist/graph.css +1 -0
- package/dist/graph.js +696 -0
- package/dist/graph.js.map +1 -0
- package/dist/hooks.js +433 -28
- package/dist/hooks.js.map +1 -1
- package/dist/primitives.css +1 -1
- package/dist/primitives.js +34 -16
- package/dist/primitives.js.map +1 -1
- package/dist/tokens.css +22 -2
- package/dist/types/composites/command-palette/CommandPalette.d.ts +68 -0
- package/dist/types/composites/command-palette/index.d.ts +4 -0
- package/dist/types/composites/command-palette/rank.d.ts +39 -0
- package/dist/types/composites/index.d.ts +3 -0
- package/dist/types/composites/shortcut-sheet/ShortcutSheet.d.ts +41 -0
- package/dist/types/composites/shortcut-sheet/index.d.ts +2 -0
- package/dist/types/composites/toaster/Toaster.d.ts +38 -0
- package/dist/types/composites/toaster/index.d.ts +2 -0
- package/dist/types/graph/add-at/index.d.ts +2 -0
- package/dist/types/graph/add-at/useAddAt.d.ts +32 -0
- package/dist/types/graph/canvas-tools/CanvasTools.d.ts +40 -0
- package/dist/types/graph/canvas-tools/index.d.ts +2 -0
- package/dist/types/graph/canvas-tools/motion.d.ts +2 -0
- package/dist/types/graph/connect-hints/index.d.ts +4 -0
- package/dist/types/graph/connect-hints/mergeFlowProps.d.ts +10 -0
- package/dist/types/graph/connect-hints/useConnectHints.d.ts +48 -0
- package/dist/types/graph/follow-fit/index.d.ts +2 -0
- package/dist/types/graph/follow-fit/useFollowFit.d.ts +21 -0
- package/dist/types/graph/ghost-wire/GhostWire.d.ts +16 -0
- package/dist/types/graph/ghost-wire/index.d.ts +2 -0
- package/dist/types/graph/index.d.ts +9 -1
- package/dist/types/graph/meter/Meter.d.ts +56 -0
- package/dist/types/graph/meter/index.d.ts +2 -0
- package/dist/types/graph/node-box/NodeBox.d.ts +53 -0
- package/dist/types/graph/node-box/geometry.d.ts +47 -0
- package/dist/types/graph/node-box/index.d.ts +4 -0
- package/dist/types/graph/port-row/PortRow.d.ts +31 -0
- package/dist/types/graph/port-row/index.d.ts +2 -0
- package/dist/types/graph/wire/Wire.d.ts +27 -0
- package/dist/types/graph/wire/index.d.ts +2 -0
- package/dist/types/hooks/index.d.ts +4 -0
- package/dist/types/hooks/use-live-value/index.d.ts +2 -0
- package/dist/types/hooks/use-live-value/useLiveValue.d.ts +9 -0
- package/dist/types/hooks/use-media-breakpoint/index.d.ts +2 -0
- package/dist/types/hooks/use-media-breakpoint/useMediaBreakpoint.d.ts +25 -0
- package/dist/types/hooks/use-shortcuts/index.d.ts +2 -0
- package/dist/types/hooks/use-shortcuts/useShortcuts.d.ts +58 -0
- package/dist/types/hooks/use-toasts/index.d.ts +4 -0
- package/dist/types/hooks/use-toasts/toastQueue.d.ts +76 -0
- package/dist/types/hooks/use-toasts/useToasts.d.ts +31 -0
- package/dist/types/primitives/button/Button.d.ts +4 -1
- package/package.json +2 -2
package/dist/hooks.js
CHANGED
|
@@ -1,13 +1,90 @@
|
|
|
1
|
-
import { useCallback as e, useEffect as t, useLayoutEffect as n,
|
|
1
|
+
import { useCallback as e, useEffect as t, useLayoutEffect as n, useMemo as r, useRef as i, useState as a, useSyncExternalStore as o } from "react";
|
|
2
|
+
// src/hooks/use-live-value/useLiveValue.ts
|
|
3
|
+
function s(e, t, r) {
|
|
4
|
+
let a = i(void 0), o = i({
|
|
5
|
+
read: t,
|
|
6
|
+
onValue: r
|
|
7
|
+
});
|
|
8
|
+
return n(() => {
|
|
9
|
+
o.current = {
|
|
10
|
+
read: t,
|
|
11
|
+
onValue: r
|
|
12
|
+
};
|
|
13
|
+
}), n(() => {
|
|
14
|
+
let t = !0, n = () => {
|
|
15
|
+
if (!t) return;
|
|
16
|
+
let e = o.current.read();
|
|
17
|
+
a.current = e, o.current.onValue?.(e);
|
|
18
|
+
}, r = e(n);
|
|
19
|
+
return n(), () => {
|
|
20
|
+
t = !1, r();
|
|
21
|
+
};
|
|
22
|
+
}, [e]), a;
|
|
23
|
+
}
|
|
24
|
+
// src/hooks/use-media-breakpoint/useMediaBreakpoint.ts
|
|
25
|
+
var c = 760, l = 600, u = {
|
|
26
|
+
narrow: "(max-width: 759.98px)",
|
|
27
|
+
phone: "(max-width: 599.98px)",
|
|
28
|
+
touch: "(hover: none) and (pointer: coarse)"
|
|
29
|
+
};
|
|
30
|
+
function d(e) {
|
|
31
|
+
return e < 600 ? "phone" : e < 760 ? "narrow" : "wide";
|
|
32
|
+
}
|
|
33
|
+
var f = {
|
|
34
|
+
"wide false": {
|
|
35
|
+
width: "wide",
|
|
36
|
+
touch: !1
|
|
37
|
+
},
|
|
38
|
+
"wide true": {
|
|
39
|
+
width: "wide",
|
|
40
|
+
touch: !0
|
|
41
|
+
},
|
|
42
|
+
"narrow false": {
|
|
43
|
+
width: "narrow",
|
|
44
|
+
touch: !1
|
|
45
|
+
},
|
|
46
|
+
"narrow true": {
|
|
47
|
+
width: "narrow",
|
|
48
|
+
touch: !0
|
|
49
|
+
},
|
|
50
|
+
"phone false": {
|
|
51
|
+
width: "phone",
|
|
52
|
+
touch: !1
|
|
53
|
+
},
|
|
54
|
+
"phone true": {
|
|
55
|
+
width: "phone",
|
|
56
|
+
touch: !0
|
|
57
|
+
}
|
|
58
|
+
}, p = f["wide false"];
|
|
59
|
+
function m() {
|
|
60
|
+
return typeof window < "u" && typeof window.matchMedia == "function";
|
|
61
|
+
}
|
|
62
|
+
function h() {
|
|
63
|
+
return m() ? f[`${window.matchMedia(u.phone).matches ? "phone" : window.matchMedia(u.narrow).matches ? "narrow" : "wide"} ${window.matchMedia(u.touch).matches}`] : p;
|
|
64
|
+
}
|
|
65
|
+
function g(e) {
|
|
66
|
+
if (!m()) return () => {};
|
|
67
|
+
let t = Object.values(u).map((e) => window.matchMedia(e));
|
|
68
|
+
for (let n of t) n.addEventListener("change", e);
|
|
69
|
+
return () => {
|
|
70
|
+
for (let n of t) n.removeEventListener("change", e);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function _() {
|
|
74
|
+
return p;
|
|
75
|
+
}
|
|
76
|
+
function v() {
|
|
77
|
+
return o(g, h, _);
|
|
78
|
+
}
|
|
2
79
|
// src/hooks/use-persistent-state/usePersistentState.ts
|
|
3
|
-
function
|
|
80
|
+
function y() {
|
|
4
81
|
try {
|
|
5
82
|
return typeof window > "u" ? null : window.localStorage;
|
|
6
83
|
} catch {
|
|
7
84
|
return null;
|
|
8
85
|
}
|
|
9
86
|
}
|
|
10
|
-
function
|
|
87
|
+
function b(e, t, n) {
|
|
11
88
|
try {
|
|
12
89
|
let r = e?.getItem(t);
|
|
13
90
|
return r == null ? void 0 : n(JSON.parse(r));
|
|
@@ -15,57 +92,385 @@ function a(e, t, n) {
|
|
|
15
92
|
return;
|
|
16
93
|
}
|
|
17
94
|
}
|
|
18
|
-
function
|
|
95
|
+
function x(e, t, n) {
|
|
19
96
|
try {
|
|
20
97
|
e?.setItem(t, JSON.stringify(n));
|
|
21
98
|
} catch {}
|
|
22
99
|
}
|
|
23
|
-
function
|
|
24
|
-
let
|
|
100
|
+
function S(n, r, i, o = {}) {
|
|
101
|
+
let s = o.storage === void 0 ? y() : o.storage, [c, l] = a(() => ({
|
|
25
102
|
key: n,
|
|
26
|
-
value:
|
|
103
|
+
value: b(s, n, i) ?? r,
|
|
27
104
|
set: !1
|
|
28
|
-
})),
|
|
29
|
-
|
|
105
|
+
})), u = c;
|
|
106
|
+
c.key !== n && (u = {
|
|
30
107
|
key: n,
|
|
31
|
-
value:
|
|
108
|
+
value: b(s, n, i) ?? r,
|
|
32
109
|
set: !1
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
}, [
|
|
36
|
-
let
|
|
37
|
-
|
|
110
|
+
}, l(u)), t(() => {
|
|
111
|
+
u.set && x(s, u.key, u.value);
|
|
112
|
+
}, [u]);
|
|
113
|
+
let d = e((e) => {
|
|
114
|
+
l((t) => ({
|
|
38
115
|
key: t.key,
|
|
39
116
|
value: typeof e == "function" ? e(t.value) : e,
|
|
40
117
|
set: !0
|
|
41
118
|
}));
|
|
42
119
|
}, []);
|
|
43
|
-
return [
|
|
120
|
+
return [u.value, d];
|
|
121
|
+
}
|
|
122
|
+
// src/hooks/use-shortcuts/useShortcuts.ts
|
|
123
|
+
function C(e) {
|
|
124
|
+
let t = e ?? (typeof navigator > "u" ? void 0 : navigator);
|
|
125
|
+
if (t === void 0) return "other";
|
|
126
|
+
let n = t.userAgentData?.platform || t.platform || t.userAgent || "";
|
|
127
|
+
return /mac|iphone|ipad|ipod/i.test(n) ? "apple" : "other";
|
|
128
|
+
}
|
|
129
|
+
var w = {
|
|
130
|
+
mod: "mod",
|
|
131
|
+
ctrl: "ctrl",
|
|
132
|
+
control: "ctrl",
|
|
133
|
+
alt: "alt",
|
|
134
|
+
option: "alt",
|
|
135
|
+
shift: "shift",
|
|
136
|
+
meta: "meta",
|
|
137
|
+
cmd: "meta",
|
|
138
|
+
command: "meta"
|
|
139
|
+
}, T = {
|
|
140
|
+
space: " ",
|
|
141
|
+
spacebar: " ",
|
|
142
|
+
esc: "escape",
|
|
143
|
+
plus: "+"
|
|
144
|
+
};
|
|
145
|
+
function E(e) {
|
|
146
|
+
let t = e === " " ? "Space" : e.trim(), n;
|
|
147
|
+
if (t === "+") return {
|
|
148
|
+
key: "+",
|
|
149
|
+
written: "+",
|
|
150
|
+
mod: !1,
|
|
151
|
+
ctrl: !1,
|
|
152
|
+
alt: !1,
|
|
153
|
+
shift: !1,
|
|
154
|
+
meta: !1
|
|
155
|
+
};
|
|
156
|
+
if (t.endsWith("++")) n = "+", t = t.slice(0, -2);
|
|
157
|
+
else {
|
|
158
|
+
let e = t.lastIndexOf("+");
|
|
159
|
+
n = t.slice(e + 1), t = e < 0 ? "" : t.slice(0, e);
|
|
160
|
+
}
|
|
161
|
+
if (n === "") return;
|
|
162
|
+
let r = n.toLowerCase(), i = {
|
|
163
|
+
key: T[r] ?? r,
|
|
164
|
+
written: n,
|
|
165
|
+
mod: !1,
|
|
166
|
+
ctrl: !1,
|
|
167
|
+
alt: !1,
|
|
168
|
+
shift: !1,
|
|
169
|
+
meta: !1
|
|
170
|
+
};
|
|
171
|
+
for (let e of t === "" ? [] : t.split("+")) {
|
|
172
|
+
let t = w[e.trim().toLowerCase()];
|
|
173
|
+
if (t === void 0) return;
|
|
174
|
+
i[t] = !0;
|
|
175
|
+
}
|
|
176
|
+
return i;
|
|
177
|
+
}
|
|
178
|
+
function ee(e) {
|
|
179
|
+
return e.mod || e.ctrl || e.alt || e.meta;
|
|
180
|
+
}
|
|
181
|
+
function D(e) {
|
|
182
|
+
return e.length === 1 && e.toLowerCase() === e.toUpperCase() && e !== " " && !/[0-9]/.test(e);
|
|
183
|
+
}
|
|
184
|
+
function O(e, t, n) {
|
|
185
|
+
let r = t.ctrl || t.mod && n !== "apple", i = t.meta || t.mod && n === "apple";
|
|
186
|
+
if (e.ctrlKey !== r || e.metaKey !== i || e.altKey !== t.alt || (!D(t.key) || t.shift) && e.shiftKey !== t.shift) return !1;
|
|
187
|
+
let a = e.key.toLowerCase();
|
|
188
|
+
return a === t.key ? !0 : /^[a-z]$/.test(a) || !/^[a-z0-9]$/.test(t.key) ? !1 : e.code === (/[a-z]/.test(t.key) ? `Key${t.key.toUpperCase()}` : `Digit${t.key}`);
|
|
189
|
+
}
|
|
190
|
+
function te(e, t, n = C()) {
|
|
191
|
+
return (typeof t == "string" ? [t] : t).some((t) => {
|
|
192
|
+
let r = E(t);
|
|
193
|
+
return r !== void 0 && O(e, r, n);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
var ne = /* @__PURE__ */ new Set([
|
|
197
|
+
"button",
|
|
198
|
+
"checkbox",
|
|
199
|
+
"color",
|
|
200
|
+
"file",
|
|
201
|
+
"hidden",
|
|
202
|
+
"image",
|
|
203
|
+
"radio",
|
|
204
|
+
"range",
|
|
205
|
+
"reset",
|
|
206
|
+
"submit"
|
|
207
|
+
]);
|
|
208
|
+
function k(e) {
|
|
209
|
+
if (e === null || typeof e.closest != "function") return !1;
|
|
210
|
+
let t = e;
|
|
211
|
+
if (t.closest(".nokey") !== null) return !0;
|
|
212
|
+
let n = t.tagName.toLowerCase();
|
|
213
|
+
return n === "input" ? !ne.has((t.type || "text").toLowerCase()) : n === "textarea" || n === "select" || t.isContentEditable ? !0 : t.closest("[contenteditable]:not([contenteditable=\"false\"])") !== null;
|
|
214
|
+
}
|
|
215
|
+
var A = {
|
|
216
|
+
ctrl: "⌃",
|
|
217
|
+
alt: "⌥",
|
|
218
|
+
shift: "⇧",
|
|
219
|
+
meta: "⌘"
|
|
220
|
+
}, j = {
|
|
221
|
+
ctrl: "Ctrl",
|
|
222
|
+
alt: "Alt",
|
|
223
|
+
shift: "Shift",
|
|
224
|
+
meta: "Meta"
|
|
225
|
+
}, M = {
|
|
226
|
+
" ": "Space",
|
|
227
|
+
escape: "Esc",
|
|
228
|
+
arrowup: "↑",
|
|
229
|
+
arrowdown: "↓",
|
|
230
|
+
arrowleft: "←",
|
|
231
|
+
arrowright: "→",
|
|
232
|
+
pageup: "Page Up",
|
|
233
|
+
pagedown: "Page Down",
|
|
234
|
+
home: "Home",
|
|
235
|
+
end: "End"
|
|
236
|
+
}, N = {
|
|
237
|
+
enter: "↩",
|
|
238
|
+
backspace: "⌫",
|
|
239
|
+
delete: "⌦",
|
|
240
|
+
tab: "⇥"
|
|
241
|
+
}, re = {
|
|
242
|
+
enter: "Enter",
|
|
243
|
+
backspace: "Backspace",
|
|
244
|
+
delete: "Delete",
|
|
245
|
+
tab: "Tab"
|
|
246
|
+
}, ie = Object.fromEntries([...[
|
|
247
|
+
"Escape",
|
|
248
|
+
"Enter",
|
|
249
|
+
"Tab",
|
|
250
|
+
"Backspace",
|
|
251
|
+
"Delete",
|
|
252
|
+
"Insert",
|
|
253
|
+
"ArrowUp",
|
|
254
|
+
"ArrowDown",
|
|
255
|
+
"ArrowLeft",
|
|
256
|
+
"ArrowRight",
|
|
257
|
+
"PageUp",
|
|
258
|
+
"PageDown",
|
|
259
|
+
"Home",
|
|
260
|
+
"End"
|
|
261
|
+
].map((e) => [e.toLowerCase(), e]), [" ", "Space"]]);
|
|
262
|
+
function P(e) {
|
|
263
|
+
return ie[e.key] ?? (e.key.length === 1 ? e.key.toUpperCase() : e.written);
|
|
264
|
+
}
|
|
265
|
+
function ae(e, t = {}) {
|
|
266
|
+
let { platform: n = C(), names: r = {} } = t, i = E(e);
|
|
267
|
+
if (i === void 0) return e;
|
|
268
|
+
let a = n === "apple", o = i.ctrl || i.mod && !a, s = i.meta || i.mod && a, c = a ? A : j, l = [];
|
|
269
|
+
o && l.push(r.Ctrl ?? c.ctrl), i.alt && l.push(r.Alt ?? c.alt), i.shift && l.push(r.Shift ?? c.shift), s && l.push(r.Meta ?? c.meta);
|
|
270
|
+
let u = i.key, d = P(i), f = r[d] ?? (a ? N[u] : re[u]) ?? M[u] ?? d;
|
|
271
|
+
return a ? [...l, f].join("") : [...l, f].join("+");
|
|
272
|
+
}
|
|
273
|
+
var oe = {
|
|
274
|
+
" ": "Space",
|
|
275
|
+
"+": "Plus"
|
|
276
|
+
};
|
|
277
|
+
function se(e, t = C()) {
|
|
278
|
+
return (typeof e == "string" ? [e] : e).flatMap((e) => {
|
|
279
|
+
let n = E(e);
|
|
280
|
+
if (n === void 0) return [];
|
|
281
|
+
let r = [];
|
|
282
|
+
return (n.ctrl || n.mod && t !== "apple") && r.push("Control"), n.alt && r.push("Alt"), n.shift && r.push("Shift"), (n.meta || n.mod && t === "apple") && r.push("Meta"), r.push(oe[n.key] ?? P(n)), [r.join("+")];
|
|
283
|
+
}).join(" ");
|
|
284
|
+
}
|
|
285
|
+
function F(e, t, n = C()) {
|
|
286
|
+
if (e.defaultPrevented || e.isComposing || e.key === "Process") return;
|
|
287
|
+
let r = k(e.target);
|
|
288
|
+
for (let i of t) {
|
|
289
|
+
if (i.enabled === !1 || e.repeat && i.repeat !== !0) continue;
|
|
290
|
+
let t = typeof i.keys == "string" ? [i.keys] : i.keys;
|
|
291
|
+
for (let a of t) {
|
|
292
|
+
let t = E(a);
|
|
293
|
+
if (t !== void 0 && O(e, t, n) && (!r || i.inTextFields === !0 && ee(t) && t.key !== "escape")) return i;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
function I(e, n = {}) {
|
|
298
|
+
let { enabled: r = !0, platform: a } = n, o = i({
|
|
299
|
+
bindings: e,
|
|
300
|
+
platform: a
|
|
301
|
+
});
|
|
302
|
+
t(() => {
|
|
303
|
+
o.current = {
|
|
304
|
+
bindings: e,
|
|
305
|
+
platform: a
|
|
306
|
+
};
|
|
307
|
+
}), t(() => {
|
|
308
|
+
if (!r || typeof window > "u") return;
|
|
309
|
+
let e = (e) => {
|
|
310
|
+
let { bindings: t, platform: n } = o.current, r = F(e, t, n ?? C());
|
|
311
|
+
r !== void 0 && (r.preventDefault !== !1 && e.preventDefault(), r.run(e));
|
|
312
|
+
};
|
|
313
|
+
return window.addEventListener("keydown", e), () => {
|
|
314
|
+
window.removeEventListener("keydown", e);
|
|
315
|
+
};
|
|
316
|
+
}, [r]);
|
|
44
317
|
}
|
|
45
318
|
// src/hooks/use-theme/useTheme.ts
|
|
46
|
-
var
|
|
319
|
+
var L = [
|
|
47
320
|
"system",
|
|
48
321
|
"light",
|
|
49
322
|
"dark"
|
|
50
|
-
],
|
|
51
|
-
function
|
|
52
|
-
return
|
|
323
|
+
], R = "system", z = "patchbay/theme";
|
|
324
|
+
function B(e) {
|
|
325
|
+
return L[(L.indexOf(e) + 1) % L.length] ?? "system";
|
|
53
326
|
}
|
|
54
|
-
function
|
|
55
|
-
return
|
|
327
|
+
function V(e) {
|
|
328
|
+
return L.find((t) => t === e);
|
|
56
329
|
}
|
|
57
|
-
function
|
|
330
|
+
function H(e, t) {
|
|
58
331
|
t === "system" ? delete e.dataset.theme : e.dataset.theme = t;
|
|
59
332
|
}
|
|
60
|
-
function
|
|
333
|
+
function U(e = z) {
|
|
61
334
|
return `try{var c=JSON.parse(localStorage.getItem(${JSON.stringify(e).replace(/</g, "\\u003c")}));if(c==="light"||c==="dark")document.documentElement.setAttribute("data-theme",c)}catch(e){}`;
|
|
62
335
|
}
|
|
63
|
-
function
|
|
64
|
-
let { key: t =
|
|
336
|
+
function W(e = {}) {
|
|
337
|
+
let { key: t = z, root: r, storage: i } = e, [a, o] = S(t, R, V, i === void 0 ? {} : { storage: i });
|
|
65
338
|
return n(() => {
|
|
66
|
-
|
|
339
|
+
H(r ?? document.documentElement, a);
|
|
67
340
|
}, [r, a]), [a, o];
|
|
68
341
|
}
|
|
69
|
-
|
|
342
|
+
// src/hooks/use-toasts/toastQueue.ts
|
|
343
|
+
var G = {
|
|
344
|
+
duration: 8e3,
|
|
345
|
+
coalesceWindow: 5e3,
|
|
346
|
+
visible: 4
|
|
347
|
+
}, K = Object.freeze({
|
|
348
|
+
toasts: Object.freeze([]),
|
|
349
|
+
nextId: 1
|
|
350
|
+
});
|
|
351
|
+
function q(e, t, n, r = {}) {
|
|
352
|
+
let i = r.coalesceWindow ?? G.coalesceWindow, { duration: a = r.duration ?? G.duration, ...o } = t, s = t.key === void 0 ? void 0 : e.toasts.find((e) => e.key === t.key && n - e.lastAt < i), c = s === void 0 ? e.toasts : e.toasts.filter((e) => e !== s), l = {
|
|
353
|
+
...o,
|
|
354
|
+
id: s?.id ?? e.nextId,
|
|
355
|
+
count: (s?.count ?? 0) + 1,
|
|
356
|
+
lastAt: n,
|
|
357
|
+
expiresAt: n + a
|
|
358
|
+
};
|
|
359
|
+
return {
|
|
360
|
+
...e,
|
|
361
|
+
toasts: [...c, l],
|
|
362
|
+
nextId: s === void 0 ? e.nextId + 1 : e.nextId
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
function J(e, t) {
|
|
366
|
+
let n = e.toasts.filter((e) => e.id !== t);
|
|
367
|
+
return n.length === e.toasts.length ? e : {
|
|
368
|
+
...e,
|
|
369
|
+
toasts: n
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
function Y(e) {
|
|
373
|
+
return e.toasts.length === 0 ? e : {
|
|
374
|
+
...e,
|
|
375
|
+
toasts: []
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
function X(e, t, n) {
|
|
379
|
+
let { heldSince: r } = e;
|
|
380
|
+
return t ? r === void 0 ? {
|
|
381
|
+
...e,
|
|
382
|
+
heldSince: n
|
|
383
|
+
} : e : r === void 0 ? e : {
|
|
384
|
+
toasts: e.toasts.map((e) => ({
|
|
385
|
+
...e,
|
|
386
|
+
expiresAt: e.expiresAt + Math.max(0, n - Math.max(r, e.lastAt))
|
|
387
|
+
})),
|
|
388
|
+
nextId: e.nextId
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
function Z(e, t) {
|
|
392
|
+
if (e.heldSince !== void 0) return e;
|
|
393
|
+
let n = e.toasts.filter((e) => e.expiresAt > t);
|
|
394
|
+
return n.length === e.toasts.length ? e : {
|
|
395
|
+
...e,
|
|
396
|
+
toasts: n
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
function Q(e) {
|
|
400
|
+
if (e.heldSince !== void 0) return;
|
|
401
|
+
let t;
|
|
402
|
+
for (let { expiresAt: n } of e.toasts) Number.isFinite(n) && (t === void 0 || n < t) && (t = n);
|
|
403
|
+
return t;
|
|
404
|
+
}
|
|
405
|
+
function $(e, t = G.visible) {
|
|
406
|
+
let n = Number.isNaN(t) ? G.visible : Math.max(0, Math.floor(t)), r = Math.max(0, e.toasts.length - n);
|
|
407
|
+
return {
|
|
408
|
+
shown: e.toasts.slice(r),
|
|
409
|
+
more: r
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
// src/hooks/use-toasts/useToasts.ts
|
|
413
|
+
var ce = () => performance.now();
|
|
414
|
+
function le(n = {}) {
|
|
415
|
+
let { duration: o, coalesceWindow: s, visible: c = G.visible, now: l = ce } = n, [u, d] = a(K), f = i(u), p = i({
|
|
416
|
+
duration: o,
|
|
417
|
+
coalesceWindow: s,
|
|
418
|
+
now: l
|
|
419
|
+
});
|
|
420
|
+
t(() => {
|
|
421
|
+
p.current = {
|
|
422
|
+
duration: o,
|
|
423
|
+
coalesceWindow: s,
|
|
424
|
+
now: l
|
|
425
|
+
};
|
|
426
|
+
});
|
|
427
|
+
let m = e((e) => {
|
|
428
|
+
let t = e(f.current, p.current.now());
|
|
429
|
+
return t === f.current || (f.current = t, d(t)), t;
|
|
430
|
+
}, []), h = e((e) => {
|
|
431
|
+
let { duration: t, coalesceWindow: n } = p.current, r = m((r, i) => q(r, e, i, {
|
|
432
|
+
duration: t,
|
|
433
|
+
coalesceWindow: n
|
|
434
|
+
})).toasts.at(-1);
|
|
435
|
+
if (r === void 0) throw Error("useToasts: a toast was shown but not added");
|
|
436
|
+
return r.id;
|
|
437
|
+
}, [m]), g = e((e) => void m((t) => J(t, e)), [m]), _ = e(() => void m(Y), [m]), v = e((e) => void m((t, n) => X(t, e, n)), [m]), y = Q(u), [b, x] = a(0);
|
|
438
|
+
t(() => {
|
|
439
|
+
if (y === void 0) return;
|
|
440
|
+
let e = setTimeout(() => {
|
|
441
|
+
let e = f.current;
|
|
442
|
+
m(Z) === e && x((e) => e + 1);
|
|
443
|
+
}, Math.max(0, Math.ceil(y - p.current.now()) + 1));
|
|
444
|
+
return () => {
|
|
445
|
+
clearTimeout(e);
|
|
446
|
+
};
|
|
447
|
+
}, [
|
|
448
|
+
y,
|
|
449
|
+
b,
|
|
450
|
+
m
|
|
451
|
+
]);
|
|
452
|
+
let S = r(() => {
|
|
453
|
+
let { shown: e, more: t } = $(u, c);
|
|
454
|
+
return {
|
|
455
|
+
toasts: e,
|
|
456
|
+
more: t,
|
|
457
|
+
onDismiss: g,
|
|
458
|
+
onHold: v
|
|
459
|
+
};
|
|
460
|
+
}, [
|
|
461
|
+
u,
|
|
462
|
+
c,
|
|
463
|
+
g,
|
|
464
|
+
v
|
|
465
|
+
]);
|
|
466
|
+
return {
|
|
467
|
+
toasts: u.toasts,
|
|
468
|
+
show: h,
|
|
469
|
+
dismiss: g,
|
|
470
|
+
clear: _,
|
|
471
|
+
toasterProps: S
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
export { q as addToast, H as applyTheme, se as ariaKeyShortcuts, y as browserStorage, V as checkTheme, Y as clearToasts, R as defaultTheme, z as defaultThemeKey, C as detectPlatform, J as dismissToast, K as emptyToastQueue, Z as expireToasts, F as findShortcut, X as holdToasts, k as isTextTarget, ae as keyLabel, te as matchesKeys, u as mediaQueries, c as narrowBelow, B as nextTheme, Q as nextToastExpiry, l as phoneBelow, h as readBreakpoint, b as readKept, p as serverBreakpoint, L as themeChoices, U as themeScript, G as toastDefaults, s as useLiveValue, v as useMediaBreakpoint, S as usePersistentState, I as useShortcuts, W as useTheme, le as useToasts, $ as visibleToasts, d as widthOf, x as writeKept };
|
|
70
475
|
|
|
71
476
|
//# sourceMappingURL=hooks.js.map
|
package/dist/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","names":["browserStorage","readKept","text","storage","key","check","writeKept","value","usePersistentState","options","held","setHeld","useState","initial","current","useEffect","set","useCallback","previous","next","themeChoices","defaultTheme","defaultThemeKey","nextTheme","choice","checkTheme","applyTheme","root","\"theme\"","themeScript","useTheme","setChoice","useLayoutEffect"],"sources":["../src/hooks/use-persistent-state/usePersistentState.ts","../src/hooks/use-theme/useTheme.ts"],"sourcesContent":["// A value kept in the browser's localStorage across reloads. Every read and write is in try, so a private window,\n// blocked storage or a full quota leaves a value that lasts the page's life instead of a failure; every value is\n// checked on read and one that fails the check is ignored, as is text that is not JSON. The key is the app's whole\n// key: an app prefixes its own (with a version number that moves if a value's shape ever changes), so two apps on one\n// origin never share a value. The initial value is never written; only a value the app sets is.\nimport { type Dispatch, type SetStateAction, useCallback, useEffect, useState } from \"react\";\n\n/** What a kept value needs of window.localStorage. */\nexport interface StorageLike {\n getItem(key: string): string | null;\n setItem(key: string, value: string): void;\n removeItem(key: string): void;\n}\n\n/** window.localStorage, or null without a window or where its accessor throws (blocked storage). */\nexport function browserStorage(): StorageLike | null {\n try {\n if (typeof window === \"undefined\") return null;\n return window.localStorage;\n } catch {\n return null;\n }\n}\n\n/**\n * Checks a value read back from storage: returns it (or a value made from it) when it is good, and undefined when it\n * is not, so the initial value is used instead.\n */\nexport type KeptCheck<T> = (value: unknown) => T | undefined;\n\n/** The value kept under `key`, checked; undefined when there is none, storage throws, or it is not good JSON. */\nexport function readKept<T>(storage: StorageLike | null, key: string, check: KeptCheck<T>): T | undefined {\n try {\n const text = storage?.getItem(key);\n if (text === null || text === undefined) return undefined;\n return check(JSON.parse(text) as unknown);\n } catch {\n return undefined;\n }\n}\n\n/** Writes `value` as JSON under `key`; a full or blocked storage is ignored. */\nexport function writeKept(storage: StorageLike | null, key: string, value: unknown): void {\n try {\n storage?.setItem(key, JSON.stringify(value));\n } catch {\n // A full or blocked storage: the page keeps the value for its life.\n }\n}\n\nexport interface PersistentStateOptions {\n /** Where values are kept; the browser's localStorage by default. null keeps nothing. */\n storage?: StorageLike | null;\n}\n\ninterface Held<T> {\n key: string;\n value: T;\n /** Set by the app (so written), not read or initial. */\n set: boolean;\n}\n\n/**\n * React state kept under `key` in localStorage: starts from the kept value when `check` accepts it, else `initial`,\n * and writes every value the app sets. A new `key` reads that key's value afresh.\n */\nexport function usePersistentState<T>(\n key: string,\n initial: T,\n check: KeptCheck<T>,\n options: PersistentStateOptions = {},\n): [T, Dispatch<SetStateAction<T>>] {\n const storage = options.storage === undefined ? browserStorage() : options.storage;\n const [held, setHeld] = useState<Held<T>>(() => ({\n key,\n value: readKept(storage, key, check) ?? initial,\n set: false,\n }));\n\n let current = held;\n if (held.key !== key) {\n // A new key: its own kept value, read during render (React's way to reset state on a prop change).\n current = { key, value: readKept(storage, key, check) ?? initial, set: false };\n setHeld(current);\n }\n\n useEffect(() => {\n if (current.set) writeKept(storage, current.key, current.value);\n // Only a change of what is held writes; a new storage object on each render does not.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [current]);\n\n const set = useCallback<Dispatch<SetStateAction<T>>>((next) => {\n setHeld((previous) => ({\n key: previous.key,\n value: typeof next === \"function\" ? (next as (previous: T) => T)(previous.value) : next,\n set: true,\n }));\n }, []);\n\n return [current.value, set];\n}\n","// The theme: system, light or dark, written to data-theme on <html> (docs/tokens.md#the-theme). System removes the\n// attribute, so tokens.css's prefers-color-scheme rule decides. The choice is kept in localStorage through\n// usePersistentState, under a key the app names (its own prefix), and themeScript gives the app's index.html a tiny\n// inline script that applies the kept choice before the first paint, so a dark page never flashes light.\nimport { useLayoutEffect } from \"react\";\nimport { type PersistentStateOptions, usePersistentState } from \"../use-persistent-state/usePersistentState\";\n\nexport type ThemeChoice = \"system\" | \"light\" | \"dark\";\n\n/** The switch's cycle order. */\nexport const themeChoices: readonly ThemeChoice[] = [\"system\", \"light\", \"dark\"];\n\n/** The page follows the system until the person chooses. */\nexport const defaultTheme: ThemeChoice = \"system\";\n\n/** The key used when the app names none. */\nexport const defaultThemeKey = \"patchbay/theme\";\n\n/** The choice after `choice` in the cycle system, light, dark. */\nexport function nextTheme(choice: ThemeChoice): ThemeChoice {\n const at = themeChoices.indexOf(choice);\n return themeChoices[(at + 1) % themeChoices.length] ?? defaultTheme;\n}\n\n/** A kept value that is one of the three choices, else undefined. */\nexport function checkTheme(value: unknown): ThemeChoice | undefined {\n return themeChoices.find((choice) => choice === value);\n}\n\n/** Writes the choice onto the root it is given (the page's <html>): system removes data-theme. */\nexport function applyTheme(root: { dataset: DOMStringMap }, choice: ThemeChoice): void {\n if (choice === \"system\") delete root.dataset[\"theme\"];\n else root.dataset[\"theme\"] = choice;\n}\n\n/**\n * The body of an inline <script> for the app's index.html, run before the page draws: it applies the choice kept\n * under `key`, as useTheme keeps it, and does nothing when storage is blocked or the value is not light or dark.\n */\nexport function themeScript(key: string = defaultThemeKey): string {\n // JSON names the key as a string literal; \"<\" is escaped so the text cannot close the script element.\n const name = JSON.stringify(key).replace(/</g, \"\\\\u003c\");\n return (\n `try{var c=JSON.parse(localStorage.getItem(${name}));` +\n `if(c===\"light\"||c===\"dark\")document.documentElement.setAttribute(\"data-theme\",c)}catch(e){}`\n );\n}\n\nexport interface UseThemeOptions extends PersistentStateOptions {\n /** The localStorage key the choice is kept under: the app's own, with its prefix. */\n key?: string;\n /** Where data-theme is written; the page's <html> by default. */\n root?: { dataset: DOMStringMap };\n}\n\n/** The theme choice and its setter; the choice is kept, and written to data-theme on <html> before paint. */\nexport function useTheme(options: UseThemeOptions = {}): [ThemeChoice, (choice: ThemeChoice) => void] {\n const { key = defaultThemeKey, root, storage } = options;\n const [choice, setChoice] = usePersistentState<ThemeChoice>(\n key,\n defaultTheme,\n checkTheme,\n storage === undefined ? {} : { storage },\n );\n useLayoutEffect(() => {\n applyTheme(root ?? document.documentElement, choice);\n }, [root, choice]);\n return [choice, setChoice];\n}\n"],"mappings":";;AAeA,SAAgBA,IAAqC;CACnD,IAAI;EAEF,OADI,OAAO,SAAW,MAAoB,OACnC,OAAO;CAChB,QAAQ;EACN,OAAO;CACT;AACF;AASA,SAAgBC,EAAY,GAA6B,GAAa,GAAoC;CACxG,IAAI;EACF,IAAMC,IAAOC,GAAS,QAAQC,CAAG;EAEjC,OADIF,KAAS,OAA4B,SAClCG,EAAM,KAAK,MAAMH,CAAI,CAAY;CAC1C,QAAQ;EACN;CACF;AACF;AAGA,SAAgBI,EAAU,GAA6B,GAAa,GAAsB;CACxF,IAAI;EACF,GAAS,QAAQF,GAAK,KAAK,UAAUG,CAAK,CAAC;CAC7C,QAAQ,CAER;AACF;AAkBA,SAAgBC,EACd,GACA,GACA,GACA,IAAkC,CAAC,GACD;CAClC,IAAML,IAAUM,EAAQ,YAAY,KAAA,IAAYT,EAAe,IAAIS,EAAQ,SACrE,CAACC,GAAMC,KAAWC,SAAyB;EAC/C;EACA,OAAOX,EAASE,GAASC,GAAKC,CAAK,KAAKQ;EAC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Q,SAAS,iBAAiBH,CAAM;CACrD,GAAG,CAACG,GAAMH,CAAM,CAAC,GACV,CAACA,GAAQO,CAAS;AAC3B"}
|
|
1
|
+
{"version":3,"file":"hooks.js","names":["useLiveValue","value","useRef","latest","useLayoutEffect","live","take","next","unsubscribe","subscribe","narrowBelow","phoneBelow","mediaQueries","widthOf","px","answers","serverBreakpoint","canQuery","readBreakpoint","lists","query","list","onChange","getServerSnapshot","useMediaBreakpoint","useSyncExternalStore","browserStorage","readKept","text","storage","key","check","writeKept","usePersistentState","options","held","setHeld","useState","initial","current","useEffect","set","useCallback","previous","detectPlatform","nav","given","name","modifierNames","keyAliases","parseKeys","rest","keys","at","lower","parsed","part","isChord","isShiftedCharacter","matchesParsed","wantCtrl","platform","wantMeta","event","pressed","matchesKeys","one","notTextInputs","isTextTarget","target","element","tag","appleModifiers","otherModifiers","sharedKeys","appleKeys","otherKeys","canonicalNames","canonicalName","keyLabel","apple","ctrl","meta","words","modifiers","names","\"Ctrl\"","\"Alt\"","\"Shift\"","\"Meta\"","lookup","canonical","named","ariaKeys","ariaKeyShortcuts","parts","findShortcut","inText","binding","bindings","useShortcuts","enabled","onKeyDown","table","chosen","themeChoices","defaultTheme","defaultThemeKey","nextTheme","choice","checkTheme","applyTheme","root","\"theme\"","themeScript","useTheme","setChoice","toastDefaults","emptyToastQueue","addToast","window","shown","input","same","queue","toast","now","duration","dismissToast","toasts","id","clearToasts","holdToasts","heldSince","expireToasts","nextToastExpiry","soonest","expiresAt","visibleToasts","cap","visible","more","performanceNow","useToasts","setQueue","update","step","show","forEach","added","dismiss","clear","hold","rearm","setRearm","timer","before","count","toasterProps","useMemo"],"sources":["../src/hooks/use-live-value/useLiveValue.ts","../src/hooks/use-media-breakpoint/useMediaBreakpoint.ts","../src/hooks/use-persistent-state/usePersistentState.ts","../src/hooks/use-shortcuts/useShortcuts.ts","../src/hooks/use-theme/useTheme.ts","../src/hooks/use-toasts/toastQueue.ts","../src/hooks/use-toasts/useToasts.ts"],"sourcesContent":["// A hot value kept outside React state: something that changes many times a second (a level, a rate) is read through\n// a subscription and handed to a callback that paints it through refs, so the component never re-renders for it\n// (docs/components.md#uselivevalue).\nimport { type RefObject, useLayoutEffect, useRef } from \"react\";\n\n/** Adds a listener, called whenever a new value is ready to read; returns what removes it. */\nexport type LiveSubscribe = (listener: () => void) => () => void;\n\n/**\n * Subscribes to a hot value while the component is mounted, without React state. On subscribing, and on every call\n * of the listener, it reads the value, keeps it in the returned ref and passes it to `onValue` (the paint). `read`\n * and `onValue` may change every render; a new `subscribe` subscribes afresh, so pass a stable one.\n */\nexport function useLiveValue<T>(\n subscribe: LiveSubscribe,\n read: () => T,\n onValue?: (value: T) => void,\n): RefObject<T | undefined> {\n const value = useRef<T | undefined>(undefined);\n const latest = useRef({ read, onValue });\n // A layout effect, so a value that arrives before the browser paints reads through the latest callbacks.\n useLayoutEffect(() => {\n latest.current = { read, onValue };\n });\n useLayoutEffect(() => {\n let live = true;\n const take = () => {\n if (!live) return;\n const next = latest.current.read();\n value.current = next;\n latest.current.onValue?.(next);\n };\n const unsubscribe = subscribe(take);\n // What changed between the render and the subscription is read now, so the first paint shows it.\n take();\n return () => {\n live = false;\n unsubscribe();\n };\n }, [subscribe]);\n return value;\n}\n","// The shell's three widths and whether the screen is touch (docs/components.md#usemediabreakpoint): wide from 760 px,\n// narrow below 760 px, phone below 600 px, and touch where the main pointer is coarse and cannot hover, the same\n// query the components' stylesheets use for their touch sizes. It reads the media queries through\n// useSyncExternalStore, so it updates as the window resizes and answers \"wide\", not touch, with no window (on a\n// server, or before hydration).\nimport { useSyncExternalStore } from \"react\";\n\n/** The window's width class: wide, narrow (below 760 px) or phone (below 600 px). */\nexport type MediaWidth = \"wide\" | \"narrow\" | \"phone\";\n\nexport type MediaBreakpoint = {\n width: MediaWidth;\n /** The main pointer is coarse and cannot hover: targets grow to their touch sizes. */\n touch: boolean;\n};\n\n/** Narrow below this many CSS px. */\nexport const narrowBelow = 760;\n/** Phone below this many CSS px. */\nexport const phoneBelow = 600;\n\n/** The media queries the hook reads, for an app's own stylesheet or matchMedia. */\nexport const mediaQueries = {\n narrow: `(max-width: ${narrowBelow - 0.02}px)`,\n phone: `(max-width: ${phoneBelow - 0.02}px)`,\n touch: \"(hover: none) and (pointer: coarse)\",\n} as const;\n\n/** The width class of a window `px` CSS px wide. */\nexport function widthOf(px: number): MediaWidth {\n if (px < phoneBelow) return \"phone\";\n if (px < narrowBelow) return \"narrow\";\n return \"wide\";\n}\n\n// One object per answer, so a snapshot that has not changed is the same object (useSyncExternalStore's rule).\nconst answers: Record<`${MediaWidth} ${boolean}`, MediaBreakpoint> = {\n \"wide false\": { width: \"wide\", touch: false },\n \"wide true\": { width: \"wide\", touch: true },\n \"narrow false\": { width: \"narrow\", touch: false },\n \"narrow true\": { width: \"narrow\", touch: true },\n \"phone false\": { width: \"phone\", touch: false },\n \"phone true\": { width: \"phone\", touch: true },\n};\n\n/** The answer with no window to ask. */\nexport const serverBreakpoint: MediaBreakpoint = answers[\"wide false\"];\n\nfunction canQuery(): boolean {\n return typeof window !== \"undefined\" && typeof window.matchMedia === \"function\";\n}\n\n/** The answer now, from the window's media queries. */\nexport function readBreakpoint(): MediaBreakpoint {\n if (!canQuery()) return serverBreakpoint;\n const width: MediaWidth = window.matchMedia(mediaQueries.phone).matches\n ? \"phone\"\n : window.matchMedia(mediaQueries.narrow).matches\n ? \"narrow\"\n : \"wide\";\n return answers[`${width} ${window.matchMedia(mediaQueries.touch).matches}`];\n}\n\nfunction subscribe(onChange: () => void): () => void {\n if (!canQuery()) return () => {};\n const lists = Object.values(mediaQueries).map((query) => window.matchMedia(query));\n for (const list of lists) list.addEventListener(\"change\", onChange);\n return () => {\n for (const list of lists) list.removeEventListener(\"change\", onChange);\n };\n}\n\nfunction getServerSnapshot(): MediaBreakpoint {\n return serverBreakpoint;\n}\n\n/** The window's width class and touch flag, kept current as either changes. */\nexport function useMediaBreakpoint(): MediaBreakpoint {\n return useSyncExternalStore(subscribe, readBreakpoint, getServerSnapshot);\n}\n","// A value kept in the browser's localStorage across reloads. Every read and write is in try, so a private window,\n// blocked storage or a full quota leaves a value that lasts the page's life instead of a failure; every value is\n// checked on read and one that fails the check is ignored, as is text that is not JSON. The key is the app's whole\n// key: an app prefixes its own (with a version number that moves if a value's shape ever changes), so two apps on one\n// origin never share a value. The initial value is never written; only a value the app sets is.\nimport { type Dispatch, type SetStateAction, useCallback, useEffect, useState } from \"react\";\n\n/** What a kept value needs of window.localStorage. */\nexport interface StorageLike {\n getItem(key: string): string | null;\n setItem(key: string, value: string): void;\n removeItem(key: string): void;\n}\n\n/** window.localStorage, or null without a window or where its accessor throws (blocked storage). */\nexport function browserStorage(): StorageLike | null {\n try {\n if (typeof window === \"undefined\") return null;\n return window.localStorage;\n } catch {\n return null;\n }\n}\n\n/**\n * Checks a value read back from storage: returns it (or a value made from it) when it is good, and undefined when it\n * is not, so the initial value is used instead.\n */\nexport type KeptCheck<T> = (value: unknown) => T | undefined;\n\n/** The value kept under `key`, checked; undefined when there is none, storage throws, or it is not good JSON. */\nexport function readKept<T>(storage: StorageLike | null, key: string, check: KeptCheck<T>): T | undefined {\n try {\n const text = storage?.getItem(key);\n if (text === null || text === undefined) return undefined;\n return check(JSON.parse(text) as unknown);\n } catch {\n return undefined;\n }\n}\n\n/** Writes `value` as JSON under `key`; a full or blocked storage is ignored. */\nexport function writeKept(storage: StorageLike | null, key: string, value: unknown): void {\n try {\n storage?.setItem(key, JSON.stringify(value));\n } catch {\n // A full or blocked storage: the page keeps the value for its life.\n }\n}\n\nexport interface PersistentStateOptions {\n /** Where values are kept; the browser's localStorage by default. null keeps nothing. */\n storage?: StorageLike | null;\n}\n\ninterface Held<T> {\n key: string;\n value: T;\n /** Set by the app (so written), not read or initial. */\n set: boolean;\n}\n\n/**\n * React state kept under `key` in localStorage: starts from the kept value when `check` accepts it, else `initial`,\n * and writes every value the app sets. A new `key` reads that key's value afresh.\n */\nexport function usePersistentState<T>(\n key: string,\n initial: T,\n check: KeptCheck<T>,\n options: PersistentStateOptions = {},\n): [T, Dispatch<SetStateAction<T>>] {\n const storage = options.storage === undefined ? browserStorage() : options.storage;\n const [held, setHeld] = useState<Held<T>>(() => ({\n key,\n value: readKept(storage, key, check) ?? initial,\n set: false,\n }));\n\n let current = held;\n if (held.key !== key) {\n // A new key: its own kept value, read during render (React's way to reset state on a prop change).\n current = { key, value: readKept(storage, key, check) ?? initial, set: false };\n setHeld(current);\n }\n\n useEffect(() => {\n if (current.set) writeKept(storage, current.key, current.value);\n // Only a change of what is held writes; a new storage object on each render does not.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [current]);\n\n const set = useCallback<Dispatch<SetStateAction<T>>>((next) => {\n setHeld((previous) => ({\n key: previous.key,\n value: typeof next === \"function\" ? (next as (previous: T) => T)(previous.value) : next,\n set: true,\n }));\n }, []);\n\n return [current.value, set];\n}\n","// Key bindings for a whole page (docs/components.md#useshortcuts): a table of bindings, each a key string such as\n// \"Mod+K\" (Cmd on Apple platforms, Ctrl elsewhere) and what it runs, read by one window listener. Single keys and\n// Escape never act while the person types in a text field; a chord (a key with Mod, Ctrl, Alt or Meta) acts there\n// only when its binding opts in. Elements inside React Flow's `nokey` class count as text fields, as React Flow\n// counts them, so the canvas's Delete and Backspace and the app's never both act on one press.\nimport { useEffect, useRef } from \"react\";\n\n/** Apple platforms use Cmd for Mod and draw modifiers as symbols; every other platform uses Ctrl. */\nexport type Platform = \"apple\" | \"other\";\n\nexport type Shortcut = {\n /**\n * The key, or several keys that do the same: modifiers then the key, joined by \"+\" (\"Mod+K\", \"Shift+?\",\n * \"Delete\", \"Mod+Shift+Z\"). Modifiers are Mod, Ctrl, Alt, Shift and Meta (any case); the key is a\n * KeyboardEvent key name (\"Escape\", \"ArrowUp\", \"Space\") or the character it types. A string naming a\n * modifier it does not know never matches.\n */\n keys: string | readonly string[];\n /** What the binding does; called with the keydown event. */\n run: (event: KeyboardEvent) => void;\n /** Lets a chord act while focus is in a text field. Single keys and Escape never do, whatever this says. */\n inTextFields?: boolean;\n /** False turns the binding off without removing it from the table. */\n enabled?: boolean;\n /** Acts on the key's auto-repeat too; by default only the first press of a held key acts. */\n repeat?: boolean;\n /** False leaves the browser's own action for the key in place; by default a matched press prevents it. */\n preventDefault?: boolean;\n};\n\nexport type UseShortcutsOptions = {\n /** False turns every binding off (while a dialog the bindings must not reach is open, say). */\n enabled?: boolean;\n /** Overrides the platform read from the browser. */\n platform?: Platform;\n};\n\n/** The platform the page runs on, from the browser; \"other\" without one. */\nexport function detectPlatform(given?: Navigator): Platform {\n const nav = given ?? (typeof navigator === \"undefined\" ? undefined : navigator);\n if (nav === undefined) return \"other\";\n const data = (nav as Navigator & { userAgentData?: { platform?: string } }).userAgentData;\n const name = data?.platform || nav.platform || nav.userAgent || \"\";\n return /mac|iphone|ipad|ipod/i.test(name) ? \"apple\" : \"other\";\n}\n\ntype Parsed = {\n /** Lower case, aliases resolved: what a keydown's key is compared with. */\n key: string;\n /** The key as the string wrote it, for a label of a key with no name of its own. */\n written: string;\n mod: boolean;\n ctrl: boolean;\n alt: boolean;\n shift: boolean;\n meta: boolean;\n};\n\nconst modifierNames: Record<string, keyof Omit<Parsed, \"key\" | \"written\">> = {\n mod: \"mod\",\n ctrl: \"ctrl\",\n control: \"ctrl\",\n alt: \"alt\",\n option: \"alt\",\n shift: \"shift\",\n meta: \"meta\",\n cmd: \"meta\",\n command: \"meta\",\n};\n\nconst keyAliases: Record<string, string> = { space: \" \", spacebar: \" \", esc: \"escape\", plus: \"+\" };\n\n/** Reads a key string; undefined when it names a modifier it does not know, or no key. */\nfunction parseKeys(keys: string): Parsed | undefined {\n let rest = keys === \" \" ? \"Space\" : keys.trim();\n let key: string;\n // \"+\" as the key itself: \"Mod++\" or a lone \"+\".\n if (rest === \"+\") return { key: \"+\", written: \"+\", mod: false, ctrl: false, alt: false, shift: false, meta: false };\n if (rest.endsWith(\"++\")) {\n key = \"+\";\n rest = rest.slice(0, -2);\n } else {\n const at = rest.lastIndexOf(\"+\");\n key = rest.slice(at + 1);\n rest = at < 0 ? \"\" : rest.slice(0, at);\n }\n if (key === \"\") return undefined;\n const lower = key.toLowerCase();\n const parsed: Parsed = {\n key: keyAliases[lower] ?? lower,\n written: key,\n mod: false,\n ctrl: false,\n alt: false,\n shift: false,\n meta: false,\n };\n for (const part of rest === \"\" ? [] : rest.split(\"+\")) {\n const name = modifierNames[part.trim().toLowerCase()];\n if (name === undefined) return undefined;\n parsed[name] = true;\n }\n return parsed;\n}\n\n/** A chord holds Mod, Ctrl, Alt or Meta; Shift alone is typing. */\nfunction isChord(parsed: Parsed): boolean {\n return parsed.mod || parsed.ctrl || parsed.alt || parsed.meta;\n}\n\n/**\n * A character that Shift itself makes (\"?\", \"!\"), whose binding need not name Shift. Not a digit: a digit is found by\n * its physical key too, so Shift+1 (\"!\") would otherwise run the binding for \"1\".\n */\nfunction isShiftedCharacter(key: string): boolean {\n return key.length === 1 && key.toLowerCase() === key.toUpperCase() && key !== \" \" && !/[0-9]/.test(key);\n}\n\ntype KeyEventLike = Pick<KeyboardEvent, \"key\" | \"code\" | \"ctrlKey\" | \"altKey\" | \"shiftKey\" | \"metaKey\">;\n\nfunction matchesParsed(event: KeyEventLike, parsed: Parsed, platform: Platform): boolean {\n const wantCtrl = parsed.ctrl || (parsed.mod && platform !== \"apple\");\n const wantMeta = parsed.meta || (parsed.mod && platform === \"apple\");\n if (event.ctrlKey !== wantCtrl || event.metaKey !== wantMeta || event.altKey !== parsed.alt) return false;\n if (!(isShiftedCharacter(parsed.key) && !parsed.shift) && event.shiftKey !== parsed.shift) return false;\n const pressed = event.key.toLowerCase();\n if (pressed === parsed.key) return true;\n // A letter or digit the layout or Alt turned into another character (Alt+K is \"˚\" on a Mac, K is \"к\" on a Russian\n // layout) is found by its physical key; a Latin letter that differs is another key (Q on an AZERTY layout).\n if (/^[a-z]$/.test(pressed) || !/^[a-z0-9]$/.test(parsed.key)) return false;\n return event.code === (/[a-z]/.test(parsed.key) ? `Key${parsed.key.toUpperCase()}` : `Digit${parsed.key}`);\n}\n\n/** Whether a keydown matches a key string (or any of several) on the platform. */\nexport function matchesKeys(\n event: KeyEventLike,\n keys: string | readonly string[],\n platform: Platform = detectPlatform(),\n): boolean {\n const list = typeof keys === \"string\" ? [keys] : keys;\n return list.some((one) => {\n const parsed = parseKeys(one);\n return parsed !== undefined && matchesParsed(event, parsed, platform);\n });\n}\n\nconst notTextInputs = new Set([\n \"button\",\n \"checkbox\",\n \"color\",\n \"file\",\n \"hidden\",\n \"image\",\n \"radio\",\n \"range\",\n \"reset\",\n \"submit\",\n]);\n\n/**\n * Whether keys pressed at the target belong to it: a text input, a textarea, a select, editable content, or anything\n * inside an element with React Flow's `nokey` class.\n */\nexport function isTextTarget(target: EventTarget | null): boolean {\n if (target === null || typeof (target as Element).closest !== \"function\") return false;\n const element = target as HTMLElement;\n if (element.closest(\".nokey\") !== null) return true;\n const tag = element.tagName.toLowerCase();\n if (tag === \"input\") return !notTextInputs.has(((element as HTMLInputElement).type || \"text\").toLowerCase());\n if (tag === \"textarea\" || tag === \"select\") return true;\n if (element.isContentEditable) return true;\n return element.closest('[contenteditable]:not([contenteditable=\"false\"])') !== null;\n}\n\ntype LabelOptions = {\n /** The platform the label is for; the browser's by default. */\n platform?: Platform;\n /** Replaces the words for keys and modifiers, by their names (\"Escape\", \"Ctrl\", \"Space\"). */\n names?: Readonly<Record<string, string>>;\n};\n\nconst appleModifiers = { ctrl: \"⌃\", alt: \"⌥\", shift: \"⇧\", meta: \"⌘\" } as const;\nconst otherModifiers = { ctrl: \"Ctrl\", alt: \"Alt\", shift: \"Shift\", meta: \"Meta\" } as const;\n\nconst sharedKeys: Record<string, string> = {\n \" \": \"Space\",\n escape: \"Esc\",\n arrowup: \"↑\",\n arrowdown: \"↓\",\n arrowleft: \"←\",\n arrowright: \"→\",\n pageup: \"Page Up\",\n pagedown: \"Page Down\",\n home: \"Home\",\n end: \"End\",\n};\nconst appleKeys: Record<string, string> = { enter: \"↩\", backspace: \"⌫\", delete: \"⌦\", tab: \"⇥\" };\nconst otherKeys: Record<string, string> = { enter: \"Enter\", backspace: \"Backspace\", delete: \"Delete\", tab: \"Tab\" };\n\nconst knownNames = [\n \"Escape\",\n \"Enter\",\n \"Tab\",\n \"Backspace\",\n \"Delete\",\n \"Insert\",\n \"ArrowUp\",\n \"ArrowDown\",\n \"ArrowLeft\",\n \"ArrowRight\",\n \"PageUp\",\n \"PageDown\",\n \"Home\",\n \"End\",\n];\nconst canonicalNames: Record<string, string> = Object.fromEntries<string>([\n ...knownNames.map((name): [string, string] => [name.toLowerCase(), name]),\n [\" \", \"Space\"],\n]);\n\n/** A parsed key's KeyboardEvent name, as `names` is keyed: \"Escape\", \"ArrowUp\", \"Space\", \"K\", \"F5\". */\nfunction canonicalName(parsed: Parsed): string {\n return canonicalNames[parsed.key] ?? (parsed.key.length === 1 ? parsed.key.toUpperCase() : parsed.written);\n}\n\n/**\n * The key string as people read it: \"⌘K\" on Apple platforms and \"Ctrl+K\" elsewhere, \"⇧⌘Z\" and \"Ctrl+Shift+Z\". A\n * string it cannot read is shown as written.\n */\nexport function keyLabel(keys: string, options: LabelOptions = {}): string {\n const { platform = detectPlatform(), names = {} } = options;\n const parsed = parseKeys(keys);\n if (parsed === undefined) return keys;\n const apple = platform === \"apple\";\n const ctrl = parsed.ctrl || (parsed.mod && !apple);\n const meta = parsed.meta || (parsed.mod && apple);\n const words = apple ? appleModifiers : otherModifiers;\n const modifiers: string[] = [];\n // Apple's order is ⌃⌥⇧⌘; elsewhere Ctrl, Alt, Shift, Meta.\n if (ctrl) modifiers.push(names[\"Ctrl\"] ?? words.ctrl);\n if (parsed.alt) modifiers.push(names[\"Alt\"] ?? words.alt);\n if (parsed.shift) modifiers.push(names[\"Shift\"] ?? words.shift);\n if (meta) modifiers.push(names[\"Meta\"] ?? words.meta);\n const lookup = parsed.key;\n const canonical = canonicalName(parsed);\n const named = names[canonical] ?? (apple ? appleKeys[lookup] : otherKeys[lookup]) ?? sharedKeys[lookup] ?? canonical;\n return apple ? [...modifiers, named].join(\"\") : [...modifiers, named].join(\"+\");\n}\n\nconst ariaKeys: Record<string, string> = { \" \": \"Space\", \"+\": \"Plus\" };\n\n/** The key strings as an `aria-keyshortcuts` value: \"Meta+K\" on Apple platforms, \"Control+K\" elsewhere. */\nexport function ariaKeyShortcuts(keys: string | readonly string[], platform: Platform = detectPlatform()): string {\n const list = typeof keys === \"string\" ? [keys] : keys;\n return list\n .flatMap((one) => {\n const parsed = parseKeys(one);\n if (parsed === undefined) return [];\n const parts: string[] = [];\n if (parsed.ctrl || (parsed.mod && platform !== \"apple\")) parts.push(\"Control\");\n if (parsed.alt) parts.push(\"Alt\");\n if (parsed.shift) parts.push(\"Shift\");\n if (parsed.meta || (parsed.mod && platform === \"apple\")) parts.push(\"Meta\");\n parts.push(ariaKeys[parsed.key] ?? canonicalName(parsed));\n return [parts.join(\"+\")];\n })\n .join(\" \");\n}\n\n/** The first binding in the table that this keydown should run, if any. */\nexport function findShortcut(\n event: KeyboardEvent,\n bindings: readonly Shortcut[],\n platform: Platform = detectPlatform(),\n): Shortcut | undefined {\n // A press a component already handled (a dialog's Escape) or one inside an input method's composition is not ours.\n if (event.defaultPrevented || event.isComposing || event.key === \"Process\") return undefined;\n const inText = isTextTarget(event.target);\n for (const binding of bindings) {\n if (binding.enabled === false) continue;\n if (event.repeat && binding.repeat !== true) continue;\n const list = typeof binding.keys === \"string\" ? [binding.keys] : binding.keys;\n for (const one of list) {\n const parsed = parseKeys(one);\n if (parsed === undefined || !matchesParsed(event, parsed, platform)) continue;\n if (inText && !(binding.inTextFields === true && isChord(parsed) && parsed.key !== \"escape\")) continue;\n return binding;\n }\n }\n return undefined;\n}\n\n/**\n * Binds the table's keys on the window while the component is mounted. The table may change every render; the\n * listener always reads the latest. The first binding that matches a press runs, and only it.\n */\nexport function useShortcuts(bindings: readonly Shortcut[], options: UseShortcutsOptions = {}): void {\n const { enabled = true, platform } = options;\n const latest = useRef({ bindings, platform });\n useEffect(() => {\n latest.current = { bindings, platform };\n });\n useEffect(() => {\n if (!enabled || typeof window === \"undefined\") return;\n const onKeyDown = (event: KeyboardEvent) => {\n const { bindings: table, platform: chosen } = latest.current;\n const binding = findShortcut(event, table, chosen ?? detectPlatform());\n if (binding === undefined) return;\n if (binding.preventDefault !== false) event.preventDefault();\n binding.run(event);\n };\n window.addEventListener(\"keydown\", onKeyDown);\n return () => {\n window.removeEventListener(\"keydown\", onKeyDown);\n };\n }, [enabled]);\n}\n","// The theme: system, light or dark, written to data-theme on <html> (docs/tokens.md#the-theme). System removes the\n// attribute, so tokens.css's prefers-color-scheme rule decides. The choice is kept in localStorage through\n// usePersistentState, under a key the app names (its own prefix), and themeScript gives the app's index.html a tiny\n// inline script that applies the kept choice before the first paint, so a dark page never flashes light.\nimport { useLayoutEffect } from \"react\";\nimport { type PersistentStateOptions, usePersistentState } from \"../use-persistent-state/usePersistentState\";\n\nexport type ThemeChoice = \"system\" | \"light\" | \"dark\";\n\n/** The switch's cycle order. */\nexport const themeChoices: readonly ThemeChoice[] = [\"system\", \"light\", \"dark\"];\n\n/** The page follows the system until the person chooses. */\nexport const defaultTheme: ThemeChoice = \"system\";\n\n/** The key used when the app names none. */\nexport const defaultThemeKey = \"patchbay/theme\";\n\n/** The choice after `choice` in the cycle system, light, dark. */\nexport function nextTheme(choice: ThemeChoice): ThemeChoice {\n const at = themeChoices.indexOf(choice);\n return themeChoices[(at + 1) % themeChoices.length] ?? defaultTheme;\n}\n\n/** A kept value that is one of the three choices, else undefined. */\nexport function checkTheme(value: unknown): ThemeChoice | undefined {\n return themeChoices.find((choice) => choice === value);\n}\n\n/** Writes the choice onto the root it is given (the page's <html>): system removes data-theme. */\nexport function applyTheme(root: { dataset: DOMStringMap }, choice: ThemeChoice): void {\n if (choice === \"system\") delete root.dataset[\"theme\"];\n else root.dataset[\"theme\"] = choice;\n}\n\n/**\n * The body of an inline <script> for the app's index.html, run before the page draws: it applies the choice kept\n * under `key`, as useTheme keeps it, and does nothing when storage is blocked or the value is not light or dark.\n */\nexport function themeScript(key: string = defaultThemeKey): string {\n // JSON names the key as a string literal; \"<\" is escaped so the text cannot close the script element.\n const name = JSON.stringify(key).replace(/</g, \"\\\\u003c\");\n return (\n `try{var c=JSON.parse(localStorage.getItem(${name}));` +\n `if(c===\"light\"||c===\"dark\")document.documentElement.setAttribute(\"data-theme\",c)}catch(e){}`\n );\n}\n\nexport interface UseThemeOptions extends PersistentStateOptions {\n /** The localStorage key the choice is kept under: the app's own, with its prefix. */\n key?: string;\n /** Where data-theme is written; the page's <html> by default. */\n root?: { dataset: DOMStringMap };\n}\n\n/** The theme choice and its setter; the choice is kept, and written to data-theme on <html> before paint. */\nexport function useTheme(options: UseThemeOptions = {}): [ThemeChoice, (choice: ThemeChoice) => void] {\n const { key = defaultThemeKey, root, storage } = options;\n const [choice, setChoice] = usePersistentState<ThemeChoice>(\n key,\n defaultTheme,\n checkTheme,\n storage === undefined ? {} : { storage },\n );\n useLayoutEffect(() => {\n applyTheme(root ?? document.documentElement, choice);\n }, [root, choice]);\n return [choice, setChoice];\n}\n","// The toast queue, pure (docs/components.md#usetoasts): every step takes the queue and the time and returns a new\n// queue, so it is tested without React or timers. A toast shown again under the same key within the coalescing window\n// counts up in place of stacking; each lasts its duration on the monotonic clock the caller reads; none expires while\n// the queue is held (the person is hovering over or focused in the toasts), and letting go moves each expiry on by the\n// time it was held; the newest few are shown and the rest fold into a count.\nimport type { ReactNode } from \"react\";\n\n/** The tones a toast is drawn in; any other string is drawn neutrally. An `err` toast is an alert, the rest status. */\nexport type ToastTone = \"ok\" | \"warn\" | \"err\" | \"quiet\" | \"off\" | (string & {});\n\n/** A button on a toast that acts on its news. Pressing it runs `run`, then dismisses the toast. */\nexport type ToastAction = {\n /** The button's words. */\n label: string;\n run: () => void;\n};\n\n/** What the app shows. */\nexport type ToastInput = {\n tone: ToastTone;\n /** The news; any node, so it may hold code or emphasis. */\n text: ReactNode;\n /**\n * Toasts shown under the same key within the coalescing window are one toast that counts up (\"×3\"), taking the\n * newest tone, text and action. Without a key a toast never coalesces.\n */\n key?: string;\n action?: ToastAction;\n /** How long this toast lasts unheld, in ms, in place of the queue's duration; Infinity keeps it until dismissed. */\n duration?: number;\n};\n\n/** A toast in the queue. */\nexport type Toast = Omit<ToastInput, \"duration\"> & {\n /** Its own, never reused while the queue lives. */\n id: number;\n /** How many times it was shown, coalesced; 1 at first. */\n count: number;\n /** When it was last shown, on the queue's clock. */\n lastAt: number;\n /** When it goes, on the queue's clock; Infinity for one kept until dismissed. */\n expiresAt: number;\n};\n\nexport type ToastQueue = {\n /** Oldest first. */\n readonly toasts: readonly Toast[];\n /** While held: since when. */\n readonly heldSince?: number;\n /** The id the next new toast takes. */\n readonly nextId: number;\n};\n\nexport type ToastQueueOptions = {\n /** How long a toast lasts unheld, in ms. */\n duration?: number;\n /** A toast shown again under its key within this many ms of its last showing counts up. */\n coalesceWindow?: number;\n};\n\n/** The defaults: 8 s a toast, 5 s to coalesce, the newest four shown. */\nexport const toastDefaults = { duration: 8000, coalesceWindow: 5000, visible: 4 } as const;\n\n/** The empty queue. */\nexport const emptyToastQueue: ToastQueue = Object.freeze({ toasts: Object.freeze([]), nextId: 1 });\n\n/** Adds a toast as the newest, or counts up the one it coalesces with and makes that the newest. */\nexport function addToast(\n queue: ToastQueue,\n input: ToastInput,\n now: number,\n options: ToastQueueOptions = {},\n): ToastQueue {\n const window = options.coalesceWindow ?? toastDefaults.coalesceWindow;\n const { duration = options.duration ?? toastDefaults.duration, ...shown } = input;\n const same =\n input.key === undefined\n ? undefined\n : queue.toasts.find((toast) => toast.key === input.key && now - toast.lastAt < window);\n const rest = same === undefined ? queue.toasts : queue.toasts.filter((toast) => toast !== same);\n const toast: Toast = {\n ...shown,\n id: same?.id ?? queue.nextId,\n count: (same?.count ?? 0) + 1,\n lastAt: now,\n expiresAt: now + duration,\n };\n return { ...queue, toasts: [...rest, toast], nextId: same === undefined ? queue.nextId + 1 : queue.nextId };\n}\n\n/** Takes the toast away; the same queue if it is not there. */\nexport function dismissToast(queue: ToastQueue, id: number): ToastQueue {\n const toasts = queue.toasts.filter((toast) => toast.id !== id);\n return toasts.length === queue.toasts.length ? queue : { ...queue, toasts };\n}\n\n/** Takes every toast away. */\nexport function clearToasts(queue: ToastQueue): ToastQueue {\n return queue.toasts.length === 0 ? queue : { ...queue, toasts: [] };\n}\n\n/**\n * Holds the queue (nothing expires) or lets it go. Letting go moves each toast's expiry on by the time it was held:\n * since the hold began, or since it was last shown if that came later. The same queue when nothing changes.\n */\nexport function holdToasts(queue: ToastQueue, held: boolean, now: number): ToastQueue {\n const { heldSince } = queue;\n if (held) return heldSince === undefined ? { ...queue, heldSince: now } : queue;\n if (heldSince === undefined) return queue;\n const toasts = queue.toasts.map((toast) => ({\n ...toast,\n expiresAt: toast.expiresAt + Math.max(0, now - Math.max(heldSince, toast.lastAt)),\n }));\n return { toasts, nextId: queue.nextId };\n}\n\n/** Drops the toasts whose time is over; nothing while held. The same queue when none is over. */\nexport function expireToasts(queue: ToastQueue, now: number): ToastQueue {\n if (queue.heldSince !== undefined) return queue;\n const toasts = queue.toasts.filter((toast) => toast.expiresAt > now);\n return toasts.length === queue.toasts.length ? queue : { ...queue, toasts };\n}\n\n/** When the soonest toast expires; undefined while held, or with none that expires. */\nexport function nextToastExpiry(queue: ToastQueue): number | undefined {\n if (queue.heldSince !== undefined) return undefined;\n let soonest: number | undefined;\n for (const { expiresAt } of queue.toasts) {\n if (Number.isFinite(expiresAt) && (soonest === undefined || expiresAt < soonest)) soonest = expiresAt;\n }\n return soonest;\n}\n\n/** The newest `visible` toasts, oldest first, and how many older ones fold into \"and n more\". */\nexport function visibleToasts(\n queue: ToastQueue,\n visible: number = toastDefaults.visible,\n): { shown: readonly Toast[]; more: number } {\n const cap = Number.isNaN(visible) ? toastDefaults.visible : Math.max(0, Math.floor(visible));\n const more = Math.max(0, queue.toasts.length - cap);\n return { shown: queue.toasts.slice(more), more };\n}\n","// useToasts (docs/components.md#usetoasts): the toast queue (toastQueue.ts) held in React state, with one timer for\n// the soonest expiry on the monotonic clock. It returns what shows a toast and the props a Toaster draws from.\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n addToast,\n clearToasts,\n dismissToast,\n emptyToastQueue,\n expireToasts,\n holdToasts,\n nextToastExpiry,\n type Toast,\n type ToastInput,\n type ToastQueue,\n toastDefaults,\n visibleToasts,\n} from \"./toastQueue\";\n\nexport type UseToastsOptions = {\n /** How long a toast lasts unheld, in ms (8000). A toast's own `duration` wins. */\n duration?: number;\n /** A toast shown again under its key within this many ms of its last showing counts up (5000). */\n coalesceWindow?: number;\n /** How many toasts are shown, the newest; older ones fold into \"and n more\" (4). */\n visible?: number;\n /** The monotonic clock, in ms (`performance.now` by default); tests pass their own. */\n now?: () => number;\n};\n\n/** What a Toaster draws from: spread it onto one (`<Toaster {...toasts.toasterProps} />`). */\nexport type ToasterBinding = {\n /** The shown toasts, oldest first. */\n toasts: readonly Toast[];\n /** How many older toasts are folded away. */\n more: number;\n onDismiss: (id: number) => void;\n /** Held while the person hovers over or is focused in the toasts: none expires. */\n onHold: (held: boolean) => void;\n};\n\nexport type UseToastsResult = {\n /** Every toast in the queue, oldest first, the folded ones included. */\n toasts: readonly Toast[];\n /** Shows a toast, or counts up the one it coalesces with; returns its id. */\n show: (input: ToastInput) => number;\n dismiss: (id: number) => void;\n clear: () => void;\n toasterProps: ToasterBinding;\n};\n\nconst performanceNow = () => performance.now();\n\nexport function useToasts(options: UseToastsOptions = {}): UseToastsResult {\n const { duration, coalesceWindow, visible = toastDefaults.visible, now = performanceNow } = options;\n const [queue, setQueue] = useState<ToastQueue>(emptyToastQueue);\n // The queue as last set, so show can return the id at once and two calls in one event both count.\n const current = useRef(queue);\n const latest = useRef({ duration, coalesceWindow, now });\n useEffect(() => {\n latest.current = { duration, coalesceWindow, now };\n });\n\n const update = useCallback((step: (queue: ToastQueue, now: number) => ToastQueue) => {\n const next = step(current.current, latest.current.now());\n if (next === current.current) return next;\n current.current = next;\n setQueue(next);\n return next;\n }, []);\n\n const show = useCallback(\n (input: ToastInput) => {\n const { duration: forEach, coalesceWindow: window } = latest.current;\n const next = update((queue, at) => addToast(queue, input, at, { duration: forEach, coalesceWindow: window }));\n const added = next.toasts.at(-1);\n if (added === undefined) throw new Error(\"useToasts: a toast was shown but not added\");\n return added.id;\n },\n [update],\n );\n const dismiss = useCallback((id: number) => void update((queue) => dismissToast(queue, id)), [update]);\n const clear = useCallback(() => void update(clearToasts), [update]);\n const hold = useCallback((held: boolean) => void update((queue, at) => holdToasts(queue, held, at)), [update]);\n\n // One timer, for the soonest expiry, a millisecond past it. A timer that still finds nothing over (it fired early\n // against the clock, or the app's clock lags the timers') is set again, or the toast would never go.\n const at = nextToastExpiry(queue);\n const [rearm, setRearm] = useState(0);\n useEffect(() => {\n if (at === undefined) return undefined;\n const timer = setTimeout(\n () => {\n const before = current.current;\n if (update(expireToasts) === before) setRearm((count) => count + 1);\n },\n Math.max(0, Math.ceil(at - latest.current.now()) + 1),\n );\n return () => {\n clearTimeout(timer);\n };\n }, [at, rearm, update]);\n\n const toasterProps = useMemo(() => {\n const { shown, more } = visibleToasts(queue, visible);\n return { toasts: shown, more, onDismiss: dismiss, onHold: hold };\n }, [queue, visible, dismiss, hold]);\n return { toasts: queue.toasts, show, dismiss, clear, toasterProps };\n}\n"],"mappings":";;AAaA,SAAgBA,EACd,GACA,GACA,GAC0B;CAC1B,IAAMC,IAAQC,EAAsB,KAAA,CAAS,GACvCC,IAASD,EAAO;EAAE;EAAM;CAAQ,CAAC;CAqBvC,OAnBAE,QAAsB;EACpB,EAAO,UAAU;GAAE;GAAM;EAAQ;CACnC,CAAC,GACDA,QAAsB;EACpB,IAAIC,IAAO,IACLC,UAAa;GACjB,IAAI,CAACD,GAAM;GACX,IAAME,IAAOJ,EAAO,QAAQ,KAAK;GAEjC,AADA,EAAM,UAAUI,GAChBJ,EAAO,QAAQ,UAAUI,CAAI;EAC/B,G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