@sypnia/browser 0.0.0-stage → 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.
@@ -0,0 +1,3 @@
1
+ (function(){'use strict';var Q=[1e3,4e3,15e3],Rt=6e4,At=30*6e4,tt=20,et=5e3,M=1e3,_t=30,xt=3,nt=1e3,Tt=2e3,kt=1e3,It=1500,d={env:40,release:40,name:100,message:500,stack:4e3,digest:100,label:80,selector:200,path:500,host:255,userAgent:500,code:40,failureMessage:160,customName:80,propName:40,propValue:200,personId:128,personName:120,email:254},Pt=20;var h={session:"sypnia:session",device:"sypnia:device",replay:"sypnia:replay",off:"sypnia:off"};function Nt(){return typeof window<"u"&&typeof document<"u"}function _(n){try{return window.localStorage.getItem(n)}catch{return null}}function E(n,t){try{return window.localStorage.setItem(n,t),!0}catch{return false}}function Dt(n){try{window.localStorage.removeItem(n);}catch{}}function a(n){try{return n()}catch{return}}function Mt(n,t=2e3){let e=globalThis.requestIdleCallback;try{if(typeof e=="function"){e(n,{timeout:t});return}}catch{}setTimeout(n,0);}function C(){return a(()=>document.visibilityState==="hidden")===true}function Ct(){return typeof CompressionStream=="function"&&typeof Response=="function"}async function Ot(n){let t=new TextEncoder().encode(n),e=new ReadableStream({start(r){r.enqueue(t),r.close();}});return new Response(e.pipeThrough(new CompressionStream("gzip"))).arrayBuffer()}function Lt(n,t){if(!n)return null;let e=Number(n);if(Number.isFinite(e))return Math.max(0,e*1e3);let r=Date.parse(n);return Number.isFinite(r)?Math.max(0,r-t):null}var Xe=/https?:\/\/[^\s)'"]+/gi,We=/\/_next\/static\/chunks\/[^\s)'"]+/gi,Ye=/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi,ze=/(["'`])(?:\\.|(?!\1).){0,200}\1/g,Ze=/\b[0-9a-f]{12,}\b/gi,Je=/[0-9]+(?:[.,][0-9]+)?/g,rt="\\t\\n\\v\\f\\r \\u0085\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000",Qe=new RegExp(`[${rt}]+`,"g"),Ft=new RegExp(`^[${rt}]+|[${rt}]+$`,"g"),tn=/^\s*at\s+(?:(.*?)\s+\()?(.+?):([0-9]+):([0-9]+)\)?\s*$/,en=/^\s*(.*?)@(.+?):([0-9]+):([0-9]+)\s*$/,nn=/^[a-z][a-z0-9+.-]*:\/\//i,rn=/[-.][0-9a-f]{8,}(\.(?:m?js|tsx?))$/i,sn=/^\/_next\/static\/chunks\/([0-9a-z_-]+)\.js$/i,on=/^.*?(\.next\/)/,an=["node_modules","/_next/static/chunks/framework","/_next/static/chunks/main","/_next/static/chunks/webpack","/_next/static/chunks/polyfills","/_next/static/chunks/turbopack-","react-dom","scheduler","node:internal","<anonymous>"];function Ht(n,t){let e=t>>>0;for(let r=0;r<n.length;r++)e^=n.charCodeAt(r),e=Math.imul(e,16777619)>>>0;return e.toString(16).padStart(8,"0")}function O(n){return Ht(n,2166136261)+Ht(n,84696351)}function ln(n,t){if(n.length<=t)return n;let e=n.charCodeAt(t-1),r=e>=55296&&e<=56319;return n.slice(0,r?t-1:t)}function un(n){if(!n)return "";let t=n.replace(Xe,"<url>").replace(We,"<chunk>").replace(Ye,"<uuid>").replace(ze,"$1\u2026$1").replace(Ze,"<hex>").replace(Je,"#").replace(Qe," ").replace(Ft,"");return ln(t,300)}function cn(n){let t=n;if(nn.test(t))try{t=new URL(t).pathname;}catch{}t=t.replace(/[?#].*$/,"").replace(rn,"$1");let e=sn.exec(t)?.[1];if(e!==void 0){let r=e.startsWith("turbopack-"),i=r?e.slice(10):e;if(i.length>=8&&/[0-9]/.test(i)&&/[a-z_]/i.test(i))return `/_next/static/chunks/${r?"turbopack-":""}*.js`}return t.replace(on,"$1")}function dn(n){if(!n)return null;let t=null;for(let e of n.split(`
2
+ `).slice(0,30)){let r=tn.exec(e)??en.exec(e);if(!r)continue;let i={fn:(r[1]??"").trim()||"<anonymous>",file:cn(r[2]??"")};if(!an.some(s=>i.file.includes(s)))return i;t??=i;}return t}function pn(n){return (n||"Error").replace(Ft,"")}function $t(n){if(n.digest&&/^[0-9]{6,}$/.test(n.digest))return O(`digest:${n.digest}`);let t=dn(n.stack);return O(`${pn(n.name)}|${un(n.message)}|${t?`${t.fn}@${t.file}`:""}`)}var fn=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,hn=/^[0-9a-f]{16,}$/i,mn=/^(?=.*[0-9])[A-Za-z0-9_-]{20,}$/,gn=/^[a-z][a-z0-9+.-]*:\/\//i;function yn(n){return n?/^[0-9]+$/.test(n)||fn.test(n)||hn.test(n)||mn.test(n)||n.includes("%"):false}function w(n){let t=n;if(gn.test(t))try{t=new URL(t).pathname;}catch{}let e=t.search(/[?#]/);return e>=0&&(t=t.slice(0,e)),t.length>1&&(t=t.replace(/\/+$/,"")),t||"/"}function qt(n){let t=w(n);return t==="/"?t:t.split("/").map(e=>yn(e)?":id":e).join("/")}function it(n,t){return !t||t.length===0?false:t.some(e=>{if(typeof e=="string"){let r=e.length>1?e.replace(/\/+$/,""):e;return n===r||n.startsWith(r==="/"?"/":`${r}/`)}return st(e,n)})}function k(n,t){return !t||t.length===0?false:t.some(e=>typeof e=="string"?n.startsWith(e):st(e,n))}function Ut(n,t){return !t||t.length===0?false:t.some(e=>typeof e=="string"?n.includes(e):st(e,n))}function st(n,t){return n.lastIndex=0,n.test(t)}var bn=/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;function P(n){return n.replace(bn,"[email]")}var vn="0".repeat(32),En="0".repeat(16);function x(n){let t=new Uint8Array(Math.ceil(n/2));try{globalThis.crypto.getRandomValues(t);}catch{for(let r=0;r<t.length;r++)t[r]=Math.floor(Math.random()*256);}let e="";for(let r of t)e+=r.toString(16).padStart(2,"0");return e.slice(0,n)}function ot(){let n=x(32);return n===vn?ot():n}function at(){let n=x(16);return n===En?at():n}function Bt(n,t){return `00-${n}-${t}-01`}function N(n){return typeof n=="string"&&/^[0-9a-f]{32}$/.test(n)}var jt="traceparent",Vt="x-sypnia-session",wn="https://ingest.sypnia.com";function L(n){return (n||wn).replace(/\/+$/,"")}function S(n){return Array.isArray(n)?n.filter(t=>typeof t=="string"||t instanceof RegExp):[]}function H(n,t){return typeof n=="string"&&n.trim()?n.trim().slice(0,t):null}function Gt(n){let t=n.capture??{},e=r=>r!==false;return {project:n.project.trim(),endpoint:L(n.endpoint),environment:H(n.environment,d.env)??"production",release:H(n.release,d.release),debug:n.debug===true,ignoreRoutes:S(n.ignoreRoutes),allowRoutes:S(n.allowRoutes),routeFor:typeof n.routeFor=="function"?n.routeFor:qt,hashRouting:n.hashRouting===true,capture:{errors:e(t.errors),clicks:e(t.clicks),requests:e(t.requests),requestFailureDetail:e(t.requestFailureDetail),vitals:e(t.vitals),forms:e(t.forms)},traceTargets:S(n.traceTargets),recordTargets:S(n.recordTargets),ignoreRequests:S(n.ignoreRequests),ignoreErrors:S(n.ignoreErrors),appFrames:S(n.appFrames),maskAllText:n.maskAllText===true,maskSelector:H(n.maskSelector,2e3),blockSelector:H(n.blockSelector,2e3),replay:n.replay===false?false:{blockedRoutes:S(n.replay?.blockedRoutes)},snapshots:n.snapshots!==false,beforeSend:typeof n.beforeSend=="function"?n.beforeSend:null}}function Sn(n){return n<768?"mobile":n<1024?"tablet":"desktop"}function D(n){let t=a(()=>window.location);if(!t)return "/";if(n){let e=t.hash.replace(/^#!?/,"");return w(e.startsWith("/")?e:`/${e}`)}return w(t.pathname)}function Kt(n,t){let e=w(n).slice(0,500),r;try{r=t(e)||e;}catch{r=e;}return {url:e,route:r.slice(0,500)}}function Xt(){let n=a(()=>document.documentElement.lang||navigator.language)??"";return n?n.slice(0,16):null}function Wt(){let n=a(()=>window.innerWidth)||0;return {dev:Sn(n),vw:n,vh:a(()=>window.innerHeight)||0}}var Rn=5e3,An=1e3,lt=null;function Yt(){let n=_(h.device);return N(n)?n:(lt??=x(32),E(h.device,lt),lt)}function zt(n){return O(`person:${n}`)}function _n(){let n=_(h.session);if(!n)return null;try{let t=JSON.parse(n);return !N(t.sid)||typeof t.last!="number"?null:{sid:t.sid,last:t.last,p:typeof t.p=="string"&&t.p?t.p:null}}catch{return null}}var F=class{constructor(t,e=At){this.now=t;this.idleMs=e;this.sid=null;this.last=0;this.person=null;this.readAt=Number.NEGATIVE_INFINITY;this.storageFailed=false;}touch(){let t=this.now();return this.sync(t),this.alive(t)?(t-this.last>=Rn&&this.write(t),{sid:this.sid,isNew:false}):{sid:this.create(t,this.person),isNew:true}}peek(){let t=this.now();return this.sync(t),this.alive(t)?this.sid:null}identify(t){let e=this.now();if(this.sync(e),t!==this.person){if(this.person===null&&this.alive(e)){this.person=t,this.write(e);return}this.end(t);}}known(){return this.sid}end(t){this.person=t,this.last=0,this.readAt=this.now(),E(h.session,JSON.stringify({sid:this.sid,last:0,p:t}));}sync(t){if(this.sid&&t-this.readAt<An)return;this.readAt=t;let e=_n();e&&(e.sid!==this.sid?e.last>=this.last:e.last>this.last)&&(this.sid=e.sid,this.last=e.last,this.person=e.p);}alive(t){return this.sid!==null&&t-this.last<=this.idleMs}create(t,e){return this.sid=x(32),this.person=e,this.write(t),this.sid}write(t){this.last=t,this.readAt=t,this.storageFailed=!E(h.session,JSON.stringify({sid:this.sid,last:t,p:this.person}));}};var ut=6e4,Zt=2048;async function Jt(n){try{let t=await n.json();return t&&typeof t=="object"?t:{}}catch{return {}}}function Qt(n){return n.slow_down&&typeof n.slow_down=="object"?n.slow_down:null}async function te(n,t){let e=n.status;if(n.ok)return {kind:"stored",slowDown:Qt(await Jt(n))};let r=await Jt(n),i=typeof r.error?.code=="string"?r.error.code:"";return e===429&&i==="limit_reached"?{kind:"limit",slowDown:Qt(r)}:e===408||e===429||e>=500?{kind:"retry",retryAfterMs:Lt(a(()=>n.headers.get("retry-after"))??null,t),throttled:e===429}:e===403&&i==="not_recordable"?{kind:"not_recordable"}:e===401||e===403?{kind:"refused"}:e===422?{kind:"session_full"}:{kind:"rejected"}}async function ee(n){if(n.length<=Zt||!Ct())return n;try{return await Ot(n)}catch{return n}}function ne(n,t,e){try{if(typeof navigator>"u"||typeof navigator.sendBeacon!="function")return !1;let r=`${n}${n.includes("?")?"&":"?"}key=${encodeURIComponent(t)}`;return navigator.sendBeacon(r,new Blob([e],{type:"text/plain;charset=UTF-8"}))}catch{return false}}var re="@sypnia/browser",ie="0.1.0";function Nn(){let n=x(32),t=(parseInt(n.charAt(16),16)&3|8).toString(16);return `${n.slice(0,8)}-${n.slice(8,12)}-4${n.slice(13,16)}-${t}${n.slice(17,20)}-${n.slice(20,32)}`}function Dn(n){let t=[],e=[],r=0;for(let i of n){let s=JSON.stringify(i).length+1;e.length>0&&(r+s>40800||e.length>=200)&&(t.push(e),e=[],r=0),e.push(i),r+=s;}return e.length>0&&t.push(e),t}function Mn(n){let t=-1;for(let e=0;e<n.length;e++){let r=n[e]?.type;if(r==="click")return e;t<0&&r!=="error"&&(t=e);}return Math.max(0,t)}var $=class{constructor(t){this.options=t;this.queue=[];this.timer=null;this.refused=false;this.overflowed=0;}get size(){return this.queue.length}peek(){return this.queue.slice()}enqueue(t){if(!this.refused){for(this.queue.push(t);this.queue.length>500;)this.queue.splice(Mn(this.queue),1),this.overflowed++;this.queue.length>=50&&this.flush("fetch");}}retain(t){this.queue=this.queue.filter(t);}start(){this.timer??=setInterval(()=>{this.flush("fetch");},1e4);}stop(){this.timer&&clearInterval(this.timer),this.timer=null;}async flush(t){try{if(this.queue.length===0||this.refused)return;let e=this.queue;this.queue=[];let r=Dn(e).map(i=>{let s={id:Nn(),events:i};return t==="beacon"&&this.sendBeacon(s)?Promise.resolve():this.send(s,0)});await Promise.all(r);}catch{}}body(t){return JSON.stringify({batch_id:t.id,sent_at:new Date(this.options.now()).toISOString().replace(/\.\d{3}Z$/,"Z"),sdk:{name:re,version:ie},events:t.events})}sendBeacon(t){let e=ne(this.options.url,this.options.project,this.body(t));return e&&this.options.debug(`sent ${t.events.length} events (beacon)`),e}async send(t,e){let r=this.body(t),i=await ee(r),s=await this.post(i);switch(s.kind){case "stored":return;case "limit":s.slowDown&&this.options.onAnswer({accepted:0,dropped:t.events.length,slow_down:s.slowDown});return;case "refused":this.refused=true,this.queue=[],this.stop();return;case "retry":return this.retry(t,e,s);default:this.options.debug(`batch of ${t.events.length} events refused (${s.kind})`);}}retry(t,e,r){let i=r.throttled?e===0?Math.min(Rt,r.retryAfterMs??Q[0]??1e3):void 0:Q[e];return i===void 0?(this.options.debug(`batch of ${t.events.length} events dropped after ${e+1} tries`),Promise.resolve()):new Promise(s=>{setTimeout(()=>{this.send(t,e+1).then(s,s);},i);})}async post(t){try{let e=await this.options.fetch(this.options.url,{method:"POST",keepalive:(typeof t=="string"?t.length:t.byteLength)<=ut,credentials:"omit",headers:{authorization:`Bearer ${this.options.project}`,"content-type":"application/json"},body:t});if(e.ok){let r=await e.clone().json().catch(()=>({}));this.options.debug(`sent: ${JSON.stringify(r)}`),this.options.onAnswer(r);}else (e.status===401||e.status===403)&&this.options.onRefused(e.status);return await te(e,this.options.now())}catch{return {kind:"retry",retryAfterMs:null,throttled:false}}}};var se=5,oe=["record","buffer","off"];function dt(n,t){return {sid:n,mode:"buffer",snapshots:t,seq:0,snaps:[],maskAllText:false,blockedRoutes:[],slowDown:null}}function Cn(n,t){return typeof n=="number"&&Number.isFinite(n)?Math.min(1,Math.max(0,n)):t}function ct(n){return Array.isArray(n)?n.filter(t=>typeof t=="string"):[]}function ae(n,t,e){let r=t.replay??{},i=oe.includes(r.mode)?r.mode:"buffer",s=t.slow_down&&typeof t.slow_down=="object"?t.slow_down:null;return {sid:n,mode:s?.replay===false?"off":i,snapshots:s?.replay!==false&&e()<Cn(t.snapshots?.sample_rate,.5),seq:0,snaps:[],maskAllText:r.mask_all_text===true,blockedRoutes:ct(r.blocked_routes),slowDown:s}}function q(n){let t=_(h.replay);if(!t)return null;try{let e=JSON.parse(t);if(e.sid!==n||!N(n)||!oe.includes(e.mode))return null;let r=typeof e.seq=="number"&&Number.isInteger(e.seq)&&e.seq>=0?e.seq:0;return {sid:n,mode:e.mode,snapshots:e.snapshots===!0,seq:r,snaps:ct(e.snaps).slice(0,se),maskAllText:e.maskAllText===!0,blockedRoutes:ct(e.blockedRoutes),slowDown:e.slowDown&&typeof e.slowDown=="object"?e.slowDown:null}}catch{return null}}function pt(n){let t=q(n.sid),e=n.mode,r=n.slowDown??null;if(t){t.seq>n.seq&&(n.seq=t.seq);for(let i of t.snaps)n.snaps.includes(i)||n.snaps.push(i);(t.mode==="off"||t.mode==="record"&&e==="buffer")&&(e=t.mode),r??=t.slowDown;}E(h.replay,JSON.stringify({...n,mode:e,snaps:n.snaps.slice(0,se),slowDown:r}));}var On=new Set(["error","session_start","page_view","identify","replay_chunk","replay_gap","page_snapshot"]);function Ln(n){return n===0||n===400||n>=500}function ft(n,t){if(!n)return false;let e=n.until?Date.parse(n.until):Number.NaN;return Number.isFinite(e)&&e<=t?false:n.send==="failures"||n.send==="none"||n.replay===false}function ht(n,t,e){return ft(t,e)?t.send==="none"?true:t.send!=="failures"?false:n.type==="request"?!Ln(n.status):!On.has(n.type):false}var Hn='button, a, summary, label, input, select, textarea, [role="button"], [role="link"], [role="tab"], [role="menuitem"], [role="menuitemcheckbox"], [role="menuitemradio"], [role="option"], [role="treeitem"], [role="checkbox"], [role="radio"], [role="switch"], [role="combobox"], [contenteditable=""], [contenteditable="true"], [contenteditable="plaintext-only"]',Fn='button, a[href], summary, input[type="submit"], input[type="button"], [role="button"], [role="tab"], [role="menuitem"], [role="menuitemcheckbox"], [role="menuitemradio"], [role="link"], [role="option"], [role="switch"], [role="checkbox"]',mt='[role="dialog"], [role="alertdialog"], dialog[open], [aria-modal="true"], [role="menu"], [role="listbox"]',$n='[role="dialog"], [role="alertdialog"], dialog, [aria-modal="true"]',de='h1, h2, h3, h4, [role="heading"]',pe='h1, h2, h3, h4, h5, h6, [role="heading"]',qn='nav, aside, header, [role="navigation"], [role="banner"], [role="complementary"]',le="[data-sypnia-mask]",Un='script, style, template, noscript, select, textarea, option, datalist, [hidden], [aria-hidden="true"]',Bn='input, [role="combobox"], [role="listbox"], [role="textbox"], [contenteditable=""], [contenteditable="true"], [contenteditable="plaintext-only"]',y=fe(null,false,n=>n);function fe(n,t,e){let r=n?`${le}, ${n}`:le,i=`${Un}, ${r}`;return {mask:r,skipText:i,skipInLabel:`${i}, ${Bn}`,maskAllText:t,routeFor:e}}function he(n){y=fe(n.maskSelector,n.maskAllText,n.routeFor);}var jn=new Set(["p","span","li","dd","dt","small","strong","em","b","i","blockquote","code","pre"]),me=new Set(["button","submit","reset","image","file"]),Vn=new Set(["select","input","textarea"]),ue={button:"button",link:"link",tab:"tab",menuitem:"menuitem",menuitemcheckbox:"menuitem",menuitemradio:"menuitem",option:"option",treeitem:"option",checkbox:"checkbox",radio:"radio",switch:"switch",combobox:"select",listbox:"select",textbox:"input",searchbox:"input",row:"row",cell:"cell",gridcell:"cell",columnheader:"cell",rowheader:"cell",heading:"heading",img:"image",image:"image"},ge='td, th, [role="cell"], [role="gridcell"], [role="columnheader"], [role="rowheader"]',ye=5,Gn=400,Kn=300;function be(n){try{return n.closest(Hn)}catch{return null}}function Xn(n){return !(!n||n.length>64||/[:\u00AB\u00BB\s]/.test(n)||/^\d/.test(n)||/(^|[-_])\d+$/.test(n)||/[0-9a-f]{8,}/i.test(n)||/^(radix|headlessui|react-select|downshift|mui|floating-ui)[-_]/i.test(n))}function ve(n){return n.replace(/["\\]/g,"\\$&")}function Wn(n){try{if(typeof CSS<"u"&&typeof CSS.escape=="function")return CSS.escape(n)}catch{}return n.replace(/([^\w-])/g,"\\$1")}function Ee(n){let t=[],e=n,r=0;for(;e&&r<ye;){let i=e.tagName.toLowerCase();if(i==="html"||i==="body")break;let s=e.getAttribute("data-testid");if(s){t.unshift(`[data-testid="${ve(s)}"]`);break}if(e.id&&Xn(e.id)){t.unshift(`#${Wn(e.id)}`);break}let l=i,o=e.getAttribute("role");o&&/^[a-z-]+$/i.test(o)&&(l+=`[role="${o}"]`);let u=e.parentElement;if(u){let c=0,f=0;for(let m=0;m<u.children.length;m++){let v=u.children[m];!v||v.tagName!==e.tagName||(f++,v===e&&(c=f));}f>1&&(l+=`:nth-of-type(${c})`);}t.unshift(l),e=u,r++;}return t.join(" > ").slice(0,d.selector)}function we(n){try{if(!n)return;let t=n.nodeType===1?n:n.parentElement;return t&&Ee(t)||void 0}catch{return}}function Yn(n){if(n.tagName.toLowerCase()!=="a")return null;let t=n.getAttribute("href");if(!t)return null;let e=t.trim();if(/^(mailto:|tel:|javascript:|#)/i.test(e))return null;try{let r=new URL(e,window.location.href);return r.protocol!=="http:"&&r.protocol!=="https:"?null:y.routeFor(r.pathname).slice(0,d.path)}catch{return null}}function p(n,t){if(typeof n!="string")return null;let e=n.replace(/\s+/g," ").trim();return e?e.length<=t?e:`${e.slice(0,Math.max(1,t-1)).trimEnd()}\u2026`:null}function gt(n){return n.tagName.toLowerCase()}function g(n){try{return n.closest(y.mask)!==null}catch{return true}}function I(n,t,e=y.skipText){let r=n.ownerDocument;if(!r||typeof r.createTreeWalker!="function"||g(n))return "";let i=r.createTreeWalker(n,5,{acceptNode(u){if(u.nodeType===3)return 1;try{return u.matches(e)?2:3}catch{return 2}}}),s="",l=0;for(let u=i.nextNode();u&&l<Gn;u=i.nextNode()){l++;let c=u.nodeValue;if(!(!c||!/\S/.test(c))&&(s+=` ${c}`,s.length>t*2+1))break}let o=s.replace(/\s+/g," ").trim();return o.length>t+1?o.slice(0,t+1):o}function Se(n){let t=n.getAttribute("contenteditable");return t!==null&&(t===""||t==="true"||t==="plaintext-only")}function zn(n){for(let t of Array.from(n.childNodes))if(t.nodeType===3&&/\S/.test(t.nodeValue||""))return true;return false}function yt(n){try{let t=(n.getAttribute("role")||"").trim().toLowerCase().split(/\s+/)[0];if(t==="textbox"&&n.getAttribute("aria-multiline")==="true")return "textarea";let e=t?ue[t]:void 0;if(e&&Object.prototype.hasOwnProperty.call(ue,t))return e;let r=gt(n);switch(r){case "button":case "summary":return "button";case "a":return "link";case "select":return "select";case "textarea":return "textarea";case "input":{let i=(n.type||n.getAttribute("type")||"text").toLowerCase();return me.has(i)?"button":i==="checkbox"?"checkbox":i==="radio"?"radio":"input"}case "label":{let i=n.control;return i&&i!==n?yt(i):"text"}case "img":case "picture":return "image";case "tr":return "row";case "svg":return "icon"}return Se(n)?"textarea":/^h[1-6]$/.test(r)||n.closest(pe)?"heading":r==="td"||r==="th"||n.closest(ge)?"cell":n.closest("svg")?"icon":jn.has(r)||r==="div"&&zn(n)?"text":"other"}catch{return "other"}}function Re(n,t,e){if(!t)return null;let r=n.ownerDocument,i=[];for(let s of t.trim().split(/\s+/)){if(!s)continue;let l=r.getElementById(s);if(!l||g(l))continue;let o=I(l,e,y.skipInLabel)||l.getAttribute("aria-label")||"";if(o&&i.push(o),i.join(" ").length>e)break}return p(i.join(" "),e)}function Zn(n,t){let e=gt(n);return e==="label"?false:e==="select"||e==="textarea"?true:e==="input"?!me.has((n.type||"").toLowerCase()):Se(n)||Vn.has(t)}function Ae(n,t){let r=n.labels?.[0]??null;if(!r&&n.id)try{r=n.ownerDocument.querySelector(`label[for="${ve(n.id)}"]`);}catch{r=null;}return !r||g(r)?null:p(I(r,t,y.skipInLabel),t)}function Jn(n,t){return Ae(n,t)??p(n.getAttribute("placeholder"),t)??p(n.getAttribute("aria-placeholder"),t)??p(n.getAttribute("data-placeholder"),t)??p(n.getAttribute("title"),t)}function _e(n,t){if(g(n))return null;let e=p(n.getAttribute("aria-label"),t);if(e)return e;let r=n.querySelector("title");return r&&!g(r)?p(r.textContent,t):null}function ce(n,t){let e=n.querySelectorAll(t);for(let r=0;r<e.length&&r<ye*4;r++){let i=e[r];if(i&&!g(i))return i}return null}function Qn(n,t){let e=ce(n,"img[alt]"),r=e?p(e.getAttribute("alt"),t):null;if(r)return r;let i=ce(n,"svg");return i?_e(i,t):null}function tr(n,t){return t==="cell"?n.closest(ge)??n:t==="row"?n.closest('tr, [role="row"]')??n:t==="heading"?n.closest(pe)??n:t==="icon"?n.closest("svg")??n:n}function er(n,t){let e=[],r=0;for(let i of Array.from(n.children)){let s=p(I(i,t),t);if(s&&(e.push(s),r+=s.length+3,r>t))break}return p(e.join(" \xB7 "),t)}function nr(n,t=yt(n)){try{let e=d.label;if(g(n))return null;let r=gt(n);if(r==="html"||r==="body"||r==="main"||n.getAttribute("role")==="main")return null;let i=tr(n,t),s=Re(i,i.getAttribute("aria-labelledby"),e);if(s)return s;let l=p(i.getAttribute("aria-label"),e);if(l)return l;if(r==="input"){let o=(n.type||"").toLowerCase();if(o==="button"||o==="submit"||o==="reset")return p(n.getAttribute("value"),e)??p(n.getAttribute("title"),e);if(o==="image")return p(n.getAttribute("alt"),e)??p(n.getAttribute("title"),e)}if(Zn(n,t))return Jn(n,e);if(r==="img")return p(n.getAttribute("alt"),e)??p(n.getAttribute("title"),e);if(t==="icon")return _e(i,e)??p(i.getAttribute("title"),e);if(t==="row"){let o=er(i,e);if(o)return o}else {let o=I(i,e,r==="label"?y.skipInLabel:y.skipText);if(t==="other"&&o.length>e)return null;let u=p(o,e);if(u)return u}return p(i.getAttribute("title"),e)??Qn(i,e)??Ae(i,e)}catch{return null}}function rr(n,t){let e=Re(n,n.getAttribute("aria-labelledby"),t);if(e)return e;let r=p(n.getAttribute("aria-label"),t);if(r)return r;if(!n.matches($n))return null;let i=n.querySelector(de);return i&&!g(i)?p(I(i,t),t):null}function ir(n){try{let t=d.label,e=n.closest(mt),r=null;for(let u=e;u;u=u.parentElement?.closest(mt)??null){if(g(u)){r??=u;continue}let c=rr(u,t);if(c)return c;r??=u;}let i=n.closest(qn),s=r??n.closest('main, [role="main"]')??i??n.ownerDocument.body;if(!s)return null;let l=s.querySelectorAll(de),o=Math.max(0,l.length-Kn);for(let u=l.length-1;u>=o;u--){let c=l[u];if(!c||c===n||c.contains(n)||!(c.compareDocumentPosition(n)&4)||c.closest(mt)!==e||g(c))continue;let f=p(I(c,t),t);if(f)return f}return s===i&&i?p(i.getAttribute("aria-label"),t):null}catch{return null}}function U(n,t){let e=yt(n),r=y.maskAllText||!!t&&t!==n&&g(t);return {sel:Ee(n),tag:n.tagName.toLowerCase().slice(0,20),txt:r?null:nr(n,e),href:Yn(n),crole:e,ctx:y.maskAllText?null:ir(n)}}var sr=new Set(["button","submit","reset","checkbox","radio","file","image","color","range","hidden"]);function xe(n){let t=n.tagName.toLowerCase();return t==="textarea"?true:t==="input"?!sr.has((n.getAttribute("type")||"text").toLowerCase()):n.isContentEditable===true||n.getAttribute("contenteditable")==="true"}function or(n){if(n.getAttribute("aria-pressed")==="true"||n.getAttribute("aria-selected")==="true")return true;let t=n.getAttribute("aria-current");if(t&&t!=="false")return true;if(n.tagName.toLowerCase()!=="a")return false;let e=(n.getAttribute("href")||"").trim();if(!e)return false;try{let r=window.location,i=new URL(e,r.href);return i.origin===r.origin&&i.pathname===r.pathname&&i.search===r.search}catch{return false}}function Te(n){try{if(!n.matches(Fn))return !1}catch{return false}if(n.hasAttribute("disabled")||n.getAttribute("aria-disabled")==="true")return false;if(n.tagName.toLowerCase()==="a"){let t=(n.getAttribute("href")||"").trim();if(n.getAttribute("target")==="_blank"||n.hasAttribute("download")||/^(mailto:|tel:)/i.test(t))return false}return !or(n)}var ar=100,lr=new Set(["file","date","time","datetime-local","month","week","color"]);function ur(n){return !!n&&typeof n=="object"&&n.nodeType===1}function ke(n){return n.tagName==="SELECT"||n.tagName==="INPUT"&&lr.has(n.type)}function bt(n){if(!n)return false;try{if(ke(n)||n.closest("select"))return !0;if(n.tagName==="LABEL"){let i=n.control;if(i&&ke(i))return !0}let t=n.closest("a");if(!t)return !1;if(t.hasAttribute("download"))return !0;let e=(t.getAttribute("target")||"").toLowerCase();if(e&&e!=="_self"&&e!=="_parent"&&e!=="_top")return !0;let r=t.getAttribute("href")||"";if(/^(?:mailto|tel|sms|whatsapp|intent):/i.test(r))return !0;if(/^https?:\/\//i.test(r))return new URL(r,window.location.href).origin!==window.location.origin}catch{}return false}function cr(n){let t=n.closest("[aria-pressed],[aria-selected],[aria-checked],[aria-current],[aria-disabled]")??n;if(t.disabled)return true;for(let r of ["aria-pressed","aria-selected","aria-checked","aria-disabled"])if(t.getAttribute(r)==="true")return true;let e=t.getAttribute("aria-current");return e!==null&&e!=="false"}function dr(n,t){if(n.detail<2)return false;let e=a(()=>window.getSelection());if(!e||e.isCollapsed||!e.toString().trim())return false;let r=e.anchorNode;return !!r&&(t.contains(r)||r.contains(t))}var R=Math.round,B=class{constructor(t){this.options=t;this.lastMutationAt=-1;this.lastExternalAt=-1;this.lastScrollAt=-1;this.burst=null;this.lastDead=null;this.lastLabel=null;this.mutations=null;this.restores=[];}install(){let t=(e,r,i,s)=>{e.addEventListener(r,i,s),this.restores.push(()=>e.removeEventListener(r,i,s));};t(document,"click",e=>this.onClick(e),true),t(window,"blur",()=>this.noteExternal(),false),t(document,"visibilitychange",()=>this.noteExternal(),false),this.hookClicksOutsideTheDocument();}watchMutations(){this.mutations||typeof MutationObserver!="function"||!document.body||(this.mutations=new MutationObserver(()=>{this.lastMutationAt=this.options.now();}),this.mutations.observe(document.body,{childList:true,subtree:true,attributes:true,characterData:true}));}noteMutation(){this.lastMutationAt=this.options.now();}uninstall(){for(let t of this.restores.splice(0))a(t);a(()=>this.mutations?.disconnect()),this.mutations=null,this.dropRage();}flushRage(){let t=this.burst;t&&(this.dropRage(),t.qualified&&this.emitRage(t));}noteExternal(){this.lastExternalAt=this.options.now();}onClick(t){try{let e=t.target,r=ur(e)?e:e?.parentElement??null;if(!r)return;let i=this.options.now(),s=this.lastLabel;if(this.lastLabel=null,s?.control&&i-s.at<=ar&&(s.control===r||s.control.contains(r)))return;let l=be(r)??r;l.tagName==="LABEL"&&(this.lastLabel={control:a(()=>l.control)??null,at:i}),bt(r)&&(this.lastExternalAt=i);let o={info:U(l,r),coords:this.coordsOf(t,l)};this.options.emit({type:"click",...o.info,...o.coords}),dr(t,l)?this.dropRage():xe(l)||this.trackRage(o),this.trackDead(l,o);}catch{}}coordsOf(t,e){let r=a(()=>e.getBoundingClientRect())??{left:0,top:0,width:0,height:0},i=window.scrollX||0,s=window.scrollY||0,l=t.detail===0&&t.clientX===0&&t.clientY===0,o=l?r.left+r.width/2:t.clientX,u=l?r.top+r.height/2:t.clientY,c=window.innerWidth||1;return {x:R(o+i),y:R(u+s),rx:Math.min(1,Math.max(0,R(o/c*1e3)/1e3)),ry:R(u+s),ex:R(r.left+i),ey:R(r.top+s),ew:R(r.width),eh:R(r.height)}}trackRage(t){let e=this.options.now(),{x:r,y:i}=t.coords,s=this.burst,l=s?.times[s.times.length-1]??Number.NEGATIVE_INFINITY;s&&e-l<=M&&Math.hypot(r-s.x,i-s.y)<=_t?(s.times.push(e),s.last=t):(this.flushRage(),this.burst={x:r,y:i,times:[e],last:t,qualified:false,timer:null});let o=this.burst;o.times.filter(u=>e-u<=M).length>=xt&&(o.qualified=true),o.qualified&&(o.timer&&clearTimeout(o.timer),o.timer=setTimeout(()=>{this.burst===o&&(this.burst=null,this.emitRage(o));},M));}dropRage(){this.burst?.timer&&clearTimeout(this.burst.timer),this.burst=null;}emitRage(t){this.options.emit({type:"rage_click",...t.last.info,...t.last.coords,n:t.times.length}),this.options.onTrouble();}trackDead(t,e){if(!this.mutations||!Te(t)||cr(t))return;let r=this.options.now();if(bt(t)){this.lastExternalAt=r;return}setTimeout(()=>{try{if(this.lastMutationAt>=r||this.options.lastRequestAt()>=r||this.options.lastNavigationAt()>=r||this.lastScrollAt>=r||this.lastExternalAt>=r||a(()=>document.visibilityState)==="hidden")return;let s=this.lastDead;if(s&&s.sel===e.info.sel&&r-s.at<Tt)return;this.lastDead={sel:e.info.sel,at:r},this.options.emit({type:"dead_click",...e.info,...e.coords,n:nt}),this.options.onTrouble();}catch{}},nt);}hookClicksOutsideTheDocument(){let t=(i,s,l)=>{let o=i,u=o?.[s];if(!o||typeof u!="function")return;let c=true,f=function(...m){return c&&a(()=>l(this)),u.apply(this,m)};o[s]=f,this.restores.push(()=>{c=false,o[s]===f&&(o[s]=u);});},e=()=>this.noteExternal(),r=()=>{this.lastScrollAt=this.options.now();};t(window.HTMLInputElement?.prototype,"click",i=>{i.type==="file"&&e();}),t(window.HTMLAnchorElement?.prototype,"click",i=>{bt(i)&&e();}),t(window.HTMLInputElement?.prototype,"showPicker",e),t(window.HTMLSelectElement?.prototype,"showPicker",e);for(let i of ["scrollIntoView","scrollTo","scrollBy"])t(window.Element?.prototype,i,r);for(let i of ["scrollTo","scrollBy"])t(window,i,r);}};var pr=/(?:\(|@|\bat\s)((?:[a-z][a-z0-9+.-]*:\/\/|\[project\]|\[turbopack\]|webpack-internal:)[^\s)]*?)(?::\d+){1,2}\)?\s*$/i,fr=/^(?:chrome|moz|safari-web|safari|ms-browser)-extension:\/\//i,hr=/^https?:\/\//i,mr=/\bethereum\b|__gCrWeb|webkit\.messageHandlers/,gr=/ResizeObserver loop|^Script error\.?$/,yr="NEXT_",br=200;function vr(n){if(!n)return [];let t=[];for(let e of n.split(`
3
+ `).slice(0,50)){let r=pr.exec(e.trim())?.[1];r&&t.push(r);}return t}function Er(n,t,e){return k(n,e)?true:n.startsWith(`${t.origin}/`)?n.slice(t.origin.length).replace(/[?#].*$/,"")!==t.pathname:false}function wr(n,t,e){if(n.src!=="window"&&n.src!=="promise")return false;if(mr.test(n.msg))return true;let r=vr(n.stack);return r.length===0?false:r.some(i=>fr.test(i))?true:r.every(i=>hr.test(i)&&!Er(i,t,e))}function Sr(n){if(n==null)return "";if(typeof n=="string")return n;try{return JSON.stringify(n)??String(n)}catch{return String(n)}}function V(n){if(n&&typeof n=="object"&&typeof n.message=="string"){let t=n;return {name:typeof t.name=="string"&&t.name?t.name:"Error",msg:t.message,stack:typeof t.stack=="string"?t.stack:null,digest:typeof t.digest=="string"&&t.digest?t.digest:null}}return {name:"Error",msg:Sr(n),stack:null,digest:null}}var j=class{constructor(t){this.options=t;this.seen=new Map;this.times=[];}accept(t){let{debug:e}=this.options;if(t.digest?.startsWith(yr)||t.src==="window"&&(!t.msg||gr.test(t.msg)))return null;if(wr(t,this.options.location(),this.options.appFrames))return e(`error not sent, not the app's: ${t.msg}`),null;if(Ut(t.msg,this.options.ignoreErrors))return e(`error not sent, in ignoreErrors: ${t.msg}`),null;let r=t.name.slice(0,d.name)||"Error",i=P(t.msg).slice(0,d.message),s=t.stack?P(t.stack).slice(0,d.stack):null,l=t.digest?t.digest.slice(0,d.digest):null,o=$t({name:r,message:i,stack:s,digest:l});return this.admit(o)?{type:"error",name:r,msg:i,stack:s,digest:l,src:t.src,fp:o}:(e(`error not sent, repeated or over ${tt} a minute: ${i}`),null)}admit(t){let e=this.options.now(),r=this.seen.get(t);if(r!==void 0&&e-r<et||(this.times=this.times.filter(i=>e-i<6e4),this.times.length>=tt))return false;if(this.seen.set(t,e),this.times.push(e),this.seen.size>br)for(let[i,s]of this.seen)e-s>=et&&this.seen.delete(i);return true}};var Rr=["valueMissing","typeMismatch","patternMismatch","tooShort","tooLong","rangeUnderflow","rangeOverflow","stepMismatch","badInput","customError"],G=class{constructor(t){this.options=t;this.lastAt=Number.NEGATIVE_INFINITY;this.remove=null;}install(){let t=e=>this.onInvalid(e);document.addEventListener("invalid",t,true),this.remove=()=>document.removeEventListener("invalid",t,true);}uninstall(){this.remove?.(),this.remove=null;}onInvalid(t){try{let e=t.target;if(!(e instanceof Element))return;this.options.onAnswer();let r=this.options.now();if(r-this.lastAt<kt)return;this.lastAt=r;let i=U(e),s=e.validity,l=s?Rr.find(o=>s[o])??null:null;this.options.emit({type:"form_invalid",field:i.txt,ctx:i.ctx,reason:l,sel:i.sel});}catch{}}};var Ar=5e3,K=class{constructor(t,e){this.now=t;this.hashRouting=e;this.restores=[];this.pending=null;}install(t){let e=a(()=>window.history);if(e)for(let[i,s]of [["pushState","push"],["replaceState","replace"]]){let l=e[i],o=true,u=function(...c){let f=l.apply(this,c);return o&&a(()=>t(s)),f};e[i]=u,this.restores.push(()=>{o=false,e[i]===u&&(e[i]=l);});}let r=()=>t("traverse");if(window.addEventListener("popstate",r),this.restores.push(()=>window.removeEventListener("popstate",r)),this.hashRouting){let i=()=>t("push");window.addEventListener("hashchange",i),this.restores.push(()=>window.removeEventListener("hashchange",i));}}uninstall(){for(let t of this.restores.splice(0))a(t);this.pending=null;}announce(t,e){this.pending=t===e?null:{path:t,since:this.now()};}resolve(t){let e=this.pending;return e?e.path===t||this.now()-e.since>=Ar?(this.pending=null,t):e.path:t}};var Ie=/^[A-Za-z][A-Za-z0-9_.:-]*$/;function Pe(n,t){let e=n.replace(/\s+/g," ").trim();return e.length>t?`${e.slice(0,t-1)}\u2026`:e}function X(n){return typeof n=="string"&&n.trim()?n:null}function W(n){if(!n||typeof n!="object")return null;let t=n,e=X(t.error),r=X(t.message),i=X(t.code)??X(t.error_code),s=e??r;return !i&&e&&Ie.test(e)&&e.toUpperCase()===e&&e.includes("_")&&(i=e,s=r),i&&!Ie.test(i)&&(i=null),!i&&!s?null:{code:i?Pe(i,d.code):null,msg:s?Pe(P(s),d.failureMessage):null}}function Ne(n,t){if(!n?.includes("json"))return null;try{return W(JSON.parse(t))}catch{return null}}var Y=class{constructor(t,e){this.options=t;this.onCall=e;this.restores=[];}plan(t){let e=a(()=>new URL(t,window.location.href));if(!e||e.protocol!=="http:"&&e.protocol!=="https:")return null;let r=e.href;if(r.startsWith(this.options.sypniaUrl())||k(r,this.options.ignoreRequests))return null;let i=e.origin===window.location.origin,s=i||k(r,this.options.traceTargets);if(!s&&!k(r,this.options.recordTargets))return null;let l;try{l=this.options.routeFor(e.pathname)||e.pathname;}catch{l=e.pathname;}return {headers:s,host:i?null:e.host.slice(0,d.host),path:l.slice(0,d.path)}}start(t,e){let r=this.plan(t);if(!r)return null;let i=this.options.session();if(!i)return null;let s=ot(),l=at(),o=(e||"GET").toUpperCase().slice(0,10),u=this.options.now(),c=r.headers?{[jt]:Bt(s,l),[Vt]:i}:{},f=false;this.onCall("start",s);let m=()=>f?false:(f=true,this.onCall("end",s),true),v=(T,J,A)=>this.options.emit({type:"request",method:o,host:r.host,path:r.path,status:T,dur:Math.max(0,Math.round(J-u)),tid:s,span:l,...T>=400&&A?.code?{code:A.code}:{},...T>=400&&A?.msg?{msg:A.msg}:{}},{sid:i,ts:u});return {headers:c,abort:()=>{m();},end:(T,J=null)=>{if(!m())return;let A=this.options.now();if(T>0){v(T,A,J);return}setTimeout(()=>{this.options.lastPageHideAt()<u&&a(()=>v(0,A,null));},It);}}}install(){a(()=>this.installFetch()),a(()=>this.installXhr());}uninstall(){for(let t of this.restores.splice(0))a(t);}installFetch(){let t=window.fetch;if(typeof t!="function")return;let e=true,r=this,i=function(s,l){let o=e?a(()=>r.traceFetch(s,l)):void 0;if(!o)return t.call(window,s,l);let u=t.call(window,o.input,o.init);return r.observeFetch(u,o.trace,o.signal),u};window.fetch=i,this.restores.push(()=>{e=false,window.fetch===i&&(window.fetch=t);});}traceFetch(t,e){let r=typeof Request=="function"&&t instanceof Request?t:null,i=r?r.url:t instanceof URL?t.href:String(t),s=this.start(i,e?.method??r?.method);if(!s)return null;let l=e?.signal??r?.signal??null;if(Object.keys(s.headers).length===0)return {input:t,init:e,trace:s,signal:l};let o=new Headers(e?.headers??r?.headers);for(let[u,c]of Object.entries(s.headers))o.has(u)||o.set(u,c);return r&&!e?{input:new Request(r,{headers:o}),init:e,trace:s,signal:l}:{input:t,init:{...e,headers:o},trace:s,signal:l}}observeFetch(t,e,r){t.then(i=>{if(i.status<400||!this.options.failureDetail){e.end(i.status);return}let s=a(()=>i.clone()),l=a(()=>i.headers.get("content-type"))??null;if(!s||!l?.includes("json")){e.end(i.status);return}s.json().then(o=>e.end(i.status,W(o)),()=>e.end(i.status));},i=>{r?.aborted===true||i?.name==="AbortError"?e.abort():e.end(0);});}installXhr(){let t=window.XMLHttpRequest?.prototype;if(!t)return;let{open:e,send:r,setRequestHeader:i}=t,s=new WeakMap,l=true,o=this;t.open=function(u,c,...f){return a(()=>s.set(this,{method:u,url:String(c),set:new Set})),e.call(this,u,c,...f)},t.setRequestHeader=function(u,c){return a(()=>s.get(this)?.set.add(u.toLowerCase())),i.call(this,u,c)},t.send=function(u){let c=s.get(this),f=l&&c?a(()=>o.start(c.url,c.method)):void 0;if(f&&c){for(let[m,v]of Object.entries(f.headers))c.set.has(m)||a(()=>i.call(this,m,v));o.observeXhr(this,f);}return r.call(this,u)},this.restores.push(()=>{l=false,t.open=e,t.send=r,t.setRequestHeader=i;});}observeXhr(t,e){let r=false;t.addEventListener("abort",()=>{r=true,e.abort();}),t.addEventListener("loadend",()=>{if(r)return;let i=t.status;e.end(i,i>=400&&this.options.failureDetail?this.xhrDetail(t):null);});}xhrDetail(t){return a(()=>{let e=t.getResponseHeader("content-type");return t.responseType==="json"?e?.includes("json")?W(t.response):null:t.responseType!==""&&t.responseType!=="text"?null:Ne(e,t.responseText)})??null}};var _r={LCP:12e4,FCP:12e4,TTFB:12e4,INP:6e4,CLS:10},xr={LCP:[2500,4e3],INP:[200,500],CLS:[.1,.25],TTFB:[800,1800],FCP:[1800,3e3]},Tr=1e3,kr=5e3,Ir=10;function Pr(n,t){return Number.isFinite(t)&&t>=0&&t<=_r[n]}function Nr(n,t){let[e,r]=xr[n];return t<=e?"good":t<=r?"needs-improvement":"poor"}function vt(n,t){let e=we(n);return {...e?{sel:e}:{},...t?{kind:t}:{}}}function Dr(n){let t=e=>Math.max(0,e.width)*Math.max(0,e.height);return Math.max(t(n.previousRect),t(n.currentRect))}var z=class{constructor(t){this.options=t;this.perPage=null;this.observers=[];this.lcp=null;this.lcpDone=false;this.firstHiddenAt=Number.POSITIVE_INFINITY;this.started=false;}start(){if(this.started||typeof PerformanceObserver!="function")return;this.started=true,a(()=>document.visibilityState)==="hidden"&&(this.firstHiddenAt=0);let t=()=>this.finishLcp();for(let e of ["keydown","click"])addEventListener(e,t,{once:true,capture:true});this.observe("largest-contentful-paint",e=>this.onLcp(e)),this.observe("layout-shift",e=>this.onShifts(e)),this.observe("event",e=>this.onInteractions(e),{durationThreshold:40}),this.observe("first-input",e=>this.onInteractions(e)),this.reportLoad();}stop(){for(let t of this.observers.splice(0))a(()=>t.disconnect());}pageStarted(t){this.perPage={page:t,interactions:[],count:0,cls:0,clsTarget:{},window:null,inpSent:-1,clsSent:-1};}pageLeft(t){a(()=>document.visibilityState)==="hidden"&&(this.firstHiddenAt=Math.min(this.firstHiddenAt,performance.now())),this.takeRecords(),this.finishLcp();let e=this.perPage;if(!this.started||!e||e.page.url!==t.url)return;let r=this.inpOf(e);r&&r.duration>e.inpSent&&(e.inpSent=r.duration,this.send("INP",Math.round(r.duration),r.target,t)),(e.cls>e.clsSent||e.clsSent<0&&this.supports("layout-shift"))&&(e.clsSent=e.cls,this.send("CLS",Math.round(e.cls*1e4)/1e4,e.clsTarget,t));}supports(t){return a(()=>PerformanceObserver.supportedEntryTypes?.includes(t))===true}observe(t,e,r={}){this.supports(t)&&a(()=>{let i=new PerformanceObserver(s=>a(()=>e(s.getEntries())));i.observe({type:t,buffered:!0,...r}),this.observers.push(i);});}takeRecords(){for(let t of this.observers){let e=a(()=>t.takeRecords())??[];if(e.length===0)continue;let r=e[0]?.entryType;r==="largest-contentful-paint"?this.onLcp(e):r==="layout-shift"?this.onShifts(e):this.onInteractions(e);}}activationStart(){return a(()=>performance.getEntriesByType("navigation")[0])?.activationStart??0}reportLoad(){let t=this.options.landing();if(!t)return;let e=this.activationStart(),r=a(()=>performance.getEntriesByType("navigation")[0]);r&&r.responseStart>0&&this.send("TTFB",Math.max(0,Math.round(r.responseStart-e)),{},t);let i=l=>{let o=l.find(u=>u.name==="first-contentful-paint");o&&o.startTime<this.firstHiddenAt&&this.send("FCP",Math.max(0,Math.round(o.startTime-e)),{},t);},s=a(()=>performance.getEntriesByType("paint"))??[];s.some(l=>l.name==="first-contentful-paint")?i(s):this.observe("paint",i);}onLcp(t){if(this.lcpDone)return;let e=t[t.length-1];if(!e||e.startTime>=this.firstHiddenAt)return;let r=e.url?"image":"text";this.lcp={value:Math.max(0,e.startTime-this.activationStart()),target:vt(e.element,r)};}finishLcp(){if(this.lcpDone||!this.started)return;this.takeRecords(),this.lcpDone=true;let t=this.options.landing();this.lcp&&t&&this.send("LCP",Math.round(this.lcp.value),this.lcp.target,t);}onShifts(t){let e=this.perPage;if(e)for(let r of t){if(r.hadRecentInput)continue;let i=(r.sources??[]).reduce((u,c)=>{let f=Dr(c);return !u||f>u.area?{node:c.node,area:f}:u},null),s=e.window,l=s&&r.startTime-s.last<Tr&&r.startTime-s.first<kr;(!s||!l)&&(e.window={value:0,first:r.startTime,last:r.startTime,largest:0,target:{}});let o=e.window;o.value+=r.value,o.last=r.startTime,r.value>o.largest&&(o.largest=r.value,o.target=vt(i?.node)),o.value>e.cls&&(e.cls=o.value,e.clsTarget=o.target);}}onInteractions(t){let e=this.perPage;if(e)for(let r of t){let i=r.interactionId??0;if(!i)continue;let s=e.interactions.find(o=>o.id===i);if(s){r.duration>s.duration&&(s.duration=r.duration);continue}e.count++;let l=/^key/.test(r.name)?"keyboard":"pointer";e.interactions.push({id:i,duration:r.duration,target:vt(r.target,l)}),e.interactions.sort((o,u)=>u.duration-o.duration),e.interactions.length=Math.min(e.interactions.length,Ir);}}inpOf(t){let e=Math.min(t.interactions.length-1,Math.floor(t.count/50));return t.interactions[e]??null}send(t,e,r,i){Pr(t,e)&&this.options.emit({type:"vital",name:t,value:e,rating:Nr(t,e),...r},{page:i});}};var Mr=new Set(["page_view","click","rage_click","dead_click","identify"]),Cr=new Set(["vital","page_leave","error"]),Or=1e3,Lr=4e3,Z=class{constructor(t,e){this.options=t;this.deps=e;this.identity=null;this.identifySent=null;this.page=null;this.landing=null;this.lang=null;this.lastSid=null;this.decision=null;this.slowDown=null;this.recorder=null;this.recorderLoading=false;this.active=false;this.idleReady=false;this.cleanups=[];this.inflight=new Set;this.lastRequestAt=-1;this.lastNavigationAt=-1;this.lastPageHideAt=-1;this.lastInputAt=Number.NEGATIVE_INFINITY;this.flushScheduled=false;this.scrollScheduled=false;this.ready=Promise.resolve();this.now=e.now??Date.now,this.random=e.random??Math.random,this.fetch=window.fetch.bind(window),this.sessions=new F(this.now),this.did=Yt(),he({maskSelector:t.maskSelector,maskAllText:t.maskAllText,routeFor:t.routeFor}),this.transport=new $({url:`${t.endpoint}/v1/ingest/events`,project:t.project,now:this.now,fetch:(i,s)=>this.fetch(i,s),onAnswer:i=>this.onAnswer(i),onRefused:i=>this.warn(`the engine refused the key (${i}): nothing is sent from this page`),debug:i=>this.debug(i)});let r=(i,s)=>this.emit(i,s);this.errors=new j({now:this.now,location:()=>({origin:window.location.origin,pathname:window.location.pathname}),ignoreErrors:t.ignoreErrors,appFrames:t.appFrames,debug:i=>this.debug(i)}),this.clicks=new B({now:this.now,emit:r,onTrouble:()=>this.onTrouble(),lastRequestAt:()=>this.lastRequestAt,lastNavigationAt:()=>this.lastNavigationAt}),this.forms=new G({now:this.now,emit:r,onAnswer:()=>this.clicks.noteMutation()}),this.requests=new Y({sypniaUrl:()=>new URL(`${t.endpoint}/v1/`,window.location.href).href,traceTargets:t.traceTargets,recordTargets:t.recordTargets,ignoreRequests:t.ignoreRequests,failureDetail:t.capture.requestFailureDetail,routeFor:t.routeFor,now:this.now,session:()=>C()||this.ignored()?null:this.session(false),lastPageHideAt:()=>this.lastPageHideAt,emit:r},(i,s)=>{i==="start"?(this.lastRequestAt=this.now(),this.inflight.add(s)):this.inflight.delete(s);}),this.vitals=new z({emit:r,landing:()=>this.landing}),this.navigation=new K(this.now,t.hashRouting);}start(){if(this.active)return;this.active=true;let{capture:t}=this.options;this.debug(`started: ${this.options.project.slice(0,12)}\u2026 \u2192 ${this.options.endpoint}, environment ${this.options.environment}, release ${this.options.release??"none"}`),this.installListeners(),t.clicks&&this.clicks.install(),t.forms&&this.forms.install(),t.requests&&this.requests.install(),this.navigation.install(e=>this.onAddressChange(e)),this.transport.start(),this.enterPage(D(this.options.hashRouting),"load",null),this.landing=this.currentPage(),this.sessions.storageFailed&&this.debug("storage unavailable, session kept in memory"),this.ready=new Promise(e=>Mt(()=>{this.onIdle().then(e,e);}));}stop(){if(this.active){a(()=>this.leavePage()),this.transport.flush("fetch"),this.active=false,this.transport.stop(),a(()=>this.recorder?.stop()),a(()=>this.vitals.stop());for(let t of this.cleanups.splice(0))a(t);a(()=>this.clicks.uninstall()),a(()=>this.forms.uninstall()),a(()=>this.requests.uninstall()),a(()=>this.navigation.uninstall()),this.page=null;}}discard(){this.transport.retain(()=>false),this.stop();}isActive(){return this.active}async onIdle(){this.active&&(this.options.capture.clicks&&a(()=>this.clicks.watchMutations()),this.idleReady=true,this.options.capture.vitals&&a(()=>this.vitals.start()),await this.prepareSession());}identify(t){if(!this.active||(this.sessions.identify(t?zt(t.person.id):null),this.identity=t,!t))return;let e=this.sessions.peek();e&&this.identifySent?.sid===e&&this.identifySent.json===JSON.stringify([t.person,t.account])||this.emit({type:"identify",person:t.person,account:t.account});}track(t,e){let r=String(t).trim().slice(0,d.customName);if(!r)return;let i=qr(e);this.emit({type:"custom",name:r,...i?{props:i}:{}},{activity:!this.sessions.peek()});}reportError(t,e={}){let r=V(t),i=typeof e.digest=="string"&&e.digest?e.digest:r.digest;this.report({...r,digest:i,src:e.source==="boundary"?"boundary":"manual"});}async flush(t="fetch"){a(()=>this.recorder?.flush(t)),await this.transport.flush(t);}sessionId(){return this.sessions.peek()??this.lastSid}announceNavigation(t,e){let r=w(this.options.hashRouting?t.replace(/^[^#]*#!?/,"")||"/":t);this.navigation.announce(r,D(this.options.hashRouting)),this.goTo(r,e);}emit(t,e={}){if(this.active)try{e.page||this.syncAddress();let r=e.page??this.currentPage();if(!r||this.isIgnored(r.url))return;let i=e.sid??this.session(e.activity??Mr.has(t.type),r,t.type==="identify");if(!i)return;let s={...this.base(t.type,i,r),...t};e.ts!==void 0&&(s.ts=e.ts),this.queue(s);}catch{}}queue(t){if(ht(t,this.slowDown,this.now())){this.debug(`not sent, the project reached a limit: ${t.type}`);return}let e=t;if(this.options.beforeSend){try{e=this.options.beforeSend(t);}catch{e=t;}if(!e){this.debug(`not sent, beforeSend dropped it: ${t.type}`);return}}this.options.debug&&a(()=>console.debug("[sypnia]",e)),e.type==="identify"&&(this.identifySent={sid:e.sid,json:$r(e)}),this.transport.enqueue(e),Cr.has(e.type)&&C()&&this.flushSoon();}base(t,e,r){return {v:1,type:t,ts:this.now(),sid:e,did:this.did,env:this.options.environment,ver:this.options.release,person:this.identity?{id:this.identity.person.id}:null,account:this.identity?.account?{id:this.identity.account.id}:null,url:r.url,route:r.route,...Wt(),lang:this.lang}}session(t,e=this.currentPage(),r=false){let i=t?this.sessions.touch().sid:this.sessions.peek();if(!i||i===this.lastSid)return i;if(this.lastSid=i,e){this.queue({...this.base("session_start",i,e),...Hr()});let s=this.identity;s&&!r&&this.identifySent?.sid!==i&&this.queue({...this.base("identify",i,e),person:s.person,account:s.account});}return this.idleReady&&this.prepareSession(),i}report(t){if(!this.active)return;let e=this.errors.accept(t);e&&(this.emit(e,{activity:!this.sessions.peek()}),this.onTrouble());}onTrouble(){a(()=>this.recorder?.onTrouble());}currentPage(){return this.page?{url:this.page.url,route:this.page.route}:null}isIgnored(t){let{allowRoutes:e,ignoreRoutes:r}=this.options;return e.length>0&&!it(t,e)?true:it(t,r)}ignored(){return !this.page||this.isIgnored(this.page.url)}onAddressChange(t){this.goTo(this.navigation.resolve(D(this.options.hashRouting)),t);}syncAddress(){let t=this.navigation.resolve(D(this.options.hashRouting));this.page&&t!==this.page.url&&this.goTo(t,"replace");}goTo(t,e){if(!this.active||this.page&&t===this.page.url)return;let r=this.page?.route??null;this.lastNavigationAt=this.now(),this.leavePage(),this.enterPage(t,e,r);}enterPage(t,e,r){let i=Kt(t,this.options.routeFor);this.lang=Xt(),this.page={...i,startedAt:this.now(),maxScroll:0,leaveSent:false},this.measureScroll(),this.vitals.pageStarted(i),this.emit({type:"page_view",nav:e,from:r},{page:i}),a(()=>this.recorder?.onPage(i));}leavePage(){let t=this.page;if(!t||t.leaveSent)return;t.leaveSent=true,this.clicks.flushRage(),this.measureScroll();let e={url:t.url,route:t.route};this.emit({type:"page_leave",dur:Math.max(0,Math.round(this.now()-t.startedAt)),scroll:t.maxScroll},{page:e}),this.vitals.pageLeft(e);}measureScroll(){let t=this.page;t&&a(()=>{let e=Math.max(document.documentElement?.scrollHeight||0,document.body?.scrollHeight||0),r=window.innerHeight||0;if(e<=0||r<=0)return;let i=e<=r?100:Math.min(100,Math.round(((window.scrollY||0)+r)/e*100));t.maxScroll=Math.max(t.maxScroll,i);});}listen(t,e,r,i){let s=l=>a(()=>r(l));t.addEventListener(e,s,i),this.cleanups.push(()=>t.removeEventListener(e,s,i));}installListeners(){this.options.capture.errors&&(this.listen(window,"error",t=>{let e=t,r=V(e.error);this.report({...r,msg:r.msg||(typeof e.message=="string"?e.message:""),src:"window"});}),this.listen(window,"unhandledrejection",t=>{let e=t.reason,r=V(e),i=!!e&&typeof e=="object"&&"message"in e;this.report({...r,name:i?r.name:"UnhandledRejection",src:"promise"});})),this.listen(window,"scroll",()=>this.onScroll(),{passive:true});for(let t of ["keydown","wheel","pointerdown","touchstart"])this.listen(document,t,()=>this.onInput(),{passive:true,capture:true});this.listen(document,"visibilitychange",()=>C()?this.onHidden():this.onVisible()),this.listen(window,"pagehide",()=>this.onPageHide()),this.listen(window,"pageshow",t=>{t.persisted&&this.onVisible();});}onScroll(){if(this.scrollScheduled)return;this.scrollScheduled=true;let t=()=>{this.scrollScheduled=false,this.measureScroll();};typeof requestAnimationFrame=="function"?requestAnimationFrame(t):setTimeout(t,0);}onInput(){let t=this.now();t-this.lastInputAt<Or||this.ignored()||(this.lastInputAt=t,this.session(true));}onHidden(){this.leavePage(),this.transport.flush("beacon"),a(()=>this.recorder?.flush("fetch"));}onVisible(){this.page&&(this.page.startedAt=this.now(),this.page.leaveSent=false),this.ignored()||this.session(true);}onPageHide(){this.lastPageHideAt=this.now(),this.leavePage(),this.transport.flush("beacon"),a(()=>this.recorder?.flush("beacon"));}flushSoon(){this.flushScheduled||(this.flushScheduled=true,queueMicrotask(()=>{this.flushScheduled=false,this.transport.flush("beacon");}));}async prepareSession(){for(let t=0;t<3;t++){let e=this.lastSid;if(!e||!this.active||this.decision?.sid===e)return;let r=q(e)??await this.askDecision(e);if(this.lastSid===e){this.decision=r,r.slowDown&&this.applySlowDown(r.slowDown,false),this.debug(`replay: ${r.mode}, snapshots: ${r.snapshots?"on":"off"}`),await this.startRecorder(r);return}}}async askDecision(t){let e=new URLSearchParams({sid:t});this.identity&&e.set("person",this.identity.person.id),this.identity?.account&&e.set("account",this.identity.account.id);let r=typeof AbortController=="function"?new AbortController:null,i=setTimeout(()=>r?.abort(),Lr);try{let s=await this.fetch(`${this.options.endpoint}/v1/ingest/config?${e.toString()}`,{headers:{authorization:`Bearer ${this.options.project}`},credentials:"omit",...r?{signal:r.signal}:{}}),l=s.ok?await s.json():null,o=l?ae(t,l,this.random):dt(t,this.random()<.5);return pt(o),q(t)??o}catch{return dt(t,this.random()<.5)}finally{clearTimeout(i);}}wantsRecorder(t){let e=this.options.replay!==false&&t.mode!=="off",r=this.options.snapshots&&t.snapshots;return e||r}async startRecorder(t){if(!this.wantsRecorder(t)){a(()=>this.recorder?.stop());return}if(!this.recorder&&!this.recorderLoading){this.recorderLoading=true;try{let e=await this.deps.loadRecorder();this.recorder=e(this.recorderHost());}catch(e){this.debug(`the recorder could not be loaded (${String(e)}): no replay on this page`);}finally{this.recorderLoading=false;}}this.active&&this.decision===t&&a(()=>this.recorder?.start(t));}recorderHost(){let{options:t}=this,e=(r,i)=>this.emit(r,{sid:i});return {endpoint:t.endpoint,project:t.project,environment:t.environment,now:this.now,page:()=>this.active?this.currentPage():null,maskAllText:t.maskAllText,maskSelector:t.maskSelector,blockSelector:t.blockSelector,blockedRoutes:[...t.replay?t.replay.blockedRoutes:[],...t.ignoreRoutes],allowRoutes:t.allowRoutes,replay:t.replay!==false,snapshots:t.snapshots,lastMutationAt:()=>this.clicks.lastMutationAt,pendingRequests:()=>this.inflight.size,onChunk:({sid:r,seq:i,bytes:s,mask:l,full:o})=>e({type:"replay_chunk",seq:i,bytes:s,mask:l,...o?{full:o}:{}},r),onGap:({sid:r,seq:i,reason:s,mask:l})=>e({type:"replay_gap",seq:i,reason:s,mask:l},r),onSnapshot:({sid:r,bytes:i,mask:s,skipped:l})=>e({type:"page_snapshot",bytes:i,mask:s,...l?{skipped:l}:{}},r),onSlowDown:r=>this.applySlowDown(r,true),debug:r=>this.debug(r)}}onAnswer(t){t.slow_down&&this.applySlowDown(t.slow_down,true);}applySlowDown(t,e){if(!ft(t,this.now())){this.slowDown=null;return}this.slowDown=t,this.debug(`slow down: send ${t.send??"all"}, replay ${t.replay===false?"off":"on"} until ${t.until??"?"}`);let r=this.now();this.transport.retain(i=>!ht(i,t,r)),t.replay===false&&a(()=>this.recorder?.onReplayLimit()),e&&this.decision&&(this.decision.slowDown=t,pt(this.decision));}debug(t){this.options.debug&&a(()=>console.debug(`[sypnia] ${t}`));}warn(t){a(()=>console.warn(`[sypnia] ${t}`));}};function Hr(){return {ua:(a(()=>navigator.userAgent)??"").slice(0,d.userAgent),ref:Fr(a(()=>document.referrer)??""),sw:a(()=>window.screen.width)||0,sh:a(()=>window.screen.height)||0,tz:(a(()=>Intl.DateTimeFormat().resolvedOptions().timeZone)??"").slice(0,64)}}function Fr(n){if(!n)return null;try{let t=new URL(n);return `${t.origin}${w(t.pathname)}`.slice(0,d.path)}catch{return null}}function $r(n){return JSON.stringify([n.person,n.account])}function qr(n){if(!n||typeof n!="object")return null;let t={},e=0;for(let r of Object.keys(n)){if(e>=Pt)break;let i=n[r],s=r.slice(0,d.propName);if(i===null||typeof i=="boolean")t[s]=i;else if(typeof i=="number"&&Number.isFinite(i))t[s]=i;else if(typeof i=="string")t[s]=i.slice(0,d.propValue);else continue;e++;}return e>0?t:null}function De(){return _(h.off)!==null}var Me="__sypnia";function Oe(){if(!Nt())return null;let n=window;return n[Me]??={runtime:null,started:false},n[Me]}function b(){return Oe()?.runtime??null}function Et(n){a(()=>console.warn(`[sypnia] off: ${n}`));}function Le(n,t){try{let e=Oe();if(!e||e.started)return;if(!n||typeof n.project!="string"||!n.project.trim()){Et("no project");return}if(n.enabled===!1){n.debug&&Et("disabled");return}if(e.started=!0,e.runtime=new Z(Gt(n),{loadRecorder:t}),De()){n.debug&&Et("opted out");return}e.runtime.start();}catch{}}function Ce(n){if(n==null)return null;let t=String(n).trim();return t?t.slice(0,d.personId):null}function wt(n,t){return typeof n=="string"&&n.trim()?n.trim().slice(0,t):null}function He(n){try{let t=b();if(!t)return;if(n===null){t.identify(null);return}let e=Ce(n?.person?.id);if(!e){a(()=>console.warn("[sypnia] identify: person.id is required"));return}let r=Ce(n.account?.id),i={person:{id:e,name:wt(n.person.name,d.personName),email:wt(n.person.email,d.email)},account:r?{id:r,name:wt(n.account?.name,d.personName)}:null};t.identify(i);}catch{}}function Fe(n,t){a(()=>b()?.track(n,t));}function $e(n,t){a(()=>b()?.reportError(n,t));}async function qe(){try{await b()?.flush("fetch");}catch{}}function Ue(){return a(()=>b()?.isActive()?b()?.sessionId():null)??null}function Be(){a(()=>{E(h.off,"1"),b()?.discard();});}function je(){a(()=>{Dt(h.off);let n=b();n&&!n.isActive()&&n.start();});}function Ve(n,t){a(()=>b()?.announceNavigation(n,t==="replace"||t==="traverse"?t:"push"));}var St="__sypniaRecorder";var Ge=a(()=>document.currentScript)??null;function Ur(n){return ()=>new Promise((t,e)=>{let r=window[St];if(r){t(r);return}let i=document.createElement("script");i.async=true,i.src=`${n}/v1/sdk-recorder.js`,i.onload=()=>{let s=window[St];s?t(s):e(new Error("sdk-recorder.js did not register"));},i.onerror=()=>e(new Error("sdk-recorder.js could not be loaded")),document.head.appendChild(i);})}function Br(){let n=Ge?.src;return n&&n.replace(/\/v1\/sdk\.js(?:\?.*)?$/,"")||void 0}function Ke(n){let t=L(n.endpoint??Br());Le({...n,endpoint:t},Ur(t));}var jr={init:Ke,identify:He,track:Fe,reportError:$e,flush:qe,getSessionId:Ue,optOut:Be,optIn:je,notifyNavigation:Ve};a(()=>{let n=window;if(n.sypnia)return;n.sypnia=jr;let t=Ge?.dataset;t?.project&&Ke({project:t.project,...t.endpoint?{endpoint:t.endpoint}:{},...t.environment?{environment:t.environment}:{},...t.release?{release:t.release}:{}}),window.dispatchEvent(new Event("sypnia:ready"));});})();
package/package.json CHANGED
@@ -1,6 +1,37 @@
1
1
  {
2
2
  "name": "@sypnia/browser",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Sypnia's browser SDK: errors, sessions, replay, clicks, requests and vitals, with typed input always masked.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md",
17
+ "LICENSE"
18
+ ],
19
+ "dependencies": {
20
+ "rrweb": "2.1.6",
21
+ "rrweb-snapshot": "2.1.6"
22
+ },
23
+ "devDependencies": {
24
+ "@sypnia/shared": "0.0.0"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "git+https://github.com/sespinosav/sypnia-js.git",
29
+ "directory": "packages/browser"
30
+ },
31
+ "homepage": "https://docs.sypnia.com/sdks/browser",
32
+ "scripts": {
33
+ "build": "tsup",
34
+ "typecheck": "tsc -p tsconfig.json",
35
+ "e2e": "playwright test -c e2e/playwright.config.mjs"
36
+ }
6
37
  }