@espejo/browser 0.1.0

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/dist/index.cjs ADDED
@@ -0,0 +1,529 @@
1
+ "use strict";var wn=Object.create;var ue=Object.defineProperty;var En=Object.getOwnPropertyDescriptor;var Sn=Object.getOwnPropertyNames;var _n=Object.getPrototypeOf,Tn=Object.prototype.hasOwnProperty;var An=(e,t)=>{for(var n in t)ue(e,n,{get:t[n],enumerable:!0})},gt=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Sn(t))!Tn.call(e,r)&&r!==n&&ue(e,r,{get:()=>t[r],enumerable:!(o=En(t,r))||o.enumerable});return e};var bt=(e,t,n)=>(n=e!=null?wn(_n(e)):{},gt(t||!e||!e.__esModule?ue(n,"default",{value:e,enumerable:!0}):n,e)),Rn=e=>gt(ue({},"__esModule",{value:!0}),e);var Po={};An(Po,{BLOCK_ATTRIBUTE:()=>Ve,BLOCK_SELECTOR:()=>Z,DEFAULT_BUDGETS:()=>$e,Espejo:()=>Te,FEEDBACK_DEFAULT_TEXT:()=>Je,MASK_SELECTOR:()=>X,MAX_VIDEO_SECONDS:()=>he,RingBuffer:()=>I,SDK_NAME:()=>dn,SDK_VERSION:()=>cn,SegmentRing:()=>q,SessionRecorder:()=>V,WIDGET_DEFAULT_TEXT:()=>Ye,autoStart:()=>Io,canShowFeedback:()=>Se,fetchAutoReportConfig:()=>me,fetchFeedbackConfig:()=>ge,installFeedbackWidget:()=>Ee,normalizeAutoReportConfig:()=>qe,normalizeFeedbackConfig:()=>Ke,sealFeedbackShown:()=>_e,sendVote:()=>ve,videoSupported:()=>K});module.exports=Rn(Po);var jn=new Set(["authorization","proxy-authorization","cookie","set-cookie","x-api-key"]),Cn=/token|secret/i;function yt(e){if(typeof e!="string")return!1;let t=e.toLowerCase().trim();return jn.has(t)||Cn.test(t)}function He(e){if(Array.isArray(e))return e.map(t=>t&&yt(t.name)?{...t,value:"[redacted]",binaryValue:void 0}:t);if(e&&typeof e=="object"){let t={};for(let[n,o]of Object.entries(e))t[n]=yt(n)?"[redacted]":o;return t}return e}var pe=/token|secret|password|signature|^code$|^key$|credential/i,Ln=/^[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}$/,De=/[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g;function Ne(e){return typeof e=="string"&&Ln.test(e)}function T(e){if(typeof e!="string"||!e)return e;let t=e.indexOf("?"),n=e.indexOf("#");if(t===-1&&n===-1&&!e.includes("@")&&!De.test(e))return e;De.lastIndex=0;try{let o=new URL(e),r=!1;(o.username||o.password)&&(o.username="redacted",o.password="redacted",r=!0);for(let p of[...o.searchParams.keys()])pe.test(p)&&(o.searchParams.set(p,"[redacted]"),r=!0);let a=o.pathname.split("/"),i=!1,s=a.map(p=>Ne(p)?(i=!0,"[redacted]"):p).join("/");i&&(o.pathname=s,r=!0);let l=o.hash.slice(1);if(l&&!l.startsWith("/")){let p=new URLSearchParams(l),u=!1;for(let c of[...p.keys()])pe.test(c)&&(p.set(c,"[redacted]"),u=!0);u&&(o.hash=p.toString(),r=!0)}return r?o.toString():e}catch{let o=e;if(n!==-1){let r=e.slice(n+1);!r.startsWith("/")&&pe.test(r)&&(o=o.slice(0,n)+"#[redacted]")}if(t!==-1){let r=n!==-1?n:e.length,a=e.slice(t+1,r);pe.test(a)&&(o=o.slice(0,t)+"?[redacted]"+o.slice(n!==-1?n:o.length))}return o=o.replace(De,"[redacted]"),o}}var Mn=/token|secret|password|credential|api_?key|authorization/i,In=new Set(["token","secret","password","credential","credentials","authorization","jwt","bearer","auth","otp","pwd"]);function Bn(e){return e.replace(/([a-z0-9])([A-Z])/g,"$1 $2").split(/[^a-zA-Z0-9]+/).filter(Boolean).map(t=>t.toLowerCase())}function wt(e){let t=Bn(e);if(t.length===0)return!1;let n=t[t.length-1];return In.has(n)?!0:t.slice(-2).join("")==="apikey"}function On(e){if(!e.includes("="))return!1;for(let t of e.split("&")){let n=t.indexOf("="),o=n===-1?t:t.slice(0,n);if(!o)continue;let r=o;try{r=decodeURIComponent(o.replace(/\+/g," "))}catch{}if(wt(r))return!0}return!1}function Y(e){if(typeof e!="string"||!e)return e;let t=e.trimStart();if(t.startsWith("{")||t.startsWith("["))try{return JSON.stringify(Pe(JSON.parse(e)))}catch{}return On(e)||Ne(t)||Mn.test(e)?"[redacted]":e}function Pe(e){if(Array.isArray(e))return e.map(Pe);if(e&&typeof e=="object"){let t={};for(let[n,o]of Object.entries(e))t[n]=wt(n)?"[redacted]":Pe(o);return t}return Ne(e)?"[redacted]":e}var Dn=new TextEncoder,Pn=new TextDecoder("utf-8",{fatal:!1}),Fe=8*1024,Et=4*1024;function J(e,t){if(typeof e!="string")return{text:e,truncated:!1};let n=Dn.encode(e);if(n.byteLength<=t)return{text:e,truncated:!1};let o=n.subarray(0,t);return{text:Pn.decode(o),truncated:!0}}function Hn(e,t,n){let o=Array.isArray(e)?e:[],r=Array.isArray(t)?t:[],a=Array.isArray(n)?n:[],i=o.filter(u=>typeof u?.status=="number"&&u.status>=400),s=i.filter(u=>u.status>=400&&u.status<500),l=i.filter(u=>u.status>=500),p=r.filter(u=>u?.level==="error").length;return{request_count:o.length,interaction_count:a.length,error_4xx_count:s.length,error_5xx_count:l.length,errors:i.slice().sort((u,c)=>(u.t_ms??0)-(c.t_ms??0)).map(u=>({t_ms:u.t_ms,method:u.method,url:u.url,status:u.status,after:Nn(a,u.t_ms)})),console_error_count:p}}function Nn(e,t,n=5e3){if(typeof t!="number")return null;let o=null;for(let r of e)typeof r?.t_ms!="number"||r.t_ms>t||t-r.t_ms>n||(!o||r.t_ms>o.t_ms)&&(o=r);return o?{t_ms:o.t_ms,kind:o.kind,label:o.label}:null}var vt=60;function Fn(e){if(!e||typeof e!="object")return null;let t=[e.testid,e.ariaLabel,e.title,e.text,e.name,e.placeholder,e.id];for(let n of t){if(typeof n!="string")continue;let o=n.replace(/\s+/g," ").trim();if(o)return o.length>vt?`${o.slice(0,vt)}\u2026`:o}return null}function St(e){let{kind:t,raw:n,tMs:o,tabId:r,url:a,x:i,y:s}=e,l={t_ms:o??null,kind:t,label:Fn(n),tag:n?.tag||null,role:n?.role||n?.type||null,selector:n?.selector||null,tabId:r??null,url:a||null};return Number.isFinite(i)&&Number.isFinite(s)&&(l.x=i,l.y=s),l}var _t=1,Un=3;function Tt(e){let{startedAt:t,durationMs:n,screen:o,tabs:r,network:a,consoleEntries:i,navigations:s,interactions:l}=e;return{schema_version:Un,summary:Hn(a,i,l),started_at:t,duration_ms:n,screen:o||{width:0,height:0},tabs:r||[],interactions:l||[],network:a||[],console:i||[],navigations:s||[]}}var At=["auto:console_error","auto:uncaught","auto:unhandled_rejection","auto:network_5xx","auto:network_failed","auto:network_4xx"];function Rt(e){return typeof e=="string"&&At.includes(e)}var $n=["manual","always","rule"],No=[...$n,...At];var jt=20,Ct=36e5,Lt=class{constructor(e,t=()=>Date.now()){this.config=e,this.now=t,this.count=0,this.lastAt=null,this.seen=new Set}get used(){return this.count}check(e){if(this.count>=this.config.max_per_page)return{allowed:!1,reason:"max_per_page"};if(this.seen.has(e))return{allowed:!1,reason:"duplicate"};let t=this.now();return this.lastAt!==null&&t-this.lastAt<this.config.cooldown_ms?{allowed:!1,reason:"cooldown"}:(this.count+=1,this.lastAt=t,this.seen.add(e),{allowed:!0,count:this.count})}},Wn=200,Gn=300;function Ue(e,t,n){let o=(t??"").slice(0,Wn),r=(n??"").slice(0,Gn);return`${e}|${o}|${r}`}function Mt(e,t){return t?"auto:network_failed":typeof e!="number"?null:e>=500?"auto:network_5xx":e>=400?"auto:network_4xx":null}var Vn=["emoji3","scale7","thumbs"];function It(e){return typeof e=="string"&&Vn.includes(e)}var Bt={emoji3:{min:0,max:2},scale7:{min:1,max:7},thumbs:{min:0,max:1}};var xt=1,kt=365,qn=30;function Ot(e){if(typeof e!="number"||!Number.isFinite(e))return qn;let t=Math.floor(e);return t<xt?xt:t>kt?kt:t}var I=class{constructor(t){this.options=t;this.slots=[];this.total=0;this.dropped=0}push(t){let n;try{n=JSON.stringify(t)?.length??0}catch{this.dropped++;return}if(n>this.options.maxBytes){this.dropped++;return}this.slots.push({item:t,bytes:n}),this.total+=n,this.evict()}evict(){for(;this.total>this.options.maxBytes||this.slots.length>this.options.maxItems;){let t=this.slots.shift();if(!t)break;this.total-=t.bytes,this.dropped++}}toArray(){return this.slots.map(t=>t.item)}get droppedCount(){return this.dropped}get byteLength(){return this.total}get length(){return this.slots.length}clear(){this.slots=[],this.total=0,this.dropped=0}};var $e={networkBytes:12e5,consoleBytes:4e5,interactionBytes:2e5,navigationBytes:5e4,maxItemsPerKind:5e3},V=class{constructor(t={}){let n={...$e,...t},o=n.maxItemsPerKind;this.network=new I({maxBytes:n.networkBytes,maxItems:o}),this.console=new I({maxBytes:n.consoleBytes,maxItems:o}),this.interactions=new I({maxBytes:n.interactionBytes,maxItems:o}),this.navigations=new I({maxBytes:n.navigationBytes,maxItems:o}),this.startedAtIso=new Date().toISOString(),this.clockStart=Dt()}elapsed(){return Math.round(Dt()-this.clockStart)}get dropped(){return{network:this.network.droppedCount,console:this.console.droppedCount,interactions:this.interactions.droppedCount,navigations:this.navigations.droppedCount}}get byteLength(){return this.network.byteLength+this.console.byteLength+this.interactions.byteLength+this.navigations.byteLength}snapshot(){return Tt({startedAt:this.startedAtIso,durationMs:this.elapsed(),screen:Kn(),network:this.network.toArray(),consoleEntries:this.console.toArray(),interactions:this.interactions.toArray(),navigations:this.navigations.toArray()})}clear(){this.network.clear(),this.console.clear(),this.interactions.clear(),this.navigations.clear()}};function Dt(){return typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now()}function Kn(){return typeof window>"u"?{width:0,height:0}:{width:window.innerWidth||0,height:window.innerHeight||0}}var zn=512*1024,Pt=/^(application\/(json|xml|javascript|x-www-form-urlencoded|.*\+json)|text\/)/i;function Ht(e,t={}){let n=(t.ignoreOrigins??[]).filter(Boolean),o=t.maxBodyReadBytes??zn,r=[],a=s=>s?n.some(l=>s.startsWith(l)):!0,i=s=>{try{e.network.push(s)}catch{}try{t.onEntry?.(s)}catch{}};if(typeof globalThis.fetch=="function"){let s=globalThis.fetch,l=function(...p){let u="",c="GET",h=null,w=e.elapsed();try{let[m,b]=p;u=typeof m=="string"?m:m instanceof URL?m.href:m.url,c=(b?.method||(typeof m=="object"&&"method"in m?m.method:"GET")||"GET").toUpperCase(),typeof b?.body=="string"&&(h=b.body)}catch{}let x=s.apply(this,p);return a(u)?x:x.then(m=>{try{let b=fe(w,e.elapsed(),c,u,h);b.status=m.status,b.response_headers=He(Jn(m.headers)),i(b),Yn(m,b,o)}catch{}return m},m=>{try{let b=fe(w,e.elapsed(),c,u,h);b.error=String(m?.message||m||"error"),i(b)}catch{}throw m})};globalThis.fetch=l,r.push(()=>{globalThis.fetch=s})}if(typeof XMLHttpRequest=="function"){let s=XMLHttpRequest.prototype,l=s.open,p=s.send;s.open=function(u,c,...h){try{this.__espejo={method:String(u||"GET").toUpperCase(),url:typeof c=="string"?c:c.href,t0:e.elapsed(),body:null}}catch{}return l.apply(this,[u,c,...h])},s.send=function(u){let c=this.__espejo;return c&&(typeof u=="string"&&(c.body=u),c.t0=e.elapsed(),a(c.url)||this.addEventListener("loadend",()=>{try{let h=fe(c.t0,e.elapsed(),c.method,c.url,c.body,"xhr");this.status===0?h.error="network error o abortado":h.status=this.status,h.response_headers=He(Xn(Zn(this)));let w=Qn(this);w!=null&&Nt(h,w),i(h)}catch{}})),p.apply(this,[u])},r.push(()=>{s.open=l,s.send=p})}if(typeof navigator<"u"&&typeof navigator.sendBeacon=="function"){let s=navigator.sendBeacon.bind(navigator);navigator.sendBeacon=function(l,p){let u=typeof l=="string"?l:l.href,c=s(l,p);try{if(!a(u)){let h=fe(e.elapsed(),e.elapsed(),"POST",u,typeof p=="string"?p:null,"beacon");c||(h.error="sendBeacon devolvi\xF3 false (encolado rechazado)"),i(h)}}catch{}return c},r.push(()=>{navigator.sendBeacon=s})}return()=>{for(let s of r.splice(0))try{s()}catch{}}}function fe(e,t,n,o,r,a="fetch"){let i={requestId:null,t_ms:e,method:n,url:T(o),status:null,duration_ms:Math.max(0,t-e),type:a,tabId:null,error:null,response_body:null,request_headers:null,response_headers:null};if(r!=null){let{text:s,truncated:l}=J(Y(r),Fe);i.request_body=s,l&&(i.request_body_truncated=!0)}return i}function Nt(e,t){let{text:n,truncated:o}=J(Y(t),Fe);e.response_body=n,o&&(e.response_body_truncated=!0)}function Yn(e,t,n){try{if(!e.body)return;let o=e.headers.get("content-type")||"";if(!Pt.test(o)||Number(e.headers.get("content-length")||"0")>n)return;e.clone().text().then(i=>{i.length>n||Nt(t,i)}).catch(()=>{})}catch{}}function Jn(e){let t={};try{e.forEach((n,o)=>{t[o]=n})}catch{}return t}function Zn(e){try{return e.getAllResponseHeaders()||""}catch{return""}}function Xn(e){let t={};for(let n of e.split(/\r?\n/)){let o=n.indexOf(":");o<=0||(t[n.slice(0,o).trim()]=n.slice(o+1).trim())}return t}function Qn(e){try{if(e.responseType&&e.responseType!=="text"&&e.responseType!=="json")return null;let t=e.getResponseHeader("content-type")||"";return t&&!Pt.test(t)?null:typeof e.responseText=="string"?e.responseText:null}catch{return null}}var eo=["error","warn"];function Ft(e,t={}){let n=[],o=(r,a)=>{try{e.console.push(r)}catch{}try{t.onEntry?.(r,a)}catch{}};if(typeof console<"u")for(let r of eo){let a=console[r]?.bind(console);a&&(console[r]=(...i)=>{try{o({t_ms:e.elapsed(),level:r,...We(i.map(no).join(" ")),url:Ge(),stack:to(i)},"console")}catch{}a(...i)},n.push(()=>{console[r]=a}))}if(typeof window<"u"){let r=i=>{o({t_ms:e.elapsed(),level:"error",...We(i.message||"window.onerror"),url:i.filename||Ge(),line:i.lineno??null,stack:i.error?.stack??null},"window_error")},a=i=>{let s=i.reason;o({t_ms:e.elapsed(),level:"error",...We(`unhandledrejection: ${s?.message||String(s)}`),url:Ge(),stack:s?.stack??null},"unhandled_rejection")};window.addEventListener("error",r),window.addEventListener("unhandledrejection",a),n.push(()=>{window.removeEventListener("error",r),window.removeEventListener("unhandledrejection",a)})}return()=>{for(let r of n.splice(0))try{r()}catch{}}}function to(e){for(let t of e)if(t instanceof Error&&typeof t.stack=="string")return t.stack;return null}function no(e){if(typeof e=="string")return e;if(e instanceof Error)return`${e.name}: ${e.message}`;try{return JSON.stringify(e)??String(e)}catch{return String(e)}}function We(e){let t=e.trimStart(),o=t.startsWith("{")||t.startsWith("[")?String(Y(e)):e.replace(/https?:\/\/\S+/g,i=>T(i)),{text:r,truncated:a}=J(o,Et);return a?{text:r,truncated:!0}:{text:r}}function Ge(){try{return typeof location<"u"?T(location.href):null}catch{return null}}var oo=80,Ve="data-espejo-block";function Ut(e,t={}){if(typeof document>"u")return()=>{};let n=(i,s,l)=>{try{if(io(s))return;let p=e.elapsed();e.interactions.push(St({kind:i,raw:lo(ao(s)),tMs:p,url:typeof location<"u"?T(location.href):null,x:l?.x,y:l?.y})),t.onEntry?.(i,p)}catch{}},o=i=>{i.target?.nodeType===1&&n("click",i.target,ro(i))},r=i=>{i.target?.nodeType===1&&n("change",i.target)},a=i=>{i.target?.nodeType===1&&n("submit",i.target)};return document.addEventListener("pointerdown",o,!0),document.addEventListener("change",r,!0),document.addEventListener("submit",a,!0),()=>{document.removeEventListener("pointerdown",o,!0),document.removeEventListener("change",r,!0),document.removeEventListener("submit",a,!0)}}function ro(e){let t=(n,o)=>o>0?Math.round(Math.min(1,Math.max(0,n/o))*1e4)/1e4:NaN;return{x:t(e.clientX,window.innerWidth),y:t(e.clientY,window.innerHeight)}}function io(e){return typeof e.closest=="function"&&e.closest(`[${Ve}]`)!==null}function so(e){let t=[],n=e;for(let o=0;n&&n.nodeType===1&&o<4;o++){if(n.id){t.unshift(`#${n.id}`);break}let r=n.tagName.toLowerCase(),a=n.parentElement;if(!a){t.unshift(r);break}let i=[...a.children].filter(s=>s.tagName===n.tagName);t.unshift(i.length>1?`${r}:nth-of-type(${i.indexOf(n)+1})`:r),n=a}return t.join(" > ")}function ao(e){let t=e;for(let n=0;t&&t.nodeType===1&&n<5;n++){let o=t.tagName.toLowerCase();if(["button","a","input","select","textarea","label","summary"].includes(o)||t.getAttribute("role")||t.hasAttribute("data-testid"))return t;t=t.parentElement}return e}function lo(e){let t=(e.innerText||e.textContent||"").replace(/\s+/g," ").trim(),n=e.getAttribute("type"),o=e.tagName.toLowerCase()==="input"&&n==="password";return{tag:e.tagName.toLowerCase(),id:e.id||null,testid:e.getAttribute("data-testid")||e.getAttribute("data-test-id")||null,ariaLabel:e.getAttribute("aria-label")||null,title:e.getAttribute("title")||null,text:o?null:t.slice(0,oo)||null,name:e.getAttribute("name")||null,placeholder:o?null:e.getAttribute("placeholder")||null,role:e.getAttribute("role")||null,type:n,selector:so(e)}}function $t(e,t){if(typeof window>"u"||typeof history>"u")return()=>{};let n="",o=()=>{try{let i=T(location.href);if(i===n)return;if(n=i,e.navigations.push({t_ms:e.elapsed(),url:i}),t)try{t(i)}catch{}}catch{}};o();let r=history.pushState,a=history.replaceState;return history.pushState=function(...i){let s=r.apply(this,i);return o(),s},history.replaceState=function(...i){let s=a.apply(this,i);return o(),s},window.addEventListener("popstate",o),window.addEventListener("hashchange",o),()=>{history.pushState=r,history.replaceState=a,window.removeEventListener("popstate",o),window.removeEventListener("hashchange",o)}}var q=class{constructor(t){this.options=t;this.segments=[];this.total=0;this.droppedSegments=0;this.overflowed=!1}startSegment(){this.segments.push({items:[],bytes:0}),this.overflowed=!1,this.evict()}push(t){if(this.segments.length===0||this.overflowed)return;let n;try{n=JSON.stringify(t)?.length??0}catch{return}let o=this.segments[this.segments.length-1];o.items.push(t),o.bytes+=n,this.total+=n,this.evict()}evict(){for(;this.total>this.options.maxBytes&&this.segments.length>1;){let t=this.segments.shift();this.total-=t.bytes,this.droppedSegments++}if(this.total>this.options.maxBytes&&this.segments.length===1){let t=this.segments.pop();this.total-=t.bytes,this.droppedSegments++,this.overflowed=!0}}toArray(){let t=[];for(let n of this.segments)t.push(...n.items);return t}get byteLength(){return this.total}get segmentCount(){return this.segments.length}get droppedCount(){return this.droppedSegments}get isOverflowed(){return this.overflowed}clear(){this.segments=[],this.total=0,this.droppedSegments=0,this.overflowed=!1}};var co=3e4,Z="[data-espejo-block]",X="[data-espejo-mask]";function Wt(e,t,n={}){let o=new q({maxBytes:n.maxBytes??3e6}),r=t({emit(a,i){try{(i||o.segmentCount===0)&&o.startSegment(),o.push(a)}catch{}},checkoutEveryNms:co,maskAllInputs:!0,blockSelector:Z,maskTextSelector:X,recordCanvas:!1,collectFonts:!1});return{stop(){try{r?.()}catch{}},events:()=>o.toArray(),buffer:o}}async function Gt(){try{return(await import("rrweb")).record??null}catch{return null}}async function Vt(){try{return(await import("rrweb-snapshot")).snapshot??null}catch{return null}}var uo=800;function qt(e){let t=new Set,n=null,o=()=>{try{let a=e.getSnapshot();if(!a||typeof document>"u"||typeof location>"u")return;let i=T(location.href);if(t.has(i))return;let s=a(document,{maskAllInputs:!0,blockSelector:Z,maskTextSelector:X,inlineStylesheet:!0,recordCanvas:!1});if(!s)return;t.add(i),po(e,i,s).catch(()=>{t.delete(i)})}catch{}};return{onRoute:()=>{typeof setTimeout>"u"||(n&&clearTimeout(n),n=setTimeout(o,uo))},stop(){n&&(clearTimeout(n),n=null)}}}async function po(e,t,n){let o=`${fo(e.ingestUrl)}/v1/ingest/route-snapshot`,r=await e.fetchImpl(o,{method:"POST",headers:{"x-espejo-key":e.key,"content-type":"application/json"},body:JSON.stringify({key:e.key,url:t,width:typeof window<"u"?window.innerWidth:0,height:typeof window<"u"?window.innerHeight:0,snapshot:n}),credentials:"omit",keepalive:!1});if(!r.ok)throw new Error(`route-snapshot rejected: HTTP ${r.status}`)}function fo(e){return e.endsWith("/")?e.slice(0,-1):e}var ho=["video/webm;codecs=vp9,opus","video/webm;codecs=vp8,opus","video/webm"],he=240;async function mo(){try{return(await navigator.permissions?.query({name:"microphone"}))?.state==="denied"}catch{return!1}}function K(){return typeof navigator<"u"&&!!navigator.mediaDevices?.getDisplayMedia&&typeof MediaRecorder<"u"}function go(){return typeof MediaRecorder>"u"?null:ho.find(e=>MediaRecorder.isTypeSupported(e))??null}async function Kt(e={}){if(!K())throw new Error("This browser can't record the screen.");let t=go();if(!t)throw new Error("This browser doesn't support MediaRecorder for webm.");let n=[],o=()=>{for(let S of n)for(let L of S.getTracks())L.stop();n.length=0},r=e.maxHeight??1080,a=e.frameRate??24,i=e.surface,s=await navigator.mediaDevices.getDisplayMedia({video:{height:{max:r},frameRate:{ideal:a,max:a},...i?{displaySurface:i}:{}},audio:!0,...i==="current-tab"?{preferCurrentTab:!0}:{}});n.push(s),await s.getVideoTracks()[0]?.applyConstraints({height:{max:r},frameRate:{max:a}}).catch(()=>{});let l=s.getAudioTracks()[0],p=new AudioContext;p.resume().catch(()=>{});let u=p.createMediaStreamDestination(),c=p.createConstantSource();c.offset.value=0,c.connect(u),c.start(),l&&p.createMediaStreamSource(new MediaStream([l])).connect(u);let h=null,w=!1,x=!1,m=async S=>{if(S===w)return{on:w,denied:!1};if(!S)return h&&(h.gain.value=0),w=!1,{on:!1,denied:!1};if(!h)try{let L=await navigator.mediaDevices.getUserMedia({audio:!0});n.push(L),h=p.createGain(),h.gain.value=0,p.createMediaStreamSource(L).connect(h),h.connect(u)}catch{return{on:!1,denied:await mo()}}return h.gain.value=1,w=!0,x=!0,{on:!0,denied:!1}},b=u.stream.getAudioTracks()[0],A=[...s.getVideoTracks()];b&&A.push(b),e.microphone&&await m(!0);let k=()=>typeof performance<"u"?performance.now():Date.now(),N=0,R=0,j=[],v=new MediaRecorder(new MediaStream(A),{mimeType:t,videoBitsPerSecond:e.videoBitsPerSecond??6e5,audioBitsPerSecond:64e3});v.ondataavailable=S=>{S.data.size>0&&j.push(S.data)};let g=t.split(";")[0],B=new Promise(S=>{v.onstop=()=>{R||(R=k()),o(),p.close().catch(()=>{}),S(new Blob(j,{type:g}))}});s.getVideoTracks()[0]?.addEventListener("ended",()=>{v.state!=="inactive"&&v.stop(),e.onUserStopped?.()});let C=Math.min(e.maxSeconds??240,240),Q=setTimeout(()=>{v.state!=="inactive"&&v.stop(),e.onLimitReached?.()},C*1e3);return v.start(1e3),N=k(),{mimeType:t,contentType:g,limitSeconds:C,get durationMs(){return N?(R||k())-N:0},setMicrophone:m,get microphoneOn(){return w},get hasAudio(){return!!l||x},async stop(){clearTimeout(Q),v.state!=="inactive"&&v.stop();let S=await B;return S.size>0?S:null}}}var bo=2e3;async function me(e,t,n){let o={config:null,videoSurface:null,hasTriggers:!1};try{if(typeof n!="function")return o;let r=`${vo(e)}/v1/ingest/config?key=${encodeURIComponent(t)}`,a=await n(r,{method:"GET",credentials:"omit",signal:yo(bo)});if(!a.ok)return o;let i=await a.json(),s=i?.data??i,l=s?.video_surface;return{config:qe(s),videoSurface:typeof l=="string"?l:null,hasTriggers:s?.has_triggers===!0}}catch{return o}}function qe(e){if(!e||typeof e!="object")return null;let t=e;if(t.enabled!==!0)return null;let n=Array.isArray(t.triggers)?t.triggers.filter(Rt):[];if(!n.length)return null;let o=zt(t.max_per_page,1,jt),r=zt(t.cooldown_ms,0,Ct);return o===null||r===null?null:{enabled:!0,triggers:n,max_per_page:o,cooldown_ms:r}}function zt(e,t,n){if(typeof e!="number"||!Number.isFinite(e))return null;let o=Math.trunc(e);return o<t?null:Math.min(o,n)}function yo(e){try{return typeof AbortSignal<"u"&&typeof AbortSignal.timeout=="function"?AbortSignal.timeout(e):void 0}catch{return}}function vo(e){return e.endsWith("/")?e.slice(0,-1):e}var xo=2e3;async function ge(e,t,n){try{if(typeof n!="function")return null;let o=`${wo(e)}/v1/ingest/feedback-config?key=${encodeURIComponent(t)}`,r=await n(o,{method:"GET",credentials:"omit",signal:ko(xo)});if(!r.ok)return null;let a=await r.json(),i=a?.data??a;return Ke(i)}catch{return null}}function Ke(e){if(!e||typeof e!="object")return null;let t=e;return t.enabled!==!0||!It(t.kind)?null:{enabled:!0,kind:t.kind,cadence_days:Ot(t.cadence_days)}}function ko(e){try{return typeof AbortSignal<"u"&&typeof AbortSignal.timeout=="function"?AbortSignal.timeout(e):void 0}catch{return}}function wo(e){return e.endsWith("/")?e.slice(0,-1):e}var be=new Map;function ye(e,t,n,o=document){let r=globalThis[n];if(r)return Promise.resolve(r);let a=be.get(n);if(a)return a;let i=new Promise(s=>{try{let l=o.createElement("script");l.src=`${e.replace(/\/+$/,"")}/sdk/${t}`,l.async=!0,l.crossOrigin="anonymous",l.addEventListener("load",()=>{s(globalThis[n]??null)}),l.addEventListener("error",()=>{be.delete(n),s(null)}),o.head.appendChild(l)}catch{be.delete(n),s(null)}});return be.set(n,i),i}var Yt="__espejoInstallTriggers";async function Jt(e,t=fetch){let n=JSON.stringify({manifest:e.manifest,events:e.events,dom:e.dom??null}),o=e.video?So(n,e.video):null,r=o??n,a={"x-espejo-key":e.key};e.video||(a["content-type"]="application/json");let i=`${Zt(e.ingestUrl)}/v1/ingest/sessions`;if(o&&e.onProgress)return Eo(i,a,o,e.onProgress);let s=await t(i,{method:"POST",headers:a,body:r,credentials:"omit",keepalive:!1});if(!s.ok){let p=await s.text().catch(()=>"");throw new Error(`ingest rejected the session: HTTP ${s.status} ${p.slice(0,200)}`)}let l=await s.json();return l.data??l}function Eo(e,t,n,o){return new Promise((r,a)=>{let i=new XMLHttpRequest;i.open("POST",e,!0),i.withCredentials=!1;for(let[s,l]of Object.entries(t))i.setRequestHeader(s,l);i.upload.onprogress=s=>{if(!(!s.lengthComputable||s.total<=0))try{o(Math.min(1,s.loaded/s.total))}catch{}},i.onload=()=>{if(i.status<200||i.status>=300){a(new Error(`ingest rejected the session: HTTP ${i.status} ${String(i.responseText).slice(0,200)}`));return}try{let s=JSON.parse(i.responseText);r(s.data??s)}catch{a(new Error("ingest returned a body that is not JSON"))}},i.onerror=()=>a(new Error("ingest unreachable: the upload could not be completed")),i.onabort=()=>a(new Error("the upload was cancelled")),i.send(n)})}async function ve(e,t=fetch){let n=`${Zt(e.ingestUrl)}/v1/ingest/feedback`,o=await t(n,{method:"POST",headers:{"x-espejo-key":e.key,"content-type":"application/json"},body:JSON.stringify({kind:e.kind,value:e.value,page_host:e.pageHost??null,user_ref:e.userRef??null}),credentials:"omit",keepalive:!1});if(!o.ok){let r=await o.text().catch(()=>"");throw new Error(`ingest rejected the vote: HTTP ${o.status} ${r.slice(0,200)}`)}}function So(e,t){let n=new FormData;return n.append("payload",e),n.append("video",new Blob([t.blob],{type:t.contentType}),"video.webm"),n}function Zt(e){return e.endsWith("/")?e.slice(0,-1):e}function xe(e,t,n,o="auto"){let r=e.createElement("div");r.setAttribute(t,""),r.setAttribute("data-theme",o),r.setAttribute("data-corner",n);let a=r.attachShadow({mode:"closed"}),i=n.startsWith("top")?"top":"bottom",s=n.endsWith("left")?"left":"right";return r.setAttribute("style",`position: fixed; ${i}: 16px; ${s}: 16px; z-index: 2147483647; display: block`),{host:r,shadow:a}}var Xt=["keydown","keyup","keypress"],Qt=e=>{e.stopPropagation()};function ke(e){for(let t of Xt)e.addEventListener(t,Qt);return()=>{for(let t of Xt)e.removeEventListener(t,Qt)}}var we=`
2
+ * { box-sizing: border-box; }
3
+
4
+ :host {
5
+ --e-bg: #ffffff;
6
+ --e-fg: #1a1a1a;
7
+ --e-muted: #6b7280;
8
+ --e-border: #e2e2e2;
9
+ --e-accent: #2f6f4f;
10
+ --e-accent-fg: #ffffff;
11
+ --e-danger: #b3261e;
12
+ --e-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
13
+ }
14
+
15
+ @media (prefers-color-scheme: dark) {
16
+ :host(:not([data-theme="light"])) {
17
+ --e-bg: #1f2125;
18
+ --e-fg: #f2f2f2;
19
+ --e-muted: #9ca3af;
20
+ --e-border: #3a3d42;
21
+ --e-accent: #4caf82;
22
+ --e-accent-fg: #0b1f16;
23
+ --e-danger: #ff6b60;
24
+ --e-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
25
+ }
26
+ }
27
+
28
+ :host([data-theme="dark"]) {
29
+ --e-bg: #1f2125;
30
+ --e-fg: #f2f2f2;
31
+ --e-muted: #9ca3af;
32
+ --e-border: #3a3d42;
33
+ --e-accent: #4caf82;
34
+ --e-accent-fg: #0b1f16;
35
+ --e-danger: #ff6b60;
36
+ --e-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
37
+ }
38
+
39
+ button:focus-visible,
40
+ textarea:focus-visible {
41
+ outline: 2px solid var(--e-accent);
42
+ outline-offset: 2px;
43
+ }
44
+
45
+ :host([data-corner="bottom-right"]){bottom:16px!important;right:16px!important}
46
+ :host([data-corner="bottom-left"]){bottom:16px!important;left:16px!important}
47
+ :host([data-corner="top-right"]){top:16px!important;right:16px!important}
48
+ :host([data-corner="top-left"]){top:16px!important;left:16px!important}
49
+ `;var en=we+`
50
+ :host {
51
+ all: initial !important;
52
+ position: fixed !important;
53
+ z-index: 2147483647 !important;
54
+ display: block !important;
55
+ }
56
+
57
+ .espejo-root {
58
+ font-family:
59
+ -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
60
+ font-size: 14px;
61
+ line-height: 1.4;
62
+ color: var(--e-fg);
63
+ position: relative;
64
+ display: block;
65
+ }
66
+
67
+ .espejo-trigger {
68
+ width: 40px;
69
+ height: 40px;
70
+ border-radius: 999px;
71
+ border: 1px solid var(--e-border);
72
+ background: var(--e-bg);
73
+ color: var(--e-fg);
74
+ box-shadow: var(--e-shadow);
75
+ cursor: pointer;
76
+ display: flex;
77
+ align-items: center;
78
+ justify-content: center;
79
+ font-size: 18px;
80
+ padding: 0;
81
+ touch-action: none;
82
+ }
83
+
84
+ /* Host arrastrado: se ancla por el eje hacia donde cay\xF3 (bordes --e-x/--e-r/--e-y/--e-b),
85
+ no siempre top-left, para que lo que se abra crezca HACIA la pantalla y no se vaya afuera. */
86
+ :host([data-dragged][data-ax="l"]){left:var(--e-x)!important;right:auto!important}
87
+ :host([data-dragged][data-ax="r"]){right:var(--e-r)!important;left:auto!important}
88
+ :host([data-dragged][data-ay="t"]){top:var(--e-y)!important;bottom:auto!important}
89
+ :host([data-dragged][data-ay="b"]){bottom:var(--e-b)!important;top:auto!important}
90
+
91
+ .espejo-trigger[hidden] {
92
+ display: none;
93
+ }
94
+
95
+ .espejo-trigger:hover {
96
+ filter: brightness(0.97);
97
+ }
98
+
99
+ .espejo-panel {
100
+ position: absolute;
101
+ width: 260px;
102
+ max-width: calc(100vw - 32px);
103
+ background: var(--e-bg);
104
+ color: var(--e-fg);
105
+ border: 1px solid var(--e-border);
106
+ border-radius: 10px;
107
+ box-shadow: var(--e-shadow);
108
+ padding: 12px;
109
+ }
110
+
111
+ .espejo-panel[hidden] {
112
+ display: none;
113
+ }
114
+
115
+ /* El panel se abre en la direcci\xF3n on-screen: se ancla al mismo eje que el host
116
+ (data-ax/data-ay, del rinc\xF3n o de la posici\xF3n real arrastrada), as\xED abre hacia adentro. */
117
+ :host([data-ay="b"]) .espejo-panel{bottom:calc(100% + 8px);top:auto}
118
+ :host([data-ay="t"]) .espejo-panel{top:calc(100% + 8px);bottom:auto}
119
+ :host([data-ax="r"]) .espejo-panel{right:0;left:auto}
120
+ :host([data-ax="l"]) .espejo-panel{left:0;right:auto}
121
+
122
+ .espejo-title {
123
+ margin: 0 0 8px;
124
+ font-size: 13px;
125
+ font-weight: 600;
126
+ }
127
+
128
+ .espejo-label {
129
+ display: block;
130
+ font-size: 12px;
131
+ color: var(--e-muted);
132
+ margin-bottom: 4px;
133
+ }
134
+
135
+ .espejo-textarea {
136
+ width: 100%;
137
+ min-height: 64px;
138
+ resize: vertical;
139
+ border: 1px solid var(--e-border);
140
+ border-radius: 6px;
141
+ padding: 6px 8px;
142
+ font: inherit;
143
+ color: inherit;
144
+ background: var(--e-bg);
145
+ }
146
+
147
+ .espejo-status {
148
+ min-height: 16px;
149
+ font-size: 12px;
150
+ margin-top: 6px;
151
+ }
152
+
153
+ .espejo-status[data-variant='error'] {
154
+ color: var(--e-danger);
155
+ }
156
+
157
+ .espejo-status[data-variant='success'] {
158
+ color: var(--e-accent);
159
+ }
160
+
161
+ .espejo-actions {
162
+ display: flex;
163
+ justify-content: flex-end;
164
+ gap: 8px;
165
+ margin-top: 10px;
166
+ }
167
+
168
+ .espejo-actions button {
169
+ font: inherit;
170
+ border-radius: 6px;
171
+ padding: 6px 10px;
172
+ cursor: pointer;
173
+ border: 1px solid var(--e-border);
174
+ background: var(--e-bg);
175
+ color: var(--e-fg);
176
+ }
177
+
178
+ .espejo-actions button[type='submit'] {
179
+ background: var(--e-accent);
180
+ border-color: var(--e-accent);
181
+ color: var(--e-accent-fg);
182
+ }
183
+
184
+ .espejo-actions button:disabled {
185
+ opacity: 0.6;
186
+ cursor: default;
187
+ }
188
+
189
+ .espejo-video {
190
+ margin-top: 8px;
191
+ }
192
+
193
+ .espejo-video [hidden] {
194
+ display: none;
195
+ }
196
+
197
+ .espejo-record {
198
+ display: flex;
199
+ align-items: center;
200
+ gap: 6px;
201
+ width: 100%;
202
+ font: inherit;
203
+ border-radius: 6px;
204
+ padding: 7px 10px;
205
+ cursor: pointer;
206
+ border: 1px solid var(--e-border);
207
+ background: var(--e-bg);
208
+ color: var(--e-fg);
209
+ }
210
+
211
+ .espejo-record:hover:not(:disabled) {
212
+ border-color: var(--e-accent);
213
+ }
214
+
215
+ .espejo-record:disabled {
216
+ opacity: 0.6;
217
+ cursor: default;
218
+ }
219
+
220
+ .espejo-record-dot {
221
+ width: 8px;
222
+ height: 8px;
223
+ border-radius: 999px;
224
+ background: var(--e-danger);
225
+ flex: none;
226
+ }
227
+
228
+ .espejo-record-hint {
229
+ margin: 4px 0 0;
230
+ font-size: 11px;
231
+ color: var(--e-muted);
232
+ }
233
+
234
+ .espejo-attached {
235
+ display: flex;
236
+ align-items: center;
237
+ gap: 6px;
238
+ margin: 0;
239
+ padding: 7px 10px;
240
+ border-radius: 6px;
241
+ border: 1px solid var(--e-accent);
242
+ font-size: 12px;
243
+ }
244
+
245
+ .espejo-attached-text {
246
+ flex: 1;
247
+ }
248
+
249
+ .espejo-attached button {
250
+ font: inherit;
251
+ font-size: 11px;
252
+ border: 0;
253
+ background: none;
254
+ padding: 2px 4px;
255
+ color: var(--e-muted);
256
+ text-decoration: underline;
257
+ cursor: pointer;
258
+ }
259
+
260
+ .espejo-attached button:disabled {
261
+ opacity: 0.6;
262
+ cursor: default;
263
+ }
264
+
265
+ .espejo-pill {
266
+ display: flex;
267
+ align-items: center;
268
+ gap: 8px;
269
+ padding: 8px 10px;
270
+ border-radius: 999px;
271
+ background: var(--e-bg);
272
+ color: var(--e-fg);
273
+ border: 1px solid var(--e-border);
274
+ box-shadow: var(--e-shadow);
275
+ font-size: 12px;
276
+ white-space: nowrap;
277
+ touch-action: none;
278
+ cursor: grab;
279
+ }
280
+
281
+ .espejo-pill[hidden] {
282
+ display: none;
283
+ }
284
+
285
+ .espejo-pill-dot {
286
+ width: 9px;
287
+ height: 9px;
288
+ border-radius: 999px;
289
+ background: var(--e-danger);
290
+ flex: none;
291
+ animation: espejo-blink 1.4s ease-in-out infinite;
292
+ }
293
+
294
+ @media (prefers-reduced-motion: reduce) {
295
+ .espejo-pill-dot {
296
+ animation: none;
297
+ }
298
+ }
299
+
300
+ @keyframes espejo-blink {
301
+ 0%, 100% { opacity: 1; }
302
+ 50% { opacity: 0.25; }
303
+ }
304
+
305
+ .espejo-pill-time {
306
+ color: var(--e-muted);
307
+ font-variant-numeric: tabular-nums;
308
+ }
309
+
310
+ .espejo-pill button {
311
+ font: inherit;
312
+ font-size: 12px;
313
+ border-radius: 999px;
314
+ padding: 4px 10px;
315
+ cursor: pointer;
316
+ touch-action: auto;
317
+ border: 1px solid var(--e-accent);
318
+ background: var(--e-accent);
319
+ color: var(--e-accent-fg);
320
+ }
321
+
322
+ .espejo-mic {
323
+ border: 1px solid var(--e-border) !important;
324
+ background: transparent !important;
325
+ color: var(--e-muted) !important;
326
+ padding: 4px 8px !important;
327
+ line-height: 1;
328
+ }
329
+
330
+ .espejo-mic:hover:not([data-blocked]) {
331
+ border-color: var(--e-accent) !important;
332
+ color: var(--e-fg) !important;
333
+ }
334
+
335
+ .espejo-mic[data-on] {
336
+ border-color: var(--e-accent) !important;
337
+ background: var(--e-accent) !important;
338
+ color: var(--e-accent-fg) !important;
339
+ }
340
+
341
+ .espejo-mic[data-blocked] {
342
+ cursor: not-allowed;
343
+ color: var(--e-muted) !important;
344
+ opacity: 0.7;
345
+ }
346
+
347
+ .espejo-markup[hidden] {
348
+ display: none !important;
349
+ }
350
+
351
+ .espejo-mic-slash {
352
+ display: none;
353
+ }
354
+
355
+ .espejo-mic[data-blocked] .espejo-mic-slash {
356
+ display: inline;
357
+ }
358
+
359
+ .espejo-mic svg {
360
+ display: block;
361
+ }
362
+ `;var Ye={triggerLabel:"Reportar un problema",title:"Reportar un problema",fieldLabel:"\xBFQu\xE9 pas\xF3?",placeholder:"Contanos qu\xE9 esperabas y qu\xE9 viste\u2026",cancel:"Cancelar",submit:"Enviar",sending:"Enviando\u2026",success:"Enviado. \xA1Gracias!",errorPrefix:"No se pudo enviar: ",record:"Grabar mi pantalla",recordHint:"Mostranos el error en vez de describirlo.",recording:"Grabando tu pantalla",stopRecording:"Frenar y adjuntar",micOn:"Micr\xF3fono prendido \xB7 clic para silenciar",micOff:"Micr\xF3fono apagado \xB7 clic para narrar",micBlocked:"Micr\xF3fono bloqueado \xB7 habilitalo en la configuraci\xF3n del navegador",micStateOn:"micr\xF3fono activo",micStateOff:"micr\xF3fono en silencio",micStateBlocked:"sin micr\xF3fono",countdown:"Grabando en",markupOn:"Marcado prendido \xB7 tu app no responde al clic mientras dibuj\xE1s",markupOff:"Dibuj\xE1 sobre la pantalla para se\xF1alar algo",videoAttached:"Grabaci\xF3n de pantalla adjuntada",videoRemove:"Sacar",limitReached:"Grabaci\xF3n detenida: se lleg\xF3 al l\xEDmite de tiempo.",recordErrorPrefix:"No se pudo empezar a grabar: "},_o='button, textarea, [href], input, select, [tabindex]:not([tabindex="-1"])';function nn(e){let t=e.doc??(typeof document<"u"?document:null);if(!t)return null;try{return Ao(t,e.report,{...Ye,...e.text},e.video,e.theme??"auto",e.position??"bottom-right",e.icon)}catch{return null}}function To(e){let t=(e??"").trim();return t.startsWith("https://")||t.startsWith("data:image/")?`<img src="${t}" alt="" width="22" height="22" />`:`<span aria-hidden="true">${t.slice(0,8)||"\u{1F41E}"}</span>`}function ze(e){let t=Math.floor(e/60),n=Math.floor(e%60);return`${t}:${String(n).padStart(2,"0")}`}function tn(e){let t=e?.name;return t==="NotAllowedError"||t==="AbortError"}function Ao(e,t,n,o,r,a,i){let{host:s,shadow:l}=xe(e,"data-espejo-widget",a,r);s.setAttribute("data-ax",a.endsWith("left")?"l":"r"),s.setAttribute("data-ay",a.startsWith("top")?"t":"b");let u=!!o?.supported()?`<div class="espejo-video" id="espejo-video">
363
+ <button type="button" class="espejo-record" id="espejo-record">
364
+ <span class="espejo-record-dot" aria-hidden="true"></span>${n.record}
365
+ </button>
366
+ <p class="espejo-record-hint" id="espejo-record-hint">${n.recordHint}</p>
367
+ <p class="espejo-attached" id="espejo-attached" hidden>
368
+ <span aria-hidden="true">\u{1F3AC}</span>
369
+ <span class="espejo-attached-text">${n.videoAttached}</span>
370
+ <button type="button" id="espejo-remove">${n.videoRemove}</button>
371
+ </p>
372
+ </div>`:"";l.innerHTML=`<style>${en}</style>
373
+ <div class="espejo-root">
374
+ <button
375
+ type="button"
376
+ class="espejo-trigger"
377
+ id="espejo-trigger"
378
+ aria-haspopup="dialog"
379
+ aria-expanded="false"
380
+ aria-label="${n.triggerLabel}"
381
+ >${To(i)}</button>
382
+ <div class="espejo-panel" id="espejo-panel" role="dialog" aria-modal="true" aria-labelledby="espejo-title" hidden>
383
+ <form id="espejo-form">
384
+ <p class="espejo-title" id="espejo-title">${n.title}</p>
385
+ <label class="espejo-label" for="espejo-textarea">${n.fieldLabel}</label>
386
+ <textarea
387
+ class="espejo-textarea"
388
+ id="espejo-textarea"
389
+ placeholder="${n.placeholder}"
390
+ required
391
+ ></textarea>
392
+ ${u}
393
+ <div class="espejo-status" id="espejo-status" role="status" aria-live="polite"></div>
394
+ <div class="espejo-actions">
395
+ <button type="button" id="espejo-cancel">${n.cancel}</button>
396
+ <button type="submit" id="espejo-submit">${n.submit}</button>
397
+ </div>
398
+ </form>
399
+ </div>
400
+ <div class="espejo-pill" id="espejo-pill" role="status" aria-live="polite" hidden>
401
+ <span class="espejo-pill-dot" aria-hidden="true"></span>
402
+ <span class="espejo-pill-label" id="espejo-pill-label">${n.recording}</span>
403
+ <span class="espejo-pill-time" id="espejo-pill-time">0:00</span>
404
+ <button
405
+ type="button"
406
+ class="espejo-mic"
407
+ id="espejo-mic"
408
+ aria-pressed="false"
409
+ title="${n.micOff}"
410
+ aria-label="${n.micOff}"
411
+ ><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true">
412
+ <rect x="9" y="2" width="6" height="11" rx="3" />
413
+ <path d="M5 11a7 7 0 0 0 14 0" />
414
+ <path d="M12 18v3" />
415
+ <path class="espejo-mic-slash" d="M4 20L20 4" />
416
+ </svg></button>
417
+ <button
418
+ type="button"
419
+ class="espejo-mic espejo-markup"
420
+ id="espejo-markup"
421
+ aria-pressed="false"
422
+ title="${n.markupOff}"
423
+ aria-label="${n.markupOff}"
424
+ ><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
425
+ <path d="M12 19l7-7-4-4-7 7-1 5z" />
426
+ <path d="M15 8l1-1a2.8 2.8 0 1 1 4 4l-1 1" />
427
+ </svg></button>
428
+ <button type="button" id="espejo-stop">${n.stopRecording}</button>
429
+ </div>
430
+ </div>`;let c=l.getElementById("espejo-trigger"),h=l.getElementById("espejo-panel"),w=l.getElementById("espejo-form"),x=l.getElementById("espejo-textarea"),m=l.getElementById("espejo-cancel"),b=l.getElementById("espejo-submit"),A=l.getElementById("espejo-status"),k=l.getElementById("espejo-pill"),N=l.getElementById("espejo-pill-label"),R=l.getElementById("espejo-pill-time"),j=l.getElementById("espejo-stop"),v=l.getElementById("espejo-mic"),g=l.getElementById("espejo-markup"),B=l.querySelector(".espejo-root"),C=l.getElementById("espejo-record"),Q=l.getElementById("espejo-attached"),S=l.getElementById("espejo-record-hint"),L=l.getElementById("espejo-remove"),F=!1,Ze=!1,Ae=0,O=!1,D=!1,P=!1,M=!1,U=!1,$=null,ee=0,un=()=>Array.from(h.querySelectorAll(_o)).filter(d=>!d.hasAttribute("disabled")&&!d.closest("[hidden]")),H=(d,f)=>{A.textContent=d,f?A.setAttribute("data-variant",f):A.removeAttribute("data-variant")},Re=()=>{!C||!Q||!S||(C.hidden=O,S.hidden=O,Q.hidden=!O)},Xe=()=>{if(O){O=!1;try{o?.discard()}catch{}Re()}},je=(d=!0)=>{F||(F=!0,h.hidden=!1,c.setAttribute("aria-expanded","true"),d&&(H(""),x.value=""),Re(),x.focus(),e.addEventListener("keydown",ne,!0))},Qe=()=>{F&&(F=!1,h.hidden=!0,c.setAttribute("aria-expanded","false"),e.removeEventListener("keydown",ne,!0),c.focus())},te=()=>{Xe(),Qe()},ne=d=>{if(!F)return;if(d.key==="Escape"){d.stopPropagation(),d.preventDefault(),te();return}if(d.key!=="Tab")return;let f=un();if(f.length===0)return;let y=f[0],E=f[f.length-1],G=l.activeElement;d.shiftKey&&G===y?(d.preventDefault(),E.focus()):!d.shiftKey&&G===E&&(d.preventDefault(),y.focus())},Ce=()=>{v.setAttribute("aria-pressed",String(P)),v.toggleAttribute("data-on",P),v.toggleAttribute("data-blocked",U);let d=U?n.micBlocked:P?n.micOn:n.micOff;v.setAttribute("title",d),v.setAttribute("aria-label",d),et()},pn=()=>U?n.micStateBlocked:P?n.micStateOn:n.micStateOff,et=()=>{let d=pn();N.textContent=ee>0?`${n.countdown} ${ee} \xB7 ${d}`:`${n.recording} \xB7 ${d}`},fn=async()=>{if(!o)return;let d;try{d=await o.setMicrophone(!0)}catch{return}D&&(P=d.on,U=d.denied,Ce())},hn=async()=>{if(!o||!D||U)return;let d=await o.setMicrophone(!P);P=d.on,U=d.denied,Ce()},oe=()=>{g.setAttribute("aria-pressed",String(M)),g.toggleAttribute("data-on",M);let d=M?n.markupOn:n.markupOff;g.setAttribute("title",d),g.setAttribute("aria-label",d)},mn=async d=>{!o?.setMarkup||!D||(M=await o.setMarkup(d,()=>{M=!1,oe()}),oe())},gn=()=>{D=!0,P=!1,U=!1,M=!1,g.hidden=!o?.setMarkup,Ce(),oe(),F=!1,h.hidden=!0,c.hidden=!0,c.setAttribute("aria-expanded","false"),e.removeEventListener("keydown",ne,!0),k.hidden=!1,_&&z(_.x,_.y),fn();let d=Date.now(),f=o?.limitSeconds??0,y=()=>{let E=(Date.now()-d)/1e3;ee=Math.max(0,5-Math.floor(E)),et(),R.textContent=f?`${ze(E)} / ${ze(f)}`:ze(E)};y(),$=e.defaultView?.setInterval(y,1e3)??null,j.focus()},Le=async d=>{if(D){D=!1,ee=0,$!==null&&(e.defaultView?.clearInterval($),$=null),k.hidden=!0,c.hidden=!1,_&&z(_.x,_.y),M&&(M=!1,await o?.setMarkup?.(!1,()=>{}),oe());try{await o?.stop(),O=!0}catch{O=!1}je(!1),d&&H(d)}},tt=()=>{if(!o||D)return;H("");let d;try{d=o.start({onUserStopped:()=>{Le()},onLimitReached:()=>{Le(n.limitReached)}})}catch(f){tn(f)||H(`${n.recordErrorPrefix}${String(f)}`,"error");return}d.then(()=>gn(),f=>{if(tn(f))return;let y=f instanceof Error?f.message:String(f);H(`${n.recordErrorPrefix}${y}`,"error")})},Me=d=>{Ze=d,b.disabled=d,m.disabled=d,x.disabled=d,C&&(C.disabled=d),L&&(L.disabled=d),b.textContent=d?n.sending:n.submit},bn=async d=>{if(d.preventDefault(),Ze)return;let f=x.value.trim();if(!f){x.focus();return}Me(!0),Ae=0,H("");try{await t(f,y=>{let E=Math.round(y*100);E<=Ae||(Ae=E,b.textContent=`${n.sending} ${E}%`)}),O=!1,Re(),H(n.success,"success"),Me(!1),e.defaultView?.setTimeout(()=>Qe(),1200)}catch(y){Me(!1);let E=y instanceof Error?y.message:String(y);H(`${n.errorPrefix}${E}`,"error"),x.focus()}},nt="espejo:widget:pos",W=e.defaultView,yn=5,re=!1,ie=!1,Ie=!1,ot=0,rt=0,it=0,st=0,_=null,se=null,at=(d,f)=>Math.max(0,Math.min(d,Math.max(0,f))),z=(d,f)=>{let y=W?.innerWidth??0,E=W?.innerHeight??0,G=s.offsetWidth,Oe=s.offsetHeight,de=at(d,y-G),ce=at(f,E-Oe);return de+G/2>y/2?(s.setAttribute("data-ax","r"),s.style.setProperty("--e-r",`${y-de-G}px`)):(s.setAttribute("data-ax","l"),s.style.setProperty("--e-x",`${de}px`)),ce+Oe/2>E/2?(s.setAttribute("data-ay","b"),s.style.setProperty("--e-b",`${E-ce-Oe}px`)):(s.setAttribute("data-ay","t"),s.style.setProperty("--e-y",`${ce}px`)),s.setAttribute("data-dragged",""),{x:de,y:ce}},vn=d=>{try{W?.localStorage.setItem(nt,JSON.stringify(d))}catch{}},xn=()=>{try{let d=W?.localStorage.getItem(nt);if(!d)return;let f=JSON.parse(d);typeof f.x=="number"&&typeof f.y=="number"&&(_=z(f.x,f.y))}catch{}},Be=d=>{if(d.button>0)return;re=!0,ie=!1;let f=s.getBoundingClientRect();it=f.left,st=f.top,ot=d.clientX,rt=d.clientY,se=d.currentTarget,se.setPointerCapture?.(d.pointerId)},lt=d=>{d.target?.closest("button")||Be(d)},ae=d=>{if(!re)return;let f=d.clientX-ot,y=d.clientY-rt;!ie&&Math.hypot(f,y)<yn||(ie=!0,_=z(it+f,st+y))},le=d=>{re&&(re=!1,se?.releasePointerCapture?.(d.pointerId),se=null,ie&&_&&(Ie=!0,vn(_)))},dt=()=>{_&&(_=z(_.x,_.y))},ct=()=>{if(Ie){Ie=!1;return}F?te():je()},ut=d=>{bn(d)},pt=()=>{Le()},ft=()=>{hn()},ht=()=>{mn(!M)},mt=()=>{Xe(),x.focus()},kn=ke(B);return c.addEventListener("click",ct),c.addEventListener("pointerdown",Be),c.addEventListener("pointermove",ae),c.addEventListener("pointerup",le),k.addEventListener("pointerdown",lt),k.addEventListener("pointermove",ae),k.addEventListener("pointerup",le),W?.addEventListener("resize",dt),m.addEventListener("click",te),w.addEventListener("submit",ut),j.addEventListener("click",pt),v.addEventListener("click",ft),g.addEventListener("click",ht),C?.addEventListener("click",tt),L?.addEventListener("click",mt),e.body.appendChild(s),xn(),{open:()=>{D||je()},destroy(){$!==null&&(e.defaultView?.clearInterval($),$=null),e.removeEventListener("keydown",ne,!0),kn(),c.removeEventListener("click",ct),c.removeEventListener("pointerdown",Be),c.removeEventListener("pointermove",ae),c.removeEventListener("pointerup",le),k.removeEventListener("pointerdown",lt),k.removeEventListener("pointermove",ae),k.removeEventListener("pointerup",le),W?.removeEventListener("resize",dt),m.removeEventListener("click",te),w.removeEventListener("submit",ut),j.removeEventListener("click",pt),v.removeEventListener("click",ft),g.removeEventListener("click",ht),C?.removeEventListener("click",tt),L?.removeEventListener("click",mt),s.remove()},shadowRootForTesting:l}}var on=we+`
431
+ :host {
432
+ all: initial !important;
433
+ position: fixed !important;
434
+ z-index: 2147483647 !important;
435
+ display: block !important;
436
+ }
437
+
438
+ .ef-root {
439
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
440
+ font-size: 14px;
441
+ line-height: 1.4;
442
+ color: var(--e-fg);
443
+ background: var(--e-bg);
444
+ border: 1px solid var(--e-border);
445
+ border-radius: 10px;
446
+ box-shadow: var(--e-shadow);
447
+ padding: 12px 14px;
448
+ width: 248px;
449
+ max-width: calc(100vw - 32px);
450
+ }
451
+
452
+ .ef-title {
453
+ margin: 0 0 10px;
454
+ font-size: 13px;
455
+ font-weight: 600;
456
+ }
457
+
458
+ .ef-options {
459
+ display: flex;
460
+ gap: 6px;
461
+ flex-wrap: wrap;
462
+ }
463
+
464
+ .ef-opt {
465
+ flex: 1 1 auto;
466
+ min-width: 34px;
467
+ min-height: 34px;
468
+ display: flex;
469
+ align-items: center;
470
+ justify-content: center;
471
+ font: inherit;
472
+ font-size: 18px;
473
+ line-height: 1;
474
+ border: 1px solid var(--e-border);
475
+ border-radius: 8px;
476
+ background: var(--e-bg);
477
+ color: var(--e-fg);
478
+ cursor: pointer;
479
+ padding: 6px;
480
+ }
481
+
482
+ .ef-options[data-kind='scale7'] .ef-opt {
483
+ font-size: 14px;
484
+ font-weight: 600;
485
+ min-width: 26px;
486
+ padding: 6px 2px;
487
+ }
488
+
489
+ .ef-opt:hover:not(:disabled) {
490
+ border-color: var(--e-accent);
491
+ }
492
+
493
+ .ef-opt:disabled {
494
+ opacity: 0.6;
495
+ cursor: default;
496
+ }
497
+
498
+ .ef-close {
499
+ position: absolute;
500
+ top: 6px;
501
+ right: 8px;
502
+ border: 0;
503
+ background: none;
504
+ color: var(--e-muted);
505
+ font-size: 16px;
506
+ line-height: 1;
507
+ cursor: pointer;
508
+ padding: 2px 4px;
509
+ }
510
+
511
+ .ef-thanks {
512
+ margin: 0;
513
+ font-size: 13px;
514
+ font-weight: 600;
515
+ color: var(--e-accent);
516
+ }
517
+
518
+ .ef-thanks[hidden],
519
+ .ef-title[hidden],
520
+ .ef-options[hidden] {
521
+ display: none;
522
+ }
523
+ `;var Je={title:"\xBFC\xF3mo estuvo tu experiencia?",thanks:"\xA1Gracias por tu feedback!",dismiss:"Cerrar",emojiSad:"Mala",emojiNeutral:"Normal",emojiHappy:"Buena",thumbsDown:"No me gust\xF3",thumbsUp:"Me gust\xF3",scaleLabel:"Puntaje"};function Ee(e){let t=e.doc??(typeof document<"u"?document:null);if(!t)return null;try{return jo(t,e.config,e.vote,{...Je,...e.text},e.theme??"auto")}catch{return null}}function Ro(e,t){if(e==="emoji3")return[{value:0,glyph:"\u{1F61E}",label:t.emojiSad},{value:1,glyph:"\u{1F610}",label:t.emojiNeutral},{value:2,glyph:"\u{1F60A}",label:t.emojiHappy}];if(e==="thumbs")return[{value:0,glyph:"\u{1F44E}",label:t.thumbsDown},{value:1,glyph:"\u{1F44D}",label:t.thumbsUp}];let{min:n,max:o}=Bt.scale7,r=[];for(let a=n;a<=o;a++)r.push({value:a,glyph:String(a),label:`${t.scaleLabel} ${a}`});return r}function jo(e,t,n,o,r){let{host:a,shadow:i}=xe(e,"data-espejo-feedback","bottom-left",r),l=Ro(t.kind,o).map(g=>`<button type="button" class="ef-opt" data-value="${g.value}" title="${g.label}" aria-label="${g.label}"><span aria-hidden="true">${g.glyph}</span></button>`).join("");i.innerHTML=`<style>${on}</style>
524
+ <div class="ef-root" role="dialog" aria-label="${o.title}">
525
+ <button type="button" class="ef-close" id="ef-close" aria-label="${o.dismiss}">\xD7</button>
526
+ <p class="ef-title" id="ef-title">${o.title}</p>
527
+ <div class="ef-options" id="ef-options" role="group" aria-label="${o.title}" data-kind="${t.kind}">${l}</div>
528
+ <p class="ef-thanks" id="ef-thanks" role="status" aria-live="polite" hidden>${o.thanks}</p>
529
+ </div>`;let p=i.querySelector(".ef-root"),u=i.getElementById("ef-close"),c=i.getElementById("ef-title"),h=i.getElementById("ef-options"),w=i.getElementById("ef-thanks"),x=Array.from(h.querySelectorAll(".ef-opt")),m=!1,b=null,A=()=>{b!==null&&(e.defaultView?.clearTimeout(b),b=null)},k=()=>{A(),e.removeEventListener("keydown",R,!0),a.remove()},N=g=>{if(!m){m=!0;for(let B of x)B.disabled=!0;n(g).catch(()=>{}),c.hidden=!0,h.hidden=!0,w.hidden=!1,b=e.defaultView?.setTimeout(k,1600)??null}},R=g=>{g.key==="Escape"&&(g.stopPropagation(),k())},j=g=>{let B=g.currentTarget??null;B&&N(Number(B.dataset.value))};for(let g of x)g.addEventListener("click",j);u.addEventListener("click",k);let v=ke(p);return e.addEventListener("keydown",R,!0),e.body.appendChild(a),{destroy(){A();for(let g of x)g.removeEventListener("click",j);u.removeEventListener("click",k),v(),e.removeEventListener("keydown",R,!0),a.remove()},shadowRootForTesting:i}}var Co="espejo:feedback:lastShown:";function rn(e){return`${Co}${e}`}function Se(e,t,n){try{let o=sn(n);if(!o)return!0;let r=o.getItem(rn(e));if(!r)return!0;let a=Number(r);return Number.isFinite(a)?Date.now()-a>=t*864e5:!0}catch{return!0}}function _e(e,t){try{sn(t)?.setItem(rn(e),String(Date.now()))}catch{}}function sn(e){return(e?.defaultView??(typeof window<"u"?window:void 0))?.localStorage??null}var Lo="__espejoInstallAnnotator";function an(e,t=document){return ye(e,"espejo.draw.js",Lo,t)}var dn="@espejo/browser",cn="0.1.0",Mo="https://app.espejo.dev",ln={source:"manual"},Te=class{constructor(t){this.recorder=null;this.uninstall=[];this.dom=null;this.routeSnapshot=null;this.snapshotFn=null;this.widget=null;this.lastReport=null;this.feedback=null;this.annotator=null;this.markupHost=null;this.video=null;this.videoBlob=null;this.videoContentType="video/webm";this.videoHasAudio=!1;this.videoMs=0;this.autoConfig=null;this.autoGuard=null;this.autoKilled=!1;this.autoInFlight=!1;this.triggerSink=null;this.triggerBuf=[];this.triggersStop=null;if(!t?.key)throw new Error("Espejo: missing data-key (the project's public key)");this.config={...t,ingestUrl:t.ingestUrl||Mo,mode:t.mode||"ring"},this.pristineFetch=typeof globalThis.fetch=="function"?globalThis.fetch.bind(globalThis):void 0}get recording(){return this.recorder!==null}start(){if(this.recorder)return;let t=new V(this.config.budgets);this.recorder=t,this.autoKilled=this.config.autoReport==="off",this.config.capture==="dom"&&(this.routeSnapshot=qt({ingestUrl:this.config.ingestUrl,key:this.config.key,getSnapshot:()=>this.snapshotFn,fetchImpl:this.pristineFetch})),this.uninstall=[Ht(t,{ignoreOrigins:[this.config.ingestUrl],onEntry:n=>this.onNetworkEntry(n)}),Ft(t,{onEntry:(n,o)=>this.onConsoleEntry(n,o)}),Ut(t,{onEntry:(n,o)=>this.pushTriggerSignal({kind:n,tMs:o})}),$t(t,n=>{this.routeSnapshot?.onRoute(),this.pushTriggerSignal({kind:"nav",tMs:t.elapsed(),url:n})})],this.config.capture==="dom"&&this.enableDom(t),this.config.button!=="off"&&(this.widget=nn({report:(n,o)=>this.report(n,ln,o),text:this.config.buttonText,theme:this.config.theme,position:this.config.position,icon:this.config.buttonIcon,video:{supported:()=>K(),start:n=>this.startVideo(n),setMicrophone:n=>this.setMicrophone(n),stop:async()=>{await this.stopVideo()},discard:()=>this.discardVideo(),setMarkup:(n,o)=>this.setMarkup(n,o),limitSeconds:240}})),this.loadAutoReport(),this.config.feedback!=="off"&&this.loadFeedback()}pushTriggerSignal(t){try{this.triggerSink?this.triggerSink(t):this.triggerBuf.length<300&&this.triggerBuf.push(t)}catch{}}async loadTriggers(){if(!this.recorder||this.triggersStop)return;let t=await ye(this.config.ingestUrl,"espejo.triggers.js",Yt);if(!(!t||!this.recorder||this.triggersStop))try{let n=t({ingestUrl:this.config.ingestUrl,key:this.config.key,fetchImpl:this.pristineFetch,now:()=>this.recorder?.elapsed()??0,subscribe:o=>{this.triggerSink=o;for(let r of this.triggerBuf.splice(0))o(r)},theme:this.config.theme});n&&(this.triggersStop=n.stop)}catch{}}async loadFeedback(){let t=await ge(this.config.ingestUrl,this.config.key,this.pristineFetch);t?.enabled&&(!this.recorder||this.feedback||Se(this.config.key,t.cadence_days)&&(_e(this.config.key),this.feedback=Ee({config:t,vote:n=>ve({ingestUrl:this.config.ingestUrl,key:this.config.key,kind:t.kind,value:n,pageHost:typeof location<"u"?location.host:void 0,userRef:this.config.userRef},this.pristineFetch),text:this.config.feedbackText,theme:this.config.theme})))}async loadAutoReport(){let{config:t,videoSurface:n,hasTriggers:o}=await me(this.config.ingestUrl,this.config.key,this.pristineFetch);n&&(this.config.videoSurface=n),o&&this.loadTriggers(),t&&(this.autoConfig=t,this.autoGuard=new Lt(t))}setAutoReport(t){this.autoKilled=!t}identify(t){this.config.userRef=t||void 0}canOpenReport(){return!!this.widget&&!this.video}openReport(){let t=this.canOpenReport();return t&&this.widget.open(),t}get lastReportId(){return this.lastReport}get autoReportActive(){return!!this.autoConfig&&!this.autoKilled}autoEnabled(t){return this.autoKilled||!this.autoConfig||!this.recorder?!1:this.autoConfig.triggers.includes(t)}onConsoleEntry(t,n){if(n==="console"&&t.level!=="error")return;this.pushTriggerSignal({kind:"console_error",tMs:this.recorder?.elapsed()??0});let o=n==="window_error"?"auto:uncaught":n==="unhandled_rejection"?"auto:unhandled_rejection":"auto:console_error";this.maybeAutoReport(o,Ue(o,t.text,t.stack))}onNetworkEntry(t){let n=Mt(t.status,!!t.error);n&&(this.pushTriggerSignal({kind:"http_error",tMs:this.recorder?.elapsed()??0}),this.maybeAutoReport(n,Ue(n,`${t.method} ${t.url}`,String(t.status??t.error))))}maybeAutoReport(t,n){try{if(!this.autoEnabled(t)||this.autoInFlight||!this.autoGuard?.check(n).allowed)return;this.autoInFlight=!0,this.report(void 0,{source:"auto",trigger:t}).catch(()=>{}).finally(()=>{this.autoInFlight=!1})}catch{this.autoInFlight=!1}}async enableDom(t){let n=this.config.rrwebRecord??await Gt();if(!n||this.recorder!==t)return;this.dom=Wt(t,n);let o=this.config.rrwebSnapshot??await Vt();this.recorder===t&&(this.snapshotFn=o,o&&this.routeSnapshot?.onRoute())}stop(){for(let t of this.uninstall.splice(0))try{t()}catch{}this.dom?.stop(),this.dom=null,this.routeSnapshot?.stop(),this.routeSnapshot=null,this.snapshotFn=null,this.widget?.destroy(),this.widget=null,this.feedback?.destroy(),this.feedback=null;try{this.triggersStop?.()}catch{}this.triggersStop=null,this.triggerSink=null,this.triggerBuf=[],this.teardownMarkup(),this.recorder=null}async startVideo(t={}){if(!K())throw new Error("This browser can't record the screen.");this.video||(this.video=await Kt({...t,surface:t.surface??this.config.videoSurface}),this.videoContentType=this.video.contentType)}async setMicrophone(t){return await this.video?.setMicrophone(t)??{on:!1,denied:!1}}get microphoneOn(){return this.video?.microphoneOn??!1}async stopVideo(){return this.video?(this.videoHasAudio=this.video.hasAudio,this.videoBlob=await this.video.stop(),this.videoMs=this.video.durationMs,this.video=null,this.videoBlob):null}get recordingVideo(){return this.video!==null}async setMarkup(t,n=()=>{}){if(!t)return this.teardownMarkup(),!1;if(this.annotator)return!0;if(typeof document>"u")return!1;let o=await an(this.config.ingestUrl);if(!o)return!1;let r=document.createElement("div");r.setAttribute("data-espejo-markup","");let a=r.attachShadow({mode:"closed"});return document.body.appendChild(r),this.markupHost=r,this.annotator=o({root:a,onExit:()=>{this.teardownMarkup(),n()}}),this.annotator?!0:(this.teardownMarkup(),!1)}teardownMarkup(){this.annotator?.destroy(),this.annotator=null,this.markupHost?.remove(),this.markupHost=null}discardVideo(){this.videoBlob=null,this.videoHasAudio=!1,this.videoMs=0}snapshot(){return this.recorder?.snapshot()??null}async report(t,n=ln,o){let r=this.recorder;if(!r)return null;let a=n.source==="auto";this.video&&!a&&await this.stopVideo();let i=r.snapshot(),s=this.dom?.events(),l=!a&&this.videoBlob?{blob:this.videoBlob,contentType:this.videoContentType}:void 0,p=await Jt({ingestUrl:this.config.ingestUrl,key:this.config.key,manifest:this.manifest(r,t,{dom:!!s?.length,video:!!l,audio:!!l&&this.videoHasAudio},n),events:i,dom:s?.length?s:void 0,video:l,onProgress:a?void 0:o},this.pristineFetch);return r.clear(),this.dom?.buffer.clear(),a||(this.videoBlob=null,this.videoHasAudio=!1,this.videoMs=0,this.lastReport=p.session_id),p.url}manifest(t,n,o,r){return{bundle_version:_t,source:"web-sdk",mode:o.video?"video":o.dom?"dom":"events",trigger:r.source==="auto"?r.trigger:this.config.mode==="always"?"always":"manual",report_source:r.source,description:n??null,started_at:t.startedAtIso,duration_ms:t.elapsed(),page:{host:typeof location<"u"?location.host:null,url:typeof location<"u"?T(location.href):null},app:{release:this.config.release??null,env:this.config.env??null},user_ref:this.config.userRef??null,sdk:{name:dn,version:cn},dropped:{...t.dropped,dom_segments:this.dom?.buffer.droppedCount??0},has_dom:o.dom,has_video:o.video,...o.video?{video_ms:this.videoMs}:{},has_audio:o.audio}}};function Io(e={}){if(typeof document>"u")return null;let t=document.currentScript,n=t?.dataset.key;if(!n)return null;let o=new Te({...e,key:n,ingestUrl:t?.dataset.ingest,mode:t?.dataset.mode==="always"?"always":"ring",capture:t?.dataset.capture==="dom"?"dom":e.capture??"events",button:t?.dataset.button==="off"?"off":e.button??"on",autoReport:t?.dataset.autoReport==="off"?"off":e.autoReport??"on",feedback:t?.dataset.feedback==="off"?"off":e.feedback??"on",feedbackText:Do(t?.dataset.feedbackText)??e.feedbackText,theme:Bo(t?.dataset.theme)??e.theme??"auto",position:Oo(t?.dataset.position)??e.position,buttonIcon:t?.dataset.buttonIcon??e.buttonIcon,videoSurface:t?.dataset.videoSurface,release:t?.dataset.release,env:t?.dataset.env,userRef:t?.dataset.userRef??e.userRef});return o.start(),globalThis.espejo=o,o}function Bo(e){return e==="light"||e==="dark"||e==="auto"?e:void 0}function Oo(e){return e==="bottom-right"||e==="bottom-left"||e==="top-right"||e==="top-left"?e:void 0}function Do(e){if(e)try{let t=JSON.parse(e);return t&&typeof t=="object"?t:void 0}catch{return}}0&&(module.exports={BLOCK_ATTRIBUTE,BLOCK_SELECTOR,DEFAULT_BUDGETS,Espejo,FEEDBACK_DEFAULT_TEXT,MASK_SELECTOR,MAX_VIDEO_SECONDS,RingBuffer,SDK_NAME,SDK_VERSION,SegmentRing,SessionRecorder,WIDGET_DEFAULT_TEXT,autoStart,canShowFeedback,fetchAutoReportConfig,fetchFeedbackConfig,installFeedbackWidget,normalizeAutoReportConfig,normalizeFeedbackConfig,sealFeedbackShown,sendVote,videoSupported});