@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.
- package/CHANGELOG.md +79 -0
- package/README.md +127 -4
- package/build/hud.iife.js +7 -7
- package/build/index.d.ts +1 -0
- package/build/recorder/RecorderProvider.js +5 -18
- package/build/recorder/api.d.ts +20 -0
- package/build/recorder/api.js +21 -9
- package/build/recorder/capture/console.d.ts +6 -1
- package/build/recorder/capture/console.js +28 -5
- package/build/recorder/capture/net.d.ts +10 -1
- package/build/recorder/capture/net.js +14 -1
- package/build/recorder/capture/redact.d.ts +1 -0
- package/build/recorder/capture/redact.js +6 -1
- package/build/recorder/capture/rrweb-lane.d.ts +19 -0
- package/build/recorder/capture/rrweb-lane.js +109 -0
- package/build/recorder/capture/rrweb.d.ts +2 -9
- package/build/recorder/capture/rrweb.js +11 -86
- package/build/recorder/config.d.ts +3 -1
- package/build/recorder/config.js +15 -2
- package/build/recorder/flight.d.ts +141 -22
- package/build/recorder/flight.js +312 -27
- package/build/recorder/hud/host-style.d.ts +14 -0
- package/build/recorder/hud/host-style.js +15 -0
- package/build/recorder/hud/host.js +1 -1
- package/build/recorder/hud/styles.d.ts +1 -11
- package/build/recorder/hud/styles.js +1 -12
- package/build/recorder/state.d.ts +18 -1
- package/build/recorder/state.js +40 -1
- package/build/recorder/storage/capture.d.ts +44 -0
- package/build/recorder/storage/capture.js +136 -0
- package/build/recorder/version.d.ts +2 -2
- package/build/recorder/version.js +1 -1
- package/build/report/bundle.d.ts +4 -0
- package/build/report/bundle.js +30 -0
- package/build/report/element.d.ts +86 -0
- package/build/report/element.js +146 -0
- package/build/report/engine.d.ts +144 -0
- package/build/report/engine.js +402 -0
- package/build/report/i18n.d.ts +78 -0
- package/build/report/i18n.js +151 -0
- package/build/report/identity.d.ts +26 -0
- package/build/report/identity.js +36 -0
- package/build/report/index.d.ts +12 -0
- package/build/report/index.js +15 -0
- package/build/report/keybind.d.ts +29 -0
- package/build/report/keybind.js +99 -0
- package/build/report/markers.d.ts +77 -0
- package/build/report/markers.js +162 -0
- package/build/report/profile.d.ts +62 -0
- package/build/report/profile.js +115 -0
- package/build/report/recorder-face.d.ts +2 -0
- package/build/report/recorder-face.js +20 -0
- package/build/report/styles.d.ts +7 -0
- package/build/report/styles.js +226 -0
- package/build/report/widget.d.ts +111 -0
- package/build/report/widget.js +927 -0
- package/build/report/wire.d.ts +68 -0
- package/build/report/wire.js +96 -0
- package/build/report-widget.mjs +229 -0
- package/package.json +11 -4
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every string Report a problem shows, one catalog per locale (cs, en). The
|
|
3
|
+
* browser's language picks one by default; the host's `locale` option,
|
|
4
|
+
* `locale` attribute and `setLocale()` switch it live — the widget repaints
|
|
5
|
+
* its text in place, so a draft and its marks survive the switch.
|
|
6
|
+
*
|
|
7
|
+
* Marking is taught as "click, hold and move" — never "drag" (D21): a
|
|
8
|
+
* first-time reporter does not know the word.
|
|
9
|
+
*/
|
|
10
|
+
export type Locale = 'cs' | 'en';
|
|
11
|
+
export interface Strings {
|
|
12
|
+
button: string;
|
|
13
|
+
title: string;
|
|
14
|
+
close: string;
|
|
15
|
+
settings: string;
|
|
16
|
+
prompt: string;
|
|
17
|
+
placeholder: string;
|
|
18
|
+
/** "The last 5 minutes are attached" for a window of `sec` seconds. */
|
|
19
|
+
attached: (sec: number) => string;
|
|
20
|
+
included: string;
|
|
21
|
+
incReplay: string;
|
|
22
|
+
incReplayMasked: {
|
|
23
|
+
strict: string;
|
|
24
|
+
balanced: string;
|
|
25
|
+
full: string;
|
|
26
|
+
};
|
|
27
|
+
incErrors: string;
|
|
28
|
+
incConsole: string;
|
|
29
|
+
incNetwork: string;
|
|
30
|
+
incFailedRequests: string;
|
|
31
|
+
incEnv: string;
|
|
32
|
+
incIdentity: string;
|
|
33
|
+
incMarks: string;
|
|
34
|
+
showWhere: string;
|
|
35
|
+
marked: (n: number) => string;
|
|
36
|
+
notify: string;
|
|
37
|
+
send: string;
|
|
38
|
+
sending: string;
|
|
39
|
+
retry: string;
|
|
40
|
+
errorCreate: string;
|
|
41
|
+
errorCapture: string;
|
|
42
|
+
sentTitle: string;
|
|
43
|
+
sentBody: string;
|
|
44
|
+
sentNotify: string;
|
|
45
|
+
seeReport: string;
|
|
46
|
+
tools: {
|
|
47
|
+
circle: string;
|
|
48
|
+
box: string;
|
|
49
|
+
arrow: string;
|
|
50
|
+
hide: string;
|
|
51
|
+
};
|
|
52
|
+
toolbar: string;
|
|
53
|
+
undo: string;
|
|
54
|
+
done: string;
|
|
55
|
+
coach: string;
|
|
56
|
+
coachMore: string;
|
|
57
|
+
/** The marking layer's name, for assistive technology. */
|
|
58
|
+
marking: string;
|
|
59
|
+
/** How to mark from the keyboard (the layer's description; shown in the coach card). */
|
|
60
|
+
keyboardHint: string;
|
|
61
|
+
hidden: string;
|
|
62
|
+
notePlaceholder: string;
|
|
63
|
+
mark: (n: number) => string;
|
|
64
|
+
removeMark: (n: number) => string;
|
|
65
|
+
shortcut: string;
|
|
66
|
+
shortcutHint: string;
|
|
67
|
+
notSet: string;
|
|
68
|
+
recordShortcut: string;
|
|
69
|
+
pressKeys: string;
|
|
70
|
+
needModifier: string;
|
|
71
|
+
removeShortcut: string;
|
|
72
|
+
back: string;
|
|
73
|
+
}
|
|
74
|
+
export declare function strings(locale: Locale): Strings;
|
|
75
|
+
/** `cs`, `cs-CZ`, `CS` → cs; `en-GB` → en; anything else → null. */
|
|
76
|
+
export declare function parseLocale(raw: unknown): Locale | null;
|
|
77
|
+
/** The first of the browser's languages the widget speaks; English otherwise. */
|
|
78
|
+
export declare function browserLocale(): Locale;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/** Czech plural: 1 · 2–4 · 5+ (and 0). */
|
|
2
|
+
function csPlural(n, one, few, many) {
|
|
3
|
+
if (n === 1)
|
|
4
|
+
return one;
|
|
5
|
+
if (n >= 2 && n <= 4)
|
|
6
|
+
return few;
|
|
7
|
+
return many;
|
|
8
|
+
}
|
|
9
|
+
const en = {
|
|
10
|
+
button: 'Report a problem',
|
|
11
|
+
title: 'Report a problem',
|
|
12
|
+
close: 'Close',
|
|
13
|
+
settings: 'Settings',
|
|
14
|
+
prompt: 'What went wrong?',
|
|
15
|
+
placeholder: 'Tell us what happened and what you expected',
|
|
16
|
+
attached: (sec) => {
|
|
17
|
+
if (sec < 60)
|
|
18
|
+
return `The last ${sec} seconds are attached`;
|
|
19
|
+
const min = Math.round(sec / 60);
|
|
20
|
+
return min === 1 ? 'The last minute is attached' : `The last ${min} minutes are attached`;
|
|
21
|
+
},
|
|
22
|
+
included: 'What’s included',
|
|
23
|
+
incReplay: 'A replay of what happened on this page',
|
|
24
|
+
incReplayMasked: {
|
|
25
|
+
strict: 'Text on the page and anything you typed are hidden in it',
|
|
26
|
+
balanced: 'Anything you typed is hidden in it',
|
|
27
|
+
full: 'It shows the page as you saw it',
|
|
28
|
+
},
|
|
29
|
+
incErrors: 'Errors the page ran into',
|
|
30
|
+
incConsole: 'Messages from the browser console',
|
|
31
|
+
incNetwork: 'Which addresses the page loaded, with their status',
|
|
32
|
+
incFailedRequests: 'Requests that failed — address and status only',
|
|
33
|
+
incEnv: 'Your browser, screen size, language and this page’s address',
|
|
34
|
+
incIdentity: 'Your name and email from this app',
|
|
35
|
+
incMarks: 'The places you marked, with your notes',
|
|
36
|
+
showWhere: 'Show us where',
|
|
37
|
+
marked: (n) => (n === 1 ? '1 place marked' : `${n} places marked`),
|
|
38
|
+
notify: 'Email me when it’s fixed',
|
|
39
|
+
send: 'Send',
|
|
40
|
+
sending: 'Sending…',
|
|
41
|
+
retry: 'Try again',
|
|
42
|
+
errorCreate: 'Couldn’t send — your text is safe, try again',
|
|
43
|
+
errorCapture: 'Your report arrived, the recording not yet — try again to attach it',
|
|
44
|
+
sentTitle: 'Thanks — we’ve got it',
|
|
45
|
+
sentBody: 'The team will take a look.',
|
|
46
|
+
sentNotify: 'We’ll email you when it’s fixed.',
|
|
47
|
+
seeReport: 'See your report',
|
|
48
|
+
tools: { circle: 'Circle', box: 'Box', arrow: 'Arrow', hide: 'Hide' },
|
|
49
|
+
toolbar: 'Marking tools',
|
|
50
|
+
undo: 'Undo',
|
|
51
|
+
done: 'Done',
|
|
52
|
+
coach: 'Click, hold and move around the problem.',
|
|
53
|
+
coachMore: 'You can mark more than one place.',
|
|
54
|
+
marking: 'Marking',
|
|
55
|
+
keyboardHint: 'Keyboard: Enter to start, arrows to move, Shift+arrows to resize, Enter to place.',
|
|
56
|
+
hidden: 'Hidden',
|
|
57
|
+
notePlaceholder: 'Add a note (optional)',
|
|
58
|
+
mark: (n) => `Mark ${n}`,
|
|
59
|
+
removeMark: (n) => `Remove mark ${n}`,
|
|
60
|
+
shortcut: 'Keyboard shortcut',
|
|
61
|
+
shortcutHint: 'Opens Report a problem anywhere in this app.',
|
|
62
|
+
notSet: 'Not set',
|
|
63
|
+
recordShortcut: 'Record a new shortcut',
|
|
64
|
+
pressKeys: 'Press keys · Esc cancels',
|
|
65
|
+
needModifier: 'Add Ctrl, Alt or ⌘ — a key on its own would get in the way of typing',
|
|
66
|
+
removeShortcut: 'Remove',
|
|
67
|
+
back: 'Back',
|
|
68
|
+
};
|
|
69
|
+
const cs = {
|
|
70
|
+
button: 'Nahlásit problém',
|
|
71
|
+
title: 'Nahlásit problém',
|
|
72
|
+
close: 'Zavřít',
|
|
73
|
+
settings: 'Nastavení',
|
|
74
|
+
prompt: 'Co se pokazilo?',
|
|
75
|
+
placeholder: 'Napište, co se stalo a co jste čekali',
|
|
76
|
+
attached: (sec) => {
|
|
77
|
+
if (sec < 60) {
|
|
78
|
+
return csPlural(sec, 'Poslední sekunda je přiložena', `Poslední ${sec} sekundy jsou přiloženy`, `Posledních ${sec} sekund je přiloženo`);
|
|
79
|
+
}
|
|
80
|
+
const min = Math.round(sec / 60);
|
|
81
|
+
return csPlural(min, 'Poslední minuta je přiložena', `Poslední ${min} minuty jsou přiloženy`, `Posledních ${min} minut je přiloženo`);
|
|
82
|
+
},
|
|
83
|
+
included: 'Co je přiloženo',
|
|
84
|
+
incReplay: 'Záznam toho, co se na stránce dělo',
|
|
85
|
+
incReplayMasked: {
|
|
86
|
+
strict: 'Texty stránky i vše, co jste napsali, jsou v něm skryté',
|
|
87
|
+
balanced: 'Vše, co jste napsali, je v něm skryté',
|
|
88
|
+
full: 'Ukazuje stránku tak, jak jste ji viděli',
|
|
89
|
+
},
|
|
90
|
+
incErrors: 'Chyby, na které stránka narazila',
|
|
91
|
+
incConsole: 'Zprávy z konzole prohlížeče',
|
|
92
|
+
incNetwork: 'Které adresy stránka načítala a s jakým výsledkem',
|
|
93
|
+
incFailedRequests: 'Požadavky, které selhaly — jen adresa a výsledek',
|
|
94
|
+
incEnv: 'Váš prohlížeč, velikost obrazovky, jazyk a adresa stránky',
|
|
95
|
+
incIdentity: 'Vaše jméno a e-mail z této aplikace',
|
|
96
|
+
incMarks: 'Místa, která jste označili, i s poznámkami',
|
|
97
|
+
showWhere: 'Ukažte nám kde',
|
|
98
|
+
marked: (n) => csPlural(n, '1 označené místo', `${n} označená místa`, `${n} označených míst`),
|
|
99
|
+
notify: 'Pošlete mi e-mail, až to bude opravené',
|
|
100
|
+
send: 'Odeslat',
|
|
101
|
+
sending: 'Odesílám…',
|
|
102
|
+
retry: 'Zkusit znovu',
|
|
103
|
+
errorCreate: 'Nepodařilo se odeslat — váš text zůstal, zkuste to znovu',
|
|
104
|
+
errorCapture: 'Hlášení dorazilo, záznam zatím ne — zkuste to znovu a přiložíme ho',
|
|
105
|
+
sentTitle: 'Díky — máme to',
|
|
106
|
+
sentBody: 'Tým se na to podívá.',
|
|
107
|
+
sentNotify: 'Až to bude opravené, pošleme vám e-mail.',
|
|
108
|
+
seeReport: 'Zobrazit hlášení',
|
|
109
|
+
tools: { circle: 'Kruh', box: 'Obdélník', arrow: 'Šipka', hide: 'Skrýt' },
|
|
110
|
+
toolbar: 'Nástroje pro označení',
|
|
111
|
+
undo: 'Zpět',
|
|
112
|
+
done: 'Hotovo',
|
|
113
|
+
coach: 'Klikněte, podržte a veďte kolem problému.',
|
|
114
|
+
coachMore: 'Označit můžete i více míst.',
|
|
115
|
+
marking: 'Označování',
|
|
116
|
+
keyboardHint: 'Klávesnice: Enter začne, šipky posouvají, Shift+šipky mění velikost, Enter umístí.',
|
|
117
|
+
hidden: 'Skryto',
|
|
118
|
+
notePlaceholder: 'Přidejte poznámku (nepovinné)',
|
|
119
|
+
mark: (n) => `Značka ${n}`,
|
|
120
|
+
removeMark: (n) => `Odebrat značku ${n}`,
|
|
121
|
+
shortcut: 'Klávesová zkratka',
|
|
122
|
+
shortcutHint: 'Otevře Nahlásit problém kdekoli v této aplikaci.',
|
|
123
|
+
notSet: 'Nenastavena',
|
|
124
|
+
recordShortcut: 'Nahrát novou zkratku',
|
|
125
|
+
pressKeys: 'Stiskněte klávesy · Esc zruší',
|
|
126
|
+
needModifier: 'Přidejte Ctrl, Alt nebo ⌘ — samotná klávesa by překážela při psaní',
|
|
127
|
+
removeShortcut: 'Odebrat',
|
|
128
|
+
back: 'Zpět',
|
|
129
|
+
};
|
|
130
|
+
const CATALOGS = { cs, en };
|
|
131
|
+
export function strings(locale) {
|
|
132
|
+
return CATALOGS[locale];
|
|
133
|
+
}
|
|
134
|
+
/** `cs`, `cs-CZ`, `CS` → cs; `en-GB` → en; anything else → null. */
|
|
135
|
+
export function parseLocale(raw) {
|
|
136
|
+
if (typeof raw !== 'string')
|
|
137
|
+
return null;
|
|
138
|
+
const lang = raw.trim().toLowerCase().split(/[-_]/)[0];
|
|
139
|
+
return lang === 'cs' || lang === 'en' ? lang : null;
|
|
140
|
+
}
|
|
141
|
+
/** The first of the browser's languages the widget speaks; English otherwise. */
|
|
142
|
+
export function browserLocale() {
|
|
143
|
+
const nav = globalThis.navigator;
|
|
144
|
+
const prefs = nav ? (nav.languages?.length ? nav.languages : [nav.language]) : [];
|
|
145
|
+
for (const p of prefs) {
|
|
146
|
+
const l = parseLocale(p);
|
|
147
|
+
if (l)
|
|
148
|
+
return l;
|
|
149
|
+
}
|
|
150
|
+
return 'en';
|
|
151
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who a report is filed as (QA Studio D4). The host vouches with a token it
|
|
3
|
+
* signed SERVER-SIDE — a compact HS256 JWS over `{sub, email, name?, iat,
|
|
4
|
+
* exp, aud: "<ws>/<project>"}` with the project's host secret, `exp` at most
|
|
5
|
+
* 24 h after `iat` — which files the report directly; or it asserts an
|
|
6
|
+
* email, which binds the report to a pending reporter (quarantined until
|
|
7
|
+
* approved). Neither: anonymous, quarantined.
|
|
8
|
+
*
|
|
9
|
+
* Held in memory only, for the life of the page: the host passes it on
|
|
10
|
+
* every load. The widget never reads the token's claims — the server
|
|
11
|
+
* verifies it; the token itself never leaves for anywhere but `base`.
|
|
12
|
+
*/
|
|
13
|
+
export type Identity = {
|
|
14
|
+
token: string;
|
|
15
|
+
} | {
|
|
16
|
+
email: string;
|
|
17
|
+
name?: string;
|
|
18
|
+
};
|
|
19
|
+
/** What `identify()` accepts: an identity, or null/undefined to go anonymous. */
|
|
20
|
+
export type IdentifyInput = Identity | null | undefined;
|
|
21
|
+
/** A clean identity, or null (with one warning) for anything malformed. */
|
|
22
|
+
export declare function normalizeIdentity(input: IdentifyInput): Identity | null;
|
|
23
|
+
/** Name the person every mounted widget files as (a widget's own `identify` wins). */
|
|
24
|
+
export declare function identify(input: IdentifyInput): void;
|
|
25
|
+
export declare function sharedIdentity(): Identity | null;
|
|
26
|
+
export declare function onSharedIdentity(fn: () => void): () => void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const JWS = /^[\w-]+\.[\w-]+\.[\w-]+$/;
|
|
2
|
+
/** A clean identity, or null (with one warning) for anything malformed. */
|
|
3
|
+
export function normalizeIdentity(input) {
|
|
4
|
+
if (!input)
|
|
5
|
+
return null;
|
|
6
|
+
if ('token' in input) {
|
|
7
|
+
const token = typeof input.token === 'string' ? input.token.trim() : '';
|
|
8
|
+
if (token.length > 4096 || !JWS.test(token)) {
|
|
9
|
+
console.warn('vitrinka: identify({token}) needs the compact JWS your server signed — reporting anonymously');
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
return { token };
|
|
13
|
+
}
|
|
14
|
+
const email = typeof input.email === 'string' ? input.email.trim().slice(0, 254) : '';
|
|
15
|
+
if (!email.includes('@')) {
|
|
16
|
+
console.warn('vitrinka: identify({email}) needs an email address — reporting anonymously');
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
const name = typeof input.name === 'string' ? input.name.trim().slice(0, 200) : '';
|
|
20
|
+
return name ? { email, name } : { email };
|
|
21
|
+
}
|
|
22
|
+
let shared = null;
|
|
23
|
+
const listeners = new Set();
|
|
24
|
+
/** Name the person every mounted widget files as (a widget's own `identify` wins). */
|
|
25
|
+
export function identify(input) {
|
|
26
|
+
shared = normalizeIdentity(input);
|
|
27
|
+
for (const l of listeners)
|
|
28
|
+
l();
|
|
29
|
+
}
|
|
30
|
+
export function sharedIdentity() {
|
|
31
|
+
return shared;
|
|
32
|
+
}
|
|
33
|
+
export function onSharedIdentity(fn) {
|
|
34
|
+
listeners.add(fn);
|
|
35
|
+
return () => listeners.delete(fn);
|
|
36
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type ReportHandle, type ReportOptions } from './element';
|
|
2
|
+
export type { CaptureClass, CaptureNarrowing, CaptureProfile, CaptureStorage } from './profile';
|
|
3
|
+
export type { Locale } from './i18n';
|
|
4
|
+
export type { IdentifyInput, Identity } from './identity';
|
|
5
|
+
export type { Marker, MarkerShape, WireMarker } from './markers';
|
|
6
|
+
export type { ReportEnvelope, SubmitReply } from './wire';
|
|
7
|
+
export type { ReportFace, ReportHandle, ReportOptions, ReportScriptOptions, VitrinkaReportElement } from './element';
|
|
8
|
+
export { identify } from './identity';
|
|
9
|
+
/** Mount Report a problem (default) or the recorder pill (`face: 'recorder'`). */
|
|
10
|
+
export declare function mountReport(opts: ReportOptions): ReportHandle;
|
|
11
|
+
/** Define `<vitrinka-report>` (idempotent; mountReport calls it). */
|
|
12
|
+
export declare function defineReportElement(): void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defineReportElement as define, mountReport as mount } from './element';
|
|
2
|
+
export { identify } from './identity';
|
|
3
|
+
const faces = {
|
|
4
|
+
loadRecord: () => import('rrweb').then((m) => m.record),
|
|
5
|
+
recorderFace: () => import('./recorder-face').then((m) => m.mountRecorderFace),
|
|
6
|
+
defaultBase: () => '',
|
|
7
|
+
};
|
|
8
|
+
/** Mount Report a problem (default) or the recorder pill (`face: 'recorder'`). */
|
|
9
|
+
export function mountReport(opts) {
|
|
10
|
+
return mount(opts, faces);
|
|
11
|
+
}
|
|
12
|
+
/** Define `<vitrinka-report>` (idempotent; mountReport calls it). */
|
|
13
|
+
export function defineReportElement() {
|
|
14
|
+
define(faces);
|
|
15
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface Keybind {
|
|
2
|
+
code: string;
|
|
3
|
+
alt: boolean;
|
|
4
|
+
ctrl: boolean;
|
|
5
|
+
meta: boolean;
|
|
6
|
+
shift: boolean;
|
|
7
|
+
}
|
|
8
|
+
export type KeyPress = Pick<KeyboardEvent, 'key' | 'code' | 'altKey' | 'ctrlKey' | 'metaKey' | 'shiftKey'>;
|
|
9
|
+
/** What a keydown means while the settings record a shortcut. */
|
|
10
|
+
export type KeybindVerdict = {
|
|
11
|
+
kind: 'cancel';
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'wait';
|
|
14
|
+
} | {
|
|
15
|
+
kind: 'bare';
|
|
16
|
+
} | {
|
|
17
|
+
kind: 'bind';
|
|
18
|
+
bind: Keybind;
|
|
19
|
+
};
|
|
20
|
+
export declare const KEYBIND_STORAGE_KEY = "report.keybind";
|
|
21
|
+
export declare function readKeybindPress(e: KeyPress): KeybindVerdict;
|
|
22
|
+
export declare function matchesKeybind(e: KeyPress, b: Keybind): boolean;
|
|
23
|
+
export declare function isMacPlatform(): boolean;
|
|
24
|
+
/** ⌃⌥⇧⌘R on a Mac, Ctrl+Alt+Shift+R elsewhere. */
|
|
25
|
+
export declare function keybindLabel(b: Keybind, mac?: boolean): string;
|
|
26
|
+
export declare function loadKeybind(): Keybind | null;
|
|
27
|
+
export declare function saveKeybind(b: Keybind | null): void;
|
|
28
|
+
/** Hear another tab change the shortcut; returns the unsubscribe. */
|
|
29
|
+
export declare function watchKeybind(on: (b: Keybind | null) => void): () => void;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The reporter's own shortcut for Report a problem (QA Studio assumptions:
|
|
3
|
+
* the snap HotKeyRecorder rules). There is no default: the person records
|
|
4
|
+
* one in the widget's settings by pressing it. The next key pressed with a
|
|
5
|
+
* modifier becomes the shortcut; Esc on its own cancels; a bare key is
|
|
6
|
+
* refused with the reason — and so is Shift alone, which in a browser types
|
|
7
|
+
* capitals. Matched by physical key (`code`: ⌥ rewrites `key` on a Mac).
|
|
8
|
+
* Stored in ONE key of the recorder storage (`vitrinka.recorder.report.keybind`
|
|
9
|
+
* in localStorage); every tab hears a change.
|
|
10
|
+
*/
|
|
11
|
+
import { getRecorderStorage } from '../recorder/storage';
|
|
12
|
+
const MODIFIER_KEYS = new Set(['Shift', 'Control', 'Alt', 'Meta', 'AltGraph', 'OS', 'CapsLock', 'Fn', 'Hyper', 'Super']);
|
|
13
|
+
export const KEYBIND_STORAGE_KEY = 'report.keybind';
|
|
14
|
+
export function readKeybindPress(e) {
|
|
15
|
+
if (MODIFIER_KEYS.has(e.key))
|
|
16
|
+
return { kind: 'wait' };
|
|
17
|
+
if (e.key === 'Escape' && !e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey)
|
|
18
|
+
return { kind: 'cancel' };
|
|
19
|
+
if (!e.altKey && !e.ctrlKey && !e.metaKey)
|
|
20
|
+
return { kind: 'bare' };
|
|
21
|
+
return { kind: 'bind', bind: { code: e.code, alt: e.altKey, ctrl: e.ctrlKey, meta: e.metaKey, shift: e.shiftKey } };
|
|
22
|
+
}
|
|
23
|
+
export function matchesKeybind(e, b) {
|
|
24
|
+
return e.code === b.code && e.altKey === b.alt && e.ctrlKey === b.ctrl && e.metaKey === b.meta && e.shiftKey === b.shift;
|
|
25
|
+
}
|
|
26
|
+
const NAMED = {
|
|
27
|
+
Space: 'Space',
|
|
28
|
+
Enter: '↵',
|
|
29
|
+
Backspace: '⌫',
|
|
30
|
+
Tab: '⇥',
|
|
31
|
+
ArrowUp: '↑',
|
|
32
|
+
ArrowDown: '↓',
|
|
33
|
+
ArrowLeft: '←',
|
|
34
|
+
ArrowRight: '→',
|
|
35
|
+
Slash: '/',
|
|
36
|
+
Backslash: '\\',
|
|
37
|
+
Period: '.',
|
|
38
|
+
Comma: ',',
|
|
39
|
+
Semicolon: ';',
|
|
40
|
+
Quote: "'",
|
|
41
|
+
BracketLeft: '[',
|
|
42
|
+
BracketRight: ']',
|
|
43
|
+
Minus: '-',
|
|
44
|
+
Equal: '=',
|
|
45
|
+
Backquote: '`',
|
|
46
|
+
};
|
|
47
|
+
function keyLabel(code) {
|
|
48
|
+
const letter = /^Key([A-Z])$/.exec(code);
|
|
49
|
+
if (letter)
|
|
50
|
+
return letter[1];
|
|
51
|
+
const digit = /^(?:Digit|Numpad)(\d)$/.exec(code);
|
|
52
|
+
if (digit)
|
|
53
|
+
return digit[1];
|
|
54
|
+
return NAMED[code] ?? code;
|
|
55
|
+
}
|
|
56
|
+
export function isMacPlatform() {
|
|
57
|
+
const nav = globalThis.navigator;
|
|
58
|
+
const platform = nav?.userAgentData?.platform ?? nav?.platform ?? '';
|
|
59
|
+
return /mac|iphone|ipad/i.test(platform);
|
|
60
|
+
}
|
|
61
|
+
/** ⌃⌥⇧⌘R on a Mac, Ctrl+Alt+Shift+R elsewhere. */
|
|
62
|
+
export function keybindLabel(b, mac = isMacPlatform()) {
|
|
63
|
+
const key = keyLabel(b.code);
|
|
64
|
+
if (mac)
|
|
65
|
+
return `${b.ctrl ? '⌃' : ''}${b.alt ? '⌥' : ''}${b.shift ? '⇧' : ''}${b.meta ? '⌘' : ''}${key}`;
|
|
66
|
+
return [b.ctrl && 'Ctrl', b.alt && 'Alt', b.shift && 'Shift', b.meta && 'Meta', key].filter(Boolean).join('+');
|
|
67
|
+
}
|
|
68
|
+
function parseKeybind(raw) {
|
|
69
|
+
if (!raw)
|
|
70
|
+
return null;
|
|
71
|
+
try {
|
|
72
|
+
const v = JSON.parse(raw);
|
|
73
|
+
if (typeof v !== 'object' || v === null)
|
|
74
|
+
return null;
|
|
75
|
+
const b = v;
|
|
76
|
+
if (typeof b.code !== 'string' || !b.code)
|
|
77
|
+
return null;
|
|
78
|
+
const bind = { code: b.code, alt: b.alt === true, ctrl: b.ctrl === true, meta: b.meta === true, shift: b.shift === true };
|
|
79
|
+
return bind.alt || bind.ctrl || bind.meta ? bind : null;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export function loadKeybind() {
|
|
86
|
+
return parseKeybind(getRecorderStorage().getString(KEYBIND_STORAGE_KEY));
|
|
87
|
+
}
|
|
88
|
+
export function saveKeybind(b) {
|
|
89
|
+
const s = getRecorderStorage();
|
|
90
|
+
if (b)
|
|
91
|
+
s.set(KEYBIND_STORAGE_KEY, JSON.stringify(b));
|
|
92
|
+
else
|
|
93
|
+
s.remove(KEYBIND_STORAGE_KEY);
|
|
94
|
+
}
|
|
95
|
+
/** Hear another tab change the shortcut; returns the unsubscribe. */
|
|
96
|
+
export function watchKeybind(on) {
|
|
97
|
+
const s = getRecorderStorage();
|
|
98
|
+
return s.watch ? s.watch(KEYBIND_STORAGE_KEY, (v) => on(parseKeybind(v))) : () => undefined;
|
|
99
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markers (QA Studio D12/D21): what a reporter draws on the frozen page —
|
|
3
|
+
* circle, box, arrow, hide — numbered 1, 2, 3… with an optional note. No
|
|
4
|
+
* element selector, ever: a marker is a region of the viewport in CSS
|
|
5
|
+
* pixels (`viewport: {w, h, dpr}` rides on the report's env).
|
|
6
|
+
*
|
|
7
|
+
* `hide` is a masking box: the region is blanked in the capture before it
|
|
8
|
+
* leaves the browser — an opaque box joins every full snapshot of the replay
|
|
9
|
+
* (so every frame and every still shows it blank), and the text and form
|
|
10
|
+
* values of the page's nodes under it (`hiddenNodeIds`, read off rrweb's
|
|
11
|
+
* mirror at send) are emptied in the snapshots and in the mutations and
|
|
12
|
+
* input events that carried them.
|
|
13
|
+
*/
|
|
14
|
+
import type { eventWithTime } from '@rrweb/types';
|
|
15
|
+
export type MarkerShape = 'circle' | 'box' | 'arrow' | 'hide';
|
|
16
|
+
export interface Rect {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
w: number;
|
|
20
|
+
h: number;
|
|
21
|
+
}
|
|
22
|
+
/** Which corner of an arrow's rect its head points into. */
|
|
23
|
+
export type ArrowHead = 'nw' | 'ne' | 'sw' | 'se';
|
|
24
|
+
export interface Marker {
|
|
25
|
+
n: number;
|
|
26
|
+
shape: MarkerShape;
|
|
27
|
+
rect: Rect;
|
|
28
|
+
note: string;
|
|
29
|
+
/** Arrows only: the head's corner (the tail sits in the opposite one). */
|
|
30
|
+
head?: ArrowHead;
|
|
31
|
+
}
|
|
32
|
+
/** A marker on the report wire. */
|
|
33
|
+
export interface WireMarker {
|
|
34
|
+
n: number;
|
|
35
|
+
shape: MarkerShape;
|
|
36
|
+
rect: Rect;
|
|
37
|
+
note?: string;
|
|
38
|
+
head?: ArrowHead;
|
|
39
|
+
}
|
|
40
|
+
export interface Point {
|
|
41
|
+
x: number;
|
|
42
|
+
y: number;
|
|
43
|
+
}
|
|
44
|
+
/** The smallest stroke that counts as a marker; a click without moving is not one. */
|
|
45
|
+
export declare const MIN_MARK_PX = 8;
|
|
46
|
+
export declare function rectBetween(a: Point, b: Point): Rect;
|
|
47
|
+
export declare function arrowHead(tail: Point, head: Point): ArrowHead;
|
|
48
|
+
/** The arrow's two ends from its rect and head corner. */
|
|
49
|
+
export declare function arrowEnds(rect: Rect, head: ArrowHead): {
|
|
50
|
+
tail: Point;
|
|
51
|
+
tip: Point;
|
|
52
|
+
};
|
|
53
|
+
/** Is the stroke from `a` to `b` big enough to be a `shape`? */
|
|
54
|
+
export declare function isMark(shape: MarkerShape, a: Point, b: Point): boolean;
|
|
55
|
+
/** Numbered 1..n in drawing order (after a removal too). */
|
|
56
|
+
export declare function renumber(markers: readonly Marker[]): Marker[];
|
|
57
|
+
export declare function toWire(markers: readonly Marker[]): WireMarker[];
|
|
58
|
+
/** Far above any id rrweb hands out in one recording. */
|
|
59
|
+
export declare const HIDE_NODE_ID_BASE = 2000000000;
|
|
60
|
+
export declare const HIDE_ATTR = "data-vitrinka-hidden";
|
|
61
|
+
/**
|
|
62
|
+
* The capture with every `hide` region blanked: the boxes join each full
|
|
63
|
+
* snapshot, and the nodes in `hiddenIds` lose their text and values in the
|
|
64
|
+
* snapshots, in mutations and in input events. Returns new events; the
|
|
65
|
+
* input is never mutated (the buffer still holds it).
|
|
66
|
+
*/
|
|
67
|
+
export declare function applyHides(events: readonly eventWithTime[], hides: readonly Rect[], hiddenIds: ReadonlySet<number>): eventWithTime[];
|
|
68
|
+
/** What `hiddenNodeIds` needs of rrweb's mirror. */
|
|
69
|
+
export interface NodeIds {
|
|
70
|
+
getId(n: Node): number;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The rrweb ids of the page's text nodes and form controls whose box is
|
|
74
|
+
* centred inside a hide region right now (the page is frozen while the
|
|
75
|
+
* reporter marks). Our own surfaces are skipped.
|
|
76
|
+
*/
|
|
77
|
+
export declare function hiddenNodeIds(hides: readonly Rect[], mirror: NodeIds | null, doc?: Document): Set<number>;
|