((e,t)=>{"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).Dexie=t()})(this,function(){var B=function(e,t){return(B=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(e,t){e.__proto__=t}:function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}))(e,t)};var _=function(){return(_=Object.assign||function(e){for(var t,n=1,r=arguments.length;n{for(var t=qe.length;t;)if(qe[--t]._value===e._value)return qe.splice(t,1)})(t),n.resolve(r)}catch(e){n.reject(e)}finally{0==--Fe&&Ge(),--n.psd.ref||n.psd.finalize()}}function Ye(){at(s,function(){$e()&&Qe()})}function $e(){var e=Te;return Ie=Te=!1,e}function Qe(){var e,t,n;do{for(;0.",lt="String expected.",ft=[],ht="__dbnames",dt="readonly",pt="readwrite";function yt(e,t){return e?t?function(){return e.apply(this,arguments)&&t.apply(this,arguments)}:e:t}var vt={type:3,lower:-1/0,lowerOpen:!1,upper:[[]],upperOpen:!1};function mt(t){return"string"!=typeof t||/\./.test(t)?function(e){return e}:function(e){return void 0===e[t]&&t in e&&delete(e=ee(e))[t],e}}function bt(){throw k.Type("Entity instances must never be new:ed. Instances are generated by the framework bypassing the constructor.")}function j(e,t){try{var n=gt(e),r=gt(t);if(n!==r)return"Array"===n?1:"Array"===r?-1:"binary"===n?1:"binary"===r?-1:"string"===n?1:"string"===r?-1:"Date"===n?1:"Date"!==r?NaN:-1;switch(n){case"number":case"Date":case"string":return t{var t=o,n=e;if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}function o(){return null!==e&&e.apply(this,arguments)||this}return B(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r),Object.defineProperty(o.prototype,"db",{get:function(){return i},enumerable:!1,configurable:!0}),o.prototype.table=function(){return a},o})(r)),new Set),e=r.prototype;e;e=F(e))Object.getOwnPropertyNames(e).forEach(function(e){return o.add(e)});function t(e){if(!e)return e;var t,n=Object.create(r.prototype);for(t in e)if(!o.has(t))try{n[t]=e[t]}catch(e){}return n}return this.schema.readHook&&this.hook.reading.unsubscribe(this.schema.readHook),this.schema.readHook=t,this.hook("reading",t),r},r.prototype.defineClass=function(){return this.mapToClass(function(e){a(this,e)})},r.prototype.add=function(t,n){var r=this,e=this.schema.primKey,o=e.auto,i=e.keyPath,a=t;return i&&o&&(a=mt(i)(t)),this._trans("readwrite",function(e){return r.core.mutate({trans:e,type:"add",keys:null!=n?[n]:null,values:[a]})}).then(function(e){return e.numFailures?K.reject(e.failures[0]):e.lastResult}).then(function(e){if(i)try{b(t,i,e)}catch(e){}return e})},r.prototype.upsert=function(r,o){var i=this,a=this.schema.primKey.keyPath;return this._trans("readwrite",function(n){return i.core.get({trans:n,key:r}).then(function(t){var e=null!=t?t:{};return Ot(e,o),a&&b(e,a,r),i.core.mutate({trans:n,type:"put",values:[e],keys:[r],upsert:!0,updates:{keys:[r],changeSpecs:[o]}}).then(function(e){return e.numFailures?K.reject(e.failures[0]):!!t})})})},r.prototype.update=function(e,t){return"object"!=typeof e||x(e)?this.where(":id").equals(e).modify(t):void 0===(e=c(e,this.schema.primKey.keyPath))?w(new k.InvalidArgument("Given object does not contain its primary key")):this.where(":id").equals(e).modify(t)},r.prototype.put=function(t,n){var r=this,e=this.schema.primKey,o=e.auto,i=e.keyPath,a=t;return i&&o&&(a=mt(i)(t)),this._trans("readwrite",function(e){return r.core.mutate({trans:e,type:"put",values:[a],keys:null!=n?[n]:null})}).then(function(e){return e.numFailures?K.reject(e.failures[0]):e.lastResult}).then(function(e){if(i)try{b(t,i,e)}catch(e){}return e})},r.prototype.delete=function(t){var n=this;return this._trans("readwrite",function(e){return n.core.mutate({trans:e,type:"delete",keys:[t]}).then(function(e){return _t(n,[t],e)}).then(function(e){return e.numFailures?K.reject(e.failures[0]):void 0})})},r.prototype.clear=function(){var t=this;return this._trans("readwrite",function(e){return t.core.mutate({trans:e,type:"deleteRange",range:vt}).then(function(e){return _t(t,null,e)})}).then(function(e){return e.numFailures?K.reject(e.failures[0]):void 0})},r.prototype.bulkGet=function(t){var n=this;return this._trans("readonly",function(e){return n.core.getMany({keys:t,trans:e}).then(function(e){return e.map(function(e){return n.hook.reading.fire(e)})})})},r.prototype.bulkAdd=function(o,e,t){var i=this,a=Array.isArray(e)?e:void 0,u=(t=t||(a?void 0:e))?t.allKeys:void 0;return this._trans("readwrite",function(e){var t=i.schema.primKey,n=t.auto,t=t.keyPath;if(t&&a)throw new k.InvalidArgument("bulkAdd(): keys argument invalid on tables with inbound keys");if(a&&a.length!==o.length)throw new k.InvalidArgument("Arguments objects and keys must have the same length");var r=o.length,n=t&&n?o.map(mt(t)):o;return i.core.mutate({trans:e,type:"add",keys:a,values:n,wantResults:u}).then(function(e){var t=e.numFailures,n=e.failures;if(0===t)return u?e.results:e.lastResult;throw new he("".concat(i.name,".bulkAdd(): ").concat(t," of ").concat(r," operations failed"),n)})})},r.prototype.bulkPut=function(o,e,t){var i=this,a=Array.isArray(e)?e:void 0,u=(t=t||(a?void 0:e))?t.allKeys:void 0;return this._trans("readwrite",function(e){var t=i.schema.primKey,n=t.auto,t=t.keyPath;if(t&&a)throw new k.InvalidArgument("bulkPut(): keys argument invalid on tables with inbound keys");if(a&&a.length!==o.length)throw new k.InvalidArgument("Arguments objects and keys must have the same length");var r=o.length,n=t&&n?o.map(mt(t)):o;return i.core.mutate({trans:e,type:"put",keys:a,values:n,wantResults:u}).then(function(e){var t=e.numFailures,n=e.failures;if(0===t)return u?e.results:e.lastResult;throw new he("".concat(i.name,".bulkPut(): ").concat(t," of ").concat(r," operations failed"),n)})})},r.prototype.bulkUpdate=function(t){var h=this,n=this.core,r=t.map(function(e){return e.key}),o=t.map(function(e){return e.changes}),d=[];return this._trans("readwrite",function(e){return n.getMany({trans:e,keys:r,cache:"clone"}).then(function(c){var l=[],f=[],s=(t.forEach(function(e,t){var n=e.key,r=e.changes,o=c[t];if(o){for(var i=0,a=Object.keys(r);is+c&&h(s+w)})})}var d=St(k)&&k.limit===1/0&&("function"!=typeof x||_)&&{index:k.index,range:k.range};return h(0).then(function(){if(0{for(var a=Math.min(e.length,r.length),u=-1,s=0;s=c})).length?K.resolve():(e.forEach(function(u){t.push(function(){var t,n,r,o=h,e=u._cfg.dbschema,i=(vn(s,o,f),vn(s,e,f),h=s._dbSchema=e,fn(o,e)),a=(i.add.forEach(function(e){hn(f,e[0],e[1].primKey,e[1].indexes)}),i.change.forEach(function(e){if(e.recreate)throw new k.Upgrade("Not yet support for changing primary key");var t=f.objectStore(e.name);e.add.forEach(function(e){return pn(t,e)}),e.change.forEach(function(e){t.deleteIndex(e.name),pn(t,e)}),e.del.forEach(function(e){return t.deleteIndex(e)})}),u._cfg.contentUpgrade);if(a&&u._cfg.version>c)return on(s,f),l._memoizedTables={},t=G(e),i.del.forEach(function(e){t[e]=o[e]}),un(s,[s.Transaction.prototype]),an(s,[s.Transaction.prototype],O(t),t),l.schema=t,(n=ue(a))&&nt(),e=K.follow(function(){var e;(r=a(l))&&n&&(e=v.bind(null,null),r.then(e,e))}),r&&"function"==typeof r.then?K.resolve(r):e.then(function(){return r})}),t.push(function(e){var t,n,r=u._cfg.dbschema;t=r,n=e,[].slice.call(n.db.objectStoreNames).forEach(function(e){return null==t[e]&&n.db.deleteObjectStore(e)}),un(s,[s.Transaction.prototype]),an(s,[s.Transaction.prototype],s._storeNames,s._dbSchema),l.schema=s._dbSchema}),t.push(function(e){s.idbdb.objectStoreNames.contains("$meta")&&(Math.ceil(s.idbdb.version/10)===u._cfg.version?(s.idbdb.deleteObjectStore("$meta"),delete s._dbSchema.$meta,s._storeNames=s._storeNames.filter(function(e){return"$meta"!==e})):e.objectStore("$meta").put(u._cfg.version,"version"))})}),function e(){return t.length?K.resolve(t.shift()(l.idbtrans)).then(e):K.resolve()}().then(function(){dn(h,f)}))}).catch(u);var e,t;O(i).forEach(function(e){hn(o,e,i[e].primKey,i[e].indexes)}),on(n,o),K.follow(function(){return n.on.populate.fire(a)}).catch(u)})}function ln(e,r){dn(e._dbSchema,r),r.db.version%10!=0||r.objectStoreNames.contains("$meta")||r.db.createObjectStore("$meta").add(Math.ceil(r.db.version/10-1),"version");var t=yn(0,e.idbdb,r);vn(e,e._dbSchema,r);for(var n=0,o=fn(t,e._dbSchema).change;n{if(t.change.length||t.recreate)return console.warn("Unable to patch indexes of table ".concat(t.name," because it has changes on the type of index or primary key.")),{value:void 0};var n=r.objectStore(t.name);t.add.forEach(function(e){l&&console.debug("Dexie upgrade patch: Creating missing index ".concat(t.name,".").concat(e.src)),pn(n,e)})})(o[n]);if("object"==typeof i)return i.value}}function fn(e,t){var n,r={del:[],add:[],change:[]};for(n in e)t[n]||r.del.push(n);for(n in t){var o=e[n],i=t[n];if(o){var a={name:n,def:i,recreate:!1,del:[],add:[],change:[]};if(""+(o.primKey.keyPath||"")!=""+(i.primKey.keyPath||"")||o.primKey.auto!==i.primKey.auto)a.recreate=!0,r.change.push(a);else{var u=o.idxByName,s=i.idxByName,c=void 0;for(c in u)s[c]||a.del.push(c);for(c in s){var l=u[c],f=s[c];l?l.src!==f.src&&a.change.push(f):a.add.push(f)}(0Math.pow(2,62)?0:e.oldVersion,b=t<1,h.idbdb=f.result,y&&ln(h,m),cn(h,t/10,m,n))},n),f.onsuccess=E(function(){m=null;var e,t,n,r,o,i,a=h.idbdb=f.result,u=W(a.objectStoreNames);if(0d.limit?n.length=d.limit:e.length===d.limit&&n.length{if(void 0===e)return void 0!==t?-1:0;if(void 0===t)return 1;if(0===(e=j(e,t))){if(n&&r)return 0;if(n)return 1;if(r)return-1}return e})(e.lower,t.lower,e.lowerOpen,t.lowerOpen)<=0&&0<=((e,t,n,r)=>{if(void 0===e)return void 0!==t?1:0;if(void 0===t)return-1;if(0===(e=j(e,t))){if(n&&r)return 0;if(n)return-1;if(r)return 1}return e})(e.upper,t.upper,e.upperOpen,t.upperOpen)}function tr(n,r,o,e){n.subscribers.add(o),e.addEventListener("abort",function(){var e,t;n.subscribers.delete(o),0===n.subscribers.size&&(e=n,t=r,setTimeout(function(){0===e.subscribers.size&&ie(t,e)},3e3))})}var nr={stack:"dbcore",level:0,name:"Cache",create:function(k){var O=k.schema.name;return _(_({},k),{transaction:function(g,w,e){var _,t,x=k.transaction(g,w,e);return"readwrite"===w&&(e=(_=new AbortController).signal,x.addEventListener("abort",(t=function(b){return function(){if(_.abort(),"readwrite"===w){for(var t=new Set,e=0,n=g;e{var o=Tn["idb://".concat(e,"/").concat(t)];if(!o)return[];if(!(e=o.queries[n]))return[null,!1,o,null];var i=e[(r.query?r.query.index.name:null)||""];if(!i)return[null,!1,o,null];switch(n){case"query":var a=i.find(function(e){return e.req.limit===r.limit&&e.req.values===r.values&&Zn(e.req.query.range,r.query.range)});return a?[a,!0,o,i]:[i.find(function(e){return("limit"in e.req?e.req.limit:1/0)>=r.limit&&(!r.values||e.req.values)&&er(e.req.query.range,r.query.range)}),!1,o,i];case"count":a=i.find(function(e){return Zn(e.req.query.range,r.query.range)});return[a,!!a,o,i]}})(O,s,"query",t),u=a[0],r=a[2],i=a[3],u&&a[1]?u.obsSet=t.obsSet:(a=c.query(t).then(function(e){var t=e.result;if(u&&(u.res=t),o){for(var n=0,r=t.length;n{var t=$e();try{o&&nt();var n=y(h,e);return n=o?n.finally(v):n}finally{t&&Qe()}})(n={subscr:t,signal:i.signal,requery:l,querier:h,trans:null}),Promise.resolve(e).then(function(e){p=!0,d=e,a||n.signal.aborted||(u={},(e=>{for(var t in e)if(m(e,t))return;return 1})(s=t)||c||(Yt(zt,f),c=!0),st(function(){return!a&&r.next&&r.next(e)}))},function(e){p=!1,["DatabaseClosedError","AbortError"].includes(null==e?void 0:e.name)||a||st(function(){a||r.error&&r.error(e)})}))};return setTimeout(l,0),e});return e.hasValue=function(){return p},e.getValue=function(){return d},e}var sr=q;function cr(e){var t=fr;try{fr=!0,Yt.storagemutated.fire(e),Bn(e,!0)}finally{fr=t}}N(sr,_(_({},e),{delete:function(e){return new sr(e,{addons:[]}).delete()},exists:function(e){return new sr(e,{addons:[]}).open().then(function(e){return e.close(),!0}).catch("NoSuchDatabaseError",function(){return!1})},getDatabaseNames:function(e){try{return t=sr.dependencies,n=t.indexedDB,t=t.IDBKeyRange,(_n(n)?Promise.resolve(n.databases()).then(function(e){return e.map(function(e){return e.name}).filter(function(e){return e!==ht})}):wn(n,t).toCollection().primaryKeys()).then(e)}catch(e){return w(new k.MissingAPI)}var t,n},defineClass:function(){return function(e){a(this,e)}},ignoreTransaction:function(e){return P.trans?at(P.transless,e):e()},vip:xn,async:function(t){return function(){try{var e=Mn(t.apply(this,arguments));return e&&"function"==typeof e.then?e:K.resolve(e)}catch(e){return w(e)}}},spawn:function(e,t,n){try{var r=Mn(e.apply(n,t||[]));return r&&"function"==typeof r.then?r:K.resolve(r)}catch(e){return w(e)}},currentTransaction:{get:function(){return P.trans||null}},waitFor:function(e,t){e=K.resolve("function"==typeof e?sr.ignoreTransaction(e):e).timeout(t||6e4);return P.trans?P.trans.waitFor(e):e},Promise:K,debug:{get:function(){return l},set:function(e){Oe(e)}},derive:U,extend:a,props:N,override:Y,Events:Kt,on:Yt,liveQuery:ur,extendObservabilitySet:An,getByKeyPath:c,setByKeyPath:b,delByKeyPath:function(t,e){"string"==typeof e?b(t,e,void 0):"length"in e&&[].map.call(e,function(e){b(t,e,void 0)})},shallowClone:G,deepClone:ee,getObjectDiff:Un,cmp:j,asap:Q,minKey:-1/0,addons:[],connections:ft,errnames:de,dependencies:or,cache:Tn,semVer:"4.3.0",version:"4.3.0".split(".").map(function(e){return parseInt(e)}).reduce(function(e,t,n){return e+t/Math.pow(10,2*n)})})),sr.maxKey=Ht(sr.dependencies.IDBKeyRange),"undefined"!=typeof dispatchEvent&&"undefined"!=typeof addEventListener&&(Yt(zt,function(e){fr||(e=new CustomEvent(Wt,{detail:e}),fr=!0,dispatchEvent(e),fr=!1)}),addEventListener(Wt,function(e){e=e.detail;fr||cr(e)}));var lr,fr=!1,hr=function(){};return"undefined"!=typeof BroadcastChannel&&((hr=function(){(lr=new BroadcastChannel(Wt)).onmessage=function(e){return e.data&&cr(e.data)}})(),"function"==typeof lr.unref&&lr.unref(),Yt(zt,function(e){fr||lr.postMessage(e)})),"undefined"!=typeof addEventListener&&(addEventListener("pagehide",function(e){if(!q.disableBfCache&&e.persisted){l&&console.debug("Dexie: handling persisted pagehide"),null!=lr&&lr.close();for(var t=0,n=ft;t