@vitalens/core 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -54,9 +54,14 @@ interface PerfContext {
54
54
  user?: PerfUser;
55
55
  device?: Record<string, unknown>;
56
56
  }
57
+ type QueryCaptureMode = 'none' | 'whitelist' | 'all';
57
58
  interface PrivacyConfig {
58
59
  /** 是否移除 URL 的 query 与 hash,默认 true。 */
59
60
  stripQuery?: boolean;
61
+ /** 请求 query 参数采集策略,默认 none;whitelist 时只采 queryWhitelist。 */
62
+ captureQuery?: QueryCaptureMode;
63
+ /** captureQuery='whitelist' 时允许采集的 query key,最多 50 个。 */
64
+ queryWhitelist?: readonly string[];
60
65
  /** 额外脱敏字段名列表,默认包含 token/password/secret/authorization。 */
61
66
  redactKeys?: readonly string[];
62
67
  /** URL 最大长度,超出截断。 */
@@ -111,6 +116,8 @@ interface PerfConfig {
111
116
  }
112
117
  interface ResolvedPrivacyConfig {
113
118
  stripQuery: boolean;
119
+ captureQuery: QueryCaptureMode;
120
+ queryWhitelist: readonly string[];
114
121
  redactKeys: readonly string[];
115
122
  maxUrlLength: number;
116
123
  maxStackLength: number;
@@ -190,6 +197,8 @@ interface RequestRecord extends BaseRecord {
190
197
  status?: number;
191
198
  durationMs: number;
192
199
  success: boolean;
200
+ /** 脱敏后的 query 参数;默认不采集。 */
201
+ query?: Record<string, string>;
193
202
  }
194
203
  interface RouteRecord extends BaseRecord {
195
204
  type: 'route';
@@ -340,4 +349,4 @@ declare function getPerf(): Perf | undefined;
340
349
  declare function initPerf(config: PerfConfig): Perf;
341
350
 
342
351
  export { DEFAULT_CAPTURE, DEFAULT_LIMITS, DEFAULT_PRIVACY, DEFAULT_SAMPLING, DEFAULT_TRANSPORT, createNoopPerf, createPerf, getPerf, initPerf, resolveConfig };
343
- export type { BaseRecord, Collector, CollectorDiagnostics, CollectorName, DegradeLevel, ErrorRecord, ErrorSource, EventRecord, ExposureRecord, FlushReason, LimitsConfig, LongTaskRecord, Perf, PerfConfig, PerfContext, PerfDiagnostics, PerfEnv, PerfErrorInput, PerfEventMap, PerfListener, PerfQuery, PerfRecord, PerfUser, Priority, PrivacyConfig, RecordType, Reporter, RequestRecord, ResolvedLimitsConfig, ResolvedPerfConfig, ResolvedPrivacyConfig, ResourceRecord, RouteInfo, RouteRecord, RouteRecordInput, StorageAdapter, StorageDiagnostics, TrackOptions, TransportConfig, VitalName, VitalRating, VitalRecord };
352
+ export type { BaseRecord, Collector, CollectorDiagnostics, CollectorName, DegradeLevel, ErrorRecord, ErrorSource, EventRecord, ExposureRecord, FlushReason, LimitsConfig, LongTaskRecord, Perf, PerfConfig, PerfContext, PerfDiagnostics, PerfEnv, PerfErrorInput, PerfEventMap, PerfListener, PerfQuery, PerfRecord, PerfUser, Priority, PrivacyConfig, QueryCaptureMode, RecordType, Reporter, RequestRecord, ResolvedLimitsConfig, ResolvedPerfConfig, ResolvedPrivacyConfig, ResourceRecord, RouteInfo, RouteRecord, RouteRecordInput, StorageAdapter, StorageDiagnostics, TrackOptions, TransportConfig, VitalName, VitalRating, VitalRecord };
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import {onCLS,onFCP,onINP,onLCP,onTTFB}from'web-vitals';var At=["vitals","errors","requests","routes","resources","longTask","click","exposure"],Dt=["vital","error","request","route","resource","longTask","event","exposure"],ze={vitals:true,errors:true,requests:true,routes:true,resources:true,longTask:true,click:false,exposure:false},be={vital:1,error:1,request:.1,route:1,resource:.1,longTask:.5,event:1,exposure:.1},O={stripQuery:true,redactKeys:["token","password","secret","authorization"],maxUrlLength:2048,maxStackLength:4096,maxMessageLength:1024,maxStringLength:2e3,user:"none"},y={maxQueueSize:1e3,maxRecordBytes:8192,maxBatchSize:50,maxBatchBytes:262144,flushIntervalMs:5e3,flushDeadlineMs:8,retentionDays:7,maxRecords:2e4,dedupeSize:200,maxErrorsPerMinute:120,maxTracksPerMinute:600},ve={reporter:"indexeddb"};function J(e,t){return typeof e=="string"&&e.trim().length>0?e.trim():t}function h(e,t,r,n){if(typeof e!="number"||!Number.isFinite(e))return t;let o=Math.trunc(e);return o<r||o>n?t:o}function Lt(e,t){return typeof e!="number"||!Number.isFinite(e)?t:Math.min(1,Math.max(0,e))}function _t(e){let t={...ze};if(!e)return t;for(let r of At){let n=e[r];typeof n=="boolean"&&(t[r]=n);}return t}function Ot(e){let t={...be};if(!e)return t;for(let r of Dt)t[r]=Lt(e[r],be[r]);return t}function Nt(e){var r;let t=((r=e==null?void 0:e.redactKeys)!=null?r:O.redactKeys).filter(n=>typeof n=="string"&&n.length>0&&n.length<=64).slice(0,100);return {stripQuery:(e==null?void 0:e.stripQuery)!==false,redactKeys:t,maxUrlLength:h(e==null?void 0:e.maxUrlLength,O.maxUrlLength,16,65536),maxStackLength:h(e==null?void 0:e.maxStackLength,O.maxStackLength,64,65536),maxMessageLength:h(e==null?void 0:e.maxMessageLength,O.maxMessageLength,16,65536),maxStringLength:h(e==null?void 0:e.maxStringLength,O.maxStringLength,16,65536),user:(e==null?void 0:e.user)==="hash"?"hash":"none"}}function Bt(e){return {maxQueueSize:h(e==null?void 0:e.maxQueueSize,y.maxQueueSize,1,1e5),maxRecordBytes:h(e==null?void 0:e.maxRecordBytes,y.maxRecordBytes,256,1048576),maxBatchSize:h(e==null?void 0:e.maxBatchSize,y.maxBatchSize,1,1e3),maxBatchBytes:h(e==null?void 0:e.maxBatchBytes,y.maxBatchBytes,1024,10485760),flushIntervalMs:h(e==null?void 0:e.flushIntervalMs,y.flushIntervalMs,100,6e5),flushDeadlineMs:h(e==null?void 0:e.flushDeadlineMs,y.flushDeadlineMs,1,100),retentionDays:h(e==null?void 0:e.retentionDays,y.retentionDays,1,365),maxRecords:h(e==null?void 0:e.maxRecords,y.maxRecords,100,1e6),dedupeSize:h(e==null?void 0:e.dedupeSize,y.dedupeSize,10,1e4),maxErrorsPerMinute:h(e==null?void 0:e.maxErrorsPerMinute,y.maxErrorsPerMinute,1,1e4),maxTracksPerMinute:h(e==null?void 0:e.maxTracksPerMinute,y.maxTracksPerMinute,1,1e5)}}function qt(e){if(!e)return ve;switch(e.reporter){case "indexeddb":case "console":case "none":return e;case "http":case "beacon":return typeof e.endpoint=="string"&&e.endpoint.trim().length>0?{reporter:e.reporter,endpoint:e.endpoint.trim()}:{reporter:"none"};default:return ve}}function W(e){let t=J(e.appId,"unknown-app");return {...e,appId:t,env:J(e.env,"prod"),buildId:J(e.buildId,"unknown"),storageNamespace:J(e.storageNamespace,t),enabled:e.enabled!==false,capture:_t(e.capture),sampling:Ot(e.sampling),privacy:Nt(e.privacy),limits:Bt(e.limits),transport:qt(e.transport),debug:e.debug===true}}function Ft(e,t){var r;try{(r=t.onError)==null||r.call(t,e);}catch{}}function p(e,t={}){try{return e()}catch(r){Ft(r,t);return}}var Ue="data-perf-track",zt="data-perf-props",Vt="data-perf-ignore",Xe=64,Ut=8192;function Ve(){}function Xt(e){if(!e)return null;let t=e;return t.nodeType!==1||typeof t.getAttribute!="function"||typeof t.hasAttribute!="function"?null:e}function jt(e){var n;try{if(typeof e.composedPath=="function"){let o=e.composedPath();if(Array.isArray(o)&&o.length>0)return o}}catch{}let t=[],r=e.target;for(let o=0;r!==null&&o<Xe;o+=1){t.push(r);try{r=(n=r.parentNode)!=null?n:null;}catch{r=null;}}return t}function Ht(e){let t=jt(e),r=Math.min(t.length,Xe);for(let n=0;n<r;n+=1){let o=Xt(t[n]);if(o){if(o.hasAttribute(Vt))return null;if(o.hasAttribute(Ue))return o}}return null}function $t(e){try{let t=e.getAttribute(Ue);if(typeof t!="string")return;let r=t.trim();return r.length>0?r:void 0}catch{return}}function Qt(e){try{let t=e.getAttribute(zt);if(typeof t!="string"||t.length===0||t.length>Ut)return;let r=JSON.parse(t);if(typeof r=="object"&&r!==null&&!Array.isArray(r))return r}catch{}}function je(e){if(typeof document=="undefined")return Ve;let t=false,r=n=>{if(!t)try{if(n.isTrusted!==!0)return;let o=Ht(n);if(!o)return;let i=$t(o);if(i===void 0)return;let s=Qt(o);p(()=>e(i,s));}catch{}};try{document.addEventListener("click",r,!0);}catch{return Ve}return ()=>{if(!t){t=true;try{document.removeEventListener("click",r,!0);}catch{}}}}var N=1024,He=4096,$e=200,Qe=2048,Gt="vitalens";function Ge(){}function R(e,t){if(typeof e=="string")return e.length>t?e.slice(0,t):e}function we(e,t){if(!(typeof e!="object"||e===null))try{return e[t]}catch{return}}function Yt(e){if(e===void 0)return "Unknown rejection";if(typeof e=="string")return e;if(e instanceof Error)return e.message||e.name||"Unknown error";try{let t=JSON.stringify(e);if(typeof t=="string"&&t.length>0)return t}catch{}try{return String(e)}catch{return "Unknown error"}}function Ye(e){var t;try{return (t=R(Yt(e),N))!=null?t:"Unknown error"}catch{return "Unknown error"}}function Ke(e){var t,r,n;try{if(e instanceof Error)return {name:R(e.name,$e),message:(t=R(e.message,N))!=null?t:"Unknown error",stack:R(e.stack,He)};if(typeof e=="string")return {message:(r=R(e,N))!=null?r:"Unknown error"};if(typeof e=="object"&&e!==null){let o=R(we(e,"name"),$e),i=R(we(e,"message"),N),s=R(we(e,"stack"),He);if(o!==void 0||i!==void 0||s!==void 0)return {name:o,message:(n=i!=null?i:o)!=null?n:Ye(e),stack:s}}return {message:Ye(e)}}catch{return {message:"Unknown error"}}}function Ee(e,t){if(t!==void 0)try{if(t()===!0)return !0}catch{}return typeof e=="string"&&e.toLowerCase().includes(Gt)}function Kt(e){return typeof e.message=="string"}function Jt(e){try{return e.reason}catch{return}}function Wt(e){if(!e)return null;let t=e;return t.nodeType!==1||typeof t.getAttribute!="function"?null:e}function Zt(e){var t;try{let r=e,n=[r.currentSrc,r.src,r.href];for(let i of n)if(typeof i=="string"&&i.length>0)return R(i,Qe);let o=(t=e.getAttribute("src"))!=null?t:e.getAttribute("href");return o?R(o,Qe):void 0}catch{return}}function Je(e,t={}){if(typeof window=="undefined")return Ge;let r=t.unhandledRejection!==false,n=t.resourceErrors!==false,o=t.isInternal,i=false,s=false,a=f=>{p(()=>e(f));},c=f=>{var u,b;if(!(i||s)){s=true;try{if(Kt(f)){let Fe=f.error==null?{message:(u=R(f.message,N))!=null?u:"Unknown error"}:Ke(f.error);if(Ee(Fe.stack,o))return;a({...Fe,source:"window"});return}if(!n)return;let A=Wt(f.target);if(!A||Ee(void 0,o))return;let Be=Zt(A),qe=typeof A.tagName=="string"?A.tagName:"resource",Ct=Be===void 0?"":`: ${Be}`;a({name:qe,message:(b=R(`Failed to load ${qe.toLowerCase()}${Ct}`,N))!=null?b:"Failed to load resource",source:"resource"});}catch{}finally{s=false;}}},d=f=>{if(!(i||s)){s=true;try{let u=Ke(Jt(f));if(Ee(u.stack,o))return;a({...u,source:"unhandledrejection"});}catch{}finally{s=false;}}};try{window.addEventListener("error",c,!0);}catch{return Ge}if(r)try{window.addEventListener("unhandledrejection",d);}catch{}return ()=>{if(!i){i=true;try{window.removeEventListener("error",c,!0);}catch{}if(r)try{window.removeEventListener("unhandledrejection",d);}catch{}}}}var er=50;function B(){}function We(){return typeof PerformanceObserver!="undefined"&&typeof PerformanceObserver=="function"}function Ze(e){try{let t=PerformanceObserver.supportedEntryTypes;return t===void 0||t.includes(e)}catch{return false}}function tr(e,t){return typeof e=="number"&&Number.isFinite(e)&&e>=0?e:t}function rr(e){return typeof e=="number"&&Number.isFinite(e)&&e>=0?e:void 0}function Z(e){try{e.disconnect();}catch{}}function et(e,t={}){if(!We()||!Ze("longtask"))return B;let r=tr(t.threshold,er),n=false,o;try{o=new PerformanceObserver(i=>{if(n)return;let s;try{s=i.getEntries();}catch{return}for(let a of s)try{let c=a.duration;if(!Number.isFinite(c)||c<r)continue;let d={durationMs:c,startTime:a.startTime};typeof a.name=="string"&&a.name.length>0&&(d.name=a.name),p(()=>e(d));}catch{}});}catch{return B}try{o.observe({entryTypes:["longtask"]});}catch{return Z(o),B}return ()=>{n||(n=true,o!==void 0&&(Z(o),o=void 0));}}function nr(e){return e.entryType==="resource"}function or(e){try{let t=e,r=t.responseStatus;if(typeof r=="number"&&r>0)return r>=400;let n=t.transferSize,o=t.decodedBodySize;return typeof n=="number"&&typeof o=="number"?n===0&&o===0&&e.duration===0:!1}catch{return false}}function ir(e,t,r){if(!nr(e))return;let n=typeof e.name=="string"?e.name:"";if(n.length===0)return;let o=Number.isFinite(e.duration)?e.duration:void 0,i=or(e),s=t!==void 0&&o!==void 0&&o>=t;if(!i&&!s)return;let a={url:n,failed:i},c=e.initiatorType;typeof c=="string"&&c.length>0&&(a.initiatorType=c),o!==void 0&&(a.durationMs=o),p(()=>r(a));}function tt(e,t={}){if(!We()||!Ze("resource"))return B;let r=rr(t.slowThreshold),n=false,o;try{o=new PerformanceObserver(i=>{if(n)return;let s;try{s=i.getEntries();}catch{return}for(let a of s)try{ir(a,r,e);}catch{}});}catch{return B}try{o.observe({entryTypes:["resource"]});}catch{return Z(o),B}return ()=>{n||(n=true,o!==void 0&&(Z(o),o=void 0));}}function D(){return Date.now()}function w(){return typeof performance!="undefined"&&typeof performance.now=="function"?performance.now():Date.now()}var H=new Set,te,q,re,ne,F,z,$=new WeakMap;function rt(e){for(let t of [...H])H.has(t)&&p(()=>t(e));}function sr(e,t){if(typeof(t==null?void 0:t.method)=="string"&&t.method.length>0)return t.method;if(typeof e=="object"&&e!==null){let r=e.method;if(typeof r=="string"&&r.length>0)return r}return "GET"}function ar(e){if(typeof e=="string")return e;if(typeof e=="object"&&e!==null){let t=e;if(typeof t.url=="string")return t.url;if(typeof t.href=="string")return t.href}try{return String(e)}catch{return ""}}function cr(e){try{let t=typeof e.status=="number"?e.status:void 0;return typeof e.ok=="boolean"?{status:t,success:e.ok}:t!==void 0?{status:t,success:t>=200&&t<300}:{success:!0}}catch{return {success:true}}}function ur(e,t){try{return {method:sr(e,t),url:ar(e),start:w()}}catch{return}}function ee(e,t){if(e)try{let r={kind:"fetch",method:e.method,url:e.url,durationMs:Math.max(0,w()-e.start),success:t.success};t.status!==void 0&&(r.status=t.status),rt(r);}catch{}}function dr(e){return function(r,n){let o=ur(r,n),i;try{i=e.call(this,r,n);}catch(s){throw ee(o,{success:false}),s}try{return i.then(s=>(ee(o,cr(s)),s),s=>{throw ee(o,{success:!1}),s})}catch{return ee(o,{success:true}),i}}}function fr(){if(typeof globalThis.fetch!="function")return;let e=globalThis.fetch;if(q!==void 0&&e===q)return;let t=dr(e);try{globalThis.fetch=t;}catch{return}te=e,q=t;}function lr(){try{q!==void 0&&te!==void 0&&globalThis.fetch===q&&(globalThis.fetch=te);}catch{}te=void 0,q=void 0;}function pr(e){return typeof e=="string"&&e.length>0?e:"GET"}function hr(e){if(typeof e=="string")return e;if(typeof e=="object"&&e!==null){let t=e.href;if(typeof t=="string")return t}try{return String(e)}catch{return ""}}function mr(e){try{return typeof e.status=="number"?e.status:void 0}catch{return}}function gr(e){try{let t=$.get(e);if(!t)return;$.delete(e);let r=mr(e),n={kind:"xhr",method:t.method,url:t.url,durationMs:Math.max(0,w()-t.start),success:r!==void 0&&r>=200&&r<300};r!==void 0&&(n.status=r),rt(n);}catch{}}function yr(e){return ()=>gr(e)}function nt(){if(typeof XMLHttpRequest!="undefined")try{return XMLHttpRequest.prototype}catch{return}}function Rr(){let e=nt();if(!e||F!==void 0&&z!==void 0&&e.open===F&&e.send===z)return;let t=e.open,r=e.send;if(typeof t!="function"||typeof r!="function")return;let n=function(s,a,c,d,f){try{$.set(this,{method:pr(s),url:hr(a),start:w()});}catch{}try{t.call(this,s,a,c,d,f);}catch(u){throw $.delete(this),u}},o=function(s){let a;try{let c=$.get(this);c&&(c.start=w(),a=yr(this),this.addEventListener("loadend",a,{once:!0}));}catch{a=void 0;}try{r.call(this,s);}catch(c){if(a!==void 0)try{this.removeEventListener("loadend",a);}catch{}throw c}};try{e.open=n;}catch{return}try{e.send=o;}catch{try{e.open=t;}catch{}return}re=t,ne=r,F=n,z=o;}function br(){let e=nt();if(e){if(F!==void 0&&re!==void 0&&e.open===F)try{e.open=re;}catch{}if(z!==void 0&&ne!==void 0&&e.send===z)try{e.send=ne;}catch{}}re=void 0,ne=void 0,F=void 0,z=void 0;}function ot(e,t={}){let r=typeof t.slowThreshold=="number"&&Number.isFinite(t.slowThreshold)&&t.slowThreshold>=0?t.slowThreshold:void 0,n=i=>{r!==void 0&&i.success&&i.durationMs<r||e(i);};H.add(n),fr(),Rr();let o=false;return ()=>{o||(o=true,H.delete(n),H.size===0&&(lr(),br()));}}function Tr(){}function it(e,t={}){if(typeof window=="undefined")return Tr;let r=t.reportAllChanges===true,n=false,o=s=>{n||p(()=>e({name:s.name,value:s.value,rating:s.rating,id:s.id}));},i=[()=>onCLS(o,{reportAllChanges:r}),()=>onFCP(o,{reportAllChanges:r}),()=>onINP(o,{reportAllChanges:r}),()=>onLCP(o,{reportAllChanges:r}),()=>onTTFB(o,{reportAllChanges:r})];for(let s of i)try{s();}catch{}return ()=>{n=true;}}var Pe=0;function kr(e){let t=new Uint8Array(Math.ceil(e/2));try{if(typeof crypto!="undefined"&&typeof crypto.getRandomValues=="function")crypto.getRandomValues(t);else for(let n=0;n<t.length;n+=1)t[n]=Math.floor(Math.random()*256);}catch{for(let n=0;n<t.length;n+=1)t[n]=Math.floor(Math.random()*256);}let r="";for(let n of t)r+=n.toString(16).padStart(2,"0");return r.slice(0,e)}function Q(){return Pe=(Pe+1)%65536,`${Date.now().toString(36)}-${Pe.toString(36)}-${kr(10)}`}var st="vitalens:session",oe;function Sr(){if(oe)return oe;try{let t=sessionStorage.getItem(st);if(t)return oe=t,t}catch{}let e=Q();oe=e;try{sessionStorage.setItem(st,e);}catch{}return e}function Ir(){if(typeof navigator=="undefined")return {};let e=navigator.connection;return {ua:typeof navigator.userAgent=="string"?navigator.userAgent.slice(0,512):"",screen:typeof screen!="undefined"?`${screen.width}x${screen.height}`:"unknown",language:typeof navigator.language=="string"?navigator.language:"unknown",connection:e==null?void 0:e.effectiveType}}function at(e){let t=typeof location!="undefined"?{path:location.pathname||"/",fullPath:`${location.pathname||"/"}${location.search||""}`}:void 0;return {appId:e.appId,buildId:e.buildId,env:e.env,sessionId:e.enabled?Sr():Q(),route:t,device:Ir()}}var ie=class{constructor(t){this.listeners=new Set;this.onError=t;}get size(){return this.listeners.size}subscribe(t){return this.listeners.add(t),()=>{this.listeners.delete(t);}}emit(t){if(t.length!==0)for(let r of [...this.listeners])p(()=>r(t),{onError:this.onError});}dispose(){this.listeners.clear();}};var Mr=/[\w.+-]+@[\w.-]+\.\w+/g,Cr=/1[3-9]\d{9}/g,Ar=new Set(["__proto__","constructor","prototype"]);function xe(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Dr(e){return Ar.has(e)}function g(e,t){return e.length<=t?e:e.slice(0,t)}function se(e){return e.replace(Mr,"[REDACTED]").replace(Cr,"[REDACTED]")}function G(e,t){let r=se(e);if(!t.stripQuery)return g(r,t.maxUrlLength);try{let n=new URL(r,"http://localhost"),o=n.origin==="http://localhost"?n.pathname||"/":`${n.origin}${n.pathname}`;return g(o,t.maxUrlLength)}catch{let n=r.search(/[?#]/),o=n>=0?r.slice(0,n):r;return g(o,t.maxUrlLength)}}function Lr(e,t){let r=e.toLowerCase();return t.redactKeys.some(n=>n.toLowerCase()===r)}function Te(e,t,r,n){if(Lr(t,r))return "[REDACTED]";if(e===null)return null;if(typeof e=="string")return g(se(e),r.maxStringLength);if(typeof e=="number"||typeof e=="boolean")return e;if(typeof e=="bigint")return e.toString();if(!(typeof e=="undefined"||typeof e=="function"||typeof e=="symbol")){if(n>=3)return "[Truncated]";if(Array.isArray(e)){let o=[];for(let i of e.slice(0,50)){let s=Te(i,t,r,n+1);s!==void 0&&o.push(s);}return o}if(xe(e)){let o={},i=0;for(let[s,a]of Object.entries(e)){if(i>=100)break;if(Dr(s))continue;let c=Te(a,s,r,n+1);c!==void 0&&(o[s]=c,i+=1);}return o}}}function ae(e,t){if(!xe(e))return;let r=Te(e,"",t,0);return xe(r)?r:void 0}function ke(e){try{return JSON.stringify(e).length}catch{return Number.POSITIVE_INFINITY}}function V(e,t){if(e)return {path:G(e.path,t),fullPath:e.fullPath?G(e.fullPath,t):void 0,name:e.name?g(se(e.name),t.maxStringLength):void 0}}function Se(e,t){return se(g(e,t))}var Ie=["P0","P1","P2"],_r=["P2","P1","P0"],ce=class{constructor(t,r=Math.max(2,Math.floor(t/4))){this.buckets={P0:[],P1:[],P2:[]};this.typeCounts=new Map;this.total=0;this.dropped=0;this.maxSize=Math.max(1,t),this.maxPerType=Math.max(1,r);}get size(){return this.total}enqueue(t,r){var n,o;return this.total>=this.maxSize&&this.dropLowest(),t.priority!=="P0"&&((n=this.typeCounts.get(t.type))!=null?n:0)>=this.maxPerType&&this.dropOldestOfType(t.type),this.total>=this.maxSize?(this.dropped+=1,false):(this.buckets[t.priority].push({record:t,size:r}),this.total+=1,this.typeCounts.set(t.type,((o=this.typeCounts.get(t.type))!=null?o:0)+1),true)}takeBatch(t,r){let n=[],o=0;for(let i of Ie){let s=this.buckets[i];for(;n.length<t;){let a=s[0];if(!a)break;if(n.length>0&&o+a.size>r)return n;if(a.size>r){s.shift(),this.total-=1,this.decrementType(a.record.type),this.dropped+=1;continue}s.shift(),this.total-=1,this.decrementType(a.record.type),n.push(a),o+=a.size;}}return n}requeue(t){for(let r of t)this.enqueue(r.record,r.size);}clear(){for(let t of Ie)this.buckets[t].length=0;this.typeCounts.clear(),this.total=0;}decrementType(t){var n;let r=(n=this.typeCounts.get(t))!=null?n:0;r<=1?this.typeCounts.delete(t):this.typeCounts.set(t,r-1);}dropLowest(){for(let t of _r){let n=this.buckets[t].shift();if(n)return this.total-=1,this.decrementType(n.record.type),this.dropped+=1,true}return false}dropOldestOfType(t){for(let r of Ie){let n=this.buckets[r],o=n.findIndex(i=>i.record.type===t);if(o>=0){let[i]=n.splice(o,1);if(i)return this.total-=1,this.decrementType(t),this.dropped+=1,true}}return false}};function Or(e){return Number.isFinite(e)?Math.min(1,Math.max(0,e)):1}function x(e,t=Math.random){let r=Or(e);return r>=1?true:r<=0?false:t()<r}function ct(){return typeof globalThis.requestIdleCallback=="function"}function ut(){let e=globalThis.scheduler;return typeof(e==null?void 0:e.postTask)=="function"}var ue=class{constructor(t){this.disposers=new Set;this.onError=t;}schedule(t,r={}){var s,a,c,d,f;let n=false,o=()=>{},i=()=>{n||(n=true,this.disposers.delete(o),p(t,{onError:this.onError}));};if(r.delayMs&&r.delayMs>0){let u=setTimeout(i,r.delayMs);o=()=>{n=true,clearTimeout(u),this.disposers.delete(o);};}else if(ut()){let u=globalThis.scheduler,b=typeof AbortController!="undefined"?new AbortController:void 0;(a=(s=u==null?void 0:u.postTask)==null?void 0:s.call(u,i,{priority:"background",signal:b==null?void 0:b.signal}))==null||a.catch(()=>{i();}),o=()=>{n=true,b==null||b.abort(),this.disposers.delete(o);};}else if(ct()){let u=globalThis,b=(f=(d=u.requestIdleCallback)==null?void 0:d.call(u,i,{timeout:(c=r.timeoutMs)!=null?c:1e3}))!=null?f:0;o=()=>{var A;n=true,(A=u.cancelIdleCallback)==null||A.call(u,b),this.disposers.delete(o);};}else {let u=setTimeout(i,0);o=()=>{n=true,clearTimeout(u),this.disposers.delete(o);};}return this.disposers.add(o),o}dispose(){for(let t of [...this.disposers])t();this.disposers.clear();}};function T(e,t,r,n){return {id:Q(),type:r,priority:n,timestamp:D(),appId:e.appId,sessionId:t.sessionId,buildId:e.buildId,env:e.env,route:t.route}}function k(e){switch(e){case "vital":case "error":return "P0";case "event":case "route":case "exposure":return "P1";case "request":case "resource":case "longTask":return "P2";default:return "P2"}}function dt(e){let t=256;if("message"in e&&(t+=e.message.length,e.stack&&(t+=e.stack.length)),"url"in e&&(t+=e.url.length),"name"in e&&typeof e.name=="string"&&(t+=e.name.length),"props"in e&&e.props)try{t+=JSON.stringify(e.props).length;}catch{t+=512;}return t}function ft(e,t){switch(e.transport.reporter){case "indexeddb":return {name:"indexeddb",report:r=>t().put(r)};case "console":return {name:"console",report:async r=>{console.warn(`[vitalens] ${r.length} records`,r.map(n=>n.type).join(","));}};case "http":case "beacon":return {name:e.transport.reporter,report:async()=>{}};default:return {name:"none",report:async()=>{}}}}function m(e,t){let r=Nr(e);return new Error(r.length>0?`${t}\uFF1A${r}`:t)}function Nr(e){if(e instanceof Error)return e.message;if(typeof e=="string")return e;if(typeof e=="object"&&e!==null&&"message"in e){let t=e.message;if(typeof t=="string")return t}return String(e)}var Br="desc";function qr(e){return typeof e!="number"||!Number.isFinite(e)?0:Math.max(0,Math.trunc(e))}function Fr(e){if(!(typeof e!="number"||!Number.isFinite(e)))return e<=0?0:Math.trunc(e)}function U(e,t={}){var d;let r=t.types?new Set(t.types):null,n=typeof t.from=="number"&&Number.isFinite(t.from)?t.from:void 0,o=typeof t.to=="number"&&Number.isFinite(t.to)?t.to:void 0,i=e.filter(f=>!(r!==null&&!r.has(f.type)||n!==void 0&&f.timestamp<n||o!==void 0&&f.timestamp>o)),s=((d=t.order)!=null?d:Br)==="asc"?1:-1;i.sort((f,u)=>(f.timestamp-u.timestamp)*s);let a=qr(t.offset),c=Fr(t.limit);return c===void 0?i.slice(a):i.slice(a,a+c)}var zr=new Set(["__proto__","constructor","prototype"]),Vr=new Set(["vital","error","request","route","resource","longTask","event","exposure"]),Ur=new Set(["LCP","INP","CLS","FCP","TTFB"]),Xr=new Set(["good","needs-improvement","poor"]),jr=new Set(["window","unhandledrejection","resource","vue","manual"]),Hr=new Set(["manual","click","pageView"]),S=["id","type","priority","timestamp","appId","sessionId","buildId","env","route"],$r={vital:new Set([...S,"name","value","rating","metricId"]),error:new Set([...S,"name","message","stack","source","fingerprint","count","component"]),request:new Set([...S,"kind","method","url","status","durationMs","success"]),route:new Set([...S,"to","from","durationMs","navigation"]),resource:new Set([...S,"url","initiatorType","durationMs","failed","status"]),longTask:new Set([...S,"durationMs","name"]),event:new Set([...S,"name","props","source","truncated"]),exposure:new Set([...S,"name","props","target","truncated"])},l=new Error("invalid perf record"),X={ok:false};function P(e){if(typeof e!="object"||e===null||Array.isArray(e))return false;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function M(e){for(let t of Object.getOwnPropertyNames(e))if(zr.has(t))return true;return false}function Qr(e,t){for(let r of Object.getOwnPropertyNames(e))if(!t.has(r))return false;return true}function ht(e){return typeof e=="string"&&Vr.has(e)}function mt(e){return typeof e=="string"&&Ur.has(e)}function gt(e){return typeof e=="string"&&Xr.has(e)}function yt(e){return typeof e=="string"&&jr.has(e)}function Rt(e){return typeof e=="string"&&Hr.has(e)}function bt(e){return e==="P0"||e==="P1"||e==="P2"}function I(e){return typeof e=="number"&&Number.isFinite(e)}function fe(e){return typeof e=="string"&&e.trim().length>0}function v(e){return e===void 0||typeof e=="string"}function de(e){return e===void 0||I(e)}function lt(e){return e===void 0||typeof e=="boolean"}function Me(e){if(!P(e)||M(e)||typeof e.path!="string"||!v(e.fullPath)||!v(e.name))return false;for(let t of Object.getOwnPropertyNames(e))if(t!=="path"&&t!=="fullPath"&&t!=="name")return false;return true}function pt(e){return P(e)&&!M(e)}function vt(e){if(!P(e)||M(e))return false;let t=e.type;if(!ht(t)||!Qr(e,$r[t])||!fe(e.id)||!I(e.timestamp)||!fe(e.appId)||!fe(e.sessionId)||!bt(e.priority)||!v(e.buildId)||!v(e.env)||e.route!==void 0&&!Me(e.route))return false;switch(t){case "vital":return mt(e.name)&&I(e.value)&&(e.rating===void 0||gt(e.rating))&&v(e.metricId);case "error":return typeof e.message=="string"&&yt(e.source)&&typeof e.fingerprint=="string"&&v(e.name)&&v(e.stack)&&v(e.component)&&de(e.count);case "request":return (e.kind==="fetch"||e.kind==="xhr")&&typeof e.method=="string"&&typeof e.url=="string"&&I(e.durationMs)&&typeof e.success=="boolean"&&de(e.status);case "route":return Me(e.to)&&(e.from===void 0||Me(e.from))&&I(e.durationMs)&&(e.navigation==="initial"||e.navigation==="spa");case "resource":return typeof e.url=="string"&&typeof e.failed=="boolean"&&v(e.initiatorType)&&de(e.durationMs)&&de(e.status);case "longTask":return I(e.durationMs)&&v(e.name);case "event":return typeof e.name=="string"&&(e.props===void 0||pt(e.props))&&(e.source===void 0||Rt(e.source))&&lt(e.truncated);case "exposure":return typeof e.name=="string"&&(e.props===void 0||pt(e.props))&&v(e.target)&&lt(e.truncated);default:return false}}function Ae(e,t){if(t>8)return X;switch(typeof e){case "string":case "boolean":return {ok:true,value:e};case "number":return Number.isFinite(e)?{ok:true,value:e}:X;case "object":{if(e===null)return {ok:true,value:null};if(Array.isArray(e)){let n=e,o=[];for(let i of n){let s=Ae(i,t+1);if(!s.ok)return X;o.push(s.value);}return {ok:true,value:o}}if(!P(e)||M(e))return X;let r={};for(let n of Object.keys(e)){let o=Ae(e[n],t+1);if(!o.ok)return X;r[n]=o.value;}return {ok:true,value:r}}default:return X}}function De(e){if(!P(e)||M(e)||typeof e.path!="string")return null;let t={path:e.path};if(e.fullPath!==void 0){if(typeof e.fullPath!="string")return null;t.fullPath=e.fullPath;}if(e.name!==void 0){if(typeof e.name!="string")return null;t.name=e.name;}return t}function wt(e,t){let r=e[t];if(r===void 0)return;if(!P(r)||M(r))throw l;let n=Ae(r,0);if(!n.ok||!P(n.value))throw l;return n.value}function L(e,t){let r=e[t];if(typeof r!="string")throw l;return r}function Ce(e,t){let r=e[t];if(!fe(r))throw l;return r}function Y(e,t){let r=e[t];if(!I(r))throw l;return r}function E(e,t){let r=e[t];if(r!==void 0){if(typeof r!="string")throw l;return r}}function le(e,t){let r=e[t];if(r!==void 0){if(!I(r))throw l;return r}}function pe(e,t){let r=e[t];if(r!==void 0){if(typeof r!="boolean")throw l;return r}}function C(e,t){let r=Ce(e,"id"),n=Ce(e,"appId"),o=Ce(e,"sessionId"),i=Y(e,"timestamp"),s=e.priority;if(!bt(s))throw l;let a=E(e,"buildId"),c=E(e,"env"),d;if(e.route!==void 0){let u=De(e.route);if(!u)throw l;d=u;}let f={id:r,type:t,priority:s,timestamp:i,appId:n,sessionId:o};return a!==void 0&&(f.buildId=a),c!==void 0&&(f.env=c),d!==void 0&&(f.route=d),f}function Gr(e){let t=e.name;if(!mt(t))throw l;let r=Y(e,"value"),n=E(e,"metricId"),o={...C(e,"vital"),type:"vital",name:t,value:r},i=e.rating;if(i!==void 0){if(!gt(i))throw l;o.rating=i;}return n!==void 0&&(o.metricId=n),o}function Yr(e){let t=L(e,"message"),r=L(e,"fingerprint"),n=e.source;if(!yt(n))throw l;let o=E(e,"name"),i=E(e,"stack"),s=E(e,"component"),a=le(e,"count"),c={...C(e,"error"),type:"error",message:t,source:n,fingerprint:r};return o!==void 0&&(c.name=o),i!==void 0&&(c.stack=i),s!==void 0&&(c.component=s),a!==void 0&&(c.count=a),c}function Kr(e){let t=e.kind;if(t!=="fetch"&&t!=="xhr")throw l;let r=L(e,"method"),n=L(e,"url"),o=Y(e,"durationMs"),i=pe(e,"success");if(i===void 0)throw l;let s=le(e,"status"),a={...C(e,"request"),type:"request",kind:t,method:r,url:n,durationMs:o,success:i};return s!==void 0&&(a.status=s),a}function Jr(e){let t=De(e.to);if(!t)throw l;let r;if(e.from!==void 0){let s=De(e.from);if(!s)throw l;r=s;}let n=Y(e,"durationMs"),o=e.navigation;if(o!=="initial"&&o!=="spa")throw l;let i={...C(e,"route"),type:"route",to:t,durationMs:n,navigation:o};return r!==void 0&&(i.from=r),i}function Wr(e){let t=L(e,"url"),r=pe(e,"failed");if(r===void 0)throw l;let n=E(e,"initiatorType"),o=le(e,"durationMs"),i=le(e,"status"),s={...C(e,"resource"),type:"resource",url:t,failed:r};return n!==void 0&&(s.initiatorType=n),o!==void 0&&(s.durationMs=o),i!==void 0&&(s.status=i),s}function Zr(e){let t=Y(e,"durationMs"),r=E(e,"name"),n={...C(e,"longTask"),type:"longTask",durationMs:t};return r!==void 0&&(n.name=r),n}function en(e){let t=L(e,"name"),r=wt(e,"props"),n=pe(e,"truncated"),o={...C(e,"event"),type:"event",name:t};r!==void 0&&(o.props=r),n!==void 0&&(o.truncated=n);let i=e.source;if(i!==void 0){if(!Rt(i))throw l;o.source=i;}return o}function tn(e){let t=L(e,"name"),r=wt(e,"props"),n=E(e,"target"),o=pe(e,"truncated"),i={...C(e,"exposure"),type:"exposure",name:t};return r!==void 0&&(i.props=r),n!==void 0&&(i.target=n),o!==void 0&&(i.truncated=o),i}function rn(e,t){switch(e){case "vital":return Gr(t);case "error":return Yr(t);case "request":return Kr(t);case "route":return Jr(t);case "resource":return Wr(t);case "longTask":return Zr(t);case "event":return en(t);case "exposure":return tn(t);default:{let r=e;throw new Error(`\u672A\u77E5\u8BB0\u5F55\u7C7B\u578B\uFF1A${String(r)}`)}}}function Et(e){let t=0;for(let r=0;r<e.length;r+=1){let n=e.charCodeAt(r);n<128?t+=1:n<2048?t+=2:n>=55296&&n<=56319?(t+=4,r+=1):t+=3;}return t}function Pt(e){try{let t=JSON.stringify(e);return typeof t!="string"?Number.POSITIVE_INFINITY:Et(t)}catch{return Number.POSITIVE_INFINITY}}function Le(e){return Pt(e)}function nn(e){if(!P(e)||M(e))return null;let t=e.type;if(!ht(t)||Pt(e)>8192)return null;let r;try{r=rn(t,e);}catch{return null}return Le(r)>8192?null:r}function he(e){if(typeof e!="string")throw new TypeError("\u5BFC\u51FA\u6570\u636E\u5FC5\u987B\u662F\u5B57\u7B26\u4E32");if(Et(e)>10485760)throw new Error("\u5BFC\u51FA\u6587\u4EF6\u8D85\u8FC7 10485760 \u5B57\u8282\u4E0A\u9650");let t;try{t=JSON.parse(e);}catch{throw new Error("\u5BFC\u51FA\u6587\u4EF6\u4E0D\u662F\u5408\u6CD5\u7684 JSON")}if(!P(t)||M(t))throw new Error("\u5BFC\u51FA\u6587\u4EF6\u4FE1\u5C01\u683C\u5F0F\u65E0\u6548");if(t.formatVersion!==1)throw new Error(`\u4E0D\u652F\u6301\u7684\u5BFC\u51FA\u683C\u5F0F\u7248\u672C\uFF1A${String(t.formatVersion)}`);if(t.appId!==void 0&&typeof t.appId!="string")throw new Error("\u5BFC\u51FA\u6587\u4EF6 appId \u5B57\u6BB5\u65E0\u6548");if(t.exportedAt!==void 0&&typeof t.exportedAt!="string")throw new Error("\u5BFC\u51FA\u6587\u4EF6 exportedAt \u5B57\u6BB5\u65E0\u6548");let r=t.records;if(!Array.isArray(r))throw new TypeError("\u5BFC\u51FA\u6587\u4EF6\u7F3A\u5C11 records \u6570\u7EC4");if(r.length>1e5)throw new Error("\u5BFC\u51FA\u8BB0\u5F55\u6570\u8D85\u8FC7\u4E0A\u9650 100000");let n=r,o=[],i=0;for(let s of n){let a=nn(s);a?o.push(a):i+=1;}return {records:o,skipped:i}}function me(e){let t={formatVersion:1,exportedAt:new Date().toISOString(),records:[...e]},r=JSON.stringify(t);if(typeof r!="string")throw new TypeError("\u5BFC\u51FA\u6570\u636E\u5E8F\u5217\u5316\u5931\u8D25");return new Blob([r],{type:"application/json"})}var on=1,_="records",ge="timestamp",xt="type",sn=1440*60*1e3,an=2e4,cn=7,un=8*1024,dn=3e3;function ye(e,t){if(typeof e!="number"||!Number.isFinite(e))return t;let r=Math.trunc(e);return r>=1?r:t}function Tt(e,t){if(typeof e!="number"||!Number.isFinite(e))return t;let r=Math.trunc(e);return r>=0?r:t}var K=class{constructor(t){this.db=null;this.opening=null;this.disposed=false;let r=typeof t.namespace=="string"?t.namespace.trim():"";if(r.length===0)throw new TypeError("IndexedDbStorage \u9700\u8981\u975E\u7A7A namespace");this.dbName=`vitalens:${r}`,this.maxRecords=ye(t.maxRecords,an),this.retentionDays=Tt(t.retentionDays,cn),this.maxRecordBytes=ye(t.maxRecordBytes,un),this.openTimeoutMs=ye(t.openTimeoutMs,dn);}async init(){if(this.disposed)throw new Error("IndexedDbStorage \u5DF2\u9500\u6BC1");if(this.db)return;if(this.opening)return this.opening;if(typeof indexedDB=="undefined")throw new Error("\u5F53\u524D\u73AF\u5883\u4E0D\u652F\u6301 IndexedDB");let t=this.openDatabase();this.opening=t;try{await t;}finally{this.opening===t&&(this.opening=null);}}async put(t){let r=this.requireDb();t.length!==0&&await this.runWriteTransaction(r,"\u5199\u5165 IndexedDB \u8BB0\u5F55",n=>{for(let o of t)n.put(o);this.deleteOverflowRecords(n);});}async query(t){let r=this.requireDb(),n=await this.readAll(r);return U(n,t)}async clear(){let t=this.requireDb();await this.runWriteTransaction(t,"\u6E05\u7A7A IndexedDB \u8BB0\u5F55",r=>{r.clear();});}async exportAll(){let t=this.requireDb(),r=await this.readAll(t);try{return me(U(r,{order:"asc"}))}catch(n){throw m(n,"\u751F\u6210\u5BFC\u51FA\u6570\u636E\u5931\u8D25")}}async importAll(t){this.requireDb();let r;try{r=await t.text();}catch(i){throw m(i,"\u8BFB\u53D6\u5BFC\u5165\u6587\u4EF6\u5931\u8D25")}let{records:n}=he(r),o=n.filter(i=>Le(i)<=this.maxRecordBytes);return await this.put(o),o.length}async prune(t){let r=this.requireDb(),n=ye(t.maxRecords,this.maxRecords),o=Tt(t.retentionDays,this.retentionDays),i=Date.now()-o*sn;await this.runWriteTransaction(r,"\u6E05\u7406\u8FC7\u671F IndexedDB \u8BB0\u5F55",s=>{let a=s.index(ge).openCursor(IDBKeyRange.upperBound(i,true));a.onsuccess=()=>{let c=a.result;c&&(c.delete(),c.continue());};}),await this.runWriteTransaction(r,"\u6309\u4E0A\u9650\u6E05\u7406 IndexedDB \u8BB0\u5F55",s=>{this.deleteOverflowRecords(s,n);});}dispose(){this.disposed=true;let t=this.db;return this.db=null,t&&(t.onversionchange=null,t.close()),Promise.resolve()}openDatabase(){return new Promise((t,r)=>{let n=false,o=null,i=()=>n?false:(n=true,o!==null&&(clearTimeout(o),o=null),true),s;try{s=indexedDB.open(this.dbName,on);}catch(a){r(m(a,"\u6253\u5F00 IndexedDB \u5931\u8D25"));return}o=setTimeout(()=>{i()&&r(new Error(`\u6253\u5F00 IndexedDB \u8D85\u65F6\uFF08${this.openTimeoutMs}ms\uFF09`));},this.openTimeoutMs),s.onupgradeneeded=()=>{let a=s.result,c=s.transaction;if(!c)return;let d=a.objectStoreNames.contains(_)?c.objectStore(_):a.createObjectStore(_,{keyPath:"id"});d.indexNames.contains(ge)||d.createIndex(ge,"timestamp",{unique:false}),d.indexNames.contains(xt)||d.createIndex(xt,"type",{unique:false});},s.onblocked=()=>{i()&&r(new Error("\u6253\u5F00 IndexedDB \u88AB\u963B\u585E\uFF1A\u5B58\u5728\u672A\u5173\u95ED\u7684\u65E7\u7248\u672C\u8FDE\u63A5"));},s.onerror=()=>{i()&&r(m(s.error,"\u6253\u5F00 IndexedDB \u5931\u8D25"));},s.onsuccess=()=>{let a=s.result;if(this.disposed){a.close(),i()&&r(new Error("IndexedDbStorage \u5DF2\u9500\u6BC1"));return}if(!i()){a.close();return}this.db=a,a.onversionchange=()=>{a.close(),this.db===a&&(this.db=null);},t();};})}requireDb(){if(this.disposed)throw new Error("IndexedDbStorage \u5DF2\u9500\u6BC1");if(!this.db)throw new Error("IndexedDbStorage \u5C1A\u672A\u521D\u59CB\u5316");return this.db}transactionDone(t,r){return new Promise((n,o)=>{t.oncomplete=()=>n(),t.onerror=()=>o(m(t.error,`${r}\u5931\u8D25`)),t.onabort=()=>o(m(t.error,`${r}\u88AB\u4E2D\u6B62`));})}requestToPromise(t){return new Promise((r,n)=>{t.onsuccess=()=>r(t.result),t.onerror=()=>n(m(t.error,"IndexedDB \u8BF7\u6C42\u5931\u8D25"));})}runWriteTransaction(t,r,n){let o;try{o=t.transaction(_,"readwrite");}catch(s){return Promise.reject(m(s,`\u521B\u5EFA${r}\u4E8B\u52A1\u5931\u8D25`))}let i=this.transactionDone(o,r);try{n(o.objectStore(_));}catch(s){i.catch(()=>{});try{o.abort();}catch{}return Promise.reject(m(s,r))}return i}async readAll(t){let r;try{r=t.transaction(_,"readonly");}catch(o){throw m(o,"\u521B\u5EFA IndexedDB \u8BFB\u4E8B\u52A1\u5931\u8D25")}let n=this.transactionDone(r,"\u8BFB\u53D6 IndexedDB \u8BB0\u5F55");try{let o=r.objectStore(_).getAll(),[i]=await Promise.all([this.requestToPromise(o),n]);return i.filter(s=>vt(s))}catch(o){throw m(o,"\u8BFB\u53D6 IndexedDB \u8BB0\u5F55\u5931\u8D25")}}deleteOverflowRecords(t,r=this.maxRecords){let n=t.count();n.onsuccess=()=>{let o=n.result-r;if(o<=0)return;let i=t.index(ge).openCursor();i.onsuccess=()=>{let s=i.result;!s||o<=0||(s.delete(),o-=1,o>0&&s.continue());};};}};var fn=5e3,ln=1440*60*1e3;function kt(e,t){if(typeof e!="number"||!Number.isFinite(e))return t;let r=Math.trunc(e);return r>=1?r:t}function pn(e){return typeof e!="number"||!Number.isFinite(e)?0:Math.max(0,Math.trunc(e))}var j=class{constructor(t={}){this.records=new Map;this.disposed=false;this.maxRecords=kt(t.maxRecords,fn);}async init(){this.assertActive();}async put(t){this.assertActive();for(let r of t)this.records.delete(r.id),this.records.set(r.id,r);this.evictOverflow();}async query(t){return this.assertActive(),U(Array.from(this.records.values()),t)}async clear(){this.assertActive(),this.records.clear();}async exportAll(){this.assertActive();let t=U(Array.from(this.records.values()),{order:"asc"});try{return me(t)}catch(r){throw m(r,"\u751F\u6210\u5BFC\u51FA\u6570\u636E\u5931\u8D25")}}async importAll(t){this.assertActive();let r;try{r=await t.text();}catch(o){throw m(o,"\u8BFB\u53D6\u5BFC\u5165\u6587\u4EF6\u5931\u8D25")}let{records:n}=he(r);return await this.put(n),n.length}async prune(t){this.assertActive();let r=kt(t.maxRecords,this.maxRecords),n=pn(t.retentionDays),o=Date.now()-n*ln,i=[];for(let s of this.records.values())s.timestamp<o?this.records.delete(s.id):i.push(s);if(i.length>r){i.sort((a,c)=>a.timestamp-c.timestamp);let s=i.length-r;for(let a of i.slice(0,s))this.records.delete(a.id);}}async dispose(){this.records.clear(),this.disposed=true;}evictOverflow(){for(;this.records.size>this.maxRecords;){let t=this.records.keys().next();if(t.done)return;this.records.delete(t.value);}}assertActive(){if(this.disposed)throw new Error("MemoryStorage \u5DF2\u9500\u6BC1")}};var hn=/^[a-z]\w{0,63}$/i;function St(e){return hn.test(e)}function It(e,t){if(!e)return {truncated:false};let r=Math.min(4096,t.limits.maxRecordBytes),n=ke(e),o=ae(e,t.privacy);return o?n>r||ke(o)>r?{props:{truncated:true},truncated:true}:{props:o,truncated:false}:{truncated:true}}var mn=6e4,gn=6e4;function Re(e){return e instanceof Error?e.message:String(e)}async function yn(e){try{if(typeof crypto=="undefined"||!crypto.subtle)return;let t=new TextEncoder().encode(e),r=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(r)).map(n=>n.toString(16).padStart(2,"0")).join("")}catch{return}}var _e=class{constructor(t){this.config=t,this.enabled=t.enabled;}track(t,r,n){}trackPageView(t){}recordRoute(t){}recordError(t){}setUser(t){}setContext(t){}subscribe(t){return ()=>{}}async flush(t){}async query(t){return []}async exportAll(){return new Blob([JSON.stringify({formatVersion:1,records:[]})],{type:"application/json"})}async importAll(t){return 0}async clear(){}getDiagnostics(){return {enabled:this.enabled,degradeLevel:0,queueSize:0,dropped:0,selfErrors:0,sampling:{...this.config.sampling},storage:{available:false,circuitOpen:false},collectors:{}}}disable(){this.enabled=false;}async destroy(){this.enabled=false;}},Oe=class{constructor(t){this.destroyed=false;this.flushing=false;this.flushFailures=0;this.flushChain=Promise.resolve();this.storageAvailable=false;this.lastPruneAt=0;this.stopHandlers=[];this.emitBuffer=[];this.emitScheduled=false;this.localDropped=0;this.selfErrors=0;this.trackTimestamps=[];this.errorTimestamps=[];this.errorFingerprints=new Map;this.onVisibilityChange=()=>{typeof document!="undefined"&&document.visibilityState==="hidden"&&this.flush("hidden");};this.onPageHide=()=>{this.flush("pagehide");};this.config=t,this.enabled=t.enabled,this.context=at(t),this.queue=new ce(t.limits.maxQueueSize),this.scheduler=new ue(n=>this.reportSelfError(n)),this.bus=new ie(n=>this.reportSelfError(n));let r={maxRecords:t.limits.maxRecords,retentionDays:t.limits.retentionDays,maxRecordBytes:t.limits.maxRecordBytes};this.storage=t.transport.reporter==="indexeddb"?new K({namespace:t.storageNamespace,...r}):new j({maxRecords:t.limits.maxRecords}),this.reporter=ft(t,()=>this.storage),this.storageReady=this.initStorage(),this.startCollectors(),this.installLifecycle();}track(t,r,n){var i;if(!this.enabled||this.destroyed)return;if(!St(t)){this.localDropped+=1,this.config.debug&&console.warn(`[vitalens] invalid event name: ${String(t)}`);return}if(!this.allowTrack()){this.localDropped+=1;return}let o=It(r,this.config);this.addEventRecord(t,o.props,"manual",o.truncated,(i=n==null?void 0:n.sampling)!=null?i:this.config.sampling.event),n!=null&&n.immediate&&this.flush("manual");}trackPageView(t){var o,i;if(!this.enabled||this.destroyed)return;let r=V(t!=null?t:this.context.route,this.config.privacy);if(!r)return;let n=this.context.route?V(this.context.route,this.config.privacy):void 0;this.context.route=r,this.addEventRecord("page_view",{from:(o=n==null?void 0:n.path)!=null?o:"",to:r.path,title:(i=r.name)!=null?i:""},"pageView",false,this.config.sampling.event);}recordRoute(t){var o,i;if(!this.enabled||this.destroyed)return;if(!x(this.config.sampling.route)){this.localDropped+=1;return}let r=V(t.to,this.config.privacy);if(!r)return;let n={...T(this.config,this.context,"route",k("route")),to:r,from:t.from?V(t.from,this.config.privacy):void 0,durationMs:Math.max(0,(o=t.durationMs)!=null?o:0),navigation:(i=t.navigation)!=null?i:"spa"};this.enqueueRecord(n);}recordError(t){!this.enabled||this.destroyed||this.addError(t);}setUser(t){if(this.config.privacy.user!=="none"){if(!t){this.context={...this.context,user:void 0};return}if(t.hash){this.context={...this.context,user:{hash:t.hash}};return}t.id&&yn(t.id).then(r=>{r&&(this.context={...this.context,user:{hash:r}});}).catch(r=>this.reportSelfError(r));}}setContext(t){var r;if(!this.destroyed&&(t.route&&(this.context={...this.context,route:V(t.route,this.config.privacy)}),t.user!==void 0&&this.setUser((r=t.user)!=null?r:null),t.device)){let n=ae(t.device,this.config.privacy);n&&(this.context={...this.context,device:n});}}subscribe(t){return this.bus.subscribe(t)}flush(t="manual"){return this.destroyed&&t!=="destroy"||!this.enabled&&t!=="destroy"?Promise.resolve():(this.flushChain=this.flushChain.then(()=>this.runFlush(t),()=>this.runFlush(t)),this.flushChain)}async query(t){return await this.storageReady,this.storage.query(t)}async exportAll(){return await this.storageReady,this.storage.exportAll()}async importAll(t){return await this.storageReady,this.storage.importAll(t)}async clear(){await this.storageReady,await this.storage.clear();}getDiagnostics(){return {enabled:this.enabled,degradeLevel:0,queueSize:this.queue.size,dropped:this.queue.dropped+this.localDropped,selfErrors:this.selfErrors,sampling:{...this.config.sampling},storage:{available:this.storageAvailable,lastError:this.storageLastError,circuitOpen:this.flushFailures>=3},collectors:{}}}disable(){this.enabled&&(this.flush("manual"),this.enabled=false,this.stopCollectors(),this.flushTimer&&(this.flushTimer(),this.flushTimer=void 0));}async destroy(){if(this.destroyed)return;this.enabled=false,this.stopCollectors(),this.removeLifecycle(),this.flushTimer&&(this.flushTimer(),this.flushTimer=void 0),await this.flush("destroy").catch(()=>{}),this.destroyed=true,this.scheduler.dispose(),this.bus.dispose(),await this.storage.dispose().catch(r=>this.reportSelfError(r));let t=globalThis;t.__VITALENS_PERF__===this&&delete t.__VITALENS_PERF__;}async initStorage(){try{await this.storage.init(),this.storageAvailable=this.config.transport.reporter==="indexeddb";}catch(t){this.reportSelfError(t),this.storageLastError=Re(t),this.storage=new j({maxRecords:this.config.limits.maxRecords}),this.storageAvailable=false,await this.storage.init();}}startCollectors(){let t=r=>{p(()=>{let n=r();n&&this.stopHandlers.push(n);},{onError:n=>this.reportSelfError(n)});};this.config.capture.vitals&&t(()=>it(r=>this.addVital(r),{reportAllChanges:true})),this.config.capture.errors&&t(()=>Je(r=>this.addError(r),{unhandledRejection:true,resourceErrors:this.config.capture.resources,isInternal:()=>this.destroyed})),this.config.capture.requests&&t(()=>ot(r=>this.addRequest(r))),this.config.capture.longTask&&t(()=>et(r=>this.addLongTask(r),{threshold:50})),this.config.capture.resources&&t(()=>tt(r=>this.addResource(r),{slowThreshold:2e3})),this.config.capture.click&&t(()=>je((r,n)=>this.track(r,n)));}stopCollectors(){for(;this.stopHandlers.length>0;){let t=this.stopHandlers.pop();t&&p(t,{onError:r=>this.reportSelfError(r)});}}installLifecycle(){p(()=>{typeof document!="undefined"&&document.addEventListener("visibilitychange",this.onVisibilityChange),typeof window!="undefined"&&window.addEventListener("pagehide",this.onPageHide);},{onError:t=>this.reportSelfError(t)});}removeLifecycle(){p(()=>{typeof document!="undefined"&&document.removeEventListener("visibilitychange",this.onVisibilityChange),typeof window!="undefined"&&window.removeEventListener("pagehide",this.onPageHide);},{onError:t=>this.reportSelfError(t)});}addVital(t){if(!x(this.config.sampling.vital)){this.localDropped+=1;return}let r={...T(this.config,this.context,"vital",k("vital")),name:t.name,value:t.value,rating:t.rating,metricId:t.id};this.enqueueRecord(r);}addError(t){if(!this.allowError()){this.localDropped+=1;return}if(!x(this.config.sampling.error)){this.localDropped+=1;return}let r=Se(t.message,this.config.privacy.maxMessageLength),n=t.stack?Se(t.stack,this.config.privacy.maxStackLength):void 0,o=t.name?g(t.name,128):void 0,i=`${t.source}:${o!=null?o:""}:${r.slice(0,120)}`,s=D(),a=this.errorFingerprints.get(i);if(a!==void 0&&s-a<mn){this.localDropped+=1;return}if(this.errorFingerprints.set(i,s),this.errorFingerprints.size>this.config.limits.dedupeSize){let d=this.errorFingerprints.keys().next().value;typeof d=="string"&&this.errorFingerprints.delete(d);}let c={...T(this.config,this.context,"error",k("error")),name:o,message:r,stack:n,source:t.source,fingerprint:i,component:t.component?g(t.component,256):void 0};this.enqueueRecord(c);}addRequest(t){if(!x(this.config.sampling.request)){this.localDropped+=1;return}let r=G(t.url,this.config.privacy);if(!r)return;let n={...T(this.config,this.context,"request",k("request")),kind:t.kind,method:g(t.method.toUpperCase(),16),url:r,status:t.status,durationMs:Math.max(0,t.durationMs),success:t.success};this.enqueueRecord(n);}addResource(t){if(!x(this.config.sampling.resource)){this.localDropped+=1;return}let r=G(t.url,this.config.privacy);if(!r)return;let n={...T(this.config,this.context,"resource",k("resource")),url:r,initiatorType:t.initiatorType?g(t.initiatorType,32):void 0,durationMs:t.durationMs,failed:t.failed};this.enqueueRecord(n);}addLongTask(t){if(!x(this.config.sampling.longTask)){this.localDropped+=1;return}let r={...T(this.config,this.context,"longTask",k("longTask")),durationMs:Math.max(0,t.durationMs),name:t.name?g(t.name,64):void 0};this.enqueueRecord(r);}addEventRecord(t,r,n,o,i){if(!x(i)){this.localDropped+=1;return}let s={...T(this.config,this.context,"event",k("event")),name:g(t,64),props:r,source:n,truncated:o};this.enqueueRecord(s);}enqueueRecord(t){if(!this.enabled||this.destroyed)return;let r=dt(t);if(r>this.config.limits.maxRecordBytes){this.localDropped+=1,this.config.debug&&console.warn(`[vitalens] record dropped, size ${r} > maxRecordBytes`);return}this.queue.enqueue(t,r)&&(this.bus.size>0&&(this.emitBuffer.push(t),this.scheduleEmit()),this.ensureFlushScheduled(this.config.limits.flushIntervalMs));}scheduleEmit(){this.emitScheduled||this.emitBuffer.length===0||this.bus.size===0||(this.emitScheduled=true,this.scheduler.schedule(()=>{this.emitScheduled=false;let t=this.emitBuffer.splice(0);this.bus.emit(t),this.emitBuffer.length>0&&this.scheduleEmit();}));}ensureFlushScheduled(t){this.destroyed||this.flushTimer||(this.flushTimer=this.scheduler.schedule(()=>{this.flushTimer=void 0,this.flush("interval").then(()=>{this.queue.size>0&&!this.destroyed&&this.ensureFlushScheduled(0);});},{delayMs:t}));}async runFlush(t){if(await this.storageReady,!this.flushing&&!(!this.enabled&&t!=="destroy")){this.flushing=true;try{let r=this.queue.takeBatch(this.config.limits.maxBatchSize,this.config.limits.maxBatchBytes);if(r.length===0)return;let n=r.map(i=>i.record),o=w();try{await this.reporter.report(n),this.flushFailures=0,this.storageLastError=void 0,this.maybePrune();}catch(i){this.flushFailures+=1,this.storageLastError=Re(i),this.reportSelfError(i),this.queue.requeue(r),this.maybeFallbackStorage(),this.ensureFlushScheduled(Math.min(3e4,1e3*2**Math.min(this.flushFailures,5)));}finally{let i=w()-o;i>this.config.limits.flushDeadlineMs&&this.config.debug&&console.warn(`[vitalens] flush exceeded deadline: ${i.toFixed(1)}ms`);}}finally{this.flushing=false,this.queue.size>0&&!this.destroyed&&this.ensureFlushScheduled(0);}}}maybeFallbackStorage(){this.flushFailures<3||this.storage instanceof K&&(this.reportSelfError(new Error("IndexedDB unavailable, falling back to memory storage")),this.storage=new j({maxRecords:this.config.limits.maxRecords}),this.storageAvailable=false,this.storage.init().catch(t=>this.reportSelfError(t)));}maybePrune(){let t=D();if(t-this.lastPruneAt<gn)return;this.lastPruneAt=t;let r=this.storage;r.prune&&this.scheduler.schedule(()=>{var n;(n=r.prune)==null||n.call(r,{maxRecords:this.config.limits.maxRecords,retentionDays:this.config.limits.retentionDays}).catch(o=>this.reportSelfError(o));});}allowTrack(){var n;let t=D(),r=t-6e4;for(;this.trackTimestamps.length>0&&((n=this.trackTimestamps[0])!=null?n:t)<r;)this.trackTimestamps.shift();return this.trackTimestamps.length>=this.config.limits.maxTracksPerMinute?false:(this.trackTimestamps.push(t),true)}allowError(){var n;let t=D(),r=t-6e4;for(;this.errorTimestamps.length>0&&((n=this.errorTimestamps[0])!=null?n:t)<r;)this.errorTimestamps.shift();return this.errorTimestamps.length>=this.config.limits.maxErrorsPerMinute?false:(this.errorTimestamps.push(t),true)}reportSelfError(t){if(this.selfErrors+=1,this.config.debug)try{console.warn("[vitalens] internal error:",Re(t));}catch{}}};function Ne(e=W({appId:"vitalens-noop",enabled:false})){return new _e(e)}function Mt(e){let t=W(e),r=typeof window!="undefined";if(!t.enabled||!r)return Ne({...t,enabled:false});let n=globalThis,o=n.__VITALENS_PERF__;if(o)return console.warn("[vitalens] createPerf called more than once; reusing the existing instance."),o;try{let i=new Oe(t);return n.__VITALENS_PERF__=i,i}catch(i){return console.warn("[vitalens] createPerf failed, falling back to noop:",Re(i)),Ne({...t,enabled:false})}}function Rn(){return globalThis.__VITALENS_PERF__}function bn(e){return Mt(e)}
2
- export{ze as DEFAULT_CAPTURE,y as DEFAULT_LIMITS,O as DEFAULT_PRIVACY,be as DEFAULT_SAMPLING,ve as DEFAULT_TRANSPORT,Ne as createNoopPerf,Mt as createPerf,Rn as getPerf,bn as initPerf,W as resolveConfig};//# sourceMappingURL=index.js.map
1
+ import {onCLS,onFCP,onINP,onLCP,onTTFB}from'web-vitals';var _t=["vitals","errors","requests","routes","resources","longTask","click","exposure"],Ot=["vital","error","request","route","resource","longTask","event","exposure"],ze={vitals:true,errors:true,requests:true,routes:true,resources:true,longTask:true,click:false,exposure:false},be={vital:1,error:1,request:.1,route:1,resource:.1,longTask:.5,event:1,exposure:.1},D={stripQuery:true,captureQuery:"none",queryWhitelist:[],redactKeys:["token","password","secret","authorization"],maxUrlLength:2048,maxStackLength:4096,maxMessageLength:1024,maxStringLength:2e3,user:"none"},g={maxQueueSize:1e3,maxRecordBytes:8192,maxBatchSize:50,maxBatchBytes:262144,flushIntervalMs:5e3,flushDeadlineMs:8,retentionDays:7,maxRecords:2e4,dedupeSize:200,maxErrorsPerMinute:120,maxTracksPerMinute:600},ve={reporter:"indexeddb"};function J(e,t){return typeof e=="string"&&e.trim().length>0?e.trim():t}function h(e,t,r,n){if(typeof e!="number"||!Number.isFinite(e))return t;let o=Math.trunc(e);return o<r||o>n?t:o}function Nt(e,t){return typeof e!="number"||!Number.isFinite(e)?t:Math.min(1,Math.max(0,e))}function Bt(e){let t={...ze};if(!e)return t;for(let r of _t){let n=e[r];typeof n=="boolean"&&(t[r]=n);}return t}function qt(e){let t={...be};if(!e)return t;for(let r of Ot)t[r]=Nt(e[r],be[r]);return t}function Ft(e){return e==="all"||e==="whitelist"?e:"none"}function zt(e){var n,o;let t=((n=e==null?void 0:e.redactKeys)!=null?n:D.redactKeys).filter(i=>typeof i=="string"&&i.length>0&&i.length<=64).slice(0,100),r=((o=e==null?void 0:e.queryWhitelist)!=null?o:D.queryWhitelist).filter(i=>typeof i=="string"&&i.length>0&&i.length<=64).slice(0,50);return {stripQuery:(e==null?void 0:e.stripQuery)!==false,captureQuery:Ft(e==null?void 0:e.captureQuery),queryWhitelist:r,redactKeys:t,maxUrlLength:h(e==null?void 0:e.maxUrlLength,D.maxUrlLength,16,65536),maxStackLength:h(e==null?void 0:e.maxStackLength,D.maxStackLength,64,65536),maxMessageLength:h(e==null?void 0:e.maxMessageLength,D.maxMessageLength,16,65536),maxStringLength:h(e==null?void 0:e.maxStringLength,D.maxStringLength,16,65536),user:(e==null?void 0:e.user)==="hash"?"hash":"none"}}function Vt(e){return {maxQueueSize:h(e==null?void 0:e.maxQueueSize,g.maxQueueSize,1,1e5),maxRecordBytes:h(e==null?void 0:e.maxRecordBytes,g.maxRecordBytes,256,1048576),maxBatchSize:h(e==null?void 0:e.maxBatchSize,g.maxBatchSize,1,1e3),maxBatchBytes:h(e==null?void 0:e.maxBatchBytes,g.maxBatchBytes,1024,10485760),flushIntervalMs:h(e==null?void 0:e.flushIntervalMs,g.flushIntervalMs,100,6e5),flushDeadlineMs:h(e==null?void 0:e.flushDeadlineMs,g.flushDeadlineMs,1,100),retentionDays:h(e==null?void 0:e.retentionDays,g.retentionDays,1,365),maxRecords:h(e==null?void 0:e.maxRecords,g.maxRecords,100,1e6),dedupeSize:h(e==null?void 0:e.dedupeSize,g.dedupeSize,10,1e4),maxErrorsPerMinute:h(e==null?void 0:e.maxErrorsPerMinute,g.maxErrorsPerMinute,1,1e4),maxTracksPerMinute:h(e==null?void 0:e.maxTracksPerMinute,g.maxTracksPerMinute,1,1e5)}}function Ut(e){if(!e)return ve;switch(e.reporter){case "indexeddb":case "console":case "none":return e;case "http":case "beacon":return typeof e.endpoint=="string"&&e.endpoint.trim().length>0?{reporter:e.reporter,endpoint:e.endpoint.trim()}:{reporter:"none"};default:return ve}}function Z(e){let t=J(e.appId,"unknown-app");return {...e,appId:t,env:J(e.env,"prod"),buildId:J(e.buildId,"unknown"),storageNamespace:J(e.storageNamespace,t),enabled:e.enabled!==false,capture:Bt(e.capture),sampling:qt(e.sampling),privacy:zt(e.privacy),limits:Vt(e.limits),transport:Ut(e.transport),debug:e.debug===true}}function Xt(e,t){var r;try{(r=t.onError)==null||r.call(t,e);}catch{}}function p(e,t={}){try{return e()}catch(r){Xt(r,t);return}}var Ue="data-perf-track",jt="data-perf-props",Qt="data-perf-ignore",Xe=64,Ht=8192;function Ve(){}function $t(e){if(!e)return null;let t=e;return t.nodeType!==1||typeof t.getAttribute!="function"||typeof t.hasAttribute!="function"?null:e}function Gt(e){var n;try{if(typeof e.composedPath=="function"){let o=e.composedPath();if(Array.isArray(o)&&o.length>0)return o}}catch{}let t=[],r=e.target;for(let o=0;r!==null&&o<Xe;o+=1){t.push(r);try{r=(n=r.parentNode)!=null?n:null;}catch{r=null;}}return t}function Yt(e){let t=Gt(e),r=Math.min(t.length,Xe);for(let n=0;n<r;n+=1){let o=$t(t[n]);if(o){if(o.hasAttribute(Qt))return null;if(o.hasAttribute(Ue))return o}}return null}function Kt(e){try{let t=e.getAttribute(Ue);if(typeof t!="string")return;let r=t.trim();return r.length>0?r:void 0}catch{return}}function Wt(e){try{let t=e.getAttribute(jt);if(typeof t!="string"||t.length===0||t.length>Ht)return;let r=JSON.parse(t);if(typeof r=="object"&&r!==null&&!Array.isArray(r))return r}catch{}}function je(e){if(typeof document=="undefined")return Ve;let t=false,r=n=>{if(!t)try{if(n.isTrusted!==!0)return;let o=Yt(n);if(!o)return;let i=Kt(o);if(i===void 0)return;let s=Wt(o);p(()=>e(i,s));}catch{}};try{document.addEventListener("click",r,!0);}catch{return Ve}return ()=>{if(!t){t=true;try{document.removeEventListener("click",r,!0);}catch{}}}}var N=1024,Qe=4096,He=200,$e=2048,Jt="vitalens";function Ge(){}function R(e,t){if(typeof e=="string")return e.length>t?e.slice(0,t):e}function we(e,t){if(!(typeof e!="object"||e===null))try{return e[t]}catch{return}}function Zt(e){if(e===void 0)return "Unknown rejection";if(typeof e=="string")return e;if(e instanceof Error)return e.message||e.name||"Unknown error";try{let t=JSON.stringify(e);if(typeof t=="string"&&t.length>0)return t}catch{}try{return String(e)}catch{return "Unknown error"}}function Ye(e){var t;try{return (t=R(Zt(e),N))!=null?t:"Unknown error"}catch{return "Unknown error"}}function Ke(e){var t,r,n;try{if(e instanceof Error)return {name:R(e.name,He),message:(t=R(e.message,N))!=null?t:"Unknown error",stack:R(e.stack,Qe)};if(typeof e=="string")return {message:(r=R(e,N))!=null?r:"Unknown error"};if(typeof e=="object"&&e!==null){let o=R(we(e,"name"),He),i=R(we(e,"message"),N),s=R(we(e,"stack"),Qe);if(o!==void 0||i!==void 0||s!==void 0)return {name:o,message:(n=i!=null?i:o)!=null?n:Ye(e),stack:s}}return {message:Ye(e)}}catch{return {message:"Unknown error"}}}function Ee(e,t){if(t!==void 0)try{if(t()===!0)return !0}catch{}return typeof e=="string"&&e.toLowerCase().includes(Jt)}function er(e){return typeof e.message=="string"}function tr(e){try{return e.reason}catch{return}}function rr(e){if(!e)return null;let t=e;return t.nodeType!==1||typeof t.getAttribute!="function"?null:e}function nr(e){var t;try{let r=e,n=[r.currentSrc,r.src,r.href];for(let i of n)if(typeof i=="string"&&i.length>0)return R(i,$e);let o=(t=e.getAttribute("src"))!=null?t:e.getAttribute("href");return o?R(o,$e):void 0}catch{return}}function We(e,t={}){if(typeof window=="undefined")return Ge;let r=t.unhandledRejection!==false,n=t.resourceErrors!==false,o=t.isInternal,i=false,s=false,a=f=>{p(()=>e(f));},c=f=>{var u,b;if(!(i||s)){s=true;try{if(er(f)){let Fe=f.error==null?{message:(u=R(f.message,N))!=null?u:"Unknown error"}:Ke(f.error);if(Ee(Fe.stack,o))return;a({...Fe,source:"window"});return}if(!n)return;let A=rr(f.target);if(!A||Ee(void 0,o))return;let Be=nr(A),qe=typeof A.tagName=="string"?A.tagName:"resource",Lt=Be===void 0?"":`: ${Be}`;a({name:qe,message:(b=R(`Failed to load ${qe.toLowerCase()}${Lt}`,N))!=null?b:"Failed to load resource",source:"resource"});}catch{}finally{s=false;}}},d=f=>{if(!(i||s)){s=true;try{let u=Ke(tr(f));if(Ee(u.stack,o))return;a({...u,source:"unhandledrejection"});}catch{}finally{s=false;}}};try{window.addEventListener("error",c,!0);}catch{return Ge}if(r)try{window.addEventListener("unhandledrejection",d);}catch{}return ()=>{if(!i){i=true;try{window.removeEventListener("error",c,!0);}catch{}if(r)try{window.removeEventListener("unhandledrejection",d);}catch{}}}}var or=50;function B(){}function Je(){return typeof PerformanceObserver!="undefined"&&typeof PerformanceObserver=="function"}function Ze(e){try{let t=PerformanceObserver.supportedEntryTypes;return t===void 0||t.includes(e)}catch{return false}}function ir(e,t){return typeof e=="number"&&Number.isFinite(e)&&e>=0?e:t}function sr(e){return typeof e=="number"&&Number.isFinite(e)&&e>=0?e:void 0}function ee(e){try{e.disconnect();}catch{}}function et(e,t={}){if(!Je()||!Ze("longtask"))return B;let r=ir(t.threshold,or),n=false,o;try{o=new PerformanceObserver(i=>{if(n)return;let s;try{s=i.getEntries();}catch{return}for(let a of s)try{let c=a.duration;if(!Number.isFinite(c)||c<r)continue;let d={durationMs:c,startTime:a.startTime};typeof a.name=="string"&&a.name.length>0&&(d.name=a.name),p(()=>e(d));}catch{}});}catch{return B}try{o.observe({entryTypes:["longtask"]});}catch{return ee(o),B}return ()=>{n||(n=true,o!==void 0&&(ee(o),o=void 0));}}function ar(e){return e.entryType==="resource"}function cr(e){try{let t=e,r=t.responseStatus;if(typeof r=="number"&&r>0)return r>=400;let n=t.transferSize,o=t.decodedBodySize;return typeof n=="number"&&typeof o=="number"?n===0&&o===0&&e.duration===0:!1}catch{return false}}function ur(e,t,r){if(!ar(e))return;let n=typeof e.name=="string"?e.name:"";if(n.length===0)return;let o=Number.isFinite(e.duration)?e.duration:void 0,i=cr(e),s=t!==void 0&&o!==void 0&&o>=t;if(!i&&!s)return;let a={url:n,failed:i},c=e.initiatorType;typeof c=="string"&&c.length>0&&(a.initiatorType=c),o!==void 0&&(a.durationMs=o),p(()=>r(a));}function tt(e,t={}){if(!Je()||!Ze("resource"))return B;let r=sr(t.slowThreshold),n=false,o;try{o=new PerformanceObserver(i=>{if(n)return;let s;try{s=i.getEntries();}catch{return}for(let a of s)try{ur(a,r,e);}catch{}});}catch{return B}try{o.observe({entryTypes:["resource"]});}catch{return ee(o),B}return ()=>{n||(n=true,o!==void 0&&(ee(o),o=void 0));}}function L(){return Date.now()}function w(){return typeof performance!="undefined"&&typeof performance.now=="function"?performance.now():Date.now()}var Q=new Set,re,q,ne,oe,F,z,H=new WeakMap;function rt(e){for(let t of [...Q])Q.has(t)&&p(()=>t(e));}function dr(e,t){if(typeof(t==null?void 0:t.method)=="string"&&t.method.length>0)return t.method;if(typeof e=="object"&&e!==null){let r=e.method;if(typeof r=="string"&&r.length>0)return r}return "GET"}function fr(e){if(typeof e=="string")return e;if(typeof e=="object"&&e!==null){let t=e;if(typeof t.url=="string")return t.url;if(typeof t.href=="string")return t.href}try{return String(e)}catch{return ""}}function lr(e){try{let t=typeof e.status=="number"?e.status:void 0;return typeof e.ok=="boolean"?{status:t,success:e.ok}:t!==void 0?{status:t,success:t>=200&&t<300}:{success:!0}}catch{return {success:true}}}function pr(e,t){try{return {method:dr(e,t),url:fr(e),start:w()}}catch{return}}function te(e,t){if(e)try{let r={kind:"fetch",method:e.method,url:e.url,durationMs:Math.max(0,w()-e.start),success:t.success};t.status!==void 0&&(r.status=t.status),rt(r);}catch{}}function hr(e){return function(r,n){let o=pr(r,n),i;try{i=e.call(this,r,n);}catch(s){throw te(o,{success:false}),s}try{return i.then(s=>(te(o,lr(s)),s),s=>{throw te(o,{success:!1}),s})}catch{return te(o,{success:true}),i}}}function mr(){if(typeof globalThis.fetch!="function")return;let e=globalThis.fetch;if(q!==void 0&&e===q)return;let t=hr(e);try{globalThis.fetch=t;}catch{return}re=e,q=t;}function yr(){try{q!==void 0&&re!==void 0&&globalThis.fetch===q&&(globalThis.fetch=re);}catch{}re=void 0,q=void 0;}function gr(e){return typeof e=="string"&&e.length>0?e:"GET"}function Rr(e){if(typeof e=="string")return e;if(typeof e=="object"&&e!==null){let t=e.href;if(typeof t=="string")return t}try{return String(e)}catch{return ""}}function br(e){try{return typeof e.status=="number"?e.status:void 0}catch{return}}function vr(e){try{let t=H.get(e);if(!t)return;H.delete(e);let r=br(e),n={kind:"xhr",method:t.method,url:t.url,durationMs:Math.max(0,w()-t.start),success:r!==void 0&&r>=200&&r<300};r!==void 0&&(n.status=r),rt(n);}catch{}}function wr(e){return ()=>vr(e)}function nt(){if(typeof XMLHttpRequest!="undefined")try{return XMLHttpRequest.prototype}catch{return}}function Er(){let e=nt();if(!e||F!==void 0&&z!==void 0&&e.open===F&&e.send===z)return;let t=e.open,r=e.send;if(typeof t!="function"||typeof r!="function")return;let n=function(s,a,c,d,f){try{H.set(this,{method:gr(s),url:Rr(a),start:w()});}catch{}try{t.call(this,s,a,c,d,f);}catch(u){throw H.delete(this),u}},o=function(s){let a;try{let c=H.get(this);c&&(c.start=w(),a=wr(this),this.addEventListener("loadend",a,{once:!0}));}catch{a=void 0;}try{r.call(this,s);}catch(c){if(a!==void 0)try{this.removeEventListener("loadend",a);}catch{}throw c}};try{e.open=n;}catch{return}try{e.send=o;}catch{try{e.open=t;}catch{}return}ne=t,oe=r,F=n,z=o;}function Pr(){let e=nt();if(e){if(F!==void 0&&ne!==void 0&&e.open===F)try{e.open=ne;}catch{}if(z!==void 0&&oe!==void 0&&e.send===z)try{e.send=oe;}catch{}}ne=void 0,oe=void 0,F=void 0,z=void 0;}function ot(e,t={}){let r=typeof t.slowThreshold=="number"&&Number.isFinite(t.slowThreshold)&&t.slowThreshold>=0?t.slowThreshold:void 0,n=i=>{r!==void 0&&i.success&&i.durationMs<r||e(i);};Q.add(n),mr(),Er();let o=false;return ()=>{o||(o=true,Q.delete(n),Q.size===0&&(yr(),Pr()));}}function Cr(){}function it(e,t={}){if(typeof window=="undefined")return Cr;let r=t.reportAllChanges===true,n=false,o=s=>{n||p(()=>e({name:s.name,value:s.value,rating:s.rating,id:s.id}));},i=[()=>onCLS(o,{reportAllChanges:r}),()=>onFCP(o,{reportAllChanges:r}),()=>onINP(o,{reportAllChanges:r}),()=>onLCP(o,{reportAllChanges:r}),()=>onTTFB(o,{reportAllChanges:r})];for(let s of i)try{s();}catch{}return ()=>{n=true;}}var Pe=0;function Mr(e){let t=new Uint8Array(Math.ceil(e/2));try{if(typeof crypto!="undefined"&&typeof crypto.getRandomValues=="function")crypto.getRandomValues(t);else for(let n=0;n<t.length;n+=1)t[n]=Math.floor(Math.random()*256);}catch{for(let n=0;n<t.length;n+=1)t[n]=Math.floor(Math.random()*256);}let r="";for(let n of t)r+=n.toString(16).padStart(2,"0");return r.slice(0,e)}function $(){return Pe=(Pe+1)%65536,`${Date.now().toString(36)}-${Pe.toString(36)}-${Mr(10)}`}var st="vitalens:session",ie;function Ar(){if(ie)return ie;try{let t=sessionStorage.getItem(st);if(t)return ie=t,t}catch{}let e=$();ie=e;try{sessionStorage.setItem(st,e);}catch{}return e}function Dr(){if(typeof navigator=="undefined")return {};let e=navigator.connection;return {ua:typeof navigator.userAgent=="string"?navigator.userAgent.slice(0,512):"",screen:typeof screen!="undefined"?`${screen.width}x${screen.height}`:"unknown",language:typeof navigator.language=="string"?navigator.language:"unknown",connection:e==null?void 0:e.effectiveType}}function at(e){let t=typeof location!="undefined"?{path:location.pathname||"/",fullPath:`${location.pathname||"/"}${location.search||""}`}:void 0;return {appId:e.appId,buildId:e.buildId,env:e.env,sessionId:e.enabled?Ar():$(),route:t,device:Dr()}}var se=class{constructor(t){this.listeners=new Set;this.onError=t;}get size(){return this.listeners.size}subscribe(t){return this.listeners.add(t),()=>{this.listeners.delete(t);}}emit(t){if(t.length!==0)for(let r of [...this.listeners])p(()=>r(t),{onError:this.onError});}dispose(){this.listeners.clear();}};var Lr=/[\w.+-]+@[\w.-]+\.\w+/g,_r=/1[3-9]\d{9}/g,Or=new Set(["__proto__","constructor","prototype"]);function xe(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function ct(e){return Or.has(e)}function y(e,t){return e.length<=t?e:e.slice(0,t)}function Y(e){return e.replace(Lr,"[REDACTED]").replace(_r,"[REDACTED]")}function G(e,t){let r=Y(e);if(!t.stripQuery)return y(r,t.maxUrlLength);try{let n=new URL(r,"http://localhost"),o=n.origin==="http://localhost"?n.pathname||"/":`${n.origin}${n.pathname}`;return y(o,t.maxUrlLength)}catch{let n=r.search(/[?#]/),o=n>=0?r.slice(0,n):r;return y(o,t.maxUrlLength)}}function ut(e,t){if(t.captureQuery==="none")return;let r={},n=0;try{let o=new URL(e,"http://localhost");for(let[i,s]of o.searchParams){if(n>=50)break;ct(i)||t.captureQuery==="whitelist"&&!t.queryWhitelist.includes(i)||(r[i]=dt(i,t)?"[REDACTED]":y(Y(s),t.maxStringLength),n+=1);}}catch{return}return n>0?r:void 0}function dt(e,t){let r=e.toLowerCase();return t.redactKeys.some(n=>n.toLowerCase()===r)}function Te(e,t,r,n){if(dt(t,r))return "[REDACTED]";if(e===null)return null;if(typeof e=="string")return y(Y(e),r.maxStringLength);if(typeof e=="number"||typeof e=="boolean")return e;if(typeof e=="bigint")return e.toString();if(!(typeof e=="undefined"||typeof e=="function"||typeof e=="symbol")){if(n>=3)return "[Truncated]";if(Array.isArray(e)){let o=[];for(let i of e.slice(0,50)){let s=Te(i,t,r,n+1);s!==void 0&&o.push(s);}return o}if(xe(e)){let o={},i=0;for(let[s,a]of Object.entries(e)){if(i>=100)break;if(ct(s))continue;let c=Te(a,s,r,n+1);c!==void 0&&(o[s]=c,i+=1);}return o}}}function ae(e,t){if(!xe(e))return;let r=Te(e,"",t,0);return xe(r)?r:void 0}function ke(e){try{return JSON.stringify(e).length}catch{return Number.POSITIVE_INFINITY}}function V(e,t){if(e)return {path:G(e.path,t),fullPath:e.fullPath?G(e.fullPath,t):void 0,name:e.name?y(Y(e.name),t.maxStringLength):void 0}}function Se(e,t){return Y(y(e,t))}var Ie=["P0","P1","P2"],Nr=["P2","P1","P0"],ce=class{constructor(t,r=Math.max(2,Math.floor(t/4))){this.buckets={P0:[],P1:[],P2:[]};this.typeCounts=new Map;this.total=0;this.dropped=0;this.maxSize=Math.max(1,t),this.maxPerType=Math.max(1,r);}get size(){return this.total}enqueue(t,r){var n,o;return this.total>=this.maxSize&&this.dropLowest(),t.priority!=="P0"&&((n=this.typeCounts.get(t.type))!=null?n:0)>=this.maxPerType&&this.dropOldestOfType(t.type),this.total>=this.maxSize?(this.dropped+=1,false):(this.buckets[t.priority].push({record:t,size:r}),this.total+=1,this.typeCounts.set(t.type,((o=this.typeCounts.get(t.type))!=null?o:0)+1),true)}takeBatch(t,r){let n=[],o=0;for(let i of Ie){let s=this.buckets[i];for(;n.length<t;){let a=s[0];if(!a)break;if(n.length>0&&o+a.size>r)return n;if(a.size>r){s.shift(),this.total-=1,this.decrementType(a.record.type),this.dropped+=1;continue}s.shift(),this.total-=1,this.decrementType(a.record.type),n.push(a),o+=a.size;}}return n}requeue(t){for(let r of t)this.enqueue(r.record,r.size);}clear(){for(let t of Ie)this.buckets[t].length=0;this.typeCounts.clear(),this.total=0;}decrementType(t){var n;let r=(n=this.typeCounts.get(t))!=null?n:0;r<=1?this.typeCounts.delete(t):this.typeCounts.set(t,r-1);}dropLowest(){for(let t of Nr){let n=this.buckets[t].shift();if(n)return this.total-=1,this.decrementType(n.record.type),this.dropped+=1,true}return false}dropOldestOfType(t){for(let r of Ie){let n=this.buckets[r],o=n.findIndex(i=>i.record.type===t);if(o>=0){let[i]=n.splice(o,1);if(i)return this.total-=1,this.decrementType(t),this.dropped+=1,true}}return false}};function Br(e){return Number.isFinite(e)?Math.min(1,Math.max(0,e)):1}function x(e,t=Math.random){let r=Br(e);return r>=1?true:r<=0?false:t()<r}function ft(){return typeof globalThis.requestIdleCallback=="function"}function lt(){let e=globalThis.scheduler;return typeof(e==null?void 0:e.postTask)=="function"}var ue=class{constructor(t){this.disposers=new Set;this.onError=t;}schedule(t,r={}){var s,a,c,d,f;let n=false,o=()=>{},i=()=>{n||(n=true,this.disposers.delete(o),p(t,{onError:this.onError}));};if(r.delayMs&&r.delayMs>0){let u=setTimeout(i,r.delayMs);o=()=>{n=true,clearTimeout(u),this.disposers.delete(o);};}else if(lt()){let u=globalThis.scheduler,b=typeof AbortController!="undefined"?new AbortController:void 0;(a=(s=u==null?void 0:u.postTask)==null?void 0:s.call(u,i,{priority:"background",signal:b==null?void 0:b.signal}))==null||a.catch(()=>{i();}),o=()=>{n=true,b==null||b.abort(),this.disposers.delete(o);};}else if(ft()){let u=globalThis,b=(f=(d=u.requestIdleCallback)==null?void 0:d.call(u,i,{timeout:(c=r.timeoutMs)!=null?c:1e3}))!=null?f:0;o=()=>{var A;n=true,(A=u.cancelIdleCallback)==null||A.call(u,b),this.disposers.delete(o);};}else {let u=setTimeout(i,0);o=()=>{n=true,clearTimeout(u),this.disposers.delete(o);};}return this.disposers.add(o),o}dispose(){for(let t of [...this.disposers])t();this.disposers.clear();}};function T(e,t,r,n){return {id:$(),type:r,priority:n,timestamp:L(),appId:e.appId,sessionId:t.sessionId,buildId:e.buildId,env:e.env,route:t.route}}function k(e){switch(e){case "vital":case "error":return "P0";case "event":case "route":case "exposure":return "P1";case "request":case "resource":case "longTask":return "P2";default:return "P2"}}function pt(e){let t=256;if("message"in e&&(t+=e.message.length,e.stack&&(t+=e.stack.length)),"url"in e&&(t+=e.url.length),"name"in e&&typeof e.name=="string"&&(t+=e.name.length),"props"in e&&e.props)try{t+=JSON.stringify(e.props).length;}catch{t+=512;}return t}function ht(e,t){switch(e.transport.reporter){case "indexeddb":return {name:"indexeddb",report:r=>t().put(r)};case "console":return {name:"console",report:async r=>{console.warn(`[vitalens] ${r.length} records`,r.map(n=>n.type).join(","));}};case "http":case "beacon":return {name:e.transport.reporter,report:async()=>{}};default:return {name:"none",report:async()=>{}}}}function m(e,t){let r=qr(e);return new Error(r.length>0?`${t}\uFF1A${r}`:t)}function qr(e){if(e instanceof Error)return e.message;if(typeof e=="string")return e;if(typeof e=="object"&&e!==null&&"message"in e){let t=e.message;if(typeof t=="string")return t}return String(e)}var Fr="desc";function zr(e){return typeof e!="number"||!Number.isFinite(e)?0:Math.max(0,Math.trunc(e))}function Vr(e){if(!(typeof e!="number"||!Number.isFinite(e)))return e<=0?0:Math.trunc(e)}function U(e,t={}){var d;let r=t.types?new Set(t.types):null,n=typeof t.from=="number"&&Number.isFinite(t.from)?t.from:void 0,o=typeof t.to=="number"&&Number.isFinite(t.to)?t.to:void 0,i=e.filter(f=>!(r!==null&&!r.has(f.type)||n!==void 0&&f.timestamp<n||o!==void 0&&f.timestamp>o)),s=((d=t.order)!=null?d:Fr)==="asc"?1:-1;i.sort((f,u)=>(f.timestamp-u.timestamp)*s);let a=zr(t.offset),c=Vr(t.limit);return c===void 0?i.slice(a):i.slice(a,a+c)}var Ur=new Set(["__proto__","constructor","prototype"]),Xr=new Set(["vital","error","request","route","resource","longTask","event","exposure"]),jr=new Set(["LCP","INP","CLS","FCP","TTFB"]),Qr=new Set(["good","needs-improvement","poor"]),Hr=new Set(["window","unhandledrejection","resource","vue","manual"]),$r=new Set(["manual","click","pageView"]),S=["id","type","priority","timestamp","appId","sessionId","buildId","env","route"],Gr={vital:new Set([...S,"name","value","rating","metricId"]),error:new Set([...S,"name","message","stack","source","fingerprint","count","component"]),request:new Set([...S,"kind","method","url","status","durationMs","success"]),route:new Set([...S,"to","from","durationMs","navigation"]),resource:new Set([...S,"url","initiatorType","durationMs","failed","status"]),longTask:new Set([...S,"durationMs","name"]),event:new Set([...S,"name","props","source","truncated"]),exposure:new Set([...S,"name","props","target","truncated"])},l=new Error("invalid perf record"),X={ok:false};function P(e){if(typeof e!="object"||e===null||Array.isArray(e))return false;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function C(e){for(let t of Object.getOwnPropertyNames(e))if(Ur.has(t))return true;return false}function Yr(e,t){for(let r of Object.getOwnPropertyNames(e))if(!t.has(r))return false;return true}function gt(e){return typeof e=="string"&&Xr.has(e)}function Rt(e){return typeof e=="string"&&jr.has(e)}function bt(e){return typeof e=="string"&&Qr.has(e)}function vt(e){return typeof e=="string"&&Hr.has(e)}function wt(e){return typeof e=="string"&&$r.has(e)}function Et(e){return e==="P0"||e==="P1"||e==="P2"}function I(e){return typeof e=="number"&&Number.isFinite(e)}function fe(e){return typeof e=="string"&&e.trim().length>0}function v(e){return e===void 0||typeof e=="string"}function de(e){return e===void 0||I(e)}function mt(e){return e===void 0||typeof e=="boolean"}function Ce(e){if(!P(e)||C(e)||typeof e.path!="string"||!v(e.fullPath)||!v(e.name))return false;for(let t of Object.getOwnPropertyNames(e))if(t!=="path"&&t!=="fullPath"&&t!=="name")return false;return true}function yt(e){return P(e)&&!C(e)}function Pt(e){if(!P(e)||C(e))return false;let t=e.type;if(!gt(t)||!Yr(e,Gr[t])||!fe(e.id)||!I(e.timestamp)||!fe(e.appId)||!fe(e.sessionId)||!Et(e.priority)||!v(e.buildId)||!v(e.env)||e.route!==void 0&&!Ce(e.route))return false;switch(t){case "vital":return Rt(e.name)&&I(e.value)&&(e.rating===void 0||bt(e.rating))&&v(e.metricId);case "error":return typeof e.message=="string"&&vt(e.source)&&typeof e.fingerprint=="string"&&v(e.name)&&v(e.stack)&&v(e.component)&&de(e.count);case "request":return (e.kind==="fetch"||e.kind==="xhr")&&typeof e.method=="string"&&typeof e.url=="string"&&I(e.durationMs)&&typeof e.success=="boolean"&&de(e.status);case "route":return Ce(e.to)&&(e.from===void 0||Ce(e.from))&&I(e.durationMs)&&(e.navigation==="initial"||e.navigation==="spa");case "resource":return typeof e.url=="string"&&typeof e.failed=="boolean"&&v(e.initiatorType)&&de(e.durationMs)&&de(e.status);case "longTask":return I(e.durationMs)&&v(e.name);case "event":return typeof e.name=="string"&&(e.props===void 0||yt(e.props))&&(e.source===void 0||wt(e.source))&&mt(e.truncated);case "exposure":return typeof e.name=="string"&&(e.props===void 0||yt(e.props))&&v(e.target)&&mt(e.truncated);default:return false}}function Ae(e,t){if(t>8)return X;switch(typeof e){case "string":case "boolean":return {ok:true,value:e};case "number":return Number.isFinite(e)?{ok:true,value:e}:X;case "object":{if(e===null)return {ok:true,value:null};if(Array.isArray(e)){let n=e,o=[];for(let i of n){let s=Ae(i,t+1);if(!s.ok)return X;o.push(s.value);}return {ok:true,value:o}}if(!P(e)||C(e))return X;let r={};for(let n of Object.keys(e)){let o=Ae(e[n],t+1);if(!o.ok)return X;r[n]=o.value;}return {ok:true,value:r}}default:return X}}function De(e){if(!P(e)||C(e)||typeof e.path!="string")return null;let t={path:e.path};if(e.fullPath!==void 0){if(typeof e.fullPath!="string")return null;t.fullPath=e.fullPath;}if(e.name!==void 0){if(typeof e.name!="string")return null;t.name=e.name;}return t}function xt(e,t){let r=e[t];if(r===void 0)return;if(!P(r)||C(r))throw l;let n=Ae(r,0);if(!n.ok||!P(n.value))throw l;return n.value}function _(e,t){let r=e[t];if(typeof r!="string")throw l;return r}function Me(e,t){let r=e[t];if(!fe(r))throw l;return r}function K(e,t){let r=e[t];if(!I(r))throw l;return r}function E(e,t){let r=e[t];if(r!==void 0){if(typeof r!="string")throw l;return r}}function le(e,t){let r=e[t];if(r!==void 0){if(!I(r))throw l;return r}}function pe(e,t){let r=e[t];if(r!==void 0){if(typeof r!="boolean")throw l;return r}}function M(e,t){let r=Me(e,"id"),n=Me(e,"appId"),o=Me(e,"sessionId"),i=K(e,"timestamp"),s=e.priority;if(!Et(s))throw l;let a=E(e,"buildId"),c=E(e,"env"),d;if(e.route!==void 0){let u=De(e.route);if(!u)throw l;d=u;}let f={id:r,type:t,priority:s,timestamp:i,appId:n,sessionId:o};return a!==void 0&&(f.buildId=a),c!==void 0&&(f.env=c),d!==void 0&&(f.route=d),f}function Kr(e){let t=e.name;if(!Rt(t))throw l;let r=K(e,"value"),n=E(e,"metricId"),o={...M(e,"vital"),type:"vital",name:t,value:r},i=e.rating;if(i!==void 0){if(!bt(i))throw l;o.rating=i;}return n!==void 0&&(o.metricId=n),o}function Wr(e){let t=_(e,"message"),r=_(e,"fingerprint"),n=e.source;if(!vt(n))throw l;let o=E(e,"name"),i=E(e,"stack"),s=E(e,"component"),a=le(e,"count"),c={...M(e,"error"),type:"error",message:t,source:n,fingerprint:r};return o!==void 0&&(c.name=o),i!==void 0&&(c.stack=i),s!==void 0&&(c.component=s),a!==void 0&&(c.count=a),c}function Jr(e){let t=e.kind;if(t!=="fetch"&&t!=="xhr")throw l;let r=_(e,"method"),n=_(e,"url"),o=K(e,"durationMs"),i=pe(e,"success");if(i===void 0)throw l;let s=le(e,"status"),a={...M(e,"request"),type:"request",kind:t,method:r,url:n,durationMs:o,success:i};return s!==void 0&&(a.status=s),a}function Zr(e){let t=De(e.to);if(!t)throw l;let r;if(e.from!==void 0){let s=De(e.from);if(!s)throw l;r=s;}let n=K(e,"durationMs"),o=e.navigation;if(o!=="initial"&&o!=="spa")throw l;let i={...M(e,"route"),type:"route",to:t,durationMs:n,navigation:o};return r!==void 0&&(i.from=r),i}function en(e){let t=_(e,"url"),r=pe(e,"failed");if(r===void 0)throw l;let n=E(e,"initiatorType"),o=le(e,"durationMs"),i=le(e,"status"),s={...M(e,"resource"),type:"resource",url:t,failed:r};return n!==void 0&&(s.initiatorType=n),o!==void 0&&(s.durationMs=o),i!==void 0&&(s.status=i),s}function tn(e){let t=K(e,"durationMs"),r=E(e,"name"),n={...M(e,"longTask"),type:"longTask",durationMs:t};return r!==void 0&&(n.name=r),n}function rn(e){let t=_(e,"name"),r=xt(e,"props"),n=pe(e,"truncated"),o={...M(e,"event"),type:"event",name:t};r!==void 0&&(o.props=r),n!==void 0&&(o.truncated=n);let i=e.source;if(i!==void 0){if(!wt(i))throw l;o.source=i;}return o}function nn(e){let t=_(e,"name"),r=xt(e,"props"),n=E(e,"target"),o=pe(e,"truncated"),i={...M(e,"exposure"),type:"exposure",name:t};return r!==void 0&&(i.props=r),n!==void 0&&(i.target=n),o!==void 0&&(i.truncated=o),i}function on(e,t){switch(e){case "vital":return Kr(t);case "error":return Wr(t);case "request":return Jr(t);case "route":return Zr(t);case "resource":return en(t);case "longTask":return tn(t);case "event":return rn(t);case "exposure":return nn(t);default:{let r=e;throw new Error(`\u672A\u77E5\u8BB0\u5F55\u7C7B\u578B\uFF1A${String(r)}`)}}}function Tt(e){let t=0;for(let r=0;r<e.length;r+=1){let n=e.charCodeAt(r);n<128?t+=1:n<2048?t+=2:n>=55296&&n<=56319?(t+=4,r+=1):t+=3;}return t}function kt(e){try{let t=JSON.stringify(e);return typeof t!="string"?Number.POSITIVE_INFINITY:Tt(t)}catch{return Number.POSITIVE_INFINITY}}function Le(e){return kt(e)}function sn(e){if(!P(e)||C(e))return null;let t=e.type;if(!gt(t)||kt(e)>8192)return null;let r;try{r=on(t,e);}catch{return null}return Le(r)>8192?null:r}function he(e){if(typeof e!="string")throw new TypeError("\u5BFC\u51FA\u6570\u636E\u5FC5\u987B\u662F\u5B57\u7B26\u4E32");if(Tt(e)>10485760)throw new Error("\u5BFC\u51FA\u6587\u4EF6\u8D85\u8FC7 10485760 \u5B57\u8282\u4E0A\u9650");let t;try{t=JSON.parse(e);}catch{throw new Error("\u5BFC\u51FA\u6587\u4EF6\u4E0D\u662F\u5408\u6CD5\u7684 JSON")}if(!P(t)||C(t))throw new Error("\u5BFC\u51FA\u6587\u4EF6\u4FE1\u5C01\u683C\u5F0F\u65E0\u6548");if(t.formatVersion!==1)throw new Error(`\u4E0D\u652F\u6301\u7684\u5BFC\u51FA\u683C\u5F0F\u7248\u672C\uFF1A${String(t.formatVersion)}`);if(t.appId!==void 0&&typeof t.appId!="string")throw new Error("\u5BFC\u51FA\u6587\u4EF6 appId \u5B57\u6BB5\u65E0\u6548");if(t.exportedAt!==void 0&&typeof t.exportedAt!="string")throw new Error("\u5BFC\u51FA\u6587\u4EF6 exportedAt \u5B57\u6BB5\u65E0\u6548");let r=t.records;if(!Array.isArray(r))throw new TypeError("\u5BFC\u51FA\u6587\u4EF6\u7F3A\u5C11 records \u6570\u7EC4");if(r.length>1e5)throw new Error("\u5BFC\u51FA\u8BB0\u5F55\u6570\u8D85\u8FC7\u4E0A\u9650 100000");let n=r,o=[],i=0;for(let s of n){let a=sn(s);a?o.push(a):i+=1;}return {records:o,skipped:i}}function me(e){let t={formatVersion:1,exportedAt:new Date().toISOString(),records:[...e]},r=JSON.stringify(t);if(typeof r!="string")throw new TypeError("\u5BFC\u51FA\u6570\u636E\u5E8F\u5217\u5316\u5931\u8D25");return new Blob([r],{type:"application/json"})}var an=1,O="records",ye="timestamp",St="type",cn=1440*60*1e3,un=2e4,dn=7,fn=8*1024,ln=3e3;function ge(e,t){if(typeof e!="number"||!Number.isFinite(e))return t;let r=Math.trunc(e);return r>=1?r:t}function It(e,t){if(typeof e!="number"||!Number.isFinite(e))return t;let r=Math.trunc(e);return r>=0?r:t}var W=class{constructor(t){this.db=null;this.opening=null;this.disposed=false;let r=typeof t.namespace=="string"?t.namespace.trim():"";if(r.length===0)throw new TypeError("IndexedDbStorage \u9700\u8981\u975E\u7A7A namespace");this.dbName=`vitalens:${r}`,this.maxRecords=ge(t.maxRecords,un),this.retentionDays=It(t.retentionDays,dn),this.maxRecordBytes=ge(t.maxRecordBytes,fn),this.openTimeoutMs=ge(t.openTimeoutMs,ln);}async init(){if(this.disposed)throw new Error("IndexedDbStorage \u5DF2\u9500\u6BC1");if(this.db)return;if(this.opening)return this.opening;if(typeof indexedDB=="undefined")throw new Error("\u5F53\u524D\u73AF\u5883\u4E0D\u652F\u6301 IndexedDB");let t=this.openDatabase();this.opening=t;try{await t;}finally{this.opening===t&&(this.opening=null);}}async put(t){let r=this.requireDb();t.length!==0&&await this.runWriteTransaction(r,"\u5199\u5165 IndexedDB \u8BB0\u5F55",n=>{for(let o of t)n.put(o);this.deleteOverflowRecords(n);});}async query(t){let r=this.requireDb(),n=await this.readAll(r);return U(n,t)}async clear(){let t=this.requireDb();await this.runWriteTransaction(t,"\u6E05\u7A7A IndexedDB \u8BB0\u5F55",r=>{r.clear();});}async exportAll(){let t=this.requireDb(),r=await this.readAll(t);try{return me(U(r,{order:"asc"}))}catch(n){throw m(n,"\u751F\u6210\u5BFC\u51FA\u6570\u636E\u5931\u8D25")}}async importAll(t){this.requireDb();let r;try{r=await t.text();}catch(i){throw m(i,"\u8BFB\u53D6\u5BFC\u5165\u6587\u4EF6\u5931\u8D25")}let{records:n}=he(r),o=n.filter(i=>Le(i)<=this.maxRecordBytes);return await this.put(o),o.length}async prune(t){let r=this.requireDb(),n=ge(t.maxRecords,this.maxRecords),o=It(t.retentionDays,this.retentionDays),i=Date.now()-o*cn;await this.runWriteTransaction(r,"\u6E05\u7406\u8FC7\u671F IndexedDB \u8BB0\u5F55",s=>{let a=s.index(ye).openCursor(IDBKeyRange.upperBound(i,true));a.onsuccess=()=>{let c=a.result;c&&(c.delete(),c.continue());};}),await this.runWriteTransaction(r,"\u6309\u4E0A\u9650\u6E05\u7406 IndexedDB \u8BB0\u5F55",s=>{this.deleteOverflowRecords(s,n);});}dispose(){this.disposed=true;let t=this.db;return this.db=null,t&&(t.onversionchange=null,t.close()),Promise.resolve()}openDatabase(){return new Promise((t,r)=>{let n=false,o=null,i=()=>n?false:(n=true,o!==null&&(clearTimeout(o),o=null),true),s;try{s=indexedDB.open(this.dbName,an);}catch(a){r(m(a,"\u6253\u5F00 IndexedDB \u5931\u8D25"));return}o=setTimeout(()=>{i()&&r(new Error(`\u6253\u5F00 IndexedDB \u8D85\u65F6\uFF08${this.openTimeoutMs}ms\uFF09`));},this.openTimeoutMs),s.onupgradeneeded=()=>{let a=s.result,c=s.transaction;if(!c)return;let d=a.objectStoreNames.contains(O)?c.objectStore(O):a.createObjectStore(O,{keyPath:"id"});d.indexNames.contains(ye)||d.createIndex(ye,"timestamp",{unique:false}),d.indexNames.contains(St)||d.createIndex(St,"type",{unique:false});},s.onblocked=()=>{i()&&r(new Error("\u6253\u5F00 IndexedDB \u88AB\u963B\u585E\uFF1A\u5B58\u5728\u672A\u5173\u95ED\u7684\u65E7\u7248\u672C\u8FDE\u63A5"));},s.onerror=()=>{i()&&r(m(s.error,"\u6253\u5F00 IndexedDB \u5931\u8D25"));},s.onsuccess=()=>{let a=s.result;if(this.disposed){a.close(),i()&&r(new Error("IndexedDbStorage \u5DF2\u9500\u6BC1"));return}if(!i()){a.close();return}this.db=a,a.onversionchange=()=>{a.close(),this.db===a&&(this.db=null);},t();};})}requireDb(){if(this.disposed)throw new Error("IndexedDbStorage \u5DF2\u9500\u6BC1");if(!this.db)throw new Error("IndexedDbStorage \u5C1A\u672A\u521D\u59CB\u5316");return this.db}transactionDone(t,r){return new Promise((n,o)=>{t.oncomplete=()=>n(),t.onerror=()=>o(m(t.error,`${r}\u5931\u8D25`)),t.onabort=()=>o(m(t.error,`${r}\u88AB\u4E2D\u6B62`));})}requestToPromise(t){return new Promise((r,n)=>{t.onsuccess=()=>r(t.result),t.onerror=()=>n(m(t.error,"IndexedDB \u8BF7\u6C42\u5931\u8D25"));})}runWriteTransaction(t,r,n){let o;try{o=t.transaction(O,"readwrite");}catch(s){return Promise.reject(m(s,`\u521B\u5EFA${r}\u4E8B\u52A1\u5931\u8D25`))}let i=this.transactionDone(o,r);try{n(o.objectStore(O));}catch(s){i.catch(()=>{});try{o.abort();}catch{}return Promise.reject(m(s,r))}return i}async readAll(t){let r;try{r=t.transaction(O,"readonly");}catch(o){throw m(o,"\u521B\u5EFA IndexedDB \u8BFB\u4E8B\u52A1\u5931\u8D25")}let n=this.transactionDone(r,"\u8BFB\u53D6 IndexedDB \u8BB0\u5F55");try{let o=r.objectStore(O).getAll(),[i]=await Promise.all([this.requestToPromise(o),n]);return i.filter(s=>Pt(s))}catch(o){throw m(o,"\u8BFB\u53D6 IndexedDB \u8BB0\u5F55\u5931\u8D25")}}deleteOverflowRecords(t,r=this.maxRecords){let n=t.count();n.onsuccess=()=>{let o=n.result-r;if(o<=0)return;let i=t.index(ye).openCursor();i.onsuccess=()=>{let s=i.result;!s||o<=0||(s.delete(),o-=1,o>0&&s.continue());};};}};var pn=5e3,hn=1440*60*1e3;function Ct(e,t){if(typeof e!="number"||!Number.isFinite(e))return t;let r=Math.trunc(e);return r>=1?r:t}function mn(e){return typeof e!="number"||!Number.isFinite(e)?0:Math.max(0,Math.trunc(e))}var j=class{constructor(t={}){this.records=new Map;this.disposed=false;this.maxRecords=Ct(t.maxRecords,pn);}async init(){this.assertActive();}async put(t){this.assertActive();for(let r of t)this.records.delete(r.id),this.records.set(r.id,r);this.evictOverflow();}async query(t){return this.assertActive(),U(Array.from(this.records.values()),t)}async clear(){this.assertActive(),this.records.clear();}async exportAll(){this.assertActive();let t=U(Array.from(this.records.values()),{order:"asc"});try{return me(t)}catch(r){throw m(r,"\u751F\u6210\u5BFC\u51FA\u6570\u636E\u5931\u8D25")}}async importAll(t){this.assertActive();let r;try{r=await t.text();}catch(o){throw m(o,"\u8BFB\u53D6\u5BFC\u5165\u6587\u4EF6\u5931\u8D25")}let{records:n}=he(r);return await this.put(n),n.length}async prune(t){this.assertActive();let r=Ct(t.maxRecords,this.maxRecords),n=mn(t.retentionDays),o=Date.now()-n*hn,i=[];for(let s of this.records.values())s.timestamp<o?this.records.delete(s.id):i.push(s);if(i.length>r){i.sort((a,c)=>a.timestamp-c.timestamp);let s=i.length-r;for(let a of i.slice(0,s))this.records.delete(a.id);}}async dispose(){this.records.clear(),this.disposed=true;}evictOverflow(){for(;this.records.size>this.maxRecords;){let t=this.records.keys().next();if(t.done)return;this.records.delete(t.value);}}assertActive(){if(this.disposed)throw new Error("MemoryStorage \u5DF2\u9500\u6BC1")}};var yn=/^[a-z]\w{0,63}$/i;function Mt(e){return yn.test(e)}function At(e,t){if(!e)return {truncated:false};let r=Math.min(4096,t.limits.maxRecordBytes),n=ke(e),o=ae(e,t.privacy);return o?n>r||ke(o)>r?{props:{truncated:true},truncated:true}:{props:o,truncated:false}:{truncated:true}}var gn=6e4,Rn=6e4;function Re(e){return e instanceof Error?e.message:String(e)}async function bn(e){try{if(typeof crypto=="undefined"||!crypto.subtle)return;let t=new TextEncoder().encode(e),r=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(r)).map(n=>n.toString(16).padStart(2,"0")).join("")}catch{return}}var _e=class{constructor(t){this.config=t,this.enabled=t.enabled;}track(t,r,n){}trackPageView(t){}recordRoute(t){}recordError(t){}setUser(t){}setContext(t){}subscribe(t){return ()=>{}}async flush(t){}async query(t){return []}async exportAll(){return new Blob([JSON.stringify({formatVersion:1,records:[]})],{type:"application/json"})}async importAll(t){return 0}async clear(){}getDiagnostics(){return {enabled:this.enabled,degradeLevel:0,queueSize:0,dropped:0,selfErrors:0,sampling:{...this.config.sampling},storage:{available:false,circuitOpen:false},collectors:{}}}disable(){this.enabled=false;}async destroy(){this.enabled=false;}},Oe=class{constructor(t){this.destroyed=false;this.flushing=false;this.flushFailures=0;this.flushChain=Promise.resolve();this.storageAvailable=false;this.lastPruneAt=0;this.stopHandlers=[];this.emitBuffer=[];this.emitScheduled=false;this.localDropped=0;this.selfErrors=0;this.trackTimestamps=[];this.errorTimestamps=[];this.errorFingerprints=new Map;this.onVisibilityChange=()=>{typeof document!="undefined"&&document.visibilityState==="hidden"&&this.flush("hidden");};this.onPageHide=()=>{this.flush("pagehide");};this.config=t,this.enabled=t.enabled,this.context=at(t),this.queue=new ce(t.limits.maxQueueSize),this.scheduler=new ue(n=>this.reportSelfError(n)),this.bus=new se(n=>this.reportSelfError(n));let r={maxRecords:t.limits.maxRecords,retentionDays:t.limits.retentionDays,maxRecordBytes:t.limits.maxRecordBytes};this.storage=t.transport.reporter==="indexeddb"?new W({namespace:t.storageNamespace,...r}):new j({maxRecords:t.limits.maxRecords}),this.reporter=ht(t,()=>this.storage),this.storageReady=this.initStorage(),this.startCollectors(),this.installLifecycle();}track(t,r,n){var i;if(!this.enabled||this.destroyed)return;if(!Mt(t)){this.localDropped+=1,this.config.debug&&console.warn(`[vitalens] invalid event name: ${String(t)}`);return}if(!this.allowTrack()){this.localDropped+=1;return}let o=At(r,this.config);this.addEventRecord(t,o.props,"manual",o.truncated,(i=n==null?void 0:n.sampling)!=null?i:this.config.sampling.event),n!=null&&n.immediate&&this.flush("manual");}trackPageView(t){var o,i;if(!this.enabled||this.destroyed)return;let r=V(t!=null?t:this.context.route,this.config.privacy);if(!r)return;let n=this.context.route?V(this.context.route,this.config.privacy):void 0;this.context.route=r,this.addEventRecord("page_view",{from:(o=n==null?void 0:n.path)!=null?o:"",to:r.path,title:(i=r.name)!=null?i:""},"pageView",false,this.config.sampling.event);}recordRoute(t){var o,i;if(!this.enabled||this.destroyed)return;if(!x(this.config.sampling.route)){this.localDropped+=1;return}let r=V(t.to,this.config.privacy);if(!r)return;let n={...T(this.config,this.context,"route",k("route")),to:r,from:t.from?V(t.from,this.config.privacy):void 0,durationMs:Math.max(0,(o=t.durationMs)!=null?o:0),navigation:(i=t.navigation)!=null?i:"spa"};this.enqueueRecord(n);}recordError(t){!this.enabled||this.destroyed||this.addError(t);}setUser(t){if(this.config.privacy.user!=="none"){if(!t){this.context={...this.context,user:void 0};return}if(t.hash){this.context={...this.context,user:{hash:t.hash}};return}t.id&&bn(t.id).then(r=>{r&&(this.context={...this.context,user:{hash:r}});}).catch(r=>this.reportSelfError(r));}}setContext(t){var r;if(!this.destroyed&&(t.route&&(this.context={...this.context,route:V(t.route,this.config.privacy)}),t.user!==void 0&&this.setUser((r=t.user)!=null?r:null),t.device)){let n=ae(t.device,this.config.privacy);n&&(this.context={...this.context,device:n});}}subscribe(t){return this.bus.subscribe(t)}flush(t="manual"){return this.destroyed&&t!=="destroy"||!this.enabled&&t!=="destroy"?Promise.resolve():(this.flushChain=this.flushChain.then(()=>this.runFlush(t),()=>this.runFlush(t)),this.flushChain)}async query(t){return await this.storageReady,this.storage.query(t)}async exportAll(){return await this.storageReady,this.storage.exportAll()}async importAll(t){return await this.storageReady,this.storage.importAll(t)}async clear(){await this.storageReady,await this.storage.clear();}getDiagnostics(){return {enabled:this.enabled,degradeLevel:0,queueSize:this.queue.size,dropped:this.queue.dropped+this.localDropped,selfErrors:this.selfErrors,sampling:{...this.config.sampling},storage:{available:this.storageAvailable,lastError:this.storageLastError,circuitOpen:this.flushFailures>=3},collectors:{}}}disable(){this.enabled&&(this.flush("manual"),this.enabled=false,this.stopCollectors(),this.flushTimer&&(this.flushTimer(),this.flushTimer=void 0));}async destroy(){if(this.destroyed)return;this.enabled=false,this.stopCollectors(),this.removeLifecycle(),this.flushTimer&&(this.flushTimer(),this.flushTimer=void 0),await this.flush("destroy").catch(()=>{}),this.destroyed=true,this.scheduler.dispose(),this.bus.dispose(),await this.storage.dispose().catch(r=>this.reportSelfError(r));let t=globalThis;t.__VITALENS_PERF__===this&&delete t.__VITALENS_PERF__;}async initStorage(){try{await this.storage.init(),this.storageAvailable=this.config.transport.reporter==="indexeddb";}catch(t){this.reportSelfError(t),this.storageLastError=Re(t),this.storage=new j({maxRecords:this.config.limits.maxRecords}),this.storageAvailable=false,await this.storage.init();}}startCollectors(){let t=r=>{p(()=>{let n=r();n&&this.stopHandlers.push(n);},{onError:n=>this.reportSelfError(n)});};this.config.capture.vitals&&t(()=>it(r=>this.addVital(r),{reportAllChanges:true})),this.config.capture.errors&&t(()=>We(r=>this.addError(r),{unhandledRejection:true,resourceErrors:this.config.capture.resources,isInternal:()=>this.destroyed})),this.config.capture.requests&&t(()=>ot(r=>this.addRequest(r))),this.config.capture.longTask&&t(()=>et(r=>this.addLongTask(r),{threshold:50})),this.config.capture.resources&&t(()=>tt(r=>this.addResource(r),{slowThreshold:2e3})),this.config.capture.click&&t(()=>je((r,n)=>this.track(r,n)));}stopCollectors(){for(;this.stopHandlers.length>0;){let t=this.stopHandlers.pop();t&&p(t,{onError:r=>this.reportSelfError(r)});}}installLifecycle(){p(()=>{typeof document!="undefined"&&document.addEventListener("visibilitychange",this.onVisibilityChange),typeof window!="undefined"&&window.addEventListener("pagehide",this.onPageHide);},{onError:t=>this.reportSelfError(t)});}removeLifecycle(){p(()=>{typeof document!="undefined"&&document.removeEventListener("visibilitychange",this.onVisibilityChange),typeof window!="undefined"&&window.removeEventListener("pagehide",this.onPageHide);},{onError:t=>this.reportSelfError(t)});}addVital(t){if(!x(this.config.sampling.vital)){this.localDropped+=1;return}let r={...T(this.config,this.context,"vital",k("vital")),name:t.name,value:t.value,rating:t.rating,metricId:t.id};this.enqueueRecord(r);}addError(t){if(!this.allowError()){this.localDropped+=1;return}if(!x(this.config.sampling.error)){this.localDropped+=1;return}let r=Se(t.message,this.config.privacy.maxMessageLength),n=t.stack?Se(t.stack,this.config.privacy.maxStackLength):void 0,o=t.name?y(t.name,128):void 0,i=`${t.source}:${o!=null?o:""}:${r.slice(0,120)}`,s=L(),a=this.errorFingerprints.get(i);if(a!==void 0&&s-a<gn){this.localDropped+=1;return}if(this.errorFingerprints.set(i,s),this.errorFingerprints.size>this.config.limits.dedupeSize){let d=this.errorFingerprints.keys().next().value;typeof d=="string"&&this.errorFingerprints.delete(d);}let c={...T(this.config,this.context,"error",k("error")),name:o,message:r,stack:n,source:t.source,fingerprint:i,component:t.component?y(t.component,256):void 0};this.enqueueRecord(c);}addRequest(t){if(!x(this.config.sampling.request)){this.localDropped+=1;return}let r=G(t.url,this.config.privacy);if(!r)return;let n={...T(this.config,this.context,"request",k("request")),kind:t.kind,method:y(t.method.toUpperCase(),16),url:r,status:t.status,durationMs:Math.max(0,t.durationMs),success:t.success,query:ut(t.url,this.config.privacy)};this.enqueueRecord(n);}addResource(t){if(!x(this.config.sampling.resource)){this.localDropped+=1;return}let r=G(t.url,this.config.privacy);if(!r)return;let n={...T(this.config,this.context,"resource",k("resource")),url:r,initiatorType:t.initiatorType?y(t.initiatorType,32):void 0,durationMs:t.durationMs,failed:t.failed};this.enqueueRecord(n);}addLongTask(t){if(!x(this.config.sampling.longTask)){this.localDropped+=1;return}let r={...T(this.config,this.context,"longTask",k("longTask")),durationMs:Math.max(0,t.durationMs),name:t.name?y(t.name,64):void 0};this.enqueueRecord(r);}addEventRecord(t,r,n,o,i){if(!x(i)){this.localDropped+=1;return}let s={...T(this.config,this.context,"event",k("event")),name:y(t,64),props:r,source:n,truncated:o};this.enqueueRecord(s);}enqueueRecord(t){if(!this.enabled||this.destroyed)return;let r=pt(t);if(r>this.config.limits.maxRecordBytes){this.localDropped+=1,this.config.debug&&console.warn(`[vitalens] record dropped, size ${r} > maxRecordBytes`);return}this.queue.enqueue(t,r)&&(this.bus.size>0&&(this.emitBuffer.push(t),this.scheduleEmit()),this.ensureFlushScheduled(this.config.limits.flushIntervalMs));}scheduleEmit(){this.emitScheduled||this.emitBuffer.length===0||this.bus.size===0||(this.emitScheduled=true,this.scheduler.schedule(()=>{this.emitScheduled=false;let t=this.emitBuffer.splice(0);this.bus.emit(t),this.emitBuffer.length>0&&this.scheduleEmit();}));}ensureFlushScheduled(t){this.destroyed||this.flushTimer||(this.flushTimer=this.scheduler.schedule(()=>{this.flushTimer=void 0,this.flush("interval").then(()=>{this.queue.size>0&&!this.destroyed&&this.ensureFlushScheduled(0);});},{delayMs:t}));}async runFlush(t){if(await this.storageReady,!this.flushing&&!(!this.enabled&&t!=="destroy")){this.flushing=true;try{let r=this.queue.takeBatch(this.config.limits.maxBatchSize,this.config.limits.maxBatchBytes);if(r.length===0)return;let n=r.map(i=>i.record),o=w();try{await this.reporter.report(n),this.flushFailures=0,this.storageLastError=void 0,this.maybePrune();}catch(i){this.flushFailures+=1,this.storageLastError=Re(i),this.reportSelfError(i),this.queue.requeue(r),this.maybeFallbackStorage(),this.ensureFlushScheduled(Math.min(3e4,1e3*2**Math.min(this.flushFailures,5)));}finally{let i=w()-o;i>this.config.limits.flushDeadlineMs&&this.config.debug&&console.warn(`[vitalens] flush exceeded deadline: ${i.toFixed(1)}ms`);}}finally{this.flushing=false,this.queue.size>0&&!this.destroyed&&this.ensureFlushScheduled(0);}}}maybeFallbackStorage(){this.flushFailures<3||this.storage instanceof W&&(this.reportSelfError(new Error("IndexedDB unavailable, falling back to memory storage")),this.storage=new j({maxRecords:this.config.limits.maxRecords}),this.storageAvailable=false,this.storage.init().catch(t=>this.reportSelfError(t)));}maybePrune(){let t=L();if(t-this.lastPruneAt<Rn)return;this.lastPruneAt=t;let r=this.storage;r.prune&&this.scheduler.schedule(()=>{var n;(n=r.prune)==null||n.call(r,{maxRecords:this.config.limits.maxRecords,retentionDays:this.config.limits.retentionDays}).catch(o=>this.reportSelfError(o));});}allowTrack(){var n;let t=L(),r=t-6e4;for(;this.trackTimestamps.length>0&&((n=this.trackTimestamps[0])!=null?n:t)<r;)this.trackTimestamps.shift();return this.trackTimestamps.length>=this.config.limits.maxTracksPerMinute?false:(this.trackTimestamps.push(t),true)}allowError(){var n;let t=L(),r=t-6e4;for(;this.errorTimestamps.length>0&&((n=this.errorTimestamps[0])!=null?n:t)<r;)this.errorTimestamps.shift();return this.errorTimestamps.length>=this.config.limits.maxErrorsPerMinute?false:(this.errorTimestamps.push(t),true)}reportSelfError(t){if(this.selfErrors+=1,this.config.debug)try{console.warn("[vitalens] internal error:",Re(t));}catch{}}};function Ne(e=Z({appId:"vitalens-noop",enabled:false})){return new _e(e)}function Dt(e){let t=Z(e),r=typeof window!="undefined";if(!t.enabled||!r)return Ne({...t,enabled:false});let n=globalThis,o=n.__VITALENS_PERF__;if(o)return console.warn("[vitalens] createPerf called more than once; reusing the existing instance."),o;try{let i=new Oe(t);return n.__VITALENS_PERF__=i,i}catch(i){return console.warn("[vitalens] createPerf failed, falling back to noop:",Re(i)),Ne({...t,enabled:false})}}function vn(){return globalThis.__VITALENS_PERF__}function wn(e){return Dt(e)}
2
+ export{ze as DEFAULT_CAPTURE,g as DEFAULT_LIMITS,D as DEFAULT_PRIVACY,be as DEFAULT_SAMPLING,ve as DEFAULT_TRANSPORT,Ne as createNoopPerf,Dt as createPerf,vn as getPerf,wn as initPerf,Z as resolveConfig};//# sourceMappingURL=index.js.map
3
3
  //# sourceMappingURL=index.js.map