@sprig-technologies/sprig-bundled
Version:
npm package for the sprig web sdk with bundled dependencies
1 lines • 1.08 MB
Source Map (JSON)
{"version":3,"file":"index-MkVSshrN.cjs","sources":["../../node_modules/@mux/upchunk/dist/upchunk.mjs","../../node_modules/@rrweb/record/dist/record.js","../../src/constants/sprigEvents.ts","../../node_modules/uuid/dist/esm-browser/rng.js","../../node_modules/uuid/dist/esm-browser/stringify.js","../../node_modules/uuid/dist/esm-browser/native.js","../../node_modules/uuid/dist/esm-browser/v4.js","../../src/helpers/BreadcrumbsLogger.ts","../../src/helpers/conflicting_widgets/intercom.ts","../../src/helpers/conflicting_widgets/index.ts","../../node_modules/strict-event-emitter/lib/index.mjs","../../src/helpers/eventEmitter.ts","../../src/helpers/general.ts","../../src/helpers/Deferred.ts","../../src/modules/moduleRegistry.ts","../../src/helpers/network.ts","../../src/controller/shared.ts","../../src/constants/css.ts","../../src/controller/iframe.ts","../../src/controller/constants.ts","../../src/controller/urlMatcher.ts","../../src/helpers/typeguards.ts","../../src/helpers/document.ts","../../src/controller/feedback.ts","../../src/controller/LaunchDarklyIntegration.ts","../../src/controller/OptimizelyIntegration.ts","../../src/controller/Queue.ts","../../src/helpers/metrics/performanceMetric.ts","../../src/helpers/metrics/metricsReporter.ts","../../src/helpers/metrics/domMetrics.ts","../../src/helpers/metrics/eventQueueLatencyMetric.ts","../../src/helpers/metrics/mutationMetrics.ts","../../src/helpers/metrics/index.ts","../../src/controller/controller.ts","../../sprig-browser/core.ts","../../node_modules/@rrweb/types/dist/types.js","../../node_modules/idb/build/index.js","../../src/modules/replay/iframeManager.ts","../../src/modules/replay/network.ts","../../src/modules/replay/semaphore.ts","../../src/modules/replay/getXPath.ts","../../src/modules/replay/utils.ts","../../src/modules/replay/userEventObserver.ts","../../src/modules/replay/replayStorageHelpers.ts","../../src/modules/replay/ReplayStorage.ts","../../src/modules/replay/alwaysOnController.ts","../../src/helpers/metrics/timedActionMetric.ts","../../src/modules/replay/replayController.ts","../../sprig-browser/replay.ts","../index.ts"],"sourcesContent":["var xe=Object.create;var q=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var Ne=Object.getPrototypeOf,De=Object.prototype.hasOwnProperty;var R=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Me=(t,e,n,r)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let i of Fe(e))!De.call(t,i)&&i!==n&&q(t,i,{get:()=>e[i],enumerable:!(r=Ue(e,i))||r.enumerable});return t};var Xe=(t,e,n)=>(n=t!=null?xe(Ne(t)):{},Me(e||!t||!t.__esModule?q(n,\"default\",{value:t,enumerable:!0}):n,t));var Ce=R((Rt,ye)=>{var T;typeof window!=\"undefined\"?T=window:typeof global!=\"undefined\"?T=global:typeof self!=\"undefined\"?T=self:T={};ye.exports=T});var Se=R((Tt,Ee)=>{Ee.exports=ut;var ot=Object.prototype.toString;function ut(t){if(!t)return!1;var e=ot.call(t);return e===\"[object Function]\"||typeof t==\"function\"&&e!==\"[object RegExp]\"||typeof window!=\"undefined\"&&(t===window.setTimeout||t===window.alert||t===window.confirm||t===window.prompt)}});var ve=R((zt,ke)=>{var M=function(t){return t.replace(/^\\s+|\\s+$/g,\"\")},lt=function(t){return Object.prototype.toString.call(t)===\"[object Array]\"};ke.exports=function(t){if(!t)return{};for(var e={},n=M(t).split(`\n`),r=0;r<n.length;r++){var i=n[r],a=i.indexOf(\":\"),o=M(i.slice(0,a)).toLowerCase(),s=M(i.slice(a+1));typeof e[o]==\"undefined\"?e[o]=s:lt(e[o])?e[o].push(s):e[o]=[e[o],s]}return e}});var Re=R((Pt,we)=>{we.exports=ht;var ct=Object.prototype.hasOwnProperty;function ht(){for(var t={},e=0;e<arguments.length;e++){var n=arguments[e];for(var r in n)ct.call(n,r)&&(t[r]=n[r])}return t}});var _e=R((_t,X)=>{\"use strict\";var Te=Ce(),pt=Se(),dt=ve(),ft=Re();X.exports=C;X.exports.default=C;C.XMLHttpRequest=Te.XMLHttpRequest||yt;C.XDomainRequest=\"withCredentials\"in new C.XMLHttpRequest?C.XMLHttpRequest:Te.XDomainRequest;mt([\"get\",\"put\",\"post\",\"patch\",\"head\",\"delete\"],function(t){C[t===\"delete\"?\"del\":t]=function(e,n,r){return n=ze(e,n,r),n.method=t.toUpperCase(),Pe(n)}});function mt(t,e){for(var n=0;n<t.length;n++)e(t[n])}function gt(t){for(var e in t)if(t.hasOwnProperty(e))return!1;return!0}function ze(t,e,n){var r=t;return pt(e)?(n=e,typeof t==\"string\"&&(r={uri:t})):r=ft(e,{uri:t}),r.callback=n,r}function C(t,e,n){return e=ze(t,e,n),Pe(e)}function Pe(t){if(typeof t.callback==\"undefined\")throw new Error(\"callback argument missing\");var e=!1,n=function(S,P,Be){e||(e=!0,t.callback(S,P,Be))};function r(){s.readyState===4&&setTimeout(o,0)}function i(){var u=void 0;if(s.response?u=s.response:u=s.responseText||bt(s),$)try{u=JSON.parse(u)}catch{}return u}function a(u){return clearTimeout(L),u instanceof Error||(u=new Error(\"\"+(u||\"Unknown XMLHttpRequest Error\"))),u.statusCode=0,n(u,V)}function o(){if(!h){var u;clearTimeout(L),t.useXDR&&s.status===void 0?u=200:u=s.status===1223?204:s.status;var S=V,P=null;return u!==0?(S={body:i(),statusCode:u,method:d,headers:{},url:p,rawRequest:s},s.getAllResponseHeaders&&(S.headers=dt(s.getAllResponseHeaders()))):P=new Error(\"Internal XMLHttpRequest Error\"),n(P,S,S.body)}}var s=t.xhr||null;s||(t.cors||t.useXDR?s=new C.XDomainRequest:s=new C.XMLHttpRequest);var c,h,p=s.url=t.uri||t.url,d=s.method=t.method||\"GET\",y=t.body||t.data,f=s.headers=t.headers||{},I=!!t.sync,$=!1,L,V={body:void 0,headers:{},statusCode:0,method:d,url:p,rawRequest:s};if(\"json\"in t&&t.json!==!1&&($=!0,f.accept||f.Accept||(f.Accept=\"application/json\"),d!==\"GET\"&&d!==\"HEAD\"&&(f[\"content-type\"]||f[\"Content-Type\"]||(f[\"Content-Type\"]=\"application/json\"),y=JSON.stringify(t.json===!0?y:t.json))),s.onreadystatechange=r,s.onload=o,s.onerror=a,s.onprogress=function(){},s.onabort=function(){h=!0},s.ontimeout=a,s.open(d,p,!I,t.username,t.password),I||(s.withCredentials=!!t.withCredentials),!I&&t.timeout>0&&(L=setTimeout(function(){if(!h){h=!0,s.abort(\"timeout\");var u=new Error(\"XMLHttpRequest timeout\");u.code=\"ETIMEDOUT\",a(u)}},t.timeout)),s.setRequestHeader)for(c in f)f.hasOwnProperty(c)&&s.setRequestHeader(c,f[c]);else if(t.headers&&!gt(t.headers))throw new Error(\"Headers cannot be set on an XDomainRequest object\");return\"responseType\"in t&&(s.responseType=t.responseType),\"beforeSend\"in t&&typeof t.beforeSend==\"function\"&&t.beforeSend(s),s.send(y||null),s}function bt(t){try{if(t.responseType===\"document\")return t.responseXML;var e=t.responseXML&&t.responseXML.documentElement.nodeName===\"parsererror\";if(t.responseType===\"\"&&!e)return t.responseXML}catch{}return null}function yt(){}});function D(t,e,...n){if(!t)throw new TypeError(ie(e,n))}function ie(t,e){let n=0;return t.replace(/%[os]/gu,()=>se(e[n++]))}function se(t){return typeof t!=\"object\"||t===null?String(t):Object.prototype.toString.call(t)}var G;function He(t){try{let e=t instanceof Error?t:new Error(se(t));if(G){G(e);return}if(typeof dispatchEvent==\"function\"&&typeof ErrorEvent==\"function\")dispatchEvent(new ErrorEvent(\"error\",{error:e,message:e.message}));else if(typeof process!=\"undefined\"&&typeof process.emit==\"function\"){process.emit(\"uncaughtException\",e);return}console.error(e)}catch{}}var m=typeof window!=\"undefined\"?window:typeof self!=\"undefined\"?self:typeof global!=\"undefined\"?global:typeof globalThis!=\"undefined\"?globalThis:void 0,Y;var g=class{constructor(e,n){this.code=e,this.message=n}warn(...e){var n;try{if(Y){Y({...this,args:e});return}let r=((n=new Error().stack)!==null&&n!==void 0?n:\"\").replace(/^(?:.+?\\n){2}/gu,`\n`);console.warn(this.message,...e,r)}catch{}}},je=new g(\"W01\",\"Unable to initialize event under dispatching.\"),We=new g(\"W02\",\"Assigning any falsy value to 'cancelBubble' property has no effect.\"),$e=new g(\"W03\",\"Assigning any truthy value to 'returnValue' property has no effect.\"),Ve=new g(\"W04\",\"Unable to preventDefault on non-cancelable events.\"),qe=new g(\"W05\",\"Unable to preventDefault inside passive event listener invocation.\"),Ge=new g(\"W06\",\"An event listener wasn't added because it has been added already: %o, %o\"),B=new g(\"W07\",\"The %o option value was abandoned because the event listener wasn't added as duplicated.\"),K=new g(\"W08\",\"The 'callback' argument must be a function or an object that has 'handleEvent' method: %o\"),vt=new g(\"W09\",\"Event attribute handler must be a function: %o\"),b=class{static get NONE(){return Z}static get CAPTURING_PHASE(){return J}static get AT_TARGET(){return Q}static get BUBBLING_PHASE(){return ee}constructor(e,n){Object.defineProperty(this,\"isTrusted\",{value:!1,enumerable:!0});let r=n!=null?n:{};N.set(this,{type:String(e),bubbles:Boolean(r.bubbles),cancelable:Boolean(r.cancelable),composed:Boolean(r.composed),target:null,currentTarget:null,stopPropagationFlag:!1,stopImmediatePropagationFlag:!1,canceledFlag:!1,inPassiveListenerFlag:!1,dispatchFlag:!1,timeStamp:Date.now()})}get type(){return l(this).type}get target(){return l(this).target}get srcElement(){return l(this).target}get currentTarget(){return l(this).currentTarget}composedPath(){let e=l(this).currentTarget;return e?[e]:[]}get NONE(){return Z}get CAPTURING_PHASE(){return J}get AT_TARGET(){return Q}get BUBBLING_PHASE(){return ee}get eventPhase(){return l(this).dispatchFlag?2:0}stopPropagation(){l(this).stopPropagationFlag=!0}get cancelBubble(){return l(this).stopPropagationFlag}set cancelBubble(e){e?l(this).stopPropagationFlag=!0:We.warn()}stopImmediatePropagation(){let e=l(this);e.stopPropagationFlag=e.stopImmediatePropagationFlag=!0}get bubbles(){return l(this).bubbles}get cancelable(){return l(this).cancelable}get returnValue(){return!l(this).canceledFlag}set returnValue(e){e?$e.warn():te(l(this))}preventDefault(){te(l(this))}get defaultPrevented(){return l(this).canceledFlag}get composed(){return l(this).composed}get isTrusted(){return!1}get timeStamp(){return l(this).timeStamp}initEvent(e,n=!1,r=!1){let i=l(this);if(i.dispatchFlag){je.warn();return}N.set(this,{...i,type:String(e),bubbles:Boolean(n),cancelable:Boolean(r),target:null,currentTarget:null,stopPropagationFlag:!1,stopImmediatePropagationFlag:!1,canceledFlag:!1})}},Z=0,J=1,Q=2,ee=3,N=new WeakMap;function l(t,e=\"this\"){let n=N.get(t);return D(n!=null,\"'%s' must be an object that Event constructor created, but got another one: %o\",e,t),n}function te(t){if(t.inPassiveListenerFlag){qe.warn();return}if(!t.cancelable){Ve.warn();return}t.canceledFlag=!0}Object.defineProperty(b,\"NONE\",{enumerable:!0});Object.defineProperty(b,\"CAPTURING_PHASE\",{enumerable:!0});Object.defineProperty(b,\"AT_TARGET\",{enumerable:!0});Object.defineProperty(b,\"BUBBLING_PHASE\",{enumerable:!0});var x=Object.getOwnPropertyNames(b.prototype);for(let t=0;t<x.length;++t)x[t]!==\"constructor\"&&Object.defineProperty(b.prototype,x[t],{enumerable:!0});typeof m!=\"undefined\"&&typeof m.Event!=\"undefined\"&&Object.setPrototypeOf(b.prototype,m.Event.prototype);function Ye(t){return m.DOMException?new m.DOMException(t,\"InvalidStateError\"):(v==null&&(v=class ae extends Error{constructor(n){super(n),Error.captureStackTrace&&Error.captureStackTrace(this,ae)}get code(){return 11}get name(){return\"InvalidStateError\"}},Object.defineProperties(v.prototype,{code:{enumerable:!0},name:{enumerable:!0}}),re(v),re(v.prototype)),new v(t))}var v,ne={INDEX_SIZE_ERR:1,DOMSTRING_SIZE_ERR:2,HIERARCHY_REQUEST_ERR:3,WRONG_DOCUMENT_ERR:4,INVALID_CHARACTER_ERR:5,NO_DATA_ALLOWED_ERR:6,NO_MODIFICATION_ALLOWED_ERR:7,NOT_FOUND_ERR:8,NOT_SUPPORTED_ERR:9,INUSE_ATTRIBUTE_ERR:10,INVALID_STATE_ERR:11,SYNTAX_ERR:12,INVALID_MODIFICATION_ERR:13,NAMESPACE_ERR:14,INVALID_ACCESS_ERR:15,VALIDATION_ERR:16,TYPE_MISMATCH_ERR:17,SECURITY_ERR:18,NETWORK_ERR:19,ABORT_ERR:20,URL_MISMATCH_ERR:21,QUOTA_EXCEEDED_ERR:22,TIMEOUT_ERR:23,INVALID_NODE_TYPE_ERR:24,DATA_CLONE_ERR:25};function re(t){let e=Object.keys(ne);for(let n=0;n<e.length;++n){let r=e[n],i=ne[r];Object.defineProperty(t,r,{get(){return i},configurable:!0,enumerable:!0})}}var w=class extends b{static wrap(e){return new(ue(e))(e)}constructor(e){super(e.type,{bubbles:e.bubbles,cancelable:e.cancelable,composed:e.composed}),e.cancelBubble&&super.stopPropagation(),e.defaultPrevented&&super.preventDefault(),oe.set(this,{original:e});let n=Object.keys(e);for(let r=0;r<n.length;++r){let i=n[r];i in this||Object.defineProperty(this,i,le(e,i))}}stopPropagation(){super.stopPropagation();let{original:e}=E(this);\"stopPropagation\"in e&&e.stopPropagation()}get cancelBubble(){return super.cancelBubble}set cancelBubble(e){super.cancelBubble=e;let{original:n}=E(this);\"cancelBubble\"in n&&(n.cancelBubble=e)}stopImmediatePropagation(){super.stopImmediatePropagation();let{original:e}=E(this);\"stopImmediatePropagation\"in e&&e.stopImmediatePropagation()}get returnValue(){return super.returnValue}set returnValue(e){super.returnValue=e;let{original:n}=E(this);\"returnValue\"in n&&(n.returnValue=e)}preventDefault(){super.preventDefault();let{original:e}=E(this);\"preventDefault\"in e&&e.preventDefault()}get timeStamp(){let{original:e}=E(this);return\"timeStamp\"in e?e.timeStamp:super.timeStamp}},oe=new WeakMap;function E(t){let e=oe.get(t);return D(e!=null,\"'this' is expected an Event object, but got\",t),e}var _=new WeakMap;_.set(Object.prototype,w);typeof m!=\"undefined\"&&typeof m.Event!=\"undefined\"&&_.set(m.Event.prototype,w);function ue(t){let e=Object.getPrototypeOf(t);if(e==null)return w;let n=_.get(e);return n==null&&(n=Ke(ue(e),e),_.set(e,n)),n}function Ke(t,e){class n extends t{}let r=Object.keys(e);for(let i=0;i<r.length;++i)Object.defineProperty(n.prototype,r[i],le(e,r[i]));return n}function le(t,e){let n=Object.getOwnPropertyDescriptor(t,e);return{get(){let r=E(this).original,i=r[e];return typeof i==\"function\"?i.bind(r):i},set(r){let i=E(this).original;i[e]=r},configurable:n.configurable,enumerable:n.enumerable}}function Ze(t,e,n,r,i,a){return{callback:t,flags:(e?1:0)|(n?2:0)|(r?4:0),signal:i,signalListener:a}}function Je(t){t.flags|=8}function ce(t){return(t.flags&1)===1}function he(t){return(t.flags&2)===2}function pe(t){return(t.flags&4)===4}function Qe(t){return(t.flags&8)===8}function et({callback:t},e,n){try{typeof t==\"function\"?t.call(e,n):typeof t.handleEvent==\"function\"&&t.handleEvent(n)}catch(r){He(r)}}function de({listeners:t},e,n){for(let r=0;r<t.length;++r)if(t[r].callback===e&&ce(t[r])===n)return r;return-1}function tt(t,e,n,r,i,a){let o;a&&(o=fe.bind(null,t,e,n),a.addEventListener(\"abort\",o));let s=Ze(e,n,r,i,a,o);return t.cow?(t.cow=!1,t.listeners=[...t.listeners,s]):t.listeners.push(s),s}function fe(t,e,n){let r=de(t,e,n);return r!==-1?me(t,r):!1}function me(t,e,n=!1){let r=t.listeners[e];return Je(r),r.signal&&r.signal.removeEventListener(\"abort\",r.signalListener),t.cow&&!n?(t.cow=!1,t.listeners=t.listeners.filter((i,a)=>a!==e),!1):(t.listeners.splice(e,1),!0)}function nt(){return Object.create(null)}function rt(t,e){var n;return(n=t[e])!==null&&n!==void 0?n:t[e]={attrCallback:void 0,attrListener:void 0,cow:!1,listeners:[]}}var k=class{constructor(){ge.set(this,nt())}addEventListener(e,n,r){let i=U(this),{callback:a,capture:o,once:s,passive:c,signal:h,type:p}=it(e,n,r);if(a==null||(h==null?void 0:h.aborted))return;let d=rt(i,p),y=de(d,a,o);if(y!==-1){at(d.listeners[y],c,s,h);return}tt(d,a,o,c,s,h)}removeEventListener(e,n,r){let i=U(this),{callback:a,capture:o,type:s}=st(e,n,r),c=i[s];a!=null&&c&&fe(c,a,o)}dispatchEvent(e){let n=U(this)[String(e.type)];if(n==null)return!0;let r=e instanceof b?e:w.wrap(e),i=l(r,\"event\");if(i.dispatchFlag)throw Ye(\"This event has been in dispatching.\");if(i.dispatchFlag=!0,i.target=i.currentTarget=this,!i.stopPropagationFlag){let{cow:a,listeners:o}=n;n.cow=!0;for(let s=0;s<o.length;++s){let c=o[s];if(!Qe(c)&&(pe(c)&&me(n,s,!a)&&(s-=1),i.inPassiveListenerFlag=he(c),et(c,this,r),i.inPassiveListenerFlag=!1,i.stopImmediatePropagationFlag))break}a||(n.cow=!1)}return i.target=null,i.currentTarget=null,i.stopImmediatePropagationFlag=!1,i.stopPropagationFlag=!1,i.dispatchFlag=!1,!i.canceledFlag}},ge=new WeakMap;function U(t,e=\"this\"){let n=ge.get(t);return D(n!=null,\"'%s' must be an object that EventTarget constructor created, but got another one: %o\",e,t),n}function it(t,e,n){var r;return be(e),typeof n==\"object\"&&n!==null?{type:String(t),callback:e!=null?e:void 0,capture:Boolean(n.capture),passive:Boolean(n.passive),once:Boolean(n.once),signal:(r=n.signal)!==null&&r!==void 0?r:void 0}:{type:String(t),callback:e!=null?e:void 0,capture:Boolean(n),passive:!1,once:!1,signal:void 0}}function st(t,e,n){return be(e),typeof n==\"object\"&&n!==null?{type:String(t),callback:e!=null?e:void 0,capture:Boolean(n.capture)}:{type:String(t),callback:e!=null?e:void 0,capture:Boolean(n)}}function be(t){if(!(typeof t==\"function\"||typeof t==\"object\"&&t!==null&&typeof t.handleEvent==\"function\")){if(t==null||typeof t==\"object\"){K.warn(t);return}throw new TypeError(ie(K.message,[t]))}}function at(t,e,n,r){Ge.warn(ce(t)?\"capture\":\"bubble\",t.callback),he(t)!==e&&B.warn(\"passive\"),pe(t)!==n&&B.warn(\"once\"),t.signal!==r&&B.warn(\"signal\")}var F=Object.getOwnPropertyNames(k.prototype);for(let t=0;t<F.length;++t)F[t]!==\"constructor\"&&Object.defineProperty(k.prototype,F[t],{enumerable:!0});typeof m!=\"undefined\"&&typeof m.EventTarget!=\"undefined\"&&Object.setPrototypeOf(k.prototype,m.EventTarget.prototype);var Ae=Xe(_e()),Oe=30720,A=512e3,O=256,H=(t,{minChunkSize:e=O,maxChunkSize:n=A}={})=>t==null||typeof t==\"number\"&&t>=256&&t%256===0&&t>=e&&t<=n,j=(t,{minChunkSize:e=O,maxChunkSize:n=A}={})=>new TypeError(`chunkSize ${t} must be a positive number in multiples of 256, between ${e} and ${n}`),W=class{constructor(e,n={}){this.readableStream=e;var r,i,a;if(!H(n.defaultChunkSize,n))throw j(n.defaultChunkSize,n);this.defaultChunkSize=(r=n.defaultChunkSize)!=null?r:Oe,this.minChunkSize=(i=n.minChunkSize)!=null?i:O,this.maxChunkSize=(a=n.maxChunkSize)!=null?a:A}get chunkSize(){var e;return(e=this._chunkSize)!=null?e:this.defaultChunkSize}set chunkSize(e){if(!H(e,this))throw j(e,this);this._chunkSize=e}get chunkByteSize(){return this.chunkSize*1024}async*[Symbol.asyncIterator](){let e,n=this.readableStream.getReader();try{for(;;){let{done:r,value:i}=await n.read();if(r){if(e){let o=e;e=void 0,yield o}break}let a=i instanceof Uint8Array?new Blob([i],{type:\"application/octet-stream\"}):i;for(e=e?new Blob([e,a]):a;e;)if(e.size===this.chunkByteSize){let o=e;e=void 0,yield o;break}else{if(e.size<this.chunkByteSize)break;{let o=e.slice(0,this.chunkByteSize);e=e.slice(this.chunkByteSize),yield o}}}}finally{if(e){let r=e;e=void 0,yield r}n.releaseLock();return}}},Ct=[200,201,202,204,308],Ie=[408,502,503,504],Le=(t,e)=>!!t&&Ct.includes(t.statusCode),Et=(t,{retryCodes:e=Ie})=>!t||e.includes(t.statusCode),St=(t,e)=>e.attemptCount>=e.attempts||!(Le(t)||Et(t,e)),z=class{static createUpload(e){return new z(e)}constructor(e){this.endpoint=e.endpoint,this.file=e.file,this.headers=e.headers||{},this.method=e.method||\"PUT\",this.attempts=e.attempts||5,this.delayBeforeAttempt=e.delayBeforeAttempt||1,this.retryCodes=e.retryCodes||Ie,this.dynamicChunkSize=e.dynamicChunkSize||!1,this.maxFileBytes=(e.maxFileSize||0)*1024,this.chunkCount=0,this.attemptCount=0,this.offline=!1,this._paused=!1,this.success=!1,this.nextChunkRangeStart=0,this.chunkedStreamIterable=new W(this.file.stream(),{...e,defaultChunkSize:e.chunkSize}),this.chunkedStreamIterator=this.chunkedStreamIterable[Symbol.asyncIterator](),this.totalChunks=Math.ceil(this.file.size/this.chunkByteSize),this.eventTarget=new k,this.validateOptions(),this.getEndpoint().then(()=>this.sendChunks()),typeof window!=\"undefined\"&&(window.addEventListener(\"online\",()=>{!this.offline||(this.offline=!1,this.dispatch(\"online\"),this.sendChunks())}),window.addEventListener(\"offline\",()=>{this.offline=!0,this.dispatch(\"offline\")}))}get maxChunkSize(){var e,n;return(n=(e=this.chunkedStreamIterable)==null?void 0:e.maxChunkSize)!=null?n:A}get minChunkSize(){var e,n;return(n=(e=this.chunkedStreamIterable)==null?void 0:e.minChunkSize)!=null?n:O}get chunkSize(){var e,n;return(n=(e=this.chunkedStreamIterable)==null?void 0:e.chunkSize)!=null?n:Oe}set chunkSize(e){this.chunkedStreamIterable.chunkSize=e}get chunkByteSize(){return this.chunkedStreamIterable.chunkByteSize}get totalChunkSize(){return Math.ceil(this.file.size/this.chunkByteSize)}on(e,n){this.eventTarget.addEventListener(e,n)}once(e,n){this.eventTarget.addEventListener(e,n,{once:!0})}off(e,n){this.eventTarget.removeEventListener(e,n)}get paused(){return this._paused}abort(){var e;this.pause(),(e=this.currentXhr)==null||e.abort()}pause(){this._paused=!0}resume(){this._paused&&(this._paused=!1,this.sendChunks())}dispatch(e,n){let r=new CustomEvent(e,{detail:n});this.eventTarget.dispatchEvent(r)}validateOptions(){if(!this.endpoint||typeof this.endpoint!=\"function\"&&typeof this.endpoint!=\"string\")throw new TypeError(\"endpoint must be defined as a string or a function that returns a promise\");if(!(this.file instanceof File))throw new TypeError(\"file must be a File object\");if(this.headers&&typeof this.headers!=\"function\"&&typeof this.headers!=\"object\")throw new TypeError(\"headers must be null, an object, or a function that returns an object or a promise\");if(!H(this.chunkSize,{maxChunkSize:this.maxChunkSize,minChunkSize:this.minChunkSize}))throw j(this.chunkSize,{maxChunkSize:this.maxChunkSize,minChunkSize:this.minChunkSize});if(this.maxChunkSize&&(typeof this.maxChunkSize!=\"number\"||this.maxChunkSize<256||this.maxChunkSize%256!==0||this.maxChunkSize<this.chunkSize||this.maxChunkSize<this.minChunkSize))throw new TypeError(`maxChunkSize must be a positive number in multiples of 256, and larger than or equal to both ${this.minChunkSize} and ${this.chunkSize}`);if(this.minChunkSize&&(typeof this.minChunkSize!=\"number\"||this.minChunkSize<256||this.minChunkSize%256!==0||this.minChunkSize>this.chunkSize||this.minChunkSize>this.maxChunkSize))throw new TypeError(`minChunkSize must be a positive number in multiples of 256, and smaller than ${this.chunkSize} and ${this.maxChunkSize}`);if(this.maxFileBytes>0&&this.maxFileBytes<this.file.size)throw new Error(`file size exceeds maximum (${this.file.size} > ${this.maxFileBytes})`);if(this.attempts&&(typeof this.attempts!=\"number\"||this.attempts<=0))throw new TypeError(\"retries must be a positive number\");if(this.delayBeforeAttempt&&(typeof this.delayBeforeAttempt!=\"number\"||this.delayBeforeAttempt<0))throw new TypeError(\"delayBeforeAttempt must be a positive number\")}getEndpoint(){return typeof this.endpoint==\"string\"?(this.endpointValue=this.endpoint,Promise.resolve(this.endpoint)):this.endpoint(this.file).then(e=>(this.endpointValue=e,this.endpointValue))}xhrPromise(e){let n=r=>{r.upload.onprogress=i=>{var p;let a=this.totalChunks-this.chunkCount,o=(this.file.size-this.nextChunkRangeStart)/this.file.size/a,s=this.nextChunkRangeStart/this.file.size,h=i.loaded/((p=i.total)!=null?p:this.chunkByteSize)*o;this.dispatch(\"progress\",Math.min((s+h)*100,100))}};return new Promise((r,i)=>{this.currentXhr=(0,Ae.default)({...e,beforeSend:n},(a,o)=>(this.currentXhr=void 0,a?i(a):r(o)))})}async sendChunk(e){let n=this.nextChunkRangeStart,r=n+e.size-1,a={...await(typeof this.headers==\"function\"?this.headers():this.headers),\"Content-Type\":this.file.type,\"Content-Range\":`bytes ${n}-${r}/${this.file.size}`};return this.dispatch(\"attempt\",{chunkNumber:this.chunkCount,totalChunks:this.totalChunks,chunkSize:this.chunkSize}),this.xhrPromise({headers:a,url:this.endpointValue,method:this.method,body:e})}async sendChunkWithRetries(e){let n=async(s,c)=>{var d;let p=(new Date().getTime()-this.lastChunkStart.getTime())/1e3;if(this.dispatch(\"chunkSuccess\",{chunk:this.chunkCount,chunkSize:this.chunkSize,attempts:this.attemptCount,timeInterval:p,response:s}),this.attemptCount=0,this.chunkCount=((d=this.chunkCount)!=null?d:0)+1,this.nextChunkRangeStart=this.nextChunkRangeStart+this.chunkByteSize,this.dynamicChunkSize){let y=this.chunkSize;p<10?y=Math.min(this.chunkSize*2,this.maxChunkSize):p>30&&(y=Math.max(this.chunkSize/2,this.minChunkSize)),this.chunkSize=Math.ceil(y/256)*256;let f=(this.file.size-this.nextChunkRangeStart)/this.chunkByteSize;this.totalChunks=Math.ceil(this.chunkCount+f)}return!0},r=async(s,c)=>(this.dispatch(\"error\",{message:`Server responded with ${s.statusCode}. Stopping upload.`,chunk:this.chunkCount,attempts:this.attemptCount}),!1),i=async(s,c)=>(this.dispatch(\"attemptFailure\",{message:`An error occured uploading chunk ${this.chunkCount}. ${this.attempts-this.attemptCount} retries left.`,chunkNumber:this.chunkCount,attemptsLeft:this.attempts-this.attemptCount}),new Promise(h=>{setTimeout(async()=>{if(this._paused||this.offline){this.pendingChunk=e,h(!1);return}let p=await this.sendChunkWithRetries(e);h(p)},this.delayBeforeAttempt*1e3)})),a;try{this.attemptCount=this.attemptCount+1,this.lastChunkStart=new Date,a=await this.sendChunk(e)}catch{}let o={retryCodes:this.retryCodes,attemptCount:this.attemptCount,attempts:this.attempts};return Le(a,o)?n(a,e):St(a,o)?r(a,e):i(a,e)}async sendChunks(){if(this.pendingChunk&&!(this._paused||this.offline)){let e=this.pendingChunk;this.pendingChunk=void 0;let n=await this.sendChunkWithRetries(e);this.success&&n&&this.dispatch(\"success\")}for(;!(this.success||this._paused||this.offline);){let{value:e,done:n}=await this.chunkedStreamIterator.next(),r=!e&&n;if(e&&(r=await this.sendChunkWithRetries(e)),this.success=!!n,this.success&&r&&this.dispatch(\"success\"),!r)return}}},It=z.createUpload;export{W as ChunkedStreamIterable,z as UpChunk,It as createUpload,j as getChunkSizeError,H as isValidChunkSize};\n//# sourceMappingURL=upchunk.mjs.map\n","var __defProp = Object.defineProperty;\nvar __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;\nvar __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== \"symbol\" ? key + \"\" : key, value);\nvar _a;\nvar __defProp$1 = Object.defineProperty;\nvar __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;\nvar __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== \"symbol\" ? key + \"\" : key, value);\nvar NodeType$2 = /* @__PURE__ */ ((NodeType2) => {\n NodeType2[NodeType2[\"Document\"] = 0] = \"Document\";\n NodeType2[NodeType2[\"DocumentType\"] = 1] = \"DocumentType\";\n NodeType2[NodeType2[\"Element\"] = 2] = \"Element\";\n NodeType2[NodeType2[\"Text\"] = 3] = \"Text\";\n NodeType2[NodeType2[\"CDATA\"] = 4] = \"CDATA\";\n NodeType2[NodeType2[\"Comment\"] = 5] = \"Comment\";\n return NodeType2;\n})(NodeType$2 || {});\nconst testableAccessors$1 = {\n Node: [\"childNodes\", \"parentNode\", \"parentElement\", \"textContent\"],\n ShadowRoot: [\"host\", \"styleSheets\"],\n Element: [\"shadowRoot\", \"querySelector\", \"querySelectorAll\"],\n MutationObserver: []\n};\nconst testableMethods$1 = {\n Node: [\"contains\", \"getRootNode\"],\n ShadowRoot: [\"getSelection\"],\n Element: [],\n MutationObserver: [\"constructor\"]\n};\nconst untaintedBasePrototype$1 = {};\nfunction getUntaintedPrototype$1(key) {\n if (untaintedBasePrototype$1[key])\n return untaintedBasePrototype$1[key];\n const defaultObj = globalThis[key];\n const defaultPrototype = defaultObj.prototype;\n const accessorNames = key in testableAccessors$1 ? testableAccessors$1[key] : void 0;\n const isUntaintedAccessors = Boolean(\n accessorNames && // @ts-expect-error 2345\n accessorNames.every(\n (accessor) => {\n var _a2, _b;\n return Boolean(\n (_b = (_a2 = Object.getOwnPropertyDescriptor(defaultPrototype, accessor)) == null ? void 0 : _a2.get) == null ? void 0 : _b.toString().includes(\"[native code]\")\n );\n }\n )\n );\n const methodNames = key in testableMethods$1 ? testableMethods$1[key] : void 0;\n const isUntaintedMethods = Boolean(\n methodNames && methodNames.every(\n // @ts-expect-error 2345\n (method) => {\n var _a2;\n return typeof defaultPrototype[method] === \"function\" && ((_a2 = defaultPrototype[method]) == null ? void 0 : _a2.toString().includes(\"[native code]\"));\n }\n )\n );\n if (isUntaintedAccessors && isUntaintedMethods) {\n untaintedBasePrototype$1[key] = defaultObj.prototype;\n return defaultObj.prototype;\n }\n try {\n const iframeEl = document.createElement(\"iframe\");\n document.body.appendChild(iframeEl);\n const win = iframeEl.contentWindow;\n if (!win) return defaultObj.prototype;\n const untaintedObject = win[key].prototype;\n document.body.removeChild(iframeEl);\n if (!untaintedObject) return defaultPrototype;\n return untaintedBasePrototype$1[key] = untaintedObject;\n } catch {\n return defaultPrototype;\n }\n}\nconst untaintedAccessorCache$1 = {};\nfunction getUntaintedAccessor$1(key, instance, accessor) {\n var _a2;\n const cacheKey = `${key}.${String(accessor)}`;\n if (untaintedAccessorCache$1[cacheKey])\n return untaintedAccessorCache$1[cacheKey].call(\n instance\n );\n const untaintedPrototype = getUntaintedPrototype$1(key);\n const untaintedAccessor = (_a2 = Object.getOwnPropertyDescriptor(\n untaintedPrototype,\n accessor\n )) == null ? void 0 : _a2.get;\n if (!untaintedAccessor) return instance[accessor];\n untaintedAccessorCache$1[cacheKey] = untaintedAccessor;\n return untaintedAccessor.call(instance);\n}\nconst untaintedMethodCache$1 = {};\nfunction getUntaintedMethod$1(key, instance, method) {\n const cacheKey = `${key}.${String(method)}`;\n if (untaintedMethodCache$1[cacheKey])\n return untaintedMethodCache$1[cacheKey].bind(\n instance\n );\n const untaintedPrototype = getUntaintedPrototype$1(key);\n const untaintedMethod = untaintedPrototype[method];\n if (typeof untaintedMethod !== \"function\") return instance[method];\n untaintedMethodCache$1[cacheKey] = untaintedMethod;\n return untaintedMethod.bind(instance);\n}\nfunction childNodes$1(n2) {\n return getUntaintedAccessor$1(\"Node\", n2, \"childNodes\");\n}\nfunction parentNode$1(n2) {\n return getUntaintedAccessor$1(\"Node\", n2, \"parentNode\");\n}\nfunction parentElement$1(n2) {\n return getUntaintedAccessor$1(\"Node\", n2, \"parentElement\");\n}\nfunction textContent$1(n2) {\n return getUntaintedAccessor$1(\"Node\", n2, \"textContent\");\n}\nfunction contains$1(n2, other) {\n return getUntaintedMethod$1(\"Node\", n2, \"contains\")(other);\n}\nfunction getRootNode$1(n2) {\n return getUntaintedMethod$1(\"Node\", n2, \"getRootNode\")();\n}\nfunction host$1(n2) {\n if (!n2 || !(\"host\" in n2)) return null;\n return getUntaintedAccessor$1(\"ShadowRoot\", n2, \"host\");\n}\nfunction styleSheets$1(n2) {\n return n2.styleSheets;\n}\nfunction shadowRoot$1(n2) {\n if (!n2 || !(\"shadowRoot\" in n2)) return null;\n return getUntaintedAccessor$1(\"Element\", n2, \"shadowRoot\");\n}\nfunction querySelector$1(n2, selectors) {\n return getUntaintedAccessor$1(\"Element\", n2, \"querySelector\")(selectors);\n}\nfunction querySelectorAll$1(n2, selectors) {\n return getUntaintedAccessor$1(\"Element\", n2, \"querySelectorAll\")(selectors);\n}\nfunction mutationObserverCtor$1() {\n return getUntaintedPrototype$1(\"MutationObserver\").constructor;\n}\nconst index$1 = {\n childNodes: childNodes$1,\n parentNode: parentNode$1,\n parentElement: parentElement$1,\n textContent: textContent$1,\n contains: contains$1,\n getRootNode: getRootNode$1,\n host: host$1,\n styleSheets: styleSheets$1,\n shadowRoot: shadowRoot$1,\n querySelector: querySelector$1,\n querySelectorAll: querySelectorAll$1,\n mutationObserver: mutationObserverCtor$1\n};\nfunction isElement(n2) {\n return n2.nodeType === n2.ELEMENT_NODE;\n}\nfunction isShadowRoot(n2) {\n const hostEl = (\n // anchor and textarea elements also have a `host` property\n // but only shadow roots have a `mode` property\n n2 && \"host\" in n2 && \"mode\" in n2 && index$1.host(n2) || null\n );\n return Boolean(\n hostEl && \"shadowRoot\" in hostEl && index$1.shadowRoot(hostEl) === n2\n );\n}\nfunction isNativeShadowDom(shadowRoot2) {\n return Object.prototype.toString.call(shadowRoot2) === \"[object ShadowRoot]\";\n}\nfunction fixBrowserCompatibilityIssuesInCSS(cssText) {\n if (cssText.includes(\" background-clip: text;\") && !cssText.includes(\" -webkit-background-clip: text;\")) {\n cssText = cssText.replace(\n /\\sbackground-clip:\\s*text;/g,\n \" -webkit-background-clip: text; background-clip: text;\"\n );\n }\n return cssText;\n}\nfunction escapeImportStatement(rule2) {\n const { cssText } = rule2;\n if (cssText.split('\"').length < 3) return cssText;\n const statement = [\"@import\", `url(${JSON.stringify(rule2.href)})`];\n if (rule2.layerName === \"\") {\n statement.push(`layer`);\n } else if (rule2.layerName) {\n statement.push(`layer(${rule2.layerName})`);\n }\n if (rule2.supportsText) {\n statement.push(`supports(${rule2.supportsText})`);\n }\n if (rule2.media.length) {\n statement.push(rule2.media.mediaText);\n }\n return statement.join(\" \") + \";\";\n}\nfunction stringifyStylesheet(s2) {\n try {\n const rules2 = s2.rules || s2.cssRules;\n if (!rules2) {\n return null;\n }\n const stringifiedRules = Array.from(\n rules2,\n (rule2) => stringifyRule(rule2, s2.href)\n ).join(\"\");\n return fixBrowserCompatibilityIssuesInCSS(stringifiedRules);\n } catch (error) {\n return null;\n }\n}\nfunction stringifyRule(rule2, sheetHref) {\n if (isCSSImportRule(rule2)) {\n let importStringified;\n try {\n importStringified = // for same-origin stylesheets,\n // we can access the imported stylesheet rules directly\n stringifyStylesheet(rule2.styleSheet) || // work around browser issues with the raw string `@import url(...)` statement\n escapeImportStatement(rule2);\n } catch (error) {\n importStringified = rule2.cssText;\n }\n if (rule2.styleSheet.href) {\n return absolutifyURLs(importStringified, rule2.styleSheet.href);\n }\n return importStringified;\n } else {\n let ruleStringified = rule2.cssText;\n if (isCSSStyleRule(rule2) && rule2.selectorText.includes(\":\")) {\n ruleStringified = fixSafariColons(ruleStringified);\n }\n if (sheetHref) {\n return absolutifyURLs(ruleStringified, sheetHref);\n }\n return ruleStringified;\n }\n}\nfunction fixSafariColons(cssStringified) {\n const regex = /(\\[(?:[\\w-]+)[^\\\\])(:(?:[\\w-]+)\\])/gm;\n return cssStringified.replace(regex, \"$1\\\\$2\");\n}\nfunction isCSSImportRule(rule2) {\n return \"styleSheet\" in rule2;\n}\nfunction isCSSStyleRule(rule2) {\n return \"selectorText\" in rule2;\n}\nclass Mirror {\n constructor() {\n __publicField$1(this, \"idNodeMap\", /* @__PURE__ */ new Map());\n __publicField$1(this, \"nodeMetaMap\", /* @__PURE__ */ new WeakMap());\n }\n getId(n2) {\n var _a2;\n if (!n2) return -1;\n const id = (_a2 = this.getMeta(n2)) == null ? void 0 : _a2.id;\n return id ?? -1;\n }\n getNode(id) {\n return this.idNodeMap.get(id) || null;\n }\n getIds() {\n return Array.from(this.idNodeMap.keys());\n }\n getMeta(n2) {\n return this.nodeMetaMap.get(n2) || null;\n }\n // removes the node from idNodeMap\n // doesn't remove the node from nodeMetaMap\n removeNodeFromMap(n2) {\n const id = this.getId(n2);\n this.idNodeMap.delete(id);\n if (n2.childNodes) {\n n2.childNodes.forEach(\n (childNode) => this.removeNodeFromMap(childNode)\n );\n }\n }\n has(id) {\n return this.idNodeMap.has(id);\n }\n hasNode(node2) {\n return this.nodeMetaMap.has(node2);\n }\n add(n2, meta) {\n const id = meta.id;\n this.idNodeMap.set(id, n2);\n this.nodeMetaMap.set(n2, meta);\n }\n replace(id, n2) {\n const oldNode = this.getNode(id);\n if (oldNode) {\n const meta = this.nodeMetaMap.get(oldNode);\n if (meta) this.nodeMetaMap.set(n2, meta);\n }\n this.idNodeMap.set(id, n2);\n }\n reset() {\n this.idNodeMap = /* @__PURE__ */ new Map();\n this.nodeMetaMap = /* @__PURE__ */ new WeakMap();\n }\n}\nfunction createMirror$2() {\n return new Mirror();\n}\nfunction maskInputValue({\n element,\n maskInputOptions,\n tagName,\n type,\n value,\n maskInputFn\n}) {\n let text = value || \"\";\n const actualType = type && toLowerCase(type);\n if (maskInputOptions[tagName.toLowerCase()] || actualType && maskInputOptions[actualType]) {\n if (maskInputFn) {\n text = maskInputFn(text, element);\n } else {\n text = \"*\".repeat(text.length);\n }\n }\n return text;\n}\nfunction toLowerCase(str) {\n return str.toLowerCase();\n}\nconst ORIGINAL_ATTRIBUTE_NAME = \"__rrweb_original__\";\nfunction is2DCanvasBlank(canvas) {\n const ctx = canvas.getContext(\"2d\");\n if (!ctx) return true;\n const chunkSize = 50;\n for (let x2 = 0; x2 < canvas.width; x2 += chunkSize) {\n for (let y = 0; y < canvas.height; y += chunkSize) {\n const getImageData = ctx.getImageData;\n const originalGetImageData = ORIGINAL_ATTRIBUTE_NAME in getImageData ? getImageData[ORIGINAL_ATTRIBUTE_NAME] : getImageData;\n const pixelBuffer = new Uint32Array(\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access\n originalGetImageData.call(\n ctx,\n x2,\n y,\n Math.min(chunkSize, canvas.width - x2),\n Math.min(chunkSize, canvas.height - y)\n ).data.buffer\n );\n if (pixelBuffer.some((pixel) => pixel !== 0)) return false;\n }\n }\n return true;\n}\nfunction getInputType(element) {\n const type = element.type;\n return element.hasAttribute(\"data-rr-is-password\") ? \"password\" : type ? (\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n toLowerCase(type)\n ) : null;\n}\nfunction extractFileExtension(path, baseURL) {\n let url;\n try {\n url = new URL(path, baseURL ?? window.location.href);\n } catch (err) {\n return null;\n }\n const regex = /\\.([0-9a-z]+)(?:$)/i;\n const match = url.pathname.match(regex);\n return (match == null ? void 0 : match[1]) ?? null;\n}\nfunction extractOrigin(url) {\n let origin = \"\";\n if (url.indexOf(\"//\") > -1) {\n origin = url.split(\"/\").slice(0, 3).join(\"/\");\n } else {\n origin = url.split(\"/\")[0];\n }\n origin = origin.split(\"?\")[0];\n return origin;\n}\nconst URL_IN_CSS_REF = /url\\((?:(')([^']*)'|(\")(.*?)\"|([^)]*))\\)/gm;\nconst URL_PROTOCOL_MATCH = /^(?:[a-z+]+:)?\\/\\//i;\nconst URL_WWW_MATCH = /^www\\..*/i;\nconst DATA_URI = /^(data:)([^,]*),(.*)/i;\nfunction absolutifyURLs(cssText, href) {\n return (cssText || \"\").replace(\n URL_IN_CSS_REF,\n (origin, quote1, path1, quote2, path2, path3) => {\n const filePath = path1 || path2 || path3;\n const maybeQuote = quote1 || quote2 || \"\";\n if (!filePath) {\n return origin;\n }\n if (URL_PROTOCOL_MATCH.test(filePath) || URL_WWW_MATCH.test(filePath)) {\n return `url(${maybeQuote}${filePath}${maybeQuote})`;\n }\n if (DATA_URI.test(filePath)) {\n return `url(${maybeQuote}${filePath}${maybeQuote})`;\n }\n if (filePath[0] === \"/\") {\n return `url(${maybeQuote}${extractOrigin(href) + filePath}${maybeQuote})`;\n }\n const stack = href.split(\"/\");\n const parts = filePath.split(\"/\");\n stack.pop();\n for (const part of parts) {\n if (part === \".\") {\n continue;\n } else if (part === \"..\") {\n stack.pop();\n } else {\n stack.push(part);\n }\n }\n return `url(${maybeQuote}${stack.join(\"/\")}${maybeQuote})`;\n }\n );\n}\nlet _id = 1;\nconst tagNameRegex = new RegExp(\"[^a-z0-9-_:]\");\nconst IGNORED_NODE = -2;\nfunction genId() {\n return _id++;\n}\nfunction getValidTagName$1(element) {\n if (element instanceof HTMLFormElement) {\n return \"form\";\n }\n const processedTagName = toLowerCase(element.tagName);\n if (tagNameRegex.test(processedTagName)) {\n return \"div\";\n }\n return processedTagName;\n}\nlet canvasService;\nlet canvasCtx;\nconst SRCSET_NOT_SPACES = /^[^ \\t\\n\\r\\u000c]+/;\nconst SRCSET_COMMAS_OR_SPACES = /^[, \\t\\n\\r\\u000c]+/;\nfunction getAbsoluteSrcsetString(doc, attributeValue) {\n if (attributeValue.trim() === \"\") {\n return attributeValue;\n }\n let pos = 0;\n function collectCharacters(regEx) {\n let chars2;\n const match = regEx.exec(attributeValue.substring(pos));\n if (match) {\n chars2 = match[0];\n pos += chars2.length;\n return chars2;\n }\n return \"\";\n }\n const output = [];\n while (true) {\n collectCharacters(SRCSET_COMMAS_OR_SPACES);\n if (pos >= attributeValue.length) {\n break;\n }\n let url = collectCharacters(SRCSET_NOT_SPACES);\n if (url.slice(-1) === \",\") {\n url = absoluteToDoc(doc, url.substring(0, url.length - 1));\n output.push(url);\n } else {\n let descriptorsStr = \"\";\n url = absoluteToDoc(doc, url);\n let inParens = false;\n while (true) {\n const c2 = attributeValue.charAt(pos);\n if (c2 === \"\") {\n output.push((url + descriptorsStr).trim());\n break;\n } else if (!inParens) {\n if (c2 === \",\") {\n pos += 1;\n output.push((url + descriptorsStr).trim());\n break;\n } else if (c2 === \"(\") {\n inParens = true;\n }\n } else {\n if (c2 === \")\") {\n inParens = false;\n }\n }\n descriptorsStr += c2;\n pos += 1;\n }\n }\n }\n return output.join(\", \");\n}\nconst cachedDocument = /* @__PURE__ */ new WeakMap();\nfunction absoluteToDoc(doc, attributeValue) {\n if (!attributeValue || attributeValue.trim() === \"\") {\n return attributeValue;\n }\n return getHref(doc, attributeValue);\n}\nfunction isSVGElement(el) {\n return Boolean(el.tagName === \"svg\" || el.ownerSVGElement);\n}\nfunction getHref(doc, customHref) {\n let a2 = cachedDocument.get(doc);\n if (!a2) {\n a2 = doc.createElement(\"a\");\n cachedDocument.set(doc, a2);\n }\n if (!customHref) {\n customHref = \"\";\n } else if (customHref.startsWith(\"blob:\") || customHref.startsWith(\"data:\")) {\n return customHref;\n }\n a2.setAttribute(\"href\", customHref);\n return a2.href;\n}\nfunction transformAttribute(doc, tagName, name, value) {\n if (!value) {\n return value;\n }\n if (name === \"src\" || name === \"href\" && !(tagName === \"use\" && value[0] === \"#\")) {\n return absoluteToDoc(doc, value);\n } else if (name === \"xlink:href\" && value[0] !== \"#\") {\n return absoluteToDoc(doc, value);\n } else if (name === \"background\" && (tagName === \"table\" || tagName === \"td\" || tagName === \"th\")) {\n return absoluteToDoc(doc, value);\n } else if (name === \"srcset\") {\n return getAbsoluteSrcsetString(doc, value);\n } else if (name === \"style\") {\n return absolutifyURLs(value, getHref(doc));\n } else if (tagName === \"object\" && name === \"data\") {\n return absoluteToDoc(doc, value);\n }\n return value;\n}\nfunction ignoreAttribute(tagName, name, _value) {\n return (tagName === \"video\" || tagName === \"audio\") && name === \"autoplay\";\n}\nfunction _isBlockedElement(element, blockClass, blockSelector) {\n try {\n if (typeof blockClass === \"string\") {\n if (element.classList.contains(blockClass)) {\n return true;\n }\n } else {\n for (let eIndex = element.classList.length; eIndex--; ) {\n const className = element.classList[eIndex];\n if (blockClass.test(className)) {\n return true;\n }\n }\n }\n if (blockSelector) {\n return element.matches(blockSelector);\n }\n } catch (e2) {\n }\n return false;\n}\nfunction classMatchesRegex(node2, regex, checkAncestors) {\n if (!node2) return false;\n if (node2.nodeType !== node2.ELEMENT_NODE) {\n if (!checkAncestors) return false;\n return classMatchesRegex(index$1.parentNode(node2), regex, checkAncestors);\n }\n for (let eIndex = node2.classList.length; eIndex--; ) {\n const className = node2.classList[eIndex];\n if (regex.test(className)) {\n return true;\n }\n }\n if (!checkAncestors) return false;\n return classMatchesRegex(index$1.parentNode(node2), regex, checkAncestors);\n}\nfunction needMaskingText(node2, maskTextClass, maskTextSelector, checkAncestors) {\n let el;\n if (isElement(node2)) {\n el = node2;\n if (!index$1.childNodes(el).length) {\n return false;\n }\n } else if (index$1.parentElement(node2) === null) {\n return false;\n } else {\n el = index$1.parentElement(node2);\n }\n try {\n if (typeof maskTextClass === \"string\") {\n if (checkAncestors) {\n if (el.closest(`.${maskTextClass}`)) return true;\n } else {\n if (el.classList.contains(maskTextClass)) return true;\n }\n } else {\n if (classMatchesRegex(el, maskTextClass, checkAncestors)) return true;\n }\n if (maskTextSelector) {\n if (checkAncestors) {\n if (el.closest(maskTextSelector)) return true;\n } else {\n if (el.matches(maskTextSelector)) return true;\n }\n }\n } catch (e2) {\n }\n return false;\n}\nfunction onceIframeLoaded(iframeEl, listener, iframeLoadTimeout) {\n const win = iframeEl.contentWindow;\n if (!win) {\n return;\n }\n let fired = false;\n let readyState;\n try {\n readyState = win.document.readyState;\n } catch (error) {\n return;\n }\n if (readyState !== \"complete\") {\n const timer = setTimeout(() => {\n if (!fired) {\n listener();\n fired = true;\n }\n }, iframeLoadTimeout);\n iframeEl.addEventListener(\"load\", () => {\n clearTimeout(timer);\n fired = true;\n listener();\n });\n return;\n }\n const blankUrl = \"about:blank\";\n if (win.location.href !== blankUrl || iframeEl.src === blankUrl || iframeEl.src === \"\") {\n setTimeout(listener, 0);\n return iframeEl.addEventListener(\"load\", listener);\n }\n iframeEl.addEventListener(\"load\", listener);\n}\nfunction onceStylesheetLoaded(link, listener, styleSheetLoadTimeout) {\n let fired = false;\n let styleSheetLoaded;\n try {\n styleSheetLoaded = link.sheet;\n } catch (error) {\n return;\n }\n if (styleSheetLoaded) return;\n const timer = setTimeout(() => {\n if (!fired) {\n listener();\n fired = true;\n }\n }, styleSheetLoadTimeout);\n link.addEventListener(\"load\", () => {\n clearTimeout(timer);\n fired = true;\n listener();\n });\n}\nfunction serializeNode(n2, options) {\n const {\n doc,\n mirror: mirror2,\n blockClass,\n blockSelector,\n needsMask,\n inlineStylesheet,\n maskInputOptions = {},\n maskTextFn,\n maskInputFn,\n dataURLOptions = {},\n inlineImages,\n recordCanvas,\n keepIframeSrcFn,\n newlyAddedElement = false\n } = options;\n const rootId = getRootId(doc, mirror2);\n switch (n2.nodeType) {\n case n2.DOCUMENT_NODE:\n if (n2.compatMode !== \"CSS1Compat\") {\n return {\n type: NodeType$2.Document,\n childNodes: [],\n compatMode: n2.compatMode\n // probably \"BackCompat\"\n };\n } else {\n return {\n type: NodeType$2.Document,\n childNodes: []\n };\n }\n case n2.DOCUMENT_TYPE_NODE:\n return {\n type: NodeType$2.DocumentType,\n name: n2.name,\n publicId: n2.publicId,\n systemId: n2.systemId,\n rootId\n };\n case n2.ELEMENT_NODE:\n return serializeElementNode(n2, {\n doc,\n blockClass,\n blockSelector,\n inlineStylesheet,\n maskInputOptions,\n maskInputFn,\n dataURLOptions,\n inlineImages,\n recordCanvas,\n keepIframeSrcFn,\n newlyAddedElement,\n rootId\n });\n case n2.TEXT_NODE:\n return serializeTextNode(n2, {\n doc,\n needsMask,\n maskTextFn,\n rootId\n });\n case n2.CDATA_SECTION_NODE:\n return {\n type: NodeType$2.CDATA,\n textContent: \"\",\n rootId\n };\n case n2.COMMENT_NODE:\n return {\n type: NodeType$2.Comment,\n textContent: index$1.textContent(n2) || \"\",\n rootId\n };\n default:\n return false;\n }\n}\nfunction getRootId(doc, mirror2) {\n if (!mirror2.hasNode(doc)) return void 0;\n const docId = mirror2.getId(doc);\n return docId === 1 ? void 0 : docId;\n}\nfunction serializeTextNode(n2, options) {\n var _a2;\n const { needsMask, maskTextFn, rootId } = options;\n const parent = index$1.parentNode(n2);\n const parentTagName = parent && parent.tagName;\n let text = index$1.textContent(n2);\n const isStyle = parentTagName === \"STYLE\" ? true : void 0;\n const isScript = parentTagName === \"SCRIPT\" ? true : void 0;\n if (isStyle && text) {\n try {\n if (n2.nextSibling || n2.previousSibling) {\n } else if ((_a2 = parent.sheet) == null ? void 0 : _a2.cssRules) {\n text = stringifyStylesheet(parent.sheet);\n }\n } catch (err) {\n console.warn(\n `Cannot get CSS styles from text's parentNode. Error: ${err}`,\n n2\n );\n }\n text = absolutifyURLs(text, getHref(options.doc));\n }\n if (isScript) {\n text = \"S