@vitrinka/web 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/README.md +78 -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/config.d.ts +6 -0
  16. package/build/recorder/config.js +1 -0
  17. package/build/recorder/hud/AnnotateOverlay.d.ts +7 -1
  18. package/build/recorder/hud/AnnotateOverlay.js +51 -17
  19. package/build/recorder/hud/Hud.d.ts +16 -1
  20. package/build/recorder/hud/Hud.js +251 -83
  21. package/build/recorder/hud/LinkSheet.d.ts +3 -3
  22. package/build/recorder/hud/LinkSheet.js +1 -1
  23. package/build/recorder/hud/Menu.d.ts +30 -0
  24. package/build/recorder/hud/Menu.js +73 -0
  25. package/build/recorder/hud/RecorderPill.d.ts +36 -27
  26. package/build/recorder/hud/RecorderPill.js +212 -123
  27. package/build/recorder/hud/Sheet.d.ts +1 -1
  28. package/build/recorder/hud/Sheet.js +1 -1
  29. package/build/recorder/hud/Tooltip.d.ts +19 -0
  30. package/build/recorder/hud/Tooltip.js +94 -0
  31. package/build/recorder/hud/controller.d.ts +148 -0
  32. package/build/recorder/hud/controller.js +17 -0
  33. package/build/recorder/hud/flow.d.ts +54 -0
  34. package/build/recorder/hud/flow.js +39 -0
  35. package/build/recorder/hud/host.js +1 -1
  36. package/build/recorder/hud/icons.d.ts +7 -0
  37. package/build/recorder/hud/icons.js +19 -0
  38. package/build/recorder/hud/iife.d.ts +13 -0
  39. package/build/recorder/hud/iife.js +11 -0
  40. package/build/recorder/hud/layer.d.ts +29 -6
  41. package/build/recorder/hud/layer.js +67 -33
  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 +41 -20
  54. package/build/recorder/index.d.ts +4 -2
  55. package/build/recorder/index.js +17 -19
  56. package/build/recorder/link.d.ts +1 -1
  57. package/build/recorder/link.js +8 -2
  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 +16 -1
  68. package/build/recorder/storage/index.js +2 -1
  69. package/package.json +9 -3
package/build/hud.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * `@vitrinka/web/hud` — the recorder HUD on its own, for hosts that bring
3
+ * their own recorder (the browser extension). Implement `HudController` and
4
+ * mount it; `build/hud.iife.js` is the same mount as a self-contained script
5
+ * defining `globalThis.VitrinkaHud.mount`.
6
+ */
7
+ export { mountRecorderHud } from './recorder/hud/mount';
8
+ export { DEFAULT_PREFS, } from './recorder/hud/controller';
@@ -3,6 +3,8 @@
3
3
  *
4
4
  * Ingest contract, shared with the Expo recorder and the browser extension:
5
5
  * GET /api/v1/recorder/policy workspace redaction policy
6
+ * GET /api/v1/recorder/me who the token is + HUD prefs (me.ts)
7
+ * PATCH /api/v1/recorder/me {prefs} (me.ts)
6
8
  * POST /api/v1/sessions {host, title, environment?, meta} → session
7
9
  * POST /api/v1/sessions/:id/events {events: [...]}
8
10
  * POST /api/v1/sessions/:id/chunk?seq=N (rrweb batch body, application/json)
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The attribute every HUD surface carries (the shadow host, a sheet host
3
+ * portaled into a dialog, the annotate-mode page stylesheet). rrweb's
4
+ * `blockSelector` names it, so none of them is recorded. Its own module so
5
+ * the HUD bundle carries the name without importing rrweb.
6
+ */
7
+ export declare const RRWEB_BLOCK_ATTR = "data-vitrinka-recorder";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The attribute every HUD surface carries (the shadow host, a sheet host
3
+ * portaled into a dialog, the annotate-mode page stylesheet). rrweb's
4
+ * `blockSelector` names it, so none of them is recorded. Its own module so
5
+ * the HUD bundle carries the name without importing rrweb.
6
+ */
7
+ export const RRWEB_BLOCK_ATTR = 'data-vitrinka-recorder';
@@ -1,5 +1,5 @@
1
- /** The extension's selector heuristic — id, then testid, then a short path. */
2
- export declare function shortSelector(el: Element | null): string;
1
+ import { elementText, shortSelector } from './selector';
2
+ export { elementText, shortSelector };
3
3
  /** Bounding rect in device pixels (the extension's `imageRect`). */
4
4
  export declare function imageRect(el: Element): {
5
5
  x: number;
@@ -7,8 +7,6 @@ export declare function imageRect(el: Element): {
7
7
  w: number;
8
8
  h: number;
9
9
  };
10
- /** The element's own visible text or value, trimmed and capped. */
11
- export declare function elementText(el: Element): string;
12
10
  export interface ClickLaneOptions {
13
11
  /** True while the HUD owns the pointer (annotate mode) or the target is HUD chrome. */
14
12
  ignore: (target: EventTarget | null) => boolean;
@@ -8,32 +8,9 @@
8
8
  import { pushEvent } from '../queue';
9
9
  import { currentRoute } from '../state';
10
10
  import { redactText } from './redact';
11
- const TEXT_CAP = 80;
11
+ import { elementText, shortSelector } from './selector';
12
+ export { elementText, shortSelector };
12
13
  const CLICKABLE = 'a,button,[role=button],input,select,textarea,label';
13
- /** The extension's selector heuristic — id, then testid, then a short path. */
14
- export function shortSelector(el) {
15
- if (!el)
16
- return '';
17
- if (el.id)
18
- return `#${el.id}`;
19
- const t = el.getAttribute('data-testid') || el.getAttribute('data-test');
20
- if (t)
21
- return `[data-testid="${t}"]`;
22
- const parts = [];
23
- let n = el;
24
- while (n && parts.length < 4) {
25
- let p = n.tagName.toLowerCase();
26
- if (n.classList.length)
27
- p += '.' + [...n.classList].slice(0, 2).join('.');
28
- parts.unshift(p);
29
- if (n.id) {
30
- parts[0] = `#${n.id}`;
31
- break;
32
- }
33
- n = n.parentElement;
34
- }
35
- return parts.join(' > ');
36
- }
37
14
  /** Bounding rect in device pixels (the extension's `imageRect`). */
38
15
  export function imageRect(el) {
39
16
  const r = el.getBoundingClientRect();
@@ -45,12 +22,6 @@ export function imageRect(el) {
45
22
  h: Math.round(r.height * s),
46
23
  };
47
24
  }
48
- /** The element's own visible text or value, trimmed and capped. */
49
- export function elementText(el) {
50
- const html = el;
51
- const raw = html.innerText || (typeof html.value === 'string' ? html.value : '') || '';
52
- return raw.trim().slice(0, TEXT_CAP);
53
- }
54
25
  /** Install the click lane; returns the uninstaller. */
55
26
  export function installClickLane(opts) {
56
27
  const onClick = (e) => {
@@ -1,5 +1,5 @@
1
- /** Elements carrying this attribute are never recorded (the HUD host). */
2
- export declare const RRWEB_BLOCK_ATTR = "data-vitrinka-recorder";
1
+ import { RRWEB_BLOCK_ATTR } from '../block';
2
+ export { RRWEB_BLOCK_ATTR };
3
3
  /** Start recording the DOM; idempotent. */
4
4
  export declare function startRRWeb(): void;
5
5
  /** Ship the tail and stop recording. */
@@ -1,12 +1,12 @@
1
1
  import { record } from 'rrweb';
2
+ import { RRWEB_BLOCK_ATTR } from '../block';
2
3
  import { pushRRWebBatch } from '../queue';
3
4
  import { currentRoute } from '../state';
4
5
  import { maskDirectives } from './redact';
6
+ export { RRWEB_BLOCK_ATTR };
5
7
  const BATCH_MS = 2000;
6
8
  /** A fresh full snapshot every 5 min keeps long recordings seekable. */
7
9
  const CHECKOUT_MS = 5 * 60 * 1000;
8
- /** Elements carrying this attribute are never recorded (the HUD host). */
9
- export const RRWEB_BLOCK_ATTR = 'data-vitrinka-recorder';
10
10
  let stop = null;
11
11
  let buf = [];
12
12
  let timer = null;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * How an element is named in a click or an annotation — DOM reads only, so
3
+ * the HUD (annotate mode) can share them without the capture queue.
4
+ */
5
+ /** The extension's selector heuristic — id, then testid, then a short path. */
6
+ export declare function shortSelector(el: Element | null): string;
7
+ /** The element's own visible text or value, trimmed and capped. */
8
+ export declare function elementText(el: Element): string;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * How an element is named in a click or an annotation — DOM reads only, so
3
+ * the HUD (annotate mode) can share them without the capture queue.
4
+ */
5
+ const TEXT_CAP = 80;
6
+ /** The extension's selector heuristic — id, then testid, then a short path. */
7
+ export function shortSelector(el) {
8
+ if (!el)
9
+ return '';
10
+ if (el.id)
11
+ return `#${el.id}`;
12
+ const t = el.getAttribute('data-testid') || el.getAttribute('data-test');
13
+ if (t)
14
+ return `[data-testid="${t}"]`;
15
+ const parts = [];
16
+ let n = el;
17
+ while (n && parts.length < 4) {
18
+ let p = n.tagName.toLowerCase();
19
+ if (n.classList.length)
20
+ p += '.' + [...n.classList].slice(0, 2).join('.');
21
+ parts.unshift(p);
22
+ if (n.id) {
23
+ parts[0] = `#${n.id}`;
24
+ break;
25
+ }
26
+ n = n.parentElement;
27
+ }
28
+ return parts.join(' > ');
29
+ }
30
+ /** The element's own visible text or value, trimmed and capped. */
31
+ export function elementText(el) {
32
+ const html = el;
33
+ const raw = html.innerText || (typeof html.value === 'string' ? html.value : '') || '';
34
+ return raw.trim().slice(0, TEXT_CAP);
35
+ }
@@ -19,6 +19,12 @@ export interface RecorderConfig {
19
19
  appVersion?: string;
20
20
  /** Explicit server lane; omitted = the key's project rule decides. */
21
21
  environment?: string;
22
+ /**
23
+ * Explicit project for a device-linked session — one origin serving several
24
+ * apps (by path) files each into its own project. Omitted = the host's
25
+ * project rule decides; an admin key's pin always wins (a mismatch is 403).
26
+ */
27
+ project?: string;
22
28
  /** Device-link label; defaults to `<browser> on <os> · <host>`. */
23
29
  label?: string;
24
30
  }
@@ -6,6 +6,7 @@ export function configureRecorder(next) {
6
6
  config.key = next.key ?? '';
7
7
  config.appVersion = next.appVersion;
8
8
  config.environment = next.environment;
9
+ config.project = next.project;
9
10
  config.label = next.label;
10
11
  }
11
12
  export function recorderConfig() {
@@ -6,7 +6,13 @@
6
6
  * restyle it; the pointer handlers are document-level CAPTURE listeners.
7
7
  *
8
8
  * The mode owns the pointer, mouse and finger alike — the page never sees a
9
- * press, a pick's click or a touch, and the HUD's own surfaces are exempt:
9
+ * press, a move, a hover, a pick's click or a touch, and nothing on it gets
10
+ * selected; the HUD's own surfaces are exempt. Every listener sits on WINDOW
11
+ * capture, ahead of anything the page registered on its document:
12
+ * - A drag over text never selects it: `user-select:none` page-wide
13
+ * (ANNOTATE_PAGE_CSS), the mousedown default cancelled and `selectstart`
14
+ * refused. The crosshair rides the same blocked stylesheet, so the page's
15
+ * own elements are never restyled (and rrweb records no mutation).
10
16
  * - A finger never pans, zooms, selects or long-presses the page: every
11
17
  * element gets `touch-action:none` (ANNOTATE_PAGE_CSS) and window-capture
12
18
  * non-passive touch listeners cancel each touch, which also stops the
@@ -7,7 +7,13 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
7
7
  * restyle it; the pointer handlers are document-level CAPTURE listeners.
8
8
  *
9
9
  * The mode owns the pointer, mouse and finger alike — the page never sees a
10
- * press, a pick's click or a touch, and the HUD's own surfaces are exempt:
10
+ * press, a move, a hover, a pick's click or a touch, and nothing on it gets
11
+ * selected; the HUD's own surfaces are exempt. Every listener sits on WINDOW
12
+ * capture, ahead of anything the page registered on its document:
13
+ * - A drag over text never selects it: `user-select:none` page-wide
14
+ * (ANNOTATE_PAGE_CSS), the mousedown default cancelled and `selectstart`
15
+ * refused. The crosshair rides the same blocked stylesheet, so the page's
16
+ * own elements are never restyled (and rrweb records no mutation).
11
17
  * - A finger never pans, zooms, selects or long-presses the page: every
12
18
  * element gets `touch-action:none` (ANNOTATE_PAGE_CSS) and window-capture
13
19
  * non-passive touch listeners cancel each touch, which also stops the
@@ -20,13 +26,19 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
20
26
  * a finger's sliver of a marquee is a slip that stays in the mode too.
21
27
  */
22
28
  import { useEffect, useState } from 'react';
23
- import { elementText, shortSelector } from '../capture/click';
24
- import { RRWEB_BLOCK_ATTR } from '../capture/rrweb';
29
+ import { elementText, shortSelector } from '../capture/selector';
30
+ import { RRWEB_BLOCK_ATTR } from '../block';
25
31
  import { AnnotateIcon } from './icons';
26
32
  import { insideHud } from './host';
27
33
  import { ANNOTATE_PAGE_CSS } from './styles';
28
34
  const TOUCH = ['touchstart', 'touchmove', 'touchend'];
29
35
  const TAIL = ['touchend', 'mousedown', 'mouseup', 'click'];
36
+ /** Pointer traffic the page must not see while the mode is on (the gesture's own events are handled below). */
37
+ const HUSHED = [
38
+ 'pointerover', 'pointerout', 'pointerenter', 'pointerleave',
39
+ 'mouseover', 'mouseout', 'mouseenter', 'mouseleave', 'mousemove', 'mouseup',
40
+ 'dblclick', 'auxclick', 'contextmenu',
41
+ ];
30
42
  /**
31
43
  * Eat the rest of the gesture that ended annotate mode. The pick flips the
32
44
  * mode off inside pointerup and React (a SyncLane commit) runs the overlay's
@@ -64,7 +76,6 @@ export function AnnotateOverlay({ onPick, onCancel }) {
64
76
  let dragging = false;
65
77
  let pid = -1; // the pointer steering the gesture
66
78
  let slop = 6;
67
- document.documentElement.style.cursor = 'crosshair';
68
79
  const pageCss = document.createElement('style');
69
80
  pageCss.setAttribute(RRWEB_BLOCK_ATTR, '');
70
81
  pageCss.textContent = ANNOTATE_PAGE_CSS;
@@ -97,6 +108,9 @@ export function AnnotateOverlay({ onPick, onCancel }) {
97
108
  place({ x: r.x - 3, y: r.y - 3, w: r.width + 2, h: r.height + 2 });
98
109
  };
99
110
  const move = (e) => {
111
+ if (insideHud(e.target))
112
+ return;
113
+ e.stopPropagation();
100
114
  if (downAt && e.pointerId !== pid)
101
115
  return; // a second finger never steers the marquee
102
116
  last = { x: e.clientX, y: e.clientY };
@@ -189,6 +203,19 @@ export function AnnotateOverlay({ onPick, onCancel }) {
189
203
  if (!insideHud(e.target))
190
204
  e.preventDefault();
191
205
  };
206
+ const hush = (e) => {
207
+ if (!insideHud(e.target))
208
+ e.stopPropagation();
209
+ };
210
+ // A mousedown's default starts a text selection (cancelling pointerdown
211
+ // does not stop it in Chromium); selectstart catches keyboard and other paths.
212
+ const noSelect = (e) => {
213
+ if (insideHud(e.target))
214
+ return;
215
+ if (e.cancelable)
216
+ e.preventDefault();
217
+ e.stopPropagation();
218
+ };
192
219
  const key = (e) => {
193
220
  if (e.key === 'Escape') {
194
221
  e.preventDefault();
@@ -196,28 +223,35 @@ export function AnnotateOverlay({ onPick, onCancel }) {
196
223
  onCancel();
197
224
  }
198
225
  };
199
- document.addEventListener('pointermove', move, true);
200
- document.addEventListener('pointerdown', down, true);
201
- document.addEventListener('pointerup', up, true);
202
- document.addEventListener('click', swallowClick, true);
226
+ window.addEventListener('pointermove', move, true);
227
+ window.addEventListener('pointerdown', down, true);
228
+ window.addEventListener('pointerup', up, true);
229
+ window.addEventListener('click', swallowClick, true);
230
+ window.addEventListener('pointercancel', cancel, true);
231
+ window.addEventListener('dragstart', noDrag, true);
232
+ window.addEventListener('mousedown', noSelect, true);
233
+ window.addEventListener('selectstart', noSelect, true);
234
+ for (const t of HUSHED)
235
+ window.addEventListener(t, hush, true);
203
236
  document.addEventListener('keydown', key, true);
204
- document.addEventListener('pointercancel', cancel, true);
205
- document.addEventListener('dragstart', noDrag, true);
206
237
  // Explicitly non-passive: window/document touch listeners default to passive.
207
238
  for (const t of TOUCH)
208
239
  window.addEventListener(t, blockTouch, { capture: true, passive: false });
209
240
  return () => {
210
- document.documentElement.style.cursor = '';
211
241
  pageCss.remove();
212
242
  if (raf !== 0)
213
243
  cancelAnimationFrame(raf);
214
- document.removeEventListener('pointermove', move, true);
215
- document.removeEventListener('pointerdown', down, true);
216
- document.removeEventListener('pointerup', up, true);
217
- document.removeEventListener('click', swallowClick, true);
244
+ window.removeEventListener('pointermove', move, true);
245
+ window.removeEventListener('pointerdown', down, true);
246
+ window.removeEventListener('pointerup', up, true);
247
+ window.removeEventListener('click', swallowClick, true);
248
+ window.removeEventListener('pointercancel', cancel, true);
249
+ window.removeEventListener('dragstart', noDrag, true);
250
+ window.removeEventListener('mousedown', noSelect, true);
251
+ window.removeEventListener('selectstart', noSelect, true);
252
+ for (const t of HUSHED)
253
+ window.removeEventListener(t, hush, true);
218
254
  document.removeEventListener('keydown', key, true);
219
- document.removeEventListener('pointercancel', cancel, true);
220
- document.removeEventListener('dragstart', noDrag, true);
221
255
  for (const t of TOUCH)
222
256
  window.removeEventListener(t, blockTouch, true);
223
257
  };
@@ -1,7 +1,22 @@
1
+ /**
2
+ * The HUD tree, rendered into the shadow host by its own React root and
3
+ * driven ONLY through a `HudController` (controller.ts) — the in-page
4
+ * recorder's, or another host's. Owns the dock (where the HUD rests), the
5
+ * pill's inline flows (flow.ts), the sheet (open/title/ctx/pick + the
6
+ * surviving draft) and where it opens, the ⋯ menu, the tooltip and details
7
+ * floats, annotate mode, the keyboard shortcuts, the Esc-anywhere /
8
+ * click-outside close and the status line a screen reader hears while the
9
+ * pill is folded.
10
+ */
1
11
  import { type ReactElement } from 'react';
12
+ import type { RecorderStorage } from '../storage';
13
+ import type { HudController } from './controller';
2
14
  export interface HudProps {
15
+ controller: HudController;
3
16
  /** The HUD host's own mount (the sheet portals here when no dialog is open). */
4
17
  hostMount: HTMLElement;
5
18
  defaultTitle: () => string;
19
+ /** Where the HUD remembers its own UI state (the dock spot). */
20
+ storage: RecorderStorage;
6
21
  }
7
- export declare function Hud({ hostMount, defaultTitle }: HudProps): ReactElement;
22
+ export declare function Hud({ controller, hostMount, defaultTitle, storage }: HudProps): ReactElement;