@tristan2828/ui-foundation 4.155.1 → 4.155.2
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.
|
@@ -7,10 +7,10 @@
|
|
|
7
7
|
- [The dark stage](#the-dark-stage) · lines 74–109
|
|
8
8
|
- [The clock](#the-clock) · lines 111–141
|
|
9
9
|
- [Sound](#sound) · lines 143–192
|
|
10
|
-
- [Background tabs](#background-tabs) · lines 194–
|
|
11
|
-
- [Interruptions](#interruptions) · lines 228–
|
|
12
|
-
- [Motion](#motion) · lines
|
|
13
|
-
- [Testing a timed screen in Playwright](#testing-a-timed-screen-in-playwright) · lines
|
|
10
|
+
- [Background tabs](#background-tabs) · lines 194–255
|
|
11
|
+
- [Interruptions](#interruptions) · lines 228–255
|
|
12
|
+
- [Motion](#motion) · lines 257–261
|
|
13
|
+
- [Testing a timed screen in Playwright](#testing-a-timed-screen-in-playwright) · lines 263–415
|
|
14
14
|
|
|
15
15
|
<!-- /index -->
|
|
16
16
|
|
|
@@ -247,6 +247,13 @@ its run is now, so it rebooks:
|
|
|
247
247
|
for where no recovery was announced: when it's false, `cancelCues()` and
|
|
248
248
|
book again.
|
|
249
249
|
|
|
250
|
+
**Speech is the one wait.** A line from `say()` starting to speak is itself
|
|
251
|
+
what stops the context, and resuming it then cuts the line off partway, so
|
|
252
|
+
while a line is being spoken the resume waits for its end (or `hush()`, or
|
|
253
|
+
a fallback a few seconds past its length). A chime due while the line
|
|
254
|
+
speaks stays silent, as it already did while the context stood still; the
|
|
255
|
+
recovery after the line rebooks from there on.
|
|
256
|
+
|
|
250
257
|
## Motion
|
|
251
258
|
|
|
252
259
|
`usePrefersReducedMotion()` is true while the person's system asks for
|
package/dist/lib/audio-cues.d.ts
CHANGED
|
@@ -40,6 +40,8 @@ export type AudioCuesEnvironment = {
|
|
|
40
40
|
now?: () => number;
|
|
41
41
|
/** The page, for noticing it's visible again after the audio stopped. */
|
|
42
42
|
document?: Pick<Document, 'addEventListener' | 'visibilityState'>;
|
|
43
|
+
/** For the fallback that ends a line whose end never comes (default the global one). */
|
|
44
|
+
setTimeout?: (callback: () => void, ms: number) => unknown;
|
|
43
45
|
};
|
|
44
46
|
export type AudioCues = {
|
|
45
47
|
/** Call from the click or tap that starts a session; sound is allowed from then on. */
|
|
@@ -64,7 +66,11 @@ export type AudioCues = {
|
|
|
64
66
|
* on a tick, for where no recovery was announced. `now` is for tests.
|
|
65
67
|
*/
|
|
66
68
|
cuesInSync: (now?: number) => boolean;
|
|
67
|
-
/**
|
|
69
|
+
/**
|
|
70
|
+
* Speaks `text`, cutting off any line still being spoken. Nothing else cuts
|
|
71
|
+
* it short: a chime, cancelCues(), and an interruption the line itself
|
|
72
|
+
* causes (iOS) wait for it to end.
|
|
73
|
+
*/
|
|
68
74
|
say: (text: string, options?: SayOptions) => void;
|
|
69
75
|
/** Stops whatever is being spoken. */
|
|
70
76
|
hush: () => void;
|
package/dist/lib/audio-cues.js
CHANGED
|
@@ -18,7 +18,11 @@
|
|
|
18
18
|
// speaking, a call, the lock screen) and booked strikes go silent or late.
|
|
19
19
|
// The context is resumed as soon as it stops, and once it runs again every
|
|
20
20
|
// booking is taken back and onCuesRecovered() callbacks fire, so the screen
|
|
21
|
-
// rebooks from where its run is now.
|
|
21
|
+
// rebooks from where its run is now. Speech is the exception: a line starting
|
|
22
|
+
// to speak is itself what stops the context, and resuming it then takes the
|
|
23
|
+
// audio back and cuts the line off partway, so while a line is being spoken
|
|
24
|
+
// the resume waits for its end (or hush(), or a fallback for a line whose end
|
|
25
|
+
// never comes). cuesInSync() catches the case
|
|
22
26
|
// where no statechange came, by comparing the audio clock with Date.now().
|
|
23
27
|
//
|
|
24
28
|
// createAudioCues takes the browser's APIs, so the rules are unit tested
|
|
@@ -29,6 +33,10 @@ const ATTACK = 0.015;
|
|
|
29
33
|
const SILENT = 0.0001;
|
|
30
34
|
// How far the audio clock may drift from Date.now() before cuesInSync() says so.
|
|
31
35
|
const SYNC_MARGIN = 250;
|
|
36
|
+
// A line whose end never comes (a browser that drops onend) holds an
|
|
37
|
+
// interrupted context's resume no longer than this, plus its length's worth.
|
|
38
|
+
const LINE_MS = 3000;
|
|
39
|
+
const LINE_MS_PER_CHARACTER = 120;
|
|
32
40
|
const NO_CUE = { cancel: () => { } };
|
|
33
41
|
export function createAudioCues(env) {
|
|
34
42
|
const now = env.now ?? Date.now;
|
|
@@ -47,6 +55,10 @@ export function createAudioCues(env) {
|
|
|
47
55
|
// The audio clock against Date.now() when the first of the current bookings
|
|
48
56
|
// was made, for cuesInSync().
|
|
49
57
|
let anchor = null;
|
|
58
|
+
// The line being spoken, if any: while it speaks, a stopped context waits
|
|
59
|
+
// for its end to be resumed, since resuming it cuts the line off.
|
|
60
|
+
let speaking = null;
|
|
61
|
+
const later = env.setTimeout ?? ((callback, ms) => globalThis.setTimeout(callback, ms));
|
|
50
62
|
const playable = () => context !== null && (context.state === 'running' || resuming);
|
|
51
63
|
const strike = (ctx, { pitch = 660, volume = 0.25, duration = 1200 }, delay) => {
|
|
52
64
|
const start = ctx.currentTime + Math.max(delay, 0) / 1000;
|
|
@@ -128,9 +140,19 @@ export function createAudioCues(env) {
|
|
|
128
140
|
}
|
|
129
141
|
else if (everRan && stoppedState(ctx.state)) {
|
|
130
142
|
stopped = true;
|
|
131
|
-
|
|
143
|
+
if (!speaking)
|
|
144
|
+
resume(ctx);
|
|
132
145
|
}
|
|
133
146
|
};
|
|
147
|
+
// The line has ended (or been cut off by hush()): a context it stopped is
|
|
148
|
+
// resumed now. A line cut off by the next say() isn't the one speaking.
|
|
149
|
+
const lineOver = (line) => {
|
|
150
|
+
if (!line || speaking !== line)
|
|
151
|
+
return;
|
|
152
|
+
speaking = null;
|
|
153
|
+
if (context && stopped)
|
|
154
|
+
resume(context);
|
|
155
|
+
};
|
|
134
156
|
const watch = (ctx) => {
|
|
135
157
|
ctx.addEventListener?.('statechange', check);
|
|
136
158
|
const page = env.document;
|
|
@@ -212,6 +234,9 @@ export function createAudioCues(env) {
|
|
|
212
234
|
if (!env.speechSynthesis || !env.SpeechSynthesisUtterance)
|
|
213
235
|
return;
|
|
214
236
|
try {
|
|
237
|
+
// The line cut off here ends without letting a stopped context go:
|
|
238
|
+
// the next one speaks straight after.
|
|
239
|
+
speaking = null;
|
|
215
240
|
env.speechSynthesis.cancel();
|
|
216
241
|
const line = new env.SpeechSynthesisUtterance(text);
|
|
217
242
|
if (lang)
|
|
@@ -220,10 +245,18 @@ export function createAudioCues(env) {
|
|
|
220
245
|
line.rate = rate;
|
|
221
246
|
if (volume !== undefined)
|
|
222
247
|
line.volume = volume;
|
|
248
|
+
const over = () => lineOver(line);
|
|
249
|
+
line.onend = over;
|
|
250
|
+
line.onerror = over;
|
|
251
|
+
speaking = line;
|
|
223
252
|
env.speechSynthesis.speak(line);
|
|
253
|
+
later(over, LINE_MS + text.length * LINE_MS_PER_CHARACTER);
|
|
224
254
|
}
|
|
225
255
|
catch {
|
|
226
256
|
// Speech unavailable: the cue is dropped.
|
|
257
|
+
speaking = null;
|
|
258
|
+
if (context && stopped)
|
|
259
|
+
resume(context);
|
|
227
260
|
}
|
|
228
261
|
},
|
|
229
262
|
hush() {
|
|
@@ -233,6 +266,7 @@ export function createAudioCues(env) {
|
|
|
233
266
|
catch {
|
|
234
267
|
// Nothing to stop.
|
|
235
268
|
}
|
|
269
|
+
lineOver(speaking);
|
|
236
270
|
},
|
|
237
271
|
vibrate(pattern) {
|
|
238
272
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.155.
|
|
3
|
+
"version": "4.155.2",
|
|
4
4
|
"description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|