@vitrinka/web 0.1.5 → 0.2.1

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 (69) hide show
  1. package/CHANGELOG.md +63 -0
  2. package/README.md +73 -21
  3. package/build/hud.d.ts +9 -0
  4. package/build/hud.iife.js +411 -0
  5. package/build/hud.js +8 -0
  6. package/build/recorder/api.d.ts +2 -0
  7. package/build/recorder/block.d.ts +7 -0
  8. package/build/recorder/block.js +7 -0
  9. package/build/recorder/capture/click.d.ts +2 -4
  10. package/build/recorder/capture/click.js +2 -31
  11. package/build/recorder/capture/rrweb.d.ts +2 -2
  12. package/build/recorder/capture/rrweb.js +2 -2
  13. package/build/recorder/capture/selector.d.ts +8 -0
  14. package/build/recorder/capture/selector.js +35 -0
  15. package/build/recorder/hud/AnnotateOverlay.d.ts +7 -1
  16. package/build/recorder/hud/AnnotateOverlay.js +58 -28
  17. package/build/recorder/hud/Hud.d.ts +16 -1
  18. package/build/recorder/hud/Hud.js +255 -87
  19. package/build/recorder/hud/LinkSheet.d.ts +3 -3
  20. package/build/recorder/hud/LinkSheet.js +1 -1
  21. package/build/recorder/hud/Menu.d.ts +30 -0
  22. package/build/recorder/hud/Menu.js +73 -0
  23. package/build/recorder/hud/RecorderPill.d.ts +36 -27
  24. package/build/recorder/hud/RecorderPill.js +212 -123
  25. package/build/recorder/hud/Sheet.d.ts +1 -1
  26. package/build/recorder/hud/Sheet.js +1 -1
  27. package/build/recorder/hud/Tooltip.d.ts +19 -0
  28. package/build/recorder/hud/Tooltip.js +94 -0
  29. package/build/recorder/hud/controller.d.ts +148 -0
  30. package/build/recorder/hud/controller.js +17 -0
  31. package/build/recorder/hud/flow.d.ts +54 -0
  32. package/build/recorder/hud/flow.js +39 -0
  33. package/build/recorder/hud/host.js +1 -1
  34. package/build/recorder/hud/icons.d.ts +7 -0
  35. package/build/recorder/hud/icons.js +19 -0
  36. package/build/recorder/hud/iife.d.ts +13 -0
  37. package/build/recorder/hud/iife.js +11 -0
  38. package/build/recorder/hud/layer.d.ts +29 -6
  39. package/build/recorder/hud/layer.js +67 -33
  40. package/build/recorder/hud/listen.d.ts +24 -0
  41. package/build/recorder/hud/listen.js +27 -0
  42. package/build/recorder/hud/mount.d.ts +13 -0
  43. package/build/recorder/hud/mount.js +27 -0
  44. package/build/recorder/hud/place.d.ts +43 -0
  45. package/build/recorder/hud/place.js +63 -0
  46. package/build/recorder/hud/spots.d.ts +45 -0
  47. package/build/recorder/hud/spots.js +107 -0
  48. package/build/recorder/hud/status.d.ts +31 -0
  49. package/build/recorder/hud/status.js +67 -0
  50. package/build/recorder/hud/styles.d.ts +28 -18
  51. package/build/recorder/hud/styles.js +295 -122
  52. package/build/recorder/hud/useDock.d.ts +9 -8
  53. package/build/recorder/hud/useDock.js +43 -22
  54. package/build/recorder/index.d.ts +2 -2
  55. package/build/recorder/index.js +9 -18
  56. package/build/recorder/link.d.ts +1 -1
  57. package/build/recorder/link.js +9 -3
  58. package/build/recorder/me.d.ts +34 -0
  59. package/build/recorder/me.js +172 -0
  60. package/build/recorder/page-controller.d.ts +12 -0
  61. package/build/recorder/page-controller.js +100 -0
  62. package/build/recorder/queue.d.ts +4 -0
  63. package/build/recorder/queue.js +2 -0
  64. package/build/recorder/recents.d.ts +23 -0
  65. package/build/recorder/recents.js +80 -0
  66. package/build/recorder/session.d.ts +2 -2
  67. package/build/recorder/session.js +15 -1
  68. package/build/recorder/storage/index.js +2 -1
  69. package/package.json +10 -4
@@ -1,42 +1,64 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  /**
3
- * The HUD tree, rendered into the shadow host by its own React root. Owns
4
- * the dock (where the HUD rests), the sheet (open/title/ctx/pick + the
5
- * surviving draft) and where it opens, annotate mode, the keyboard
6
- * shortcuts, the Esc-anywhere / click-outside close and the status line a
7
- * screen reader hears while the capsule is folded.
3
+ * The HUD tree, rendered into the shadow host by its own React root and
4
+ * driven ONLY through a `HudController` (controller.ts) — the in-page
5
+ * recorder's, or another host's. Owns the dock (where the HUD rests), the
6
+ * pill's inline flows (flow.ts), the sheet (open/title/ctx/pick + the
7
+ * surviving draft) and where it opens, the ⋯ menu, the tooltip and details
8
+ * floats, annotate mode, the keyboard shortcuts, the Esc-anywhere /
9
+ * click-outside close and the status line a screen reader hears while the
10
+ * pill is folded.
8
11
  */
9
- import { colOf, rowOf } from '@vitrinka/link/dock';
10
- import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore, } from 'react';
12
+ import { useCallback, useEffect, useLayoutEffect, useMemo, useReducer, useRef, useState, useSyncExternalStore, } from 'react';
11
13
  import { createPortal } from 'react-dom';
12
- import { readLink, recorderConfig, vitrinkaLinked } from '../config';
13
- import { forgetLink, linkDevice, LinkExpired } from '../link';
14
- import { getState, health } from '../queue';
15
- import { addAnnotation, addNote, startSession, stopSession, togglePause } from '../session';
16
- import { annotateState, setAnnotating, subscribe } from '../state';
17
14
  import { AnnotateOverlay } from './AnnotateOverlay';
15
+ import { flowReducer, NO_FLOW } from './flow';
18
16
  import { createSheetHost, insideHud, sheetTarget } from './host';
19
- import { anchoredLayer, hostOrigin, PHONE_QUERY, phoneLayer, restingBox, useMedia, usePresence, useViewportTick } from './layer';
17
+ import { anchoredLayer, hostOrigin, PHONE_QUERY, phoneLayer, restingBox, useFloat, useMedia, usePresence, useViewportTick, } from './layer';
20
18
  import { LinkSheet } from './LinkSheet';
19
+ import { listen } from './listen';
20
+ import { Menu } from './Menu';
21
+ import { alignFor, towardCentre } from './place';
21
22
  import { RecorderPill } from './RecorderPill';
22
23
  import { Sheet } from './Sheet';
24
+ import { colOf, rowOf } from './spots';
25
+ import { fmtAgo, healthLine } from './status';
23
26
  import { HUD_CSS } from './styles';
27
+ import { Tooltip } from './Tooltip';
24
28
  import { useDock } from './useDock';
25
- let version = 0;
26
- const bump = () => ++version;
27
- function useRecorderState() {
28
- return useSyncExternalStore((cb) => subscribe(() => { bump(); cb(); }), () => version, () => version);
29
+ /** "Saving…" stays at least this long, so a fast save still reads as one. */
30
+ const MIN_SAVING_MS = 700;
31
+ /** How long the clock says "Saved" after a note or annotation. */
32
+ const FLASH_MS = 1600;
33
+ /** A clock that ticks every second while `active` (the timer, ages, the sync chip). */
34
+ function useNow(active) {
35
+ const [now, setNow] = useState(() => Date.now());
36
+ useEffect(() => {
37
+ if (!active)
38
+ return;
39
+ setNow(Date.now());
40
+ const t = setInterval(() => setNow(Date.now()), 1000);
41
+ return () => clearInterval(t);
42
+ }, [active]);
43
+ return active ? now : Date.now();
29
44
  }
30
- export function Hud({ hostMount, defaultTitle }) {
31
- useRecorderState();
32
- const rec = getState();
45
+ const errorText = (e) => (e instanceof Error ? e.message : String(e));
46
+ export function Hud({ controller, hostMount, defaultTitle, storage }) {
47
+ const snap = useSyncExternalStore(controller.subscribe, controller.getSnapshot, controller.getSnapshot);
48
+ const rec = snap.recording;
33
49
  const [sheet, setSheet] = useState(null);
34
50
  const [draft, setDraft] = useState('');
35
51
  const [starting, setStarting] = useState(false);
36
- const [stopping, setStopping] = useState(false);
37
- const annotating = annotateState.active;
38
- const linked = vitrinkaLinked();
39
- const canUnlink = !recorderConfig().key && readLink() !== null;
52
+ const [menu, setMenu] = useState(false);
53
+ const [flow, dispatch] = useReducer(flowReducer, NO_FLOW);
54
+ const [flash, setFlash] = useState(false);
55
+ const annotating = snap.annotating;
56
+ const now = useNow(rec !== null || menu || flow.face !== 'none');
57
+ const rootRef = useRef(null);
58
+ const pillRef = useRef(null);
59
+ const menuRef = useRef(null);
60
+ const detailRef = useRef(null);
61
+ const layerRef = useRef(null);
40
62
  // Device link (Netflix-style code): the sheet paints the phase, this owns it.
41
63
  const [link, setLink] = useState(null);
42
64
  const linkRef = useRef(null);
@@ -45,103 +67,179 @@ export function Hud({ hostMount, defaultTitle }) {
45
67
  linkRef.current = null;
46
68
  setLink(null);
47
69
  }, []);
70
+ const onStartRef = useRef(() => undefined);
48
71
  const beginLink = useCallback(() => {
49
72
  linkRef.current?.cancel();
50
73
  setSheet(null);
74
+ setMenu(false);
51
75
  setLink({ phase: 'starting', flow: null });
52
- linkDevice()
53
- .then((flow) => {
54
- linkRef.current = flow;
55
- setLink({ phase: 'waiting', flow });
56
- return flow.linked.then(() => {
57
- if (linkRef.current !== flow)
76
+ controller
77
+ .link()
78
+ .then((lf) => {
79
+ linkRef.current = lf;
80
+ setLink({ phase: 'waiting', flow: lf });
81
+ return lf.linked.then(() => {
82
+ if (linkRef.current !== lf)
58
83
  return;
59
84
  linkRef.current = null;
60
85
  setLink(null);
61
86
  // Linked: start recording exactly as if a key had been passed.
62
87
  onStartRef.current();
63
88
  }, (e) => {
64
- if (linkRef.current !== flow)
89
+ if (linkRef.current !== lf)
65
90
  return;
66
91
  linkRef.current = null;
67
- if (e instanceof LinkExpired)
68
- setLink({ phase: 'expired', flow });
69
- else if (!(e instanceof Error && e.name === 'AbortError'))
70
- setLink({ phase: 'error', flow, error: e instanceof Error ? e.message : String(e) });
92
+ const name = e instanceof Error ? e.name : '';
93
+ if (name === 'LinkExpired')
94
+ setLink({ phase: 'expired', flow: lf });
95
+ else if (name !== 'AbortError')
96
+ setLink({ phase: 'error', flow: lf, error: errorText(e) });
71
97
  });
72
98
  })
73
- .catch((e) => setLink({ phase: 'error', flow: null, error: e instanceof Error ? e.message : String(e) }));
74
- }, []);
75
- const onUnlink = useCallback(() => {
76
- closeLink();
77
- setSheet(null);
78
- setAnnotating(false);
79
- forgetLink();
80
- }, [closeLink]);
99
+ .catch((e) => setLink({ phase: 'error', flow: null, error: errorText(e) }));
100
+ }, [controller]);
81
101
  const closeSheet = useCallback(() => setSheet(null), []);
82
- // A drag closes the composer (its draft survives); the link sheet follows the dock.
83
- const dock = useDock(closeSheet);
102
+ // A drag closes the composer (its draft survives) and the menu; the link sheet follows the dock.
103
+ const onMoveStart = useCallback(() => {
104
+ setSheet(null);
105
+ setMenu(false);
106
+ }, []);
107
+ const dock = useDock(onMoveStart, storage);
84
108
  const phone = useMedia(PHONE_QUERY);
85
109
  const openNote = useCallback(() => {
86
- if (!getState())
110
+ if (!controller.getSnapshot().recording)
87
111
  return;
88
- setAnnotating(false);
112
+ controller.setAnnotating(false);
113
+ setMenu(false);
89
114
  setSheet({ title: 'Note', ctx: `step · ${location.pathname}`, pick: null });
90
- }, []);
115
+ }, [controller]);
91
116
  const toggleAnnotate = useCallback(() => {
92
- if (!getState())
117
+ const s = controller.getSnapshot();
118
+ if (!s.recording)
93
119
  return;
94
120
  setSheet(null);
95
- setAnnotating(!annotateState.active);
96
- }, []);
121
+ setMenu(false);
122
+ controller.setAnnotating(!s.annotating);
123
+ }, [controller]);
97
124
  const onPick = useCallback((pick) => {
98
- setAnnotating(false);
125
+ controller.setAnnotating(false);
99
126
  const ctx = pick.selector
100
127
  ? `${pick.selector} · ${location.pathname}`
101
128
  : `${Math.round(pick.rect.w)}×${Math.round(pick.rect.h)} · ${location.pathname}`;
102
129
  setSheet({ title: pick.selector ? 'Annotate element' : 'Annotate region', ctx, pick });
130
+ }, [controller]);
131
+ const cancelAnnotate = useCallback(() => controller.setAnnotating(false), [controller]);
132
+ const flashTimer = useRef(undefined);
133
+ const saidSaved = useCallback(() => {
134
+ clearTimeout(flashTimer.current);
135
+ setFlash(true);
136
+ flashTimer.current = setTimeout(() => setFlash(false), FLASH_MS);
103
137
  }, []);
104
- const cancelAnnotate = useCallback(() => setAnnotating(false), []);
138
+ useEffect(() => () => clearTimeout(flashTimer.current), []);
105
139
  const onSend = useCallback((text, task) => {
106
140
  const s = sheet;
107
141
  setSheet(null);
108
142
  if (!s)
109
143
  return;
110
144
  if (s.pick) {
111
- addAnnotation(text, s.pick.rect, s.pick.selector, { task });
145
+ controller.annotate({ text, rect: s.pick.rect, selector: s.pick.selector, task });
112
146
  setDraft('');
147
+ saidSaved();
113
148
  }
114
149
  else if (text) {
115
- addNote(text);
150
+ controller.note(text);
116
151
  setDraft('');
152
+ saidSaved();
117
153
  }
118
- }, [sheet]);
154
+ }, [sheet, controller, saidSaved]);
119
155
  const onStart = useCallback(() => {
120
- if (!vitrinkaLinked()) {
156
+ if (!controller.getSnapshot().linked) {
121
157
  beginLink();
122
158
  return;
123
159
  }
124
160
  setStarting(true);
125
- startSession({ title: defaultTitle() })
161
+ controller
162
+ .start({ title: defaultTitle() })
126
163
  .catch((e) => console.warn('vitrinka: start failed', e))
127
164
  .finally(() => setStarting(false));
128
- }, [defaultTitle, beginLink]);
129
- const onStartRef = useRef(onStart);
165
+ }, [controller, defaultTitle, beginLink]);
130
166
  onStartRef.current = onStart;
131
- const onStop = useCallback(() => {
167
+ const onPause = useCallback(() => {
168
+ void controller.togglePause();
169
+ }, [controller]);
170
+ // The inline flows. Stop drains first; a refusal (offline) keeps the session.
171
+ const runStop = useCallback(() => {
172
+ const t0 = Date.now();
173
+ const settle = (ev) => setTimeout(() => dispatch(ev), Math.max(0, MIN_SAVING_MS - (Date.now() - t0)));
174
+ controller.stop().then((r) => settle({ type: 'saved', ...(r.boardUrl ? { boardUrl: r.boardUrl } : {}) }), (e) => {
175
+ console.warn('vitrinka: stop —', errorText(e));
176
+ settle({ type: 'failed', message: errorText(e) });
177
+ });
178
+ }, [controller]);
179
+ const askStop = useCallback(() => {
180
+ if (!controller.getSnapshot().recording)
181
+ return;
182
+ setSheet(null);
183
+ setMenu(false);
184
+ controller.setAnnotating(false);
185
+ dispatch({ type: 'ask', action: 'stop' });
186
+ }, [controller]);
187
+ const askUnlink = useCallback(() => {
132
188
  setSheet(null);
133
- setAnnotating(false);
134
- setStopping(true);
135
- stopSession()
136
- .catch((e) => console.warn('vitrinka: stop —', e instanceof Error ? e.message : e))
137
- .finally(() => setStopping(false));
189
+ setMenu(false);
190
+ dispatch({ type: 'ask', action: 'unlink' });
138
191
  }, []);
139
- const onPause = useCallback(() => {
140
- void togglePause();
192
+ const onConfirm = useCallback(() => {
193
+ if (flow.face !== 'confirm')
194
+ return;
195
+ dispatch({ type: 'confirm', queued: controller.getSnapshot().recording?.sync.queued ?? 0 });
196
+ if (flow.action === 'stop') {
197
+ runStop();
198
+ return;
199
+ }
200
+ closeLink();
201
+ setSheet(null);
202
+ controller.setAnnotating(false);
203
+ controller.unlink();
204
+ }, [flow, controller, runStop, closeLink]);
205
+ const onCancel = useCallback(() => dispatch({ type: 'cancel' }), []);
206
+ const onDismiss = useCallback(() => dispatch({ type: 'dismiss' }), []);
207
+ const onRetry = useCallback(() => {
208
+ dispatch({ type: 'retry', queued: controller.getSnapshot().recording?.sync.queued ?? 0 });
209
+ runStop();
210
+ }, [controller, runStop]);
211
+ // A stop confirm outlives nothing: the session ended under it (401, the server).
212
+ useEffect(() => {
213
+ if (!rec && flow.face === 'confirm' && flow.action === 'stop')
214
+ dispatch({ type: 'cancel' });
215
+ }, [rec, flow]);
216
+ // Who the token is (and the user's server-side prefs): on mount and once linked.
217
+ useEffect(() => {
218
+ if (snap.linked)
219
+ void controller.getMe();
220
+ }, [snap.linked, controller]);
221
+ // A keyboard open (Enter, Space, ↓ on ⋯) moves focus to the first item, as a menu button does.
222
+ const focusMenu = useRef(false);
223
+ const toggleMenu = useCallback((byKeyboard) => {
224
+ focusMenu.current = byKeyboard;
225
+ setMenu((m) => !m);
141
226
  }, []);
227
+ useEffect(() => {
228
+ if (!menu || !focusMenu.current)
229
+ return;
230
+ focusMenu.current = false;
231
+ const raf = requestAnimationFrame(() => menuRef.current?.querySelector('[role^="menuitem"]:not([aria-disabled="true"])')?.focus({ preventScroll: true }));
232
+ return () => cancelAnimationFrame(raf);
233
+ }, [menu]);
234
+ useEffect(() => {
235
+ if (!menu)
236
+ return;
237
+ void controller.getMe();
238
+ void controller.refreshRecents();
239
+ }, [menu, controller]);
142
240
  // Shortcuts (window keydown, CAPTURE — the host's shield stops a keydown
143
241
  // from a focused HUD control before it could bubble to window, and a drag
144
- // leaves the handle focused): ⌥⇧A annotate · ⌥⇧N note · ⌥⇧P pause.
242
+ // leaves the handle focused): ⌥⇧A annotate · ⌥⇧N note · ⌥⇧P pause · ⌥⇧S stop.
145
243
  useEffect(() => {
146
244
  const key = (e) => {
147
245
  if (!e.altKey || !e.shiftKey || e.metaKey || e.ctrlKey)
@@ -152,13 +250,14 @@ export function Hud({ hostMount, defaultTitle }) {
152
250
  openNote();
153
251
  else if (e.code === 'KeyP')
154
252
  onPause();
253
+ else if (e.code === 'KeyS')
254
+ askStop();
155
255
  else
156
256
  return;
157
257
  e.preventDefault();
158
258
  };
159
- window.addEventListener('keydown', key, true);
160
- return () => window.removeEventListener('keydown', key, true);
161
- }, [toggleAnnotate, openNote, onPause]);
259
+ return listen(window, 'keydown', key, { capture: true });
260
+ }, [toggleAnnotate, openNote, onPause, askStop]);
162
261
  // Esc anywhere and click-outside close the sheet (capture-phase, so the
163
262
  // page's own dialog never sees the Esc that closed ours).
164
263
  useEffect(() => {
@@ -176,17 +275,46 @@ export function Hud({ hostMount, defaultTitle }) {
176
275
  return;
177
276
  closeSheet();
178
277
  };
179
- document.addEventListener('keydown', key, true);
278
+ const offKey = listen(document, 'keydown', key, { capture: true });
279
+ document.addEventListener('pointerdown', down, true);
280
+ return () => {
281
+ offKey();
282
+ document.removeEventListener('pointerdown', down, true);
283
+ };
284
+ }, [sheet, closeSheet]);
285
+ // The menu closes on Esc (focus back on its ⋯) and on a press outside it and the pill.
286
+ useEffect(() => {
287
+ if (!menu)
288
+ return;
289
+ const key = (e) => {
290
+ if (e.key !== 'Escape')
291
+ return;
292
+ e.preventDefault();
293
+ e.stopPropagation();
294
+ setMenu(false);
295
+ pillRef.current?.querySelector('.seg.on .b-more')?.focus();
296
+ };
297
+ const down = (e) => {
298
+ const path = e.composedPath();
299
+ if (!path.includes(menuRef.current) && !path.includes(pillRef.current))
300
+ setMenu(false);
301
+ };
302
+ const offKey = listen(document, 'keydown', key, { capture: true });
180
303
  document.addEventListener('pointerdown', down, true);
181
304
  return () => {
182
- document.removeEventListener('keydown', key, true);
305
+ offKey();
183
306
  document.removeEventListener('pointerdown', down, true);
184
307
  };
185
- }, [sheet, link, closeSheet, closeLink]);
186
- // Sheets enter and leave (presence) with their last content kept for the
187
- // closing frames.
308
+ }, [menu]);
309
+ useEffect(() => {
310
+ if (dock.dragging)
311
+ setMenu(false);
312
+ }, [dock.dragging]);
313
+ // Sheets and the menu enter and leave (presence) with their last content
314
+ // kept for the closing frames.
188
315
  const sheetP = usePresence(sheet !== null, 150);
189
316
  const linkP = usePresence(link !== null, 150);
317
+ const menuP = usePresence(menu, 150);
190
318
  const lastSheet = useRef(null);
191
319
  const lastLink = useRef(null);
192
320
  if (sheet)
@@ -207,25 +335,65 @@ export function Hud({ hostMount, defaultTitle }) {
207
335
  return { ...h, own: true };
208
336
  }, [sheetP.mounted, hostMount]);
209
337
  useEffect(() => () => portal?.destroy(), [portal]);
210
- // Where the open layer sits (D5): anchored to the dock's resting box and
211
- // opening toward the centre, or a phone bottom sheet over the visual viewport.
338
+ // Where the open layer sits (D5): beside the dock's resting box, toward the
339
+ // centre and inside the viewport, or a phone bottom sheet over the visual viewport.
212
340
  const layerOpen = sheet !== null || link !== null;
213
341
  const vvTick = useViewportTick(layerOpen && phone);
214
- const [layer, setLayer] = useState({ style: {}, origin: 'bottom-right' });
342
+ // On desktop the placement is measured, so a viewport resize or a grown
343
+ // sheet (the textarea resizes) must place it again.
344
+ const [sizeTick, setSizeTick] = useState(0);
345
+ useEffect(() => {
346
+ if (!layerOpen || phone)
347
+ return;
348
+ const bump = () => setSizeTick((n) => n + 1);
349
+ const ro = typeof ResizeObserver === 'function' ? new ResizeObserver(bump) : null;
350
+ const pop = layerRef.current?.firstElementChild;
351
+ if (ro && pop)
352
+ ro.observe(pop);
353
+ addEventListener('resize', bump);
354
+ return () => {
355
+ ro?.disconnect();
356
+ removeEventListener('resize', bump);
357
+ };
358
+ }, [layerOpen, phone, sheetP.mounted, linkP.mounted]);
359
+ const [layer, setLayer] = useState({ style: {}, origin: 'bottom right' });
215
360
  useLayoutEffect(() => {
216
361
  const el = dock.ref.current;
217
362
  if (!layerOpen || !el)
218
363
  return;
219
364
  const o = hostOrigin(sheet && portal ? portal.mount : hostMount);
220
- setLayer(phone ? { style: phoneLayer(o), origin: 'bottom-center' } : anchoredLayer(restingBox(el), dock.place, o));
221
- }, [layerOpen, sheet, portal, hostMount, dock.place, dock.ref, phone, vvTick]);
365
+ if (phone) {
366
+ setLayer({ style: phoneLayer(o), origin: 'bottom center' });
367
+ return;
368
+ }
369
+ const pop = layerRef.current?.firstElementChild;
370
+ const size = pop ? { w: pop.offsetWidth, h: pop.offsetHeight } : { w: 288, h: 200 };
371
+ setLayer(anchoredLayer(restingBox(el), size, dock.place, o));
372
+ }, [layerOpen, sheet, link?.phase, portal, hostMount, dock.place, dock.ref, phone, vvTick, sizeTick, snap.prefs.size]);
222
373
  const layerCls = phone ? 'phone' : 'anchor';
223
374
  const motionCls = phone ? 'rise' : 'grow';
224
- const sheetEl = shownSheet && portal ? (_jsxs("div", { className: "hud", children: [portal.own ? _jsx("style", { children: HUD_CSS }) : null, _jsx("div", { className: layerCls, style: layer.style, children: _jsx(Sheet, { className: `${motionCls} ${sheetP.cls}`, origin: layer.origin, title: shownSheet.title, ctx: shownSheet.ctx, pick: shownSheet.pick !== null, draft: draft, onDraft: setDraft, onSend: onSend, onClose: closeSheet }) })] })) : null;
375
+ // The floats: menu and details card beside the dock, toward the centre.
376
+ const side = towardCentre(dock.place);
377
+ const align = alignFor(dock.place);
378
+ const anchor = useCallback(() => {
379
+ const el = dock.ref.current;
380
+ return el ? { el, box: restingBox(el) } : null;
381
+ }, [dock.ref]);
382
+ useFloat(menuRef, anchor, side, align, menuP.mounted);
383
+ const tucked = 'tuck' in dock.place;
384
+ const line = rec ? healthLine(rec.sync, now) : '';
385
+ const detailOn = rec !== null && (snap.prefs.verbose || line !== '') && !menu && !layerOpen && flow.face === 'none' && !dock.dragging && !tucked;
386
+ const detailP = usePresence(detailOn, 150);
387
+ useFloat(detailRef, anchor, side, align, detailP.mounted);
388
+ const lastRec = useRef(rec);
389
+ if (rec)
390
+ lastRec.current = rec;
391
+ const detailRec = rec ?? lastRec.current;
392
+ const sheetEl = shownSheet && portal ? (_jsxs("div", { className: "hud", "data-size": snap.prefs.size, children: [portal.own ? _jsx("style", { children: HUD_CSS }) : null, _jsx("div", { ref: layerRef, className: layerCls, style: layer.style, children: _jsx(Sheet, { className: `${motionCls} ${sheetP.cls}`, origin: layer.origin, title: shownSheet.title, ctx: shownSheet.ctx, pick: shownSheet.pick !== null, draft: draft, onDraft: setDraft, onSend: onSend, onClose: closeSheet }) })] })) : null;
225
393
  // Stable phrases only: a live region re-announces on every text change.
226
- const hs = rec ? health().state : null;
394
+ const hs = rec?.sync.state ?? null;
227
395
  const status = !rec
228
- ? linked
396
+ ? snap.linked
229
397
  ? 'Recorder ready'
230
398
  : 'Recorder not linked'
231
399
  : hs === 'dead'
@@ -239,5 +407,5 @@ export function Hud({ hostMount, defaultTitle }) {
239
407
  const dockAttrs = 'tuck' in place
240
408
  ? { 'data-tuck': place.tuck, style: { '--ty': String(place.y) } }
241
409
  : { 'data-row': rowOf(place.spot), 'data-col': colOf(place.spot) };
242
- return (_jsxs("div", { className: "hud", "data-spot": 'spot' in place ? place.spot : undefined, children: [_jsx("style", { children: HUD_CSS }), annotating && rec ? _jsx(AnnotateOverlay, { onPick: onPick, onCancel: cancelAnnotate }) : null, _jsx("div", { ref: dock.ref, className: dock.dragging ? 'dock dragging' : 'dock', ...dockAttrs, onClickCapture: dock.onClickCapture, children: _jsx(RecorderPill, { rec: rec, composing: sheet !== null, annotating: annotating, stopping: stopping, starting: starting, linked: linked, canUnlink: canUnlink, place: place, dragging: dock.dragging, handle: dock.handle, onMove: dock.moveTo, onLink: beginLink, onUnlink: onUnlink, onStart: onStart, onPause: onPause, onNote: openNote, onAnnotate: toggleAnnotate, onStop: onStop }) }), sheetEl && portal ? createPortal(sheetEl, portal.mount) : null, linkP.mounted && shownLink ? (_jsx("div", { className: layerCls, style: layer.style, children: _jsx(LinkSheet, { className: `${motionCls} ${linkP.cls}`, origin: layer.origin, phase: shownLink.phase, start: shownLink.flow?.start ?? null, error: shownLink.error, onRetry: beginLink, onClose: closeLink }) })) : null, _jsx("div", { className: "sr", role: "status", "aria-live": "polite", children: status })] }));
410
+ return (_jsxs("div", { ref: rootRef, className: "hud", "data-size": snap.prefs.size, "data-spot": 'spot' in place ? place.spot : undefined, children: [_jsx("style", { children: HUD_CSS }), annotating && rec ? _jsx(AnnotateOverlay, { onPick: onPick, onCancel: cancelAnnotate }) : null, _jsx("div", { ref: dock.ref, className: dock.dragging ? 'dock dragging' : 'dock', ...dockAttrs, onClickCapture: dock.onClickCapture, children: _jsx(RecorderPill, { snap: snap, now: now, flow: flow, flash: flash, composing: sheet !== null, starting: starting, menuOpen: menu, place: place, dragging: dock.dragging, handle: dock.handle, pillRef: pillRef, onMove: dock.moveTo, onLink: beginLink, onStart: onStart, onPause: onPause, onNote: openNote, onAnnotate: toggleAnnotate, onMenu: toggleMenu, onAskStop: askStop, onConfirm: onConfirm, onCancel: onCancel, onRetry: onRetry, onDismiss: onDismiss }) }), menuP.mounted ? (_jsx(Menu, { snap: snap, now: now, place: place, className: `grow ${menuP.cls}`, menuRef: menuRef, onClose: () => setMenu(false), onMove: dock.moveTo, onSize: (size) => void controller.setPrefs({ size }), onVerbose: (verbose) => void controller.setPrefs({ verbose }), onAskUnlink: askUnlink, onLink: beginLink })) : null, _jsx(Tooltip, { root: rootRef, side: side, suppressed: dock.dragging || menu || layerOpen }), detailP.mounted && detailRec ? (_jsx("div", { ref: detailRef, className: ['float detail grow', detailP.cls, snap.prefs.verbose ? '' : 'line', line ? 'bad' : ''].filter(Boolean).join(' '), "data-e2e": "recorder-detail", "aria-hidden": "true", children: snap.prefs.verbose ? (_jsxs(_Fragment, { children: [_jsxs("dl", { children: [_jsx("dt", { children: "events" }), _jsx("dd", { children: detailRec.sync.events }), _jsx("dt", { children: "queue" }), _jsxs("dd", { children: [detailRec.sync.queued, detailRec.sync.chunks ? ` (${detailRec.sync.chunks} chunk${detailRec.sync.chunks === 1 ? '' : 's'})` : ''] }), _jsx("dt", { children: "last sync" }), _jsx("dd", { children: detailRec.sync.lastSyncAt === null ? '—' : `${fmtAgo(now - detailRec.sync.lastSyncAt)} · ${detailRec.sync.state}` }), _jsx("dt", { children: "server seq" }), _jsx("dd", { children: Math.max(0, detailRec.sync.serverMaxSeq) }), _jsx("dt", { children: "session" }), _jsx("dd", { children: detailRec.sessionId }), _jsx("dt", { children: "recorder" }), _jsx("dd", { children: snap.version })] }), line ? _jsx("div", { className: "warnline", children: line }) : null] })) : (line) })) : null, sheetEl && portal ? createPortal(sheetEl, portal.mount) : null, linkP.mounted && shownLink ? (_jsx("div", { ref: layerRef, className: layerCls, style: layer.style, children: _jsx(LinkSheet, { className: `${motionCls} ${linkP.cls}`, origin: layer.origin, phase: shownLink.phase, start: shownLink.flow?.start ?? null, error: shownLink.error, onRetry: beginLink, onClose: closeLink }) })) : null, _jsx("div", { className: "sr", role: "status", "aria-live": "polite", children: status })] }));
243
411
  }
@@ -5,15 +5,15 @@
5
5
  * Polling runs in the parent; this only paints the state.
6
6
  */
7
7
  import type { ReactElement } from 'react';
8
- import type { LinkStart } from '@vitrinka/link';
8
+ import type { HudLinkCode } from './controller';
9
9
  export type LinkPhase = 'starting' | 'waiting' | 'expired' | 'error';
10
10
  export interface LinkSheetProps {
11
11
  /** Presence classes (`grow`/`rise` + `is-open`/`is-closing`). */
12
12
  className: string;
13
- /** The corner it grows from (`bottom-right`, …). */
13
+ /** CSS transform-origin: the point nearest the dock it grows from. */
14
14
  origin: string;
15
15
  phase: LinkPhase;
16
- start: LinkStart | null;
16
+ start: HudLinkCode | null;
17
17
  error?: string;
18
18
  onRetry: () => void;
19
19
  onClose: () => void;
@@ -15,5 +15,5 @@ export const LINK_STRINGS = {
15
15
  export function LinkSheet({ className, origin, phase, start, error, onRetry, onClose }) {
16
16
  // The QR serves the desktop→phone path; a touch device cannot scan itself (D5).
17
17
  const qr = useMedia(FINE_QUERY);
18
- return (_jsxs("div", { className: `pop link ${className}`, "data-origin": origin, role: "dialog", "aria-labelledby": "vt-link-title", "data-e2e": "link-sheet", children: [_jsxs("div", { className: "pop-head", children: [_jsxs("span", { className: "title", children: [_jsx("i", {}), _jsx("span", { id: "vt-link-title", children: LINK_STRINGS.title })] }), _jsx("button", { type: "button", className: "closeb", "aria-label": "Close", onClick: onClose, children: _jsx(CloseIcon, {}) })] }), phase === 'starting' || !start ? (_jsx("div", { className: "linkline", children: phase === 'error' ? error || 'could not start the link' : LINK_STRINGS.starting })) : (_jsxs(_Fragment, { children: [_jsxs("div", { className: qr ? 'linkgrid' : 'linkgrid noqr', children: [_jsx("div", { className: "code", "data-e2e": "link-code", children: start.user_code }), _jsxs("a", { className: "sendb", href: start.verifyUrl, target: "_blank", rel: "noopener noreferrer", children: [_jsx(NewTabIcon, {}), _jsx("span", { children: LINK_STRINGS.open })] }), qr ? _jsx("img", { className: "qr", src: start.qrUrl, alt: LINK_STRINGS.qrAlt, width: 76, height: 76 }) : null] }), _jsxs("div", { className: phase === 'expired' || phase === 'error' ? 'linkline bad' : 'linkline', children: [phase === 'waiting' ? LINK_STRINGS.waiting : phase === 'expired' ? LINK_STRINGS.expired : error, phase === 'expired' || phase === 'error' ? (_jsx("button", { type: "button", className: "retry", onClick: onRetry, children: LINK_STRINGS.retry })) : null] })] })), _jsx("div", { className: "hints", children: qr ? LINK_STRINGS.hint : LINK_STRINGS.hintTouch })] }));
18
+ return (_jsxs("div", { className: `pop link ${className}`, style: { transformOrigin: origin }, role: "dialog", "aria-labelledby": "vt-link-title", "data-e2e": "link-sheet", children: [_jsxs("div", { className: "pop-head", children: [_jsxs("span", { className: "title", children: [_jsx("i", {}), _jsx("span", { id: "vt-link-title", children: LINK_STRINGS.title })] }), _jsx("button", { type: "button", className: "closeb", "aria-label": "Close", onClick: onClose, children: _jsx(CloseIcon, {}) })] }), phase === 'starting' || !start ? (_jsx("div", { className: "linkline", children: phase === 'error' ? error || 'could not start the link' : LINK_STRINGS.starting })) : (_jsxs(_Fragment, { children: [_jsxs("div", { className: qr ? 'linkgrid' : 'linkgrid noqr', children: [_jsx("div", { className: "code", "data-e2e": "link-code", children: start.user_code }), _jsxs("a", { className: "sendb", href: start.verifyUrl, target: "_blank", rel: "noopener noreferrer", children: [_jsx(NewTabIcon, {}), _jsx("span", { children: LINK_STRINGS.open })] }), qr ? _jsx("img", { className: "qr", src: start.qrUrl, alt: LINK_STRINGS.qrAlt, width: 76, height: 76 }) : null] }), _jsxs("div", { className: phase === 'expired' || phase === 'error' ? 'linkline bad' : 'linkline', children: [phase === 'waiting' ? LINK_STRINGS.waiting : phase === 'expired' ? LINK_STRINGS.expired : error, phase === 'expired' || phase === 'error' ? (_jsx("button", { type: "button", className: "retry", onClick: onRetry, children: LINK_STRINGS.retry })) : null] })] })), _jsx("div", { className: "hints", children: qr ? LINK_STRINGS.hint : LINK_STRINGS.hintTouch })] }));
19
19
  }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * The ⋯ menu: who the recorder is linked as, the open board, the device's
3
+ * recent recordings and "Go to vitrinka", then the HUD's own settings —
4
+ * size, verbose details, position (a miniature screen of the eight spots) —
5
+ * and Unlink. A fixed float placed beside the dock by the caller; ↑/↓ move
6
+ * between items, Esc closes.
7
+ */
8
+ import { type ReactElement, type RefObject } from 'react';
9
+ import type { HudAccount, HudSize, HudSnapshot } from './controller';
10
+ import { type Place } from './spots';
11
+ /** The account line: `lukas@… · ADF`, or the key build's `Recorder key · <name> · project <p>`. */
12
+ export declare function accountLines(account: HudAccount | null, linked: boolean): {
13
+ who: string;
14
+ ws: string;
15
+ sub: string;
16
+ };
17
+ export interface MenuProps {
18
+ snap: HudSnapshot;
19
+ now: number;
20
+ place: Place;
21
+ className: string;
22
+ menuRef: RefObject<HTMLDivElement | null>;
23
+ onClose: () => void;
24
+ onMove: (place: Place) => void;
25
+ onSize: (size: HudSize) => void;
26
+ onVerbose: (on: boolean) => void;
27
+ onAskUnlink: () => void;
28
+ onLink: () => void;
29
+ }
30
+ export declare function Menu(p: MenuProps): ReactElement;
@@ -0,0 +1,73 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { HomeIcon, NewTabIcon, UnlinkIcon } from './icons';
3
+ import { isVertical, SPOT_NAMES, SPOTS } from './spots';
4
+ import { fmtAgo, fmtDuration } from './status';
5
+ const SIZES = [
6
+ { size: 'sm', label: 'S', name: 'Small' },
7
+ { size: 'md', label: 'M', name: 'Medium' },
8
+ { size: 'lg', label: 'L', name: 'Large' },
9
+ ];
10
+ const STATUS_WORDS = { recording: 'recording', saved: 'saved', unsaved: 'not stopped', deleted: 'deleted' };
11
+ /** The account line: `lukas@… · ADF`, or the key build's `Recorder key · <name> · project <p>`. */
12
+ export function accountLines(account, linked) {
13
+ if (!linked)
14
+ return { who: 'Not linked', ws: '', sub: 'Link this device to record' };
15
+ if (!account)
16
+ return { who: 'Linked device', ws: '', sub: 'checking who this is…' };
17
+ if (account.kind === 'key') {
18
+ const bits = ['Recorder key', account.label, account.project ? `project ${account.project}` : null].filter(Boolean);
19
+ return { who: bits.join(' · '), ws: '', sub: account.workspace.name };
20
+ }
21
+ return {
22
+ who: account.user?.email || account.user?.name || 'Linked device',
23
+ ws: account.workspace.name,
24
+ sub: account.label ? `this device · ${account.label}` : 'this device',
25
+ };
26
+ }
27
+ export function Menu(p) {
28
+ const { snap } = p;
29
+ const lines = accountLines(snap.account, snap.linked);
30
+ const current = 'spot' in p.place ? p.place.spot : null;
31
+ const rec = snap.recording;
32
+ const sizeIndex = SIZES.findIndex((s) => s.size === snap.prefs.size);
33
+ // ↑/↓ walk the items (radios included); Home/End jump.
34
+ const onKey = (e) => {
35
+ if (!['ArrowDown', 'ArrowUp', 'Home', 'End'].includes(e.key))
36
+ return;
37
+ const items = [...e.currentTarget.querySelectorAll('[role^="menuitem"]:not([aria-disabled="true"])')];
38
+ if (!items.length)
39
+ return;
40
+ e.preventDefault();
41
+ e.stopPropagation();
42
+ const root = e.currentTarget.getRootNode();
43
+ const at = items.indexOf(root.activeElement);
44
+ const next = e.key === 'Home' ? 0 : e.key === 'End' ? items.length - 1 : (at + (e.key === 'ArrowDown' ? 1 : -1) + items.length) % items.length;
45
+ items[next]?.focus();
46
+ };
47
+ const act = (fn) => () => {
48
+ p.onClose();
49
+ fn();
50
+ };
51
+ return (_jsxs("div", { ref: p.menuRef, className: `float menu ${p.className}`, role: "menu", "aria-label": "Recorder", "data-e2e": "recorder-menu", onKeyDown: onKey, children: [_jsxs("div", { className: "m-head", "data-e2e": "menu-account", children: [_jsxs("div", { className: snap.account?.kind === 'key' ? 'm-who wraps' : 'm-who', children: [_jsx("span", { className: "email", children: lines.who }), lines.ws ? _jsxs("span", { className: "ws", children: ["\u00B7 ", lines.ws] }) : null] }), _jsxs("div", { className: "m-sub", children: [rec ? _jsx("span", { className: "live", children: "\u25CF recording \u00B7 " }) : null, lines.sub] })] }), !snap.linked ? (_jsx("button", { type: "button", role: "menuitem", className: "mi", onClick: act(p.onLink), children: _jsx("span", { children: "Link recorder" }) })) : null, rec?.boardUrl ? (_jsxs("a", { role: "menuitem", className: "mi", href: rec.boardUrl, target: "_blank", rel: "noopener noreferrer", onClick: p.onClose, children: [_jsx(NewTabIcon, {}), " Open this board"] })) : null, _jsx("div", { className: "m-rule" }), _jsx("div", { className: "m-label", "aria-hidden": "true", children: "Recent" }), snap.recents.length === 0 ? _jsx("div", { className: "m-empty", children: "No recordings on this device yet" }) : null, snap.recents.map((r) => {
52
+ const live = rec?.sessionId === r.sessionId;
53
+ const meta = [
54
+ live ? 'now' : fmtAgo(p.now - r.startedAt),
55
+ r.durationMs !== undefined ? fmtDuration(r.durationMs) : null,
56
+ live ? 'recording' : STATUS_WORDS[r.status],
57
+ ].filter(Boolean);
58
+ const status = live ? 'recording' : r.status;
59
+ const body = (_jsxs(_Fragment, { children: [_jsxs("span", { className: "r-main", children: [_jsx("span", { className: "r-title", children: r.title || 'Untitled recording' }), _jsxs("span", { className: "r-meta", children: [_jsx("i", { "data-status": status }), meta.join(' · ')] })] }), r.boardUrl ? (_jsx("span", { className: "end", children: _jsx(NewTabIcon, {}) })) : null] }));
60
+ return r.boardUrl ? (_jsx("a", { role: "menuitem", className: "mi recent", href: r.boardUrl, target: "_blank", rel: "noopener noreferrer", onClick: p.onClose, "data-e2e": "recent", children: body }, r.sessionId)) : (_jsx("div", { role: "menuitem", "aria-disabled": "true", className: "mi recent", "data-e2e": "recent", children: body }, r.sessionId));
61
+ }), _jsxs("a", { role: "menuitem", className: "mi", href: snap.workspaceUrl, target: "_blank", rel: "noopener noreferrer", onClick: p.onClose, children: [_jsx(HomeIcon, {}), " Go to vitrinka", _jsx("span", { className: "end", children: _jsx(NewTabIcon, {}) })] }), _jsx("div", { className: "m-rule" }), _jsxs("div", { className: "m-row", children: [_jsx("span", { id: "vt-size", children: "Size" }), _jsx("span", { className: "sizes", role: "group", "aria-labelledby": "vt-size", style: { '--i': String(Math.max(0, sizeIndex)) }, children: SIZES.map((s) => (_jsx("button", { type: "button", role: "menuitemradio", "aria-checked": snap.prefs.size === s.size, "aria-label": `Size ${s.name}`, onClick: () => p.onSize(s.size), children: s.label }, s.size))) })] }), _jsxs("div", { className: "m-row toggle", role: "menuitemcheckbox", "aria-checked": snap.prefs.verbose, tabIndex: 0, onClick: () => p.onVerbose(!snap.prefs.verbose), onKeyDown: (e) => {
62
+ if (e.key !== 'Enter' && e.key !== ' ')
63
+ return;
64
+ e.preventDefault();
65
+ p.onVerbose(!snap.prefs.verbose);
66
+ }, children: [_jsx("span", { children: "Technical details" }), _jsx("span", { className: "switch", "data-on": String(snap.prefs.verbose) })] }), _jsxs("div", { className: "m-row", children: [_jsx("span", { id: "vt-move", children: "Position" }), _jsx("span", { className: "screen", role: "group", "aria-labelledby": "vt-move", children: SPOTS.map((s) => (_jsx("button", { type: "button", role: "menuitemradio", "aria-checked": current === s, "aria-label": `Move to ${SPOT_NAMES[s]}`, "data-v": isVertical(s) ? '' : undefined, style: gridCell(s), onClick: act(() => p.onMove({ spot: s })) }, s))) })] }), snap.canUnlink ? (_jsxs(_Fragment, { children: [_jsx("div", { className: "m-rule" }), _jsxs("button", { type: "button", role: "menuitem", className: "mi danger", onClick: act(p.onAskUnlink), children: [_jsx(UnlinkIcon, {}), " Unlink this device"] })] })) : null, snap.prefs.verbose ? _jsx("div", { className: "m-foot", children: snap.version }) : null] }));
67
+ }
68
+ /** The cell a spot takes in the 3×3 miniature (the centre stays empty). */
69
+ function gridCell(s) {
70
+ const row = { t: 1, m: 2, b: 3 }[s[0]];
71
+ const col = { l: 1, c: 2, r: 3 }[s[1]];
72
+ return { gridRow: row, gridColumn: col };
73
+ }