Files
obsidian-livesync/pouchdb-browser-webpack/dist/pouchdb-browser.js
vorotamoroz e2da4ec454 # Fixed
- Illegible coloring of the Diff dialog.

# Implemented
- On-the-fly encryption and decryption in replication.
- Text splitting algorithms updated
(use a bit more memory (which is saved by On-the-fly enc-dec), but faster than old algorithms.)
- Garbage collector is now decent and memory saving.

# Internal things
- Refactored so much.
2022-06-09 17:44:08 +09:00

1 line
168 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
var e={105:e=>{e.exports=function(e){return function(){var t=arguments.length;if(t){for(var n=[],r=-1;++r<t;)n[r]=arguments[r];return e.call(this,n)}return e.call(this,[])}}},187:e=>{var t,n="object"==typeof Reflect?Reflect:null,r=n&&"function"==typeof n.apply?n.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};t=n&&"function"==typeof n.ownKeys?n.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var i=Number.isNaN||function(e){return e!=e};function o(){o.init.call(this)}e.exports=o,e.exports.once=function(e,t){return new Promise((function(n,r){function i(n){e.removeListener(t,o),r(n)}function o(){"function"==typeof e.removeListener&&e.removeListener("error",i),n([].slice.call(arguments))}v(e,t,o,{once:!0}),"error"!==t&&function(e,t,n){"function"==typeof e.on&&v(e,"error",t,{once:!0})}(e,i)}))},o.EventEmitter=o,o.prototype._events=void 0,o.prototype._eventsCount=0,o.prototype._maxListeners=void 0;var s=10;function a(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function u(e){return void 0===e._maxListeners?o.defaultMaxListeners:e._maxListeners}function c(e,t,n,r){var i,o,s,c;if(a(n),void 0===(o=e._events)?(o=e._events=Object.create(null),e._eventsCount=0):(void 0!==o.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),o=e._events),s=o[t]),void 0===s)s=o[t]=n,++e._eventsCount;else if("function"==typeof s?s=o[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),(i=u(e))>0&&s.length>i&&!s.warned){s.warned=!0;var f=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");f.name="MaxListenersExceededWarning",f.emitter=e,f.type=t,f.count=s.length,c=f,console&&console.warn&&console.warn(c)}return e}function f(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function l(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=f.bind(r);return i.listener=n,r.wrapFn=i,i}function d(e,t,n){var r=e._events;if(void 0===r)return[];var i=r[t];return void 0===i?[]:"function"==typeof i?n?[i.listener||i]:[i]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(i):p(i,i.length)}function h(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function p(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function v(e,t,n,r){if("function"==typeof e.on)r.once?e.once(t,n):e.on(t,n);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,(function i(o){r.once&&e.removeEventListener(t,i),n(o)}))}}Object.defineProperty(o,"defaultMaxListeners",{enumerable:!0,get:function(){return s},set:function(e){if("number"!=typeof e||e<0||i(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");s=e}}),o.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},o.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||i(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},o.prototype.getMaxListeners=function(){return u(this)},o.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var i="error"===e,o=this._events;if(void 0!==o)i=i&&void 0===o.error;else if(!i)return!1;if(i){var s;if(t.length>0&&(s=t[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var u=o[e];if(void 0===u)return!1;if("function"==typeof u)r(u,this,t);else{var c=u.length,f=p(u,c);for(n=0;n<c;++n)r(f[n],this,t)}return!0},o.prototype.addListener=function(e,t){return c(this,e,t,!1)},o.prototype.on=o.prototype.addListener,o.prototype.prependListener=function(e,t){return c(this,e,t,!0)},o.prototype.once=function(e,t){return a(t),this.on(e,l(this,e,t)),this},o.prototype.prependOnceListener=function(e,t){return a(t),this.prependListener(e,l(this,e,t)),this},o.prototype.removeListener=function(e,t){var n,r,i,o,s;if(a(t),void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0==--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,o=n.length-1;o>=0;o--)if(n[o]===t||n[o].listener===t){s=n[o].listener,i=o;break}if(i<0)return this;0===i?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,i),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,s||t)}return this},o.prototype.off=o.prototype.removeListener,o.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0==--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var i,o=Object.keys(n);for(r=0;r<o.length;++r)"removeListener"!==(i=o[r])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},o.prototype.listeners=function(e){return d(this,e,!0)},o.prototype.rawListeners=function(e){return d(this,e,!1)},o.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):h.call(e,t)},o.prototype.listenerCount=h,o.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]}},624:(e,t,n)=>{var r,i,o,s=[n(525),n(785),n(291),n(709),n(506),n(176)],a=-1,u=[],c=!1;function f(){r&&i&&(r=!1,i.length?u=i.concat(u):a=-1,u.length&&l())}function l(){if(!r){c=!1,r=!0;for(var e=u.length,t=setTimeout(f);e;){for(i=u,u=[];i&&++a<e;)i[a].run();a=-1,e=u.length}i=null,a=-1,r=!1,clearTimeout(t)}}for(var d=-1,h=s.length;++d<h;)if(s[d]&&s[d].test&&s[d].test()){o=s[d].install(l);break}function p(e,t){this.fun=e,this.array=t}p.prototype.run=function(){var e=this.fun,t=this.array;switch(t.length){case 0:return e();case 1:return e(t[0]);case 2:return e(t[0],t[1]);case 3:return e(t[0],t[1],t[2]);default:return e.apply(null,t)}},e.exports=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];u.push(new p(e,t)),c||r||(c=!0,o())}},709:(e,t,n)=>{t.test=function(){return!n.g.setImmediate&&void 0!==n.g.MessageChannel},t.install=function(e){var t=new n.g.MessageChannel;return t.port1.onmessage=e,function(){t.port2.postMessage(0)}}},291:(e,t,n)=>{var r=n.g.MutationObserver||n.g.WebKitMutationObserver;t.test=function(){return r},t.install=function(e){var t=0,i=new r(e),o=n.g.document.createTextNode("");return i.observe(o,{characterData:!0}),function(){o.data=t=++t%2}}},785:(e,t,n)=>{t.test=function(){return"function"==typeof n.g.queueMicrotask},t.install=function(e){return function(){n.g.queueMicrotask(e)}}},506:(e,t,n)=>{t.test=function(){return"document"in n.g&&"onreadystatechange"in n.g.document.createElement("script")},t.install=function(e){return function(){var t=n.g.document.createElement("script");return t.onreadystatechange=function(){e(),t.onreadystatechange=null,t.parentNode.removeChild(t),t=null},n.g.document.documentElement.appendChild(t),e}}},176:(e,t)=>{t.test=function(){return!0},t.install=function(e){return function(){setTimeout(e,0)}}},717:e=>{"function"==typeof Object.create?e.exports=function(e,t){t&&(e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}))}:e.exports=function(e,t){if(t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}}},198:(e,t,n)=>{n.d(t,{Z:()=>fr});var r,i,o=n(624),s=n.n(o),a=n(586),u=n(322),c=n.n(u),f=n(684),l=n(105),d=n.n(l),h=n(717),p=n.n(h),v=n(187),y=n.n(v);function g(e){return"$"+e}function _(e){return e.substring(1)}function m(){this._store={}}function b(e){if(this._store=new m,e&&Array.isArray(e))for(var t=0,n=e.length;t<n;t++)this.add(e[t])}m.prototype.get=function(e){var t=g(e);return this._store[t]},m.prototype.set=function(e,t){var n=g(e);return this._store[n]=t,!0},m.prototype.has=function(e){return g(e)in this._store},m.prototype.keys=function(){return Object.keys(this._store).map((e=>_(e)))},m.prototype.delete=function(e){var t=g(e),n=t in this._store;return delete this._store[t],n},m.prototype.forEach=function(e){for(var t=Object.keys(this._store),n=0,r=t.length;n<r;n++){var i=t[n];e(this._store[i],i=_(i))}},Object.defineProperty(m.prototype,"size",{get:function(){return Object.keys(this._store).length}}),b.prototype.add=function(e){return this._store.set(e,!0)},b.prototype.has=function(e){return this._store.has(e)},b.prototype.forEach=function(e){this._store.forEach((function(t,n){e(n)}))},Object.defineProperty(b.prototype,"size",{get:function(){return this._store.size}}),function(){if("undefined"==typeof Symbol||"undefined"==typeof Map||"undefined"==typeof Set)return!1;var e=Object.getOwnPropertyDescriptor(Map,Symbol.species);return e&&"get"in e&&Map[Symbol.species]===Map}()?(r=Set,i=Map):(r=b,i=m);var w,k=Function.prototype.toString,j=k.call(Object);function O(e){var t,n,r;if(!e||"object"!=typeof e)return e;if(Array.isArray(e)){for(t=[],n=0,r=e.length;n<r;n++)t[n]=O(e[n]);return t}if(e instanceof Date&&isFinite(e))return e.toISOString();if(function(e){return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Blob&&e instanceof Blob}(e))return function(e){if(e instanceof ArrayBuffer)return function(e){if("function"==typeof e.slice)return e.slice(0);var t=new ArrayBuffer(e.byteLength),n=new Uint8Array(t),r=new Uint8Array(e);return n.set(r),t}(e);var t=e.size,n=e.type;return"function"==typeof e.slice?e.slice(0,t,n):e.webkitSlice(0,t,n)}(e);if(!function(e){var t=Object.getPrototypeOf(e);if(null===t)return!0;var n=t.constructor;return"function"==typeof n&&n instanceof n&&k.call(n)==j}(e))return e;for(n in t={},e)if(Object.prototype.hasOwnProperty.call(e,n)){var i=O(e[n]);void 0!==i&&(t[n]=i)}return t}function $(e){var t=!1;return d()((function(n){if(t)throw new Error("once called more than once");t=!0,e.apply(this,n)}))}function x(e){return d()((function(t){t=O(t);var n=this,r="function"==typeof t[t.length-1]&&t.pop(),i=new Promise((function(r,i){var o;try{var s=$((function(e,t){e?i(e):r(t)}));t.push(s),(o=e.apply(n,t))&&"function"==typeof o.then&&r(o)}catch(e){i(e)}}));return r&&i.then((function(e){r(null,e)}),r),i}))}function q(e,t){return x(d()((function(n){if(this._closed)return Promise.reject(new Error("database is closed"));if(this._destroyed)return Promise.reject(new Error("database is destroyed"));var r=this;return function(e,t,n){if(e.constructor.listeners("debug").length){for(var r=["api",e.name,t],i=0;i<n.length-1;i++)r.push(n[i]);e.constructor.emit("debug",r);var o=n[n.length-1];n[n.length-1]=function(n,r){var i=["api",e.name,t];i=i.concat(n?["error",n]:["success",r]),e.constructor.emit("debug",i),o(n,r)}}}(r,e,n),this.taskqueue.isReady?t.apply(this,n):new Promise((function(t,i){r.taskqueue.addTask((function(o){o?i(o):t(r[e].apply(r,n))}))}))})))}function A(e,t){for(var n={},r=0,i=t.length;r<i;r++){var o=t[r];o in e&&(n[o]=e[o])}return n}function S(e){return e}function E(e){return[{ok:e}]}function P(e,t,n){var r=t.docs,o=new i;r.forEach((function(e){o.has(e.id)?o.get(e.id).push(e):o.set(e.id,[e])}));var s=o.size,a=0,u=new Array(s);var c=[];o.forEach((function(e,t){c.push(t)}));var f=0;!function r(){if(!(f>=c.length)){var i=Math.min(f+6,c.length),l=c.slice(f,i);!function(i,c){i.forEach((function(i,f){var l=c+f,d=o.get(i),h=A(d[0],["atts_since","attachments"]);h.open_revs=d.map((function(e){return e.rev})),h.open_revs=h.open_revs.filter(S);var p=S;0===h.open_revs.length&&(delete h.open_revs,p=E),["revs","attachments","binary","ajax","latest"].forEach((function(e){e in t&&(h[e]=t[e])})),e.get(i,h,(function(e,t){var o,c,f,d;o=e?[{error:e}]:p(t),c=i,f=o,u[l]={id:c,docs:f},++a===s&&(d=[],u.forEach((function(e){e.docs.forEach((function(t){d.push({id:e.id,docs:[t]})}))})),n(null,{results:d})),r()}))}))}(l,f),f+=l.length}}()}try{localStorage.setItem("_pouch_check_localstorage",1),w=!!localStorage.getItem("_pouch_check_localstorage")}catch(e){w=!1}function C(){return w}function D(){y().call(this),this._listeners={},function(e){C()&&addEventListener("storage",(function(t){e.emit(t.key)}))}(this)}function L(e){if("undefined"!=typeof console&&"function"==typeof console[e]){var t=Array.prototype.slice.call(arguments,1);console[e].apply(console,t)}}function B(e){var t=0;return e||(t=2e3),function(e,t){var n=6e5;return e=parseInt(e,10)||0,(t=parseInt(t,10))!=t||t<=e?t=(e||1)<<1:t+=1,t>n&&(e=3e5,t=n),~~((t-e)*Math.random()+e)}(e,t)}function I(e,t){L("info","The above "+e+" is totally normal. "+t)}p()(D,y()),D.prototype.addListener=function(e,t,n,r){if(!this._listeners[t]){var i=this,o=!1;this._listeners[t]=a,this.on(e,a)}function a(){if(i._listeners[t])if(o)o="waiting";else{o=!0;var e=A(r,["style","include_docs","attachments","conflicts","filter","doc_ids","view","since","query_params","binary","return_docs"]);n.changes(e).on("change",(function(e){e.seq>r.since&&!r.cancelled&&(r.since=e.seq,r.onChange(e))})).on("complete",(function(){"waiting"===o&&s()(a),o=!1})).on("error",(function(){o=!1}))}}},D.prototype.removeListener=function(e,t){t in this._listeners&&(y().prototype.removeListener.call(this,e,this._listeners[t]),delete this._listeners[t])},D.prototype.notifyLocalWindows=function(e){C()&&(localStorage[e]="a"===localStorage[e]?"b":"a")},D.prototype.notify=function(e){this.emit(e),this.notifyLocalWindows(e)};var T="function"==typeof Object.assign?Object.assign:function(e){for(var t=Object(e),n=1;n<arguments.length;n++){var r=arguments[n];if(null!=r)for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t};function M(e,t,n){Error.call(this,n),this.status=e,this.name=t,this.message=n,this.error=!0}p()(M,Error),M.prototype.toString=function(){return JSON.stringify({status:this.status,name:this.name,message:this.message,reason:this.reason})},new M(401,"unauthorized","Name or password is incorrect.");var N=new M(400,"bad_request","Missing JSON list of 'docs'"),R=new M(404,"not_found","missing"),F=new M(409,"conflict","Document update conflict"),U=new M(400,"bad_request","_id field must contain a string"),z=new M(412,"missing_id","_id is required for puts"),J=new M(400,"bad_request","Only reserved document ids may start with underscore."),K=(new M(412,"precondition_failed","Database not open"),new M(500,"unknown_error","Database encountered an unknown error")),V=new M(500,"badarg","Some query argument is invalid"),Q=(new M(400,"invalid_request","Request was invalid"),new M(400,"query_parse_error","Some query parameter is invalid")),G=new M(500,"doc_validation","Bad special document member"),W=new M(400,"bad_request","Something wrong with the request"),Z=new M(400,"bad_request","Document must be a JSON object"),X=(new M(404,"not_found","Database not found"),new M(500,"indexed_db_went_bad","unknown")),Y=(new M(500,"web_sql_went_bad","unknown"),new M(500,"levelDB_went_went_bad","unknown"),new M(403,"forbidden","Forbidden by design doc validate_doc_update function"),new M(400,"bad_request","Invalid rev format")),H=(new M(412,"file_exists","The database could not be created, the file already exists."),new M(412,"missing_stub","A pre-existing attachment stub wasn't found"));function ee(e,t){function n(t){for(var n=Object.getOwnPropertyNames(e),r=0,i=n.length;r<i;r++)"function"!=typeof e[n[r]]&&(this[n[r]]=e[n[r]]);void 0===this.stack&&(this.stack=(new Error).stack),void 0!==t&&(this.reason=t)}return n.prototype=M.prototype,new n(t)}function te(e){if("object"!=typeof e){var t=e;(e=K).data=t}return"error"in e&&"conflict"===e.error&&(e.name="conflict",e.status=409),"name"in e||(e.name=e.error||"unknown"),"status"in e||(e.status=500),"message"in e||(e.message=e.message||e.reason),"stack"in e||(e.stack=(new Error).stack),e}function ne(e){var t={},n=e.filter&&"function"==typeof e.filter;return t.query=e.query_params,function(r){r.doc||(r.doc={});var i=n&&function(e,t,n){try{return!e(t,n)}catch(e){var r="Filter function threw: "+e.toString();return ee(W,r)}}(e.filter,r.doc,t);if("object"==typeof i)return i;if(i)return!1;if(e.include_docs){if(!e.attachments)for(var o in r.doc._attachments)Object.prototype.hasOwnProperty.call(r.doc._attachments,o)&&(r.doc._attachments[o].stub=!0)}else delete r.doc;return!0}}function re(e){for(var t=[],n=0,r=e.length;n<r;n++)t=t.concat(e[n]);return t}function ie(e){var t;if(e?"string"!=typeof e?t=ee(U):/^_/.test(e)&&!/^_(design|local)/.test(e)&&(t=ee(J)):t=ee(z),t)throw t}function oe(e){return"boolean"==typeof e._remote?e._remote:"function"==typeof e.type&&(L("warn","db.type() is deprecated and will be removed in a future version of PouchDB"),"http"===e.type())}function se(e){if(!e)return null;var t=e.split("/");return 2===t.length?t:1===t.length?[e,e]:null}function ae(e){var t=se(e);return t?t.join("/"):null}new M(413,"invalid_url","Provided URL is invalid");var ue=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],ce="queryKey",fe=/(?:^|&)([^&=]*)=?([^&]*)/g,le=/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;function de(e){for(var t=le.exec(e),n={},r=14;r--;){var i=ue[r],o=t[r]||"",s=-1!==["user","password"].indexOf(i);n[i]=s?decodeURIComponent(o):o}return n[ce]={},n[ue[12]].replace(fe,(function(e,t,r){t&&(n[ce][t]=r)})),n}function he(e,t){var n=[],r=[];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(n.push(i),r.push(t[i]));return n.push(e),Function.apply(null,n).apply(null,r)}function pe(e,t,n){return e.get(t).catch((function(e){if(404!==e.status)throw e;return{}})).then((function(r){var i=r._rev,o=n(r);return o?(o._id=t,o._rev=i,function(e,t,n){return e.put(t).then((function(e){return{updated:!0,rev:e.rev}}),(function(r){if(409!==r.status)throw r;return pe(e,t._id,n)}))}(e,o,n)):{updated:!1,rev:i}}))}var ve=function(e){return atob(e)},ye=function(e){return btoa(e)};function ge(e,t){e=e||[],t=t||{};try{return new Blob(e,t)}catch(i){if("TypeError"!==i.name)throw i;for(var n=new("undefined"!=typeof BlobBuilder?BlobBuilder:"undefined"!=typeof MSBlobBuilder?MSBlobBuilder:"undefined"!=typeof MozBlobBuilder?MozBlobBuilder:WebKitBlobBuilder),r=0;r<e.length;r+=1)n.append(e[r]);return n.getBlob(t.type)}}function _e(e){for(var t=e.length,n=new ArrayBuffer(t),r=new Uint8Array(n),i=0;i<t;i++)r[i]=e.charCodeAt(i);return n}function me(e,t){return ge([_e(e)],{type:t})}function be(e,t){return me(ve(e),t)}function we(e,t){var n=new FileReader,r="function"==typeof n.readAsBinaryString;n.onloadend=function(e){var n=e.target.result||"";if(r)return t(n);t(function(e){for(var t="",n=new Uint8Array(e),r=n.byteLength,i=0;i<r;i++)t+=String.fromCharCode(n[i]);return t}(n))},r?n.readAsBinaryString(e):n.readAsArrayBuffer(e)}function ke(e,t){we(e,(function(e){t(e)}))}function je(e,t){ke(e,(function(e){t(ye(e))}))}var Oe=self.setImmediate||self.setTimeout;function $e(e,t,n,r,i){(n>0||r<t.size)&&(t=function(e,t,n){return e.webkitSlice?e.webkitSlice(t,n):e.slice(t,n)}(t,n,r)),function(e,t){var n=new FileReader;n.onloadend=function(e){var n=e.target.result||new ArrayBuffer(0);t(n)},n.readAsArrayBuffer(e)}(t,(function(t){e.append(t),i()}))}function xe(e,t,n,r,i){(n>0||r<t.length)&&(t=t.substring(n,r)),e.appendBinary(t),i()}function qe(e,t){var n="string"==typeof e,r=n?e.length:e.size,i=Math.min(32768,r),o=Math.ceil(r/i),s=0,a=n?new(c()):new(c().ArrayBuffer),u=n?xe:$e;function f(){Oe(d)}function l(){var e,n=(e=a.end(!0),ye(e));t(n),a.destroy()}function d(){var t=s*i;s++,u(a,e,t,t+i,s<o?f:l)}d()}function Ae(e){return c().hash(e)}function Se(e,t){if(!t)return(0,a.Z)().replace(/-/g,"").toLowerCase();var n=T({},e);return delete n._rev_tree,Ae(JSON.stringify(n))}var Ee=a.Z;function Pe(e){for(var t,n,r,i,o=e.rev_tree.slice();i=o.pop();){var s=i.ids,a=s[2],u=i.pos;if(a.length)for(var c=0,f=a.length;c<f;c++)o.push({pos:u+1,ids:a[c]});else{var l=!!s[1].deleted,d=s[0];t&&!(r!==l?r:n!==u?n<u:t<d)||(t=d,n=u,r=l)}}return n+"-"+t}function Ce(e,t){for(var n,r=e.slice();n=r.pop();)for(var i=n.pos,o=n.ids,s=o[2],a=t(0===s.length,i,o[0],n.ctx,o[1]),u=0,c=s.length;u<c;u++)r.push({pos:i+1,ids:s[u],ctx:a})}function De(e,t){return e.pos-t.pos}function Le(e){var t=[];Ce(e,(function(e,n,r,i,o){e&&t.push({rev:n+"-"+r,pos:n,opts:o})})),t.sort(De).reverse();for(var n=0,r=t.length;n<r;n++)delete t[n].pos;return t}function Be(e){for(var t=Pe(e),n=Le(e.rev_tree),r=[],i=0,o=n.length;i<o;i++){var s=n[i];s.rev===t||s.opts.deleted||r.push(s.rev)}return r}function Ie(e){for(var t,n=[],r=e.slice();t=r.pop();){var i=t.pos,o=t.ids,s=o[0],a=o[1],u=o[2],c=0===u.length,f=t.history?t.history.slice():[];f.push({id:s,opts:a}),c&&n.push({pos:i+1-f.length,ids:f});for(var l=0,d=u.length;l<d;l++)r.push({pos:i+1,ids:u[l],history:f})}return n.reverse()}function Te(e,t){return e.pos-t.pos}function Me(e,t,n){var r=function(e,t,n){for(var r,i=0,o=e.length;i<o;)n(e[r=i+o>>>1],t)<0?i=r+1:o=r;return i}(e,t,n);e.splice(r,0,t)}function Ne(e,t){for(var n,r,i=t,o=e.length;i<o;i++){var s=e[i],a=[s.id,s.opts,[]];r?(r[2].push(a),r=a):n=r=a}return n}function Re(e,t){return e[0]<t[0]?-1:1}function Fe(e,t){for(var n=[{tree1:e,tree2:t}],r=!1;n.length>0;){var i=n.pop(),o=i.tree1,s=i.tree2;(o[1].status||s[1].status)&&(o[1].status="available"===o[1].status||"available"===s[1].status?"available":"missing");for(var a=0;a<s[2].length;a++)if(o[2][0]){for(var u=!1,c=0;c<o[2].length;c++)o[2][c][0]===s[2][a][0]&&(n.push({tree1:o[2][c],tree2:s[2][a]}),u=!0);u||(r="new_branch",Me(o[2],s[2][a],Re))}else r="new_leaf",o[2][0]=s[2][a]}return{conflicts:r,tree:e}}function Ue(e,t,n){var r,i=[],o=!1,s=!1;if(!e.length)return{tree:[t],conflicts:"new_leaf"};for(var a=0,u=e.length;a<u;a++){var c=e[a];if(c.pos===t.pos&&c.ids[0]===t.ids[0])r=Fe(c.ids,t.ids),i.push({pos:c.pos,ids:r.tree}),o=o||r.conflicts,s=!0;else if(!0!==n){var f=c.pos<t.pos?c:t,l=c.pos<t.pos?t:c,d=l.pos-f.pos,h=[],p=[];for(p.push({ids:f.ids,diff:d,parent:null,parentIdx:null});p.length>0;){var v=p.pop();if(0!==v.diff)for(var y=v.ids[2],g=0,_=y.length;g<_;g++)p.push({ids:y[g],diff:v.diff-1,parent:v.ids,parentIdx:g});else v.ids[0]===l.ids[0]&&h.push(v)}var m=h[0];m?(r=Fe(m.ids,l.ids),m.parent[2][m.parentIdx]=r.tree,i.push({pos:f.pos,ids:f.ids}),o=o||r.conflicts,s=!0):i.push(c)}else i.push(c)}return s||i.push(t),i.sort(Te),{tree:i,conflicts:o||"internal_node"}}function ze(e,t,n){var r=Ue(e,t),i=function(e,t){for(var n,r,i=Ie(e),o=0,s=i.length;o<s;o++){var a,u=i[o],c=u.ids;if(c.length>t){n||(n={});var f=c.length-t;a={pos:u.pos+f,ids:Ne(c,f)};for(var l=0;l<f;l++){var d=u.pos+l+"-"+c[l].id;n[d]=!0}}else a={pos:u.pos,ids:Ne(c,0)};r=r?Ue(r,a,!0).tree:[a]}return n&&Ce(r,(function(e,t,r){delete n[t+"-"+r]})),{tree:r,revs:n?Object.keys(n):[]}}(r.tree,n);return{tree:i.tree,stemmedRevs:i.revs,conflicts:r.conflicts}}function Je(e){return e.ids}function Ke(e,t){t||(t=Pe(e));for(var n,r=t.substring(t.indexOf("-")+1),i=e.rev_tree.map(Je);n=i.pop();){if(n[0]===r)return!!n[1].deleted;i=i.concat(n[2])}}function Ve(e){return/^_local/.test(e)}function Qe(e,t,n){y().call(this);var r=this;this.db=e;var i=(t=t?O(t):{}).complete=$((function(t,n){var i,s;t?(s="error",("listenerCount"in(i=r)?i.listenerCount(s):y().listenerCount(i,s))>0&&r.emit("error",t)):r.emit("complete",n),r.removeAllListeners(),e.removeListener("destroyed",o)}));function o(){r.cancel()}n&&(r.on("complete",(function(e){n(null,e)})),r.on("error",n)),e.once("destroyed",o),t.onChange=function(e,t,n){r.isCancelled||function(e,t,n,r){try{e.emit("change",t,n,r)}catch(e){L("error",'Error in .on("change", function):',e)}}(r,e,t,n)};var s=new Promise((function(e,n){t.complete=function(t,r){t?n(t):e(r)}}));r.once("cancel",(function(){e.removeListener("destroyed",o),t.complete(null,{status:"cancelled"})})),this.then=s.then.bind(s),this.catch=s.catch.bind(s),this.then((function(e){i(null,e)}),i),e.taskqueue.isReady?r.validateChanges(t):e.taskqueue.addTask((function(e){e?t.complete(e):r.isCancelled?r.emit("cancel"):r.validateChanges(t)}))}function Ge(e,t,n){var r=[{rev:e._rev}];"all_docs"===n.style&&(r=Le(t.rev_tree).map((function(e){return{rev:e.rev}})));var i={id:t.id,changes:r,doc:e};return Ke(t,e._rev)&&(i.deleted=!0),n.conflicts&&(i.doc._conflicts=Be(t),i.doc._conflicts.length||delete i.doc._conflicts),i}function We(e,t){return e<t?-1:e>t?1:0}function Ze(e,t){return function(n,r){n||r[0]&&r[0].error?((n=n||r[0]).docId=t,e(n)):e(null,r.length?r[0]:r)}}function Xe(e,t){var n=We(e._id,t._id);return 0!==n?n:We(e._revisions?e._revisions.start:0,t._revisions?t._revisions.start:0)}function Ye(e){var t=e._compactionQueue[0],n=t.opts,r=t.callback;e.get("_local/compaction").catch((function(){return!1})).then((function(t){t&&t.last_seq&&(n.last_seq=t.last_seq),e._compact(n,(function(t,n){t?r(t):r(null,n),s()((function(){e._compactionQueue.shift(),e._compactionQueue.length&&Ye(e)}))}))}))}function He(){for(var e in y().call(this),He.prototype)"function"==typeof this[e]&&(this[e]=this[e].bind(this))}function et(){this.isReady=!1,this.failed=!1,this.queue=[]}function tt(e,t){if(!(this instanceof tt))return new tt(e,t);var n=this;if(t=t||{},e&&"object"==typeof e&&(e=(t=e).name,delete t.name),void 0===t.deterministic_revs&&(t.deterministic_revs=!0),this.__opts=t=O(t),n.auto_compaction=t.auto_compaction,n.prefix=tt.prefix,"string"!=typeof e)throw new Error("Missing/invalid DB name");var r=function(e,t){var n=e.match(/([a-z-]*):\/\/(.*)/);if(n)return{name:/https?/.test(n[1])?n[1]+"://"+n[2]:n[2],adapter:n[1]};var r=tt.adapters,i=tt.preferredAdapters,o=tt.prefix,s=t.adapter;if(!s)for(var a=0;a<i.length&&"idb"===(s=i[a])&&"websql"in r&&C()&&localStorage["_pouch__websqldb_"+o+e];++a)L("log",'PouchDB is downgrading "'+e+'" to WebSQL to avoid data loss, because it was already opened with WebSQL.');var u=r[s];return{name:u&&"use_prefix"in u&&!u.use_prefix?e:o+e,adapter:s}}((t.prefix||"")+e,t);if(t.name=r.name,t.adapter=t.adapter||r.adapter,n.name=e,n._adapter=t.adapter,tt.emit("debug",["adapter","Picked adapter: ",t.adapter]),!tt.adapters[t.adapter]||!tt.adapters[t.adapter].valid())throw new Error("Invalid Adapter: "+t.adapter);if(t.view_adapter&&(!tt.adapters[t.view_adapter]||!tt.adapters[t.view_adapter].valid()))throw new Error("Invalid View Adapter: "+t.view_adapter);He.call(n),n.taskqueue=new et,n.adapter=t.adapter,tt.adapters[t.adapter].call(n,t,(function(e){if(e)return n.taskqueue.fail(e);!function(e){function t(t){e.removeListener("closed",n),t||e.constructor.emit("destroyed",e.name)}function n(){e.removeListener("destroyed",t),e.constructor.emit("unref",e)}e.once("destroyed",t),e.once("closed",n),e.constructor.emit("ref",e)}(n),n.emit("created",n),tt.emit("created",n.name),n.taskqueue.ready(n)}))}p()(Qe,y()),Qe.prototype.cancel=function(){this.isCancelled=!0,this.db.taskqueue.isReady&&this.emit("cancel")},Qe.prototype.validateChanges=function(e){var t=e.complete,n=this;tt._changesFilterPlugin?tt._changesFilterPlugin.validate(e,(function(r){if(r)return t(r);n.doChanges(e)})):n.doChanges(e)},Qe.prototype.doChanges=function(e){var t=this,n=e.complete;if("live"in(e=O(e))&&!("continuous"in e)&&(e.continuous=e.live),e.processChange=Ge,"latest"===e.since&&(e.since="now"),e.since||(e.since=0),"now"!==e.since){if(tt._changesFilterPlugin){if(tt._changesFilterPlugin.normalize(e),tt._changesFilterPlugin.shouldFilter(this,e))return tt._changesFilterPlugin.filter(this,e)}else["doc_ids","filter","selector","view"].forEach((function(t){t in e&&L("warn",'The "'+t+'" option was passed in to changes/replicate, but pouchdb-changes-filter plugin is not installed, so it was ignored. Please install the plugin to enable filtering.')}));"descending"in e||(e.descending=!1),e.limit=0===e.limit?1:e.limit,e.complete=n;var r=this.db._changes(e);if(r&&"function"==typeof r.cancel){var i=t.cancel;t.cancel=d()((function(e){r.cancel(),i.apply(this,e)}))}}else this.db.info().then((function(r){t.isCancelled?n(null,{status:"cancelled"}):(e.since=r.update_seq,t.doChanges(e))}),n)},p()(He,y()),He.prototype.post=q("post",(function(e,t,n){if("function"==typeof t&&(n=t,t={}),"object"!=typeof e||Array.isArray(e))return n(ee(Z));this.bulkDocs({docs:[e]},t,Ze(n,e._id))})),He.prototype.put=q("put",(function(e,t,n){if("function"==typeof t&&(n=t,t={}),"object"!=typeof e||Array.isArray(e))return n(ee(Z));if(ie(e._id),Ve(e._id)&&"function"==typeof this._putLocal)return e._deleted?this._removeLocal(e,n):this._putLocal(e,n);var r,i,o,s,a=this;function u(n){"function"==typeof a._put&&!1!==t.new_edits?a._put(e,t,n):a.bulkDocs({docs:[e]},t,Ze(n,e._id))}t.force&&e._rev?(i=(r=e._rev.split("-"))[1],o=parseInt(r[0],10)+1,s=Se(),e._revisions={start:o,ids:[s,i]},e._rev=o+"-"+s,t.new_edits=!1,u((function(t){var r=t?null:{ok:!0,id:e._id,rev:e._rev};n(t,r)}))):u(n)})),He.prototype.putAttachment=q("putAttachment",(function(e,t,n,r,i){var o=this;function s(e){var n="_rev"in e?parseInt(e._rev,10):0;return e._attachments=e._attachments||{},e._attachments[t]={content_type:i,data:r,revpos:++n},o.put(e)}return"function"==typeof i&&(i=r,r=n,n=null),void 0===i&&(i=r,r=n,n=null),i||L("warn","Attachment",t,"on document",e,"is missing content_type"),o.get(e).then((function(e){if(e._rev!==n)throw ee(F);return s(e)}),(function(t){if(t.reason===R.message)return s({_id:e});throw t}))})),He.prototype.removeAttachment=q("removeAttachment",(function(e,t,n,r){var i=this;i.get(e,(function(e,o){if(e)r(e);else if(o._rev===n){if(!o._attachments)return r();delete o._attachments[t],0===Object.keys(o._attachments).length&&delete o._attachments,i.put(o,r)}else r(ee(F))}))})),He.prototype.remove=q("remove",(function(e,t,n,r){var i;"string"==typeof t?(i={_id:e,_rev:t},"function"==typeof n&&(r=n,n={})):(i=e,"function"==typeof t?(r=t,n={}):(r=n,n=t)),(n=n||{}).was_delete=!0;var o={_id:i._id,_rev:i._rev||n.rev,_deleted:!0};if(Ve(o._id)&&"function"==typeof this._removeLocal)return this._removeLocal(i,r);this.bulkDocs({docs:[o]},n,Ze(r,o._id))})),He.prototype.revsDiff=q("revsDiff",(function(e,t,n){"function"==typeof t&&(n=t,t={});var r=Object.keys(e);if(!r.length)return n(null,{});var o=0,s=new i;function a(e,t){s.has(e)||s.set(e,{missing:[]}),s.get(e).missing.push(t)}r.map((function(t){this._getRevisionTree(t,(function(i,u){if(i&&404===i.status&&"missing"===i.message)s.set(t,{missing:e[t]});else{if(i)return n(i);!function(t,n){var r=e[t].slice(0);Ce(n,(function(e,n,i,o,s){var u=n+"-"+i,c=r.indexOf(u);-1!==c&&(r.splice(c,1),"available"!==s.status&&a(t,u))})),r.forEach((function(e){a(t,e)}))}(t,u)}if(++o===r.length){var c={};return s.forEach((function(e,t){c[t]=e})),n(null,c)}}))}),this)})),He.prototype.bulkGet=q("bulkGet",(function(e,t){P(this,e,t)})),He.prototype.compactDocument=q("compactDocument",(function(e,t,n){var r=this;this._getRevisionTree(e,(function(i,o){if(i)return n(i);var s=function(e){var t={},n=[];return Ce(e,(function(e,r,i,o){var s=r+"-"+i;return e&&(t[s]=0),void 0!==o&&n.push({from:o,to:s}),s})),n.reverse(),n.forEach((function(e){void 0===t[e.from]?t[e.from]=1+t[e.to]:t[e.from]=Math.min(t[e.from],1+t[e.to])})),t}(o),a=[],u=[];Object.keys(s).forEach((function(e){s[e]>t&&a.push(e)})),Ce(o,(function(e,t,n,r,i){var o=t+"-"+n;"available"===i.status&&-1!==a.indexOf(o)&&u.push(o)})),r._doCompaction(e,u,n)}))})),He.prototype.compact=q("compact",(function(e,t){"function"==typeof e&&(t=e,e={});var n=this;e=e||{},n._compactionQueue=n._compactionQueue||[],n._compactionQueue.push({opts:e,callback:t}),1===n._compactionQueue.length&&Ye(n)})),He.prototype._compact=function(e,t){var n=this,r={return_docs:!1,last_seq:e.last_seq||0},i=[];n.changes(r).on("change",(function(e){i.push(n.compactDocument(e.id,0))})).on("complete",(function(e){var r=e.last_seq;Promise.all(i).then((function(){return pe(n,"_local/compaction",(function(e){return(!e.last_seq||e.last_seq<r)&&(e.last_seq=r,e)}))})).then((function(){t(null,{ok:!0})})).catch(t)})).on("error",t)},He.prototype.get=q("get",(function(e,t,n){if("function"==typeof t&&(n=t,t={}),"string"!=typeof e)return n(ee(U));if(Ve(e)&&"function"==typeof this._getLocal)return this._getLocal(e,n);var r=[],i=this;function o(){var o=[],s=r.length;if(!s)return n(null,o);r.forEach((function(r){i.get(e,{rev:r,revs:t.revs,latest:t.latest,attachments:t.attachments,binary:t.binary},(function(e,t){if(e)o.push({missing:r});else{for(var i,a=0,u=o.length;a<u;a++)if(o[a].ok&&o[a].ok._rev===t._rev){i=!0;break}i||o.push({ok:t})}--s||n(null,o)}))}))}if(!t.open_revs)return this._get(e,t,(function(r,o){if(r)return r.docId=e,n(r);var s=o.doc,a=o.metadata,u=o.ctx;if(t.conflicts){var c=Be(a);c.length&&(s._conflicts=c)}if(Ke(a,s._rev)&&(s._deleted=!0),t.revs||t.revs_info){for(var f=s._rev.split("-"),l=parseInt(f[0],10),d=f[1],h=Ie(a.rev_tree),p=null,v=0;v<h.length;v++){var y=h[v],g=y.ids.map((function(e){return e.id})).indexOf(d);(g===l-1||!p&&-1!==g)&&(p=y)}if(!p)return(r=new Error("invalid rev tree")).docId=e,n(r);var _=p.ids.map((function(e){return e.id})).indexOf(s._rev.split("-")[1])+1,m=p.ids.length-_;if(p.ids.splice(_,m),p.ids.reverse(),t.revs&&(s._revisions={start:p.pos+p.ids.length-1,ids:p.ids.map((function(e){return e.id}))}),t.revs_info){var b=p.pos+p.ids.length;s._revs_info=p.ids.map((function(e){return{rev:--b+"-"+e.id,status:e.opts.status}}))}}if(t.attachments&&s._attachments){var w=s._attachments,k=Object.keys(w).length;if(0===k)return n(null,s);Object.keys(w).forEach((function(e){this._getAttachment(s._id,e,w[e],{rev:s._rev,binary:t.binary,ctx:u},(function(t,r){var i=s._attachments[e];i.data=r,delete i.stub,delete i.length,--k||n(null,s)}))}),i)}else{if(s._attachments)for(var j in s._attachments)Object.prototype.hasOwnProperty.call(s._attachments,j)&&(s._attachments[j].stub=!0);n(null,s)}}));if("all"===t.open_revs)this._getRevisionTree(e,(function(e,t){if(e)return n(e);r=Le(t).map((function(e){return e.rev})),o()}));else{if(!Array.isArray(t.open_revs))return n(ee(K,"function_clause"));r=t.open_revs;for(var s=0;s<r.length;s++){var a=r[s];if("string"!=typeof a||!/^\d+-/.test(a))return n(ee(Y))}o()}})),He.prototype.getAttachment=q("getAttachment",(function(e,t,n,r){var i=this;n instanceof Function&&(r=n,n={}),this._get(e,n,(function(o,s){return o?r(o):s.doc._attachments&&s.doc._attachments[t]?(n.ctx=s.ctx,n.binary=!0,void i._getAttachment(e,t,s.doc._attachments[t],n,r)):r(ee(R))}))})),He.prototype.allDocs=q("allDocs",(function(e,t){if("function"==typeof e&&(t=e,e={}),e.skip=void 0!==e.skip?e.skip:0,e.start_key&&(e.startkey=e.start_key),e.end_key&&(e.endkey=e.end_key),"keys"in e){if(!Array.isArray(e.keys))return t(new TypeError("options.keys must be an array"));var n=["startkey","endkey","key"].filter((function(t){return t in e}))[0];if(n)return void t(ee(Q,"Query parameter `"+n+"` is not compatible with multi-get"));if(!oe(this)&&(function(e){var t="limit"in e?e.keys.slice(e.skip,e.limit+e.skip):e.skip>0?e.keys.slice(e.skip):e.keys;e.keys=t,e.skip=0,delete e.limit,e.descending&&(t.reverse(),e.descending=!1)}(e),0===e.keys.length))return this._allDocs({limit:0},t)}return this._allDocs(e,t)})),He.prototype.changes=function(e,t){return"function"==typeof e&&(t=e,e={}),(e=e||{}).return_docs="return_docs"in e?e.return_docs:!e.live,new Qe(this,e,t)},He.prototype.close=q("close",(function(e){return this._closed=!0,this.emit("closed"),this._close(e)})),He.prototype.info=q("info",(function(e){var t=this;this._info((function(n,r){if(n)return e(n);r.db_name=r.db_name||t.name,r.auto_compaction=!(!t.auto_compaction||oe(t)),r.adapter=t.adapter,e(null,r)}))})),He.prototype.id=q("id",(function(e){return this._id(e)})),He.prototype.type=function(){return"function"==typeof this._type?this._type():this.adapter},He.prototype.bulkDocs=q("bulkDocs",(function(e,t,n){if("function"==typeof t&&(n=t,t={}),t=t||{},Array.isArray(e)&&(e={docs:e}),!e||!e.docs||!Array.isArray(e.docs))return n(ee(N));for(var r=0;r<e.docs.length;++r)if("object"!=typeof e.docs[r]||Array.isArray(e.docs[r]))return n(ee(Z));var i;if(e.docs.forEach((function(e){e._attachments&&Object.keys(e._attachments).forEach((function(t){i=i||function(e){return"_"===e.charAt(0)&&e+" is not a valid attachment name, attachment names cannot start with '_'"}(t),e._attachments[t].content_type||L("warn","Attachment",t,"on document",e._id,"is missing content_type")}))})),i)return n(ee(W,i));"new_edits"in t||(t.new_edits=!("new_edits"in e)||e.new_edits);var o=this;t.new_edits||oe(o)||e.docs.sort(Xe),function(e){for(var t=0;t<e.length;t++){var n=e[t];if(n._deleted)delete n._attachments;else if(n._attachments)for(var r=Object.keys(n._attachments),i=0;i<r.length;i++){var o=r[i];n._attachments[o]=A(n._attachments[o],["data","digest","content_type","length","revpos","stub"])}}}(e.docs);var s=e.docs.map((function(e){return e._id}));return this._bulkDocs(e,t,(function(e,r){if(e)return n(e);if(t.new_edits||(r=r.filter((function(e){return e.error}))),!oe(o))for(var i=0,a=r.length;i<a;i++)r[i].id=r[i].id||s[i];n(null,r)}))})),He.prototype.registerDependentDatabase=q("registerDependentDatabase",(function(e,t){var n=O(this.__opts);this.__opts.view_adapter&&(n.adapter=this.__opts.view_adapter);var r=new this.constructor(e,n);pe(this,"_local/_pouch_dependentDbs",(function(t){return t.dependentDbs=t.dependentDbs||{},!t.dependentDbs[e]&&(t.dependentDbs[e]=!0,t)})).then((function(){t(null,{db:r})})).catch(t)})),He.prototype.destroy=q("destroy",(function(e,t){"function"==typeof e&&(t=e,e={});var n=this,r=!("use_prefix"in n)||n.use_prefix;function i(){n._destroy(e,(function(e,r){if(e)return t(e);n._destroyed=!0,n.emit("destroyed"),t(null,r||{ok:!0})}))}if(oe(n))return i();n.get("_local/_pouch_dependentDbs",(function(e,o){if(e)return 404!==e.status?t(e):i();var s=o.dependentDbs,a=n.constructor,u=Object.keys(s).map((function(e){var t=r?e.replace(new RegExp("^"+a.prefix),""):e;return new a(t,n.__opts).destroy()}));Promise.all(u).then(i,t)}))})),et.prototype.execute=function(){var e;if(this.failed)for(;e=this.queue.shift();)e(this.failed);else for(;e=this.queue.shift();)e()},et.prototype.fail=function(e){this.failed=e,this.execute()},et.prototype.ready=function(e){this.isReady=!0,this.db=e,this.execute()},et.prototype.addTask=function(e){this.queue.push(e),this.failed&&this.execute()},p()(tt,He);var nt="undefined"!=typeof AbortController?AbortController:function(){return{abort:function(){}}},rt=fetch,it=Headers;tt.adapters={},tt.preferredAdapters=[],tt.prefix="_pouch_";var ot=new(y());function st(e,t){for(var n=e,r=0,i=t.length;r<i&&(n=n[t[r]]);r++);return n}function at(e){for(var t=[],n="",r=0,i=e.length;r<i;r++){var o=e[r];r>0&&"\\"===e[r-1]&&("$"===o||"."===o)?n=n.substring(0,n.length-1)+o:"."===o?(t.push(n),n=""):n+=o}return t.push(n),t}!function(e){Object.keys(y().prototype).forEach((function(t){"function"==typeof y().prototype[t]&&(e[t]=ot[t].bind(ot))}));var t=e._destructionListeners=new i;e.on("ref",(function(e){t.has(e.name)||t.set(e.name,[]),t.get(e.name).push(e)})),e.on("unref",(function(e){if(t.has(e.name)){var n=t.get(e.name),r=n.indexOf(e);r<0||(n.splice(r,1),n.length>1?t.set(e.name,n):t.delete(e.name))}})),e.on("destroyed",(function(e){if(t.has(e)){var n=t.get(e);t.delete(e),n.forEach((function(e){e.emit("destroyed",!0)}))}}))}(tt),tt.adapter=function(e,t,n){t.valid()&&(tt.adapters[e]=t,n&&tt.preferredAdapters.push(e))},tt.plugin=function(e){if("function"==typeof e)e(tt);else{if("object"!=typeof e||0===Object.keys(e).length)throw new Error('Invalid plugin: got "'+e+'", expected an object or a function');Object.keys(e).forEach((function(t){tt.prototype[t]=e[t]}))}return this.__defaults&&(tt.__defaults=T({},this.__defaults)),tt},tt.defaults=function(e){function t(e,n){if(!(this instanceof t))return new t(e,n);n=n||{},e&&"object"==typeof e&&(e=(n=e).name,delete n.name),n=T({},t.__defaults,n),tt.call(this,e,n)}return p()(t,tt),t.preferredAdapters=tt.preferredAdapters.slice(),Object.keys(tt).forEach((function(e){e in t||(t[e]=tt[e])})),t.__defaults=T({},this.__defaults,e),t},tt.fetch=function(e,t){return rt(e,t)};var ut=["$or","$nor","$not"];function ct(e){return ut.indexOf(e)>-1}function ft(e){return Object.keys(e)[0]}function lt(e){var t={},n={$or:!0,$nor:!0};return e.forEach((function(e){Object.keys(e).forEach((function(r){var i=e[r];if("object"!=typeof i&&(i={$eq:i}),ct(r))if(i instanceof Array){if(n[r])return n[r]=!1,void(t[r]=i);var o=[];t[r].forEach((function(e){Object.keys(i).forEach((function(t){var n=i[t],r=Math.max(Object.keys(e).length,Object.keys(n).length),s=lt([e,n]);Object.keys(s).length<=r||o.push(s)}))})),t[r]=o}else t[r]=lt([i]);else{var s=t[r]=t[r]||{};Object.keys(i).forEach((function(e){var t=i[e];return"$gt"===e||"$gte"===e?function(e,t,n){void 0===n.$eq&&(void 0!==n.$gte?"$gte"===e?t>n.$gte&&(n.$gte=t):t>=n.$gte&&(delete n.$gte,n.$gt=t):void 0!==n.$gt?"$gte"===e?t>n.$gt&&(delete n.$gt,n.$gte=t):t>n.$gt&&(n.$gt=t):n[e]=t)}(e,t,s):"$lt"===e||"$lte"===e?function(e,t,n){void 0===n.$eq&&(void 0!==n.$lte?"$lte"===e?t<n.$lte&&(n.$lte=t):t<=n.$lte&&(delete n.$lte,n.$lt=t):void 0!==n.$lt?"$lte"===e?t<n.$lt&&(delete n.$lt,n.$lte=t):t<n.$lt&&(n.$lt=t):n[e]=t)}(e,t,s):"$ne"===e?function(e,t){"$ne"in t?t.$ne.push(e):t.$ne=[e]}(t,s):"$eq"===e?function(e,t){delete t.$gt,delete t.$gte,delete t.$lt,delete t.$lte,delete t.$ne,t.$eq=e}(t,s):"$regex"===e?function(e,t){"$regex"in t?t.$regex.push(e):t.$regex=[e]}(t,s):void(s[e]=t)}))}}))})),t}function dt(e){for(var t in e){if(Array.isArray(e))for(var n in e)e[n].$and&&(e[n]=lt(e[n].$and));var r=e[t];"object"==typeof r&&dt(r)}return e}function ht(e,t){for(var n in e){"$and"===n&&(t=!0);var r=e[n];"object"==typeof r&&(t=ht(r,t))}return t}function pt(e){var t=O(e),n=!1;ht(t,!1)&&("$and"in(t=dt(t))&&(t=lt(t.$and)),n=!0),["$or","$nor"].forEach((function(e){e in t&&t[e].forEach((function(e){for(var t=Object.keys(e),n=0;n<t.length;n++){var r=t[n],i=e[r];"object"==typeof i&&null!==i||(e[r]={$eq:i})}}))})),"$not"in t&&(t.$not=lt([t.$not]));for(var r=Object.keys(t),i=0;i<r.length;i++){var o=r[i],s=t[o];"object"!=typeof s||null===s?s={$eq:s}:n||("$ne"in s&&(s.$ne=[s.$ne]),"$regex"in s&&(s.$regex=[s.$regex])),t[o]=s}return t}function vt(e,t){if(e===t)return 0;e=yt(e),t=yt(t);var n=bt(e),r=bt(t);if(n-r!=0)return n-r;switch(typeof e){case"number":return e-t;case"boolean":return e<t?-1:1;case"string":return function(e,t){return e===t?0:e>t?1:-1}(e,t)}return Array.isArray(e)?function(e,t){for(var n=Math.min(e.length,t.length),r=0;r<n;r++){var i=vt(e[r],t[r]);if(0!==i)return i}return e.length===t.length?0:e.length>t.length?1:-1}(e,t):function(e,t){for(var n=Object.keys(e),r=Object.keys(t),i=Math.min(n.length,r.length),o=0;o<i;o++){var s=vt(n[o],r[o]);if(0!==s)return s;if(0!==(s=vt(e[n[o]],t[r[o]])))return s}return n.length===r.length?0:n.length>r.length?1:-1}(e,t)}function yt(e){switch(typeof e){case"undefined":return null;case"number":return e===1/0||e===-1/0||isNaN(e)?null:e;case"object":var t=e;if(Array.isArray(e)){var n=e.length;e=new Array(n);for(var r=0;r<n;r++)e[r]=yt(t[r])}else{if(e instanceof Date)return e.toJSON();if(null!==e)for(var i in e={},t)if(Object.prototype.hasOwnProperty.call(t,i)){var o=t[i];void 0!==o&&(e[i]=yt(o))}}}return e}function gt(e){return bt(e=yt(e))+""+function(e){if(null!==e)switch(typeof e){case"boolean":return e?1:0;case"number":return function(e){if(0===e)return"1";var t,n=e.toExponential().split(/e\+?/),r=parseInt(n[1],10),i=e<0,o=i?"0":"2";o+=""+(function(e,t,n){for(var r="",i=3-e.length;r.length<i;)r+="0";return r}(t=((i?-r:r)- -324).toString())+t);var s=Math.abs(parseFloat(n[0]));i&&(s=10-s);var a=s.toFixed(20);return o+""+a.replace(/\.?0+$/,"")}(e);case"string":return e.replace(/\u0002/g,"").replace(/\u0001/g,"").replace(/\u0000/g,"");case"object":var t=Array.isArray(e),n=t?e:Object.keys(e),r=-1,i=n.length,o="";if(t)for(;++r<i;)o+=gt(n[r]);else for(;++r<i;){var s=n[r];o+=gt(s)+gt(e[s])}return o}return""}(e)+"\0"}function _t(e,t){var n,r=t;if("1"===e[t])n=0,t++;else{var i="0"===e[t];t++;var o="",s=e.substring(t,t+3),a=parseInt(s,10)+-324;for(i&&(a=-a),t+=3;;){var u=e[t];if("\0"===u)break;o+=u,t++}n=1===(o=o.split(".")).length?parseInt(o,10):parseFloat(o[0]+"."+o[1]),i&&(n-=10),0!==a&&(n=parseFloat(n+"e"+a))}return{num:n,length:t-r}}function mt(e,t){var n=e.pop();if(t.length){var r=t[t.length-1];n===r.element&&(t.pop(),r=t[t.length-1]);var i=r.element,o=r.index;Array.isArray(i)?i.push(n):o===e.length-2?i[e.pop()]=n:e.push(n)}}function bt(e){var t=["boolean","number","string","object"].indexOf(typeof e);return~t?null===e?1:Array.isArray(e)?5:t<3?t+2:t+3:Array.isArray(e)?5:void 0}function wt(e,t,n){return n.every((function(n){var r=t[n],i=at(n),o=st(e,i);return ct(n)?function(e,t,n){return"$or"===e?t.some((function(e){return wt(n,e,Object.keys(e))})):"$not"===e?!wt(n,t,Object.keys(t)):!t.find((function(e){return wt(n,e,Object.keys(e))}))}(n,r,e):kt(r,e,i,o)}))}function kt(e,t,n,r){return!e||("object"==typeof e?Object.keys(e).every((function(i){var o=e[i];if(0===i.indexOf("$"))return jt(i,t,o,n,r);var s=at(i);if(void 0===r&&"object"!=typeof o&&s.length>0)return!1;var a=st(r,s);return"object"==typeof o?kt(o,t,n,a):jt("$eq",t,o,s,a)})):e===r)}function jt(e,t,n,r,i){if(!qt[e])throw new Error('unknown operator "'+e+'" - should be one of $eq, $lte, $lt, $gt, $gte, $exists, $ne, $in, $nin, $size, $mod, $regex, $elemMatch, $type, $allMatch or $all');return qt[e](t,n,r,i)}function Ot(e){return null!=e}function $t(e){return void 0!==e}function xt(e,t){return t.some((function(t){return e instanceof Array?e.some((function(e){return 0===vt(t,e)})):0===vt(t,e)}))}var qt={$elemMatch:function(e,t,n,r){return!!Array.isArray(r)&&0!==r.length&&("object"==typeof r[0]?r.some((function(e){return wt(e,t,Object.keys(t))})):r.some((function(r){return kt(t,e,n,r)})))},$allMatch:function(e,t,n,r){return!!Array.isArray(r)&&0!==r.length&&("object"==typeof r[0]?r.every((function(e){return wt(e,t,Object.keys(t))})):r.every((function(r){return kt(t,e,n,r)})))},$eq:function(e,t,n,r){return $t(r)&&0===vt(r,t)},$gte:function(e,t,n,r){return $t(r)&&vt(r,t)>=0},$gt:function(e,t,n,r){return $t(r)&&vt(r,t)>0},$lte:function(e,t,n,r){return $t(r)&&vt(r,t)<=0},$lt:function(e,t,n,r){return $t(r)&&vt(r,t)<0},$exists:function(e,t,n,r){return t?$t(r):!$t(r)},$mod:function(e,t,n,r){return Ot(r)&&function(e,t){return"number"==typeof e&&parseInt(e,10)===e&&e%t[0]===t[1]}(r,t)},$ne:function(e,t,n,r){return t.every((function(e){return 0!==vt(r,e)}))},$in:function(e,t,n,r){return Ot(r)&&xt(r,t)},$nin:function(e,t,n,r){return Ot(r)&&!xt(r,t)},$size:function(e,t,n,r){return Ot(r)&&Array.isArray(r)&&function(e,t){return e.length===t}(r,t)},$all:function(e,t,n,r){return Array.isArray(r)&&function(e,t){return t.every((function(t){return e.some((function(e){return 0===vt(t,e)}))}))}(r,t)},$regex:function(e,t,n,r){return Ot(r)&&"string"==typeof r&&t.every((function(e){return function(e,t){return new RegExp(t).test(e)}(r,e)}))},$type:function(e,t,n,r){return function(e,t){switch(t){case"null":return null===e;case"boolean":return"boolean"==typeof e;case"number":return"number"==typeof e;case"string":return"string"==typeof e;case"array":return e instanceof Array;case"object":return"[object Object]"==={}.toString.call(e)}}(r,t)}};function At(e,t){if(e.selector&&e.filter&&"_selector"!==e.filter){var n="string"==typeof e.filter?e.filter:"function";return t(new Error('selector invalid for filter "'+n+'"'))}t()}function St(e){e.view&&!e.filter&&(e.filter="_view"),e.selector&&!e.filter&&(e.filter="_selector"),e.filter&&"string"==typeof e.filter&&("_view"===e.filter?e.view=ae(e.view):e.filter=ae(e.filter))}function Et(e,t){return t.filter&&"string"==typeof t.filter&&!t.doc_ids&&!oe(e.db)}function Pt(e,t){var n=t.complete;if("_view"===t.filter){if(!t.view||"string"!=typeof t.view){var r=ee(W,"`view` filter parameter not found or invalid.");return n(r)}var i=se(t.view);e.db.get("_design/"+i[0],(function(r,o){if(e.isCancelled)return n(null,{status:"cancelled"});if(r)return n(te(r));var s=o&&o.views&&o.views[i[1]]&&o.views[i[1]].map;if(!s)return n(ee(R,o.views?"missing json key: "+i[1]:"missing json key: views"));t.filter=he(["return function(doc) {",' "use strict";'," var emitted = false;"," var emit = function (a, b) {"," emitted = true;"," };"," var view = "+s+";"," view(doc);"," if (emitted) {"," return true;"," }","};"].join("\n"),{}),e.doChanges(t)}))}else if(t.selector)t.filter=function(e){return function(e,t){if("object"!=typeof t)throw new Error("Selector error: expected a JSON object");var n=function(e,t,n){if(e=e.filter((function(e){return wt(e.doc,t.selector,n)})),t.sort){var r=function(e){function t(t){return e.map((function(e){var n=at(ft(e));return st(t,n)}))}return function(e,n){var r,i,o=vt(t(e.doc),t(n.doc));return 0!==o?o:(r=e.doc._id)<(i=n.doc._id)?-1:r>i?1:0}}(t.sort);e=e.sort(r),"string"!=typeof t.sort[0]&&"desc"===(i=t.sort[0])[ft(i)]&&(e=e.reverse())}var i;if("limit"in t||"skip"in t){var o=t.skip||0,s=("limit"in t?t.limit:e.length)+o;e=e.slice(o,s)}return e}([{doc:e}],{selector:t=pt(t)},Object.keys(t));return n&&1===n.length}(e,t.selector)},e.doChanges(t);else{var o=se(t.filter);e.db.get("_design/"+o[0],(function(r,i){if(e.isCancelled)return n(null,{status:"cancelled"});if(r)return n(te(r));var s=i&&i.filters&&i.filters[o[1]];if(!s)return n(ee(R,i&&i.filters?"missing json key: "+o[1]:"missing json key: filters"));t.filter=he('"use strict";\nreturn '+s+";",{}),e.doChanges(t)}))}}function Ct(e){return e.reduce((function(e,t){return e[t]=!0,e}),{})}tt.plugin((function(e){e._changesFilterPlugin={validate:At,normalize:St,shouldFilter:Et,filter:Pt}})),tt.version="7.3.0";var Dt=Ct(["_id","_rev","_access","_attachments","_deleted","_revisions","_revs_info","_conflicts","_deleted_conflicts","_local_seq","_rev_tree","_replication_id","_replication_state","_replication_state_time","_replication_state_reason","_replication_stats","_removed"]),Lt=Ct(["_access","_attachments","_replication_id","_replication_state","_replication_state_time","_replication_state_reason","_replication_stats"]);function Bt(e){if(!/^\d+-/.test(e))return ee(Y);var t=e.indexOf("-"),n=e.substring(0,t),r=e.substring(t+1);return{prefix:parseInt(n,10),id:r}}function It(e,t,n){var r,i,o;n||(n={deterministic_revs:!0});var s={status:"available"};if(e._deleted&&(s.deleted=!0),t)if(e._id||(e._id=Ee()),i=Se(e,n.deterministic_revs),e._rev){if((o=Bt(e._rev)).error)return o;e._rev_tree=[{pos:o.prefix,ids:[o.id,{status:"missing"},[[i,s,[]]]]}],r=o.prefix+1}else e._rev_tree=[{pos:1,ids:[i,s,[]]}],r=1;else if(e._revisions&&(e._rev_tree=function(e,t){for(var n=e.start-e.ids.length+1,r=e.ids,i=[r[0],t,[]],o=1,s=r.length;o<s;o++)i=[r[o],{status:"missing"},[i]];return[{pos:n,ids:i}]}(e._revisions,s),r=e._revisions.start,i=e._revisions.ids[0]),!e._rev_tree){if((o=Bt(e._rev)).error)return o;r=o.prefix,i=o.id,e._rev_tree=[{pos:r,ids:[i,s,[]]}]}ie(e._id),e._rev=r+"-"+i;var a={metadata:{},data:{}};for(var u in e)if(Object.prototype.hasOwnProperty.call(e,u)){var c="_"===u[0];if(c&&!Dt[u]){var f=ee(G,u);throw f.message=G.message+": "+u,f}c&&!Lt[u]?a.metadata[u.slice(1)]=e[u]:a.data[u]=e[u]}return a}function Tt(e,t,n){if(e.stub)return n();"string"==typeof e.data?function(e,t,n){var r=function(e){try{return ve(e)}catch(e){return{error:ee(V,"Attachment is not a valid base64 string")}}}(e.data);if(r.error)return n(r.error);e.length=r.length,e.data="blob"===t?me(r,e.content_type):"base64"===t?ye(r):r,qe(r,(function(t){e.digest="md5-"+t,n()}))}(e,t,n):function(e,t,n){qe(e.data,(function(r){e.digest="md5-"+r,e.length=e.data.size||e.data.length||0,"binary"===t?ke(e.data,(function(t){e.data=t,n()})):"base64"===t?je(e.data,(function(t){e.data=t,n()})):n()}))}(e,t,n)}function Mt(e,t,n,r,o,s,a,u,c){e=e||1e3;var f=u.new_edits,l=new i,d=0,h=t.length;function p(){++d===h&&c&&c()}t.forEach((function(e,t){if(e._id&&Ve(e._id)){var r=e._deleted?"_removeLocal":"_putLocal";n[r](e,{ctx:o},(function(e,n){s[t]=e||n,p()}))}else{var i=e.metadata.id;l.has(i)?(h--,l.get(i).push([e,t])):l.set(i,[[e,t]])}})),l.forEach((function(t,n){var i=0;function o(){++i<t.length?c():p()}function c(){var c=t[i],l=c[0],d=c[1];if(r.has(n))!function(e,t,n,r,i,o,s,a){if(function(e,t){for(var n,r=e.slice(),i=t.split("-"),o=parseInt(i[0],10),s=i[1];n=r.pop();){if(n.pos===o&&n.ids[0]===s)return!0;for(var a=n.ids[2],u=0,c=a.length;u<c;u++)r.push({pos:n.pos+1,ids:a[u]})}return!1}(t.rev_tree,n.metadata.rev)&&!a)return r[i]=n,o();var u=t.winningRev||Pe(t),c="deleted"in t?t.deleted:Ke(t,u),f="deleted"in n.metadata?n.metadata.deleted:Ke(n.metadata),l=/^1-/.test(n.metadata.rev);if(c&&!f&&a&&l){var d=n.data;d._rev=u,d._id=n.metadata.id,n=It(d,a)}var h=ze(t.rev_tree,n.metadata.rev_tree[0],e);if(a&&(c&&f&&"new_leaf"!==h.conflicts||!c&&"new_leaf"!==h.conflicts||c&&!f&&"new_branch"===h.conflicts)){var p=ee(F);return r[i]=p,o()}var v=n.metadata.rev;n.metadata.rev_tree=h.tree,n.stemmedRevs=h.stemmedRevs||[],t.rev_map&&(n.metadata.rev_map=t.rev_map);var y=Pe(n.metadata),g=Ke(n.metadata,y),_=c===g?0:c<g?-1:1;s(n,y,g,v===y?g:Ke(n.metadata,v),!0,_,i,o)}(e,r.get(n),l,s,d,o,a,f);else{var h=ze([],l.metadata.rev_tree[0],e);l.metadata.rev_tree=h.tree,l.stemmedRevs=h.stemmedRevs||[],function(e,t,n){var r=Pe(e.metadata),i=Ke(e.metadata,r);if("was_delete"in u&&i)return s[t]=ee(R,"deleted"),n();var o=f&&function(e){return"missing"===e.metadata.rev_tree[0].ids[1].status}(e);if(o){var c=ee(F);return s[t]=c,n()}a(e,r,i,i,!1,i?0:1,t,n)}(l,d,o)}}c()}))}var Nt="document-store",Rt="by-sequence",Ft="attach-store",Ut="attach-seq-store",zt="meta-store",Jt="local-store",Kt="detect-blob-support";function Vt(e){try{return JSON.stringify(e)}catch(t){return f.stringify(e)}}function Qt(e){return function(t){var n="unknown_error";t.target&&t.target.error&&(n=t.target.error.name||t.target.error.message),e(ee(X,n,t.type))}}function Gt(e,t,n){return{data:Vt(e),winningRev:t,deletedOrLocal:n?"1":"0",seq:e.seq,id:e.id}}function Wt(e){if(!e)return null;var t=function(e){try{return JSON.parse(e)}catch(t){return f.parse(e)}}(e.data);return t.winningRev=e.winningRev,t.deleted="1"===e.deletedOrLocal,t.seq=e.seq,t}function Zt(e){if(!e)return e;var t=e._doc_id_rev.lastIndexOf(":");return e._id=e._doc_id_rev.substring(0,t-1),e._rev=e._doc_id_rev.substring(t+1),delete e._doc_id_rev,e}function Xt(e,t,n,r){n?r(e?"string"!=typeof e?e:be(e,t):ge([""],{type:t})):e?"string"!=typeof e?we(e,(function(e){r(ye(e))})):r(e):r("")}function Yt(e,t,n,r){var i=Object.keys(e._attachments||{});if(!i.length)return r&&r();var o=0;function s(){++o===i.length&&r&&r()}i.forEach((function(r){t.attachments&&t.include_docs?function(e,t){var r=e._attachments[t],i=r.digest;n.objectStore(Ft).get(i).onsuccess=function(e){r.body=e.target.result.body,s()}}(e,r):(e._attachments[r].stub=!0,s())}))}function Ht(e,t){return Promise.all(e.map((function(e){if(e.doc&&e.doc._attachments){var n=Object.keys(e.doc._attachments);return Promise.all(n.map((function(n){var r=e.doc._attachments[n];if("body"in r){var i=r.body,o=r.content_type;return new Promise((function(s){Xt(i,o,t,(function(t){e.doc._attachments[n]=T(A(r,["digest","content_type"]),{data:t}),s()}))}))}})))}})))}function en(e,t,n){var r=[],i=n.objectStore(Rt),o=n.objectStore(Ft),s=n.objectStore(Ut),a=e.length;function u(){--a||r.length&&r.forEach((function(e){s.index("digestSeq").count(IDBKeyRange.bound(e+"::",e+"::￿",!1,!1)).onsuccess=function(t){t.target.result||o.delete(e)}}))}e.forEach((function(e){var n=i.index("_doc_id_rev"),o=t+"::"+e;n.getKey(o).onsuccess=function(e){var t=e.target.result;if("number"!=typeof t)return u();i.delete(t),s.index("seq").openCursor(IDBKeyRange.only(t)).onsuccess=function(e){var t=e.target.result;if(t){var n=t.value.digestSeq.split("::")[0];r.push(n),s.delete(t.primaryKey),t.continue()}else u()}}}))}function tn(e,t,n){try{return{txn:e.transaction(t,n)}}catch(e){return{error:e}}}var nn=new D;function rn(e,t,n,r,o,s){for(var a,u,c,f,l,d,h,p,v=t.docs,y=0,g=v.length;y<g;y++){var _=v[y];_._id&&Ve(_._id)||(_=v[y]=It(_,n.new_edits,e)).error&&!h&&(h=_)}if(h)return s(h);var m=!1,b=0,w=new Array(v.length),k=new i,j=!1,O=r._meta.blobSupport?"blob":"base64";function $(){m=!0,x()}function x(){p&&m&&(p.docCount+=b,d.put(p))}function q(){j||(nn.notify(r._meta.name),s(null,w))}function A(e,t,n,r,i,o,s,a){e.metadata.winningRev=t,e.metadata.deleted=n;var u=e.data;if(u._id=e.metadata.id,u._rev=e.metadata.rev,r&&(u._deleted=!0),u._attachments&&Object.keys(u._attachments).length)return function(e,t,n,r,i,o){var s=e.data,a=0,u=Object.keys(s._attachments);function c(){a===u.length&&S(e,t,n,r,i,o)}function l(){a++,c()}u.forEach((function(n){var r=e.data._attachments[n];if(r.stub)a++,c();else{var i=r.data;delete r.data,r.revpos=parseInt(t,10),function(e,t,n){f.count(e).onsuccess=function(r){if(r.target.result)return n();var i={digest:e,body:t};f.put(i).onsuccess=n}}(r.digest,i,l)}}))}(e,t,n,i,s,a);b+=o,x(),S(e,t,n,i,s,a)}function S(e,t,n,i,o,s){var f=e.data,d=e.metadata;function h(o){var s=e.stemmedRevs||[];i&&r.auto_compaction&&(s=s.concat(function(e){var t=[];return Ce(e.rev_tree,(function(e,n,r,i,o){"available"!==o.status||e||(t.push(n+"-"+r),o.status="missing")})),t}(e.metadata))),s&&s.length&&en(s,e.metadata.id,a),d.seq=o.target.result;var c=Gt(d,t,n);u.put(c).onsuccess=p}function p(){w[o]={ok:!0,id:d.id,rev:d.rev},k.set(e.metadata.id,e.metadata),function(e,t,n){var r=0,i=Object.keys(e.data._attachments||{});if(!i.length)return n();function o(){++r===i.length&&n()}function s(n){var r=e.data._attachments[n].digest,i=l.put({seq:t,digestSeq:r+"::"+t});i.onsuccess=o,i.onerror=function(e){e.preventDefault(),e.stopPropagation(),o()}}for(var a=0;a<i.length;a++)s(i[a])}(e,d.seq,s)}f._doc_id_rev=d.id+"::"+d.rev,delete f._id,delete f._rev;var v=c.put(f);v.onsuccess=h,v.onerror=function(e){e.preventDefault(),e.stopPropagation(),c.index("_doc_id_rev").getKey(f._doc_id_rev).onsuccess=function(e){c.put(f,e.target.result).onsuccess=h}}}!function(e,t,n){if(!e.length)return n();var r,i=0;function o(){i++,e.length===i&&(r?n(r):n())}e.forEach((function(e){var n=e.data&&e.data._attachments?Object.keys(e.data._attachments):[],i=0;if(!n.length)return o();function s(e){r=e,++i===n.length&&o()}for(var a in e.data._attachments)Object.prototype.hasOwnProperty.call(e.data._attachments,a)&&Tt(e.data._attachments[a],t,s)}))}(v,O,(function(t){if(t)return s(t);!function(){var t=tn(o,[Nt,Rt,Ft,Jt,Ut,zt],"readwrite");if(t.error)return s(t.error);(a=t.txn).onabort=Qt(s),a.ontimeout=Qt(s),a.oncomplete=q,u=a.objectStore(Nt),c=a.objectStore(Rt),f=a.objectStore(Ft),l=a.objectStore(Ut),(d=a.objectStore(zt)).get(zt).onsuccess=function(e){p=e.target.result,x()},function(e){var t=[];if(v.forEach((function(e){e.data&&e.data._attachments&&Object.keys(e.data._attachments).forEach((function(n){var r=e.data._attachments[n];r.stub&&t.push(r.digest)}))})),!t.length)return e();var n,r=0;t.forEach((function(i){!function(e,t){f.get(e).onsuccess=function(n){if(n.target.result)t();else{var r=ee(H,"unknown stub attachment with digest "+e);r.status=412,t(r)}}}(i,(function(i){i&&!n&&(n=i),++r===t.length&&e(n)}))}))}((function(t){if(t)return j=!0,s(t);!function(){if(v.length)for(var t=0,i=0,o=v.length;i<o;i++){var s=v[i];s._id&&Ve(s._id)?c():u.get(s.metadata.id).onsuccess=f}function c(){++t===v.length&&Mt(e.revs_limit,v,r,k,a,w,A,n,$)}function f(e){var t=Wt(e.target.result);t&&k.set(t.id,t),c()}}()}))}()}))}function on(e,t,n,r,i){var o,s,a;function u(e){s=e.target.result,o&&i(o,s,a)}function c(e){o=e.target.result,s&&i(o,s,a)}function f(e){var t=e.target.result;if(!t)return i();i([t.key],[t.value],t)}-1===r&&(r=1e3),"function"==typeof e.getAll&&"function"==typeof e.getAllKeys&&r>1&&!n?(a={continue:function(){if(!o.length)return i();var n,a=o[o.length-1];if(t&&t.upper)try{n=IDBKeyRange.bound(a,t.upper,!0,t.upperOpen)}catch(e){if("DataError"===e.name&&0===e.code)return i()}else n=IDBKeyRange.lowerBound(a,!0);t=n,o=null,s=null,e.getAll(t,r).onsuccess=u,e.getAllKeys(t,r).onsuccess=c}},e.getAll(t,r).onsuccess=u,e.getAllKeys(t,r).onsuccess=c):n?e.openCursor(t,"prev").onsuccess=f:e.openCursor(t).onsuccess=f}function sn(e,t,n){var r,i,o="startkey"in e&&e.startkey,s="endkey"in e&&e.endkey,a="key"in e&&e.key,u="keys"in e&&e.keys,c=e.skip||0,f="number"==typeof e.limit?e.limit:-1,l=!1!==e.inclusive_end;if(!u&&(r=function(e,t,n,r,i){try{if(e&&t)return i?IDBKeyRange.bound(t,e,!n,!1):IDBKeyRange.bound(e,t,!1,!n);if(e)return i?IDBKeyRange.upperBound(e):IDBKeyRange.lowerBound(e);if(t)return i?IDBKeyRange.lowerBound(t,!n):IDBKeyRange.upperBound(t,!n);if(r)return IDBKeyRange.only(r)}catch(e){return{error:e}}return null}(o,s,l,a,e.descending),(i=r&&r.error)&&("DataError"!==i.name||0!==i.code)))return n(ee(X,i.name,i.message));var d=[Nt,Rt,zt];e.attachments&&d.push(Ft);var h=tn(t,d,"readonly");if(h.error)return n(h.error);var p=h.txn;p.oncomplete=function(){e.attachments?Ht(w,e.binary).then($):$()},p.onabort=Qt(n);var v,y,g=p.objectStore(Nt),_=p.objectStore(Rt),m=p.objectStore(zt),b=_.index("_doc_id_rev"),w=[];function k(t,n){var r={id:n.id,key:n.id,value:{rev:t}};n.deleted?u&&(w.push(r),r.value.deleted=!0,r.doc=null):c--<=0&&(w.push(r),e.include_docs&&function(t,n,r){var i=t.id+"::"+r;b.get(i).onsuccess=function(r){if(n.doc=Zt(r.target.result)||{},e.conflicts){var i=Be(t);i.length&&(n.doc._conflicts=i)}Yt(n.doc,e,p)}}(n,r,t))}function j(e){for(var t=0,n=e.length;t<n&&w.length!==f;t++){var r=e[t];if(r.error&&u)w.push(r);else{var i=Wt(r);k(i.winningRev,i)}}}function O(e,t,n){n&&(j(t),w.length<f&&n.continue())}function $(){var t={total_rows:v,offset:e.skip,rows:w};e.update_seq&&void 0!==y&&(t.update_seq=y),n(null,t)}return m.get(zt).onsuccess=function(e){v=e.target.result.docCount},e.update_seq&&(_.openCursor(null,"prev").onsuccess=function(e){var t=e.target.result,n=void 0;return t&&t.key&&(n=t.key),function(e){e.target.result&&e.target.result.length>0&&(y=e.target.result[0])}({target:{result:[n]}})}),i||0===f?void 0:u?function(e,t,n){var r=new Array(e.length),i=0;e.forEach((function(o,s){t.get(o).onsuccess=function(t){t.target.result?r[s]=t.target.result:r[s]={key:o,error:"not_found"},++i===e.length&&n(e,r,{})}}))}(e.keys,g,O):-1===f?function(e,t,n){if("function"!=typeof e.getAll){var r=[];e.openCursor(t).onsuccess=function(e){var t=e.target.result;t?(r.push(t.value),t.continue()):n({target:{result:r}})}}else e.getAll(t).onsuccess=n}(g,r,(function(t){var n=t.target.result;e.descending&&(n=n.reverse()),j(n)})):void on(g,r,e.descending,f+c,O)}var an=!1,un=[];function cn(){!an&&un.length&&(an=!0,un.shift()())}var fn,ln=new i,dn=new i;function hn(e,t){var n=this;!function(t,o,a){un.push((function(){var t;t=function(e,t){!function(e,t,n,r){try{e(t,n)}catch(t){r.emit("error",t)}}(o,e,t,a),an=!1,s()((function(){cn()}))},function(e,t,n){var o=t.name,a=null,u=null;function c(e){return function(t,n){t&&t instanceof Error&&!t.reason&&u&&(t.reason=u),e(t,n)}}function f(e){var t=e.createObjectStore(Nt,{keyPath:"id"});e.createObjectStore(Rt,{autoIncrement:!0}).createIndex("_doc_id_rev","_doc_id_rev",{unique:!0}),e.createObjectStore(Ft,{keyPath:"digest"}),e.createObjectStore(zt,{keyPath:"id",autoIncrement:!1}),e.createObjectStore(Kt),t.createIndex("deletedOrLocal","deletedOrLocal",{unique:!1}),e.createObjectStore(Jt,{keyPath:"_id"});var n=e.createObjectStore(Ut,{autoIncrement:!0});n.createIndex("seq","seq"),n.createIndex("digestSeq","digestSeq",{unique:!0})}function l(e,t){var n=e.objectStore(Nt);n.createIndex("deletedOrLocal","deletedOrLocal",{unique:!1}),n.openCursor().onsuccess=function(e){var r=e.target.result;if(r){var i=r.value,o=Ke(i);i.deletedOrLocal=o?"1":"0",n.put(i),r.continue()}else t()}}function d(e){e.createObjectStore(Jt,{keyPath:"_id"}).createIndex("_doc_id_rev","_doc_id_rev",{unique:!0})}function h(e,t){var n=e.objectStore(Jt),r=e.objectStore(Nt),i=e.objectStore(Rt);r.openCursor().onsuccess=function(e){var o=e.target.result;if(o){var s=o.value,a=s.id,u=Ve(a),c=Pe(s);if(u){var f=a+"::"+c,l=a+"::",d=a+"::~",h=i.index("_doc_id_rev"),p=IDBKeyRange.bound(l,d,!1,!1),v=h.openCursor(p);v.onsuccess=function(e){if(v=e.target.result){var t=v.value;t._doc_id_rev===f&&n.put(t),i.delete(v.primaryKey),v.continue()}else r.delete(o.primaryKey),o.continue()}}else o.continue()}else t&&t()}}function p(e){var t=e.createObjectStore(Ut,{autoIncrement:!0});t.createIndex("seq","seq"),t.createIndex("digestSeq","digestSeq",{unique:!0})}function v(e,t){var n=e.objectStore(Rt),r=e.objectStore(Ft),i=e.objectStore(Ut);r.count().onsuccess=function(e){if(!e.target.result)return t();n.openCursor().onsuccess=function(e){var n=e.target.result;if(!n)return t();for(var r=n.value,o=n.primaryKey,s=Object.keys(r._attachments||{}),a={},u=0;u<s.length;u++)a[r._attachments[s[u]].digest]=!0;var c=Object.keys(a);for(u=0;u<c.length;u++){var f=c[u];i.put({seq:o,digestSeq:f+"::"+o})}n.continue()}}}function y(e){function t(e){return e.data?Wt(e):(e.deleted="1"===e.deletedOrLocal,e)}var n=e.objectStore(Rt),r=e.objectStore(Nt);r.openCursor().onsuccess=function(e){var i=e.target.result;if(i){var o=t(i.value);if(o.winningRev=o.winningRev||Pe(o),o.seq)return a();s()}function s(){var e=o.id+"::",t=o.id+"::￿",r=n.index("_doc_id_rev").openCursor(IDBKeyRange.bound(e,t)),i=0;r.onsuccess=function(e){var t=e.target.result;if(!t)return o.seq=i,a();var n=t.primaryKey;n>i&&(i=n),t.continue()}}function a(){var e=Gt(o,o.winningRev,o.deleted);r.put(e).onsuccess=function(){i.continue()}}}}e._meta=null,e._remote=!1,e.type=function(){return"idb"},e._id=x((function(t){t(null,e._meta.instanceId)})),e._bulkDocs=function(n,r,i){rn(t,n,r,e,a,c(i))},e._get=function(e,t,n){var r,i,o,s=t.ctx;if(!s){var u=tn(a,[Nt,Rt,Ft],"readonly");if(u.error)return n(u.error);s=u.txn}function c(){n(o,{doc:r,metadata:i,ctx:s})}s.objectStore(Nt).get(e).onsuccess=function(e){if(!(i=Wt(e.target.result)))return o=ee(R,"missing"),c();var n;if(t.rev)n=t.latest?function(e,t){for(var n,r=t.rev_tree.slice();n=r.pop();){var i=n.pos,o=n.ids,s=o[0],a=o[1],u=o[2],c=0===u.length,f=n.history?n.history.slice():[];if(f.push({id:s,pos:i,opts:a}),c)for(var l=0,d=f.length;l<d;l++){var h=f[l];if(h.pos+"-"+h.id===e)return i+"-"+s}for(var p=0,v=u.length;p<v;p++)r.push({pos:i+1,ids:u[p],history:f})}throw new Error("Unable to resolve latest revision for id "+t.id+", rev "+e)}(t.rev,i):t.rev;else if(n=i.winningRev,Ke(i))return o=ee(R,"deleted"),c();var a=s.objectStore(Rt),u=i.id+"::"+n;a.index("_doc_id_rev").get(u).onsuccess=function(e){if((r=e.target.result)&&(r=Zt(r)),!r)return o=ee(R,"missing"),c();c()}}},e._getAttachment=function(e,t,n,r,i){var o;if(r.ctx)o=r.ctx;else{var s=tn(a,[Nt,Rt,Ft],"readonly");if(s.error)return i(s.error);o=s.txn}var u=n.digest,c=n.content_type;o.objectStore(Ft).get(u).onsuccess=function(e){Xt(e.target.result.body,c,r.binary,(function(e){i(null,e)}))}},e._info=function(t){var n,r,i=tn(a,[zt,Rt],"readonly");if(i.error)return t(i.error);var o=i.txn;o.objectStore(zt).get(zt).onsuccess=function(e){r=e.target.result.docCount},o.objectStore(Rt).openCursor(null,"prev").onsuccess=function(e){var t=e.target.result;n=t?t.key:0},o.oncomplete=function(){t(null,{doc_count:r,update_seq:n,idb_attachment_format:e._meta.blobSupport?"binary":"base64"})}},e._allDocs=function(e,t){sn(e,a,c(t))},e._changes=function(t){return function(e,t,n,o){if((e=O(e)).continuous){var s=n+":"+Ee();return nn.addListener(n,s,t,e),nn.notify(n),{cancel:function(){nn.removeListener(n,s)}}}var a=e.doc_ids&&new r(e.doc_ids);e.since=e.since||0;var u=e.since,c="limit"in e?e.limit:-1;0===c&&(c=1);var f,l,d,h,p=[],v=0,y=ne(e),g=new i;function _(e,t,n,r){if(n.seq!==t)return r();if(n.winningRev===e._rev)return r(n,e);var i=e._id+"::"+n.winningRev;h.get(i).onsuccess=function(e){r(n,Zt(e.target.result))}}function m(){e.complete(null,{results:p,last_seq:u})}var b=[Nt,Rt];e.attachments&&b.push(Ft);var w=tn(o,b,"readonly");if(w.error)return e.complete(w.error);(f=w.txn).onabort=Qt(e.complete),f.oncomplete=function(){!e.continuous&&e.attachments?Ht(p).then(m):m()},l=f.objectStore(Rt),d=f.objectStore(Nt),h=l.index("_doc_id_rev"),on(l,e.since&&!e.descending?IDBKeyRange.lowerBound(e.since,!0):null,e.descending,c,(function(t,n,r){if(r&&t.length){var i=new Array(t.length),o=new Array(t.length),s=0;n.forEach((function(n,u){!function(e,t,n){if(a&&!a.has(e._id))return n();var r=g.get(e._id);if(r)return _(e,t,r,n);d.get(e._id).onsuccess=function(i){r=Wt(i.target.result),g.set(e._id,r),_(e,t,r,n)}}(Zt(n),t[u],(function(n,a){o[u]=n,i[u]=a,++s===t.length&&function(){for(var t=[],n=0,s=i.length;n<s&&v!==c;n++){var a=i[n];if(a){var u=o[n];t.push(l(u,a))}}Promise.all(t).then((function(t){for(var n=0,r=t.length;n<r;n++)t[n]&&e.onChange(t[n])})).catch(e.complete),v!==c&&r.continue()}()}))}))}function l(t,n){var r=e.processChange(n,t,e);u=r.seq=t.seq;var i=y(r);return"object"==typeof i?Promise.reject(i):i?(v++,e.return_docs&&p.push(r),e.attachments&&e.include_docs?new Promise((function(t){Yt(n,e,f,(function(){Ht([r],e.binary).then((function(){t(r)}))}))})):Promise.resolve(r)):Promise.resolve()}}))}(t,e,o,a)},e._close=function(e){a.close(),ln.delete(o),e()},e._getRevisionTree=function(e,t){var n=tn(a,[Nt],"readonly");if(n.error)return t(n.error);n.txn.objectStore(Nt).get(e).onsuccess=function(e){var n=Wt(e.target.result);n?t(null,n.rev_tree):t(ee(R))}},e._doCompaction=function(e,t,n){var r=tn(a,[Nt,Rt,Ft,Ut],"readwrite");if(r.error)return n(r.error);var i=r.txn;i.objectStore(Nt).get(e).onsuccess=function(n){var r=Wt(n.target.result);Ce(r.rev_tree,(function(e,n,r,i,o){var s=n+"-"+r;-1!==t.indexOf(s)&&(o.status="missing")})),en(t,e,i);var o=r.winningRev,s=r.deleted;i.objectStore(Nt).put(Gt(r,o,s))},i.onabort=Qt(n),i.oncomplete=function(){n()}},e._getLocal=function(e,t){var n=tn(a,[Jt],"readonly");if(n.error)return t(n.error);var r=n.txn.objectStore(Jt).get(e);r.onerror=Qt(t),r.onsuccess=function(e){var n=e.target.result;n?(delete n._doc_id_rev,t(null,n)):t(ee(R))}},e._putLocal=function(e,t,n){"function"==typeof t&&(n=t,t={}),delete e._revisions;var r=e._rev,i=e._id;e._rev=r?"0-"+(parseInt(r.split("-")[1],10)+1):"0-1";var o,s=t.ctx;if(!s){var u=tn(a,[Jt],"readwrite");if(u.error)return n(u.error);(s=u.txn).onerror=Qt(n),s.oncomplete=function(){o&&n(null,o)}}var c,f=s.objectStore(Jt);r?(c=f.get(i)).onsuccess=function(i){var s=i.target.result;s&&s._rev===r?f.put(e).onsuccess=function(){o={ok:!0,id:e._id,rev:e._rev},t.ctx&&n(null,o)}:n(ee(F))}:((c=f.add(e)).onerror=function(e){n(ee(F)),e.preventDefault(),e.stopPropagation()},c.onsuccess=function(){o={ok:!0,id:e._id,rev:e._rev},t.ctx&&n(null,o)})},e._removeLocal=function(e,t,n){"function"==typeof t&&(n=t,t={});var r,i=t.ctx;if(!i){var o=tn(a,[Jt],"readwrite");if(o.error)return n(o.error);(i=o.txn).oncomplete=function(){r&&n(null,r)}}var s=e._id,u=i.objectStore(Jt),c=u.get(s);c.onerror=Qt(n),c.onsuccess=function(i){var o=i.target.result;o&&o._rev===e._rev?(u.delete(s),r={ok:!0,id:s,rev:"0-0"},t.ctx&&n(null,r)):n(ee(R))}},e._destroy=function(e,t){nn.removeAllListeners(o);var n=dn.get(o);n&&n.result&&(n.result.close(),ln.delete(o));var r=indexedDB.deleteDatabase(o);r.onsuccess=function(){dn.delete(o),C()&&o in localStorage&&delete localStorage[o],t(null,{ok:!0})},r.onerror=Qt(t)};var g=ln.get(o);if(g)return a=g.idb,e._meta=g.global,s()((function(){n(null,e)}));var _=indexedDB.open(o,5);dn.set(o,_),_.onupgradeneeded=function(e){var t=e.target.result;if(e.oldVersion<1)return f(t);var n=e.currentTarget.transaction;e.oldVersion<3&&d(t),e.oldVersion<4&&p(t);var r=[l,h,v,y],i=e.oldVersion;function o(){var e=r[i-1];i++,e&&e(n,o)}o()},_.onsuccess=function(t){(a=t.target.result).onversionchange=function(){a.close(),ln.delete(o)},a.onabort=function(e){L("error","Database has a global failure",e.target.error),u=e.target.error,a.close(),ln.delete(o)};var r,i,s,c,f=a.transaction([zt,Kt,Nt],"readwrite"),l=!1;function d(){void 0!==s&&l&&(e._meta={name:o,instanceId:c,blobSupport:s},ln.set(o,{idb:a,global:e._meta}),n(null,e))}function h(){if(void 0!==i&&void 0!==r){var e=o+"_id";e in r?c=r[e]:r[e]=c=Ee(),r.docCount=i,f.objectStore(zt).put(r)}}f.objectStore(zt).get(zt).onsuccess=function(e){r=e.target.result||{id:zt},h()},function(e,t){e.objectStore(Nt).index("deletedOrLocal").count(IDBKeyRange.only("0")).onsuccess=function(e){t(e.target.result)}}(f,(function(e){i=e,h()})),fn||(fn=function(e){return new Promise((function(t){var n=ge([""]),r=e.objectStore(Kt).put(n,"key");r.onsuccess=function(){var e=navigator.userAgent.match(/Chrome\/(\d+)/),n=navigator.userAgent.match(/Edge\//);t(n||!e||parseInt(e[1],10)>=43)},r.onerror=e.onabort=function(e){e.preventDefault(),e.stopPropagation(),t(!1)}})).catch((function(){return!1}))}(f)),fn.then((function(e){s=e,d()})),f.oncomplete=function(){l=!0,d()},f.onabort=Qt(n)},_.onerror=function(e){var t=e.target.error&&e.target.error.message;t?-1!==t.indexOf("stored database is a higher version")&&(t=new Error('This DB was created with the newer "indexeddb" adapter, but you are trying to open it with the older "idb" adapter')):t="Failed to open indexedDB, are you in private browsing mode?",L("error",t),n(ee(X,t))}}(n,e,t)})),cn()}(0,t,n.constructor)}hn.valid=function(){try{return"undefined"!=typeof indexedDB&&"undefined"!=typeof IDBKeyRange}catch(e){return!1}};var pn=5e3,vn={};function yn(e){var t=e.doc||e.ok,n=t&&t._attachments;n&&Object.keys(n).forEach((function(e){var t=n[e];t.data=be(t.data,t.content_type)}))}function gn(e){return/^_design/.test(e)?"_design/"+encodeURIComponent(e.slice(8)):/^_local/.test(e)?"_local/"+encodeURIComponent(e.slice(7)):encodeURIComponent(e)}function _n(e){return e._attachments&&Object.keys(e._attachments)?Promise.all(Object.keys(e._attachments).map((function(t){var n=e._attachments[t];if(n.data&&"string"!=typeof n.data)return new Promise((function(e){je(n.data,e)})).then((function(e){n.data=e}))}))):Promise.resolve()}function mn(e,t){return bn(e,e.db+"/"+t)}function bn(e,t){var n=e.path?"/":"";return e.protocol+"://"+e.host+(e.port?":"+e.port:"")+"/"+e.path+n+t}function wn(e){return"?"+Object.keys(e).map((function(t){return t+"="+encodeURIComponent(e[t])})).join("&")}function kn(e,t){var n=this,r=function(e,t){if(function(e){if(!e.prefix)return!1;var t=de(e.prefix).protocol;return"http"===t||"https"===t}(t)){var n=t.name.substr(t.prefix.length);e=t.prefix.replace(/\/?$/,"/")+encodeURIComponent(n)}var r=de(e);(r.user||r.password)&&(r.auth={username:r.user,password:r.password});var i=r.path.replace(/(^\/|\/$)/g,"").split("/");return r.db=i.pop(),-1===r.db.indexOf("%")&&(r.db=encodeURIComponent(r.db)),r.path=i.join("/"),r}(e.name,e),i=mn(r,"");e=O(e);var o,a=function(t,n){if((n=n||{}).headers=n.headers||new it,n.credentials="include",e.auth||r.auth){var i=e.auth||r.auth,o=i.username+":"+i.password,s=ye(unescape(encodeURIComponent(o)));n.headers.set("Authorization","Basic "+s)}var a=e.headers||{};return Object.keys(a).forEach((function(e){n.headers.append(e,a[e])})),function(e){var t="undefined"!=typeof navigator&&navigator.userAgent?navigator.userAgent.toLowerCase():"",n=-1!==t.indexOf("msie"),r=-1!==t.indexOf("trident"),i=-1!==t.indexOf("edge"),o=!("method"in e)||"GET"===e.method;return(n||r||i)&&o}(n)&&(t+=(-1===t.indexOf("?")?"?":"&")+"_nonce="+Date.now()),(e.fetch||rt)(t,n)};function u(e,t){return q(e,d()((function(e){f().then((function(){return t.apply(this,e)})).catch((function(t){e.pop()(t)}))}))).bind(n)}function c(e,t,n){var r={};return(t=t||{}).headers=t.headers||new it,t.headers.get("Content-Type")||t.headers.set("Content-Type","application/json"),t.headers.get("Accept")||t.headers.set("Accept","application/json"),a(e,t).then((function(e){return r.ok=e.ok,r.status=e.status,e.json()})).then((function(e){if(r.data=e,!r.ok){r.data.status=r.status;var t=te(r.data);if(n)return n(t);throw t}if(Array.isArray(r.data)&&(r.data=r.data.map((function(e){return e.error||e.missing?te(e):e}))),!n)return r;n(null,r.data)}))}function f(){return e.skip_setup?Promise.resolve():o||((o=c(i).catch((function(e){return e&&e.status&&404===e.status?(I(404,"PouchDB is just detecting if the remote exists."),c(i,{method:"PUT"})):Promise.reject(e)})).catch((function(e){return!(!e||!e.status||412!==e.status)||Promise.reject(e)}))).catch((function(){o=null})),o)}function l(e){return e.split("/").map(encodeURIComponent).join("/")}s()((function(){t(null,n)})),n._remote=!0,n.type=function(){return"http"},n.id=u("id",(function(e){a(bn(r,"")).then((function(e){return e.json()})).catch((function(){return{}})).then((function(t){var n=t&&t.uuid?t.uuid+r.db:mn(r,"");e(null,n)}))})),n.compact=u("compact",(function(e,t){"function"==typeof e&&(t=e,e={}),e=O(e),c(mn(r,"_compact"),{method:"POST"}).then((function(){!function r(){n.info((function(n,i){i&&!i.compact_running?t(null,{ok:!0}):setTimeout(r,e.interval||200)}))}()}))})),n.bulkGet=q("bulkGet",(function(e,t){var n=this;function i(t){var n={};e.revs&&(n.revs=!0),e.attachments&&(n.attachments=!0),e.latest&&(n.latest=!0),c(mn(r,"_bulk_get"+wn(n)),{method:"POST",body:JSON.stringify({docs:e.docs})}).then((function(n){e.attachments&&e.binary&&n.data.results.forEach((function(e){e.docs.forEach(yn)})),t(null,n.data)})).catch(t)}function o(){var r=Math.ceil(e.docs.length/50),i=0,o=new Array(r);function s(e){return function(n,s){o[e]=s.results,++i===r&&t(null,{results:re(o)})}}for(var a=0;a<r;a++){var u=A(e,["revs","attachments","binary","latest"]);u.docs=e.docs.slice(50*a,Math.min(e.docs.length,50*(a+1))),P(n,u,s(a))}}var s=bn(r,""),a=vn[s];"boolean"!=typeof a?i((function(e,n){e?(vn[s]=!1,I(e.status,"PouchDB is just detecting if the remote supports the _bulk_get API."),o()):(vn[s]=!0,t(null,n))})):a?i(t):o()})),n._info=function(e){f().then((function(){return a(mn(r,""))})).then((function(e){return e.json()})).then((function(t){t.host=mn(r,""),e(null,t)})).catch(e)},n.fetch=function(e,t){return f().then((function(){var n="/"===e.substring(0,1)?bn(r,e.substring(1)):mn(r,e);return a(n,t)}))},n.get=u("get",(function(e,t,n){"function"==typeof t&&(n=t,t={});var i={};function o(e){var n,i=e._attachments,o=i&&Object.keys(i);if(i&&o.length)return n=o.map((function(n){return function(){return function(n){var o=i[n],s=gn(e._id)+"/"+l(n)+"?rev="+e._rev;return a(mn(r,s)).then((function(e){return"buffer"in e?e.buffer():e.blob()})).then((function(e){if(t.binary){var n=Object.getOwnPropertyDescriptor(e.__proto__,"type");return n&&!n.set||(e.type=o.content_type),e}return new Promise((function(t){je(e,t)}))})).then((function(e){delete o.stub,delete o.length,o.data=e}))}(n)}})),new Promise((function(e,t){var r,i=0,o=0,s=0,a=n.length;function u(){++s===a?r?t(r):e():l()}function c(){i--,u()}function f(e){i--,r=r||e,u()}function l(){for(;i<5&&o<a;)i++,n[o++]().then(c,f)}l()}))}(t=O(t)).revs&&(i.revs=!0),t.revs_info&&(i.revs_info=!0),t.latest&&(i.latest=!0),t.open_revs&&("all"!==t.open_revs&&(t.open_revs=JSON.stringify(t.open_revs)),i.open_revs=t.open_revs),t.rev&&(i.rev=t.rev),t.conflicts&&(i.conflicts=t.conflicts),t.update_seq&&(i.update_seq=t.update_seq),e=gn(e),c(mn(r,e+wn(i))).then((function(e){return Promise.resolve().then((function(){if(t.attachments)return n=e.data,Array.isArray(n)?Promise.all(n.map((function(e){if(e.ok)return o(e.ok)}))):o(n);var n})).then((function(){n(null,e.data)}))})).catch((function(t){t.docId=e,n(t)}))})),n.remove=u("remove",(function(e,t,n,i){var o;"string"==typeof t?(o={_id:e,_rev:t},"function"==typeof n&&(i=n,n={})):(o=e,"function"==typeof t?(i=t,n={}):(i=n,n=t));var s=o._rev||n.rev;c(mn(r,gn(o._id))+"?rev="+s,{method:"DELETE"},i).catch(i)})),n.getAttachment=u("getAttachment",(function(e,t,n,i){"function"==typeof n&&(i=n,n={});var o,s=n.rev?"?rev="+n.rev:"",u=mn(r,gn(e))+"/"+l(t)+s;a(u,{method:"GET"}).then((function(e){if(o=e.headers.get("content-type"),e.ok)return"undefined"==typeof process||process.browser||"function"!=typeof e.buffer?e.blob():e.buffer();throw e})).then((function(e){"undefined"==typeof process||process.browser||(e.type=o),i(null,e)})).catch((function(e){i(e)}))})),n.removeAttachment=u("removeAttachment",(function(e,t,n,i){c(mn(r,gn(e)+"/"+l(t))+"?rev="+n,{method:"DELETE"},i).catch(i)})),n.putAttachment=u("putAttachment",(function(e,t,n,i,o,s){"function"==typeof o&&(s=o,o=i,i=n,n=null);var a=gn(e)+"/"+l(t),u=mn(r,a);if(n&&(u+="?rev="+n),"string"==typeof i){var f;try{f=ve(i)}catch(e){return s(ee(V,"Attachment is not a valid base64 string"))}i=f?me(f,o):""}c(u,{headers:new it({"Content-Type":o}),method:"PUT",body:i},s).catch(s)})),n._bulkDocs=function(e,t,n){e.new_edits=t.new_edits,f().then((function(){return Promise.all(e.docs.map(_n))})).then((function(){return c(mn(r,"_bulk_docs"),{method:"POST",body:JSON.stringify(e)},n)})).catch(n)},n._put=function(e,t,n){f().then((function(){return _n(e)})).then((function(){return c(mn(r,gn(e._id)),{method:"PUT",body:JSON.stringify(e)})})).then((function(e){n(null,e.data)})).catch((function(t){t.docId=e&&e._id,n(t)}))},n.allDocs=u("allDocs",(function(e,t){"function"==typeof e&&(t=e,e={});var n,i={},o="GET";(e=O(e)).conflicts&&(i.conflicts=!0),e.update_seq&&(i.update_seq=!0),e.descending&&(i.descending=!0),e.include_docs&&(i.include_docs=!0),e.attachments&&(i.attachments=!0),e.key&&(i.key=JSON.stringify(e.key)),e.start_key&&(e.startkey=e.start_key),e.startkey&&(i.startkey=JSON.stringify(e.startkey)),e.end_key&&(e.endkey=e.end_key),e.endkey&&(i.endkey=JSON.stringify(e.endkey)),void 0!==e.inclusive_end&&(i.inclusive_end=!!e.inclusive_end),void 0!==e.limit&&(i.limit=e.limit),void 0!==e.skip&&(i.skip=e.skip);var s=wn(i);void 0!==e.keys&&(o="POST",n={keys:e.keys}),c(mn(r,"_all_docs"+s),{method:o,body:JSON.stringify(n)}).then((function(n){e.include_docs&&e.attachments&&e.binary&&n.data.rows.forEach(yn),t(null,n.data)})).catch(t)})),n._changes=function(e){var t="batch_size"in e?e.batch_size:25;(e=O(e)).continuous&&!("heartbeat"in e)&&(e.heartbeat=1e4);var n="timeout"in e?e.timeout:3e4;"timeout"in e&&e.timeout&&n-e.timeout<pn&&(n=e.timeout+pn),"heartbeat"in e&&e.heartbeat&&n-e.heartbeat<pn&&(n=e.heartbeat+pn);var i={};"timeout"in e&&e.timeout&&(i.timeout=e.timeout);var o=void 0!==e.limit&&e.limit,a=o;if(e.style&&(i.style=e.style),(e.include_docs||e.filter&&"function"==typeof e.filter)&&(i.include_docs=!0),e.attachments&&(i.attachments=!0),e.continuous&&(i.feed="longpoll"),e.seq_interval&&(i.seq_interval=e.seq_interval),e.conflicts&&(i.conflicts=!0),e.descending&&(i.descending=!0),e.update_seq&&(i.update_seq=!0),"heartbeat"in e&&e.heartbeat&&(i.heartbeat=e.heartbeat),e.filter&&"string"==typeof e.filter&&(i.filter=e.filter),e.view&&"string"==typeof e.view&&(i.filter="_view",i.view=e.view),e.query_params&&"object"==typeof e.query_params)for(var u in e.query_params)Object.prototype.hasOwnProperty.call(e.query_params,u)&&(i[u]=e.query_params[u]);var l,d="GET";e.doc_ids?(i.filter="_doc_ids",d="POST",l={doc_ids:e.doc_ids}):e.selector&&(i.filter="_selector",d="POST",l={selector:e.selector});var h,p=new nt,v=function(n,s){if(!e.aborted){i.since=n,"object"==typeof i.since&&(i.since=JSON.stringify(i.since)),e.descending?o&&(i.limit=a):i.limit=!o||a>t?t:a;var u=mn(r,"_changes"+wn(i)),v={signal:p.signal,method:d,body:JSON.stringify(l)};h=n,e.aborted||f().then((function(){return c(u,v,s)})).catch(s)}},y={results:[]},g=function(n,r){if(!e.aborted){var i=0;if(r&&r.results){i=r.results.length,y.last_seq=r.last_seq;var u=null,c=null;"number"==typeof r.pending&&(u=r.pending),"string"!=typeof y.last_seq&&"number"!=typeof y.last_seq||(c=y.last_seq),e.query_params,r.results=r.results.filter((function(t){a--;var n=ne(e)(t);return n&&(e.include_docs&&e.attachments&&e.binary&&yn(t),e.return_docs&&y.results.push(t),e.onChange(t,u,c)),n}))}else if(n)return e.aborted=!0,void e.complete(n);r&&r.last_seq&&(h=r.last_seq);var f=o&&a<=0||r&&i<t||e.descending;(!e.continuous||o&&a<=0)&&f?e.complete(null,y):s()((function(){v(h,g)}))}};return v(e.since||0,g),{cancel:function(){e.aborted=!0,p.abort()}}},n.revsDiff=u("revsDiff",(function(e,t,n){"function"==typeof t&&(n=t,t={}),c(mn(r,"_revs_diff"),{method:"POST",body:JSON.stringify(e)},n).catch(n)})),n._close=function(e){e()},n._destroy=function(e,t){c(mn(r,""),{method:"DELETE"}).then((function(e){t(null,e)})).catch((function(e){404===e.status?t(null,{ok:!0}):t(e)}))}}function jn(e){this.status=400,this.name="query_parse_error",this.message=e,this.error=!0;try{Error.captureStackTrace(this,jn)}catch(e){}}function On(e){this.status=404,this.name="not_found",this.message=e,this.error=!0;try{Error.captureStackTrace(this,On)}catch(e){}}function $n(e){this.status=500,this.name="invalid_value",this.message=e,this.error=!0;try{Error.captureStackTrace(this,$n)}catch(e){}}function xn(e,t){return t&&e.then((function(e){s()((function(){t(null,e)}))}),(function(e){s()((function(){t(e)}))})),e}function qn(e,t){return function(){var n=arguments,r=this;return e.add((function(){return t.apply(r,n)}))}}function An(e){var t=new r(e),n=new Array(t.size),i=-1;return t.forEach((function(e){n[++i]=e})),n}function Sn(e){var t=new Array(e.size),n=-1;return e.forEach((function(e,r){t[++n]=r})),t}function En(e){return new $n("builtin "+e+" function requires map values to be numbers or number arrays")}function Pn(e){for(var t=0,n=0,r=e.length;n<r;n++){var i=e[n];if("number"!=typeof i){if(!Array.isArray(i))throw En("_sum");t="number"==typeof t?[t]:t;for(var o=0,s=i.length;o<s;o++){var a=i[o];if("number"!=typeof a)throw En("_sum");void 0===t[o]?t.push(a):t[o]+=a}}else"number"==typeof t?t+=i:t[0]+=i}return t}kn.valid=function(){return!0},p()(jn,Error),p()(On,Error),p()($n,Error);var Cn=L.bind(null,"log"),Dn=Array.isArray,Ln=JSON.parse;function Bn(e,t){return he("return ("+e.replace(/;\s*$/,"")+");",{emit:t,sum:Pn,log:Cn,isArray:Dn,toJSON:Ln})}function In(){this.promise=new Promise((function(e){e()}))}function Tn(e){if(!e)return"undefined";switch(typeof e){case"function":case"string":return e.toString();default:return JSON.stringify(e)}}function Mn(e,t,n,r,i,o){var s,a=function(e,t){return Tn(e)+Tn(t)+"undefined"}(n,r);if(!i&&(s=e._cachedViews=e._cachedViews||{})[a])return s[a];var u=e.info().then((function(u){var c=u.db_name+"-mrview-"+(i?"temp":Ae(a));return pe(e,"_local/"+o,(function(e){e.views=e.views||{};var n=t;-1===n.indexOf("/")&&(n=t+"/"+t);var r=e.views[n]=e.views[n]||{};if(!r[c])return r[c]=!0,e})).then((function(){return e.registerDependentDatabase(c).then((function(t){var i=t.db;i.auto_compaction=!0;var o={name:c,db:i,sourceDB:e,adapter:e.adapter,mapFun:n,reduceFun:r};return o.db.get("_local/lastSeq").catch((function(e){if(404!==e.status)throw e})).then((function(e){return o.seq=e?e.seq:0,s&&o.db.once("destroyed",(function(){delete s[a]})),o}))}))}))}));return s&&(s[a]=u),u}In.prototype.add=function(e){return this.promise=this.promise.catch((function(){})).then((function(){return e()})),this.promise},In.prototype.finish=function(){return this.promise};var Nn={},Rn=new In;function Fn(e){return-1===e.indexOf("/")?[e,e]:e.split("/")}function Un(e,t){try{e.emit("error",t)}catch(e){L("error","The user's map/reduce function threw an uncaught error.\nYou can debug this error by doing:\nmyDatabase.on('error', function (err) { debugger; });\nPlease double-check your map/reduce function."),L("error",t)}}var zn=function(e,t){return Pn(t)},Jn=function(e,t){return t.length},Kn=function(e,t){return{sum:Pn(t),min:Math.min.apply(null,t),max:Math.max.apply(null,t),count:t.length,sumsqr:function(e){for(var t=0,n=0,r=e.length;n<r;n++){var i=e[n];t+=i*i}return t}(t)}},Vn=function(e,t,n,o){function a(e,t,n){try{t(n)}catch(t){Un(e,t)}}function u(e,t,n,r,i){try{return{output:t(n,r,i)}}catch(t){return Un(e,t),{error:t}}}function c(e,t){var n=vt(e.key,t.key);return 0!==n?n:vt(e.value,t.value)}function f(e,t,n){return n=n||0,"number"==typeof t?e.slice(n,t+n):n>0?e.slice(n):e}function l(e){var t=e.value;return t&&"object"==typeof t&&t._id||e.id}function h(e){return function(t){return e.include_docs&&e.attachments&&e.binary&&function(e){e.rows.forEach((function(e){var t=e.doc&&e.doc._attachments;t&&Object.keys(t).forEach((function(e){var n=t[e];t[e].data=be(n.data,n.content_type)}))}))}(t),t}}function p(e,t,n,r){var i=t[e];void 0!==i&&(r&&(i=encodeURIComponent(JSON.stringify(i))),n.push(e+"="+i))}function v(e){if(void 0!==e){var t=Number(e);return isNaN(t)||t!==parseInt(e,10)?e:t}}function y(e,t){var n=e.descending?"endkey":"startkey",r=e.descending?"startkey":"endkey";if(void 0!==e[n]&&void 0!==e[r]&&vt(e[n],e[r])>0)throw new jn("No rows can match your key range, reverse your start_key and end_key or set {descending : true}");if(t.reduce&&!1!==e.reduce){if(e.include_docs)throw new jn("{include_docs:true} is invalid for reduce");if(e.keys&&e.keys.length>1&&!e.group&&!e.group_level)throw new jn("Multi-key fetches for reduce views must use {group: true}")}["group_level","limit","skip"].forEach((function(t){var n=function(e){if(e){if("number"!=typeof e)return new jn('Invalid value for integer: "'+e+'"');if(e<0)return new jn('Invalid value for positive integer: "'+e+'"')}}(e[t]);if(n)throw n}))}function g(e){return function(t){if(404===t.status)return e;throw t}}function _(e){var t="string"==typeof e?e:e.name,n=Nn[t];return n||(n=Nn[t]=new In),n}function m(e,t){return qn(_(e),(function(){return function(e,t){var n,o;var s=function(e,t){if("function"==typeof e&&2===e.length){var n=e;return function(e){return n(e,t)}}return Bn(e.toString(),t)}(e.mapFun,(function(e,t){var r={id:o._id,key:yt(e)};null!=t&&(r.value=yt(t)),n.push(r)})),u=e.seq||0;function f(t,n){return function(){return function(e,t,n){var i="_local/lastSeq";return e.db.get(i).catch(g({_id:i,seq:0})).then((function(i){var o=Sn(t);return Promise.all(o.map((function(n){return function(e,t,n){var i="_local/doc_"+e,o={_id:i,keys:[]},s=n.get(e),a=s[0];return(function(e){return 1===e.length&&/^1-/.test(e[0].rev)}(s[1])?Promise.resolve(o):t.db.get(i).catch(g(o))).then((function(e){return function(e){return e.keys.length?t.db.allDocs({keys:e.keys,include_docs:!0}):Promise.resolve({rows:[]})}(e).then((function(t){return function(e,t){for(var n=[],i=new r,o=0,s=t.rows.length;o<s;o++){var u=t.rows[o].doc;if(u&&(n.push(u),i.add(u._id),u._deleted=!a.has(u._id),!u._deleted)){var c=a.get(u._id);"value"in c&&(u.value=c.value)}}var f=Sn(a);return f.forEach((function(e){if(!i.has(e)){var t={_id:e},r=a.get(e);"value"in r&&(t.value=r.value),n.push(t)}})),e.keys=An(f.concat(e.keys)),n.push(e),n}(e,t)}))}))}(n,e,t)}))).then((function(t){var r=re(t);return i.seq=n,r.push(i),e.db.bulkDocs({docs:r})}))}))}(e,t,n)}}let l=0,d={view:e.name,indexed_docs:l};e.sourceDB.emit("indexing",d);var h=new In;function p(){return e.sourceDB.changes({return_docs:!0,conflicts:!0,include_docs:!0,style:"all_docs",since:u,limit:t.changes_batch_size}).then(v)}function v(r){var d=r.results;if(!d.length)return;var v=function(t){for(var r=new i,f=0,l=t.length;f<l;f++){var d=t[f];if("_"!==d.doc._id[0]){n=[],(o=d.doc)._deleted||a(e.sourceDB,s,o),n.sort(c);var h=y(n);r.set(d.doc._id,[h,d.changes])}u=d.seq}return r}(d);h.add(f(v,u)),l+=d.length;let g={view:e.name,last_seq:r.last_seq,results_count:d.length,indexed_docs:l};return e.sourceDB.emit("indexing",g),d.length<t.changes_batch_size?void 0:p()}function y(e){for(var t,n=new i,r=0,o=e.length;r<o;r++){var s=e[r],a=[s.key,s.id];r>0&&0===vt(s.key,t)&&a.push(r),n.set(gt(a),s),t=s.key}return n}return p().then((function(){return h.finish()})).then((function(){e.seq=u}))}(e,t)}))()}function b(e,t){return qn(_(e),(function(){return function(e,t){var n,r=e.reduceFun&&!1!==t.reduce,o=t.skip||0;function s(t){return t.include_docs=!0,e.db.allDocs(t).then((function(e){return n=e.total_rows,e.rows.map((function(e){if("value"in e.doc&&"object"==typeof e.doc.value&&null!==e.doc.value){var t=Object.keys(e.doc.value).sort(),n=["id","key","value"];if(!(t<n||t>n))return e.doc.value}var r=function(e){for(var t=[],n=[],r=0;;){var i=e[r++];if("\0"!==i)switch(i){case"1":t.push(null);break;case"2":t.push("1"===e[r]),r++;break;case"3":var o=_t(e,r);t.push(o.num),r+=o.length;break;case"4":for(var s="";;){var a=e[r];if("\0"===a)break;s+=a,r++}s=s.replace(/\u0001\u0001/g,"\0").replace(/\u0001\u0002/g,"").replace(/\u0002\u0002/g,""),t.push(s);break;case"5":var u={element:[],index:t.length};t.push(u.element),n.push(u);break;case"6":var c={element:{},index:t.length};t.push(c.element),n.push(c);break;default:throw new Error("bad collationIndex or unexpectedly reached end of input: "+i)}else{if(1===t.length)return t.pop();mt(t,n)}}}(e.doc._id);return{key:r[0],id:r[1],value:"value"in e.doc?e.doc.value:null}}))}))}function a(s){var a;if(a=r?function(e,t,n){0===n.group_level&&delete n.group_level;var r=n.group||n.group_level,i=function(e){var t=e.toString(),n=function(e){if(/^_sum/.test(e))return zn;if(/^_count/.test(e))return Jn;if(/^_stats/.test(e))return Kn;if(/^_/.test(e))throw new Error(e+" is not a supported reduce function.")}(t);return n||Bn(t)}(e.reduceFun),o=[],s=isNaN(n.group_level)?Number.POSITIVE_INFINITY:n.group_level;t.forEach((function(e){var t=o[o.length-1],n=r?e.key:null;if(r&&Array.isArray(n)&&(n=n.slice(0,s)),t&&0===vt(t.groupKey,n))return t.keys.push([e.key,e.id]),void t.values.push(e.value);o.push({keys:[[e.key,e.id]],values:[e.value],groupKey:n})})),t=[];for(var a=0,c=o.length;a<c;a++){var l=o[a],d=u(e.sourceDB,i,l.keys,l.values,!1);if(d.error&&d.error instanceof $n)throw d.error;t.push({value:d.error?null:d.output,key:l.groupKey})}return{rows:f(t,n.limit,n.skip)}}(e,s,t):void 0===t.keys?{total_rows:n,offset:o,rows:s}:{total_rows:n,offset:o,rows:f(s,t.limit,t.skip)},t.update_seq&&(a.update_seq=e.seq),t.include_docs){var c=An(s.map(l));return e.sourceDB.allDocs({keys:c,include_docs:!0,conflicts:t.conflicts,attachments:t.attachments,binary:t.binary}).then((function(e){var t=new i;return e.rows.forEach((function(e){t.set(e.id,e.doc)})),s.forEach((function(e){var n=l(e),r=t.get(n);r&&(e.doc=r)})),a}))}return a}if(void 0===t.keys||t.keys.length||(t.limit=0,delete t.keys),void 0!==t.keys){var c=t.keys.map((function(e){var n={startkey:gt([e]),endkey:gt([e,{}])};return t.update_seq&&(n.update_seq=!0),s(n)}));return Promise.all(c).then(re).then(a)}var d,h,p={descending:t.descending};if(t.update_seq&&(p.update_seq=!0),"start_key"in t&&(d=t.start_key),"startkey"in t&&(d=t.startkey),"end_key"in t&&(h=t.end_key),"endkey"in t&&(h=t.endkey),void 0!==d&&(p.startkey=t.descending?gt([d,{}]):gt([d])),void 0!==h){var v=!1!==t.inclusive_end;t.descending&&(v=!v),p.endkey=gt(v?[h,{}]:[h])}if(void 0!==t.key){var y=gt([t.key]),g=gt([t.key,{}]);p.descending?(p.endkey=y,p.startkey=g):(p.startkey=y,p.endkey=g)}return r||("number"==typeof t.limit&&(p.limit=t.limit),p.skip=o),s(p).then(a)}(e,t)}))()}function w(t,n,r){if("function"==typeof t._query)return function(e,t,n){return new Promise((function(r,i){e._query(t,n,(function(e,t){if(e)return i(e);r(t)}))}))}(t,n,r);if(oe(t))return function(e,t,n){var r,i,o,s=[],a="GET";if(p("reduce",n,s),p("include_docs",n,s),p("attachments",n,s),p("limit",n,s),p("descending",n,s),p("group",n,s),p("group_level",n,s),p("skip",n,s),p("stale",n,s),p("conflicts",n,s),p("startkey",n,s,!0),p("start_key",n,s,!0),p("endkey",n,s,!0),p("end_key",n,s,!0),p("inclusive_end",n,s),p("key",n,s,!0),p("update_seq",n,s),s=""===(s=s.join("&"))?"":"?"+s,void 0!==n.keys){var u="keys="+encodeURIComponent(JSON.stringify(n.keys));u.length+s.length+1<=2e3?s+=("?"===s[0]?"&":"?")+u:(a="POST","string"==typeof t?r={keys:n.keys}:t.keys=n.keys)}if("string"==typeof t){var c=Fn(t);return e.fetch("_design/"+c[0]+"/_view/"+c[1]+s,{headers:new it({"Content-Type":"application/json"}),method:a,body:JSON.stringify(r)}).then((function(e){return i=e.ok,o=e.status,e.json()})).then((function(e){if(!i)throw e.status=o,te(e);return e.rows.forEach((function(e){if(e.value&&e.value.error&&"builtin_reduce_error"===e.value.error)throw new Error(e.reason)})),e})).then(h(n))}return r=r||{},Object.keys(t).forEach((function(e){Array.isArray(t[e])?r[e]=t[e]:r[e]=t[e].toString()})),e.fetch("_temp_view"+s,{headers:new it({"Content-Type":"application/json"}),method:"POST",body:JSON.stringify(r)}).then((function(e){return i=e.ok,o=e.status,e.json()})).then((function(e){if(!i)throw e.status=o,te(e);return e})).then(h(n))}(t,n,r);var i={changes_batch_size:t.__opts.view_update_changes_batch_size||50};if("string"!=typeof n)return y(r,n),Rn.add((function(){return Mn(t,"temp_view/temp_view",n.map,n.reduce,!0,e).then((function(e){return t=m(e,i).then((function(){return b(e,r)})),n=function(){return e.db.destroy()},t.then((function(e){return n().then((function(){return e}))}),(function(e){return n().then((function(){throw e}))}));var t,n}))})),Rn.finish();var o=n,a=Fn(o),u=a[0],c=a[1];return t.get("_design/"+u).then((function(n){var a=n.views&&n.views[c];if(!a)throw new On("ddoc "+n._id+" has no view named "+c);return function(e,t){var n=e.views&&e.views[t];if("string"!=typeof n.map)throw new On("ddoc "+e._id+" has no string view named "+t+", instead found object of type: "+typeof n.map)}(n,c),y(r,a),Mn(t,o,a.map,a.reduce,!1,e).then((function(e){return"ok"===r.stale||"update_after"===r.stale?("update_after"===r.stale&&s()((function(){m(e,i)})),b(e,r)):m(e,i).then((function(){return b(e,r)}))}))}))}var k;return{query:function(e,t,n){var r=this;"function"==typeof t&&(n=t,t={}),t=t?function(e){return e.group_level=v(e.group_level),e.limit=v(e.limit),e.skip=v(e.skip),e}(t):{},"function"==typeof e&&(e={map:e});var i=Promise.resolve().then((function(){return w(r,e,t)}));return xn(i,n),i},viewCleanup:(k=function(){var e=this;return"function"==typeof e._viewCleanup?function(e){return new Promise((function(t,n){e._viewCleanup((function(e,r){if(e)return n(e);t(r)}))}))}(e):oe(e)?function(e){return e.fetch("_view_cleanup",{headers:new it({"Content-Type":"application/json"}),method:"POST"}).then((function(e){return e.json()}))}(e):function(e){return e.get("_local/mrviews").then((function(t){var n=new i;Object.keys(t.views).forEach((function(e){var t=Fn(e),i="_design/"+t[0],o=t[1],s=n.get(i);s||(s=new r,n.set(i,s)),s.add(o)}));var o={keys:Sn(n),include_docs:!0};return e.allDocs(o).then((function(r){var i={};r.rows.forEach((function(e){var r=e.key.substring(8);n.get(e.key).forEach((function(n){var o=r+"/"+n;t.views[o]||(o=n);var s=Object.keys(t.views[o]),a=e.doc&&e.doc.views&&e.doc.views[n];s.forEach((function(e){i[e]=i[e]||a}))}))}));var o=Object.keys(i).filter((function(e){return!i[e]})).map((function(t){return qn(_(t),(function(){return new e.constructor(t,e.__opts).destroy()}))()}));return Promise.all(o).then((function(){return{ok:!0}}))}))}),g({ok:!0}))}(e)},d()((function(e){var t=e.pop(),n=k.apply(this,e);return"function"==typeof t&&xn(n,t),n})))}}("mrviews"),Qn={query:function(e,t,n){return Vn.query.call(this,e,t,n)},viewCleanup:function(e){return Vn.viewCleanup.call(this,e)}};function Gn(e){return/^1-/.test(e)}function Wn(e,t){var n=Object.keys(t._attachments);return Promise.all(n.map((function(n){return e.getAttachment(t._id,n,{rev:t._rev})})))}function Zn(e,t,n,r){n=O(n);var i=[],o=!0;return Promise.resolve().then((function(){var t=Object.keys(n).filter((function(e){var t=n[e].missing;return 1===t.length&&Gn(t[0])}));if(t.length>0)return function(t){return e.allDocs({keys:t,include_docs:!0,conflicts:!0}).then((function(e){if(r.cancelled)throw new Error("cancelled");e.rows.forEach((function(e){var t;e.deleted||!e.doc||!Gn(e.value.rev)||(t=e.doc)._attachments&&Object.keys(t._attachments).length>0||function(e){return e._conflicts&&e._conflicts.length>0}(e.doc)||(e.doc._conflicts&&delete e.doc._conflicts,i.push(e.doc),delete n[e.id])}))}))}(t)})).then((function(){var s=function(e){var t=[];return Object.keys(e).forEach((function(n){e[n].missing.forEach((function(e){t.push({id:n,rev:e})}))})),{docs:t,revs:!0,latest:!0}}(n);if(s.docs.length)return e.bulkGet(s).then((function(n){if(r.cancelled)throw new Error("cancelled");return Promise.all(n.results.map((function(n){return Promise.all(n.docs.map((function(n){var r=n.ok;return n.error&&(o=!1),r&&r._attachments?function(e,t,n){var r=oe(t)&&!oe(e),i=Object.keys(n._attachments);return r?e.get(n._id).then((function(r){return Promise.all(i.map((function(i){return function(e,t,n){return!e._attachments||!e._attachments[n]||e._attachments[n].digest!==t._attachments[n].digest}(r,n,i)?t.getAttachment(n._id,i):e.getAttachment(r._id,i)})))})).catch((function(e){if(404!==e.status)throw e;return Wn(t,n)})):Wn(t,n)}(t,e,r).then((function(e){var t=Object.keys(r._attachments);return e.forEach((function(e,n){var i=r._attachments[t[n]];delete i.stub,delete i.length,i.data=e})),r})):r})))}))).then((function(e){i=i.concat(re(e).filter(Boolean))}))}))})).then((function(){return{ok:o,docs:i}}))}var Xn="pouchdb";function Yn(e,t,n,r,i){return e.get(t).catch((function(n){if(404===n.status)return"http"!==e.adapter&&"https"!==e.adapter||I(404,"PouchDB is just checking if a remote checkpoint exists."),{session_id:r,_id:t,history:[],replicator:Xn,version:1};throw n})).then((function(o){if(!i.cancelled&&o.last_seq!==n)return o.history=(o.history||[]).filter((function(e){return e.session_id!==r})),o.history.unshift({last_seq:n,session_id:r}),o.history=o.history.slice(0,5),o.version=1,o.replicator=Xn,o.session_id=r,o.last_seq=n,e.put(o).catch((function(o){if(409===o.status)return Yn(e,t,n,r,i);throw o}))}))}function Hn(e,t,n,r,i){this.src=e,this.target=t,this.id=n,this.returnValue=r,this.opts=i||{}}Hn.prototype.writeCheckpoint=function(e,t){var n=this;return this.updateTarget(e,t).then((function(){return n.updateSource(e,t)}))},Hn.prototype.updateTarget=function(e,t){return this.opts.writeTargetCheckpoint?Yn(this.target,this.id,e,t,this.returnValue):Promise.resolve(!0)},Hn.prototype.updateSource=function(e,t){if(this.opts.writeSourceCheckpoint){var n=this;return Yn(this.src,this.id,e,t,this.returnValue).catch((function(e){if(rr(e))return n.opts.writeSourceCheckpoint=!1,!0;throw e}))}return Promise.resolve(!0)};var er={undefined:function(e,t){return 0===vt(e.last_seq,t.last_seq)?t.last_seq:0},1:function(e,t){return(n=t,r=e,n.session_id===r.session_id?{last_seq:n.last_seq,history:n.history}:tr(n.history,r.history)).last_seq;var n,r}};function tr(e,t){var n=e[0],r=e.slice(1),i=t[0],o=t.slice(1);return n&&0!==t.length?nr(n.session_id,t)?{last_seq:n.last_seq,history:e}:nr(i.session_id,r)?{last_seq:i.last_seq,history:o}:tr(r,o):{last_seq:0,history:[]}}function nr(e,t){var n=t[0],r=t.slice(1);return!(!e||0===t.length)&&(e===n.session_id||nr(e,r))}function rr(e){return"number"==typeof e.status&&4===Math.floor(e.status/100)}function ir(e,t,n,r,i){var o,a,u,c=[],f={seq:0,changes:[],docs:[]},l=!1,d=!1,h=!1,p=0,v=n.continuous||n.live||!1,y=n.batch_size||100,g=n.batches_limit||10,_=n.style||"all_docs",m=!1,b=n.doc_ids,w=n.selector,k=[],j=Ee();i=i||{ok:!0,start_time:(new Date).toISOString(),docs_read:0,docs_written:0,doc_write_failures:0,errors:[]};var $={};function x(){return u?Promise.resolve():function(e,t,n){var r=n.doc_ids?n.doc_ids.sort(vt):"",i=n.filter?n.filter.toString():"",o="",s="",a="";return n.selector&&(a=JSON.stringify(n.selector)),n.filter&&n.query_params&&(o=JSON.stringify(function(e){return Object.keys(e).sort(vt).reduce((function(t,n){return t[n]=e[n],t}),{})}(n.query_params))),n.filter&&"_view"===n.filter&&(s=n.view.toString()),Promise.all([e.id(),t.id()]).then((function(e){var t=e[0]+e[1]+i+s+o+r+a;return new Promise((function(e){qe(t,e)}))})).then((function(e){return"_local/"+e.replace(/\//g,".").replace(/\+/g,"_")}))}(e,t,n).then((function(i){a=i;var o;o=!1===n.checkpoint?{writeSourceCheckpoint:!1,writeTargetCheckpoint:!1}:"source"===n.checkpoint?{writeSourceCheckpoint:!0,writeTargetCheckpoint:!1}:"target"===n.checkpoint?{writeSourceCheckpoint:!1,writeTargetCheckpoint:!0}:{writeSourceCheckpoint:!0,writeTargetCheckpoint:!0},u=new Hn(e,t,a,r,o)}))}function q(){if(k=[],0!==o.docs.length){var e=o.docs,s={timeout:n.timeout};return t.bulkDocs({docs:e,new_edits:!1},s).then((function(t){if(r.cancelled)throw D(),new Error("cancelled");var n=Object.create(null);t.forEach((function(e){e.error&&(n[e.id]=e)}));var o=Object.keys(n).length;i.doc_write_failures+=o,i.docs_written+=e.length-o,e.forEach((function(e){var t=n[e._id];if(t){i.errors.push(t);var o=(t.name||"").toLowerCase();if("unauthorized"!==o&&"forbidden"!==o)throw t;r.emit("denied",O(t))}else k.push(e)}))}),(function(t){throw i.doc_write_failures+=e.length,t}))}}function A(){if(o.error)throw new Error("There was a problem getting docs.");i.last_seq=p=o.seq;var e=O(i);return k.length&&(e.docs=k,"number"==typeof o.pending&&(e.pending=o.pending,delete o.pending),r.emit("change",e)),l=!0,u.writeCheckpoint(o.seq,j).then((function(){if(r.emit("checkpoint",{checkpoint:o.seq}),l=!1,r.cancelled)throw D(),new Error("cancelled");o=void 0,M()})).catch((function(e){throw R(e),e}))}function S(){return Zn(e,t,o.diffs,r).then((function(e){o.error=!e.ok,e.docs.forEach((function(e){delete o.diffs[e._id],i.docs_read++,o.docs.push(e)}))}))}function E(){var e;r.cancelled||o||(0!==c.length?(o=c.shift(),r.emit("checkpoint",{start_next_batch:o.seq}),(e={},o.changes.forEach((function(t){r.emit("checkpoint",{revs_diff:t}),"_user/"!==t.id&&(e[t.id]=t.changes.map((function(e){return e.rev})))})),t.revsDiff(e).then((function(e){if(r.cancelled)throw D(),new Error("cancelled");o.diffs=e}))).then(S).then(q).then(A).then(E).catch((function(e){C("batch processing terminated with error",e)}))):P(!0))}function P(e){0!==f.changes.length?(e||d||f.changes.length>=y)&&(c.push(f),f={seq:0,changes:[],docs:[]},"pending"!==r.state&&"stopped"!==r.state||(r.state="active",r.emit("active")),E()):0!==c.length||o||((v&&$.live||d)&&(r.state="pending",r.emit("paused")),d&&D())}function C(e,t){h||(t.message||(t.message=e),i.ok=!1,i.status="aborting",c=[],f={seq:0,changes:[],docs:[]},D(t))}function D(o){if(!(h||r.cancelled&&(i.status="cancelled",l)))if(i.status=i.status||"complete",i.end_time=(new Date).toISOString(),i.last_seq=p,h=!0,o){(o=ee(o)).result=i;var s=(o.name||"").toLowerCase();"unauthorized"===s||"forbidden"===s?(r.emit("error",o),r.removeAllListeners()):function(e,t,n,r){if(!1===e.retry)return t.emit("error",n),void t.removeAllListeners();if("function"!=typeof e.back_off_function&&(e.back_off_function=B),t.emit("requestError",n),"active"===t.state||"pending"===t.state){t.emit("paused",n),t.state="stopped";var i=function(){e.current_back_off=0};t.once("paused",(function(){t.removeListener("active",i)})),t.once("active",i)}e.current_back_off=e.current_back_off||0,e.current_back_off=e.back_off_function(e.current_back_off),setTimeout(r,e.current_back_off)}(n,r,o,(function(){ir(e,t,n,r)}))}else r.emit("complete",i),r.removeAllListeners()}function L(e,t,i){if(r.cancelled)return D();"number"==typeof t&&(f.pending=t),ne(n)(e)&&(f.seq=e.seq||i,f.changes.push(e),r.emit("checkpoint",{pending_batch:f.seq}),s()((function(){P(0===c.length&&$.live)})))}function I(e){if(m=!1,r.cancelled)return D();if(e.results.length>0)$.since=e.results[e.results.length-1].seq,M(),P(!0);else{var t=function(){v?($.live=!0,M()):d=!0,P(!0)};o||0!==e.results.length?t():(l=!0,u.writeCheckpoint(e.last_seq,j).then((function(){l=!1,i.last_seq=p=e.last_seq,t()})).catch(R))}}function T(e){if(m=!1,r.cancelled)return D();C("changes rejected",e)}function M(){if(!m&&!d&&c.length<g){m=!0,r._changes&&(r.removeListener("cancel",r._abortChanges),r._changes.cancel()),r.once("cancel",i);var t=e.changes($).on("change",L);t.then(o,o),t.then(I).catch(T),n.retry&&(r._changes=t,r._abortChanges=i)}function i(){t.cancel()}function o(){r.removeListener("cancel",i)}}function N(){x().then((function(){if(!r.cancelled)return u.getCheckpoint().then((function(e){$={since:p=e,limit:y,batch_size:y,style:_,doc_ids:b,selector:w,return_docs:!0},n.filter&&("string"!=typeof n.filter?$.include_docs=!0:$.filter=n.filter),"heartbeat"in n&&($.heartbeat=n.heartbeat),"timeout"in n&&($.timeout=n.timeout),n.query_params&&($.query_params=n.query_params),n.view&&($.view=n.view),M()}));D()})).catch((function(e){C("getCheckpoint rejected with ",e)}))}function R(e){l=!1,C("writeCheckpoint completed with error",e)}r.ready(e,t),r.cancelled?D():(r._addedListeners||(r.once("cancel",D),"function"==typeof n.complete&&(r.once("error",n.complete),r.once("complete",(function(e){n.complete(null,e)}))),r._addedListeners=!0),void 0===n.since?N():x().then((function(){return l=!0,u.writeCheckpoint(n.since,j)})).then((function(){l=!1,r.cancelled?D():(p=n.since,N())})).catch(R))}function or(){y().call(this),this.cancelled=!1,this.state="pending";var e=this,t=new Promise((function(t,n){e.once("complete",t),e.once("error",n)}));e.then=function(e,n){return t.then(e,n)},e.catch=function(e){return t.catch(e)},e.catch((function(){}))}function sr(e,t){var n=t.PouchConstructor;return"string"==typeof e?new n(e,t):e}function ar(e,t,n,r){if("function"==typeof n&&(r=n,n={}),void 0===n&&(n={}),n.doc_ids&&!Array.isArray(n.doc_ids))throw ee(W,"`doc_ids` filter parameter is not a list.");n.complete=r,(n=O(n)).continuous=n.continuous||n.live,n.retry="retry"in n&&n.retry,n.PouchConstructor=n.PouchConstructor||this;var i=new or(n);return ir(sr(e,n),sr(t,n),n,i),i}function ur(e,t,n,r){return"function"==typeof n&&(r=n,n={}),void 0===n&&(n={}),(n=O(n)).PouchConstructor=n.PouchConstructor||this,new cr(e=sr(e,n),t=sr(t,n),n,r)}function cr(e,t,n,r){var i=this;this.canceled=!1;var o=n.push?T({},n,n.push):n,s=n.pull?T({},n,n.pull):n;function a(e){i.emit("change",{direction:"pull",change:e})}function u(e){i.emit("change",{direction:"push",change:e})}function c(e){i.emit("denied",{direction:"push",doc:e})}function f(e){i.emit("denied",{direction:"pull",doc:e})}function l(){i.pushPaused=!0,i.pullPaused&&i.emit("paused")}function d(){i.pullPaused=!0,i.pushPaused&&i.emit("paused")}function h(){i.pushPaused=!1,i.pullPaused&&i.emit("active",{direction:"push"})}function p(){i.pullPaused=!1,i.pushPaused&&i.emit("active",{direction:"pull"})}this.push=ar(e,t,o),this.pull=ar(t,e,s),this.pushPaused=!0,this.pullPaused=!0;var v={};function y(e){return function(t,n){("change"===t&&(n===a||n===u)||"denied"===t&&(n===f||n===c)||"paused"===t&&(n===d||n===l)||"active"===t&&(n===p||n===h))&&(t in v||(v[t]={}),v[t][e]=!0,2===Object.keys(v[t]).length&&i.removeAllListeners(t))}}function g(e,t,n){-1==e.listeners(t).indexOf(n)&&e.on(t,n)}n.live&&(this.push.on("complete",i.pull.cancel.bind(i.pull)),this.pull.on("complete",i.push.cancel.bind(i.push))),this.on("newListener",(function(e){"change"===e?(g(i.pull,"change",a),g(i.push,"change",u)):"denied"===e?(g(i.pull,"denied",f),g(i.push,"denied",c)):"active"===e?(g(i.pull,"active",p),g(i.push,"active",h)):"paused"===e&&(g(i.pull,"paused",d),g(i.push,"paused",l))})),this.on("removeListener",(function(e){"change"===e?(i.pull.removeListener("change",a),i.push.removeListener("change",u)):"denied"===e?(i.pull.removeListener("denied",f),i.push.removeListener("denied",c)):"active"===e?(i.pull.removeListener("active",p),i.push.removeListener("active",h)):"paused"===e&&(i.pull.removeListener("paused",d),i.push.removeListener("paused",l))})),this.pull.on("removeListener",y("pull")),this.push.on("removeListener",y("push"));var _=Promise.all([this.push,this.pull]).then((function(e){var t={push:e[0],pull:e[1]};return i.emit("complete",t),r&&r(null,t),i.removeAllListeners(),t}),(function(e){if(i.cancel(),r?r(e):i.emit("error",e),i.removeAllListeners(),r)throw e}));this.then=function(e,t){return _.then(e,t)},this.catch=function(e){return _.catch(e)}}Hn.prototype.getCheckpoint=function(){var e=this;return e.opts&&e.opts.writeSourceCheckpoint&&!e.opts.writeTargetCheckpoint?e.src.get(e.id).then((function(e){return e.last_seq||0})).catch((function(e){if(404!==e.status)throw e;return 0})):e.target.get(e.id).then((function(t){return e.opts&&e.opts.writeTargetCheckpoint&&!e.opts.writeSourceCheckpoint?t.last_seq||0:e.src.get(e.id).then((function(e){return t.version!==e.version?0:(n=t.version?t.version.toString():"undefined")in er?er[n](t,e):0;var n}),(function(n){if(404===n.status&&t.last_seq)return e.src.put({_id:e.id,last_seq:0}).then((function(){return 0}),(function(n){return rr(n)?(e.opts.writeSourceCheckpoint=!1,t.last_seq):0}));throw n}))})).catch((function(e){if(404!==e.status)throw e;return 0}))},p()(or,y()),or.prototype.cancel=function(){this.cancelled=!0,this.state="cancelled",this.emit("cancel")},or.prototype.ready=function(e,t){var n=this;function r(){n.cancel()}function i(){e.removeListener("destroyed",r),t.removeListener("destroyed",r)}n._readyCalled||(n._readyCalled=!0,e.once("destroyed",r),t.once("destroyed",r),n.once("complete",i),n.once("error",i))},p()(cr,y()),cr.prototype.cancel=function(){this.canceled||(this.canceled=!0,this.push.cancel(),this.pull.cancel())},tt.plugin((function(e){e.adapter("idb",hn,!0)})).plugin((function(e){e.adapter("http",kn,!1),e.adapter("https",kn,!1)})).plugin(Qn).plugin((function(e){e.replicate=ar,e.sync=ur,Object.defineProperty(e.prototype,"replicate",{get:function(){var e=this;return void 0===this.replicateMethods&&(this.replicateMethods={from:function(t,n,r){return e.constructor.replicate(t,e,n,r)},to:function(t,n,r){return e.constructor.replicate(e,t,n,r)}}),this.replicateMethods}}),e.prototype.sync=function(e,t,n){return this.constructor.sync(this,e,t,n)}}));const fr=tt},614:(e,t,n)=>{n.d(t,{Z:()=>vt});var r=n(717),i=n.n(r);function o(e,t,n){Error.call(this,n),this.status=e,this.name=t,this.message=n,this.error=!0}i()(o,Error),o.prototype.toString=function(){return JSON.stringify({status:this.status,name:this.name,message:this.message,reason:this.reason})},new o(401,"unauthorized","Name or password is incorrect."),new o(400,"bad_request","Missing JSON list of 'docs'"),new o(404,"not_found","missing"),new o(409,"conflict","Document update conflict"),new o(400,"bad_request","_id field must contain a string"),new o(412,"missing_id","_id is required for puts"),new o(400,"bad_request","Only reserved document ids may start with underscore."),new o(412,"precondition_failed","Database not open");var s=new o(500,"unknown_error","Database encountered an unknown error");function a(e){if("object"!=typeof e){var t=e;(e=s).data=t}return"error"in e&&"conflict"===e.error&&(e.name="conflict",e.status=409),"name"in e||(e.name=e.error||"unknown"),"status"in e||(e.status=500),"message"in e||(e.message=e.message||e.reason),"stack"in e||(e.stack=(new Error).stack),e}new o(500,"badarg","Some query argument is invalid"),new o(400,"invalid_request","Request was invalid"),new o(400,"query_parse_error","Some query parameter is invalid"),new o(500,"doc_validation","Bad special document member"),new o(400,"bad_request","Something wrong with the request"),new o(400,"bad_request","Document must be a JSON object"),new o(404,"not_found","Database not found"),new o(500,"indexed_db_went_bad","unknown"),new o(500,"web_sql_went_bad","unknown"),new o(500,"levelDB_went_went_bad","unknown"),new o(403,"forbidden","Forbidden by design doc validate_doc_update function"),new o(400,"bad_request","Invalid rev format"),new o(412,"file_exists","The database could not be created, the file already exists."),new o(412,"missing_stub","A pre-existing attachment stub wasn't found"),new o(413,"invalid_url","Provided URL is invalid"),"undefined"!=typeof AbortController&&AbortController,fetch;var u,c,f=Headers;function l(e){return"$"+e}function d(e){return e.substring(1)}function h(){this._store={}}function p(e){if(this._store=new h,e&&Array.isArray(e))for(var t=0,n=e.length;t<n;t++)this.add(e[t])}function v(e){for(var t=e.length,n=new ArrayBuffer(t),r=new Uint8Array(n),i=0;i<t;i++)r[i]=e.charCodeAt(i);return n}function y(e,t){return function(e,t){return function(e,t){e=e||[],t=t||{};try{return new Blob(e,t)}catch(i){if("TypeError"!==i.name)throw i;for(var n=new("undefined"!=typeof BlobBuilder?BlobBuilder:"undefined"!=typeof MSBlobBuilder?MSBlobBuilder:"undefined"!=typeof MozBlobBuilder?MozBlobBuilder:WebKitBlobBuilder),r=0;r<e.length;r+=1)n.append(e[r]);return n.getBlob(t.type)}}([v(e)],{type:t})}(atob(e),t)}h.prototype.get=function(e){var t=l(e);return this._store[t]},h.prototype.set=function(e,t){var n=l(e);return this._store[n]=t,!0},h.prototype.has=function(e){return l(e)in this._store},h.prototype.keys=function(){return Object.keys(this._store).map((e=>d(e)))},h.prototype.delete=function(e){var t=l(e),n=t in this._store;return delete this._store[t],n},h.prototype.forEach=function(e){for(var t=Object.keys(this._store),n=0,r=t.length;n<r;n++){var i=t[n];e(this._store[i],i=d(i))}},Object.defineProperty(h.prototype,"size",{get:function(){return Object.keys(this._store).length}}),p.prototype.add=function(e){return this._store.set(e,!0)},p.prototype.has=function(e){return this._store.has(e)},p.prototype.forEach=function(e){this._store.forEach((function(t,n){e(n)}))},Object.defineProperty(p.prototype,"size",{get:function(){return this._store.size}}),function(){if("undefined"==typeof Symbol||"undefined"==typeof Map||"undefined"==typeof Set)return!1;var e=Object.getOwnPropertyDescriptor(Map,Symbol.species);return e&&"get"in e&&Map[Symbol.species]===Map}()?(u=Set,c=Map):(u=p,c=h);function g(e,t){if(e===t)return 0;e=_(e),t=_(t);var n=k(e),r=k(t);if(n-r!=0)return n-r;switch(typeof e){case"number":return e-t;case"boolean":return e<t?-1:1;case"string":return function(e,t){return e===t?0:e>t?1:-1}(e,t)}return Array.isArray(e)?function(e,t){for(var n=Math.min(e.length,t.length),r=0;r<n;r++){var i=g(e[r],t[r]);if(0!==i)return i}return e.length===t.length?0:e.length>t.length?1:-1}(e,t):function(e,t){for(var n=Object.keys(e),r=Object.keys(t),i=Math.min(n.length,r.length),o=0;o<i;o++){var s=g(n[o],r[o]);if(0!==s)return s;if(0!==(s=g(e[n[o]],t[r[o]])))return s}return n.length===r.length?0:n.length>r.length?1:-1}(e,t)}function _(e){switch(typeof e){case"undefined":return null;case"number":return e===1/0||e===-1/0||isNaN(e)?null:e;case"object":var t=e;if(Array.isArray(e)){var n=e.length;e=new Array(n);for(var r=0;r<n;r++)e[r]=_(t[r])}else{if(e instanceof Date)return e.toJSON();if(null!==e)for(var i in e={},t)if(Object.prototype.hasOwnProperty.call(t,i)){var o=t[i];void 0!==o&&(e[i]=_(o))}}}return e}function m(e){return k(e=_(e))+""+function(e){if(null!==e)switch(typeof e){case"boolean":return e?1:0;case"number":return function(e){if(0===e)return"1";var t,n=e.toExponential().split(/e\+?/),r=parseInt(n[1],10),i=e<0,o=i?"0":"2";o+=""+(function(e,t,n){for(var r="",i=3-e.length;r.length<i;)r+="0";return r}(t=((i?-r:r)- -324).toString())+t);var s=Math.abs(parseFloat(n[0]));i&&(s=10-s);var a=s.toFixed(20);return o+""+a.replace(/\.?0+$/,"")}(e);case"string":return e.replace(/\u0002/g,"").replace(/\u0001/g,"").replace(/\u0000/g,"");case"object":var t=Array.isArray(e),n=t?e:Object.keys(e),r=-1,i=n.length,o="";if(t)for(;++r<i;)o+=m(n[r]);else for(;++r<i;){var s=n[r];o+=m(s)+m(e[s])}return o}return""}(e)+"\0"}function b(e,t){var n,r=t;if("1"===e[t])n=0,t++;else{var i="0"===e[t];t++;var o="",s=e.substring(t,t+3),a=parseInt(s,10)+-324;for(i&&(a=-a),t+=3;;){var u=e[t];if("\0"===u)break;o+=u,t++}n=1===(o=o.split(".")).length?parseInt(o,10):parseFloat(o[0]+"."+o[1]),i&&(n-=10),0!==a&&(n=parseFloat(n+"e"+a))}return{num:n,length:t-r}}function w(e,t){var n=e.pop();if(t.length){var r=t[t.length-1];n===r.element&&(t.pop(),r=t[t.length-1]);var i=r.element,o=r.index;Array.isArray(i)?i.push(n):o===e.length-2?i[e.pop()]=n:e.push(n)}}function k(e){var t=["boolean","number","string","object"].indexOf(typeof e);return~t?null===e?1:Array.isArray(e)?5:t<3?t+2:t+3:Array.isArray(e)?5:void 0}var j=n(105),O=n.n(j),$=n(624),x=n.n($),q=n(187),A=n.n(q),S=n(586),E=n(322),P=n.n(E);function C(e){return P().hash(e)}self.setImmediate||self.setTimeout;var D,L=Function.prototype.toString,B=L.call(Object);function I(e){var t,n,r;if(!e||"object"!=typeof e)return e;if(Array.isArray(e)){for(t=[],n=0,r=e.length;n<r;n++)t[n]=I(e[n]);return t}if(e instanceof Date&&isFinite(e))return e.toISOString();if(function(e){return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Blob&&e instanceof Blob}(e))return function(e){if(e instanceof ArrayBuffer)return function(e){if("function"==typeof e.slice)return e.slice(0);var t=new ArrayBuffer(e.byteLength),n=new Uint8Array(t),r=new Uint8Array(e);return n.set(r),t}(e);var t=e.size,n=e.type;return"function"==typeof e.slice?e.slice(0,t,n):e.webkitSlice(0,t,n)}(e);if(!function(e){var t=Object.getPrototypeOf(e);if(null===t)return!0;var n=t.constructor;return"function"==typeof n&&n instanceof n&&L.call(n)==B}(e))return e;for(n in t={},e)if(Object.prototype.hasOwnProperty.call(e,n)){var i=I(e[n]);void 0!==i&&(t[n]=i)}return t}function T(e){return O()((function(t){t=I(t);var n=this,r="function"==typeof t[t.length-1]&&t.pop(),i=new Promise((function(r,i){var o,s,a;try{var u=(s=function(e,t){e?i(e):r(t)},a=!1,O()((function(e){if(a)throw new Error("once called more than once");a=!0,s.apply(this,e)})));t.push(u),(o=e.apply(n,t))&&"function"==typeof o.then&&r(o)}catch(e){i(e)}}));return r&&i.then((function(e){r(null,e)}),r),i}))}try{localStorage.setItem("_pouch_check_localstorage",1),D=!!localStorage.getItem("_pouch_check_localstorage")}catch(e){D=!1}function M(){return D}function N(){A().call(this),this._listeners={},function(e){M()&&addEventListener("storage",(function(t){e.emit(t.key)}))}(this)}function R(e){if("undefined"!=typeof console&&"function"==typeof console[e]){var t=Array.prototype.slice.call(arguments,1);console[e].apply(console,t)}}i()(N,A()),N.prototype.addListener=function(e,t,n,r){if(!this._listeners[t]){var i=this,o=!1;this._listeners[t]=s,this.on(e,s)}function s(){if(i._listeners[t])if(o)o="waiting";else{o=!0;var e=function(e,t){for(var n={},r=0,i=t.length;r<i;r++){var o=t[r];o in e&&(n[o]=e[o])}return n}(r,["style","include_docs","attachments","conflicts","filter","doc_ids","view","since","query_params","binary","return_docs"]);n.changes(e).on("change",(function(e){e.seq>r.since&&!r.cancelled&&(r.since=e.seq,r.onChange(e))})).on("complete",(function(){"waiting"===o&&x()(s),o=!1})).on("error",(function(){o=!1}))}}},N.prototype.removeListener=function(e,t){t in this._listeners&&(A().prototype.removeListener.call(this,e,this._listeners[t]),delete this._listeners[t])},N.prototype.notifyLocalWindows=function(e){M()&&(localStorage[e]="a"===localStorage[e]?"b":"a")},N.prototype.notify=function(e){this.emit(e),this.notifyLocalWindows(e)};var F="function"==typeof Object.assign?Object.assign:function(e){for(var t=Object(e),n=1;n<arguments.length;n++){var r=arguments[n];if(null!=r)for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t};function U(e){for(var t=[],n=0,r=e.length;n<r;n++)t=t.concat(e[n]);return t}function z(e){return"boolean"==typeof e._remote?e._remote:"function"==typeof e.type&&(R("warn","db.type() is deprecated and will be removed in a future version of PouchDB"),"http"===e.type())}function J(e,t,n){return e.get(t).catch((function(e){if(404!==e.status)throw e;return{}})).then((function(r){var i=r._rev,o=n(r);return o?(o._id=t,o._rev=i,function(e,t,n){return e.put(t).then((function(e){return{updated:!0,rev:e.rev}}),(function(r){if(409!==r.status)throw r;return J(e,t._id,n)}))}(e,o,n)):{updated:!1,rev:i}}))}function K(e){this.status=400,this.name="query_parse_error",this.message=e,this.error=!0;try{Error.captureStackTrace(this,K)}catch(e){}}function V(e){this.status=404,this.name="not_found",this.message=e,this.error=!0;try{Error.captureStackTrace(this,V)}catch(e){}}function Q(e){this.status=500,this.name="invalid_value",this.message=e,this.error=!0;try{Error.captureStackTrace(this,Q)}catch(e){}}function G(e,t){return t&&e.then((function(e){x()((function(){t(null,e)}))}),(function(e){x()((function(){t(e)}))})),e}function W(e,t){return function(){var n=arguments,r=this;return e.add((function(){return t.apply(r,n)}))}}function Z(e){var t=new u(e),n=new Array(t.size),r=-1;return t.forEach((function(e){n[++r]=e})),n}function X(e){var t=new Array(e.size),n=-1;return e.forEach((function(e,r){t[++n]=r})),t}function Y(){this.promise=new Promise((function(e){e()}))}function H(e){if(!e)return"undefined";switch(typeof e){case"function":case"string":return e.toString();default:return JSON.stringify(e)}}function ee(e,t,n,r,i,o){var s,a=function(e,t){return H(e)+H(t)+"undefined"}(n,r);if(!i&&(s=e._cachedViews=e._cachedViews||{})[a])return s[a];var u=e.info().then((function(u){var c=u.db_name+"-mrview-"+(i?"temp":C(a));return J(e,"_local/"+o,(function(e){e.views=e.views||{};var n=t;-1===n.indexOf("/")&&(n=t+"/"+t);var r=e.views[n]=e.views[n]||{};if(!r[c])return r[c]=!0,e})).then((function(){return e.registerDependentDatabase(c).then((function(t){var i=t.db;i.auto_compaction=!0;var o={name:c,db:i,sourceDB:e,adapter:e.adapter,mapFun:n,reduceFun:r};return o.db.get("_local/lastSeq").catch((function(e){if(404!==e.status)throw e})).then((function(e){return o.seq=e?e.seq:0,s&&o.db.once("destroyed",(function(){delete s[a]})),o}))}))}))}));return s&&(s[a]=u),u}S.Z,i()(K,Error),i()(V,Error),i()(Q,Error),Y.prototype.add=function(e){return this.promise=this.promise.catch((function(){})).then((function(){return e()})),this.promise},Y.prototype.finish=function(){return this.promise};var te={},ne=new Y;function re(e){return-1===e.indexOf("/")?[e,e]:e.split("/")}function ie(e,t){try{e.emit("error",t)}catch(e){R("error","The user's map/reduce function threw an uncaught error.\nYou can debug this error by doing:\nmyDatabase.on('error', function (err) { debugger; });\nPlease double-check your map/reduce function."),R("error",t)}}function oe(e,t){for(var n=e,r=0,i=t.length;r<i&&(n=n[t[r]]);r++);return n}function se(e,t,n){for(var r=0,i=t.length;r<i-1;r++){var o=t[r];e=e[o]=e[o]||{}}e[t[i-1]]=n}function ae(e,t){return e<t?-1:e>t?1:0}function ue(e){for(var t=[],n="",r=0,i=e.length;r<i;r++){var o=e[r];r>0&&"\\"===e[r-1]&&("$"===o||"."===o)?n=n.substring(0,n.length-1)+o:"."===o?(t.push(n),n=""):n+=o}return t.push(n),t}var ce=["$or","$nor","$not"];function fe(e){return ce.indexOf(e)>-1}function le(e){return Object.keys(e)[0]}function de(e){return e[le(e)]}function he(e){var t={},n={$or:!0,$nor:!0};return e.forEach((function(e){Object.keys(e).forEach((function(r){var i=e[r];if("object"!=typeof i&&(i={$eq:i}),fe(r))if(i instanceof Array){if(n[r])return n[r]=!1,void(t[r]=i);var o=[];t[r].forEach((function(e){Object.keys(i).forEach((function(t){var n=i[t],r=Math.max(Object.keys(e).length,Object.keys(n).length),s=he([e,n]);Object.keys(s).length<=r||o.push(s)}))})),t[r]=o}else t[r]=he([i]);else{var s=t[r]=t[r]||{};Object.keys(i).forEach((function(e){var t=i[e];return"$gt"===e||"$gte"===e?function(e,t,n){void 0===n.$eq&&(void 0!==n.$gte?"$gte"===e?t>n.$gte&&(n.$gte=t):t>=n.$gte&&(delete n.$gte,n.$gt=t):void 0!==n.$gt?"$gte"===e?t>n.$gt&&(delete n.$gt,n.$gte=t):t>n.$gt&&(n.$gt=t):n[e]=t)}(e,t,s):"$lt"===e||"$lte"===e?function(e,t,n){void 0===n.$eq&&(void 0!==n.$lte?"$lte"===e?t<n.$lte&&(n.$lte=t):t<=n.$lte&&(delete n.$lte,n.$lt=t):void 0!==n.$lt?"$lte"===e?t<n.$lt&&(delete n.$lt,n.$lte=t):t<n.$lt&&(n.$lt=t):n[e]=t)}(e,t,s):"$ne"===e?function(e,t){"$ne"in t?t.$ne.push(e):t.$ne=[e]}(t,s):"$eq"===e?function(e,t){delete t.$gt,delete t.$gte,delete t.$lt,delete t.$lte,delete t.$ne,t.$eq=e}(t,s):"$regex"===e?function(e,t){"$regex"in t?t.$regex.push(e):t.$regex=[e]}(t,s):void(s[e]=t)}))}}))})),t}function pe(e){for(var t in e){if(Array.isArray(e))for(var n in e)e[n].$and&&(e[n]=he(e[n].$and));var r=e[t];"object"==typeof r&&pe(r)}return e}function ve(e,t){for(var n in e){"$and"===n&&(t=!0);var r=e[n];"object"==typeof r&&(t=ve(r,t))}return t}function ye(e){var t=I(e),n=!1;ve(t,!1)&&("$and"in(t=pe(t))&&(t=he(t.$and)),n=!0),["$or","$nor"].forEach((function(e){e in t&&t[e].forEach((function(e){for(var t=Object.keys(e),n=0;n<t.length;n++){var r=t[n],i=e[r];"object"==typeof i&&null!==i||(e[r]={$eq:i})}}))})),"$not"in t&&(t.$not=he([t.$not]));for(var r=Object.keys(t),i=0;i<r.length;i++){var o=r[i],s=t[o];"object"!=typeof s||null===s?s={$eq:s}:n||("$ne"in s&&(s.$ne=[s.$ne]),"$regex"in s&&(s.$regex=[s.$regex])),t[o]=s}return t}function ge(e,t,n){if(e=e.filter((function(e){return _e(e.doc,t.selector,n)})),t.sort){var r=function(e){function t(t){return e.map((function(e){var n=ue(le(e));return oe(t,n)}))}return function(e,n){var r=g(t(e.doc),t(n.doc));return 0!==r?r:ae(e.doc._id,n.doc._id)}}(t.sort);e=e.sort(r),"string"!=typeof t.sort[0]&&"desc"===de(t.sort[0])&&(e=e.reverse())}if("limit"in t||"skip"in t){var i=t.skip||0,o=("limit"in t?t.limit:e.length)+i;e=e.slice(i,o)}return e}function _e(e,t,n){return n.every((function(n){var r=t[n],i=ue(n),o=oe(e,i);return fe(n)?function(e,t,n){return"$or"===e?t.some((function(e){return _e(n,e,Object.keys(e))})):"$not"===e?!_e(n,t,Object.keys(t)):!t.find((function(e){return _e(n,e,Object.keys(e))}))}(n,r,e):me(r,e,i,o)}))}function me(e,t,n,r){return!e||("object"==typeof e?Object.keys(e).every((function(i){var o=e[i];if(0===i.indexOf("$"))return be(i,t,o,n,r);var s=ue(i);if(void 0===r&&"object"!=typeof o&&s.length>0)return!1;var a=oe(r,s);return"object"==typeof o?me(o,t,n,a):be("$eq",t,o,s,a)})):e===r)}function be(e,t,n,r,i){if(!Oe[e])throw new Error('unknown operator "'+e+'" - should be one of $eq, $lte, $lt, $gt, $gte, $exists, $ne, $in, $nin, $size, $mod, $regex, $elemMatch, $type, $allMatch or $all');return Oe[e](t,n,r,i)}function we(e){return null!=e}function ke(e){return void 0!==e}function je(e,t){return t.some((function(t){return e instanceof Array?e.some((function(e){return 0===g(t,e)})):0===g(t,e)}))}var Oe={$elemMatch:function(e,t,n,r){return!!Array.isArray(r)&&0!==r.length&&("object"==typeof r[0]?r.some((function(e){return _e(e,t,Object.keys(t))})):r.some((function(r){return me(t,e,n,r)})))},$allMatch:function(e,t,n,r){return!!Array.isArray(r)&&0!==r.length&&("object"==typeof r[0]?r.every((function(e){return _e(e,t,Object.keys(t))})):r.every((function(r){return me(t,e,n,r)})))},$eq:function(e,t,n,r){return ke(r)&&0===g(r,t)},$gte:function(e,t,n,r){return ke(r)&&g(r,t)>=0},$gt:function(e,t,n,r){return ke(r)&&g(r,t)>0},$lte:function(e,t,n,r){return ke(r)&&g(r,t)<=0},$lt:function(e,t,n,r){return ke(r)&&g(r,t)<0},$exists:function(e,t,n,r){return t?ke(r):!ke(r)},$mod:function(e,t,n,r){return we(r)&&function(e,t){return"number"==typeof e&&parseInt(e,10)===e&&e%t[0]===t[1]}(r,t)},$ne:function(e,t,n,r){return t.every((function(e){return 0!==g(r,e)}))},$in:function(e,t,n,r){return we(r)&&je(r,t)},$nin:function(e,t,n,r){return we(r)&&!je(r,t)},$size:function(e,t,n,r){return we(r)&&Array.isArray(r)&&function(e,t){return e.length===t}(r,t)},$all:function(e,t,n,r){return Array.isArray(r)&&function(e,t){return t.every((function(t){return e.some((function(e){return 0===g(t,e)}))}))}(r,t)},$regex:function(e,t,n,r){return we(r)&&"string"==typeof r&&t.every((function(e){return function(e,t){return new RegExp(t).test(e)}(r,e)}))},$type:function(e,t,n,r){return function(e,t){switch(t){case"null":return null===e;case"boolean":return"boolean"==typeof e;case"number":return"number"==typeof e;case"string":return"string"==typeof e;case"array":return e instanceof Array;case"object":return"[object Object]"==={}.toString.call(e)}}(r,t)}};function $e(e,t){if("object"!=typeof t)throw new Error("Selector error: expected a JSON object");var n=ge([{doc:e}],{selector:t=ye(t)},Object.keys(t));return n&&1===n.length}function xe(e){return(e=I(e)).index||(e.index={}),["type","name","ddoc"].forEach((function(t){e.index[t]&&(e[t]=e.index[t],delete e.index[t])})),e.fields&&(e.index.fields=e.fields,delete e.fields),e.type||(e.type="json"),e}function qe(e,t,n){var r="",i=t,o=!0;if(-1!==["$in","$nin","$or","$and","$mod","$nor","$all"].indexOf(e)&&(Array.isArray(t)||(r="Query operator "+e+" must be an array.")),-1!==["$not","$elemMatch","$allMatch"].indexOf(e)&&(Array.isArray(t)||"object"!=typeof t||null===t)&&(r="Query operator "+e+" must be an object."),"$mod"===e&&Array.isArray(t))if(2!==t.length)r="Query operator $mod must be in the format [divisor, remainder], where divisor and remainder are both integers.";else{var s=t[0],a=t[1];0===s&&(r="Query operator $mod's divisor cannot be 0, cannot divide by zero.",o=!1),"number"==typeof s&&parseInt(s,10)===s||(r="Query operator $mod's divisor is not an integer.",i=s),parseInt(a,10)!==a&&(r="Query operator $mod's remainder is not an integer.",i=a)}if("$exists"===e&&"boolean"!=typeof t&&(r="Query operator $exists must be a boolean."),"$type"===e){var u=["null","boolean","number","string","array","object"],c='"'+u.slice(0,u.length-1).join('", "')+'", or "'+u[u.length-1]+'"';("string"!=typeof t||-1==u.indexOf(t))&&(r="Query operator $type must be a string. Supported values: "+c+".")}if("$size"===e&&parseInt(t,10)!==t&&(r="Query operator $size must be a integer."),"$regex"===e&&"string"!=typeof t&&(console.log("here",n),n?r="Query operator $regex must be a string.":t instanceof RegExp||(r="Query operator $regex must be a string or an instance of a javascript regular expression.")),r)throw o&&(r+=" Received"+(null===i?" ":Array.isArray(i)?" array":" "+typeof i)+": "+("object"==typeof i&&null!==i?JSON.stringify(i,null,"\t"):i)),new Error(r)}var Ae=["$all","$allMatch","$and","$elemMatch","$exists","$in","$mod","$nin","$nor","$not","$or","$regex","$size","$type"],Se=["$in","$nin","$mod","$all"],Ee=["$eq","$gt","$gte","$lt","$lte"];function Pe(e,t){if(Array.isArray(e))for(var n of e)"object"==typeof n&&null!==s&&Pe(n,t);else for(var r=Object.keys(e),i=0;i<r.length;i++){var o=r[i],s=e[o];-1!==Ae.indexOf(o)&&qe(o,s,t),-1===Ee.indexOf(o)&&-1===Se.indexOf(o)&&"object"==typeof s&&null!==s&&Pe(s,t)}}function Ce(e,t,n,r){var i,o;n.headers=new f({"Content-type":"application/json"}),e.fetch(t,n).then((function(e){return i=e.status,o=e.ok,e.json()})).then((function(e){if(o)r(null,e);else{e.status=i;var t=a(e);r(t)}})).catch(r)}function De(e,t,n){t=xe(t),Ce(e,"_index",{method:"POST",body:JSON.stringify(t)},n)}function Le(e,t,n){Pe(t.selector,!0),Ce(e,"_find",{method:"POST",body:JSON.stringify(t)},n)}function Be(e,t,n){Ce(e,"_explain",{method:"POST",body:JSON.stringify(t)},n)}function Ie(e,t){Ce(e,"_index",{method:"GET"},t)}function Te(e,t,n){var r=t.ddoc,i=t.type||"json",o=t.name;return r?o?void Ce(e,"_index/"+[r,i,o].map(encodeURIComponent).join("/"),{method:"DELETE"},n):n(new Error("you must provide an index's name")):n(new Error("you must provide an index's ddoc"))}function Me(e){return function(){for(var t=arguments.length,n=new Array(t),r=-1;++r<t;)n[r]=arguments[r];return e.call(this,n)}}function Ne(e){return Me((function(t){var n=t.pop(),r=e.apply(this,t);return function(e,t){e.then((function(e){x()((function(){t(null,e)}))}),(function(e){x()((function(){t(e)}))}))}(r,n),r}))}var Re=Me((function(e){for(var t=[],n=0,r=e.length;n<r;n++){var i=e[n];Array.isArray(i)?t=t.concat(Re.apply(null,i)):t.push(i)}return t}));function Fe(e){for(var t={},n=0,r=e.length;n<r;n++)t=F(t,e[n]);return t}function Ue(e,t){for(var n=0,r=Math.min(e.length,t.length);n<r;n++)if(e[n]!==t[n])return!1;return!0}function ze(e,t){if(e.length!==t.length)return!1;for(var n=0,r=e.length;n<r;n++)if(e[n]!==t[n])return!1;return!0}var Je=function(e,t,n,r){function i(e,t,n){try{t(n)}catch(t){ie(e,t)}}function o(e,t,n,r,i){try{return{output:t(n,r,i)}}catch(t){return ie(e,t),{error:t}}}function s(e,t){var n=g(e.key,t.key);return 0!==n?n:g(e.value,t.value)}function l(e,t,n){return n=n||0,"number"==typeof t?e.slice(n,t+n):n>0?e.slice(n):e}function d(e){var t=e.value;return t&&"object"==typeof t&&t._id||e.id}function h(e){return function(t){return e.include_docs&&e.attachments&&e.binary&&function(e){e.rows.forEach((function(e){var t=e.doc&&e.doc._attachments;t&&Object.keys(t).forEach((function(e){var n=t[e];t[e].data=y(n.data,n.content_type)}))}))}(t),t}}function p(e,t,n,r){var i=t[e];void 0!==i&&(r&&(i=encodeURIComponent(JSON.stringify(i))),n.push(e+"="+i))}function v(e){if(void 0!==e){var t=Number(e);return isNaN(t)||t!==parseInt(e,10)?e:t}}function k(e,t){var n=e.descending?"endkey":"startkey",r=e.descending?"startkey":"endkey";if(void 0!==e[n]&&void 0!==e[r]&&g(e[n],e[r])>0)throw new K("No rows can match your key range, reverse your start_key and end_key or set {descending : true}");if(t.reduce&&!1!==e.reduce){if(e.include_docs)throw new K("{include_docs:true} is invalid for reduce");if(e.keys&&e.keys.length>1&&!e.group&&!e.group_level)throw new K("Multi-key fetches for reduce views must use {group: true}")}["group_level","limit","skip"].forEach((function(t){var n=function(e){if(e){if("number"!=typeof e)return new K('Invalid value for integer: "'+e+'"');if(e<0)return new K('Invalid value for positive integer: "'+e+'"')}}(e[t]);if(n)throw n}))}function j(e){return function(t){if(404===t.status)return e;throw t}}function $(e){var t="string"==typeof e?e:e.name,n=te[t];return n||(n=te[t]=new Y),n}function q(e,n){return W($(e),(function(){return function(e,n){var r,o;var a=t(e.mapFun,(function(e,t){var n={id:o._id,key:_(e)};null!=t&&(n.value=_(t)),r.push(n)})),f=e.seq||0;function l(t,n){return function(){return function(e,t,n){var r="_local/lastSeq";return e.db.get(r).catch(j({_id:r,seq:0})).then((function(r){var i=X(t);return Promise.all(i.map((function(n){return function(e,t,n){var r,i="_local/doc_"+e,o={_id:i,keys:[]},s=n.get(e),a=s[0];return(r=s[1],1===r.length&&/^1-/.test(r[0].rev)?Promise.resolve(o):t.db.get(i).catch(j(o))).then((function(e){return function(e){return e.keys.length?t.db.allDocs({keys:e.keys,include_docs:!0}):Promise.resolve({rows:[]})}(e).then((function(t){return function(e,t){for(var n=[],r=new u,i=0,o=t.rows.length;i<o;i++){var s=t.rows[i].doc;if(s&&(n.push(s),r.add(s._id),s._deleted=!a.has(s._id),!s._deleted)){var c=a.get(s._id);"value"in c&&(s.value=c.value)}}var f=X(a);return f.forEach((function(e){if(!r.has(e)){var t={_id:e},i=a.get(e);"value"in i&&(t.value=i.value),n.push(t)}})),e.keys=Z(f.concat(e.keys)),n.push(e),n}(e,t)}))}))}(n,e,t)}))).then((function(t){var i=U(t);return r.seq=n,i.push(r),e.db.bulkDocs({docs:i})}))}))}(e,t,n)}}let d=0,h={view:e.name,indexed_docs:d};e.sourceDB.emit("indexing",h);var p=new Y;function v(){return e.sourceDB.changes({return_docs:!0,conflicts:!0,include_docs:!0,style:"all_docs",since:f,limit:n.changes_batch_size}).then(y)}function y(t){var u=t.results;if(!u.length)return;var h=function(t){for(var n=new c,u=0,l=t.length;u<l;u++){var d=t[u];if("_"!==d.doc._id[0]){r=[],(o=d.doc)._deleted||i(e.sourceDB,a,o),r.sort(s);var h=b(r);n.set(d.doc._id,[h,d.changes])}f=d.seq}return n}(u);p.add(l(h,f)),d+=u.length;let y={view:e.name,last_seq:t.last_seq,results_count:u.length,indexed_docs:d};return e.sourceDB.emit("indexing",y),u.length<n.changes_batch_size?void 0:v()}function b(e){for(var t,n=new c,r=0,i=e.length;r<i;r++){var o=e[r],s=[o.key,o.id];r>0&&0===g(o.key,t)&&s.push(r),n.set(m(s),o),t=o.key}return n}return v().then((function(){return p.finish()})).then((function(){e.seq=f}))}(e,n)}))()}function A(e,t){return W($(e),(function(){return function(e,t){var r,i=e.reduceFun&&!1!==t.reduce,s=t.skip||0;function a(t){return t.include_docs=!0,e.db.allDocs(t).then((function(e){return r=e.total_rows,e.rows.map((function(e){if("value"in e.doc&&"object"==typeof e.doc.value&&null!==e.doc.value){var t=Object.keys(e.doc.value).sort(),n=["id","key","value"];if(!(t<n||t>n))return e.doc.value}var r=function(e){for(var t=[],n=[],r=0;;){var i=e[r++];if("\0"!==i)switch(i){case"1":t.push(null);break;case"2":t.push("1"===e[r]),r++;break;case"3":var o=b(e,r);t.push(o.num),r+=o.length;break;case"4":for(var s="";;){var a=e[r];if("\0"===a)break;s+=a,r++}s=s.replace(/\u0001\u0001/g,"\0").replace(/\u0001\u0002/g,"").replace(/\u0002\u0002/g,""),t.push(s);break;case"5":var u={element:[],index:t.length};t.push(u.element),n.push(u);break;case"6":var c={element:{},index:t.length};t.push(c.element),n.push(c);break;default:throw new Error("bad collationIndex or unexpectedly reached end of input: "+i)}else{if(1===t.length)return t.pop();w(t,n)}}}(e.doc._id);return{key:r[0],id:r[1],value:"value"in e.doc?e.doc.value:null}}))}))}function u(a){var u;if(u=i?function(e,t,r){0===r.group_level&&delete r.group_level;var i=r.group||r.group_level,s=n(e.reduceFun),a=[],u=isNaN(r.group_level)?Number.POSITIVE_INFINITY:r.group_level;t.forEach((function(e){var t=a[a.length-1],n=i?e.key:null;if(i&&Array.isArray(n)&&(n=n.slice(0,u)),t&&0===g(t.groupKey,n))return t.keys.push([e.key,e.id]),void t.values.push(e.value);a.push({keys:[[e.key,e.id]],values:[e.value],groupKey:n})})),t=[];for(var c=0,f=a.length;c<f;c++){var d=a[c],h=o(e.sourceDB,s,d.keys,d.values,!1);if(h.error&&h.error instanceof Q)throw h.error;t.push({value:h.error?null:h.output,key:d.groupKey})}return{rows:l(t,r.limit,r.skip)}}(e,a,t):void 0===t.keys?{total_rows:r,offset:s,rows:a}:{total_rows:r,offset:s,rows:l(a,t.limit,t.skip)},t.update_seq&&(u.update_seq=e.seq),t.include_docs){var f=Z(a.map(d));return e.sourceDB.allDocs({keys:f,include_docs:!0,conflicts:t.conflicts,attachments:t.attachments,binary:t.binary}).then((function(e){var t=new c;return e.rows.forEach((function(e){t.set(e.id,e.doc)})),a.forEach((function(e){var n=d(e),r=t.get(n);r&&(e.doc=r)})),u}))}return u}if(void 0===t.keys||t.keys.length||(t.limit=0,delete t.keys),void 0!==t.keys){var f=t.keys.map((function(e){var n={startkey:m([e]),endkey:m([e,{}])};return t.update_seq&&(n.update_seq=!0),a(n)}));return Promise.all(f).then(U).then(u)}var h,p,v={descending:t.descending};if(t.update_seq&&(v.update_seq=!0),"start_key"in t&&(h=t.start_key),"startkey"in t&&(h=t.startkey),"end_key"in t&&(p=t.end_key),"endkey"in t&&(p=t.endkey),void 0!==h&&(v.startkey=t.descending?m([h,{}]):m([h])),void 0!==p){var y=!1!==t.inclusive_end;t.descending&&(y=!y),v.endkey=m(y?[p,{}]:[p])}if(void 0!==t.key){var _=m([t.key]),k=m([t.key,{}]);v.descending?(v.endkey=_,v.startkey=k):(v.startkey=_,v.endkey=k)}return i||("number"==typeof t.limit&&(v.limit=t.limit),v.skip=s),a(v).then(u)}(e,t)}))()}var S;return{query:function(t,n,i){var o=this;"function"==typeof n&&(i=n,n={}),n=n?function(e){return e.group_level=v(e.group_level),e.limit=v(e.limit),e.skip=v(e.skip),e}(n):{},"function"==typeof t&&(t={map:t});var s=Promise.resolve().then((function(){return function(t,n,i){if("function"==typeof t._query)return function(e,t,n){return new Promise((function(r,i){e._query(t,n,(function(e,t){if(e)return i(e);r(t)}))}))}(t,n,i);if(z(t))return function(e,t,n){var r,i,o,s=[],u="GET";if(p("reduce",n,s),p("include_docs",n,s),p("attachments",n,s),p("limit",n,s),p("descending",n,s),p("group",n,s),p("group_level",n,s),p("skip",n,s),p("stale",n,s),p("conflicts",n,s),p("startkey",n,s,!0),p("start_key",n,s,!0),p("endkey",n,s,!0),p("end_key",n,s,!0),p("inclusive_end",n,s),p("key",n,s,!0),p("update_seq",n,s),s=""===(s=s.join("&"))?"":"?"+s,void 0!==n.keys){var c="keys="+encodeURIComponent(JSON.stringify(n.keys));c.length+s.length+1<=2e3?s+=("?"===s[0]?"&":"?")+c:(u="POST","string"==typeof t?r={keys:n.keys}:t.keys=n.keys)}if("string"==typeof t){var l=re(t);return e.fetch("_design/"+l[0]+"/_view/"+l[1]+s,{headers:new f({"Content-Type":"application/json"}),method:u,body:JSON.stringify(r)}).then((function(e){return i=e.ok,o=e.status,e.json()})).then((function(e){if(!i)throw e.status=o,a(e);return e.rows.forEach((function(e){if(e.value&&e.value.error&&"builtin_reduce_error"===e.value.error)throw new Error(e.reason)})),e})).then(h(n))}return r=r||{},Object.keys(t).forEach((function(e){Array.isArray(t[e])?r[e]=t[e]:r[e]=t[e].toString()})),e.fetch("_temp_view"+s,{headers:new f({"Content-Type":"application/json"}),method:"POST",body:JSON.stringify(r)}).then((function(e){return i=e.ok,o=e.status,e.json()})).then((function(e){if(!i)throw e.status=o,a(e);return e})).then(h(n))}(t,n,i);var o={changes_batch_size:t.__opts.view_update_changes_batch_size||50};if("string"!=typeof n)return k(i,n),ne.add((function(){return ee(t,"temp_view/temp_view",n.map,n.reduce,!0,e).then((function(e){return t=q(e,o).then((function(){return A(e,i)})),n=function(){return e.db.destroy()},t.then((function(e){return n().then((function(){return e}))}),(function(e){return n().then((function(){throw e}))}));var t,n}))})),ne.finish();var s=n,u=re(s),c=u[0],l=u[1];return t.get("_design/"+c).then((function(n){var a=n.views&&n.views[l];if(!a)throw new V("ddoc "+n._id+" has no view named "+l);return r(n,l),k(i,a),ee(t,s,a.map,a.reduce,!1,e).then((function(e){return"ok"===i.stale||"update_after"===i.stale?("update_after"===i.stale&&x()((function(){q(e,o)})),A(e,i)):q(e,o).then((function(){return A(e,i)}))}))}))}(o,t,n)}));return G(s,i),s},viewCleanup:(S=function(){var t=this;return"function"==typeof t._viewCleanup?function(e){return new Promise((function(t,n){e._viewCleanup((function(e,r){if(e)return n(e);t(r)}))}))}(t):z(t)?function(e){return e.fetch("_view_cleanup",{headers:new f({"Content-Type":"application/json"}),method:"POST"}).then((function(e){return e.json()}))}(t):function(t){return t.get("_local/"+e).then((function(e){var n=new c;Object.keys(e.views).forEach((function(e){var t=re(e),r="_design/"+t[0],i=t[1],o=n.get(r);o||(o=new u,n.set(r,o)),o.add(i)}));var r={keys:X(n),include_docs:!0};return t.allDocs(r).then((function(r){var i={};r.rows.forEach((function(t){var r=t.key.substring(8);n.get(t.key).forEach((function(n){var o=r+"/"+n;e.views[o]||(o=n);var s=Object.keys(e.views[o]),a=t.doc&&t.doc.views&&t.doc.views[n];s.forEach((function(e){i[e]=i[e]||a}))}))}));var o=Object.keys(i).filter((function(e){return!i[e]})).map((function(e){return W($(e),(function(){return new t.constructor(e,t.__opts).destroy()}))()}));return Promise.all(o).then((function(){return{ok:!0}}))}))}),j({ok:!0}))}(t)},O()((function(e){var t=e.pop(),n=S.apply(this,e);return"function"==typeof t&&G(n,t),n})))}}("indexes",(function(e,t){return function(e,t,n){var r=function(e){for(var t=0,n=e.length;t<n;t++)if(-1!==e[t].indexOf("."))return!1;return!0}(e),i=1===e.length;return r?i?function(e,t,n){return function(r){n&&!$e(r,n)||t(r[e])}}(e[0],t,n):function(e,t,n){return function(r){if(!n||$e(r,n)){for(var i=[],o=0,s=e.length;o<s;o++)i.push(r[e[o]]);t(i)}}}(e,t,n):i?function(e,t,n){var r=ue(e);return function(e){if(!n||$e(e,n)){for(var i=e,o=0,s=r.length;o<s;o++)if(void 0===(i=i[r[o]]))return;t(i)}}}(e[0],t,n):function(e,t,n){return function(r){if(!n||$e(r,n)){for(var i=[],o=0,s=e.length;o<s;o++){for(var a=ue(e[o]),u=r,c=0,f=a.length;c<f;c++)if(void 0===(u=u[a[c]]))return;i.push(u)}t(i)}}}(e,t,n)}(Object.keys(e.fields),t,e.partial_filter_selector)}),(function(){throw new Error("reduce not supported")}),(function(e,t){var n=e.views[t];if(!n.map||!n.map.fields)throw new Error("ddoc "+e._id+" with view "+t+" doesn't have map.fields defined. maybe it wasn't created by this plugin?")}));function Ke(e){return e._customFindAbstractMapper||Je}function Ve(e){return e.fields=e.fields.map((function(e){if("string"==typeof e){var t={};return t[e]="asc",t}return e})),e}function Qe(e,t){for(var n=[],r=0;r<t.def.fields.length;r++){var i=le(t.def.fields[r]);n.push(e[i])}return n}function Ge(e){return e.allDocs({startkey:"_design/",endkey:"_design/￿",include_docs:!0}).then((function(e){var t={indexes:[{ddoc:null,name:"_all_docs",type:"special",def:{fields:[{_id:"asc"}]}}]};return t.indexes=Re(t.indexes,e.rows.filter((function(e){return"query"===e.doc.language})).map((function(e){return(void 0!==e.doc.views?Object.keys(e.doc.views):[]).map((function(t){var n=e.doc.views[t];return{ddoc:e.id,name:t,type:"json",def:Ve(n.options.def)}}))}))),t.indexes.sort((function(e,t){return ae(e.name,t.name)})),t.total_rows=t.indexes.length,t}))}var We=null,Ze={"￿":{}};const Xe={queryOpts:{limit:0,startkey:Ze,endkey:We},inMemoryFields:[]};function Ye(e,t){for(var n=e.def.fields.map(le),r=0,i=n.length;r<i;r++)if(t===n[r])return!0;return!1}function He(e,t){return"$eq"!==le(e[t])}function et(e,t){var n=t.def.fields.map(le);return e.slice().sort((function(e,t){var r=n.indexOf(e),i=n.indexOf(t);return-1===r&&(r=Number.MAX_VALUE),-1===i&&(i=Number.MAX_VALUE),ae(r,i)}))}function tt(e,t,n,r){var i=Re(e,function(e,t,n){for(var r=!1,i=0,o=(n=et(n,e)).length;i<o;i++){var s=n[i];if(r||!Ye(e,s))return n.slice(i);i<o-1&&He(t,s)&&(r=!0)}return[]}(t,n,r),function(e){var t=[];return Object.keys(e).forEach((function(n){var r=e[n];Object.keys(r).forEach((function(e){"$ne"===e&&t.push(n)}))})),t}(n));return et(function(e){for(var t={},n=0;n<e.length;n++)t["$"+e[n]]=!0;return Object.keys(t).map((function(e){return e.substring(1)}))}(i),t)}var nt=["$eq","$gt","$gte","$lt","$lte"];function rt(e){return-1===nt.indexOf(e)}function it(e,t,n,r){var i=e.def.fields.map(le);return!!function(e,t,n){if(t){var r=(s=e,!((o=t).length>s.length)&&Ue(o,s)),i=Ue(n,e);return r&&i}var o,s;return function(e,t){e=e.slice();for(var n=0,r=t.length;n<r;n++){var i=t[n];if(!e.length)break;var o=e.indexOf(i);if(-1===o)return!1;e.splice(o,1)}return!0}(n,e)}(i,t,n)&&function(e,t){var n=t[e[0]];return void 0===n||!(1===Object.keys(n).length&&"$ne"===le(n))}(i,r)}function ot(e,t){switch(e){case"$eq":return{startkey:t,endkey:t};case"$lte":return{endkey:t};case"$gte":return{startkey:t};case"$lt":return{endkey:t,inclusive_end:!1};case"$gt":return{startkey:t,inclusive_start:!1}}}function st(e,t){return t.defaultUsed?function(e){return{queryOpts:{startkey:null},inMemoryFields:[Object.keys(e)]}}(e):1===t.def.fields.length?function(e,t){var n,r=le(t.def.fields[0]),i=e[r]||{},o=[];return Object.keys(i).forEach((function(e){rt(e)&&o.push(r);var t=function(e,t){switch(e){case"$eq":return{key:t};case"$lte":return{endkey:t};case"$gte":return{startkey:t};case"$lt":return{endkey:t,inclusive_end:!1};case"$gt":return{startkey:t,inclusive_start:!1}}return{startkey:We}}(e,i[e]);n=n?Fe([n,t]):t})),{queryOpts:n,inMemoryFields:o}}(e,t):function(e,t){var n,r,i=t.def.fields.map(le),o=[],s=[],a=[];function u(e){!1!==n&&s.push(We),!1!==r&&a.push(Ze),o=i.slice(e)}for(var c=0,f=i.length;c<f;c++){var l=e[i[c]];if(!l||!Object.keys(l).length){u(c);break}if(Object.keys(l).some(rt)){u(c);break}if(c>0){var d="$gt"in l||"$gte"in l||"$lt"in l||"$lte"in l,h=Object.keys(e[i[c-1]]),p=ze(h,["$eq"]),v=ze(h,Object.keys(l));if(d&&!p&&!v){u(c);break}}for(var y=Object.keys(l),g=null,_=0;_<y.length;_++){var m=y[_],b=ot(m,l[m]);g=g?Fe([g,b]):b}s.push("startkey"in g?g.startkey:We),a.push("endkey"in g?g.endkey:Ze),"inclusive_start"in g&&(n=g.inclusive_start),"inclusive_end"in g&&(r=g.inclusive_end)}var w={startkey:s,endkey:a};return void 0!==n&&(w.inclusive_start=n),void 0!==r&&(w.inclusive_end=r),{queryOpts:w,inMemoryFields:o}}(e,t)}function at(e,t){var n=e.selector,r=e.sort;if(function(e){return Object.keys(e).map((function(t){return e[t]})).some((function(e){return"object"==typeof e&&0===Object.keys(e).length}))}(n))return F({},Xe,{index:t[0]});var i=function(e,t){var n,r=Object.keys(e),i=t?t.map(le):[];return n=r.length>=i.length?r:i,0===i.length?{fields:n}:{fields:n=n.sort((function(e,t){var n=i.indexOf(e);-1===n&&(n=Number.MAX_VALUE);var r=i.indexOf(t);return-1===r&&(r=Number.MAX_VALUE),n<r?-1:n>r?1:0})),sortOrder:t.map(le)}}(n,r),o=i.fields,s=function(e,t,n,r,i){var o=function(e,t,n,r){return r.filter((function(r){return it(r,n,t,e)}))}(e,t,n,r);if(0===o.length){if(i)throw{error:"no_usable_index",message:"There is no index available for this selector."};var s=r[0];return s.defaultUsed=!0,s}if(1===o.length&&!i)return o[0];var a=function(e){for(var t={},n=0,r=e.length;n<r;n++)t[e[n]]=!0;return t}(t);if(i){var u="_design/"+i[0],c=2===i.length&&i[1],f=o.find((function(e){return!(!c||e.ddoc!==u||c!==e.name)||e.ddoc===u}));if(!f)throw{error:"unknown_error",message:"Could not find that index or could not use that index for the query"};return f}return function(e,t){for(var n=null,r=-1,i=0,o=e.length;i<o;i++){var s=e[i],a=t(s);a>r&&(r=a,n=s)}return n}(o,(function(e){for(var t=e.def.fields.map(le),n=0,r=0,i=t.length;r<i;r++){var o=t[r];a[o]&&n++}return n}))}(n,o,i.sortOrder,t,e.use_index),a=st(n,s);return{queryOpts:a.queryOpts,index:s,inMemoryFields:tt(a.inMemoryFields,s,n,o)}}function ut(e,t,n){var r,i;return t.selector&&(Pe(t.selector,!1),t.selector=ye(t.selector)),t.sort&&(t.sort=function(e){if(!Array.isArray(e))throw new Error("invalid sort json - should be an array");return e.map((function(e){if("string"==typeof e){var t={};return t[e]="asc",t}return e}))}(t.sort)),t.use_index&&(t.use_index=(i=[],"string"==typeof(r=t.use_index)?i.push(r):i=r,i.map((function(e){return e.replace("_design/","")})))),function(e){if("object"!=typeof e.selector)throw new Error("you must provide a selector when you find()")}(t),Ge(e).then((function(r){e.constructor.emit("debug",["find","planning query",t]);var i=at(t,r.indexes);e.constructor.emit("debug",["find","query plan",i]);var o=i.index;!function(e,t){if(t.defaultUsed&&e.sort){var n=e.sort.filter((function(e){return"_id"!==Object.keys(e)[0]})).map((function(e){return Object.keys(e)[0]}));if(n.length>0)throw new Error('Cannot sort on field(s) "'+n.join(",")+'" when using the default index')}t.defaultUsed}(t,o);var s=F({include_docs:!0,reduce:!1,indexes_count:r.total_rows},i.queryOpts);return"startkey"in s&&"endkey"in s&&g(s.startkey,s.endkey)>0?{docs:[]}:(t.sort&&"string"!=typeof t.sort[0]&&"desc"===de(t.sort[0])&&(s.descending=!0,s=function(e){var t=I(e);return delete t.startkey,delete t.endkey,delete t.inclusive_start,delete t.inclusive_end,"endkey"in e&&(t.startkey=e.endkey),"startkey"in e&&(t.endkey=e.startkey),"inclusive_start"in e&&(t.inclusive_end=e.inclusive_start),"inclusive_end"in e&&(t.inclusive_start=e.inclusive_end),t}(s)),i.inMemoryFields.length||("limit"in t&&(s.limit=t.limit),"skip"in t&&(s.skip=t.skip)),n?Promise.resolve(i,s):Promise.resolve().then((function(){if("_all_docs"===o.name)return function(e,t){var n=I(t);return n.descending?("endkey"in n&&"string"!=typeof n.endkey&&(n.endkey=""),"startkey"in n&&"string"!=typeof n.startkey&&(n.limit=0)):("startkey"in n&&"string"!=typeof n.startkey&&(n.startkey=""),"endkey"in n&&"string"!=typeof n.endkey&&(n.limit=0)),"key"in n&&"string"!=typeof n.key&&(n.limit=0),n.limit>0&&n.indexes_count&&(n.original_limit=n.limit,n.limit+=n.indexes_count),e.allDocs(n).then((function(e){return e.rows=e.rows.filter((function(e){return!/^_design\//.test(e.id)})),n.original_limit&&(n.limit=n.original_limit),e.rows=e.rows.slice(0,n.limit),e}))}(e,s);var t,n=(t=o).ddoc.substring(8)+"/"+t.name;return Ke(e).query.call(e,n,s)})).then((function(e){!1===s.inclusive_start&&(e.rows=function(e,t,n){for(var r=n.def.fields,i=0,o=e.length;i<o;i++){var s=Qe(e[i].doc,n);if(1===r.length)s=s[0];else for(;s.length>t.length;)s.pop();if(Math.abs(g(s,t))>0)break}return i>0?e.slice(i):e}(e.rows,s.startkey,o)),i.inMemoryFields.length&&(e.rows=ge(e.rows,t,i.inMemoryFields));var n={docs:e.rows.map((function(e){var n=e.doc;return t.fields?function(e,t){for(var n={},r=0,i=t.length;r<i;r++){var o=ue(t[r]),s=oe(e,o);void 0!==s&&se(n,o,s)}return n}(n,t.fields):n}))};return o.defaultUsed&&(n.warning="No matching index found, create an index to optimize query time."),n})))}))}var ct=Ne((function(e,t){var n,r=I((t=xe(t)).index);function i(){return n||(n=C(JSON.stringify(t)))}t.index=Ve(t.index),function(e){var t=e.fields.filter((function(e){return"asc"===de(e)}));if(0!==t.length&&t.length!==e.fields.length)throw new Error("unsupported mixed sorting")}(t.index);var o=t.name||"idx-"+i(),s=t.ddoc||"idx-"+i(),a="_design/"+s,u=!1,c=!1;return e.constructor.emit("debug",["find","creating index",a]),J(e,a,(function(e){return e._rev&&"query"!==e.language&&(u=!0),e.language="query",e.views=e.views||{},!(c=!!e.views[o])&&(e.views[o]={map:{fields:Fe(t.index.fields)},reduce:"_count",options:{def:r}},e)})).then((function(){if(u)throw new Error('invalid language for ddoc with id "'+a+'" (should be "query")')})).then((function(){var t=s+"/"+o;return Ke(e).query.call(e,t,{limit:0,reduce:!1}).then((function(){return{id:a,name:o,result:c?"exists":"created"}}))}))})),ft=Ne(ut),lt=Ne((function(e,t){return ut(e,t,!0).then((function(n){return{dbname:e.name,index:n.index,selector:t.selector,range:{start_key:n.queryOpts.startkey,end_key:n.queryOpts.endkey},opts:{use_index:t.use_index||[],bookmark:"nil",limit:t.limit,skip:t.skip,sort:t.sort||{},fields:t.fields,conflicts:!1,r:[49]},limit:t.limit,skip:t.skip||0,fields:t.fields}}))})),dt=Ne(Ge),ht=Ne((function(e,t){if(!t.ddoc)throw new Error("you must supply an index.ddoc when deleting");if(!t.name)throw new Error("you must supply an index.name when deleting");var n=t.ddoc,r=t.name;return J(e,n,(function(e){return 1===Object.keys(e.views).length&&e.views[r]?{_id:n,_deleted:!0}:(delete e.views[r],e)})).then((function(){return Ke(e).viewCleanup.apply(e)})).then((function(){return{ok:!0}}))})),pt={};pt.createIndex=T((function(e,t){if("object"!=typeof e)return t(new Error("you must provide an index to create"));(z(this)?De:ct)(this,e,t)})),pt.find=T((function(e,t){if(void 0===t&&(t=e,e=void 0),"object"!=typeof e)return t(new Error("you must provide search parameters to find()"));(z(this)?Le:ft)(this,e,t)})),pt.explain=T((function(e,t){if(void 0===t&&(t=e,e=void 0),"object"!=typeof e)return t(new Error("you must provide search parameters to explain()"));(z(this)?Be:lt)(this,e,t)})),pt.getIndexes=T((function(e){(z(this)?Ie:dt)(this,e)})),pt.deleteIndex=T((function(e,t){if("object"!=typeof e)return t(new Error("you must provide an index to delete"));(z(this)?Te:ht)(this,e,t)}));const vt=pt},552:e=>{function t(e,t){return function(...n){function r(){let r=null;const i="query"===t?1:0;n.length>i&&"function"==typeof n[n.length-1]&&(r=n.pop());let o=e._originals[t].bind(e);for(const n of e._handlers[t])o=n.bind(e,o);const s=o(...n);return s.then&&r&&function(e,t){e.then(((...e)=>{t(null,...e)})).catch((e=>{t(e)}))}(s,r),s}return"changes"!==t&&e.taskqueue&&!e.taskqueue.isReady?new Promise(((t,n)=>{e.taskqueue.addTask((e=>{e?n(e):t()}))})).then(r):r()}}const n={install:function(e,n={}){e._originals&&e._handlers||(e._originals={},e._handlers={});for(const[r,i]of Object.entries(n)){if(!(r in e))throw new Error(`Method '${r}' does not exist on given base, so it cannot be wrapped.`);r in e._originals||(e._originals[r]=e[r]),r in e._handlers?e._handlers[r].unshift(i):(e._handlers[r]=[i],e[r]=t(e,r))}},uninstall:function(e,t){if(!e._originals||!e._handlers)throw new Error("No wrapper methods installed, so no methods can be uninstalled.");for(const[n,r]of Object.entries(t)){const t=`Wrapper method for '${n}' not installed: ${r.toString()}`;if(!(n in e._handlers))throw new Error(t);const i=e._handlers[n].indexOf(r);if(-1===i)throw new Error(t);e._handlers[n].splice(i,1)}}};try{e.exports=n}catch{}try{window.PouchDBWrappers=n}catch{}},322:e=>{e.exports=function(e){var t=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function n(e,t){var n=e[0],r=e[1],i=e[2],o=e[3];r=((r+=((i=((i+=((o=((o+=((n=((n+=(r&i|~r&o)+t[0]-680876936|0)<<7|n>>>25)+r|0)&r|~n&i)+t[1]-389564586|0)<<12|o>>>20)+n|0)&n|~o&r)+t[2]+606105819|0)<<17|i>>>15)+o|0)&o|~i&n)+t[3]-1044525330|0)<<22|r>>>10)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r&i|~r&o)+t[4]-176418897|0)<<7|n>>>25)+r|0)&r|~n&i)+t[5]+1200080426|0)<<12|o>>>20)+n|0)&n|~o&r)+t[6]-1473231341|0)<<17|i>>>15)+o|0)&o|~i&n)+t[7]-45705983|0)<<22|r>>>10)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r&i|~r&o)+t[8]+1770035416|0)<<7|n>>>25)+r|0)&r|~n&i)+t[9]-1958414417|0)<<12|o>>>20)+n|0)&n|~o&r)+t[10]-42063|0)<<17|i>>>15)+o|0)&o|~i&n)+t[11]-1990404162|0)<<22|r>>>10)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r&i|~r&o)+t[12]+1804603682|0)<<7|n>>>25)+r|0)&r|~n&i)+t[13]-40341101|0)<<12|o>>>20)+n|0)&n|~o&r)+t[14]-1502002290|0)<<17|i>>>15)+o|0)&o|~i&n)+t[15]+1236535329|0)<<22|r>>>10)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r&o|i&~o)+t[1]-165796510|0)<<5|n>>>27)+r|0)&i|r&~i)+t[6]-1069501632|0)<<9|o>>>23)+n|0)&r|n&~r)+t[11]+643717713|0)<<14|i>>>18)+o|0)&n|o&~n)+t[0]-373897302|0)<<20|r>>>12)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r&o|i&~o)+t[5]-701558691|0)<<5|n>>>27)+r|0)&i|r&~i)+t[10]+38016083|0)<<9|o>>>23)+n|0)&r|n&~r)+t[15]-660478335|0)<<14|i>>>18)+o|0)&n|o&~n)+t[4]-405537848|0)<<20|r>>>12)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r&o|i&~o)+t[9]+568446438|0)<<5|n>>>27)+r|0)&i|r&~i)+t[14]-1019803690|0)<<9|o>>>23)+n|0)&r|n&~r)+t[3]-187363961|0)<<14|i>>>18)+o|0)&n|o&~n)+t[8]+1163531501|0)<<20|r>>>12)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r&o|i&~o)+t[13]-1444681467|0)<<5|n>>>27)+r|0)&i|r&~i)+t[2]-51403784|0)<<9|o>>>23)+n|0)&r|n&~r)+t[7]+1735328473|0)<<14|i>>>18)+o|0)&n|o&~n)+t[12]-1926607734|0)<<20|r>>>12)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r^i^o)+t[5]-378558|0)<<4|n>>>28)+r|0)^r^i)+t[8]-2022574463|0)<<11|o>>>21)+n|0)^n^r)+t[11]+1839030562|0)<<16|i>>>16)+o|0)^o^n)+t[14]-35309556|0)<<23|r>>>9)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r^i^o)+t[1]-1530992060|0)<<4|n>>>28)+r|0)^r^i)+t[4]+1272893353|0)<<11|o>>>21)+n|0)^n^r)+t[7]-155497632|0)<<16|i>>>16)+o|0)^o^n)+t[10]-1094730640|0)<<23|r>>>9)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r^i^o)+t[13]+681279174|0)<<4|n>>>28)+r|0)^r^i)+t[0]-358537222|0)<<11|o>>>21)+n|0)^n^r)+t[3]-722521979|0)<<16|i>>>16)+o|0)^o^n)+t[6]+76029189|0)<<23|r>>>9)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r^i^o)+t[9]-640364487|0)<<4|n>>>28)+r|0)^r^i)+t[12]-421815835|0)<<11|o>>>21)+n|0)^n^r)+t[15]+530742520|0)<<16|i>>>16)+o|0)^o^n)+t[2]-995338651|0)<<23|r>>>9)+i|0,r=((r+=((o=((o+=(r^((n=((n+=(i^(r|~o))+t[0]-198630844|0)<<6|n>>>26)+r|0)|~i))+t[7]+1126891415|0)<<10|o>>>22)+n|0)^((i=((i+=(n^(o|~r))+t[14]-1416354905|0)<<15|i>>>17)+o|0)|~n))+t[5]-57434055|0)<<21|r>>>11)+i|0,r=((r+=((o=((o+=(r^((n=((n+=(i^(r|~o))+t[12]+1700485571|0)<<6|n>>>26)+r|0)|~i))+t[3]-1894986606|0)<<10|o>>>22)+n|0)^((i=((i+=(n^(o|~r))+t[10]-1051523|0)<<15|i>>>17)+o|0)|~n))+t[1]-2054922799|0)<<21|r>>>11)+i|0,r=((r+=((o=((o+=(r^((n=((n+=(i^(r|~o))+t[8]+1873313359|0)<<6|n>>>26)+r|0)|~i))+t[15]-30611744|0)<<10|o>>>22)+n|0)^((i=((i+=(n^(o|~r))+t[6]-1560198380|0)<<15|i>>>17)+o|0)|~n))+t[13]+1309151649|0)<<21|r>>>11)+i|0,r=((r+=((o=((o+=(r^((n=((n+=(i^(r|~o))+t[4]-145523070|0)<<6|n>>>26)+r|0)|~i))+t[11]-1120210379|0)<<10|o>>>22)+n|0)^((i=((i+=(n^(o|~r))+t[2]+718787259|0)<<15|i>>>17)+o|0)|~n))+t[9]-343485551|0)<<21|r>>>11)+i|0,e[0]=n+e[0]|0,e[1]=r+e[1]|0,e[2]=i+e[2]|0,e[3]=o+e[3]|0}function r(e){var t,n=[];for(t=0;t<64;t+=4)n[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return n}function i(e){var t,n=[];for(t=0;t<64;t+=4)n[t>>2]=e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24);return n}function o(e){var t,i,o,s,a,u,c=e.length,f=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=c;t+=64)n(f,r(e.substring(t-64,t)));for(i=(e=e.substring(t-64)).length,o=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;t<i;t+=1)o[t>>2]|=e.charCodeAt(t)<<(t%4<<3);if(o[t>>2]|=128<<(t%4<<3),t>55)for(n(f,o),t=0;t<16;t+=1)o[t]=0;return s=(s=8*c).toString(16).match(/(.*?)(.{0,8})$/),a=parseInt(s[2],16),u=parseInt(s[1],16)||0,o[14]=a,o[15]=u,n(f,o),f}function s(e){var n,r="";for(n=0;n<4;n+=1)r+=t[e>>8*n+4&15]+t[e>>8*n&15];return r}function a(e){var t;for(t=0;t<e.length;t+=1)e[t]=s(e[t]);return e.join("")}function u(e){return/[\u0080-\uFFFF]/.test(e)&&(e=unescape(encodeURIComponent(e))),e}function c(e){var t,n=[],r=e.length;for(t=0;t<r-1;t+=2)n.push(parseInt(e.substr(t,2),16));return String.fromCharCode.apply(String,n)}function f(){this.reset()}return a(o("hello")),"undefined"==typeof ArrayBuffer||ArrayBuffer.prototype.slice||function(){function e(e,t){return(e=0|e||0)<0?Math.max(e+t,0):Math.min(e,t)}ArrayBuffer.prototype.slice=function(t,n){var r,i,o,s,a=this.byteLength,u=e(t,a),c=a;return undefined!==n&&(c=e(n,a)),u>c?new ArrayBuffer(0):(r=c-u,i=new ArrayBuffer(r),o=new Uint8Array(i),s=new Uint8Array(this,u,r),o.set(s),i)}}(),f.prototype.append=function(e){return this.appendBinary(u(e)),this},f.prototype.appendBinary=function(e){this._buff+=e,this._length+=e.length;var t,i=this._buff.length;for(t=64;t<=i;t+=64)n(this._hash,r(this._buff.substring(t-64,t)));return this._buff=this._buff.substring(t-64),this},f.prototype.end=function(e){var t,n,r=this._buff,i=r.length,o=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<i;t+=1)o[t>>2]|=r.charCodeAt(t)<<(t%4<<3);return this._finish(o,i),n=a(this._hash),e&&(n=c(n)),this.reset(),n},f.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},f.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},f.prototype.setState=function(e){return this._buff=e.buff,this._length=e.length,this._hash=e.hash,this},f.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},f.prototype._finish=function(e,t){var r,i,o,s=t;if(e[s>>2]|=128<<(s%4<<3),s>55)for(n(this._hash,e),s=0;s<16;s+=1)e[s]=0;r=(r=8*this._length).toString(16).match(/(.*?)(.{0,8})$/),i=parseInt(r[2],16),o=parseInt(r[1],16)||0,e[14]=i,e[15]=o,n(this._hash,e)},f.hash=function(e,t){return f.hashBinary(u(e),t)},f.hashBinary=function(e,t){var n=a(o(e));return t?c(n):n},f.ArrayBuffer=function(){this.reset()},f.ArrayBuffer.prototype.append=function(e){var t,r,o,s,a,u=(r=this._buff.buffer,o=e,s=!0,(a=new Uint8Array(r.byteLength+o.byteLength)).set(new Uint8Array(r)),a.set(new Uint8Array(o),r.byteLength),s?a:a.buffer),c=u.length;for(this._length+=e.byteLength,t=64;t<=c;t+=64)n(this._hash,i(u.subarray(t-64,t)));return this._buff=t-64<c?new Uint8Array(u.buffer.slice(t-64)):new Uint8Array(0),this},f.ArrayBuffer.prototype.end=function(e){var t,n,r=this._buff,i=r.length,o=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<i;t+=1)o[t>>2]|=r[t]<<(t%4<<3);return this._finish(o,i),n=a(this._hash),e&&(n=c(n)),this.reset(),n},f.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},f.ArrayBuffer.prototype.getState=function(){var e,t=f.prototype.getState.call(this);return t.buff=(e=t.buff,String.fromCharCode.apply(null,new Uint8Array(e))),t},f.ArrayBuffer.prototype.setState=function(e){return e.buff=function(e,t){var n,r=e.length,i=new ArrayBuffer(r),o=new Uint8Array(i);for(n=0;n<r;n+=1)o[n]=e.charCodeAt(n);return t?o:i}(e.buff,!0),f.prototype.setState.call(this,e)},f.ArrayBuffer.prototype.destroy=f.prototype.destroy,f.ArrayBuffer.prototype._finish=f.prototype._finish,f.ArrayBuffer.hash=function(e,t){var r=a(function(e){var t,r,o,s,a,u,c=e.length,f=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=c;t+=64)n(f,i(e.subarray(t-64,t)));for(r=(e=t-64<c?e.subarray(t-64):new Uint8Array(0)).length,o=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;t<r;t+=1)o[t>>2]|=e[t]<<(t%4<<3);if(o[t>>2]|=128<<(t%4<<3),t>55)for(n(f,o),t=0;t<16;t+=1)o[t]=0;return s=(s=8*c).toString(16).match(/(.*?)(.{0,8})$/),a=parseInt(s[2],16),u=parseInt(s[1],16)||0,o[14]=a,o[15]=u,n(f,o),f}(new Uint8Array(e)));return t?c(r):r},f}()},380:(e,t,n)=>{const r=n(552);function i(e){return"_"!==e[0]}function o(e){return!("string"!=typeof e._id||!/^_local/.test(e._id))||!!e._deleted&&0===Object.keys(e).filter(i).length}function s(e){const t=function(t){return!o(t)&&e.incoming?e.incoming(t):t},n=function(t){return!o(t)&&e.outgoing?e.outgoing(t):t},i={async get(e,...t){const r=await e(...t);return Array.isArray(r)?(await Promise.all(r.map((async e=>{e.ok&&(e.ok=await n(e.ok))}))),r):n(r)},bulkDocs:async(e,n,...r)=>(n.docs?n.docs=await Promise.all(n.docs.map(t)):n=await Promise.all(n.map(t)),e(n,...r)),async allDocs(e,...t){const r=await e(...t);return await Promise.all(r.rows.map((async e=>{e.doc&&(e.doc=await n(e.doc))}))),r},async bulkGet(e,...t){const r=async e=>e.ok?{ok:await n(e.ok)}:e;let{results:i,...o}=await e(...t);return i=await Promise.all(i.map((async e=>{const{id:t,docs:n}=e;return t&&n&&Array.isArray(n)?{id:t,docs:await Promise.all(n.map(r))}:e}))),{results:i,...o}},changes(e,...t){async function r(e){return e.doc?(e.doc=await n(e.doc),e):e}async function i(e){return e.results?(e.results=await Promise.all(e.results.map(r)),e):e}const o=e(...t),{on:s,then:a}=o;return Object.assign(o,{on(e,t){const n=t;return"change"===e?t=async e=>{n(await r(e))}:"complete"===e&&(t=async e=>{n(await i(e))}),s.call(o,e,t)},then:(e,t)=>a.call(o,i).then(e,t)})}};"http"===this.type()&&(i.put=async function(e,n,...r){return e(n=await t(n),...r)},i.query=async function(e,...t){const r=await e(...t);return await Promise.all(r.rows.map((async e=>{e.doc&&(e.doc=await n(e.doc))}))),r}),r.install(this,i)}e.exports={transform:s,filter:s},"undefined"!=typeof window&&window.PouchDB&&window.PouchDB.plugin(t)},586:(e,t,n)=>{var r;n.d(t,{Z:()=>f});var i=new Uint8Array(16);function o(){if(!r&&!(r="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return r(i)}const s=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i,a=function(e){return"string"==typeof e&&s.test(e)};for(var u=[],c=0;c<256;++c)u.push((c+256).toString(16).substr(1));const f=function(e,t,n){var r=(e=e||{}).random||(e.rng||o)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(var i=0;i<16;++i)t[n+i]=r[i];return t}return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(u[e[t+0]]+u[e[t+1]]+u[e[t+2]]+u[e[t+3]]+"-"+u[e[t+4]]+u[e[t+5]]+"-"+u[e[t+6]]+u[e[t+7]]+"-"+u[e[t+8]]+u[e[t+9]]+"-"+u[e[t+10]]+u[e[t+11]]+u[e[t+12]]+u[e[t+13]]+u[e[t+14]]+u[e[t+15]]).toLowerCase();if(!a(n))throw TypeError("Stringified UUID is invalid");return n}(r)}},684:(e,t)=>{function n(e,t,n){var r=n[n.length-1];e===r.element&&(n.pop(),r=n[n.length-1]);var i=r.element,o=r.index;Array.isArray(i)?i.push(e):o===t.length-2?i[t.pop()]=e:t.push(e)}t.stringify=function(e){var t=[];t.push({obj:e});for(var n,r,i,o,s,a,u,c,f,l,d="";n=t.pop();)if(r=n.obj,d+=n.prefix||"",i=n.val||"")d+=i;else if("object"!=typeof r)d+=void 0===r?null:JSON.stringify(r);else if(null===r)d+="null";else if(Array.isArray(r)){for(t.push({val:"]"}),o=r.length-1;o>=0;o--)s=0===o?"":",",t.push({obj:r[o],prefix:s});t.push({val:"["})}else{for(u in a=[],r)r.hasOwnProperty(u)&&a.push(u);for(t.push({val:"}"}),o=a.length-1;o>=0;o--)f=r[c=a[o]],l=o>0?",":"",l+=JSON.stringify(c)+":",t.push({obj:f,prefix:l});t.push({val:"{"})}return d},t.parse=function(e){for(var t,r,i,o,s,a,u,c,f,l=[],d=[],h=0;;)if("}"!==(t=e[h++])&&"]"!==t&&void 0!==t)switch(t){case" ":case"\t":case"\n":case":":case",":break;case"n":h+=3,n(null,l,d);break;case"t":h+=3,n(!0,l,d);break;case"f":h+=4,n(!1,l,d);break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":case"-":for(r="",h--;;){if(i=e[h++],!/[\d\.\-e\+]/.test(i)){h--;break}r+=i}n(parseFloat(r),l,d);break;case'"':for(o="",s=void 0,a=0;'"'!==(u=e[h++])||"\\"===s&&a%2==1;)o+=u,"\\"===(s=u)?a++:a=0;n(JSON.parse('"'+o+'"'),l,d);break;case"[":c={element:[],index:l.length},l.push(c.element),d.push(c);break;case"{":f={element:{},index:l.length},l.push(f.element),d.push(f);break;default:throw new Error("unexpectedly reached end of input: "+t)}else{if(1===l.length)return l.pop();n(l.pop(),l,d)}}},525:()=>{}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,n),o.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var r={};(()=>{n.d(r,{o:()=>o});const e=n(198).Z,t=n(614).Z,i=n(380),o=e.plugin(t).plugin(i)})();var i=r.o;export{i as PouchDB};