@sprig-technologies/sprig-browser 2.30.2 → 2.30.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core-IYeRexvz.js +12 -0
- package/dist/core-pJaEAG0Z.cjs +12 -0
- package/dist/core.cjs +1 -1
- package/dist/core.d.ts +6 -2
- package/dist/core.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +1 -1
- package/dist/metricsReporter-ChJRb1ed.js +2 -0
- package/dist/metricsReporter-DwcQeyB8.cjs +2 -0
- package/dist/replay.cjs +4 -4
- package/dist/replay.js +5 -5
- package/dist/{view-4ILgM5Tw.cjs → view-C-j1BBYA.cjs} +2 -2
- package/dist/{view-C5kHSC2Q.js → view-CVyjVx3W.js} +2 -2
- package/package.json +1 -1
- package/dist/core-BTd5RhnR.cjs +0 -12
- package/dist/core-BzwoEbTD.js +0 -12
- package/dist/metricsReporter-B6Yx0G8b.js +0 -2
- package/dist/metricsReporter-BIT_adF4.cjs +0 -2
package/dist/replay.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var ms=Object.defineProperty,ys=(t,e,n)=>e in t?ms(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,
|
|
1
|
+
var ms=Object.defineProperty,ys=(t,e,n)=>e in t?ms(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Fe=(t,e,n)=>(ys(t,typeof e!="symbol"?e+"":e,n),n);import{i as P,s as Fn,P as Un,r as qn,a as H,v as Ue,c as gs,e as Ln,d as ot,w as Hn,b as vs,f as lt,S as Mt,g as bs}from"./metricsReporter-ChJRb1ed.js";var ut=(t=>(t[t.DomContentLoaded=0]="DomContentLoaded",t[t.Load=1]="Load",t[t.FullSnapshot=2]="FullSnapshot",t[t.IncrementalSnapshot=3]="IncrementalSnapshot",t[t.Meta=4]="Meta",t[t.Custom=5]="Custom",t[t.Plugin=6]="Plugin",t))(ut||{});class ws{constructor(e){Fe(this,"awaitingResolvers",[]),Fe(this,"activeCount",0),this.capacity=e}async acquire(){if(this.activeCount<this.capacity){this.activeCount++;return}return new Promise(e=>{this.awaitingResolvers.push(e)})}release(){const e=this.awaitingResolvers.shift();e&&this.activeCount<=this.capacity?e():this.activeCount--}async execute(e){try{return await this.acquire(),await e()}finally{this.release()}}setLimit(e){this.capacity=e}}const Wn=new ws(2),_s=t=>Wn.setLimit(t),ks=async t=>Wn.execute(async()=>{var e;P(`Beginning upload of chunk ${t.chunkIndex} for survey: ${t.surveyId}`);const n=await Fn(t.uploadUrl,{body:t.data,method:"PUT"});P(`Completed upload of chunk ${t.chunkIndex} for survey: ${t.surveyId}`);const r=(e=n.headers)==null?void 0:e.get("ETag");if(!r)throw new Error(`Upload response did not include etag for upload ${t.uploadId}, part ${t.chunkIndex}`);return r}),Vn=async({apiUrl:t,surveyId:e,uploadId:n,etags:r,headers:s,responseGroupUuid:a,replayDuration:i,eventDigest:o},l=!1)=>{var u;if(!l&&!n&&!r){P(`Cannot mark upload complete: isMobile: ${l} / uploadId: ${n} / etags: ${r}`);return}P(`Marking upload complete for survey: ${e}`);const d=await Fn(`${t}/sdk/1/completeSessionReplay`,{method:"POST",body:JSON.stringify({etags:r,uploadId:n,responseGroupUuid:a,surveyId:e,replayDuration:i,eventDigest:o,userAgent:(u=window?.navigator)==null?void 0:u.userAgent}),headers:s,shouldRetryRequest:!0});return P(`Done marking upload complete for survey: ${e}`),d},K=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,B=Object.keys,F=Array.isArray;function W(t,e){return typeof e!="object"||B(e).forEach(function(n){t[n]=e[n]}),t}typeof Promise>"u"||K.Promise||(K.Promise=Promise);const qe=Object.getPrototypeOf,xs={}.hasOwnProperty;function z(t,e){return xs.call(t,e)}function Ae(t,e){typeof e=="function"&&(e=e(qe(t))),(typeof Reflect>"u"?B:Reflect.ownKeys)(e).forEach(n=>{ee(t,n,e[n])})}const Gn=Object.defineProperty;function ee(t,e,n,r){Gn(t,e,W(n&&z(n,"get")&&typeof n.get=="function"?{get:n.get,set:n.set,configurable:!0}:{value:n,configurable:!0,writable:!0},r))}function De(t){return{from:function(e){return t.prototype=Object.create(e.prototype),ee(t.prototype,"constructor",t),{extend:Ae.bind(null,t.prototype)}}}}const Es=Object.getOwnPropertyDescriptor;function Ft(t,e){let n;return Es(t,e)||(n=qe(t))&&Ft(n,e)}const Ss=[].slice;function ct(t,e,n){return Ss.call(t,e,n)}function zn(t,e){return e(t)}function Le(t){if(!t)throw new Error("Assertion Failed")}function Yn(t){K.setImmediate?setImmediate(t):setTimeout(t,0)}function Jn(t,e){return t.reduce((n,r,s)=>{var a=e(r,s);return a&&(n[a[0]]=a[1]),n},{})}function te(t,e){if(typeof e=="string"&&z(t,e))return t[e];if(!e)return t;if(typeof e!="string"){for(var n=[],r=0,s=e.length;r<s;++r){var a=te(t,e[r]);n.push(a)}return n}var i=e.indexOf(".");if(i!==-1){var o=t[e.substr(0,i)];return o==null?void 0:te(o,e.substr(i+1))}}function J(t,e,n){if(t&&e!==void 0&&(!("isFrozen"in Object)||!Object.isFrozen(t)))if(typeof e!="string"&&"length"in e){Le(typeof n!="string"&&"length"in n);for(var r=0,s=e.length;r<s;++r)J(t,e[r],n[r])}else{var a=e.indexOf(".");if(a!==-1){var i=e.substr(0,a),o=e.substr(a+1);if(o==="")n===void 0?F(t)&&!isNaN(parseInt(i))?t.splice(i,1):delete t[i]:t[i]=n;else{var l=t[i];l&&z(t,i)||(l=t[i]={}),J(l,o,n)}}else n===void 0?F(t)&&!isNaN(parseInt(e))?t.splice(e,1):delete t[e]:t[e]=n}}function Qn(t){var e={};for(var n in t)z(t,n)&&(e[n]=t[n]);return e}const Is=[].concat;function Xn(t){return Is.apply([],t)}const Zn="BigUint64Array,BigInt64Array,Array,Boolean,String,Date,RegExp,Blob,File,FileList,FileSystemFileHandle,FileSystemDirectoryHandle,ArrayBuffer,DataView,Uint8ClampedArray,ImageBitmap,ImageData,Map,Set,CryptoKey".split(",").concat(Xn([8,16,32,64].map(t=>["Int","Uint","Float"].map(e=>e+t+"Array")))).filter(t=>K[t]),Ps=Zn.map(t=>K[t]);Jn(Zn,t=>[t,!0]);let le=null;function He(t){le=typeof WeakMap<"u"&&new WeakMap;const e=Ut(t);return le=null,e}function Ut(t){if(!t||typeof t!="object")return t;let e=le&&le.get(t);if(e)return e;if(F(t)){e=[],le&&le.set(t,e);for(var n=0,r=t.length;n<r;++n)e.push(Ut(t[n]))}else if(Ps.indexOf(t.constructor)>=0)e=t;else{const a=qe(t);for(var s in e=a===Object.prototype?{}:Object.create(a),le&&le.set(t,e),t)z(t,s)&&(e[s]=Ut(t[s]))}return e}const{toString:Cs}={};function qt(t){return Cs.call(t).slice(8,-1)}const Lt=typeof Symbol<"u"?Symbol.iterator:"@@iterator",As=typeof Lt=="symbol"?function(t){var e;return t!=null&&(e=t[Lt])&&e.apply(t)}:function(){return null},Te={};function ne(t){var e,n,r,s;if(arguments.length===1){if(F(t))return t.slice();if(this===Te&&typeof t=="string")return[t];if(s=As(t)){for(n=[];!(r=s.next()).done;)n.push(r.value);return n}if(t==null)return[t];if(typeof(e=t.length)=="number"){for(n=new Array(e);e--;)n[e]=t[e];return n}return[t]}for(e=arguments.length,n=new Array(e);e--;)n[e]=arguments[e];return n}const Ht=typeof Symbol<"u"?t=>t[Symbol.toStringTag]==="AsyncFunction":()=>!1;var X=typeof location<"u"&&/^(http|https):\/\/(localhost|127\.0\.0\.1)/.test(location.href);function er(t,e){X=t,tr=e}var tr=()=>!0;const Ds=!new Error("").stack;function ge(){if(Ds)try{throw ge.arguments,new Error}catch(t){return t}return new Error}function Wt(t,e){var n=t.stack;return n?(e=e||0,n.indexOf(t.name)===0&&(e+=(t.name+t.message).split(`
|
|
2
2
|
`).length),n.split(`
|
|
3
3
|
`).slice(e).filter(tr).map(r=>`
|
|
4
|
-
`+r).join("")):""}var nr=["Unknown","Constraint","Data","TransactionInactive","ReadOnly","Version","NotFound","InvalidState","InvalidAccess","Abort","Timeout","QuotaExceeded","Syntax","DataClone"],Vt=["Modify","Bulk","OpenFailed","VersionChange","Schema","Upgrade","InvalidTable","MissingAPI","NoSuchDatabase","InvalidArgument","SubTransaction","Unsupported","Internal","DatabaseClosed","PrematureCommit","ForeignAwait"].concat(nr),Ts={VersionChanged:"Database version changed by other database connection",DatabaseClosed:"Database has been closed",Abort:"Transaction aborted",TransactionInactive:"Transaction has already completed or failed",MissingAPI:"IndexedDB API missing. Please visit https://tinyurl.com/y2uuvskb"};function
|
|
5
|
-
`)}function
|
|
6
|
-
`+
|
|
7
|
-
From previous: `);return this._state!==null&&(this._stack=t),t}finally{Xt=!1}}},timeout:function(t,e){return t<1/0?new E((n,r)=>{var s=setTimeout(()=>r(new C.Timeout(e)),t);this.then(n,r).finally(clearTimeout.bind(null,s))}):this}}),typeof Symbol<"u"&&Symbol.toStringTag&&ee(E.prototype,Symbol.toStringTag,"Dexie.Promise"),Oe.env=hr(),Ce(E,{all:function(){var t=ne.apply(null,arguments).map(_t);return new E(function(e,n){t.length===0&&e([]);var r=t.length;t.forEach((s,i)=>E.resolve(s).then(a=>{t[i]=a,--r||e(t)},n))})},resolve:t=>{if(t instanceof E)return t;if(t&&typeof t.then=="function")return new E((n,r)=>{t.then(n,r)});var e=new E(Ve,!0,t);return dr(e,en),e},reject:vt,race:function(){var t=ne.apply(null,arguments).map(_t);return new E((e,n)=>{t.map(r=>E.resolve(r).then(e,n))})},PSD:{get:()=>I,set:t=>I=t},totalEchoes:{get:()=>wt},newPSD:ue,usePSD:Re,scheduler:{get:()=>Ge,set:t=>{Ge=t}},rejectionMapper:{get:()=>tn,set:t=>{tn=t}},follow:(t,e)=>new E((n,r)=>ue((s,i)=>{var a=I;a.unhandleds=[],a.onunhandled=i,a.finalize=ve(function(){(function(o){function l(){o(),yt.splice(yt.indexOf(l),1)}yt.push(l),++we,Ge(()=>{--we==0&&an()},[])})(()=>{this.unhandleds.length===0?s():i(this.unhandleds[0])})},a.finalize),t()},e,n,r))}),pt&&(pt.allSettled&&ee(E,"allSettled",function(){const t=ne.apply(null,arguments).map(_t);return new E(e=>{t.length===0&&e([]);let n=t.length;const r=new Array(n);t.forEach((s,i)=>E.resolve(s).then(a=>r[i]={status:"fulfilled",value:a},a=>r[i]={status:"rejected",reason:a}).then(()=>--n||e(r)))})}),pt.any&&typeof AggregateError<"u"&&ee(E,"any",function(){const t=ne.apply(null,arguments).map(_t);return new E((e,n)=>{t.length===0&&n(new AggregateError([]));let r=t.length;const s=new Array(r);t.forEach((i,a)=>E.resolve(i).then(o=>e(o),o=>{s[a]=o,--r||n(new AggregateError(s))}))})}));const U={awaits:0,echoes:0,id:0};var Fs=0,bt=[],on=0,wt=0,Us=0;function ue(t,e,n,r){var s=I,i=Object.create(s);i.parent=s,i.ref=0,i.global=!1,i.id=++Us;var a=Oe.env;i.env=Qt?{Promise:E,PromiseProp:{value:E,configurable:!0,writable:!0},all:E.all,race:E.race,allSettled:E.allSettled,any:E.any,resolve:E.resolve,reject:E.reject,nthen:fr(a.nthen,i),gthen:fr(a.gthen,i)}:{},e&&W(i,e),++s.ref,i.finalize=function(){--this.parent.ref||this.parent.finalize()};var o=Re(i,t,n,r);return i.ref===0&&i.finalize(),o}function Ke(){return U.id||(U.id=++Fs),++U.awaits,U.echoes+=ir,U.id}function re(){return!!U.awaits&&(--U.awaits==0&&(U.id=0),U.echoes=U.awaits*ir,!0)}function _t(t){return U.echoes&&t&&t.constructor===pt?(Ke(),t.then(e=>(re(),e),e=>(re(),$(e)))):t}function qs(t){++wt,U.echoes&&--U.echoes!=0||(U.echoes=U.id=0),bt.push(I),ce(t,!0)}function Ls(){var t=bt[bt.length-1];bt.pop(),ce(t,!1)}function ce(t,e){var n=I;if((e?!U.echoes||on++&&t===I:!on||--on&&t===I)||pr(e?qs.bind(null,t):Ls),t!==I&&(I=t,n===Oe&&(Oe.env=hr()),Qt)){var r=Oe.env.Promise,s=t.env;ht.then=s.nthen,r.prototype.then=s.gthen,(n.global||t.global)&&(Object.defineProperty(K,"Promise",s.PromiseProp),r.all=s.all,r.race=s.race,r.resolve=s.resolve,r.reject=s.reject,s.allSettled&&(r.allSettled=s.allSettled),s.any&&(r.any=s.any))}}function hr(){var t=K.Promise;return Qt?{Promise:t,PromiseProp:Object.getOwnPropertyDescriptor(K,"Promise"),all:t.all,race:t.race,allSettled:t.allSettled,any:t.any,resolve:t.resolve,reject:t.reject,nthen:ht.then,gthen:t.prototype.then}:{}}function Re(t,e,n,r,s){var i=I;try{return ce(t,!0),e(n,r,s)}finally{ce(i,!1)}}function pr(t){ar.call(Yt,t)}function kt(t,e,n,r){return typeof t!="function"?t:function(){var s=I;n&&Ke(),ce(e,!0);try{return t.apply(this,arguments)}finally{ce(s,!1),r&&pr(re)}}}function fr(t,e){return function(n,r){return t.call(this,kt(n,e),kt(r,e))}}(""+ar).indexOf("[native code]")===-1&&(Ke=re=O);const mr="unhandledrejection";function yr(t,e){var n;try{n=e.onuncatched(t)}catch{}if(n!==!1)try{var r,s={promise:e,reason:t};if(K.document&&document.createEvent?((r=document.createEvent("Event")).initEvent(mr,!0,!0),W(r,s)):K.CustomEvent&&W(r=new CustomEvent(mr,{detail:s}),s),r&&K.dispatchEvent&&(dispatchEvent(r),!K.PromiseRejectionEvent&&K.onunhandledrejection))try{K.onunhandledrejection(r)}catch{}X&&r&&!r.defaultPrevented&&console.warn(`Unhandled rejection: ${t.stack||t}`)}catch{}}var $=E.reject;function ln(t,e,n,r){if(t.idbdb&&(t._state.openComplete||I.letThrough||t._vip)){var s=t._createTransaction(e,n,t._dbSchema);try{s.create(),t._state.PR1398_maxLoop=3}catch(i){return i.name===Gt.InvalidState&&t.isOpen()&&--t._state.PR1398_maxLoop>0?(console.warn("Dexie: Need to reopen db"),t._close(),t.open().then(()=>ln(t,e,n,r))):$(i)}return s._promise(e,(i,a)=>ue(()=>(I.trans=s,r(i,a,s)))).then(i=>s._completion.then(()=>i))}if(t._state.openComplete)return $(new C.DatabaseClosed(t._state.dbOpenError));if(!t._state.isBeingOpened){if(!t._options.autoOpen)return $(new C.DatabaseClosed);t.open().catch(O)}return t._state.dbReadyPromise.then(()=>ln(t,e,n,r))}const gr="3.2.7",_e="\uFFFF",un=-1/0,se="Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.",vr="String expected.",Qe=[],xt=typeof navigator<"u"&&/(MSIE|Trident|Edge)/.test(navigator.userAgent),Hs=xt,Ws=xt,br=t=>!/(dexie\.js|dexie\.min\.js)/.test(t),Et="__dbnames",cn="readonly",dn="readwrite";function ke(t,e){return t?e?function(){return t.apply(this,arguments)&&e.apply(this,arguments)}:t:e}const wr={type:3,lower:-1/0,lowerOpen:!1,upper:[[]],upperOpen:!1};function St(t){return typeof t!="string"||/\./.test(t)?e=>e:e=>(e[t]===void 0&&t in e&&delete(e=Le(e))[t],e)}class Vs{_trans(e,n,r){const s=this._tx||I.trans,i=this.name;function a(l,u,d){if(!d.schema[i])throw new C.NotFound("Table "+i+" not part of transaction");return n(d.idbtrans,d)}const o=Ye();try{return s&&s.db===this.db?s===I.trans?s._promise(e,a,r):ue(()=>s._promise(e,a,r),{trans:s,transless:I.transless||I}):ln(this.db,e,[this.name],a)}finally{o&&Je()}}get(e,n){return e&&e.constructor===Object?this.where(e).first(n):this._trans("readonly",r=>this.core.get({trans:r,key:e}).then(s=>this.hook.reading.fire(s))).then(n)}where(e){if(typeof e=="string")return new this.db.WhereClause(this,e);if(F(e))return new this.db.WhereClause(this,`[${e.join("+")}]`);const n=B(e);if(n.length===1)return this.where(n[0]).equals(e[n[0]]);const r=this.schema.indexes.concat(this.schema.primKey).filter(u=>{if(u.compound&&n.every(d=>u.keyPath.indexOf(d)>=0)){for(let d=0;d<n.length;++d)if(n.indexOf(u.keyPath[d])===-1)return!1;return!0}return!1}).sort((u,d)=>u.keyPath.length-d.keyPath.length)[0];if(r&&this.db._maxKey!==_e){const u=r.keyPath.slice(0,n.length);return this.where(u).equals(u.map(d=>e[d]))}!r&&X&&console.warn(`The query ${JSON.stringify(e)} on ${this.name} would benefit of a compound index [${n.join("+")}]`);const{idxByName:s}=this.schema,i=this.db._deps.indexedDB;function a(u,d){try{return i.cmp(u,d)===0}catch{return!1}}const[o,l]=n.reduce(([u,d],c)=>{const h=s[c],p=e[c];return[u||h,u||!h?ke(d,h&&h.multi?y=>{const m=te(y,c);return F(m)&&m.some(v=>a(p,v))}:y=>a(p,te(y,c))):d]},[null,null]);return o?this.where(o.name).equals(e[o.keyPath]).filter(l):r?this.filter(l):this.where(n).equals("")}filter(e){return this.toCollection().and(e)}count(e){return this.toCollection().count(e)}offset(e){return this.toCollection().offset(e)}limit(e){return this.toCollection().limit(e)}each(e){return this.toCollection().each(e)}toArray(e){return this.toCollection().toArray(e)}toCollection(){return new this.db.Collection(new this.db.WhereClause(this))}orderBy(e){return new this.db.Collection(new this.db.WhereClause(this,F(e)?`[${e.join("+")}]`:e))}reverse(){return this.toCollection().reverse()}mapToClass(e){this.schema.mappedClass=e;const n=r=>{if(!r)return r;const s=Object.create(e.prototype);for(var i in r)if(z(r,i))try{s[i]=r[i]}catch{}return s};return this.schema.readHook&&this.hook.reading.unsubscribe(this.schema.readHook),this.schema.readHook=n,this.hook("reading",n),e}defineClass(){return this.mapToClass(function(e){W(this,e)})}add(e,n){const{auto:r,keyPath:s}=this.schema.primKey;let i=e;return s&&r&&(i=St(s)(e)),this._trans("readwrite",a=>this.core.mutate({trans:a,type:"add",keys:n!=null?[n]:null,values:[i]})).then(a=>a.numFailures?E.reject(a.failures[0]):a.lastResult).then(a=>{if(s)try{J(e,s,a)}catch{}return a})}update(e,n){if(typeof e!="object"||F(e))return this.where(":id").equals(e).modify(n);{const r=te(e,this.schema.primKey.keyPath);if(r===void 0)return $(new C.InvalidArgument("Given object does not contain its primary key"));try{typeof n!="function"?B(n).forEach(s=>{J(e,s,n[s])}):n(e,{value:e,primKey:r})}catch{}return this.where(":id").equals(r).modify(n)}}put(e,n){const{auto:r,keyPath:s}=this.schema.primKey;let i=e;return s&&r&&(i=St(s)(e)),this._trans("readwrite",a=>this.core.mutate({trans:a,type:"put",values:[i],keys:n!=null?[n]:null})).then(a=>a.numFailures?E.reject(a.failures[0]):a.lastResult).then(a=>{if(s)try{J(e,s,a)}catch{}return a})}delete(e){return this._trans("readwrite",n=>this.core.mutate({trans:n,type:"delete",keys:[e]})).then(n=>n.numFailures?E.reject(n.failures[0]):void 0)}clear(){return this._trans("readwrite",e=>this.core.mutate({trans:e,type:"deleteRange",range:wr})).then(e=>e.numFailures?E.reject(e.failures[0]):void 0)}bulkGet(e){return this._trans("readonly",n=>this.core.getMany({keys:e,trans:n}).then(r=>r.map(s=>this.hook.reading.fire(s))))}bulkAdd(e,n,r){const s=Array.isArray(n)?n:void 0,i=(r=r||(s?void 0:n))?r.allKeys:void 0;return this._trans("readwrite",a=>{const{auto:o,keyPath:l}=this.schema.primKey;if(l&&s)throw new C.InvalidArgument("bulkAdd(): keys argument invalid on tables with inbound keys");if(s&&s.length!==e.length)throw new C.InvalidArgument("Arguments objects and keys must have the same length");const u=e.length;let d=l&&o?e.map(St(l)):e;return this.core.mutate({trans:a,type:"add",keys:s,values:d,wantResults:i}).then(({numFailures:c,results:h,lastResult:p,failures:y})=>{if(c===0)return i?h:p;throw new He(`${this.name}.bulkAdd(): ${c} of ${u} operations failed`,y)})})}bulkPut(e,n,r){const s=Array.isArray(n)?n:void 0,i=(r=r||(s?void 0:n))?r.allKeys:void 0;return this._trans("readwrite",a=>{const{auto:o,keyPath:l}=this.schema.primKey;if(l&&s)throw new C.InvalidArgument("bulkPut(): keys argument invalid on tables with inbound keys");if(s&&s.length!==e.length)throw new C.InvalidArgument("Arguments objects and keys must have the same length");const u=e.length;let d=l&&o?e.map(St(l)):e;return this.core.mutate({trans:a,type:"put",keys:s,values:d,wantResults:i}).then(({numFailures:c,results:h,lastResult:p,failures:y})=>{if(c===0)return i?h:p;throw new He(`${this.name}.bulkPut(): ${c} of ${u} operations failed`,y)})})}bulkDelete(e){const n=e.length;return this._trans("readwrite",r=>this.core.mutate({trans:r,type:"delete",keys:e})).then(({numFailures:r,lastResult:s,failures:i})=>{if(r===0)return s;throw new He(`${this.name}.bulkDelete(): ${r} of ${n} operations failed`,i)})}}function Xe(t){var e={},n=function(a,o){if(o){for(var l=arguments.length,u=new Array(l-1);--l;)u[l-1]=arguments[l];return e[a].subscribe.apply(null,u),t}if(typeof a=="string")return e[a]};n.addEventType=i;for(var r=1,s=arguments.length;r<s;++r)i(arguments[r]);return n;function i(a,o,l){if(typeof a!="object"){var u;o||(o=Bs),l||(l=O);var d={subscribers:[],fire:l,subscribe:function(c){d.subscribers.indexOf(c)===-1&&(d.subscribers.push(c),d.fire=o(d.fire,c))},unsubscribe:function(c){d.subscribers=d.subscribers.filter(function(h){return h!==c}),d.fire=d.subscribers.reduce(o,l)}};return e[a]=n[a]=d,d}B(u=a).forEach(function(c){var h=u[c];if(F(h))i(c,u[c][0],u[c][1]);else{if(h!=="asap")throw new C.InvalidArgument("Invalid event config");var p=i(c,We,function(){for(var y=arguments.length,m=new Array(y);y--;)m[y]=arguments[y];p.subscribers.forEach(function(v){Yn(function(){v.apply(null,m)})})})}})}}function Ze(t,e){return Ae(e).from({prototype:t}),e}function je(t,e){return!(t.filter||t.algorithm||t.or)&&(e?t.justLimit:!t.replayFilter)}function hn(t,e){t.filter=ke(t.filter,e)}function pn(t,e,n){var r=t.replayFilter;t.replayFilter=r?()=>ke(r(),e()):e,t.justLimit=n&&!r}function It(t,e){if(t.isPrimKey)return e.primaryKey;const n=e.getIndexByKeyPath(t.index);if(!n)throw new C.Schema("KeyPath "+t.index+" on object store "+e.name+" is not indexed");return n}function _r(t,e,n){const r=It(t,e.schema);return e.openCursor({trans:n,values:!t.keysOnly,reverse:t.dir==="prev",unique:!!t.unique,query:{index:r,range:t.range}})}function Pt(t,e,n,r){const s=t.replayFilter?ke(t.filter,t.replayFilter()):t.filter;if(t.or){const i={},a=(o,l,u)=>{if(!s||s(l,u,h=>l.stop(h),h=>l.fail(h))){var d=l.primaryKey,c=""+d;c==="[object ArrayBuffer]"&&(c=""+new Uint8Array(d)),z(i,c)||(i[c]=!0,e(o,l,u))}};return Promise.all([t.or._iterate(a,n),kr(_r(t,r,n),t.algorithm,a,!t.keysOnly&&t.valueMapper)])}return kr(_r(t,r,n),ke(t.algorithm,s),e,!t.keysOnly&&t.valueMapper)}function kr(t,e,n,r){var s=R(r?(i,a,o)=>n(r(i),a,o):n);return t.then(i=>{if(i)return i.start(()=>{var a=()=>i.continue();e&&!e(i,o=>a=o,o=>{i.stop(o),a=O},o=>{i.fail(o),a=O})||s(i.value,i,o=>a=o),a()})})}function V(t,e){try{const n=xr(t),r=xr(e);if(n!==r)return n==="Array"?1:r==="Array"?-1:n==="binary"?1:r==="binary"?-1:n==="string"?1:r==="string"?-1:n==="Date"?1:r!=="Date"?NaN:-1;switch(n){case"number":case"Date":case"string":return t>e?1:t<e?-1:0;case"binary":return function(s,i){const a=s.length,o=i.length,l=a<o?a:o;for(let u=0;u<l;++u)if(s[u]!==i[u])return s[u]<i[u]?-1:1;return a===o?0:a<o?-1:1}(Er(t),Er(e));case"Array":return function(s,i){const a=s.length,o=i.length,l=a<o?a:o;for(let u=0;u<l;++u){const d=V(s[u],i[u]);if(d!==0)return d}return a===o?0:a<o?-1:1}(t,e)}}catch{}return NaN}function xr(t){const e=typeof t;if(e!=="object")return e;if(ArrayBuffer.isView(t))return"binary";const n=qt(t);return n==="ArrayBuffer"?"binary":n}function Er(t){return t instanceof Uint8Array?t:ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t)}class Gs{_read(e,n){var r=this._ctx;return r.error?r.table._trans(null,$.bind(null,r.error)):r.table._trans("readonly",e).then(n)}_write(e){var n=this._ctx;return n.error?n.table._trans(null,$.bind(null,n.error)):n.table._trans("readwrite",e,"locked")}_addAlgorithm(e){var n=this._ctx;n.algorithm=ke(n.algorithm,e)}_iterate(e,n){return Pt(this._ctx,e,n,this._ctx.table.core)}clone(e){var n=Object.create(this.constructor.prototype),r=Object.create(this._ctx);return e&&W(r,e),n._ctx=r,n}raw(){return this._ctx.valueMapper=null,this}each(e){var n=this._ctx;return this._read(r=>Pt(n,e,r,n.table.core))}count(e){return this._read(n=>{const r=this._ctx,s=r.table.core;if(je(r,!0))return s.count({trans:n,query:{index:It(r,s.schema),range:r.range}}).then(a=>Math.min(a,r.limit));var i=0;return Pt(r,()=>(++i,!1),n,s).then(()=>i)}).then(e)}sortBy(e,n){const r=e.split(".").reverse(),s=r[0],i=r.length-1;function a(u,d){return d?a(u[r[d]],d-1):u[s]}var o=this._ctx.dir==="next"?1:-1;function l(u,d){var c=a(u,i),h=a(d,i);return c<h?-o:c>h?o:0}return this.toArray(function(u){return u.sort(l)}).then(n)}toArray(e){return this._read(n=>{var r=this._ctx;if(r.dir==="next"&&je(r,!0)&&r.limit>0){const{valueMapper:s}=r,i=It(r,r.table.core.schema);return r.table.core.query({trans:n,limit:r.limit,values:!0,query:{index:i,range:r.range}}).then(({result:a})=>s?a.map(s):a)}{const s=[];return Pt(r,i=>s.push(i),n,r.table.core).then(()=>s)}},e)}offset(e){var n=this._ctx;return e<=0||(n.offset+=e,je(n)?pn(n,()=>{var r=e;return(s,i)=>r===0||(r===1?(--r,!1):(i(()=>{s.advance(r),r=0}),!1))}):pn(n,()=>{var r=e;return()=>--r<0})),this}limit(e){return this._ctx.limit=Math.min(this._ctx.limit,e),pn(this._ctx,()=>{var n=e;return function(r,s,i){return--n<=0&&s(i),n>=0}},!0),this}until(e,n){return hn(this._ctx,function(r,s,i){return!e(r.value)||(s(i),n)}),this}first(e){return this.limit(1).toArray(function(n){return n[0]}).then(e)}last(e){return this.reverse().first(e)}filter(e){var n,r;return hn(this._ctx,function(s){return e(s.value)}),n=this._ctx,r=e,n.isMatch=ke(n.isMatch,r),this}and(e){return this.filter(e)}or(e){return new this.db.WhereClause(this._ctx.table,e,this)}reverse(){return this._ctx.dir=this._ctx.dir==="prev"?"next":"prev",this._ondirectionchange&&this._ondirectionchange(this._ctx.dir),this}desc(){return this.reverse()}eachKey(e){var n=this._ctx;return n.keysOnly=!n.isMatch,this.each(function(r,s){e(s.key,s)})}eachUniqueKey(e){return this._ctx.unique="unique",this.eachKey(e)}eachPrimaryKey(e){var n=this._ctx;return n.keysOnly=!n.isMatch,this.each(function(r,s){e(s.primaryKey,s)})}keys(e){var n=this._ctx;n.keysOnly=!n.isMatch;var r=[];return this.each(function(s,i){r.push(i.key)}).then(function(){return r}).then(e)}primaryKeys(e){var n=this._ctx;if(n.dir==="next"&&je(n,!0)&&n.limit>0)return this._read(s=>{var i=It(n,n.table.core.schema);return n.table.core.query({trans:s,values:!1,limit:n.limit,query:{index:i,range:n.range}})}).then(({result:s})=>s).then(e);n.keysOnly=!n.isMatch;var r=[];return this.each(function(s,i){r.push(i.primaryKey)}).then(function(){return r}).then(e)}uniqueKeys(e){return this._ctx.unique="unique",this.keys(e)}firstKey(e){return this.limit(1).keys(function(n){return n[0]}).then(e)}lastKey(e){return this.reverse().firstKey(e)}distinct(){var e=this._ctx,n=e.index&&e.table.schema.idxByName[e.index];if(!n||!n.multi)return this;var r={};return hn(this._ctx,function(s){var i=s.primaryKey.toString(),a=z(r,i);return r[i]=!0,!a}),this}modify(e){var n=this._ctx;return this._write(r=>{var s;if(typeof e=="function")s=e;else{var i=B(e),a=i.length;s=function(m){for(var v=!1,g=0;g<a;++g){var f=i[g],_=e[f];te(m,f)!==_&&(J(m,f,_),v=!0)}return v}}const o=n.table.core,{outbound:l,extractKey:u}=o.schema.primaryKey,d=this.db._options.modifyChunkSize||200,c=[];let h=0;const p=[],y=(m,v)=>{const{failures:g,numFailures:f}=v;h+=m-f;for(let _ of B(g))c.push(g[_])};return this.clone().primaryKeys().then(m=>{const v=g=>{const f=Math.min(d,m.length-g);return o.getMany({trans:r,keys:m.slice(g,g+f),cache:"immutable"}).then(_=>{const w=[],S=[],x=l?[]:null,b=[];for(let k=0;k<f;++k){const j=_[k],T={value:Le(j),primKey:m[g+k]};s.call(T,T.value,T)!==!1&&(T.value==null?b.push(m[g+k]):l||V(u(j),u(T.value))===0?(S.push(T.value),l&&x.push(m[g+k])):(b.push(m[g+k]),w.push(T.value)))}const D=je(n)&&n.limit===1/0&&(typeof e!="function"||e===fn)&&{index:n.index,range:n.range};return Promise.resolve(w.length>0&&o.mutate({trans:r,type:"add",values:w}).then(k=>{for(let j in k.failures)b.splice(parseInt(j),1);y(w.length,k)})).then(()=>(S.length>0||D&&typeof e=="object")&&o.mutate({trans:r,type:"put",keys:x,values:S,criteria:D,changeSpec:typeof e!="function"&&e}).then(k=>y(S.length,k))).then(()=>(b.length>0||D&&e===fn)&&o.mutate({trans:r,type:"delete",keys:b,criteria:D}).then(k=>y(b.length,k))).then(()=>m.length>g+f&&v(g+d))})};return v(0).then(()=>{if(c.length>0)throw new ct("Error modifying one or more objects",c,h,p);return m.length})})})}delete(){var e=this._ctx,n=e.range;return je(e)&&(e.isPrimKey&&!Ws||n.type===3)?this._write(r=>{const{primaryKey:s}=e.table.core.schema,i=n;return e.table.core.count({trans:r,query:{index:s,range:i}}).then(a=>e.table.core.mutate({trans:r,type:"deleteRange",range:i}).then(({failures:o,lastResult:l,results:u,numFailures:d})=>{if(d)throw new ct("Could not delete some values",Object.keys(o).map(c=>o[c]),a-d);return a-d}))}):this.modify(fn)}}const fn=(t,e)=>e.value=null;function zs(t,e){return t<e?-1:t===e?0:1}function Ys(t,e){return t>e?-1:t===e?0:1}function Y(t,e,n){var r=t instanceof Ir?new t.Collection(t):t;return r._ctx.error=n?new n(e):new TypeError(e),r}function Ne(t){return new t.Collection(t,()=>Sr("")).limit(0)}function Js(t,e,n,r,s,i){for(var a=Math.min(t.length,r.length),o=-1,l=0;l<a;++l){var u=e[l];if(u!==r[l])return s(t[l],n[l])<0?t.substr(0,l)+n[l]+n.substr(l+1):s(t[l],r[l])<0?t.substr(0,l)+r[l]+n.substr(l+1):o>=0?t.substr(0,o)+e[o]+n.substr(o+1):null;s(t[l],u)<0&&(o=l)}return a<r.length&&i==="next"?t+n.substr(t.length):a<t.length&&i==="prev"?t.substr(0,n.length):o<0?null:t.substr(0,o)+r[o]+n.substr(o+1)}function Ct(t,e,n,r){var s,i,a,o,l,u,d,c=n.length;if(!n.every(m=>typeof m=="string"))return Y(t,vr);function h(m){s=function(g){return g==="next"?f=>f.toUpperCase():f=>f.toLowerCase()}(m),i=function(g){return g==="next"?f=>f.toLowerCase():f=>f.toUpperCase()}(m),a=m==="next"?zs:Ys;var v=n.map(function(g){return{lower:i(g),upper:s(g)}}).sort(function(g,f){return a(g.lower,f.lower)});o=v.map(function(g){return g.upper}),l=v.map(function(g){return g.lower}),u=m,d=m==="next"?"":r}h("next");var p=new t.Collection(t,()=>de(o[0],l[c-1]+r));p._ondirectionchange=function(m){h(m)};var y=0;return p._addAlgorithm(function(m,v,g){var f=m.key;if(typeof f!="string")return!1;var _=i(f);if(e(_,l,y))return!0;for(var w=null,S=y;S<c;++S){var x=Js(f,_,o[S],l[S],a,u);x===null&&w===null?y=S+1:(w===null||a(w,x)>0)&&(w=x)}return v(w!==null?function(){m.continue(w+d)}:g),!1}),p}function de(t,e,n,r){return{type:2,lower:t,upper:e,lowerOpen:n,upperOpen:r}}function Sr(t){return{type:1,lower:t,upper:t}}class Ir{get Collection(){return this._ctx.table.db.Collection}between(e,n,r,s){r=r!==!1,s=s===!0;try{return this._cmp(e,n)>0||this._cmp(e,n)===0&&(r||s)&&(!r||!s)?Ne(this):new this.Collection(this,()=>de(e,n,!r,!s))}catch{return Y(this,se)}}equals(e){return e==null?Y(this,se):new this.Collection(this,()=>Sr(e))}above(e){return e==null?Y(this,se):new this.Collection(this,()=>de(e,void 0,!0))}aboveOrEqual(e){return e==null?Y(this,se):new this.Collection(this,()=>de(e,void 0,!1))}below(e){return e==null?Y(this,se):new this.Collection(this,()=>de(void 0,e,!1,!0))}belowOrEqual(e){return e==null?Y(this,se):new this.Collection(this,()=>de(void 0,e))}startsWith(e){return typeof e!="string"?Y(this,vr):this.between(e,e+_e,!0,!0)}startsWithIgnoreCase(e){return e===""?this.startsWith(e):Ct(this,(n,r)=>n.indexOf(r[0])===0,[e],_e)}equalsIgnoreCase(e){return Ct(this,(n,r)=>n===r[0],[e],"")}anyOfIgnoreCase(){var e=ne.apply(De,arguments);return e.length===0?Ne(this):Ct(this,(n,r)=>r.indexOf(n)!==-1,e,"")}startsWithAnyOfIgnoreCase(){var e=ne.apply(De,arguments);return e.length===0?Ne(this):Ct(this,(n,r)=>r.some(s=>n.indexOf(s)===0),e,_e)}anyOf(){const e=ne.apply(De,arguments);let n=this._cmp;try{e.sort(n)}catch{return Y(this,se)}if(e.length===0)return Ne(this);const r=new this.Collection(this,()=>de(e[0],e[e.length-1]));r._ondirectionchange=i=>{n=i==="next"?this._ascending:this._descending,e.sort(n)};let s=0;return r._addAlgorithm((i,a,o)=>{const l=i.key;for(;n(l,e[s])>0;)if(++s,s===e.length)return a(o),!1;return n(l,e[s])===0||(a(()=>{i.continue(e[s])}),!1)}),r}notEqual(e){return this.inAnyRange([[un,e],[e,this.db._maxKey]],{includeLowers:!1,includeUppers:!1})}noneOf(){const e=ne.apply(De,arguments);if(e.length===0)return new this.Collection(this);try{e.sort(this._ascending)}catch{return Y(this,se)}const n=e.reduce((r,s)=>r?r.concat([[r[r.length-1][1],s]]):[[un,s]],null);return n.push([e[e.length-1],this.db._maxKey]),this.inAnyRange(n,{includeLowers:!1,includeUppers:!1})}inAnyRange(e,n){const r=this._cmp,s=this._ascending,i=this._descending,a=this._min,o=this._max;if(e.length===0)return Ne(this);if(!e.every(f=>f[0]!==void 0&&f[1]!==void 0&&s(f[0],f[1])<=0))return Y(this,"First argument to inAnyRange() must be an Array of two-value Arrays [lower,upper] where upper must not be lower than lower",C.InvalidArgument);const l=!n||n.includeLowers!==!1,u=n&&n.includeUppers===!0;let d,c=s;function h(f,_){return c(f[0],_[0])}try{d=e.reduce(function(f,_){let w=0,S=f.length;for(;w<S;++w){const x=f[w];if(r(_[0],x[1])<0&&r(_[1],x[0])>0){x[0]=a(x[0],_[0]),x[1]=o(x[1],_[1]);break}}return w===S&&f.push(_),f},[]),d.sort(h)}catch{return Y(this,se)}let p=0;const y=u?f=>s(f,d[p][1])>0:f=>s(f,d[p][1])>=0,m=l?f=>i(f,d[p][0])>0:f=>i(f,d[p][0])>=0;let v=y;const g=new this.Collection(this,()=>de(d[0][0],d[d.length-1][1],!l,!u));return g._ondirectionchange=f=>{f==="next"?(v=y,c=s):(v=m,c=i),d.sort(h)},g._addAlgorithm((f,_,w)=>{for(var S=f.key;v(S);)if(++p,p===d.length)return _(w),!1;return!!function(x){return!y(x)&&!m(x)}(S)||(this._cmp(S,d[p][1])===0||this._cmp(S,d[p][0])===0||_(()=>{c===s?f.continue(d[p][0]):f.continue(d[p][1])}),!1)}),g}startsWithAnyOf(){const e=ne.apply(De,arguments);return e.every(n=>typeof n=="string")?e.length===0?Ne(this):this.inAnyRange(e.map(n=>[n,n+_e])):Y(this,"startsWithAnyOf() only works with strings")}}function Z(t){return R(function(e){return et(e),t(e.target.error),!1})}function et(t){t.stopPropagation&&t.stopPropagation(),t.preventDefault&&t.preventDefault()}const tt="storagemutated",he="x-storagemutated-1",pe=Xe(null,tt);class Qs{_lock(){return qe(!I.global),++this._reculock,this._reculock!==1||I.global||(I.lockOwnerFor=this),this}_unlock(){if(qe(!I.global),--this._reculock==0)for(I.global||(I.lockOwnerFor=null);this._blockedFuncs.length>0&&!this._locked();){var e=this._blockedFuncs.shift();try{Re(e[1],e[0])}catch{}}return this}_locked(){return this._reculock&&I.lockOwnerFor!==this}create(e){if(!this.mode)return this;const n=this.db.idbdb,r=this.db._state.dbOpenError;if(qe(!this.idbtrans),!e&&!n)switch(r&&r.name){case"DatabaseClosedError":throw new C.DatabaseClosed(r);case"MissingAPIError":throw new C.MissingAPI(r.message,r);default:throw new C.OpenFailed(r)}if(!this.active)throw new C.TransactionInactive;return qe(this._completion._state===null),(e=this.idbtrans=e||(this.db.core?this.db.core.transaction(this.storeNames,this.mode,{durability:this.chromeTransactionDurability}):n.transaction(this.storeNames,this.mode,{durability:this.chromeTransactionDurability}))).onerror=R(s=>{et(s),this._reject(e.error)}),e.onabort=R(s=>{et(s),this.active&&this._reject(new C.Abort(e.error)),this.active=!1,this.on("abort").fire(s)}),e.oncomplete=R(()=>{this.active=!1,this._resolve(),"mutatedParts"in e&&pe.storagemutated.fire(e.mutatedParts)}),this}_promise(e,n,r){if(e==="readwrite"&&this.mode!=="readwrite")return $(new C.ReadOnly("Transaction is readonly"));if(!this.active)return $(new C.TransactionInactive);if(this._locked())return new E((i,a)=>{this._blockedFuncs.push([()=>{this._promise(e,n,r).then(i,a)},I])});if(r)return ue(()=>{var i=new E((a,o)=>{this._lock();const l=n(a,o,this);l&&l.then&&l.then(a,o)});return i.finally(()=>this._unlock()),i._lib=!0,i});var s=new E((i,a)=>{var o=n(i,a,this);o&&o.then&&o.then(i,a)});return s._lib=!0,s}_root(){return this.parent?this.parent._root():this}waitFor(e){var n=this._root();const r=E.resolve(e);if(n._waitingFor)n._waitingFor=n._waitingFor.then(()=>r);else{n._waitingFor=r,n._waitingQueue=[];var s=n.idbtrans.objectStore(n.storeNames[0]);(function a(){for(++n._spinCount;n._waitingQueue.length;)n._waitingQueue.shift()();n._waitingFor&&(s.get(-1/0).onsuccess=a)})()}var i=n._waitingFor;return new E((a,o)=>{r.then(l=>n._waitingQueue.push(R(a.bind(null,l))),l=>n._waitingQueue.push(R(o.bind(null,l)))).finally(()=>{n._waitingFor===i&&(n._waitingFor=null)})})}abort(){this.active&&(this.active=!1,this.idbtrans&&this.idbtrans.abort(),this._reject(new C.Abort))}table(e){const n=this._memoizedTables||(this._memoizedTables={});if(z(n,e))return n[e];const r=this.schema[e];if(!r)throw new C.NotFound("Table "+e+" not part of transaction");const s=new this.db.Table(e,r,this);return s.core=this.db.core.table(e),n[e]=s,s}}function mn(t,e,n,r,s,i,a){return{name:t,keyPath:e,unique:n,multi:r,auto:s,compound:i,src:(n&&!a?"&":"")+(r?"*":"")+(s?"++":"")+Pr(e)}}function Pr(t){return typeof t=="string"?t:t?"["+[].join.call(t,"+")+"]":""}function Cr(t,e,n){return{name:t,primKey:e,indexes:n,mappedClass:null,idxByName:Jn(n,r=>[r.name,r])}}let nt=t=>{try{return t.only([[]]),nt=()=>[[]],[[]]}catch{return nt=()=>_e,_e}};function yn(t){return t==null?()=>{}:typeof t=="string"?function(e){return e.split(".").length===1?n=>n[e]:n=>te(n,e)}(t):e=>te(e,t)}function Ar(t){return[].slice.call(t)}let Xs=0;function rt(t){return t==null?":id":typeof t=="string"?t:`[${t.join("+")}]`}function Zs(t,e,n){function r(l){if(l.type===3)return null;if(l.type===4)throw new Error("Cannot convert never type to IDBKeyRange");const{lower:u,upper:d,lowerOpen:c,upperOpen:h}=l;return u===void 0?d===void 0?null:e.upperBound(d,!!h):d===void 0?e.lowerBound(u,!!c):e.bound(u,d,!!c,!!h)}const{schema:s,hasGetAll:i}=function(l,u){const d=Ar(l.objectStoreNames);return{schema:{name:l.name,tables:d.map(c=>u.objectStore(c)).map(c=>{const{keyPath:h,autoIncrement:p}=c,y=F(h),m=h==null,v={},g={name:c.name,primaryKey:{name:null,isPrimaryKey:!0,outbound:m,compound:y,keyPath:h,autoIncrement:p,unique:!0,extractKey:yn(h)},indexes:Ar(c.indexNames).map(f=>c.index(f)).map(f=>{const{name:_,unique:w,multiEntry:S,keyPath:x}=f,b={name:_,compound:F(x),keyPath:x,unique:w,multiEntry:S,extractKey:yn(x)};return v[rt(x)]=b,b}),getIndexByKeyPath:f=>v[rt(f)]};return v[":id"]=g.primaryKey,h!=null&&(v[rt(h)]=g.primaryKey),g})},hasGetAll:d.length>0&&"getAll"in u.objectStore(d[0])&&!(typeof navigator<"u"&&/Safari/.test(navigator.userAgent)&&!/(Chrome\/|Edge\/)/.test(navigator.userAgent)&&[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1]<604)}}(t,n),a=s.tables.map(l=>function(u){const d=u.name;return{name:d,schema:u,mutate:function({trans:c,type:h,keys:p,values:y,range:m}){return new Promise((v,g)=>{v=R(v);const f=c.objectStore(d),_=f.keyPath==null,w=h==="put"||h==="add";if(!w&&h!=="delete"&&h!=="deleteRange")throw new Error("Invalid operation type: "+h);const{length:S}=p||y||{length:1};if(p&&y&&p.length!==y.length)throw new Error("Given keys array must have same length as given values array.");if(S===0)return v({numFailures:0,failures:{},results:[],lastResult:void 0});let x;const b=[],D=[];let k=0;const j=L=>{++k,et(L)};if(h==="deleteRange"){if(m.type===4)return v({numFailures:k,failures:D,results:[],lastResult:void 0});m.type===3?b.push(x=f.clear()):b.push(x=f.delete(r(m)))}else{const[L,M]=w?_?[y,p]:[y,null]:[p,null];if(w)for(let N=0;N<S;++N)b.push(x=M&&M[N]!==void 0?f[h](L[N],M[N]):f[h](L[N])),x.onerror=j;else for(let N=0;N<S;++N)b.push(x=f[h](L[N])),x.onerror=j}const T=L=>{const M=L.target.result;b.forEach((N,Ie)=>N.error!=null&&(D[Ie]=N.error)),v({numFailures:k,failures:D,results:h==="delete"?p:b.map(N=>N.result),lastResult:M})};x.onerror=L=>{j(L),T(L)},x.onsuccess=T})},getMany:({trans:c,keys:h})=>new Promise((p,y)=>{p=R(p);const m=c.objectStore(d),v=h.length,g=new Array(v);let f,_=0,w=0;const S=b=>{const D=b.target;g[D._pos]=D.result,++w===_&&p(g)},x=Z(y);for(let b=0;b<v;++b)h[b]!=null&&(f=m.get(h[b]),f._pos=b,f.onsuccess=S,f.onerror=x,++_);_===0&&p(g)}),get:({trans:c,key:h})=>new Promise((p,y)=>{p=R(p);const m=c.objectStore(d).get(h);m.onsuccess=v=>p(v.target.result),m.onerror=Z(y)}),query:function(c){return h=>new Promise((p,y)=>{p=R(p);const{trans:m,values:v,limit:g,query:f}=h,_=g===1/0?void 0:g,{index:w,range:S}=f,x=m.objectStore(d),b=w.isPrimaryKey?x:x.index(w.name),D=r(S);if(g===0)return p({result:[]});if(c){const k=v?b.getAll(D,_):b.getAllKeys(D,_);k.onsuccess=j=>p({result:j.target.result}),k.onerror=Z(y)}else{let k=0;const j=v||!("openKeyCursor"in b)?b.openCursor(D):b.openKeyCursor(D),T=[];j.onsuccess=L=>{const M=j.result;return M?(T.push(v?M.value:M.primaryKey),++k===g?p({result:T}):void M.continue()):p({result:T})},j.onerror=Z(y)}})}(i),openCursor:function({trans:c,values:h,query:p,reverse:y,unique:m}){return new Promise((v,g)=>{v=R(v);const{index:f,range:_}=p,w=c.objectStore(d),S=f.isPrimaryKey?w:w.index(f.name),x=y?m?"prevunique":"prev":m?"nextunique":"next",b=h||!("openKeyCursor"in S)?S.openCursor(r(_),x):S.openKeyCursor(r(_),x);b.onerror=Z(g),b.onsuccess=R(D=>{const k=b.result;if(!k)return void v(null);k.___id=++Xs,k.done=!1;const j=k.continue.bind(k);let T=k.continuePrimaryKey;T&&(T=T.bind(k));const L=k.advance.bind(k),M=()=>{throw new Error("Cursor not stopped")};k.trans=c,k.stop=k.continue=k.continuePrimaryKey=k.advance=()=>{throw new Error("Cursor not started")},k.fail=R(g),k.next=function(){let N=1;return this.start(()=>N--?this.continue():this.stop()).then(()=>this)},k.start=N=>{const Ie=new Promise((G,ye)=>{G=R(G),b.onerror=Z(ye),k.fail=ye,k.stop=$e=>{k.stop=k.continue=k.continuePrimaryKey=k.advance=M,G($e)}}),Pe=()=>{if(b.result)try{N()}catch(G){k.fail(G)}else k.done=!0,k.start=()=>{throw new Error("Cursor behind last entry")},k.stop()};return b.onsuccess=R(G=>{b.onsuccess=Pe,Pe()}),k.continue=j,k.continuePrimaryKey=T,k.advance=L,Pe(),Ie},v(k)},g)})},count({query:c,trans:h}){const{index:p,range:y}=c;return new Promise((m,v)=>{const g=h.objectStore(d),f=p.isPrimaryKey?g:g.index(p.name),_=r(y),w=_?f.count(_):f.count();w.onsuccess=R(S=>m(S.target.result)),w.onerror=Z(v)})}}}(l)),o={};return a.forEach(l=>o[l.name]=l),{stack:"dbcore",transaction:t.transaction.bind(t),table(l){if(!o[l])throw new Error(`Table '${l}' not found`);return o[l]},MIN_KEY:-1/0,MAX_KEY:nt(e),schema:s}}function gn({_novip:t},e){const n=e.db,r=function(s,i,{IDBKeyRange:a,indexedDB:o},l){return{dbcore:function(u,d){return d.reduce((c,{create:h})=>({...c,...h(c)}),u)}(Zs(i,a,l),s.dbcore)}}(t._middlewares,n,t._deps,e);t.core=r.dbcore,t.tables.forEach(s=>{const i=s.name;t.core.schema.tables.some(a=>a.name===i)&&(s.core=t.core.table(i),t[i]instanceof t.Table&&(t[i].core=s.core))})}function At({_novip:t},e,n,r){n.forEach(s=>{const i=r[s];e.forEach(a=>{const o=Ft(a,s);(!o||"value"in o&&o.value===void 0)&&(a===t.Transaction.prototype||a instanceof t.Transaction?ee(a,s,{get(){return this.table(s)},set(l){Gn(this,s,{value:l,writable:!0,configurable:!0,enumerable:!0})}}):a[s]=new t.Table(s,i))})})}function vn({_novip:t},e){e.forEach(n=>{for(let r in n)n[r]instanceof t.Table&&delete n[r]})}function ei(t,e){return t._cfg.version-e._cfg.version}function ti(t,e,n,r){const s=t._dbSchema,i=t._createTransaction("readwrite",t._storeNames,s);i.create(n),i._completion.catch(r);const a=i._reject.bind(i),o=I.transless||I;ue(()=>{I.trans=i,I.transless=o,e===0?(B(s).forEach(l=>{bn(n,l,s[l].primKey,s[l].indexes)}),gn(t,n),E.follow(()=>t.on.populate.fire(i)).catch(a)):function({_novip:l},u,d,c){const h=[],p=l._versions;let y=l._dbSchema=_n(l,l.idbdb,c),m=!1;const v=p.filter(f=>f._cfg.version>=u);function g(){return h.length?E.resolve(h.shift()(d.idbtrans)).then(g):E.resolve()}return v.forEach(f=>{h.push(()=>{const _=y,w=f._cfg.dbschema;kn(l,_,c),kn(l,w,c),y=l._dbSchema=w;const S=Dr(_,w);S.add.forEach(b=>{bn(c,b[0],b[1].primKey,b[1].indexes)}),S.change.forEach(b=>{if(b.recreate)throw new C.Upgrade("Not yet support for changing primary key");{const D=c.objectStore(b.name);b.add.forEach(k=>wn(D,k)),b.change.forEach(k=>{D.deleteIndex(k.name),wn(D,k)}),b.del.forEach(k=>D.deleteIndex(k))}});const x=f._cfg.contentUpgrade;if(x&&f._cfg.version>u){gn(l,c),d._memoizedTables={},m=!0;let b=Qn(w);S.del.forEach(T=>{b[T]=_[T]}),vn(l,[l.Transaction.prototype]),At(l,[l.Transaction.prototype],B(b),b),d.schema=b;const D=Ht(x);let k;D&&Ke();const j=E.follow(()=>{if(k=x(d),k&&D){var T=re.bind(null,null);k.then(T,T)}});return k&&typeof k.then=="function"?E.resolve(k):j.then(()=>k)}}),h.push(_=>{(!m||!Hs)&&function(w,S){[].slice.call(S.db.objectStoreNames).forEach(x=>w[x]==null&&S.db.deleteObjectStore(x))}(f._cfg.dbschema,_),vn(l,[l.Transaction.prototype]),At(l,[l.Transaction.prototype],l._storeNames,l._dbSchema),d.schema=l._dbSchema})}),g().then(()=>{var f,_;_=c,B(f=y).forEach(w=>{_.db.objectStoreNames.contains(w)||bn(_,w,f[w].primKey,f[w].indexes)})})}(t,e,i,n).catch(a)})}function Dr(t,e){const n={del:[],add:[],change:[]};let r;for(r in t)e[r]||n.del.push(r);for(r in e){const s=t[r],i=e[r];if(s){const a={name:r,def:i,recreate:!1,del:[],add:[],change:[]};if(""+(s.primKey.keyPath||"")!=""+(i.primKey.keyPath||"")||s.primKey.auto!==i.primKey.auto&&!xt)a.recreate=!0,n.change.push(a);else{const o=s.idxByName,l=i.idxByName;let u;for(u in o)l[u]||a.del.push(u);for(u in l){const d=o[u],c=l[u];d?d.src!==c.src&&a.change.push(c):a.add.push(c)}(a.del.length>0||a.add.length>0||a.change.length>0)&&n.change.push(a)}}else n.add.push([r,i])}return n}function bn(t,e,n,r){const s=t.db.createObjectStore(e,n.keyPath?{keyPath:n.keyPath,autoIncrement:n.auto}:{autoIncrement:n.auto});return r.forEach(i=>wn(s,i)),s}function wn(t,e){t.createIndex(e.name,e.keyPath,{unique:e.unique,multiEntry:e.multi})}function _n(t,e,n){const r={};return ut(e.objectStoreNames,0).forEach(s=>{const i=n.objectStore(s);let a=i.keyPath;const o=mn(Pr(a),a||"",!1,!1,!!i.autoIncrement,a&&typeof a!="string",!0),l=[];for(let d=0;d<i.indexNames.length;++d){const c=i.index(i.indexNames[d]);a=c.keyPath;var u=mn(c.name,a,!!c.unique,!!c.multiEntry,!1,a&&typeof a!="string",!1);l.push(u)}r[s]=Cr(s,o,l)}),r}function kn({_novip:t},e,n){const r=n.db.objectStoreNames;for(let s=0;s<r.length;++s){const i=r[s],a=n.objectStore(i);t._hasGetAll="getAll"in a;for(let o=0;o<a.indexNames.length;++o){const l=a.indexNames[o],u=a.index(l).keyPath,d=typeof u=="string"?u:"["+ut(u).join("+")+"]";if(e[i]){const c=e[i].idxByName[d];c&&(c.name=l,delete e[i].idxByName[d],e[i].idxByName[l]=c)}}}typeof navigator<"u"&&/Safari/.test(navigator.userAgent)&&!/(Chrome\/|Edge\/)/.test(navigator.userAgent)&&K.WorkerGlobalScope&&K instanceof K.WorkerGlobalScope&&[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1]<604&&(t._hasGetAll=!1)}class ni{_parseStoresSpec(e,n){B(e).forEach(r=>{if(e[r]!==null){var s=e[r].split(",").map((a,o)=>{const l=(a=a.trim()).replace(/([&*]|\+\+)/g,""),u=/^\[/.test(l)?l.match(/^\[(.*)\]$/)[1].split("+"):l;return mn(l,u||null,/\&/.test(a),/\*/.test(a),/\+\+/.test(a),F(u),o===0)}),i=s.shift();if(i.multi)throw new C.Schema("Primary key cannot be multi-valued");s.forEach(a=>{if(a.auto)throw new C.Schema("Only primary key can be marked as autoIncrement (++)");if(!a.keyPath)throw new C.Schema("Index must have a name and cannot be an empty string")}),n[r]=Cr(r,i,s)}})}stores(e){const n=this.db;this._cfg.storesSource=this._cfg.storesSource?W(this._cfg.storesSource,e):e;const r=n._versions,s={};let i={};return r.forEach(a=>{W(s,a._cfg.storesSource),i=a._cfg.dbschema={},a._parseStoresSpec(s,i)}),n._dbSchema=i,vn(n,[n._allTables,n,n.Transaction.prototype]),At(n,[n._allTables,n,n.Transaction.prototype,this._cfg.tables],B(i),i),n._storeNames=B(i),this}upgrade(e){return this._cfg.contentUpgrade=zt(this._cfg.contentUpgrade||O,e),this}}function xn(t,e){let n=t._dbNamesDB;return n||(n=t._dbNamesDB=new Se(Et,{addons:[],indexedDB:t,IDBKeyRange:e}),n.version(1).stores({dbnames:"name"})),n.table("dbnames")}function En(t){return t&&typeof t.databases=="function"}function Sn(t){return ue(function(){return I.letThrough=!0,t()})}function ri(){var t;return!navigator.userAgentData&&/Safari\//.test(navigator.userAgent)&&!/Chrom(e|ium)\//.test(navigator.userAgent)&&indexedDB.databases?new Promise(function(e){var n=function(){return indexedDB.databases().finally(e)};t=setInterval(n,100),n()}).finally(function(){return clearInterval(t)}):Promise.resolve()}function si(t){const e=t._state,{indexedDB:n}=t._deps;if(e.isBeingOpened||t.idbdb)return e.dbReadyPromise.then(()=>e.dbOpenError?$(e.dbOpenError):t);X&&(e.openCanceller._stackHolder=ge()),e.isBeingOpened=!0,e.dbOpenError=null,e.openComplete=!1;const r=e.openCanceller;function s(){if(e.openCanceller!==r)throw new C.DatabaseClosed("db.open() was cancelled")}let i=e.dbReadyResolve,a=null,o=!1;const l=()=>new E((u,d)=>{if(s(),!n)throw new C.MissingAPI;const c=t.name,h=e.autoSchema?n.open(c):n.open(c,Math.round(10*t.verno));if(!h)throw new C.MissingAPI;h.onerror=Z(d),h.onblocked=R(t._fireOnBlocked),h.onupgradeneeded=R(p=>{if(a=h.transaction,e.autoSchema&&!t._options.allowEmptyDB){h.onerror=et,a.abort(),h.result.close();const m=n.deleteDatabase(c);m.onsuccess=m.onerror=R(()=>{d(new C.NoSuchDatabase(`Database ${c} doesnt exist`))})}else{a.onerror=Z(d);var y=p.oldVersion>Math.pow(2,62)?0:p.oldVersion;o=y<1,t._novip.idbdb=h.result,ti(t,y/10,a,d)}},d),h.onsuccess=R(()=>{a=null;const p=t._novip.idbdb=h.result,y=ut(p.objectStoreNames);if(y.length>0)try{const v=p.transaction((m=y).length===1?m[0]:m,"readonly");e.autoSchema?function({_novip:g},f,_){g.verno=f.version/10;const w=g._dbSchema=_n(0,f,_);g._storeNames=ut(f.objectStoreNames,0),At(g,[g._allTables],B(w),w)}(t,p,v):(kn(t,t._dbSchema,v),function(g,f){const _=Dr(_n(0,g.idbdb,f),g._dbSchema);return!(_.add.length||_.change.some(w=>w.add.length||w.change.length))}(t,v)||console.warn("Dexie SchemaDiff: Schema was extended without increasing the number passed to db.version(). Some queries may fail.")),gn(t,v)}catch{}var m;Qe.push(t),p.onversionchange=R(v=>{e.vcFired=!0,t.on("versionchange").fire(v)}),p.onclose=R(v=>{t.on("close").fire(v)}),o&&function({indexedDB:v,IDBKeyRange:g},f){!En(v)&&f!==Et&&xn(v,g).put({name:f}).catch(O)}(t._deps,c),u()},d)}).catch(u=>u&&u.name==="UnknownError"&&e.PR1398_maxLoop>0?(e.PR1398_maxLoop--,console.warn("Dexie: Workaround for Chrome UnknownError on open()"),l()):E.reject(u));return E.race([r,(typeof navigator>"u"?E.resolve():ri()).then(l)]).then(()=>(s(),e.onReadyBeingFired=[],E.resolve(Sn(()=>t.on.ready.fire(t.vip))).then(function u(){if(e.onReadyBeingFired.length>0){let d=e.onReadyBeingFired.reduce(zt,O);return e.onReadyBeingFired=[],E.resolve(Sn(()=>d(t.vip))).then(u)}}))).finally(()=>{e.onReadyBeingFired=null,e.isBeingOpened=!1}).then(()=>t).catch(u=>{e.dbOpenError=u;try{a&&a.abort()}catch{}return r===e.openCanceller&&t._close(),$(u)}).finally(()=>{e.openComplete=!0,i()})}function In(t){var e=i=>t.next(i),n=s(e),r=s(i=>t.throw(i));function s(i){return a=>{var o=i(a),l=o.value;return o.done?l:l&&typeof l.then=="function"?l.then(n,r):F(l)?Promise.all(l).then(n,r):n(l)}}return s(e)()}function ii(t,e,n){var r=arguments.length;if(r<2)throw new C.InvalidArgument("Too few arguments");for(var s=new Array(r-1);--r;)s[r-1]=arguments[r];return n=s.pop(),[t,Xn(s),n]}function Tr(t,e,n,r,s){return E.resolve().then(()=>{const i=I.transless||I,a=t._createTransaction(e,n,t._dbSchema,r),o={trans:a,transless:i};if(r)a.idbtrans=r.idbtrans;else try{a.create(),t._state.PR1398_maxLoop=3}catch(c){return c.name===Gt.InvalidState&&t.isOpen()&&--t._state.PR1398_maxLoop>0?(console.warn("Dexie: Need to reopen db"),t._close(),t.open().then(()=>Tr(t,e,n,null,s))):$(c)}const l=Ht(s);let u;l&&Ke();const d=E.follow(()=>{if(u=s.call(a,a),u)if(l){var c=re.bind(null,null);u.then(c,c)}else typeof u.next=="function"&&typeof u.throw=="function"&&(u=In(u))},o);return(u&&typeof u.then=="function"?E.resolve(u).then(c=>a.active?c:$(new C.PrematureCommit("Transaction committed too early. See http://bit.ly/2kdckMn"))):d.then(()=>u)).then(c=>(r&&a._resolve(),a._completion.then(()=>c))).catch(c=>(a._reject(c),$(c)))})}function Dt(t,e,n){const r=F(t)?t.slice():[t];for(let s=0;s<n;++s)r.push(e);return r}const ai={stack:"dbcore",name:"VirtualIndexMiddleware",level:1,create:function(t){return{...t,table(e){const n=t.table(e),{schema:r}=n,s={},i=[];function a(u,d,c){const h=rt(u),p=s[h]=s[h]||[],y=u==null?0:typeof u=="string"?1:u.length,m=d>0,v={...c,isVirtual:m,keyTail:d,keyLength:y,extractKey:yn(u),unique:!m&&c.unique};return p.push(v),v.isPrimaryKey||i.push(v),y>1&&a(y===2?u[0]:u.slice(0,y-1),d+1,c),p.sort((g,f)=>g.keyTail-f.keyTail),v}const o=a(r.primaryKey.keyPath,0,r.primaryKey);s[":id"]=[o];for(const u of r.indexes)a(u.keyPath,0,u);function l(u){const d=u.query.index;return d.isVirtual?{...u,query:{index:d,range:(c=u.query.range,h=d.keyTail,{type:c.type===1?2:c.type,lower:Dt(c.lower,c.lowerOpen?t.MAX_KEY:t.MIN_KEY,h),lowerOpen:!0,upper:Dt(c.upper,c.upperOpen?t.MIN_KEY:t.MAX_KEY,h),upperOpen:!0})}}:u;var c,h}return{...n,schema:{...r,primaryKey:o,indexes:i,getIndexByKeyPath:function(u){const d=s[rt(u)];return d&&d[0]}},count:u=>n.count(l(u)),query:u=>n.query(l(u)),openCursor(u){const{keyTail:d,isVirtual:c,keyLength:h}=u.query.index;return c?n.openCursor(l(u)).then(p=>p&&function(y){return Object.create(y,{continue:{value:function(m){m!=null?y.continue(Dt(m,u.reverse?t.MAX_KEY:t.MIN_KEY,d)):u.unique?y.continue(y.key.slice(0,h).concat(u.reverse?t.MIN_KEY:t.MAX_KEY,d)):y.continue()}},continuePrimaryKey:{value(m,v){y.continuePrimaryKey(Dt(m,t.MAX_KEY,d),v)}},primaryKey:{get:()=>y.primaryKey},key:{get(){const m=y.key;return h===1?m[0]:m.slice(0,h)}},value:{get:()=>y.value}})}(p)):n.openCursor(u)}}}}}};function Pn(t,e,n,r){return n=n||{},r=r||"",B(t).forEach(s=>{if(z(e,s)){var i=t[s],a=e[s];if(typeof i=="object"&&typeof a=="object"&&i&&a){const o=qt(i);o!==qt(a)?n[r+s]=e[s]:o==="Object"?Pn(i,a,n,r+s+"."):i!==a&&(n[r+s]=e[s])}else i!==a&&(n[r+s]=e[s])}else n[r+s]=void 0}),B(e).forEach(s=>{z(t,s)||(n[r+s]=e[s])}),n}const oi={stack:"dbcore",name:"HooksMiddleware",level:2,create:t=>({...t,table(e){const n=t.table(e),{primaryKey:r}=n.schema;return{...n,mutate(s){const i=I.trans,{deleting:a,creating:o,updating:l}=i.table(e).hook;switch(s.type){case"add":if(o.fire===O)break;return i._promise("readwrite",()=>u(s),!0);case"put":if(o.fire===O&&l.fire===O)break;return i._promise("readwrite",()=>u(s),!0);case"delete":if(a.fire===O)break;return i._promise("readwrite",()=>u(s),!0);case"deleteRange":if(a.fire===O)break;return i._promise("readwrite",()=>function(c){return d(c.trans,c.range,1e4)}(s),!0)}return n.mutate(s);function u(c){const h=I.trans,p=c.keys||function(y,m){return m.type==="delete"?m.keys:m.keys||m.values.map(y.extractKey)}(r,c);if(!p)throw new Error("Keys missing");return(c=c.type==="add"||c.type==="put"?{...c,keys:p}:{...c}).type!=="delete"&&(c.values=[...c.values]),c.keys&&(c.keys=[...c.keys]),function(y,m,v){return m.type==="add"?Promise.resolve([]):y.getMany({trans:m.trans,keys:v,cache:"immutable"})}(n,c,p).then(y=>{const m=p.map((v,g)=>{const f=y[g],_={onerror:null,onsuccess:null};if(c.type==="delete")a.fire.call(_,v,f,h);else if(c.type==="add"||f===void 0){const w=o.fire.call(_,v,c.values[g],h);v==null&&w!=null&&(v=w,c.keys[g]=v,r.outbound||J(c.values[g],r.keyPath,v))}else{const w=Pn(f,c.values[g]),S=l.fire.call(_,w,v,f,h);if(S){const x=c.values[g];Object.keys(S).forEach(b=>{z(x,b)?x[b]=S[b]:J(x,b,S[b])})}}return _});return n.mutate(c).then(({failures:v,results:g,numFailures:f,lastResult:_})=>{for(let w=0;w<p.length;++w){const S=g?g[w]:p[w],x=m[w];S==null?x.onerror&&x.onerror(v[w]):x.onsuccess&&x.onsuccess(c.type==="put"&&y[w]?c.values[w]:S)}return{failures:v,results:g,numFailures:f,lastResult:_}}).catch(v=>(m.forEach(g=>g.onerror&&g.onerror(v)),Promise.reject(v)))})}function d(c,h,p){return n.query({trans:c,values:!1,query:{index:r,range:h},limit:p}).then(({result:y})=>u({type:"delete",keys:y,trans:c}).then(m=>m.numFailures>0?Promise.reject(m.failures[0]):y.length<p?{failures:[],numFailures:0,lastResult:void 0}:d(c,{...h,lower:y[y.length-1],lowerOpen:!0},p)))}}}}})};function Or(t,e,n){try{if(!e||e.keys.length<t.length)return null;const r=[];for(let s=0,i=0;s<e.keys.length&&i<t.length;++s)V(e.keys[s],t[i])===0&&(r.push(n?Le(e.values[s]):e.values[s]),++i);return r.length===t.length?r:null}catch{return null}}const li={stack:"dbcore",level:-1,create:t=>({table:e=>{const n=t.table(e);return{...n,getMany:r=>{if(!r.cache)return n.getMany(r);const s=Or(r.keys,r.trans._cache,r.cache==="clone");return s?E.resolve(s):n.getMany(r).then(i=>(r.trans._cache={keys:r.keys,values:r.cache==="clone"?Le(i):i},i))},mutate:r=>(r.type!=="add"&&(r.trans._cache=null),n.mutate(r))}}})};function Cn(t){return!("from"in t)}const ie=function(t,e){if(!this){const n=new ie;return t&&"d"in t&&W(n,t),n}W(this,arguments.length?{d:1,from:t,to:arguments.length>1?e:t}:{d:0})};function st(t,e,n){const r=V(e,n);if(isNaN(r))return;if(r>0)throw RangeError();if(Cn(t))return W(t,{from:e,to:n,d:1});const s=t.l,i=t.r;if(V(n,t.from)<0)return s?st(s,e,n):t.l={from:e,to:n,d:1,l:null,r:null},Kr(t);if(V(e,t.to)>0)return i?st(i,e,n):t.r={from:e,to:n,d:1,l:null,r:null},Kr(t);V(e,t.from)<0&&(t.from=e,t.l=null,t.d=i?i.d+1:1),V(n,t.to)>0&&(t.to=n,t.r=null,t.d=t.l?t.l.d+1:1);const a=!t.r;s&&!t.l&&Tt(t,s),i&&a&&Tt(t,i)}function Tt(t,e){Cn(e)||function n(r,{from:s,to:i,l:a,r:o}){st(r,s,i),a&&n(r,a),o&&n(r,o)}(t,e)}function ui(t,e){const n=An(e);let r=n.next();if(r.done)return!1;let s=r.value;const i=An(t);let a=i.next(s.from),o=a.value;for(;!r.done&&!a.done;){if(V(o.from,s.to)<=0&&V(o.to,s.from)>=0)return!0;V(s.from,o.from)<0?s=(r=n.next(o.from)).value:o=(a=i.next(s.from)).value}return!1}function An(t){let e=Cn(t)?null:{s:0,n:t};return{next(n){const r=arguments.length>0;for(;e;)switch(e.s){case 0:if(e.s=1,r)for(;e.n.l&&V(n,e.n.from)<0;)e={up:e,n:e.n.l,s:1};else for(;e.n.l;)e={up:e,n:e.n.l,s:1};case 1:if(e.s=2,!r||V(n,e.n.to)<=0)return{value:e.n,done:!1};case 2:if(e.n.r){e.s=3,e={up:e,n:e.n.r,s:0};continue}case 3:e=e.up}return{done:!0}}}}function Kr(t){var e,n;const r=(((e=t.r)===null||e===void 0?void 0:e.d)||0)-(((n=t.l)===null||n===void 0?void 0:n.d)||0),s=r>1?"r":r<-1?"l":"";if(s){const i=s==="r"?"l":"r",a={...t},o=t[s];t.from=o.from,t.to=o.to,t[s]=o[s],a[s]=o[i],t[i]=a,a.d=Rr(a)}t.d=Rr(t)}function Rr({r:t,l:e}){return(t?e?Math.max(t.d,e.d):t.d:e?e.d:0)+1}Ce(ie.prototype,{add(t){return Tt(this,t),this},addKey(t){return st(this,t,t),this},addKeys(t){return t.forEach(e=>st(this,e,e)),this},[Lt](){return An(this)}});const ci={stack:"dbcore",level:0,create:t=>{const e=t.schema.name,n=new ie(t.MIN_KEY,t.MAX_KEY);return{...t,table:r=>{const s=t.table(r),{schema:i}=s,{primaryKey:a}=i,{extractKey:o,outbound:l}=a,u={...s,mutate:h=>{const p=h.trans,y=p.mutatedParts||(p.mutatedParts={}),m=x=>{const b=`idb://${e}/${r}/${x}`;return y[b]||(y[b]=new ie)},v=m(""),g=m(":dels"),{type:f}=h;let[_,w]=h.type==="deleteRange"?[h.range]:h.type==="delete"?[h.keys]:h.values.length<50?[[],h.values]:[];const S=h.trans._cache;return s.mutate(h).then(x=>{if(F(_)){f!=="delete"&&(_=x.results),v.addKeys(_);const b=Or(_,S);b||f==="add"||g.addKeys(_),(b||w)&&function(D,k,j,T){function L(M){const N=D(M.name||"");function Ie(G){return G!=null?M.extractKey(G):null}const Pe=G=>M.multiEntry&&F(G)?G.forEach(ye=>N.addKey(ye)):N.addKey(G);(j||T).forEach((G,ye)=>{const $e=j&&Ie(j[ye]),Bt=T&&Ie(T[ye]);V($e,Bt)!==0&&($e!=null&&Pe($e),Bt!=null&&Pe(Bt))})}k.indexes.forEach(L)}(m,i,b,w)}else if(_){const b={from:_.lower,to:_.upper};g.add(b),v.add(b)}else v.add(n),g.add(n),i.indexes.forEach(b=>m(b.name).add(n));return x})}},d=({query:{index:h,range:p}})=>{var y,m;return[h,new ie((y=p.lower)!==null&&y!==void 0?y:t.MIN_KEY,(m=p.upper)!==null&&m!==void 0?m:t.MAX_KEY)]},c={get:h=>[a,new ie(h.key)],getMany:h=>[a,new ie().addKeys(h.keys)],count:d,query:d,openCursor:d};return B(c).forEach(h=>{u[h]=function(p){const{subscr:y}=I;if(y){const m=w=>{const S=`idb://${e}/${r}/${w}`;return y[S]||(y[S]=new ie)},v=m(""),g=m(":dels"),[f,_]=c[h](p);if(m(f.name||"").add(_),!f.isPrimaryKey){if(h!=="count"){const w=h==="query"&&l&&p.values&&s.query({...p,values:!1});return s[h].apply(this,arguments).then(S=>{if(h==="query"){if(l&&p.values)return w.then(({result:b})=>(v.addKeys(b),S));const x=p.values?S.result.map(o):S.result;p.values?v.addKeys(x):g.addKeys(x)}else if(h==="openCursor"){const x=S,b=p.values;return x&&Object.create(x,{key:{get:()=>(g.addKey(x.primaryKey),x.key)},primaryKey:{get(){const D=x.primaryKey;return g.addKey(D),D}},value:{get:()=>(b&&v.addKey(x.primaryKey),x.value)}})}return S})}g.add(n)}}return s[h].apply(this,arguments)}}),u}}}};class Se{constructor(e,n){this._middlewares={},this.verno=0;const r=Se.dependencies;this._options=n={addons:Se.addons,autoOpen:!0,indexedDB:r.indexedDB,IDBKeyRange:r.IDBKeyRange,...n},this._deps={indexedDB:n.indexedDB,IDBKeyRange:n.IDBKeyRange};const{addons:s}=n;this._dbSchema={},this._versions=[],this._storeNames=[],this._allTables={},this.idbdb=null,this._novip=this;const i={dbOpenError:null,isBeingOpened:!1,onReadyBeingFired:null,openComplete:!1,dbReadyResolve:O,dbReadyPromise:null,cancelOpen:O,openCanceller:null,autoSchema:!0,PR1398_maxLoop:3};var a;i.dbReadyPromise=new E(o=>{i.dbReadyResolve=o}),i.openCanceller=new E((o,l)=>{i.cancelOpen=l}),this._state=i,this.name=e,this.on=Xe(this,"populate","blocked","versionchange","close",{ready:[zt,O]}),this.on.ready.subscribe=zn(this.on.ready.subscribe,o=>(l,u)=>{Se.vip(()=>{const d=this._state;if(d.openComplete)d.dbOpenError||E.resolve().then(l),u&&o(l);else if(d.onReadyBeingFired)d.onReadyBeingFired.push(l),u&&o(l);else{o(l);const c=this;u||o(function h(){c.on.ready.unsubscribe(l),c.on.ready.unsubscribe(h)})}})}),this.Collection=(a=this,Ze(Gs.prototype,function(o,l){this.db=a;let u=wr,d=null;if(l)try{u=l()}catch(y){d=y}const c=o._ctx,h=c.table,p=h.hook.reading.fire;this._ctx={table:h,index:c.index,isPrimKey:!c.index||h.schema.primKey.keyPath&&c.index===h.schema.primKey.name,range:u,keysOnly:!1,dir:"next",unique:"",algorithm:null,filter:null,replayFilter:null,justLimit:!0,isMatch:null,offset:0,limit:1/0,error:d,or:c.or,valueMapper:p!==We?p:null}})),this.Table=function(o){return Ze(Vs.prototype,function(l,u,d){this.db=o,this._tx=d,this.name=l,this.schema=u,this.hook=o._allTables[l]?o._allTables[l].hook:Xe(null,{creating:[Rs,O],reading:[Ks,We],updating:[Ns,O],deleting:[js,O]})})}(this),this.Transaction=function(o){return Ze(Qs.prototype,function(l,u,d,c,h){this.db=o,this.mode=l,this.storeNames=u,this.schema=d,this.chromeTransactionDurability=c,this.idbtrans=null,this.on=Xe(this,"complete","error","abort"),this.parent=h||null,this.active=!0,this._reculock=0,this._blockedFuncs=[],this._resolve=null,this._reject=null,this._waitingFor=null,this._waitingQueue=null,this._spinCount=0,this._completion=new E((p,y)=>{this._resolve=p,this._reject=y}),this._completion.then(()=>{this.active=!1,this.on.complete.fire()},p=>{var y=this.active;return this.active=!1,this.on.error.fire(p),this.parent?this.parent._reject(p):y&&this.idbtrans&&this.idbtrans.abort(),$(p)})})}(this),this.Version=function(o){return Ze(ni.prototype,function(l){this.db=o,this._cfg={version:l,storesSource:null,dbschema:{},tables:{},contentUpgrade:null}})}(this),this.WhereClause=function(o){return Ze(Ir.prototype,function(l,u,d){this.db=o,this._ctx={table:l,index:u===":id"?null:u,or:d};const c=o._deps.indexedDB;if(!c)throw new C.MissingAPI;this._cmp=this._ascending=c.cmp.bind(c),this._descending=(h,p)=>c.cmp(p,h),this._max=(h,p)=>c.cmp(h,p)>0?h:p,this._min=(h,p)=>c.cmp(h,p)<0?h:p,this._IDBKeyRange=o._deps.IDBKeyRange})}(this),this.on("versionchange",o=>{o.newVersion>0?console.warn(`Another connection wants to upgrade database '${this.name}'. Closing db now to resume the upgrade.`):console.warn(`Another connection wants to delete database '${this.name}'. Closing db now to resume the delete request.`),this.close()}),this.on("blocked",o=>{!o.newVersion||o.newVersion<o.oldVersion?console.warn(`Dexie.delete('${this.name}') was blocked`):console.warn(`Upgrade '${this.name}' blocked by other connection holding version ${o.oldVersion/10}`)}),this._maxKey=nt(n.IDBKeyRange),this._createTransaction=(o,l,u,d)=>new this.Transaction(o,l,u,this._options.chromeTransactionDurability,d),this._fireOnBlocked=o=>{this.on("blocked").fire(o),Qe.filter(l=>l.name===this.name&&l!==this&&!l._state.vcFired).map(l=>l.on("versionchange").fire(o))},this.use(ai),this.use(oi),this.use(ci),this.use(li),this.vip=Object.create(this,{_vip:{value:!0}}),s.forEach(o=>o(this))}version(e){if(isNaN(e)||e<.1)throw new C.Type("Given version is not a positive number");if(e=Math.round(10*e)/10,this.idbdb||this._state.isBeingOpened)throw new C.Schema("Cannot add version when database is open");this.verno=Math.max(this.verno,e);const n=this._versions;var r=n.filter(s=>s._cfg.version===e)[0];return r||(r=new this.Version(e),n.push(r),n.sort(ei),r.stores({}),this._state.autoSchema=!1,r)}_whenReady(e){return this.idbdb&&(this._state.openComplete||I.letThrough||this._vip)?e():new E((n,r)=>{if(this._state.openComplete)return r(new C.DatabaseClosed(this._state.dbOpenError));if(!this._state.isBeingOpened){if(!this._options.autoOpen)return void r(new C.DatabaseClosed);this.open().catch(O)}this._state.dbReadyPromise.then(n,r)}).then(e)}use({stack:e,create:n,level:r,name:s}){s&&this.unuse({stack:e,name:s});const i=this._middlewares[e]||(this._middlewares[e]=[]);return i.push({stack:e,create:n,level:r??10,name:s}),i.sort((a,o)=>a.level-o.level),this}unuse({stack:e,name:n,create:r}){return e&&this._middlewares[e]&&(this._middlewares[e]=this._middlewares[e].filter(s=>r?s.create!==r:!!n&&s.name!==n)),this}open(){return si(this)}_close(){const e=this._state,n=Qe.indexOf(this);if(n>=0&&Qe.splice(n,1),this.idbdb){try{this.idbdb.close()}catch{}this._novip.idbdb=null}e.dbReadyPromise=new E(r=>{e.dbReadyResolve=r}),e.openCanceller=new E((r,s)=>{e.cancelOpen=s})}close(){this._close();const e=this._state;this._options.autoOpen=!1,e.dbOpenError=new C.DatabaseClosed,e.isBeingOpened&&e.cancelOpen(e.dbOpenError)}delete(){const e=arguments.length>0,n=this._state;return new E((r,s)=>{const i=()=>{this.close();var a=this._deps.indexedDB.deleteDatabase(this.name);a.onsuccess=R(()=>{(function({indexedDB:o,IDBKeyRange:l},u){!En(o)&&u!==Et&&xn(o,l).delete(u).catch(O)})(this._deps,this.name),r()}),a.onerror=Z(s),a.onblocked=this._fireOnBlocked};if(e)throw new C.InvalidArgument("Arguments not allowed in db.delete()");n.isBeingOpened?n.dbReadyPromise.then(i):i()})}backendDB(){return this.idbdb}isOpen(){return this.idbdb!==null}hasBeenClosed(){const e=this._state.dbOpenError;return e&&e.name==="DatabaseClosed"}hasFailed(){return this._state.dbOpenError!==null}dynamicallyOpened(){return this._state.autoSchema}get tables(){return B(this._allTables).map(e=>this._allTables[e])}transaction(){const e=ii.apply(this,arguments);return this._transaction.apply(this,e)}_transaction(e,n,r){let s=I.trans;s&&s.db===this&&e.indexOf("!")===-1||(s=null);const i=e.indexOf("?")!==-1;let a,o;e=e.replace("!","").replace("?","");try{if(o=n.map(u=>{var d=u instanceof this.Table?u.name:u;if(typeof d!="string")throw new TypeError("Invalid table argument to Dexie.transaction(). Only Table or String are allowed");return d}),e=="r"||e===cn)a=cn;else{if(e!="rw"&&e!=dn)throw new C.InvalidArgument("Invalid transaction mode: "+e);a=dn}if(s){if(s.mode===cn&&a===dn){if(!i)throw new C.SubTransaction("Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY");s=null}s&&o.forEach(u=>{if(s&&s.storeNames.indexOf(u)===-1){if(!i)throw new C.SubTransaction("Table "+u+" not included in parent transaction.");s=null}}),i&&s&&!s.active&&(s=null)}}catch(u){return s?s._promise(null,(d,c)=>{c(u)}):$(u)}const l=Tr.bind(null,this,a,o,s,r);return s?s._promise(a,l,"lock"):I.trans?Re(I.transless,()=>this._whenReady(l)):this._whenReady(l)}table(e){if(!z(this._allTables,e))throw new C.InvalidTable(`Table ${e} does not exist`);return this._allTables[e]}}const di=typeof Symbol<"u"&&"observable"in Symbol?Symbol.observable:"@@observable";class hi{constructor(e){this._subscribe=e}subscribe(e,n,r){return this._subscribe(e&&typeof e!="function"?e:{next:e,error:n,complete:r})}[di](){return this}}function jr(t,e){return B(e).forEach(n=>{Tt(t[n]||(t[n]=new ie),e[n])}),t}function pi(t){let e,n=!1;const r=new hi(s=>{const i=Ht(t);let a=!1,o={},l={};const u={get closed(){return a},unsubscribe:()=>{a=!0,pe.storagemutated.unsubscribe(p)}};s.start&&s.start(u);let d=!1,c=!1;function h(){return B(l).some(m=>o[m]&&ui(o[m],l[m]))}const p=m=>{jr(o,m),h()&&y()},y=()=>{if(d||a)return;o={};const m={},v=function(g){i&&Ke();const f=()=>ue(t,{subscr:g,trans:null}),_=I.trans?Re(I.transless,f):f();return i&&_.then(re,re),_}(m);c||(pe(tt,p),c=!0),d=!0,Promise.resolve(v).then(g=>{n=!0,e=g,d=!1,a||(h()?y():(o={},l=m,s.next&&s.next(g)))},g=>{d=!1,n=!1,s.error&&s.error(g),u.unsubscribe()})};return y(),u});return r.hasValue=()=>n,r.getValue=()=>e,r}let Dn;try{Dn={indexedDB:K.indexedDB||K.mozIndexedDB||K.webkitIndexedDB||K.msIndexedDB,IDBKeyRange:K.IDBKeyRange||K.webkitIDBKeyRange}}catch{Dn={indexedDB:null,IDBKeyRange:null}}const xe=Se;function Ot(t){let e=ae;try{ae=!0,pe.storagemutated.fire(t)}finally{ae=e}}Ce(xe,{...dt,delete:t=>new xe(t,{addons:[]}).delete(),exists:t=>new xe(t,{addons:[]}).open().then(e=>(e.close(),!0)).catch("NoSuchDatabaseError",()=>!1),getDatabaseNames(t){try{return function({indexedDB:e,IDBKeyRange:n}){return En(e)?Promise.resolve(e.databases()).then(r=>r.map(s=>s.name).filter(s=>s!==Et)):xn(e,n).toCollection().primaryKeys()}(xe.dependencies).then(t)}catch{return $(new C.MissingAPI)}},defineClass:()=>function(t){W(this,t)},ignoreTransaction:t=>I.trans?Re(I.transless,t):t(),vip:Sn,async:function(t){return function(){try{var e=In(t.apply(this,arguments));return e&&typeof e.then=="function"?e:E.resolve(e)}catch(n){return $(n)}}},spawn:function(t,e,n){try{var r=In(t.apply(n,e||[]));return r&&typeof r.then=="function"?r:E.resolve(r)}catch(s){return $(s)}},currentTransaction:{get:()=>I.trans||null},waitFor:function(t,e){const n=E.resolve(typeof t=="function"?xe.ignoreTransaction(t):t).timeout(e||6e4);return I.trans?I.trans.waitFor(n):n},Promise:E,debug:{get:()=>X,set:t=>{er(t,t==="dexie"?()=>!0:br)}},derive:Ae,extend:W,props:Ce,override:zn,Events:Xe,on:pe,liveQuery:pi,extendObservabilitySet:jr,getByKeyPath:te,setByKeyPath:J,delByKeyPath:function(t,e){typeof e=="string"?J(t,e,void 0):"length"in e&&[].map.call(e,function(n){J(t,n,void 0)})},shallowClone:Qn,deepClone:Le,getObjectDiff:Pn,cmp:V,asap:Yn,minKey:un,addons:[],connections:Qe,errnames:Gt,dependencies:Dn,semVer:gr,version:gr.split(".").map(t=>parseInt(t)).reduce((t,e,n)=>t+e/Math.pow(10,2*n))}),xe.maxKey=nt(xe.dependencies.IDBKeyRange),typeof dispatchEvent<"u"&&typeof addEventListener<"u"&&(pe(tt,t=>{if(!ae){let e;xt?(e=document.createEvent("CustomEvent"),e.initCustomEvent(he,!0,!0,t)):e=new CustomEvent(he,{detail:t}),ae=!0,dispatchEvent(e),ae=!1}}),addEventListener(he,({detail:t})=>{ae||Ot(t)}));let ae=!1;if(typeof BroadcastChannel<"u"){const t=new BroadcastChannel(he);typeof t.unref=="function"&&t.unref(),pe(tt,e=>{ae||t.postMessage(e)}),t.onmessage=e=>{e.data&&Ot(e.data)}}else if(typeof self<"u"&&typeof navigator<"u"){pe(tt,e=>{try{ae||(typeof localStorage<"u"&&localStorage.setItem(he,JSON.stringify({trig:Math.random(),changedParts:e})),typeof self.clients=="object"&&[...self.clients.matchAll({includeUncontrolled:!0})].forEach(n=>n.postMessage({type:he,changedParts:e})))}catch{}}),typeof addEventListener<"u"&&addEventListener("storage",e=>{if(e.key===he){const n=JSON.parse(e.newValue);n&&Ot(n.changedParts)}});const t=self.document&&navigator.serviceWorker;t&&t.addEventListener("message",function({data:e}){e&&e.type===he&&Ot(e.changedParts)})}E.rejectionMapper=function(t,e){if(!t||t instanceof Te||t instanceof TypeError||t instanceof SyntaxError||!t.name||!sr[t.name])return t;var n=new sr[t.name](e||t.message,t);return"stack"in t&&ee(n,"stack",{get:function(){return this.inner.stack}}),n},er(X,br);const Nr=async(t,e)=>{const n=performance.now();try{await t()}finally{const r=performance.now()-n;let s=Un[e];s||(s=qn(e)),s.report(r/1e3)}},Br=(t,e)=>{const n=performance.now();try{t()}finally{const r=performance.now()-n;let s=Un[e];s||(s=qn(e)),s.report(r/1e3)}},fi=30,mi=3e4;let it=0;const $r=()=>{H.setItem("sprig.disableReplayRecording","disabled")},Ee=()=>!!H.getItem("sprig.disableReplayRecording"),yi=["did not allow mutations","called in an invalid security context"],gi=t=>{if(!t)return!0;for(const e of yi)if(t.toLowerCase().includes(e))return!1;return!0},vi=(t,e,{reportError:n=!0,extraInfo:r})=>{Ee()||e instanceof Error&&($r(),gi(e?.message)&&(n&&window.UserLeap.reportError(t,e,r),_i()))},bi=async(t,e,{reportError:n}={reportError:!0})=>{var r;let s;try{if(n&&(r=window.navigator.storage)!=null&&r.estimate){const{quota:i,usage:a}=await window.navigator.storage.estimate();s={availableSpaceInMB:i&&a?(i-a)/(1024*1024):void 0,quota:i,usage:a}}}catch(i){window.UserLeap.reportError("Error getting storage estimate",i,{originalMessage:t,originalError:e})}vi(t,e,{reportError:n,extraInfo:s})},wi=()=>{const t=H.getItem("sprig.sessionId");if(t)return P(`Found saved session id: ${t}`),H.removeItem("sprig.sessionId"),t;const e=Fe();return P(`Generating new uuid: ${e}`),e},q=wi();window.addEventListener("beforeunload",()=>{P(`Before page unload saving session id: ${q}`),H.setItem("sprig.sessionId",q)});const _i=async()=>{A.transaction("rw",A.events,A.chunkUploads,A.pendingCaptures,()=>{A.events.clear(),A.chunkUploads.clear(),A.pendingCaptures.clear()}).catch(()=>{})},Tn=(t,e,n=()=>!0)=>A.table(e).where("timestamp").below(t).and(n).delete(),ki=async(t,e)=>{let n=[];return await Nr(async()=>{n=await A.events.where("[sessionId+timestamp]").between([q,t],[q,e??Date.now()]).toArray()},"sdk_replay_get_events_between_seconds"),n},xi=(t,e,n)=>{const r=new Date,s=r.setMinutes(r.getMinutes()+(n??fi));return A.events.where("[sessionId+timestamp]").between([q,t],[q,e]).modify({expiredAt:s})},Ei=t=>A.chunkUploads.add({...t,sessionId:t.sessionId??q}),Si=(t,e)=>A.chunkUploads.update(t,{data:null,etag:e,status:"UploadComplete"}),Ii=({status:t,uploadId:e})=>e?A.chunkUploads.where({uploadId:e,status:t}).toArray():A.chunkUploads.where({sessionId:q,status:t}).toArray(),Pi=t=>A.chunkUploads.where({uploadId:t,status:"UploadComplete"}).toArray(),Ci=t=>A.chunkUploads.where({uploadId:t,status:"UploadComplete"}).delete(),Ai=t=>A.pendingCaptures.add({...t,sessionId:t.sessionId??q,canUpload:!1}),Mr=async t=>{let e=await A.pendingCaptures.where("sessionId").equals(q).toArray();return t.beforePresent&&(e=e.filter(n=>n.targetTimestamp<Date.now())),t.isHeatmap&&(e=e.filter(n=>n.captureParams.isHeatmap??!1)),e},Di=()=>A.pendingCaptures.where("sessionId").equals(q).toArray(),Ti=t=>A.pendingCaptures.where("sessionId").equals(q).and(e=>e.captureParams.responseGroupId===t).modify({canUpload:!0}),Oi=async t=>{var e;if((e=window.navigator.storage)!=null&&e.estimate){const{quota:n,usage:r}=await window.navigator.storage.estimate();if(n&&r&&(n-r)/1073741824<t)return!1}return!0},Fr=async t=>{if(parseInt(H.getItem("sprig.pendingCount")??"0")===0)return;const e=Date.now();return oe(async()=>{await A.pendingCaptures.where("sessionId").equals(q).and(n=>n.captureParams.isHeatmap??!1).and(n=>t?t.includes(n.uuid):!0).modify(n=>{n.targetTimestamp=e,n.captureParams.triggerTimestamp=e,n.captureParams.replayParams.replayDurationSeconds=Math.floor((e-n.timestamp)/1e3)})},"Error marking pending heatmaps ready")},Ki=async()=>{const t=(await Mr({isHeatmap:!0})).map(n=>({eventId:n.captureParams.eventId,uuid:n.uuid})),e=[];t.forEach(({eventId:n,uuid:r})=>{gs(n)||e.push(r)}),e.length&&Fr(e)},Ri=t=>{if(t>1){it=0;return}const e=Date.now();if(!it){it=e;return}e-it>=mi&&(Fr(),it=0)};class ji extends Se{constructor(){super("replayStorage",{autoOpen:!1}),Me(this,"events"),Me(this,"chunkUploads"),Me(this,"pendingCaptures")}}const A=new ji;A.version(1).stores({events:"uuid, timestamp, [sessionId+timestamp]",chunkUploads:"uuid, timestamp, [sessionId+status], [uploadId+status], [sessionId+status+uploadId]",pendingCaptures:"uuid, timestamp, [sessionId+targetTimestamp]"}),A.open().catch(t=>{Ln(`Error opening replay storage: ${JSON.stringify(t)}`),$r()});const Ni=t=>{if(t instanceof Attr)return null;let e=1;for(let n=t.previousSibling;n;n=n.previousSibling)n.nodeName===t.nodeName&&++e;return e},Ur=t=>{if(t===null)return"";const e=[];if(t instanceof Document)return"/";for(let n=t;n&&!(n instanceof Document)&&n!==null;n=n instanceof Attr?n.ownerElement:n.parentElement){const r=e[e.length]={name:void 0,position:null};switch(n.nodeType){case Node.TEXT_NODE:r.name="text()";break;case Node.ATTRIBUTE_NODE:r.name="@"+n.nodeName;break;case Node.PROCESSING_INSTRUCTION_NODE:r.name="processing-instruction()";break;case Node.COMMENT_NODE:r.name="comment()";break;case Node.ELEMENT_NODE:r.name=n.nodeName;break}r.position=Ni(n)}return"/"+e.reverse().map(n=>n.position!==null?`/${n.name}[${n.position}]`:`/${n.name}`).join("")},fe={capture:!0,passive:!0},Bi=["a","button","input","option","li","link"],$i=["Escape","Enter","Backspace","F5","Tab"];let Kt=!1;const Mi=["label","type","role","title","placeholder","errormessage","valuetext","href"],qr="aria-",Fi=t=>{if(!t.tagName)return"No tagName";const e=t.getAttribute("type");return e?`${e} ${t.tagName.toLowerCase()}`:t.tagName.toLowerCase()},Lr=t=>{var e;if(((e=t.tagName)==null?void 0:e.toLowerCase())==="html")return{element:"html"};const n=t.textContent,r=n?{text:n}:{};r.element=Fi(t);for(const s of t.attributes){let i=s.name;const a=s.value;i.startsWith(qr)&&(i=i.substring(qr.length)),Mi.includes(i)&&(r[i]=a)}return r},Ui=t=>{var e;if(!t)return{};const n={...Lr(t)},r=t.parentElement;if(r&&Bi.includes((e=r.tagName)==null?void 0:e.toLowerCase())){const s=Lr(r);Object.assign(n,s)}return n},Hr=(t,e)=>{var n;cs({x:e.x,y:e.y,type:t,elementAttributes:Ui(e.target),windowHeight:window.innerHeight,windowWidth:window.innerWidth,...e.target instanceof HTMLElement?{rect:(n=e.target)==null?void 0:n.getBoundingClientRect(),xPath:Ur(e.target)}:{}})},qi=t=>e=>Hr(t,e),Wr=t=>{$i.includes(t.key)&&ps({key:t.key})},Li=()=>{window.performance.getEntriesByType("navigation").map(t=>t.type).includes("reload")&&ds({url:window.location.href,currentPageTitle:document.title})},Hi=()=>{window.performance.getEntriesByType("navigation").map(t=>t.type).includes("back_forward")&&hs({curUrl:window.location.href,fromUrl:document.referrer,currentPageTitle:document.title})},Wi=(t,e)=>{let n;return r=>{clearTimeout(n),n=window.setTimeout(()=>t(r),e)}},Vi=t=>{if(!(t.target instanceof HTMLElement||t.target instanceof Document))return;let e=t.target;"scrollTop"in e||(e=e.documentElement),fs({xPath:Ur(e),x:e.scrollLeft,y:e.scrollTop,elementAttributes:{targetScrollWidth:e.scrollWidth,targetClientWidth:e.clientWidth,targetScrollHeight:e.scrollHeight,targetClientHeight:e.clientHeight}})},Vr=Wi(Vi,750),Gr=qi("left_click"),zr=t=>{t.button===2&&Hr("right_click",t)},Gi=()=>{Kt||(window.addEventListener("click",Gr,fe),window.addEventListener("mousedown",zr,fe),window.addEventListener("keydown",Wr,fe),window.addEventListener("scroll",Vr,fe),Kt=!0,Li(),Hi())},zi=()=>{Kt&&(window.removeEventListener("click",Gr,fe),window.removeEventListener("mousedown",zr,fe),window.removeEventListener("keydown",Wr,fe),window.removeEventListener("scroll",Vr,fe),Kt=!1)},Yi=async(t,e,n)=>new Promise((r,s)=>{const i=t.createElement("script");i.src=e,i.onload=r,i.onerror=s,n&&(i.nonce=n),t.head.appendChild(i)});let Yr=1,On=5e3,Rt=6e4;const Ji=5,Jr=1e3,Qr=30,jt=Qr+Ji;let Kn,Rn,Xr,Zr=Date.now(),at=!1,Nt;const es={},Qi=async({viewDocument:t,maxReplayDurationSeconds:e,replayNonce:n,maxInflightRequests:r=2,replaySettings:s,teardownAfter:i=!1})=>{at||(i&&H.setItem("sprig.teardownAfterCapture","true"),await oe(async()=>{if(Ee()){P("Not initializing replay because recording is disabled");return}if(!e){P("Not initializing replay because config didn't specify maxReplayDurationSeconds");return}if(s!=null&&s.minAvailableGb&&(Yr=s.minAvailableGb),!await Oi(Yr)){Hn("Minimum storage not available");return}if(P("Initializing replay"),s!=null&&s.minDuration&&(On=s.minDuration),s!=null&&s.batchDuration&&(Rt=s.batchDuration),_s(r),sa(),ea(e+jt,30*60,e+jt),ta(),!window.rrwebRecord){P("Loading recording script");const u=window.UserLeap.replayLibraryURL??"https://cdn.sprig.com/dependencies/record-2.0.0-alpha.6.min.js";await Yi(t,u,n),P("Recording script finished loading")}const a=window.rrwebRecord;if(!a){Hn("Record script failed to set global function");return}let o=!0,l=0;Nt=a({checkoutEveryNms:Qr*1e3,sampling:{input:"last",scroll:250,media:800},emit:(u,d)=>{if(Ee())return;if(Zr=Date.now(),d&&u.type===Mt.Meta)l=performance.now();else if(d&&l&&u.type===Mt.FullSnapshot){const h=performance.now()-l;vs("sdk_replay_snapshot_seconds",h/1e3)}const c=o||!!d;o=!1,Xi({uuid:Fe(),event:JSON.stringify(u),isValidStart:c,timestamp:Date.now()})},...s}),at=!0,Rn||(Rn=window.setInterval(()=>{Date.now()-Zr>Jr&&Q("Sprig_Noop",{})},Jr)),lt.on("survey.complete",u=>{us({id:u,userAgent:window.navigator.userAgent})}),Gi()},"Error initializing replay"))};let me=H.getItem("sprig.pendingCount"),jn=!!H.getItem("sprig.isCapturingHeatmap"),Nn=!1,Bn=[];const Xi=t=>{var e,n,r,s;if((e=t.event)!=null&&e.includes("Sprig_Scroll")){const i=(s=(r=(n=JSON.parse(t.event))==null?void 0:n.data)==null?void 0:r.payload)==null?void 0:s.xPath;if(!i)return;const a=Fe();es[i]=a,t.uuid=a}Bn.push(t),Nn||Zi()},ts=t=>{const e=t.map(n=>({...n,sessionId:n.sessionId??q}));if(jn&&Ri(e.length),e.length!==0)return A.transaction("rw",A.events,()=>{A.events.bulkAdd(e)}).catch(n=>{Be("Error storing replay events",n)})},Zi=()=>{Nn=!0,setTimeout(async()=>{if(Ee())return;const t=Bn;Bn=[],Nn=!1,Br(async()=>{await ts(t)},"sdk_replay_add_event_batch_seconds")},500)},ea=(t=6*60,e=30*60,n=4*60)=>{Kn=window.setInterval(()=>{const r=Date.now();Ee()||(ot(`Performing periodic replay data cleanup / Event Seconds ${t} / Chunk Seconds ${e} / Pending Capture Seconds ${n}`),Nr(()=>A.transaction("rw!",A.events,A.chunkUploads,A.pendingCaptures,()=>{Tn(r-t*1e3,"events",s=>s.expiredAt===void 0||s.expiredAt<r-t*1e3),Tn(r-e*1e3,"chunkUploads"),Tn(r-n*1e3,"pendingCaptures",s=>s.canUpload===void 0||s.canUpload===!1)}).catch(s=>{clearInterval(Kn),Be("Error deleting table rows",s)}),"sdk_replay_cleanup_seconds"),P("Cleanup complete"))},30*1e3)},ta=(t=5)=>{Xr=window.setInterval(async()=>{oe(async()=>{const e=parseInt(me??"0");if(e===0)return;const n=await Mr({beforePresent:!0});n!=null&&n.length&&(await Promise.all(n.map(async r=>(await A.pendingCaptures.delete(r.uuid),as(r.captureParams,r.canUpload)))),me=(e-n.length).toString(),H.setItem("sprig.pendingCount",me))},"Error initiating pending captures")},t*1e3)},na=async(t,e,n,r,s)=>{const i=Math.min(t+s,n),a=`from: ${new Date(t).toLocaleTimeString()} to ${new Date(i).toLocaleTimeString()}`;P(`Getting event batch ${a}`);const o=await ki(t,i);if(!(o!=null&&o.length))return P(`No events found ${a}`),{validStartFound:r,events:[]};if(!r){P(`Searching for valid start in ${o.length} events ${a}`);let l=-1;if(o?.forEach((d,c)=>{if(!d.isValidStart)return;const h=d.timestamp<=e;(l<0||h)&&(l=c)}),l<0)return P(`No valid start found in ${o.length} events ${a}`),{validStartFound:r,events:[]};const u=o[l].timestamp;return P(`Found valid start at: ${new Date(u).toLocaleTimeString()} in events ${a}`),{validStartFound:!0,events:o?.slice(l)}}return{validStartFound:r,events:o}},ra=(t,e,n)=>{const r=t.length,s=e*1024*1024,i=Math.ceil(r/n),a=Math.max(s,i);P(`Total file bytes: ${r} / target chunk size: ${a}`);const o=[];let l=0;for(;l<r;)o.push(t.slice(l,l+a)),l+=a;return o},ns=t=>Promise.all(t.map(async e=>{const n=await ks(e);return await Si(e.uuid,n),e.uploadId})),rs=async t=>{P(`Marking upload complete if finished: ${t}`);const e=await Pi(t);if(!(e!=null&&e.length)){P(`No finished chunks found for upload: ${t}`);return}const n=e.reduce((i,a)=>(i.find(o=>o.chunkIndex===a.chunkIndex)||i.push(a),i),[]);n.sort((i,a)=>i.chunkIndex-a.chunkIndex);const r=n.map(i=>({ETag:i.etag,PartNumber:i.chunkIndex})).filter(i=>i.ETag!==null),s=n[0];await Vn({apiUrl:s.apiUrl,surveyId:s.surveyId,uploadId:t,responseGroupUuid:s.responseGroupId,etags:r,headers:s.completeUploadHeaders,replayDuration:s.replayDuration}),P(`Cleaning up chunks for ${t}`),await Ci(t),P(`Done cleaning up chunks for ${t}`)},sa=async()=>{oe(async()=>{const t=await Ii({status:"ReadyForUpload"});if(!(t!=null&&t.length))return;const e=await ns(t);P(`Finished uploading unfinished chunks for ${e}`),e!=null&&e.length&&await Promise.all(e.map(n=>{if(n)return rs(n)}))},"Error uploading unfinished chunks")},ia=async(t,e)=>{await ns(e),P(`Done uploading chunks for uploads: ${t.join(",")}`),await Promise.all(t.map(n=>rs(n)))},aa=t=>{let e=0;t.forEach(s=>{e+=s.length});const n=new Uint8Array(e);let r=0;return t.forEach(s=>{n.set(s,r),r+=s.length}),n},ss=async(t,e,n)=>{const r=new TextEncoder;let s=null,i=null,a=null,o=!1,l=!1,[u,d]=[0,0];const c=t-jt*1e3,h=[];let p=[];P(`Getting events between ${new Date(t).toLocaleTimeString()} and ${new Date(e).toLocaleTimeString()}`),P(`Using batch duration: ${Rt}ms`);for(let m=c;m<e;m+=Rt){if({validStartFound:l,events:p}=await na(m,t,e,l,Rt),!(p!=null&&p.length)){P("No events found");continue}u===0&&(u=p[0].timestamp),d=p[p.length-1].timestamp,P(`Last event time in batch: ${new Date(d).toLocaleTimeString()}`);const v=`${o?",":"["}${p.map(f=>f.event).join(",")}`,g=r.encode(v);n&&i===null&&(ot("Attempting compression"),a=new window.CompressionStream("gzip"),i=a.writable.getWriter()),Br(()=>{n&&i?i.write(g):h.push(g)},"sdk_replay_compression_seconds"),o=!0}if(d-u<On)return P(`Replay duration is shorter than minimum of ${On}ms / Start:${u} / End:${d}`),null;const y=r.encode("]");return ot("Writing final close brace"),i&&a?(i.write(y),i.close(),s=new Uint8Array(await new Response(a.readable).arrayBuffer())):(h.push(y),s=aa(h)),P("Finished generating file data"),s},oa=async(t,e)=>{const n=window.CompressionStream!==void 0;let r=null;const s=e??Date.now(),i=s-t;try{r=await ss(i,s,n)}catch(a){a instanceof Error&&window.UserLeap.reportError("Error compressing replay",a),n&&oe(async()=>{await ss(i,s,!1)},"fileData fallback failed")}return r},is=async t=>{const{surveyId:e,responseGroupId:n,visitorId:r,apiUrl:s,completeUploadHeaders:i,replayParams:a,triggerTimestamp:o}=t,l=await oa(a.replayDurationSeconds*1e3,o);if(l!=null&&l.length)P(`Found file data for survey: ${e}`);else{P(`File data is empty for survey: ${e}`);return}const u=ra(l,a.minimumChunkSizeMb,a.signedUrls.length);P(`Got ${u.length} chunks for survey: ${e}`);const d=await Promise.all(u.map(async(c,h)=>{const p=Fe(),y={apiUrl:s,chunkIndex:h+1,completeUploadHeaders:i,etag:null,responseGroupId:n,status:"ReadyForUpload",surveyId:e,timestamp:o,totalChunks:u.length,data:c,uploadId:a.uploadId,uploadUrl:a.signedUrls[h].url,uuid:p,visitorId:r};return P(`Recording chunk upload: ${JSON.stringify({index:y.chunkIndex,surveyId:y.surveyId,uploadId:y.uploadId,size:c.length,id:p},null,2)}`),await Ei(y),P(`Done creating chunk upload: ${p}`),y}));P(`All chunk records created. Beginning upload for survey: ${e}`),await ia([a.uploadId],d)},as=async(t,e)=>{if(P(`Attempting replay capture: ${JSON.stringify({isStandalone:t.isStandalone,duration:t.replayParams.replayDurationSeconds,type:t.replayParams.replayDurationType,responseGroupId:t.responseGroupId,surveyId:t.surveyId,triggerTimestamp:t.triggerTimestamp,visitorId:t.visitorId},null,2)}`),Ee()){P(`Replay recording is disabled: ${t.surveyId}`);return}P(`Replay recording enabled: ${t.surveyId}`);const{isHeatmap:n,isStandalone:r,replayParams:s,triggerTimestamp:i,responseGroupId:a}=t,o=async()=>{setTimeout(()=>lt.removeListener($t.QuestionAnswered,o),0),oe(async()=>{s.replayDurationType==="before"?await is(t):await Ti(a)},"Error in schedule/capture callback")};oe(async()=>{if(s.replayDurationType==="after"||s.replayDurationType==="beforeAndAfter"){!r&&!n&&(P("Attaching QuestionAnswered listener for non-standalone replay"),lt.on($t.QuestionAnswered,o)),P(`Scheduling capture for replay of type: ${s.replayDurationType}`),await ls(t);return}if(r||n||e)P(`Proceeding to capture replay for survey: ${t.surveyId} / standalone? ${r} / canUpload? ${e}`),await is(t),n&&la();else{const l=jt+s.replayDurationSeconds,u=i-l*1e3,d=i;P(`Setting expiry minutes to ${s.expirationTimeLimitMinutes} for events from ${new Date(u).toLocaleTimeString()} to ${new Date(d).toLocaleTimeString()}`),await xi(u,d,s.expirationTimeLimitMinutes),P("Attaching QuestionAnswered listener"),lt.on($t.QuestionAnswered,o)}},"Error in scheduling/capturing replay")},la=async()=>{parseInt(me??"0")||(H.removeItem("sprig.isCapturingHeatmap"),jn=!1),H.getItem("sprig.teardownAfterCapture")&&($n(),os(),H.removeItem("sprig.teardownAfterCapture"))},os=()=>{if(Ee()){ot("Not clearing user data, replay is disabled");return}return A.transaction("rw",A.events,A.pendingCaptures,()=>{A.events.where("sessionId").equals(q).delete(),A.pendingCaptures.where("sessionId").equals(q).delete()}).catch(t=>{Be("Error clearing session event data",t)})},ls=async t=>{P(`Scheduling replay capture: ${JSON.stringify(t)}`);const{isHeatmap:e,surveyId:n}=t,r=await Di(),s=r?.filter(o=>o.captureParams.surveyId===n);if(s!=null&&s.length){P(`Pending capture exists for survey: ${n}`);return}e&&(jn=!0,H.setItem("sprig.isCapturingHeatmap","true"));const i={...t,replayParams:{...t.replayParams}};t.replayParams.replayDurationType==="beforeAndAfter"&&(i.replayParams.replayDurationSeconds*=2),i.replayParams.replayDurationType="before";const a=t.triggerTimestamp+t.replayParams.replayDurationSeconds*1e3;return i.triggerTimestamp=a,me=me?(parseInt(me)+1).toString():"1",H.setItem("sprig.pendingCount",me),Ai({uuid:Fe(),targetTimestamp:a,timestamp:Date.now(),captureParams:i})},Q=(t,e)=>{var n,r;if(at)try{(r=(n=window.rrwebRecord)==null?void 0:n.addCustomEvent)==null||r.call(n,t,e)}catch(s){Be("Error recording custom event",s)}},oe=async(t,e)=>{try{await t()}catch(n){Be(e,n)}},ua=t=>{t.description&&(t.description=Mn(t.description)),Q("Sprig_PageView",t)},ca=t=>{Q("Sprig_TrackEvent",t)},da=t=>{Q("Sprig_ShowSurvey",t)},us=t=>{Q("Sprig_SubmitSurvey",t)},cs=t=>{var e;(e=t?.elementAttributes)!=null&&e.text&&(t.elementAttributes.text=Mn(t.elementAttributes.text)),Q("Sprig_Click",t)},ds=t=>{Q("Sprig_Refresh",t)},hs=t=>{t.currentPageTitle&&(t.currentPageTitle=Mn(t.currentPageTitle)),Q("Sprig_BackForward",t)},ps=t=>{Q("Sprig_Keystroke",t)},fs=async t=>{const{x:e,xPath:n,y:r}=t,s=es[n];s?oe(async()=>{var i,a,o,l;const u=await A.events.get(s);if(u!=null&&u.event){const d=JSON.parse(u.event),c=e>((a=(i=d.data)==null?void 0:i.payload)==null?void 0:a.x)||0,h=r>((l=(o=d.data)==null?void 0:o.payload)==null?void 0:l.y)||0;if(!(c||h))return;c&&(d.data.payload.x=e),h&&(d.data.payload.y=r),d.data.payload.elementAttributes=t.elementAttributes,u.event=JSON.stringify(d),A.events.put(u)}else Q("Sprig_Scroll",t)},"Error updating scroll event"):Q("Sprig_Scroll",t)},$n=()=>{Nt&&(Nt(),Nt=void 0),at=!1,[Kn,Rn,Xr].forEach(t=>{t&&clearInterval(t)}),zi()},Be=(t,e,{reportError:n}={reportError:!0})=>($n(),Ln(`${t} - ${JSON.stringify(e)}`),bi(t,e,{reportError:n})),ha=()=>at,Mn=t=>t&&t.trim().substring(0,500).replace(/\s\s+/g," ").replace(/\r?\n|\r/g," ").substring(0,250),pa=async({surveyId:t,responseGroupUuid:e,eventDigest:n,headers:r})=>{if(!t||!e)return!1;const s=window.UserLeap._API_URL;try{const i=await Vn({surveyId:t,responseGroupUuid:e,eventDigest:n,apiUrl:s,headers:r},!0);return!(i!=null&&i.error)}catch(i){return console.warn("[Sprig] Error with completing session replay"),i instanceof Error&&window.UserLeap.reportError("completeSessionReplay",i),!1}},fa=Object.freeze(Object.defineProperty({__proto__:null,RecordBackForward:hs,RecordClick:cs,RecordEvent:ca,RecordKeystroke:ps,RecordPageView:ua,RecordRefresh:ds,RecordScroll:fs,RecordSurveyComplete:us,RecordSurveyShown:da,_completeSessionReplay:pa,batchStoreEvents:ts,checkPendingHeatmapsUrl:Ki,clearUserReplayData:os,disableRecording:Be,initializeReplay:Qi,isReplayRecording:ha,scheduleCapture:ls,scheduleOrCaptureReplay:as,teardownReplay:$n,tryReplayAction:oe},Symbol.toStringTag,{value:"Module"}));bs(fa);
|
|
4
|
+
`+r).join("")):""}var nr=["Unknown","Constraint","Data","TransactionInactive","ReadOnly","Version","NotFound","InvalidState","InvalidAccess","Abort","Timeout","QuotaExceeded","Syntax","DataClone"],Vt=["Modify","Bulk","OpenFailed","VersionChange","Schema","Upgrade","InvalidTable","MissingAPI","NoSuchDatabase","InvalidArgument","SubTransaction","Unsupported","Internal","DatabaseClosed","PrematureCommit","ForeignAwait"].concat(nr),Ts={VersionChanged:"Database version changed by other database connection",DatabaseClosed:"Database has been closed",Abort:"Transaction aborted",TransactionInactive:"Transaction has already completed or failed",MissingAPI:"IndexedDB API missing. Please visit https://tinyurl.com/y2uuvskb"};function Oe(t,e){this._e=ge(),this.name=t,this.message=e}function rr(t,e){return t+". Errors: "+Object.keys(e).map(n=>e[n].toString()).filter((n,r,s)=>s.indexOf(n)===r).join(`
|
|
5
|
+
`)}function dt(t,e,n,r){this._e=ge(),this.failures=e,this.failedKeys=r,this.successCount=n,this.message=rr(t,e)}function We(t,e){this._e=ge(),this.name="BulkError",this.failures=Object.keys(e).map(n=>e[n]),this.failuresByPos=e,this.message=rr(t,e)}De(Oe).from(Error).extend({stack:{get:function(){return this._stack||(this._stack=this.name+": "+this.message+Wt(this._e,2))}},toString:function(){return this.name+": "+this.message}}),De(dt).from(Oe),De(We).from(Oe);var Gt=Vt.reduce((t,e)=>(t[e]=e+"Error",t),{});const Os=Oe;var C=Vt.reduce((t,e)=>{var n=e+"Error";function r(s,a){this._e=ge(),this.name=n,s?typeof s=="string"?(this.message=`${s}${a?`
|
|
6
|
+
`+a:""}`,this.inner=a||null):typeof s=="object"&&(this.message=`${s.name} ${s.message}`,this.inner=s):(this.message=Ts[e]||n,this.inner=null)}return De(r).from(Os),t[e]=r,t},{});C.Syntax=SyntaxError,C.Type=TypeError,C.Range=RangeError;var sr=nr.reduce((t,e)=>(t[e+"Error"]=C[e],t),{}),ht=Vt.reduce((t,e)=>(["Syntax","Type","Range"].indexOf(e)===-1&&(t[e+"Error"]=C[e]),t),{});function O(){}function Ve(t){return t}function Ks(t,e){return t==null||t===Ve?e:function(n){return e(t(n))}}function ve(t,e){return function(){t.apply(this,arguments),e.apply(this,arguments)}}function Rs(t,e){return t===O?e:function(){var n=t.apply(this,arguments);n!==void 0&&(arguments[0]=n);var r=this.onsuccess,s=this.onerror;this.onsuccess=null,this.onerror=null;var a=e.apply(this,arguments);return r&&(this.onsuccess=this.onsuccess?ve(r,this.onsuccess):r),s&&(this.onerror=this.onerror?ve(s,this.onerror):s),a!==void 0?a:n}}function js(t,e){return t===O?e:function(){t.apply(this,arguments);var n=this.onsuccess,r=this.onerror;this.onsuccess=this.onerror=null,e.apply(this,arguments),n&&(this.onsuccess=this.onsuccess?ve(n,this.onsuccess):n),r&&(this.onerror=this.onerror?ve(r,this.onerror):r)}}function Ns(t,e){return t===O?e:function(n){var r=t.apply(this,arguments);W(n,r);var s=this.onsuccess,a=this.onerror;this.onsuccess=null,this.onerror=null;var i=e.apply(this,arguments);return s&&(this.onsuccess=this.onsuccess?ve(s,this.onsuccess):s),a&&(this.onerror=this.onerror?ve(a,this.onerror):a),r===void 0?i===void 0?void 0:i:W(r,i)}}function Bs(t,e){return t===O?e:function(){return e.apply(this,arguments)!==!1&&t.apply(this,arguments)}}function zt(t,e){return t===O?e:function(){var n=t.apply(this,arguments);if(n&&typeof n.then=="function"){for(var r=this,s=arguments.length,a=new Array(s);s--;)a[s]=arguments[s];return n.then(function(){return e.apply(r,a)})}return e.apply(this,arguments)}}ht.ModifyError=dt,ht.DexieError=Oe,ht.BulkError=We;var Ge={};const ar=100,[Yt,pt,Jt]=typeof Promise>"u"?[]:(()=>{let t=Promise.resolve();if(typeof crypto>"u"||!crypto.subtle)return[t,qe(t),t];const e=crypto.subtle.digest("SHA-512",new Uint8Array([0]));return[e,qe(e),t]})(),ir=pt&&pt.then,ft=Yt&&Yt.constructor,Qt=!!Jt;var Xt=!1,$s=Jt?()=>{Jt.then(vt)}:K.setImmediate?setImmediate.bind(null,vt):K.MutationObserver?()=>{var t=document.createElement("div");new MutationObserver(()=>{vt(),t=null}).observe(t,{attributes:!0}),t.setAttribute("i","1")}:()=>{setTimeout(vt,0)},ze=function(t,e){Ye.push([t,e]),mt&&($s(),mt=!1)},Zt=!0,mt=!0,be=[],yt=[],en=null,tn=Ve,Ke={id:"global",global:!0,ref:0,unhandleds:[],onunhandled:yr,pgp:!1,env:{},finalize:function(){this.unhandleds.forEach(t=>{try{yr(t[0],t[1])}catch{}})}},I=Ke,Ye=[],we=0,gt=[];function E(t){if(typeof this!="object")throw new TypeError("Promises must be constructed via new");this._listeners=[],this.onuncatched=O,this._lib=!1;var e=this._PSD=I;if(X&&(this._stackHolder=ge(),this._prev=null,this._numPrev=0),typeof t!="function"){if(t!==Ge)throw new TypeError("Not a function");return this._state=arguments[1],this._value=arguments[2],void(this._state===!1&&rn(this,this._value))}this._state=null,this._value=null,++e.ref,lr(this,t)}const nn={get:function(){var t=I,e=_t;function n(r,s){var a=!t.global&&(t!==I||e!==_t);const i=a&&!re();var o=new E((l,u)=>{sn(this,new or(xt(r,t,a,i),xt(s,t,a,i),l,u,t))});return X&&dr(o,this),o}return n.prototype=Ge,n},set:function(t){ee(this,"then",t&&t.prototype===Ge?nn:{get:function(){return t},set:nn.set})}};function or(t,e,n,r,s){this.onFulfilled=typeof t=="function"?t:null,this.onRejected=typeof e=="function"?e:null,this.resolve=n,this.reject=r,this.psd=s}function lr(t,e){try{e(n=>{if(t._state===null){if(n===t)throw new TypeError("A promise cannot be resolved with itself.");var r=t._lib&&Je();n&&typeof n.then=="function"?lr(t,(s,a)=>{n instanceof E?n._then(s,a):n.then(s,a)}):(t._state=!0,t._value=n,ur(t)),r&&Qe()}},rn.bind(null,t))}catch(n){rn(t,n)}}function rn(t,e){if(yt.push(e),t._state===null){var n=t._lib&&Je();e=tn(e),t._state=!1,t._value=e,X&&e!==null&&typeof e=="object"&&!e._promise&&function(r,s,a){try{r.apply(null,a)}catch{}}(()=>{var r=Ft(e,"stack");e._promise=t,ee(e,"stack",{get:()=>Xt?r&&(r.get?r.get.apply(e):r.value):t.stack})}),function(r){be.some(s=>s._value===r._value)||be.push(r)}(t),ur(t),n&&Qe()}}function ur(t){var e=t._listeners;t._listeners=[];for(var n=0,r=e.length;n<r;++n)sn(t,e[n]);var s=t._PSD;--s.ref||s.finalize(),we===0&&(++we,ze(()=>{--we==0&&an()},[]))}function sn(t,e){if(t._state!==null){var n=t._state?e.onFulfilled:e.onRejected;if(n===null)return(t._state?e.resolve:e.reject)(t._value);++e.psd.ref,++we,ze(Ms,[n,t,e])}else t._listeners.push(e)}function Ms(t,e,n){try{en=e;var r,s=e._value;e._state?r=t(s):(yt.length&&(yt=[]),r=t(s),yt.indexOf(s)===-1&&function(a){for(var i=be.length;i;)if(be[--i]._value===a._value)return void be.splice(i,1)}(e)),n.resolve(r)}catch(a){n.reject(a)}finally{en=null,--we==0&&an(),--n.psd.ref||n.psd.finalize()}}function cr(t,e,n){if(e.length===n)return e;var r="";if(t._state===!1){var s,a,i=t._value;i!=null?(s=i.name||"Error",a=i.message||i,r=Wt(i,0)):(s=i,a=""),e.push(s+(a?": "+a:"")+r)}return X&&((r=Wt(t._stackHolder,2))&&e.indexOf(r)===-1&&e.push(r),t._prev&&cr(t._prev,e,n)),e}function dr(t,e){var n=e?e._numPrev+1:0;n<100&&(t._prev=e,t._numPrev=n)}function vt(){Je()&&Qe()}function Je(){var t=Zt;return Zt=!1,mt=!1,t}function Qe(){var t,e,n;do for(;Ye.length>0;)for(t=Ye,Ye=[],n=t.length,e=0;e<n;++e){var r=t[e];r[0].apply(null,r[1])}while(Ye.length>0);Zt=!0,mt=!0}function an(){var t=be;be=[],t.forEach(r=>{r._PSD.onunhandled.call(null,r._value,r)});for(var e=gt.slice(0),n=e.length;n;)e[--n]()}function bt(t){return new E(Ge,!1,t)}function R(t,e){var n=I;return function(){var r=Je(),s=I;try{return ce(n,!0),t.apply(this,arguments)}catch(a){e&&e(a)}finally{ce(s,!1),r&&Qe()}}}Ae(E.prototype,{then:nn,_then:function(t,e){sn(this,new or(null,null,t,e,I))},catch:function(t){if(arguments.length===1)return this.then(null,t);var e=arguments[0],n=arguments[1];return typeof e=="function"?this.then(null,r=>r instanceof e?n(r):bt(r)):this.then(null,r=>r&&r.name===e?n(r):bt(r))},finally:function(t){return this.then(e=>(t(),e),e=>(t(),bt(e)))},stack:{get:function(){if(this._stack)return this._stack;try{Xt=!0;var t=cr(this,[],20).join(`
|
|
7
|
+
From previous: `);return this._state!==null&&(this._stack=t),t}finally{Xt=!1}}},timeout:function(t,e){return t<1/0?new E((n,r)=>{var s=setTimeout(()=>r(new C.Timeout(e)),t);this.then(n,r).finally(clearTimeout.bind(null,s))}):this}}),typeof Symbol<"u"&&Symbol.toStringTag&&ee(E.prototype,Symbol.toStringTag,"Dexie.Promise"),Ke.env=hr(),Ae(E,{all:function(){var t=ne.apply(null,arguments).map(kt);return new E(function(e,n){t.length===0&&e([]);var r=t.length;t.forEach((s,a)=>E.resolve(s).then(i=>{t[a]=i,--r||e(t)},n))})},resolve:t=>{if(t instanceof E)return t;if(t&&typeof t.then=="function")return new E((n,r)=>{t.then(n,r)});var e=new E(Ge,!0,t);return dr(e,en),e},reject:bt,race:function(){var t=ne.apply(null,arguments).map(kt);return new E((e,n)=>{t.map(r=>E.resolve(r).then(e,n))})},PSD:{get:()=>I,set:t=>I=t},totalEchoes:{get:()=>_t},newPSD:ue,usePSD:je,scheduler:{get:()=>ze,set:t=>{ze=t}},rejectionMapper:{get:()=>tn,set:t=>{tn=t}},follow:(t,e)=>new E((n,r)=>ue((s,a)=>{var i=I;i.unhandleds=[],i.onunhandled=a,i.finalize=ve(function(){(function(o){function l(){o(),gt.splice(gt.indexOf(l),1)}gt.push(l),++we,ze(()=>{--we==0&&an()},[])})(()=>{this.unhandleds.length===0?s():a(this.unhandleds[0])})},i.finalize),t()},e,n,r))}),ft&&(ft.allSettled&&ee(E,"allSettled",function(){const t=ne.apply(null,arguments).map(kt);return new E(e=>{t.length===0&&e([]);let n=t.length;const r=new Array(n);t.forEach((s,a)=>E.resolve(s).then(i=>r[a]={status:"fulfilled",value:i},i=>r[a]={status:"rejected",reason:i}).then(()=>--n||e(r)))})}),ft.any&&typeof AggregateError<"u"&&ee(E,"any",function(){const t=ne.apply(null,arguments).map(kt);return new E((e,n)=>{t.length===0&&n(new AggregateError([]));let r=t.length;const s=new Array(r);t.forEach((a,i)=>E.resolve(a).then(o=>e(o),o=>{s[i]=o,--r||n(new AggregateError(s))}))})}));const U={awaits:0,echoes:0,id:0};var Fs=0,wt=[],on=0,_t=0,Us=0;function ue(t,e,n,r){var s=I,a=Object.create(s);a.parent=s,a.ref=0,a.global=!1,a.id=++Us;var i=Ke.env;a.env=Qt?{Promise:E,PromiseProp:{value:E,configurable:!0,writable:!0},all:E.all,race:E.race,allSettled:E.allSettled,any:E.any,resolve:E.resolve,reject:E.reject,nthen:fr(i.nthen,a),gthen:fr(i.gthen,a)}:{},e&&W(a,e),++s.ref,a.finalize=function(){--this.parent.ref||this.parent.finalize()};var o=je(a,t,n,r);return a.ref===0&&a.finalize(),o}function Re(){return U.id||(U.id=++Fs),++U.awaits,U.echoes+=ar,U.id}function re(){return!!U.awaits&&(--U.awaits==0&&(U.id=0),U.echoes=U.awaits*ar,!0)}function kt(t){return U.echoes&&t&&t.constructor===ft?(Re(),t.then(e=>(re(),e),e=>(re(),$(e)))):t}function qs(t){++_t,U.echoes&&--U.echoes!=0||(U.echoes=U.id=0),wt.push(I),ce(t,!0)}function Ls(){var t=wt[wt.length-1];wt.pop(),ce(t,!1)}function ce(t,e){var n=I;if((e?!U.echoes||on++&&t===I:!on||--on&&t===I)||pr(e?qs.bind(null,t):Ls),t!==I&&(I=t,n===Ke&&(Ke.env=hr()),Qt)){var r=Ke.env.Promise,s=t.env;pt.then=s.nthen,r.prototype.then=s.gthen,(n.global||t.global)&&(Object.defineProperty(K,"Promise",s.PromiseProp),r.all=s.all,r.race=s.race,r.resolve=s.resolve,r.reject=s.reject,s.allSettled&&(r.allSettled=s.allSettled),s.any&&(r.any=s.any))}}function hr(){var t=K.Promise;return Qt?{Promise:t,PromiseProp:Object.getOwnPropertyDescriptor(K,"Promise"),all:t.all,race:t.race,allSettled:t.allSettled,any:t.any,resolve:t.resolve,reject:t.reject,nthen:pt.then,gthen:t.prototype.then}:{}}function je(t,e,n,r,s){var a=I;try{return ce(t,!0),e(n,r,s)}finally{ce(a,!1)}}function pr(t){ir.call(Yt,t)}function xt(t,e,n,r){return typeof t!="function"?t:function(){var s=I;n&&Re(),ce(e,!0);try{return t.apply(this,arguments)}finally{ce(s,!1),r&&pr(re)}}}function fr(t,e){return function(n,r){return t.call(this,xt(n,e),xt(r,e))}}(""+ir).indexOf("[native code]")===-1&&(Re=re=O);const mr="unhandledrejection";function yr(t,e){var n;try{n=e.onuncatched(t)}catch{}if(n!==!1)try{var r,s={promise:e,reason:t};if(K.document&&document.createEvent?((r=document.createEvent("Event")).initEvent(mr,!0,!0),W(r,s)):K.CustomEvent&&W(r=new CustomEvent(mr,{detail:s}),s),r&&K.dispatchEvent&&(dispatchEvent(r),!K.PromiseRejectionEvent&&K.onunhandledrejection))try{K.onunhandledrejection(r)}catch{}X&&r&&!r.defaultPrevented&&console.warn(`Unhandled rejection: ${t.stack||t}`)}catch{}}var $=E.reject;function ln(t,e,n,r){if(t.idbdb&&(t._state.openComplete||I.letThrough||t._vip)){var s=t._createTransaction(e,n,t._dbSchema);try{s.create(),t._state.PR1398_maxLoop=3}catch(a){return a.name===Gt.InvalidState&&t.isOpen()&&--t._state.PR1398_maxLoop>0?(console.warn("Dexie: Need to reopen db"),t._close(),t.open().then(()=>ln(t,e,n,r))):$(a)}return s._promise(e,(a,i)=>ue(()=>(I.trans=s,r(a,i,s)))).then(a=>s._completion.then(()=>a))}if(t._state.openComplete)return $(new C.DatabaseClosed(t._state.dbOpenError));if(!t._state.isBeingOpened){if(!t._options.autoOpen)return $(new C.DatabaseClosed);t.open().catch(O)}return t._state.dbReadyPromise.then(()=>ln(t,e,n,r))}const gr="3.2.7",_e="\uFFFF",un=-1/0,se="Invalid key provided. Keys must be of type string, number, Date or Array<string | number | Date>.",vr="String expected.",Xe=[],Et=typeof navigator<"u"&&/(MSIE|Trident|Edge)/.test(navigator.userAgent),Hs=Et,Ws=Et,br=t=>!/(dexie\.js|dexie\.min\.js)/.test(t),St="__dbnames",cn="readonly",dn="readwrite";function ke(t,e){return t?e?function(){return t.apply(this,arguments)&&e.apply(this,arguments)}:t:e}const wr={type:3,lower:-1/0,lowerOpen:!1,upper:[[]],upperOpen:!1};function It(t){return typeof t!="string"||/\./.test(t)?e=>e:e=>(e[t]===void 0&&t in e&&delete(e=He(e))[t],e)}class Vs{_trans(e,n,r){const s=this._tx||I.trans,a=this.name;function i(l,u,d){if(!d.schema[a])throw new C.NotFound("Table "+a+" not part of transaction");return n(d.idbtrans,d)}const o=Je();try{return s&&s.db===this.db?s===I.trans?s._promise(e,i,r):ue(()=>s._promise(e,i,r),{trans:s,transless:I.transless||I}):ln(this.db,e,[this.name],i)}finally{o&&Qe()}}get(e,n){return e&&e.constructor===Object?this.where(e).first(n):this._trans("readonly",r=>this.core.get({trans:r,key:e}).then(s=>this.hook.reading.fire(s))).then(n)}where(e){if(typeof e=="string")return new this.db.WhereClause(this,e);if(F(e))return new this.db.WhereClause(this,`[${e.join("+")}]`);const n=B(e);if(n.length===1)return this.where(n[0]).equals(e[n[0]]);const r=this.schema.indexes.concat(this.schema.primKey).filter(u=>{if(u.compound&&n.every(d=>u.keyPath.indexOf(d)>=0)){for(let d=0;d<n.length;++d)if(n.indexOf(u.keyPath[d])===-1)return!1;return!0}return!1}).sort((u,d)=>u.keyPath.length-d.keyPath.length)[0];if(r&&this.db._maxKey!==_e){const u=r.keyPath.slice(0,n.length);return this.where(u).equals(u.map(d=>e[d]))}!r&&X&&console.warn(`The query ${JSON.stringify(e)} on ${this.name} would benefit of a compound index [${n.join("+")}]`);const{idxByName:s}=this.schema,a=this.db._deps.indexedDB;function i(u,d){try{return a.cmp(u,d)===0}catch{return!1}}const[o,l]=n.reduce(([u,d],c)=>{const h=s[c],p=e[c];return[u||h,u||!h?ke(d,h&&h.multi?y=>{const m=te(y,c);return F(m)&&m.some(v=>i(p,v))}:y=>i(p,te(y,c))):d]},[null,null]);return o?this.where(o.name).equals(e[o.keyPath]).filter(l):r?this.filter(l):this.where(n).equals("")}filter(e){return this.toCollection().and(e)}count(e){return this.toCollection().count(e)}offset(e){return this.toCollection().offset(e)}limit(e){return this.toCollection().limit(e)}each(e){return this.toCollection().each(e)}toArray(e){return this.toCollection().toArray(e)}toCollection(){return new this.db.Collection(new this.db.WhereClause(this))}orderBy(e){return new this.db.Collection(new this.db.WhereClause(this,F(e)?`[${e.join("+")}]`:e))}reverse(){return this.toCollection().reverse()}mapToClass(e){this.schema.mappedClass=e;const n=r=>{if(!r)return r;const s=Object.create(e.prototype);for(var a in r)if(z(r,a))try{s[a]=r[a]}catch{}return s};return this.schema.readHook&&this.hook.reading.unsubscribe(this.schema.readHook),this.schema.readHook=n,this.hook("reading",n),e}defineClass(){return this.mapToClass(function(e){W(this,e)})}add(e,n){const{auto:r,keyPath:s}=this.schema.primKey;let a=e;return s&&r&&(a=It(s)(e)),this._trans("readwrite",i=>this.core.mutate({trans:i,type:"add",keys:n!=null?[n]:null,values:[a]})).then(i=>i.numFailures?E.reject(i.failures[0]):i.lastResult).then(i=>{if(s)try{J(e,s,i)}catch{}return i})}update(e,n){if(typeof e!="object"||F(e))return this.where(":id").equals(e).modify(n);{const r=te(e,this.schema.primKey.keyPath);if(r===void 0)return $(new C.InvalidArgument("Given object does not contain its primary key"));try{typeof n!="function"?B(n).forEach(s=>{J(e,s,n[s])}):n(e,{value:e,primKey:r})}catch{}return this.where(":id").equals(r).modify(n)}}put(e,n){const{auto:r,keyPath:s}=this.schema.primKey;let a=e;return s&&r&&(a=It(s)(e)),this._trans("readwrite",i=>this.core.mutate({trans:i,type:"put",values:[a],keys:n!=null?[n]:null})).then(i=>i.numFailures?E.reject(i.failures[0]):i.lastResult).then(i=>{if(s)try{J(e,s,i)}catch{}return i})}delete(e){return this._trans("readwrite",n=>this.core.mutate({trans:n,type:"delete",keys:[e]})).then(n=>n.numFailures?E.reject(n.failures[0]):void 0)}clear(){return this._trans("readwrite",e=>this.core.mutate({trans:e,type:"deleteRange",range:wr})).then(e=>e.numFailures?E.reject(e.failures[0]):void 0)}bulkGet(e){return this._trans("readonly",n=>this.core.getMany({keys:e,trans:n}).then(r=>r.map(s=>this.hook.reading.fire(s))))}bulkAdd(e,n,r){const s=Array.isArray(n)?n:void 0,a=(r=r||(s?void 0:n))?r.allKeys:void 0;return this._trans("readwrite",i=>{const{auto:o,keyPath:l}=this.schema.primKey;if(l&&s)throw new C.InvalidArgument("bulkAdd(): keys argument invalid on tables with inbound keys");if(s&&s.length!==e.length)throw new C.InvalidArgument("Arguments objects and keys must have the same length");const u=e.length;let d=l&&o?e.map(It(l)):e;return this.core.mutate({trans:i,type:"add",keys:s,values:d,wantResults:a}).then(({numFailures:c,results:h,lastResult:p,failures:y})=>{if(c===0)return a?h:p;throw new We(`${this.name}.bulkAdd(): ${c} of ${u} operations failed`,y)})})}bulkPut(e,n,r){const s=Array.isArray(n)?n:void 0,a=(r=r||(s?void 0:n))?r.allKeys:void 0;return this._trans("readwrite",i=>{const{auto:o,keyPath:l}=this.schema.primKey;if(l&&s)throw new C.InvalidArgument("bulkPut(): keys argument invalid on tables with inbound keys");if(s&&s.length!==e.length)throw new C.InvalidArgument("Arguments objects and keys must have the same length");const u=e.length;let d=l&&o?e.map(It(l)):e;return this.core.mutate({trans:i,type:"put",keys:s,values:d,wantResults:a}).then(({numFailures:c,results:h,lastResult:p,failures:y})=>{if(c===0)return a?h:p;throw new We(`${this.name}.bulkPut(): ${c} of ${u} operations failed`,y)})})}bulkDelete(e){const n=e.length;return this._trans("readwrite",r=>this.core.mutate({trans:r,type:"delete",keys:e})).then(({numFailures:r,lastResult:s,failures:a})=>{if(r===0)return s;throw new We(`${this.name}.bulkDelete(): ${r} of ${n} operations failed`,a)})}}function Ze(t){var e={},n=function(i,o){if(o){for(var l=arguments.length,u=new Array(l-1);--l;)u[l-1]=arguments[l];return e[i].subscribe.apply(null,u),t}if(typeof i=="string")return e[i]};n.addEventType=a;for(var r=1,s=arguments.length;r<s;++r)a(arguments[r]);return n;function a(i,o,l){if(typeof i!="object"){var u;o||(o=Bs),l||(l=O);var d={subscribers:[],fire:l,subscribe:function(c){d.subscribers.indexOf(c)===-1&&(d.subscribers.push(c),d.fire=o(d.fire,c))},unsubscribe:function(c){d.subscribers=d.subscribers.filter(function(h){return h!==c}),d.fire=d.subscribers.reduce(o,l)}};return e[i]=n[i]=d,d}B(u=i).forEach(function(c){var h=u[c];if(F(h))a(c,u[c][0],u[c][1]);else{if(h!=="asap")throw new C.InvalidArgument("Invalid event config");var p=a(c,Ve,function(){for(var y=arguments.length,m=new Array(y);y--;)m[y]=arguments[y];p.subscribers.forEach(function(v){Yn(function(){v.apply(null,m)})})})}})}}function et(t,e){return De(e).from({prototype:t}),e}function Ne(t,e){return!(t.filter||t.algorithm||t.or)&&(e?t.justLimit:!t.replayFilter)}function hn(t,e){t.filter=ke(t.filter,e)}function pn(t,e,n){var r=t.replayFilter;t.replayFilter=r?()=>ke(r(),e()):e,t.justLimit=n&&!r}function Pt(t,e){if(t.isPrimKey)return e.primaryKey;const n=e.getIndexByKeyPath(t.index);if(!n)throw new C.Schema("KeyPath "+t.index+" on object store "+e.name+" is not indexed");return n}function _r(t,e,n){const r=Pt(t,e.schema);return e.openCursor({trans:n,values:!t.keysOnly,reverse:t.dir==="prev",unique:!!t.unique,query:{index:r,range:t.range}})}function Ct(t,e,n,r){const s=t.replayFilter?ke(t.filter,t.replayFilter()):t.filter;if(t.or){const a={},i=(o,l,u)=>{if(!s||s(l,u,h=>l.stop(h),h=>l.fail(h))){var d=l.primaryKey,c=""+d;c==="[object ArrayBuffer]"&&(c=""+new Uint8Array(d)),z(a,c)||(a[c]=!0,e(o,l,u))}};return Promise.all([t.or._iterate(i,n),kr(_r(t,r,n),t.algorithm,i,!t.keysOnly&&t.valueMapper)])}return kr(_r(t,r,n),ke(t.algorithm,s),e,!t.keysOnly&&t.valueMapper)}function kr(t,e,n,r){var s=R(r?(a,i,o)=>n(r(a),i,o):n);return t.then(a=>{if(a)return a.start(()=>{var i=()=>a.continue();e&&!e(a,o=>i=o,o=>{a.stop(o),i=O},o=>{a.fail(o),i=O})||s(a.value,a,o=>i=o),i()})})}function V(t,e){try{const n=xr(t),r=xr(e);if(n!==r)return n==="Array"?1:r==="Array"?-1:n==="binary"?1:r==="binary"?-1:n==="string"?1:r==="string"?-1:n==="Date"?1:r!=="Date"?NaN:-1;switch(n){case"number":case"Date":case"string":return t>e?1:t<e?-1:0;case"binary":return function(s,a){const i=s.length,o=a.length,l=i<o?i:o;for(let u=0;u<l;++u)if(s[u]!==a[u])return s[u]<a[u]?-1:1;return i===o?0:i<o?-1:1}(Er(t),Er(e));case"Array":return function(s,a){const i=s.length,o=a.length,l=i<o?i:o;for(let u=0;u<l;++u){const d=V(s[u],a[u]);if(d!==0)return d}return i===o?0:i<o?-1:1}(t,e)}}catch{}return NaN}function xr(t){const e=typeof t;if(e!=="object")return e;if(ArrayBuffer.isView(t))return"binary";const n=qt(t);return n==="ArrayBuffer"?"binary":n}function Er(t){return t instanceof Uint8Array?t:ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t)}class Gs{_read(e,n){var r=this._ctx;return r.error?r.table._trans(null,$.bind(null,r.error)):r.table._trans("readonly",e).then(n)}_write(e){var n=this._ctx;return n.error?n.table._trans(null,$.bind(null,n.error)):n.table._trans("readwrite",e,"locked")}_addAlgorithm(e){var n=this._ctx;n.algorithm=ke(n.algorithm,e)}_iterate(e,n){return Ct(this._ctx,e,n,this._ctx.table.core)}clone(e){var n=Object.create(this.constructor.prototype),r=Object.create(this._ctx);return e&&W(r,e),n._ctx=r,n}raw(){return this._ctx.valueMapper=null,this}each(e){var n=this._ctx;return this._read(r=>Ct(n,e,r,n.table.core))}count(e){return this._read(n=>{const r=this._ctx,s=r.table.core;if(Ne(r,!0))return s.count({trans:n,query:{index:Pt(r,s.schema),range:r.range}}).then(i=>Math.min(i,r.limit));var a=0;return Ct(r,()=>(++a,!1),n,s).then(()=>a)}).then(e)}sortBy(e,n){const r=e.split(".").reverse(),s=r[0],a=r.length-1;function i(u,d){return d?i(u[r[d]],d-1):u[s]}var o=this._ctx.dir==="next"?1:-1;function l(u,d){var c=i(u,a),h=i(d,a);return c<h?-o:c>h?o:0}return this.toArray(function(u){return u.sort(l)}).then(n)}toArray(e){return this._read(n=>{var r=this._ctx;if(r.dir==="next"&&Ne(r,!0)&&r.limit>0){const{valueMapper:s}=r,a=Pt(r,r.table.core.schema);return r.table.core.query({trans:n,limit:r.limit,values:!0,query:{index:a,range:r.range}}).then(({result:i})=>s?i.map(s):i)}{const s=[];return Ct(r,a=>s.push(a),n,r.table.core).then(()=>s)}},e)}offset(e){var n=this._ctx;return e<=0||(n.offset+=e,Ne(n)?pn(n,()=>{var r=e;return(s,a)=>r===0||(r===1?(--r,!1):(a(()=>{s.advance(r),r=0}),!1))}):pn(n,()=>{var r=e;return()=>--r<0})),this}limit(e){return this._ctx.limit=Math.min(this._ctx.limit,e),pn(this._ctx,()=>{var n=e;return function(r,s,a){return--n<=0&&s(a),n>=0}},!0),this}until(e,n){return hn(this._ctx,function(r,s,a){return!e(r.value)||(s(a),n)}),this}first(e){return this.limit(1).toArray(function(n){return n[0]}).then(e)}last(e){return this.reverse().first(e)}filter(e){var n,r;return hn(this._ctx,function(s){return e(s.value)}),n=this._ctx,r=e,n.isMatch=ke(n.isMatch,r),this}and(e){return this.filter(e)}or(e){return new this.db.WhereClause(this._ctx.table,e,this)}reverse(){return this._ctx.dir=this._ctx.dir==="prev"?"next":"prev",this._ondirectionchange&&this._ondirectionchange(this._ctx.dir),this}desc(){return this.reverse()}eachKey(e){var n=this._ctx;return n.keysOnly=!n.isMatch,this.each(function(r,s){e(s.key,s)})}eachUniqueKey(e){return this._ctx.unique="unique",this.eachKey(e)}eachPrimaryKey(e){var n=this._ctx;return n.keysOnly=!n.isMatch,this.each(function(r,s){e(s.primaryKey,s)})}keys(e){var n=this._ctx;n.keysOnly=!n.isMatch;var r=[];return this.each(function(s,a){r.push(a.key)}).then(function(){return r}).then(e)}primaryKeys(e){var n=this._ctx;if(n.dir==="next"&&Ne(n,!0)&&n.limit>0)return this._read(s=>{var a=Pt(n,n.table.core.schema);return n.table.core.query({trans:s,values:!1,limit:n.limit,query:{index:a,range:n.range}})}).then(({result:s})=>s).then(e);n.keysOnly=!n.isMatch;var r=[];return this.each(function(s,a){r.push(a.primaryKey)}).then(function(){return r}).then(e)}uniqueKeys(e){return this._ctx.unique="unique",this.keys(e)}firstKey(e){return this.limit(1).keys(function(n){return n[0]}).then(e)}lastKey(e){return this.reverse().firstKey(e)}distinct(){var e=this._ctx,n=e.index&&e.table.schema.idxByName[e.index];if(!n||!n.multi)return this;var r={};return hn(this._ctx,function(s){var a=s.primaryKey.toString(),i=z(r,a);return r[a]=!0,!i}),this}modify(e){var n=this._ctx;return this._write(r=>{var s;if(typeof e=="function")s=e;else{var a=B(e),i=a.length;s=function(m){for(var v=!1,g=0;g<i;++g){var f=a[g],_=e[f];te(m,f)!==_&&(J(m,f,_),v=!0)}return v}}const o=n.table.core,{outbound:l,extractKey:u}=o.schema.primaryKey,d=this.db._options.modifyChunkSize||200,c=[];let h=0;const p=[],y=(m,v)=>{const{failures:g,numFailures:f}=v;h+=m-f;for(let _ of B(g))c.push(g[_])};return this.clone().primaryKeys().then(m=>{const v=g=>{const f=Math.min(d,m.length-g);return o.getMany({trans:r,keys:m.slice(g,g+f),cache:"immutable"}).then(_=>{const w=[],S=[],x=l?[]:null,b=[];for(let k=0;k<f;++k){const j=_[k],T={value:He(j),primKey:m[g+k]};s.call(T,T.value,T)!==!1&&(T.value==null?b.push(m[g+k]):l||V(u(j),u(T.value))===0?(S.push(T.value),l&&x.push(m[g+k])):(b.push(m[g+k]),w.push(T.value)))}const D=Ne(n)&&n.limit===1/0&&(typeof e!="function"||e===fn)&&{index:n.index,range:n.range};return Promise.resolve(w.length>0&&o.mutate({trans:r,type:"add",values:w}).then(k=>{for(let j in k.failures)b.splice(parseInt(j),1);y(w.length,k)})).then(()=>(S.length>0||D&&typeof e=="object")&&o.mutate({trans:r,type:"put",keys:x,values:S,criteria:D,changeSpec:typeof e!="function"&&e}).then(k=>y(S.length,k))).then(()=>(b.length>0||D&&e===fn)&&o.mutate({trans:r,type:"delete",keys:b,criteria:D}).then(k=>y(b.length,k))).then(()=>m.length>g+f&&v(g+d))})};return v(0).then(()=>{if(c.length>0)throw new dt("Error modifying one or more objects",c,h,p);return m.length})})})}delete(){var e=this._ctx,n=e.range;return Ne(e)&&(e.isPrimKey&&!Ws||n.type===3)?this._write(r=>{const{primaryKey:s}=e.table.core.schema,a=n;return e.table.core.count({trans:r,query:{index:s,range:a}}).then(i=>e.table.core.mutate({trans:r,type:"deleteRange",range:a}).then(({failures:o,lastResult:l,results:u,numFailures:d})=>{if(d)throw new dt("Could not delete some values",Object.keys(o).map(c=>o[c]),i-d);return i-d}))}):this.modify(fn)}}const fn=(t,e)=>e.value=null;function zs(t,e){return t<e?-1:t===e?0:1}function Ys(t,e){return t>e?-1:t===e?0:1}function Y(t,e,n){var r=t instanceof Ir?new t.Collection(t):t;return r._ctx.error=n?new n(e):new TypeError(e),r}function Be(t){return new t.Collection(t,()=>Sr("")).limit(0)}function Js(t,e,n,r,s,a){for(var i=Math.min(t.length,r.length),o=-1,l=0;l<i;++l){var u=e[l];if(u!==r[l])return s(t[l],n[l])<0?t.substr(0,l)+n[l]+n.substr(l+1):s(t[l],r[l])<0?t.substr(0,l)+r[l]+n.substr(l+1):o>=0?t.substr(0,o)+e[o]+n.substr(o+1):null;s(t[l],u)<0&&(o=l)}return i<r.length&&a==="next"?t+n.substr(t.length):i<t.length&&a==="prev"?t.substr(0,n.length):o<0?null:t.substr(0,o)+r[o]+n.substr(o+1)}function At(t,e,n,r){var s,a,i,o,l,u,d,c=n.length;if(!n.every(m=>typeof m=="string"))return Y(t,vr);function h(m){s=function(g){return g==="next"?f=>f.toUpperCase():f=>f.toLowerCase()}(m),a=function(g){return g==="next"?f=>f.toLowerCase():f=>f.toUpperCase()}(m),i=m==="next"?zs:Ys;var v=n.map(function(g){return{lower:a(g),upper:s(g)}}).sort(function(g,f){return i(g.lower,f.lower)});o=v.map(function(g){return g.upper}),l=v.map(function(g){return g.lower}),u=m,d=m==="next"?"":r}h("next");var p=new t.Collection(t,()=>de(o[0],l[c-1]+r));p._ondirectionchange=function(m){h(m)};var y=0;return p._addAlgorithm(function(m,v,g){var f=m.key;if(typeof f!="string")return!1;var _=a(f);if(e(_,l,y))return!0;for(var w=null,S=y;S<c;++S){var x=Js(f,_,o[S],l[S],i,u);x===null&&w===null?y=S+1:(w===null||i(w,x)>0)&&(w=x)}return v(w!==null?function(){m.continue(w+d)}:g),!1}),p}function de(t,e,n,r){return{type:2,lower:t,upper:e,lowerOpen:n,upperOpen:r}}function Sr(t){return{type:1,lower:t,upper:t}}class Ir{get Collection(){return this._ctx.table.db.Collection}between(e,n,r,s){r=r!==!1,s=s===!0;try{return this._cmp(e,n)>0||this._cmp(e,n)===0&&(r||s)&&(!r||!s)?Be(this):new this.Collection(this,()=>de(e,n,!r,!s))}catch{return Y(this,se)}}equals(e){return e==null?Y(this,se):new this.Collection(this,()=>Sr(e))}above(e){return e==null?Y(this,se):new this.Collection(this,()=>de(e,void 0,!0))}aboveOrEqual(e){return e==null?Y(this,se):new this.Collection(this,()=>de(e,void 0,!1))}below(e){return e==null?Y(this,se):new this.Collection(this,()=>de(void 0,e,!1,!0))}belowOrEqual(e){return e==null?Y(this,se):new this.Collection(this,()=>de(void 0,e))}startsWith(e){return typeof e!="string"?Y(this,vr):this.between(e,e+_e,!0,!0)}startsWithIgnoreCase(e){return e===""?this.startsWith(e):At(this,(n,r)=>n.indexOf(r[0])===0,[e],_e)}equalsIgnoreCase(e){return At(this,(n,r)=>n===r[0],[e],"")}anyOfIgnoreCase(){var e=ne.apply(Te,arguments);return e.length===0?Be(this):At(this,(n,r)=>r.indexOf(n)!==-1,e,"")}startsWithAnyOfIgnoreCase(){var e=ne.apply(Te,arguments);return e.length===0?Be(this):At(this,(n,r)=>r.some(s=>n.indexOf(s)===0),e,_e)}anyOf(){const e=ne.apply(Te,arguments);let n=this._cmp;try{e.sort(n)}catch{return Y(this,se)}if(e.length===0)return Be(this);const r=new this.Collection(this,()=>de(e[0],e[e.length-1]));r._ondirectionchange=a=>{n=a==="next"?this._ascending:this._descending,e.sort(n)};let s=0;return r._addAlgorithm((a,i,o)=>{const l=a.key;for(;n(l,e[s])>0;)if(++s,s===e.length)return i(o),!1;return n(l,e[s])===0||(i(()=>{a.continue(e[s])}),!1)}),r}notEqual(e){return this.inAnyRange([[un,e],[e,this.db._maxKey]],{includeLowers:!1,includeUppers:!1})}noneOf(){const e=ne.apply(Te,arguments);if(e.length===0)return new this.Collection(this);try{e.sort(this._ascending)}catch{return Y(this,se)}const n=e.reduce((r,s)=>r?r.concat([[r[r.length-1][1],s]]):[[un,s]],null);return n.push([e[e.length-1],this.db._maxKey]),this.inAnyRange(n,{includeLowers:!1,includeUppers:!1})}inAnyRange(e,n){const r=this._cmp,s=this._ascending,a=this._descending,i=this._min,o=this._max;if(e.length===0)return Be(this);if(!e.every(f=>f[0]!==void 0&&f[1]!==void 0&&s(f[0],f[1])<=0))return Y(this,"First argument to inAnyRange() must be an Array of two-value Arrays [lower,upper] where upper must not be lower than lower",C.InvalidArgument);const l=!n||n.includeLowers!==!1,u=n&&n.includeUppers===!0;let d,c=s;function h(f,_){return c(f[0],_[0])}try{d=e.reduce(function(f,_){let w=0,S=f.length;for(;w<S;++w){const x=f[w];if(r(_[0],x[1])<0&&r(_[1],x[0])>0){x[0]=i(x[0],_[0]),x[1]=o(x[1],_[1]);break}}return w===S&&f.push(_),f},[]),d.sort(h)}catch{return Y(this,se)}let p=0;const y=u?f=>s(f,d[p][1])>0:f=>s(f,d[p][1])>=0,m=l?f=>a(f,d[p][0])>0:f=>a(f,d[p][0])>=0;let v=y;const g=new this.Collection(this,()=>de(d[0][0],d[d.length-1][1],!l,!u));return g._ondirectionchange=f=>{f==="next"?(v=y,c=s):(v=m,c=a),d.sort(h)},g._addAlgorithm((f,_,w)=>{for(var S=f.key;v(S);)if(++p,p===d.length)return _(w),!1;return!!function(x){return!y(x)&&!m(x)}(S)||(this._cmp(S,d[p][1])===0||this._cmp(S,d[p][0])===0||_(()=>{c===s?f.continue(d[p][0]):f.continue(d[p][1])}),!1)}),g}startsWithAnyOf(){const e=ne.apply(Te,arguments);return e.every(n=>typeof n=="string")?e.length===0?Be(this):this.inAnyRange(e.map(n=>[n,n+_e])):Y(this,"startsWithAnyOf() only works with strings")}}function Z(t){return R(function(e){return tt(e),t(e.target.error),!1})}function tt(t){t.stopPropagation&&t.stopPropagation(),t.preventDefault&&t.preventDefault()}const nt="storagemutated",he="x-storagemutated-1",pe=Ze(null,nt);class Qs{_lock(){return Le(!I.global),++this._reculock,this._reculock!==1||I.global||(I.lockOwnerFor=this),this}_unlock(){if(Le(!I.global),--this._reculock==0)for(I.global||(I.lockOwnerFor=null);this._blockedFuncs.length>0&&!this._locked();){var e=this._blockedFuncs.shift();try{je(e[1],e[0])}catch{}}return this}_locked(){return this._reculock&&I.lockOwnerFor!==this}create(e){if(!this.mode)return this;const n=this.db.idbdb,r=this.db._state.dbOpenError;if(Le(!this.idbtrans),!e&&!n)switch(r&&r.name){case"DatabaseClosedError":throw new C.DatabaseClosed(r);case"MissingAPIError":throw new C.MissingAPI(r.message,r);default:throw new C.OpenFailed(r)}if(!this.active)throw new C.TransactionInactive;return Le(this._completion._state===null),(e=this.idbtrans=e||(this.db.core?this.db.core.transaction(this.storeNames,this.mode,{durability:this.chromeTransactionDurability}):n.transaction(this.storeNames,this.mode,{durability:this.chromeTransactionDurability}))).onerror=R(s=>{tt(s),this._reject(e.error)}),e.onabort=R(s=>{tt(s),this.active&&this._reject(new C.Abort(e.error)),this.active=!1,this.on("abort").fire(s)}),e.oncomplete=R(()=>{this.active=!1,this._resolve(),"mutatedParts"in e&&pe.storagemutated.fire(e.mutatedParts)}),this}_promise(e,n,r){if(e==="readwrite"&&this.mode!=="readwrite")return $(new C.ReadOnly("Transaction is readonly"));if(!this.active)return $(new C.TransactionInactive);if(this._locked())return new E((a,i)=>{this._blockedFuncs.push([()=>{this._promise(e,n,r).then(a,i)},I])});if(r)return ue(()=>{var a=new E((i,o)=>{this._lock();const l=n(i,o,this);l&&l.then&&l.then(i,o)});return a.finally(()=>this._unlock()),a._lib=!0,a});var s=new E((a,i)=>{var o=n(a,i,this);o&&o.then&&o.then(a,i)});return s._lib=!0,s}_root(){return this.parent?this.parent._root():this}waitFor(e){var n=this._root();const r=E.resolve(e);if(n._waitingFor)n._waitingFor=n._waitingFor.then(()=>r);else{n._waitingFor=r,n._waitingQueue=[];var s=n.idbtrans.objectStore(n.storeNames[0]);(function i(){for(++n._spinCount;n._waitingQueue.length;)n._waitingQueue.shift()();n._waitingFor&&(s.get(-1/0).onsuccess=i)})()}var a=n._waitingFor;return new E((i,o)=>{r.then(l=>n._waitingQueue.push(R(i.bind(null,l))),l=>n._waitingQueue.push(R(o.bind(null,l)))).finally(()=>{n._waitingFor===a&&(n._waitingFor=null)})})}abort(){this.active&&(this.active=!1,this.idbtrans&&this.idbtrans.abort(),this._reject(new C.Abort))}table(e){const n=this._memoizedTables||(this._memoizedTables={});if(z(n,e))return n[e];const r=this.schema[e];if(!r)throw new C.NotFound("Table "+e+" not part of transaction");const s=new this.db.Table(e,r,this);return s.core=this.db.core.table(e),n[e]=s,s}}function mn(t,e,n,r,s,a,i){return{name:t,keyPath:e,unique:n,multi:r,auto:s,compound:a,src:(n&&!i?"&":"")+(r?"*":"")+(s?"++":"")+Pr(e)}}function Pr(t){return typeof t=="string"?t:t?"["+[].join.call(t,"+")+"]":""}function Cr(t,e,n){return{name:t,primKey:e,indexes:n,mappedClass:null,idxByName:Jn(n,r=>[r.name,r])}}let rt=t=>{try{return t.only([[]]),rt=()=>[[]],[[]]}catch{return rt=()=>_e,_e}};function yn(t){return t==null?()=>{}:typeof t=="string"?function(e){return e.split(".").length===1?n=>n[e]:n=>te(n,e)}(t):e=>te(e,t)}function Ar(t){return[].slice.call(t)}let Xs=0;function st(t){return t==null?":id":typeof t=="string"?t:`[${t.join("+")}]`}function Zs(t,e,n){function r(l){if(l.type===3)return null;if(l.type===4)throw new Error("Cannot convert never type to IDBKeyRange");const{lower:u,upper:d,lowerOpen:c,upperOpen:h}=l;return u===void 0?d===void 0?null:e.upperBound(d,!!h):d===void 0?e.lowerBound(u,!!c):e.bound(u,d,!!c,!!h)}const{schema:s,hasGetAll:a}=function(l,u){const d=Ar(l.objectStoreNames);return{schema:{name:l.name,tables:d.map(c=>u.objectStore(c)).map(c=>{const{keyPath:h,autoIncrement:p}=c,y=F(h),m=h==null,v={},g={name:c.name,primaryKey:{name:null,isPrimaryKey:!0,outbound:m,compound:y,keyPath:h,autoIncrement:p,unique:!0,extractKey:yn(h)},indexes:Ar(c.indexNames).map(f=>c.index(f)).map(f=>{const{name:_,unique:w,multiEntry:S,keyPath:x}=f,b={name:_,compound:F(x),keyPath:x,unique:w,multiEntry:S,extractKey:yn(x)};return v[st(x)]=b,b}),getIndexByKeyPath:f=>v[st(f)]};return v[":id"]=g.primaryKey,h!=null&&(v[st(h)]=g.primaryKey),g})},hasGetAll:d.length>0&&"getAll"in u.objectStore(d[0])&&!(typeof navigator<"u"&&/Safari/.test(navigator.userAgent)&&!/(Chrome\/|Edge\/)/.test(navigator.userAgent)&&[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1]<604)}}(t,n),i=s.tables.map(l=>function(u){const d=u.name;return{name:d,schema:u,mutate:function({trans:c,type:h,keys:p,values:y,range:m}){return new Promise((v,g)=>{v=R(v);const f=c.objectStore(d),_=f.keyPath==null,w=h==="put"||h==="add";if(!w&&h!=="delete"&&h!=="deleteRange")throw new Error("Invalid operation type: "+h);const{length:S}=p||y||{length:1};if(p&&y&&p.length!==y.length)throw new Error("Given keys array must have same length as given values array.");if(S===0)return v({numFailures:0,failures:{},results:[],lastResult:void 0});let x;const b=[],D=[];let k=0;const j=L=>{++k,tt(L)};if(h==="deleteRange"){if(m.type===4)return v({numFailures:k,failures:D,results:[],lastResult:void 0});m.type===3?b.push(x=f.clear()):b.push(x=f.delete(r(m)))}else{const[L,M]=w?_?[y,p]:[y,null]:[p,null];if(w)for(let N=0;N<S;++N)b.push(x=M&&M[N]!==void 0?f[h](L[N],M[N]):f[h](L[N])),x.onerror=j;else for(let N=0;N<S;++N)b.push(x=f[h](L[N])),x.onerror=j}const T=L=>{const M=L.target.result;b.forEach((N,Pe)=>N.error!=null&&(D[Pe]=N.error)),v({numFailures:k,failures:D,results:h==="delete"?p:b.map(N=>N.result),lastResult:M})};x.onerror=L=>{j(L),T(L)},x.onsuccess=T})},getMany:({trans:c,keys:h})=>new Promise((p,y)=>{p=R(p);const m=c.objectStore(d),v=h.length,g=new Array(v);let f,_=0,w=0;const S=b=>{const D=b.target;g[D._pos]=D.result,++w===_&&p(g)},x=Z(y);for(let b=0;b<v;++b)h[b]!=null&&(f=m.get(h[b]),f._pos=b,f.onsuccess=S,f.onerror=x,++_);_===0&&p(g)}),get:({trans:c,key:h})=>new Promise((p,y)=>{p=R(p);const m=c.objectStore(d).get(h);m.onsuccess=v=>p(v.target.result),m.onerror=Z(y)}),query:function(c){return h=>new Promise((p,y)=>{p=R(p);const{trans:m,values:v,limit:g,query:f}=h,_=g===1/0?void 0:g,{index:w,range:S}=f,x=m.objectStore(d),b=w.isPrimaryKey?x:x.index(w.name),D=r(S);if(g===0)return p({result:[]});if(c){const k=v?b.getAll(D,_):b.getAllKeys(D,_);k.onsuccess=j=>p({result:j.target.result}),k.onerror=Z(y)}else{let k=0;const j=v||!("openKeyCursor"in b)?b.openCursor(D):b.openKeyCursor(D),T=[];j.onsuccess=L=>{const M=j.result;return M?(T.push(v?M.value:M.primaryKey),++k===g?p({result:T}):void M.continue()):p({result:T})},j.onerror=Z(y)}})}(a),openCursor:function({trans:c,values:h,query:p,reverse:y,unique:m}){return new Promise((v,g)=>{v=R(v);const{index:f,range:_}=p,w=c.objectStore(d),S=f.isPrimaryKey?w:w.index(f.name),x=y?m?"prevunique":"prev":m?"nextunique":"next",b=h||!("openKeyCursor"in S)?S.openCursor(r(_),x):S.openKeyCursor(r(_),x);b.onerror=Z(g),b.onsuccess=R(D=>{const k=b.result;if(!k)return void v(null);k.___id=++Xs,k.done=!1;const j=k.continue.bind(k);let T=k.continuePrimaryKey;T&&(T=T.bind(k));const L=k.advance.bind(k),M=()=>{throw new Error("Cursor not stopped")};k.trans=c,k.stop=k.continue=k.continuePrimaryKey=k.advance=()=>{throw new Error("Cursor not started")},k.fail=R(g),k.next=function(){let N=1;return this.start(()=>N--?this.continue():this.stop()).then(()=>this)},k.start=N=>{const Pe=new Promise((G,ye)=>{G=R(G),b.onerror=Z(ye),k.fail=ye,k.stop=Me=>{k.stop=k.continue=k.continuePrimaryKey=k.advance=M,G(Me)}}),Ce=()=>{if(b.result)try{N()}catch(G){k.fail(G)}else k.done=!0,k.start=()=>{throw new Error("Cursor behind last entry")},k.stop()};return b.onsuccess=R(G=>{b.onsuccess=Ce,Ce()}),k.continue=j,k.continuePrimaryKey=T,k.advance=L,Ce(),Pe},v(k)},g)})},count({query:c,trans:h}){const{index:p,range:y}=c;return new Promise((m,v)=>{const g=h.objectStore(d),f=p.isPrimaryKey?g:g.index(p.name),_=r(y),w=_?f.count(_):f.count();w.onsuccess=R(S=>m(S.target.result)),w.onerror=Z(v)})}}}(l)),o={};return i.forEach(l=>o[l.name]=l),{stack:"dbcore",transaction:t.transaction.bind(t),table(l){if(!o[l])throw new Error(`Table '${l}' not found`);return o[l]},MIN_KEY:-1/0,MAX_KEY:rt(e),schema:s}}function gn({_novip:t},e){const n=e.db,r=function(s,a,{IDBKeyRange:i,indexedDB:o},l){return{dbcore:function(u,d){return d.reduce((c,{create:h})=>({...c,...h(c)}),u)}(Zs(a,i,l),s.dbcore)}}(t._middlewares,n,t._deps,e);t.core=r.dbcore,t.tables.forEach(s=>{const a=s.name;t.core.schema.tables.some(i=>i.name===a)&&(s.core=t.core.table(a),t[a]instanceof t.Table&&(t[a].core=s.core))})}function Dt({_novip:t},e,n,r){n.forEach(s=>{const a=r[s];e.forEach(i=>{const o=Ft(i,s);(!o||"value"in o&&o.value===void 0)&&(i===t.Transaction.prototype||i instanceof t.Transaction?ee(i,s,{get(){return this.table(s)},set(l){Gn(this,s,{value:l,writable:!0,configurable:!0,enumerable:!0})}}):i[s]=new t.Table(s,a))})})}function vn({_novip:t},e){e.forEach(n=>{for(let r in n)n[r]instanceof t.Table&&delete n[r]})}function ea(t,e){return t._cfg.version-e._cfg.version}function ta(t,e,n,r){const s=t._dbSchema,a=t._createTransaction("readwrite",t._storeNames,s);a.create(n),a._completion.catch(r);const i=a._reject.bind(a),o=I.transless||I;ue(()=>{I.trans=a,I.transless=o,e===0?(B(s).forEach(l=>{bn(n,l,s[l].primKey,s[l].indexes)}),gn(t,n),E.follow(()=>t.on.populate.fire(a)).catch(i)):function({_novip:l},u,d,c){const h=[],p=l._versions;let y=l._dbSchema=_n(l,l.idbdb,c),m=!1;const v=p.filter(f=>f._cfg.version>=u);function g(){return h.length?E.resolve(h.shift()(d.idbtrans)).then(g):E.resolve()}return v.forEach(f=>{h.push(()=>{const _=y,w=f._cfg.dbschema;kn(l,_,c),kn(l,w,c),y=l._dbSchema=w;const S=Dr(_,w);S.add.forEach(b=>{bn(c,b[0],b[1].primKey,b[1].indexes)}),S.change.forEach(b=>{if(b.recreate)throw new C.Upgrade("Not yet support for changing primary key");{const D=c.objectStore(b.name);b.add.forEach(k=>wn(D,k)),b.change.forEach(k=>{D.deleteIndex(k.name),wn(D,k)}),b.del.forEach(k=>D.deleteIndex(k))}});const x=f._cfg.contentUpgrade;if(x&&f._cfg.version>u){gn(l,c),d._memoizedTables={},m=!0;let b=Qn(w);S.del.forEach(T=>{b[T]=_[T]}),vn(l,[l.Transaction.prototype]),Dt(l,[l.Transaction.prototype],B(b),b),d.schema=b;const D=Ht(x);let k;D&&Re();const j=E.follow(()=>{if(k=x(d),k&&D){var T=re.bind(null,null);k.then(T,T)}});return k&&typeof k.then=="function"?E.resolve(k):j.then(()=>k)}}),h.push(_=>{(!m||!Hs)&&function(w,S){[].slice.call(S.db.objectStoreNames).forEach(x=>w[x]==null&&S.db.deleteObjectStore(x))}(f._cfg.dbschema,_),vn(l,[l.Transaction.prototype]),Dt(l,[l.Transaction.prototype],l._storeNames,l._dbSchema),d.schema=l._dbSchema})}),g().then(()=>{var f,_;_=c,B(f=y).forEach(w=>{_.db.objectStoreNames.contains(w)||bn(_,w,f[w].primKey,f[w].indexes)})})}(t,e,a,n).catch(i)})}function Dr(t,e){const n={del:[],add:[],change:[]};let r;for(r in t)e[r]||n.del.push(r);for(r in e){const s=t[r],a=e[r];if(s){const i={name:r,def:a,recreate:!1,del:[],add:[],change:[]};if(""+(s.primKey.keyPath||"")!=""+(a.primKey.keyPath||"")||s.primKey.auto!==a.primKey.auto&&!Et)i.recreate=!0,n.change.push(i);else{const o=s.idxByName,l=a.idxByName;let u;for(u in o)l[u]||i.del.push(u);for(u in l){const d=o[u],c=l[u];d?d.src!==c.src&&i.change.push(c):i.add.push(c)}(i.del.length>0||i.add.length>0||i.change.length>0)&&n.change.push(i)}}else n.add.push([r,a])}return n}function bn(t,e,n,r){const s=t.db.createObjectStore(e,n.keyPath?{keyPath:n.keyPath,autoIncrement:n.auto}:{autoIncrement:n.auto});return r.forEach(a=>wn(s,a)),s}function wn(t,e){t.createIndex(e.name,e.keyPath,{unique:e.unique,multiEntry:e.multi})}function _n(t,e,n){const r={};return ct(e.objectStoreNames,0).forEach(s=>{const a=n.objectStore(s);let i=a.keyPath;const o=mn(Pr(i),i||"",!1,!1,!!a.autoIncrement,i&&typeof i!="string",!0),l=[];for(let d=0;d<a.indexNames.length;++d){const c=a.index(a.indexNames[d]);i=c.keyPath;var u=mn(c.name,i,!!c.unique,!!c.multiEntry,!1,i&&typeof i!="string",!1);l.push(u)}r[s]=Cr(s,o,l)}),r}function kn({_novip:t},e,n){const r=n.db.objectStoreNames;for(let s=0;s<r.length;++s){const a=r[s],i=n.objectStore(a);t._hasGetAll="getAll"in i;for(let o=0;o<i.indexNames.length;++o){const l=i.indexNames[o],u=i.index(l).keyPath,d=typeof u=="string"?u:"["+ct(u).join("+")+"]";if(e[a]){const c=e[a].idxByName[d];c&&(c.name=l,delete e[a].idxByName[d],e[a].idxByName[l]=c)}}}typeof navigator<"u"&&/Safari/.test(navigator.userAgent)&&!/(Chrome\/|Edge\/)/.test(navigator.userAgent)&&K.WorkerGlobalScope&&K instanceof K.WorkerGlobalScope&&[].concat(navigator.userAgent.match(/Safari\/(\d*)/))[1]<604&&(t._hasGetAll=!1)}class na{_parseStoresSpec(e,n){B(e).forEach(r=>{if(e[r]!==null){var s=e[r].split(",").map((i,o)=>{const l=(i=i.trim()).replace(/([&*]|\+\+)/g,""),u=/^\[/.test(l)?l.match(/^\[(.*)\]$/)[1].split("+"):l;return mn(l,u||null,/\&/.test(i),/\*/.test(i),/\+\+/.test(i),F(u),o===0)}),a=s.shift();if(a.multi)throw new C.Schema("Primary key cannot be multi-valued");s.forEach(i=>{if(i.auto)throw new C.Schema("Only primary key can be marked as autoIncrement (++)");if(!i.keyPath)throw new C.Schema("Index must have a name and cannot be an empty string")}),n[r]=Cr(r,a,s)}})}stores(e){const n=this.db;this._cfg.storesSource=this._cfg.storesSource?W(this._cfg.storesSource,e):e;const r=n._versions,s={};let a={};return r.forEach(i=>{W(s,i._cfg.storesSource),a=i._cfg.dbschema={},i._parseStoresSpec(s,a)}),n._dbSchema=a,vn(n,[n._allTables,n,n.Transaction.prototype]),Dt(n,[n._allTables,n,n.Transaction.prototype,this._cfg.tables],B(a),a),n._storeNames=B(a),this}upgrade(e){return this._cfg.contentUpgrade=zt(this._cfg.contentUpgrade||O,e),this}}function xn(t,e){let n=t._dbNamesDB;return n||(n=t._dbNamesDB=new Ie(St,{addons:[],indexedDB:t,IDBKeyRange:e}),n.version(1).stores({dbnames:"name"})),n.table("dbnames")}function En(t){return t&&typeof t.databases=="function"}function Sn(t){return ue(function(){return I.letThrough=!0,t()})}function ra(){var t;return!navigator.userAgentData&&/Safari\//.test(navigator.userAgent)&&!/Chrom(e|ium)\//.test(navigator.userAgent)&&indexedDB.databases?new Promise(function(e){var n=function(){return indexedDB.databases().finally(e)};t=setInterval(n,100),n()}).finally(function(){return clearInterval(t)}):Promise.resolve()}function sa(t){const e=t._state,{indexedDB:n}=t._deps;if(e.isBeingOpened||t.idbdb)return e.dbReadyPromise.then(()=>e.dbOpenError?$(e.dbOpenError):t);X&&(e.openCanceller._stackHolder=ge()),e.isBeingOpened=!0,e.dbOpenError=null,e.openComplete=!1;const r=e.openCanceller;function s(){if(e.openCanceller!==r)throw new C.DatabaseClosed("db.open() was cancelled")}let a=e.dbReadyResolve,i=null,o=!1;const l=()=>new E((u,d)=>{if(s(),!n)throw new C.MissingAPI;const c=t.name,h=e.autoSchema?n.open(c):n.open(c,Math.round(10*t.verno));if(!h)throw new C.MissingAPI;h.onerror=Z(d),h.onblocked=R(t._fireOnBlocked),h.onupgradeneeded=R(p=>{if(i=h.transaction,e.autoSchema&&!t._options.allowEmptyDB){h.onerror=tt,i.abort(),h.result.close();const m=n.deleteDatabase(c);m.onsuccess=m.onerror=R(()=>{d(new C.NoSuchDatabase(`Database ${c} doesnt exist`))})}else{i.onerror=Z(d);var y=p.oldVersion>Math.pow(2,62)?0:p.oldVersion;o=y<1,t._novip.idbdb=h.result,ta(t,y/10,i,d)}},d),h.onsuccess=R(()=>{i=null;const p=t._novip.idbdb=h.result,y=ct(p.objectStoreNames);if(y.length>0)try{const v=p.transaction((m=y).length===1?m[0]:m,"readonly");e.autoSchema?function({_novip:g},f,_){g.verno=f.version/10;const w=g._dbSchema=_n(0,f,_);g._storeNames=ct(f.objectStoreNames,0),Dt(g,[g._allTables],B(w),w)}(t,p,v):(kn(t,t._dbSchema,v),function(g,f){const _=Dr(_n(0,g.idbdb,f),g._dbSchema);return!(_.add.length||_.change.some(w=>w.add.length||w.change.length))}(t,v)||console.warn("Dexie SchemaDiff: Schema was extended without increasing the number passed to db.version(). Some queries may fail.")),gn(t,v)}catch{}var m;Xe.push(t),p.onversionchange=R(v=>{e.vcFired=!0,t.on("versionchange").fire(v)}),p.onclose=R(v=>{t.on("close").fire(v)}),o&&function({indexedDB:v,IDBKeyRange:g},f){!En(v)&&f!==St&&xn(v,g).put({name:f}).catch(O)}(t._deps,c),u()},d)}).catch(u=>u&&u.name==="UnknownError"&&e.PR1398_maxLoop>0?(e.PR1398_maxLoop--,console.warn("Dexie: Workaround for Chrome UnknownError on open()"),l()):E.reject(u));return E.race([r,(typeof navigator>"u"?E.resolve():ra()).then(l)]).then(()=>(s(),e.onReadyBeingFired=[],E.resolve(Sn(()=>t.on.ready.fire(t.vip))).then(function u(){if(e.onReadyBeingFired.length>0){let d=e.onReadyBeingFired.reduce(zt,O);return e.onReadyBeingFired=[],E.resolve(Sn(()=>d(t.vip))).then(u)}}))).finally(()=>{e.onReadyBeingFired=null,e.isBeingOpened=!1}).then(()=>t).catch(u=>{e.dbOpenError=u;try{i&&i.abort()}catch{}return r===e.openCanceller&&t._close(),$(u)}).finally(()=>{e.openComplete=!0,a()})}function In(t){var e=a=>t.next(a),n=s(e),r=s(a=>t.throw(a));function s(a){return i=>{var o=a(i),l=o.value;return o.done?l:l&&typeof l.then=="function"?l.then(n,r):F(l)?Promise.all(l).then(n,r):n(l)}}return s(e)()}function aa(t,e,n){var r=arguments.length;if(r<2)throw new C.InvalidArgument("Too few arguments");for(var s=new Array(r-1);--r;)s[r-1]=arguments[r];return n=s.pop(),[t,Xn(s),n]}function Tr(t,e,n,r,s){return E.resolve().then(()=>{const a=I.transless||I,i=t._createTransaction(e,n,t._dbSchema,r),o={trans:i,transless:a};if(r)i.idbtrans=r.idbtrans;else try{i.create(),t._state.PR1398_maxLoop=3}catch(c){return c.name===Gt.InvalidState&&t.isOpen()&&--t._state.PR1398_maxLoop>0?(console.warn("Dexie: Need to reopen db"),t._close(),t.open().then(()=>Tr(t,e,n,null,s))):$(c)}const l=Ht(s);let u;l&&Re();const d=E.follow(()=>{if(u=s.call(i,i),u)if(l){var c=re.bind(null,null);u.then(c,c)}else typeof u.next=="function"&&typeof u.throw=="function"&&(u=In(u))},o);return(u&&typeof u.then=="function"?E.resolve(u).then(c=>i.active?c:$(new C.PrematureCommit("Transaction committed too early. See http://bit.ly/2kdckMn"))):d.then(()=>u)).then(c=>(r&&i._resolve(),i._completion.then(()=>c))).catch(c=>(i._reject(c),$(c)))})}function Tt(t,e,n){const r=F(t)?t.slice():[t];for(let s=0;s<n;++s)r.push(e);return r}const ia={stack:"dbcore",name:"VirtualIndexMiddleware",level:1,create:function(t){return{...t,table(e){const n=t.table(e),{schema:r}=n,s={},a=[];function i(u,d,c){const h=st(u),p=s[h]=s[h]||[],y=u==null?0:typeof u=="string"?1:u.length,m=d>0,v={...c,isVirtual:m,keyTail:d,keyLength:y,extractKey:yn(u),unique:!m&&c.unique};return p.push(v),v.isPrimaryKey||a.push(v),y>1&&i(y===2?u[0]:u.slice(0,y-1),d+1,c),p.sort((g,f)=>g.keyTail-f.keyTail),v}const o=i(r.primaryKey.keyPath,0,r.primaryKey);s[":id"]=[o];for(const u of r.indexes)i(u.keyPath,0,u);function l(u){const d=u.query.index;return d.isVirtual?{...u,query:{index:d,range:(c=u.query.range,h=d.keyTail,{type:c.type===1?2:c.type,lower:Tt(c.lower,c.lowerOpen?t.MAX_KEY:t.MIN_KEY,h),lowerOpen:!0,upper:Tt(c.upper,c.upperOpen?t.MIN_KEY:t.MAX_KEY,h),upperOpen:!0})}}:u;var c,h}return{...n,schema:{...r,primaryKey:o,indexes:a,getIndexByKeyPath:function(u){const d=s[st(u)];return d&&d[0]}},count:u=>n.count(l(u)),query:u=>n.query(l(u)),openCursor(u){const{keyTail:d,isVirtual:c,keyLength:h}=u.query.index;return c?n.openCursor(l(u)).then(p=>p&&function(y){return Object.create(y,{continue:{value:function(m){m!=null?y.continue(Tt(m,u.reverse?t.MAX_KEY:t.MIN_KEY,d)):u.unique?y.continue(y.key.slice(0,h).concat(u.reverse?t.MIN_KEY:t.MAX_KEY,d)):y.continue()}},continuePrimaryKey:{value(m,v){y.continuePrimaryKey(Tt(m,t.MAX_KEY,d),v)}},primaryKey:{get:()=>y.primaryKey},key:{get(){const m=y.key;return h===1?m[0]:m.slice(0,h)}},value:{get:()=>y.value}})}(p)):n.openCursor(u)}}}}}};function Pn(t,e,n,r){return n=n||{},r=r||"",B(t).forEach(s=>{if(z(e,s)){var a=t[s],i=e[s];if(typeof a=="object"&&typeof i=="object"&&a&&i){const o=qt(a);o!==qt(i)?n[r+s]=e[s]:o==="Object"?Pn(a,i,n,r+s+"."):a!==i&&(n[r+s]=e[s])}else a!==i&&(n[r+s]=e[s])}else n[r+s]=void 0}),B(e).forEach(s=>{z(t,s)||(n[r+s]=e[s])}),n}const oa={stack:"dbcore",name:"HooksMiddleware",level:2,create:t=>({...t,table(e){const n=t.table(e),{primaryKey:r}=n.schema;return{...n,mutate(s){const a=I.trans,{deleting:i,creating:o,updating:l}=a.table(e).hook;switch(s.type){case"add":if(o.fire===O)break;return a._promise("readwrite",()=>u(s),!0);case"put":if(o.fire===O&&l.fire===O)break;return a._promise("readwrite",()=>u(s),!0);case"delete":if(i.fire===O)break;return a._promise("readwrite",()=>u(s),!0);case"deleteRange":if(i.fire===O)break;return a._promise("readwrite",()=>function(c){return d(c.trans,c.range,1e4)}(s),!0)}return n.mutate(s);function u(c){const h=I.trans,p=c.keys||function(y,m){return m.type==="delete"?m.keys:m.keys||m.values.map(y.extractKey)}(r,c);if(!p)throw new Error("Keys missing");return(c=c.type==="add"||c.type==="put"?{...c,keys:p}:{...c}).type!=="delete"&&(c.values=[...c.values]),c.keys&&(c.keys=[...c.keys]),function(y,m,v){return m.type==="add"?Promise.resolve([]):y.getMany({trans:m.trans,keys:v,cache:"immutable"})}(n,c,p).then(y=>{const m=p.map((v,g)=>{const f=y[g],_={onerror:null,onsuccess:null};if(c.type==="delete")i.fire.call(_,v,f,h);else if(c.type==="add"||f===void 0){const w=o.fire.call(_,v,c.values[g],h);v==null&&w!=null&&(v=w,c.keys[g]=v,r.outbound||J(c.values[g],r.keyPath,v))}else{const w=Pn(f,c.values[g]),S=l.fire.call(_,w,v,f,h);if(S){const x=c.values[g];Object.keys(S).forEach(b=>{z(x,b)?x[b]=S[b]:J(x,b,S[b])})}}return _});return n.mutate(c).then(({failures:v,results:g,numFailures:f,lastResult:_})=>{for(let w=0;w<p.length;++w){const S=g?g[w]:p[w],x=m[w];S==null?x.onerror&&x.onerror(v[w]):x.onsuccess&&x.onsuccess(c.type==="put"&&y[w]?c.values[w]:S)}return{failures:v,results:g,numFailures:f,lastResult:_}}).catch(v=>(m.forEach(g=>g.onerror&&g.onerror(v)),Promise.reject(v)))})}function d(c,h,p){return n.query({trans:c,values:!1,query:{index:r,range:h},limit:p}).then(({result:y})=>u({type:"delete",keys:y,trans:c}).then(m=>m.numFailures>0?Promise.reject(m.failures[0]):y.length<p?{failures:[],numFailures:0,lastResult:void 0}:d(c,{...h,lower:y[y.length-1],lowerOpen:!0},p)))}}}}})};function Or(t,e,n){try{if(!e||e.keys.length<t.length)return null;const r=[];for(let s=0,a=0;s<e.keys.length&&a<t.length;++s)V(e.keys[s],t[a])===0&&(r.push(n?He(e.values[s]):e.values[s]),++a);return r.length===t.length?r:null}catch{return null}}const la={stack:"dbcore",level:-1,create:t=>({table:e=>{const n=t.table(e);return{...n,getMany:r=>{if(!r.cache)return n.getMany(r);const s=Or(r.keys,r.trans._cache,r.cache==="clone");return s?E.resolve(s):n.getMany(r).then(a=>(r.trans._cache={keys:r.keys,values:r.cache==="clone"?He(a):a},a))},mutate:r=>(r.type!=="add"&&(r.trans._cache=null),n.mutate(r))}}})};function Cn(t){return!("from"in t)}const ae=function(t,e){if(!this){const n=new ae;return t&&"d"in t&&W(n,t),n}W(this,arguments.length?{d:1,from:t,to:arguments.length>1?e:t}:{d:0})};function at(t,e,n){const r=V(e,n);if(isNaN(r))return;if(r>0)throw RangeError();if(Cn(t))return W(t,{from:e,to:n,d:1});const s=t.l,a=t.r;if(V(n,t.from)<0)return s?at(s,e,n):t.l={from:e,to:n,d:1,l:null,r:null},Kr(t);if(V(e,t.to)>0)return a?at(a,e,n):t.r={from:e,to:n,d:1,l:null,r:null},Kr(t);V(e,t.from)<0&&(t.from=e,t.l=null,t.d=a?a.d+1:1),V(n,t.to)>0&&(t.to=n,t.r=null,t.d=t.l?t.l.d+1:1);const i=!t.r;s&&!t.l&&Ot(t,s),a&&i&&Ot(t,a)}function Ot(t,e){Cn(e)||function n(r,{from:s,to:a,l:i,r:o}){at(r,s,a),i&&n(r,i),o&&n(r,o)}(t,e)}function ua(t,e){const n=An(e);let r=n.next();if(r.done)return!1;let s=r.value;const a=An(t);let i=a.next(s.from),o=i.value;for(;!r.done&&!i.done;){if(V(o.from,s.to)<=0&&V(o.to,s.from)>=0)return!0;V(s.from,o.from)<0?s=(r=n.next(o.from)).value:o=(i=a.next(s.from)).value}return!1}function An(t){let e=Cn(t)?null:{s:0,n:t};return{next(n){const r=arguments.length>0;for(;e;)switch(e.s){case 0:if(e.s=1,r)for(;e.n.l&&V(n,e.n.from)<0;)e={up:e,n:e.n.l,s:1};else for(;e.n.l;)e={up:e,n:e.n.l,s:1};case 1:if(e.s=2,!r||V(n,e.n.to)<=0)return{value:e.n,done:!1};case 2:if(e.n.r){e.s=3,e={up:e,n:e.n.r,s:0};continue}case 3:e=e.up}return{done:!0}}}}function Kr(t){var e,n;const r=(((e=t.r)===null||e===void 0?void 0:e.d)||0)-(((n=t.l)===null||n===void 0?void 0:n.d)||0),s=r>1?"r":r<-1?"l":"";if(s){const a=s==="r"?"l":"r",i={...t},o=t[s];t.from=o.from,t.to=o.to,t[s]=o[s],i[s]=o[a],t[a]=i,i.d=Rr(i)}t.d=Rr(t)}function Rr({r:t,l:e}){return(t?e?Math.max(t.d,e.d):t.d:e?e.d:0)+1}Ae(ae.prototype,{add(t){return Ot(this,t),this},addKey(t){return at(this,t,t),this},addKeys(t){return t.forEach(e=>at(this,e,e)),this},[Lt](){return An(this)}});const ca={stack:"dbcore",level:0,create:t=>{const e=t.schema.name,n=new ae(t.MIN_KEY,t.MAX_KEY);return{...t,table:r=>{const s=t.table(r),{schema:a}=s,{primaryKey:i}=a,{extractKey:o,outbound:l}=i,u={...s,mutate:h=>{const p=h.trans,y=p.mutatedParts||(p.mutatedParts={}),m=x=>{const b=`idb://${e}/${r}/${x}`;return y[b]||(y[b]=new ae)},v=m(""),g=m(":dels"),{type:f}=h;let[_,w]=h.type==="deleteRange"?[h.range]:h.type==="delete"?[h.keys]:h.values.length<50?[[],h.values]:[];const S=h.trans._cache;return s.mutate(h).then(x=>{if(F(_)){f!=="delete"&&(_=x.results),v.addKeys(_);const b=Or(_,S);b||f==="add"||g.addKeys(_),(b||w)&&function(D,k,j,T){function L(M){const N=D(M.name||"");function Pe(G){return G!=null?M.extractKey(G):null}const Ce=G=>M.multiEntry&&F(G)?G.forEach(ye=>N.addKey(ye)):N.addKey(G);(j||T).forEach((G,ye)=>{const Me=j&&Pe(j[ye]),$t=T&&Pe(T[ye]);V(Me,$t)!==0&&(Me!=null&&Ce(Me),$t!=null&&Ce($t))})}k.indexes.forEach(L)}(m,a,b,w)}else if(_){const b={from:_.lower,to:_.upper};g.add(b),v.add(b)}else v.add(n),g.add(n),a.indexes.forEach(b=>m(b.name).add(n));return x})}},d=({query:{index:h,range:p}})=>{var y,m;return[h,new ae((y=p.lower)!==null&&y!==void 0?y:t.MIN_KEY,(m=p.upper)!==null&&m!==void 0?m:t.MAX_KEY)]},c={get:h=>[i,new ae(h.key)],getMany:h=>[i,new ae().addKeys(h.keys)],count:d,query:d,openCursor:d};return B(c).forEach(h=>{u[h]=function(p){const{subscr:y}=I;if(y){const m=w=>{const S=`idb://${e}/${r}/${w}`;return y[S]||(y[S]=new ae)},v=m(""),g=m(":dels"),[f,_]=c[h](p);if(m(f.name||"").add(_),!f.isPrimaryKey){if(h!=="count"){const w=h==="query"&&l&&p.values&&s.query({...p,values:!1});return s[h].apply(this,arguments).then(S=>{if(h==="query"){if(l&&p.values)return w.then(({result:b})=>(v.addKeys(b),S));const x=p.values?S.result.map(o):S.result;p.values?v.addKeys(x):g.addKeys(x)}else if(h==="openCursor"){const x=S,b=p.values;return x&&Object.create(x,{key:{get:()=>(g.addKey(x.primaryKey),x.key)},primaryKey:{get(){const D=x.primaryKey;return g.addKey(D),D}},value:{get:()=>(b&&v.addKey(x.primaryKey),x.value)}})}return S})}g.add(n)}}return s[h].apply(this,arguments)}}),u}}}};class Ie{constructor(e,n){this._middlewares={},this.verno=0;const r=Ie.dependencies;this._options=n={addons:Ie.addons,autoOpen:!0,indexedDB:r.indexedDB,IDBKeyRange:r.IDBKeyRange,...n},this._deps={indexedDB:n.indexedDB,IDBKeyRange:n.IDBKeyRange};const{addons:s}=n;this._dbSchema={},this._versions=[],this._storeNames=[],this._allTables={},this.idbdb=null,this._novip=this;const a={dbOpenError:null,isBeingOpened:!1,onReadyBeingFired:null,openComplete:!1,dbReadyResolve:O,dbReadyPromise:null,cancelOpen:O,openCanceller:null,autoSchema:!0,PR1398_maxLoop:3};var i;a.dbReadyPromise=new E(o=>{a.dbReadyResolve=o}),a.openCanceller=new E((o,l)=>{a.cancelOpen=l}),this._state=a,this.name=e,this.on=Ze(this,"populate","blocked","versionchange","close",{ready:[zt,O]}),this.on.ready.subscribe=zn(this.on.ready.subscribe,o=>(l,u)=>{Ie.vip(()=>{const d=this._state;if(d.openComplete)d.dbOpenError||E.resolve().then(l),u&&o(l);else if(d.onReadyBeingFired)d.onReadyBeingFired.push(l),u&&o(l);else{o(l);const c=this;u||o(function h(){c.on.ready.unsubscribe(l),c.on.ready.unsubscribe(h)})}})}),this.Collection=(i=this,et(Gs.prototype,function(o,l){this.db=i;let u=wr,d=null;if(l)try{u=l()}catch(y){d=y}const c=o._ctx,h=c.table,p=h.hook.reading.fire;this._ctx={table:h,index:c.index,isPrimKey:!c.index||h.schema.primKey.keyPath&&c.index===h.schema.primKey.name,range:u,keysOnly:!1,dir:"next",unique:"",algorithm:null,filter:null,replayFilter:null,justLimit:!0,isMatch:null,offset:0,limit:1/0,error:d,or:c.or,valueMapper:p!==Ve?p:null}})),this.Table=function(o){return et(Vs.prototype,function(l,u,d){this.db=o,this._tx=d,this.name=l,this.schema=u,this.hook=o._allTables[l]?o._allTables[l].hook:Ze(null,{creating:[Rs,O],reading:[Ks,Ve],updating:[Ns,O],deleting:[js,O]})})}(this),this.Transaction=function(o){return et(Qs.prototype,function(l,u,d,c,h){this.db=o,this.mode=l,this.storeNames=u,this.schema=d,this.chromeTransactionDurability=c,this.idbtrans=null,this.on=Ze(this,"complete","error","abort"),this.parent=h||null,this.active=!0,this._reculock=0,this._blockedFuncs=[],this._resolve=null,this._reject=null,this._waitingFor=null,this._waitingQueue=null,this._spinCount=0,this._completion=new E((p,y)=>{this._resolve=p,this._reject=y}),this._completion.then(()=>{this.active=!1,this.on.complete.fire()},p=>{var y=this.active;return this.active=!1,this.on.error.fire(p),this.parent?this.parent._reject(p):y&&this.idbtrans&&this.idbtrans.abort(),$(p)})})}(this),this.Version=function(o){return et(na.prototype,function(l){this.db=o,this._cfg={version:l,storesSource:null,dbschema:{},tables:{},contentUpgrade:null}})}(this),this.WhereClause=function(o){return et(Ir.prototype,function(l,u,d){this.db=o,this._ctx={table:l,index:u===":id"?null:u,or:d};const c=o._deps.indexedDB;if(!c)throw new C.MissingAPI;this._cmp=this._ascending=c.cmp.bind(c),this._descending=(h,p)=>c.cmp(p,h),this._max=(h,p)=>c.cmp(h,p)>0?h:p,this._min=(h,p)=>c.cmp(h,p)<0?h:p,this._IDBKeyRange=o._deps.IDBKeyRange})}(this),this.on("versionchange",o=>{o.newVersion>0?console.warn(`Another connection wants to upgrade database '${this.name}'. Closing db now to resume the upgrade.`):console.warn(`Another connection wants to delete database '${this.name}'. Closing db now to resume the delete request.`),this.close()}),this.on("blocked",o=>{!o.newVersion||o.newVersion<o.oldVersion?console.warn(`Dexie.delete('${this.name}') was blocked`):console.warn(`Upgrade '${this.name}' blocked by other connection holding version ${o.oldVersion/10}`)}),this._maxKey=rt(n.IDBKeyRange),this._createTransaction=(o,l,u,d)=>new this.Transaction(o,l,u,this._options.chromeTransactionDurability,d),this._fireOnBlocked=o=>{this.on("blocked").fire(o),Xe.filter(l=>l.name===this.name&&l!==this&&!l._state.vcFired).map(l=>l.on("versionchange").fire(o))},this.use(ia),this.use(oa),this.use(ca),this.use(la),this.vip=Object.create(this,{_vip:{value:!0}}),s.forEach(o=>o(this))}version(e){if(isNaN(e)||e<.1)throw new C.Type("Given version is not a positive number");if(e=Math.round(10*e)/10,this.idbdb||this._state.isBeingOpened)throw new C.Schema("Cannot add version when database is open");this.verno=Math.max(this.verno,e);const n=this._versions;var r=n.filter(s=>s._cfg.version===e)[0];return r||(r=new this.Version(e),n.push(r),n.sort(ea),r.stores({}),this._state.autoSchema=!1,r)}_whenReady(e){return this.idbdb&&(this._state.openComplete||I.letThrough||this._vip)?e():new E((n,r)=>{if(this._state.openComplete)return r(new C.DatabaseClosed(this._state.dbOpenError));if(!this._state.isBeingOpened){if(!this._options.autoOpen)return void r(new C.DatabaseClosed);this.open().catch(O)}this._state.dbReadyPromise.then(n,r)}).then(e)}use({stack:e,create:n,level:r,name:s}){s&&this.unuse({stack:e,name:s});const a=this._middlewares[e]||(this._middlewares[e]=[]);return a.push({stack:e,create:n,level:r??10,name:s}),a.sort((i,o)=>i.level-o.level),this}unuse({stack:e,name:n,create:r}){return e&&this._middlewares[e]&&(this._middlewares[e]=this._middlewares[e].filter(s=>r?s.create!==r:!!n&&s.name!==n)),this}open(){return sa(this)}_close(){const e=this._state,n=Xe.indexOf(this);if(n>=0&&Xe.splice(n,1),this.idbdb){try{this.idbdb.close()}catch{}this._novip.idbdb=null}e.dbReadyPromise=new E(r=>{e.dbReadyResolve=r}),e.openCanceller=new E((r,s)=>{e.cancelOpen=s})}close(){this._close();const e=this._state;this._options.autoOpen=!1,e.dbOpenError=new C.DatabaseClosed,e.isBeingOpened&&e.cancelOpen(e.dbOpenError)}delete(){const e=arguments.length>0,n=this._state;return new E((r,s)=>{const a=()=>{this.close();var i=this._deps.indexedDB.deleteDatabase(this.name);i.onsuccess=R(()=>{(function({indexedDB:o,IDBKeyRange:l},u){!En(o)&&u!==St&&xn(o,l).delete(u).catch(O)})(this._deps,this.name),r()}),i.onerror=Z(s),i.onblocked=this._fireOnBlocked};if(e)throw new C.InvalidArgument("Arguments not allowed in db.delete()");n.isBeingOpened?n.dbReadyPromise.then(a):a()})}backendDB(){return this.idbdb}isOpen(){return this.idbdb!==null}hasBeenClosed(){const e=this._state.dbOpenError;return e&&e.name==="DatabaseClosed"}hasFailed(){return this._state.dbOpenError!==null}dynamicallyOpened(){return this._state.autoSchema}get tables(){return B(this._allTables).map(e=>this._allTables[e])}transaction(){const e=aa.apply(this,arguments);return this._transaction.apply(this,e)}_transaction(e,n,r){let s=I.trans;s&&s.db===this&&e.indexOf("!")===-1||(s=null);const a=e.indexOf("?")!==-1;let i,o;e=e.replace("!","").replace("?","");try{if(o=n.map(u=>{var d=u instanceof this.Table?u.name:u;if(typeof d!="string")throw new TypeError("Invalid table argument to Dexie.transaction(). Only Table or String are allowed");return d}),e=="r"||e===cn)i=cn;else{if(e!="rw"&&e!=dn)throw new C.InvalidArgument("Invalid transaction mode: "+e);i=dn}if(s){if(s.mode===cn&&i===dn){if(!a)throw new C.SubTransaction("Cannot enter a sub-transaction with READWRITE mode when parent transaction is READONLY");s=null}s&&o.forEach(u=>{if(s&&s.storeNames.indexOf(u)===-1){if(!a)throw new C.SubTransaction("Table "+u+" not included in parent transaction.");s=null}}),a&&s&&!s.active&&(s=null)}}catch(u){return s?s._promise(null,(d,c)=>{c(u)}):$(u)}const l=Tr.bind(null,this,i,o,s,r);return s?s._promise(i,l,"lock"):I.trans?je(I.transless,()=>this._whenReady(l)):this._whenReady(l)}table(e){if(!z(this._allTables,e))throw new C.InvalidTable(`Table ${e} does not exist`);return this._allTables[e]}}const da=typeof Symbol<"u"&&"observable"in Symbol?Symbol.observable:"@@observable";class ha{constructor(e){this._subscribe=e}subscribe(e,n,r){return this._subscribe(e&&typeof e!="function"?e:{next:e,error:n,complete:r})}[da](){return this}}function jr(t,e){return B(e).forEach(n=>{Ot(t[n]||(t[n]=new ae),e[n])}),t}function pa(t){let e,n=!1;const r=new ha(s=>{const a=Ht(t);let i=!1,o={},l={};const u={get closed(){return i},unsubscribe:()=>{i=!0,pe.storagemutated.unsubscribe(p)}};s.start&&s.start(u);let d=!1,c=!1;function h(){return B(l).some(m=>o[m]&&ua(o[m],l[m]))}const p=m=>{jr(o,m),h()&&y()},y=()=>{if(d||i)return;o={};const m={},v=function(g){a&&Re();const f=()=>ue(t,{subscr:g,trans:null}),_=I.trans?je(I.transless,f):f();return a&&_.then(re,re),_}(m);c||(pe(nt,p),c=!0),d=!0,Promise.resolve(v).then(g=>{n=!0,e=g,d=!1,i||(h()?y():(o={},l=m,s.next&&s.next(g)))},g=>{d=!1,n=!1,s.error&&s.error(g),u.unsubscribe()})};return y(),u});return r.hasValue=()=>n,r.getValue=()=>e,r}let Dn;try{Dn={indexedDB:K.indexedDB||K.mozIndexedDB||K.webkitIndexedDB||K.msIndexedDB,IDBKeyRange:K.IDBKeyRange||K.webkitIDBKeyRange}}catch{Dn={indexedDB:null,IDBKeyRange:null}}const xe=Ie;function Kt(t){let e=ie;try{ie=!0,pe.storagemutated.fire(t)}finally{ie=e}}Ae(xe,{...ht,delete:t=>new xe(t,{addons:[]}).delete(),exists:t=>new xe(t,{addons:[]}).open().then(e=>(e.close(),!0)).catch("NoSuchDatabaseError",()=>!1),getDatabaseNames(t){try{return function({indexedDB:e,IDBKeyRange:n}){return En(e)?Promise.resolve(e.databases()).then(r=>r.map(s=>s.name).filter(s=>s!==St)):xn(e,n).toCollection().primaryKeys()}(xe.dependencies).then(t)}catch{return $(new C.MissingAPI)}},defineClass:()=>function(t){W(this,t)},ignoreTransaction:t=>I.trans?je(I.transless,t):t(),vip:Sn,async:function(t){return function(){try{var e=In(t.apply(this,arguments));return e&&typeof e.then=="function"?e:E.resolve(e)}catch(n){return $(n)}}},spawn:function(t,e,n){try{var r=In(t.apply(n,e||[]));return r&&typeof r.then=="function"?r:E.resolve(r)}catch(s){return $(s)}},currentTransaction:{get:()=>I.trans||null},waitFor:function(t,e){const n=E.resolve(typeof t=="function"?xe.ignoreTransaction(t):t).timeout(e||6e4);return I.trans?I.trans.waitFor(n):n},Promise:E,debug:{get:()=>X,set:t=>{er(t,t==="dexie"?()=>!0:br)}},derive:De,extend:W,props:Ae,override:zn,Events:Ze,on:pe,liveQuery:pa,extendObservabilitySet:jr,getByKeyPath:te,setByKeyPath:J,delByKeyPath:function(t,e){typeof e=="string"?J(t,e,void 0):"length"in e&&[].map.call(e,function(n){J(t,n,void 0)})},shallowClone:Qn,deepClone:He,getObjectDiff:Pn,cmp:V,asap:Yn,minKey:un,addons:[],connections:Xe,errnames:Gt,dependencies:Dn,semVer:gr,version:gr.split(".").map(t=>parseInt(t)).reduce((t,e,n)=>t+e/Math.pow(10,2*n))}),xe.maxKey=rt(xe.dependencies.IDBKeyRange),typeof dispatchEvent<"u"&&typeof addEventListener<"u"&&(pe(nt,t=>{if(!ie){let e;Et?(e=document.createEvent("CustomEvent"),e.initCustomEvent(he,!0,!0,t)):e=new CustomEvent(he,{detail:t}),ie=!0,dispatchEvent(e),ie=!1}}),addEventListener(he,({detail:t})=>{ie||Kt(t)}));let ie=!1;if(typeof BroadcastChannel<"u"){const t=new BroadcastChannel(he);typeof t.unref=="function"&&t.unref(),pe(nt,e=>{ie||t.postMessage(e)}),t.onmessage=e=>{e.data&&Kt(e.data)}}else if(typeof self<"u"&&typeof navigator<"u"){pe(nt,e=>{try{ie||(typeof localStorage<"u"&&localStorage.setItem(he,JSON.stringify({trig:Math.random(),changedParts:e})),typeof self.clients=="object"&&[...self.clients.matchAll({includeUncontrolled:!0})].forEach(n=>n.postMessage({type:he,changedParts:e})))}catch{}}),typeof addEventListener<"u"&&addEventListener("storage",e=>{if(e.key===he){const n=JSON.parse(e.newValue);n&&Kt(n.changedParts)}});const t=self.document&&navigator.serviceWorker;t&&t.addEventListener("message",function({data:e}){e&&e.type===he&&Kt(e.changedParts)})}E.rejectionMapper=function(t,e){if(!t||t instanceof Oe||t instanceof TypeError||t instanceof SyntaxError||!t.name||!sr[t.name])return t;var n=new sr[t.name](e||t.message,t);return"stack"in t&&ee(n,"stack",{get:function(){return this.inner.stack}}),n},er(X,br);const Nr=async(t,e)=>{const n=performance.now();try{await t()}finally{const r=performance.now()-n;let s=Un[e];s||(s=qn(e)),s.report(r/1e3)}},Br=(t,e)=>{const n=performance.now();try{t()}finally{const r=performance.now()-n;let s=Un[e];s||(s=qn(e)),s.report(r/1e3)}},fa=30,ma=3e4;let it=0;const $r=()=>{H.setItem("sprig.disableReplayRecording","disabled")},Ee=()=>!!H.getItem("sprig.disableReplayRecording"),ya=["did not allow mutations","called in an invalid security context"],ga=t=>{if(!t)return!0;for(const e of ya)if(t.toLowerCase().includes(e))return!1;return!0},va=(t,e,{reportError:n=!0,extraInfo:r})=>{Ee()||e instanceof Error&&($r(),ga(e?.message)&&(n&&window.UserLeap.reportError(t,e,r),_a()))},ba=async(t,e,{reportError:n}={reportError:!0})=>{var r;let s;try{if(n&&(r=window.navigator.storage)!=null&&r.estimate){const{quota:a,usage:i}=await window.navigator.storage.estimate();s={availableSpaceInMB:a&&i?(a-i)/(1024*1024):void 0,quota:a,usage:i}}}catch(a){window.UserLeap.reportError("Error getting storage estimate",a,{originalMessage:t,originalError:e})}va(t,e,{reportError:n,extraInfo:s})},wa=()=>{const t=H.getItem("sprig.sessionId");if(t)return P(`Found saved session id: ${t}`),H.removeItem("sprig.sessionId"),t;const e=Ue();return P(`Generating new uuid: ${e}`),e},q=wa();window.addEventListener("beforeunload",()=>{P(`Before page unload saving session id: ${q}`),H.setItem("sprig.sessionId",q)});const _a=async()=>{A.transaction("rw",A.events,A.chunkUploads,A.pendingCaptures,()=>{A.events.clear(),A.chunkUploads.clear(),A.pendingCaptures.clear()}).catch(()=>{})},Tn=(t,e,n=()=>!0)=>A.table(e).where("timestamp").below(t).and(n).delete(),ka=async(t,e)=>{let n=[];return await Nr(async()=>{n=await A.events.where("[sessionId+timestamp]").between([q,t],[q,e??Date.now()]).toArray()},"sdk_replay_get_events_between_seconds"),n},xa=(t,e,n)=>{const r=new Date,s=r.setMinutes(r.getMinutes()+(n??fa));return A.events.where("[sessionId+timestamp]").between([q,t],[q,e]).modify({expiredAt:s})},Ea=t=>A.chunkUploads.add({...t,sessionId:t.sessionId??q}),Sa=(t,e)=>A.chunkUploads.update(t,{data:null,etag:e,status:"UploadComplete"}),Ia=({status:t,uploadId:e})=>e?A.chunkUploads.where({uploadId:e,status:t}).toArray():A.chunkUploads.where({sessionId:q,status:t}).toArray(),Pa=t=>A.chunkUploads.where({uploadId:t,status:"UploadComplete"}).toArray(),Ca=t=>A.chunkUploads.where({uploadId:t,status:"UploadComplete"}).delete(),Aa=t=>A.pendingCaptures.add({...t,sessionId:t.sessionId??q,canUpload:!1}),Mr=async t=>{let e=await A.pendingCaptures.where("sessionId").equals(q).toArray();return t.beforePresent&&(e=e.filter(n=>n.targetTimestamp<Date.now())),t.isHeatmap&&(e=e.filter(n=>n.captureParams.isHeatmap??!1)),e},Da=()=>A.pendingCaptures.where("sessionId").equals(q).toArray(),Ta=t=>A.pendingCaptures.where("sessionId").equals(q).and(e=>e.captureParams.responseGroupId===t).modify({canUpload:!0}),Oa=async t=>{var e;if((e=window.navigator.storage)!=null&&e.estimate){const{quota:n,usage:r}=await window.navigator.storage.estimate();if(n&&r&&(n-r)/1073741824<t)return!1}return!0},Fr=async t=>{if(parseInt(H.getItem("sprig.pendingCount")??"0")===0)return;const e=Date.now();return oe(async()=>{await A.pendingCaptures.where("sessionId").equals(q).and(n=>n.captureParams.isHeatmap??!1).and(n=>t?t.includes(n.uuid):!0).modify(n=>{n.targetTimestamp=e,n.captureParams.triggerTimestamp=e,n.captureParams.replayParams.replayDurationSeconds=Math.floor((e-n.timestamp)/1e3)})},"Error marking pending heatmaps ready")},Ka=async()=>{const t=(await Mr({isHeatmap:!0})).map(n=>({eventId:n.captureParams.eventId,uuid:n.uuid})),e=[];t.forEach(({eventId:n,uuid:r})=>{gs(n)||e.push(r)}),e.length&&Fr(e)},Ra=t=>{if(t>1){it=0;return}const e=Date.now();if(!it){it=e;return}e-it>=ma&&(Fr(),it=0)};class ja extends Ie{constructor(){super("replayStorage",{autoOpen:!1}),Fe(this,"events"),Fe(this,"chunkUploads"),Fe(this,"pendingCaptures")}}const A=new ja;A.version(1).stores({events:"uuid, timestamp, [sessionId+timestamp]",chunkUploads:"uuid, timestamp, [sessionId+status], [uploadId+status], [sessionId+status+uploadId]",pendingCaptures:"uuid, timestamp, [sessionId+targetTimestamp]"}),A.open().catch(t=>{Ln(`Error opening replay storage: ${JSON.stringify(t)}`),$r()});const Na=t=>{if(t instanceof Attr)return null;let e=1;for(let n=t.previousSibling;n;n=n.previousSibling)n.nodeName===t.nodeName&&++e;return e},Ur=t=>{if(t===null)return"";const e=[];if(t instanceof Document)return"/";for(let n=t;n&&!(n instanceof Document)&&n!==null;n=n instanceof Attr?n.ownerElement:n.parentElement){const r=e[e.length]={name:void 0,position:null};switch(n.nodeType){case Node.TEXT_NODE:r.name="text()";break;case Node.ATTRIBUTE_NODE:r.name="@"+n.nodeName;break;case Node.PROCESSING_INSTRUCTION_NODE:r.name="processing-instruction()";break;case Node.COMMENT_NODE:r.name="comment()";break;case Node.ELEMENT_NODE:r.name=n.nodeName;break}r.position=Na(n)}return"/"+e.reverse().map(n=>n.position!==null?`/${n.name}[${n.position}]`:`/${n.name}`).join("")},fe={capture:!0,passive:!0},Ba=["a","button","input","option","li","link"],$a=["Escape","Enter","Backspace","F5","Tab"];let Rt=!1;const Ma=["label","type","role","title","placeholder","errormessage","valuetext","href"],qr="aria-",Fa=t=>{if(!t.tagName)return"No tagName";const e=t.getAttribute("type");return e?`${e} ${t.tagName.toLowerCase()}`:t.tagName.toLowerCase()},Lr=t=>{var e;if(((e=t.tagName)==null?void 0:e.toLowerCase())==="html")return{element:"html"};const n=t.textContent,r=n?{text:n}:{};r.element=Fa(t);for(const s of t.attributes){let a=s.name;const i=s.value;a.startsWith(qr)&&(a=a.substring(qr.length)),Ma.includes(a)&&(r[a]=i)}return r},Ua=t=>{var e;if(!t)return{};const n={...Lr(t)},r=t.parentElement;if(r&&Ba.includes((e=r.tagName)==null?void 0:e.toLowerCase())){const s=Lr(r);Object.assign(n,s)}return n},Hr=(t,e)=>{var n;cs({x:e.x,y:e.y,type:t,elementAttributes:Ua(e.target),windowHeight:window.innerHeight,windowWidth:window.innerWidth,...e.target instanceof HTMLElement?{rect:(n=e.target)==null?void 0:n.getBoundingClientRect(),xPath:Ur(e.target)}:{}})},qa=t=>e=>Hr(t,e),Wr=t=>{$a.includes(t.key)&&ps({key:t.key})},La=()=>{window.performance.getEntriesByType("navigation").map(t=>t.type).includes("reload")&&ds({url:window.location.href,currentPageTitle:document.title})},Ha=()=>{window.performance.getEntriesByType("navigation").map(t=>t.type).includes("back_forward")&&hs({curUrl:window.location.href,fromUrl:document.referrer,currentPageTitle:document.title})},Wa=(t,e)=>{let n;return r=>{clearTimeout(n),n=window.setTimeout(()=>t(r),e)}},Va=t=>{if(!(t.target instanceof HTMLElement||t.target instanceof Document))return;let e=t.target;"scrollTop"in e||(e=e.documentElement),fs({xPath:Ur(e),x:e.scrollLeft,y:e.scrollTop,elementAttributes:{targetScrollWidth:e.scrollWidth,targetClientWidth:e.clientWidth,targetScrollHeight:e.scrollHeight,targetClientHeight:e.clientHeight}})},Vr=Wa(Va,750),Gr=qa("left_click"),zr=t=>{t.button===2&&Hr("right_click",t)},Ga=()=>{Rt||(window.addEventListener("click",Gr,fe),window.addEventListener("mousedown",zr,fe),window.addEventListener("keydown",Wr,fe),window.addEventListener("scroll",Vr,fe),Rt=!0,La(),Ha())},za=()=>{Rt&&(window.removeEventListener("click",Gr,fe),window.removeEventListener("mousedown",zr,fe),window.removeEventListener("keydown",Wr,fe),window.removeEventListener("scroll",Vr,fe),Rt=!1)},Ya=async(t,e,n)=>new Promise((r,s)=>{const a=t.createElement("script");a.src=e,a.onload=r,a.onerror=s,n&&(a.nonce=n),t.head.appendChild(a)});let Yr=1,On=5e3,jt=6e4;const Ja=5,Jr=1e3,Qr=30,Nt=Qr+Ja;let Kn,Rn,Xr,Zr=Date.now(),$e=!1,Bt;const es={},Qa=async({viewDocument:t,maxReplayDurationSeconds:e,replayNonce:n,maxInflightRequests:r=2,replaySettings:s,teardownAfter:a=!1})=>{$e||(a&&H.setItem("sprig.teardownAfterCapture","true"),await oe(async()=>{if(Ee()){P("Not initializing replay because recording is disabled");return}if(!e){P("Not initializing replay because config didn't specify maxReplayDurationSeconds");return}if(s!=null&&s.minAvailableGb&&(Yr=s.minAvailableGb),!await Oa(Yr)){Hn("Minimum storage not available");return}if(P("Initializing replay"),s!=null&&s.minDuration&&(On=s.minDuration),s!=null&&s.batchDuration&&(jt=s.batchDuration),_s(r),si(),ei(e+Nt,30*60,e+Nt),ti(),!window.rrwebRecord){P("Loading recording script");const u=window.UserLeap.replayLibraryURL??"https://cdn.sprig.com/dependencies/record-2.0.0-alpha.6.min.js";await Ya(t,u,n),P("Recording script finished loading")}const i=window.rrwebRecord;if(!i){Hn("Record script failed to set global function");return}let o=!0,l=0;Bt=i({checkoutEveryNms:Qr*1e3,sampling:{input:"last",scroll:250,media:800},emit:(u,d)=>{if(Ee())return;if(Zr=Date.now(),d&&u.type===ut.Meta)l=performance.now();else if(d&&l&&u.type===ut.FullSnapshot){const h=performance.now()-l;vs("sdk_replay_snapshot_seconds",h/1e3)}const c=o||!!d&&u.type===ut.Meta;o=!1,Xa({uuid:Ue(),event:JSON.stringify(u),isValidStart:c,timestamp:Date.now()})},...s}),$e=!0,Rn||(Rn=window.setInterval(()=>{Date.now()-Zr>Jr&&Q("Sprig_Noop",{})},Jr)),lt.on("survey.complete",u=>{us({id:u,userAgent:window.navigator.userAgent})}),Ga()},"Error initializing replay"))};let me=H.getItem("sprig.pendingCount"),jn=!!H.getItem("sprig.isCapturingHeatmap"),Nn=!1,Bn=[];const Xa=t=>{var e,n,r,s;if((e=t.event)!=null&&e.includes("Sprig_Scroll")){const a=(s=(r=(n=JSON.parse(t.event))==null?void 0:n.data)==null?void 0:r.payload)==null?void 0:s.xPath;if(!a)return;const i=Ue();es[a]=i,t.uuid=i}Bn.push(t),Nn||Za()},ts=t=>{const e=t.map(n=>({...n,sessionId:n.sessionId??q}));if(jn&&Ra(e.length),e.length!==0)return A.transaction("rw",A.events,()=>{A.events.bulkAdd(e)}).catch(n=>{Se("Error storing replay events",n)})},Za=()=>{Nn=!0,setTimeout(async()=>{if(Ee())return;const t=Bn;Bn=[],Nn=!1,Br(async()=>{await ts(t)},"sdk_replay_add_event_batch_seconds")},500)},ei=(t=6*60,e=30*60,n=4*60)=>{Kn=window.setInterval(()=>{const r=Date.now();Ee()||(ot(`Performing periodic replay data cleanup / Event Seconds ${t} / Chunk Seconds ${e} / Pending Capture Seconds ${n}`),Nr(()=>A.transaction("rw!",A.events,A.chunkUploads,A.pendingCaptures,()=>{Tn(r-t*1e3,"events",s=>s.expiredAt===void 0||s.expiredAt<r-t*1e3),Tn(r-e*1e3,"chunkUploads"),Tn(r-n*1e3,"pendingCaptures",s=>s.canUpload===void 0||s.canUpload===!1)}).catch(s=>{clearInterval(Kn),Se("Error deleting table rows",s)}),"sdk_replay_cleanup_seconds"),P("Cleanup complete"))},30*1e3)},ti=(t=5)=>{Xr=window.setInterval(async()=>{oe(async()=>{const e=parseInt(me??"0");if(e===0)return;const n=await Mr({beforePresent:!0});n!=null&&n.length&&(await Promise.all(n.map(async r=>(await A.pendingCaptures.delete(r.uuid),is(r.captureParams,r.canUpload)))),me=(e-n.length).toString(),H.setItem("sprig.pendingCount",me))},"Error initiating pending captures")},t*1e3)},ni=async(t,e,n,r,s)=>{const a=Math.min(t+s,n),i=`from: ${new Date(t).toLocaleTimeString()} to ${new Date(a).toLocaleTimeString()}`;P(`Getting event batch ${i}`);const o=await ka(t,a);if(!(o!=null&&o.length))return P(`No events found ${i}`),{validStartFound:r,events:[]};if(!r){P(`Searching for valid start in ${o.length} events ${i}`);let l=-1;if(o?.forEach((d,c)=>{if(!d.isValidStart)return;const h=d.timestamp<=e;(l<0||h)&&(l=c)}),l<0)return P(`No valid start found in ${o.length} events ${i}`),{validStartFound:r,events:[]};const u=o[l].timestamp;return P(`Found valid start at: ${new Date(u).toLocaleTimeString()} in events ${i}`),{validStartFound:!0,events:o?.slice(l)}}return{validStartFound:r,events:o}},ri=(t,e,n)=>{const r=t.length,s=e*1024*1024,a=Math.ceil(r/n),i=Math.max(s,a);P(`Total file bytes: ${r} / target chunk size: ${i}`);const o=[];let l=0;for(;l<r;)o.push(t.slice(l,l+i)),l+=i;return o},ns=t=>Promise.all(t.map(async e=>{const n=await ks(e);return await Sa(e.uuid,n),e.uploadId})),rs=async t=>{P(`Marking upload complete if finished: ${t}`);const e=await Pa(t);if(!(e!=null&&e.length)){P(`No finished chunks found for upload: ${t}`);return}const n=e.reduce((a,i)=>(a.find(o=>o.chunkIndex===i.chunkIndex)||a.push(i),a),[]);n.sort((a,i)=>a.chunkIndex-i.chunkIndex);const r=n.map(a=>({ETag:a.etag,PartNumber:a.chunkIndex})).filter(a=>a.ETag!==null),s=n[0];await Vn({apiUrl:s.apiUrl,surveyId:s.surveyId,uploadId:t,responseGroupUuid:s.responseGroupId,etags:r,headers:s.completeUploadHeaders,replayDuration:s.replayDuration}),P(`Cleaning up chunks for ${t}`),await Ca(t),P(`Done cleaning up chunks for ${t}`)},si=async()=>{oe(async()=>{const t=await Ia({status:"ReadyForUpload"});if(!(t!=null&&t.length))return;const e=await ns(t);P(`Finished uploading unfinished chunks for ${e}`),e!=null&&e.length&&await Promise.all(e.map(n=>{if(n)return rs(n)}))},"Error uploading unfinished chunks")},ai=async(t,e)=>{await ns(e),P(`Done uploading chunks for uploads: ${t.join(",")}`),await Promise.all(t.map(n=>rs(n)))},ii=t=>{let e=0;t.forEach(s=>{e+=s.length});const n=new Uint8Array(e);let r=0;return t.forEach(s=>{n.set(s,r),r+=s.length}),n},ss=async(t,e,n)=>{const r=new TextEncoder;let s=null,a=null,i=null,o=!1,l=!1,[u,d]=[0,0];const c=t-Nt*1e3,h=[];let p=[];P(`Getting events between ${new Date(t).toLocaleTimeString()} and ${new Date(e).toLocaleTimeString()}`),P(`Using batch duration: ${jt}ms`);for(let m=c;m<e;m+=jt){if({validStartFound:l,events:p}=await ni(m,t,e,l,jt),!(p!=null&&p.length)){P("No events found");continue}u===0&&(u=p[0].timestamp),d=p[p.length-1].timestamp,P(`Last event time in batch: ${new Date(d).toLocaleTimeString()}`);const v=`${o?",":"["}${p.map(f=>f.event).join(",")}`,g=r.encode(v);n&&a===null&&(ot("Attempting compression"),i=new window.CompressionStream("gzip"),a=i.writable.getWriter()),Br(()=>{n&&a?a.write(g):h.push(g)},"sdk_replay_compression_seconds"),o=!0}if(d-u<On)return P(`Replay duration is shorter than minimum of ${On}ms / Start:${u} / End:${d}`),null;const y=r.encode("]");return ot("Writing final close brace"),a&&i?(a.write(y),a.close(),s=new Uint8Array(await new Response(i.readable).arrayBuffer())):(h.push(y),s=ii(h)),P("Finished generating file data"),s},oi=async(t,e)=>{const n=window.CompressionStream!==void 0;let r=null;const s=e??Date.now(),a=s-t;try{r=await ss(a,s,n)}catch(i){i instanceof Error&&window.UserLeap.reportError("Error compressing replay",i),n&&oe(async()=>{await ss(a,s,!1)},"fileData fallback failed")}return r},as=async t=>{const{surveyId:e,responseGroupId:n,visitorId:r,apiUrl:s,completeUploadHeaders:a,replayParams:i,triggerTimestamp:o}=t,l=await oi(i.replayDurationSeconds*1e3,o);if(l!=null&&l.length)P(`Found file data for survey: ${e}`);else{P(`File data is empty for survey: ${e}`);return}const u=ri(l,i.minimumChunkSizeMb,i.signedUrls.length);P(`Got ${u.length} chunks for survey: ${e}`);const d=await Promise.all(u.map(async(c,h)=>{const p=Ue(),y={apiUrl:s,chunkIndex:h+1,completeUploadHeaders:a,etag:null,responseGroupId:n,status:"ReadyForUpload",surveyId:e,timestamp:o,totalChunks:u.length,data:c,uploadId:i.uploadId,uploadUrl:i.signedUrls[h].url,uuid:p,visitorId:r};return P(`Recording chunk upload: ${JSON.stringify({index:y.chunkIndex,surveyId:y.surveyId,uploadId:y.uploadId,size:c.length,id:p},null,2)}`),await Ea(y),P(`Done creating chunk upload: ${p}`),y}));P(`All chunk records created. Beginning upload for survey: ${e}`),await ai([i.uploadId],d)},is=async(t,e)=>{if(P(`Attempting replay capture: ${JSON.stringify({isStandalone:t.isStandalone,duration:t.replayParams.replayDurationSeconds,type:t.replayParams.replayDurationType,responseGroupId:t.responseGroupId,surveyId:t.surveyId,triggerTimestamp:t.triggerTimestamp,visitorId:t.visitorId},null,2)}`),Ee()){P(`Replay recording is disabled: ${t.surveyId}`);return}P(`Replay recording enabled: ${t.surveyId}`);const{isHeatmap:n,isStandalone:r,replayParams:s,triggerTimestamp:a,responseGroupId:i}=t,o=async()=>{setTimeout(()=>lt.removeListener(Mt.QuestionAnswered,o),0),oe(async()=>{s.replayDurationType==="before"?await as(t):await Ta(i)},"Error in schedule/capture callback")};oe(async()=>{if(s.replayDurationType==="after"||s.replayDurationType==="beforeAndAfter"){!r&&!n&&(P("Attaching QuestionAnswered listener for non-standalone replay"),lt.on(Mt.QuestionAnswered,o)),P(`Scheduling capture for replay of type: ${s.replayDurationType}`),await ls(t);return}if(r||n||e)P(`Proceeding to capture replay for survey: ${t.surveyId} / standalone? ${r} / canUpload? ${e}`),await as(t),n&&li();else{const l=Nt+s.replayDurationSeconds,u=a-l*1e3,d=a;P(`Setting expiry minutes to ${s.expirationTimeLimitMinutes} for events from ${new Date(u).toLocaleTimeString()} to ${new Date(d).toLocaleTimeString()}`),await xa(u,d,s.expirationTimeLimitMinutes),P("Attaching QuestionAnswered listener"),lt.on(Mt.QuestionAnswered,o)}},"Error in scheduling/capturing replay")},li=async()=>{parseInt(me??"0")||(H.removeItem("sprig.isCapturingHeatmap"),jn=!1),H.getItem("sprig.teardownAfterCapture")&&($n(),os(),H.removeItem("sprig.teardownAfterCapture"))},os=()=>{if(Ee()){ot("Not clearing user data, replay is disabled");return}return A.transaction("rw",A.events,A.pendingCaptures,()=>{A.events.where("sessionId").equals(q).delete(),A.pendingCaptures.where("sessionId").equals(q).delete()}).catch(t=>{Se("Error clearing session event data",t)})},ls=async t=>{P(`Scheduling replay capture: ${JSON.stringify(t)}`);const{isHeatmap:e,surveyId:n}=t,r=await Da(),s=r?.filter(o=>o.captureParams.surveyId===n);if(s!=null&&s.length){P(`Pending capture exists for survey: ${n}`);return}e&&(ci(),jn=!0,H.setItem("sprig.isCapturingHeatmap","true"));const a={...t,replayParams:{...t.replayParams}};t.replayParams.replayDurationType==="beforeAndAfter"&&(a.replayParams.replayDurationSeconds*=2),a.replayParams.replayDurationType="before";const i=t.triggerTimestamp+t.replayParams.replayDurationSeconds*1e3;return a.triggerTimestamp=i,me=me?(parseInt(me)+1).toString():"1",H.setItem("sprig.pendingCount",me),Aa({uuid:Ue(),targetTimestamp:i,timestamp:Date.now(),captureParams:a})},Q=(t,e)=>{var n,r;if($e)try{(r=(n=window.rrwebRecord)==null?void 0:n.addCustomEvent)==null||r.call(n,t,e)}catch(s){Se("Error recording custom event",s)}},oe=async(t,e)=>{try{await t()}catch(n){Se(e,n)}},ui=t=>{t.description&&(t.description=Mn(t.description)),Q("Sprig_PageView",t)},ci=()=>{var t,e;if(!(!$e||!window.rrwebRecord))try{(e=(t=window.rrwebRecord)==null?void 0:t.takeFullSnapshot)==null||e.call(t,!0)}catch(n){Se("Error recording full snapshot",n)}},di=t=>{Q("Sprig_TrackEvent",t)},hi=t=>{Q("Sprig_ShowSurvey",t)},us=t=>{Q("Sprig_SubmitSurvey",t)},cs=t=>{var e;(e=t?.elementAttributes)!=null&&e.text&&(t.elementAttributes.text=Mn(t.elementAttributes.text)),Q("Sprig_Click",t)},ds=t=>{Q("Sprig_Refresh",t)},hs=t=>{t.currentPageTitle&&(t.currentPageTitle=Mn(t.currentPageTitle)),Q("Sprig_BackForward",t)},ps=t=>{Q("Sprig_Keystroke",t)},fs=async t=>{const{x:e,xPath:n,y:r}=t,s=es[n];s?oe(async()=>{var a,i,o,l;const u=await A.events.get(s);if(u!=null&&u.event){const d=JSON.parse(u.event),c=e>((i=(a=d.data)==null?void 0:a.payload)==null?void 0:i.x)||0,h=r>((l=(o=d.data)==null?void 0:o.payload)==null?void 0:l.y)||0;if(!(c||h))return;c&&(d.data.payload.x=e),h&&(d.data.payload.y=r),d.data.payload.elementAttributes=t.elementAttributes,u.event=JSON.stringify(d),A.events.put(u)}else Q("Sprig_Scroll",t)},"Error updating scroll event"):Q("Sprig_Scroll",t)},$n=()=>{Bt&&(Bt(),Bt=void 0),$e=!1,[Kn,Rn,Xr].forEach(t=>{t&&clearInterval(t)}),za()},Se=(t,e,{reportError:n}={reportError:!0})=>($n(),Ln(`${t} - ${JSON.stringify(e)}`),ba(t,e,{reportError:n})),pi=()=>$e,Mn=t=>t&&t.trim().substring(0,500).replace(/\s\s+/g," ").replace(/\r?\n|\r/g," ").substring(0,250),fi=async({surveyId:t,responseGroupUuid:e,eventDigest:n,headers:r})=>{if(!t||!e)return!1;const s=window.UserLeap._API_URL;try{const a=await Vn({surveyId:t,responseGroupUuid:e,eventDigest:n,apiUrl:s,headers:r},!0);return!(a!=null&&a.error)}catch(a){return console.warn("[Sprig] Error with completing session replay"),a instanceof Error&&window.UserLeap.reportError("completeSessionReplay",a),!1}},mi=Object.freeze(Object.defineProperty({__proto__:null,RecordBackForward:hs,RecordClick:cs,RecordEvent:di,RecordKeystroke:ps,RecordPageView:ui,RecordRefresh:ds,RecordScroll:fs,RecordSurveyComplete:us,RecordSurveyShown:hi,_completeSessionReplay:fi,batchStoreEvents:ts,checkPendingHeatmapsUrl:Ka,clearUserReplayData:os,disableRecording:Se,initializeReplay:Qa,isReplayRecording:pi,scheduleCapture:ls,scheduleOrCaptureReplay:is,teardownReplay:$n,tryReplayAction:oe},Symbol.toStringTag,{value:"Module"}));bs(mi);
|