@feiyangdefeng/sdk 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -8
- package/dist/collector/auto-tracker.d.ts +6 -0
- package/dist/collector/auto-tracker.d.ts.map +1 -1
- package/dist/collector/click-event-dispatcher.d.ts +8 -0
- package/dist/collector/click-event-dispatcher.d.ts.map +1 -0
- package/dist/collector/click-event-factory.d.ts +23 -0
- package/dist/collector/click-event-factory.d.ts.map +1 -0
- package/dist/collector/click-tracker.d.ts +14 -5
- package/dist/collector/click-tracker.d.ts.map +1 -1
- package/dist/collector/error-tracker.d.ts.map +1 -1
- package/dist/collector/exposure-tracker.d.ts.map +1 -1
- package/dist/collector/input-tracker.d.ts +14 -1
- package/dist/collector/input-tracker.d.ts.map +1 -1
- package/dist/collector/performance-tracker.d.ts.map +1 -1
- package/dist/collector/touch-interaction-tracker.d.ts +20 -0
- package/dist/collector/touch-interaction-tracker.d.ts.map +1 -0
- package/dist/collector/view-tracker.d.ts.map +1 -1
- package/dist/core/capabilities.d.ts +16 -0
- package/dist/core/capabilities.d.ts.map +1 -0
- package/dist/core/component-info-sanitize.d.ts +10 -0
- package/dist/core/component-info-sanitize.d.ts.map +1 -0
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/panel-manager.d.ts +27 -0
- package/dist/core/panel-manager.d.ts.map +1 -0
- package/dist/core/request.d.ts +3 -0
- package/dist/core/request.d.ts.map +1 -1
- package/dist/core/utils.d.ts +9 -0
- package/dist/core/utils.d.ts.map +1 -1
- package/dist/core/vue-utils.d.ts +58 -0
- package/dist/core/vue-utils.d.ts.map +1 -0
- package/dist/extension/frame-adapters/angular-adapter.d.ts +16 -0
- package/dist/extension/frame-adapters/angular-adapter.d.ts.map +1 -0
- package/dist/extension/frame-adapters/component-resolvers.d.ts +9 -0
- package/dist/extension/frame-adapters/component-resolvers.d.ts.map +1 -0
- package/dist/extension/frame-adapters/dom-context.d.ts +6 -0
- package/dist/extension/frame-adapters/dom-context.d.ts.map +1 -0
- package/dist/extension/frame-adapters/dom-data.d.ts +7 -0
- package/dist/extension/frame-adapters/dom-data.d.ts.map +1 -0
- package/dist/extension/frame-adapters/react-adapter.d.ts +12 -0
- package/dist/extension/frame-adapters/react-adapter.d.ts.map +1 -0
- package/dist/extension/frame-adapters/react-fiber-dom.d.ts +7 -0
- package/dist/extension/frame-adapters/react-fiber-dom.d.ts.map +1 -0
- package/dist/extension/frame-adapters/react-fiber-internal.d.ts +19 -0
- package/dist/extension/frame-adapters/react-fiber-internal.d.ts.map +1 -0
- package/dist/extension/frame-adapters/resolve.d.ts +7 -0
- package/dist/extension/frame-adapters/resolve.d.ts.map +1 -0
- package/dist/extension/frame-adapters/ui-lib-heuristics.d.ts +7 -0
- package/dist/extension/frame-adapters/ui-lib-heuristics.d.ts.map +1 -0
- package/dist/extension/naive-ui-tracker.d.ts +20 -0
- package/dist/extension/naive-ui-tracker.d.ts.map +1 -0
- package/dist/extension/performance-alert-engine.d.ts +16 -0
- package/dist/extension/performance-alert-engine.d.ts.map +1 -0
- package/dist/extension/performance-cleanup-scheduler.d.ts +8 -0
- package/dist/extension/performance-cleanup-scheduler.d.ts.map +1 -0
- package/dist/extension/performance-metrics-aggregator.d.ts +11 -0
- package/dist/extension/performance-metrics-aggregator.d.ts.map +1 -0
- package/dist/extension/performance-monitor-storage.d.ts +16 -0
- package/dist/extension/performance-monitor-storage.d.ts.map +1 -0
- package/dist/extension/performance-monitor.d.ts +88 -0
- package/dist/extension/performance-monitor.d.ts.map +1 -0
- package/dist/extension/plugin-lifecycle.d.ts +9 -0
- package/dist/extension/plugin-lifecycle.d.ts.map +1 -0
- package/dist/extension/plugin-manager.d.ts +3 -0
- package/dist/extension/plugin-manager.d.ts.map +1 -1
- package/dist/extension/session-replay-budget.d.ts +20 -0
- package/dist/extension/session-replay-budget.d.ts.map +1 -0
- package/dist/extension/session-replay-interaction-lifecycle.d.ts +23 -0
- package/dist/extension/session-replay-interaction-lifecycle.d.ts.map +1 -0
- package/dist/extension/session-replay-store.d.ts +25 -0
- package/dist/extension/session-replay-store.d.ts.map +1 -0
- package/dist/extension/session-replay.d.ts +17 -29
- package/dist/extension/session-replay.d.ts.map +1 -1
- package/dist/extension/user-action-sequence.d.ts +151 -0
- package/dist/extension/user-action-sequence.d.ts.map +1 -0
- package/dist/extension/vue-integration.d.ts +28 -0
- package/dist/extension/vue-integration.d.ts.map +1 -0
- package/dist/extension/vue-plugin.d.ts +66 -0
- package/dist/extension/vue-plugin.d.ts.map +1 -0
- package/dist/index.d.ts +21 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.es.js +10069 -6046
- package/dist/index.es.js.map +1 -1
- package/dist/index.iife.js +2 -2
- package/dist/index.iife.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/panels/offline-storage-viewer.html.d.ts +6 -0
- package/dist/panels/offline-storage-viewer.html.d.ts.map +1 -0
- package/dist/panels/performance-panel.html.d.ts +6 -0
- package/dist/panels/performance-panel.html.d.ts.map +1 -0
- package/dist/processor/data-processor.d.ts +3 -1
- package/dist/processor/data-processor.d.ts.map +1 -1
- package/dist/processor/deduplicator.d.ts.map +1 -1
- package/dist/processor/pipeline-context.d.ts +8 -0
- package/dist/processor/pipeline-context.d.ts.map +1 -0
- package/dist/processor/processor-pipeline.d.ts +11 -0
- package/dist/processor/processor-pipeline.d.ts.map +1 -0
- package/dist/processor/processor-stage.d.ts +8 -0
- package/dist/processor/processor-stage.d.ts.map +1 -0
- package/dist/processor/stages/compress-stage.d.ts +12 -0
- package/dist/processor/stages/compress-stage.d.ts.map +1 -0
- package/dist/processor/stages/deduplicate-stage.d.ts +12 -0
- package/dist/processor/stages/deduplicate-stage.d.ts.map +1 -0
- package/dist/processor/stages/sample-stage.d.ts +12 -0
- package/dist/processor/stages/sample-stage.d.ts.map +1 -0
- package/dist/runtime/tracker-config-coordinator.d.ts +22 -0
- package/dist/runtime/tracker-config-coordinator.d.ts.map +1 -0
- package/dist/runtime/tracker-event-bus-bridge.d.ts +20 -0
- package/dist/runtime/tracker-event-bus-bridge.d.ts.map +1 -0
- package/dist/runtime/tracker-event-dispatcher.d.ts +31 -0
- package/dist/runtime/tracker-event-dispatcher.d.ts.map +1 -0
- package/dist/runtime/tracker-event-enricher.d.ts +14 -0
- package/dist/runtime/tracker-event-enricher.d.ts.map +1 -0
- package/dist/runtime/tracker-feature-registry.d.ts +26 -0
- package/dist/runtime/tracker-feature-registry.d.ts.map +1 -0
- package/dist/runtime/tracker-plugin-context.d.ts +11 -0
- package/dist/runtime/tracker-plugin-context.d.ts.map +1 -0
- package/dist/tracker.d.ts +29 -12
- package/dist/tracker.d.ts.map +1 -1
- package/dist/transport/batch-sender-state.d.ts +3 -0
- package/dist/transport/batch-sender-state.d.ts.map +1 -0
- package/dist/transport/batch-sender.d.ts +24 -12
- package/dist/transport/batch-sender.d.ts.map +1 -1
- package/dist/transport/delivery-coordinator.d.ts +18 -0
- package/dist/transport/delivery-coordinator.d.ts.map +1 -0
- package/dist/transport/event-queue.d.ts +20 -0
- package/dist/transport/event-queue.d.ts.map +1 -0
- package/dist/transport/flush-scheduler.d.ts +19 -0
- package/dist/transport/flush-scheduler.d.ts.map +1 -0
- package/dist/transport/offline-recovery-manager.d.ts +17 -0
- package/dist/transport/offline-recovery-manager.d.ts.map +1 -0
- package/dist/transport/offline-storage.d.ts +1 -1
- package/dist/transport/offline-storage.d.ts.map +1 -1
- package/dist/transport/retry-handler.d.ts.map +1 -1
- package/dist/transport/sender.d.ts +8 -1
- package/dist/transport/sender.d.ts.map +1 -1
- package/docs/ARCHITECTURE_MAP.md +476 -0
- package/docs/BROWSER_SUPPORT.md +15 -0
- package/docs/ENGINEERING_OVERVIEW.md +154 -0
- package/docs/ERROR_SCENARIO_EVALUATION.md +124 -0
- package/docs/FRAME_ADAPTERS.md +70 -0
- package/docs/FRAME_ADAPTERS_GUIDE.md +195 -0
- package/docs/MINIPROGRAM.md +11 -0
- package/docs/OPTIMIZATION_PLAN.md +123 -0
- package/docs/PERFORMANCE_BASELINE.md +181 -0
- package/docs/README.md +30 -0
- package/docs/UI_LIB_COMPAT.md +31 -0
- package/docs/USAGE.md +4064 -0
- package/docs/VIEW_LOCAL_CACHE_AND_PROFILE.md +252 -0
- package/docs/VUE3_INTEGRATION.md +528 -0
- package/examples/README.md +54 -0
- package/examples/reference/user-action-profile.ts +446 -0
- package/examples/reference/user-profile-backend.ts +397 -0
- package/examples/reference/vue3-naive-ui-example.vue +211 -0
- package/package.json +39 -8
- package/tests/README.md +203 -0
package/dist/index.umd.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TrackerSDK={})}(this,function(e){"use strict";var t=Object.defineProperty,r=(e,r,s)=>((e,r,s)=>r in e?t(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s)(e,"symbol"!=typeof r?r+"":r,s);const s={appId:"",serverUrl:void 0,enableAutoTrack:!0,enableErrorTrack:!0,enablePerformanceTrack:!1,enableSessionReplay:!1,batchSize:10,batchWait:5e3,sampleRate:1,enableOfflineStorage:!0,maxOfflineStorageSize:1e3,maxRetries:3,userId:"",deviceId:"",customProperties:{}};class n{constructor(e){r(this,"config"),this.config={...s,...e,customProperties:{...s.customProperties,...e.customProperties}}}get(e){return this.config[e]}getAll(){return{...this.config}}set(e,t){this.config[e]=t}update(e){this.config={...this.config,...e,customProperties:{...this.config.customProperties,...e.customProperties||{}}}}}const i=new class{constructor(){r(this,"events",new Map)}on(e,t){this.events.has(e)||this.events.set(e,[]),this.events.get(e).push(t)}off(e,t){if(!this.events.has(e))return;if(!t)return void this.events.delete(e);const r=this.events.get(e),s=r.indexOf(t);s>-1&&r.splice(s,1)}emit(e,...t){if(!this.events.has(e))return;this.events.get(e).forEach(r=>{try{r(...t)}catch(s){console.error(`EventBus: Error in callback for event "${e}":`,s)}})}once(e,t){const r=(...s)=>{t(...s),this.off(e,r)};this.on(e,r)}clear(){this.events.clear()}};function a(){return`${Date.now()}-${Math.random().toString(36).substring(2,9)}`}function o(){return"undefined"==typeof window?"":window.location.href}function l(){return"undefined"==typeof window?"":document.title||""}function c(e,t){let r=null;return function(...s){r&&clearTimeout(r),r=setTimeout(()=>{r=null,e(...s)},t)}}function h(e,t){let r=null,s=0;return function(...n){const i=Date.now(),a=t-(i-s);a<=0||a>t?(r&&(clearTimeout(r),r=null),s=i,e(...n)):r||(r=setTimeout(()=>{s=Date.now(),r=null,e(...n)},a))}}function d(e){if(null===e||"object"!=typeof e)return e;if(e instanceof Date)return new Date(e.getTime());if(e instanceof Array)return e.map(e=>d(e));if("object"==typeof e){const t={};for(const r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=d(e[r]));return t}return e}function u(e){if(!e)return"";const t=[];for(;e&&e.nodeType===Node.ELEMENT_NODE;){let r=e.nodeName.toLowerCase();if(e.id){r+=`#${e.id}`,t.unshift(r);break}if(e.className){const t=e.className.trim().split(/\s+/).filter(e=>e.length>0).join(".");t&&(r+=`.${t}`)}let s=e,n=1;for(;s=s.previousElementSibling;)s.nodeName===e.nodeName&&n++;n>1&&(r+=`:nth-of-type(${n})`),t.unshift(r),e=e.parentElement}return t.join(" > ")}function f(e){var t;return e?{tagName:e.tagName.toLowerCase(),id:e.id||void 0,className:e.className&&"string"==typeof e.className?e.className:void 0,text:(null==(t=e.textContent)?void 0:t.trim().substring(0,100))||void 0}:{}}class p{constructor(){r(this,"startTime",Date.now()),r(this,"currentUrl",""),r(this,"popstateHandler",null),r(this,"visibilityChangeHandler",null),r(this,"beforeUnloadHandler",null),r(this,"isTracking",!1),r(this,"pendingUrlCheck",null),r(this,"lastPageViewTime",0),r(this,"minPageViewInterval",1e3),r(this,"hiddenStartTime",null),r(this,"totalHiddenTime",0),r(this,"isVisible",!0)}init(){this.trackPageView(),this.setupSPARouter(),this.setupPageLifecycle()}trackPageView(){if(this.isTracking)return{type:"pageview",name:"pageview",timestamp:Date.now(),url:this.currentUrl||o(),title:l()};this.isTracking=!0;try{const e=Date.now(),t=o(),r=l(),s="undefined"==typeof window?"":document.referrer||"",n=t!==this.currentUrl||""===this.currentUrl;if(!n&&this.lastPageViewTime>0){if(e-this.lastPageViewTime<this.minPageViewInterval)return{type:"pageview",name:"pageview",timestamp:e,url:this.currentUrl,title:r}}const i=this.currentUrl?e-this.startTime-this.totalHiddenTime:0,a=i>0?i:0,c={type:"pageview",name:"pageview",timestamp:e,url:t,title:r,referrer:this.currentUrl?s:void 0,duration:a>0?a:void 0};return n&&(this.startTime=e,this.currentUrl=t,this.totalHiddenTime=0),this.lastPageViewTime=e,"undefined"!=typeof window&&window.__trackerEventBus&&window.__trackerEventBus.emit("pageview",c),c}finally{setTimeout(()=>{this.isTracking=!1},0)}}setupSPARouter(){if("undefined"==typeof window)return;this.popstateHandler=()=>{this.trackPageView()},window.addEventListener("popstate",this.popstateHandler);const e=history;if(!e._trackerPushStateWrapped){const t=history.pushState.bind(history);e._originalPushState=t,e._trackerPushStateWrapped=!0;const r=this;history.pushState=function(...e){const s=t.apply(history,e);return r.pendingUrlCheck&&clearTimeout(r.pendingUrlCheck),r.pendingUrlCheck=setTimeout(()=>{o()!==r.currentUrl&&r.trackPageView(),r.pendingUrlCheck=null},100),s}}if(!e._trackerReplaceStateWrapped){const t=history.replaceState.bind(history);e._originalReplaceState=t,e._trackerReplaceStateWrapped=!0;const r=this;history.replaceState=function(...e){const s=t.apply(history,e);return r.pendingUrlCheck&&clearTimeout(r.pendingUrlCheck),r.pendingUrlCheck=setTimeout(()=>{o()!==r.currentUrl&&r.trackPageView(),r.pendingUrlCheck=null},100),s}}}setupPageLifecycle(){"undefined"!=typeof document&&(this.visibilityChangeHandler=()=>{const e=document.hidden,t=Date.now();e&&this.isVisible?(this.hiddenStartTime=t,this.isVisible=!1):e||this.isVisible||(this.hiddenStartTime&&(this.totalHiddenTime+=t-this.hiddenStartTime,this.hiddenStartTime=null),this.isVisible=!0)},document.addEventListener("visibilitychange",this.visibilityChangeHandler),this.beforeUnloadHandler=()=>{const e=Date.now();this.hiddenStartTime&&(this.totalHiddenTime+=e-this.hiddenStartTime,this.hiddenStartTime=null);const t=this.currentUrl?e-this.startTime-this.totalHiddenTime:0;if(t>0&&this.currentUrl)try{const r={type:"pageview",name:"page-before-unload",timestamp:e,url:this.currentUrl,title:l(),duration:t};"undefined"!=typeof window&&window.__trackerEventBus&&window.__trackerEventBus.emit("pageview",r)}catch(r){console.error("ViewTracker: Error sending final pageview event:",r)}},window.addEventListener("beforeunload",this.beforeUnloadHandler))}destroy(){if(this.pendingUrlCheck&&(clearTimeout(this.pendingUrlCheck),this.pendingUrlCheck=null),this.popstateHandler&&"undefined"!=typeof window&&(window.removeEventListener("popstate",this.popstateHandler),this.popstateHandler=null),this.visibilityChangeHandler&&"undefined"!=typeof document&&(document.removeEventListener("visibilitychange",this.visibilityChangeHandler),this.visibilityChangeHandler=null),this.beforeUnloadHandler&&"undefined"!=typeof window&&(window.removeEventListener("beforeunload",this.beforeUnloadHandler),this.beforeUnloadHandler=null),"undefined"!=typeof window){const e=history;e._trackerPushStateWrapped&&e._originalPushState&&(history.pushState=e._originalPushState,e._trackerPushStateWrapped=!1,delete e._originalPushState),e._trackerReplaceStateWrapped&&e._originalReplaceState&&(history.replaceState=e._originalReplaceState,e._trackerReplaceStateWrapped=!1,delete e._originalReplaceState)}}}class m{constructor(){r(this,"clickHandler",null),r(this,"touchStartHandler",null),r(this,"touchEndHandler",null),r(this,"debounceTime",300),r(this,"touchTimeout",null),r(this,"lastTouch",null),r(this,"TOUCH_CLICK_THRESHOLD",300),r(this,"TOUCH_DISTANCE_THRESHOLD",10)}init(e){"undefined"!=typeof window&&(void 0!==e&&(this.debounceTime=e),this.clickHandler=c((...e)=>{const t=e[0];this.handleClick(t)},this.debounceTime),this.touchStartHandler=e=>{this.handleTouch(e)},this.touchEndHandler=c((...e)=>{const t=e[0];this.handleTouch(t)},this.debounceTime),document.addEventListener("click",this.clickHandler,!1),document.addEventListener("touchstart",this.touchStartHandler,{passive:!0,capture:!1}),document.addEventListener("touchend",this.touchEndHandler,{passive:!0,capture:!1}))}handleTouch(e){try{const t=Date.now();switch(e.type){case"touchstart":if(e.touches.length>0){const r=e.touches[0];this.lastTouch={x:r.clientX,y:r.clientY,time:t}}break;case"touchend":if(this.lastTouch&&e.changedTouches.length>0){const r=e.changedTouches[0],s=Math.abs(r.clientX-this.lastTouch.x),n=Math.abs(r.clientY-this.lastTouch.y);t-this.lastTouch.time<this.TOUCH_CLICK_THRESHOLD&&s<this.TOUCH_DISTANCE_THRESHOLD&&n<this.TOUCH_DISTANCE_THRESHOLD&&(this.touchTimeout&&clearTimeout(this.touchTimeout),this.touchTimeout=window.setTimeout(()=>{try{this.processTouchInteraction(r,e.target)}catch(t){console.error("ClickTracker: Error processing touch interaction:",t)}this.touchTimeout=null},100)),this.lastTouch=null}}}catch(t){console.error("ClickTracker: Error handling touch event:",t)}}processTouchInteraction(e,t){if(!t)return;const r=o(),s=l(),n=Date.now(),i={x:e.clientX,y:e.clientY},a=()=>{try{const e=u(t),a=f(t),o={type:"click",name:"touch-click",timestamp:n,url:r,title:s,elementPath:e,elementInfo:a,position:i,interactionType:"touch"};"undefined"!=typeof window&&window.__trackerEventBus&&window.__trackerEventBus.emit("click",o)}catch(e){console.error("ClickTracker: Error processing touch interaction:",e)}};"undefined"!=typeof requestIdleCallback?requestIdleCallback(a,{timeout:50}):setTimeout(a,0)}handleClick(e){try{const t=e.target;if(!t)return;const r=o(),s=l(),n=Date.now(),i={x:e.clientX,y:e.clientY},a=()=>{try{const e=u(t),a=f(t),o={type:"click",name:"click",timestamp:n,url:r,title:s,elementPath:e,elementInfo:a,position:i,interactionType:"mouse"};"undefined"!=typeof window&&window.__trackerEventBus&&window.__trackerEventBus.emit("click",o)}catch(e){console.error("ClickTracker: Error processing click event:",e)}};"undefined"!=typeof requestIdleCallback?requestIdleCallback(a,{timeout:100}):setTimeout(a,0)}catch(t){console.error("ClickTracker: Error handling click event:",t)}}getClickEvent(e){try{const t=e.target;return t?{type:"click",name:"click",timestamp:Date.now(),url:o(),title:l(),elementPath:u(t),elementInfo:f(t),position:{x:e.clientX,y:e.clientY},interactionType:"mouse"}:null}catch(t){return console.error("ClickTracker: Error creating click event:",t),null}}destroy(){this.clickHandler&&"undefined"!=typeof document&&(document.removeEventListener("click",this.clickHandler,!1),this.clickHandler=null),this.touchStartHandler&&"undefined"!=typeof document&&(document.removeEventListener("touchstart",this.touchStartHandler),this.touchStartHandler=null),this.touchEndHandler&&"undefined"!=typeof document&&(document.removeEventListener("touchend",this.touchEndHandler),this.touchEndHandler=null),this.touchTimeout&&(clearTimeout(this.touchTimeout),this.touchTimeout=null),this.lastTouch=null}}class g{constructor(e={}){r(this,"observer",null),r(this,"exposedElements",new Set),r(this,"options"),r(this,"exposureMap",new Map),r(this,"scrollFallbackHandler",null),r(this,"resizeFallbackHandler",null),r(this,"cachedElements",[]),r(this,"lastCacheUpdate",0),r(this,"CACHE_UPDATE_INTERVAL",2e3),this.options={threshold:.5,root:null,rootMargin:"0px",...e}}init(){"undefined"!=typeof window&&window.IntersectionObserver?(this.observer=new IntersectionObserver(h((...e)=>{e[0].forEach(e=>{this.handleIntersection(e)})},100),{threshold:this.options.threshold||.5,root:this.options.root,rootMargin:this.options.rootMargin}),this.observeElements()):this.initScrollFallback()}observeElements(){if(!this.observer||"undefined"==typeof document)return;const e=document.querySelectorAll("[data-track-exposure]");e.forEach(e=>{this.observer.observe(e)}),this.cachedElements=Array.from(e),this.lastCacheUpdate=Date.now()}observe(e){this.observer&&(this.observer.observe(e),this.cachedElements.includes(e)||(this.cachedElements.push(e),this.lastCacheUpdate=Date.now()))}unobserve(e){if(!this.observer)return;this.observer.unobserve(e),this.exposedElements.delete(e),this.exposureMap.delete(e);const t=this.cachedElements.indexOf(e);t>-1&&(this.cachedElements.splice(t,1),this.lastCacheUpdate=Date.now())}handleIntersection(e){const{target:t,intersectionRatio:r,isIntersecting:s}=e;if(s&&r>=(this.options.threshold||.5))this.exposedElements.has(t)||(this.exposedElements.add(t),this.triggerExposure(t)),this.exposureMap.set(t,Date.now());else if(!s){const e=this.exposureMap.get(t);if(e){const r=Date.now()-e;this.triggerExposure(t,r),this.exposureMap.delete(t),this.exposedElements.delete(t)}}}triggerExposure(e,t){try{const r={type:"exposure",name:"exposure",timestamp:Date.now(),url:o(),title:l(),elementPath:u(e),duration:t};"undefined"!=typeof window&&window.__trackerEventBus&&window.__trackerEventBus.emit("exposure",r)}catch(r){console.error("ExposureTracker: Error triggering exposure event:",r)}}getExposureElements(){const e=Date.now();return(0===this.cachedElements.length||e-this.lastCacheUpdate>this.CACHE_UPDATE_INTERVAL)&&"undefined"!=typeof document&&(this.cachedElements=Array.from(document.querySelectorAll("[data-track-exposure]")),this.lastCacheUpdate=e),this.cachedElements}initScrollFallback(){if("undefined"==typeof window)return;this.cachedElements=Array.from(document.querySelectorAll("[data-track-exposure]")),this.lastCacheUpdate=Date.now();const e=h(()=>{const e=this.getExposureElements(),t=Date.now();e.forEach(e=>{const r=e.getBoundingClientRect(),s=window.innerHeight||document.documentElement.clientHeight,n=window.innerWidth||document.documentElement.clientWidth,i=(Math.min(r.bottom,s)-Math.max(r.top,0))*(Math.min(r.right,n)-Math.max(r.left,0)),a=r.height*r.width;if((a>0?i/a:0)>=(this.options.threshold||.5))this.exposedElements.has(e)||(this.exposedElements.add(e),this.exposureMap.set(e,t),this.triggerExposure(e));else if(this.exposedElements.has(e)){const r=this.exposureMap.get(e);if(r){const s=t-r;this.triggerExposure(e,s),this.exposureMap.delete(e),this.exposedElements.delete(e)}}})},100);this.scrollFallbackHandler=e,this.resizeFallbackHandler=e,window.addEventListener("scroll",this.scrollFallbackHandler,{passive:!0}),window.addEventListener("resize",this.resizeFallbackHandler,{passive:!0}),setTimeout(e,0)}destroy(){this.observer&&(this.observer.disconnect(),this.observer=null),this.scrollFallbackHandler&&"undefined"!=typeof window&&(window.removeEventListener("scroll",this.scrollFallbackHandler),this.scrollFallbackHandler=null),this.resizeFallbackHandler&&"undefined"!=typeof window&&(window.removeEventListener("resize",this.resizeFallbackHandler),this.resizeFallbackHandler=null),this.exposedElements.clear(),this.exposureMap.clear(),this.cachedElements=[],this.lastCacheUpdate=0}}class w{constructor(){r(this,"inputHandler",null),r(this,"changeHandler",null),r(this,"inputDebounceTime",500),r(this,"selectDebounceTime",300),r(this,"skipEmptyInput",!0),r(this,"sensitiveKeywords",["password","pwd","secret","token","key","auth","credential"])}init(e,t){"undefined"!=typeof window&&(void 0!==e&&(this.inputDebounceTime=e,this.selectDebounceTime=Math.min(e,300)),void 0!==t&&(this.skipEmptyInput=t),this.inputHandler=c((...e)=>{const t=e[0];this.handleInput(t)},this.inputDebounceTime),this.changeHandler=c((...e)=>{const t=e[0];this.handleChange(t)},this.selectDebounceTime),document.addEventListener("input",this.inputHandler,!1),document.addEventListener("change",this.changeHandler,!1))}handleInput(e){var t;const r=e.target;if(!r)return;const s=null==(t=r.tagName)?void 0:t.toLowerCase();if("input"!==s&&"textarea"!==s)return;const n=o(),i=l(),a=Date.now(),c=()=>{var e;try{const t=u(r),o={...f(r),name:r.name||void 0,type:r.type||void 0,placeholder:r.placeholder||void 0},l=this.isSensitiveField(r);let c,h,d="text";if("textarea"===s)d="textarea";else if("input"===s){const t=(null==(e=r.type)?void 0:e.toLowerCase())||"text";d="checkbox"===t?"checkbox":"radio"===t?"radio":"text"}if(l?(h=r.value.length,c=void 0):(c=r.value,h=r.value.length),this.skipEmptyInput&&0===h)return;const p={type:"input",name:"input",timestamp:a,url:n,title:i,elementPath:t,elementInfo:o,inputType:d,value:c,valueLength:h,isSensitive:l};"undefined"!=typeof window&&window.__trackerEventBus&&window.__trackerEventBus.emit("input",p)}catch(t){console.error("InputTracker: Error processing input event:",t)}};"undefined"!=typeof requestIdleCallback?requestIdleCallback(c,{timeout:100}):setTimeout(c,0)}handleChange(e){var t;const r=e.target;if(!r)return;if("select"!==(null==(t=r.tagName)?void 0:t.toLowerCase()))return;const s=o(),n=l(),i=Date.now(),a=()=>{try{const e=u(r),t={...f(r),name:r.name||void 0},a=this.isSensitiveField(r),o=r;let l,c;if(a?(c=o.value.length,l=void 0):(l=o.value,c=o.value.length),this.skipEmptyInput&&0===c)return;const h={type:"input",name:"input",timestamp:i,url:s,title:n,elementPath:e,elementInfo:t,inputType:"select",value:l,valueLength:c,isSensitive:a};"undefined"!=typeof window&&window.__trackerEventBus&&window.__trackerEventBus.emit("input",h)}catch(e){console.error("InputTracker: Error processing change event:",e)}};"undefined"!=typeof requestIdleCallback?requestIdleCallback(a,{timeout:100}):setTimeout(a,0)}isSensitiveField(e){var t,r,s,n;if(e instanceof HTMLInputElement){if("password"===(null==(t=e.type)?void 0:t.toLowerCase()))return!0}const i=(null==(r=e.name)?void 0:r.toLowerCase())||"";if(i)for(const l of this.sensitiveKeywords)if(i.includes(l))return!0;const a=(null==(s=e.id)?void 0:s.toLowerCase())||"";if(a)for(const l of this.sensitiveKeywords)if(a.includes(l))return!0;const o=(null==(n=e.className)?void 0:n.toLowerCase())||"";if(o)for(const l of this.sensitiveKeywords)if(o.includes(l))return!0;return!1}destroy(){this.inputHandler&&"undefined"!=typeof document&&(document.removeEventListener("input",this.inputHandler,!1),this.inputHandler=null),this.changeHandler&&"undefined"!=typeof document&&(document.removeEventListener("change",this.changeHandler,!1),this.changeHandler=null)}}class _{constructor(){r(this,"viewTracker"),r(this,"clickTracker"),r(this,"exposureTracker"),r(this,"inputTracker"),r(this,"enabled",!1),this.viewTracker=new p,this.clickTracker=new m,this.exposureTracker=new g,this.inputTracker=new w}init(e){if(this.enabled)return;const{enableClick:t=!0,enableExposure:r=!0,enableInput:s=!0,clickDebounceTime:n,inputDebounceTime:i}=e||{};this.viewTracker.init(),t&&this.clickTracker.init(n),r&&this.exposureTracker.init(),s&&this.inputTracker.init(i),this.enabled=!0}getViewTracker(){return this.viewTracker}getClickTracker(){return this.clickTracker}getExposureTracker(){return this.exposureTracker}getInputTracker(){return this.inputTracker}destroy(){this.enabled&&(this.viewTracker.destroy(),this.clickTracker.destroy(),this.exposureTracker.destroy(),this.inputTracker.destroy(),this.enabled=!1)}}class y{constructor(){r(this,"handlers",[]),r(this,"errorCache",new Map),r(this,"debounceTime",500)}init(){if("undefined"==typeof window)return;const e=e=>{e instanceof ErrorEvent?this.handleJSError(e):this.handleResourceError(e)};window.addEventListener("error",e,!0),this.handlers.push(()=>{window.removeEventListener("error",e,!0)});const t=e=>{this.handlePromiseError(e)};window.addEventListener("unhandledrejection",t),this.handlers.push(()=>{window.removeEventListener("unhandledrejection",t)})}handleJSError(e){var t;try{const r={type:"error",name:"js-error",timestamp:Date.now(),url:e.filename||o(),title:l(),errorType:"js",message:e.message||"Unknown error",stack:null==(t=e.error)?void 0:t.stack,filename:e.filename,lineno:e.lineno,colno:e.colno};this.emitError(r)}catch(r){console.error("ErrorTracker: Error handling JS error:",r)}}handlePromiseError(e){try{const t=e.reason;let r,s="Unhandled promise rejection";t instanceof Error?(s=t.message,r=t.stack):s="string"==typeof t?t:JSON.stringify(t);const n={type:"error",name:"promise-error",timestamp:Date.now(),url:o(),title:l(),errorType:"promise",message:s,stack:r};this.emitError(n)}catch(t){console.error("ErrorTracker: Error handling promise error:",t)}}handleResourceError(e){var t;try{const r=e.target;if(!r)return;const s=null==(t=r.tagName)?void 0:t.toLowerCase();if(!["img","script","link","audio","video"].includes(s))return;let n="";if(r instanceof HTMLImageElement||r instanceof HTMLScriptElement?n=r.src||"":r instanceof HTMLLinkElement?n=r.href||"":(r instanceof HTMLAudioElement||r instanceof HTMLVideoElement)&&(n=r.src||""),!n)return;const i={type:"error",name:"resource-error",timestamp:Date.now(),url:o(),title:l(),errorType:"resource",message:`Failed to load resource: ${n}`,resourceUrl:n,resourceType:s};this.emitError(i)}catch(r){console.error("ErrorTracker: Error handling resource error:",r)}}getErrorKey(e){const t=[e.errorType,e.message];return"js"!==e.errorType&&"promise"!==e.errorType||(e.filename&&t.push(e.filename),e.lineno&&t.push(String(e.lineno)),e.colno&&t.push(String(e.colno))),"resource"===e.errorType&&e.resourceUrl&&t.push(e.resourceUrl),t.join("|")}emitError(e){const t=this.getErrorKey(e),r=this.errorCache.get(t),s=Date.now();r&&s-r<this.debounceTime||(this.errorCache.set(t,s),this.cleanExpiredErrorCache(s),"undefined"!=typeof window&&window.__trackerEventBus&&window.__trackerEventBus.emit("error",e))}cleanExpiredErrorCache(e){for(const[t,r]of this.errorCache.entries())e-r>3e5&&this.errorCache.delete(t)}trackError(e,t){try{let r,s;e instanceof Error?(r=e.message,s=e.stack):r=e;const n={type:"error",name:"custom-error",timestamp:Date.now(),url:o(),title:l(),errorType:"js",message:r,stack:s,properties:t};this.emitError(n)}catch(r){console.error("ErrorTracker: Error tracking custom error:",r)}}destroy(){this.handlers.forEach(e=>e()),this.handlers=[],this.errorCache.clear()}}class b{constructor(){r(this,"observer",null),r(this,"navigationTimingCollected",!1),r(this,"resourceCache",new Map),r(this,"longTaskCache",new Map),r(this,"resourceDebounceTime",1e3),r(this,"longTaskDebounceTime",100)}init(){"undefined"!=typeof window&&window.performance&&("complete"===document.readyState?(this.collectNavigationTiming(),this.collectResourceTiming()):window.addEventListener("load",()=>{this.collectNavigationTiming(),this.collectResourceTiming()}),this.observeLongTasks())}collectNavigationTiming(){if(!this.navigationTimingCollected)try{const e=performance.getEntriesByType("navigation")[0];if(!e)return;const 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,response:e.responseEnd-e.responseStart,domParse:e.domInteractive-e.responseEnd,resourceLoad:e.loadEventStart-e.domContentLoadedEventEnd,total:e.loadEventEnd-e.fetchStart,domContentLoaded:e.domContentLoadedEventEnd-e.fetchStart,load:e.loadEventEnd-e.fetchStart},r={type:"performance",name:"navigation-timing",timestamp:Date.now(),url:o(),title:l(),metricType:"navigation",metrics:t};this.navigationTimingCollected=!0,this.emitPerformance(r)}catch(e){console.error("PerformanceTracker: Error collecting navigation timing:",e)}}collectResourceTiming(){try{const e=performance.getEntriesByType("resource");if(!e||0===e.length)return;const t=Date.now();e.forEach(e=>{const r=e.name,s=this.resourceCache.get(r);if(s&&t-s<this.resourceDebounceTime)return;this.resourceCache.set(r,t);const n={dns:e.domainLookupEnd-e.domainLookupStart,tcp:e.connectEnd-e.connectStart,request:e.responseStart-e.requestStart,response:e.responseEnd-e.responseStart,total:e.responseEnd-e.startTime,size:e.transferSize||0},i={type:"performance",name:"resource-timing",timestamp:t,url:o(),title:l(),metricType:"resource",metrics:{...n,resourceUrl:e.name,resourceType:e.initiatorType}};this.emitPerformance(i)}),this.cleanExpiredResourceCache(t)}catch(e){console.error("PerformanceTracker: Error collecting resource timing:",e)}}observeLongTasks(){if("undefined"!=typeof PerformanceObserver)try{const e=h((...e)=>{const t=e[0],r=Date.now(),s=`${t.startTime}-${t.duration}`,n=this.longTaskCache.get(s);if(n&&r-n<this.longTaskDebounceTime)return;this.longTaskCache.set(s,r);const i={type:"performance",name:"longtask",timestamp:r,url:o(),title:l(),metricType:"longtask",metrics:{duration:t.duration,startTime:t.startTime}};this.emitPerformance(i),this.cleanExpiredLongTaskCache(r)},this.longTaskDebounceTime);this.observer=new PerformanceObserver(t=>{t.getEntries().forEach(t=>{"longtask"===t.entryType&&e(t)})}),this.observer.observe({entryTypes:["longtask"]})}catch(e){console.error("PerformanceTracker: Error observing long tasks:",e)}}cleanExpiredResourceCache(e){for(const[t,r]of this.resourceCache.entries())e-r>3e5&&this.resourceCache.delete(t)}cleanExpiredLongTaskCache(e){for(const[t,r]of this.longTaskCache.entries())e-r>6e4&&this.longTaskCache.delete(t)}emitPerformance(e){"undefined"!=typeof window&&window.__trackerEventBus&&window.__trackerEventBus.emit("performance",e)}collectMetrics(){try{const e=performance.getEntriesByType("navigation")[0];if(!e)return null;const t={dns:e.domainLookupEnd-e.domainLookupStart,tcp:e.connectEnd-e.connectStart,ttfb:e.responseStart-e.requestStart,response:e.responseEnd-e.responseStart,domParse:e.domInteractive-e.responseEnd,resourceLoad:e.loadEventStart-e.domContentLoadedEventEnd,total:e.loadEventEnd-e.fetchStart};return{type:"performance",name:"custom-performance",timestamp:Date.now(),url:o(),title:l(),metricType:"navigation",metrics:t}}catch(e){return console.error("PerformanceTracker: Error collecting metrics:",e),null}}destroy(){this.observer&&(this.observer.disconnect(),this.observer=null),this.navigationTimingCollected=!1,this.resourceCache.clear(),this.longTaskCache.clear()}}class v{track(e,t){return{type:"custom",name:"custom",eventName:e,timestamp:Date.now(),url:o(),title:l(),properties:t}}}class k{shouldSample(e){return e>=1||!(e<=0)&&Math.random()<e}shouldSampleCritical(e,t){return!!e||this.shouldSample(t)}}class E{constructor(){r(this,"eventCache",new Map),r(this,"cacheTimeouts",{click:1e4,exposure:3e4,error:5e3,performance:6e4,pageview:1e4,input:3e3,custom:1e3}),r(this,"defaultCacheTimeout",6e4)}isDuplicate(e){const t=this.getEventKey(e),r=this.eventCache.get(t),s=Date.now();let n=this.cacheTimeouts[e.type]||this.defaultCacheTimeout;if("custom"===e.type&&"eventName"in e){const t=e.eventName;"api-request"!==t&&"api-response"!==t||(n=5e3)}return!!(r&&s-r<n)||(this.eventCache.set(t,s),this.cleanExpiredCache(s),!1)}getEventKey(e){const t=[e.type,e.name,e.url];if("click"===e.type&&"elementPath"in e){if(t.push(e.elementPath||""),"position"in e&&e.position){const r=10,s=Math.floor(e.position.x/r)*r,n=Math.floor(e.position.y/r)*r;t.push(`${s}-${n}`)}}else if("exposure"===e.type&&"elementPath"in e)t.push(e.elementPath||"");else if("input"===e.type&&"elementPath"in e){if(t.push(e.elementPath||""),"value"in e&&void 0!==e.value&&null!==e.value){const r=String(e.value),s=r.length>10?r.substring(0,10):r;t.push(this.simpleHash(s))}else"valueLength"in e&&void 0!==e.valueLength&&t.push(String(e.valueLength));"isSensitive"in e&&e.isSensitive&&t.push("sensitive")}else if("error"===e.type&&"message"in e)t.push(e.message),"filename"in e&&e.filename&&t.push(e.filename),"lineno"in e&&e.lineno&&t.push(String(e.lineno)),"colno"in e&&e.colno&&t.push(String(e.colno)),"resourceUrl"in e&&e.resourceUrl&&t.push(e.resourceUrl);else if("performance"===e.type&&"metricType"in e)if(t.push(e.metricType),"resource"===e.metricType&&"metrics"in e&&e.metrics){const r=e.metrics.resourceUrl;r&&t.push(String(r))}else if("longtask"===e.metricType&&"metrics"in e&&e.metrics){const r=e.metrics;void 0!==r.startTime&&void 0!==r.duration&&t.push(`${r.startTime}-${r.duration}`)}else e.metricType;else if("custom"===e.type&&"eventName"in e){if(t.push(e.eventName),"api-request"===e.eventName||"api-response"===e.eventName){if(e.properties){const r=e.properties,s=r.url?String(r.url):"",n=r.method?String(r.method):"",i=r.fullUrl?String(r.fullUrl):"";if(s||n||i)t.push(i||`${n}:${s}`);else try{const r=JSON.stringify(e.properties);t.push(r.substring(0,100))}catch{t.push(String(Object.keys(e.properties).length))}}}else if(e.properties)try{const r=JSON.stringify(e.properties);t.push(r.substring(0,100))}catch{t.push(String(Object.keys(e.properties).length))}}else if("pageview"===e.type){const r=Math.floor(e.timestamp/1e4);t.push(String(r))}return t.join("|")}simpleHash(e){let t=0;for(let r=0;r<e.length;r++){t=(t<<5)-t+e.charCodeAt(r),t&=t}return Math.abs(t).toString(36).substring(0,8)}cleanExpiredCache(e){const t=2*Math.max(...Object.values(this.cacheTimeouts),this.defaultCacheTimeout);for(const[r,s]of this.eventCache.entries())e-s>t&&this.eventCache.delete(r)}clear(){this.eventCache.clear()}}
|
|
2
|
-
/*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) */function T(e){let t=e.length;for(;--t>=0;)e[t]=0}const S=256,x=286,z=30,I=15,R=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),C=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),D=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),U=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),A=new Array(576);T(A);const H=new Array(60);T(H);const L=new Array(512);T(L);const B=new Array(256);T(B);const O=new Array(29);T(O);const P=new Array(z);function N(e,t,r,s,n){this.static_tree=e,this.extra_bits=t,this.extra_base=r,this.elems=s,this.max_length=n,this.has_stree=e&&e.length}let M,F,Z;function q(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}T(P);const j=e=>e<256?L[e]:L[256+(e>>>7)],$=(e,t)=>{e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=t>>>8&255},K=(e,t,r)=>{e.bi_valid>16-r?(e.bi_buf|=t<<e.bi_valid&65535,$(e,e.bi_buf),e.bi_buf=t>>16-e.bi_valid,e.bi_valid+=r-16):(e.bi_buf|=t<<e.bi_valid&65535,e.bi_valid+=r)},V=(e,t,r)=>{K(e,r[2*t],r[2*t+1])},X=(e,t)=>{let r=0;do{r|=1&e,e>>>=1,r<<=1}while(--t>0);return r>>>1},W=(e,t,r)=>{const s=new Array(16);let n,i,a=0;for(n=1;n<=I;n++)a=a+r[n-1]<<1,s[n]=a;for(i=0;i<=t;i++){let t=e[2*i+1];0!==t&&(e[2*i]=X(s[t]++,t))}},J=e=>{let t;for(t=0;t<x;t++)e.dyn_ltree[2*t]=0;for(t=0;t<z;t++)e.dyn_dtree[2*t]=0;for(t=0;t<19;t++)e.bl_tree[2*t]=0;e.dyn_ltree[512]=1,e.opt_len=e.static_len=0,e.sym_next=e.matches=0},Y=e=>{e.bi_valid>8?$(e,e.bi_buf):e.bi_valid>0&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0},G=(e,t,r,s)=>{const n=2*t,i=2*r;return e[n]<e[i]||e[n]===e[i]&&s[t]<=s[r]},Q=(e,t,r)=>{const s=e.heap[r];let n=r<<1;for(;n<=e.heap_len&&(n<e.heap_len&&G(t,e.heap[n+1],e.heap[n],e.depth)&&n++,!G(t,s,e.heap[n],e.depth));)e.heap[r]=e.heap[n],r=n,n<<=1;e.heap[r]=s},ee=(e,t,r)=>{let s,n,i,a,o=0;if(0!==e.sym_next)do{s=255&e.pending_buf[e.sym_buf+o++],s+=(255&e.pending_buf[e.sym_buf+o++])<<8,n=e.pending_buf[e.sym_buf+o++],0===s?V(e,n,t):(i=B[n],V(e,i+S+1,t),a=R[i],0!==a&&(n-=O[i],K(e,n,a)),s--,i=j(s),V(e,i,r),a=C[i],0!==a&&(s-=P[i],K(e,s,a)))}while(o<e.sym_next);V(e,256,t)},te=(e,t)=>{const r=t.dyn_tree,s=t.stat_desc.static_tree,n=t.stat_desc.has_stree,i=t.stat_desc.elems;let a,o,l,c=-1;for(e.heap_len=0,e.heap_max=573,a=0;a<i;a++)0!==r[2*a]?(e.heap[++e.heap_len]=c=a,e.depth[a]=0):r[2*a+1]=0;for(;e.heap_len<2;)l=e.heap[++e.heap_len]=c<2?++c:0,r[2*l]=1,e.depth[l]=0,e.opt_len--,n&&(e.static_len-=s[2*l+1]);for(t.max_code=c,a=e.heap_len>>1;a>=1;a--)Q(e,r,a);l=i;do{a=e.heap[1],e.heap[1]=e.heap[e.heap_len--],Q(e,r,1),o=e.heap[1],e.heap[--e.heap_max]=a,e.heap[--e.heap_max]=o,r[2*l]=r[2*a]+r[2*o],e.depth[l]=(e.depth[a]>=e.depth[o]?e.depth[a]:e.depth[o])+1,r[2*a+1]=r[2*o+1]=l,e.heap[1]=l++,Q(e,r,1)}while(e.heap_len>=2);e.heap[--e.heap_max]=e.heap[1],((e,t)=>{const r=t.dyn_tree,s=t.max_code,n=t.stat_desc.static_tree,i=t.stat_desc.has_stree,a=t.stat_desc.extra_bits,o=t.stat_desc.extra_base,l=t.stat_desc.max_length;let c,h,d,u,f,p,m=0;for(u=0;u<=I;u++)e.bl_count[u]=0;for(r[2*e.heap[e.heap_max]+1]=0,c=e.heap_max+1;c<573;c++)h=e.heap[c],u=r[2*r[2*h+1]+1]+1,u>l&&(u=l,m++),r[2*h+1]=u,h>s||(e.bl_count[u]++,f=0,h>=o&&(f=a[h-o]),p=r[2*h],e.opt_len+=p*(u+f),i&&(e.static_len+=p*(n[2*h+1]+f)));if(0!==m){do{for(u=l-1;0===e.bl_count[u];)u--;e.bl_count[u]--,e.bl_count[u+1]+=2,e.bl_count[l]--,m-=2}while(m>0);for(u=l;0!==u;u--)for(h=e.bl_count[u];0!==h;)d=e.heap[--c],d>s||(r[2*d+1]!==u&&(e.opt_len+=(u-r[2*d+1])*r[2*d],r[2*d+1]=u),h--)}})(e,t),W(r,c,e.bl_count)},re=(e,t,r)=>{let s,n,i=-1,a=t[1],o=0,l=7,c=4;for(0===a&&(l=138,c=3),t[2*(r+1)+1]=65535,s=0;s<=r;s++)n=a,a=t[2*(s+1)+1],++o<l&&n===a||(o<c?e.bl_tree[2*n]+=o:0!==n?(n!==i&&e.bl_tree[2*n]++,e.bl_tree[32]++):o<=10?e.bl_tree[34]++:e.bl_tree[36]++,o=0,i=n,0===a?(l=138,c=3):n===a?(l=6,c=3):(l=7,c=4))},se=(e,t,r)=>{let s,n,i=-1,a=t[1],o=0,l=7,c=4;for(0===a&&(l=138,c=3),s=0;s<=r;s++)if(n=a,a=t[2*(s+1)+1],!(++o<l&&n===a)){if(o<c)do{V(e,n,e.bl_tree)}while(0!==--o);else 0!==n?(n!==i&&(V(e,n,e.bl_tree),o--),V(e,16,e.bl_tree),K(e,o-3,2)):o<=10?(V(e,17,e.bl_tree),K(e,o-3,3)):(V(e,18,e.bl_tree),K(e,o-11,7));o=0,i=n,0===a?(l=138,c=3):n===a?(l=6,c=3):(l=7,c=4)}};let ne=!1;const ie=(e,t,r,s)=>{K(e,0+(s?1:0),3),Y(e),$(e,r),$(e,~r),r&&e.pending_buf.set(e.window.subarray(t,t+r),e.pending),e.pending+=r};var ae={_tr_init:e=>{ne||((()=>{let e,t,r,s,n;const i=new Array(16);for(r=0,s=0;s<28;s++)for(O[s]=r,e=0;e<1<<R[s];e++)B[r++]=s;for(B[r-1]=s,n=0,s=0;s<16;s++)for(P[s]=n,e=0;e<1<<C[s];e++)L[n++]=s;for(n>>=7;s<z;s++)for(P[s]=n<<7,e=0;e<1<<C[s]-7;e++)L[256+n++]=s;for(t=0;t<=I;t++)i[t]=0;for(e=0;e<=143;)A[2*e+1]=8,e++,i[8]++;for(;e<=255;)A[2*e+1]=9,e++,i[9]++;for(;e<=279;)A[2*e+1]=7,e++,i[7]++;for(;e<=287;)A[2*e+1]=8,e++,i[8]++;for(W(A,287,i),e=0;e<z;e++)H[2*e+1]=5,H[2*e]=X(e,5);M=new N(A,R,257,x,I),F=new N(H,C,0,z,I),Z=new N(new Array(0),D,0,19,7)})(),ne=!0),e.l_desc=new q(e.dyn_ltree,M),e.d_desc=new q(e.dyn_dtree,F),e.bl_desc=new q(e.bl_tree,Z),e.bi_buf=0,e.bi_valid=0,J(e)},_tr_stored_block:ie,_tr_flush_block:(e,t,r,s)=>{let n,i,a=0;e.level>0?(2===e.strm.data_type&&(e.strm.data_type=(e=>{let t,r=4093624447;for(t=0;t<=31;t++,r>>>=1)if(1&r&&0!==e.dyn_ltree[2*t])return 0;if(0!==e.dyn_ltree[18]||0!==e.dyn_ltree[20]||0!==e.dyn_ltree[26])return 1;for(t=32;t<S;t++)if(0!==e.dyn_ltree[2*t])return 1;return 0})(e)),te(e,e.l_desc),te(e,e.d_desc),a=(e=>{let t;for(re(e,e.dyn_ltree,e.l_desc.max_code),re(e,e.dyn_dtree,e.d_desc.max_code),te(e,e.bl_desc),t=18;t>=3&&0===e.bl_tree[2*U[t]+1];t--);return e.opt_len+=3*(t+1)+5+5+4,t})(e),n=e.opt_len+3+7>>>3,i=e.static_len+3+7>>>3,i<=n&&(n=i)):n=i=r+5,r+4<=n&&-1!==t?ie(e,t,r,s):4===e.strategy||i===n?(K(e,2+(s?1:0),3),ee(e,A,H)):(K(e,4+(s?1:0),3),((e,t,r,s)=>{let n;for(K(e,t-257,5),K(e,r-1,5),K(e,s-4,4),n=0;n<s;n++)K(e,e.bl_tree[2*U[n]+1],3);se(e,e.dyn_ltree,t-1),se(e,e.dyn_dtree,r-1)})(e,e.l_desc.max_code+1,e.d_desc.max_code+1,a+1),ee(e,e.dyn_ltree,e.dyn_dtree)),J(e),s&&Y(e)},_tr_tally:(e,t,r)=>(e.pending_buf[e.sym_buf+e.sym_next++]=t,e.pending_buf[e.sym_buf+e.sym_next++]=t>>8,e.pending_buf[e.sym_buf+e.sym_next++]=r,0===t?e.dyn_ltree[2*r]++:(e.matches++,t--,e.dyn_ltree[2*(B[r]+S+1)]++,e.dyn_dtree[2*j(t)]++),e.sym_next===e.sym_end),_tr_align:e=>{K(e,2,3),V(e,256,A),(e=>{16===e.bi_valid?($(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):e.bi_valid>=8&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8)})(e)}};var oe=(e,t,r,s)=>{let n=65535&e,i=e>>>16&65535,a=0;for(;0!==r;){a=r>2e3?2e3:r,r-=a;do{n=n+t[s++]|0,i=i+n|0}while(--a);n%=65521,i%=65521}return n|i<<16};const le=new Uint32Array((()=>{let e,t=[];for(var r=0;r<256;r++){e=r;for(var s=0;s<8;s++)e=1&e?3988292384^e>>>1:e>>>1;t[r]=e}return t})());var ce=(e,t,r,s)=>{const n=le,i=s+r;e^=-1;for(let a=s;a<i;a++)e=e>>>8^n[255&(e^t[a])];return-1^e},he={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},de={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:ue,_tr_stored_block:fe,_tr_flush_block:pe,_tr_tally:me,_tr_align:ge}=ae,{Z_NO_FLUSH:we,Z_PARTIAL_FLUSH:_e,Z_FULL_FLUSH:ye,Z_FINISH:be,Z_BLOCK:ve,Z_OK:ke,Z_STREAM_END:Ee,Z_STREAM_ERROR:Te,Z_DATA_ERROR:Se,Z_BUF_ERROR:xe,Z_DEFAULT_COMPRESSION:ze,Z_FILTERED:Ie,Z_HUFFMAN_ONLY:Re,Z_RLE:Ce,Z_FIXED:De,Z_DEFAULT_STRATEGY:Ue,Z_UNKNOWN:Ae,Z_DEFLATED:He}=de,Le=258,Be=262,Oe=42,Pe=113,Ne=666,Me=(e,t)=>(e.msg=he[t],t),Fe=e=>2*e-(e>4?9:0),Ze=e=>{let t=e.length;for(;--t>=0;)e[t]=0},qe=e=>{let t,r,s,n=e.w_size;t=e.hash_size,s=t;do{r=e.head[--s],e.head[s]=r>=n?r-n:0}while(--t);t=n,s=t;do{r=e.prev[--s],e.prev[s]=r>=n?r-n:0}while(--t)};let je=(e,t,r)=>(t<<e.hash_shift^r)&e.hash_mask;const $e=e=>{const t=e.state;let r=t.pending;r>e.avail_out&&(r=e.avail_out),0!==r&&(e.output.set(t.pending_buf.subarray(t.pending_out,t.pending_out+r),e.next_out),e.next_out+=r,t.pending_out+=r,e.total_out+=r,e.avail_out-=r,t.pending-=r,0===t.pending&&(t.pending_out=0))},Ke=(e,t)=>{pe(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,$e(e.strm)},Ve=(e,t)=>{e.pending_buf[e.pending++]=t},Xe=(e,t)=>{e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=255&t},We=(e,t,r,s)=>{let n=e.avail_in;return n>s&&(n=s),0===n?0:(e.avail_in-=n,t.set(e.input.subarray(e.next_in,e.next_in+n),r),1===e.state.wrap?e.adler=oe(e.adler,t,n,r):2===e.state.wrap&&(e.adler=ce(e.adler,t,n,r)),e.next_in+=n,e.total_in+=n,n)},Je=(e,t)=>{let r,s,n=e.max_chain_length,i=e.strstart,a=e.prev_length,o=e.nice_match;const l=e.strstart>e.w_size-Be?e.strstart-(e.w_size-Be):0,c=e.window,h=e.w_mask,d=e.prev,u=e.strstart+Le;let f=c[i+a-1],p=c[i+a];e.prev_length>=e.good_match&&(n>>=2),o>e.lookahead&&(o=e.lookahead);do{if(r=t,c[r+a]===p&&c[r+a-1]===f&&c[r]===c[i]&&c[++r]===c[i+1]){i+=2,r++;do{}while(c[++i]===c[++r]&&c[++i]===c[++r]&&c[++i]===c[++r]&&c[++i]===c[++r]&&c[++i]===c[++r]&&c[++i]===c[++r]&&c[++i]===c[++r]&&c[++i]===c[++r]&&i<u);if(s=Le-(u-i),i=u-Le,s>a){if(e.match_start=t,a=s,s>=o)break;f=c[i+a-1],p=c[i+a]}}}while((t=d[t&h])>l&&0!==--n);return a<=e.lookahead?a:e.lookahead},Ye=e=>{const t=e.w_size;let r,s,n;do{if(s=e.window_size-e.lookahead-e.strstart,e.strstart>=t+(t-Be)&&(e.window.set(e.window.subarray(t,t+t-s),0),e.match_start-=t,e.strstart-=t,e.block_start-=t,e.insert>e.strstart&&(e.insert=e.strstart),qe(e),s+=t),0===e.strm.avail_in)break;if(r=We(e.strm,e.window,e.strstart+e.lookahead,s),e.lookahead+=r,e.lookahead+e.insert>=3)for(n=e.strstart-e.insert,e.ins_h=e.window[n],e.ins_h=je(e,e.ins_h,e.window[n+1]);e.insert&&(e.ins_h=je(e,e.ins_h,e.window[n+3-1]),e.prev[n&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=n,n++,e.insert--,!(e.lookahead+e.insert<3)););}while(e.lookahead<Be&&0!==e.strm.avail_in)},Ge=(e,t)=>{let r,s,n,i=e.pending_buf_size-5>e.w_size?e.w_size:e.pending_buf_size-5,a=0,o=e.strm.avail_in;do{if(r=65535,n=e.bi_valid+42>>3,e.strm.avail_out<n)break;if(n=e.strm.avail_out-n,s=e.strstart-e.block_start,r>s+e.strm.avail_in&&(r=s+e.strm.avail_in),r>n&&(r=n),r<i&&(0===r&&t!==be||t===we||r!==s+e.strm.avail_in))break;a=t===be&&r===s+e.strm.avail_in?1:0,fe(e,0,0,a),e.pending_buf[e.pending-4]=r,e.pending_buf[e.pending-3]=r>>8,e.pending_buf[e.pending-2]=~r,e.pending_buf[e.pending-1]=~r>>8,$e(e.strm),s&&(s>r&&(s=r),e.strm.output.set(e.window.subarray(e.block_start,e.block_start+s),e.strm.next_out),e.strm.next_out+=s,e.strm.avail_out-=s,e.strm.total_out+=s,e.block_start+=s,r-=s),r&&(We(e.strm,e.strm.output,e.strm.next_out,r),e.strm.next_out+=r,e.strm.avail_out-=r,e.strm.total_out+=r)}while(0===a);return o-=e.strm.avail_in,o&&(o>=e.w_size?(e.matches=2,e.window.set(e.strm.input.subarray(e.strm.next_in-e.w_size,e.strm.next_in),0),e.strstart=e.w_size,e.insert=e.strstart):(e.window_size-e.strstart<=o&&(e.strstart-=e.w_size,e.window.set(e.window.subarray(e.w_size,e.w_size+e.strstart),0),e.matches<2&&e.matches++,e.insert>e.strstart&&(e.insert=e.strstart)),e.window.set(e.strm.input.subarray(e.strm.next_in-o,e.strm.next_in),e.strstart),e.strstart+=o,e.insert+=o>e.w_size-e.insert?e.w_size-e.insert:o),e.block_start=e.strstart),e.high_water<e.strstart&&(e.high_water=e.strstart),a?4:t!==we&&t!==be&&0===e.strm.avail_in&&e.strstart===e.block_start?2:(n=e.window_size-e.strstart,e.strm.avail_in>n&&e.block_start>=e.w_size&&(e.block_start-=e.w_size,e.strstart-=e.w_size,e.window.set(e.window.subarray(e.w_size,e.w_size+e.strstart),0),e.matches<2&&e.matches++,n+=e.w_size,e.insert>e.strstart&&(e.insert=e.strstart)),n>e.strm.avail_in&&(n=e.strm.avail_in),n&&(We(e.strm,e.window,e.strstart,n),e.strstart+=n,e.insert+=n>e.w_size-e.insert?e.w_size-e.insert:n),e.high_water<e.strstart&&(e.high_water=e.strstart),n=e.bi_valid+42>>3,n=e.pending_buf_size-n>65535?65535:e.pending_buf_size-n,i=n>e.w_size?e.w_size:n,s=e.strstart-e.block_start,(s>=i||(s||t===be)&&t!==we&&0===e.strm.avail_in&&s<=n)&&(r=s>n?n:s,a=t===be&&0===e.strm.avail_in&&r===s?1:0,fe(e,e.block_start,r,a),e.block_start+=r,$e(e.strm)),a?3:1)},Qe=(e,t)=>{let r,s;for(;;){if(e.lookahead<Be){if(Ye(e),e.lookahead<Be&&t===we)return 1;if(0===e.lookahead)break}if(r=0,e.lookahead>=3&&(e.ins_h=je(e,e.ins_h,e.window[e.strstart+3-1]),r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),0!==r&&e.strstart-r<=e.w_size-Be&&(e.match_length=Je(e,r)),e.match_length>=3)if(s=me(e,e.strstart-e.match_start,e.match_length-3),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=3){e.match_length--;do{e.strstart++,e.ins_h=je(e,e.ins_h,e.window[e.strstart+3-1]),r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart}while(0!==--e.match_length);e.strstart++}else e.strstart+=e.match_length,e.match_length=0,e.ins_h=e.window[e.strstart],e.ins_h=je(e,e.ins_h,e.window[e.strstart+1]);else s=me(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(s&&(Ke(e,!1),0===e.strm.avail_out))return 1}return e.insert=e.strstart<2?e.strstart:2,t===be?(Ke(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(Ke(e,!1),0===e.strm.avail_out)?1:2},et=(e,t)=>{let r,s,n;for(;;){if(e.lookahead<Be){if(Ye(e),e.lookahead<Be&&t===we)return 1;if(0===e.lookahead)break}if(r=0,e.lookahead>=3&&(e.ins_h=je(e,e.ins_h,e.window[e.strstart+3-1]),r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),e.prev_length=e.match_length,e.prev_match=e.match_start,e.match_length=2,0!==r&&e.prev_length<e.max_lazy_match&&e.strstart-r<=e.w_size-Be&&(e.match_length=Je(e,r),e.match_length<=5&&(e.strategy===Ie||3===e.match_length&&e.strstart-e.match_start>4096)&&(e.match_length=2)),e.prev_length>=3&&e.match_length<=e.prev_length){n=e.strstart+e.lookahead-3,s=me(e,e.strstart-1-e.prev_match,e.prev_length-3),e.lookahead-=e.prev_length-1,e.prev_length-=2;do{++e.strstart<=n&&(e.ins_h=je(e,e.ins_h,e.window[e.strstart+3-1]),r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart)}while(0!==--e.prev_length);if(e.match_available=0,e.match_length=2,e.strstart++,s&&(Ke(e,!1),0===e.strm.avail_out))return 1}else if(e.match_available){if(s=me(e,0,e.window[e.strstart-1]),s&&Ke(e,!1),e.strstart++,e.lookahead--,0===e.strm.avail_out)return 1}else e.match_available=1,e.strstart++,e.lookahead--}return e.match_available&&(s=me(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=e.strstart<2?e.strstart:2,t===be?(Ke(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(Ke(e,!1),0===e.strm.avail_out)?1:2};function tt(e,t,r,s,n){this.good_length=e,this.max_lazy=t,this.nice_length=r,this.max_chain=s,this.func=n}const rt=[new tt(0,0,0,0,Ge),new tt(4,4,8,4,Qe),new tt(4,5,16,8,Qe),new tt(4,6,32,32,Qe),new tt(4,4,16,16,et),new tt(8,16,32,32,et),new tt(8,16,128,128,et),new tt(8,32,128,256,et),new tt(32,128,258,1024,et),new tt(32,258,258,4096,et)];function st(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=He,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),Ze(this.dyn_ltree),Ze(this.dyn_dtree),Ze(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),Ze(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),Ze(this.depth),this.sym_buf=0,this.lit_bufsize=0,this.sym_next=0,this.sym_end=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const nt=e=>{if(!e)return 1;const t=e.state;return!t||t.strm!==e||t.status!==Oe&&57!==t.status&&69!==t.status&&73!==t.status&&91!==t.status&&103!==t.status&&t.status!==Pe&&t.status!==Ne?1:0},it=e=>{if(nt(e))return Me(e,Te);e.total_in=e.total_out=0,e.data_type=Ae;const t=e.state;return t.pending=0,t.pending_out=0,t.wrap<0&&(t.wrap=-t.wrap),t.status=2===t.wrap?57:t.wrap?Oe:Pe,e.adler=2===t.wrap?0:1,t.last_flush=-2,ue(t),ke},at=e=>{const t=it(e);var r;return t===ke&&((r=e.state).window_size=2*r.w_size,Ze(r.head),r.max_lazy_match=rt[r.level].max_lazy,r.good_match=rt[r.level].good_length,r.nice_match=rt[r.level].nice_length,r.max_chain_length=rt[r.level].max_chain,r.strstart=0,r.block_start=0,r.lookahead=0,r.insert=0,r.match_length=r.prev_length=2,r.match_available=0,r.ins_h=0),t},ot=(e,t,r,s,n,i)=>{if(!e)return Te;let a=1;if(t===ze&&(t=6),s<0?(a=0,s=-s):s>15&&(a=2,s-=16),n<1||n>9||r!==He||s<8||s>15||t<0||t>9||i<0||i>De||8===s&&1!==a)return Me(e,Te);8===s&&(s=9);const o=new st;return e.state=o,o.strm=e,o.status=Oe,o.wrap=a,o.gzhead=null,o.w_bits=s,o.w_size=1<<o.w_bits,o.w_mask=o.w_size-1,o.hash_bits=n+7,o.hash_size=1<<o.hash_bits,o.hash_mask=o.hash_size-1,o.hash_shift=~~((o.hash_bits+3-1)/3),o.window=new Uint8Array(2*o.w_size),o.head=new Uint16Array(o.hash_size),o.prev=new Uint16Array(o.w_size),o.lit_bufsize=1<<n+6,o.pending_buf_size=4*o.lit_bufsize,o.pending_buf=new Uint8Array(o.pending_buf_size),o.sym_buf=o.lit_bufsize,o.sym_end=3*(o.lit_bufsize-1),o.level=t,o.strategy=i,o.method=r,at(e)};var lt={deflateInit:(e,t)=>ot(e,t,He,15,8,Ue),deflateInit2:ot,deflateReset:at,deflateResetKeep:it,deflateSetHeader:(e,t)=>nt(e)||2!==e.state.wrap?Te:(e.state.gzhead=t,ke),deflate:(e,t)=>{if(nt(e)||t>ve||t<0)return e?Me(e,Te):Te;const r=e.state;if(!e.output||0!==e.avail_in&&!e.input||r.status===Ne&&t!==be)return Me(e,0===e.avail_out?xe:Te);const s=r.last_flush;if(r.last_flush=t,0!==r.pending){if($e(e),0===e.avail_out)return r.last_flush=-1,ke}else if(0===e.avail_in&&Fe(t)<=Fe(s)&&t!==be)return Me(e,xe);if(r.status===Ne&&0!==e.avail_in)return Me(e,xe);if(r.status===Oe&&0===r.wrap&&(r.status=Pe),r.status===Oe){let t=He+(r.w_bits-8<<4)<<8,s=-1;if(s=r.strategy>=Re||r.level<2?0:r.level<6?1:6===r.level?2:3,t|=s<<6,0!==r.strstart&&(t|=32),t+=31-t%31,Xe(r,t),0!==r.strstart&&(Xe(r,e.adler>>>16),Xe(r,65535&e.adler)),e.adler=1,r.status=Pe,$e(e),0!==r.pending)return r.last_flush=-1,ke}if(57===r.status)if(e.adler=0,Ve(r,31),Ve(r,139),Ve(r,8),r.gzhead)Ve(r,(r.gzhead.text?1:0)+(r.gzhead.hcrc?2:0)+(r.gzhead.extra?4:0)+(r.gzhead.name?8:0)+(r.gzhead.comment?16:0)),Ve(r,255&r.gzhead.time),Ve(r,r.gzhead.time>>8&255),Ve(r,r.gzhead.time>>16&255),Ve(r,r.gzhead.time>>24&255),Ve(r,9===r.level?2:r.strategy>=Re||r.level<2?4:0),Ve(r,255&r.gzhead.os),r.gzhead.extra&&r.gzhead.extra.length&&(Ve(r,255&r.gzhead.extra.length),Ve(r,r.gzhead.extra.length>>8&255)),r.gzhead.hcrc&&(e.adler=ce(e.adler,r.pending_buf,r.pending,0)),r.gzindex=0,r.status=69;else if(Ve(r,0),Ve(r,0),Ve(r,0),Ve(r,0),Ve(r,0),Ve(r,9===r.level?2:r.strategy>=Re||r.level<2?4:0),Ve(r,3),r.status=Pe,$e(e),0!==r.pending)return r.last_flush=-1,ke;if(69===r.status){if(r.gzhead.extra){let t=r.pending,s=(65535&r.gzhead.extra.length)-r.gzindex;for(;r.pending+s>r.pending_buf_size;){let n=r.pending_buf_size-r.pending;if(r.pending_buf.set(r.gzhead.extra.subarray(r.gzindex,r.gzindex+n),r.pending),r.pending=r.pending_buf_size,r.gzhead.hcrc&&r.pending>t&&(e.adler=ce(e.adler,r.pending_buf,r.pending-t,t)),r.gzindex+=n,$e(e),0!==r.pending)return r.last_flush=-1,ke;t=0,s-=n}let n=new Uint8Array(r.gzhead.extra);r.pending_buf.set(n.subarray(r.gzindex,r.gzindex+s),r.pending),r.pending+=s,r.gzhead.hcrc&&r.pending>t&&(e.adler=ce(e.adler,r.pending_buf,r.pending-t,t)),r.gzindex=0}r.status=73}if(73===r.status){if(r.gzhead.name){let t,s=r.pending;do{if(r.pending===r.pending_buf_size){if(r.gzhead.hcrc&&r.pending>s&&(e.adler=ce(e.adler,r.pending_buf,r.pending-s,s)),$e(e),0!==r.pending)return r.last_flush=-1,ke;s=0}t=r.gzindex<r.gzhead.name.length?255&r.gzhead.name.charCodeAt(r.gzindex++):0,Ve(r,t)}while(0!==t);r.gzhead.hcrc&&r.pending>s&&(e.adler=ce(e.adler,r.pending_buf,r.pending-s,s)),r.gzindex=0}r.status=91}if(91===r.status){if(r.gzhead.comment){let t,s=r.pending;do{if(r.pending===r.pending_buf_size){if(r.gzhead.hcrc&&r.pending>s&&(e.adler=ce(e.adler,r.pending_buf,r.pending-s,s)),$e(e),0!==r.pending)return r.last_flush=-1,ke;s=0}t=r.gzindex<r.gzhead.comment.length?255&r.gzhead.comment.charCodeAt(r.gzindex++):0,Ve(r,t)}while(0!==t);r.gzhead.hcrc&&r.pending>s&&(e.adler=ce(e.adler,r.pending_buf,r.pending-s,s))}r.status=103}if(103===r.status){if(r.gzhead.hcrc){if(r.pending+2>r.pending_buf_size&&($e(e),0!==r.pending))return r.last_flush=-1,ke;Ve(r,255&e.adler),Ve(r,e.adler>>8&255),e.adler=0}if(r.status=Pe,$e(e),0!==r.pending)return r.last_flush=-1,ke}if(0!==e.avail_in||0!==r.lookahead||t!==we&&r.status!==Ne){let s=0===r.level?Ge(r,t):r.strategy===Re?((e,t)=>{let r;for(;;){if(0===e.lookahead&&(Ye(e),0===e.lookahead)){if(t===we)return 1;break}if(e.match_length=0,r=me(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,r&&(Ke(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===be?(Ke(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(Ke(e,!1),0===e.strm.avail_out)?1:2})(r,t):r.strategy===Ce?((e,t)=>{let r,s,n,i;const a=e.window;for(;;){if(e.lookahead<=Le){if(Ye(e),e.lookahead<=Le&&t===we)return 1;if(0===e.lookahead)break}if(e.match_length=0,e.lookahead>=3&&e.strstart>0&&(n=e.strstart-1,s=a[n],s===a[++n]&&s===a[++n]&&s===a[++n])){i=e.strstart+Le;do{}while(s===a[++n]&&s===a[++n]&&s===a[++n]&&s===a[++n]&&s===a[++n]&&s===a[++n]&&s===a[++n]&&s===a[++n]&&n<i);e.match_length=Le-(i-n),e.match_length>e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=3?(r=me(e,1,e.match_length-3),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(r=me(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),r&&(Ke(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===be?(Ke(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(Ke(e,!1),0===e.strm.avail_out)?1:2})(r,t):rt[r.level].func(r,t);if(3!==s&&4!==s||(r.status=Ne),1===s||3===s)return 0===e.avail_out&&(r.last_flush=-1),ke;if(2===s&&(t===_e?ge(r):t!==ve&&(fe(r,0,0,!1),t===ye&&(Ze(r.head),0===r.lookahead&&(r.strstart=0,r.block_start=0,r.insert=0))),$e(e),0===e.avail_out))return r.last_flush=-1,ke}return t!==be?ke:r.wrap<=0?Ee:(2===r.wrap?(Ve(r,255&e.adler),Ve(r,e.adler>>8&255),Ve(r,e.adler>>16&255),Ve(r,e.adler>>24&255),Ve(r,255&e.total_in),Ve(r,e.total_in>>8&255),Ve(r,e.total_in>>16&255),Ve(r,e.total_in>>24&255)):(Xe(r,e.adler>>>16),Xe(r,65535&e.adler)),$e(e),r.wrap>0&&(r.wrap=-r.wrap),0!==r.pending?ke:Ee)},deflateEnd:e=>{if(nt(e))return Te;const t=e.state.status;return e.state=null,t===Pe?Me(e,Se):ke},deflateSetDictionary:(e,t)=>{let r=t.length;if(nt(e))return Te;const s=e.state,n=s.wrap;if(2===n||1===n&&s.status!==Oe||s.lookahead)return Te;if(1===n&&(e.adler=oe(e.adler,t,r,0)),s.wrap=0,r>=s.w_size){0===n&&(Ze(s.head),s.strstart=0,s.block_start=0,s.insert=0);let e=new Uint8Array(s.w_size);e.set(t.subarray(r-s.w_size,r),0),t=e,r=s.w_size}const i=e.avail_in,a=e.next_in,o=e.input;for(e.avail_in=r,e.next_in=0,e.input=t,Ye(s);s.lookahead>=3;){let e=s.strstart,t=s.lookahead-2;do{s.ins_h=je(s,s.ins_h,s.window[e+3-1]),s.prev[e&s.w_mask]=s.head[s.ins_h],s.head[s.ins_h]=e,e++}while(--t);s.strstart=e,s.lookahead=2,Ye(s)}return s.strstart+=s.lookahead,s.block_start=s.strstart,s.insert=s.lookahead,s.lookahead=0,s.match_length=s.prev_length=2,s.match_available=0,e.next_in=a,e.input=o,e.avail_in=i,s.wrap=n,ke},deflateInfo:"pako deflate (from Nodeca project)"};const ct=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var ht=function(e){const t=Array.prototype.slice.call(arguments,1);for(;t.length;){const r=t.shift();if(r){if("object"!=typeof r)throw new TypeError(r+"must be non-object");for(const t in r)ct(r,t)&&(e[t]=r[t])}}return e},dt=e=>{let t=0;for(let s=0,n=e.length;s<n;s++)t+=e[s].length;const r=new Uint8Array(t);for(let s=0,n=0,i=e.length;s<i;s++){let t=e[s];r.set(t,n),n+=t.length}return r};let ut=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(cs){ut=!1}const ft=new Uint8Array(256);for(let hs=0;hs<256;hs++)ft[hs]=hs>=252?6:hs>=248?5:hs>=240?4:hs>=224?3:hs>=192?2:1;ft[254]=ft[254]=1;var pt=e=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(e);let t,r,s,n,i,a=e.length,o=0;for(n=0;n<a;n++)r=e.charCodeAt(n),55296==(64512&r)&&n+1<a&&(s=e.charCodeAt(n+1),56320==(64512&s)&&(r=65536+(r-55296<<10)+(s-56320),n++)),o+=r<128?1:r<2048?2:r<65536?3:4;for(t=new Uint8Array(o),i=0,n=0;i<o;n++)r=e.charCodeAt(n),55296==(64512&r)&&n+1<a&&(s=e.charCodeAt(n+1),56320==(64512&s)&&(r=65536+(r-55296<<10)+(s-56320),n++)),r<128?t[i++]=r:r<2048?(t[i++]=192|r>>>6,t[i++]=128|63&r):r<65536?(t[i++]=224|r>>>12,t[i++]=128|r>>>6&63,t[i++]=128|63&r):(t[i++]=240|r>>>18,t[i++]=128|r>>>12&63,t[i++]=128|r>>>6&63,t[i++]=128|63&r);return t},mt=(e,t)=>{const r=t||e.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(e.subarray(0,t));let s,n;const i=new Array(2*r);for(n=0,s=0;s<r;){let t=e[s++];if(t<128){i[n++]=t;continue}let a=ft[t];if(a>4)i[n++]=65533,s+=a-1;else{for(t&=2===a?31:3===a?15:7;a>1&&s<r;)t=t<<6|63&e[s++],a--;a>1?i[n++]=65533:t<65536?i[n++]=t:(t-=65536,i[n++]=55296|t>>10&1023,i[n++]=56320|1023&t)}}return((e,t)=>{if(t<65534&&e.subarray&&ut)return String.fromCharCode.apply(null,e.length===t?e:e.subarray(0,t));let r="";for(let s=0;s<t;s++)r+=String.fromCharCode(e[s]);return r})(i,n)},gt=(e,t)=>{(t=t||e.length)>e.length&&(t=e.length);let r=t-1;for(;r>=0&&128==(192&e[r]);)r--;return r<0||0===r?t:r+ft[e[r]]>t?r:t};var wt=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const _t=Object.prototype.toString,{Z_NO_FLUSH:yt,Z_SYNC_FLUSH:bt,Z_FULL_FLUSH:vt,Z_FINISH:kt,Z_OK:Et,Z_STREAM_END:Tt,Z_DEFAULT_COMPRESSION:St,Z_DEFAULT_STRATEGY:xt,Z_DEFLATED:zt}=de;function It(e){this.options=ht({level:St,method:zt,chunkSize:16384,windowBits:15,memLevel:8,strategy:xt},e||{});let t=this.options;t.raw&&t.windowBits>0?t.windowBits=-t.windowBits:t.gzip&&t.windowBits>0&&t.windowBits<16&&(t.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new wt,this.strm.avail_out=0;let r=lt.deflateInit2(this.strm,t.level,t.method,t.windowBits,t.memLevel,t.strategy);if(r!==Et)throw new Error(he[r]);if(t.header&<.deflateSetHeader(this.strm,t.header),t.dictionary){let e;if(e="string"==typeof t.dictionary?pt(t.dictionary):"[object ArrayBuffer]"===_t.call(t.dictionary)?new Uint8Array(t.dictionary):t.dictionary,r=lt.deflateSetDictionary(this.strm,e),r!==Et)throw new Error(he[r]);this._dict_set=!0}}function Rt(e,t){const r=new It(t);if(r.push(e,!0),r.err)throw r.msg||he[r.err];return r.result}It.prototype.push=function(e,t){const r=this.strm,s=this.options.chunkSize;let n,i;if(this.ended)return!1;for(i=t===~~t?t:!0===t?kt:yt,"string"==typeof e?r.input=pt(e):"[object ArrayBuffer]"===_t.call(e)?r.input=new Uint8Array(e):r.input=e,r.next_in=0,r.avail_in=r.input.length;;)if(0===r.avail_out&&(r.output=new Uint8Array(s),r.next_out=0,r.avail_out=s),(i===bt||i===vt)&&r.avail_out<=6)this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;else{if(n=lt.deflate(r,i),n===Tt)return r.next_out>0&&this.onData(r.output.subarray(0,r.next_out)),n=lt.deflateEnd(this.strm),this.onEnd(n),this.ended=!0,n===Et;if(0!==r.avail_out){if(i>0&&r.next_out>0)this.onData(r.output.subarray(0,r.next_out)),r.avail_out=0;else if(0===r.avail_in)break}else this.onData(r.output)}return!0},It.prototype.onData=function(e){this.chunks.push(e)},It.prototype.onEnd=function(e){e===Et&&(this.result=dt(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var Ct={Deflate:It,deflate:Rt,deflateRaw:function(e,t){return(t=t||{}).raw=!0,Rt(e,t)},gzip:function(e,t){return(t=t||{}).gzip=!0,Rt(e,t)}};const Dt=16209;var Ut=function(e,t){let r,s,n,i,a,o,l,c,h,d,u,f,p,m,g,w,_,y,b,v,k,E,T,S;const x=e.state;r=e.next_in,T=e.input,s=r+(e.avail_in-5),n=e.next_out,S=e.output,i=n-(t-e.avail_out),a=n+(e.avail_out-257),o=x.dmax,l=x.wsize,c=x.whave,h=x.wnext,d=x.window,u=x.hold,f=x.bits,p=x.lencode,m=x.distcode,g=(1<<x.lenbits)-1,w=(1<<x.distbits)-1;e:do{f<15&&(u+=T[r++]<<f,f+=8,u+=T[r++]<<f,f+=8),_=p[u&g];t:for(;;){if(y=_>>>24,u>>>=y,f-=y,y=_>>>16&255,0===y)S[n++]=65535&_;else{if(!(16&y)){if(64&y){if(32&y){x.mode=16191;break e}e.msg="invalid literal/length code",x.mode=Dt;break e}_=p[(65535&_)+(u&(1<<y)-1)];continue t}for(b=65535&_,y&=15,y&&(f<y&&(u+=T[r++]<<f,f+=8),b+=u&(1<<y)-1,u>>>=y,f-=y),f<15&&(u+=T[r++]<<f,f+=8,u+=T[r++]<<f,f+=8),_=m[u&w];;){if(y=_>>>24,u>>>=y,f-=y,y=_>>>16&255,16&y){if(v=65535&_,y&=15,f<y&&(u+=T[r++]<<f,f+=8,f<y&&(u+=T[r++]<<f,f+=8)),v+=u&(1<<y)-1,v>o){e.msg="invalid distance too far back",x.mode=Dt;break e}if(u>>>=y,f-=y,y=n-i,v>y){if(y=v-y,y>c&&x.sane){e.msg="invalid distance too far back",x.mode=Dt;break e}if(k=0,E=d,0===h){if(k+=l-y,y<b){b-=y;do{S[n++]=d[k++]}while(--y);k=n-v,E=S}}else if(h<y){if(k+=l+h-y,y-=h,y<b){b-=y;do{S[n++]=d[k++]}while(--y);if(k=0,h<b){y=h,b-=y;do{S[n++]=d[k++]}while(--y);k=n-v,E=S}}}else if(k+=h-y,y<b){b-=y;do{S[n++]=d[k++]}while(--y);k=n-v,E=S}for(;b>2;)S[n++]=E[k++],S[n++]=E[k++],S[n++]=E[k++],b-=3;b&&(S[n++]=E[k++],b>1&&(S[n++]=E[k++]))}else{k=n-v;do{S[n++]=S[k++],S[n++]=S[k++],S[n++]=S[k++],b-=3}while(b>2);b&&(S[n++]=S[k++],b>1&&(S[n++]=S[k++]))}break}if(64&y){e.msg="invalid distance code",x.mode=Dt;break e}_=m[(65535&_)+(u&(1<<y)-1)]}}break}}while(r<s&&n<a);b=f>>3,r-=b,f-=b<<3,u&=(1<<f)-1,e.next_in=r,e.next_out=n,e.avail_in=r<s?s-r+5:5-(r-s),e.avail_out=n<a?a-n+257:257-(n-a),x.hold=u,x.bits=f};const At=15,Ht=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),Lt=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),Bt=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),Ot=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]);var Pt=(e,t,r,s,n,i,a,o)=>{const l=o.bits;let c,h,d,u,f,p,m=0,g=0,w=0,_=0,y=0,b=0,v=0,k=0,E=0,T=0,S=null;const x=new Uint16Array(16),z=new Uint16Array(16);let I,R,C,D=null;for(m=0;m<=At;m++)x[m]=0;for(g=0;g<s;g++)x[t[r+g]]++;for(y=l,_=At;_>=1&&0===x[_];_--);if(y>_&&(y=_),0===_)return n[i++]=20971520,n[i++]=20971520,o.bits=1,0;for(w=1;w<_&&0===x[w];w++);for(y<w&&(y=w),k=1,m=1;m<=At;m++)if(k<<=1,k-=x[m],k<0)return-1;if(k>0&&(0===e||1!==_))return-1;for(z[1]=0,m=1;m<At;m++)z[m+1]=z[m]+x[m];for(g=0;g<s;g++)0!==t[r+g]&&(a[z[t[r+g]]++]=g);if(0===e?(S=D=a,p=20):1===e?(S=Ht,D=Lt,p=257):(S=Bt,D=Ot,p=0),T=0,g=0,m=w,f=i,b=y,v=0,d=-1,E=1<<y,u=E-1,1===e&&E>852||2===e&&E>592)return 1;for(;;){I=m-v,a[g]+1<p?(R=0,C=a[g]):a[g]>=p?(R=D[a[g]-p],C=S[a[g]-p]):(R=96,C=0),c=1<<m-v,h=1<<b,w=h;do{h-=c,n[f+(T>>v)+h]=I<<24|R<<16|C}while(0!==h);for(c=1<<m-1;T&c;)c>>=1;if(0!==c?(T&=c-1,T+=c):T=0,g++,0===--x[m]){if(m===_)break;m=t[r+a[g]]}if(m>y&&(T&u)!==d){for(0===v&&(v=y),f+=w,b=m-v,k=1<<b;b+v<_&&(k-=x[b+v],!(k<=0));)b++,k<<=1;if(E+=1<<b,1===e&&E>852||2===e&&E>592)return 1;d=T&u,n[d]=y<<24|b<<16|f-i}}return 0!==T&&(n[f+T]=m-v<<24|64<<16),o.bits=y,0};const{Z_FINISH:Nt,Z_BLOCK:Mt,Z_TREES:Ft,Z_OK:Zt,Z_STREAM_END:qt,Z_NEED_DICT:jt,Z_STREAM_ERROR:$t,Z_DATA_ERROR:Kt,Z_MEM_ERROR:Vt,Z_BUF_ERROR:Xt,Z_DEFLATED:Wt}=de,Jt=16180,Yt=16190,Gt=16191,Qt=16192,er=16194,tr=16199,rr=16200,sr=16206,nr=16209,ir=e=>(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24);function ar(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const or=e=>{if(!e)return 1;const t=e.state;return!t||t.strm!==e||t.mode<Jt||t.mode>16211?1:0},lr=e=>{if(or(e))return $t;const t=e.state;return e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=Jt,t.last=0,t.havedict=0,t.flags=-1,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(852),t.distcode=t.distdyn=new Int32Array(592),t.sane=1,t.back=-1,Zt},cr=e=>{if(or(e))return $t;const t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,lr(e)},hr=(e,t)=>{let r;if(or(e))return $t;const s=e.state;return t<0?(r=0,t=-t):(r=5+(t>>4),t<48&&(t&=15)),t&&(t<8||t>15)?$t:(null!==s.window&&s.wbits!==t&&(s.window=null),s.wrap=r,s.wbits=t,cr(e))},dr=(e,t)=>{if(!e)return $t;const r=new ar;e.state=r,r.strm=e,r.window=null,r.mode=Jt;const s=hr(e,t);return s!==Zt&&(e.state=null),s};let ur,fr,pr=!0;const mr=e=>{if(pr){ur=new Int32Array(512),fr=new Int32Array(32);let t=0;for(;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(Pt(1,e.lens,0,288,ur,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;Pt(2,e.lens,0,32,fr,0,e.work,{bits:5}),pr=!1}e.lencode=ur,e.lenbits=9,e.distcode=fr,e.distbits=5},gr=(e,t,r,s)=>{let n;const i=e.state;return null===i.window&&(i.wsize=1<<i.wbits,i.wnext=0,i.whave=0,i.window=new Uint8Array(i.wsize)),s>=i.wsize?(i.window.set(t.subarray(r-i.wsize,r),0),i.wnext=0,i.whave=i.wsize):(n=i.wsize-i.wnext,n>s&&(n=s),i.window.set(t.subarray(r-s,r-s+n),i.wnext),(s-=n)?(i.window.set(t.subarray(r-s,r),0),i.wnext=s,i.whave=i.wsize):(i.wnext+=n,i.wnext===i.wsize&&(i.wnext=0),i.whave<i.wsize&&(i.whave+=n))),0};var wr={inflateReset:cr,inflateReset2:hr,inflateResetKeep:lr,inflateInit:e=>dr(e,15),inflateInit2:dr,inflate:(e,t)=>{let r,s,n,i,a,o,l,c,h,d,u,f,p,m,g,w,_,y,b,v,k,E,T=0;const S=new Uint8Array(4);let x,z;const I=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(or(e)||!e.output||!e.input&&0!==e.avail_in)return $t;r=e.state,r.mode===Gt&&(r.mode=Qt),a=e.next_out,n=e.output,l=e.avail_out,i=e.next_in,s=e.input,o=e.avail_in,c=r.hold,h=r.bits,d=o,u=l,E=Zt;e:for(;;)switch(r.mode){case Jt:if(0===r.wrap){r.mode=Qt;break}for(;h<16;){if(0===o)break e;o--,c+=s[i++]<<h,h+=8}if(2&r.wrap&&35615===c){0===r.wbits&&(r.wbits=15),r.check=0,S[0]=255&c,S[1]=c>>>8&255,r.check=ce(r.check,S,2,0),c=0,h=0,r.mode=16181;break}if(r.head&&(r.head.done=!1),!(1&r.wrap)||(((255&c)<<8)+(c>>8))%31){e.msg="incorrect header check",r.mode=nr;break}if((15&c)!==Wt){e.msg="unknown compression method",r.mode=nr;break}if(c>>>=4,h-=4,k=8+(15&c),0===r.wbits&&(r.wbits=k),k>15||k>r.wbits){e.msg="invalid window size",r.mode=nr;break}r.dmax=1<<r.wbits,r.flags=0,e.adler=r.check=1,r.mode=512&c?16189:Gt,c=0,h=0;break;case 16181:for(;h<16;){if(0===o)break e;o--,c+=s[i++]<<h,h+=8}if(r.flags=c,(255&r.flags)!==Wt){e.msg="unknown compression method",r.mode=nr;break}if(57344&r.flags){e.msg="unknown header flags set",r.mode=nr;break}r.head&&(r.head.text=c>>8&1),512&r.flags&&4&r.wrap&&(S[0]=255&c,S[1]=c>>>8&255,r.check=ce(r.check,S,2,0)),c=0,h=0,r.mode=16182;case 16182:for(;h<32;){if(0===o)break e;o--,c+=s[i++]<<h,h+=8}r.head&&(r.head.time=c),512&r.flags&&4&r.wrap&&(S[0]=255&c,S[1]=c>>>8&255,S[2]=c>>>16&255,S[3]=c>>>24&255,r.check=ce(r.check,S,4,0)),c=0,h=0,r.mode=16183;case 16183:for(;h<16;){if(0===o)break e;o--,c+=s[i++]<<h,h+=8}r.head&&(r.head.xflags=255&c,r.head.os=c>>8),512&r.flags&&4&r.wrap&&(S[0]=255&c,S[1]=c>>>8&255,r.check=ce(r.check,S,2,0)),c=0,h=0,r.mode=16184;case 16184:if(1024&r.flags){for(;h<16;){if(0===o)break e;o--,c+=s[i++]<<h,h+=8}r.length=c,r.head&&(r.head.extra_len=c),512&r.flags&&4&r.wrap&&(S[0]=255&c,S[1]=c>>>8&255,r.check=ce(r.check,S,2,0)),c=0,h=0}else r.head&&(r.head.extra=null);r.mode=16185;case 16185:if(1024&r.flags&&(f=r.length,f>o&&(f=o),f&&(r.head&&(k=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Uint8Array(r.head.extra_len)),r.head.extra.set(s.subarray(i,i+f),k)),512&r.flags&&4&r.wrap&&(r.check=ce(r.check,s,f,i)),o-=f,i+=f,r.length-=f),r.length))break e;r.length=0,r.mode=16186;case 16186:if(2048&r.flags){if(0===o)break e;f=0;do{k=s[i+f++],r.head&&k&&r.length<65536&&(r.head.name+=String.fromCharCode(k))}while(k&&f<o);if(512&r.flags&&4&r.wrap&&(r.check=ce(r.check,s,f,i)),o-=f,i+=f,k)break e}else r.head&&(r.head.name=null);r.length=0,r.mode=16187;case 16187:if(4096&r.flags){if(0===o)break e;f=0;do{k=s[i+f++],r.head&&k&&r.length<65536&&(r.head.comment+=String.fromCharCode(k))}while(k&&f<o);if(512&r.flags&&4&r.wrap&&(r.check=ce(r.check,s,f,i)),o-=f,i+=f,k)break e}else r.head&&(r.head.comment=null);r.mode=16188;case 16188:if(512&r.flags){for(;h<16;){if(0===o)break e;o--,c+=s[i++]<<h,h+=8}if(4&r.wrap&&c!==(65535&r.check)){e.msg="header crc mismatch",r.mode=nr;break}c=0,h=0}r.head&&(r.head.hcrc=r.flags>>9&1,r.head.done=!0),e.adler=r.check=0,r.mode=Gt;break;case 16189:for(;h<32;){if(0===o)break e;o--,c+=s[i++]<<h,h+=8}e.adler=r.check=ir(c),c=0,h=0,r.mode=Yt;case Yt:if(0===r.havedict)return e.next_out=a,e.avail_out=l,e.next_in=i,e.avail_in=o,r.hold=c,r.bits=h,jt;e.adler=r.check=1,r.mode=Gt;case Gt:if(t===Mt||t===Ft)break e;case Qt:if(r.last){c>>>=7&h,h-=7&h,r.mode=sr;break}for(;h<3;){if(0===o)break e;o--,c+=s[i++]<<h,h+=8}switch(r.last=1&c,c>>>=1,h-=1,3&c){case 0:r.mode=16193;break;case 1:if(mr(r),r.mode=tr,t===Ft){c>>>=2,h-=2;break e}break;case 2:r.mode=16196;break;case 3:e.msg="invalid block type",r.mode=nr}c>>>=2,h-=2;break;case 16193:for(c>>>=7&h,h-=7&h;h<32;){if(0===o)break e;o--,c+=s[i++]<<h,h+=8}if((65535&c)!=(c>>>16^65535)){e.msg="invalid stored block lengths",r.mode=nr;break}if(r.length=65535&c,c=0,h=0,r.mode=er,t===Ft)break e;case er:r.mode=16195;case 16195:if(f=r.length,f){if(f>o&&(f=o),f>l&&(f=l),0===f)break e;n.set(s.subarray(i,i+f),a),o-=f,i+=f,l-=f,a+=f,r.length-=f;break}r.mode=Gt;break;case 16196:for(;h<14;){if(0===o)break e;o--,c+=s[i++]<<h,h+=8}if(r.nlen=257+(31&c),c>>>=5,h-=5,r.ndist=1+(31&c),c>>>=5,h-=5,r.ncode=4+(15&c),c>>>=4,h-=4,r.nlen>286||r.ndist>30){e.msg="too many length or distance symbols",r.mode=nr;break}r.have=0,r.mode=16197;case 16197:for(;r.have<r.ncode;){for(;h<3;){if(0===o)break e;o--,c+=s[i++]<<h,h+=8}r.lens[I[r.have++]]=7&c,c>>>=3,h-=3}for(;r.have<19;)r.lens[I[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,x={bits:r.lenbits},E=Pt(0,r.lens,0,19,r.lencode,0,r.work,x),r.lenbits=x.bits,E){e.msg="invalid code lengths set",r.mode=nr;break}r.have=0,r.mode=16198;case 16198:for(;r.have<r.nlen+r.ndist;){for(;T=r.lencode[c&(1<<r.lenbits)-1],g=T>>>24,w=T>>>16&255,_=65535&T,!(g<=h);){if(0===o)break e;o--,c+=s[i++]<<h,h+=8}if(_<16)c>>>=g,h-=g,r.lens[r.have++]=_;else{if(16===_){for(z=g+2;h<z;){if(0===o)break e;o--,c+=s[i++]<<h,h+=8}if(c>>>=g,h-=g,0===r.have){e.msg="invalid bit length repeat",r.mode=nr;break}k=r.lens[r.have-1],f=3+(3&c),c>>>=2,h-=2}else if(17===_){for(z=g+3;h<z;){if(0===o)break e;o--,c+=s[i++]<<h,h+=8}c>>>=g,h-=g,k=0,f=3+(7&c),c>>>=3,h-=3}else{for(z=g+7;h<z;){if(0===o)break e;o--,c+=s[i++]<<h,h+=8}c>>>=g,h-=g,k=0,f=11+(127&c),c>>>=7,h-=7}if(r.have+f>r.nlen+r.ndist){e.msg="invalid bit length repeat",r.mode=nr;break}for(;f--;)r.lens[r.have++]=k}}if(r.mode===nr)break;if(0===r.lens[256]){e.msg="invalid code -- missing end-of-block",r.mode=nr;break}if(r.lenbits=9,x={bits:r.lenbits},E=Pt(1,r.lens,0,r.nlen,r.lencode,0,r.work,x),r.lenbits=x.bits,E){e.msg="invalid literal/lengths set",r.mode=nr;break}if(r.distbits=6,r.distcode=r.distdyn,x={bits:r.distbits},E=Pt(2,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,x),r.distbits=x.bits,E){e.msg="invalid distances set",r.mode=nr;break}if(r.mode=tr,t===Ft)break e;case tr:r.mode=rr;case rr:if(o>=6&&l>=258){e.next_out=a,e.avail_out=l,e.next_in=i,e.avail_in=o,r.hold=c,r.bits=h,Ut(e,u),a=e.next_out,n=e.output,l=e.avail_out,i=e.next_in,s=e.input,o=e.avail_in,c=r.hold,h=r.bits,r.mode===Gt&&(r.back=-1);break}for(r.back=0;T=r.lencode[c&(1<<r.lenbits)-1],g=T>>>24,w=T>>>16&255,_=65535&T,!(g<=h);){if(0===o)break e;o--,c+=s[i++]<<h,h+=8}if(w&&!(240&w)){for(y=g,b=w,v=_;T=r.lencode[v+((c&(1<<y+b)-1)>>y)],g=T>>>24,w=T>>>16&255,_=65535&T,!(y+g<=h);){if(0===o)break e;o--,c+=s[i++]<<h,h+=8}c>>>=y,h-=y,r.back+=y}if(c>>>=g,h-=g,r.back+=g,r.length=_,0===w){r.mode=16205;break}if(32&w){r.back=-1,r.mode=Gt;break}if(64&w){e.msg="invalid literal/length code",r.mode=nr;break}r.extra=15&w,r.mode=16201;case 16201:if(r.extra){for(z=r.extra;h<z;){if(0===o)break e;o--,c+=s[i++]<<h,h+=8}r.length+=c&(1<<r.extra)-1,c>>>=r.extra,h-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=16202;case 16202:for(;T=r.distcode[c&(1<<r.distbits)-1],g=T>>>24,w=T>>>16&255,_=65535&T,!(g<=h);){if(0===o)break e;o--,c+=s[i++]<<h,h+=8}if(!(240&w)){for(y=g,b=w,v=_;T=r.distcode[v+((c&(1<<y+b)-1)>>y)],g=T>>>24,w=T>>>16&255,_=65535&T,!(y+g<=h);){if(0===o)break e;o--,c+=s[i++]<<h,h+=8}c>>>=y,h-=y,r.back+=y}if(c>>>=g,h-=g,r.back+=g,64&w){e.msg="invalid distance code",r.mode=nr;break}r.offset=_,r.extra=15&w,r.mode=16203;case 16203:if(r.extra){for(z=r.extra;h<z;){if(0===o)break e;o--,c+=s[i++]<<h,h+=8}r.offset+=c&(1<<r.extra)-1,c>>>=r.extra,h-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){e.msg="invalid distance too far back",r.mode=nr;break}r.mode=16204;case 16204:if(0===l)break e;if(f=u-l,r.offset>f){if(f=r.offset-f,f>r.whave&&r.sane){e.msg="invalid distance too far back",r.mode=nr;break}f>r.wnext?(f-=r.wnext,p=r.wsize-f):p=r.wnext-f,f>r.length&&(f=r.length),m=r.window}else m=n,p=a-r.offset,f=r.length;f>l&&(f=l),l-=f,r.length-=f;do{n[a++]=m[p++]}while(--f);0===r.length&&(r.mode=rr);break;case 16205:if(0===l)break e;n[a++]=r.length,l--,r.mode=rr;break;case sr:if(r.wrap){for(;h<32;){if(0===o)break e;o--,c|=s[i++]<<h,h+=8}if(u-=l,e.total_out+=u,r.total+=u,4&r.wrap&&u&&(e.adler=r.check=r.flags?ce(r.check,n,u,a-u):oe(r.check,n,u,a-u)),u=l,4&r.wrap&&(r.flags?c:ir(c))!==r.check){e.msg="incorrect data check",r.mode=nr;break}c=0,h=0}r.mode=16207;case 16207:if(r.wrap&&r.flags){for(;h<32;){if(0===o)break e;o--,c+=s[i++]<<h,h+=8}if(4&r.wrap&&c!==(4294967295&r.total)){e.msg="incorrect length check",r.mode=nr;break}c=0,h=0}r.mode=16208;case 16208:E=qt;break e;case nr:E=Kt;break e;case 16210:return Vt;default:return $t}return e.next_out=a,e.avail_out=l,e.next_in=i,e.avail_in=o,r.hold=c,r.bits=h,(r.wsize||u!==e.avail_out&&r.mode<nr&&(r.mode<sr||t!==Nt))&&gr(e,e.output,e.next_out,u-e.avail_out),d-=e.avail_in,u-=e.avail_out,e.total_in+=d,e.total_out+=u,r.total+=u,4&r.wrap&&u&&(e.adler=r.check=r.flags?ce(r.check,n,u,e.next_out-u):oe(r.check,n,u,e.next_out-u)),e.data_type=r.bits+(r.last?64:0)+(r.mode===Gt?128:0)+(r.mode===tr||r.mode===er?256:0),(0===d&&0===u||t===Nt)&&E===Zt&&(E=Xt),E},inflateEnd:e=>{if(or(e))return $t;let t=e.state;return t.window&&(t.window=null),e.state=null,Zt},inflateGetHeader:(e,t)=>{if(or(e))return $t;const r=e.state;return 2&r.wrap?(r.head=t,t.done=!1,Zt):$t},inflateSetDictionary:(e,t)=>{const r=t.length;let s,n,i;return or(e)?$t:(s=e.state,0!==s.wrap&&s.mode!==Yt?$t:s.mode===Yt&&(n=1,n=oe(n,t,r,0),n!==s.check)?Kt:(i=gr(e,t,r,r),i?(s.mode=16210,Vt):(s.havedict=1,Zt)))},inflateInfo:"pako inflate (from Nodeca project)"};var _r=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const yr=Object.prototype.toString,{Z_NO_FLUSH:br,Z_FINISH:vr,Z_OK:kr,Z_STREAM_END:Er,Z_NEED_DICT:Tr,Z_STREAM_ERROR:Sr,Z_DATA_ERROR:xr,Z_MEM_ERROR:zr}=de;function Ir(e){this.options=ht({chunkSize:65536,windowBits:15,to:""},e||{});const t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(t.windowBits>=0&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&(15&t.windowBits||(t.windowBits|=15)),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new wt,this.strm.avail_out=0;let r=wr.inflateInit2(this.strm,t.windowBits);if(r!==kr)throw new Error(he[r]);if(this.header=new _r,wr.inflateGetHeader(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=pt(t.dictionary):"[object ArrayBuffer]"===yr.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(r=wr.inflateSetDictionary(this.strm,t.dictionary),r!==kr)))throw new Error(he[r])}function Rr(e,t){const r=new Ir(t);if(r.push(e),r.err)throw r.msg||he[r.err];return r.result}Ir.prototype.push=function(e,t){const r=this.strm,s=this.options.chunkSize,n=this.options.dictionary;let i,a,o;if(this.ended)return!1;for(a=t===~~t?t:!0===t?vr:br,"[object ArrayBuffer]"===yr.call(e)?r.input=new Uint8Array(e):r.input=e,r.next_in=0,r.avail_in=r.input.length;;){for(0===r.avail_out&&(r.output=new Uint8Array(s),r.next_out=0,r.avail_out=s),i=wr.inflate(r,a),i===Tr&&n&&(i=wr.inflateSetDictionary(r,n),i===kr?i=wr.inflate(r,a):i===xr&&(i=Tr));r.avail_in>0&&i===Er&&r.state.wrap>0&&0!==e[r.next_in];)wr.inflateReset(r),i=wr.inflate(r,a);switch(i){case Sr:case xr:case Tr:case zr:return this.onEnd(i),this.ended=!0,!1}if(o=r.avail_out,r.next_out&&(0===r.avail_out||i===Er))if("string"===this.options.to){let e=gt(r.output,r.next_out),t=r.next_out-e,n=mt(r.output,e);r.next_out=t,r.avail_out=s-t,t&&r.output.set(r.output.subarray(e,e+t),0),this.onData(n)}else this.onData(r.output.length===r.next_out?r.output:r.output.subarray(0,r.next_out));if(i!==kr||0!==o){if(i===Er)return i=wr.inflateEnd(this.strm),this.onEnd(i),this.ended=!0,!0;if(0===r.avail_in)break}}return!0},Ir.prototype.onData=function(e){this.chunks.push(e)},Ir.prototype.onEnd=function(e){e===kr&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=dt(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var Cr={Inflate:Ir,inflate:Rr,inflateRaw:function(e,t){return(t=t||{}).raw=!0,Rr(e,t)},ungzip:Rr};const{Deflate:Dr,deflate:Ur,deflateRaw:Ar,gzip:Hr}=Ct,{Inflate:Lr,inflate:Br,inflateRaw:Or,ungzip:Pr}=Cr;var Nr={Deflate:Dr,deflate:Ur,deflateRaw:Ar,gzip:Hr,Inflate:Lr,inflate:Br,inflateRaw:Or,ungzip:Pr,constants:de};class Mr{compress(e){try{const t=Nr.deflate(e);if("undefined"!=typeof btoa){let e="";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return btoa(e)}return"undefined"!=typeof Buffer?Buffer.from(t).toString("base64"):e}catch(t){return console.error("Compressor: Error compressing data:",t),e}}decompress(e){try{let t;if("undefined"!=typeof atob){const r=atob(e);t=new Uint8Array(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e)}else{if("undefined"==typeof Buffer)return e;{const r=Buffer.from(e,"base64");t=new Uint8Array(r)}}return Nr.inflate(t,{to:"string"})}catch(t){return console.error("Compressor: Error decompressing data:",t),e}}shouldCompress(e){return e.length>1024}}class Fr{constructor(){r(this,"sampler"),r(this,"deduplicator"),r(this,"compressor"),this.sampler=new k,this.deduplicator=new E,this.compressor=new Mr}process(e,t={}){const{sampleRate:r=1,enableDeduplication:s=!0,enableCompression:n=!1,isCritical:i=!1}=t;if(!this.sampler.shouldSampleCritical(i,r))return null;if(s&&this.deduplicator.isDuplicate(e))return null;const a=d(e);if(n&&a.properties){const e=JSON.stringify(a.properties);this.compressor.shouldCompress(e)&&(a.compressedProperties=this.compressor.compress(e),delete a.properties)}return a}processBatch(e,t={}){return e.map(e=>this.process(e,t)).filter(e=>null!==e)}serialize(e){try{return JSON.stringify(e)}catch(t){return console.error("DataProcessor: Error serializing event:",t),""}}deserialize(e){try{return JSON.parse(e)}catch(t){return console.error("DataProcessor: Error deserializing event:",t),null}}}function Zr(){if("undefined"!=typeof AbortController)return AbortController;class e{constructor(){r(this,"aborted",!1)}abort(){this.aborted=!0}}return class{constructor(){r(this,"signal"),this.signal=new e}abort(){this.signal.abort()}}}async function qr(e,t){return new Promise((r,s)=>{const n=new XMLHttpRequest,i=(null==t?void 0:t.method)||"GET";if(n.open(i,e,!0),null==t?void 0:t.headers){new Headers(t.headers).forEach((e,t)=>{null!=e&&n.setRequestHeader(t,String(e))})}if(null==t?void 0:t.signal){if(t.signal.aborted)return void s(new DOMException("Aborted","AbortError"))}n.onload=()=>{const t=n.getAllResponseHeaders(),s={};t.split("\n").forEach(e=>{const t=e.split(": ");t[0]&&t[1]&&(s[t[0].toLowerCase()]=t[1])});const i=new Headers(s),a=n.responseText||"",o=n.responseURL||e,l=n.status,c={ok:l>=200&&l<300,status:l,statusText:n.statusText,type:"basic",url:o,headers:i,redirected:!1,body:null,bodyUsed:!1,arrayBuffer:()=>Promise.resolve(new ArrayBuffer(0)),blob:()=>Promise.resolve(new Blob),formData:()=>Promise.resolve(new FormData),json:async()=>{try{return JSON.parse(a||"{}")}catch{throw new TypeError("Invalid JSON response")}},text:()=>Promise.resolve(a),clone:()=>({...c,headers:new Headers(s)})};r(c)},n.onerror=()=>{s(new TypeError("Network request failed"))},n.ontimeout=()=>{s(new Error("Request timeout"))};const a=null==t?void 0:t.body;a instanceof FormData||a instanceof Blob||"string"==typeof a||null===a?n.send(a):a?n.send(String(a)):n.send(null)})}async function jr(e,t={}){const{method:r="POST",headers:s={},body:n,timeout:i=1e4}=t,a=new(Zr()),o=setTimeout(()=>a.abort(),i);try{const t=function(){if("function"==typeof fetch)try{return new(Zr()),fetch}catch{return qr}if("undefined"!=typeof XMLHttpRequest)return qr;throw new Error("fetch is not available and XMLHttpRequest fallback is not supported")}(),i=await t(e,{method:r,headers:{"Content-Type":"application/json",...s},body:n,signal:a.signal});let l;clearTimeout(o);const c=i.headers.get("content-type");return l=c&&c.includes("application/json")?await i.json():await i.text(),{ok:i.ok,status:i.status,statusText:i.statusText,data:l}}catch(l){throw clearTimeout(o),l}}async function $r(e,t={}){var r;return"undefined"!=typeof process&&(null==(r=process.versions)?void 0:r.node)?async function(e,t={}){var r;const{method:s="POST",headers:n={},body:i,timeout:a=1e4}=t;try{let t;try{const e=await import("node-fetch");t=e.default||e}catch(o){if("undefined"!=typeof process&&(null==(r=process.versions)?void 0:r.node))throw new Error("node-fetch is required in Node.js environment. Please install it: pnpm add node-fetch");throw new Error("Network request failed: node-fetch not available")}const c=new(Zr()),h=setTimeout(()=>c.abort(),a);try{const r=await t(e,{method:s,headers:{"Content-Type":"application/json",...n},body:i,signal:c.signal});let a;clearTimeout(h);const o=r.headers.get("content-type");return a=o&&o.includes("application/json")?await r.json():await r.text(),{ok:r.ok,status:r.status,statusText:r.statusText,data:a}}catch(l){throw clearTimeout(h),l}}catch(l){throw l}}(e,t):jr(e,t)}function Kr(e,t,r={}){return $r(e,{...r,method:"POST",body:"string"==typeof t?t:JSON.stringify(t)})}class Vr{async execute(e,t={}){const{maxRetries:r=3,initialDelay:s=1e3,maxDelay:n=1e4,shouldRetry:i=()=>!0}=t;let a,o=s;for(let c=0;c<=r;c++)try{return await e()}catch(l){if(a=l,!(c<r&&i(l)))break;await this.sleep(o),o=Math.min(2*o,n)}throw a}sleep(e){return new Promise(t=>setTimeout(t,e))}isRetryableError(e){if(e instanceof Error){const t=e.message.toLowerCase();return t.includes("network")||t.includes("timeout")||t.includes("fetch")||t.includes("connection")}return!1}}class Xr{constructor(e){r(this,"serverUrl"),r(this,"retryHandler"),this.serverUrl=e,this.retryHandler=new Vr}async send(e,t={}){if(!this.serverUrl||"about:blank"===this.serverUrl)return!1;const{enableRetry:r=!0,maxRetries:s=3}=t;try{if(r)await this.retryHandler.execute(async()=>{const t=await Kr(this.serverUrl,e);if(!t.ok)throw new Error(`HTTP ${t.status}: ${t.statusText}`);return t},{maxRetries:s,shouldRetry:e=>this.retryHandler.isRetryableError(e)});else{const t=await Kr(this.serverUrl,e);if(!t.ok)throw new Error(`HTTP ${t.status}: ${t.statusText}`)}return!0}catch(n){return console.error("Sender: Error sending event:",n),!1}}async sendBatch(e,t={}){if(0===e.length)return!0;if(!this.serverUrl||"about:blank"===this.serverUrl)return!1;const{enableRetry:r=!0,maxRetries:s=3}=t;try{if(r)await this.retryHandler.execute(async()=>{const t=await Kr(this.serverUrl,{events:e});if(!t.ok)throw new Error(`HTTP ${t.status}: ${t.statusText}`);return t},{maxRetries:s,shouldRetry:e=>this.retryHandler.isRetryableError(e)});else{const t=await Kr(this.serverUrl,{events:e});if(!t.ok)throw new Error(`HTTP ${t.status}: ${t.statusText}`)}return!0}catch(n){return console.error("Sender: Error sending batch events:",n),!1}}setServerUrl(e){this.serverUrl=e}}const Wr=new class{constructor(){if(r(this,"storage",null),"undefined"!=typeof window&&window.localStorage)try{const e="__tracker_test__";window.localStorage.setItem(e,e),window.localStorage.removeItem(e),this.storage=window.localStorage}catch(e){}}getItem(e){if(!this.storage)return null;try{return this.storage.getItem(e)}catch(t){return null}}setItem(e,t){if(this.storage)try{this.storage.setItem(e,t)}catch(r){}}removeItem(e){if(this.storage)try{this.storage.removeItem(e)}catch(t){}}clear(){if(this.storage)try{this.storage.clear()}catch(e){}}},Jr=new class{constructor(){if(r(this,"storage",null),"undefined"!=typeof window&&window.sessionStorage)try{const e="__tracker_test__";window.sessionStorage.setItem(e,e),window.sessionStorage.removeItem(e),this.storage=window.sessionStorage}catch(e){}}getItem(e){if(!this.storage)return null;try{return this.storage.getItem(e)}catch(t){return null}}setItem(e,t){if(this.storage)try{this.storage.setItem(e,t)}catch(r){}}removeItem(e){if(this.storage)try{this.storage.removeItem(e)}catch(t){}}clear(){if(this.storage)try{this.storage.clear()}catch(e){}}},Yr=new class{constructor(){r(this,"data",new Map)}getItem(e){return this.data.get(e)||null}setItem(e,t){this.data.set(e,t)}removeItem(e){this.data.delete(e)}clear(){this.data.clear()}},Gr=new class{constructor(){r(this,"dbName","__tracker_db__"),r(this,"storeName","__tracker_store__"),r(this,"db",null),r(this,"initPromise",null)}async init(){return!!this.db||(this.initPromise?this.initPromise:!("undefined"==typeof window||!window.indexedDB)&&(this.initPromise=new Promise(e=>{const t=indexedDB.open(this.dbName,1);t.onerror=()=>{this.initPromise=null,e(!1)},t.onsuccess=()=>{this.db=t.result,this.initPromise=null,e(!0)},t.onupgradeneeded=e=>{const t=e.target.result;if(!t.objectStoreNames.contains(this.storeName)){t.createObjectStore(this.storeName,{keyPath:"id",autoIncrement:!0}).createIndex("key","key",{unique:!0})}}}),this.initPromise))}async getItem(e){return this.db||await this.init(),this.db?new Promise(t=>{let r;try{r=this.db.transaction([this.storeName],"readonly")}catch(n){return console.error("IndexedDBStorage: Error creating transaction for get:",n),void t(null)}r.onerror=()=>{console.error("IndexedDBStorage: Transaction error in get:",r.error),t(null)},r.onabort=()=>{console.error("IndexedDBStorage: Transaction aborted in get"),t(null)};const s=r.objectStore(this.storeName).index("key").get(e);s.onsuccess=()=>{const e=s.result;t(e?e.value:null)},s.onerror=()=>{console.error("IndexedDBStorage: Error in get request:",s.error),t(null)}}):null}async setItem(e,t){return this.db||await this.init(),!!this.db&&new Promise(r=>{let s;try{s=this.db.transaction([this.storeName],"readwrite")}catch(a){return console.error("IndexedDBStorage: Error creating transaction:",a),void r(!1)}s.onerror=()=>{console.error("IndexedDBStorage: Transaction error:",s.error),r(!1)},s.onabort=()=>{console.error("IndexedDBStorage: Transaction aborted"),r(!1)};const n=s.objectStore(this.storeName),i=n.index("key").get(e);i.onsuccess=()=>{const s={key:e,value:t,updatedAt:Date.now()};let a;i.result?(s.id=i.result.id,a=n.put(s)):a=n.add(s),a.onsuccess=()=>{r(!0)},a.onerror=()=>{console.error("IndexedDBStorage: Error in put/add request:",a.error),r(!1)}},i.onerror=()=>{console.error("IndexedDBStorage: Error in get request:",i.error),r(!1)}})}async removeItem(e){return!!this.db&&new Promise(t=>{let r;try{r=this.db.transaction([this.storeName],"readwrite")}catch(i){return console.error("IndexedDBStorage: Error creating transaction for remove:",i),void t(!1)}r.onerror=()=>{console.error("IndexedDBStorage: Transaction error in remove:",r.error),t(!1)},r.onabort=()=>{console.error("IndexedDBStorage: Transaction aborted in remove"),t(!1)};const s=r.objectStore(this.storeName),n=s.index("key").get(e);n.onsuccess=()=>{if(n.result){const e=s.delete(n.result.id);e.onsuccess=()=>t(!0),e.onerror=()=>{console.error("IndexedDBStorage: Error in delete request:",e.error),t(!1)}}else t(!0)},n.onerror=()=>{console.error("IndexedDBStorage: Error in get request for remove:",n.error),t(!1)}})}async getAll(){return this.db||await this.init(),this.db?new Promise(e=>{const t=this.db.transaction([this.storeName],"readonly").objectStore(this.storeName).getAll();t.onsuccess=()=>{const r=t.result.map(e=>({key:e.key,value:e.value}));e(r)},t.onerror=()=>{e([])}}):[]}};class Qr{constructor(e=1e3){if(r(this,"storageKey","__tracker_offline_events__"),r(this,"maxSize"),r(this,"useIndexedDB",!0),r(this,"memoryStorage",new Map),r(this,"saveQueue",Promise.resolve()),e<=0)throw new Error("OfflineStorage: maxSize must be positive");this.maxSize=e}async init(){await Gr.init()||(this.useIndexedDB=!1,console.warn("OfflineStorage: IndexedDB initialization failed, will use memory storage as fallback"))}async save(e){try{return this.saveQueue=this.saveQueue.then(async()=>{await this.doSave(e)}).catch(e=>{throw console.error("OfflineStorage: Error in save queue:",e),e}),await this.saveQueue,!0}catch(t){console.error("OfflineStorage: Error saving event:",t);try{const t=this.memoryStorage.get(this.storageKey)||[];return t.length>=this.maxSize&&t.shift(),t.push(this.sanitizeEvent(e)),this.memoryStorage.set(this.storageKey,t),!0}catch(r){return console.error("OfflineStorage: Fallback storage also failed:",r),!1}}}async doSave(e){try{const t=this.sanitizeEvent(e),r=await this.getAll();if(r.length>=this.maxSize&&r.shift(),r.push(t),this.useIndexedDB){const e=this.safeStringify(r);if(!e)throw new Error("Failed to stringify events");await Gr.setItem(this.storageKey,e)||(this.useIndexedDB=!1,this.memoryStorage.set(this.storageKey,r))}else this.memoryStorage.set(this.storageKey,r)}catch(t){if(console.error("OfflineStorage: Error in doSave:",t),!this.useIndexedDB)throw t;this.useIndexedDB=!1;try{const t=this.memoryStorage.get(this.storageKey)||[];t.length>=this.maxSize&&t.shift(),t.push(this.sanitizeEvent(e)),this.memoryStorage.set(this.storageKey,t)}catch(r){throw r}}}sanitizeEvent(e){return{...e,properties:e.properties?this.sanitizeObject(e.properties):void 0}}sanitizeObject(e,t=new WeakSet){if("object"!=typeof e||null===e)return e;if(t.has(e))return{};t.add(e);const r={};for(const[s,n]of Object.entries(e))r[s]="object"==typeof n&&null!==n?this.sanitizeObject(n,t):n;return r}safeStringify(e){try{return JSON.stringify(e)}catch(t){try{if("object"==typeof e&&null!==e){const t=this.sanitizeObject(e);return JSON.stringify(t)}return JSON.stringify(e)}catch(r){return console.error("OfflineStorage: Failed to stringify after sanitization:",r),null}}}async getAll(){try{if(this.useIndexedDB){const e=await Gr.getItem(this.storageKey);return e?JSON.parse(e):[]}return this.memoryStorage.get(this.storageKey)||[]}catch(e){return console.error("OfflineStorage: Error getting events:",e),this.useIndexedDB?(this.useIndexedDB=!1,this.memoryStorage.get(this.storageKey)||[]):[]}}async remove(e){try{const t=await this.getAll(),r=new Map(e.map(e=>[this.getEventKey(e),e])),s=t.filter(e=>!r.has(this.getEventKey(e)));if(0===s.length)return this.useIndexedDB?await Gr.removeItem(this.storageKey):this.memoryStorage.delete(this.storageKey),!0;if(this.useIndexedDB){const e=this.safeStringify(s);if(!e)throw new Error("Failed to stringify remaining events");const t=await Gr.setItem(this.storageKey,e);return t||(this.useIndexedDB=!1,this.memoryStorage.set(this.storageKey,s),!0)}return this.memoryStorage.set(this.storageKey,s),!0}catch(t){return console.error("OfflineStorage: Error removing events:",t),!1}}async clear(){try{return this.useIndexedDB?await Gr.removeItem(this.storageKey):this.memoryStorage.delete(this.storageKey),!0}catch(e){return console.error("OfflineStorage: Error clearing events:",e),!1}}async getCount(){return(await this.getAll()).length}getEventKey(e){return`${e.type}-${e.name}-${e.timestamp}-${e.url}`}}class es{constructor(e,t={}){r(this,"sender"),r(this,"offlineStorage"),r(this,"queue",[]),r(this,"timer",null),r(this,"batchSize"),r(this,"batchWait"),r(this,"enableOfflineStorage"),r(this,"isProcessing",!1),r(this,"isInitialized",!1),r(this,"initPromise",null),r(this,"eventCallbacks",new Map),this.sender=new Xr(e),this.offlineStorage=new Qr(t.maxOfflineStorageSize??1e3),this.batchSize=t.batchSize||10,this.batchWait=t.batchWait||5e3,this.enableOfflineStorage=t.enableOfflineStorage??!0,this.initPromise=this.init()}async init(){this.enableOfflineStorage&&(await this.offlineStorage.init(),this.flushOfflineEvents()),this.isInitialized=!0}async ensureInitialized(){!this.isInitialized&&this.initPromise&&await this.initPromise}add(e,t){this.queue.push(e),(null==t?void 0:t.onBatchComplete)&&this.eventCallbacks.set(e,t),this.queue.length>=this.batchSize?this.flush():this.timer||(this.timer=setTimeout(()=>{this.flush()},this.batchWait))}async addAsync(e){await this.ensureInitialized(),this.add(e)}async flush(){if(this.isProcessing||0===this.queue.length)return;await this.ensureInitialized(),this.isProcessing=!0,this.timer&&(clearTimeout(this.timer),this.timer=null);const e=[...this.queue];this.queue=[];const t=new Map;e.forEach(e=>{const r=this.eventCallbacks.get(e);if(null==r?void 0:r.onBatchComplete){const s=r.onBatchComplete;t.has(s)||t.set(s,[]),t.get(s).push(e)}this.eventCallbacks.delete(e)});try{const r=await this.sender.sendBatch(e);if(!r&&this.enableOfflineStorage)for(const t of e)await this.offlineStorage.save(t);t.forEach((e,t)=>{try{t(e,r)}catch(s){console.error("BatchSender: Error in batch complete callback:",s)}})}catch(r){if(console.error("BatchSender: Error flushing events:",r),this.enableOfflineStorage)for(const t of e)await this.offlineStorage.save(t);t.forEach((e,t)=>{try{t(e,!1)}catch(r){console.error("BatchSender: Error in batch complete callback:",r)}})}finally{this.isProcessing=!1,this.queue.length>0&&setTimeout(()=>{this.flush().catch(e=>{console.error("BatchSender: Error in recursive flush:",e)})},0)}}async flushOfflineEvents(){try{const e=await this.offlineStorage.getAll();if(0===e.length)return;const t=this.batchSize;for(let r=0;r<e.length;r+=t){const s=e.slice(r,r+t);if(!(await this.sender.sendBatch(s)))break;await this.offlineStorage.remove(s)}}catch(e){console.error("BatchSender: Error flushing offline events:",e)}}setServerUrl(e){this.sender.setServerUrl(e)}async getOfflineEvents(){return await this.ensureInitialized(),this.offlineStorage.getAll()}async getOfflineEventCount(){return await this.ensureInitialized(),this.offlineStorage.getCount()}async clearOfflineStorage(){return await this.ensureInitialized(),this.offlineStorage.clear()}destroy(){this.timer&&(clearTimeout(this.timer),this.timer=null),this.flush().catch(e=>{console.error("BatchSender: Error during destroy flush:",e)})}async destroyAsync(){this.timer&&(clearTimeout(this.timer),this.timer=null),await this.flush()}}class ts{constructor(){r(this,"plugins",new Map),r(this,"trackerInstance",null)}setTrackerInstance(e){this.trackerInstance=e}use(e){if(this.plugins.has(e.name))console.warn(`PluginManager: Plugin "${e.name}" is already installed`);else if(this.trackerInstance)try{e.install(this.trackerInstance),this.plugins.set(e.name,e)}catch(t){console.error(`PluginManager: Error installing plugin "${e.name}":`,t)}else console.error("PluginManager: Tracker instance is not set")}unuse(e){const t=this.plugins.get(e);if(t){if(t.uninstall&&this.trackerInstance)try{t.uninstall(this.trackerInstance)}catch(r){console.error(`PluginManager: Error uninstalling plugin "${e}":`,r)}this.plugins.delete(e)}}get(e){return this.plugins.get(e)}getAll(){return Array.from(this.plugins.values())}clear(){for(const e of this.plugins.keys())this.unuse(e)}}class rs{constructor(){r(this,"pageViews",[]),r(this,"startTime",Date.now())}analyzePageView(e){this.pageViews.push(e)}getMetrics(){const e=new Set,t=new Set;let r=0;const s=[];return this.pageViews.forEach(n=>{n.deviceId&&e.add(n.deviceId),n.sessionId&&t.add(n.sessionId),n.duration&&(r+=n.duration),s.push(n.url)}),{pv:this.pageViews.length,uv:e.size,sessions:t.size,avgDuration:this.pageViews.length>0?r/this.pageViews.length:0,paths:s}}getVisitPath(){return this.pageViews.map(e=>e.url)}getDuration(){return Date.now()-this.startTime}reset(){this.pageViews=[],this.startTime=Date.now()}}class ss{constructor(){r(this,"snapshots",[]),r(this,"interactions",[]),r(this,"observer",null),r(this,"isRecording",!1),r(this,"maxSnapshots",1e3),r(this,"mutationHandler",null),r(this,"throttledMouseMoveHandler",null),r(this,"handleClick",e=>{var t;this.recordInteraction({type:"click",timestamp:Date.now(),data:{x:e.clientX,y:e.clientY,target:null==(t=e.target)?void 0:t.tagName}})}),r(this,"handleInput",e=>{const t=e.target;t&&this.recordInteraction({type:"input",timestamp:Date.now(),data:{tagName:t.tagName,value:t.value.substring(0,100)}})}),r(this,"handleScroll",()=>{this.recordInteraction({type:"scroll",timestamp:Date.now(),data:{scrollX:window.scrollX,scrollY:window.scrollY}})}),r(this,"handleMouseMove",e=>{this.recordInteraction({type:"mousemove",timestamp:Date.now(),data:{x:e.clientX,y:e.clientY}})})}start(){this.isRecording||"undefined"==typeof document||(this.isRecording=!0,this.takeSnapshot(),this.mutationHandler=h((...e)=>{const t=e[0];this.recordMutations(t)},100),this.observer=new MutationObserver(this.mutationHandler),this.observer.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0,characterData:!0}),this.setupInteractionListeners())}stop(){this.isRecording&&(this.isRecording=!1,this.observer&&(this.observer.disconnect(),this.observer=null),this.removeInteractionListeners())}takeSnapshot(){this.snapshots.length>=this.maxSnapshots&&this.snapshots.shift();try{const e={timestamp:Date.now(),html:document.documentElement.outerHTML,mutations:[]};this.snapshots.push(e)}catch(e){console.error("SessionReplay: Error taking snapshot:",e)}}recordMutations(e){if(0===this.snapshots.length)return;this.snapshots[this.snapshots.length-1].mutations.push(...e)}setupInteractionListeners(){"undefined"!=typeof window&&(document.addEventListener("click",this.handleClick,!0),document.addEventListener("input",this.handleInput,!0),window.addEventListener("scroll",this.handleScroll,{passive:!0}),this.throttledMouseMoveHandler=h((...e)=>{const t=e[0];this.handleMouseMove(t)},100),document.addEventListener("mousemove",this.throttledMouseMoveHandler,{passive:!0}))}removeInteractionListeners(){"undefined"!=typeof document&&(document.removeEventListener("click",this.handleClick,!0),document.removeEventListener("input",this.handleInput,!0),window.removeEventListener("scroll",this.handleScroll,{passive:!0}),this.throttledMouseMoveHandler&&(document.removeEventListener("mousemove",this.throttledMouseMoveHandler,{passive:!0}),this.throttledMouseMoveHandler=null))}recordInteraction(e){this.interactions.length>=this.maxSnapshots&&this.interactions.shift(),this.interactions.push(e)}getData(){return{snapshots:[...this.snapshots],interactions:[...this.interactions]}}clear(){this.snapshots=[],this.interactions=[]}destroy(){this.stop(),this.clear()}}const ns={enabled:!0,recordRequestBody:!0,recordResponseBody:!0,maxResponseBodySize:102400,maxRequestBodySize:102400,onlyFailedRequests:!1};function is(e,t){return!t||("string"==typeof t?e.includes(t):t instanceof RegExp?t.test(e):"function"!=typeof t||t(e))}function as(e,t){if(!e||"object"!=typeof e||0===t.length)return e;if(Array.isArray(e))return e.map(e=>as(e,t));const r={};for(const[s,n]of Object.entries(e)){const e=s.toLowerCase(),i=t.some(t=>e.includes(t.toLowerCase()));r[s]=i?"[FILTERED]":"object"==typeof n&&null!==n?as(n,t):n}return r}function os(e={}){const t={...ns,...e};let r=null,s=null,n=null,i=null;const a=new Map;return{name:"network-interceptor",install(e){if(t.enabled&&"undefined"!=typeof window&&(void 0!==window.fetch&&(r=window.fetch,window.fetch=async function(s,n){const i="string"==typeof s?s:s instanceof URL?s.href:s.url,c=(null==n?void 0:n.method)||("string"==typeof s||s instanceof URL||!("method"in s)?void 0:s.method)||"GET";if(!is(i,t.urlFilter))return r.call(this,s,n);const h=`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,d=Date.now(),u={};let f;if("string"!=typeof s&&!(s instanceof URL)&&"headers"in s&&s.headers instanceof Headers&&s.headers.forEach((e,t)=>{u[t]=e}),(null==n?void 0:n.headers)&&(n.headers instanceof Headers?n.headers.forEach((e,t)=>{u[t]=e}):Array.isArray(n.headers)?n.headers.forEach(([e,t])=>{u[e]=t}):Object.assign(u,n.headers)),t.recordRequestBody){const e=(null==n?void 0:n.body)??("string"==typeof s||s instanceof URL||!("body"in s)?null:s.body);if(f=await async function(e,t,r){if(e&&r)try{if("string"==typeof e)return e.length>t?e.substring(0,t)+"...[TRUNCATED]":e;if(e instanceof FormData){const t={};for(const[r,s]of e.entries())s instanceof File?t[r]=`[File: ${s.name}, ${s.size} bytes]`:t[r]=s;return t}if(e instanceof URLSearchParams)return Object.fromEntries(e.entries());if(e instanceof Blob){if(e.size>t)return`[Blob: ${e.size} bytes, type: ${e.type}]`;try{return await e.text()}catch{return`[Blob: ${e.size} bytes, type: ${e.type}]`}}return e instanceof ArrayBuffer?e.byteLength>t?`[ArrayBuffer: ${e.byteLength} bytes]`:(new TextDecoder).decode(e):"[Unsupported body type]"}catch(s){return console.warn("NetworkInterceptor: Failed to read request body:",s),"[Error reading body]"}}(e,t.maxRequestBodySize,t.recordRequestBody),t.sensitiveFields&&t.sensitiveFields.length>0&&void 0!==f)if("string"==typeof f)try{f=as(JSON.parse(f),t.sensitiveFields)}catch{f=as(f,t.sensitiveFields)}else f=as(f,t.sensitiveFields)}a.set(h,{url:i,method:c,headers:u,startTime:d,requestBody:f});const p={type:"custom",name:"custom",eventName:"api-request",timestamp:d,url:o(),title:l(),properties:{url:i.split("?")[0].split("#")[0],fullUrl:i,method:c,headers:t.sensitiveFields&&t.sensitiveFields.length>0?as(u,t.sensitiveFields):u,body:f,timestamp:d}};e.send(p);try{const u=await r.call(this,s,n),f=Date.now(),p=f-d,m=u.status,g=u.ok;if(t.onlyFailedRequests&&g)return a.delete(h),u;let w;t.recordResponseBody&&(w=await async function(e,t,r){if(r)try{if(!(e instanceof Response)){const r=e,s=r.responseText||"";if(s.length>t)return s.substring(0,t)+"...[TRUNCATED]";let n="";try{n=r.getResponseHeader("content-type")||""}catch{}if(n.includes("application/json"))try{return JSON.parse(s)}catch{return s}return s}{const r=e.headers.get("content-length");if(r&&parseInt(r,10)>t)return`[Response too large: ${r} bytes]`;let n;try{n=e.clone()}catch(s){return"[Response body already consumed]"}const i=e.headers.get("content-type")||"";if(i.includes("application/json")){const e=await n.text();if(e.length>t)return e.substring(0,t)+"...[TRUNCATED]";try{return JSON.parse(e)}catch{return e}}else{if(i.includes("text/")){const e=await n.text();return e.length>t?e.substring(0,t)+"...[TRUNCATED]":e}try{return`[${i||"unknown"}: ${(await n.blob()).size} bytes]`}catch{return`[${i||"unknown"}: unable to read]`}}}}catch(s){return console.warn("NetworkInterceptor: Failed to read response body:",s),"[Error reading response]"}}(u,t.maxResponseBodySize,t.recordResponseBody),t.sensitiveFields&&t.sensitiveFields.length>0&&void 0!==w&&(w=as(w,t.sensitiveFields)));const _=u.headers.get("content-length"),y=_?parseInt(_,10):void 0,b={type:"custom",name:"custom",eventName:"api-response",timestamp:f,url:o(),title:l(),properties:{url:i.split("?")[0].split("#")[0],fullUrl:i,method:c,statusCode:m,duration:p,responseSize:y,success:g,body:w,timestamp:f}};return e.send(b),a.delete(h),u}catch(m){const t=Date.now(),r=t-d,s={type:"custom",name:"custom",eventName:"api-response",timestamp:t,url:o(),title:l(),properties:{url:i.split("?")[0].split("#")[0],fullUrl:i,method:c,statusCode:0,duration:r,success:!1,error:m instanceof Error?m.message:String(m),timestamp:t}};throw e.send(s),a.delete(h),m}}),"undefined"!=typeof XMLHttpRequest)){s=XMLHttpRequest.prototype.open,n=XMLHttpRequest.prototype.send,i=XMLHttpRequest.prototype.setRequestHeader;const r=new WeakMap,a=new WeakMap;XMLHttpRequest.prototype.open=function(e,t,n,i,o){const l="string"==typeof t?t:t.href;return a.set(this,{url:l,method:e.toUpperCase(),startTime:Date.now()}),r.set(this,{}),s.call(this,e,t,void 0===n||n,i,o)},XMLHttpRequest.prototype.setRequestHeader=function(e,t){const s=r.get(this)||{};return s[e]=t,r.set(this,s),i.call(this,e,t)},XMLHttpRequest.prototype.send=function(s){const i=a.get(this);if(!i)return n.call(this,s);const{url:c,method:h,startTime:d}=i,u=r.get(this)||{};if(!is(c,t.urlFilter))return n.call(this,s);let f;if(t.recordRequestBody&&s){if("string"==typeof s)f=s.length>t.maxRequestBodySize?s.substring(0,t.maxRequestBodySize)+"...[TRUNCATED]":s;else if(s instanceof FormData){const e={};for(const[t,r]of s.entries())r instanceof File?e[t]=`[File: ${r.name}, ${r.size} bytes]`:e[t]=r;f=e}else f=s instanceof Blob?s.size>t.maxRequestBodySize?`[Blob: ${s.size} bytes, type: ${s.type}]`:"[Blob]":"[Unsupported body type]";t.sensitiveFields&&t.sensitiveFields.length>0&&(f=as(f,t.sensitiveFields))}i.requestBody=f;const p={type:"custom",name:"custom",eventName:"api-request",timestamp:d,url:o(),title:l(),properties:{url:c.split("?")[0].split("#")[0],fullUrl:c,method:h,headers:t.sensitiveFields&&t.sensitiveFields.length>0?as(u,t.sensitiveFields):u,body:f,timestamp:d}};e.send(p);const m=()=>{if(this.readyState===XMLHttpRequest.DONE){const n=Date.now(),i=n-d,u=this.status,f=u>=200&&u<400;if(t.onlyFailedRequests&&f)return this.removeEventListener("readystatechange",m),a.delete(this),void r.delete(this);let p="";try{p=this.responseText||""}catch(s){console.warn("NetworkInterceptor: Failed to read XHR responseText:",s)}const g=p.length;let w;if(t.recordResponseBody){if(p.length>t.maxResponseBodySize)w=p.substring(0,t.maxResponseBodySize)+"...[TRUNCATED]";else{let e="";try{e=this.getResponseHeader("content-type")||""}catch{}if(e.includes("application/json"))try{w=JSON.parse(p)}catch{w=p}else w=p}t.sensitiveFields&&t.sensitiveFields.length>0&&(w=as(w,t.sensitiveFields))}const _={type:"custom",name:"custom",eventName:"api-response",timestamp:n,url:o(),title:l(),properties:{url:c.split("?")[0].split("#")[0],fullUrl:c,method:h,statusCode:u,duration:i,responseSize:g,success:f,body:w,timestamp:n}};e.send(_),this.removeEventListener("readystatechange",m),a.delete(this),r.delete(this)}};return this.addEventListener("readystatechange",m),n.call(this,s)}}},uninstall(){"undefined"!=typeof window&&(r&&(window.fetch=r,r=null),s&&n&&i&&(XMLHttpRequest.prototype.open=s,XMLHttpRequest.prototype.send=n,XMLHttpRequest.prototype.setRequestHeader=i,s=null,n=null,i=null),a.clear())}}}const ls=os();e.createNetworkInterceptorPlugin=os,e.default=class{constructor(e){if(r(this,"config"),r(this,"autoTracker",null),r(this,"errorTracker",null),r(this,"performanceTracker",null),r(this,"customTracker"),r(this,"dataProcessor"),r(this,"batchSender"),r(this,"pluginManager"),r(this,"behaviorAnalysis"),r(this,"sessionReplay",null),r(this,"userInfo",null),r(this,"deviceId"),r(this,"sessionId"),!e.appId)throw new Error("Tracker: appId is required");this.config=new n(e),this.deviceId=e.deviceId||function(){if("undefined"==typeof window)return a();const e="__tracker_device_id__";let t=localStorage.getItem(e);if(!t){t=a();try{localStorage.setItem(e,t)}catch(r){}}return t}(),this.sessionId=function(){if("undefined"==typeof window)return a();const e="__tracker_session_id__";let t=sessionStorage.getItem(e);if(!t){t=a();try{sessionStorage.setItem(e,t)}catch(r){}}return t}(),this.customTracker=new v,this.dataProcessor=new Fr;const t=e.serverUrl||"about:blank";this.batchSender=new es(t,{batchSize:this.config.get("batchSize"),batchWait:this.config.get("batchWait"),enableOfflineStorage:this.config.get("enableOfflineStorage")??!0,maxOfflineStorageSize:this.config.get("maxOfflineStorageSize")}),e.serverUrl||this.batchSender.setServerUrl(""),this.pluginManager=new ts,this.behaviorAnalysis=new rs,this.pluginManager.setTrackerInstance({send:this.send.bind(this),getConfig:()=>this.config.getAll(),setUser:this.setUser.bind(this),getUser:()=>this.userInfo}),this.init(),"undefined"!=typeof window&&(window.__trackerEventBus={emit:(e,t)=>{i.emit(e,t)}})}init(){this.config.get("enableAutoTrack")&&(this.autoTracker=new _,this.autoTracker.init(),this.setupAutoTrackListeners()),this.config.get("enableErrorTrack")&&(this.errorTracker=new y,this.errorTracker.init()),this.config.get("enablePerformanceTrack")&&(this.performanceTracker=new b,this.performanceTracker.init()),this.config.get("enableSessionReplay")&&(this.sessionReplay=new ss,this.sessionReplay.start()),this.config.get("userId")&&this.setUser({userId:this.config.get("userId")})}setupAutoTrackListeners(){i.on("pageview",e=>{this.send(e)}),i.on("click",e=>{this.send(e)}),i.on("exposure",e=>{this.send(e)}),i.on("input",e=>{this.send(e)}),i.on("error",e=>{this.send(e)}),i.on("performance",e=>{this.send(e)})}send(e){try{const t=this.enrichEvent(e),r=this.dataProcessor.process(t,{sampleRate:this.config.get("sampleRate"),enableDeduplication:!0,isCritical:"error"===e.type});if(!r)return;const s=this.config.get("beforeSend");if(s){const e=s(r);if(!1===e||null===e)return;e&&Object.assign(r,e)}this.batchSender.add(r,{onBatchComplete:(e,t)=>{const r=this.config.get("afterSend");r&&e.forEach(e=>{setTimeout(()=>{r(e,t)},0)})}}),"pageview"===e.type&&this.behaviorAnalysis.analyzePageView(r)}catch(t){const e=this.config.get("onError");e?e(t):console.error("Tracker: Error sending event:",t)}}enrichEvent(e){var t;const r=e.userId||(null==(t=this.userInfo)?void 0:t.userId)||this.config.get("userId"),s={...this.config.get("customProperties")||{},...e.properties||{}},n=Object.keys(s).length>0?s:void 0,i={...e,deviceId:e.deviceId||this.deviceId,sessionId:e.sessionId||this.sessionId};return r&&""!==r&&(i.userId=r),n&&(i.properties=n),i}track(e,t){const r=this.customTracker.track(e,t);this.send(r)}setUser(e){this.userInfo={...this.userInfo,...e},this.config.set("userId",e.userId||"")}getUser(){return this.userInfo}trackError(e,t){if(this.errorTracker)this.errorTracker.trackError(e,t);else{const r={type:"error",name:"custom-error",timestamp:Date.now(),url:o(),title:l(),errorType:"js",message:e instanceof Error?e.message:e,stack:e instanceof Error?e.stack:void 0,properties:t};this.send(r)}}trackPerformance(){if(this.performanceTracker){const e=this.performanceTracker.collectMetrics();e&&this.send(e)}}trackPageView(){if(this.autoTracker){const e=this.autoTracker.getViewTracker().trackPageView();this.send(e)}}use(e){this.pluginManager.use(e)}updateConfig(e){this.config.update(e),void 0!==e.serverUrl&&(e.serverUrl?this.batchSender.setServerUrl(e.serverUrl):this.batchSender.setServerUrl(""))}getConfig(){return this.config.getAll()}getBehaviorMetrics(){return this.behaviorAnalysis.getMetrics()}getSessionReplayData(){var e;return null==(e=this.sessionReplay)?void 0:e.getData()}async getOfflineEvents(){return this.batchSender.getOfflineEvents()}async getOfflineEventCount(){return this.batchSender.getOfflineEventCount()}async clearOfflineStorage(){return this.batchSender.clearOfflineStorage()}getAutoTracker(){return this.autoTracker}destroy(){var e,t,r,s;null==(e=this.autoTracker)||e.destroy(),null==(t=this.errorTracker)||t.destroy(),null==(r=this.performanceTracker)||r.destroy(),null==(s=this.sessionReplay)||s.destroy(),this.batchSender.destroy(),this.pluginManager.clear(),i.clear()}async destroyAsync(){var e,t,r,s;null==(e=this.autoTracker)||e.destroy(),null==(t=this.errorTracker)||t.destroy(),null==(r=this.performanceTracker)||r.destroy(),null==(s=this.sessionReplay)||s.destroy(),await this.batchSender.destroyAsync(),this.pluginManager.clear(),i.clear()}},e.eventBus=i,e.indexedDBStorage=Gr,e.localStorage=Wr,e.memoryStorage=Yr,e.networkInterceptorPlugin=ls,e.sessionStorage=Jr,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TrackerSDK={})}(this,function(e){"use strict";var t=Object.defineProperty,n=(e,n,r)=>((e,n,r)=>n in e?t(e,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[n]=r)(e,"symbol"!=typeof n?n+"":n,r);function r(e){if(!e||"undefined"==typeof window)return null;const t=e;if(t.__vueParentComponent)return t.__vueParentComponent;if(t.__vue__)return t.__vue__;let n=e.parentElement,r=0;for(;n&&r<5;){const e=n;if(e.__vueParentComponent)return e.__vueParentComponent;if(e.__vue__)return e.__vue__;n=n.parentElement,r++}return null}function s(e){var t,n,r,s,i,a,o;if(e)return(null==(t=e.$options)?void 0:t.name)?e.$options.name:e.__name?e.__name:(null==(n=e.type)?void 0:n.name)?e.type.name:(null==(r=e.type)?void 0:r.__name)?e.type.__name:(null==(i=null==(s=e.$)?void 0:s.type)?void 0:i.name)?e.$.type.name:(null==(o=null==(a=e.$)?void 0:a.type)?void 0:o.__name)?e.$.type.__name:void 0}function i(e){if(e)return e.$props?e.$props:e.props?e.props:void 0}function a(e){if(e)return e.$attrs?e.$attrs:e.attrs?e.attrs:void 0}function o(e){if(!e)return;const t=i(e);if(t){if("value"in t)return t.value;if("modelValue"in t)return t.modelValue}if(e.setupState){if("value"in e.setupState)return e.setupState.value;if("modelValue"in e.setupState)return e.setupState.modelValue}if(e.ctx){if("value"in e.ctx)return e.ctx.value;if("modelValue"in e.ctx)return e.ctx.modelValue}}const l=["password","token","secret","key","auth","credential","pwd"];function c(e){if(!e)return;const t={};for(const[n,r]of Object.entries(e)){const e=n.toLowerCase();if(l.some(t=>{const r=t.toLowerCase();if(e===r)return!0;const s=e.indexOf(r);if(s<0)return!1;const i=s>0?n[s-1]:null,a=s+r.length<n.length?n[s+r.length]:null;if(0===s&&null!==a&&("-"===a||"_"===a||/[A-Z]/.test(a)))return!0;if(s===e.length-r.length&&null!==i){if("-"===i||"_"===i||/[A-Z]/.test(i))return!0;const e=n.substring(s,s+r.length);if(/[A-Z]/.test(e[0]))return!0}if(s>0&&s<e.length-r.length&&null!==i&&null!==a){if(("-"===i||"_"===i||/[A-Z]/.test(i))&&("-"===a||"_"===a||/[A-Z]/.test(a)))return!0;const e=n.substring(s,s+r.length);if(/[A-Z]/.test(e[0]))return!0}return!1}))if(null===r)t[n]="[null]";else{if(void 0===r)continue;t[n]=`[${typeof r}]`}else if("object"!=typeof r||null===r||Array.isArray(r))t[n]=r;else{const e=c(r);t[n]=void 0!==e?e:{}}}return t}function d(e){var t,n;if(!e)return;const r=e.className;if("string"==typeof r){const e=r.match(/\bn-([a-z-]+)\b/);if(e)return`n-${e[1]}`}const s=null==(t=e.tagName)?void 0:t.toLowerCase();if(s&&s.startsWith("n-"))return s;let i=e.parentElement,a=0;for(;i&&a<3;){const e=i.className;if("string"==typeof e){const t=e.match(/\bn-([a-z-]+)\b/);if(t)return`n-${t[1]}`}const t=null==(n=i.tagName)?void 0:n.toLowerCase();if(t&&t.startsWith("n-"))return t;i=i.parentElement,a++}}function h(e){return{maxDepth:(null==e?void 0:e.maxDepth)??3,maxKeys:(null==e?void 0:e.maxKeys)??32,stripFunctions:(null==e?void 0:e.stripFunctions)??!0}}function u(e,t,n,r){if(n>t.maxDepth)return"[Truncated]";if(null==e)return e;const s=typeof e;if("function"===s)return t.stripFunctions?void 0:"[Function]";if("symbol"===s||"bigint"===s)return String(e);if("object"!==s)return e;if(r.has(e))return"[Circular]";if(Array.isArray(e)){r.add(e);const s=Math.min(e.length,t.maxKeys),i=[];for(let a=0;a<s;a++)i.push(u(e[a],t,n+1,r));return i}r.add(e);const i=e,a=Object.keys(i).slice(0,t.maxKeys),o={};for(const l of a)o[l]=u(i[l],t,n+1,r);return o}function p(e,t){if(!e||0===Object.keys(e).length)return;let n;try{n=c(e)}catch{n=e}if(!n||0===Object.keys(n).length)return;return u(n,t,0,new WeakSet)}function f(e){return null==e?null:e instanceof Element?e:e instanceof Text||e instanceof Comment?e.parentElement:null}const m=/^__reactFiber\$/;function g(e){const t=function(e){try{const t=new Set;for(const n of Object.keys(e))t.add(n);for(const n of Object.getOwnPropertyNames(e))t.add(n);for(const e of t)if(m.test(e))return e}catch{}return null}(e);if(!t)return null;try{return e[t]??null}catch{return null}}function v(e,t=0){if(t>8)return null;if(null==e)return null;if("function"==typeof e)return e;if("string"==typeof e)return e;if("object"==typeof e&&null!==e){const n=e;if("function"==typeof n.type||"string"==typeof n.type)return v(n.type,t+1);if("function"==typeof n.render)return n.render}return null}function b(e){return v(e.type??e.elementType)}function y(e){return"function"==typeof b(e)}function w(e,t){try{const n=function(e,t){let n=e,r=0;for(;null!=n&&r<t;){const e=n;if(y(e))return e;n=e.return,r++}return null}(e,t.maxFiberHops);if(!n)return;const r=b(n);if("function"!=typeof r)return;const s=function(e){const t=e;return t.displayName||t.name||"Anonymous"}(r),i=function(e){const t=e.memoizedProps??e.pendingProps;if(!t||"object"!=typeof t)return{};const n={...t};return delete n.children,delete n.key,delete n.ref,n}(n);return{componentName:s,displayName:s,props:p(i,t.limits)}}catch{return}}function _(e={}){const t=e.priority??80,n=e.maxDomWalkDepth??15,r=e.maxFiberHops??40;return{name:"react-fiber",priority:t,resolveComponentInfo(e){var t;try{const s=f(e.target);if(!s)return;const i=h(e.trackerConfig.componentInfo),a=function(e,t,n,r){try{const s=function(e,t,n){let r=e,s=0;for(;null!=r&&s<=t;){const e=n(r);if(e)return e;r=r.parentElement,s++}return null}(e,t,g);if(!s)return;return w(s,{maxFiberHops:n,limits:r})}catch{return}}(s,n,r,i);if(!a)return;const o=null==(t=e.event)?void 0:t.type;return o&&(a.eventMeta={...a.eventMeta,nativeEventType:o}),a}catch{return}}}}function k(e,t){const n=e.constructor,r=(null==n?void 0:n.name)&&"Object"!==n.name&&""!==n.name?n.name:"Unknown",s=Object.keys(e).filter(e=>!e.startsWith("_")).slice(0,t.maxKeys),i={};for(const a of s)i[a]=e[a];return{componentName:r,displayName:r,props:p(i,t)}}function x(e={}){const t=e.priority??79,n=e.maxDomWalkDepth??15;return{name:"angular-ivy",priority:t,resolveComponentInfo(t){var r;try{const s=f(t.target);if(!s)return;const i=function(e){if(e.getComponent)return e.getComponent;if(e.useFallbackNgProbe){const e=globalThis.ng;if("function"==typeof(null==e?void 0:e.getComponent))return t=>e.getComponent(t)??null}return null}(e);if(!i)return;const a=h(t.trackerConfig.componentInfo);let o=s,l=0;for(;null!=o&&l<=n;){const e=i(o);if(null!=e&&"object"==typeof e){const n=k(e,a),s=null==(r=t.event)?void 0:r.type;return s&&(n.eventMeta={...n.eventMeta,nativeEventType:s}),n}o=o.parentElement,l++}return}catch{return}}}}const T={appId:"",serverUrl:void 0,enableAutoTrack:!0,enableErrorTrack:!0,enablePerformanceTrack:!1,enableSessionReplay:!1,batchSize:10,batchWait:5e3,sampleRate:1,enableOfflineStorage:!0,maxOfflineStorageSize:1e3,maxRetries:3,enableCompression:!1,userId:"",deviceId:"",customProperties:{},enableVueTracking:!1,enableNaiveUITracking:!1,componentInfoDepth:3,extractComponentProps:!0,extractComponentValue:!0,enableReactTracking:!1,enableAngularTracking:!1};class S{constructor(e){n(this,"config"),this.config={...T,...e,customProperties:{...T.customProperties,...e.customProperties}}}get(e){return this.config[e]}getAll(){return{...this.config}}set(e,t){this.config[e]=t}update(e){this.config={...this.config,...e,customProperties:{...this.config.customProperties,...e.customProperties||{}}}}}const E=new class{constructor(){n(this,"events",new Map)}on(e,t){this.events.has(e)||this.events.set(e,[]),this.events.get(e).push(t)}off(e,t){if(!this.events.has(e))return;if(!t)return void this.events.delete(e);const n=this.events.get(e),r=n.indexOf(t);r>-1&&n.splice(r,1)}emit(e,...t){if(!this.events.has(e))return;this.events.get(e).forEach(n=>{try{n(...t)}catch(r){console.error(`EventBus: Error in callback for event "${e}":`,r)}})}once(e,t){const n=(...r)=>{t(...r),this.off(e,n)};this.on(e,n)}clear(){this.events.clear()}};function I(){return`${Date.now()}-${Math.random().toString(36).substring(2,9)}`}function C(){if("undefined"==typeof window)return I();if("undefined"==typeof localStorage||!localStorage)return I();const e="__tracker_device_id__";let t=null;try{t=localStorage.getItem(e)}catch(n){return I()}if(!t){t=I();try{localStorage.setItem(e,t)}catch(n){}}return t}function R(){if("undefined"==typeof window)return I();if("undefined"==typeof sessionStorage||!sessionStorage)return I();const e="__tracker_session_id__";let t=null;try{t=sessionStorage.getItem(e)}catch(n){return I()}if(!t){t=I();try{sessionStorage.setItem(e,t)}catch(n){}}return t}function z(){return"undefined"==typeof window?"":window.location.href}function D(){return"undefined"!=typeof window&&!!window.__trackerInternalPanel}function M(){return"undefined"==typeof window?"":document.title||""}function B(e,t){let n=null;return function(...r){n&&clearTimeout(n),n=setTimeout(()=>{n=null,e(...r)},t)}}function A(e,t){let n=null,r=0;return function(...s){const i=Date.now(),a=t-(i-r);a<=0||a>t?(n&&(clearTimeout(n),n=null),r=i,e(...s)):n||(n=setTimeout(()=>{r=Date.now(),n=null,e(...s)},a))}}function P(e){return L(e,new WeakSet)}function L(e,t){if(null===e||"object"!=typeof e)return e;if(t.has(e))return{__circular:!0};if(e instanceof Date)return new Date(e.getTime());if(e instanceof Array){t.add(e);const n=e.map(e=>L(e,t));return t.delete(e),n}if("object"==typeof e){t.add(e);const n={};for(const r in e)Object.prototype.hasOwnProperty.call(e,r)&&(n[r]=L(e[r],t));return t.delete(e),n}return e}function U(e){if("string"==typeof e)return e;if(e&&"object"==typeof e&&"baseVal"in e){const t=e.baseVal;return"string"==typeof t?t:""}if(null==e)return"";try{const t=String(e);return"[object SVGAnimatedString]"===t?"":t}catch{return""}}function O(e){if(!e)return"";const t=[];for(;e&&e.nodeType===Node.ELEMENT_NODE;){let n=e.nodeName.toLowerCase();if(e.id){n+=`#${e.id}`,t.unshift(n);break}const r=U(e.className);if(r){const e=r.trim().split(/\s+/).filter(e=>e.length>0).join(".");e&&(n+=`.${e}`)}let s=e,i=1;for(;s=s.previousElementSibling;)s.nodeName===e.nodeName&&i++;i>1&&(n+=`:nth-of-type(${i})`),t.unshift(n),e=e.parentElement}return t.join(" > ")}function N(e){var t;return e?{tagName:e.tagName.toLowerCase(),id:e.id||void 0,className:U(e.className)||void 0,text:(null==(t=e.textContent)?void 0:t.trim().substring(0,100))||void 0}:{}}class H{track(e,t){return{type:"custom",name:"custom",eventName:e,timestamp:Date.now(),url:z(),title:M(),properties:t}}}class F{shouldSample(e){return e>=1||!(e<=0)&&Math.random()<e}shouldSampleCritical(e,t){return!!e||this.shouldSample(t)}}class ${constructor(){n(this,"eventCache",new Map),n(this,"cacheTimeouts",{click:1e4,exposure:3e4,error:5e3,performance:6e4,pageview:1e4,input:3e3,custom:1e3}),n(this,"defaultCacheTimeout",6e4)}isDuplicate(e){const t=this.getEventKey(e),n=this.eventCache.get(t),r=Date.now();let s=this.cacheTimeouts[e.type]||this.defaultCacheTimeout;if("custom"===e.type&&"eventName"in e){const t=e.eventName;"api-request"!==t&&"api-response"!==t||(s=5e3)}return!!(n&&r-n<s)||(this.eventCache.set(t,r),this.cleanExpiredCache(r),!1)}getEventKey(e){const t=[e.type,e.name,e.url];if("click"===e.type&&"elementPath"in e){if(t.push(e.elementPath||""),"position"in e&&e.position){const n=10,r=Math.floor(e.position.x/n)*n,s=Math.floor(e.position.y/n)*n;t.push(`${r}-${s}`)}}else if("exposure"===e.type&&"elementPath"in e)t.push(e.elementPath||"");else if("input"===e.type&&"elementPath"in e){if(t.push(e.elementPath||""),"value"in e&&void 0!==e.value&&null!==e.value){const n=String(e.value),r=n.length>10?n.substring(0,10):n;t.push(this.simpleHash(r))}else"valueLength"in e&&void 0!==e.valueLength&&t.push(String(e.valueLength));"isSensitive"in e&&e.isSensitive&&t.push("sensitive")}else if("error"===e.type&&"message"in e)t.push(e.message),"filename"in e&&e.filename&&t.push(e.filename),"lineno"in e&&e.lineno&&t.push(String(e.lineno)),"colno"in e&&e.colno&&t.push(String(e.colno)),"resourceUrl"in e&&e.resourceUrl&&t.push(e.resourceUrl);else if("performance"===e.type&&"metricType"in e)if(t.push(e.metricType),"resource"===e.metricType&&"metrics"in e&&e.metrics){const n=e.metrics.resourceUrl;n&&t.push(String(n))}else if("longtask"===e.metricType&&"metrics"in e&&e.metrics){const n=e.metrics;void 0!==n.startTime&&void 0!==n.duration&&t.push(`${n.startTime}-${n.duration}`)}else e.metricType;else if("custom"===e.type&&"eventName"in e){if(t.push(e.eventName),"api-request"===e.eventName||"api-response"===e.eventName){if(e.properties){const n=e.properties,r=n.url?String(n.url):"",s=n.method?String(n.method):"",i=n.fullUrl?String(n.fullUrl):"";if(r||s||i)t.push(i||`${s}:${r}`);else try{const n=JSON.stringify(e.properties);t.push(n.substring(0,100))}catch{t.push(String(Object.keys(e.properties).length))}}}else if(e.properties)try{const n=JSON.stringify(e.properties);t.push(n.substring(0,100))}catch{t.push(String(Object.keys(e.properties).length))}}else if("pageview"===e.type){const n=Math.floor(e.timestamp/1e4);t.push(String(n))}return t.join("|")}simpleHash(e){let t=0;for(let n=0;n<e.length;n++){t=(t<<5)-t+e.charCodeAt(n),t&=t}return Math.abs(t).toString(36).substring(0,8)}cleanExpiredCache(e){const t=Object.values(this.cacheTimeouts),n=2*(t.length>0?Math.max(...t,this.defaultCacheTimeout):this.defaultCacheTimeout);for(const[r,s]of this.eventCache.entries())e-s>n&&this.eventCache.delete(r)}clear(){this.eventCache.clear()}}
|
|
2
|
+
/*! pako 2.1.0 https://github.com/nodeca/pako @license (MIT AND Zlib) */function j(e){let t=e.length;for(;--t>=0;)e[t]=0}const q=256,V=286,Z=30,K=15,W=new Uint8Array([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0]),J=new Uint8Array([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13]),X=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7]),G=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),Q=new Array(576);j(Q);const Y=new Array(60);j(Y);const ee=new Array(512);j(ee);const te=new Array(256);j(te);const ne=new Array(29);j(ne);const re=new Array(Z);function se(e,t,n,r,s){this.static_tree=e,this.extra_bits=t,this.extra_base=n,this.elems=r,this.max_length=s,this.has_stree=e&&e.length}let ie,ae,oe;function le(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}j(re);const ce=e=>e<256?ee[e]:ee[256+(e>>>7)],de=(e,t)=>{e.pending_buf[e.pending++]=255&t,e.pending_buf[e.pending++]=t>>>8&255},he=(e,t,n)=>{e.bi_valid>16-n?(e.bi_buf|=t<<e.bi_valid&65535,de(e,e.bi_buf),e.bi_buf=t>>16-e.bi_valid,e.bi_valid+=n-16):(e.bi_buf|=t<<e.bi_valid&65535,e.bi_valid+=n)},ue=(e,t,n)=>{he(e,n[2*t],n[2*t+1])},pe=(e,t)=>{let n=0;do{n|=1&e,e>>>=1,n<<=1}while(--t>0);return n>>>1},fe=(e,t,n)=>{const r=new Array(16);let s,i,a=0;for(s=1;s<=K;s++)a=a+n[s-1]<<1,r[s]=a;for(i=0;i<=t;i++){let t=e[2*i+1];0!==t&&(e[2*i]=pe(r[t]++,t))}},me=e=>{let t;for(t=0;t<V;t++)e.dyn_ltree[2*t]=0;for(t=0;t<Z;t++)e.dyn_dtree[2*t]=0;for(t=0;t<19;t++)e.bl_tree[2*t]=0;e.dyn_ltree[512]=1,e.opt_len=e.static_len=0,e.sym_next=e.matches=0},ge=e=>{e.bi_valid>8?de(e,e.bi_buf):e.bi_valid>0&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0},ve=(e,t,n,r)=>{const s=2*t,i=2*n;return e[s]<e[i]||e[s]===e[i]&&r[t]<=r[n]},be=(e,t,n)=>{const r=e.heap[n];let s=n<<1;for(;s<=e.heap_len&&(s<e.heap_len&&ve(t,e.heap[s+1],e.heap[s],e.depth)&&s++,!ve(t,r,e.heap[s],e.depth));)e.heap[n]=e.heap[s],n=s,s<<=1;e.heap[n]=r},ye=(e,t,n)=>{let r,s,i,a,o=0;if(0!==e.sym_next)do{r=255&e.pending_buf[e.sym_buf+o++],r+=(255&e.pending_buf[e.sym_buf+o++])<<8,s=e.pending_buf[e.sym_buf+o++],0===r?ue(e,s,t):(i=te[s],ue(e,i+q+1,t),a=W[i],0!==a&&(s-=ne[i],he(e,s,a)),r--,i=ce(r),ue(e,i,n),a=J[i],0!==a&&(r-=re[i],he(e,r,a)))}while(o<e.sym_next);ue(e,256,t)},we=(e,t)=>{const n=t.dyn_tree,r=t.stat_desc.static_tree,s=t.stat_desc.has_stree,i=t.stat_desc.elems;let a,o,l,c=-1;for(e.heap_len=0,e.heap_max=573,a=0;a<i;a++)0!==n[2*a]?(e.heap[++e.heap_len]=c=a,e.depth[a]=0):n[2*a+1]=0;for(;e.heap_len<2;)l=e.heap[++e.heap_len]=c<2?++c:0,n[2*l]=1,e.depth[l]=0,e.opt_len--,s&&(e.static_len-=r[2*l+1]);for(t.max_code=c,a=e.heap_len>>1;a>=1;a--)be(e,n,a);l=i;do{a=e.heap[1],e.heap[1]=e.heap[e.heap_len--],be(e,n,1),o=e.heap[1],e.heap[--e.heap_max]=a,e.heap[--e.heap_max]=o,n[2*l]=n[2*a]+n[2*o],e.depth[l]=(e.depth[a]>=e.depth[o]?e.depth[a]:e.depth[o])+1,n[2*a+1]=n[2*o+1]=l,e.heap[1]=l++,be(e,n,1)}while(e.heap_len>=2);e.heap[--e.heap_max]=e.heap[1],((e,t)=>{const n=t.dyn_tree,r=t.max_code,s=t.stat_desc.static_tree,i=t.stat_desc.has_stree,a=t.stat_desc.extra_bits,o=t.stat_desc.extra_base,l=t.stat_desc.max_length;let c,d,h,u,p,f,m=0;for(u=0;u<=K;u++)e.bl_count[u]=0;for(n[2*e.heap[e.heap_max]+1]=0,c=e.heap_max+1;c<573;c++)d=e.heap[c],u=n[2*n[2*d+1]+1]+1,u>l&&(u=l,m++),n[2*d+1]=u,d>r||(e.bl_count[u]++,p=0,d>=o&&(p=a[d-o]),f=n[2*d],e.opt_len+=f*(u+p),i&&(e.static_len+=f*(s[2*d+1]+p)));if(0!==m){do{for(u=l-1;0===e.bl_count[u];)u--;e.bl_count[u]--,e.bl_count[u+1]+=2,e.bl_count[l]--,m-=2}while(m>0);for(u=l;0!==u;u--)for(d=e.bl_count[u];0!==d;)h=e.heap[--c],h>r||(n[2*h+1]!==u&&(e.opt_len+=(u-n[2*h+1])*n[2*h],n[2*h+1]=u),d--)}})(e,t),fe(n,c,e.bl_count)},_e=(e,t,n)=>{let r,s,i=-1,a=t[1],o=0,l=7,c=4;for(0===a&&(l=138,c=3),t[2*(n+1)+1]=65535,r=0;r<=n;r++)s=a,a=t[2*(r+1)+1],++o<l&&s===a||(o<c?e.bl_tree[2*s]+=o:0!==s?(s!==i&&e.bl_tree[2*s]++,e.bl_tree[32]++):o<=10?e.bl_tree[34]++:e.bl_tree[36]++,o=0,i=s,0===a?(l=138,c=3):s===a?(l=6,c=3):(l=7,c=4))},ke=(e,t,n)=>{let r,s,i=-1,a=t[1],o=0,l=7,c=4;for(0===a&&(l=138,c=3),r=0;r<=n;r++)if(s=a,a=t[2*(r+1)+1],!(++o<l&&s===a)){if(o<c)do{ue(e,s,e.bl_tree)}while(0!==--o);else 0!==s?(s!==i&&(ue(e,s,e.bl_tree),o--),ue(e,16,e.bl_tree),he(e,o-3,2)):o<=10?(ue(e,17,e.bl_tree),he(e,o-3,3)):(ue(e,18,e.bl_tree),he(e,o-11,7));o=0,i=s,0===a?(l=138,c=3):s===a?(l=6,c=3):(l=7,c=4)}};let xe=!1;const Te=(e,t,n,r)=>{he(e,0+(r?1:0),3),ge(e),de(e,n),de(e,~n),n&&e.pending_buf.set(e.window.subarray(t,t+n),e.pending),e.pending+=n};var Se={_tr_init:e=>{xe||((()=>{let e,t,n,r,s;const i=new Array(16);for(n=0,r=0;r<28;r++)for(ne[r]=n,e=0;e<1<<W[r];e++)te[n++]=r;for(te[n-1]=r,s=0,r=0;r<16;r++)for(re[r]=s,e=0;e<1<<J[r];e++)ee[s++]=r;for(s>>=7;r<Z;r++)for(re[r]=s<<7,e=0;e<1<<J[r]-7;e++)ee[256+s++]=r;for(t=0;t<=K;t++)i[t]=0;for(e=0;e<=143;)Q[2*e+1]=8,e++,i[8]++;for(;e<=255;)Q[2*e+1]=9,e++,i[9]++;for(;e<=279;)Q[2*e+1]=7,e++,i[7]++;for(;e<=287;)Q[2*e+1]=8,e++,i[8]++;for(fe(Q,287,i),e=0;e<Z;e++)Y[2*e+1]=5,Y[2*e]=pe(e,5);ie=new se(Q,W,257,V,K),ae=new se(Y,J,0,Z,K),oe=new se(new Array(0),X,0,19,7)})(),xe=!0),e.l_desc=new le(e.dyn_ltree,ie),e.d_desc=new le(e.dyn_dtree,ae),e.bl_desc=new le(e.bl_tree,oe),e.bi_buf=0,e.bi_valid=0,me(e)},_tr_stored_block:Te,_tr_flush_block:(e,t,n,r)=>{let s,i,a=0;e.level>0?(2===e.strm.data_type&&(e.strm.data_type=(e=>{let t,n=4093624447;for(t=0;t<=31;t++,n>>>=1)if(1&n&&0!==e.dyn_ltree[2*t])return 0;if(0!==e.dyn_ltree[18]||0!==e.dyn_ltree[20]||0!==e.dyn_ltree[26])return 1;for(t=32;t<q;t++)if(0!==e.dyn_ltree[2*t])return 1;return 0})(e)),we(e,e.l_desc),we(e,e.d_desc),a=(e=>{let t;for(_e(e,e.dyn_ltree,e.l_desc.max_code),_e(e,e.dyn_dtree,e.d_desc.max_code),we(e,e.bl_desc),t=18;t>=3&&0===e.bl_tree[2*G[t]+1];t--);return e.opt_len+=3*(t+1)+5+5+4,t})(e),s=e.opt_len+3+7>>>3,i=e.static_len+3+7>>>3,i<=s&&(s=i)):s=i=n+5,n+4<=s&&-1!==t?Te(e,t,n,r):4===e.strategy||i===s?(he(e,2+(r?1:0),3),ye(e,Q,Y)):(he(e,4+(r?1:0),3),((e,t,n,r)=>{let s;for(he(e,t-257,5),he(e,n-1,5),he(e,r-4,4),s=0;s<r;s++)he(e,e.bl_tree[2*G[s]+1],3);ke(e,e.dyn_ltree,t-1),ke(e,e.dyn_dtree,n-1)})(e,e.l_desc.max_code+1,e.d_desc.max_code+1,a+1),ye(e,e.dyn_ltree,e.dyn_dtree)),me(e),r&&ge(e)},_tr_tally:(e,t,n)=>(e.pending_buf[e.sym_buf+e.sym_next++]=t,e.pending_buf[e.sym_buf+e.sym_next++]=t>>8,e.pending_buf[e.sym_buf+e.sym_next++]=n,0===t?e.dyn_ltree[2*n]++:(e.matches++,t--,e.dyn_ltree[2*(te[n]+q+1)]++,e.dyn_dtree[2*ce(t)]++),e.sym_next===e.sym_end),_tr_align:e=>{he(e,2,3),ue(e,256,Q),(e=>{16===e.bi_valid?(de(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):e.bi_valid>=8&&(e.pending_buf[e.pending++]=255&e.bi_buf,e.bi_buf>>=8,e.bi_valid-=8)})(e)}};var Ee=(e,t,n,r)=>{let s=65535&e,i=e>>>16&65535,a=0;for(;0!==n;){a=n>2e3?2e3:n,n-=a;do{s=s+t[r++]|0,i=i+s|0}while(--a);s%=65521,i%=65521}return s|i<<16};const Ie=new Uint32Array((()=>{let e,t=[];for(var n=0;n<256;n++){e=n;for(var r=0;r<8;r++)e=1&e?3988292384^e>>>1:e>>>1;t[n]=e}return t})());var Ce=(e,t,n,r)=>{const s=Ie,i=r+n;e^=-1;for(let a=r;a<i;a++)e=e>>>8^s[255&(e^t[a])];return-1^e},Re={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"},ze={Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_TREES:6,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,Z_BINARY:0,Z_TEXT:1,Z_UNKNOWN:2,Z_DEFLATED:8};const{_tr_init:De,_tr_stored_block:Me,_tr_flush_block:Be,_tr_tally:Ae,_tr_align:Pe}=Se,{Z_NO_FLUSH:Le,Z_PARTIAL_FLUSH:Ue,Z_FULL_FLUSH:Oe,Z_FINISH:Ne,Z_BLOCK:He,Z_OK:Fe,Z_STREAM_END:$e,Z_STREAM_ERROR:je,Z_DATA_ERROR:qe,Z_BUF_ERROR:Ve,Z_DEFAULT_COMPRESSION:Ze,Z_FILTERED:Ke,Z_HUFFMAN_ONLY:We,Z_RLE:Je,Z_FIXED:Xe,Z_DEFAULT_STRATEGY:Ge,Z_UNKNOWN:Qe,Z_DEFLATED:Ye}=ze,et=258,tt=262,nt=42,rt=113,st=666,it=(e,t)=>(e.msg=Re[t],t),at=e=>2*e-(e>4?9:0),ot=e=>{let t=e.length;for(;--t>=0;)e[t]=0},lt=e=>{let t,n,r,s=e.w_size;t=e.hash_size,r=t;do{n=e.head[--r],e.head[r]=n>=s?n-s:0}while(--t);t=s,r=t;do{n=e.prev[--r],e.prev[r]=n>=s?n-s:0}while(--t)};let ct=(e,t,n)=>(t<<e.hash_shift^n)&e.hash_mask;const dt=e=>{const t=e.state;let n=t.pending;n>e.avail_out&&(n=e.avail_out),0!==n&&(e.output.set(t.pending_buf.subarray(t.pending_out,t.pending_out+n),e.next_out),e.next_out+=n,t.pending_out+=n,e.total_out+=n,e.avail_out-=n,t.pending-=n,0===t.pending&&(t.pending_out=0))},ht=(e,t)=>{Be(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,dt(e.strm)},ut=(e,t)=>{e.pending_buf[e.pending++]=t},pt=(e,t)=>{e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=255&t},ft=(e,t,n,r)=>{let s=e.avail_in;return s>r&&(s=r),0===s?0:(e.avail_in-=s,t.set(e.input.subarray(e.next_in,e.next_in+s),n),1===e.state.wrap?e.adler=Ee(e.adler,t,s,n):2===e.state.wrap&&(e.adler=Ce(e.adler,t,s,n)),e.next_in+=s,e.total_in+=s,s)},mt=(e,t)=>{let n,r,s=e.max_chain_length,i=e.strstart,a=e.prev_length,o=e.nice_match;const l=e.strstart>e.w_size-tt?e.strstart-(e.w_size-tt):0,c=e.window,d=e.w_mask,h=e.prev,u=e.strstart+et;let p=c[i+a-1],f=c[i+a];e.prev_length>=e.good_match&&(s>>=2),o>e.lookahead&&(o=e.lookahead);do{if(n=t,c[n+a]===f&&c[n+a-1]===p&&c[n]===c[i]&&c[++n]===c[i+1]){i+=2,n++;do{}while(c[++i]===c[++n]&&c[++i]===c[++n]&&c[++i]===c[++n]&&c[++i]===c[++n]&&c[++i]===c[++n]&&c[++i]===c[++n]&&c[++i]===c[++n]&&c[++i]===c[++n]&&i<u);if(r=et-(u-i),i=u-et,r>a){if(e.match_start=t,a=r,r>=o)break;p=c[i+a-1],f=c[i+a]}}}while((t=h[t&d])>l&&0!==--s);return a<=e.lookahead?a:e.lookahead},gt=e=>{const t=e.w_size;let n,r,s;do{if(r=e.window_size-e.lookahead-e.strstart,e.strstart>=t+(t-tt)&&(e.window.set(e.window.subarray(t,t+t-r),0),e.match_start-=t,e.strstart-=t,e.block_start-=t,e.insert>e.strstart&&(e.insert=e.strstart),lt(e),r+=t),0===e.strm.avail_in)break;if(n=ft(e.strm,e.window,e.strstart+e.lookahead,r),e.lookahead+=n,e.lookahead+e.insert>=3)for(s=e.strstart-e.insert,e.ins_h=e.window[s],e.ins_h=ct(e,e.ins_h,e.window[s+1]);e.insert&&(e.ins_h=ct(e,e.ins_h,e.window[s+3-1]),e.prev[s&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=s,s++,e.insert--,!(e.lookahead+e.insert<3)););}while(e.lookahead<tt&&0!==e.strm.avail_in)},vt=(e,t)=>{let n,r,s,i=e.pending_buf_size-5>e.w_size?e.w_size:e.pending_buf_size-5,a=0,o=e.strm.avail_in;do{if(n=65535,s=e.bi_valid+42>>3,e.strm.avail_out<s)break;if(s=e.strm.avail_out-s,r=e.strstart-e.block_start,n>r+e.strm.avail_in&&(n=r+e.strm.avail_in),n>s&&(n=s),n<i&&(0===n&&t!==Ne||t===Le||n!==r+e.strm.avail_in))break;a=t===Ne&&n===r+e.strm.avail_in?1:0,Me(e,0,0,a),e.pending_buf[e.pending-4]=n,e.pending_buf[e.pending-3]=n>>8,e.pending_buf[e.pending-2]=~n,e.pending_buf[e.pending-1]=~n>>8,dt(e.strm),r&&(r>n&&(r=n),e.strm.output.set(e.window.subarray(e.block_start,e.block_start+r),e.strm.next_out),e.strm.next_out+=r,e.strm.avail_out-=r,e.strm.total_out+=r,e.block_start+=r,n-=r),n&&(ft(e.strm,e.strm.output,e.strm.next_out,n),e.strm.next_out+=n,e.strm.avail_out-=n,e.strm.total_out+=n)}while(0===a);return o-=e.strm.avail_in,o&&(o>=e.w_size?(e.matches=2,e.window.set(e.strm.input.subarray(e.strm.next_in-e.w_size,e.strm.next_in),0),e.strstart=e.w_size,e.insert=e.strstart):(e.window_size-e.strstart<=o&&(e.strstart-=e.w_size,e.window.set(e.window.subarray(e.w_size,e.w_size+e.strstart),0),e.matches<2&&e.matches++,e.insert>e.strstart&&(e.insert=e.strstart)),e.window.set(e.strm.input.subarray(e.strm.next_in-o,e.strm.next_in),e.strstart),e.strstart+=o,e.insert+=o>e.w_size-e.insert?e.w_size-e.insert:o),e.block_start=e.strstart),e.high_water<e.strstart&&(e.high_water=e.strstart),a?4:t!==Le&&t!==Ne&&0===e.strm.avail_in&&e.strstart===e.block_start?2:(s=e.window_size-e.strstart,e.strm.avail_in>s&&e.block_start>=e.w_size&&(e.block_start-=e.w_size,e.strstart-=e.w_size,e.window.set(e.window.subarray(e.w_size,e.w_size+e.strstart),0),e.matches<2&&e.matches++,s+=e.w_size,e.insert>e.strstart&&(e.insert=e.strstart)),s>e.strm.avail_in&&(s=e.strm.avail_in),s&&(ft(e.strm,e.window,e.strstart,s),e.strstart+=s,e.insert+=s>e.w_size-e.insert?e.w_size-e.insert:s),e.high_water<e.strstart&&(e.high_water=e.strstart),s=e.bi_valid+42>>3,s=e.pending_buf_size-s>65535?65535:e.pending_buf_size-s,i=s>e.w_size?e.w_size:s,r=e.strstart-e.block_start,(r>=i||(r||t===Ne)&&t!==Le&&0===e.strm.avail_in&&r<=s)&&(n=r>s?s:r,a=t===Ne&&0===e.strm.avail_in&&n===r?1:0,Me(e,e.block_start,n,a),e.block_start+=n,dt(e.strm)),a?3:1)},bt=(e,t)=>{let n,r;for(;;){if(e.lookahead<tt){if(gt(e),e.lookahead<tt&&t===Le)return 1;if(0===e.lookahead)break}if(n=0,e.lookahead>=3&&(e.ins_h=ct(e,e.ins_h,e.window[e.strstart+3-1]),n=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),0!==n&&e.strstart-n<=e.w_size-tt&&(e.match_length=mt(e,n)),e.match_length>=3)if(r=Ae(e,e.strstart-e.match_start,e.match_length-3),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=3){e.match_length--;do{e.strstart++,e.ins_h=ct(e,e.ins_h,e.window[e.strstart+3-1]),n=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart}while(0!==--e.match_length);e.strstart++}else e.strstart+=e.match_length,e.match_length=0,e.ins_h=e.window[e.strstart],e.ins_h=ct(e,e.ins_h,e.window[e.strstart+1]);else r=Ae(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(r&&(ht(e,!1),0===e.strm.avail_out))return 1}return e.insert=e.strstart<2?e.strstart:2,t===Ne?(ht(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(ht(e,!1),0===e.strm.avail_out)?1:2},yt=(e,t)=>{let n,r,s;for(;;){if(e.lookahead<tt){if(gt(e),e.lookahead<tt&&t===Le)return 1;if(0===e.lookahead)break}if(n=0,e.lookahead>=3&&(e.ins_h=ct(e,e.ins_h,e.window[e.strstart+3-1]),n=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),e.prev_length=e.match_length,e.prev_match=e.match_start,e.match_length=2,0!==n&&e.prev_length<e.max_lazy_match&&e.strstart-n<=e.w_size-tt&&(e.match_length=mt(e,n),e.match_length<=5&&(e.strategy===Ke||3===e.match_length&&e.strstart-e.match_start>4096)&&(e.match_length=2)),e.prev_length>=3&&e.match_length<=e.prev_length){s=e.strstart+e.lookahead-3,r=Ae(e,e.strstart-1-e.prev_match,e.prev_length-3),e.lookahead-=e.prev_length-1,e.prev_length-=2;do{++e.strstart<=s&&(e.ins_h=ct(e,e.ins_h,e.window[e.strstart+3-1]),n=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart)}while(0!==--e.prev_length);if(e.match_available=0,e.match_length=2,e.strstart++,r&&(ht(e,!1),0===e.strm.avail_out))return 1}else if(e.match_available){if(r=Ae(e,0,e.window[e.strstart-1]),r&&ht(e,!1),e.strstart++,e.lookahead--,0===e.strm.avail_out)return 1}else e.match_available=1,e.strstart++,e.lookahead--}return e.match_available&&(r=Ae(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=e.strstart<2?e.strstart:2,t===Ne?(ht(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(ht(e,!1),0===e.strm.avail_out)?1:2};function wt(e,t,n,r,s){this.good_length=e,this.max_lazy=t,this.nice_length=n,this.max_chain=r,this.func=s}const _t=[new wt(0,0,0,0,vt),new wt(4,4,8,4,bt),new wt(4,5,16,8,bt),new wt(4,6,32,32,bt),new wt(4,4,16,16,yt),new wt(8,16,32,32,yt),new wt(8,16,128,128,yt),new wt(8,32,128,256,yt),new wt(32,128,258,1024,yt),new wt(32,258,258,4096,yt)];function kt(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=Ye,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new Uint16Array(1146),this.dyn_dtree=new Uint16Array(122),this.bl_tree=new Uint16Array(78),ot(this.dyn_ltree),ot(this.dyn_dtree),ot(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new Uint16Array(16),this.heap=new Uint16Array(573),ot(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new Uint16Array(573),ot(this.depth),this.sym_buf=0,this.lit_bufsize=0,this.sym_next=0,this.sym_end=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}const xt=e=>{if(!e)return 1;const t=e.state;return!t||t.strm!==e||t.status!==nt&&57!==t.status&&69!==t.status&&73!==t.status&&91!==t.status&&103!==t.status&&t.status!==rt&&t.status!==st?1:0},Tt=e=>{if(xt(e))return it(e,je);e.total_in=e.total_out=0,e.data_type=Qe;const t=e.state;return t.pending=0,t.pending_out=0,t.wrap<0&&(t.wrap=-t.wrap),t.status=2===t.wrap?57:t.wrap?nt:rt,e.adler=2===t.wrap?0:1,t.last_flush=-2,De(t),Fe},St=e=>{const t=Tt(e);var n;return t===Fe&&((n=e.state).window_size=2*n.w_size,ot(n.head),n.max_lazy_match=_t[n.level].max_lazy,n.good_match=_t[n.level].good_length,n.nice_match=_t[n.level].nice_length,n.max_chain_length=_t[n.level].max_chain,n.strstart=0,n.block_start=0,n.lookahead=0,n.insert=0,n.match_length=n.prev_length=2,n.match_available=0,n.ins_h=0),t},Et=(e,t,n,r,s,i)=>{if(!e)return je;let a=1;if(t===Ze&&(t=6),r<0?(a=0,r=-r):r>15&&(a=2,r-=16),s<1||s>9||n!==Ye||r<8||r>15||t<0||t>9||i<0||i>Xe||8===r&&1!==a)return it(e,je);8===r&&(r=9);const o=new kt;return e.state=o,o.strm=e,o.status=nt,o.wrap=a,o.gzhead=null,o.w_bits=r,o.w_size=1<<o.w_bits,o.w_mask=o.w_size-1,o.hash_bits=s+7,o.hash_size=1<<o.hash_bits,o.hash_mask=o.hash_size-1,o.hash_shift=~~((o.hash_bits+3-1)/3),o.window=new Uint8Array(2*o.w_size),o.head=new Uint16Array(o.hash_size),o.prev=new Uint16Array(o.w_size),o.lit_bufsize=1<<s+6,o.pending_buf_size=4*o.lit_bufsize,o.pending_buf=new Uint8Array(o.pending_buf_size),o.sym_buf=o.lit_bufsize,o.sym_end=3*(o.lit_bufsize-1),o.level=t,o.strategy=i,o.method=n,St(e)};var It={deflateInit:(e,t)=>Et(e,t,Ye,15,8,Ge),deflateInit2:Et,deflateReset:St,deflateResetKeep:Tt,deflateSetHeader:(e,t)=>xt(e)||2!==e.state.wrap?je:(e.state.gzhead=t,Fe),deflate:(e,t)=>{if(xt(e)||t>He||t<0)return e?it(e,je):je;const n=e.state;if(!e.output||0!==e.avail_in&&!e.input||n.status===st&&t!==Ne)return it(e,0===e.avail_out?Ve:je);const r=n.last_flush;if(n.last_flush=t,0!==n.pending){if(dt(e),0===e.avail_out)return n.last_flush=-1,Fe}else if(0===e.avail_in&&at(t)<=at(r)&&t!==Ne)return it(e,Ve);if(n.status===st&&0!==e.avail_in)return it(e,Ve);if(n.status===nt&&0===n.wrap&&(n.status=rt),n.status===nt){let t=Ye+(n.w_bits-8<<4)<<8,r=-1;if(r=n.strategy>=We||n.level<2?0:n.level<6?1:6===n.level?2:3,t|=r<<6,0!==n.strstart&&(t|=32),t+=31-t%31,pt(n,t),0!==n.strstart&&(pt(n,e.adler>>>16),pt(n,65535&e.adler)),e.adler=1,n.status=rt,dt(e),0!==n.pending)return n.last_flush=-1,Fe}if(57===n.status)if(e.adler=0,ut(n,31),ut(n,139),ut(n,8),n.gzhead)ut(n,(n.gzhead.text?1:0)+(n.gzhead.hcrc?2:0)+(n.gzhead.extra?4:0)+(n.gzhead.name?8:0)+(n.gzhead.comment?16:0)),ut(n,255&n.gzhead.time),ut(n,n.gzhead.time>>8&255),ut(n,n.gzhead.time>>16&255),ut(n,n.gzhead.time>>24&255),ut(n,9===n.level?2:n.strategy>=We||n.level<2?4:0),ut(n,255&n.gzhead.os),n.gzhead.extra&&n.gzhead.extra.length&&(ut(n,255&n.gzhead.extra.length),ut(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(e.adler=Ce(e.adler,n.pending_buf,n.pending,0)),n.gzindex=0,n.status=69;else if(ut(n,0),ut(n,0),ut(n,0),ut(n,0),ut(n,0),ut(n,9===n.level?2:n.strategy>=We||n.level<2?4:0),ut(n,3),n.status=rt,dt(e),0!==n.pending)return n.last_flush=-1,Fe;if(69===n.status){if(n.gzhead.extra){let t=n.pending,r=(65535&n.gzhead.extra.length)-n.gzindex;for(;n.pending+r>n.pending_buf_size;){let s=n.pending_buf_size-n.pending;if(n.pending_buf.set(n.gzhead.extra.subarray(n.gzindex,n.gzindex+s),n.pending),n.pending=n.pending_buf_size,n.gzhead.hcrc&&n.pending>t&&(e.adler=Ce(e.adler,n.pending_buf,n.pending-t,t)),n.gzindex+=s,dt(e),0!==n.pending)return n.last_flush=-1,Fe;t=0,r-=s}let s=new Uint8Array(n.gzhead.extra);n.pending_buf.set(s.subarray(n.gzindex,n.gzindex+r),n.pending),n.pending+=r,n.gzhead.hcrc&&n.pending>t&&(e.adler=Ce(e.adler,n.pending_buf,n.pending-t,t)),n.gzindex=0}n.status=73}if(73===n.status){if(n.gzhead.name){let t,r=n.pending;do{if(n.pending===n.pending_buf_size){if(n.gzhead.hcrc&&n.pending>r&&(e.adler=Ce(e.adler,n.pending_buf,n.pending-r,r)),dt(e),0!==n.pending)return n.last_flush=-1,Fe;r=0}t=n.gzindex<n.gzhead.name.length?255&n.gzhead.name.charCodeAt(n.gzindex++):0,ut(n,t)}while(0!==t);n.gzhead.hcrc&&n.pending>r&&(e.adler=Ce(e.adler,n.pending_buf,n.pending-r,r)),n.gzindex=0}n.status=91}if(91===n.status){if(n.gzhead.comment){let t,r=n.pending;do{if(n.pending===n.pending_buf_size){if(n.gzhead.hcrc&&n.pending>r&&(e.adler=Ce(e.adler,n.pending_buf,n.pending-r,r)),dt(e),0!==n.pending)return n.last_flush=-1,Fe;r=0}t=n.gzindex<n.gzhead.comment.length?255&n.gzhead.comment.charCodeAt(n.gzindex++):0,ut(n,t)}while(0!==t);n.gzhead.hcrc&&n.pending>r&&(e.adler=Ce(e.adler,n.pending_buf,n.pending-r,r))}n.status=103}if(103===n.status){if(n.gzhead.hcrc){if(n.pending+2>n.pending_buf_size&&(dt(e),0!==n.pending))return n.last_flush=-1,Fe;ut(n,255&e.adler),ut(n,e.adler>>8&255),e.adler=0}if(n.status=rt,dt(e),0!==n.pending)return n.last_flush=-1,Fe}if(0!==e.avail_in||0!==n.lookahead||t!==Le&&n.status!==st){let r=0===n.level?vt(n,t):n.strategy===We?((e,t)=>{let n;for(;;){if(0===e.lookahead&&(gt(e),0===e.lookahead)){if(t===Le)return 1;break}if(e.match_length=0,n=Ae(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,n&&(ht(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===Ne?(ht(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(ht(e,!1),0===e.strm.avail_out)?1:2})(n,t):n.strategy===Je?((e,t)=>{let n,r,s,i;const a=e.window;for(;;){if(e.lookahead<=et){if(gt(e),e.lookahead<=et&&t===Le)return 1;if(0===e.lookahead)break}if(e.match_length=0,e.lookahead>=3&&e.strstart>0&&(s=e.strstart-1,r=a[s],r===a[++s]&&r===a[++s]&&r===a[++s])){i=e.strstart+et;do{}while(r===a[++s]&&r===a[++s]&&r===a[++s]&&r===a[++s]&&r===a[++s]&&r===a[++s]&&r===a[++s]&&r===a[++s]&&s<i);e.match_length=et-(i-s),e.match_length>e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=3?(n=Ae(e,1,e.match_length-3),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(n=Ae(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),n&&(ht(e,!1),0===e.strm.avail_out))return 1}return e.insert=0,t===Ne?(ht(e,!0),0===e.strm.avail_out?3:4):e.sym_next&&(ht(e,!1),0===e.strm.avail_out)?1:2})(n,t):_t[n.level].func(n,t);if(3!==r&&4!==r||(n.status=st),1===r||3===r)return 0===e.avail_out&&(n.last_flush=-1),Fe;if(2===r&&(t===Ue?Pe(n):t!==He&&(Me(n,0,0,!1),t===Oe&&(ot(n.head),0===n.lookahead&&(n.strstart=0,n.block_start=0,n.insert=0))),dt(e),0===e.avail_out))return n.last_flush=-1,Fe}return t!==Ne?Fe:n.wrap<=0?$e:(2===n.wrap?(ut(n,255&e.adler),ut(n,e.adler>>8&255),ut(n,e.adler>>16&255),ut(n,e.adler>>24&255),ut(n,255&e.total_in),ut(n,e.total_in>>8&255),ut(n,e.total_in>>16&255),ut(n,e.total_in>>24&255)):(pt(n,e.adler>>>16),pt(n,65535&e.adler)),dt(e),n.wrap>0&&(n.wrap=-n.wrap),0!==n.pending?Fe:$e)},deflateEnd:e=>{if(xt(e))return je;const t=e.state.status;return e.state=null,t===rt?it(e,qe):Fe},deflateSetDictionary:(e,t)=>{let n=t.length;if(xt(e))return je;const r=e.state,s=r.wrap;if(2===s||1===s&&r.status!==nt||r.lookahead)return je;if(1===s&&(e.adler=Ee(e.adler,t,n,0)),r.wrap=0,n>=r.w_size){0===s&&(ot(r.head),r.strstart=0,r.block_start=0,r.insert=0);let e=new Uint8Array(r.w_size);e.set(t.subarray(n-r.w_size,n),0),t=e,n=r.w_size}const i=e.avail_in,a=e.next_in,o=e.input;for(e.avail_in=n,e.next_in=0,e.input=t,gt(r);r.lookahead>=3;){let e=r.strstart,t=r.lookahead-2;do{r.ins_h=ct(r,r.ins_h,r.window[e+3-1]),r.prev[e&r.w_mask]=r.head[r.ins_h],r.head[r.ins_h]=e,e++}while(--t);r.strstart=e,r.lookahead=2,gt(r)}return r.strstart+=r.lookahead,r.block_start=r.strstart,r.insert=r.lookahead,r.lookahead=0,r.match_length=r.prev_length=2,r.match_available=0,e.next_in=a,e.input=o,e.avail_in=i,r.wrap=s,Fe},deflateInfo:"pako deflate (from Nodeca project)"};const Ct=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var Rt=function(e){const t=Array.prototype.slice.call(arguments,1);for(;t.length;){const n=t.shift();if(n){if("object"!=typeof n)throw new TypeError(n+"must be non-object");for(const t in n)Ct(n,t)&&(e[t]=n[t])}}return e},zt=e=>{let t=0;for(let r=0,s=e.length;r<s;r++)t+=e[r].length;const n=new Uint8Array(t);for(let r=0,s=0,i=e.length;r<i;r++){let t=e[r];n.set(t,s),s+=t.length}return n};let Dt=!0;try{String.fromCharCode.apply(null,new Uint8Array(1))}catch(Ss){Dt=!1}const Mt=new Uint8Array(256);for(let Es=0;Es<256;Es++)Mt[Es]=Es>=252?6:Es>=248?5:Es>=240?4:Es>=224?3:Es>=192?2:1;Mt[254]=Mt[254]=1;var Bt=e=>{if("function"==typeof TextEncoder&&TextEncoder.prototype.encode)return(new TextEncoder).encode(e);let t,n,r,s,i,a=e.length,o=0;for(s=0;s<a;s++)n=e.charCodeAt(s),55296==(64512&n)&&s+1<a&&(r=e.charCodeAt(s+1),56320==(64512&r)&&(n=65536+(n-55296<<10)+(r-56320),s++)),o+=n<128?1:n<2048?2:n<65536?3:4;for(t=new Uint8Array(o),i=0,s=0;i<o;s++)n=e.charCodeAt(s),55296==(64512&n)&&s+1<a&&(r=e.charCodeAt(s+1),56320==(64512&r)&&(n=65536+(n-55296<<10)+(r-56320),s++)),n<128?t[i++]=n:n<2048?(t[i++]=192|n>>>6,t[i++]=128|63&n):n<65536?(t[i++]=224|n>>>12,t[i++]=128|n>>>6&63,t[i++]=128|63&n):(t[i++]=240|n>>>18,t[i++]=128|n>>>12&63,t[i++]=128|n>>>6&63,t[i++]=128|63&n);return t},At=(e,t)=>{const n=t||e.length;if("function"==typeof TextDecoder&&TextDecoder.prototype.decode)return(new TextDecoder).decode(e.subarray(0,t));let r,s;const i=new Array(2*n);for(s=0,r=0;r<n;){let t=e[r++];if(t<128){i[s++]=t;continue}let a=Mt[t];if(a>4)i[s++]=65533,r+=a-1;else{for(t&=2===a?31:3===a?15:7;a>1&&r<n;)t=t<<6|63&e[r++],a--;a>1?i[s++]=65533:t<65536?i[s++]=t:(t-=65536,i[s++]=55296|t>>10&1023,i[s++]=56320|1023&t)}}return((e,t)=>{if(t<65534&&e.subarray&&Dt)return String.fromCharCode.apply(null,e.length===t?e:e.subarray(0,t));let n="";for(let r=0;r<t;r++)n+=String.fromCharCode(e[r]);return n})(i,s)},Pt=(e,t)=>{(t=t||e.length)>e.length&&(t=e.length);let n=t-1;for(;n>=0&&128==(192&e[n]);)n--;return n<0||0===n?t:n+Mt[e[n]]>t?n:t};var Lt=function(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0};const Ut=Object.prototype.toString,{Z_NO_FLUSH:Ot,Z_SYNC_FLUSH:Nt,Z_FULL_FLUSH:Ht,Z_FINISH:Ft,Z_OK:$t,Z_STREAM_END:jt,Z_DEFAULT_COMPRESSION:qt,Z_DEFAULT_STRATEGY:Vt,Z_DEFLATED:Zt}=ze;function Kt(e){this.options=Rt({level:qt,method:Zt,chunkSize:16384,windowBits:15,memLevel:8,strategy:Vt},e||{});let t=this.options;t.raw&&t.windowBits>0?t.windowBits=-t.windowBits:t.gzip&&t.windowBits>0&&t.windowBits<16&&(t.windowBits+=16),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Lt,this.strm.avail_out=0;let n=It.deflateInit2(this.strm,t.level,t.method,t.windowBits,t.memLevel,t.strategy);if(n!==$t)throw new Error(Re[n]);if(t.header&&It.deflateSetHeader(this.strm,t.header),t.dictionary){let e;if(e="string"==typeof t.dictionary?Bt(t.dictionary):"[object ArrayBuffer]"===Ut.call(t.dictionary)?new Uint8Array(t.dictionary):t.dictionary,n=It.deflateSetDictionary(this.strm,e),n!==$t)throw new Error(Re[n]);this._dict_set=!0}}function Wt(e,t){const n=new Kt(t);if(n.push(e,!0),n.err)throw n.msg||Re[n.err];return n.result}Kt.prototype.push=function(e,t){const n=this.strm,r=this.options.chunkSize;let s,i;if(this.ended)return!1;for(i=t===~~t?t:!0===t?Ft:Ot,"string"==typeof e?n.input=Bt(e):"[object ArrayBuffer]"===Ut.call(e)?n.input=new Uint8Array(e):n.input=e,n.next_in=0,n.avail_in=n.input.length;;)if(0===n.avail_out&&(n.output=new Uint8Array(r),n.next_out=0,n.avail_out=r),(i===Nt||i===Ht)&&n.avail_out<=6)this.onData(n.output.subarray(0,n.next_out)),n.avail_out=0;else{if(s=It.deflate(n,i),s===jt)return n.next_out>0&&this.onData(n.output.subarray(0,n.next_out)),s=It.deflateEnd(this.strm),this.onEnd(s),this.ended=!0,s===$t;if(0!==n.avail_out){if(i>0&&n.next_out>0)this.onData(n.output.subarray(0,n.next_out)),n.avail_out=0;else if(0===n.avail_in)break}else this.onData(n.output)}return!0},Kt.prototype.onData=function(e){this.chunks.push(e)},Kt.prototype.onEnd=function(e){e===$t&&(this.result=zt(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var Jt={Deflate:Kt,deflate:Wt,deflateRaw:function(e,t){return(t=t||{}).raw=!0,Wt(e,t)},gzip:function(e,t){return(t=t||{}).gzip=!0,Wt(e,t)}};const Xt=16209;var Gt=function(e,t){let n,r,s,i,a,o,l,c,d,h,u,p,f,m,g,v,b,y,w,_,k,x,T,S;const E=e.state;n=e.next_in,T=e.input,r=n+(e.avail_in-5),s=e.next_out,S=e.output,i=s-(t-e.avail_out),a=s+(e.avail_out-257),o=E.dmax,l=E.wsize,c=E.whave,d=E.wnext,h=E.window,u=E.hold,p=E.bits,f=E.lencode,m=E.distcode,g=(1<<E.lenbits)-1,v=(1<<E.distbits)-1;e:do{p<15&&(u+=T[n++]<<p,p+=8,u+=T[n++]<<p,p+=8),b=f[u&g];t:for(;;){if(y=b>>>24,u>>>=y,p-=y,y=b>>>16&255,0===y)S[s++]=65535&b;else{if(!(16&y)){if(64&y){if(32&y){E.mode=16191;break e}e.msg="invalid literal/length code",E.mode=Xt;break e}b=f[(65535&b)+(u&(1<<y)-1)];continue t}for(w=65535&b,y&=15,y&&(p<y&&(u+=T[n++]<<p,p+=8),w+=u&(1<<y)-1,u>>>=y,p-=y),p<15&&(u+=T[n++]<<p,p+=8,u+=T[n++]<<p,p+=8),b=m[u&v];;){if(y=b>>>24,u>>>=y,p-=y,y=b>>>16&255,16&y){if(_=65535&b,y&=15,p<y&&(u+=T[n++]<<p,p+=8,p<y&&(u+=T[n++]<<p,p+=8)),_+=u&(1<<y)-1,_>o){e.msg="invalid distance too far back",E.mode=Xt;break e}if(u>>>=y,p-=y,y=s-i,_>y){if(y=_-y,y>c&&E.sane){e.msg="invalid distance too far back",E.mode=Xt;break e}if(k=0,x=h,0===d){if(k+=l-y,y<w){w-=y;do{S[s++]=h[k++]}while(--y);k=s-_,x=S}}else if(d<y){if(k+=l+d-y,y-=d,y<w){w-=y;do{S[s++]=h[k++]}while(--y);if(k=0,d<w){y=d,w-=y;do{S[s++]=h[k++]}while(--y);k=s-_,x=S}}}else if(k+=d-y,y<w){w-=y;do{S[s++]=h[k++]}while(--y);k=s-_,x=S}for(;w>2;)S[s++]=x[k++],S[s++]=x[k++],S[s++]=x[k++],w-=3;w&&(S[s++]=x[k++],w>1&&(S[s++]=x[k++]))}else{k=s-_;do{S[s++]=S[k++],S[s++]=S[k++],S[s++]=S[k++],w-=3}while(w>2);w&&(S[s++]=S[k++],w>1&&(S[s++]=S[k++]))}break}if(64&y){e.msg="invalid distance code",E.mode=Xt;break e}b=m[(65535&b)+(u&(1<<y)-1)]}}break}}while(n<r&&s<a);w=p>>3,n-=w,p-=w<<3,u&=(1<<p)-1,e.next_in=n,e.next_out=s,e.avail_in=n<r?r-n+5:5-(n-r),e.avail_out=s<a?a-s+257:257-(s-a),E.hold=u,E.bits=p};const Qt=15,Yt=new Uint16Array([3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0]),en=new Uint8Array([16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78]),tn=new Uint16Array([1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0]),nn=new Uint8Array([16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64]);var rn=(e,t,n,r,s,i,a,o)=>{const l=o.bits;let c,d,h,u,p,f,m=0,g=0,v=0,b=0,y=0,w=0,_=0,k=0,x=0,T=0,S=null;const E=new Uint16Array(16),I=new Uint16Array(16);let C,R,z,D=null;for(m=0;m<=Qt;m++)E[m]=0;for(g=0;g<r;g++)E[t[n+g]]++;for(y=l,b=Qt;b>=1&&0===E[b];b--);if(y>b&&(y=b),0===b)return s[i++]=20971520,s[i++]=20971520,o.bits=1,0;for(v=1;v<b&&0===E[v];v++);for(y<v&&(y=v),k=1,m=1;m<=Qt;m++)if(k<<=1,k-=E[m],k<0)return-1;if(k>0&&(0===e||1!==b))return-1;for(I[1]=0,m=1;m<Qt;m++)I[m+1]=I[m]+E[m];for(g=0;g<r;g++)0!==t[n+g]&&(a[I[t[n+g]]++]=g);if(0===e?(S=D=a,f=20):1===e?(S=Yt,D=en,f=257):(S=tn,D=nn,f=0),T=0,g=0,m=v,p=i,w=y,_=0,h=-1,x=1<<y,u=x-1,1===e&&x>852||2===e&&x>592)return 1;for(;;){C=m-_,a[g]+1<f?(R=0,z=a[g]):a[g]>=f?(R=D[a[g]-f],z=S[a[g]-f]):(R=96,z=0),c=1<<m-_,d=1<<w,v=d;do{d-=c,s[p+(T>>_)+d]=C<<24|R<<16|z}while(0!==d);for(c=1<<m-1;T&c;)c>>=1;if(0!==c?(T&=c-1,T+=c):T=0,g++,0===--E[m]){if(m===b)break;m=t[n+a[g]]}if(m>y&&(T&u)!==h){for(0===_&&(_=y),p+=v,w=m-_,k=1<<w;w+_<b&&(k-=E[w+_],!(k<=0));)w++,k<<=1;if(x+=1<<w,1===e&&x>852||2===e&&x>592)return 1;h=T&u,s[h]=y<<24|w<<16|p-i}}return 0!==T&&(s[p+T]=m-_<<24|64<<16),o.bits=y,0};const{Z_FINISH:sn,Z_BLOCK:an,Z_TREES:on,Z_OK:ln,Z_STREAM_END:cn,Z_NEED_DICT:dn,Z_STREAM_ERROR:hn,Z_DATA_ERROR:un,Z_MEM_ERROR:pn,Z_BUF_ERROR:fn,Z_DEFLATED:mn}=ze,gn=16180,vn=16190,bn=16191,yn=16192,wn=16194,_n=16199,kn=16200,xn=16206,Tn=16209,Sn=e=>(e>>>24&255)+(e>>>8&65280)+((65280&e)<<8)+((255&e)<<24);function En(){this.strm=null,this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new Uint16Array(320),this.work=new Uint16Array(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}const In=e=>{if(!e)return 1;const t=e.state;return!t||t.strm!==e||t.mode<gn||t.mode>16211?1:0},Cn=e=>{if(In(e))return hn;const t=e.state;return e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=1&t.wrap),t.mode=gn,t.last=0,t.havedict=0,t.flags=-1,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new Int32Array(852),t.distcode=t.distdyn=new Int32Array(592),t.sane=1,t.back=-1,ln},Rn=e=>{if(In(e))return hn;const t=e.state;return t.wsize=0,t.whave=0,t.wnext=0,Cn(e)},zn=(e,t)=>{let n;if(In(e))return hn;const r=e.state;return t<0?(n=0,t=-t):(n=5+(t>>4),t<48&&(t&=15)),t&&(t<8||t>15)?hn:(null!==r.window&&r.wbits!==t&&(r.window=null),r.wrap=n,r.wbits=t,Rn(e))},Dn=(e,t)=>{if(!e)return hn;const n=new En;e.state=n,n.strm=e,n.window=null,n.mode=gn;const r=zn(e,t);return r!==ln&&(e.state=null),r};let Mn,Bn,An=!0;const Pn=e=>{if(An){Mn=new Int32Array(512),Bn=new Int32Array(32);let t=0;for(;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(rn(1,e.lens,0,288,Mn,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;rn(2,e.lens,0,32,Bn,0,e.work,{bits:5}),An=!1}e.lencode=Mn,e.lenbits=9,e.distcode=Bn,e.distbits=5},Ln=(e,t,n,r)=>{let s;const i=e.state;return null===i.window&&(i.wsize=1<<i.wbits,i.wnext=0,i.whave=0,i.window=new Uint8Array(i.wsize)),r>=i.wsize?(i.window.set(t.subarray(n-i.wsize,n),0),i.wnext=0,i.whave=i.wsize):(s=i.wsize-i.wnext,s>r&&(s=r),i.window.set(t.subarray(n-r,n-r+s),i.wnext),(r-=s)?(i.window.set(t.subarray(n-r,n),0),i.wnext=r,i.whave=i.wsize):(i.wnext+=s,i.wnext===i.wsize&&(i.wnext=0),i.whave<i.wsize&&(i.whave+=s))),0};var Un={inflateReset:Rn,inflateReset2:zn,inflateResetKeep:Cn,inflateInit:e=>Dn(e,15),inflateInit2:Dn,inflate:(e,t)=>{let n,r,s,i,a,o,l,c,d,h,u,p,f,m,g,v,b,y,w,_,k,x,T=0;const S=new Uint8Array(4);let E,I;const C=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]);if(In(e)||!e.output||!e.input&&0!==e.avail_in)return hn;n=e.state,n.mode===bn&&(n.mode=yn),a=e.next_out,s=e.output,l=e.avail_out,i=e.next_in,r=e.input,o=e.avail_in,c=n.hold,d=n.bits,h=o,u=l,x=ln;e:for(;;)switch(n.mode){case gn:if(0===n.wrap){n.mode=yn;break}for(;d<16;){if(0===o)break e;o--,c+=r[i++]<<d,d+=8}if(2&n.wrap&&35615===c){0===n.wbits&&(n.wbits=15),n.check=0,S[0]=255&c,S[1]=c>>>8&255,n.check=Ce(n.check,S,2,0),c=0,d=0,n.mode=16181;break}if(n.head&&(n.head.done=!1),!(1&n.wrap)||(((255&c)<<8)+(c>>8))%31){e.msg="incorrect header check",n.mode=Tn;break}if((15&c)!==mn){e.msg="unknown compression method",n.mode=Tn;break}if(c>>>=4,d-=4,k=8+(15&c),0===n.wbits&&(n.wbits=k),k>15||k>n.wbits){e.msg="invalid window size",n.mode=Tn;break}n.dmax=1<<n.wbits,n.flags=0,e.adler=n.check=1,n.mode=512&c?16189:bn,c=0,d=0;break;case 16181:for(;d<16;){if(0===o)break e;o--,c+=r[i++]<<d,d+=8}if(n.flags=c,(255&n.flags)!==mn){e.msg="unknown compression method",n.mode=Tn;break}if(57344&n.flags){e.msg="unknown header flags set",n.mode=Tn;break}n.head&&(n.head.text=c>>8&1),512&n.flags&&4&n.wrap&&(S[0]=255&c,S[1]=c>>>8&255,n.check=Ce(n.check,S,2,0)),c=0,d=0,n.mode=16182;case 16182:for(;d<32;){if(0===o)break e;o--,c+=r[i++]<<d,d+=8}n.head&&(n.head.time=c),512&n.flags&&4&n.wrap&&(S[0]=255&c,S[1]=c>>>8&255,S[2]=c>>>16&255,S[3]=c>>>24&255,n.check=Ce(n.check,S,4,0)),c=0,d=0,n.mode=16183;case 16183:for(;d<16;){if(0===o)break e;o--,c+=r[i++]<<d,d+=8}n.head&&(n.head.xflags=255&c,n.head.os=c>>8),512&n.flags&&4&n.wrap&&(S[0]=255&c,S[1]=c>>>8&255,n.check=Ce(n.check,S,2,0)),c=0,d=0,n.mode=16184;case 16184:if(1024&n.flags){for(;d<16;){if(0===o)break e;o--,c+=r[i++]<<d,d+=8}n.length=c,n.head&&(n.head.extra_len=c),512&n.flags&&4&n.wrap&&(S[0]=255&c,S[1]=c>>>8&255,n.check=Ce(n.check,S,2,0)),c=0,d=0}else n.head&&(n.head.extra=null);n.mode=16185;case 16185:if(1024&n.flags&&(p=n.length,p>o&&(p=o),p&&(n.head&&(k=n.head.extra_len-n.length,n.head.extra||(n.head.extra=new Uint8Array(n.head.extra_len)),n.head.extra.set(r.subarray(i,i+p),k)),512&n.flags&&4&n.wrap&&(n.check=Ce(n.check,r,p,i)),o-=p,i+=p,n.length-=p),n.length))break e;n.length=0,n.mode=16186;case 16186:if(2048&n.flags){if(0===o)break e;p=0;do{k=r[i+p++],n.head&&k&&n.length<65536&&(n.head.name+=String.fromCharCode(k))}while(k&&p<o);if(512&n.flags&&4&n.wrap&&(n.check=Ce(n.check,r,p,i)),o-=p,i+=p,k)break e}else n.head&&(n.head.name=null);n.length=0,n.mode=16187;case 16187:if(4096&n.flags){if(0===o)break e;p=0;do{k=r[i+p++],n.head&&k&&n.length<65536&&(n.head.comment+=String.fromCharCode(k))}while(k&&p<o);if(512&n.flags&&4&n.wrap&&(n.check=Ce(n.check,r,p,i)),o-=p,i+=p,k)break e}else n.head&&(n.head.comment=null);n.mode=16188;case 16188:if(512&n.flags){for(;d<16;){if(0===o)break e;o--,c+=r[i++]<<d,d+=8}if(4&n.wrap&&c!==(65535&n.check)){e.msg="header crc mismatch",n.mode=Tn;break}c=0,d=0}n.head&&(n.head.hcrc=n.flags>>9&1,n.head.done=!0),e.adler=n.check=0,n.mode=bn;break;case 16189:for(;d<32;){if(0===o)break e;o--,c+=r[i++]<<d,d+=8}e.adler=n.check=Sn(c),c=0,d=0,n.mode=vn;case vn:if(0===n.havedict)return e.next_out=a,e.avail_out=l,e.next_in=i,e.avail_in=o,n.hold=c,n.bits=d,dn;e.adler=n.check=1,n.mode=bn;case bn:if(t===an||t===on)break e;case yn:if(n.last){c>>>=7&d,d-=7&d,n.mode=xn;break}for(;d<3;){if(0===o)break e;o--,c+=r[i++]<<d,d+=8}switch(n.last=1&c,c>>>=1,d-=1,3&c){case 0:n.mode=16193;break;case 1:if(Pn(n),n.mode=_n,t===on){c>>>=2,d-=2;break e}break;case 2:n.mode=16196;break;case 3:e.msg="invalid block type",n.mode=Tn}c>>>=2,d-=2;break;case 16193:for(c>>>=7&d,d-=7&d;d<32;){if(0===o)break e;o--,c+=r[i++]<<d,d+=8}if((65535&c)!=(c>>>16^65535)){e.msg="invalid stored block lengths",n.mode=Tn;break}if(n.length=65535&c,c=0,d=0,n.mode=wn,t===on)break e;case wn:n.mode=16195;case 16195:if(p=n.length,p){if(p>o&&(p=o),p>l&&(p=l),0===p)break e;s.set(r.subarray(i,i+p),a),o-=p,i+=p,l-=p,a+=p,n.length-=p;break}n.mode=bn;break;case 16196:for(;d<14;){if(0===o)break e;o--,c+=r[i++]<<d,d+=8}if(n.nlen=257+(31&c),c>>>=5,d-=5,n.ndist=1+(31&c),c>>>=5,d-=5,n.ncode=4+(15&c),c>>>=4,d-=4,n.nlen>286||n.ndist>30){e.msg="too many length or distance symbols",n.mode=Tn;break}n.have=0,n.mode=16197;case 16197:for(;n.have<n.ncode;){for(;d<3;){if(0===o)break e;o--,c+=r[i++]<<d,d+=8}n.lens[C[n.have++]]=7&c,c>>>=3,d-=3}for(;n.have<19;)n.lens[C[n.have++]]=0;if(n.lencode=n.lendyn,n.lenbits=7,E={bits:n.lenbits},x=rn(0,n.lens,0,19,n.lencode,0,n.work,E),n.lenbits=E.bits,x){e.msg="invalid code lengths set",n.mode=Tn;break}n.have=0,n.mode=16198;case 16198:for(;n.have<n.nlen+n.ndist;){for(;T=n.lencode[c&(1<<n.lenbits)-1],g=T>>>24,v=T>>>16&255,b=65535&T,!(g<=d);){if(0===o)break e;o--,c+=r[i++]<<d,d+=8}if(b<16)c>>>=g,d-=g,n.lens[n.have++]=b;else{if(16===b){for(I=g+2;d<I;){if(0===o)break e;o--,c+=r[i++]<<d,d+=8}if(c>>>=g,d-=g,0===n.have){e.msg="invalid bit length repeat",n.mode=Tn;break}k=n.lens[n.have-1],p=3+(3&c),c>>>=2,d-=2}else if(17===b){for(I=g+3;d<I;){if(0===o)break e;o--,c+=r[i++]<<d,d+=8}c>>>=g,d-=g,k=0,p=3+(7&c),c>>>=3,d-=3}else{for(I=g+7;d<I;){if(0===o)break e;o--,c+=r[i++]<<d,d+=8}c>>>=g,d-=g,k=0,p=11+(127&c),c>>>=7,d-=7}if(n.have+p>n.nlen+n.ndist){e.msg="invalid bit length repeat",n.mode=Tn;break}for(;p--;)n.lens[n.have++]=k}}if(n.mode===Tn)break;if(0===n.lens[256]){e.msg="invalid code -- missing end-of-block",n.mode=Tn;break}if(n.lenbits=9,E={bits:n.lenbits},x=rn(1,n.lens,0,n.nlen,n.lencode,0,n.work,E),n.lenbits=E.bits,x){e.msg="invalid literal/lengths set",n.mode=Tn;break}if(n.distbits=6,n.distcode=n.distdyn,E={bits:n.distbits},x=rn(2,n.lens,n.nlen,n.ndist,n.distcode,0,n.work,E),n.distbits=E.bits,x){e.msg="invalid distances set",n.mode=Tn;break}if(n.mode=_n,t===on)break e;case _n:n.mode=kn;case kn:if(o>=6&&l>=258){e.next_out=a,e.avail_out=l,e.next_in=i,e.avail_in=o,n.hold=c,n.bits=d,Gt(e,u),a=e.next_out,s=e.output,l=e.avail_out,i=e.next_in,r=e.input,o=e.avail_in,c=n.hold,d=n.bits,n.mode===bn&&(n.back=-1);break}for(n.back=0;T=n.lencode[c&(1<<n.lenbits)-1],g=T>>>24,v=T>>>16&255,b=65535&T,!(g<=d);){if(0===o)break e;o--,c+=r[i++]<<d,d+=8}if(v&&!(240&v)){for(y=g,w=v,_=b;T=n.lencode[_+((c&(1<<y+w)-1)>>y)],g=T>>>24,v=T>>>16&255,b=65535&T,!(y+g<=d);){if(0===o)break e;o--,c+=r[i++]<<d,d+=8}c>>>=y,d-=y,n.back+=y}if(c>>>=g,d-=g,n.back+=g,n.length=b,0===v){n.mode=16205;break}if(32&v){n.back=-1,n.mode=bn;break}if(64&v){e.msg="invalid literal/length code",n.mode=Tn;break}n.extra=15&v,n.mode=16201;case 16201:if(n.extra){for(I=n.extra;d<I;){if(0===o)break e;o--,c+=r[i++]<<d,d+=8}n.length+=c&(1<<n.extra)-1,c>>>=n.extra,d-=n.extra,n.back+=n.extra}n.was=n.length,n.mode=16202;case 16202:for(;T=n.distcode[c&(1<<n.distbits)-1],g=T>>>24,v=T>>>16&255,b=65535&T,!(g<=d);){if(0===o)break e;o--,c+=r[i++]<<d,d+=8}if(!(240&v)){for(y=g,w=v,_=b;T=n.distcode[_+((c&(1<<y+w)-1)>>y)],g=T>>>24,v=T>>>16&255,b=65535&T,!(y+g<=d);){if(0===o)break e;o--,c+=r[i++]<<d,d+=8}c>>>=y,d-=y,n.back+=y}if(c>>>=g,d-=g,n.back+=g,64&v){e.msg="invalid distance code",n.mode=Tn;break}n.offset=b,n.extra=15&v,n.mode=16203;case 16203:if(n.extra){for(I=n.extra;d<I;){if(0===o)break e;o--,c+=r[i++]<<d,d+=8}n.offset+=c&(1<<n.extra)-1,c>>>=n.extra,d-=n.extra,n.back+=n.extra}if(n.offset>n.dmax){e.msg="invalid distance too far back",n.mode=Tn;break}n.mode=16204;case 16204:if(0===l)break e;if(p=u-l,n.offset>p){if(p=n.offset-p,p>n.whave&&n.sane){e.msg="invalid distance too far back",n.mode=Tn;break}p>n.wnext?(p-=n.wnext,f=n.wsize-p):f=n.wnext-p,p>n.length&&(p=n.length),m=n.window}else m=s,f=a-n.offset,p=n.length;p>l&&(p=l),l-=p,n.length-=p;do{s[a++]=m[f++]}while(--p);0===n.length&&(n.mode=kn);break;case 16205:if(0===l)break e;s[a++]=n.length,l--,n.mode=kn;break;case xn:if(n.wrap){for(;d<32;){if(0===o)break e;o--,c|=r[i++]<<d,d+=8}if(u-=l,e.total_out+=u,n.total+=u,4&n.wrap&&u&&(e.adler=n.check=n.flags?Ce(n.check,s,u,a-u):Ee(n.check,s,u,a-u)),u=l,4&n.wrap&&(n.flags?c:Sn(c))!==n.check){e.msg="incorrect data check",n.mode=Tn;break}c=0,d=0}n.mode=16207;case 16207:if(n.wrap&&n.flags){for(;d<32;){if(0===o)break e;o--,c+=r[i++]<<d,d+=8}if(4&n.wrap&&c!==(4294967295&n.total)){e.msg="incorrect length check",n.mode=Tn;break}c=0,d=0}n.mode=16208;case 16208:x=cn;break e;case Tn:x=un;break e;case 16210:return pn;default:return hn}return e.next_out=a,e.avail_out=l,e.next_in=i,e.avail_in=o,n.hold=c,n.bits=d,(n.wsize||u!==e.avail_out&&n.mode<Tn&&(n.mode<xn||t!==sn))&&Ln(e,e.output,e.next_out,u-e.avail_out),h-=e.avail_in,u-=e.avail_out,e.total_in+=h,e.total_out+=u,n.total+=u,4&n.wrap&&u&&(e.adler=n.check=n.flags?Ce(n.check,s,u,e.next_out-u):Ee(n.check,s,u,e.next_out-u)),e.data_type=n.bits+(n.last?64:0)+(n.mode===bn?128:0)+(n.mode===_n||n.mode===wn?256:0),(0===h&&0===u||t===sn)&&x===ln&&(x=fn),x},inflateEnd:e=>{if(In(e))return hn;let t=e.state;return t.window&&(t.window=null),e.state=null,ln},inflateGetHeader:(e,t)=>{if(In(e))return hn;const n=e.state;return 2&n.wrap?(n.head=t,t.done=!1,ln):hn},inflateSetDictionary:(e,t)=>{const n=t.length;let r,s,i;return In(e)?hn:(r=e.state,0!==r.wrap&&r.mode!==vn?hn:r.mode===vn&&(s=1,s=Ee(s,t,n,0),s!==r.check)?un:(i=Ln(e,t,n,n),i?(r.mode=16210,pn):(r.havedict=1,ln)))},inflateInfo:"pako inflate (from Nodeca project)"};var On=function(){this.text=0,this.time=0,this.xflags=0,this.os=0,this.extra=null,this.extra_len=0,this.name="",this.comment="",this.hcrc=0,this.done=!1};const Nn=Object.prototype.toString,{Z_NO_FLUSH:Hn,Z_FINISH:Fn,Z_OK:$n,Z_STREAM_END:jn,Z_NEED_DICT:qn,Z_STREAM_ERROR:Vn,Z_DATA_ERROR:Zn,Z_MEM_ERROR:Kn}=ze;function Wn(e){this.options=Rt({chunkSize:65536,windowBits:15,to:""},e||{});const t=this.options;t.raw&&t.windowBits>=0&&t.windowBits<16&&(t.windowBits=-t.windowBits,0===t.windowBits&&(t.windowBits=-15)),!(t.windowBits>=0&&t.windowBits<16)||e&&e.windowBits||(t.windowBits+=32),t.windowBits>15&&t.windowBits<48&&(15&t.windowBits||(t.windowBits|=15)),this.err=0,this.msg="",this.ended=!1,this.chunks=[],this.strm=new Lt,this.strm.avail_out=0;let n=Un.inflateInit2(this.strm,t.windowBits);if(n!==$n)throw new Error(Re[n]);if(this.header=new On,Un.inflateGetHeader(this.strm,this.header),t.dictionary&&("string"==typeof t.dictionary?t.dictionary=Bt(t.dictionary):"[object ArrayBuffer]"===Nn.call(t.dictionary)&&(t.dictionary=new Uint8Array(t.dictionary)),t.raw&&(n=Un.inflateSetDictionary(this.strm,t.dictionary),n!==$n)))throw new Error(Re[n])}function Jn(e,t){const n=new Wn(t);if(n.push(e),n.err)throw n.msg||Re[n.err];return n.result}Wn.prototype.push=function(e,t){const n=this.strm,r=this.options.chunkSize,s=this.options.dictionary;let i,a,o;if(this.ended)return!1;for(a=t===~~t?t:!0===t?Fn:Hn,"[object ArrayBuffer]"===Nn.call(e)?n.input=new Uint8Array(e):n.input=e,n.next_in=0,n.avail_in=n.input.length;;){for(0===n.avail_out&&(n.output=new Uint8Array(r),n.next_out=0,n.avail_out=r),i=Un.inflate(n,a),i===qn&&s&&(i=Un.inflateSetDictionary(n,s),i===$n?i=Un.inflate(n,a):i===Zn&&(i=qn));n.avail_in>0&&i===jn&&n.state.wrap>0&&0!==e[n.next_in];)Un.inflateReset(n),i=Un.inflate(n,a);switch(i){case Vn:case Zn:case qn:case Kn:return this.onEnd(i),this.ended=!0,!1}if(o=n.avail_out,n.next_out&&(0===n.avail_out||i===jn))if("string"===this.options.to){let e=Pt(n.output,n.next_out),t=n.next_out-e,s=At(n.output,e);n.next_out=t,n.avail_out=r-t,t&&n.output.set(n.output.subarray(e,e+t),0),this.onData(s)}else this.onData(n.output.length===n.next_out?n.output:n.output.subarray(0,n.next_out));if(i!==$n||0!==o){if(i===jn)return i=Un.inflateEnd(this.strm),this.onEnd(i),this.ended=!0,!0;if(0===n.avail_in)break}}return!0},Wn.prototype.onData=function(e){this.chunks.push(e)},Wn.prototype.onEnd=function(e){e===$n&&("string"===this.options.to?this.result=this.chunks.join(""):this.result=zt(this.chunks)),this.chunks=[],this.err=e,this.msg=this.strm.msg};var Xn={Inflate:Wn,inflate:Jn,inflateRaw:function(e,t){return(t=t||{}).raw=!0,Jn(e,t)},ungzip:Jn};const{Deflate:Gn,deflate:Qn,deflateRaw:Yn,gzip:er}=Jt,{Inflate:tr,inflate:nr,inflateRaw:rr,ungzip:sr}=Xn;var ir={Deflate:Gn,deflate:Qn,deflateRaw:Yn,gzip:er,Inflate:tr,inflate:nr,inflateRaw:rr,ungzip:sr,constants:ze};class ar{compress(e){try{const t=ir.deflate(e);if("undefined"!=typeof btoa){let e="";for(let n=0;n<t.length;n++)e+=String.fromCharCode(t[n]);return btoa(e)}return"undefined"!=typeof Buffer?Buffer.from(t).toString("base64"):e}catch(t){return console.error("Compressor: Error compressing data:",t),e}}decompress(e){try{let t;if("undefined"!=typeof atob){const n=atob(e);t=new Uint8Array(n.length);for(let e=0;e<n.length;e++)t[e]=n.charCodeAt(e)}else{if("undefined"==typeof Buffer)return e;{const n=Buffer.from(e,"base64");t=new Uint8Array(n)}}return ir.inflate(t,{to:"string"})}catch(t){return console.error("Compressor: Error decompressing data:",t),e}}shouldCompress(e){return e.length>1024}}class or{constructor(e){this.stages=e}process(e,t){let n=e;for(const r of this.stages){if(!n)return null;n=r.process(n,t)}return n}}class lr{constructor(e){this.sampler=e}process(e,t){return this.sampler.shouldSampleCritical(t.isCritical,t.sampleRate)?e:null}}class cr{constructor(e){this.deduplicator=e}process(e,t){return t.enableDeduplication&&this.deduplicator.isDuplicate(e)?null:e}}class dr{constructor(e){this.compressor=e}process(e,t){const n=P(e);if(!t.enableCompression||!n.properties)return n;const r=JSON.stringify(n.properties);return this.compressor.shouldCompress(r)&&(n.compressedProperties=this.compressor.compress(r),delete n.properties),n}}class hr{constructor(e={}){n(this,"sampler"),n(this,"deduplicator"),n(this,"compressor"),n(this,"pipeline"),n(this,"defaultOptions"),this.sampler=new F,this.deduplicator=new $,this.compressor=new ar,this.defaultOptions={sampleRate:e.sampleRate??1,enableDeduplication:e.enableDeduplication??!0,enableCompression:e.enableCompression??!1,isCritical:e.isCritical??!1},this.pipeline=new or([new lr(this.sampler),new cr(this.deduplicator),new dr(this.compressor)])}process(e,t={}){const n={sampleRate:t.sampleRate??this.defaultOptions.sampleRate,enableDeduplication:t.enableDeduplication??this.defaultOptions.enableDeduplication,enableCompression:t.enableCompression??this.defaultOptions.enableCompression,isCritical:t.isCritical??this.defaultOptions.isCritical};return this.pipeline.process(e,n)}processBatch(e,t={}){return e.map(e=>this.process(e,t)).filter(e=>null!==e)}serialize(e){try{return JSON.stringify(e)}catch(t){return console.error("DataProcessor: Error serializing event:",t),""}}deserialize(e){try{return JSON.parse(e)}catch(t){return console.error("DataProcessor: Error deserializing event:",t),null}}}function ur(){if("undefined"!=typeof AbortController)return AbortController;class e{constructor(){n(this,"aborted",!1)}abort(){this.aborted=!0}}return class{constructor(){n(this,"signal"),this.signal=new e}abort(){this.signal.abort()}}}async function pr(e,t){return new Promise((n,r)=>{const s=new XMLHttpRequest,i=(null==t?void 0:t.method)||"GET";if(s.open(i,e,!0),null==t?void 0:t.headers){new Headers(t.headers).forEach((e,t)=>{null!=e&&s.setRequestHeader(t,String(e))})}if(null==t?void 0:t.signal){const e=t.signal;if(e.aborted)return void r(new DOMException("Aborted","AbortError"));if("function"==typeof e.addEventListener)e.addEventListener("abort",()=>{s.abort(),r(new DOMException("Aborted","AbortError"))});else{const t=setInterval(()=>{e.aborted&&(clearInterval(t),s.abort(),r(new DOMException("Aborted","AbortError")))},100),n=()=>clearInterval(t);s.addEventListener("loadend",n),s.addEventListener("error",n),s.addEventListener("timeout",n)}}s.onload=()=>{const t=s.getAllResponseHeaders(),r={};t.split("\n").forEach(e=>{const t=e.split(": ");t[0]&&t[1]&&(r[t[0].toLowerCase()]=t[1])});const i=new Headers(r),a=s.responseText||"",o=s.responseURL||e,l=s.status,c={ok:l>=200&&l<300,status:l,statusText:s.statusText,type:"basic",url:o,headers:i,redirected:!1,body:null,bodyUsed:!1,arrayBuffer:()=>Promise.resolve(new ArrayBuffer(0)),blob:()=>Promise.resolve(new Blob),formData:()=>Promise.resolve(new FormData),json:async()=>{try{return JSON.parse(a||"{}")}catch{throw new TypeError("Invalid JSON response")}},text:()=>Promise.resolve(a),clone:()=>({...c,headers:new Headers(r)})};n(c)},s.onerror=()=>{r(new TypeError("Network request failed"))},s.ontimeout=()=>{r(new Error("Request timeout"))};const a=null==t?void 0:t.body;a instanceof FormData||a instanceof Blob||"string"==typeof a||null===a?s.send(a):a?s.send(String(a)):s.send(null)})}async function fr(e,t={}){const{method:n="POST",headers:r={},body:s,timeout:i=1e4}=t,a=new(ur()),o=setTimeout(()=>a.abort(),i);try{const t=function(){if("function"==typeof fetch)try{return new(ur()),fetch}catch{if("undefined"!=typeof XMLHttpRequest)return pr;throw new Error("AbortController is not available. This should not happen in Node.js 18+ or modern browsers.")}if("undefined"!=typeof XMLHttpRequest)return pr;throw new Error("fetch is not available. Node.js 18+ is required (engines.node >= 18.0.0). For browser environments, please use a modern browser or provide a fetch polyfill.")}(),i=await t(e,{method:n,headers:{"Content-Type":"application/json",...r},body:s,signal:a.signal});let l;clearTimeout(o);const c=i.headers.get("content-type");return l=c&&c.includes("application/json")?await i.json():await i.text(),{ok:i.ok,status:i.status,statusText:i.statusText,data:l}}catch(l){throw clearTimeout(o),l}}function mr(e,t,n={}){return async function(e,t={}){return fr(e,t)}(e,{...n,method:"POST",body:"string"==typeof t?t:JSON.stringify(t)})}class gr{async execute(e,t={}){const{maxRetries:n=3,initialDelay:r=1e3,maxDelay:s=1e4,shouldRetry:i=()=>!0}=t,a=Math.min(n,100);let o,l=r;for(let d=0;d<=a;d++)try{return await e()}catch(c){if(o=c,!(d<a&&i(c)))break;await this.sleep(l),l=Math.min(2*l,s)}throw o}sleep(e){return new Promise(t=>setTimeout(t,e))}isRetryableError(e){if(e instanceof Error){const t=e.message.toLowerCase();return t.includes("network")||t.includes("timeout")||t.includes("fetch")||t.includes("connection")}return!1}}class vr{constructor(e,t={}){n(this,"serverUrl"),n(this,"retryHandler"),n(this,"defaultMaxRetries"),this.serverUrl=e,this.retryHandler=new gr,this.defaultMaxRetries=t.maxRetries??3}async send(e,t={}){if(!this.serverUrl||"about:blank"===this.serverUrl)return!1;const{enableRetry:n=!0,maxRetries:r}=t,s=r??this.defaultMaxRetries;try{if(n)await this.retryHandler.execute(async()=>{const t=await mr(this.serverUrl,e);if(!t.ok)throw new Error(`HTTP ${t.status}: ${t.statusText}`);return t},{maxRetries:s,shouldRetry:e=>this.retryHandler.isRetryableError(e)});else{const t=await mr(this.serverUrl,e);if(!t.ok)throw new Error(`HTTP ${t.status}: ${t.statusText}`)}return!0}catch(i){return console.error("Sender: Error sending event:",i),!1}}async sendBatch(e,t={}){if(0===e.length)return!0;if(!this.serverUrl||"about:blank"===this.serverUrl)return!1;const{enableRetry:n=!0,maxRetries:r}=t,s=r??this.defaultMaxRetries;try{if(n)await this.retryHandler.execute(async()=>{const t=await mr(this.serverUrl,{events:e});if(!t.ok)throw new Error(`HTTP ${t.status}: ${t.statusText}`);return t},{maxRetries:s,shouldRetry:e=>this.retryHandler.isRetryableError(e)});else{const t=await mr(this.serverUrl,{events:e});if(!t.ok)throw new Error(`HTTP ${t.status}: ${t.statusText}`)}return!0}catch(i){return console.error("Sender: Error sending batch events:",i),!1}}setServerUrl(e){this.serverUrl=e}setMaxRetries(e){this.defaultMaxRetries=e}}function br(){if("undefined"==typeof PerformanceObserver)return!1;try{const e=new PerformanceObserver(()=>{});return e.observe({entryTypes:["longtask"]}),e.disconnect(),!0}catch{return!1}}function yr(){return"undefined"!=typeof IntersectionObserver}function wr(){return"undefined"!=typeof indexedDB}const _r=new class{constructor(){if(n(this,"storage",null),"undefined"!=typeof window&&window.localStorage)try{const e="__tracker_test__";window.localStorage.setItem(e,e),window.localStorage.removeItem(e),this.storage=window.localStorage}catch(e){}}getItem(e){if(!this.storage)return null;try{return this.storage.getItem(e)}catch(t){return null}}setItem(e,t){if(this.storage)try{this.storage.setItem(e,t)}catch(n){}}removeItem(e){if(this.storage)try{this.storage.removeItem(e)}catch(t){}}clear(){if(this.storage)try{this.storage.clear()}catch(e){}}},kr=new class{constructor(){if(n(this,"storage",null),"undefined"!=typeof window&&window.sessionStorage)try{const e="__tracker_test__";window.sessionStorage.setItem(e,e),window.sessionStorage.removeItem(e),this.storage=window.sessionStorage}catch(e){}}getItem(e){if(!this.storage)return null;try{return this.storage.getItem(e)}catch(t){return null}}setItem(e,t){if(this.storage)try{this.storage.setItem(e,t)}catch(n){}}removeItem(e){if(this.storage)try{this.storage.removeItem(e)}catch(t){}}clear(){if(this.storage)try{this.storage.clear()}catch(e){}}},xr=new class{constructor(){n(this,"data",new Map)}getItem(e){return this.data.get(e)||null}setItem(e,t){this.data.set(e,t)}removeItem(e){this.data.delete(e)}clear(){this.data.clear()}},Tr=new class{constructor(){n(this,"dbName","__tracker_db__"),n(this,"storeName","__tracker_store__"),n(this,"db",null),n(this,"initPromise",null)}async init(){return!!this.db||(this.initPromise?this.initPromise:!("undefined"==typeof window||!window.indexedDB)&&(this.initPromise=new Promise(e=>{const t=indexedDB.open(this.dbName,1);t.onerror=()=>{this.initPromise=null,e(!1)},t.onsuccess=()=>{this.db=t.result,this.initPromise=null,e(!0)},t.onupgradeneeded=e=>{const t=e.target.result;if(!t.objectStoreNames.contains(this.storeName)){t.createObjectStore(this.storeName,{keyPath:"id",autoIncrement:!0}).createIndex("key","key",{unique:!0})}}}),this.initPromise))}async getItem(e){return this.db||await this.init(),this.db?new Promise(t=>{let n;try{n=this.db.transaction([this.storeName],"readonly")}catch(s){return console.error("IndexedDBStorage: Error creating transaction for get:",s),void t(null)}n.onerror=()=>{console.error("IndexedDBStorage: Transaction error in get:",n.error),t(null)},n.onabort=()=>{console.error("IndexedDBStorage: Transaction aborted in get"),t(null)};const r=n.objectStore(this.storeName).index("key").get(e);r.onsuccess=()=>{const e=r.result;t(e?e.value:null)},r.onerror=()=>{console.error("IndexedDBStorage: Error in get request:",r.error),t(null)}}):null}async setItem(e,t){return this.db||await this.init(),!!this.db&&new Promise(n=>{let r;try{r=this.db.transaction([this.storeName],"readwrite")}catch(a){return console.error("IndexedDBStorage: Error creating transaction:",a),void n(!1)}r.onerror=()=>{console.error("IndexedDBStorage: Transaction error:",r.error),n(!1)},r.onabort=()=>{console.error("IndexedDBStorage: Transaction aborted"),n(!1)};const s=r.objectStore(this.storeName),i=s.index("key").get(e);i.onsuccess=()=>{const r={key:e,value:t,updatedAt:Date.now()};let a;i.result?(r.id=i.result.id,a=s.put(r)):a=s.add(r),a.onsuccess=()=>{n(!0)},a.onerror=()=>{console.error("IndexedDBStorage: Error in put/add request:",a.error),n(!1)}},i.onerror=()=>{console.error("IndexedDBStorage: Error in get request:",i.error),n(!1)}})}async removeItem(e){return!!this.db&&new Promise(t=>{let n;try{n=this.db.transaction([this.storeName],"readwrite")}catch(i){return console.error("IndexedDBStorage: Error creating transaction for remove:",i),void t(!1)}n.onerror=()=>{console.error("IndexedDBStorage: Transaction error in remove:",n.error),t(!1)},n.onabort=()=>{console.error("IndexedDBStorage: Transaction aborted in remove"),t(!1)};const r=n.objectStore(this.storeName),s=r.index("key").get(e);s.onsuccess=()=>{if(s.result){const e=r.delete(s.result.id);e.onsuccess=()=>t(!0),e.onerror=()=>{console.error("IndexedDBStorage: Error in delete request:",e.error),t(!1)}}else t(!0)},s.onerror=()=>{console.error("IndexedDBStorage: Error in get request for remove:",s.error),t(!1)}})}async getAll(){return this.db||await this.init(),this.db?new Promise(e=>{const t=this.db.transaction([this.storeName],"readonly").objectStore(this.storeName).getAll();t.onsuccess=()=>{const n=t.result.map(e=>({key:e.key,value:e.value}));e(n)},t.onerror=()=>{e([])}}):[]}};class Sr{constructor(e=1e3){if(n(this,"storageKey","__tracker_offline_events__"),n(this,"maxSize"),n(this,"useIndexedDB",!0),n(this,"memoryStorage",new Map),n(this,"saveQueue",Promise.resolve()),e<=0)throw new Error("OfflineStorage: maxSize must be positive");this.maxSize=e}async init(){if(!wr())return void(this.useIndexedDB=!1);await Tr.init()||(this.useIndexedDB=!1,console.warn("OfflineStorage: IndexedDB initialization failed, will use memory storage as fallback"))}async save(e){try{return this.saveQueue=this.saveQueue.then(async()=>{await this.doSave(e)}).catch(e=>{throw console.error("OfflineStorage: Error in save queue:",e),e}),await this.saveQueue,!0}catch(t){console.error("OfflineStorage: Error saving event:",t);try{const t=this.memoryStorage.get(this.storageKey)||[];return t.length>=this.maxSize&&t.shift(),t.push(this.sanitizeEvent(e)),this.memoryStorage.set(this.storageKey,t),!0}catch(n){return console.error("OfflineStorage: Fallback storage also failed:",n),!1}}}async doSave(e){try{const t=this.sanitizeEvent(e),n=await this.getAll();if(n.length>=this.maxSize&&n.shift(),n.push(t),this.useIndexedDB){const e=this.safeStringify(n);if(!e)throw new Error("Failed to stringify events");await Tr.setItem(this.storageKey,e)||(this.useIndexedDB=!1,this.memoryStorage.set(this.storageKey,n))}else this.memoryStorage.set(this.storageKey,n)}catch(t){if(console.error("OfflineStorage: Error in doSave:",t),!this.useIndexedDB)throw t;{this.useIndexedDB=!1;const t=this.memoryStorage.get(this.storageKey)||[];t.length>=this.maxSize&&t.shift(),t.push(this.sanitizeEvent(e)),this.memoryStorage.set(this.storageKey,t)}}}sanitizeEvent(e){return{...e,properties:e.properties?this.sanitizeObject(e.properties):void 0}}sanitizeObject(e,t=new WeakSet){if("object"!=typeof e||null===e)return e;if(t.has(e))return{};t.add(e);const n={};for(const[r,s]of Object.entries(e))n[r]="object"==typeof s&&null!==s?this.sanitizeObject(s,t):s;return n}safeStringify(e){try{return JSON.stringify(e)}catch(t){try{if("object"==typeof e&&null!==e){const t=this.sanitizeObject(e);return JSON.stringify(t)}return JSON.stringify(e)}catch(n){return console.error("OfflineStorage: Failed to stringify after sanitization:",n),null}}}async getAll(){try{if(this.useIndexedDB){const e=await Tr.getItem(this.storageKey);return e?JSON.parse(e):[]}return this.memoryStorage.get(this.storageKey)||[]}catch(e){return console.error("OfflineStorage: Error getting events:",e),this.useIndexedDB?(this.useIndexedDB=!1,this.memoryStorage.get(this.storageKey)||[]):[]}}async remove(e){try{const t=await this.getAll(),n=new Map(e.map(e=>[this.getEventKey(e),e])),r=t.filter(e=>!n.has(this.getEventKey(e)));if(0===r.length)return this.useIndexedDB?await Tr.removeItem(this.storageKey):this.memoryStorage.delete(this.storageKey),!0;if(this.useIndexedDB){const e=this.safeStringify(r);if(!e)throw new Error("Failed to stringify remaining events");const t=await Tr.setItem(this.storageKey,e);return t||(this.useIndexedDB=!1,this.memoryStorage.set(this.storageKey,r),!0)}return this.memoryStorage.set(this.storageKey,r),!0}catch(t){return console.error("OfflineStorage: Error removing events:",t),!1}}async clear(){try{return this.useIndexedDB?await Tr.removeItem(this.storageKey):this.memoryStorage.delete(this.storageKey),!0}catch(e){return console.error("OfflineStorage: Error clearing events:",e),!1}}async getCount(){return(await this.getAll()).length}getEventKey(e){return`${e.type}-${e.name}-${e.timestamp}-${e.url}`}}class Er{constructor(){n(this,"queue",[]),n(this,"eventCallbacks",new Map)}add(e,t){return this.queue.push(e),(null==t?void 0:t.onBatchComplete)&&this.eventCallbacks.set(e,t),this.queue.length}size(){return this.queue.length}isEmpty(){return 0===this.queue.length}drain(){const e=[...this.queue];this.queue=[];const t=new Map;return e.forEach(e=>{const n=this.eventCallbacks.get(e);if(null==n?void 0:n.onBatchComplete){const r=n.onBatchComplete;t.has(r)||t.set(r,[]),t.get(r).push(e)}this.eventCallbacks.delete(e)}),{events:e,callbackMap:t}}}class Ir{constructor(e={},t){n(this,"timer",null),n(this,"batchSize"),n(this,"batchWait"),this.onFlush=t,this.batchSize=e.batchSize??10,this.batchWait=e.batchWait??5e3}schedule(e){0!==this.batchSize?e>=this.batchSize?this.onFlush():0!==this.batchWait?this.timer||(this.timer=setTimeout(()=>{this.onFlush()},this.batchWait)):this.onFlush():this.onFlush()}clear(){this.timer&&(clearTimeout(this.timer),this.timer=null)}getTimer(){return this.timer}setOptions(e){void 0!==e.batchSize&&(this.batchSize=e.batchSize),void 0!==e.batchWait&&(this.batchWait=e.batchWait)}}class Cr{constructor(e,t){this.sender=e,this.offlineRecoveryManager=t}async deliverBatch(e,t,n){try{const r=await this.sender.sendBatch(e,{maxRetries:n.maxRetries});!r&&n.enableOfflineStorage&&await this.offlineRecoveryManager.persistFailedEvents(e),this.dispatchCallbacks(t,r)}catch(r){console.error("BatchSender: Error flushing events:",r),n.enableOfflineStorage&&await this.offlineRecoveryManager.persistFailedEvents(e),this.dispatchCallbacks(t,!1)}}dispatchCallbacks(e,t){e.forEach((e,n)=>{try{n(e,t)}catch(r){console.error("BatchSender: Error in batch complete callback:",r)}})}}class Rr{constructor(e,t){this.sender=e,this.offlineStorage=t}async persistFailedEvents(e){for(const t of e)await this.offlineStorage.save(t)}async recoverStoredEvents(e){try{const t=await this.offlineStorage.getAll();if(0===t.length)return;for(let n=0;n<t.length;n+=e.batchSize){const r=t.slice(n,n+e.batchSize);if(!(await this.sender.sendBatch(r,{maxRetries:e.maxRetries})))break;await this.offlineStorage.remove(r)}}catch(t){console.error("BatchSender: Error flushing offline events:",t)}}}class zr{constructor(e,t={}){n(this,"sender"),n(this,"offlineStorage"),n(this,"eventQueue"),n(this,"flushScheduler"),n(this,"deliveryCoordinator"),n(this,"offlineRecoveryManager"),n(this,"batchSize"),n(this,"maxRetries"),n(this,"enableOfflineStorage"),n(this,"state","idle"),n(this,"isProcessing",!1),n(this,"flushPromise",null),n(this,"isInitialized",!1),n(this,"initPromise",null),this.maxRetries=t.maxRetries??3,this.sender=new vr(e,{maxRetries:this.maxRetries}),this.offlineStorage=new Sr(t.maxOfflineStorageSize??1e3),this.eventQueue=new Er,this.offlineRecoveryManager=new Rr(this.sender,this.offlineStorage),this.deliveryCoordinator=new Cr(this.sender,this.offlineRecoveryManager),this.batchSize=t.batchSize??10,this.flushScheduler=new Ir({batchSize:t.batchSize,batchWait:t.batchWait},()=>{this.flush()}),this.enableOfflineStorage=t.enableOfflineStorage??!0,this.initPromise=this.init()}get timer(){return this.flushScheduler.getTimer()}getState(){return this.state}async init(){this.enableOfflineStorage&&(await this.offlineStorage.init(),this.offlineRecoveryManager.recoverStoredEvents({batchSize:this.batchSize,maxRetries:this.maxRetries})),this.isInitialized=!0}async ensureInitialized(){!this.isInitialized&&this.initPromise&&await this.initPromise}add(e,t){const n=this.eventQueue.add(e,t);this.flushScheduler.schedule(n),"idle"===this.state&&n>0&&(this.state=this.timer?"scheduled":this.state)}async addAsync(e){await this.ensureInitialized(),this.add(e)}async flush(){this.isProcessing?await(this.flushPromise??Promise.resolve()):this.eventQueue.isEmpty()?"destroying"===this.state?this.state="destroyed":"destroyed"!==this.state&&(this.state="idle"):(await this.ensureInitialized(),this.isProcessing=!0,this.state="flushing",this.flushPromise=(async()=>{this.flushScheduler.clear();const{events:e,callbackMap:t}=this.eventQueue.drain();try{await this.deliveryCoordinator.deliverBatch(e,t,{maxRetries:this.maxRetries,enableOfflineStorage:this.enableOfflineStorage})}finally{this.isProcessing=!1,this.flushPromise=null,this.eventQueue.isEmpty()?"destroying"===this.state?this.state="destroyed":this.state="idle":(this.state="destroying"===this.state?"destroying":"scheduled",setTimeout(()=>{this.flush().catch(e=>{console.error("BatchSender: Error in recursive flush:",e)})},0))}})(),await this.flushPromise)}setServerUrl(e){this.sender.setServerUrl(e)}setMaxRetries(e){this.maxRetries=e,this.sender.setMaxRetries(e)}setBatchOptions(e){void 0!==e.batchSize&&(this.batchSize=e.batchSize),this.flushScheduler.setOptions(e)}async getOfflineEvents(){return await this.ensureInitialized(),this.offlineStorage.getAll()}async getOfflineEventCount(){return await this.ensureInitialized(),this.offlineStorage.getCount()}async clearOfflineStorage(){return await this.ensureInitialized(),this.offlineStorage.clear()}destroy(){this.state="destroying",this.flushScheduler.clear(),this.flush().catch(e=>{console.error("BatchSender: Error during destroy flush:",e)})}async destroyAsync(){this.state="destroying",this.flushScheduler.clear(),await this.flush(),this.state="destroyed"}}class Dr{canInstall(e,t,n){return t.has(e.name)?(console.warn(`PluginManager: Plugin "${e.name}" is already installed`),!1):!!n||(console.error("PluginManager: Tracker instance is not set"),!1)}install(e,t){try{return e.install(t),!0}catch(n){return console.error(`PluginManager: Error installing plugin "${e.name}":`,n),!1}}uninstall(e,t,n){if(t.uninstall&&n)try{t.uninstall(n)}catch(r){console.error(`PluginManager: Error uninstalling plugin "${e}":`,r)}}}class Mr{constructor(e=new Dr){n(this,"plugins",new Map),n(this,"trackerInstance",null),n(this,"lifecycle"),this.lifecycle=e}setTrackerInstance(e){this.trackerInstance=e}use(e){this.lifecycle.canInstall(e,this.plugins,this.trackerInstance)&&this.lifecycle.install(e,this.trackerInstance)&&this.plugins.set(e.name,e)}unuse(e){const t=this.plugins.get(e);t&&(this.lifecycle.uninstall(e,t,this.trackerInstance),this.plugins.delete(e))}get(e){return this.plugins.get(e)}getAll(){return Array.from(this.plugins.values())}clear(){for(const e of this.plugins.keys())this.unuse(e)}}class Br{constructor(){n(this,"pageViews",[]),n(this,"startTime",Date.now())}analyzePageView(e){this.pageViews.push(e)}getMetrics(){const e=new Set,t=new Set;let n=0;const r=[];return this.pageViews.forEach(s=>{s.deviceId&&e.add(s.deviceId),s.sessionId&&t.add(s.sessionId),s.duration&&(n+=s.duration),r.push(s.url)}),{pv:this.pageViews.length,uv:e.size,sessions:t.size,avgDuration:this.pageViews.length>0?n/this.pageViews.length:0,paths:r}}getVisitPath(){return this.pageViews.map(e=>e.url)}getDuration(){return Date.now()-this.startTime}reset(){this.pageViews=[],this.startTime=Date.now()}}class Ar{constructor(e){this.options=e}evaluate(e,t,n){if("navigation"!==e.metricType&&"longtask"!==e.metricType)return[];const r=[];for(const s of t){if(!s.enabled)continue;const t=this.resolveMetricValue(s,e);if(void 0===t||!this.isTriggered(s,t))continue;const i=this.createAlert(s,t,e);n.push(i),r.push(i),this.options.onAlert(i)}return r}resolveMetricValue(e,t){return"ttfb"===e.metric&&"navigation"===t.metricType?t.metrics.ttfb:"total"===e.metric&&"navigation"===t.metricType?t.metrics.total:"longtask"===e.metric&&"longtask"===t.metricType?t.metrics.duration:void 0}isTriggered(e,t){switch(e.operator){case">":return t>e.threshold;case">=":return t>=e.threshold;case"<":return t<e.threshold;case"<=":return t<=e.threshold;default:return!1}}createAlert(e,t,n){let r="warning";return t>2*e.threshold?r="critical":t>1.5*e.threshold&&(r="error"),{id:`alert-${Date.now()}-${Math.random().toString(36).substring(2,11)}`,ruleId:e.id,level:r,message:e.message||`${e.name}: ${t.toFixed(2)}ms 超过阈值 ${e.threshold}ms`,value:t,threshold:e.threshold,timestamp:Date.now(),url:n.url,resolved:!1}}}class Pr{constructor(){n(this,"timer",null)}start(e){return this.timer||"undefined"==typeof window||(this.timer=window.setInterval(()=>{e()},36e5)),this.timer}stop(){this.timer&&"undefined"!=typeof window?(clearInterval(this.timer),this.timer=null):this.timer=null}getTimer(){return this.timer}}class Lr{build(e,t,n){const r=Date.now(),s=t||r-36e5,i=n||r,a=e.filter(e=>e.timestamp>=s&&e.timestamp<=i),o=a.filter(e=>"navigation"===e.metricType),l=a.filter(e=>"resource"===e.metricType),c=a.filter(e=>"longtask"===e.metricType);return{navigation:{dns:this.average(o.map(e=>e.metrics),"dns"),tcp:this.average(o.map(e=>e.metrics),"tcp"),ssl:this.average(o.map(e=>e.metrics),"ssl"),ttfb:this.average(o.map(e=>e.metrics),"ttfb"),response:this.average(o.map(e=>e.metrics),"response"),domParse:this.average(o.map(e=>e.metrics),"domParse"),resourceLoad:this.average(o.map(e=>e.metrics),"resourceLoad"),total:this.average(o.map(e=>e.metrics),"total"),domContentLoaded:this.average(o.map(e=>e.metrics),"domContentLoaded"),load:this.average(o.map(e=>e.metrics),"load")},resources:this.buildResourceMetrics(l),longTasks:this.buildLongTaskMetrics(c),timeRange:{start:s,end:i}}}buildResourceMetrics(e){const t={total:e.length,avgLoadTime:0,maxLoadTime:0,totalSize:0,byType:{}};if(0===e.length)return t;const n=e.map(e=>e.metrics.total||0).filter(e=>e>0);n.length>0&&(t.avgLoadTime=n.reduce((e,t)=>e+t,0)/n.length,t.maxLoadTime=Math.max(...n)),t.totalSize=e.reduce((e,t)=>e+(t.metrics.size||0),0);const r=new Map;return e.forEach(e=>{const t=e.metrics,n=t.resourceType||"unknown";r.has(n)||r.set(n,[]),r.get(n).push(t.total||0)}),r.forEach((n,r)=>{const s=e.filter(e=>e.metrics.resourceType===r);t.byType[r]={count:n.length,avgLoadTime:n.reduce((e,t)=>e+t,0)/n.length,totalSize:s.reduce((e,t)=>e+(t.metrics.size||0),0)}}),t}buildLongTaskMetrics(e){const t={total:e.length,avgDuration:0,maxDuration:0,recent:e.slice(-10).map(e=>({duration:e.metrics.duration||0,startTime:e.metrics.startTime||0,timestamp:e.timestamp}))};if(0===e.length)return t;const n=e.map(e=>e.metrics.duration||0).filter(e=>e>0);return n.length>0&&(t.avgDuration=n.reduce((e,t)=>e+t,0)/n.length,t.maxDuration=Math.max(...n)),t}average(e,t){const n=e.map(e=>e[t]||0).filter(e=>e>0);return 0===n.length?0:n.reduce((e,t)=>e+t,0)/n.length}}class Ur{constructor(e){this.storageKey=e}async save(e,t){try{const n={events:e.slice(-1e3),alerts:t.slice(-100),timestamp:Date.now()};await Tr.setItem(this.storageKey,JSON.stringify(n))}catch(n){console.error("PerformanceMonitor: Failed to save to storage:",n)}}async load(){try{const e=await Tr.getItem(this.storageKey);return e?JSON.parse(e):{}}catch(e){return console.error("PerformanceMonitor: Failed to load history data:",e),{}}}}class Or{constructor(e={}){n(this,"events",[]),n(this,"alerts",[]),n(this,"alertRules",[]),n(this,"options"),n(this,"storageKey"),n(this,"maxStoredEvents"),n(this,"retentionTime"),n(this,"alertEngine"),n(this,"metricsAggregator"),n(this,"storage"),n(this,"cleanupScheduler"),this.options={enableAlerts:e.enableAlerts??!0,defaultAlertRules:e.defaultAlertRules??this.getDefaultAlertRules(),onAlert:e.onAlert??(()=>{}),storageKey:e.storageKey??"__tracker_performance_events__",maxStoredEvents:e.maxStoredEvents??1e4,retentionTime:e.retentionTime??6048e5},this.storageKey=this.options.storageKey,this.maxStoredEvents=this.options.maxStoredEvents,this.retentionTime=this.options.retentionTime,this.alertRules=this.options.defaultAlertRules,this.storage=new Ur(this.storageKey),this.cleanupScheduler=new Pr,this.alertEngine=new Ar({onAlert:e=>{this.options.onAlert(e)}}),this.metricsAggregator=new Lr,this.init()}init(){const e=(...e)=>{const t=e[0];this.handlePerformanceEvent(t)};E.on("performance",e),this._performanceHandler=e,this.loadHistoryData(),this.startCleanupTimer()}handlePerformanceEvent(e){this.events.push(e),this.events.length>this.maxStoredEvents&&(this.events=this.events.slice(-this.maxStoredEvents)),this.options.enableAlerts&&this.checkAlertRules(e),this.saveToStorage()}checkAlertRules(e){this.alertEngine.evaluate(e,this.alertRules,this.alerts),this.alerts.length>1e3&&(this.alerts=this.alerts.slice(-1e3))}getDefaultAlertRules(){return[{id:"ttfb-warning",name:"TTFB告警",metric:"ttfb",threshold:1e3,operator:">",enabled:!0,message:"TTFB超过1000ms,可能影响用户体验"},{id:"total-load-warning",name:"总加载时间告警",metric:"total",threshold:3e3,operator:">",enabled:!0,message:"页面总加载时间超过3000ms,可能影响用户体验"},{id:"longtask-warning",name:"长任务告警",metric:"longtask",threshold:50,operator:">",enabled:!0,message:"检测到长任务超过50ms,可能阻塞主线程"}]}getMetrics(e,t){return this.metricsAggregator.build(this.events,e,t)}generateReport(e={}){const t=Date.now(),n=e.startTime||(e.duration?t-e.duration:t-36e5),r=e.endTime||t,s=this.getMetrics(n,r),i=this.alerts.filter(e=>e.timestamp>=n&&e.timestamp<=r),a={pageLoads:this.events.filter(e=>"navigation"===e.metricType&&e.timestamp>=n&&e.timestamp<=r).length,avgTTFB:s.navigation.ttfb,avgTotalLoadTime:s.navigation.total,totalLongTasks:s.longTasks.total,totalResources:s.resources.total},o=this.generateTrends(n,r);return{id:`report-${Date.now()}`,generatedAt:t,timeRange:{start:n,end:r},summary:a,metrics:s,alerts:i,trends:o}}generateTrends(e,t){const n=[];let r=e;for(;r<t;){const e=Math.min(r+36e5,t),s=this.getMetrics(r,e);n.push({time:r,metrics:{navigation:s.navigation,resources:{total:s.resources.total,avgLoadTime:s.resources.avgLoadTime,maxLoadTime:s.resources.maxLoadTime,totalSize:s.resources.totalSize,byType:s.resources.byType},longTasks:{total:s.longTasks.total,avgDuration:s.longTasks.avgDuration,maxDuration:s.longTasks.maxDuration,recent:s.longTasks.recent}}}),r=e}return n}getAlerts(e){return void 0===e?[...this.alerts]:this.alerts.filter(t=>t.resolved===e)}addAlertRule(e){this.alertRules.push(e)}removeAlertRule(e){const t=this.alertRules.findIndex(t=>t.id===e);return t>=0&&(this.alertRules.splice(t,1),!0)}getAlertRules(){return[...this.alertRules]}resolveAlert(e){const t=this.alerts.find(t=>t.id===e);return!!t&&(t.resolved=!0,!0)}async saveToStorage(){await this.storage.save(this.events,this.alerts)}async loadHistoryData(){const e=await this.storage.load();e.events&&(this.events=e.events),e.alerts&&(this.alerts=e.alerts)}startCleanupTimer(){this.cleanupScheduler.start(()=>{this.cleanup()})}cleanup(){const e=Date.now()-this.retentionTime;this.events=this.events.filter(t=>t.timestamp>=e),this.alerts=this.alerts.filter(t=>t.timestamp>=e),this.saveToStorage()}destroy(){const e=this._performanceHandler;e&&E.off("performance",e),this.cleanupScheduler.stop()}}const Nr='\n<!DOCTYPE html>\n<html lang="zh-CN">\n<head>\n <meta charset="UTF-8">\n <meta name="viewport" content="width=device-width, initial-scale=1.0">\n <title>性能监控面板 - Tracker SDK</title>\n <style>\n * {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n }\n body {\n font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, \'Helvetica Neue\', Arial, sans-serif;\n background: #f5f5f5;\n padding: 20px;\n }\n .container {\n max-width: 1400px;\n margin: 0 auto;\n background: white;\n border-radius: 8px;\n box-shadow: 0 2px 8px rgba(0,0,0,0.1);\n padding: 30px;\n }\n h1 {\n color: #333;\n margin-bottom: 10px;\n border-bottom: 3px solid #9C27B0;\n padding-bottom: 10px;\n }\n .subtitle {\n color: #666;\n margin-bottom: 30px;\n }\n .toolbar {\n display: flex;\n gap: 10px;\n margin-bottom: 20px;\n flex-wrap: wrap;\n }\n button {\n background: #9C27B0;\n color: white;\n border: none;\n padding: 10px 20px;\n border-radius: 4px;\n cursor: pointer;\n font-size: 14px;\n transition: background 0.3s;\n }\n button:hover {\n background: #7B1FA2;\n }\n button.secondary {\n background: #2196F3;\n }\n button.secondary:hover {\n background: #1976D2;\n }\n button.success {\n background: #4CAF50;\n }\n button.success:hover {\n background: #45a049;\n }\n .stats-grid {\n display: grid;\n grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));\n gap: 15px;\n margin-bottom: 30px;\n }\n .stat-card {\n background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n color: white;\n padding: 20px;\n border-radius: 8px;\n box-shadow: 0 2px 4px rgba(0,0,0,0.1);\n }\n .stat-card.warning {\n background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);\n }\n .stat-card.success {\n background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);\n }\n .stat-card.info {\n background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);\n }\n .stat-label {\n font-size: 12px;\n opacity: 0.9;\n margin-bottom: 5px;\n }\n .stat-value {\n font-size: 32px;\n font-weight: bold;\n }\n .stat-unit {\n font-size: 14px;\n opacity: 0.8;\n margin-left: 5px;\n }\n .tabs {\n display: flex;\n gap: 10px;\n margin-bottom: 20px;\n border-bottom: 2px solid #eee;\n }\n .tab {\n padding: 10px 20px;\n cursor: pointer;\n border: none;\n background: none;\n color: #666;\n font-size: 14px;\n border-bottom: 2px solid transparent;\n margin-bottom: -2px;\n }\n .tab.active {\n color: #9C27B0;\n border-bottom-color: #9C27B0;\n font-weight: bold;\n }\n .tab-content {\n display: none;\n }\n .tab-content.active {\n display: block;\n }\n .metrics-table {\n width: 100%;\n border-collapse: collapse;\n margin-top: 20px;\n }\n .metrics-table th,\n .metrics-table td {\n padding: 12px;\n text-align: left;\n border-bottom: 1px solid #eee;\n }\n .metrics-table th {\n background: #f9f9f9;\n font-weight: bold;\n color: #333;\n }\n .metrics-table tr:hover {\n background: #f9f9f9;\n }\n .alert-item {\n padding: 15px;\n border-left: 4px solid #f44336;\n background: #fff3f3;\n margin-bottom: 10px;\n border-radius: 4px;\n }\n .alert-item.warning {\n border-left-color: #FF9800;\n background: #fff8f0;\n }\n .alert-item.error {\n border-left-color: #f44336;\n background: #fff3f3;\n }\n .alert-item.critical {\n border-left-color: #d32f2f;\n background: #ffebee;\n }\n .alert-header {\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin-bottom: 5px;\n }\n .alert-level {\n display: inline-block;\n padding: 4px 8px;\n border-radius: 4px;\n font-size: 12px;\n font-weight: bold;\n color: white;\n }\n .alert-level.warning {\n background: #FF9800;\n }\n .alert-level.error {\n background: #f44336;\n }\n .alert-level.critical {\n background: #d32f2f;\n }\n .alert-time {\n color: #999;\n font-size: 12px;\n }\n .chart-container {\n width: 100%;\n height: 300px;\n margin: 20px 0;\n position: relative;\n }\n .chart-bar {\n display: flex;\n align-items: flex-end;\n height: 250px;\n gap: 10px;\n padding: 20px;\n background: #f9f9f9;\n border-radius: 4px;\n }\n .chart-bar-item {\n flex: 1;\n background: linear-gradient(to top, #9C27B0, #7B1FA2);\n border-radius: 4px 4px 0 0;\n position: relative;\n min-height: 10px;\n }\n .chart-bar-label {\n text-align: center;\n margin-top: 5px;\n font-size: 12px;\n color: #666;\n }\n .chart-bar-value {\n position: absolute;\n top: -20px;\n left: 50%;\n transform: translateX(-50%);\n font-size: 11px;\n color: #333;\n font-weight: bold;\n }\n .loading {\n text-align: center;\n padding: 40px;\n color: #666;\n }\n .spinner {\n border: 3px solid #f3f3f3;\n border-top: 3px solid #9C27B0;\n border-radius: 50%;\n width: 40px;\n height: 40px;\n animation: spin 1s linear infinite;\n margin: 0 auto 20px;\n }\n @keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n }\n .empty-state {\n text-align: center;\n padding: 60px 20px;\n color: #999;\n }\n </style>\n</head>\n<body>\n <div class="container">\n <h1>📊 性能监控面板</h1>\n <p class="subtitle">实时性能指标监控和告警</p>\n\n <div class="toolbar">\n <button onclick="refreshData()">🔄 刷新数据</button>\n <button class="secondary" onclick="generateReport()">📄 生成报告</button>\n <button class="success" onclick="exportData()">📥 导出数据</button>\n </div>\n\n <div class="stats-grid" id="stats-grid">\n <div class="stat-card">\n <div class="stat-label">TTFB</div>\n <div class="stat-value" id="stat-ttfb">-<span class="stat-unit">ms</span></div>\n </div>\n <div class="stat-card">\n <div class="stat-label">总加载时间</div>\n <div class="stat-value" id="stat-total">-<span class="stat-unit">ms</span></div>\n </div>\n <div class="stat-card info">\n <div class="stat-label">资源总数</div>\n <div class="stat-value" id="stat-resources">-</div>\n </div>\n <div class="stat-card warning">\n <div class="stat-label">长任务</div>\n <div class="stat-value" id="stat-longtasks">-</div>\n </div>\n <div class="stat-card warning">\n <div class="stat-label">活跃告警</div>\n <div class="stat-value" id="stat-alerts">-</div>\n </div>\n </div>\n\n <div class="tabs">\n <button class="tab active" onclick="switchTab(\'navigation\')" data-tab="navigation">页面加载</button>\n <button class="tab" onclick="switchTab(\'resources\')" data-tab="resources">资源加载</button>\n <button class="tab" onclick="switchTab(\'longtasks\')" data-tab="longtasks">长任务</button>\n <button class="tab" onclick="switchTab(\'alerts\')" data-tab="alerts">告警</button>\n </div>\n\n <div id="tab-navigation" class="tab-content active">\n <h2>页面加载性能</h2>\n <div class="chart-container">\n <div class="chart-bar" id="navigation-chart"></div>\n </div>\n <table class="metrics-table">\n <thead>\n <tr>\n <th>指标</th>\n <th>值</th>\n <th>说明</th>\n </tr>\n </thead>\n <tbody id="navigation-metrics">\n </tbody>\n </table>\n </div>\n\n <div id="tab-resources" class="tab-content">\n <h2>资源加载性能</h2>\n <table class="metrics-table">\n <thead>\n <tr>\n <th>资源类型</th>\n <th>数量</th>\n <th>平均加载时间</th>\n <th>总大小</th>\n </tr>\n </thead>\n <tbody id="resources-metrics">\n </tbody>\n </table>\n </div>\n\n <div id="tab-longtasks" class="tab-content">\n <h2>长任务监控</h2>\n <table class="metrics-table">\n <thead>\n <tr>\n <th>时间</th>\n <th>持续时间</th>\n <th>开始时间</th>\n </tr>\n </thead>\n <tbody id="longtasks-metrics">\n </tbody>\n </table>\n </div>\n\n <div id="tab-alerts" class="tab-content">\n <h2>性能告警</h2>\n <div id="alerts-list"></div>\n </div>\n </div>\n\n <script>\n // 标记这是SDK内部面板,不应被监控\n window.__trackerInternalPanel = true;\n \n let metricsData = null;\n let alertsData = [];\n\n // 从父窗口获取Tracker实例\n function getTrackerInstance() {\n if (window.opener && window.opener.__trackerInstance) {\n return window.opener.__trackerInstance;\n }\n // 尝试从全局变量获取\n if (window.__trackerInstance) {\n return window.__trackerInstance;\n }\n return null;\n }\n\n // 刷新数据\n async function refreshData() {\n const tracker = getTrackerInstance();\n if (!tracker) {\n alert(\'无法获取Tracker实例,请确保从Tracker打开此面板\');\n return;\n }\n\n try {\n // 获取性能指标\n metricsData = tracker.getPerformanceMetrics();\n \n // 获取告警\n alertsData = tracker.getPerformanceMonitor().getAlerts(false);\n\n // 更新UI\n updateStats();\n updateNavigationTab();\n updateResourcesTab();\n updateLongTasksTab();\n updateAlertsTab();\n } catch (error) {\n console.error(\'刷新数据失败:\', error);\n alert(\'刷新数据失败: \' + (error instanceof Error ? error.message : String(error)));\n }\n }\n\n // 更新统计卡片\n function updateStats() {\n if (!metricsData) return;\n\n document.getElementById(\'stat-ttfb\').innerHTML = \n Math.round(metricsData.navigation.ttfb) + \'<span class="stat-unit">ms</span>\';\n document.getElementById(\'stat-total\').innerHTML = \n Math.round(metricsData.navigation.total) + \'<span class="stat-unit">ms</span>\';\n document.getElementById(\'stat-resources\').textContent = metricsData.resources.total;\n document.getElementById(\'stat-longtasks\').textContent = metricsData.longTasks.total;\n document.getElementById(\'stat-alerts\').textContent = alertsData.length;\n }\n\n // 更新页面加载标签页\n function updateNavigationTab() {\n if (!metricsData) return;\n\n const nav = metricsData.navigation;\n const metrics = [\n { name: \'DNS查询\', value: nav.dns, desc: \'域名解析时间\' },\n { name: \'TCP连接\', value: nav.tcp, desc: \'TCP连接建立时间\' },\n { name: \'SSL握手\', value: nav.ssl, desc: \'SSL/TLS握手时间\' },\n { name: \'TTFB\', value: nav.ttfb, desc: \'首字节时间\' },\n { name: \'响应时间\', value: nav.response, desc: \'服务器响应时间\' },\n { name: \'DOM解析\', value: nav.domParse, desc: \'DOM解析时间\' },\n { name: \'资源加载\', value: nav.resourceLoad, desc: \'资源加载时间\' },\n { name: \'总加载时间\', value: nav.total, desc: \'页面总加载时间\' }\n ];\n\n const tbody = document.getElementById(\'navigation-metrics\');\n tbody.innerHTML = metrics.map(m => `\n <tr>\n <td><strong>${m.name}</strong></td>\n <td>${Math.round(m.value)} ms</td>\n <td>${m.desc}</td>\n </tr>\n `).join(\'\');\n\n // 更新图表\n updateNavigationChart(metrics);\n }\n\n // 更新导航图表\n function updateNavigationChart(metrics) {\n const chart = document.getElementById(\'navigation-chart\');\n const values = metrics.map(m => m.value).filter(v => v > 0);\n const maxValue = values.length > 0 ? Math.max(...values) : 1;\n \n chart.innerHTML = metrics.map(m => {\n const height = maxValue > 0 ? (m.value / maxValue) * 100 : 0;\n return `\n <div class="chart-bar-item" style="height: ${height}%">\n <div class="chart-bar-value">${Math.round(m.value)}ms</div>\n </div>\n `;\n }).join(\'\') + metrics.map(m => `\n <div class="chart-bar-label">${m.name}</div>\n `).join(\'\');\n }\n\n // 更新资源标签页\n function updateResourcesTab() {\n if (!metricsData) return;\n\n const resources = metricsData.resources;\n const tbody = document.getElementById(\'resources-metrics\');\n \n if (Object.keys(resources.byType).length === 0) {\n tbody.innerHTML = \'<tr><td colspan="4" style="text-align: center; color: #999;">暂无资源数据</td></tr>\';\n return;\n }\n\n tbody.innerHTML = Object.entries(resources.byType).map(([type, stats]) => `\n <tr>\n <td><strong>${type}</strong></td>\n <td>${stats.count}</td>\n <td>${Math.round(stats.avgLoadTime)} ms</td>\n <td>${formatSize(stats.totalSize)}</td>\n </tr>\n `).join(\'\');\n\n // 添加总计行\n tbody.innerHTML += `\n <tr style="background: #f9f9f9; font-weight: bold;">\n <td>总计</td>\n <td>${resources.total}</td>\n <td>${Math.round(resources.avgLoadTime)} ms</td>\n <td>${formatSize(resources.totalSize)}</td>\n </tr>\n `;\n }\n\n // 更新长任务标签页\n function updateLongTasksTab() {\n if (!metricsData) return;\n\n const longTasks = metricsData.longTasks;\n const tbody = document.getElementById(\'longtasks-metrics\');\n \n if (longTasks.recent.length === 0) {\n tbody.innerHTML = \'<tr><td colspan="3" style="text-align: center; color: #999;">暂无长任务数据</td></tr>\';\n return;\n }\n\n tbody.innerHTML = longTasks.recent.map(task => {\n const date = new Date(task.timestamp);\n return `\n <tr>\n <td>${date.toLocaleString()}</td>\n <td>${Math.round(task.duration)} ms</td>\n <td>${Math.round(task.startTime)}</td>\n </tr>\n `;\n }).join(\'\');\n }\n\n // 更新告警标签页\n function updateAlertsTab() {\n const container = document.getElementById(\'alerts-list\');\n \n if (alertsData.length === 0) {\n container.innerHTML = \'<div class="empty-state"><p>暂无告警</p></div>\';\n return;\n }\n\n container.innerHTML = alertsData.map(alert => {\n const date = new Date(alert.timestamp);\n return `\n <div class="alert-item ${alert.level}">\n <div class="alert-header">\n <div>\n <span class="alert-level ${alert.level}">${alert.level.toUpperCase()}</span>\n <strong style="margin-left: 10px;">${alert.message}</strong>\n </div>\n <span class="alert-time">${date.toLocaleString()}</span>\n </div>\n <div style="margin-top: 5px; color: #666; font-size: 13px;">\n 值: ${Math.round(alert.value)}ms | 阈值: ${alert.threshold}ms\n ${alert.url ? \' | URL: \' + alert.url : \'\'}\n </div>\n </div>\n `;\n }).join(\'\');\n }\n\n // 切换标签页\n function switchTab(tabName) {\n // 更新标签按钮\n document.querySelectorAll(\'.tab\').forEach(tab => {\n tab.classList.remove(\'active\');\n if (tab.getAttribute(\'data-tab\') === tabName) {\n tab.classList.add(\'active\');\n }\n });\n\n // 更新内容\n document.querySelectorAll(\'.tab-content\').forEach(content => content.classList.remove(\'active\'));\n const targetTab = document.getElementById(\'tab-\' + tabName);\n if (targetTab) {\n targetTab.classList.add(\'active\');\n }\n }\n\n // 生成报告\n async function generateReport() {\n const tracker = getTrackerInstance();\n if (!tracker) {\n alert(\'无法获取Tracker实例\');\n return;\n }\n\n try {\n const report = tracker.generatePerformanceReport({\n duration: 3600000 // 最近1小时\n });\n\n // 下载JSON报告\n const dataStr = JSON.stringify(report, null, 2);\n const dataBlob = new Blob([dataStr], { type: \'application/json\' });\n const url = URL.createObjectURL(dataBlob);\n const link = document.createElement(\'a\');\n link.href = url;\n link.download = `performance-report-${new Date().toISOString().split(\'T\')[0]}.json`;\n link.click();\n URL.revokeObjectURL(url);\n } catch (error) {\n console.error(\'生成报告失败:\', error);\n alert(\'生成报告失败: \' + (error instanceof Error ? error.message : String(error)));\n }\n }\n\n // 导出数据\n function exportData() {\n if (!metricsData) {\n alert(\'请先刷新数据\');\n return;\n }\n\n const data = {\n metrics: metricsData,\n alerts: alertsData,\n exportedAt: new Date().toISOString()\n };\n\n const dataStr = JSON.stringify(data, null, 2);\n const dataBlob = new Blob([dataStr], { type: \'application/json\' });\n const url = URL.createObjectURL(dataBlob);\n const link = document.createElement(\'a\');\n link.href = url;\n link.download = `performance-data-${new Date().toISOString().split(\'T\')[0]}.json`;\n link.click();\n URL.revokeObjectURL(url);\n }\n\n // 格式化文件大小\n function formatSize(bytes) {\n if (bytes === 0) return \'0 B\';\n const k = 1024;\n const sizes = [\'B\', \'KB\', \'MB\', \'GB\'];\n const i = Math.floor(Math.log(bytes) / Math.log(k));\n return Math.round(bytes / Math.pow(k, i) * 100) / 100 + \' \' + sizes[i];\n }\n\n // 页面加载时自动刷新\n window.addEventListener(\'load\', () => {\n setTimeout(refreshData, 500);\n \n // 每30秒自动刷新\n setInterval(refreshData, 30000);\n });\n <\/script>\n</body>\n</html>\n',Hr='\n<!DOCTYPE html>\n<html lang="zh-CN">\n<head>\n <meta charset="UTF-8">\n <meta name="viewport" content="width=device-width, initial-scale=1.0">\n <title>查看离线存储数据 - Tracker SDK</title>\n <style>\n * {\n margin: 0;\n padding: 0;\n box-sizing: border-box;\n }\n body {\n font-family: -apple-system, BlinkMacSystemFont, \'Segoe UI\', Roboto, \'Helvetica Neue\', Arial, sans-serif;\n background: #f5f5f5;\n padding: 20px;\n }\n .container {\n max-width: 1400px;\n margin: 0 auto;\n background: white;\n border-radius: 8px;\n box-shadow: 0 2px 8px rgba(0,0,0,0.1);\n padding: 30px;\n }\n h1 {\n color: #333;\n margin-bottom: 10px;\n border-bottom: 3px solid #4CAF50;\n padding-bottom: 10px;\n }\n .subtitle {\n color: #666;\n margin-bottom: 30px;\n }\n .toolbar {\n display: flex;\n gap: 10px;\n margin-bottom: 20px;\n flex-wrap: wrap;\n }\n button {\n background: #4CAF50;\n color: white;\n border: none;\n padding: 10px 20px;\n border-radius: 4px;\n cursor: pointer;\n font-size: 14px;\n transition: background 0.3s;\n }\n button:hover {\n background: #45a049;\n }\n button.danger {\n background: #f44336;\n }\n button.danger:hover {\n background: #da190b;\n }\n button.secondary {\n background: #2196F3;\n }\n button.secondary:hover {\n background: #1976D2;\n }\n .stats {\n display: grid;\n grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));\n gap: 15px;\n margin-bottom: 20px;\n }\n .stat-card {\n background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);\n color: white;\n padding: 20px;\n border-radius: 8px;\n box-shadow: 0 2px 4px rgba(0,0,0,0.1);\n }\n .stat-card.success {\n background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);\n }\n .stat-card.warning {\n background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);\n }\n .stat-card.info {\n background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);\n }\n .stat-label {\n font-size: 12px;\n opacity: 0.9;\n margin-bottom: 5px;\n }\n .stat-value {\n font-size: 32px;\n font-weight: bold;\n }\n .filters {\n background: #f9f9f9;\n padding: 15px;\n border-radius: 4px;\n margin-bottom: 20px;\n }\n .filters label {\n display: inline-block;\n margin-right: 15px;\n font-size: 14px;\n color: #666;\n }\n .filters select, .filters input {\n padding: 5px 10px;\n border: 1px solid #ddd;\n border-radius: 4px;\n margin-left: 5px;\n }\n .events-container {\n max-height: 600px;\n overflow-y: auto;\n border: 1px solid #ddd;\n border-radius: 4px;\n }\n .event-item {\n border-bottom: 1px solid #eee;\n padding: 15px;\n transition: background 0.2s;\n }\n .event-item:hover {\n background: #f9f9f9;\n }\n .event-item:last-child {\n border-bottom: none;\n }\n .event-header {\n display: flex;\n justify-content: space-between;\n align-items: center;\n margin-bottom: 10px;\n }\n .event-type {\n display: inline-block;\n padding: 4px 8px;\n border-radius: 4px;\n font-size: 12px;\n font-weight: bold;\n color: white;\n }\n .event-type.pageview { background: #4CAF50; }\n .event-type.click { background: #2196F3; }\n .event-type.exposure { background: #FF9800; }\n .event-type.error { background: #f44336; }\n .event-type.performance { background: #9C27B0; }\n .event-type.custom { background: #607D8B; }\n .event-time {\n color: #999;\n font-size: 12px;\n }\n .event-details {\n font-size: 13px;\n color: #666;\n margin-top: 8px;\n }\n .event-details pre {\n background: #f5f5f5;\n padding: 10px;\n border-radius: 4px;\n overflow-x: auto;\n font-size: 12px;\n margin-top: 5px;\n }\n .empty-state {\n text-align: center;\n padding: 60px 20px;\n color: #999;\n }\n .empty-state svg {\n width: 100px;\n height: 100px;\n margin-bottom: 20px;\n opacity: 0.3;\n }\n .loading {\n text-align: center;\n padding: 40px;\n color: #666;\n }\n .spinner {\n border: 3px solid #f3f3f3;\n border-top: 3px solid #4CAF50;\n border-radius: 50%;\n width: 40px;\n height: 40px;\n animation: spin 1s linear infinite;\n margin: 0 auto 20px;\n }\n @keyframes spin {\n 0% { transform: rotate(0deg); }\n 100% { transform: rotate(360deg); }\n }\n .json-viewer {\n background: #f5f5f5;\n padding: 10px;\n border-radius: 4px;\n font-family: \'Courier New\', monospace;\n font-size: 12px;\n max-height: 300px;\n overflow-y: auto;\n }\n </style>\n</head>\n<body>\n <div class="container">\n <h1>📦 离线存储数据查看器</h1>\n <p class="subtitle">查看 Tracker SDK 离线存储的所有事件数据</p>\n\n <div class="toolbar">\n <button onclick="loadEvents()">🔄 刷新数据</button>\n <button class="secondary" onclick="exportData()">📥 导出数据</button>\n <button class="danger" onclick="clearStorage()">🗑️ 清空存储</button>\n <button onclick="openDevTools()">🔧 打开开发者工具</button>\n </div>\n\n <div class="stats" id="stats">\n <div class="stat-card success">\n <div class="stat-label">总事件数</div>\n <div class="stat-value" id="total-count">-</div>\n </div>\n <div class="stat-card info">\n <div class="stat-label">存储大小</div>\n <div class="stat-value" id="storage-size">-</div>\n </div>\n <div class="stat-card warning">\n <div class="stat-label">事件类型分布</div>\n <div class="stat-value" id="type-distribution">-</div>\n </div>\n </div>\n\n <div class="filters">\n <label>\n 事件类型:\n <select id="filter-type" onchange="filterEvents()">\n <option value="">全部</option>\n <option value="pageview">页面浏览</option>\n <option value="click">点击</option>\n <option value="exposure">曝光</option>\n <option value="error">错误</option>\n <option value="performance">性能</option>\n <option value="custom">自定义</option>\n </select>\n </label>\n <label>\n 搜索:\n <input type="text" id="search-input" placeholder="搜索事件..." oninput="filterEvents()">\n </label>\n <label>\n 排序:\n <select id="sort-order" onchange="filterEvents()">\n <option value="desc">最新优先</option>\n <option value="asc">最旧优先</option>\n </select>\n </label>\n </div>\n\n <div class="events-container" id="events-container">\n <div class="loading">\n <div class="spinner"></div>\n <p>加载中...</p>\n </div>\n </div>\n </div>\n\n <script>\n // 标记这是SDK内部面板,不应被监控\n window.__trackerInternalPanel = true;\n \n let allEvents = [];\n let filteredEvents = [];\n\n // 从父窗口获取Tracker实例\n function getTrackerInstance() {\n if (window.opener && window.opener.__trackerInstance) {\n return window.opener.__trackerInstance;\n }\n // 尝试从全局变量获取\n if (window.__trackerInstance) {\n return window.__trackerInstance;\n }\n return null;\n }\n\n // 加载事件\n async function loadEvents() {\n const container = document.getElementById(\'events-container\');\n container.innerHTML = \'<div class="loading"><div class="spinner"></div><p>加载中...</p></div>\';\n\n try {\n const tracker = getTrackerInstance();\n if (tracker) {\n allEvents = await tracker.getOfflineEvents();\n } else {\n // 直接访问IndexedDB\n allEvents = await getEventsFromIndexedDB();\n }\n\n updateStats();\n filterEvents();\n } catch (error) {\n container.innerHTML = `<div class="empty-state"><p>加载失败: ${error.message}</p></div>`;\n console.error(\'加载事件失败:\', error);\n }\n }\n\n // 直接从IndexedDB获取事件\n async function getEventsFromIndexedDB() {\n return new Promise((resolve, reject) => {\n const request = indexedDB.open(\'__tracker_db__\', 1);\n \n request.onsuccess = (event) => {\n const db = event.target.result;\n if (!db.objectStoreNames.contains(\'__tracker_store__\')) {\n resolve([]);\n return;\n }\n const transaction = db.transaction([\'__tracker_store__\'], \'readonly\');\n const store = transaction.objectStore(\'__tracker_store__\');\n const index = store.index(\'key\');\n const getRequest = index.get(\'__tracker_offline_events__\');\n\n getRequest.onsuccess = () => {\n const result = getRequest.result;\n if (result && result.value) {\n try {\n const events = JSON.parse(result.value);\n resolve(events);\n } catch (e) {\n resolve([]);\n }\n } else {\n resolve([]);\n }\n };\n\n getRequest.onerror = () => {\n reject(new Error(\'获取数据失败\'));\n };\n };\n\n request.onerror = () => {\n reject(new Error(\'打开数据库失败\'));\n };\n });\n }\n\n // 更新统计信息\n function updateStats() {\n const totalCount = allEvents.length;\n document.getElementById(\'total-count\').textContent = totalCount;\n\n const size = new Blob([JSON.stringify(allEvents)]).size;\n const sizeKB = (size / 1024).toFixed(2);\n document.getElementById(\'storage-size\').textContent = sizeKB + \' KB\';\n\n const typeCount = {};\n allEvents.forEach(event => {\n typeCount[event.type] = (typeCount[event.type] || 0) + 1;\n });\n const typeStr = Object.entries(typeCount)\n .map(([type, count]) => `${type}: ${count}`)\n .join(\', \');\n document.getElementById(\'type-distribution\').textContent = typeStr || \'无\';\n }\n\n // 过滤事件\n function filterEvents() {\n const typeFilter = document.getElementById(\'filter-type\').value;\n const searchText = document.getElementById(\'search-input\').value.toLowerCase();\n const sortOrder = document.getElementById(\'sort-order\').value;\n\n filteredEvents = allEvents.filter(event => {\n const matchType = !typeFilter || event.type === typeFilter;\n const matchSearch = !searchText || \n JSON.stringify(event).toLowerCase().includes(searchText);\n return matchType && matchSearch;\n });\n\n filteredEvents.sort((a, b) => {\n return sortOrder === \'desc\' ? b.timestamp - a.timestamp : a.timestamp - b.timestamp;\n });\n\n renderEvents();\n }\n\n // 渲染事件列表\n function renderEvents() {\n const container = document.getElementById(\'events-container\');\n\n if (filteredEvents.length === 0) {\n container.innerHTML = `\n <div class="empty-state">\n <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">\n <path d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>\n </svg>\n <p>没有找到事件数据</p>\n <p style="margin-top: 10px; font-size: 12px;">请确保已经使用Tracker SDK收集了一些事件</p>\n </div>\n `;\n return;\n }\n\n const typeLabels = {\n pageview: \'页面浏览\',\n click: \'点击\',\n exposure: \'曝光\',\n error: \'错误\',\n performance: \'性能\',\n custom: \'自定义\'\n };\n\n container.innerHTML = filteredEvents.map((event) => {\n const date = new Date(event.timestamp);\n return `\n <div class="event-item">\n <div class="event-header">\n <div>\n <span class="event-type ${event.type}">${typeLabels[event.type] || event.type}</span>\n <span style="margin-left: 10px; font-weight: bold;">${event.name || event.eventName || \'-\'}</span>\n </div>\n <div class="event-time">${date.toLocaleString()}</div>\n </div>\n <div class="event-details">\n <div><strong>URL:</strong> ${event.url || \'-\'}</div>\n <div style="margin-top: 5px;"><strong>标题:</strong> ${event.title || \'-\'}</div>\n ${event.userId ? `<div style="margin-top: 5px;"><strong>用户ID:</strong> ${event.userId}</div>` : \'\'}\n ${event.properties ? `\n <div style="margin-top: 10px;">\n <strong>属性:</strong>\n <div class="json-viewer">${JSON.stringify(event.properties, null, 2)}</div>\n </div>\n ` : \'\'}\n ${event.errorType ? `<div style="margin-top: 5px;"><strong>错误类型:</strong> ${event.errorType}</div>` : \'\'}\n ${event.message ? `<div style="margin-top: 5px;"><strong>消息:</strong> ${event.message}</div>` : \'\'}\n <div style="margin-top: 10px; font-size: 11px; color: #999;">\n <details>\n <summary style="cursor: pointer;">查看完整数据</summary>\n <div class="json-viewer" style="margin-top: 10px;">${JSON.stringify(event, null, 2)}</div>\n </details>\n </div>\n </div>\n </div>\n `;\n }).join(\'\');\n }\n\n // 导出数据\n function exportData() {\n const dataStr = JSON.stringify(allEvents, null, 2);\n const dataBlob = new Blob([dataStr], { type: \'application/json\' });\n const url = URL.createObjectURL(dataBlob);\n const link = document.createElement(\'a\');\n link.href = url;\n link.download = `tracker-offline-events-${new Date().toISOString().split(\'T\')[0]}.json`;\n link.click();\n URL.revokeObjectURL(url);\n }\n\n // 清空存储\n async function clearStorage() {\n if (!confirm(\'确定要清空所有离线存储的数据吗?此操作不可恢复!\')) {\n return;\n }\n\n try {\n const tracker = getTrackerInstance();\n if (tracker) {\n await tracker.clearOfflineStorage();\n } else {\n const request = indexedDB.open(\'__tracker_db__\', 1);\n request.onsuccess = (event) => {\n const db = event.target.result;\n if (!db.objectStoreNames.contains(\'__tracker_store__\')) {\n alert(\'存储已清空(存储不存在)\');\n loadEvents();\n return;\n }\n const transaction = db.transaction([\'__tracker_store__\'], \'readwrite\');\n const store = transaction.objectStore(\'__tracker_store__\');\n const index = store.index(\'key\');\n const getRequest = index.get(\'__tracker_offline_events__\');\n getRequest.onsuccess = () => {\n if (getRequest.result) {\n store.delete(getRequest.result.id);\n }\n };\n };\n }\n alert(\'存储已清空\');\n loadEvents();\n } catch (error) {\n alert(\'清空失败: \' + error.message);\n console.error(\'清空存储失败:\', error);\n }\n }\n\n // 打开开发者工具\n function openDevTools() {\n alert(\'请在浏览器中按F12打开开发者工具,然后:\\n\\n1. 打开 Application 标签\\n2. 选择 IndexedDB\\n3. 找到 TrackerStorage 数据库\\n4. 查看 keyValueStore 中的数据\');\n }\n\n // 页面加载时自动加载数据\n window.addEventListener(\'load\', () => {\n setTimeout(loadEvents, 500);\n });\n <\/script>\n</body>\n</html>\n';class Fr{setTrackerInstance(e){"undefined"!=typeof window&&(window.__trackerInstance=e)}openPerformancePanel(){if("undefined"!=typeof window)try{const e=window.open("about:blank","_blank","width=1400,height=900,resizable=yes,scrollbars=yes");if(!e)return void alert("无法打开性能监控面板,请检查浏览器弹窗设置");e.document.write(Nr),e.document.close(),e.document.title="性能监控面板 - Tracker SDK"}catch(e){console.error("PanelManager: Failed to open performance panel:",e),alert("打开性能监控面板失败: "+(e instanceof Error?e.message:String(e)))}else console.warn("PanelManager: Cannot open panel in non-browser environment")}openOfflineStorageViewer(){if("undefined"!=typeof window)try{const e=window.open("about:blank","_blank","width=1400,height=900,resizable=yes,scrollbars=yes");if(!e)return void alert("无法打开离线存储查看器,请检查浏览器弹窗设置");e.document.write(Hr),e.document.close(),e.document.title="离线存储数据查看器 - Tracker SDK"}catch(e){console.error("PanelManager: Failed to open offline storage viewer:",e),alert("打开离线存储查看器失败: "+(e instanceof Error?e.message:String(e)))}else console.warn("PanelManager: Cannot open panel in non-browser environment")}getPerformancePanelHTML(){return Nr}getOfflineStorageViewerHTML(){return Hr}}class $r{enrich(e,t){var n;const r=e.userId||(null==(n=t.userInfo)?void 0:n.userId)||t.configUserId,s={...t.customProperties||{},...e.properties||{}},i=Object.keys(s).length>0?s:void 0,a={...e,deviceId:e.deviceId||t.deviceId,sessionId:e.sessionId||t.sessionId};return r&&""!==r&&(a.userId=r),i&&(a.properties=i),a}}const jr=["pageview","click","exposure","input","error","performance"];class qr{constructor(e){n(this,"handlers",[]),this.send=e}setup(){this.handlers.length>0||jr.forEach(e=>{const t=e=>{this.send(e)};E.on(e,t),this.handlers.push({event:e,handler:t})})}teardown(){this.handlers.forEach(({event:e,handler:t})=>{E.off(e,t)}),this.handlers=[]}attachToWindow(){"undefined"!=typeof window&&(window.__trackerEventBus={emit:(e,t)=>{E.emit(e,t)}})}}class Vr{constructor(e,t){this.configStore=e,this.batchSender=t}apply(e){this.configStore.update(e),void 0!==e.serverUrl&&this.batchSender.setServerUrl(e.serverUrl||""),void 0!==e.maxRetries&&this.batchSender.setMaxRetries(e.maxRetries),void 0===e.batchSize&&void 0===e.batchWait||this.batchSender.setBatchOptions({batchSize:this.configStore.get("batchSize")??10,batchWait:this.configStore.get("batchWait")??5e3})}}class Zr{constructor(){n(this,"startTime",Date.now()),n(this,"currentUrl",""),n(this,"popstateHandler",null),n(this,"visibilityChangeHandler",null),n(this,"beforeUnloadHandler",null),n(this,"isTracking",!1),n(this,"pendingUrlCheck",null),n(this,"lastPageViewTime",0),n(this,"minPageViewInterval",1e3),n(this,"hiddenStartTime",null),n(this,"totalHiddenTime",0),n(this,"isVisible",!0)}init(){this.trackPageView(),this.setupSPARouter(),this.setupPageLifecycle()}trackPageView(){if(D())return{type:"pageview",name:"pageview",timestamp:Date.now(),url:z(),title:M()};if(this.isTracking)return{type:"pageview",name:"pageview",timestamp:Date.now(),url:this.currentUrl||z(),title:M()};this.isTracking=!0;try{const e=Date.now(),t=z(),n=M(),r="undefined"==typeof window?"":document.referrer||"",s=t!==this.currentUrl||""===this.currentUrl;if(!s&&this.lastPageViewTime>0){if(e-this.lastPageViewTime<this.minPageViewInterval)return{type:"pageview",name:"pageview",timestamp:e,url:this.currentUrl,title:n}}const i=this.currentUrl?e-this.startTime-this.totalHiddenTime:0,a=i>0?i:0,o={type:"pageview",name:"pageview",timestamp:e,url:t,title:n,referrer:this.currentUrl?r:void 0,duration:a>0?a:void 0};return s&&(this.startTime=e,this.currentUrl=t,this.totalHiddenTime=0),this.lastPageViewTime=e,"undefined"!=typeof window&&window.__trackerEventBus&&window.__trackerEventBus.emit("pageview",o),o}finally{setTimeout(()=>{this.isTracking=!1},0)}}setupSPARouter(){if("undefined"==typeof window)return;this.popstateHandler=()=>{this.trackPageView()},window.addEventListener("popstate",this.popstateHandler);const e=history;if(!e._trackerPushStateWrapped){const t=history.pushState.bind(history);e._originalPushState=t,e._trackerPushStateWrapped=!0,history.pushState=(...e)=>{const n=t.apply(history,e);return this.pendingUrlCheck&&clearTimeout(this.pendingUrlCheck),this.pendingUrlCheck=setTimeout(()=>{z()!==this.currentUrl&&this.trackPageView(),this.pendingUrlCheck=null},100),n}}if(!e._trackerReplaceStateWrapped){const t=history.replaceState.bind(history);e._originalReplaceState=t,e._trackerReplaceStateWrapped=!0,history.replaceState=(...e)=>{const n=t.apply(history,e);return this.pendingUrlCheck&&clearTimeout(this.pendingUrlCheck),this.pendingUrlCheck=setTimeout(()=>{z()!==this.currentUrl&&this.trackPageView(),this.pendingUrlCheck=null},100),n}}}setupPageLifecycle(){"undefined"!=typeof document&&(this.visibilityChangeHandler=()=>{const e=document.hidden,t=Date.now();e&&this.isVisible?(this.hiddenStartTime=t,this.isVisible=!1):e||this.isVisible||(this.hiddenStartTime&&(this.totalHiddenTime+=t-this.hiddenStartTime,this.hiddenStartTime=null),this.isVisible=!0)},document.addEventListener("visibilitychange",this.visibilityChangeHandler),this.beforeUnloadHandler=()=>{const e=Date.now();this.hiddenStartTime&&(this.totalHiddenTime+=e-this.hiddenStartTime,this.hiddenStartTime=null);const t=this.currentUrl?e-this.startTime-this.totalHiddenTime:0;if(t>0&&this.currentUrl)try{const n={type:"pageview",name:"page-before-unload",timestamp:e,url:this.currentUrl,title:M(),duration:t};"undefined"!=typeof window&&window.__trackerEventBus&&window.__trackerEventBus.emit("pageview",n)}catch(n){console.error("ViewTracker: Error sending final pageview event:",n)}},window.addEventListener("beforeunload",this.beforeUnloadHandler))}destroy(){if(this.pendingUrlCheck&&(clearTimeout(this.pendingUrlCheck),this.pendingUrlCheck=null),this.popstateHandler&&"undefined"!=typeof window&&(window.removeEventListener("popstate",this.popstateHandler),this.popstateHandler=null),this.visibilityChangeHandler&&"undefined"!=typeof document&&(document.removeEventListener("visibilitychange",this.visibilityChangeHandler),this.visibilityChangeHandler=null),this.beforeUnloadHandler&&"undefined"!=typeof window&&(window.removeEventListener("beforeunload",this.beforeUnloadHandler),this.beforeUnloadHandler=null),"undefined"!=typeof window){const e=history;e._trackerPushStateWrapped&&e._originalPushState&&(history.pushState=e._originalPushState,e._trackerPushStateWrapped=!1,delete e._originalPushState),e._trackerReplaceStateWrapped&&e._originalReplaceState&&(history.replaceState=e._originalReplaceState,e._trackerReplaceStateWrapped=!1,delete e._originalReplaceState)}}}function Kr(e,t={}){var n;if(!e||"undefined"==typeof window)return;const{extractProps:l=!0,extractAttrs:h=!0,extractValue:u=!0,extractLabel:p=!0}=t,f=d(e),m=r(e),g=f||s(m);if(!g&&!m)return;const v={};if(g&&(v.componentName=g),l&&m){const e=i(m);e&&(v.props=c(e),"type"in e&&(v.componentType=String(e.type)),"disabled"in e&&(v.disabled=Boolean(e.disabled)),"label"in e&&p&&(v.label=String(e.label)))}if(h&&m){const e=a(m);e&&(v.attrs=c(e),!v.componentType&&"type"in e&&(v.componentType=String(e.type)),void 0===v.disabled&&"disabled"in e&&(v.disabled=Boolean(e.disabled)))}if(u&&m){const e=o(m);if(null!=e){const t=i(m);if(t&&("type"in t&&"password"===String(t.type).toLowerCase()||"password"in t||"n-input"===g&&"type"in t&&"password"===String(t.type).toLowerCase())){const t="string"==typeof e?e.length:void 0;v.value=void 0!==t?`[password:${t} chars]`:`[${typeof e}]`}else"object"==typeof e?Array.isArray(e)?(v.value=`[Array(${e.length})]`,"n-select"!==g&&"n-cascader"!==g||(v.options={count:e.length,multiple:!(!t||!("multiple"in t))&&Boolean(t.multiple)})):v.value="[Object]":v.value=e}}if(p&&!v.label){const t=null==(n=e.textContent)?void 0:n.trim();t&&t.length>0&&t.length<100&&(v.label=t.substring(0,100))}if(("n-select"===g||"n-cascader"===g)&&m){const e=i(m);e&&"options"in e&&Array.isArray(e.options)&&(v.options={count:e.options.length,multiple:!(!e||!("multiple"in e))&&Boolean(e.multiple)})}return Object.keys(v).length>0?v:void 0}function Wr(e){if(!e)return!1;const t=d(e);return void 0!==t&&t.startsWith("n-")}const Jr={"n-button":["default","primary","success","info","warning","error","tertiary","quaternary"],"n-input":["text","password","textarea","number","email","tel","url"],"n-select":["default","multiple","tags","filterable"],"n-checkbox":["default","indeterminate"],"n-radio":["default","button"],"n-switch":["default"],"n-date-picker":["date","datetime","daterange","datetimerange"],"n-time-picker":["time","timerange"],"n-cascader":["default","multiple","filterable"],"n-transfer":["default"],"n-tree-select":["default","multiple","filterable"],"n-form":["default","inline"],"n-form-item":["default"],"n-table":["default","bordered","striped"],"n-pagination":["default"],"n-menu":["default","horizontal","vertical"],"n-tabs":["default","card","bar"],"n-drawer":["default"],"n-modal":["default"],"n-message":["default","success","info","warning","error"],"n-notification":["default","success","info","warning","error"],"n-popover":["default"],"n-tooltip":["default"],"n-dropdown":["default"],"n-breadcrumb":["default"],"n-steps":["default","vertical"],"n-timeline":["default"],"n-card":["default","bordered","hoverable"],"n-collapse":["default","accordion"],"n-divider":["default","horizontal","vertical"],"n-space":["default","vertical"],"n-grid":["default"],"n-layout":["default"],"n-back-top":["default"],"n-anchor":["default"],"n-affix":["default"],"n-watermark":["default"],"n-spin":["default"],"n-skeleton":["default"],"n-progress":["default","line","circle","dashboard"],"n-rate":["default"],"n-slider":["default","range"],"n-color-picker":["default"],"n-image":["default"],"n-avatar":["default","circle","square"],"n-badge":["default"],"n-tag":["default","success","info","warning","error"],"n-empty":["default"],"n-result":["default","success","info","warning","error","404","500"],"n-descriptions":["default","bordered"],"n-statistic":["default"],"n-list":["default","bordered"],"n-list-item":["default"],"n-carousel":["default","dot","arrow"],"n-calendar":["default"]};function Xr(e,t={}){if(!e)return;if(!Wr(e))return;const n=Kr(e,{extractProps:t.extractProps,extractAttrs:t.extractAttrs,extractValue:t.extractValue,extractLabel:t.extractLabel});if(!n)return;const r=n.componentName;if(!r||!r.startsWith("n-"))return n;switch(r){case"n-button":!function(e,t){var n;if(!t.label){const r=null==(n=e.textContent)?void 0:n.trim();r&&(t.label=r.substring(0,50))}const r=e.querySelector('.n-button__icon, [class*="icon"]');r&&(t.hasIcon=!0);(e.classList.contains("n-button--disabled")||e.hasAttribute("disabled"))&&(t.disabled=!0);e.classList.contains("n-button--loading")&&(t.loading=!0)}(e,n);break;case"n-input":!function(e,t){var n;const r=e.querySelector("input, textarea");if(r){if(!(null==(n=t.attrs)?void 0:n.placeholder)&&r.placeholder&&(t.attrs||(t.attrs={}),t.attrs.placeholder=r.placeholder),"input"===r.tagName.toLowerCase()){const e=r.type||"text";t.componentType||(t.componentType=e),"password"===e&&(t.isSensitive=!0,t.value&&"string"==typeof t.value&&(t.value.startsWith("[password:")||(t.value=`[password:${t.value.length} chars]`)))}const e=r.value;if(e){"password"===r.type||t.props&&"type"in t.props&&"password"===String(t.props.type).toLowerCase()?(t.value=`[password:${e.length} chars]`,t.isSensitive=!0):t.value=e.length>100?e.substring(0,100)+"...":e}else t.value}}(e,n);break;case"n-select":case"n-cascader":case"n-tree-select":!function(e,t){var n;const r=e.querySelector(".n-base-selection, .n-base-selection-label");if(r){const e=null==(n=r.textContent)?void 0:n.trim();e&&!t.label&&(t.label=e.substring(0,100))}e.classList.contains("n-base-selection--multiple")&&(t.options||(t.options={}),t.options.multiple=!0);e.querySelector(".n-base-selection-input")&&(t.filterable=!0)}(e,n);break;case"n-checkbox":case"n-radio":!function(e,t){var n;const r=e.querySelector('input[type="checkbox"], input[type="radio"]');if(r){t.checked=r.checked;const s=e.querySelector("label, .n-checkbox__label, .n-radio__label");if(s){const e=null==(n=s.textContent)?void 0:n.trim();e&&!t.label&&(t.label=e.substring(0,100))}r.value&&(t.value=r.value)}}(e,n);break;case"n-switch":!function(e,t){const n=e.querySelector('input[type="checkbox"]');n&&(t.checked=n.checked,t.value=n.checked)}(e,n);break;case"n-form":case"n-form-item":!function(e,t){var n;const r=e.querySelector(".n-form-item-label, label");if(r){const e=null==(n=r.textContent)?void 0:n.trim();e&&!t.label&&(t.label=e.substring(0,100))}const s=e.querySelector('.n-form-item-label__asterisk, [class*="required"]');s&&(t.required=!0)}(e,n)}return n}function Gr(e){if(!e)return;const t=e.getAttribute("data-track-name")||e.getAttribute("data-track-component");if(!t)return;const n={componentName:t},r=e.getAttribute("data-track-props");if(r&&r.length<=8192)try{const e=JSON.parse(r);e&&"object"==typeof e&&(n.props=e)}catch{}return n}function Qr(e,t){const n=e.getAttribute("class");return!!n&&n.split(/\s+/).some(e=>e===t||e.startsWith(`${t}-`))}function Yr(e){if(e)return function(e){let t;return function(e,t,n){let r=e,s=0;for(;null!=r&&s<=t;){if(!1===n(r,s))return;r=r.parentElement,s++}}(e,8,e=>Qr(e,"ant-btn")?(t={componentName:"AntButton"},!1):Qr(e,"ant-input")||Qr(e,"ant-input-affix-wrapper")||Qr(e,"ant-input-group-wrapper")?(t={componentName:"AntInput"},!1):void 0),t}(e)}function es(e){return t=>{const n=e.frameAdapters?(r=e.frameAdapters,[...r].sort((e,t)=>(t.priority??0)-(e.priority??0))):[];var r;for(const e of n)try{const n=e.resolveComponentInfo(t);if(n)return n}catch{}}}function ts(e){const t={extractProps:e.extractComponentProps??!0,extractValue:e.extractComponentValue??!0};return n=>{const r=f(n.target);if(r)try{if(e.enableNaiveUITracking){const e=Xr(r,t);if(e)return e}if(e.enableVueTracking){const e=Kr(r,t);if(e)return e}}catch{return}}}function ns(e){return Gr(f(e.target))}function rs(e){return Yr(f(e.target))??void 0}function ss(e,t,n){if(!e)return;const r=n();return function(e,t){for(const n of t){const t=n(e);if(t)return t}}({target:e,event:t,trackerConfig:r},[es(r),ts(r),ns,rs])}class is{constructor(e={}){this.options=e}create(e){const t={type:"click",name:e.eventName,timestamp:e.timestamp,url:z(),title:M(),elementPath:O(e.element),elementInfo:N(e.element),position:e.position,interactionType:e.interactionType},n=this.options.getConfig;if(n)try{const r=ss(e.element,e.nativeEvent,n);r&&(t.componentInfo=r)}catch(r){console.warn("ClickTracker: Error extracting component info:",r)}return t}}class as{dispatch(e){const t="undefined"!=typeof window?window.__trackerEventBus??null:null;t&&t.emit("click",e)}schedule(e,t){"undefined"!=typeof requestIdleCallback?requestIdleCallback(e,{timeout:t}):setTimeout(e,0)}}class os{constructor(e=300,t=10){n(this,"lastTouch",null),this.clickThresholdMs=e,this.distanceThresholdPx=t}recordTouchStart(e,t){this.lastTouch={x:e.clientX,y:e.clientY,time:t}}resolveTouchEnd(e,t){if(!this.lastTouch)return{isTap:!1};const n=Math.abs(e.clientX-this.lastTouch.x),r=Math.abs(e.clientY-this.lastTouch.y),s=t-this.lastTouch.time;return this.lastTouch=null,s<this.clickThresholdMs&&n<this.distanceThresholdPx&&r<this.distanceThresholdPx?{isTap:!0,position:{x:e.clientX,y:e.clientY}}:{isTap:!1}}reset(){this.lastTouch=null}}class ls{constructor(){n(this,"clickHandler",null),n(this,"touchStartHandler",null),n(this,"touchEndHandler",null),n(this,"debounceTime",300),n(this,"touchTimeout",null),n(this,"configGetter",null),n(this,"eventFactory",new is),n(this,"eventDispatcher",new as),n(this,"touchInteractionTracker",new os)}init(e,t){"undefined"!=typeof window&&(void 0!==e&&(this.debounceTime=e),t&&(this.configGetter=t.getConfig??null),this.eventFactory=new is({getConfig:this.configGetter}),this.clickHandler=B((...e)=>{const t=e[0];this.handleClick(t)},this.debounceTime),this.touchStartHandler=e=>{this.handleTouch(e)},this.touchEndHandler=B((...e)=>{const t=e[0];this.handleTouch(t)},this.debounceTime),document.addEventListener("click",this.clickHandler,!1),document.addEventListener("touchstart",this.touchStartHandler,{passive:!0,capture:!1}),document.addEventListener("touchend",this.touchEndHandler,{passive:!0,capture:!1}))}handleTouch(e){try{const t=Date.now();switch(e.type){case"touchstart":e.touches.length>0&&this.touchInteractionTracker.recordTouchStart(e.touches[0],t);break;case"touchend":if(e.changedTouches.length>0){const n=e.changedTouches[0];this.touchInteractionTracker.resolveTouchEnd(n,t).isTap&&(this.touchTimeout&&clearTimeout(this.touchTimeout),this.touchTimeout=window.setTimeout(()=>{try{this.processTouchInteraction(n,e.target)}catch(t){console.error("ClickTracker: Error processing touch interaction:",t)}this.touchTimeout=null},100))}}}catch(t){console.error("ClickTracker: Error handling touch event:",t)}}processTouchInteraction(e,t){if(D())return;if(!t)return;const n=Date.now();this.eventDispatcher.schedule(()=>{try{const r=this.eventFactory.create({element:t,timestamp:n,position:{x:e.clientX,y:e.clientY},interactionType:"touch",eventName:"touch-click"});this.eventDispatcher.dispatch(r)}catch(r){console.error("ClickTracker: Error processing touch interaction:",r)}},50)}handleClick(e){if(!D())try{const t=e.target;if(!t)return;const n=Date.now(),r=()=>{try{const r=this.eventFactory.create({element:t,timestamp:n,position:{x:e.clientX,y:e.clientY},interactionType:"mouse",eventName:"click",nativeEvent:e});this.eventDispatcher.dispatch(r)}catch(r){console.error("ClickTracker: Error processing click event:",r)}};this.eventDispatcher.schedule(r,100)}catch(t){console.error("ClickTracker: Error handling click event:",t)}}getClickEvent(e){try{const t=e.target;return t?this.eventFactory.create({element:t,timestamp:Date.now(),position:{x:e.clientX,y:e.clientY},interactionType:"mouse",eventName:"click",nativeEvent:e}):null}catch(t){return console.error("ClickTracker: Error creating click event:",t),null}}destroy(){this.clickHandler&&"undefined"!=typeof document&&(document.removeEventListener("click",this.clickHandler,!1),this.clickHandler=null),this.touchStartHandler&&"undefined"!=typeof document&&(document.removeEventListener("touchstart",this.touchStartHandler),this.touchStartHandler=null),this.touchEndHandler&&"undefined"!=typeof document&&(document.removeEventListener("touchend",this.touchEndHandler),this.touchEndHandler=null),this.touchTimeout&&(clearTimeout(this.touchTimeout),this.touchTimeout=null),this.touchInteractionTracker.reset()}}class cs{constructor(e={}){n(this,"observer",null),n(this,"exposedElements",new Set),n(this,"options"),n(this,"exposureMap",new Map),n(this,"scrollFallbackHandler",null),n(this,"resizeFallbackHandler",null),n(this,"cachedElements",[]),n(this,"lastCacheUpdate",0),n(this,"CACHE_UPDATE_INTERVAL",2e3),this.options={threshold:.5,root:null,rootMargin:"0px",...e}}init(){"undefined"!=typeof window&&yr()?(this.observer=new IntersectionObserver(A((...e)=>{e[0].forEach(e=>{this.handleIntersection(e)})},100),{threshold:this.options.threshold||.5,root:this.options.root,rootMargin:this.options.rootMargin}),this.observeElements()):this.initScrollFallback()}observeElements(){if(!this.observer||"undefined"==typeof document)return;const e=document.querySelectorAll("[data-track-exposure]");e.forEach(e=>{this.observer.observe(e)}),this.cachedElements=Array.from(e),this.lastCacheUpdate=Date.now()}observe(e){this.observer&&(this.observer.observe(e),this.cachedElements.includes(e)||(this.cachedElements.push(e),this.lastCacheUpdate=Date.now()))}unobserve(e){if(!this.observer)return;this.observer.unobserve(e),this.exposedElements.delete(e),this.exposureMap.delete(e);const t=this.cachedElements.indexOf(e);t>-1&&(this.cachedElements.splice(t,1),this.lastCacheUpdate=Date.now())}handleIntersection(e){if(D())return;const{target:t,intersectionRatio:n,isIntersecting:r}=e;if(r&&n>=(this.options.threshold||.5))this.exposedElements.has(t)||(this.exposedElements.add(t),this.triggerExposure(t)),this.exposureMap.set(t,Date.now());else if(!r){const e=this.exposureMap.get(t);if(e){const n=Date.now()-e;this.triggerExposure(t,n),this.exposureMap.delete(t),this.exposedElements.delete(t)}}}triggerExposure(e,t){try{const n={type:"exposure",name:"exposure",timestamp:Date.now(),url:z(),title:M(),elementPath:O(e),duration:t};"undefined"!=typeof window&&window.__trackerEventBus&&window.__trackerEventBus.emit("exposure",n)}catch(n){console.error("ExposureTracker: Error triggering exposure event:",n)}}getExposureElements(){const e=Date.now();return(0===this.cachedElements.length||e-this.lastCacheUpdate>this.CACHE_UPDATE_INTERVAL)&&"undefined"!=typeof document&&(this.cachedElements=Array.from(document.querySelectorAll("[data-track-exposure]")),this.lastCacheUpdate=e),this.cachedElements}initScrollFallback(){if("undefined"==typeof window)return;this.cachedElements=Array.from(document.querySelectorAll("[data-track-exposure]")),this.lastCacheUpdate=Date.now();const e=A(()=>{const e=this.getExposureElements(),t=Date.now();e.forEach(e=>{const n=e.getBoundingClientRect(),r=window.innerHeight||document.documentElement.clientHeight,s=window.innerWidth||document.documentElement.clientWidth,i=(Math.min(n.bottom,r)-Math.max(n.top,0))*(Math.min(n.right,s)-Math.max(n.left,0)),a=n.height*n.width;if((a>0?i/a:0)>=(this.options.threshold||.5))this.exposedElements.has(e)||(this.exposedElements.add(e),this.exposureMap.set(e,t),this.triggerExposure(e));else if(this.exposedElements.has(e)){const n=this.exposureMap.get(e);if(n){const r=t-n;this.triggerExposure(e,r),this.exposureMap.delete(e),this.exposedElements.delete(e)}}})},100);this.scrollFallbackHandler=e,this.resizeFallbackHandler=e,window.addEventListener("scroll",this.scrollFallbackHandler,{passive:!0}),window.addEventListener("resize",this.resizeFallbackHandler,{passive:!0}),setTimeout(e,0)}destroy(){this.observer&&(this.observer.disconnect(),this.observer=null),this.scrollFallbackHandler&&"undefined"!=typeof window&&(window.removeEventListener("scroll",this.scrollFallbackHandler),this.scrollFallbackHandler=null),this.resizeFallbackHandler&&"undefined"!=typeof window&&(window.removeEventListener("resize",this.resizeFallbackHandler),this.resizeFallbackHandler=null),this.exposedElements.clear(),this.exposureMap.clear(),this.cachedElements=[],this.lastCacheUpdate=0}}class ds{constructor(){n(this,"inputHandler",null),n(this,"changeHandler",null),n(this,"inputDebounceTime",500),n(this,"selectDebounceTime",300),n(this,"skipEmptyInput",!0),n(this,"sensitiveKeywords",["password","pwd","secret","token","key","auth","credential"]),n(this,"configGetter",null)}init(e,t,n){"undefined"!=typeof window&&(void 0!==e&&(this.inputDebounceTime=e,this.selectDebounceTime=Math.min(e,300)),void 0!==t&&(this.skipEmptyInput=t),n&&(this.configGetter=n.getConfig??null),this.inputHandler=B((...e)=>{const t=e[0];this.handleInput(t)},this.inputDebounceTime),this.changeHandler=B((...e)=>{const t=e[0];this.handleChange(t)},this.selectDebounceTime),document.addEventListener("input",this.inputHandler,!1),document.addEventListener("change",this.changeHandler,!1))}mergeComponentValueIntoInput(e,t,n){e.componentInfo=t,void 0===t.value||n||("string"==typeof t.value?t.value.startsWith("[password:")||t.value.startsWith("[FILTERED]")||(e.value=t.value):"number"!=typeof t.value&&"boolean"!=typeof t.value||(e.value=String(t.value)))}handleInput(e){var t;if(D())return;const n=e.target;if(!n)return;const r=null==(t=n.tagName)?void 0:t.toLowerCase();if("input"!==r&&"textarea"!==r)return;const s=z(),i=M(),a=Date.now(),o=()=>{var t;try{const l=O(n),c={...N(n),name:n.name||void 0,type:n.type||void 0,placeholder:n.placeholder||void 0},d=this.isSensitiveField(n);let h,u,p="text";if("textarea"===r)p="textarea";else if("input"===r){const e=(null==(t=n.type)?void 0:t.toLowerCase())||"text";p="checkbox"===e?"checkbox":"radio"===e?"radio":"text"}if(d?(u=n.value.length,h=void 0):(h=n.value,u=n.value.length),this.skipEmptyInput&&0===u)return;const f={type:"input",name:"input",timestamp:a,url:s,title:i,elementPath:l,elementInfo:c,inputType:p,value:h,valueLength:u,isSensitive:d};if(this.configGetter)try{const t=ss(n,e,this.configGetter);t&&this.mergeComponentValueIntoInput(f,t,d)}catch(o){console.warn("InputTracker: Error extracting component info:",o)}"undefined"!=typeof window&&window.__trackerEventBus&&window.__trackerEventBus.emit("input",f)}catch(l){console.error("InputTracker: Error processing input event:",l)}};"undefined"!=typeof requestIdleCallback?requestIdleCallback(o,{timeout:100}):setTimeout(o,0)}handleChange(e){var t;if(D())return;const n=e.target;if(!n)return;if("select"!==(null==(t=n.tagName)?void 0:t.toLowerCase()))return;const r=z(),s=M(),i=Date.now(),a=()=>{try{const a=O(n),o={...N(n),name:n.name||void 0},l=this.isSensitiveField(n),c=n;let d,h;if(l?(h=c.value.length,d=void 0):(d=c.value,h=c.value.length),this.skipEmptyInput&&0===h)return;const u={type:"input",name:"input",timestamp:i,url:r,title:s,elementPath:a,elementInfo:o,inputType:"select",value:d,valueLength:h,isSensitive:l};if(this.configGetter)try{const t=ss(n,e,this.configGetter);t&&this.mergeComponentValueIntoInput(u,t,l)}catch(t){console.warn("InputTracker: Error extracting component info:",t)}"undefined"!=typeof window&&window.__trackerEventBus&&window.__trackerEventBus.emit("input",u)}catch(a){console.error("InputTracker: Error processing change event:",a)}};"undefined"!=typeof requestIdleCallback?requestIdleCallback(a,{timeout:100}):setTimeout(a,0)}isSensitiveField(e){var t,n,r;if(e instanceof HTMLInputElement){if("password"===(null==(t=e.type)?void 0:t.toLowerCase()))return!0}const s=(null==(n=e.name)?void 0:n.toLowerCase())||"";if(s)for(const o of this.sensitiveKeywords)if(s.includes(o))return!0;const i=(null==(r=e.id)?void 0:r.toLowerCase())||"";if(i)for(const o of this.sensitiveKeywords)if(i.includes(o))return!0;const a=U(e.className).toLowerCase();if(a)for(const o of this.sensitiveKeywords)if(a.includes(o))return!0;return!1}destroy(){this.inputHandler&&"undefined"!=typeof document&&(document.removeEventListener("input",this.inputHandler,!1),this.inputHandler=null),this.changeHandler&&"undefined"!=typeof document&&(document.removeEventListener("change",this.changeHandler,!1),this.changeHandler=null)}}class hs{constructor(){n(this,"viewTracker"),n(this,"clickTracker"),n(this,"exposureTracker"),n(this,"inputTracker"),n(this,"enabled",!1),this.viewTracker=new Zr,this.clickTracker=new ls,this.exposureTracker=new cs,this.inputTracker=new ds}init(e){if(this.enabled)return;const{enableClick:t=!0,enableExposure:n=!0,enableInput:r=!0,clickDebounceTime:s,inputDebounceTime:i,enableVueTracking:a=!1,enableNaiveUITracking:o=!1,extractComponentProps:l=!0,extractComponentValue:c=!0,getConfig:d}=e||{};this.viewTracker.init(),t&&this.clickTracker.init(s,{enableVueTracking:a,enableNaiveUITracking:o,extractComponentProps:l,extractComponentValue:c,getConfig:d}),n&&this.exposureTracker.init(),r&&this.inputTracker.init(i,void 0,{enableVueTracking:a,enableNaiveUITracking:o,extractComponentProps:l,extractComponentValue:c,getConfig:d}),this.enabled=!0}getViewTracker(){return this.viewTracker}getClickTracker(){return this.clickTracker}getExposureTracker(){return this.exposureTracker}getInputTracker(){return this.inputTracker}destroy(){this.enabled&&(this.viewTracker.destroy(),this.clickTracker.destroy(),this.exposureTracker.destroy(),this.inputTracker.destroy(),this.enabled=!1)}}class us{constructor(){n(this,"handlers",[]),n(this,"errorCache",new Map),n(this,"debounceTime",500)}init(){if("undefined"==typeof window)return;const e=e=>{e instanceof ErrorEvent?this.handleJSError(e):this.handleResourceError(e)};window.addEventListener("error",e,!0),this.handlers.push(()=>{window.removeEventListener("error",e,!0)});const t=e=>{this.handlePromiseError(e)};window.addEventListener("unhandledrejection",t),this.handlers.push(()=>{window.removeEventListener("unhandledrejection",t)})}handleJSError(e){var t;try{const n={type:"error",name:"js-error",timestamp:Date.now(),url:e.filename||z(),title:M(),errorType:"js",message:e.message||"Unknown error",stack:null==(t=e.error)?void 0:t.stack,filename:e.filename,lineno:e.lineno,colno:e.colno};this.emitError(n)}catch(n){console.error("ErrorTracker: Error handling JS error:",n)}}handlePromiseError(e){if(!D())try{const t=e.reason;let n,r="Unhandled promise rejection";t instanceof Error?(r=t.message,n=t.stack):r="string"==typeof t?t:JSON.stringify(t);const s={type:"error",name:"promise-error",timestamp:Date.now(),url:z(),title:M(),errorType:"promise",message:r,stack:n};this.emitError(s)}catch(t){console.error("ErrorTracker: Error handling promise error:",t)}}handleResourceError(e){var t;if(!D())try{const n=e.target;if(!n)return;const r=null==(t=n.tagName)?void 0:t.toLowerCase();if(!["img","script","link","audio","video"].includes(r))return;let s="";if(n instanceof HTMLImageElement||n instanceof HTMLScriptElement?s=n.src||"":n instanceof HTMLLinkElement?s=n.href||"":(n instanceof HTMLAudioElement||n instanceof HTMLVideoElement)&&(s=n.src||""),!s)return;const i={type:"error",name:"resource-error",timestamp:Date.now(),url:z(),title:M(),errorType:"resource",message:`Failed to load resource: ${s}`,resourceUrl:s,resourceType:r};this.emitError(i)}catch(n){console.error("ErrorTracker: Error handling resource error:",n)}}getErrorKey(e){const t=[e.errorType,e.message];return"js"!==e.errorType&&"promise"!==e.errorType||(e.filename&&t.push(e.filename),e.lineno&&t.push(String(e.lineno)),e.colno&&t.push(String(e.colno))),"resource"===e.errorType&&e.resourceUrl&&t.push(e.resourceUrl),t.join("|")}emitError(e){const t=this.getErrorKey(e),n=this.errorCache.get(t),r=Date.now();n&&r-n<this.debounceTime||(this.errorCache.set(t,r),this.cleanExpiredErrorCache(r),"undefined"!=typeof window&&window.__trackerEventBus&&window.__trackerEventBus.emit("error",e))}cleanExpiredErrorCache(e){for(const[t,n]of this.errorCache.entries())e-n>3e5&&this.errorCache.delete(t)}trackError(e,t){try{let n,r;e instanceof Error?(n=e.message,r=e.stack):n=e;const s={type:"error",name:"custom-error",timestamp:Date.now(),url:z(),title:M(),errorType:"js",message:n,stack:r,properties:t};this.emitError(s)}catch(n){console.error("ErrorTracker: Error tracking custom error:",n)}}destroy(){this.handlers.forEach(e=>e()),this.handlers=[],this.errorCache.clear()}}class ps{constructor(){n(this,"observer",null),n(this,"navigationTimingCollected",!1),n(this,"resourceCache",new Map),n(this,"longTaskCache",new Map),n(this,"resourceDebounceTime",1e3),n(this,"longTaskDebounceTime",100)}init(){"undefined"!=typeof window&&window.performance&&("complete"===document.readyState?(this.collectNavigationTiming(),this.collectResourceTiming()):window.addEventListener("load",()=>{this.collectNavigationTiming(),this.collectResourceTiming()}),this.observeLongTasks())}collectNavigationTiming(){if(!D()&&!this.navigationTimingCollected)try{const e=performance.getEntriesByType("navigation")[0];if(!e)return;const 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,response:e.responseEnd-e.responseStart,domParse:e.domInteractive-e.responseEnd,resourceLoad:e.loadEventStart-e.domContentLoadedEventEnd,total:e.loadEventEnd-e.fetchStart,domContentLoaded:e.domContentLoadedEventEnd-e.fetchStart,load:e.loadEventEnd-e.fetchStart},n={type:"performance",name:"navigation-timing",timestamp:Date.now(),url:z(),title:M(),metricType:"navigation",metrics:t};this.navigationTimingCollected=!0,this.emitPerformance(n)}catch(e){console.error("PerformanceTracker: Error collecting navigation timing:",e)}}collectResourceTiming(){try{const e=performance.getEntriesByType("resource");if(!e||0===e.length)return;const t=Date.now();e.forEach(e=>{const n=e.name,r=this.resourceCache.get(n);if(r&&t-r<this.resourceDebounceTime)return;this.resourceCache.set(n,t);const s={dns:e.domainLookupEnd-e.domainLookupStart,tcp:e.connectEnd-e.connectStart,request:e.responseStart-e.requestStart,response:e.responseEnd-e.responseStart,total:e.responseEnd-e.startTime,size:e.transferSize||0},i={type:"performance",name:"resource-timing",timestamp:t,url:z(),title:M(),metricType:"resource",metrics:{...s,resourceUrl:e.name,resourceType:e.initiatorType}};this.emitPerformance(i)}),this.cleanExpiredResourceCache(t)}catch(e){console.error("PerformanceTracker: Error collecting resource timing:",e)}}observeLongTasks(){if("undefined"!=typeof PerformanceObserver&&br())try{const e=A((...e)=>{const t=e[0],n=Date.now(),r=`${t.startTime}-${t.duration}`,s=this.longTaskCache.get(r);if(s&&n-s<this.longTaskDebounceTime)return;this.longTaskCache.set(r,n);const i={type:"performance",name:"longtask",timestamp:n,url:z(),title:M(),metricType:"longtask",metrics:{duration:t.duration,startTime:t.startTime}};this.emitPerformance(i),this.cleanExpiredLongTaskCache(n)},this.longTaskDebounceTime);this.observer=new PerformanceObserver(t=>{t.getEntries().forEach(t=>{"longtask"===t.entryType&&e(t)})}),this.observer.observe({entryTypes:["longtask"]})}catch(e){console.error("PerformanceTracker: Error observing long tasks:",e)}}cleanExpiredResourceCache(e){for(const[t,n]of this.resourceCache.entries())e-n>3e5&&this.resourceCache.delete(t)}cleanExpiredLongTaskCache(e){for(const[t,n]of this.longTaskCache.entries())e-n>6e4&&this.longTaskCache.delete(t)}emitPerformance(e){"undefined"!=typeof window&&window.__trackerEventBus&&window.__trackerEventBus.emit("performance",e)}collectMetrics(){try{const e=performance.getEntriesByType("navigation")[0];if(!e)return null;const t={dns:e.domainLookupEnd-e.domainLookupStart,tcp:e.connectEnd-e.connectStart,ttfb:e.responseStart-e.requestStart,response:e.responseEnd-e.responseStart,domParse:e.domInteractive-e.responseEnd,resourceLoad:e.loadEventStart-e.domContentLoadedEventEnd,total:e.loadEventEnd-e.fetchStart};return{type:"performance",name:"custom-performance",timestamp:Date.now(),url:z(),title:M(),metricType:"navigation",metrics:t}}catch(e){return console.error("PerformanceTracker: Error collecting metrics:",e),null}}destroy(){this.observer&&(this.observer.disconnect(),this.observer=null),this.navigationTimingCollected=!1,this.resourceCache.clear(),this.longTaskCache.clear()}}class fs{constructor(e=Number.POSITIVE_INFINITY){n(this,"maxTotalBytes"),n(this,"stoppedByBudget",!1),this.maxTotalBytes=e}getStoppedByBudget(){return this.stoppedByBudget}setStoppedByBudget(e){this.stoppedByBudget=e}estimateTotalBytes(e){let t=0;for(const n of e.snapshots)t+=n.html.length+64,t+=384*n.mutations.length;for(const n of e.interactions)t+=this.estimateInteractionBytes(n);return t}allowsWrite(e,t){return!this.stoppedByBudget&&(this.maxTotalBytes===Number.POSITIVE_INFINITY||(!(this.estimateTotalBytes(e)+t>this.maxTotalBytes)||(this.stoppedByBudget=!0,!1)))}estimateInteractionBytes(e){try{return JSON.stringify(e).length}catch{return 128}}}class ms{constructor(e){n(this,"throttledMouseMoveHandler",null),n(this,"handleClick",e=>{var t;this.options.onInteraction({type:"click",timestamp:Date.now(),data:{x:e.clientX,y:e.clientY,target:null==(t=e.target)?void 0:t.tagName}})}),n(this,"handleInput",e=>{const t=e.target;t&&this.options.onInteraction({type:"input",timestamp:Date.now(),data:{tagName:t.tagName,value:t.value.substring(0,100)}})}),n(this,"handleScroll",()=>{this.options.onInteraction({type:"scroll",timestamp:Date.now(),data:{scrollX:window.scrollX,scrollY:window.scrollY}})}),n(this,"handleMouseMove",e=>{this.options.onInteraction({type:"mousemove",timestamp:Date.now(),data:{x:e.clientX,y:e.clientY}})}),this.options=e}start(){"undefined"!=typeof window&&"undefined"!=typeof document&&(document.addEventListener("click",this.handleClick,!0),document.addEventListener("input",this.handleInput,!0),window.addEventListener("scroll",this.handleScroll,{passive:!0}),this.options.recordMouseMove&&(this.throttledMouseMoveHandler=A((...e)=>{const t=e[0];this.handleMouseMove(t)},100),document.addEventListener("mousemove",this.throttledMouseMoveHandler,{passive:!0})))}stop(){"undefined"!=typeof document&&(document.removeEventListener("click",this.handleClick,!0),document.removeEventListener("input",this.handleInput,!0),window.removeEventListener("scroll",this.handleScroll,{passive:!0}),this.throttledMouseMoveHandler&&(document.removeEventListener("mousemove",this.throttledMouseMoveHandler,{passive:!0}),this.throttledMouseMoveHandler=null))}}class gs{constructor(e,t){n(this,"snapshots",[]),n(this,"interactions",[]),this.maxSnapshots=e,this.maxMutationRecordsPerSnapshot=t}getSnapshots(){return this.snapshots}setSnapshots(e){this.snapshots=e}getInteractions(){return this.interactions}setInteractions(e){this.interactions=e}createSnapshot(e,t){this.snapshots.length>=this.maxSnapshots&&this.snapshots.shift(),this.snapshots.push({timestamp:t,html:e,mutations:[]})}hasSnapshots(){return this.snapshots.length>0}planMutationsForLatestSnapshot(e){const t=this.snapshots[this.snapshots.length-1];if(!t||0===e.length)return[];let n=e;const r=t.mutations.length+n.length;if(r>this.maxMutationRecordsPerSnapshot){const s=r-this.maxMutationRecordsPerSnapshot;if(s<=t.mutations.length)t.mutations.splice(0,s);else{const r=s-t.mutations.length;t.mutations.length=0,n=e.slice(r)}}return n}appendMutationsToLatestSnapshot(e){if(0===e.length)return;const t=this.snapshots[this.snapshots.length-1];t&&t.mutations.push(...e)}appendInteraction(e){this.interactions.length>=this.maxSnapshots&&this.interactions.shift(),this.interactions.push(e)}getData(){return{snapshots:[...this.snapshots],interactions:[...this.interactions]}}clear(){this.snapshots=[],this.interactions=[]}}class vs{constructor(e={}){n(this,"observer",null),n(this,"isRecording",!1),n(this,"mutationThrottleMs",100),n(this,"store"),n(this,"budget"),n(this,"interactionLifecycle");const t=e.recordMouseMove??!0;this.mutationThrottleMs=e.snapshotThrottleMs??100;const r=e.maxSnapshots??1e3,s=void 0!==e.maxTotalBytes&&e.maxTotalBytes>0?e.maxTotalBytes:Number.POSITIVE_INFINITY,i=void 0!==e.maxMutationRecordsPerSnapshot&&e.maxMutationRecordsPerSnapshot>0?e.maxMutationRecordsPerSnapshot:8e3;this.store=new gs(r,i),this.budget=new fs(s),this.interactionLifecycle=new ms({recordMouseMove:t,onInteraction:e=>{this.recordInteraction(e)}})}get snapshots(){return this.store.getSnapshots()}set snapshots(e){this.store.setSnapshots(e)}get interactions(){return this.store.getInteractions()}set interactions(e){this.store.setInteractions(e)}get stoppedByBudget(){return this.budget.getStoppedByBudget()}set stoppedByBudget(e){this.budget.setStoppedByBudget(e)}withinByteBudget(e){return this.budget.allowsWrite({snapshots:this.snapshots,interactions:this.interactions},e)}start(){if(this.isRecording||"undefined"==typeof document)return;this.isRecording=!0,this.takeSnapshot();const e=A((...e)=>{const t=e[0];this.recordMutations(t)},this.mutationThrottleMs);"function"==typeof MutationObserver?(this.observer=new MutationObserver(e),this.observer.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0,characterData:!0}),this.interactionLifecycle.start()):this.interactionLifecycle.start()}stop(){this.isRecording&&(this.isRecording=!1,this.observer&&(this.observer.disconnect(),this.observer=null),this.interactionLifecycle.stop())}takeSnapshot(){try{const e=document.documentElement.outerHTML;if(!this.withinByteBudget(e.length))return;this.store.createSnapshot(e,Date.now())}catch(e){console.error("SessionReplay: Error taking snapshot:",e)}}recordMutations(e){if(this.stoppedByBudget||!this.store.hasSnapshots()||0===e.length)return;const t=this.store.planMutationsForLatestSnapshot(e);if(0===t.length)return;const n=384*t.length;this.withinByteBudget(n)&&this.store.appendMutationsToLatestSnapshot(t)}recordInteraction(e){const t=this.budget.estimateInteractionBytes(e);this.withinByteBudget(t)&&this.store.appendInteraction(e)}getData(){return{snapshots:[...this.snapshots],interactions:[...this.interactions]}}clear(){this.snapshots=[],this.interactions=[]}destroy(){this.stop(),this.clear()}}class bs{constructor(e){n(this,"autoTracker",null),n(this,"errorTracker",null),n(this,"performanceTracker",null),n(this,"sessionReplay",null),this.config=e}init(){if(this.config.get("enableAutoTrack")&&!this.autoTracker&&(this.autoTracker=new hs,this.autoTracker.init({enableVueTracking:this.config.get("enableVueTracking")??!1,enableNaiveUITracking:this.config.get("enableNaiveUITracking")??!1,extractComponentProps:this.config.get("extractComponentProps")??!0,extractComponentValue:this.config.get("extractComponentValue")??!0,getConfig:()=>this.config.getAll()})),this.config.get("enableErrorTrack")&&!this.errorTracker&&(this.errorTracker=new us,this.errorTracker.init()),this.config.get("enablePerformanceTrack")&&!this.performanceTracker&&(this.performanceTracker=new ps,this.performanceTracker.init()),this.config.get("enableSessionReplay")&&!this.sessionReplay){const e=this.config.get("sessionReplay")||{},t=this.config.get("maxSessionReplaySnapshots");this.sessionReplay=new vs({...e,maxSnapshots:e.maxSnapshots??t}),this.sessionReplay.start()}}getAutoTracker(){return this.autoTracker}getErrorTracker(){return this.errorTracker}getPerformanceTracker(){return this.performanceTracker}getSessionReplay(){return this.sessionReplay}destroy(){var e,t,n,r;null==(e=this.autoTracker)||e.destroy(),null==(t=this.errorTracker)||t.destroy(),null==(n=this.performanceTracker)||n.destroy(),null==(r=this.sessionReplay)||r.destroy()}}class ys{constructor(e,t,n,r,s){this.enricher=e,this.dataProcessor=t,this.batchSender=n,this.behaviorAnalysis=r,this.shouldSkip=s}dispatch(e,t){if(!this.shouldSkip())try{const n=this.enricher.enrich(e,{deviceId:t.deviceId,sessionId:t.sessionId,configUserId:t.configUserId,userInfo:t.userInfo,customProperties:t.customProperties}),r=this.dataProcessor.process(n,{sampleRate:t.sampleRate,enableDeduplication:!0,enableCompression:t.enableCompression??!1,isCritical:"error"===e.type});if(!r)return;if(t.beforeSend){const e=t.beforeSend(r);if(!1===e||null===e)return;e&&Object.assign(r,e)}this.batchSender.add(r,{onBatchComplete:(e,n)=>{t.afterSend&&e.forEach(e=>{setTimeout(()=>{var r;null==(r=t.afterSend)||r.call(t,e,n)},0)})}}),"pageview"===e.type&&this.behaviorAnalysis.analyzePageView(r)}catch(n){t.onError?t.onError(n):console.error("Tracker: Error sending event:",n)}}}const ws={enabled:!0,recordRequestBody:!0,recordResponseBody:!0,maxResponseBodySize:102400,maxRequestBodySize:102400,onlyFailedRequests:!1};function _s(e,t){return!t||("string"==typeof t?e.includes(t):t instanceof RegExp?t.test(e):"function"!=typeof t||t(e))}function ks(e,t){if(!e||"object"!=typeof e||0===t.length)return e;if(Array.isArray(e))return e.map(e=>ks(e,t));const n={};for(const[r,s]of Object.entries(e)){const e=r.toLowerCase(),i=t.some(t=>e.includes(t.toLowerCase()));n[r]=i?"[FILTERED]":"object"==typeof s&&null!==s?ks(s,t):s}return n}function xs(e={}){const t={...ws,...e};let n=null,r=null,s=null,i=null;const a=new Map;return{name:"network-interceptor",install(e){if(t.enabled&&"undefined"!=typeof window&&(void 0!==window.fetch&&(n=window.fetch,window.fetch=async function(r,s){const i="string"==typeof r?r:r instanceof URL?r.href:r.url,o=(null==s?void 0:s.method)||("string"==typeof r||r instanceof URL||!("method"in r)?void 0:r.method)||"GET";if(!_s(i,t.urlFilter))return n.call(this,r,s);const l=`${Date.now()}-${Math.random().toString(36).substring(2,9)}`,c=Date.now(),d={};let h;if("string"!=typeof r&&!(r instanceof URL)&&"headers"in r&&r.headers instanceof Headers&&r.headers.forEach((e,t)=>{d[t]=e}),(null==s?void 0:s.headers)&&(s.headers instanceof Headers?s.headers.forEach((e,t)=>{d[t]=e}):Array.isArray(s.headers)?s.headers.forEach(([e,t])=>{d[e]=t}):Object.assign(d,s.headers)),t.recordRequestBody){const e=(null==s?void 0:s.body)??("string"==typeof r||r instanceof URL||!("body"in r)?null:r.body);if(h=await async function(e,t,n){if(e&&n)try{if("string"==typeof e)return e.length>t?e.substring(0,t)+"...[TRUNCATED]":e;if(e instanceof FormData){const t={};for(const[n,r]of e.entries())r instanceof File?t[n]=`[File: ${r.name}, ${r.size} bytes]`:t[n]=r;return t}if(e instanceof URLSearchParams)return Object.fromEntries(e.entries());if(e instanceof Blob){if(e.size>t)return`[Blob: ${e.size} bytes, type: ${e.type}]`;try{return await e.text()}catch{return`[Blob: ${e.size} bytes, type: ${e.type}]`}}return e instanceof ArrayBuffer?e.byteLength>t?`[ArrayBuffer: ${e.byteLength} bytes]`:(new TextDecoder).decode(e):"[Unsupported body type]"}catch(r){return console.warn("NetworkInterceptor: Failed to read request body:",r),"[Error reading body]"}}(e,t.maxRequestBodySize,t.recordRequestBody),t.sensitiveFields&&t.sensitiveFields.length>0&&void 0!==h)if("string"==typeof h)try{h=ks(JSON.parse(h),t.sensitiveFields)}catch{h=ks(h,t.sensitiveFields)}else h=ks(h,t.sensitiveFields)}a.set(l,{url:i,method:o,headers:d,startTime:c,requestBody:h});const u={type:"custom",name:"custom",eventName:"api-request",timestamp:c,url:z(),title:M(),properties:{url:i.split("?")[0].split("#")[0],fullUrl:i,method:o,headers:t.sensitiveFields&&t.sensitiveFields.length>0?ks(d,t.sensitiveFields):d,body:h,timestamp:c}};e.send(u);try{const d=await n.call(this,r,s),h=Date.now(),u=h-c,p=d.status,f=d.ok;if(t.onlyFailedRequests&&f)return a.delete(l),d;let m;t.recordResponseBody&&(m=await async function(e,t,n){if(n)try{if(!(e instanceof Response)){const n=e,r=n.responseText||"";if(r.length>t)return r.substring(0,t)+"...[TRUNCATED]";let s="";try{s=n.getResponseHeader("content-type")||""}catch{}if(s.includes("application/json"))try{return JSON.parse(r)}catch{return r}return r}{const n=e.headers.get("content-length");if(n&&parseInt(n,10)>t)return`[Response too large: ${n} bytes]`;let s;try{s=e.clone()}catch(r){return"[Response body already consumed]"}const i=e.headers.get("content-type")||"";if(i.includes("application/json")){const e=await s.text();if(e.length>t)return e.substring(0,t)+"...[TRUNCATED]";try{return JSON.parse(e)}catch{return e}}else{if(i.includes("text/")){const e=await s.text();return e.length>t?e.substring(0,t)+"...[TRUNCATED]":e}try{return`[${i||"unknown"}: ${(await s.blob()).size} bytes]`}catch{return`[${i||"unknown"}: unable to read]`}}}}catch(r){return console.warn("NetworkInterceptor: Failed to read response body:",r),"[Error reading response]"}}(d,t.maxResponseBodySize,t.recordResponseBody),t.sensitiveFields&&t.sensitiveFields.length>0&&void 0!==m&&(m=ks(m,t.sensitiveFields)));const g=d.headers.get("content-length"),v=g?parseInt(g,10):void 0,b={type:"custom",name:"custom",eventName:"api-response",timestamp:h,url:z(),title:M(),properties:{url:i.split("?")[0].split("#")[0],fullUrl:i,method:o,statusCode:p,duration:u,responseSize:v,success:f,body:m,timestamp:h}};return e.send(b),a.delete(l),d}catch(p){const t=Date.now(),n=t-c,r={type:"custom",name:"custom",eventName:"api-response",timestamp:t,url:z(),title:M(),properties:{url:i.split("?")[0].split("#")[0],fullUrl:i,method:o,statusCode:0,duration:n,success:!1,error:p instanceof Error?p.message:String(p),timestamp:t}};throw e.send(r),a.delete(l),p}}),"undefined"!=typeof XMLHttpRequest)){r=XMLHttpRequest.prototype.open,s=XMLHttpRequest.prototype.send,i=XMLHttpRequest.prototype.setRequestHeader;const n=new WeakMap,a=new WeakMap;XMLHttpRequest.prototype.open=function(e,t,s,i,o){const l="string"==typeof t?t:t.href;return a.set(this,{url:l,method:e.toUpperCase(),startTime:Date.now()}),n.set(this,{}),r.call(this,e,t,void 0===s||s,i,o)},XMLHttpRequest.prototype.setRequestHeader=function(e,t){const r=n.get(this)||{};return r[e]=t,n.set(this,r),i.call(this,e,t)},XMLHttpRequest.prototype.send=function(r){const i=a.get(this);if(!i)return s.call(this,r);const{url:o,method:l,startTime:c}=i,d=n.get(this)||{};if(!_s(o,t.urlFilter))return s.call(this,r);let h;if(t.recordRequestBody&&r){if("string"==typeof r)h=r.length>t.maxRequestBodySize?r.substring(0,t.maxRequestBodySize)+"...[TRUNCATED]":r;else if(r instanceof FormData){const e={};for(const[t,n]of r.entries())n instanceof File?e[t]=`[File: ${n.name}, ${n.size} bytes]`:e[t]=n;h=e}else h=r instanceof Blob?r.size>t.maxRequestBodySize?`[Blob: ${r.size} bytes, type: ${r.type}]`:"[Blob]":"[Unsupported body type]";t.sensitiveFields&&t.sensitiveFields.length>0&&(h=ks(h,t.sensitiveFields))}i.requestBody=h;const u={type:"custom",name:"custom",eventName:"api-request",timestamp:c,url:z(),title:M(),properties:{url:o.split("?")[0].split("#")[0],fullUrl:o,method:l,headers:t.sensitiveFields&&t.sensitiveFields.length>0?ks(d,t.sensitiveFields):d,body:h,timestamp:c}};e.send(u);const p=()=>{if(this.readyState===XMLHttpRequest.DONE){const s=Date.now(),i=s-c,d=this.status,h=d>=200&&d<400;if(t.onlyFailedRequests&&h)return this.removeEventListener("readystatechange",p),a.delete(this),void n.delete(this);let u="";try{u=this.responseText||""}catch(r){console.warn("NetworkInterceptor: Failed to read XHR responseText:",r)}const f=u.length;let m;if(t.recordResponseBody){if(u.length>t.maxResponseBodySize)m=u.substring(0,t.maxResponseBodySize)+"...[TRUNCATED]";else{let e="";try{e=this.getResponseHeader("content-type")||""}catch{}if(e.includes("application/json"))try{m=JSON.parse(u)}catch{m=u}else m=u}t.sensitiveFields&&t.sensitiveFields.length>0&&(m=ks(m,t.sensitiveFields))}const g={type:"custom",name:"custom",eventName:"api-response",timestamp:s,url:z(),title:M(),properties:{url:o.split("?")[0].split("#")[0],fullUrl:o,method:l,statusCode:d,duration:i,responseSize:f,success:h,body:m,timestamp:s}};e.send(g),this.removeEventListener("readystatechange",p),a.delete(this),n.delete(this)}};return this.addEventListener("readystatechange",p),s.call(this,r)}}},uninstall(){"undefined"!=typeof window&&(n&&(window.fetch=n,n=null),r&&s&&i&&(XMLHttpRequest.prototype.open=r,XMLHttpRequest.prototype.send=s,XMLHttpRequest.prototype.setRequestHeader=i,r=null,s=null,i=null),a.clear())}}}const Ts=xs();e.PerformanceMonitor=Or,e.UserActionSequence=class{constructor(e,t,r,s={}){var i,a,o,l,c,d,h,u;n(this,"events",[]),n(this,"sessionId"),n(this,"userId"),n(this,"deviceId"),n(this,"startTime"),n(this,"maxEvents"),n(this,"sampleRate"),n(this,"enableSampling"),n(this,"performanceMode"),n(this,"performanceBudget"),n(this,"eventTypeCounts",new Map),n(this,"isSorted",!0),n(this,"lastEventTimestamp",0),n(this,"eventIndexes",{pageViews:[],clicks:[],inputs:[],errors:[],customEvents:[]}),n(this,"cachedProfile",null),n(this,"cacheTimestamp",0),n(this,"cacheTTL",5e3),n(this,"eventQueue",[]),n(this,"isProcessing",!1),n(this,"maxQueueSize",100),n(this,"performanceMetrics",{addEventTimes:[],profileGenerationTimes:[]}),n(this,"performanceModeActive",!1),this.sessionId=e,this.deviceId=t,this.userId=r,this.startTime=Date.now(),this.maxEvents=s.maxEvents??1e4,this.sampleRate=s.sampleRate??1,this.enableSampling=s.enableSampling??!0,this.performanceMode={mode:(null==(i=s.performanceMode)?void 0:i.mode)??"balanced",asyncProcessing:(null==(a=s.performanceMode)?void 0:a.asyncProcessing)??!0,useWebWorker:(null==(o=s.performanceMode)?void 0:o.useWebWorker)??!1,eventSampleRate:(null==(l=s.performanceMode)?void 0:l.eventSampleRate)??this.sampleRate,maxEvents:(null==(c=s.performanceMode)?void 0:c.maxEvents)??this.maxEvents,enablePerformanceMonitoring:(null==(d=s.performanceMode)?void 0:d.enablePerformanceMonitoring)??!0},this.performanceBudget={addEventMaxTime:(null==(h=s.performanceBudget)?void 0:h.addEventMaxTime)??1,profileGenerationMaxTime:(null==(u=s.performanceBudget)?void 0:u.profileGenerationMaxTime)??16}}addEventAsync(e){this.performanceMode.asyncProcessing?(this.eventQueue.length>=this.maxQueueSize&&this.eventQueue.shift(),this.eventQueue.push(e),this.isProcessing||this.processQueueAsync()):this.addEventInternal(e)}addEvent(e){const t=performance.now();try{if(this.shouldSkipForPerformance(e))return;this.addEventInternal(e)}finally{const e=performance.now()-t;this.recordPerformance("addEvent",e),e>this.performanceBudget.addEventMaxTime&&this.enablePerformanceMode()}}addEventInternal(e){if(this.events.length>=this.maxEvents&&this.cleanupOldEvents(),this.enableSampling&&Math.random()>this.sampleRate&&"error"!==e.type&&"custom"!==e.type)return;const t={type:e.type,name:e.name,timestamp:e.timestamp,url:e.url,title:e.title,sessionId:this.sessionId,deviceId:this.deviceId,userId:this.userId||e.userId,properties:this.sanitizeProperties(e.properties),..."custom"===e.type&&"eventName"in e?{eventName:e.eventName}:{}},n=this.events.length;this.events.push(t),this.updateIndexes(e.type,n),this.eventTypeCounts.set(e.type,(this.eventTypeCounts.get(e.type)||0)+1),e.timestamp<this.lastEventTimestamp&&(this.isSorted=!1),this.lastEventTimestamp=e.timestamp,this.cachedProfile=null}processQueueAsync(){0!==this.eventQueue.length?(this.isProcessing=!0,"undefined"!=typeof window&&"requestIdleCallback"in window?requestIdleCallback(()=>{this.processBatch(),this.processQueueAsync()},{timeout:100}):setTimeout(()=>{this.processBatch(),this.processQueueAsync()},0)):this.isProcessing=!1}processBatch(){this.eventQueue.splice(0,10).forEach(e=>{this.addEventInternal(e)})}shouldSkipForPerformance(e){return!!this.performanceModeActive&&("error"!==e.type&&"custom"!==e.type&&Math.random()>.5)}enablePerformanceMode(){this.performanceModeActive||(console.warn("UserActionSequence: Entering performance mode due to slow operations"),this.performanceModeActive=!0,this.sampleRate=Math.max(.1,.5*this.sampleRate),this.maxEvents=Math.floor(.5*this.maxEvents),this.cleanupOldEvents())}sanitizeProperties(e){if(!e)return;const t={};for(const[n,r]of Object.entries(e)){const e=JSON.stringify(r);e.length>1e3?t[n]=e.substring(0,1e3)+"...":t[n]=r}return Object.keys(t).length>0?t:void 0}updateIndexes(e,t){switch(e){case"pageview":this.eventIndexes.pageViews.push(t);break;case"click":this.eventIndexes.clicks.push(t);break;case"input":this.eventIndexes.inputs.push(t);break;case"error":this.eventIndexes.errors.push(t);break;case"custom":this.eventIndexes.customEvents.push(t)}}cleanupOldEvents(){const e=Math.floor(this.maxEvents/2),t=this.events.length-e;this.events=this.events.slice(-e),this.rebuildIndexes(),this.recalculateCounts(),this.performanceMode.enablePerformanceMonitoring&&console.warn(`UserActionSequence: Cleaned up ${t} old events`)}rebuildIndexes(){this.eventIndexes={pageViews:[],clicks:[],inputs:[],errors:[],customEvents:[]},this.events.forEach((e,t)=>{this.updateIndexes(e.type,t)})}recalculateCounts(){this.eventTypeCounts.clear(),this.events.forEach(e=>{this.eventTypeCounts.set(e.type,(this.eventTypeCounts.get(e.type)||0)+1)})}getSequence(){return this.isSorted||(this.events.sort((e,t)=>e.timestamp-t.timestamp),this.isSorted=!0,this.rebuildIndexes()),this.events}getDuration(){if(0===this.events.length)return 0;const e=this.getSequence();return e[e.length-1].timestamp-this.startTime}getEventsByType(e){const t=this.getIndexesByType(e),n=this.getSequence();return t.filter(e=>e>=0&&e<n.length).map(e=>n[e]).filter(Boolean)}getIndexesByType(e){switch(e){case"pageview":return this.eventIndexes.pageViews;case"click":return this.eventIndexes.clicks;case"input":return this.eventIndexes.inputs;case"error":return this.eventIndexes.errors;case"custom":return this.eventIndexes.customEvents;default:return[]}}generateProfile(){const e=Date.now();if(this.cachedProfile&&e-this.cacheTimestamp<this.cacheTTL)return this.cachedProfile;const t=this.getSequence(),n=e=>e.filter(e=>e>=0&&e<t.length).map(e=>t[e]).filter(Boolean),r={sessionId:this.sessionId,userId:this.userId,deviceId:this.deviceId,startTime:this.startTime,duration:this.getDuration(),totalEvents:t.length,eventTypes:Object.fromEntries(this.eventTypeCounts),pageViews:n(this.eventIndexes.pageViews),clicks:n(this.eventIndexes.clicks),inputs:n(this.eventIndexes.inputs),errors:n(this.eventIndexes.errors),customEvents:n(this.eventIndexes.customEvents),userJourney:this.buildUserJourneyOptimized(t),behaviorMetrics:this.calculateBehaviorMetricsOptimized(t)};return this.cachedProfile=r,this.cacheTimestamp=e,r}generateProfileAsync(){return new Promise(e=>{"undefined"!=typeof window&&"requestIdleCallback"in window?requestIdleCallback(()=>{const t=performance.now(),n=this.generateProfile(),r=performance.now()-t;this.recordPerformance("profileGeneration",r),e(n)},{timeout:1e3}):setTimeout(()=>{const t=performance.now(),n=this.generateProfile(),r=performance.now()-t;this.recordPerformance("profileGeneration",r),e(n)},0)})}generateLightweightProfile(){const e=this.getSequence();return{sessionId:this.sessionId,userId:this.userId,deviceId:this.deviceId,startTime:this.startTime,duration:this.getDuration(),totalEvents:e.length,eventTypes:Object.fromEntries(this.eventTypeCounts),behaviorMetrics:this.calculateBehaviorMetricsOptimized(e)}}buildUserJourneyOptimized(e){const t=[];let n=this.startTime;for(let r=0;r<e.length;r++){const s=e[r];t.push({step:r+1,timestamp:s.timestamp,type:s.type,url:s.url,title:s.title,action:this.extractAction(s),duration:s.timestamp-n}),n=s.timestamp}return t}extractAction(e){var t,n;switch(e.type){case"pageview":return`访问页面: ${e.title||e.url}`;case"click":{const n=e;return`点击: ${(null==(t=n.elementInfo)?void 0:t.text)||n.elementPath||"未知元素"}`}case"input":{const t=e;return`输入: ${(null==(n=t.elementInfo)?void 0:n.name)||t.elementPath||"未知字段"}`}case"error":return`错误: ${e.message}`;case"custom":return`自定义事件: ${e.eventName}`;default:return`${e.type} 事件`}}calculateBehaviorMetricsOptimized(e){const t=this.eventIndexes.pageViews.filter(t=>t>=0&&t<e.length),n=t.map(t=>e[t]);let r=0;const s=new Set;for(const i of n)i.duration&&(r+=i.duration),s.add(i.url);return{pv:t.length,avgPageDuration:t.length>0?r/t.length:0,clickCount:this.eventIndexes.clicks.length,inputCount:this.eventIndexes.inputs.length,errorCount:this.eventIndexes.errors.length,uniquePages:s.size}}recordPerformance(e,t){if(!this.performanceMode.enablePerformanceMonitoring)return;const n=this.performanceMetrics[`${e}Times`];n&&(n.push(t),n.length>100&&n.shift())}getPerformanceStats(){const e=this.performanceMetrics.addEventTimes,t=this.performanceMetrics.profileGenerationTimes;return{avgAddEventTime:e.length>0?e.reduce((e,t)=>e+t,0)/e.length:0,avgProfileGenerationTime:t.length>0?t.reduce((e,t)=>e+t,0)/t.length:0,p95AddEventTime:this.percentile(e,95),p95ProfileGenerationTime:this.percentile(t,95)}}percentile(e,t){if(0===e.length)return 0;const n=[...e].sort((e,t)=>e-t),r=Math.ceil(t/100*n.length)-1;return n[Math.max(0,r)]||0}reset(){this.events=[],this.eventQueue=[],this.eventTypeCounts.clear(),this.eventIndexes={pageViews:[],clicks:[],inputs:[],errors:[],customEvents:[]},this.cachedProfile=null,this.isSorted=!0,this.lastEventTimestamp=0,this.startTime=Date.now(),this.performanceModeActive=!1}},e.createAngularFrameAdapter=x,e.createNetworkInterceptorPlugin=xs,e.createReactFrameAdapter=_,e.default=class{constructor(e){var t;if(n(this,"config"),n(this,"customTracker"),n(this,"dataProcessor"),n(this,"batchSender"),n(this,"pluginManager"),n(this,"behaviorAnalysis"),n(this,"performanceMonitor"),n(this,"panelManager"),n(this,"eventEnricher"),n(this,"eventBusBridge"),n(this,"configCoordinator"),n(this,"featureRegistry"),n(this,"eventDispatcher"),n(this,"userInfo",null),n(this,"deviceId"),n(this,"sessionId"),!e.appId)throw new Error("Tracker: appId is required");const r={...e,frameAdapters:[...e.enableReactTracking?[_({priority:80})]:[],...e.enableAngularTracking?[x({getComponent:e.angularGetComponent,priority:79})]:[],...e.frameAdapters??[]]};(null==(t=r.frameAdapters)?void 0:t.length)||delete r.frameAdapters,this.config=new S(r),this.deviceId=e.deviceId||C(),this.sessionId=R(),this.customTracker=new H,this.dataProcessor=new hr;const s=e.serverUrl||"about:blank";var i;this.batchSender=new zr(s,{batchSize:this.config.get("batchSize"),batchWait:this.config.get("batchWait"),enableOfflineStorage:this.config.get("enableOfflineStorage")??!0,maxOfflineStorageSize:this.config.get("maxOfflineStorageSize"),maxRetries:this.config.get("maxRetries")??3}),e.serverUrl||this.batchSender.setServerUrl(""),this.pluginManager=new Mr,this.behaviorAnalysis=new Br,this.performanceMonitor=new Or,this.panelManager=new Fr,this.eventEnricher=new $r,this.eventBusBridge=new qr(this.send.bind(this)),this.configCoordinator=new Vr(this.config,this.batchSender),this.featureRegistry=new bs(this.config),this.eventDispatcher=new ys(this.eventEnricher,this.dataProcessor,this.batchSender,this.behaviorAnalysis,()=>"undefined"!=typeof window&&D()),this.pluginManager.setTrackerInstance({send:(i={send:this.send.bind(this),getConfig:()=>this.config.getAll(),setUser:this.setUser.bind(this),getUser:()=>this.userInfo}).send,getConfig:i.getConfig,setUser:i.setUser,getUser:i.getUser}),this.panelManager.setTrackerInstance(this),this.init(),this.eventBusBridge.attachToWindow()}init(){this.eventBusBridge.setup(),this.featureRegistry.init(),this.config.get("userId")&&this.setUser({userId:this.config.get("userId")})}send(e){this.eventDispatcher.dispatch(e,{deviceId:this.deviceId,sessionId:this.sessionId,configUserId:this.config.get("userId"),userInfo:this.userInfo,customProperties:this.config.get("customProperties")||{},sampleRate:this.config.get("sampleRate"),enableCompression:this.config.get("enableCompression")??!1,beforeSend:this.config.get("beforeSend"),afterSend:this.config.get("afterSend"),onError:this.config.get("onError")})}track(e,t){const n=this.customTracker.track(e,t);this.send(n)}setUser(e){this.userInfo={...this.userInfo,...e},this.config.set("userId",e.userId||"")}getUser(){return this.userInfo}trackError(e,t){const n=this.featureRegistry.getErrorTracker();if(n)n.trackError(e,t);else{const n={type:"error",name:"custom-error",timestamp:Date.now(),url:z(),title:M(),errorType:"js",message:e instanceof Error?e.message:e,stack:e instanceof Error?e.stack:void 0,properties:t};this.send(n)}}trackPerformance(){const e=this.featureRegistry.getPerformanceTracker();if(e){const t=e.collectMetrics();t&&this.send(t)}}trackPageView(){const e=this.featureRegistry.getAutoTracker();if(e){const t=e.getViewTracker().trackPageView();this.send(t)}}use(e){this.pluginManager.use(e)}updateConfig(e){this.configCoordinator.apply(e)}getConfig(){return this.config.getAll()}openPerformancePanel(){this.panelManager.openPerformancePanel()}openOfflineStorageViewer(){this.panelManager.openOfflineStorageViewer()}getPerformanceMetrics(e,t){return this.performanceMonitor.getMetrics(e,t)}generatePerformanceReport(e){return this.performanceMonitor.generateReport(e)}getPerformanceMonitor(){return this.performanceMonitor}getBehaviorMetrics(){return this.behaviorAnalysis.getMetrics()}getSessionReplayData(){var e;return null==(e=this.featureRegistry.getSessionReplay())?void 0:e.getData()}async getOfflineEvents(){return this.batchSender.getOfflineEvents()}async getOfflineEventCount(){return this.batchSender.getOfflineEventCount()}async clearOfflineStorage(){return this.batchSender.clearOfflineStorage()}getAutoTracker(){return this.featureRegistry.getAutoTracker()}destroy(){this.eventBusBridge.teardown(),this.featureRegistry.destroy(),this.performanceMonitor.destroy(),this.batchSender.destroy(),this.pluginManager.clear()}async destroyAsync(){this.eventBusBridge.teardown(),this.featureRegistry.destroy(),this.performanceMonitor.destroy(),await this.batchSender.destroyAsync(),this.pluginManager.clear(),E.clear()}},e.eventBus=E,e.extractDomDataComponentInfo=Gr,e.extractNaiveUIComponentInfo=Xr,e.extractVueComponentInfo=Kr,e.filterSensitiveData=c,e.getComponentAttrs=a,e.getComponentName=s,e.getComponentProps=i,e.getComponentValue=o,e.getDeviceId=C,e.getNaiveUIComponentTypes=function(e){return Jr[e]},e.getSessionId=R,e.getVueComponentInstance=r,e.identifyNaiveUIComponent=d,e.indexedDBStorage=Tr,e.isNaiveUIComponent=Wr,e.isNaiveUIComponentType=function(e,t){return!!e&&d(e)===t},e.isVueComponent=function(e){return!!e&&null!==r(e)},e.localStorage=_r,e.memoryStorage=xr,e.mergeSanitizeLimits=h,e.networkInterceptorPlugin=Ts,e.resolveClickComponentInfo=ss,e.sanitizeForComponentInfo=p,e.sessionStorage=kr,e.supportsIndexedDBApi=wr,e.supportsIntersectionObserver=yr,e.supportsLongTaskObserver=br,e.useTracker=function(){var e,t;if("undefined"==typeof window)return;const n=window.__VUE_APP__;if(null==(t=null==(e=null==n?void 0:n.config)?void 0:e.globalProperties)?void 0:t.$tracker)return n.config.globalProperties.$tracker;const r=window.__TRACKER_INSTANCE__;return r||void 0},e.vuePlugin=function(e,t){const{tracker:n,enableAutoTrack:r=!0,enableComponentInfo:s=!0}=t;n?(e.config.globalProperties.$tracker=n,e.provide("tracker",n),r&&e.mixin({mounted(){}})):console.error("VuePlugin: Tracker instance is required")},Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
3
3
|
//# sourceMappingURL=index.umd.js.map
|