@espejo/browser 0.3.0 → 0.4.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/agent.cjs +3 -3
- package/dist/agent.js +1 -1
- package/dist/chat.cjs +14 -14
- package/dist/chat.js +15 -15
- package/dist/{chunk-HP3BBKZO.js → chunk-VJ6CMZCB.js} +3 -3
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{A as $,G as m,I as V,b as A,w as T,x as
|
|
2
|
-
`).length+1;let u=n.body??i;return u&&
|
|
3
|
-
`)}function y(e,t,n){if(e.truncated)return;let r=" ".repeat(t)+n;if(e.used+r.length+1>e.max-z.length-1){e.truncated=!0;return}e.lines.push(r),e.used+=r.length+1}function d(e){if(!e.text.length)return;let t=f(e.text.join(" "),me);e.text=[],t&&y(e,e.textDepth,`text ${S(t)}`)}function x(e,t,n,r,o){for(let i=e.firstChild;i&&!o.truncated;i=i.nextSibling)if(i.nodeType===3){if(r)continue;let s=i.nodeValue??"";if(!s.trim())continue;o.text.length||(o.textDepth=t),n?o.text[o.text.length-1]!=="***"&&o.text.push("***"):o.text.push(s)}else i.nodeType===1&&he(i,t,n,r,o)}function he(e,t,n,r,o){if(K.has(e.tagName)||e.hasAttribute(D)||!N(e))return;if(e.hasAttribute(m)){d(o),y(o,t,"[blocked]");return}n=n||e.hasAttribute(E);let i=Te(e);if(i){d(o),y(o,t,ve(e,i,n,o)),b(e)||x(e,t+1,n,!0,o);return}let s=ye(e);if(s){d(o);let a=Q(e,o.doc,n);y(o,t,a?`${s} ${S(a)}`:s),x(e,t+1,n,r,o),d(o);return}let l=xe(e);if(l){d(o);let a=n?"***":L(e,null);a&&y(o,t,`heading ${S(a)} [h${l}]`),x(e,t+1,n,!0,o);return}let u=e.tagName==="LABEL"&&(e.hasAttribute("for")||!!e.querySelector("input,select,textarea")),c=Ee.has(e.tagName);c&&d(o),x(e,t,n,r||u,o),c&&d(o)}function N(e){if(e.hidden||e.getAttribute("aria-hidden")==="true"||e.tagName==="INPUT"&&e.type==="hidden"||e.tagName==="DIALOG"&&!e.hasAttribute("open"))return!1;let t=e.parentElement;if(t?.tagName==="DETAILS"&&!t.hasAttribute("open")&&e.tagName!=="SUMMARY")return!1;let n=e.ownerDocument.defaultView;if(!n)return!0;let r=n.getComputedStyle(e);return r.display!=="none"&&r.visibility!=="hidden"&&r.visibility!=="collapse"}function Te(e){let t=e.getAttribute("role");if(t&&Ae.has(t))return t;switch(e.tagName){case"A":if(e.hasAttribute("href"))return"link";break;case"BUTTON":case"SUMMARY":return"button";case"SELECT":{let r=e;return r.multiple||r.size>1?"listbox":"combobox"}case"TEXTAREA":return"textbox";case"INPUT":{let r=R(e);return r==="checkbox"||r==="radio"?r:r==="button"||r==="submit"||r==="reset"||r==="image"?"button":r==="range"?"slider":r==="file"?"file":r==="hidden"?null:"textbox"}}if(I(e))return"textbox";let n=e.getAttribute("tabindex");return n!==null&&Number(n)>=0?t||"focusable":null}function ye(e){let t=e.getAttribute("role");return t&&Y[t]?Y[t]:ge[e.tagName]??null}function xe(e){let t=/^H([1-6])$/.exec(e.tagName);return t?Number(t[1]):e.getAttribute("role")==="heading"?Number(e.getAttribute("aria-level"))||2:0}function R(e){return(e.getAttribute("type")??"").toLowerCase()}function I(e){let t=e.getAttribute("contenteditable")?.toLowerCase();return t===""||t==="true"||t==="plaintext-only"}function B(e){for(let t=e;t;t=t.parentElement){let n=t.getAttribute("contenteditable")?.toLowerCase();if(n==="false")return!1;if(n!==void 0&&I(t))return!0}return!1}function b(e){return e.tagName==="INPUT"||e.tagName==="SELECT"||e.tagName==="TEXTAREA"||I(e)}function ve(e,t,n,r){let o=k(e,r.doc,n),i=o?`${t} ${S(o)}`:t;i+=` ref=${r.refs.refFor(e)}`;let s=we(e,t,n);return s.length?`${i} ${s.join(" ")}`:i}function Q(e,t,n){let r=e.getAttribute("aria-labelledby");if(r){let i=r.split(/\s+/).map(l=>t.getElementById(l)).filter(l=>!!l).map(l=>L(l,null)).join(" "),s=f(i,p);if(s)return n?"***":s}let o=f(e.getAttribute("aria-label"),p);return o&&n?"***":o}function k(e,t,n){let r=Se(e,t);return r&&n?"***":r}function Se(e,t){let n=Q(e,t,!1);if(n)return n;let r=e.tagName,o=r==="INPUT"?R(e):"";if(r==="INPUT"||r==="SELECT"||r==="TEXTAREA"){let l=Re(e,t),u=f(l.map(c=>L(c,e)).join(" "),p);if(u)return u;if(o==="button"||o==="submit"||o==="reset"){let c=f(e.getAttribute("value"),p);if(c)return c}}let i=f(e.getAttribute("alt"),p);if(i)return i;if(!b(e)){let l=L(e,null);if(l)return l}let s=f(e.getAttribute("title"),p);return s||(r==="INPUT"&&o!=="password"||r==="TEXTAREA"?f(e.getAttribute("placeholder"),p):"")}function Re(e,t){let n=[],r=e.id;if(r)for(let i of t.querySelectorAll("label[for]"))i.getAttribute("for")===r&&n.push(i);let o=e.closest("label");return o&&!n.includes(o)&&n.push(o),n}function L(e,t){if(b(e)||B(e)||e.closest(`[${m}]`))return"";if(e.closest(`[${E}]`))return"***";let n=[],r=o=>{for(let i=o.firstChild;i;i=i.nextSibling){if(i.nodeType===3){n.push(i.nodeValue??"");continue}if(i.nodeType!==1)continue;let s=i;if(!(s===t||K.has(s.tagName)||s.hasAttribute(m))&&!(b(s)||!N(s))){if(s.hasAttribute(E)){n.push("***");continue}if(s.tagName==="IMG"){n.push(s.getAttribute("alt")??"");continue}r(s)}}};return r(e),f(n.join(" "),p)}function we(e,t,n){let r=[],o=e.tagName,i=o==="INPUT"?R(e):"",s=c=>e.getAttribute(`aria-${c}`);if(o==="SELECT"){let c=[...e.selectedOptions].map(a=>f(a.textContent,p)).filter(Boolean);c.length&&r.push(`value=${S(n?"***":c.join(", "))}`)}else if(i==="checkbox"||i==="radio")r.push(e.checked?"[checked]":"[unchecked]");else if(o==="TEXTAREA"||o==="INPUT"&&U.has(i))i==="password"&&r.push("[password]"),r.push(e.value?"[filled]":"[empty]");else if(I(e))r.push(e.textContent?.trim()?"[filled]":"[empty]");else if(t==="checkbox"||t==="switch"||s("checked")!==null){let c=s("checked");r.push(c==="true"?"[checked]":c==="mixed"?"[mixed]":"[unchecked]")}(F(e)||s("disabled")==="true")&&r.push("[disabled]");let l=o==="SUMMARY"?String(!!e.parentElement?.hasAttribute("open")):s("expanded");l==="true"?r.push("[expanded]"):l==="false"&&r.push("[collapsed]"),s("selected")==="true"&&r.push("[selected]"),(e.hasAttribute("required")||s("required")==="true")&&r.push("[required]"),(e.readOnly||s("readonly")==="true")&&r.push("[readonly]");let u=Me(e,i,n);return u!==null&&r.push(u?`[invalid: ${u}]`:"[invalid]"),r}var _e=["valueMissing","typeMismatch","patternMismatch","tooShort","tooLong","rangeUnderflow","rangeOverflow","stepMismatch","badInput","customError"];function Me(e,t,n){let r=e.validity,o=e.getAttribute("aria-invalid"),i=!!r&&r.valid===!1;return!i&&(!o||o==="false")?null:!i||n||t==="password"?"":_e.filter(s=>r[s]===!0).join(", ")}function F(e){if(e.disabled)return!0;try{if(e.matches(":disabled"))return!0}catch{}if(!/^(BUTTON|INPUT|SELECT|TEXTAREA)$/.test(e.tagName))return!1;let t=e.closest("fieldset[disabled]");if(!t)return!1;let n=[...t.children].find(r=>r.tagName==="LEGEND");return!n||!n.contains(e)}function f(e,t){let n=(e??"").replace(/\s+/g," ").trim();return n.length>t?`${n.slice(0,t)}\u2026`:n}function S(e){return`"${e.replace(/"/g,"'")}"`}function w(e){return!!e.closest(`[${E}]`)}function P(e){return!!e.closest(`[${m}]`)}var Ce=4e3,Le=50,Ne=250,J=50;async function te(e,t){let n=Ue(e,t),r=Be(e,t),o=await Ie(e,t,n,r);for(let i of e.actionHandlers)try{i({action:t,label:n,...r,result:o})}catch{}return o}function j(e,t){if(!t||!_.includes(t.type))return{error:"unknown_action"};if(!e.policy.allow.includes(t.type))return{error:"not_allowed"};if(t.type==="navigate"){let o=g(t.url);return o?{el:null,target:o}:{error:"cross_origin"}}let n=typeof t.ref=="string"?e.refs.resolve(t.ref):null;if(!n)return{error:"stale_ref"};if(P(n))return{error:"blocked"};let r=null;if((t.type==="click"||t.type==="fill")&&F(n))return{error:"disabled"};if(t.type==="click"){if(ne(n))return{error:"cross_origin"};let o=O(n);o&&(r=g(o))}if(t.type==="fill"){let o=$e(n,t.value);if(o)return{error:o}}return{el:n,target:r}}async function Ie(e,t,n,r){let o=j(e,t);if("error"in o)return{ok:!1,error:o.error};let i=e.policy.confirm.includes(t.type);if(i){let c=await He(e,{action:t,label:n,...r});if(c!==!0)return{ok:!1,error:c};if(o=j(e,t),"error"in o)return{ok:!1,error:o.error}}if(e.presence){let c=await X(e.presence,t,o.el);if(c!==!0)return{ok:!1,error:c};if(o=j(e,t),"error"in o)return{ok:!1,error:o.error};if(!i&&e.policy.confirm.includes(t.type))return{ok:!1,error:"confirmation_required"}}let{el:s,target:l}=o;re();let u=t.type==="click"&&!l&&s.hasAttribute("aria-expanded")&&s.hasAttribute("aria-controls")?Z(s):null;try{if(t.type==="navigate")location.assign(l.href);else if(t.type==="highlight")s.scrollIntoView({block:"center"}),Ge(s);else if(t.type==="scroll_to")s.scrollIntoView({block:"center"});else if(t.type==="click"){if(!ke(s))return{ok:!1,error:"cross_origin"}}else{let c=De(s,t.value??"");if(c)return{ok:!1,error:c}}}catch{return{ok:!1,error:"action_failed"}}await je();for(let c=0;u&&Oe(u,Z(s));c+=J){if(c>=Ne)return{ok:!1,error:"no_effect",snapshot:h(e.refs)};await new Promise(a=>setTimeout(a,J))}return{ok:!0,snapshot:h(e.refs)}}function ke(e){let t=e.getBoundingClientRect(),n=e.ownerDocument.defaultView,r=n&&typeof n.PointerEvent=="function"?n.PointerEvent:null,o=n?.MouseEvent??MouseEvent,i=(l,u,c)=>{let a={bubbles:l!=="pointerenter",composed:!0,cancelable:l!=="pointerenter",view:n,clientX:t.left+t.width/2,clientY:t.top+t.height/2,button:0,buttons:u,detail:l==="mousedown"||l==="mouseup"||l==="click"?1:0};return c&&r&&Object.assign(a,{pointerId:1,pointerType:"mouse",isPrimary:!0}),e.dispatchEvent(c&&r?new r(l,a):new o(l,a))};i("pointerover",0,!0),i("pointerenter",0,!0),i("mouseover",0,!1);let s=i("pointerdown",1,!0);return s&&i("mousedown",1,!1)&&e.focus?.(),i("pointerup",0,!0),s&&i("mouseup",0,!1),ne(e)?!1:(i("click",0,!1),!0)}var Pe='[role="menu"],[role="listbox"],[role="dialog"],[role="grid"],[role="tree"],dialog';function Z(e){let t=e.ownerDocument,n=(e.getAttribute("aria-controls")??"").split(/\s+/).map(r=>r&&t.getElementById(r));return[e.isConnected,e.getAttribute("aria-expanded"),...n.filter(r=>r&&ee(r)),null,...[...t.querySelectorAll(Pe)].filter(ee)]}var Oe=(e,t)=>e.length===t.length&&e.every((n,r)=>n===t[r]);function ee(e){for(let t=e;t;t=t.parentElement)if(!N(t))return!1;return!0}function ne(e){let t=O(e);if(t)return!g(t);let n=e.form,r=(e.getAttribute("type")??"").toLowerCase(),o=e.tagName==="BUTTON"?r==="submit"||!r:e.tagName==="INPUT"&&(r==="submit"||r==="image");if(!n||!o)return!1;let i=(e.getAttribute("formaction")??n.getAttribute("action")??"").trim();return!!i&&!g(i)}function O(e){let t=e.closest("a[href],area[href]");return t?(t.getAttribute("href")??"").trim()||location.href:null}async function He(e,t){if(!e.confirmHandlers.size)return"confirmation_required";try{return(await Promise.all([...e.confirmHandlers].map(r=>r(t)))).every(r=>r===!0)?!0:"declined"}catch{return"declined"}}function $e(e,t){if(typeof t!="string")return"missing_value";let n=e.tagName;if(n==="INPUT"){let r=R(e);if(r==="password"||r==="file"||r==="hidden")return"forbidden";if(!U.has(r))return"not_fillable"}else if(n!=="TEXTAREA"&&n!=="SELECT")return"not_fillable";return w(e)?"forbidden":e.readOnly?"readonly":null}function De(e,t){let n;if(e.tagName==="SELECT"){let o=e,i=[...o.options].find(s=>s.value===t)??[...o.options].find(s=>(s.textContent??"").replace(/\s+/g," ").trim()===t.trim());if(!i)return"invalid_value";t=i.value,n=HTMLSelectElement.prototype}else n=e.tagName==="TEXTAREA"?HTMLTextAreaElement.prototype:HTMLInputElement.prototype;e.focus?.();let r=Object.getOwnPropertyDescriptor(n,"value")?.set;return r?r.call(e,t):e.value=t,e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})),null}function g(e){if(typeof e!="string"||!e.trim())return null;try{let t=new URL(e,location.href);return t.username||t.password?null:t.origin===location.origin&&/^https?:$/.test(t.protocol)?t:null}catch{return null}}function Ue(e,t){if(t?.type==="navigate"){let i=typeof t.url=="string"?t.url:"?";return`navigate to ${g(i)?.href??i}`}let n=t&&typeof t.ref=="string"?e.refs.resolve(t.ref):null,r=n&&!P(n)?k(n,n.ownerDocument,w(n)):"",o=`${t?.type??"?"} ${r?`"${r}"`:t?.ref??"?"}`;if(t?.type==="fill"&&typeof t.value=="string"&&(o+=` with "${t.value}"`),t?.type==="click"&&n){let i=O(n);i&&(o+=` (goes to ${g(i)?.href??i})`)}return o}function Be(e,t){if(!t)return{};if(t.type==="navigate")return typeof t.url=="string"?{destination:g(t.url)?.href??t.url}:{};let n=typeof t.ref=="string"?e.refs.resolve(t.ref):null,r=n&&!P(n)?k(n,n.ownerDocument,w(n)):"",o={},i=r||(typeof t.ref=="string"?t.ref:"");if(i&&(o.target=i),t.type==="fill"&&typeof t.value=="string"&&(o.value=t.value),t.type==="click"&&n){let s=O(n);s&&(o.destination=g(s)?.href??s)}return o}var Fe=100;function je(){return new Promise(e=>{let t=!1,n=()=>{t||(t=!0,setTimeout(e,Le))};typeof requestAnimationFrame=="function"&&requestAnimationFrame(n),setTimeout(n,Fe)})}var G=null;function Ge(e){let t=e.ownerDocument,{host:n,shadow:r}=V(t,D,"top-left"),o=t.createElement("div");o.setAttribute("style","position:absolute;inset:0;border:3px solid #2f6f4f;border-radius:6px;box-shadow:0 0 0 4px rgba(47,111,79,.25);pointer-events:none"),r.appendChild(o);let i=()=>{let u=e.getBoundingClientRect();n.setAttribute("style",`position:fixed;top:${u.top-4}px;left:${u.left-4}px;width:${u.width+8}px;height:${u.height+8}px;z-index:2147483647;pointer-events:none;display:block;margin:0;padding:0`)};i(),(t.body??t.documentElement).appendChild(n);let s=t.defaultView;s?.addEventListener("scroll",i,!0),s?.addEventListener("resize",i);let l=setTimeout(re,Ce);G={host:n,stop:()=>{clearTimeout(l),s?.removeEventListener("scroll",i,!0),s?.removeEventListener("resize",i),n.remove()}}}function re(){G?.stop(),G=null}var qe=10,Ve=10,oe=6e4,ie=160,se=["page","recent","errors"],Xe=`[${E}],[${m}],[contenteditable],textarea,input,select`;function le(e,t,n={}){let r=Array.isArray(n?.include)?n.include.filter(l=>se.includes(l)):se,o=typeof window<"u"?window:null,i=r.some(l=>l!=="page")?We(t):null,s=n?.maxChars;return{version:T,page:r.includes("page")?h(e,{maxChars:s}):"",url:typeof location<"u"?A(location.href):"",viewport:{w:o?.innerWidth??0,h:o?.innerHeight??0,scrollY:Math.round(o?.scrollY??0),scrollH:typeof document<"u"?document.documentElement?.scrollHeight??0:0},recent:i&&r.includes("recent")?Ye(i):[],errors:i&&r.includes("errors")?ze(i):[]}}function We(e){try{return e&&typeof e.snapshot=="function"?e.snapshot():null}catch{return null}}function Ye(e){let t=e.duration_ms,n=[];for(let r of e.interactions){let o=r.t_ms??0,i=Ke(r);n.push({t:o,line:`${r.kind} ${i}`.trim()+H(t,o)})}for(let r of e.navigations)n.push({t:r.t_ms,line:`nav ${A(r.url)}${H(t,r.t_ms)}`});return n.sort((r,o)=>r.t-o.t).slice(-qe).map(r=>ce(r.line))}function ze(e){let t=e.duration_ms,n=[];for(let r of e.network){let o=r.t_ms??0;if(t-o>oe)continue;let i=!!r.error;if(!i&&!(r.status!==null&&r.status>=400))continue;let s=i?`failed (${r.error})`:String(r.status);n.push({t:o,line:`${r.method??"GET"} ${A(r.url??"")} ${s}${H(t,o)}`})}for(let r of e.console){let o=r.t_ms??0;if(r.level!=="error"||t-o>oe)continue;let i=r.text.replace(/\s+/g," ").trim().replace(/https?:\/\/\S+/g,s=>A(s));n.push({t:o,line:`console.error ${q(i.slice(0,120))}${H(t,o)}`})}return n.sort((r,o)=>r.t-o.t).slice(-Ve).map(r=>ce(r.line))}function Ke(e){let t=Je(e.selector),n=e.role||e.tag||"";if(!t||t.closest(`[${E}],[${m}]`))return n;if(b(t)||B(t)||t.querySelector(Xe)){let r=(t.getAttribute("aria-label")||t.getAttribute("data-testid")||"").replace(/\s+/g," ").trim();return r?`${n} ${q(r.slice(0,80))}`.trim():n}return e.label&&Qe(e.label,t)?q(e.label):n}function Qe(e,t){let n=e.replace(/…$/,"");return[t.getAttribute("data-testid"),t.getAttribute("data-test-id"),t.getAttribute("aria-label"),t.getAttribute("title"),t.innerText||t.textContent,t.getAttribute("name"),t.id].some(o=>!!o&&o.replace(/\s+/g," ").trim().startsWith(n))}function Je(e){if(!e||typeof document>"u")return null;try{return document.querySelector(e)}catch{return null}}function H(e,t){return` (${Math.max(0,Math.round((e-t)/1e3))}s ago)`}function q(e){return`"${e.replace(/"/g,"'")}"`}function ce(e){return e.length>ie?`${e.slice(0,ie)}\u2026`:e}function bt(e){let t={refs:new v,policy:{allow:[...M.allow],confirm:[...M.confirm]},confirmHandlers:new Set,actionHandlers:new Set};return{getContext:n=>le(t.refs,e,n),act:async n=>{let r=await te(t,n);return W(t.presence??null,n,r),r},tools:(n=>$(n.format,n.allow??t.policy.allow)),policy(n){let r=s=>Array.isArray(s)?s.filter(l=>_.includes(l)):null,o=r(n?.allow),i=r(n?.confirm);return o&&(t.policy.allow=o),i&&(t.policy.confirm=i),{allow:[...t.policy.allow],confirm:[...t.policy.confirm]}},presence(n){return t.presence=n&&typeof n=="object"?n:null,()=>{t.presence===n&&(t.presence=null)}},on(n,r){if(n!=="action_confirm"&&n!=="action")return()=>{};let o=n==="action_confirm"?t.confirmHandlers:t.actionHandlers;return o.add(r),()=>{o.delete(r)}}}}export{ue as a,D as b,v as c,h as d,Ce as e,bt as f};
|
|
1
|
+
import{A as $,G as m,I as V,b as A,w as T,x as y,y as H}from"./chunk-5KPTJYDE.js";var ue=1500,M=new WeakMap;async function X(e,t,n){let r;M.set(t,n);try{return await Promise.race([Promise.resolve().then(()=>e.before?.(t,n)),new Promise(o=>r=setTimeout(o,1500))]),!0}catch{return"declined"}finally{clearTimeout(r)}}function W(e,t,n){if(!t||!M.has(t))return;let r=M.get(t)??null;M.delete(t);try{e?.after?.(t,r,n)}catch{}}var E="data-espejo-mask",D="data-espejo-agent",ae=12e3,fe=500,pe=1e5,p=80,me=120,z="[truncated]",de=2e3,S=class{constructor(){this.byElement=new WeakMap;this.byRef=new Map;this.next=1}refFor(t){let n=this.byElement.get(t);return n||(n=`e${this.next++}`,this.byElement.set(t,n),this.byRef.set(n,new WeakRef(t))),n}resolve(t){let n=this.byRef.get(t)?.deref();return n?n.isConnected?n:null:(this.byRef.delete(t),null)}sweep(){if(!(this.byRef.size<de))for(let[t,n]of this.byRef)n.deref()||this.byRef.delete(t)}},K=new Set(["SCRIPT","STYLE","NOSCRIPT","TEMPLATE","HEAD","META","LINK","IFRAME","SVG","svg"]),ge={MAIN:"main",NAV:"nav",HEADER:"header",FORM:"form",DIALOG:"dialog"},Y={main:"main",navigation:"nav",banner:"header",form:"form",dialog:"dialog",alertdialog:"dialog"},Ae=new Set(["button","link","tab","menuitem","checkbox","switch","combobox","option"]),Ee=new Set(["P","DIV","LI","TD","TH","DT","DD","SECTION","ARTICLE","ASIDE","FOOTER","BLOCKQUOTE","PRE","TR","UL","OL","TABLE","FIGCAPTION","LEGEND","FIELDSET"]),U=new Set(["","text","email","search","tel","url","number","password","date","datetime-local","month","week","time"]);function be(e){return typeof e!="number"||!Number.isFinite(e)?ae:Math.min(pe,Math.max(fe,Math.floor(e)))}function h(e,t={}){let n=t.doc??document,r=n.defaultView,o=be(t.maxChars);e.sweep();let i=n.documentElement,s=[`espejo-snapshot/${T}`,`url ${A(n.location?.href??"")}`,`title ${f(n.title,p)}`,`viewport ${r?.innerWidth??0}x${r?.innerHeight??0}`,`scroll ${Math.round(r?.scrollY??0)}/${i?.scrollHeight??0}`],l={refs:e,lines:s,used:0,max:o,truncated:!1,text:[],textDepth:0,doc:n};l.used=s.join(`
|
|
2
|
+
`).length+1;let u=n.body??i;return u&&v(u,0,_(u),!1,l),d(l),l.truncated&&l.lines.push(z),l.lines.join(`
|
|
3
|
+
`)}function x(e,t,n){if(e.truncated)return;let r=" ".repeat(t)+n;if(e.used+r.length+1>e.max-z.length-1){e.truncated=!0;return}e.lines.push(r),e.used+=r.length+1}function d(e){if(!e.text.length)return;let t=f(e.text.join(" "),me);e.text=[],t&&x(e,e.textDepth,`text ${R(t)}`)}function v(e,t,n,r,o){for(let i=e.firstChild;i&&!o.truncated;i=i.nextSibling)if(i.nodeType===3){if(r)continue;let s=i.nodeValue??"";if(!s.trim())continue;o.text.length||(o.textDepth=t),n?o.text[o.text.length-1]!=="***"&&o.text.push("***"):o.text.push(s)}else i.nodeType===1&&he(i,t,n,r,o)}function he(e,t,n,r,o){if(K.has(e.tagName)||e.hasAttribute(D)||!L(e))return;if(e.hasAttribute(m)){d(o),x(o,t,"[blocked]");return}n=n||e.hasAttribute(E);let i=Te(e);if(i){d(o),x(o,t,ve(e,i,n,o)),b(e)||v(e,t+1,n,!0,o);return}let s=ye(e);if(s){d(o);let a=Q(e,o.doc,n);x(o,t,a?`${s} ${R(a)}`:s),v(e,t+1,n,r,o),d(o);return}let l=xe(e);if(l){d(o);let a=n?"***":C(e,null);a&&x(o,t,`heading ${R(a)} [h${l}]`),v(e,t+1,n,!0,o);return}let u=e.tagName==="LABEL"&&(e.hasAttribute("for")||!!e.querySelector("input,select,textarea")),c=Ee.has(e.tagName);c&&d(o),v(e,t,n,r||u,o),c&&d(o)}function L(e){if(e.hidden||e.getAttribute("aria-hidden")==="true"||e.tagName==="INPUT"&&e.type==="hidden"||e.tagName==="DIALOG"&&!e.hasAttribute("open"))return!1;let t=e.parentElement;if(t?.tagName==="DETAILS"&&!t.hasAttribute("open")&&e.tagName!=="SUMMARY")return!1;let n=e.ownerDocument.defaultView;if(!n)return!0;let r=n.getComputedStyle(e);return r.display!=="none"&&r.visibility!=="hidden"&&r.visibility!=="collapse"}function Te(e){let t=e.getAttribute("role");if(t&&Ae.has(t))return t;switch(e.tagName){case"A":if(e.hasAttribute("href"))return"link";break;case"BUTTON":case"SUMMARY":return"button";case"SELECT":{let r=e;return r.multiple||r.size>1?"listbox":"combobox"}case"TEXTAREA":return"textbox";case"INPUT":{let r=w(e);return r==="checkbox"||r==="radio"?r:r==="button"||r==="submit"||r==="reset"||r==="image"?"button":r==="range"?"slider":r==="file"?"file":r==="hidden"?null:"textbox"}}if(N(e))return"textbox";let n=e.getAttribute("tabindex");return n!==null&&Number(n)>=0?t||"focusable":null}function ye(e){let t=e.getAttribute("role");return t&&Y[t]?Y[t]:ge[e.tagName]??null}function xe(e){let t=/^H([1-6])$/.exec(e.tagName);return t?Number(t[1]):e.getAttribute("role")==="heading"?Number(e.getAttribute("aria-level"))||2:0}function w(e){return(e.getAttribute("type")??"").toLowerCase()}function N(e){let t=e.getAttribute("contenteditable")?.toLowerCase();return t===""||t==="true"||t==="plaintext-only"}function B(e){for(let t=e;t;t=t.parentElement){let n=t.getAttribute("contenteditable")?.toLowerCase();if(n==="false")return!1;if(n!==void 0&&N(t))return!0}return!1}function b(e){return e.tagName==="INPUT"||e.tagName==="SELECT"||e.tagName==="TEXTAREA"||N(e)}function ve(e,t,n,r){let o=I(e,r.doc,n),i=o?`${t} ${R(o)}`:t;i+=` ref=${r.refs.refFor(e)}`;let s=we(e,t,n);return s.length?`${i} ${s.join(" ")}`:i}function Q(e,t,n){let r=e.getAttribute("aria-labelledby");if(r){let i=r.split(/\s+/).map(l=>t.getElementById(l)).filter(l=>!!l).map(l=>C(l,null)).join(" "),s=f(i,p);if(s)return n?"***":s}let o=f(e.getAttribute("aria-label"),p);return o&&n?"***":o}function I(e,t,n){let r=Se(e,t);return r&&n?"***":r}function Se(e,t){let n=Q(e,t,!1);if(n)return n;let r=e.tagName,o=r==="INPUT"?w(e):"";if(r==="INPUT"||r==="SELECT"||r==="TEXTAREA"){let l=Re(e,t),u=f(l.map(c=>C(c,e)).join(" "),p);if(u)return u;if(o==="button"||o==="submit"||o==="reset"){let c=f(e.getAttribute("value"),p);if(c)return c}}let i=f(e.getAttribute("alt"),p);if(i)return i;if(!b(e)){let l=C(e,null);if(l)return l}let s=f(e.getAttribute("title"),p);return s||(r==="INPUT"&&o!=="password"||r==="TEXTAREA"?f(e.getAttribute("placeholder"),p):"")}function Re(e,t){let n=[],r=e.id;if(r)for(let i of t.querySelectorAll("label[for]"))i.getAttribute("for")===r&&n.push(i);let o=e.closest("label");return o&&!n.includes(o)&&n.push(o),n}function C(e,t){if(b(e)||B(e)||e.closest(`[${m}]`))return"";if(e.closest(`[${E}]`))return"***";let n=[],r=o=>{for(let i=o.firstChild;i;i=i.nextSibling){if(i.nodeType===3){n.push(i.nodeValue??"");continue}if(i.nodeType!==1)continue;let s=i;if(!(s===t||K.has(s.tagName)||s.hasAttribute(m))&&!(b(s)||!L(s))){if(s.hasAttribute(E)){n.push("***");continue}if(s.tagName==="IMG"){n.push(s.getAttribute("alt")??"");continue}r(s)}}};return r(e),f(n.join(" "),p)}function we(e,t,n){let r=[],o=e.tagName,i=o==="INPUT"?w(e):"",s=c=>e.getAttribute(`aria-${c}`);if(o==="SELECT"){let c=[...e.selectedOptions].map(a=>f(a.textContent,p)).filter(Boolean);c.length&&r.push(`value=${R(n?"***":c.join(", "))}`)}else if(i==="checkbox"||i==="radio")r.push(e.checked?"[checked]":"[unchecked]");else if(o==="TEXTAREA"||o==="INPUT"&&U.has(i))i==="password"&&r.push("[password]"),r.push(e.value?"[filled]":"[empty]");else if(N(e))r.push(e.textContent?.trim()?"[filled]":"[empty]");else if(t==="checkbox"||t==="switch"||s("checked")!==null){let c=s("checked");r.push(c==="true"?"[checked]":c==="mixed"?"[mixed]":"[unchecked]")}(F(e)||s("disabled")==="true")&&r.push("[disabled]");let l=o==="SUMMARY"?String(!!e.parentElement?.hasAttribute("open")):s("expanded");l==="true"?r.push("[expanded]"):l==="false"&&r.push("[collapsed]"),s("selected")==="true"&&r.push("[selected]"),(e.hasAttribute("required")||s("required")==="true")&&r.push("[required]"),(e.readOnly||s("readonly")==="true")&&r.push("[readonly]");let u=Me(e,i,n);return u!==null&&r.push(u?`[invalid: ${u}]`:"[invalid]"),r}var _e=["valueMissing","typeMismatch","patternMismatch","tooShort","tooLong","rangeUnderflow","rangeOverflow","stepMismatch","badInput","customError"];function Me(e,t,n){let r=e.validity,o=e.getAttribute("aria-invalid"),i=!!r&&r.valid===!1;return!i&&(!o||o==="false")?null:!i||n||t==="password"?"":_e.filter(s=>r[s]===!0).join(", ")}function F(e){if(e.disabled)return!0;try{if(e.matches(":disabled"))return!0}catch{}if(!/^(BUTTON|INPUT|SELECT|TEXTAREA)$/.test(e.tagName))return!1;let t=e.closest("fieldset[disabled]");if(!t)return!1;let n=[...t.children].find(r=>r.tagName==="LEGEND");return!n||!n.contains(e)}function f(e,t){let n=(e??"").replace(/\s+/g," ").trim();return n.length>t?`${n.slice(0,t)}\u2026`:n}function R(e){return`"${e.replace(/"/g,"'")}"`}function _(e){return!!e.closest(`[${E}]`)}function k(e){return!!e.closest(`[${m}]`)}var Ce=4e3,Le=50,Ne=250,J=50;async function te(e,t){let n=Ue(e,t),r=Be(e,t),o=await Ie(e,t,n,r);for(let i of e.actionHandlers)try{i({action:t,label:n,...r,result:o})}catch{}return o}function j(e,t){if(!t||!y.includes(t.type))return{error:"unknown_action"};if(!e.policy.allow.includes(t.type))return{error:"not_allowed"};if(t.type==="navigate"){let o=g(t.url);return o?{el:null,target:o}:{error:"cross_origin"}}let n=typeof t.ref=="string"?e.refs.resolve(t.ref):null;if(!n)return{error:"stale_ref"};if(k(n))return{error:"blocked"};let r=null;if((t.type==="click"||t.type==="fill")&&F(n))return{error:"disabled"};if(t.type==="click"){if(ne(n))return{error:"cross_origin"};let o=P(n);o&&(r=g(o))}if(t.type==="fill"){let o=$e(n,t.value);if(o)return{error:o}}return{el:n,target:r}}async function Ie(e,t,n,r){let o=j(e,t);if("error"in o)return{ok:!1,error:o.error};let i=e.policy.confirm.includes(t.type);if(i){let c=await He(e,{action:t,label:n,...r});if(c!==!0)return{ok:!1,error:c};if(o=j(e,t),"error"in o)return{ok:!1,error:o.error}}if(e.presence){let c=await X(e.presence,t,o.el);if(c!==!0)return{ok:!1,error:c};if(o=j(e,t),"error"in o)return{ok:!1,error:o.error};if(!i&&e.policy.confirm.includes(t.type))return{ok:!1,error:"confirmation_required"}}let{el:s,target:l}=o;re();let u=t.type==="click"&&!l&&s.hasAttribute("aria-expanded")&&s.hasAttribute("aria-controls")?Z(s):null;try{if(t.type==="navigate")location.assign(l.href);else if(t.type==="highlight")s.scrollIntoView({block:"center"}),Ge(s);else if(t.type==="scroll_to")s.scrollIntoView({block:"center"});else if(t.type==="click"){if(!ke(s))return{ok:!1,error:"cross_origin"}}else{let c=De(s,t.value??"");if(c)return{ok:!1,error:c}}}catch{return{ok:!1,error:"action_failed"}}await je();for(let c=0;u&&Oe(u,Z(s));c+=J){if(c>=Ne)return{ok:!1,error:"no_effect",snapshot:h(e.refs)};await new Promise(a=>setTimeout(a,J))}return{ok:!0,snapshot:h(e.refs)}}function ke(e){let t=e.getBoundingClientRect(),n=e.ownerDocument.defaultView,r=n&&typeof n.PointerEvent=="function"?n.PointerEvent:null,o=n?.MouseEvent??MouseEvent,i=(l,u,c)=>{let a={bubbles:l!=="pointerenter",composed:!0,cancelable:l!=="pointerenter",view:n,clientX:t.left+t.width/2,clientY:t.top+t.height/2,button:0,buttons:u,detail:l==="mousedown"||l==="mouseup"||l==="click"?1:0};return c&&r&&Object.assign(a,{pointerId:1,pointerType:"mouse",isPrimary:!0}),e.dispatchEvent(c&&r?new r(l,a):new o(l,a))};i("pointerover",0,!0),i("pointerenter",0,!0),i("mouseover",0,!1);let s=i("pointerdown",1,!0);return s&&i("mousedown",1,!1)&&e.focus?.(),i("pointerup",0,!0),s&&i("mouseup",0,!1),ne(e)?!1:(i("click",0,!1),!0)}var Pe='[role="menu"],[role="listbox"],[role="dialog"],[role="grid"],[role="tree"],dialog';function Z(e){let t=e.ownerDocument,n=(e.getAttribute("aria-controls")??"").split(/\s+/).map(r=>r&&t.getElementById(r));return[e.isConnected,e.getAttribute("aria-expanded"),...n.filter(r=>r&&ee(r)),null,...[...t.querySelectorAll(Pe)].filter(ee)]}var Oe=(e,t)=>e.length===t.length&&e.every((n,r)=>n===t[r]);function ee(e){for(let t=e;t;t=t.parentElement)if(!L(t))return!1;return!0}function ne(e){let t=P(e);if(t)return!g(t);let n=e.form,r=(e.getAttribute("type")??"").toLowerCase(),o=e.tagName==="BUTTON"?r==="submit"||!r:e.tagName==="INPUT"&&(r==="submit"||r==="image");if(!n||!o)return!1;let i=(e.getAttribute("formaction")??n.getAttribute("action")??"").trim();return!!i&&!g(i)}function P(e){let t=e.closest("a[href],area[href]");return t?(t.getAttribute("href")??"").trim()||location.href:null}async function He(e,t){if(!e.confirmHandlers.size)return"confirmation_required";try{return(await Promise.all([...e.confirmHandlers].map(r=>r(t)))).every(r=>r===!0)?!0:"declined"}catch{return"declined"}}function $e(e,t){if(typeof t!="string")return"missing_value";let n=e.tagName;if(n==="INPUT"){let r=w(e);if(r==="password"||r==="file"||r==="hidden")return"forbidden";if(!U.has(r))return"not_fillable"}else if(n!=="TEXTAREA"&&n!=="SELECT")return"not_fillable";return _(e)?"forbidden":e.readOnly?"readonly":null}function De(e,t){let n;if(e.tagName==="SELECT"){let o=e,i=[...o.options].find(s=>s.value===t)??[...o.options].find(s=>(s.textContent??"").replace(/\s+/g," ").trim()===t.trim());if(!i)return"invalid_value";t=i.value,n=HTMLSelectElement.prototype}else n=e.tagName==="TEXTAREA"?HTMLTextAreaElement.prototype:HTMLInputElement.prototype;e.focus?.();let r=Object.getOwnPropertyDescriptor(n,"value")?.set;return r?r.call(e,t):e.value=t,e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})),null}function g(e){if(typeof e!="string"||!e.trim())return null;try{let t=new URL(e,location.href);return t.username||t.password?null:t.origin===location.origin&&/^https?:$/.test(t.protocol)?t:null}catch{return null}}function Ue(e,t){if(t?.type==="navigate"){let i=typeof t.url=="string"?t.url:"?";return`navigate to ${g(i)?.href??i}`}let n=t&&typeof t.ref=="string"?e.refs.resolve(t.ref):null,r=n&&!k(n)?I(n,n.ownerDocument,_(n)):"",o=`${t?.type??"?"} ${r?`"${r}"`:t?.ref??"?"}`;if(t?.type==="fill"&&typeof t.value=="string"&&(o+=` with "${t.value}"`),t?.type==="click"&&n){let i=P(n);i&&(o+=` (goes to ${g(i)?.href??i})`)}return o}function Be(e,t){if(!t)return{};if(t.type==="navigate")return typeof t.url=="string"?{destination:g(t.url)?.href??t.url}:{};let n=typeof t.ref=="string"?e.refs.resolve(t.ref):null,r=n&&!k(n)?I(n,n.ownerDocument,_(n)):"",o={},i=r||(typeof t.ref=="string"?t.ref:"");if(i&&(o.target=i),t.type==="fill"&&typeof t.value=="string"&&(o.value=t.value),t.type==="click"&&n){let s=P(n);s&&(o.destination=g(s)?.href??s)}return o}var Fe=100;function je(){return new Promise(e=>{let t=!1,n=()=>{t||(t=!0,setTimeout(e,Le))};typeof requestAnimationFrame=="function"&&requestAnimationFrame(n),setTimeout(n,Fe)})}var G=null;function Ge(e){let t=e.ownerDocument,{host:n,shadow:r}=V(t,D,"top-left"),o=t.createElement("div");o.setAttribute("style","position:absolute;inset:0;border:3px solid #2f6f4f;border-radius:6px;box-shadow:0 0 0 4px rgba(47,111,79,.25);pointer-events:none"),r.appendChild(o);let i=()=>{let u=e.getBoundingClientRect();n.setAttribute("style",`position:fixed;top:${u.top-4}px;left:${u.left-4}px;width:${u.width+8}px;height:${u.height+8}px;z-index:2147483647;pointer-events:none;display:block;margin:0;padding:0`)};i(),(t.body??t.documentElement).appendChild(n);let s=t.defaultView;s?.addEventListener("scroll",i,!0),s?.addEventListener("resize",i);let l=setTimeout(re,Ce);G={host:n,stop:()=>{clearTimeout(l),s?.removeEventListener("scroll",i,!0),s?.removeEventListener("resize",i),n.remove()}}}function re(){G?.stop(),G=null}var qe=10,Ve=10,oe=6e4,ie=160,se=["page","recent","errors"],Xe=`[${E}],[${m}],[contenteditable],textarea,input,select`;function le(e,t,n={}){let r=Array.isArray(n?.include)?n.include.filter(l=>se.includes(l)):se,o=typeof window<"u"?window:null,i=r.some(l=>l!=="page")?We(t):null,s=n?.maxChars;return{version:T,page:r.includes("page")?h(e,{maxChars:s}):"",url:typeof location<"u"?A(location.href):"",viewport:{w:o?.innerWidth??0,h:o?.innerHeight??0,scrollY:Math.round(o?.scrollY??0),scrollH:typeof document<"u"?document.documentElement?.scrollHeight??0:0},recent:i&&r.includes("recent")?Ye(i):[],errors:i&&r.includes("errors")?ze(i):[]}}function We(e){try{return e&&typeof e.snapshot=="function"?e.snapshot():null}catch{return null}}function Ye(e){let t=e.duration_ms,n=[];for(let r of e.interactions){let o=r.t_ms??0,i=Ke(r);n.push({t:o,line:`${r.kind} ${i}`.trim()+O(t,o)})}for(let r of e.navigations)n.push({t:r.t_ms,line:`nav ${A(r.url)}${O(t,r.t_ms)}`});return n.sort((r,o)=>r.t-o.t).slice(-qe).map(r=>ce(r.line))}function ze(e){let t=e.duration_ms,n=[];for(let r of e.network){let o=r.t_ms??0;if(t-o>oe)continue;let i=!!r.error;if(!i&&!(r.status!==null&&r.status>=400))continue;let s=i?`failed (${r.error})`:String(r.status);n.push({t:o,line:`${r.method??"GET"} ${A(r.url??"")} ${s}${O(t,o)}`})}for(let r of e.console){let o=r.t_ms??0;if(r.level!=="error"||t-o>oe)continue;let i=r.text.replace(/\s+/g," ").trim().replace(/https?:\/\/\S+/g,s=>A(s));n.push({t:o,line:`console.error ${q(i.slice(0,120))}${O(t,o)}`})}return n.sort((r,o)=>r.t-o.t).slice(-Ve).map(r=>ce(r.line))}function Ke(e){let t=Je(e.selector),n=e.role||e.tag||"";if(!t||t.closest(`[${E}],[${m}]`))return n;if(b(t)||B(t)||t.querySelector(Xe)){let r=(t.getAttribute("aria-label")||t.getAttribute("data-testid")||"").replace(/\s+/g," ").trim();return r?`${n} ${q(r.slice(0,80))}`.trim():n}return e.label&&Qe(e.label,t)?q(e.label):n}function Qe(e,t){let n=e.replace(/…$/,"");return[t.getAttribute("data-testid"),t.getAttribute("data-test-id"),t.getAttribute("aria-label"),t.getAttribute("title"),t.innerText||t.textContent,t.getAttribute("name"),t.id].some(o=>!!o&&o.replace(/\s+/g," ").trim().startsWith(n))}function Je(e){if(!e||typeof document>"u")return null;try{return document.querySelector(e)}catch{return null}}function O(e,t){return` (${Math.max(0,Math.round((e-t)/1e3))}s ago)`}function q(e){return`"${e.replace(/"/g,"'")}"`}function ce(e){return e.length>ie?`${e.slice(0,ie)}\u2026`:e}function bt(e){let t={refs:new S,policy:{allow:[...y],confirm:[...H.confirm]},confirmHandlers:new Set,actionHandlers:new Set};return{getContext:n=>le(t.refs,e,n),act:async n=>{let r=await te(t,n);return W(t.presence??null,n,r),r},tools:(n=>$(n.format,n.allow??t.policy.allow)),policy(n){let r=s=>Array.isArray(s)?s.filter(l=>y.includes(l)):null,o=r(n?.allow),i=r(n?.confirm);return o&&(t.policy.allow=o),i&&(t.policy.confirm=i),{allow:[...t.policy.allow],confirm:[...t.policy.confirm]}},presence(n){return t.presence=n&&typeof n=="object"?n:null,()=>{t.presence===n&&(t.presence=null)}},on(n,r){if(n!=="action_confirm"&&n!=="action")return()=>{};let o=n==="action_confirm"?t.confirmHandlers:t.actionHandlers;return o.add(r),()=>{o.delete(r)}}}}export{ue as a,D as b,S as c,h as d,Ce as e,bt as f};
|
package/dist/index.cjs
CHANGED
|
@@ -526,4 +526,4 @@ textarea:focus-visible {
|
|
|
526
526
|
<p class="ef-title" id="ef-title">${o.title}</p>
|
|
527
527
|
<div class="ef-options" id="ef-options" role="group" aria-label="${o.title}" data-kind="${t.kind}">${d}</div>
|
|
528
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"),l=i.getElementById("ef-title"),h=i.getElementById("ef-options"),x=i.getElementById("ef-thanks"),E=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()},H=g=>{if(!m){m=!0;for(let B of E)B.disabled=!0;n(g).catch(()=>{}),l.hidden=!0,h.hidden=!0,x.hidden=!1,b=e.defaultView?.setTimeout(k,1600)??null}},R=g=>{g.key==="Escape"&&(g.stopPropagation(),k())},C=g=>{let B=g.currentTarget??null;B&&H(Number(B.dataset.value))};for(let g of E)g.addEventListener("click",C);u.addEventListener("click",k);let v=xe(p);return e.addEventListener("keydown",R,!0),e.body.appendChild(a),{destroy(){A();for(let g of E)g.removeEventListener("click",C);u.removeEventListener("click",k),v(),e.removeEventListener("keydown",R,!0),a.remove()},shadowRootForTesting:i}}var jo="espejo:feedback:lastShown:";function rn(e){return`${jo}${e}`}function _e(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 Te(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 ve(e,"espejo.draw.js",Lo,t)}var cn="@espejo/browser",ln="0.3.0",Io="https://app.espejo.dev",dn={source:"manual"},Ae=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||Io,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=Kt({ingestUrl:this.config.ingestUrl,key:this.config.key,getSnapshot:()=>this.snapshotFn,fetchImpl:this.pristineFetch})),this.uninstall=[Nt(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,dn,o),text:this.config.buttonText,theme:this.config.theme,position:this.config.position,icon:this.config.buttonIcon,video:{supported:()=>q(),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 ve(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 this.getFeedbackConfig();t?.enabled&&(!this.recorder||this.feedback||_e(this.config.key,t.cadence_days)&&(Te(this.config.key),this.feedback=Se({config:t,vote:n=>this.postVote(t.kind,n),text:this.config.feedbackText,theme:this.config.theme})))}postVote(t,n){return Ee({ingestUrl:this.config.ingestUrl,key:this.config.key,kind:t,value:n,pageHost:typeof location<"u"?location.host:void 0,userRef:this.config.userRef},this.pristineFetch)}getFeedbackConfig(){return be(this.config.ingestUrl,this.config.key,this.pristineFetch)}async vote(t,n){let o=await this.getFeedbackConfig();if(!o)throw new Error("Espejo: feedback is off");let r=n?.kind??o.kind,{min:a,max:i}=fe[r];if(!(Number.isInteger(t)&&t>=a&&t<=i))throw new Error(`Espejo: invalid ${r} vote`);return this.postVote(r,t)}async loadAutoReport(){let{config:t,videoSurface:n,hasTriggers:o}=await ge(this.config.ingestUrl,this.config.key,this.pristineFetch);n&&(this.config.videoSurface=n),o&&this.loadTriggers(),t&&(this.autoConfig=t,this.autoGuard=new It(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,$e(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,$e(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(!q())throw new Error("This browser can't record the screen.");this.video||(this.video=await qt({...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=dn,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(),d=!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:!!d,audio:!!d&&this.videoHasAudio},n),events:i,dom:s?.length?s:void 0,video:d,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:Tt,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:cn,version:ln},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 Mo(e={}){if(typeof document>"u")return null;let t=document.currentScript,n=t?.dataset.key;if(!n)return null;let o=new Ae({...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});
|
|
529
|
+
</div>`;let p=i.querySelector(".ef-root"),u=i.getElementById("ef-close"),l=i.getElementById("ef-title"),h=i.getElementById("ef-options"),x=i.getElementById("ef-thanks"),E=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()},H=g=>{if(!m){m=!0;for(let B of E)B.disabled=!0;n(g).catch(()=>{}),l.hidden=!0,h.hidden=!0,x.hidden=!1,b=e.defaultView?.setTimeout(k,1600)??null}},R=g=>{g.key==="Escape"&&(g.stopPropagation(),k())},C=g=>{let B=g.currentTarget??null;B&&H(Number(B.dataset.value))};for(let g of E)g.addEventListener("click",C);u.addEventListener("click",k);let v=xe(p);return e.addEventListener("keydown",R,!0),e.body.appendChild(a),{destroy(){A();for(let g of E)g.removeEventListener("click",C);u.removeEventListener("click",k),v(),e.removeEventListener("keydown",R,!0),a.remove()},shadowRootForTesting:i}}var jo="espejo:feedback:lastShown:";function rn(e){return`${jo}${e}`}function _e(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 Te(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 ve(e,"espejo.draw.js",Lo,t)}var cn="@espejo/browser",ln="0.4.0",Io="https://app.espejo.dev",dn={source:"manual"},Ae=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||Io,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=Kt({ingestUrl:this.config.ingestUrl,key:this.config.key,getSnapshot:()=>this.snapshotFn,fetchImpl:this.pristineFetch})),this.uninstall=[Nt(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,dn,o),text:this.config.buttonText,theme:this.config.theme,position:this.config.position,icon:this.config.buttonIcon,video:{supported:()=>q(),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 ve(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 this.getFeedbackConfig();t?.enabled&&(!this.recorder||this.feedback||_e(this.config.key,t.cadence_days)&&(Te(this.config.key),this.feedback=Se({config:t,vote:n=>this.postVote(t.kind,n),text:this.config.feedbackText,theme:this.config.theme})))}postVote(t,n){return Ee({ingestUrl:this.config.ingestUrl,key:this.config.key,kind:t,value:n,pageHost:typeof location<"u"?location.host:void 0,userRef:this.config.userRef},this.pristineFetch)}getFeedbackConfig(){return be(this.config.ingestUrl,this.config.key,this.pristineFetch)}async vote(t,n){let o=await this.getFeedbackConfig();if(!o)throw new Error("Espejo: feedback is off");let r=n?.kind??o.kind,{min:a,max:i}=fe[r];if(!(Number.isInteger(t)&&t>=a&&t<=i))throw new Error(`Espejo: invalid ${r} vote`);return this.postVote(r,t)}async loadAutoReport(){let{config:t,videoSurface:n,hasTriggers:o}=await ge(this.config.ingestUrl,this.config.key,this.pristineFetch);n&&(this.config.videoSurface=n),o&&this.loadTriggers(),t&&(this.autoConfig=t,this.autoGuard=new It(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,$e(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,$e(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(!q())throw new Error("This browser can't record the screen.");this.video||(this.video=await qt({...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=dn,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(),d=!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:!!d,audio:!!d&&this.videoHasAudio},n),events:i,dom:s?.length?s:void 0,video:d,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:Tt,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:cn,version:ln},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 Mo(e={}){if(typeof document>"u")return null;let t=document.currentScript,n=t?.dataset.key;if(!n)return null;let o=new Ae({...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});
|
package/dist/index.d.cts
CHANGED
|
@@ -213,7 +213,7 @@ interface VoteInput {
|
|
|
213
213
|
declare function sendVote(input: VoteInput, fetchImpl?: typeof fetch): Promise<void>;
|
|
214
214
|
|
|
215
215
|
declare const SDK_NAME = "@espejo/browser";
|
|
216
|
-
declare const SDK_VERSION = "0.
|
|
216
|
+
declare const SDK_VERSION = "0.4.0";
|
|
217
217
|
interface EspejoConfig {
|
|
218
218
|
key: string;
|
|
219
219
|
ingestUrl?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -213,7 +213,7 @@ interface VoteInput {
|
|
|
213
213
|
declare function sendVote(input: VoteInput, fetchImpl?: typeof fetch): Promise<void>;
|
|
214
214
|
|
|
215
215
|
declare const SDK_NAME = "@espejo/browser";
|
|
216
|
-
declare const SDK_VERSION = "0.
|
|
216
|
+
declare const SDK_VERSION = "0.4.0";
|
|
217
217
|
interface EspejoConfig {
|
|
218
218
|
key: string;
|
|
219
219
|
ingestUrl?: string;
|
package/dist/index.js
CHANGED
|
@@ -478,4 +478,4 @@ import{G as oo,H as mt,I as ce,J as ue,K as pe,a as je,b as T,c as K,d as Ae,e a
|
|
|
478
478
|
<p class="ef-title" id="ef-title">${n.title}</p>
|
|
479
479
|
<div class="ef-options" id="ef-options" role="group" aria-label="${n.title}" data-kind="${e.kind}">${l}</div>
|
|
480
480
|
<p class="ef-thanks" id="ef-thanks" role="status" aria-live="polite" hidden>${n.thanks}</p>
|
|
481
|
-
</div>`;let h=s.querySelector(".ef-root"),m=s.getElementById("ef-close"),c=s.getElementById("ef-title"),p=s.getElementById("ef-options"),w=s.getElementById("ef-thanks"),k=Array.from(p.querySelectorAll(".ef-opt")),f=!1,b=null,j=()=>{b!==null&&(t.defaultView?.clearTimeout(b),b=null)},x=()=>{j(),t.removeEventListener("keydown",A,!0),d.remove()},O=g=>{if(!f){f=!0;for(let M of k)M.disabled=!0;o(g).catch(()=>{}),c.hidden=!0,p.hidden=!0,w.hidden=!1,b=t.defaultView?.setTimeout(x,1600)??null}},A=g=>{g.key==="Escape"&&(g.stopPropagation(),x())},C=g=>{let M=g.currentTarget??null;M&&O(Number(M.dataset.value))};for(let g of k)g.addEventListener("click",C);m.addEventListener("click",x);let y=ue(h);return t.addEventListener("keydown",A,!0),t.body.appendChild(d),{destroy(){j();for(let g of k)g.removeEventListener("click",C);m.removeEventListener("click",x),y(),t.removeEventListener("keydown",A,!0),d.remove()},shadowRootForTesting:s}}var Fo="espejo:feedback:lastShown:";function $t(t){return`${Fo}${t}`}function Ie(t,e,o){try{let n=Wt(o);if(!n)return!0;let i=n.getItem($t(t));if(!i)return!0;let d=Number(i);return Number.isFinite(d)?Date.now()-d>=e*864e5:!0}catch{return!0}}function Oe(t,e){try{Wt(e)?.setItem($t(t),String(Date.now()))}catch{}}function Wt(t){return(t?.defaultView??(typeof window<"u"?window:void 0))?.localStorage??null}var Po="__espejoInstallAnnotator";function Nt(t,e=document){return be(t,"espejo.draw.js",Po,e)}var Do="@espejo/browser",Ho="0.3.0",Io="https://app.espejo.dev",Vt={source:"manual"},Ue=class{constructor(e){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(!e?.key)throw new Error("Espejo: missing data-key (the project's public key)");this.config={...e,ingestUrl:e.ingestUrl||Io,mode:e.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 e=new q(this.config.budgets);this.recorder=e,this.autoKilled=this.config.autoReport==="off",this.config.capture==="dom"&&(this.routeSnapshot=jt({ingestUrl:this.config.ingestUrl,key:this.config.key,getSnapshot:()=>this.snapshotFn,fetchImpl:this.pristineFetch})),this.uninstall=[kt(e,{ignoreOrigins:[this.config.ingestUrl],onEntry:o=>this.onNetworkEntry(o)}),wt(e,{onEntry:(o,n)=>this.onConsoleEntry(o,n)}),mt(e,{onEntry:(o,n)=>this.pushTriggerSignal({kind:o,tMs:n})}),St(e,o=>{this.routeSnapshot?.onRoute(),this.pushTriggerSignal({kind:"nav",tMs:e.elapsed(),url:o})})],this.config.capture==="dom"&&this.enableDom(e),this.config.button!=="off"&&(this.widget=It({report:(o,n)=>this.report(o,Vt,n),text:this.config.buttonText,theme:this.config.theme,position:this.config.position,icon:this.config.buttonIcon,video:{supported:()=>Y(),start:o=>this.startVideo(o),setMicrophone:o=>this.setMicrophone(o),stop:async()=>{await this.stopVideo()},discard:()=>this.discardVideo(),setMarkup:(o,n)=>this.setMarkup(o,n),limitSeconds:240}})),this.loadAutoReport(),this.config.feedback!=="off"&&this.loadFeedback()}pushTriggerSignal(e){try{this.triggerSink?this.triggerSink(e):this.triggerBuf.length<300&&this.triggerBuf.push(e)}catch{}}async loadTriggers(){if(!this.recorder||this.triggersStop)return;let e=await be(this.config.ingestUrl,"espejo.triggers.js",Bt);if(!(!e||!this.recorder||this.triggersStop))try{let o=e({ingestUrl:this.config.ingestUrl,key:this.config.key,fetchImpl:this.pristineFetch,now:()=>this.recorder?.elapsed()??0,subscribe:n=>{this.triggerSink=n;for(let i of this.triggerBuf.splice(0))n(i)},theme:this.config.theme});o&&(this.triggersStop=o.stop)}catch{}}async loadFeedback(){let e=await this.getFeedbackConfig();e?.enabled&&(!this.recorder||this.feedback||Ie(this.config.key,e.cadence_days)&&(Oe(this.config.key),this.feedback=He({config:e,vote:o=>this.postVote(e.kind,o),text:this.config.feedbackText,theme:this.config.theme})))}postVote(e,o){return Pe({ingestUrl:this.config.ingestUrl,key:this.config.key,kind:e,value:o,pageHost:typeof location<"u"?location.host:void 0,userRef:this.config.userRef},this.pristineFetch)}getFeedbackConfig(){return Fe(this.config.ingestUrl,this.config.key,this.pristineFetch)}async vote(e,o){let n=await this.getFeedbackConfig();if(!n)throw new Error("Espejo: feedback is off");let i=o?.kind??n.kind,{min:d,max:s}=le[i];if(!(Number.isInteger(e)&&e>=d&&e<=s))throw new Error(`Espejo: invalid ${i} vote`);return this.postVote(i,e)}async loadAutoReport(){let{config:e,videoSurface:o,hasTriggers:n}=await Me(this.config.ingestUrl,this.config.key,this.pristineFetch);o&&(this.config.videoSurface=o),n&&this.loadTriggers(),e&&(this.autoConfig=e,this.autoGuard=new pt(e))}setAutoReport(e){this.autoKilled=!e}identify(e){this.config.userRef=e||void 0}canOpenReport(){return!!this.widget&&!this.video}openReport(){let e=this.canOpenReport();return e&&this.widget.open(),e}get lastReportId(){return this.lastReport}get autoReportActive(){return!!this.autoConfig&&!this.autoKilled}autoEnabled(e){return this.autoKilled||!this.autoConfig||!this.recorder?!1:this.autoConfig.triggers.includes(e)}onConsoleEntry(e,o){if(o==="console"&&e.level!=="error")return;this.pushTriggerSignal({kind:"console_error",tMs:this.recorder?.elapsed()??0});let n=o==="window_error"?"auto:uncaught":o==="unhandled_rejection"?"auto:unhandled_rejection":"auto:console_error";this.maybeAutoReport(n,Ce(n,e.text,e.stack))}onNetworkEntry(e){let o=ft(e.status,!!e.error);o&&(this.pushTriggerSignal({kind:"http_error",tMs:this.recorder?.elapsed()??0}),this.maybeAutoReport(o,Ce(o,`${e.method} ${e.url}`,String(e.status??e.error))))}maybeAutoReport(e,o){try{if(!this.autoEnabled(e)||this.autoInFlight||!this.autoGuard?.check(o).allowed)return;this.autoInFlight=!0,this.report(void 0,{source:"auto",trigger:e}).catch(()=>{}).finally(()=>{this.autoInFlight=!1})}catch{this.autoInFlight=!1}}async enableDom(e){let o=this.config.rrwebRecord??await Rt();if(!o||this.recorder!==e)return;this.dom=Et(e,o);let n=this.config.rrwebSnapshot??await Tt();this.recorder===e&&(this.snapshotFn=n,n&&this.routeSnapshot?.onRoute())}stop(){for(let e of this.uninstall.splice(0))try{e()}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(e={}){if(!Y())throw new Error("This browser can't record the screen.");this.video||(this.video=await At({...e,surface:e.surface??this.config.videoSurface}),this.videoContentType=this.video.contentType)}async setMicrophone(e){return await this.video?.setMicrophone(e)??{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(e,o=()=>{}){if(!e)return this.teardownMarkup(),!1;if(this.annotator)return!0;if(typeof document>"u")return!1;let n=await Nt(this.config.ingestUrl);if(!n)return!1;let i=document.createElement("div");i.setAttribute("data-espejo-markup","");let d=i.attachShadow({mode:"closed"});return document.body.appendChild(i),this.markupHost=i,this.annotator=n({root:d,onExit:()=>{this.teardownMarkup(),o()}}),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(e,o=Vt,n){let i=this.recorder;if(!i)return null;let d=o.source==="auto";this.video&&!d&&await this.stopVideo();let s=i.snapshot(),r=this.dom?.events(),l=!d&&this.videoBlob?{blob:this.videoBlob,contentType:this.videoContentType}:void 0,h=await Mt({ingestUrl:this.config.ingestUrl,key:this.config.key,manifest:this.manifest(i,e,{dom:!!r?.length,video:!!l,audio:!!l&&this.videoHasAudio},o),events:s,dom:r?.length?r:void 0,video:l,onProgress:d?void 0:n},this.pristineFetch);return i.clear(),this.dom?.buffer.clear(),d||(this.videoBlob=null,this.videoHasAudio=!1,this.videoMs=0,this.lastReport=h.session_id),h.url}manifest(e,o,n,i){return{bundle_version:at,source:"web-sdk",mode:n.video?"video":n.dom?"dom":"events",trigger:i.source==="auto"?i.trigger:this.config.mode==="always"?"always":"manual",report_source:i.source,description:o??null,started_at:e.startedAtIso,duration_ms:e.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:Do,version:Ho},dropped:{...e.dropped,dom_segments:this.dom?.buffer.droppedCount??0},has_dom:n.dom,has_video:n.video,...n.video?{video_ms:this.videoMs}:{},has_audio:n.audio}}};function Kn(t={}){if(typeof document>"u")return null;let e=document.currentScript,o=e?.dataset.key;if(!o)return null;let n=new Ue({...t,key:o,ingestUrl:e?.dataset.ingest,mode:e?.dataset.mode==="always"?"always":"ring",capture:e?.dataset.capture==="dom"?"dom":t.capture??"events",button:e?.dataset.button==="off"?"off":t.button??"on",autoReport:e?.dataset.autoReport==="off"?"off":t.autoReport??"on",feedback:e?.dataset.feedback==="off"?"off":t.feedback??"on",feedbackText:$o(e?.dataset.feedbackText)??t.feedbackText,theme:Oo(e?.dataset.theme)??t.theme??"auto",position:Uo(e?.dataset.position)??t.position,buttonIcon:e?.dataset.buttonIcon??t.buttonIcon,videoSurface:e?.dataset.videoSurface,release:e?.dataset.release,env:e?.dataset.env,userRef:e?.dataset.userRef??t.userRef});return n.start(),globalThis.espejo=n,n}function Oo(t){return t==="light"||t==="dark"||t==="auto"?t:void 0}function Uo(t){return t==="bottom-right"||t==="bottom-left"||t==="top-right"||t==="top-left"?t:void 0}function $o(t){if(t)try{let e=JSON.parse(t);return e&&typeof e=="object"?e:void 0}catch{return}}export{oo as BLOCK_ATTRIBUTE,ge as BLOCK_SELECTOR,vt as DEFAULT_BUDGETS,Ue as Espejo,Ut as FEEDBACK_DEFAULT_TEXT,he as MASK_SELECTOR,Be as MAX_VIDEO_SECONDS,I as RingBuffer,Do as SDK_NAME,Ho as SDK_VERSION,J as SegmentRing,q as SessionRecorder,Ht as WIDGET_DEFAULT_TEXT,Kn as autoStart,Ie as canShowFeedback,Me as fetchAutoReportConfig,Fe as fetchFeedbackConfig,He as installFeedbackWidget,Lt as normalizeAutoReportConfig,_t as normalizeFeedbackConfig,Oe as sealFeedbackShown,Pe as sendVote,Y as videoSupported};
|
|
481
|
+
</div>`;let h=s.querySelector(".ef-root"),m=s.getElementById("ef-close"),c=s.getElementById("ef-title"),p=s.getElementById("ef-options"),w=s.getElementById("ef-thanks"),k=Array.from(p.querySelectorAll(".ef-opt")),f=!1,b=null,j=()=>{b!==null&&(t.defaultView?.clearTimeout(b),b=null)},x=()=>{j(),t.removeEventListener("keydown",A,!0),d.remove()},O=g=>{if(!f){f=!0;for(let M of k)M.disabled=!0;o(g).catch(()=>{}),c.hidden=!0,p.hidden=!0,w.hidden=!1,b=t.defaultView?.setTimeout(x,1600)??null}},A=g=>{g.key==="Escape"&&(g.stopPropagation(),x())},C=g=>{let M=g.currentTarget??null;M&&O(Number(M.dataset.value))};for(let g of k)g.addEventListener("click",C);m.addEventListener("click",x);let y=ue(h);return t.addEventListener("keydown",A,!0),t.body.appendChild(d),{destroy(){j();for(let g of k)g.removeEventListener("click",C);m.removeEventListener("click",x),y(),t.removeEventListener("keydown",A,!0),d.remove()},shadowRootForTesting:s}}var Fo="espejo:feedback:lastShown:";function $t(t){return`${Fo}${t}`}function Ie(t,e,o){try{let n=Wt(o);if(!n)return!0;let i=n.getItem($t(t));if(!i)return!0;let d=Number(i);return Number.isFinite(d)?Date.now()-d>=e*864e5:!0}catch{return!0}}function Oe(t,e){try{Wt(e)?.setItem($t(t),String(Date.now()))}catch{}}function Wt(t){return(t?.defaultView??(typeof window<"u"?window:void 0))?.localStorage??null}var Po="__espejoInstallAnnotator";function Nt(t,e=document){return be(t,"espejo.draw.js",Po,e)}var Do="@espejo/browser",Ho="0.4.0",Io="https://app.espejo.dev",Vt={source:"manual"},Ue=class{constructor(e){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(!e?.key)throw new Error("Espejo: missing data-key (the project's public key)");this.config={...e,ingestUrl:e.ingestUrl||Io,mode:e.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 e=new q(this.config.budgets);this.recorder=e,this.autoKilled=this.config.autoReport==="off",this.config.capture==="dom"&&(this.routeSnapshot=jt({ingestUrl:this.config.ingestUrl,key:this.config.key,getSnapshot:()=>this.snapshotFn,fetchImpl:this.pristineFetch})),this.uninstall=[kt(e,{ignoreOrigins:[this.config.ingestUrl],onEntry:o=>this.onNetworkEntry(o)}),wt(e,{onEntry:(o,n)=>this.onConsoleEntry(o,n)}),mt(e,{onEntry:(o,n)=>this.pushTriggerSignal({kind:o,tMs:n})}),St(e,o=>{this.routeSnapshot?.onRoute(),this.pushTriggerSignal({kind:"nav",tMs:e.elapsed(),url:o})})],this.config.capture==="dom"&&this.enableDom(e),this.config.button!=="off"&&(this.widget=It({report:(o,n)=>this.report(o,Vt,n),text:this.config.buttonText,theme:this.config.theme,position:this.config.position,icon:this.config.buttonIcon,video:{supported:()=>Y(),start:o=>this.startVideo(o),setMicrophone:o=>this.setMicrophone(o),stop:async()=>{await this.stopVideo()},discard:()=>this.discardVideo(),setMarkup:(o,n)=>this.setMarkup(o,n),limitSeconds:240}})),this.loadAutoReport(),this.config.feedback!=="off"&&this.loadFeedback()}pushTriggerSignal(e){try{this.triggerSink?this.triggerSink(e):this.triggerBuf.length<300&&this.triggerBuf.push(e)}catch{}}async loadTriggers(){if(!this.recorder||this.triggersStop)return;let e=await be(this.config.ingestUrl,"espejo.triggers.js",Bt);if(!(!e||!this.recorder||this.triggersStop))try{let o=e({ingestUrl:this.config.ingestUrl,key:this.config.key,fetchImpl:this.pristineFetch,now:()=>this.recorder?.elapsed()??0,subscribe:n=>{this.triggerSink=n;for(let i of this.triggerBuf.splice(0))n(i)},theme:this.config.theme});o&&(this.triggersStop=o.stop)}catch{}}async loadFeedback(){let e=await this.getFeedbackConfig();e?.enabled&&(!this.recorder||this.feedback||Ie(this.config.key,e.cadence_days)&&(Oe(this.config.key),this.feedback=He({config:e,vote:o=>this.postVote(e.kind,o),text:this.config.feedbackText,theme:this.config.theme})))}postVote(e,o){return Pe({ingestUrl:this.config.ingestUrl,key:this.config.key,kind:e,value:o,pageHost:typeof location<"u"?location.host:void 0,userRef:this.config.userRef},this.pristineFetch)}getFeedbackConfig(){return Fe(this.config.ingestUrl,this.config.key,this.pristineFetch)}async vote(e,o){let n=await this.getFeedbackConfig();if(!n)throw new Error("Espejo: feedback is off");let i=o?.kind??n.kind,{min:d,max:s}=le[i];if(!(Number.isInteger(e)&&e>=d&&e<=s))throw new Error(`Espejo: invalid ${i} vote`);return this.postVote(i,e)}async loadAutoReport(){let{config:e,videoSurface:o,hasTriggers:n}=await Me(this.config.ingestUrl,this.config.key,this.pristineFetch);o&&(this.config.videoSurface=o),n&&this.loadTriggers(),e&&(this.autoConfig=e,this.autoGuard=new pt(e))}setAutoReport(e){this.autoKilled=!e}identify(e){this.config.userRef=e||void 0}canOpenReport(){return!!this.widget&&!this.video}openReport(){let e=this.canOpenReport();return e&&this.widget.open(),e}get lastReportId(){return this.lastReport}get autoReportActive(){return!!this.autoConfig&&!this.autoKilled}autoEnabled(e){return this.autoKilled||!this.autoConfig||!this.recorder?!1:this.autoConfig.triggers.includes(e)}onConsoleEntry(e,o){if(o==="console"&&e.level!=="error")return;this.pushTriggerSignal({kind:"console_error",tMs:this.recorder?.elapsed()??0});let n=o==="window_error"?"auto:uncaught":o==="unhandled_rejection"?"auto:unhandled_rejection":"auto:console_error";this.maybeAutoReport(n,Ce(n,e.text,e.stack))}onNetworkEntry(e){let o=ft(e.status,!!e.error);o&&(this.pushTriggerSignal({kind:"http_error",tMs:this.recorder?.elapsed()??0}),this.maybeAutoReport(o,Ce(o,`${e.method} ${e.url}`,String(e.status??e.error))))}maybeAutoReport(e,o){try{if(!this.autoEnabled(e)||this.autoInFlight||!this.autoGuard?.check(o).allowed)return;this.autoInFlight=!0,this.report(void 0,{source:"auto",trigger:e}).catch(()=>{}).finally(()=>{this.autoInFlight=!1})}catch{this.autoInFlight=!1}}async enableDom(e){let o=this.config.rrwebRecord??await Rt();if(!o||this.recorder!==e)return;this.dom=Et(e,o);let n=this.config.rrwebSnapshot??await Tt();this.recorder===e&&(this.snapshotFn=n,n&&this.routeSnapshot?.onRoute())}stop(){for(let e of this.uninstall.splice(0))try{e()}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(e={}){if(!Y())throw new Error("This browser can't record the screen.");this.video||(this.video=await At({...e,surface:e.surface??this.config.videoSurface}),this.videoContentType=this.video.contentType)}async setMicrophone(e){return await this.video?.setMicrophone(e)??{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(e,o=()=>{}){if(!e)return this.teardownMarkup(),!1;if(this.annotator)return!0;if(typeof document>"u")return!1;let n=await Nt(this.config.ingestUrl);if(!n)return!1;let i=document.createElement("div");i.setAttribute("data-espejo-markup","");let d=i.attachShadow({mode:"closed"});return document.body.appendChild(i),this.markupHost=i,this.annotator=n({root:d,onExit:()=>{this.teardownMarkup(),o()}}),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(e,o=Vt,n){let i=this.recorder;if(!i)return null;let d=o.source==="auto";this.video&&!d&&await this.stopVideo();let s=i.snapshot(),r=this.dom?.events(),l=!d&&this.videoBlob?{blob:this.videoBlob,contentType:this.videoContentType}:void 0,h=await Mt({ingestUrl:this.config.ingestUrl,key:this.config.key,manifest:this.manifest(i,e,{dom:!!r?.length,video:!!l,audio:!!l&&this.videoHasAudio},o),events:s,dom:r?.length?r:void 0,video:l,onProgress:d?void 0:n},this.pristineFetch);return i.clear(),this.dom?.buffer.clear(),d||(this.videoBlob=null,this.videoHasAudio=!1,this.videoMs=0,this.lastReport=h.session_id),h.url}manifest(e,o,n,i){return{bundle_version:at,source:"web-sdk",mode:n.video?"video":n.dom?"dom":"events",trigger:i.source==="auto"?i.trigger:this.config.mode==="always"?"always":"manual",report_source:i.source,description:o??null,started_at:e.startedAtIso,duration_ms:e.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:Do,version:Ho},dropped:{...e.dropped,dom_segments:this.dom?.buffer.droppedCount??0},has_dom:n.dom,has_video:n.video,...n.video?{video_ms:this.videoMs}:{},has_audio:n.audio}}};function Kn(t={}){if(typeof document>"u")return null;let e=document.currentScript,o=e?.dataset.key;if(!o)return null;let n=new Ue({...t,key:o,ingestUrl:e?.dataset.ingest,mode:e?.dataset.mode==="always"?"always":"ring",capture:e?.dataset.capture==="dom"?"dom":t.capture??"events",button:e?.dataset.button==="off"?"off":t.button??"on",autoReport:e?.dataset.autoReport==="off"?"off":t.autoReport??"on",feedback:e?.dataset.feedback==="off"?"off":t.feedback??"on",feedbackText:$o(e?.dataset.feedbackText)??t.feedbackText,theme:Oo(e?.dataset.theme)??t.theme??"auto",position:Uo(e?.dataset.position)??t.position,buttonIcon:e?.dataset.buttonIcon??t.buttonIcon,videoSurface:e?.dataset.videoSurface,release:e?.dataset.release,env:e?.dataset.env,userRef:e?.dataset.userRef??t.userRef});return n.start(),globalThis.espejo=n,n}function Oo(t){return t==="light"||t==="dark"||t==="auto"?t:void 0}function Uo(t){return t==="bottom-right"||t==="bottom-left"||t==="top-right"||t==="top-left"?t:void 0}function $o(t){if(t)try{let e=JSON.parse(t);return e&&typeof e=="object"?e:void 0}catch{return}}export{oo as BLOCK_ATTRIBUTE,ge as BLOCK_SELECTOR,vt as DEFAULT_BUDGETS,Ue as Espejo,Ut as FEEDBACK_DEFAULT_TEXT,he as MASK_SELECTOR,Be as MAX_VIDEO_SECONDS,I as RingBuffer,Do as SDK_NAME,Ho as SDK_VERSION,J as SegmentRing,q as SessionRecorder,Ht as WIDGET_DEFAULT_TEXT,Kn as autoStart,Ie as canShowFeedback,Me as fetchAutoReportConfig,Fe as fetchFeedbackConfig,He as installFeedbackWidget,Lt as normalizeAutoReportConfig,_t as normalizeFeedbackConfig,Oe as sealFeedbackShown,Pe as sendVote,Y as videoSupported};
|