@tristan2828/ui-foundation 4.155.0 → 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–248
11
- - [Interruptions](#interruptions) · lines 228–248
12
- - [Motion](#motion) · lines 250–254
13
- - [Testing a timed screen in Playwright](#testing-a-timed-screen-in-playwright) · lines 256–408
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
@@ -21,6 +21,10 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
21
21
  // - Its buttons are 44px, a finger's (the row is 48px tall, and the
22
22
  // buttons between Aa and Hide keyboard scroll sideways on a narrow
23
23
  // phone), on semantic tokens only.
24
+ // - No double-tap zoom on the row or the panel (`touch-manipulation`):
25
+ // Safari takes two quick presses of a button for a double-tap and
26
+ // zooms the page, which pushes buttons off the row and leaves the row
27
+ // behind the keyboard until the zoom settles. Pinch zoom still works.
24
28
  //
25
29
  // Placed inside the field's element, not in a portal, like the floating
26
30
  // toolbar (rich-text-floating-toolbar.tsx says why): `position: fixed`,
@@ -191,7 +195,7 @@ export function RichTextKeyboardBar({ view, state, readOnly, controls, onFormat,
191
195
  };
192
196
  const shown = edge !== null && ready;
193
197
  const bottom = edge ? edge.bottom - (panel ? panelHeight : 0) : 0;
194
- return (_jsxs("div", { ref: ref, "data-slot": "rich-text-keyboard-bar", "data-rich-text-menu": "", onBlur: onBlur, children: [_jsx("span", { ref: probe, "aria-hidden": "true", className: "pointer-events-none fixed top-0 left-0 size-0" }), _jsxs("div", { ref: row, role: "toolbar", "aria-label": "Formatting", "aria-controls": controls, style: edge ? { top: bottom, left: edge.left, width: edge.width } : undefined, className: cn('fixed z-50 flex h-12 -translate-y-full items-center gap-0.5 border-t border-border bg-card px-1 text-card-foreground', !shown && 'invisible'), children: [_jsx(Toggle, { "aria-label": panel ? 'Keyboard' : 'All Formats', pressed: panel, disabled: readOnly, className: "size-11 min-w-11 font-serif text-base aria-pressed:bg-muted aria-pressed:text-foreground [&_svg]:size-5", onMouseDown: keep, onPressedChange: (open) => {
198
+ return (_jsxs("div", { ref: ref, "data-slot": "rich-text-keyboard-bar", "data-rich-text-menu": "", onBlur: onBlur, children: [_jsx("span", { ref: probe, "aria-hidden": "true", className: "pointer-events-none fixed top-0 left-0 size-0" }), _jsxs("div", { ref: row, role: "toolbar", "aria-label": "Formatting", "aria-controls": controls, style: edge ? { top: bottom, left: edge.left, width: edge.width } : undefined, className: cn('fixed z-50 flex h-12 -translate-y-full touch-manipulation items-center gap-0.5 border-t border-border bg-card px-1 text-card-foreground', !shown && 'invisible'), children: [_jsx(Toggle, { "aria-label": panel ? 'Keyboard' : 'All Formats', pressed: panel, disabled: readOnly, className: "size-11 min-w-11 font-serif text-base aria-pressed:bg-muted aria-pressed:text-foreground [&_svg]:size-5", onMouseDown: keep, onPressedChange: (open) => {
195
199
  setPanel(open);
196
200
  if (!open)
197
201
  virtualKeyboard()?.show();
@@ -202,7 +206,7 @@ export function RichTextKeyboardBar({ view, state, readOnly, controls, onFormat,
202
206
  disabled: readOnly, className: "size-11 [&_svg]:size-5", onMouseDown: keep, onClick: press(() => undo(view.state, view.dispatch)), children: _jsx(Undo2Icon, { "aria-hidden": "true" }) })] }))] }), _jsx(Button, { variant: "ghost", size: "icon-lg", "aria-label": "Hide Keyboard", className: "size-11 [&_svg]:size-5", onMouseDown: keep, onClick: () => {
203
207
  setPanel(false);
204
208
  view.dom.blur();
205
- }, children: _jsx(ChevronDownIcon, { "aria-hidden": "true" }) })] }), panel && edge && (_jsxs("div", { role: "group", "aria-label": "All Formats", "data-slot": "rich-text-keyboard-panel", style: { top: edge.bottom - panelHeight, left: edge.left, width: edge.width, height: panelHeight }, className: "fixed z-50 flex flex-col gap-3 overflow-y-auto bg-card px-3 py-3 text-card-foreground", onMouseDown: keep, children: [_jsx("p", { className: "type-caption text-muted-foreground", children: "Words" }), _jsx("div", { role: "toolbar", "aria-label": "Format Words", className: "flex flex-wrap items-center gap-1", children: _jsx(FormatButtons, { formats: "selection", state: state, readOnly: readOnly, onFormat: onFormat, text: text, touch: true }) }), _jsx("p", { className: "type-caption text-muted-foreground", children: "Blocks" }), _jsxs("div", { className: "grid grid-cols-4 gap-1.5", children: [BLOCKS.map((item) => {
209
+ }, children: _jsx(ChevronDownIcon, { "aria-hidden": "true" }) })] }), panel && edge && (_jsxs("div", { role: "group", "aria-label": "All Formats", "data-slot": "rich-text-keyboard-panel", style: { top: edge.bottom - panelHeight, left: edge.left, width: edge.width, height: panelHeight }, className: "fixed z-50 flex touch-manipulation flex-col gap-3 overflow-y-auto bg-card px-3 py-3 text-card-foreground", onMouseDown: keep, children: [_jsx("p", { className: "type-caption text-muted-foreground", children: "Words" }), _jsx("div", { role: "toolbar", "aria-label": "Format Words", className: "flex flex-wrap items-center gap-1", children: _jsx(FormatButtons, { formats: "selection", state: state, readOnly: readOnly, onFormat: onFormat, text: text, touch: true }) }), _jsx("p", { className: "type-caption text-muted-foreground", children: "Blocks" }), _jsxs("div", { className: "grid grid-cols-4 gap-1.5", children: [BLOCKS.map((item) => {
206
210
  const Icon = item.icon;
207
211
  const disabled = readOnly || (item.id === 'table' && state !== null && formatOn(state, 'table'));
208
212
  const look = TILE;
@@ -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
- /** Speaks `text`, cutting off any line still being spoken. */
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;
@@ -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. cuesInSync() catches the case
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
- resume(ctx);
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.0",
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": {