forked from pouchdb/pouchdb
/
pouchdb.min.js
11 lines (11 loc) · 141 KB
/
pouchdb.min.js
1
2
3
4
5
6
7
8
9
10
11
// PouchDB 5.4.5
//
// (c) 2012-2016 Dale Harvey and the PouchDB team
// PouchDB may be freely distributed under the Apache license, version 2.0.
// For all details and documentation:
// http://pouchdb.com
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;t="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,t.PouchDB=e()}}(function(){var e;return function t(e,n,r){function o(a,s){if(!n[a]){if(!e[a]){var u="function"==typeof require&&require;if(!s&&u)return u(a,!0);if(i)return i(a,!0);var c=new Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c}var f=n[a]={exports:{}};e[a][0].call(f.exports,function(t){var n=e[a][1][t];return o(n?n:t)},f,f.exports,t,e,n,r)}return n[a].exports}for(var i="function"==typeof require&&require,a=0;a<r.length;a++)o(r[a]);return o}({1:[function(e,t,n){function r(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function o(e){return"function"==typeof e}function i(e){return"number"==typeof e}function a(e){return"object"==typeof e&&null!==e}function s(e){return void 0===e}t.exports=r,r.EventEmitter=r,r.prototype._events=void 0,r.prototype._maxListeners=void 0,r.defaultMaxListeners=10,r.prototype.setMaxListeners=function(e){if(!i(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.prototype.emit=function(e){var t,n,r,i,u,c;if(this._events||(this._events={}),"error"===e&&(!this._events.error||a(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;var f=new Error('Uncaught, unspecified "error" event. ('+t+")");throw f.context=t,f}if(n=this._events[e],s(n))return!1;if(o(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:i=Array.prototype.slice.call(arguments,1),n.apply(this,i)}else if(a(n))for(i=Array.prototype.slice.call(arguments,1),c=n.slice(),r=c.length,u=0;r>u;u++)c[u].apply(this,i);return!0},r.prototype.addListener=function(e,t){var n;if(!o(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,o(t.listener)?t.listener:t),this._events[e]?a(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,a(this._events[e])&&!this._events[e].warned&&(n=s(this._maxListeners)?r.defaultMaxListeners:this._maxListeners,n&&n>0&&this._events[e].length>n&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())),this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(e,t){function n(){this.removeListener(e,n),r||(r=!0,t.apply(this,arguments))}if(!o(t))throw TypeError("listener must be a function");var r=!1;return n.listener=t,this.on(e,n),this},r.prototype.removeListener=function(e,t){var n,r,i,s;if(!o(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],i=n.length,r=-1,n===t||o(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(a(n)){for(s=i;s-- >0;)if(n[s]===t||n[s].listener&&n[s].listener===t){r=s;break}if(0>r)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(r,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],o(n))this.removeListener(e,n);else if(n)for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},r.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?o(this._events[e])?[this._events[e]]:this._events[e].slice():[]},r.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(o(t))return 1;if(t)return t.length}return 0},r.listenerCount=function(e,t){return e.listenerCount(t)}},{}],2:[function(e,t,n){function r(){d&&f&&(d=!1,f.length?l=f.concat(l):h=-1,l.length&&o())}function o(){if(!d){var e=s(r);d=!0;for(var t=l.length;t;){for(f=l,l=[];++h<t;)f&&f[h].run();h=-1,t=l.length}f=null,d=!1,u(e)}}function i(e,t){this.fun=e,this.array=t}function a(){}var s,u,c=t.exports={};!function(){try{s=setTimeout}catch(e){s=function(){throw new Error("setTimeout is not defined")}}try{u=clearTimeout}catch(e){u=function(){throw new Error("clearTimeout is not defined")}}}();var f,l=[],d=!1,h=-1;c.nextTick=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];l.push(new i(e,t)),1!==l.length||d||s(o,0)},i.prototype.run=function(){this.fun.apply(null,this.array)},c.title="browser",c.browser=!0,c.env={},c.argv=[],c.version="",c.versions={},c.on=a,c.addListener=a,c.once=a,c.off=a,c.removeListener=a,c.removeAllListeners=a,c.emit=a,c.binding=function(e){throw new Error("process.binding is not supported")},c.cwd=function(){return"/"},c.chdir=function(e){throw new Error("process.chdir is not supported")},c.umask=function(){return 0}},{}],3:[function(e,t,n){(function(n,r){"use strict";function o(e){return e&&"object"==typeof e&&"default"in e?e["default"]:e}function i(e){return e instanceof ArrayBuffer||"undefined"!=typeof Blob&&e instanceof Blob}function a(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}function s(e){if(e instanceof ArrayBuffer)return a(e);var t=e.size,n=e.type;return"function"==typeof e.slice?e.slice(0,t,n):e.webkitSlice(0,t,n)}function u(e){var t=Object.getPrototypeOf(e);if(null===t)return!0;var n=t.constructor;return"function"==typeof n&&n instanceof n&&Ir.call(n)==Dr}function c(e){var t,n,r;if(!e||"object"!=typeof e)return e;if(Array.isArray(e)){for(t=[],n=0,r=e.length;r>n;n++)t[n]=c(e[n]);return t}if(e instanceof Date)return e.toISOString();if(i(e))return s(e);if(!u(e))return e;t={};for(n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var o=c(e[n]);"undefined"!=typeof o&&(t[n]=o)}return t}function f(e){var t=!1;return qr(function(n){if(t)throw new Error("once called more than once");t=!0,e.apply(this,n)})}function l(e){return qr(function(t){t=c(t);var r,o=this,i="function"==typeof t[t.length-1]?t.pop():!1;i&&(r=function(e,t){n.nextTick(function(){i(e,t)})});var a=new Lr(function(n,r){var i;try{var a=f(function(e,t){e?r(e):n(t)});t.push(a),i=e.apply(o,t),i&&"function"==typeof i.then&&n(i)}catch(s){r(s)}});return r&&a.then(function(e){r(null,e)},r),a})}function d(e,t){function n(e,t,n){if(Rr.enabled){for(var r=[e._db_name,t],o=0;o<n.length-1;o++)r.push(n[o]);Rr.apply(null,r);var i=n[n.length-1];n[n.length-1]=function(n,r){var o=[e._db_name,t];o=o.concat(n?["error",n]:["success",r]),Rr.apply(null,o),i(n,r)}}}return l(qr(function(r){if(this._closed)return Lr.reject(new Error("database is closed"));if(this._destroyed)return Lr.reject(new Error("database is destroyed"));var o=this;return n(o,e,r),this.taskqueue.isReady?t.apply(this,r):new Lr(function(t,n){o.taskqueue.addTask(function(i){i?n(i):t(o[e].apply(o,r))})})}))}function h(e,t){for(var n={},r=0,o=t.length;o>r;r++){var i=t[r];i in e&&(n[i]=e[i])}return n}function p(e){return e}function v(e){return[{ok:e}]}function y(e,t,n){function r(){var e=[];d.forEach(function(t){t.docs.forEach(function(n){e.push({id:t.id,docs:[n]})})}),n(null,{results:e})}function o(){++l===f&&r()}function i(e,t,n){d[e]={id:t,docs:n},o()}function a(){if(!(_>=y.length)){var e=Math.min(_+Nr,y.length),t=y.slice(_,e);s(t,_),_+=t.length}}function s(n,r){n.forEach(function(n,o){var s=r+o,u=c[n],f=h(u[0],["atts_since","attachments"]);f.open_revs=u.map(function(e){return e.rev}),f.open_revs=f.open_revs.filter(p);var l=p;0===f.open_revs.length&&(delete f.open_revs,l=v),["revs","attachments","binary","ajax"].forEach(function(e){e in t&&(f[e]=t[e])}),e.get(n,f,function(e,t){var r;r=e?[{error:e}]:l(t),i(s,n,r),a()})})}var u=t.docs,c={};u.forEach(function(e){e.id in c?c[e.id].push(e):c[e.id]=[e]});var f=Object.keys(c).length,l=0,d=new Array(f),y=Object.keys(c),_=0;a()}function _(){return"undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage&&"undefined"!=typeof chrome.storage.local}function m(){return gr}function g(e){_()?chrome.storage.onChanged.addListener(function(t){null!=t.db_name&&e.emit(t.dbName.newValue)}):m()&&("undefined"!=typeof addEventListener?addEventListener("storage",function(t){e.emit(t.key)}):window.attachEvent("storage",function(t){e.emit(t.key)}))}function b(){xr.EventEmitter.call(this),this._listeners={},g(this)}function w(e){if("undefined"!==console&&e in console){var t=Array.prototype.slice.call(arguments,1);console[e].apply(console,t)}}function E(e,t){var n=6e5;e=parseInt(e,10)||0,t=parseInt(t,10),t!==t||e>=t?t=(e||1)<<1:t+=1,t>n&&(e=n>>1,t=n);var r=Math.random(),o=t-e;return~~(o*r+e)}function k(e){var t=0;return e||(t=2e3),E(e,t)}function S(e,t){w("info","The above "+e+" is totally normal. "+t)}function q(e){Error.call(this,e.reason),this.status=e.status,this.name=e.error,this.message=e.reason,this.error=!0}function x(e,t){function n(t){for(var n in e)"function"!=typeof e[n]&&(this[n]=e[n]);void 0!==t&&(this.reason=t)}return n.prototype=q.prototype,new n(t)}function A(e){if("object"!=typeof e){var t=e;e=Wr,e.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),e}function T(e,t,n){try{return!e(t,n)}catch(r){var o="Filter function threw: "+r.toString();return x(Vr,o)}}function O(e){var t={},n=e.filter&&"function"==typeof e.filter;return t.query=e.query_params,function(r){r.doc||(r.doc={});var o=n&&T(e.filter,r.doc,t);if("object"==typeof o)return o;if(o)return!1;if(e.include_docs){if(!e.attachments)for(var i in r.doc._attachments)r.doc._attachments.hasOwnProperty(i)&&(r.doc._attachments[i].stub=!0)}else delete r.doc;return!0}}function j(e){for(var t=[],n=0,r=e.length;r>n;n++)t=t.concat(e[n]);return t}function C(e){var t;if(e?"string"!=typeof e?t=x(Ur):/^_/.test(e)&&!/^_(design|local)/.test(e)&&(t=x(zr)):t=x(Hr),t)throw t}function L(e,t){return"listenerCount"in e?e.listenerCount(t):xr.EventEmitter.listenerCount(e,t)}function I(e){if(!e)return null;var t=e.split("/");return 2===t.length?t:1===t.length?[e,e]:null}function D(e){var t=I(e);return t?t.join("/"):null}function R(e){for(var t=oo.exec(e),n={},r=14;r--;){var o=to[r],i=t[r]||"",a=-1!==["user","password"].indexOf(o);n[o]=a?decodeURIComponent(i):i}return n[no]={},n[to[12]].replace(ro,function(e,t,r){t&&(n[no][t]=r)}),n}function N(e,t,n){return new Lr(function(r,o){e.get(t,function(i,a){if(i){if(404!==i.status)return o(i);a={}}var s=a._rev,u=n(a);return u?(u._id=t,u._rev=s,void r(B(e,u,n))):r({updated:!1,rev:s})})})}function B(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 N(e,t._id,n)})}function P(e){return 0|Math.random()*e}function M(e,t){t=t||io.length;var n="",r=-1;if(e){for(;++r<e;)n+=io[P(t)];return n}for(;++r<36;)switch(r){case 8:case 13:case 18:case 23:n+="-";break;case 19:n+=io[3&P(16)|8];break;default:n+=io[P(16)]}return n}function F(e){for(var t,n,r,o,i=e.rev_tree.slice();o=i.pop();){var a=o.ids,s=a[2],u=o.pos;if(s.length)for(var c=0,f=s.length;f>c;c++)i.push({pos:u+1,ids:s[c]});else{var l=!!a[1].deleted,d=a[0];t&&!(r!==l?r:n!==u?u>n:d>t)||(t=d,n=u,r=l)}}return n+"-"+t}function U(e,t){for(var n,r=e.slice();n=r.pop();)for(var o=n.pos,i=n.ids,a=i[2],s=t(0===a.length,o,i[0],n.ctx,i[1]),u=0,c=a.length;c>u;u++)r.push({pos:o+1,ids:a[u],ctx:s})}function H(e,t){return e.pos-t.pos}function z(e){var t=[];U(e,function(e,n,r,o,i){e&&t.push({rev:n+"-"+r,pos:n,opts:i})}),t.sort(H).reverse();for(var n=0,r=t.length;r>n;n++)delete t[n].pos;return t}function K(e){for(var t=F(e),n=z(e.rev_tree),r=[],o=0,i=n.length;i>o;o++){var a=n[o];a.rev===t||a.opts.deleted||r.push(a.rev)}return r}function W(e){var t=[];return U(e.rev_tree,function(e,n,r,o,i){"available"!==i.status||e||(t.push(n+"-"+r),i.status="missing")}),t}function J(e){for(var t,n=[],r=e.slice();t=r.pop();){var o=t.pos,i=t.ids,a=i[0],s=i[1],u=i[2],c=0===u.length,f=t.history?t.history.slice():[];f.push({id:a,opts:s}),c&&n.push({pos:o+1-f.length,ids:f});for(var l=0,d=u.length;d>l;l++)r.push({pos:o+1,ids:u[l],history:f})}return n.reverse()}function X(e,t){return e.pos-t.pos}function G(e,t,n){for(var r,o=0,i=e.length;i>o;)r=o+i>>>1,n(e[r],t)<0?o=r+1:i=r;return o}function V(e,t,n){var r=G(e,t,n);e.splice(r,0,t)}function Q(e,t){for(var n,r,o=t,i=e.length;i>o;o++){var a=e[o],s=[a.id,a.opts,[]];r?(r[2].push(s),r=s):n=r=s}return n}function $(e,t){return e[0]<t[0]?-1:1}function Y(e,t){for(var n=[{tree1:e,tree2:t}],r=!1;n.length>0;){var o=n.pop(),i=o.tree1,a=o.tree2;(i[1].status||a[1].status)&&(i[1].status="available"===i[1].status||"available"===a[1].status?"available":"missing");for(var s=0;s<a[2].length;s++)if(i[2][0]){for(var u=!1,c=0;c<i[2].length;c++)i[2][c][0]===a[2][s][0]&&(n.push({tree1:i[2][c],tree2:a[2][s]}),u=!0);u||(r="new_branch",V(i[2],a[2][s],$))}else r="new_leaf",i[2][0]=a[2][s]}return{conflicts:r,tree:e}}function Z(e,t,n){var r,o=[],i=!1,a=!1;if(!e.length)return{tree:[t],conflicts:"new_leaf"};for(var s=0,u=e.length;u>s;s++){var c=e[s];if(c.pos===t.pos&&c.ids[0]===t.ids[0])r=Y(c.ids,t.ids),o.push({pos:c.pos,ids:r.tree}),i=i||r.conflicts,a=!0;else if(n!==!0){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],_=0,m=y.length;m>_;_++)p.push({ids:y[_],diff:v.diff-1,parent:v.ids,parentIdx:_});else v.ids[0]===l.ids[0]&&h.push(v)}var g=h[0];g?(r=Y(g.ids,l.ids),g.parent[2][g.parentIdx]=r.tree,o.push({pos:f.pos,ids:f.ids}),i=i||r.conflicts,a=!0):o.push(c)}else o.push(c)}return a||o.push(t),o.sort(X),{tree:o,conflicts:i||"internal_node"}}function ee(e,t){for(var n,r=J(e),o={},i=0,a=r.length;a>i;i++){for(var s=r[i],u=s.ids,c=Math.max(0,u.length-t),f={pos:s.pos+c,ids:Q(u,c)},l=0;c>l;l++){var d=s.pos+l+"-"+u[l].id;o[d]=!0}n=n?Z(n,f,!0).tree:[f]}return U(n,function(e,t,n){delete o[t+"-"+n]}),{tree:n,revs:Object.keys(o)}}function te(e,t,n){var r=Z(e,t),o=ee(r.tree,n);return{tree:o.tree,stemmedRevs:o.revs,conflicts:r.conflicts}}function ne(e,t){for(var n,r=e.slice(),o=t.split("-"),i=parseInt(o[0],10),a=o[1];n=r.pop();){if(n.pos===i&&n.ids[0]===a)return!0;for(var s=n.ids[2],u=0,c=s.length;c>u;u++)r.push({pos:n.pos+1,ids:s[u]})}return!1}function re(e){return e.ids}function oe(e,t){t||(t=F(e));for(var n,r=t.substring(t.indexOf("-")+1),o=e.rev_tree.map(re);n=o.pop();){if(n[0]===r)return!!n[1].deleted;o=o.concat(n[2])}}function ie(e){return/^_local/.test(e)}function ae(e){return Ar("return "+e+";",{})}function se(e){return new Function("doc",["var emitted = false;","var emit = function (a, b) {"," emitted = true;","};","var view = "+e+";","view(doc);","if (emitted) {"," return true;","}"].join("\n"))}function ue(e,t){try{e.emit("change",t)}catch(n){w("error",'Error in .on("change", function):',n)}}function ce(e,t,n){function r(){o.cancel()}xr.EventEmitter.call(this);var o=this;this.db=e,t=t?c(t):{};var i=t.complete=f(function(t,n){t?L(o,"error")>0&&o.emit("error",t):o.emit("complete",n),o.removeAllListeners(),e.removeListener("destroyed",r)});n&&(o.on("complete",function(e){n(null,e)}),o.on("error",n)),e.once("destroyed",r),t.onChange=function(e){t.isCancelled||(ue(o,e),o.startSeq&&o.startSeq<=e.seq&&(o.startSeq=!1))};var a=new Lr(function(e,n){t.complete=function(t,r){t?n(t):e(r)}});o.once("cancel",function(){e.removeListener("destroyed",r),t.complete(null,{status:"cancelled"})}),this.then=a.then.bind(a),this["catch"]=a["catch"].bind(a),this.then(function(e){i(null,e)},i),e.taskqueue.isReady?o.doChanges(t):e.taskqueue.addTask(function(){o.isCancelled?o.emit("cancel"):o.doChanges(t)})}function fe(e,t,n){var r=[{rev:e._rev}];"all_docs"===n.style&&(r=z(t.rev_tree).map(function(e){return{rev:e.rev}}));var o={id:t.id,changes:r,doc:e};return oe(t,e._rev)&&(o.deleted=!0),n.conflicts&&(o.doc._conflicts=K(t),o.doc._conflicts.length||delete o.doc._conflicts),o}function le(e,t){return t>e?-1:e>t?1:0}function de(e,t){for(var n=0;n<e.length;n++)if(t(e[n],n)===!0)return e[n]}function he(e){return function(t,n){t||n[0]&&n[0].error?e(t||n[0]):e(null,n.length?n[0]:n)}}function pe(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),o=0;o<r.length;o++){var i=r[o];n._attachments[i]=h(n._attachments[i],["data","digest","content_type","length","revpos","stub"])}}}function ve(e,t){var n=le(e._id,t._id);if(0!==n)return n;var r=e._revisions?e._revisions.start:0,o=t._revisions?t._revisions.start:0;return le(r,o)}function ye(e){var t={},n=[];return U(e,function(e,r,o,i){var a=r+"-"+o;return e&&(t[a]=0),void 0!==i&&n.push({from:i,to:a}),a}),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}function _e(e,t,n){var r="limit"in t?t.keys.slice(t.skip,t.limit+t.skip):t.skip>0?t.keys.slice(t.skip):t.keys;if(t.descending&&r.reverse(),!r.length)return e._allDocs({limit:0},n);var o={offset:t.skip};return Lr.all(r.map(function(n){var r=br.extend({key:n,deleted:"ok"},t);return["limit","skip","keys"].forEach(function(e){delete r[e]}),new Lr(function(t,i){e._allDocs(r,function(e,r){return e?i(e):(o.total_rows=r.total_rows,void t(r.rows[0]||{key:n,error:"not_found"}))})})})).then(function(e){return o.rows=e,o})}function me(e){var t=e._compactionQueue[0],r=t.opts,o=t.callback;e.get("_local/compaction")["catch"](function(){return!1}).then(function(t){t&&t.last_seq&&(r.last_seq=t.last_seq),e._compact(r,function(t,r){t?o(t):o(null,r),n.nextTick(function(){e._compactionQueue.shift(),e._compactionQueue.length&&me(e)})})})}function ge(e){return"_"===e.charAt(0)?e+"is not a valid attachment name, attachment names cannot start with '_'":!1}function be(){xr.EventEmitter.call(this)}function we(){this.isReady=!1,this.failed=!1,this.queue=[]}function Ee(e){e&&r.debug&&w("error",e)}function ke(e,t){function n(){i.emit("destroyed",o)}function r(){e.removeListener("destroyed",n),e.emit("destroyed",e)}var o=t.originalName,i=e.constructor,a=i._destructionListeners;e.once("destroyed",n),a.has(o)||a.set(o,[]),a.get(o).push(r)}function Se(e,t,n){if(!(this instanceof Se))return new Se(e,t,n);var r=this;if("function"!=typeof t&&"undefined"!=typeof t||(n=t,t={}),e&&"object"==typeof e&&(t=e,e=void 0),"undefined"==typeof n)n=Ee;else{var o=n;n=function(){return w("warn","Using a callback for new PouchDB()is deprecated."),o.apply(null,arguments)}}e=e||t.name,t=c(t),delete t.name,this.__opts=t;var i=n;r.auto_compaction=t.auto_compaction,r.prefix=Se.prefix,be.call(r),r.taskqueue=new we;var a=new Lr(function(o,i){n=function(e,t){return e?i(e):(delete t.then,void o(t))},t=c(t);var a,s;return function(){try{if("string"!=typeof e)throw s=new Error("Missing/invalid DB name"),s.code=400,s;var n=(t.prefix||"")+e;if(a=Se.parseAdapter(n,t),t.originalName=e,t.name=a.name,t.adapter=t.adapter||a.adapter,r._adapter=t.adapter,wr("pouchdb:adapter")("Picked adapter: "+t.adapter),r._db_name=e,!Se.adapters[t.adapter])throw s=new Error("Adapter is missing"),s.code=404,s;if(!Se.adapters[t.adapter].valid())throw s=new Error("Invalid Adapter"),s.code=404,s}catch(o){r.taskqueue.fail(o)}}(),s?i(s):(r.adapter=t.adapter,r.replicate={},r.replicate.from=function(e,t,n){return r.constructor.replicate(e,r,t,n)},r.replicate.to=function(e,t,n){return r.constructor.replicate(r,e,t,n)},r.sync=function(e,t,n){return r.constructor.sync(r,e,t,n)},r.replicate.sync=r.sync,void Se.adapters[t.adapter].call(r,t,function(e){return e?(r.taskqueue.fail(e),void n(e)):(ke(r,t),r.emit("created",r),Se.emit("created",t.originalName),r.taskqueue.ready(r),void n(null,r))}))});a.then(function(e){i(null,e)},i),r.then=a.then.bind(a),r["catch"]=a["catch"].bind(a)}function qe(e){Object.keys(xr.EventEmitter.prototype).forEach(function(t){"function"==typeof xr.EventEmitter.prototype[t]&&(e[t]=ao[t].bind(ao))});var t=e._destructionListeners=new Sr.Map;e.on("destroyed",function(e){t.get(e).forEach(function(e){e()}),t["delete"](e)})}function xe(e){return e.reduce(function(e,t){return e[t]=!0,e},{})}function Ae(e){if(!/^\d+\-./.test(e))return x(Zr);var t=e.indexOf("-"),n=e.substring(0,t),r=e.substring(t+1);return{prefix:parseInt(n,10),id:r}}function Te(e,t){for(var n=e.start-e.ids.length+1,r=e.ids,o=[r[0],t,[]],i=1,a=r.length;a>i;i++)o=[r[i],{status:"missing"},[o]];return[{pos:n,ids:o}]}function Oe(e,t){var n,r,o,i={status:"available"};if(e._deleted&&(i.deleted=!0),t)if(e._id||(e._id=M()),r=M(32,16).toLowerCase(),e._rev){if(o=Ae(e._rev),o.error)return o;e._rev_tree=[{pos:o.prefix,ids:[o.id,{status:"missing"},[[r,i,[]]]]}],n=o.prefix+1}else e._rev_tree=[{pos:1,ids:[r,i,[]]}],n=1;else if(e._revisions&&(e._rev_tree=Te(e._revisions,i),n=e._revisions.start,r=e._revisions.ids[0]),!e._rev_tree){if(o=Ae(e._rev),o.error)return o;n=o.prefix,r=o.id,e._rev_tree=[{pos:n,ids:[r,i,[]]}]}C(e._id),e._rev=n+"-"+r;var a={metadata:{},data:{}};for(var s in e)if(Object.prototype.hasOwnProperty.call(e,s)){var u="_"===s[0];if(u&&!co[s]){var c=x(Gr,s);throw c.message=Gr.message+": "+s,c}u&&!fo[s]?a.metadata[s.slice(1)]=e[s]:a.data[s]=e[s]}return a}function je(e,t){e=e||[],t=t||{};try{return new Blob(e,t)}catch(n){if("TypeError"!==n.name)throw n;for(var r="undefined"!=typeof BlobBuilder?BlobBuilder:"undefined"!=typeof MSBlobBuilder?MSBlobBuilder:"undefined"!=typeof MozBlobBuilder?MozBlobBuilder:WebKitBlobBuilder,o=new r,i=0;i<e.length;i+=1)o.append(e[i]);return o.getBlob(t.type)}}function Ce(e){for(var t=e.length,n=new ArrayBuffer(t),r=new Uint8Array(n),o=0;t>o;o++)r[o]=e.charCodeAt(o);return n}function Le(e,t){return je([Ce(e)],{type:t})}function Ie(e,t){return Le(lo(e),t)}function De(e){for(var t="",n=new Uint8Array(e),r=n.byteLength,o=0;r>o;o++)t+=String.fromCharCode(n[o]);return t}function Re(e,t){if("undefined"==typeof FileReader)return t(De((new FileReaderSync).readAsArrayBuffer(e)));var n=new FileReader,r="function"==typeof n.readAsBinaryString;n.onloadend=function(e){var n=e.target.result||"";return r?t(n):void t(De(n))},r?n.readAsBinaryString(e):n.readAsArrayBuffer(e)}function Ne(e,t){Re(e,function(e){t(e)})}function Be(e,t){Ne(e,function(e){t(ho(e))})}function Pe(e,t){if("undefined"==typeof FileReader)return t((new FileReaderSync).readAsArrayBuffer(e));var n=new FileReader;n.onloadend=function(e){var n=e.target.result||new ArrayBuffer(0);t(n)},n.readAsArrayBuffer(e)}function Me(e){return ho(e)}function Fe(e,t,n){return e.webkitSlice?e.webkitSlice(t,n):e.slice(t,n)}function Ue(e,t,n,r,o){(n>0||r<t.size)&&(t=Fe(t,n,r)),Pe(t,function(t){e.append(t),o()})}function He(e,t,n,r,o){(n>0||r<t.length)&&(t=t.substring(n,r)),e.appendBinary(t),o()}function ze(e,t){function n(){po(o)}function r(){var e=f.end(!0),n=Me(e);t(n),f.destroy()}function o(){var t=c*s,o=t+s;c++,u>c?l(f,e,t,o,n):l(f,e,t,o,r)}var i="string"==typeof e,a=i?e.length:e.size,s=Math.min(vo,a),u=Math.ceil(a/s),c=0,f=i?new Tr:new Tr.ArrayBuffer,l=i?He:Ue;o()}function Ke(e){return Tr.hash(e)}function We(e){try{return lo(e)}catch(t){var n=x(Jr,"Attachment is not a valid base64 string");return{error:n}}}function Je(e,t,n){var r=We(e.data);return r.error?n(r.error):(e.length=r.length,"blob"===t?e.data=Le(r,e.content_type):"base64"===t?e.data=ho(r):e.data=r,void ze(r,function(t){e.digest="md5-"+t,n()}))}function Xe(e,t,n){ze(e.data,function(r){e.digest="md5-"+r,e.length=e.data.size||e.data.length||0,"binary"===t?Ne(e.data,function(t){e.data=t,n()}):"base64"===t?Be(e.data,function(t){e.data=t,n()}):n()})}function Ge(e,t,n){return e.stub?n():void("string"==typeof e.data?Je(e,t,n):Xe(e,t,n))}function Ve(e,t,n){function r(){i++,e.length===i&&(o?n(o):n())}if(!e.length)return n();var o,i=0;e.forEach(function(e){function n(e){o=e,a++,a===i.length&&r()}var i=e.data&&e.data._attachments?Object.keys(e.data._attachments):[],a=0;if(!i.length)return r();for(var s in e.data._attachments)e.data._attachments.hasOwnProperty(s)&&Ge(e.data._attachments[s],t,n)})}function Qe(e,t,n,r,o,i,a,s){if(ne(t.rev_tree,n.metadata.rev))return r[o]=n,i();var u=t.winningRev||F(t),c="deleted"in t?t.deleted:oe(t,u),f="deleted"in n.metadata?n.metadata.deleted:oe(n.metadata),l=/^1-/.test(n.metadata.rev);if(c&&!f&&s&&l){var d=n.data;d._rev=u,d._id=n.metadata.id,n=Oe(d,s)}var h=te(t.rev_tree,n.metadata.rev_tree[0],e),p=s&&(c&&f||!c&&"new_leaf"!==h.conflicts||c&&!f&&"new_branch"===h.conflicts);if(p){var v=x(Fr);return r[o]=v,i()}var y=n.metadata.rev;n.metadata.rev_tree=h.tree,n.stemmedRevs=h.stemmedRevs||[],t.rev_map&&(n.metadata.rev_map=t.rev_map);var _,m=F(n.metadata),g=oe(n.metadata,m),b=c===g?0:g>c?-1:1;_=y===m?g:oe(n.metadata,y),a(n,m,g,_,!0,b,o,i)}function $e(e){return"missing"===e.metadata.rev_tree[0].ids[1].status}function Ye(e,t,n,r,o,i,a,s,u){function c(e,t,n){var r=F(e.metadata),o=oe(e.metadata,r);if("was_delete"in s&&o)return i[t]=x(Mr,"deleted"),n();var u=l&&$e(e);if(u){var c=x(Fr);return i[t]=c,n()}var f=o?0:1;a(e,r,o,o,!1,f,t,n)}function f(){++h===p&&u&&u()}e=e||1e3;var l=s.new_edits,d=new Sr.Map,h=0,p=t.length;t.forEach(function(e,t){if(e._id&&ie(e._id)){var r=e._deleted?"_removeLocal":"_putLocal";return void n[r](e,{ctx:o},function(e,n){i[t]=e||n,f()})}var a=e.metadata.id;d.has(a)?(p--,d.get(a).push([e,t])):d.set(a,[[e,t]])}),d.forEach(function(t,n){function o(){++u<t.length?s():f()}function s(){var s=t[u],f=s[0],d=s[1];if(r.has(n))Qe(e,r.get(n),f,i,d,o,a,l);else{var h=te([],f.metadata.rev_tree[0],e);f.metadata.rev_tree=h.tree,f.stemmedRevs=h.stemmedRevs||[],c(f,d,o)}}var u=0;s()})}function Ze(e){try{return JSON.parse(e)}catch(t){return Or.parse(e)}}function et(e){return e.length<5e4?JSON.parse(e):Ze(e)}function tt(e){try{return JSON.stringify(e)}catch(t){return Or.stringify(e)}}function nt(e,t,n,r){try{e.apply(t,n)}catch(o){r.emit("error",o)}}function rt(e){if(!So.running&&So.queue.length){So.running=!0;var t=So.queue.shift();t.action(function(r,o){nt(t.callback,this,[r,o],e),So.running=!1,n.nextTick(function(){rt(e)})})}}function ot(e){return function(t){var n="unknown_error";t.target&&t.target.error&&(n=t.target.error.name||t.target.error.message),e(x($r,n,t.type))}}function it(e,t,n){return{data:tt(e),winningRev:t,deletedOrLocal:n?"1":"0",seq:e.seq,id:e.id}}function at(e){if(!e)return null;var t=et(e.data);return t.winningRev=e.winningRev,t.deleted="1"===e.deletedOrLocal,t.seq=e.seq,t}function st(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 ut(e,t,n,r){n?r(e?"string"!=typeof e?e:Ie(e,t):je([""],{type:t})):e?"string"!=typeof e?Re(e,function(e){r(ho(e))}):r(e):r("")}function ct(e,t,n,r){function o(){++s===a.length&&r&&r()}function i(e,t){var r=e._attachments[t],i=r.digest,a=n.objectStore(go).get(i);a.onsuccess=function(e){r.body=e.target.result.body,o()}}var a=Object.keys(e._attachments||{});if(!a.length)return r&&r();var s=0;a.forEach(function(n){t.attachments&&t.include_docs?i(e,n):(e._attachments[n].stub=!0,o())})}function ft(e,t){return Lr.all(e.map(function(e){if(e.doc&&e.doc._attachments){var n=Object.keys(e.doc._attachments);return Lr.all(n.map(function(n){var r=e.doc._attachments[n];if("body"in r){var o=r.body,i=r.content_type;return new Lr(function(a){ut(o,i,t,function(t){e.doc._attachments[n]=br.extend(h(r,["digest","content_type"]),{data:t}),a()})})}}))}}))}function lt(e,t,n){function r(){c--,c||o()}function o(){i.length&&i.forEach(function(e){var t=u.index("digestSeq").count(IDBKeyRange.bound(e+"::",e+"::",!1,!1));t.onsuccess=function(t){var n=t.target.result;n||s["delete"](e)}})}var i=[],a=n.objectStore(mo),s=n.objectStore(go),u=n.objectStore(bo),c=e.length;e.forEach(function(e){var n=a.index("_doc_id_rev"),o=t+"::"+e;n.getKey(o).onsuccess=function(e){var t=e.target.result;if("number"!=typeof t)return r();a["delete"](t);var n=u.index("seq").openCursor(IDBKeyRange.only(t));n.onsuccess=function(e){var t=e.target.result;if(t){var n=t.value.digestSeq.split("::")[0];i.push(n),u["delete"](t.primaryKey),t["continue"]()}else r()}}})}function dt(e,t,n){try{return{txn:e.transaction(t,n)}}catch(r){return{error:r}}}function ht(e,t,n,r,o,i,a){function s(){var e=[_o,mo,go,Eo,bo],t=dt(o,e,"readwrite");return t.error?a(t.error):(m=t.txn,m.onabort=ot(a),m.ontimeout=ot(a),m.oncomplete=f,g=m.objectStore(_o),b=m.objectStore(mo),w=m.objectStore(go),E=m.objectStore(bo),void d(function(e){return e?(L=!0,a(e)):void c()}))}function u(){Ye(e.revs_limit,S,r,C,m,j,h,n)}function c(){function e(){++n===S.length&&u()}function t(t){var n=at(t.target.result);n&&C.set(n.id,n),e()}if(S.length)for(var n=0,r=0,o=S.length;o>r;r++){var i=S[r];if(i._id&&ie(i._id))e();else{var a=g.get(i.metadata.id);a.onsuccess=t}}}function f(){L||(i.notify(r._meta.name),r._meta.docCount+=q,a(null,j))}function l(e,t){var n=w.get(e);n.onsuccess=function(n){if(n.target.result)t();else{var r=x(eo,"unknown stub attachment with digest "+e);r.status=412,t(r)}}}function d(e){function t(){++o===n.length&&e(r)}var n=[];if(S.forEach(function(e){e.data&&e.data._attachments&&Object.keys(e.data._attachments).forEach(function(t){var r=e.data._attachments[t];r.stub&&n.push(r.digest)})}),!n.length)return e();var r,o=0;n.forEach(function(e){l(e,function(e){e&&!r&&(r=e),t()})})}function h(e,t,n,r,o,i,a,s){q+=i,e.metadata.winningRev=t,e.metadata.deleted=n;var u=e.data;u._id=e.metadata.id,u._rev=e.metadata.rev,r&&(u._deleted=!0);var c=u._attachments&&Object.keys(u._attachments).length;return c?v(e,t,n,o,a,s):void p(e,t,n,o,a,s)}function p(e,t,n,o,i,a){function s(i){var a=e.stemmedRevs||[];o&&r.auto_compaction&&(a=a.concat(W(e.metadata))),a&&a.length&<(a,e.metadata.id,m),l.seq=i.target.result,delete l.rev;var s=it(l,t,n),u=g.put(s);u.onsuccess=c}function u(e){e.preventDefault(),e.stopPropagation();var t=b.index("_doc_id_rev"),n=t.getKey(f._doc_id_rev);n.onsuccess=function(e){var t=b.put(f,e.target.result);t.onsuccess=s}}function c(){j[i]={ok:!0,id:l.id,rev:t},C.set(e.metadata.id,e.metadata),y(e,l.seq,a)}var f=e.data,l=e.metadata;f._doc_id_rev=l.id+"::"+l.rev,delete f._id,delete f._rev;var d=b.put(f);d.onsuccess=s,d.onerror=u}function v(e,t,n,r,o,i){function a(){c===f.length&&p(e,t,n,r,o,i)}function s(){c++,a()}var u=e.data,c=0,f=Object.keys(u._attachments);f.forEach(function(n){var r=e.data._attachments[n];if(r.stub)c++,a();else{var o=r.data;delete r.data,r.revpos=parseInt(t,10);var i=r.digest;_(i,o,s)}})}function y(e,t,n){function r(){++i===a.length&&n()}function o(n){var o=e.data._attachments[n].digest,i=E.put({seq:t,digestSeq:o+"::"+t});i.onsuccess=r,i.onerror=function(e){e.preventDefault(),e.stopPropagation(),r()}}var i=0,a=Object.keys(e.data._attachments||{});if(!a.length)return n();for(var s=0;s<a.length;s++)o(a[s])}function _(e,t,n){var r=w.count(e);r.onsuccess=function(r){var o=r.target.result;if(o)return n();var i={digest:e,body:t},a=w.put(i);a.onsuccess=n}}for(var m,g,b,w,E,k,S=t.docs,q=0,A=0,T=S.length;T>A;A++){var O=S[A];O._id&&ie(O._id)||(O=S[A]=Oe(O,n.new_edits),O.error&&!k&&(k=O))}if(k)return a(k);var j=new Array(S.length),C=new Sr.Map,L=!1,I=r._meta.blobSupport?"blob":"base64";Ve(S,I,function(e){return e?a(e):void s()})}function pt(e,t,n,r,o){try{if(e&&t)return o?IDBKeyRange.bound(t,e,!n,!1):IDBKeyRange.bound(e,t,!1,!n);if(e)return o?IDBKeyRange.upperBound(e):IDBKeyRange.lowerBound(e);if(t)return o?IDBKeyRange.lowerBound(t,!n):IDBKeyRange.upperBound(t,!n);if(r)return IDBKeyRange.only(r)}catch(i){return{
error:i}}return null}function vt(e,t,n,r){return"DataError"===n.name&&0===n.code?r(null,{total_rows:e._meta.docCount,offset:t.skip,rows:[]}):void r(x($r,n.name,n.message))}function yt(e,t,n,r){function o(e,r){function o(t,n,r){var o=t.id+"::"+r;k.get(o).onsuccess=function(r){n.doc=st(r.target.result),e.conflicts&&(n.doc._conflicts=K(t)),ct(n.doc,e,g)}}function i(t,n,r){var i={id:r.id,key:r.id,value:{rev:n}},a=r.deleted;if("ok"===e.deleted)S.push(i),a?(i.value.deleted=!0,i.doc=null):e.include_docs&&o(r,i,n);else if(!a&&d--<=0&&(S.push(i),e.include_docs&&o(r,i,n),0===--h))return;t["continue"]()}function a(e){q=t._meta.docCount;var n=e.target.result;if(n){var r=at(n.value),o=r.winningRev;i(n,o,r)}}function s(){r(null,{total_rows:q,offset:e.skip,rows:S})}function u(){e.attachments?ft(S,e.binary).then(s):s()}var c="startkey"in e?e.startkey:!1,f="endkey"in e?e.endkey:!1,l="key"in e?e.key:!1,d=e.skip||0,h="number"==typeof e.limit?e.limit:-1,p=e.inclusive_end!==!1,v="descending"in e&&e.descending?"prev":null,y=pt(c,f,p,l,v);if(y&&y.error)return vt(t,e,y.error,r);var _=[_o,mo];e.attachments&&_.push(go);var m=dt(n,_,"readonly");if(m.error)return r(m.error);var g=m.txn,b=g.objectStore(_o),w=g.objectStore(mo),E=v?b.openCursor(y,v):b.openCursor(y),k=w.index("_doc_id_rev"),S=[],q=0;g.oncomplete=u,E.onsuccess=a}function i(e,n){return 0===e.limit?n(null,{total_rows:t._meta.docCount,offset:e.skip,rows:[]}):void o(e,n)}i(e,r)}function _t(e){return new Lr(function(t){var n=je([""]);e.objectStore(ko).put(n,"key"),e.onabort=function(e){e.preventDefault(),e.stopPropagation(),t(!1)},e.oncomplete=function(){var e=navigator.userAgent.match(/Chrome\/(\d+)/),n=navigator.userAgent.match(/Edge\//);t(n||!e||parseInt(e[1],10)>=43)}})["catch"](function(){return!1})}function mt(e,t){var n=this;So.queue.push({action:function(t){gt(n,e,t)},callback:t}),rt(n.constructor)}function gt(e,t,r){function o(e){var t=e.createObjectStore(_o,{keyPath:"id"});e.createObjectStore(mo,{autoIncrement:!0}).createIndex("_doc_id_rev","_doc_id_rev",{unique:!0}),e.createObjectStore(go,{keyPath:"digest"}),e.createObjectStore(wo,{keyPath:"id",autoIncrement:!1}),e.createObjectStore(ko),t.createIndex("deletedOrLocal","deletedOrLocal",{unique:!1}),e.createObjectStore(Eo,{keyPath:"_id"});var n=e.createObjectStore(bo,{autoIncrement:!0});n.createIndex("seq","seq"),n.createIndex("digestSeq","digestSeq",{unique:!0})}function i(e,t){var n=e.objectStore(_o);n.createIndex("deletedOrLocal","deletedOrLocal",{unique:!1}),n.openCursor().onsuccess=function(e){var r=e.target.result;if(r){var o=r.value,i=oe(o);o.deletedOrLocal=i?"1":"0",n.put(o),r["continue"]()}else t()}}function a(e){e.createObjectStore(Eo,{keyPath:"_id"}).createIndex("_doc_id_rev","_doc_id_rev",{unique:!0})}function s(e,t){var n=e.objectStore(Eo),r=e.objectStore(_o),o=e.objectStore(mo),i=r.openCursor();i.onsuccess=function(e){var i=e.target.result;if(i){var a=i.value,s=a.id,u=ie(s),c=F(a);if(u){var f=s+"::"+c,l=s+"::",d=s+"::~",h=o.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),o["delete"](v.primaryKey),v["continue"]()}else r["delete"](i.primaryKey),i["continue"]()}}else i["continue"]()}else t&&t()}}function u(e){var t=e.createObjectStore(bo,{autoIncrement:!0});t.createIndex("seq","seq"),t.createIndex("digestSeq","digestSeq",{unique:!0})}function f(e,t){var n=e.objectStore(mo),r=e.objectStore(go),o=e.objectStore(bo),i=r.count();i.onsuccess=function(e){var r=e.target.result;return r?void(n.openCursor().onsuccess=function(e){var n=e.target.result;if(!n)return t();for(var r=n.value,i=n.primaryKey,a=Object.keys(r._attachments||{}),s={},u=0;u<a.length;u++){var c=r._attachments[a[u]];s[c.digest]=!0}var f=Object.keys(s);for(u=0;u<f.length;u++){var l=f[u];o.put({seq:i,digestSeq:l+"::"+i})}n["continue"]()}):t()}}function d(e){function t(e){return e.data?at(e):(e.deleted="1"===e.deletedOrLocal,e)}var n=e.objectStore(mo),r=e.objectStore(_o),o=r.openCursor();o.onsuccess=function(e){function o(){var e=s.id+"::",t=s.id+"::",r=n.index("_doc_id_rev").openCursor(IDBKeyRange.bound(e,t)),o=0;r.onsuccess=function(e){var t=e.target.result;if(!t)return s.seq=o,i();var n=t.primaryKey;n>o&&(o=n),t["continue"]()}}function i(){var e=it(s,s.winningRev,s.deleted),t=r.put(e);t.onsuccess=function(){a["continue"]()}}var a=e.target.result;if(a){var s=t(a.value);return s.winningRev=s.winningRev||F(s),s.seq?i():void o()}}}var h=t.name,p=null;e._meta=null,e.type=function(){return"idb"},e._id=l(function(t){t(null,e._meta.instanceId)}),e._bulkDocs=function(n,r,o){ht(t,n,r,e,p,xo,o)},e._get=function(e,t,n){function r(){n(a,{doc:o,metadata:i,ctx:s})}var o,i,a,s=t.ctx;if(!s){var u=dt(p,[_o,mo,go],"readonly");if(u.error)return n(u.error);s=u.txn}s.objectStore(_o).get(e).onsuccess=function(e){if(i=at(e.target.result),!i)return a=x(Mr,"missing"),r();if(oe(i)&&!t.rev)return a=x(Mr,"deleted"),r();var n=s.objectStore(mo),u=t.rev||i.winningRev,c=i.id+"::"+u;n.index("_doc_id_rev").get(c).onsuccess=function(e){return o=e.target.result,o&&(o=st(o)),o?void r():(a=x(Mr,"missing"),r())}}},e._getAttachment=function(e,t,n,r,o){var i;if(r.ctx)i=r.ctx;else{var a=dt(p,[_o,mo,go],"readonly");if(a.error)return o(a.error);i=a.txn}var s=n.digest,u=n.content_type;i.objectStore(go).get(s).onsuccess=function(e){var t=e.target.result.body;ut(t,u,r.binary,function(e){o(null,e)})}},e._info=function(t){if(null===p||!qo.has(h)){var n=new Error("db isn't open");return n.id="idbNull",t(n)}var r,o,i=dt(p,[mo],"readonly");if(i.error)return t(i.error);var a=i.txn,s=a.objectStore(mo).openCursor(null,"prev");s.onsuccess=function(t){var n=t.target.result;r=n?n.key:0,o=e._meta.docCount},a.oncomplete=function(){t(null,{doc_count:o,update_seq:r,idb_attachment_format:e._meta.blobSupport?"binary":"base64"})}},e._allDocs=function(t,n){yt(t,e,p,n)},e._changes=function(t){function n(e){function n(){return c.seq!==a?e["continue"]():(u=a,c.winningRev===i._rev?o(i):void r())}function r(){var e=i._id+"::"+c.winningRev,t=_.get(e);t.onsuccess=function(e){o(st(e.target.result))}}function o(n){var r=t.processChange(n,c,t);r.seq=c.seq;var o=b(r);return"object"==typeof o?t.complete(o):(o&&(g++,l&&m.push(r),t.attachments&&t.include_docs?ct(n,t,d,function(){ft([r],t.binary).then(function(){t.onChange(r)})}):t.onChange(r)),void(g!==f&&e["continue"]()))}var i=st(e.value),a=e.key;if(s&&!s.has(i._id))return e["continue"]();var c;return(c=w.get(i._id))?n():void(y.get(i._id).onsuccess=function(e){c=at(e.target.result),w.set(i._id,c),n()})}function r(e){var t=e.target.result;t&&n(t)}function o(){var e=[_o,mo];t.attachments&&e.push(go);var n=dt(p,e,"readonly");if(n.error)return t.complete(n.error);d=n.txn,d.onabort=ot(t.complete),d.oncomplete=i,v=d.objectStore(mo),y=d.objectStore(_o),_=v.index("_doc_id_rev");var o;o=t.descending?v.openCursor(null,"prev"):v.openCursor(IDBKeyRange.lowerBound(t.since,!0)),o.onsuccess=r}function i(){function e(){t.complete(null,{results:m,last_seq:u})}!t.continuous&&t.attachments?ft(m).then(e):e()}if(t=c(t),t.continuous){var a=h+":"+M();return xo.addListener(h,a,e,t),xo.notify(h),{cancel:function(){xo.removeListener(h,a)}}}var s=t.doc_ids&&new Sr.Set(t.doc_ids);t.since=t.since||0;var u=t.since,f="limit"in t?t.limit:-1;0===f&&(f=1);var l;l="return_docs"in t?t.return_docs:"returnDocs"in t?t.returnDocs:!0;var d,v,y,_,m=[],g=0,b=O(t),w=new Sr.Map;o()},e._close=function(e){return null===p?e(x(Kr)):(p.close(),qo["delete"](h),p=null,void e())},e._getRevisionTree=function(e,t){var n=dt(p,[_o],"readonly");if(n.error)return t(n.error);var r=n.txn,o=r.objectStore(_o).get(e);o.onsuccess=function(e){var n=at(e.target.result);n?t(null,n.rev_tree):t(x(Mr))}},e._doCompaction=function(e,t,n){var r=[_o,mo,go,bo],o=dt(p,r,"readwrite");if(o.error)return n(o.error);var i=o.txn,a=i.objectStore(_o);a.get(e).onsuccess=function(n){var r=at(n.target.result);U(r.rev_tree,function(e,n,r,o,i){var a=n+"-"+r;-1!==t.indexOf(a)&&(i.status="missing")}),lt(t,e,i);var o=r.winningRev,a=r.deleted;i.objectStore(_o).put(it(r,o,a))},i.onabort=ot(n),i.oncomplete=function(){n()}},e._getLocal=function(e,t){var n=dt(p,[Eo],"readonly");if(n.error)return t(n.error);var r=n.txn,o=r.objectStore(Eo).get(e);o.onerror=ot(t),o.onsuccess=function(e){var n=e.target.result;n?(delete n._doc_id_rev,t(null,n)):t(x(Mr))}},e._putLocal=function(e,t,n){"function"==typeof t&&(n=t,t={}),delete e._revisions;var r=e._rev,o=e._id;r?e._rev="0-"+(parseInt(r.split("-")[1],10)+1):e._rev="0-1";var i,a=t.ctx;if(!a){var s=dt(p,[Eo],"readwrite");if(s.error)return n(s.error);a=s.txn,a.onerror=ot(n),a.oncomplete=function(){i&&n(null,i)}}var u,c=a.objectStore(Eo);r?(u=c.get(o),u.onsuccess=function(o){var a=o.target.result;if(a&&a._rev===r){var s=c.put(e);s.onsuccess=function(){i={ok:!0,id:e._id,rev:e._rev},t.ctx&&n(null,i)}}else n(x(Fr))}):(u=c.add(e),u.onerror=function(e){n(x(Fr)),e.preventDefault(),e.stopPropagation()},u.onsuccess=function(){i={ok:!0,id:e._id,rev:e._rev},t.ctx&&n(null,i)})},e._removeLocal=function(e,t,n){"function"==typeof t&&(n=t,t={});var r=t.ctx;if(!r){var o=dt(p,[Eo],"readwrite");if(o.error)return n(o.error);r=o.txn,r.oncomplete=function(){i&&n(null,i)}}var i,a=e._id,s=r.objectStore(Eo),u=s.get(a);u.onerror=ot(n),u.onsuccess=function(r){var o=r.target.result;o&&o._rev===e._rev?(s["delete"](a),i={ok:!0,id:a,rev:"0-0"},t.ctx&&n(null,i)):n(x(Mr))}},e._destroy=function(e,t){xo.removeAllListeners(h);var n=Ao.get(h);n&&n.result&&(n.result.close(),qo["delete"](h));var r=indexedDB.deleteDatabase(h);r.onsuccess=function(){Ao["delete"](h),m()&&h in localStorage&&delete localStorage[h],t(null,{ok:!0})},r.onerror=ot(t)};var v=qo.get(h);if(v)return p=v.idb,e._meta=v.global,void n.nextTick(function(){r(null,e)});var y;y=t.storage?bt(h,t.storage):indexedDB.open(h,yo),Ao.set(h,y),y.onupgradeneeded=function(e){function t(){var e=c[l-1];l++,e&&e(r,t)}var n=e.target.result;if(e.oldVersion<1)return o(n);var r=e.currentTarget.transaction;e.oldVersion<3&&a(n),e.oldVersion<4&&u(n);var c=[i,s,f,d],l=e.oldVersion;t()},y.onsuccess=function(t){p=t.target.result,p.onversionchange=function(){p.close(),qo["delete"](h)},p.onabort=function(e){w("error","Database has a global failure",e.target.error),p.close(),qo["delete"](h)};var n=p.transaction([wo,ko,_o],"readwrite"),o=n.objectStore(wo).get(wo),i=null,a=null,s=null;o.onsuccess=function(t){var o=function(){null!==i&&null!==a&&null!==s&&(e._meta={name:h,instanceId:s,blobSupport:i,docCount:a},qo.set(h,{idb:p,global:e._meta}),r(null,e))},u=t.target.result||{id:wo};h+"_id"in u?(s=u[h+"_id"],o()):(s=M(),u[h+"_id"]=s,n.objectStore(wo).put(u).onsuccess=function(){o()}),uo||(uo=_t(n)),uo.then(function(e){i=e,o()});var c=n.objectStore(_o).index("deletedOrLocal");c.count(IDBKeyRange.only("0")).onsuccess=function(e){a=e.target.result,o()}}},y.onerror=function(){var e="Failed to open indexedDB, are you in private browsing mode?";w("error",e),r(x($r,e))}}function bt(e,t){try{return indexedDB.open(e,{version:yo,storage:t})}catch(n){return indexedDB.open(e,yo)}}function wt(e){e.adapter("idb",mt,!0)}function Et(e){return decodeURIComponent(escape(e))}function kt(e){return 65>e?e-48:e-55}function St(e,t,n){for(var r="";n>t;)r+=String.fromCharCode(kt(e.charCodeAt(t++))<<4|kt(e.charCodeAt(t++)));return r}function qt(e,t,n){for(var r="";n>t;)r+=String.fromCharCode(kt(e.charCodeAt(t+2))<<12|kt(e.charCodeAt(t+3))<<8|kt(e.charCodeAt(t))<<4|kt(e.charCodeAt(t+1))),t+=4;return r}function xt(e,t){return"UTF-8"===t?Et(St(e,0,e.length)):qt(e,0,e.length)}function At(e){return"'"+e+"'"}function Tt(e){return e.replace(/\u0002/g,"").replace(/\u0001/g,"").replace(/\u0000/g,"")}function Ot(e){return e.replace(/\u0001\u0001/g,"\x00").replace(/\u0001\u0002/g,"").replace(/\u0002\u0002/g,"")}function jt(e){return delete e._id,delete e._rev,JSON.stringify(e)}function Ct(e,t,n){return e=JSON.parse(e),e._id=t,e._rev=n,e}function Lt(e){for(var t="(";e--;)t+="?",e&&(t+=",");return t+")"}function It(e,t,n,r,o){return"SELECT "+e+" FROM "+("string"==typeof t?t:t.join(" JOIN "))+(n?" ON "+n:"")+(r?" WHERE "+("string"==typeof r?r:r.join(" AND ")):"")+(o?" ORDER BY "+o:"")}function Dt(e,t,n){function r(){++i===e.length&&o()}function o(){if(a.length){var e="SELECT DISTINCT digest AS digest FROM "+Do+" WHERE seq IN "+Lt(a.length);n.executeSql(e,a,function(e,t){for(var n=[],r=0;r<t.rows.length;r++)n.push(t.rows.item(r).digest);if(n.length){var o="DELETE FROM "+Do+" WHERE seq IN ("+a.map(function(){return"?"}).join(",")+")";e.executeSql(o,a,function(e){var t="SELECT digest FROM "+Do+" WHERE digest IN ("+n.map(function(){return"?"}).join(",")+")";e.executeSql(t,n,function(e,t){for(var r=new Sr.Set,o=0;o<t.rows.length;o++)r.add(t.rows.item(o).digest);n.forEach(function(t){r.has(t)||(e.executeSql("DELETE FROM "+Do+" WHERE digest=?",[t]),e.executeSql("DELETE FROM "+Co+" WHERE digest=?",[t]))})})})}})}}if(e.length){var i=0,a=[];e.forEach(function(e){var o="SELECT seq FROM "+jo+" WHERE doc_id=? AND rev=?";n.executeSql(o,[t,e],function(e,t){if(!t.rows.length)return r();var n=t.rows.item(0).seq;a.push(n),e.executeSql("DELETE FROM "+jo+" WHERE seq=?",[n],r)})})}}function Rt(e){return function(t){w("error","WebSQL threw an error",t);var n=t&&t.constructor.toString().match(/function ([^\(]+)/),r=n&&n[1]||t.type,o=t.target||t.message;e(x(Yr,o,r))}}function Nt(e){if("size"in e)return 1e6*e.size;var t="undefined"!=typeof navigator&&/Android/.test(navigator.userAgent);return t?5e6:1}function Bt(e,t,n,r,o,i,a){function s(){return g?a(g):(i.notify(r._name),r._docCount=-1,void a(null,b))}function u(e,t){var n="SELECT count(*) as cnt FROM "+Co+" WHERE digest=?";m.executeSql(n,[e],function(n,r){if(0===r.rows.item(0).cnt){var o=x(eo,"unknown stub attachment with digest "+e);t(o)}else t()})}function c(e){function t(){++o===n.length&&e(r)}var n=[];if(y.forEach(function(e){e.data&&e.data._attachments&&Object.keys(e.data._attachments).forEach(function(t){var r=e.data._attachments[t];r.stub&&n.push(r.digest)})}),!n.length)return e();var r,o=0;n.forEach(function(e){u(e,function(e){e&&!r&&(r=e),t()})})}function f(e,t,n,o,i,a,s,u){function c(){function t(e,t){function r(){return++i===a.length&&t(),!1}function o(t){var o="INSERT INTO "+Do+" (digest, seq) VALUES (?,?)",i=[n._attachments[t].digest,e];m.executeSql(o,i,r,r)}var i=0,a=Object.keys(n._attachments||{});if(!a.length)return t();for(var s=0;s<a.length;s++)o(a[s])}var n=e.data,r=o?1:0,i=n._id,a=n._rev,s=jt(n),u="INSERT INTO "+jo+" (doc_id, rev, json, deleted) VALUES (?, ?, ?, ?);",c=[i,a,s,r];m.executeSql(u,c,function(e,n){var r=n.insertId;t(r,function(){d(e,r)})},function(){var e=It("seq",jo,null,"doc_id=? AND rev=?");return m.executeSql(e,[i,a],function(e,n){var o=n.rows.item(0).seq,u="UPDATE "+jo+" SET json=?, deleted=? WHERE doc_id=? AND rev=?;",c=[s,r,i,a];e.executeSql(u,c,function(e){t(o,function(){d(e,o)})})}),!1})}function f(e){p||(e?(p=e,u(p)):v===y.length&&c())}function l(e){v++,f(e)}function d(n,o){var a=e.metadata.id,c=e.stemmedRevs||[];i&&r.auto_compaction&&(c=W(e.metadata).concat(c)),c.length&&Dt(c,a,n),e.metadata.seq=o,delete e.metadata.rev;var f=i?"UPDATE "+Oo+" SET json=?, max_seq=?, winningseq=(SELECT seq FROM "+jo+" WHERE doc_id="+Oo+".id AND rev=?) WHERE id=?":"INSERT INTO "+Oo+" (id, winningseq, max_seq, json) VALUES (?,?,?,?);",l=tt(e.metadata),d=i?[l,o,t,a]:[a,o,o,l];n.executeSql(f,d,function(){b[s]={ok:!0,id:e.metadata.id,rev:t},w.set(a,e.metadata),u()})}var p=null,v=0;e.data._id=e.metadata.id,e.data._rev=e.metadata.rev;var y=Object.keys(e.data._attachments||{});o&&(e.data._deleted=!0),y.forEach(function(n){var r=e.data._attachments[n];if(r.stub)v++,f();else{var o=r.data;delete r.data,r.revpos=parseInt(t,10);var i=r.digest;h(i,o,l)}}),y.length||c()}function l(){Ye(e.revs_limit,y,r,w,m,b,f,n)}function d(e){function t(){++n===y.length&&e()}if(!y.length)return e();var n=0;y.forEach(function(e){if(e._id&&ie(e._id))return t();var n=e.metadata.id;m.executeSql("SELECT json FROM "+Oo+" WHERE id = ?",[n],function(e,r){if(r.rows.length){var o=et(r.rows.item(0).json);w.set(n,o)}t()})})}function h(e,t,n){var r="SELECT digest FROM "+Co+" WHERE digest=?";m.executeSql(r,[e],function(o,i){return i.rows.length?n():(r="INSERT INTO "+Co+" (digest, body, escaped) VALUES (?,?,1)",void o.executeSql(r,[e,Tt(t)],function(){n()},function(){return n(),!1}))})}var p=n.new_edits,v=t.docs,y=v.map(function(e){if(e._id&&ie(e._id))return e;var t=Oe(e,p);return t}),_=y.filter(function(e){return e.error});if(_.length)return a(_[0]);var m,g,b=new Array(y.length),w=new Sr.Map;Ve(y,"binary",function(e){return e?a(e):void o.transaction(function(e){m=e,c(function(e){e?g=e:d(l)})},Rt(a),s)})}function Pt(e){return e.websql(e.name,e.version,e.description,e.size)}function Mt(e){try{return{db:Pt(e)}}catch(t){return{error:t}}}function Ft(e){var t=Ro.get(e.name);return t||(t=Mt(e),Ro.set(e.name,t),t.db&&(t.db._sqlitePlugin="undefined"!=typeof sqlitePlugin)),t}function Ut(e,t,n,r,o){function i(){++u===s.length&&o&&o()}function a(e,o){var a=e._attachments[o],s={binary:t.binary,ctx:r};n._getAttachment(e._id,o,a,s,function(t,n){e._attachments[o]=br.extend(h(a,["digest","content_type"]),{data:n}),i()})}var s=Object.keys(e._attachments||{});if(!s.length)return o&&o();var u=0;s.forEach(function(n){t.attachments&&t.include_docs?a(e,n):(e._attachments[n].stub=!0,i())})}function Ht(e,t){function n(){m()&&(window.localStorage["_pouch__websqldb_"+g._name]=!0),t(null,g)}function r(e,t){e.executeSql(Fo),e.executeSql("ALTER TABLE "+jo+" ADD COLUMN deleted TINYINT(1) DEFAULT 0",[],function(){e.executeSql(Po),e.executeSql("ALTER TABLE "+Oo+" ADD COLUMN local TINYINT(1) DEFAULT 0",[],function(){e.executeSql("CREATE INDEX IF NOT EXISTS 'doc-store-local-idx' ON "+Oo+" (local, id)");var n="SELECT "+Oo+".winningseq AS seq, "+Oo+".json AS metadata FROM "+jo+" JOIN "+Oo+" ON "+jo+".seq = "+Oo+".winningseq";e.executeSql(n,[],function(e,n){for(var r=[],o=[],i=0;i<n.rows.length;i++){var a=n.rows.item(i),s=a.seq,u=JSON.parse(a.metadata);oe(u)&&r.push(s),ie(u.id)&&o.push(u.id)}e.executeSql("UPDATE "+Oo+"SET local = 1 WHERE id IN "+Lt(o.length),o,function(){e.executeSql("UPDATE "+jo+" SET deleted = 1 WHERE seq IN "+Lt(r.length),r,t)})})})})}function o(e,t){var n="CREATE TABLE IF NOT EXISTS "+Lo+" (id UNIQUE, rev, json)";e.executeSql(n,[],function(){var n="SELECT "+Oo+".id AS id, "+jo+".json AS data FROM "+jo+" JOIN "+Oo+" ON "+jo+".seq = "+Oo+".winningseq WHERE local = 1";e.executeSql(n,[],function(e,n){function r(){if(!o.length)return t(e);var n=o.shift(),i=JSON.parse(n.data)._rev;e.executeSql("INSERT INTO "+Lo+" (id, rev, json) VALUES (?,?,?)",[n.id,i,n.data],function(e){e.executeSql("DELETE FROM "+Oo+" WHERE id=?",[n.id],function(e){e.executeSql("DELETE FROM "+jo+" WHERE seq=?",[n.seq],function(){r()})})})}for(var o=[],i=0;i<n.rows.length;i++)o.push(n.rows.item(i));r()})})}function i(e,t){function n(n){function r(){if(!n.length)return t(e);var o=n.shift(),i=xt(o.hex,_),a=i.lastIndexOf("::"),s=i.substring(0,a),u=i.substring(a+2),c="UPDATE "+jo+" SET doc_id=?, rev=? WHERE doc_id_rev=?";e.executeSql(c,[s,u,i],function(){r()})}r()}var r="ALTER TABLE "+jo+" ADD COLUMN doc_id";e.executeSql(r,[],function(e){var t="ALTER TABLE "+jo+" ADD COLUMN rev";e.executeSql(t,[],function(e){e.executeSql(Mo,[],function(e){var t="SELECT hex(doc_id_rev) as hex FROM "+jo;e.executeSql(t,[],function(e,t){for(var r=[],o=0;o<t.rows.length;o++)r.push(t.rows.item(o));n(r)})})})})}function a(e,t){function n(e){var n="SELECT COUNT(*) AS cnt FROM "+Co;e.executeSql(n,[],function(e,n){function r(){var n=It(Ko+", "+Oo+".id AS id",[Oo,jo],zo,null,Oo+".id ");n+=" LIMIT "+a+" OFFSET "+i,i+=a,e.executeSql(n,[],function(e,n){function o(e,t){var n=i[e]=i[e]||[];-1===n.indexOf(t)&&n.push(t)}if(!n.rows.length)return t(e);for(var i={},a=0;a<n.rows.length;a++)for(var s=n.rows.item(a),u=Ct(s.data,s.id,s.rev),c=Object.keys(u._attachments||{}),f=0;f<c.length;f++){var l=u._attachments[c[f]];o(l.digest,s.seq)}var d=[];if(Object.keys(i).forEach(function(e){var t=i[e];t.forEach(function(t){d.push([e,t])})}),!d.length)return r();var h=0;d.forEach(function(t){var n="INSERT INTO "+Do+" (digest, seq) VALUES (?,?)";e.executeSql(n,t,function(){++h===d.length&&r()})})})}var o=n.rows.item(0).cnt;if(!o)return t(e);var i=0,a=10;r()})}var r="CREATE TABLE IF NOT EXISTS "+Do+" (digest, seq INTEGER)";e.executeSql(r,[],function(e){e.executeSql(Ho,[],function(e){e.executeSql(Uo,[],n)})})}function s(e,t){var n="ALTER TABLE "+Co+" ADD COLUMN escaped TINYINT(1) DEFAULT 0";e.executeSql(n,[],t)}function u(e,t){var n="ALTER TABLE "+Oo+" ADD COLUMN max_seq INTEGER";e.executeSql(n,[],function(e){var n="UPDATE "+Oo+" SET max_seq=(SELECT MAX(seq) FROM "+jo+" WHERE doc_id=id)";e.executeSql(n,[],function(e){var n="CREATE UNIQUE INDEX IF NOT EXISTS 'doc-max-seq-idx' ON "+Oo+" (max_seq)";e.executeSql(n,[],t)})})}function f(e,t){e.executeSql('SELECT HEX("a") AS hex',[],function(e,n){var r=n.rows.item(0).hex;_=2===r.length?"UTF-8":"UTF-16",t()})}function d(){for(;E.length>0;){var e=E.pop();e(null,b)}}function h(e,t){if(0===t){var n="CREATE TABLE IF NOT EXISTS "+Io+" (dbid, db_version INTEGER)",c="CREATE TABLE IF NOT EXISTS "+Co+" (digest UNIQUE, escaped TINYINT(1), body BLOB)",f="CREATE TABLE IF NOT EXISTS "+Do+" (digest, seq INTEGER)",l="CREATE TABLE IF NOT EXISTS "+Oo+" (id unique, json, winningseq, max_seq INTEGER UNIQUE)",h="CREATE TABLE IF NOT EXISTS "+jo+" (seq INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, json, deleted TINYINT(1), doc_id, rev)",p="CREATE TABLE IF NOT EXISTS "+Lo+" (id UNIQUE, rev, json)";e.executeSql(c),e.executeSql(p),e.executeSql(f,[],function(){e.executeSql(Uo),e.executeSql(Ho)}),e.executeSql(l,[],function(){e.executeSql(Fo),e.executeSql(h,[],function(){e.executeSql(Po),e.executeSql(Mo),e.executeSql(n,[],function(){var t="INSERT INTO "+Io+" (db_version, dbid) VALUES (?,?)";b=M();var n=[To,b];e.executeSql(t,n,function(){d()})})})})}else{var v=function(){var n=To>t;n&&e.executeSql("UPDATE "+Io+" SET db_version = "+To);var r="SELECT dbid FROM "+Io;e.executeSql(r,[],function(e,t){b=t.rows.item(0).dbid,d()})},y=[r,o,i,a,s,u,v],_=t,m=function(e){y[_-1](e,m),_++};m(e)}}function p(){q.transaction(function(e){f(e,function(){v(e)})},Rt(t),n)}function v(e){var t="SELECT sql FROM sqlite_master WHERE tbl_name = "+Io;e.executeSql(t,[],function(e,t){t.rows.length?/db_version/.test(t.rows.item(0).sql)?e.executeSql("SELECT db_version FROM "+Io,[],function(e,t){var n=t.rows.item(0).db_version;h(e,n)}):e.executeSql("ALTER TABLE "+Io+" ADD COLUMN db_version INTEGER",[],function(){h(e,1)}):h(e,0)})}function y(e,t){if(-1!==g._docCount)return t(g._docCount);var n=It("COUNT("+Oo+".id) AS 'num'",[Oo,jo],zo,jo+".deleted=0");e.executeSql(n,[],function(e,n){g._docCount=n.rows.item(0).num,t(g._docCount)})}var _,g=this,b=null,w=Nt(e),E=[];g._docCount=-1,g._name=e.name;var k=br.extend({},e,{version:Bo,description:e.name,size:w}),S=Ft(k);if(S.error)return Rt(t)(S.error);var q=S.db;"function"!=typeof q.readTransaction&&(q.readTransaction=q.transaction),p(),g.type=function(){return"websql"},g._id=l(function(e){e(null,b)}),g._info=function(e){q.readTransaction(function(t){y(t,function(n){var r="SELECT MAX(seq) AS seq FROM "+jo;t.executeSql(r,[],function(t,r){var o=r.rows.item(0).seq||0;e(null,{doc_count:n,update_seq:o,sqlite_plugin:q._sqlitePlugin,websql_encoding:_})})})},Rt(e))},g._bulkDocs=function(t,n,r){Bt(e,t,n,g,q,No,r)},g._get=function(e,t,n){function r(){n(a,{doc:o,metadata:i,ctx:s})}var o,i,a,s=t.ctx;if(!s)return q.readTransaction(function(r){g._get(e,br.extend({ctx:r},t),n)});var u,c;t.rev?(u=It(Ko,[Oo,jo],Oo+".id="+jo+".doc_id",[jo+".doc_id=?",jo+".rev=?"]),c=[e,t.rev]):(u=It(Ko,[Oo,jo],zo,Oo+".id=?"),c=[e]),s.executeSql(u,c,function(e,n){if(!n.rows.length)return a=x(Mr,"missing"),r();var s=n.rows.item(0);return i=et(s.metadata),s.deleted&&!t.rev?(a=x(Mr,"deleted"),r()):(o=Ct(s.data,i.id,s.rev),void r())})},g._allDocs=function(e,t){var n,r=[],o="startkey"in e?e.startkey:!1,i="endkey"in e?e.endkey:!1,a="key"in e?e.key:!1,s="descending"in e?e.descending:!1,u="limit"in e?e.limit:-1,c="skip"in e?e.skip:0,f=e.inclusive_end!==!1,l=[],d=[];if(a!==!1)d.push(Oo+".id = ?"),l.push(a);else if(o!==!1||i!==!1){if(o!==!1&&(d.push(Oo+".id "+(s?"<=":">=")+" ?"),l.push(o)),i!==!1){var h=s?">":"<";f&&(h+="="),d.push(Oo+".id "+h+" ?"),l.push(i)}a!==!1&&(d.push(Oo+".id = ?"),l.push(a))}"ok"!==e.deleted&&d.push(jo+".deleted = 0"),q.readTransaction(function(t){y(t,function(o){if(n=o,0!==u){var i=It(Ko,[Oo,jo],zo,d,Oo+".id "+(s?"DESC":"ASC"));i+=" LIMIT "+u+" OFFSET "+c,t.executeSql(i,l,function(t,n){for(var o=0,i=n.rows.length;i>o;o++){var a=n.rows.item(o),s=et(a.metadata),u=s.id,c=Ct(a.data,u,a.rev),f=c._rev,l={id:u,key:u,value:{rev:f}};if(e.include_docs&&(l.doc=c,l.doc._rev=f,e.conflicts&&(l.doc._conflicts=K(s)),Ut(l.doc,e,g,t)),a.deleted){if("ok"!==e.deleted)continue;l.value.deleted=!0,l.doc=null}r.push(l)}})}})},Rt(t),function(){t(null,{total_rows:n,offset:e.skip,rows:r})})},g._changes=function(e){function t(){var t=Oo+".json AS metadata, "+Oo+".max_seq AS maxSeq, "+jo+".json AS winningDoc, "+jo+".rev AS winningRev ",n=Oo+" JOIN "+jo,u=Oo+".id="+jo+".doc_id AND "+Oo+".winningseq="+jo+".seq",c=["maxSeq > ?"],f=[e.since];e.doc_ids&&(c.push(Oo+".id IN "+Lt(e.doc_ids.length)),f=f.concat(e.doc_ids));var l="maxSeq "+(r?"DESC":"ASC"),d=It(t,n,u,c,l),h=O(e);e.view||e.filter||(d+=" LIMIT "+o);var p=e.since||0;q.readTransaction(function(t){t.executeSql(d,f,function(t,n){function r(t){return function(){e.onChange(t)}}for(var u=0,c=n.rows.length;c>u;u++){var f=n.rows.item(u),l=et(f.metadata);p=f.maxSeq;var d=Ct(f.winningDoc,l.id,f.winningRev),v=e.processChange(d,l,e);v.seq=f.maxSeq;var y=h(v);if("object"==typeof y)return e.complete(y);if(y&&(s++,i&&a.push(v),e.attachments&&e.include_docs?Ut(d,e,g,t,r(v)):r(v)()),s===o)break}})},Rt(e.complete),function(){e.continuous||e.complete(null,{results:a,last_seq:p})})}if(e=c(e),e.continuous){var n=g._name+":"+M();return No.addListener(g._name,n,g,e),No.notify(g._name),{cancel:function(){No.removeListener(g._name,n)}}}var r=e.descending;e.since=e.since&&!r?e.since:0;var o="limit"in e?e.limit:-1;0===o&&(o=1);var i;i="return_docs"in e?e.return_docs:"returnDocs"in e?e.returnDocs:!0;var a=[],s=0;t()},g._close=function(e){e()},g._getAttachment=function(e,t,n,r,o){var i,a=r.ctx,s=n.digest,u=n.content_type,c="SELECT escaped, CASE WHEN escaped = 1 THEN body ELSE HEX(body) END AS body FROM "+Co+" WHERE digest=?";a.executeSql(c,[s],function(e,t){var n=t.rows.item(0),a=n.escaped?Ot(n.body):xt(n.body,_);i=r.binary?Le(a,u):ho(a),o(null,i)})},g._getRevisionTree=function(e,t){q.readTransaction(function(n){var r="SELECT json AS metadata FROM "+Oo+" WHERE id = ?";n.executeSql(r,[e],function(e,n){if(n.rows.length){var r=et(n.rows.item(0).metadata);t(null,r.rev_tree)}else t(x(Mr))})})},g._doCompaction=function(e,t,n){return t.length?void q.transaction(function(n){var r="SELECT json AS metadata FROM "+Oo+" WHERE id = ?";n.executeSql(r,[e],function(n,r){var o=et(r.rows.item(0).metadata);U(o.rev_tree,function(e,n,r,o,i){var a=n+"-"+r;-1!==t.indexOf(a)&&(i.status="missing")});var i="UPDATE "+Oo+" SET json = ? WHERE id = ?";n.executeSql(i,[tt(o),e])}),Dt(t,e,n)},Rt(n),function(){n()}):n()},g._getLocal=function(e,t){q.readTransaction(function(n){var r="SELECT json, rev FROM "+Lo+" WHERE id=?";n.executeSql(r,[e],function(n,r){if(r.rows.length){var o=r.rows.item(0),i=Ct(o.json,e,o.rev);t(null,i)}else t(x(Mr))})})},g._putLocal=function(e,t,n){function r(e){var r,c;i?(r="UPDATE "+Lo+" SET rev=?, json=? WHERE id=? AND rev=?",c=[o,u,a,i]):(r="INSERT INTO "+Lo+" (id, rev, json) VALUES (?,?,?)",c=[a,o,u]),e.executeSql(r,c,function(e,r){r.rowsAffected?(s={ok:!0,id:a,rev:o},t.ctx&&n(null,s)):n(x(Fr))},function(){return n(x(Fr)),!1})}"function"==typeof t&&(n=t,t={}),delete e._revisions;var o,i=e._rev,a=e._id;o=i?e._rev="0-"+(parseInt(i.split("-")[1],10)+1):e._rev="0-1";var s,u=jt(e);t.ctx?r(t.ctx):q.transaction(r,Rt(n),function(){s&&n(null,s)})},g._removeLocal=function(e,t,n){function r(r){var i="DELETE FROM "+Lo+" WHERE id=? AND rev=?",a=[e._id,e._rev];r.executeSql(i,a,function(r,i){return i.rowsAffected?(o={ok:!0,id:e._id,rev:"0-0"},void(t.ctx&&n(null,o))):n(x(Mr))})}"function"==typeof t&&(n=t,t={});var o;t.ctx?r(t.ctx):q.transaction(r,Rt(n),function(){o&&n(null,o)})},g._destroy=function(e,t){No.removeAllListeners(g._name),q.transaction(function(e){var t=[Oo,jo,Co,Io,Lo,Do];t.forEach(function(t){e.executeSql("DROP TABLE IF EXISTS "+t,[])})},Rt(t),function(){m()&&(delete window.localStorage["_pouch__websqldb_"+g._name],delete window.localStorage[g._name]),t(null,{ok:!0})})}}function zt(){try{return openDatabase("_pouch_validate_websql",1,"",1),!0}catch(e){return!1}}function Kt(){if("undefined"==typeof indexedDB||null===indexedDB||!/iP(hone|od|ad)/.test(navigator.userAgent))return!0;var e=m(),t="_pouch__websqldb_valid_"+navigator.userAgent;if(e&&localStorage[t])return"1"===localStorage[t];var n=zt();return e&&(localStorage[t]=n?"1":"0"),n}function Wt(){return"undefined"==typeof openDatabase?!1:"undefined"!=typeof sqlitePlugin?!0:Kt()}function Jt(){return"undefined"!=typeof cordova?!0:Wt()}function Xt(e){return function(t,n,r,o){if("undefined"!=typeof sqlitePlugin){var i=br.extend({},e,{name:t,version:n,description:r,size:o});return sqlitePlugin.openDatabase(i)}return openDatabase(t,n,r,o)}}function Gt(e,t){var n=Xt(e),r=br.extend({websql:n},e);"undefined"==typeof cordova||Wt()||w("error","PouchDB error: you must install a SQLite plugin in order for PouchDB to work on this platform. Options:\n - https://github.com/nolanlawson/cordova-plugin-sqlite-2\n - https://github.com/litehelpers/Cordova-sqlite-storage\n - https://github.com/Microsoft/cordova-plugin-websql"),Ht.call(this,r,t)}function Vt(e){e.adapter("websql",Gt,!0)}function Qt(){for(var e={},t=new Lr(function(t,n){e.resolve=t,e.reject=n}),n=new Array(arguments.length),r=0;r<n.length;r++)n[r]=arguments[r];return e.promise=t,Lr.resolve().then(function(){return fetch.apply(null,n)}).then(function(t){e.resolve(t)})["catch"](function(t){e.reject(t)}),e}function $t(e,t){var n,r,o,i=new Headers,a={method:e.method,credentials:"include",headers:i};return e.json&&(i.set("Accept","application/json"),i.set("Content-Type",e.headers["Content-Type"]||"application/json")),e.body&&e.body instanceof Blob?Pe(e.body,function(e){a.body=e}):e.body&&e.processData&&"string"!=typeof e.body?a.body=JSON.stringify(e.body):"body"in e?a.body=e.body:a.body=null,Object.keys(e.headers).forEach(function(t){e.headers.hasOwnProperty(t)&&i.set(t,e.headers[t])}),n=Qt(e.url,a),e.timeout>0&&(r=setTimeout(function(){n.reject(new Error("Load timeout for resource: "+e.url))},e.timeout)),n.promise.then(function(t){return o={statusCode:t.status},e.timeout>0&&clearTimeout(r),o.statusCode>=200&&o.statusCode<300?e.binary?t.blob():t.text():t.json()}).then(function(e){o.statusCode>=200&&o.statusCode<300?t(null,o,e):t(e,o)})["catch"](function(e){t(e,o)}),{abort:n.reject}}function Yt(e,t){var n,r,o=!1,i=function(){n.abort()},a=function(){o=!0,n.abort()};n=e.xhr?new e.xhr:new XMLHttpRequest;try{n.open(e.method,e.url)}catch(s){return t(new Error(s.name||"Url is invalid"))}n.withCredentials="withCredentials"in e?e.withCredentials:!0,"GET"===e.method?delete e.headers["Content-Type"]:e.json&&(e.headers.Accept="application/json",e.headers["Content-Type"]=e.headers["Content-Type"]||"application/json",e.body&&e.processData&&"string"!=typeof e.body&&(e.body=JSON.stringify(e.body))),e.binary&&(n.responseType="arraybuffer"),"body"in e||(e.body=null);for(var u in e.headers)e.headers.hasOwnProperty(u)&&n.setRequestHeader(u,e.headers[u]);return e.timeout>0&&(r=setTimeout(a,e.timeout),n.onprogress=function(){clearTimeout(r),4!==n.readyState&&(r=setTimeout(a,e.timeout))},"undefined"!=typeof n.upload&&(n.upload.onprogress=n.onprogress)),n.onreadystatechange=function(){if(4===n.readyState){var r={statusCode:n.status};if(n.status>=200&&n.status<300){var i;i=e.binary?je([n.response||""],{
type:n.getResponseHeader("Content-Type")}):n.responseText,t(null,r,i)}else{var a={};if(o)a=new Error("ETIMEDOUT"),a.code="ETIMEDOUT";else try{a=JSON.parse(n.response)}catch(s){}a.status=n.status,t(a)}}},e.body&&e.body instanceof Blob?Pe(e.body,function(e){n.send(e)}):n.send(e.body),{abort:i}}function Zt(){try{return new XMLHttpRequest,!0}catch(e){return!1}}function en(e,t){return Wo||e.xhr?Yt(e,t):$t(e,t)}function tn(){return""}function nn(e,t){function n(t,n,r){if(!e.binary&&e.json&&"string"==typeof t)try{t=JSON.parse(t)}catch(o){return r(o)}Array.isArray(t)&&(t=t.map(function(e){return e.error||e.missing?A(e):e})),e.binary&&Jo(t,n),r(null,t,n)}e=c(e);var r={method:"GET",headers:{},json:!0,processData:!0,timeout:1e4,cache:!1};return e=br.extend(r,e),e.json&&(e.binary||(e.headers.Accept="application/json"),e.headers["Content-Type"]=e.headers["Content-Type"]||"application/json"),e.binary&&(e.encoding=null,e.json=!1),e.processData||(e.json=!1),en(e,function(r,o,i){if(r)return t(A(r));var a,s=o.headers&&o.headers["content-type"],u=i||tn();if(!e.binary&&(e.json||!e.processData)&&"object"!=typeof u&&(/json/.test(s)||/^[\s]*\{/.test(u)&&/\}[\s]*$/.test(u)))try{u=JSON.parse(u.toString())}catch(c){}o.statusCode>=200&&o.statusCode<300?n(u,o,t):(a=A(u),a.status=o.statusCode,t(a))})}function rn(e,t){var n=navigator&&navigator.userAgent?navigator.userAgent.toLowerCase():"",r=-1!==n.indexOf("safari")&&-1===n.indexOf("chrome"),o=-1!==n.indexOf("msie"),i=-1!==n.indexOf("edge"),a=r||(o||i)&&"GET"===e.method,s="cache"in e?e.cache:!0,u=/^blob:/.test(e.url);if(!u&&(a||!s)){var c=-1!==e.url.indexOf("?");e.url+=(c?"&":"?")+"_nonce="+Date.now()}return nn(e,t)}function on(e){var t=e.doc&&e.doc._attachments;t&&Object.keys(t).forEach(function(e){var n=t[e];n.data=Ie(n.data,n.content_type)})}function an(e){return/^_design/.test(e)?"_design/"+encodeURIComponent(e.slice(8)):/^_local/.test(e)?"_local/"+encodeURIComponent(e.slice(7)):encodeURIComponent(e)}function sn(e){return e._attachments&&Object.keys(e._attachments)?Lr.all(Object.keys(e._attachments).map(function(t){var n=e._attachments[t];return n.data&&"string"!=typeof n.data?new Lr(function(e){Be(n.data,e)}).then(function(e){n.data=e}):void 0})):Lr.resolve()}function un(e){var t=R(e);(t.user||t.password)&&(t.auth={username:t.user,password:t.password});var n=t.path.replace(/(^\/|\/$)/g,"").split("/");return t.db=n.pop(),-1===t.db.indexOf("%")&&(t.db=encodeURIComponent(t.db)),t.path=n.join("/"),t}function cn(e,t){return fn(e,e.db+"/"+t)}function fn(e,t){var n=e.path?"/":"";return e.protocol+"://"+e.host+(e.port?":"+e.port:"")+"/"+e.path+n+t}function ln(e){return"?"+Object.keys(e).map(function(t){return t+"="+encodeURIComponent(e[t])}).join("&")}function dn(e,t){function n(e,t,n){var r=e.ajax||{},o=br.extend(c(p),r,t);return $o(o.method+" "+o.url),s._ajax(o,n)}function r(e,t){return new Lr(function(r,o){n(e,t,function(e,t){return e?o(e):void r(t)})})}function o(e,t){return d(e,qr(function(e){i().then(function(){return t.apply(this,e)})["catch"](function(t){var n=e.pop();n(t)})}))}function i(){if(e.skipSetup||e.skip_setup)return Lr.resolve();if(g)return g;var t={method:"GET",url:l};return g=r({},t)["catch"](function(e){return e&&e.status&&404===e.status?(S(404,"PouchDB is just detecting if the remote exists."),r({},{method:"PUT",url:l})):Lr.reject(e)})["catch"](function(e){return e&&e.status&&412===e.status?!0:Lr.reject(e)}),g["catch"](function(){g=null}),g}function a(e){return e.split("/").map(encodeURIComponent).join("/")}var s=this,u=un;e.getHost&&(u=e.getHost);var f=u(e.name,e),l=cn(f,"");e=c(e);var p=e.ajax||{};if(s.getUrl=function(){return l},s.getHeaders=function(){return p.headers||{}},e.auth||f.auth){var v=e.auth||f.auth,_=v.username+":"+v.password,m=ho(unescape(encodeURIComponent(_)));p.headers=p.headers||{},p.headers.Authorization="Basic "+m}s._ajax=rn;var g;setTimeout(function(){t(null,s)}),s.type=function(){return"http"},s.id=o("id",function(e){n({},{method:"GET",url:fn(f,"")},function(t,n){var r=n&&n.uuid?n.uuid+f.db:cn(f,"");e(null,r)})}),s.request=o("request",function(e,t){e.url=cn(f,e.url),n({},e,t)}),s.compact=o("compact",function(e,t){"function"==typeof e&&(t=e,e={}),e=c(e),n(e,{url:cn(f,"_compact"),method:"POST"},function(){function n(){s.info(function(r,o){o&&!o.compact_running?t(null,{ok:!0}):setTimeout(n,e.interval||200)})}n()})}),s.bulkGet=d("bulkGet",function(e,t){function r(t){var r={};e.revs&&(r.revs=!0),e.attachments&&(r.attachments=!0),n({},{url:cn(f,"_bulk_get"+ln(r)),method:"POST",body:{docs:e.docs}},t)}function o(){function n(e){return function(n,r){s[e]=r.results,++a===o&&t(null,{results:j(s)})}}for(var r=Go,o=Math.ceil(e.docs.length/r),a=0,s=new Array(o),u=0;o>u;u++){var c=h(e,["revs","attachments"]);c.ajax=p,c.docs=e.docs.slice(u*r,Math.min(e.docs.length,(u+1)*r)),y(i,c,n(u))}}var i=this,a=fn(f,""),s=Vo[a];"boolean"!=typeof s?r(function(e,n){if(e){var r=Math.floor(e.status/100);4===r||5===r?(Vo[a]=!1,S(e.status,"PouchDB is just detecting if the remote supports the _bulk_get API."),o()):t(e)}else Vo[a]=!0,t(null,n)}):s?r(t):o()}),s._info=function(e){i().then(function(){n({},{method:"GET",url:cn(f,"")},function(t,n){return t?e(t):(n.host=cn(f,""),void e(null,n))})})["catch"](e)},s.get=o("get",function(e,t,n){function o(e){function n(){if(!i.length)return null;var n=i.pop(),s=o[n],u=an(e._id)+"/"+a(n)+"?rev="+e._rev;return r(t,{method:"GET",url:cn(f,u),binary:!0}).then(function(e){return t.binary?e:new Lr(function(t){Be(e,t)})}).then(function(e){delete s.stub,delete s.length,s.data=e})}var o=e._attachments,i=o&&Object.keys(o);return o&&i.length?new jr(n,5,{promise:Lr}).start():void 0}function i(e){return Array.isArray(e)?Lr.all(e.map(function(e){return e.ok?o(e.ok):void 0})):o(e)}"function"==typeof t&&(n=t,t={}),t=c(t);var s={};t.revs&&(s.revs=!0),t.revs_info&&(s.revs_info=!0),t.open_revs&&("all"!==t.open_revs&&(t.open_revs=JSON.stringify(t.open_revs)),s.open_revs=t.open_revs),t.rev&&(s.rev=t.rev),t.conflicts&&(s.conflicts=t.conflicts),e=an(e);var u={method:"GET",url:cn(f,e+ln(s))};r(t,u).then(function(e){return Lr.resolve().then(function(){return t.attachments?i(e):void 0}).then(function(){n(null,e)})})["catch"](n)}),s.remove=o("remove",function(e,t,r,o){var i;"string"==typeof t?(i={_id:e,_rev:t},"function"==typeof r&&(o=r,r={})):(i=e,"function"==typeof t?(o=t,r={}):(o=r,r=t));var a=i._rev||r.rev;n(r,{method:"DELETE",url:cn(f,an(i._id))+"?rev="+a},o)}),s.getAttachment=o("getAttachment",function(e,t,r,o){"function"==typeof r&&(o=r,r={});var i=r.rev?"?rev="+r.rev:"",s=cn(f,an(e))+"/"+a(t)+i;n(r,{method:"GET",url:s,binary:!0},o)}),s.removeAttachment=o("removeAttachment",function(e,t,r,o){var i=cn(f,an(e)+"/"+a(t))+"?rev="+r;n({},{method:"DELETE",url:i},o)}),s.putAttachment=o("putAttachment",function(e,t,r,o,i,s){"function"==typeof i&&(s=i,i=o,o=r,r=null);var u=an(e)+"/"+a(t),c=cn(f,u);if(r&&(c+="?rev="+r),"string"==typeof o){var l;try{l=lo(o)}catch(d){return s(x(Jr,"Attachment is not a valid base64 string"))}o=l?Le(l,i):""}var h={headers:{"Content-Type":i},method:"PUT",url:c,processData:!1,body:o,timeout:p.timeout||6e4};n({},h,s)}),s._bulkDocs=function(e,t,r){e.new_edits=t.new_edits,i().then(function(){return Lr.all(e.docs.map(sn))}).then(function(){n(t,{method:"POST",url:cn(f,"_bulk_docs"),body:e},function(e,t){return e?r(e):(t.forEach(function(e){e.ok=!0}),void r(null,t))})})["catch"](r)},s.allDocs=o("allDocs",function(e,t){"function"==typeof e&&(t=e,e={}),e=c(e);var n,o={},i="GET";e.conflicts&&(o.conflicts=!0),e.descending&&(o.descending=!0),e.include_docs&&(o.include_docs=!0),e.attachments&&(o.attachments=!0),e.key&&(o.key=JSON.stringify(e.key)),e.start_key&&(e.startkey=e.start_key),e.startkey&&(o.startkey=JSON.stringify(e.startkey)),e.end_key&&(e.endkey=e.end_key),e.endkey&&(o.endkey=JSON.stringify(e.endkey)),"undefined"!=typeof e.inclusive_end&&(o.inclusive_end=!!e.inclusive_end),"undefined"!=typeof e.limit&&(o.limit=e.limit),"undefined"!=typeof e.skip&&(o.skip=e.skip);var a=ln(o);if("undefined"!=typeof e.keys){var s="keys="+encodeURIComponent(JSON.stringify(e.keys));s.length+a.length+1<=Qo?a+="&"+s:(i="POST",n={keys:e.keys})}r(e,{method:i,url:cn(f,"_all_docs"+a),body:n}).then(function(n){e.include_docs&&e.attachments&&e.binary&&n.rows.forEach(on),t(null,n)})["catch"](t)}),s._changes=function(e){var t="batch_size"in e?e.batch_size:Xo;e=c(e),e.timeout="timeout"in e?e.timeout:"timeout"in p?p.timeout:3e4;var r,o=e.timeout?{timeout:e.timeout-5e3}:{},a="undefined"!=typeof e.limit?e.limit:!1;r="return_docs"in e?e.return_docs:"returnDocs"in e?e.returnDocs:!0;var s=a;if(e.style&&(o.style=e.style),(e.include_docs||e.filter&&"function"==typeof e.filter)&&(o.include_docs=!0),e.attachments&&(o.attachments=!0),e.continuous&&(o.feed="longpoll"),e.conflicts&&(o.conflicts=!0),e.descending&&(o.descending=!0),"heartbeat"in e?e.heartbeat&&(o.heartbeat=e.heartbeat):o.heartbeat=1e4,e.filter&&"string"==typeof e.filter&&(o.filter=e.filter),e.view&&"string"==typeof e.view&&(o.filter="_view",o.view=e.view),e.query_params&&"object"==typeof e.query_params)for(var u in e.query_params)e.query_params.hasOwnProperty(u)&&(o[u]=e.query_params[u]);var l,d="GET";if(e.doc_ids){o.filter="_doc_ids";var h=JSON.stringify(e.doc_ids);h.length<Qo?o.doc_ids=h:(d="POST",l={doc_ids:e.doc_ids})}var v,y,_=function(r,u){if(!e.aborted){o.since=r,"object"==typeof o.since&&(o.since=JSON.stringify(o.since)),e.descending?a&&(o.limit=s):o.limit=!a||s>t?t:s;var c={method:d,url:cn(f,"_changes"+ln(o)),timeout:e.timeout,body:l};y=r,e.aborted||i().then(function(){v=n(e,c,u)})["catch"](u)}},m={results:[]},g=function(n,o){if(!e.aborted){var i=0;if(o&&o.results){i=o.results.length,m.last_seq=o.last_seq;var u={};u.query=e.query_params,o.results=o.results.filter(function(t){s--;var n=O(e)(t);return n&&(e.include_docs&&e.attachments&&e.binary&&on(t),r&&m.results.push(t),e.onChange(t)),n})}else if(n)return e.aborted=!0,void e.complete(n);o&&o.last_seq&&(y=o.last_seq);var c=a&&0>=s||o&&t>i||e.descending;(!e.continuous||a&&0>=s)&&c?e.complete(null,m):setTimeout(function(){_(y,g)},0)}};return _(e.since||0,g),{cancel:function(){e.aborted=!0,v&&v.abort()}}},s.revsDiff=o("revsDiff",function(e,t,r){"function"==typeof t&&(r=t,t={}),n(t,{method:"POST",url:cn(f,"_revs_diff"),body:e},r)}),s._close=function(e){e()},s._destroy=function(e,t){n(e,{url:cn(f,""),method:"DELETE"},function(e,n){return e&&e.status&&404!==e.status?t(e):void t(null,n)})}}function hn(e){e.adapter("http",dn,!1),e.adapter("https",dn,!1)}function pn(){this.promise=new Lr(function(e){e()})}function vn(e){var t,n=e.db,r=e.viewName,o=e.map,i=e.reduce,a=e.temporary,s=o.toString()+(i&&i.toString())+"undefined";if(!a&&(t=n._cachedViews=n._cachedViews||{},t[s]))return t[s];var u=n.info().then(function(e){function u(e){e.views=e.views||{};var t=r;-1===t.indexOf("/")&&(t=r+"/"+r);var n=e.views[t]=e.views[t]||{};if(!n[c])return n[c]=!0,e}var c=e.db_name+"-mrview-"+(a?"temp":Ke(s));return N(n,"_local/mrviews",u).then(function(){return n.registerDependentDatabase(c).then(function(e){var r=e.db;r.auto_compaction=!0;var a={name:c,db:r,sourceDB:n,adapter:n.adapter,mapFun:o,reduceFun:i};return a.db.get("_local/lastSeq")["catch"](function(e){if(404!==e.status)throw e}).then(function(e){return a.seq=e?e.seq:0,t&&a.db.once("destroyed",function(){delete t[s]}),a})})})});return t&&(t[s]=u),u}function yn(e,t,n,r,o,i){return Ar("return ("+e.replace(/;\s*$/,"")+");",{emit:t,sum:n,log:r,isArray:o,toJSON:i})}function _n(e){return-1===e.indexOf("/")?[e,e]:e.split("/")}function mn(e){return 1===e.length&&/^1-/.test(e[0].rev)}function gn(e,t){try{e.emit("error",t)}catch(n){w("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."),w("error",t)}}function bn(e,t,n){try{return{output:t.apply(null,n)}}catch(r){return gn(e,r),{error:r}}}function wn(e,t){var n=Cr.collate(e.key,t.key);return 0!==n?n:Cr.collate(e.value,t.value)}function En(e,t,n){return n=n||0,"number"==typeof t?e.slice(n,t+n):n>0?e.slice(n):e}function kn(e){var t=e.value,n=t&&"object"==typeof t&&t._id||e.id;return n}function Sn(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=Ie(n.data,n.content_type)})})}function qn(e){return function(t){return e.include_docs&&e.attachments&&e.binary&&Sn(t),t}}function xn(e){var t="builtin "+e+" function requires map values to be numbers or number arrays";return new Qn(t)}function An(e){for(var t=0,n=0,r=e.length;r>n;n++){var o=e[n];if("number"!=typeof o){if(!Array.isArray(o))throw xn("_sum");t="number"==typeof t?[t]:t;for(var i=0,a=o.length;a>i;i++){var s=o[i];if("number"!=typeof s)throw xn("_sum");"undefined"==typeof t[i]?t.push(s):t[i]+=s}}else"number"==typeof t?t+=o:t[0]+=o}return t}function Tn(e,t,n,r){var o=t[e];"undefined"!=typeof o&&(r&&(o=encodeURIComponent(JSON.stringify(o))),n.push(e+"="+o))}function On(e){if("undefined"!=typeof e){var t=Number(e);return isNaN(t)||t!==parseInt(e,10)?e:t}}function jn(e){return e.group_level=On(e.group_level),e.limit=On(e.limit),e.skip=On(e.skip),e}function Cn(e){if(e){if("number"!=typeof e)return new Gn('Invalid value for integer: "'+e+'"');if(0>e)return new Gn('Invalid value for positive integer: "'+e+'"')}}function Ln(e,t){var n=e.descending?"endkey":"startkey",r=e.descending?"startkey":"endkey";if("undefined"!=typeof e[n]&&"undefined"!=typeof e[r]&&Cr.collate(e[n],e[r])>0)throw new Gn("No rows can match your key range, reverse your start_key and end_key or set {descending : true}");if(t.reduce&&e.reduce!==!1){if(e.include_docs)throw new Gn("{include_docs:true} is invalid for reduce");if(e.keys&&e.keys.length>1&&!e.group&&!e.group_level)throw new Gn("Multi-key fetches for reduce views must use {group: true}")}["group_level","limit","skip"].forEach(function(t){var n=Cn(e[t]);if(n)throw n})}function In(e,t,n){var r,o=[],i="GET";if(Tn("reduce",n,o),Tn("include_docs",n,o),Tn("attachments",n,o),Tn("limit",n,o),Tn("descending",n,o),Tn("group",n,o),Tn("group_level",n,o),Tn("skip",n,o),Tn("stale",n,o),Tn("conflicts",n,o),Tn("startkey",n,o,!0),Tn("start_key",n,o,!0),Tn("endkey",n,o,!0),Tn("end_key",n,o,!0),Tn("inclusive_end",n,o),Tn("key",n,o,!0),o=o.join("&"),o=""===o?"":"?"+o,"undefined"!=typeof n.keys){var a=2e3,s="keys="+encodeURIComponent(JSON.stringify(n.keys));s.length+o.length+1<=a?o+=("?"===o[0]?"&":"?")+s:(i="POST","string"==typeof t?r={keys:n.keys}:t.keys=n.keys)}if("string"==typeof t){var u=_n(t);return e.request({method:i,url:"_design/"+u[0]+"/_view/"+u[1]+o,body:r}).then(qn(n))}return r=r||{},Object.keys(t).forEach(function(e){Array.isArray(t[e])?r[e]=t[e]:r[e]=t[e].toString()}),e.request({method:"POST",url:"_temp_view"+o,body:r}).then(qn(n))}function Dn(e,t,n){return new Lr(function(r,o){e._query(t,n,function(e,t){return e?o(e):void r(t)})})}function Rn(e){return new Lr(function(t,n){e._viewCleanup(function(e,r){return e?n(e):void t(r)})})}function Nn(e){return function(t){if(404===t.status)return e;throw t}}function Bn(e,t,n){function r(){return mn(f)?Lr.resolve(s):t.db.get(a)["catch"](Nn(s))}function o(e){return e.keys.length?t.db.allDocs({keys:e.keys,include_docs:!0}):Lr.resolve({rows:[]})}function i(e,t){for(var n=[],r={},o=0,i=t.rows.length;i>o;o++){var a=t.rows[o],s=a.doc;if(s&&(n.push(s),r[s._id]=!0,s._deleted=!c[s._id],!s._deleted)){var u=c[s._id];"value"in u&&(s.value=u.value)}}var f=Object.keys(c);return f.forEach(function(e){if(!r[e]){var t={_id:e},o=c[e];"value"in o&&(t.value=o.value),n.push(t)}}),e.keys=ni(f.concat(e.keys)),n.push(e),n}var a="_local/doc_"+e,s={_id:a,keys:[]},u=n[e],c=u.indexableKeysToKeyValues,f=u.changes;return r().then(function(e){return o(e).then(function(t){return i(e,t)})})}function Pn(e,t,n){var r="_local/lastSeq";return e.db.get(r)["catch"](Nn({_id:r,seq:0})).then(function(r){var o=Object.keys(t);return Lr.all(o.map(function(n){return Bn(n,e,t)})).then(function(t){var o=j(t);return r.seq=n,o.push(r),e.db.bulkDocs({docs:o})})})}function Mn(e){var t="string"==typeof e?e:e.name,n=ri[t];return n||(n=ri[t]=new pn),n}function Fn(e){return ti(Mn(e),function(){return Un(e)})()}function Un(e){function t(e,t){var n={id:o._id,key:Cr.normalizeKey(e)};"undefined"!=typeof t&&null!==t&&(n.value=Cr.normalizeKey(t)),r.push(n)}function n(t,n){return function(){return Pn(e,t,n)}}var r,o,i;if("function"==typeof e.mapFun&&2===e.mapFun.length){var a=e.mapFun;i=function(e){return a(e,t)}}else i=yn(e.mapFun.toString(),t,An,ai,Array.isArray,JSON.parse);var s=e.seq||0,u=new pn;return new Lr(function(t,a){function c(){u.finish().then(function(){e.seq=s,t()})}function f(){function t(e){a(e)}e.sourceDB.changes({conflicts:!0,include_docs:!0,style:"all_docs",since:s,limit:ii}).on("complete",function(t){var a=t.results;if(!a.length)return c();for(var l={},d=0,h=a.length;h>d;d++){var p=a[d];if("_"!==p.doc._id[0]){r=[],o=p.doc,o._deleted||bn(e.sourceDB,i,[o]),r.sort(wn);for(var v,y={},_=0,m=r.length;m>_;_++){var g=r[_],b=[g.key,g.id];0===Cr.collate(g.key,v)&&b.push(_);var w=Cr.toIndexableString(b);y[w]=g,v=g.key}l[p.doc._id]={indexableKeysToKeyValues:y,changes:p.changes}}s=p.seq}return u.add(n(l,s)),a.length<ii?c():f()}).on("error",t)}f()})}function Hn(e,t,n){0===n.group_level&&delete n.group_level;var r,o=n.group||n.group_level;r=si[e.reduceFun]?si[e.reduceFun]:yn(e.reduceFun.toString(),null,An,ai,Array.isArray,JSON.parse);var i=[],a=isNaN(n.group_level)?Number.POSITIVE_INFINITY:n.group_level;t.forEach(function(e){var t=i[i.length-1],n=o?e.key:null;return o&&Array.isArray(n)&&(n=n.slice(0,a)),t&&0===Cr.collate(t.groupKey,n)?(t.keys.push([e.key,e.id]),void t.values.push(e.value)):void i.push({keys:[[e.key,e.id]],values:[e.value],groupKey:n})}),t=[];for(var s=0,u=i.length;u>s;s++){var c=i[s],f=bn(e.sourceDB,r,[c.keys,c.values,!1]);if(f.error&&f.error instanceof Qn)throw f.error;t.push({value:f.error?null:f.output,key:c.groupKey})}return{rows:En(t,n.limit,n.skip)}}function zn(e,t){return ti(Mn(e),function(){return Kn(e,t)})()}function Kn(e,t){function n(t){return t.include_docs=!0,e.db.allDocs(t).then(function(e){return o=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(!(n>t||t>n))return e.doc.value}var r=Cr.parseIndexableString(e.doc._id);return{key:r[0],id:r[1],value:"value"in e.doc?e.doc.value:null}})})}function r(n){var r;if(r=i?Hn(e,n,t):{total_rows:o,offset:a,rows:n},t.include_docs){var s=ni(n.map(kn));return e.sourceDB.allDocs({keys:s,include_docs:!0,conflicts:t.conflicts,attachments:t.attachments,binary:t.binary}).then(function(e){var t={};return e.rows.forEach(function(e){e.doc&&(t["$"+e.id]=e.doc)}),n.forEach(function(e){var n=kn(e),r=t["$"+n];r&&(e.doc=r)}),r})}return r}var o,i=e.reduceFun&&t.reduce!==!1,a=t.skip||0;if("undefined"==typeof t.keys||t.keys.length||(t.limit=0,delete t.keys),"undefined"!=typeof t.keys){var s=t.keys,u=s.map(function(e){var t={startkey:Cr.toIndexableString([e]),endkey:Cr.toIndexableString([e,{}])};return n(t)});return Lr.all(u).then(j).then(r)}var c={descending:t.descending};if(t.start_key&&(t.startkey=t.start_key),t.end_key&&(t.endkey=t.end_key),"undefined"!=typeof t.startkey&&(c.startkey=t.descending?Cr.toIndexableString([t.startkey,{}]):Cr.toIndexableString([t.startkey])),"undefined"!=typeof t.endkey){var f=t.inclusive_end!==!1;t.descending&&(f=!f),c.endkey=Cr.toIndexableString(f?[t.endkey,{}]:[t.endkey])}if("undefined"!=typeof t.key){var l=Cr.toIndexableString([t.key]),d=Cr.toIndexableString([t.key,{}]);c.descending?(c.endkey=l,c.startkey=d):(c.startkey=l,c.endkey=d)}return i||("number"==typeof t.limit&&(c.limit=t.limit),c.skip=a),n(c).then(r)}function Wn(e){return e.request({method:"POST",url:"_view_cleanup"})}function Jn(e){return e.get("_local/mrviews").then(function(t){var n={};Object.keys(t.views).forEach(function(e){var t=_n(e),r="_design/"+t[0],o=t[1];n[r]=n[r]||{},n[r][o]=!0});var r={keys:Object.keys(n),include_docs:!0};return e.allDocs(r).then(function(r){var o={};r.rows.forEach(function(e){var r=e.key.substring(8);Object.keys(n[e.key]).forEach(function(n){var i=r+"/"+n;t.views[i]||(i=n);var a=Object.keys(t.views[i]),s=e.doc&&e.doc.views&&e.doc.views[n];a.forEach(function(e){o[e]=o[e]||s})})});var i=Object.keys(o).filter(function(e){return!o[e]}),a=i.map(function(t){return ti(Mn(t),function(){return new e.constructor(t,e.__opts).destroy()})()});return Lr.all(a).then(function(){return{ok:!0}})})},Nn({ok:!0}))}function Xn(e,t,r){if("http"===e.type())return In(e,t,r);if("function"==typeof e._query)return Dn(e,t,r);if("string"!=typeof t){Ln(r,t);var o={db:e,viewName:"temp_view/temp_view",map:t.map,reduce:t.reduce,temporary:!0};return oi.add(function(){return vn(o).then(function(e){function t(){return e.db.destroy()}return ei(Fn(e).then(function(){return zn(e,r)}),t)})}),oi.finish()}var i=t,a=_n(i),s=a[0],u=a[1];return e.get("_design/"+s).then(function(t){var o=t.views&&t.views[u];if(!o||"string"!=typeof o.map)throw new Vn("ddoc "+s+" has no view named "+u);Ln(r,o);var a={db:e,viewName:i,map:o.map,reduce:o.reduce};return vn(a).then(function(e){return"ok"===r.stale||"update_after"===r.stale?("update_after"===r.stale&&n.nextTick(function(){Fn(e)}),zn(e,r)):Fn(e).then(function(){return zn(e,r)})})})}function Gn(e){this.status=400,this.name="query_parse_error",this.message=e,this.error=!0;try{Error.captureStackTrace(this,Gn)}catch(t){}}function Vn(e){this.status=404,this.name="not_found",this.message=e,this.error=!0;try{Error.captureStackTrace(this,Vn)}catch(t){}}function Qn(e){this.status=500,this.name="invalid_value",this.message=e,this.error=!0;try{Error.captureStackTrace(this,Qn)}catch(t){}}function $n(e){return/^1-/.test(e)}function Yn(e,t,n){return!e._attachments||!e._attachments[n]||e._attachments[n].digest!==t._attachments[n].digest}function Zn(e,t){var n=Object.keys(t._attachments);return Lr.all(n.map(function(n){return e.getAttachment(t._id,n,{rev:t._rev})}))}function er(e,t,n){var r="http"===t.type()&&"http"!==e.type(),o=Object.keys(n._attachments);return r?e.get(n._id).then(function(r){return Lr.all(o.map(function(o){return Yn(r,n,o)?t.getAttachment(n._id,o):e.getAttachment(r._id,o)}))})["catch"](function(e){if(404!==e.status)throw e;return Zn(t,n)}):Zn(t,n)}function tr(e){var t=[];return Object.keys(e).forEach(function(n){var r=e[n].missing;r.forEach(function(e){t.push({id:n,rev:e})})}),{docs:t,revs:!0}}function nr(e,t,n,r){function o(){var o=tr(n);if(o.docs.length)return e.bulkGet(o).then(function(n){if(r.cancelled)throw new Error("cancelled");return Lr.all(n.results.map(function(n){return Lr.all(n.docs.map(function(n){var r=n.ok;return n.error&&(l=!1),r&&r._attachments?er(t,e,r).then(function(e){var t=Object.keys(r._attachments);return e.forEach(function(e,n){var o=r._attachments[t[n]];delete o.stub,delete o.length,o.data=e}),r}):r}))})).then(function(e){f=f.concat(j(e).filter(Boolean))})})}function i(e){return e._attachments&&Object.keys(e._attachments).length>0}function a(t){return e.allDocs({keys:t,include_docs:!0}).then(function(e){if(r.cancelled)throw new Error("cancelled");e.rows.forEach(function(e){!e.deleted&&e.doc&&$n(e.value.rev)&&!i(e.doc)&&(f.push(e.doc),delete n[e.id])})})}function s(){var e=Object.keys(n).filter(function(e){var t=n[e].missing;return 1===t.length&&$n(t[0])});return e.length>0?a(e):void 0}function u(){return{ok:l,docs:f}}n=c(n);var f=[],l=!0;return Lr.resolve().then(s).then(o).then(u)}function rr(e,t,n,r,o){return e.get(t)["catch"](function(n){if(404===n.status)return"http"===e.type()&&S(404,"PouchDB is just checking if a remote checkpoint exists."),{session_id:r,_id:t,history:[],replicator:di,version:li};throw n}).then(function(i){return o.cancelled?void 0:(i.history=(i.history||[]).filter(function(e){return e.session_id!==r}),i.history.unshift({last_seq:n,session_id:r}),i.history=i.history.slice(0,hi),i.version=li,i.replicator=di,i.session_id=r,i.last_seq=n,e.put(i)["catch"](function(i){if(409===i.status)return rr(e,t,n,r,o);throw i}))})}function or(e,t,n,r){this.src=e,this.target=t,this.id=n,this.returnValue=r}function ir(e,t){return e.session_id===t.session_id?{last_seq:e.last_seq,history:e.history}:ar(e.history,t.history)}function ar(e,t){var n=e[0],r=e.slice(1),o=t[0],i=t.slice(1);if(!n||0===t.length)return{last_seq:pi,history:[]};var a=n.session_id;if(sr(a,t))return{last_seq:n.last_seq,history:e};var s=o.session_id;return sr(s,r)?{last_seq:o.last_seq,history:i}:ar(r,i)}function sr(e,t){var n=t[0],r=t.slice(1);return e&&0!==t.length?e===n.session_id?!0:sr(e,r):!1}function ur(e){return"number"==typeof e.status&&4===Math.floor(e.status/100)}function cr(e,t,n,r){if(e.retry===!1)return t.emit("error",n),void t.removeAllListeners();if("function"!=typeof e.back_off_function&&(e.back_off_function=k),t.emit("requestError",n),"active"===t.state||"pending"===t.state){t.emit("paused",n),t.state="stopped";var o=function(){e.current_back_off=yi},i=function(){t.removeListener("active",o)};t.once("paused",i),t.once("active",o)}e.current_back_off=e.current_back_off||yi,e.current_back_off=e.back_off_function(e.current_back_off),setTimeout(r,e.current_back_off)}function fr(e){return Object.keys(e).sort(Cr.collate).reduce(function(t,n){return t[n]=e[n],t},{})}function lr(e,t,n){var r=n.doc_ids?n.doc_ids.sort(Cr.collate):"",o=n.filter?n.filter.toString():"",i="",a="";return n.filter&&n.query_params&&(i=JSON.stringify(fr(n.query_params))),n.filter&&"_view"===n.filter&&(a=n.view.toString()),Lr.all([e.id(),t.id()]).then(function(e){var t=e[0]+e[1]+o+a+i+r;return new Lr(function(e){ze(t,e)})}).then(function(e){return e=e.replace(/\//g,".").replace(/\+/g,"_"),"_local/"+e})}function dr(e,t,n,r,o){function i(){return k?Lr.resolve():lr(e,t,n).then(function(n){E=n,k=new or(e,t,E,r)})}function a(){if(B=[],0!==w.docs.length){var e=w.docs;return t.bulkDocs({docs:e,new_edits:!1}).then(function(t){if(r.cancelled)throw p(),new Error("cancelled");var n=[],i={};t.forEach(function(e){e.error&&(o.doc_write_failures++,n.push(e),i[e.id]=e)}),N=N.concat(n),o.docs_written+=w.docs.length-n.length;var a=n.filter(function(e){return"unauthorized"!==e.name&&"forbidden"!==e.name});if(e.forEach(function(e){var t=i[e._id];t?r.emit("denied",c(t)):B.push(e)}),a.length>0){var s=new Error("bulkDocs error");throw s.other_errors=n,h("target.bulkDocs failed to write docs",s),new Error("bulkWrite partial failure")}},function(t){throw o.doc_write_failures+=e.length,t})}}function s(){if(w.error)throw new Error("There was a problem getting docs.");o.last_seq=j=w.seq;var e=c(o);return B.length&&(e.docs=B,r.emit("change",e)),x=!0,k.writeCheckpoint(w.seq,P).then(function(){if(x=!1,r.cancelled)throw p(),new Error("cancelled");w=void 0,m()})["catch"](b)}function u(){var e={};return w.changes.forEach(function(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 p(),new Error("cancelled");w.diffs=e})}function f(){return nr(e,t,w.diffs,r).then(function(e){w.error=!e.ok,e.docs.forEach(function(e){delete w.diffs[e._id],o.docs_read++,w.docs.push(e)})})}function l(){if(!r.cancelled&&!w){if(0===S.length)return void d(!0);w=S.shift(),u().then(f).then(a).then(s).then(l)["catch"](function(e){h("batch processing terminated with error",e)})}}function d(e){return 0===q.changes.length?void(0!==S.length||w||((C&&F.live||A)&&(r.state="pending",r.emit("paused")),A&&p())):void((e||A||q.changes.length>=L)&&(S.push(q),q={seq:0,changes:[],docs:[]},"pending"!==r.state&&"stopped"!==r.state||(r.state="active",r.emit("active")),l()))}function h(e,t){T||(t.message||(t.message=e),o.ok=!1,o.status="aborting",o.errors.push(t),N=N.concat(t),S=[],q={seq:0,changes:[],docs:[]},p())}function p(){if(!(T||r.cancelled&&(o.status="cancelled",x))){o.status=o.status||"complete",o.end_time=new Date,o.last_seq=j,T=!0;var i=N.filter(function(e){return"unauthorized"!==e.name&&"forbidden"!==e.name});if(i.length>0){var a=N.pop();N.length>0&&(a.other_errors=N),a.result=o,cr(n,r,a,function(){dr(e,t,n,r)})}else o.errors=N,r.emit("complete",o),r.removeAllListeners()}}function v(e){if(r.cancelled)return p();var t=O(n)(e);t&&(q.seq=e.seq,q.changes.push(e),d(0===S.length&&F.live))}function y(e){if(D=!1,r.cancelled)return p();if(e.results.length>0)F.since=e.last_seq,m(),d(!0);else{var t=function(){C?(F.live=!0,m()):A=!0,d(!0)};w||0!==e.results.length?t():(x=!0,k.writeCheckpoint(e.last_seq,P).then(function(){x=!1,o.last_seq=j=e.last_seq,t()})["catch"](b))}}function _(e){return D=!1,r.cancelled?p():void h("changes rejected",e)}function m(){function t(){i.cancel()}function o(){r.removeListener("cancel",t)}if(!D&&!A&&S.length<I){D=!0,r._changes&&(r.removeListener("cancel",r._abortChanges),r._changes.cancel()),r.once("cancel",t);var i=e.changes(F).on("change",v);i.then(o,o),i.then(y)["catch"](_),n.retry&&(r._changes=i,r._abortChanges=t)}}function g(){i().then(function(){return r.cancelled?void p():k.getCheckpoint().then(function(e){j=e,F={since:j,limit:L,batch_size:L,style:"all_docs",doc_ids:R,return_docs:!0},n.filter&&("string"!=typeof n.filter?F.include_docs=!0:F.filter=n.filter),"heartbeat"in n&&(F.heartbeat=n.heartbeat),"timeout"in n&&(F.timeout=n.timeout),n.query_params&&(F.query_params=n.query_params),n.view&&(F.view=n.view),m()})})["catch"](function(e){h("getCheckpoint rejected with ",e)})}function b(e){throw x=!1,h("writeCheckpoint completed with error",e),e}var w,E,k,S=[],q={seq:0,changes:[],docs:[]},x=!1,A=!1,T=!1,j=0,C=n.continuous||n.live||!1,L=n.batch_size||100,I=n.batches_limit||10,D=!1,R=n.doc_ids,N=[],B=[],P=M();o=o||{ok:!0,start_time:new Date,docs_read:0,docs_written:0,doc_write_failures:0,errors:[]};var F={};return r.ready(e,t),r.cancelled?void p():(r._addedListeners||(r.once("cancel",p),"function"==typeof n.complete&&(r.once("error",n.complete),r.once("complete",function(e){n.complete(null,e)})),r._addedListeners=!0),void("undefined"==typeof n.since?g():i().then(function(){return x=!0,k.writeCheckpoint(n.since,P)}).then(function(){return x=!1,r.cancelled?void p():(j=n.since,void g())})["catch"](b)))}function hr(){xr.EventEmitter.call(this),this.cancelled=!1,this.state="pending";var e=this,t=new Lr(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 pr(e,t){var n=t.PouchConstructor;return"string"==typeof e?new n(e,t):e}function vr(e,t,n,r){if("function"==typeof n&&(r=n,n={}),"undefined"==typeof n&&(n={}),n.doc_ids&&!Array.isArray(n.doc_ids))throw x(Vr,"`doc_ids` filter parameter is not a list.");n.complete=r,n=c(n),n.continuous=n.continuous||n.live,n.retry="retry"in n?n.retry:!1,n.PouchConstructor=n.PouchConstructor||this;var o=new hr(n),i=pr(e,n),a=pr(t,n);return dr(i,a,n,o),o}function yr(e,t,n,r){return"function"==typeof n&&(r=n,n={}),"undefined"==typeof n&&(n={}),n=c(n),n.PouchConstructor=n.PouchConstructor||this,e=pr(e,n),t=pr(t,n),new _r(e,t,n,r)}function _r(e,t,n,r){function o(e){h.emit("change",{direction:"pull",change:e})}function i(e){h.emit("change",{direction:"push",change:e})}function a(e){h.emit("denied",{direction:"push",doc:e})}function s(e){h.emit("denied",{direction:"pull",doc:e})}function u(){h.pushPaused=!0,h.pullPaused&&h.emit("paused")}function c(){h.pullPaused=!0,h.pushPaused&&h.emit("paused")}function f(){h.pushPaused=!1,h.pullPaused&&h.emit("active",{direction:"push"})}function l(){h.pullPaused=!1,h.pushPaused&&h.emit("active",{direction:"pull"})}function d(e){return function(t,n){var r="change"===t&&(n===o||n===i),d="denied"===t&&(n===s||n===a),p="paused"===t&&(n===c||n===u),v="active"===t&&(n===l||n===f);(r||d||p||v)&&(t in y||(y[t]={}),y[t][e]=!0,2===Object.keys(y[t]).length&&h.removeAllListeners(t))}}var h=this;this.canceled=!1;var p=n.push?br.extend({},n,n.push):n,v=n.pull?br.extend({},n,n.pull):n;this.push=vr(e,t,p),this.pull=vr(t,e,v),this.pushPaused=!0,this.pullPaused=!0;
var y={};n.live&&(this.push.on("complete",h.pull.cancel.bind(h.pull)),this.pull.on("complete",h.push.cancel.bind(h.push))),this.on("newListener",function(e){"change"===e?(h.pull.on("change",o),h.push.on("change",i)):"denied"===e?(h.pull.on("denied",s),h.push.on("denied",a)):"active"===e?(h.pull.on("active",l),h.push.on("active",f)):"paused"===e&&(h.pull.on("paused",c),h.push.on("paused",u))}),this.on("removeListener",function(e){"change"===e?(h.pull.removeListener("change",o),h.push.removeListener("change",i)):"denied"===e?(h.pull.removeListener("denied",s),h.push.removeListener("denied",a)):"active"===e?(h.pull.removeListener("active",l),h.push.removeListener("active",f)):"paused"===e&&(h.pull.removeListener("paused",c),h.push.removeListener("paused",u))}),this.pull.on("removeListener",d("pull")),this.push.on("removeListener",d("push"));var _=Lr.all([this.push,this.pull]).then(function(e){var t={push:e[0],pull:e[1]};return h.emit("complete",t),r&&r(null,t),h.removeAllListeners(),t},function(e){if(h.cancel(),r?r(e):h.emit("error",e),h.removeAllListeners(),r)throw e});this.then=function(e,t){return _.then(e,t)},this["catch"]=function(e){return _["catch"](e)}}function mr(e){e.replicate=vr,e.sync=yr}var gr,br=e(10),wr=o(e(5)),Er=o(e(9)),kr=o(e(11)),Sr=e(15),qr=o(e(4)),xr=e(1),Ar=o(e(16)),Tr=o(e(17)),Or=o(e(18)),jr=o(e(7)),Cr=e(13),Lr="function"==typeof Promise?Promise:kr,Ir=Function.prototype.toString,Dr=Ir.call(Object),Rr=wr("pouchdb:api"),Nr=6;if(_())gr=!1;else try{localStorage.setItem("_pouch_check_localstorage",1),gr=!!localStorage.getItem("_pouch_check_localstorage")}catch(Br){gr=!1}Er(b,xr.EventEmitter),b.prototype.addListener=function(e,t,n,r){function o(){function e(){a=!1}if(i._listeners[t]){if(a)return void(a="waiting");a=!0;var s=h(r,["style","include_docs","attachments","conflicts","filter","doc_ids","view","since","query_params","binary"]);n.changes(s).on("change",function(e){e.seq>r.since&&!r.cancelled&&(r.since=e.seq,r.onChange(e))}).on("complete",function(){"waiting"===a&&setTimeout(function(){o()},0),a=!1}).on("error",e)}}if(!this._listeners[t]){var i=this,a=!1;this._listeners[t]=o,this.on(e,o)}},b.prototype.removeListener=function(e,t){t in this._listeners&&xr.EventEmitter.prototype.removeListener.call(this,e,this._listeners[t])},b.prototype.notifyLocalWindows=function(e){_()?chrome.storage.local.set({dbName:e}):m()&&(localStorage[e]="a"===localStorage[e]?"b":"a")},b.prototype.notify=function(e){this.emit(e),this.notifyLocalWindows(e)},Er(q,Error),q.prototype.toString=function(){return JSON.stringify({status:this.status,name:this.name,message:this.message,reason:this.reason})};var Pr=(new q({status:401,error:"unauthorized",reason:"Name or password is incorrect."}),new q({status:400,error:"bad_request",reason:"Missing JSON list of 'docs'"})),Mr=new q({status:404,error:"not_found",reason:"missing"}),Fr=new q({status:409,error:"conflict",reason:"Document update conflict"}),Ur=new q({status:400,error:"bad_request",reason:"_id field must contain a string"}),Hr=new q({status:412,error:"missing_id",reason:"_id is required for puts"}),zr=new q({status:400,error:"bad_request",reason:"Only reserved document ids may start with underscore."}),Kr=new q({status:412,error:"precondition_failed",reason:"Database not open"}),Wr=new q({status:500,error:"unknown_error",reason:"Database encountered an unknown error"}),Jr=new q({status:500,error:"badarg",reason:"Some query argument is invalid"}),Xr=(new q({status:400,error:"invalid_request",reason:"Request was invalid"}),new q({status:400,error:"query_parse_error",reason:"Some query parameter is invalid"})),Gr=new q({status:500,error:"doc_validation",reason:"Bad special document member"}),Vr=new q({status:400,error:"bad_request",reason:"Something wrong with the request"}),Qr=new q({status:400,error:"bad_request",reason:"Document must be a JSON object"}),$r=(new q({status:404,error:"not_found",reason:"Database not found"}),new q({status:500,error:"indexed_db_went_bad",reason:"unknown"})),Yr=new q({status:500,error:"web_sql_went_bad",reason:"unknown"}),Zr=(new q({status:500,error:"levelDB_went_went_bad",reason:"unknown"}),new q({status:403,error:"forbidden",reason:"Forbidden by design doc validate_doc_update function"}),new q({status:400,error:"bad_request",reason:"Invalid rev format"})),eo=(new q({status:412,error:"file_exists",reason:"The database could not be created, the file already exists."}),new q({status:412,error:"missing_stub"})),to=(new q({status:413,error:"invalid_url",reason:"Provided URL is invalid"}),["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"]),no="queryKey",ro=/(?:^|&)([^&=]*)=?([^&]*)/g,oo=/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,io="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");Er(ce,xr.EventEmitter),ce.prototype.cancel=function(){this.isCancelled=!0,this.db.taskqueue.isReady&&this.emit("cancel")},ce.prototype.doChanges=function(e){var t=this,n=e.complete;if(e=c(e),"live"in e&&!("continuous"in e)&&(e.continuous=e.live),e.processChange=fe,"latest"===e.since&&(e.since="now"),e.since||(e.since=0),"now"===e.since)return void this.db.info().then(function(r){return t.isCancelled?void n(null,{status:"cancelled"}):(e.since=r.update_seq,void t.doChanges(e))},n);if(e.continuous&&"now"!==e.since&&this.db.info().then(function(e){t.startSeq=e.update_seq},function(e){if("idbNull"!==e.id)throw e}),e.view&&!e.filter&&(e.filter="_view"),e.filter&&"string"==typeof e.filter&&("_view"===e.filter?e.view=D(e.view):e.filter=D(e.filter),"http"!==this.db.type()&&!e.doc_ids))return this.filterChanges(e);"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 o=t.cancel;t.cancel=qr(function(e){r.cancel(),o.apply(this,e)})}},ce.prototype.filterChanges=function(e){var t=this,n=e.complete;if("_view"===e.filter){if(!e.view||"string"!=typeof e.view){var r=x(Vr,"`view` filter parameter not found or invalid.");return n(r)}var o=I(e.view);this.db.get("_design/"+o[0],function(r,i){if(t.isCancelled)return n(null,{status:"cancelled"});if(r)return n(A(r));var a=i&&i.views&&i.views[o[1]]&&i.views[o[1]].map;return a?(e.filter=se(a),void t.doChanges(e)):n(x(Mr,i.views?"missing json key: "+o[1]:"missing json key: views"))})}else{var i=I(e.filter);if(!i)return t.doChanges(e);this.db.get("_design/"+i[0],function(r,o){if(t.isCancelled)return n(null,{status:"cancelled"});if(r)return n(A(r));var a=o&&o.filters&&o.filters[i[1]];return a?(e.filter=ae(a),void t.doChanges(e)):n(x(Mr,o&&o.filters?"missing json key: "+i[1]:"missing json key: filters"))})}},Er(be,xr.EventEmitter),be.prototype.post=d("post",function(e,t,n){return"function"==typeof t&&(n=t,t={}),"object"!=typeof e||Array.isArray(e)?n(x(Qr)):void this.bulkDocs({docs:[e]},t,he(n))}),be.prototype.put=d("put",qr(function(e){function t(){a||(w("warn","db.put(doc, id, rev) has been deprecated and will be removed in a future release, please use db.put({_id: id, _rev: rev}) instead"),a=!0)}var n,r,o,i,a=!1,s=e.shift(),u="_id"in s;if("object"!=typeof s||Array.isArray(s))return(i=e.pop())(x(Qr));for(;;)if(n=e.shift(),r=typeof n,"string"!==r||u?"string"!==r||!u||"_rev"in s?"object"===r?o=n:"function"===r&&(i=n):(t(),s._rev=n):(t(),s._id=n,u=!0),!e.length)break;return o=o||{},C(s._id),ie(s._id)&&"function"==typeof this._putLocal?s._deleted?this._removeLocal(s,i):this._putLocal(s,i):void this.bulkDocs({docs:[s]},o,he(i))})),be.prototype.putAttachment=d("putAttachment",function(e,t,n,r,o){function i(e){var n="_rev"in e?parseInt(e._rev,10):0;return e._attachments=e._attachments||{},e._attachments[t]={content_type:o,data:r,revpos:++n},a.put(e)}var a=this;return"function"==typeof o&&(o=r,r=n,n=null),"undefined"==typeof o&&(o=r,r=n,n=null),a.get(e).then(function(e){if(e._rev!==n)throw x(Fr);return i(e)},function(t){if(t.reason===Mr.message)return i({_id:e});throw t})}),be.prototype.removeAttachment=d("removeAttachment",function(e,t,n,r){var o=this;o.get(e,function(e,i){return e?void r(e):i._rev!==n?void r(x(Fr)):i._attachments?(delete i._attachments[t],0===Object.keys(i._attachments).length&&delete i._attachments,void o.put(i,r)):r()})}),be.prototype.remove=d("remove",function(e,t,n,r){var o;"string"==typeof t?(o={_id:e,_rev:t},"function"==typeof n&&(r=n,n={})):(o=e,"function"==typeof t?(r=t,n={}):(r=n,n=t)),n=n||{},n.was_delete=!0;var i={_id:o._id,_rev:o._rev||n.rev};return i._deleted=!0,ie(i._id)&&"function"==typeof this._removeLocal?this._removeLocal(o,r):void this.bulkDocs({docs:[i]},n,he(r))}),be.prototype.revsDiff=d("revsDiff",function(e,t,n){function r(e,t){s.has(e)||s.set(e,{missing:[]}),s.get(e).missing.push(t)}function o(t,n){var o=e[t].slice(0);U(n,function(e,n,i,a,s){var u=n+"-"+i,c=o.indexOf(u);-1!==c&&(o.splice(c,1),"available"!==s.status&&r(t,u))}),o.forEach(function(e){r(t,e)})}"function"==typeof t&&(n=t,t={});var i=Object.keys(e);if(!i.length)return n(null,{});var a=0,s=new Sr.Map;i.map(function(t){this._getRevisionTree(t,function(r,u){if(r&&404===r.status&&"missing"===r.message)s.set(t,{missing:e[t]});else{if(r)return n(r);o(t,u)}if(++a===i.length){var c={};return s.forEach(function(e,t){c[t]=e}),n(null,c)}})},this)}),be.prototype.bulkGet=d("bulkGet",function(e,t){y(this,e,t)}),be.prototype.compactDocument=d("compactDocument",function(e,t,n){var r=this;this._getRevisionTree(e,function(o,i){if(o)return n(o);var a=ye(i),s=[],u=[];Object.keys(a).forEach(function(e){a[e]>t&&s.push(e)}),U(i,function(e,t,n,r,o){var i=t+"-"+n;"available"===o.status&&-1!==s.indexOf(i)&&u.push(i)}),r._doCompaction(e,u,n)})}),be.prototype.compact=d("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&&me(n)}),be.prototype._compact=function(e,t){function n(e){a.push(o.compactDocument(e.id,0))}function r(e){var n=e.last_seq;Lr.all(a).then(function(){return N(o,"_local/compaction",function(e){return!e.last_seq||e.last_seq<n?(e.last_seq=n,e):!1})}).then(function(){t(null,{ok:!0})})["catch"](t)}var o=this,i={return_docs:!1,last_seq:e.last_seq||0},a=[];o.changes(i).on("change",n).on("complete",r).on("error",t)},be.prototype.get=d("get",function(e,t,n){function r(){var r=[],a=o.length;return a?void o.forEach(function(o){i.get(e,{rev:o,revs:t.revs,attachments:t.attachments},function(e,t){e?r.push({missing:o}):r.push({ok:t}),a--,a||n(null,r)})}):n(null,r)}if("function"==typeof t&&(n=t,t={}),"string"!=typeof e)return n(x(Ur));if(ie(e)&&"function"==typeof this._getLocal)return this._getLocal(e,n);var o=[],i=this;if(!t.open_revs)return this._get(e,t,function(e,r){if(e)return n(e);var o=r.doc,a=r.metadata,s=r.ctx;if(t.conflicts){var u=K(a);u.length&&(o._conflicts=u)}if(oe(a,o._rev)&&(o._deleted=!0),t.revs||t.revs_info){var c=J(a.rev_tree),f=de(c,function(e){return-1!==e.ids.map(function(e){return e.id}).indexOf(o._rev.split("-")[1])}),l=f.ids.map(function(e){return e.id}).indexOf(o._rev.split("-")[1])+1,d=f.ids.length-l;if(f.ids.splice(l,d),f.ids.reverse(),t.revs&&(o._revisions={start:f.pos+f.ids.length-1,ids:f.ids.map(function(e){return e.id})}),t.revs_info){var h=f.pos+f.ids.length;o._revs_info=f.ids.map(function(e){return h--,{rev:h+"-"+e.id,status:e.opts.status}})}}if(t.attachments&&o._attachments){var p=o._attachments,v=Object.keys(p).length;if(0===v)return n(null,o);Object.keys(p).forEach(function(e){this._getAttachment(o._id,e,p[e],{rev:o._rev,binary:t.binary,ctx:s},function(t,r){var i=o._attachments[e];i.data=r,delete i.stub,delete i.length,--v||n(null,o)})},i)}else{if(o._attachments)for(var y in o._attachments)o._attachments.hasOwnProperty(y)&&(o._attachments[y].stub=!0);n(null,o)}});if("all"===t.open_revs)this._getRevisionTree(e,function(e,t){return e?n(e):(o=z(t).map(function(e){return e.rev}),void r())});else{if(!Array.isArray(t.open_revs))return n(x(Wr,"function_clause"));o=t.open_revs;for(var a=0;a<o.length;a++){var s=o[a];if("string"!=typeof s||!/^\d+-/.test(s))return n(x(Zr))}r()}}),be.prototype.getAttachment=d("getAttachment",function(e,t,n,r){var o=this;n instanceof Function&&(r=n,n={}),this._get(e,n,function(i,a){return i?r(i):a.doc._attachments&&a.doc._attachments[t]?(n.ctx=a.ctx,n.binary=!0,o._getAttachment(e,t,a.doc._attachments[t],n,r),void 0):r(x(Mr))})}),be.prototype.allDocs=d("allDocs",function(e,t){if("function"==typeof e&&(t=e,e={}),e.skip="undefined"!=typeof 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(x(Xr,"Query parameter `"+n+"` is not compatible with multi-get"));if("http"!==this.type())return _e(this,e,t)}return this._allDocs(e,t)}),be.prototype.changes=function(e,t){return"function"==typeof e&&(t=e,e={}),new ce(this,e,t)},be.prototype.close=d("close",function(e){return this._closed=!0,this._close(e)}),be.prototype.info=d("info",function(e){var t=this;this._info(function(n,r){return n?e(n):(r.db_name=r.db_name||t._db_name,r.auto_compaction=!(!t.auto_compaction||"http"===t.type()),r.adapter=t.type(),void e(null,r))})}),be.prototype.id=d("id",function(e){return this._id(e)}),be.prototype.type=function(){return"function"==typeof this._type?this._type():this.adapter},be.prototype.bulkDocs=d("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(x(Pr));for(var r=0;r<e.docs.length;++r)if("object"!=typeof e.docs[r]||Array.isArray(e.docs[r]))return n(x(Qr));var o;return e.docs.forEach(function(e){e._attachments&&Object.keys(e._attachments).forEach(function(e){o=o||ge(e)})}),o?n(x(Vr,o)):("new_edits"in t||("new_edits"in e?t.new_edits=e.new_edits:t.new_edits=!0),t.new_edits||"http"===this.type()||e.docs.sort(ve),pe(e.docs),this._bulkDocs(e,t,function(e,r){return e?n(e):(t.new_edits||(r=r.filter(function(e){return e.error})),void n(null,r))}))}),be.prototype.registerDependentDatabase=d("registerDependentDatabase",function(e,t){function n(t){return t.dependentDbs=t.dependentDbs||{},t.dependentDbs[e]?!1:(t.dependentDbs[e]=!0,t)}var r=new this.constructor(e,this.__opts);N(this,"_local/_pouch_dependentDbs",n).then(function(){t(null,{db:r})})["catch"](t)}),be.prototype.destroy=d("destroy",function(e,t){function n(){r._destroy(e,function(e,n){return e?t(e):(r._destroyed=!0,r.emit("destroyed"),void t(null,n||{ok:!0}))})}"function"==typeof e&&(t=e,e={});var r=this,o="use_prefix"in r?r.use_prefix:!0;return"http"===r.type()?n():void r.get("_local/_pouch_dependentDbs",function(e,i){if(e)return 404!==e.status?t(e):n();var a=i.dependentDbs,s=r.constructor,u=Object.keys(a).map(function(e){var t=o?e.replace(new RegExp("^"+s.prefix),""):e;return new s(t,r.__opts).destroy()});Lr.all(u).then(n,t)})}),we.prototype.execute=function(){var e;if(this.failed)for(;e=this.queue.shift();)e(this.failed);else for(;e=this.queue.shift();)e()},we.prototype.fail=function(e){this.failed=e,this.execute()},we.prototype.ready=function(e){this.isReady=!0,this.db=e,this.execute()},we.prototype.addTask=function(e){this.queue.push(e),this.failed&&this.execute()},Er(Se,be),Se.debug=wr,Se.adapters={},Se.preferredAdapters=[],Se.prefix="_pouch_";var ao=new xr.EventEmitter;qe(Se),Se.parseAdapter=function(e,t){var n,r,o=e.match(/([a-z\-]*):\/\/(.*)/);if(o){if(e=/http(s?)/.test(o[1])?o[1]+"://"+o[2]:o[2],n=o[1],!Se.adapters[n].valid())throw"Invalid adapter";return{name:e,adapter:o[1]}}var i="idb"in Se.adapters&&"websql"in Se.adapters&&m()&&localStorage["_pouch__websqldb_"+Se.prefix+e];if(t.adapter)r=t.adapter;else if("undefined"!=typeof t&&t.db)r="leveldb";else for(var a=0;a<Se.preferredAdapters.length;++a)if(r=Se.preferredAdapters[a],r in Se.adapters){if(i&&"idb"===r){w("log",'PouchDB is downgrading "'+e+'" to WebSQL to avoid data loss, because it was already opened with WebSQL.');continue}break}n=Se.adapters[r];var s=n&&"use_prefix"in n?n.use_prefix:!0;return{name:s?Se.prefix+e:e,adapter:r}},Se.adapter=function(e,t,n){t.valid()&&(Se.adapters[e]=t,n&&Se.preferredAdapters.push(e))},Se.plugin=function(e){return"function"==typeof e?e(Se):Object.keys(e).forEach(function(t){Se.prototype[t]=e[t]}),Se},Se.defaults=function(e){function t(n,r,o){return this instanceof t?("function"!=typeof r&&"undefined"!=typeof r||(o=r,r={}),n&&"object"==typeof n&&(r=n,n=void 0),r=br.extend({},e,r),void Se.call(this,n,r,o)):new t(n,r,o)}return Er(t,Se),t.preferredAdapters=Se.preferredAdapters.slice(),Object.keys(Se).forEach(function(e){e in t||(t[e]=Se[e])}),t};var so="5.4.5";Se.version=so;var uo,co=xe(["_id","_rev","_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"]),fo=xe(["_attachments","_replication_id","_replication_state","_replication_state_time","_replication_state_reason","_replication_stats"]),lo=function(e){return atob(e)},ho=function(e){return btoa(e)},po=r.setImmediate||r.setTimeout,vo=32768,yo=5,_o="document-store",mo="by-sequence",go="attach-store",bo="attach-seq-store",wo="meta-store",Eo="local-store",ko="detect-blob-support",So={running:!1,queue:[]},qo=new Sr.Map,xo=new b,Ao=new Sr.Map;mt.valid=function(){var e="undefined"!=typeof openDatabase&&/(Safari|iPhone|iPad|iPod)/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)&&!/BlackBerry/.test(navigator.platform);return!e&&"undefined"!=typeof indexedDB&&"undefined"!=typeof IDBKeyRange};var To=7,Oo=At("document-store"),jo=At("by-sequence"),Co=At("attach-store"),Lo=At("local-store"),Io=At("metadata-store"),Do=At("attach-seq-store"),Ro=new Sr.Map,No=new b,Bo=1,Po="CREATE INDEX IF NOT EXISTS 'by-seq-deleted-idx' ON "+jo+" (seq, deleted)",Mo="CREATE UNIQUE INDEX IF NOT EXISTS 'by-seq-doc-id-rev' ON "+jo+" (doc_id, rev)",Fo="CREATE INDEX IF NOT EXISTS 'doc-winningseq-idx' ON "+Oo+" (winningseq)",Uo="CREATE INDEX IF NOT EXISTS 'attach-seq-seq-idx' ON "+Do+" (seq)",Ho="CREATE UNIQUE INDEX IF NOT EXISTS 'attach-seq-digest-idx' ON "+Do+" (digest, seq)",zo=jo+".seq = "+Oo+".winningseq",Ko=jo+".seq AS seq, "+jo+".deleted AS deleted, "+jo+".json AS data, "+jo+".rev AS rev, "+Oo+".json AS metadata";Gt.valid=Jt,Gt.use_prefix=!0;var Wo=Zt(),Jo=function(){},Xo=25,Go=50,Vo={},Qo=1800,$o=wr("pouchdb:http");dn.valid=function(){return!0},pn.prototype.add=function(e){return this.promise=this.promise["catch"](function(){}).then(function(){return e()}),this.promise},pn.prototype.finish=function(){return this.promise};var Yo=function(e,t){return t&&e.then(function(e){n.nextTick(function(){t(null,e)})},function(e){n.nextTick(function(){t(e)})}),e},Zo=function(e){return qr(function(t){var n=t.pop(),r=e.apply(this,t);return"function"==typeof n&&Yo(r,n),r})},ei=function(e,t){return e.then(function(e){return t().then(function(){return e})},function(e){return t().then(function(){throw e})})},ti=function(e,t){return function(){var n=arguments,r=this;return e.add(function(){return t.apply(r,n)})}},ni=function(e){for(var t={},n=0,r=e.length;r>n;n++)t["$"+e[n]]=!0;var o=Object.keys(t),i=new Array(o.length);for(n=0,r=o.length;r>n;n++)i[n]=o[n].substring(1);return i},ri={},oi=new pn,ii=50,ai=w.bind(null,"log"),si={_sum:function(e,t){return An(t)},_count:function(e,t){return t.length},_stats:function(e,t){function n(e){for(var t=0,n=0,r=e.length;r>n;n++){var o=e[n];t+=o*o}return t}return{sum:An(t),min:Math.min.apply(null,t),max:Math.max.apply(null,t),count:t.length,sumsqr:n(t)}}},ui=Zo(function(){var e=this;return"http"===e.type()?Wn(e):"function"==typeof e._viewCleanup?Rn(e):Jn(e)}),ci=function(e,t,n){"function"==typeof t&&(n=t,t={}),t=t?jn(t):{},"function"==typeof e&&(e={map:e});var r=this,o=Lr.resolve().then(function(){return Xn(r,e,t)});return Yo(o,n),o};Er(Gn,Error),Er(Vn,Error),Er(Qn,Error);var fi={query:ci,viewCleanup:ui},li=1,di="pouchdb",hi=5,pi=0;or.prototype.writeCheckpoint=function(e,t){var n=this;return this.updateTarget(e,t).then(function(){return n.updateSource(e,t)})},or.prototype.updateTarget=function(e,t){return rr(this.target,this.id,e,t,this.returnValue)},or.prototype.updateSource=function(e,t){var n=this;return this.readOnlySource?Lr.resolve(!0):rr(this.src,this.id,e,t,this.returnValue)["catch"](function(e){if(ur(e))return n.readOnlySource=!0,!0;throw e})};var vi={undefined:function(e,t){return 0===Cr.collate(e.last_seq,t.last_seq)?t.last_seq:0},1:function(e,t){return ir(t,e).last_seq}};or.prototype.getCheckpoint=function(){var e=this;return e.target.get(e.id).then(function(t){return e.readOnlySource?Lr.resolve(t.last_seq):e.src.get(e.id).then(function(e){if(t.version!==e.version)return pi;var n;return n=t.version?t.version.toString():"undefined",n in vi?vi[n](t,e):pi},function(n){if(404===n.status&&t.last_seq)return e.src.put({_id:e.id,last_seq:pi}).then(function(){return pi},function(n){return ur(n)?(e.readOnlySource=!0,t.last_seq):pi});throw n})})["catch"](function(e){if(404!==e.status)throw e;return pi})};var yi=0;Er(hr,xr.EventEmitter),hr.prototype.cancel=function(){this.cancelled=!0,this.state="cancelled",this.emit("cancel")},hr.prototype.ready=function(e,t){function n(){o.cancel()}function r(){e.removeListener("destroyed",n),t.removeListener("destroyed",n)}var o=this;o._readyCalled||(o._readyCalled=!0,e.once("destroyed",n),t.once("destroyed",n),o.once("complete",r))},Er(_r,xr.EventEmitter),_r.prototype.cancel=function(){this.canceled||(this.canceled=!0,this.push.cancel(),this.pull.cancel())},Se.plugin(wt).plugin(Vt).plugin(hn).plugin(fi).plugin(mr),t.exports=Se}).call(this,e(2),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{1:1,10:10,11:11,13:13,15:15,16:16,17:17,18:18,2:2,4:4,5:5,7:7,9:9}],4:[function(e,t,n){"use strict";function r(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,[])}}t.exports=r},{}],5:[function(e,t,n){function r(){return"WebkitAppearance"in document.documentElement.style||window.console&&(console.firebug||console.exception&&console.table)||navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31}function o(){var e=arguments,t=this.useColors;if(e[0]=(t?"%c":"")+this.namespace+(t?" %c":" ")+e[0]+(t?"%c ":" ")+"+"+n.humanize(this.diff),!t)return e;var r="color: "+this.color;e=[e[0],r,"color: inherit"].concat(Array.prototype.slice.call(e,1));var o=0,i=0;return e[0].replace(/%[a-z%]/g,function(e){"%%"!==e&&(o++,"%c"===e&&(i=o))}),e.splice(i,0,r),e}function i(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function a(e){try{null==e?n.storage.removeItem("debug"):n.storage.debug=e}catch(t){}}function s(){var e;try{e=n.storage.debug}catch(t){}return e}function u(){try{return window.localStorage}catch(e){}}n=t.exports=e(6),n.log=i,n.formatArgs=o,n.save=a,n.load=s,n.useColors=r,n.storage="undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage?chrome.storage.local:u(),n.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],n.formatters.j=function(e){return JSON.stringify(e)},n.enable(s())},{6:6}],6:[function(e,t,n){function r(){return n.colors[f++%n.colors.length]}function o(e){function t(){}function o(){var e=o,t=+new Date,i=t-(c||t);e.diff=i,e.prev=c,e.curr=t,c=t,null==e.useColors&&(e.useColors=n.useColors()),null==e.color&&e.useColors&&(e.color=r());var a=Array.prototype.slice.call(arguments);a[0]=n.coerce(a[0]),"string"!=typeof a[0]&&(a=["%o"].concat(a));var s=0;a[0]=a[0].replace(/%([a-z%])/g,function(t,r){if("%%"===t)return t;s++;var o=n.formatters[r];if("function"==typeof o){var i=a[s];t=o.call(e,i),a.splice(s,1),s--}return t}),"function"==typeof n.formatArgs&&(a=n.formatArgs.apply(e,a));var u=o.log||n.log||console.log.bind(console);u.apply(e,a)}t.enabled=!1,o.enabled=!0;var i=n.enabled(e)?o:t;return i.namespace=e,i}function i(e){n.save(e);for(var t=(e||"").split(/[\s,]+/),r=t.length,o=0;r>o;o++)t[o]&&(e=t[o].replace(/\*/g,".*?"),"-"===e[0]?n.skips.push(new RegExp("^"+e.substr(1)+"$")):n.names.push(new RegExp("^"+e+"$")))}function a(){n.enable("")}function s(e){var t,r;for(t=0,r=n.skips.length;r>t;t++)if(n.skips[t].test(e))return!1;for(t=0,r=n.names.length;r>t;t++)if(n.names[t].test(e))return!0;return!1}function u(e){return e instanceof Error?e.stack||e.message:e}n=t.exports=o,n.coerce=u,n.disable=a,n.enable=i,n.enabled=s,n.humanize=e(12),n.names=[],n.skips=[],n.formatters={};var c,f=0},{12:12}],7:[function(t,n,r){!function(t,o){"function"==typeof e&&e.amd?e([],o):"object"==typeof r?n.exports=o():(t.PromisePool=o(),t.promisePool=t.PromisePool)}(this,function(){"use strict";var e=function(){this._listeners={}};e.prototype.addEventListener=function(e,t){this._listeners[e]=this._listeners[e]||[],this._listeners[e].indexOf(t)<0&&this._listeners[e].push(t)},e.prototype.removeEventListener=function(e,t){if(this._listeners[e]){var n=this._listeners[e].indexOf(t);n>=0&&this._listeners[e].splice(n,1)}},e.prototype.dispatchEvent=function(e){if(this._listeners[e.type]&&this._listeners[e.type].length)for(var t=this._listeners[e.type].slice(),n=0,r=t.length;r>n;++n)t[n].call(this,e)};var t=function(e){return"function"==typeof e.constructor&&"GeneratorFunction"===e.constructor.name},n=function(e){return{next:function(){var t=e();return t?{value:t}:{done:!0}}}},r=function(e){var t=!1;return{next:function(){return t?{done:!0}:(t=!0,{value:e})}}},o=function(e,o){var i=typeof e;if("object"===i){if("function"==typeof e.next)return e;if("function"==typeof e.then)return r(e)}return"function"===i?t(e)?e():n(e):r(o.resolve(e))},i=function(e,t,n){this.target=e,this.type=t,this.data=n},a=function(t,n,r){if(e.call(this),"number"!=typeof n||Math.floor(n)!==n||1>n)throw new Error("Invalid concurrency");this._concurrency=n,this._options=r||{},this._options.promise=this._options.promise||Promise,this._iterator=o(t,this._options.promise),this._done=!1,this._size=0,this._promise=null,this._callbacks=null};return a.prototype=new e,a.prototype.constructor=a,a.prototype.concurrency=function(e){return"undefined"!=typeof e&&(this._concurrency=e,this.active()&&this._proceed()),this._concurrency},a.prototype.size=function(){return this._size},a.prototype.active=function(){return!!this._promise},a.prototype.promise=function(){return this._promise},a.prototype.start=function(){var e=this,t=this._options.promise;return this._promise=new t(function(t,n){e._callbacks={reject:n,resolve:t},e._proceed()}),this._promise},a.prototype._fireEvent=function(e,t){this.dispatchEvent(new i(this,e,t))},a.prototype._settle=function(e){e?this._callbacks.reject(e):this._callbacks.resolve(),this._promise=null,this._callbacks=null},a.prototype._onPooledPromiseFulfilled=function(e,t){this._size--,this.active()&&(this._fireEvent("fulfilled",{promise:e,result:t}),this._proceed())},a.prototype._onPooledPromiseRejected=function(e,t){this._size--,this.active()&&(this._fireEvent("rejected",{promise:e,error:t}),this._settle(t||new Error("Unknown error")))},a.prototype._trackPromise=function(e){var t=this;e.then(function(n){t._onPooledPromiseFulfilled(e,n)},function(n){t._onPooledPromiseRejected(e,n)})["catch"](function(e){t._settle(new Error("Promise processing failed: "+e))})},a.prototype._proceed=function(){if(!this._done){for(var e=null;this._size<this._concurrency&&!(e=this._iterator.next()).done;)this._size++,this._trackPromise(e.value);this._done=null===e||!!e.done}this._done&&0===this._size&&this._settle()},a.PromisePoolEvent=i,a.PromisePool=a,a})},{}],8:[function(e,t,n){(function(e){"use strict";function n(){f=!0;for(var e,t,n=l.length;n;){for(t=l,l=[],e=-1;++e<n;)t[e]();n=l.length}f=!1}function r(e){1!==l.push(e)||f||o()}var o,i=e.MutationObserver||e.WebKitMutationObserver;if(i){var a=0,s=new i(n),u=e.document.createTextNode("");s.observe(u,{characterData:!0}),o=function(){u.data=a=++a%2}}else if(e.setImmediate||"undefined"==typeof e.MessageChannel)o="document"in e&&"onreadystatechange"in e.document.createElement("script")?function(){var t=e.document.createElement("script");t.onreadystatechange=function(){n(),t.onreadystatechange=null,t.parentNode.removeChild(t),t=null},e.document.documentElement.appendChild(t)}:function(){setTimeout(n,0)};else{var c=new e.MessageChannel;c.port1.onmessage=n,o=function(){c.port2.postMessage(0)}}var f,l=[];t.exports=r}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],9:[function(e,t,n){"function"==typeof Object.create?t.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:t.exports=function(e,t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}},{}],10:[function(e,t,n){(function(){var e=Array.prototype.slice,t=Array.prototype.forEach,n=function(r){if("object"!=typeof r)throw r+" is not an object";var o=e.call(arguments,1);return t.call(o,function(e){if(e)for(var t in e)"object"==typeof e[t]&&r[t]?n.call(r,r[t],e[t]):r[t]=e[t]}),r};this.extend=n}).call(this)},{}],11:[function(e,t,n){"use strict";function r(){}function o(e){if("function"!=typeof e)throw new TypeError("resolver must be a function");this.state=m,this.queue=[],this.outcome=void 0,e!==r&&u(this,e)}function i(e,t,n){this.promise=e,"function"==typeof t&&(this.onFulfilled=t,this.callFulfilled=this.otherCallFulfilled),"function"==typeof n&&(this.onRejected=n,this.callRejected=this.otherCallRejected)}function a(e,t,n){p(function(){var r;try{r=t(n)}catch(o){return v.reject(e,o)}r===e?v.reject(e,new TypeError("Cannot resolve promise with itself")):v.resolve(e,r)})}function s(e){var t=e&&e.then;return e&&"object"==typeof e&&"function"==typeof t?function(){t.apply(e,arguments)}:void 0}function u(e,t){function n(t){i||(i=!0,v.reject(e,t))}function r(t){i||(i=!0,v.resolve(e,t))}function o(){t(r,n)}var i=!1,a=c(o);"error"===a.status&&n(a.value)}function c(e,t){var n={};try{n.value=e(t),n.status="success"}catch(r){n.status="error",n.value=r}return n}function f(e){return e instanceof this?e:v.resolve(new this(r),e)}function l(e){var t=new this(r);return v.reject(t,e)}function d(e){function t(e,t){function r(e){a[t]=e,++s!==o||i||(i=!0,v.resolve(c,a))}n.resolve(e).then(r,function(e){i||(i=!0,v.reject(c,e))})}var n=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var o=e.length,i=!1;if(!o)return this.resolve([]);for(var a=new Array(o),s=0,u=-1,c=new this(r);++u<o;)t(e[u],u);return c}function h(e){function t(e){n.resolve(e).then(function(e){i||(i=!0,v.resolve(s,e))},function(e){i||(i=!0,v.reject(s,e))})}var n=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var o=e.length,i=!1;if(!o)return this.resolve([]);for(var a=-1,s=new this(r);++a<o;)t(e[a]);return s}var p=e(8),v={},y=["REJECTED"],_=["FULFILLED"],m=["PENDING"];t.exports=o,o.prototype["catch"]=function(e){return this.then(null,e)},o.prototype.then=function(e,t){if("function"!=typeof e&&this.state===_||"function"!=typeof t&&this.state===y)return this;var n=new this.constructor(r);if(this.state!==m){var o=this.state===_?e:t;a(n,o,this.outcome)}else this.queue.push(new i(n,e,t));return n},i.prototype.callFulfilled=function(e){v.resolve(this.promise,e)},i.prototype.otherCallFulfilled=function(e){a(this.promise,this.onFulfilled,e)},i.prototype.callRejected=function(e){v.reject(this.promise,e)},i.prototype.otherCallRejected=function(e){a(this.promise,this.onRejected,e)},v.resolve=function(e,t){
var n=c(s,t);if("error"===n.status)return v.reject(e,n.value);var r=n.value;if(r)u(e,r);else{e.state=_,e.outcome=t;for(var o=-1,i=e.queue.length;++o<i;)e.queue[o].callFulfilled(t)}return e},v.reject=function(e,t){e.state=y,e.outcome=t;for(var n=-1,r=e.queue.length;++n<r;)e.queue[n].callRejected(t);return e},o.resolve=f,o.reject=l,o.all=d,o.race=h},{8:8}],12:[function(e,t,n){function r(e){if(e=""+e,!(e.length>1e4)){var t=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(t){var n=parseFloat(t[1]),r=(t[2]||"ms").toLowerCase();switch(r){case"years":case"year":case"yrs":case"yr":case"y":return n*l;case"days":case"day":case"d":return n*f;case"hours":case"hour":case"hrs":case"hr":case"h":return n*c;case"minutes":case"minute":case"mins":case"min":case"m":return n*u;case"seconds":case"second":case"secs":case"sec":case"s":return n*s;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n}}}}function o(e){return e>=f?Math.round(e/f)+"d":e>=c?Math.round(e/c)+"h":e>=u?Math.round(e/u)+"m":e>=s?Math.round(e/s)+"s":e+"ms"}function i(e){return a(e,f,"day")||a(e,c,"hour")||a(e,u,"minute")||a(e,s,"second")||e+" ms"}function a(e,t,n){return t>e?void 0:1.5*t>e?Math.floor(e/t)+" "+n:Math.ceil(e/t)+" "+n+"s"}var s=1e3,u=60*s,c=60*u,f=24*c,l=365.25*f;t.exports=function(e,t){return t=t||{},"string"==typeof e?r(e):t["long"]?i(e):o(e)}},{}],13:[function(e,t,n){"use strict";function r(e){if(null!==e)switch(typeof e){case"boolean":return e?1:0;case"number":return f(e);case"string":return e.replace(/\u0002/g,"").replace(/\u0001/g,"").replace(/\u0000/g,"");case"object":var t=Array.isArray(e),r=t?e:Object.keys(e),o=-1,i=r.length,a="";if(t)for(;++o<i;)a+=n.toIndexableString(r[o]);else for(;++o<i;){var s=r[o];a+=n.toIndexableString(s)+n.toIndexableString(e[s])}return a}return""}function o(e,t){var n,r=t,o="1"===e[t];if(o)n=0,t++;else{var i="0"===e[t];t++;var a="",s=e.substring(t,t+d),u=parseInt(s,10)+l;for(i&&(u=-u),t+=d;;){var c=e[t];if("\x00"===c)break;a+=c,t++}a=a.split("."),n=1===a.length?parseInt(a,10):parseFloat(a[0]+"."+a[1]),i&&(n-=10),0!==u&&(n=parseFloat(n+"e"+u))}return{num:n,length:t-r}}function i(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 o=r.element,i=r.index;if(Array.isArray(o))o.push(n);else if(i===e.length-2){var a=e.pop();o[a]=n}else e.push(n)}}function a(e,t){for(var r=Math.min(e.length,t.length),o=0;r>o;o++){var i=n.collate(e[o],t[o]);if(0!==i)return i}return e.length===t.length?0:e.length>t.length?1:-1}function s(e,t){return e===t?0:e>t?1:-1}function u(e,t){for(var r=Object.keys(e),o=Object.keys(t),i=Math.min(r.length,o.length),a=0;i>a;a++){var s=n.collate(r[a],o[a]);if(0!==s)return s;if(s=n.collate(e[r[a]],t[o[a]]),0!==s)return s}return r.length===o.length?0:r.length>o.length?1:-1}function c(e){var t=["boolean","number","string","object"],n=t.indexOf(typeof e);return~n?null===e?1:Array.isArray(e)?5:3>n?n+2:n+3:Array.isArray(e)?5:void 0}function f(e){if(0===e)return"1";var t=e.toExponential().split(/e\+?/),n=parseInt(t[1],10),r=0>e,o=r?"0":"2",i=(r?-n:n)-l,a=p.padLeft(i.toString(),"0",d);o+=h+a;var s=Math.abs(parseFloat(t[0]));r&&(s=10-s);var u=s.toFixed(20);return u=u.replace(/\.?0+$/,""),o+=h+u}var l=-324,d=3,h="",p=e(14);n.collate=function(e,t){if(e===t)return 0;e=n.normalizeKey(e),t=n.normalizeKey(t);var r=c(e),o=c(t);if(r-o!==0)return r-o;if(null===e)return 0;switch(typeof e){case"number":return e-t;case"boolean":return e===t?0:t>e?-1:1;case"string":return s(e,t)}return Array.isArray(e)?a(e,t):u(e,t)},n.normalizeKey=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 r=e.length;e=new Array(r);for(var o=0;r>o;o++)e[o]=n.normalizeKey(t[o])}else{if(e instanceof Date)return e.toJSON();if(null!==e){e={};for(var i in t)if(t.hasOwnProperty(i)){var a=t[i];"undefined"!=typeof a&&(e[i]=n.normalizeKey(a))}}}}return e},n.toIndexableString=function(e){var t="\x00";return e=n.normalizeKey(e),c(e)+h+r(e)+t},n.parseIndexableString=function(e){for(var t=[],n=[],r=0;;){var a=e[r++];if("\x00"!==a)switch(a){case"1":t.push(null);break;case"2":t.push("1"===e[r]),r++;break;case"3":var s=o(e,r);t.push(s.num),r+=s.length;break;case"4":for(var u="";;){var c=e[r];if("\x00"===c)break;u+=c,r++}u=u.replace(/\u0001\u0001/g,"\x00").replace(/\u0001\u0002/g,"").replace(/\u0002\u0002/g,""),t.push(u);break;case"5":var f={element:[],index:t.length};t.push(f.element),n.push(f);break;case"6":var l={element:{},index:t.length};t.push(l.element),n.push(l);break;default:throw new Error("bad collationIndex or unexpectedly reached end of input: "+a)}else{if(1===t.length)return t.pop();i(t,n)}}}},{14:14}],14:[function(e,t,n){"use strict";function r(e,t,n){for(var r="",o=n-e.length;r.length<o;)r+=t;return r}n.padLeft=function(e,t,n){var o=r(e,t,n);return o+e},n.padRight=function(e,t,n){var o=r(e,t,n);return e+o},n.stringLexCompare=function(e,t){var n,r=e.length,o=t.length;for(n=0;r>n;n++){if(n===o)return 1;var i=e.charAt(n),a=t.charAt(n);if(i!==a)return a>i?-1:1}return o>r?-1:0},n.intToDecimalForm=function(e){var t=0>e,n="";do{var r=t?-Math.ceil(e%10):Math.floor(e%10);n=r+n,e=t?Math.ceil(e/10):Math.floor(e/10)}while(e);return t&&"0"!==n&&(n="-"+n),n}},{}],15:[function(e,t,n){"use strict";function r(){this.store={}}function o(e){if(this.store=new r,e&&Array.isArray(e))for(var t=0,n=e.length;n>t;t++)this.add(e[t])}n.Map=r,n.Set=o,r.prototype.mangle=function(e){if("string"!=typeof e)throw new TypeError("key must be a string but Got "+e);return"$"+e},r.prototype.unmangle=function(e){return e.substring(1)},r.prototype.get=function(e){var t=this.mangle(e);return t in this.store?this.store[t]:void 0},r.prototype.set=function(e,t){var n=this.mangle(e);return this.store[n]=t,!0},r.prototype.has=function(e){var t=this.mangle(e);return t in this.store},r.prototype["delete"]=function(e){var t=this.mangle(e);return t in this.store?(delete this.store[t],!0):!1},r.prototype.forEach=function(e){for(var t=Object.keys(this.store),n=0,r=t.length;r>n;n++){var o=t[n],i=this.store[o];o=this.unmangle(o),e(i,o)}},o.prototype.add=function(e){return this.store.set(e,!0)},o.prototype.has=function(e){return this.store.has(e)},o.prototype["delete"]=function(e){return this.store["delete"](e)}},{}],16:[function(e,t,n){(function(){var e={}.hasOwnProperty,n=[].slice;t.exports=function(t,r){var o,i,a,s;i=[],s=[];for(o in r)e.call(r,o)&&(a=r[o],"this"!==o&&(i.push(o),s.push(a)));return Function.apply(null,n.call(i).concat([t])).apply(r["this"],s)}}).call(this)},{}],17:[function(t,n,r){!function(t){if("object"==typeof r)n.exports=t();else if("function"==typeof e&&e.amd)e(t);else{var o;try{o=window}catch(i){o=self}o.SparkMD5=t()}}(function(e){"use strict";function t(e,t,n,r,o,i){return t=g(g(t,e),g(r,i)),g(t<<o|t>>>32-o,n)}function n(e,n,r,o,i,a,s){return t(n&r|~n&o,e,n,i,a,s)}function r(e,n,r,o,i,a,s){return t(n&o|r&~o,e,n,i,a,s)}function o(e,n,r,o,i,a,s){return t(n^r^o,e,n,i,a,s)}function i(e,n,r,o,i,a,s){return t(r^(n|~o),e,n,i,a,s)}function a(e,t){var a=e[0],s=e[1],u=e[2],c=e[3];a=n(a,s,u,c,t[0],7,-680876936),c=n(c,a,s,u,t[1],12,-389564586),u=n(u,c,a,s,t[2],17,606105819),s=n(s,u,c,a,t[3],22,-1044525330),a=n(a,s,u,c,t[4],7,-176418897),c=n(c,a,s,u,t[5],12,1200080426),u=n(u,c,a,s,t[6],17,-1473231341),s=n(s,u,c,a,t[7],22,-45705983),a=n(a,s,u,c,t[8],7,1770035416),c=n(c,a,s,u,t[9],12,-1958414417),u=n(u,c,a,s,t[10],17,-42063),s=n(s,u,c,a,t[11],22,-1990404162),a=n(a,s,u,c,t[12],7,1804603682),c=n(c,a,s,u,t[13],12,-40341101),u=n(u,c,a,s,t[14],17,-1502002290),s=n(s,u,c,a,t[15],22,1236535329),a=r(a,s,u,c,t[1],5,-165796510),c=r(c,a,s,u,t[6],9,-1069501632),u=r(u,c,a,s,t[11],14,643717713),s=r(s,u,c,a,t[0],20,-373897302),a=r(a,s,u,c,t[5],5,-701558691),c=r(c,a,s,u,t[10],9,38016083),u=r(u,c,a,s,t[15],14,-660478335),s=r(s,u,c,a,t[4],20,-405537848),a=r(a,s,u,c,t[9],5,568446438),c=r(c,a,s,u,t[14],9,-1019803690),u=r(u,c,a,s,t[3],14,-187363961),s=r(s,u,c,a,t[8],20,1163531501),a=r(a,s,u,c,t[13],5,-1444681467),c=r(c,a,s,u,t[2],9,-51403784),u=r(u,c,a,s,t[7],14,1735328473),s=r(s,u,c,a,t[12],20,-1926607734),a=o(a,s,u,c,t[5],4,-378558),c=o(c,a,s,u,t[8],11,-2022574463),u=o(u,c,a,s,t[11],16,1839030562),s=o(s,u,c,a,t[14],23,-35309556),a=o(a,s,u,c,t[1],4,-1530992060),c=o(c,a,s,u,t[4],11,1272893353),u=o(u,c,a,s,t[7],16,-155497632),s=o(s,u,c,a,t[10],23,-1094730640),a=o(a,s,u,c,t[13],4,681279174),c=o(c,a,s,u,t[0],11,-358537222),u=o(u,c,a,s,t[3],16,-722521979),s=o(s,u,c,a,t[6],23,76029189),a=o(a,s,u,c,t[9],4,-640364487),c=o(c,a,s,u,t[12],11,-421815835),u=o(u,c,a,s,t[15],16,530742520),s=o(s,u,c,a,t[2],23,-995338651),a=i(a,s,u,c,t[0],6,-198630844),c=i(c,a,s,u,t[7],10,1126891415),u=i(u,c,a,s,t[14],15,-1416354905),s=i(s,u,c,a,t[5],21,-57434055),a=i(a,s,u,c,t[12],6,1700485571),c=i(c,a,s,u,t[3],10,-1894986606),u=i(u,c,a,s,t[10],15,-1051523),s=i(s,u,c,a,t[1],21,-2054922799),a=i(a,s,u,c,t[8],6,1873313359),c=i(c,a,s,u,t[15],10,-30611744),u=i(u,c,a,s,t[6],15,-1560198380),s=i(s,u,c,a,t[13],21,1309151649),a=i(a,s,u,c,t[4],6,-145523070),c=i(c,a,s,u,t[11],10,-1120210379),u=i(u,c,a,s,t[2],15,718787259),s=i(s,u,c,a,t[9],21,-343485551),e[0]=g(a,e[0]),e[1]=g(s,e[1]),e[2]=g(u,e[2]),e[3]=g(c,e[3])}function s(e){var t,n=[];for(t=0;64>t;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 u(e){var t,n=[];for(t=0;64>t;t+=4)n[t>>2]=e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24);return n}function c(e){var t,n,r,o,i,u,c=e.length,f=[1732584193,-271733879,-1732584194,271733878];for(t=64;c>=t;t+=64)a(f,s(e.substring(t-64,t)));for(e=e.substring(t-64),n=e.length,r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;n>t;t+=1)r[t>>2]|=e.charCodeAt(t)<<(t%4<<3);if(r[t>>2]|=128<<(t%4<<3),t>55)for(a(f,r),t=0;16>t;t+=1)r[t]=0;return o=8*c,o=o.toString(16).match(/(.*?)(.{0,8})$/),i=parseInt(o[2],16),u=parseInt(o[1],16)||0,r[14]=i,r[15]=u,a(f,r),f}function f(e){var t,n,r,o,i,s,c=e.length,f=[1732584193,-271733879,-1732584194,271733878];for(t=64;c>=t;t+=64)a(f,u(e.subarray(t-64,t)));for(e=c>t-64?e.subarray(t-64):new Uint8Array(0),n=e.length,r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;n>t;t+=1)r[t>>2]|=e[t]<<(t%4<<3);if(r[t>>2]|=128<<(t%4<<3),t>55)for(a(f,r),t=0;16>t;t+=1)r[t]=0;return o=8*c,o=o.toString(16).match(/(.*?)(.{0,8})$/),i=parseInt(o[2],16),s=parseInt(o[1],16)||0,r[14]=i,r[15]=s,a(f,r),f}function l(e){var t,n="";for(t=0;4>t;t+=1)n+=b[e>>8*t+4&15]+b[e>>8*t&15];return n}function d(e){var t;for(t=0;t<e.length;t+=1)e[t]=l(e[t]);return e.join("")}function h(e){return/[\u0080-\uFFFF]/.test(e)&&(e=unescape(encodeURIComponent(e))),e}function p(e,t){var n,r=e.length,o=new ArrayBuffer(r),i=new Uint8Array(o);for(n=0;r>n;n+=1)i[n]=e.charCodeAt(n);return t?i:o}function v(e){return String.fromCharCode.apply(null,new Uint8Array(e))}function y(e,t,n){var r=new Uint8Array(e.byteLength+t.byteLength);return r.set(new Uint8Array(e)),r.set(new Uint8Array(t),e.byteLength),n?r:r.buffer}function _(e){var t,n=[],r=e.length;for(t=0;r-1>t;t+=2)n.push(parseInt(e.substr(t,2),16));return String.fromCharCode.apply(String,n)}function m(){this.reset()}var g=function(e,t){return e+t&4294967295},b=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];return"5d41402abc4b2a76b9719d911017c592"!==d(c("hello"))&&(g=function(e,t){var n=(65535&e)+(65535&t),r=(e>>16)+(t>>16)+(n>>16);return r<<16|65535&n}),"undefined"==typeof ArrayBuffer||ArrayBuffer.prototype.slice||!function(){function t(e,t){return e=0|e||0,0>e?Math.max(e+t,0):Math.min(e,t)}ArrayBuffer.prototype.slice=function(n,r){var o,i,a,s,u=this.byteLength,c=t(n,u),f=u;return r!==e&&(f=t(r,u)),c>f?new ArrayBuffer(0):(o=f-c,i=new ArrayBuffer(o),a=new Uint8Array(i),s=new Uint8Array(this,c,o),a.set(s),i)}}(),m.prototype.append=function(e){return this.appendBinary(h(e)),this},m.prototype.appendBinary=function(e){this._buff+=e,this._length+=e.length;var t,n=this._buff.length;for(t=64;n>=t;t+=64)a(this._hash,s(this._buff.substring(t-64,t)));return this._buff=this._buff.substring(t-64),this},m.prototype.end=function(e){var t,n,r=this._buff,o=r.length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;o>t;t+=1)i[t>>2]|=r.charCodeAt(t)<<(t%4<<3);return this._finish(i,o),n=d(this._hash),e&&(n=_(n)),this.reset(),n},m.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},m.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash}},m.prototype.setState=function(e){return this._buff=e.buff,this._length=e.length,this._hash=e.hash,this},m.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},m.prototype._finish=function(e,t){var n,r,o,i=t;if(e[i>>2]|=128<<(i%4<<3),i>55)for(a(this._hash,e),i=0;16>i;i+=1)e[i]=0;n=8*this._length,n=n.toString(16).match(/(.*?)(.{0,8})$/),r=parseInt(n[2],16),o=parseInt(n[1],16)||0,e[14]=r,e[15]=o,a(this._hash,e)},m.hash=function(e,t){return m.hashBinary(h(e),t)},m.hashBinary=function(e,t){var n=c(e),r=d(n);return t?_(r):r},m.ArrayBuffer=function(){this.reset()},m.ArrayBuffer.prototype.append=function(e){var t,n=y(this._buff.buffer,e,!0),r=n.length;for(this._length+=e.byteLength,t=64;r>=t;t+=64)a(this._hash,u(n.subarray(t-64,t)));return this._buff=r>t-64?new Uint8Array(n.buffer.slice(t-64)):new Uint8Array(0),this},m.ArrayBuffer.prototype.end=function(e){var t,n,r=this._buff,o=r.length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;o>t;t+=1)i[t>>2]|=r[t]<<(t%4<<3);return this._finish(i,o),n=d(this._hash),e&&(n=_(n)),this.reset(),n},m.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},m.ArrayBuffer.prototype.getState=function(){var e=m.prototype.getState.call(this);return e.buff=v(e.buff),e},m.ArrayBuffer.prototype.setState=function(e){return e.buff=p(e.buff,!0),m.prototype.setState.call(this,e)},m.ArrayBuffer.prototype.destroy=m.prototype.destroy,m.ArrayBuffer.prototype._finish=m.prototype._finish,m.ArrayBuffer.hash=function(e,t){var n=f(new Uint8Array(e)),r=d(n);return t?_(r):r},m})},{}],18:[function(e,t,n){"use strict";function r(e,t,n){var r=n[n.length-1];e===r.element&&(n.pop(),r=n[n.length-1]);var o=r.element,i=r.index;if(Array.isArray(o))o.push(e);else if(i===t.length-2){var a=t.pop();o[a]=e}else t.push(e)}n.stringify=function(e){var t=[];t.push({obj:e});for(var n,r,o,i,a,s,u,c,f,l,d,h="";n=t.pop();)if(r=n.obj,o=n.prefix||"",i=n.val||"",h+=o,i)h+=i;else if("object"!=typeof r)h+="undefined"==typeof r?null:JSON.stringify(r);else if(null===r)h+="null";else if(Array.isArray(r)){for(t.push({val:"]"}),a=r.length-1;a>=0;a--)s=0===a?"":",",t.push({obj:r[a],prefix:s});t.push({val:"["})}else{u=[];for(c in r)r.hasOwnProperty(c)&&u.push(c);for(t.push({val:"}"}),a=u.length-1;a>=0;a--)f=u[a],l=r[f],d=a>0?",":"",d+=JSON.stringify(f)+":",t.push({obj:l,prefix:d});t.push({val:"{"})}return h},n.parse=function(e){for(var t,n,o,i,a,s,u,c,f,l=[],d=[],h=0;;)if(t=e[h++],"}"!==t&&"]"!==t&&"undefined"!=typeof t)switch(t){case" ":case" ":case"\n":case":":case",":break;case"n":h+=3,r(null,l,d);break;case"t":h+=3,r(!0,l,d);break;case"f":h+=4,r(!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(n="",h--;;){if(o=e[h++],!/[\d\.\-e\+]/.test(o)){h--;break}n+=o}r(parseFloat(n),l,d);break;case'"':for(i="",a=void 0,s=0;;){if(u=e[h++],'"'===u&&("\\"!==a||s%2!==1))break;i+=u,a=u,"\\"===a?s++:s=0}r(JSON.parse('"'+i+'"'),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();r(l.pop(),l,d)}}},{}]},{},[3])(3)});