alphana-sdk 1.0.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -46,19 +46,34 @@ interface TrackerConfig {
46
46
  */
47
47
  trackLogs?: boolean;
48
48
  /**
49
- * List of page paths for which heatmap data should be captured.
50
- * Only paths registered here will be tracked. If empty or undefined, the SDK
51
- * will send data for all pages (the backend enforces limits at ingest time).
49
+ * List of page paths for which heatmap data should be captured client-side.
50
+ * Paths should match the dashboard "Heatmap pages" list (decoded Unicode is
51
+ * fine the SDK normalizes percent-encoding vs `window.location` mismatches).
52
52
  *
53
- * Obtain the list of registered paths from the alphana dashboard under
54
- * "Heatmap Pages" for your app, then pass them here.
53
+ * If empty or undefined, the SDK may still collect moves locally, but the
54
+ * backend only persists points when the app has at least one registered
55
+ * heatmap page and the path matches.
55
56
  *
56
57
  * Example: `heatmapPages: ["/", "/pricing", "/dashboard"]`
57
58
  */
58
59
  heatmapPages?: string[];
60
+ /**
61
+ * When true, records DOM mutations with rrweb and sends `session_replay` events
62
+ * for pixel-accurate session replay in the dashboard (requires plan + platform).
63
+ * @default false
64
+ */
65
+ sessionReplay?: boolean;
66
+ /** rrweb full snapshot interval in ms. @default 600000 (10 min) */
67
+ sessionReplayCheckoutEveryNms?: number;
68
+ /** Max rrweb events per batch before an immediate flush. @default 48 */
69
+ sessionReplayMaxEventsPerBatch?: number;
70
+ /** Periodic flush of buffered rrweb events (ms). @default 4000 */
71
+ sessionReplayFlushIntervalMs?: number;
59
72
  /** Called synchronously for every emitted event. */
60
73
  onEvent?: (event: TrackerEvent) => void;
61
74
  }
75
+ /** Assigned variant key per running A/B experiment (`null` = not in experiment). */
76
+ type AbVariantsMap = Record<string, string | null>;
62
77
  interface GeoLocation {
63
78
  /** ISO 3166-1 alpha-2 country code, e.g. "US" */
64
79
  country: string;
@@ -121,6 +136,36 @@ interface UTurn {
121
136
  timestamp: number;
122
137
  sessionId: string;
123
138
  }
139
+ /**
140
+ * One-time (or rare) snapshot of the client environment for a session.
141
+ * Lets the backend align device / OS / browser with what the browser reports
142
+ * (useful vs. reduced User-Agent strings) and store locale / viewport context
143
+ * for session replay catalog rows.
144
+ */
145
+ interface ClientContext {
146
+ sessionId: string;
147
+ timestamp: number;
148
+ device: "desktop" | "mobile" | "tablet";
149
+ os: string;
150
+ browser: string;
151
+ language: string;
152
+ languages: string[];
153
+ /** `prefers-color-scheme` when available */
154
+ colorScheme: "" | "light" | "dark";
155
+ screenWidth: number;
156
+ screenHeight: number;
157
+ viewportWidth: number;
158
+ viewportHeight: number;
159
+ devicePixelRatio: number;
160
+ /** IANA time zone from `Intl`, e.g. `Asia/Tehran` */
161
+ timeZone: string;
162
+ sdkVersion: string;
163
+ }
164
+ /** One batch of rrweb `eventWithTime` payloads for the backend. */
165
+ interface SessionReplayBatch {
166
+ seq: number;
167
+ events: unknown[];
168
+ }
124
169
  type TrackerEvent = {
125
170
  type: "pageview";
126
171
  data: PageView;
@@ -136,6 +181,12 @@ type TrackerEvent = {
136
181
  } | {
137
182
  type: "uturn";
138
183
  data: UTurn;
184
+ } | {
185
+ type: "client_context";
186
+ data: ClientContext;
187
+ } | {
188
+ type: "session_replay";
189
+ data: SessionReplayBatch;
139
190
  };
140
191
  interface SessionData {
141
192
  id: string;
@@ -215,12 +266,14 @@ declare class LogCapture {
215
266
  declare const DEFAULT_ENDPOINT = "https://api.alphana.ir/api/events";
216
267
  type SubscriberFn = (event: TrackerEvent) => void;
217
268
  type FlagSubscriberFn = (flags: Record<string, boolean>) => void;
269
+ type AbTestSubscriberFn = (variants: AbVariantsMap) => void;
218
270
  declare class UserTracker {
219
271
  private readonly cfg;
220
272
  private session;
221
273
  private navigation?;
222
274
  private time?;
223
275
  private heatmap?;
276
+ private sessionReplay?;
224
277
  /** Public so consumers can call logCapture.capture() for manual log entries. */
225
278
  logCapture?: LogCapture;
226
279
  private initialized;
@@ -232,6 +285,8 @@ declare class UserTracker {
232
285
  private userProperties;
233
286
  private flags;
234
287
  private readonly flagSubscribers;
288
+ private abVariants;
289
+ private readonly abTestSubscribers;
235
290
  constructor(config?: TrackerConfig);
236
291
  /**
237
292
  * Attach event listeners and start tracking.
@@ -309,6 +364,34 @@ declare class UserTracker {
309
364
  onFlagsChange(fn: FlagSubscriberFn): () => void;
310
365
  /** Fetch (or re-fetch) flags from the backend evaluate endpoint. */
311
366
  fetchFlags(): Promise<void>;
367
+ /**
368
+ * Returns variant keys assigned to this visitor for each running experiment.
369
+ * Fetched on `init()` and after `fetchAbTests()`.
370
+ *
371
+ * ```ts
372
+ * const variants = tracker.getAbVariants();
373
+ * // { 'checkout-cta-test': 'variant-b' }
374
+ * ```
375
+ */
376
+ getAbVariants(): AbVariantsMap;
377
+ /**
378
+ * Returns the assigned variant key for one experiment, or `null` if the
379
+ * experiment is not running or not found.
380
+ */
381
+ getAbVariant(experimentKey: string): string | null;
382
+ /**
383
+ * Returns `true` when the visitor is assigned to the given variant key.
384
+ */
385
+ isAbVariant(experimentKey: string, variantKey: string): boolean;
386
+ /**
387
+ * Subscribe to A/B assignment updates. Returns an unsubscribe function.
388
+ */
389
+ onAbTestsChange(fn: AbTestSubscriberFn): () => void;
390
+ /**
391
+ * Fetch (or re-fetch) variant assignments from `/ab-tests/evaluate`.
392
+ * @param keys When set, only these experiment keys are evaluated and merged.
393
+ */
394
+ fetchAbTests(keys?: string[]): Promise<void>;
312
395
  /** A read-only snapshot of the current session. */
313
396
  getSession(): Readonly<SessionData>;
314
397
  /** All page views recorded so far. */
@@ -336,4 +419,15 @@ declare class UserTracker {
336
419
  private sendBatch;
337
420
  }
338
421
 
339
- export { DEFAULT_ENDPOINT, type GeoLocation, type HeatmapPoint, type HeatmapRenderOptions, LogCapture, type LogEntry, type LogLevel, type PageView, type RageClick, type SessionData, type TimeSpent, type TrackerConfig, type TrackerEvent, type UTurn, UserTracker };
422
+ declare const ALPHANA_SDK_VERSION = "1.0.2";
423
+
424
+ /**
425
+ * Canonical URL path (+ optional query) for analytics / heatmap matching.
426
+ *
427
+ * Next.js `usePathname()` often returns percent-encoded segments while
428
+ * `window.location.pathname` is decoded — without normalization the backend
429
+ * cannot match registered heatmap pages or aggregate the same route.
430
+ */
431
+ declare function normalizeTrackerPath(path: string): string;
432
+
433
+ export { ALPHANA_SDK_VERSION, type AbVariantsMap, type ClientContext, DEFAULT_ENDPOINT, type GeoLocation, type HeatmapPoint, type HeatmapRenderOptions, LogCapture, type LogEntry, type LogLevel, type PageView, type RageClick, type SessionData, type TimeSpent, type TrackerConfig, type TrackerEvent, type UTurn, UserTracker, normalizeTrackerPath };
package/dist/index.js CHANGED
@@ -1,3 +1,23 @@
1
- 'use strict';var f="__ut_vid__";function d(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,a=>{let t=Math.random()*16|0;return (a==="x"?t:t&3|8).toString(16)})}function y(){if(typeof localStorage=="undefined")return d();try{let a=localStorage.getItem(f);if(a)return a;let t=d();return localStorage.setItem(f,t),t}catch(a){return d()}}var b="__ut_last_pv_path__",S="__ut_last_pv_entry_ms__";function w(a){if(typeof sessionStorage=="undefined")return null;try{return sessionStorage.getItem(a)}catch(t){return null}}function E(a,t){if(typeof sessionStorage!="undefined")try{sessionStorage.setItem(a,t);}catch(e){}}function P(a,t){E(b,a),E(S,String(t));}function T(){if(typeof performance=="undefined")return;let t=performance.getEntriesByType("navigation")[0];if(t!=null&&t.type)return t.type;let e=performance.navigation;if((e==null?void 0:e.type)===2)return "back_forward"}var h=class h{constructor({emit:t,sessionId:e}){this.previousPath="";this.originalPushState=null;this.originalReplaceState=null;this.pageEntryTime=0;this.handlePopState=()=>{this.handleNavigation();};this.emit=t,this.sessionId=e;}init(){let t=window.location.pathname+window.location.search;T()==="back_forward"&&this.tryEmitMpaHistoryTraversalUturn(t),this.recordPageView(t),window.addEventListener("popstate",this.handlePopState),this.originalPushState=history.pushState.bind(history);let e=this.originalPushState;history.pushState=(n,s,r)=>{e(n,s,r),this.handleNavigation();},this.originalReplaceState=history.replaceState.bind(history);let i=this.originalReplaceState;history.replaceState=(n,s,r)=>{i(n,s,r),this.handleNavigation();};}destroy(){window.removeEventListener("popstate",this.handlePopState),this.originalPushState&&(history.pushState=this.originalPushState),this.originalReplaceState&&(history.replaceState=this.originalReplaceState);}tryEmitMpaHistoryTraversalUturn(t){let e=w(b),i=w(S),n=i?Number(i):0;if(!e||!Number.isFinite(n)||n<=0||e===t)return;let s=Date.now()-n;s<0||s>h.UTURN_THRESHOLD_MS||this.emitUturn(e,t,s);}handleNavigation(){let t=window.location.pathname+window.location.search;if(t!==this.previousPath){if(this.previousPath&&this.pageEntryTime>0){let e=Date.now()-this.pageEntryTime;e<=h.UTURN_THRESHOLD_MS&&this.emitUturn(this.previousPath,t,e);}this.recordPageView(t);}}emitUturn(t,e,i){this.emit({type:"uturn",data:{fromPath:t,toPath:e,timeOnPageMs:i,timestamp:Date.now(),sessionId:this.sessionId}});}recordPageView(t){this.previousPath=t,this.pageEntryTime=Date.now(),P(t,this.pageEntryTime),this.emit({type:"pageview",data:{path:t,title:document.title,timestamp:Date.now(),sessionId:this.sessionId,referrer:document.referrer||void 0}}),window.dispatchEvent(new CustomEvent("tracker:navigate",{detail:{path:t,title:document.title}}));}};h.UTURN_THRESHOLD_MS=5e3;var p=h;var u=class{constructor({emit:t,sessionId:e}){this.currentPath="";this.startTime=0;this.tracking=false;this.handleNavigate=t=>{this.stopTracking(),this.currentPath=t.detail.path,this.startTracking();};this.handleVisibilityChange=()=>{document.hidden?this.stopTracking():this.startTracking();};this.handleUnload=()=>{this.stopTracking();};this.emit=t,this.sessionId=e;}init(){this.currentPath=window.location.pathname+window.location.search,this.startTracking(),window.addEventListener("tracker:navigate",this.handleNavigate),document.addEventListener("visibilitychange",this.handleVisibilityChange),window.addEventListener("beforeunload",this.handleUnload),window.addEventListener("pagehide",this.handleUnload);}destroy(){this.stopTracking(),window.removeEventListener("tracker:navigate",this.handleNavigate),document.removeEventListener("visibilitychange",this.handleVisibilityChange),window.removeEventListener("beforeunload",this.handleUnload),window.removeEventListener("pagehide",this.handleUnload);}startTracking(){this.startTime=Date.now(),this.tracking=true;}stopTracking(){if(!this.tracking||!this.currentPath)return;let t=Date.now()-this.startTime;if(t<100){this.tracking=false;return}this.emit({type:"timespent",data:{path:this.currentPath,duration:t,sessionId:this.sessionId,timestamp:Date.now()}}),this.tracking=false;}};function v(a,t){let e=0;return (...i)=>{let n=Date.now();n-e>=t&&(e=n,a(...i));}}var o=class o{constructor({emit:t,sessionId:e,sampleRate:i=.3,maxPoints:n=2e3,allowedPaths:s}){this.currentPath="";this.pointCounts={};this.recentClicks=[];this.handleMouseMove=t=>{if(Math.random()>this.sampleRate)return;let e=document.documentElement.scrollWidth,i=document.documentElement.scrollHeight,n=t.clientY+window.scrollY;this.recordPoint({x:t.clientX,y:n,xPct:e>0?t.clientX/e*100:0,yPct:i>0?n/i*100:0,pw:e,ph:i,type:"move"});};this.handleClick=t=>{if(Date.now()-this.lastTouchTime<500)return;let e=document.documentElement.scrollWidth,i=document.documentElement.scrollHeight,n=t.clientY+window.scrollY,s=this.getClickTarget(t);this.recordPoint({x:t.clientX,y:n,xPct:e>0?t.clientX/e*100:0,yPct:i>0?n/i*100:0,pw:e,ph:i,type:"click",...s?{target:s}:{}}),this.checkRageClick(t.clientX,n,this.currentPath);};this.lastTouchTime=0;this.handleTouchEnd=t=>{let e=t.changedTouches[0];if(!e)return;let i=document.documentElement.scrollWidth,n=document.documentElement.scrollHeight,s=e.clientY+window.scrollY;this.lastTouchTime=Date.now(),this.recordPoint({x:e.clientX,y:s,xPct:i>0?e.clientX/i*100:0,yPct:n>0?s/n*100:0,pw:i,ph:n,type:"click"}),this.checkRageClick(e.clientX,s,this.currentPath);};this.handleScroll=()=>{if(Math.random()>this.sampleRate)return;let t=document.documentElement.scrollWidth,e=document.documentElement.scrollHeight,i=window.innerWidth,n=window.scrollX,s=window.scrollY,r=n+i/2;this.recordPoint({x:i/2,y:s,xPct:t>0?r/t*100:50,yPct:e>0?s/e*100:0,pw:t,ph:e,type:"scroll"});};this.handleNavigate=t=>{this.currentPath=t.detail.path;};this.emit=t,this.sessionId=e,this.sampleRate=i,this.maxPoints=n,this.allowedPaths=s&&s.length>0?new Set(s):null,this.throttledMouseMove=v(this.handleMouseMove,50),this.throttledScroll=v(this.handleScroll,100);}init(){this.currentPath=window.location.pathname+window.location.search,document.addEventListener("mousemove",this.throttledMouseMove),document.addEventListener("click",this.handleClick),document.addEventListener("touchend",this.handleTouchEnd,{passive:true}),window.addEventListener("scroll",this.throttledScroll,{passive:true}),window.addEventListener("tracker:navigate",this.handleNavigate);}destroy(){document.removeEventListener("mousemove",this.throttledMouseMove),document.removeEventListener("click",this.handleClick),document.removeEventListener("touchend",this.handleTouchEnd),window.removeEventListener("scroll",this.throttledScroll),window.removeEventListener("tracker:navigate",this.handleNavigate);}canRecord(){var t;return this.allowedPaths!==null&&!this.allowedPaths.has(this.currentPath)?false:((t=this.pointCounts[this.currentPath])!=null?t:0)<this.maxPoints}recordPoint(t){var e;this.canRecord()&&(this.pointCounts[this.currentPath]=((e=this.pointCounts[this.currentPath])!=null?e:0)+1,this.emit({type:"heatmap",data:{...t,path:this.currentPath,timestamp:Date.now()}}));}getClickTarget(t){var n,s,r,l;let e=t.target;return e&&(e.getAttribute("aria-label")||((n=e.closest("[aria-label]"))==null?void 0:n.getAttribute("aria-label"))||e.getAttribute("data-track-label")||e.getAttribute("id")||(e instanceof HTMLButtonElement||e instanceof HTMLAnchorElement?(s=e.innerText)==null?void 0:s.trim().slice(0,60):(l=(r=e.closest("button, a"))==null?void 0:r.textContent)==null?void 0:l.trim().slice(0,60)))||void 0}checkRageClick(t,e,i){let n=Date.now();this.recentClicks=this.recentClicks.filter(r=>n-r.t<o.RAGE_WINDOW_MS),this.recentClicks.push({x:t,y:e,t:n});let s=this.recentClicks.filter(r=>Math.hypot(r.x-t,r.y-e)<=o.RAGE_RADIUS_PX);s.length>=o.RAGE_THRESHOLD&&(this.emit({type:"rageclik",data:{path:i,x:t,y:e,count:s.length,timestamp:n,sessionId:this.sessionId}}),this.recentClicks=[]);}};o.RAGE_THRESHOLD=3,o.RAGE_WINDOW_MS=1e3,o.RAGE_RADIUS_PX=50;var g=o;var c=class{constructor(t){this.prevOnError=null;this.prevOnUnhandledRejection=null;this.initialized=false;try{let e=new URL(t.endpoint),i=e.pathname.replace(/\/$/,"").split("/");i.pop(),e.pathname=i.join("/")||"/",this.endpoint=e.toString().replace(/\/$/,"");}catch(e){this.endpoint=t.endpoint;}this.sessionId=t.sessionId,this.appId=t.appId,this.authHeaders=t.secretKey?{Authorization:`Bearer ${t.secretKey}`}:{};}init(){typeof window=="undefined"||this.initialized||(this.origInfo=console.info.bind(console),this.origWarn=console.warn.bind(console),this.origError=console.error.bind(console),console.info=(...t)=>{this.origInfo(...t),this.send("info",this.format(t));},console.warn=(...t)=>{this.origWarn(...t),this.send("warn",this.format(t));},console.error=(...t)=>{this.origError(...t);let[e]=t,i=e instanceof Error?e.stack:void 0;this.send("error",this.format(t),{stack:i});},this.prevOnError=window.onerror,window.onerror=(t,e,i,n,s)=>(this.send("error",String(t),{stack:s==null?void 0:s.stack,meta:{src:e,line:i,col:n}}),typeof this.prevOnError=="function"?this.prevOnError(t,e,i,n,s):false),this.prevOnUnhandledRejection=t=>{let e=t.reason,i=e instanceof Error?e.message:String(e!=null?e:"Unhandled promise rejection");this.send("error",i,{stack:e instanceof Error?e.stack:void 0});},window.addEventListener("unhandledrejection",this.prevOnUnhandledRejection),this.initialized=true);}destroy(){this.initialized&&(console.info=this.origInfo,console.warn=this.origWarn,console.error=this.origError,window.onerror=this.prevOnError,this.prevOnUnhandledRejection&&window.removeEventListener("unhandledrejection",this.prevOnUnhandledRejection),this.initialized=false);}capture(t,e,i){this.send(t,e,i);}format(t){return t.map(e=>{if(e instanceof Error)return e.message;if(typeof e=="object")try{return JSON.stringify(e)}catch(i){return String(e)}return String(e)}).join(" ")}send(t,e,i){let n={sessionId:this.sessionId,...this.appId?{appId:this.appId}:{},level:t,message:e,url:typeof window!="undefined"?window.location.href:void 0,stack:i==null?void 0:i.stack,meta:i==null?void 0:i.meta,timestamp:Date.now()},s=`${this.endpoint}/logs/ingest`,r=JSON.stringify(n);fetch(s,{method:"POST",headers:{"Content-Type":"application/json",...this.authHeaders},body:r,keepalive:true}).catch(l=>{this.origError&&this.origError("[user-tracker] Failed to send log:",l);});}};var k="https://api.alphana.ir/api/events",I={endpoint:k,trackNavigation:true,trackTime:true,trackHeatmap:true,trackLogs:true,mouseSampleRate:.3,maxHeatmapPoints:2e3,batchSize:20,flushInterval:5e3},m=class{constructor(t={}){this.initialized=false;this.subscribers=new Set;this.queue=[];this.flushTimer=null;this.heartbeatTimer=null;this.userProperties={};this.flags={};this.flagSubscribers=new Set;this.handleVisibilityChange=()=>{document.visibilityState==="hidden"&&(this.queue.length>0&&this.flushBeacon(),this.sendDeactivate());};this.handlePageHide=()=>{this.queue.length>0&&this.flushBeacon(),this.sendDeactivate();};this.handleNavigate=t=>{};var e;this.cfg={...I,...t};try{new URL(this.cfg.endpoint);}catch(i){throw new Error(`[alpha-tracker] Invalid endpoint URL: "${this.cfg.endpoint}"`)}this.session={id:(e=t.sessionId)!=null?e:d(),visitorId:y(),startedAt:Date.now(),pageViews:[],timeSpent:{},heatmap:{}};}init(){if(typeof window=="undefined"||this.initialized)return this;let t=this.emit.bind(this),{id:e}=this.session;return this.cfg.trackNavigation&&(this.navigation=new p({emit:t,sessionId:e}),this.navigation.init()),this.cfg.trackTime&&(this.time=new u({emit:t,sessionId:e}),this.time.init()),this.cfg.trackHeatmap&&(this.heatmap=new g({emit:t,sessionId:e,sampleRate:this.cfg.mouseSampleRate,maxPoints:this.cfg.maxHeatmapPoints,allowedPaths:this.cfg.heatmapPages}),this.heatmap.init()),this.cfg.endpoint&&(this.flushTimer=setInterval(()=>{this.queue.length>0&&this.flushQueue();},this.cfg.flushInterval),window.addEventListener("visibilitychange",this.handleVisibilityChange),window.addEventListener("pagehide",this.handlePageHide),this.heartbeatTimer=setInterval(()=>{document.visibilityState!=="hidden"&&this.sendHeartbeat();},3e4),this.cfg.trackLogs&&(this.logCapture=new c({endpoint:this.cfg.endpoint,sessionId:this.session.id,secretKey:this.cfg.secretKey,appId:this.cfg.appId}),this.logCapture.init())),this.initialized=true,this.fetchFlags(),this}destroy(){var t,e,i,n;this.flushTimer!==null&&(clearInterval(this.flushTimer),this.flushTimer=null),this.heartbeatTimer!==null&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null),typeof window!="undefined"&&(window.removeEventListener("visibilitychange",this.handleVisibilityChange),window.removeEventListener("pagehide",this.handlePageHide)),(t=this.navigation)==null||t.destroy(),(e=this.time)==null||e.destroy(),(i=this.heatmap)==null||i.destroy(),(n=this.logCapture)==null||n.destroy(),typeof window!="undefined"&&window.removeEventListener("tracker:navigate",this.handleNavigate),this.queue.length>0&&this.cfg.endpoint&&this.flushBeacon(),this.initialized=false;}async sendHeartbeat(){if(!this.cfg.endpoint)return;let t=`${this.cfg.endpoint}/heartbeat`,e=this.cfg.secretKey?{Authorization:`Bearer ${this.cfg.secretKey}`}:{},i=JSON.stringify({sessionId:this.session.id,visitorId:this.session.visitorId,path:typeof window!="undefined"?window.location.pathname:"/",active:true,...this.cfg.appId?{appId:this.cfg.appId}:{}});try{await fetch(t,{method:"POST",headers:{"Content-Type":"application/json",...e},body:i,keepalive:!0});}catch(n){}}sendDeactivate(){if(!this.cfg.endpoint)return;let t=`${this.cfg.endpoint}/heartbeat`,e=this.cfg.secretKey?{Authorization:`Bearer ${this.cfg.secretKey}`}:{},i=JSON.stringify({sessionId:this.session.id,path:typeof window!="undefined"?window.location.pathname:"/",active:false,...this.cfg.appId?{appId:this.cfg.appId}:{}});typeof navigator!="undefined"&&navigator.sendBeacon?navigator.sendBeacon(t,new Blob([i],{type:"application/json"})):fetch(t,{method:"POST",headers:{"Content-Type":"application/json",...e},body:i,keepalive:true}).catch(()=>{});}emit(t){var e,i,n;switch(t.type){case "pageview":this.session.pageViews.push(t.data);break;case "timespent":{let s=(e=this.session.timeSpent[t.data.path])!=null?e:0;this.session.timeSpent[t.data.path]=s+t.data.duration;break}case "heatmap":{let s=t.data.path;this.session.heatmap[s]||(this.session.heatmap[s]=[]);let r=this.session.heatmap[s];r.length<this.cfg.maxHeatmapPoints&&r.push(t.data);break}}this.subscribers.forEach(s=>s(t)),(n=(i=this.cfg).onEvent)==null||n.call(i,t),this.cfg.endpoint&&(this.queue.push(t),this.queue.length>=this.cfg.batchSize&&this.flushQueue());}subscribe(t){return this.subscribers.add(t),()=>this.subscribers.delete(t)}trackPageView(t){let e=t!=null?t:typeof window!="undefined"?window.location.pathname+window.location.search:"/";this.emit({type:"pageview",data:{path:e,title:typeof document!="undefined"?document.title:"",timestamp:Date.now(),sessionId:this.session.id,referrer:typeof document!="undefined"&&document.referrer||void 0}}),typeof window!="undefined"&&window.dispatchEvent(new CustomEvent("tracker:navigate",{detail:{path:e,title:document.title}}));}identify(t){this.userProperties={...this.userProperties,...t},this.fetchFlags();}getFlags(){return {...this.flags}}isFeatureEnabled(t){return this.flags[t]===true}onFlagsChange(t){return this.flagSubscribers.add(t),()=>this.flagSubscribers.delete(t)}async fetchFlags(){if(!this.cfg.endpoint||!this.cfg.secretKey)return;let t=this.cfg.endpoint.replace(/\/events$/,"")+"/feature-flags/evaluate";try{let e=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.cfg.secretKey}`},body:JSON.stringify({userProperties:this.userProperties})});if(!e.ok)return;let i=await e.json();this.flags=i,this.flagSubscribers.forEach(n=>n({...this.flags}));}catch(e){}}getSession(){return this.session}getPageViews(){return [...this.session.pageViews]}getTimeSpent(){return {...this.session.timeSpent}}getHeatmapData(t){var e;return t!==void 0?[...(e=this.session.heatmap[t])!=null?e:[]]:Object.entries(this.session.heatmap).reduce((i,[n,s])=>(i[n]=[...s],i),{})}flush(){this.flushQueue();}async flushQueue(){if(this.queue.length===0)return;let t=this.queue.splice(0);await this.sendBatch(t);}flushBeacon(){if(this.queue.length===0)return;let t=this.queue.splice(0),e=`${this.cfg.endpoint}/batch`,i=new Blob([this.buildBatchBody(t)],{type:"application/json"});typeof navigator!="undefined"&&navigator.sendBeacon?navigator.sendBeacon(e,i):this.sendBatch(t);}buildBatchBody(t){return JSON.stringify({...this.cfg.appId?{appId:this.cfg.appId}:{},visitorId:this.session.visitorId,events:t.map(e=>({sessionId:this.session.id,type:e.type,data:e.data}))})}async sendBatch(t){let e=`${this.cfg.endpoint}/batch`,i=this.cfg.secretKey?{Authorization:`Bearer ${this.cfg.secretKey}`}:{};try{await fetch(e,{method:"POST",headers:{"Content-Type":"application/json",...i},body:this.buildBatchBody(t),keepalive:!0});}catch(n){}}};
2
- exports.DEFAULT_ENDPOINT=k;exports.LogCapture=c;exports.UserTracker=m;//# sourceMappingURL=index.js.map
1
+ 'use strict';var tt=(t=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(t,{get:(e,r)=>(typeof require!="undefined"?require:e)[r]}):t)(function(t){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});function rt(t){return t.replace(/\/events\/?$/,"")}var wt="__ut_vid__";function we(){return typeof crypto!="undefined"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>{let e=Math.random()*16|0;return (t==="x"?e:e&3|8).toString(16)})}function At(){if(typeof localStorage=="undefined")return we();try{let t=localStorage.getItem(wt);if(t)return t;let e=we();return localStorage.setItem(wt,e),e}catch(t){return we()}}function R(t){if(!t)return t;let e=t.indexOf("?"),r=e>=0?t.slice(0,e):t,i=e>=0?t.slice(e):"",n=r;for(let a=0;a<5;a++)try{let s=decodeURIComponent(n);if(s===n)break;n=s;}catch(s){break}let o=i;for(let a=0;a<5;a++)try{let s=decodeURIComponent(o);if(s===o)break;o=s;}catch(s){break}return n+o}var Rt="__ut_last_pv_path__",Et="__ut_last_pv_entry_ms__";function kt(t){if(typeof sessionStorage=="undefined")return null;try{return sessionStorage.getItem(t)}catch(e){return null}}function Tt(t,e){if(typeof sessionStorage!="undefined")try{sessionStorage.setItem(t,e);}catch(r){}}function pr(t,e){Tt(Rt,t),Tt(Et,String(e));}function fr(){if(typeof performance=="undefined")return;let e=performance.getEntriesByType("navigation")[0];if(e!=null&&e.type)return e.type;let r=performance.navigation;if((r==null?void 0:r.type)===2)return "back_forward"}var Ae=class Ae{constructor({emit:e,sessionId:r}){this.previousPath="";this.originalPushState=null;this.originalReplaceState=null;this.pageEntryTime=0;this.handlePopState=()=>{this.handleNavigation();};this.emit=e,this.sessionId=r;}init(){let e=R(window.location.pathname+window.location.search);fr()==="back_forward"&&this.tryEmitMpaHistoryTraversalUturn(e),this.recordPageView(e),window.addEventListener("popstate",this.handlePopState),this.originalPushState=history.pushState.bind(history);let r=this.originalPushState;history.pushState=(n,o,a)=>{r(n,o,a),this.handleNavigation();},this.originalReplaceState=history.replaceState.bind(history);let i=this.originalReplaceState;history.replaceState=(n,o,a)=>{i(n,o,a),this.handleNavigation();};}destroy(){window.removeEventListener("popstate",this.handlePopState),this.originalPushState&&(history.pushState=this.originalPushState),this.originalReplaceState&&(history.replaceState=this.originalReplaceState);}tryEmitMpaHistoryTraversalUturn(e){let r=kt(Rt),i=kt(Et),n=i?Number(i):0;if(!r||!Number.isFinite(n)||n<=0||R(r)===e)return;let o=Date.now()-n;o<0||o>Ae.UTURN_THRESHOLD_MS||this.emitUturn(R(r),e,o);}handleNavigation(){let e=R(window.location.pathname+window.location.search);if(e!==this.previousPath){if(this.previousPath&&this.pageEntryTime>0){let r=Date.now()-this.pageEntryTime;r<=Ae.UTURN_THRESHOLD_MS&&this.emitUturn(this.previousPath,e,r);}this.recordPageView(e);}}emitUturn(e,r,i){this.emit({type:"uturn",data:{fromPath:e,toPath:r,timeOnPageMs:i,timestamp:Date.now(),sessionId:this.sessionId}});}recordPageView(e){let r=R(e);this.previousPath=r,this.pageEntryTime=Date.now(),pr(r,this.pageEntryTime),this.emit({type:"pageview",data:{path:r,title:document.title,timestamp:Date.now(),sessionId:this.sessionId,referrer:document.referrer||void 0}}),window.dispatchEvent(new CustomEvent("tracker:navigate",{detail:{path:r,title:document.title}}));}};Ae.UTURN_THRESHOLD_MS=5e3;var Ne=Ae;var Oe=class{constructor({emit:e,sessionId:r}){this.currentPath="";this.startTime=0;this.tracking=false;this.handleNavigate=e=>{this.stopTracking(),this.currentPath=R(e.detail.path),this.startTracking();};this.handleVisibilityChange=()=>{document.hidden?this.stopTracking():this.startTracking();};this.handleUnload=()=>{this.stopTracking();};this.emit=e,this.sessionId=r;}init(){this.currentPath=R(window.location.pathname+window.location.search),this.startTracking(),window.addEventListener("tracker:navigate",this.handleNavigate),document.addEventListener("visibilitychange",this.handleVisibilityChange),window.addEventListener("beforeunload",this.handleUnload),window.addEventListener("pagehide",this.handleUnload);}destroy(){this.stopTracking(),window.removeEventListener("tracker:navigate",this.handleNavigate),document.removeEventListener("visibilitychange",this.handleVisibilityChange),window.removeEventListener("beforeunload",this.handleUnload),window.removeEventListener("pagehide",this.handleUnload);}startTracking(){this.startTime=Date.now(),this.tracking=true;}stopTracking(){if(!this.tracking||!this.currentPath)return;let e=Date.now()-this.startTime;if(e<100){this.tracking=false;return}this.emit({type:"timespent",data:{path:this.currentPath,duration:e,sessionId:this.sessionId,timestamp:Date.now()}}),this.tracking=false;}};function it(t,e){let r=0;return (...i)=>{let n=Date.now();n-r>=e&&(r=n,t(...i));}}var ae=class ae{constructor({emit:e,sessionId:r,sampleRate:i=.3,maxPoints:n=2e3,allowedPaths:o}){this.currentPath="";this.pointCounts={};this.recentClicks=[];this.handleMouseMove=e=>{if(Math.random()>this.sampleRate)return;let r=document.documentElement.scrollWidth,i=document.documentElement.scrollHeight,n=e.clientY+window.scrollY;this.recordPoint({x:e.clientX,y:n,xPct:r>0?e.clientX/r*100:0,yPct:i>0?n/i*100:0,pw:r,ph:i,type:"move"});};this.handleClick=e=>{if(Date.now()-this.lastTouchTime<500)return;let r=document.documentElement.scrollWidth,i=document.documentElement.scrollHeight,n=e.clientY+window.scrollY,o=this.getClickTarget(e);this.recordPoint({x:e.clientX,y:n,xPct:r>0?e.clientX/r*100:0,yPct:i>0?n/i*100:0,pw:r,ph:i,type:"click",...o?{target:o}:{}}),this.checkRageClick(e.clientX,n,this.currentPath);};this.lastTouchTime=0;this.handleTouchEnd=e=>{let r=e.changedTouches[0];if(!r)return;let i=document.documentElement.scrollWidth,n=document.documentElement.scrollHeight,o=r.clientY+window.scrollY;this.lastTouchTime=Date.now(),this.recordPoint({x:r.clientX,y:o,xPct:i>0?r.clientX/i*100:0,yPct:n>0?o/n*100:0,pw:i,ph:n,type:"click"}),this.checkRageClick(r.clientX,o,this.currentPath);};this.handleScroll=()=>{if(Math.random()>this.sampleRate)return;let e=document.documentElement.scrollWidth,r=document.documentElement.scrollHeight,i=window.innerWidth,n=window.scrollX,o=window.scrollY,a=n+i/2;this.recordPoint({x:i/2,y:o,xPct:e>0?a/e*100:50,yPct:r>0?o/r*100:0,pw:e,ph:r,type:"scroll"});};this.handleNavigate=e=>{this.currentPath=R(e.detail.path);};this.emit=e,this.sessionId=r,this.sampleRate=i,this.maxPoints=n,this.allowedPaths=o&&o.length>0?new Set(o.map(a=>R(a))):null,this.throttledMouseMove=it(this.handleMouseMove,50),this.throttledScroll=it(this.handleScroll,100);}init(){this.currentPath=R(window.location.pathname+window.location.search),document.addEventListener("mousemove",this.throttledMouseMove),document.addEventListener("click",this.handleClick),document.addEventListener("touchend",this.handleTouchEnd,{passive:true}),window.addEventListener("scroll",this.throttledScroll,{passive:true}),window.addEventListener("tracker:navigate",this.handleNavigate);}destroy(){document.removeEventListener("mousemove",this.throttledMouseMove),document.removeEventListener("click",this.handleClick),document.removeEventListener("touchend",this.handleTouchEnd),window.removeEventListener("scroll",this.throttledScroll),window.removeEventListener("tracker:navigate",this.handleNavigate);}canRecord(){var e;return this.allowedPaths!==null&&!this.allowedPaths.has(this.currentPath)?false:((e=this.pointCounts[this.currentPath])!=null?e:0)<this.maxPoints}recordPoint(e){var r;this.canRecord()&&(this.pointCounts[this.currentPath]=((r=this.pointCounts[this.currentPath])!=null?r:0)+1,this.emit({type:"heatmap",data:{...e,path:this.currentPath,timestamp:Date.now()}}));}getClickTarget(e){var n,o,a,s;let r=e.target;return r&&(r.getAttribute("aria-label")||((n=r.closest("[aria-label]"))==null?void 0:n.getAttribute("aria-label"))||r.getAttribute("data-track-label")||r.getAttribute("id")||(r instanceof HTMLButtonElement||r instanceof HTMLAnchorElement?(o=r.innerText)==null?void 0:o.trim().slice(0,60):(s=(a=r.closest("button, a"))==null?void 0:a.textContent)==null?void 0:s.trim().slice(0,60)))||void 0}checkRageClick(e,r,i){let n=Date.now();this.recentClicks=this.recentClicks.filter(a=>n-a.t<ae.RAGE_WINDOW_MS),this.recentClicks.push({x:e,y:r,t:n});let o=this.recentClicks.filter(a=>Math.hypot(a.x-e,a.y-r)<=ae.RAGE_RADIUS_PX);o.length>=ae.RAGE_THRESHOLD&&(this.emit({type:"rageclik",data:{path:i,x:e,y:r,count:o.length,timestamp:n,sessionId:this.sessionId}}),this.recentClicks=[]);}};ae.RAGE_THRESHOLD=3,ae.RAGE_WINDOW_MS=1e3,ae.RAGE_RADIUS_PX=50;var Le=ae;var ke=class{constructor(e){this.prevOnError=null;this.prevOnUnhandledRejection=null;this.initialized=false;try{let r=new URL(e.endpoint),i=r.pathname.replace(/\/$/,"").split("/");i.pop(),r.pathname=i.join("/")||"/",this.endpoint=r.toString().replace(/\/$/,"");}catch(r){this.endpoint=e.endpoint;}this.sessionId=e.sessionId,this.appId=e.appId,this.authHeaders=e.secretKey?{Authorization:`Bearer ${e.secretKey}`}:{};}init(){typeof window=="undefined"||this.initialized||(this.origInfo=console.info.bind(console),this.origWarn=console.warn.bind(console),this.origError=console.error.bind(console),console.info=(...e)=>{this.origInfo(...e),this.send("info",this.format(e));},console.warn=(...e)=>{this.origWarn(...e),this.send("warn",this.format(e));},console.error=(...e)=>{this.origError(...e);let[r]=e,i=r instanceof Error?r.stack:void 0;this.send("error",this.format(e),{stack:i});},this.prevOnError=window.onerror,window.onerror=(e,r,i,n,o)=>(this.send("error",String(e),{stack:o==null?void 0:o.stack,meta:{src:r,line:i,col:n}}),typeof this.prevOnError=="function"?this.prevOnError(e,r,i,n,o):false),this.prevOnUnhandledRejection=e=>{let r=e.reason,i=r instanceof Error?r.message:String(r!=null?r:"Unhandled promise rejection");this.send("error",i,{stack:r instanceof Error?r.stack:void 0});},window.addEventListener("unhandledrejection",this.prevOnUnhandledRejection),this.initialized=true);}destroy(){this.initialized&&(console.info=this.origInfo,console.warn=this.origWarn,console.error=this.origError,window.onerror=this.prevOnError,this.prevOnUnhandledRejection&&window.removeEventListener("unhandledrejection",this.prevOnUnhandledRejection),this.initialized=false);}capture(e,r,i){this.send(e,r,i);}format(e){return e.map(r=>{if(r instanceof Error)return r.message;if(typeof r=="object")try{return JSON.stringify(r)}catch(i){return String(r)}return String(r)}).join(" ")}send(e,r,i){let n={sessionId:this.sessionId,...this.appId?{appId:this.appId}:{},level:e,message:r,url:typeof window!="undefined"?window.location.href:void 0,stack:i==null?void 0:i.stack,meta:i==null?void 0:i.meta,timestamp:Date.now()},o=`${this.endpoint}/logs/ingest`,a=JSON.stringify(n);fetch(o,{method:"POST",headers:{"Content-Type":"application/json",...this.authHeaders},body:a,keepalive:true}).catch(s=>{this.origError&&this.origError("[user-tracker] Failed to send log:",s);});}};var F;(function(t){t[t.Document=0]="Document",t[t.DocumentType=1]="DocumentType",t[t.Element=2]="Element",t[t.Text=3]="Text",t[t.CDATA=4]="CDATA",t[t.Comment=5]="Comment";})(F||(F={}));function gr(t){return t.nodeType===t.ELEMENT_NODE}function pe(t){var e=t==null?void 0:t.host;return (e==null?void 0:e.shadowRoot)===t}function ue(t){return Object.prototype.toString.call(t)==="[object ShadowRoot]"}function mr(t){return t.includes(" background-clip: text;")&&!t.includes(" -webkit-background-clip: text;")&&(t=t.replace(" background-clip: text;"," -webkit-background-clip: text; background-clip: text;")),t}function nt(t){try{var e=t.rules||t.cssRules;return e?mr(Array.from(e).map(ot).join("")):null}catch(r){return null}}function ot(t){var e=t.cssText;if(vr(t))try{e=nt(t.styleSheet)||e;}catch(r){}return e}function vr(t){return "styleSheet"in t}var Nt=(function(){function t(){this.idNodeMap=new Map,this.nodeMetaMap=new WeakMap;}return t.prototype.getId=function(e){var r;if(!e)return -1;var i=(r=this.getMeta(e))===null||r===void 0?void 0:r.id;return i!=null?i:-1},t.prototype.getNode=function(e){return this.idNodeMap.get(e)||null},t.prototype.getIds=function(){return Array.from(this.idNodeMap.keys())},t.prototype.getMeta=function(e){return this.nodeMetaMap.get(e)||null},t.prototype.removeNodeFromMap=function(e){var r=this,i=this.getId(e);this.idNodeMap.delete(i),e.childNodes&&e.childNodes.forEach(function(n){return r.removeNodeFromMap(n)});},t.prototype.has=function(e){return this.idNodeMap.has(e)},t.prototype.hasNode=function(e){return this.nodeMetaMap.has(e)},t.prototype.add=function(e,r){var i=r.id;this.idNodeMap.set(i,e),this.nodeMetaMap.set(e,r);},t.prototype.replace=function(e,r){var i=this.getNode(e);if(i){var n=this.nodeMetaMap.get(i);n&&this.nodeMetaMap.set(r,n);}this.idNodeMap.set(e,r);},t.prototype.reset=function(){this.idNodeMap=new Map,this.nodeMetaMap=new WeakMap;},t})();function Ot(){return new Nt}function Re(t){var e=t.maskInputOptions,r=t.tagName,i=t.type,n=t.value,o=t.maskInputFn,a=n||"";return (e[r.toLowerCase()]||e[i])&&(o?a=o(a):a="*".repeat(a.length)),a}var Mt="__rrweb_original__";function Ir(t){var e=t.getContext("2d");if(!e)return true;for(var r=50,i=0;i<t.width;i+=r)for(var n=0;n<t.height;n+=r){var o=e.getImageData,a=Mt in o?o[Mt]:o,s=new Uint32Array(a.call(e,i,n,Math.min(r,t.width-i),Math.min(r,t.height-n)).data.buffer);if(s.some(function(c){return c!==0}))return false}return true}var yr=1,Cr=new RegExp("[^a-z0-9-_:]"),he=-2;function st(){return yr++}function Sr(t){if(t instanceof HTMLFormElement)return "form";var e=t.tagName.toLowerCase().trim();return Cr.test(e)?"div":e}function br(t){return t.cssRules?Array.from(t.cssRules).map(function(e){return e.cssText||""}).join(""):""}function wr(t){var e="";return t.indexOf("//")>-1?e=t.split("/").slice(0,3).join("/"):e=t.split("/")[0],e=e.split("?")[0],e}var ve,xt,Ar=/url\((?:(')([^']*)'|(")(.*?)"|([^)]*))\)/gm,kr=/^(?!www\.|(?:http|ftp)s?:\/\/|[A-Za-z]:\\|\/\/|#).*/,Tr=/^(data:)([^,]*),(.*)/i;function Fe(t,e){return (t||"").replace(Ar,function(r,i,n,o,a,s){var c=n||a||s,l=i||o||"";if(!c)return r;if(!kr.test(c)||Tr.test(c))return "url(".concat(l).concat(c).concat(l,")");if(c[0]==="/")return "url(".concat(l).concat(wr(e)+c).concat(l,")");var d=e.split("/"),u=c.split("/");d.pop();for(var p=0,f=u;p<f.length;p++){var h=f[p];h!=="."&&(h===".."?d.pop():d.push(h));}return "url(".concat(l).concat(d.join("/")).concat(l,")")})}var Rr=/^[^ \t\n\r\u000c]+/,Er=/^[, \t\n\r\u000c]+/;function Mr(t,e){if(e.trim()==="")return e;var r=0;function i(l){var d,u=l.exec(e.substring(r));return u?(d=u[0],r+=d.length,d):""}for(var n=[];i(Er),!(r>=e.length);){var o=i(Rr);if(o.slice(-1)===",")o=Ie(t,o.substring(0,o.length-1)),n.push(o);else {var a="";o=Ie(t,o);for(var s=false;;){var c=e.charAt(r);if(c===""){n.push((o+a).trim());break}else if(s)c===")"&&(s=false);else if(c===","){r+=1,n.push((o+a).trim());break}else c==="("&&(s=true);a+=c,r+=1;}}}return n.join(", ")}function Ie(t,e){if(!e||e.trim()==="")return e;var r=t.createElement("a");return r.href=e,r.href}function xr(t){return !!(t.tagName==="svg"||t.ownerSVGElement)}function at(){var t=document.createElement("a");return t.href="",t.href}function ct(t,e,r,i){return r==="src"||r==="href"&&i&&!(e==="use"&&i[0]==="#")||r==="xlink:href"&&i&&i[0]!=="#"||r==="background"&&i&&(e==="table"||e==="td"||e==="th")?Ie(t,i):r==="srcset"&&i?Mr(t,i):r==="style"&&i?Fe(i,at()):e==="object"&&r==="data"&&i?Ie(t,i):i}function Nr(t,e,r){if(typeof e=="string"){if(t.classList.contains(e))return true}else for(var i=t.classList.length;i--;){var n=t.classList[i];if(e.test(n))return true}return r?t.matches(r):false}function Te(t,e,r){if(!t)return false;if(t.nodeType!==t.ELEMENT_NODE)return r?Te(t.parentNode,e,r):false;for(var i=t.classList.length;i--;){var n=t.classList[i];if(e.test(n))return true}return r?Te(t.parentNode,e,r):false}function lt(t,e,r){var i=t.nodeType===t.ELEMENT_NODE?t:t.parentElement;if(i===null)return false;if(typeof e=="string"){if(i.classList.contains(e)||i.closest(".".concat(e)))return true}else if(Te(i,e,true))return true;return !!(r&&(i.matches(r)||i.closest(r)))}function Or(t,e,r){var i=t.contentWindow;if(i){var n=false,o;try{o=i.document.readyState;}catch(c){return}if(o!=="complete"){var a=setTimeout(function(){n||(e(),n=true);},r);t.addEventListener("load",function(){clearTimeout(a),n=true,e();});return}var s="about:blank";if(i.location.href!==s||t.src===s||t.src==="")return setTimeout(e,0),t.addEventListener("load",e);t.addEventListener("load",e);}}function Lr(t,e,r){var i=false,n;try{n=t.sheet;}catch(a){return}if(!n){var o=setTimeout(function(){i||(e(),i=true);},r);t.addEventListener("load",function(){clearTimeout(o),i=true,e();});}}function Fr(t,e){var r=e.doc,i=e.mirror,n=e.blockClass,o=e.blockSelector,a=e.maskTextClass,s=e.maskTextSelector,c=e.inlineStylesheet,l=e.maskInputOptions,d=l===void 0?{}:l,u=e.maskTextFn,p=e.maskInputFn,f=e.dataURLOptions,h=f===void 0?{}:f,v=e.inlineImages,C=e.recordCanvas,I=e.keepIframeSrcFn,g=e.newlyAddedElement,m=g===void 0?false:g,A=Dr(r,i);switch(t.nodeType){case t.DOCUMENT_NODE:return t.compatMode!=="CSS1Compat"?{type:F.Document,childNodes:[],compatMode:t.compatMode}:{type:F.Document,childNodes:[]};case t.DOCUMENT_TYPE_NODE:return {type:F.DocumentType,name:t.name,publicId:t.publicId,systemId:t.systemId,rootId:A};case t.ELEMENT_NODE:return Pr(t,{doc:r,blockClass:n,blockSelector:o,inlineStylesheet:c,maskInputOptions:d,maskInputFn:p,dataURLOptions:h,inlineImages:v,recordCanvas:C,keepIframeSrcFn:I,newlyAddedElement:m,rootId:A});case t.TEXT_NODE:return Wr(t,{maskTextClass:a,maskTextSelector:s,maskTextFn:u,rootId:A});case t.CDATA_SECTION_NODE:return {type:F.CDATA,textContent:"",rootId:A};case t.COMMENT_NODE:return {type:F.Comment,textContent:t.textContent||"",rootId:A};default:return false}}function Dr(t,e){if(e.hasNode(t)){var r=e.getId(t);return r===1?void 0:r}}function Wr(t,e){var r,i=e.maskTextClass,n=e.maskTextSelector,o=e.maskTextFn,a=e.rootId,s=t.parentNode&&t.parentNode.tagName,c=t.textContent,l=s==="STYLE"?true:void 0,d=s==="SCRIPT"?true:void 0;if(l&&c){try{t.nextSibling||t.previousSibling||!((r=t.parentNode.sheet)===null||r===void 0)&&r.cssRules&&(c=br(t.parentNode.sheet));}catch(u){console.warn("Cannot get CSS styles from text's parentNode. Error: ".concat(u),t);}c=Fe(c,at());}return d&&(c="SCRIPT_PLACEHOLDER"),!l&&!d&&c&&lt(t,i,n)&&(c=o?o(c):c.replace(/[\S]/g,"*")),{type:F.Text,textContent:c||"",isStyle:l,rootId:a}}function Pr(t,e){for(var r=e.doc,i=e.blockClass,n=e.blockSelector,o=e.inlineStylesheet,a=e.maskInputOptions,s=a===void 0?{}:a,c=e.maskInputFn,l=e.dataURLOptions,d=l===void 0?{}:l,u=e.inlineImages,p=e.recordCanvas,f=e.keepIframeSrcFn,h=e.newlyAddedElement,v=h===void 0?false:h,C=e.rootId,I=Nr(t,i,n),g=Sr(t),m={},A=t.attributes.length,B=0;B<A;B++){var D=t.attributes[B];m[D.name]=ct(r,g,D.name,D.value);}if(g==="link"&&o){var W=Array.from(r.styleSheets).find(function(Y){return Y.href===t.href}),k=null;W&&(k=nt(W)),k&&(delete m.rel,delete m.href,m._cssText=Fe(k,W.href));}if(g==="style"&&t.sheet&&!(t.innerText||t.textContent||"").trim().length){var k=nt(t.sheet);k&&(m._cssText=Fe(k,at()));}if(g==="input"||g==="textarea"||g==="select"){var Z=t.value,K=t.checked;m.type!=="radio"&&m.type!=="checkbox"&&m.type!=="submit"&&m.type!=="button"&&Z?m.value=Re({type:m.type,tagName:g,value:Z,maskInputOptions:s,maskInputFn:c}):K&&(m.checked=K);}if(g==="option"&&(t.selected&&!s.select?m.selected=true:delete m.selected),g==="canvas"&&p){if(t.__context==="2d")Ir(t)||(m.rr_dataURL=t.toDataURL(d.type,d.quality));else if(!("__context"in t)){var Q=t.toDataURL(d.type,d.quality),j=document.createElement("canvas");j.width=t.width,j.height=t.height;var X=j.toDataURL(d.type,d.quality);Q!==X&&(m.rr_dataURL=Q);}}if(g==="img"&&u){ve||(ve=r.createElement("canvas"),xt=ve.getContext("2d"));var O=t,z=O.crossOrigin;O.crossOrigin="anonymous";var q=function(){try{ve.width=O.naturalWidth,ve.height=O.naturalHeight,xt.drawImage(O,0,0),m.rr_dataURL=ve.toDataURL(d.type,d.quality);}catch(Y){console.warn("Cannot inline img src=".concat(O.currentSrc,"! Error: ").concat(Y));}z?m.crossOrigin=z:O.removeAttribute("crossorigin");};O.complete&&O.naturalWidth!==0?q():O.onload=q;}if((g==="audio"||g==="video")&&(m.rr_mediaState=t.paused?"paused":"played",m.rr_mediaCurrentTime=t.currentTime),v||(t.scrollLeft&&(m.rr_scrollLeft=t.scrollLeft),t.scrollTop&&(m.rr_scrollTop=t.scrollTop)),I){var re=t.getBoundingClientRect(),ne=re.width,G=re.height;m={class:m.class,rr_width:"".concat(ne,"px"),rr_height:"".concat(G,"px")};}return g==="iframe"&&!f(m.src)&&(t.contentDocument||(m.rr_src=m.src),delete m.src),{type:F.Element,tagName:g,attributes:m,childNodes:[],isSVG:xr(t)||void 0,needBlock:I,rootId:C}}function T(t){return t===void 0?"":t.toLowerCase()}function Br(t,e){if(e.comment&&t.type===F.Comment)return true;if(t.type===F.Element){if(e.script&&(t.tagName==="script"||t.tagName==="link"&&t.attributes.rel==="preload"&&t.attributes.as==="script"||t.tagName==="link"&&t.attributes.rel==="prefetch"&&typeof t.attributes.href=="string"&&t.attributes.href.endsWith(".js")))return true;if(e.headFavicon&&(t.tagName==="link"&&t.attributes.rel==="shortcut icon"||t.tagName==="meta"&&(T(t.attributes.name).match(/^msapplication-tile(image|color)$/)||T(t.attributes.name)==="application-name"||T(t.attributes.rel)==="icon"||T(t.attributes.rel)==="apple-touch-icon"||T(t.attributes.rel)==="shortcut icon")))return true;if(t.tagName==="meta"){if(e.headMetaDescKeywords&&T(t.attributes.name).match(/^description|keywords$/))return true;if(e.headMetaSocial&&(T(t.attributes.property).match(/^(og|twitter|fb):/)||T(t.attributes.name).match(/^(og|twitter):/)||T(t.attributes.name)==="pinterest"))return true;if(e.headMetaRobots&&(T(t.attributes.name)==="robots"||T(t.attributes.name)==="googlebot"||T(t.attributes.name)==="bingbot"))return true;if(e.headMetaHttpEquiv&&t.attributes["http-equiv"]!==void 0)return true;if(e.headMetaAuthorship&&(T(t.attributes.name)==="author"||T(t.attributes.name)==="generator"||T(t.attributes.name)==="framework"||T(t.attributes.name)==="publisher"||T(t.attributes.name)==="progid"||T(t.attributes.property).match(/^article:/)||T(t.attributes.property).match(/^product:/)))return true;if(e.headMetaVerification&&(T(t.attributes.name)==="google-site-verification"||T(t.attributes.name)==="yandex-verification"||T(t.attributes.name)==="csrf-token"||T(t.attributes.name)==="p:domain_verify"||T(t.attributes.name)==="verify-v1"||T(t.attributes.name)==="verification"||T(t.attributes.name)==="shopify-checkout-api-token"))return true}}return false}function de(t,e){var r=e.doc,i=e.mirror,n=e.blockClass,o=e.blockSelector,a=e.maskTextClass,s=e.maskTextSelector,c=e.skipChild,l=c===void 0?false:c,d=e.inlineStylesheet,u=d===void 0?true:d,p=e.maskInputOptions,f=p===void 0?{}:p,h=e.maskTextFn,v=e.maskInputFn,C=e.slimDOMOptions,I=e.dataURLOptions,g=I===void 0?{}:I,m=e.inlineImages,A=m===void 0?false:m,B=e.recordCanvas,D=B===void 0?false:B,W=e.onSerialize,k=e.onIframeLoad,Z=e.iframeLoadTimeout,K=Z===void 0?5e3:Z,Q=e.onStylesheetLoad,j=e.stylesheetLoadTimeout,X=j===void 0?5e3:j,O=e.keepIframeSrcFn,z=O===void 0?function(){return false}:O,q=e.newlyAddedElement,re=q===void 0?false:q,ne=e.preserveWhiteSpace,G=ne===void 0?true:ne,Y=Fr(t,{doc:r,mirror:i,blockClass:n,blockSelector:o,maskTextClass:a,maskTextSelector:s,inlineStylesheet:u,maskInputOptions:f,maskTextFn:h,maskInputFn:v,dataURLOptions:g,inlineImages:A,recordCanvas:D,keepIframeSrcFn:z,newlyAddedElement:re});if(!Y)return console.warn(t,"not serialized"),null;var se;i.hasNode(t)?se=i.getId(t):Br(Y,C)||!G&&Y.type===F.Text&&!Y.isStyle&&!Y.textContent.replace(/^\s+|\s+$/gm,"").length?se=he:se=st();var N=Object.assign(Y,{id:se});if(i.add(t,N),se===he)return null;W&&W(t);var $=!l;if(N.type===F.Element){$=$&&!N.needBlock,delete N.needBlock;var ie=t.shadowRoot;ie&&ue(ie)&&(N.isShadowHost=true);}if((N.type===F.Document||N.type===F.Element)&&$){C.headWhitespace&&N.type===F.Element&&N.tagName==="head"&&(G=false);for(var me={doc:r,mirror:i,blockClass:n,blockSelector:o,maskTextClass:a,maskTextSelector:s,skipChild:l,inlineStylesheet:u,maskInputOptions:f,maskTextFn:h,maskInputFn:v,slimDOMOptions:C,dataURLOptions:g,inlineImages:A,recordCanvas:D,preserveWhiteSpace:G,onSerialize:W,onIframeLoad:k,iframeLoadTimeout:K,onStylesheetLoad:Q,stylesheetLoadTimeout:X,keepIframeSrcFn:z},y=0,V=Array.from(t.childNodes);y<V.length;y++){var U=V[y],E=de(U,me);E&&N.childNodes.push(E);}if(gr(t)&&t.shadowRoot)for(var J=0,w=Array.from(t.shadowRoot.childNodes);J<w.length;J++){var U=w[J],E=de(U,me);E&&(ue(t.shadowRoot)&&(E.isShadow=true),N.childNodes.push(E));}}return t.parentNode&&pe(t.parentNode)&&ue(t.parentNode)&&(N.isShadow=true),N.type===F.Element&&N.tagName==="iframe"&&Or(t,function(){var H=t.contentDocument;if(H&&k){var be=de(H,{doc:H,mirror:i,blockClass:n,blockSelector:o,maskTextClass:a,maskTextSelector:s,skipChild:false,inlineStylesheet:u,maskInputOptions:f,maskTextFn:h,maskInputFn:v,slimDOMOptions:C,dataURLOptions:g,inlineImages:A,recordCanvas:D,preserveWhiteSpace:G,onSerialize:W,onIframeLoad:k,iframeLoadTimeout:K,onStylesheetLoad:Q,stylesheetLoadTimeout:X,keepIframeSrcFn:z});be&&k(t,be);}},K),N.type===F.Element&&N.tagName==="link"&&N.attributes.rel==="stylesheet"&&Lr(t,function(){if(Q){var H=de(t,{doc:r,mirror:i,blockClass:n,blockSelector:o,maskTextClass:a,maskTextSelector:s,skipChild:false,inlineStylesheet:u,maskInputOptions:f,maskTextFn:h,maskInputFn:v,slimDOMOptions:C,dataURLOptions:g,inlineImages:A,recordCanvas:D,preserveWhiteSpace:G,onSerialize:W,onIframeLoad:k,iframeLoadTimeout:K,onStylesheetLoad:Q,stylesheetLoadTimeout:X,keepIframeSrcFn:z});H&&Q(t,H);}},X),N}function Lt(t,e){var r=e||{},i=r.mirror,n=i===void 0?new Nt:i,o=r.blockClass,a=o===void 0?"rr-block":o,s=r.blockSelector,c=s===void 0?null:s,l=r.maskTextClass,d=l===void 0?"rr-mask":l,u=r.maskTextSelector,p=u===void 0?null:u,f=r.inlineStylesheet,h=f===void 0?true:f,v=r.inlineImages,C=v===void 0?false:v,I=r.recordCanvas,g=I===void 0?false:I,m=r.maskAllInputs,A=m===void 0?false:m,B=r.maskTextFn,D=r.maskInputFn,W=r.slimDOM,k=W===void 0?false:W,Z=r.dataURLOptions,K=r.preserveWhiteSpace,Q=r.onSerialize,j=r.onIframeLoad,X=r.iframeLoadTimeout,O=r.onStylesheetLoad,z=r.stylesheetLoadTimeout,q=r.keepIframeSrcFn,re=q===void 0?function(){return false}:q,ne=A===true?{color:true,date:true,"datetime-local":true,email:true,month:true,number:true,range:true,search:true,tel:true,text:true,time:true,url:true,week:true,textarea:true,select:true,password:true}:A===false?{password:true}:A,G=k===true||k==="all"?{script:true,comment:true,headFavicon:true,headWhitespace:true,headMetaDescKeywords:k==="all",headMetaSocial:true,headMetaRobots:true,headMetaHttpEquiv:true,headMetaAuthorship:true,headMetaVerification:true}:k===false?{}:k;return de(t,{doc:t,mirror:n,blockClass:a,blockSelector:c,maskTextClass:d,maskTextSelector:p,skipChild:false,inlineStylesheet:h,maskInputOptions:ne,maskTextFn:B,maskInputFn:D,slimDOMOptions:G,dataURLOptions:Z,inlineImages:C,recordCanvas:g,preserveWhiteSpace:K,onSerialize:Q,onIframeLoad:j,iframeLoadTimeout:X,onStylesheetLoad:O,stylesheetLoadTimeout:z,keepIframeSrcFn:re,newlyAddedElement:false})}function P(t,e,r=document){let i={capture:true,passive:true};return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}var ye=`Please stop import mirror directly. Instead of that,\r
2
+ now you can use replayer.getMirror() to access the mirror instance of a replayer,\r
3
+ or you can use record.mirror to access the mirror instance during recording.`,Ft={map:{},getId(){return console.error(ye),-1},getNode(){return console.error(ye),null},removeNodeFromMap(){console.error(ye);},has(){return console.error(ye),false},reset(){console.error(ye);}};typeof window!="undefined"&&window.Proxy&&window.Reflect&&(Ft=new Proxy(Ft,{get(t,e,r){return e==="map"&&console.error(ye),Reflect.get(t,e,r)}}));function Ce(t,e,r={}){let i=null,n=0;return function(...o){let a=Date.now();!n&&r.leading===false&&(n=a);let s=e-(a-n),c=this;s<=0||s>e?(i&&(clearTimeout(i),i=null),n=a,t.apply(c,o)):!i&&r.trailing!==false&&(i=setTimeout(()=>{n=r.leading===false?0:Date.now(),i=null,t.apply(c,o);},s));}}function fe(t,e,r,i,n=window){let o=n.Object.getOwnPropertyDescriptor(t,e);return n.Object.defineProperty(t,e,i?r:{set(a){setTimeout(()=>{r.set.call(this,a);},0),o&&o.set&&o.set.call(this,a);}}),()=>fe(t,e,o||{},true)}function ee(t,e,r){try{if(!(e in t))return ()=>{};let i=t[e],n=r(i);return typeof n=="function"&&(n.prototype=n.prototype||{},Object.defineProperties(n,{__rrweb_original__:{enumerable:!1,value:i}})),t[e]=n,()=>{t[e]=i;}}catch(i){return ()=>{}}}function We(){return window.innerHeight||document.documentElement&&document.documentElement.clientHeight||document.body&&document.body.clientHeight}function Pe(){return window.innerWidth||document.documentElement&&document.documentElement.clientWidth||document.body&&document.body.clientWidth}function M(t,e,r,i){if(!t)return false;let n=t.nodeType===t.ELEMENT_NODE?t:t.parentElement;if(!n)return false;if(typeof e=="string"){if(n.classList.contains(e)||i&&n.closest("."+e)!==null)return true}else if(Te(n,e,i))return true;return !!(r&&(t.matches(r)||i&&n.closest(r)!==null))}function Dt(t,e){return e.getId(t)!==-1}function Be(t,e){return e.getId(t)===he}function dt(t,e){if(pe(t))return false;let r=e.getId(t);return e.has(r)?t.parentNode&&t.parentNode.nodeType===t.DOCUMENT_NODE?false:t.parentNode?dt(t.parentNode,e):true:true}function ut(t){return !!t.changedTouches}function Wt(t=window){"NodeList"in t&&!t.NodeList.prototype.forEach&&(t.NodeList.prototype.forEach=Array.prototype.forEach),"DOMTokenList"in t&&!t.DOMTokenList.prototype.forEach&&(t.DOMTokenList.prototype.forEach=Array.prototype.forEach),Node.prototype.contains||(Node.prototype.contains=(...e)=>{let r=e[0];if(!(0 in e))throw new TypeError("1 argument is required");do if(this===r)return true;while(r=r&&r.parentNode);return false});}function Ve(t,e){return !!(t.nodeName==="IFRAME"&&e.getMeta(t))}function _e(t,e){return !!(t.nodeName==="LINK"&&t.nodeType===t.ELEMENT_NODE&&t.getAttribute&&t.getAttribute("rel")==="stylesheet"&&e.getMeta(t))}function Ge(t){return !!(t!=null&&t.shadowRoot)}var De=class{constructor(){this.id=1,this.styleIDMap=new WeakMap,this.idStyleMap=new Map;}getId(e){var r;return (r=this.styleIDMap.get(e))!==null&&r!==void 0?r:-1}has(e){return this.styleIDMap.has(e)}add(e,r){if(this.has(e))return this.getId(e);let i;return r===void 0?i=this.id++:i=r,this.styleIDMap.set(e,i),this.idStyleMap.set(i,e),i}getStyle(e){return this.idStyleMap.get(e)||null}reset(){this.styleIDMap=new WeakMap,this.idStyleMap=new Map,this.id=1;}generateId(){return this.id++}};var b=(t=>(t[t.DomContentLoaded=0]="DomContentLoaded",t[t.Load=1]="Load",t[t.FullSnapshot=2]="FullSnapshot",t[t.IncrementalSnapshot=3]="IncrementalSnapshot",t[t.Meta=4]="Meta",t[t.Custom=5]="Custom",t[t.Plugin=6]="Plugin",t))(b||{}),S=(t=>(t[t.Mutation=0]="Mutation",t[t.MouseMove=1]="MouseMove",t[t.MouseInteraction=2]="MouseInteraction",t[t.Scroll=3]="Scroll",t[t.ViewportResize=4]="ViewportResize",t[t.Input=5]="Input",t[t.TouchMove=6]="TouchMove",t[t.MediaInteraction=7]="MediaInteraction",t[t.StyleSheetRule=8]="StyleSheetRule",t[t.CanvasMutation=9]="CanvasMutation",t[t.Font=10]="Font",t[t.Log=11]="Log",t[t.Drag=12]="Drag",t[t.StyleDeclaration=13]="StyleDeclaration",t[t.Selection=14]="Selection",t[t.AdoptedStyleSheet=15]="AdoptedStyleSheet",t))(S||{}),Ue=(t=>(t[t.MouseUp=0]="MouseUp",t[t.MouseDown=1]="MouseDown",t[t.Click=2]="Click",t[t.ContextMenu=3]="ContextMenu",t[t.DblClick=4]="DblClick",t[t.Focus=5]="Focus",t[t.Blur=6]="Blur",t[t.TouchStart=7]="TouchStart",t[t.TouchMove_Departed=8]="TouchMove_Departed",t[t.TouchEnd=9]="TouchEnd",t[t.TouchCancel=10]="TouchCancel",t))(Ue||{}),oe=(t=>(t[t["2D"]=0]="2D",t[t.WebGL=1]="WebGL",t[t.WebGL2=2]="WebGL2",t))(oe||{});function Pt(t){return "__ln"in t}var ht=class{constructor(){this.length=0,this.head=null;}get(e){if(e>=this.length)throw new Error("Position outside of list range");let r=this.head;for(let i=0;i<e;i++)r=(r==null?void 0:r.next)||null;return r}addNode(e){let r={value:e,previous:null,next:null};if(e.__ln=r,e.previousSibling&&Pt(e.previousSibling)){let i=e.previousSibling.__ln.next;r.next=i,r.previous=e.previousSibling.__ln,e.previousSibling.__ln.next=r,i&&(i.previous=r);}else if(e.nextSibling&&Pt(e.nextSibling)&&e.nextSibling.__ln.previous){let i=e.nextSibling.__ln.previous;r.previous=i,r.next=e.nextSibling.__ln,e.nextSibling.__ln.previous=r,i&&(i.next=r);}else this.head&&(this.head.previous=r),r.next=this.head,this.head=r;this.length++;}removeNode(e){let r=e.__ln;this.head&&(r.previous?(r.previous.next=r.next,r.next&&(r.next.previous=r.previous)):(this.head=r.next,this.head&&(this.head.previous=null)),e.__ln&&delete e.__ln,this.length--);}},Bt=(t,e)=>`${t}@${e}`,He=class{constructor(){this.frozen=false,this.locked=false,this.texts=[],this.attributes=[],this.removes=[],this.mapRemoves=[],this.movedMap={},this.addedSet=new Set,this.movedSet=new Set,this.droppedSet=new Set,this.processMutations=e=>{e.forEach(this.processMutation),this.emit();},this.emit=()=>{if(this.frozen||this.locked)return;let e=[],r=new ht,i=s=>{let c=s,l=he;for(;l===he;)c=c&&c.nextSibling,l=c&&this.mirror.getId(c);return l},n=s=>{var c,l,d,u;let p=null;((l=(c=s.getRootNode)===null||c===void 0?void 0:c.call(s))===null||l===void 0?void 0:l.nodeType)===Node.DOCUMENT_FRAGMENT_NODE&&s.getRootNode().host&&(p=s.getRootNode().host);let f=p;for(;((u=(d=f==null?void 0:f.getRootNode)===null||d===void 0?void 0:d.call(f))===null||u===void 0?void 0:u.nodeType)===Node.DOCUMENT_FRAGMENT_NODE&&f.getRootNode().host;)f=f.getRootNode().host;let h=!this.doc.contains(s)&&(!f||!this.doc.contains(f));if(!s.parentNode||h)return;let v=pe(s.parentNode)?this.mirror.getId(p):this.mirror.getId(s.parentNode),C=i(s);if(v===-1||C===-1)return r.addNode(s);let I=de(s,{doc:this.doc,mirror:this.mirror,blockClass:this.blockClass,blockSelector:this.blockSelector,maskTextClass:this.maskTextClass,maskTextSelector:this.maskTextSelector,skipChild:true,newlyAddedElement:true,inlineStylesheet:this.inlineStylesheet,maskInputOptions:this.maskInputOptions,maskTextFn:this.maskTextFn,maskInputFn:this.maskInputFn,slimDOMOptions:this.slimDOMOptions,dataURLOptions:this.dataURLOptions,recordCanvas:this.recordCanvas,inlineImages:this.inlineImages,onSerialize:g=>{Ve(g,this.mirror)&&this.iframeManager.addIframe(g),_e(g,this.mirror)&&this.stylesheetManager.trackLinkElement(g),Ge(s)&&this.shadowDomManager.addShadowRoot(s.shadowRoot,this.doc);},onIframeLoad:(g,m)=>{this.iframeManager.attachIframe(g,m),this.shadowDomManager.observeAttachShadow(g);},onStylesheetLoad:(g,m)=>{this.stylesheetManager.attachLinkElement(g,m);}});I&&e.push({parentId:v,nextId:C,node:I});};for(;this.mapRemoves.length;)this.mirror.removeNodeFromMap(this.mapRemoves.shift());for(let s of Array.from(this.movedSet.values()))Vt(this.removes,s,this.mirror)&&!this.movedSet.has(s.parentNode)||n(s);for(let s of Array.from(this.addedSet.values()))!_t(this.droppedSet,s)&&!Vt(this.removes,s,this.mirror)||_t(this.movedSet,s)?n(s):this.droppedSet.add(s);let o=null;for(;r.length;){let s=null;if(o){let c=this.mirror.getId(o.value.parentNode),l=i(o.value);c!==-1&&l!==-1&&(s=o);}if(!s)for(let c=r.length-1;c>=0;c--){let l=r.get(c);if(l){let d=this.mirror.getId(l.value.parentNode);if(i(l.value)===-1)continue;if(d!==-1){s=l;break}else {let p=l.value;if(p.parentNode&&p.parentNode.nodeType===Node.DOCUMENT_FRAGMENT_NODE){let f=p.parentNode.host;if(this.mirror.getId(f)!==-1){s=l;break}}}}}if(!s){for(;r.head;)r.removeNode(r.head.value);break}o=s.previous,r.removeNode(s.value),n(s.value);}let a={texts:this.texts.map(s=>({id:this.mirror.getId(s.node),value:s.value})).filter(s=>this.mirror.has(s.id)),attributes:this.attributes.map(s=>({id:this.mirror.getId(s.node),attributes:s.attributes})).filter(s=>this.mirror.has(s.id)),removes:this.removes,adds:e};!a.texts.length&&!a.attributes.length&&!a.removes.length&&!a.adds.length||(this.texts=[],this.attributes=[],this.removes=[],this.addedSet=new Set,this.movedSet=new Set,this.droppedSet=new Set,this.movedMap={},this.mutationCb(a));},this.processMutation=e=>{if(!Be(e.target,this.mirror))switch(e.type){case "characterData":{let r=e.target.textContent;!M(e.target,this.blockClass,this.blockSelector,false)&&r!==e.oldValue&&this.texts.push({value:lt(e.target,this.maskTextClass,this.maskTextSelector)&&r?this.maskTextFn?this.maskTextFn(r):r.replace(/[\S]/g,"*"):r,node:e.target});break}case "attributes":{let r=e.target,i=e.target.getAttribute(e.attributeName);if(e.attributeName==="value"&&(i=Re({maskInputOptions:this.maskInputOptions,tagName:e.target.tagName,type:e.target.getAttribute("type"),value:i,maskInputFn:this.maskInputFn})),M(e.target,this.blockClass,this.blockSelector,false)||i===e.oldValue)return;let n=this.attributes.find(o=>o.node===e.target);if(r.tagName==="IFRAME"&&e.attributeName==="src"&&!this.keepIframeSrcFn(i))if(!r.contentDocument)e.attributeName="rr_src";else return;if(n||(n={node:e.target,attributes:{}},this.attributes.push(n)),e.attributeName==="style"){let o=this.doc.createElement("span");e.oldValue&&o.setAttribute("style",e.oldValue),(n.attributes.style===void 0||n.attributes.style===null)&&(n.attributes.style={});let a=n.attributes.style;for(let s of Array.from(r.style)){let c=r.style.getPropertyValue(s),l=r.style.getPropertyPriority(s);(c!==o.style.getPropertyValue(s)||l!==o.style.getPropertyPriority(s))&&(l===""?a[s]=c:a[s]=[c,l]);}for(let s of Array.from(o.style))r.style.getPropertyValue(s)===""&&(a[s]=false);}else n.attributes[e.attributeName]=ct(this.doc,r.tagName,e.attributeName,i);break}case "childList":{if(M(e.target,this.blockClass,this.blockSelector,true))return;e.addedNodes.forEach(r=>this.genAdds(r,e.target)),e.removedNodes.forEach(r=>{let i=this.mirror.getId(r),n=pe(e.target)?this.mirror.getId(e.target.host):this.mirror.getId(e.target);M(e.target,this.blockClass,this.blockSelector,false)||Be(r,this.mirror)||!Dt(r,this.mirror)||(this.addedSet.has(r)?(pt(this.addedSet,r),this.droppedSet.add(r)):this.addedSet.has(e.target)&&i===-1||dt(e.target,this.mirror)||(this.movedSet.has(r)&&this.movedMap[Bt(i,n)]?pt(this.movedSet,r):this.removes.push({parentId:n,id:i,isShadow:pe(e.target)&&ue(e.target)?true:void 0})),this.mapRemoves.push(r));});break}}},this.genAdds=(e,r)=>{if(this.mirror.hasNode(e)){if(Be(e,this.mirror))return;this.movedSet.add(e);let i=null;r&&this.mirror.hasNode(r)&&(i=this.mirror.getId(r)),i&&i!==-1&&(this.movedMap[Bt(this.mirror.getId(e),i)]=true);}else this.addedSet.add(e),this.droppedSet.delete(e);M(e,this.blockClass,this.blockSelector,false)||e.childNodes.forEach(i=>this.genAdds(i));};}init(e){["mutationCb","blockClass","blockSelector","maskTextClass","maskTextSelector","inlineStylesheet","maskInputOptions","maskTextFn","maskInputFn","keepIframeSrcFn","recordCanvas","inlineImages","slimDOMOptions","dataURLOptions","doc","mirror","iframeManager","stylesheetManager","shadowDomManager","canvasManager"].forEach(r=>{this[r]=e[r];});}freeze(){this.frozen=true,this.canvasManager.freeze();}unfreeze(){this.frozen=false,this.canvasManager.unfreeze(),this.emit();}isFrozen(){return this.frozen}lock(){this.locked=true,this.canvasManager.lock();}unlock(){this.locked=false,this.canvasManager.unlock(),this.emit();}reset(){this.shadowDomManager.reset(),this.canvasManager.reset();}};function pt(t,e){t.delete(e),e.childNodes.forEach(r=>pt(t,r));}function Vt(t,e,r){return t.length===0?false:Gt(t,e,r)}function Gt(t,e,r){let{parentNode:i}=e;if(!i)return false;let n=r.getId(i);return t.some(o=>o.id===n)?true:Gt(t,i,r)}function _t(t,e){return t.size===0?false:Ut(t,e)}function Ut(t,e){let{parentNode:r}=e;return r?t.has(r)?true:Ut(t,r):false}var le=[],Kt=typeof CSSGroupingRule!="undefined",zt=typeof CSSMediaRule!="undefined",Yt=typeof CSSSupportsRule!="undefined",Jt=typeof CSSConditionRule!="undefined";function Ee(t){try{if("composedPath"in t){let e=t.composedPath();if(e.length)return e[0]}else if("path"in t&&t.path.length)return t.path[0];return t.target}catch(e){return t.target}}function ft(t,e){var r,i;let n=new He;le.push(n),n.init(t);let o=window.MutationObserver||window.__rrMutationObserver,a=(i=(r=window==null?void 0:window.Zone)===null||r===void 0?void 0:r.__symbol__)===null||i===void 0?void 0:i.call(r,"MutationObserver");a&&window[a]&&(o=window[a]);let s=new o(n.processMutations.bind(n));return s.observe(e,{attributes:true,attributeOldValue:true,characterData:true,characterDataOldValue:true,childList:true,subtree:true}),s}function _r({mousemoveCb:t,sampling:e,doc:r,mirror:i}){if(e.mousemove===false)return ()=>{};let n=typeof e.mousemove=="number"?e.mousemove:50,o=typeof e.mousemoveCallback=="number"?e.mousemoveCallback:500,a=[],s,c=Ce(u=>{let p=Date.now()-s;t(a.map(f=>(f.timeOffset-=p,f)),u),a=[],s=null;},o),l=Ce(u=>{let p=Ee(u),{clientX:f,clientY:h}=ut(u)?u.changedTouches[0]:u;s||(s=Date.now()),a.push({x:f,y:h,id:i.getId(p),timeOffset:Date.now()-s}),c(typeof DragEvent!="undefined"&&u instanceof DragEvent?S.Drag:u instanceof MouseEvent?S.MouseMove:S.TouchMove);},n,{trailing:false}),d=[P("mousemove",l,r),P("touchmove",l,r),P("drag",l,r)];return ()=>{d.forEach(u=>u());}}function Gr({mouseInteractionCb:t,doc:e,mirror:r,blockClass:i,blockSelector:n,sampling:o}){if(o.mouseInteraction===false)return ()=>{};let a=o.mouseInteraction===true||o.mouseInteraction===void 0?{}:o.mouseInteraction,s=[],c=l=>d=>{let u=Ee(d);if(M(u,i,n,true))return;let p=ut(d)?d.changedTouches[0]:d;if(!p)return;let f=r.getId(u),{clientX:h,clientY:v}=p;t({type:Ue[l],id:f,x:h,y:v});};return Object.keys(Ue).filter(l=>Number.isNaN(Number(l))&&!l.endsWith("_Departed")&&a[l]!==false).forEach(l=>{let d=l.toLowerCase(),u=c(l);s.push(P(d,u,e));}),()=>{s.forEach(l=>l());}}function gt({scrollCb:t,doc:e,mirror:r,blockClass:i,blockSelector:n,sampling:o}){let a=Ce(s=>{let c=Ee(s);if(!c||M(c,i,n,true))return;let l=r.getId(c);if(c===e){let d=e.scrollingElement||e.documentElement;t({id:l,x:d.scrollLeft,y:d.scrollTop});}else t({id:l,x:c.scrollLeft,y:c.scrollTop});},o.scroll||100);return P("scroll",a,e)}function Ur({viewportResizeCb:t}){let e=-1,r=-1,i=Ce(()=>{let n=We(),o=Pe();(e!==n||r!==o)&&(t({width:Number(o),height:Number(n)}),e=n,r=o);},200);return P("resize",i,window)}function Ht(t,e){let r=Object.assign({},t);return e||delete r.userTriggered,r}var Hr=["INPUT","TEXTAREA","SELECT"],Zt=new WeakMap;function Zr({inputCb:t,doc:e,mirror:r,blockClass:i,blockSelector:n,ignoreClass:o,maskInputOptions:a,maskInputFn:s,sampling:c,userTriggeredOnInput:l}){function d(I){let g=Ee(I),m=I.isTrusted;if(g&&g.tagName==="OPTION"&&(g=g.parentElement),!g||!g.tagName||Hr.indexOf(g.tagName)<0||M(g,i,n,true))return;let A=g.type;if(g.classList.contains(o))return;let B=g.value,D=false;A==="radio"||A==="checkbox"?D=g.checked:(a[g.tagName.toLowerCase()]||a[A])&&(B=Re({maskInputOptions:a,tagName:g.tagName,type:A,value:B,maskInputFn:s})),u(g,Ht({text:B,isChecked:D,userTriggered:m},l));let W=g.name;A==="radio"&&W&&D&&e.querySelectorAll(`input[type="radio"][name="${W}"]`).forEach(k=>{k!==g&&u(k,Ht({text:k.value,isChecked:!D,userTriggered:false},l));});}function u(I,g){let m=Zt.get(I);if(!m||m.text!==g.text||m.isChecked!==g.isChecked){Zt.set(I,g);let A=r.getId(I);t(Object.assign(Object.assign({},g),{id:A}));}}let f=(c.input==="last"?["change"]:["input","change"]).map(I=>P(I,d,e)),h=e.defaultView;if(!h)return ()=>{f.forEach(I=>I());};let v=h.Object.getOwnPropertyDescriptor(h.HTMLInputElement.prototype,"value"),C=[[h.HTMLInputElement.prototype,"value"],[h.HTMLInputElement.prototype,"checked"],[h.HTMLSelectElement.prototype,"value"],[h.HTMLTextAreaElement.prototype,"value"],[h.HTMLSelectElement.prototype,"selectedIndex"],[h.HTMLOptionElement.prototype,"selected"]];return v&&v.set&&f.push(...C.map(I=>fe(I[0],I[1],{set(){d({target:this});}},false,h))),()=>{f.forEach(I=>I());}}function Ze(t){let e=[];function r(i,n){if(Kt&&i.parentRule instanceof CSSGroupingRule||zt&&i.parentRule instanceof CSSMediaRule||Yt&&i.parentRule instanceof CSSSupportsRule||Jt&&i.parentRule instanceof CSSConditionRule){let a=Array.from(i.parentRule.cssRules).indexOf(i);n.unshift(a);}else if(i.parentStyleSheet){let a=Array.from(i.parentStyleSheet.cssRules).indexOf(i);n.unshift(a);}return n}return r(t,e)}function ce(t,e,r){let i,n;return t?(t.ownerNode?i=e.getId(t.ownerNode):n=r.getId(t),{styleId:n,id:i}):{}}function Kr({styleSheetRuleCb:t,mirror:e,stylesheetManager:r},{win:i}){let n=i.CSSStyleSheet.prototype.insertRule;i.CSSStyleSheet.prototype.insertRule=function(d,u){let{id:p,styleId:f}=ce(this,e,r.styleMirror);return (p&&p!==-1||f&&f!==-1)&&t({id:p,styleId:f,adds:[{rule:d,index:u}]}),n.apply(this,[d,u])};let o=i.CSSStyleSheet.prototype.deleteRule;i.CSSStyleSheet.prototype.deleteRule=function(d){let{id:u,styleId:p}=ce(this,e,r.styleMirror);return (u&&u!==-1||p&&p!==-1)&&t({id:u,styleId:p,removes:[{index:d}]}),o.apply(this,[d])};let a;i.CSSStyleSheet.prototype.replace&&(a=i.CSSStyleSheet.prototype.replace,i.CSSStyleSheet.prototype.replace=function(d){let{id:u,styleId:p}=ce(this,e,r.styleMirror);return (u&&u!==-1||p&&p!==-1)&&t({id:u,styleId:p,replace:d}),a.apply(this,[d])});let s;i.CSSStyleSheet.prototype.replaceSync&&(s=i.CSSStyleSheet.prototype.replaceSync,i.CSSStyleSheet.prototype.replaceSync=function(d){let{id:u,styleId:p}=ce(this,e,r.styleMirror);return (u&&u!==-1||p&&p!==-1)&&t({id:u,styleId:p,replaceSync:d}),s.apply(this,[d])});let c={};Kt?c.CSSGroupingRule=i.CSSGroupingRule:(zt&&(c.CSSMediaRule=i.CSSMediaRule),Jt&&(c.CSSConditionRule=i.CSSConditionRule),Yt&&(c.CSSSupportsRule=i.CSSSupportsRule));let l={};return Object.entries(c).forEach(([d,u])=>{l[d]={insertRule:u.prototype.insertRule,deleteRule:u.prototype.deleteRule},u.prototype.insertRule=function(p,f){let{id:h,styleId:v}=ce(this.parentStyleSheet,e,r.styleMirror);return (h&&h!==-1||v&&v!==-1)&&t({id:h,styleId:v,adds:[{rule:p,index:[...Ze(this),f||0]}]}),l[d].insertRule.apply(this,[p,f])},u.prototype.deleteRule=function(p){let{id:f,styleId:h}=ce(this.parentStyleSheet,e,r.styleMirror);return (f&&f!==-1||h&&h!==-1)&&t({id:f,styleId:h,removes:[{index:[...Ze(this),p]}]}),l[d].deleteRule.apply(this,[p])};}),()=>{i.CSSStyleSheet.prototype.insertRule=n,i.CSSStyleSheet.prototype.deleteRule=o,a&&(i.CSSStyleSheet.prototype.replace=a),s&&(i.CSSStyleSheet.prototype.replaceSync=s),Object.entries(c).forEach(([d,u])=>{u.prototype.insertRule=l[d].insertRule,u.prototype.deleteRule=l[d].deleteRule;});}}function mt({mirror:t,stylesheetManager:e},r){var i,n,o;let a=null;r.nodeName==="#document"?a=t.getId(r):a=t.getId(r.host);let s=r.nodeName==="#document"?(i=r.defaultView)===null||i===void 0?void 0:i.Document:(o=(n=r.ownerDocument)===null||n===void 0?void 0:n.defaultView)===null||o===void 0?void 0:o.ShadowRoot,c=Object.getOwnPropertyDescriptor(s==null?void 0:s.prototype,"adoptedStyleSheets");return a===null||a===-1||!s||!c?()=>{}:(Object.defineProperty(r,"adoptedStyleSheets",{configurable:c.configurable,enumerable:c.enumerable,get(){var l;return (l=c.get)===null||l===void 0?void 0:l.call(this)},set(l){var d;let u=(d=c.set)===null||d===void 0?void 0:d.call(this,l);if(a!==null&&a!==-1)try{e.adoptStyleSheets(l,a);}catch(p){}return u}}),()=>{Object.defineProperty(r,"adoptedStyleSheets",{configurable:c.configurable,enumerable:c.enumerable,get:c.get,set:c.set});})}function zr({styleDeclarationCb:t,mirror:e,ignoreCSSAttributes:r,stylesheetManager:i},{win:n}){let o=n.CSSStyleDeclaration.prototype.setProperty;n.CSSStyleDeclaration.prototype.setProperty=function(s,c,l){var d;if(r.has(s))return o.apply(this,[s,c,l]);let{id:u,styleId:p}=ce((d=this.parentRule)===null||d===void 0?void 0:d.parentStyleSheet,e,i.styleMirror);return (u&&u!==-1||p&&p!==-1)&&t({id:u,styleId:p,set:{property:s,value:c,priority:l},index:Ze(this.parentRule)}),o.apply(this,[s,c,l])};let a=n.CSSStyleDeclaration.prototype.removeProperty;return n.CSSStyleDeclaration.prototype.removeProperty=function(s){var c;if(r.has(s))return a.apply(this,[s]);let{id:l,styleId:d}=ce((c=this.parentRule)===null||c===void 0?void 0:c.parentStyleSheet,e,i.styleMirror);return (l&&l!==-1||d&&d!==-1)&&t({id:l,styleId:d,remove:{property:s},index:Ze(this.parentRule)}),a.apply(this,[s])},()=>{n.CSSStyleDeclaration.prototype.setProperty=o,n.CSSStyleDeclaration.prototype.removeProperty=a;}}function Yr({mediaInteractionCb:t,blockClass:e,blockSelector:r,mirror:i,sampling:n}){let o=s=>Ce(c=>{let l=Ee(c);if(!l||M(l,e,r,true))return;let{currentTime:d,volume:u,muted:p,playbackRate:f}=l;t({type:s,id:i.getId(l),currentTime:d,volume:u,muted:p,playbackRate:f});},n.media||500),a=[P("play",o(0)),P("pause",o(1)),P("seeked",o(2)),P("volumechange",o(3)),P("ratechange",o(4))];return ()=>{a.forEach(s=>s());}}function Jr({fontCb:t,doc:e}){let r=e.defaultView;if(!r)return ()=>{};let i=[],n=new WeakMap,o=r.FontFace;r.FontFace=function(c,l,d){let u=new o(c,l,d);return n.set(u,{family:c,buffer:typeof l!="string",descriptors:d,fontSource:typeof l=="string"?l:JSON.stringify(Array.from(new Uint8Array(l)))}),u};let a=ee(e.fonts,"add",function(s){return function(c){return setTimeout(()=>{let l=n.get(c);l&&(t(l),n.delete(c));},0),s.apply(this,[c])}});return i.push(()=>{r.FontFace=o;}),i.push(a),()=>{i.forEach(s=>s());}}function Qr(t){let{doc:e,mirror:r,blockClass:i,blockSelector:n,selectionCb:o}=t,a=true,s=()=>{let c=e.getSelection();if(!c||a&&(c!=null&&c.isCollapsed))return;a=c.isCollapsed||false;let l=[],d=c.rangeCount||0;for(let u=0;u<d;u++){let p=c.getRangeAt(u),{startContainer:f,startOffset:h,endContainer:v,endOffset:C}=p;M(f,i,n,true)||M(v,i,n,true)||l.push({start:r.getId(f),startOffset:h,end:r.getId(v),endOffset:C});}o({ranges:l});};return s(),P("selectionchange",s)}function jr(t,e){let{mutationCb:r,mousemoveCb:i,mouseInteractionCb:n,scrollCb:o,viewportResizeCb:a,inputCb:s,mediaInteractionCb:c,styleSheetRuleCb:l,styleDeclarationCb:d,canvasMutationCb:u,fontCb:p,selectionCb:f}=t;t.mutationCb=(...h)=>{e.mutation&&e.mutation(...h),r(...h);},t.mousemoveCb=(...h)=>{e.mousemove&&e.mousemove(...h),i(...h);},t.mouseInteractionCb=(...h)=>{e.mouseInteraction&&e.mouseInteraction(...h),n(...h);},t.scrollCb=(...h)=>{e.scroll&&e.scroll(...h),o(...h);},t.viewportResizeCb=(...h)=>{e.viewportResize&&e.viewportResize(...h),a(...h);},t.inputCb=(...h)=>{e.input&&e.input(...h),s(...h);},t.mediaInteractionCb=(...h)=>{e.mediaInteaction&&e.mediaInteaction(...h),c(...h);},t.styleSheetRuleCb=(...h)=>{e.styleSheetRule&&e.styleSheetRule(...h),l(...h);},t.styleDeclarationCb=(...h)=>{e.styleDeclaration&&e.styleDeclaration(...h),d(...h);},t.canvasMutationCb=(...h)=>{e.canvasMutation&&e.canvasMutation(...h),u(...h);},t.fontCb=(...h)=>{e.font&&e.font(...h),p(...h);},t.selectionCb=(...h)=>{e.selection&&e.selection(...h),f(...h);};}function Qt(t,e={}){let r=t.doc.defaultView;if(!r)return ()=>{};jr(t,e);let i=ft(t,t.doc),n=_r(t),o=Gr(t),a=gt(t),s=Ur(t),c=Zr(t),l=Yr(t),d=Kr(t,{win:r}),u=mt(t,t.doc),p=zr(t,{win:r}),f=t.collectFonts?Jr(t):()=>{},h=Qr(t),v=[];for(let C of t.plugins)v.push(C.observer(C.callback,r,C.options));return ()=>{le.forEach(C=>C.reset()),i.disconnect(),n(),o(),a(),s(),c(),l(),d(),u(),p(),f(),h(),v.forEach(C=>C());}}var Me=class{constructor(e){this.generateIdFn=e,this.iframeIdToRemoteIdMap=new WeakMap,this.iframeRemoteIdToIdMap=new WeakMap;}getId(e,r,i,n){let o=i||this.getIdToRemoteIdMap(e),a=n||this.getRemoteIdToIdMap(e),s=o.get(r);return s||(s=this.generateIdFn(),o.set(r,s),a.set(s,r)),s}getIds(e,r){let i=this.getIdToRemoteIdMap(e),n=this.getRemoteIdToIdMap(e);return r.map(o=>this.getId(e,o,i,n))}getRemoteId(e,r,i){let n=i||this.getRemoteIdToIdMap(e);if(typeof r!="number")return r;let o=n.get(r);return o||-1}getRemoteIds(e,r){let i=this.getRemoteIdToIdMap(e);return r.map(n=>this.getRemoteId(e,n,i))}reset(e){if(!e){this.iframeIdToRemoteIdMap=new WeakMap,this.iframeRemoteIdToIdMap=new WeakMap;return}this.iframeIdToRemoteIdMap.delete(e),this.iframeRemoteIdToIdMap.delete(e);}getIdToRemoteIdMap(e){let r=this.iframeIdToRemoteIdMap.get(e);return r||(r=new Map,this.iframeIdToRemoteIdMap.set(e,r)),r}getRemoteIdToIdMap(e){let r=this.iframeRemoteIdToIdMap.get(e);return r||(r=new Map,this.iframeRemoteIdToIdMap.set(e,r)),r}};var Ke=class{constructor(e){this.iframes=new WeakMap,this.crossOriginIframeMap=new WeakMap,this.crossOriginIframeMirror=new Me(st),this.mutationCb=e.mutationCb,this.wrappedEmit=e.wrappedEmit,this.stylesheetManager=e.stylesheetManager,this.recordCrossOriginIframes=e.recordCrossOriginIframes,this.crossOriginIframeStyleMirror=new Me(this.stylesheetManager.styleMirror.generateId.bind(this.stylesheetManager.styleMirror)),this.mirror=e.mirror,this.recordCrossOriginIframes&&window.addEventListener("message",this.handleMessage.bind(this));}addIframe(e){this.iframes.set(e,true),e.contentWindow&&this.crossOriginIframeMap.set(e.contentWindow,e);}addLoadListener(e){this.loadListener=e;}attachIframe(e,r){var i;this.mutationCb({adds:[{parentId:this.mirror.getId(e),nextId:null,node:r}],removes:[],texts:[],attributes:[],isAttachIframe:true}),(i=this.loadListener)===null||i===void 0||i.call(this,e),e.contentDocument&&e.contentDocument.adoptedStyleSheets&&e.contentDocument.adoptedStyleSheets.length>0&&this.stylesheetManager.adoptStyleSheets(e.contentDocument.adoptedStyleSheets,this.mirror.getId(e.contentDocument));}handleMessage(e){if(e.data.type==="rrweb"){if(!e.source)return;let i=this.crossOriginIframeMap.get(e.source);if(!i)return;let n=this.transformCrossOriginEvent(i,e.data.event);n&&this.wrappedEmit(n,e.data.isCheckout);}}transformCrossOriginEvent(e,r){var i;switch(r.type){case b.FullSnapshot:return this.crossOriginIframeMirror.reset(e),this.crossOriginIframeStyleMirror.reset(e),this.replaceIdOnNode(r.data.node,e),{timestamp:r.timestamp,type:b.IncrementalSnapshot,data:{source:S.Mutation,adds:[{parentId:this.mirror.getId(e),nextId:null,node:r.data.node}],removes:[],texts:[],attributes:[],isAttachIframe:true}};case b.Meta:case b.Load:case b.DomContentLoaded:return false;case b.Plugin:return r;case b.Custom:return this.replaceIds(r.data.payload,e,["id","parentId","previousId","nextId"]),r;case b.IncrementalSnapshot:switch(r.data.source){case S.Mutation:return r.data.adds.forEach(n=>{this.replaceIds(n,e,["parentId","nextId","previousId"]),this.replaceIdOnNode(n.node,e);}),r.data.removes.forEach(n=>{this.replaceIds(n,e,["parentId","id"]);}),r.data.attributes.forEach(n=>{this.replaceIds(n,e,["id"]);}),r.data.texts.forEach(n=>{this.replaceIds(n,e,["id"]);}),r;case S.Drag:case S.TouchMove:case S.MouseMove:return r.data.positions.forEach(n=>{this.replaceIds(n,e,["id"]);}),r;case S.ViewportResize:return false;case S.MediaInteraction:case S.MouseInteraction:case S.Scroll:case S.CanvasMutation:case S.Input:return this.replaceIds(r.data,e,["id"]),r;case S.StyleSheetRule:case S.StyleDeclaration:return this.replaceIds(r.data,e,["id"]),this.replaceStyleIds(r.data,e,["styleId"]),r;case S.Font:return r;case S.Selection:return r.data.ranges.forEach(n=>{this.replaceIds(n,e,["start","end"]);}),r;case S.AdoptedStyleSheet:return this.replaceIds(r.data,e,["id"]),this.replaceStyleIds(r.data,e,["styleIds"]),(i=r.data.styles)===null||i===void 0||i.forEach(n=>{this.replaceStyleIds(n,e,["styleId"]);}),r}}}replace(e,r,i,n){for(let o of n)!Array.isArray(r[o])&&typeof r[o]!="number"||(Array.isArray(r[o])?r[o]=e.getIds(i,r[o]):r[o]=e.getId(i,r[o]));return r}replaceIds(e,r,i){return this.replace(this.crossOriginIframeMirror,e,r,i)}replaceStyleIds(e,r,i){return this.replace(this.crossOriginIframeStyleMirror,e,r,i)}replaceIdOnNode(e,r){this.replaceIds(e,r,["id"]),"childNodes"in e&&e.childNodes.forEach(i=>{this.replaceIdOnNode(i,r);});}};var ze=class{constructor(e){this.shadowDoms=new WeakSet,this.restorePatches=[],this.mutationCb=e.mutationCb,this.scrollCb=e.scrollCb,this.bypassOptions=e.bypassOptions,this.mirror=e.mirror;let r=this;this.restorePatches.push(ee(Element.prototype,"attachShadow",function(i){return function(n){let o=i.call(this,n);return this.shadowRoot&&r.addShadowRoot(this.shadowRoot,this.ownerDocument),o}}));}addShadowRoot(e,r){ue(e)&&(this.shadowDoms.has(e)||(this.shadowDoms.add(e),ft(Object.assign(Object.assign({},this.bypassOptions),{doc:r,mutationCb:this.mutationCb,mirror:this.mirror,shadowDomManager:this}),e),gt(Object.assign(Object.assign({},this.bypassOptions),{scrollCb:this.scrollCb,doc:e,mirror:this.mirror})),setTimeout(()=>{e.adoptedStyleSheets&&e.adoptedStyleSheets.length>0&&this.bypassOptions.stylesheetManager.adoptStyleSheets(e.adoptedStyleSheets,this.mirror.getId(e.host)),mt({mirror:this.mirror,stylesheetManager:this.bypassOptions.stylesheetManager},e);},0)));}observeAttachShadow(e){if(e.contentWindow){let r=this;this.restorePatches.push(ee(e.contentWindow.HTMLElement.prototype,"attachShadow",function(i){return function(n){let o=i.call(this,n);return this.shadowRoot&&r.addShadowRoot(this.shadowRoot,e.contentDocument),o}}));}}reset(){this.restorePatches.forEach(e=>e()),this.shadowDoms=new WeakSet;}};function jt(t,e){var r={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(r[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,i=Object.getOwnPropertySymbols(t);n<i.length;n++)e.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(t,i[n])&&(r[i[n]]=t[i[n]]);return r}function Xt(t,e,r,i){function n(o){return o instanceof r?o:new r(function(a){a(o);})}return new(r||(r=Promise))(function(o,a){function s(d){try{l(i.next(d));}catch(u){a(u);}}function c(d){try{l(i.throw(d));}catch(u){a(u);}}function l(d){d.done?o(d.value):n(d.value).then(s,c);}l((i=i.apply(t,[])).next());})}var Se="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",Xr=typeof Uint8Array=="undefined"?[]:new Uint8Array(256);for(xe=0;xe<Se.length;xe++)Xr[Se.charCodeAt(xe)]=xe;var xe,qt=function(t){var e=new Uint8Array(t),r,i=e.length,n="";for(r=0;r<i;r+=3)n+=Se[e[r]>>2],n+=Se[(e[r]&3)<<4|e[r+1]>>4],n+=Se[(e[r+1]&15)<<2|e[r+2]>>6],n+=Se[e[r+2]&63];return i%3===2?n=n.substring(0,n.length-1)+"=":i%3===1&&(n=n.substring(0,n.length-2)+"=="),n};var $t=new Map;function qr(t,e){let r=$t.get(t);return r||(r=new Map,$t.set(t,r)),r.has(e)||r.set(e,[]),r.get(e)}var vt=(t,e,r)=>{if(!t||!(er(t,e)||typeof t=="object"))return;let i=t.constructor.name,n=qr(r,i),o=n.indexOf(t);return o===-1&&(o=n.length,n.push(t)),o};function Ye(t,e,r){if(t instanceof Array)return t.map(i=>Ye(i,e,r));if(t===null)return t;if(t instanceof Float32Array||t instanceof Float64Array||t instanceof Int32Array||t instanceof Uint32Array||t instanceof Uint8Array||t instanceof Uint16Array||t instanceof Int16Array||t instanceof Int8Array||t instanceof Uint8ClampedArray)return {rr_type:t.constructor.name,args:[Object.values(t)]};if(t instanceof ArrayBuffer){let i=t.constructor.name,n=qt(t);return {rr_type:i,base64:n}}else {if(t instanceof DataView)return {rr_type:t.constructor.name,args:[Ye(t.buffer,e,r),t.byteOffset,t.byteLength]};if(t instanceof HTMLImageElement){let i=t.constructor.name,{src:n}=t;return {rr_type:i,src:n}}else if(t instanceof HTMLCanvasElement){let i="HTMLImageElement",n=t.toDataURL();return {rr_type:i,src:n}}else {if(t instanceof ImageData)return {rr_type:t.constructor.name,args:[Ye(t.data,e,r),t.width,t.height]};if(er(t,e)||typeof t=="object"){let i=t.constructor.name,n=vt(t,e,r);return {rr_type:i,index:n}}}}return t}var Je=(t,e,r)=>[...t].map(i=>Ye(i,e,r)),er=(t,e)=>!!["WebGLActiveInfo","WebGLBuffer","WebGLFramebuffer","WebGLProgram","WebGLRenderbuffer","WebGLShader","WebGLShaderPrecisionFormat","WebGLTexture","WebGLUniformLocation","WebGLVertexArrayObject","WebGLVertexArrayObjectOES"].filter(n=>typeof e[n]=="function").find(n=>t instanceof e[n]);function tr(t,e,r,i){let n=[],o=Object.getOwnPropertyNames(e.CanvasRenderingContext2D.prototype);for(let a of o)try{if(typeof e.CanvasRenderingContext2D.prototype[a]!="function")continue;let s=ee(e.CanvasRenderingContext2D.prototype,a,function(c){return function(...l){return M(this.canvas,r,i,!0)||setTimeout(()=>{let d=Je([...l],e,this);t(this.canvas,{type:oe["2D"],property:a,args:d});},0),c.apply(this,l)}});n.push(s);}catch(s){let c=fe(e.CanvasRenderingContext2D.prototype,a,{set(l){t(this.canvas,{type:oe["2D"],property:a,args:[l],setter:true});}});n.push(c);}return ()=>{n.forEach(a=>a());}}function It(t,e,r){let i=[];try{let n=ee(t.HTMLCanvasElement.prototype,"getContext",function(o){return function(a,...s){return M(this,e,r,!0)||"__context"in this||(this.__context=a),o.apply(this,[a,...s])}});i.push(n);}catch(n){console.error("failed to patch HTMLCanvasElement.prototype.getContext");}return ()=>{i.forEach(n=>n());}}function rr(t,e,r,i,n,o,a){let s=[],c=Object.getOwnPropertyNames(t);for(let l of c)if(!["isContextLost","canvas","drawingBufferWidth","drawingBufferHeight"].includes(l))try{if(typeof t[l]!="function")continue;let d=ee(t,l,function(u){return function(...p){let f=u.apply(this,p);if(vt(f,a,this),!M(this.canvas,i,n,!0)){let h=Je([...p],a,this),v={type:e,property:l,args:h};r(this.canvas,v);}return f}});s.push(d);}catch(d){let u=fe(t,l,{set(p){r(this.canvas,{type:e,property:l,args:[p],setter:true});}});s.push(u);}return s}function ir(t,e,r,i,n){let o=[];return o.push(...rr(e.WebGLRenderingContext.prototype,oe.WebGL,t,r,i,n,e)),typeof e.WebGL2RenderingContext!="undefined"&&o.push(...rr(e.WebGL2RenderingContext.prototype,oe.WebGL2,t,r,i,n,e)),()=>{o.forEach(a=>a());}}var yt=null;try{nr=typeof module!="undefined"&&typeof module.require=="function"&&module.require("worker_threads")||typeof __non_webpack_require__=="function"&&__non_webpack_require__("worker_threads")||typeof tt=="function"&&tt("worker_threads"),yt=nr.Worker;}catch(t){}var nr;function $r(t,e){return Buffer.from(t,"base64").toString("utf8")}function or(t,e,r){var o=$r(t),a=o.indexOf(`
4
+ `,10)+1,s=o.substring(a)+("");return function(l){return new yt(s,Object.assign({},l,{eval:true}))}}function ei(t,e){var r=atob(t);return r}function ti(t,e,r){var o=ei(t),a=o.indexOf(`
5
+ `,10)+1,s=o.substring(a)+(""),c=new Blob([s],{type:"application/javascript"});return URL.createObjectURL(c)}function sr(t,e,r){var i;return function(o){return i=i||ti(t),new Worker(i,o)}}var ri=Object.prototype.toString.call(typeof process!="undefined"?process:0)==="[object process]";function ar(){return ri}function cr(t,e,r){return ar()?or(t):sr(t)}var lr=cr("Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwooZnVuY3Rpb24gKCkgewogICAgJ3VzZSBzdHJpY3QnOwoKICAgIC8qISAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKg0KICAgIENvcHlyaWdodCAoYykgTWljcm9zb2Z0IENvcnBvcmF0aW9uLg0KDQogICAgUGVybWlzc2lvbiB0byB1c2UsIGNvcHksIG1vZGlmeSwgYW5kL29yIGRpc3RyaWJ1dGUgdGhpcyBzb2Z0d2FyZSBmb3IgYW55DQogICAgcHVycG9zZSB3aXRoIG9yIHdpdGhvdXQgZmVlIGlzIGhlcmVieSBncmFudGVkLg0KDQogICAgVEhFIFNPRlRXQVJFIElTIFBST1ZJREVEICJBUyBJUyIgQU5EIFRIRSBBVVRIT1IgRElTQ0xBSU1TIEFMTCBXQVJSQU5USUVTIFdJVEgNCiAgICBSRUdBUkQgVE8gVEhJUyBTT0ZUV0FSRSBJTkNMVURJTkcgQUxMIElNUExJRUQgV0FSUkFOVElFUyBPRiBNRVJDSEFOVEFCSUxJVFkNCiAgICBBTkQgRklUTkVTUy4gSU4gTk8gRVZFTlQgU0hBTEwgVEhFIEFVVEhPUiBCRSBMSUFCTEUgRk9SIEFOWSBTUEVDSUFMLCBESVJFQ1QsDQogICAgSU5ESVJFQ1QsIE9SIENPTlNFUVVFTlRJQUwgREFNQUdFUyBPUiBBTlkgREFNQUdFUyBXSEFUU09FVkVSIFJFU1VMVElORyBGUk9NDQogICAgTE9TUyBPRiBVU0UsIERBVEEgT1IgUFJPRklUUywgV0hFVEhFUiBJTiBBTiBBQ1RJT04gT0YgQ09OVFJBQ1QsIE5FR0xJR0VOQ0UgT1INCiAgICBPVEhFUiBUT1JUSU9VUyBBQ1RJT04sIEFSSVNJTkcgT1VUIE9GIE9SIElOIENPTk5FQ1RJT04gV0lUSCBUSEUgVVNFIE9SDQogICAgUEVSRk9STUFOQ0UgT0YgVEhJUyBTT0ZUV0FSRS4NCiAgICAqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKiAqLw0KDQogICAgZnVuY3Rpb24gX19hd2FpdGVyKHRoaXNBcmcsIF9hcmd1bWVudHMsIFAsIGdlbmVyYXRvcikgew0KICAgICAgICBmdW5jdGlvbiBhZG9wdCh2YWx1ZSkgeyByZXR1cm4gdmFsdWUgaW5zdGFuY2VvZiBQID8gdmFsdWUgOiBuZXcgUChmdW5jdGlvbiAocmVzb2x2ZSkgeyByZXNvbHZlKHZhbHVlKTsgfSk7IH0NCiAgICAgICAgcmV0dXJuIG5ldyAoUCB8fCAoUCA9IFByb21pc2UpKShmdW5jdGlvbiAocmVzb2x2ZSwgcmVqZWN0KSB7DQogICAgICAgICAgICBmdW5jdGlvbiBmdWxmaWxsZWQodmFsdWUpIHsgdHJ5IHsgc3RlcChnZW5lcmF0b3IubmV4dCh2YWx1ZSkpOyB9IGNhdGNoIChlKSB7IHJlamVjdChlKTsgfSB9DQogICAgICAgICAgICBmdW5jdGlvbiByZWplY3RlZCh2YWx1ZSkgeyB0cnkgeyBzdGVwKGdlbmVyYXRvclsidGhyb3ciXSh2YWx1ZSkpOyB9IGNhdGNoIChlKSB7IHJlamVjdChlKTsgfSB9DQogICAgICAgICAgICBmdW5jdGlvbiBzdGVwKHJlc3VsdCkgeyByZXN1bHQuZG9uZSA/IHJlc29sdmUocmVzdWx0LnZhbHVlKSA6IGFkb3B0KHJlc3VsdC52YWx1ZSkudGhlbihmdWxmaWxsZWQsIHJlamVjdGVkKTsgfQ0KICAgICAgICAgICAgc3RlcCgoZ2VuZXJhdG9yID0gZ2VuZXJhdG9yLmFwcGx5KHRoaXNBcmcsIF9hcmd1bWVudHMgfHwgW10pKS5uZXh0KCkpOw0KICAgICAgICB9KTsNCiAgICB9CgogICAgLyoKICAgICAqIGJhc2U2NC1hcnJheWJ1ZmZlciAxLjAuMSA8aHR0cHM6Ly9naXRodWIuY29tL25pa2xhc3ZoL2Jhc2U2NC1hcnJheWJ1ZmZlcj4KICAgICAqIENvcHlyaWdodCAoYykgMjAyMSBOaWtsYXMgdm9uIEhlcnR6ZW4gPGh0dHBzOi8vaGVydHplbi5jb20+CiAgICAgKiBSZWxlYXNlZCB1bmRlciBNSVQgTGljZW5zZQogICAgICovCiAgICB2YXIgY2hhcnMgPSAnQUJDREVGR0hJSktMTU5PUFFSU1RVVldYWVphYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODkrLyc7CiAgICAvLyBVc2UgYSBsb29rdXAgdGFibGUgdG8gZmluZCB0aGUgaW5kZXguCiAgICB2YXIgbG9va3VwID0gdHlwZW9mIFVpbnQ4QXJyYXkgPT09ICd1bmRlZmluZWQnID8gW10gOiBuZXcgVWludDhBcnJheSgyNTYpOwogICAgZm9yICh2YXIgaSA9IDA7IGkgPCBjaGFycy5sZW5ndGg7IGkrKykgewogICAgICAgIGxvb2t1cFtjaGFycy5jaGFyQ29kZUF0KGkpXSA9IGk7CiAgICB9CiAgICB2YXIgZW5jb2RlID0gZnVuY3Rpb24gKGFycmF5YnVmZmVyKSB7CiAgICAgICAgdmFyIGJ5dGVzID0gbmV3IFVpbnQ4QXJyYXkoYXJyYXlidWZmZXIpLCBpLCBsZW4gPSBieXRlcy5sZW5ndGgsIGJhc2U2NCA9ICcnOwogICAgICAgIGZvciAoaSA9IDA7IGkgPCBsZW47IGkgKz0gMykgewogICAgICAgICAgICBiYXNlNjQgKz0gY2hhcnNbYnl0ZXNbaV0gPj4gMl07CiAgICAgICAgICAgIGJhc2U2NCArPSBjaGFyc1soKGJ5dGVzW2ldICYgMykgPDwgNCkgfCAoYnl0ZXNbaSArIDFdID4+IDQpXTsKICAgICAgICAgICAgYmFzZTY0ICs9IGNoYXJzWygoYnl0ZXNbaSArIDFdICYgMTUpIDw8IDIpIHwgKGJ5dGVzW2kgKyAyXSA+PiA2KV07CiAgICAgICAgICAgIGJhc2U2NCArPSBjaGFyc1tieXRlc1tpICsgMl0gJiA2M107CiAgICAgICAgfQogICAgICAgIGlmIChsZW4gJSAzID09PSAyKSB7CiAgICAgICAgICAgIGJhc2U2NCA9IGJhc2U2NC5zdWJzdHJpbmcoMCwgYmFzZTY0Lmxlbmd0aCAtIDEpICsgJz0nOwogICAgICAgIH0KICAgICAgICBlbHNlIGlmIChsZW4gJSAzID09PSAxKSB7CiAgICAgICAgICAgIGJhc2U2NCA9IGJhc2U2NC5zdWJzdHJpbmcoMCwgYmFzZTY0Lmxlbmd0aCAtIDIpICsgJz09JzsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGJhc2U2NDsKICAgIH07CgogICAgY29uc3QgbGFzdEJsb2JNYXAgPSBuZXcgTWFwKCk7DQogICAgY29uc3QgdHJhbnNwYXJlbnRCbG9iTWFwID0gbmV3IE1hcCgpOw0KICAgIGZ1bmN0aW9uIGdldFRyYW5zcGFyZW50QmxvYkZvcih3aWR0aCwgaGVpZ2h0LCBkYXRhVVJMT3B0aW9ucykgew0KICAgICAgICByZXR1cm4gX19hd2FpdGVyKHRoaXMsIHZvaWQgMCwgdm9pZCAwLCBmdW5jdGlvbiogKCkgew0KICAgICAgICAgICAgY29uc3QgaWQgPSBgJHt3aWR0aH0tJHtoZWlnaHR9YDsNCiAgICAgICAgICAgIGlmICgnT2Zmc2NyZWVuQ2FudmFzJyBpbiBnbG9iYWxUaGlzKSB7DQogICAgICAgICAgICAgICAgaWYgKHRyYW5zcGFyZW50QmxvYk1hcC5oYXMoaWQpKQ0KICAgICAgICAgICAgICAgICAgICByZXR1cm4gdHJhbnNwYXJlbnRCbG9iTWFwLmdldChpZCk7DQogICAgICAgICAgICAgICAgY29uc3Qgb2Zmc2NyZWVuID0gbmV3IE9mZnNjcmVlbkNhbnZhcyh3aWR0aCwgaGVpZ2h0KTsNCiAgICAgICAgICAgICAgICBvZmZzY3JlZW4uZ2V0Q29udGV4dCgnMmQnKTsNCiAgICAgICAgICAgICAgICBjb25zdCBibG9iID0geWllbGQgb2Zmc2NyZWVuLmNvbnZlcnRUb0Jsb2IoZGF0YVVSTE9wdGlvbnMpOw0KICAgICAgICAgICAgICAgIGNvbnN0IGFycmF5QnVmZmVyID0geWllbGQgYmxvYi5hcnJheUJ1ZmZlcigpOw0KICAgICAgICAgICAgICAgIGNvbnN0IGJhc2U2NCA9IGVuY29kZShhcnJheUJ1ZmZlcik7DQogICAgICAgICAgICAgICAgdHJhbnNwYXJlbnRCbG9iTWFwLnNldChpZCwgYmFzZTY0KTsNCiAgICAgICAgICAgICAgICByZXR1cm4gYmFzZTY0Ow0KICAgICAgICAgICAgfQ0KICAgICAgICAgICAgZWxzZSB7DQogICAgICAgICAgICAgICAgcmV0dXJuICcnOw0KICAgICAgICAgICAgfQ0KICAgICAgICB9KTsNCiAgICB9DQogICAgY29uc3Qgd29ya2VyID0gc2VsZjsNCiAgICB3b3JrZXIub25tZXNzYWdlID0gZnVuY3Rpb24gKGUpIHsNCiAgICAgICAgcmV0dXJuIF9fYXdhaXRlcih0aGlzLCB2b2lkIDAsIHZvaWQgMCwgZnVuY3Rpb24qICgpIHsNCiAgICAgICAgICAgIGlmICgnT2Zmc2NyZWVuQ2FudmFzJyBpbiBnbG9iYWxUaGlzKSB7DQogICAgICAgICAgICAgICAgY29uc3QgeyBpZCwgYml0bWFwLCB3aWR0aCwgaGVpZ2h0LCBkYXRhVVJMT3B0aW9ucyB9ID0gZS5kYXRhOw0KICAgICAgICAgICAgICAgIGNvbnN0IHRyYW5zcGFyZW50QmFzZTY0ID0gZ2V0VHJhbnNwYXJlbnRCbG9iRm9yKHdpZHRoLCBoZWlnaHQsIGRhdGFVUkxPcHRpb25zKTsNCiAgICAgICAgICAgICAgICBjb25zdCBvZmZzY3JlZW4gPSBuZXcgT2Zmc2NyZWVuQ2FudmFzKHdpZHRoLCBoZWlnaHQpOw0KICAgICAgICAgICAgICAgIGNvbnN0IGN0eCA9IG9mZnNjcmVlbi5nZXRDb250ZXh0KCcyZCcpOw0KICAgICAgICAgICAgICAgIGN0eC5kcmF3SW1hZ2UoYml0bWFwLCAwLCAwKTsNCiAgICAgICAgICAgICAgICBiaXRtYXAuY2xvc2UoKTsNCiAgICAgICAgICAgICAgICBjb25zdCBibG9iID0geWllbGQgb2Zmc2NyZWVuLmNvbnZlcnRUb0Jsb2IoZGF0YVVSTE9wdGlvbnMpOw0KICAgICAgICAgICAgICAgIGNvbnN0IHR5cGUgPSBibG9iLnR5cGU7DQogICAgICAgICAgICAgICAgY29uc3QgYXJyYXlCdWZmZXIgPSB5aWVsZCBibG9iLmFycmF5QnVmZmVyKCk7DQogICAgICAgICAgICAgICAgY29uc3QgYmFzZTY0ID0gZW5jb2RlKGFycmF5QnVmZmVyKTsNCiAgICAgICAgICAgICAgICBpZiAoIWxhc3RCbG9iTWFwLmhhcyhpZCkgJiYgKHlpZWxkIHRyYW5zcGFyZW50QmFzZTY0KSA9PT0gYmFzZTY0KSB7DQogICAgICAgICAgICAgICAgICAgIGxhc3RCbG9iTWFwLnNldChpZCwgYmFzZTY0KTsNCiAgICAgICAgICAgICAgICAgICAgcmV0dXJuIHdvcmtlci5wb3N0TWVzc2FnZSh7IGlkIH0pOw0KICAgICAgICAgICAgICAgIH0NCiAgICAgICAgICAgICAgICBpZiAobGFzdEJsb2JNYXAuZ2V0KGlkKSA9PT0gYmFzZTY0KQ0KICAgICAgICAgICAgICAgICAgICByZXR1cm4gd29ya2VyLnBvc3RNZXNzYWdlKHsgaWQgfSk7DQogICAgICAgICAgICAgICAgd29ya2VyLnBvc3RNZXNzYWdlKHsNCiAgICAgICAgICAgICAgICAgICAgaWQsDQogICAgICAgICAgICAgICAgICAgIHR5cGUsDQogICAgICAgICAgICAgICAgICAgIGJhc2U2NCwNCiAgICAgICAgICAgICAgICAgICAgd2lkdGgsDQogICAgICAgICAgICAgICAgICAgIGhlaWdodCwNCiAgICAgICAgICAgICAgICB9KTsNCiAgICAgICAgICAgICAgICBsYXN0QmxvYk1hcC5zZXQoaWQsIGJhc2U2NCk7DQogICAgICAgICAgICB9DQogICAgICAgICAgICBlbHNlIHsNCiAgICAgICAgICAgICAgICByZXR1cm4gd29ya2VyLnBvc3RNZXNzYWdlKHsgaWQ6IGUuZGF0YS5pZCB9KTsNCiAgICAgICAgICAgIH0NCiAgICAgICAgfSk7DQogICAgfTsKCn0pKCk7Cgo=");var Qe=class{constructor(e){this.pendingCanvasMutations=new Map,this.rafStamps={latestId:0,invokeId:null},this.frozen=false,this.locked=false,this.processMutation=(c,l)=>{(this.rafStamps.invokeId&&this.rafStamps.latestId!==this.rafStamps.invokeId||!this.rafStamps.invokeId)&&(this.rafStamps.invokeId=this.rafStamps.latestId),this.pendingCanvasMutations.has(c)||this.pendingCanvasMutations.set(c,[]),this.pendingCanvasMutations.get(c).push(l);};let{sampling:r="all",win:i,blockClass:n,blockSelector:o,recordCanvas:a,dataURLOptions:s}=e;this.mutationCb=e.mutationCb,this.mirror=e.mirror,a&&r==="all"&&this.initCanvasMutationObserver(i,n,o),a&&typeof r=="number"&&this.initCanvasFPSObserver(r,i,n,o,{dataURLOptions:s});}reset(){this.pendingCanvasMutations.clear(),this.resetObservers&&this.resetObservers();}freeze(){this.frozen=true;}unfreeze(){this.frozen=false;}lock(){this.locked=true;}unlock(){this.locked=false;}initCanvasFPSObserver(e,r,i,n,o){let a=It(r,i,n),s=new Map,c=new lr;c.onmessage=h=>{let{id:v}=h.data;if(s.set(v,false),!("base64"in h.data))return;let{base64:C,type:I,width:g,height:m}=h.data;this.mutationCb({id:v,type:oe["2D"],commands:[{property:"clearRect",args:[0,0,g,m]},{property:"drawImage",args:[{rr_type:"ImageBitmap",args:[{rr_type:"Blob",data:[{rr_type:"ArrayBuffer",base64:C}],type:I}]},0,0]}]});};let l=1e3/e,d=0,u,p=()=>{let h=[];return r.document.querySelectorAll("canvas").forEach(v=>{M(v,i,n,true)||h.push(v);}),h},f=h=>{if(d&&h-d<l){u=requestAnimationFrame(f);return}d=h,p().forEach(v=>Xt(this,void 0,void 0,function*(){var C;let I=this.mirror.getId(v);if(s.get(I))return;if(s.set(I,true),["webgl","webgl2"].includes(v.__context)){let m=v.getContext(v.__context);((C=m==null?void 0:m.getContextAttributes())===null||C===void 0?void 0:C.preserveDrawingBuffer)===false&&(m==null||m.clear(m.COLOR_BUFFER_BIT));}let g=yield createImageBitmap(v);c.postMessage({id:I,bitmap:g,width:v.width,height:v.height,dataURLOptions:o.dataURLOptions},[g]);})),u=requestAnimationFrame(f);};u=requestAnimationFrame(f),this.resetObservers=()=>{a(),cancelAnimationFrame(u);};}initCanvasMutationObserver(e,r,i){this.startRAFTimestamping(),this.startPendingCanvasMutationFlusher();let n=It(e,r,i),o=tr(this.processMutation.bind(this),e,r,i),a=ir(this.processMutation.bind(this),e,r,i,this.mirror);this.resetObservers=()=>{n(),o(),a();};}startPendingCanvasMutationFlusher(){requestAnimationFrame(()=>this.flushPendingCanvasMutations());}startRAFTimestamping(){let e=r=>{this.rafStamps.latestId=r,requestAnimationFrame(e);};requestAnimationFrame(e);}flushPendingCanvasMutations(){this.pendingCanvasMutations.forEach((e,r)=>{let i=this.mirror.getId(r);this.flushPendingCanvasMutationFor(r,i);}),requestAnimationFrame(()=>this.flushPendingCanvasMutations());}flushPendingCanvasMutationFor(e,r){if(this.frozen||this.locked)return;let i=this.pendingCanvasMutations.get(e);if(!i||r===-1)return;let n=i.map(a=>jt(a,["type"])),{type:o}=i[0];this.mutationCb({id:r,type:o,commands:n}),this.pendingCanvasMutations.delete(e);}};var je=class{constructor(e){this.trackedLinkElements=new WeakSet,this.styleMirror=new De,this.mutationCb=e.mutationCb,this.adoptedStyleSheetCb=e.adoptedStyleSheetCb;}attachLinkElement(e,r){"_cssText"in r.attributes&&this.mutationCb({adds:[],removes:[],texts:[],attributes:[{id:r.id,attributes:r.attributes}]}),this.trackLinkElement(e);}trackLinkElement(e){this.trackedLinkElements.has(e)||(this.trackedLinkElements.add(e),this.trackStylesheetInLinkElement(e));}adoptStyleSheets(e,r){if(e.length===0)return;let i={id:r,styleIds:[]},n=[];for(let o of e){let a;if(this.styleMirror.has(o))a=this.styleMirror.getId(o);else {a=this.styleMirror.add(o);let s=Array.from(o.rules||CSSRule);n.push({styleId:a,rules:s.map((c,l)=>({rule:ot(c),index:l}))});}i.styleIds.push(a);}n.length>0&&(i.styles=n),this.adoptedStyleSheetCb(i);}reset(){this.styleMirror.reset(),this.trackedLinkElements=new WeakSet;}trackStylesheetInLinkElement(e){}};function L(t){return Object.assign(Object.assign({},t),{timestamp:Date.now()})}var x,Xe,Ct,qe=false,te=Ot();function ge(t={}){let{emit:e,checkoutEveryNms:r,checkoutEveryNth:i,blockClass:n="rr-block",blockSelector:o=null,ignoreClass:a="rr-ignore",maskTextClass:s="rr-mask",maskTextSelector:c=null,inlineStylesheet:l=true,maskAllInputs:d,maskInputOptions:u,slimDOMOptions:p,maskInputFn:f,maskTextFn:h,hooks:v,packFn:C,sampling:I={},dataURLOptions:g={},mousemoveWait:m,recordCanvas:A=false,recordCrossOriginIframes:B=false,userTriggeredOnInput:D=false,collectFonts:W=false,inlineImages:k=false,plugins:Z,keepIframeSrcFn:K=()=>false,ignoreCSSAttributes:Q=new Set([])}=t,j=B?window.parent===window:true,X=false;if(!j)try{window.parent.document,X=!1;}catch(y){X=true;}if(j&&!e)throw new Error("emit function is required");m!==void 0&&I.mousemove===void 0&&(I.mousemove=m),te.reset();let O=d===true?{color:true,date:true,"datetime-local":true,email:true,month:true,number:true,range:true,search:true,tel:true,text:true,time:true,url:true,week:true,textarea:true,select:true,password:true}:u!==void 0?u:{password:true},z=p===true||p==="all"?{script:true,comment:true,headFavicon:true,headWhitespace:true,headMetaSocial:true,headMetaRobots:true,headMetaHttpEquiv:true,headMetaVerification:true,headMetaAuthorship:p==="all",headMetaDescKeywords:p==="all"}:p||{};Wt();let q,re=0,ne=y=>{for(let V of Z||[])V.eventProcessor&&(y=V.eventProcessor(y));return C&&(y=C(y)),y};x=(y,V)=>{var U;if(!((U=le[0])===null||U===void 0)&&U.isFrozen()&&y.type!==b.FullSnapshot&&!(y.type===b.IncrementalSnapshot&&y.data.source===S.Mutation)&&le.forEach(E=>E.unfreeze()),j)e==null||e(ne(y),V);else if(X){let E={type:"rrweb",event:ne(y),isCheckout:V};window.parent.postMessage(E,"*");}if(y.type===b.FullSnapshot)q=y,re=0;else if(y.type===b.IncrementalSnapshot){if(y.data.source===S.Mutation&&y.data.isAttachIframe)return;re++;let E=i&&re>=i,J=r&&y.timestamp-q.timestamp>r;(E||J)&&Xe(true);}};let G=y=>{x(L({type:b.IncrementalSnapshot,data:Object.assign({source:S.Mutation},y)}));},Y=y=>x(L({type:b.IncrementalSnapshot,data:Object.assign({source:S.Scroll},y)})),se=y=>x(L({type:b.IncrementalSnapshot,data:Object.assign({source:S.CanvasMutation},y)})),N=y=>x(L({type:b.IncrementalSnapshot,data:Object.assign({source:S.AdoptedStyleSheet},y)})),$=new je({mutationCb:G,adoptedStyleSheetCb:N}),ie=new Ke({mirror:te,mutationCb:G,stylesheetManager:$,recordCrossOriginIframes:B,wrappedEmit:x});for(let y of Z||[])y.getMirror&&y.getMirror({nodeMirror:te,crossOriginIframeMirror:ie.crossOriginIframeMirror,crossOriginIframeStyleMirror:ie.crossOriginIframeStyleMirror});Ct=new Qe({recordCanvas:A,mutationCb:se,win:window,blockClass:n,blockSelector:o,mirror:te,sampling:I.canvas,dataURLOptions:g});let me=new ze({mutationCb:G,scrollCb:Y,bypassOptions:{blockClass:n,blockSelector:o,maskTextClass:s,maskTextSelector:c,inlineStylesheet:l,maskInputOptions:O,dataURLOptions:g,maskTextFn:h,maskInputFn:f,recordCanvas:A,inlineImages:k,sampling:I,slimDOMOptions:z,iframeManager:ie,stylesheetManager:$,canvasManager:Ct,keepIframeSrcFn:K},mirror:te});Xe=(y=false)=>{var V,U,E,J,w,H;x(L({type:b.Meta,data:{href:window.location.href,width:Pe(),height:We()}}),y),$.reset(),le.forEach(_=>_.lock());let be=Lt(document,{mirror:te,blockClass:n,blockSelector:o,maskTextClass:s,maskTextSelector:c,inlineStylesheet:l,maskAllInputs:O,maskTextFn:h,slimDOM:z,dataURLOptions:g,recordCanvas:A,inlineImages:k,onSerialize:_=>{Ve(_,te)&&ie.addIframe(_),_e(_,te)&&$.trackLinkElement(_),Ge(_)&&me.addShadowRoot(_.shadowRoot,document);},onIframeLoad:(_,et)=>{ie.attachIframe(_,et),me.observeAttachShadow(_);},onStylesheetLoad:(_,et)=>{$.attachLinkElement(_,et);},keepIframeSrcFn:K});if(!be)return console.warn("Failed to snapshot the document");x(L({type:b.FullSnapshot,data:{node:be,initialOffset:{left:window.pageXOffset!==void 0?window.pageXOffset:(document==null?void 0:document.documentElement.scrollLeft)||((U=(V=document==null?void 0:document.body)===null||V===void 0?void 0:V.parentElement)===null||U===void 0?void 0:U.scrollLeft)||((E=document==null?void 0:document.body)===null||E===void 0?void 0:E.scrollLeft)||0,top:window.pageYOffset!==void 0?window.pageYOffset:(document==null?void 0:document.documentElement.scrollTop)||((w=(J=document==null?void 0:document.body)===null||J===void 0?void 0:J.parentElement)===null||w===void 0?void 0:w.scrollTop)||((H=document==null?void 0:document.body)===null||H===void 0?void 0:H.scrollTop)||0}}})),le.forEach(_=>_.unlock()),document.adoptedStyleSheets&&document.adoptedStyleSheets.length>0&&$.adoptStyleSheets(document.adoptedStyleSheets,te.getId(document));};try{let y=[];y.push(P("DOMContentLoaded",()=>{x(L({type:b.DomContentLoaded,data:{}}));}));let V=E=>{var J;return Qt({mutationCb:G,mousemoveCb:(w,H)=>x(L({type:b.IncrementalSnapshot,data:{source:H,positions:w}})),mouseInteractionCb:w=>x(L({type:b.IncrementalSnapshot,data:Object.assign({source:S.MouseInteraction},w)})),scrollCb:Y,viewportResizeCb:w=>x(L({type:b.IncrementalSnapshot,data:Object.assign({source:S.ViewportResize},w)})),inputCb:w=>x(L({type:b.IncrementalSnapshot,data:Object.assign({source:S.Input},w)})),mediaInteractionCb:w=>x(L({type:b.IncrementalSnapshot,data:Object.assign({source:S.MediaInteraction},w)})),styleSheetRuleCb:w=>x(L({type:b.IncrementalSnapshot,data:Object.assign({source:S.StyleSheetRule},w)})),styleDeclarationCb:w=>x(L({type:b.IncrementalSnapshot,data:Object.assign({source:S.StyleDeclaration},w)})),canvasMutationCb:se,fontCb:w=>x(L({type:b.IncrementalSnapshot,data:Object.assign({source:S.Font},w)})),selectionCb:w=>{x(L({type:b.IncrementalSnapshot,data:Object.assign({source:S.Selection},w)}));},blockClass:n,ignoreClass:a,maskTextClass:s,maskTextSelector:c,maskInputOptions:O,inlineStylesheet:l,sampling:I,recordCanvas:A,inlineImages:k,userTriggeredOnInput:D,collectFonts:W,doc:E,maskInputFn:f,maskTextFn:h,keepIframeSrcFn:K,blockSelector:o,slimDOMOptions:z,dataURLOptions:g,mirror:te,iframeManager:ie,stylesheetManager:$,shadowDomManager:me,canvasManager:Ct,ignoreCSSAttributes:Q,plugins:((J=Z==null?void 0:Z.filter(w=>w.observer))===null||J===void 0?void 0:J.map(w=>({observer:w.observer,options:w.options,callback:H=>x(L({type:b.Plugin,data:{plugin:w.name,payload:H}}))})))||[]},v)};ie.addLoadListener(E=>{y.push(V(E.contentDocument));});let U=()=>{Xe(),y.push(V(document)),qe=!0;};return document.readyState==="interactive"||document.readyState==="complete"?U():y.push(P("load",()=>{x(L({type:b.Load,data:{}})),U();},window)),()=>{y.forEach(E=>E()),qe=!1;}}catch(y){console.warn(y);}}ge.addCustomEvent=(t,e)=>{if(!qe)throw new Error("please add custom event after start recording");x(L({type:b.Custom,data:{tag:t,payload:e}}));};ge.freezePage=()=>{le.forEach(t=>t.freeze());};ge.takeFullSnapshot=t=>{if(!qe)throw new Error("please take full snapshot after start recording");Xe(t);};ge.mirror=te;var $e=class{constructor(e){this.opts=e;this.seq=0;this.buffer=[];this.stopRecording=null;this.flushTimer=null;}start(){var e,r;typeof document=="undefined"||this.stopRecording||(this.stopRecording=(r=ge({emit:i=>{this.buffer.push(i),this.buffer.length>=this.opts.maxEventsPerBatch&&this.flush();},checkoutEveryNms:(e=this.opts.checkoutEveryNms)!=null?e:6e5}))!=null?r:null,this.flushTimer=setInterval(()=>{this.buffer.length>0&&this.flush();},this.opts.flushIntervalMs));}flush(){if(this.buffer.length===0)return;let e=this.buffer.splice(0,this.buffer.length);this.opts.emit({type:"session_replay",data:{seq:this.seq++,events:e}});}destroy(){var e;this.flushTimer!==null&&(clearInterval(this.flushTimer),this.flushTimer=null),this.flush(),(e=this.stopRecording)==null||e.call(this),this.stopRecording=null;}};var St="1.0.2";function dr(t){var r,i;let e=t.toLowerCase();return /ipad|tablet|(android(?!.*mobile))/i.test(e)?"tablet":/mobile|android|iphone|ipod|windows phone/i.test(e)?"mobile":typeof navigator!="undefined"&&navigator.maxTouchPoints>0&&typeof window!="undefined"&&((i=(r=window.matchMedia)==null?void 0:r.call(window,"(pointer: coarse)"))==null?void 0:i.matches)&&/macintosh|mac os x/i.test(e)?"tablet":"desktop"}function ii(t){return /windows/i.test(t)?"Windows":/android/i.test(t)?"Android":/iphone|ipad|ipod/i.test(t)?"iOS":/mac os x|macintosh/i.test(t)?"macOS":/linux/i.test(t)?"Linux":"Other"}function ni(t){return /edg\//i.test(t)?"Edge":/opr\/|opera/i.test(t)?"Opera":/chrome\/[0-9]/i.test(t)&&!/chromium/i.test(t)?"Chrome":/firefox\/[0-9]/i.test(t)?"Firefox":/safari\/[0-9]/i.test(t)&&!/chrome/i.test(t)?"Safari":"Other"}function oi(){let e=navigator.userAgentData;return e?{mobile:e.mobile,platform:e.platform}:{}}function si(t,e){var i;let r=((i=e.platform)!=null?i:"").toLowerCase();return r==="ios"||r==="ipados"||r==="android"?e.mobile?"mobile":"tablet":e.mobile===true?"mobile":dr(t)}function ur(t){var s,c,l,d,u,p,f,h,v,C,I,g;if(typeof window=="undefined"||typeof navigator=="undefined")return {sessionId:t,timestamp:Date.now(),device:"desktop",os:"Other",browser:"Other",language:"",languages:[],colorScheme:"",screenWidth:0,screenHeight:0,viewportWidth:0,viewportHeight:0,devicePixelRatio:1,timeZone:"",sdkVersion:St};let e=navigator.userAgent||"",r=oi(),i=r.mobile!==void 0||r.platform?si(e,r):dr(e),n="";(c=(s=window.matchMedia)==null?void 0:s.call(window,"(prefers-color-scheme: dark)"))!=null&&c.matches?n="dark":(d=(l=window.matchMedia)==null?void 0:l.call(window,"(prefers-color-scheme: light)"))!=null&&d.matches&&(n="light");let o="";try{o=(u=Intl.DateTimeFormat().resolvedOptions().timeZone)!=null?u:"";}catch(m){o="";}let a=typeof navigator.languages!="undefined"&&navigator.languages.length?[...navigator.languages]:navigator.language?[navigator.language]:[];return {sessionId:t,timestamp:Date.now(),device:i,os:ii(e),browser:ni(e),language:navigator.language||"",languages:a,colorScheme:n,screenWidth:(f=(p=window.screen)==null?void 0:p.width)!=null?f:0,screenHeight:(v=(h=window.screen)==null?void 0:h.height)!=null?v:0,viewportWidth:(C=window.innerWidth)!=null?C:0,viewportHeight:(I=window.innerHeight)!=null?I:0,devicePixelRatio:(g=window.devicePixelRatio)!=null?g:1,timeZone:o,sdkVersion:St}}var hr="https://api.alphana.ir/api/events",ai={endpoint:hr,trackNavigation:true,trackTime:true,trackHeatmap:true,trackLogs:true,mouseSampleRate:.3,maxHeatmapPoints:2e3,batchSize:20,flushInterval:5e3,sessionReplay:false,sessionReplayCheckoutEveryNms:6e5,sessionReplayMaxEventsPerBatch:48,sessionReplayFlushIntervalMs:4e3};function ci(t){switch(t.type){case "pageview":return {type:"pageview",data:{...t.data,path:R(t.data.path)}};case "timespent":return {type:"timespent",data:{...t.data,path:R(t.data.path)}};case "heatmap":return {type:"heatmap",data:{...t.data,path:R(t.data.path)}};case "rageclik":return {type:"rageclik",data:{...t.data,path:R(t.data.path)}};case "uturn":return {type:"uturn",data:{...t.data,fromPath:R(t.data.fromPath),toPath:R(t.data.toPath)}};case "client_context":return t;case "session_replay":return t;default:return t}}var bt=class{constructor(e={}){this.initialized=false;this.subscribers=new Set;this.queue=[];this.flushTimer=null;this.heartbeatTimer=null;this.userProperties={};this.flags={};this.flagSubscribers=new Set;this.abVariants={};this.abTestSubscribers=new Set;this.handleVisibilityChange=()=>{document.visibilityState==="hidden"&&(this.queue.length>0&&this.flushBeacon(),this.sendDeactivate());};this.handlePageHide=()=>{this.queue.length>0&&this.flushBeacon(),this.sendDeactivate();};this.handleNavigate=e=>{};var r;this.cfg={...ai,...e};try{new URL(this.cfg.endpoint);}catch(i){throw new Error(`[alpha-tracker] Invalid endpoint URL: "${this.cfg.endpoint}"`)}this.session={id:(r=e.sessionId)!=null?r:we(),visitorId:At(),startedAt:Date.now(),pageViews:[],timeSpent:{},heatmap:{}};}init(){if(typeof window=="undefined"||this.initialized)return this;let e=this.emit.bind(this),{id:r}=this.session;return e({type:"client_context",data:ur(r)}),this.cfg.trackNavigation&&(this.navigation=new Ne({emit:e,sessionId:r}),this.navigation.init()),this.cfg.trackTime&&(this.time=new Oe({emit:e,sessionId:r}),this.time.init()),this.cfg.trackHeatmap&&(this.heatmap=new Le({emit:e,sessionId:r,sampleRate:this.cfg.mouseSampleRate,maxPoints:this.cfg.maxHeatmapPoints,allowedPaths:this.cfg.heatmapPages}),this.heatmap.init()),this.cfg.sessionReplay&&(this.sessionReplay=new $e({emit:e,checkoutEveryNms:this.cfg.sessionReplayCheckoutEveryNms,maxEventsPerBatch:this.cfg.sessionReplayMaxEventsPerBatch,flushIntervalMs:this.cfg.sessionReplayFlushIntervalMs}),this.sessionReplay.start()),this.cfg.endpoint&&(this.flushTimer=setInterval(()=>{this.queue.length>0&&this.flushQueue();},this.cfg.flushInterval),window.addEventListener("visibilitychange",this.handleVisibilityChange),window.addEventListener("pagehide",this.handlePageHide),this.heartbeatTimer=setInterval(()=>{document.visibilityState!=="hidden"&&this.sendHeartbeat();},3e4),this.cfg.trackLogs&&(this.logCapture=new ke({endpoint:this.cfg.endpoint,sessionId:this.session.id,secretKey:this.cfg.secretKey,appId:this.cfg.appId}),this.logCapture.init())),this.initialized=true,this.fetchFlags(),this.fetchAbTests(),this}destroy(){var e,r,i,n,o;this.flushTimer!==null&&(clearInterval(this.flushTimer),this.flushTimer=null),this.heartbeatTimer!==null&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null),typeof window!="undefined"&&(window.removeEventListener("visibilitychange",this.handleVisibilityChange),window.removeEventListener("pagehide",this.handlePageHide)),(e=this.navigation)==null||e.destroy(),(r=this.time)==null||r.destroy(),(i=this.heatmap)==null||i.destroy(),(n=this.sessionReplay)==null||n.destroy(),this.sessionReplay=void 0,(o=this.logCapture)==null||o.destroy(),typeof window!="undefined"&&window.removeEventListener("tracker:navigate",this.handleNavigate),this.queue.length>0&&this.cfg.endpoint&&this.flushBeacon(),this.initialized=false;}async sendHeartbeat(){if(!this.cfg.endpoint)return;let e=`${this.cfg.endpoint}/heartbeat`,r=this.cfg.secretKey?{Authorization:`Bearer ${this.cfg.secretKey}`}:{},i=JSON.stringify({sessionId:this.session.id,visitorId:this.session.visitorId,path:R(typeof window!="undefined"?window.location.pathname+window.location.search:"/"),active:true,...this.cfg.appId?{appId:this.cfg.appId}:{}});try{await fetch(e,{method:"POST",headers:{"Content-Type":"application/json",...r},body:i,keepalive:!0});}catch(n){}}sendDeactivate(){if(!this.cfg.endpoint)return;let e=`${this.cfg.endpoint}/heartbeat`,r=this.cfg.secretKey?{Authorization:`Bearer ${this.cfg.secretKey}`}:{},i=JSON.stringify({sessionId:this.session.id,visitorId:this.session.visitorId,path:R(typeof window!="undefined"?window.location.pathname+window.location.search:"/"),active:false,...this.cfg.appId?{appId:this.cfg.appId}:{}});typeof navigator!="undefined"&&navigator.sendBeacon?navigator.sendBeacon(e,new Blob([i],{type:"application/json"})):fetch(e,{method:"POST",headers:{"Content-Type":"application/json",...r},body:i,keepalive:true}).catch(()=>{});}emit(e){var r,i,n;switch(e=ci(e),e.type){case "pageview":this.session.pageViews.push(e.data);break;case "timespent":{let o=(r=this.session.timeSpent[e.data.path])!=null?r:0;this.session.timeSpent[e.data.path]=o+e.data.duration;break}case "heatmap":{let o=e.data.path;this.session.heatmap[o]||(this.session.heatmap[o]=[]);let a=this.session.heatmap[o];a.length<this.cfg.maxHeatmapPoints&&a.push(e.data);break}}this.subscribers.forEach(o=>o(e)),(n=(i=this.cfg).onEvent)==null||n.call(i,e),this.cfg.endpoint&&(this.queue.push(e),this.queue.length>=this.cfg.batchSize&&this.flushQueue());}subscribe(e){return this.subscribers.add(e),()=>this.subscribers.delete(e)}trackPageView(e){let r=R(e!=null?e:typeof window!="undefined"?window.location.pathname+window.location.search:"/");this.emit({type:"pageview",data:{path:r,title:typeof document!="undefined"?document.title:"",timestamp:Date.now(),sessionId:this.session.id,referrer:typeof document!="undefined"&&document.referrer||void 0}}),typeof window!="undefined"&&window.dispatchEvent(new CustomEvent("tracker:navigate",{detail:{path:r,title:document.title}}));}identify(e){this.userProperties={...this.userProperties,...e},this.fetchFlags();}getFlags(){return {...this.flags}}isFeatureEnabled(e){return this.flags[e]===true}onFlagsChange(e){return this.flagSubscribers.add(e),()=>this.flagSubscribers.delete(e)}async fetchFlags(){if(!this.cfg.endpoint||!this.cfg.secretKey)return;let e=rt(this.cfg.endpoint)+"/feature-flags/evaluate";try{let r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.cfg.secretKey}`},body:JSON.stringify({userProperties:this.userProperties})});if(!r.ok)return;let i=await r.json();this.flags=i,this.flagSubscribers.forEach(n=>n({...this.flags}));}catch(r){}}getAbVariants(){return {...this.abVariants}}getAbVariant(e){let r=this.abVariants[e];return r!=null?r:null}isAbVariant(e,r){return this.abVariants[e]===r}onAbTestsChange(e){return this.abTestSubscribers.add(e),()=>this.abTestSubscribers.delete(e)}async fetchAbTests(e){if(!this.cfg.endpoint||!this.cfg.secretKey)return;let r=rt(this.cfg.endpoint)+"/ab-tests/evaluate";try{let i={visitorId:this.session.visitorId};e!=null&&e.length&&(i.keys=e);let n=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${this.cfg.secretKey}`},body:JSON.stringify(i)});if(!n.ok)return;let o=await n.json();this.abVariants=e!=null&&e.length?{...this.abVariants,...o}:{...o},this.abTestSubscribers.forEach(a=>a({...this.abVariants}));}catch(i){}}getSession(){return this.session}getPageViews(){return [...this.session.pageViews]}getTimeSpent(){return {...this.session.timeSpent}}getHeatmapData(e){var r;return e!==void 0?[...(r=this.session.heatmap[e])!=null?r:[]]:Object.entries(this.session.heatmap).reduce((i,[n,o])=>(i[n]=[...o],i),{})}flush(){this.flushQueue();}async flushQueue(){if(this.queue.length===0)return;let e=this.queue.splice(0);await this.sendBatch(e);}flushBeacon(){if(this.queue.length===0)return;let e=this.queue.splice(0),r=`${this.cfg.endpoint}/batch`,i=new Blob([this.buildBatchBody(e)],{type:"application/json"});typeof navigator!="undefined"&&navigator.sendBeacon?navigator.sendBeacon(r,i):this.sendBatch(e);}buildBatchBody(e){return JSON.stringify({...this.cfg.appId?{appId:this.cfg.appId}:{},visitorId:this.session.visitorId,events:e.map(r=>({sessionId:this.session.id,type:r.type,data:r.data}))})}async sendBatch(e){let r=`${this.cfg.endpoint}/batch`,i=this.cfg.secretKey?{Authorization:`Bearer ${this.cfg.secretKey}`}:{};try{await fetch(r,{method:"POST",headers:{"Content-Type":"application/json",...i},body:this.buildBatchBody(e),keepalive:!0});}catch(n){}}};/*! Bundled license information:
6
+
7
+ rrweb/es/rrweb/ext/tslib/tslib.es6.js:
8
+ (*! *****************************************************************************
9
+ Copyright (c) Microsoft Corporation.
10
+
11
+ Permission to use, copy, modify, and/or distribute this software for any
12
+ purpose with or without fee is hereby granted.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
15
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
16
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
17
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
18
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20
+ PERFORMANCE OF THIS SOFTWARE.
21
+ ***************************************************************************** *)
22
+ */exports.ALPHANA_SDK_VERSION=St;exports.DEFAULT_ENDPOINT=hr;exports.LogCapture=ke;exports.UserTracker=bt;exports.normalizeTrackerPath=R;//# sourceMappingURL=index.js.map
3
23
  //# sourceMappingURL=index.js.map