@vitrinka/web 0.6.0 → 0.7.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 (60) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/README.md +127 -4
  3. package/build/hud.iife.js +7 -7
  4. package/build/index.d.ts +1 -0
  5. package/build/recorder/RecorderProvider.js +5 -18
  6. package/build/recorder/api.d.ts +20 -0
  7. package/build/recorder/api.js +21 -9
  8. package/build/recorder/capture/console.d.ts +6 -1
  9. package/build/recorder/capture/console.js +28 -5
  10. package/build/recorder/capture/net.d.ts +10 -1
  11. package/build/recorder/capture/net.js +14 -1
  12. package/build/recorder/capture/redact.d.ts +1 -0
  13. package/build/recorder/capture/redact.js +6 -1
  14. package/build/recorder/capture/rrweb-lane.d.ts +19 -0
  15. package/build/recorder/capture/rrweb-lane.js +109 -0
  16. package/build/recorder/capture/rrweb.d.ts +2 -9
  17. package/build/recorder/capture/rrweb.js +11 -86
  18. package/build/recorder/config.d.ts +3 -1
  19. package/build/recorder/config.js +15 -2
  20. package/build/recorder/flight.d.ts +141 -22
  21. package/build/recorder/flight.js +312 -27
  22. package/build/recorder/hud/host-style.d.ts +14 -0
  23. package/build/recorder/hud/host-style.js +15 -0
  24. package/build/recorder/hud/host.js +1 -1
  25. package/build/recorder/hud/styles.d.ts +1 -11
  26. package/build/recorder/hud/styles.js +1 -12
  27. package/build/recorder/state.d.ts +18 -1
  28. package/build/recorder/state.js +40 -1
  29. package/build/recorder/storage/capture.d.ts +44 -0
  30. package/build/recorder/storage/capture.js +136 -0
  31. package/build/recorder/version.d.ts +2 -2
  32. package/build/recorder/version.js +1 -1
  33. package/build/report/bundle.d.ts +4 -0
  34. package/build/report/bundle.js +30 -0
  35. package/build/report/element.d.ts +86 -0
  36. package/build/report/element.js +146 -0
  37. package/build/report/engine.d.ts +144 -0
  38. package/build/report/engine.js +402 -0
  39. package/build/report/i18n.d.ts +78 -0
  40. package/build/report/i18n.js +151 -0
  41. package/build/report/identity.d.ts +26 -0
  42. package/build/report/identity.js +36 -0
  43. package/build/report/index.d.ts +12 -0
  44. package/build/report/index.js +15 -0
  45. package/build/report/keybind.d.ts +29 -0
  46. package/build/report/keybind.js +99 -0
  47. package/build/report/markers.d.ts +77 -0
  48. package/build/report/markers.js +162 -0
  49. package/build/report/profile.d.ts +62 -0
  50. package/build/report/profile.js +115 -0
  51. package/build/report/recorder-face.d.ts +2 -0
  52. package/build/report/recorder-face.js +20 -0
  53. package/build/report/styles.d.ts +7 -0
  54. package/build/report/styles.js +226 -0
  55. package/build/report/widget.d.ts +111 -0
  56. package/build/report/widget.js +927 -0
  57. package/build/report/wire.d.ts +68 -0
  58. package/build/report/wire.js +96 -0
  59. package/build/report-widget.mjs +229 -0
  60. package/package.json +11 -4
@@ -0,0 +1,927 @@
1
+ /**
2
+ * Report a problem — the report face's UI (QA Studio D12 C, D21 B).
3
+ *
4
+ * - A large floating "Report a problem" button (hidden with `button: false`;
5
+ * the host then opens it from its own control, `open-selector`, or
6
+ * `open()`), and the reporter's own shortcut (keybind.ts).
7
+ * - Describe first: a small card "What went wrong?" + Send. The capture is
8
+ * frozen when the card opens (the buffer rolls on).
9
+ * - "Show us where" marks the frozen page: circle, box, arrow, hide, numbered
10
+ * 1, 2, 3… with an optional note each. No element selector. Until the first
11
+ * mark exists a coach card rides beside the pointer with a tiny loop of the
12
+ * gesture and the words "click, hold and move".
13
+ * - Rendered once into the shared HUD host's shadow root (top layer,
14
+ * shielded, blocked from rrweb); `paint()` rewrites text and state in place,
15
+ * so a locale switch keeps the typed draft, the marks and their notes.
16
+ * Drafts live in memory only.
17
+ */
18
+ import { redactUrl } from '../recorder/capture/redact';
19
+ import { createHudHost, createSheetHost, insideHud, sheetTarget } from '../recorder/hud/host';
20
+ import { listen } from '../recorder/hud/listen';
21
+ import { acquireEngine, releaseEngine } from './engine';
22
+ import { browserLocale, parseLocale, strings } from './i18n';
23
+ import { normalizeIdentity, onSharedIdentity, sharedIdentity } from './identity';
24
+ import { keybindLabel, loadKeybind, matchesKeybind, readKeybindPress, saveKeybind, watchKeybind } from './keybind';
25
+ import { arrowEnds, arrowHead, isMark, rectBetween, renumber, toWire, } from './markers';
26
+ import { REPORT_CSS } from './styles';
27
+ import { ReportJob } from './wire';
28
+ const SVG_NS = 'http://www.w3.org/2000/svg';
29
+ const TITLE_CAP = 100;
30
+ const EMPTY_CAPTURE = { chunks: [], truncated: false, console: [], network: [] };
31
+ const TOOLS = ['circle', 'box', 'arrow', 'hide'];
32
+ /** A keyboard mark starts as this, centred; arrows move it 10 px, Shift+arrows resize it. */
33
+ const KB_DRAFT = { w: 160, h: 80 };
34
+ const MIN_KB_SIZE = 16;
35
+ const KB_STEPS = {
36
+ ArrowLeft: [-10, 0],
37
+ ArrowRight: [10, 0],
38
+ ArrowUp: [0, -10],
39
+ ArrowDown: [0, 10],
40
+ };
41
+ const ICON = {
42
+ close: '<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M4 4l8 8M12 4l-8 8" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>',
43
+ gear: '<svg viewBox="0 0 16 16" aria-hidden="true"><circle cx="8" cy="8" r="2.2" fill="none" stroke="currentColor" stroke-width="1.4"/><path d="M8 1.5v2M8 12.5v2M1.5 8h2M12.5 8h2M3.4 3.4l1.4 1.4M11.2 11.2l1.4 1.4M3.4 12.6l1.4-1.4M11.2 4.8l1.4-1.4" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"/></svg>',
44
+ clip: '<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M10.5 4.5l-5 5a1.6 1.6 0 002.3 2.3l5.4-5.4a3 3 0 00-4.2-4.2L3.6 7.6a4.4 4.4 0 006.2 6.2l4-4" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round"/></svg>',
45
+ chevron: '<svg viewBox="0 0 12 12" aria-hidden="true"><path d="M3 4.5l3 3 3-3" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>',
46
+ pen: '<svg viewBox="0 0 16 16" aria-hidden="true"><path d="M10.8 2.7l2.5 2.5-7.6 7.6-3.1 0.6 0.6-3.1z" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linejoin="round"/></svg>',
47
+ check: '<svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="10" fill="none" stroke="currentColor" stroke-width="1.8"/><path d="M7.5 12.3l3 3 6-6.3" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>',
48
+ };
49
+ /** The coach's loop (D21): a pointer presses, holds and goes round the problem. */
50
+ const LOOP_PATH = 'M 134 14 C 200 14, 214 50, 134 50 C 54 50, 68 14, 134 14';
51
+ function coachArt(reduced) {
52
+ const motion = reduced
53
+ ? ''
54
+ : `<animateMotion dur="2.8s" repeatCount="indefinite" keyPoints="0;0;1;1" keyTimes="0;0.18;0.72;1" calcMode="linear" path="${LOOP_PATH}"/>`;
55
+ return ('<svg viewBox="0 0 268 64" aria-hidden="true">' +
56
+ '<rect class="bar" x="84" y="27" width="100" height="10" rx="5"/>' +
57
+ `<path class="loop" d="${LOOP_PATH}" pathLength="200"/>` +
58
+ `<g class="pointer"${reduced ? ' transform="translate(134 14)"' : ''}>` +
59
+ '<circle class="hold" r="9"/>' +
60
+ '<path d="M0 0 L0 15 L4 11 L7 18 L10 16.6 L7 10 L12.5 10 Z" fill="#fff" stroke="#151417" stroke-width="1"/>' +
61
+ `${motion}</g></svg>`);
62
+ }
63
+ function h(tag, attrs = {}, ...kids) {
64
+ const el = document.createElement(tag);
65
+ for (const [k, v] of Object.entries(attrs))
66
+ el.setAttribute(k, v);
67
+ el.append(...kids);
68
+ return el;
69
+ }
70
+ /** One of the constant icons above as a node. */
71
+ function icon(markup) {
72
+ const t = document.createElement('template');
73
+ t.innerHTML = markup;
74
+ const el = t.content.firstElementChild;
75
+ if (!el)
76
+ throw new Error('vitrinka: icon markup is empty');
77
+ return el;
78
+ }
79
+ function svgEl(tag, attrs) {
80
+ const el = document.createElementNS(SVG_NS, tag);
81
+ for (const [k, v] of Object.entries(attrs))
82
+ el.setAttribute(k, String(v));
83
+ return el;
84
+ }
85
+ function titleOf(description) {
86
+ const line = description.split('\n')[0]?.trim() ?? '';
87
+ return line.length > TITLE_CAP ? `${line.slice(0, TITLE_CAP - 1)}…` : line;
88
+ }
89
+ function reducedMotion() {
90
+ return globalThis.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false;
91
+ }
92
+ /** The focused element (HTML or SVG: an SVG link or a tabindexed shape is a control too), through open shadow roots; null when nothing but <body> has it. */
93
+ function deepActiveElement() {
94
+ let active = document.activeElement;
95
+ while (active?.shadowRoot?.activeElement)
96
+ active = active.shadowRoot.activeElement;
97
+ if (active === document.body)
98
+ return null;
99
+ return active instanceof HTMLElement || active instanceof SVGElement ? active : null;
100
+ }
101
+ /** The widget's DOM, built once into the HUD host's shadow mount. */
102
+ function buildDom(mount) {
103
+ const fabLabel = h('span');
104
+ const fabKbd = h('kbd');
105
+ const fab = h('button', { class: 'fab', type: 'button', part: 'button', 'aria-haspopup': 'dialog' }, fabLabel, fabKbd);
106
+ const title = h('h2', { id: 'vr-title' });
107
+ const gear = h('button', { class: 'icon', type: 'button' }, icon(ICON.gear));
108
+ const closeBtn = h('button', { class: 'icon', type: 'button' }, icon(ICON.close));
109
+ const head = h('header', { class: 'head' }, title, gear, closeBtn);
110
+ const prompt = h('label', { class: 'prompt', for: 'vr-desc' });
111
+ const desc = h('textarea', { class: 'desc', id: 'vr-desc', rows: '3' });
112
+ const attachedText = h('span');
113
+ const discloseText = h('span');
114
+ const disclose = h('button', { class: 'link', type: 'button', 'aria-expanded': 'false', 'aria-controls': 'vr-included' }, discloseText, icon(ICON.chevron));
115
+ const attached = h('div', { class: 'attached' }, icon(ICON.clip), attachedText, h('span', { 'aria-hidden': 'true' }, '·'), disclose);
116
+ const included = h('ul', { class: 'included', id: 'vr-included' });
117
+ const markedChips = h('span', { class: 'chips' });
118
+ const markedText = h('span');
119
+ const marked = h('div', { class: 'marked' }, markedChips, markedText);
120
+ const notifyBox = h('input', { type: 'checkbox' });
121
+ const notifyText = h('span');
122
+ const notify = h('label', { class: 'notify' }, notifyBox, notifyText);
123
+ const error = h('p', { class: 'error', role: 'alert' });
124
+ const whereText = h('span');
125
+ const where = h('button', { class: 'where', type: 'button' }, icon(ICON.pen), whereText);
126
+ const send = h('button', { class: 'send', type: 'button' });
127
+ const describe = h('div', { class: 'pane describe' }, prompt, desc, attached, included, marked, notify, error, h('div', { class: 'actions' }, where, send));
128
+ const bindLabel = h('span', { class: 'label', id: 'vr-bind-label' });
129
+ const bindBtn = h('button', { class: 'bind', type: 'button', 'aria-pressed': 'false', 'aria-describedby': 'vr-bind-label' });
130
+ const unbind = h('button', { class: 'link', type: 'button' });
131
+ const bindHint = h('p', { class: 'hint' });
132
+ const bindReason = h('p', { class: 'reason', role: 'status' });
133
+ const back = h('button', { class: 'link', type: 'button' });
134
+ const settings = h('div', { class: 'pane settings' }, h('div', { class: 'row' }, bindLabel, bindBtn), bindReason, bindHint, h('div', { class: 'settings-foot' }, back, unbind));
135
+ const sentTitle = h('h3');
136
+ const sentBody = h('p', { class: 'sent-body' });
137
+ const seeText = h('span');
138
+ const see = h('a', { class: 'see', target: '_blank', rel: 'noopener noreferrer' }, seeText);
139
+ const sentClose = h('button', { class: 'link', type: 'button' });
140
+ const sent = h('div', { class: 'pane sent', role: 'status' }, h('div', { class: 'sent-head' }, icon(ICON.check), sentTitle), sentBody, h('div', { class: 'sent-actions' }, see, sentClose));
141
+ const card = h('section', { class: 'card', role: 'dialog', 'aria-modal': 'false', 'aria-labelledby': 'vr-title' }, head, describe, settings, sent);
142
+ const ink = svgEl('svg', { class: 'ink', 'aria-hidden': 'true' });
143
+ const defs = svgEl('defs', {});
144
+ const headMarker = svgEl('marker', { id: 'vr-head', viewBox: '0 0 10 10', refX: 7, refY: 5, markerWidth: 5, markerHeight: 5, orient: 'auto-start-reverse' });
145
+ headMarker.append(svgEl('path', { d: 'M0 0L10 5L0 10z', fill: '#dc2f4c' }));
146
+ defs.append(headMarker);
147
+ const shapes = svgEl('g', {});
148
+ const draft = svgEl('g', { class: 'draft' });
149
+ ink.append(defs, shapes, draft);
150
+ const pins = h('div', { class: 'pins' });
151
+ const coachText = h('p');
152
+ const coachMore = h('p');
153
+ const coachKeys = h('p', { class: 'keys', id: 'vr-keys' });
154
+ const coach = h('div', { class: 'coach', role: 'status' });
155
+ coach.append(icon(coachArt(reducedMotion())), coachText, coachMore, coachKeys);
156
+ const toolButtons = new Map();
157
+ for (const t of TOOLS)
158
+ toolButtons.set(t, h('button', { type: 'button', 'aria-pressed': 'false', 'data-tool': t }));
159
+ const undo = h('button', { type: 'button' });
160
+ const done = h('button', { type: 'button', class: 'done' });
161
+ const toolbar = h('div', { class: 'toolbar', role: 'toolbar' }, ...toolButtons.values(), h('span', { class: 'sep', 'aria-hidden': 'true' }), undo, done);
162
+ // Focusable: from the keyboard, Enter places a mark the arrows then move (markKey).
163
+ const mark = h('div', { class: 'mark', tabindex: '0', role: 'application', 'aria-describedby': 'vr-keys' }, pins, coach, toolbar);
164
+ mark.prepend(ink);
165
+ const root = h('div', { class: 'vr' }, fab, card, mark);
166
+ const style = h('style');
167
+ style.textContent = REPORT_CSS;
168
+ // The sheet rides inside the root: the whole tree moves into an open dialog and back (followDialog).
169
+ root.prepend(style);
170
+ mount.append(root);
171
+ return {
172
+ root, fab, fabLabel, fabKbd, card, title, gear, closeBtn,
173
+ describe, prompt, desc, attached, attachedText, disclose, discloseText, included, marked, markedChips, markedText,
174
+ notify, notifyBox, notifyText, error, where, whereText, send,
175
+ settings, bindLabel, bindBtn, unbind, bindHint, bindReason, back,
176
+ sent, sentTitle, sentBody, see, seeText, sentClose,
177
+ mark, ink, shapes, draft, pins, coach, coachText, coachMore, coachKeys, toolButtons, toolbar, undo, done,
178
+ };
179
+ }
180
+ export class ReportWidget {
181
+ opts;
182
+ hud;
183
+ engine;
184
+ config = null;
185
+ locale;
186
+ s;
187
+ button;
188
+ openSelector;
189
+ /** This widget's own word: undefined defers to the page-wide identity; null is anonymous. */
190
+ identity;
191
+ keybind;
192
+ isOpen = false;
193
+ /** Where focus was when the card opened, outside the report: close() hands it back. */
194
+ opener = null;
195
+ view = 'describe';
196
+ marking = false;
197
+ markers = [];
198
+ nextKey = 1;
199
+ tool = 'circle';
200
+ frozen = null;
201
+ job = null;
202
+ sending = false;
203
+ error = '';
204
+ result = null;
205
+ notify = false;
206
+ sentNotify = false;
207
+ includedOpen = false;
208
+ recordingBind = false;
209
+ bindRefused = false;
210
+ /** The note input the reporter is in (or just drew); others with no text fold away. */
211
+ noteOpen = null;
212
+ drawing = null;
213
+ offs = [];
214
+ pins = new Map();
215
+ /** Per hide mark: the page nodes it covered when drawn (they are blanked in the capture). */
216
+ hideIds = new Map();
217
+ /** Native dialogs in the order they opened (seeded with those already open, in DOM order). */
218
+ dialogOrder = [...document.querySelectorAll('dialog[open]')].filter((d) => d instanceof HTMLDialogElement);
219
+ /**
220
+ * Where the report must live: the modal shown last (only the top modal is
221
+ * not inert), else the dialog opened last, else the recorder's rule
222
+ * (`sheetTarget`: ARIA dialogs included).
223
+ */
224
+ activeDialog() {
225
+ this.dialogOrder = this.dialogOrder.filter((d) => d.isConnected && d.open);
226
+ const isModal = (d) => {
227
+ try {
228
+ return d.matches(':modal');
229
+ }
230
+ catch {
231
+ return false; // a browser without :modal: opening order decides
232
+ }
233
+ };
234
+ const modal = [...this.dialogOrder].reverse().find(isModal);
235
+ return modal ?? this.dialogOrder.at(-1) ?? sheetTarget();
236
+ }
237
+ /** The open dialog the report lives in while one is up (a modal makes everything outside it inert). */
238
+ sheet = null;
239
+ e;
240
+ constructor(opts) {
241
+ this.opts = opts;
242
+ this.locale = opts.locale ?? browserLocale();
243
+ this.s = strings(this.locale);
244
+ this.button = opts.button;
245
+ this.openSelector = opts.openSelector ?? null;
246
+ this.identity = opts.identity === undefined ? undefined : normalizeIdentity(opts.identity);
247
+ this.keybind = loadKeybind();
248
+ this.hud = createHudHost();
249
+ this.e = buildDom(this.hud.mount);
250
+ this.engine = acquireEngine({
251
+ base: opts.base,
252
+ key: opts.key,
253
+ appVersion: opts.appVersion,
254
+ capture: opts.capture,
255
+ sanitizeUrl: opts.sanitizeUrl,
256
+ loadRecord: opts.loadRecord,
257
+ });
258
+ void this.engine?.ready.then((c) => {
259
+ this.config = c;
260
+ this.paint();
261
+ });
262
+ this.bind();
263
+ this.paint();
264
+ this.followDialog();
265
+ }
266
+ /**
267
+ * Live inside the topmost open dialog while there is one (the recorder's
268
+ * sheet path, hud/host.ts): a modal makes everything outside it inert and
269
+ * its focus trap pulls focus back. The one DOM tree moves, so the draft,
270
+ * the marks and their notes go along; focus is restored after the move.
271
+ */
272
+ followDialog() {
273
+ const target = this.activeDialog();
274
+ if ((this.sheet?.target ?? null) === target)
275
+ return;
276
+ const root = this.e.root.getRootNode();
277
+ const focused = root instanceof ShadowRoot && root.activeElement instanceof HTMLElement ? root.activeElement : null;
278
+ const previous = this.sheet;
279
+ if (target) {
280
+ const host = createSheetHost(target);
281
+ host.mount.append(this.e.root);
282
+ this.sheet = { target, host };
283
+ }
284
+ else {
285
+ this.hud.mount.append(this.e.root);
286
+ this.sheet = null;
287
+ }
288
+ previous?.host.destroy();
289
+ focused?.focus();
290
+ }
291
+ // -- public -------------------------------------------------------------
292
+ open() {
293
+ if (this.isOpen)
294
+ return;
295
+ this.isOpen = true;
296
+ this.opener = insideHud(document.activeElement) ? null : deepActiveElement();
297
+ if (this.view !== 'describe')
298
+ this.view = 'describe';
299
+ this.result = null;
300
+ // The minutes before THIS open; a half-sent report keeps the capture it started with.
301
+ if (!this.job)
302
+ this.frozen = this.engine?.freeze() ?? null;
303
+ this.paint();
304
+ requestAnimationFrame(() => this.e.desc.focus());
305
+ }
306
+ close() {
307
+ if (!this.isOpen)
308
+ return;
309
+ if (this.marking)
310
+ this.endMarking(false);
311
+ this.stopRecordingBind();
312
+ this.isOpen = false;
313
+ this.view = 'describe';
314
+ this.paint();
315
+ // Focus goes back where it came from — the host's control, the field the
316
+ // shortcut fired in — else to the button; never lost to <body> when the
317
+ // host hid the button and opened the card from its own control.
318
+ const opener = this.opener;
319
+ this.opener = null;
320
+ opener?.focus();
321
+ if (opener && deepActiveElement() === opener)
322
+ return;
323
+ if (this.button)
324
+ this.e.fab.focus();
325
+ }
326
+ setLocale(raw) {
327
+ const next = parseLocale(raw) ?? browserLocale();
328
+ if (next === this.locale)
329
+ return;
330
+ this.locale = next;
331
+ this.s = strings(next);
332
+ this.paint();
333
+ }
334
+ setButton(on) {
335
+ this.button = on;
336
+ this.paint();
337
+ }
338
+ setOpenSelector(sel) {
339
+ this.openSelector = sel || null;
340
+ }
341
+ identify(input) {
342
+ // null (or a malformed identity) is this widget going anonymous; undefined hands it back to the page-wide one.
343
+ this.identity = input === undefined ? undefined : normalizeIdentity(input);
344
+ this.paint();
345
+ }
346
+ unmount() {
347
+ this.stopRecordingBind();
348
+ for (const off of this.offs.splice(0).reverse())
349
+ off();
350
+ releaseEngine(this.engine);
351
+ this.sheet?.host.destroy();
352
+ this.sheet = null;
353
+ this.hud.destroy();
354
+ }
355
+ // -- behaviour ------------------------------------------------------------
356
+ bind() {
357
+ const e = this.e;
358
+ const on = (el, type, fn) => {
359
+ el.addEventListener(type, fn);
360
+ };
361
+ on(e.fab, 'click', () => (this.isOpen ? this.close() : this.open()));
362
+ on(e.closeBtn, 'click', () => this.close());
363
+ on(e.gear, 'click', () => this.show(this.view === 'settings' ? 'describe' : 'settings'));
364
+ on(e.back, 'click', () => this.show('describe'));
365
+ on(e.sentClose, 'click', () => this.close());
366
+ on(e.desc, 'input', () => this.paint());
367
+ on(e.disclose, 'click', () => {
368
+ this.includedOpen = !this.includedOpen;
369
+ this.paint();
370
+ });
371
+ on(e.notifyBox, 'change', () => {
372
+ this.notify = e.notifyBox.checked;
373
+ });
374
+ on(e.where, 'click', () => this.startMarking());
375
+ on(e.send, 'click', () => void this.send());
376
+ on(e.bindBtn, 'click', () => (this.recordingBind ? this.stopRecordingBind() : this.startRecordingBind()));
377
+ on(e.unbind, 'click', () => {
378
+ this.keybind = null;
379
+ saveKeybind(null);
380
+ this.paint();
381
+ });
382
+ on(e.card, 'keydown', (ev) => {
383
+ if (ev.key !== 'Escape' || this.recordingBind)
384
+ return;
385
+ ev.preventDefault();
386
+ if (this.view === 'settings')
387
+ this.show('describe');
388
+ else
389
+ this.close();
390
+ });
391
+ for (const [tool, btn] of e.toolButtons) {
392
+ on(btn, 'click', (ev) => {
393
+ this.tool = tool;
394
+ this.renderKbDraft();
395
+ this.paint();
396
+ // From the keyboard (no pointer: detail 0), go straight back to drawing with it.
397
+ if (ev.detail === 0)
398
+ e.mark.focus();
399
+ });
400
+ }
401
+ on(e.mark, 'keydown', (ev) => this.markKey(ev));
402
+ on(e.undo, 'click', () => {
403
+ this.markers = renumberDrawn(this.markers.slice(0, -1));
404
+ this.renderMarks();
405
+ this.paint();
406
+ });
407
+ on(e.done, 'click', () => this.endMarking(true));
408
+ on(e.mark, 'pointerdown', (ev) => this.pointerDown(ev));
409
+ on(e.mark, 'pointermove', (ev) => this.pointerMove(ev));
410
+ on(e.mark, 'pointerup', (ev) => this.pointerUp(ev));
411
+ on(e.mark, 'pointercancel', () => this.cancelDraft());
412
+ // The page is frozen while marking: it never scrolls under the marks.
413
+ this.offs.push(listen(e.mark, 'wheel', (ev) => ev.preventDefault()));
414
+ this.offs.push(listen(e.mark, 'touchmove', (ev) => ev.preventDefault()));
415
+ this.offs.push(listen(window, 'keydown', (ev) => {
416
+ if (this.recordingBind)
417
+ return;
418
+ if (this.marking && ev.key === 'Escape') {
419
+ ev.preventDefault();
420
+ // Esc drops a keyboard mark being placed; the next one leaves marking.
421
+ if (this.kbDraft)
422
+ this.cancelDraft();
423
+ else
424
+ this.endMarking(true);
425
+ return;
426
+ }
427
+ if (this.keybind && matchesKeybind(ev, this.keybind)) {
428
+ ev.preventDefault();
429
+ if (this.isOpen)
430
+ this.close();
431
+ else
432
+ this.open();
433
+ }
434
+ }, { capture: true }));
435
+ this.offs.push(listen(document, 'click', (ev) => {
436
+ const sel = this.openSelector;
437
+ const t = ev.target;
438
+ if (!sel || !(t instanceof Element))
439
+ return;
440
+ let hit = null;
441
+ try {
442
+ hit = t.closest(sel);
443
+ }
444
+ catch {
445
+ return; // not a selector: nothing of the page opens the card
446
+ }
447
+ if (!hit)
448
+ return;
449
+ ev.preventDefault();
450
+ this.open();
451
+ }));
452
+ this.offs.push(watchKeybind((b) => {
453
+ this.keybind = b;
454
+ this.paint();
455
+ }));
456
+ this.offs.push(onSharedIdentity(() => this.paint()));
457
+ // The recorder took the page's capture over: stop saying minutes are attached.
458
+ if (this.engine)
459
+ this.offs.push(this.engine.onChange(() => this.paint()));
460
+ // Dialogs open and close anywhere: follow them, at most once a frame.
461
+ let frame = 0;
462
+ const dialogs = new MutationObserver((records) => {
463
+ // The order dialogs open in: a modal shown later sits on top, whatever the DOM order.
464
+ // Only a closed → open transition is an opening; a redundant write to an open dialog changes nothing.
465
+ for (const r of records) {
466
+ if (r.type !== 'attributes' || r.attributeName !== 'open' || !(r.target instanceof HTMLDialogElement))
467
+ continue;
468
+ const target = r.target;
469
+ if (!target.open)
470
+ this.dialogOrder = this.dialogOrder.filter((d) => d !== target);
471
+ else if (r.oldValue === null)
472
+ this.dialogOrder = [...this.dialogOrder.filter((d) => d !== target), target];
473
+ }
474
+ if (frame)
475
+ return;
476
+ frame = requestAnimationFrame(() => {
477
+ frame = 0;
478
+ this.followDialog();
479
+ });
480
+ });
481
+ dialogs.observe(document.documentElement, {
482
+ subtree: true,
483
+ childList: true,
484
+ attributes: true,
485
+ attributeOldValue: true,
486
+ attributeFilter: ['open', 'data-state'],
487
+ });
488
+ this.offs.push(() => {
489
+ dialogs.disconnect();
490
+ if (frame)
491
+ cancelAnimationFrame(frame);
492
+ });
493
+ }
494
+ show(view) {
495
+ this.stopRecordingBind();
496
+ this.view = view;
497
+ this.paint();
498
+ if (view === 'describe')
499
+ requestAnimationFrame(() => this.e.desc.focus());
500
+ if (view === 'settings')
501
+ requestAnimationFrame(() => this.e.bindBtn.focus());
502
+ }
503
+ who() {
504
+ return this.identity !== undefined ? this.identity : sharedIdentity();
505
+ }
506
+ // -- the shortcut recorder ----------------------------------------------
507
+ stopBindListener = null;
508
+ startRecordingBind() {
509
+ this.recordingBind = true;
510
+ this.bindRefused = false;
511
+ this.stopBindListener = listen(window, 'keydown', (ev) => {
512
+ ev.preventDefault();
513
+ ev.stopPropagation();
514
+ const verdict = readKeybindPress(ev);
515
+ if (verdict.kind === 'wait')
516
+ return;
517
+ if (verdict.kind === 'bare') {
518
+ this.bindRefused = true;
519
+ this.paint();
520
+ return;
521
+ }
522
+ if (verdict.kind === 'bind') {
523
+ this.keybind = verdict.bind;
524
+ saveKeybind(verdict.bind);
525
+ }
526
+ this.stopRecordingBind();
527
+ }, { capture: true });
528
+ this.paint();
529
+ }
530
+ stopRecordingBind() {
531
+ if (!this.recordingBind)
532
+ return;
533
+ this.recordingBind = false;
534
+ this.bindRefused = false;
535
+ this.stopBindListener?.();
536
+ this.stopBindListener = null;
537
+ this.paint();
538
+ }
539
+ // -- marking --------------------------------------------------------------
540
+ startMarking() {
541
+ if (this.job?.id)
542
+ return; // the report is on its way: Retry finishes it as it was marked
543
+ this.marking = true;
544
+ this.noteOpen = null;
545
+ this.renderMarks();
546
+ this.paint();
547
+ const vw = globalThis.innerWidth || 800;
548
+ const vh = globalThis.innerHeight || 600;
549
+ this.placeCoach({ x: vw / 2 - 150, y: vh - 260 }, false);
550
+ this.e.mark.focus();
551
+ }
552
+ endMarking(backToCard) {
553
+ this.cancelDraft();
554
+ this.marking = false;
555
+ this.noteOpen = null;
556
+ this.paint();
557
+ if (backToCard && this.isOpen)
558
+ requestAnimationFrame(() => this.e.desc.focus());
559
+ }
560
+ onChrome(t) {
561
+ return t instanceof Node && (this.e.toolbar.contains(t) || this.e.pins.contains(t));
562
+ }
563
+ pointerDown(ev) {
564
+ if (this.onChrome(ev.target) || ev.button !== 0 || !ev.isPrimary)
565
+ return;
566
+ ev.preventDefault();
567
+ const root = this.e.root.getRootNode();
568
+ if (root instanceof ShadowRoot && root.activeElement instanceof HTMLElement)
569
+ root.activeElement.blur();
570
+ this.noteOpen = null;
571
+ this.drawing = { start: { x: ev.clientX, y: ev.clientY }, shape: this.tool, pointer: ev.pointerId };
572
+ try {
573
+ this.e.mark.setPointerCapture(ev.pointerId);
574
+ }
575
+ catch {
576
+ // a synthetic pointer: no capture needed
577
+ }
578
+ this.e.coach.classList.add('pressing');
579
+ this.renderPins();
580
+ }
581
+ pointerMove(ev) {
582
+ if (!this.markers.length)
583
+ this.placeCoach({ x: ev.clientX, y: ev.clientY }, true);
584
+ const d = this.drawing;
585
+ if (!d || ev.pointerId !== d.pointer)
586
+ return;
587
+ this.e.draft.replaceChildren(...this.shapeNodes({ shape: d.shape, rect: rectBetween(d.start, { x: ev.clientX, y: ev.clientY }), head: arrowHead(d.start, { x: ev.clientX, y: ev.clientY }) }));
588
+ }
589
+ pointerUp(ev) {
590
+ const d = this.drawing;
591
+ if (!d || ev.pointerId !== d.pointer)
592
+ return;
593
+ const end = { x: ev.clientX, y: ev.clientY };
594
+ this.cancelDraft();
595
+ if (!isMark(d.shape, d.start, end))
596
+ return;
597
+ this.addMarker(d.shape, rectBetween(d.start, end), d.shape === 'arrow' ? arrowHead(d.start, end) : undefined);
598
+ }
599
+ /** A new numbered mark; a hide also names the page nodes under it now, while the page sits frozen. */
600
+ addMarker(shape, rect, head) {
601
+ const key = this.nextKey++;
602
+ if (shape === 'hide') {
603
+ const ids = this.engine?.hiddenIdsAt(rect);
604
+ if (ids)
605
+ this.hideIds.set(key, ids);
606
+ }
607
+ this.markers = renumberDrawn([...this.markers, { key, n: this.markers.length + 1, shape, rect, note: '', ...(head ? { head } : {}) }]);
608
+ this.noteOpen = key;
609
+ this.renderMarks();
610
+ this.paint();
611
+ this.pins.get(key)?.note.focus();
612
+ }
613
+ cancelDraft() {
614
+ this.drawing = null;
615
+ this.kbDraft = null;
616
+ this.e.draft.replaceChildren();
617
+ this.e.coach.classList.remove('pressing');
618
+ }
619
+ // -- marking from the keyboard (Enter starts, arrows move, Shift+arrows resize, Enter places) --
620
+ kbDraft = null;
621
+ markKey(ev) {
622
+ if (ev.target !== this.e.mark)
623
+ return;
624
+ const vw = globalThis.innerWidth || 800;
625
+ const vh = globalThis.innerHeight || 600;
626
+ if (ev.key === 'Enter' || ev.key === ' ') {
627
+ ev.preventDefault();
628
+ if (!this.kbDraft) {
629
+ this.kbDraft = { x: Math.round(vw / 2 - KB_DRAFT.w / 2), y: Math.round(vh / 2 - KB_DRAFT.h / 2), ...KB_DRAFT };
630
+ this.renderKbDraft();
631
+ return;
632
+ }
633
+ const rect = this.kbDraft;
634
+ this.cancelDraft();
635
+ this.addMarker(this.tool, rect, this.tool === 'arrow' ? 'se' : undefined);
636
+ return;
637
+ }
638
+ const step = KB_STEPS[ev.key];
639
+ if (!step || !this.kbDraft)
640
+ return;
641
+ ev.preventDefault();
642
+ const d = this.kbDraft;
643
+ const [dx, dy] = step;
644
+ this.kbDraft = ev.shiftKey
645
+ ? { ...d, w: Math.min(vw - d.x, Math.max(MIN_KB_SIZE, d.w + dx)), h: Math.min(vh - d.y, Math.max(MIN_KB_SIZE, d.h + dy)) }
646
+ : { ...d, x: Math.min(vw - d.w, Math.max(0, d.x + dx)), y: Math.min(vh - d.h, Math.max(0, d.y + dy)) };
647
+ this.renderKbDraft();
648
+ }
649
+ renderKbDraft() {
650
+ const r = this.kbDraft;
651
+ if (!r)
652
+ return;
653
+ this.e.draft.replaceChildren(...this.shapeNodes({ shape: this.tool, rect: r, head: 'se' }));
654
+ }
655
+ /** The coach rides beside the pointer, inside the viewport. */
656
+ placeCoach(p, beside) {
657
+ const vw = globalThis.innerWidth || 800;
658
+ const vh = globalThis.innerHeight || 600;
659
+ const w = this.e.coach.offsetWidth || 300;
660
+ const hgt = this.e.coach.offsetHeight || 140;
661
+ let x = beside ? p.x + 20 : p.x;
662
+ let y = beside ? p.y + 20 : p.y;
663
+ if (x + w > vw - 8)
664
+ x = beside ? p.x - w - 20 : vw - w - 8;
665
+ if (y + hgt > vh - 90)
666
+ y = beside ? p.y - hgt - 20 : vh - hgt - 90;
667
+ this.e.coach.style.left = `${Math.max(8, x)}px`;
668
+ this.e.coach.style.top = `${Math.max(8, y)}px`;
669
+ }
670
+ shapeNodes(m) {
671
+ const { x, y, w, h: hh } = m.rect;
672
+ if (m.shape === 'circle') {
673
+ return [svgEl('ellipse', { class: 'stroke', cx: x + w / 2, cy: y + hh / 2, rx: Math.max(1, w / 2), ry: Math.max(1, hh / 2) })];
674
+ }
675
+ if (m.shape === 'box')
676
+ return [svgEl('rect', { class: 'stroke', x, y, width: w, height: hh, rx: 6 })];
677
+ if (m.shape === 'arrow') {
678
+ const { tail, tip } = arrowEnds(m.rect, m.head ?? 'se');
679
+ return [svgEl('line', { class: 'stroke', x1: tail.x, y1: tail.y, x2: tip.x, y2: tip.y, 'marker-end': 'url(#vr-head)' })];
680
+ }
681
+ const veil = svgEl('rect', { class: 'veil', x, y, width: w, height: hh, rx: 4 });
682
+ const label = svgEl('text', { class: 'veil-label', x: x + w / 2, y: y + hh / 2 + 4, 'text-anchor': 'middle' });
683
+ label.textContent = w > 60 && hh > 20 ? this.s.hidden : '';
684
+ return [veil, label];
685
+ }
686
+ renderMarks() {
687
+ this.e.shapes.replaceChildren(...this.markers.flatMap((m) => this.shapeNodes(m)));
688
+ const live = new Set(this.markers.map((m) => m.key));
689
+ for (const [key, pin] of this.pins) {
690
+ if (live.has(key))
691
+ continue;
692
+ pin.el.remove();
693
+ this.pins.delete(key);
694
+ }
695
+ for (const m of this.markers) {
696
+ if (this.pins.has(m.key))
697
+ continue;
698
+ const num = h('button', { class: 'num', type: 'button' });
699
+ const note = h('input', { class: 'note', type: 'text', maxlength: '500' });
700
+ const rm = h('button', { class: 'rm', type: 'button' }, icon(ICON.close));
701
+ const el = h('div', { class: 'pin' }, num, note, rm);
702
+ num.addEventListener('click', () => {
703
+ this.noteOpen = m.key;
704
+ this.renderPins();
705
+ note.focus();
706
+ });
707
+ note.addEventListener('input', () => {
708
+ this.markers = this.markers.map((x) => (x.key === m.key ? { ...x, note: note.value } : x));
709
+ });
710
+ note.addEventListener('focus', () => {
711
+ this.noteOpen = m.key;
712
+ this.renderPins();
713
+ });
714
+ note.addEventListener('keydown', (ev) => {
715
+ if (ev.key !== 'Enter')
716
+ return;
717
+ ev.preventDefault();
718
+ // Back to the page, ready for the next mark from the keyboard.
719
+ this.e.mark.focus();
720
+ });
721
+ rm.addEventListener('click', () => {
722
+ this.markers = renumberDrawn(this.markers.filter((x) => x.key !== m.key));
723
+ this.renderMarks();
724
+ this.paint();
725
+ });
726
+ this.e.pins.append(el);
727
+ this.pins.set(m.key, { el, num, note, rm });
728
+ }
729
+ this.renderPins();
730
+ }
731
+ /** Pin numbers, positions and which notes show; text in place (the locale may have changed). */
732
+ renderPins() {
733
+ const vw = globalThis.innerWidth || 800;
734
+ for (const m of this.markers) {
735
+ const pin = this.pins.get(m.key);
736
+ if (!pin)
737
+ continue;
738
+ const anchor = m.shape === 'arrow' ? arrowEnds(m.rect, m.head ?? 'se').tail : { x: m.rect.x, y: m.rect.y };
739
+ const showNote = this.noteOpen === m.key || m.note.trim() !== '';
740
+ const width = showNote ? 290 : 30;
741
+ pin.el.style.left = `${Math.min(Math.max(4, anchor.x - 12), vw - width)}px`;
742
+ pin.el.style.top = `${Math.max(4, anchor.y - 12)}px`;
743
+ pin.num.textContent = String(m.n);
744
+ pin.num.setAttribute('aria-label', this.s.mark(m.n));
745
+ pin.note.hidden = !showNote;
746
+ pin.rm.hidden = !showNote;
747
+ pin.note.placeholder = this.s.notePlaceholder;
748
+ pin.note.setAttribute('aria-label', `${this.s.mark(m.n)} — ${this.s.notePlaceholder}`);
749
+ pin.rm.setAttribute('aria-label', this.s.removeMark(m.n));
750
+ }
751
+ }
752
+ // -- sending --------------------------------------------------------------
753
+ envelope(description, capture) {
754
+ const who = this.who();
755
+ const loc = globalThis.location;
756
+ return {
757
+ title: titleOf(description),
758
+ description,
759
+ env: {
760
+ url: redactUrl(loc ? `${loc.origin}${loc.pathname}` : ''),
761
+ ua: globalThis.navigator?.userAgent ?? '',
762
+ viewport: { w: globalThis.innerWidth || 0, h: globalThis.innerHeight || 0, dpr: globalThis.devicePixelRatio || 1 },
763
+ appVersion: this.opts.appVersion ?? '',
764
+ locale: globalThis.navigator?.language ?? '',
765
+ },
766
+ console: capture.console,
767
+ network: capture.network,
768
+ ...(who ? { identity: who, notify: this.notify } : {}),
769
+ markers: toWire(this.markers),
770
+ locale: this.locale,
771
+ };
772
+ }
773
+ async send() {
774
+ const description = this.e.desc.value.trim();
775
+ if (this.sending || !description)
776
+ return;
777
+ this.sending = true;
778
+ this.error = '';
779
+ this.paint();
780
+ // Nothing reached the server yet: build again, with the marks as they are now.
781
+ if (this.job && !this.job.id)
782
+ this.job = null;
783
+ try {
784
+ if (!this.job) {
785
+ const marked = new Set();
786
+ for (const m of this.markers)
787
+ for (const id of this.hideIds.get(m.key) ?? [])
788
+ marked.add(id);
789
+ const capture = this.engine
790
+ ? await this.engine.build(this.frozen ?? { clip: null, stored: Promise.resolve(new Map()) }, this.markers, marked).catch((e) => {
791
+ console.warn('vitrinka: the capture could not be prepared — the report goes without it', e);
792
+ return EMPTY_CAPTURE;
793
+ })
794
+ : EMPTY_CAPTURE;
795
+ this.job = new ReportJob(capture, globalThis.location?.host ?? '', { url: this.opts.base, key: this.opts.key });
796
+ }
797
+ this.result = await this.job.run(this.envelope(description, this.job.capture));
798
+ this.sentNotify = this.notify && this.who() !== null;
799
+ this.view = 'sent';
800
+ this.job = null;
801
+ this.frozen = null;
802
+ this.e.desc.value = '';
803
+ this.markers = [];
804
+ this.hideIds.clear();
805
+ this.notify = false;
806
+ this.e.notifyBox.checked = false;
807
+ this.includedOpen = false;
808
+ this.renderMarks();
809
+ this.engine?.clear();
810
+ }
811
+ catch (e) {
812
+ console.warn('vitrinka: the report did not go through — Retry resumes it', e);
813
+ this.error = this.job?.id ? 'capture' : 'create';
814
+ }
815
+ finally {
816
+ this.sending = false;
817
+ this.paint();
818
+ }
819
+ if (this.view === 'sent')
820
+ requestAnimationFrame(() => (this.result?.reportUrl ? this.e.see : this.e.sentClose).focus());
821
+ }
822
+ // -- paint: every string and state, in place -------------------------------
823
+ includedItems() {
824
+ const s = this.s;
825
+ const items = [];
826
+ const lanes = this.config?.lanes;
827
+ if (lanes?.replay)
828
+ items.push(`${s.incReplay} — ${s.incReplayMasked[this.config?.masking ?? 'strict'].toLowerCase()}`);
829
+ if (lanes?.errors)
830
+ items.push(s.incErrors);
831
+ if (lanes?.console)
832
+ items.push(s.incConsole);
833
+ if (lanes?.network)
834
+ items.push(s.incNetwork);
835
+ else if (lanes?.errors)
836
+ items.push(s.incFailedRequests);
837
+ items.push(s.incEnv);
838
+ if (this.who())
839
+ items.push(s.incIdentity);
840
+ if (this.markers.length)
841
+ items.push(s.incMarks);
842
+ return items;
843
+ }
844
+ paint() {
845
+ const { e, s } = this;
846
+ const who = this.who();
847
+ e.root.setAttribute('lang', this.locale);
848
+ e.root.classList.toggle('nobutton', !this.button);
849
+ e.fab.hidden = !this.button || this.marking;
850
+ e.fabLabel.textContent = s.button;
851
+ e.fab.setAttribute('aria-expanded', String(this.isOpen));
852
+ e.fabKbd.hidden = !this.keybind;
853
+ e.fabKbd.textContent = this.keybind ? keybindLabel(this.keybind) : '';
854
+ e.card.hidden = !this.isOpen || this.marking;
855
+ e.title.textContent = s.title;
856
+ e.gear.setAttribute('aria-label', s.settings);
857
+ e.gear.setAttribute('aria-pressed', String(this.view === 'settings'));
858
+ e.closeBtn.setAttribute('aria-label', s.close);
859
+ e.describe.hidden = this.view !== 'describe';
860
+ e.settings.hidden = this.view !== 'settings';
861
+ e.sent.hidden = this.view !== 'sent';
862
+ e.prompt.textContent = s.prompt;
863
+ e.desc.placeholder = s.placeholder;
864
+ e.attachedText.textContent = s.attached(this.config?.profile.windowSec ?? 60);
865
+ // Only a widget that captures says the minutes are attached.
866
+ e.attached.hidden = this.engine === null || this.config?.capturing === false;
867
+ e.discloseText.textContent = s.included;
868
+ e.disclose.setAttribute('aria-expanded', String(this.includedOpen));
869
+ e.included.hidden = !this.includedOpen;
870
+ e.included.replaceChildren(...this.includedItems().map((t) => h('li', {}, t)));
871
+ e.marked.hidden = this.markers.length === 0;
872
+ e.markedChips.replaceChildren(...this.markers.map((m) => h('span', { class: m.shape === 'hide' ? 'chip hide' : 'chip', 'aria-hidden': 'true' }, String(m.n))));
873
+ e.markedText.textContent = s.marked(this.markers.length);
874
+ e.notify.hidden = who === null;
875
+ e.notifyText.textContent = s.notify;
876
+ e.error.hidden = this.error === '';
877
+ e.error.textContent = this.error === 'create' ? s.errorCreate : this.error === 'capture' ? s.errorCapture : '';
878
+ e.whereText.textContent = s.showWhere;
879
+ e.where.disabled = this.sending || Boolean(this.job?.id);
880
+ e.send.textContent = this.sending ? s.sending : this.error ? s.retry : s.send;
881
+ e.send.disabled = this.sending || e.desc.value.trim() === '';
882
+ e.bindLabel.textContent = s.shortcut;
883
+ e.bindBtn.setAttribute('aria-pressed', String(this.recordingBind));
884
+ e.bindBtn.setAttribute('aria-label', `${s.shortcut}: ${this.keybind ? keybindLabel(this.keybind) : s.notSet} — ${s.recordShortcut}`);
885
+ e.bindBtn.textContent = this.recordingBind ? s.pressKeys : this.keybind ? keybindLabel(this.keybind) : s.notSet;
886
+ e.unbind.textContent = s.removeShortcut;
887
+ e.unbind.hidden = !this.keybind || this.recordingBind;
888
+ e.bindHint.textContent = s.shortcutHint;
889
+ e.bindReason.hidden = !this.bindRefused;
890
+ e.bindReason.textContent = this.bindRefused ? s.needModifier : '';
891
+ e.back.textContent = s.back;
892
+ e.sentTitle.textContent = s.sentTitle;
893
+ e.sentBody.textContent = this.sentNotify ? s.sentNotify : s.sentBody;
894
+ e.seeText.textContent = s.seeReport;
895
+ const url = this.result?.reportUrl;
896
+ e.see.hidden = !url;
897
+ if (url)
898
+ e.see.setAttribute('href', url);
899
+ else
900
+ e.see.removeAttribute('href');
901
+ e.sentClose.textContent = s.close;
902
+ e.mark.hidden = !this.marking;
903
+ e.toolbar.setAttribute('aria-label', s.toolbar);
904
+ for (const [tool, btn] of e.toolButtons) {
905
+ btn.textContent = s.tools[tool];
906
+ btn.setAttribute('aria-pressed', String(this.tool === tool));
907
+ }
908
+ e.undo.textContent = s.undo;
909
+ e.undo.disabled = this.markers.length === 0;
910
+ e.done.textContent = s.done;
911
+ e.coach.hidden = !this.marking || this.markers.length > 0;
912
+ e.coachText.textContent = s.coach;
913
+ e.coachMore.textContent = s.coachMore;
914
+ e.coachKeys.textContent = s.keyboardHint;
915
+ e.mark.setAttribute('aria-label', s.marking);
916
+ if (this.marking) {
917
+ for (const label of e.shapes.querySelectorAll('.veil-label')) {
918
+ if (label.textContent)
919
+ label.textContent = s.hidden;
920
+ }
921
+ this.renderPins();
922
+ }
923
+ }
924
+ }
925
+ function renumberDrawn(markers) {
926
+ return renumber(markers).map((m, i) => ({ ...m, key: markers[i].key }));
927
+ }