@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
@@ -0,0 +1,94 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * The HUD's one tooltip (transitions.dev 17): any element carrying
4
+ * `data-tip` (and optionally `data-keys`, the shortcut) under `root` shows it
5
+ * on mouse hover or keyboard focus. It is a fixed float placed by place.ts —
6
+ * toward the page centre from the dock, flipped and shifted into the
7
+ * viewport — so it never clips at the pill's or the screen's edge. The first
8
+ * appearance waits a beat (CSS); moving to a neighbour while it shows makes
9
+ * the bubble travel; leaving hides it at once. Visual only (`aria-hidden`):
10
+ * every trigger already carries its accessible name and `aria-keyshortcuts`.
11
+ */
12
+ import { useEffect, useLayoutEffect, useRef, useState } from 'react';
13
+ import { placeFloating } from './place';
14
+ function triggerOf(t) {
15
+ return t instanceof Element ? t.closest('[data-tip]') : null;
16
+ }
17
+ export function Tooltip({ root, side, suppressed }) {
18
+ const [target, setTarget] = useState(null);
19
+ const tipRef = useRef(null);
20
+ const showing = useRef(false);
21
+ useEffect(() => {
22
+ const r = root.current;
23
+ if (!r)
24
+ return;
25
+ const over = (e) => {
26
+ if (e.pointerType !== 'mouse')
27
+ return;
28
+ const t = triggerOf(e.target);
29
+ if (t)
30
+ setTarget(t);
31
+ };
32
+ const out = (e) => {
33
+ const t = triggerOf(e.target);
34
+ if (!t)
35
+ return;
36
+ const to = e.relatedTarget;
37
+ if (to instanceof Node && t.contains(to))
38
+ return;
39
+ if (!triggerOf(to))
40
+ setTarget(null);
41
+ };
42
+ const focusIn = (e) => {
43
+ const t = triggerOf(e.target);
44
+ if (t?.matches(':focus-visible'))
45
+ setTarget(t);
46
+ };
47
+ const hide = () => setTarget(null);
48
+ r.addEventListener('pointerover', over);
49
+ r.addEventListener('pointerout', out);
50
+ r.addEventListener('focusin', focusIn);
51
+ r.addEventListener('focusout', hide);
52
+ r.addEventListener('pointerdown', hide, true);
53
+ return () => {
54
+ r.removeEventListener('pointerover', over);
55
+ r.removeEventListener('pointerout', out);
56
+ r.removeEventListener('focusin', focusIn);
57
+ r.removeEventListener('focusout', hide);
58
+ r.removeEventListener('pointerdown', hide, true);
59
+ };
60
+ }, [root]);
61
+ const text = target?.dataset.tip ?? '';
62
+ const keys = target?.dataset.keys ?? '';
63
+ // A trigger inside a folded segment (the tray closing) has nothing to explain.
64
+ const visible = target !== null && text !== '' && !suppressed && target.isConnected && !target.closest('.seg:not(.on)');
65
+ useLayoutEffect(() => {
66
+ const tip = tipRef.current;
67
+ if (!tip)
68
+ return;
69
+ if (!visible || !target) {
70
+ tip.dataset.show = 'false';
71
+ showing.current = false;
72
+ return;
73
+ }
74
+ const r = target.getBoundingClientRect();
75
+ const p = placeFloating({ x: r.left, y: r.top, w: r.width, h: r.height }, { w: tip.offsetWidth, h: tip.offsetHeight }, { w: innerWidth, h: innerHeight }, side, { gap: 8, margin: 6 });
76
+ const at = `${Math.round(p.x)}px ${Math.round(p.y)}px`;
77
+ if (!showing.current) {
78
+ // Hidden: snap the geometry under the trigger so only the appear plays.
79
+ tip.classList.add('snap');
80
+ tip.style.translate = at;
81
+ tip.style.transformOrigin = p.origin;
82
+ void tip.offsetWidth;
83
+ tip.classList.remove('snap');
84
+ }
85
+ else {
86
+ tip.style.translate = at;
87
+ tip.style.transformOrigin = p.origin;
88
+ }
89
+ tip.dataset.side = p.side;
90
+ tip.dataset.show = 'true';
91
+ showing.current = true;
92
+ }, [visible, target, text, keys, side]);
93
+ return (_jsxs("div", { ref: tipRef, className: "float tip", "aria-hidden": "true", "data-show": "false", "data-e2e": "tooltip", children: [_jsx("span", { children: text }), keys ? _jsx("kbd", { children: keys }) : null] }));
94
+ }
@@ -0,0 +1,148 @@
1
+ /**
2
+ * The HUD's seam: everything the pill shows comes from a `HudController`
3
+ * snapshot, and everything it does goes through the controller's actions. The
4
+ * in-page recorder supplies one (`recorder/page-controller.ts`); the browser
5
+ * extension can mount the same HUD with its own (`@vitrinka/web/hud`,
6
+ * `build/hud.iife.js`). DOM-free and React-free: only plain data crosses.
7
+ *
8
+ * Contract:
9
+ * - `getSnapshot()` returns the SAME object until something changed
10
+ * (`useSyncExternalStore` semantics); `subscribe` calls back after a change.
11
+ * Time-varying values ride as timestamps, so the HUD's own clock tick never
12
+ * needs a new snapshot.
13
+ * - Actions reject with an `Error` the HUD shows verbatim (`stop` while the
14
+ * server is unreachable, a failed start). A link flow's `linked` rejects
15
+ * with an error NAMED `LinkExpired` or `AbortError` for those two outcomes.
16
+ */
17
+ export type HudSize = 'sm' | 'md' | 'lg';
18
+ export interface HudPrefs {
19
+ size: HudSize;
20
+ /** Technical details (events, queue, last sync, session id, version). */
21
+ verbose: boolean;
22
+ }
23
+ /** Who the recorder token belongs to (`GET /api/v1/recorder/me`). */
24
+ export interface HudAccount {
25
+ /** `linked` = a device link (a user); `key` = an admin-minted recorder key. */
26
+ kind: 'linked' | 'key';
27
+ workspace: {
28
+ slug: string;
29
+ name: string;
30
+ };
31
+ user: {
32
+ email: string;
33
+ name: string;
34
+ } | null;
35
+ project: string | null;
36
+ label: string | null;
37
+ }
38
+ export type HudSyncState = 'ok' | 'backlog' | 'offline' | 'dead';
39
+ /** Delivery health of the live session — honest: `synced` is the server's word. */
40
+ export interface HudSync {
41
+ state: HudSyncState;
42
+ synced: boolean;
43
+ /** Items (events + rrweb chunks) not yet delivered. */
44
+ queued: number;
45
+ /** Of those, rrweb chunks. */
46
+ chunks: number;
47
+ failures: number;
48
+ error: string;
49
+ /** Epoch ms of the last confirmed delivery or reconcile; null before any. */
50
+ lastSyncAt: number | null;
51
+ /** Events allocated so far (the local seq). */
52
+ events: number;
53
+ serverMaxSeq: number;
54
+ deadReason: string;
55
+ }
56
+ export interface HudRecording {
57
+ sessionId: string;
58
+ title: string;
59
+ /** Server-minted board link; opened verbatim. */
60
+ boardUrl?: string;
61
+ paused: boolean;
62
+ /** The server stopped accepting this session; Stop completes locally. */
63
+ dead: boolean;
64
+ /** Elapsed = activeMs + (now - resumedAt) while running. */
65
+ activeMs: number;
66
+ /** Epoch ms the clock last resumed; null while paused or dead. */
67
+ resumedAt: number | null;
68
+ sync: HudSync;
69
+ }
70
+ export type HudRecentStatus = 'recording' | 'saved' | 'unsaved' | 'deleted';
71
+ /** One of the device's last recordings. */
72
+ export interface HudRecent {
73
+ sessionId: string;
74
+ title: string;
75
+ startedAt: number;
76
+ durationMs?: number;
77
+ status: HudRecentStatus;
78
+ boardUrl?: string;
79
+ }
80
+ export interface HudSnapshot {
81
+ /** Something to authenticate with (an explicit key or a stored link). */
82
+ linked: boolean;
83
+ /** A stored link can be forgotten; an explicit key cannot. */
84
+ canUnlink: boolean;
85
+ /** Annotate mode owns the page pointer (the click lane ignores it). */
86
+ annotating: boolean;
87
+ recording: HudRecording | null;
88
+ /** Null until `getMe` answered (or when the server is too old for it). */
89
+ account: HudAccount | null;
90
+ prefs: HudPrefs;
91
+ /** Newest first, at most five. */
92
+ recents: readonly HudRecent[];
93
+ /** "Go to vitrinka": the configured workspace URL. */
94
+ workspaceUrl: string;
95
+ /** Recorder id, e.g. `web/0.2.1` (verbose mode shows it). */
96
+ version: string;
97
+ }
98
+ /** The code half of a device link, as the link sheet paints it. */
99
+ export interface HudLinkCode {
100
+ user_code: string;
101
+ verifyUrl: string;
102
+ qrUrl: string;
103
+ }
104
+ export interface HudLinkFlow {
105
+ start: HudLinkCode;
106
+ /** Resolves once approved (the token is stored by then). */
107
+ linked: Promise<void>;
108
+ cancel: () => void;
109
+ }
110
+ /** A viewport rect in CSS pixels. */
111
+ export interface HudRect {
112
+ x: number;
113
+ y: number;
114
+ w: number;
115
+ h: number;
116
+ }
117
+ export interface HudAnnotation {
118
+ text: string;
119
+ rect: HudRect;
120
+ /** '' for a free region. */
121
+ selector: string;
122
+ /** Also file it as an intake task. */
123
+ task: boolean;
124
+ }
125
+ export interface HudController {
126
+ getSnapshot(): HudSnapshot;
127
+ subscribe(listener: () => void): () => void;
128
+ start(opts: {
129
+ title: string;
130
+ }): Promise<void>;
131
+ togglePause(): Promise<void>;
132
+ /** Drains, then closes the session; rejects (session kept) while unreachable. */
133
+ stop(): Promise<{
134
+ boardUrl?: string;
135
+ }>;
136
+ note(text: string): void;
137
+ annotate(a: HudAnnotation): void;
138
+ setAnnotating(active: boolean): void;
139
+ link(): Promise<HudLinkFlow>;
140
+ unlink(): void;
141
+ /** Refresh `account` (and server prefs); null when unknown. Never rejects. */
142
+ getMe(): Promise<HudAccount | null>;
143
+ /** Apply locally at once, then persist where the server keeps prefs. Never rejects. */
144
+ setPrefs(patch: Partial<HudPrefs>): Promise<void>;
145
+ /** Fill missing board links of recents from the server. Never rejects. */
146
+ refreshRecents(): Promise<void>;
147
+ }
148
+ export declare const DEFAULT_PREFS: HudPrefs;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The HUD's seam: everything the pill shows comes from a `HudController`
3
+ * snapshot, and everything it does goes through the controller's actions. The
4
+ * in-page recorder supplies one (`recorder/page-controller.ts`); the browser
5
+ * extension can mount the same HUD with its own (`@vitrinka/web/hud`,
6
+ * `build/hud.iife.js`). DOM-free and React-free: only plain data crosses.
7
+ *
8
+ * Contract:
9
+ * - `getSnapshot()` returns the SAME object until something changed
10
+ * (`useSyncExternalStore` semantics); `subscribe` calls back after a change.
11
+ * Time-varying values ride as timestamps, so the HUD's own clock tick never
12
+ * needs a new snapshot.
13
+ * - Actions reject with an `Error` the HUD shows verbatim (`stop` while the
14
+ * server is unreachable, a failed start). A link flow's `linked` rejects
15
+ * with an error NAMED `LinkExpired` or `AbortError` for those two outcomes.
16
+ */
17
+ export const DEFAULT_PREFS = { size: 'md', verbose: false };
@@ -0,0 +1,54 @@
1
+ /**
2
+ * The pill's inline flows — what it says when it is not just a recorder:
3
+ *
4
+ * none ─ask(stop)→ confirm ─confirm→ saving ─saved→ saved ─dismiss→ none
5
+ * │ └─failed→ failed ─retry→ saving
6
+ * └─cancel→ none └─dismiss→ none
7
+ * none ─ask(unlink)→ confirm ─confirm→ none (the caller unlinks)
8
+ *
9
+ * Saved stays until the tester dismisses it. A pure reducer, so the HUD's
10
+ * transitions are testable without a DOM; an event that does not apply to
11
+ * the current state leaves it unchanged.
12
+ */
13
+ export type ConfirmAction = 'stop' | 'unlink';
14
+ export type Flow = {
15
+ face: 'none';
16
+ } | {
17
+ face: 'confirm';
18
+ action: ConfirmAction;
19
+ }
20
+ /** `total` = items queued when the save began (0 = nothing to drain). */
21
+ | {
22
+ face: 'saving';
23
+ total: number;
24
+ } | {
25
+ face: 'saved';
26
+ boardUrl?: string;
27
+ } | {
28
+ face: 'failed';
29
+ message: string;
30
+ };
31
+ export type FlowEvent = {
32
+ type: 'ask';
33
+ action: ConfirmAction;
34
+ } | {
35
+ type: 'cancel';
36
+ } | {
37
+ type: 'confirm';
38
+ queued: number;
39
+ } | {
40
+ type: 'retry';
41
+ queued: number;
42
+ } | {
43
+ type: 'saved';
44
+ boardUrl?: string;
45
+ } | {
46
+ type: 'failed';
47
+ message: string;
48
+ } | {
49
+ type: 'dismiss';
50
+ };
51
+ export declare const NO_FLOW: Flow;
52
+ export declare function flowReducer(flow: Flow, ev: FlowEvent): Flow;
53
+ /** Save progress 0…1 while draining `total` items of which `queued` remain; null = indeterminate. */
54
+ export declare function saveProgress(flow: Flow, queued: number): number | null;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * The pill's inline flows — what it says when it is not just a recorder:
3
+ *
4
+ * none ─ask(stop)→ confirm ─confirm→ saving ─saved→ saved ─dismiss→ none
5
+ * │ └─failed→ failed ─retry→ saving
6
+ * └─cancel→ none └─dismiss→ none
7
+ * none ─ask(unlink)→ confirm ─confirm→ none (the caller unlinks)
8
+ *
9
+ * Saved stays until the tester dismisses it. A pure reducer, so the HUD's
10
+ * transitions are testable without a DOM; an event that does not apply to
11
+ * the current state leaves it unchanged.
12
+ */
13
+ export const NO_FLOW = { face: 'none' };
14
+ export function flowReducer(flow, ev) {
15
+ switch (ev.type) {
16
+ case 'ask':
17
+ return flow.face === 'none' ? { face: 'confirm', action: ev.action } : flow;
18
+ case 'cancel':
19
+ return flow.face === 'confirm' ? NO_FLOW : flow;
20
+ case 'confirm':
21
+ if (flow.face !== 'confirm')
22
+ return flow;
23
+ return flow.action === 'stop' ? { face: 'saving', total: ev.queued } : NO_FLOW;
24
+ case 'retry':
25
+ return flow.face === 'failed' ? { face: 'saving', total: ev.queued } : flow;
26
+ case 'saved':
27
+ return flow.face === 'saving' ? { face: 'saved', ...(ev.boardUrl ? { boardUrl: ev.boardUrl } : {}) } : flow;
28
+ case 'failed':
29
+ return flow.face === 'saving' ? { face: 'failed', message: ev.message } : flow;
30
+ case 'dismiss':
31
+ return flow.face === 'saved' || flow.face === 'failed' ? NO_FLOW : flow;
32
+ }
33
+ }
34
+ /** Save progress 0…1 while draining `total` items of which `queued` remain; null = indeterminate. */
35
+ export function saveProgress(flow, queued) {
36
+ if (flow.face !== 'saving' || flow.total <= 0)
37
+ return null;
38
+ return Math.min(1, Math.max(0, 1 - queued / flow.total));
39
+ }
@@ -11,7 +11,7 @@
11
11
  * would close the very dialog being reported. Bubble-phase stops on the host
12
12
  * — no preventDefault, so buttons and the textarea still focus.
13
13
  */
14
- import { RRWEB_BLOCK_ATTR } from '../capture/rrweb';
14
+ import { RRWEB_BLOCK_ATTR } from '../block';
15
15
  import { HOST_STYLE, SHEET_HOST_STYLE } from './styles';
16
16
  const SHIELDED = [
17
17
  'pointerdown', 'pointerup', 'pointermove', 'pointerover', 'pointerout', 'pointercancel',
@@ -13,3 +13,10 @@ export declare function ArrowUpIcon(): ReactElement;
13
13
  export declare function MoreIcon(): ReactElement;
14
14
  export declare function NewTabIcon(): ReactElement;
15
15
  export declare function StopIcon(): ReactElement;
16
+ export declare function CircleCheckIcon(): ReactElement;
17
+ export declare function CloudOffIcon(): ReactElement;
18
+ export declare function AlertIcon(): ReactElement;
19
+ /** A ring with a gap; spun by `.spin`. */
20
+ export declare function SpinnerIcon(): ReactElement;
21
+ export declare function UnlinkIcon(): ReactElement;
22
+ export declare function HomeIcon(): ReactElement;
@@ -38,3 +38,22 @@ export function NewTabIcon() {
38
38
  export function StopIcon() {
39
39
  return (_jsx("svg", { ...base, children: _jsx("rect", { x: "5", y: "5", width: "14", height: "14", rx: "2" }) }));
40
40
  }
41
+ export function CircleCheckIcon() {
42
+ return (_jsxs("svg", { ...base, children: [_jsx("circle", { cx: "12", cy: "12", r: "10" }), _jsx("path", { d: "m8 12.5 2.5 2.5L16 9.5" })] }));
43
+ }
44
+ export function CloudOffIcon() {
45
+ return (_jsxs("svg", { ...base, children: [_jsx("path", { d: "m2 2 20 20" }), _jsx("path", { d: "M5.8 8.1A6 6 0 0 0 8 19h9.5a4.5 4.5 0 0 0 1.9-.4" }), _jsx("path", { d: "M21.5 15.6A4.5 4.5 0 0 0 17.5 10a6 6 0 0 0-7.4-3.8" })] }));
46
+ }
47
+ export function AlertIcon() {
48
+ return (_jsxs("svg", { ...base, children: [_jsx("path", { d: "m21.7 18-8-14a2 2 0 0 0-3.4 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.7-3z" }), _jsx("path", { d: "M12 9v4" }), _jsx("path", { d: "M12 17h.01" })] }));
49
+ }
50
+ /** A ring with a gap; spun by `.spin`. */
51
+ export function SpinnerIcon() {
52
+ return (_jsx("svg", { ...base, className: "spinner spin", children: _jsx("circle", { cx: "12", cy: "12", r: "10" }) }));
53
+ }
54
+ export function UnlinkIcon() {
55
+ return (_jsxs("svg", { ...base, children: [_jsx("path", { d: "m18.8 12.7 1.7-1.7a5 5 0 0 0-7.1-7.1l-1.7 1.7" }), _jsx("path", { d: "m5.2 11.3-1.7 1.7a5 5 0 0 0 7.1 7.1l1.7-1.7" }), _jsx("path", { d: "M8 2v3" }), _jsx("path", { d: "M2 8h3" }), _jsx("path", { d: "M16 22v-3" }), _jsx("path", { d: "M22 16h-3" })] }));
56
+ }
57
+ export function HomeIcon() {
58
+ return (_jsxs("svg", { ...base, children: [_jsx("path", { d: "M3 10.5 12 3l9 7.5" }), _jsx("path", { d: "M5 9v11h14V9" })] }));
59
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Entry of `build/hud.iife.js`: the HUD as one self-contained script (React
3
+ * bundled in, no imports) for hosts without a bundler — the browser
4
+ * extension's content script. It defines `globalThis.VitrinkaHud`:
5
+ *
6
+ * const unmount = VitrinkaHud.mount(controller, { title: () => document.title });
7
+ *
8
+ * `controller` implements `HudController` (`@vitrinka/web/hud` types).
9
+ */
10
+ import { mountRecorderHud } from './mount';
11
+ export interface VitrinkaHudGlobal {
12
+ mount: typeof mountRecorderHud;
13
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Entry of `build/hud.iife.js`: the HUD as one self-contained script (React
3
+ * bundled in, no imports) for hosts without a bundler — the browser
4
+ * extension's content script. It defines `globalThis.VitrinkaHud`:
5
+ *
6
+ * const unmount = VitrinkaHud.mount(controller, { title: () => document.title });
7
+ *
8
+ * `controller` implements `HudController` (`@vitrinka/web/hud` types).
9
+ */
10
+ import { mountRecorderHud } from './mount';
11
+ globalThis.VitrinkaHud = { mount: mountRecorderHud };
@@ -1,14 +1,16 @@
1
1
  /**
2
2
  * Where a sheet opens and how it enters and leaves (recorder-hud-subtle D5).
3
3
  * On desktop and tablet a sheet is a popover anchored to the dock, opening
4
- * toward the viewport centre from whichever spot the dock rests on; on a
4
+ * toward the viewport centre from whichever spot the dock rests on (place.ts:
5
+ * sideways from a vertical dock, never past a viewport edge); on a
5
6
  * phone (narrow + coarse pointer) it is a bottom sheet over the visual
6
7
  * viewport, so it rides above the on-screen keyboard. Coordinates are
7
8
  * relative to the sheet host's own origin box, which may sit inside a
8
9
  * transformed dialog.
9
10
  */
10
- import { type Place } from '@vitrinka/link/dock';
11
- import { type CSSProperties } from 'react';
11
+ import { type CSSProperties, type RefObject } from 'react';
12
+ import { type FloatAlign, type FloatSide } from './place';
13
+ import type { Place } from './spots';
12
14
  export declare const PHONE_QUERY = "(max-width: 640px) and (pointer: coarse)";
13
15
  export declare const FINE_QUERY = "(pointer: fine)";
14
16
  /** A live media query (false where matchMedia is missing). */
@@ -30,15 +32,26 @@ export interface Box {
30
32
  right: number;
31
33
  bottom: number;
32
34
  }
33
- /** The dock's resting box — layout only, so a spring in flight does not skew the anchor. */
35
+ /**
36
+ * The dock's resting box in viewport px — its rect minus the translate it is
37
+ * springing through (the FLIP), so an anchor never chases a settle in flight.
38
+ */
34
39
  export declare function restingBox(el: HTMLElement): Box;
35
40
  /** The viewport position of the host a sheet renders in (its 0×0 origin box). */
36
41
  export declare function hostOrigin(mount: HTMLElement): {
37
42
  x: number;
38
43
  y: number;
39
44
  };
40
- /** A popover anchored to the dock, growing from the corner nearest it. */
41
- export declare function anchoredLayer(dock: Box, place: Place, origin: {
45
+ /**
46
+ * A popover anchored to the dock: toward the page centre (sideways from a
47
+ * vertical or tucked dock), flush with the dock's outer edge, flipped and
48
+ * shifted so the measured `size` never leaves the viewport; it grows from
49
+ * the point nearest the dock.
50
+ */
51
+ export declare function anchoredLayer(dock: Box, size: {
52
+ w: number;
53
+ h: number;
54
+ }, place: Place, origin: {
42
55
  x: number;
43
56
  y: number;
44
57
  }): {
@@ -50,3 +63,13 @@ export declare function phoneLayer(origin: {
50
63
  x: number;
51
64
  y: number;
52
65
  }): CSSProperties;
66
+ /**
67
+ * Keep a fixed float beside its anchor: placed on every commit, on a size
68
+ * change of either (the tray unfolding, a recents list loading) and on a
69
+ * viewport resize. Writes the style directly — no state, no re-render.
70
+ * `anchor` returns the box to sit beside (viewport px) or null to skip.
71
+ */
72
+ export declare function useFloat(float: RefObject<HTMLElement | null>, anchor: () => {
73
+ el: HTMLElement;
74
+ box: Box;
75
+ } | null, side: FloatSide, align: FloatAlign, active: boolean): void;
@@ -1,14 +1,15 @@
1
1
  /**
2
2
  * Where a sheet opens and how it enters and leaves (recorder-hud-subtle D5).
3
3
  * On desktop and tablet a sheet is a popover anchored to the dock, opening
4
- * toward the viewport centre from whichever spot the dock rests on; on a
4
+ * toward the viewport centre from whichever spot the dock rests on (place.ts:
5
+ * sideways from a vertical dock, never past a viewport edge); on a
5
6
  * phone (narrow + coarse pointer) it is a bottom sheet over the visual
6
7
  * viewport, so it rides above the on-screen keyboard. Coordinates are
7
8
  * relative to the sheet host's own origin box, which may sit inside a
8
9
  * transformed dialog.
9
10
  */
10
- import { colOf, rowOf, untuck } from '@vitrinka/link/dock';
11
- import { useEffect, useState, useSyncExternalStore } from 'react';
11
+ import { useCallback, useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore, } from 'react';
12
+ import { alignFor, placeFloating, towardCentre } from './place';
12
13
  export const PHONE_QUERY = '(max-width: 640px) and (pointer: coarse)';
13
14
  export const FINE_QUERY = '(pointer: fine)';
14
15
  /** A live media query (false where matchMedia is missing). */
@@ -67,11 +68,21 @@ export function usePresence(open, closeMs) {
67
68
  }, [open, closeMs]);
68
69
  return { mounted: open || mounted, cls };
69
70
  }
70
- /** The dock's resting box — layout only, so a spring in flight does not skew the anchor. */
71
+ /**
72
+ * The dock's resting box in viewport px — its rect minus the translate it is
73
+ * springing through (the FLIP), so an anchor never chases a settle in flight.
74
+ */
71
75
  export function restingBox(el) {
72
- const left = el.offsetLeft;
73
- const top = el.offsetTop;
74
- return { left, top, right: left + el.offsetWidth, bottom: top + el.offsetHeight };
76
+ const r = el.getBoundingClientRect();
77
+ const t = getComputedStyle(el).transform;
78
+ let dx = 0;
79
+ let dy = 0;
80
+ if (t && t !== 'none' && typeof DOMMatrixReadOnly === 'function') {
81
+ const m = new DOMMatrixReadOnly(t);
82
+ dx = m.m41;
83
+ dy = m.m42;
84
+ }
85
+ return { left: r.left - dx, top: r.top - dy, right: r.right - dx, bottom: r.bottom - dy };
75
86
  }
76
87
  /** The viewport position of the host a sheet renders in (its 0×0 origin box). */
77
88
  export function hostOrigin(mount) {
@@ -82,32 +93,15 @@ export function hostOrigin(mount) {
82
93
  const r = host.getBoundingClientRect();
83
94
  return { x: r.left, y: r.top };
84
95
  }
85
- const GAP = 8;
86
- /** A popover anchored to the dock, growing from the corner nearest it. */
87
- export function anchoredLayer(dock, place, origin) {
88
- const spot = untuck(place);
89
- const row = rowOf(spot);
90
- const col = colOf(spot);
91
- let ax;
92
- let tx;
93
- let ay;
94
- let ty;
95
- if ('tuck' in place) {
96
- ax = place.tuck === 'left' ? dock.right + GAP : dock.left - GAP;
97
- tx = place.tuck === 'left' ? '0' : '-100%';
98
- ay = row === 't' ? dock.top : dock.bottom;
99
- ty = row === 't' ? '0' : '-100%';
100
- }
101
- else {
102
- ax = col === 'l' ? dock.left : col === 'r' ? dock.right : innerWidth / 2;
103
- tx = col === 'l' ? '0' : col === 'r' ? '-100%' : '-50%';
104
- ay = row === 't' ? dock.bottom + GAP : dock.top - GAP;
105
- ty = row === 't' ? '0' : '-100%';
106
- }
107
- return {
108
- style: { left: ax - origin.x, top: ay - origin.y, translate: `${tx} ${ty}` },
109
- origin: `${row === 't' ? 'top' : 'bottom'}-${col === 'l' ? 'left' : col === 'c' ? 'center' : 'right'}`,
110
- };
96
+ /**
97
+ * A popover anchored to the dock: toward the page centre (sideways from a
98
+ * vertical or tucked dock), flush with the dock's outer edge, flipped and
99
+ * shifted so the measured `size` never leaves the viewport; it grows from
100
+ * the point nearest the dock.
101
+ */
102
+ export function anchoredLayer(dock, size, place, origin) {
103
+ const p = placeFloating({ x: dock.left, y: dock.top, w: dock.right - dock.left, h: dock.bottom - dock.top }, size, { w: innerWidth, h: innerHeight }, towardCentre(place), { align: alignFor(place), gap: 8, margin: 8 });
104
+ return { style: { left: p.x - origin.x, top: p.y - origin.y }, origin: p.origin };
111
105
  }
112
106
  /** A phone bottom sheet: the full visual viewport, content pinned to its bottom edge. */
113
107
  export function phoneLayer(origin) {
@@ -119,3 +113,43 @@ export function phoneLayer(origin) {
119
113
  height: vv?.height ?? innerHeight,
120
114
  };
121
115
  }
116
+ /**
117
+ * Keep a fixed float beside its anchor: placed on every commit, on a size
118
+ * change of either (the tray unfolding, a recents list loading) and on a
119
+ * viewport resize. Writes the style directly — no state, no re-render.
120
+ * `anchor` returns the box to sit beside (viewport px) or null to skip.
121
+ */
122
+ export function useFloat(float, anchor, side, align, active) {
123
+ const anchorRef = useRef(anchor);
124
+ anchorRef.current = anchor;
125
+ const place = useCallback(() => {
126
+ const f = float.current;
127
+ const a = anchorRef.current();
128
+ if (!f || !a)
129
+ return;
130
+ const p = placeFloating({ x: a.box.left, y: a.box.top, w: a.box.right - a.box.left, h: a.box.bottom - a.box.top }, { w: f.offsetWidth, h: f.offsetHeight }, { w: innerWidth, h: innerHeight }, side, { align, gap: 8, margin: 8 });
131
+ f.style.translate = `${Math.round(p.x)}px ${Math.round(p.y)}px`;
132
+ f.style.transformOrigin = p.origin;
133
+ f.dataset.side = p.side;
134
+ }, [float, side, align]);
135
+ useLayoutEffect(() => {
136
+ if (active)
137
+ place();
138
+ });
139
+ useEffect(() => {
140
+ if (!active || typeof ResizeObserver !== 'function')
141
+ return;
142
+ const ro = new ResizeObserver(place);
143
+ const f = float.current;
144
+ const a = anchorRef.current();
145
+ if (f)
146
+ ro.observe(f);
147
+ if (a)
148
+ ro.observe(a.el);
149
+ addEventListener('resize', place);
150
+ return () => {
151
+ ro.disconnect();
152
+ removeEventListener('resize', place);
153
+ };
154
+ }, [active, place, float]);
155
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * `listen` — the ONE way the HUD registers a window/document listener that
3
+ * cancels its event (`preventDefault`). It is always `{ passive: false }` and
4
+ * always the browser's own registration, never a host's patched one.
5
+ *
6
+ * Why not plain `addEventListener(…, { passive: false })`: zone.js (every
7
+ * Angular host) patches `addEventListener` and funnels every listener of one
8
+ * target + type + phase through ONE native listener, registered with the
9
+ * options of whoever came FIRST. Angular CDK's InputModalityDetector registers
10
+ * `keydown`, `mousedown` and `touchstart` on document `{ passive: true,
11
+ * capture: true }` at boot, so the HUD's Esc handler ran inside a passive
12
+ * invocation: Chrome logged "Unable to preventDefault inside passive event
13
+ * listener invocation" and the default went ahead anyway. zone.js keeps the
14
+ * unpatched functions under `__zone_symbol__addEventListener` /
15
+ * `__zone_symbol__removeEventListener`; registering through them gives the
16
+ * handler its own native listener with its own options (and keeps the HUD's
17
+ * pointer traffic out of the host's change detection).
18
+ */
19
+ export interface ListenOptions {
20
+ capture?: boolean;
21
+ }
22
+ export declare function listen<K extends keyof WindowEventMap>(target: Window, type: K, fn: (e: WindowEventMap[K]) => void, opts?: ListenOptions): () => void;
23
+ export declare function listen<K extends keyof DocumentEventMap>(target: Document, type: K, fn: (e: DocumentEventMap[K]) => void, opts?: ListenOptions): () => void;
24
+ export declare function listen(target: EventTarget, type: string, fn: (e: Event) => void, opts?: ListenOptions): () => void;