@amplitude/plugin-session-replay-browser 1.37.0-codexsemantic-review-integration.0 → 1.37.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.
@@ -1,2 +1,2 @@
1
- function e(e,t){return t.forEach(function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach(function(n){if("default"!==n&&!(n in e)){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}})}),Object.freeze(e)}var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)};function n(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var r,i,o=function(){return o=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},o.apply(this,arguments)};function s(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n}function a(e,t,n,r){return new(n||(n=Promise))(function(i,o){function s(e){try{l(r.next(e))}catch(e){o(e)}}function a(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}l((r=r.apply(e,t||[])).next())})}function l(e,t){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=t.call(e,o)}catch(e){a=[6,e],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,l])}}}function c(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function u(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,i,o=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}function d(e,t,n){if(n||2===arguments.length)for(var r,i=0,o=t.length;i<o;i++)!r&&i in t||(r||(r=Array.prototype.slice.call(t,0,i)),r[i]=t[i]);return e.concat(r||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError,function(e){e.SET="$set",e.SET_ONCE="$setOnce",e.ADD="$add",e.APPEND="$append",e.PREPEND="$prepend",e.REMOVE="$remove",e.PREINSERT="$preInsert",e.POSTINSERT="$postInsert",e.UNSET="$unset",e.CLEAR_ALL="$clearAll"}(r||(r={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(i||(i={}));var v,h="$default_instance",f="https://api2.amplitude.com/2/httpapi";!function(e){e.Unknown="unknown",e.Skipped="skipped",e.Success="success",e.RateLimit="rate_limit",e.PayloadTooLarge="payload_too_large",e.Invalid="invalid",e.Failed="failed",e.Timeout="Timeout",e.SystemError="SystemError"}(v||(v={}));var g=function(){var e="ampIntegrationContext";return"undefined"!=typeof globalThis&&void 0!==globalThis[e]?globalThis[e]:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:void 0},p=d([],u(Array(256).keys()),!1).map(function(e){return e.toString(16).padStart(2,"0")}),m=function(e){var t,n=g();if(!(null===(t=null==n?void 0:n.crypto)||void 0===t?void 0:t.getRandomValues))return function(e){return e?(e^16*Math.random()>>e/4).toString(16):(String(1e7)+String(-1e3)+String(-4e3)+String(-8e3)+String(-1e11)).replace(/[018]/g,m)}(e);var r=n.crypto.getRandomValues(new Uint8Array(16));return r[6]=15&r[6]|64,r[8]=63&r[8]|128,d([],u(r.entries()),!1).map(function(e){var t=u(e,2),n=t[0],r=t[1];return[4,6,8,10].includes(n)?"-".concat(p[r]):p[r]}).join("")},y={},b={get exports(){return y},set exports(e){y=e}},S=Object.prototype.hasOwnProperty;function w(e){return"[Throws: "+(e?e.message:"?")+"]"}function I(e){var t=[];return function e(n){if(null===n||"object"!=typeof n)return n;if(-1!==t.indexOf(n))return"[Circular]";if(t.push(n),"function"==typeof n.toJSON)try{var r=e(n.toJSON());return t.pop(),r}catch(e){return w(e)}if(Array.isArray(n)){var i=n.map(e);return t.pop(),i}var o=Object.keys(n).reduce(function(t,r){return t[r]=e(function(e,t){if(S.call(e,t))try{return e[t]}catch(e){return w(e)}return e[t]}(n,r)),t},{});return t.pop(),o}(e)}b.exports=function(e,t,n){return JSON.stringify(I(e),t,n)};var C,k=y.ensureProperties=I,E=y||e({__proto__:null,ensureProperties:k,get default(){return y}},[y]),x=function(e){return{promise:e||Promise.resolve()}};!function(e){e[e.None=0]="None",e[e.Error=1]="Error",e[e.Warn=2]="Warn",e[e.Verbose=3]="Verbose",e[e.Debug=4]="Debug"}(C||(C={}));var P="Amplitude Logger ",T=function(){function e(){this.logLevel=C.None}return e.prototype.disable=function(){this.logLevel=C.None},e.prototype.enable=function(e){void 0===e&&(e=C.Warn),this.logLevel=e},e.prototype.log=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<C.Verbose||console.log("".concat(P,"[Log]: ").concat(e.join(" ")))},e.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<C.Warn||console.warn("".concat(P,"[Warn]: ").concat(e.join(" ")))},e.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<C.Error||console.error("".concat(P,"[Error]: ").concat(e.join(" ")))},e.prototype.debug=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<C.Debug||console.log("".concat(P,"[Debug]: ").concat(e.join(" ")))},e}(),M=function(e){return void 0===e||""===e?h:e},R=function(){return{flushMaxRetries:12,flushQueueSize:200,flushIntervalMillis:1e4,instanceName:h,logLevel:C.Warn,loggerProvider:new T,offline:!1,optOut:!1,serverUrl:f,serverZone:"US",useBatch:!1}},O=function(){function e(e){var t,n,r,i;this._optOut=!1;var o=R();this.apiKey=e.apiKey,this.flushIntervalMillis=null!==(t=e.flushIntervalMillis)&&void 0!==t?t:o.flushIntervalMillis,this.flushMaxRetries=e.flushMaxRetries||o.flushMaxRetries,this.flushQueueSize=e.flushQueueSize||o.flushQueueSize,this.instanceName=M(e.instanceName),this.loggerProvider=e.loggerProvider||o.loggerProvider,this.logLevel=null!==(n=e.logLevel)&&void 0!==n?n:o.logLevel,this.minIdLength=e.minIdLength,this.plan=e.plan,this.ingestionMetadata=e.ingestionMetadata,this.offline=void 0!==e.offline?e.offline:o.offline,this.optOut=null!==(r=e.optOut)&&void 0!==r?r:o.optOut,this.serverUrl=e.serverUrl,this.serverZone=e.serverZone||o.serverZone,this.storageProvider=e.storageProvider,this.transportProvider=e.transportProvider,this.useBatch=null!==(i=e.useBatch)&&void 0!==i?i:o.useBatch,this.loggerProvider.enable(this.logLevel);var s=A(e.serverUrl,e.serverZone,e.useBatch);this.serverZone=s.serverZone,this.serverUrl=s.serverUrl}return Object.defineProperty(e.prototype,"optOut",{get:function(){return this._optOut},set:function(e){this._optOut=e},enumerable:!1,configurable:!0}),e}(),_=function(e,t){return"EU"===e?t?"https://api.eu.amplitude.com/batch":"https://api.eu.amplitude.com/2/httpapi":t?"https://api2.amplitude.com/batch":f},A=function(e,t,n){if(void 0===e&&(e=""),void 0===t&&(t=R().serverZone),void 0===n&&(n=R().useBatch),e)return{serverUrl:e,serverZone:void 0};var r=["US","EU"].includes(t)?t:R().serverZone;return{serverZone:r,serverUrl:_(r,n)}};var L=function(e,t,n,r,i){return void 0===i&&(i=null),function(){for(var o=[],s=0;s<arguments.length;s++)o[s]=arguments[s];var a=n(),l=a.logger,c=a.logLevel;if(c&&c<C.Debug||!c||!l)return e.apply(i,o);var u,d={type:"invoke public method",name:t,args:o,stacktrace:(u=1,void 0===u&&(u=0),((new Error).stack||"").split("\n").slice(2+u).map(function(e){return e.trim()})),time:{start:(new Date).toISOString()},states:{}};r&&d.states&&(d.states.before=r());var v=e.apply(i,o);return v&&v.promise?v.promise.then(function(){r&&d.states&&(d.states.after=r()),d.time&&(d.time.end=(new Date).toISOString()),l.debug(JSON.stringify(d,null,2))}):(r&&d.states&&(d.states.after=r()),d.time&&(d.time.end=(new Date).toISOString()),l.debug(JSON.stringify(d,null,2))),v}};class F{getApplicationContext(){return{versionName:this.versionName,language:N(),platform:"Web",os:void 0,deviceModel:void 0}}}const N=()=>"undefined"!=typeof navigator&&(navigator.languages&&navigator.languages[0]||navigator.language)||"";class D{constructor(){this.queue=[]}logEvent(e){this.receiver?this.receiver(e):this.queue.length<512&&this.queue.push(e)}setEventReceiver(e){this.receiver=e,this.queue.length>0&&(this.queue.forEach(t=>{e(t)}),this.queue=[])}}const q=(e,t)=>{const n=["string","number","boolean","undefined"],r=typeof e;if(r!==typeof t)return!1;for(const i of n)if(i===r)return e===t;if(null==e&&null==t)return!0;if(null==e||null==t)return!1;if(e.length!==t.length)return!1;const i=Array.isArray(e),o=Array.isArray(t);if(i!==o)return!1;if(!i||!o){const n=Object.keys(e).sort(),r=Object.keys(t).sort();if(!q(n,r))return!1;let i=!0;return Object.keys(e).forEach(n=>{q(e[n],t[n])||(i=!1)}),i}for(let n=0;n<e.length;n++)if(!q(e[n],t[n]))return!1;return!0};Object.entries||(Object.entries=function(e){const t=Object.keys(e);let n=t.length;const r=new Array(n);for(;n--;)r[n]=[t[n],e[t[n]]];return r});class U{constructor(){this.identity={userProperties:{}},this.listeners=new Set}editIdentity(){const e=this,t=Object.assign({},this.identity.userProperties),n=Object.assign(Object.assign({},this.identity),{userProperties:t});return{setUserId:function(e){return n.userId=e,this},setDeviceId:function(e){return n.deviceId=e,this},setUserProperties:function(e){return n.userProperties=e,this},setOptOut(e){return n.optOut=e,this},updateUserProperties:function(e){let t=n.userProperties||{};for(const[n,r]of Object.entries(e))switch(n){case"$set":for(const[e,n]of Object.entries(r))t[e]=n;break;case"$unset":for(const e of Object.keys(r))delete t[e];break;case"$clearAll":t={}}return n.userProperties=t,this},commit:function(){return e.setIdentity(n),this}}}getIdentity(){return Object.assign({},this.identity)}setIdentity(e){const t=Object.assign({},this.identity);this.identity=Object.assign({},e),q(t,this.identity)||this.listeners.forEach(t=>{t(e)})}addIdentityListener(e){this.listeners.add(e)}removeIdentityListener(e){this.listeners.delete(e)}}const j="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:self;class B{constructor(){this.identityStore=new U,this.eventBridge=new D,this.applicationContextProvider=new F}static getInstance(e){return j.analyticsConnectorInstances||(j.analyticsConnectorInstances={}),j.analyticsConnectorInstances[e]||(j.analyticsConnectorInstances[e]=new B),j.analyticsConnectorInstances[e]}}var W=function(e){return B.getInstance(M(e))},z=function(e){var t=0;if(0===e.length)return t;for(var n=0;n<e.length;n++){t=(t<<5)-t+e.charCodeAt(n),t|=0}return t},K=function(){function e(){}return e.prototype.send=function(e,t,n){return Promise.resolve(null)},e.prototype.buildResponse=function(e){var t,n,r,i,o,s,a,l,c,u,d,h,f,g,p,m,y,b,S,w,I,C;if("object"!=typeof e)return null;var k=e.code||0,E=this.buildStatus(k);switch(E){case v.Success:return{status:E,statusCode:k,body:{eventsIngested:null!==(t=e.events_ingested)&&void 0!==t?t:0,payloadSizeBytes:null!==(n=e.payload_size_bytes)&&void 0!==n?n:0,serverUploadTime:null!==(r=e.server_upload_time)&&void 0!==r?r:0}};case v.Invalid:return{status:E,statusCode:k,body:{error:null!==(i=e.error)&&void 0!==i?i:"",missingField:null!==(o=e.missing_field)&&void 0!==o?o:"",eventsWithInvalidFields:null!==(s=e.events_with_invalid_fields)&&void 0!==s?s:{},eventsWithMissingFields:null!==(a=e.events_with_missing_fields)&&void 0!==a?a:{},eventsWithInvalidIdLengths:null!==(l=e.events_with_invalid_id_lengths)&&void 0!==l?l:{},epsThreshold:null!==(c=e.eps_threshold)&&void 0!==c?c:0,exceededDailyQuotaDevices:null!==(u=e.exceeded_daily_quota_devices)&&void 0!==u?u:{},silencedDevices:null!==(d=e.silenced_devices)&&void 0!==d?d:[],silencedEvents:null!==(h=e.silenced_events)&&void 0!==h?h:[],throttledDevices:null!==(f=e.throttled_devices)&&void 0!==f?f:{},throttledEvents:null!==(g=e.throttled_events)&&void 0!==g?g:[]}};case v.PayloadTooLarge:return{status:E,statusCode:k,body:{error:null!==(p=e.error)&&void 0!==p?p:""}};case v.RateLimit:return{status:E,statusCode:k,body:{error:null!==(m=e.error)&&void 0!==m?m:"",epsThreshold:null!==(y=e.eps_threshold)&&void 0!==y?y:0,throttledDevices:null!==(b=e.throttled_devices)&&void 0!==b?b:{},throttledUsers:null!==(S=e.throttled_users)&&void 0!==S?S:{},exceededDailyQuotaDevices:null!==(w=e.exceeded_daily_quota_devices)&&void 0!==w?w:{},exceededDailyQuotaUsers:null!==(I=e.exceeded_daily_quota_users)&&void 0!==I?I:{},throttledEvents:null!==(C=e.throttled_events)&&void 0!==C?C:[]}};case v.Timeout:default:return{status:E,statusCode:k}}},e.prototype.buildStatus=function(e){return function(e){return e>=200&&e<300}(e)?v.Success:429===e?v.RateLimit:413===e?v.PayloadTooLarge:408===e?v.Timeout:e>=400&&e<500?v.Invalid:e>=500?v.Failed:v.Unknown},e}(),H=function(e){function t(t){void 0===t&&(t={});var n=e.call(this)||this;return n.customHeaders=t,n}return n(t,e),t.prototype.send=function(e,t){return a(this,void 0,void 0,function(){var n,r,i;return l(this,function(s){switch(s.label){case 0:if("undefined"==typeof fetch)throw new Error("FetchTransport is not supported");return n={headers:o({"Content-Type":"application/json",Accept:"*/*"},this.customHeaders),body:JSON.stringify(t),method:"POST"},[4,fetch(e,n)];case 1:return[4,(r=s.sent()).text()];case 2:i=s.sent();try{return[2,this.buildResponse(JSON.parse(i))]}catch(e){return[2,this.buildResponse({code:r.status})]}return[2]}})})},t}(K),$=function(){function e(e,t){this.key="AMP_remote_config_".concat(e.substring(0,10)),this.logger=t;try{this.isSupported="undefined"!=typeof localStorage}catch(e){this.logger.debug("Remote config localstorage failed to access: ",e),this.isSupported=!1}}return e.prototype.fetchConfig=function(){var e=null,t={remoteConfig:null,lastFetch:new Date};if(!this.isSupported)return Promise.resolve(t);try{e=localStorage.getItem(this.key)}catch(e){return this.logger.debug("Remote config localstorage failed to access: ",e),Promise.resolve(t)}if(null===e)return this.logger.debug("Remote config localstorage gets null because the key does not exist"),Promise.resolve(t);try{var n=JSON.parse(e);return this.logger.debug("Remote config localstorage parsed successfully: ".concat(E(n))),Promise.resolve({remoteConfig:n.remoteConfig,lastFetch:new Date(n.lastFetch)})}catch(e){return this.logger.debug("Remote config localstorage failed to parse: ",e),localStorage.removeItem(this.key),Promise.resolve(t)}},e.prototype.setConfig=function(e){if(!this.isSupported)return Promise.resolve(!1);try{return localStorage.setItem(this.key,JSON.stringify(e)),this.logger.debug("Remote config localstorage set successfully."),Promise.resolve(!0)}catch(e){this.logger.debug("Remote config localstorage failed to set: ",e)}return Promise.resolve(!1)},e}();var G,J=401,Q=403,V=429,Z=function(){function e(t,n,r,i,o,s,a){void 0===r&&(r="US"),void 0===s&&(s=e.DEFAULT_CONFIG_GROUP),this.callbackInfos=[],this.lastSuccessfulFetch=null,this.fetchPromise=null,this.isLastFetchInvalidApiKey=!1,this.apiKey=t,this.configGroup=s,this.serverUrl=i||("US"===r?"https://sr-client-cfg.amplitude.com/config":"https://sr-client-cfg.eu.amplitude.com/config"),this.logger=n,this.storage=a||new $(t,n),this.customFetch=o}return e.prototype.subscribe=function(e,t,n){var r=m(),i={id:r,key:e,deliveryMode:t,callback:n};return this.callbackInfos.push(i),"all"===t?this.subscribeAll(i):this.subscribeWaitForRemote(i,t.timeout),r},e.prototype.unsubscribe=function(e){var t=this.callbackInfos.findIndex(function(t){return t.id===e});return-1===t?(this.logger.debug("Remote config client unsubscribe failed because callback with id ".concat(e," doesn't exist.")),!1):(this.callbackInfos.splice(t,1),this.logger.debug("Remote config client unsubscribe succeeded removing callback with id ".concat(e,".")),!0)},e.prototype.updateConfigs=function(){return a(this,void 0,void 0,function(){var e,t=this;return l(this,function(n){switch(n.label){case 0:return this.lastSuccessfulFetch&&Date.now()-this.lastSuccessfulFetch<3e5?(this.logger.debug("Remote config client skipping updateConfigs: Too recent"),[2]):[4,this.getOrCreateFetchPromise()];case 1:return e=n.sent(),this.storage.setConfig(e),this.callbackInfos.forEach(function(n){t.sendCallback(n,e,"remote")}),[2]}})})},e.prototype.getOrCreateFetchPromise=function(){var e=this;return this.fetchPromise?this.fetchPromise:this.isLastFetchInvalidApiKey?(this.logger.debug("Remote config client skipping fetch: Invalid API key"),this.fetchPromise=Promise.resolve({remoteConfig:null,lastFetch:new Date}).finally(function(){e.fetchPromise=null}),this.fetchPromise):(this.fetchPromise=this.fetch().then(function(t){return null!==t.remoteConfig&&(e.lastSuccessfulFetch=Date.now()),t}).finally(function(){e.fetchPromise=null}),this.fetchPromise)},e.prototype.subscribeAll=function(e){return a(this,void 0,void 0,function(){var t,n,r,i=this;return l(this,function(o){switch(o.label){case 0:return t=this.getOrCreateFetchPromise().then(function(t){i.logger.debug("Remote config client subscription all mode fetched from remote: ".concat(JSON.stringify(t))),i.sendCallback(e,t,"remote"),i.storage.setConfig(t)}),n=this.storage.fetchConfig().then(function(e){return e}),[4,Promise.race([t,n])];case 1:return void 0!==(r=o.sent())&&(this.logger.debug("Remote config client subscription all mode fetched from cache: ".concat(JSON.stringify(r))),null!==r.remoteConfig?this.sendCallback(e,r,"cache"):this.logger.debug("Remote config client skips sending callback because cache is empty (first time user).")),[4,t];case 2:return o.sent(),[2]}})})},e.prototype.subscribeWaitForRemote=function(e,t){return a(this,void 0,void 0,function(){var n,r;return l(this,function(i){switch(i.label){case 0:n=new Promise(function(e,n){setTimeout(function(){n("Timeout exceeded")},t)}),i.label=1;case 1:return i.trys.push([1,3,,5]),[4,Promise.race([this.getOrCreateFetchPromise(),n])];case 2:return r=i.sent(),this.logger.debug("Remote config client subscription wait for remote mode returns from remote."),this.sendCallback(e,r,"remote"),this.storage.setConfig(r),[3,5];case 3:return i.sent(),this.logger.debug("Remote config client subscription wait for remote mode exceeded timeout. Try to fetch from cache."),[4,this.storage.fetchConfig()];case 4:return null!==(r=i.sent()).remoteConfig?(this.logger.debug("Remote config client subscription wait for remote mode returns a cached copy."),this.sendCallback(e,r,"cache")):(this.logger.debug("Remote config client subscription wait for remote mode failed to fetch cache."),this.sendCallback(e,r,"remote")),[3,5];case 5:return[2]}})})},e.prototype.sendCallback=function(e,t,n){var r;e.lastCallback=new Date,r=e.key?e.key.split(".").reduce(function(e,t){return null===e?e:t in e?e[t]:null},t.remoteConfig):t.remoteConfig,e.callback(r,n,t.lastFetch)},e.prototype.fetch=function(e,t){return void 0===e&&(e=3),void 0===t&&(t=1e3),a(this,void 0,void 0,function(){var n,r,i,o,s,a,c=this;return l(this,function(u){switch(u.label){case 0:n=t/e,r={remoteConfig:null,lastFetch:new Date},i=function(r){var i,s,a,u,d,v,h,f,g;return l(this,function(l){switch(l.label){case 0:i=!0,s=new AbortController,a=setTimeout(function(){return s.abort()},t),l.label=1;case 1:return l.trys.push([1,10,11,12]),u=o.getUrlParams(),d={Accept:"*/*"},o.customFetch?[4,(p=o.customFetch({url:u,method:"GET",headers:d,signal:s.signal}),m=s.signal,new Promise(function(e,t){var n=function(){var e=new Error("Remote config custom fetch aborted by timeout");e.name="AbortError",t(e)};m.addEventListener("abort",n,{once:!0}),p.then(function(t){m.removeEventListener("abort",n),e(t)},function(e){m.removeEventListener("abort",n),t(e)})}))]:[3,3];case 2:return h=l.sent(),[3,5];case 3:return[4,fetch(u,{method:"GET",headers:d,signal:s.signal})];case 4:h=l.sent(),l.label=5;case 5:return(v=h).ok||v.status>=200&&v.status<300?[3,7]:[4,v.text()];case 6:return f=l.sent(),o.logger.debug("Remote config client fetch with retry time ".concat(e," failed with ").concat(v.status,": ").concat(f)),v.status===J||v.status===Q?(o.logger.error("Remote config client fetch failed with ".concat(v.status,". Invalid API key; future fetches will be skipped.")),o.isLastFetchInvalidApiKey=!0,i=!1):v.status>=400&&v.status<500&&v.status!==V&&(i=!1),[3,9];case 7:return[4,v.json()];case 8:return[2,{value:{remoteConfig:l.sent(),lastFetch:new Date}}];case 9:return[3,12];case 10:return(g=l.sent())instanceof Error&&"AbortError"===g.name?o.logger.debug("Remote config client fetch with retry time ".concat(e," timed out after ").concat(t,"ms")):o.logger.debug("Remote config client fetch with retry time ".concat(e," is rejected because: "),g),[3,12];case 11:return clearTimeout(a),[7];case 12:return i?r<e-1?[4,new Promise(function(e){return setTimeout(e,c.getJitterDelay(n))})]:[3,14]:[2,"break"];case 13:l.sent(),l.label=14;case 14:return[2]}var p,m})},o=this,s=0,u.label=1;case 1:return s<e?[5,i(s)]:[3,4];case 2:if("object"==typeof(a=u.sent()))return[2,a.value];if("break"===a)return[3,4];u.label=3;case 3:return s++,[3,1];case 4:return[2,r]}})})},e.prototype.getJitterDelay=function(e){return Math.floor(Math.random()*e)},e.prototype.getUrlParams=function(){var e=encodeURIComponent(this.apiKey),t=new URLSearchParams;return t.append("config_group",this.configGroup),"".concat(this.serverUrl,"/").concat(e,"?").concat(t.toString())},e.DEFAULT_CONFIG_GROUP="browser",e}();!function(e){e.US="US",e.EU="EU",e.STAGING="STAGING"}(G||(G={}));var X,Y="https://app.amplitude.com",ee={US:Y,EU:"https://app.eu.amplitude.com",STAGING:"https://apps.stag2.amplitude.com"};var te="__AMPLITUDE_MESSENGER_INSTANCE__",ne="__AMPLITUDE_MESSENGER__",re=function(){function e(e){var t=(void 0===e?{}:e).origin,n=void 0===t?Y:t;this[X]=!0,this.isSetup=!1,this.messageHandler=null,this.requestCallbacks={},this.actionHandlers=new Map,this.pendingMessages=new Map,this.scriptLoadPromises=new Map,this.endpoint=n}return e.prototype.notify=function(e){var t,n,r,i;null===(n=null===(t=this.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Message sent: ",JSON.stringify(e)),null===(i=null===(r=window.opener)||void 0===r?void 0:r.postMessage)||void 0===i||i.call(r,e,this.endpoint)},e.prototype.sendRequest=function(e,t,n){var r=this;void 0===n&&(n={timeout:15e3});var i="".concat(Date.now(),"-").concat(Math.random().toString(36).substr(2,9)),o={id:i,action:e,args:t};return new Promise(function(t,s){r.requestCallbacks[i]={resolve:t,reject:s},r.notify(o),n.timeout>0&&setTimeout(function(){s(new Error("".concat(e," timed out (id: ").concat(i,")"))),delete r.requestCallbacks[i]},n.timeout)})},e.prototype.handleResponse=function(e){var t;this.requestCallbacks[e.id]?(this.requestCallbacks[e.id].resolve(e.responseData),delete this.requestCallbacks[e.id]):null===(t=this.logger)||void 0===t||t.warn("No callback found for request id: ".concat(e.id))},e.prototype.registerActionHandler=function(e,t){var n,r,i,o;this.actionHandlers.has(e)&&(null===(o=null===(i=this.logger)||void 0===i?void 0:i.warn)||void 0===o||o.call(i,"Overwriting existing action handler for: ".concat(e))),this.actionHandlers.set(e,t);var s=this.pendingMessages.get(e);if(s){this.pendingMessages.delete(e);try{for(var a=c(s),l=a.next();!l.done;l=a.next()){t(l.value)}}catch(e){n={error:e}}finally{try{l&&!l.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}}},e.prototype.loadScriptOnce=function(e){return a(this,void 0,void 0,function(){var t,n,r;return l(this,function(i){switch(i.label){case 0:if(t=this.scriptLoadPromises.get(e))return[2,t];n=function(e){return document.querySelector('script[src="'.concat(CSS.escape(e),'"]'))?Promise.resolve({status:!0}):new Promise(function(t,n){var r;try{var i=document.createElement("script");i.type="text/javascript",i.async=!0,i.src=e,i.addEventListener("load",function(){t({status:!0})},{once:!0}),i.addEventListener("error",function(){n({status:!1,message:"Failed to load the script ".concat(e)})}),null===(r=document.head)||void 0===r||r.appendChild(i)}catch(e){n(e)}})}(e).then(function(){}),this.scriptLoadPromises.set(e,n),i.label=1;case 1:return i.trys.push([1,3,,4]),[4,n];case 2:return i.sent(),[3,4];case 3:throw r=i.sent(),this.scriptLoadPromises.delete(e),r;case 4:return[2]}})})},e.prototype.setup=function(e){var t,n,r=this,i=void 0===e?{}:e,o=i.logger,s=i.endpoint;o&&(this.logger=o),s&&this.endpoint===Y&&(this.endpoint=s),this.isSetup||(this.isSetup=!0,null===(n=null===(t=this.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Setting up messenger"),this.messageHandler=function(e){var t,n,i,o,s;if(null===(n=null===(t=r.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Message received: ",JSON.stringify(e)),r.endpoint===e.origin){var a=e.data,l=null==a?void 0:a.action;if(l)if("id"in a&&a.id)null===(o=null===(i=r.logger)||void 0===i?void 0:i.debug)||void 0===o||o.call(i,"Received Response to previous request: ",JSON.stringify(e)),r.handleResponse(a);else{if("ping"===l)return void r.notify({action:"pong"});var c=r.actionHandlers.get(l);if(c)c(a.data);else{var u=null!==(s=r.pendingMessages.get(l))&&void 0!==s?s:[];u.push(a.data),r.pendingMessages.set(l,u)}}}},window.addEventListener("message",this.messageHandler),this.notify({action:"page-loaded"}))},e.prototype.destroy=function(){this.messageHandler&&(window.removeEventListener("message",this.messageHandler),this.messageHandler=null),this.isSetup=!1,this.actionHandlers.clear(),this.pendingMessages.clear(),this.requestCallbacks={},this.scriptLoadPromises.clear();var e=g();(null==e?void 0:e[ne])===this&&delete e[ne]},e}();function ie(e){var t,n=g(),r=null==n?void 0:n[ne];if("object"==typeof(t=r)&&null!==t&&te in t&&!0===t[te])return r;var i=new re(e);return n&&(n[ne]=i),i}X=te;var oe=["desktop","tablet","mobile"],se="__AMPLITUDE_BACKGROUND_CAPTURE__";function ae(e,t){var n,r=e;if(!0!==r[se]){r[se]=!0;var i=null!==(n=null==t?void 0:t.scriptUrl)&&void 0!==n?n:"https://cdn.amplitude.com/libs/background-capture-1.1.0.js.gz",s=null,a=function(t,n){var r,i;"background-capture-complete"===t&&(null===(i=null===(r=e.logger)||void 0===r?void 0:r.debug)||void 0===i||i.call(r,"Background capture complete"),e.notify({action:"background-capture-complete",data:n}))};e.registerActionHandler("initialize-background-capture",function(t){var n,r;null===(r=null===(n=e.logger)||void 0===n?void 0:n.debug)||void 0===r||r.call(n,"Initializing background capture (external script)");var l=new URL(i,e.endpoint).toString(),c=t&&"object"==typeof t?function(e){if("string"==typeof e)return oe.includes(e)?e:void 0}(t.deviceMode):void 0;e.loadScriptOnce(l).then(function(){var t,n,r;null===(n=null===(t=e.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Background capture script loaded (external)"),s=null===(r=null===window||void 0===window?void 0:window.amplitudeBackgroundCapture)||void 0===r?void 0:r.call(window,o({messenger:e,onBackgroundCapture:a},void 0!==c?{initialDeviceMode:c}:{})),e.notify({action:"background-capture-loaded"})}).catch(function(){var t;null===(t=e.logger)||void 0===t||t.warn("Failed to initialize background capture")})}),e.registerActionHandler("close-background-capture",function(){var e;null===(e=null==s?void 0:s.close)||void 0===e||e.call(s),s=null})}}var le,ce="[Amplitude]",ue="".concat(ce," Session Replay ID"),de=G.US,ve={enabled:!0},he=1e3,fe="".concat(ce," Session Replay Debug"),ge="https://api-sr.amplitude.com/sessions/v2/track",pe="https://api-sr.eu.amplitude.com/sessions/v2/track",me="https://api-sr.stag2.amplitude.com/sessions/v2/track",ye=9e6,be=/payload.*exceed/i,Se=500,we=1e4,Ie=1024,Ce="X-Session-Replay-Event-Skipped",ke="amplitude-sr-iframe";!function(e){e.GET_SR_PROPS="get-sr-props",e.DEBUG_INFO="debug-info",e.FETCH_REQUEST="fetch-request",e.METADATA="metadata",e.TARGETING_DECISION="targeting-decision",e.REPLAY_GATE_DECISION="replay-gate-decision"}(le||(le={}));var Ee=function(){function e(e){this.logger=e,this.log=this.getSafeMethod("log"),this.warn=this.getSafeMethod("warn"),this.error=this.getSafeMethod("error"),this.debug=this.getSafeMethod("debug")}return e.prototype.getSafeMethod=function(e){var t;if(!this.logger)return function(){};var n=this.logger[e];return"function"==typeof n?(null!==(t=n.__rrweb_original__)&&void 0!==t?t:n).bind(this.logger):function(){}},e.prototype.enable=function(e){this.logger.enable(e)},e.prototype.disable=function(){this.logger.disable()},e}(),xe="medium";function Pe(e){var t=e.type;return e.hasAttribute("data-rr-is-password")?"password":t?t.toLowerCase():null}var Te=new Map,Me=function(e){var t=Te.get(e);if(t)return t;var n="\0TRAIL\0",r="\0MID\0",i="\0DS\0",o="\0ST\0",s="\0QU\0",a=e;a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=a.replace(/\/\*\*$/,n)).replace(/\/\*\*\//g,r)).replace(/\*\*/g,i)).replace(/\*/g,o)).replace(/\?/g,s)).replace(/[.+^${}()|[\]\\]/g,"\\$&")).split(n).join("(/.*)?")).split(r).join("/(.*\\/)?")).split(i).join(".*")).split(o).join(".*")).split(s).join(".");var l=new RegExp("^".concat(a,"$"));return Te.set(e,l),l},Re=function(e,t,n){var r;switch(t){case"light":if("input"!==e)return!1;var i=n?Pe(n):"";return!!i&&(!!["password","hidden","email","tel"].includes(i)||!!(null===(r=n.autocomplete)||void 0===r?void 0:r.startsWith("cc-")));case"medium":return"input"===e;case"conservative":return!0;default:return Re(e,xe,n)}},Oe=function(e,t){var n,r,i;if(e&&t.urlMaskLevels)try{for(var o=c(t.urlMaskLevels),s=o.next();!s.done;s=o.next()){var a=s.value;if(Me(a.match).test(e))return a.maskLevel}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}return null!==(i=t.defaultMaskLevel)&&void 0!==i?i:xe},_e=function(e,t,n,r){var i,o;if(void 0===t&&(t={defaultMaskLevel:xe}),n){if(n.closest(".amp-mask, [data-amp-mask]"))return!0;var s=(null!==(i=t.maskSelector)&&void 0!==i?i:[]).some(function(e){return n.closest(e)});if(s)return!0;if(n.closest(".amp-unmask, [data-amp-unmask]"))return!1;var a=(null!==(o=t.unmaskSelector)&&void 0!==o?o:[]).some(function(e){return n.closest(e)});if(a)return!1}return Re(e,Oe(r,t),n)},Ae=function(e,t,n){return function(r,i){return _e(e,t,i,null==n?void 0:n())?r.replace(/[^\s]/g,"*"):r}},Le=function(e,t){return function(n,r,i){var o;if("style"===n)return r;if(!(null!==(o=null==e?void 0:e.maskAttributes)&&void 0!==o?o:[]).includes(n))return r;var s=["INPUT","SELECT","TEXTAREA"].includes(i.tagName)?"input":"text";return _e(s,e,i,null==t?void 0:t())?r.replace(/[^\s]/g,"*"):r}},Fe=function(e){var t=null==e?void 0:e.blockSelector;return d(d([],u("string"==typeof t?t?[t]:[]:null!=t?t:[]),!1),["[data-amp-block]"],!1).join(",")},Ne=function(e,t){var n,r;return e&&("conservative"===Oe(t,e)||"conservative"===e.defaultMaskLevel||(null===(n=e.urlMaskLevels)||void 0===n?void 0:n.some(function(e){return"conservative"===e.maskLevel})))?"*":d(d([],u(null!==(r=null==e?void 0:e.maskSelector)&&void 0!==r?r:[]),!1),["[data-amp-mask]"],!1).join(",")};function De(e,t){return t||("STAGING"===e?me:"EU"===e?pe:ge)}var qe=function(){var e=g();return(null==e?void 0:e.location)?e.location.href:""},Ue=function(e,t){var n,r;try{for(var i=c(t),o=i.next();!o.done;o=i.next()){var s=o.value,a=Me(s.selector);if(a.test(e))return e.replace(a,s.replacement)}}catch(e){n={error:e}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}return e},je=function(){return a(void 0,void 0,void 0,function(){var e,t,n,r,i,o,s;return l(this,function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),(e=g())?[4,e.navigator.storage.estimate()]:[3,2];case 1:return t=a.sent(),n=t.usage,r=t.quota,i=t.usageDetails,o=n?Math.round(n/Ie):0,s=n&&r?Math.round(1e3*(n/r+Number.EPSILON))/1e3:0,[2,{totalStorageSize:o,percentOfQuota:s,usageDetails:JSON.stringify(i)}];case 2:return[3,4];case 3:return a.sent(),[3,4];case 4:return[2,{totalStorageSize:0,percentOfQuota:0,usageDetails:""}]}})})},Be=function(e){var t=o({},e),n=t.apiKey;return t.apiKey="****".concat(n.substring(n.length-4)),t},We=function(){return{flushMaxRetries:2,logLevel:C.Warn,loggerProvider:new T,transportProvider:new H}},ze=function(e){function t(t,n){var r,i,s,a,l,c,v,h,f,g,p,m,y,b,S=this,w=We();(S=e.call(this,o(o({transportProvider:w.transportProvider,loggerProvider:new Ee(n.loggerProvider||w.loggerProvider)},n),{apiKey:t}))||this).flushMaxRetries=void 0!==n.flushMaxRetries&&n.flushMaxRetries<=w.flushMaxRetries?n.flushMaxRetries:w.flushMaxRetries,S.apiKey=t,S.sampleRate=n.sampleRate||0,S.semanticCapture=n.semanticCapture,S.semanticAnalyticsContext=n.semanticAnalyticsContext,S.serverZone=n.serverZone||de,S.configServerUrl=n.configServerUrl,S.trackServerUrl=n.trackServerUrl,S.shouldInlineStylesheet=n.shouldInlineStylesheet,S.inlineImages=n.inlineImages,S.version=n.version,S.performanceConfig=n.performanceConfig||ve,S.storeType=null!==(r=n.storeType)&&void 0!==r?r:"memory",S.applyBackgroundColorToBlockedElements=null!==(i=n.applyBackgroundColorToBlockedElements)&&void 0!==i&&i,S.enableUrlChangePolling=null!==(s=n.enableUrlChangePolling)&&void 0!==s&&s,S.urlChangePollingInterval=null!==(a=n.urlChangePollingInterval)&&void 0!==a?a:he,S.captureDocumentTitle=null!==(l=n.captureDocumentTitle)&&void 0!==l&&l,void 0!==n.fullSnapshotIntervalMs&&(S.fullSnapshotIntervalMs=n.fullSnapshotIntervalMs),void 0!==n.eagerFullSnapshotSend&&(S.eagerFullSnapshotSend=n.eagerFullSnapshotSend),S.captureFullSnapshotOnFocus=null!==(c=n.captureFullSnapshotOnFocus)&&void 0!==c&&c,void 0!==n.maxPersistedEventsSizeBytes&&(S.maxPersistedEventsSizeBytes=Je(n.maxPersistedEventsSizeBytes,He,$e,"maxPersistedEventsSizeBytes",S.loggerProvider)),void 0!==n.maxSingleEventSizeBytes&&(S.maxSingleEventSizeBytes=Je(n.maxSingleEventSizeBytes,He,Ge,"maxSingleEventSizeBytes",S.loggerProvider)),S.privacyConfig=o(o({},null!==(v=n.privacyConfig)&&void 0!==v?v:{}),{unmaskSelector:Array.from(new Set(d([".".concat("amp-unmask")],u(null!==(f=null===(h=n.privacyConfig)||void 0===h?void 0:h.unmaskSelector)&&void 0!==f?f:[]),!1)))}),n.interactionConfig&&(S.interactionConfig=n.interactionConfig,S.interactionConfig.ugcFilterRules&&function(e){if(!e.every(function(e){return"string"==typeof e.selector&&"string"==typeof e.replacement}))throw new Error("ugcFilterRules must be an array of objects with selector and replacement properties");if(!e.every(function(e){return"string"==typeof(t=e.selector)&&""!==t.trim()&&!!/^\/|^https?:\/\/[^\s]+$/.test(t);var t}))throw new Error("ugcFilterRules must be an array of objects with valid globs")}(S.interactionConfig.ugcFilterRules)),n.debugMode&&(S.debugMode=n.debugMode);var I=n;return S.useWebWorker=null===(m=null!==(g=n.useWebWorker)&&void 0!==g?g:null===(p=I.experimental)||void 0===p?void 0:p.useWebWorker)||void 0===m||m,S.enableTransportCompression=null===(y=n.enableTransportCompression)||void 0===y||y,S.sendTimeoutMs=n.sendTimeoutMs,S.captureAdoptedStyleSheets=null===(b=n.captureAdoptedStyleSheets)||void 0===b||b,n.crossOriginIframes&&(S.crossOriginIframes=n.crossOriginIframes),n.flushIntervalConfig?S.flushIntervalConfig=function(e,t){var n,r,i={};void 0!==e.minIntervalMs&&(!Number.isFinite(e.minIntervalMs)||e.minIntervalMs<Ke?(t.warn("flushIntervalConfig.minIntervalMs ".concat(e.minIntervalMs," is below floor ").concat(Ke,"ms; clamping.")),i.minIntervalMs=Ke):i.minIntervalMs=e.minIntervalMs);void 0!==e.maxIntervalMs&&(Number.isNaN(e.maxIntervalMs)||e.maxIntervalMs<Ke?(t.warn("flushIntervalConfig.maxIntervalMs ".concat(e.maxIntervalMs," is below floor ").concat(Ke,"ms; clamping.")),i.maxIntervalMs=Ke):i.maxIntervalMs=e.maxIntervalMs);if(void 0!==i.minIntervalMs||void 0!==i.maxIntervalMs){var o=null!==(n=i.minIntervalMs)&&void 0!==n?n:Se,s=null!==(r=i.maxIntervalMs)&&void 0!==r?r:we;s<o&&(void 0===i.maxIntervalMs?(t.warn("flushIntervalConfig.minIntervalMs (".concat(o,") exceeds the default maxIntervalMs (").concat(we,"); raising max to match min.")),i.maxIntervalMs=o):void 0===i.minIntervalMs?(t.warn("flushIntervalConfig.maxIntervalMs (".concat(s,") is below the default minIntervalMs (").concat(Se,"); lowering min to match max.")),i.minIntervalMs=s):(t.warn("flushIntervalConfig.maxIntervalMs (".concat(i.maxIntervalMs,") is less than minIntervalMs (").concat(i.minIntervalMs,"); raising max to match min.")),i.maxIntervalMs=i.minIntervalMs))}return i}(n.flushIntervalConfig,S.loggerProvider):S.flushIntervalConfig={minIntervalMs:1e3,maxIntervalMs:1e4},S.handleSendEvents=n.handleSendEvents,S.handleFetchConfig=n.handleFetchConfig,S}return n(t,e),t}(O),Ke=100,He=1e3,$e=8e6,Ge=1e7;function Je(e,t,n,r,i){if(Number.isFinite(e))return e<t?(i.warn("".concat(r," ").concat(e," is below floor ").concat(t,"; clamping.")),t):e>n?(i.warn("".concat(r," ").concat(e," exceeds ceiling ").concat(n,"; clamping.")),n):e;i.warn("".concat(r," value is not a finite number (got ").concat(String(e),"); ignoring."))}var Qe=new Set(["button","checkbox","combobox","link","listbox","menuitem","menuitemcheckbox","menuitemradio","option","radio","searchbox","slider","spinbutton","switch","tab","textbox","treeitem","gridcell"]),Ve=new Set(["banner","navigation","main","complementary","contentinfo","search","form","region","dialog","alertdialog","list","table","row","group"]),Ze=new Set(["button","cell","checkbox","columnheader","gridcell","heading","link","menuitem","menuitemcheckbox","menuitemradio","option","radio","rowheader","switch","tab","tooltip","treeitem","alert","status","listitem"]),Xe=new Set(["INPUT","SELECT","TEXTAREA"]),Ye=["type","name","href","target","aria-controls","aria-haspopup","data-testid"];function et(e,t){var n=e.replace(/\s+/g," ").trim();return n.length>t?n.slice(0,t-1)+"…":n}function tt(e,t){void 0===t&&(t="https://semantic.invalid/");try{var n=new URL(e,t);if("http:"!==n.protocol&&"https:"!==n.protocol)return"/";var r=/^#!?\//.test(n.hash)?"#"+n.hash.slice(1).split(/[?#]/)[0]:"",i=function(e){return e.split("/").map(function(e){var t;try{t=decodeURIComponent(e)}catch(e){return":id"}return/^\d+$/.test(t)||/^[\da-f]{8,}$/i.test(t)||/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/i.test(t)||t.length>=16&&/^[a-z\d]+$/i.test(t)&&/[a-z]/i.test(t)&&/\d/.test(t)?":id":e}).join("/")};return i(n.pathname)+i(r)}catch(e){return"/"}}function nt(e){var t,n,r,i,o=null===(t=e.getAttribute("role"))||void 0===t?void 0:t.trim().split(/\s+/)[0].toLowerCase();if(o)return"none"===o||"presentation"===o?"generic":o;var s=e.tagName.toLowerCase();if("a"===s||"area"===s)return e.hasAttribute("href")?"link":"generic";if("input"===s){return null!==(r={button:"button",image:"button",reset:"button",submit:"button",file:"button",checkbox:"checkbox",radio:"radio",range:"slider",number:"spinbutton",search:"searchbox",hidden:"generic"}[(null!==(n=e.getAttribute("type"))&&void 0!==n?n:"text").toLowerCase()])&&void 0!==r?r:e.hasAttribute("list")?"combobox":"textbox"}if("select"===s)return e.multiple||e.size>1?"listbox":"combobox";return/^h[1-6]$/.test(s)?"heading":"section"===s?e.hasAttribute("aria-label")||e.hasAttribute("aria-labelledby")?"region":"generic":null!==(i={button:"button",summary:"button",textarea:"textbox",nav:"navigation",main:"main",form:"form",header:"banner",footer:"contentinfo",aside:"complementary",dialog:"dialog",ul:"list",ol:"list",menu:"list",li:"listitem",table:"table",tr:"row",td:"cell",th:"columnheader",img:"img",option:"option",progress:"progressbar",output:"status",fieldset:"group",details:"group",optgroup:"group"}[s])&&void 0!==i?i:"generic"}function rt(e){var t,n=null===(t=e.getAttribute("aria-invalid"))||void 0===t?void 0:t.trim().toLowerCase();return!!n&&"false"!==n}function it(e){var t=function(t){try{var n=e.getPrivacy().blockSelector;return!!t.closest(d([".amp-block","[data-amp-block]"],u("string"==typeof n?[n]:null!=n?n:[]),!1).join(","))}catch(e){return!0}},n=function(n){try{return t(n)||_e(Xe.has(n.tagName)?"input":"text",e.getPrivacy(),n,e.getUrl())}catch(e){return!0}},r=function(e){return!!e.closest('[contenteditable]:not([contenteditable="false"])')},i=function(t,i,o){var s;if(void 0===o&&(o=80),n(t)||r(t)||void 0===i&&Xe.has(t.tagName))return null;if(void 0!==i)return null===i?null:et(i,o);for(var a,l=e.document.createTreeWalker(t,5),c=0,u="";a=l.nextNode();){if(++c>256)return null;if(1===a.nodeType){var d=a;if(n(d)||r(d)||Xe.has(d.tagName))return null}else u+=null!==(s=a.nodeValue)&&void 0!==s?s:"";if(u.length>2*o)break}return et(u,o)},o=function(o){var s,a,l,u,d,v=function(e,t){return{name:e||null,source:null===e?"masked":e?t:"unnamed"}};if(t(o))return v(null,"masked");var h=o.getAttribute("aria-labelledby");if(h){var f=h.trim().split(/\s+/).slice(0,20).map(function(t){return e.document.getElementById(t)}).filter(function(e){return!!e}).map(function(e){return i(e)});if(f.some(function(e){return null===e}))return v(null,"masked");var g=et(f.join(" "),80);if(g)return v(g,"aria-labelledby")}var p=o.getAttribute("aria-label");if(null==p?void 0:p.trim())return v(i(o,p),"aria-label");var m=o.labels;if(null==m?void 0:m.length){var y=m[0],b="";if(n(y))return v(null,"masked");for(var S=!1,w=e.document.createTreeWalker(y,5),I=void 0,C=0;I=w.nextNode();){if(++C>256){S=!0;break}if(1===I.nodeType&&I!==o&&(n(I)||r(I))){S=!0;break}3!==I.nodeType||(null===(l=I.parentElement)||void 0===l?void 0:l.closest('input, select, textarea, [contenteditable]:not([contenteditable="false"])'))||(b+=null!==(u=I.nodeValue)&&void 0!==u?u:"")}return v(S?null:i(y,b),y.htmlFor?"label-for":"label-wrap")}if("IMG"===o.tagName&&o.hasAttribute("alt"))return v(i(o,o.getAttribute("alt")),"alt");if("INPUT"===o.tagName&&/^(button|submit|reset)$/i.test(null!==(d=o.getAttribute("type"))&&void 0!==d?d:"")&&o.hasAttribute("value"))return v(i(o,o.getAttribute("value")),"value");if(Ze.has(nt(o))){var k=i(o);if(null===k||k)return v(k,"text")}try{for(var E=c(["title","placeholder"]),x=E.next();!x.done;x=E.next()){var P=x.value,T=o.getAttribute(P);if(T)return v(i(o,T),P)}}catch(e){s={error:e}}finally{try{x&&!x.done&&(a=E.return)&&a.call(E)}finally{if(s)throw s.error}}return v("","unnamed")},s=function(n){if(t(n))return null;var r=e.getNodeId(n);return r<0?null:r},a=function(e){var t=o(e);return{id:s(e),role:nt(e),name:t.name,name_source:t.source}},l=function(t){var n=t;try{return n.checkVisibility?n.checkVisibility({opacityProperty:!0,visibilityProperty:!0}):t.getClientRects().length>0&&"hidden"!==e.window.getComputedStyle(t).visibility}catch(e){return!1}},v=null,h=0,f="";return{id:s,blocked:t,masked:n,text:i,name:o,describe:a,visible:l,role:nt,url:function(t){return void 0===t&&(t=e.getUrl()),tt(t,e.getUrl())},actionable:function(e){for(var t=e,n=e,r=0;t&&r<12;r++,t=t.parentElement){var i=nt(t);if(Qe.has(i))return t;n===e&&"generic"!==i&&(n=t)}return n},container:function(e){for(var t=e.parentElement,n=0;t&&n<20;n++,t=t.parentElement)if(Ve.has(nt(t))||t.hasAttribute("aria-label")){var r=a(t);return{id:r.id,role:r.role,name:r.name}}return null},states:function(e){var t,n,r=[],i=e,o="INPUT"===e.tagName&&"checkbox"===i.type&&i.indeterminate||"mixed"===e.getAttribute("aria-checked")||"mixed"===e.getAttribute("aria-pressed");try{for(var s=c(Object.entries({disabled:e.matches(":disabled")||"true"===e.getAttribute("aria-disabled"),required:i.required||"true"===e.getAttribute("aria-required"),invalid:rt(e)||i.willValidate&&!i.validity.valid,checked:!o&&(i.checked||"true"===e.getAttribute("aria-checked")),mixed:o,busy:"true"===e.getAttribute("aria-busy"),open:("DETAILS"===e.tagName||"DIALOG"===e.tagName)&&e.hasAttribute("open"),expanded:"true"===e.getAttribute("aria-expanded"),collapsed:"false"===e.getAttribute("aria-expanded"),selected:i.selected||"true"===e.getAttribute("aria-selected"),current:e.hasAttribute("aria-current")&&"false"!==e.getAttribute("aria-current"),pressed:"true"===e.getAttribute("aria-pressed"),readonly:i.readOnly||"true"===e.getAttribute("aria-readonly")})),a=s.next();!a.done;a=s.next()){var l=u(a.value,2),d=l[0];l[1]&&r.push(d)}}catch(e){t={error:e}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}return r},heading:function(){var t=e.window.performance.now(),n=e.getUrl();if(t<h&&n===f&&(!v||v.isConnected&&l(v)))return v?i(v):null;v=null,h=t+250,f=n;var r=e.document.body;if(!r)return null;for(var o=e.document.createTreeWalker(r,1),s=o.nextNode(),a=0;s&&a++<2e3&&e.window.performance.now()-t<2;){var c="H1"===s.tagName;if((c||s.matches('[role="heading"][aria-level="1"]'))&&l(s)){if(s.closest('main,[role="main"]')){v=s;break}c&&!v&&(v=s)}s=o.nextNode()}return v?i(v):null},invalidateHeading:function(){h=0,v=null},attributes:function(r){var i,o,s,a={};if(t(r))return a;try{for(var l=c(Ye),u=l.next();!u.done;u=l.next()){var d=u.value,v=r.getAttribute(d);null===v||(null===(s=e.getPrivacy().maskAttributes)||void 0===s?void 0:s.includes(d))&&n(r)||(a[d]=et("href"===d?tt(v,e.getUrl()):v,60))}}catch(e){i={error:e}}finally{try{u&&!u.done&&(o=l.return)&&o.call(l)}finally{if(i)throw i.error}}return a}}}var ot=new WeakMap;function st(e){try{return e.crypto.randomUUID()}catch(e){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}}function at(e,t){var n=ot.get(e);return n||(n=Object.freeze({tab_id:st(t),document_id:st(t)}),ot.set(e,n)),n}var lt={click:2e3,keys:1e3,"resource-error":200,field:1e3,submit:300,notice:300,dialog:300,"amp-event":500,context:200,recording:200,navigation:200,visibility:200,lifecycle:200};function ct(e){return o(o({},e),{families:e.families?o({},e.families):void 0})}var ut=["valueMissing","typeMismatch","patternMismatch","tooShort","tooLong","rangeUnderflow","rangeOverflow","stepMismatch","badInput","customError"];function dt(e){var t,n=e.target;return 1===(null==n?void 0:n.nodeType)?n:null!==(t=null==n?void 0:n.parentElement)&&void 0!==t?t:null}function vt(e){return["INPUT","SELECT","TEXTAREA"].includes(e.tagName)}function ht(e){var t;return"INPUT"===e.tagName&&["password","hidden"].includes(null!==(t=Pe(e))&&void 0!==t?t:"")}function ft(e){var t,n,r=[];if(vt(e))try{for(var i=c(ut),o=i.next();!o.done;o=i.next()){var s=o.value;e.validity[s]&&r.push(s)}}catch(e){t={error:e}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}return rt(e)&&r.push("ariaInvalid"),{valid:(!vt(e)||e.validity.valid)&&!r.includes("ariaInvalid"),validity:r}}function gt(e,t){var n=e.helpers.name(t),r=n.name,i=n.source;return{id:e.helpers.id(t),role:e.helpers.role(t),name:"text"===i||"value"===i?null:r,name_source:"text"===i||"value"===i?"masked":i}}function pt(e,t,n){if(n)return null;if("SELECT"===t.tagName){var r=t.selectedOptions[0];return!r||e.helpers.blocked(r)?null:r.hasAttribute("label")?e.helpers.text(r,r.label):e.helpers.text(r)}return"INPUT"===t.tagName&&["radio","checkbox"].includes(t.type)&&t.checked?gt(e,t).name:null}var mt={families:["click","field","submit"],setup:function(e){var t,n,r=e.host,i=e.helpers,s=[],a=new Set,l=!0,v=new WeakMap,h=new Map,f=function(e){var t=r.window.setTimeout(function(){a.delete(t),l&&e()},0);return a.add(t),t},g=function(e,t){r.document.addEventListener(e,t,!0),s.push(function(){return r.document.removeEventListener(e,t,!0)})},p=function(t){var n=e.now();if(l&&e.enabled("click")&&("auxclick"!==t.type||1===t.button)){var s=dt(t);if(s&&!i.blocked(s)){var a=i.actionable(s);if(!i.blocked(a)&&e.canEmit("click")){var u=function(e,t){var n,r,i,o=null!==(i=e.host.getPrivacy().maskAttributes)&&void 0!==i?i:[];try{for(var s=c(["data-amp-key","data-testid","data-test","data-cy","id"]),a=s.next();!a.done;a=s.next()){var l=a.value,u=t.getAttribute(l);if(!(!u||o.includes(l)&&e.helpers.masked(t)||"id"===l&&(/^\d+$/.test(u)||/[a-f\d]{8,}/i.test(u)||/:r/.test(u)||/\d{3,}/.test(u))))return u.length>80?"".concat(u.slice(0,79),"…"):u}}catch(e){n={error:e}}finally{try{a&&!a.done&&(r=s.return)&&r.call(s)}finally{if(n)throw n.error}}return null}(e,a),d=null;if(!u&&r.getSelector)try{d=r.getSelector(a)}catch(e){}e.emit("click",o(o(o(o({},i.describe(a)),{container:i.container(a),states:i.states(a),visible:i.visible(a),key:u}),u?{}:{selector:d}),{attrs:i.attributes(a),url:i.url(),heading:i.heading(),keyboard:0===t.detail,modifiers:[t.altKey?"alt":"",t.ctrlKey?"ctrl":"",t.metaKey?"meta":"",t.shiftKey?"shift":""].filter(Boolean),trusted:t.isTrusted}),n)}}}},m=function(t){var n,s;if(e.enabled("field")){var a=dt(t),l=null==a?void 0:a.closest('input, select, textarea, [contenteditable=""], [contenteditable="true"], [contenteditable="plaintext-only"]');if(l&&("change"!==t.type||vt(l))&&!ht(l)&&!i.blocked(l)&&e.canEmit("field")){var c=_e("input",r.getPrivacy(),l,r.getUrl()),u=o(o(o(o(o(o({},gt(e,l)),{states:i.states(l),kind:"INPUT"===l.tagName?l.type:vt(l)?l.tagName.toLowerCase():"contenteditable",value_state:(vt(l)?l.value.length>0:(null!==(s=null===(n=l.textContent)||void 0===n?void 0:n.length)&&void 0!==s?s:0)>0)?"filled":"empty"}),"INPUT"===l.tagName&&["checkbox","radio"].includes(l.type)?{checked:l.checked}:{}),function(e,t){if(t)return{};if("TEXTAREA"===e.tagName)return{value:e.value};if("INPUT"!==e.tagName)return{};var n=e;return["checkbox","radio","file","button","submit","reset","image"].includes(n.type)?{}:{value:n.value}}(l,c)),ft(l)),{masked:c,option_label:pt(e,l,c)}),d=JSON.stringify(u),h=v.get(l),f=e.now();(null==h?void 0:h.payload)===d&&("focusout"===t.type||f-h.timestamp<500)||e.emit("field",u)&&v.set(l,{payload:d,timestamp:f})}}},y=function(e,t){var n=i.describe(e);if(null===n.name&&"masked"!==n.name_source){var r=null!=t?t:e.querySelector('button:not([type]), button[type="submit"], input[type="submit"], input[type="image"]');r&&!i.blocked(r)&&(n.name=i.name(r).name)}return{id:n.id,role:n.role,name:n.name}};return e.enabled("click")&&(r.externalClicks?s.push(e.on("click",p)):g("click",function(e){return p(e)}),(null!==(t=r.externalAuxClicks)&&void 0!==t?t:r.externalClicks)||g("auxclick",function(e){return p(e)})),e.enabled("field")&&(g("change",m),g("focusout",m)),e.enabled("submit")&&(g("submit",function(t){if(e.enabled("submit")){var n=dt(t);if("FORM"===(null==n?void 0:n.tagName)&&!i.blocked(n)){var r=t.submitter,o=r&&!i.blocked(r)?r:null;f(function(){e.enabled("submit")&&!i.blocked(n)&&e.canEmit("submit")&&e.emit("submit",{form:y(n,o&&!i.blocked(o)?o:null),submitter:o&&!i.blocked(o)?{id:i.id(o),role:i.role(o),name:i.name(o).name}:null,valid:!0,invalid_fields:[],prevented:t.defaultPrevented})})}}}),g("invalid",function(t){if(e.enabled("submit")){var r=dt(t);if(r&&vt(r)){var o=r.form;if(o&&!i.blocked(o)){var s=h.get(o);s||(s=new Set,h.set(o,s)),!ht(r)&&!i.blocked(r)&&s.size<10&&s.add(r),void 0===n&&(n=f(function(){var t,r;n=void 0;var o=d([],u(h),!1);if(h.clear(),e.enabled("submit"))try{for(var s=c(o),a=s.next();!a.done;a=s.next()){var l=u(a.value,2),v=l[0],f=l[1];i.blocked(v)||e.canEmit("submit")&&e.emit("submit",{form:y(v,null),submitter:null,valid:!1,prevented:!0,invalid_fields:d([],u(f),!1).filter(function(e){return!i.blocked(e)&&!ht(e)}).map(function(t){var n=gt(e,t);return{id:n.id,name:n.name,validity:ft(t).validity}})})}}catch(e){t={error:e}}finally{try{a&&!a.done&&(r=s.return)&&r.call(s)}finally{if(t)throw t.error}}}))}}}})),function(){l=!1,s.forEach(function(e){return e()}),a.forEach(function(e){return r.window.clearTimeout(e)}),a.clear(),h.clear()}}},yt='dialog,[role="dialog"],[role="alertdialog"],[aria-modal="true"]';function bt(e,t){var n,r,i,o,s,a;return l(this,function(l){switch(l.label){case 0:n=[{children:[e],index:0,hidden:!1}],l.label=1;case 1:return n.length?(r=n[n.length-1]).index===r.children.length?(n.pop(),[3,1]):(i=r.children[r.index++],o=i.attributes,s=r.hidden||void 0!==(null==o?void 0:o.hidden)||"true"===(null==o?void 0:o["aria-hidden"]),[4,{node:i,baseline:t,hidden:s}]):[3,3];case 2:return l.sent(),(null===(a=i.childNodes)||void 0===a?void 0:a.length)&&n.push({children:i.childNodes,index:0,hidden:s}),[3,1];case 3:return[2]}})}function St(e){var t,n,r,i,o,s,a,u,d,v,h,f,g,p,m,y,b,S,w,I,C,k,E,x,P,T;return l(this,function(M){switch(M.label){case 0:return"snapshot"!==e.type?[3,2]:[5,c(bt(e.node,!0))];case 1:return M.sent(),[3,33];case 2:M.trys.push([2,7,8,9]),t=c(e.texts),n=t.next(),M.label=3;case 3:return n.done?[3,6]:[4,{id:n.value.id,text:!0}];case 4:M.sent(),M.label=5;case 5:return n=t.next(),[3,3];case 6:return[3,9];case 7:return r=M.sent(),w={error:r},[3,9];case 8:try{n&&!n.done&&(I=t.return)&&I.call(t)}finally{if(w)throw w.error}return[7];case 9:i=function(e){return l(this,function(t){switch(t.label){case 0:return[4,{id:e.id,dialogs:["open","hidden","aria-hidden","role","aria-modal"].some(function(t){return t in e.attributes})}];case 1:return t.sent(),[2]}})},M.label=10;case 10:M.trys.push([10,15,16,17]),o=c(e.attributes),s=o.next(),M.label=11;case 11:return s.done?[3,14]:(a=s.value,[5,i(a)]);case 12:M.sent(),M.label=13;case 13:return s=o.next(),[3,11];case 14:return[3,17];case 15:return u=M.sent(),C={error:u},[3,17];case 16:try{s&&!s.done&&(k=o.return)&&k.call(o)}finally{if(C)throw C.error}return[7];case 17:d=new Set,v=function(e){var t=!d.has(e);return d.size<1e3&&d.add(e),{id:e,text:t}},M.label=18;case 18:M.trys.push([18,23,24,25]),h=c(e.removes),f=h.next(),M.label=19;case 19:return f.done?[3,22]:(g=f.value,[4,v(g.parentId)]);case 20:M.sent(),M.label=21;case 21:return f=h.next(),[3,19];case 22:return[3,25];case 23:return p=M.sent(),E={error:p},[3,25];case 24:try{f&&!f.done&&(x=h.return)&&x.call(h)}finally{if(E)throw E.error}return[7];case 25:M.trys.push([25,31,32,33]),m=c(e.adds),y=m.next(),M.label=26;case 26:return y.done?[3,30]:(b=y.value,[4,v(b.parentId)]);case 27:return M.sent(),[5,c(bt(b.node,!1))];case 28:M.sent(),M.label=29;case 29:return y=m.next(),[3,26];case 30:return[3,33];case 31:return S=M.sent(),P={error:S},[3,33];case 32:try{y&&!y.done&&(T=m.return)&&T.call(m)}finally{if(P)throw P.error}return[7];case 33:return[2]}})}var wt={families:["notice","dialog"],setup:function(e){var t=e.hasCapacity("notice"),n=e.hasCapacity("dialog"),r=e.host,i=e.helpers,o=r.window;if(!t&&!n||!r.getNode)return function(){};var s,a=!0,l=null,d=!1,v=0,h=[],f=new Set,g=new Set,p=new Set,m=new WeakMap,y=new WeakMap,b=new Map,S=new WeakMap,w=new Set,I=new Set,C=!1,k=!1,E=function(e){var t;if(!I.has(e)){I.add(e);try{null===(t=r.onError)||void 0===t||t.call(r,new Error("Semantic feedback ".concat(e," limit reached; some changes may be omitted.")))}catch(e){}}},x=function(e,n){var r;if(t&&e.isConnected&&!(void 0!==n&&(null!==(r=y.get(e))&&void 0!==r?r:-1)>=n)){if(!g.has(e)&&!b.has(e)){if(g.size+b.size>=256)return void E("notice queue");g.add(e)}void 0!==n&&y.set(e,n)}},P=function(e){n&&!p.has(e)&&p.add(e)},T=e.subscribe(function(e){"click"===e.name&&(l=e.timestamp)}),M=function(){return null!==l&&e.now()-l>=0&&e.now()-l<=3e3?l:null},R=function(){g.clear(),b.forEach(function(e){return o.clearTimeout(e)}),b.clear()},O=function(){a=!1,U(),T(),void 0!==s&&(d?o.clearTimeout(s):o.cancelAnimationFrame(s),s=void 0),R(),h.length=0,f.clear(),p.clear(),w.clear()},_=function(){return t&&!e.hasCapacity("notice")&&(t=!1,R()),n&&!e.hasCapacity("dialog")&&(n=!1,p.clear(),w.clear(),f.clear()),t||n||O(),a},A=function(n){if(g.delete(n),n.isConnected&&!b.has(n)){var r=m.get(n),s=void 0===r?0:500-(e.now()-r);s<=0?function(t){if(a&&t.isConnected&&!i.blocked(t)&&e.canEmit("notice")){var n=i.text(t,void 0,200);if(null===n||n.trim()){var r=t.getAttribute("role"),o=i.container(t);e.emit("notice",{id:i.id(t),role:"alert"===r||"status"===r||"log"===r?r:"live",text:n,visible:i.visible(t),region:o?{role:o.role,name:o.name}:null,cause_click_ts:M()}),m.set(t,e.now())}}}(n):b.set(n,o.setTimeout(function(){b.delete(n),a&&t&&(x(n),g.size&&N())},s))}},L=function(t){if(p.delete(t),i.blocked(t))return w.delete(t),void f.delete(t);var n=S.get(t),r=function(e){return e.isConnected&&e.matches(yt)&&!e.closest('[hidden],[aria-hidden="true"]')&&("DIALOG"!==e.tagName||e.hasAttribute("open"))}(t);if((null==n?void 0:n.open)!==r&&(n||r)){var o=function(e){var t=S.get(e),n=e.isConnected&&e.matches(yt)&&!e.closest('[hidden],[aria-hidden="true"]')&&("DIALOG"!==e.tagName||e.hasAttribute("open")),r="true"===e.getAttribute("aria-modal");try{r=r||e.matches(":modal")}catch(e){}var o=!e.isConnected&&t?t.payload:i.describe(e);return{open:n,payload:{id:o.id,role:"alertdialog"===e.getAttribute("role")?"alertdialog":"dialog",name:e.isConnected?o.name:null,name_source:e.isConnected?o.name_source:"masked",state:n?"open":"closed",modal:!e.isConnected&&t?t.payload.modal:r,visible:n&&i.visible(e),cause_click_ts:M()}}}(t);S.set(t,o),r?w.add(t):w.delete(t),e.emit("dialog",o.payload),t.isConnected||f.delete(t)}},F=function(){var e,t,n,r,i,l,d,v;if(s=void 0,a&&_()){var m=o.performance.now();if(C){C=!1;try{for(var y=c(f),S=y.next();!S.done;S=y.next()){var I=S.value;P(I)}}catch(t){e={error:t}}finally{try{S&&!S.done&&(t=y.return)&&t.call(y)}finally{if(e)throw e.error}}try{for(var E=c(g),x=E.next();!x.done;x=E.next()){(I=x.value).isConnected||g.delete(I)}}catch(e){n={error:e}}finally{try{x&&!x.done&&(r=E.return)&&r.call(E)}finally{if(n)throw n.error}}try{for(var T=c(b),M=T.next();!M.done;M=T.next()){var R=u(M.value,2),O=(I=R[0],R[1]);I.isConnected||(o.clearTimeout(O),b.delete(I))}}catch(e){i={error:e}}finally{try{M&&!M.done&&(l=T.return)&&l.call(T)}finally{if(i)throw i.error}}try{for(var F=c(f),D=F.next();!D.done;D=F.next()){(I=D.value).isConnected||w.has(I)||(f.delete(I),p.delete(I))}}catch(e){d={error:e}}finally{try{D&&!D.done&&(v=F.return)&&v.call(F)}finally{if(d)throw d.error}}}var U=0,j=function(e){for(;a&&(g.size||p.size)&&U<50&&o.performance.now()<e;){var t=p.size>0&&(k||!g.size);k=!t,U++,t?L(p.values().next().value):A(g.values().next().value),_()}};j(m+2);for(var B=0;a&&h.length&&B++<1e3&&o.performance.now()-m<4;){var W=h[0],z=W.work.next();z.done?h.shift():q(z.value,W.generation)}j(m+4),a&&(C||h.length||g.size||p.size)&&N()}},N=function(){a&&void 0===s&&(d="function"!=typeof o.requestAnimationFrame,s=d?o.setTimeout(F,16):o.requestAnimationFrame(F))},D=function(e){return!!f.has(e)||(f.size>=256?(E("dialog tracking"),!1):(f.add(e),!0))},q=function(e,o){var s,a,l;if("node"in e){var u=e.node,d=e.baseline,v=e.hidden;if(2!==u.type)return;var h=null!==(l=u.attributes)&&void 0!==l?l:{},g="dialog"===u.tagName||"dialog"===h.role||"alertdialog"===h.role||"true"===h["aria-modal"],p=["alert","status","log"].includes(h.role)||["polite","assertive"].includes(h["aria-live"]);if((!n||!g)&&(!t||!p||d))return;var m=r.getNode(u.id);if(!m||1!==m.nodeType||i.blocked(m))return;var y=m;if(n&&g&&D(y))if(d&&!S.has(y)){var b=!v&&("dialog"!==u.tagName||void 0!==h.open);S.set(y,{open:b,payload:{id:u.id,role:"alertdialog"===h.role?"alertdialog":"dialog",name:null,name_source:"unnamed",state:b?"open":"closed",modal:"true"===h["aria-modal"]||"modal"===h.rr_open_mode,visible:!1,cause_click_ts:null}}),b&&w.add(y)}else{var I=S.get(y);I&&d&&(I.payload.id=u.id),P(y)}t&&p&&!d&&x(y,o)}else if(t&&e.text||n&&e.dialogs){var C=r.getNode(e.id),k=1===(null==C?void 0:C.nodeType)?C:null==C?void 0:C.parentElement;if(k&&k.isConnected&&!i.blocked(k)){if(t&&e.text){var E=k.closest('[role="alert"],[role="status"],[role="log"],[aria-live="polite"],[aria-live="assertive"]');E&&x(E,o)}if(n&&e.dialogs){k.matches(yt)&&D(k)&&P(k);try{for(var T=c(f),M=T.next();!M.done;M=T.next()){g=M.value;k.contains(g)&&P(g)}}catch(e){s={error:e}}finally{try{M&&!M.done&&(a=T.return)&&a.call(T)}finally{if(s)throw s.error}}}}}},U=e.on("dom",function(e){a&&_()&&(v++,("snapshot"===e.type||e.removes.length)&&(C=!0),h.length>=128?E("replay batch queue"):h.push({work:St(e),generation:v}),N())});return O}};var It={families:["context","recording","visibility","lifecycle"],setup:function(e){var t=[],n=e.host,r=n.document,i=n.window;if(e.enabled("context")&&t.push(e.on("snapshot",function(){return function(e){var t,n,r,i,s;if(e.canEmit("context")){var a=e.host,l=a.document,u=a.window,d={total:0,inlined:0,unreadable:0};try{for(var v=c(Array.from(l.styleSheets)),h=v.next();!h.done;h=v.next()){var f=h.value;d.total++;try{f.cssRules,!1!==a.inlineStylesheet&&d.inlined++}catch(e){d.unreadable++}}}catch(e){t={error:e}}finally{try{h&&!h.done&&(n=v.return)&&n.call(v)}finally{if(t)throw t.error}}var g="function"==typeof u.matchMedia&&u.matchMedia("(pointer:coarse)").matches,p=g&&u.innerWidth<768?"mobile":g&&u.innerWidth<1024?"tablet":"desktop",m=e.dropped();e.emit("context",o({sdk:a.sdk,mask:null!==(r=a.getPrivacy().defaultMaskLevel)&&void 0!==r?r:"medium",css:d,viewport:{w:u.innerWidth,h:u.innerHeight},device:p,language:u.navigator.language,visibility_state:"hidden"===l.visibilityState?"hidden":"visible",focused:l.hasFocus(),user_agent:u.navigator.userAgent,analytics_sdk:null!==(s=null===(i=a.getAnalyticsContext)||void 0===i?void 0:i.call(a))&&void 0!==s?s:{present:!1,autocapture:[]}},Object.keys(m).length?{caps_hit:m}:{}))}}(e)})),e.enabled("recording")&&t.push(e.on("recording",function(t){return e.emit("recording",t)})),e.enabled("visibility")){var s=function(){return"hidden"===r.visibilityState?"hidden":"visible"},a=s(),l=function(){var t=s();t!==a&&(a=t,e.emit("visibility",{state:t}))};r.addEventListener("visibilitychange",l,!0),t.push(function(){return r.removeEventListener("visibilitychange",l,!0)})}if(e.enabled("lifecycle")){var u=function(n,r,i){var o=function(t){e.emit("lifecycle",{type:"pageshow"===r&&t.persisted?"pageshow_bfcache":i})};n.addEventListener(r,o,!0),t.push(function(){return n.removeEventListener(r,o,!0)})};u(i,"pagehide","pagehide"),u(i,"pageshow","pageshow"),u(r,"freeze","freeze"),u(r,"resume","resume")}return function(){return t.forEach(function(e){return e()})}}},Ct=/^(Escape|Enter|Tab|ArrowUp|ArrowDown|ArrowLeft|ArrowRight|Home|End|PageUp|PageDown|F[1-9]|F1[0-2])$/,kt=/^[kpf]$/i,Et={families:["keys"],setup:function(e){var t=e.host.document,n=e.helpers,r=function(t){if(e.enabled("keys")&&!t.repeat&&!t.isComposing&&229!==t.keyCode&&!t.getModifierState("AltGraph")){var r=t.key;if(!Ct.test(r)){if(t.altKey||t.ctrlKey===t.metaKey||!kt.test(r))return;r=r.toUpperCase()}var i=t.composedPath().filter(function(e){return 1===e.nodeType}),o=i[0];if(o&&!i.some(function(e){return n.blocked(e)})&&!o.matches('input[type="password"], input[type="hidden"]')&&e.canEmit("keys")){var s=n.name(o),a="value"===s.source||"text"===s.source&&!!o.closest("input,textarea,select,[contenteditable]");e.emit("keys",{key:[t.ctrlKey?"Ctrl":"",t.metaKey?"Meta":"",t.altKey?"Alt":"",t.shiftKey?"Shift":"",r].filter(Boolean).join("+"),target:{id:n.id(o),role:n.role(o),name:a?null:s.name,name_source:a?"masked":s.source,states:n.states(o)}})}}},i=function(){return t.removeEventListener("keydown",r,!0)};return e.onCleanup(i),t.addEventListener("keydown",r,!0),i}},xt=65535,Pt={families:["resource-error"],setup:function(e){var t,n=e.host,r=n.document,i=n.window,s=e.helpers,a=!0,l=[],u=0,d=r.fonts,v=function(){void 0!==t&&i.clearTimeout(t),t=void 0},h=function(){var t,n,r,i;v();var d=l,h=u;if(l=[],u=0,a&&e.enabled("resource-error")){var f=new Map;try{for(var g=c(d),p=g.next();!p.done;p=g.next()){var m=p.value;if(m.element.isConnected&&!s.blocked(m.element)){var y=s.container(m.element),b=o(o({rt:m.rt,count:m.count},m.path?{path:m.path}:{}),y?{container:y}:{}),S=JSON.stringify([b.rt,b.path,b.container]),w=f.get(S);w?w.count=Math.min(xt,w.count+b.count):f.set(S,b)}}}catch(e){t={error:e}}finally{try{p&&!p.done&&(n=g.return)&&n.call(g)}finally{if(t)throw t.error}}h&&e.emit("resource-error",{rt:"font",count:h});try{for(var I=c(f.values()),C=I.next();!C.done;C=I.next()){b=C.value;e.emit("resource-error",b)}}catch(e){r={error:e}}finally{try{C&&!C.done&&(i=I.return)&&i.call(I)}finally{if(r)throw r.error}}}},f=function(){"hidden"===r.visibilityState?h():void 0===t&&(t=i.setTimeout(h,500))},g=function(t){if(a&&e.enabled("resource-error")){var n=t.target;if(n&&1===n.nodeType&&!s.blocked(n)){var i,o;if("IMG"===n.tagName)i="img",o=n.currentSrc||n.getAttribute("src")||"";else if("SCRIPT"===n.tagName&&n.hasAttribute("src"))i="script",o=n.getAttribute("src")||"";else{if("LINK"!==n.tagName||!n.relList.contains("stylesheet"))return;i="css",o=n.getAttribute("href")||""}var c=function(e){if(e)try{var t=new URL(e,r.baseURI);if("http:"!==t.protocol&&"https:"!==t.protocol)return;var n=s.url(t.origin+t.pathname);return n.length<=200?n:void 0}catch(e){return}}(o),u=l.find(function(e){return e.element===n&&e.rt===i&&e.path===c});u?u.count=Math.min(xt,u.count+1):(l.length>=100&&h(),l.push({element:n,rt:i,path:c,count:1})),f()}}},p=function(t){if(a&&e.enabled("resource-error")){var n=t.fontfaces;(null==n?void 0:n.length)&&(u=Math.min(xt,u+n.length),f())}},m=function(){"hidden"===r.visibilityState&&h()},y=function(){a=!1,v(),l=[],u=0,r.removeEventListener("error",g,!0),r.removeEventListener("visibilitychange",m,!0),i.removeEventListener("pagehide",h,!0),null==d||d.removeEventListener("loadingerror",p)};return e.onCleanup(y),r.addEventListener("error",g,!0),r.addEventListener("visibilitychange",m,!0),i.addEventListener("pagehide",h,!0),null==d||d.addEventListener("loadingerror",p),y}},Tt=new Set(["[Amplitude] Dead Click","[Amplitude] Rage Click","[Amplitude] Error Click","[Amplitude] Thrashed Cursor"]),Mt=["[Amplitude] Clicks","[Amplitude] Begin Time","[Amplitude] End Time"],Rt="[Amplitude] Element Text",Ot="[Amplitude] Element Tag",_t="[Amplitude] Page Path",At={families:["amp-event"],setup:function(e){if(!e.enabled("amp-event"))return function(){};var t,n=e.subscribe(function(e){"click"===e.name&&(t={timestamp:e.timestamp,id:e.payload.id,name:e.payload.name})}),r=e.on("analytics",function(n){var r,i;if(e.enabled("amp-event")&&Tt.has(n.eventType)){var o=e.helpers,s=n.element;if((!s||!o.blocked(s))&&e.canEmit("amp-event")){var a=n.properties,l={},u=null,d=a[Rt];if("string"==typeof d){if(s){var v=o.text(s),h=o.text(s,d);null!==v&&v===h&&(u=h)}l[Rt]=u}var f=a[Ot];s?l[Ot]=s.tagName.toLowerCase():"string"==typeof f&&/^[a-z][a-z0-9-]{0,59}$/i.test(f)&&(l[Ot]=f.toLowerCase());try{for(var g=c(Mt),p=g.next();!p.done;p=g.next()){var m=p.value,y=a[m];"number"==typeof y&&Number.isFinite(y)&&(l[m]=y)}}catch(e){r={error:e}}finally{try{p&&!p.done&&(i=g.return)&&i.call(g)}finally{if(r)throw r.error}}var b=a[_t];"string"==typeof b&&(l[_t]=o.url(b));var S=t?e.now()-t.timestamp:1/0,w=null!==u&&t&&S>=0&&S<=3e3&&t.name===u?t.id:null;e.emit("amp-event",{event_type:n.eventType,insert_id:"string"==typeof n.insertId?n.insertId:null,id:w,props:l})}}});return function(){r(),n(),t=void 0}}},Lt=[mt,wt,It,{families:["navigation"],setup:function(e){return e.on("url",function(t){var n=t.url,r=t.timestamp;n.trim()&&e.canEmit("navigation")&&e.emit("navigation",{url:e.helpers.url(n)},r)})}},At,Et,Pt];function Ft(e,t,n){return void 0===n&&(n=Lt),function(e,t,n){var r,i,s=ct(e),a=!1,l=!1,u=!1,d=[],v={},h={},f=new Map,g=new Set,p=null!==(r=t.now)&&void 0!==r?r:Date.now,m=function(e){var n;try{null===(n=t.onError)||void 0===n||n.call(t,e)}catch(e){}},y=function(e){try{e()}catch(e){m(e)}},b=function(e){var t;return a&&!1!==(null===(t=s.families)||void 0===t?void 0:t[e])},S=function(e){var t;return b(e)&&(null!==(t=v[e])&&void 0!==t?t:0)<lt[e]},w=function(e){var t;return!(!b(e)||!S(e)&&(h[e]=(null!==(t=h[e])&&void 0!==t?t:0)+1,1))},I={host:t,helpers:it(t),now:p,enabled:b,canEmit:w,hasCapacity:S,dropped:function(){return o({},h)},hasSnapshot:function(){return u},emit:function(e,n,r){var i,s,a;if(void 0===r&&(r=p()),!w(e))return!1;try{a=null===(i=t.getIdentity)||void 0===i?void 0:i.call(t)}catch(e){m(e)}null!=a||(a=at(t.document,t.window));var l={name:e,payload:o(o({},n),{v:1,tab_id:a.tab_id,document_id:a.document_id}),timestamp:r};v[e]=(null!==(s=v[e])&&void 0!==s?s:0)+1;try{t.emit(l)}catch(e){return m(e),!1}return"context"===e&&(h={}),g.forEach(function(e){return y(function(){return e(l)})}),!0},on:function(e,t){var n=f.get(e);n||(n=new Set,f.set(e,n));var r=function(e){return y(function(){return t(e)})};n.add(r);var i=n;return function(){i.delete(r)}},subscribe:function(e){return g.add(e),function(){g.delete(e)}}},C=function(){a=!1;var e=d;d=[],e.reverse().forEach(function(e){return y(e)}),f.clear(),g.clear()},k=function(){var e,r,u,v;if(!a&&l&&s.enabled){var h=null!==(u=s.sampleRate)&&void 0!==u?u:1;if(!(!Number.isFinite(h)||h<=0||h>1||(void 0===i&&(i=(null!==(v=t.random)&&void 0!==v?v:Math.random)()),i>=h))){a=!0;var f=function(e){if(e.families.some(b)){var t=[],n=o(o({},I),{onCleanup:function(e){t.push(e)},on:function(e,n){var r=I.on(e,n);return t.push(r),r},subscribe:function(e){var n=I.subscribe(e);return t.push(n),n}}),r=function(){t.splice(0).reverse().forEach(function(e){return y(e)})};try{t.push(e.setup(n)),d.push(r)}catch(e){r(),m(e)}}};try{for(var g=c(n),p=g.next();!p.done;p=g.next())f(p.value)}catch(t){e={error:t}}finally{try{p&&!p.done&&(r=g.return)&&r.call(g)}finally{if(e)throw e.error}}}}};return{isActive:function(){return a},start:function(){l=!0,k()},stop:function(){l=!1,u=!1,C()},updateConfig:function(e){C(),s=ct(e),k()},resetSession:function(){C(),i=void 0,u=!1,v={},h={},k()},notify:function(e,t){var n,r,i;"snapshot"===e&&(u=!0),"snapshot"!==e&&"navigation"!==e&&"url"!==e||null===(r=(n=I.helpers).invalidateHeading)||void 0===r||r.call(n),a&&(null===(i=f.get(e))||void 0===i||i.forEach(function(e){return e(t)}))}}}(e,t,n)}var Nt,Dt,qt,Ut=(e=>(e[e.DomContentLoaded=0]="DomContentLoaded",e[e.Load=1]="Load",e[e.FullSnapshot=2]="FullSnapshot",e[e.IncrementalSnapshot=3]="IncrementalSnapshot",e[e.Meta=4]="Meta",e[e.Custom=5]="Custom",e[e.Plugin=6]="Plugin",e))(Ut||{}),jt=(e=>(e[e.Mutation=0]="Mutation",e[e.MouseMove=1]="MouseMove",e[e.MouseInteraction=2]="MouseInteraction",e[e.Scroll=3]="Scroll",e[e.ViewportResize=4]="ViewportResize",e[e.Input=5]="Input",e[e.TouchMove=6]="TouchMove",e[e.MediaInteraction=7]="MediaInteraction",e[e.StyleSheetRule=8]="StyleSheetRule",e[e.CanvasMutation=9]="CanvasMutation",e[e.Font=10]="Font",e[e.Log=11]="Log",e[e.Drag=12]="Drag",e[e.StyleDeclaration=13]="StyleDeclaration",e[e.Selection=14]="Selection",e[e.AdoptedStyleSheet=15]="AdoptedStyleSheet",e[e.CustomElement=16]="CustomElement",e))(jt||{}),Bt=(e=>(e[e.MouseUp=0]="MouseUp",e[e.MouseDown=1]="MouseDown",e[e.Click=2]="Click",e[e.ContextMenu=3]="ContextMenu",e[e.DblClick=4]="DblClick",e[e.Focus=5]="Focus",e[e.Blur=6]="Blur",e[e.TouchStart=7]="TouchStart",e[e.TouchMove_Departed=8]="TouchMove_Departed",e[e.TouchEnd=9]="TouchEnd",e[e.TouchCancel=10]="TouchCancel",e))(Bt||{}),Wt=function(){function e(e){this.ready=!1,this.firstSnapshot=!1,this.pendingSnapshots=0,this.pendingEvents=[],this.startSignal={state:"start",reason:"init"},this.resumeReason="focus",this.config={enabled:!1},this.capture=Ft(this.config,e)}return e.prototype.prepare=function(e,t){var n=this.sessionId!==t,r=void 0===this.sessionId;this.config=e,this.capture.updateConfig(e),n&&this.capture.resetSession(),this.startSignal={state:n?"start":"resume",reason:r?"init":n?"new_session":this.resumeReason},this.sessionId=t,this.ready=!1,this.firstSnapshot=!1,this.pendingSnapshots=0,this.pendingEvents=[]},e.prototype.recordingReady=function(){var e,t;if(this.config.enabled&&!this.ready){this.ready=!0,this.capture.start();var n=this.pendingEvents;this.pendingEvents=[];try{for(var r=c(n),i=r.next();!i.done;i=r.next()){var o=i.value;this.event(o)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}var s=this.pendingSnapshots;this.pendingSnapshots=0;for(var a=0;a<s;a++)this.snapshot()}},e.prototype.event=function(e){if(this.config.enabled){var t=e.type===Ut.FullSnapshot,n=e.type===Ut.IncrementalSnapshot&&e.data.source===jt.Mutation,r=e.type===Ut.Plugin&&"amplitude/url-tracking@1"===e.data.plugin?e.data.payload:void 0,i=r&&"object"==typeof r&&"url-change-event"===r.type&&"string"==typeof r.href?r.href:void 0;(t||n||void 0!==i)&&(this.ready?this.capture.isActive()&&(void 0!==i?this.capture.notify("url",{url:i,timestamp:e.timestamp}):e.type===Ut.FullSnapshot?(this.capture.notify("dom",{type:"snapshot",node:e.data.node}),this.snapshot()):e.type===Ut.IncrementalSnapshot&&e.data.source===jt.Mutation&&this.capture.notify("dom",o(o({},e.data),{type:"mutation"}))):this.pendingEvents.length<128&&this.pendingEvents.push(e))}},e.prototype.click=function(e){this.ready&&this.capture.notify("click",e)},e.prototype.snapshot=function(){this.config.enabled&&(this.ready?(this.firstSnapshot||(this.firstSnapshot=!0,this.capture.notify("recording",this.startSignal)),this.capture.notify("snapshot",void 0)):this.pendingSnapshots++)},e.prototype.stop=function(e,t){void 0===e&&(e="targeting"),void 0===t&&(t="stop");var n=this.ready&&this.firstSnapshot;this.ready=!1,this.firstSnapshot=!1,n&&(this.resumeReason=e,this.capture.notify("recording",{state:t,reason:e})),this.capture.stop(),this.pendingEvents=[],this.ready=!1,this.pendingSnapshots=0},e}(),zt="AMP_semantic_tab_v1",Kt=new WeakMap,Ht=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function $t(e,t){if(qt=new Date,e.nodeType!==Node.ELEMENT_NODE)throw new Error("Can't generate CSS selector for non-element node type.");if("html"===e.tagName.toLowerCase())return"html";var n={root:document.body,idName:function(e){return!0},className:function(e){return!0},tagName:function(e){return!0},attr:function(e,t){return!1},seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4,timeoutMs:void 0};Nt=o(o({},n),t),Dt=function(e,t){if(e.nodeType===Node.DOCUMENT_NODE)return e;if(e===t.root)return e.ownerDocument;return e}(Nt.root,n);var r=Gt(e,"all",function(){return Gt(e,"two",function(){return Gt(e,"one",function(){return Gt(e,"none")})})});if(r){var i=rn(on(r,e));return i.length>0&&(r=i[0]),Qt(r)}throw new Error("Selector was not found.")}function Gt(e,t,n){for(var r=null,i=[],o=e,s=0,a=function(){var e,a,l=(new Date).getTime()-qt.getTime();if(void 0!==Nt.timeoutMs&&l>Nt.timeoutMs)throw new Error("Timeout: Can't find a unique selector after ".concat(l,"ms"));var v=en(function(e){var t=e.getAttribute("id");if(t&&Nt.idName(t))return{name:"#"+CSS.escape(t),penalty:0};return null}(o))||en.apply(void 0,d([],u(function(e){var t=Array.from(e.attributes).filter(function(e){return Nt.attr(e.name,e.value)});return t.map(function(e){return{name:"[".concat(CSS.escape(e.name),'="').concat(CSS.escape(e.value),'"]'),penalty:.5}})}(o)),!1))||en.apply(void 0,d([],u(function(e){var t=Array.from(e.classList).filter(Nt.className);return t.map(function(e){return{name:"."+CSS.escape(e),penalty:1}})}(o)),!1))||en(function(e){var t=e.tagName.toLowerCase();if(Nt.tagName(t))return{name:t,penalty:2};return null}(o))||[{name:"*",penalty:3}],h=function(e){var t=e.parentNode;if(!t)return null;var n=t.firstChild;if(!n)return null;var r=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&r++,n!==e);)n=n.nextSibling;return r}(o);if("all"==t)h&&(v=v.concat(v.filter(Yt).map(function(e){return Xt(e,h)})));else if("two"==t)v=v.slice(0,1),h&&(v=v.concat(v.filter(Yt).map(function(e){return Xt(e,h)})));else if("one"==t){var f=u(v=v.slice(0,1),1)[0];h&&Yt(f)&&(v=[Xt(f,h)])}else"none"==t&&(v=[{name:"*",penalty:3}],h&&(v=[Xt(v[0],h)]));try{for(var g=(e=void 0,c(v)),p=g.next();!p.done;p=g.next()){(f=p.value).level=s}}catch(t){e={error:t}}finally{try{p&&!p.done&&(a=g.return)&&a.call(g)}finally{if(e)throw e.error}}if(i.push(v),i.length>=Nt.seedMinLength&&(r=Jt(i,n)))return"break";o=o.parentElement,s++};o;){if("break"===a())break}return r||(r=Jt(i,n)),!r&&n?n():r}function Jt(e,t){var n,r,i=rn(nn(e));if(i.length>Nt.threshold)return t?t():null;try{for(var o=c(i),s=o.next();!s.done;s=o.next()){var a=s.value;if(Zt(a))return a}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}return null}function Qt(e){for(var t=e[0],n=t.name,r=1;r<e.length;r++){var i=e[r].level||0;n=t.level===i-1?"".concat(e[r].name," > ").concat(n):"".concat(e[r].name," ").concat(n),t=e[r]}return n}function Vt(e){return e.map(function(e){return e.penalty}).reduce(function(e,t){return e+t},0)}function Zt(e){var t=Qt(e);switch(Dt.querySelectorAll(t).length){case 0:throw new Error("Can't select any node with this selector: ".concat(t));case 1:return!0;default:return!1}}function Xt(e,t){return{name:e.name+":nth-child(".concat(t,")"),penalty:e.penalty+1}}function Yt(e){return"html"!==e.name&&!e.name.startsWith("#")}function en(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e.filter(tn);return n.length>0?n:null}function tn(e){return null!=e}function nn(e,t){var n,r,i,o,s,a;return void 0===t&&(t=[]),l(this,function(l){switch(l.label){case 0:if(!(e.length>0))return[3,9];l.label=1;case 1:l.trys.push([1,6,7,8]),n=c(e[0]),r=n.next(),l.label=2;case 2:return r.done?[3,5]:(i=r.value,[5,c(nn(e.slice(1,e.length),t.concat(i)))]);case 3:l.sent(),l.label=4;case 4:return r=n.next(),[3,2];case 5:return[3,8];case 6:return o=l.sent(),s={error:o},[3,8];case 7:try{r&&!r.done&&(a=n.return)&&a.call(n)}finally{if(s)throw s.error}return[7];case 8:return[3,11];case 9:return[4,t];case 10:l.sent(),l.label=11;case 11:return[2]}})}function rn(e){return d([],u(e),!1).sort(function(e,t){return Vt(e)-Vt(t)})}function on(e,t,n){var r,i,o;return void 0===n&&(n={counter:0,visited:new Map}),l(this,function(s){switch(s.label){case 0:if(!(e.length>2&&e.length>Nt.optimizedMinLength))return[3,5];r=1,s.label=1;case 1:return r<e.length-1?n.counter>Nt.maxNumberOfTries?[2]:(n.counter+=1,(i=d([],u(e),!1)).splice(r,1),o=Qt(i),n.visited.has(o)?[2]:Zt(i)&&function(e,t){return Dt.querySelector(Qt(e))===t}(i,t)?[4,i]:[3,4]):[3,5];case 2:return s.sent(),n.visited.set(o,!0),[5,c(on(i,t,n))];case 3:s.sent(),s.label=4;case 4:return r++,[3,1];case 5:return[2]}})}var sn=function(e,t){var n=document.createDocumentFragment();return function(e,t,n){var r,i,s=o({},e);try{for(var a=c(["blockSelector","maskSelector","unmaskSelector"]),l=a.next();!l.done;l=a.next()){var u=l.value,d=e[u],v=("string"==typeof d?[d]:null!=d?d:[]).filter(function(e){try{return t(e),!0}catch(t){if(!n)throw new Error("Invalid privacy selector: ".concat(e));return n(e),!1}});s[u]=v.length?v:void 0}}catch(e){r={error:e}}finally{try{l&&!l.done&&(i=a.return)&&i.call(a)}finally{if(r)throw r.error}}return s}(e,function(e){n.querySelector(e)},function(e){t.warn('[session-replay-browser] omitting selector "'.concat(e,'" because it is invalid'))})},an=function(){function e(e,t){this.localConfig=t,this.remoteConfigClient=e}return e.prototype.generateJoinedConfig=function(){var e,t,n,r,i,s,v,h;return a(this,void 0,void 0,function(){var a,f,g,p,m,y,b,S,w,I,C,k,E,x,P,T,M,R,O=this;return l(this,function(l){switch(l.label){case 0:(a=o({},this.localConfig)).optOut=this.localConfig.optOut,a.captureEnabled=!0,l.label=1;case 1:return l.trys.push([1,3,,4]),[4,new Promise(function(e,t){O.remoteConfigClient.subscribe("configs.sessionReplay",{timeout:1500},function(n,r){var i;if(O.localConfig.loggerProvider.debug("Session Replay remote configuration received from ".concat(r,":"),JSON.stringify(n,null,2)),n){var o=n,s=o.sr_sampling_config,l=o.sr_privacy_config,c=o.sr_targeting_config,u=o.sr_semantic_config,d=null===(i=a.interactionConfig)||void 0===i?void 0:i.ugcFilterRules;a.interactionConfig=o.sr_interaction_config,a.interactionConfig&&d&&(a.interactionConfig.ugcFilterRules=d),a.loggingConfig=o.sr_logging_config,(s||l||c||u)&&(f={},u&&(f.sr_semantic_config=u),s&&(f.sr_sampling_config=s),l&&(f.sr_privacy_config=l),c&&(f.sr_targeting_config=c)),e()}else t(new Error("No remote config received"))})})];case 2:return l.sent(),[3,4];case 3:return g=l.sent(),this.localConfig.loggerProvider.error("Failed to generate joined config: ",g),a.captureEnabled=!1,[2,{localConfig:this.localConfig,joinedConfig:a,remoteConfig:void 0}];case 4:if(!f)return[2,{localConfig:this.localConfig,joinedConfig:a,remoteConfig:f}];if(p=f.sr_sampling_config,m=f.sr_privacy_config,y=f.sr_targeting_config,(b=f.sr_semantic_config)&&(a.semanticCapture=o(o(o({enabled:!1},a.semanticCapture),b),{families:o(o({},null===(e=a.semanticCapture)||void 0===e?void 0:e.families),b.families)})),p&&Object.keys(p).length>0?(Object.prototype.hasOwnProperty.call(p,"capture_enabled")?a.captureEnabled=p.capture_enabled:a.captureEnabled=!1,Object.prototype.hasOwnProperty.call(p,"sample_rate")&&(a.sampleRate=p.sample_rate),Object.prototype.hasOwnProperty.call(p,"min_session_duration_ms")&&(a.minSessionDurationMs=this.sanitizeMinSessionDurationMs(p.min_session_duration_ms))):(a.captureEnabled=!0,this.localConfig.loggerProvider.debug("Remote config successfully fetched, but no values set for project, Session Replay capture enabled.")),m){S=null!==(t=a.privacyConfig)&&void 0!==t?t:{},w={defaultMaskLevel:null!==(r=null!==(n=m.defaultMaskLevel)&&void 0!==n?n:S.defaultMaskLevel)&&void 0!==r?r:"medium",blockSelector:[],maskSelector:[],unmaskSelector:[],maskAttributes:d([],u(new Set(d(d([],u(null!==(i=S.maskAttributes)&&void 0!==i?i:[]),!1),u(null!==(s=m.maskAttributes)&&void 0!==s?s:[]),!1))),!1),urlMaskLevels:d(d([],u(null!==(v=m.urlMaskLevels)&&void 0!==v?v:[]),!1),u(null!==(h=S.urlMaskLevels)&&void 0!==h?h:[]),!1)},I=function(e){var t,n,r,i,o,s,a,l,u,d={};"string"==typeof e.blockSelector&&(e.blockSelector=[e.blockSelector]);try{for(var v=c(null!==(a=e.blockSelector)&&void 0!==a?a:[]),h=v.next();!h.done;h=v.next()){d[h.value]="block"}}catch(e){t={error:e}}finally{try{h&&!h.done&&(n=v.return)&&n.call(v)}finally{if(t)throw t.error}}try{for(var f=c(null!==(l=e.maskSelector)&&void 0!==l?l:[]),g=f.next();!g.done;g=f.next()){d[g.value]="mask"}}catch(e){r={error:e}}finally{try{g&&!g.done&&(i=f.return)&&i.call(f)}finally{if(r)throw r.error}}try{for(var p=c(null!==(u=e.unmaskSelector)&&void 0!==u?u:[]),m=p.next();!m.done;m=p.next()){d[m.value]="unmask"}}catch(e){o={error:e}}finally{try{m&&!m.done&&(s=p.return)&&s.call(p)}finally{if(o)throw o.error}}return d},C=o(o({},I(S)),I(m));try{for(k=c(Object.entries(C)),E=k.next();!E.done;E=k.next())x=u(E.value,2),P=x[0],"mask"===(T=x[1])?w.maskSelector.push(P):"block"===T?w.blockSelector.push(P):"unmask"===T&&w.unmaskSelector.push(P)}catch(e){M={error:e}}finally{try{E&&!E.done&&(R=k.return)&&R.call(k)}finally{if(M)throw M.error}}a.privacyConfig=sn(w,this.localConfig.loggerProvider)}return y&&Object.keys(y).length>0&&(a.targetingConfig=y),this.localConfig.loggerProvider.debug(JSON.stringify({name:"session replay joined config",config:Be(a)},null,2)),[2,{localConfig:this.localConfig,joinedConfig:a,remoteConfig:f}]}})})},e.prototype.sanitizeMinSessionDurationMs=function(e){if("number"==typeof e&&Number.isFinite(e)){if(!(e<0))return e>ln?(this.localConfig.loggerProvider.warn("min_session_duration_ms remote value ".concat(e," exceeds ").concat(ln,"ms ceiling; clamping.")),ln):e;this.localConfig.loggerProvider.warn("min_session_duration_ms remote value is negative (".concat(e,"); ignoring."))}else this.localConfig.loggerProvider.warn("min_session_duration_ms remote value is not a finite number (got ".concat(String(e),"); ignoring."))},e}(),ln=6e4,cn=function(e,t){return a(void 0,void 0,void 0,function(){var n,r;return l(this,function(i){return n=new ze(e,t),r=new Z(e,n.loggerProvider,n.serverZone,t.configServerUrl,t.handleFetchConfig),[2,new an(r,n)]})})};function un(e){for(var t=e.length,n=0;n<t&&!(e.charCodeAt(n)>127);n++);if(n===t)return t;for(var r=n;n<t;n++){var i=e.charCodeAt(n);if(i<=127)r++;else if(i<=2047)r+=2;else if(i>=55296&&i<=56319){var o=n+1<t?e.charCodeAt(n+1):NaN;o>=56320&&o<=57343?(r+=4,n++):r+=3}else r+=3}return r}function dn(e){for(var t=0,n=0;n<e.length;n++)t+=un(e[n]);return t}function vn(e,t){if(!(3*e.length<=t)){var n=un(e);return n>t?n:void 0}}function hn(e,t){t<0&&(t=0);for(var n=e.length,r=0,i=0;i<n;i++){var o=e.charCodeAt(i),s=1,a=1;if(o<=127)s=1;else if(o<=2047)s=2;else if(o>=55296&&o<=56319){var l=i+1<n?e.charCodeAt(i+1):NaN;l>=56320&&l<=57343?(s=4,a=2):s=3}else s=3;if(r+s>t)break;r+=s,2===a&&i++}return i>=n?{value:e,truncated:!1}:{value:e.slice(0,i),truncated:!0}}function fn(e){if(e.type!==Ut.IncrementalSnapshot)return!1;var t=e.data;return t.source===jt.Mutation&&!t.isAttachIframe}function gn(e){var t,n,r=new Map;if(e.forEach(function(e,t){if(e.attributes&&"style"in e.attributes){var n=r.get(e.id);n?n.push(t):r.set(e.id,[t])}}),0===r.size)return e;var i=function(t){return e[t].attributes.style},s=new Set,a=new Map,l=function(e){if(1===e.length)return"continue";var t=-1;e.forEach(function(e,n){var r;("object"!=typeof(r=i(e))||null===r)&&(t=n)});var n=[];if(e.forEach(function(e,r){r!==t&&(s.add(e),r>t&&n.push(e))}),n.length>0){var r=n[n.length-1],o=function(e){var t,n,r,i,o={};try{for(var s=c(e),a=s.next();!a.done;a=s.next()){var l=a.value;try{for(var u=(r=void 0,c(Object.keys(l))),d=u.next();!d.done;d=u.next()){var v=d.value;o[v]=l[v]}}catch(e){r={error:e}}finally{try{d&&!d.done&&(i=u.return)&&i.call(u)}finally{if(r)throw r.error}}}}catch(e){t={error:e}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}return o}(n.map(function(e){return i(e)}));s.delete(r),a.set(r,o)}};try{for(var u=c(r.values()),d=u.next();!d.done;d=u.next()){l(d.value)}}catch(e){t={error:e}}finally{try{d&&!d.done&&(n=u.return)&&n.call(u)}finally{if(t)throw t.error}}if(0===s.size&&0===a.size)return e;var v=[];return e.forEach(function(e,t){var n=a.get(t);if(void 0===n)if(s.has(t)){var r=o({},e.attributes);delete r.style,Object.keys(r).length>0&&v.push(o(o({},e),{attributes:r}))}else v.push(e);else v.push(o(o({},e),{attributes:o(o({},e.attributes),{style:n})}))}),v}function pn(e){var t,n,r,i,s=e[0],a=new Map,l=new Map,d=new Map,v=new Map,h=new Map;e.forEach(function(e,t){var n,r,i,o,s=e.data;try{for(var u=c(s.adds),f=u.next();!f.done;f=u.next()){var g=f.value;a.has(g.node.id)||a.set(g.node.id,t),l.set(g.node.id,t),h.set(g.node.id,g.parentId)}}catch(e){n={error:e}}finally{try{f&&!f.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}try{for(var p=c(s.removes),m=p.next();!m.done;m=p.next()){var y=m.value;d.has(y.id)||d.set(y.id,t),v.set(y.id,t)}}catch(e){i={error:e}}finally{try{m&&!m.done&&(o=p.return)&&o.call(p)}finally{if(i)throw i.error}}});var f=new Set,g=new Set;try{for(var p=c(a),m=p.next();!m.done;m=p.next()){var y=u(m.value,2),b=y[0],S=y[1],w=d.get(b);if(void 0!==w)l.get(b)>=v.get(b)||(S<w?f.add(b):w<S&&g.add(b))}}catch(e){t={error:e}}finally{try{m&&!m.done&&(n=p.return)&&n.call(p)}finally{if(t)throw t.error}}var I=new Set;if(f.size>0||g.size>0)for(var C=!0;C;){C=!1;try{for(var k=(r=void 0,c(h)),E=k.next();!E.done;E=k.next()){var x=u(E.value,2),P=x[0],T=x[1];if(!f.has(P)&&!g.has(P)&&!I.has(P)&&(f.has(T)||g.has(T)||I.has(T))){var M=d.get(P),R=a.get(P);void 0!==M&&void 0!==R&&M<R?g.add(P):void 0!==M&&void 0!==R&&M===R?I.add(P):f.add(P),C=!0}}}catch(e){r={error:e}}finally{try{E&&!E.done&&(i=k.return)&&i.call(k)}finally{if(r)throw r.error}}}var O=f.size>0||g.size>0||I.size>0,_=[];e.forEach(function(e,t){var n,r;try{for(var i=c(e.data.removes),o=i.next();!o.done;o=i.next()){var s=o.value;f.has(s.id)||(g.has(s.id)&&t>=a.get(s.id)||I.has(s.id)&&(f.has(s.parentId)||g.has(s.parentId)||I.has(s.parentId))||_.push(s))}}catch(e){n={error:e}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}});var A=e.flatMap(function(e){return e.data.adds}),L=e.flatMap(function(e){return e.data.texts}),F=e.flatMap(function(e){return e.data.attributes}),N=O?F.filter(function(e){return!f.has(e.id)&&!g.has(e.id)&&!I.has(e.id)}):F,D={source:jt.Mutation,removes:_,adds:O?A.filter(function(e){return!f.has(e.node.id)&&!g.has(e.node.id)&&!I.has(e.node.id)}):A,texts:O?L.filter(function(e){return!f.has(e.id)&&!g.has(e.id)&&!I.has(e.id)}):L,attributes:gn(N)};return o(o({},s),{data:D})}function mn(e){if(e.length<=1)return e;for(var t=[],n=0;n<e.length;)if(fn(e[n])){for(var r=n+1;r<e.length&&fn(e[r]);)r++;t.push(r>n+1?pn(e.slice(n,r)):e[n]),n=r}else t.push(e[n]),n++;return t}var yn=function(){function e(e,t,n,r,i){var o,s=this;this.taskQueue=[],this.pendingQueue=[],this.isProcessing=!1,this.compressEvent=function(e){var t=e,n=t.type,r=t.timestamp,i=t.delay,o=t.data;return null!=i?JSON.stringify({type:n,timestamp:r,delay:i,data:o}):JSON.stringify({type:n,timestamp:r,data:o})},this.addCompressedEventToManager=function(e,t){var n,r=vn(e,null!==(n=s.config.maxSingleEventSizeBytes)&&void 0!==n?n:ye);void 0===r?s.eventsManager&&s.deviceId&&s.eventsManager.addEvent({event:{type:"replay",data:e},sessionId:t,deviceId:s.deviceId}):s.config.loggerProvider.warn("Session replay event dropped: serialized size ".concat(Math.round(r/1024)," KB exceeds maximum allowed event size. If this recurs, please open a GitHub issue at https://github.com/amplitude/Amplitude-TypeScript/issues or contact Amplitude support."))},this.addCompressedEvent=function(e,t){if(s.worker)try{s.worker.postMessage({event:e,sessionId:t})}catch(n){"DataCloneError"===n.name?s.worker.postMessage(JSON.stringify({event:e,sessionId:t})):s.config.loggerProvider.warn("Unexpected error while posting message to worker:",n)}else{var n=s.compressEvent(e);s.addCompressedEventToManager(n,t)}},this.flushQueue=function(){var e;for(s.pendingQueue.length>0&&(e=s.taskQueue).push.apply(e,d([],u(s.mergeMutationTasks(s.pendingQueue.splice(0))),!1));s.taskQueue.length>0;){var t=s.taskQueue.shift();if(t){var n=t.event,r=t.sessionId,i=s.compressEvent(n);s.addCompressedEventToManager(i,r)}}s.isProcessing=!1},this.terminate=function(){var e;null===(e=s.worker)||void 0===e||e.terminate()};var a=g();if(this.canUseIdleCallback=a&&"requestIdleCallback"in a,this.eventsManager=e,this.config=t,this.deviceId=n,this.timeout=(null===(o=t.performanceConfig)||void 0===o?void 0:o.timeout)||2e3,this.onFullSnapshotProcessed=i,r){t.loggerProvider.log("Enabling web worker for compression");try{var l=new Blob([r],{type:"application/javascript"}),c=URL.createObjectURL(l),v=new Worker(c);v.onerror=function(e){e.preventDefault(),t.loggerProvider.error("Worker failed, falling back to non-worker compression: ".concat(e.message," (").concat(e.filename,":").concat(e.lineno,")")),v.terminate(),s.worker=void 0},v.onmessage=function(e){var t=e.data,n=t.compressedEvent,r=t.sessionId;s.addCompressedEventToManager(n,r)},this.worker=v}catch(e){t.loggerProvider.error("Failed to create worker, falling back to non-worker compression:",e)}}}return e.prototype.scheduleIdleProcessing=function(){var e=this;this.isProcessing||(this.isProcessing=!0,requestIdleCallback(function(t){e.processQueue(t)},{timeout:this.timeout}))},e.prototype.enqueueEvent=function(e,t){var n,r,i,o;if(e.type===Ut.FullSnapshot){if(this.config.loggerProvider.debug("Processing full snapshot immediately."),this.taskQueue.length>0||this.pendingQueue.length>0){var s=d(d([],u(this.taskQueue.splice(0)),!1),u(this.mergeMutationTasks(this.pendingQueue.splice(0))),!1);try{for(var a=c(s),l=a.next();!l.done;l=a.next()){var v=l.value,h=this.compressEvent(v.event);this.addCompressedEventToManager(h,v.sessionId)}}catch(e){n={error:e}}finally{try{l&&!l.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}this.isProcessing=!1}var f=this.compressEvent(e);return this.addCompressedEventToManager(f,t),void(null===(i=this.onFullSnapshotProcessed)||void 0===i||i.call(this))}this.canUseIdleCallback&&(null===(o=this.config.performanceConfig)||void 0===o?void 0:o.enabled)?(this.config.loggerProvider.debug("Enqueuing event for processing during idle time."),this.pendingQueue.push({event:e,sessionId:t}),this.scheduleIdleProcessing()):(this.config.loggerProvider.debug("Processing event without idle callback."),this.addCompressedEvent(e,t))},e.prototype.processQueue=function(e){var t,n=this;for(this.pendingQueue.length>0&&(t=this.taskQueue).push.apply(t,d([],u(this.mergeMutationTasks(this.pendingQueue.splice(0))),!1));this.taskQueue.length>0&&(e.timeRemaining()>0||e.didTimeout);){var r=this.taskQueue.shift();if(r){var i=r.event,o=r.sessionId;this.addCompressedEvent(i,o)}}this.taskQueue.length>0||this.pendingQueue.length>0?requestIdleCallback(function(e){n.processQueue(e)},{timeout:this.timeout}):this.isProcessing=!1},e.prototype.mergeMutationTasks=function(e){var t,n,r;if(!1===(null===(r=this.config.performanceConfig)||void 0===r?void 0:r.mergeMutations))return e;if(e.length<=1)return e;for(var i=[],o=0;o<e.length;){for(var s=e[o].sessionId,a=o+1;a<e.length&&e[a].sessionId===s;)a++;var l=mn(e.slice(o,a).map(function(e){return e.event}));try{for(var u=(t=void 0,c(l)),d=u.next();!d.done;d=u.next()){var v=d.value;i.push({event:v,sessionId:s})}}catch(e){t={error:e}}finally{try{d&&!d.done&&(n=u.return)&&n.call(u)}finally{if(t)throw t.error}}o=a}return i},e}(),bn="Session replay event batch rejected due to exceeded retry count",Sn="Failed to store session replay events in IndexedDB",wn="Session replay event batch dropped: server signalled capture disabled or session out of valid range for this session",In="1.52.0-codexsemantic-review-integration.0";function Cn(e,t){return a(this,void 0,void 0,function(){var n,r,i,o,s,u,d,v,h,f,g,p,m,y,b=this;return l(this,function(S){switch(S.label){case 0:return S.trys.push([0,4,,5]),n=t.CompressionStream,r=new n("gzip"),i=r.writable.getWriter(),o=r.readable.getReader(),s=[],u=a(b,void 0,void 0,function(){var e,t,n;return l(this,function(r){switch(r.label){case 0:return[4,o.read()];case 1:if(e=r.sent(),t=e.done,n=e.value,t)return[3,3];s.push(n),r.label=2;case 2:return[3,0];case 3:return[2]}})}),[4,i.write((new TextEncoder).encode(e))];case 1:return S.sent(),[4,i.close()];case 2:return S.sent(),[4,u];case 3:S.sent(),d=s.reduce(function(e,t){return e+t.length},0),v=new Uint8Array(d),h=0;try{for(f=c(s),g=f.next();!g.done;g=f.next())p=g.value,v.set(p,h),h+=p.length}catch(e){m={error:e}}finally{try{g&&!g.done&&(y=f.return)&&y.call(f)}finally{if(m)throw m.error}}return[2,v];case 4:return S.sent(),[2,null];case 5:return[2]}})})}var kn=function(){function e(e){var t=e.trackServerUrl,n=e.loggerProvider,r=e.payloadBatcher,i=e.workerScript,o=e.enableTransportCompression,s=e.sendTimeoutMs,a=e.handleSendEvents,l=this;if(this.storageKey="",this.retryTimeout=1e3,this.scheduled=null,this.queue=[],this.sendIdCounter=0,this.pendingWorkerRequests=new Map,this.timedOutWorkerRequests=new Map,this.flushPauseUntilMs=0,this.mergeOnNextFlush=!1,this.coalesceNextFlush=!1,this.mergeLogFiredThisPause=!1,this.killedSessions=new Set,this.loggerProvider=n,this.payloadBatcher=r||function(e){return e},this.trackServerUrl=t,this.enableTransportCompression=null==o||o,this.sendTimeoutMs=null!=s?s:1e4,this.handleSendEvents=a,i)try{var d=new Blob([i],{type:"application/javascript"}),v=URL.createObjectURL(d),h=new Worker(v);h.onerror=function(e){var t,r;e.preventDefault(),n.error("Track destination worker failed, falling back to main-thread sending: ".concat(e.message," (").concat(e.filename,":").concat(e.lineno,")")),h.terminate(),l.worker=void 0;try{for(var i=c(l.pendingWorkerRequests),o=i.next();!o.done;o=i.next()){var s=u(o.value,2)[1];s.timeout&&clearTimeout(s.timeout),n.warn("Session replay event send failed due to worker crash: ".concat(e.message)),s.resolve()}}catch(e){t={error:e}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(t)throw t.error}}l.pendingWorkerRequests.clear(),l.timedOutWorkerRequests.clear()},h.onmessage=function(e){var t=e.data;if("log"===t.type)n.log(t.message);else if("warn"===t.type)n.warn(t.message);else if("payload_too_large"===t.type){var r=l.pendingWorkerRequests.get(t.id);if(r)r.timeout&&clearTimeout(r.timeout),l.handlePayloadTooLargeResponse(r.context,t.isWaf),r.resolve(),l.pendingWorkerRequests.delete(t.id);else(i=l.timedOutWorkerRequests.get(t.id))&&(l.timedOutWorkerRequests.delete(t.id),l.handlePayloadTooLargeResponse(i,t.isWaf))}else if("complete"===t.type){var i,o=l.pendingWorkerRequests.get(t.id);if(o)o.timeout&&clearTimeout(o.timeout),void 0!==t.skipCode&&l.applyServerDirective(o.context.sessionId,t.skipCode),l.completeRequest({context:o.context}),o.resolve(),l.pendingWorkerRequests.delete(t.id);else(i=l.timedOutWorkerRequests.get(t.id))&&(l.timedOutWorkerRequests.delete(t.id),void 0!==t.skipCode&&l.applyServerDirective(i.sessionId,t.skipCode),l.completeRequest({context:i}))}else"fetch-request"===t.type&&l.handleDelegatedFetch(h,t).catch(function(e){n.warn("Failed to handle delegated session replay fetch:",e)})},this.worker=h}catch(e){n.error("Failed to create track destination worker, falling back to main-thread sending:",e)}}return e.prototype.sendEventsList=function(e){this.addToQueue(o(o({},e),{attempts:0,timeout:0}))},e.prototype.markCoalesceNextFlush=function(){this.coalesceNextFlush=!0,this.schedule(0)},e.prototype.sendBeacon=function(e){var t,n,r=this,i=e.events,o=e.sessionId,s=e.deviceId,a=e.apiKey,l=e.serverZone,c=function(e){return un(e)},u=i,d=JSON.stringify({version:2,events:u});if(c(d)>65536){for(var v=0,h=u.length;v<h;){var f=Math.floor((v+h+1)/2);c(JSON.stringify({version:2,events:u.slice(0,f)}))<=65536?v=f:h=f-1}u=u.slice(0,v),d=JSON.stringify({version:2,events:u}),this.loggerProvider.warn("sendBeacon payload exceeded 64 KB limit, trimmed from ".concat(i.length," to ").concat(u.length," events"))}if(0!==u.length)if(this.handleSendEvents){var p=new URLSearchParams({device_id:s,session_id:String(o),type:"replay"}),m="".concat(De(l,this.trackServerUrl),"?").concat(p.toString()),y={"Content-Type":"application/json",Accept:"*/*",Authorization:"Bearer ".concat(a)};this.loggerProvider.debug("Routing session replay exit batch (".concat(u.length," events) through custom transport for session id ").concat(o,"."));try{this.handleSendEvents({url:m,method:"POST",headers:y,body:d,keepalive:!0}).catch(function(e){r.loggerProvider.warn("Custom transport failed to send session replay exit batch:",e)})}catch(e){this.loggerProvider.warn("Custom transport threw while sending session replay exit batch:",e)}}else{var b=new URLSearchParams({device_id:s,session_id:String(o),type:"replay",api_key:a}),S="".concat(De(l,this.trackServerUrl),"?").concat(b.toString()),w=g();try{var I=new Blob([d],{type:"application/json"});!1===(null===(n=null===(t=null==w?void 0:w.navigator)||void 0===t?void 0:t.sendBeacon)||void 0===n?void 0:n.call(t,S,I))&&this.loggerProvider.warn("sendBeacon failed to queue session replay payload")}catch(e){}}},e.prototype.addToQueue=function(){for(var e=this,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];t.filter(function(t){return e.killedSessions.has(t.sessionId)?(e.completeRequest({context:t,err:wn}),!1):t.attempts<(t.flushMaxRetries||0)?(t.attempts+=1,!0):(e.completeRequest({context:t,err:bn}),!1)}).forEach(function(t){e.queue=e.queue.concat(t),e.schedule(0)})},e.prototype.schedule=function(e){var t=this;if(!this.scheduled){var n=this.flushPauseUntilMs-Date.now(),r=n>e?n:e;n>0&&(this.mergeOnNextFlush=!0),this.scheduled=setTimeout(function(){t.flush(!0).then(function(){t.queue.length>0&&t.schedule(e)})},r)}},e.prototype.flush=function(e){return void 0===e&&(e=!1),a(this,void 0,void 0,function(){var t,n,r,i,o,s,a;return l(this,function(l){switch(l.label){case 0:t=this.queue,this.queue=[],this.scheduled&&(clearTimeout(this.scheduled),this.scheduled=null),this.mergeOnNextFlush?(this.mergeOnNextFlush=!1,this.coalesceNextFlush=!1,t=this.mergeQueueAfterThrottle(t)):this.coalesceNextFlush&&(this.coalesceNextFlush=!1,t=this.mergeDrainBacklog(t)),l.label=1;case 1:l.trys.push([1,6,7,8]),n=c(t),r=n.next(),l.label=2;case 2:return r.done?[3,5]:(i=r.value,[4,this.send(i,e)]);case 3:l.sent(),l.label=4;case 4:return r=n.next(),[3,2];case 5:return[3,8];case 6:return o=l.sent(),s={error:o},[3,8];case 7:try{r&&!r.done&&(a=n.return)&&a.call(n)}finally{if(s)throw s.error}return[7];case 8:return[2]}})})},e.prototype.mergeQueueAfterThrottle=function(e){var t=this.coalesceByIdentity(e);return t.length<e.length&&!this.mergeLogFiredThisPause&&(this.mergeLogFiredThisPause=!0,this.loggerProvider.log("Session replay throttle pause ended; merged ".concat(e.length," queued batches into ").concat(t.length," request(s)"))),t},e.prototype.mergeDrainBacklog=function(e){var t=this.coalesceByIdentity(e);return t.length<e.length&&this.loggerProvider.log("Session replay coalesced ".concat(e.length," persisted page-load backlog batches into ").concat(t.length," request(s)")),t},e.prototype.coalesceByIdentity=function(e){var t,n,r,i,s,v,h,f,g,p,m,y=this;if(e.length<=1)return e;var b=new Map;try{for(var S=c(e),w=S.next();!w.done;w=S.next()){var I=w.value,C=[I.sessionId,null!==(s=I.deviceId)&&void 0!==s?s:"",null!==(v=I.apiKey)&&void 0!==v?v:"",I.type,null!==(h=I.serverZone)&&void 0!==h?h:"",I.sampleRate,null!==(g=null===(f=I.version)||void 0===f?void 0:f.type)&&void 0!==g?g:"",null!==(m=null===(p=I.version)||void 0===p?void 0:p.version)&&void 0!==m?m:""].join("|"),k=b.get(C);k?k.push(I):b.set(C,[I])}}catch(e){t={error:e}}finally{try{w&&!w.done&&(n=S.return)&&n.call(S)}finally{if(t)throw t.error}}var E=[],x=function(e){var t,n;if(1===e.length)return E.push(e[0]),"continue";var r=null,i=0,s=function(){r&&E.push(r),r=null,i=0},v=function(e){var t=dn(e.events);if(null===r)return r=o(o({},e),{events:d([],u(e.events),!1),attempts:0}),i=t,"continue";if(i+t>4e6)return s(),r=o(o({},e),{events:d([],u(e.events),!1),attempts:0}),i=t,"continue";var n=r.onComplete,c=e.onComplete;r.events=r.events.concat(e.events),i+=t,r.onComplete=function(){return a(y,void 0,void 0,function(){return l(this,function(e){switch(e.label){case 0:return[4,Promise.allSettled([n(),c()])];case 1:return e.sent(),[2]}})})}};try{for(var h=(t=void 0,c(e)),f=h.next();!f.done;f=h.next()){v(f.value)}}catch(e){t={error:e}}finally{try{f&&!f.done&&(n=h.return)&&n.call(h)}finally{if(t)throw t.error}}s()};try{for(var P=c(b.values()),T=P.next();!T.done;T=P.next()){x(T.value)}}catch(e){r={error:e}}finally{try{T&&!T.done&&(i=P.return)&&i.call(P)}finally{if(r)throw r.error}}return E},e.prototype.send=function(e,t){return void 0===t&&(t=!0),a(this,void 0,void 0,function(){var n,r,i,o;return l(this,function(s){return this.killedSessions.has(e.sessionId)?[2,this.completeRequest({context:e,err:wn})]:(n=e.apiKey)?(r=e.deviceId)?0===(i=this.payloadBatcher({version:1,events:e.events})).events.length?(this.completeRequest({context:e}),[2]):(o=this.worker)?[2,this.sendViaWorker(o,e,i,t)]:[2,this.sendOnMainThread(n,r,e,i,t)]:[2,this.completeRequest({context:e,err:"Session replay event batch not sent due to missing device ID"})]:[2,this.completeRequest({context:e,err:"Session replay event batch not sent due to missing api key"})]})})},e.prototype.sendViaWorker=function(e,t,n,r){return a(this,void 0,void 0,function(){var i,o=this;return l(this,function(s){return i="".concat(++this.sendIdCounter),[2,new Promise(function(s){var a,l=o.sendTimeoutMs>0?setTimeout(function(){var e=o.pendingWorkerRequests.get(i);e&&(o.pendingWorkerRequests.delete(i),o.rememberTimedOutRequest(i,e.context),o.loggerProvider.warn("Session replay worker send timed out after ".concat(o.sendTimeoutMs,"ms; leaving events for retry")),e.resolve())},o.sendTimeoutMs):void 0;o.pendingWorkerRequests.set(i,{context:t,resolve:s,timeout:l}),e.postMessage({type:"send",id:i,payload:n,useRetry:r,useCustomTransport:!!o.handleSendEvents,context:{apiKey:t.apiKey,deviceId:t.deviceId,sessionId:t.sessionId,events:t.events,eventType:t.type,flushMaxRetries:null!==(a=t.flushMaxRetries)&&void 0!==a?a:0,sampleRate:t.sampleRate,serverZone:t.serverZone,trackServerUrl:o.trackServerUrl,version:t.version,currentUrl:qe(),sdkVersion:In,enableTransportCompression:o.enableTransportCompression,sendTimeoutMs:o.sendTimeoutMs}})})]})})},e.prototype.rememberTimedOutRequest=function(e,t){var n,r;if(this.timedOutWorkerRequests.set(e,t),this.timedOutWorkerRequests.size>256)try{for(var i=c(this.timedOutWorkerRequests.keys()),o=i.next();!o.done;o=i.next()){var s=o.value;this.timedOutWorkerRequests.delete(s);break}}catch(e){n={error:e}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}},e.prototype.handleDelegatedFetch=function(e,t){var n,r,i;return a(this,void 0,void 0,function(){var o,s,a,c,u,d,v,h,f,g,p;return l(this,function(l){switch(l.label){case 0:o=t.requestId,s=t.url,a=t.method,c=t.headers,u=t.body,d=t.keepalive,l.label=1;case 1:return l.trys.push([1,10,,11]),v=void 0,this.handleSendEvents?[4,this.handleSendEvents({url:s,method:a,headers:c,body:u,keepalive:d})]:[3,3];case 2:return v=l.sent(),[3,5];case 3:return this.loggerProvider.warn("Delegated session replay fetch received without a custom transport configured; falling back to built-in fetch."),[4,fetch(s,{method:a,headers:c,body:u,keepalive:d})];case 4:v=l.sent(),l.label=5;case 5:if(h=v.status,f=null,g="",h>=200&&h<300&&(f=null!==(i=null===(r=null===(n=v.headers)||void 0===n?void 0:n.get)||void 0===r?void 0:r.call(n,Ce))&&void 0!==i?i:null),413!==h)return[3,9];l.label=6;case 6:return l.trys.push([6,8,,9]),[4,v.text()];case 7:return g=l.sent(),[3,9];case 8:return l.sent(),[3,9];case 9:return this.loggerProvider.debug("Delegated session replay fetch (request ".concat(o,") returned status ").concat(h,".")),e.postMessage({type:"fetch-response",requestId:o,status:h,skipHeader:f,body:g}),[3,11];case 10:return p=l.sent(),this.loggerProvider.debug("Delegated session replay fetch (request ".concat(o,") failed:"),p),e.postMessage({type:"fetch-response",requestId:o,status:0,skipHeader:null,body:String(p),error:!0}),[3,11];case 11:return[2]}})})},e.prototype.sendOnMainThread=function(e,t,n,r,i){var s,c,u,d,v,h,f;return a(this,void 0,void 0,function(){var a,p,m,y,b,S,w,I,C,k,E,x,P,T,M,R,O,_,A,L,F,N;return l(this,function(l){switch(l.label){case 0:a=qe(),p=In,m=n.sampleRate,y=new URLSearchParams({device_id:t,session_id:"".concat(n.sessionId),type:"".concat(n.type)}),b="".concat(null!==(c=null===(s=n.version)||void 0===s?void 0:s.type)&&void 0!==c?c:"standalone","/").concat(null!==(d=null===(u=n.version)||void 0===u?void 0:u.version)&&void 0!==d?d:p),l.label=1;case 1:return l.trys.push([1,19,,23]),S=JSON.stringify(r),w=g(),this.enableTransportCompression&&w&&"CompressionStream"in w?[4,Cn(S,w)]:[3,3];case 2:return C=l.sent(),[3,4];case 3:C=null,l.label=4;case 4:if(k=(I=C)?I.byteLength:un(S),E=new AbortController,x=o({"Content-Type":"application/json",Accept:"*/*",Authorization:"Bearer ".concat(e),"X-Client-Version":p,"X-Client-Library":b,"X-Client-Url":a.substring(0,1e3),"X-Client-Sample-Rate":"".concat(m),"X-Sampling-Hash-Alg":"xxhash32"},I?{"Content-Encoding":"gzip"}:{}),M={headers:x,body:P=null!=I?I:S,method:"POST",keepalive:T=k<=65536,signal:E.signal},R="".concat(De(n.serverZone,this.trackServerUrl),"?").concat(y.toString()),0===r.events.length)return this.completeRequest({context:n}),[2];O=this.sendTimeoutMs>0?setTimeout(function(){E.abort()},this.sendTimeoutMs):void 0,_=void 0,l.label=5;case 5:return l.trys.push([5,,10,11]),this.handleSendEvents?[4,(D=this.handleSendEvents({url:R,method:"POST",headers:x,body:P,keepalive:T}),q=E.signal,new Promise(function(e,t){var n=function(){var e=new Error("Custom session replay transport aborted by send timeout");e.name="AbortError",t(e)};q.addEventListener("abort",n,{once:!0}),D.then(function(t){q.removeEventListener("abort",n),e(t)},function(e){q.removeEventListener("abort",n),t(e)})}))]:[3,7];case 6:return A=l.sent(),[3,9];case 7:return[4,fetch(R,M)];case 8:A=l.sent(),l.label=9;case 9:return _=A,[3,11];case 10:return O&&clearTimeout(O),[7];case 11:if(null===_)return this.completeRequest({context:n,err:"Unexpected error occurred"}),[2];if(_.status>=200&&_.status<300&&(L=null!==(f=null===(h=null===(v=_.headers)||void 0===v?void 0:v.get)||void 0===h?void 0:h.call(v,Ce))&&void 0!==f?f:null,this.applyServerDirective(n.sessionId,L)),i)return[3,12];F="";try{F=JSON.stringify(_.body,null,2)}catch(e){}return this.completeRequest({context:n,success:"".concat(_.status,": ").concat(F)}),[3,18];case 12:if(F="",413!==_.status)return[3,16];l.label=13;case 13:return l.trys.push([13,15,,16]),[4,_.text()];case 14:return F=l.sent(),[3,16];case 15:return l.sent(),[3,16];case 16:return[4,this.handleReponse(_.status,n,F)];case 17:l.sent(),l.label=18;case 18:return[3,23];case 19:return N=l.sent(),!!N&&"object"==typeof N&&"AbortError"===N.name&&i?[4,this.handleOtherResponse(n)]:[3,21];case 20:return l.sent(),[3,22];case 21:this.completeRequest({context:n,err:N}),l.label=22;case 22:return[3,23];case 23:return[2]}var D,q})})},e.prototype.handleReponse=function(e,t,n){return void 0===n&&(n=""),a(this,void 0,void 0,function(){var r;return l(this,function(i){switch(i.label){case 0:switch(r=(new K).buildStatus(e),r){case v.Success:return[3,1];case v.Failed:case v.Timeout:case v.RateLimit:return[3,2];case v.PayloadTooLarge:return[3,4]}return[3,5];case 1:return this.handleSuccessResponse(t),[3,8];case 2:return[4,this.handleOtherResponse(t)];case 3:return i.sent(),[3,8];case 4:return this.handlePayloadTooLargeResponse(t,be.test(n)),[3,8];case 5:return 499!==e?[3,7]:[4,this.handleOtherResponse(t)];case 6:return i.sent(),[3,8];case 7:this.completeRequest({context:t,err:"Network error occurred, event batch rejected"}),i.label=8;case 8:return[2]}})})},e.prototype.handlePayloadTooLargeResponse=function(e,t){var n=t?"WAF (compressed payload too large)":"server (event too large)",r=Math.round(e.events.reduce(function(e,t){return e+t.length},0)/Ie);if(t)if(1!==e.events.length){this.loggerProvider.warn("Session replay event batch rejected by ".concat(n," (").concat(e.events.length," events, ").concat(r," KB total) — splitting and retrying")),e.onComplete();var i=function(){return Promise.resolve()},s=Math.floor(e.events.length/2);this.sendEventsList(o(o({},e),{events:e.events.slice(0,s),onComplete:i})),this.sendEventsList(o(o({},e),{events:e.events.slice(s),onComplete:i}))}else this.completeRequest({context:e,err:"Session replay event dropped: single event (".concat(r," KB, 1 event) rejected by ").concat(n," — cannot split further")});else this.completeRequest({context:e,err:"Session replay event batch dropped: ".concat(n," rejected payload (").concat(e.events.length," events, ").concat(r," KB) — not retrying non-WAF 413")})},e.prototype.handleSuccessResponse=function(e){var t=Math.round(dn(e.events)/Ie);this.completeRequest({context:e,success:"Session replay event batch tracked successfully for session id ".concat(e.sessionId,", size of events: ").concat(t," KB")})},e.prototype.handleOtherResponse=function(e){return a(this,void 0,void 0,function(){var t;return l(this,function(n){switch(n.label){case 0:return t=Math.random()*e.attempts*this.retryTimeout,e.attempts++,e.attempts>(e.flushMaxRetries||0)?(this.completeRequest({context:e,err:bn}),[2]):[4,new Promise(function(e){return setTimeout(e,t)})];case 1:return n.sent(),[4,this.send(e,!0)];case 2:return n.sent(),[2]}})})},e.prototype.completeRequest=function(e){var t=e.context,n=e.err,r=e.success;t.onComplete(),n?this.loggerProvider.warn(n):r&&this.loggerProvider.log(r)},e.prototype.applyServerDirective=function(e,t){if(null===t)return this.flushPauseUntilMs=0,void(this.mergeLogFiredThisPause=!1);if("429"===t){var n=this.flushPauseUntilMs>Date.now();return this.flushPauseUntilMs=Date.now()+6e4,void(n||this.loggerProvider.log("Session replay throttled by server; pausing flush schedule for ".concat(60,"s")))}"4005"!==t&&"4004"!==t||this.killSession(e,t)},e.prototype.killSession=function(e,t){var n,r,i,o;if(!this.killedSessions.has(e)){if(this.killedSessions.add(e),this.killedSessions.size>256)try{for(var s=c(this.killedSessions),a=s.next();!a.done;a=s.next()){var l=a.value;this.killedSessions.delete(l);break}}catch(e){n={error:e}}finally{try{a&&!a.done&&(r=s.return)&&r.call(s)}finally{if(n)throw n.error}}this.loggerProvider.log("Session replay capture stopped for session ".concat(e," by server directive ").concat(t,"; remaining events will be dropped"));var u=[];try{for(var d=c(this.queue),v=d.next();!v.done;v=d.next()){var h=v.value;h.sessionId===e?this.completeRequest({context:h,err:wn}):u.push(h)}}catch(e){i={error:e}}finally{try{v&&!v.done&&(o=d.return)&&o.call(d)}finally{if(i)throw i.error}}this.queue=u}},e}();const En=(e,t)=>t.some(t=>e instanceof t);let xn,Pn;const Tn=new WeakMap,Mn=new WeakMap,Rn=new WeakMap;let On={get(e,t,n){if(e instanceof IDBTransaction){if("done"===t)return Tn.get(e);if("store"===t)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return Fn(e[t])},set:(e,t,n)=>(e[t]=n,!0),has:(e,t)=>e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e};function _n(e){On=e(On)}function An(e){return(Pn||(Pn=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(e)?function(...t){return e.apply(Nn(this),t),Fn(this.request)}:function(...t){return Fn(e.apply(Nn(this),t))}}function Ln(e){return"function"==typeof e?An(e):(e instanceof IDBTransaction&&function(e){if(Tn.has(e))return;const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("complete",i),e.removeEventListener("error",o),e.removeEventListener("abort",o)},i=()=>{t(),r()},o=()=>{n(e.error||new DOMException("AbortError","AbortError")),r()};e.addEventListener("complete",i),e.addEventListener("error",o),e.addEventListener("abort",o)});Tn.set(e,t)}(e),En(e,xn||(xn=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction]))?new Proxy(e,On):e)}function Fn(e){if(e instanceof IDBRequest)return function(e){const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("success",i),e.removeEventListener("error",o)},i=()=>{t(Fn(e.result)),r()},o=()=>{n(e.error),r()};e.addEventListener("success",i),e.addEventListener("error",o)});return Rn.set(t,e),t}(e);if(Mn.has(e))return Mn.get(e);const t=Ln(e);return t!==e&&(Mn.set(e,t),Rn.set(t,e)),t}const Nn=e=>Rn.get(e);function Dn(e,t,{blocked:n,upgrade:r,blocking:i,terminated:o}={}){const s=indexedDB.open(e,t),a=Fn(s);return r&&s.addEventListener("upgradeneeded",e=>{r(Fn(s.result),e.oldVersion,e.newVersion,Fn(s.transaction),e)}),n&&s.addEventListener("blocked",e=>n(e.oldVersion,e.newVersion,e)),a.then(e=>{o&&e.addEventListener("close",()=>o()),i&&e.addEventListener("versionchange",e=>i(e.oldVersion,e.newVersion,e))}).catch(()=>{}),a}const qn=["get","getKey","getAll","getAllKeys","count"],Un=["put","add","delete","clear"],jn=new Map;function Bn(e,t){if(!(e instanceof IDBDatabase)||t in e||"string"!=typeof t)return;if(jn.get(t))return jn.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,i=Un.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!i&&!qn.includes(n))return;const o=async function(e,...t){const o=this.transaction(e,i?"readwrite":"readonly");let s=o.store;return r&&(s=s.index(t.shift())),(await Promise.all([s[n](...t),i&&o.done]))[0]};return jn.set(t,o),o}_n(e=>({...e,get:(t,n,r)=>Bn(t,n)||e.get(t,n,r),has:(t,n)=>!!Bn(t,n)||e.has(t,n)}));const Wn=["continue","continuePrimaryKey","advance"],zn={},Kn=new WeakMap,Hn=new WeakMap,$n={get(e,t){if(!Wn.includes(t))return e[t];let n=zn[t];return n||(n=zn[t]=function(...e){Kn.set(this,Hn.get(this)[t](...e))}),n}};async function*Gn(...e){let t=this;if(t instanceof IDBCursor||(t=await t.openCursor(...e)),!t)return;const n=new Proxy(t,$n);for(Hn.set(n,t),Rn.set(n,Nn(t));t;)yield n,t=await(Kn.get(n)||t.continue()),Kn.delete(n)}function Jn(e,t){return t===Symbol.asyncIterator&&En(e,[IDBIndex,IDBObjectStore,IDBCursor])||"iterate"===t&&En(e,[IDBIndex,IDBObjectStore])}_n(e=>({...e,get:(t,n,r)=>Jn(t,n)?Gn:e.get(t,n,r),has:(t,n)=>Jn(t,n)||e.has(t,n)}));var Qn=function(){function e(e){var t,n,r,i=this;this.minInterval=Se,this.maxInterval=we,this.maxPersistedEventsSize=6e6,this._timeAtLastSplit=Date.now(),this.eventsContentBytes=new WeakMap,this.sequenceContentBytes=new Map,this.shouldSplitEventsList=function(e,t){var n=i.getEventsArraySize(e),r=i.maxPersistedEventsSize-n,o=t.length>=r;return!o&&3*t.length>=r&&(o=un(t)>=r),!!o||!!(Date.now()-i.timeAtLastSplit>i.interval&&e.length)&&(i.interval=Math.min(i.maxInterval,i.interval+i.minInterval),i._timeAtLastSplit=Date.now(),!0)},this.loggerProvider=e.loggerProvider,this.minInterval=null!==(t=e.minInterval)&&void 0!==t?t:this.minInterval,this.maxInterval=null!==(n=e.maxInterval)&&void 0!==n?n:this.maxInterval,this.maxPersistedEventsSize=null!==(r=e.maxPersistedEventsSize)&&void 0!==r?r:this.maxPersistedEventsSize,this.interval=this.minInterval}return Object.defineProperty(e.prototype,"timeAtLastSplit",{get:function(){return this._timeAtLastSplit},enumerable:!1,configurable:!0}),e.prototype.isPrefixOf=function(e,t){return!(t.length<e.length)&&(0===e.length||t[e.length-1]===e.tail)},e.prototype.measureContentBytes=function(e,t){if(e&&e.length===t.length&&this.isPrefixOf(e,t))return e;var n=0,r=0;e&&this.isPrefixOf(e,t)&&(n=e.contentBytes,r=e.length);for(var i=r;i<t.length;i++)n+=un(t[i]);return{length:t.length,contentBytes:n,tail:t.length>0?t[t.length-1]:void 0}},e.prototype.getEventsContentBytes=function(e){var t=this.measureContentBytes(this.eventsContentBytes.get(e),e);return this.eventsContentBytes.set(e,t),t.contentBytes},e.prototype.getEventsArraySize=function(e){return this.getEventsContentBytes(e)+(2+Math.max(0,e.length-1)+2*e.length)},e.prototype.recallSequenceContentBytes=function(e,t){var n=this.sequenceContentBytes.get(e);n&&n.length===t.length&&this.isPrefixOf(n,t)&&this.eventsContentBytes.set(t,n)},e.prototype.rememberSequenceContentBytes=function(e,t){var n=this.measureContentBytes(this.sequenceContentBytes.get(e),t);this.sequenceContentBytes.set(e,n),this.eventsContentBytes.set(t,n)},e.prototype.forgetSequenceContentBytes=function(e){this.sequenceContentBytes.delete(e)},e}(),Vn=function(e,t,n){var r;"object"==typeof(r=n)&&null!==r&&"AbortError"===r.name?e.debug(t):e.warn(t)};var Zn="sessionCurrentSequence",Xn="sequencesToSend",Yn=5e3;function er(e,t,n){var r=setTimeout(n,t);return e.then(function(){return clearTimeout(r)},function(){return clearTimeout(r)}),function(){return clearTimeout(r)}}var tr=function(e){var t,n;return e.objectStoreNames.contains(Zn)||(n=e.createObjectStore(Zn,{keyPath:"sessionId"})),e.objectStoreNames.contains(Xn)||(t=e.createObjectStore(Xn,{keyPath:"sequenceId",autoIncrement:!0})).createIndex("sessionId","sessionId"),{sequencesStore:t,currentSequenceStore:n}},nr=function(e){return a(void 0,void 0,void 0,function(){return l(this,function(t){switch(t.label){case 0:return[4,(n=Dn(e,1,{upgrade:tr}),r=2e3,i="IDB openDB timed out",void 0===i&&(i="IDB operation timed out"),new Promise(function(e,t){var o=setTimeout(function(){return t(new Error("".concat(i," after ").concat(r,"ms")))},r);n.then(function(t){clearTimeout(o),e(t)},function(e){clearTimeout(o),t(e)})}))];case 1:return[2,t.sent()]}var n,r,i})})},rr=function(e){function t(t){var n,r=this;return(r=e.call(this,t)||this).consecutiveFailures=0,r.hasTriggeredFallback=!1,r.emptyFilteredCount=0,r.getSequencesToSend=function(){return a(r,void 0,void 0,function(){var e,t,n,r,i,o,s,a,c,u,d=this;return l(this,function(l){switch(l.label){case 0:e=!1,t=!1,l.label=1;case 1:return l.trys.push([1,9,,10]),n=[],(r=this.db.transaction("sequencesToSend","readwrite")).done.catch(function(n){e||t||(Vn(d.loggerProvider,"".concat(Sn,": ").concat(n),n),d.recordFailure())}),i=er(r.done,Yn,function(){e||t||(t=!0,Vn(d.loggerProvider,"".concat(Sn,": transaction timed out")),d.recordFailure())}),[4,r.store.openCursor()];case 2:o=l.sent(),l.label=3;case 3:return o?(s=o.value,a=s.sessionId,0!==(c=s.events).length?[3,5]:(this.maybeLogEmptyFiltered("getSequencesToSend"),[4,o.delete()])):[3,8];case 4:return l.sent(),[3,6];case 5:n.push({events:c,sequenceId:o.key,sessionId:a}),l.label=6;case 6:return[4,o.continue()];case 7:return o=l.sent(),[3,3];case 8:return this.recordSuccess(),i(),[2,n];case 9:return u=l.sent(),t||(e=!0,Vn(this.loggerProvider,"".concat(Sn,": ").concat(u),u),this.recordFailure()),[3,10];case 10:return[2,void 0]}})})},r.storeCurrentSequence=function(e){return a(r,void 0,void 0,function(){var t,n,r,i,a,c,u,d,v=this;return l(this,function(l){switch(l.label){case 0:t=!1,n=!1,l.label=1;case 1:return l.trys.push([1,5,,6]),(r=this.db.transaction([Zn,Xn],"readwrite")).done.catch(function(e){t||n||(Vn(v.loggerProvider,"".concat(Sn,": ").concat(e),e),v.recordFailure())}),i=er(r.done,Yn,function(){t||n||(n=!0,Vn(v.loggerProvider,"".concat(Sn,": transaction timed out")),v.recordFailure())}),[4,r.objectStore(Zn).get(e)];case 2:return!(a=l.sent())||a.tabId&&a.tabId!==this.tabId?(i(),[2,void 0]):0===a.events.length?(this.maybeLogEmptyFiltered("storeCurrentSequence"),i(),[2,void 0]):[4,r.objectStore(Xn).put({sessionId:e,events:a.events,tabId:this.tabId})];case 3:return c=l.sent(),[4,r.objectStore(Zn).put({sessionId:e,events:[],tabId:this.tabId})];case 4:return l.sent(),this.rememberSequenceContentBytes(e,[]),this.recordSuccess(),i(),a.tabId,u=s(a,["tabId"]),[2,o(o({},u),{sessionId:e,sequenceId:c})];case 5:return d=l.sent(),this.forgetSequenceContentBytes(e),n||(t=!0,Vn(this.loggerProvider,"".concat(Sn,": ").concat(d),d),this.recordFailure()),[3,6];case 6:return[2,void 0]}})})},r.addEventToCurrentSequence=function(e,t){return a(r,void 0,void 0,function(){var n,r,i,o,s,a,c,u,d,v,h,f,g,p,m=this;return l(this,function(l){switch(l.label){case 0:n=!1,r=!1,l.label=1;case 1:return l.trys.push([1,15,,16]),(i=this.db.transaction([Zn,Xn],"readwrite")).done.catch(function(e){n||r||(Vn(m.loggerProvider,"".concat(Sn,": ").concat(e),e),m.recordFailure())}),o=er(i.done,Yn,function(){n||r||(r=!0,Vn(m.loggerProvider,"".concat(Sn,": transaction timed out")),m.recordFailure())}),[4,i.objectStore(Zn).get(e)];case 2:return(null==(s=l.sent())?void 0:s.tabId)&&s.tabId!==this.tabId?s.events.length>0?[4,i.objectStore(Xn).put({sessionId:e,events:s.events,tabId:s.tabId})]:[3,4]:[3,6];case 3:l.sent(),l.label=4;case 4:return a=[t],[4,i.objectStore(Zn).put({sessionId:e,events:a,tabId:this.tabId})];case 5:return l.sent(),this.rememberSequenceContentBytes(e,a),this.recordSuccess(),o(),[2,void 0];case 6:return(c=s)?[3,8]:(u=[t],[4,i.objectStore(Zn).put({sessionId:e,events:u,tabId:this.tabId})]);case 7:return l.sent(),this.rememberSequenceContentBytes(e,u),this.recordSuccess(),o(),[2,void 0];case 8:return this.recallSequenceContentBytes(e,c.events),this.shouldSplitEventsList(c.events,t)?[3,10]:(d=c.events.concat(t),[4,i.objectStore(Zn).put({sessionId:e,events:d,tabId:this.tabId})]);case 9:return l.sent(),this.rememberSequenceContentBytes(e,d),this.recordSuccess(),o(),[2,void 0];case 10:return 0!==(v=c.events).length?[3,12]:(this.maybeLogEmptyFiltered("addEventToCurrentSequence"),h=[t],[4,i.objectStore(Zn).put({sessionId:e,events:h,tabId:this.tabId})]);case 11:return l.sent(),this.rememberSequenceContentBytes(e,h),this.recordSuccess(),o(),[2,void 0];case 12:return f=[t],[4,i.objectStore(Zn).put({sessionId:e,events:f,tabId:this.tabId})];case 13:return l.sent(),this.rememberSequenceContentBytes(e,f),[4,i.objectStore(Xn).put({sessionId:e,events:v,tabId:this.tabId})];case 14:return g=l.sent(),this.recordSuccess(),o(),[2,{events:v,sessionId:e,sequenceId:g}];case 15:return p=l.sent(),this.forgetSequenceContentBytes(e),r||(n=!0,Vn(this.loggerProvider,"".concat(Sn,": ").concat(p),p),this.recordFailure()),[3,16];case 16:return[2,void 0]}})})},r.storeSendingEvents=function(e,t){return a(r,void 0,void 0,function(){var n,r;return l(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.db.put(Xn,{sessionId:e,events:t,tabId:this.tabId})];case 1:return n=i.sent(),this.recordSuccess(),[2,n];case 2:return r=i.sent(),Vn(this.loggerProvider,"".concat(Sn,": ").concat(r),r),this.recordFailure(),[3,3];case 3:return[2,void 0]}})})},r.cleanUpSessionEventsStore=function(e,t){return a(r,void 0,void 0,function(){var e;return l(this,function(n){switch(n.label){case 0:if(!t)return[2];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this.db.delete(Xn,t)];case 2:return n.sent(),this.recordSuccess(),[3,4];case 3:return e=n.sent(),Vn(this.loggerProvider,"".concat(Sn,": ").concat(e),e),this.recordFailure(),[3,4];case 4:return[2]}})})},r.db=t.db,r.tabId=t.tabId,r.onPersistentFailure=t.onPersistentFailure,r.consecutiveFailureThreshold=null!==(n=t.consecutiveFailureThreshold)&&void 0!==n?n:1,r}return n(t,e),t.prototype.maybeLogEmptyFiltered=function(e){this.emptyFilteredCount++%100==0&&this.loggerProvider.debug("Filtered empty session replay sequence at ".concat(e," (idb store)"))},t.prototype.recordFailure=function(){var e;this.consecutiveFailures++,!this.hasTriggeredFallback&&this.consecutiveFailures>=this.consecutiveFailureThreshold&&(this.hasTriggeredFallback=!0,null===(e=this.onPersistentFailure)||void 0===e||e.call(this))},t.prototype.recordSuccess=function(){this.consecutiveFailures=0},t.new=function(e,n){var r;return a(this,void 0,void 0,function(){var i,s,a,c,u;return l(this,function(l){switch(l.label){case 0:return l.trys.push([0,2,,3]),i="replay"===e?"":"_".concat(e),s="".concat(n.apiKey.substring(0,10),"_amp_session_replay_events").concat(i),[4,nr(s)];case 1:return a=l.sent(),c=null!==(r=n.tabId)&&void 0!==r?r:function(){try{return crypto.randomUUID()}catch(e){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}}(),[2,new t(o(o({},n),{db:a,tabId:c}))];case 2:return u=l.sent(),Vn(n.loggerProvider,"".concat(Sn,": ").concat(u),u),[3,3];case 3:return[2]}})})},t.prototype.getCurrentSequenceEvents=function(e){return a(this,void 0,void 0,function(){var t,n,r,i,o,a,u,d;return l(this,function(l){switch(l.label){case 0:return e?[4,this.db.get("sessionCurrentSequence",e)]:[3,2];case 1:return(i=l.sent())?i.tabId&&i.tabId!==this.tabId?[2,void 0]:(i.tabId,[2,[o=s(i,["tabId"])]]):[2,void 0];case 2:t=[],l.label=3;case 3:return l.trys.push([3,8,9,10]),[4,this.db.getAll("sessionCurrentSequence")];case 4:n=c.apply(void 0,[l.sent()]),r=n.next(),l.label=5;case 5:if(r.done)return[3,7];if((i=r.value).tabId&&i.tabId!==this.tabId)return[3,6];i.tabId,o=s(i,["tabId"]),t.push(o),l.label=6;case 6:return r=n.next(),[3,5];case 7:return[3,10];case 8:return a=l.sent(),u={error:a},[3,10];case 9:try{r&&!r.done&&(d=n.return)&&d.call(n)}finally{if(u)throw u.error}return[7];case 10:return[2,t]}})})},t}(Qn),ir=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.finalizedSequences={},t.sequences={},t.sequenceId=0,t.emptyFilteredCount=0,t}return n(t,e),t.prototype.resetCurrentSequence=function(e){this.sequences[e]=[]},t.prototype.addSequence=function(e){var t=this.sequenceId++,n=d([],u(this.sequences[e]),!1);return this.finalizedSequences[t]={sessionId:e,events:n},this.resetCurrentSequence(e),{sequenceId:t,events:n,sessionId:e}},t.prototype.maybeLogEmptyFiltered=function(e){this.emptyFilteredCount++%100==0&&this.loggerProvider.debug("Filtered empty session replay sequence at ".concat(e," (in-memory store)"))},t.prototype.getSequencesToSend=function(){return a(this,void 0,void 0,function(){var e,t,n,r,i,o,s,a,d,v;return l(this,function(l){e=[];try{for(t=c(Object.entries(this.finalizedSequences)),n=t.next();!n.done;n=t.next())r=u(n.value,2),i=r[0],o=r[1],s=o.sessionId,0!==(a=o.events).length?e.push({sequenceId:Number(i),sessionId:s,events:a}):(this.maybeLogEmptyFiltered("getSequencesToSend"),delete this.finalizedSequences[Number(i)])}catch(e){d={error:e}}finally{try{n&&!n.done&&(v=t.return)&&v.call(t)}finally{if(d)throw d.error}}return[2,e]})})},t.prototype.storeCurrentSequence=function(e){return a(this,void 0,void 0,function(){var t;return l(this,function(n){return(t=this.sequences[e])?0===t.length?(this.maybeLogEmptyFiltered("storeCurrentSequence"),[2,void 0]):[2,this.addSequence(e)]:[2,void 0]})})},t.prototype.addEventToCurrentSequence=function(e,t){return a(this,void 0,void 0,function(){var n;return l(this,function(r){return this.sequences[e]||this.resetCurrentSequence(e),this.shouldSplitEventsList(this.sequences[e],t)&&(0===this.sequences[e].length?this.maybeLogEmptyFiltered("addEventToCurrentSequence"):n=this.addSequence(e)),this.sequences[e].push(t),[2,n]})})},t.prototype.storeSendingEvents=function(e,t){return a(this,void 0,void 0,function(){return l(this,function(n){return this.finalizedSequences[this.sequenceId]={sessionId:e,events:t},[2,this.sequenceId++]})})},t.prototype.cleanUpSessionEventsStore=function(e,t){return a(this,void 0,void 0,function(){return l(this,function(e){return void 0!==t&&delete this.finalizedSequences[t],[2]})})},t}(Qn),or=function(e){var t=e.config,n=e.minInterval,r=e.maxInterval,i=e.maxPersistedEventsSize,s=e.type,c=e.payloadBatcher,v=e.storeType,h=e.trackDestinationWorkerScript,f=e.shouldSend;return a(void 0,void 0,void 0,function(){function e(e){return void 0===e&&(e=!1),a(this,void 0,void 0,function(){return l(this,function(t){return[2,p.flush(e)]})})}var g,p,m,y,b,S,w,I,C,k,E,x,P,T,M,R,O;return l(this,function(_){switch(_.label){case 0:return g=null!==(O=t.maxSingleEventSizeBytes)&&void 0!==O?O:ye,p=new kn(o(o({},t),{loggerProvider:t.loggerProvider,payloadBatcher:c,workerScript:h})),m=function(){return new ir({loggerProvider:t.loggerProvider,maxInterval:r,minInterval:n,maxPersistedEventsSize:i})},b=!1,w=function(){return a(void 0,void 0,void 0,function(){var e,n,r;return l(this,function(i){switch(i.label){case 0:return b?(b=!1,t.loggerProvider.warn("IDB store is experiencing repeated failures; falling back to in-memory event store."),y?[4,S.getSequencesToSend()]:[3,2]):[2];case 1:return n=i.sent(),[3,3];case 2:n=void 0,i.label=3;case 3:return e=n,S=m(),e&&y&&(r=y,e.forEach(function(e){P({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:r})})),[2]}})})},I=function(){return a(void 0,void 0,void 0,function(){var e;return l(this,function(o){switch(o.label){case 0:return[4,rr.new(s,{loggerProvider:t.loggerProvider,minInterval:n,maxInterval:r,maxPersistedEventsSize:i,apiKey:t.apiKey,onPersistentFailure:function(){w()}})];case 1:return(e=o.sent())?(b=!0,[2,e]):(t.loggerProvider.log("Failed to initialize idb store, falling back to memory store."),[2,m()])}})})},"idb"!==v?[3,2]:[4,I()];case 1:return C=_.sent(),[3,3];case 2:C=m(),_.label=3;case 3:return S=C,k=[],E=0,x=function(e){if(!(e<=E)){var t=Math.min(e-E,k.length);t>0&&(k.splice(0,t),E=e)}},P=function(e){for(var n=e.events,r=e.sessionId,i=e.deviceId,o=e.sequenceId,c=n,u=[],d=0;d<n.length;d++){var v=vn(n[d],g);void 0!==v?(0===u.length&&(c=n.slice(0,d)),u.push(v)):c!==n&&c.push(n[d])}u.length>0&&t.loggerProvider.warn("Dropping ".concat(u.length," oversized event(s) from session replay sequence before send. Sizes: ").concat(u.map(function(e){return"".concat(Math.round(e/1024)," KB")}).join(", "),". If this recurs, please open a GitHub issue at https://github.com/amplitude/Amplitude-TypeScript/issues or contact Amplitude support.")),0!==c.length?(t.debugMode&&je().then(function(e){var n=e.totalStorageSize,r=e.percentOfQuota,i=e.usageDetails;t.loggerProvider.debug("Total storage size: ".concat(n," KB, percentage of quota: ").concat(r,"%, usage details: ").concat(i))}).catch(function(){}),p.sendEventsList({events:c,sessionId:r,flushMaxRetries:t.flushMaxRetries,apiKey:t.apiKey,deviceId:i,sampleRate:t.sampleRate,serverZone:t.serverZone,version:t.version,type:s,onComplete:function(){return a(void 0,void 0,void 0,function(){return l(this,function(e){switch(e.label){case 0:return[4,S.cleanUpSessionEventsStore(r,o)];case 1:return e.sent(),[2]}})})}})):S.cleanUpSessionEventsStore(r,o).catch(function(e){t.loggerProvider.warn("Failed to clean up session replay events store:",e)})},T=function(e){var n=e.sessionId,r=e.deviceId;if(y=r,!f||f()){var i=E+k.length;S.storeCurrentSequence(n).then(function(e){e&&(x(i),P({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:r}))}).catch(function(e){t.loggerProvider.warn("Failed to get current sequence of session replay events for session:",e)})}},M=function(e){var n=e.deviceId;return a(void 0,void 0,void 0,function(){var e;return l(this,function(r){switch(r.label){case 0:return y=n,[4,S.getSequencesToSend()];case 1:return(null==(e=r.sent())?void 0:e.length)?(t.loggerProvider.log("Draining ".concat(e.length," stored sequence(s) from previous session.")),e.length>1&&p.markCoalesceNextFlush(),e.forEach(function(e){P({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:n})}),[2]):[2]}})})},R=function(e){var n=e.event,r=e.sessionId,i=e.deviceId;y=i;var o=!f||f(),s=E+k.length;k.push(n.data),S.addEventToCurrentSequence(r,n.data).then(function(e){if(e){if(!o)return S.cleanUpSessionEventsStore(e.sessionId,e.sequenceId).catch(function(e){t.loggerProvider.warn("Failed to clean up dropped session replay sequence:",e)}),void x(s);x(s),P({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:i})}}).catch(function(e){t.loggerProvider.warn("Failed to add event to session replay capture:",e)})},[2,{sendCurrentSequenceEvents:T,addEvent:R,sendStoredEvents:M,flush:e,getBeaconEvents:function(){return d([],u(k),!1)},dropPendingBeaconEvents:function(){x(E+k.length)},trackDestination:p}]}})})},sr=function(){function e(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=new Map;e.forEach(function(e){n.set(e.name,e.manager)}),this.managers=n}return e.prototype.sendStoredEvents=function(e){return a(this,void 0,void 0,function(){var t;return l(this,function(n){switch(n.label){case 0:return t=[],this.managers.forEach(function(n){t.push(n.sendStoredEvents(e))}),[4,Promise.all(t)];case 1:return n.sent(),[2]}})})},e.prototype.addEvent=function(e){var t,n=e.sessionId,r=e.event,i=e.deviceId;null===(t=this.managers.get(r.type))||void 0===t||t.addEvent({sessionId:n,event:r,deviceId:i})},e.prototype.sendCurrentSequenceEvents=function(e){var t=e.sessionId,n=e.deviceId;this.managers.forEach(function(e){e.sendCurrentSequenceEvents({sessionId:t,deviceId:n})})},e.prototype.flush=function(e){return a(this,void 0,void 0,function(){var t;return l(this,function(n){switch(n.label){case 0:return t=[],this.managers.forEach(function(n){t.push(n.flush(e))}),[4,Promise.all(t)];case 1:return n.sent(),[2]}})})},e}(),ar=function(e){var t=e.version,n=e.events,r=[];return n.forEach(function(e){var t=JSON.parse(e);t.count=1,"click"===t.type&&r.push(t)}),{version:t,events:r}},lr=function(e){var t=e.version,n=e.events,r=[];n.forEach(function(e){var t=JSON.parse(e);"click"===t.type&&r.push(t)});var i=r.reduce(function(e,t){var n=t.x,r=t.y,i=t.selector,s=t.timestamp,a=s-s%36e5,l="".concat(n,":").concat(r,":").concat(null!=i?i:"",":").concat(a);return e[l]?e[l].count+=1:e[l]=o(o({},t),{timestamp:a,count:1}),e},{});return{version:t,events:Object.values(i)}},cr=function(){function e(e,t){var n=this;this.createHook=function(e){var t=e.eventsManager,r=e.sessionId,i=e.deviceIdFn,o=e.mirror,s=e.ugcFilterRules,a=e.performanceOptions;return function(e){var l,c,u,d,v;if(e.type===Bt.Click){var h=g();if(h){var f=h.location,p=h.innerHeight,m=h.innerWidth;if(f){var y=e.x,b=e.y;if(void 0!==y&&void 0!==b){var S,w=o.getNode(e.id);if(w)try{S=null!==(l=n.getSelector(w,a))&&void 0!==l?l:void 0}catch(e){n.logger.debug("error resolving selector from finder")}var I=Ue(f.href,s),C={x:y+(null!==(u=null===(c=n.scrollWatcher)||void 0===c?void 0:c.currentScrollX)&&void 0!==u?u:0),y:b+(null!==(v=null===(d=n.scrollWatcher)||void 0===d?void 0:d.currentScrollY)&&void 0!==v?v:0),selector:S,viewportHeight:p,viewportWidth:m,pageUrl:I,timestamp:Date.now(),type:"click"},k=i();k&&t.addEvent({sessionId:r,event:{type:"interaction",data:JSON.stringify(C)},deviceId:k})}}}}}},this.logger=e,this.scrollWatcher=t}return e.prototype.getSelector=function(e,t){var n,r,i;if(null===(n=this.clickSelectors)||void 0===n?void 0:n.has(e))return null!==(r=this.clickSelectors.get(e))&&void 0!==r?r:null;var o=$t(e,t);return null===(i=this.clickSelectors)||void 0===i||i.set(e,o),o},e.prototype.createSharedHook=function(e,t){var n=this;return function(r,i){if(r.type===Bt.Click){var o=n.clickSelectors;n.clickSelectors=new Map;try{try{null==e||e(r)}catch(e){n.logger.debug("Heatmap click hook failed",e)}if("click"===(null==i?void 0:i.type))try{null==t||t(i)}catch(e){n.logger.debug("Semantic click hook failed",e)}}finally{n.clickSelectors=o}}}},e}();function ur(){var e=g();return(null==e?void 0:e.innerHeight)||document.documentElement&&document.documentElement.clientHeight||0}function dr(){var e=g();return(null==e?void 0:e.innerWidth)||document.documentElement&&document.documentElement.clientWidth||0}var vr=function(){function e(e,t){var n=g();n&&n.navigator&&"function"==typeof n.navigator.sendBeacon?this.sendBeacon=function(e,t){try{if(n.navigator.sendBeacon(e,JSON.stringify(t)))return!0}catch(e){}return!1}:this.sendBeacon=function(){return!1},this.sendXhr=function(e,t){var n=new XMLHttpRequest;return n.open("POST",e,!0),n.setRequestHeader("Accept","*/*"),n.send(JSON.stringify(t)),!0},this.basePageUrl=De(t.serverZone,t.trackServerUrl),this.apiKey=t.apiKey,this.context=e,this.handleSendEvents=t.handleSendEvents,this.loggerProvider=t.loggerProvider}return e.prototype.send=function(e,t){var n,r=this,i=this.context,o=i.sessionId,s=i.type;if(this.handleSendEvents){var a=new URLSearchParams({device_id:e,session_id:String(o),type:String(s)}),l="".concat(this.basePageUrl,"?").concat(a.toString()),c={"Content-Type":"application/json",Accept:"*/*",Authorization:"Bearer ".concat(this.apiKey)};try{this.handleSendEvents({url:l,method:"POST",headers:c,body:JSON.stringify(t),keepalive:!0}).catch(function(e){var t;null===(t=r.loggerProvider)||void 0===t||t.warn("Custom transport failed to send session replay interaction beacon:",e)})}catch(e){null===(n=this.loggerProvider)||void 0===n||n.warn("Custom transport threw while sending session replay interaction beacon:",e)}}else{var u=new URLSearchParams({device_id:e,session_id:String(o),type:String(s),api_key:this.apiKey}),d="".concat(this.basePageUrl,"?").concat(u.toString());this.sendBeacon(d,t)||this.sendXhr(d,t)}},e}(),hr=function(){function e(e,t){var n=this;this.timestamp=Date.now(),this.hook=function(e){n.update(e)},this.send=function(e){return function(t){var r,i,o,s,a=e(),l=g();if(l&&a){var c=null!==(r=l.scrollX)&&void 0!==r?r:0,u=null!==(i=l.scrollY)&&void 0!==i?i:0;(c>0||u>0)&&n.update({id:1,x:c,y:u}),n.transport.send(a,{version:1,events:[{maxScrollX:n._maxScrollX,maxScrollY:n._maxScrollY,maxScrollWidth:n._maxScrollWidth,maxScrollHeight:n._maxScrollHeight,viewportHeight:ur(),viewportWidth:dr(),pageUrl:Ue(l.location.href,null!==(s=null===(o=n.config.interactionConfig)||void 0===o?void 0:o.ugcFilterRules)&&void 0!==s?s:[]),timestamp:n.timestamp,type:"scroll"}]})}}},this._maxScrollX=0,this._maxScrollY=0,this._currentScrollX=0,this._currentScrollY=0,this._maxScrollWidth=dr(),this._maxScrollHeight=ur(),this.config=t,this.transport=e}return e.default=function(t,n){return new e(new vr(t,n),n)},Object.defineProperty(e.prototype,"maxScrollX",{get:function(){return this._maxScrollX},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"maxScrollY",{get:function(){return this._maxScrollY},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"maxScrollWidth",{get:function(){return this._maxScrollWidth},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"maxScrollHeight",{get:function(){return this._maxScrollHeight},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"currentScrollX",{get:function(){return this._currentScrollX},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"currentScrollY",{get:function(){return this._currentScrollY},enumerable:!1,configurable:!0}),e.prototype.update=function(e){var t=Date.now();if(this._currentScrollX=e.x,this._currentScrollY=e.y,e.x>this._maxScrollX){var n=dr();this._maxScrollX=e.x;var r=e.x+n;r>this._maxScrollWidth&&(this._maxScrollWidth=r),this.timestamp=t}if(e.y>this._maxScrollY){var i=ur();this._maxScrollY=e.y;var o=e.y+i;o>this._maxScrollHeight&&(this._maxScrollHeight=o),this.timestamp=t}},e}(),fr=function(e){var t=e.sessionId,n=e.deviceId;this.deviceId=n,this.sessionId=t,t&&n&&(this.sessionReplayId=function(e,t){return"".concat(t,"/").concat(e)}(t,n))},gr=864e5,pr=function(e){return"".concat("AMP_SR_START_").concat(e.substring(0,10),"_")},mr=function(e,t){return"".concat(pr(e)).concat(t)},yr=function(){try{var e=g();return null==e?void 0:e.localStorage}catch(e){return}},br=function(){var e=this;this.dbs={},this.createStore=function(t){return a(e,void 0,void 0,function(){return l(this,function(e){switch(e.label){case 0:return[4,Dn(t,1,{upgrade:function(e){e.objectStoreNames.contains("sessionTargetingMatch")||e.createObjectStore("sessionTargetingMatch",{keyPath:"sessionId"})}})];case 1:return[2,e.sent()]}})})},this.openOrCreateDB=function(t){return a(e,void 0,void 0,function(){var e,n;return l(this,function(r){switch(r.label){case 0:return this.dbs&&this.dbs[t]?[2,this.dbs[t]]:(e="".concat(t.substring(0,10),"_amp_session_replay_targeting"),[4,this.createStore(e)]);case 1:return n=r.sent(),this.dbs[t]=n,[2,n]}})})},this.getTargetingMatchForSession=function(t){var n=t.loggerProvider,r=t.apiKey,i=t.sessionId;return a(e,void 0,void 0,function(){var e,t,o,s;return l(this,function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),[4,this.openOrCreateDB(r)];case 1:return e=a.sent(),t=String(i),[4,e.get("sessionTargetingMatch",t)];case 2:return[2,null==(o=a.sent())?void 0:o.targetingMatch];case 3:return s=a.sent(),Vn(n,"Failed to get targeting match for session id ".concat(i,": ").concat(s),s),[3,4];case 4:return[2,void 0]}})})},this.storeTargetingMatchForSession=function(t){var n=t.loggerProvider,r=t.apiKey,i=t.sessionId,o=t.targetingMatch;return a(e,void 0,void 0,function(){var e,t,s;return l(this,function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),[4,this.openOrCreateDB(r)];case 1:return e=a.sent(),t=String(i),[4,e.put("sessionTargetingMatch",{targetingMatch:o,sessionId:t,lastUpdated:Date.now()})];case 2:return[2,a.sent()];case 3:return s=a.sent(),Vn(n,"Failed to store targeting match for session id ".concat(i,": ").concat(s),s),[3,4];case 4:return[2,void 0]}})})},this.clearStoreOfOldSessions=function(t){var n=t.loggerProvider,r=t.apiKey,i=t.currentSessionId;return a(e,void 0,void 0,function(){var e,t,o,s,a,c,u,d;return l(this,function(l){switch(l.label){case 0:return l.trys.push([0,8,,9]),[4,this.openOrCreateDB(r)];case 1:return e=l.sent(),t=String(i),[4,(o=e.transaction("sessionTargetingMatch","readwrite")).store.getAll()];case 2:s=l.sent(),a=0,l.label=3;case 3:return a<s.length?(c=s[a],u=Date.now()-c.lastUpdated,c.sessionId!==t&&u>1728e5?[4,o.store.delete(c.sessionId)]:[3,5]):[3,6];case 4:l.sent(),l.label=5;case 5:return a++,[3,3];case 6:return[4,o.done];case 7:return l.sent(),[3,9];case 8:return d=l.sent(),Vn(n,"Failed to clear old targeting matches for sessions: ".concat(d),d),[3,9];case 9:return[2]}})})}},Sr=new br,wr=function(e){var t=e.sessionId,n=e.targetingConfig,r=e.loggerProvider,i=e.apiKey,s=e.targetingParams,c=e.urlChange,u=void 0!==c&&c;return a(void 0,void 0,void 0,function(){var e,a,c,d,v,h;return l(this,function(l){switch(l.label){case 0:return[4,Sr.clearStoreOfOldSessions({loggerProvider:r,apiKey:i,currentSessionId:t})];case 1:return l.sent(),[4,Sr.getTargetingMatchForSession({loggerProvider:r,apiKey:i,sessionId:t})];case 2:if(!0===l.sent()&&!u)return[2,!0];e=!0,l.label=3;case 3:return l.trys.push([3,6,,7]),[4,import("./index-min3.js")];case 4:return a=l.sent().evaluateTargeting,c=o(o({},s),{flag:n,sessionId:"string"==typeof t?parseInt(t,10):t,apiKey:i,loggerProvider:r}),[4,a(c)];case 5:return(d=l.sent())&&d.sr_targeting_config&&(e="on"===d.sr_targeting_config.key),Sr.storeTargetingMatchForSession({loggerProvider:r,apiKey:i,sessionId:t,targetingMatch:e}),[3,7];case 6:return v=l.sent(),h=v,r.warn(h.message),[3,7];case 7:return[2,e]}})})},Ir=2654435761,Cr=2246822519,kr=3266489917,Er=374761393;function xr(e,t){return(e<<t|e>>>32-t)>>>0}function Pr(e,t){return e=xr(e=e+Math.imul(t,Cr)>>>0,13),e=Math.imul(e,Ir)>>>0}function Tr(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}function Mr(e,t){void 0===t&&(t=0);var n,r=function(e){for(var t=[],n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r>=55296&&r<=56319&&n+1<e.length){var i=e.charCodeAt(n+1);i>=56320&&i<=57343&&(r=i-56320+(r-55296<<10)+65536,n++)}r<128?t.push(r):r<2048?t.push(192|r>>6,128|63&r):r<65536?t.push(224|r>>12,128|r>>6&63,128|63&r):t.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r)}return new Uint8Array(t)}(e),i=r.length,o=0;if(i>=16){for(var s=t+Ir+Cr>>>0,a=t+Cr>>>0,l=t>>>0,c=t-Ir>>>0;o<=i-16;)s=Pr(s,Tr(r,o)),a=Pr(a,Tr(r,o+=4)),l=Pr(l,Tr(r,o+=4)),c=Pr(c,Tr(r,o+=4)),o+=4;n=xr(s,1)+xr(a,7)+xr(l,12)+xr(c,18)>>>0}else n=t+Er>>>0;for(n=n+i>>>0;o<=i-4;)n=n+Math.imul(Tr(r,o),kr)>>>0,n=Math.imul(xr(n,17),668265263)>>>0,o+=4;for(;o<i;)n=n+Math.imul(r[o],Er)>>>0,n=Math.imul(xr(n,11),Ir)>>>0,o++;return n^=n>>>15,n=Math.imul(n,Cr)>>>0,n^=n>>>13,n=Math.imul(n,kr)>>>0,(n^=n>>>16)>>>0}var Rr="__amplitude_url_tracking_patched__",Or=new WeakMap;function _r(e,t,n){if(void 0===n&&(n={}),!(null==e?void 0:e.location))return function(){};var r=n.enablePolling,i=void 0!==r&&r,o=n.pollingInterval,s=void 0===o?he:o;if(i){var a=function(){var t;return null!==(t=e.location.href)&&void 0!==t?t:""},l=a(),c=e.setInterval(function(){var e,r=a();r!==l&&(l=r,t(r),null===(e=n.onNavigation)||void 0===e||e.call(n,"replace"))},s);return function(){null!=c&&e.clearInterval(c)}}var u=Or.get(e);if(!u){var d=void 0,v=new Set,h=function(t){var n=function(){var t;return null!==(t=e.location.href)&&void 0!==t?t:""}();void 0!==d&&n===d||(d=n,v.forEach(function(e){return e(n,t)}))},f=function(e,t){var n=function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];var i=e.apply(this,n);return h(t),i};return n[Rr]=!0,n},g=e.history;if(null==g?void 0:g.pushState){var p=Reflect.get(g,"pushState");p[Rr]||(g.pushState=f(p,"push"))}if(null==g?void 0:g.replaceState){var m=Reflect.get(g,"replaceState");m[Rr]||(g.replaceState=f(m,"replace"))}u={callbacks:v,notify:h,onPopStateOrHashChange:function(e){return h("hashchange"===(null==e?void 0:e.type)?"hash":"pop")},listenersAttached:!1},Or.set(e,u)}var y=u;y.listenersAttached||(e.addEventListener("popstate",y.onPopStateOrHashChange),e.addEventListener("hashchange",y.onPopStateOrHashChange),y.listenersAttached=!0);var b=function(e,r){var i;t(e),null===(i=n.onNavigation)||void 0===i||i.call(n,r)};return y.callbacks.add(b),function(){y.callbacks.delete(b),0===y.callbacks.size&&y.listenersAttached&&(e.removeEventListener("popstate",y.onPopStateOrHashChange),e.removeEventListener("hashchange",y.onPopStateOrHashChange),y.listenersAttached=!1)}}function Ar(e){return void 0===e&&(e={}),{name:"amplitude/url-tracking@1",observer:function(t,n,r){var i,s,a,l=o(o({},e),r),c=l.ugcFilterRules||[],u=null!==(i=l.enablePolling)&&void 0!==i&&i,d=null!==(s=l.pollingInterval)&&void 0!==s?s:he,v=null!==(a=l.captureDocumentTitle)&&void 0!==a&&a;if(!n)return function(){};var h=void 0,f=function(){return n.location&&n.location.href||""},g=function(){var e=f();if(void 0===h||e!==h){h=e;var r=function(){var e=n.innerHeight,t=n.innerWidth,r=n.document,i=f(),o="";return v&&(o=(null==r?void 0:r.title)||""),{href:c.length>0?Ue(i,c):i,title:o,viewportHeight:e,viewportWidth:t,type:"url-change-event"}}();t(r)}},p=_r(n,function(){return g()},u?{enablePolling:!0,pollingInterval:d}:{});return g(),function(){return p()}},options:e}}Ar();var Lr=function(){function e(){this.pendingLoadListeners=new Map}return e.prototype.start=function(){var e,t=this;null===(e=this.mutationObserver)||void 0===e||e.disconnect(),g()&&(this.sendToAllIframes({type:ke,action:"start"}),this.mutationObserver=new MutationObserver(function(e){var n,r,i,o,s,a;try{for(var l=c(e),u=l.next();!u.done;u=l.next()){var d=u.value;try{for(var v=(i=void 0,c(Array.from(d.addedNodes))),h=v.next();!h.done;h=v.next()){(p=h.value)instanceof HTMLIFrameElement?t.sendToIframeAfterLoad(p):p instanceof Element&&p.querySelectorAll("iframe").forEach(function(e){t.sendToIframeAfterLoad(e)})}}catch(e){i={error:e}}finally{try{h&&!h.done&&(o=v.return)&&o.call(v)}finally{if(i)throw i.error}}try{for(var f=(s=void 0,c(Array.from(d.removedNodes))),g=f.next();!g.done;g=f.next()){var p;if((p=g.value)instanceof HTMLIFrameElement){var m=t.pendingLoadListeners.get(p);m&&(p.removeEventListener("load",m),t.pendingLoadListeners.delete(p))}}}catch(e){s={error:e}}finally{try{g&&!g.done&&(a=f.return)&&a.call(f)}finally{if(s)throw s.error}}}}catch(e){n={error:e}}finally{try{u&&!u.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}}),this.mutationObserver.observe(document.documentElement,{childList:!0,subtree:!0}))},e.prototype.stop=function(){var e;null===(e=this.mutationObserver)||void 0===e||e.disconnect(),this.mutationObserver=void 0,this.pendingLoadListeners.forEach(function(e,t){t.removeEventListener("load",e)}),this.pendingLoadListeners.clear(),this.sendToAllIframes({type:ke,action:"stop"})},e.prototype.sendToIframeAfterLoad=function(e){var t=this,n=function(){t.pendingLoadListeners.delete(e),t.sendToIframe(e,{type:ke,action:"start"})};this.pendingLoadListeners.set(e,n),e.addEventListener("load",n,{once:!0})},e.prototype.sendToAllIframes=function(e){var t=this;document.querySelectorAll("iframe").forEach(function(n){return t.sendToIframe(n,e)})},e.prototype.sendToIframe=function(e,t){var n;try{null===(n=e.contentWindow)||void 0===n||n.postMessage(t,"*")}catch(e){}},e}();var Fr,Nr,Dr,qr=function(){function e(){var e=this;this.name="@amplitude/session-replay-browser",this.recordCancelCallback=null,this.eventCount=0,this.sessionTargetingMatch=!1,this.pageLeaveFns=[],this.suppressedSendCount=0,this.hasEmittedGateDecision=!1,this.recordFunction=null,this.recordEventsInFlight=!1,this.recordingEnabled=!0,this.recordingGeneration=0,this.startChildRecordingOnSetup=!1,this.pendingEmitEvents=[],this.currentPageUrl="",this.recordEventsPendingShouldLogMetadata=null,this.urlChangeCleanup=null,this.crossOriginIframeCoordinator=null,this.crossOriginParentSignalCleanup=null,this.latestUrlChangeTargetingEvaluationId=0,this.teardownEventListeners=function(t){var n=g();n&&(n.removeEventListener("blur",e.blurListener),n.removeEventListener("focus",e.focusListener),!t&&n.addEventListener("blur",e.blurListener),!t&&n.addEventListener("focus",e.focusListener),n.self&&"onpagehide"in n.self?(n.removeEventListener("pagehide",e.pageLeaveListener),!t&&n.addEventListener("pagehide",e.pageLeaveListener)):(n.removeEventListener("beforeunload",e.pageLeaveListener),!t&&n.addEventListener("beforeunload",e.pageLeaveListener)))},this.blurListener=function(){e.sendEvents()},this.focusListener=function(){var t;if(e.recordingEnabled)if(e.recordCancelCallback&&e.recordFunction){if(!1===(null===(t=e.config)||void 0===t?void 0:t.captureFullSnapshotOnFocus))return;try{e.recordFunction.takeFullSnapshot(!0)}catch(t){e.loggerProvider.warn("Failed to take full snapshot on focus:",t)}}else e.recordEventsInFlight||e.recordEvents(!1)},this.pageLeaveListener=function(t){var n;null===(n=e.eventCompressor)||void 0===n||n.flushQueue(),e.sendEvents(),e.pageLeaveFns.forEach(function(e){e(t)})},this.evaluateTargetingAndCapture=function(t,n,r,o){return void 0===n&&(n=!1),void 0===r&&(r=!1),void 0===o&&(o=!1),a(e,void 0,void 0,function(){var e,s,a,c,u,d,v,h,f,p,m,y;return l(this,function(l){switch(l.label){case 0:if(!this.identifiers||!this.identifiers.sessionId||!this.config)return this.identifiers&&!this.identifiers.sessionId?this.loggerProvider.log("Session ID has not been set yet, cannot evaluate targeting for Session Replay."):this.loggerProvider.warn("Session replay init has not been called, cannot evaluate targeting."),[2];if(!this.config.targetingConfig){if(!n)return this.loggerProvider.log("No targeting config set, skipping initialization/recording for event."),[2];this.loggerProvider.log("Targeting config has not been set yet, cannot evaluate targeting.")}return this.lastTargetingParams=t,e=this.config.targetingConfig,e&&!this.sessionTargetingMatch?(s=o?this.latestUrlChangeTargetingEvaluationId:void 0,(a=t.event)&&Object.values(i).includes(a.event_type)&&(a=void 0),c=null!==(m=null!==(h=null===(v=t.page)||void 0===v?void 0:v.url)&&void 0!==h?h:null===(p=null===(f=g())||void 0===f?void 0:f.location)||void 0===p?void 0:p.href)&&void 0!==m?m:"",u=null!==(y=t.page)&&void 0!==y?y:""!==c?{url:c}:void 0,[4,wr({sessionId:this.identifiers.sessionId,targetingConfig:e,loggerProvider:this.loggerProvider,apiKey:this.config.apiKey,targetingParams:{userProperties:t.userProperties,event:a,page:u},urlChange:o})]):[3,2];case 1:if(d=l.sent(),o&&void 0!==s&&s!==this.latestUrlChangeTargetingEvaluationId)return this.loggerProvider.debug("Ignoring stale URL-change targeting result #".concat(s,"; latest is #").concat(this.latestUrlChangeTargetingEvaluationId,".")),[2];this.sessionTargetingMatch=this.sessionTargetingMatch||d,this.loggerProvider.debug(JSON.stringify({name:"targeted replay capture config",sessionTargetingMatch:this.sessionTargetingMatch,event:a,targetingParams:t},null,2)),l.label=2;case 2:return n?(this.initialize(!0),[3,5]):[3,3];case 3:return!r&&this.recordCancelCallback?[3,5]:(this.loggerProvider.log("Recording events for session due to forceRestart or no ongoing recording."),[4,this.recordEvents()]);case 4:l.sent(),l.label=5;case 5:return[2]}})})},this.addCustomRRWebEvent=function(t,n,r){return void 0===n&&(n={}),void 0===r&&(r=!0),a(e,void 0,void 0,function(){var e,i,s,a;return l(this,function(l){switch(l.label){case 0:return l.trys.push([0,3,,4]),e=void 0,(i=this.config)&&t!==le.METADATA?(e={config:Be(i),version:In},r?[4,je()]:[3,2]):[3,2];case 1:s=l.sent(),e=o(o({},s),e),l.label=2;case 2:return this.recordCancelCallback&&this.recordFunction?this.recordFunction.addCustomEvent(t,o(o({},n),e)):this.loggerProvider.debug("Not able to add custom replay capture event ".concat(t," due to no ongoing recording.")),[3,4];case 3:return a=l.sent(),this.loggerProvider.debug("Error while adding custom replay capture event: ",a),[3,4];case 4:return[2]}})})},this.stopRecordingEvents=function(t,n){var r,i,o,s;void 0===t&&(t="targeting"),void 0===n&&(n="stop");try{null===(r=e.semanticAdapter)||void 0===r||r.stop(t,n),e.loggerProvider.log("Session Replay capture stopping."),e.recordCancelCallback&&e.recordCancelCallback(),e.recordCancelCallback=null,null===(i=e.networkObservers)||void 0===i||i.stop(),null===(o=e.crossOriginIframeCoordinator)||void 0===o||o.stop(),e.crossOriginIframeCoordinator=null,null===(s=e.crossOriginParentSignalCleanup)||void 0===s||s.call(e),e.crossOriginParentSignalCleanup=null}catch(t){var a=t;e.loggerProvider.warn("Error occurred while stopping replay capture: ".concat(a.toString()))}},this.loggerProvider=new Ee(new T)}return e.prototype.init=function(e,t){return x(this._init(e,t))},e.prototype.setupUrlChangeListener=function(){var e,t,n=this;null===(e=this.urlChangeCleanup)||void 0===e||e.call(this);var r=g();if(null==r?void 0:r.location){var i=!!(null===(t=this.config)||void 0===t?void 0:t.targetingConfig),o=_r(r,function(e){if(n.currentPageUrl=e,i){var t=++n.latestUrlChangeTargetingEvaluationId;n.evaluateTargetingAndCapture({userProperties:{},event:void 0,page:{url:e}},!1,!1,!0),n.loggerProvider.debug("Queued URL-change targeting re-evaluation #".concat(t," for ").concat(e,"."))}});this.urlChangeCleanup=function(){o(),n.urlChangeCleanup=null}}},e.prototype.isBelowMinSessionDuration=function(){var e,t=null===(e=this.config)||void 0===e?void 0:e.minSessionDurationMs;return void 0!==t&&void 0!==this.sessionStartTime&&Date.now()-this.sessionStartTime<t},e.prototype.getCurrentPageForTargeting=function(){var e,t,n=null===(t=null===(e=g())||void 0===e?void 0:e.location)||void 0===t?void 0:t.href;return null!=n?{url:n}:void 0},e.prototype._init=function(e,t){var n,r,i,s,v,h,f,p,m,y,b,S,w,I,C;return a(this,void 0,void 0,function(){var a,k,E,x,P,M,R,O,_,A,L,F,N,D,q,U,j,B,W,z,K,H,$,G,J,Q,V,Z,X,Y,te,ne=this;return l(this,function(l){switch(l.label){case 0:return null===(n=this.urlChangeCleanup)||void 0===n||n.call(this),null===(r=this.semanticAdapter)||void 0===r||r.stop("customer_stop"),this.semanticAdapter=void 0,this.recordingEnabled=!0,this.startChildRecordingOnSetup=!1,this.loggerProvider=new Ee(t.loggerProvider||new T),Object.prototype.hasOwnProperty.call(t,"logLevel")&&this.loggerProvider.enable(t.logLevel),this.currentPageUrl=qe(),this.identifiers=new fr({sessionId:t.sessionId,deviceId:t.deviceId}),a=Date.now(),function(e,t,n){var r,i,o=yr();if(o){var s=pr(e);try{for(var a=[],l=0;l<o.length;l++)if((f=o.key(l))&&f.startsWith(s)){var u=o.getItem(f);if(null!==u){var d=Number(u);(!Number.isFinite(d)||d<=0||t-d>=gr)&&a.push(f)}}try{for(var v=c(a),h=v.next();!h.done;h=v.next()){var f=h.value;o.removeItem(f)}}catch(e){r={error:e}}finally{try{h&&!h.done&&(i=v.return)&&i.call(v)}finally{if(r)throw r.error}}}catch(e){null==n||n.debug("Failed to prune stale replay start times: ".concat(String(e)))}}}(e,a,this.loggerProvider),this.sessionStartTime=void 0!==t.sessionId&&null!==(i=function(e,t,n,r){var i=yr();if(i){var o=mr(e,t);try{var s=i.getItem(o);if(null!==s){var a=Number(s);if(Number.isFinite(a)&&a>0&&a<=n&&n-a<gr)return a}return i.setItem(o,String(n)),n}catch(e){return void(null==r||r.debug("Failed to read/write replay start time from storage: ".concat(String(e))))}}}(e,t.sessionId,a,this.loggerProvider))&&void 0!==i?i:a,k=this,[4,cn(e,t)];case 1:return k.joinedConfigGenerator=l.sent(),[4,this.joinedConfigGenerator.generateJoinedConfig()];case 2:return E=l.sent(),x=E.joinedConfig,P=E.localConfig,M=E.remoteConfig,this.config=x,this.setMetadata(t.sessionId,x,P,M,null===(s=t.version)||void 0===s?void 0:s.version,In,null===(v=t.version)||void 0===v?void 0:v.type),this.pageLeaveFns=[],t.sessionId&&(null===(h=this.config.interactionConfig)||void 0===h?void 0:h.enabled)&&(R=hr.default({sessionId:t.sessionId,type:"interaction"},this.config),this.pageLeaveFns=[R.send(this.getDeviceId.bind(this)).bind(R)],this.scrollHook=R.hook.bind(R),this.clickHandler=new cr(this.loggerProvider,R)),O=[],"idb"!==(_=this.config.storeType)||(null===(f=g())||void 0===f?void 0:f.indexedDB)||(_="memory",this.loggerProvider.warn("Could not use preferred indexedDB storage, reverting to in memory option.")),this.loggerProvider.log("Using ".concat(_," for event storage.")),F=g(),this.config.useWebWorker&&F&&F.Worker?[4,import("./index-min2.js")]:[3,4];case 3:N=l.sent(),D=N.compressionScript,q=N.trackDestinationScript,A=D,L=q,l.label=4;case 4:return l.trys.push([4,6,,7]),[4,or({config:this.config,type:"replay",minInterval:null===(p=this.config.flushIntervalConfig)||void 0===p?void 0:p.minIntervalMs,maxInterval:null===(m=this.config.flushIntervalConfig)||void 0===m?void 0:m.maxIntervalMs,maxPersistedEventsSize:this.config.maxPersistedEventsSizeBytes,storeType:_,trackDestinationWorkerScript:L,shouldSend:function(){return!ne.isBelowMinSessionDuration()}})];case 5:return U=l.sent(),this.rrwebEventManager=U,O.push({name:"replay",manager:U}),[3,7];case 6:return j=l.sent(),K=j,this.loggerProvider.warn("Error occurred while creating replay events manager: ".concat(K.toString())),[3,7];case 7:if(!(null===(y=this.config.interactionConfig)||void 0===y?void 0:y.enabled))return[3,11];B=this.config.interactionConfig.batch?lr:ar,l.label=8;case 8:return l.trys.push([8,10,,11]),[4,or({config:this.config,type:"interaction",minInterval:null!==(b=this.config.interactionConfig.trackEveryNms)&&void 0!==b?b:3e4,maxInterval:6e4,maxPersistedEventsSize:this.config.maxPersistedEventsSizeBytes,payloadBatcher:B,storeType:_,trackDestinationWorkerScript:L})];case 9:return W=l.sent(),O.push({name:"interaction",manager:W}),[3,11];case 10:return z=l.sent(),K=z,this.loggerProvider.warn("Error occurred while creating interaction events manager: ".concat(K.toString())),[3,11];case 11:if(this.eventsManager=new(sr.bind.apply(sr,d([void 0],u(O),!1))),this.eventCompressor&&this.eventCompressor.terminate(),H=!0===this.config.eagerFullSnapshotSend?function(){return ne.sendEvents()}:void 0,this.eventCompressor=new yn(this.eventsManager,this.config,this.getDeviceId(),A,H),this.pendingEmitEvents.length>0){$=this.pendingEmitEvents.splice(0);try{for(G=c($),J=G.next();!J.done;J=G.next())Q=J.value,V=Q.event,Z=Q.sessionId,this.eventCompressor.enqueueEvent(V,Z)}catch(e){Y={error:e}}finally{try{J&&!J.done&&(te=G.return)&&te.call(G)}finally{if(Y)throw Y.error}}}return this.pageLeaveFns=d(d([],u(this.pageLeaveFns),!1),[function(){var e;if(ne.config&&(null===(e=ne.identifiers)||void 0===e?void 0:e.sessionId)&&U){var t=U.getBeaconEvents();if(t.length){var n=ne.getDeviceId();n&&(ne.isBelowMinSessionDuration()||U.trackDestination.sendBeacon({events:t,sessionId:ne.identifiers.sessionId,deviceId:n,apiKey:ne.config.apiKey,serverZone:ne.config.serverZone}))}}}],!1),[4,this.initializeNetworkObservers()];case 12:return l.sent(),(null===(S=g())||void 0===S?void 0:S.opener)&&(ae(X=ie()),X.setup(o({logger:this.loggerProvider},this.config.serverZone&&{endpoint:ee[this.config.serverZone]}))),this.loggerProvider.log("Installing @amplitude/session-replay-browser."),this.teardownEventListeners(!1),[4,this.evaluateTargetingAndCapture({userProperties:t.userProperties,page:this.getCurrentPageForTargeting()},!0)];case 13:return l.sent(),(this.config.targetingConfig||(null!==(C=null===(I=null===(w=this.config.privacyConfig)||void 0===w?void 0:w.urlMaskLevels)||void 0===I?void 0:I.length)&&void 0!==C?C:0)>0)&&this.setupUrlChangeListener(),[2]}})})},e.prototype.setSessionId=function(e,t){return x(this.asyncSetSessionId(e,t))},e.prototype.asyncSetSessionId=function(e,t,n){var r,i,o,s,c,u;return a(this,void 0,void 0,function(){var a,d,v,h,f;return l(this,function(l){switch(l.label){case 0:return a=null===(r=this.identifiers)||void 0===r?void 0:r.sessionId,d=this.getDeviceId(),void 0===a||a!==e||void 0!==t&&t!==d||void 0!==(null==n?void 0:n.userProperties)&&0!==Object.keys(n.userProperties).length?(this.latestUrlChangeTargetingEvaluationId++,this.sessionTargetingMatch=!1,this.lastShouldRecordDecision=void 0,a&&this.sendEvents(a),(v=a!==e)&&(null===(o=null===(i=this.config)||void 0===i?void 0:i.semanticCapture)||void 0===o?void 0:o.enabled)&&this.semanticAdapter&&this.stopRecordingEvents("new_session"),v&&(null===(s=this.rrwebEventManager)||void 0===s||s.dropPendingBeaconEvents()),h=t||this.getDeviceId(),this.identifiers=new fr({sessionId:e,deviceId:h}),v&&(this.sessionStartTime=Date.now(),this.suppressedSendCount=0,this.hasEmittedGateDecision=!1,(null===(c=this.config)||void 0===c?void 0:c.apiKey)&&(function(e,t,n,r){var i=yr();if(i)try{i.setItem(mr(e,t),String(n))}catch(e){null==r||r.debug("Failed to write replay start time to storage: ".concat(String(e)))}}(this.config.apiKey,e,this.sessionStartTime,this.loggerProvider),void 0!==a&&function(e,t,n){var r=yr();if(r)try{r.removeItem(mr(e,t))}catch(e){null==n||n.debug("Failed to remove replay start time from storage: ".concat(String(e)))}}(this.config.apiKey,a,this.loggerProvider))),this.joinedConfigGenerator&&a?[4,this.joinedConfigGenerator.generateJoinedConfig()]:[3,2]):[2];case 1:f=l.sent().joinedConfig,this.config=f,l.label=2;case 2:return(null===(u=this.config)||void 0===u?void 0:u.targetingConfig)?[4,this.evaluateTargetingAndCapture({userProperties:null==n?void 0:n.userProperties,page:this.getCurrentPageForTargeting()},!1,!0)]:[3,4];case 3:return l.sent(),[3,6];case 4:return[4,this.recordEvents()];case 5:l.sent(),l.label=6;case 6:return[2]}})})},e.prototype.getSessionReplayProperties=function(){var e,t=this.config,n=this.identifiers;if(!t||!n)return this.loggerProvider.warn("Session replay init has not been called, cannot get session replay properties."),{};var r=this.getShouldRecord(),i={};return r&&((e={})[ue]=n.sessionReplayId?n.sessionReplayId:null,i=e,t.debugMode&&(i[fe]=JSON.stringify({appHash:z(t.apiKey).toString()}))),this.addCustomRRWebEvent(le.GET_SR_PROPS,{shouldRecord:r,eventProperties:i},10===this.eventCount),10===this.eventCount&&(this.eventCount=0),this.eventCount++,i},e.prototype.sendEvents=function(e){var t,n,r=e||(null===(t=this.identifiers)||void 0===t?void 0:t.sessionId),i=this.getDeviceId();if(this.eventsManager&&r&&i){if(this.isBelowMinSessionDuration()){var o=this.sessionStartTime,s=this.config.minSessionDurationMs;return this.loggerProvider.log("Session ".concat(r," not sent: duration ").concat(Date.now()-o,"ms is below minimum ").concat(s,"ms.")),void this.suppressedSendCount++}if(!this.hasEmittedGateDecision&&void 0!==(null===(n=this.config)||void 0===n?void 0:n.minSessionDurationMs)&&this.recordCancelCallback&&this.recordFunction){this.hasEmittedGateDecision=!0;var a=void 0!==this.sessionStartTime?Date.now()-this.sessionStartTime:void 0;this.addCustomRRWebEvent(le.REPLAY_GATE_DECISION,{sessionId:r,suppressedSendCount:this.suppressedSendCount,elapsedMs:a,minSessionDurationMs:this.config.minSessionDurationMs},!1)}this.eventsManager.sendCurrentSequenceEvents({sessionId:r,deviceId:i})}},e.prototype.initialize=function(e){var t;return void 0===e&&(e=!1),a(this,void 0,void 0,function(){var n;return l(this,function(r){return(null===(t=this.identifiers)||void 0===t?void 0:t.sessionId)?(n=this.getDeviceId())?(this.eventsManager&&e&&this.eventsManager.sendStoredEvents({deviceId:n}),[2,this.recordEvents()]):(this.loggerProvider.log("Session is not being recorded due to lack of device id."),[2,Promise.resolve()]):(this.loggerProvider.log("Session is not being recorded due to lack of session id."),[2,Promise.resolve()])})})},e.prototype.shouldOptOut=function(){var e,t,n;(null===(e=this.config)||void 0===e?void 0:e.instanceName)&&(n=W(this.config.instanceName).identityStore.getIdentity().optOut);return void 0!==n?n:null===(t=this.config)||void 0===t?void 0:t.optOut},e.prototype.getShouldRecord=function(){if(!this.identifiers||!this.config||!this.identifiers.sessionId)return this.loggerProvider.warn("Session is not being recorded due to lack of config, please call sessionReplay.init."),!1;if(!this.recordingEnabled)return this.loggerProvider.log("Session ".concat(this.identifiers.sessionId," not being captured because recording was stopped.")),!1;if(!this.config.captureEnabled)return this.loggerProvider.log("Session ".concat(this.identifiers.sessionId," not being captured due to capture being disabled for project or because the remote config could not be fetched.")),!1;if(this.shouldOptOut())return this.loggerProvider.log("Opting session ".concat(this.identifiers.sessionId," out of recording due to optOut config.")),!1;var e,t,n=!1,r="",i=!1;this.config.targetingConfig?this.sessionTargetingMatch?(r="Capturing replays for session ".concat(this.identifiers.sessionId," due to matching targeting conditions."),this.loggerProvider.log(r),n=!0,i=!0):(r="Not capturing replays for session ".concat(this.identifiers.sessionId," due to not matching targeting conditions."),this.loggerProvider.log(r),n=!1,i=!1):(e=this.identifiers.sessionId,t=this.config.sampleRate,Mr(e.toString())%1e6/1e6<t)?(n=!0,i=!0):(r="Opting session ".concat(this.identifiers.sessionId," out of recording due to sample rate."),this.loggerProvider.log(r),n=!1,i=!1);return this.lastShouldRecordDecision!==n&&this.config.targetingConfig&&(this.addCustomRRWebEvent(le.TARGETING_DECISION,{message:r,sessionId:this.identifiers.sessionId,matched:i,targetingParams:this.lastTargetingParams}),this.lastShouldRecordDecision=n),n},e.prototype.getBlockSelectors=function(){var e;return Fe(null===(e=this.config)||void 0===e?void 0:e.privacyConfig)},e.prototype.getMaskTextSelectors=function(){var e;return Ne(null===(e=this.config)||void 0===e?void 0:e.privacyConfig,this.currentPageUrl)},e.prototype.getRecordingPlugins=function(e){var t,n,r,i,o,s;return a(this,void 0,void 0,function(){var a,c,u,d;return l(this,function(l){switch(l.label){case 0:a=[];try{c=Ar({ugcFilterRules:(null===(n=null===(t=this.config)||void 0===t?void 0:t.interactionConfig)||void 0===n?void 0:n.ugcFilterRules)||[],enablePolling:(null===(r=this.config)||void 0===r?void 0:r.enableUrlChangePolling)||!1,pollingInterval:null===(i=this.config)||void 0===i?void 0:i.urlChangePollingInterval,captureDocumentTitle:null===(o=this.config)||void 0===o?void 0:o.captureDocumentTitle}),a.push(c)}catch(e){this.loggerProvider.warn("Failed to create URL tracking plugin:",e)}if(!(null===(s=null==e?void 0:e.console)||void 0===s?void 0:s.enabled))return[3,4];l.label=1;case 1:return l.trys.push([1,3,,4]),[4,import("./console-plugin-min.js")];case 2:return u=l.sent().getRecordConsolePlugin,a.push(u({level:e.console.levels})),[3,4];case 3:return d=l.sent(),this.loggerProvider.warn("Failed to load console plugin:",d),[3,4];case 4:return[2,a.length>0?a:void 0]}})})},e.prototype.getRecordFunction=function(){return a(this,void 0,void 0,function(){var e,t;return l(this,function(n){switch(n.label){case 0:if(this.recordFunction)return[2,this.recordFunction];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,import("./rrweb-record-min.js")];case 2:return e=n.sent().record,this.recordFunction=e,[2,e];case 3:return t=n.sent(),this.loggerProvider.warn("Failed to load rrweb-record module:",t),[2,null];case 4:return[2]}})})},e.prototype.recordEvents=function(e){return void 0===e&&(e=!0),a(this,void 0,void 0,function(){var t;return l(this,function(n){switch(n.label){case 0:if(this.recordEventsInFlight)return this.recordEventsPendingShouldLogMetadata=e,[2];this.recordEventsInFlight=!0,n.label=1;case 1:return n.trys.push([1,,6,7]),[4,this._recordEvents(e)];case 2:n.sent(),n.label=3;case 3:return null===this.recordEventsPendingShouldLogMetadata?[3,5]:(t=this.recordEventsPendingShouldLogMetadata,this.recordEventsPendingShouldLogMetadata=null,[4,this._recordEvents(t)]);case 4:return n.sent(),[3,3];case 5:return[3,7];case 6:return this.recordEventsInFlight=!1,this.recordEventsPendingShouldLogMetadata=null,[7];case 7:return[2]}})})},e.prototype.shouldAbandonRecordStart=function(e){return!this.recordingEnabled||e!==this.recordingGeneration},e.prototype._recordEvents=function(e){var t,n,r,i,s,c,u,d,v,h,f,p,m;return void 0===e&&(e=!0),a(this,void 0,void 0,function(){var a,y,b,S,w,I,C,k,E,x,P,T,M,R,O,_,A,L,F,N,D,q=this;return l(this,function(l){switch(l.label){case 0:return a=this.config,y=this.getShouldRecord(),b=null===(t=this.identifiers)||void 0===t?void 0:t.sessionId,y&&b&&a?(this.stopRecordingEvents("focus","pause"),S=this.recordingGeneration,[4,this.getRecordFunction()]):((null===(n=null==a?void 0:a.semanticCapture)||void 0===n?void 0:n.enabled)&&this.semanticAdapter&&this.recordCancelCallback&&this.stopRecordingEvents(this.shouldOptOut()?"opt_out":a.targetingConfig?"targeting":"sampled_out"),[2]);case 1:return!(w=l.sent())||this.shouldAbandonRecordStart(S)?[2]:[4,this.initializeNetworkObservers()];case 2:if(l.sent(),this.shouldAbandonRecordStart(S))return[2];I=null===(r=a.loggingConfig)||void 0===r?void 0:r.network,C=De(a.serverZone,a.trackServerUrl),k=[ge,pe,me,C],null===(i=this.networkObservers)||void 0===i||i.start(function(e){k.some(function(t){return e.url.startsWith(t)})||q.addCustomRRWebEvent(le.FETCH_REQUEST,e)},I),E=a.interactionConfig,x=a.loggingConfig,P=(null==E?void 0:E.enabled)&&this.eventsManager?null===(s=this.clickHandler)||void 0===s?void 0:s.createHook({eventsManager:this.eventsManager,sessionId:b,deviceIdFn:this.getDeviceId.bind(this),mirror:w.mirror,ugcFilterRules:null!==(c=E.ugcFilterRules)&&void 0!==c?c:[],performanceOptions:null===(u=a.performanceConfig)||void 0===u?void 0:u.interaction}):void 0,T=(null===(d=a.semanticCapture)||void 0===d?void 0:d.enabled)&&w.supportsNativeMouseInteraction,M=P,T&&(R=null!==(v=this.clickHandler)&&void 0!==v?v:this.clickHandler=new cr(this.loggerProvider),M=R.createSharedHook(P,function(e){var t;return null===(t=q.semanticAdapter)||void 0===t?void 0:t.click(e)})),O=o(o({},M?{mouseInteraction:M}:{}),(null==E?void 0:E.enabled)?{scroll:this.scrollHook}:{}),_=(null==E?void 0:E.enabled)&&E.ugcFilterRules?E.ugcFilterRules:[],this.loggerProvider.log("Session Replay capture beginning for ".concat(b,".")),l.label=3;case 3:return l.trys.push([3,5,,6]),A=!!(null===(h=a.crossOriginIframes)||void 0===h?void 0:h.enabled),L=!1!==(null===(f=a.crossOriginIframes)||void 0===f?void 0:f.coordinateChildren),(F=A&&function(){try{var e=g();return!!e&&e.parent!==e}catch(e){return!0}}())&&L?(this.crossOriginParentSignalCleanup=function(e){var t=g();if(!t)return function(){};var n=t.parent;function r(t){if(t.source===n){var r=t.data;(null==r?void 0:r.type)===ke&&("start"===r.action?e.onStart():"stop"===r.action&&e.onStop())}}return t.addEventListener("message",r),function(){return t.removeEventListener("message",r)}}({onStart:function(){q.recordingEnabled&&q._recordEventsInChildMode(w,b,a,O)},onStop:function(){try{q.recordCancelCallback&&q.recordCancelCallback(),q.recordCancelCallback=null}catch(t){var e=t;q.loggerProvider.warn("Error occurred while stopping child iframe replay capture: ".concat(e.toString()))}}}),this.startChildRecordingOnSetup&&(this.startChildRecordingOnSetup=!1,this._recordEventsInChildMode(w,b,a,O)),[2]):(this.startChildRecordingOnSetup=!1,[4,this.getRecordingPlugins(x)]);case 4:return N=l.sent(),this.shouldAbandonRecordStart(S)?[2]:(this.prepareSemanticCapture(a,b),this.recordCancelCallback=w(o(o({},this.buildRRWebRecordOptions(a,O,function(e){var t,n,r,i,o=(null===(n=null===(t=q.config)||void 0===t?void 0:t.semanticCapture)||void 0===n?void 0:n.enabled)&&q.semanticAdapter&&e.type===Ut.Custom&&"amp-semantic/recording"===e.data.tag&&"stop"===(null===(r=e.data.payload)||void 0===r?void 0:r.state);if((q.shouldOptOut()||!q.recordingEnabled)&&!o)return q.loggerProvider.log(q.shouldOptOut()?"Opting session ".concat(b," out of recording due to optOut config."):"Session Replay capture stopping for ".concat(b,".")),q.stopRecordingEvents(q.shouldOptOut()?"opt_out":"customer_stop"),void q.sendEvents();e.type===Ut.Meta&&(e.data.href=Ue(e.data.href,_)),q.eventCompressor?q.eventCompressor.enqueueEvent(e,b):q.pendingEmitEvents.push({event:e,sessionId:b}),null===(i=q.semanticAdapter)||void 0===i||i.event(e)},"Error while capturing replay: ")),{plugins:N,recordCrossOriginIframes:A})),this.recordCancelCallback&&(null===(p=this.semanticAdapter)||void 0===p||p.recordingReady()),A&&!F&&L&&(this.crossOriginIframeCoordinator||(this.crossOriginIframeCoordinator=new Lr),this.crossOriginIframeCoordinator.start()),this.addCustomRRWebEvent(le.DEBUG_INFO),e&&this.addCustomRRWebEvent(le.METADATA,this.metadata),[3,6]);case 5:return D=l.sent(),null===(m=this.semanticAdapter)||void 0===m||m.stop("error"),this.loggerProvider.warn("Failed to initialize session replay:",D),[3,6];case 6:return[2]}})})},e.prototype.prepareSemanticCapture=function(e,t){var n,r,i,s,a=this,l=g();if(null==l?void 0:l.document){if(!(null===(n=e.semanticCapture)||void 0===n?void 0:n.enabled))return null===(r=this.semanticAdapter)||void 0===r||r.stop("targeting"),void(null===(i=this.semanticAdapter)||void 0===i||i.prepare({enabled:!1},t));this.semanticAdapter||(this.semanticAdapter=new Wt({document:l.document,window:l,sdk:"@amplitude/session-replay-browser@".concat(In),externalClicks:!0===(null===(s=this.recordFunction)||void 0===s?void 0:s.supportsNativeMouseInteraction),externalAuxClicks:!1,getNodeId:function(e){var t,n,r,i;return null!==(i=null===(r=null===(t=a.recordFunction)||void 0===t?void 0:(n=t.mirror).getId)||void 0===r?void 0:r.call(n,e))&&void 0!==i?i:-1},getNode:function(e){var t,n;return null!==(n=null===(t=a.recordFunction)||void 0===t?void 0:t.mirror.getNode(e))&&void 0!==n?n:null},getPrivacy:function(){var e,t;return null!==(t=null===(e=a.config)||void 0===e?void 0:e.privacyConfig)&&void 0!==t?t:{}},getUrl:function(){return l.location.href},getIdentity:function(){return function(e){var t=e.document,n=Kt.get(t);if(n)return n;var r=at(t,e);if(e.top===e)try{var i=e.sessionStorage,s=function(){var e;try{var t=JSON.parse(null!==(e=i.getItem(zt))&&void 0!==e?e:"null");if(t&&Ht.test(t.tab_id)&&(null===t.owner||"string"==typeof t.owner))return t}catch(e){}},a=s();null===(null==a?void 0:a.owner)&&(r=Object.freeze(o(o({},r),{tab_id:a.tab_id})));var l=function(e){try{i.setItem(zt,JSON.stringify({tab_id:r.tab_id,owner:e}))}catch(e){}};i.setItem(zt,JSON.stringify({tab_id:r.tab_id,owner:r.document_id})),e.addEventListener("pagehide",function(){var e;(null===(e=s())||void 0===e?void 0:e.owner)===r.document_id&&l(null)}),e.addEventListener("pageshow",function(e){e.persisted&&l(r.document_id)})}catch(n){r=at(t,e)}return Kt.set(t,r),r}(l)},getAnalyticsContext:function(){var e,t;return null!==(t=null===(e=a.config)||void 0===e?void 0:e.semanticAnalyticsContext)&&void 0!==t?t:{present:!1,autocapture:[]}},inlineStylesheet:e.shouldInlineStylesheet,getSelector:function(e){var t,n;try{var r=o(o({},null===(n=null===(t=a.config)||void 0===t?void 0:t.performanceConfig)||void 0===n?void 0:n.interaction),{timeoutMs:1});return a.clickHandler?a.clickHandler.getSelector(e,r):$t(e,r)}catch(e){return null}},emit:function(e){a.recordCancelCallback&&a.recordFunction&&a.recordFunction.addCustomEvent("amp-semantic/".concat(e.name),e.payload)},onError:function(e){return a.loggerProvider.debug("Semantic capture error:",e)}})),this.semanticAdapter.prepare(e.semanticCapture,t)}},e.prototype.buildRRWebRecordOptions=function(e,t,n,r){var i=this,s=e.privacyConfig;return o(o(o(o({emit:n,inlineStylesheet:e.shouldInlineStylesheet,inlineImages:e.inlineImages,hooks:t},function(e,t){return void 0===t&&(t=function(){return""}),{maskAllInputs:!0,maskTextClass:"amp-mask",blockClass:"amp-block",blockSelector:Fe(e),maskTextSelector:Ne(e,t()),maskInputFn:Ae("input",e,t),maskTextFn:Ae("text",e,t),maskAttributeFn:Le(e,t)}}(s,function(){return i.currentPageUrl})),{applyBackgroundColorToBlockedElements:e.applyBackgroundColorToBlockedElements}),void 0!==e.fullSnapshotIntervalMs&&{checkoutEveryNms:e.fullSnapshotIntervalMs}),{recordCanvas:!1,captureAdoptedStyleSheets:e.captureAdoptedStyleSheets,slimDOMOptions:{script:!0,comment:!0,headFavicon:!0,headWhitespace:!0,headMetaDescKeywords:!0,headMetaSocial:!0,headMetaRobots:!0,headMetaHttpEquiv:!0,headMetaAuthorship:!0,headMetaVerification:!0},errorHandler:function(e){var t=e;if(t.message.includes("insertRule")&&t.message.includes("CSSStyleSheet"))throw t;if(t._external_)throw t;return i.loggerProvider.warn(r,t.toString()),!0}})},e.prototype._recordEventsInChildMode=function(e,t,n,r){try{this.recordCancelCallback&&this.recordCancelCallback(),this.recordCancelCallback=null,this.recordCancelCallback=e(o(o({},this.buildRRWebRecordOptions(n,r,function(){},"Error while capturing replay (child iframe): ")),{recordCrossOriginIframes:!0})),this.loggerProvider.log("Session Replay child iframe capture beginning for session ".concat(t,"."))}catch(e){this.loggerProvider.warn("Failed to initialize session replay in child iframe mode:",e)}},e.prototype.getDeviceId=function(){var e;return null===(e=this.identifiers)||void 0===e?void 0:e.deviceId},e.prototype.getSessionId=function(){var e;return null===(e=this.identifiers)||void 0===e?void 0:e.sessionId},e.prototype.start=function(){return x(this._start())},e.prototype._start=function(){return a(this,void 0,void 0,function(){return l(this,function(e){switch(e.label){case 0:return this.recordingEnabled=!0,this.startChildRecordingOnSetup=!0,[4,this.recordEvents()];case 1:return e.sent(),[2]}})})},e.prototype.stop=function(){this.recordingEnabled=!1,this.startChildRecordingOnSetup=!1,this.recordingGeneration++,this.stopRecordingEvents("customer_stop"),this.sendEvents()},e.prototype.flush=function(e){var t;return void 0===e&&(e=!1),a(this,void 0,void 0,function(){return l(this,function(n){return[2,null===(t=this.eventsManager)||void 0===t?void 0:t.flush(e)]})})},e.prototype.shutdown=function(){var e,t;this.recordingEnabled=!1,this.startChildRecordingOnSetup=!1,this.recordingGeneration++,null===(e=this.urlChangeCleanup)||void 0===e||e.call(this),null===(t=this.crossOriginParentSignalCleanup)||void 0===t||t.call(this),this.crossOriginParentSignalCleanup=null,this.teardownEventListeners(!0),this.stopRecordingEvents(this.semanticAdapter&&this.shouldOptOut()?"opt_out":"customer_stop"),this.sendEvents()},e.prototype.mapSDKType=function(e){return"plugin"===e?"@amplitude/plugin-session-replay-browser":"segment"===e?"@amplitude/segment-session-replay-plugin":null},e.prototype.setMetadata=function(e,t,n,r,i,o,s){var a=(null==e?void 0:e.toString())?z(e.toString()):void 0;this.metadata={joinedConfig:t,localConfig:n,remoteConfig:r,sessionId:e,hashValue:a,sampleRate:t.sampleRate,replaySDKType:this.mapSDKType(s),replaySDKVersion:i,standaloneSDKType:"@amplitude/session-replay-browser",standaloneSDKVersion:o}},e.prototype.initializeNetworkObservers=function(){var e,t,n;return a(this,void 0,void 0,function(){var r,i;return l(this,function(o){switch(o.label){case 0:if(!(null===(n=null===(t=null===(e=this.config)||void 0===e?void 0:e.loggingConfig)||void 0===t?void 0:t.network)||void 0===n?void 0:n.enabled)||this.networkObservers)return[3,4];o.label=1;case 1:return o.trys.push([1,3,,4]),[4,import("./observers-min.js")];case 2:return r=o.sent().NetworkObservers,this.networkObservers=new r,[3,4];case 3:return i=o.sent(),this.loggerProvider.warn("Failed to import or instantiate NetworkObservers:",i),[3,4];case 4:return[2]}})})},e}(),Ur=function(e){return function(){var t=e.config||We();return{logger:t.loggerProvider,logLevel:t.logLevel}}},jr=function(){var e=new qr;return{init:L(e.init.bind(e),"init",Ur(e)),evaluateTargetingAndCapture:L(e.evaluateTargetingAndCapture.bind(e),"evaluateTargetingAndRecord",Ur(e)),setSessionId:L(e.setSessionId.bind(e),"setSessionId",Ur(e)),getSessionId:L(e.getSessionId.bind(e),"getSessionId",Ur(e)),getSessionReplayProperties:L(e.getSessionReplayProperties.bind(e),"getSessionReplayProperties",Ur(e)),flush:L(e.flush.bind(e),"flush",Ur(e)),start:L(e.start.bind(e),"start",Ur(e)),stop:L(e.stop.bind(e),"stop",Ur(e)),shutdown:L(e.shutdown.bind(e),"shutdown",Ur(e))}}(),Br=jr.init,Wr=jr.setSessionId,zr=jr.getSessionId,Kr=jr.getSessionReplayProperties,Hr=jr.flush,$r=jr.start,Gr=jr.stop,Jr=jr.shutdown,Qr=jr.evaluateTargetingAndCapture;!function(e){e.SET="$set",e.SET_ONCE="$setOnce",e.ADD="$add",e.APPEND="$append",e.PREPEND="$prepend",e.REMOVE="$remove",e.PREINSERT="$preInsert",e.POSTINSERT="$postInsert",e.UNSET="$unset",e.CLEAR_ALL="$clearAll"}(Fr||(Fr={})),function(e){e.REVENUE_PRODUCT_ID="$productId",e.REVENUE_QUANTITY="$quantity",e.REVENUE_PRICE="$price",e.REVENUE_TYPE="$revenueType",e.REVENUE_CURRENCY="$currency",e.REVENUE="$revenue"}(Nr||(Nr={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(Dr||(Dr={}));const Vr=[Fr.SET,Fr.SET_ONCE,Fr.ADD,Fr.APPEND,Fr.PREPEND,Fr.POSTINSERT];const Zr="1.37.0-codexsemantic-review-integration.0";class Xr{constructor(e){this.name=Xr.pluginName,this.type="enrichment",this.config=null,this.sessionReplay={flush:Hr,getSessionId:zr,getSessionReplayProperties:Kr,init:Br,setSessionId:Wr,start:$r,stop:Gr,shutdown:Jr,evaluateTargetingAndCapture:Qr},this.options=Object.assign({forceSessionTracking:!1},e),this.srInitOptions=this.options}setup(e,t){var n,r,i,o,s,l,c,u,d;return a(this,void 0,void 0,function*(){try{null==e||e.loggerProvider.log(`Installing @amplitude/plugin-session-replay, version ${Zr}.`),this.config=e,this.options.forceSessionTracking&&("boolean"==typeof e.defaultTracking?!1===e.defaultTracking&&(e.defaultTracking={pageViews:!1,formInteractions:!1,fileDownloads:!1,sessions:!0}):e.defaultTracking=Object.assign(Object.assign({},e.defaultTracking),{sessions:!0}));const a=W(this.config.instanceName).identityStore.getIdentity().userProperties;this.srInitOptions={instanceName:this.config.instanceName,deviceId:null!==(n=this.options.deviceId)&&void 0!==n?n:this.config.deviceId,optOut:this.config.optOut,sessionId:this.options.customSessionId?void 0:this.config.sessionId,loggerProvider:this.config.loggerProvider,logLevel:this.config.logLevel,flushMaxRetries:this.config.flushMaxRetries,serverZone:this.config.serverZone,configServerUrl:this.options.configServerUrl||(null===(r=this.config.remoteConfig)||void 0===r?void 0:r.serverUrl),trackServerUrl:this.options.trackServerUrl,sampleRate:this.options.sampleRate,semanticCapture:this.options.semanticCapture,semanticAnalyticsContext:{present:!0,autocapture:(t=this.config.autocapture,!0===t?["attribution","fileDownloads","formInteractions","pageViews","sessions","elementInteractions","webVitals","frustrationInteractions"]:t&&"object"==typeof t?Object.keys(t).filter(e=>{const n=t[e];if("frustrationInteractions"!==e)return Boolean(n);const r=t.frustrationInteractions;return!0===r||!(!r||"object"!=typeof r)&&(!1!==r.deadClicks&&null!==r.deadClicks||Boolean(r.errorClicks))}):[])},privacyConfig:{blockSelector:null===(i=this.options.privacyConfig)||void 0===i?void 0:i.blockSelector,maskAttributes:null===(o=this.options.privacyConfig)||void 0===o?void 0:o.maskAttributes,maskSelector:null===(s=this.options.privacyConfig)||void 0===s?void 0:s.maskSelector,unmaskSelector:null===(l=this.options.privacyConfig)||void 0===l?void 0:l.unmaskSelector,defaultMaskLevel:null===(c=this.options.privacyConfig)||void 0===c?void 0:c.defaultMaskLevel},debugMode:this.options.debugMode,shouldInlineStylesheet:this.options.shouldInlineStylesheet,inlineImages:this.options.inlineImages,version:{type:"plugin",version:Zr},performanceConfig:this.options.performanceConfig,storeType:this.options.storeType,useWebWorker:null!==(u=this.options.useWebWorker)&&void 0!==u?u:null===(d=this.options.experimental)||void 0===d?void 0:d.useWebWorker,userProperties:a,applyBackgroundColorToBlockedElements:this.options.applyBackgroundColorToBlockedElements,interactionConfig:this.options.interactionConfig,captureDocumentTitle:this.options.captureDocumentTitle,enableUrlChangePolling:this.options.enableUrlChangePolling,urlChangePollingInterval:this.options.urlChangePollingInterval,captureAdoptedStyleSheets:this.options.captureAdoptedStyleSheets,crossOriginIframes:this.options.crossOriginIframes,flushIntervalConfig:this.options.flushIntervalConfig,eagerFullSnapshotSend:this.options.eagerFullSnapshotSend,captureFullSnapshotOnFocus:this.options.captureFullSnapshotOnFocus,maxPersistedEventsSizeBytes:this.options.maxPersistedEventsSizeBytes,maxSingleEventSizeBytes:this.options.maxSingleEventSizeBytes,sendTimeoutMs:this.options.sendTimeoutMs,handleSendEvents:this.options.handleSendEvents,handleFetchConfig:this.options.handleFetchConfig},yield this.sessionReplay.init(e.apiKey,this.srInitOptions).promise}catch(t){null==e||e.loggerProvider.error(`Session Replay: Failed to initialize due to ${t.message}`)}var t})}onSessionIdChanged(e){var t;return a(this,void 0,void 0,function*(){null===(t=this.config)||void 0===t||t.loggerProvider.debug(`Analytics session id is changed to ${e}, SR session id is ${String(this.sessionReplay.getSessionId())}.`),yield this.sessionReplay.setSessionId(e).promise})}onOptOutChanged(e){var t;return a(this,void 0,void 0,function*(){null===(t=this.config)||void 0===t||t.loggerProvider.debug(`optOut is changed to ${String(e)}, calling ${e?"sessionReplay.shutdown()":"sessionReplay.init()"}.`),e?this.sessionReplay.shutdown():null!=this.config&&(yield this.sessionReplay.init(this.config.apiKey,this.srInitOptions).promise)})}execute(e){var t,n,r;return a(this,void 0,void 0,function*(){try{if(this.options.customSessionId){const t=this.options.customSessionId(e);if(t){t!==this.sessionReplay.getSessionId()&&(yield this.sessionReplay.setSessionId(t).promise);const n=this.sessionReplay.getSessionReplayProperties();e.event_properties=Object.assign(Object.assign({},e.event_properties),n)}}else{const r=null===(t=this.config)||void 0===t?void 0:t.sessionId;if(r&&r!==this.sessionReplay.getSessionId()&&(yield this.sessionReplay.setSessionId(r).promise),r&&r===e.session_id){let t;e.event_type===i.IDENTIFY&&(t=(e=>{if(!e.user_properties)return;let t={};return Object.keys(e.user_properties).forEach(n=>{if(Vr.includes(n)){const r=e.user_properties&&e.user_properties[n];t=Object.assign(Object.assign({},t),r)}}),t})(e));const r=g();yield this.sessionReplay.evaluateTargetingAndCapture({event:e,userProperties:t,page:null!=(null===(n=null==r?void 0:r.location)||void 0===n?void 0:n.href)?{url:r.location.href}:void 0});const o=this.sessionReplay.getSessionReplayProperties();e.event_properties=Object.assign(Object.assign({},e.event_properties),o)}}return e.event_type===i.IDENTIFY&&e.event_properties&&delete e.event_properties["[Amplitude] Session Replay ID"],Promise.resolve(e)}catch(t){return null===(r=this.config)||void 0===r||r.loggerProvider.error(`Session Replay: Failed to enrich event due to ${t.message}`),Promise.resolve(e)}})}teardown(){var e;return a(this,void 0,void 0,function*(){try{this.sessionReplay.shutdown(),this.config=null}catch(t){null===(e=this.config)||void 0===e||e.loggerProvider.error(`Session Replay: teardown failed due to ${t.message}`)}})}getSessionReplayProperties(){return this.sessionReplay.getSessionReplayProperties()}start(){return a(this,void 0,void 0,function*(){yield this.sessionReplay.start().promise})}stop(){this.sessionReplay.stop()}}Xr.pluginName="@amplitude/plugin-session-replay-browser";const Yr=e=>new Xr(e);export{Xr as S,c as _,d as a,u as b,a as c,l as d,o as e,g,Dn as o,Yr as s,hn as t};
1
+ function e(e,t){return t.forEach(function(t){t&&"string"!=typeof t&&!Array.isArray(t)&&Object.keys(t).forEach(function(n){if("default"!==n&&!(n in e)){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}})}),Object.freeze(e)}var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},t(e,n)};function n(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var r,i,o=function(){return o=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},o.apply(this,arguments)};function s(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]])}return n}function a(e,t,n,r){return new(n||(n=Promise))(function(i,o){function s(e){try{l(r.next(e))}catch(e){o(e)}}function a(e){try{l(r.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(s,a)}l((r=r.apply(e,t||[])).next())})}function l(e,t){var n,r,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(l){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,r=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=t.call(e,o)}catch(e){a=[6,e],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,l])}}}function c(e){var t="function"==typeof Symbol&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function u(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,i,o=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=o.next()).done;)s.push(r.value)}catch(e){i={error:e}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}function d(e,t,n){if(n||2===arguments.length)for(var r,i=0,o=t.length;i<o;i++)!r&&i in t||(r||(r=Array.prototype.slice.call(t,0,i)),r[i]=t[i]);return e.concat(r||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError,function(e){e.SET="$set",e.SET_ONCE="$setOnce",e.ADD="$add",e.APPEND="$append",e.PREPEND="$prepend",e.REMOVE="$remove",e.PREINSERT="$preInsert",e.POSTINSERT="$postInsert",e.UNSET="$unset",e.CLEAR_ALL="$clearAll"}(r||(r={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(i||(i={}));var h,v="$default_instance",g="https://api2.amplitude.com/2/httpapi";!function(e){e.Unknown="unknown",e.Skipped="skipped",e.Success="success",e.RateLimit="rate_limit",e.PayloadTooLarge="payload_too_large",e.Invalid="invalid",e.Failed="failed",e.Timeout="Timeout",e.SystemError="SystemError"}(h||(h={}));var f=function(){var e="ampIntegrationContext";return"undefined"!=typeof globalThis&&void 0!==globalThis[e]?globalThis[e]:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:void 0},p=d([],u(Array(256).keys()),!1).map(function(e){return e.toString(16).padStart(2,"0")}),m=function(e){var t,n=f();if(!(null===(t=null==n?void 0:n.crypto)||void 0===t?void 0:t.getRandomValues))return function(e){return e?(e^16*Math.random()>>e/4).toString(16):(String(1e7)+String(-1e3)+String(-4e3)+String(-8e3)+String(-1e11)).replace(/[018]/g,m)}(e);var r=n.crypto.getRandomValues(new Uint8Array(16));return r[6]=15&r[6]|64,r[8]=63&r[8]|128,d([],u(r.entries()),!1).map(function(e){var t=u(e,2),n=t[0],r=t[1];return[4,6,8,10].includes(n)?"-".concat(p[r]):p[r]}).join("")},y={},b={get exports(){return y},set exports(e){y=e}},S=Object.prototype.hasOwnProperty;function I(e){return"[Throws: "+(e?e.message:"?")+"]"}function w(e){var t=[];return function e(n){if(null===n||"object"!=typeof n)return n;if(-1!==t.indexOf(n))return"[Circular]";if(t.push(n),"function"==typeof n.toJSON)try{var r=e(n.toJSON());return t.pop(),r}catch(e){return I(e)}if(Array.isArray(n)){var i=n.map(e);return t.pop(),i}var o=Object.keys(n).reduce(function(t,r){return t[r]=e(function(e,t){if(S.call(e,t))try{return e[t]}catch(e){return I(e)}return e[t]}(n,r)),t},{});return t.pop(),o}(e)}b.exports=function(e,t,n){return JSON.stringify(w(e),t,n)};var C,E=y.ensureProperties=w,P=y||e({__proto__:null,ensureProperties:E,get default(){return y}},[y]),k=function(e){return{promise:e||Promise.resolve()}};!function(e){e[e.None=0]="None",e[e.Error=1]="Error",e[e.Warn=2]="Warn",e[e.Verbose=3]="Verbose",e[e.Debug=4]="Debug"}(C||(C={}));var x="Amplitude Logger ",T=function(){function e(){this.logLevel=C.None}return e.prototype.disable=function(){this.logLevel=C.None},e.prototype.enable=function(e){void 0===e&&(e=C.Warn),this.logLevel=e},e.prototype.log=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<C.Verbose||console.log("".concat(x,"[Log]: ").concat(e.join(" ")))},e.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<C.Warn||console.warn("".concat(x,"[Warn]: ").concat(e.join(" ")))},e.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<C.Error||console.error("".concat(x,"[Error]: ").concat(e.join(" ")))},e.prototype.debug=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this.logLevel<C.Debug||console.log("".concat(x,"[Debug]: ").concat(e.join(" ")))},e}(),R=function(e){return void 0===e||""===e?v:e},M=function(){return{flushMaxRetries:12,flushQueueSize:200,flushIntervalMillis:1e4,instanceName:v,logLevel:C.Warn,loggerProvider:new T,offline:!1,optOut:!1,serverUrl:g,serverZone:"US",useBatch:!1}},O=function(){function e(e){var t,n,r,i;this._optOut=!1;var o=M();this.apiKey=e.apiKey,this.flushIntervalMillis=null!==(t=e.flushIntervalMillis)&&void 0!==t?t:o.flushIntervalMillis,this.flushMaxRetries=e.flushMaxRetries||o.flushMaxRetries,this.flushQueueSize=e.flushQueueSize||o.flushQueueSize,this.instanceName=R(e.instanceName),this.loggerProvider=e.loggerProvider||o.loggerProvider,this.logLevel=null!==(n=e.logLevel)&&void 0!==n?n:o.logLevel,this.minIdLength=e.minIdLength,this.plan=e.plan,this.ingestionMetadata=e.ingestionMetadata,this.offline=void 0!==e.offline?e.offline:o.offline,this.optOut=null!==(r=e.optOut)&&void 0!==r?r:o.optOut,this.serverUrl=e.serverUrl,this.serverZone=e.serverZone||o.serverZone,this.storageProvider=e.storageProvider,this.transportProvider=e.transportProvider,this.useBatch=null!==(i=e.useBatch)&&void 0!==i?i:o.useBatch,this.loggerProvider.enable(this.logLevel);var s=_(e.serverUrl,e.serverZone,e.useBatch);this.serverZone=s.serverZone,this.serverUrl=s.serverUrl}return Object.defineProperty(e.prototype,"optOut",{get:function(){return this._optOut},set:function(e){this._optOut=e},enumerable:!1,configurable:!0}),e}(),F=function(e,t){return"EU"===e?t?"https://api.eu.amplitude.com/batch":"https://api.eu.amplitude.com/2/httpapi":t?"https://api2.amplitude.com/batch":g},_=function(e,t,n){if(void 0===e&&(e=""),void 0===t&&(t=M().serverZone),void 0===n&&(n=M().useBatch),e)return{serverUrl:e,serverZone:void 0};var r=["US","EU"].includes(t)?t:M().serverZone;return{serverZone:r,serverUrl:F(r,n)}};var L=function(e,t,n,r,i){return void 0===i&&(i=null),function(){for(var o=[],s=0;s<arguments.length;s++)o[s]=arguments[s];var a=n(),l=a.logger,c=a.logLevel;if(c&&c<C.Debug||!c||!l)return e.apply(i,o);var u,d={type:"invoke public method",name:t,args:o,stacktrace:(u=1,void 0===u&&(u=0),((new Error).stack||"").split("\n").slice(2+u).map(function(e){return e.trim()})),time:{start:(new Date).toISOString()},states:{}};r&&d.states&&(d.states.before=r());var h=e.apply(i,o);return h&&h.promise?h.promise.then(function(){r&&d.states&&(d.states.after=r()),d.time&&(d.time.end=(new Date).toISOString()),l.debug(JSON.stringify(d,null,2))}):(r&&d.states&&(d.states.after=r()),d.time&&(d.time.end=(new Date).toISOString()),l.debug(JSON.stringify(d,null,2))),h}};class D{getApplicationContext(){return{versionName:this.versionName,language:A(),platform:"Web",os:void 0,deviceModel:void 0}}}const A=()=>"undefined"!=typeof navigator&&(navigator.languages&&navigator.languages[0]||navigator.language)||"";class q{constructor(){this.queue=[]}logEvent(e){this.receiver?this.receiver(e):this.queue.length<512&&this.queue.push(e)}setEventReceiver(e){this.receiver=e,this.queue.length>0&&(this.queue.forEach(t=>{e(t)}),this.queue=[])}}const N=(e,t)=>{const n=["string","number","boolean","undefined"],r=typeof e;if(r!==typeof t)return!1;for(const i of n)if(i===r)return e===t;if(null==e&&null==t)return!0;if(null==e||null==t)return!1;if(e.length!==t.length)return!1;const i=Array.isArray(e),o=Array.isArray(t);if(i!==o)return!1;if(!i||!o){const n=Object.keys(e).sort(),r=Object.keys(t).sort();if(!N(n,r))return!1;let i=!0;return Object.keys(e).forEach(n=>{N(e[n],t[n])||(i=!1)}),i}for(let n=0;n<e.length;n++)if(!N(e[n],t[n]))return!1;return!0};Object.entries||(Object.entries=function(e){const t=Object.keys(e);let n=t.length;const r=new Array(n);for(;n--;)r[n]=[t[n],e[t[n]]];return r});class B{constructor(){this.identity={userProperties:{}},this.listeners=new Set}editIdentity(){const e=this,t=Object.assign({},this.identity.userProperties),n=Object.assign(Object.assign({},this.identity),{userProperties:t});return{setUserId:function(e){return n.userId=e,this},setDeviceId:function(e){return n.deviceId=e,this},setUserProperties:function(e){return n.userProperties=e,this},setOptOut(e){return n.optOut=e,this},updateUserProperties:function(e){let t=n.userProperties||{};for(const[n,r]of Object.entries(e))switch(n){case"$set":for(const[e,n]of Object.entries(r))t[e]=n;break;case"$unset":for(const e of Object.keys(r))delete t[e];break;case"$clearAll":t={}}return n.userProperties=t,this},commit:function(){return e.setIdentity(n),this}}}getIdentity(){return Object.assign({},this.identity)}setIdentity(e){const t=Object.assign({},this.identity);this.identity=Object.assign({},e),N(t,this.identity)||this.listeners.forEach(t=>{t(e)})}addIdentityListener(e){this.listeners.add(e)}removeIdentityListener(e){this.listeners.delete(e)}}const j="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:self;class U{constructor(){this.identityStore=new B,this.eventBridge=new q,this.applicationContextProvider=new D}static getInstance(e){return j.analyticsConnectorInstances||(j.analyticsConnectorInstances={}),j.analyticsConnectorInstances[e]||(j.analyticsConnectorInstances[e]=new U),j.analyticsConnectorInstances[e]}}var W=function(e){return U.getInstance(R(e))},z=function(e){var t=0;if(0===e.length)return t;for(var n=0;n<e.length;n++){t=(t<<5)-t+e.charCodeAt(n),t|=0}return t},H=function(){function e(){}return e.prototype.send=function(e,t,n){return Promise.resolve(null)},e.prototype.buildResponse=function(e){var t,n,r,i,o,s,a,l,c,u,d,v,g,f,p,m,y,b,S,I,w,C;if("object"!=typeof e)return null;var E=e.code||0,P=this.buildStatus(E);switch(P){case h.Success:return{status:P,statusCode:E,body:{eventsIngested:null!==(t=e.events_ingested)&&void 0!==t?t:0,payloadSizeBytes:null!==(n=e.payload_size_bytes)&&void 0!==n?n:0,serverUploadTime:null!==(r=e.server_upload_time)&&void 0!==r?r:0}};case h.Invalid:return{status:P,statusCode:E,body:{error:null!==(i=e.error)&&void 0!==i?i:"",missingField:null!==(o=e.missing_field)&&void 0!==o?o:"",eventsWithInvalidFields:null!==(s=e.events_with_invalid_fields)&&void 0!==s?s:{},eventsWithMissingFields:null!==(a=e.events_with_missing_fields)&&void 0!==a?a:{},eventsWithInvalidIdLengths:null!==(l=e.events_with_invalid_id_lengths)&&void 0!==l?l:{},epsThreshold:null!==(c=e.eps_threshold)&&void 0!==c?c:0,exceededDailyQuotaDevices:null!==(u=e.exceeded_daily_quota_devices)&&void 0!==u?u:{},silencedDevices:null!==(d=e.silenced_devices)&&void 0!==d?d:[],silencedEvents:null!==(v=e.silenced_events)&&void 0!==v?v:[],throttledDevices:null!==(g=e.throttled_devices)&&void 0!==g?g:{},throttledEvents:null!==(f=e.throttled_events)&&void 0!==f?f:[]}};case h.PayloadTooLarge:return{status:P,statusCode:E,body:{error:null!==(p=e.error)&&void 0!==p?p:""}};case h.RateLimit:return{status:P,statusCode:E,body:{error:null!==(m=e.error)&&void 0!==m?m:"",epsThreshold:null!==(y=e.eps_threshold)&&void 0!==y?y:0,throttledDevices:null!==(b=e.throttled_devices)&&void 0!==b?b:{},throttledUsers:null!==(S=e.throttled_users)&&void 0!==S?S:{},exceededDailyQuotaDevices:null!==(I=e.exceeded_daily_quota_devices)&&void 0!==I?I:{},exceededDailyQuotaUsers:null!==(w=e.exceeded_daily_quota_users)&&void 0!==w?w:{},throttledEvents:null!==(C=e.throttled_events)&&void 0!==C?C:[]}};case h.Timeout:default:return{status:P,statusCode:E}}},e.prototype.buildStatus=function(e){return function(e){return e>=200&&e<300}(e)?h.Success:429===e?h.RateLimit:413===e?h.PayloadTooLarge:408===e?h.Timeout:e>=400&&e<500?h.Invalid:e>=500?h.Failed:h.Unknown},e}(),K=function(e){function t(t){void 0===t&&(t={});var n=e.call(this)||this;return n.customHeaders=t,n}return n(t,e),t.prototype.send=function(e,t){return a(this,void 0,void 0,function(){var n,r,i;return l(this,function(s){switch(s.label){case 0:if("undefined"==typeof fetch)throw new Error("FetchTransport is not supported");return n={headers:o({"Content-Type":"application/json",Accept:"*/*"},this.customHeaders),body:JSON.stringify(t),method:"POST"},[4,fetch(e,n)];case 1:return[4,(r=s.sent()).text()];case 2:i=s.sent();try{return[2,this.buildResponse(JSON.parse(i))]}catch(e){return[2,this.buildResponse({code:r.status})]}return[2]}})})},t}(H),$=function(){function e(e,t){this.key="AMP_remote_config_".concat(e.substring(0,10)),this.logger=t;try{this.isSupported="undefined"!=typeof localStorage}catch(e){this.logger.debug("Remote config localstorage failed to access: ",e),this.isSupported=!1}}return e.prototype.fetchConfig=function(){var e=null,t={remoteConfig:null,lastFetch:new Date};if(!this.isSupported)return Promise.resolve(t);try{e=localStorage.getItem(this.key)}catch(e){return this.logger.debug("Remote config localstorage failed to access: ",e),Promise.resolve(t)}if(null===e)return this.logger.debug("Remote config localstorage gets null because the key does not exist"),Promise.resolve(t);try{var n=JSON.parse(e);return this.logger.debug("Remote config localstorage parsed successfully: ".concat(P(n))),Promise.resolve({remoteConfig:n.remoteConfig,lastFetch:new Date(n.lastFetch)})}catch(e){return this.logger.debug("Remote config localstorage failed to parse: ",e),localStorage.removeItem(this.key),Promise.resolve(t)}},e.prototype.setConfig=function(e){if(!this.isSupported)return Promise.resolve(!1);try{return localStorage.setItem(this.key,JSON.stringify(e)),this.logger.debug("Remote config localstorage set successfully."),Promise.resolve(!0)}catch(e){this.logger.debug("Remote config localstorage failed to set: ",e)}return Promise.resolve(!1)},e}();var G,Q=401,J=403,V=429,Z=function(){function e(t,n,r,i,o,s,a){void 0===r&&(r="US"),void 0===s&&(s=e.DEFAULT_CONFIG_GROUP),this.callbackInfos=[],this.lastSuccessfulFetch=null,this.fetchPromise=null,this.isLastFetchInvalidApiKey=!1,this.apiKey=t,this.configGroup=s,this.serverUrl=i||("US"===r?"https://sr-client-cfg.amplitude.com/config":"https://sr-client-cfg.eu.amplitude.com/config"),this.logger=n,this.storage=a||new $(t,n),this.customFetch=o}return e.prototype.subscribe=function(e,t,n){var r=m(),i={id:r,key:e,deliveryMode:t,callback:n};return this.callbackInfos.push(i),"all"===t?this.subscribeAll(i):this.subscribeWaitForRemote(i,t.timeout),r},e.prototype.unsubscribe=function(e){var t=this.callbackInfos.findIndex(function(t){return t.id===e});return-1===t?(this.logger.debug("Remote config client unsubscribe failed because callback with id ".concat(e," doesn't exist.")),!1):(this.callbackInfos.splice(t,1),this.logger.debug("Remote config client unsubscribe succeeded removing callback with id ".concat(e,".")),!0)},e.prototype.updateConfigs=function(){return a(this,void 0,void 0,function(){var e,t=this;return l(this,function(n){switch(n.label){case 0:return this.lastSuccessfulFetch&&Date.now()-this.lastSuccessfulFetch<3e5?(this.logger.debug("Remote config client skipping updateConfigs: Too recent"),[2]):[4,this.getOrCreateFetchPromise()];case 1:return e=n.sent(),this.storage.setConfig(e),this.callbackInfos.forEach(function(n){t.sendCallback(n,e,"remote")}),[2]}})})},e.prototype.getOrCreateFetchPromise=function(){var e=this;return this.fetchPromise?this.fetchPromise:this.isLastFetchInvalidApiKey?(this.logger.debug("Remote config client skipping fetch: Invalid API key"),this.fetchPromise=Promise.resolve({remoteConfig:null,lastFetch:new Date}).finally(function(){e.fetchPromise=null}),this.fetchPromise):(this.fetchPromise=this.fetch().then(function(t){return null!==t.remoteConfig&&(e.lastSuccessfulFetch=Date.now()),t}).finally(function(){e.fetchPromise=null}),this.fetchPromise)},e.prototype.subscribeAll=function(e){return a(this,void 0,void 0,function(){var t,n,r,i=this;return l(this,function(o){switch(o.label){case 0:return t=this.getOrCreateFetchPromise().then(function(t){i.logger.debug("Remote config client subscription all mode fetched from remote: ".concat(JSON.stringify(t))),i.sendCallback(e,t,"remote"),i.storage.setConfig(t)}),n=this.storage.fetchConfig().then(function(e){return e}),[4,Promise.race([t,n])];case 1:return void 0!==(r=o.sent())&&(this.logger.debug("Remote config client subscription all mode fetched from cache: ".concat(JSON.stringify(r))),null!==r.remoteConfig?this.sendCallback(e,r,"cache"):this.logger.debug("Remote config client skips sending callback because cache is empty (first time user).")),[4,t];case 2:return o.sent(),[2]}})})},e.prototype.subscribeWaitForRemote=function(e,t){return a(this,void 0,void 0,function(){var n,r;return l(this,function(i){switch(i.label){case 0:n=new Promise(function(e,n){setTimeout(function(){n("Timeout exceeded")},t)}),i.label=1;case 1:return i.trys.push([1,3,,5]),[4,Promise.race([this.getOrCreateFetchPromise(),n])];case 2:return r=i.sent(),this.logger.debug("Remote config client subscription wait for remote mode returns from remote."),this.sendCallback(e,r,"remote"),this.storage.setConfig(r),[3,5];case 3:return i.sent(),this.logger.debug("Remote config client subscription wait for remote mode exceeded timeout. Try to fetch from cache."),[4,this.storage.fetchConfig()];case 4:return null!==(r=i.sent()).remoteConfig?(this.logger.debug("Remote config client subscription wait for remote mode returns a cached copy."),this.sendCallback(e,r,"cache")):(this.logger.debug("Remote config client subscription wait for remote mode failed to fetch cache."),this.sendCallback(e,r,"remote")),[3,5];case 5:return[2]}})})},e.prototype.sendCallback=function(e,t,n){var r;e.lastCallback=new Date,r=e.key?e.key.split(".").reduce(function(e,t){return null===e?e:t in e?e[t]:null},t.remoteConfig):t.remoteConfig,e.callback(r,n,t.lastFetch)},e.prototype.fetch=function(e,t){return void 0===e&&(e=3),void 0===t&&(t=1e3),a(this,void 0,void 0,function(){var n,r,i,o,s,a,c=this;return l(this,function(u){switch(u.label){case 0:n=t/e,r={remoteConfig:null,lastFetch:new Date},i=function(r){var i,s,a,u,d,h,v,g,f;return l(this,function(l){switch(l.label){case 0:i=!0,s=new AbortController,a=setTimeout(function(){return s.abort()},t),l.label=1;case 1:return l.trys.push([1,10,11,12]),u=o.getUrlParams(),d={Accept:"*/*"},o.customFetch?[4,(p=o.customFetch({url:u,method:"GET",headers:d,signal:s.signal}),m=s.signal,new Promise(function(e,t){var n=function(){var e=new Error("Remote config custom fetch aborted by timeout");e.name="AbortError",t(e)};m.addEventListener("abort",n,{once:!0}),p.then(function(t){m.removeEventListener("abort",n),e(t)},function(e){m.removeEventListener("abort",n),t(e)})}))]:[3,3];case 2:return v=l.sent(),[3,5];case 3:return[4,fetch(u,{method:"GET",headers:d,signal:s.signal})];case 4:v=l.sent(),l.label=5;case 5:return(h=v).ok||h.status>=200&&h.status<300?[3,7]:[4,h.text()];case 6:return g=l.sent(),o.logger.debug("Remote config client fetch with retry time ".concat(e," failed with ").concat(h.status,": ").concat(g)),h.status===Q||h.status===J?(o.logger.error("Remote config client fetch failed with ".concat(h.status,". Invalid API key; future fetches will be skipped.")),o.isLastFetchInvalidApiKey=!0,i=!1):h.status>=400&&h.status<500&&h.status!==V&&(i=!1),[3,9];case 7:return[4,h.json()];case 8:return[2,{value:{remoteConfig:l.sent(),lastFetch:new Date}}];case 9:return[3,12];case 10:return(f=l.sent())instanceof Error&&"AbortError"===f.name?o.logger.debug("Remote config client fetch with retry time ".concat(e," timed out after ").concat(t,"ms")):o.logger.debug("Remote config client fetch with retry time ".concat(e," is rejected because: "),f),[3,12];case 11:return clearTimeout(a),[7];case 12:return i?r<e-1?[4,new Promise(function(e){return setTimeout(e,c.getJitterDelay(n))})]:[3,14]:[2,"break"];case 13:l.sent(),l.label=14;case 14:return[2]}var p,m})},o=this,s=0,u.label=1;case 1:return s<e?[5,i(s)]:[3,4];case 2:if("object"==typeof(a=u.sent()))return[2,a.value];if("break"===a)return[3,4];u.label=3;case 3:return s++,[3,1];case 4:return[2,r]}})})},e.prototype.getJitterDelay=function(e){return Math.floor(Math.random()*e)},e.prototype.getUrlParams=function(){var e=encodeURIComponent(this.apiKey),t=new URLSearchParams;return t.append("config_group",this.configGroup),"".concat(this.serverUrl,"/").concat(e,"?").concat(t.toString())},e.DEFAULT_CONFIG_GROUP="browser",e}();!function(e){e.US="US",e.EU="EU",e.STAGING="STAGING"}(G||(G={}));var Y,X="https://app.amplitude.com",ee={US:X,EU:"https://app.eu.amplitude.com",STAGING:"https://apps.stag2.amplitude.com"};var te="__AMPLITUDE_MESSENGER_INSTANCE__",ne="__AMPLITUDE_MESSENGER__",re=function(){function e(e){var t=(void 0===e?{}:e).origin,n=void 0===t?X:t;this[Y]=!0,this.isSetup=!1,this.messageHandler=null,this.requestCallbacks={},this.actionHandlers=new Map,this.pendingMessages=new Map,this.scriptLoadPromises=new Map,this.endpoint=n}return e.prototype.notify=function(e){var t,n,r,i;null===(n=null===(t=this.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Message sent: ",JSON.stringify(e)),null===(i=null===(r=window.opener)||void 0===r?void 0:r.postMessage)||void 0===i||i.call(r,e,this.endpoint)},e.prototype.sendRequest=function(e,t,n){var r=this;void 0===n&&(n={timeout:15e3});var i="".concat(Date.now(),"-").concat(Math.random().toString(36).substr(2,9)),o={id:i,action:e,args:t};return new Promise(function(t,s){r.requestCallbacks[i]={resolve:t,reject:s},r.notify(o),n.timeout>0&&setTimeout(function(){s(new Error("".concat(e," timed out (id: ").concat(i,")"))),delete r.requestCallbacks[i]},n.timeout)})},e.prototype.handleResponse=function(e){var t;this.requestCallbacks[e.id]?(this.requestCallbacks[e.id].resolve(e.responseData),delete this.requestCallbacks[e.id]):null===(t=this.logger)||void 0===t||t.warn("No callback found for request id: ".concat(e.id))},e.prototype.registerActionHandler=function(e,t){var n,r,i,o;this.actionHandlers.has(e)&&(null===(o=null===(i=this.logger)||void 0===i?void 0:i.warn)||void 0===o||o.call(i,"Overwriting existing action handler for: ".concat(e))),this.actionHandlers.set(e,t);var s=this.pendingMessages.get(e);if(s){this.pendingMessages.delete(e);try{for(var a=c(s),l=a.next();!l.done;l=a.next()){t(l.value)}}catch(e){n={error:e}}finally{try{l&&!l.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}}},e.prototype.loadScriptOnce=function(e){return a(this,void 0,void 0,function(){var t,n,r;return l(this,function(i){switch(i.label){case 0:if(t=this.scriptLoadPromises.get(e))return[2,t];n=function(e){return document.querySelector('script[src="'.concat(CSS.escape(e),'"]'))?Promise.resolve({status:!0}):new Promise(function(t,n){var r;try{var i=document.createElement("script");i.type="text/javascript",i.async=!0,i.src=e,i.addEventListener("load",function(){t({status:!0})},{once:!0}),i.addEventListener("error",function(){n({status:!1,message:"Failed to load the script ".concat(e)})}),null===(r=document.head)||void 0===r||r.appendChild(i)}catch(e){n(e)}})}(e).then(function(){}),this.scriptLoadPromises.set(e,n),i.label=1;case 1:return i.trys.push([1,3,,4]),[4,n];case 2:return i.sent(),[3,4];case 3:throw r=i.sent(),this.scriptLoadPromises.delete(e),r;case 4:return[2]}})})},e.prototype.setup=function(e){var t,n,r=this,i=void 0===e?{}:e,o=i.logger,s=i.endpoint;o&&(this.logger=o),s&&this.endpoint===X&&(this.endpoint=s),this.isSetup||(this.isSetup=!0,null===(n=null===(t=this.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Setting up messenger"),this.messageHandler=function(e){var t,n,i,o,s;if(null===(n=null===(t=r.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Message received: ",JSON.stringify(e)),r.endpoint===e.origin){var a=e.data,l=null==a?void 0:a.action;if(l)if("id"in a&&a.id)null===(o=null===(i=r.logger)||void 0===i?void 0:i.debug)||void 0===o||o.call(i,"Received Response to previous request: ",JSON.stringify(e)),r.handleResponse(a);else{if("ping"===l)return void r.notify({action:"pong"});var c=r.actionHandlers.get(l);if(c)c(a.data);else{var u=null!==(s=r.pendingMessages.get(l))&&void 0!==s?s:[];u.push(a.data),r.pendingMessages.set(l,u)}}}},window.addEventListener("message",this.messageHandler),this.notify({action:"page-loaded"}))},e.prototype.destroy=function(){this.messageHandler&&(window.removeEventListener("message",this.messageHandler),this.messageHandler=null),this.isSetup=!1,this.actionHandlers.clear(),this.pendingMessages.clear(),this.requestCallbacks={},this.scriptLoadPromises.clear();var e=f();(null==e?void 0:e[ne])===this&&delete e[ne]},e}();function ie(e){var t,n=f(),r=null==n?void 0:n[ne];if("object"==typeof(t=r)&&null!==t&&te in t&&!0===t[te])return r;var i=new re(e);return n&&(n[ne]=i),i}Y=te;var oe=["desktop","tablet","mobile"],se="__AMPLITUDE_BACKGROUND_CAPTURE__";function ae(e,t){var n,r=e;if(!0!==r[se]){r[se]=!0;var i=null!==(n=null==t?void 0:t.scriptUrl)&&void 0!==n?n:"https://cdn.amplitude.com/libs/background-capture-1.1.0.js.gz",s=null,a=function(t,n){var r,i;"background-capture-complete"===t&&(null===(i=null===(r=e.logger)||void 0===r?void 0:r.debug)||void 0===i||i.call(r,"Background capture complete"),e.notify({action:"background-capture-complete",data:n}))};e.registerActionHandler("initialize-background-capture",function(t){var n,r;null===(r=null===(n=e.logger)||void 0===n?void 0:n.debug)||void 0===r||r.call(n,"Initializing background capture (external script)");var l=new URL(i,e.endpoint).toString(),c=t&&"object"==typeof t?function(e){if("string"==typeof e)return oe.includes(e)?e:void 0}(t.deviceMode):void 0;e.loadScriptOnce(l).then(function(){var t,n,r;null===(n=null===(t=e.logger)||void 0===t?void 0:t.debug)||void 0===n||n.call(t,"Background capture script loaded (external)"),s=null===(r=null===window||void 0===window?void 0:window.amplitudeBackgroundCapture)||void 0===r?void 0:r.call(window,o({messenger:e,onBackgroundCapture:a},void 0!==c?{initialDeviceMode:c}:{})),e.notify({action:"background-capture-loaded"})}).catch(function(){var t;null===(t=e.logger)||void 0===t||t.warn("Failed to initialize background capture")})}),e.registerActionHandler("close-background-capture",function(){var e;null===(e=null==s?void 0:s.close)||void 0===e||e.call(s),s=null})}}var le,ce="[Amplitude]",ue="".concat(ce," Session Replay ID"),de=G.US,he={enabled:!0},ve=1e3,ge="".concat(ce," Session Replay Debug"),fe="https://api-sr.amplitude.com/sessions/v2/track",pe="https://api-sr.eu.amplitude.com/sessions/v2/track",me="https://api-sr.stag2.amplitude.com/sessions/v2/track",ye=9e6,be=/payload.*exceed/i,Se=500,Ie=1e4,we=1024,Ce="X-Session-Replay-Event-Skipped",Ee="amplitude-sr-iframe";!function(e){e.GET_SR_PROPS="get-sr-props",e.DEBUG_INFO="debug-info",e.FETCH_REQUEST="fetch-request",e.METADATA="metadata",e.TARGETING_DECISION="targeting-decision",e.REPLAY_GATE_DECISION="replay-gate-decision"}(le||(le={}));var Pe=function(){function e(e){this.logger=e,this.log=this.getSafeMethod("log"),this.warn=this.getSafeMethod("warn"),this.error=this.getSafeMethod("error"),this.debug=this.getSafeMethod("debug")}return e.prototype.getSafeMethod=function(e){var t;if(!this.logger)return function(){};var n=this.logger[e];return"function"==typeof n?(null!==(t=n.__rrweb_original__)&&void 0!==t?t:n).bind(this.logger):function(){}},e.prototype.enable=function(e){this.logger.enable(e)},e.prototype.disable=function(){this.logger.disable()},e}(),ke="medium";var xe=new Map,Te=function(e){var t=xe.get(e);if(t)return t;var n="\0TRAIL\0",r="\0MID\0",i="\0DS\0",o="\0ST\0",s="\0QU\0",a=e;a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=a.replace(/\/\*\*$/,n)).replace(/\/\*\*\//g,r)).replace(/\*\*/g,i)).replace(/\*/g,o)).replace(/\?/g,s)).replace(/[.+^${}()|[\]\\]/g,"\\$&")).split(n).join("(/.*)?")).split(r).join("/(.*\\/)?")).split(i).join(".*")).split(o).join(".*")).split(s).join(".");var l=new RegExp("^".concat(a,"$"));return xe.set(e,l),l},Re=function(e,t,n){switch(t){case"light":if("input"!==e)return!1;var r=n?function(e){var t=e.type;return e.hasAttribute("data-rr-is-password")?"password":t?t.toLowerCase():null}(n):"";return!!r&&(!!["password","hidden","email","tel"].includes(r)||!!n.autocomplete.startsWith("cc-"));case"medium":return"input"===e;case"conservative":return!0;default:return Re(e,ke,n)}},Me=function(e,t){var n,r,i;if(e&&t.urlMaskLevels)try{for(var o=c(t.urlMaskLevels),s=o.next();!s.done;s=o.next()){var a=s.value;if(Te(a.match).test(e))return a.maskLevel}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}return null!==(i=t.defaultMaskLevel)&&void 0!==i?i:ke},Oe=function(e,t,n,r){var i,o;if(void 0===t&&(t={defaultMaskLevel:ke}),n){if(n.closest(".amp-mask, [data-amp-mask]"))return!0;var s=(null!==(i=t.maskSelector)&&void 0!==i?i:[]).some(function(e){return n.closest(e)});if(s)return!0;if(n.closest(".amp-unmask, [data-amp-unmask]"))return!1;var a=(null!==(o=t.unmaskSelector)&&void 0!==o?o:[]).some(function(e){return n.closest(e)});if(a)return!1}return Re(e,Me(r,t),n)},Fe=function(e,t,n){return function(r,i){return Oe(e,t,i,null==n?void 0:n())?r.replace(/[^\s]/g,"*"):r}},_e=function(e,t){return function(n,r,i){var o;if("style"===n)return r;if(!(null!==(o=null==e?void 0:e.maskAttributes)&&void 0!==o?o:[]).includes(n))return r;var s=["INPUT","SELECT","TEXTAREA"].includes(i.tagName)?"input":"text";return Oe(s,e,i,null==t?void 0:t())?r.replace(/[^\s]/g,"*"):r}},Le=function(e){var t=null==e?void 0:e.blockSelector;return d(d([],u("string"==typeof t?t?[t]:[]:null!=t?t:[]),!1),["[data-amp-block]"],!1).join(",")},De=function(e,t){var n,r;return e&&("conservative"===Me(t,e)||"conservative"===e.defaultMaskLevel||(null===(n=e.urlMaskLevels)||void 0===n?void 0:n.some(function(e){return"conservative"===e.maskLevel})))?"*":d(d([],u(null!==(r=null==e?void 0:e.maskSelector)&&void 0!==r?r:[]),!1),["[data-amp-mask]"],!1).join(",")};function Ae(e,t){return t||("STAGING"===e?me:"EU"===e?pe:fe)}var qe=function(){var e=f();return(null==e?void 0:e.location)?e.location.href:""},Ne=function(e,t){var n,r;try{for(var i=c(t),o=i.next();!o.done;o=i.next()){var s=o.value,a=Te(s.selector);if(a.test(e))return e.replace(a,s.replacement)}}catch(e){n={error:e}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}return e},Be=function(){return a(void 0,void 0,void 0,function(){var e,t,n,r,i,o,s;return l(this,function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),(e=f())?[4,e.navigator.storage.estimate()]:[3,2];case 1:return t=a.sent(),n=t.usage,r=t.quota,i=t.usageDetails,o=n?Math.round(n/we):0,s=n&&r?Math.round(1e3*(n/r+Number.EPSILON))/1e3:0,[2,{totalStorageSize:o,percentOfQuota:s,usageDetails:JSON.stringify(i)}];case 2:return[3,4];case 3:return a.sent(),[3,4];case 4:return[2,{totalStorageSize:0,percentOfQuota:0,usageDetails:""}]}})})},je=function(e){e.loggerProvider;var t=s(e,["loggerProvider"]),n=o(o({},t),{apiKey:"****".concat(e.apiKey.substring(e.apiKey.length-4))});return JSON.parse(JSON.stringify(n))},Ue=function(){return{flushMaxRetries:2,logLevel:C.Warn,loggerProvider:new T,transportProvider:new K}},We=function(e){function t(t,n){var r,i,s,a,l,c,h,v,g,f,p,m,y,b,S=this,I=Ue();(S=e.call(this,o(o({transportProvider:I.transportProvider,loggerProvider:new Pe(n.loggerProvider||I.loggerProvider)},n),{apiKey:t}))||this).flushMaxRetries=void 0!==n.flushMaxRetries&&n.flushMaxRetries<=I.flushMaxRetries?n.flushMaxRetries:I.flushMaxRetries,S.apiKey=t,S.sampleRate=n.sampleRate||0,S.semanticCapture=n.semanticCapture,S.semanticAnalyticsContext=n.semanticAnalyticsContext,S.serverZone=n.serverZone||de,S.configServerUrl=n.configServerUrl,S.trackServerUrl=n.trackServerUrl,S.shouldInlineStylesheet=n.shouldInlineStylesheet,S.inlineImages=n.inlineImages,S.version=n.version,S.performanceConfig=n.performanceConfig||he,S.storeType=null!==(r=n.storeType)&&void 0!==r?r:"memory",S.applyBackgroundColorToBlockedElements=null!==(i=n.applyBackgroundColorToBlockedElements)&&void 0!==i&&i,S.enableUrlChangePolling=null!==(s=n.enableUrlChangePolling)&&void 0!==s&&s,S.urlChangePollingInterval=null!==(a=n.urlChangePollingInterval)&&void 0!==a?a:ve,S.captureDocumentTitle=null!==(l=n.captureDocumentTitle)&&void 0!==l&&l,void 0!==n.fullSnapshotIntervalMs&&(S.fullSnapshotIntervalMs=n.fullSnapshotIntervalMs),void 0!==n.eagerFullSnapshotSend&&(S.eagerFullSnapshotSend=n.eagerFullSnapshotSend),S.captureFullSnapshotOnFocus=null!==(c=n.captureFullSnapshotOnFocus)&&void 0!==c&&c,void 0!==n.maxPersistedEventsSizeBytes&&(S.maxPersistedEventsSizeBytes=Ge(n.maxPersistedEventsSizeBytes,He,Ke,"maxPersistedEventsSizeBytes",S.loggerProvider)),void 0!==n.maxSingleEventSizeBytes&&(S.maxSingleEventSizeBytes=Ge(n.maxSingleEventSizeBytes,He,$e,"maxSingleEventSizeBytes",S.loggerProvider)),S.privacyConfig=o(o({},null!==(h=n.privacyConfig)&&void 0!==h?h:{}),{unmaskSelector:Array.from(new Set(d([".".concat("amp-unmask")],u(null!==(g=null===(v=n.privacyConfig)||void 0===v?void 0:v.unmaskSelector)&&void 0!==g?g:[]),!1)))}),n.interactionConfig&&(S.interactionConfig=n.interactionConfig,S.interactionConfig.ugcFilterRules&&function(e){if(!e.every(function(e){return"string"==typeof e.selector&&"string"==typeof e.replacement}))throw new Error("ugcFilterRules must be an array of objects with selector and replacement properties");if(!e.every(function(e){return"string"==typeof(t=e.selector)&&""!==t.trim()&&!!/^\/|^https?:\/\/[^\s]+$/.test(t);var t}))throw new Error("ugcFilterRules must be an array of objects with valid globs")}(S.interactionConfig.ugcFilterRules)),n.debugMode&&(S.debugMode=n.debugMode);var w=n;return S.useWebWorker=null===(m=null!==(f=n.useWebWorker)&&void 0!==f?f:null===(p=w.experimental)||void 0===p?void 0:p.useWebWorker)||void 0===m||m,S.enableTransportCompression=null===(y=n.enableTransportCompression)||void 0===y||y,S.sendTimeoutMs=n.sendTimeoutMs,S.captureAdoptedStyleSheets=null===(b=n.captureAdoptedStyleSheets)||void 0===b||b,n.crossOriginIframes&&(S.crossOriginIframes=n.crossOriginIframes),n.flushIntervalConfig?S.flushIntervalConfig=function(e,t){var n,r,i={};void 0!==e.minIntervalMs&&(!Number.isFinite(e.minIntervalMs)||e.minIntervalMs<ze?(t.warn("flushIntervalConfig.minIntervalMs ".concat(e.minIntervalMs," is below floor ").concat(ze,"ms; clamping.")),i.minIntervalMs=ze):i.minIntervalMs=e.minIntervalMs);void 0!==e.maxIntervalMs&&(Number.isNaN(e.maxIntervalMs)||e.maxIntervalMs<ze?(t.warn("flushIntervalConfig.maxIntervalMs ".concat(e.maxIntervalMs," is below floor ").concat(ze,"ms; clamping.")),i.maxIntervalMs=ze):i.maxIntervalMs=e.maxIntervalMs);if(void 0!==i.minIntervalMs||void 0!==i.maxIntervalMs){var o=null!==(n=i.minIntervalMs)&&void 0!==n?n:Se,s=null!==(r=i.maxIntervalMs)&&void 0!==r?r:Ie;s<o&&(void 0===i.maxIntervalMs?(t.warn("flushIntervalConfig.minIntervalMs (".concat(o,") exceeds the default maxIntervalMs (").concat(Ie,"); raising max to match min.")),i.maxIntervalMs=o):void 0===i.minIntervalMs?(t.warn("flushIntervalConfig.maxIntervalMs (".concat(s,") is below the default minIntervalMs (").concat(Se,"); lowering min to match max.")),i.minIntervalMs=s):(t.warn("flushIntervalConfig.maxIntervalMs (".concat(i.maxIntervalMs,") is less than minIntervalMs (").concat(i.minIntervalMs,"); raising max to match min.")),i.maxIntervalMs=i.minIntervalMs))}return i}(n.flushIntervalConfig,S.loggerProvider):S.flushIntervalConfig={minIntervalMs:1e3,maxIntervalMs:1e4},S.handleSendEvents=n.handleSendEvents,S.handleFetchConfig=n.handleFetchConfig,S}return n(t,e),t}(O),ze=100,He=1e3,Ke=8e6,$e=1e7;function Ge(e,t,n,r,i){if(Number.isFinite(e))return e<t?(i.warn("".concat(r," ").concat(e," is below floor ").concat(t,"; clamping.")),t):e>n?(i.warn("".concat(r," ").concat(e," exceeds ceiling ").concat(n,"; clamping.")),n):e;i.warn("".concat(r," value is not a finite number (got ").concat(String(e),"); ignoring."))}var Qe=(e=>(e[e.DomContentLoaded=0]="DomContentLoaded",e[e.Load=1]="Load",e[e.FullSnapshot=2]="FullSnapshot",e[e.IncrementalSnapshot=3]="IncrementalSnapshot",e[e.Meta=4]="Meta",e[e.Custom=5]="Custom",e[e.Plugin=6]="Plugin",e))(Qe||{}),Je=(e=>(e[e.Mutation=0]="Mutation",e[e.MouseMove=1]="MouseMove",e[e.MouseInteraction=2]="MouseInteraction",e[e.Scroll=3]="Scroll",e[e.ViewportResize=4]="ViewportResize",e[e.Input=5]="Input",e[e.TouchMove=6]="TouchMove",e[e.MediaInteraction=7]="MediaInteraction",e[e.StyleSheetRule=8]="StyleSheetRule",e[e.CanvasMutation=9]="CanvasMutation",e[e.Font=10]="Font",e[e.Log=11]="Log",e[e.Drag=12]="Drag",e[e.StyleDeclaration=13]="StyleDeclaration",e[e.Selection=14]="Selection",e[e.AdoptedStyleSheet=15]="AdoptedStyleSheet",e[e.CustomElement=16]="CustomElement",e))(Je||{}),Ve=(e=>(e[e.MouseUp=0]="MouseUp",e[e.MouseDown=1]="MouseDown",e[e.Click=2]="Click",e[e.ContextMenu=3]="ContextMenu",e[e.DblClick=4]="DblClick",e[e.Focus=5]="Focus",e[e.Blur=6]="Blur",e[e.TouchStart=7]="TouchStart",e[e.TouchMove_Departed=8]="TouchMove_Departed",e[e.TouchEnd=9]="TouchEnd",e[e.TouchCancel=10]="TouchCancel",e))(Ve||{}),Ze=function(){function e(e,t){this.createCapture=e,this.ready=!1,this.pendingSnapshots=0,this.pendingUrls=0,this.pendingEvents=[],this.config={enabled:!1},this.capture=e(this.config,t)}return e.prototype.prepare=function(e,t){this.stop(),this.config=e,this.capture.updateConfig(e),this.sessionId!==t&&this.capture.resetSession(),this.sessionId=t},e.prototype.recordingReady=function(){var e,t;if(this.config.enabled&&!this.ready){this.ready=!0,this.capture.start();var n=this.pendingEvents;this.pendingEvents=[],this.pendingSnapshots=0,this.pendingUrls=0;try{for(var r=c(n),i=r.next();!i.done;i=r.next()){var o=i.value;"snapshot"===o.type?this.snapshot():this.url(o.url,o.timestamp)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}}},e.prototype.event=function(e){if(e.type===Qe.FullSnapshot&&this.snapshot(),e.type===Qe.Plugin&&"amplitude/url-tracking@1"===e.data.plugin){var t=e.data.payload;"url-change-event"===(null==t?void 0:t.type)&&"string"==typeof t.href&&this.url(t.href,e.timestamp)}},e.prototype.url=function(e,t){this.config.enabled&&(this.ready?this.capture.isActive()&&this.capture.notify("url",{url:e,timestamp:t}):this.pendingUrls<200&&(this.pendingUrls++,this.pendingEvents.push({type:"url",url:e,timestamp:t})))},e.prototype.snapshot=function(){this.config.enabled&&(this.ready?this.capture.isActive()&&this.capture.notify("snapshot",void 0):this.pendingSnapshots<200&&(this.pendingSnapshots++,this.pendingEvents.push({type:"snapshot"})))},e.prototype.stop=function(){this.ready=!1,this.pendingSnapshots=0,this.pendingUrls=0,this.pendingEvents=[],this.capture.stop()},e}(),Ye="AMP_semantic_tab_v1",Xe=new WeakMap,et=/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;var tt=function(e,t){var n=document.createDocumentFragment();return function(e,t,n){var r,i,s=o({},e);try{for(var a=c(["blockSelector","maskSelector","unmaskSelector"]),l=a.next();!l.done;l=a.next()){var u=l.value,d=e[u],h=("string"==typeof d?[d]:null!=d?d:[]).filter(function(e){try{return t(e),!0}catch(t){if(!n)throw new Error("Invalid privacy selector: ".concat(e));return n(e),!1}});s[u]=h.length?h:void 0}}catch(e){r={error:e}}finally{try{l&&!l.done&&(i=a.return)&&i.call(a)}finally{if(r)throw r.error}}return s}(e,function(e){n.querySelector(e)},function(e){t.warn('[session-replay-browser] omitting selector "'.concat(e,'" because it is invalid'))})},nt=function(){function e(e,t){this.localConfig=t,this.remoteConfigClient=e}return e.prototype.generateJoinedConfig=function(){var e,t,n,r,i,s,h,v;return a(this,void 0,void 0,function(){var a,g,f,p,m,y,b,S,I,w,C,E,P,k,x,T,R,M,O=this;return l(this,function(l){switch(l.label){case 0:(a=o({},this.localConfig)).optOut=this.localConfig.optOut,a.captureEnabled=!0,l.label=1;case 1:return l.trys.push([1,3,,4]),[4,new Promise(function(e,t){O.remoteConfigClient.subscribe("configs.sessionReplay",{timeout:1500},function(n,r){var i;if(O.localConfig.loggerProvider.debug("Session Replay remote configuration received from ".concat(r,":"),JSON.stringify(n,null,2)),n){var o=n,s=o.sr_sampling_config,l=o.sr_privacy_config,c=o.sr_targeting_config,u=o.sr_semantic_config,d=null===(i=a.interactionConfig)||void 0===i?void 0:i.ugcFilterRules;a.interactionConfig=o.sr_interaction_config,a.interactionConfig&&d&&(a.interactionConfig.ugcFilterRules=d),a.loggingConfig=o.sr_logging_config,(s||l||c||u)&&(g={},u&&(g.sr_semantic_config=u),s&&(g.sr_sampling_config=s),l&&(g.sr_privacy_config=l),c&&(g.sr_targeting_config=c)),e()}else t(new Error("No remote config received"))})})];case 2:return l.sent(),[3,4];case 3:return f=l.sent(),this.localConfig.loggerProvider.error("Failed to generate joined config: ",f),a.captureEnabled=!1,[2,{localConfig:this.localConfig,joinedConfig:a,remoteConfig:void 0}];case 4:if(!g)return[2,{localConfig:this.localConfig,joinedConfig:a,remoteConfig:g}];if(p=g.sr_sampling_config,m=g.sr_privacy_config,y=g.sr_targeting_config,(b=g.sr_semantic_config)&&(a.semanticCapture=o(o(o(o({enabled:!1},a.semanticCapture),void 0!==b.enabled?{enabled:b.enabled}:{}),void 0!==b.sampleRate?{sampleRate:this.sanitizeSemanticSampleRate(b.sampleRate)}:{}),{families:o(o({},null===(e=a.semanticCapture)||void 0===e?void 0:e.families),b.families)})),p&&Object.keys(p).length>0?(Object.prototype.hasOwnProperty.call(p,"capture_enabled")?a.captureEnabled=p.capture_enabled:a.captureEnabled=!1,Object.prototype.hasOwnProperty.call(p,"sample_rate")&&(a.sampleRate=p.sample_rate),Object.prototype.hasOwnProperty.call(p,"min_session_duration_ms")&&(a.minSessionDurationMs=this.sanitizeMinSessionDurationMs(p.min_session_duration_ms))):(a.captureEnabled=!0,this.localConfig.loggerProvider.debug("Remote config successfully fetched, but no values set for project, Session Replay capture enabled.")),m){S=null!==(t=a.privacyConfig)&&void 0!==t?t:{},I={defaultMaskLevel:null!==(r=null!==(n=m.defaultMaskLevel)&&void 0!==n?n:S.defaultMaskLevel)&&void 0!==r?r:"medium",blockSelector:[],maskSelector:[],unmaskSelector:[],maskAttributes:d([],u(new Set(d(d([],u(null!==(i=S.maskAttributes)&&void 0!==i?i:[]),!1),u(null!==(s=m.maskAttributes)&&void 0!==s?s:[]),!1))),!1),urlMaskLevels:d(d([],u(null!==(h=m.urlMaskLevels)&&void 0!==h?h:[]),!1),u(null!==(v=S.urlMaskLevels)&&void 0!==v?v:[]),!1)},w=function(e){var t,n,r,i,o,s,a,l,u,d={};"string"==typeof e.blockSelector&&(e.blockSelector=[e.blockSelector]);try{for(var h=c(null!==(a=e.blockSelector)&&void 0!==a?a:[]),v=h.next();!v.done;v=h.next()){d[v.value]="block"}}catch(e){t={error:e}}finally{try{v&&!v.done&&(n=h.return)&&n.call(h)}finally{if(t)throw t.error}}try{for(var g=c(null!==(l=e.maskSelector)&&void 0!==l?l:[]),f=g.next();!f.done;f=g.next()){d[f.value]="mask"}}catch(e){r={error:e}}finally{try{f&&!f.done&&(i=g.return)&&i.call(g)}finally{if(r)throw r.error}}try{for(var p=c(null!==(u=e.unmaskSelector)&&void 0!==u?u:[]),m=p.next();!m.done;m=p.next()){d[m.value]="unmask"}}catch(e){o={error:e}}finally{try{m&&!m.done&&(s=p.return)&&s.call(p)}finally{if(o)throw o.error}}return d},C=o(o({},w(S)),w(m));try{for(E=c(Object.entries(C)),P=E.next();!P.done;P=E.next())k=u(P.value,2),x=k[0],"mask"===(T=k[1])?I.maskSelector.push(x):"block"===T?I.blockSelector.push(x):"unmask"===T&&I.unmaskSelector.push(x)}catch(e){R={error:e}}finally{try{P&&!P.done&&(M=E.return)&&M.call(E)}finally{if(R)throw R.error}}a.privacyConfig=tt(I,this.localConfig.loggerProvider)}return y&&Object.keys(y).length>0&&(a.targetingConfig=y),this.localConfig.loggerProvider.debug(JSON.stringify({name:"session replay joined config",config:je(a)},null,2)),[2,{localConfig:this.localConfig,joinedConfig:a,remoteConfig:g}]}})})},e.prototype.sanitizeSemanticSampleRate=function(e){return"number"==typeof e&&Number.isFinite(e)&&e>=0&&e<=1?e:(this.localConfig.loggerProvider.warn("Invalid semantic sampleRate remote value (".concat(String(e),"); disabling capture.")),0)},e.prototype.sanitizeMinSessionDurationMs=function(e){if("number"==typeof e&&Number.isFinite(e)){if(!(e<0))return e>rt?(this.localConfig.loggerProvider.warn("min_session_duration_ms remote value ".concat(e," exceeds ").concat(rt,"ms ceiling; clamping.")),rt):e;this.localConfig.loggerProvider.warn("min_session_duration_ms remote value is negative (".concat(e,"); ignoring."))}else this.localConfig.loggerProvider.warn("min_session_duration_ms remote value is not a finite number (got ".concat(String(e),"); ignoring."))},e}(),rt=6e4,it=function(e,t){return a(void 0,void 0,void 0,function(){var n,r;return l(this,function(i){return n=new We(e,t),r=new Z(e,n.loggerProvider,n.serverZone,t.configServerUrl,t.handleFetchConfig),[2,new nt(r,n)]})})};function ot(e){for(var t=e.length,n=0;n<t&&!(e.charCodeAt(n)>127);n++);if(n===t)return t;for(var r=n;n<t;n++){var i=e.charCodeAt(n);if(i<=127)r++;else if(i<=2047)r+=2;else if(i>=55296&&i<=56319){var o=n+1<t?e.charCodeAt(n+1):NaN;o>=56320&&o<=57343?(r+=4,n++):r+=3}else r+=3}return r}function st(e){for(var t=0,n=0;n<e.length;n++)t+=ot(e[n]);return t}function at(e,t){if(!(3*e.length<=t)){var n=ot(e);return n>t?n:void 0}}function lt(e,t){t<0&&(t=0);for(var n=e.length,r=0,i=0;i<n;i++){var o=e.charCodeAt(i),s=1,a=1;if(o<=127)s=1;else if(o<=2047)s=2;else if(o>=55296&&o<=56319){var l=i+1<n?e.charCodeAt(i+1):NaN;l>=56320&&l<=57343?(s=4,a=2):s=3}else s=3;if(r+s>t)break;r+=s,2===a&&i++}return i>=n?{value:e,truncated:!1}:{value:e.slice(0,i),truncated:!0}}function ct(e){if(e.type!==Qe.IncrementalSnapshot)return!1;var t=e.data;return t.source===Je.Mutation&&!t.isAttachIframe}function ut(e){var t,n,r=new Map;if(e.forEach(function(e,t){if(e.attributes&&"style"in e.attributes){var n=r.get(e.id);n?n.push(t):r.set(e.id,[t])}}),0===r.size)return e;var i=function(t){return e[t].attributes.style},s=new Set,a=new Map,l=function(e){if(1===e.length)return"continue";var t=-1;e.forEach(function(e,n){var r;("object"!=typeof(r=i(e))||null===r)&&(t=n)});var n=[];if(e.forEach(function(e,r){r!==t&&(s.add(e),r>t&&n.push(e))}),n.length>0){var r=n[n.length-1],o=function(e){var t,n,r,i,o={};try{for(var s=c(e),a=s.next();!a.done;a=s.next()){var l=a.value;try{for(var u=(r=void 0,c(Object.keys(l))),d=u.next();!d.done;d=u.next()){var h=d.value;o[h]=l[h]}}catch(e){r={error:e}}finally{try{d&&!d.done&&(i=u.return)&&i.call(u)}finally{if(r)throw r.error}}}}catch(e){t={error:e}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}return o}(n.map(function(e){return i(e)}));s.delete(r),a.set(r,o)}};try{for(var u=c(r.values()),d=u.next();!d.done;d=u.next()){l(d.value)}}catch(e){t={error:e}}finally{try{d&&!d.done&&(n=u.return)&&n.call(u)}finally{if(t)throw t.error}}if(0===s.size&&0===a.size)return e;var h=[];return e.forEach(function(e,t){var n=a.get(t);if(void 0===n)if(s.has(t)){var r=o({},e.attributes);delete r.style,Object.keys(r).length>0&&h.push(o(o({},e),{attributes:r}))}else h.push(e);else h.push(o(o({},e),{attributes:o(o({},e.attributes),{style:n})}))}),h}function dt(e){var t,n,r,i,s=e[0],a=new Map,l=new Map,d=new Map,h=new Map,v=new Map;e.forEach(function(e,t){var n,r,i,o,s=e.data;try{for(var u=c(s.adds),g=u.next();!g.done;g=u.next()){var f=g.value;a.has(f.node.id)||a.set(f.node.id,t),l.set(f.node.id,t),v.set(f.node.id,f.parentId)}}catch(e){n={error:e}}finally{try{g&&!g.done&&(r=u.return)&&r.call(u)}finally{if(n)throw n.error}}try{for(var p=c(s.removes),m=p.next();!m.done;m=p.next()){var y=m.value;d.has(y.id)||d.set(y.id,t),h.set(y.id,t)}}catch(e){i={error:e}}finally{try{m&&!m.done&&(o=p.return)&&o.call(p)}finally{if(i)throw i.error}}});var g=new Set,f=new Set;try{for(var p=c(a),m=p.next();!m.done;m=p.next()){var y=u(m.value,2),b=y[0],S=y[1],I=d.get(b);if(void 0!==I)l.get(b)>=h.get(b)||(S<I?g.add(b):I<S&&f.add(b))}}catch(e){t={error:e}}finally{try{m&&!m.done&&(n=p.return)&&n.call(p)}finally{if(t)throw t.error}}var w=new Set;if(g.size>0||f.size>0)for(var C=!0;C;){C=!1;try{for(var E=(r=void 0,c(v)),P=E.next();!P.done;P=E.next()){var k=u(P.value,2),x=k[0],T=k[1];if(!g.has(x)&&!f.has(x)&&!w.has(x)&&(g.has(T)||f.has(T)||w.has(T))){var R=d.get(x),M=a.get(x);void 0!==R&&void 0!==M&&R<M?f.add(x):void 0!==R&&void 0!==M&&R===M?w.add(x):g.add(x),C=!0}}}catch(e){r={error:e}}finally{try{P&&!P.done&&(i=E.return)&&i.call(E)}finally{if(r)throw r.error}}}var O=g.size>0||f.size>0||w.size>0,F=[];e.forEach(function(e,t){var n,r;try{for(var i=c(e.data.removes),o=i.next();!o.done;o=i.next()){var s=o.value;g.has(s.id)||(f.has(s.id)&&t>=a.get(s.id)||w.has(s.id)&&(g.has(s.parentId)||f.has(s.parentId)||w.has(s.parentId))||F.push(s))}}catch(e){n={error:e}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}});var _=e.flatMap(function(e){return e.data.adds}),L=e.flatMap(function(e){return e.data.texts}),D=e.flatMap(function(e){return e.data.attributes}),A=O?D.filter(function(e){return!g.has(e.id)&&!f.has(e.id)&&!w.has(e.id)}):D,q={source:Je.Mutation,removes:F,adds:O?_.filter(function(e){return!g.has(e.node.id)&&!f.has(e.node.id)&&!w.has(e.node.id)}):_,texts:O?L.filter(function(e){return!g.has(e.id)&&!f.has(e.id)&&!w.has(e.id)}):L,attributes:ut(A)};return o(o({},s),{data:q})}function ht(e){if(e.length<=1)return e;for(var t=[],n=0;n<e.length;)if(ct(e[n])){for(var r=n+1;r<e.length&&ct(e[r]);)r++;t.push(r>n+1?dt(e.slice(n,r)):e[n]),n=r}else t.push(e[n]),n++;return t}var vt=function(){function e(e,t,n,r,i){var o,s=this;this.taskQueue=[],this.pendingQueue=[],this.isProcessing=!1,this.compressEvent=function(e){var t=e,n=t.type,r=t.timestamp,i=t.delay,o=t.data;return null!=i?JSON.stringify({type:n,timestamp:r,delay:i,data:o}):JSON.stringify({type:n,timestamp:r,data:o})},this.addCompressedEventToManager=function(e,t){var n,r=at(e,null!==(n=s.config.maxSingleEventSizeBytes)&&void 0!==n?n:ye);void 0===r?s.eventsManager&&s.deviceId&&s.eventsManager.addEvent({event:{type:"replay",data:e},sessionId:t,deviceId:s.deviceId}):s.config.loggerProvider.warn("Session replay event dropped: serialized size ".concat(Math.round(r/1024)," KB exceeds maximum allowed event size. If this recurs, please open a GitHub issue at https://github.com/amplitude/Amplitude-TypeScript/issues or contact Amplitude support."))},this.addCompressedEvent=function(e,t){if(s.worker)try{s.worker.postMessage({event:e,sessionId:t})}catch(n){"DataCloneError"===n.name?s.worker.postMessage(JSON.stringify({event:e,sessionId:t})):s.config.loggerProvider.warn("Unexpected error while posting message to worker:",n)}else{var n=s.compressEvent(e);s.addCompressedEventToManager(n,t)}},this.flushQueue=function(){var e;for(s.pendingQueue.length>0&&(e=s.taskQueue).push.apply(e,d([],u(s.mergeMutationTasks(s.pendingQueue.splice(0))),!1));s.taskQueue.length>0;){var t=s.taskQueue.shift();if(t){var n=t.event,r=t.sessionId,i=s.compressEvent(n);s.addCompressedEventToManager(i,r)}}s.isProcessing=!1},this.terminate=function(){var e;null===(e=s.worker)||void 0===e||e.terminate()};var a=f();if(this.canUseIdleCallback=a&&"requestIdleCallback"in a,this.eventsManager=e,this.config=t,this.deviceId=n,this.timeout=(null===(o=t.performanceConfig)||void 0===o?void 0:o.timeout)||2e3,this.onFullSnapshotProcessed=i,r){t.loggerProvider.log("Enabling web worker for compression");try{var l=new Blob([r],{type:"application/javascript"}),c=URL.createObjectURL(l),h=new Worker(c);h.onerror=function(e){e.preventDefault(),t.loggerProvider.error("Worker failed, falling back to non-worker compression: ".concat(e.message," (").concat(e.filename,":").concat(e.lineno,")")),h.terminate(),s.worker=void 0},h.onmessage=function(e){var t=e.data,n=t.compressedEvent,r=t.sessionId;s.addCompressedEventToManager(n,r)},this.worker=h}catch(e){t.loggerProvider.error("Failed to create worker, falling back to non-worker compression:",e)}}}return e.prototype.scheduleIdleProcessing=function(){var e=this;this.isProcessing||(this.isProcessing=!0,requestIdleCallback(function(t){e.processQueue(t)},{timeout:this.timeout}))},e.prototype.enqueueEvent=function(e,t){var n,r,i,o;if(e.type===Qe.FullSnapshot){if(this.config.loggerProvider.debug("Processing full snapshot immediately."),this.taskQueue.length>0||this.pendingQueue.length>0){var s=d(d([],u(this.taskQueue.splice(0)),!1),u(this.mergeMutationTasks(this.pendingQueue.splice(0))),!1);try{for(var a=c(s),l=a.next();!l.done;l=a.next()){var h=l.value,v=this.compressEvent(h.event);this.addCompressedEventToManager(v,h.sessionId)}}catch(e){n={error:e}}finally{try{l&&!l.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}this.isProcessing=!1}var g=this.compressEvent(e);return this.addCompressedEventToManager(g,t),void(null===(i=this.onFullSnapshotProcessed)||void 0===i||i.call(this))}this.canUseIdleCallback&&(null===(o=this.config.performanceConfig)||void 0===o?void 0:o.enabled)?(this.config.loggerProvider.debug("Enqueuing event for processing during idle time."),this.pendingQueue.push({event:e,sessionId:t}),this.scheduleIdleProcessing()):(this.config.loggerProvider.debug("Processing event without idle callback."),this.addCompressedEvent(e,t))},e.prototype.processQueue=function(e){var t,n=this;for(this.pendingQueue.length>0&&(t=this.taskQueue).push.apply(t,d([],u(this.mergeMutationTasks(this.pendingQueue.splice(0))),!1));this.taskQueue.length>0&&(e.timeRemaining()>0||e.didTimeout);){var r=this.taskQueue.shift();if(r){var i=r.event,o=r.sessionId;this.addCompressedEvent(i,o)}}this.taskQueue.length>0||this.pendingQueue.length>0?requestIdleCallback(function(e){n.processQueue(e)},{timeout:this.timeout}):this.isProcessing=!1},e.prototype.mergeMutationTasks=function(e){var t,n,r;if(!1===(null===(r=this.config.performanceConfig)||void 0===r?void 0:r.mergeMutations))return e;if(e.length<=1)return e;for(var i=[],o=0;o<e.length;){for(var s=e[o].sessionId,a=o+1;a<e.length&&e[a].sessionId===s;)a++;var l=ht(e.slice(o,a).map(function(e){return e.event}));try{for(var u=(t=void 0,c(l)),d=u.next();!d.done;d=u.next()){var h=d.value;i.push({event:h,sessionId:s})}}catch(e){t={error:e}}finally{try{d&&!d.done&&(n=u.return)&&n.call(u)}finally{if(t)throw t.error}}o=a}return i},e}(),gt="Session replay event batch rejected due to exceeded retry count",ft="Failed to store session replay events in IndexedDB",pt="Session replay event batch dropped: server signalled capture disabled or session out of valid range for this session",mt="1.53.0";function yt(e,t){return a(this,void 0,void 0,function(){var n,r,i,o,s,u,d,h,v,g,f,p,m,y,b=this;return l(this,function(S){switch(S.label){case 0:return S.trys.push([0,4,,5]),n=t.CompressionStream,r=new n("gzip"),i=r.writable.getWriter(),o=r.readable.getReader(),s=[],u=a(b,void 0,void 0,function(){var e,t,n;return l(this,function(r){switch(r.label){case 0:return[4,o.read()];case 1:if(e=r.sent(),t=e.done,n=e.value,t)return[3,3];s.push(n),r.label=2;case 2:return[3,0];case 3:return[2]}})}),[4,i.write((new TextEncoder).encode(e))];case 1:return S.sent(),[4,i.close()];case 2:return S.sent(),[4,u];case 3:S.sent(),d=s.reduce(function(e,t){return e+t.length},0),h=new Uint8Array(d),v=0;try{for(g=c(s),f=g.next();!f.done;f=g.next())p=f.value,h.set(p,v),v+=p.length}catch(e){m={error:e}}finally{try{f&&!f.done&&(y=g.return)&&y.call(g)}finally{if(m)throw m.error}}return[2,h];case 4:return S.sent(),[2,null];case 5:return[2]}})})}var bt=function(){function e(e){var t=e.trackServerUrl,n=e.loggerProvider,r=e.payloadBatcher,i=e.workerScript,o=e.enableTransportCompression,s=e.sendTimeoutMs,a=e.handleSendEvents,l=this;if(this.storageKey="",this.retryTimeout=1e3,this.scheduled=null,this.queue=[],this.sendIdCounter=0,this.pendingWorkerRequests=new Map,this.timedOutWorkerRequests=new Map,this.flushPauseUntilMs=0,this.mergeOnNextFlush=!1,this.coalesceNextFlush=!1,this.mergeLogFiredThisPause=!1,this.killedSessions=new Set,this.loggerProvider=n,this.payloadBatcher=r||function(e){return e},this.trackServerUrl=t,this.enableTransportCompression=null==o||o,this.sendTimeoutMs=null!=s?s:1e4,this.handleSendEvents=a,i)try{var d=new Blob([i],{type:"application/javascript"}),h=URL.createObjectURL(d),v=new Worker(h);v.onerror=function(e){var t,r;e.preventDefault(),n.error("Track destination worker failed, falling back to main-thread sending: ".concat(e.message," (").concat(e.filename,":").concat(e.lineno,")")),v.terminate(),l.worker=void 0;try{for(var i=c(l.pendingWorkerRequests),o=i.next();!o.done;o=i.next()){var s=u(o.value,2)[1];s.timeout&&clearTimeout(s.timeout),n.warn("Session replay event send failed due to worker crash: ".concat(e.message)),s.resolve()}}catch(e){t={error:e}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(t)throw t.error}}l.pendingWorkerRequests.clear(),l.timedOutWorkerRequests.clear()},v.onmessage=function(e){var t=e.data;if("log"===t.type)n.log(t.message);else if("warn"===t.type)n.warn(t.message);else if("payload_too_large"===t.type){var r=l.pendingWorkerRequests.get(t.id);if(r)r.timeout&&clearTimeout(r.timeout),l.handlePayloadTooLargeResponse(r.context,t.isWaf),r.resolve(),l.pendingWorkerRequests.delete(t.id);else(i=l.timedOutWorkerRequests.get(t.id))&&(l.timedOutWorkerRequests.delete(t.id),l.handlePayloadTooLargeResponse(i,t.isWaf))}else if("complete"===t.type){var i,o=l.pendingWorkerRequests.get(t.id);if(o)o.timeout&&clearTimeout(o.timeout),void 0!==t.skipCode&&l.applyServerDirective(o.context.sessionId,t.skipCode),l.completeRequest({context:o.context}),o.resolve(),l.pendingWorkerRequests.delete(t.id);else(i=l.timedOutWorkerRequests.get(t.id))&&(l.timedOutWorkerRequests.delete(t.id),void 0!==t.skipCode&&l.applyServerDirective(i.sessionId,t.skipCode),l.completeRequest({context:i}))}else"fetch-request"===t.type&&l.handleDelegatedFetch(v,t).catch(function(e){n.warn("Failed to handle delegated session replay fetch:",e)})},this.worker=v}catch(e){n.error("Failed to create track destination worker, falling back to main-thread sending:",e)}}return e.prototype.sendEventsList=function(e){this.addToQueue(o(o({},e),{attempts:0,timeout:0}))},e.prototype.markCoalesceNextFlush=function(){this.coalesceNextFlush=!0,this.schedule(0)},e.prototype.sendBeacon=function(e){var t,n,r=this,i=e.events,o=e.sessionId,s=e.deviceId,a=e.apiKey,l=e.serverZone,c=function(e){return ot(e)},u=i,d=JSON.stringify({version:2,events:u});if(c(d)>65536){for(var h=0,v=u.length;h<v;){var g=Math.floor((h+v+1)/2);c(JSON.stringify({version:2,events:u.slice(0,g)}))<=65536?h=g:v=g-1}u=u.slice(0,h),d=JSON.stringify({version:2,events:u}),this.loggerProvider.warn("sendBeacon payload exceeded 64 KB limit, trimmed from ".concat(i.length," to ").concat(u.length," events"))}if(0!==u.length)if(this.handleSendEvents){var p=new URLSearchParams({device_id:s,session_id:String(o),type:"replay"}),m="".concat(Ae(l,this.trackServerUrl),"?").concat(p.toString()),y={"Content-Type":"application/json",Accept:"*/*",Authorization:"Bearer ".concat(a)};this.loggerProvider.debug("Routing session replay exit batch (".concat(u.length," events) through custom transport for session id ").concat(o,"."));try{this.handleSendEvents({url:m,method:"POST",headers:y,body:d,keepalive:!0}).catch(function(e){r.loggerProvider.warn("Custom transport failed to send session replay exit batch:",e)})}catch(e){this.loggerProvider.warn("Custom transport threw while sending session replay exit batch:",e)}}else{var b=new URLSearchParams({device_id:s,session_id:String(o),type:"replay",api_key:a}),S="".concat(Ae(l,this.trackServerUrl),"?").concat(b.toString()),I=f();try{var w=new Blob([d],{type:"application/json"});!1===(null===(n=null===(t=null==I?void 0:I.navigator)||void 0===t?void 0:t.sendBeacon)||void 0===n?void 0:n.call(t,S,w))&&this.loggerProvider.warn("sendBeacon failed to queue session replay payload")}catch(e){}}},e.prototype.addToQueue=function(){for(var e=this,t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];t.filter(function(t){return e.killedSessions.has(t.sessionId)?(e.completeRequest({context:t,err:pt}),!1):t.attempts<(t.flushMaxRetries||0)?(t.attempts+=1,!0):(e.completeRequest({context:t,err:gt}),!1)}).forEach(function(t){e.queue=e.queue.concat(t),e.schedule(0)})},e.prototype.schedule=function(e){var t=this;if(!this.scheduled){var n=this.flushPauseUntilMs-Date.now(),r=n>e?n:e;n>0&&(this.mergeOnNextFlush=!0),this.scheduled=setTimeout(function(){t.flush(!0).then(function(){t.queue.length>0&&t.schedule(e)})},r)}},e.prototype.flush=function(e){return void 0===e&&(e=!1),a(this,void 0,void 0,function(){var t,n,r,i,o,s,a;return l(this,function(l){switch(l.label){case 0:t=this.queue,this.queue=[],this.scheduled&&(clearTimeout(this.scheduled),this.scheduled=null),this.mergeOnNextFlush?(this.mergeOnNextFlush=!1,this.coalesceNextFlush=!1,t=this.mergeQueueAfterThrottle(t)):this.coalesceNextFlush&&(this.coalesceNextFlush=!1,t=this.mergeDrainBacklog(t)),l.label=1;case 1:l.trys.push([1,6,7,8]),n=c(t),r=n.next(),l.label=2;case 2:return r.done?[3,5]:(i=r.value,[4,this.send(i,e)]);case 3:l.sent(),l.label=4;case 4:return r=n.next(),[3,2];case 5:return[3,8];case 6:return o=l.sent(),s={error:o},[3,8];case 7:try{r&&!r.done&&(a=n.return)&&a.call(n)}finally{if(s)throw s.error}return[7];case 8:return[2]}})})},e.prototype.mergeQueueAfterThrottle=function(e){var t=this.coalesceByIdentity(e);return t.length<e.length&&!this.mergeLogFiredThisPause&&(this.mergeLogFiredThisPause=!0,this.loggerProvider.log("Session replay throttle pause ended; merged ".concat(e.length," queued batches into ").concat(t.length," request(s)"))),t},e.prototype.mergeDrainBacklog=function(e){var t=this.coalesceByIdentity(e);return t.length<e.length&&this.loggerProvider.log("Session replay coalesced ".concat(e.length," persisted page-load backlog batches into ").concat(t.length," request(s)")),t},e.prototype.coalesceByIdentity=function(e){var t,n,r,i,s,h,v,g,f,p,m,y=this;if(e.length<=1)return e;var b=new Map;try{for(var S=c(e),I=S.next();!I.done;I=S.next()){var w=I.value,C=[w.sessionId,null!==(s=w.deviceId)&&void 0!==s?s:"",null!==(h=w.apiKey)&&void 0!==h?h:"",w.type,null!==(v=w.serverZone)&&void 0!==v?v:"",w.sampleRate,null!==(f=null===(g=w.version)||void 0===g?void 0:g.type)&&void 0!==f?f:"",null!==(m=null===(p=w.version)||void 0===p?void 0:p.version)&&void 0!==m?m:""].join("|"),E=b.get(C);E?E.push(w):b.set(C,[w])}}catch(e){t={error:e}}finally{try{I&&!I.done&&(n=S.return)&&n.call(S)}finally{if(t)throw t.error}}var P=[],k=function(e){var t,n;if(1===e.length)return P.push(e[0]),"continue";var r=null,i=0,s=function(){r&&P.push(r),r=null,i=0},h=function(e){var t=st(e.events);if(null===r)return r=o(o({},e),{events:d([],u(e.events),!1),attempts:0}),i=t,"continue";if(i+t>4e6)return s(),r=o(o({},e),{events:d([],u(e.events),!1),attempts:0}),i=t,"continue";var n=r.onComplete,c=e.onComplete;r.events=r.events.concat(e.events),i+=t,r.onComplete=function(){return a(y,void 0,void 0,function(){return l(this,function(e){switch(e.label){case 0:return[4,Promise.allSettled([n(),c()])];case 1:return e.sent(),[2]}})})}};try{for(var v=(t=void 0,c(e)),g=v.next();!g.done;g=v.next()){h(g.value)}}catch(e){t={error:e}}finally{try{g&&!g.done&&(n=v.return)&&n.call(v)}finally{if(t)throw t.error}}s()};try{for(var x=c(b.values()),T=x.next();!T.done;T=x.next()){k(T.value)}}catch(e){r={error:e}}finally{try{T&&!T.done&&(i=x.return)&&i.call(x)}finally{if(r)throw r.error}}return P},e.prototype.send=function(e,t){return void 0===t&&(t=!0),a(this,void 0,void 0,function(){var n,r,i,o;return l(this,function(s){return this.killedSessions.has(e.sessionId)?[2,this.completeRequest({context:e,err:pt})]:(n=e.apiKey)?(r=e.deviceId)?0===(i=this.payloadBatcher({version:1,events:e.events})).events.length?(this.completeRequest({context:e}),[2]):(o=this.worker)?[2,this.sendViaWorker(o,e,i,t)]:[2,this.sendOnMainThread(n,r,e,i,t)]:[2,this.completeRequest({context:e,err:"Session replay event batch not sent due to missing device ID"})]:[2,this.completeRequest({context:e,err:"Session replay event batch not sent due to missing api key"})]})})},e.prototype.sendViaWorker=function(e,t,n,r){return a(this,void 0,void 0,function(){var i,o=this;return l(this,function(s){return i="".concat(++this.sendIdCounter),[2,new Promise(function(s){var a,l=o.sendTimeoutMs>0?setTimeout(function(){var e=o.pendingWorkerRequests.get(i);e&&(o.pendingWorkerRequests.delete(i),o.rememberTimedOutRequest(i,e.context),o.loggerProvider.warn("Session replay worker send timed out after ".concat(o.sendTimeoutMs,"ms; leaving events for retry")),e.resolve())},o.sendTimeoutMs):void 0;o.pendingWorkerRequests.set(i,{context:t,resolve:s,timeout:l}),e.postMessage({type:"send",id:i,payload:n,useRetry:r,useCustomTransport:!!o.handleSendEvents,context:{apiKey:t.apiKey,deviceId:t.deviceId,sessionId:t.sessionId,events:t.events,eventType:t.type,flushMaxRetries:null!==(a=t.flushMaxRetries)&&void 0!==a?a:0,sampleRate:t.sampleRate,serverZone:t.serverZone,trackServerUrl:o.trackServerUrl,version:t.version,currentUrl:qe(),sdkVersion:mt,enableTransportCompression:o.enableTransportCompression,sendTimeoutMs:o.sendTimeoutMs}})})]})})},e.prototype.rememberTimedOutRequest=function(e,t){var n,r;if(this.timedOutWorkerRequests.set(e,t),this.timedOutWorkerRequests.size>256)try{for(var i=c(this.timedOutWorkerRequests.keys()),o=i.next();!o.done;o=i.next()){var s=o.value;this.timedOutWorkerRequests.delete(s);break}}catch(e){n={error:e}}finally{try{o&&!o.done&&(r=i.return)&&r.call(i)}finally{if(n)throw n.error}}},e.prototype.handleDelegatedFetch=function(e,t){var n,r,i;return a(this,void 0,void 0,function(){var o,s,a,c,u,d,h,v,g,f,p;return l(this,function(l){switch(l.label){case 0:o=t.requestId,s=t.url,a=t.method,c=t.headers,u=t.body,d=t.keepalive,l.label=1;case 1:return l.trys.push([1,10,,11]),h=void 0,this.handleSendEvents?[4,this.handleSendEvents({url:s,method:a,headers:c,body:u,keepalive:d})]:[3,3];case 2:return h=l.sent(),[3,5];case 3:return this.loggerProvider.warn("Delegated session replay fetch received without a custom transport configured; falling back to built-in fetch."),[4,fetch(s,{method:a,headers:c,body:u,keepalive:d})];case 4:h=l.sent(),l.label=5;case 5:if(v=h.status,g=null,f="",v>=200&&v<300&&(g=null!==(i=null===(r=null===(n=h.headers)||void 0===n?void 0:n.get)||void 0===r?void 0:r.call(n,Ce))&&void 0!==i?i:null),413!==v)return[3,9];l.label=6;case 6:return l.trys.push([6,8,,9]),[4,h.text()];case 7:return f=l.sent(),[3,9];case 8:return l.sent(),[3,9];case 9:return this.loggerProvider.debug("Delegated session replay fetch (request ".concat(o,") returned status ").concat(v,".")),e.postMessage({type:"fetch-response",requestId:o,status:v,skipHeader:g,body:f}),[3,11];case 10:return p=l.sent(),this.loggerProvider.debug("Delegated session replay fetch (request ".concat(o,") failed:"),p),e.postMessage({type:"fetch-response",requestId:o,status:0,skipHeader:null,body:String(p),error:!0}),[3,11];case 11:return[2]}})})},e.prototype.sendOnMainThread=function(e,t,n,r,i){var s,c,u,d,h,v,g;return a(this,void 0,void 0,function(){var a,p,m,y,b,S,I,w,C,E,P,k,x,T,R,M,O,F,_,L,D,A;return l(this,function(l){switch(l.label){case 0:a=qe(),p=mt,m=n.sampleRate,y=new URLSearchParams({device_id:t,session_id:"".concat(n.sessionId),type:"".concat(n.type)}),b="".concat(null!==(c=null===(s=n.version)||void 0===s?void 0:s.type)&&void 0!==c?c:"standalone","/").concat(null!==(d=null===(u=n.version)||void 0===u?void 0:u.version)&&void 0!==d?d:p),l.label=1;case 1:return l.trys.push([1,19,,23]),S=JSON.stringify(r),I=f(),this.enableTransportCompression&&I&&"CompressionStream"in I?[4,yt(S,I)]:[3,3];case 2:return C=l.sent(),[3,4];case 3:C=null,l.label=4;case 4:if(E=(w=C)?w.byteLength:ot(S),P=new AbortController,k=o({"Content-Type":"application/json",Accept:"*/*",Authorization:"Bearer ".concat(e),"X-Client-Version":p,"X-Client-Library":b,"X-Client-Url":a.substring(0,1e3),"X-Client-Sample-Rate":"".concat(m),"X-Sampling-Hash-Alg":"xxhash32"},w?{"Content-Encoding":"gzip"}:{}),R={headers:k,body:x=null!=w?w:S,method:"POST",keepalive:T=E<=65536,signal:P.signal},M="".concat(Ae(n.serverZone,this.trackServerUrl),"?").concat(y.toString()),0===r.events.length)return this.completeRequest({context:n}),[2];O=this.sendTimeoutMs>0?setTimeout(function(){P.abort()},this.sendTimeoutMs):void 0,F=void 0,l.label=5;case 5:return l.trys.push([5,,10,11]),this.handleSendEvents?[4,(q=this.handleSendEvents({url:M,method:"POST",headers:k,body:x,keepalive:T}),N=P.signal,new Promise(function(e,t){var n=function(){var e=new Error("Custom session replay transport aborted by send timeout");e.name="AbortError",t(e)};N.addEventListener("abort",n,{once:!0}),q.then(function(t){N.removeEventListener("abort",n),e(t)},function(e){N.removeEventListener("abort",n),t(e)})}))]:[3,7];case 6:return _=l.sent(),[3,9];case 7:return[4,fetch(M,R)];case 8:_=l.sent(),l.label=9;case 9:return F=_,[3,11];case 10:return O&&clearTimeout(O),[7];case 11:if(null===F)return this.completeRequest({context:n,err:"Unexpected error occurred"}),[2];if(F.status>=200&&F.status<300&&(L=null!==(g=null===(v=null===(h=F.headers)||void 0===h?void 0:h.get)||void 0===v?void 0:v.call(h,Ce))&&void 0!==g?g:null,this.applyServerDirective(n.sessionId,L)),i)return[3,12];D="";try{D=JSON.stringify(F.body,null,2)}catch(e){}return this.completeRequest({context:n,success:"".concat(F.status,": ").concat(D)}),[3,18];case 12:if(D="",413!==F.status)return[3,16];l.label=13;case 13:return l.trys.push([13,15,,16]),[4,F.text()];case 14:return D=l.sent(),[3,16];case 15:return l.sent(),[3,16];case 16:return[4,this.handleReponse(F.status,n,D)];case 17:l.sent(),l.label=18;case 18:return[3,23];case 19:return A=l.sent(),!!A&&"object"==typeof A&&"AbortError"===A.name&&i?[4,this.handleOtherResponse(n)]:[3,21];case 20:return l.sent(),[3,22];case 21:this.completeRequest({context:n,err:A}),l.label=22;case 22:return[3,23];case 23:return[2]}var q,N})})},e.prototype.handleReponse=function(e,t,n){return void 0===n&&(n=""),a(this,void 0,void 0,function(){var r;return l(this,function(i){switch(i.label){case 0:switch(r=(new H).buildStatus(e),r){case h.Success:return[3,1];case h.Failed:case h.Timeout:case h.RateLimit:return[3,2];case h.PayloadTooLarge:return[3,4]}return[3,5];case 1:return this.handleSuccessResponse(t),[3,8];case 2:return[4,this.handleOtherResponse(t)];case 3:return i.sent(),[3,8];case 4:return this.handlePayloadTooLargeResponse(t,be.test(n)),[3,8];case 5:return 499!==e?[3,7]:[4,this.handleOtherResponse(t)];case 6:return i.sent(),[3,8];case 7:this.completeRequest({context:t,err:"Network error occurred, event batch rejected"}),i.label=8;case 8:return[2]}})})},e.prototype.handlePayloadTooLargeResponse=function(e,t){var n=t?"WAF (compressed payload too large)":"server (event too large)",r=Math.round(e.events.reduce(function(e,t){return e+t.length},0)/we);if(t)if(1!==e.events.length){this.loggerProvider.warn("Session replay event batch rejected by ".concat(n," (").concat(e.events.length," events, ").concat(r," KB total) — splitting and retrying")),e.onComplete();var i=function(){return Promise.resolve()},s=Math.floor(e.events.length/2);this.sendEventsList(o(o({},e),{events:e.events.slice(0,s),onComplete:i})),this.sendEventsList(o(o({},e),{events:e.events.slice(s),onComplete:i}))}else this.completeRequest({context:e,err:"Session replay event dropped: single event (".concat(r," KB, 1 event) rejected by ").concat(n," — cannot split further")});else this.completeRequest({context:e,err:"Session replay event batch dropped: ".concat(n," rejected payload (").concat(e.events.length," events, ").concat(r," KB) — not retrying non-WAF 413")})},e.prototype.handleSuccessResponse=function(e){var t=Math.round(st(e.events)/we);this.completeRequest({context:e,success:"Session replay event batch tracked successfully for session id ".concat(e.sessionId,", size of events: ").concat(t," KB")})},e.prototype.handleOtherResponse=function(e){return a(this,void 0,void 0,function(){var t;return l(this,function(n){switch(n.label){case 0:return t=Math.random()*e.attempts*this.retryTimeout,e.attempts++,e.attempts>(e.flushMaxRetries||0)?(this.completeRequest({context:e,err:gt}),[2]):[4,new Promise(function(e){return setTimeout(e,t)})];case 1:return n.sent(),[4,this.send(e,!0)];case 2:return n.sent(),[2]}})})},e.prototype.completeRequest=function(e){var t=e.context,n=e.err,r=e.success;t.onComplete(),n?this.loggerProvider.warn(n):r&&this.loggerProvider.log(r)},e.prototype.applyServerDirective=function(e,t){if(null===t)return this.flushPauseUntilMs=0,void(this.mergeLogFiredThisPause=!1);if("429"===t){var n=this.flushPauseUntilMs>Date.now();return this.flushPauseUntilMs=Date.now()+6e4,void(n||this.loggerProvider.log("Session replay throttled by server; pausing flush schedule for ".concat(60,"s")))}"4005"!==t&&"4004"!==t||this.killSession(e,t)},e.prototype.killSession=function(e,t){var n,r,i,o;if(!this.killedSessions.has(e)){if(this.killedSessions.add(e),this.killedSessions.size>256)try{for(var s=c(this.killedSessions),a=s.next();!a.done;a=s.next()){var l=a.value;this.killedSessions.delete(l);break}}catch(e){n={error:e}}finally{try{a&&!a.done&&(r=s.return)&&r.call(s)}finally{if(n)throw n.error}}this.loggerProvider.log("Session replay capture stopped for session ".concat(e," by server directive ").concat(t,"; remaining events will be dropped"));var u=[];try{for(var d=c(this.queue),h=d.next();!h.done;h=d.next()){var v=h.value;v.sessionId===e?this.completeRequest({context:v,err:pt}):u.push(v)}}catch(e){i={error:e}}finally{try{h&&!h.done&&(o=d.return)&&o.call(d)}finally{if(i)throw i.error}}this.queue=u}},e}();const St=(e,t)=>t.some(t=>e instanceof t);let It,wt;const Ct=new WeakMap,Et=new WeakMap,Pt=new WeakMap;let kt={get(e,t,n){if(e instanceof IDBTransaction){if("done"===t)return Ct.get(e);if("store"===t)return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return Mt(e[t])},set:(e,t,n)=>(e[t]=n,!0),has:(e,t)=>e instanceof IDBTransaction&&("done"===t||"store"===t)||t in e};function xt(e){kt=e(kt)}function Tt(e){return(wt||(wt=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])).includes(e)?function(...t){return e.apply(Ot(this),t),Mt(this.request)}:function(...t){return Mt(e.apply(Ot(this),t))}}function Rt(e){return"function"==typeof e?Tt(e):(e instanceof IDBTransaction&&function(e){if(Ct.has(e))return;const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("complete",i),e.removeEventListener("error",o),e.removeEventListener("abort",o)},i=()=>{t(),r()},o=()=>{n(e.error||new DOMException("AbortError","AbortError")),r()};e.addEventListener("complete",i),e.addEventListener("error",o),e.addEventListener("abort",o)});Ct.set(e,t)}(e),St(e,It||(It=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction]))?new Proxy(e,kt):e)}function Mt(e){if(e instanceof IDBRequest)return function(e){const t=new Promise((t,n)=>{const r=()=>{e.removeEventListener("success",i),e.removeEventListener("error",o)},i=()=>{t(Mt(e.result)),r()},o=()=>{n(e.error),r()};e.addEventListener("success",i),e.addEventListener("error",o)});return Pt.set(t,e),t}(e);if(Et.has(e))return Et.get(e);const t=Rt(e);return t!==e&&(Et.set(e,t),Pt.set(t,e)),t}const Ot=e=>Pt.get(e);function Ft(e,t,{blocked:n,upgrade:r,blocking:i,terminated:o}={}){const s=indexedDB.open(e,t),a=Mt(s);return r&&s.addEventListener("upgradeneeded",e=>{r(Mt(s.result),e.oldVersion,e.newVersion,Mt(s.transaction),e)}),n&&s.addEventListener("blocked",e=>n(e.oldVersion,e.newVersion,e)),a.then(e=>{o&&e.addEventListener("close",()=>o()),i&&e.addEventListener("versionchange",e=>i(e.oldVersion,e.newVersion,e))}).catch(()=>{}),a}const _t=["get","getKey","getAll","getAllKeys","count"],Lt=["put","add","delete","clear"],Dt=new Map;function At(e,t){if(!(e instanceof IDBDatabase)||t in e||"string"!=typeof t)return;if(Dt.get(t))return Dt.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,i=Lt.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!i&&!_t.includes(n))return;const o=async function(e,...t){const o=this.transaction(e,i?"readwrite":"readonly");let s=o.store;return r&&(s=s.index(t.shift())),(await Promise.all([s[n](...t),i&&o.done]))[0]};return Dt.set(t,o),o}xt(e=>({...e,get:(t,n,r)=>At(t,n)||e.get(t,n,r),has:(t,n)=>!!At(t,n)||e.has(t,n)}));const qt=["continue","continuePrimaryKey","advance"],Nt={},Bt=new WeakMap,jt=new WeakMap,Ut={get(e,t){if(!qt.includes(t))return e[t];let n=Nt[t];return n||(n=Nt[t]=function(...e){Bt.set(this,jt.get(this)[t](...e))}),n}};async function*Wt(...e){let t=this;if(t instanceof IDBCursor||(t=await t.openCursor(...e)),!t)return;const n=new Proxy(t,Ut);for(jt.set(n,t),Pt.set(n,Ot(t));t;)yield n,t=await(Bt.get(n)||t.continue()),Bt.delete(n)}function zt(e,t){return t===Symbol.asyncIterator&&St(e,[IDBIndex,IDBObjectStore,IDBCursor])||"iterate"===t&&St(e,[IDBIndex,IDBObjectStore])}xt(e=>({...e,get:(t,n,r)=>zt(t,n)?Wt:e.get(t,n,r),has:(t,n)=>zt(t,n)||e.has(t,n)}));var Ht=function(){function e(e){var t,n,r,i=this;this.minInterval=Se,this.maxInterval=Ie,this.maxPersistedEventsSize=6e6,this._timeAtLastSplit=Date.now(),this.eventsContentBytes=new WeakMap,this.sequenceContentBytes=new Map,this.shouldSplitEventsList=function(e,t){var n=i.getEventsArraySize(e),r=i.maxPersistedEventsSize-n,o=t.length>=r;return!o&&3*t.length>=r&&(o=ot(t)>=r),!!o||!!(Date.now()-i.timeAtLastSplit>i.interval&&e.length)&&(i.interval=Math.min(i.maxInterval,i.interval+i.minInterval),i._timeAtLastSplit=Date.now(),!0)},this.loggerProvider=e.loggerProvider,this.minInterval=null!==(t=e.minInterval)&&void 0!==t?t:this.minInterval,this.maxInterval=null!==(n=e.maxInterval)&&void 0!==n?n:this.maxInterval,this.maxPersistedEventsSize=null!==(r=e.maxPersistedEventsSize)&&void 0!==r?r:this.maxPersistedEventsSize,this.interval=this.minInterval}return Object.defineProperty(e.prototype,"timeAtLastSplit",{get:function(){return this._timeAtLastSplit},enumerable:!1,configurable:!0}),e.prototype.isPrefixOf=function(e,t){return!(t.length<e.length)&&(0===e.length||t[e.length-1]===e.tail)},e.prototype.measureContentBytes=function(e,t){if(e&&e.length===t.length&&this.isPrefixOf(e,t))return e;var n=0,r=0;e&&this.isPrefixOf(e,t)&&(n=e.contentBytes,r=e.length);for(var i=r;i<t.length;i++)n+=ot(t[i]);return{length:t.length,contentBytes:n,tail:t.length>0?t[t.length-1]:void 0}},e.prototype.getEventsContentBytes=function(e){var t=this.measureContentBytes(this.eventsContentBytes.get(e),e);return this.eventsContentBytes.set(e,t),t.contentBytes},e.prototype.getEventsArraySize=function(e){return this.getEventsContentBytes(e)+(2+Math.max(0,e.length-1)+2*e.length)},e.prototype.recallSequenceContentBytes=function(e,t){var n=this.sequenceContentBytes.get(e);n&&n.length===t.length&&this.isPrefixOf(n,t)&&this.eventsContentBytes.set(t,n)},e.prototype.rememberSequenceContentBytes=function(e,t){var n=this.measureContentBytes(this.sequenceContentBytes.get(e),t);this.sequenceContentBytes.set(e,n),this.eventsContentBytes.set(t,n)},e.prototype.forgetSequenceContentBytes=function(e){this.sequenceContentBytes.delete(e)},e}(),Kt=function(e,t,n){var r;"object"==typeof(r=n)&&null!==r&&"AbortError"===r.name?e.debug(t):e.warn(t)};var $t="sessionCurrentSequence",Gt="sequencesToSend",Qt=5e3;function Jt(e,t,n){var r=setTimeout(n,t);return e.then(function(){return clearTimeout(r)},function(){return clearTimeout(r)}),function(){return clearTimeout(r)}}var Vt,Zt,Yt,Xt=function(e){var t,n;return e.objectStoreNames.contains($t)||(n=e.createObjectStore($t,{keyPath:"sessionId"})),e.objectStoreNames.contains(Gt)||(t=e.createObjectStore(Gt,{keyPath:"sequenceId",autoIncrement:!0})).createIndex("sessionId","sessionId"),{sequencesStore:t,currentSequenceStore:n}},en=function(e){return a(void 0,void 0,void 0,function(){return l(this,function(t){switch(t.label){case 0:return[4,(n=Ft(e,1,{upgrade:Xt}),r=2e3,i="IDB openDB timed out",void 0===i&&(i="IDB operation timed out"),new Promise(function(e,t){var o=setTimeout(function(){return t(new Error("".concat(i," after ").concat(r,"ms")))},r);n.then(function(t){clearTimeout(o),e(t)},function(e){clearTimeout(o),t(e)})}))];case 1:return[2,t.sent()]}var n,r,i})})},tn=function(e){function t(t){var n,r=this;return(r=e.call(this,t)||this).consecutiveFailures=0,r.hasTriggeredFallback=!1,r.emptyFilteredCount=0,r.getSequencesToSend=function(){return a(r,void 0,void 0,function(){var e,t,n,r,i,o,s,a,c,u,d=this;return l(this,function(l){switch(l.label){case 0:e=!1,t=!1,l.label=1;case 1:return l.trys.push([1,9,,10]),n=[],(r=this.db.transaction("sequencesToSend","readwrite")).done.catch(function(n){e||t||(Kt(d.loggerProvider,"".concat(ft,": ").concat(n),n),d.recordFailure())}),i=Jt(r.done,Qt,function(){e||t||(t=!0,Kt(d.loggerProvider,"".concat(ft,": transaction timed out")),d.recordFailure())}),[4,r.store.openCursor()];case 2:o=l.sent(),l.label=3;case 3:return o?(s=o.value,a=s.sessionId,0!==(c=s.events).length?[3,5]:(this.maybeLogEmptyFiltered("getSequencesToSend"),[4,o.delete()])):[3,8];case 4:return l.sent(),[3,6];case 5:n.push({events:c,sequenceId:o.key,sessionId:a}),l.label=6;case 6:return[4,o.continue()];case 7:return o=l.sent(),[3,3];case 8:return this.recordSuccess(),i(),[2,n];case 9:return u=l.sent(),t||(e=!0,Kt(this.loggerProvider,"".concat(ft,": ").concat(u),u),this.recordFailure()),[3,10];case 10:return[2,void 0]}})})},r.storeCurrentSequence=function(e){return a(r,void 0,void 0,function(){var t,n,r,i,a,c,u,d,h=this;return l(this,function(l){switch(l.label){case 0:t=!1,n=!1,l.label=1;case 1:return l.trys.push([1,5,,6]),(r=this.db.transaction([$t,Gt],"readwrite")).done.catch(function(e){t||n||(Kt(h.loggerProvider,"".concat(ft,": ").concat(e),e),h.recordFailure())}),i=Jt(r.done,Qt,function(){t||n||(n=!0,Kt(h.loggerProvider,"".concat(ft,": transaction timed out")),h.recordFailure())}),[4,r.objectStore($t).get(e)];case 2:return!(a=l.sent())||a.tabId&&a.tabId!==this.tabId?(i(),[2,void 0]):0===a.events.length?(this.maybeLogEmptyFiltered("storeCurrentSequence"),i(),[2,void 0]):[4,r.objectStore(Gt).put({sessionId:e,events:a.events,tabId:this.tabId})];case 3:return c=l.sent(),[4,r.objectStore($t).put({sessionId:e,events:[],tabId:this.tabId})];case 4:return l.sent(),this.rememberSequenceContentBytes(e,[]),this.recordSuccess(),i(),a.tabId,u=s(a,["tabId"]),[2,o(o({},u),{sessionId:e,sequenceId:c})];case 5:return d=l.sent(),this.forgetSequenceContentBytes(e),n||(t=!0,Kt(this.loggerProvider,"".concat(ft,": ").concat(d),d),this.recordFailure()),[3,6];case 6:return[2,void 0]}})})},r.addEventToCurrentSequence=function(e,t){return a(r,void 0,void 0,function(){var n,r,i,o,s,a,c,u,d,h,v,g,f,p,m=this;return l(this,function(l){switch(l.label){case 0:n=!1,r=!1,l.label=1;case 1:return l.trys.push([1,15,,16]),(i=this.db.transaction([$t,Gt],"readwrite")).done.catch(function(e){n||r||(Kt(m.loggerProvider,"".concat(ft,": ").concat(e),e),m.recordFailure())}),o=Jt(i.done,Qt,function(){n||r||(r=!0,Kt(m.loggerProvider,"".concat(ft,": transaction timed out")),m.recordFailure())}),[4,i.objectStore($t).get(e)];case 2:return(null==(s=l.sent())?void 0:s.tabId)&&s.tabId!==this.tabId?s.events.length>0?[4,i.objectStore(Gt).put({sessionId:e,events:s.events,tabId:s.tabId})]:[3,4]:[3,6];case 3:l.sent(),l.label=4;case 4:return a=[t],[4,i.objectStore($t).put({sessionId:e,events:a,tabId:this.tabId})];case 5:return l.sent(),this.rememberSequenceContentBytes(e,a),this.recordSuccess(),o(),[2,void 0];case 6:return(c=s)?[3,8]:(u=[t],[4,i.objectStore($t).put({sessionId:e,events:u,tabId:this.tabId})]);case 7:return l.sent(),this.rememberSequenceContentBytes(e,u),this.recordSuccess(),o(),[2,void 0];case 8:return this.recallSequenceContentBytes(e,c.events),this.shouldSplitEventsList(c.events,t)?[3,10]:(d=c.events.concat(t),[4,i.objectStore($t).put({sessionId:e,events:d,tabId:this.tabId})]);case 9:return l.sent(),this.rememberSequenceContentBytes(e,d),this.recordSuccess(),o(),[2,void 0];case 10:return 0!==(h=c.events).length?[3,12]:(this.maybeLogEmptyFiltered("addEventToCurrentSequence"),v=[t],[4,i.objectStore($t).put({sessionId:e,events:v,tabId:this.tabId})]);case 11:return l.sent(),this.rememberSequenceContentBytes(e,v),this.recordSuccess(),o(),[2,void 0];case 12:return g=[t],[4,i.objectStore($t).put({sessionId:e,events:g,tabId:this.tabId})];case 13:return l.sent(),this.rememberSequenceContentBytes(e,g),[4,i.objectStore(Gt).put({sessionId:e,events:h,tabId:this.tabId})];case 14:return f=l.sent(),this.recordSuccess(),o(),[2,{events:h,sessionId:e,sequenceId:f}];case 15:return p=l.sent(),this.forgetSequenceContentBytes(e),r||(n=!0,Kt(this.loggerProvider,"".concat(ft,": ").concat(p),p),this.recordFailure()),[3,16];case 16:return[2,void 0]}})})},r.storeSendingEvents=function(e,t){return a(r,void 0,void 0,function(){var n,r;return l(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.db.put(Gt,{sessionId:e,events:t,tabId:this.tabId})];case 1:return n=i.sent(),this.recordSuccess(),[2,n];case 2:return r=i.sent(),Kt(this.loggerProvider,"".concat(ft,": ").concat(r),r),this.recordFailure(),[3,3];case 3:return[2,void 0]}})})},r.cleanUpSessionEventsStore=function(e,t){return a(r,void 0,void 0,function(){var e;return l(this,function(n){switch(n.label){case 0:if(!t)return[2];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,this.db.delete(Gt,t)];case 2:return n.sent(),this.recordSuccess(),[3,4];case 3:return e=n.sent(),Kt(this.loggerProvider,"".concat(ft,": ").concat(e),e),this.recordFailure(),[3,4];case 4:return[2]}})})},r.db=t.db,r.tabId=t.tabId,r.onPersistentFailure=t.onPersistentFailure,r.consecutiveFailureThreshold=null!==(n=t.consecutiveFailureThreshold)&&void 0!==n?n:1,r}return n(t,e),t.prototype.maybeLogEmptyFiltered=function(e){this.emptyFilteredCount++%100==0&&this.loggerProvider.debug("Filtered empty session replay sequence at ".concat(e," (idb store)"))},t.prototype.recordFailure=function(){var e;this.consecutiveFailures++,!this.hasTriggeredFallback&&this.consecutiveFailures>=this.consecutiveFailureThreshold&&(this.hasTriggeredFallback=!0,null===(e=this.onPersistentFailure)||void 0===e||e.call(this))},t.prototype.recordSuccess=function(){this.consecutiveFailures=0},t.new=function(e,n){var r;return a(this,void 0,void 0,function(){var i,s,a,c,u;return l(this,function(l){switch(l.label){case 0:return l.trys.push([0,2,,3]),i="replay"===e?"":"_".concat(e),s="".concat(n.apiKey.substring(0,10),"_amp_session_replay_events").concat(i),[4,en(s)];case 1:return a=l.sent(),c=null!==(r=n.tabId)&&void 0!==r?r:function(){try{return crypto.randomUUID()}catch(e){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}}(),[2,new t(o(o({},n),{db:a,tabId:c}))];case 2:return u=l.sent(),Kt(n.loggerProvider,"".concat(ft,": ").concat(u),u),[3,3];case 3:return[2]}})})},t.prototype.getCurrentSequenceEvents=function(e){return a(this,void 0,void 0,function(){var t,n,r,i,o,a,u,d;return l(this,function(l){switch(l.label){case 0:return e?[4,this.db.get("sessionCurrentSequence",e)]:[3,2];case 1:return(i=l.sent())?i.tabId&&i.tabId!==this.tabId?[2,void 0]:(i.tabId,[2,[o=s(i,["tabId"])]]):[2,void 0];case 2:t=[],l.label=3;case 3:return l.trys.push([3,8,9,10]),[4,this.db.getAll("sessionCurrentSequence")];case 4:n=c.apply(void 0,[l.sent()]),r=n.next(),l.label=5;case 5:if(r.done)return[3,7];if((i=r.value).tabId&&i.tabId!==this.tabId)return[3,6];i.tabId,o=s(i,["tabId"]),t.push(o),l.label=6;case 6:return r=n.next(),[3,5];case 7:return[3,10];case 8:return a=l.sent(),u={error:a},[3,10];case 9:try{r&&!r.done&&(d=n.return)&&d.call(n)}finally{if(u)throw u.error}return[7];case 10:return[2,t]}})})},t}(Ht),nn=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.finalizedSequences={},t.sequences={},t.sequenceId=0,t.emptyFilteredCount=0,t}return n(t,e),t.prototype.resetCurrentSequence=function(e){this.sequences[e]=[]},t.prototype.addSequence=function(e){var t=this.sequenceId++,n=d([],u(this.sequences[e]),!1);return this.finalizedSequences[t]={sessionId:e,events:n},this.resetCurrentSequence(e),{sequenceId:t,events:n,sessionId:e}},t.prototype.maybeLogEmptyFiltered=function(e){this.emptyFilteredCount++%100==0&&this.loggerProvider.debug("Filtered empty session replay sequence at ".concat(e," (in-memory store)"))},t.prototype.getSequencesToSend=function(){return a(this,void 0,void 0,function(){var e,t,n,r,i,o,s,a,d,h;return l(this,function(l){e=[];try{for(t=c(Object.entries(this.finalizedSequences)),n=t.next();!n.done;n=t.next())r=u(n.value,2),i=r[0],o=r[1],s=o.sessionId,0!==(a=o.events).length?e.push({sequenceId:Number(i),sessionId:s,events:a}):(this.maybeLogEmptyFiltered("getSequencesToSend"),delete this.finalizedSequences[Number(i)])}catch(e){d={error:e}}finally{try{n&&!n.done&&(h=t.return)&&h.call(t)}finally{if(d)throw d.error}}return[2,e]})})},t.prototype.storeCurrentSequence=function(e){return a(this,void 0,void 0,function(){var t;return l(this,function(n){return(t=this.sequences[e])?0===t.length?(this.maybeLogEmptyFiltered("storeCurrentSequence"),[2,void 0]):[2,this.addSequence(e)]:[2,void 0]})})},t.prototype.addEventToCurrentSequence=function(e,t){return a(this,void 0,void 0,function(){var n;return l(this,function(r){return this.sequences[e]||this.resetCurrentSequence(e),this.shouldSplitEventsList(this.sequences[e],t)&&(0===this.sequences[e].length?this.maybeLogEmptyFiltered("addEventToCurrentSequence"):n=this.addSequence(e)),this.sequences[e].push(t),[2,n]})})},t.prototype.storeSendingEvents=function(e,t){return a(this,void 0,void 0,function(){return l(this,function(n){return this.finalizedSequences[this.sequenceId]={sessionId:e,events:t},[2,this.sequenceId++]})})},t.prototype.cleanUpSessionEventsStore=function(e,t){return a(this,void 0,void 0,function(){return l(this,function(e){return void 0!==t&&delete this.finalizedSequences[t],[2]})})},t}(Ht),rn=function(e){var t=e.config,n=e.minInterval,r=e.maxInterval,i=e.maxPersistedEventsSize,s=e.type,c=e.payloadBatcher,h=e.storeType,v=e.trackDestinationWorkerScript,g=e.shouldSend;return a(void 0,void 0,void 0,function(){function e(e){return void 0===e&&(e=!1),a(this,void 0,void 0,function(){return l(this,function(t){return[2,p.flush(e)]})})}var f,p,m,y,b,S,I,w,C,E,P,k,x,T,R,M,O;return l(this,function(F){switch(F.label){case 0:return f=null!==(O=t.maxSingleEventSizeBytes)&&void 0!==O?O:ye,p=new bt(o(o({},t),{loggerProvider:t.loggerProvider,payloadBatcher:c,workerScript:v})),m=function(){return new nn({loggerProvider:t.loggerProvider,maxInterval:r,minInterval:n,maxPersistedEventsSize:i})},b=!1,I=function(){return a(void 0,void 0,void 0,function(){var e,n,r;return l(this,function(i){switch(i.label){case 0:return b?(b=!1,t.loggerProvider.warn("IDB store is experiencing repeated failures; falling back to in-memory event store."),y?[4,S.getSequencesToSend()]:[3,2]):[2];case 1:return n=i.sent(),[3,3];case 2:n=void 0,i.label=3;case 3:return e=n,S=m(),e&&y&&(r=y,e.forEach(function(e){x({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:r})})),[2]}})})},w=function(){return a(void 0,void 0,void 0,function(){var e;return l(this,function(o){switch(o.label){case 0:return[4,tn.new(s,{loggerProvider:t.loggerProvider,minInterval:n,maxInterval:r,maxPersistedEventsSize:i,apiKey:t.apiKey,onPersistentFailure:function(){I()}})];case 1:return(e=o.sent())?(b=!0,[2,e]):(t.loggerProvider.log("Failed to initialize idb store, falling back to memory store."),[2,m()])}})})},"idb"!==h?[3,2]:[4,w()];case 1:return C=F.sent(),[3,3];case 2:C=m(),F.label=3;case 3:return S=C,E=[],P=0,k=function(e){if(!(e<=P)){var t=Math.min(e-P,E.length);t>0&&(E.splice(0,t),P=e)}},x=function(e){for(var n=e.events,r=e.sessionId,i=e.deviceId,o=e.sequenceId,c=n,u=[],d=0;d<n.length;d++){var h=at(n[d],f);void 0!==h?(0===u.length&&(c=n.slice(0,d)),u.push(h)):c!==n&&c.push(n[d])}u.length>0&&t.loggerProvider.warn("Dropping ".concat(u.length," oversized event(s) from session replay sequence before send. Sizes: ").concat(u.map(function(e){return"".concat(Math.round(e/1024)," KB")}).join(", "),". If this recurs, please open a GitHub issue at https://github.com/amplitude/Amplitude-TypeScript/issues or contact Amplitude support.")),0!==c.length?(t.debugMode&&Be().then(function(e){var n=e.totalStorageSize,r=e.percentOfQuota,i=e.usageDetails;t.loggerProvider.debug("Total storage size: ".concat(n," KB, percentage of quota: ").concat(r,"%, usage details: ").concat(i))}).catch(function(){}),p.sendEventsList({events:c,sessionId:r,flushMaxRetries:t.flushMaxRetries,apiKey:t.apiKey,deviceId:i,sampleRate:t.sampleRate,serverZone:t.serverZone,version:t.version,type:s,onComplete:function(){return a(void 0,void 0,void 0,function(){return l(this,function(e){switch(e.label){case 0:return[4,S.cleanUpSessionEventsStore(r,o)];case 1:return e.sent(),[2]}})})}})):S.cleanUpSessionEventsStore(r,o).catch(function(e){t.loggerProvider.warn("Failed to clean up session replay events store:",e)})},T=function(e){var n=e.sessionId,r=e.deviceId;if(y=r,!g||g()){var i=P+E.length;S.storeCurrentSequence(n).then(function(e){e&&(k(i),x({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:r}))}).catch(function(e){t.loggerProvider.warn("Failed to get current sequence of session replay events for session:",e)})}},R=function(e){var n=e.deviceId;return a(void 0,void 0,void 0,function(){var e;return l(this,function(r){switch(r.label){case 0:return y=n,[4,S.getSequencesToSend()];case 1:return(null==(e=r.sent())?void 0:e.length)?(t.loggerProvider.log("Draining ".concat(e.length," stored sequence(s) from previous session.")),e.length>1&&p.markCoalesceNextFlush(),e.forEach(function(e){x({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:n})}),[2]):[2]}})})},M=function(e){var n=e.event,r=e.sessionId,i=e.deviceId;y=i;var o=!g||g(),s=P+E.length;E.push(n.data),S.addEventToCurrentSequence(r,n.data).then(function(e){if(e){if(!o)return S.cleanUpSessionEventsStore(e.sessionId,e.sequenceId).catch(function(e){t.loggerProvider.warn("Failed to clean up dropped session replay sequence:",e)}),void k(s);k(s),x({sequenceId:e.sequenceId,events:e.events,sessionId:e.sessionId,deviceId:i})}}).catch(function(e){t.loggerProvider.warn("Failed to add event to session replay capture:",e)})},[2,{sendCurrentSequenceEvents:T,addEvent:M,sendStoredEvents:R,flush:e,getBeaconEvents:function(){return d([],u(E),!1)},dropPendingBeaconEvents:function(){k(P+E.length)},trackDestination:p}]}})})},on=function(){function e(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=new Map;e.forEach(function(e){n.set(e.name,e.manager)}),this.managers=n}return e.prototype.sendStoredEvents=function(e){return a(this,void 0,void 0,function(){var t;return l(this,function(n){switch(n.label){case 0:return t=[],this.managers.forEach(function(n){t.push(n.sendStoredEvents(e))}),[4,Promise.all(t)];case 1:return n.sent(),[2]}})})},e.prototype.addEvent=function(e){var t,n=e.sessionId,r=e.event,i=e.deviceId;null===(t=this.managers.get(r.type))||void 0===t||t.addEvent({sessionId:n,event:r,deviceId:i})},e.prototype.sendCurrentSequenceEvents=function(e){var t=e.sessionId,n=e.deviceId;this.managers.forEach(function(e){e.sendCurrentSequenceEvents({sessionId:t,deviceId:n})})},e.prototype.flush=function(e){return a(this,void 0,void 0,function(){var t;return l(this,function(n){switch(n.label){case 0:return t=[],this.managers.forEach(function(n){t.push(n.flush(e))}),[4,Promise.all(t)];case 1:return n.sent(),[2]}})})},e}();function sn(e,t){if(Yt=new Date,e.nodeType!==Node.ELEMENT_NODE)throw new Error("Can't generate CSS selector for non-element node type.");if("html"===e.tagName.toLowerCase())return"html";var n={root:document.body,idName:function(e){return!0},className:function(e){return!0},tagName:function(e){return!0},attr:function(e,t){return!1},seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4,timeoutMs:void 0};Vt=o(o({},n),t),Zt=function(e,t){if(e.nodeType===Node.DOCUMENT_NODE)return e;if(e===t.root)return e.ownerDocument;return e}(Vt.root,n);var r=an(e,"all",function(){return an(e,"two",function(){return an(e,"one",function(){return an(e,"none")})})});if(r){var i=mn(yn(r,e));return i.length>0&&(r=i[0]),cn(r)}throw new Error("Selector was not found.")}function an(e,t,n){for(var r=null,i=[],o=e,s=0,a=function(){var e,a,l=(new Date).getTime()-Yt.getTime();if(void 0!==Vt.timeoutMs&&l>Vt.timeoutMs)throw new Error("Timeout: Can't find a unique selector after ".concat(l,"ms"));var h=gn(function(e){var t=e.getAttribute("id");if(t&&Vt.idName(t))return{name:"#"+CSS.escape(t),penalty:0};return null}(o))||gn.apply(void 0,d([],u(function(e){var t=Array.from(e.attributes).filter(function(e){return Vt.attr(e.name,e.value)});return t.map(function(e){return{name:"[".concat(CSS.escape(e.name),'="').concat(CSS.escape(e.value),'"]'),penalty:.5}})}(o)),!1))||gn.apply(void 0,d([],u(function(e){var t=Array.from(e.classList).filter(Vt.className);return t.map(function(e){return{name:"."+CSS.escape(e),penalty:1}})}(o)),!1))||gn(function(e){var t=e.tagName.toLowerCase();if(Vt.tagName(t))return{name:t,penalty:2};return null}(o))||[{name:"*",penalty:3}],v=function(e){var t=e.parentNode;if(!t)return null;var n=t.firstChild;if(!n)return null;var r=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&r++,n!==e);)n=n.nextSibling;return r}(o);if("all"==t)v&&(h=h.concat(h.filter(vn).map(function(e){return hn(e,v)})));else if("two"==t)h=h.slice(0,1),v&&(h=h.concat(h.filter(vn).map(function(e){return hn(e,v)})));else if("one"==t){var g=u(h=h.slice(0,1),1)[0];v&&vn(g)&&(h=[hn(g,v)])}else"none"==t&&(h=[{name:"*",penalty:3}],v&&(h=[hn(h[0],v)]));try{for(var f=(e=void 0,c(h)),p=f.next();!p.done;p=f.next()){(g=p.value).level=s}}catch(t){e={error:t}}finally{try{p&&!p.done&&(a=f.return)&&a.call(f)}finally{if(e)throw e.error}}if(i.push(h),i.length>=Vt.seedMinLength&&(r=ln(i,n)))return"break";o=o.parentElement,s++};o;){if("break"===a())break}return r||(r=ln(i,n)),!r&&n?n():r}function ln(e,t){var n,r,i=mn(pn(e));if(i.length>Vt.threshold)return t?t():null;try{for(var o=c(i),s=o.next();!s.done;s=o.next()){var a=s.value;if(dn(a))return a}}catch(e){n={error:e}}finally{try{s&&!s.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}return null}function cn(e){for(var t=e[0],n=t.name,r=1;r<e.length;r++){var i=e[r].level||0;n=t.level===i-1?"".concat(e[r].name," > ").concat(n):"".concat(e[r].name," ").concat(n),t=e[r]}return n}function un(e){return e.map(function(e){return e.penalty}).reduce(function(e,t){return e+t},0)}function dn(e){var t=cn(e);switch(Zt.querySelectorAll(t).length){case 0:throw new Error("Can't select any node with this selector: ".concat(t));case 1:return!0;default:return!1}}function hn(e,t){return{name:e.name+":nth-child(".concat(t,")"),penalty:e.penalty+1}}function vn(e){return"html"!==e.name&&!e.name.startsWith("#")}function gn(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=e.filter(fn);return n.length>0?n:null}function fn(e){return null!=e}function pn(e,t){var n,r,i,o,s,a;return void 0===t&&(t=[]),l(this,function(l){switch(l.label){case 0:if(!(e.length>0))return[3,9];l.label=1;case 1:l.trys.push([1,6,7,8]),n=c(e[0]),r=n.next(),l.label=2;case 2:return r.done?[3,5]:(i=r.value,[5,c(pn(e.slice(1,e.length),t.concat(i)))]);case 3:l.sent(),l.label=4;case 4:return r=n.next(),[3,2];case 5:return[3,8];case 6:return o=l.sent(),s={error:o},[3,8];case 7:try{r&&!r.done&&(a=n.return)&&a.call(n)}finally{if(s)throw s.error}return[7];case 8:return[3,11];case 9:return[4,t];case 10:l.sent(),l.label=11;case 11:return[2]}})}function mn(e){return d([],u(e),!1).sort(function(e,t){return un(e)-un(t)})}function yn(e,t,n){var r,i,o;return void 0===n&&(n={counter:0,visited:new Map}),l(this,function(s){switch(s.label){case 0:if(!(e.length>2&&e.length>Vt.optimizedMinLength))return[3,5];r=1,s.label=1;case 1:return r<e.length-1?n.counter>Vt.maxNumberOfTries?[2]:(n.counter+=1,(i=d([],u(e),!1)).splice(r,1),o=cn(i),n.visited.has(o)?[2]:dn(i)&&function(e,t){return Zt.querySelector(cn(e))===t}(i,t)?[4,i]:[3,4]):[3,5];case 2:return s.sent(),n.visited.set(o,!0),[5,c(yn(i,t,n))];case 3:s.sent(),s.label=4;case 4:return r++,[3,1];case 5:return[2]}})}var bn=function(e){var t=e.version,n=e.events,r=[];return n.forEach(function(e){var t=JSON.parse(e);t.count=1,"click"===t.type&&r.push(t)}),{version:t,events:r}},Sn=function(e){var t=e.version,n=e.events,r=[];n.forEach(function(e){var t=JSON.parse(e);"click"===t.type&&r.push(t)});var i=r.reduce(function(e,t){var n=t.x,r=t.y,i=t.selector,s=t.timestamp,a=s-s%36e5,l="".concat(n,":").concat(r,":").concat(null!=i?i:"",":").concat(a);return e[l]?e[l].count+=1:e[l]=o(o({},t),{timestamp:a,count:1}),e},{});return{version:t,events:Object.values(i)}},In=function(e,t){var n=this;this.createHook=function(e){var t=e.eventsManager,r=e.sessionId,i=e.deviceIdFn,o=e.mirror,s=e.ugcFilterRules,a=e.performanceOptions;return function(e){if(e.type===Ve.Click){var l=f();if(l){var c=l.location,u=l.innerHeight,d=l.innerWidth;if(c){var h=e.x,v=e.y;if(void 0!==h&&void 0!==v){var g,p=o.getNode(e.id);if(p)try{g=sn(p,a)}catch(e){n.logger.debug("error resolving selector from finder")}var m=Ne(c.href,s),y={x:h+n.scrollWatcher.currentScrollX,y:v+n.scrollWatcher.currentScrollY,selector:g,viewportHeight:u,viewportWidth:d,pageUrl:m,timestamp:Date.now(),type:"click"},b=i();b&&t.addEvent({sessionId:r,event:{type:"interaction",data:JSON.stringify(y)},deviceId:b})}}}}}},this.logger=e,this.scrollWatcher=t};function wn(){var e=f();return(null==e?void 0:e.innerHeight)||document.documentElement&&document.documentElement.clientHeight||0}function Cn(){var e=f();return(null==e?void 0:e.innerWidth)||document.documentElement&&document.documentElement.clientWidth||0}var En=function(){function e(e,t){var n=f();n&&n.navigator&&"function"==typeof n.navigator.sendBeacon?this.sendBeacon=function(e,t){try{if(n.navigator.sendBeacon(e,JSON.stringify(t)))return!0}catch(e){}return!1}:this.sendBeacon=function(){return!1},this.sendXhr=function(e,t){var n=new XMLHttpRequest;return n.open("POST",e,!0),n.setRequestHeader("Accept","*/*"),n.send(JSON.stringify(t)),!0},this.basePageUrl=Ae(t.serverZone,t.trackServerUrl),this.apiKey=t.apiKey,this.context=e,this.handleSendEvents=t.handleSendEvents,this.loggerProvider=t.loggerProvider}return e.prototype.send=function(e,t){var n,r=this,i=this.context,o=i.sessionId,s=i.type;if(this.handleSendEvents){var a=new URLSearchParams({device_id:e,session_id:String(o),type:String(s)}),l="".concat(this.basePageUrl,"?").concat(a.toString()),c={"Content-Type":"application/json",Accept:"*/*",Authorization:"Bearer ".concat(this.apiKey)};try{this.handleSendEvents({url:l,method:"POST",headers:c,body:JSON.stringify(t),keepalive:!0}).catch(function(e){var t;null===(t=r.loggerProvider)||void 0===t||t.warn("Custom transport failed to send session replay interaction beacon:",e)})}catch(e){null===(n=this.loggerProvider)||void 0===n||n.warn("Custom transport threw while sending session replay interaction beacon:",e)}}else{var u=new URLSearchParams({device_id:e,session_id:String(o),type:String(s),api_key:this.apiKey}),d="".concat(this.basePageUrl,"?").concat(u.toString());this.sendBeacon(d,t)||this.sendXhr(d,t)}},e}(),Pn=function(){function e(e,t){var n=this;this.timestamp=Date.now(),this.hook=function(e){n.update(e)},this.send=function(e){return function(t){var r,i,o,s,a=e(),l=f();if(l&&a){var c=null!==(r=l.scrollX)&&void 0!==r?r:0,u=null!==(i=l.scrollY)&&void 0!==i?i:0;(c>0||u>0)&&n.update({id:1,x:c,y:u}),n.transport.send(a,{version:1,events:[{maxScrollX:n._maxScrollX,maxScrollY:n._maxScrollY,maxScrollWidth:n._maxScrollWidth,maxScrollHeight:n._maxScrollHeight,viewportHeight:wn(),viewportWidth:Cn(),pageUrl:Ne(l.location.href,null!==(s=null===(o=n.config.interactionConfig)||void 0===o?void 0:o.ugcFilterRules)&&void 0!==s?s:[]),timestamp:n.timestamp,type:"scroll"}]})}}},this._maxScrollX=0,this._maxScrollY=0,this._currentScrollX=0,this._currentScrollY=0,this._maxScrollWidth=Cn(),this._maxScrollHeight=wn(),this.config=t,this.transport=e}return e.default=function(t,n){return new e(new En(t,n),n)},Object.defineProperty(e.prototype,"maxScrollX",{get:function(){return this._maxScrollX},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"maxScrollY",{get:function(){return this._maxScrollY},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"maxScrollWidth",{get:function(){return this._maxScrollWidth},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"maxScrollHeight",{get:function(){return this._maxScrollHeight},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"currentScrollX",{get:function(){return this._currentScrollX},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"currentScrollY",{get:function(){return this._currentScrollY},enumerable:!1,configurable:!0}),e.prototype.update=function(e){var t=Date.now();if(this._currentScrollX=e.x,this._currentScrollY=e.y,e.x>this._maxScrollX){var n=Cn();this._maxScrollX=e.x;var r=e.x+n;r>this._maxScrollWidth&&(this._maxScrollWidth=r),this.timestamp=t}if(e.y>this._maxScrollY){var i=wn();this._maxScrollY=e.y;var o=e.y+i;o>this._maxScrollHeight&&(this._maxScrollHeight=o),this.timestamp=t}},e}(),kn=function(e){var t=e.sessionId,n=e.deviceId;this.deviceId=n,this.sessionId=t,t&&n&&(this.sessionReplayId=function(e,t){return"".concat(t,"/").concat(e)}(t,n))},xn=864e5,Tn=function(e){return"".concat("AMP_SR_START_").concat(e.substring(0,10),"_")},Rn=function(e,t){return"".concat(Tn(e)).concat(t)},Mn=function(){try{var e=f();return null==e?void 0:e.localStorage}catch(e){return}},On=function(){var e=this;this.dbs={},this.createStore=function(t){return a(e,void 0,void 0,function(){return l(this,function(e){switch(e.label){case 0:return[4,Ft(t,1,{upgrade:function(e){e.objectStoreNames.contains("sessionTargetingMatch")||e.createObjectStore("sessionTargetingMatch",{keyPath:"sessionId"})}})];case 1:return[2,e.sent()]}})})},this.openOrCreateDB=function(t){return a(e,void 0,void 0,function(){var e,n;return l(this,function(r){switch(r.label){case 0:return this.dbs&&this.dbs[t]?[2,this.dbs[t]]:(e="".concat(t.substring(0,10),"_amp_session_replay_targeting"),[4,this.createStore(e)]);case 1:return n=r.sent(),this.dbs[t]=n,[2,n]}})})},this.getTargetingMatchForSession=function(t){var n=t.loggerProvider,r=t.apiKey,i=t.sessionId;return a(e,void 0,void 0,function(){var e,t,o,s;return l(this,function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),[4,this.openOrCreateDB(r)];case 1:return e=a.sent(),t=String(i),[4,e.get("sessionTargetingMatch",t)];case 2:return[2,null==(o=a.sent())?void 0:o.targetingMatch];case 3:return s=a.sent(),Kt(n,"Failed to get targeting match for session id ".concat(i,": ").concat(s),s),[3,4];case 4:return[2,void 0]}})})},this.storeTargetingMatchForSession=function(t){var n=t.loggerProvider,r=t.apiKey,i=t.sessionId,o=t.targetingMatch;return a(e,void 0,void 0,function(){var e,t,s;return l(this,function(a){switch(a.label){case 0:return a.trys.push([0,3,,4]),[4,this.openOrCreateDB(r)];case 1:return e=a.sent(),t=String(i),[4,e.put("sessionTargetingMatch",{targetingMatch:o,sessionId:t,lastUpdated:Date.now()})];case 2:return[2,a.sent()];case 3:return s=a.sent(),Kt(n,"Failed to store targeting match for session id ".concat(i,": ").concat(s),s),[3,4];case 4:return[2,void 0]}})})},this.clearStoreOfOldSessions=function(t){var n=t.loggerProvider,r=t.apiKey,i=t.currentSessionId;return a(e,void 0,void 0,function(){var e,t,o,s,a,c,u,d;return l(this,function(l){switch(l.label){case 0:return l.trys.push([0,8,,9]),[4,this.openOrCreateDB(r)];case 1:return e=l.sent(),t=String(i),[4,(o=e.transaction("sessionTargetingMatch","readwrite")).store.getAll()];case 2:s=l.sent(),a=0,l.label=3;case 3:return a<s.length?(c=s[a],u=Date.now()-c.lastUpdated,c.sessionId!==t&&u>1728e5?[4,o.store.delete(c.sessionId)]:[3,5]):[3,6];case 4:l.sent(),l.label=5;case 5:return a++,[3,3];case 6:return[4,o.done];case 7:return l.sent(),[3,9];case 8:return d=l.sent(),Kt(n,"Failed to clear old targeting matches for sessions: ".concat(d),d),[3,9];case 9:return[2]}})})}},Fn=new On,_n=function(e){var t=e.sessionId,n=e.targetingConfig,r=e.loggerProvider,i=e.apiKey,s=e.targetingParams,c=e.urlChange,u=void 0!==c&&c;return a(void 0,void 0,void 0,function(){var e,a,c,d,h,v;return l(this,function(l){switch(l.label){case 0:return[4,Fn.clearStoreOfOldSessions({loggerProvider:r,apiKey:i,currentSessionId:t})];case 1:return l.sent(),[4,Fn.getTargetingMatchForSession({loggerProvider:r,apiKey:i,sessionId:t})];case 2:if(!0===l.sent()&&!u)return[2,!0];e=!0,l.label=3;case 3:return l.trys.push([3,6,,7]),[4,import("./index-min3.js")];case 4:return a=l.sent().evaluateTargeting,c=o(o({},s),{flag:n,sessionId:"string"==typeof t?parseInt(t,10):t,apiKey:i,loggerProvider:r}),[4,a(c)];case 5:return(d=l.sent())&&d.sr_targeting_config&&(e="on"===d.sr_targeting_config.key),Fn.storeTargetingMatchForSession({loggerProvider:r,apiKey:i,sessionId:t,targetingMatch:e}),[3,7];case 6:return h=l.sent(),v=h,r.warn(v.message),[3,7];case 7:return[2,e]}})})},Ln=2654435761,Dn=2246822519,An=3266489917,qn=374761393;function Nn(e,t){return(e<<t|e>>>32-t)>>>0}function Bn(e,t){return e=Nn(e=e+Math.imul(t,Dn)>>>0,13),e=Math.imul(e,Ln)>>>0}function jn(e,t){return(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0}function Un(e,t){void 0===t&&(t=0);var n,r=function(e){for(var t=[],n=0;n<e.length;n++){var r=e.charCodeAt(n);if(r>=55296&&r<=56319&&n+1<e.length){var i=e.charCodeAt(n+1);i>=56320&&i<=57343&&(r=i-56320+(r-55296<<10)+65536,n++)}r<128?t.push(r):r<2048?t.push(192|r>>6,128|63&r):r<65536?t.push(224|r>>12,128|r>>6&63,128|63&r):t.push(240|r>>18,128|r>>12&63,128|r>>6&63,128|63&r)}return new Uint8Array(t)}(e),i=r.length,o=0;if(i>=16){for(var s=t+Ln+Dn>>>0,a=t+Dn>>>0,l=t>>>0,c=t-Ln>>>0;o<=i-16;)s=Bn(s,jn(r,o)),a=Bn(a,jn(r,o+=4)),l=Bn(l,jn(r,o+=4)),c=Bn(c,jn(r,o+=4)),o+=4;n=Nn(s,1)+Nn(a,7)+Nn(l,12)+Nn(c,18)>>>0}else n=t+qn>>>0;for(n=n+i>>>0;o<=i-4;)n=n+Math.imul(jn(r,o),An)>>>0,n=Math.imul(Nn(n,17),668265263)>>>0,o+=4;for(;o<i;)n=n+Math.imul(r[o],qn)>>>0,n=Math.imul(Nn(n,11),Ln)>>>0,o++;return n^=n>>>15,n=Math.imul(n,Dn)>>>0,n^=n>>>13,n=Math.imul(n,An)>>>0,(n^=n>>>16)>>>0}var Wn="__amplitude_url_tracking_patched__",zn=new WeakMap;function Hn(e,t,n){if(void 0===n&&(n={}),!(null==e?void 0:e.location))return function(){};var r=n.enablePolling,i=void 0!==r&&r,o=n.pollingInterval,s=void 0===o?ve:o;if(i){var a=function(){var t;return null!==(t=e.location.href)&&void 0!==t?t:""},l=a(),c=e.setInterval(function(){var e=a();e!==l&&(l=e,t(e))},s);return function(){null!=c&&e.clearInterval(c)}}var u=zn.get(e);if(!u){var d=void 0,h=new Set,v=function(){var t=function(){var t;return null!==(t=e.location.href)&&void 0!==t?t:""}();void 0!==d&&t===d||(d=t,h.forEach(function(e){return e(t)}))},g=function(e){var t=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];var r=e.apply(this,t);return v(),r};return t[Wn]=!0,t},f=e.history;if(null==f?void 0:f.pushState){var p=Reflect.get(f,"pushState");p[Wn]||(f.pushState=g(p))}if(null==f?void 0:f.replaceState){var m=Reflect.get(f,"replaceState");m[Wn]||(f.replaceState=g(m))}u={callbacks:h,notify:v,onPopStateOrHashChange:function(){return v()},listenersAttached:!1},zn.set(e,u)}var y=u;return y.listenersAttached||(e.addEventListener("popstate",y.onPopStateOrHashChange),e.addEventListener("hashchange",y.onPopStateOrHashChange),y.listenersAttached=!0),y.callbacks.add(t),function(){y.callbacks.delete(t),0===y.callbacks.size&&y.listenersAttached&&(e.removeEventListener("popstate",y.onPopStateOrHashChange),e.removeEventListener("hashchange",y.onPopStateOrHashChange),y.listenersAttached=!1)}}function Kn(e){return void 0===e&&(e={}),{name:"amplitude/url-tracking@1",observer:function(t,n,r){var i,s,a,l=o(o({},e),r),c=l.ugcFilterRules||[],u=null!==(i=l.enablePolling)&&void 0!==i&&i,d=null!==(s=l.pollingInterval)&&void 0!==s?s:ve,h=null!==(a=l.captureDocumentTitle)&&void 0!==a&&a;if(!n)return function(){};var v=void 0,g=function(){return n.location&&n.location.href||""},f=function(){var e=g();if(void 0===v||e!==v){v=e;var r=function(){var e=n.innerHeight,t=n.innerWidth,r=n.document,i=g(),o="";return h&&(o=(null==r?void 0:r.title)||""),{href:c.length>0?Ne(i,c):i,title:o,viewportHeight:e,viewportWidth:t,type:"url-change-event"}}();t(r)}},p=Hn(n,function(){return f()},u?{enablePolling:!0,pollingInterval:d}:{});return f(),function(){return p()}},options:e}}Kn();var $n=function(){function e(){this.pendingLoadListeners=new Map}return e.prototype.start=function(){var e,t=this;null===(e=this.mutationObserver)||void 0===e||e.disconnect(),f()&&(this.sendToAllIframes({type:Ee,action:"start"}),this.mutationObserver=new MutationObserver(function(e){var n,r,i,o,s,a;try{for(var l=c(e),u=l.next();!u.done;u=l.next()){var d=u.value;try{for(var h=(i=void 0,c(Array.from(d.addedNodes))),v=h.next();!v.done;v=h.next()){(p=v.value)instanceof HTMLIFrameElement?t.sendToIframeAfterLoad(p):p instanceof Element&&p.querySelectorAll("iframe").forEach(function(e){t.sendToIframeAfterLoad(e)})}}catch(e){i={error:e}}finally{try{v&&!v.done&&(o=h.return)&&o.call(h)}finally{if(i)throw i.error}}try{for(var g=(s=void 0,c(Array.from(d.removedNodes))),f=g.next();!f.done;f=g.next()){var p;if((p=f.value)instanceof HTMLIFrameElement){var m=t.pendingLoadListeners.get(p);m&&(p.removeEventListener("load",m),t.pendingLoadListeners.delete(p))}}}catch(e){s={error:e}}finally{try{f&&!f.done&&(a=g.return)&&a.call(g)}finally{if(s)throw s.error}}}}catch(e){n={error:e}}finally{try{u&&!u.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}}),this.mutationObserver.observe(document.documentElement,{childList:!0,subtree:!0}))},e.prototype.stop=function(){var e;null===(e=this.mutationObserver)||void 0===e||e.disconnect(),this.mutationObserver=void 0,this.pendingLoadListeners.forEach(function(e,t){t.removeEventListener("load",e)}),this.pendingLoadListeners.clear(),this.sendToAllIframes({type:Ee,action:"stop"})},e.prototype.sendToIframeAfterLoad=function(e){var t=this,n=function(){t.pendingLoadListeners.delete(e),t.sendToIframe(e,{type:Ee,action:"start"})};this.pendingLoadListeners.set(e,n),e.addEventListener("load",n,{once:!0})},e.prototype.sendToAllIframes=function(e){var t=this;document.querySelectorAll("iframe").forEach(function(n){return t.sendToIframe(n,e)})},e.prototype.sendToIframe=function(e,t){var n;try{null===(n=e.contentWindow)||void 0===n||n.postMessage(t,"*")}catch(e){}},e}();var Gn,Qn,Jn,Vn=function(){function e(){this.focusLeftWindow=!1}return e.prototype.noteBlur=function(){var e=this;this.focusLeftWindow=!1,this.cancelFocusDestinationCheck();var t=f();this.scheduleFocusInspect(t,function(){var n,r=null===(n=null==t?void 0:t.document)||void 0===n?void 0:n.activeElement;"IFRAME"!==(null==r?void 0:r.tagName)?(e.releaseFocusedFrame(),e.focusLeftWindow=!0):e.watchFocusedFrame(r)})},e.prototype.onDocumentHidden=function(){this.releaseFocusedFrame()},e.prototype.onDocumentVisible=function(){this.focusLeftWindow=!1,this.cancelFocusDestinationCheck(),this.releaseFocusedFrame()},e.prototype.consumeArrivedFromOutside=function(){var e,t,n=this.focusLeftWindow&&"visible"===(null===(t=null===(e=f())||void 0===e?void 0:e.document)||void 0===t?void 0:t.visibilityState);return this.focusLeftWindow=!1,this.releaseFocusedFrame(),n},e.prototype.stop=function(){this.focusLeftWindow=!1,this.cancelFocusDestinationCheck(),this.releaseFocusedFrame()},e.prototype.noteFrameBlur=function(){var e=this;this.cancelFocusDestinationCheck();var t=f();this.scheduleFocusInspect(t,function(){var n,r=null===(n=null==t?void 0:t.document)||void 0===n?void 0:n.activeElement,i=null==t?void 0:t.document;if("function"==typeof(null==i?void 0:i.hasFocus)&&i.hasFocus()||"IFRAME"!==(null==r?void 0:r.tagName))e.releaseFocusedFrame();else{var o=e.focusHolder(r);o?e.watchFocusedFrame(o):e.focusLeftWindow=!0}})},e.prototype.focusHolder=function(e,t){if(null==t?void 0:t.has(e))return e;var n,r=null!=t?t:new Set;r.add(e);try{n=e.contentDocument}catch(t){return e}if(null==n)return e;if("function"==typeof n.hasFocus&&n.hasFocus())return e;var i=n.activeElement;return"IFRAME"===(null==i?void 0:i.tagName)?this.focusHolder(i,r):void 0},e.prototype.watchFocusedFrame=function(e){var t,n=this;this.releaseFocusedFrame();var r=function(){n.noteFrameBlur()};try{if(null==(t=e.contentWindow)||"function"!=typeof t.addEventListener)return;t.addEventListener("blur",r)}catch(e){return}this.focusedFrameWindow=t,this.focusedFrameBlur=r},e.prototype.releaseFocusedFrame=function(){var e=this.focusedFrameWindow,t=this.focusedFrameBlur;if(this.focusedFrameWindow=void 0,this.focusedFrameBlur=void 0,void 0!==e)try{e.removeEventListener("blur",t)}catch(e){}},e.prototype.scheduleFocusInspect=function(e,t){var n=this,r=function(){n.focusDestinationFrame=void 0;try{t()}catch(e){n.releaseFocusedFrame()}};"function"!=typeof(null==e?void 0:e.requestAnimationFrame)?r():this.focusDestinationFrame=e.requestAnimationFrame(r)},e.prototype.cancelFocusDestinationCheck=function(){if(void 0!==this.focusDestinationFrame){var e=f();"function"==typeof(null==e?void 0:e.cancelAnimationFrame)&&e.cancelAnimationFrame(this.focusDestinationFrame),this.focusDestinationFrame=void 0}},e}(),Zn=function(){function e(){var e=this;this.name="@amplitude/session-replay-browser",this.recordCancelCallback=null,this.eventCount=0,this.sessionTargetingMatch=!1,this.pageLeaveFns=[],this.suppressedSendCount=0,this.hasEmittedGateDecision=!1,this.recordFunction=null,this.recordEventsInFlight=!1,this.recordingEnabled=!0,this.recordingGeneration=0,this.startChildRecordingOnSetup=!1,this.pendingEmitEvents=[],this.windowFocus=new Vn,this.currentPageUrl="",this.recordEventsPendingShouldLogMetadata=null,this.urlChangeCleanup=null,this.crossOriginIframeCoordinator=null,this.crossOriginParentSignalCleanup=null,this.latestUrlChangeTargetingEvaluationId=0,this.teardownEventListeners=function(t){var n=f();if(n){n.removeEventListener("blur",e.blurListener),n.removeEventListener("focus",e.focusListener),!t&&n.addEventListener("blur",e.blurListener),!t&&n.addEventListener("focus",e.focusListener),n.self&&"onpagehide"in n.self?(n.removeEventListener("pagehide",e.pageLeaveListener),!t&&n.addEventListener("pagehide",e.pageLeaveListener)):(n.removeEventListener("beforeunload",e.pageLeaveListener),!t&&n.addEventListener("beforeunload",e.pageLeaveListener));var r=n.document;(null==r?void 0:r.addEventListener)&&r.removeEventListener&&(r.removeEventListener("visibilitychange",e.visibilityListener),!t&&r.addEventListener("visibilitychange",e.visibilityListener))}},this.blurListener=function(){e.scheduleHiddenSend(),e.windowFocus.noteBlur()},this.visibilityListener=function(){var t,n,r=null===(n=null===(t=f())||void 0===t?void 0:t.document)||void 0===n?void 0:n.visibilityState;if("hidden"===r)return e.windowFocus.onDocumentHidden(),void e.scheduleHiddenSend();"visible"===r&&(e.windowFocus.onDocumentVisible(),e.cancelHiddenSend(),e.captureVisibleTab())},this.focusListener=function(){var t;if(e.recordingEnabled)if(e.windowFocus.consumeArrivedFromOutside())e.captureVisibleTab();else if(e.recordCancelCallback&&e.recordFunction){if(!1===(null===(t=e.config)||void 0===t?void 0:t.captureFullSnapshotOnFocus))return;try{e.recordFunction.takeFullSnapshot(!0)}catch(t){e.loggerProvider.warn("Failed to take full snapshot on focus:",t)}}else e.recordEventsInFlight||e.recordEvents(!1)},this.pageLeaveListener=function(t){e.cancelHiddenSend(),e.flushPendingReplayEvents(),e.pageLeaveFns.forEach(function(e){e(t)})},this.evaluateTargetingAndCapture=function(t,n,r,o){return void 0===n&&(n=!1),void 0===r&&(r=!1),void 0===o&&(o=!1),a(e,void 0,void 0,function(){var e,s,a,c,u,d,h,v,g,p,m,y;return l(this,function(l){switch(l.label){case 0:if(!this.identifiers||!this.identifiers.sessionId||!this.config)return this.identifiers&&!this.identifiers.sessionId?this.loggerProvider.log("Session ID has not been set yet, cannot evaluate targeting for Session Replay."):this.loggerProvider.warn("Session replay init has not been called, cannot evaluate targeting."),[2];if(!this.config.targetingConfig){if(!n)return this.loggerProvider.log("No targeting config set, skipping initialization/recording for event."),[2];this.loggerProvider.log("Targeting config has not been set yet, cannot evaluate targeting.")}return this.lastTargetingParams=t,e=this.config.targetingConfig,e&&!this.sessionTargetingMatch?(s=o?this.latestUrlChangeTargetingEvaluationId:void 0,(a=t.event)&&Object.values(i).includes(a.event_type)&&(a=void 0),c=null!==(m=null!==(v=null===(h=t.page)||void 0===h?void 0:h.url)&&void 0!==v?v:null===(p=null===(g=f())||void 0===g?void 0:g.location)||void 0===p?void 0:p.href)&&void 0!==m?m:"",u=null!==(y=t.page)&&void 0!==y?y:""!==c?{url:c}:void 0,[4,_n({sessionId:this.identifiers.sessionId,targetingConfig:e,loggerProvider:this.loggerProvider,apiKey:this.config.apiKey,targetingParams:{userProperties:t.userProperties,event:a,page:u},urlChange:o})]):[3,2];case 1:if(d=l.sent(),o&&void 0!==s&&s!==this.latestUrlChangeTargetingEvaluationId)return this.loggerProvider.debug("Ignoring stale URL-change targeting result #".concat(s,"; latest is #").concat(this.latestUrlChangeTargetingEvaluationId,".")),[2];this.sessionTargetingMatch=this.sessionTargetingMatch||d,this.loggerProvider.debug(JSON.stringify({name:"targeted replay capture config",sessionTargetingMatch:this.sessionTargetingMatch,event:a,targetingParams:t},null,2)),l.label=2;case 2:return n?(this.initialize(!0),[3,5]):[3,3];case 3:return!r&&this.recordCancelCallback?[3,5]:(this.loggerProvider.log("Recording events for session due to forceRestart or no ongoing recording."),[4,this.recordEvents()]);case 4:l.sent(),l.label=5;case 5:return[2]}})})},this.addCustomRRWebEvent=function(t,n,r){return void 0===n&&(n={}),void 0===r&&(r=!0),a(e,void 0,void 0,function(){var e,i,s,a;return l(this,function(l){switch(l.label){case 0:return l.trys.push([0,3,,4]),e=void 0,(i=this.config)&&t!==le.METADATA?(e={config:je(i),version:mt},r?[4,Be()]:[3,2]):[3,2];case 1:s=l.sent(),e=o(o({},s),e),l.label=2;case 2:return this.recordCancelCallback&&this.recordFunction?this.recordFunction.addCustomEvent(t,o(o({},n),e)):this.loggerProvider.debug("Not able to add custom replay capture event ".concat(t," due to no ongoing recording.")),[3,4];case 3:return a=l.sent(),this.loggerProvider.debug("Error while adding custom replay capture event: ",a),[3,4];case 4:return[2]}})})},this.stopRecordingEvents=function(){var t,n,r;try{e.useSemanticAdapter(function(e){return e.stop()}),e.loggerProvider.log("Session Replay capture stopping."),e.recordCancelCallback&&e.recordCancelCallback(),e.recordCancelCallback=null,null===(t=e.networkObservers)||void 0===t||t.stop(),null===(n=e.crossOriginIframeCoordinator)||void 0===n||n.stop(),e.crossOriginIframeCoordinator=null,null===(r=e.crossOriginParentSignalCleanup)||void 0===r||r.call(e),e.crossOriginParentSignalCleanup=null}catch(t){var i=t;e.loggerProvider.warn("Error occurred while stopping replay capture: ".concat(i.toString()))}},this.loggerProvider=new Pe(new T)}return e.prototype.init=function(e,t){return k(this._init(e,t))},e.prototype.setupUrlChangeListener=function(){var e,t,n=this;null===(e=this.urlChangeCleanup)||void 0===e||e.call(this);var r=f();if(null==r?void 0:r.location){var i=!!(null===(t=this.config)||void 0===t?void 0:t.targetingConfig),o=Hn(r,function(e){if(n.currentPageUrl=e,i){var t=++n.latestUrlChangeTargetingEvaluationId;n.evaluateTargetingAndCapture({userProperties:{},event:void 0,page:{url:e}},!1,!1,!0),n.loggerProvider.debug("Queued URL-change targeting re-evaluation #".concat(t," for ").concat(e,"."))}});this.urlChangeCleanup=function(){o(),n.urlChangeCleanup=null}}},e.prototype.isBelowMinSessionDuration=function(){var e,t=null===(e=this.config)||void 0===e?void 0:e.minSessionDurationMs;return void 0!==t&&void 0!==this.sessionStartTime&&Date.now()-this.sessionStartTime<t},e.prototype.getCurrentPageForTargeting=function(){var e,t,n=null===(t=null===(e=f())||void 0===e?void 0:e.location)||void 0===t?void 0:t.href;return null!=n?{url:n}:void 0},e.prototype._init=function(e,t){var n,r,i,s,h,v,g,p,m,y,b,S,I,w;return a(this,void 0,void 0,function(){var a,C,E,P,k,x,R,M,O,F,_,L,D,A,q,N,B,j,U,W,z,H,K,$,G,Q,J,V,Z,Y,X,te=this;return l(this,function(l){switch(l.label){case 0:return null===(n=this.urlChangeCleanup)||void 0===n||n.call(this),this.useSemanticAdapter(function(e){return e.stop()}),this.semanticAdapter=void 0,this.recordingEnabled=!0,this.startChildRecordingOnSetup=!1,this.loggerProvider=new Pe(t.loggerProvider||new T),Object.prototype.hasOwnProperty.call(t,"logLevel")&&this.loggerProvider.enable(t.logLevel),this.currentPageUrl=qe(),this.identifiers=new kn({sessionId:t.sessionId,deviceId:t.deviceId}),a=Date.now(),function(e,t,n){var r,i,o=Mn();if(o){var s=Tn(e);try{for(var a=[],l=0;l<o.length;l++)if((g=o.key(l))&&g.startsWith(s)){var u=o.getItem(g);if(null!==u){var d=Number(u);(!Number.isFinite(d)||d<=0||t-d>=xn)&&a.push(g)}}try{for(var h=c(a),v=h.next();!v.done;v=h.next()){var g=v.value;o.removeItem(g)}}catch(e){r={error:e}}finally{try{v&&!v.done&&(i=h.return)&&i.call(h)}finally{if(r)throw r.error}}}catch(e){null==n||n.debug("Failed to prune stale replay start times: ".concat(String(e)))}}}(e,a,this.loggerProvider),this.sessionStartTime=void 0!==t.sessionId&&null!==(r=function(e,t,n,r){var i=Mn();if(i){var o=Rn(e,t);try{var s=i.getItem(o);if(null!==s){var a=Number(s);if(Number.isFinite(a)&&a>0&&a<=n&&n-a<xn)return a}return i.setItem(o,String(n)),n}catch(e){return void(null==r||r.debug("Failed to read/write replay start time from storage: ".concat(String(e))))}}}(e,t.sessionId,a,this.loggerProvider))&&void 0!==r?r:a,C=this,[4,it(e,t)];case 1:return C.joinedConfigGenerator=l.sent(),[4,this.joinedConfigGenerator.generateJoinedConfig()];case 2:return E=l.sent(),P=E.joinedConfig,k=E.localConfig,x=E.remoteConfig,this.config=P,this.setMetadata(t.sessionId,P,k,x,null===(i=t.version)||void 0===i?void 0:i.version,mt,null===(s=t.version)||void 0===s?void 0:s.type),this.pageLeaveFns=[],t.sessionId&&(null===(h=this.config.interactionConfig)||void 0===h?void 0:h.enabled)&&(R=Pn.default({sessionId:t.sessionId,type:"interaction"},this.config),this.pageLeaveFns=[R.send(this.getDeviceId.bind(this)).bind(R)],this.scrollHook=R.hook.bind(R),this.clickHandler=new In(this.loggerProvider,R)),M=[],"idb"!==(O=this.config.storeType)||(null===(v=f())||void 0===v?void 0:v.indexedDB)||(O="memory",this.loggerProvider.warn("Could not use preferred indexedDB storage, reverting to in memory option.")),this.loggerProvider.log("Using ".concat(O," for event storage.")),L=f(),this.config.useWebWorker&&L&&L.Worker?[4,import("./index-min2.js")]:[3,4];case 3:D=l.sent(),A=D.compressionScript,q=D.trackDestinationScript,F=A,_=q,l.label=4;case 4:return l.trys.push([4,6,,7]),[4,rn({config:this.config,type:"replay",minInterval:null===(g=this.config.flushIntervalConfig)||void 0===g?void 0:g.minIntervalMs,maxInterval:null===(p=this.config.flushIntervalConfig)||void 0===p?void 0:p.maxIntervalMs,maxPersistedEventsSize:this.config.maxPersistedEventsSizeBytes,storeType:O,trackDestinationWorkerScript:_,shouldSend:function(){return!te.isBelowMinSessionDuration()}})];case 5:return N=l.sent(),this.rrwebEventManager=N,M.push({name:"replay",manager:N}),[3,7];case 6:return B=l.sent(),z=B,this.loggerProvider.warn("Error occurred while creating replay events manager: ".concat(z.toString())),[3,7];case 7:if(!(null===(m=this.config.interactionConfig)||void 0===m?void 0:m.enabled))return[3,11];j=this.config.interactionConfig.batch?Sn:bn,l.label=8;case 8:return l.trys.push([8,10,,11]),[4,rn({config:this.config,type:"interaction",minInterval:null!==(y=this.config.interactionConfig.trackEveryNms)&&void 0!==y?y:3e4,maxInterval:6e4,maxPersistedEventsSize:this.config.maxPersistedEventsSizeBytes,payloadBatcher:j,storeType:O,trackDestinationWorkerScript:_})];case 9:return U=l.sent(),M.push({name:"interaction",manager:U}),[3,11];case 10:return W=l.sent(),z=W,this.loggerProvider.warn("Error occurred while creating interaction events manager: ".concat(z.toString())),[3,11];case 11:if(this.eventsManager=new(on.bind.apply(on,d([void 0],u(M),!1))),this.eventCompressor&&this.eventCompressor.terminate(),H=!0===this.config.eagerFullSnapshotSend?function(){return te.sendEvents()}:void 0,this.eventCompressor=new vt(this.eventsManager,this.config,this.getDeviceId(),F,H),this.pendingEmitEvents.length>0){K=this.pendingEmitEvents.splice(0);try{for($=c(K),G=$.next();!G.done;G=$.next())Q=G.value,J=Q.event,V=Q.sessionId,this.eventCompressor.enqueueEvent(J,V)}catch(e){Y={error:e}}finally{try{G&&!G.done&&(X=$.return)&&X.call($)}finally{if(Y)throw Y.error}}}return this.pageLeaveFns=d(d([],u(this.pageLeaveFns),!1),[function(){var e;if(te.config&&(null===(e=te.identifiers)||void 0===e?void 0:e.sessionId)&&N){var t=N.getBeaconEvents();if(t.length){var n=te.getDeviceId();n&&(te.isBelowMinSessionDuration()||N.trackDestination.sendBeacon({events:t,sessionId:te.identifiers.sessionId,deviceId:n,apiKey:te.config.apiKey,serverZone:te.config.serverZone}))}}}],!1),[4,this.initializeNetworkObservers()];case 12:return l.sent(),(null===(b=f())||void 0===b?void 0:b.opener)&&(ae(Z=ie()),Z.setup(o({logger:this.loggerProvider},this.config.serverZone&&{endpoint:ee[this.config.serverZone]}))),this.loggerProvider.log("Installing @amplitude/session-replay-browser."),this.teardownEventListeners(!1),[4,this.evaluateTargetingAndCapture({userProperties:t.userProperties,page:this.getCurrentPageForTargeting()},!0)];case 13:return l.sent(),(this.config.targetingConfig||(null!==(w=null===(I=null===(S=this.config.privacyConfig)||void 0===S?void 0:S.urlMaskLevels)||void 0===I?void 0:I.length)&&void 0!==w?w:0)>0)&&this.setupUrlChangeListener(),[2]}})})},e.prototype.setSessionId=function(e,t){return k(this.asyncSetSessionId(e,t))},e.prototype.asyncSetSessionId=function(e,t,n){var r,i,o,s,c,u;return a(this,void 0,void 0,function(){var a,d,h,v,g;return l(this,function(l){switch(l.label){case 0:return a=null===(r=this.identifiers)||void 0===r?void 0:r.sessionId,d=this.getDeviceId(),void 0===a||a!==e||void 0!==t&&t!==d||void 0!==(null==n?void 0:n.userProperties)&&0!==Object.keys(n.userProperties).length?(this.latestUrlChangeTargetingEvaluationId++,this.sessionTargetingMatch=!1,this.lastShouldRecordDecision=void 0,a&&this.sendEvents(a),(h=a!==e)&&(null===(o=null===(i=this.config)||void 0===i?void 0:i.semanticCapture)||void 0===o?void 0:o.enabled)&&this.semanticAdapter&&this.useSemanticAdapter(function(e){return e.stop()}),h&&(null===(s=this.rrwebEventManager)||void 0===s||s.dropPendingBeaconEvents()),v=t||this.getDeviceId(),this.identifiers=new kn({sessionId:e,deviceId:v}),h&&(this.sessionStartTime=Date.now(),this.suppressedSendCount=0,this.hasEmittedGateDecision=!1,(null===(c=this.config)||void 0===c?void 0:c.apiKey)&&(function(e,t,n,r){var i=Mn();if(i)try{i.setItem(Rn(e,t),String(n))}catch(e){null==r||r.debug("Failed to write replay start time to storage: ".concat(String(e)))}}(this.config.apiKey,e,this.sessionStartTime,this.loggerProvider),void 0!==a&&function(e,t,n){var r=Mn();if(r)try{r.removeItem(Rn(e,t))}catch(e){null==n||n.debug("Failed to remove replay start time from storage: ".concat(String(e)))}}(this.config.apiKey,a,this.loggerProvider))),this.joinedConfigGenerator&&a?[4,this.joinedConfigGenerator.generateJoinedConfig()]:[3,2]):[2];case 1:g=l.sent().joinedConfig,this.config=g,l.label=2;case 2:return(null===(u=this.config)||void 0===u?void 0:u.targetingConfig)?[4,this.evaluateTargetingAndCapture({userProperties:null==n?void 0:n.userProperties,page:this.getCurrentPageForTargeting()},!1,!0)]:[3,4];case 3:return l.sent(),[3,6];case 4:return[4,this.recordEvents()];case 5:l.sent(),l.label=6;case 6:return[2]}})})},e.prototype.getSessionReplayProperties=function(){var e,t=this.config,n=this.identifiers;if(!t||!n)return this.loggerProvider.warn("Session replay init has not been called, cannot get session replay properties."),{};var r=this.getShouldRecord(),i={};return r&&((e={})[ue]=n.sessionReplayId?n.sessionReplayId:null,i=e,t.debugMode&&(i[ge]=JSON.stringify({appHash:z(t.apiKey).toString()}))),this.addCustomRRWebEvent(le.GET_SR_PROPS,{shouldRecord:r,eventProperties:i},10===this.eventCount),10===this.eventCount&&(this.eventCount=0),this.eventCount++,i},e.prototype.flushPendingReplayEvents=function(){var e;null===(e=this.eventCompressor)||void 0===e||e.flushQueue(),this.sendEvents()},e.prototype.scheduleHiddenSend=function(){var e,t=this;if(null===(e=this.eventCompressor)||void 0===e||e.flushQueue(),void 0===this.hiddenFlushTimer){var n=this.hostSetTimeout();this.hiddenFlushTimer=n(function(){t.hiddenFlushTimer=void 0,t.sendEvents()},0)}},e.prototype.cancelHiddenSend=function(){void 0!==this.hiddenFlushTimer&&(this.hostClearTimeout()(this.hiddenFlushTimer),this.hiddenFlushTimer=void 0)},e.prototype.hostSetTimeout=function(){var e=f();return"function"==typeof(null==e?void 0:e.setTimeout)?e.setTimeout.bind(e):setTimeout},e.prototype.hostClearTimeout=function(){var e=f();return"function"==typeof(null==e?void 0:e.clearTimeout)?e.clearTimeout.bind(e):clearTimeout},e.prototype.captureVisibleTab=function(){var e;if(this.recordingEnabled)if(null===(e=this.eventCompressor)||void 0===e||e.flushQueue(),this.recordCancelCallback&&this.recordFunction){try{this.recordFunction.takeFullSnapshot(!0)}catch(e){this.loggerProvider.warn("Failed to take full snapshot when the tab became visible:",e)}this.sendEvents()}else this.recordEventsInFlight||this.recordEvents(!1)},e.prototype.sendEvents=function(e){var t,n,r=e||(null===(t=this.identifiers)||void 0===t?void 0:t.sessionId),i=this.getDeviceId();if(this.eventsManager&&r&&i){if(this.isBelowMinSessionDuration()){var o=this.sessionStartTime,s=this.config.minSessionDurationMs;return this.loggerProvider.log("Session ".concat(r," not sent: duration ").concat(Date.now()-o,"ms is below minimum ").concat(s,"ms.")),void this.suppressedSendCount++}if(!this.hasEmittedGateDecision&&void 0!==(null===(n=this.config)||void 0===n?void 0:n.minSessionDurationMs)&&this.recordCancelCallback&&this.recordFunction){this.hasEmittedGateDecision=!0;var a=void 0!==this.sessionStartTime?Date.now()-this.sessionStartTime:void 0;this.addCustomRRWebEvent(le.REPLAY_GATE_DECISION,{sessionId:r,suppressedSendCount:this.suppressedSendCount,elapsedMs:a,minSessionDurationMs:this.config.minSessionDurationMs},!1)}this.eventsManager.sendCurrentSequenceEvents({sessionId:r,deviceId:i})}},e.prototype.initialize=function(e){var t;return void 0===e&&(e=!1),a(this,void 0,void 0,function(){var n;return l(this,function(r){return(null===(t=this.identifiers)||void 0===t?void 0:t.sessionId)?(n=this.getDeviceId())?(this.eventsManager&&e&&this.eventsManager.sendStoredEvents({deviceId:n}),[2,this.recordEvents()]):(this.loggerProvider.log("Session is not being recorded due to lack of device id."),[2,Promise.resolve()]):(this.loggerProvider.log("Session is not being recorded due to lack of session id."),[2,Promise.resolve()])})})},e.prototype.shouldOptOut=function(){var e,t,n;(null===(e=this.config)||void 0===e?void 0:e.instanceName)&&(n=W(this.config.instanceName).identityStore.getIdentity().optOut);return void 0!==n?n:null===(t=this.config)||void 0===t?void 0:t.optOut},e.prototype.getShouldRecord=function(){if(!this.identifiers||!this.config||!this.identifiers.sessionId)return this.loggerProvider.warn("Session is not being recorded due to lack of config, please call sessionReplay.init."),!1;if(!this.recordingEnabled)return this.loggerProvider.log("Session ".concat(this.identifiers.sessionId," not being captured because recording was stopped.")),!1;if(!this.config.captureEnabled)return this.loggerProvider.log("Session ".concat(this.identifiers.sessionId," not being captured due to capture being disabled for project or because the remote config could not be fetched.")),!1;if(this.shouldOptOut())return this.loggerProvider.log("Opting session ".concat(this.identifiers.sessionId," out of recording due to optOut config.")),!1;var e,t,n=!1,r="",i=!1;this.config.targetingConfig?this.sessionTargetingMatch?(r="Capturing replays for session ".concat(this.identifiers.sessionId," due to matching targeting conditions."),this.loggerProvider.log(r),n=!0,i=!0):(r="Not capturing replays for session ".concat(this.identifiers.sessionId," due to not matching targeting conditions."),this.loggerProvider.log(r),n=!1,i=!1):(e=this.identifiers.sessionId,t=this.config.sampleRate,Un(e.toString())%1e6/1e6<t)?(n=!0,i=!0):(r="Opting session ".concat(this.identifiers.sessionId," out of recording due to sample rate."),this.loggerProvider.log(r),n=!1,i=!1);return this.lastShouldRecordDecision!==n&&this.config.targetingConfig&&(this.addCustomRRWebEvent(le.TARGETING_DECISION,{message:r,sessionId:this.identifiers.sessionId,matched:i,targetingParams:this.lastTargetingParams}),this.lastShouldRecordDecision=n),n},e.prototype.getBlockSelectors=function(){var e;return Le(null===(e=this.config)||void 0===e?void 0:e.privacyConfig)},e.prototype.getMaskTextSelectors=function(){var e;return De(null===(e=this.config)||void 0===e?void 0:e.privacyConfig,this.currentPageUrl)},e.prototype.getRecordingPlugins=function(e){var t,n,r,i,o,s;return a(this,void 0,void 0,function(){var a,c,u,d;return l(this,function(l){switch(l.label){case 0:a=[];try{c=Kn({ugcFilterRules:(null===(n=null===(t=this.config)||void 0===t?void 0:t.interactionConfig)||void 0===n?void 0:n.ugcFilterRules)||[],enablePolling:(null===(r=this.config)||void 0===r?void 0:r.enableUrlChangePolling)||!1,pollingInterval:null===(i=this.config)||void 0===i?void 0:i.urlChangePollingInterval,captureDocumentTitle:null===(o=this.config)||void 0===o?void 0:o.captureDocumentTitle}),a.push(c)}catch(e){this.loggerProvider.warn("Failed to create URL tracking plugin:",e)}if(!(null===(s=null==e?void 0:e.console)||void 0===s?void 0:s.enabled))return[3,4];l.label=1;case 1:return l.trys.push([1,3,,4]),[4,import("./console-plugin-min.js")];case 2:return u=l.sent().getRecordConsolePlugin,a.push(u({level:e.console.levels})),[3,4];case 3:return d=l.sent(),this.loggerProvider.warn("Failed to load console plugin:",d),[3,4];case 4:return[2,a.length>0?a:void 0]}})})},e.prototype.getRecordFunction=function(){return a(this,void 0,void 0,function(){var e,t;return l(this,function(n){switch(n.label){case 0:if(this.recordFunction)return[2,this.recordFunction];n.label=1;case 1:return n.trys.push([1,3,,4]),[4,import("./rrweb-record-min.js")];case 2:return e=n.sent().record,this.recordFunction=e,[2,e];case 3:return t=n.sent(),this.loggerProvider.warn("Failed to load rrweb-record module:",t),[2,null];case 4:return[2]}})})},e.prototype.recordEvents=function(e){return void 0===e&&(e=!0),a(this,void 0,void 0,function(){var t;return l(this,function(n){switch(n.label){case 0:if(this.recordEventsInFlight)return this.recordEventsPendingShouldLogMetadata=e,[2];this.recordEventsInFlight=!0,n.label=1;case 1:return n.trys.push([1,,6,7]),[4,this._recordEvents(e)];case 2:n.sent(),n.label=3;case 3:return null===this.recordEventsPendingShouldLogMetadata?[3,5]:(t=this.recordEventsPendingShouldLogMetadata,this.recordEventsPendingShouldLogMetadata=null,[4,this._recordEvents(t)]);case 4:return n.sent(),[3,3];case 5:return[3,7];case 6:return this.recordEventsInFlight=!1,this.recordEventsPendingShouldLogMetadata=null,[7];case 7:return[2]}})})},e.prototype.shouldAbandonRecordStart=function(e){return!this.recordingEnabled||e!==this.recordingGeneration},e.prototype._recordEvents=function(e){var t,n,r,i,s,c,u,d;return void 0===e&&(e=!0),a(this,void 0,void 0,function(){var a,h,v,g,p,m,y,b,S,I,w,C,E,P,k,x,T,R=this;return l(this,function(l){switch(l.label){case 0:return a=this.config,h=this.getShouldRecord(),v=null===(t=this.identifiers)||void 0===t?void 0:t.sessionId,h&&v&&a?(this.stopRecordingEvents(),g=this.recordingGeneration,[4,this.getRecordFunction()]):(this.semanticAdapter&&this.recordCancelCallback&&this.stopRecordingEvents(),[2]);case 1:return!(p=l.sent())||this.shouldAbandonRecordStart(g)?[2]:[4,this.initializeNetworkObservers()];case 2:if(l.sent(),this.shouldAbandonRecordStart(g))return[2];m=null===(n=a.loggingConfig)||void 0===n?void 0:n.network,y=Ae(a.serverZone,a.trackServerUrl),b=[fe,pe,me,y],null===(r=this.networkObservers)||void 0===r||r.start(function(e){b.some(function(t){return e.url.startsWith(t)})||R.addCustomRRWebEvent(le.FETCH_REQUEST,e)},m),S=a.interactionConfig,I=a.loggingConfig,w=(null==S?void 0:S.enabled)?{mouseInteraction:this.eventsManager&&(null===(i=this.clickHandler)||void 0===i?void 0:i.createHook({eventsManager:this.eventsManager,sessionId:v,deviceIdFn:this.getDeviceId.bind(this),mirror:p.mirror,ugcFilterRules:null!==(s=S.ugcFilterRules)&&void 0!==s?s:[],performanceOptions:null===(c=a.performanceConfig)||void 0===c?void 0:c.interaction})),scroll:this.scrollHook}:{},C=(null==S?void 0:S.enabled)&&S.ugcFilterRules?S.ugcFilterRules:[],this.loggerProvider.log("Session Replay capture beginning for ".concat(v,".")),l.label=3;case 3:return l.trys.push([3,5,,6]),E=!!(null===(u=a.crossOriginIframes)||void 0===u?void 0:u.enabled),P=!1!==(null===(d=a.crossOriginIframes)||void 0===d?void 0:d.coordinateChildren),(k=E&&function(){try{var e=f();return!!e&&e.parent!==e}catch(e){return!0}}())&&P?(this.crossOriginParentSignalCleanup=function(e){var t=f();if(!t)return function(){};var n=t.parent;function r(t){if(t.source===n){var r=t.data;(null==r?void 0:r.type)===Ee&&("start"===r.action?e.onStart():"stop"===r.action&&e.onStop())}}return t.addEventListener("message",r),function(){return t.removeEventListener("message",r)}}({onStart:function(){R.recordingEnabled&&R._recordEventsInChildMode(p,v,a,w)},onStop:function(){try{R.recordCancelCallback&&R.recordCancelCallback(),R.recordCancelCallback=null}catch(t){var e=t;R.loggerProvider.warn("Error occurred while stopping child iframe replay capture: ".concat(e.toString()))}}}),this.startChildRecordingOnSetup&&(this.startChildRecordingOnSetup=!1,this._recordEventsInChildMode(p,v,a,w)),[2]):(this.startChildRecordingOnSetup=!1,[4,this.getRecordingPlugins(I)]);case 4:return x=l.sent(),this.shouldAbandonRecordStart(g)?[2]:(this.prepareSemanticCapture(a,v),this.recordCancelCallback=p(o(o({},this.buildRRWebRecordOptions(a,w,function(e){if(R.shouldOptOut()||!R.recordingEnabled)return R.loggerProvider.log(R.shouldOptOut()?"Opting session ".concat(v," out of recording due to optOut config."):"Session Replay capture stopping for ".concat(v,".")),R.stopRecordingEvents(),void R.sendEvents();e.type===Qe.Meta&&(e.data.href=Ne(e.data.href,C)),R.eventCompressor?R.eventCompressor.enqueueEvent(e,v):R.pendingEmitEvents.push({event:e,sessionId:v}),R.useSemanticAdapter(function(t){return t.event(e)})},"Error while capturing replay: ")),{plugins:x,recordCrossOriginIframes:E})),this.recordCancelCallback&&this.useSemanticAdapter(function(e){return e.recordingReady()}),E&&!k&&P&&(this.crossOriginIframeCoordinator||(this.crossOriginIframeCoordinator=new $n),this.crossOriginIframeCoordinator.start()),this.addCustomRRWebEvent(le.DEBUG_INFO),e&&this.addCustomRRWebEvent(le.METADATA,this.metadata),[3,6]);case 5:return T=l.sent(),this.useSemanticAdapter(function(e){return e.stop()}),this.loggerProvider.warn("Failed to initialize session replay:",T),[3,6];case 6:return[2]}})})},e.prototype.useSemanticAdapter=function(e){var t=this.semanticAdapter;if(t)try{e(t)}catch(e){this.semanticAdapter=void 0,this.loggerProvider.debug("Semantic capture failed:",e);try{t.stop()}catch(e){this.loggerProvider.debug("Semantic capture stop failed:",e)}}},e.prototype.prepareSemanticCapture=function(e,t){var n,r=this,i=f();if(null==i?void 0:i.document){var s=e.semanticCapture,a=null==s?void 0:s.createCapture;if(!(null==s?void 0:s.enabled)||"function"!=typeof a)return this.useSemanticAdapter(function(e){return e.stop()}),void this.useSemanticAdapter(function(e){return e.prepare({enabled:!1},t)});if((null===(n=this.semanticAdapter)||void 0===n?void 0:n.createCapture)!==a){this.useSemanticAdapter(function(e){return e.stop()}),this.semanticAdapter=void 0;try{this.semanticAdapter=new Ze(a,{document:i.document,window:i,sdk:"@amplitude/session-replay-browser@".concat(mt),getPrivacy:function(){var e,t;return null!==(t=null===(e=r.config)||void 0===e?void 0:e.privacyConfig)&&void 0!==t?t:{}},getIdentity:function(){return function(e){var t=e.document,n=Xe.get(t);if(n)return n;var r=Object.freeze({tab_id:m(),document_id:m()}),i=r;if(e.top===e)try{var s=e.sessionStorage,a=function(){var e;try{var t=JSON.parse(null!==(e=s.getItem(Ye))&&void 0!==e?e:"null");if(t&&et.test(t.tab_id)&&(null===t.owner||"string"==typeof t.owner))return t}catch(e){}},l=a();null===(null==l?void 0:l.owner)&&(i=Object.freeze(o(o({},i),{tab_id:l.tab_id})));var c=function(e){try{s.setItem(Ye,JSON.stringify({tab_id:i.tab_id,owner:e}))}catch(e){}};s.setItem(Ye,JSON.stringify({tab_id:i.tab_id,owner:i.document_id})),e.addEventListener("pagehide",function(){var e;(null===(e=a())||void 0===e?void 0:e.owner)===i.document_id&&c(null)}),e.addEventListener("pageshow",function(e){e.persisted&&c(i.document_id)})}catch(e){i=r}return Xe.set(t,i),i}(i)},getAnalyticsContext:function(){var e,t;return null!==(t=null===(e=r.config)||void 0===e?void 0:e.semanticAnalyticsContext)&&void 0!==t?t:{present:!1,autocapture:[]}},inlineStylesheet:e.shouldInlineStylesheet,emit:function(e){if(r.recordCancelCallback&&r.recordFunction)try{r.recordFunction.addCustomEvent("amp-semantic/".concat(e.name),e.payload)}catch(e){r.loggerProvider.debug("Error while adding semantic replay capture event:",e)}},onError:function(e){return r.loggerProvider.debug("Semantic capture error:",e)}})}catch(e){return void this.loggerProvider.debug("Semantic capture initialization failed:",e)}}this.useSemanticAdapter(function(e){return e.prepare(s,t)})}},e.prototype.buildRRWebRecordOptions=function(e,t,n,r){var i=this,s=e.privacyConfig;return o(o(o(o({emit:n,inlineStylesheet:e.shouldInlineStylesheet,inlineImages:e.inlineImages,hooks:t},function(e,t){return void 0===t&&(t=function(){return""}),{maskAllInputs:!0,maskTextClass:"amp-mask",blockClass:"amp-block",blockSelector:Le(e),maskTextSelector:De(e,t()),maskInputFn:Fe("input",e,t),maskTextFn:Fe("text",e,t),maskAttributeFn:_e(e,t)}}(s,function(){return i.currentPageUrl})),{applyBackgroundColorToBlockedElements:e.applyBackgroundColorToBlockedElements}),void 0!==e.fullSnapshotIntervalMs&&{checkoutEveryNms:e.fullSnapshotIntervalMs}),{recordCanvas:!1,captureAdoptedStyleSheets:e.captureAdoptedStyleSheets,slimDOMOptions:{script:!0,comment:!0,headFavicon:!0,headWhitespace:!0,headMetaDescKeywords:!0,headMetaSocial:!0,headMetaRobots:!0,headMetaHttpEquiv:!0,headMetaAuthorship:!0,headMetaVerification:!0},errorHandler:function(e){var t=e;if(t.message.includes("insertRule")&&t.message.includes("CSSStyleSheet"))throw t;if(t._external_)throw t;return i.loggerProvider.warn(r,t.toString()),!0}})},e.prototype._recordEventsInChildMode=function(e,t,n,r){try{this.recordCancelCallback&&this.recordCancelCallback(),this.recordCancelCallback=null,this.recordCancelCallback=e(o(o({},this.buildRRWebRecordOptions(n,r,function(){},"Error while capturing replay (child iframe): ")),{recordCrossOriginIframes:!0})),this.loggerProvider.log("Session Replay child iframe capture beginning for session ".concat(t,"."))}catch(e){this.loggerProvider.warn("Failed to initialize session replay in child iframe mode:",e)}},e.prototype.getDeviceId=function(){var e;return null===(e=this.identifiers)||void 0===e?void 0:e.deviceId},e.prototype.getSessionId=function(){var e;return null===(e=this.identifiers)||void 0===e?void 0:e.sessionId},e.prototype.start=function(){return k(this._start())},e.prototype._start=function(){return a(this,void 0,void 0,function(){return l(this,function(e){switch(e.label){case 0:return this.recordingEnabled=!0,this.startChildRecordingOnSetup=!0,[4,this.recordEvents()];case 1:return e.sent(),[2]}})})},e.prototype.stop=function(){this.recordingEnabled=!1,this.startChildRecordingOnSetup=!1,this.recordingGeneration++,this.cancelHiddenSend(),this.windowFocus.stop(),this.stopRecordingEvents(),this.sendEvents()},e.prototype.flush=function(e){var t;return void 0===e&&(e=!1),a(this,void 0,void 0,function(){return l(this,function(n){return[2,null===(t=this.eventsManager)||void 0===t?void 0:t.flush(e)]})})},e.prototype.shutdown=function(){var e,t;this.recordingEnabled=!1,this.startChildRecordingOnSetup=!1,this.recordingGeneration++,this.cancelHiddenSend(),this.windowFocus.stop(),null===(e=this.urlChangeCleanup)||void 0===e||e.call(this),null===(t=this.crossOriginParentSignalCleanup)||void 0===t||t.call(this),this.crossOriginParentSignalCleanup=null,this.teardownEventListeners(!0),this.stopRecordingEvents(),this.sendEvents()},e.prototype.mapSDKType=function(e){return"plugin"===e?"@amplitude/plugin-session-replay-browser":"segment"===e?"@amplitude/segment-session-replay-plugin":null},e.prototype.setMetadata=function(e,t,n,r,i,o,s){var a=(null==e?void 0:e.toString())?z(e.toString()):void 0;this.metadata={joinedConfig:t,localConfig:n,remoteConfig:r,sessionId:e,hashValue:a,sampleRate:t.sampleRate,replaySDKType:this.mapSDKType(s),replaySDKVersion:i,standaloneSDKType:"@amplitude/session-replay-browser",standaloneSDKVersion:o}},e.prototype.initializeNetworkObservers=function(){var e,t,n;return a(this,void 0,void 0,function(){var r,i;return l(this,function(o){switch(o.label){case 0:if(!(null===(n=null===(t=null===(e=this.config)||void 0===e?void 0:e.loggingConfig)||void 0===t?void 0:t.network)||void 0===n?void 0:n.enabled)||this.networkObservers)return[3,4];o.label=1;case 1:return o.trys.push([1,3,,4]),[4,import("./observers-min.js")];case 2:return r=o.sent().NetworkObservers,this.networkObservers=new r,[3,4];case 3:return i=o.sent(),this.loggerProvider.warn("Failed to import or instantiate NetworkObservers:",i),[3,4];case 4:return[2]}})})},e}(),Yn=function(e){return function(){var t=e.config||Ue();return{logger:t.loggerProvider,logLevel:t.logLevel}}},Xn=function(){var e=new Zn;return{init:L(e.init.bind(e),"init",Yn(e)),evaluateTargetingAndCapture:L(e.evaluateTargetingAndCapture.bind(e),"evaluateTargetingAndRecord",Yn(e)),setSessionId:L(e.setSessionId.bind(e),"setSessionId",Yn(e)),getSessionId:L(e.getSessionId.bind(e),"getSessionId",Yn(e)),getSessionReplayProperties:L(e.getSessionReplayProperties.bind(e),"getSessionReplayProperties",Yn(e)),flush:L(e.flush.bind(e),"flush",Yn(e)),start:L(e.start.bind(e),"start",Yn(e)),stop:L(e.stop.bind(e),"stop",Yn(e)),shutdown:L(e.shutdown.bind(e),"shutdown",Yn(e))}}(),er=Xn.init,tr=Xn.setSessionId,nr=Xn.getSessionId,rr=Xn.getSessionReplayProperties,ir=Xn.flush,or=Xn.start,sr=Xn.stop,ar=Xn.shutdown,lr=Xn.evaluateTargetingAndCapture;!function(e){e.SET="$set",e.SET_ONCE="$setOnce",e.ADD="$add",e.APPEND="$append",e.PREPEND="$prepend",e.REMOVE="$remove",e.PREINSERT="$preInsert",e.POSTINSERT="$postInsert",e.UNSET="$unset",e.CLEAR_ALL="$clearAll"}(Gn||(Gn={})),function(e){e.REVENUE_PRODUCT_ID="$productId",e.REVENUE_QUANTITY="$quantity",e.REVENUE_PRICE="$price",e.REVENUE_TYPE="$revenueType",e.REVENUE_CURRENCY="$currency",e.REVENUE="$revenue"}(Qn||(Qn={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(Jn||(Jn={}));const cr=[Gn.SET,Gn.SET_ONCE,Gn.ADD,Gn.APPEND,Gn.PREPEND,Gn.POSTINSERT];function ur(e,t){if("boolean"==typeof e)return e;const n=e&&"object"==typeof e?e[t]:void 0;return!1!==n&&(!function(){var e,t,n=f();return"string"==typeof(null===(t=null===(e=null==n?void 0:n.chrome)||void 0===e?void 0:e.runtime)||void 0===t?void 0:t.id)}()||Boolean(n))}function dr(e){return!0===e||"object"==typeof e&&null!==e}function hr(e,t=e){const n=[],r=["attribution","fileDownloads","formInteractions","pageViews","sessions"];for(const e of r)ur(t,e)&&n.push(e);if(ur(e,"pageUrlEnrichment")&&n.push("pageUrlEnrichment"),!0===e)n.push("networkTracking","elementInteractions","webVitals","frustrationInteractions");else if(e&&"object"==typeof e){dr(e.networkTracking)&&n.push("networkTracking"),dr(e.elementInteractions)&&n.push("elementInteractions"),dr(e.webVitals)&&n.push("webVitals"),dr(e.performanceTracking)&&n.push("performanceTracking");const t=e.frustrationInteractions;(!0===t||t&&"object"==typeof t&&(!1!==t.deadClicks&&null!==t.deadClicks||Boolean(t.errorClicks)))&&n.push("frustrationInteractions")}return n}const vr="1.37.1";class gr{constructor(e){this.name=gr.pluginName,this.type="enrichment",this.config=null,this.sessionReplay={flush:ir,getSessionId:nr,getSessionReplayProperties:rr,init:er,setSessionId:tr,start:or,stop:sr,shutdown:ar,evaluateTargetingAndCapture:lr},this.options=Object.assign({forceSessionTracking:!1},e),this.srInitOptions=this.options}setup(e,t){var n,r,i,o,s,l,c,u,d;return a(this,void 0,void 0,function*(){try{null==e||e.loggerProvider.log(`Installing @amplitude/plugin-session-replay, version ${vr}.`),this.config=e,this.options.forceSessionTracking&&("boolean"==typeof e.defaultTracking?!1===e.defaultTracking&&(e.defaultTracking={pageViews:!1,formInteractions:!1,fileDownloads:!1,sessions:!0}):e.defaultTracking=Object.assign(Object.assign({},e.defaultTracking),{sessions:!0}));const t=W(this.config.instanceName).identityStore.getIdentity().userProperties;this.srInitOptions={instanceName:this.config.instanceName,deviceId:null!==(n=this.options.deviceId)&&void 0!==n?n:this.config.deviceId,optOut:this.config.optOut,sessionId:this.options.customSessionId?void 0:this.config.sessionId,loggerProvider:this.config.loggerProvider,logLevel:this.config.logLevel,flushMaxRetries:this.config.flushMaxRetries,serverZone:this.config.serverZone,configServerUrl:this.options.configServerUrl||(null===(r=this.config.remoteConfig)||void 0===r?void 0:r.serverUrl),trackServerUrl:this.options.trackServerUrl,sampleRate:this.options.sampleRate,semanticCapture:this.options.semanticCapture,semanticAnalyticsContext:{present:!0,autocapture:hr(this.config.autocapture,this.config.defaultTracking)},privacyConfig:{blockSelector:null===(i=this.options.privacyConfig)||void 0===i?void 0:i.blockSelector,maskAttributes:null===(o=this.options.privacyConfig)||void 0===o?void 0:o.maskAttributes,maskSelector:null===(s=this.options.privacyConfig)||void 0===s?void 0:s.maskSelector,unmaskSelector:null===(l=this.options.privacyConfig)||void 0===l?void 0:l.unmaskSelector,defaultMaskLevel:null===(c=this.options.privacyConfig)||void 0===c?void 0:c.defaultMaskLevel},debugMode:this.options.debugMode,shouldInlineStylesheet:this.options.shouldInlineStylesheet,inlineImages:this.options.inlineImages,version:{type:"plugin",version:vr},performanceConfig:this.options.performanceConfig,storeType:this.options.storeType,useWebWorker:null!==(u=this.options.useWebWorker)&&void 0!==u?u:null===(d=this.options.experimental)||void 0===d?void 0:d.useWebWorker,userProperties:t,applyBackgroundColorToBlockedElements:this.options.applyBackgroundColorToBlockedElements,interactionConfig:this.options.interactionConfig,captureDocumentTitle:this.options.captureDocumentTitle,enableUrlChangePolling:this.options.enableUrlChangePolling,urlChangePollingInterval:this.options.urlChangePollingInterval,captureAdoptedStyleSheets:this.options.captureAdoptedStyleSheets,crossOriginIframes:this.options.crossOriginIframes,flushIntervalConfig:this.options.flushIntervalConfig,eagerFullSnapshotSend:this.options.eagerFullSnapshotSend,captureFullSnapshotOnFocus:this.options.captureFullSnapshotOnFocus,maxPersistedEventsSizeBytes:this.options.maxPersistedEventsSizeBytes,maxSingleEventSizeBytes:this.options.maxSingleEventSizeBytes,sendTimeoutMs:this.options.sendTimeoutMs,handleSendEvents:this.options.handleSendEvents,handleFetchConfig:this.options.handleFetchConfig},yield this.sessionReplay.init(e.apiKey,this.srInitOptions).promise}catch(t){null==e||e.loggerProvider.error(`Session Replay: Failed to initialize due to ${t.message}`)}})}onSessionIdChanged(e){var t;return a(this,void 0,void 0,function*(){null===(t=this.config)||void 0===t||t.loggerProvider.debug(`Analytics session id is changed to ${e}, SR session id is ${String(this.sessionReplay.getSessionId())}.`),yield this.sessionReplay.setSessionId(e).promise})}onOptOutChanged(e){var t;return a(this,void 0,void 0,function*(){null===(t=this.config)||void 0===t||t.loggerProvider.debug(`optOut is changed to ${String(e)}, calling ${e?"sessionReplay.shutdown()":"sessionReplay.init()"}.`),e?this.sessionReplay.shutdown():null!=this.config&&(yield this.sessionReplay.init(this.config.apiKey,this.srInitOptions).promise)})}execute(e){var t,n,r;return a(this,void 0,void 0,function*(){try{if(this.options.customSessionId){const t=this.options.customSessionId(e);if(t){t!==this.sessionReplay.getSessionId()&&(yield this.sessionReplay.setSessionId(t).promise);const n=this.sessionReplay.getSessionReplayProperties();e.event_properties=Object.assign(Object.assign({},e.event_properties),n)}}else{const r=null===(t=this.config)||void 0===t?void 0:t.sessionId;if(r&&r!==this.sessionReplay.getSessionId()&&(yield this.sessionReplay.setSessionId(r).promise),r&&r===e.session_id){let t;e.event_type===i.IDENTIFY&&(t=(e=>{if(!e.user_properties)return;let t={};return Object.keys(e.user_properties).forEach(n=>{if(cr.includes(n)){const r=e.user_properties&&e.user_properties[n];t=Object.assign(Object.assign({},t),r)}}),t})(e));const r=f();yield this.sessionReplay.evaluateTargetingAndCapture({event:e,userProperties:t,page:null!=(null===(n=null==r?void 0:r.location)||void 0===n?void 0:n.href)?{url:r.location.href}:void 0});const o=this.sessionReplay.getSessionReplayProperties();e.event_properties=Object.assign(Object.assign({},e.event_properties),o)}}return e.event_type===i.IDENTIFY&&e.event_properties&&delete e.event_properties["[Amplitude] Session Replay ID"],Promise.resolve(e)}catch(t){return null===(r=this.config)||void 0===r||r.loggerProvider.error(`Session Replay: Failed to enrich event due to ${t.message}`),Promise.resolve(e)}})}teardown(){var e;return a(this,void 0,void 0,function*(){try{this.sessionReplay.shutdown(),this.config=null}catch(t){null===(e=this.config)||void 0===e||e.loggerProvider.error(`Session Replay: teardown failed due to ${t.message}`)}})}getSessionReplayProperties(){return this.sessionReplay.getSessionReplayProperties()}start(){return a(this,void 0,void 0,function*(){yield this.sessionReplay.start().promise})}stop(){this.sessionReplay.stop()}}gr.pluginName="@amplitude/plugin-session-replay-browser";const fr=e=>new gr(e);export{gr as S,c as _,d as a,u as b,a as c,l as d,o as e,f as g,Ft as o,fr as s,lt as t};
2
2
  //# sourceMappingURL=index-min.js.map