@vitrinka/web 0.1.3 → 0.1.5

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @vitrinka/web
2
2
 
3
+ ## 0.1.5
4
+
5
+ - **A `project` prop.** `VitrinkaRecorderRoot` takes `project`. A
6
+ device-linked session then files into that project instead of the one the
7
+ host's rule picks. One origin that serves several apps by path can now send
8
+ each app's sessions to its own project. A recorder key's pin still wins.
9
+
10
+ ## 0.1.4
11
+
12
+ - **Annotate works by finger.** On a phone or tablet, a drag in annotate
13
+ mode used to scroll the page: the browser took the gesture and the
14
+ marquee froze where it was. The next tap then quit annotate mode without
15
+ picking anything. Now annotate mode owns every touch on the page, so a
16
+ drag draws the region, and the page no longer pans, zooms, selects text
17
+ or opens a long-press menu. Leaving annotate mode gives all of that back.
18
+ If the browser does take a gesture, the marquee clears and you stay in
19
+ annotate mode.
20
+ - **A pick never presses the page.** Tapping or clicking a button to
21
+ annotate it also pressed the button, on desktop too, and the journey
22
+ recorded the pick as a click. The pick's click is now swallowed, even
23
+ after annotate mode has closed.
24
+ - Finger taps get a 12px slop before they become a marquee (a mouse keeps
25
+ 6px). A slip that draws only a sliver stays in annotate mode instead of
26
+ quitting it, and a second finger never moves the marquee.
27
+
3
28
  ## 0.1.3
4
29
 
5
30
  - **A throw over a page link or image lands.** Grabbing the HUD where the
package/README.md CHANGED
@@ -82,6 +82,11 @@ Vite and plain React work the same way — pass `url` / `recorderKey` from
82
82
  `import.meta.env` (the `NEXT_PUBLIC_*` fallback only applies where a
83
83
  bundler inlines `process.env`).
84
84
 
85
+ One origin serving several apps by path (`/portal/`, `/designer/`, …)
86
+ can file each app's sessions into its own project: pass `project` per app.
87
+ Without it, the host's project rule decides; a recorder key's project pin
88
+ always wins, and a different `project` is refused.
89
+
85
90
  ### Env vars
86
91
 
87
92
  | Var | What |
@@ -122,7 +127,7 @@ you leave (keycaps show on hover):
122
127
  |---|---|---|
123
128
  | ⏸ Pause / ▶ Resume | ⌥⇧P (Alt⇧P) | freezes the clock and capture |
124
129
  | ✎ Note | ⌥⇧N | the note sheet — Enter sends, ⇧Enter newline, Esc / ✕ / click-outside cancel (the draft survives a cancel) |
125
- | ⌖ Annotate | ⌥⇧A | click an element or drag a region, then describe it; `board` (an annotation on the board) or `task` (also filed as an intake draft) |
130
+ | ⌖ Annotate | ⌥⇧A | click or tap an element, or drag a region (a finger too — the page does not scroll or press while annotating), then describe it; `board` (an annotation on the board) or `task` (also filed as an intake draft) |
126
131
  | ⋯ | | **Open board** (the server-minted link) · **Stop recording** · **Unlink** · **Move to** |
127
132
 
128
133
  Move it anywhere: drag the puck or capsule and it lands on one of six spots
@@ -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() {
@@ -1,10 +1,22 @@
1
1
  /**
2
2
  * Annotate mode (⌖): crosshair, the hovered element outlined, a drag past
3
- * 6px switches to a marquee; the page dims and a hint bar says what to do.
4
- * Click → element pick (selector + rect), drag → region (rect). The chrome
5
- * lives in the shadow root so the page cannot restyle it; the pointer
6
- * handlers are document-level CAPTURE listeners so the page never sees the
7
- * pick click.
3
+ * 6px (12px for a finger) switches to a marquee; the page dims and a hint
4
+ * bar says what to do. Click or tap → element pick (selector + rect), drag →
5
+ * region (rect). The chrome lives in the shadow root so the page cannot
6
+ * restyle it; the pointer handlers are document-level CAPTURE listeners.
7
+ *
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:
10
+ * - A finger never pans, zooms, selects or long-presses the page: every
11
+ * element gets `touch-action:none` (ANNOTATE_PAGE_CSS) and window-capture
12
+ * non-passive touch listeners cancel each touch, which also stops the
13
+ * browser synthesising a click from it. Native drags are blocked too.
14
+ * - A pick switches the mode off inside pointerup, and React unmounts this
15
+ * overlay before the gesture's tail (touchend, click) is dispatched; the
16
+ * one-shot `swallowGestureTail` guard outlives the overlay to eat it.
17
+ * - A pointercancel drops the marquee and stays in annotate mode; one
18
+ * pointer (the primary) steers a gesture, a second finger never does, and
19
+ * a finger's sliver of a marquee is a slip that stays in the mode too.
8
20
  */
9
21
  import { type ReactElement } from 'react';
10
22
  export interface Pick {
@@ -1,22 +1,74 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  /**
3
3
  * Annotate mode (⌖): crosshair, the hovered element outlined, a drag past
4
- * 6px switches to a marquee; the page dims and a hint bar says what to do.
5
- * Click → element pick (selector + rect), drag → region (rect). The chrome
6
- * lives in the shadow root so the page cannot restyle it; the pointer
7
- * handlers are document-level CAPTURE listeners so the page never sees the
8
- * pick click.
4
+ * 6px (12px for a finger) switches to a marquee; the page dims and a hint
5
+ * bar says what to do. Click or tap → element pick (selector + rect), drag →
6
+ * region (rect). The chrome lives in the shadow root so the page cannot
7
+ * restyle it; the pointer handlers are document-level CAPTURE listeners.
8
+ *
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:
11
+ * - A finger never pans, zooms, selects or long-presses the page: every
12
+ * element gets `touch-action:none` (ANNOTATE_PAGE_CSS) and window-capture
13
+ * non-passive touch listeners cancel each touch, which also stops the
14
+ * browser synthesising a click from it. Native drags are blocked too.
15
+ * - A pick switches the mode off inside pointerup, and React unmounts this
16
+ * overlay before the gesture's tail (touchend, click) is dispatched; the
17
+ * one-shot `swallowGestureTail` guard outlives the overlay to eat it.
18
+ * - A pointercancel drops the marquee and stays in annotate mode; one
19
+ * pointer (the primary) steers a gesture, a second finger never does, and
20
+ * a finger's sliver of a marquee is a slip that stays in the mode too.
9
21
  */
10
22
  import { useEffect, useState } from 'react';
11
23
  import { elementText, shortSelector } from '../capture/click';
24
+ import { RRWEB_BLOCK_ATTR } from '../capture/rrweb';
12
25
  import { AnnotateIcon } from './icons';
13
26
  import { insideHud } from './host';
27
+ import { ANNOTATE_PAGE_CSS } from './styles';
28
+ const TOUCH = ['touchstart', 'touchmove', 'touchend'];
29
+ const TAIL = ['touchend', 'mousedown', 'mouseup', 'click'];
30
+ /**
31
+ * Eat the rest of the gesture that ended annotate mode. The pick flips the
32
+ * mode off inside pointerup and React (a SyncLane commit) runs the overlay's
33
+ * cleanup in that microtask, BEFORE the browser dispatches touchend or the
34
+ * click — so this guard lives on `window`, not in the effect. Window capture
35
+ * runs ahead of the page and of the click lane, so a pick is never pressed
36
+ * nor journaled as a click. One-shot: the gesture's click or the next
37
+ * pointerdown disarms it; keyboard (`detail` 0) and synthetic clicks pass.
38
+ */
39
+ function swallowGestureTail() {
40
+ const eat = (e) => {
41
+ if (!e.isTrusted || insideHud(e.target))
42
+ return;
43
+ if (e.type === 'click' && e.detail === 0)
44
+ return;
45
+ if (e.cancelable)
46
+ e.preventDefault();
47
+ e.stopImmediatePropagation();
48
+ if (e.type === 'click')
49
+ off();
50
+ };
51
+ const off = () => {
52
+ for (const t of TAIL)
53
+ window.removeEventListener(t, eat, true);
54
+ window.removeEventListener('pointerdown', off, true);
55
+ };
56
+ for (const t of TAIL)
57
+ window.addEventListener(t, eat, { capture: true, passive: false });
58
+ window.addEventListener('pointerdown', off, true);
59
+ }
14
60
  export function AnnotateOverlay({ onPick, onCancel }) {
15
61
  const [box, setBox] = useState(null);
16
62
  useEffect(() => {
17
63
  let downAt = null;
18
64
  let dragging = false;
65
+ let pid = -1; // the pointer steering the gesture
66
+ let slop = 6;
19
67
  document.documentElement.style.cursor = 'crosshair';
68
+ const pageCss = document.createElement('style');
69
+ pageCss.setAttribute(RRWEB_BLOCK_ATTR, '');
70
+ pageCss.textContent = ANNOTATE_PAGE_CSS;
71
+ (document.head ?? document.documentElement).append(pageCss);
20
72
  let raf = 0;
21
73
  let last = null;
22
74
  const same = (a, b) => a === b || (a !== null && b !== null && a.x === b.x && a.y === b.y && a.w === b.w && a.h === b.h);
@@ -26,7 +78,7 @@ export function AnnotateOverlay({ onPick, onCancel }) {
26
78
  if (!last)
27
79
  return;
28
80
  const { x, y } = last;
29
- if (downAt && (dragging || Math.hypot(x - downAt.x, y - downAt.y) > 6)) {
81
+ if (downAt && (dragging || Math.hypot(x - downAt.x, y - downAt.y) > slop)) {
30
82
  dragging = true;
31
83
  place({
32
84
  x: Math.min(downAt.x, x),
@@ -45,32 +97,55 @@ export function AnnotateOverlay({ onPick, onCancel }) {
45
97
  place({ x: r.x - 3, y: r.y - 3, w: r.width + 2, h: r.height + 2 });
46
98
  };
47
99
  const move = (e) => {
100
+ if (downAt && e.pointerId !== pid)
101
+ return; // a second finger never steers the marquee
48
102
  last = { x: e.clientX, y: e.clientY };
49
103
  if (raf === 0)
50
104
  raf = requestAnimationFrame(frame);
51
105
  };
106
+ /** Drop the gesture and its outline; annotate mode stays on. */
107
+ const reset = () => {
108
+ downAt = null;
109
+ dragging = false;
110
+ pid = -1;
111
+ last = null;
112
+ if (raf !== 0)
113
+ cancelAnimationFrame(raf);
114
+ raf = 0;
115
+ place(null);
116
+ };
52
117
  const down = (e) => {
53
118
  if (insideHud(e.target))
54
119
  return;
55
120
  e.preventDefault();
56
121
  e.stopPropagation();
122
+ if (!e.isPrimary)
123
+ return;
124
+ pid = e.pointerId;
125
+ slop = e.pointerType === 'touch' ? 12 : 6;
126
+ dragging = false;
57
127
  downAt = { x: e.clientX, y: e.clientY };
128
+ move(e); // a finger has no hover: outline what is under it now
58
129
  };
59
130
  const up = (e) => {
60
- if (!downAt)
131
+ if (!downAt || e.pointerId !== pid)
61
132
  return;
62
133
  e.preventDefault();
63
134
  e.stopPropagation();
135
+ swallowGestureTail();
64
136
  const start = downAt;
65
137
  const wasDrag = dragging;
66
138
  downAt = null;
67
139
  dragging = false;
140
+ pid = -1;
68
141
  if (wasDrag) {
69
142
  const x = Math.min(start.x, e.clientX);
70
143
  const y = Math.min(start.y, e.clientY);
71
144
  const w = Math.abs(e.clientX - start.x);
72
145
  const h = Math.abs(e.clientY - start.y);
73
146
  if (w < 4 || h < 4) {
147
+ if (e.pointerType === 'touch')
148
+ return reset(); // a finger's slip, not a request to leave
74
149
  onCancel();
75
150
  return;
76
151
  }
@@ -89,12 +164,31 @@ export function AnnotateOverlay({ onPick, onCancel }) {
89
164
  text: elementText(el),
90
165
  });
91
166
  };
167
+ // The browser took the pointer (a pan that slipped through, a native drag).
168
+ const cancel = (e) => {
169
+ if (e.pointerId === pid)
170
+ reset();
171
+ };
92
172
  const swallowClick = (e) => {
93
173
  if (insideHud(e.target))
94
174
  return;
95
175
  e.preventDefault();
96
176
  e.stopPropagation();
97
177
  };
178
+ // A cancelled touchstart stops pan, zoom, pull-to-refresh, long-press and
179
+ // the click synthesised from a tap — iOS included, where touch-action is
180
+ // not always honoured; stopping it keeps swipers and responders out.
181
+ const blockTouch = (e) => {
182
+ if (insideHud(e.target))
183
+ return;
184
+ if (e.cancelable)
185
+ e.preventDefault();
186
+ e.stopPropagation();
187
+ };
188
+ const noDrag = (e) => {
189
+ if (!insideHud(e.target))
190
+ e.preventDefault();
191
+ };
98
192
  const key = (e) => {
99
193
  if (e.key === 'Escape') {
100
194
  e.preventDefault();
@@ -107,8 +201,14 @@ export function AnnotateOverlay({ onPick, onCancel }) {
107
201
  document.addEventListener('pointerup', up, true);
108
202
  document.addEventListener('click', swallowClick, true);
109
203
  document.addEventListener('keydown', key, true);
204
+ document.addEventListener('pointercancel', cancel, true);
205
+ document.addEventListener('dragstart', noDrag, true);
206
+ // Explicitly non-passive: window/document touch listeners default to passive.
207
+ for (const t of TOUCH)
208
+ window.addEventListener(t, blockTouch, { capture: true, passive: false });
110
209
  return () => {
111
210
  document.documentElement.style.cursor = '';
211
+ pageCss.remove();
112
212
  if (raf !== 0)
113
213
  cancelAnimationFrame(raf);
114
214
  document.removeEventListener('pointermove', move, true);
@@ -116,6 +216,10 @@ export function AnnotateOverlay({ onPick, onCancel }) {
116
216
  document.removeEventListener('pointerup', up, true);
117
217
  document.removeEventListener('click', swallowClick, true);
118
218
  document.removeEventListener('keydown', key, true);
219
+ document.removeEventListener('pointercancel', cancel, true);
220
+ document.removeEventListener('dragstart', noDrag, true);
221
+ for (const t of TOUCH)
222
+ window.removeEventListener(t, blockTouch, true);
119
223
  };
120
224
  }, [onPick, onCancel]);
121
225
  return (_jsxs(_Fragment, { children: [_jsx("div", { className: "dim", "data-e2e": "annotate-dim" }), box ? (_jsx("div", { className: "outline", style: { left: box.x, top: box.y, width: box.w, height: box.h } })) : null, _jsxs("div", { className: "hint", children: [_jsx(AnnotateIcon, {}), " Click an element or drag an area", _jsx("span", { className: "keys", children: " \u00B7 esc cancels" })] })] }));
@@ -20,6 +20,16 @@ export declare const HUD_CSS_BASE = "\n* { box-sizing: border-box; font-family:
20
20
  export declare const HOST_STYLE: string;
21
21
  /** Inline style of a sheet host portaled into a dialog — the same 0×0 origin box. */
22
22
  export declare const SHEET_HOST_STYLE: string;
23
+ /**
24
+ * The PAGE (light-DOM) sheet while annotate mode owns the pointer — one
25
+ * <style> in the page head, removed on exit. `touch-action:none` on every
26
+ * element, not just the root: Chromium re-enables panning inside each inner
27
+ * scroller, and it keeps a finger's drag a marquee even where a touchstart
28
+ * cannot be cancelled (a tap that stops a fling). The rest (callout,
29
+ * selection, tap flash) only matters to a finger, so a mouse-only desktop
30
+ * renders exactly as before.
31
+ */
32
+ export declare const ANNOTATE_PAGE_CSS: string;
23
33
  /** Link-sheet additions (appended to HUD_CSS). */
24
34
  export declare const LINK_CSS = "\n.linkgrid { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:4px 12px; align-items:center; margin-top:10px; }\n.linkgrid.noqr { grid-template-columns:minmax(0,1fr); }\n.code { font-size:22px; font-weight:700; line-height:1.2; letter-spacing:.08em; font-variant-numeric:tabular-nums; color:var(--fg); }\n.linkgrid .sendb { justify-self:start; margin-top:6px; }\n.qr { grid-column:2; grid-row:1 / span 3; width:76px; height:76px; border-radius:8px; background:#fff; padding:4px; }\n.linkline { margin-top:8px; font-size:11px; line-height:1.4; color:var(--fg-2); display:flex; gap:10px; align-items:center; }\n.linkline.bad { color:var(--warn); }\n.retry { all:unset; box-sizing:border-box; cursor:pointer; min-height:24px; padding:4px 9px; border-radius:7px; box-shadow:inset 0 0 0 1px var(--edge);\n color:var(--fg); font-size:11.5px; font-weight:600; line-height:1; }\n@media (hover: hover) { .retry:hover { background:var(--ink-2); } }\n";
25
35
  /** Reduced motion: no ripple, no springs, no slides — every state change is instant. */
@@ -244,6 +244,18 @@ export const HOST_STYLE = 'all:initial;position:fixed;z-index:2147483647;inset:0
244
244
  'background:transparent;overflow:visible;width:0;height:0;pointer-events:none;color-scheme:normal;';
245
245
  /** Inline style of a sheet host portaled into a dialog — the same 0×0 origin box. */
246
246
  export const SHEET_HOST_STYLE = HOST_STYLE;
247
+ /**
248
+ * The PAGE (light-DOM) sheet while annotate mode owns the pointer — one
249
+ * <style> in the page head, removed on exit. `touch-action:none` on every
250
+ * element, not just the root: Chromium re-enables panning inside each inner
251
+ * scroller, and it keeps a finger's drag a marquee even where a touchstart
252
+ * cannot be cancelled (a tap that stops a fling). The rest (callout,
253
+ * selection, tap flash) only matters to a finger, so a mouse-only desktop
254
+ * renders exactly as before.
255
+ */
256
+ export const ANNOTATE_PAGE_CSS = '*{touch-action:none!important}' +
257
+ '@media (any-pointer:coarse){*{-webkit-touch-callout:none!important;-webkit-user-select:none!important;' +
258
+ 'user-select:none!important;-webkit-tap-highlight-color:transparent!important}}';
247
259
  /** Link-sheet additions (appended to HUD_CSS). */
248
260
  export const LINK_CSS = `
249
261
  .linkgrid { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:4px 12px; align-items:center; margin-top:10px; }
@@ -28,6 +28,8 @@ export interface VitrinkaRecorderRootProps {
28
28
  appVersion?: string;
29
29
  /** Explicit server lane; omitted = the key's project rule decides. */
30
30
  environment?: string;
31
+ /** Explicit project; omitted = the host's project rule decides. */
32
+ project?: string;
31
33
  /** A router's pathname, when the History wrap is not enough. */
32
34
  route?: string | null;
33
35
  children?: ReactNode;
@@ -25,7 +25,14 @@ export function VitrinkaRecorderRoot(props) {
25
25
  if (!url)
26
26
  return createElement(Fragment, null, props.children);
27
27
  return createElement(RecorderProvider, {
28
- config: { url, key, appVersion: props.appVersion, environment: props.environment, label: props.label },
28
+ config: {
29
+ url,
30
+ key,
31
+ appVersion: props.appVersion,
32
+ environment: props.environment,
33
+ project: props.project,
34
+ label: props.label,
35
+ },
29
36
  }, createElement(RouteFeed, { route: props.route }), props.children);
30
37
  }
31
38
  function RouteFeed({ route }) {
@@ -17,8 +17,8 @@ import { type SessionState } from './queue';
17
17
  export { currentRoute, notify, subscribe } from './state';
18
18
  export type { SessionDone } from '../protocol';
19
19
  /** Sent as `meta.recorder`; bumped with the package version. */
20
- export declare const RECORDER_VERSION = "0.1.3";
21
- export declare const RECORDER_ID = "web/0.1.3";
20
+ export declare const RECORDER_VERSION = "0.1.5";
21
+ export declare const RECORDER_ID = "web/0.1.5";
22
22
  /** What `POST /api/v1/sessions` answers (the fields this recorder keeps). */
23
23
  export interface SessionOut {
24
24
  id: string;
@@ -5,7 +5,7 @@ import { armReconcile, capturesSettled, disarmReconcile, drainBuffer, getState,
5
5
  import { currentRoute, notify } from './state';
6
6
  export { currentRoute, notify, subscribe } from './state';
7
7
  /** Sent as `meta.recorder`; bumped with the package version. */
8
- export const RECORDER_VERSION = '0.1.3';
8
+ export const RECORDER_VERSION = '0.1.5';
9
9
  export const RECORDER_ID = `web/${RECORDER_VERSION}`;
10
10
  /**
11
11
  * Re-apply a RECOVERED session's redaction policy after a reload — and
@@ -64,6 +64,7 @@ export async function startSession(opts = {}) {
64
64
  const ses = await api('POST', '/api/v1/sessions', {
65
65
  host: pageHost(),
66
66
  title: opts.title || '',
67
+ ...(cfg.project ? { project: cfg.project } : {}),
67
68
  ...(environment ? { environment } : {}),
68
69
  meta: {
69
70
  recorder: RECORDER_ID,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitrinka/web",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "vitrinka toolkit for React DOM apps — the journey recorder: capture manual-testing sessions (rrweb DOM stream, clicks, navigation, network, console, notes) straight into vitrinka boards.",
5
5
  "license": "Elastic-2.0",
6
6
  "repository": {