@vitrinka/web 0.8.0 → 0.8.2

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/build/one.iife.js CHANGED
@@ -1 +1 @@
1
- (()=>{var{defineProperty:E,getOwnPropertyNames:z,getOwnPropertyDescriptor:K}=Object,B=Object.prototype.hasOwnProperty;function j(e){return this[e]}var G=(e)=>{var n=(S??=new WeakMap).get(e),t;if(n)return n;if(n=E({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var o of z(e))if(!B.call(n,o))E(n,o,{get:j.bind(e,o),enumerable:!(t=K(e,o))||t.enumerable})}return S.set(e,n),n},S;var J=(e)=>e;function W(e,n){this[e]=J.bind(null,n)}var F=(e,n)=>{for(var t in n)E(e,t,{get:n[t],enumerable:!0,configurable:!0,set:W.bind(n,t)})};var cn={};var _={};F(_,{ACK_EVENT:()=>C,COMMAND_EVENT:()=>x,HELLO_EVENT:()=>c,LEAD_ATTR:()=>l,ONE_VERSION:()=>u,PAGE_ATTR:()=>d,announce:()=>H,answeredBy:()=>D,ask:()=>M,documentEnv:()=>Z,holderAnswers:()=>V,isLive:()=>k,markPage:()=>rn,nonce:()=>h,pageMarked:()=>an,parseAck:()=>N,parseClaim:()=>L,parseCommand:()=>P,parseHello:()=>A,readClaim:()=>b,releaseClaim:()=>tn,sendCommand:()=>ln,serializeClaim:()=>I,serveCommands:()=>dn,serveHello:()=>un,takeClaim:()=>nn,unmarkPage:()=>sn,updateClaim:()=>en,watchClaim:()=>on});function w(e,n,t,o={}){let i=e,r=i.__zone_symbol__addEventListener??e.addEventListener,a=i.__zone_symbol__removeEventListener??e.removeEventListener,m=o.capture??!1;return r.call(e,n,t,{capture:m,passive:!1}),()=>a.call(e,n,t,m)}var u=1,d="data-vitrinka-page",l="data-vitrinka-lead",c="vitrinka:hello",x="vitrinka:command",C="vitrinka:ack";function Z(){let n=globalThis.document?.documentElement;if(!n||typeof globalThis.dispatchEvent!=="function")return null;return{root:n,bus:globalThis}}function h(e){return`${e}.${Math.random().toString(36).slice(2,10)}`}var q=["page","extension"],Q=["starting","recording","paused","stopping","saved"],U=["pause","stop","note"],X=["not_recording","stopping","not_here","bad_command"];function v(e){if(typeof e!=="string")return null;try{let n=JSON.parse(e);return n!==null&&typeof n==="object"&&!Array.isArray(n)?n:null}catch{return null}}var s=(e)=>typeof e==="string",f=(e)=>s(e)&&q.includes(e),T=(e)=>s(e)&&Q.includes(e),g=(e)=>typeof e==="number"&&Number.isInteger(e)&&e>=1;function L(e){let n=v(e);if(!n||!g(n.v)||!f(n.by)||!s(n.id)||!n.id||!T(n.state))return null;return{v:n.v,by:n.by,id:n.id,state:n.state,sessionId:s(n.sessionId)?n.sessionId:Number.isFinite(n.sessionId)?String(n.sessionId):"",since:typeof n.since==="number"?n.since:0}}function I(e){return JSON.stringify({v:e.v,by:e.by,id:e.id,state:e.state,sessionId:e.sessionId,since:e.since})}function k(e){return e!==void 0&&e!==null&&e!=="saved"}function Y(e){if(e===null||typeof e!=="object"||Array.isArray(e))return null;let n=e;if(!f(n.by)||!T(n.state))return null;return{by:n.by,state:n.state,here:n.here===!0,...s(n.id)&&n.id?{id:n.id}:{}}}function A(e){let n=v(e);if(!n||!g(n.v)||!f(n.from)||!s(n.inst)||!n.inst)return null;let t=Y(n.live);return{v:n.v,from:n.from,inst:n.inst,...n.ask===!0?{ask:!0}:{},...n.live!==void 0?{live:t}:{},...n.gone===!0?{gone:!0}:{}}}function P(e){let n=v(e);if(!n||!g(n.v)||!f(n.from)||!s(n.inst)||!n.inst||!s(n.id)||!n.id)return null;if(!s(n.op)||!U.includes(n.op))return null;return{v:n.v,from:n.from,inst:n.inst,id:n.id,op:n.op,...s(n.text)?{text:n.text}:{}}}function N(e){let n=v(e);if(!n||!g(n.v)||!f(n.from)||!s(n.inst)||!s(n.id)||typeof n.ok!=="boolean")return null;return{v:n.v,from:n.from,inst:n.inst,id:n.id,ok:n.ok,...s(n.code)&&X.includes(n.code)?{code:n.code}:{},...s(n.error)?{error:n.error}:{}}}function b(e){return L(e.root.getAttribute(l))}function R(e,n){let t=I(n);if(e.root.getAttribute(l)!==t)e.root.setAttribute(l,t)}function nn(e,n,t){let o=b(e);if(o&&o.id!==t.id&&k(o.state)&&V(e,n,o))return{ok:!1,holder:o};let i={v:u,by:n.from,id:t.id,state:t.state,sessionId:t.sessionId??"",since:o?.id===t.id&&k(o.state)?o.since:Date.now()};return R(e,i),{ok:!0,claim:i}}function en(e,n,t){let o=b(e);if(o?.id!==n)return!1;return R(e,{...o,v:u,state:t.state,sessionId:t.sessionId??o.sessionId}),!0}function tn(e,n){if(b(e)?.id!==n)return!1;return e.root.removeAttribute(l),!0}function on(e,n){if(e.watch)return e.watch(n);if(typeof MutationObserver!=="function"||typeof Node>"u"||!(e.root instanceof Node))return()=>{return};let t=new MutationObserver(n);return t.observe(e.root,{attributes:!0,attributeFilter:[l]}),()=>t.disconnect()}function rn(e,n){if(e.root.getAttribute(d)!==n)e.root.setAttribute(d,n)}function sn(e){e.root.removeAttribute(d)}function an(e){return e.root.getAttribute(d)!==null}function y(e,n,t){e.bus.dispatchEvent(new CustomEvent(n,{detail:JSON.stringify(t)}))}function O(e,n,t){return w(e.bus,n,(o)=>t(o.detail))}function M(e,n){let t=[],o=O(e,c,(i)=>{let r=A(i);if(r&&!r.ask&&r.inst!==n.inst)t.push(r)});try{y(e,c,{v:u,from:n.from,inst:n.inst,ask:!0})}finally{o()}return t}function H(e,n,t,o={}){y(e,c,{v:u,from:n.from,inst:n.inst,live:t,...o.gone?{gone:!0}:{}})}function un(e,n,t,o,i={}){return O(e,c,(r)=>{let a=A(r);if(!a||a.inst===n.inst)return;if(!a.ask)o?.(a);else if(i.answerIf?.()??!0)H(e,n,t())})}function D(e,n){return e.some((t)=>t.live?.here===!0&&(t.live.id?t.live.id===n.id:t.from===n.by))}function V(e,n,t){return D(M(e,n),t)}function ln(e,n,t,o){let i=h("c"),r=null,a=O(e,C,(m)=>{let p=N(m);if(p&&p.id===i&&p.inst!==n.inst&&!r)r=p});try{y(e,x,{v:u,from:n.from,inst:n.inst,id:i,op:t,...o!==void 0?{text:o}:{}})}finally{a()}return r}function dn(e,n,t){return O(e,x,(o)=>{let i=P(o);if(!i||i.inst===n.inst)return;let r=t(i);if(!r)return;y(e,C,{v:u,from:n.from,inst:n.inst,id:i.id,...r})})}globalThis.VitrinkaOne=Object.freeze({..._});})();
1
+ (()=>{var{defineProperty:H,getOwnPropertyNames:w,getOwnPropertyDescriptor:d}=Object,p=Object.prototype.hasOwnProperty;function E(k){return this[k]}var f=(k)=>{var j=(x??=new WeakMap).get(k),q;if(j)return j;if(j=H({},"__esModule",{value:!0}),k&&typeof k==="object"||typeof k==="function"){for(var F of w(k))if(!p.call(j,F))H(j,F,{get:E.bind(k,F),enumerable:!(q=d(k,F))||q.enumerable})}return x.set(k,j),j},x;var c=(k)=>k;function b(k,j){this[k]=c.bind(null,j)}var l=(k,j)=>{for(var q in j)H(k,q,{get:j[q],enumerable:!0,configurable:!0,set:b.bind(j,q)})};var Yj={};var g={};l(g,{watchClaim:()=>qj,updateClaim:()=>jj,unmarkPage:()=>Jj,takeClaim:()=>e,serveHello:()=>Uj,serveCommands:()=>Xj,serializeClaim:()=>o,sendCommand:()=>Wj,releaseClaim:()=>kj,readClaim:()=>P,parseHello:()=>S,parseCommand:()=>i,parseClaim:()=>y,parseAck:()=>N,pageMarked:()=>Qj,nonce:()=>L,markPage:()=>Fj,isLive:()=>I,holderAnswers:()=>h,documentEnv:()=>s,ask:()=>_,answeredBy:()=>A,announce:()=>T,PAGE_ATTR:()=>Z,ONE_VERSION:()=>X,LEAD_ATTR:()=>Y,HELLO_EVENT:()=>$,COMMAND_EVENT:()=>u,ACK_EVENT:()=>C});function O(k,j,q,F={}){let J=k,Q=J.__zone_symbol__addEventListener??k.addEventListener,W=J.__zone_symbol__removeEventListener??k.removeEventListener,z=F.capture??!1;return Q.call(k,j,q,{capture:z,passive:!1}),()=>W.call(k,j,q,z)}var X=1,Z="data-vitrinka-page",Y="data-vitrinka-lead",$="vitrinka:hello",u="vitrinka:command",C="vitrinka:ack";function s(){let j=globalThis.document?.documentElement;if(!j||typeof globalThis.dispatchEvent!=="function")return null;return{root:j,bus:globalThis}}function L(k){return`${k}.${Math.random().toString(36).slice(2,10)}`}var t=["page","extension"],a=["starting","recording","paused","stopping","saved"],n=["pause","stop","note"],v=["not_recording","stopping","not_here","bad_command"];function K(k){if(typeof k!=="string")return null;try{let j=JSON.parse(k);return j!==null&&typeof j==="object"&&!Array.isArray(j)?j:null}catch{return null}}var U=(k)=>typeof k==="string",B=(k)=>U(k)&&t.includes(k),R=(k)=>U(k)&&a.includes(k),M=(k)=>typeof k==="number"&&Number.isInteger(k)&&k>=1;function y(k){let j=K(k);if(!j||!M(j.v)||!B(j.by)||!U(j.id)||!j.id||!R(j.state))return null;return{v:j.v,by:j.by,id:j.id,state:j.state,sessionId:U(j.sessionId)?j.sessionId:Number.isFinite(j.sessionId)?String(j.sessionId):"",since:typeof j.since==="number"?j.since:0}}function o(k){return JSON.stringify({v:k.v,by:k.by,id:k.id,state:k.state,sessionId:k.sessionId,since:k.since})}function I(k){return k!==void 0&&k!==null&&k!=="saved"}function r(k){if(k===null||typeof k!=="object"||Array.isArray(k))return null;let j=k;if(!B(j.by)||!R(j.state))return null;return{by:j.by,state:j.state,here:j.here===!0,...U(j.id)&&j.id?{id:j.id}:{}}}function S(k){let j=K(k);if(!j||!M(j.v)||!B(j.from)||!U(j.inst)||!j.inst)return null;let q=r(j.live);return{v:j.v,from:j.from,inst:j.inst,...j.ask===!0?{ask:!0}:{},...j.live!==void 0?{live:q}:{},...j.gone===!0?{gone:!0}:{}}}function i(k){let j=K(k);if(!j||!M(j.v)||!B(j.from)||!U(j.inst)||!j.inst||!U(j.id)||!j.id)return null;if(!U(j.op)||!n.includes(j.op))return null;return{v:j.v,from:j.from,inst:j.inst,id:j.id,op:j.op,...U(j.text)?{text:j.text}:{}}}function N(k){let j=K(k);if(!j||!M(j.v)||!B(j.from)||!U(j.inst)||!U(j.id)||typeof j.ok!=="boolean")return null;return{v:j.v,from:j.from,inst:j.inst,id:j.id,ok:j.ok,...U(j.code)&&v.includes(j.code)?{code:j.code}:{},...U(j.error)?{error:j.error}:{}}}function P(k){return y(k.root.getAttribute(Y))}function m(k,j){let q=o(j);if(k.root.getAttribute(Y)!==q)k.root.setAttribute(Y,q)}function e(k,j,q){let F=P(k);if(F&&F.id!==q.id&&I(F.state)&&h(k,j,F))return{ok:!1,holder:F};let J={v:X,by:j.from,id:q.id,state:q.state,sessionId:q.sessionId??"",since:F?.id===q.id&&I(F.state)?F.since:Date.now()};return m(k,J),{ok:!0,claim:J}}function jj(k,j,q){let F=P(k);if(F?.id!==j)return!1;return m(k,{...F,v:X,state:q.state,sessionId:q.sessionId??F.sessionId}),!0}function kj(k,j){if(P(k)?.id!==j)return!1;return k.root.removeAttribute(Y),!0}function qj(k,j){if(k.watch)return k.watch(j);if(typeof MutationObserver!=="function"||typeof Node>"u"||!(k.root instanceof Node))return()=>{return};let q=new MutationObserver(j);return q.observe(k.root,{attributes:!0,attributeFilter:[Y]}),()=>q.disconnect()}function Fj(k,j){if(k.root.getAttribute(Z)!==j)k.root.setAttribute(Z,j)}function Jj(k){k.root.removeAttribute(Z)}function Qj(k){return k.root.getAttribute(Z)!==null}function V(k,j,q){k.bus.dispatchEvent(new CustomEvent(j,{detail:JSON.stringify(q)}))}function D(k,j,q){return O(k.bus,j,(F)=>q(F.detail))}function _(k,j){let q=[],F=D(k,$,(J)=>{let Q=S(J);if(Q&&!Q.ask&&Q.inst!==j.inst)q.push(Q)});try{V(k,$,{v:X,from:j.from,inst:j.inst,ask:!0})}finally{F()}return q}function T(k,j,q,F={}){V(k,$,{v:X,from:j.from,inst:j.inst,live:q,...F.gone?{gone:!0}:{}})}function Uj(k,j,q,F,J={}){return D(k,$,(Q)=>{let W=S(Q);if(!W||W.inst===j.inst)return;if(!W.ask)F?.(W);else if(J.answerIf?.()??!0)T(k,j,q())})}function A(k,j){return k.some((q)=>q.live?.here===!0&&(q.live.id?q.live.id===j.id:q.from===j.by))}function h(k,j,q){return A(_(k,j),q)}function Wj(k,j,q,F){let J=L("c"),Q=null,W=D(k,C,(z)=>{let G=N(z);if(G&&G.id===J&&G.inst!==j.inst&&!Q)Q=G});try{V(k,u,{v:X,from:j.from,inst:j.inst,id:J,op:q,...F!==void 0?{text:F}:{}})}finally{W()}return Q}function Xj(k,j,q){return D(k,u,(F)=>{let J=i(F);if(!J||J.inst===j.inst)return;let Q=q(J);if(!Q)return;V(k,C,{v:X,from:j.from,inst:j.inst,id:J.id,...Q})})}globalThis.VitrinkaOne=Object.freeze({...g});})();
@@ -52,6 +52,8 @@ export interface ApiOptions {
52
52
  * Its 401 never touches the recorder's device link.
53
53
  */
54
54
  target?: ApiTarget;
55
+ /** Cancels the request, its answer's body included — the report face's leg deadline (report/wire.ts). */
56
+ signal?: AbortSignal;
55
57
  }
56
58
  export declare function api<T = Record<string, unknown>>(method: string, path: string, body?: unknown, opts?: ApiOptions): Promise<T>;
57
59
  /**
@@ -74,9 +76,9 @@ export declare function uploadImage(sessionId: string, seq: number, blob: Blob):
74
76
  /**
75
77
  * POST raw bytes (an rrweb chunk, an image) to a blob leaf under the
76
78
  * configured bearer: the session doors above and the report face's
77
- * `/api/v1/reports/{id}/chunk?seq=N` (with its own `target`). Returns the
78
- * server's `blobKey`.
79
+ * `/api/v1/reports/{id}/chunk?seq=N` (with its own `target` and leg
80
+ * deadline `signal`). Returns the server's `blobKey`.
79
81
  */
80
- export declare function uploadTo(path: string, contentType: string, body: string | Blob, target?: ApiTarget): Promise<{
82
+ export declare function uploadTo(path: string, contentType: string, body: string | Blob, target?: ApiTarget, signal?: AbortSignal): Promise<{
81
83
  blobKey?: string;
82
84
  }>;
@@ -44,6 +44,7 @@ export async function api(method, path, body, opts = {}) {
44
44
  mode: 'cors',
45
45
  credentials: 'omit',
46
46
  keepalive: opts.keepalive ?? false,
47
+ ...(opts.signal ? { signal: opts.signal } : {}),
47
48
  headers: {
48
49
  authorization: `Bearer ${key}`,
49
50
  ...(body !== undefined ? { 'content-type': 'application/json' } : {}),
@@ -81,15 +82,16 @@ function upload(sessionId, leaf, seq, contentType, body) {
81
82
  /**
82
83
  * POST raw bytes (an rrweb chunk, an image) to a blob leaf under the
83
84
  * configured bearer: the session doors above and the report face's
84
- * `/api/v1/reports/{id}/chunk?seq=N` (with its own `target`). Returns the
85
- * server's `blobKey`.
85
+ * `/api/v1/reports/{id}/chunk?seq=N` (with its own `target` and leg
86
+ * deadline `signal`). Returns the server's `blobKey`.
86
87
  */
87
- export async function uploadTo(path, contentType, body, target) {
88
+ export async function uploadTo(path, contentType, body, target, signal) {
88
89
  const { url, key } = resolveTarget(target);
89
90
  const res = await fetch(url + path, {
90
91
  method: 'POST',
91
92
  mode: 'cors',
92
93
  credentials: 'omit',
94
+ ...(signal ? { signal } : {}),
93
95
  headers: { authorization: `Bearer ${key}`, 'content-type': contentType },
94
96
  body,
95
97
  });
@@ -67,6 +67,8 @@ export declare function startLead(h: LeadHandlers, at?: OneEnv | null): () => vo
67
67
  export declare function claimForStart(): void;
68
68
  /** The Start settled: created (the claim moves on with the session) or not (it goes). */
69
69
  export declare function settleStart(created: boolean): void;
70
+ /** A Start claimed this document and waits on its session: no session record yet, but one is on its way. */
71
+ export declare function startInFlight(): boolean;
70
72
  /** This document's Stop is draining `sessionId` (null: it settled). */
71
73
  export declare function setLeadStopping(sessionId: string | null): void;
72
74
  /** The HUD's flow face (D7). */
@@ -369,6 +369,10 @@ export function settleStart(created) {
369
369
  releaseClaim(env, self.inst);
370
370
  refresh();
371
371
  }
372
+ /** A Start claimed this document and waits on its session: no session record yet, but one is on its way. */
373
+ export function startInFlight() {
374
+ return starting;
375
+ }
372
376
  /** This document's Stop is draining `sessionId` (null: it settled). */
373
377
  export function setLeadStopping(sessionId) {
374
378
  stopping = sessionId;
@@ -11,7 +11,7 @@ export interface RecorderStorage {
11
11
  * shares (memory) has nothing to hear.
12
12
  */
13
13
  watch?(key: string, onChange: (value: string | null) => void): () => void;
14
- /** Run synchronously inside an exclusive cross-document lock. Required when shared across tabs. */
14
+ /** Run synchronously inside an exclusive cross-document lock that sees every earlier holder's writes. Required when shared across tabs. */
15
15
  withLock?(name: string, run: () => void): Promise<void>;
16
16
  /** Enumerate this driver's namespaced keys (cross-tab Stop participants). */
17
17
  keys?(): string[];
@@ -12,8 +12,9 @@
12
12
  */
13
13
  import { withRecorderLock } from './lock';
14
14
  // Keys land as `vitrinka.recorder.<key>`: rec · buffer · chunks · images ·
15
- // blobs · link (the recorder) and dock · prefs · me · recents (the HUD). An
16
- // attached image's bytes live in the blob journal (./blobs, IndexedDB).
15
+ // blobs · link (the recorder), lock.seq (the seq lock's fence, ./lock) and
16
+ // dock · prefs · me · recents (the HUD). An attached image's bytes live in
17
+ // the blob journal (./blobs, IndexedDB).
17
18
  const PREFIX = 'vitrinka.recorder.';
18
19
  let current = null;
19
20
  let used = false;
@@ -5,22 +5,104 @@ export async function withRecorderLock(name, run) {
5
5
  await navigator.locks.request(key, { signal: AbortSignal.timeout(5000) }, run);
6
6
  return;
7
7
  }
8
+ const fence = { area: localArea(), key: `vitrinka.recorder.lock.${name}` };
8
9
  // Web Locks requires a secure context. IndexedDB readwrite transactions
9
10
  // also serialize across tabs, including ordinary HTTP development hosts.
10
11
  const db = await lockDatabase();
11
- await new Promise((resolve, reject) => {
12
+ const unheard = { fence: undefined, since: 0 };
13
+ while (!(await holdOnce(db, key, fence, run, unheard)))
14
+ await pause();
15
+ }
16
+ /** One fence this tab never hears (its storage cleared, a write lost) holds it back this long; then it runs anyway. */
17
+ const HAND_OVER_MS = 1000;
18
+ const HEAR_POLL_MS = 5;
19
+ const pause = () => new Promise((resolve) => setTimeout(resolve, HEAR_POLL_MS));
20
+ function localArea() {
21
+ try {
22
+ return globalThis.localStorage ?? null;
23
+ }
24
+ catch {
25
+ return null; // refused (a sandboxed frame): exclusion alone
26
+ }
27
+ }
28
+ /** Has this document's localStorage heard the last holder's fence (none yet: nothing to hear)? */
29
+ function heard(fence, last) {
30
+ return typeof last !== 'string' || !fence.area || fence.area.getItem(fence.key) === last;
31
+ }
32
+ /** A new fence, written after this holder's own writes; null when the store refused it. */
33
+ function publishFence(fence) {
34
+ if (!fence.area)
35
+ return null;
36
+ const next = `${Date.now().toString(36)}.${Math.random().toString(36).slice(2)}`;
37
+ try {
38
+ fence.area.setItem(fence.key, next);
39
+ return next;
40
+ }
41
+ catch (error) {
42
+ console.warn('vitrinka: recorder lock fence not stored — the next tab may not see this allocation', error);
43
+ return null;
44
+ }
45
+ }
46
+ /**
47
+ * Has this tab waited out `last`? The clock starts when a transaction first
48
+ * shows that fence, and again for a newer one: time spent queued for the
49
+ * lock, or suspended, never counts as time spent hearing its holder.
50
+ */
51
+ function waitedOut(unheard, last) {
52
+ const now = Date.now();
53
+ if (unheard.fence !== last) {
54
+ unheard.fence = last;
55
+ unheard.since = now;
56
+ return false;
57
+ }
58
+ if (now - unheard.since < HAND_OVER_MS)
59
+ return false;
60
+ warnUnheard();
61
+ return true;
62
+ }
63
+ let unheardWarned = false;
64
+ function warnUnheard() {
65
+ if (unheardWarned)
66
+ return;
67
+ unheardWarned = true;
68
+ console.warn(`vitrinka: this tab did not hear the last recorder lock holder within ${HAND_OVER_MS} ms — numbering anyway`);
69
+ }
70
+ /**
71
+ * One IndexedDB hold. A readwrite transaction excludes the other tabs but
72
+ * does not show them the holder's localStorage writes: Chromium keeps a copy
73
+ * of localStorage per renderer and delivers another tab's writes to it
74
+ * later, unordered with the transaction hand-over, so the next holder could
75
+ * read the seq watermark from before the last allocation and number a
76
+ * capture twice. Each holder therefore leaves a fresh fence in localStorage,
77
+ * after its own writes (they reach every tab in order), and in this
78
+ * transaction's record, which every tab reads coherently. A tab whose
79
+ * localStorage does not show the record's fence yet lets go and retries
80
+ * (the transaction would commit across a timer) until it hears it or waited
81
+ * it out.
82
+ */
83
+ function holdOnce(db, key, fence, run, unheard) {
84
+ return new Promise((resolve, reject) => {
12
85
  const tx = db.transaction('locks', 'readwrite');
13
- tx.oncomplete = () => resolve();
86
+ const store = tx.objectStore('locks');
87
+ let ran = false;
88
+ tx.oncomplete = () => resolve(ran);
14
89
  tx.onabort = () => reject(tx.error ?? new Error('vitrinka: recorder lock transaction aborted'));
15
- const request = tx.objectStore('locks').get(key);
90
+ const request = store.get(key);
16
91
  request.onsuccess = () => {
92
+ if (!heard(fence, request.result) && !waitedOut(unheard, request.result))
93
+ return;
17
94
  try {
18
95
  run();
19
96
  }
20
97
  catch (error) {
21
98
  reject(error);
22
99
  tx.abort();
100
+ return;
23
101
  }
102
+ ran = true;
103
+ const next = publishFence(fence);
104
+ if (next)
105
+ store.put(next, key);
24
106
  };
25
107
  });
26
108
  }
@@ -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.8.0";
3
- export declare const RECORDER_ID = "web/0.8.0";
2
+ export declare const RECORDER_VERSION = "0.8.2";
3
+ export declare const RECORDER_ID = "web/0.8.2";
@@ -1,3 +1,3 @@
1
1
  /** Sent as `meta.recorder` and written as `data-vitrinka-page`; bumped with the package version. */
2
- export const RECORDER_VERSION = '0.8.0';
2
+ export const RECORDER_VERSION = '0.8.2';
3
3
  export const RECORDER_ID = `web/${RECORDER_VERSION}`;
@@ -1,22 +1,3 @@
1
- /**
2
- * The two ways in, shared by the npm entry (`@vitrinka/web/report`) and the
3
- * single-file widget (`build/report-widget.mjs`): the `<vitrinka-report>`
4
- * custom element and `mountReport(opts)`, which creates one.
5
- *
6
- * <vitrinka-report key="vkb_…" base="https://vitrinka.example"
7
- * locale="cs" button="false" open-selector="#help-report">
8
- *
9
- * The element is a configuration holder that renders nothing itself: the
10
- * widget paints into the shared HUD host on `<html>` (top layer, shadow
11
- * root). Attributes are live — `locale` repaints in place, `button` shows or
12
- * hides the floating button, `open-selector` rebinds; a changed `key` or
13
- * `base` remounts. The face is config (QA Studio D6): `face: 'recorder'`
14
- * mounts the recorder pill instead (npm entry only — it needs React and a
15
- * `vkr_` key or a device link). A linked vitrinka member also switches faces
16
- * in place (vt-8020 D8, face.ts): the report menu's Record swaps in the pill
17
- * on the device link, the pill's "Report a problem" swaps back, and the pick
18
- * survives a reload (npm entry only, like `face: 'recorder'`).
19
- */
20
1
  import type { RecordLoader } from './engine';
21
2
  import { type Locale } from './i18n';
22
3
  import type { IdentifyInput } from './identity';
@@ -52,6 +33,7 @@ export interface ReportOptions extends ReportScriptOptions {
52
33
  export interface ReportHandle {
53
34
  /** The face on screen — a linked member's Record switch turns a `report` mount into `recorder`. */
54
35
  readonly face: ReportFace;
36
+ /** Opens the card; on a member's switched pill it swaps back first (never while the pill records or starts to). */
55
37
  open(): void;
56
38
  close(): void;
57
39
  identify(who: IdentifyInput): void;
@@ -64,6 +46,7 @@ export interface VitrinkaReportElement extends HTMLElement {
64
46
  options: ReportScriptOptions;
65
47
  /** The face on screen: `recorder` while a linked member has switched to the pill. */
66
48
  readonly face: ReportFace;
49
+ /** Opens the card; on the pill it swaps back first (never while the pill records or starts to). */
67
50
  open(): void;
68
51
  close(): void;
69
52
  identify(who: IdentifyInput): void;
@@ -1,6 +1,28 @@
1
- import { memberLinked, rememberFace, startFace, watchMemberLink } from './face';
1
+ /**
2
+ * The two ways in, shared by the npm entry (`@vitrinka/web/report`) and the
3
+ * single-file widget (`build/report-widget.mjs`): the `<vitrinka-report>`
4
+ * custom element and `mountReport(opts)`, which creates one.
5
+ *
6
+ * <vitrinka-report key="vkb_…" base="https://vitrinka.example"
7
+ * locale="cs" button="false" open-selector="#help-report">
8
+ *
9
+ * The element is a configuration holder that renders nothing itself: the
10
+ * widget paints into the shared HUD host on `<html>` (top layer, shadow
11
+ * root). Attributes are live — `locale` repaints in place, `button` shows or
12
+ * hides the floating button, `open-selector` rebinds; a changed `key` or
13
+ * `base` remounts. The face is config (QA Studio D6): `face: 'recorder'`
14
+ * mounts the recorder pill instead (npm entry only — it needs React and a
15
+ * `vkr_` key or a device link). A linked vitrinka member also switches faces
16
+ * in place (vt-8020 D8, face.ts): the report menu's Record swaps in the pill
17
+ * on the device link, the pill's "Report a problem" swaps back, and the pick
18
+ * survives a reload (npm entry only, like `face: 'recorder'`). The host's
19
+ * openers — `open()` and `open-selector` — swap back too and open the card,
20
+ * except while the pill records or starts to.
21
+ */
22
+ import { listen } from '../recorder/hud/listen';
23
+ import { memberLinked, pillRecording, rememberFace, startFace, watchMemberLink } from './face';
2
24
  import { parseLocale } from './i18n';
3
- import { ReportWidget } from './widget';
25
+ import { hitsOpener, ReportWidget } from './widget';
4
26
  export const REPORT_TAG = 'vitrinka-report';
5
27
  const ATTRS = ['key', 'base', 'open-selector', 'locale', 'button'];
6
28
  function trimBase(raw) {
@@ -26,6 +48,10 @@ export function defineReportElement(faces) {
26
48
  gen = 0;
27
49
  /** The report widget currently offers Record. */
28
50
  recordOffered = false;
51
+ /** The host's `open-selector` control while the pill shows (the report widget binds it otherwise). */
52
+ offPillOpener = null;
53
+ /** An open() refused on a recording pill has said why. */
54
+ warnedRecording = false;
29
55
  offLink = null;
30
56
  pendingIdentity = undefined;
31
57
  get face() {
@@ -52,7 +78,7 @@ export function defineReportElement(faces) {
52
78
  this.mount();
53
79
  return;
54
80
  }
55
- // The rest are the report face's: the pill reads none, and a switch back reads them afresh.
81
+ // The rest are the report face's: the pill's opener reads `open-selector` per click, and a switch back reads them afresh.
56
82
  if (!this.widget)
57
83
  return;
58
84
  if (name === 'locale')
@@ -63,7 +89,10 @@ export function defineReportElement(faces) {
63
89
  this.widget.setOpenSelector(value);
64
90
  }
65
91
  open() {
66
- this.widget?.open();
92
+ if (this.shown === 'recorder')
93
+ this.openFromPill();
94
+ else
95
+ this.widget?.open();
67
96
  }
68
97
  close() {
69
98
  this.widget?.close();
@@ -105,6 +134,8 @@ export function defineReportElement(faces) {
105
134
  this.widget?.unmount();
106
135
  this.widget = null;
107
136
  this.recordOffered = false;
137
+ this.offPillOpener?.();
138
+ this.offPillOpener = null;
108
139
  this.pill?.();
109
140
  this.pill = null;
110
141
  }
@@ -116,6 +147,13 @@ export function defineReportElement(faces) {
116
147
  const loadPill = faces.recorderFace;
117
148
  if (face === 'recorder' && loadPill) {
118
149
  this.shown = 'recorder';
150
+ // The widget that binds the host's control is down while the pill shows: the control still reaches the card.
151
+ this.offPillOpener = listen(document, 'click', (ev) => {
152
+ if (!hitsOpener(ev, this.getAttribute('open-selector')))
153
+ return;
154
+ ev.preventDefault();
155
+ this.open();
156
+ });
119
157
  const gen = this.gen;
120
158
  loadPill()
121
159
  .then((mountPill) => {
@@ -161,6 +199,40 @@ export function defineReportElement(faces) {
161
199
  this.recordOffered = offer;
162
200
  this.widget.setRecordSwitch(offer ? () => this.switchTo('recorder') : null);
163
201
  }
202
+ /**
203
+ * A host opener on the pill: back to Report a problem — remembered as the
204
+ * pill's own row does — and the card opens there. Deferred like switchTo,
205
+ * then decided on the face this mount shows by then (a remount — a new
206
+ * key or base, a reconnect — drops it), asked again right before the
207
+ * pill comes down: never while it records or a Start waits on its
208
+ * session, as leaving strands it.
209
+ */
210
+ openFromPill() {
211
+ if (this.keepsPill())
212
+ return;
213
+ const at = this.at;
214
+ setTimeout(() => {
215
+ if (!at || this.at !== at)
216
+ return;
217
+ if (this.shown === 'recorder') {
218
+ if (this.keepsPill())
219
+ return;
220
+ rememberFace('report');
221
+ this.show('report');
222
+ }
223
+ this.widget?.open();
224
+ }, 0);
225
+ }
226
+ /** The pill is recording (or starting to): it stays, and the first refusal says why. */
227
+ keepsPill() {
228
+ if (!pillRecording())
229
+ return false;
230
+ if (!this.warnedRecording) {
231
+ console.warn('vitrinka: Report a problem stays closed while the recorder pill records — leaving would strand the session; stop the recording first');
232
+ }
233
+ this.warnedRecording = true;
234
+ return true;
235
+ }
164
236
  /** The member's pick, remembered for this browser; applied once the menu that asked has let go of its click. */
165
237
  switchTo(face) {
166
238
  rememberFace(face);
@@ -125,6 +125,14 @@ export declare class CaptureEngine {
125
125
  private standDown;
126
126
  /** Freeze the capture now (the card opened); the buffer rolls on. */
127
127
  freeze(): Frozen;
128
+ /**
129
+ * The card opened before the lazily loaded recorder ran (a slow network,
130
+ * device or runner): the frozen clip holds no screen of this page, and the
131
+ * report would go without its replay. When the recorder runs by Send, take
132
+ * its view now, as freeze() does for one that only just started. Earlier
133
+ * loads' windows and the console/network entries stay the frozen ones.
134
+ */
135
+ private withScreen;
128
136
  /**
129
137
  * The rrweb ids of the page nodes under a hide right now — taken when the
130
138
  * hide is drawn (the page sits frozen under the marking layer); null when
@@ -288,6 +288,26 @@ export class CaptureEngine {
288
288
  stored.catch(() => undefined); // build reports a failed read
289
289
  return { clip, stored };
290
290
  }
291
+ /**
292
+ * The card opened before the lazily loaded recorder ran (a slow network,
293
+ * device or runner): the frozen clip holds no screen of this page, and the
294
+ * report would go without its replay. When the recorder runs by Send, take
295
+ * its view now, as freeze() does for one that only just started. Earlier
296
+ * loads' windows and the console/network entries stay the frozen ones.
297
+ */
298
+ withScreen(clip) {
299
+ if (!this.capturing || !runningRecord() || (clip && clipHasSnapshot(clip)))
300
+ return clip;
301
+ checkoutRRWeb();
302
+ const now = takeFlightClip();
303
+ if (!now)
304
+ return clip;
305
+ return {
306
+ windows: [...(clip?.windows.filter((w) => w.stored) ?? []), ...now.windows.filter((w) => !w.stored)],
307
+ lanes: clip?.lanes ?? now.lanes,
308
+ truncated: clip?.truncated ?? now.truncated,
309
+ };
310
+ }
291
311
  /**
292
312
  * The rrweb ids of the page nodes under a hide right now — taken when the
293
313
  * hide is drawn (the page sits frozen under the marking layer); null when
@@ -317,12 +337,13 @@ export class CaptureEngine {
317
337
  for (const id of hiddenNodeIds(hides, mirror))
318
338
  hiddenIds.add(id);
319
339
  const events = [];
320
- let truncated = frozen.clip?.truncated ?? false;
340
+ const clip = this.withScreen(frozen.clip);
341
+ let truncated = clip?.truncated ?? false;
321
342
  const pinned = await frozen.stored.catch((e) => {
322
343
  console.warn('vitrinka: the stored part of the capture could not be read — the replay starts later', e);
323
344
  return null;
324
345
  });
325
- for (const w of frozen.clip?.windows ?? []) {
346
+ for (const w of clip?.windows ?? []) {
326
347
  if (!w.stored) {
327
348
  events.push(...w.events);
328
349
  continue;
@@ -335,7 +356,7 @@ export class CaptureEngine {
335
356
  events.push(...read.events);
336
357
  }
337
358
  // The console and network entries, earlier loads' included (priorLanes).
338
- const lanes = frozen.clip?.lanes ?? [];
359
+ const lanes = clip?.lanes ?? [];
339
360
  const whole = withheld ? { events: [], dropped: false } : wholeWindows(applyHides(events, hides, hiddenIds), CHUNK_HARD_BYTES);
340
361
  if (whole.dropped)
341
362
  truncated = true;
@@ -15,6 +15,13 @@ export declare const MODE_KEY = "vitrinka.report.mode";
15
15
  export declare function rememberDisplayMode(mode: string | undefined): void;
16
16
  /** The face a mount starts on: a member's last pick, else the pill for a dev-mode member; everyone else the report face. */
17
17
  export declare function startFace(base: string): ReportFace;
18
+ /**
19
+ * The pill holds a recording — the session record its ⋯ menu reads, which
20
+ * offers "Report a problem" only while there is none (Menu.tsx) — or a Start
21
+ * still waiting on its session. Leaving the pill then would strand the
22
+ * session, so a host opener never switches away.
23
+ */
24
+ export declare function pillRecording(): boolean;
18
25
  /**
19
26
  * Hear the stored link change: another tab's link or unlink (the storage
20
27
  * event), or this document's (`storeLink` / `clearLink` notify). Returns the
@@ -12,6 +12,8 @@
12
12
  */
13
13
  import { linkWorkspace } from '@vitrinka/link';
14
14
  import { LINK_KEY, readLink } from '../recorder/config';
15
+ import { startInFlight } from '../recorder/lead';
16
+ import { getState } from '../recorder/queue';
15
17
  import { subscribe } from '../recorder/state';
16
18
  import { getRecorderStorage } from '../recorder/storage';
17
19
  /** localStorage key of the face this browser last picked on this origin. */
@@ -77,6 +79,15 @@ export function startFace(base) {
77
79
  return picked;
78
80
  return store()?.getItem(MODE_KEY) === 'dev' ? 'recorder' : 'report';
79
81
  }
82
+ /**
83
+ * The pill holds a recording — the session record its ⋯ menu reads, which
84
+ * offers "Report a problem" only while there is none (Menu.tsx) — or a Start
85
+ * still waiting on its session. Leaving the pill then would strand the
86
+ * session, so a host opener never switches away.
87
+ */
88
+ export function pillRecording() {
89
+ return getState() !== null || startInFlight();
90
+ }
80
91
  /**
81
92
  * Hear the stored link change: another tab's link or unlink (the storage
82
93
  * event), or this document's (`storeLink` / `clearLink` notify). Returns the
@@ -92,6 +92,8 @@ export interface Strings {
92
92
  myReports: string;
93
93
  recentRecordings: string;
94
94
  record: string;
95
+ /** Why Record waits: the switch to the pill would lose the unsent report. */
96
+ recordHasDraft: string;
95
97
  openVitrinka: string;
96
98
  openPortal: string;
97
99
  loading: string;
@@ -82,6 +82,7 @@ const en = {
82
82
  myReports: 'My reports',
83
83
  recentRecordings: 'Recent recordings',
84
84
  record: 'Record',
85
+ recordHasDraft: 'Send or clear the report you started first',
85
86
  openVitrinka: 'Open vitrinka',
86
87
  openPortal: 'Open the report portal',
87
88
  loading: 'Loading…',
@@ -202,6 +203,7 @@ const cs = {
202
203
  myReports: 'Moje hlášení',
203
204
  recentRecordings: 'Nedávné nahrávky',
204
205
  record: 'Nahrávat',
206
+ recordHasDraft: 'Odešlete nebo smažte rozepsané hlášení',
205
207
  openVitrinka: 'Otevřít vitrinku',
206
208
  openPortal: 'Otevřít portál hlášení',
207
209
  loading: 'Načítám…',