cronapp-framework-mobile-js
Version:
Javascript library for CronApp's projects
2 lines • 62.5 kB
JavaScript
!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.PouchAdapterCordovaSqlite=e()}}(function(){var e;return function(){function e(t,n,r){function i(s,a){if(!n[s]){if(!t[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(o)return o(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var f=n[s]={exports:{}};t[s][0].call(f.exports,function(e){var n=t[s][1][e];return i(n||e)},f,f.exports,e,t,n,r)}return n[s].exports}for(var o="function"==typeof require&&require,s=0;s<r.length;s++)i(r[s]);return i}return e}()({1:[function(e,t,n){var r;r="function"==typeof Object.assign?Object.assign:function(e){for(var t=Object(e),n=1;n<arguments.length;n++){var r=arguments[n];if(null!=r)for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t},t.exports=r},{}],2:[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},{}],3:[function(e,t,n){function r(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function i(e){return"function"==typeof e}function o(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function a(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(!o(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.prototype.emit=function(e){var t,n,r,o,u,c;if(this._events||(this._events={}),"error"===e&&(!this._events.error||s(this._events.error)&&!this._events.error.length)){if((t=arguments[1])instanceof Error)throw t;var f=new Error('Uncaught, unspecified "error" event. ('+t+")");throw f.context=t,f}if(n=this._events[e],a(n))return!1;if(i(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:o=Array.prototype.slice.call(arguments,1),n.apply(this,o)}else if(s(n))for(o=Array.prototype.slice.call(arguments,1),c=n.slice(),r=c.length,u=0;u<r;u++)c[u].apply(this,o);return!0},r.prototype.addListener=function(e,t){var n;if(!i(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,i(t.listener)?t.listener:t),this._events[e]?s(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,s(this._events[e])&&!this._events[e].warned&&(n=a(this._maxListeners)?r.defaultMaxListeners:this._maxListeners)&&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(!i(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,o,a;if(!i(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],o=n.length,r=-1,n===t||i(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(n)){for(a=o;a-- >0;)if(n[a]===t||n[a].listener&&n[a].listener===t){r=a;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],i(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]?i(this._events[e])?[this._events[e]]:this._events[e].slice():[]},r.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(i(t))return 1;if(t)return t.length}return 0},r.listenerCount=function(e,t){return e.listenerCount(t)}},{}],4:[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||i()}var i,o=e.MutationObserver||e.WebKitMutationObserver;if(o){var s=0,a=new o(n),u=e.document.createTextNode("");a.observe(u,{characterData:!0}),i=function(){u.data=s=++s%2}}else if(e.setImmediate||void 0===e.MessageChannel)i="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,i=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:{})},{}],5:[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}},{}],6:[function(e,t,n){"use strict";function r(e,t){var n=t.keys,r={offset:t.skip};return Promise.all(n.map(function(n){var i=_.assign({key:n,deleted:"ok"},t);return["limit","skip","keys"].forEach(function(e){delete i[e]}),new Promise(function(o,s){e._allDocs(i,function(e,i){if(e)return s(e);t.update_seq&&void 0!==i.update_seq&&(r.update_seq=i.update_seq),r.total_rows=i.total_rows,o(i.rows[0]||{key:n,error:"not_found"})})})})).then(function(e){return r.rows=e,r})}function i(e){return e.reduce(function(e,t){return e[t]=!0,e},{})}function o(e){if(!/^\d+-./.test(e))return g.createError(g.INVALID_REV);var t=e.indexOf("-"),n=e.substring(0,t),r=e.substring(t+1);return{prefix:parseInt(n,10),id:r}}function s(e,t){for(var n=e.start-e.ids.length+1,r=e.ids,i=[r[0],t,[]],o=1,s=r.length;o<s;o++)i=[r[o],{status:"missing"},[i]];return[{pos:n,ids:i}]}function a(e,t,n){n||(n={deterministic_revs:!0});var r,i,a,u={status:"available"};if(e._deleted&&(u.deleted=!0),t)if(e._id||(e._id=_.uuid()),i=_.rev(e,n.deterministic_revs),e._rev){if(a=o(e._rev),a.error)return a;e._rev_tree=[{pos:a.prefix,ids:[a.id,{status:"missing"},[[i,u,[]]]]}],r=a.prefix+1}else e._rev_tree=[{pos:1,ids:[i,u,[]]}],r=1;else if(e._revisions&&(e._rev_tree=s(e._revisions,u),r=e._revisions.start,i=e._revisions.ids[0]),!e._rev_tree){if(a=o(e._rev),a.error)return a;r=a.prefix,i=a.id,e._rev_tree=[{pos:r,ids:[i,u,[]]}]}_.invalidIdError(e._id),e._rev=r+"-"+i;var c={metadata:{},data:{}};for(var f in e)if(Object.prototype.hasOwnProperty.call(e,f)){var l="_"===f[0];if(l&&!b[f]){var d=g.createError(g.DOC_VALIDATION,f);throw d.message=g.DOC_VALIDATION.message+": "+f,d}l&&!w[f]?c.metadata[f.slice(1)]=e[f]:c.data[f]=e[f]}return c}function u(e){try{return E.atob(e)}catch(e){var t=g.createError(g.BAD_ARG,"Attachment is not a valid base64 string");return{error:t}}}function c(e,t,n){var r=u(e.data);if(r.error)return n(r.error);e.length=r.length,e.data="blob"===t?E.binaryStringToBlobOrBuffer(r,e.content_type):"base64"===t?E.btoa(r):r,y.binaryMd5(r,function(t){e.digest="md5-"+t,n()})}function f(e,t,n){y.binaryMd5(e.data,function(r){e.digest="md5-"+r,e.length=e.data.size||e.data.length||0,"binary"===t?E.blobOrBufferToBinaryString(e.data,function(t){e.data=t,n()}):"base64"===t?E.blobOrBufferToBase64(e.data,function(t){e.data=t,n()}):n()})}function l(e,t,n){if(e.stub)return n();"string"==typeof e.data?c(e,t,n):f(e,t,n)}function d(e,t,n){function r(){o++,e.length===o&&(i?n(i):n())}if(!e.length)return n();var i,o=0;e.forEach(function(e){function n(e){i=e,++s===o.length&&r()}var o=e.data&&e.data._attachments?Object.keys(e.data._attachments):[],s=0;if(!o.length)return r();for(var a in e.data._attachments)e.data._attachments.hasOwnProperty(a)&&l(e.data._attachments[a],t,n)})}function h(e,t,n,r,i,o,s,u){if(m.revExists(t.rev_tree,n.metadata.rev)&&!u)return r[i]=n,o();var c=t.winningRev||m.winningRev(t),f="deleted"in t?t.deleted:m.isDeleted(t,c),l="deleted"in n.metadata?n.metadata.deleted:m.isDeleted(n.metadata),d=/^1-/.test(n.metadata.rev);if(f&&!l&&u&&d){var h=n.data;h._rev=c,h._id=n.metadata.id,n=a(h,u)}var v=m.merge(t.rev_tree,n.metadata.rev_tree[0],e);if(u&&(f&&l&&"new_leaf"!==v.conflicts||!f&&"new_leaf"!==v.conflicts||f&&!l&&"new_branch"===v.conflicts)){var p=g.createError(g.REV_CONFLICT);return r[i]=p,o()}var _=n.metadata.rev;n.metadata.rev_tree=v.tree,n.stemmedRevs=v.stemmedRevs||[],t.rev_map&&(n.metadata.rev_map=t.rev_map);var E,y=m.winningRev(n.metadata),S=m.isDeleted(n.metadata,y),b=f===S?0:f<S?-1:1;E=_===y?S:m.isDeleted(n.metadata,_),s(n,y,S,E,!0,b,i,o)}function v(e){return"missing"===e.metadata.rev_tree[0].ids[1].status}function p(e,t,n,r,i,o,s,a,u){function c(e,t,n){var r=m.winningRev(e.metadata),i=m.isDeleted(e.metadata,r);if("was_delete"in a&&i)return o[t]=g.createError(g.MISSING_DOC,"deleted"),n();if(l&&v(e)){var u=g.createError(g.REV_CONFLICT);return o[t]=u,n()}s(e,r,i,i,!1,i?0:1,t,n)}function f(){++p===_&&u&&u()}e=e||1e3;var l=a.new_edits,d=new S.Map,p=0,_=t.length;t.forEach(function(e,t){if(e._id&&m.isLocalId(e._id)){var r=e._deleted?"_removeLocal":"_putLocal";return void n[r](e,{ctx:i},function(e,n){o[t]=e||n,f()})}var s=e.metadata.id;d.has(s)?(_--,d.get(s).push([e,t])):d.set(s,[[e,t]])}),d.forEach(function(t,n){function i(){++u<t.length?a():f()}function a(){var a=t[u],f=a[0],d=a[1];if(r.has(n))h(e,r.get(n),f,o,d,i,s,l);else{var v=m.merge([],f.metadata.rev_tree[0],e);f.metadata.rev_tree=v.tree,f.stemmedRevs=v.stemmedRevs||[],c(f,d,i)}}var u=0;a()})}Object.defineProperty(n,"__esModule",{value:!0});var _=e(14),g=e(10),E=e(8),y=e(12),m=e(13),S=e(9),b=i(["_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"]),w=i(["_attachments","_replication_id","_replication_state","_replication_state_time","_replication_state_reason","_replication_stats"]);n.invalidIdError=_.invalidIdError,n.normalizeDdocFunctionName=_.normalizeDdocFunctionName,n.parseDdocFunctionName=_.parseDdocFunctionName,n.isDeleted=m.isDeleted,n.isLocalId=m.isLocalId,n.allDocsKeysQuery=r,n.parseDoc=a,n.preprocessAttachments=d,n.processDocs=p,n.updateDoc=h},{10:10,12:12,13:13,14:14,8:8,9:9}],7:[function(e,t,n){"use strict";function r(e){return decodeURIComponent(escape(e))}function i(e){return e<65?e-48:e-55}function o(e,t,n){for(var r="";t<n;)r+=String.fromCharCode(i(e.charCodeAt(t++))<<4|i(e.charCodeAt(t++)));return r}function s(e,t,n){for(var r="";t<n;)r+=String.fromCharCode(i(e.charCodeAt(t+2))<<12|i(e.charCodeAt(t+3))<<8|i(e.charCodeAt(t))<<4|i(e.charCodeAt(t+1))),t+=4;return r}function a(e,t){return"UTF-8"===t?r(o(e,0,e.length)):s(e,0,e.length)}function u(e){return"'"+e+"'"}function c(e){return e.replace(/\u0002/g,"").replace(/\u0001/g,"").replace(/\u0000/g,"")}function f(e){return e.replace(/\u0001\u0001/g,"\0").replace(/\u0001\u0002/g,"").replace(/\u0002\u0002/g,"")}function l(e){return delete e._id,delete e._rev,JSON.stringify(e)}function d(e,t,n){return e=JSON.parse(e),e._id=t,e._rev=n,e}function h(e){for(var t="(";e--;)t+="?",e&&(t+=",");return t+")"}function v(e,t,n,r,i){return"SELECT "+e+" FROM "+("string"==typeof t?t:t.join(" JOIN "))+(n?" ON "+n:"")+(r?" WHERE "+("string"==typeof r?r:r.join(" AND ")):"")+(i?" ORDER BY "+i:"")}function p(e,t,n){function r(){++o===e.length&&i()}function i(){if(s.length){var e="SELECT DISTINCT digest AS digest FROM "+U+" WHERE seq IN "+h(s.length);n.executeSql(e,s,function(e,t){for(var n=[],r=0;r<t.rows.length;r++)n.push(t.rows.item(r).digest);if(n.length){var i="DELETE FROM "+U+" WHERE seq IN ("+s.map(function(){return"?"}).join(",")+")";e.executeSql(i,s,function(e){var t="SELECT digest FROM "+U+" WHERE digest IN ("+n.map(function(){return"?"}).join(",")+")";e.executeSql(t,n,function(e,t){for(var r=new T.Set,i=0;i<t.rows.length;i++)r.add(t.rows.item(i).digest);n.forEach(function(t){r.has(t)||(e.executeSql("DELETE FROM "+U+" WHERE digest=?",[t]),e.executeSql("DELETE FROM "+C+" WHERE digest=?",[t]))})})})}})}}if(e.length){var o=0,s=[];e.forEach(function(e){var i="SELECT seq FROM "+D+" WHERE doc_id=? AND rev=?";n.executeSql(i,[t,e],function(e,t){if(!t.rows.length)return r();var n=t.rows.item(0).seq;s.push(n),e.executeSql("DELETE FROM "+D+" WHERE seq=?",[n],r)})})}}function _(e){return function(t){I.guardedConsole("error","WebSQL threw an error",t);var n=t&&t.constructor.toString().match(/function ([^(]+)/),r=n&&n[1]||t.type,i=t.target||t.message;e(A.createError(A.WSQ_ERROR,i,r))}}function g(e){return"size"in e?1e6*e.size:"undefined"!=typeof navigator&&/Android/.test(navigator.userAgent)?5e6:1}function E(e,t,n,r,i,o,s){function a(){if(I)return s(I);o.notify(r._name),s(null,N)}function u(e,t){var n="SELECT count(*) as cnt FROM "+C+" WHERE digest=?";w.executeSql(n,[e],function(n,r){if(0===r.rows.item(0).cnt){var i=A.createError(A.MISSING_STUB,"unknown stub attachment with digest "+e);t(i)}else t()})}function f(e){function t(){++i===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,i=0;n.forEach(function(e){u(e,function(e){e&&!r&&(r=e),t()})})}function d(e,t,n,i,o,s,a,u){function c(){function t(e,t){function r(){return++i===o.length&&t(),!1}var i=0,o=Object.keys(n._attachments||{});if(!o.length)return t();for(var s=0;s<o.length;s++)!function(t){var i="INSERT INTO "+U+" (digest, seq) VALUES (?,?)",o=[n._attachments[t].digest,e];w.executeSql(i,o,r,r)}(o[s])}var n=e.data,r=i?1:0,o=n._id,s=n._rev,a=l(n),u="INSERT INTO "+D+" (doc_id, rev, json, deleted) VALUES (?, ?, ?, ?);",c=[o,s,a,r];w.executeSql(u,c,function(e,n){var r=n.insertId;t(r,function(){h(e,r)})},function(){var e=v("seq",D,null,"doc_id=? AND rev=?");return w.executeSql(e,[o,s],function(e,n){var i=n.rows.item(0).seq,u="UPDATE "+D+" SET json=?, deleted=? WHERE doc_id=? AND rev=?;",c=[a,r,o,s];e.executeSql(u,c,function(e){t(i,function(){h(e,i)})})}),!1})}function f(e){_||(e?(_=e,u(_)):g===y.length&&c())}function d(e){g++,f(e)}function h(n,i){var s=e.metadata.id,c=e.stemmedRevs||[];o&&r.auto_compaction&&(c=O.compactTree(e.metadata).concat(c)),c.length&&p(c,s,n),e.metadata.seq=i;var f=e.metadata.rev;delete e.metadata.rev;var l=o?"UPDATE "+L+" SET json=?, max_seq=?, winningseq=(SELECT seq FROM "+D+" WHERE doc_id="+L+".id AND rev=?) WHERE id=?":"INSERT INTO "+L+" (id, winningseq, max_seq, json) VALUES (?,?,?,?);",d=x.safeJsonStringify(e.metadata),h=o?[d,i,t,s]:[s,i,i,d];n.executeSql(l,h,function(){N[a]={ok:!0,id:e.metadata.id,rev:f},R.set(s,e.metadata),u()})}var _=null,g=0;e.data._id=e.metadata.id,e.data._rev=e.metadata.rev;var y=Object.keys(e.data._attachments||{});i&&(e.data._deleted=!0),y.forEach(function(n){var r=e.data._attachments[n];if(r.stub)g++,f();else{var i=r.data;delete r.data,r.revpos=parseInt(t,10);E(r.digest,i,d)}}),y.length||c()}function h(){q.processDocs(e.revs_limit,S,r,R,w,N,d,n)}function g(e){function t(){++n===S.length&&e()}if(!S.length)return e();var n=0;S.forEach(function(e){if(e._id&&q.isLocalId(e._id))return t();var n=e.metadata.id;w.executeSql("SELECT json FROM "+L+" WHERE id = ?",[n],function(e,r){if(r.rows.length){var i=x.safeJsonParse(r.rows.item(0).json);R.set(n,i)}t()})})}function E(e,t,n){var r="SELECT digest FROM "+C+" WHERE digest=?";w.executeSql(r,[e],function(i,o){if(o.rows.length)return n();r="INSERT INTO "+C+" (digest, body, escaped) VALUES (?,?,1)",i.executeSql(r,[e,c(t)],function(){n()},function(){return n(),!1})})}var y=n.new_edits,m=t.docs,S=m.map(function(t){return t._id&&q.isLocalId(t._id)?t:q.parseDoc(t,y,e)}),b=S.filter(function(e){return e.error});if(b.length)return s(b[0]);var w,I,N=new Array(S.length),R=new T.Map;q.preprocessAttachments(S,"binary",function(e){if(e)return s(e);i.transaction(function(e){w=e,f(function(e){e?I=e:g(h)})},_(s),a)})}function y(e){return e.websql(e.name,e.version,e.description,e.size)}function m(e){try{return{db:y(e)}}catch(e){return{error:e}}}function S(e){var t=j.get(e.name);return t||(t=m(e),j.set(e.name,t)),t}function b(e,t,n,r,i){function o(){++u===a.length&&i&&i()}function s(e,i){var s=e._attachments[i],a={binary:t.binary,ctx:r};n._getAttachment(e._id,i,s,a,function(t,n){e._attachments[i]=I.assign(I.pick(s,["digest","content_type"]),{data:n}),o()})}var a=Object.keys(e._attachments||{});if(!a.length)return i&&i();var u=0;a.forEach(function(n){t.attachments&&t.include_docs?s(e,n):(e._attachments[n].stub=!0,o())})}function w(e,t){function n(){I.hasLocalStorage()&&(window.localStorage["_pouch__websqldb_"+K._name]=!0),t(null,K)}function r(e,t){e.executeSql(H),e.executeSql("ALTER TABLE "+D+" ADD COLUMN deleted TINYINT(1) DEFAULT 0",[],function(){e.executeSql(P),e.executeSql("ALTER TABLE "+L+" ADD COLUMN local TINYINT(1) DEFAULT 0",[],function(){e.executeSql("CREATE INDEX IF NOT EXISTS 'doc-store-local-idx' ON "+L+" (local, id)");var n="SELECT "+L+".winningseq AS seq, "+L+".json AS metadata FROM "+D+" JOIN "+L+" ON "+D+".seq = "+L+".winningseq";e.executeSql(n,[],function(e,n){for(var r=[],i=[],o=0;o<n.rows.length;o++){var s=n.rows.item(o),a=s.seq,u=JSON.parse(s.metadata);q.isDeleted(u)&&r.push(a),q.isLocalId(u.id)&&i.push(u.id)}e.executeSql("UPDATE "+L+"SET local = 1 WHERE id IN "+h(i.length),i,function(){e.executeSql("UPDATE "+D+" SET deleted = 1 WHERE seq IN "+h(r.length),r,t)})})})})}function i(e,t){var n="CREATE TABLE IF NOT EXISTS "+B+" (id UNIQUE, rev, json)";e.executeSql(n,[],function(){var n="SELECT "+L+".id AS id, "+D+".json AS data FROM "+D+" JOIN "+L+" ON "+D+".seq = "+L+".winningseq WHERE local = 1";e.executeSql(n,[],function(e,n){function r(){if(!i.length)return t(e);var n=i.shift(),o=JSON.parse(n.data)._rev;e.executeSql("INSERT INTO "+B+" (id, rev, json) VALUES (?,?,?)",[n.id,o,n.data],function(e){e.executeSql("DELETE FROM "+L+" WHERE id=?",[n.id],function(e){e.executeSql("DELETE FROM "+D+" WHERE seq=?",[n.seq],function(){r()})})})}for(var i=[],o=0;o<n.rows.length;o++)i.push(n.rows.item(o));r()})})}function o(e,t){function n(n){function r(){if(!n.length)return t(e);var i=n.shift(),o=a(i.hex,Y),s=o.lastIndexOf("::"),u=o.substring(0,s),c=o.substring(s+2),f="UPDATE "+D+" SET doc_id=?, rev=? WHERE doc_id_rev=?";e.executeSql(f,[u,c,o],function(){r()})}r()}var r="ALTER TABLE "+D+" ADD COLUMN doc_id";e.executeSql(r,[],function(e){var t="ALTER TABLE "+D+" ADD COLUMN rev";e.executeSql(t,[],function(e){e.executeSql(W,[],function(e){var t="SELECT hex(doc_id_rev) as hex FROM "+D;e.executeSql(t,[],function(e,t){for(var r=[],i=0;i<t.rows.length;i++)r.push(t.rows.item(i));n(r)})})})})}function s(e,t){function n(e){var n="SELECT COUNT(*) AS cnt FROM "+C;e.executeSql(n,[],function(e,n){function r(){var n=v(G+", "+L+".id AS id",[L,D],X,null,L+".id ");n+=" LIMIT "+o+" OFFSET "+i,i+=o,e.executeSql(n,[],function(e,n){if(!n.rows.length)return t(e);for(var i={},o=0;o<n.rows.length;o++)for(var s=n.rows.item(o),a=d(s.data,s.id,s.rev),u=Object.keys(a._attachments||{}),c=0;c<u.length;c++){var f=a._attachments[u[c]];!function(e,t){var n=i[e]=i[e]||[];-1===n.indexOf(t)&&n.push(t)}(f.digest,s.seq)}var l=[];if(Object.keys(i).forEach(function(e){i[e].forEach(function(t){l.push([e,t])})}),!l.length)return r();var h=0;l.forEach(function(t){var n="INSERT INTO "+U+" (digest, seq) VALUES (?,?)";e.executeSql(n,t,function(){++h===l.length&&r()})})})}if(!n.rows.item(0).cnt)return t(e);var i=0,o=10;r()})}var r="CREATE TABLE IF NOT EXISTS "+U+" (digest, seq INTEGER)";e.executeSql(r,[],function(e){e.executeSql(V,[],function(e){e.executeSql(J,[],n)})})}function u(e,t){var n="ALTER TABLE "+C+" ADD COLUMN escaped TINYINT(1) DEFAULT 0";e.executeSql(n,[],t)}function c(e,t){var n="ALTER TABLE "+L+" ADD COLUMN max_seq INTEGER";e.executeSql(n,[],function(e){var n="UPDATE "+L+" SET max_seq=(SELECT MAX(seq) FROM "+D+" WHERE doc_id=id)";e.executeSql(n,[],function(e){var n="CREATE UNIQUE INDEX IF NOT EXISTS 'doc-max-seq-idx' ON "+L+" (max_seq)";e.executeSql(n,[],t)})})}function y(e,t){e.executeSql('SELECT HEX("a") AS hex',[],function(e,n){var r=n.rows.item(0).hex;Y=2===r.length?"UTF-8":"UTF-16",t()})}function m(){for(;ee.length>0;){ee.pop()(null,$)}}function w(e,t){if(0===t){var n="CREATE TABLE IF NOT EXISTS "+M+" (dbid, db_version INTEGER)",a="CREATE TABLE IF NOT EXISTS "+C+" (digest UNIQUE, escaped TINYINT(1), body BLOB)",f="CREATE TABLE IF NOT EXISTS "+U+" (digest, seq INTEGER)",l="CREATE TABLE IF NOT EXISTS "+L+" (id unique, json, winningseq, max_seq INTEGER UNIQUE)",d="CREATE TABLE IF NOT EXISTS "+D+" (seq INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, json, deleted TINYINT(1), doc_id, rev)",h="CREATE TABLE IF NOT EXISTS "+B+" (id UNIQUE, rev, json)";e.executeSql(a),e.executeSql(h),e.executeSql(f,[],function(){e.executeSql(J),e.executeSql(V)}),e.executeSql(l,[],function(){e.executeSql(H),e.executeSql(d,[],function(){e.executeSql(P),e.executeSql(W),e.executeSql(n,[],function(){var t="INSERT INTO "+M+" (db_version, dbid) VALUES (?,?)";$=I.uuid();var n=[R,$];e.executeSql(t,n,function(){m()})})})})}else{var v=function(){t<R&&e.executeSql("UPDATE "+M+" SET db_version = "+R);var n="SELECT dbid FROM "+M;e.executeSql(n,[],function(e,t){$=t.rows.item(0).dbid,m()})},p=[r,i,o,s,u,c,v],_=t,g=function(e){p[_-1](e,g),_++};g(e)}}function T(e){var t="SELECT sql FROM sqlite_master WHERE tbl_name = "+M;e.executeSql(t,[],function(e,t){t.rows.length?/db_version/.test(t.rows.item(0).sql)?e.executeSql("SELECT db_version FROM "+M,[],function(e,t){w(e,t.rows.item(0).db_version)}):e.executeSql("ALTER TABLE "+M+" ADD COLUMN db_version INTEGER",[],function(){w(e,1)}):w(e,0)})}function j(e,t){var n="SELECT MAX(seq) AS seq FROM "+D;e.executeSql(n,[],function(e,n){var r=n.rows.item(0).seq||0;t(r)})}function z(e,t){var n=v("COUNT("+L+".id) AS 'num'",[L,D],X,D+".deleted=0");e.executeSql(n,[],function(e,n){t(n.rows.item(0).num)})}function Q(e,t,n,r,i){var o=v(G,[L,D],X,L+".id=?"),s=[t];e.executeSql(o,s,function(e,t){if(!t.rows.length){var o=A.createError(A.MISSING_DOC,"missing");return i(o)}var s=t.rows.item(0),a=x.safeJsonParse(s.metadata);r(O.latest(n,a))})}var Y,K=this,$=null,Z=g(e),ee=[];K._name=e.name;var te=I.assign({},e,{version:k,description:e.name,size:Z}),ne=S(te);if(ne.error)return _(t)(ne.error);var re=ne.db;"function"!=typeof re.readTransaction&&(re.readTransaction=re.transaction),function(){re.transaction(function(e){y(e,function(){T(e)})},_(t),n)}(),K._remote=!1,K.type=function(){return"websql"},K._id=I.toPromise(function(e){e(null,$)}),K._info=function(e){var t,n;re.readTransaction(function(e){j(e,function(e){t=e}),z(e,function(e){n=e})},_(e),function(){e(null,{doc_count:n,update_seq:t,websql_encoding:Y})})},K._bulkDocs=function(t,n,r){E(e,t,n,K,re,F,r)},K._get=function(e,t,n){function r(e){n(e,{doc:i,metadata:o,ctx:s})}var i,o,s=t.ctx;if(!s)return re.readTransaction(function(r){K._get(e,I.assign({ctx:r},t),n)});var a,u;if(t.rev){if(t.latest)return void Q(s,e,t.rev,function(r){t.latest=!1,t.rev=r,K._get(e,t,n)},r);a=v(G,[L,D],L+".id="+D+".doc_id",[D+".doc_id=?",D+".rev=?"]),u=[e,t.rev]}else a=v(G,[L,D],X,L+".id=?"),u=[e];s.executeSql(a,u,function(e,n){if(!n.rows.length){return r(A.createError(A.MISSING_DOC,"missing"))}var s=n.rows.item(0);if(o=x.safeJsonParse(s.metadata),s.deleted&&!t.rev){return r(A.createError(A.MISSING_DOC,"deleted"))}i=d(s.data,o.id,s.rev),r()})},K._allDocs=function(e,t){var n,r,i=[],o="startkey"in e&&e.startkey,s="endkey"in e&&e.endkey,a="key"in e&&e.key,u="keys"in e&&e.keys,c="descending"in e&&e.descending,f="limit"in e?e.limit:-1,l="skip"in e?e.skip:0,h=!1!==e.inclusive_end,p=[],g=[];if(u){var E=[],y="";u.forEach(function(e){-1===E.indexOf(e)&&(E.push(e),y+="?,")}),y=y.substring(0,y.length-1),g.push(L+".id IN ("+y+")"),p=p.concat(E)}else if(!1!==a)g.push(L+".id = ?"),p.push(a);else if(!1!==o||!1!==s){if(!1!==o&&(g.push(L+".id "+(c?"<=":">=")+" ?"),p.push(o)),!1!==s){var m=c?">":"<";h&&(m+="="),g.push(L+".id "+m+" ?"),p.push(s)}!1!==a&&(g.push(L+".id = ?"),p.push(a))}u||g.push(D+".deleted = 0"),re.readTransaction(function(t){if(z(t,function(e){n=e}),e.update_seq&&j(t,function(e){r=e}),0!==f){var o=v(G,[L,D],X,g,L+".id "+(c?"DESC":"ASC"));o+=" LIMIT "+f+" OFFSET "+l,t.executeSql(o,p,function(t,n){for(var r=0,o=n.rows.length;r<o;r++){var s=n.rows.item(r),a=x.safeJsonParse(s.metadata),c=a.id,f=d(s.data,c,s.rev),l=f._rev,h={id:c,key:c,value:{rev:l}};if(e.include_docs){if(h.doc=f,h.doc._rev=l,e.conflicts){var v=O.collectConflicts(a);v.length&&(h.doc._conflicts=v)}b(h.doc,e,K,t)}if(s.deleted){if(!u)continue;h.value.deleted=!0,h.doc=null}if(u){var p=u.indexOf(c,p);do{i[p]=h,p=u.indexOf(c,p+1)}while(p>-1&&p<u.length)}else i.push(h)}u&&u.forEach(function(e,t){i[t]||(i[t]={key:e,error:"not_found"})})})}},_(t),function(){var o={total_rows:n,offset:e.skip,rows:i};e.update_seq&&(o.update_seq=r),t(null,o)})},K._changes=function(e){if(e=I.clone(e),e.continuous){var t=K._name+":"+I.uuid();return F.addListener(K._name,t,K,e),F.notify(K._name),{cancel:function(){F.removeListener(K._name,t)}}}var n=e.descending;e.since=e.since&&!n?e.since:0;var r="limit"in e?e.limit:-1;0===r&&(r=1);var i=[],o=0;!function(){var t=L+".json AS metadata, "+L+".max_seq AS maxSeq, "+D+".json AS winningDoc, "+D+".rev AS winningRev ",s=L+" JOIN "+D,a=L+".id="+D+".doc_id AND "+L+".winningseq="+D+".seq",u=["maxSeq > ?"],c=[e.since];e.doc_ids&&(u.push(L+".id IN "+h(e.doc_ids.length)),c=c.concat(e.doc_ids));var f="maxSeq "+(n?"DESC":"ASC"),l=v(t,s,a,u,f),p=I.filterChange(e);e.view||e.filter||(l+=" LIMIT "+r);var g=e.since||0;re.readTransaction(function(t){t.executeSql(l,c,function(t,n){function s(t){return function(){e.onChange(t)}}for(var a=0,u=n.rows.length;a<u;a++){var c=n.rows.item(a),f=x.safeJsonParse(c.metadata);g=c.maxSeq;var l=d(c.winningDoc,f.id,c.winningRev),h=e.processChange(l,f,e);h.seq=c.maxSeq;var v=p(h);if("object"==typeof v)return e.complete(v);if(v&&(o++,e.return_docs&&i.push(h),e.attachments&&e.include_docs?b(l,e,K,t,s(h)):s(h)()),o===r)break}})},_(e.complete),function(){e.continuous||e.complete(null,{results:i,last_seq:g})})}()},K._close=function(e){e()},K._getAttachment=function(e,t,n,r,i){var o,s=r.ctx,u=n.digest,c=n.content_type,l="SELECT escaped, CASE WHEN escaped = 1 THEN body ELSE HEX(body) END AS body FROM "+C+" WHERE digest=?";s.executeSql(l,[u],function(e,t){var n=t.rows.item(0),s=n.escaped?f(n.body):a(n.body,Y);o=r.binary?N.binaryStringToBlobOrBuffer(s,c):N.btoa(s),i(null,o)})},K._getRevisionTree=function(e,t){re.readTransaction(function(n){var r="SELECT json AS metadata FROM "+L+" WHERE id = ?";n.executeSql(r,[e],function(e,n){if(n.rows.length){var r=x.safeJsonParse(n.rows.item(0).metadata);t(null,r.rev_tree)}else t(A.createError(A.MISSING_DOC))})})},K._doCompaction=function(e,t,n){if(!t.length)return n();re.transaction(function(n){var r="SELECT json AS metadata FROM "+L+" WHERE id = ?";n.executeSql(r,[e],function(n,r){var i=x.safeJsonParse(r.rows.item(0).metadata);O.traverseRevTree(i.rev_tree,function(e,n,r,i,o){var s=n+"-"+r;-1!==t.indexOf(s)&&(o.status="missing")});var o="UPDATE "+L+" SET json = ? WHERE id = ?";n.executeSql(o,[x.safeJsonStringify(i),e])}),p(t,e,n)},_(n),function(){n()})},K._getLocal=function(e,t){re.readTransaction(function(n){var r="SELECT json, rev FROM "+B+" WHERE id=?";n.executeSql(r,[e],function(n,r){if(r.rows.length){var i=r.rows.item(0),o=d(i.json,e,i.rev);t(null,o)}else t(A.createError(A.MISSING_DOC))})})},K._putLocal=function(e,t,n){function r(e){var r,c;o?(r="UPDATE "+B+" SET rev=?, json=? WHERE id=? AND rev=?",c=[i,u,s,o]):(r="INSERT INTO "+B+" (id, rev, json) VALUES (?,?,?)",c=[s,i,u]),e.executeSql(r,c,function(e,r){r.rowsAffected?(a={ok:!0,id:s,rev:i},t.ctx&&n(null,a)):n(A.createError(A.REV_CONFLICT))},function(){return n(A.createError(A.REV_CONFLICT)),!1})}"function"==typeof t&&(n=t,t={}),delete e._revisions;var i,o=e._rev,s=e._id;i=e._rev=o?"0-"+(parseInt(o.split("-")[1],10)+1):"0-1";var a,u=l(e);t.ctx?r(t.ctx):re.transaction(r,_(n),function(){a&&n(null,a)})},K._removeLocal=function(e,t,n){function r(r){var o="DELETE FROM "+B+" WHERE id=? AND rev=?",s=[e._id,e._rev];r.executeSql(o,s,function(r,o){if(!o.rowsAffected)return n(A.createError(A.MISSING_DOC));i={ok:!0,id:e._id,rev:"0-0"},t.ctx&&n(null,i)})}"function"==typeof t&&(n=t,t={});var i;t.ctx?r(t.ctx):re.transaction(r,_(n),function(){i&&n(null,i)})},K._destroy=function(e,t){F.removeAllListeners(K._name),re.transaction(function(e){[L,D,C,M,B,U].forEach(function(t){e.executeSql("DROP TABLE IF EXISTS "+t,[])})},_(t),function(){I.hasLocalStorage()&&(delete window.localStorage["_pouch__websqldb_"+K._name],delete window.localStorage[K._name]),t(null,{ok:!0})})}}var T=e(9),A=e(10),I=e(14),q=e(6),O=e(13),x=e(11),N=e(8),R=7,L=u("document-store"),D=u("by-sequence"),C=u("attach-store"),B=u("local-store"),M=u("metadata-store"),U=u("attach-seq-store"),j=new T.Map,F=new I.changesHandler,k=1,P="CREATE INDEX IF NOT EXISTS 'by-seq-deleted-idx' ON "+D+" (seq, deleted)",W="CREATE UNIQUE INDEX IF NOT EXISTS 'by-seq-doc-id-rev' ON "+D+" (doc_id, rev)",H="CREATE INDEX IF NOT EXISTS 'doc-winningseq-idx' ON "+L+" (winningseq)",J="CREATE INDEX IF NOT EXISTS 'attach-seq-seq-idx' ON "+U+" (seq)",V="CREATE UNIQUE INDEX IF NOT EXISTS 'attach-seq-digest-idx' ON "+U+" (digest, seq)",X=D+".seq = "+L+".winningseq",G=D+".seq AS seq, "+D+".deleted AS deleted, "+D+".json AS data, "+D+".rev AS rev, "+L+".json AS metadata";t.exports=w},{10:10,11:11,13:13,14:14,6:6,8:8,9:9}],8:[function(e,t,n){"use strict";function r(e,t){e=e||[],t=t||{};try{return new Blob(e,t)}catch(o){if("TypeError"!==o.name)throw o;for(var n="undefined"!=typeof BlobBuilder?BlobBuilder:"undefined"!=typeof MSBlobBuilder?MSBlobBuilder:"undefined"!=typeof MozBlobBuilder?MozBlobBuilder:WebKitBlobBuilder,r=new n,i=0;i<e.length;i+=1)r.append(e[i]);return r.getBlob(t.type)}}function i(e){for(var t=e.length,n=new ArrayBuffer(t),r=new Uint8Array(n),i=0;i<t;i++)r[i]=e.charCodeAt(i);return n}function o(e,t){return r([i(e)],{type:t})}function s(e,t){return o(h(e),t)}function a(e){for(var t="",n=new Uint8Array(e),r=n.byteLength,i=0;i<r;i++)t+=String.fromCharCode(n[i]);return t}function u(e,t){var n=new FileReader,r="function"==typeof n.readAsBinaryString;n.onloadend=function(e){var n=e.target.result||"";if(r)return t(n);t(a(n))},r?n.readAsBinaryString(e):n.readAsArrayBuffer(e)}function c(e,t){u(e,function(e){t(e)})}function f(e,t){c(e,function(e){t(v(e))})}function l(e,t){var n=new FileReader;n.onloadend=function(e){var n=e.target.result||new ArrayBuffer(0);t(n)},n.readAsArrayBuffer(e)}function d(){}Object.defineProperty(n,"__esModule",{value:!0});var h=function(e){return atob(e)},v=function(e){return btoa(e)};n.atob=h,n.btoa=v,n.base64StringToBlobOrBuffer=s,n.binaryStringToArrayBuffer=i,n.binaryStringToBlobOrBuffer=o,n.blob=r,n.blobOrBufferToBase64=f,n.blobOrBufferToBinaryString=c,n.readAsArrayBuffer=l,n.readAsBinaryString=u,n.typedBuffer=d},{}],9:[function(e,t,n){"use strict"
;function r(e){return"$"+e}function i(e){return e.substring(1)}function o(){this._store={}}function s(e){if(this._store=new o,e&&Array.isArray(e))for(var t=0,n=e.length;t<n;t++)this.add(e[t])}Object.defineProperty(n,"__esModule",{value:!0}),o.prototype.get=function(e){var t=r(e);return this._store[t]},o.prototype.set=function(e,t){var n=r(e);return this._store[n]=t,!0},o.prototype.has=function(e){return r(e)in this._store},o.prototype.delete=function(e){var t=r(e),n=t in this._store;return delete this._store[t],n},o.prototype.forEach=function(e){for(var t=Object.keys(this._store),n=0,r=t.length;n<r;n++){var o=t[n],s=this._store[o];o=i(o),e(s,o)}},Object.defineProperty(o.prototype,"size",{get:function(){return Object.keys(this._store).length}}),s.prototype.add=function(e){return this._store.set(e,!0)},s.prototype.has=function(e){return this._store.has(e)},s.prototype.forEach=function(e){this._store.forEach(function(t,n){e(n)})},Object.defineProperty(s.prototype,"size",{get:function(){return this._store.size}}),!function(){if("undefined"==typeof Symbol||"undefined"==typeof Map||"undefined"==typeof Set)return!1;var e=Object.getOwnPropertyDescriptor(Map,Symbol.species);return e&&"get"in e&&Map[Symbol.species]===Map}()?(n.Set=s,n.Map=o):(n.Set=Set,n.Map=Map)},{}],10:[function(e,t,n){"use strict";function r(e,t,n){Error.call(this,n),this.status=e,this.name=t,this.message=n,this.error=!0}function i(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=r.prototype,new n(t)}function o(e){if("object"!=typeof e){var t=e;e=v,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}Object.defineProperty(n,"__esModule",{value:!0}),function(e){return e&&"object"==typeof e&&"default"in e?e.default:e}(e(5))(r,Error),r.prototype.toString=function(){return JSON.stringify({status:this.status,name:this.name,message:this.message,reason:this.reason})};var s=new r(401,"unauthorized","Name or password is incorrect."),a=new r(400,"bad_request","Missing JSON list of 'docs'"),u=new r(404,"not_found","missing"),c=new r(409,"conflict","Document update conflict"),f=new r(400,"bad_request","_id field must contain a string"),l=new r(412,"missing_id","_id is required for puts"),d=new r(400,"bad_request","Only reserved document ids may start with underscore."),h=new r(412,"precondition_failed","Database not open"),v=new r(500,"unknown_error","Database encountered an unknown error"),p=new r(500,"badarg","Some query argument is invalid"),_=new r(400,"invalid_request","Request was invalid"),g=new r(400,"query_parse_error","Some query parameter is invalid"),E=new r(500,"doc_validation","Bad special document member"),y=new r(400,"bad_request","Something wrong with the request"),m=new r(400,"bad_request","Document must be a JSON object"),S=new r(404,"not_found","Database not found"),b=new r(500,"indexed_db_went_bad","unknown"),w=new r(500,"web_sql_went_bad","unknown"),T=new r(500,"levelDB_went_went_bad","unknown"),A=new r(403,"forbidden","Forbidden by design doc validate_doc_update function"),I=new r(400,"bad_request","Invalid rev format"),q=new r(412,"file_exists","The database could not be created, the file already exists."),O=new r(412,"missing_stub","A pre-existing attachment stub wasn't found"),x=new r(413,"invalid_url","Provided URL is invalid");n.UNAUTHORIZED=s,n.MISSING_BULK_DOCS=a,n.MISSING_DOC=u,n.REV_CONFLICT=c,n.INVALID_ID=f,n.MISSING_ID=l,n.RESERVED_ID=d,n.NOT_OPEN=h,n.UNKNOWN_ERROR=v,n.BAD_ARG=p,n.INVALID_REQUEST=_,n.QUERY_PARSE_ERROR=g,n.DOC_VALIDATION=E,n.BAD_REQUEST=y,n.NOT_AN_OBJECT=m,n.DB_MISSING=S,n.WSQ_ERROR=w,n.LDB_ERROR=T,n.FORBIDDEN=A,n.INVALID_REV=I,n.FILE_EXISTS=q,n.MISSING_STUB=O,n.IDB_ERROR=b,n.INVALID_URL=x,n.createError=i,n.generateErrorFromResponse=o},{5:5}],11:[function(e,t,n){"use strict";function r(e){try{return JSON.parse(e)}catch(t){return o.parse(e)}}function i(e){try{return JSON.stringify(e)}catch(t){return o.stringify(e)}}Object.defineProperty(n,"__esModule",{value:!0});var o=function(e){return e&&"object"==typeof e&&"default"in e?e.default:e}(e(21));n.safeJsonParse=r,n.safeJsonStringify=i},{21:21}],12:[function(e,t,n){(function(t){"use strict";function r(e){return c.btoa(e)}function i(e,t,n){return e.webkitSlice?e.webkitSlice(t,n):e.slice(t,n)}function o(e,t,n,r,o){(n>0||r<t.size)&&(t=i(t,n,r)),c.readAsArrayBuffer(t,function(t){e.append(t),o()})}function s(e,t,n,r,i){(n>0||r<t.length)&&(t=t.substring(n,r)),e.appendBinary(t),i()}function a(e,t){function n(){l(a)}function i(){var e=_.end(!0),n=r(e);t(n),_.destroy()}function a(){var t=p*h,r=t+h;p++,p<v?g(_,e,t,r,n):g(_,e,t,r,i)}var u="string"==typeof e,c=u?e.length:e.size,h=Math.min(d,c),v=Math.ceil(c/h),p=0,_=u?new f:new f.ArrayBuffer,g=u?s:o;a()}function u(e){return f.hash(e)}Object.defineProperty(n,"__esModule",{value:!0});var c=e(8),f=function(e){return e&&"object"==typeof e&&"default"in e?e.default:e}(e(15)),l=t.setImmediate||t.setTimeout,d=32768;n.binaryMd5=a,n.stringMd5=u}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{15:15,8:8}],13:[function(e,t,n){"use strict";function r(e){for(var t,n,r,i,o=e.rev_tree.slice();i=o.pop();){var s=i.ids,a=s[2],u=i.pos;if(a.length)for(var c=0,f=a.length;c<f;c++)o.push({pos:u+1,ids:a[c]});else{var l=!!s[1].deleted,d=s[0];t&&!(r!==l?r:n!==u?n<u:t<d)||(t=d,n=u,r=l)}}return n+"-"+t}function i(e,t){for(var n,r=e.slice();n=r.pop();)for(var i=n.pos,o=n.ids,s=o[2],a=t(0===s.length,i,o[0],n.ctx,o[1]),u=0,c=s.length;u<c;u++)r.push({pos:i+1,ids:s[u],ctx:a})}function o(e,t){return e.pos-t.pos}function s(e){var t=[];i(e,function(e,n,r,i,o){e&&t.push({rev:n+"-"+r,pos:n,opts:o})}),t.sort(o).reverse();for(var n=0,r=t.length;n<r;n++)delete t[n].pos;return t}function a(e){for(var t=r(e),n=s(e.rev_tree),i=[],o=0,a=n.length;o<a;o++){var u=n[o];u.rev===t||u.opts.deleted||i.push(u.rev)}return i}function u(e){var t=[];return i(e.rev_tree,function(e,n,r,i,o){"available"!==o.status||e||(t.push(n+"-"+r),o.status="missing")}),t}function c(e){for(var t,n=[],r=e.slice();t=r.pop();){var i=t.pos,o=t.ids,s=o[0],a=o[1],u=o[2],c=0===u.length,f=t.history?t.history.slice():[];f.push({id:s,opts:a}),c&&n.push({pos:i+1-f.length,ids:f});for(var l=0,d=u.length;l<d;l++)r.push({pos:i+1,ids:u[l],history:f})}return n.reverse()}function f(e,t){return e.pos-t.pos}function l(e,t,n){for(var r,i=0,o=e.length;i<o;)r=i+o>>>1,n(e[r],t)<0?i=r+1:o=r;return i}function d(e,t,n){var r=l(e,t,n);e.splice(r,0,t)}function h(e,t){for(var n,r,i=t,o=e.length;i<o;i++){var s=e[i],a=[s.id,s.opts,[]];r?(r[2].push(a),r=a):n=r=a}return n}function v(e,t){return e[0]<t[0]?-1:1}function p(e,t){for(var n=[{tree1:e,tree2:t}],r=!1;n.length>0;){var i=n.pop(),o=i.tree1,s=i.tree2;(o[1].status||s[1].status)&&(o[1].status="available"===o[1].status||"available"===s[1].status?"available":"missing");for(var a=0;a<s[2].length;a++)if(o[2][0]){for(var u=!1,c=0;c<o[2].length;c++)o[2][c][0]===s[2][a][0]&&(n.push({tree1:o[2][c],tree2:s[2][a]}),u=!0);u||(r="new_branch",d(o[2],s[2][a],v))}else r="new_leaf",o[2][0]=s[2][a]}return{conflicts:r,tree:e}}function _(e,t,n){var r,i=[],o=!1,s=!1;if(!e.length)return{tree:[t],conflicts:"new_leaf"};for(var a=0,u=e.length;a<u;a++){var c=e[a];if(c.pos===t.pos&&c.ids[0]===t.ids[0])r=p(c.ids,t.ids),i.push({pos:c.pos,ids:r.tree}),o=o||r.conflicts,s=!0;else if(!0!==n){var l=c.pos<t.pos?c:t,d=c.pos<t.pos?t:c,h=d.pos-l.pos,v=[],_=[];for(_.push({ids:l.ids,diff:h,parent:null,parentIdx:null});_.length>0;){var g=_.pop();if(0!==g.diff)for(var E=g.ids[2],y=0,m=E.length;y<m;y++)_.push({ids:E[y],diff:g.diff-1,parent:g.ids,parentIdx:y});else g.ids[0]===d.ids[0]&&v.push(g)}var S=v[0];S?(r=p(S.ids,d.ids),S.parent[2][S.parentIdx]=r.tree,i.push({pos:l.pos,ids:l.ids}),o=o||r.conflicts,s=!0):i.push(c)}else i.push(c)}return s||i.push(t),i.sort(f),{tree:i,conflicts:o||"internal_node"}}function g(e,t){for(var n,r,o=c(e),s=0,a=o.length;s<a;s++){var u,f=o[s],l=f.ids;if(l.length>t){n||(n={});var d=l.length-t;u={pos:f.pos+d,ids:h(l,d)};for(var v=0;v<d;v++){var p=f.pos+v+"-"+l[v].id;n[p]=!0}}else u={pos:f.pos,ids:h(l,0)};r=r?_(r,u,!0).tree:[u]}return n&&i(r,function(e,t,r){delete n[t+"-"+r]}),{tree:r,revs:n?Object.keys(n):[]}}function E(e,t,n){var r=_(e,t),i=g(r.tree,n);return{tree:i.tree,stemmedRevs:i.revs,conflicts:r.conflicts}}function y(e,t){for(var n,r=e.slice(),i=t.split("-"),o=parseInt(i[0],10),s=i[1];n=r.pop();){if(n.pos===o&&n.ids[0]===s)return!0;for(var a=n.ids[2],u=0,c=a.length;u<c;u++)r.push({pos:n.pos+1,ids:a[u]})}return!1}function m(e){return e.ids}function S(e,t){t||(t=r(e));for(var n,i=t.substring(t.indexOf("-")+1),o=e.rev_tree.map(m);n=o.pop();){if(n[0]===i)return!!n[1].deleted;o=o.concat(n[2])}}function b(e){return/^_local/.test(e)}function w(e,t){for(var n,r=t.rev_tree.slice();n=r.pop();){var i=n.pos,o=n.ids,s=o[0],a=o[1],u=o[2],c=0===u.length,f=n.history?n.history.slice():[];if(f.push({id:s,pos:i,opts:a}),c)for(var l=0,d=f.length;l<d;l++){var h=f[l],v=h.pos+"-"+h.id;if(v===e)return i+"-"+s}for(var p=0,_=u.length;p<_;p++)r.push({pos:i+1,ids:u[p],history:f})}throw new Error("Unable to resolve latest revision for id "+t.id+", rev "+e)}Object.defineProperty(n,"__esModule",{value:!0}),n.collectConflicts=a,n.collectLeaves=s,n.compactTree=u,n.isDeleted=S,n.isLocalId=b,n.merge=E,n.revExists=y,n.rootToLeaf=c,n.traverseRevTree=i,n.winningRev=r,n.latest=w},{}],14:[function(e,t,n){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e.default:e}function i(e){return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Blob&&e instanceof Blob}function o(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 o(e);var t=e.size,n=e.type;return"function"==typeof e.slice?e.slice(0,t,n):e.webkitSlice(0,t,n)}function a(e){var t=Object.getPrototypeOf(e);if(null===t)return!0;var n=t.constructor;return"function"==typeof n&&n instanceof n&&z.call(n)==Q}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<r;n++)t[n]=u(e[n]);return t}if(e instanceof Date)return e.toISOString();if(i(e))return s(e);if(!a(e))return e;t={};for(n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var o=u(e[n]);void 0!==o&&(t[n]=o)}return t}function c(e){var t=!1;return F(function(n){if(t)throw new Error("once called more than once");t=!0,e.apply(this,n)})}function f(e){return F(function(t){t=u(t);var n=this,r="function"==typeof t[t.length-1]&&t.pop(),i=new Promise(function(r,i){var o;try{var s=c(function(e,t){e?i(e):r(t)});t.push(s),o=e.apply(n,t),o&&"function"==typeof o.then&&r(o)}catch(e){i(e)}});return r&&i.then(function(e){r(null,e)},r),i})}function l(e,t,n){if(e.constructor.listeners("debug").length){for(var r=["api",e.name,t],i=0;i<n.length-1;i++)r.push(n[i]);e.constructor.emit("debug",r);var o=n[n.length-1];n[n.length-1]=function(n,r){var i=["api",e.name,t];i=i.concat(n?["error",n]:["success",r]),e.constructor.emit("debug",i),o(n,r)}}}function d(e,t){return f(F(function(n){if(this._closed)return Promise.reject(new Error("database is closed"));if(this._destroyed)return Promise.reject(new Error("database is destroyed"));var r=this;return l(r,e,n),this.taskqueue.isReady?t.apply(this,n):new Promise(function(t,i){r.taskqueue.addTask(function(o){o?i(o):t(r[e].apply(r,n))})})}))}function h(e,t){for(var n={},r=0,i=t.length;r<i;r++){var o=t[r];o in e&&(n[o]=e[o])}return n}function v(e){return e}function p(e){return[{ok:e}]}function _(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 i(){++l===f&&r()}function o(e,t,n){d[e]={id:t,docs:n},i()}function s(){if(!(g>=_.length)){var e=Math.min(g+Y,_.length),t=_.slice(g,e);a(t,g),g+=t.length}}function a(n,r){n.forEach(function(n,i){var a=r+i,u=c.get(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(v);var l=v;0===f.open_revs.length&&(delete f.open_revs,l=p),["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),o(a,n,r),s()})})}var u=t.docs,c=new k.Map;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),_=[];c.forEach(function(e,t){_.push(t)});var g=0;s()}function g(){return j}function E(e){g()&&addEventListener("storage",function(t){e.emit(t.key)})}function y(){W.EventEmitter.call(this),this._listeners={},E(this)}function m(e){if("undefined"!=typeof console&&"function"==typeof console[e]){var t=Array.prototype.slice.call(arguments,1);console[e].apply(console,t)}}function S(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 b(e){var t=0;return e||(t=2e3),S(e,t)}function w(e,t){m("info","The above "+e+" is totally normal. "+t)}function T(e,t,n){try{return!e(t,n)}catch(e){var r="Filter function threw: "+e.toString();return J.createError(J.BAD_REQUEST,r)}}function A(e){var t={},n=e.filter&&"function"==typeof e.filter;return t.query=e.query_params,function(r){r.doc||(r.doc={});var i=n&&T(e.filter,r.doc,t);if("object"==typeof i)return i;if(i)return!1;if(e.include_docs){if(!e.attachments)for(var o in r.doc._attachments)r.doc._attachments.hasOwnProperty(o)&&(r.doc._attachments[o].stub=!0)}else delete r.doc;return!0}}function I(e){for(var t=[],n=0,r=e.length;n<r;n++)t=t.concat(e[n]);return t}function q(){}function O(e){var t;if(e?"string"!=typeof e?t=J.createError(J.INVALID_ID):/^_/.test(e)&&!/^_(design|local)/.test(e)&&(t=J.createError(J.RESERVED_ID)):t=J.createError(J.MISSING_ID),t)throw t}function x(e){return"boolean"==typeof e._remote?e._remote:"function"==typeof e.type&&(m("warn","db.type() is deprecated and will be removed in a future version of PouchDB"),"http"===e.type())}function N(e,t){return"listenerCount"in e?e.listenerCount(t):W.EventEmitter.listenerCount(e,t)}function R(e){if(!e)return null;var t=e.split("/");return 2===t.length?t:1===t.length?[e,e]:null}function L(e){var t=R(e);return t?t.join("/"):null}function D(e){for(var t=oe.exec(e),n={},r=14;r--;){var i=ne[r],o=t[r]||"",s=-1!==["user","password"].indexOf(i);n[i]=s?decodeURIComponent(o):o}return n[re]={},n[ne[12]].replace(ie,function(e,t,r){t&&(n[re][t]=r)}),n}function C(e,t){var n=[],r=[];for(var i in t)t.hasOwnProperty(i)&&(n.push(i),r.push(t[i]));return n.push(e),Function.apply(null,n).apply(null,r)}function B(e,t,n){return new Promise(function(r,i){e.get(t,function(o,s){if(o){if(404!==o.status)return i(o);s={}}var a=s._rev,u=n(s);if(!u)return r({updated:!1,rev:a});u._id=t,u._rev=a,r(M(e,u,n))})})}function M(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 B(e,t._id,n)})}function U(e,t){var n=G.clone(e);return t?(delete n._rev_tree,X.stringMd5(JSON.stringify(n))):V.v4().replace(/-/g,"").toLowerCase()}Object.defineProperty(n,"__esModule",{value:!0});var j,F=r(e(2)),k=e(9),P=r(e(4)),W=e(3),H=r(e(5)),J=e(10),V=r(e(16)),X=e(12),G=e(14),z=Function.prototype.toString,Q=z.call(Object),Y=6;try{localStorage.setItem("_pouch_check_localstorage",1),j=!!localStorage.getItem("_pouch_check_localstorage")}catch(e){j=!1}H(y,W.EventEmitter),y.prototype.addListener=function(e,t,n,r){function i(){function e(){s=!1}if(o._listeners[t]){if(s)return void(s="waiting");s=!0;var a=h(r,["style","include_docs","attachments","conflicts","filter","doc_ids","view","since","query_params","binary","return_docs"]);n.changes(a).on("change",function(e){e.seq>r.since&&!r.cancelled&&(r.since=e.seq,r.onChange(e))}).on("complete",function(){"waiting"===s&&P(i),s=!1}).on("error",e)}}if(!this._listeners[t]){var o=this,s=!1;this._listeners[t]=i,this.on(e,i)}},y.prototype.removeListener=function(e,t){t in this._listeners&&(W.EventEmitter.prototype.removeListener.call(this,e,this._listeners[t]),delete this._listeners[t])},y.prototype.notifyLocalWindows=function(e){g()&&(localStorage[e]="a"===localStorage[e]?"b":"a")},y.prototype.notify=function(e){this.emit(e),this.notifyLocalWindows(e)};var K;K="function"==typeof Object.assign?Object.assign:function(e){for(var t=Object(e),n=1;n<arguments.length;n++){var r=arguments[n];if(null!=r)for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t};var $,Z=K,ee=q.name;$=ee?function(e){return e.name}:function(e){var t=e.toString().match(/^\s*function\s*(?:(\S+)\s*)?\(/);return t&&t[1]?t[1]:""};var te=$,ne=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],re="queryKey",ie=/(?:^|&)([^&=]*)=?([^&]*)/g,oe=/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,se=V.v4;n.adapterFun=d,n.assign=Z,n.bulkGetShim=_,n.changesHandler=y,n.clone=u,n.defaultBackOff=b,n.explainError=w,n.filterChange=A,n.flatten=I,n.functionName=te,n.guardedConsole=m,n.hasLocalStorage=g,n.invalidIdError=O,n.isRemote=x,n.listenerCount=N,n.nextTick=P,n.normalizeDdocFunctionName=L,n.once=c,n.parseDdocFunctionName=R,n.parseUri=D,n.pick=h,n.rev=U,n.scopeEval=C,n.toPromise=f,n.upsert=B,n.uuid=se},{10:10,12:12,14:14,16:16,2:2,3:3,4:4,5:5,9:9}],15:[function(t,n,r){!function(t){if("object"==typeof r)n.exports=t();else if("function"==typeof e&&e.amd)e(t);else{var i;try{i=window}catch(e){i=self}i.SparkMD5=t()}}(function(e){"use strict";function t(e,t){var n=e[0],r=e[1],i=e[2],o=e[3];n+=(r&i|~r&o)+t[0]-680876936|0,n=(n<<7|n>>>25)+r|0,o+=(n&r|~n&i)+t[1]-389564586|0,o=(o<<12|o>>>20)+n|0,i+=(o&n|~o&r)+t[2]+606105819|0,i=(i<<17|i>>>15)+o|0,r+=(i&o|~i&n)+t[3