@vitrinka/web 0.1.2 → 0.1.4

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,31 @@
1
1
  # @vitrinka/web
2
2
 
3
+ ## 0.1.4
4
+
5
+ - **Annotate works by finger.** On a phone or tablet, a drag in annotate
6
+ mode used to scroll the page: the browser took the gesture and the
7
+ marquee froze where it was. The next tap then quit annotate mode without
8
+ picking anything. Now annotate mode owns every touch on the page, so a
9
+ drag draws the region, and the page no longer pans, zooms, selects text
10
+ or opens a long-press menu. Leaving annotate mode gives all of that back.
11
+ If the browser does take a gesture, the marquee clears and you stay in
12
+ annotate mode.
13
+ - **A pick never presses the page.** Tapping or clicking a button to
14
+ annotate it also pressed the button, on desktop too, and the journey
15
+ recorded the pick as a click. The pick's click is now swallowed, even
16
+ after annotate mode has closed.
17
+ - Finger taps get a 12px slop before they become a marquee (a mouse keeps
18
+ 6px). A slip that draws only a sliver stays in annotate mode instead of
19
+ quitting it, and a second finger never moves the marquee.
20
+
21
+ ## 0.1.3
22
+
23
+ - **A throw over a page link or image lands.** Grabbing the HUD where the
24
+ page has a link or image underneath could start the browser's native drag
25
+ of that element. The browser then cancelled the pointer, and the HUD snapped
26
+ back to its spot. A press on the capsule, the puck or the tab now blocks
27
+ native drags until it ends.
28
+
3
29
  ## 0.1.2
4
30
 
5
31
  - **A HUD that is barely there.** Idle, it is a 28px glass puck (a hollow
package/README.md CHANGED
@@ -122,7 +122,7 @@ you leave (keycaps show on hover):
122
122
  |---|---|---|
123
123
  | ⏸ Pause / ▶ Resume | ⌥⇧P (Alt⇧P) | freezes the clock and capture |
124
124
  | ✎ 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) |
125
+ | ⌖ 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
126
  | ⋯ | | **Open board** (the server-minted link) · **Stop recording** · **Unlink** · **Move to** |
127
127
 
128
128
  Move it anywhere: drag the puck or capsule and it lands on one of six spots
@@ -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; }
@@ -89,6 +89,19 @@ export function useDock(onMoveStart) {
89
89
  ro.observe(el);
90
90
  return () => ro.disconnect();
91
91
  }, []);
92
+ // A press on a handle (capsule, puck or tab) belongs to the HUD alone. On
93
+ // the first move the browser hit-tests the press point again for a native
94
+ // drag source. By then the dock has moved off that point, so a link or image
95
+ // of the page underneath would start a native drag, which cancels the
96
+ // pointer and drops the throw. Cancel any dragstart while a press is live.
97
+ useEffect(() => {
98
+ const guard = (e) => {
99
+ if (press.current)
100
+ e.preventDefault();
101
+ };
102
+ document.addEventListener('dragstart', guard, true);
103
+ return () => document.removeEventListener('dragstart', guard, true);
104
+ }, []);
92
105
  const release = useCallback((e, cancelled) => {
93
106
  const p = press.current;
94
107
  press.current = null;
@@ -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.2";
21
- export declare const RECORDER_ID = "web/0.1.2";
20
+ export declare const RECORDER_VERSION = "0.1.4";
21
+ export declare const RECORDER_ID = "web/0.1.4";
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.2';
8
+ export const RECORDER_VERSION = '0.1.4';
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitrinka/web",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
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": {