"use strict";var T=Object.defineProperty;var le=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var de=Object.prototype.hasOwnProperty;var fe=(s,e)=>{for(var t in e)T(s,t,{get:e[t],enumerable:!0})},he=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of pe(e))!de.call(s,r)&&r!==t&&T(s,r,{get:()=>e[r],enumerable:!(n=le(e,r))||n.enumerable});return s};var ge=s=>he(T({},"__esModule",{value:!0}),s);var Re={};fe(Re,{BehaviorPlugin:()=>$,Client:()=>B,ErrorPlugin:()=>O,NetworkPlugin:()=>U,OfflinePlugin:()=>K,PerformancePlugin:()=>F,addBreadcrumb:()=>oe,captureEvent:()=>te,captureException:()=>Y,captureMessage:()=>ee,default:()=>xe,disable:()=>ce,enable:()=>ue,flush:()=>ae,getClient:()=>Z,init:()=>J,setExtra:()=>se,setTag:()=>re,setTags:()=>ie,setUser:()=>ne});module.exports=ge(Re);function A(s){try{let e=s.match(/^(https?):\/\/([^@]+)@([^/]+)\/(.+)$/);if(!e)throw new Error("Invalid DSN format");let[,t,n,r,i]=e;return{protocol:t,publicKey:n,host:r,projectId:i}}catch(e){throw new Error(`Failed to parse DSN: ${e.message}`)}}function b(s){return`${s.protocol}://${s.host}/${s.projectId}/envelope/`}function p(){return Date.now()}function v(s){return s!==null&&typeof s=="object"&&!Array.isArray(s)}function C(s){let e=0;for(let t=0;t`${i.filename}:${i.lineno||0}`).join("|"),r=e.replace(/['"]?\d+['"]?/g,"").replace(/\s+/g," ").trim();return C(`${s}:${r}:${n}`)}function me(s){let e=[{name:"WeChat",pattern:/MicroMessenger\/([\d.]+)/i},{name:"QQ Browser",pattern:/QIBrowser\/([\d.]+)/i},{name:"UC Browser",pattern:/UCBrowser\/([\d.]+)/i},{name:"Edge",pattern:/Edg\/([\d.]+)/i},{name:"Edge",pattern:/Edge\/([\d.]+)/i},{name:"Opera",pattern:/OPR\/([\d.]+)/i},{name:"Opera",pattern:/Opera\/([\d.]+)/i},{name:"Firefox",pattern:/Firefox\/([\d.]+)/i},{name:"Safari",pattern:/Version\/([\d.]+).*Safari/i},{name:"Chrome",pattern:/Chrome\/([\d.]+)/i},{name:"IE",pattern:/MSIE ([\d.]+)/i},{name:"IE",pattern:/Trident.*rv:([\d.]+)/i}];for(let t of e){let n=s.match(t.pattern);if(n){let r=n[1]||"",i=r.split(".")[0]||"";return{name:t.name,version:r,major:i}}}return{name:"Unknown",version:"",major:""}}function ve(s){let e=[{name:"Windows 11",pattern:/Windows NT 10\.0.*Win64.*x64/i},{name:"Windows 10",pattern:/Windows NT 10\.0/i},{name:"Windows 8.1",pattern:/Windows NT 6\.3/i},{name:"Windows 8",pattern:/Windows NT 6\.2/i},{name:"Windows 7",pattern:/Windows NT 6\.1/i},{name:"Windows Vista",pattern:/Windows NT 6\.0/i},{name:"Windows XP",pattern:/Windows NT 5\.1/i},{name:"macOS",pattern:/Mac OS X ([\d_.]+)/i},{name:"iOS",pattern:/OS ([\d_.]+) like Mac OS X/i},{name:"Android",pattern:/Android ([\d.]+)/i},{name:"Android",pattern:/Android/i},{name:"Linux",pattern:/Linux/i}];for(let t of e){let n=s.match(t.pattern);if(n){let r=n[1]||"";return r&&(r=r.replace(/_/g,".")),{name:t.name,version:r}}}return{name:"Unknown",version:""}}function ye(s){let e=/Mobile|Android|iPhone|iPod|BlackBerry|Windows Phone|Opera Mini/i.test(s),t=/Tablet|iPad|PlayBook|Kindle|Silk/i.test(s),n="desktop";t?n="tablet":e&&(n="mobile");let r="",i="",o=s.match(/iPhone/i),a=s.match(/iPad/i),c=s.match(/SM-([A-Z0-9]+)/i),u=s.match(/Pixel ([0-9A-Z]+)/i),d=s.match(/HUAWEI ([A-Z0-9]+)/i);return o?(r="Apple",i="iPhone"):a?(r="Apple",i="iPad"):c?(r="Samsung",i=c[1]):u?(r="Google",i=`Pixel ${u[1]}`):d&&(r="Huawei",i=d[1]),{type:n,vendor:r,model:i}}function X(){let s=typeof navigator!="undefined"?navigator.userAgent:"",e=me(s),t=ve(s),n=ye(s);return{browser:e,os:t,device:n,url:typeof location!="undefined"?location.href:"",referrer:typeof document!="undefined"?document.referrer:"",title:typeof document!="undefined"?document.title:"",language:typeof navigator!="undefined"?navigator.language:"",user_agent:s,screen_width:typeof screen!="undefined"?screen.width:0,screen_height:typeof screen!="undefined"?screen.height:0,viewport_width:typeof window!="undefined"?window.innerWidth:0,viewport_height:typeof window!="undefined"?window.innerHeight:0}}function g(){return typeof location!="undefined"?location.href:""}function z(){return typeof document!="undefined"?document.referrer:""}function M(s){if(!s)return s;try{let e=new URL(s),t=["password","passwd","pwd","token","access_token","refresh_token","api_key","apikey","key","secret","private_key","code","auth","id_token","idToken","session","session_id"],n=e.searchParams,r=!1;for(let i of Array.from(n.keys())){let o=i.toLowerCase().replace(/[-_]/g,"_");t.some(a=>o.includes(a))&&(n.set(i,"[Filtered]"),r=!0)}return r?e.toString():s}catch(e){return s}}function w(s,e=[]){return!e||e.length===0?!1:e.some(t=>{if(typeof t=="string"){if(t.includes("*")){let n=t.replace(/[.+?^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*");return new RegExp(n).test(s)}return s.includes(t)}return t.test(s)})}var be={Chrome:"c",Safari:"s",Firefox:"f",Edge:"e",Opera:"o",IE:"i",WeChat:"w","QQ Browser":"q","UC Browser":"u","Mobile Chrome":"cm","Mobile Safari":"sm"},Ee={"Windows 11":"w11","Windows 10":"w10","Windows 8.1":"w81","Windows 8":"w8","Windows 7":"w7","Windows Vista":"wv","Windows XP":"wxp",macOS:"m",iOS:"i",Android:"a",Linux:"l"};function I(){let s=X(),e=be[s.browser.name]||s.browser.name.toLowerCase(),t=Ee[s.os.name]||s.os.name.toLowerCase();return{browser:{name:e,version:s.browser.major},os:{name:t,version:s.os.version.split(".")[0]},device:{type:s.device.type,brand:s.device.vendor||void 0,model:s.device.model||void 0}}}function V(){let s=X(),e=`${s.browser.name}|${s.browser.major}|${s.os.name}|${s.os.version.split(".")[0]}|${s.device.type}|${s.device.vendor}|${s.device.model}|${s.language}`;return C(e).substring(0,16)}var we={enabled:!0,sampleRate:1,maxQueueSize:100,flushInterval:5e3,maxRetries:3,retryDelay:1e3,environment:"production",contextLevel:{fatal:{maxStackFrames:5,maxBreadcrumbs:20},error:{maxStackFrames:5,maxBreadcrumbs:10},warning:{maxStackFrames:3,maxBreadcrumbs:5},info:{maxStackFrames:0,maxBreadcrumbs:0},debug:{maxStackFrames:0,maxBreadcrumbs:0}}},S=class{constructor(e){this.contexts=null;this.contextId=null;this.contextReported=!1;this.config={...we,...e}}markContextReported(){this.contextReported=!0}get(e){return this.config[e]}getAll(){return{...this.config}}set(e,t){this.config[e]=t}setUser(e){this.config.user=e||void 0}setTags(e){this.config.tags={...this.config.tags||{},...e}}setTag(e,t){this.config.tags||(this.config.tags={}),this.config.tags[e]=t}setExtra(e,t){this.config.extra||(this.config.extra={}),this.config.extra[e]=t}shouldSample(){var t;let e=(t=this.config.sampleRate)!=null?t:1;return e>=1?!0:e<=0?!1:Math.random()typeof n=="string"?e.includes(n):n.test(e))}getEncodedContext(){return this.contexts||(this.contexts=I()),this.contexts}applyToEvent(e,t=!0){var n,r,i,o;return this.config.release&&(e.release=this.config.release),this.config.environment&&(e.environment=this.config.environment),this.config.user&&(e.user=this.config.user),this.config.tags&&(e.tags={...this.config.tags,...e.tags||{}}),e.request?e.request.url||(e.request.url=g()):e.request={url:g(),referrer:z()},this.contextId||(this.contextId=V()),e.context_id=this.contextId,this.applyContextLevel(e),t&&!this.contextReported&&(this.contexts||(this.contexts=I()),e.contexts=this.contexts,e.env={b:(n=this.contexts.browser)==null?void 0:n.name,bv:(r=this.contexts.browser)==null?void 0:r.version,os:(i=this.contexts.os)==null?void 0:i.name,osv:(o=this.contexts.os)==null?void 0:o.version}),e}applyContextLevel(e){var i,o,a,c;let t=this.config.contextLevel;if(!t)return;let n=e.level||"error",r=t[n]||t.error;(o=(i=e.exception)==null?void 0:i.stacktrace)!=null&&o.frames&&r.maxStackFrames>0?e.exception.stacktrace.frames=e.exception.stacktrace.frames.slice(0,r.maxStackFrames):r.maxStackFrames===0&&((c=(a=e.exception)==null?void 0:a.stacktrace)!=null&&c.frames)&&delete e.exception.stacktrace,e.breadcrumbs&&r.maxBreadcrumbs>0?e.breadcrumbs=e.breadcrumbs.slice(-r.maxBreadcrumbs):r.maxBreadcrumbs===0&&delete e.breadcrumbs}};var x=class{constructor(){this.handlers=new Map}on(e,t){this.handlers.has(e)||this.handlers.set(e,[]),this.handlers.get(e).push(t)}off(e,t){let n=this.handlers.get(e);if(n){let r=n.indexOf(t);r>-1&&n.splice(r,1)}}emit(e,...t){let n=this.handlers.get(e);if(n)for(let r of n)try{r(...t)}catch(i){console.error("[LightSDK] EventBus handler error:",i)}}once(e,t){let n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}destroy(){this.handlers.clear()}};var R=class{constructor(e,t,n,r,i){this.queue=[];this.timer=null;this.lastFlushTime=0;this.dedupeMap=new Map;this.pendingCounts=new Map;this.errorRateWindow={};this.paused=!1;this.pauseTimer=null;this.maxSize=e,this.flushInterval=t,this.eventBus=n,this.flushCallback=r,this.syncFlushCallback=i}start(){this.startTimer(),this.setupVisibilityListener()}startTimer(){this.timer||(this.timer=setInterval(()=>{(this.queue.length>0||this.pendingCounts.size>0)&&this.flush()},this.flushInterval))}setupVisibilityListener(){typeof document!="undefined"&&document.addEventListener("visibilitychange",()=>{document.hidden&&(this.queue.length>0||this.pendingCounts.size>0)&&this.flushSync()}),typeof window!="undefined"&&(window.addEventListener("beforeunload",()=>{(this.queue.length>0||this.pendingCounts.size>0)&&this.flushSync()}),window.addEventListener("pagehide",()=>{(this.queue.length>0||this.pendingCounts.size>0)&&this.flushSync()}))}checkInfiniteLoop(e){let t=p(),n=t-1e3;this.errorRateWindow[e]||(this.errorRateWindow[e]=[]);let r=this.errorRateWindow[e];for(r.push(t);r.length>0&&r[0]10?(this.paused||(console.warn("[LightSDK] Infinite loop detected, pausing SDK for 60s",{fingerprint:e,count:r.length}),this.eventBus.emit("error",new Error("Infinite loop detected")),this.paused=!0,this.pauseTimer&&clearTimeout(this.pauseTimer),this.pauseTimer=setTimeout(()=>{this.paused=!1,this.errorRateWindow={},console.info("[LightSDK] Resumed after infinite loop detection")},6e4)),!0):!1}enqueue(e){if(this.paused)return;let t=this.getDedupeKey(e);if(t){if(this.checkInfiniteLoop(t))return;let n=p(),r=this.dedupeMap.get(t);if(r)if(n-r.lastTime<6e4){if(r.count>=3){if(!this.pendingCounts.has(t))this.pendingCounts.set(t,{count:1,ts_start:n,ts_end:n});else{let i=this.pendingCounts.get(t);i.count++,i.ts_end=n}return}r.count++,r.lastTime=n}else this.dedupeMap.set(t,{count:1,lastTime:n,firstReported:!0}),this.pendingCounts.delete(t);else this.dedupeMap.set(t,{count:1,lastTime:n,firstReported:!1})}this.queue.length>=this.maxSize&&this.flush(),this.queue.push(e),this.eventBus.emit("event",e),this.queue.length>=this.maxSize&&this.flush()}buildCountEvents(){let e=[];for(let[t,n]of this.pendingCounts.entries()){let r={type:"count",fingerprint:t,count:n.count,ts_start:n.ts_start,ts_end:n.ts_end,timestamp:p(),level:"info"};e.push(r)}return this.pendingCounts.clear(),e}getDedupeKey(e){if(e.type==="error"){let t=e;return t.fingerprint||t.message}return null}async flush(){if(this.queue.length===0&&this.pendingCounts.size===0)return;let e=this.queue.splice(0,this.queue.length),t=this.buildCountEvents(),n=[...e,...t];this.lastFlushTime=p(),this.eventBus.emit("report",n);try{await this.flushCallback(n),this.eventBus.emit("reported",n)}catch(r){throw e.forEach(i=>this.queue.unshift(i)),r}}flushSync(){if(this.queue.length===0&&this.pendingCounts.size===0)return;let e=this.queue.splice(0,this.queue.length),t=this.buildCountEvents(),n=[...e,...t];this.lastFlushTime=p(),this.eventBus.emit("report",n);try{this.syncFlushCallback(n),this.eventBus.emit("reported",n)}catch(r){console.error("[LightSDK] Sync flush failed",r)}}size(){return this.queue.length}destroy(){this.timer&&(clearInterval(this.timer),this.timer=null),this.pauseTimer&&(clearTimeout(this.pauseTimer),this.pauseTimer=null),this.dedupeMap.clear(),this.pendingCounts.clear(),this.errorRateWindow={}}};var Q={event_id:"eid",timestamp:"ts",start_timestamp:"sts",type:"t",level:"l",message:"m",platform:"p",release:"r",environment:"e",fingerprint:"fp",context_id:"cid",user:"u",tags:"tg",exception:"ex",request:"req",contexts:"ctx",breadcrumbs:"bc",transaction:"tx",duration:"d",spans:"sp",extra:"xt"},Ne=Object.fromEntries(Object.entries(Q).map(([s,e])=>[e,s]));function G(s){if(!s||typeof s!="object")return s;let e={};for(let[t,n]of Object.entries(s)){let r=Q[t]||t;e[r]=n}return e}var L=class{constructor(e,t,n){this.useShortFields=!0;this.dsn=e,this.maxRetries=t,this.retryDelay=n}async report(e){if(e.length===0)return;let t=this.buildEnvelope(e),n=0;for(;n<=this.maxRetries;)try{await this.send(t,!1);return}catch(r){let i=r.status;if(i&&i>=400&&i<500||(n++,n>this.maxRetries))throw r;await this.delay(this.retryDelay*Math.pow(2,n-1))}}reportSync(e){if(e.length===0)return;let t=this.buildEnvelope(e);try{if(this.sendSync(t))return}catch(n){}this.sendViaImage(t)}buildEnvelope(e){let t=this.extractSharedMeta(e),n={event_id:this.generateEventId(),sent_at:new Date().toISOString(),meta:t};this.useShortFields&&(n._sf=1);let r=this.applyRelativeTimestamps(e,n),o=[JSON.stringify(n)];for(let a of r){let c=this.stripSharedFields(a,t);this.useShortFields&&(c=G(c));let u=JSON.stringify(c),d=JSON.stringify({type:this.getEnvelopeType(a),length:u.length});o.push(d,u)}return o.join(` `)}applyRelativeTimestamps(e,t){if(e.length<=1)return e;let n=[],r=e[0].timestamp?new Date(e[0].timestamp).getTime():Date.now();t._rt=1,t._bt=r;for(let i=0;io.release===t.release)&&(n.release=t.release),t.environment&&e.every(o=>o.environment===t.environment)&&(n.environment=t.environment),t.user&&e.every(o=>JSON.stringify(o.user)===JSON.stringify(t.user))&&(n.user=t.user);let r=t.env;return r&&(n.env=r),n}stripSharedFields(e,t){let n={...e};return t.release&&n.release===t.release&&delete n.release,t.environment&&n.environment===t.environment&&delete n.environment,t.user&&JSON.stringify(n.user)===JSON.stringify(t.user)&&delete n.user,t.env&&delete n.env,n}getEnvelopeType(e){switch(e.type){case"error":return"event";case"performance":return"transaction";default:return e.type}}generateEventId(){return"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx".replace(/[x]/g,()=>(Math.random()*16|0).toString(16))}async send(e,t=!1){let n=b(this.dsn);if(navigator.sendBeacon)try{let r=new Blob([e],{type:"application/x-sentry-envelope"});if(navigator.sendBeacon(n,r))return}catch(r){}if(typeof fetch=="function")try{let r=await fetch(n,{method:"POST",body:e,headers:{"Content-Type":"application/x-sentry-envelope"},keepalive:!0});if(r.ok)return;let i=new Error(`HTTP ${r.status}`);throw i.status=r.status,i}catch(r){throw r}if(typeof XMLHttpRequest!="undefined")return new Promise((r,i)=>{let o=new XMLHttpRequest;o.open("POST",n,!t),o.setRequestHeader("Content-Type","application/x-sentry-envelope"),o.onload=()=>{if(o.status>=200&&o.status<300)r();else{let a=new Error(`HTTP ${o.status}`);a.status=o.status,i(a)}},o.onerror=()=>i(new Error("Network error")),o.send(e)});throw new Error("No transport available")}sendSync(e){let t=b(this.dsn);if(navigator.sendBeacon)try{let n=new Blob([e],{type:"application/x-sentry-envelope"});return navigator.sendBeacon(t,n)}catch(n){return!1}if(typeof XMLHttpRequest!="undefined")try{let n=new XMLHttpRequest;return n.open("POST",t,!1),n.setRequestHeader("Content-Type","application/x-sentry-envelope"),n.send(e),n.status>=200&&n.status<300}catch(n){return!1}return!1}sendViaImage(e){try{let t=b(this.dsn),n=new Image,r=encodeURIComponent(btoa(e));return n.src=t+"&sentry_data="+r.substring(0,2e3),!0}catch(t){return!1}}delay(e){return new Promise(t=>setTimeout(t,e))}};var k=class{constructor(e){this.plugins=new Map;this.client=e}add(e){if(!this.plugins.has(e.name)){this.plugins.set(e.name,e);try{e.setup(this.client)}catch(t){console.error(`[LightSDK] Plugin "${e.name}" setup error:`,t)}}}remove(e){let t=this.plugins.get(e);if(t){if(t.destroy)try{t.destroy()}catch(n){console.error(`[LightSDK] Plugin "${e}" destroy error:`,n)}this.plugins.delete(e)}}get(e){return this.plugins.get(e)}has(e){return this.plugins.has(e)}applyBeforeReport(e){let t=e;for(let n of this.plugins.values())if(n.beforeReport)try{let r=n.beforeReport(t);if(r===null)return null;t=r}catch(r){console.error(`[LightSDK] Plugin "${n.name}" beforeReport error:`,r)}return t}applyAfterReport(e){for(let t of this.plugins.values())if(t.afterReport)try{t.afterReport(e)}catch(n){console.error(`[LightSDK] Plugin "${t.name}" afterReport error:`,n)}}destroy(){for(let e of this.plugins.values())if(e.destroy)try{e.destroy()}catch(t){console.error(`[LightSDK] Plugin "${e.name}" destroy error:`,t)}this.plugins.clear()}};var _=class{constructor(e){this.breadcrumbs=[];this.maxBreadcrumbs=20;this.enabled=!0;var t,n,r,i;if(!e.dsn)throw new Error("DSN is required");this.dsn=A(e.dsn),this.configManager=new S(e),this.config=this.configManager.getAll(),this.eventBus=new x,this.reporter=new L(this.dsn,(t=e.maxRetries)!=null?t:3,(n=e.retryDelay)!=null?n:1e3),this.pluginManager=new k(this),this.queue=new R((r=e.maxQueueSize)!=null?r:100,(i=e.flushInterval)!=null?i:5e3,this.eventBus,async o=>this.flushEvents(o),o=>this.syncFlushEvents(o)),this.enabled=e.enabled!==!1}init(){this.enabled&&(this.queue.start(),this.emit("ready"))}async flushEvents(e){let t=[];for(let i of e){let o=this.pluginManager.applyBeforeReport(i);o&&t.push(o)}if(t.length===0)return;let n=!0,r=[];for(let i of t){let o=this.configManager.applyToEvent(i,n);n=!1;let a=this.config.get("beforeSend")?this.config.get("beforeSend")(o):o;a&&r.push(a)}if(r.length!==0){await this.reporter.report(r),this.configManager.markContextReported();for(let i of r)this.pluginManager.applyAfterReport(i)}}syncFlushEvents(e){let t=[];for(let i of e){let o=this.pluginManager.applyBeforeReport(i);o&&t.push(o)}if(t.length===0)return;let n=!0,r=[];for(let i of t){let o=this.configManager.applyToEvent(i,n);n=!1;let a=this.config.get("beforeSend")?this.config.get("beforeSend")(o):o;a&&r.push(a)}r.length!==0&&(this.reporter.reportSync(r),this.configManager.markContextReported())}on(e,t){this.eventBus.on(e,t)}off(e,t){this.eventBus.off(e,t)}emit(e,...t){this.eventBus.emit(e,...t)}captureException(e){if(!this.enabled||!this.configManager.shouldSample())return;let t=this.buildErrorEvent(e);this.configManager.isIgnoredError(t.message)||(t.breadcrumbs=[...this.breadcrumbs],this.queue.enqueue(t))}captureMessage(e,t="info"){if(!this.enabled||!this.configManager.shouldSample())return;let n={type:"error",level:t,message:e,timestamp:p(),breadcrumbs:[...this.breadcrumbs]};this.configManager.isIgnoredError(e)||this.queue.enqueue(n)}captureEvent(e){if(!this.enabled||!this.configManager.shouldSample())return;let t={timestamp:p(),level:"info",...e};this.queue.enqueue(t)}buildErrorEvent(e){let t=p();if(e instanceof Error){let r=this.parseStackTrace(e.stack),i=E(e.name,e.message,r);return{type:"error",level:"error",message:e.message,timestamp:t,exception:{type:e.name,value:e.message,stacktrace:{frames:r.slice(0,5)}},fingerprint:i}}return{type:"error",level:"error",message:String(e),timestamp:t}}parseStackTrace(e){if(!e)return[];let t=[],n=e.split(` `);for(let r of n){let i=r.match(/^\s*at\s*(.+?)\s*\((.+?):(\d+):(\d+)\)\s*$/);if(i){let[,o,a,c,u]=i;t.push({filename:a,function:o,lineno:parseInt(c,10),colno:parseInt(u,10),in_app:!a.includes("node_modules")})}else{let o=r.match(/^\s*at\s*(.+?):(\d+):(\d+)\s*$/);if(o){let[,a,c,u]=o;t.push({filename:a,lineno:parseInt(c,10),colno:parseInt(u,10),in_app:!a.includes("node_modules")})}}}return t.reverse()}setUser(e){this.configManager.setUser(e)}setTag(e,t){this.configManager.setTag(e,t)}setTags(e){this.configManager.setTags(e)}setExtra(e,t){this.configManager.setExtra(e,t)}addBreadcrumb(e){let t={...e,timestamp:p()};this.breadcrumbs.push(t),this.breadcrumbs.length>this.maxBreadcrumbs&&this.breadcrumbs.shift()}async flush(){await this.queue.flush()}disable(){this.enabled=!1}enable(){this.enabled=!0}use(e){e&&typeof e=="object"&&"name"in e&&"setup"in e&&this.pluginManager.add(e)}destroy(){this.queue.destroy(),this.pluginManager.destroy(),this.eventBus.destroy(),this.breadcrumbs=[]}},B=_;var D=class{constructor(){this.name="error";this.version="1.0.0";this.config={maxStackFrames:5,captureNodeModules:!1,captureColumn:!0,relativePathOnly:!1}}setup(e){this.client=e,this.loadConfig(),this.setupGlobalError(),this.setupUnhandledRejection(),this.setupResourceError()}loadConfig(){let e=this.client.config;e&&v(e.error)&&(this.config={...this.config,...e.error}),e.ignoreErrors&&(this.config.ignoreErrors=[...this.config.ignoreErrors||[],...e.ignoreErrors]),e.ignoreUrls&&(this.config.ignoreUrls=[...this.config.ignoreUrls||[],...e.ignoreUrls])}shouldIgnoreError(e){return!this.config.ignoreErrors||!e?!1:this.config.ignoreErrors.some(t=>typeof t=="string"?e.includes(t):t.test(e))}shouldIgnoreScriptUrl(e){return w(e,this.config.ignoreUrls)}setupGlobalError(){if(typeof window=="undefined")return;let e=window.onerror;window.onerror=(t,n,r,i,o)=>{try{e&&e.call(window,t,n,r,i,o);let a=this.buildErrorEvent(o||t,n,r,i);a&&this.client.captureEvent(a)}catch(a){console.error("[LightSDK] ErrorPlugin global error handler error:",a)}return!1}}setupUnhandledRejection(){typeof window!="undefined"&&window.addEventListener("unhandledrejection",e=>{try{let t=e.reason,n=this.buildErrorEvent(t);n&&(n.type==="error"&&(n.tags={...n.tags||{},unhandled:"true",promise:"true"}),this.client.captureEvent(n))}catch(t){console.error("[LightSDK] ErrorPlugin unhandledrejection handler error:",t)}})}setupResourceError(){typeof window!="undefined"&&window.addEventListener("error",e=>{var i;let t=e.target;if(!t)return;let n=(i=t.tagName)==null?void 0:i.toLowerCase(),r=t.src||t.href;if(n&&r&&["img","script","link","audio","video"].includes(n))try{this.client.captureEvent({type:"error",level:"warning",message:`Resource load failed: ${n} ${r}`,timestamp:p(),tags:{resource_type:n,resource_url:r},exception:{type:"ResourceError",value:`Failed to load ${n} resource`}})}catch(o){console.error("[LightSDK] ErrorPlugin resource error handler error:",o)}},!0)}buildErrorEvent(e,t,n,r){let i=p();if(e instanceof Error){if(this.shouldIgnoreError(e.message))return null;let c=this.parseStackTrace(e.stack),u=E(e.name,e.message,c);return{type:"error",level:"error",message:e.message,timestamp:i,exception:{type:e.name,value:e.message,stacktrace:{frames:c.slice(0,this.config.maxStackFrames||5)}},fingerprint:u}}let o=String(e);if(this.shouldIgnoreError(o))return null;let a=[];return t&&a.push({filename:t,lineno:n,colno:this.config.captureColumn?r:void 0,in_app:!0}),{type:"error",level:"error",message:o,timestamp:i,exception:{type:"Error",value:o,stacktrace:{frames:a}}}}parseStackTrace(e){if(!e)return[];let t=[],n=e.split(` `),r=typeof location!="undefined"?`${location.protocol}//${location.host}`:"";for(let i of n){let o=i.match(/^\s*at\s*(.+?)\s*\((.+?):(\d+):(\d+)\)\s*$/);if(o){let[,a,c,u,d]=o,f=c.includes("node_modules");if(!this.config.captureNodeModules&&f)continue;let h=c;this.config.relativePathOnly&&r&&c.startsWith(r)&&(h=c.substring(r.length)),t.push({filename:h,function:a,lineno:parseInt(u,10),colno:this.config.captureColumn?parseInt(d,10):void 0,in_app:!f})}else{let a=i.match(/^\s*at\s*(.+?):(\d+):(\d+)\s*$/);if(a){let[,c,u,d]=a,f=c.includes("node_modules");if(!this.config.captureNodeModules&&f)continue;let h=c;this.config.relativePathOnly&&r&&c.startsWith(r)&&(h=c.substring(r.length)),t.push({filename:h,lineno:parseInt(u,10),colno:this.config.captureColumn?parseInt(d,10):void 0,in_app:!f})}}}return t.reverse()}destroy(){}},O=D;var N=class{constructor(){this.name="performance";this.version="1.0.0";this.config={sampleRate:.1,captureLongTasks:!0,captureResources:!1,resourceSampleRate:.01,longTaskSampleRate:.05,captureNavigation:!0,captureFP:!0}}setup(e){this.client=e,this.loadConfig(),this.shouldSample("default")&&(this.observeWebVitals(),this.observeLongTasks(),this.observeNavigation(),this.observeResources())}loadConfig(){let e=this.client.config;e&&v(e.performance)&&(this.config={...this.config,...e.performance})}shouldSample(e="default"){var n,r,i;let t=(n=this.config.sampleRate)!=null?n:.1;return e==="resource"?t=(r=this.config.resourceSampleRate)!=null?r:.01:e==="longtask"&&(t=(i=this.config.longTaskSampleRate)!=null?i:.05),t>=1?!0:t<=0?!1:Math.random(){let n=t.getEntriesByName("first-paint");n.length>0&&this.reportMetric("FP",n[0].startTime,"ms")}).observe({type:"paint",buffered:!0})}catch(e){}}observeLCP(){try{new PerformanceObserver(t=>{let n=t.getEntries(),r=n[n.length-1];if(r){let i=r.renderTime||r.loadTime||r.startTime;this.reportMetric("LCP",i,"ms")}}).observe({type:"largest-contentful-paint",buffered:!0})}catch(e){}}observeFID(){try{new PerformanceObserver(t=>{let n=t.getEntries();if(n.length>0){let r=n[0],i=r.processingStart-r.startTime;this.reportMetric("FID",i,"ms")}}).observe({type:"first-input",buffered:!0})}catch(e){}}observeCLS(){try{let e=0,t=0,n=[];new PerformanceObserver(i=>{let o=i.getEntries();for(let a of o)if(!a.hadRecentInput){let c=n[0],u=n[n.length-1];t&&a.startTime-u.endTime<1e3&&a.startTime-c.startTime<5e3?(t+=a.value||0,n.push(a)):(t=a.value||0,n=[a]),t>e&&(e=t,this.reportMetric("CLS",e,""))}}).observe({type:"layout-shift",buffered:!0})}catch(e){}}observeFCP(){try{new PerformanceObserver(t=>{let n=t.getEntriesByName("first-contentful-paint");n.length>0&&this.reportMetric("FCP",n[0].startTime,"ms")}).observe({type:"paint",buffered:!0})}catch(e){}}observeTTFB(){try{new PerformanceObserver(t=>{let n=t.getEntriesByType("navigation");if(n.length>0){let r=n[0],i=r.responseStart-r.requestStart;this.reportMetric("TTFB",Math.max(0,i),"ms")}}).observe({type:"navigation",buffered:!0})}catch(e){}}observeLongTasks(){if(this.config.captureLongTasks)try{new PerformanceObserver(t=>{let n=t.getEntries();for(let r of n)this.shouldSample("longtask")&&this.reportMetric("longtask",r.duration,"ms")}).observe({type:"longtask",buffered:!0})}catch(e){}}observeNavigation(){this.config.captureNavigation&&typeof performance!="undefined"&&window.addEventListener("load",()=>{setTimeout(()=>{let e=performance.timing;if(!e)return;let t=e.navigationStart,n={dom_ready:e.domContentLoadedEventEnd-t,load_time:e.loadEventEnd-t,dns:e.domainLookupEnd-e.domainLookupStart,tcp:e.connectEnd-e.connectStart,ssl:e.secureConnectionStart>0?e.connectEnd-e.secureConnectionStart:0,ttfb:e.responseStart-e.requestStart,download:e.responseEnd-e.responseStart,dom_parse:e.domInteractive-e.responseEnd};for(let[r,i]of Object.entries(n))i>0&&this.reportMetric(r,i,"ms")},0)})}observeResources(){if(this.config.captureResources&&typeof performance!="undefined")try{new PerformanceObserver(t=>{if(!this.shouldSample("resource"))return;let n=t.getEntriesByType("resource");for(let r of n)r.duration>1e3&&this.reportMetric("resource_slow",r.duration,"ms",{resource_name:r.name.substring(0,200),resource_type:r.initiatorType})}).observe({type:"resource",buffered:!0})}catch(e){}}getRating(e,t){let r={LCP:{good:2500,poor:4e3},FCP:{good:1800,poor:3e3},FP:{good:1800,poor:3e3},FID:{good:100,poor:300},CLS:{good:.1,poor:.25},TTFB:{good:800,poor:1800}}[e];return!r||t<=r.good?"good":t<=r.poor?"needs-improvement":"poor"}reportMetric(e,t,n,r={}){let i=this.getRating(e,t),o={type:"performance",level:"info",metric:e,value:Math.round(t*100)/100,unit:n,rating:i,timestamp:p(),tags:{metric:e,rating:i,...r}};this.client.captureEvent(o)}destroy(){}},F=N;var q=class{constructor(){this.name="network";this.version="1.0.0";this.config={captureSuccess:!1,captureBody:!1,captureRequestBody:!1,captureResponseBody:!1,captureRequestHeaders:["content-type","user-agent"],captureResponseHeaders:["content-type","content-length"],errorSampleRate:1,successSampleRate:.01,slowThreshold:3e3,slowSampleRate:1,ignoreStatusCodes:[]}}setup(e){this.client=e,this.loadConfig(),this.patchFetch(),this.patchXHR()}loadConfig(){let e=this.client.config;e&&v(e.network)&&(this.config={...this.config,...e.network}),e.ignoreUrls&&(this.config.ignoreUrls=[...this.config.ignoreUrls||[],...e.ignoreUrls])}shouldIgnore(e){return w(e,this.config.ignoreUrls||[])}shouldSample(e,t){var r,i,o,a;let n=e?(r=this.config.errorSampleRate)!=null?r:1:(i=this.config.successSampleRate)!=null?i:.01;return!e&&t>=((o=this.config.slowThreshold)!=null?o:3e3)&&(n=(a=this.config.slowSampleRate)!=null?a:1),n>=1?!0:n<=0?!1:Math.random(){var y;let d=p()-r,f=u.ok,h=u.status;return(y=e.config.ignoreStatusCodes)!=null&&y.includes(h)||!e.shouldSample(!f,d)||(!f||e.config.captureSuccess)&&e.reportNetwork({sub_type:"fetch",method:o.toUpperCase(),url:a,status_code:h,duration:d,success:f,error:f?void 0:`HTTP ${h}`}),u},u=>{let d=p()-r;throw e.shouldSample(!0,d)&&e.reportNetwork({sub_type:"fetch",method:o.toUpperCase(),url:a,duration:d,success:!1,error:(u==null?void 0:u.message)||"Network error"}),u}),c}}patchXHR(){if(typeof XMLHttpRequest=="undefined")return;this.originalXHROpen=XMLHttpRequest.prototype.open,this.originalXHRSend=XMLHttpRequest.prototype.send;let e=this;XMLHttpRequest.prototype.open=function(t,n){return this._lightMethod=t,this._lightUrl=typeof n=="string"?n:n.toString(),e.originalXHROpen.apply(this,arguments)},XMLHttpRequest.prototype.send=function(t){let n=p(),r=this._lightMethod||"GET",i=this._lightUrl||"";if(e.shouldIgnore(i))return e.originalXHRSend.apply(this,arguments);let o=M(i),a=0;t&&typeof t=="string"&&(a=t.length);let c=()=>{var y;let u=p()-n,d=this.status,f=d>=200&&d<300;if((y=e.config.ignoreStatusCodes)!=null&&y.includes(d)){this.removeEventListener("loadend",c);return}if(!e.shouldSample(!f,u)){this.removeEventListener("loadend",c);return}if(f&&!e.config.captureSuccess){this.removeEventListener("loadend",c);return}let h=0;try{let P=this.getResponseHeader("content-length");P&&(h=parseInt(P,10)),!h&&this.responseText&&(h=this.responseText.length)}catch(P){}e.reportNetwork({sub_type:"xhr",method:r.toUpperCase(),url:o,status_code:d,duration:u,request_size:a||void 0,response_size:h||void 0,success:f,error:f?void 0:`HTTP ${d}`}),this.removeEventListener("loadend",c)};return this.addEventListener("loadend",c),e.originalXHRSend.apply(this,arguments)}}reportNetwork(e){let t={type:"network",level:e.success?"info":"error",timestamp:p(),tags:{method:e.method,sub_type:e.sub_type,success:String(e.success)},...e};this.client.captureEvent(t)}destroy(){this.originalFetch&&(window.fetch=this.originalFetch),this.originalXHROpen&&(XMLHttpRequest.prototype.open=this.originalXHROpen),this.originalXHRSend&&(XMLHttpRequest.prototype.send=this.originalXHRSend)}},U=q;var H=class{constructor(){this.name="behavior";this.version="1.0.0";this.config={capturePV:!0,captureClick:!0,captureRoute:!0,captureDuration:!0,captureScroll:!0,clickThrottle:300,scrollThrottle:1e3,sampleRate:.1};this.lastClickTime=0;this.lastScrollTime=0;this.maxScrollDepth=0;this.pageEnterTime=0;this.scrollReported=!1}setup(e){this.client=e,this.loadConfig(),this.shouldSample()&&(this.config.capturePV&&this.trackPV(),this.config.captureClick&&this.trackClick(),this.config.captureRoute&&this.trackRoute(),this.config.captureDuration&&this.trackPageDuration(),this.config.captureScroll&&this.trackScroll())}loadConfig(){let e=this.client.config;e&&v(e.behavior)&&(this.config={...this.config,...e.behavior})}shouldSample(){var t;let e=(t=this.config.sampleRate)!=null?t:.1;return e>=1?!0:e<=0?!1:Math.random(){var a,c,u;let t=p(),n=(a=this.config.clickThrottle)!=null?a:300;if(t-this.lastClickTime{let i=g();if(i!==e){let o=e,a=i;e=i,this.reportBehavior({sub_type:"route",page_url:a,referrer:o,properties:{from:o,to:a}}),this.pageEnterTime=p(),this.maxScrollDepth=0,this.scrollReported=!1}},n=history.pushState,r=history.replaceState;history.pushState=function(){let i=n.apply(this,arguments);return setTimeout(t,0),i},history.replaceState=function(){let i=r.apply(this,arguments);return setTimeout(t,0),i},window.addEventListener("popstate",()=>{setTimeout(t,0)}),window.addEventListener("hashchange",()=>{setTimeout(t,0)})}trackPageDuration(){if(typeof window=="undefined")return;this.pageEnterTime=p();let e=()=>{let t=p()-this.pageEnterTime;t>1e3&&(this.config.captureScroll&&!this.scrollReported&&this.reportScroll(),this.reportBehavior({sub_type:"duration",page_url:g(),properties:{duration:t,max_scroll_depth:this.maxScrollDepth}}))};document.addEventListener("visibilitychange",()=>{document.hidden?e():this.pageEnterTime=p()}),window.addEventListener("beforeunload",e),window.addEventListener("pagehide",e)}trackScroll(){if(typeof window=="undefined")return;let e=()=>{var i;let t=p(),n=(i=this.config.scrollThrottle)!=null?i:1e3;if(t-this.lastScrollTimethis.maxScrollDepth&&(this.maxScrollDepth=r)};window.addEventListener("scroll",e,{passive:!0})}reportScroll(){this.scrollReported||(this.scrollReported=!0,this.reportBehavior({sub_type:"scroll",page_url:g(),properties:{max_depth:this.maxScrollDepth}}))}reportBehavior(e){let t={type:"behavior",level:"info",timestamp:p(),tags:{sub_type:e.sub_type,page_url:g()},...e};this.client.captureEvent(t)}destroy(){}},$=H;var Se="light-sentry-offline",m="events",W=1e3,j=class{constructor(){this.name="offline";this.version="1.0.0";this.config={maxEvents:W};this.db=null;this.isOnline=!0;this.isSyncing=!1;this.pendingEvents=[]}setup(e){this.client=e,this.loadConfig(),this.initDatabase(),this.setupNetworkListeners()}loadConfig(){let e=this.client.config;e&&typeof e.offline=="object"&&(this.config={...this.config,...e.offline})}async initDatabase(){if(typeof indexedDB=="undefined"){console.warn("[LightSDK] OfflinePlugin: IndexedDB not available");return}return new Promise((e,t)=>{let n=indexedDB.open(Se,1);n.onerror=()=>{console.warn("[LightSDK] OfflinePlugin: Failed to open IndexedDB"),t(n.error)},n.onsuccess=()=>{this.db=n.result,e()},n.onupgradeneeded=r=>{let i=r.target.result;i.objectStoreNames.contains(m)||i.createObjectStore(m,{keyPath:"id"}).createIndex("timestamp","timestamp",{unique:!1})}})}setupNetworkListeners(){typeof window!="undefined"&&(this.isOnline=navigator.onLine,window.addEventListener("online",()=>{console.info("[LightSDK] OfflinePlugin: Network online"),this.isOnline=!0,this.syncPendingEvents()}),window.addEventListener("offline",()=>{console.info("[LightSDK] OfflinePlugin: Network offline"),this.isOnline=!1}))}generateId(){return`${Date.now()}-${Math.random().toString(36).substring(2,11)}`}async saveToIndexedDB(e){if(this.db)return new Promise((t,n)=>{let i=this.db.transaction([m],"readwrite").objectStore(m),o=i.count();o.onsuccess=async()=>{let a=o.result;a>=(this.config.maxEvents||W)&&await this.deleteOldestEvents(a-(this.config.maxEvents||W)+1);let c={id:this.generateId(),event:{...e,offline:!0},timestamp:p()},u=i.add(c);u.onsuccess=()=>t(),u.onerror=()=>n(u.error)}})}async deleteOldestEvents(e){if(!(!this.db||e<=0))return new Promise((t,n)=>{let a=this.db.transaction([m],"readwrite").objectStore(m).index("timestamp").openCursor(),c=0;a.onsuccess=u=>{let d=u.target.result;d&&cn(a.error)})}async getAllStoredEvents(){return this.db?new Promise((e,t)=>{let o=this.db.transaction([m],"readonly").objectStore(m).index("timestamp").getAll();o.onsuccess=()=>{let a=o.result||[];a.sort((c,u)=>c.timestamp-u.timestamp),e(a)},o.onerror=()=>t(o.error)}):[]}async clearStoredEvents(){if(this.db)return new Promise((e,t)=>{let i=this.db.transaction([m],"readwrite").objectStore(m).clear();i.onsuccess=()=>e(),i.onerror=()=>t(i.error)})}async syncPendingEvents(){if(!(!this.isOnline||this.isSyncing)){this.isSyncing=!0,console.info("[LightSDK] OfflinePlugin: Syncing pending events");try{let e=await this.getAllStoredEvents();if(e.length===0){console.info("[LightSDK] OfflinePlugin: No pending events to sync"),this.isSyncing=!1;return}let t=50;for(let n=0;no.event);try{await(async()=>new Promise((a,c)=>{this.client.emit("sync:offline",i),a()}))(),console.info(`[LightSDK] OfflinePlugin: Synced ${r.length} events`)}catch(o){console.error("[LightSDK] OfflinePlugin: Failed to sync batch",o)}}await this.clearStoredEvents(),console.info("[LightSDK] OfflinePlugin: All pending events synced")}catch(e){console.error("[LightSDK] OfflinePlugin: Sync failed",e)}finally{this.isSyncing=!1}}}beforeReport(e){if(!this.isOnline)return this.saveToIndexedDB(e).catch(n=>{console.error("[LightSDK] OfflinePlugin: Failed to save event offline",n)}),null;let t={...e};return delete t.offline,t}destroy(){this.db&&(this.db.close(),this.db=null)}},K=j;var l=null;function J(s){var r;let e=new B(s),t=[new O,new K],n=((r=s.plugins)==null?void 0:r.filter(i=>typeof i=="string"))||[];(n.includes("performance")||n.includes("all"))&&t.push(new F),(n.includes("network")||n.includes("all"))&&t.push(new U),(n.includes("behavior")||n.includes("all"))&&t.push(new $);for(let i of t)e.use(i);if(s.plugins)for(let i of s.plugins)typeof i=="object"&&i!==null&&"name"in i&&"setup"in i&&e.use(i);return e.init(),l=e,e}function Z(){return l}function Y(s){l==null||l.captureException(s)}function ee(s,e){l==null||l.captureMessage(s,e)}function te(s){l==null||l.captureEvent(s)}function ne(s){l==null||l.setUser(s)}function re(s,e){l==null||l.setTag(s,e)}function ie(s){l==null||l.setTags(s)}function se(s,e){l==null||l.setExtra(s,e)}function oe(s){l==null||l.addBreadcrumb(s)}async function ae(){await(l==null?void 0:l.flush())}function ce(){l==null||l.disable()}function ue(){l==null||l.enable()}var xe={init:J,getClient:Z,captureException:Y,captureMessage:ee,captureEvent:te,setUser:ne,setTag:re,setTags:ie,setExtra:se,addBreadcrumb:oe,flush:ae,disable:ce,enable:ue};