class Xs{constructor(t,e){this._snapshotIds=new Map,this._snapshotStorage=t,this._resourceLoader=e}serveSnapshot(t,e,n){const r=this._snapshot(t,e);if(!r)return new Response(null,{status:404});const i=r.render();return this._snapshotIds.set(n,r),new Response(i.html,{status:200,headers:{"Content-Type":"text/html; charset=utf-8"}})}async serveClosestScreenshot(t,e){const n=this._snapshot(t,e),r=n==null?void 0:n.closestScreenshot();return r?new Response(await this._resourceLoader(r)):new Response(null,{status:404})}serveSnapshotInfo(t,e){const n=this._snapshot(t,e);return this._respondWithJson(n?{viewport:n.viewport(),url:n.snapshot().frameUrl,timestamp:n.snapshot().timestamp,wallTime:n.snapshot().wallTime}:{error:"No snapshot found"})}_snapshot(t,e){const n=e.get("name");return this._snapshotStorage.snapshotByName(t,n)}_respondWithJson(t){return new Response(JSON.stringify(t),{status:200,headers:{"Cache-Control":"public, max-age=31536000","Content-Type":"application/json"}})}async serveResource(t,e,n){let r;const i=this._snapshotIds.get(n);for(const T of t)if(r=i==null?void 0:i.resourceByUrl($s(T),e),r)break;if(!r)return new Response(null,{status:404});const a=r.response.content._sha1,o=a?await this._resourceLoader(a)||new Blob([]):new Blob([]);let c=r.response.content.mimeType;/^text\/|^application\/(javascript|json)/.test(c)&&!c.includes("charset")&&(c=`${c}; charset=utf-8`);const _=new Headers;c!=="x-unknown"&&_.set("Content-Type",c);for(const{name:T,value:A}of r.response.headers)_.set(T,A);_.delete("Content-Encoding"),_.delete("Access-Control-Allow-Origin"),_.set("Access-Control-Allow-Origin","*"),_.delete("Content-Length"),_.set("Content-Length",String(o.size)),this._snapshotStorage.hasResourceOverride(r.request.url)?_.set("Cache-Control","no-store, no-cache, max-age=0"):_.set("Cache-Control","public, max-age=31536000");const{status:m}=r.response,w=m===101||m===204||m===205||m===304;return new Response(w?null:o,{headers:_,status:r.response.status,statusText:r.response.statusText})}}function $s(s){try{const t=new URL(s);return t.hash="",t.toString()}catch{return s}}function Js(s){const t=new Map,{files:e,stacks:n}=s;for(const r of n){const[i,a]=r;t.set(`call@${i}`,a.map(o=>({file:e[o[0]],line:o[1],column:o[2],function:o[3]})))}return t}const Un={"&":"&","<":"<",">":">",'"':""","'":"'"};function Qs(s){return s.replace(/[&<>"']/ug,t=>Un[t])}function zs(s){return s.replace(/[&<]/ug,t=>Un[t])}function Mt(s,t,e){return s.find((n,r)=>{if(r===s.length-1)return!0;const i=s[r+1];return Math.abs(t(n)-e)i.frameSwapWallTime,t):Mt(this._screencastFrames,i=>i.timestamp,e);return n==null?void 0:n.sha1}render(){const t=[],e=(i,a,o,c)=>{if(typeof i=="string"){o==="STYLE"||o==="style"?t.push(fr(or(i))):t.push(zs(i));return}if(er(i)){const h=a-i[0][0];if(h>=0&&h<=a){const _=rr(this._snapshots[h]),m=i[0][1];if(m>=0&&m<_.length)return e(_[m],h,o,c)}}else if(Hn(i)){const[h,_,...m]=i;if(h.toUpperCase()==="SCRIPT")return;const w=h==="NOSCRIPT"?"X-NOSCRIPT":h,T=Object.entries(_||{});t.push("<",w);const A="__playwright_current_src__",u=w==="IFRAME"||w==="FRAME",l=w==="A",f=w==="IMG",p=w==="META",g=f&&T.some(d=>d[0]===A),I=w==="SOURCE"&&o==="PICTURE"&&(c==null?void 0:c.some(d=>d[0]===A)),O=p&&T.some(d=>d[0].toLowerCase()==="http-equiv"&&!sr.has(d[1].trim().toLowerCase()));for(const[d,b]of T){let y=d;u&&d.toLowerCase()==="src"&&(y="__playwright_src__"),f&&d===A&&(y="src"),["src","srcset"].includes(d.toLowerCase())&&(g||I)&&(y="_"+y),O&&(d.toLowerCase()==="http-equiv"||d.toLowerCase()==="content")&&(y="_"+d);let E=b;!l&&(d.toLowerCase()==="href"||d.toLowerCase()==="src"||d===A)&&(E=lt(b)),t.push(" ",y,'="',Qs(E),'"')}t.push(">");for(const d of m)e(d,a,w,T);nr.has(w)||t.push("");return}else return},n=this._snapshot;return{html:this._htmlCache.getOrCompute(this,()=>{var c;e(n.html,this._index,void 0,void 0);const i=(c=n.doctype)==null?void 0:c.replace(/[^a-zA-Z0-9]/g,""),o=(i?``:"")+["",`