@vitrinka/web 0.7.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 +8 -0
- package/README.md +4 -1
- package/build/recorder/version.d.ts +2 -2
- package/build/recorder/version.js +1 -1
- package/build/report/widget.d.ts +2 -0
- package/build/report/widget.js +21 -1
- package/build/report-widget.mjs +5 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @vitrinka/web
|
|
2
2
|
|
|
3
|
+
## 0.7.1
|
|
4
|
+
|
|
5
|
+
- **Report a problem hands focus back.** Closing the card returns focus to
|
|
6
|
+
whatever had it when the card opened — the host's own control (`button:
|
|
7
|
+
false` with `open-selector` or `open()`), the field the reporter's shortcut
|
|
8
|
+
fired in — and falls back to the button. With the button hidden, focus
|
|
9
|
+
was lost to `<body>`.
|
|
10
|
+
|
|
3
11
|
## 0.7.0
|
|
4
12
|
|
|
5
13
|
**Report a problem** — the report face of the one capture client (QA Studio
|
package/README.md
CHANGED
|
@@ -359,7 +359,10 @@ function ReportAProblem({ locale, token }: { locale: string; token?: string }) {
|
|
|
359
359
|
|
|
360
360
|
The handle (and the element) has `open()`, `close()`, `identify()`,
|
|
361
361
|
`setLocale()`; the handle also `unmount()`s. For the tag from npm, call
|
|
362
|
-
`defineReportElement()` once.
|
|
362
|
+
`defineReportElement()` once. Closing the card hands focus back to whatever
|
|
363
|
+
had it when the card opened (your control, the field the shortcut fired in),
|
|
364
|
+
else to the button: call `open()` once your control holds focus again — after
|
|
365
|
+
a menu that opened it has handed focus back to its trigger.
|
|
363
366
|
|
|
364
367
|
**Who reports.** Vouch for your signed-in user with a token your SERVER
|
|
365
368
|
signs — never in the browser — over `{sub, email, name?, iat, exp, aud:
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/** Sent as `meta.recorder` and written as `data-vitrinka-page`; bumped with the package version. */
|
|
2
|
-
export declare const RECORDER_VERSION = "0.7.
|
|
3
|
-
export declare const RECORDER_ID = "web/0.7.
|
|
2
|
+
export declare const RECORDER_VERSION = "0.7.1";
|
|
3
|
+
export declare const RECORDER_ID = "web/0.7.1";
|
package/build/report/widget.d.ts
CHANGED
|
@@ -30,6 +30,8 @@ export declare class ReportWidget {
|
|
|
30
30
|
private identity;
|
|
31
31
|
private keybind;
|
|
32
32
|
private isOpen;
|
|
33
|
+
/** Where focus was when the card opened, outside the report: close() hands it back. */
|
|
34
|
+
private opener;
|
|
33
35
|
private view;
|
|
34
36
|
private marking;
|
|
35
37
|
private markers;
|
package/build/report/widget.js
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* Drafts live in memory only.
|
|
17
17
|
*/
|
|
18
18
|
import { redactUrl } from '../recorder/capture/redact';
|
|
19
|
-
import { createHudHost, createSheetHost, sheetTarget } from '../recorder/hud/host';
|
|
19
|
+
import { createHudHost, createSheetHost, insideHud, sheetTarget } from '../recorder/hud/host';
|
|
20
20
|
import { listen } from '../recorder/hud/listen';
|
|
21
21
|
import { acquireEngine, releaseEngine } from './engine';
|
|
22
22
|
import { browserLocale, parseLocale, strings } from './i18n';
|
|
@@ -89,6 +89,15 @@ function titleOf(description) {
|
|
|
89
89
|
function reducedMotion() {
|
|
90
90
|
return globalThis.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false;
|
|
91
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
|
+
}
|
|
92
101
|
/** The widget's DOM, built once into the HUD host's shadow mount. */
|
|
93
102
|
function buildDom(mount) {
|
|
94
103
|
const fabLabel = h('span');
|
|
@@ -181,6 +190,8 @@ export class ReportWidget {
|
|
|
181
190
|
identity;
|
|
182
191
|
keybind;
|
|
183
192
|
isOpen = false;
|
|
193
|
+
/** Where focus was when the card opened, outside the report: close() hands it back. */
|
|
194
|
+
opener = null;
|
|
184
195
|
view = 'describe';
|
|
185
196
|
marking = false;
|
|
186
197
|
markers = [];
|
|
@@ -282,6 +293,7 @@ export class ReportWidget {
|
|
|
282
293
|
if (this.isOpen)
|
|
283
294
|
return;
|
|
284
295
|
this.isOpen = true;
|
|
296
|
+
this.opener = insideHud(document.activeElement) ? null : deepActiveElement();
|
|
285
297
|
if (this.view !== 'describe')
|
|
286
298
|
this.view = 'describe';
|
|
287
299
|
this.result = null;
|
|
@@ -300,6 +312,14 @@ export class ReportWidget {
|
|
|
300
312
|
this.isOpen = false;
|
|
301
313
|
this.view = 'describe';
|
|
302
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;
|
|
303
323
|
if (this.button)
|
|
304
324
|
this.e.fab.focus();
|
|
305
325
|
}
|
package/build/report-widget.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
function Lt(e,t,n,r){if(e===1)return t;if(e>=2&&e<=4)return n;return r}var Ai={button:"Report a problem",title:"Report a problem",close:"Close",settings:"Settings",prompt:"What went wrong?",placeholder:"Tell us what happened and what you expected",attached:(e)=>{if(e<60)return`The last ${e} seconds are attached`;let t=Math.round(e/60);return t===1?"The last minute is attached":`The last ${t} minutes are attached`},included:"What’s included",incReplay:"A replay of what happened on this page",incReplayMasked:{strict:"Text on the page and anything you typed are hidden in it",balanced:"Anything you typed is hidden in it",full:"It shows the page as you saw it"},incErrors:"Errors the page ran into",incConsole:"Messages from the browser console",incNetwork:"Which addresses the page loaded, with their status",incFailedRequests:"Requests that failed — address and status only",incEnv:"Your browser, screen size, language and this page’s address",incIdentity:"Your name and email from this app",incMarks:"The places you marked, with your notes",showWhere:"Show us where",marked:(e)=>e===1?"1 place marked":`${e} places marked`,notify:"Email me when it’s fixed",send:"Send",sending:"Sending…",retry:"Try again",errorCreate:"Couldn’t send — your text is safe, try again",errorCapture:"Your report arrived, the recording not yet — try again to attach it",sentTitle:"Thanks — we’ve got it",sentBody:"The team will take a look.",sentNotify:"We’ll email you when it’s fixed.",seeReport:"See your report",tools:{circle:"Circle",box:"Box",arrow:"Arrow",hide:"Hide"},toolbar:"Marking tools",undo:"Undo",done:"Done",coach:"Click, hold and move around the problem.",coachMore:"You can mark more than one place.",marking:"Marking",keyboardHint:"Keyboard: Enter to start, arrows to move, Shift+arrows to resize, Enter to place.",hidden:"Hidden",notePlaceholder:"Add a note (optional)",mark:(e)=>`Mark ${e}`,removeMark:(e)=>`Remove mark ${e}`,shortcut:"Keyboard shortcut",shortcutHint:"Opens Report a problem anywhere in this app.",notSet:"Not set",recordShortcut:"Record a new shortcut",pressKeys:"Press keys · Esc cancels",needModifier:"Add Ctrl, Alt or ⌘ — a key on its own would get in the way of typing",removeShortcut:"Remove",back:"Back"},Pi={button:"Nahlásit problém",title:"Nahlásit problém",close:"Zavřít",settings:"Nastavení",prompt:"Co se pokazilo?",placeholder:"Napište, co se stalo a co jste čekali",attached:(e)=>{if(e<60)return Lt(e,"Poslední sekunda je přiložena",`Poslední ${e} sekundy jsou přiloženy`,`Posledních ${e} sekund je přiloženo`);let t=Math.round(e/60);return Lt(t,"Poslední minuta je přiložena",`Poslední ${t} minuty jsou přiloženy`,`Posledních ${t} minut je přiloženo`)},included:"Co je přiloženo",incReplay:"Záznam toho, co se na stránce dělo",incReplayMasked:{strict:"Texty stránky i vše, co jste napsali, jsou v něm skryté",balanced:"Vše, co jste napsali, je v něm skryté",full:"Ukazuje stránku tak, jak jste ji viděli"},incErrors:"Chyby, na které stránka narazila",incConsole:"Zprávy z konzole prohlížeče",incNetwork:"Které adresy stránka načítala a s jakým výsledkem",incFailedRequests:"Požadavky, které selhaly — jen adresa a výsledek",incEnv:"Váš prohlížeč, velikost obrazovky, jazyk a adresa stránky",incIdentity:"Vaše jméno a e-mail z této aplikace",incMarks:"Místa, která jste označili, i s poznámkami",showWhere:"Ukažte nám kde",marked:(e)=>Lt(e,"1 označené místo",`${e} označená místa`,`${e} označených míst`),notify:"Pošlete mi e-mail, až to bude opravené",send:"Odeslat",sending:"Odesílám…",retry:"Zkusit znovu",errorCreate:"Nepodařilo se odeslat — váš text zůstal, zkuste to znovu",errorCapture:"Hlášení dorazilo, záznam zatím ne — zkuste to znovu a přiložíme ho",sentTitle:"Díky — máme to",sentBody:"Tým se na to podívá.",sentNotify:"Až to bude opravené, pošleme vám e-mail.",seeReport:"Zobrazit hlášení",tools:{circle:"Kruh",box:"Obdélník",arrow:"Šipka",hide:"Skrýt"},toolbar:"Nástroje pro označení",undo:"Zpět",done:"Hotovo",coach:"Klikněte, podržte a veďte kolem problému.",coachMore:"Označit můžete i více míst.",marking:"Označování",keyboardHint:"Klávesnice: Enter začne, šipky posouvají, Shift+šipky mění velikost, Enter umístí.",hidden:"Skryto",notePlaceholder:"Přidejte poznámku (nepovinné)",mark:(e)=>`Značka ${e}`,removeMark:(e)=>`Odebrat značku ${e}`,shortcut:"Klávesová zkratka",shortcutHint:"Otevře Nahlásit problém kdekoli v této aplikaci.",notSet:"Nenastavena",recordShortcut:"Nahrát novou zkratku",pressKeys:"Stiskněte klávesy · Esc zruší",needModifier:"Přidejte Ctrl, Alt nebo ⌘ — samotná klávesa by překážela při psaní",removeShortcut:"Odebrat",back:"Zpět"},_i={cs:Pi,en:Ai};function Dt(e){return _i[e]}function Ce(e){if(typeof e!=="string")return null;let t=e.trim().toLowerCase().split(/[-_]/)[0];return t==="cs"||t==="en"?t:null}function Nt(){let e=globalThis.navigator,t=e?e.languages?.length?e.languages:[e.language]:[];for(let n of t){let r=Ce(n);if(r)return r}return"en"}var hr="[redacted]",Li=["authorization","proxyauthorization","cookie","setcookie","xapikey","xauthtoken","xcsrftoken","xamzsecuritytoken"],Di=["password","passwd","secret","token","accesstoken","refreshtoken","idtoken","authorization","apikey","clientsecret","card","cardnumber","cvv","cvc","pin","ssn"];function ce(e){return String(e).toLowerCase().replace(/[-_]/g,"")}var Ot=null;function Bt(e){let t=JSON.stringify(e??null);if(Ot?.src===t)return Ot.rules;let n=new Set(Li),r=new Set(Di),o=[];for(let s of e?.extraHeaders??[]){let a=ce(s);if(a)n.add(a)}for(let s of e?.extraBodyKeys??[]){let a=ce(s);if(a)r.add(a)}for(let s of e?.patterns??[])try{o.push(new RegExp(s,"g"))}catch(a){console.warn("vitrinka redact: unsupported pattern skipped",s,a)}let i={full:e?.fullFidelity===!0,maskAllText:e?.maskAllText===!0,headers:n,bodyKeys:r,patterns:o};return Ot={src:t,rules:i},i}var Ni=new Set(["password","passwd","pwd","secret","token","auth","authorization","otp","pin","apikey","credential","credentials","cookie","cvv","cvc","iban","ssn"]),Oi=["apikey","privatekey","secretkey","sessionid","cardnumber","birthnumber","rodnecislo","accesstoken","refreshtoken","idtoken"];function Bi(e){return e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[^A-Za-z0-9]+/).filter(Boolean).map((t)=>t.toLowerCase())}function gr(e){let t=Bi(e);if(t.some((n)=>Ni.has(n)))return!0;for(let n=0;n<t.length;n++){let r="";for(let o=n;o<t.length;o++){if(r+=t[o],Oi.includes(r))return!0;if(r.length>24)break}}return!1}function mr(e,t){let n=ce(t);return e.headers.has(n)||n.endsWith("apikey")||n.endsWith("token")||gr(t)}function W(e,t){return e.bodyKeys.has(ce(t))||gr(t)}function br(e,t){if(W(e,t))return!0;let n=ce(t);return n.endsWith("apikey")||n.endsWith("token")}var Hi=/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z ]*PRIVATE KEY-----|$)/g,qi=/-----BEGIN[A-Z +]*PRIVATE[ +]KEY-----/;function yr(e){return e.includes("PRIVATE KEY-----")?e.replace(Hi,"[redacted]"):e}function de(e,t){let n=yr(t);for(let r of e.patterns)r.lastIndex=0,n=n.replace(r,"[redacted]");return n}function kr(e,t){if(qi.test(t))return!0;for(let n of t.matchAll(/([A-Za-z][A-Za-z0-9_.\-[\]]{0,60})\s*[:=]/g))if(W(e,n[1]))return!0;return!1}function Xe(e){let t=e;for(let n=0;n<3;n++){let r=$i(t);if(r===t)break;t=r}return t}function $i(e){if(!e.includes("%"))return e;try{return decodeURIComponent(e)}catch{return e.replace(/(%[0-9A-Fa-f]{2})+/g,(t)=>{try{return decodeURIComponent(t)}catch{return t.replace(/%([0-9A-Fa-f]{2})/g,(n,r)=>{let o=Number.parseInt(r,16);return o<128?String.fromCharCode(o):n})}})}}function vr(e,t,n){let r=!1,o=n.split(/[&;]/).map((i)=>{if(i==="")return i;let s=i.indexOf("="),a=s>=0?i.slice(0,s):i,l=Xe(a.replace(/\+/g," ")),d=l.lastIndexOf("?"),g=d>=0?l.slice(d+1):null;if(t(e,l)||g!==null&&t(e,g))return r=!0,`${a}=[redacted]`;if(s>=0&&kr(e,Xe(i.slice(s+1))))return r=!0,`${a}=[redacted]`;return i});return r?o.join("&"):n}function Ht(e,t){if(e.full||!t)return t;let n=t.search(/[?#]/);if(n<0)return de(e,t);let r=t.slice(n+1).split("#").map((o)=>vr(e,br,o)).join("#");return de(e,t.slice(0,n+1)+r)}var Fi=/([A-Za-z][A-Za-z0-9_.\-[\]]{0,60})("?\s*[:=]\s*(?!\/\/))("?)([^&?"'\s,}]*)\3/g,Ki=/([?&])([^=&#\s]{1,120})=([^&#\s]*)/g,Wi=/^([A-Za-z][A-Za-z0-9_.-]{0,60})[ \t]*:[ \t]*(.+)$/gm,zi=131072;function Je(e,t){if(t.length>zi)return`[body omitted: ${t.length} bytes, unmaskable]`;let n=yr(t).replace(Wi,(r,o)=>mr(e,o)?`${o}: [redacted]`:r).replace(/\b((?:proxy-)?authorization|www-authenticate)(\s*[:=]\s*)[^\r\n]+/gi,(r,o,i)=>`${o}${i}[redacted]`).replace(/\b(Digest|Negotiate|NTLM)\s+(?=[A-Za-z][A-Za-z-]{0,30}\s*=)[^\r\n]+/gi,(r,o)=>`${o} [redacted]`).replace(/\b(Bearer|Basic)\s+[A-Za-z0-9._~+/=-]+/gi,"$1 [redacted]").replace(/\beyJ[A-Za-z0-9._-]{10,}/g,"[redacted]").replace(Ki,(r,o,i,s)=>{if(br(e,Xe(i)))return`${o}${i}=[redacted]`;if(kr(e,Xe(s)))return`${o}${i}=[redacted]`;return r}).replace(Fi,(r,o,i,s,a)=>{if(a==="[redacted]")return r;return W(e,o)?`${o}${i}${s}[redacted]${s}`:r});return de(e,n)}function ji(e){switch(ce(e)){case"url":case"href":case"uri":case"location":return!0;default:return!1}}var Ui=64;function Ge(e,t,n){if(n>Ui)return"[redacted]";if(Array.isArray(t))return t.map((r)=>Ge(e,r,n+1));if(t!==null&&typeof t==="object"){let r={};for(let[o,i]of Object.entries(t))if(W(e,o))r[o]="[redacted]";else if(typeof i==="string"&&ji(o))r[o]=Ht(e,i);else r[o]=Ge(e,i,n+1);return r}return typeof t==="string"?de(e,t):t}function pr(e){if(!e.includes("\\"))return e;return e.replace(/\\u([0-9A-Fa-f]{4})|\\(.)/g,(t,n,r)=>n!==void 0?String.fromCharCode(Number.parseInt(n,16)):r)}function Vi(e,t){for(let n of t.matchAll(/"((?:[^"\\\r\n]|\\.)*)"\s*:\s*[{\[]/g))if(W(e,pr(n[1])))return"";return t.replace(/("((?:[A-Za-z0-9_-]|\\u[0-9A-Fa-f]{4}|\\.)+)"\s*:\s*)("(?:[^"\\]|\\.)*"?|[^,{}[\]"\r\n]*)/g,(n,r,o)=>W(e,pr(o))?`${r}"[redacted]"`:n)}function qt(e){let t=e.trimStart();return t.startsWith("{")||t.startsWith("[")}function Yi(e,t,n){let r=/boundary="?([^";]+)"?/i.exec(n);if(!r)return null;let o=`--${r[1]}`,i=t.split(o);if(i.length<3||i[0]!=="")return null;if(!i[i.length-1].startsWith("--"))return null;let s=[i[0]];for(let a=1;a<i.length-1;a++){let l=i[a];if(!l.startsWith(`\r
|
|
1
|
+
function Lt(e,t,n,r){if(e===1)return t;if(e>=2&&e<=4)return n;return r}var _i={button:"Report a problem",title:"Report a problem",close:"Close",settings:"Settings",prompt:"What went wrong?",placeholder:"Tell us what happened and what you expected",attached:(e)=>{if(e<60)return`The last ${e} seconds are attached`;let t=Math.round(e/60);return t===1?"The last minute is attached":`The last ${t} minutes are attached`},included:"What’s included",incReplay:"A replay of what happened on this page",incReplayMasked:{strict:"Text on the page and anything you typed are hidden in it",balanced:"Anything you typed is hidden in it",full:"It shows the page as you saw it"},incErrors:"Errors the page ran into",incConsole:"Messages from the browser console",incNetwork:"Which addresses the page loaded, with their status",incFailedRequests:"Requests that failed — address and status only",incEnv:"Your browser, screen size, language and this page’s address",incIdentity:"Your name and email from this app",incMarks:"The places you marked, with your notes",showWhere:"Show us where",marked:(e)=>e===1?"1 place marked":`${e} places marked`,notify:"Email me when it’s fixed",send:"Send",sending:"Sending…",retry:"Try again",errorCreate:"Couldn’t send — your text is safe, try again",errorCapture:"Your report arrived, the recording not yet — try again to attach it",sentTitle:"Thanks — we’ve got it",sentBody:"The team will take a look.",sentNotify:"We’ll email you when it’s fixed.",seeReport:"See your report",tools:{circle:"Circle",box:"Box",arrow:"Arrow",hide:"Hide"},toolbar:"Marking tools",undo:"Undo",done:"Done",coach:"Click, hold and move around the problem.",coachMore:"You can mark more than one place.",marking:"Marking",keyboardHint:"Keyboard: Enter to start, arrows to move, Shift+arrows to resize, Enter to place.",hidden:"Hidden",notePlaceholder:"Add a note (optional)",mark:(e)=>`Mark ${e}`,removeMark:(e)=>`Remove mark ${e}`,shortcut:"Keyboard shortcut",shortcutHint:"Opens Report a problem anywhere in this app.",notSet:"Not set",recordShortcut:"Record a new shortcut",pressKeys:"Press keys · Esc cancels",needModifier:"Add Ctrl, Alt or ⌘ — a key on its own would get in the way of typing",removeShortcut:"Remove",back:"Back"},Li={button:"Nahlásit problém",title:"Nahlásit problém",close:"Zavřít",settings:"Nastavení",prompt:"Co se pokazilo?",placeholder:"Napište, co se stalo a co jste čekali",attached:(e)=>{if(e<60)return Lt(e,"Poslední sekunda je přiložena",`Poslední ${e} sekundy jsou přiloženy`,`Posledních ${e} sekund je přiloženo`);let t=Math.round(e/60);return Lt(t,"Poslední minuta je přiložena",`Poslední ${t} minuty jsou přiloženy`,`Posledních ${t} minut je přiloženo`)},included:"Co je přiloženo",incReplay:"Záznam toho, co se na stránce dělo",incReplayMasked:{strict:"Texty stránky i vše, co jste napsali, jsou v něm skryté",balanced:"Vše, co jste napsali, je v něm skryté",full:"Ukazuje stránku tak, jak jste ji viděli"},incErrors:"Chyby, na které stránka narazila",incConsole:"Zprávy z konzole prohlížeče",incNetwork:"Které adresy stránka načítala a s jakým výsledkem",incFailedRequests:"Požadavky, které selhaly — jen adresa a výsledek",incEnv:"Váš prohlížeč, velikost obrazovky, jazyk a adresa stránky",incIdentity:"Vaše jméno a e-mail z této aplikace",incMarks:"Místa, která jste označili, i s poznámkami",showWhere:"Ukažte nám kde",marked:(e)=>Lt(e,"1 označené místo",`${e} označená místa`,`${e} označených míst`),notify:"Pošlete mi e-mail, až to bude opravené",send:"Odeslat",sending:"Odesílám…",retry:"Zkusit znovu",errorCreate:"Nepodařilo se odeslat — váš text zůstal, zkuste to znovu",errorCapture:"Hlášení dorazilo, záznam zatím ne — zkuste to znovu a přiložíme ho",sentTitle:"Díky — máme to",sentBody:"Tým se na to podívá.",sentNotify:"Až to bude opravené, pošleme vám e-mail.",seeReport:"Zobrazit hlášení",tools:{circle:"Kruh",box:"Obdélník",arrow:"Šipka",hide:"Skrýt"},toolbar:"Nástroje pro označení",undo:"Zpět",done:"Hotovo",coach:"Klikněte, podržte a veďte kolem problému.",coachMore:"Označit můžete i více míst.",marking:"Označování",keyboardHint:"Klávesnice: Enter začne, šipky posouvají, Shift+šipky mění velikost, Enter umístí.",hidden:"Skryto",notePlaceholder:"Přidejte poznámku (nepovinné)",mark:(e)=>`Značka ${e}`,removeMark:(e)=>`Odebrat značku ${e}`,shortcut:"Klávesová zkratka",shortcutHint:"Otevře Nahlásit problém kdekoli v této aplikaci.",notSet:"Nenastavena",recordShortcut:"Nahrát novou zkratku",pressKeys:"Stiskněte klávesy · Esc zruší",needModifier:"Přidejte Ctrl, Alt nebo ⌘ — samotná klávesa by překážela při psaní",removeShortcut:"Odebrat",back:"Zpět"},Di={cs:Li,en:_i};function Dt(e){return Di[e]}function Ce(e){if(typeof e!=="string")return null;let t=e.trim().toLowerCase().split(/[-_]/)[0];return t==="cs"||t==="en"?t:null}function Nt(){let e=globalThis.navigator,t=e?e.languages?.length?e.languages:[e.language]:[];for(let n of t){let r=Ce(n);if(r)return r}return"en"}var hr="[redacted]",Ni=["authorization","proxyauthorization","cookie","setcookie","xapikey","xauthtoken","xcsrftoken","xamzsecuritytoken"],Oi=["password","passwd","secret","token","accesstoken","refreshtoken","idtoken","authorization","apikey","clientsecret","card","cardnumber","cvv","cvc","pin","ssn"];function ce(e){return String(e).toLowerCase().replace(/[-_]/g,"")}var Ot=null;function Bt(e){let t=JSON.stringify(e??null);if(Ot?.src===t)return Ot.rules;let n=new Set(Ni),r=new Set(Oi),o=[];for(let s of e?.extraHeaders??[]){let a=ce(s);if(a)n.add(a)}for(let s of e?.extraBodyKeys??[]){let a=ce(s);if(a)r.add(a)}for(let s of e?.patterns??[])try{o.push(new RegExp(s,"g"))}catch(a){console.warn("vitrinka redact: unsupported pattern skipped",s,a)}let i={full:e?.fullFidelity===!0,maskAllText:e?.maskAllText===!0,headers:n,bodyKeys:r,patterns:o};return Ot={src:t,rules:i},i}var Bi=new Set(["password","passwd","pwd","secret","token","auth","authorization","otp","pin","apikey","credential","credentials","cookie","cvv","cvc","iban","ssn"]),Hi=["apikey","privatekey","secretkey","sessionid","cardnumber","birthnumber","rodnecislo","accesstoken","refreshtoken","idtoken"];function qi(e){return e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[^A-Za-z0-9]+/).filter(Boolean).map((t)=>t.toLowerCase())}function gr(e){let t=qi(e);if(t.some((n)=>Bi.has(n)))return!0;for(let n=0;n<t.length;n++){let r="";for(let o=n;o<t.length;o++){if(r+=t[o],Hi.includes(r))return!0;if(r.length>24)break}}return!1}function mr(e,t){let n=ce(t);return e.headers.has(n)||n.endsWith("apikey")||n.endsWith("token")||gr(t)}function W(e,t){return e.bodyKeys.has(ce(t))||gr(t)}function br(e,t){if(W(e,t))return!0;let n=ce(t);return n.endsWith("apikey")||n.endsWith("token")}var $i=/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z ]*PRIVATE KEY-----|$)/g,Fi=/-----BEGIN[A-Z +]*PRIVATE[ +]KEY-----/;function yr(e){return e.includes("PRIVATE KEY-----")?e.replace($i,"[redacted]"):e}function de(e,t){let n=yr(t);for(let r of e.patterns)r.lastIndex=0,n=n.replace(r,"[redacted]");return n}function kr(e,t){if(Fi.test(t))return!0;for(let n of t.matchAll(/([A-Za-z][A-Za-z0-9_.\-[\]]{0,60})\s*[:=]/g))if(W(e,n[1]))return!0;return!1}function Xe(e){let t=e;for(let n=0;n<3;n++){let r=Ki(t);if(r===t)break;t=r}return t}function Ki(e){if(!e.includes("%"))return e;try{return decodeURIComponent(e)}catch{return e.replace(/(%[0-9A-Fa-f]{2})+/g,(t)=>{try{return decodeURIComponent(t)}catch{return t.replace(/%([0-9A-Fa-f]{2})/g,(n,r)=>{let o=Number.parseInt(r,16);return o<128?String.fromCharCode(o):n})}})}}function vr(e,t,n){let r=!1,o=n.split(/[&;]/).map((i)=>{if(i==="")return i;let s=i.indexOf("="),a=s>=0?i.slice(0,s):i,l=Xe(a.replace(/\+/g," ")),d=l.lastIndexOf("?"),g=d>=0?l.slice(d+1):null;if(t(e,l)||g!==null&&t(e,g))return r=!0,`${a}=[redacted]`;if(s>=0&&kr(e,Xe(i.slice(s+1))))return r=!0,`${a}=[redacted]`;return i});return r?o.join("&"):n}function Ht(e,t){if(e.full||!t)return t;let n=t.search(/[?#]/);if(n<0)return de(e,t);let r=t.slice(n+1).split("#").map((o)=>vr(e,br,o)).join("#");return de(e,t.slice(0,n+1)+r)}var Wi=/([A-Za-z][A-Za-z0-9_.\-[\]]{0,60})("?\s*[:=]\s*(?!\/\/))("?)([^&?"'\s,}]*)\3/g,zi=/([?&])([^=&#\s]{1,120})=([^&#\s]*)/g,ji=/^([A-Za-z][A-Za-z0-9_.-]{0,60})[ \t]*:[ \t]*(.+)$/gm,Ui=131072;function Ge(e,t){if(t.length>Ui)return`[body omitted: ${t.length} bytes, unmaskable]`;let n=yr(t).replace(ji,(r,o)=>mr(e,o)?`${o}: [redacted]`:r).replace(/\b((?:proxy-)?authorization|www-authenticate)(\s*[:=]\s*)[^\r\n]+/gi,(r,o,i)=>`${o}${i}[redacted]`).replace(/\b(Digest|Negotiate|NTLM)\s+(?=[A-Za-z][A-Za-z-]{0,30}\s*=)[^\r\n]+/gi,(r,o)=>`${o} [redacted]`).replace(/\b(Bearer|Basic)\s+[A-Za-z0-9._~+/=-]+/gi,"$1 [redacted]").replace(/\beyJ[A-Za-z0-9._-]{10,}/g,"[redacted]").replace(zi,(r,o,i,s)=>{if(br(e,Xe(i)))return`${o}${i}=[redacted]`;if(kr(e,Xe(s)))return`${o}${i}=[redacted]`;return r}).replace(Wi,(r,o,i,s,a)=>{if(a==="[redacted]")return r;return W(e,o)?`${o}${i}${s}[redacted]${s}`:r});return de(e,n)}function Vi(e){switch(ce(e)){case"url":case"href":case"uri":case"location":return!0;default:return!1}}var Yi=64;function Je(e,t,n){if(n>Yi)return"[redacted]";if(Array.isArray(t))return t.map((r)=>Je(e,r,n+1));if(t!==null&&typeof t==="object"){let r={};for(let[o,i]of Object.entries(t))if(W(e,o))r[o]="[redacted]";else if(typeof i==="string"&&Vi(o))r[o]=Ht(e,i);else r[o]=Je(e,i,n+1);return r}return typeof t==="string"?de(e,t):t}function pr(e){if(!e.includes("\\"))return e;return e.replace(/\\u([0-9A-Fa-f]{4})|\\(.)/g,(t,n,r)=>n!==void 0?String.fromCharCode(Number.parseInt(n,16)):r)}function Xi(e,t){for(let n of t.matchAll(/"((?:[^"\\\r\n]|\\.)*)"\s*:\s*[{\[]/g))if(W(e,pr(n[1])))return"";return t.replace(/("((?:[A-Za-z0-9_-]|\\u[0-9A-Fa-f]{4}|\\.)+)"\s*:\s*)("(?:[^"\\]|\\.)*"?|[^,{}[\]"\r\n]*)/g,(n,r,o)=>W(e,pr(o))?`${r}"[redacted]"`:n)}function qt(e){let t=e.trimStart();return t.startsWith("{")||t.startsWith("[")}function Gi(e,t,n){let r=/boundary="?([^";]+)"?/i.exec(n);if(!r)return null;let o=`--${r[1]}`,i=t.split(o);if(i.length<3||i[0]!=="")return null;if(!i[i.length-1].startsWith("--"))return null;let s=[i[0]];for(let a=1;a<i.length-1;a++){let l=i[a];if(!l.startsWith(`\r
|
|
2
2
|
`)||!l.endsWith(`\r
|
|
3
3
|
`))return null;let d=l.indexOf(`\r
|
|
4
4
|
\r
|
|
5
|
-
`);if(d<0)return null;let g=l.slice(2,d),b=l.slice(d+4,-2),p=/content-disposition:[^\r\n]*;\s*name="([^"]*)"/i.exec(g)?.[1]??"",h=p!==""&&W(e,p)?"[redacted]":
|
|
5
|
+
`);if(d<0)return null;let g=l.slice(2,d),b=l.slice(d+4,-2),p=/content-disposition:[^\r\n]*;\s*name="([^"]*)"/i.exec(g)?.[1]??"",h=p!==""&&W(e,p)?"[redacted]":Ge(e,b);s.push(`\r
|
|
6
6
|
${g}\r
|
|
7
7
|
\r
|
|
8
8
|
${h}\r
|
|
9
|
-
`)}return s.push(i[i.length-1]),s.join(o)}var wr=262144;function fr(e,t,n){if(e.full||!t)return t;try{if(qt(t)){if(t.length<=wr)try{return JSON.stringify(Ge(e,JSON.parse(t),0))}catch{}return de(e,Vi(e,t))}let r=(n??"").toLowerCase();if(r.includes("x-www-form-urlencoded"))return Je(e,vr(e,W,t));if(r.includes("multipart/form-data")){let o=Yi(e,t,n??"");if(o!==null)return o;return`[multipart body omitted: unparseable (${t.length} chars)]`}return Je(e,t)}catch{return"[redacted]"}}function xr(e,t){if(t===void 0)return;if(e.full)return t;if(qt(t))try{return JSON.stringify(Ge(e,JSON.parse(t),0))}catch{}try{return Je(e,t)}catch{return"[redacted]"}}function Sr(e,t,n,r){if(e.full)return t.length>n?`${t.slice(0,n)}…[truncated]`:t;if(t.length>n&&r?.toLowerCase().includes("multipart/form-data"))return`[multipart body omitted: oversized (${t.length} chars)]`;if(qt(t)&&t.length<=wr){let i=fr(e,t,r);return i.length>n?`${i.slice(0,n)}…[truncated]`:i}let o=t.length>n?`${t.slice(0,n)}…[truncated]`:t;return fr(e,o,r)}function Er(e,t,n){if(!t)return;let r=n?.maxValueLen??1024,o=n?.budget??8192,i={};for(let[s,a]of Object.entries(t)){let d=(e.full?String(a):mr(e,s)?"[redacted]":de(e,String(a))).slice(0,r);if(o-=s.length+d.length,o<0){i["…"]="(truncated)";break}i[s]=d}return i}function Rr(e){if(e.full)return{maskAllInputs:!1,maskAllText:!1};return{maskAllInputs:!0,maskAllText:e.maskAllText,...e.maskAllText?{maskTextSelector:"*"}:{}}}var w={tabId:"root",tabHost:"/",pathname:"/"};function Tr(){try{let e=globalThis.sessionStorage,t=e.getItem("vitrinka.tab");if(t)return t;let n=Math.random().toString(36).slice(2,10);return e.setItem("vitrinka.tab",n),n}catch{return"root"}}function Mr(e,t){w.tabId=e,w.tabHost=t}var Ae={following:null},Ie="__vitrinkaCaptureOwner";function Cr(e,t){let n=globalThis,r=n[Ie];if(r){if(e==="report")return null;if(r.face==="report")n[Ie]=null,r.yieldTo?.()}let o=`${e}:${Date.now().toString(36)}.${Math.random().toString(36).slice(2,10)}`;return n[Ie]={face:e,token:o,...t?{yieldTo:t}:{}},o}function Ir(e){let t=globalThis;if(e&&t[Ie]?.token===e)t[Ie]=null}var Xi=new Set;function Pe(){for(let e of Xi)e()}async function Ar(e,t){let n=`vitrinka.recorder.${e}`;if(globalThis.navigator?.locks){await navigator.locks.request(n,{signal:AbortSignal.timeout(5000)},t);return}let r=await Ji();await new Promise((o,i)=>{let s=r.transaction("locks","readwrite");s.oncomplete=()=>o(),s.onabort=()=>i(s.error??Error("vitrinka: recorder lock transaction aborted"));let a=s.objectStore("locks").get(n);a.onsuccess=()=>{try{t()}catch(l){i(l),s.abort()}}})}var _e;function Ji(){if(!_e)_e=new Promise((e,t)=>{let n=indexedDB.open("vitrinka.recorder.locks",1);n.onupgradeneeded=()=>n.result.createObjectStore("locks"),n.onerror=()=>t(n.error),n.onsuccess=()=>{let r=n.result;r.onversionchange=()=>{r.close(),_e=void 0},e(r)}}).catch((e)=>{throw _e=void 0,e});return _e}var ee="vitrinka.recorder.",$t=null,Gi=!1;function z(){if(!$t)$t=Zi()??Qi();return Gi=!0,$t}function Zi(){try{let e=globalThis.localStorage;if(!e)return null;let t=`${ee}probe`;return e.setItem(t,"1"),e.removeItem(t),{getString:(n)=>e.getItem(ee+n),set:(n,r)=>e.setItem(ee+n,r),remove:(n)=>e.removeItem(ee+n),withLock:Ar,keys:()=>Array.from({length:e.length},(n,r)=>e.key(r)).filter((n)=>n!==null&&n.startsWith(ee)).map((n)=>n.slice(ee.length)),watch:(n,r)=>{let o=(i)=>{if(i.storageArea===e&&i.key===ee+n)r(i.newValue)};return globalThis.addEventListener("storage",o),()=>globalThis.removeEventListener("storage",o)}}}catch{return console.warn("vitrinka: localStorage unavailable — the recorder queue will not survive a reload"),null}}function Qi(){let e=new Map;return{getString:(t)=>e.get(t)??null,set:(t,n)=>void e.set(t,n),remove:(t)=>void e.delete(t),keys:()=>[...e.keys()]}}var Ze={url:"",key:""};function Qe(){return Ze}var Ft=new Set;function Pr(e){let t=e.replace(/\/+$/,"");return Ft.add(t),()=>Ft.delete(t)}function Kt(e){if(Ze.url!==""&&e.startsWith(Ze.url))return!0;for(let t of Ft)if(t!==""&&e.startsWith(t))return!0;return!1}var es="link";function ts(){let e=z().getString(es);if(!e)return null;try{let t=JSON.parse(e);return typeof t.token==="string"&&t.token?t:null}catch{return null}}function _r(){return Ze.key||ts()?.token||""}var ue=Bt(null);function Dr(e){ue=Bt(e??null)}function Nr(e){return xr(ue,e)}function Wt(e,t,n){return Sr(ue,e,t,n)}var Lr=null,Or=null;function zt(e){Or=e??null}function ns(e){let t=Or??Qe().sanitizeUrl;if(!t)return e;let n;try{let r=t(e);if(typeof r==="string")return r;n=`returned ${typeof r}`}catch{n="threw"}if(Lr!==t)Lr=t,console.warn(`vitrinka: sanitizeUrl ${n} — such URLs are recorded as their origin only`);return rs(e)??hr}function rs(e){try{let{origin:t}=new URL(e);return t==="null"?null:t}catch{return null}}function te(e){return Ht(ue,ns(e))}var os=4;function jt(e){return e.type===os}function Ut(e){if(!jt(e))return e;return{...e,data:{...e.data,href:te(e.data.href)}}}function Le(e){return Er(ue,e)}function Br(){return Rr(ue)}var De="data-vitrinka-recorder";var Vt="all:initial;position:fixed;z-index:2147483647;inset:0 auto auto 0;margin:0;padding:0;border:0;background:transparent;overflow:visible;width:0;height:0;pointer-events:none;color-scheme:normal;",Hr=Vt;var is=["pointerdown","pointerup","pointermove","pointerover","pointerout","pointercancel","mousedown","mouseup","mousemove","mouseover","mouseout","click","dblclick","auxclick","contextmenu","touchstart","touchend","touchmove","touchcancel","wheel","focusin","focusout","keydown","keyup","keypress","paste","dragenter","dragover","dragleave","drop"];function $r(e){for(let t of is)e.addEventListener(t,(n)=>n.stopPropagation())}function Fr(){let e=document.createElement("div");e.setAttribute(De,""),e.setAttribute("data-vitrinka-hud",""),e.style.cssText=Vt;let t=e.attachShadow({mode:"open"}),n=document.createElement("div");t.append(n),$r(e),document.documentElement.append(e);let r=typeof e.showPopover==="function",o=()=>{if(!r||!e.isConnected)return;try{e.hidePopover?.()}catch{}try{e.showPopover?.()}catch{}};if(r)e.popover="manual";o();let i=!1,s=()=>{if(i)return;i=!0,queueMicrotask(()=>{i=!1,o()})},a=(c)=>{if(c.type==="attributes")return c.target instanceof Element&&qr(c.target);for(let p of[c.addedNodes,c.removedNodes])for(let h of p){if(!(h instanceof Element))continue;if(qr(h))return!0;if(h.childElementCount>0&&h.querySelector(Kr))return!0}return!1},l=[],d=0,g=()=>{d=0;let c=l;if(l=[],c.some(a))s()},b=new MutationObserver((c)=>{for(let p of c)l.push(p);if(d===0)d=typeof requestAnimationFrame==="function"?requestAnimationFrame(g):setTimeout(g,16)});return b.observe(document.documentElement,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["open","data-state"]}),{host:e,mount:n,destroy:()=>{if(b.disconnect(),d!==0&&typeof cancelAnimationFrame==="function")cancelAnimationFrame(d);l=[];try{e.hidePopover?.()}catch{}e.remove()}}}var Kr='dialog,[role="dialog"]';function qr(e){return e.matches(Kr)}function Wr(){let e=document.querySelectorAll("dialog[open]"),t=e[e.length-1];if(t)return t;let n=document.querySelectorAll('[role="dialog"][data-state="open"]');return n[n.length-1]??null}function zr(e){let t=document.createElement("div");t.setAttribute(De,""),t.setAttribute("data-vitrinka-sheet",""),t.style.cssText=Hr;let n=t.attachShadow({mode:"open"}),r=document.createElement("div");return n.append(r),$r(t),e.append(t),{mount:r,destroy:()=>t.remove()}}function N(e,t,n,r={}){let o=e,i=o.__zone_symbol__addEventListener??e.addEventListener,s=o.__zone_symbol__removeEventListener??e.removeEventListener,a=r.capture??!1;return i.call(e,t,n,{capture:a,passive:!1}),()=>s.call(e,t,n,a)}class T extends Error{constructor(e,t){super(e);this.status=t,this.name="VitrinkaApiError"}}function j(e){return e>=400&&e<500&&e!==408&&e!==429}function jr(e){return e===401}var ss=null;function Ur(e){if(jr(e))ss?.()}function Vr(e){return e??{url:Qe().url,key:_r()}}async function O(e,t,n,r={}){let{url:o,key:i}=Vr(r.target),s=await fetch(o+t,{method:e,mode:"cors",credentials:"omit",keepalive:r.keepalive??!1,headers:{authorization:`Bearer ${i}`,...n!==void 0?{"content-type":"application/json"}:{}},body:n===void 0?void 0:JSON.stringify(n)}),a=await s.text();if(!s.ok){if(!r.target)Ur(s.status);throw new T(`${e} ${t} → ${s.status}: ${a}`,s.status)}return a?JSON.parse(a):{}}function Yr(e,t,n){return Jr(e,"chunk",t,"application/json",n)}function Xr(e,t,n){return Jr(e,"shot",t,n.type,n)}function Jr(e,t,n,r,o){return Yt(`/api/v1/sessions/${e}/${t}?seq=${n}`,r,o)}async function Yt(e,t,n,r){let{url:o,key:i}=Vr(r),s=await fetch(o+e,{method:"POST",mode:"cors",credentials:"omit",headers:{authorization:`Bearer ${i}`,"content-type":t},body:n}),a=await s.text();if(!s.ok){if(!r)Ur(s.status);throw new T(`POST ${e} → ${s.status}: ${a}`,s.status)}try{return JSON.parse(a)}catch{return{}}}var Gr=30000,as=4194304,ls=20000,Gt=500,cs=2000,ds=2,Zr={windowMs:Gr,checkoutMs:Gr,maxBytes:as,maxEvents:ls,maxLaneEvents:Gt},V=`${Date.now().toString(36)}.${Math.random().toString(36).slice(2,8)}`;function Zt(e,t){return t&&t.load===e.load?t.startMs:e.lastMs}var us=new TextEncoder,X=!1,Qr=0,E=Zr,v=[],M=[],B=[],U=[],ps=0,fe=[],he=new Map,ge=null,pe=null,Ne=!1,fs=0,Y=null,et=null,Jt=Promise.resolve();function eo(e=Zr){if(en(),X=!0,Qr++,E=e,Y=e.store??null,v=(e.prior??[]).filter((t)=>t.kind!=="lanes").map((t)=>({id:t.id,load:t.load,startMs:t.startMs,lastMs:t.lastMs,events:[],count:t.count,bytes:t.bytes,href:t.href,route:t.route,stored:!0})),M=(e.priorLanes??[]).slice(-e.maxLaneEvents),B=[],U=[],fe=(e.prior??[]).filter((t)=>t.kind==="lanes").map((t)=>({id:t.id,lastMs:t.lastMs})),he.clear(),ge=null,nt(Date.now()),Y)et=setInterval(tt,cs)}function to(){tt(),en(),X=!1,Y=null,v=[],M=[],B=[],U=[],fe=[],he.clear(),ge=null}function no(){return E}function Qt(e){pe=e}function ro(){if(!X)return;v=[],M=[],B=[],U=[],fe=[],he.clear(),ge=null;let e=w.tabId;ne((t)=>t.clear(e)),pe?.()}function oo(){return Jt}function tt(){if(!X||!Y)return;let e=Date.now();nt(e),tn(e);for(let t of v){if(t.stored)continue;let n=he.get(t.id)??{events:0,parts:0};if(n.events===t.events.length)continue;let r=JSON.stringify(t.events.slice(n.events)),o=n.parts;he.set(t.id,{events:t.events.length,parts:o+1});let i=io(t);ne((s)=>s.putWindowChunk(i,o,r,[]))}hs(e)}function hs(e){let t=e-E.windowMs;while(U.length>0&&U[0].lastMs<=t){let[a]=U.splice(0,1);if(a)ne((l)=>l.dropWindow(a.id))}for(let a of fe.filter((l)=>l.lastMs<=t))ne((l)=>l.dropWindow(a.id));fe=fe.filter((a)=>a.lastMs>t);let n=B;if(!n.length)return;B=[];let r=U.at(-1);if(!r||r.startMs<=t)r={id:`${V}.lanes.${++ps}`,startMs:Date.parse(n[0].ts),lastMs:0,parts:0},U.push(r);r.lastMs=Date.parse(n.at(-1).ts);let o=r.parts++,i=r,s={id:i.id,tab:w.tabId,scope:E.scope??"",kind:"lanes",load:V,startMs:i.startMs,lastMs:i.lastMs,count:0,bytes:0,href:"",route:""};ne((a)=>a.putWindowChunk(s,o,"[]",n))}function en(){if(et)clearInterval(et);et=null}function io(e){return{id:e.id,tab:w.tabId,scope:E.scope??"",load:e.load,startMs:e.startMs,lastMs:e.lastMs,count:e.count,bytes:e.bytes,href:e.href,route:e.route}}function ne(e){let t=Y;if(!t)return;Jt=Jt.then(()=>e(t)).catch((n)=>{if(Y!==t)return;Y=null,en(),console.warn("vitrinka: browser capture storage failed — the capture stays in memory for this page",n)})}function Xt(e){let[t]=v.splice(e,1);if(!t)return;he.delete(t.id),ne((n)=>n.dropWindow(t.id))}function nt(e){while(v.length>0){let r=v[0],o=v[1];if(!o&&r.load===V)break;if(Zt(r,o)>e-E.windowMs)break;Xt(0)}if(Ne)return;let t=v.at(-1);if(t&&t.load===V&&pe&&t.lastMs<=e-E.windowMs){Ne=!0;try{pe()}finally{Ne=!1}let r=v.indexOf(t);if(r>=0&&r<v.length-1)for(let o=r;o>=0;o--)Xt(o)}let n=!1;while(v.length>0&&gs()){if(v.length===1&&v[0].load===V&&!n&&pe){n=!0,Ne=!0;try{pe()}finally{Ne=!1}if(v.length>1)continue}Xt(0),ge=v[0]?.startMs??e}}function so(){return X?`flight:${Qr}`:null}function tn(e){let t=Math.min(v[0]?.startMs??Number.POSITIVE_INFINITY,e-E.windowMs),n=M.findIndex((r)=>Date.parse(r.ts)>=t);if(n===-1)M=[];else if(n>0)M=M.slice(n)}function gs(){let e=0,t=0;for(let n of v)e+=n.bytes,t+=n.count;return e>E.maxBytes||t>E.maxEvents}function ao(e){if(!X)return;let t=v[0];if(jt(e)){let r=globalThis.location?.pathname??w.pathname,o={id:`${V}.${++fs}`,load:V,startMs:e.timestamp,lastMs:e.timestamp,events:[],count:0,bytes:0,href:e.data.href,route:te(r)};v.push(o);let i=io(o);ne((s)=>s.putWindow(i))}let n=v.at(-1);if(!n||n.load!==V)return;if(n.events.push(e),n.count++,n.lastMs=Math.max(n.lastMs,e.timestamp),n.bytes+=us.encode(JSON.stringify(e)).length,nt(e.timestamp),v[0]!==t)tn(e.timestamp)}function lo(e,t,n){if(!X)return null;let r=E.keepLane?E.keepLane(e,t):t;if(r===null)return null;let o=new Date().toISOString(),i={ts:o,tabId:n.tabId,tabHost:n.tabHost,kind:e,payload:r},s=E.maxLaneEvents;if(M.push(i),M.length>s)M.splice(0,M.length-s);if(Y){if(B.push(i),B.length>s)B.splice(0,B.length-s)}return o}function nn(){if(!X)return null;let e=Date.now();return nt(e),tn(e),{windows:v.map((t)=>({...t,events:t.events.slice()})),lanes:M.slice(),truncated:ge!==null&&ge>e-E.windowMs}}function co(e){return e.windows.some((t)=>t.events[1]?.type===ds)}var rn=null;function rt(){if(!rn)rn=typeof indexedDB>"u"?ms():bs();return rn}function ms(){let e=new Map;return{durable:!1,put:async(t,n)=>void e.set(t,n),get:async(t)=>e.get(t)??null,delete:async(t)=>void e.delete(t),keys:async()=>[...e.keys()]}}function bs(){let e,t=()=>(e??=new Promise((r,o)=>{let i=indexedDB.open("vitrinka.recorder.blobs",1);i.onupgradeneeded=()=>i.result.createObjectStore("blobs"),i.onerror=()=>o(i.error??Error("vitrinka: blob journal did not open")),i.onsuccess=()=>{let s=i.result;s.onversionchange=()=>{s.close(),e=void 0},s.onclose=()=>{e=void 0},r(s)}}).catch((r)=>{throw e=void 0,r}),e),n=async(r,o)=>{let i=t(),s;try{s=(await i).transaction("blobs",r)}catch(l){if(e===i)e=void 0;throw l}let a=o(s.objectStore("blobs"));return new Promise((l,d)=>{s.oncomplete=()=>l(a.result),s.onabort=s.onerror=()=>d(s.error??a.error??Error("vitrinka: blob journal transaction failed"))})};return{durable:!0,put:async(r,o)=>void await n("readwrite",(i)=>i.put(o,r)),get:async(r)=>{let o=await n("readonly",(i)=>i.get(r));return o instanceof Blob?o:null},delete:async(r)=>void await n("readwrite",(o)=>o.delete(r)),keys:async()=>(await n("readonly",(r)=>r.getAllKeys())).filter((r)=>typeof r==="string")}}var ys=2000,ln=20000,vo=200,ks=4194304,vs=3145728,pt=500,ws=ks-1024,xs=12582912,Ss=10485760,Es=xs-64,Rs=1048576,Ts=new TextEncoder;function Re(e){return Ts.encode(e).length}var x=()=>z();function q(e,t){let n=x().getString(e);if(!n)return t;try{return JSON.parse(n)}catch{return t}}var uo=!1;function F(e,t){try{return x().set(e,t),!0}catch(n){if(!uo)uo=!0,console.warn("vitrinka: storage write failed — the queue tail is memory-only until it clears",n);return!1}}var st="rec",ie;function S(){if(ie===void 0)ie=q(st,null);return ie}function wo(e){if(ie=e,e===null)x().remove(st),x().remove(Ms);else F(st,JSON.stringify(Cs(e)))}var Ms="notes";var Be=null;function Cs(e){if(Be?.sessionId!==e.sessionId)return e;return{...e,paused:!0,activeMs:Be.activeMs,resumeAt:null,stopping:Be.at}}var Is=new Set;function As(){for(let e of Is)try{e()}catch(t){console.warn("vitrinka: before-stop hook failed",t)}}function Ps(e){let t=null;if(e)try{t=JSON.parse(e)}catch{return"unchanged"}let n=S();if(t?.stopping&&t.sessionId===n?.sessionId&&!n.paused&&Be?.sessionId!==t.sessionId)As();if(!t){if(!n)return"unchanged";return ie=null,ko(),Ws(),"ended"}if(n?.sessionId===t.sessionId){if(t.seq=Math.max(t.seq,n.seq),t.policy===void 0&&n.policy!==void 0)t.policy=n.policy;if(t.attachments===void 0&&n.attachments!==void 0)t.attachments=n.attachments;if(Be?.sessionId===t.sessionId)t.paused=n.paused,t.activeMs=n.activeMs,t.resumeAt=n.resumeAt,delete t.stopping;return ie=t,"updated"}return ie=t,ko(),"joined"}var _s=700,se,H=null,Z=!1;function be(){if(se===void 0)se=q("buffer",[]);return se}function ft(){if(H)clearTimeout(H),H=null;if(se!==void 0&&!Z)F("buffer",JSON.stringify(se))}function xo(){if(Z=!1,H)return;H=setTimeout(()=>{H=null,ft(),So()},_s)}function po(e){se=e,Z=!1,ft()}var me,ke=0;function re(){if(me===void 0)me=q("chunks",[]),ke=me.reduce((e,t)=>e+t.body.length,0);return me}function So(){if(Z)return;let e=re();if(e.length===0){x().remove("chunks");return}if(ke>Rs){x().remove("chunks");return}F("chunks",JSON.stringify(e))}function Ls(e){me=e,ke=e.reduce((t,n)=>t+n.body.length,0),Z=!1,So()}var at,ve=new Map,ye=new Set,we=new Map,ot=new Map,fo=5,Ds=200,Ns=67108864,Os=0,ho=!1,Bs="blobs";function C(){return at??=q("images",[]),at}function Eo(){if(Z)return;let e=C().filter((t)=>!ye.has(t.blob));if(e.length===0)x().remove("images");else F("images",JSON.stringify(e))}function Ro(e){at=e,Z=!1,Eo()}function Hs(e,t){let n=rt();if(!n.durable&&!ho)ho=!0,console.warn("vitrinka: no IndexedDB — an attached image will not survive a reload");F(Bs,"1");let r=[];return{drafts:t.map(({blob:i,payload:s})=>{let a=`${e}/${Io}.${++Os}`;return ve.set(a,i),ye.add(a),r.push(n.put(a,i).then(()=>{if(!(ve.has(a)||C().some((d)=>d.blob===a)||[...we.values()].includes(a)))return ye.delete(a),cn(a),!1;if(!n.durable)return!1;if(ye.delete(a),C().some((d)=>d.blob===a))Eo();return!0},(l)=>(console.warn("vitrinka: an attached image could not be journaled — it will not survive a reload",l),!1))),{blob:a,payload:s}}),journaled:Promise.all(r).then((i)=>i.every(Boolean))}}function cn(e){rt().delete(e).catch((t)=>console.warn("vitrinka: blob journal delete failed",t))}function xe(e,t){for(let n of e)if(ve.delete(n),ye.delete(n),ot.delete(n),t)cn(n)}var lt=(e)=>e.kind==="event"?(e.images??[]).map((t)=>t.blob):[];var qs=0,To="",Mo=0,go=-1;function dn(){qs=Date.now(),Mo=0,To=""}function Se(e){Mo++,To=String(e instanceof Error?e.message:e).slice(0,200)}var mo={actions:0,pages:0,frames:0,notes:0},$s=new Set;function Fs(e){let t={...mo};for(let n of e)if(n.kind==="click")t.actions++;else if(n.kind==="nav")t.pages++;else if(n.kind==="rrweb")t.frames+=typeof n.payload?.count==="number"?n.payload.count:1;else if(n.kind==="note"){if(t.notes++,typeof n.payload?.cid==="string")$s.add(n.payload.cid)}mo=t}function Ks(e){let t=S();if(!t||t.dead)return;if(t.dead=!0,t.deadReason=e,!t.paused&&t.resumeAt)t.activeMs=(t.activeMs||0)+(Date.now()-Date.parse(t.resumeAt)),t.resumeAt=null;wo(t),console.warn("vitrinka: session marked dead —",e),Pe()}var on=null;function Ws(){if(on)clearInterval(on);on=null}function Co(e){let t=S();if(!t||t.dead||e<1)return null;let n=q("seq",null),r=Math.max(t.seq,n?.sessionId===t.sessionId?n.seq:0)+1;return x().set("seq",JSON.stringify({sessionId:t.sessionId,seq:r+e-1})),t.seq=r+e-1,wo(t),{seq:r,sessionId:t.sessionId}}var Io=`${Date.now().toString(36)}.${Math.random().toString(36).slice(2)}`,ct="allocation.",zs=0,I=new Set,js=16777216,dt=0,ut=0,Ee=new Map;function ht(e){return e.kind==="event"?1+(e.images?.length??0):1}function Us(e,t){return new Set(Array.from({length:ht(t)},(n,r)=>e+r))}function un(e,t,n){return JSON.stringify(n&&n.size<ht(e)?{draft:e,seq:t,left:[...n]}:{draft:e,seq:t})}var bo=!1,Oe=null;function it(e){if(!I.delete(e))return;if(dt-=e.bytes,e.draft.kind==="chunk")ut--}function Ao(e){if(I.add(e),dt+=e.bytes,e.draft.kind==="chunk")ut++;while(I.size>ln||dt>js||ut>vo){let t=I.values().next().value;it(t),x().remove(t.key),xe(lt(t.draft),!0);let n=Error("vitrinka: pending allocation budget full — oldest capture dropped");Se(n),console.warn(n.message)}}function Po(e=!1){if(bo&&!e)return;bo=!0;let t=x();if(!t.withLock)return;let n=new Set([...I].map((r)=>r.key));for(let r of t.keys?.()??[]){if(!r.startsWith(ct)||n.has(r)||Ee.has(r))continue;let o=q(r,null);if(o&&o.draft&&o.draft.sessionId===S()?.sessionId)Ao({...o,key:r,persisted:!0,bytes:Re(JSON.stringify(o))})}}function _o(e,t,n){let{ts:r,tabId:o,tabHost:i,sessionId:s}=e,a=(l)=>!n||n.has(l);if(e.kind==="event"){let l=e.images??[],d=t+l.length,g=l.length?{...e.event,payload:{...e.event.payload,attachments:l.map((c,p)=>t+p)}}:e.event,b=be();if(a(d)&&!b.some((c)=>c.seq===d))b.push({seq:d,ts:r,tabId:o,tabHost:i,...g});if(l.length){let c=C();l.forEach((h,k)=>{let m=t+k;if(!a(m)||c.some((y)=>y.seq===m))return;if(b.some((y)=>y.seq===m)){we.set(m,h.blob);return}c.push({seq:m,ts:r,tabId:o,tabHost:i,sessionId:s,blob:h.blob,payload:h.payload})});let p=c.reduce((h,k)=>h+k.payload.bytes,0);while(c.length>Ds||p>Ns){let h=c.shift();p-=h.payload.bytes,G(h.sessionId,new Set([h.seq])),xe([h.blob],!0),console.warn(`vitrinka: attached image queue full — dropped ${h.payload.name} (seq ${h.seq}); its note lands without it`)}Ro(c)}if(b.length>ln){let c=b.splice(0,b.length-ln);G(s,new Set(c.map((p)=>p.seq))),console.warn(`vitrinka: retry buffer full — dropped ${c.length} oldest events`)}}else{let l=re();if(!l.some((d)=>d.seq===t)&&!be().some((d)=>d.seq===t))l.push({seq:t,ts:r,tabId:o,tabHost:i,sessionId:s,...e.part}),ke+=e.part.body.length;while(l.length>vo){let d=l.shift();ke-=d.body.length,G(s,new Set([d.seq])),console.warn(`vitrinka: pending chunk queue full — dropped rrweb chunk seq ${d.seq}`)}}xo(),oe()}function G(e,t){for(let[n,r]of Ee){if(r.sessionId!==e)continue;let o=r.seqs.size;for(let s of r.seqs)if(t.has(s))r.seqs.delete(s);let i=r.seqs.size&&r.seqs.size<o&&r.persisted?q(n,null):null;if(i){let s=new Set([...r.seqs].filter((a)=>!i.left||i.left.includes(a)));if(s.size)F(n,un(i.draft,i.seq,s));else r.seqs.clear()}if(r.seqs.size===0){x().remove(n),Ee.delete(n);let s=n.slice(ct.length,n.lastIndexOf(".")),a=`tab.${s}`,l=q(a,null);if(l?.departed&&l.recoverable&&!x().keys?.().some((d)=>d.startsWith(`${ct}${s}.`)))x().remove(a)}}}function Lo(){if(Oe)return Oe;let e=x();return Oe=pn(Promise.resolve().then(async()=>{for(let t of I)await e.withLock("seq",()=>{if(!I.has(t))return;if(t.persisted){let o=q(t.key,null);if(!o){it(t),xe(lt(t.draft),!1);return}t.seq=o.seq,t.left=o.left}if(Ps(e.getString(st)??null),S()?.sessionId!==t.draft.sessionId){it(t),xe(lt(t.draft),!0);return}let n=t.seq??Co(ht(t.draft))?.seq;if(n===void 0)return;t.seq=n;let r=t.left?new Set(t.left):Us(n,t.draft);if(t.persisted)e.set(t.key,un(t.draft,n,r));Ee.set(t.key,{sessionId:t.draft.sessionId,seqs:r,persisted:t.persisted}),_o(t.draft,n,r),it(t)})}).catch((t)=>{throw Se(t),console.warn("vitrinka: seq allocation failed — capture kept for retry",t),oe(),Pe(),t})).finally(()=>{Oe=null}),Oe}function Do(e,t){let n=S(),r=e.kind==="event"&&e.event.kind==="note";if(!n||n.dead||n.paused&&!r)return!1;if(Po(),x().withLock){let o=`${ct}${Io}.${++zs}`,i=JSON.stringify({draft:e}),s={key:o,draft:e,persisted:!t&&F(o,i),bytes:Re(i)};Ao(s),Lo(),t?.then((a)=>{if(a)Vs(s)})}else{let o=Co(ht(e));if(o)_o(e,o.seq);else xe(lt(e),!0)}return!0}function Vs(e){let t=Ee.get(e.key);if(t)t.persisted=F(e.key,un(e.draft,e.seq,t.seqs));else if(I.has(e))e.persisted=F(e.key,JSON.stringify({draft:e.draft}))}var yo=new Set;function pn(e){return yo.add(e),e.catch(()=>{return}).finally(()=>{yo.delete(e)})}function J(e){return S()?.sessionId!==e.sessionId}function He(e,t,n,r=[]){if(Ae.following)return null;let o=S();if(!o)return lo(e,t,n);if(o.dead||o.paused&&e!=="note")return null;let i=new Date().toISOString(),{tabId:s,tabHost:a}=n,l=r.length?Hs(o.sessionId,r):null;return Do({sessionId:o.sessionId,ts:i,tabId:s,tabHost:a,kind:"event",event:{kind:e,payload:t},...l?{images:l.drafts}:{}},l?.journaled),fn(),i}function No(e){be().push(e),fn(),xo(),oe()}var Ys=Date.now();function fn(){Ys=Date.now()}function hn(e,t=Ss,n=Es){let r=[],o=[],i=[],s=2,a=()=>{if(!i.length)return;r.push({count:i.length,body:`[${i.join(",")}]`}),i=[],s=2};for(let l of e){let d=JSON.stringify(l),g=Re(d)+1;if(g>n){o.push(g);continue}if(g>t){a(),r.push({count:1,body:`[${d}]`});continue}if(i.length&&s+g>t)a();i.push(d),s+=g}return a(),{parts:r,dropped:o}}function Oo(e,t){if(!e.length)return 0;let n=S();if(!n||n.paused||n.dead||Ae.following)return 0;let{parts:r,dropped:o}=hn(e);for(let l of o)console.warn(`vitrinka: rrweb event (${l} bytes) exceeds the chunk cap — dropped`),He("note",{text:`⚠ rrweb event dropped (${(l/1048576).toFixed(1)} MiB > chunk cap) — replay may be incomplete from here`},t);let i=new Date().toISOString(),{tabId:s,tabHost:a}=t;for(let l of r)if(!Do({sessionId:n.sessionId,ts:i,tabId:s,tabHost:a,kind:"chunk",part:l}))return 0;return fn(),r.length}async function Xs(e=5){let t=re();if(t.length===0)return!0;let n=S(),r=0,o=new Set;for(let i of t){if(r>=e)break;if(r++,!n||i.sessionId!==n.sessionId){console.warn(`vitrinka: dropping rrweb chunk seq ${i.seq} from ended session ${i.sessionId}`),o.add(i.seq);continue}try{let s=await Yr(n.sessionId,i.seq,i.body);if(J(n))return re().length===0;No({seq:i.seq,ts:i.ts,tabId:i.tabId,tabHost:i.tabHost,kind:"rrweb",payload:{count:i.count},blobKey:s.blobKey}),dn(),o.add(i.seq)}catch(s){if(J(n))return re().length===0;if(s instanceof T&&j(s.status)){console.warn(`vitrinka: rrweb chunk seq ${i.seq} rejected permanently (${s.status}) — dropped`),G(i.sessionId,new Set([i.seq])),o.add(i.seq);continue}Se(s),console.warn("vitrinka: chunk upload failed",s);break}}if(o.size)Ls(re().filter((i)=>!o.has(i.seq)));return re().length===0}async function Js(e=4){let t=C();if(t.length===0)return!0;let n=S(),r=0,o=new Set,i=[];for(let s of t){if(r>=e)break;if(r++,!n||s.sessionId!==n.sessionId){console.warn(`vitrinka: dropping attachment seq ${s.seq} from ended session ${s.sessionId}`),o.add(s.seq),i.push(s.blob);continue}let a=ve.get(s.blob)??null;if(!a){try{a=await rt().get(s.blob),ot.delete(s.blob)}catch(l){if(J(n))return C().length===0;let d=(ot.get(s.blob)??0)+1;if(console.warn(`vitrinka: blob journal read failed (${d}/${fo})`,l),d<fo){ot.set(s.blob,d),Se(l);break}}if(J(n))return C().length===0}if(!a){console.warn(`vitrinka: attachment seq ${s.seq} (${s.payload.name}) lost its bytes — its note lands without it`),G(s.sessionId,new Set([s.seq])),o.add(s.seq),i.push(s.blob);continue}try{let l=await Xr(n.sessionId,s.seq,a);if(J(n))return C().length===0;No({seq:s.seq,ts:s.ts,tabId:s.tabId,tabHost:s.tabHost,kind:"attachment",payload:{...s.payload},blobKey:l.blobKey}),ve.delete(s.blob),we.set(s.seq,s.blob),dn(),o.add(s.seq)}catch(l){if(J(n))return C().length===0;if(l instanceof T&&j(l.status)){console.warn(`vitrinka: attachment seq ${s.seq} rejected permanently (${l.status}) — dropped`),G(s.sessionId,new Set([s.seq])),o.add(s.seq),i.push(s.blob);continue}Se(l),console.warn("vitrinka: attachment upload failed",l);break}}if(o.size)ft(),Ro(C().filter((s)=>!o.has(s.seq)));return xe(i,!0),C().length===0}var sn=null;function oe(){if(sn)return;sn=setTimeout(()=>{sn=null,Gs()},ys)}var an=!1;async function Gs(e={}){if(an)return!1;an=!0;try{return await Zs(e)}finally{an=!1}}async function Zs(e){if(S()?.dead)return!1;if(Po(!0),I.size)await Lo();if(I.size)return!1;let t=await Xs(),n=e.keepalive?C().length===0:await Js(),r=t&&n;if(!r)oe();let o=S(),i=be();if(!o||i.length===0)return r;let s=[],a=new Set,l=0,d=e.keepalive?61440:vs;for(let c of i){if(s.length>=pt)break;let p=Re(JSON.stringify(c))+1;if(p>ws){console.warn(`vitrinka: event seq ${c.seq} (${p} bytes) exceeds the wire cap — dropped`),a.add(c.seq);continue}if(p>d){if(e.keepalive)break;if(s.length===0)s.push(c),l=p;break}if(s.length>0&&l+p>d)break;s.push(c),l+=p}if(a.size){if(G(o.sessionId,a),po(be().filter((c)=>!a.has(c.seq))),!s.length)return oe(),!1}if(!s.length)return!1;ft();try{await O("POST",`/api/v1/sessions/${o.sessionId}/events`,{events:s},e)}catch(c){if(J(o))return!1;if(c instanceof T&&j(c.status))return Ks(`server rejected this session (${c.status})`),!1;return Se(c),Pe(),console.warn("vitrinka: flush failed, retrying",c),oe(),!1}if(J(o))return!0;dn(),go=Math.max(go,...s.map((c)=>c.seq)),Fs(s);let g=new Set(s.map((c)=>c.seq));G(o.sessionId,g);let b=be().filter((c)=>!g.has(c.seq));po(b),Pe();for(let c of g){let p=we.get(c);if(p===void 0)continue;we.delete(c),cn(p)}if(b.length)oe();return!0}function ko(){if(H)clearTimeout(H),H=null;se=[],me=[],ke=0,at=[],ve.clear(),ye.clear(),we.clear(),I.clear(),dt=ut=0,Ee.clear(),Z=!0}var Qs=8192,qe="__vitrinkaRecorderConsolePatched";function gt(e){return e.map((t)=>{if(typeof t==="string")return t;if(t instanceof Error)return t.stack??t.message;try{return JSON.stringify(t)}catch{return String(t)}}).join(" ").slice(0,Qs)}function mt(e,t="error"){if(!e||e.startsWith("vitrinka:"))return;He("console",{level:t,text:Nr(e)},{tabId:w.tabId,tabHost:w.tabHost})}var gn="__vitrinkaRecorderConsoleUnpatch",Bo={};function Ho(){let e=globalThis;if(e[qe]!==void 0&&e[qe]!==Bo)return;e[gn]?.()}function qo(e={}){let t=globalThis;if(t[qe])return;t[qe]=Bo;let n=console.error,r=n.bind(console),o=(...d)=>{r(...d);try{mt(gt(d))}catch{}};console.error=o;let i=(e.levels??[]).map((d)=>{let g=console[d],b=g.bind(console),c=(...p)=>{b(...p);try{mt(gt(p),d)}catch{}};return console[d]=c,()=>{if(console[d]===c)console[d]=g}}),s=(d)=>{try{mt(gt([d.error??d.message]))}catch{}},a=(d)=>{try{mt(`unhandled rejection: ${gt([d.reason])}`)}catch{}},l=typeof addEventListener==="function";if(l)addEventListener("error",s),addEventListener("unhandledrejection",a);t[gn]=()=>{if(console.error===o)console.error=n;for(let d of i)d();if(l)removeEventListener("error",s),removeEventListener("unhandledrejection",a);delete t[qe],delete t[gn]}}var $o=65536,$e=524288,Fo=3000;var mn="full";function yn(){if(Ae.following)return null;let e=S();if(e)return!e.paused&&!e.dead?e.sessionId:null;return so()}function Fe(e){return e!==null&&yn()===e}function bt(e,t){if(typeof e==="string")return Wt(e,$o,t);if(typeof URLSearchParams<"u"&&e instanceof URLSearchParams)return Wt(e.toString(),$o,"application/x-www-form-urlencoded");return ea(e)}function ea(e){if(e==null)return;if(typeof FormData<"u"&&e instanceof FormData){let t=0;try{e.forEach(()=>t++)}catch{}return`[formdata body omitted: ${t} field(s)]`}if(typeof Blob<"u"&&e instanceof Blob)return`[blob body omitted: ${e.size} bytes${e.type?`, ${e.type}`:""}]`;if(e instanceof ArrayBuffer)return`[buffer body omitted: ${e.byteLength} bytes]`;if(ArrayBuffer.isView(e))return`[buffer body omitted: ${e.byteLength} bytes]`;if(typeof ReadableStream<"u"&&e instanceof ReadableStream)return"[stream body omitted]";return`[${typeof e} body omitted]`}function bn(e){for(let[t,n]of Object.entries(e??{}))if(t.toLowerCase().replace(/[-_]/g,"")==="contenttype")return n;return""}function kn(e){return typeof e==="string"||e instanceof URL?{}:e}function Ke(e){let t=typeof e.url==="string"?te(e.url):e.url;He("net",{...e,url:t},{tabId:w.tabId,tabHost:w.tabHost})}function vn(e){if(!e)return;try{let t={},n=e;if(typeof n.forEach==="function")if(Array.isArray(e)){for(let r of e)if(Array.isArray(r)&&r.length>=2)t[String(r[0])]=String(r[1])}else n.forEach((r,o)=>{t[o]=String(r)});else if(typeof e==="object")for(let[r,o]of Object.entries(e))t[r]=String(o);return Object.keys(t).length>0?t:void 0}catch{return}}function ta(e,t){let n=vn(t?.headers);if(n)return n;let r=kn(e);return vn(r.headers)}function na(e){if(!e)return;let t={};for(let n of e.split(/\r?\n/)){let r=n.indexOf(":");if(r>0)t[n.slice(0,r).trim()]=n.slice(r+1).trim()}return Object.keys(t).length>0?t:void 0}function wn(e){try{e.body?.cancel?.().catch(()=>{return})}catch{}}function ra(e){let t=e.get("content-length");if(!t)return null;let n=Number(t);return Number.isFinite(n)?n:null}async function oa(e,t){let n=await ia(e,t);if(n===void 0)return;let r="";try{r=t.get("content-type")??""}catch{}return bt(n,r)}async function ia(e,t){let n=ra(t);if(n!==null&&n>$e)return wn(e),`[body omitted: ${n} bytes]`;let r=e.body;if(r?.getReader){let o=r.getReader(),i=[],s=0,a=!1,l=!1,d=Date.now()+Fo;try{while(s<$e){let p=d-Date.now();if(p<=0){l=!0;break}let h,k=await Promise.race([o.read(),new Promise((f)=>{h=setTimeout(()=>f("timeout"),p)})]).finally(()=>{if(h!==void 0)clearTimeout(h)});if(k==="timeout"){l=!0;break}let{done:m,value:y}=k;if(m)break;if(y){let f=$e-s,R=y.byteLength>f?y.subarray(0,f):y;i.push(R),s+=R.byteLength}}a=s>=$e,o.cancel().catch(()=>{return})}catch{return}let g=new Uint8Array(s),b=0;for(let p of i)g.set(p,b),b+=p.byteLength;let c;try{c=new TextDecoder().decode(g)}catch{return`[body omitted: ${s} bytes, undecodable]`}if(l)return`${c}…[body read timed out after ${Fo}ms]`;return a?`${c}…[truncated at ${$e} bytes]`:c}if(n===null)return wn(e),"[body omitted: length-less response, no stream API]";try{return await e.text()}catch{return}}var We="__vitrinkaRecorderNetPatched",xn="__vitrinkaRecorderNetUnpatch",Ko={};function Wo(){let e=globalThis;if(e[We]!==void 0&&e[We]!==Ko)return;e[xn]?.()}function zo(e={}){let t=globalThis;if(t[We])return;t[We]=Ko,mn=e.detail??"full";let n=[];t[xn]=()=>{for(let c of n.splice(0))c();delete t[We],delete t[xn]};let r=globalThis.fetch,o=async(c,p)=>{let h=typeof c==="string"?c:c instanceof URL?c.href:c.url,k=yn();if(Kt(h)||k===null)return r(c,p);let m=p?.method??("method"in kn(c)?kn(c).method:"GET"),y=Date.now();try{let f=await r(c,p),R=Date.now()-y;if(mn==="meta"){if(Fe(k))Ke({method:m,url:h,status:f.status,ms:R,via:"fetch"});return f}let D;try{D=f.clone()}catch{D=void 0}let{headers:Te,status:Ve}=f;return pn((async()=>{if(!Fe(k)){if(D)wn(D);return}let Ye=D?await oa(D,Te):void 0;if(!Fe(k))return;let Me=ta(c,p);Ke({method:m,url:h,status:Ve,ms:R,reqHeaders:Le(Me),resHeaders:Le(vn(Te)),reqBody:bt(p?.body,bn(Me)),resBody:Ye,via:"fetch"})})()),f}catch(f){if(Fe(k))Ke({method:m,url:h,error:String(f),ms:Date.now()-y,via:"fetch"});throw f}};globalThis.fetch=o,n.push(()=>{if(globalThis.fetch===o)globalThis.fetch=r});let i=globalThis.XMLHttpRequest;if(!i?.prototype)return;let s=i.prototype.open,a=i.prototype.send,l=i.prototype.setRequestHeader;n.push(()=>{let c=i.prototype;if(c.open===d)c.open=s;if(c.send===b)c.send=a;if(c.setRequestHeader===g)c.setRequestHeader=l});let d=i.prototype.open=function(...c){return this.__vt={method:c[0],url:String(c[1])},s.apply(this,c)},g=i.prototype.setRequestHeader=function(c,p){let h=this.__vt;if(h)(h.reqHeaders??={})[c]=p;return l?.call(this,c,p)},b=i.prototype.send=function(c){let p=this.__vt,h=yn();if(p&&!Kt(p.url)&&h!==null){let k=Date.now();this.addEventListener("loadend",()=>{if(!Fe(h))return;if(mn==="meta"){Ke({method:p.method,url:p.url,status:this.status,ms:Date.now()-k,via:"xhr"});return}let m;try{m=na(this.getAllResponseHeaders())}catch{m=void 0}let y;try{y=this.responseType===""||this.responseType==="text"?bt(this.responseText,bn(m)):void 0}catch{y=void 0}Ke({method:p.method,url:p.url,status:this.status,ms:Date.now()-k,reqHeaders:Le(p.reqHeaders),resHeaders:Le(m),reqBody:bt(c,bn(p.reqHeaders)),resBody:y,via:"xhr"})})}return a.call(this,c)}}var sa=2000,aa=300000,je=null,Ue=null,ze=[],yt=null;function jo(){if(!ze.length)return;let e=ze;ze=[],Oo(e,{tabId:w.tabId,tabHost:w.tabHost})}function kt(){return Ue}function Uo(e,t,n={}){if(je)return;let r=Br(),o=n.unmaskSelector;try{je=e({emit:t==="flight"?(s)=>ao(Ut(s)):(s)=>{ze.push(Ut(s))},checkoutEveryNms:t==="flight"?no().checkoutMs:aa,inlineImages:!1,collectFonts:!0,maskAllInputs:r.maskAllInputs,...r.maskTextSelector?{maskTextSelector:r.maskTextSelector}:{},...r.maskTextSelector&&o?{maskTextFn:(s,a)=>{try{if(a?.closest(o))return s}catch{}return s.replace(/\S/g,"*")}}:{},blockSelector:`[${De}]`})??null}catch(i){console.warn("vitrinka: rrweb failed to start",i);return}if(Ue=e,t==="flight")Qt(Sn);if(t==="session")yt=setInterval(jo,sa)}function Vo(){if(yt)clearInterval(yt);yt=null,jo();try{je?.()}catch{}je=null,Ue=null,Qt(null),ze=[]}function Sn(){if(!je||!Ue)return;try{Ue.takeFullSnapshot?.(!0)}catch{}}var Jo="vitrinka.capture",A="windows",P="chunks";function ae(e){return new Promise((t,n)=>{e.oncomplete=()=>t(),e.onabort=e.onerror=()=>n(e.error??Error("vitrinka: capture store transaction failed"))})}function En(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error??Error("vitrinka: capture store request failed"))})}function Yo(e){return IDBKeyRange.bound([e,0],[e,Number.MAX_SAFE_INTEGER])}function Xo(e){if(typeof e!=="object"||e===null)return!1;let t=e;return typeof t.id==="string"&&typeof t.tab==="string"&&typeof t.startMs==="number"&&typeof t.lastMs==="number"}function Go(e=globalThis.indexedDB){if(!e)return Promise.reject(Error("vitrinka: IndexedDB is not available"));return new Promise((t,n)=>{let r=e.open(Jo,1);r.onupgradeneeded=()=>{r.result.createObjectStore(A,{keyPath:"id"}),r.result.createObjectStore(P)},r.onerror=()=>n(r.error??Error("vitrinka: capture store did not open")),r.onblocked=()=>n(Error("vitrinka: capture store is blocked by another tab")),r.onsuccess=()=>t(r.result)}).then((t)=>{t.onversionchange=()=>t.close();let n=(o,i)=>{o.objectStore(A).delete(i),o.objectStore(P).delete(Yo(i))};return{async putWindow(o){let i=t.transaction(A,"readwrite");i.objectStore(A).put(o),await ae(i)},async putChunk(o,i,s,a){let l=t.transaction(P,"readwrite"),d={events:s,lanes:[...a]};l.objectStore(P).put(d,[o,i]),await ae(l)},async putWindowChunk(o,i,s,a){let l=t.transaction([A,P],"readwrite"),d={events:s,lanes:[...a]};try{l.objectStore(P).put(d,[o.id,i]),l.objectStore(A).put(o)}catch(g){throw l.abort(),g}await ae(l)},async dropWindow(o){let i=t.transaction([A,P],"readwrite");n(i,o),await ae(i)},async clear(o){let i=t.transaction([A,P],"readwrite"),s=await En(i.objectStore(A).getAll());for(let a of s)if(Xo(a)&&a.tab===o)n(i,a.id);await ae(i)},async sweep(o,i,s,a){let l=t.transaction([A,P],"readwrite"),d=(await En(l.objectStore(A).getAll())).filter(Xo),g=[],b=new Map;for(let c of d)b.set(c.tab,[...b.get(c.tab)??[],c]);for(let[c,p]of b){let h=p.filter((m)=>m.kind!=="lanes").sort((m,y)=>m.startMs-y.startMs),k=(m)=>m.kind==="lanes"?m.lastMs:Zt(m,h[h.indexOf(m)+1]);for(let m of p.sort((y,f)=>y.startMs-f.startMs))if(k(m)<=o-i||c===s&&m.scope!==a)n(l,m.id);else if(c===s)g.push(m)}return await ae(l),g},async read(o){let i=t.transaction(P,"readonly"),s=await En(i.objectStore(P).getAll(Yo(o)));await ae(i);let a=[],l=[];for(let d of s)a.push(...JSON.parse(d.events)),l.push(...d.lanes);return{events:a,lanes:l}},close:()=>t.close()}})}function Zo(e=globalThis.indexedDB){try{e?.deleteDatabase(Jo)}catch(t){console.warn("vitrinka: could not delete the capture store",t)}}function Rn(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),w:Math.abs(t.x-e.x),h:Math.abs(t.y-e.y)}}function Tn(e,t){return`${t.y<e.y?"n":"s"}${t.x<e.x?"w":"e"}`}function Mn(e,t){let n=e.x,r=e.x+e.w,o=e.y,i=e.y+e.h,s={x:t.endsWith("w")?n:r,y:t.startsWith("n")?o:i};return{tail:{x:t.endsWith("w")?r:n,y:t.startsWith("n")?i:o},tip:s}}function Qo(e,t,n){if(e==="arrow")return Math.hypot(n.x-t.x,n.y-t.y)>=16;return Math.abs(n.x-t.x)>=8&&Math.abs(n.y-t.y)>=8}function ei(e){return e.map((t,n)=>({...t,n:n+1}))}function ti(e){return e.map((t)=>({n:t.n,shape:t.shape,rect:{x:Math.round(t.rect.x),y:Math.round(t.rect.y),w:Math.round(t.rect.w),h:Math.round(t.rect.h)},...t.note.trim()?{note:t.note.trim()}:{},...t.shape==="arrow"&&t.head?{head:t.head}:{}}))}var la=2,ca=3,da=0,ua=5,Cn=2,pa=3,fa=2000000000,ha="data-vitrinka-hidden",ga="#1b1b1f";function ma(e,t){let n=`position:fixed;left:${Math.round(e.x)}px;top:${Math.round(e.y)}px;width:${Math.round(e.w)}px;height:${Math.round(e.h)}px;background:${ga};z-index:2147483647;pointer-events:none;`;return{type:Cn,id:fa+t,tagName:"div",attributes:{[ha]:"",style:n},childNodes:[]}}function In(e,t,n,r){let o={...e};if(e.type===pa&&t.has(e.id))o.textContent="";if(e.attributes&&t.has(e.id)&&"value"in e.attributes)o.attributes={...e.attributes,value:""};if(e.childNodes){if(o.childNodes=e.childNodes.map((i)=>In(i,t,n,r)),!r.done&&e.type===Cn&&e.tagName==="body")o.childNodes.push(...n),r.done=!0}return o}function ba(e,t){(e.childNodes?.find((r)=>r.type===Cn)??e).childNodes?.push(...t)}function ya(e,t){return In(e,t,[],{done:!0})}function ni(e,t,n){if(!t.length&&!n.size)return e.slice();let r=t.map(ma);return e.map((o)=>{let i=o.data;if(o.type===la&&i.node){let s={done:!1},a=In(i.node,n,r,s);if(!s.done)ba(a,r);return{...o,data:{...o.data,node:a}}}if(o.type!==ca||!n.size)return o;if(i.source===da){let s=o.data,a={...s,...s.texts?{texts:s.texts.map((l)=>n.has(l.id)?{...l,value:""}:l)}:{},...s.adds?{adds:s.adds.map((l)=>({...l,node:ya(l.node,n)}))}:{},...s.attributes?{attributes:s.attributes.map((l)=>n.has(l.id)&&("value"in l.attributes)?{...l,attributes:{...l.attributes,value:""}}:l)}:{}};return{...o,data:a}}if(i.source===ua){let s=o.data;if(n.has(s.id))return{...o,data:{...s,text:""}}}return o})}function ka(e,t){return e.x>=t.x&&e.x<=t.x+t.w&&e.y>=t.y&&e.y<=t.y+t.h}function va(e){return{x:e.left+e.width/2,y:e.top+e.height/2}}function An(e,t,n=document){let r=new Set;if(!e.length||!t||!n.body)return r;let o=(l)=>l.width>0&&l.height>0&&e.some((d)=>ka(va(l),d)),i=(l)=>{let d=t.getId(l);if(d>0)r.add(d)},s=n.createTreeWalker(n.body,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT),a=n.createRange();for(let l=s.nextNode();l;l=s.nextNode())if(l.nodeType===Node.TEXT_NODE){if(!l.textContent?.trim())continue;if(a.selectNodeContents(l),o(a.getBoundingClientRect()))i(l)}else if(l instanceof HTMLInputElement||l instanceof HTMLTextAreaElement||l instanceof HTMLSelectElement){if(o(l.getBoundingClientRect()))i(l)}return a.detach(),r}var wa=["errors","interactions","full","console","network"];var vt={storage:"memory",windowSec:300,maxBytes:12582912,classes:["errors","interactions"]};function St(e){return{storage:"memory",windowSec:60,maxBytes:4194304,classes:e===!1?["errors"]:["errors","interactions"]}}function wt(e,t,n){return Math.min(n,Math.max(t,e))}function xa(e){if(!Array.isArray(e))return null;return wa.filter((t)=>e.includes(t))}function ri(e,t){if(typeof e!=="object"||e===null)return St(t);let n=e;return{storage:n.storage==="browser"?"browser":n.storage==="memory"?"memory":vt.storage,windowSec:typeof n.windowSec==="number"&&Number.isFinite(n.windowSec)?wt(Math.round(n.windowSec),10,3600):vt.windowSec,maxBytes:typeof n.maxBytes==="number"&&Number.isFinite(n.maxBytes)?wt(Math.round(n.maxBytes),262144,67108864):vt.maxBytes,classes:xa(n.classes)??vt.classes}}function xt(e){let t=e.includes("full");return{replay:t||e.includes("interactions"),errors:t||e.includes("errors"),console:t||e.includes("console"),network:t||e.includes("network")}}function Sa(e){let t=[];if(e.errors)t.push("errors");if(e.replay)t.push("interactions");if(e.console)t.push("console");if(e.network)t.push("network");return t}function oi(e,t){if(!t)return e;let n=typeof t.windowSec==="number"&&t.windowSec>0?Math.min(e.windowSec,t.windowSec):e.windowSec,r=typeof t.maxBytes==="number"&&t.maxBytes>0?Math.min(e.maxBytes,t.maxBytes):e.maxBytes,o=e.classes;if(t.classes){let i=xt(e.classes),s=xt(t.classes);o=Sa({replay:i.replay&&s.replay,errors:i.errors&&s.errors,console:i.console&&s.console,network:i.network&&s.network})}return{storage:t.storage==="memory"?"memory":e.storage,windowSec:wt(n,10,3600),maxBytes:wt(r,262144,67108864),classes:o}}function ii(e){return e==="balanced"||e==="full"?e:"strict"}function si(e){if(e==="full")return{fullFidelity:!0};if(e==="balanced")return{};return{maskAllText:!0}}var ai="[data-vitrinka-unmask]";var Ea=3670016,li=4194240,Ra=2000,ci=500,Ta=60000,Ma=/[A-Za-z0-9_-]{20,}/g;function K(e,t=""){return typeof e==="string"?e:t}function Ca(e){let t=K(e),n;try{n=new URL(t,globalThis.location?.href??"http://localhost").pathname}catch{n=t.split(/[?#]/)[0]??""}return n.replace(Ma,"•••").slice(0,300)}var Ia=4;function Aa(e,t){let n=[],r=!1,o=[],i=!1,s=()=>{if(i)r=!0;else n.push(...o);o=[],i=!1};for(let a of e){if(a.type===Ia&&o.length)s();if(!i&&Re(JSON.stringify(a))+1>t)i=!0;o.push(a)}return s(),{events:n,dropped:r}}function Pa(e){return(t,n)=>{if(t==="console"){let r=K(n?.level,"error");if(r==="error"?!(e.errors||e.console):!e.console)return null;return{level:r,text:K(n?.text).slice(0,Ra)}}if(t==="net"){let r=typeof n?.status==="number"?n.status:0,o=r===0||r>=400||n?.error!==void 0;if(!(e.network||e.errors&&o))return null;return{method:K(n?.method,"GET").toUpperCase(),path:Ca(n?.url),status:r,ms:typeof n?.ms==="number"?Math.max(0,Math.round(n.ms)):0}}return null}}async function _a(e){try{let t=await O("GET","/api/v1/report-config",void 0,{target:e}),n=typeof t.flightRecorder==="boolean"?t.flightRecorder:void 0;return{project:K(t.project),profile:t.captureProfile==null?St(n):ri(t.captureProfile,n),masking:ii(t.profile),reachable:!0}}catch(t){return console.warn("vitrinka: report config unavailable — capturing the last minute, strictly masked",t),{project:"",profile:St(),masking:"strict",reachable:!1}}}function di(e){let t=e?.mirror;if(typeof t!=="object"||t===null)return null;let n=t.getId;return typeof n==="function"?{getId:(r)=>Number(n.call(t,r))}:null}class ui{opts;ready;store=null;stopped=!1;claim=null;config=null;listeners=new Set;capturing=!1;offs=[];capture=[];constructor(e){this.opts=e;this.ready=this.start()}async start(){let{opts:e}=this;this.offs.push(Pr(e.base));let t=await _a({url:e.base,key:e.key}),n=oi(t.profile,e.capture),r=xt(n.classes),o={project:t.project,profile:n,lanes:r,masking:t.masking,reachable:t.reachable,capturing:!1};if(this.stopped)return o;if(this.config=o,this.claim=Cr("report",()=>this.standDown()),!this.claim)return console.warn("vitrinka: the recorder runs this page’s capture — Report a problem sends without one"),o;this.capturing=!0,o.capturing=!0,Mr(Tr(),globalThis.location?.host??""),w.pathname=globalThis.location?.pathname??"/",Dr(si(o.masking)),zt(e.sanitizeUrl),this.capture.push(()=>zt(null));let i=n.windowSec*1000,s=[e.base,t.project,o.masking,n.classes.join(",")].join("|"),a=[],l=[];if(n.storage==="browser")try{this.store=await Go();let d=await this.store.sweep(Date.now(),i,w.tabId,s);a=d;let g=this.store;l=(await Promise.all(d.filter((c)=>c.kind==="lanes").map((c)=>g.read(c.id)))).flatMap((c)=>c.lanes).sort((c,p)=>Date.parse(c.ts)-Date.parse(p.ts))}catch(d){console.warn("vitrinka: browser capture storage unavailable — keeping the capture in memory",d),this.store=null,a=[],l=[]}else Zo();if(!this.capturing)return this.store?.close(),this.store=null,o;if(eo({windowMs:i,checkoutMs:Math.min(Ta,i),maxBytes:n.maxBytes,maxEvents:Math.max(20000,Math.round(n.maxBytes/200)),maxLaneEvents:Gt,keepLane:Pa(r),store:this.store,scope:s,prior:a,priorLanes:l}),this.capture.push(to),this.store&&typeof window<"u"){let d=()=>tt();this.capture.push(N(window,"pagehide",d),N(document,"visibilitychange",d))}if(r.errors||r.console)qo({levels:r.console?["warn","info","log"]:[]}),this.capture.push(Ho);if(r.errors||r.network)zo({detail:"meta"}),this.capture.push(Wo);if(r.replay){let d=await e.loadRecord(e.base).catch((g)=>(console.warn("vitrinka: the page recorder did not load — reports go without a replay",g),null));if(d&&this.capturing)Uo(d,"flight",{unmaskSelector:ai}),this.capture.push(Vo)}return o}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}standDown(){if(!this.capturing)return;if(this.capturing=!1,this.config)this.config.capturing=!1;for(let t of this.capture.splice(0).reverse())t();let e=this.store;if(this.store=null,e)oo().then(()=>e.close());for(let t of this.listeners)t()}freeze(){if(!this.capturing)return{clip:null,stored:Promise.resolve(new Map)};w.pathname=globalThis.location?.pathname??w.pathname;let e=nn();if(e&&kt()&&!co(e))Sn(),e=nn();let t=this.store,n=e?.windows.filter((o)=>o.stored).map((o)=>o.id)??[],r=t&&n.length?Promise.all(n.map(async(o)=>[o,await t.read(o)])).then((o)=>new Map(o)):Promise.resolve(new Map);return r.catch(()=>{return}),{clip:e,stored:r}}hiddenIdsAt(e){if(!this.capturing)return null;let t=di(kt());return t?An([e],t):null}async build(e,t,n=new Set){let r=t.filter((f)=>f.shape==="hide").map((f)=>f.rect),o=di(kt()),i=r.length>0&&!o;if(i)console.warn("vitrinka: this page recorder cannot name what a hide covers — the report goes without its replay");let s=new Set(n);if(r.length&&o)for(let f of An(r,o))s.add(f);let a=[],l=e.clip?.truncated??!1,d=await e.stored.catch((f)=>(console.warn("vitrinka: the stored part of the capture could not be read — the replay starts later",f),null));for(let f of e.clip?.windows??[]){if(!f.stored){a.push(...f.events);continue}let R=d?.get(f.id);if(!R?.events.length)l=!0;else a.push(...R.events)}let g=e.clip?.lanes??[],b=i?{events:[],dropped:!1}:Aa(ni(a,r,s),li);if(b.dropped)l=!0;let{parts:c,dropped:p}=hn(b.events,Ea,li),h=[],k=0;for(let f of c){k+=f.count;let R=b.events[k-1]?.timestamp??Date.now();h.push({seq:h.length+1,ts:new Date(R).toISOString(),count:f.count,body:f.body})}let m=g.filter((f)=>f.kind==="console").slice(-ci).map((f)=>({level:K(f.payload?.level,"error"),ts:f.ts,text:K(f.payload?.text)})),y=g.filter((f)=>f.kind==="net").slice(-ci).map((f)=>({method:K(f.payload?.method,"GET"),path:K(f.payload?.path),status:typeof f.payload?.status==="number"?f.payload.status:0,ms:typeof f.payload?.ms==="number"?f.payload.ms:0}));return{chunks:h,truncated:l||p.length>0,console:m,network:y}}clear(){if(this.capturing)ro()}stop(){this.stopped=!0,this.listeners.clear(),this.standDown(),Ir(this.claim),this.claim=null;for(let e of this.offs.splice(0).reverse())e()}}var L=null;function pi(e){if(L){let t=L.engine.opts;if(!(t.base===e.base&&t.key===e.key&&t.sanitizeUrl===e.sanitizeUrl&&JSON.stringify(t.capture??{})===JSON.stringify(e.capture??{})))return console.warn("vitrinka: one capture engine per page — this widget reports without a capture (another widget’s key, base, capture or sanitizeUrl owns it)"),null;return L.refs++,L.engine}return L={engine:new ui(e),refs:1},L.engine}function fi(e){if(!e||!L||L.engine!==e)return;if(--L.refs>0)return;L=null,e.stop()}var La=/^[\w-]+\.[\w-]+\.[\w-]+$/;function Et(e){if(!e)return null;if("token"in e){let r=typeof e.token==="string"?e.token.trim():"";if(r.length>4096||!La.test(r))return console.warn("vitrinka: identify({token}) needs the compact JWS your server signed — reporting anonymously"),null;return{token:r}}let t=typeof e.email==="string"?e.email.trim().slice(0,254):"";if(!t.includes("@"))return console.warn("vitrinka: identify({email}) needs an email address — reporting anonymously"),null;let n=typeof e.name==="string"?e.name.trim().slice(0,200):"";return n?{email:t,name:n}:{email:t}}var hi=null,Pn=new Set;function Da(e){hi=Et(e);for(let t of Pn)t()}function gi(){return hi}function mi(e){return Pn.add(e),()=>Pn.delete(e)}var Na=new Set(["Shift","Control","Alt","Meta","AltGraph","OS","CapsLock","Fn","Hyper","Super"]),Rt="report.keybind";function bi(e){if(Na.has(e.key))return{kind:"wait"};if(e.key==="Escape"&&!e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey)return{kind:"cancel"};if(!e.altKey&&!e.ctrlKey&&!e.metaKey)return{kind:"bare"};return{kind:"bind",bind:{code:e.code,alt:e.altKey,ctrl:e.ctrlKey,meta:e.metaKey,shift:e.shiftKey}}}function yi(e,t){return e.code===t.code&&e.altKey===t.alt&&e.ctrlKey===t.ctrl&&e.metaKey===t.meta&&e.shiftKey===t.shift}var Oa={Space:"Space",Enter:"↵",Backspace:"⌫",Tab:"⇥",ArrowUp:"↑",ArrowDown:"↓",ArrowLeft:"←",ArrowRight:"→",Slash:"/",Backslash:"\\",Period:".",Comma:",",Semicolon:";",Quote:"'",BracketLeft:"[",BracketRight:"]",Minus:"-",Equal:"=",Backquote:"`"};function Ba(e){let t=/^Key([A-Z])$/.exec(e);if(t)return t[1];let n=/^(?:Digit|Numpad)(\d)$/.exec(e);if(n)return n[1];return Oa[e]??e}function Ha(){let e=globalThis.navigator,t=e?.userAgentData?.platform??e?.platform??"";return/mac|iphone|ipad/i.test(t)}function Tt(e,t=Ha()){let n=Ba(e.code);if(t)return`${e.ctrl?"⌃":""}${e.alt?"⌥":""}${e.shift?"⇧":""}${e.meta?"⌘":""}${n}`;return[e.ctrl&&"Ctrl",e.alt&&"Alt",e.shift&&"Shift",e.meta&&"Meta",n].filter(Boolean).join("+")}function ki(e){if(!e)return null;try{let t=JSON.parse(e);if(typeof t!=="object"||t===null)return null;let n=t;if(typeof n.code!=="string"||!n.code)return null;let r={code:n.code,alt:n.alt===!0,ctrl:n.ctrl===!0,meta:n.meta===!0,shift:n.shift===!0};return r.alt||r.ctrl||r.meta?r:null}catch{return null}}function vi(){return ki(z().getString(Rt))}function _n(e){let t=z();if(e)t.set(Rt,JSON.stringify(e));else t.remove(Rt)}function wi(e){let t=z();return t.watch?t.watch(Rt,(n)=>e(ki(n))):()=>{return}}var xi=`
|
|
9
|
+
`)}return s.push(i[i.length-1]),s.join(o)}var wr=262144;function fr(e,t,n){if(e.full||!t)return t;try{if(qt(t)){if(t.length<=wr)try{return JSON.stringify(Je(e,JSON.parse(t),0))}catch{}return de(e,Xi(e,t))}let r=(n??"").toLowerCase();if(r.includes("x-www-form-urlencoded"))return Ge(e,vr(e,W,t));if(r.includes("multipart/form-data")){let o=Gi(e,t,n??"");if(o!==null)return o;return`[multipart body omitted: unparseable (${t.length} chars)]`}return Ge(e,t)}catch{return"[redacted]"}}function xr(e,t){if(t===void 0)return;if(e.full)return t;if(qt(t))try{return JSON.stringify(Je(e,JSON.parse(t),0))}catch{}try{return Ge(e,t)}catch{return"[redacted]"}}function Sr(e,t,n,r){if(e.full)return t.length>n?`${t.slice(0,n)}…[truncated]`:t;if(t.length>n&&r?.toLowerCase().includes("multipart/form-data"))return`[multipart body omitted: oversized (${t.length} chars)]`;if(qt(t)&&t.length<=wr){let i=fr(e,t,r);return i.length>n?`${i.slice(0,n)}…[truncated]`:i}let o=t.length>n?`${t.slice(0,n)}…[truncated]`:t;return fr(e,o,r)}function Er(e,t,n){if(!t)return;let r=n?.maxValueLen??1024,o=n?.budget??8192,i={};for(let[s,a]of Object.entries(t)){let d=(e.full?String(a):mr(e,s)?"[redacted]":de(e,String(a))).slice(0,r);if(o-=s.length+d.length,o<0){i["…"]="(truncated)";break}i[s]=d}return i}function Rr(e){if(e.full)return{maskAllInputs:!1,maskAllText:!1};return{maskAllInputs:!0,maskAllText:e.maskAllText,...e.maskAllText?{maskTextSelector:"*"}:{}}}var w={tabId:"root",tabHost:"/",pathname:"/"};function Tr(){try{let e=globalThis.sessionStorage,t=e.getItem("vitrinka.tab");if(t)return t;let n=Math.random().toString(36).slice(2,10);return e.setItem("vitrinka.tab",n),n}catch{return"root"}}function Mr(e,t){w.tabId=e,w.tabHost=t}var Ae={following:null},Ie="__vitrinkaCaptureOwner";function Cr(e,t){let n=globalThis,r=n[Ie];if(r){if(e==="report")return null;if(r.face==="report")n[Ie]=null,r.yieldTo?.()}let o=`${e}:${Date.now().toString(36)}.${Math.random().toString(36).slice(2,10)}`;return n[Ie]={face:e,token:o,...t?{yieldTo:t}:{}},o}function Ir(e){let t=globalThis;if(e&&t[Ie]?.token===e)t[Ie]=null}var Ji=new Set;function Pe(){for(let e of Ji)e()}async function Ar(e,t){let n=`vitrinka.recorder.${e}`;if(globalThis.navigator?.locks){await navigator.locks.request(n,{signal:AbortSignal.timeout(5000)},t);return}let r=await Zi();await new Promise((o,i)=>{let s=r.transaction("locks","readwrite");s.oncomplete=()=>o(),s.onabort=()=>i(s.error??Error("vitrinka: recorder lock transaction aborted"));let a=s.objectStore("locks").get(n);a.onsuccess=()=>{try{t()}catch(l){i(l),s.abort()}}})}var _e;function Zi(){if(!_e)_e=new Promise((e,t)=>{let n=indexedDB.open("vitrinka.recorder.locks",1);n.onupgradeneeded=()=>n.result.createObjectStore("locks"),n.onerror=()=>t(n.error),n.onsuccess=()=>{let r=n.result;r.onversionchange=()=>{r.close(),_e=void 0},e(r)}}).catch((e)=>{throw _e=void 0,e});return _e}var ee="vitrinka.recorder.",$t=null,Qi=!1;function z(){if(!$t)$t=es()??ts();return Qi=!0,$t}function es(){try{let e=globalThis.localStorage;if(!e)return null;let t=`${ee}probe`;return e.setItem(t,"1"),e.removeItem(t),{getString:(n)=>e.getItem(ee+n),set:(n,r)=>e.setItem(ee+n,r),remove:(n)=>e.removeItem(ee+n),withLock:Ar,keys:()=>Array.from({length:e.length},(n,r)=>e.key(r)).filter((n)=>n!==null&&n.startsWith(ee)).map((n)=>n.slice(ee.length)),watch:(n,r)=>{let o=(i)=>{if(i.storageArea===e&&i.key===ee+n)r(i.newValue)};return globalThis.addEventListener("storage",o),()=>globalThis.removeEventListener("storage",o)}}}catch{return console.warn("vitrinka: localStorage unavailable — the recorder queue will not survive a reload"),null}}function ts(){let e=new Map;return{getString:(t)=>e.get(t)??null,set:(t,n)=>void e.set(t,n),remove:(t)=>void e.delete(t),keys:()=>[...e.keys()]}}var Ze={url:"",key:""};function Qe(){return Ze}var Ft=new Set;function Pr(e){let t=e.replace(/\/+$/,"");return Ft.add(t),()=>Ft.delete(t)}function Kt(e){if(Ze.url!==""&&e.startsWith(Ze.url))return!0;for(let t of Ft)if(t!==""&&e.startsWith(t))return!0;return!1}var ns="link";function rs(){let e=z().getString(ns);if(!e)return null;try{let t=JSON.parse(e);return typeof t.token==="string"&&t.token?t:null}catch{return null}}function _r(){return Ze.key||rs()?.token||""}var ue=Bt(null);function Dr(e){ue=Bt(e??null)}function Nr(e){return xr(ue,e)}function Wt(e,t,n){return Sr(ue,e,t,n)}var Lr=null,Or=null;function zt(e){Or=e??null}function os(e){let t=Or??Qe().sanitizeUrl;if(!t)return e;let n;try{let r=t(e);if(typeof r==="string")return r;n=`returned ${typeof r}`}catch{n="threw"}if(Lr!==t)Lr=t,console.warn(`vitrinka: sanitizeUrl ${n} — such URLs are recorded as their origin only`);return is(e)??hr}function is(e){try{let{origin:t}=new URL(e);return t==="null"?null:t}catch{return null}}function te(e){return Ht(ue,os(e))}var ss=4;function jt(e){return e.type===ss}function Ut(e){if(!jt(e))return e;return{...e,data:{...e.data,href:te(e.data.href)}}}function Le(e){return Er(ue,e)}function Br(){return Rr(ue)}var De="data-vitrinka-recorder";var Vt="all:initial;position:fixed;z-index:2147483647;inset:0 auto auto 0;margin:0;padding:0;border:0;background:transparent;overflow:visible;width:0;height:0;pointer-events:none;color-scheme:normal;",Hr=Vt;var as=["pointerdown","pointerup","pointermove","pointerover","pointerout","pointercancel","mousedown","mouseup","mousemove","mouseover","mouseout","click","dblclick","auxclick","contextmenu","touchstart","touchend","touchmove","touchcancel","wheel","focusin","focusout","keydown","keyup","keypress","paste","dragenter","dragover","dragleave","drop"];function $r(e){for(let t of as)e.addEventListener(t,(n)=>n.stopPropagation())}function Fr(){let e=document.createElement("div");e.setAttribute(De,""),e.setAttribute("data-vitrinka-hud",""),e.style.cssText=Vt;let t=e.attachShadow({mode:"open"}),n=document.createElement("div");t.append(n),$r(e),document.documentElement.append(e);let r=typeof e.showPopover==="function",o=()=>{if(!r||!e.isConnected)return;try{e.hidePopover?.()}catch{}try{e.showPopover?.()}catch{}};if(r)e.popover="manual";o();let i=!1,s=()=>{if(i)return;i=!0,queueMicrotask(()=>{i=!1,o()})},a=(c)=>{if(c.type==="attributes")return c.target instanceof Element&&qr(c.target);for(let p of[c.addedNodes,c.removedNodes])for(let h of p){if(!(h instanceof Element))continue;if(qr(h))return!0;if(h.childElementCount>0&&h.querySelector(Kr))return!0}return!1},l=[],d=0,g=()=>{d=0;let c=l;if(l=[],c.some(a))s()},b=new MutationObserver((c)=>{for(let p of c)l.push(p);if(d===0)d=typeof requestAnimationFrame==="function"?requestAnimationFrame(g):setTimeout(g,16)});return b.observe(document.documentElement,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["open","data-state"]}),{host:e,mount:n,destroy:()=>{if(b.disconnect(),d!==0&&typeof cancelAnimationFrame==="function")cancelAnimationFrame(d);l=[];try{e.hidePopover?.()}catch{}e.remove()}}}var Kr='dialog,[role="dialog"]';function qr(e){return e.matches(Kr)}function Wr(){let e=document.querySelectorAll("dialog[open]"),t=e[e.length-1];if(t)return t;let n=document.querySelectorAll('[role="dialog"][data-state="open"]');return n[n.length-1]??null}function zr(e){let t=document.createElement("div");t.setAttribute(De,""),t.setAttribute("data-vitrinka-sheet",""),t.style.cssText=Hr;let n=t.attachShadow({mode:"open"}),r=document.createElement("div");return n.append(r),$r(t),e.append(t),{mount:r,destroy:()=>t.remove()}}function jr(e){if(!(e instanceof Node))return!1;let t=e instanceof Element?e:e.parentElement;return Boolean(t?.closest("[data-vitrinka-hud],[data-vitrinka-sheet]"))}function N(e,t,n,r={}){let o=e,i=o.__zone_symbol__addEventListener??e.addEventListener,s=o.__zone_symbol__removeEventListener??e.removeEventListener,a=r.capture??!1;return i.call(e,t,n,{capture:a,passive:!1}),()=>s.call(e,t,n,a)}class T extends Error{constructor(e,t){super(e);this.status=t,this.name="VitrinkaApiError"}}function j(e){return e>=400&&e<500&&e!==408&&e!==429}function Ur(e){return e===401}var ls=null;function Vr(e){if(Ur(e))ls?.()}function Yr(e){return e??{url:Qe().url,key:_r()}}async function O(e,t,n,r={}){let{url:o,key:i}=Yr(r.target),s=await fetch(o+t,{method:e,mode:"cors",credentials:"omit",keepalive:r.keepalive??!1,headers:{authorization:`Bearer ${i}`,...n!==void 0?{"content-type":"application/json"}:{}},body:n===void 0?void 0:JSON.stringify(n)}),a=await s.text();if(!s.ok){if(!r.target)Vr(s.status);throw new T(`${e} ${t} → ${s.status}: ${a}`,s.status)}return a?JSON.parse(a):{}}function Xr(e,t,n){return Jr(e,"chunk",t,"application/json",n)}function Gr(e,t,n){return Jr(e,"shot",t,n.type,n)}function Jr(e,t,n,r,o){return Yt(`/api/v1/sessions/${e}/${t}?seq=${n}`,r,o)}async function Yt(e,t,n,r){let{url:o,key:i}=Yr(r),s=await fetch(o+e,{method:"POST",mode:"cors",credentials:"omit",headers:{authorization:`Bearer ${i}`,"content-type":t},body:n}),a=await s.text();if(!s.ok){if(!r)Vr(s.status);throw new T(`POST ${e} → ${s.status}: ${a}`,s.status)}try{return JSON.parse(a)}catch{return{}}}var Zr=30000,cs=4194304,ds=20000,Jt=500,us=2000,ps=2,Qr={windowMs:Zr,checkoutMs:Zr,maxBytes:cs,maxEvents:ds,maxLaneEvents:Jt},V=`${Date.now().toString(36)}.${Math.random().toString(36).slice(2,8)}`;function Zt(e,t){return t&&t.load===e.load?t.startMs:e.lastMs}var fs=new TextEncoder,X=!1,eo=0,E=Qr,v=[],M=[],B=[],U=[],hs=0,fe=[],he=new Map,ge=null,pe=null,Ne=!1,gs=0,Y=null,et=null,Gt=Promise.resolve();function to(e=Qr){if(en(),X=!0,eo++,E=e,Y=e.store??null,v=(e.prior??[]).filter((t)=>t.kind!=="lanes").map((t)=>({id:t.id,load:t.load,startMs:t.startMs,lastMs:t.lastMs,events:[],count:t.count,bytes:t.bytes,href:t.href,route:t.route,stored:!0})),M=(e.priorLanes??[]).slice(-e.maxLaneEvents),B=[],U=[],fe=(e.prior??[]).filter((t)=>t.kind==="lanes").map((t)=>({id:t.id,lastMs:t.lastMs})),he.clear(),ge=null,nt(Date.now()),Y)et=setInterval(tt,us)}function no(){tt(),en(),X=!1,Y=null,v=[],M=[],B=[],U=[],fe=[],he.clear(),ge=null}function ro(){return E}function Qt(e){pe=e}function oo(){if(!X)return;v=[],M=[],B=[],U=[],fe=[],he.clear(),ge=null;let e=w.tabId;ne((t)=>t.clear(e)),pe?.()}function io(){return Gt}function tt(){if(!X||!Y)return;let e=Date.now();nt(e),tn(e);for(let t of v){if(t.stored)continue;let n=he.get(t.id)??{events:0,parts:0};if(n.events===t.events.length)continue;let r=JSON.stringify(t.events.slice(n.events)),o=n.parts;he.set(t.id,{events:t.events.length,parts:o+1});let i=so(t);ne((s)=>s.putWindowChunk(i,o,r,[]))}ms(e)}function ms(e){let t=e-E.windowMs;while(U.length>0&&U[0].lastMs<=t){let[a]=U.splice(0,1);if(a)ne((l)=>l.dropWindow(a.id))}for(let a of fe.filter((l)=>l.lastMs<=t))ne((l)=>l.dropWindow(a.id));fe=fe.filter((a)=>a.lastMs>t);let n=B;if(!n.length)return;B=[];let r=U.at(-1);if(!r||r.startMs<=t)r={id:`${V}.lanes.${++hs}`,startMs:Date.parse(n[0].ts),lastMs:0,parts:0},U.push(r);r.lastMs=Date.parse(n.at(-1).ts);let o=r.parts++,i=r,s={id:i.id,tab:w.tabId,scope:E.scope??"",kind:"lanes",load:V,startMs:i.startMs,lastMs:i.lastMs,count:0,bytes:0,href:"",route:""};ne((a)=>a.putWindowChunk(s,o,"[]",n))}function en(){if(et)clearInterval(et);et=null}function so(e){return{id:e.id,tab:w.tabId,scope:E.scope??"",load:e.load,startMs:e.startMs,lastMs:e.lastMs,count:e.count,bytes:e.bytes,href:e.href,route:e.route}}function ne(e){let t=Y;if(!t)return;Gt=Gt.then(()=>e(t)).catch((n)=>{if(Y!==t)return;Y=null,en(),console.warn("vitrinka: browser capture storage failed — the capture stays in memory for this page",n)})}function Xt(e){let[t]=v.splice(e,1);if(!t)return;he.delete(t.id),ne((n)=>n.dropWindow(t.id))}function nt(e){while(v.length>0){let r=v[0],o=v[1];if(!o&&r.load===V)break;if(Zt(r,o)>e-E.windowMs)break;Xt(0)}if(Ne)return;let t=v.at(-1);if(t&&t.load===V&&pe&&t.lastMs<=e-E.windowMs){Ne=!0;try{pe()}finally{Ne=!1}let r=v.indexOf(t);if(r>=0&&r<v.length-1)for(let o=r;o>=0;o--)Xt(o)}let n=!1;while(v.length>0&&bs()){if(v.length===1&&v[0].load===V&&!n&&pe){n=!0,Ne=!0;try{pe()}finally{Ne=!1}if(v.length>1)continue}Xt(0),ge=v[0]?.startMs??e}}function ao(){return X?`flight:${eo}`:null}function tn(e){let t=Math.min(v[0]?.startMs??Number.POSITIVE_INFINITY,e-E.windowMs),n=M.findIndex((r)=>Date.parse(r.ts)>=t);if(n===-1)M=[];else if(n>0)M=M.slice(n)}function bs(){let e=0,t=0;for(let n of v)e+=n.bytes,t+=n.count;return e>E.maxBytes||t>E.maxEvents}function lo(e){if(!X)return;let t=v[0];if(jt(e)){let r=globalThis.location?.pathname??w.pathname,o={id:`${V}.${++gs}`,load:V,startMs:e.timestamp,lastMs:e.timestamp,events:[],count:0,bytes:0,href:e.data.href,route:te(r)};v.push(o);let i=so(o);ne((s)=>s.putWindow(i))}let n=v.at(-1);if(!n||n.load!==V)return;if(n.events.push(e),n.count++,n.lastMs=Math.max(n.lastMs,e.timestamp),n.bytes+=fs.encode(JSON.stringify(e)).length,nt(e.timestamp),v[0]!==t)tn(e.timestamp)}function co(e,t,n){if(!X)return null;let r=E.keepLane?E.keepLane(e,t):t;if(r===null)return null;let o=new Date().toISOString(),i={ts:o,tabId:n.tabId,tabHost:n.tabHost,kind:e,payload:r},s=E.maxLaneEvents;if(M.push(i),M.length>s)M.splice(0,M.length-s);if(Y){if(B.push(i),B.length>s)B.splice(0,B.length-s)}return o}function nn(){if(!X)return null;let e=Date.now();return nt(e),tn(e),{windows:v.map((t)=>({...t,events:t.events.slice()})),lanes:M.slice(),truncated:ge!==null&&ge>e-E.windowMs}}function uo(e){return e.windows.some((t)=>t.events[1]?.type===ps)}var rn=null;function rt(){if(!rn)rn=typeof indexedDB>"u"?ys():ks();return rn}function ys(){let e=new Map;return{durable:!1,put:async(t,n)=>void e.set(t,n),get:async(t)=>e.get(t)??null,delete:async(t)=>void e.delete(t),keys:async()=>[...e.keys()]}}function ks(){let e,t=()=>(e??=new Promise((r,o)=>{let i=indexedDB.open("vitrinka.recorder.blobs",1);i.onupgradeneeded=()=>i.result.createObjectStore("blobs"),i.onerror=()=>o(i.error??Error("vitrinka: blob journal did not open")),i.onsuccess=()=>{let s=i.result;s.onversionchange=()=>{s.close(),e=void 0},s.onclose=()=>{e=void 0},r(s)}}).catch((r)=>{throw e=void 0,r}),e),n=async(r,o)=>{let i=t(),s;try{s=(await i).transaction("blobs",r)}catch(l){if(e===i)e=void 0;throw l}let a=o(s.objectStore("blobs"));return new Promise((l,d)=>{s.oncomplete=()=>l(a.result),s.onabort=s.onerror=()=>d(s.error??a.error??Error("vitrinka: blob journal transaction failed"))})};return{durable:!0,put:async(r,o)=>void await n("readwrite",(i)=>i.put(o,r)),get:async(r)=>{let o=await n("readonly",(i)=>i.get(r));return o instanceof Blob?o:null},delete:async(r)=>void await n("readwrite",(o)=>o.delete(r)),keys:async()=>(await n("readonly",(r)=>r.getAllKeys())).filter((r)=>typeof r==="string")}}var vs=2000,ln=20000,wo=200,ws=4194304,xs=3145728,pt=500,Ss=ws-1024,Es=12582912,Rs=10485760,Ts=Es-64,Ms=1048576,Cs=new TextEncoder;function Re(e){return Cs.encode(e).length}var x=()=>z();function q(e,t){let n=x().getString(e);if(!n)return t;try{return JSON.parse(n)}catch{return t}}var po=!1;function F(e,t){try{return x().set(e,t),!0}catch(n){if(!po)po=!0,console.warn("vitrinka: storage write failed — the queue tail is memory-only until it clears",n);return!1}}var st="rec",ie;function S(){if(ie===void 0)ie=q(st,null);return ie}function xo(e){if(ie=e,e===null)x().remove(st),x().remove(Is);else F(st,JSON.stringify(As(e)))}var Is="notes";var Be=null;function As(e){if(Be?.sessionId!==e.sessionId)return e;return{...e,paused:!0,activeMs:Be.activeMs,resumeAt:null,stopping:Be.at}}var Ps=new Set;function _s(){for(let e of Ps)try{e()}catch(t){console.warn("vitrinka: before-stop hook failed",t)}}function Ls(e){let t=null;if(e)try{t=JSON.parse(e)}catch{return"unchanged"}let n=S();if(t?.stopping&&t.sessionId===n?.sessionId&&!n.paused&&Be?.sessionId!==t.sessionId)_s();if(!t){if(!n)return"unchanged";return ie=null,vo(),js(),"ended"}if(n?.sessionId===t.sessionId){if(t.seq=Math.max(t.seq,n.seq),t.policy===void 0&&n.policy!==void 0)t.policy=n.policy;if(t.attachments===void 0&&n.attachments!==void 0)t.attachments=n.attachments;if(Be?.sessionId===t.sessionId)t.paused=n.paused,t.activeMs=n.activeMs,t.resumeAt=n.resumeAt,delete t.stopping;return ie=t,"updated"}return ie=t,vo(),"joined"}var Ds=700,se,H=null,Z=!1;function be(){if(se===void 0)se=q("buffer",[]);return se}function ft(){if(H)clearTimeout(H),H=null;if(se!==void 0&&!Z)F("buffer",JSON.stringify(se))}function So(){if(Z=!1,H)return;H=setTimeout(()=>{H=null,ft(),Eo()},Ds)}function fo(e){se=e,Z=!1,ft()}var me,ke=0;function re(){if(me===void 0)me=q("chunks",[]),ke=me.reduce((e,t)=>e+t.body.length,0);return me}function Eo(){if(Z)return;let e=re();if(e.length===0){x().remove("chunks");return}if(ke>Ms){x().remove("chunks");return}F("chunks",JSON.stringify(e))}function Ns(e){me=e,ke=e.reduce((t,n)=>t+n.body.length,0),Z=!1,Eo()}var at,ve=new Map,ye=new Set,we=new Map,ot=new Map,ho=5,Os=200,Bs=67108864,Hs=0,go=!1,qs="blobs";function C(){return at??=q("images",[]),at}function Ro(){if(Z)return;let e=C().filter((t)=>!ye.has(t.blob));if(e.length===0)x().remove("images");else F("images",JSON.stringify(e))}function To(e){at=e,Z=!1,Ro()}function $s(e,t){let n=rt();if(!n.durable&&!go)go=!0,console.warn("vitrinka: no IndexedDB — an attached image will not survive a reload");F(qs,"1");let r=[];return{drafts:t.map(({blob:i,payload:s})=>{let a=`${e}/${Ao}.${++Hs}`;return ve.set(a,i),ye.add(a),r.push(n.put(a,i).then(()=>{if(!(ve.has(a)||C().some((d)=>d.blob===a)||[...we.values()].includes(a)))return ye.delete(a),cn(a),!1;if(!n.durable)return!1;if(ye.delete(a),C().some((d)=>d.blob===a))Ro();return!0},(l)=>(console.warn("vitrinka: an attached image could not be journaled — it will not survive a reload",l),!1))),{blob:a,payload:s}}),journaled:Promise.all(r).then((i)=>i.every(Boolean))}}function cn(e){rt().delete(e).catch((t)=>console.warn("vitrinka: blob journal delete failed",t))}function xe(e,t){for(let n of e)if(ve.delete(n),ye.delete(n),ot.delete(n),t)cn(n)}var lt=(e)=>e.kind==="event"?(e.images??[]).map((t)=>t.blob):[];var Fs=0,Mo="",Co=0,mo=-1;function dn(){Fs=Date.now(),Co=0,Mo=""}function Se(e){Co++,Mo=String(e instanceof Error?e.message:e).slice(0,200)}var bo={actions:0,pages:0,frames:0,notes:0},Ks=new Set;function Ws(e){let t={...bo};for(let n of e)if(n.kind==="click")t.actions++;else if(n.kind==="nav")t.pages++;else if(n.kind==="rrweb")t.frames+=typeof n.payload?.count==="number"?n.payload.count:1;else if(n.kind==="note"){if(t.notes++,typeof n.payload?.cid==="string")Ks.add(n.payload.cid)}bo=t}function zs(e){let t=S();if(!t||t.dead)return;if(t.dead=!0,t.deadReason=e,!t.paused&&t.resumeAt)t.activeMs=(t.activeMs||0)+(Date.now()-Date.parse(t.resumeAt)),t.resumeAt=null;xo(t),console.warn("vitrinka: session marked dead —",e),Pe()}var on=null;function js(){if(on)clearInterval(on);on=null}function Io(e){let t=S();if(!t||t.dead||e<1)return null;let n=q("seq",null),r=Math.max(t.seq,n?.sessionId===t.sessionId?n.seq:0)+1;return x().set("seq",JSON.stringify({sessionId:t.sessionId,seq:r+e-1})),t.seq=r+e-1,xo(t),{seq:r,sessionId:t.sessionId}}var Ao=`${Date.now().toString(36)}.${Math.random().toString(36).slice(2)}`,ct="allocation.",Us=0,I=new Set,Vs=16777216,dt=0,ut=0,Ee=new Map;function ht(e){return e.kind==="event"?1+(e.images?.length??0):1}function Ys(e,t){return new Set(Array.from({length:ht(t)},(n,r)=>e+r))}function un(e,t,n){return JSON.stringify(n&&n.size<ht(e)?{draft:e,seq:t,left:[...n]}:{draft:e,seq:t})}var yo=!1,Oe=null;function it(e){if(!I.delete(e))return;if(dt-=e.bytes,e.draft.kind==="chunk")ut--}function Po(e){if(I.add(e),dt+=e.bytes,e.draft.kind==="chunk")ut++;while(I.size>ln||dt>Vs||ut>wo){let t=I.values().next().value;it(t),x().remove(t.key),xe(lt(t.draft),!0);let n=Error("vitrinka: pending allocation budget full — oldest capture dropped");Se(n),console.warn(n.message)}}function _o(e=!1){if(yo&&!e)return;yo=!0;let t=x();if(!t.withLock)return;let n=new Set([...I].map((r)=>r.key));for(let r of t.keys?.()??[]){if(!r.startsWith(ct)||n.has(r)||Ee.has(r))continue;let o=q(r,null);if(o&&o.draft&&o.draft.sessionId===S()?.sessionId)Po({...o,key:r,persisted:!0,bytes:Re(JSON.stringify(o))})}}function Lo(e,t,n){let{ts:r,tabId:o,tabHost:i,sessionId:s}=e,a=(l)=>!n||n.has(l);if(e.kind==="event"){let l=e.images??[],d=t+l.length,g=l.length?{...e.event,payload:{...e.event.payload,attachments:l.map((c,p)=>t+p)}}:e.event,b=be();if(a(d)&&!b.some((c)=>c.seq===d))b.push({seq:d,ts:r,tabId:o,tabHost:i,...g});if(l.length){let c=C();l.forEach((h,k)=>{let m=t+k;if(!a(m)||c.some((y)=>y.seq===m))return;if(b.some((y)=>y.seq===m)){we.set(m,h.blob);return}c.push({seq:m,ts:r,tabId:o,tabHost:i,sessionId:s,blob:h.blob,payload:h.payload})});let p=c.reduce((h,k)=>h+k.payload.bytes,0);while(c.length>Os||p>Bs){let h=c.shift();p-=h.payload.bytes,J(h.sessionId,new Set([h.seq])),xe([h.blob],!0),console.warn(`vitrinka: attached image queue full — dropped ${h.payload.name} (seq ${h.seq}); its note lands without it`)}To(c)}if(b.length>ln){let c=b.splice(0,b.length-ln);J(s,new Set(c.map((p)=>p.seq))),console.warn(`vitrinka: retry buffer full — dropped ${c.length} oldest events`)}}else{let l=re();if(!l.some((d)=>d.seq===t)&&!be().some((d)=>d.seq===t))l.push({seq:t,ts:r,tabId:o,tabHost:i,sessionId:s,...e.part}),ke+=e.part.body.length;while(l.length>wo){let d=l.shift();ke-=d.body.length,J(s,new Set([d.seq])),console.warn(`vitrinka: pending chunk queue full — dropped rrweb chunk seq ${d.seq}`)}}So(),oe()}function J(e,t){for(let[n,r]of Ee){if(r.sessionId!==e)continue;let o=r.seqs.size;for(let s of r.seqs)if(t.has(s))r.seqs.delete(s);let i=r.seqs.size&&r.seqs.size<o&&r.persisted?q(n,null):null;if(i){let s=new Set([...r.seqs].filter((a)=>!i.left||i.left.includes(a)));if(s.size)F(n,un(i.draft,i.seq,s));else r.seqs.clear()}if(r.seqs.size===0){x().remove(n),Ee.delete(n);let s=n.slice(ct.length,n.lastIndexOf(".")),a=`tab.${s}`,l=q(a,null);if(l?.departed&&l.recoverable&&!x().keys?.().some((d)=>d.startsWith(`${ct}${s}.`)))x().remove(a)}}}function Do(){if(Oe)return Oe;let e=x();return Oe=pn(Promise.resolve().then(async()=>{for(let t of I)await e.withLock("seq",()=>{if(!I.has(t))return;if(t.persisted){let o=q(t.key,null);if(!o){it(t),xe(lt(t.draft),!1);return}t.seq=o.seq,t.left=o.left}if(Ls(e.getString(st)??null),S()?.sessionId!==t.draft.sessionId){it(t),xe(lt(t.draft),!0);return}let n=t.seq??Io(ht(t.draft))?.seq;if(n===void 0)return;t.seq=n;let r=t.left?new Set(t.left):Ys(n,t.draft);if(t.persisted)e.set(t.key,un(t.draft,n,r));Ee.set(t.key,{sessionId:t.draft.sessionId,seqs:r,persisted:t.persisted}),Lo(t.draft,n,r),it(t)})}).catch((t)=>{throw Se(t),console.warn("vitrinka: seq allocation failed — capture kept for retry",t),oe(),Pe(),t})).finally(()=>{Oe=null}),Oe}function No(e,t){let n=S(),r=e.kind==="event"&&e.event.kind==="note";if(!n||n.dead||n.paused&&!r)return!1;if(_o(),x().withLock){let o=`${ct}${Ao}.${++Us}`,i=JSON.stringify({draft:e}),s={key:o,draft:e,persisted:!t&&F(o,i),bytes:Re(i)};Po(s),Do(),t?.then((a)=>{if(a)Xs(s)})}else{let o=Io(ht(e));if(o)Lo(e,o.seq);else xe(lt(e),!0)}return!0}function Xs(e){let t=Ee.get(e.key);if(t)t.persisted=F(e.key,un(e.draft,e.seq,t.seqs));else if(I.has(e))e.persisted=F(e.key,JSON.stringify({draft:e.draft}))}var ko=new Set;function pn(e){return ko.add(e),e.catch(()=>{return}).finally(()=>{ko.delete(e)})}function G(e){return S()?.sessionId!==e.sessionId}function He(e,t,n,r=[]){if(Ae.following)return null;let o=S();if(!o)return co(e,t,n);if(o.dead||o.paused&&e!=="note")return null;let i=new Date().toISOString(),{tabId:s,tabHost:a}=n,l=r.length?$s(o.sessionId,r):null;return No({sessionId:o.sessionId,ts:i,tabId:s,tabHost:a,kind:"event",event:{kind:e,payload:t},...l?{images:l.drafts}:{}},l?.journaled),fn(),i}function Oo(e){be().push(e),fn(),So(),oe()}var Gs=Date.now();function fn(){Gs=Date.now()}function hn(e,t=Rs,n=Ts){let r=[],o=[],i=[],s=2,a=()=>{if(!i.length)return;r.push({count:i.length,body:`[${i.join(",")}]`}),i=[],s=2};for(let l of e){let d=JSON.stringify(l),g=Re(d)+1;if(g>n){o.push(g);continue}if(g>t){a(),r.push({count:1,body:`[${d}]`});continue}if(i.length&&s+g>t)a();i.push(d),s+=g}return a(),{parts:r,dropped:o}}function Bo(e,t){if(!e.length)return 0;let n=S();if(!n||n.paused||n.dead||Ae.following)return 0;let{parts:r,dropped:o}=hn(e);for(let l of o)console.warn(`vitrinka: rrweb event (${l} bytes) exceeds the chunk cap — dropped`),He("note",{text:`⚠ rrweb event dropped (${(l/1048576).toFixed(1)} MiB > chunk cap) — replay may be incomplete from here`},t);let i=new Date().toISOString(),{tabId:s,tabHost:a}=t;for(let l of r)if(!No({sessionId:n.sessionId,ts:i,tabId:s,tabHost:a,kind:"chunk",part:l}))return 0;return fn(),r.length}async function Js(e=5){let t=re();if(t.length===0)return!0;let n=S(),r=0,o=new Set;for(let i of t){if(r>=e)break;if(r++,!n||i.sessionId!==n.sessionId){console.warn(`vitrinka: dropping rrweb chunk seq ${i.seq} from ended session ${i.sessionId}`),o.add(i.seq);continue}try{let s=await Xr(n.sessionId,i.seq,i.body);if(G(n))return re().length===0;Oo({seq:i.seq,ts:i.ts,tabId:i.tabId,tabHost:i.tabHost,kind:"rrweb",payload:{count:i.count},blobKey:s.blobKey}),dn(),o.add(i.seq)}catch(s){if(G(n))return re().length===0;if(s instanceof T&&j(s.status)){console.warn(`vitrinka: rrweb chunk seq ${i.seq} rejected permanently (${s.status}) — dropped`),J(i.sessionId,new Set([i.seq])),o.add(i.seq);continue}Se(s),console.warn("vitrinka: chunk upload failed",s);break}}if(o.size)Ns(re().filter((i)=>!o.has(i.seq)));return re().length===0}async function Zs(e=4){let t=C();if(t.length===0)return!0;let n=S(),r=0,o=new Set,i=[];for(let s of t){if(r>=e)break;if(r++,!n||s.sessionId!==n.sessionId){console.warn(`vitrinka: dropping attachment seq ${s.seq} from ended session ${s.sessionId}`),o.add(s.seq),i.push(s.blob);continue}let a=ve.get(s.blob)??null;if(!a){try{a=await rt().get(s.blob),ot.delete(s.blob)}catch(l){if(G(n))return C().length===0;let d=(ot.get(s.blob)??0)+1;if(console.warn(`vitrinka: blob journal read failed (${d}/${ho})`,l),d<ho){ot.set(s.blob,d),Se(l);break}}if(G(n))return C().length===0}if(!a){console.warn(`vitrinka: attachment seq ${s.seq} (${s.payload.name}) lost its bytes — its note lands without it`),J(s.sessionId,new Set([s.seq])),o.add(s.seq),i.push(s.blob);continue}try{let l=await Gr(n.sessionId,s.seq,a);if(G(n))return C().length===0;Oo({seq:s.seq,ts:s.ts,tabId:s.tabId,tabHost:s.tabHost,kind:"attachment",payload:{...s.payload},blobKey:l.blobKey}),ve.delete(s.blob),we.set(s.seq,s.blob),dn(),o.add(s.seq)}catch(l){if(G(n))return C().length===0;if(l instanceof T&&j(l.status)){console.warn(`vitrinka: attachment seq ${s.seq} rejected permanently (${l.status}) — dropped`),J(s.sessionId,new Set([s.seq])),o.add(s.seq),i.push(s.blob);continue}Se(l),console.warn("vitrinka: attachment upload failed",l);break}}if(o.size)ft(),To(C().filter((s)=>!o.has(s.seq)));return xe(i,!0),C().length===0}var sn=null;function oe(){if(sn)return;sn=setTimeout(()=>{sn=null,Qs()},vs)}var an=!1;async function Qs(e={}){if(an)return!1;an=!0;try{return await ea(e)}finally{an=!1}}async function ea(e){if(S()?.dead)return!1;if(_o(!0),I.size)await Do();if(I.size)return!1;let t=await Js(),n=e.keepalive?C().length===0:await Zs(),r=t&&n;if(!r)oe();let o=S(),i=be();if(!o||i.length===0)return r;let s=[],a=new Set,l=0,d=e.keepalive?61440:xs;for(let c of i){if(s.length>=pt)break;let p=Re(JSON.stringify(c))+1;if(p>Ss){console.warn(`vitrinka: event seq ${c.seq} (${p} bytes) exceeds the wire cap — dropped`),a.add(c.seq);continue}if(p>d){if(e.keepalive)break;if(s.length===0)s.push(c),l=p;break}if(s.length>0&&l+p>d)break;s.push(c),l+=p}if(a.size){if(J(o.sessionId,a),fo(be().filter((c)=>!a.has(c.seq))),!s.length)return oe(),!1}if(!s.length)return!1;ft();try{await O("POST",`/api/v1/sessions/${o.sessionId}/events`,{events:s},e)}catch(c){if(G(o))return!1;if(c instanceof T&&j(c.status))return zs(`server rejected this session (${c.status})`),!1;return Se(c),Pe(),console.warn("vitrinka: flush failed, retrying",c),oe(),!1}if(G(o))return!0;dn(),mo=Math.max(mo,...s.map((c)=>c.seq)),Ws(s);let g=new Set(s.map((c)=>c.seq));J(o.sessionId,g);let b=be().filter((c)=>!g.has(c.seq));fo(b),Pe();for(let c of g){let p=we.get(c);if(p===void 0)continue;we.delete(c),cn(p)}if(b.length)oe();return!0}function vo(){if(H)clearTimeout(H),H=null;se=[],me=[],ke=0,at=[],ve.clear(),ye.clear(),we.clear(),I.clear(),dt=ut=0,Ee.clear(),Z=!0}var ta=8192,qe="__vitrinkaRecorderConsolePatched";function gt(e){return e.map((t)=>{if(typeof t==="string")return t;if(t instanceof Error)return t.stack??t.message;try{return JSON.stringify(t)}catch{return String(t)}}).join(" ").slice(0,ta)}function mt(e,t="error"){if(!e||e.startsWith("vitrinka:"))return;He("console",{level:t,text:Nr(e)},{tabId:w.tabId,tabHost:w.tabHost})}var gn="__vitrinkaRecorderConsoleUnpatch",Ho={};function qo(){let e=globalThis;if(e[qe]!==void 0&&e[qe]!==Ho)return;e[gn]?.()}function $o(e={}){let t=globalThis;if(t[qe])return;t[qe]=Ho;let n=console.error,r=n.bind(console),o=(...d)=>{r(...d);try{mt(gt(d))}catch{}};console.error=o;let i=(e.levels??[]).map((d)=>{let g=console[d],b=g.bind(console),c=(...p)=>{b(...p);try{mt(gt(p),d)}catch{}};return console[d]=c,()=>{if(console[d]===c)console[d]=g}}),s=(d)=>{try{mt(gt([d.error??d.message]))}catch{}},a=(d)=>{try{mt(`unhandled rejection: ${gt([d.reason])}`)}catch{}},l=typeof addEventListener==="function";if(l)addEventListener("error",s),addEventListener("unhandledrejection",a);t[gn]=()=>{if(console.error===o)console.error=n;for(let d of i)d();if(l)removeEventListener("error",s),removeEventListener("unhandledrejection",a);delete t[qe],delete t[gn]}}var Fo=65536,$e=524288,Ko=3000;var mn="full";function yn(){if(Ae.following)return null;let e=S();if(e)return!e.paused&&!e.dead?e.sessionId:null;return ao()}function Fe(e){return e!==null&&yn()===e}function bt(e,t){if(typeof e==="string")return Wt(e,Fo,t);if(typeof URLSearchParams<"u"&&e instanceof URLSearchParams)return Wt(e.toString(),Fo,"application/x-www-form-urlencoded");return na(e)}function na(e){if(e==null)return;if(typeof FormData<"u"&&e instanceof FormData){let t=0;try{e.forEach(()=>t++)}catch{}return`[formdata body omitted: ${t} field(s)]`}if(typeof Blob<"u"&&e instanceof Blob)return`[blob body omitted: ${e.size} bytes${e.type?`, ${e.type}`:""}]`;if(e instanceof ArrayBuffer)return`[buffer body omitted: ${e.byteLength} bytes]`;if(ArrayBuffer.isView(e))return`[buffer body omitted: ${e.byteLength} bytes]`;if(typeof ReadableStream<"u"&&e instanceof ReadableStream)return"[stream body omitted]";return`[${typeof e} body omitted]`}function bn(e){for(let[t,n]of Object.entries(e??{}))if(t.toLowerCase().replace(/[-_]/g,"")==="contenttype")return n;return""}function kn(e){return typeof e==="string"||e instanceof URL?{}:e}function Ke(e){let t=typeof e.url==="string"?te(e.url):e.url;He("net",{...e,url:t},{tabId:w.tabId,tabHost:w.tabHost})}function vn(e){if(!e)return;try{let t={},n=e;if(typeof n.forEach==="function")if(Array.isArray(e)){for(let r of e)if(Array.isArray(r)&&r.length>=2)t[String(r[0])]=String(r[1])}else n.forEach((r,o)=>{t[o]=String(r)});else if(typeof e==="object")for(let[r,o]of Object.entries(e))t[r]=String(o);return Object.keys(t).length>0?t:void 0}catch{return}}function ra(e,t){let n=vn(t?.headers);if(n)return n;let r=kn(e);return vn(r.headers)}function oa(e){if(!e)return;let t={};for(let n of e.split(/\r?\n/)){let r=n.indexOf(":");if(r>0)t[n.slice(0,r).trim()]=n.slice(r+1).trim()}return Object.keys(t).length>0?t:void 0}function wn(e){try{e.body?.cancel?.().catch(()=>{return})}catch{}}function ia(e){let t=e.get("content-length");if(!t)return null;let n=Number(t);return Number.isFinite(n)?n:null}async function sa(e,t){let n=await aa(e,t);if(n===void 0)return;let r="";try{r=t.get("content-type")??""}catch{}return bt(n,r)}async function aa(e,t){let n=ia(t);if(n!==null&&n>$e)return wn(e),`[body omitted: ${n} bytes]`;let r=e.body;if(r?.getReader){let o=r.getReader(),i=[],s=0,a=!1,l=!1,d=Date.now()+Ko;try{while(s<$e){let p=d-Date.now();if(p<=0){l=!0;break}let h,k=await Promise.race([o.read(),new Promise((f)=>{h=setTimeout(()=>f("timeout"),p)})]).finally(()=>{if(h!==void 0)clearTimeout(h)});if(k==="timeout"){l=!0;break}let{done:m,value:y}=k;if(m)break;if(y){let f=$e-s,R=y.byteLength>f?y.subarray(0,f):y;i.push(R),s+=R.byteLength}}a=s>=$e,o.cancel().catch(()=>{return})}catch{return}let g=new Uint8Array(s),b=0;for(let p of i)g.set(p,b),b+=p.byteLength;let c;try{c=new TextDecoder().decode(g)}catch{return`[body omitted: ${s} bytes, undecodable]`}if(l)return`${c}…[body read timed out after ${Ko}ms]`;return a?`${c}…[truncated at ${$e} bytes]`:c}if(n===null)return wn(e),"[body omitted: length-less response, no stream API]";try{return await e.text()}catch{return}}var We="__vitrinkaRecorderNetPatched",xn="__vitrinkaRecorderNetUnpatch",Wo={};function zo(){let e=globalThis;if(e[We]!==void 0&&e[We]!==Wo)return;e[xn]?.()}function jo(e={}){let t=globalThis;if(t[We])return;t[We]=Wo,mn=e.detail??"full";let n=[];t[xn]=()=>{for(let c of n.splice(0))c();delete t[We],delete t[xn]};let r=globalThis.fetch,o=async(c,p)=>{let h=typeof c==="string"?c:c instanceof URL?c.href:c.url,k=yn();if(Kt(h)||k===null)return r(c,p);let m=p?.method??("method"in kn(c)?kn(c).method:"GET"),y=Date.now();try{let f=await r(c,p),R=Date.now()-y;if(mn==="meta"){if(Fe(k))Ke({method:m,url:h,status:f.status,ms:R,via:"fetch"});return f}let D;try{D=f.clone()}catch{D=void 0}let{headers:Te,status:Ve}=f;return pn((async()=>{if(!Fe(k)){if(D)wn(D);return}let Ye=D?await sa(D,Te):void 0;if(!Fe(k))return;let Me=ra(c,p);Ke({method:m,url:h,status:Ve,ms:R,reqHeaders:Le(Me),resHeaders:Le(vn(Te)),reqBody:bt(p?.body,bn(Me)),resBody:Ye,via:"fetch"})})()),f}catch(f){if(Fe(k))Ke({method:m,url:h,error:String(f),ms:Date.now()-y,via:"fetch"});throw f}};globalThis.fetch=o,n.push(()=>{if(globalThis.fetch===o)globalThis.fetch=r});let i=globalThis.XMLHttpRequest;if(!i?.prototype)return;let s=i.prototype.open,a=i.prototype.send,l=i.prototype.setRequestHeader;n.push(()=>{let c=i.prototype;if(c.open===d)c.open=s;if(c.send===b)c.send=a;if(c.setRequestHeader===g)c.setRequestHeader=l});let d=i.prototype.open=function(...c){return this.__vt={method:c[0],url:String(c[1])},s.apply(this,c)},g=i.prototype.setRequestHeader=function(c,p){let h=this.__vt;if(h)(h.reqHeaders??={})[c]=p;return l?.call(this,c,p)},b=i.prototype.send=function(c){let p=this.__vt,h=yn();if(p&&!Kt(p.url)&&h!==null){let k=Date.now();this.addEventListener("loadend",()=>{if(!Fe(h))return;if(mn==="meta"){Ke({method:p.method,url:p.url,status:this.status,ms:Date.now()-k,via:"xhr"});return}let m;try{m=oa(this.getAllResponseHeaders())}catch{m=void 0}let y;try{y=this.responseType===""||this.responseType==="text"?bt(this.responseText,bn(m)):void 0}catch{y=void 0}Ke({method:p.method,url:p.url,status:this.status,ms:Date.now()-k,reqHeaders:Le(p.reqHeaders),resHeaders:Le(m),reqBody:bt(c,bn(p.reqHeaders)),resBody:y,via:"xhr"})})}return a.call(this,c)}}var la=2000,ca=300000,je=null,Ue=null,ze=[],yt=null;function Uo(){if(!ze.length)return;let e=ze;ze=[],Bo(e,{tabId:w.tabId,tabHost:w.tabHost})}function kt(){return Ue}function Vo(e,t,n={}){if(je)return;let r=Br(),o=n.unmaskSelector;try{je=e({emit:t==="flight"?(s)=>lo(Ut(s)):(s)=>{ze.push(Ut(s))},checkoutEveryNms:t==="flight"?ro().checkoutMs:ca,inlineImages:!1,collectFonts:!0,maskAllInputs:r.maskAllInputs,...r.maskTextSelector?{maskTextSelector:r.maskTextSelector}:{},...r.maskTextSelector&&o?{maskTextFn:(s,a)=>{try{if(a?.closest(o))return s}catch{}return s.replace(/\S/g,"*")}}:{},blockSelector:`[${De}]`})??null}catch(i){console.warn("vitrinka: rrweb failed to start",i);return}if(Ue=e,t==="flight")Qt(Sn);if(t==="session")yt=setInterval(Uo,la)}function Yo(){if(yt)clearInterval(yt);yt=null,Uo();try{je?.()}catch{}je=null,Ue=null,Qt(null),ze=[]}function Sn(){if(!je||!Ue)return;try{Ue.takeFullSnapshot?.(!0)}catch{}}var Jo="vitrinka.capture",A="windows",P="chunks";function ae(e){return new Promise((t,n)=>{e.oncomplete=()=>t(),e.onabort=e.onerror=()=>n(e.error??Error("vitrinka: capture store transaction failed"))})}function En(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error??Error("vitrinka: capture store request failed"))})}function Xo(e){return IDBKeyRange.bound([e,0],[e,Number.MAX_SAFE_INTEGER])}function Go(e){if(typeof e!=="object"||e===null)return!1;let t=e;return typeof t.id==="string"&&typeof t.tab==="string"&&typeof t.startMs==="number"&&typeof t.lastMs==="number"}function Zo(e=globalThis.indexedDB){if(!e)return Promise.reject(Error("vitrinka: IndexedDB is not available"));return new Promise((t,n)=>{let r=e.open(Jo,1);r.onupgradeneeded=()=>{r.result.createObjectStore(A,{keyPath:"id"}),r.result.createObjectStore(P)},r.onerror=()=>n(r.error??Error("vitrinka: capture store did not open")),r.onblocked=()=>n(Error("vitrinka: capture store is blocked by another tab")),r.onsuccess=()=>t(r.result)}).then((t)=>{t.onversionchange=()=>t.close();let n=(o,i)=>{o.objectStore(A).delete(i),o.objectStore(P).delete(Xo(i))};return{async putWindow(o){let i=t.transaction(A,"readwrite");i.objectStore(A).put(o),await ae(i)},async putChunk(o,i,s,a){let l=t.transaction(P,"readwrite"),d={events:s,lanes:[...a]};l.objectStore(P).put(d,[o,i]),await ae(l)},async putWindowChunk(o,i,s,a){let l=t.transaction([A,P],"readwrite"),d={events:s,lanes:[...a]};try{l.objectStore(P).put(d,[o.id,i]),l.objectStore(A).put(o)}catch(g){throw l.abort(),g}await ae(l)},async dropWindow(o){let i=t.transaction([A,P],"readwrite");n(i,o),await ae(i)},async clear(o){let i=t.transaction([A,P],"readwrite"),s=await En(i.objectStore(A).getAll());for(let a of s)if(Go(a)&&a.tab===o)n(i,a.id);await ae(i)},async sweep(o,i,s,a){let l=t.transaction([A,P],"readwrite"),d=(await En(l.objectStore(A).getAll())).filter(Go),g=[],b=new Map;for(let c of d)b.set(c.tab,[...b.get(c.tab)??[],c]);for(let[c,p]of b){let h=p.filter((m)=>m.kind!=="lanes").sort((m,y)=>m.startMs-y.startMs),k=(m)=>m.kind==="lanes"?m.lastMs:Zt(m,h[h.indexOf(m)+1]);for(let m of p.sort((y,f)=>y.startMs-f.startMs))if(k(m)<=o-i||c===s&&m.scope!==a)n(l,m.id);else if(c===s)g.push(m)}return await ae(l),g},async read(o){let i=t.transaction(P,"readonly"),s=await En(i.objectStore(P).getAll(Xo(o)));await ae(i);let a=[],l=[];for(let d of s)a.push(...JSON.parse(d.events)),l.push(...d.lanes);return{events:a,lanes:l}},close:()=>t.close()}})}function Qo(e=globalThis.indexedDB){try{e?.deleteDatabase(Jo)}catch(t){console.warn("vitrinka: could not delete the capture store",t)}}function Rn(e,t){return{x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),w:Math.abs(t.x-e.x),h:Math.abs(t.y-e.y)}}function Tn(e,t){return`${t.y<e.y?"n":"s"}${t.x<e.x?"w":"e"}`}function Mn(e,t){let n=e.x,r=e.x+e.w,o=e.y,i=e.y+e.h,s={x:t.endsWith("w")?n:r,y:t.startsWith("n")?o:i};return{tail:{x:t.endsWith("w")?r:n,y:t.startsWith("n")?i:o},tip:s}}function ei(e,t,n){if(e==="arrow")return Math.hypot(n.x-t.x,n.y-t.y)>=16;return Math.abs(n.x-t.x)>=8&&Math.abs(n.y-t.y)>=8}function ti(e){return e.map((t,n)=>({...t,n:n+1}))}function ni(e){return e.map((t)=>({n:t.n,shape:t.shape,rect:{x:Math.round(t.rect.x),y:Math.round(t.rect.y),w:Math.round(t.rect.w),h:Math.round(t.rect.h)},...t.note.trim()?{note:t.note.trim()}:{},...t.shape==="arrow"&&t.head?{head:t.head}:{}}))}var da=2,ua=3,pa=0,fa=5,Cn=2,ha=3,ga=2000000000,ma="data-vitrinka-hidden",ba="#1b1b1f";function ya(e,t){let n=`position:fixed;left:${Math.round(e.x)}px;top:${Math.round(e.y)}px;width:${Math.round(e.w)}px;height:${Math.round(e.h)}px;background:${ba};z-index:2147483647;pointer-events:none;`;return{type:Cn,id:ga+t,tagName:"div",attributes:{[ma]:"",style:n},childNodes:[]}}function In(e,t,n,r){let o={...e};if(e.type===ha&&t.has(e.id))o.textContent="";if(e.attributes&&t.has(e.id)&&"value"in e.attributes)o.attributes={...e.attributes,value:""};if(e.childNodes){if(o.childNodes=e.childNodes.map((i)=>In(i,t,n,r)),!r.done&&e.type===Cn&&e.tagName==="body")o.childNodes.push(...n),r.done=!0}return o}function ka(e,t){(e.childNodes?.find((r)=>r.type===Cn)??e).childNodes?.push(...t)}function va(e,t){return In(e,t,[],{done:!0})}function ri(e,t,n){if(!t.length&&!n.size)return e.slice();let r=t.map(ya);return e.map((o)=>{let i=o.data;if(o.type===da&&i.node){let s={done:!1},a=In(i.node,n,r,s);if(!s.done)ka(a,r);return{...o,data:{...o.data,node:a}}}if(o.type!==ua||!n.size)return o;if(i.source===pa){let s=o.data,a={...s,...s.texts?{texts:s.texts.map((l)=>n.has(l.id)?{...l,value:""}:l)}:{},...s.adds?{adds:s.adds.map((l)=>({...l,node:va(l.node,n)}))}:{},...s.attributes?{attributes:s.attributes.map((l)=>n.has(l.id)&&("value"in l.attributes)?{...l,attributes:{...l.attributes,value:""}}:l)}:{}};return{...o,data:a}}if(i.source===fa){let s=o.data;if(n.has(s.id))return{...o,data:{...s,text:""}}}return o})}function wa(e,t){return e.x>=t.x&&e.x<=t.x+t.w&&e.y>=t.y&&e.y<=t.y+t.h}function xa(e){return{x:e.left+e.width/2,y:e.top+e.height/2}}function An(e,t,n=document){let r=new Set;if(!e.length||!t||!n.body)return r;let o=(l)=>l.width>0&&l.height>0&&e.some((d)=>wa(xa(l),d)),i=(l)=>{let d=t.getId(l);if(d>0)r.add(d)},s=n.createTreeWalker(n.body,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT),a=n.createRange();for(let l=s.nextNode();l;l=s.nextNode())if(l.nodeType===Node.TEXT_NODE){if(!l.textContent?.trim())continue;if(a.selectNodeContents(l),o(a.getBoundingClientRect()))i(l)}else if(l instanceof HTMLInputElement||l instanceof HTMLTextAreaElement||l instanceof HTMLSelectElement){if(o(l.getBoundingClientRect()))i(l)}return a.detach(),r}var Sa=["errors","interactions","full","console","network"];var vt={storage:"memory",windowSec:300,maxBytes:12582912,classes:["errors","interactions"]};function St(e){return{storage:"memory",windowSec:60,maxBytes:4194304,classes:e===!1?["errors"]:["errors","interactions"]}}function wt(e,t,n){return Math.min(n,Math.max(t,e))}function Ea(e){if(!Array.isArray(e))return null;return Sa.filter((t)=>e.includes(t))}function oi(e,t){if(typeof e!=="object"||e===null)return St(t);let n=e;return{storage:n.storage==="browser"?"browser":n.storage==="memory"?"memory":vt.storage,windowSec:typeof n.windowSec==="number"&&Number.isFinite(n.windowSec)?wt(Math.round(n.windowSec),10,3600):vt.windowSec,maxBytes:typeof n.maxBytes==="number"&&Number.isFinite(n.maxBytes)?wt(Math.round(n.maxBytes),262144,67108864):vt.maxBytes,classes:Ea(n.classes)??vt.classes}}function xt(e){let t=e.includes("full");return{replay:t||e.includes("interactions"),errors:t||e.includes("errors"),console:t||e.includes("console"),network:t||e.includes("network")}}function Ra(e){let t=[];if(e.errors)t.push("errors");if(e.replay)t.push("interactions");if(e.console)t.push("console");if(e.network)t.push("network");return t}function ii(e,t){if(!t)return e;let n=typeof t.windowSec==="number"&&t.windowSec>0?Math.min(e.windowSec,t.windowSec):e.windowSec,r=typeof t.maxBytes==="number"&&t.maxBytes>0?Math.min(e.maxBytes,t.maxBytes):e.maxBytes,o=e.classes;if(t.classes){let i=xt(e.classes),s=xt(t.classes);o=Ra({replay:i.replay&&s.replay,errors:i.errors&&s.errors,console:i.console&&s.console,network:i.network&&s.network})}return{storage:t.storage==="memory"?"memory":e.storage,windowSec:wt(n,10,3600),maxBytes:wt(r,262144,67108864),classes:o}}function si(e){return e==="balanced"||e==="full"?e:"strict"}function ai(e){if(e==="full")return{fullFidelity:!0};if(e==="balanced")return{};return{maskAllText:!0}}var li="[data-vitrinka-unmask]";var Ta=3670016,ci=4194240,Ma=2000,di=500,Ca=60000,Ia=/[A-Za-z0-9_-]{20,}/g;function K(e,t=""){return typeof e==="string"?e:t}function Aa(e){let t=K(e),n;try{n=new URL(t,globalThis.location?.href??"http://localhost").pathname}catch{n=t.split(/[?#]/)[0]??""}return n.replace(Ia,"•••").slice(0,300)}var Pa=4;function _a(e,t){let n=[],r=!1,o=[],i=!1,s=()=>{if(i)r=!0;else n.push(...o);o=[],i=!1};for(let a of e){if(a.type===Pa&&o.length)s();if(!i&&Re(JSON.stringify(a))+1>t)i=!0;o.push(a)}return s(),{events:n,dropped:r}}function La(e){return(t,n)=>{if(t==="console"){let r=K(n?.level,"error");if(r==="error"?!(e.errors||e.console):!e.console)return null;return{level:r,text:K(n?.text).slice(0,Ma)}}if(t==="net"){let r=typeof n?.status==="number"?n.status:0,o=r===0||r>=400||n?.error!==void 0;if(!(e.network||e.errors&&o))return null;return{method:K(n?.method,"GET").toUpperCase(),path:Aa(n?.url),status:r,ms:typeof n?.ms==="number"?Math.max(0,Math.round(n.ms)):0}}return null}}async function Da(e){try{let t=await O("GET","/api/v1/report-config",void 0,{target:e}),n=typeof t.flightRecorder==="boolean"?t.flightRecorder:void 0;return{project:K(t.project),profile:t.captureProfile==null?St(n):oi(t.captureProfile,n),masking:si(t.profile),reachable:!0}}catch(t){return console.warn("vitrinka: report config unavailable — capturing the last minute, strictly masked",t),{project:"",profile:St(),masking:"strict",reachable:!1}}}function ui(e){let t=e?.mirror;if(typeof t!=="object"||t===null)return null;let n=t.getId;return typeof n==="function"?{getId:(r)=>Number(n.call(t,r))}:null}class pi{opts;ready;store=null;stopped=!1;claim=null;config=null;listeners=new Set;capturing=!1;offs=[];capture=[];constructor(e){this.opts=e;this.ready=this.start()}async start(){let{opts:e}=this;this.offs.push(Pr(e.base));let t=await Da({url:e.base,key:e.key}),n=ii(t.profile,e.capture),r=xt(n.classes),o={project:t.project,profile:n,lanes:r,masking:t.masking,reachable:t.reachable,capturing:!1};if(this.stopped)return o;if(this.config=o,this.claim=Cr("report",()=>this.standDown()),!this.claim)return console.warn("vitrinka: the recorder runs this page’s capture — Report a problem sends without one"),o;this.capturing=!0,o.capturing=!0,Mr(Tr(),globalThis.location?.host??""),w.pathname=globalThis.location?.pathname??"/",Dr(ai(o.masking)),zt(e.sanitizeUrl),this.capture.push(()=>zt(null));let i=n.windowSec*1000,s=[e.base,t.project,o.masking,n.classes.join(",")].join("|"),a=[],l=[];if(n.storage==="browser")try{this.store=await Zo();let d=await this.store.sweep(Date.now(),i,w.tabId,s);a=d;let g=this.store;l=(await Promise.all(d.filter((c)=>c.kind==="lanes").map((c)=>g.read(c.id)))).flatMap((c)=>c.lanes).sort((c,p)=>Date.parse(c.ts)-Date.parse(p.ts))}catch(d){console.warn("vitrinka: browser capture storage unavailable — keeping the capture in memory",d),this.store=null,a=[],l=[]}else Qo();if(!this.capturing)return this.store?.close(),this.store=null,o;if(to({windowMs:i,checkoutMs:Math.min(Ca,i),maxBytes:n.maxBytes,maxEvents:Math.max(20000,Math.round(n.maxBytes/200)),maxLaneEvents:Jt,keepLane:La(r),store:this.store,scope:s,prior:a,priorLanes:l}),this.capture.push(no),this.store&&typeof window<"u"){let d=()=>tt();this.capture.push(N(window,"pagehide",d),N(document,"visibilitychange",d))}if(r.errors||r.console)$o({levels:r.console?["warn","info","log"]:[]}),this.capture.push(qo);if(r.errors||r.network)jo({detail:"meta"}),this.capture.push(zo);if(r.replay){let d=await e.loadRecord(e.base).catch((g)=>(console.warn("vitrinka: the page recorder did not load — reports go without a replay",g),null));if(d&&this.capturing)Vo(d,"flight",{unmaskSelector:li}),this.capture.push(Yo)}return o}onChange(e){return this.listeners.add(e),()=>this.listeners.delete(e)}standDown(){if(!this.capturing)return;if(this.capturing=!1,this.config)this.config.capturing=!1;for(let t of this.capture.splice(0).reverse())t();let e=this.store;if(this.store=null,e)io().then(()=>e.close());for(let t of this.listeners)t()}freeze(){if(!this.capturing)return{clip:null,stored:Promise.resolve(new Map)};w.pathname=globalThis.location?.pathname??w.pathname;let e=nn();if(e&&kt()&&!uo(e))Sn(),e=nn();let t=this.store,n=e?.windows.filter((o)=>o.stored).map((o)=>o.id)??[],r=t&&n.length?Promise.all(n.map(async(o)=>[o,await t.read(o)])).then((o)=>new Map(o)):Promise.resolve(new Map);return r.catch(()=>{return}),{clip:e,stored:r}}hiddenIdsAt(e){if(!this.capturing)return null;let t=ui(kt());return t?An([e],t):null}async build(e,t,n=new Set){let r=t.filter((f)=>f.shape==="hide").map((f)=>f.rect),o=ui(kt()),i=r.length>0&&!o;if(i)console.warn("vitrinka: this page recorder cannot name what a hide covers — the report goes without its replay");let s=new Set(n);if(r.length&&o)for(let f of An(r,o))s.add(f);let a=[],l=e.clip?.truncated??!1,d=await e.stored.catch((f)=>(console.warn("vitrinka: the stored part of the capture could not be read — the replay starts later",f),null));for(let f of e.clip?.windows??[]){if(!f.stored){a.push(...f.events);continue}let R=d?.get(f.id);if(!R?.events.length)l=!0;else a.push(...R.events)}let g=e.clip?.lanes??[],b=i?{events:[],dropped:!1}:_a(ri(a,r,s),ci);if(b.dropped)l=!0;let{parts:c,dropped:p}=hn(b.events,Ta,ci),h=[],k=0;for(let f of c){k+=f.count;let R=b.events[k-1]?.timestamp??Date.now();h.push({seq:h.length+1,ts:new Date(R).toISOString(),count:f.count,body:f.body})}let m=g.filter((f)=>f.kind==="console").slice(-di).map((f)=>({level:K(f.payload?.level,"error"),ts:f.ts,text:K(f.payload?.text)})),y=g.filter((f)=>f.kind==="net").slice(-di).map((f)=>({method:K(f.payload?.method,"GET"),path:K(f.payload?.path),status:typeof f.payload?.status==="number"?f.payload.status:0,ms:typeof f.payload?.ms==="number"?f.payload.ms:0}));return{chunks:h,truncated:l||p.length>0,console:m,network:y}}clear(){if(this.capturing)oo()}stop(){this.stopped=!0,this.listeners.clear(),this.standDown(),Ir(this.claim),this.claim=null;for(let e of this.offs.splice(0).reverse())e()}}var L=null;function fi(e){if(L){let t=L.engine.opts;if(!(t.base===e.base&&t.key===e.key&&t.sanitizeUrl===e.sanitizeUrl&&JSON.stringify(t.capture??{})===JSON.stringify(e.capture??{})))return console.warn("vitrinka: one capture engine per page — this widget reports without a capture (another widget’s key, base, capture or sanitizeUrl owns it)"),null;return L.refs++,L.engine}return L={engine:new pi(e),refs:1},L.engine}function hi(e){if(!e||!L||L.engine!==e)return;if(--L.refs>0)return;L=null,e.stop()}var Na=/^[\w-]+\.[\w-]+\.[\w-]+$/;function Et(e){if(!e)return null;if("token"in e){let r=typeof e.token==="string"?e.token.trim():"";if(r.length>4096||!Na.test(r))return console.warn("vitrinka: identify({token}) needs the compact JWS your server signed — reporting anonymously"),null;return{token:r}}let t=typeof e.email==="string"?e.email.trim().slice(0,254):"";if(!t.includes("@"))return console.warn("vitrinka: identify({email}) needs an email address — reporting anonymously"),null;let n=typeof e.name==="string"?e.name.trim().slice(0,200):"";return n?{email:t,name:n}:{email:t}}var gi=null,Pn=new Set;function Oa(e){gi=Et(e);for(let t of Pn)t()}function mi(){return gi}function bi(e){return Pn.add(e),()=>Pn.delete(e)}var Ba=new Set(["Shift","Control","Alt","Meta","AltGraph","OS","CapsLock","Fn","Hyper","Super"]),Rt="report.keybind";function yi(e){if(Ba.has(e.key))return{kind:"wait"};if(e.key==="Escape"&&!e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey)return{kind:"cancel"};if(!e.altKey&&!e.ctrlKey&&!e.metaKey)return{kind:"bare"};return{kind:"bind",bind:{code:e.code,alt:e.altKey,ctrl:e.ctrlKey,meta:e.metaKey,shift:e.shiftKey}}}function ki(e,t){return e.code===t.code&&e.altKey===t.alt&&e.ctrlKey===t.ctrl&&e.metaKey===t.meta&&e.shiftKey===t.shift}var Ha={Space:"Space",Enter:"↵",Backspace:"⌫",Tab:"⇥",ArrowUp:"↑",ArrowDown:"↓",ArrowLeft:"←",ArrowRight:"→",Slash:"/",Backslash:"\\",Period:".",Comma:",",Semicolon:";",Quote:"'",BracketLeft:"[",BracketRight:"]",Minus:"-",Equal:"=",Backquote:"`"};function qa(e){let t=/^Key([A-Z])$/.exec(e);if(t)return t[1];let n=/^(?:Digit|Numpad)(\d)$/.exec(e);if(n)return n[1];return Ha[e]??e}function $a(){let e=globalThis.navigator,t=e?.userAgentData?.platform??e?.platform??"";return/mac|iphone|ipad/i.test(t)}function Tt(e,t=$a()){let n=qa(e.code);if(t)return`${e.ctrl?"⌃":""}${e.alt?"⌥":""}${e.shift?"⇧":""}${e.meta?"⌘":""}${n}`;return[e.ctrl&&"Ctrl",e.alt&&"Alt",e.shift&&"Shift",e.meta&&"Meta",n].filter(Boolean).join("+")}function vi(e){if(!e)return null;try{let t=JSON.parse(e);if(typeof t!=="object"||t===null)return null;let n=t;if(typeof n.code!=="string"||!n.code)return null;let r={code:n.code,alt:n.alt===!0,ctrl:n.ctrl===!0,meta:n.meta===!0,shift:n.shift===!0};return r.alt||r.ctrl||r.meta?r:null}catch{return null}}function wi(){return vi(z().getString(Rt))}function _n(e){let t=z();if(e)t.set(Rt,JSON.stringify(e));else t.remove(Rt)}function xi(e){let t=z();return t.watch?t.watch(Rt,(n)=>e(vi(n))):()=>{return}}var Si=`
|
|
10
10
|
:host { all: initial; }
|
|
11
11
|
.vr {
|
|
12
12
|
--ink: #f2f1ef;
|
|
@@ -225,5 +225,5 @@ kbd {
|
|
|
225
225
|
.coach .loop { animation: none; stroke-dashoffset: 0; }
|
|
226
226
|
.coach .hold { animation: none; opacity: .9; }
|
|
227
227
|
}
|
|
228
|
-
`;class Ln{capture;tabHost;target;id="";custody="";sent="";blobKeys=new Map;rowsPosted=0;skipCapture=!1;constructor(e,t,n){this.capture=e;this.tabHost=t;this.target=n}async run(e){let t={target:this.target},n={title:e.title,description:e.description,markers:e.markers,notify:e.notify??!1},r=JSON.stringify(n);if(!this.id){let i=await O("POST","/api/v1/reports",e,t);if(typeof i.id!=="string"||!i.id)throw Error("vitrinka: the server filed the report without an id");this.id=i.id,this.custody=i.custody==="direct"?"direct":"quarantined",this.sent=r}else if(this.sent!==r)await O("PATCH",`/api/v1/reports/${encodeURIComponent(this.id)}`,n,t),this.sent=r;if(!this.skipCapture)try{await this.sendCapture()}catch(i){if(!(i instanceof T)||!j(i.status))throw i;console.warn("vitrinka: the server refused the recording — the report goes without it",i),this.skipCapture=!0}let o=await O("POST",`/api/v1/reports/${encodeURIComponent(this.id)}/submit`,{},t);return{status:o.status==="filed"?"filed":"quarantined",...typeof o.reportUrl==="string"&&o.reportUrl?{reportUrl:o.reportUrl}:{}}}async sendCapture(){let e=encodeURIComponent(this.id),{chunks:t,truncated:n}=this.capture;for(let o of t){if(this.blobKeys.has(o.seq))continue;let i=await Yt(`/api/v1/reports/${e}/chunk?seq=${o.seq}`,"application/json",o.body,this.target);if(!i.blobKey)throw Error(`vitrinka: chunk ${o.seq} came back without a blob key`);this.blobKeys.set(o.seq,i.blobKey)}let r=t.map((o)=>({seq:o.seq,ts:o.ts,tabHost:this.tabHost,kind:"rrweb",payload:{count:o.count,source:"replay",truncated:n},blobKey:this.blobKeys.get(o.seq)??""}));while(this.rowsPosted<r.length){let o=r.slice(this.rowsPosted,this.rowsPosted+pt);await O("POST",`/api/v1/reports/${e}/events`,{events:o},{target:this.target}),this.rowsPosted+=o.length}}}var
|
|
229
|
-
`)[0]?.trim()??"";return t.length>Si?`${t.slice(0,Si-1)}…`:t}function za(){return globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches??!1}function ja(e){let t=u("span"),n=u("kbd"),r=u("button",{class:"fab",type:"button",part:"button","aria-haspopup":"dialog"},t,n),o=u("h2",{id:"vr-title"}),i=u("button",{class:"icon",type:"button"},Q(le.gear)),s=u("button",{class:"icon",type:"button"},Q(le.close)),a=u("header",{class:"head"},o,i,s),l=u("label",{class:"prompt",for:"vr-desc"}),d=u("textarea",{class:"desc",id:"vr-desc",rows:"3"}),g=u("span"),b=u("span"),c=u("button",{class:"link",type:"button","aria-expanded":"false","aria-controls":"vr-included"},b,Q(le.chevron)),p=u("div",{class:"attached"},Q(le.clip),g,u("span",{"aria-hidden":"true"},"·"),c),h=u("ul",{class:"included",id:"vr-included"}),k=u("span",{class:"chips"}),m=u("span"),y=u("div",{class:"marked"},k,m),f=u("input",{type:"checkbox"}),R=u("span"),D=u("label",{class:"notify"},f,R),Te=u("p",{class:"error",role:"alert"}),Ve=u("span"),Ye=u("button",{class:"where",type:"button"},Q(le.pen),Ve),Me=u("button",{class:"send",type:"button"}),Hn=u("div",{class:"pane describe"},l,d,p,h,y,D,Te,u("div",{class:"actions"},Ye,Me)),qn=u("span",{class:"label",id:"vr-bind-label"}),$n=u("button",{class:"bind",type:"button","aria-pressed":"false","aria-describedby":"vr-bind-label"}),Fn=u("button",{class:"link",type:"button"}),Kn=u("p",{class:"hint"}),Wn=u("p",{class:"reason",role:"status"}),zn=u("button",{class:"link",type:"button"}),jn=u("div",{class:"pane settings"},u("div",{class:"row"},qn,$n),Wn,Kn,u("div",{class:"settings-foot"},zn,Fn)),Un=u("h3"),Vn=u("p",{class:"sent-body"}),Yn=u("span"),Xn=u("a",{class:"see",target:"_blank",rel:"noopener noreferrer"},Yn),Jn=u("button",{class:"link",type:"button"}),Gn=u("div",{class:"pane sent",role:"status"},u("div",{class:"sent-head"},Q(le.check),Un),Vn,u("div",{class:"sent-actions"},Xn,Jn)),Zn=u("section",{class:"card",role:"dialog","aria-modal":"false","aria-labelledby":"vr-title"},a,Hn,jn,Gn),Ct=_("svg",{class:"ink","aria-hidden":"true"}),Qn=_("defs",{}),er=_("marker",{id:"vr-head",viewBox:"0 0 10 10",refX:7,refY:5,markerWidth:5,markerHeight:5,orient:"auto-start-reverse"});er.append(_("path",{d:"M0 0L10 5L0 10z",fill:"#dc2f4c"})),Qn.append(er);let tr=_("g",{}),nr=_("g",{class:"draft"});Ct.append(Qn,tr,nr);let rr=u("div",{class:"pins"}),or=u("p"),ir=u("p"),sr=u("p",{class:"keys",id:"vr-keys"}),It=u("div",{class:"coach",role:"status"});It.append(Q(Ka(za())),or,ir,sr);let At=new Map;for(let ur of $a)At.set(ur,u("button",{type:"button","aria-pressed":"false","data-tool":ur}));let ar=u("button",{type:"button"}),lr=u("button",{type:"button",class:"done"}),cr=u("div",{class:"toolbar",role:"toolbar"},...At.values(),u("span",{class:"sep","aria-hidden":"true"}),ar,lr),Pt=u("div",{class:"mark",tabindex:"0",role:"application","aria-describedby":"vr-keys"},rr,It,cr);Pt.prepend(Ct);let _t=u("div",{class:"vr"},r,Zn,Pt),dr=u("style");return dr.textContent=xi,_t.prepend(dr),e.append(_t),{root:_t,fab:r,fabLabel:t,fabKbd:n,card:Zn,title:o,gear:i,closeBtn:s,describe:Hn,prompt:l,desc:d,attached:p,attachedText:g,disclose:c,discloseText:b,included:h,marked:y,markedChips:k,markedText:m,notify:D,notifyBox:f,notifyText:R,error:Te,where:Ye,whereText:Ve,send:Me,settings:jn,bindLabel:qn,bindBtn:$n,unbind:Fn,bindHint:Kn,bindReason:Wn,back:zn,sent:Gn,sentTitle:Un,sentBody:Vn,see:Xn,seeText:Yn,sentClose:Jn,mark:Pt,ink:Ct,shapes:tr,draft:nr,pins:rr,coach:It,coachText:or,coachMore:ir,coachKeys:sr,toolButtons:At,toolbar:cr,undo:ar,done:lr}}class On{opts;hud;engine;config=null;locale;s;button;openSelector;identity;keybind;isOpen=!1;view="describe";marking=!1;markers=[];nextKey=1;tool="circle";frozen=null;job=null;sending=!1;error="";result=null;notify=!1;sentNotify=!1;includedOpen=!1;recordingBind=!1;bindRefused=!1;noteOpen=null;drawing=null;offs=[];pins=new Map;hideIds=new Map;dialogOrder=[...document.querySelectorAll("dialog[open]")].filter((e)=>e instanceof HTMLDialogElement);activeDialog(){this.dialogOrder=this.dialogOrder.filter((n)=>n.isConnected&&n.open);let e=(n)=>{try{return n.matches(":modal")}catch{return!1}};return[...this.dialogOrder].reverse().find(e)??this.dialogOrder.at(-1)??Wr()}sheet=null;e;constructor(e){this.opts=e;this.locale=e.locale??Nt(),this.s=Dt(this.locale),this.button=e.button,this.openSelector=e.openSelector??null,this.identity=e.identity===void 0?void 0:Et(e.identity),this.keybind=vi(),this.hud=Fr(),this.e=ja(this.hud.mount),this.engine=pi({base:e.base,key:e.key,appVersion:e.appVersion,capture:e.capture,sanitizeUrl:e.sanitizeUrl,loadRecord:e.loadRecord}),this.engine?.ready.then((t)=>{this.config=t,this.paint()}),this.bind(),this.paint(),this.followDialog()}followDialog(){let e=this.activeDialog();if((this.sheet?.target??null)===e)return;let t=this.e.root.getRootNode(),n=t instanceof ShadowRoot&&t.activeElement instanceof HTMLElement?t.activeElement:null,r=this.sheet;if(e){let o=zr(e);o.mount.append(this.e.root),this.sheet={target:e,host:o}}else this.hud.mount.append(this.e.root),this.sheet=null;r?.host.destroy(),n?.focus()}open(){if(this.isOpen)return;if(this.isOpen=!0,this.view!=="describe")this.view="describe";if(this.result=null,!this.job)this.frozen=this.engine?.freeze()??null;this.paint(),requestAnimationFrame(()=>this.e.desc.focus())}close(){if(!this.isOpen)return;if(this.marking)this.endMarking(!1);if(this.stopRecordingBind(),this.isOpen=!1,this.view="describe",this.paint(),this.button)this.e.fab.focus()}setLocale(e){let t=Ce(e)??Nt();if(t===this.locale)return;this.locale=t,this.s=Dt(t),this.paint()}setButton(e){this.button=e,this.paint()}setOpenSelector(e){this.openSelector=e||null}identify(e){this.identity=e===void 0?void 0:Et(e),this.paint()}unmount(){this.stopRecordingBind();for(let e of this.offs.splice(0).reverse())e();fi(this.engine),this.sheet?.host.destroy(),this.sheet=null,this.hud.destroy()}bind(){let e=this.e,t=(o,i,s)=>{o.addEventListener(i,s)};t(e.fab,"click",()=>this.isOpen?this.close():this.open()),t(e.closeBtn,"click",()=>this.close()),t(e.gear,"click",()=>this.show(this.view==="settings"?"describe":"settings")),t(e.back,"click",()=>this.show("describe")),t(e.sentClose,"click",()=>this.close()),t(e.desc,"input",()=>this.paint()),t(e.disclose,"click",()=>{this.includedOpen=!this.includedOpen,this.paint()}),t(e.notifyBox,"change",()=>{this.notify=e.notifyBox.checked}),t(e.where,"click",()=>this.startMarking()),t(e.send,"click",()=>void this.send()),t(e.bindBtn,"click",()=>this.recordingBind?this.stopRecordingBind():this.startRecordingBind()),t(e.unbind,"click",()=>{this.keybind=null,_n(null),this.paint()}),t(e.card,"keydown",(o)=>{if(o.key!=="Escape"||this.recordingBind)return;if(o.preventDefault(),this.view==="settings")this.show("describe");else this.close()});for(let[o,i]of e.toolButtons)t(i,"click",(s)=>{if(this.tool=o,this.renderKbDraft(),this.paint(),s.detail===0)e.mark.focus()});if(t(e.mark,"keydown",(o)=>this.markKey(o)),t(e.undo,"click",()=>{this.markers=Nn(this.markers.slice(0,-1)),this.renderMarks(),this.paint()}),t(e.done,"click",()=>this.endMarking(!0)),t(e.mark,"pointerdown",(o)=>this.pointerDown(o)),t(e.mark,"pointermove",(o)=>this.pointerMove(o)),t(e.mark,"pointerup",(o)=>this.pointerUp(o)),t(e.mark,"pointercancel",()=>this.cancelDraft()),this.offs.push(N(e.mark,"wheel",(o)=>o.preventDefault())),this.offs.push(N(e.mark,"touchmove",(o)=>o.preventDefault())),this.offs.push(N(window,"keydown",(o)=>{if(this.recordingBind)return;if(this.marking&&o.key==="Escape"){if(o.preventDefault(),this.kbDraft)this.cancelDraft();else this.endMarking(!0);return}if(this.keybind&&yi(o,this.keybind))if(o.preventDefault(),this.isOpen)this.close();else this.open()},{capture:!0})),this.offs.push(N(document,"click",(o)=>{let i=this.openSelector,s=o.target;if(!i||!(s instanceof Element))return;let a=null;try{a=s.closest(i)}catch{return}if(!a)return;o.preventDefault(),this.open()})),this.offs.push(wi((o)=>{this.keybind=o,this.paint()})),this.offs.push(mi(()=>this.paint())),this.engine)this.offs.push(this.engine.onChange(()=>this.paint()));let n=0,r=new MutationObserver((o)=>{for(let i of o){if(i.type!=="attributes"||i.attributeName!=="open"||!(i.target instanceof HTMLDialogElement))continue;let s=i.target;if(!s.open)this.dialogOrder=this.dialogOrder.filter((a)=>a!==s);else if(i.oldValue===null)this.dialogOrder=[...this.dialogOrder.filter((a)=>a!==s),s]}if(n)return;n=requestAnimationFrame(()=>{n=0,this.followDialog()})});r.observe(document.documentElement,{subtree:!0,childList:!0,attributes:!0,attributeOldValue:!0,attributeFilter:["open","data-state"]}),this.offs.push(()=>{if(r.disconnect(),n)cancelAnimationFrame(n)})}show(e){if(this.stopRecordingBind(),this.view=e,this.paint(),e==="describe")requestAnimationFrame(()=>this.e.desc.focus());if(e==="settings")requestAnimationFrame(()=>this.e.bindBtn.focus())}who(){return this.identity!==void 0?this.identity:gi()}stopBindListener=null;startRecordingBind(){this.recordingBind=!0,this.bindRefused=!1,this.stopBindListener=N(window,"keydown",(e)=>{e.preventDefault(),e.stopPropagation();let t=bi(e);if(t.kind==="wait")return;if(t.kind==="bare"){this.bindRefused=!0,this.paint();return}if(t.kind==="bind")this.keybind=t.bind,_n(t.bind);this.stopRecordingBind()},{capture:!0}),this.paint()}stopRecordingBind(){if(!this.recordingBind)return;this.recordingBind=!1,this.bindRefused=!1,this.stopBindListener?.(),this.stopBindListener=null,this.paint()}startMarking(){if(this.job?.id)return;this.marking=!0,this.noteOpen=null,this.renderMarks(),this.paint();let e=globalThis.innerWidth||800,t=globalThis.innerHeight||600;this.placeCoach({x:e/2-150,y:t-260},!1),this.e.mark.focus()}endMarking(e){if(this.cancelDraft(),this.marking=!1,this.noteOpen=null,this.paint(),e&&this.isOpen)requestAnimationFrame(()=>this.e.desc.focus())}onChrome(e){return e instanceof Node&&(this.e.toolbar.contains(e)||this.e.pins.contains(e))}pointerDown(e){if(this.onChrome(e.target)||e.button!==0||!e.isPrimary)return;e.preventDefault();let t=this.e.root.getRootNode();if(t instanceof ShadowRoot&&t.activeElement instanceof HTMLElement)t.activeElement.blur();this.noteOpen=null,this.drawing={start:{x:e.clientX,y:e.clientY},shape:this.tool,pointer:e.pointerId};try{this.e.mark.setPointerCapture(e.pointerId)}catch{}this.e.coach.classList.add("pressing"),this.renderPins()}pointerMove(e){if(!this.markers.length)this.placeCoach({x:e.clientX,y:e.clientY},!0);let t=this.drawing;if(!t||e.pointerId!==t.pointer)return;this.e.draft.replaceChildren(...this.shapeNodes({shape:t.shape,rect:Rn(t.start,{x:e.clientX,y:e.clientY}),head:Tn(t.start,{x:e.clientX,y:e.clientY})}))}pointerUp(e){let t=this.drawing;if(!t||e.pointerId!==t.pointer)return;let n={x:e.clientX,y:e.clientY};if(this.cancelDraft(),!Qo(t.shape,t.start,n))return;this.addMarker(t.shape,Rn(t.start,n),t.shape==="arrow"?Tn(t.start,n):void 0)}addMarker(e,t,n){let r=this.nextKey++;if(e==="hide"){let o=this.engine?.hiddenIdsAt(t);if(o)this.hideIds.set(r,o)}this.markers=Nn([...this.markers,{key:r,n:this.markers.length+1,shape:e,rect:t,note:"",...n?{head:n}:{}}]),this.noteOpen=r,this.renderMarks(),this.paint(),this.pins.get(r)?.note.focus()}cancelDraft(){this.drawing=null,this.kbDraft=null,this.e.draft.replaceChildren(),this.e.coach.classList.remove("pressing")}kbDraft=null;markKey(e){if(e.target!==this.e.mark)return;let t=globalThis.innerWidth||800,n=globalThis.innerHeight||600;if(e.key==="Enter"||e.key===" "){if(e.preventDefault(),!this.kbDraft){this.kbDraft={x:Math.round(t/2-Dn.w/2),y:Math.round(n/2-Dn.h/2),...Dn},this.renderKbDraft();return}let a=this.kbDraft;this.cancelDraft(),this.addMarker(this.tool,a,this.tool==="arrow"?"se":void 0);return}let r=Fa[e.key];if(!r||!this.kbDraft)return;e.preventDefault();let o=this.kbDraft,[i,s]=r;this.kbDraft=e.shiftKey?{...o,w:Math.min(t-o.x,Math.max(Ri,o.w+i)),h:Math.min(n-o.y,Math.max(Ri,o.h+s))}:{...o,x:Math.min(t-o.w,Math.max(0,o.x+i)),y:Math.min(n-o.h,Math.max(0,o.y+s))},this.renderKbDraft()}renderKbDraft(){let e=this.kbDraft;if(!e)return;this.e.draft.replaceChildren(...this.shapeNodes({shape:this.tool,rect:e,head:"se"}))}placeCoach(e,t){let n=globalThis.innerWidth||800,r=globalThis.innerHeight||600,o=this.e.coach.offsetWidth||300,i=this.e.coach.offsetHeight||140,s=t?e.x+20:e.x,a=t?e.y+20:e.y;if(s+o>n-8)s=t?e.x-o-20:n-o-8;if(a+i>r-90)a=t?e.y-i-20:r-i-90;this.e.coach.style.left=`${Math.max(8,s)}px`,this.e.coach.style.top=`${Math.max(8,a)}px`}shapeNodes(e){let{x:t,y:n,w:r,h:o}=e.rect;if(e.shape==="circle")return[_("ellipse",{class:"stroke",cx:t+r/2,cy:n+o/2,rx:Math.max(1,r/2),ry:Math.max(1,o/2)})];if(e.shape==="box")return[_("rect",{class:"stroke",x:t,y:n,width:r,height:o,rx:6})];if(e.shape==="arrow"){let{tail:a,tip:l}=Mn(e.rect,e.head??"se");return[_("line",{class:"stroke",x1:a.x,y1:a.y,x2:l.x,y2:l.y,"marker-end":"url(#vr-head)"})]}let i=_("rect",{class:"veil",x:t,y:n,width:r,height:o,rx:4}),s=_("text",{class:"veil-label",x:t+r/2,y:n+o/2+4,"text-anchor":"middle"});return s.textContent=r>60&&o>20?this.s.hidden:"",[i,s]}renderMarks(){this.e.shapes.replaceChildren(...this.markers.flatMap((t)=>this.shapeNodes(t)));let e=new Set(this.markers.map((t)=>t.key));for(let[t,n]of this.pins){if(e.has(t))continue;n.el.remove(),this.pins.delete(t)}for(let t of this.markers){if(this.pins.has(t.key))continue;let n=u("button",{class:"num",type:"button"}),r=u("input",{class:"note",type:"text",maxlength:"500"}),o=u("button",{class:"rm",type:"button"},Q(le.close)),i=u("div",{class:"pin"},n,r,o);n.addEventListener("click",()=>{this.noteOpen=t.key,this.renderPins(),r.focus()}),r.addEventListener("input",()=>{this.markers=this.markers.map((s)=>s.key===t.key?{...s,note:r.value}:s)}),r.addEventListener("focus",()=>{this.noteOpen=t.key,this.renderPins()}),r.addEventListener("keydown",(s)=>{if(s.key!=="Enter")return;s.preventDefault(),this.e.mark.focus()}),o.addEventListener("click",()=>{this.markers=Nn(this.markers.filter((s)=>s.key!==t.key)),this.renderMarks(),this.paint()}),this.e.pins.append(i),this.pins.set(t.key,{el:i,num:n,note:r,rm:o})}this.renderPins()}renderPins(){let e=globalThis.innerWidth||800;for(let t of this.markers){let n=this.pins.get(t.key);if(!n)continue;let r=t.shape==="arrow"?Mn(t.rect,t.head??"se").tail:{x:t.rect.x,y:t.rect.y},o=this.noteOpen===t.key||t.note.trim()!=="",i=o?290:30;n.el.style.left=`${Math.min(Math.max(4,r.x-12),e-i)}px`,n.el.style.top=`${Math.max(4,r.y-12)}px`,n.num.textContent=String(t.n),n.num.setAttribute("aria-label",this.s.mark(t.n)),n.note.hidden=!o,n.rm.hidden=!o,n.note.placeholder=this.s.notePlaceholder,n.note.setAttribute("aria-label",`${this.s.mark(t.n)} — ${this.s.notePlaceholder}`),n.rm.setAttribute("aria-label",this.s.removeMark(t.n))}}envelope(e,t){let n=this.who(),r=globalThis.location;return{title:Wa(e),description:e,env:{url:te(r?`${r.origin}${r.pathname}`:""),ua:globalThis.navigator?.userAgent??"",viewport:{w:globalThis.innerWidth||0,h:globalThis.innerHeight||0,dpr:globalThis.devicePixelRatio||1},appVersion:this.opts.appVersion??"",locale:globalThis.navigator?.language??""},console:t.console,network:t.network,...n?{identity:n,notify:this.notify}:{},markers:ti(this.markers),locale:this.locale}}async send(){let e=this.e.desc.value.trim();if(this.sending||!e)return;if(this.sending=!0,this.error="",this.paint(),this.job&&!this.job.id)this.job=null;try{if(!this.job){let t=new Set;for(let r of this.markers)for(let o of this.hideIds.get(r.key)??[])t.add(o);let n=this.engine?await this.engine.build(this.frozen??{clip:null,stored:Promise.resolve(new Map)},this.markers,t).catch((r)=>(console.warn("vitrinka: the capture could not be prepared — the report goes without it",r),Ei)):Ei;this.job=new Ln(n,globalThis.location?.host??"",{url:this.opts.base,key:this.opts.key})}this.result=await this.job.run(this.envelope(e,this.job.capture)),this.sentNotify=this.notify&&this.who()!==null,this.view="sent",this.job=null,this.frozen=null,this.e.desc.value="",this.markers=[],this.hideIds.clear(),this.notify=!1,this.e.notifyBox.checked=!1,this.includedOpen=!1,this.renderMarks(),this.engine?.clear()}catch(t){console.warn("vitrinka: the report did not go through — Retry resumes it",t),this.error=this.job?.id?"capture":"create"}finally{this.sending=!1,this.paint()}if(this.view==="sent")requestAnimationFrame(()=>((this.result?.reportUrl)?this.e.see:this.e.sentClose).focus())}includedItems(){let e=this.s,t=[],n=this.config?.lanes;if(n?.replay)t.push(`${e.incReplay} — ${e.incReplayMasked[this.config?.masking??"strict"].toLowerCase()}`);if(n?.errors)t.push(e.incErrors);if(n?.console)t.push(e.incConsole);if(n?.network)t.push(e.incNetwork);else if(n?.errors)t.push(e.incFailedRequests);if(t.push(e.incEnv),this.who())t.push(e.incIdentity);if(this.markers.length)t.push(e.incMarks);return t}paint(){let{e,s:t}=this,n=this.who();e.root.setAttribute("lang",this.locale),e.root.classList.toggle("nobutton",!this.button),e.fab.hidden=!this.button||this.marking,e.fabLabel.textContent=t.button,e.fab.setAttribute("aria-expanded",String(this.isOpen)),e.fabKbd.hidden=!this.keybind,e.fabKbd.textContent=this.keybind?Tt(this.keybind):"",e.card.hidden=!this.isOpen||this.marking,e.title.textContent=t.title,e.gear.setAttribute("aria-label",t.settings),e.gear.setAttribute("aria-pressed",String(this.view==="settings")),e.closeBtn.setAttribute("aria-label",t.close),e.describe.hidden=this.view!=="describe",e.settings.hidden=this.view!=="settings",e.sent.hidden=this.view!=="sent",e.prompt.textContent=t.prompt,e.desc.placeholder=t.placeholder,e.attachedText.textContent=t.attached(this.config?.profile.windowSec??60),e.attached.hidden=this.engine===null||this.config?.capturing===!1,e.discloseText.textContent=t.included,e.disclose.setAttribute("aria-expanded",String(this.includedOpen)),e.included.hidden=!this.includedOpen,e.included.replaceChildren(...this.includedItems().map((o)=>u("li",{},o))),e.marked.hidden=this.markers.length===0,e.markedChips.replaceChildren(...this.markers.map((o)=>u("span",{class:o.shape==="hide"?"chip hide":"chip","aria-hidden":"true"},String(o.n)))),e.markedText.textContent=t.marked(this.markers.length),e.notify.hidden=n===null,e.notifyText.textContent=t.notify,e.error.hidden=this.error==="",e.error.textContent=this.error==="create"?t.errorCreate:this.error==="capture"?t.errorCapture:"",e.whereText.textContent=t.showWhere,e.where.disabled=this.sending||Boolean(this.job?.id),e.send.textContent=this.sending?t.sending:this.error?t.retry:t.send,e.send.disabled=this.sending||e.desc.value.trim()==="",e.bindLabel.textContent=t.shortcut,e.bindBtn.setAttribute("aria-pressed",String(this.recordingBind)),e.bindBtn.setAttribute("aria-label",`${t.shortcut}: ${this.keybind?Tt(this.keybind):t.notSet} — ${t.recordShortcut}`),e.bindBtn.textContent=this.recordingBind?t.pressKeys:this.keybind?Tt(this.keybind):t.notSet,e.unbind.textContent=t.removeShortcut,e.unbind.hidden=!this.keybind||this.recordingBind,e.bindHint.textContent=t.shortcutHint,e.bindReason.hidden=!this.bindRefused,e.bindReason.textContent=this.bindRefused?t.needModifier:"",e.back.textContent=t.back,e.sentTitle.textContent=t.sentTitle,e.sentBody.textContent=this.sentNotify?t.sentNotify:t.sentBody,e.seeText.textContent=t.seeReport;let r=this.result?.reportUrl;if(e.see.hidden=!r,r)e.see.setAttribute("href",r);else e.see.removeAttribute("href");e.sentClose.textContent=t.close,e.mark.hidden=!this.marking,e.toolbar.setAttribute("aria-label",t.toolbar);for(let[o,i]of e.toolButtons)i.textContent=t.tools[o],i.setAttribute("aria-pressed",String(this.tool===o));if(e.undo.textContent=t.undo,e.undo.disabled=this.markers.length===0,e.done.textContent=t.done,e.coach.hidden=!this.marking||this.markers.length>0,e.coachText.textContent=t.coach,e.coachMore.textContent=t.coachMore,e.coachKeys.textContent=t.keyboardHint,e.mark.setAttribute("aria-label",t.marking),this.marking){for(let o of e.shapes.querySelectorAll(".veil-label"))if(o.textContent)o.textContent=t.hidden;this.renderPins()}}}function Nn(e){return ei(e).map((t,n)=>({...t,key:e[n].key}))}var Mt="vitrinka-report",Ua=["key","base","open-selector","locale","button"];function Mi(e){return e.trim().replace(/\/+$/,"")}function Bn(e){if(typeof customElements>"u"||customElements.get(Mt))return;class t extends HTMLElement{static get observedAttributes(){return Ua}options={};widget=null;pendingIdentity=void 0;connectedCallback(){this.hidden=!0,this.mountWidget()}disconnectedCallback(){this.widget?.unmount(),this.widget=null}attributeChangedCallback(n,r,o){if(r===o)return;if(!this.widget){if(this.isConnected&&(n==="key"||n==="base"))this.mountWidget();return}if(n==="locale")this.widget.setLocale(o);else if(n==="button")this.widget.setButton(o!=="false");else if(n==="open-selector")this.widget.setOpenSelector(o);else this.widget.unmount(),this.widget=null,this.mountWidget()}open(){this.widget?.open()}close(){this.widget?.close()}identify(n){this.pendingIdentity=n,this.widget?.identify(n)}setLocale(n){this.setAttribute("locale",String(n))}mountWidget(){if(this.widget)return;let n=(this.getAttribute("key")??"").trim(),r=Mi(this.getAttribute("base")??e.defaultBase());if(!n||!r){console.warn(`vitrinka: <${Mt}> needs a key${r?"":" and a base"} — nothing mounted`);return}this.widget=new On({base:r,key:n,locale:Ce(this.getAttribute("locale")),button:this.getAttribute("button")!=="false",openSelector:this.getAttribute("open-selector"),identity:this.pendingIdentity,appVersion:this.options.appVersion,capture:this.options.capture,sanitizeUrl:this.options.sanitizeUrl,loadRecord:e.loadRecord})}}customElements.define(Mt,t)}function Ci(e,t){if(e.face==="recorder")return Va(e,t);Bn(t);let n=document.createElement(Mt);if(n.setAttribute("key",e.key),e.base)n.setAttribute("base",e.base);if(e.locale)n.setAttribute("locale",String(e.locale));if(e.button===!1)n.setAttribute("button","false");if(e.openSelector)n.setAttribute("open-selector",e.openSelector);if(n.options={appVersion:e.appVersion,capture:e.capture,sanitizeUrl:e.sanitizeUrl},e.identity!==void 0)n.identify(e.identity);return(e.parent??document.body).append(n),{face:"report",open:()=>n.open(),close:()=>n.close(),identify:(r)=>n.identify(r),setLocale:(r)=>n.setLocale(r),unmount:()=>n.remove()}}function Va(e,t){let n=Mi(e.base??t.defaultBase()),r=null,o=!1;if(!t.recorderFace)console.warn("vitrinka: the recorder face needs the npm package (@vitrinka/web/report) — nothing mounted");else t.recorderFace().then((s)=>{if(!o)r=s({base:n,key:e.key,appVersion:e.appVersion,sanitizeUrl:e.sanitizeUrl})}).catch((s)=>console.warn("vitrinka: the recorder face did not load",s));let i=()=>{return};return{face:"recorder",open:i,close:i,identify:i,setLocale:i,unmount:()=>{o=!0,r?.()}}}var Ya=(()=>{try{return new URL(import.meta.url).origin}catch{return""}})();async function Xa(e){let n=await import(`${e}/vendor/rrweb-record-1.min.js`)??{},r=typeof n.default==="object"&&n.default!==null?n.default.record:void 0,o=typeof n.default==="function"?n.default:r??n.record;return typeof o==="function"?o:null}var Ii={loadRecord:Xa,recorderFace:null,defaultBase:()=>Ya};Bn(Ii);function Lc(e){return Ci(e,Ii)}export{Da as identify,Lc as mountReport};
|
|
228
|
+
`;class Ln{capture;tabHost;target;id="";custody="";sent="";blobKeys=new Map;rowsPosted=0;skipCapture=!1;constructor(e,t,n){this.capture=e;this.tabHost=t;this.target=n}async run(e){let t={target:this.target},n={title:e.title,description:e.description,markers:e.markers,notify:e.notify??!1},r=JSON.stringify(n);if(!this.id){let i=await O("POST","/api/v1/reports",e,t);if(typeof i.id!=="string"||!i.id)throw Error("vitrinka: the server filed the report without an id");this.id=i.id,this.custody=i.custody==="direct"?"direct":"quarantined",this.sent=r}else if(this.sent!==r)await O("PATCH",`/api/v1/reports/${encodeURIComponent(this.id)}`,n,t),this.sent=r;if(!this.skipCapture)try{await this.sendCapture()}catch(i){if(!(i instanceof T)||!j(i.status))throw i;console.warn("vitrinka: the server refused the recording — the report goes without it",i),this.skipCapture=!0}let o=await O("POST",`/api/v1/reports/${encodeURIComponent(this.id)}/submit`,{},t);return{status:o.status==="filed"?"filed":"quarantined",...typeof o.reportUrl==="string"&&o.reportUrl?{reportUrl:o.reportUrl}:{}}}async sendCapture(){let e=encodeURIComponent(this.id),{chunks:t,truncated:n}=this.capture;for(let o of t){if(this.blobKeys.has(o.seq))continue;let i=await Yt(`/api/v1/reports/${e}/chunk?seq=${o.seq}`,"application/json",o.body,this.target);if(!i.blobKey)throw Error(`vitrinka: chunk ${o.seq} came back without a blob key`);this.blobKeys.set(o.seq,i.blobKey)}let r=t.map((o)=>({seq:o.seq,ts:o.ts,tabHost:this.tabHost,kind:"rrweb",payload:{count:o.count,source:"replay",truncated:n},blobKey:this.blobKeys.get(o.seq)??""}));while(this.rowsPosted<r.length){let o=r.slice(this.rowsPosted,this.rowsPosted+pt);await O("POST",`/api/v1/reports/${e}/events`,{events:o},{target:this.target}),this.rowsPosted+=o.length}}}var Fa="http://www.w3.org/2000/svg",Ei=100,Ri={chunks:[],truncated:!1,console:[],network:[]},Ka=["circle","box","arrow","hide"],Dn={w:160,h:80},Ti=16,Wa={ArrowLeft:[-10,0],ArrowRight:[10,0],ArrowUp:[0,-10],ArrowDown:[0,10]},le={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>',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>',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>',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>',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>',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>'},Mi="M 134 14 C 200 14, 214 50, 134 50 C 54 50, 68 14, 134 14";function za(e){let t=e?"":`<animateMotion dur="2.8s" repeatCount="indefinite" keyPoints="0;0;1;1" keyTimes="0;0.18;0.72;1" calcMode="linear" path="${Mi}"/>`;return`<svg viewBox="0 0 268 64" aria-hidden="true"><rect class="bar" x="84" y="27" width="100" height="10" rx="5"/><path class="loop" d="${Mi}" pathLength="200"/><g class="pointer"${e?' transform="translate(134 14)"':""}><circle class="hold" r="9"/><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"/>${t}</g></svg>`}function u(e,t={},...n){let r=document.createElement(e);for(let[o,i]of Object.entries(t))r.setAttribute(o,i);return r.append(...n),r}function Q(e){let t=document.createElement("template");t.innerHTML=e;let n=t.content.firstElementChild;if(!n)throw Error("vitrinka: icon markup is empty");return n}function _(e,t){let n=document.createElementNS(Fa,e);for(let[r,o]of Object.entries(t))n.setAttribute(r,String(o));return n}function ja(e){let t=e.split(`
|
|
229
|
+
`)[0]?.trim()??"";return t.length>Ei?`${t.slice(0,Ei-1)}…`:t}function Ua(){return globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches??!1}function Ci(){let e=document.activeElement;while(e?.shadowRoot?.activeElement)e=e.shadowRoot.activeElement;if(e===document.body)return null;return e instanceof HTMLElement||e instanceof SVGElement?e:null}function Va(e){let t=u("span"),n=u("kbd"),r=u("button",{class:"fab",type:"button",part:"button","aria-haspopup":"dialog"},t,n),o=u("h2",{id:"vr-title"}),i=u("button",{class:"icon",type:"button"},Q(le.gear)),s=u("button",{class:"icon",type:"button"},Q(le.close)),a=u("header",{class:"head"},o,i,s),l=u("label",{class:"prompt",for:"vr-desc"}),d=u("textarea",{class:"desc",id:"vr-desc",rows:"3"}),g=u("span"),b=u("span"),c=u("button",{class:"link",type:"button","aria-expanded":"false","aria-controls":"vr-included"},b,Q(le.chevron)),p=u("div",{class:"attached"},Q(le.clip),g,u("span",{"aria-hidden":"true"},"·"),c),h=u("ul",{class:"included",id:"vr-included"}),k=u("span",{class:"chips"}),m=u("span"),y=u("div",{class:"marked"},k,m),f=u("input",{type:"checkbox"}),R=u("span"),D=u("label",{class:"notify"},f,R),Te=u("p",{class:"error",role:"alert"}),Ve=u("span"),Ye=u("button",{class:"where",type:"button"},Q(le.pen),Ve),Me=u("button",{class:"send",type:"button"}),Hn=u("div",{class:"pane describe"},l,d,p,h,y,D,Te,u("div",{class:"actions"},Ye,Me)),qn=u("span",{class:"label",id:"vr-bind-label"}),$n=u("button",{class:"bind",type:"button","aria-pressed":"false","aria-describedby":"vr-bind-label"}),Fn=u("button",{class:"link",type:"button"}),Kn=u("p",{class:"hint"}),Wn=u("p",{class:"reason",role:"status"}),zn=u("button",{class:"link",type:"button"}),jn=u("div",{class:"pane settings"},u("div",{class:"row"},qn,$n),Wn,Kn,u("div",{class:"settings-foot"},zn,Fn)),Un=u("h3"),Vn=u("p",{class:"sent-body"}),Yn=u("span"),Xn=u("a",{class:"see",target:"_blank",rel:"noopener noreferrer"},Yn),Gn=u("button",{class:"link",type:"button"}),Jn=u("div",{class:"pane sent",role:"status"},u("div",{class:"sent-head"},Q(le.check),Un),Vn,u("div",{class:"sent-actions"},Xn,Gn)),Zn=u("section",{class:"card",role:"dialog","aria-modal":"false","aria-labelledby":"vr-title"},a,Hn,jn,Jn),Ct=_("svg",{class:"ink","aria-hidden":"true"}),Qn=_("defs",{}),er=_("marker",{id:"vr-head",viewBox:"0 0 10 10",refX:7,refY:5,markerWidth:5,markerHeight:5,orient:"auto-start-reverse"});er.append(_("path",{d:"M0 0L10 5L0 10z",fill:"#dc2f4c"})),Qn.append(er);let tr=_("g",{}),nr=_("g",{class:"draft"});Ct.append(Qn,tr,nr);let rr=u("div",{class:"pins"}),or=u("p"),ir=u("p"),sr=u("p",{class:"keys",id:"vr-keys"}),It=u("div",{class:"coach",role:"status"});It.append(Q(za(Ua())),or,ir,sr);let At=new Map;for(let ur of Ka)At.set(ur,u("button",{type:"button","aria-pressed":"false","data-tool":ur}));let ar=u("button",{type:"button"}),lr=u("button",{type:"button",class:"done"}),cr=u("div",{class:"toolbar",role:"toolbar"},...At.values(),u("span",{class:"sep","aria-hidden":"true"}),ar,lr),Pt=u("div",{class:"mark",tabindex:"0",role:"application","aria-describedby":"vr-keys"},rr,It,cr);Pt.prepend(Ct);let _t=u("div",{class:"vr"},r,Zn,Pt),dr=u("style");return dr.textContent=Si,_t.prepend(dr),e.append(_t),{root:_t,fab:r,fabLabel:t,fabKbd:n,card:Zn,title:o,gear:i,closeBtn:s,describe:Hn,prompt:l,desc:d,attached:p,attachedText:g,disclose:c,discloseText:b,included:h,marked:y,markedChips:k,markedText:m,notify:D,notifyBox:f,notifyText:R,error:Te,where:Ye,whereText:Ve,send:Me,settings:jn,bindLabel:qn,bindBtn:$n,unbind:Fn,bindHint:Kn,bindReason:Wn,back:zn,sent:Jn,sentTitle:Un,sentBody:Vn,see:Xn,seeText:Yn,sentClose:Gn,mark:Pt,ink:Ct,shapes:tr,draft:nr,pins:rr,coach:It,coachText:or,coachMore:ir,coachKeys:sr,toolButtons:At,toolbar:cr,undo:ar,done:lr}}class On{opts;hud;engine;config=null;locale;s;button;openSelector;identity;keybind;isOpen=!1;opener=null;view="describe";marking=!1;markers=[];nextKey=1;tool="circle";frozen=null;job=null;sending=!1;error="";result=null;notify=!1;sentNotify=!1;includedOpen=!1;recordingBind=!1;bindRefused=!1;noteOpen=null;drawing=null;offs=[];pins=new Map;hideIds=new Map;dialogOrder=[...document.querySelectorAll("dialog[open]")].filter((e)=>e instanceof HTMLDialogElement);activeDialog(){this.dialogOrder=this.dialogOrder.filter((n)=>n.isConnected&&n.open);let e=(n)=>{try{return n.matches(":modal")}catch{return!1}};return[...this.dialogOrder].reverse().find(e)??this.dialogOrder.at(-1)??Wr()}sheet=null;e;constructor(e){this.opts=e;this.locale=e.locale??Nt(),this.s=Dt(this.locale),this.button=e.button,this.openSelector=e.openSelector??null,this.identity=e.identity===void 0?void 0:Et(e.identity),this.keybind=wi(),this.hud=Fr(),this.e=Va(this.hud.mount),this.engine=fi({base:e.base,key:e.key,appVersion:e.appVersion,capture:e.capture,sanitizeUrl:e.sanitizeUrl,loadRecord:e.loadRecord}),this.engine?.ready.then((t)=>{this.config=t,this.paint()}),this.bind(),this.paint(),this.followDialog()}followDialog(){let e=this.activeDialog();if((this.sheet?.target??null)===e)return;let t=this.e.root.getRootNode(),n=t instanceof ShadowRoot&&t.activeElement instanceof HTMLElement?t.activeElement:null,r=this.sheet;if(e){let o=zr(e);o.mount.append(this.e.root),this.sheet={target:e,host:o}}else this.hud.mount.append(this.e.root),this.sheet=null;r?.host.destroy(),n?.focus()}open(){if(this.isOpen)return;if(this.isOpen=!0,this.opener=jr(document.activeElement)?null:Ci(),this.view!=="describe")this.view="describe";if(this.result=null,!this.job)this.frozen=this.engine?.freeze()??null;this.paint(),requestAnimationFrame(()=>this.e.desc.focus())}close(){if(!this.isOpen)return;if(this.marking)this.endMarking(!1);this.stopRecordingBind(),this.isOpen=!1,this.view="describe",this.paint();let e=this.opener;if(this.opener=null,e?.focus(),e&&Ci()===e)return;if(this.button)this.e.fab.focus()}setLocale(e){let t=Ce(e)??Nt();if(t===this.locale)return;this.locale=t,this.s=Dt(t),this.paint()}setButton(e){this.button=e,this.paint()}setOpenSelector(e){this.openSelector=e||null}identify(e){this.identity=e===void 0?void 0:Et(e),this.paint()}unmount(){this.stopRecordingBind();for(let e of this.offs.splice(0).reverse())e();hi(this.engine),this.sheet?.host.destroy(),this.sheet=null,this.hud.destroy()}bind(){let e=this.e,t=(o,i,s)=>{o.addEventListener(i,s)};t(e.fab,"click",()=>this.isOpen?this.close():this.open()),t(e.closeBtn,"click",()=>this.close()),t(e.gear,"click",()=>this.show(this.view==="settings"?"describe":"settings")),t(e.back,"click",()=>this.show("describe")),t(e.sentClose,"click",()=>this.close()),t(e.desc,"input",()=>this.paint()),t(e.disclose,"click",()=>{this.includedOpen=!this.includedOpen,this.paint()}),t(e.notifyBox,"change",()=>{this.notify=e.notifyBox.checked}),t(e.where,"click",()=>this.startMarking()),t(e.send,"click",()=>void this.send()),t(e.bindBtn,"click",()=>this.recordingBind?this.stopRecordingBind():this.startRecordingBind()),t(e.unbind,"click",()=>{this.keybind=null,_n(null),this.paint()}),t(e.card,"keydown",(o)=>{if(o.key!=="Escape"||this.recordingBind)return;if(o.preventDefault(),this.view==="settings")this.show("describe");else this.close()});for(let[o,i]of e.toolButtons)t(i,"click",(s)=>{if(this.tool=o,this.renderKbDraft(),this.paint(),s.detail===0)e.mark.focus()});if(t(e.mark,"keydown",(o)=>this.markKey(o)),t(e.undo,"click",()=>{this.markers=Nn(this.markers.slice(0,-1)),this.renderMarks(),this.paint()}),t(e.done,"click",()=>this.endMarking(!0)),t(e.mark,"pointerdown",(o)=>this.pointerDown(o)),t(e.mark,"pointermove",(o)=>this.pointerMove(o)),t(e.mark,"pointerup",(o)=>this.pointerUp(o)),t(e.mark,"pointercancel",()=>this.cancelDraft()),this.offs.push(N(e.mark,"wheel",(o)=>o.preventDefault())),this.offs.push(N(e.mark,"touchmove",(o)=>o.preventDefault())),this.offs.push(N(window,"keydown",(o)=>{if(this.recordingBind)return;if(this.marking&&o.key==="Escape"){if(o.preventDefault(),this.kbDraft)this.cancelDraft();else this.endMarking(!0);return}if(this.keybind&&ki(o,this.keybind))if(o.preventDefault(),this.isOpen)this.close();else this.open()},{capture:!0})),this.offs.push(N(document,"click",(o)=>{let i=this.openSelector,s=o.target;if(!i||!(s instanceof Element))return;let a=null;try{a=s.closest(i)}catch{return}if(!a)return;o.preventDefault(),this.open()})),this.offs.push(xi((o)=>{this.keybind=o,this.paint()})),this.offs.push(bi(()=>this.paint())),this.engine)this.offs.push(this.engine.onChange(()=>this.paint()));let n=0,r=new MutationObserver((o)=>{for(let i of o){if(i.type!=="attributes"||i.attributeName!=="open"||!(i.target instanceof HTMLDialogElement))continue;let s=i.target;if(!s.open)this.dialogOrder=this.dialogOrder.filter((a)=>a!==s);else if(i.oldValue===null)this.dialogOrder=[...this.dialogOrder.filter((a)=>a!==s),s]}if(n)return;n=requestAnimationFrame(()=>{n=0,this.followDialog()})});r.observe(document.documentElement,{subtree:!0,childList:!0,attributes:!0,attributeOldValue:!0,attributeFilter:["open","data-state"]}),this.offs.push(()=>{if(r.disconnect(),n)cancelAnimationFrame(n)})}show(e){if(this.stopRecordingBind(),this.view=e,this.paint(),e==="describe")requestAnimationFrame(()=>this.e.desc.focus());if(e==="settings")requestAnimationFrame(()=>this.e.bindBtn.focus())}who(){return this.identity!==void 0?this.identity:mi()}stopBindListener=null;startRecordingBind(){this.recordingBind=!0,this.bindRefused=!1,this.stopBindListener=N(window,"keydown",(e)=>{e.preventDefault(),e.stopPropagation();let t=yi(e);if(t.kind==="wait")return;if(t.kind==="bare"){this.bindRefused=!0,this.paint();return}if(t.kind==="bind")this.keybind=t.bind,_n(t.bind);this.stopRecordingBind()},{capture:!0}),this.paint()}stopRecordingBind(){if(!this.recordingBind)return;this.recordingBind=!1,this.bindRefused=!1,this.stopBindListener?.(),this.stopBindListener=null,this.paint()}startMarking(){if(this.job?.id)return;this.marking=!0,this.noteOpen=null,this.renderMarks(),this.paint();let e=globalThis.innerWidth||800,t=globalThis.innerHeight||600;this.placeCoach({x:e/2-150,y:t-260},!1),this.e.mark.focus()}endMarking(e){if(this.cancelDraft(),this.marking=!1,this.noteOpen=null,this.paint(),e&&this.isOpen)requestAnimationFrame(()=>this.e.desc.focus())}onChrome(e){return e instanceof Node&&(this.e.toolbar.contains(e)||this.e.pins.contains(e))}pointerDown(e){if(this.onChrome(e.target)||e.button!==0||!e.isPrimary)return;e.preventDefault();let t=this.e.root.getRootNode();if(t instanceof ShadowRoot&&t.activeElement instanceof HTMLElement)t.activeElement.blur();this.noteOpen=null,this.drawing={start:{x:e.clientX,y:e.clientY},shape:this.tool,pointer:e.pointerId};try{this.e.mark.setPointerCapture(e.pointerId)}catch{}this.e.coach.classList.add("pressing"),this.renderPins()}pointerMove(e){if(!this.markers.length)this.placeCoach({x:e.clientX,y:e.clientY},!0);let t=this.drawing;if(!t||e.pointerId!==t.pointer)return;this.e.draft.replaceChildren(...this.shapeNodes({shape:t.shape,rect:Rn(t.start,{x:e.clientX,y:e.clientY}),head:Tn(t.start,{x:e.clientX,y:e.clientY})}))}pointerUp(e){let t=this.drawing;if(!t||e.pointerId!==t.pointer)return;let n={x:e.clientX,y:e.clientY};if(this.cancelDraft(),!ei(t.shape,t.start,n))return;this.addMarker(t.shape,Rn(t.start,n),t.shape==="arrow"?Tn(t.start,n):void 0)}addMarker(e,t,n){let r=this.nextKey++;if(e==="hide"){let o=this.engine?.hiddenIdsAt(t);if(o)this.hideIds.set(r,o)}this.markers=Nn([...this.markers,{key:r,n:this.markers.length+1,shape:e,rect:t,note:"",...n?{head:n}:{}}]),this.noteOpen=r,this.renderMarks(),this.paint(),this.pins.get(r)?.note.focus()}cancelDraft(){this.drawing=null,this.kbDraft=null,this.e.draft.replaceChildren(),this.e.coach.classList.remove("pressing")}kbDraft=null;markKey(e){if(e.target!==this.e.mark)return;let t=globalThis.innerWidth||800,n=globalThis.innerHeight||600;if(e.key==="Enter"||e.key===" "){if(e.preventDefault(),!this.kbDraft){this.kbDraft={x:Math.round(t/2-Dn.w/2),y:Math.round(n/2-Dn.h/2),...Dn},this.renderKbDraft();return}let a=this.kbDraft;this.cancelDraft(),this.addMarker(this.tool,a,this.tool==="arrow"?"se":void 0);return}let r=Wa[e.key];if(!r||!this.kbDraft)return;e.preventDefault();let o=this.kbDraft,[i,s]=r;this.kbDraft=e.shiftKey?{...o,w:Math.min(t-o.x,Math.max(Ti,o.w+i)),h:Math.min(n-o.y,Math.max(Ti,o.h+s))}:{...o,x:Math.min(t-o.w,Math.max(0,o.x+i)),y:Math.min(n-o.h,Math.max(0,o.y+s))},this.renderKbDraft()}renderKbDraft(){let e=this.kbDraft;if(!e)return;this.e.draft.replaceChildren(...this.shapeNodes({shape:this.tool,rect:e,head:"se"}))}placeCoach(e,t){let n=globalThis.innerWidth||800,r=globalThis.innerHeight||600,o=this.e.coach.offsetWidth||300,i=this.e.coach.offsetHeight||140,s=t?e.x+20:e.x,a=t?e.y+20:e.y;if(s+o>n-8)s=t?e.x-o-20:n-o-8;if(a+i>r-90)a=t?e.y-i-20:r-i-90;this.e.coach.style.left=`${Math.max(8,s)}px`,this.e.coach.style.top=`${Math.max(8,a)}px`}shapeNodes(e){let{x:t,y:n,w:r,h:o}=e.rect;if(e.shape==="circle")return[_("ellipse",{class:"stroke",cx:t+r/2,cy:n+o/2,rx:Math.max(1,r/2),ry:Math.max(1,o/2)})];if(e.shape==="box")return[_("rect",{class:"stroke",x:t,y:n,width:r,height:o,rx:6})];if(e.shape==="arrow"){let{tail:a,tip:l}=Mn(e.rect,e.head??"se");return[_("line",{class:"stroke",x1:a.x,y1:a.y,x2:l.x,y2:l.y,"marker-end":"url(#vr-head)"})]}let i=_("rect",{class:"veil",x:t,y:n,width:r,height:o,rx:4}),s=_("text",{class:"veil-label",x:t+r/2,y:n+o/2+4,"text-anchor":"middle"});return s.textContent=r>60&&o>20?this.s.hidden:"",[i,s]}renderMarks(){this.e.shapes.replaceChildren(...this.markers.flatMap((t)=>this.shapeNodes(t)));let e=new Set(this.markers.map((t)=>t.key));for(let[t,n]of this.pins){if(e.has(t))continue;n.el.remove(),this.pins.delete(t)}for(let t of this.markers){if(this.pins.has(t.key))continue;let n=u("button",{class:"num",type:"button"}),r=u("input",{class:"note",type:"text",maxlength:"500"}),o=u("button",{class:"rm",type:"button"},Q(le.close)),i=u("div",{class:"pin"},n,r,o);n.addEventListener("click",()=>{this.noteOpen=t.key,this.renderPins(),r.focus()}),r.addEventListener("input",()=>{this.markers=this.markers.map((s)=>s.key===t.key?{...s,note:r.value}:s)}),r.addEventListener("focus",()=>{this.noteOpen=t.key,this.renderPins()}),r.addEventListener("keydown",(s)=>{if(s.key!=="Enter")return;s.preventDefault(),this.e.mark.focus()}),o.addEventListener("click",()=>{this.markers=Nn(this.markers.filter((s)=>s.key!==t.key)),this.renderMarks(),this.paint()}),this.e.pins.append(i),this.pins.set(t.key,{el:i,num:n,note:r,rm:o})}this.renderPins()}renderPins(){let e=globalThis.innerWidth||800;for(let t of this.markers){let n=this.pins.get(t.key);if(!n)continue;let r=t.shape==="arrow"?Mn(t.rect,t.head??"se").tail:{x:t.rect.x,y:t.rect.y},o=this.noteOpen===t.key||t.note.trim()!=="",i=o?290:30;n.el.style.left=`${Math.min(Math.max(4,r.x-12),e-i)}px`,n.el.style.top=`${Math.max(4,r.y-12)}px`,n.num.textContent=String(t.n),n.num.setAttribute("aria-label",this.s.mark(t.n)),n.note.hidden=!o,n.rm.hidden=!o,n.note.placeholder=this.s.notePlaceholder,n.note.setAttribute("aria-label",`${this.s.mark(t.n)} — ${this.s.notePlaceholder}`),n.rm.setAttribute("aria-label",this.s.removeMark(t.n))}}envelope(e,t){let n=this.who(),r=globalThis.location;return{title:ja(e),description:e,env:{url:te(r?`${r.origin}${r.pathname}`:""),ua:globalThis.navigator?.userAgent??"",viewport:{w:globalThis.innerWidth||0,h:globalThis.innerHeight||0,dpr:globalThis.devicePixelRatio||1},appVersion:this.opts.appVersion??"",locale:globalThis.navigator?.language??""},console:t.console,network:t.network,...n?{identity:n,notify:this.notify}:{},markers:ni(this.markers),locale:this.locale}}async send(){let e=this.e.desc.value.trim();if(this.sending||!e)return;if(this.sending=!0,this.error="",this.paint(),this.job&&!this.job.id)this.job=null;try{if(!this.job){let t=new Set;for(let r of this.markers)for(let o of this.hideIds.get(r.key)??[])t.add(o);let n=this.engine?await this.engine.build(this.frozen??{clip:null,stored:Promise.resolve(new Map)},this.markers,t).catch((r)=>(console.warn("vitrinka: the capture could not be prepared — the report goes without it",r),Ri)):Ri;this.job=new Ln(n,globalThis.location?.host??"",{url:this.opts.base,key:this.opts.key})}this.result=await this.job.run(this.envelope(e,this.job.capture)),this.sentNotify=this.notify&&this.who()!==null,this.view="sent",this.job=null,this.frozen=null,this.e.desc.value="",this.markers=[],this.hideIds.clear(),this.notify=!1,this.e.notifyBox.checked=!1,this.includedOpen=!1,this.renderMarks(),this.engine?.clear()}catch(t){console.warn("vitrinka: the report did not go through — Retry resumes it",t),this.error=this.job?.id?"capture":"create"}finally{this.sending=!1,this.paint()}if(this.view==="sent")requestAnimationFrame(()=>((this.result?.reportUrl)?this.e.see:this.e.sentClose).focus())}includedItems(){let e=this.s,t=[],n=this.config?.lanes;if(n?.replay)t.push(`${e.incReplay} — ${e.incReplayMasked[this.config?.masking??"strict"].toLowerCase()}`);if(n?.errors)t.push(e.incErrors);if(n?.console)t.push(e.incConsole);if(n?.network)t.push(e.incNetwork);else if(n?.errors)t.push(e.incFailedRequests);if(t.push(e.incEnv),this.who())t.push(e.incIdentity);if(this.markers.length)t.push(e.incMarks);return t}paint(){let{e,s:t}=this,n=this.who();e.root.setAttribute("lang",this.locale),e.root.classList.toggle("nobutton",!this.button),e.fab.hidden=!this.button||this.marking,e.fabLabel.textContent=t.button,e.fab.setAttribute("aria-expanded",String(this.isOpen)),e.fabKbd.hidden=!this.keybind,e.fabKbd.textContent=this.keybind?Tt(this.keybind):"",e.card.hidden=!this.isOpen||this.marking,e.title.textContent=t.title,e.gear.setAttribute("aria-label",t.settings),e.gear.setAttribute("aria-pressed",String(this.view==="settings")),e.closeBtn.setAttribute("aria-label",t.close),e.describe.hidden=this.view!=="describe",e.settings.hidden=this.view!=="settings",e.sent.hidden=this.view!=="sent",e.prompt.textContent=t.prompt,e.desc.placeholder=t.placeholder,e.attachedText.textContent=t.attached(this.config?.profile.windowSec??60),e.attached.hidden=this.engine===null||this.config?.capturing===!1,e.discloseText.textContent=t.included,e.disclose.setAttribute("aria-expanded",String(this.includedOpen)),e.included.hidden=!this.includedOpen,e.included.replaceChildren(...this.includedItems().map((o)=>u("li",{},o))),e.marked.hidden=this.markers.length===0,e.markedChips.replaceChildren(...this.markers.map((o)=>u("span",{class:o.shape==="hide"?"chip hide":"chip","aria-hidden":"true"},String(o.n)))),e.markedText.textContent=t.marked(this.markers.length),e.notify.hidden=n===null,e.notifyText.textContent=t.notify,e.error.hidden=this.error==="",e.error.textContent=this.error==="create"?t.errorCreate:this.error==="capture"?t.errorCapture:"",e.whereText.textContent=t.showWhere,e.where.disabled=this.sending||Boolean(this.job?.id),e.send.textContent=this.sending?t.sending:this.error?t.retry:t.send,e.send.disabled=this.sending||e.desc.value.trim()==="",e.bindLabel.textContent=t.shortcut,e.bindBtn.setAttribute("aria-pressed",String(this.recordingBind)),e.bindBtn.setAttribute("aria-label",`${t.shortcut}: ${this.keybind?Tt(this.keybind):t.notSet} — ${t.recordShortcut}`),e.bindBtn.textContent=this.recordingBind?t.pressKeys:this.keybind?Tt(this.keybind):t.notSet,e.unbind.textContent=t.removeShortcut,e.unbind.hidden=!this.keybind||this.recordingBind,e.bindHint.textContent=t.shortcutHint,e.bindReason.hidden=!this.bindRefused,e.bindReason.textContent=this.bindRefused?t.needModifier:"",e.back.textContent=t.back,e.sentTitle.textContent=t.sentTitle,e.sentBody.textContent=this.sentNotify?t.sentNotify:t.sentBody,e.seeText.textContent=t.seeReport;let r=this.result?.reportUrl;if(e.see.hidden=!r,r)e.see.setAttribute("href",r);else e.see.removeAttribute("href");e.sentClose.textContent=t.close,e.mark.hidden=!this.marking,e.toolbar.setAttribute("aria-label",t.toolbar);for(let[o,i]of e.toolButtons)i.textContent=t.tools[o],i.setAttribute("aria-pressed",String(this.tool===o));if(e.undo.textContent=t.undo,e.undo.disabled=this.markers.length===0,e.done.textContent=t.done,e.coach.hidden=!this.marking||this.markers.length>0,e.coachText.textContent=t.coach,e.coachMore.textContent=t.coachMore,e.coachKeys.textContent=t.keyboardHint,e.mark.setAttribute("aria-label",t.marking),this.marking){for(let o of e.shapes.querySelectorAll(".veil-label"))if(o.textContent)o.textContent=t.hidden;this.renderPins()}}}function Nn(e){return ti(e).map((t,n)=>({...t,key:e[n].key}))}var Mt="vitrinka-report",Ya=["key","base","open-selector","locale","button"];function Ii(e){return e.trim().replace(/\/+$/,"")}function Bn(e){if(typeof customElements>"u"||customElements.get(Mt))return;class t extends HTMLElement{static get observedAttributes(){return Ya}options={};widget=null;pendingIdentity=void 0;connectedCallback(){this.hidden=!0,this.mountWidget()}disconnectedCallback(){this.widget?.unmount(),this.widget=null}attributeChangedCallback(n,r,o){if(r===o)return;if(!this.widget){if(this.isConnected&&(n==="key"||n==="base"))this.mountWidget();return}if(n==="locale")this.widget.setLocale(o);else if(n==="button")this.widget.setButton(o!=="false");else if(n==="open-selector")this.widget.setOpenSelector(o);else this.widget.unmount(),this.widget=null,this.mountWidget()}open(){this.widget?.open()}close(){this.widget?.close()}identify(n){this.pendingIdentity=n,this.widget?.identify(n)}setLocale(n){this.setAttribute("locale",String(n))}mountWidget(){if(this.widget)return;let n=(this.getAttribute("key")??"").trim(),r=Ii(this.getAttribute("base")??e.defaultBase());if(!n||!r){console.warn(`vitrinka: <${Mt}> needs a key${r?"":" and a base"} — nothing mounted`);return}this.widget=new On({base:r,key:n,locale:Ce(this.getAttribute("locale")),button:this.getAttribute("button")!=="false",openSelector:this.getAttribute("open-selector"),identity:this.pendingIdentity,appVersion:this.options.appVersion,capture:this.options.capture,sanitizeUrl:this.options.sanitizeUrl,loadRecord:e.loadRecord})}}customElements.define(Mt,t)}function Ai(e,t){if(e.face==="recorder")return Xa(e,t);Bn(t);let n=document.createElement(Mt);if(n.setAttribute("key",e.key),e.base)n.setAttribute("base",e.base);if(e.locale)n.setAttribute("locale",String(e.locale));if(e.button===!1)n.setAttribute("button","false");if(e.openSelector)n.setAttribute("open-selector",e.openSelector);if(n.options={appVersion:e.appVersion,capture:e.capture,sanitizeUrl:e.sanitizeUrl},e.identity!==void 0)n.identify(e.identity);return(e.parent??document.body).append(n),{face:"report",open:()=>n.open(),close:()=>n.close(),identify:(r)=>n.identify(r),setLocale:(r)=>n.setLocale(r),unmount:()=>n.remove()}}function Xa(e,t){let n=Ii(e.base??t.defaultBase()),r=null,o=!1;if(!t.recorderFace)console.warn("vitrinka: the recorder face needs the npm package (@vitrinka/web/report) — nothing mounted");else t.recorderFace().then((s)=>{if(!o)r=s({base:n,key:e.key,appVersion:e.appVersion,sanitizeUrl:e.sanitizeUrl})}).catch((s)=>console.warn("vitrinka: the recorder face did not load",s));let i=()=>{return};return{face:"recorder",open:i,close:i,identify:i,setLocale:i,unmount:()=>{o=!0,r?.()}}}var Ga=(()=>{try{return new URL(import.meta.url).origin}catch{return""}})();async function Ja(e){let n=await import(`${e}/vendor/rrweb-record-1.min.js`)??{},r=typeof n.default==="object"&&n.default!==null?n.default.record:void 0,o=typeof n.default==="function"?n.default:r??n.record;return typeof o==="function"?o:null}var Pi={loadRecord:Ja,recorderFace:null,defaultBase:()=>Ga};Bn(Pi);function Nc(e){return Ai(e,Pi)}export{Oa as identify,Nc as mountReport};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitrinka/web",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "vitrinka toolkit for React DOM apps — the journey recorder (capture manual-testing sessions: rrweb DOM stream, clicks, navigation, network, console, notes) and Report a problem (a reporter's button, marks and the last minutes, cs/en), straight into vitrinka.",
|
|
5
5
|
"license": "Elastic-2.0",
|
|
6
6
|
"repository": {
|