com.vaadin.polymer.public.bower_components.pouchdb.dist.pouchdb.min.js Maven / Gradle / Ivy
The newest version!
// PouchDB 6.3.4
//
// (c) 2012-2017 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 e(t,n,r){function o(a,s){if(!n[a]){if(!t[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:{}};t[a][0].call(f.exports,function(e){var n=t[a][1][e];return o(n||e)},f,f.exports,e,t,n,r)}return n[a].exports}for(var i="function"==typeof require&&require,a=0;a=31||"undefined"!=typeof navigator&&navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))}function i(e){var t=this.useColors;if(e[0]=(t?"%c":"")+this.namespace+(t?" %c":" ")+e[0]+(t?"%c ":" ")+"+"+n.humanize(this.diff),t){var r="color: "+this.color;e.splice(1,0,r,"color: inherit");var o=0,i=0;e[0].replace(/%[a-zA-Z%]/g,function(e){"%%"!==e&&(o++,"%c"===e&&(i=o))}),e.splice(i,0,r)}}function a(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function s(e){try{null==e?n.storage.removeItem("debug"):n.storage.debug=e}catch(e){}}function u(){var e;try{e=n.storage.debug}catch(e){}return!e&&void 0!==r&&"env"in r&&(e=r.env.DEBUG),e}n=t.exports=e(3),n.log=a,n.formatArgs=i,n.save=s,n.load=u,n.useColors=o,n.storage="undefined"!=typeof chrome&&void 0!==chrome.storage?chrome.storage.local:function(){try{return window.localStorage}catch(e){}}(),n.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],n.formatters.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}},n.enable(u())}).call(this,e(9))},{3:3,9:9}],3:[function(e,t,n){function r(e){var t,r=0;for(t in e)r=(r<<5)-r+e.charCodeAt(t),r|=0;return n.colors[Math.abs(r)%n.colors.length]}function o(e){function t(){if(t.enabled){var e=t,r=+new Date,o=r-(c||r);e.diff=o,e.prev=c,e.curr=r,c=r;for(var i=new Array(arguments.length),a=0;a0&&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(r<0)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){return 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)}},{}],5:[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;++e1e4)){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]);switch((t[2]||"ms").toLowerCase()){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;default:return}}}}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){if(!(e0)return r(e);if("number"===n&&!1===isNaN(e))return t.long?i(e):o(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}},{}],9:[function(e,t,n){function r(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function i(e){if(l===setTimeout)return setTimeout(e,0);if((l===r||!l)&&setTimeout)return l=setTimeout,setTimeout(e,0);try{return l(e,0)}catch(t){try{return l.call(null,e,0)}catch(t){return l.call(this,e,0)}}}function a(e){if(d===clearTimeout)return clearTimeout(e);if((d===o||!d)&&clearTimeout)return d=clearTimeout,clearTimeout(e);try{return d(e)}catch(t){try{return d.call(null,e)}catch(t){return d.call(this,e)}}}function s(){g&&p&&(g=!1,p.length?v=p.concat(v):y=-1,v.length&&u())}function u(){if(!g){var e=i(s);g=!0;for(var t=v.length;t;){for(p=v,v=[];++y1)for(var n=1;n>>25)+r|0,i+=(n&r|~n&o)+t[1]-389564586|0,i=(i<<12|i>>>20)+n|0,o+=(i&n|~i&r)+t[2]+606105819|0,o=(o<<17|o>>>15)+i|0,r+=(o&i|~o&n)+t[3]-1044525330|0,r=(r<<22|r>>>10)+o|0,n+=(r&o|~r&i)+t[4]-176418897|0,n=(n<<7|n>>>25)+r|0,i+=(n&r|~n&o)+t[5]+1200080426|0,i=(i<<12|i>>>20)+n|0,o+=(i&n|~i&r)+t[6]-1473231341|0,o=(o<<17|o>>>15)+i|0,r+=(o&i|~o&n)+t[7]-45705983|0,r=(r<<22|r>>>10)+o|0,n+=(r&o|~r&i)+t[8]+1770035416|0,n=(n<<7|n>>>25)+r|0,i+=(n&r|~n&o)+t[9]-1958414417|0,i=(i<<12|i>>>20)+n|0,o+=(i&n|~i&r)+t[10]-42063|0,o=(o<<17|o>>>15)+i|0,r+=(o&i|~o&n)+t[11]-1990404162|0,r=(r<<22|r>>>10)+o|0,n+=(r&o|~r&i)+t[12]+1804603682|0,n=(n<<7|n>>>25)+r|0,i+=(n&r|~n&o)+t[13]-40341101|0,i=(i<<12|i>>>20)+n|0,o+=(i&n|~i&r)+t[14]-1502002290|0,o=(o<<17|o>>>15)+i|0,r+=(o&i|~o&n)+t[15]+1236535329|0,r=(r<<22|r>>>10)+o|0,n+=(r&i|o&~i)+t[1]-165796510|0,n=(n<<5|n>>>27)+r|0,i+=(n&o|r&~o)+t[6]-1069501632|0,i=(i<<9|i>>>23)+n|0,o+=(i&r|n&~r)+t[11]+643717713|0,o=(o<<14|o>>>18)+i|0,r+=(o&n|i&~n)+t[0]-373897302|0,r=(r<<20|r>>>12)+o|0,n+=(r&i|o&~i)+t[5]-701558691|0,n=(n<<5|n>>>27)+r|0,i+=(n&o|r&~o)+t[10]+38016083|0,i=(i<<9|i>>>23)+n|0,o+=(i&r|n&~r)+t[15]-660478335|0,o=(o<<14|o>>>18)+i|0,r+=(o&n|i&~n)+t[4]-405537848|0,r=(r<<20|r>>>12)+o|0,n+=(r&i|o&~i)+t[9]+568446438|0,n=(n<<5|n>>>27)+r|0,i+=(n&o|r&~o)+t[14]-1019803690|0,i=(i<<9|i>>>23)+n|0,o+=(i&r|n&~r)+t[3]-187363961|0,o=(o<<14|o>>>18)+i|0,r+=(o&n|i&~n)+t[8]+1163531501|0,r=(r<<20|r>>>12)+o|0,n+=(r&i|o&~i)+t[13]-1444681467|0,n=(n<<5|n>>>27)+r|0,i+=(n&o|r&~o)+t[2]-51403784|0,i=(i<<9|i>>>23)+n|0,o+=(i&r|n&~r)+t[7]+1735328473|0,o=(o<<14|o>>>18)+i|0,r+=(o&n|i&~n)+t[12]-1926607734|0,r=(r<<20|r>>>12)+o|0,n+=(r^o^i)+t[5]-378558|0,n=(n<<4|n>>>28)+r|0,i+=(n^r^o)+t[8]-2022574463|0,i=(i<<11|i>>>21)+n|0,o+=(i^n^r)+t[11]+1839030562|0,o=(o<<16|o>>>16)+i|0,r+=(o^i^n)+t[14]-35309556|0,r=(r<<23|r>>>9)+o|0,n+=(r^o^i)+t[1]-1530992060|0,n=(n<<4|n>>>28)+r|0,i+=(n^r^o)+t[4]+1272893353|0,i=(i<<11|i>>>21)+n|0,o+=(i^n^r)+t[7]-155497632|0,o=(o<<16|o>>>16)+i|0,r+=(o^i^n)+t[10]-1094730640|0,r=(r<<23|r>>>9)+o|0,n+=(r^o^i)+t[13]+681279174|0,n=(n<<4|n>>>28)+r|0,i+=(n^r^o)+t[0]-358537222|0,i=(i<<11|i>>>21)+n|0,o+=(i^n^r)+t[3]-722521979|0,o=(o<<16|o>>>16)+i|0,r+=(o^i^n)+t[6]+76029189|0,r=(r<<23|r>>>9)+o|0,n+=(r^o^i)+t[9]-640364487|0,n=(n<<4|n>>>28)+r|0,i+=(n^r^o)+t[12]-421815835|0,i=(i<<11|i>>>21)+n|0,o+=(i^n^r)+t[15]+530742520|0,o=(o<<16|o>>>16)+i|0,r+=(o^i^n)+t[2]-995338651|0,r=(r<<23|r>>>9)+o|0,n+=(o^(r|~i))+t[0]-198630844|0,n=(n<<6|n>>>26)+r|0,i+=(r^(n|~o))+t[7]+1126891415|0,i=(i<<10|i>>>22)+n|0,o+=(n^(i|~r))+t[14]-1416354905|0,o=(o<<15|o>>>17)+i|0,r+=(i^(o|~n))+t[5]-57434055|0,r=(r<<21|r>>>11)+o|0,n+=(o^(r|~i))+t[12]+1700485571|0,n=(n<<6|n>>>26)+r|0,i+=(r^(n|~o))+t[3]-1894986606|0,i=(i<<10|i>>>22)+n|0,o+=(n^(i|~r))+t[10]-1051523|0,o=(o<<15|o>>>17)+i|0,r+=(i^(o|~n))+t[1]-2054922799|0,r=(r<<21|r>>>11)+o|0,n+=(o^(r|~i))+t[8]+1873313359|0,n=(n<<6|n>>>26)+r|0,i+=(r^(n|~o))+t[15]-30611744|0,i=(i<<10|i>>>22)+n|0,o+=(n^(i|~r))+t[6]-1560198380|0,o=(o<<15|o>>>17)+i|0,r+=(i^(o|~n))+t[13]+1309151649|0,r=(r<<21|r>>>11)+o|0,n+=(o^(r|~i))+t[4]-145523070|0,n=(n<<6|n>>>26)+r|0,i+=(r^(n|~o))+t[11]-1120210379|0,i=(i<<10|i>>>22)+n|0,o+=(n^(i|~r))+t[2]+718787259|0,o=(o<<15|o>>>17)+i|0,r+=(i^(o|~n))+t[9]-343485551|0,r=(r<<21|r>>>11)+o|0,e[0]=n+e[0]|0,e[1]=r+e[1]|0,e[2]=o+e[2]|0,e[3]=i+e[3]|0}function n(e){var t,n=[];for(t=0;t<64;t+=4)n[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return n}function r(e){var t,n=[];for(t=0;t<64;t+=4)n[t>>2]=e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24);return n}function o(e){var r,o,i,a,s,u,c=e.length,f=[1732584193,-271733879,-1732584194,271733878];for(r=64;r<=c;r+=64)t(f,n(e.substring(r-64,r)));for(e=e.substring(r-64),o=e.length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],r=0;r>2]|=e.charCodeAt(r)<<(r%4<<3);if(i[r>>2]|=128<<(r%4<<3),r>55)for(t(f,i),r=0;r<16;r+=1)i[r]=0;return a=8*c,a=a.toString(16).match(/(.*?)(.{0,8})$/),s=parseInt(a[2],16),u=parseInt(a[1],16)||0,i[14]=s,i[15]=u,t(f,i),f}function i(e){var n,o,i,a,s,u,c=e.length,f=[1732584193,-271733879,-1732584194,271733878];for(n=64;n<=c;n+=64)t(f,r(e.subarray(n-64,n)));for(e=n-64>2]|=e[n]<<(n%4<<3);if(i[n>>2]|=128<<(n%4<<3),n>55)for(t(f,i),n=0;n<16;n+=1)i[n]=0;return a=8*c,a=a.toString(16).match(/(.*?)(.{0,8})$/),s=parseInt(a[2],16),u=parseInt(a[1],16)||0,i[14]=s,i[15]=u,t(f,i),f}function a(e){var t,n="";for(t=0;t<4;t+=1)n+=p[e>>8*t+4&15]+p[e>>8*t&15];return n}function s(e){var t;for(t=0;t>16)+(t>>16)+(n>>16)<<16|65535&n},"undefined"==typeof ArrayBuffer||ArrayBuffer.prototype.slice||function(){function t(e,t){return e=0|e||0,e<0?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)}}(),h.prototype.append=function(e){return this.appendBinary(u(e)),this},h.prototype.appendBinary=function(e){this._buff+=e,this._length+=e.length;var r,o=this._buff.length;for(r=64;r<=o;r+=64)t(this._hash,n(this._buff.substring(r-64,r)));return this._buff=this._buff.substring(r-64),this},h.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;t>2]|=r.charCodeAt(t)<<(t%4<<3);return this._finish(i,o),n=s(this._hash),e&&(n=d(n)),this.reset(),n},h.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},h.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash}},h.prototype.setState=function(e){return this._buff=e.buff,this._length=e.length,this._hash=e.hash,this},h.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},h.prototype._finish=function(e,n){var r,o,i,a=n;if(e[a>>2]|=128<<(a%4<<3),a>55)for(t(this._hash,e),a=0;a<16;a+=1)e[a]=0;r=8*this._length,r=r.toString(16).match(/(.*?)(.{0,8})$/),o=parseInt(r[2],16),i=parseInt(r[1],16)||0,e[14]=o,e[15]=i,t(this._hash,e)},h.hash=function(e,t){return h.hashBinary(u(e),t)},h.hashBinary=function(e,t){var n=o(e),r=s(n);return t?d(r):r},h.ArrayBuffer=function(){this.reset()},h.ArrayBuffer.prototype.append=function(e){var n,o=l(this._buff.buffer,e,!0),i=o.length;for(this._length+=e.byteLength,n=64;n<=i;n+=64)t(this._hash,r(o.subarray(n-64,n)));return this._buff=n-64>2]|=r[t]<<(t%4<<3);return this._finish(i,o),n=s(this._hash),e&&(n=d(n)),this.reset(),n},h.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},h.ArrayBuffer.prototype.getState=function(){var e=h.prototype.getState.call(this);return e.buff=f(e.buff),e},h.ArrayBuffer.prototype.setState=function(e){return e.buff=c(e.buff,!0),h.prototype.setState.call(this,e)},h.ArrayBuffer.prototype.destroy=h.prototype.destroy,h.ArrayBuffer.prototype._finish=h.prototype._finish,h.ArrayBuffer.hash=function(e,t){var n=i(new Uint8Array(e)),r=s(n);return t?d(r):r},h})},{}],11:[function(e,t,n){var r=e(14),o=e(15),i=o;i.v1=r,i.v4=o,t.exports=i},{14:14,15:15}],12:[function(e,t,n){function r(e,t){var n=t||0,r=o;return r[e[n++]]+r[e[n++]]+r[e[n++]]+r[e[n++]]+"-"+r[e[n++]]+r[e[n++]]+"-"+r[e[n++]]+r[e[n++]]+"-"+r[e[n++]]+r[e[n++]]+"-"+r[e[n++]]+r[e[n++]]+r[e[n++]]+r[e[n++]]+r[e[n++]]+r[e[n++]]}for(var o=[],i=0;i<256;++i)o[i]=(i+256).toString(16).substr(1);t.exports=r},{}],13:[function(e,t,n){(function(e){var n,r=e.crypto||e.msCrypto;if(r&&r.getRandomValues){var o=new Uint8Array(16);n=function(){return r.getRandomValues(o),o}}if(!n){var i=new Array(16);n=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),i[t]=e>>>((3&t)<<3)&255;return i}}t.exports=n}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],14:[function(e,t,n){function r(e,t,n){var r=t&&n||0,o=t||[];e=e||{};var a=void 0!==e.clockseq?e.clockseq:u,l=void 0!==e.msecs?e.msecs:(new Date).getTime(),d=void 0!==e.nsecs?e.nsecs:f+1,h=l-c+(d-f)/1e4;if(h<0&&void 0===e.clockseq&&(a=a+1&16383),(h<0||l>c)&&void 0===e.nsecs&&(d=0),d>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");c=l,f=d,u=a,l+=122192928e5;var p=(1e4*(268435455&l)+d)%4294967296;o[r++]=p>>>24&255,o[r++]=p>>>16&255,o[r++]=p>>>8&255,o[r++]=255&p;var v=l/4294967296*1e4&268435455;o[r++]=v>>>8&255,o[r++]=255&v,o[r++]=v>>>24&15|16,o[r++]=v>>>16&255,o[r++]=a>>>8|128,o[r++]=255&a;for(var g=e.node||s,y=0;y<6;++y)o[r+y]=g[y];return t||i(o)}var o=e(13),i=e(12),a=o(),s=[1|a[0],a[1],a[2],a[3],a[4],a[5]],u=16383&(a[6]<<8|a[7]),c=0,f=0;t.exports=r},{12:12,13:13}],15:[function(e,t,n){function r(e,t,n){var r=t&&n||0;"string"==typeof e&&(t="binary"==e?new Array(16):null,e=null),e=e||{};var a=e.random||(e.rng||o)();if(a[6]=15&a[6]|64,a[8]=63&a[8]|128,t)for(var s=0;s<16;++s)t[r+s]=a[s];return t||i(a)}var o=e(13),i=e(12);t.exports=r},{12:12,13:13}],16:[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+=void 0===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&&void 0!==t)switch(t){case" ":case"\t":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++])&&("\\"!==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)}}},{}],17:[function(e,t,n){(function(n){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e.default:e}function o(e){return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Blob&&e instanceof Blob}function i(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 a(e){if(e instanceof ArrayBuffer)return i(e);var t=e.size,n=e.type;return"function"==typeof e.slice?e.slice(0,t,n):e.webkitSlice(0,t,n)}function s(e){var t=Object.getPrototypeOf(e);if(null===t)return!0;var n=t.constructor;return"function"==typeof n&&n instanceof n&&go.call(n)==yo}function u(e){var t,n,r;if(!e||"object"!=typeof e)return e;if(Array.isArray(e)){for(t=[],n=0,r=e.length;n=h.length)){var e=Math.min(p+wo,h.length),t=h.slice(p,e);s(t,p),p+=t.length}}function s(n,r){n.forEach(function(n,o){var s=r+o,u=c.get(n),f=y(u[0],["atts_since","attachments"]);f.open_revs=u.map(function(e){return e.rev}),f.open_revs=f.open_revs.filter(_);var l=_;0===f.open_revs.length&&(delete f.open_revs,l=m),["revs","attachments","binary","ajax","latest"].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=new mo;u.forEach(function(e){c.has(e.id)?c.get(e.id).push(e):c.set(e.id,[e])});var f=c.size,l=0,d=new Array(f),h=[];c.forEach(function(e,t){h.push(t)});var p=0;a()}function w(){return"undefined"!=typeof chrome&&void 0!==chrome.storage&&void 0!==chrome.storage.local}function E(){return bo}function k(e){w()?chrome.storage.onChanged.addListener(function(t){null!=t.db_name&&e.emit(t.dbName.newValue)}):E()&&("undefined"!=typeof addEventListener?addEventListener("storage",function(t){e.emit(t.key)}):window.attachEvent("storage",function(t){e.emit(t.key)}))}function S(){uo.EventEmitter.call(this),this._listeners={},k(this)}function q(e){if("undefined"!==console&&e in console){var t=Array.prototype.slice.call(arguments,1);console[e].apply(console,t)}}function A(e,t){return e=parseInt(e,10)||0,t=parseInt(t,10),t!==t||t<=e?t=(e||1)<<1:t+=1,t>6e5&&(e=3e5,t=6e5),~~((t-e)*Math.random()+e)}function x(e){var t=0;return e||(t=2e3),A(e,t)}function T(e,t){q("info","The above "+e+" is totally normal. "+t)}function O(e,t,n){Error.call(this,n),this.status=e,this.name=t,this.message=n,this.error=!0}function j(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=O.prototype,new n(t)}function C(e){if("object"!=typeof e){var t=e;e=jo,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 L(e,t,n){try{return!e(t,n)}catch(e){var r="Filter function threw: "+e.toString();return j(Do,r)}}function I(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&&L(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 D(e){for(var t=[],n=0,r=e.length;n>>1,n(e[r],t)<0?o=r+1:i=r;return o}function te(e,t,n){var r=ee(e,t,n);e.splice(r,0,t)}function ne(e,t){for(var n,r,o=t,i=e.length;o0;){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;s0;){var v=p.pop();if(0!==v.diff)for(var g=v.ids[2],y=0,_=g.length;y<_;y++)p.push({ids:g[y],diff:v.diff-1,parent:v.ids,parentIdx:y});else v.ids[0]===l.ids[0]&&h.push(v)}var m=h[0];m?(r=oe(m.ids,l.ids),m.parent[2][m.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(Z),{tree:o,conflicts:i||"internal_node"}}function ae(e,t){for(var n,r,o=Y(e),i=0,a=o.length;it){n||(n={});var f=c.length-t;s={pos:u.pos+f,ids:ne(c,f)};for(var l=0;l0&&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){o.isCancelled||he(o,e)};var a=new vo(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.validateChanges(t):e.taskqueue.addTask(function(e){e?t.complete(e):o.isCancelled?o.emit("cancel"):o.validateChanges(t)})}function ve(e,t,n){var r=[{rev:e._rev}];"all_docs"===n.style&&(r=G(t.rev_tree).map(function(e){return{rev:e.rev}}));var o={id:t.id,changes:r,doc:e};return fe(t,e._rev)&&(o.deleted=!0),n.conflicts&&(o.doc._conflicts=V(t),o.doc._conflicts.length||delete o.doc._conflicts),o}function ge(e,t){return et?1:0}function ye(e,t){return function(n,r){n||r[0]&&r[0].error?(n=n||r[0],n.docId=t,e(n)):e(null,r.length?r[0]:r)}}function _e(e){for(var t=0;t0?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 vo.all(r.map(function(n){var r=ko({key:n,deleted:"ok"},t);return["limit","skip","keys"].forEach(function(e){delete r[e]}),new vo(function(t,i){e._allDocs(r,function(e,r){if(e)return i(e);o.total_rows=r.total_rows,t(r.rows[0]||{key:n,error:"not_found"})})})})).then(function(e){return o.rows=e,o})}function Ee(e){var t=e._compactionQueue[0],n=t.opts,r=t.callback;e.get("_local/compaction").catch(function(){return!1}).then(function(t){t&&t.last_seq&&(n.last_seq=t.last_seq),e._compact(n,function(t,n){t?r(t):r(null,n),fo(function(){e._compactionQueue.shift(),e._compactionQueue.length&&Ee(e)})})})}function ke(e){return"_"===e.charAt(0)&&e+" is not a valid attachment name, attachment names cannot start with '_'"}function Se(){uo.EventEmitter.call(this)}function qe(){this.isReady=!1,this.failed=!1,this.queue=[]}function Ae(e,t){var n=e.match(/([a-z-]*):\/\/(.*)/);if(n)return{name:/https?/.test(n[1])?n[1]+"://"+n[2]:n[2],adapter:n[1]};var r=Te.adapters,o=Te.preferredAdapters,i=Te.prefix,a=t.adapter;if(!a)for(var s=0;st?1:0}function Le(e){for(var t=[],n="",r=0,o=e.length;r0&&"\\"===e[r-1]?n=n.substring(0,n.length-1)+".":(t.push(n),n=""):n+=i}return t.push(n),t}function Ie(e){return Ko.indexOf(e)>-1}function De(e){return Object.keys(e)[0]}function Re(e){return e[De(e)]}function Ne(e){var t={};return e.forEach(function(e){Object.keys(e).forEach(function(n){var r=e[n];if("object"!=typeof r&&(r={$eq:r}),Ie(n))r instanceof Array?t[n]=r.map(function(e){return Ne([e])}):t[n]=Ne([r]);else{var o=t[n]=t[n]||{};Object.keys(r).forEach(function(e){var t=r[e];return"$gt"===e||"$gte"===e?Be(e,t,o):"$lt"===e||"$lte"===e?$e(e,t,o):"$ne"===e?Fe(t,o):"$eq"===e?Me(t,o):void(o[e]=t)})}})}),t}function Be(e,t,n){void 0===n.$eq&&(void 0!==n.$gte?"$gte"===e?t>n.$gte&&(n.$gte=t):t>=n.$gte&&(delete n.$gte,n.$gt=t):void 0!==n.$gt?"$gte"===e?t>n.$gt&&(delete n.$gt,n.$gte=t):t>n.$gt&&(n.$gt=t):n[e]=t)}function $e(e,t,n){void 0===n.$eq&&(void 0!==n.$lte?"$lte"===e?tt.length?1:-1}function Ye(e,t){return e===t?0:e>t?1:-1}function Ze(e,t){for(var n=Object.keys(e),r=Object.keys(t),o=Math.min(n.length,r.length),i=0;ir.length?1:-1}function et(e){var t=["boolean","number","string","object"],n=t.indexOf(typeof e);return~n?null===e?1:Array.isArray(e)?5:n<3?n+2:n+3:Array.isArray(e)?5:void 0}function tt(e){if(0===e)return"1";var t=e.toExponential().split(/e\+?/),n=parseInt(t[1],10),r=e<0,o=r?"0":"2",i=(r?-n:n)-Xo,a=Je(i.toString(),"0",Go);o+=Vo+a;var s=Math.abs(parseFloat(t[0]));r&&(s=10-s);var u=s.toFixed(20);return u=u.replace(/\.?0+$/,""),o+=Vo+u}function nt(e){function t(t){return e.map(function(e){var n=De(e),r=Le(n);return je(t,r)})}return function(e,n){var r=t(e.doc),o=t(n.doc),i=He(r,o);return 0!==i?i:Ce(e.doc._id,n.doc._id)}}function rt(e,t,n){if(e=e.filter(function(e){return ot(e.doc,t.selector,n)}),t.sort){var r=nt(t.sort);e=e.sort(r),"string"!=typeof t.sort[0]&&"desc"===Re(t.sort[0])&&(e=e.reverse())}if("limit"in t||"skip"in t){var o=t.skip||0,i=("limit"in t?t.limit:e.length)+o;e=e.slice(o,i)}return e}function ot(e,t,n){return n.every(function(n){var r=t[n],o=Le(n),i=je(e,o);return Ie(n)?at(n,r,e):it(r,e,o,i)})}function it(e,t,n,r){return!e||Object.keys(e).every(function(o){var i=e[o];return st(o,t,i,n,r)})}function at(e,t,n){return"$or"===e?t.some(function(e){return ot(n,e,Object.keys(e))}):"$not"===e?!ot(n,t,Object.keys(t)):!t.find(function(e){return ot(n,e,Object.keys(e))})}function st(e,t,n,r,o){if(!Qo[e])throw new Error('unknown operator "'+e+'" - should be one of $eq, $lte, $lt, $gt, $gte, $exists, $ne, $in, $nin, $size, $mod, $regex, $elemMatch, $type, $allMatch or $all');return Qo[e](t,n,r,o)}function ut(e){return void 0!==e&&null!==e}function ct(e){return void 0!==e}function ft(e,t){var n=t[0],r=t[1];if(0===n)throw new Error("Bad divisor, cannot divide by zero");if(parseInt(n,10)!==n)throw new Error("Divisor is not an integer");if(parseInt(r,10)!==r)throw new Error("Modulus is not an integer");return parseInt(e,10)===e&&e%n===r}function lt(e,t){return t.some(function(t){return e instanceof Array?e.indexOf(t)>-1:e===t})}function dt(e,t){return t.every(function(t){return e.indexOf(t)>-1})}function ht(e,t){return e.length===t}function pt(e,t){return new RegExp(t).test(e)}function vt(e,t){switch(t){case"null":return null===e;case"boolean":return"boolean"==typeof e;case"number":return"number"==typeof e;case"string":return"string"==typeof e;case"array":return e instanceof Array;case"object":return"[object Object]"==={}.toString.call(e)}throw new Error(t+" not supported as a type.Please use one of object, string, array, number, boolean or null.")}function gt(e,t){if("object"!=typeof t)throw new Error("Selector error: expected a JSON object");t=Pe(t);var n={doc:e},r=rt([n],{selector:t},Object.keys(t));return r&&1===r.length}function yt(e){return U('"use strict";\nreturn '+e+";",{})}function _t(e){return U(["return function(doc) {",' "use strict";'," var emitted = false;"," var emit = function (a, b) {"," emitted = true;"," };"," var view = "+e+";"," view(doc);"," if (emitted) {"," return true;"," }","};"].join("\n"),{})}function mt(e,t){if(e.selector&&e.filter&&"_selector"!==e.filter){var n="string"==typeof e.filter?e.filter:"function";return t(new Error('selector invalid for filter "'+n+'"'))}t()}function bt(e){e.view&&!e.filter&&(e.filter="_view"),e.selector&&!e.filter&&(e.filter="_selector"),e.filter&&"string"==typeof e.filter&&("_view"===e.filter?e.view=M(e.view):e.filter=M(e.filter))}function wt(e,t){return t.filter&&"string"==typeof t.filter&&!t.doc_ids&&!B(e.db)}function Et(e,t){var n=t.complete;if("_view"===t.filter){if(!t.view||"string"!=typeof t.view){var r=j(Do,"`view` filter parameter not found or invalid.");return n(r)}var o=F(t.view);e.db.get("_design/"+o[0],function(r,i){if(e.isCancelled)return n(null,{status:"cancelled"});if(r)return n(C(r));var a=i&&i.views&&i.views[o[1]]&&i.views[o[1]].map;if(!a)return n(j(qo,i.views?"missing json key: "+o[1]:"missing json key: views"));t.filter=_t(a),e.doChanges(t)})}else if(t.selector)t.filter=function(e){return gt(e,t.selector)},e.doChanges(t);else{var i=F(t.filter);e.db.get("_design/"+i[0],function(r,o){if(e.isCancelled)return n(null,{status:"cancelled"});if(r)return n(C(r));var a=o&&o.filters&&o.filters[i[1]];if(!a)return n(j(qo,o&&o.filters?"missing json key: "+i[1]:"missing json key: filters"));t.filter=yt(a),e.doChanges(t)})}}function kt(e){e._changesFilterPlugin={validate:mt,normalize:bt,shouldFilter:wt,filter:Et}}function St(e){return e.reduce(function(e,t){return e[t]=!0,e},{})}function qt(e){if(!/^\d+-./.test(e))return j($o);var t=e.indexOf("-"),n=e.substring(0,t),r=e.substring(t+1);return{prefix:parseInt(n,10),id:r}}function At(e,t){for(var n=e.start-e.ids.length+1,r=e.ids,o=[r[0],t,[]],i=1,a=r.length;i0||r0||r1&&!n;d?(l={continue:s},e.getAll(t,r).onsuccess=i,e.getAllKeys(t,r).onsuccess=a):n?e.openCursor(t,"prev").onsuccess=u:e.openCursor(t).onsuccess=u}function ln(e,t,n){function r(e){var t=e.target.result;t?(o.push(t.value),t.continue()):n({target:{result:o}})}if("function"==typeof e.getAll)return void(e.getAll(t).onsuccess=n);var o=[];e.openCursor(t).onsuccess=r}function dn(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(e){return{error:e}}return null}function hn(e,t,n){function r(t,n,r){var o=t.id+"::"+r;q.get(o).onsuccess=function(r){if(n.doc=nn(r.target.result),e.conflicts){var o=V(t);o.length&&(n.doc._conflicts=o)}on(n.doc,e,b)}}function o(t,n){var o={id:n.id,key:n.id,value:{rev:t}},i=n.deleted;"ok"===e.deleted?(A.push(o),i?(o.value.deleted=!0,o.doc=null):e.include_docs&&r(n,o,t)):!i&&h--<=0&&(A.push(o),e.include_docs&&r(n,o,t))}function i(e){for(var t=0,n=e.length;t=43)},e.onabort=function(e){e.preventDefault(),e.stopPropagation(),t(!1)}}).catch(function(){return!1})}function vn(e,t){e.objectStore(ai).index("deletedOrLocal").count(IDBKeyRange.only("0")).onsuccess=function(e){t(e.target.result)}}function gn(e,t,n,r){try{e(t,n)}catch(t){r.emit("error",t)}}function yn(){!pi&&vi.length&&(pi=!0,vi.shift()())}function _n(e,t,n){vi.push(function(){e(function(e,r){gn(t,e,r,n),pi=!1,fo(function(){yn(n)})})}),yn()}function mn(e,t,n,r){function o(t,n,r){function o(t,n){var r=e.processChange(n,t,e);d=r.seq=t.seq;var o=w(r);if("object"==typeof o)return e.complete(o);o&&(b++,p&&m.push(r),e.attachments&&e.include_docs?on(n,e,v,function(){an([r],e.binary).then(function(){e.onChange(r)})}):e.onChange(r))}function i(){for(var e=0,t=s.length;ei&&(i=n),t.continue()}}()}}}var l=t.name,d=null;e._meta=null,e._remote=!1,e.type=function(){return"idb"},e._id=f(function(t){t(null,e._meta.instanceId)}),e._bulkDocs=function(n,r,o){cn(t,n,r,e,d,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=un(d,[ai,si,ui],"readonly");if(u.error)return n(u.error);s=u.txn}s.objectStore(ai).get(e).onsuccess=function(e){if(!(i=tn(e.target.result)))return a=j(qo,"missing"),r();var n;if(t.rev)n=t.latest?de(t.rev,i):t.rev;else{n=i.winningRev;if(fe(i))return a=j(qo,"deleted"),r()}var u=s.objectStore(si),c=i.id+"::"+n;u.index("_doc_id_rev").get(c).onsuccess=function(e){if(o=e.target.result,o&&(o=nn(o)),!o)return a=j(qo,"missing"),r();r()}}},e._getAttachment=function(e,t,n,r,o){var i;if(r.ctx)i=r.ctx;else{var a=un(d,[ai,si,ui],"readonly");if(a.error)return o(a.error);i=a.txn}var s=n.digest,u=n.content_type;i.objectStore(ui).get(s).onsuccess=function(e){rn(e.target.result.body,u,r.binary,function(e){o(null,e)})}},e._info=function(t){var n,r,o=un(d,[fi,si],"readonly");if(o.error)return t(o.error);var i=o.txn;i.objectStore(fi).get(fi).onsuccess=function(e){r=e.target.result.docCount},i.objectStore(si).openCursor(null,"prev").onsuccess=function(e){var t=e.target.result;n=t?t.key:0},i.oncomplete=function(){t(null,{doc_count:r,update_seq:n,idb_attachment_format:e._meta.blobSupport?"binary":"base64"})}},e._allDocs=function(e,t){hn(e,d,t)},e._changes=function(t){return mn(t,e,l,d)},e._close=function(e){d.close(),gi.delete(l),e()},e._getRevisionTree=function(e,t){var n=un(d,[ai],"readonly");if(n.error)return t(n.error);n.txn.objectStore(ai).get(e).onsuccess=function(e){var n=tn(e.target.result);n?t(null,n.rev_tree):t(j(qo))}},e._doCompaction=function(e,t,n){var r=[ai,si,ui,ci],o=un(d,r,"readwrite");if(o.error)return n(o.error);var i=o.txn;i.objectStore(ai).get(e).onsuccess=function(n){var r=tn(n.target.result);K(r.rev_tree,function(e,n,r,o,i){var a=n+"-"+r;-1!==t.indexOf(a)&&(i.status="missing")}),sn(t,e,i);var o=r.winningRev,a=r.deleted;i.objectStore(ai).put(en(r,o,a))},i.onabort=Zt(n),i.oncomplete=function(){n()}},e._getLocal=function(e,t){var n=un(d,[li],"readonly");if(n.error)return t(n.error);var r=n.txn,o=r.objectStore(li).get(e);o.onerror=Zt(t),o.onsuccess=function(e){var n=e.target.result;n?(delete n._doc_id_rev,t(null,n)):t(j(qo))}},e._putLocal=function(e,t,n){"function"==typeof t&&(n=t,t={}),delete e._revisions;var r=e._rev,o=e._id;e._rev=r?"0-"+(parseInt(r.split("-")[1],10)+1):"0-1";var i,a=t.ctx;if(!a){var s=un(d,[li],"readwrite");if(s.error)return n(s.error);a=s.txn,a.onerror=Zt(n),a.oncomplete=function(){i&&n(null,i)}}var u,c=a.objectStore(li);r?(u=c.get(o),u.onsuccess=function(o){var a=o.target.result;if(a&&a._rev===r){c.put(e).onsuccess=function(){i={ok:!0,id:e._id,rev:e._rev},t.ctx&&n(null,i)}}else n(j(Ao))}):(u=c.add(e),u.onerror=function(e){n(j(Ao)),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=un(d,[li],"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(li),u=s.get(a);u.onerror=Zt(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(j(qo))}},e._destroy=function(e,t){hi.removeAllListeners(l);var n=yi.get(l);n&&n.result&&(n.result.close(),gi.delete(l));var r=indexedDB.deleteDatabase(l);r.onsuccess=function(){yi.delete(l),E()&&l in localStorage&&delete localStorage[l],t(null,{ok:!0})},r.onerror=Zt(t)};var h=gi.get(l);if(h)return d=h.idb,e._meta=h.global,fo(function(){n(null,e)});var p;p=t.storage?En(l,t.storage):indexedDB.open(l,ii),yi.set(l,p),p.onupgradeneeded=function(e){function t(){var e=l[d-1];d++,e&&e(f,t)}var n=e.target.result;if(e.oldVersion<1)return r(n);var f=e.currentTarget.transaction;e.oldVersion<3&&i(n),e.oldVersion<4&&s(n);var l=[o,a,u,c],d=e.oldVersion;t()},p.onsuccess=function(t){function r(){void 0!==s&&f&&(e._meta={name:l,instanceId:u,blobSupport:s},gi.set(l,{idb:d,global:e._meta}),n(null,e))}function o(){if(void 0!==a&&void 0!==i){var e=l+"_id";e in i?u=i[e]:i[e]=u=Wo(),i.docCount=a,c.objectStore(fi).put(i)}}d=t.target.result,d.onversionchange=function(){d.close(),gi.delete(l)},d.onabort=function(e){q("error","Database has a global failure",e.target.error),d.close(),gi.delete(l)};var i,a,s,u,c=d.transaction([fi,di,ai],"readwrite"),f=!1;c.objectStore(fi).get(fi).onsuccess=function(e){i=e.target.result||{id:fi},o()},vn(c,function(e){a=e,o()}),Yo||(Yo=pn(c)),Yo.then(function(e){s=e,r()}),c.oncomplete=function(){f=!0,r()}},p.onerror=function(){var e="Failed to open indexedDB, are you in private browsing mode?";q("error",e),n(j(No,e))}}function En(e,t){try{return indexedDB.open(e,{version:ii,storage:t})}catch(t){return indexedDB.open(e,ii)}}function kn(e){return decodeURIComponent(escape(e))}function Sn(e){return e<65?e-48:e-55}function qn(e,t,n){for(var r="";t0;){k.pop()(null,b)}}function h(e,t){if(0===t){var n="CREATE TABLE IF NOT EXISTS "+Si+" (dbid, db_version INTEGER)",u="CREATE TABLE IF NOT EXISTS "+Ei+" (digest UNIQUE, escaped TINYINT(1), body BLOB)",f="CREATE TABLE IF NOT EXISTS "+qi+" (digest, seq INTEGER)",l="CREATE TABLE IF NOT EXISTS "+bi+" (id unique, json, winningseq, max_seq INTEGER UNIQUE)",h="CREATE TABLE IF NOT EXISTS "+wi+" (seq INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, json, deleted TINYINT(1), doc_id, rev)",p="CREATE TABLE IF NOT EXISTS "+ki+" (id UNIQUE, rev, json)";e.executeSql(u),e.executeSql(p),e.executeSql(f,[],function(){e.executeSql(Li),e.executeSql(Ii)}),e.executeSql(l,[],function(){e.executeSql(Ci),e.executeSql(h,[],function(){e.executeSql(Oi),e.executeSql(ji),e.executeSql(n,[],function(){var t="INSERT INTO "+Si+" (db_version, dbid) VALUES (?,?)";b=Wo();var n=[mi,b];e.executeSql(t,n,function(){d()})})})})}else{var v=function(){t=")+" ?"),l.push(o)),!1!==i){var h=s?">":"<";f&&(h+="="),d.push(bi+".id "+h+" ?"),l.push(i)}!1!==a&&(d.push(bi+".id = ?"),l.push(a))}"ok"!==e.deleted&&d.push(wi+".deleted = 0"),A.readTransaction(function(t){if(g(t,function(e){n=e}),0!==u){var o=Dn(Ri,[bi,wi],Di,d,bi+".id "+(s?"DESC":"ASC"));o+=" LIMIT "+u+" OFFSET "+c,t.executeSql(o,l,function(t,n){for(var o=0,i=n.rows.length;o ?"],f=[e.since];e.doc_ids&&(c.push(bi+".id IN "+In(e.doc_ids.length)),f=f.concat(e.doc_ids));var l="maxSeq "+(n?"DESC":"ASC"),d=Dn(t,s,u,c,l),h=I(e);e.view||e.filter||(d+=" LIMIT "+r);var p=e.since||0;A.readTransaction(function(t){t.executeSql(d,f,function(t,n){function s(t){return function(){e.onChange(t)}}for(var u=0,c=n.rows.length;u0&&(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):(e.status=o.statusCode,t(e))}).catch(function(e){e||(e=new Error("canceled")),t(e)}),{abort:n.reject}}function Qn(e,t){var n,r,o=!1,i=function(){n.abort(),u()},a=function(){o=!0,n.abort(),u()},s={abort:i},u=function(){clearTimeout(r),s.abort=function(){},n&&(n.onprogress=void 0,n.upload&&(n.upload.onprogress=void 0),n.onreadystatechange=void 0,n=void 0)};n=e.xhr?new e.xhr:new XMLHttpRequest;try{n.open(e.method,e.url)}catch(e){return t(new Error(e.name||"Url is invalid"))}n.withCredentials=!("withCredentials"in e)||e.withCredentials,"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 c in e.headers)e.headers.hasOwnProperty(c)&&n.setRequestHeader(c,e.headers[c]);return e.timeout>0&&(r=setTimeout(a,e.timeout),n.onprogress=function(){clearTimeout(r),4!==n.readyState&&(r=setTimeout(a,e.timeout))},void 0!==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?Tt([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 if("string"==typeof n.response)try{a=JSON.parse(n.response)}catch(e){}a.status=n.status,t(a)}u()}},e.body&&e.body instanceof Blob?Nt(e.body,function(e){n.send(e)}):n.send(e.body),s}function Yn(e,t){return Bi||e.xhr?Qn(e,t):Vn(e,t)}function Zn(){return""}function er(e,t){function n(t,n,r){if(!e.binary&&e.json&&"string"==typeof t)try{t=JSON.parse(t)}catch(e){return r(e)}Array.isArray(t)&&(t=t.map(function(e){return e.error||e.missing?C(e):e})),e.binary&&$i(t,n),r(null,t,n)}return e=u(e),e=ko({method:"GET",headers:{},json:!0,processData:!0,timeout:1e4,cache:!1},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),Yn(e,function(r,o,i){if(r)return t(C(r));var a,s=o.headers&&o.headers["content-type"],u=i||Zn();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(e){}o.statusCode>=200&&o.statusCode<300?n(u,o,t):(a=C(u),a.status=o.statusCode,t(a))})}function tr(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;if(!/^blob:/.test(e.url)&&(a||!s)){var u=-1!==e.url.indexOf("?");e.url+=(u?"&":"?")+"_nonce="+Date.now()}return er(e,t)}function nr(e,t){
return new vo(function(n,r){function o(){f++,e[l++]().then(a,s)}function i(){++d===h?c?r(c):n():u()}function a(){f--,i()}function s(e){f--,c=c||e,i()}function u(){for(;ft?t:f;var l={method:p,url:ur(c,"_changes"+fr(o)),timeout:r,body:h};g=a,e.aborted||i().then(function(){v=n(e,l,u)}).catch(u)}},_={results:[]},m=function(n,r){if(!e.aborted){var o=0;if(r&&r.results){o=r.results.length,_.last_seq=r.last_seq;({}).query=e.query_params,r.results=r.results.filter(function(t){f--;var n=I(e)(t);return n&&(e.include_docs&&e.attachments&&e.binary&&rr(t),a&&_.results.push(t),e.onChange(t)),n})}else if(n)return e.aborted=!0,void e.complete(n);r&&r.last_seq&&(g=r.last_seq);var i=s&&f<=0||r&&o0}function a(e){return e._conflicts&&e._conflicts.length>0}function s(t){return e.allDocs({keys:t,include_docs:!0,conflicts:!0}).then(function(e){if(r.cancelled)throw new Error("cancelled");e.rows.forEach(function(e){e.deleted||!e.doc||!Br(e.value.rev)||i(e.doc)||a(e.doc)||(e.doc._conflicts&&delete e.doc._conflicts,l.push(e.doc),delete n[e.id])})})}function c(){var e=Object.keys(n).filter(function(e){var t=n[e].missing;return 1===t.length&&Br(t[0])});if(e.length>0)return s(e)}function f(){return{ok:d,docs:l}}n=u(n);var l=[],d=!0;return vo.resolve().then(c).then(o).then(f)}function Jr(e,t,n,r,o){return e.get(t).catch(function(n){if(404===n.status)return"http"!==e.adapter&&"https"!==e.adapter||T(404,"PouchDB is just checking if a remote checkpoint exists."),{session_id:r,_id:t,history:[],replicator:ta,version:ea};throw n}).then(function(i){if(!o.cancelled&&i.last_seq!==n)return 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,na),i.version=ea,i.replicator=ta,i.session_id=r,i.last_seq=n,e.put(i).catch(function(i){if(409===i.status)return Jr(e,t,n,r,o);throw i})})}function Hr(e,t,n,r,o){this.src=e,this.target=t,this.id=n,this.returnValue=r,this.opts=o}function Wr(e,t){return e.session_id===t.session_id?{last_seq:e.last_seq,history:e.history}:zr(e.history,t.history)}function zr(e,t){var n=e[0],r=e.slice(1),o=t[0],i=t.slice(1);return n&&0!==t.length?Kr(n.session_id,t)?{last_seq:n.last_seq,history:e}:Kr(o.session_id,r)?{last_seq:o.last_seq,history:i}:zr(r,i):{last_seq:ra,history:[]}}function Kr(e,t){var n=t[0],r=t.slice(1);return!(!e||0===t.length)&&(e===n.session_id||Kr(e,r))}function Xr(e){return"number"==typeof e.status&&4===Math.floor(e.status/100)}function Gr(e,t,n,r){if(!1===e.retry)return t.emit("error",n),void t.removeAllListeners();if("function"!=typeof e.back_off_function&&(e.back_off_function=x),t.emit("requestError",n),"active"===t.state||"pending"===t.state){t.emit("paused",n),t.state="stopped";var o=function(){e.current_back_off=ia},i=function(){t.removeListener("active",o)};t.once("paused",i),t.once("active",o)}e.current_back_off=e.current_back_off||ia,e.current_back_off=e.back_off_function(e.current_back_off),setTimeout(r,e.current_back_off)}function Vr(e){return Object.keys(e).sort(He).reduce(function(t,n){return t[n]=e[n],t},{})}function Qr(e,t,n){var r=n.doc_ids?n.doc_ids.sort(He):"",o=n.filter?n.filter.toString():"",i="",a="",s="";return n.selector&&(s=JSON.stringify(n.selector)),n.filter&&n.query_params&&(i=JSON.stringify(Vr(n.query_params))),n.filter&&"_view"===n.filter&&(a=n.view.toString()),vo.all([e.id(),t.id()]).then(function(e){var t=e[0]+e[1]+o+a+i+r+s;return new vo(function(e){Pt(t,e)})}).then(function(e){return"_local/"+(e=e.replace(/\//g,".").replace(/\+/g,"_"))})}function Yr(e,t,n,r,o){function i(){return k?vo.resolve():Qr(e,t,n).then(function(o){E=o;var i={};i=!1===n.checkpoint?{writeSourceCheckpoint:!1,writeTargetCheckpoint:!1}:"source"===n.checkpoint?{writeSourceCheckpoint:!0,writeTargetCheckpoint:!1}:"target"===n.checkpoint?{writeSourceCheckpoint:!1,writeTargetCheckpoint:!0}:{writeSourceCheckpoint:!0,writeTargetCheckpoint:!0},k=new Hr(e,t,E,r,i)})}function a(){if($=[],0!==w.docs.length){var e=w.docs,i={timeout:n.timeout};return t.bulkDocs({docs:e,new_edits:!1},i).then(function(t){if(r.cancelled)throw p(),new Error("cancelled");var n=Object.create(null);t.forEach(function(e){e.error&&(n[e.id]=e)});var i=Object.keys(n).length;o.doc_write_failures+=i,o.docs_written+=e.length-i,e.forEach(function(e){var t=n[e._id];if(t){if(o.errors.push(t),"unauthorized"!==t.name&&"forbidden"!==t.name)throw t;r.emit("denied",u(t))}else $.push(e)})},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=O=w.seq;var e=u(o);return $.length&&(e.docs=$,r.emit("change",e)),A=!0,k.writeCheckpoint(w.seq,F).then(function(){if(A=!1,r.cancelled)throw p(),new Error("cancelled");w=void 0,_()}).catch(function(e){throw b(e),e})}function c(){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 Ur(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(),c().then(f).then(a).then(s).then(l).catch(function(e){h("batch processing terminated with error",e)})}}function d(e){if(0===q.changes.length)return void(0!==S.length||w||((C&&M.live||x)&&(r.state="pending",r.emit("paused")),x&&p()));(e||x||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",S=[],q={seq:0,changes:[],docs:[]},p(t))}function p(i){T||r.cancelled&&(o.status="cancelled",A)||(o.status=o.status||"complete",o.end_time=new Date,o.last_seq=O,T=!0,i?(i=j(i),i.result=o,"unauthorized"===i.name||"forbidden"===i.name?(r.emit("error",i),r.removeAllListeners()):Gr(n,r,i,function(){Yr(e,t,n,r)})):(r.emit("complete",o),r.removeAllListeners()))}function v(e){if(r.cancelled)return p();I(n)(e)&&(q.seq=e.seq,q.changes.push(e),d(0===S.length&&M.live))}function g(e){if(R=!1,r.cancelled)return p();if(e.results.length>0)M.since=e.last_seq,_(),d(!0);else{var t=function(){C?(M.live=!0,_()):x=!0,d(!0)};w||0!==e.results.length?t():(A=!0,k.writeCheckpoint(e.last_seq,F).then(function(){A=!1,o.last_seq=O=e.last_seq,t()}).catch(b))}}function y(e){if(R=!1,r.cancelled)return p();h("changes rejected",e)}function _(){function t(){i.cancel()}function o(){r.removeListener("cancel",t)}if(!R&&!x&&S.lengthr.since&&!r.cancelled&&(r.since=e.seq,r.onChange(e))}).on("complete",function(){"waiting"===a&&fo(o),a=!1}).on("error",e)}}if(!this._listeners[t]){var i=this,a=!1;this._listeners[t]=o,this.on(e,o)}},S.prototype.removeListener=function(e,t){t in this._listeners&&(uo.EventEmitter.prototype.removeListener.call(this,e,this._listeners[t]),delete this._listeners[t])},S.prototype.notifyLocalWindows=function(e){w()?chrome.storage.local.set({dbName:e}):E()&&(localStorage[e]="a"===localStorage[e]?"b":"a")},S.prototype.notify=function(e){this.emit(e),this.notifyLocalWindows(e)};var Eo;Eo="function"==typeof Object.assign?Object.assign:function(e){for(var t=Object(e),n=1;nt&&s.push(e)}),K(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)})}),Se.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&&Ee(n)}),Se.prototype._compact=function(e,t){function n(e){a.push(o.compactDocument(e.id,0))}function r(e){var n=e.last_seq;vo.all(a).then(function(){return J(o,"_local/compaction",function(e){return(!e.last_seq||e.last_seq1?t.set(e.name,n):t.delete(e.name))}}),e.on("destroyed",function(e){if(t.has(e)){var n=t.get(e);t.delete(e),n.forEach(function(e){e.emit("destroyed",!0)})}})}(Te),Te.adapter=function(e,t,n){t.valid()&&(Te.adapters[e]=t,n&&Te.preferredAdapters.push(e))},Te.plugin=function(e){if("function"==typeof e)e(Te);else{if("object"!=typeof e||0===Object.keys(e).length)throw new Error('Invalid plugin: got "'+e+'", expected an object or a function');Object.keys(e).forEach(function(t){Te.prototype[t]=e[t]})}return this.__defaults&&(Te.__defaults=ko({},this.__defaults)),Te},Te.defaults=function(e){function t(e,n){if(!(this instanceof t))return new t(e,n);n=n||{},e&&"object"==typeof e&&(n=e,e=n.name,delete n.name),n=ko({},t.__defaults,n),Te.call(this,e,n)}return co(t,Te),t.preferredAdapters=Te.preferredAdapters.slice(),Object.keys(Te).forEach(function(e){e in t||(t[e]=Te[e])}),t.__defaults=ko({},this.__defaults,e),t};var Ko=["$or","$nor","$not"],Xo=-324,Go=3,Vo="",Qo={$elemMatch:function(e,t,n,r){return!!Array.isArray(r)&&(0!==r.length&&("object"==typeof r[0]?r.some(function(e){return ot(e,t,Object.keys(t))}):r.some(function(r){return it(t,e,n,r)})))},$allMatch:function(e,t,n,r){return!!Array.isArray(r)&&(0!==r.length&&("object"==typeof r[0]?r.every(function(e){return ot(e,t,Object.keys(t))}):r.every(function(r){return it(t,e,n,r)})))},$eq:function(e,t,n,r){return ct(r)&&0===He(r,t)},$gte:function(e,t,n,r){return ct(r)&&He(r,t)>=0},$gt:function(e,t,n,r){return ct(r)&&He(r,t)>0},$lte:function(e,t,n,r){return ct(r)&&He(r,t)<=0},$lt:function(e,t,n,r){return ct(r)&&He(r,t)<0},$exists:function(e,t,n,r){return t?ct(r):!ct(r)},$mod:function(e,t,n,r){return ut(r)&&ft(r,t)},$ne:function(e,t,n,r){return t.every(function(e){return 0!==He(r,e)})},$in:function(e,t,n,r){return ut(r)&<(r,t)},$nin:function(e,t,n,r){return ut(r)&&!lt(r,t)},$size:function(e,t,n,r){return ut(r)&&ht(r,t)},$all:function(e,t,n,r){return Array.isArray(r)&&dt(r,t)},$regex:function(e,t,n,r){return ut(r)&&pt(r,t)},$type:function(e,t,n,r){return vt(r,t)}};Te.plugin(Oe),Te.plugin(kt),Te.version="6.3.4";var Yo,Zo=St(["_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"]),ei=St(["_attachments","_replication_id","_replication_state","_replication_state_time","_replication_state_reason","_replication_stats"]),ti=function(e){return atob(e)},ni=function(e){return btoa(e)},ri=n.setImmediate||n.setTimeout,oi=32768,ii=5,ai="document-store",si="by-sequence",ui="attach-store",ci="attach-seq-store",fi="meta-store",li="local-store",di="detect-blob-support",hi=new S,pi=!1,vi=[],gi=new mo,yi=new mo;bn.valid=function(){return!("undefined"!=typeof openDatabase&&/(Safari|iPhone|iPad|iPod)/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)&&!/BlackBerry/.test(navigator.platform))&&"undefined"!=typeof indexedDB&&"undefined"!=typeof IDBKeyRange};var _i=function(e){e.adapter("idb",bn,!0)},mi=7,bi=Tn("document-store"),wi=Tn("by-sequence"),Ei=Tn("attach-store"),ki=Tn("local-store"),Si=Tn("metadata-store"),qi=Tn("attach-seq-store"),Ai=new mo,xi=new S,Ti=1,Oi="CREATE INDEX IF NOT EXISTS 'by-seq-deleted-idx' ON "+wi+" (seq, deleted)",ji="CREATE UNIQUE INDEX IF NOT EXISTS 'by-seq-doc-id-rev' ON "+wi+" (doc_id, rev)",Ci="CREATE INDEX IF NOT EXISTS 'doc-winningseq-idx' ON "+bi+" (winningseq)",Li="CREATE INDEX IF NOT EXISTS 'attach-seq-seq-idx' ON "+qi+" (seq)",Ii="CREATE UNIQUE INDEX IF NOT EXISTS 'attach-seq-digest-idx' ON "+qi+" (digest, seq)",Di=wi+".seq = "+bi+".winningseq",Ri=wi+".seq AS seq, "+wi+".deleted AS deleted, "+wi+".json AS data, "+wi+".rev AS rev, "+bi+".json AS metadata";Xn.valid=zn,Xn.use_prefix=!0;var Ni=function(e){e.adapter("websql",Xn,!0)},Bi=function(){try{return new XMLHttpRequest,!0}catch(e){return!1}}(),$i=function(){},Fi=25,Mi=50,Pi=5e3,Ui=1e4,Ji={};lr.valid=function(){return!0};var Hi=function(e){e.adapter("http",lr,!1),e.adapter("https",lr,!1)};co(dr,Error),co(hr,Error),co(pr,Error);var Wi=q.bind(null,"log"),zi=Array.isArray,Ki=JSON.parse;Sr.prototype.add=function(e){return this.promise=this.promise.catch(function(){}).then(function(){return e()}),this.promise},Sr.prototype.finish=function(){return this.promise};var Xi={},Gi=new Sr,Vi=50,Qi={_sum:function(e,t){return Er(t)},_count:function(e,t){return t.length},_stats:function(e,t){return{sum:Er(t),min:Math.min.apply(null,t),max:Math.max.apply(null,t),count:t.length,sumsqr:function(e){for(var t=0,n=0,r=e.length;n0?e.slice(n):e}function u(e){var t=e.value;return t&&"object"==typeof t&&t._id||e.id}function c(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=Ct(n.data,n.content_type)})})}function f(e){return function(t){return e.include_docs&&e.attachments&&e.binary&&c(t),t}}function l(e,t,n,r){var o=t[e];void 0!==o&&(r&&(o=encodeURIComponent(JSON.stringify(o))),n.push(e+"="+o))}function d(e){if(void 0!==e){var t=Number(e);return isNaN(t)||t!==parseInt(e,10)?e:t}}function h(e){return e.group_level=d(e.group_level),e.limit=d(e.limit),e.skip=d(e.skip),e}function p(e){if(e){if("number"!=typeof e)return new dr('Invalid value for integer: "'+e+'"');if(e<0)return new dr('Invalid value for positive integer: "'+e+'"')}}function v(e,t){var n=e.descending?"endkey":"startkey",r=e.descending?"startkey":"endkey";if(void 0!==e[n]&&void 0!==e[r]&&He(e[n],e[r])>0)throw new dr("No rows can match your key range, reverse your start_key and end_key or set {descending : true}");if(t.reduce&&!1!==e.reduce){if(e.include_docs)throw new dr("{include_docs:true} is invalid for reduce");if(e.keys&&e.keys.length>1&&!e.group&&!e.group_level)throw new dr("Multi-key fetches for reduce views must use {group: true}")}["group_level","limit","skip"].forEach(function(t){var n=p(e[t]);if(n)throw n})}function g(e,t,n){var r,o=[],i="GET";if(l("reduce",n,o),l("include_docs",n,o),l("attachments",n,o),l("limit",n,o),l("descending",n,o),l("group",n,o),l("group_level",n,o),l("skip",n,o),l("stale",n,o),l("conflicts",n,o),l("startkey",n,o,!0),l("start_key",n,o,!0),l("endkey",n,o,!0),l("end_key",n,o,!0),l("inclusive_end",n,o),l("key",n,o,!0),o=o.join("&"),o=""===o?"":"?"+o,void 0!==n.keys){var a="keys="+encodeURIComponent(JSON.stringify(n.keys));a.length+o.length+1<=2e3?o+=("?"===o[0]?"&":"?")+a:(i="POST","string"==typeof t?r={keys:n.keys}:t.keys=n.keys)}if("string"==typeof t){var s=Tr(t);return e.request({method:i,url:"_design/"+s[0]+"/_view/"+s[1]+o,body:r}).then(function(e){return e.rows.forEach(function(e){if(e.value&&e.value.error&&"builtin_reduce_error"===e.value.error)throw new Error(e.reason)}),e}).then(f(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(f(n))}function y(e,t,n){return new vo(function(r,o){e._query(t,n,function(e,t){if(e)return o(e);r(t)})})}function _(e){return new vo(function(t,n){e._viewCleanup(function(e,r){if(e)return n(e);t(r)})})}function m(e){return function(t){if(404===t.status)return e;throw t}}function b(e,t,n){function r(e){return e.keys.length?t.db.allDocs({keys:e.keys,include_docs:!0}):vo.resolve({rows:[]})}function o(e,t){for(var n=[],r=new _o,o=0,i=t.rows.length;o0&&0===He(i.key,t)&&a.push(r),n.set(Ke(a),i),t=i.key}return n}var f,l,d=t(e.mapFun,n),h=e.seq||0,p=new Sr;return i().then(function(){return p.finish()}).then(function(){e.seq=h})}function q(e,t,r){0===r.group_level&&delete r.group_level;var o=r.group||r.group_level,a=n(e.reduceFun),u=[],c=isNaN(r.group_level)?Number.POSITIVE_INFINITY:r.group_level;t.forEach(function(e){var t=u[u.length-1],n=o?e.key:null;if(o&&Array.isArray(n)&&(n=n.slice(0,c)),t&&0===He(t.groupKey,n))return t.keys.push([e.key,e.id]),void t.values.push(e.value);u.push({keys:[[e.key,e.id]],values:[e.value],groupKey:n})}),t=[];for(var f=0,l=u.length;fn))return e.doc.value}var r=Ve(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?q(e,n,t):{total_rows:o,offset:a,rows:n},t.include_docs){var s=mr(n.map(u));return e.sourceDB.allDocs({keys:s,include_docs:!0,conflicts:t.conflicts,attachments:t.attachments,binary:t.binary}).then(function(e){var t=new mo;return e.rows.forEach(function(e){t.set(e.id,e.doc)}),n.forEach(function(e){var n=u(e),r=t.get(n);r&&(e.doc=r)}),r})}return r}var o,i=e.reduceFun&&!1!==t.reduce,a=t.skip||0;if(void 0===t.keys||t.keys.length||(t.limit=0,delete t.keys),void 0!==t.keys){var s=t.keys,c=s.map(function(e){return n({startkey:Ke([e]),endkey:Ke([e,{}])})});return vo.all(c).then(D).then(r)}var f,l,d={descending:t.descending};if("start_key"in t&&(f=t.start_key),"startkey"in t&&(f=t.startkey),"end_key"in t&&(l=t.end_key),"endkey"in t&&(l=t.endkey),void 0!==f&&(d.startkey=Ke(t.descending?[f,{}]:[f])),void 0!==l){var h=!1!==t.inclusive_end;t.descending&&(h=!h),d.endkey=Ke(h?[l,{}]:[l])}if(void 0!==t.key){var p=Ke([t.key]),v=Ke([t.key,{}]);d.descending?(d.endkey=p,d.startkey=v):(d.startkey=p,d.endkey=v)}return i||("number"==typeof t.limit&&(d.limit=t.limit),d.skip=a),n(d).then(r)}function T(e){return e.request({method:"POST",url:"_view_cleanup"})}function O(t){return t.get("_local/"+e).then(function(e){var n=new mo;Object.keys(e.views).forEach(function(e){var t=Tr(e),r="_design/"+t[0],o=t[1],i=n.get(r);i||(i=new _o,n.set(r,i)),i.add(o)});var r={keys:br(n),include_docs:!0};return t.allDocs(r).then(function(r){var o={};r.rows.forEach(function(t){var r=t.key.substring(8);n.get(t.key).forEach(function(n){var i=r+"/"+n;e.views[i]||(i=n);var a=Object.keys(e.views[i]),s=t.doc&&t.doc.views&&t.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(e){return _r(E(e),function(){return new t.constructor(e,t.__opts).destroy()})()});return vo.all(a).then(function(){return{ok:!0}})})},m({ok:!0}))}function j(t,n,o){if("function"==typeof t._query)return y(t,n,o);if(B(t))return g(t,n,o);if("string"!=typeof n)return v(o,n),Gi.add(function(){return xr(t,"temp_view/temp_view",n.map,n.reduce,!0,e).then(function(e){return yr(k(e).then(function(){return A(e,o)}),function(){return e.db.destroy()})})}),Gi.finish();var i=n,a=Tr(i),s=a[0],u=a[1];return t.get("_design/"+s).then(function(n){var a=n.views&&n.views[u];if(!a)throw new hr("ddoc "+n._id+" has no view named "+u);return r(n,u),v(o,a),xr(t,i,a.map,a.reduce,!1,e).then(function(e){return"ok"===o.stale||"update_after"===o.stale?("update_after"===o.stale&&fo(function(){k(e)}),A(e,o)):k(e).then(function(){return A(e,o)})})})}function C(e,t,n){var r=this;"function"==typeof t&&(n=t,t={}),t=t?h(t):{},"function"==typeof e&&(e={map:e});var o=vo.resolve().then(function(){return j(r,e,t)});return vr(o,n),o}return{query:C,viewCleanup:gr(function(){var e=this;return"function"==typeof e._viewCleanup?_(e):B(e)?T(e):O(e)})}}("mrviews",Lr,Ir,Dr),Zi={query:Rr,viewCleanup:Nr},ea=1,ta="pouchdb",na=5,ra=0;Hr.prototype.writeCheckpoint=function(e,t){var n=this;return this.updateTarget(e,t).then(function(){return n.updateSource(e,t)})},Hr.prototype.updateTarget=function(e,t){return this.opts.writeTargetCheckpoint?Jr(this.target,this.id,e,t,this.returnValue):vo.resolve(!0)},Hr.prototype.updateSource=function(e,t){if(this.opts.writeSourceCheckpoint){var n=this;return this.readOnlySource?vo.resolve(!0):Jr(this.src,this.id,e,t,this.returnValue).catch(function(e){if(Xr(e))return n.readOnlySource=!0,!0;throw e})}return vo.resolve(!0)};var oa={undefined:function(e,t){return 0===He(e.last_seq,t.last_seq)?t.last_seq:0},1:function(e,t){return Wr(t,e).last_seq}};Hr.prototype.getCheckpoint=function(){var e=this;return e.target.get(e.id).then(function(t){return e.readOnlySource?vo.resolve(t.last_seq):e.src.get(e.id).then(function(e){if(t.version!==e.version)return ra;var n;return n=t.version?t.version.toString():"undefined",n in oa?oa[n](t,e):ra},function(n){if(404===n.status&&t.last_seq)return e.src.put({_id:e.id,last_seq:ra}).then(function(){return ra},function(n){return Xr(n)?(e.readOnlySource=!0,t.last_seq):ra});throw n})}).catch(function(e){if(404!==e.status)throw e;return ra})};var ia=0;co(Zr,uo.EventEmitter),Zr.prototype.cancel=function(){this.cancelled=!0,this.state="cancelled",this.emit("cancel")},Zr.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))},co(ro,uo.EventEmitter),ro.prototype.cancel=function(){this.canceled||(this.canceled=!0,this.push.cancel(),this.pull.cancel())},Te.plugin(_i).plugin(Ni).plugin(Hi).plugin(Zi).plugin(oo),t.exports=Te}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{1:1,10:10,11:11,16:16,2:2,4:4,5:5,6:6,7:7}]},{},[17])(17)});
© 2015 - 2024 Weber Informatics LLC | Privacy Policy