<!DOCTYPE html>
<html ng-app="app">

  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width" />
    <title></title>
    
    <link data-require="ionic@1.0.0-beta.1" data-semver="1.0.0-beta.1" rel="stylesheet" href="http://code.ionicframework.com/nightly/css/ionic.css" />
    <link rel="stylesheet" href="style.css" />
    <script data-require="ionic@1.0.0-beta.1" data-semver="1.0.0-beta.1" src="http://code.ionicframework.com/nightly/js/ionic.bundle.js"></script>
    <!-- cordova script (this will be a 404 during development) -->
    <script src="cordova.js"></script>
    <script src="pouch.js"></script>  
    <script src="app.js"></script>
    
    </head>
<body>
//Header
<ion-nav-bar class="bar-positive">
    <ion-nav-back-button class="button-clear">
        <i class="ion-arrow-left-c"></i> Back
    </ion-nav-back-button>
</ion-nav-bar>
    
    //Tabs

    
  <ion-tabs class="tabs-positive">
      
    <ion-tab icon="ion-ios-list" ui-sref="categories">
      <ion-nav-view name="categories"></ion-nav-view>
    </ion-tab>
      
    <ion-tab icon="ion-ios-search" ui-sref="search">
      <ion-nav-view name="search"></ion-nav-view>
    </ion-tab>
      
    <ion-tab icon="ion-ios-heart" ui-sref="favorites">
      <ion-nav-view name="favorites"></ion-nav-view>
    </ion-tab>
      
  </ion-tabs>


//Template views
  
<script type="text/ng-template" id="search.html">
  <ion-view title="Seach">
    <ion-content padding="true">
       <h2>type your search</h2>
       <p>search results here</p>
    </ion-content>
  </ion-view>
</script>
    
<script type="text/ng-template" id="favorites.html">
  <ion-view title="favorites">
    <ion-content padding="true">
       <h2>Your favorites</h2>
       <p>list of favorites</p>
    </ion-content>
  </ion-view>
</script>
  </body>

</html>
var app = angular.module('app', ['ionic'])
var localDB = new PouchDB("sample_navnedb");
var remoteDB = new PouchDB("https://kandersen.iriscouch.com/sample_navnedb");



//When device is ready

ionic.Platform.ready(function(){
    // will execute when device is ready, or immediately if the device is already ready.
      localDB.sync(remoteDB, {live: true});
});

app.factory('PouchDBListener', ['$rootScope', function($rootScope) {
    $rootScope.names = [];
    localDB.changes({
        continuous: true,
        onChange: function(change) {
            if (!change.deleted) {
                $rootScope.$apply(function() {
                    localDB.get(change.id, function(err, doc) {
                        $rootScope.$apply(function() {
                            if (err) console.log(err);
                            $rootScope.names.push(doc);
                            //$rootScope.$broadcast('add', doc);
                        })
                    });
                })
            } else {
                $rootScope.$apply(function() { 
                    $rootScope.$broadcast('delete', change.id);
                });
            }
        }
    });
 
    return true;
 
}]);

  
app.controller("MyController", function($scope, $ionicPopup, PouchDBListener) {
 
    //$scope.names = [];
    console.log($scope.names)
    
    /*$scope.$on('add', function(event, name) {
        $scope.names.push(name);
    });*/
    
//Favorite click
$scope.addFav = function(favName) {     
        $ionicPopup.alert({
            title: 'Favorite',
            template: favName + ' has been added',
            okText: 'OK'
        })
    }
    
});  

app.config(function($stateProvider, $urlRouterProvider) {
  $urlRouterProvider.otherwise('/categories')

//Tab states
  
$stateProvider.state('search', {
  url: '/search',
  views: {
    search: {
      templateUrl: 'search.html'
    }
  }
})

$stateProvider.state('favorites', {
  url: '/favorites',
  views: {
    favorites: {
      templateUrl: 'favorites.html'
    }
  }
})
  
// category tab and child views
$stateProvider

    .state('categories', {
        abstract: true,
        url: '/categories',
        views: {
            categories: {
                template: '<ion-nav-view></ion-nav-view>'
            }
        }
    })

    .state('categories.index', {
        url: '',
        templateUrl: 'categories.html',
    })
    .state('categories.all', {
        url: '/all',
        templateUrl: 'all.html',
    })      
    .state('categories.arabic', {
        url: '/arabic',
        templateUrl: 'templates/categories/arabic.html'             
    })
    .state('categories.bible', {
        url: '/bible',
        templateUrl: 'templates/categories/bible.html'       
    })
    .state('categories.english', {
        url: '/english',
        templateUrl: 'templates/categories/english.html'       
    })
    .state('categories.famous', {
        url: '/famous',
        templateUrl: 'templates/categories/famous.html'       
    })
    .state('categories.female', {
        url: '/female',
        templateUrl: 'templates/categories/female.html'       
    })
    .state('categories.greekMyth', {
        url: '/greekmyth',
        templateUrl: 'templates/categories/greek_mythology.html'       
    })
    .state('categories.hyphenate', {
        url: '/hyphenate',
        templateUrl: 'templates/categories/hyphenate.html'       
    })
    .state('categories.male', {
        url: '/male',
        templateUrl: 'templates/categories/male.html'       
    })
    .state('categories.nature', {
        url: '/nature',
        templateUrl: 'templates/categories/nature.html'       
    })
    .state('categories.nordicMyth', {
        url: '/nordicmyth',
        templateUrl: 'templates/categories/nordic_mythology.html'       
    })
    .state('categories.royal', {
        url: '/royal',
        templateUrl: 'templates/categories/royal.html'       
    })
    .state('categories.scandinavian', {
        url: '/scandinavian',
        templateUrl: 'templates/categories/scandinavian.html'       
    })
    .state('categories.tale', {
        url: '/tale',
        templateUrl: 'templates/categories/tale.html'       
    })
})
/* Styles go here */

  <ion-view title="All">
    <ion-content padding="true">
        <div class="list" ng-controller="MyController">
              <div class="item item-button-right" ng-repeat="name in names">
                {{name.name}} 
                <button class="button button-clear button-assertive" ng-click="addFav(name.name)">
                  <i class="icon ion-ios-heart-outline"></i>
                </button>
              </div>
        </div>      
    </ion-content>
  </ion-view>
  <ion-view title="Categories">
    <ion-content padding="true">
      <h2>Select a category</h2>
      
    
<div class="row">
  <div class="col"><button ui-sref="categories.all" class="button button-block button-positive">all</button></div>

</div>

    </ion-content>
  </ion-view>
//    PouchDB 3.4.0
//    
//    (c) 2012-2015 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;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.PouchDB=e()}}(function(){var define,module,exports;return function e(t,n,r){function o(s,a){if(!n[s]){if(!t[s]){var c="function"==typeof require&&require;if(!a&&c)return c(s,!0);if(i)return i(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var f=n[s]={exports:{}};t[s][0].call(f.exports,function(e){var n=t[s][1][e];return o(n?n:e)},f,f.exports,e,t,n,r)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;s<r.length;s++)o(r[s]);return o}({1:[function(e,t,n){"use strict";function r(e,t){for(var n=0;n<e.length;n++)if(t(e[n],n)===!0)return e[n];return!1}function o(e){return function(t,n){t||n[0]&&n[0].error?e(t||n[0]):e(null,n.length?n[0]:n)}}function i(e){var t={},n=[];return u.traverseRevTree(e,function(e,r,o,i){var s=r+"-"+o;return e&&(t[s]=0),void 0!==i&&n.push({from:i,to:s}),s}),n.reverse(),n.forEach(function(e){t[e.from]=void 0===t[e.from]?1+t[e.to]:Math.min(t[e.from],1+t[e.to])}),t}function s(e,t,n){var r="limit"in t?t.keys.slice(t.skip,t.limit+t.skip):t.skip>0?t.keys.slice(t.skip):t.keys;if(t.descending&&r.reverse(),!r.length)return e._allDocs({limit:0},n);var o={offset:t.skip};return h.all(r.map(function(n){var r=c.extend(!0,{key:n,deleted:"ok"},t);return["limit","skip","keys"].forEach(function(e){delete r[e]}),new h(function(t,i){e._allDocs(r,function(e,r){return e?i(e):(o.total_rows=r.total_rows,void t(r.rows[0]||{key:n,error:"not_found"}))})})})).then(function(e){return o.rows=e,o})}function a(){var e=this;l.call(this);var t,n=0,r=["change","delete","create","update"];this.on("newListener",function(o){if(~r.indexOf(o)){if(n)return void n++;n++;var i=0;t=this.changes({conflicts:!0,include_docs:!0,continuous:!0,since:"now",onChange:function(t){t.seq<=i||(i=t.seq,e.emit("change",t),t.doc._deleted?e.emit("delete",t):"1"===t.doc._rev.split("-")[0]?e.emit("create",t):e.emit("update",t))}})}}),this.on("removeListener",function(e){~r.indexOf(e)&&(n--,n||t.cancel())})}var c=e(35),u=e(30),f=e(20),l=e(39).EventEmitter,d=e(26),p=e(14),h=c.Promise;c.inherits(a,l),t.exports=a,a.prototype.post=c.adapterFun("post",function(e,t,n){return"function"==typeof t&&(n=t,t={}),"object"!=typeof e||Array.isArray(e)?n(f.error(f.NOT_AN_OBJECT)):void this.bulkDocs({docs:[e]},t,o(n))}),a.prototype.put=c.adapterFun("put",c.getArguments(function(e){var t,n,r,i,s=e.shift(),a="_id"in s;if("object"!=typeof s||Array.isArray(s))return(i=e.pop())(f.error(f.NOT_AN_OBJECT));for(s=c.clone(s);;)if(t=e.shift(),n=typeof t,"string"!==n||a?"string"!==n||!a||"_rev"in s?"object"===n?r=t:"function"===n&&(i=t):s._rev=t:(s._id=t,a=!0),!e.length)break;r=r||{};var u=c.invalidIdError(s._id);return u?i(u):c.isLocalId(s._id)&&"function"==typeof this._putLocal?s._deleted?this._removeLocal(s,i):this._putLocal(s,i):void this.bulkDocs({docs:[s]},r,o(i))})),a.prototype.putAttachment=c.adapterFun("putAttachment",function(e,t,n,r,o,i){function s(e){return e._attachments=e._attachments||{},e._attachments[t]={content_type:o,data:r},a.put(e)}var a=this;return"function"==typeof o&&(i=o,o=r,r=n,n=null),"undefined"==typeof o&&(o=r,r=n,n=null),a.get(e).then(function(e){if(e._rev!==n)throw f.error(f.REV_CONFLICT);return s(e)},function(t){if(t.reason===f.MISSING_DOC.message)return s({_id:e});throw t})}),a.prototype.removeAttachment=c.adapterFun("removeAttachment",function(e,t,n,r){var o=this;o.get(e,function(e,i){return e?void r(e):i._rev!==n?void r(f.error(f.REV_CONFLICT)):i._attachments?(delete i._attachments[t],0===Object.keys(i._attachments).length&&delete i._attachments,void o.put(i,r)):r()})}),a.prototype.remove=c.adapterFun("remove",function(e,t,n,r){var i;"string"==typeof t?(i={_id:e,_rev:t},"function"==typeof n&&(r=n,n={})):(i=e,"function"==typeof t?(r=t,n={}):(r=n,n=t)),n=c.clone(n||{}),n.was_delete=!0;var s={_id:i._id,_rev:i._rev||n.rev};return s._deleted=!0,c.isLocalId(s._id)&&"function"==typeof this._removeLocal?this._removeLocal(i,r):void this.bulkDocs({docs:[s]},n,o(r))}),a.prototype.revsDiff=c.adapterFun("revsDiff",function(e,t,n){function r(e,t){a.has(e)||a.set(e,{missing:[]}),a.get(e).missing.push(t)}function o(t,n){var o=e[t].slice(0);u.traverseRevTree(n,function(e,n,i,s,a){var c=n+"-"+i,u=o.indexOf(c);-1!==u&&(o.splice(u,1),"available"!==a.status&&r(t,c))}),o.forEach(function(e){r(t,e)})}"function"==typeof t&&(n=t,t={}),t=c.clone(t);var i=Object.keys(e);if(!i.length)return n(null,{});var s=0,a=new c.Map;i.map(function(t){this._getRevisionTree(t,function(r,c){if(r&&404===r.status&&"missing"===r.message)a.set(t,{missing:e[t]});else{if(r)return n(r);o(t,c)}if(++s===i.length){var u={};return a.forEach(function(e,t){u[t]=e}),n(null,u)}})},this)}),a.prototype.compactDocument=c.adapterFun("compactDocument",function(e,t,n){var r=this;this._getRevisionTree(e,function(o,s){if(o)return n(o);var a=i(s),c=[],f=[];Object.keys(a).forEach(function(e){a[e]>t&&c.push(e)}),u.traverseRevTree(s,function(e,t,n,r,o){var i=t+"-"+n;"available"===o.status&&-1!==c.indexOf(i)&&f.push(i)}),r._doCompaction(e,f,n)})}),a.prototype.compact=c.adapterFun("compact",function(e,t){"function"==typeof e&&(t=e,e={});var n=this;e=c.clone(e||{}),n.get("_local/compaction")["catch"](function(){return!1}).then(function(r){return"function"==typeof n._compact?(r&&r.last_seq&&(e.last_seq=r.last_seq),n._compact(e,t)):void 0})}),a.prototype._compact=function(e,t){function n(e){s.push(o.compactDocument(e.id,0))}function r(e){var n=e.last_seq;h.all(s).then(function(){return d(o,"_local/compaction",function(e){return!e.last_seq||e.last_seq<n?(e.last_seq=n,e):!1})}).then(function(){t(null,{ok:!0})})["catch"](t)}var o=this,i={returnDocs:!1,last_seq:e.last_seq||0},s=[];o.changes(i).on("change",n).on("complete",r).on("error",t)},a.prototype.get=c.adapterFun("get",function(e,t,n){function o(){var r=[],o=i.length;return o?void i.forEach(function(i){s.get(e,{rev:i,revs:t.revs,attachments:t.attachments},function(e,t){r.push(e?{missing:i}:{ok:t}),o--,o||n(null,r)})}):n(null,r)}if("function"==typeof t&&(n=t,t={}),"string"!=typeof e)return n(f.error(f.INVALID_ID));if(c.isLocalId(e)&&"function"==typeof this._getLocal)return this._getLocal(e,n);var i=[],s=this;if(!t.open_revs)return this._get(e,t,function(e,o){if(t=c.clone(t),e)return n(e);var i=o.doc,a=o.metadata,f=o.ctx;if(t.conflicts){var l=u.collectConflicts(a);l.length&&(i._conflicts=l)}if(c.isDeleted(a,i._rev)&&(i._deleted=!0),t.revs||t.revs_info){var d=u.rootToLeaf(a.rev_tree),p=r(d,function(e){return-1!==e.ids.map(function(e){return e.id}).indexOf(i._rev.split("-")[1])}),h=p.ids.map(function(e){return e.id}).indexOf(i._rev.split("-")[1])+1,v=p.ids.length-h;if(p.ids.splice(h,v),p.ids.reverse(),t.revs&&(i._revisions={start:p.pos+p.ids.length-1,ids:p.ids.map(function(e){return e.id})}),t.revs_info){var _=p.pos+p.ids.length;i._revs_info=p.ids.map(function(e){return _--,{rev:_+"-"+e.id,status:e.opts.status}})}}if(t.local_seq&&(c.info('The "local_seq" option is deprecated and will be removed'),i._local_seq=o.metadata.seq),t.attachments&&i._attachments){var m=i._attachments,g=Object.keys(m).length;if(0===g)return n(null,i);Object.keys(m).forEach(function(e){this._getAttachment(m[e],{encode:!0,ctx:f},function(t,r){var o=i._attachments[e];o.data=r,delete o.stub,delete o.length,--g||n(null,i)})},s)}else{if(i._attachments)for(var y in i._attachments)i._attachments.hasOwnProperty(y)&&(i._attachments[y].stub=!0);n(null,i)}});if("all"===t.open_revs)this._getRevisionTree(e,function(e,t){return e?n(e):(i=u.collectLeaves(t).map(function(e){return e.rev}),void o())});else{if(!Array.isArray(t.open_revs))return n(f.error(f.UNKNOWN_ERROR,"function_clause"));i=t.open_revs;for(var a=0;a<i.length;a++){var l=i[a];if("string"!=typeof l||!/^\d+-/.test(l))return n(f.error(f.INVALID_REV))}o()}}),a.prototype.getAttachment=c.adapterFun("getAttachment",function(e,t,n,r){var o=this;n instanceof Function&&(r=n,n={}),n=c.clone(n),this._get(e,n,function(e,i){return e?r(e):i.doc._attachments&&i.doc._attachments[t]?(n.ctx=i.ctx,void o._getAttachment(i.doc._attachments[t],n,r)):r(f.error(f.MISSING_DOC))})}),a.prototype.allDocs=c.adapterFun("allDocs",function(e,t){if("function"==typeof e&&(t=e,e={}),e=c.clone(e),e.skip="undefined"!=typeof e.skip?e.skip:0,"keys"in e){if(!Array.isArray(e.keys))return t(new TypeError("options.keys must be an array"));var n=["startkey","endkey","key"].filter(function(t){return t in e})[0];if(n)return void t(f.error(f.QUERY_PARSE_ERROR,"Query parameter `"+n+"` is not compatible with multi-get"));if("http"!==this.type())return s(this,e,t)}return this._allDocs(e,t)}),a.prototype.changes=function(e,t){return"function"==typeof e&&(t=e,e={}),new p(this,e,t)},a.prototype.close=c.adapterFun("close",function(e){return this._closed=!0,this._close(e)}),a.prototype.info=c.adapterFun("info",function(e){var t=this;this._info(function(n,r){return n?e(n):(r.db_name=r.db_name||t._db_name,r.auto_compaction=!(!t.auto_compaction||"http"===t.type()),void e(null,r))})}),a.prototype.id=c.adapterFun("id",function(e){return this._id(e)}),a.prototype.type=function(){return"function"==typeof this._type?this._type():this.adapter},a.prototype.bulkDocs=c.adapterFun("bulkDocs",function(e,t,n){if("function"==typeof t&&(n=t,t={}),t=c.clone(t),Array.isArray(e)&&(e={docs:e}),!e||!e.docs||!Array.isArray(e.docs))return n(f.error(f.MISSING_BULK_DOCS));for(var r=0;r<e.docs.length;++r)if("object"!=typeof e.docs[r]||Array.isArray(e.docs[r]))return n(f.error(f.NOT_AN_OBJECT));return e=c.clone(e),"new_edits"in t||(t.new_edits="new_edits"in e?e.new_edits:!0),t.new_edits||"http"===this.type()||e.docs.sort(function(e,t){var n=c.compare(e._id,t._id);if(0!==n)return n;var r=e._revisions?e._revisions.start:0,o=t._revisions?t._revisions.start:0;return c.compare(r,o)}),e.docs.forEach(function(e){e._deleted&&delete e._attachments}),this._bulkDocs(e,t,function(e,r){return e?n(e):(t.new_edits||(r=r.filter(function(e){return e.error})),void n(null,r))})}),a.prototype.registerDependentDatabase=c.adapterFun("registerDependentDatabase",function(e,t){function n(t){return t.dependentDbs=t.dependentDbs||{},t.dependentDbs[e]?!1:(t.dependentDbs[e]=!0,t)}var r=new this.constructor(e,this.__opts||{});d(this,"_local/_pouch_dependentDbs",n,function(e){return e?t(e):t(null,{db:r})})})},{14:14,20:20,26:26,30:30,35:35,39:39}],2:[function(e,t,n){(function(n){"use strict";function r(e){return/^_design/.test(e)?"_design/"+encodeURIComponent(e.slice(8)):/^_local/.test(e)?"_local/"+encodeURIComponent(e.slice(7)):encodeURIComponent(e)}function o(e){return e._attachments&&Object.keys(e._attachments)?l.Promise.all(Object.keys(e._attachments).map(function(t){var n=e._attachments[t];if(n.data&&"string"!=typeof n.data){if(h)return new l.Promise(function(e){l.readAsBinaryString(n.data,function(t){n.data=l.btoa(t),e()})});n.data=n.data.toString("base64")}})):l.Promise.resolve()}function i(e,t){if(/http(s?):/.test(e)){var n=l.parseUri(e);n.remote=!0,(n.user||n.password)&&(n.auth={username:n.user,password:n.password});var r=n.path.replace(/(^\/|\/$)/g,"").split("/");if(n.db=r.pop(),n.path=r.join("/"),t=t||{},t=l.clone(t),n.headers=t.headers||t.ajax&&t.ajax.headers||{},t.auth||n.auth){var o=t.auth||n.auth,i=l.btoa(o.username+":"+o.password);n.headers.Authorization="Basic "+i}return t.headers&&(n.headers=t.headers),n}return{host:"",path:"/",db:e,auth:!1}}function s(e,t){return a(e,e.db+"/"+t)}function a(e,t){if(e.remote){var n=e.path?"/":"";return e.protocol+"://"+e.host+":"+e.port+"/"+e.path+n+t}return"/"+t}function c(e,t){function n(e,t){var n=l.extend(!0,l.clone(y),e);return p(n.method+" "+n.url),l.ajax(n,t)}function c(e){return e.split("/").map(encodeURIComponent).join("/")}var _=this;_.getHost=e.getHost?e.getHost:i;var m=_.getHost(e.name,e),g=s(m,"");_.getUrl=function(){return g},_.getHeaders=function(){return l.clone(m.headers)};var y=e.ajax||{};e=l.clone(e);var b=function(){n({headers:m.headers,method:"PUT",url:g},function(e){e&&401===e.status?n({headers:m.headers,method:"HEAD",url:g},function(e){e?t(e):t(null,_)}):e&&412!==e.status?t(e):t(null,_)})};e.skipSetup||n({headers:m.headers,method:"GET",url:g},function(e){e?404===e.status?(l.explain404("PouchDB is just detecting if the remote DB exists."),b()):t(e):t(null,_)}),_.type=function(){return"http"},_.id=l.adapterFun("id",function(e){n({headers:m.headers,method:"GET",url:a(m,"")},function(t,n){var r=n&&n.uuid?n.uuid+m.db:s(m,"");e(null,r)})}),_.request=l.adapterFun("request",function(e,t){e.headers=m.headers,e.url=s(m,e.url),n(e,t)}),_.compact=l.adapterFun("compact",function(e,t){"function"==typeof e&&(t=e,e={}),e=l.clone(e),n({headers:m.headers,url:s(m,"_compact"),method:"POST"},function(){function n(){_.info(function(r,o){o.compact_running?setTimeout(n,e.interval||200):t(null,{ok:!0})})}"function"==typeof t&&n()})}),_._info=function(e){n({headers:m.headers,method:"GET",url:s(m,"")},function(t,n){t?e(t):(n.host=s(m,""),e(null,n))})},_.get=l.adapterFun("get",function(e,t,o){"function"==typeof t&&(o=t,t={}),t=l.clone(t),void 0===t.auto_encode&&(t.auto_encode=!0);var i=[];t.revs&&i.push("revs=true"),t.revs_info&&i.push("revs_info=true"),t.local_seq&&i.push("local_seq=true"),t.open_revs&&("all"!==t.open_revs&&(t.open_revs=JSON.stringify(t.open_revs)),i.push("open_revs="+t.open_revs)),t.attachments&&i.push("attachments=true"),t.rev&&i.push("rev="+t.rev),t.conflicts&&i.push("conflicts="+t.conflicts),i=i.join("&"),i=""===i?"":"?"+i,t.auto_encode&&(e=r(e));var a={headers:m.headers,method:"GET",url:s(m,e+i)},c=t.ajax||{};l.extend(!0,a,c);var u=e.split("/");(u.length>1&&"_design"!==u[0]&&"_local"!==u[0]||u.length>2&&"_design"===u[0]&&"_local"!==u[0])&&(a.binary=!0),n(a,function(e,t,n){return e?o(e):void o(null,t,n)})}),_.remove=l.adapterFun("remove",function(e,t,o,i){var a;"string"==typeof t?(a={_id:e,_rev:t},"function"==typeof o&&(i=o,o={})):(a=e,"function"==typeof t?(i=t,o={}):(i=o,o=t));var c=a._rev||o.rev;n({headers:m.headers,method:"DELETE",url:s(m,r(a._id))+"?rev="+c},i)}),_.getAttachment=l.adapterFun("getAttachment",function(e,t,n,o){"function"==typeof n&&(o=n,n={}),n=l.clone(n),void 0===n.auto_encode&&(n.auto_encode=!0),n.auto_encode&&(e=r(e)),n.auto_encode=!1,_.get(e+"/"+c(t),n,o)}),_.removeAttachment=l.adapterFun("removeAttachment",function(e,t,o,i){var a=s(m,r(e)+"/"+c(t))+"?rev="+o;n({headers:m.headers,method:"DELETE",url:a},i)}),_.putAttachment=l.adapterFun("putAttachment",function(e,t,o,i,a,u){"function"==typeof a&&(u=a,a=i,i=o,o=null),"undefined"==typeof a&&(a=i,i=o,o=null);var f=r(e)+"/"+c(t),p=s(m,f);if(o&&(p+="?rev="+o),"string"==typeof i){var _;try{_=l.atob(i)}catch(g){return u(d.error(d.BAD_ARG,"Attachments need to be base64 encoded"))}i=h?l.createBlob([l.fixBinary(_)],{type:a}):_?new v(_,"binary"):""}var y={headers:l.clone(m.headers),method:"PUT",url:p,processData:!1,body:i,timeout:6e4};y.headers["Content-Type"]=a,n(y,u)}),_.put=l.adapterFun("put",l.getArguments(function(e){var t,i,a,c=e.shift(),u="_id"in c,f=e.pop();return"object"!=typeof c||Array.isArray(c)?f(d.error(d.NOT_AN_OBJECT)):(c=l.clone(c),void o(c).then(function(){for(;;)if(t=e.shift(),i=typeof t,"string"!==i||u?"string"!==i||!u||"_rev"in c?"object"===i&&(a=l.clone(t)):c._rev=t:(c._id=t,u=!0),!e.length)break;a=a||{};var o=l.invalidIdError(c._id);if(o)throw o;var d=[];a&&"undefined"!=typeof a.new_edits&&d.push("new_edits="+a.new_edits),d=d.join("&"),""!==d&&(d="?"+d),n({headers:m.headers,method:"PUT",url:s(m,r(c._id))+d,body:c},function(e,t){return e?f(e):(t.ok=!0,void f(null,t))})})["catch"](f))})),_.post=l.adapterFun("post",function(e,t,n){return"function"==typeof t&&(n=t,t={}),t=l.clone(t),"object"!=typeof e?n(d.error(d.NOT_AN_OBJECT)):("_id"in e||(e._id=l.uuid()),void _.put(e,t,function(e,t){return e?n(e):(t.ok=!0,void n(null,t))}))}),_._bulkDocs=function(e,t,r){"undefined"!=typeof t.new_edits&&(e.new_edits=t.new_edits),l.Promise.all(e.docs.map(o)).then(function(){n({headers:m.headers,method:"POST",url:s(m,"_bulk_docs"),body:e},function(e,t){return e?r(e):(t.forEach(function(e){e.ok=!0}),void r(null,t))})})["catch"](r)},_.allDocs=l.adapterFun("allDocs",function(e,t){"function"==typeof e&&(t=e,e={}),e=l.clone(e);var r,o=[],i="GET";if(e.conflicts&&o.push("conflicts=true"),e.descending&&o.push("descending=true"),e.include_docs&&o.push("include_docs=true"),e.attachments&&o.push("attachments=true"),e.key&&o.push("key="+encodeURIComponent(JSON.stringify(e.key))),e.startkey&&o.push("startkey="+encodeURIComponent(JSON.stringify(e.startkey))),e.endkey&&o.push("endkey="+encodeURIComponent(JSON.stringify(e.endkey))),"undefined"!=typeof e.inclusive_end&&o.push("inclusive_end="+!!e.inclusive_end),"undefined"!=typeof e.limit&&o.push("limit="+e.limit),"undefined"!=typeof e.skip&&o.push("skip="+e.skip),o=o.join("&"),""!==o&&(o="?"+o),"undefined"!=typeof e.keys){var a="keys="+encodeURIComponent(JSON.stringify(e.keys));a.length+o.length+1<=f?o+=(-1!==o.indexOf("?")?"&":"?")+a:(i="POST",r=JSON.stringify({keys:e.keys}))}n({headers:m.headers,method:i,url:s(m,"_all_docs"+o),body:r},t)}),_._changes=function(e){var t="batch_size"in e?e.batch_size:u;e=l.clone(e),e.timeout=e.timeout||3e4;var r={timeout:e.timeout-5e3},o="undefined"!=typeof e.limit?e.limit:!1;0===o&&(o=1);var i;i="returnDocs"in e?e.returnDocs:!0;var a=o;if(e.style&&(r.style=e.style),(e.include_docs||e.filter&&"function"==typeof e.filter)&&(r.include_docs=!0),e.attachments&&(r.attachments=!0),e.continuous&&(r.feed="longpoll"),e.conflicts&&(r.conflicts=!0),e.descending&&(r.descending=!0),e.filter&&"string"==typeof e.filter&&(r.filter=e.filter,"_view"===e.filter&&e.view&&"string"==typeof e.view&&(r.view=e.view)),e.query_params&&"object"==typeof e.query_params)for(var c in e.query_params)e.query_params.hasOwnProperty(c)&&(r[c]=e.query_params[c]);var p,h="GET";if(e.doc_ids){r.filter="_doc_ids";var v=JSON.stringify(e.doc_ids);v.length<f?r.doc_ids=v:(h="POST",p={doc_ids:e.doc_ids})}if(e.continuous&&_._useSSE)return _.sse(e,r,i);var g,y,b=function(i,c){if(!e.aborted){r.since=i,"object"==typeof r.since&&(r.since=JSON.stringify(r.since)),e.descending?o&&(r.limit=a):r.limit=!o||a>t?t:a;var u="?"+Object.keys(r).map(function(e){return e+"="+r[e]}).join("&"),f={headers:m.headers,method:h,url:s(m,"_changes"+u),timeout:e.timeout,body:p};y=i,e.aborted||(g=n(f,c))}},E=10,w=0,S={results:[]},T=function(n,r){if(!e.aborted){var s=0;if(r&&r.results){s=r.results.length,S.last_seq=r.last_seq;var c={};c.query=e.query_params,r.results=r.results.filter(function(t){a--;var n=l.filterChange(e)(t);return n&&(i&&S.results.push(t),l.call(e.onChange,t)),n})}else if(n)return e.aborted=!0,void l.call(e.complete,n);r&&r.last_seq&&(y=r.last_seq);var u=o&&0>=a||r&&t>s||e.descending;if((!e.continuous||o&&0>=a)&&u)l.call(e.complete,null,S);else{n?w+=1:w=0;var f=1<<w,p=E*f,h=e.maximumWait||3e4;if(p>h)return void l.call(e.complete,n||d.error(d.UNKNOWN_ERROR));setTimeout(function(){b(y,T)},p)}}};return b(e.since||0,T),{cancel:function(){e.aborted=!0,g&&g.abort()}}},_.sse=function(e,t,n){function r(t){var r=JSON.parse(t.data);n&&u.results.push(r),u.last_seq=r.seq,l.call(e.onChange,r)}function o(t){return c.removeEventListener("message",r,!1),d===!1?(_._useSSE=!1,void(f=_._changes(e))):(c.close(),void l.call(e.complete,t))}t.feed="eventsource",t.since=e.since||0,t.limit=e.limit,delete t.timeout;var i="?"+Object.keys(t).map(function(e){return e+"="+t[e]}).join("&"),a=s(m,"_changes"+i),c=new EventSource(a),u={results:[],last_seq:!1},f=!1,d=!1;return c.addEventListener("message",r,!1),c.onopen=function(){d=!0},c.onerror=o,{cancel:function(){return f?f.cancel():(c.removeEventListener("message",r,!1),void c.close())}}},_._useSSE=!1,_.revsDiff=l.adapterFun("revsDiff",function(e,t,r){"function"==typeof t&&(r=t,t={}),n({headers:m.headers,method:"POST",url:s(m,"_revs_diff"),body:JSON.stringify(e)},r)}),_._close=function(e){e()},_.destroy=l.adapterFun("destroy",function(e){n({url:s(m,""),method:"DELETE",headers:m.headers},function(t,n){t?(_.emit("error",t),e(t)):(_.emit("destroyed"),e(null,n))})})}var u=25,f=1800,l=e(35),d=e(20),p=e(41)("pouchdb:http"),h="undefined"==typeof n||n.browser,v=e(19);c.destroy=l.toPromise(function(e,t,n){var r=i(e,t);t=t||{},"function"==typeof t&&(n=t,t={}),t=l.clone(t),t.headers=r.headers,t.method="DELETE",t.url=s(r,"");var o=t.ajax||{};t=l.extend({},t,o),l.ajax(t,n)}),c.valid=function(){return!0},t.exports=c}).call(this,e(40))},{19:19,20:20,35:35,40:40,41:41}],3:[function(e,t,n){"use strict";function r(e,t,n,r,o){try{if(e&&t)return o?IDBKeyRange.bound(t,e,!n,!1):IDBKeyRange.bound(e,t,!1,!n);if(e)return o?IDBKeyRange.upperBound(e):IDBKeyRange.lowerBound(e);if(t)return o?IDBKeyRange.lowerBound(t,!n):IDBKeyRange.upperBound(t,!n);if(r)return IDBKeyRange.only(r)}catch(i){return{error:i}}return null}function o(e,t,n,r){return"DataError"===n.name&&0===n.code?r(null,{total_rows:e._meta.docCount,offset:t.skip,rows:[]}):void r(a.error(a.IDB_ERROR,n.name,n.message))}function i(e,t,n,i){function a(e,i){function a(t,n,r){var o=t.id+"::"+r;L.get(o).onsuccess=function(r){n.doc=p(r.target.result),e.conflicts&&(n.doc._conflicts=s.collectConflicts(t)),v(n.doc,e,R)}}function c(t,n,r){var o={id:r.id,key:r.id,value:{rev:n}},i=r.deleted;if("ok"===e.deleted)N.push(o),i?(o.value.deleted=!0,o.doc=null):e.include_docs&&a(r,o,n);else if(!i&&S--<=0&&(N.push(o),e.include_docs&&a(r,o,n),0===--T))return;t["continue"]()}function u(e){j=t._meta.docCount;var n=e.target.result;if(n){var r=h(n.value),o=r.winningRev;c(n,o,r)}}function g(){i(null,{total_rows:j,offset:e.skip,rows:N})}function y(){e.attachments?_(N).then(g):g()}var b="startkey"in e?e.startkey:!1,E="endkey"in e?e.endkey:!1,w="key"in e?e.key:!1,S=e.skip||0,T="number"==typeof e.limit?e.limit:-1,A=e.inclusive_end!==!1,x="descending"in e&&e.descending?"prev":null,O=r(b,E,A,w,x);if(O&&O.error)return o(t,e,O.error,i);var k=[d,l];e.attachments&&k.push(f);var q=m(n,k,"readonly");if(q.error)return i(q.error);var R=q.txn,D=R.objectStore(d),C=R.objectStore(l),I=x?D.openCursor(O,x):D.openCursor(O),L=C.index("_doc_id_rev"),N=[],j=0;R.oncomplete=y,I.onsuccess=u}function c(e,n){return 0===e.limit?n(null,{total_rows:t._meta.docCount,offset:e.skip,rows:[]}):void a(e,n)}c(e,i)}var s=e(30),a=e(20),c=e(7),u=e(6),f=u.ATTACH_STORE,l=u.BY_SEQ_STORE,d=u.DOC_STORE,p=c.decodeDoc,h=c.decodeMetadata,v=c.fetchAttachmentsIfNecessary,_=c.postProcessAttachments,m=c.openTransactionSafely;t.exports=i},{20:20,30:30,6:6,7:7}],4:[function(e,t,n){"use strict";function r(e,t){return new o.Promise(function(n,r){var i=o.createBlob([""],{type:"image/png"});e.objectStore(s).put(i,"key"),e.oncomplete=function(){var e=t.transaction([s],"readwrite"),i=e.objectStore(s).get("key");i.onerror=r,i.onsuccess=function(e){var t=e.target.result,r=URL.createObjectURL(t);o.ajax({url:r,cache:!0,binary:!0},function(e,t){e&&405===e.status?n(!0):(n(!(!t||"image/png"!==t.type)),e&&404===e.status&&o.explain404("PouchDB is just detecting blob URL support.")),URL.revokeObjectURL(r)})}}})["catch"](function(){return!1})}var o=e(35),i=e(6),s=i.DETECT_BLOB_SUPPORT_STORE;t.exports=r},{35:35,6:6}],5:[function(e,t,n){"use strict";function r(e,t,n,r,s,a){function y(){var e=[l,f,u,p,d,c],t=g(r,e,"readwrite");return t.error?a(t.error):(D=t.txn,D.onerror=m(a),D.ontimeout=m(a),D.oncomplete=w,C=D.objectStore(l),I=D.objectStore(f),L=D.objectStore(u),N=D.objectStore(c),void T(function(e){return e?(V=!0,a(e)):void E()}))}function b(){o.processDocs(B,n,H,D,J,A,t)}function E(){function e(){++n===B.length&&b()}function t(t){var n=v(t.target.result);n&&H.set(n.id,n),e()}if(B.length)for(var n=0,r=0,i=B.length;i>r;r++){var s=B[r];if(s._id&&o.isLocalId(s._id))e();else{var a=C.get(s.metadata.id);a.onsuccess=t}}}function w(){V||(s.notify(n._meta.name),n._meta.docCount+=F,a(null,J))}function S(e,t){var n=L.get(e);n.onsuccess=function(n){if(n.target.result)t();else{var r=i.error(i.MISSING_STUB,"unknown stub attachment with digest "+e);r.status=412,t(r)}}}function T(e){function t(){++o===n.length&&e(r)}var n=[];if(B.forEach(function(e){e.data&&e.data._attachments&&Object.keys(e.data._attachments).forEach(function(t){var r=e.data._attachments[t];r.stub&&n.push(r.digest)})}),!n.length)return e();var r,o=0;n.forEach(function(e){S(e,function(e){e&&!r&&(r=e),t()})})}function A(e,t,n,r,o,i,s,a){F+=i;var c=e.data;c._id=e.metadata.id,c._rev=e.metadata.rev,r&&(c._deleted=!0);var u=c._attachments&&Object.keys(c._attachments).length;return u?k(e,t,n,o,s,a):void O(e,t,n,o,s,a)}function x(e){var t=o.compactTree(e.metadata);h(t,e.metadata.id,D)}function O(e,t,r,o,i,s){function a(i){o&&n.auto_compaction&&x(e),l.seq=i.target.result,delete l.rev;var s=_(l,t,r),a=C.put(s);a.onsuccess=u}function c(e){e.preventDefault(),e.stopPropagation();var t=I.index("_doc_id_rev"),n=t.getKey(f._doc_id_rev);n.onsuccess=function(e){var t=I.put(f,e.target.result);t.onsuccess=a}}function u(){J[i]={ok:!0,id:l.id,rev:t},H.set(e.metadata.id,e.metadata),q(e,l.seq,s)}var f=e.data,l=e.metadata;f._doc_id_rev=l.id+"::"+l.rev,delete f._id,delete f._rev;var d=I.put(f);d.onsuccess=a,d.onerror=c}function k(e,t,n,r,o,i){function s(){u===f.length&&O(e,t,n,r,o,i)}function a(){u++,s()}var c=e.data,u=0,f=Object.keys(c._attachments);f.forEach(function(t){var n=e.data._attachments[t];if(n.stub)u++,s();else{var r=n.data;delete n.data;var o=n.digest;R(o,r,a)}})}function q(e,t,n){function r(){++i===s.length&&n()}function o(n){var o=e.data._attachments[n].digest,i=N.put({seq:t,digestSeq:o+"::"+t});i.onsuccess=r,i.onerror=function(e){e.preventDefault(),e.stopPropagation(),r()}}var i=0,s=Object.keys(e.data._attachments||{});if(!s.length)return n();for(var a=0;a<s.length;a++)o(s[a])}function R(e,t,n){var r=L.count(e);r.onsuccess=function(r){var o=r.target.result;if(o)return n();var i={digest:e,body:t},s=L.put(i);s.onsuccess=n}}for(var D,C,I,L,N,j,B=e.docs,F=0,P=0,M=B.length;M>P;P++){var U=B[P];U._id&&o.isLocalId(U._id)||(U=B[P]=o.parseDoc(U,t.new_edits),U.error&&!j&&(j=U))}if(j)return a(j);var J=new Array(B.length),H=new o.Map,V=!1,G=n._meta.blobSupport?"blob":"base64";o.preprocessAttachments(B,G,function(e){return e?a(e):void y()})}var o=e(35),i=e(20),s=e(7),a=e(6),c=a.ATTACH_AND_SEQ_STORE,u=a.ATTACH_STORE,f=a.BY_SEQ_STORE,l=a.DOC_STORE,d=a.LOCAL_STORE,p=a.META_STORE,h=s.compactRevs,v=s.decodeMetadata,_=s.encodeMetadata,m=s.idbError,g=s.openTransactionSafely;t.exports=r},{20:20,35:35,6:6,7:7}],6:[function(e,t,n){"use strict";n.ADAPTER_VERSION=5,n.DOC_STORE="document-store",n.BY_SEQ_STORE="by-sequence",n.ATTACH_STORE="attach-store",n.ATTACH_AND_SEQ_STORE="attach-seq-store",n.META_STORE="meta-store",n.LOCAL_STORE="local-store",n.DETECT_BLOB_SUPPORT_STORE="detect-blob-support"},{}],7:[function(e,t,n){(function(t){"use strict";function r(e,t,n){try{e.apply(t,n)}catch(r){"undefined"!=typeof PouchDB&&PouchDB.emit("error",r)}}var o=e(20),i=e(35),s=e(6);n.taskQueue={running:!1,queue:[]},n.applyNext=function(){if(!n.taskQueue.running&&n.taskQueue.queue.length){n.taskQueue.running=!0;var e=n.taskQueue.queue.shift();e.action(function(o,i){r(e.callback,this,[o,i]),n.taskQueue.running=!1,t.nextTick(n.applyNext)})}},n.idbError=function(e){return function(t){var n=t.target&&t.target.error&&t.target.error.name||t.target;e(o.error(o.IDB_ERROR,n,t.type))}},n.encodeMetadata=function(e,t,n){return{data:i.safeJsonStringify(e),winningRev:t,deletedOrLocal:n?"1":"0",seq:e.seq,id:e.id}},n.decodeMetadata=function(e){if(!e)return null;var t=i.safeJsonParse(e.data);return t.winningRev=e.winningRev,t.deleted="1"===e.deletedOrLocal,t.seq=e.seq,t},n.decodeDoc=function(e){if(!e)return e;var t=i.lastIndexOf(e._doc_id_rev,":");return e._id=e._doc_id_rev.substring(0,t-1),e._rev=e._doc_id_rev.substring(t+1),delete e._doc_id_rev,e},n.readBlobData=function(e,t,n,r){n?e?"string"!=typeof e?i.readAsBinaryString(e,function(e){r(i.btoa(e))}):r(e):r(""):e?"string"!=typeof e?r(e):(e=i.fixBinary(atob(e)),r(i.createBlob([e],{type:t}))):r(i.createBlob([""],{type:t}))},n.fetchAttachmentsIfNecessary=function(e,t,n,r){function o(){++c===a.length&&r&&r()}function i(e,t){var r=e._attachments[t],i=r.digest,a=n.objectStore(s.ATTACH_STORE).get(i);a.onsuccess=function(e){r.body=e.target.result.body,o()}}var a=Object.keys(e._attachments||{});if(!a.length)return r&&r();var c=0;a.forEach(function(n){t.attachments&&t.include_docs?i(e,n):(e._attachments[n].stub=!0,o())})},n.postProcessAttachments=function(e){return i.Promise.all(e.map(function(e){if(e.doc&&e.doc._attachments){var t=Object.keys(e.doc._attachments);return i.Promise.all(t.map(function(t){var r=e.doc._attachments[t];if("body"in r){var o=r.body,s=r.content_type;return new i.Promise(function(a){n.readBlobData(o,s,!0,function(n){e.doc._attachments[t]=i.extend(i.pick(r,["digest","content_type"]),{data:n}),a()})})}}))}}))},n.compactRevs=function(e,t,n){function r(){f--,f||o()}function o(){i.length&&i.forEach(function(e){var t=u.index("digestSeq").count(IDBKeyRange.bound(e+"::",e+"::￿",!1,!1));t.onsuccess=function(t){var n=t.target.result;n||c["delete"](e)}})}var i=[],a=n.objectStore(s.BY_SEQ_STORE),c=n.objectStore(s.ATTACH_STORE),u=n.objectStore(s.ATTACH_AND_SEQ_STORE),f=e.length;e.forEach(function(e){var n=a.index("_doc_id_rev"),o=t+"::"+e;n.getKey(o).onsuccess=function(e){var t=e.target.result;if("number"!=typeof t)return r();a["delete"](t);var n=u.index("seq").openCursor(IDBKeyRange.only(t));n.onsuccess=function(e){var t=e.target.result;if(t){var n=t.value.digestSeq.split("::")[0];i.push(n),u["delete"](t.primaryKey),t["continue"]()}else r()}}})},n.openTransactionSafely=function(e,t,n){try{return{txn:e.transaction(t,n)}}catch(r){return{error:r}}}}).call(this,e(40))},{20:20,35:35,40:40,6:6}],8:[function(e,t,n){(function(n){"use strict";function r(e,t){var n=this;C.queue.push({action:function(t){o(n,e,t)},callback:t}),S()}function o(e,t,o){function i(e){var t=e.createObjectStore(b,{keyPath:"id"});e.createObjectStore(g,{autoIncrement:!0}).createIndex("_doc_id_rev","_doc_id_rev",{unique:!0}),e.createObjectStore(m,{keyPath:"digest"}),e.createObjectStore(w,{keyPath:"id",autoIncrement:!1}),e.createObjectStore(y),t.createIndex("deletedOrLocal","deletedOrLocal",{unique:!1}),e.createObjectStore(E,{keyPath:"_id"});var n=e.createObjectStore(_,{autoIncrement:!0});n.createIndex("seq","seq"),n.createIndex("digestSeq","digestSeq",{unique:!0})}function f(e,t){var n=e.objectStore(b);n.createIndex("deletedOrLocal","deletedOrLocal",{unique:!1}),n.openCursor().onsuccess=function(e){var r=e.target.result;if(r){var o=r.value,i=a.isDeleted(o);o.deletedOrLocal=i?"1":"0",n.put(o),r["continue"]()}else t()}}function l(e){e.createObjectStore(E,{keyPath:"_id"}).createIndex("_doc_id_rev","_doc_id_rev",{unique:!0})}function S(e,t){var n=e.objectStore(E),r=e.objectStore(b),o=e.objectStore(g),i=r.openCursor();i.onsuccess=function(e){var i=e.target.result;if(i){var s=i.value,u=s.id,f=a.isLocalId(u),l=c.winningRev(s);if(f){var d=u+"::"+l,p=u+"::",h=u+"::~",v=o.index("_doc_id_rev"),_=IDBKeyRange.bound(p,h,!1,!1),m=v.openCursor(_);m.onsuccess=function(e){if(m=e.target.result){var t=m.value;t._doc_id_rev===d&&n.put(t),o["delete"](m.primaryKey),m["continue"]()}else r["delete"](i.primaryKey),i["continue"]()}}else i["continue"]()}else t&&t()}}function C(e){var t=e.createObjectStore(_,{autoIncrement:!0});t.createIndex("seq","seq"),t.createIndex("digestSeq","digestSeq",{unique:!0})}function N(e,t){var n=e.objectStore(g),r=e.objectStore(m),o=e.objectStore(_),i=r.count();i.onsuccess=function(e){var r=e.target.result;return r?void(n.openCursor().onsuccess=function(e){var n=e.target.result;if(!n)return t();for(var r=n.value,i=n.primaryKey,s=Object.keys(r._attachments||{}),a={},c=0;c<s.length;c++){var u=r._attachments[s[c]];a[u.digest]=!0}var f=Object.keys(a);for(c=0;c<f.length;c++){var l=f[c];o.put({seq:i,digestSeq:l+"::"+i})}n["continue"]()}):t()}}function j(e){function t(e){return e.data?x(e):(e.deleted="1"===e.deletedOrLocal,e)}var n=e.objectStore(g),r=e.objectStore(b),o=r.openCursor();

o.onsuccess=function(e){function o(){var e=a.id+"::",t=a.id+"::￿",r=n.index("_doc_id_rev").openCursor(IDBKeyRange.bound(e,t)),o=0;r.onsuccess=function(e){var t=e.target.result;if(!t)return a.seq=o,i();var n=t.primaryKey;n>o&&(o=n),t["continue"]()}}function i(){var e=O(a,a.winningRev,a.deleted),t=r.put(e);t.onsuccess=function(){s["continue"]()}}var s=e.target.result;if(s){var a=t(s.value);return a.winningRev=a.winningRev||c.winningRev(a),a.seq?i():void o()}}}var B=t.name,F=null;e._meta=null,e.type=function(){return"idb"},e._id=a.toPromise(function(t){t(null,e._meta.instanceId)}),e._bulkDocs=function(t,n,o){d(t,n,e,F,r.Changes,o)},e._get=function(e,t,n){function r(){n(s,{doc:o,metadata:i,ctx:c})}var o,i,s,c;if(t=a.clone(t),t.ctx)c=t.ctx;else{var f=I(F,[b,g,m],"readonly");if(f.error)return n(f.error);c=f.txn}c.objectStore(b).get(e).onsuccess=function(e){if(i=x(e.target.result),!i)return s=u.error(u.MISSING_DOC,"missing"),r();if(a.isDeleted(i)&&!t.rev)return s=u.error(u.MISSING_DOC,"deleted"),r();var n=c.objectStore(g),f=t.rev||i.winningRev,l=i.id+"::"+f;n.index("_doc_id_rev").get(l).onsuccess=function(e){return o=e.target.result,o&&(o=A(o)),o?void r():(s=u.error(u.MISSING_DOC,"missing"),r())}}},e._getAttachment=function(e,t,n){var r;if(t=a.clone(t),t.ctx)r=t.ctx;else{var o=I(F,[b,g,m],"readonly");if(o.error)return n(o.error);r=o.txn}var i=e.digest,s=e.content_type;r.objectStore(m).get(i).onsuccess=function(e){var r=e.target.result.body;D(r,s,t.encode,function(e){n(null,e)})}},e._info=function(t){if(null===F||!L[B]){var n=new Error("db isn't open");return n.id="idbNull",t(n)}var r,o,i=I(F,[g],"readonly");if(i.error)return t(i.error);var s=i.txn,a=s.objectStore(g).openCursor(null,"prev");a.onsuccess=function(t){var n=t.target.result;r=n?n.key:0,o=e._meta.docCount},s.oncomplete=function(){t(null,{doc_count:o,update_seq:r,idb_attachment_format:e._meta.blobSupport?"binary":"base64"})}},e._allDocs=function(t,n){p(t,e,F,n)},e._changes=function(t){function n(e){function n(){return a.seq!==s?e["continue"]():(l=s,a.winningRev===i._rev?o(i):void r())}function r(){var e=i._id+"::"+a.winningRev,t=v.index("_doc_id_rev").openCursor(IDBKeyRange.bound(e,e+"￿"));t.onsuccess=function(e){o(A(e.target.result.value))}}function o(n){var r=t.processChange(n,a,t);r.seq=a.seq,w(r)&&(E++,p&&y.push(r),t.attachments&&t.include_docs?k(n,t,h,function(){R([r]).then(function(){t.onChange(r)})}):t.onChange(r)),E!==d&&e["continue"]()}var i=A(e.value),s=e.key;if(u&&!u.has(i._id))return e["continue"]();var a;return(a=S.get(i._id))?n():void(_.get(i._id).onsuccess=function(e){a=x(e.target.result),S.set(i._id,a),n()})}function o(e){var t=e.target.result;t&&n(t)}function i(){var e=[b,g];t.attachments&&e.push(m);var n=I(F,e,"readonly");if(n.error)return t.complete(n.error);h=n.txn,h.onerror=q(t.complete),h.oncomplete=s,v=h.objectStore(g),_=h.objectStore(b);var r;r=f?v.openCursor(null,f):v.openCursor(IDBKeyRange.lowerBound(t.since,!0)),r.onsuccess=o}function s(){function e(){t.complete(null,{results:y,last_seq:l})}!t.continuous&&t.attachments?R(y).then(e):e()}if(t=a.clone(t),t.continuous){var c=B+":"+a.uuid();return r.Changes.addListener(B,c,e,t),r.Changes.notify(B),{cancel:function(){r.Changes.removeListener(B,c)}}}var u=t.doc_ids&&new a.Set(t.doc_ids),f=t.descending?"prev":null;t.since=t.since||0;var l=t.since,d="limit"in t?t.limit:-1;0===d&&(d=1);var p;p="returnDocs"in t?t.returnDocs:!0;var h,v,_,y=[],E=0,w=a.filterChange(t),S=new a.Map;i()},e._close=function(e){return null===F?e(u.error(u.NOT_OPEN)):(F.close(),delete L[B],F=null,void e())},e._getRevisionTree=function(e,t){var n=I(F,[b],"readonly");if(n.error)return t(n.error);var r=n.txn,o=r.objectStore(b).get(e);o.onsuccess=function(e){var n=x(e.target.result);n?t(null,n.rev_tree):t(u.error(u.MISSING_DOC))}},e._doCompaction=function(e,t,n){var r=[b,g,m,_],o=I(F,r,"readwrite");if(o.error)return n(o.error);var i=o.txn,s=i.objectStore(b);s.get(e).onsuccess=function(n){var r=x(n.target.result);c.traverseRevTree(r.rev_tree,function(e,n,r,o,i){var s=n+"-"+r;-1!==t.indexOf(s)&&(i.status="missing")}),T(t,e,i);var o=r.winningRev,s=r.deleted;i.objectStore(b).put(O(r,o,s))},i.onerror=q(n),i.oncomplete=function(){a.call(n)}},e._getLocal=function(e,t){var n=I(F,[E],"readonly");if(n.error)return t(n.error);var r=n.txn,o=r.objectStore(E).get(e);o.onerror=q(t),o.onsuccess=function(e){var n=e.target.result;n?(delete n._doc_id_rev,t(null,n)):t(u.error(u.MISSING_DOC))}},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,s=t.ctx;if(!s){var a=I(F,[E],"readwrite");if(a.error)return n(a.error);s=a.txn,s.onerror=q(n),s.oncomplete=function(){i&&n(null,i)}}var c,f=s.objectStore(E);r?(c=f.get(o),c.onsuccess=function(o){var s=o.target.result;if(s&&s._rev===r){var a=f.put(e);a.onsuccess=function(){i={ok:!0,id:e._id,rev:e._rev},t.ctx&&n(null,i)}}else n(u.error(u.REV_CONFLICT))}):(c=f.add(e),c.onerror=function(e){n(u.error(u.REV_CONFLICT)),e.preventDefault(),e.stopPropagation()},c.onsuccess=function(){i={ok:!0,id:e._id,rev:e._rev},t.ctx&&n(null,i)})},e._removeLocal=function(e,t){var n=I(F,[E],"readwrite");if(n.error)return t(n.error);var r,o=n.txn;o.oncomplete=function(){r&&t(null,r)};var i=e._id,s=o.objectStore(E),a=s.get(i);a.onerror=q(t),a.onsuccess=function(n){var o=n.target.result;o&&o._rev===e._rev?(s["delete"](i),r={ok:!0,id:i,rev:"0-0"}):t(u.error(u.MISSING_DOC))}};var P=L[B];if(P)return F=P.idb,e._meta=P.global,void n.nextTick(function(){o(null,e)});var M=indexedDB.open(B,v);"openReqList"in r||(r.openReqList={}),r.openReqList[B]=M,M.onupgradeneeded=function(e){function t(){var e=o[s-1];s++,e&&e(r,t)}var n=e.target.result;if(e.oldVersion<1)return i(n);var r=e.currentTarget.transaction;e.oldVersion<3&&l(n),e.oldVersion<4&&C(n);var o=[f,S,N,j],s=e.oldVersion;t()},M.onsuccess=function(t){F=t.target.result,F.onversionchange=function(){F.close(),delete L[B]},F.onabort=function(){F.close(),delete L[B]};var n=F.transaction([w,y,b],"readwrite"),r=n.objectStore(w).get(w),i=null,c=null,u=null;r.onsuccess=function(t){var r=function(){null!==i&&null!==c&&null!==u&&(e._meta={name:B,instanceId:u,blobSupport:i,docCount:c},L[B]={idb:F,global:e._meta},o(null,e))},f=t.target.result||{id:w};B+"_id"in f?(u=f[B+"_id"],r()):(u=a.uuid(),f[B+"_id"]=u,n.objectStore(w).put(f).onsuccess=function(){r()}),s||(s=h(n,F)),s.then(function(e){i=e,r()});var l=n.objectStore(b).index("deletedOrLocal");l.count(IDBKeyRange.only("0")).onsuccess=function(e){c=e.target.result,r()}}},M.onerror=q(o)}function i(e,t,n){"openReqList"in r||(r.openReqList={}),r.Changes.removeAllListeners(e),r.openReqList[e]&&r.openReqList[e].result&&(r.openReqList[e].result.close(),delete L[e]);var o=indexedDB.deleteDatabase(e);o.onsuccess=function(){r.openReqList[e]&&(r.openReqList[e]=null),a.hasLocalStorage()&&e in localStorage&&delete localStorage[e],n(null,{ok:!0})},o.onerror=q(n)}var s,a=e(35),c=e(30),u=e(20),f=e(7),l=e(6),d=e(5),p=e(3),h=e(4),v=l.ADAPTER_VERSION,_=l.ATTACH_AND_SEQ_STORE,m=l.ATTACH_STORE,g=l.BY_SEQ_STORE,y=l.DETECT_BLOB_SUPPORT_STORE,b=l.DOC_STORE,E=l.LOCAL_STORE,w=l.META_STORE,S=f.applyNext,T=f.compactRevs,A=f.decodeDoc,x=f.decodeMetadata,O=f.encodeMetadata,k=f.fetchAttachmentsIfNecessary,q=f.idbError,R=f.postProcessAttachments,D=f.readBlobData,C=f.taskQueue,I=f.openTransactionSafely,L={};r.valid=function(){var e="undefined"!=typeof openDatabase&&/(Safari|iPhone|iPad|iPod)/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent);return!e&&"undefined"!=typeof indexedDB&&"undefined"!=typeof IDBKeyRange},r.destroy=a.toPromise(function(e,t,n){C.queue.push({action:function(n){i(e,t,n)},callback:n}),S()}),r.Changes=new a.Changes,t.exports=r}).call(this,e(40))},{20:20,3:3,30:30,35:35,4:4,40:40,5:5,6:6,7:7}],9:[function(e,t,n){t.exports=["idb","websql"]},{}],10:[function(e,t,n){"use strict";function r(e,t,n,r,a,_){function m(){return q?_(q):(a.notify(n._name),n._docCount=-1,void _(null,R))}function g(e,t){var n="SELECT count(*) as cnt FROM "+f+" WHERE digest=?";k.executeSql(n,[e],function(n,r){if(0===r.rows.item(0).cnt){var o=i.error(i.MISSING_STUB,"unknown stub attachment with digest "+e);t(o)}else t()})}function y(e){function t(){++o===n.length&&e(r)}var n=[];if(x.forEach(function(e){e.data&&e.data._attachments&&Object.keys(e.data._attachments).forEach(function(t){var r=e.data._attachments[t];r.stub&&n.push(r.digest)})}),!n.length)return e();var r,o=0;n.forEach(function(e){g(e,function(e){e&&!r&&(r=e),t()})})}function b(e,t,r,i,s,a,f,v){function _(){function t(e,t){function r(){return++i===s.length&&t(),!1}function o(t){var o="INSERT INTO "+l+" (digest, seq) VALUES (?,?)",i=[n._attachments[t].digest,e];k.executeSql(o,i,r,r)}var i=0,s=Object.keys(n._attachments||{});if(!s.length)return t();for(var a=0;a<s.length;a++)o(s[a])}var n=e.data,r=i?1:0,o=n._id,s=n._rev,a=p(n),c="INSERT INTO "+u+" (doc_id, rev, json, deleted) VALUES (?, ?, ?, ?);",f=[o,s,a,r];k.executeSql(c,f,function(e,n){var r=n.insertId;t(r,function(){b(e,r)})},function(){var e=d("seq",u,null,"doc_id=? AND rev=?");return k.executeSql(e,[o,s],function(e,n){var i=n.rows.item(0).seq,c="UPDATE "+u+" SET json=?, deleted=? WHERE doc_id=? AND rev=?;",f=[a,r,o,s];e.executeSql(c,f,function(e){t(i,function(){b(e,i)})})}),!1})}function m(e){E||(e?(E=e,v(E)):w===T.length&&_())}function g(e){w++,m(e)}function y(){if(s&&n.auto_compaction){var t=e.metadata.id,r=o.compactTree(e.metadata);h(r,t,k)}}function b(n,r){y(),e.metadata.seq=r,delete e.metadata.rev;var i=s?"UPDATE "+c+" SET json=?, max_seq=?, winningseq=(SELECT seq FROM "+u+" WHERE doc_id="+c+".id AND rev=?) WHERE id=?":"INSERT INTO "+c+" (id, winningseq, max_seq, json) VALUES (?,?,?,?);",a=o.safeJsonStringify(e.metadata),l=e.metadata.id,d=s?[a,r,t,l]:[l,r,r,a];n.executeSql(i,d,function(){R[f]={ok:!0,id:e.metadata.id,rev:t},D.set(l,e.metadata),v()})}var E=null,w=0;e.data._id=e.metadata.id,e.data._rev=e.metadata.rev;var T=Object.keys(e.data._attachments||{});i&&(e.data._deleted=!0),T.forEach(function(t){var n=e.data._attachments[t];if(n.stub)w++,m();else{var r=n.data;delete n.data;var o=n.digest;S(o,r,g)}}),T.length||_()}function E(){o.processDocs(x,n,D,k,R,b,t)}function w(e){function t(){++n===x.length&&e()}if(!x.length)return e();var n=0;x.forEach(function(e){if(e._id&&o.isLocalId(e._id))return t();var n=e.metadata.id;k.executeSql("SELECT json FROM "+c+" WHERE id = ?",[n],function(e,r){if(r.rows.length){var i=o.safeJsonParse(r.rows.item(0).json);D.set(n,i)}t()})})}function S(e,t,n){var r="SELECT digest FROM "+f+" WHERE digest=?";k.executeSql(r,[e],function(o,i){return i.rows.length?n():(r="INSERT INTO "+f+" (digest, body, escaped) VALUES (?,?,1)",void o.executeSql(r,[e,s.escapeBlob(t)],function(){n()},function(){return n(),!1}))})}var T=t.new_edits,A=e.docs,x=A.map(function(e){if(e._id&&o.isLocalId(e._id))return e;var t=o.parseDoc(e,T);return t}),O=x.filter(function(e){return e.error});if(O.length)return _(O[0]);var k,q,R=new Array(x.length),D=new o.Map;o.preprocessAttachments(x,"binary",function(e){return e?_(e):void r.transaction(function(e){k=e,y(function(e){e?q=e:w(E)})},v(_),m)})}var o=e(35),i=e(20),s=e(12),a=e(11),c=a.DOC_STORE,u=a.BY_SEQ_STORE,f=a.ATTACH_STORE,l=a.ATTACH_AND_SEQ_STORE,d=s.select,p=s.stringifyDoc,h=s.compactRevs,v=s.unknownError;t.exports=r},{11:11,12:12,20:20,35:35}],11:[function(e,t,n){"use strict";function r(e){return"'"+e+"'"}n.ADAPTER_VERSION=7,n.DOC_STORE=r("document-store"),n.BY_SEQ_STORE=r("by-sequence"),n.ATTACH_STORE=r("attach-store"),n.LOCAL_STORE=r("local-store"),n.META_STORE=r("metadata-store"),n.ATTACH_AND_SEQ_STORE=r("attach-seq-store")},{}],12:[function(e,t,n){"use strict";function r(e){return e.replace(/\u0002/g,"").replace(/\u0001/g,"").replace(/\u0000/g,"")}function o(e){return e.replace(/\u0001\u0001/g,"\x00").replace(/\u0001\u0002/g,"").replace(/\u0002\u0002/g,"")}function i(e){return delete e._id,delete e._rev,JSON.stringify(e)}function s(e,t,n){return e=JSON.parse(e),e._id=t,e._rev=n,e}function a(e){for(var t="(";e--;)t+="?",e&&(t+=",");return t+")"}function c(e,t,n,r,o){return"SELECT "+e+" FROM "+("string"==typeof t?t:t.join(" JOIN "))+(n?" ON "+n:"")+(r?" WHERE "+("string"==typeof r?r:r.join(" AND ")):"")+(o?" ORDER BY "+o:"")}function u(e,t,n){function r(){++i===e.length&&o()}function o(){if(s.length){var e="SELECT DISTINCT digest AS digest FROM "+b+" WHERE seq IN "+a(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 o="DELETE FROM "+b+" WHERE seq IN ("+s.map(function(){return"?"}).join(",")+")";e.executeSql(o,s,function(e){var t="SELECT digest FROM "+b+" WHERE digest IN ("+n.map(function(){return"?"}).join(",")+")";e.executeSql(t,n,function(e,t){for(var r=new v.Set,o=0;o<t.rows.length;o++)r.add(t.rows.item(o).digest);n.forEach(function(t){r.has(t)||(e.executeSql("DELETE FROM "+b+" WHERE digest=?",[t]),e.executeSql("DELETE FROM "+y+" WHERE digest=?",[t]))})})})}})}}if(e.length){var i=0,s=[];e.forEach(function(e){var o="SELECT seq FROM "+g+" WHERE doc_id=? AND rev=?";n.executeSql(o,[t,e],function(e,t){if(!t.rows.length)return r();var n=t.rows.item(0).seq;s.push(n),e.executeSql("DELETE FROM "+g+" WHERE seq=?",[n],r)})})}}function f(e){return function(t){var n=t&&t.constructor.toString().match(/function ([^\(]+)/),r=n&&n[1]||t.type,o=t.target||t.message;e(_.error(_.WSQ_ERROR,o,r))}}function l(e){if("size"in e)return 1e6*e.size;var t=/Android/.test(window.navigator.userAgent);return t?5e6:1}function d(){return"undefined"!=typeof sqlitePlugin?sqlitePlugin.openDatabase.bind(sqlitePlugin):"undefined"!=typeof openDatabase?function(e){return openDatabase(e.name,e.version,e.description,e.size)}:void 0}function p(e){var t=d(),n=E[e.name];return n||(n=E[e.name]=t(e),n._sqlitePlugin="undefined"!=typeof sqlitePlugin),n}function h(){return"undefined"!=typeof openDatabase||"undefined"!=typeof SQLitePlugin}var v=e(35),_=e(20),m=e(11),g=m.BY_SEQ_STORE,y=m.ATTACH_STORE,b=m.ATTACH_AND_SEQ_STORE,E={};t.exports={escapeBlob:r,unescapeBlob:o,stringifyDoc:i,unstringifyDoc:s,qMarks:a,select:c,compactRevs:u,unknownError:f,getSize:l,openDB:p,valid:h}},{11:11,20:20,35:35}],13:[function(e,t,n){"use strict";function r(e,t,n,r,o){function s(){++u===c.length&&o&&o()}function a(e,t){var o=e._attachments[t],a={encode:!0,ctx:r};n._getAttachment(o,a,function(n,r){e._attachments[t]=i.extend(i.pick(o,["digest","content_type"]),{data:r}),s()})}var c=Object.keys(e._attachments||{});if(!c.length)return o&&o();var u=0;c.forEach(function(n){t.attachments&&t.include_docs?a(e,n):(e._attachments[n].stub=!0,s())})}function o(e,t){function n(){i.hasLocalStorage()&&(window.localStorage["_pouch__websqldb_"+K._name]=!0),t(null,K)}function u(e,t){e.executeSql(R),e.executeSql("ALTER TABLE "+h+" ADD COLUMN deleted TINYINT(1) DEFAULT 0",[],function(){e.executeSql(k),e.executeSql("ALTER TABLE "+p+" ADD COLUMN local TINYINT(1) DEFAULT 0",[],function(){e.executeSql("CREATE INDEX IF NOT EXISTS 'doc-store-local-idx' ON "+p+" (local, id)");var n="SELECT "+p+".winningseq AS seq, "+p+".json AS metadata FROM "+h+" JOIN "+p+" ON "+h+".seq = "+p+".winningseq";e.executeSql(n,[],function(e,n){for(var r=[],o=[],s=0;s<n.rows.length;s++){var a=n.rows.item(s),c=a.seq,u=JSON.parse(a.metadata);i.isDeleted(u)&&r.push(c),i.isLocalId(u.id)&&o.push(u.id)}e.executeSql("UPDATE "+p+"SET local = 1 WHERE id IN "+y(o.length),o,function(){e.executeSql("UPDATE "+h+" SET deleted = 1 WHERE seq IN "+y(r.length),r,t)})})})})}function N(e,t){var n="CREATE TABLE IF NOT EXISTS "+_+" (id UNIQUE, rev, json)";e.executeSql(n,[],function(){var n="SELECT "+p+".id AS id, "+h+".json AS data FROM "+h+" JOIN "+p+" ON "+h+".seq = "+p+".winningseq WHERE local = 1";e.executeSql(n,[],function(e,n){function r(){if(!o.length)return t(e);var n=o.shift(),i=JSON.parse(n.data)._rev;e.executeSql("INSERT INTO "+_+" (id, rev, json) VALUES (?,?,?)",[n.id,i,n.data],function(e){e.executeSql("DELETE FROM "+p+" WHERE id=?",[n.id],function(e){e.executeSql("DELETE FROM "+h+" WHERE seq=?",[n.seq],function(){r()})})})}for(var o=[],i=0;i<n.rows.length;i++)o.push(n.rows.item(i));r()})})}function j(e,t){function n(n){function r(){if(!n.length)return t(e);var o=n.shift(),i=c(o.hex,W),s=i.lastIndexOf("::"),a=i.substring(0,s),u=i.substring(s+2),f="UPDATE "+h+" SET doc_id=?, rev=? WHERE doc_id_rev=?";e.executeSql(f,[a,u,i],function(){r()})}r()}var r="ALTER TABLE "+h+" ADD COLUMN doc_id";e.executeSql(r,[],function(e){var t="ALTER TABLE "+h+" ADD COLUMN rev";e.executeSql(t,[],function(e){e.executeSql(q,[],function(e){var t="SELECT hex(doc_id_rev) as hex FROM "+h;e.executeSql(t,[],function(e,t){for(var r=[],o=0;o<t.rows.length;o++)r.push(t.rows.item(o));n(r)})})})})}function B(e,t){function n(e){var n="SELECT COUNT(*) AS cnt FROM "+v;e.executeSql(n,[],function(e,n){function r(){var n=w(L+", "+p+".id AS id",[p,h],I,null,p+".id ");n+=" LIMIT "+s+" OFFSET "+i,i+=s,e.executeSql(n,[],function(e,n){function o(e,t){var n=i[e]=i[e]||[];-1===n.indexOf(t)&&n.push(t)}if(!n.rows.length)return t(e);for(var i={},s=0;s<n.rows.length;s++)for(var a=n.rows.item(s),c=E(a.data,a.id,a.rev),u=Object.keys(c._attachments||{}),f=0;f<u.length;f++){var l=c._attachments[u[f]];o(l.digest,a.seq)}var d=[];if(Object.keys(i).forEach(function(e){var t=i[e];t.forEach(function(t){d.push([e,t])})}),!d.length)return r();var p=0;d.forEach(function(t){var n="INSERT INTO "+g+" (digest, seq) VALUES (?,?)";e.executeSql(n,t,function(){++p===d.length&&r()})})})}var o=n.rows.item(0).cnt;if(!o)return t(e);var i=0,s=10;r()})}var r="CREATE TABLE IF NOT EXISTS "+g+" (digest, seq INTEGER)";e.executeSql(r,[],function(e){e.executeSql(C,[],function(e){e.executeSql(D,[],n)})})}function F(e,t){var n="ALTER TABLE "+v+" ADD COLUMN escaped TINYINT(1) DEFAULT 0";e.executeSql(n,[],t)}function P(e,t){var n="ALTER TABLE "+p+" ADD COLUMN max_seq INTEGER";e.executeSql(n,[],function(e){var n="UPDATE "+p+" SET max_seq=(SELECT MAX(seq) FROM "+h+" WHERE doc_id=id)";e.executeSql(n,[],function(e){var n="CREATE UNIQUE INDEX IF NOT EXISTS 'doc-max-seq-idx' ON "+p+" (max_seq)";e.executeSql(n,[],t)})})}function M(e,t){e.executeSql('SELECT HEX("a") AS hex',[],function(e,n){var r=n.rows.item(0).hex;W=2===r.length?"UTF-8":"UTF-16",t()})}function U(){for(;X.length>0;){var e=X.pop();e(null,Q)}}function J(e,t){if(0===t){var n="CREATE TABLE IF NOT EXISTS "+m+" (dbid, db_version INTEGER)",r="CREATE TABLE IF NOT EXISTS "+v+" (digest UNIQUE, escaped TINYINT(1), body BLOB)",o="CREATE TABLE IF NOT EXISTS "+g+" (digest, seq INTEGER)",s="CREATE TABLE IF NOT EXISTS "+p+" (id unique, json, winningseq, max_seq INTEGER UNIQUE)",a="CREATE TABLE IF NOT EXISTS "+h+" (seq INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, json, deleted TINYINT(1), doc_id, rev)",c="CREATE TABLE IF NOT EXISTS "+_+" (id UNIQUE, rev, json)";e.executeSql(r),e.executeSql(c),e.executeSql(o,[],function(){e.executeSql(D),e.executeSql(C)}),e.executeSql(s,[],function(){e.executeSql(R),e.executeSql(a,[],function(){e.executeSql(k),e.executeSql(q),e.executeSql(n,[],function(){var t="INSERT INTO "+m+" (db_version, dbid) VALUES (?,?)";Q=i.uuid();var n=[d,Q];e.executeSql(t,n,function(){U()})})})})}else{var f=function(){var n=d>t;n&&e.executeSql("UPDATE "+m+" SET db_version = "+d);var r="SELECT dbid FROM "+m;e.executeSql(r,[],function(e,t){Q=t.rows.item(0).dbid,U()})},l=[u,N,j,B,F,P,f],y=t,b=function(e){l[y-1](e,b),y++};b(e)}}function H(){Y.transaction(function(e){M(e,function(){V(e)})},T(t),n)}function V(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){var n=t.rows.item(0).db_version;J(e,n)}):e.executeSql("ALTER TABLE "+m+" ADD COLUMN db_version INTEGER",[],function(){J(e,1)}):J(e,0)})}function G(e,t){if(-1!==K._docCount)return t(K._docCount);var n=w("COUNT("+p+".id) AS 'num'",[p,h],I,h+".deleted=0");e.executeSql(n,[],function(e,n){K._docCount=n.rows.item(0).num,t(K._docCount)})}var W,K=this,Q=null,z=A(e),X=[];K._docCount=-1,K._name=e.name;var Y=x({name:K._name,version:O,description:K._name,size:z,location:e.location,createFromLocation:e.createFromLocation});return Y?("function"!=typeof Y.readTransaction&&(Y.readTransaction=Y.transaction),i.isCordova()?window.addEventListener(K._name+"_pouch",function $(){window.removeEventListener(K._name+"_pouch",$,!1),H()},!1):H(),K.type=function(){return"websql"},K._id=i.toPromise(function(e){e(null,Q)}),K._info=function(e){Y.readTransaction(function(t){G(t,function(n){var r="SELECT MAX(seq) AS seq FROM "+h;t.executeSql(r,[],function(t,r){var o=r.rows.item(0).seq||0;e(null,{doc_count:n,update_seq:o,sqlite_plugin:Y._sqlitePlugin,websql_encoding:W})})})},T(e))},K._bulkDocs=function(e,t,n){l(e,t,K,Y,o.Changes,n)},K._get=function(e,t,n){function r(){n(c,{doc:o,metadata:s,ctx:l})}t=i.clone(t);var o,s,c;if(!t.ctx)return void Y.readTransaction(function(r){t.ctx=r,K._get(e,t,n)});var u,f,l=t.ctx;t.rev?(u=w(L,[p,h],p+".id="+h+".doc_id",[h+".doc_id=?",h+".rev=?"]),f=[e,t.rev]):(u=w(L,[p,h],I,p+".id=?"),f=[e]),l.executeSql(u,f,function(e,n){if(!n.rows.length)return c=a.error(a.MISSING_DOC,"missing"),r();var u=n.rows.item(0);return s=i.safeJsonParse(u.metadata),u.deleted&&!t.rev?(c=a.error(a.MISSING_DOC,"deleted"),r()):(o=E(u.data,s.id,u.rev),void r())})},K._allDocs=function(e,t){var n,o=[],a="startkey"in e?e.startkey:!1,c="endkey"in e?e.endkey:!1,u="key"in e?e.key:!1,f="descending"in e?e.descending:!1,l="limit"in e?e.limit:-1,d="skip"in e?e.skip:0,v=e.inclusive_end!==!1,_=[],m=[];if(u!==!1)m.push(p+".id = ?"),_.push(u);else if(a!==!1||c!==!1){if(a!==!1&&(m.push(p+".id "+(f?"<=":">=")+" ?"),_.push(a)),c!==!1){var g=f?">":"<";v&&(g+="="),m.push(p+".id "+g+" ?"),_.push(c)}u!==!1&&(m.push(p+".id = ?"),_.push(u))}"ok"!==e.deleted&&m.push(h+".deleted = 0"),Y.readTransaction(function(t){G(t,function(a){if(n=a,0!==l){var c=w(L,[p,h],I,m,p+".id "+(f?"DESC":"ASC"));c+=" LIMIT "+l+" OFFSET "+d,t.executeSql(c,_,function(t,n){for(var a=0,c=n.rows.length;c>a;a++){var u=n.rows.item(a),f=i.safeJsonParse(u.metadata),l=f.id,d=E(u.data,l,u.rev),p=d._rev,h={id:l,key:l,value:{rev:p}};if(e.include_docs&&(h.doc=d,h.doc._rev=p,e.conflicts&&(h.doc._conflicts=s.collectConflicts(f)),r(h.doc,e,K,t)),u.deleted){if("ok"!==e.deleted)continue;h.value.deleted=!0,h.doc=null}o.push(h)}})}})},T(t),function(){t(null,{total_rows:n,offset:e.skip,rows:o})})},K._changes=function(e){function t(){var t=p+".json AS metadata, "+p+".max_seq AS maxSeq, "+h+".json AS winningDoc, "+h+".rev AS winningRev ",n=p+" JOIN "+h,o=p+".id="+h+".doc_id AND "+p+".winningseq="+h+".seq",l=["maxSeq > ?"],d=[e.since];e.doc_ids&&(l.push(p+".id IN "+y(e.doc_ids.length)),d=d.concat(e.doc_ids));var v="maxSeq "+(s?"DESC":"ASC"),_=w(t,n,o,l,v),m=i.filterChange(e);e.view||e.filter||(_+=" LIMIT "+a);var g=e.since||0;Y.readTransaction(function(t){t.executeSql(_,d,function(t,n){function o(t){return function(){e.onChange(t)}}for(var s=0,l=n.rows.length;l>s;s++){var d=n.rows.item(s),p=i.safeJsonParse(d.metadata);g=d.maxSeq;var h=E(d.winningDoc,p.id,d.winningRev),v=e.processChange(h,p,e);if(v.seq=d.maxSeq,m(v)&&(f++,c&&u.push(v),e.attachments&&e.include_docs?r(h,e,K,t,o(v)):o(v)()),f===a)break}})},T(e.complete),function(){e.continuous||e.complete(null,{results:u,last_seq:g})})}if(e=i.clone(e),e.continuous){var n=K._name+":"+i.uuid();return o.Changes.addListener(K._name,n,K,e),o.Changes.notify(K._name),{cancel:function(){o.Changes.removeListener(K._name,n)}}}var s=e.descending;e.since=e.since&&!s?e.since:0;var a="limit"in e?e.limit:-1;0===a&&(a=1);var c;c="returnDocs"in e?e.returnDocs:!0;var u=[],f=0;t()},K._close=function(e){e()},K._getAttachment=function(e,t,n){var r,o=t.ctx,s=e.digest,a=e.content_type,u="SELECT escaped, CASE WHEN escaped = 1 THEN body ELSE HEX(body) END AS body FROM "+v+" WHERE digest=?";o.executeSql(u,[s],function(e,o){var s=o.rows.item(0),u=s.escaped?f.unescapeBlob(s.body):c(s.body,W);t.encode?r=btoa(u):(u=i.fixBinary(u),r=i.createBlob([u],{type:a})),n(null,r)})},K._getRevisionTree=function(e,t){Y.readTransaction(function(n){var r="SELECT json AS metadata FROM "+p+" WHERE id = ?";n.executeSql(r,[e],function(e,n){if(n.rows.length){var r=i.safeJsonParse(n.rows.item(0).metadata);t(null,r.rev_tree)}else t(a.error(a.MISSING_DOC))})})},K._doCompaction=function(e,t,n){return t.length?void Y.transaction(function(n){var r="SELECT json AS metadata FROM "+p+" WHERE id = ?";n.executeSql(r,[e],function(n,r){var o=i.safeJsonParse(r.rows.item(0).metadata);s.traverseRevTree(o.rev_tree,function(e,n,r,o,i){var s=n+"-"+r;-1!==t.indexOf(s)&&(i.status="missing")});var a="UPDATE "+p+" SET json = ? WHERE id = ?";n.executeSql(a,[i.safeJsonStringify(o),e])}),S(t,e,n)},T(n),function(){n()}):n()},K._getLocal=function(e,t){Y.readTransaction(function(n){var r="SELECT json, rev FROM "+_+" WHERE id=?";n.executeSql(r,[e],function(n,r){if(r.rows.length){var o=r.rows.item(0),i=E(o.json,e,o.rev);t(null,i)}else t(a.error(a.MISSING_DOC))})})},K._putLocal=function(e,t,n){function r(e){var r,f;i?(r="UPDATE "+_+" SET rev=?, json=? WHERE id=? AND rev=?",f=[o,u,s,i]):(r="INSERT INTO "+_+" (id, rev, json) VALUES (?,?,?)",f=[s,o,u]),e.executeSql(r,f,function(e,r){r.rowsAffected?(c={ok:!0,id:s,rev:o},t.ctx&&n(null,c)):n(a.error(a.REV_CONFLICT))},function(){return n(a.error(a.REV_CONFLICT)),!1})}"function"==typeof t&&(n=t,t={}),delete e._revisions;var o,i=e._rev,s=e._id;o=e._rev=i?"0-"+(parseInt(i.split("-")[1],10)+1):"0-1";var c,u=b(e);t.ctx?r(t.ctx):Y.transaction(function(e){r(e)},T(n),function(){c&&n(null,c)})},void(K._removeLocal=function(e,t){var n;Y.transaction(function(r){var o="DELETE FROM "+_+" WHERE id=? AND rev=?",i=[e._id,e._rev];r.executeSql(o,i,function(r,o){return o.rowsAffected?void(n={ok:!0,id:e._id,rev:"0-0"}):t(a.error(a.MISSING_DOC))})},T(t),function(){n&&t(null,n)})})):t(a.error(a.UNKNOWN_ERROR))}var i=e(35),s=e(30),a=e(20),c=e(23),u=e(11),f=e(12),l=e(10),d=u.ADAPTER_VERSION,p=u.DOC_STORE,h=u.BY_SEQ_STORE,v=u.ATTACH_STORE,_=u.LOCAL_STORE,m=u.META_STORE,g=u.ATTACH_AND_SEQ_STORE,y=f.qMarks,b=f.stringifyDoc,E=f.unstringifyDoc,w=f.select,S=f.compactRevs,T=f.unknownError,A=f.getSize,x=f.openDB,O=1,k="CREATE INDEX IF NOT EXISTS 'by-seq-deleted-idx' ON "+h+" (seq, deleted)",q="CREATE UNIQUE INDEX IF NOT EXISTS 'by-seq-doc-id-rev' ON "+h+" (doc_id, rev)",R="CREATE INDEX IF NOT EXISTS 'doc-winningseq-idx' ON "+p+" (winningseq)",D="CREATE INDEX IF NOT EXISTS 'attach-seq-seq-idx' ON "+g+" (seq)",C="CREATE UNIQUE INDEX IF NOT EXISTS 'attach-seq-digest-idx' ON "+g+" (digest, seq)",I=h+".seq = "+p+".winningseq",L=h+".seq AS seq, "+h+".deleted AS deleted, "+h+".json AS data, "+h+".rev AS rev, "+p+".json AS metadata";o.valid=f.valid,o.destroy=i.toPromise(function(e,t,n){o.Changes.removeAllListeners(e);var r=A(t),s=x({name:e,version:O,description:e,size:r,location:t.location,createFromLocation:t.createFromLocation});s.transaction(function(e){var t=[p,h,v,m,_,g];t.forEach(function(t){e.executeSql("DROP TABLE IF EXISTS "+t,[])})},T(n),function(){i.hasLocalStorage()&&(delete window.localStorage["_pouch__websqldb_"+e],delete window.localStorage[e]),n(null,{ok:!0})})}),o.Changes=new i.Changes,t.exports=o},{10:10,11:11,12:12,20:20,23:23,30:30,35:35}],14:[function(e,t,n){"use strict";function r(e,t,n){function r(){o.cancel()}c.call(this);var o=this;this.db=e,t=t?i.clone(t):{};var s=n||t.complete||function(){},a=t.complete=i.once(function(t,n){t?o.emit("error",t):o.emit("complete",n),o.removeAllListeners(),e.removeListener("destroyed",r)});s&&(o.on("complete",function(e){s(null,e)}),o.on("error",function(e){s(e)}));var u=t.onChange;u&&o.on("change",u),e.once("destroyed",r),t.onChange=function(e){t.isCancelled||(o.emit("change",e),o.startSeq&&o.startSeq<=e.seq&&(o.emit("uptodate"),o.startSeq=!1),e.deleted?o.emit("delete",e):1===e.changes.length&&"1-"===e.changes[0].rev.slice(0,2)?o.emit("create",e):o.emit("update",e))};var f=new i.Promise(function(e,n){t.complete=function(t,r){t?n(t):e(r)}});o.once("cancel",function(){u&&o.removeListener("change",u),t.complete(null,{status:"cancelled"})}),this.then=f.then.bind(f),this["catch"]=f["catch"].bind(f),this.then(function(e){a(null,e)},a),e.taskqueue.isReady?o.doChanges(t):e.taskqueue.addTask(function(){o.isCancelled?o.emit("cancel"):o.doChanges(t)})}function o(e,t,n){var r=[{rev:e._rev}];"all_docs"===n.style&&(r=s.collectLeaves(t.rev_tree).map(function(e){return{rev:e.rev}}));var o={id:t.id,changes:r,doc:e};return i.isDeleted(t,e._rev)&&(o.deleted=!0),n.conflicts&&(o.doc._conflicts=s.collectConflicts(t),o.doc._conflicts.length||delete o.doc._conflicts),o}var i=e(35),s=e(30),a=e(20),c=e(39).EventEmitter,u=e(28),f=e(29);t.exports=r,i.inherits(r,c),r.prototype.cancel=function(){this.isCancelled=!0,this.db.taskqueue.isReady&&this.emit("cancel")},r.prototype.doChanges=function(e){var t=this,n=e.complete;if(e=i.clone(e),"live"in e&&!("continuous"in e)&&(e.continuous=e.live),e.processChange=o,"latest"===e.since&&(e.since="now"),e.since||(e.since=0),"now"===e.since)return void this.db.info().then(function(r){return t.isCancelled?void n(null,{status:"cancelled"}):(e.since=r.update_seq,void t.doChanges(e))},n);if(e.continuous&&"now"!==e.since&&this.db.info().then(function(e){t.startSeq=e.update_seq},function(e){if("idbNull"!==e.id)throw e}),"http"!==this.db.type()&&e.filter&&"string"==typeof e.filter&&!e.doc_ids)return this.filterChanges(e);"descending"in e||(e.descending=!1),e.limit=0===e.limit?1:e.limit,e.complete=n;var r=this.db._changes(e);if(r&&"function"==typeof r.cancel){var s=t.cancel;t.cancel=i.getArguments(function(e){r.cancel(),s.apply(this,e)})}},r.prototype.filterChanges=function(e){var t=this,n=e.complete;if("_view"===e.filter){if(!e.view||"string"!=typeof e.view){var r=a.error(a.BAD_REQUEST,"`view` filter parameter is not provided.");return void n(r)}var o=e.view.split("/");this.db.get("_design/"+o[0],function(r,i){if(t.isCancelled)return void n(null,{status:"cancelled"});if(r)return void n(a.generateErrorFromResponse(r));if(i&&i.views&&i.views[o[1]]){var s=f(i.views[o[1]].map);return e.filter=s,void t.doChanges(e)}var c=i.views?"missing json key: "+o[1]:"missing json key: views";r||(r=a.error(a.MISSING_DOC,c)),n(r)})}else{var i=e.filter.split("/");this.db.get("_design/"+i[0],function(r,o){if(t.isCancelled)return void n(null,{status:"cancelled"});if(r)return void n(a.generateErrorFromResponse(r));if(o&&o.filters&&o.filters[i[1]]){var s=u(o.filters[i[1]]);return e.filter=s,void t.doChanges(e)}var c=o&&o.filters?"missing json key: "+i[1]:"missing json key: filters";return r||(r=a.error(a.MISSING_DOC,c)),void n(r)})}}},{20:20,28:28,29:29,30:30,35:35,39:39}],15:[function(e,t,n){"use strict";function r(e,t,n,o){return e.get(t)["catch"](function(n){if(404===n.status)return"http"===e.type()&&i.explain404("PouchDB is just checking if a remote checkpoint exists."),{_id:t};throw n}).then(function(i){return o.cancelled?void 0:(i.last_seq=n,e.put(i)["catch"](function(i){if(409===i.status)return r(e,t,n,o);throw i}))})}function o(e,t,n,r){this.src=e,this.target=t,this.id=n,this.returnValue=r}var i=e(35),s=e(63),a=s.collate;o.prototype.writeCheckpoint=function(e){var t=this;return this.updateTarget(e).then(function(){return t.updateSource(e)})},o.prototype.updateTarget=function(e){return r(this.target,this.id,e,this.returnValue)},o.prototype.updateSource=function(e){var t=this;return this.readOnlySource?i.Promise.resolve(!0):r(this.src,this.id,e,this.returnValue)["catch"](function(e){var n="number"==typeof e.status&&4===Math.floor(e.status/100);if(n)return t.readOnlySource=!0,!0;throw e})},o.prototype.getCheckpoint=function(){var e=this;return e.target.get(e.id).then(function(t){return e.src.get(e.id).then(function(e){return 0===a(t.last_seq,e.last_seq)?e.last_seq:0},function(n){if(404===n.status&&t.last_seq)return e.src.put({_id:e.id,last_seq:0}).then(function(){return 0},function(n){return 401===n.status?(e.readOnlySource=!0,t.last_seq):0});throw n})})["catch"](function(e){
if(404!==e.status)throw e;return 0})},t.exports=o},{35:35,63:63}],16:[function(e,t,n){(function(n,r){"use strict";function o(e){e&&r.debug&&console.error(e)}function i(e,t,r){if(!(this instanceof i))return new i(e,t,r);var f=this;("function"==typeof t||"undefined"==typeof t)&&(r=t,t={}),e&&"object"==typeof e&&(t=e,e=void 0),"undefined"==typeof r&&(r=o),t=t||{},this.__opts=t;var l=r;f.auto_compaction=t.auto_compaction,f.prefix=i.prefix,s.call(f),f.taskqueue=new c;var d=new u(function(o,s){r=function(e,t){return e?s(e):(delete t.then,void o(t))},t=a.clone(t);var c,u,l=t.name||e;return function(){try{if("string"!=typeof l)throw u=new Error("Missing/invalid DB name"),u.code=400,u;if(c=i.parseAdapter(l,t),t.originalName=l,t.name=c.name,t.prefix&&"http"!==c.adapter&&"https"!==c.adapter&&(t.name=t.prefix+t.name),t.adapter=t.adapter||c.adapter,f._adapter=t.adapter,f._db_name=l,!i.adapters[t.adapter])throw u=new Error("Adapter is missing"),u.code=404,u;if(!i.adapters[t.adapter].valid())throw u=new Error("Invalid Adapter"),u.code=404,u}catch(e){f.taskqueue.fail(e),f.changes=a.toPromise(function(t){t.complete&&t.complete(e)})}}(),u?s(u):(f.adapter=t.adapter,f.replicate={},f.replicate.from=function(e,t,n){return f.constructor.replicate(e,f,t,n)},f.replicate.to=function(e,t,n){return f.constructor.replicate(f,e,t,n)},f.sync=function(e,t,n){return f.constructor.sync(f,e,t,n)},f.replicate.sync=f.sync,f.destroy=a.adapterFun("destroy",function(e){var t=this,n=this.__opts||{};t.info(function(r,o){return r?e(r):(n.internal=!0,void t.constructor.destroy(o.db_name,n,e))})}),i.adapters[t.adapter].call(f,t,function(e){function n(e){"destroyed"===e&&(f.emit("destroyed"),i.removeListener(l,n))}return e?void(r&&(f.taskqueue.fail(e),r(e))):(i.on(l,n),f.emit("created",f),i.emit("created",t.originalName),f.taskqueue.ready(f),void r(null,f))}),t.skipSetup&&(f.taskqueue.ready(f),n.nextTick(function(){r(null,f)})),void(a.isCordova()&&cordova.fireWindowEvent(t.name+"_pouch",{})))});d.then(function(e){l(null,e)},l),f.then=d.then.bind(d),f["catch"]=d["catch"].bind(d)}var s=e(1),a=e(35),c=e(34),u=a.Promise;a.inherits(i,s),i.debug=e(41),t.exports=i}).call(this,e(40),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{1:1,34:34,35:35,40:40,41:41}],17:[function(e,t,n){(function(n){"use strict";function r(e,t){function r(t,n,r){if(e.binary||e.json||!e.processData||"string"==typeof t){if(!e.binary&&e.json&&"string"==typeof t)try{t=JSON.parse(t)}catch(o){return r(o)}}else t=JSON.stringify(t);Array.isArray(t)&&(t=t.map(function(e){return e.error||e.missing?s.generateErrorFromResponse(e):e})),r(null,t,n)}function c(e,t){var n,r;if(e.code&&e.status){var o=new Error(e.message||e.code);return o.status=e.status,t(o)}try{n=JSON.parse(e.responseText),r=s.generateErrorFromResponse(n)}catch(i){r=s.generateErrorFromResponse(e)}t(r)}function u(e){return n.browser?"":new i("","binary")}var f=!1,l=a.getArguments(function(e){f||(t.apply(this,e),f=!0)});"function"==typeof e&&(l=e,e={}),e=a.clone(e);var d={method:"GET",headers:{},json:!0,processData:!0,timeout:1e4,cache:!1};return e=a.extend(!0,d,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),o(e,function(t,n,o){if(t)return t.status=n?n.statusCode:400,c(t,l);var i,a=n.headers&&n.headers["content-type"],f=o||u();e.binary||!e.json&&e.processData||"object"==typeof f||!(/json/.test(a)||/^[\s]*\{/.test(f)&&/\}[\s]*$/.test(f))||(f=JSON.parse(f)),n.statusCode>=200&&n.statusCode<300?r(f,n,l):(e.binary&&(f=JSON.parse(f.toString())),i=s.generateErrorFromResponse(f),i.status=n.statusCode,l(i))})}var o=e(25),i=e(19),s=e(20),a=e(35);t.exports=r}).call(this,e(40))},{19:19,20:20,25:25,35:35,40:40}],18:[function(e,t,n){(function(e){"use strict";function n(t,n){t=t||[],n=n||{};try{return new Blob(t,n)}catch(r){if("TypeError"!==r.name)throw r;for(var o=e.BlobBuilder||e.MSBlobBuilder||e.MozBlobBuilder||e.WebKitBlobBuilder,i=new o,s=0;s<t.length;s+=1)i.append(t[s]);return i.getBlob(n.type)}}t.exports=n}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],19:[function(e,t,n){t.exports={}},{}],20:[function(e,t,n){"use strict";function r(e){Error.call(e.reason),this.status=e.status,this.name=e.error,this.message=e.reason,this.error=!0}var o=e(44);o(r,Error),r.prototype.toString=function(){return JSON.stringify({status:this.status,name:this.name,message:this.message})},n.UNAUTHORIZED=new r({status:401,error:"unauthorized",reason:"Name or password is incorrect."}),n.MISSING_BULK_DOCS=new r({status:400,error:"bad_request",reason:"Missing JSON list of 'docs'"}),n.MISSING_DOC=new r({status:404,error:"not_found",reason:"missing"}),n.REV_CONFLICT=new r({status:409,error:"conflict",reason:"Document update conflict"}),n.INVALID_ID=new r({status:400,error:"invalid_id",reason:"_id field must contain a string"}),n.MISSING_ID=new r({status:412,error:"missing_id",reason:"_id is required for puts"}),n.RESERVED_ID=new r({status:400,error:"bad_request",reason:"Only reserved document ids may start with underscore."}),n.NOT_OPEN=new r({status:412,error:"precondition_failed",reason:"Database not open"}),n.UNKNOWN_ERROR=new r({status:500,error:"unknown_error",reason:"Database encountered an unknown error"}),n.BAD_ARG=new r({status:500,error:"badarg",reason:"Some query argument is invalid"}),n.INVALID_REQUEST=new r({status:400,error:"invalid_request",reason:"Request was invalid"}),n.QUERY_PARSE_ERROR=new r({status:400,error:"query_parse_error",reason:"Some query parameter is invalid"}),n.DOC_VALIDATION=new r({status:500,error:"doc_validation",reason:"Bad special document member"}),n.BAD_REQUEST=new r({status:400,error:"bad_request",reason:"Something wrong with the request"}),n.NOT_AN_OBJECT=new r({status:400,error:"bad_request",reason:"Document must be a JSON object"}),n.DB_MISSING=new r({status:404,error:"not_found",reason:"Database not found"}),n.IDB_ERROR=new r({status:500,error:"indexed_db_went_bad",reason:"unknown"}),n.WSQ_ERROR=new r({status:500,error:"web_sql_went_bad",reason:"unknown"}),n.LDB_ERROR=new r({status:500,error:"levelDB_went_went_bad",reason:"unknown"}),n.FORBIDDEN=new r({status:403,error:"forbidden",reason:"Forbidden by design doc validate_doc_update function"}),n.INVALID_REV=new r({status:400,error:"bad_request",reason:"Invalid rev format"}),n.FILE_EXISTS=new r({status:412,error:"file_exists",reason:"The database could not be created, the file already exists."}),n.MISSING_STUB=new r({status:412,error:"missing_stub"}),n.error=function(e,t,n){function o(t){for(var r in e)"function"!=typeof e[r]&&(this[r]=e[r]);void 0!==n&&(this.name=n),void 0!==t&&(this.reason=t)}return o.prototype=r.prototype,new o(t)},n.getErrorTypeByProp=function(e,t,r){var o=n,i=Object.keys(o).filter(function(n){var r=o[n];return"function"!=typeof r&&r[e]===t}),s=r&&i.filter(function(e){var t=o[e];return t.message===r})[0]||i[0];return s?o[s]:null},n.generateErrorFromResponse=function(e){var t,r,o,i,s,a=n;return r=e.error===!0&&"string"==typeof e.name?e.name:e.error,s=e.reason,o=a.getErrorTypeByProp("name",r,s),e.missing||"missing"===s||"deleted"===s||"not_found"===r?o=a.MISSING_DOC:"doc_validation"===r?(o=a.DOC_VALIDATION,i=s):"bad_request"===r&&o.message!==s&&(0===s.indexOf("unknown stub attachment")?(o=a.MISSING_STUB,i=s):o=a.BAD_REQUEST),o||(o=a.getErrorTypeByProp("status",e.status,s)||a.UNKNOWN_ERROR),t=a.error(o,s,r),i&&(t.message=i),e.id&&(t.id=e.id),e.status&&(t.status=e.status),e.statusText&&(t.name=e.statusText),e.missing&&(t.missing=e.missing),t}},{44:44}],21:[function(e,t,n){(function(n,r){"use strict";function o(e){var t=[255&e,e>>>8&255,e>>>16&255,e>>>24&255];return t.map(function(e){return String.fromCharCode(e)}).join("")}function i(e){for(var t="",n=0;n<e.length;n++)t+=o(e[n]);return btoa(t)}function s(e,t,n,r){(n>0||r<t.byteLength)&&(t=new Uint8Array(t,n,Math.min(r,t.byteLength)-n)),e.append(t)}function a(e,t,n,r){(n>0||r<t.length)&&(t=t.substring(n,r)),e.appendBinary(t)}var c=e(38),u=e(74),f=r.setImmediate||r.setTimeout,l=32768;t.exports=function(e,t){function r(){var n=_*h,o=n+h;if(_++,v>_)g(m,e,n,o),f(r);else{g(m,e,n,o);var s=m.end(!0),a=i(s);t(null,a),m.destroy()}}if(!n.browser){var o=c.createHash("md5").update(e).digest("base64");return void t(null,o)}var d="string"==typeof e,p=d?e.length:e.byteLength,h=Math.min(l,p),v=Math.ceil(p/h),_=0,m=d?new u:new u.ArrayBuffer,g=d?a:s;r()}}).call(this,e(40),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{38:38,40:40,74:74}],22:[function(e,t,n){"use strict";function r(e){return e.reduce(function(e,t){return e[t]=!0,e},{})}function o(e){if(!/^\d+\-./.test(e))return s.error(s.INVALID_REV);var t=e.indexOf("-"),n=e.substring(0,t),r=e.substring(t+1);return{prefix:parseInt(n,10),id:r}}function i(e,t){for(var n=e.start-e.ids.length+1,r=e.ids,o=[r[0],t,[]],i=1,s=r.length;s>i;i++)o=[r[i],{status:"missing"},[o]];return[{pos:n,ids:o}]}var s=e(20),a=e(27),c=r(["_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"]),u=r(["_attachments","_replication_id","_replication_state","_replication_state_time","_replication_state_reason","_replication_stats"]);n.invalidIdError=function(e){var t;if(e?"string"!=typeof e?t=s.error(s.INVALID_ID):/^_/.test(e)&&!/^_(design|local)/.test(e)&&(t=s.error(s.RESERVED_ID)):t=s.error(s.MISSING_ID),t)throw t},n.parseDoc=function(e,t){var r,f,l,d={status:"available"};if(e._deleted&&(d.deleted=!0),t)if(e._id||(e._id=a()),f=a(32,16).toLowerCase(),e._rev){if(l=o(e._rev),l.error)return l;e._rev_tree=[{pos:l.prefix,ids:[l.id,{status:"missing"},[[f,d,[]]]]}],r=l.prefix+1}else e._rev_tree=[{pos:1,ids:[f,d,[]]}],r=1;else if(e._revisions&&(e._rev_tree=i(e._revisions,d),r=e._revisions.start,f=e._revisions.ids[0]),!e._rev_tree){if(l=o(e._rev),l.error)return l;r=l.prefix,f=l.id,e._rev_tree=[{pos:r,ids:[f,d,[]]}]}n.invalidIdError(e._id),e._rev=r+"-"+f;var p={metadata:{},data:{}};for(var h in e)if(e.hasOwnProperty(h)){var v="_"===h[0];if(v&&!c[h]){var _=s.error(s.DOC_VALIDATION,h);throw _.message=s.DOC_VALIDATION.message+": "+h,_}v&&!u[h]?p.metadata[h.slice(1)]=e[h]:p.data[h]=e[h]}return p}},{20:20,27:27}],23:[function(e,t,n){"use strict";function r(e){return decodeURIComponent(window.escape(e))}function o(e){return 65>e?e-48:e-55}function i(e,t,n){for(var r="";n>t;)r+=String.fromCharCode(o(e.charCodeAt(t++))<<4|o(e.charCodeAt(t++)));return r}function s(e,t,n){for(var r="";n>t;)r+=String.fromCharCode(o(e.charCodeAt(t+2))<<12|o(e.charCodeAt(t+3))<<8|o(e.charCodeAt(t))<<4|o(e.charCodeAt(t+1))),t+=4;return r}function a(e,t){return"UTF-8"===t?r(i(e,0,e.length)):s(e,0,e.length)}t.exports=a},{}],24:[function(e,t,n){"use strict";function r(e){for(var t=o,n=t.parser[t.strictMode?"strict":"loose"].exec(e),r={},i=14;i--;){var s=t.key[i],a=n[i]||"",c=-1!==["user","password"].indexOf(s);r[s]=c?decodeURIComponent(a):a}return r[t.q.name]={},r[t.key[12]].replace(t.q.parser,function(e,n,o){n&&(r[t.q.name][n]=o)}),r}var o={strictMode:!1,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}};t.exports=r},{}],25:[function(e,t,n){"use strict";var r=e(18),o=e(35);t.exports=function(e,t){var n,i,s,a=function(){n.abort()};if(n=e.xhr?new e.xhr:new XMLHttpRequest,"GET"===e.method&&!e.cache){var c=-1!==e.url.indexOf("?");e.url+=(c?"&":"?")+"_nonce="+Date.now()}n.open(e.method,e.url),n.withCredentials=!0,e.json&&(e.headers.Accept="application/json",e.headers["Content-Type"]=e.headers["Content-Type"]||"application/json",e.body&&e.processData&&"string"!=typeof e.body&&(e.body=JSON.stringify(e.body))),e.binary&&(n.responseType="arraybuffer"),"body"in e||(e.body=null);for(var u in e.headers)e.headers.hasOwnProperty(u)&&n.setRequestHeader(u,e.headers[u]);return e.timeout>0&&(i=setTimeout(a,e.timeout),n.onprogress=function(){clearTimeout(i),i=setTimeout(a,e.timeout)},"undefined"==typeof s&&(s=-1!==Object.keys(n).indexOf("upload")),s&&(n.upload.onprogress=n.onprogress)),n.onreadystatechange=function(){if(4===n.readyState){var o={statusCode:n.status};if(n.status>=200&&n.status<300){var i;i=e.binary?r([n.response||""],{type:n.getResponseHeader("Content-Type")}):n.responseText,t(null,o,i)}else{var s={};try{s=JSON.parse(n.response)}catch(a){}t(s,o)}}},e.body&&e.body instanceof Blob?o.readAsBinaryString(e.body,function(e){n.send(o.fixBinary(e))}):n.send(e.body),{abort:a}}},{18:18,35:35}],26:[function(e,t,n){"use strict";var r=e(73).upsert;t.exports=function(e,t,n,o){return r.call(e,t,n,o)}},{73:73}],27:[function(e,t,n){"use strict";function r(e){return 0|Math.random()*e}function o(e,t){t=t||i.length;var n="",o=-1;if(e){for(;++o<e;)n+=i[r(t)];return n}for(;++o<36;)switch(o){case 8:case 13:case 18:case 23:n+="-";break;case 19:n+=i[3&r(16)|8];break;default:n+=i[r(16)]}return n}var i="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");t.exports=o},{}],28:[function(_dereq_,module,exports){"use strict";function evalFilter(input){return eval(["(function () { return ",input," })()"].join(""))}module.exports=evalFilter},{}],29:[function(_dereq_,module,exports){"use strict";function evalView(input){return eval(["(function () {","  return function (doc) {","    var emitted = false;","    var emit = function (a, b) {","      emitted = true;","    };","    var view = "+input+";","    view(doc);","    if (emitted) {","      return true;","    }","  }","})()"].join("\n"))}module.exports=evalView},{}],30:[function(e,t,n){"use strict";function r(e,t,n){for(var r,o=0,i=e.length;i>o;)r=o+i>>>1,n(e[r],t)<0?o=r+1:i=r;return o}function o(e,t,n){var o=r(e,t,n);e.splice(o,0,t)}function i(e){for(var t,n=e.shift(),r=[n.id,n.opts,[]],o=r;e.length;)n=e.shift(),t=[n.id,n.opts,[]],o[2].push(t),o=t;return r}function s(e,t){return e[0]<t[0]?-1:1}function a(e,t){for(var n=[{tree1:e,tree2:t}],r=!1;n.length>0;){var i=n.pop(),a=i.tree1,c=i.tree2;(a[1].status||c[1].status)&&(a[1].status="available"===a[1].status||"available"===c[1].status?"available":"missing");for(var u=0;u<c[2].length;u++)if(a[2][0]){for(var f=!1,l=0;l<a[2].length;l++)a[2][l][0]===c[2][u][0]&&(n.push({tree1:a[2][l],tree2:c[2][u]}),f=!0);f||(r="new_branch",o(a[2],c[2][u],s))}else r="new_leaf",a[2][0]=c[2][u]}return{conflicts:r,tree:e}}function c(e,t,n){var r,o=[],i=!1,s=!1;return e.length?(e.forEach(function(e){if(e.pos===t.pos&&e.ids[0]===t.ids[0])r=a(e.ids,t.ids),o.push({pos:e.pos,ids:r.tree}),i=i||r.conflicts,s=!0;else if(n!==!0){var c=e.pos<t.pos?e:t,u=e.pos<t.pos?t:e,f=u.pos-c.pos,l=[],d=[];for(d.push({ids:c.ids,diff:f,parent:null,parentIdx:null});d.length>0;){var p=d.pop();0!==p.diff?p.ids&&p.ids[2].forEach(function(e,t){d.push({ids:e,diff:p.diff-1,parent:p.ids,parentIdx:t})}):p.ids[0]===u.ids[0]&&l.push(p)}var h=l[0];h?(r=a(h.ids,u.ids),h.parent[2][h.parentIdx]=r.tree,o.push({pos:c.pos,ids:c.ids}),i=i||r.conflicts,s=!0):o.push(e)}else o.push(e)}),s||o.push(t),o.sort(function(e,t){return e.pos-t.pos}),{tree:o,conflicts:i||"internal_node"}):{tree:[t],conflicts:"new_leaf"}}function u(e,t){var n=l.rootToLeaf(e).map(function(e){var n=e.ids.slice(-t);return{pos:e.pos+(e.ids.length-n.length),ids:i(n)}});return n.reduce(function(e,t){return c(e,t,!0).tree},[n.shift()])}var f=e(66),l={};l.merge=function(e,t,n){e=f(!0,[],e),t=f(!0,{},t);var r=c(e,t);return{tree:u(r.tree,n),conflicts:r.conflicts}},l.winningRev=function(e){var t=[];return l.traverseRevTree(e.rev_tree,function(e,n,r,o,i){e&&t.push({pos:n,id:r,deleted:!!i.deleted})}),t.sort(function(e,t){return e.deleted!==t.deleted?e.deleted>t.deleted?1:-1:e.pos!==t.pos?t.pos-e.pos:e.id<t.id?1:-1}),t[0].pos+"-"+t[0].id},l.traverseRevTree=function(e,t){for(var n,r=e.slice();n=r.pop();)for(var o=n.pos,i=n.ids,s=i[2],a=t(0===s.length,o,i[0],n.ctx,i[1]),c=0,u=s.length;u>c;c++)r.push({pos:o+1,ids:s[c],ctx:a})},l.collectLeaves=function(e){var t=[];return l.traverseRevTree(e,function(e,n,r,o,i){e&&t.push({rev:n+"-"+r,pos:n,opts:i})}),t.sort(function(e,t){return t.pos-e.pos}),t.forEach(function(e){delete e.pos}),t},l.collectConflicts=function(e){var t=l.winningRev(e),n=l.collectLeaves(e.rev_tree),r=[];return n.forEach(function(e){e.rev===t||e.opts.deleted||r.push(e.rev)}),r},l.rootToLeaf=function(e){var t=[];return l.traverseRevTree(e,function(e,n,r,o,i){if(o=o?o.slice(0):[],o.push({id:r,opts:i}),e){var s=n+1-o.length;t.unshift({pos:s,ids:o})}return o}),t},t.exports=l},{66:66}],31:[function(e,t,n){"use strict";function r(e,t){e=parseInt(e,10),t=parseInt(t,10),e!==e&&(e=0),t!==t||e>=t?t=(e||1)<<1:t+=1;var n=Math.random(),r=t-e;return~~(r*n+e)}function o(e){var t=0;return e||(t=2e3),r(e,t)}function i(e,t,n,r,i,s,a){return r.retry===!1?(i.emit("error",a),void i.removeAllListeners()):(r.default_back_off=r.default_back_off||0,r.retries=r.retries||0,"function"!=typeof r.back_off_function&&(r.back_off_function=o),r.retries++,r.max_retries&&r.retries>r.max_retries?(i.emit("error",new Error("tried "+r.retries+" times but replication failed")),void i.removeAllListeners()):(i.emit("requestError",a),"active"===i.state&&(i.emit("paused",a),i.state="stopped",i.once("active",function(){r.current_back_off=r.default_back_off})),r.current_back_off=r.current_back_off||r.default_back_off,r.current_back_off=r.back_off_function(r.current_back_off),void setTimeout(function(){c(e,t,n,r,i)},r.current_back_off)))}function s(){d.call(this),this.cancelled=!1,this.state="pending";var e=this,t=new l.Promise(function(t,n){e.once("complete",t),e.once("error",n)});e.then=function(e,n){return t.then(e,n)},e["catch"]=function(e){return t["catch"](e)},e["catch"](function(){})}function a(e,t,n){var r=n.filter?n.filter.toString():"";return e.id().then(function(e){return t.id().then(function(t){var o=e+t+r+JSON.stringify(n.query_params)+n.doc_ids;return l.MD5(o).then(function(e){return e=e.replace(/\//g,".").replace(/\+/g,"_"),"_local/"+e})})})}function c(e,t,n,r,o,s){function a(){if(0!==x.docs.length){var e=x.docs;return n.bulkDocs({docs:e,new_edits:!1}).then(function(t){if(F.cancelled)throw b(),new Error("cancelled");var n=[],r={};t.forEach(function(e){e.error&&(s.doc_write_failures++,n.push(e),r[e.id]=e)}),s.errors=n,M=M.concat(n),s.docs_written+=x.docs.length-n.length;var i=n.filter(function(e){return"unauthorized"!==e.name&&"forbidden"!==e.name});if(U=[],e.forEach(function(e){var t=r[e._id];t?o.emit("denied",l.clone(t)):U.push(e)}),i.length>0){var a=new Error("bulkDocs error");throw a.other_errors=n,y("target.bulkDocs failed to write docs",a),new Error("bulkWrite partial failure")}},function(t){throw s.doc_write_failures+=e.length,t})}}function c(e){for(var n=x.diffs,r=n[e].missing,o=[],i=0;i<r.length;i+=h)o.push(r.slice(i,Math.min(r.length,i+h)));return l.Promise.all(o.map(function(r){var o={revs:!0,open_revs:r,attachments:!0};return t.get(e,o).then(function(t){t.forEach(function(e){return F.cancelled?b():void(e.ok&&(s.docs_read++,x.pendingRevs++,x.docs.push(e.ok)))}),delete n[e]})}))}function u(){var e=Object.keys(x.diffs);return l.Promise.all(e.map(c))}function f(){var e=Object.keys(x.diffs).filter(function(e){var t=x.diffs[e].missing;return 1===t.length&&"1-"===t[0].slice(0,2)});return e.length?t.allDocs({keys:e,include_docs:!0}).then(function(e){if(F.cancelled)throw b(),new Error("cancelled");e.rows.forEach(function(e){!e.doc||e.deleted||"1-"!==e.value.rev.slice(0,2)||e.doc._attachments&&0!==Object.keys(e.doc._attachments).length||(s.docs_read++,x.pendingRevs++,x.docs.push(e.doc),delete x.diffs[e.id])})}):l.Promise.resolve()}function d(){return f().then(u)}function v(){return q=!0,P.writeCheckpoint(x.seq).then(function(){if(q=!1,F.cancelled)throw b(),new Error("cancelled");s.last_seq=C=x.seq;var e=l.clone(s);e.docs=U,o.emit("change",e),x=void 0,T()})["catch"](function(e){throw q=!1,y("writeCheckpoint completed with error",e),e})}function _(){var e={};return x.changes.forEach(function(t){"_user/"!==t.id&&(e[t.id]=t.changes.map(function(e){return e.rev}))}),n.revsDiff(e).then(function(e){if(F.cancelled)throw b(),new Error("cancelled");x.diffs=e,x.pendingRevs=0})}function m(){if(!F.cancelled&&!x){if(0===O.length)return void g(!0);x=O.shift(),_().then(d).then(a).then(v).then(m)["catch"](function(e){y("batch processing terminated with error",e)})}}function g(e){return 0===k.changes.length?void(0!==O.length||x||((I&&J.live||R)&&(o.state="pending",o.emit("paused"),o.emit("uptodate",s)),R&&b())):void((e||R||k.changes.length>=L)&&(O.push(k),k={seq:0,changes:[],docs:[]},("pending"===o.state||"stopped"===o.state)&&(o.state="active",o.emit("active")),m()))}function y(e,t){D||(t.message||(t.message=e),s.ok=!1,s.status="aborting",s.errors.push(t),M=M.concat(t),O=[],k={seq:0,changes:[],docs:[]},b())}function b(){if(!(D||F.cancelled&&(s.status="cancelled",q))){s.status=s.status||"complete",s.end_time=new Date,s.last_seq=C,D=F.cancelled=!0;var a=M.filter(function(e){return"unauthorized"!==e.name&&"forbidden"!==e.name});if(a.length>0){var c=M.pop();M.length>0&&(c.other_errors=M),c.result=s,i(e,t,n,r,o,s,c)}else s.errors=M,o.emit("complete",s),o.removeAllListeners()}}function E(e){if(F.cancelled)return b();var t=l.filterChange(r)(e);t&&(0!==k.changes.length||0!==O.length||x||o.emit("outofdate",s),k.seq=e.seq,k.changes.push(e),g(0===O.length))}function w(e){return j=!1,F.cancelled?b():(e.results.length>0?(J.since=e.last_seq,T()):I?(J.live=!0,T()):R=!0,void g(!0))}function S(e){return j=!1,F.cancelled?b():void y("changes rejected",e)}function T(){function e(){r.cancel()}function n(){o.removeListener("cancel",e)}if(!j&&!R&&O.length<N){j=!0,o.once("cancel",e);var r=t.changes(J).on("change",E);r.then(n,n),r.then(w)["catch"](S)}}function A(){P.getCheckpoint().then(function(e){C=e,J={since:C,limit:L,batch_size:L,style:"all_docs",doc_ids:B,returnDocs:!0},r.filter&&("string"!=typeof r.filter?J.include_docs=!0:J.filter=r.filter),r.query_params&&(J.query_params=r.query_params),r.view&&(J.view=r.view),T()})["catch"](function(e){y("getCheckpoint rejected with ",e)})}var x,O=[],k={seq:0,changes:[],docs:[]},q=!1,R=!1,D=!1,C=0,I=r.continuous||r.live||!1,L=r.batch_size||100,N=r.batches_limit||10,j=!1,B=r.doc_ids,F={cancelled:!1},P=new p(t,n,e,F),M=[],U=[];s=s||{ok:!0,start_time:new Date,docs_read:0,docs_written:0,doc_write_failures:0,errors:[]};var J={};return o.ready(t,n),o.cancelled?void b():(o.once("cancel",b),"function"==typeof r.onChange&&o.on("change",r.onChange),"function"==typeof r.complete&&(o.once("error",r.complete),o.once("complete",function(e){r.complete(null,e)})),void("undefined"==typeof r.since?A():(q=!0,P.writeCheckpoint(r.since).then(function(){return q=!1,F.cancelled?void b():(C=r.since,void A())})["catch"](function(e){throw q=!1,y("writeCheckpoint completed with error",e),e}))))}function u(e,t){var n=t.PouchConstructor;return"string"==typeof e?new n(e,t):e.then?e:l.Promise.resolve(e)}function f(e,t,n,r){"function"==typeof n&&(r=n,n={}),"undefined"==typeof n&&(n={}),n.complete||(n.complete=r||function(){}),n=l.clone(n),n.continuous=n.continuous||n.live,n.retry="retry"in n?n.retry:v,n.PouchConstructor=n.PouchConstructor||this;var o=new s(n);return u(e,n).then(function(e){return u(t,n).then(function(t){return a(e,t,n).then(function(r){c(r,e,t,n,o)})})})["catch"](function(e){o.emit("error",e),n.complete(e)}),o}var l=e(35),d=e(39).EventEmitter,p=e(15),h=50,v=!1;l.inherits(s,d),s.prototype.cancel=function(){this.cancelled=!0,this.state="cancelled",this.emit("cancel")},s.prototype.ready=function(e,t){function n(){o.cancel()}function r(){e.removeListener("destroyed",n),t.removeListener("destroyed",n)}var o=this;e.once("destroyed",n),t.once("destroyed",n),this.then(r,r)},n.toPouch=u,n.replicate=f},{15:15,35:35,39:39}],32:[function(e,t,n){"use strict";var r=e(16),o=e(35),i=o.Promise,s=e(39).EventEmitter;r.adapters={},r.preferredAdapters=e(9),r.prefix="_pouch_";var a=new s,c=["on","addListener","emit","listeners","once","removeAllListeners","removeListener","setMaxListeners"];c.forEach(function(e){r[e]=a[e].bind(a)}),r.setMaxListeners(0),r.parseAdapter=function(e,t){var n,i,s=e.match(/([a-z\-]*):\/\/(.*)/);if(s){if(e=/http(s?)/.test(s[1])?s[1]+"://"+s[2]:s[2],n=s[1],!r.adapters[n].valid())throw"Invalid adapter";return{name:e,adapter:s[1]}}var a="idb"in r.adapters&&"websql"in r.adapters&&o.hasLocalStorage()&&localStorage["_pouch__websqldb_"+r.prefix+e];if("undefined"!=typeof t&&t.db)i="leveldb";else for(var c=0;c<r.preferredAdapters.length;++c)if(i=r.preferredAdapters[c],i in r.adapters){if(a&&"idb"===i)continue;break}if(n=r.adapters[i],i&&n){var u="use_prefix"in n?n.use_prefix:!0;return{name:u?r.prefix+e:e,adapter:i}}throw"No valid adapter found"},r.destroy=o.toPromise(function(e,t,n){function s(){u.destroy(d,t,function(t,o){t?n(t):(r.emit("destroyed",e),r.emit(e,"destroyed"),n(null,o||{ok:!0}))})}("function"==typeof t||"undefined"==typeof t)&&(n=t,t={}),e&&"object"==typeof e&&(t=e,e=void 0),t.internal||console.log("PouchDB.destroy() is deprecated and will be removed. Please use db.destroy() instead.");var a=r.parseAdapter(t.name||e,t),c=a.name,u=r.adapters[a.adapter],f="use_prefix"in u?u.use_prefix:!0,l=f?c.replace(new RegExp("^"+r.prefix),""):c,d=("http"===a.adapter||"https"===a.adapter?"":t.prefix||"")+c,p=o.extend(!0,{},t,{adapter:a.adapter});new r(l,p,function(e,a){return e?n(e):void a.get("_local/_pouch_dependentDbs",function(e,c){if(e)return 404!==e.status?n(e):s();var u=c.dependentDbs,l=Object.keys(u).map(function(e){var n=f?e.replace(new RegExp("^"+r.prefix),""):e,i=o.extend(!0,t,a.__opts||{});return a.constructor.destroy(n,i)});i.all(l).then(s,function(e){n(e)})})})}),r.adapter=function(e,t){t.valid()&&(r.adapters[e]=t)},r.plugin=function(e){Object.keys(e).forEach(function(t){r.prototype[t]=e[t]})},r.defaults=function(e){function t(t,n,i){("function"==typeof n||"undefined"==typeof n)&&(i=n,n={}),t&&"object"==typeof t&&(n=t,t=void 0),n=o.extend(!0,{},e,n),r.call(this,t,n,i)}return o.inherits(t,r),t.destroy=o.toPromise(function(t,n,i){return("function"==typeof n||"undefined"==typeof n)&&(i=n,n={}),t&&"object"==typeof t&&(n=t,t=void 0),n=o.extend(!0,{},e,n),r.destroy(t,n,i)}),c.forEach(function(e){t[e]=a[e].bind(a)}),t.setMaxListeners(0),t.preferredAdapters=r.preferredAdapters.slice(),Object.keys(r).forEach(function(e){e in t||(t[e]=r[e])}),t},t.exports=r},{16:16,35:35,39:39,9:9}],33:[function(e,t,n){"use strict";function r(e,t,n,r){return"function"==typeof n&&(r=n,n={}),"undefined"==typeof n&&(n={}),n=i.clone(n),n.PouchConstructor=n.PouchConstructor||this,e=s.toPouch(e,n),t=s.toPouch(t,n),new o(e,t,n,r)}function o(e,t,n,r){function o(e){v||(v=!0,d.emit("cancel",e))}function s(e){d.emit("change",{direction:"pull",change:e})}function c(e){d.emit("change",{direction:"push",change:e})}function u(e){d.emit("denied",{direction:"push",doc:e})}function f(e){d.emit("denied",{direction:"pull",doc:e})}function l(e){return function(t,n){var r="change"===t&&(n===s||n===c),i="cancel"===t&&n===o,a=t in _&&n===_[t];(r||i||a)&&(t in m||(m[t]={}),m[t][e]=!0,2===Object.keys(m[t]).length&&d.removeAllListeners(t))}}var d=this;this.canceled=!1;var p,h;"onChange"in n&&(p=n.onChange,delete n.onChange),"function"!=typeof r||n.complete?"complete"in n&&(h=n.complete,delete n.complete):h=r,this.push=a(e,t,n),this.pull=a(t,e,n);var v=!1,_={},m={};n.live&&(this.push.on("complete",d.pull.cancel.bind(d.pull)),this.pull.on("complete",d.push.cancel.bind(d.push))),this.on("newListener",function(e){"change"===e?(d.pull.on("change",s),d.push.on("change",c)):"denied"===e?(d.pull.on("denied",f),d.push.on("denied",u)):"cancel"===e?(d.pull.on("cancel",o),d.push.on("cancel",o)):"error"===e||"removeListener"===e||"complete"===e||e in _||(_[e]=function(t){d.emit(e,t)},d.pull.on(e,_[e]),d.push.on(e,_[e]))}),this.on("removeListener",function(e){"change"===e?(d.pull.removeListener("change",s),d.push.removeListener("change",c)):"cancel"===e?(d.pull.removeListener("cancel",o),d.push.removeListener("cancel",o)):e in _&&"function"==typeof _[e]&&(d.pull.removeListener(e,_[e]),d.push.removeListener(e,_[e]),delete _[e])}),this.pull.on("removeListener",l("pull")),this.push.on("removeListener",l("push"));var g=i.Promise.all([this.push,this.pull]).then(function(e){var t={push:e[0],pull:e[1]};return d.emit("complete",t),h&&h(null,t),d.removeAllListeners(),t},function(e){throw d.cancel(),d.emit("error",e),h&&h(e),d.removeAllListeners(),e});this.then=function(e,t){return g.then(e,t)},this["catch"]=function(e){return g["catch"](e)}}var i=e(35),s=e(31),a=s.replicate,c=e(39).EventEmitter;i.inherits(o,c),t.exports=r,o.prototype.cancel=function(){this.canceled||(this.canceled=!0,this.push.cancel(),this.pull.cancel())}},{31:31,35:35,39:39}],34:[function(e,t,n){"use strict";function r(){this.isReady=!1,this.failed=!1,this.queue=[]}t.exports=r,r.prototype.execute=function(){var e,t;if(this.failed)for(;e=this.queue.shift();)"function"!=typeof e?(t=e.parameters[e.parameters.length-1],"function"==typeof t?t(this.failed):"changes"===e.name&&"function"==typeof t.complete&&t.complete(this.failed)):e(this.failed);else if(this.isReady)for(;e=this.queue.shift();)"function"==typeof e?e():e.task=this.db[e.name].apply(this.db,e.parameters)},r.prototype.fail=function(e){this.failed=e,this.execute()},r.prototype.ready=function(e){return this.failed?!1:0===arguments.length?this.isReady:(this.isReady=e?!0:!1,this.db=e,void this.execute())},r.prototype.addTask=function(e,t){if("function"!=typeof e){var n={name:e,parameters:t};return this.queue.push(n),this.failed&&this.execute(),n}this.queue.push(e),this.failed&&this.execute()}},{}],35:[function(e,t,n){(function(t,r){function o(){return"undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage&&"undefined"!=typeof chrome.storage.local}function i(){if(!(this instanceof i))return new i;var e=this;u.call(this),this.isChrome=o(),this.listeners={},this.hasLocal=!1,this.isChrome||(this.hasLocal=n.hasLocalStorage()),this.isChrome?chrome.storage.onChanged.addListener(function(t){null!=t.db_name&&e.emit(t.dbName.newValue)}):this.hasLocal&&("undefined"!=typeof addEventListener?addEventListener("storage",function(t){e.emit(t.key)}):window.attachEvent("storage",function(t){e.emit(t.key)}))}var s=e(30);n.extend=e(66),n.ajax=e(17),n.createBlob=e(18),n.uuid=e(27),n.getArguments=e(37);var a=e(19),c=e(20),u=e(39).EventEmitter,f=e(65);n.Map=f.Map,n.Set=f.Set;var l=e(22);n.Promise="function"==typeof r.Promise?r.Promise:e(48);var d=n.Promise;n.lastIndexOf=function(e,t){for(var n=e.length-1;n>=0;n--)if(e.charAt(n)===t)return n;return-1},n.clone=function(e){return n.extend(!0,{},e)},n.pick=function(e,t){for(var n={},r=0,o=t.length;o>r;r++){var i=t[r];n[i]=e[i]}return n},n.inherits=e(44),n.call=n.getArguments(function(e){if(e.length){var t=e.shift();"function"==typeof t&&t.apply(this,e)}}),n.isLocalId=function(e){return/^_local/.test(e)},n.isDeleted=function(e,t){t||(t=s.winningRev(e));var n=t.indexOf("-");-1!==n&&(t=t.substring(n+1));var r=!1;return s.traverseRevTree(e.rev_tree,function(e,n,o,i,s){o===t&&(r=!!s.deleted)}),r},n.revExists=function(e,t){var n=!1;return s.traverseRevTree(e.rev_tree,function(e,r,o){r+"-"+o===t&&(n=!0)}),n},n.filterChange=function(e){var t={},n=e.filter&&"function"==typeof e.filter;return t.query=e.query_params,function(r){if(r.doc||(r.doc={}),e.filter&&n&&!e.filter.call(this,r.doc,t))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}},n.parseDoc=l.parseDoc,n.invalidIdError=l.invalidIdError,n.isCordova=function(){return"undefined"!=typeof cordova||"undefined"!=typeof PhoneGap||"undefined"!=typeof phonegap},n.hasLocalStorage=function(){if(o())return!1;try{return localStorage}catch(e){return!1}},n.Changes=i,n.inherits(i,u),i.prototype.addListener=function(e,r,o,i){function s(){if(a.listeners[r]){if(c)return void(c="waiting");c=!0,o.changes({style:i.style,include_docs:i.include_docs,attachments:i.attachments,conflicts:i.conflicts,continuous:!1,descending:!1,filter:i.filter,doc_ids:i.doc_ids,view:i.view,since:i.since,query_params:i.query_params}).on("change",function(e){e.seq>i.since&&!i.cancelled&&(i.since=e.seq,n.call(i.onChange,e))}).on("complete",function(){"waiting"===c&&t.nextTick(function(){a.notify(e)}),c=!1}).on("error",function(){c=!1})}}if(!this.listeners[r]){var a=this,c=!1;this.listeners[r]=s,this.on(e,s)}},i.prototype.removeListener=function(e,t){t in this.listeners&&u.prototype.removeListener.call(this,e,this.listeners[t])},i.prototype.notifyLocalWindows=function(e){this.isChrome?chrome.storage.local.set({dbName:e}):this.hasLocal&&(localStorage[e]="a"===localStorage[e]?"b":"a")},i.prototype.notify=function(e){this.emit(e),this.notifyLocalWindows(e)},n.atob="function"==typeof atob?function(e){return atob(e)}:function(e){var t=new a(e,"base64");if(t.toString("base64")!==e)throw"Cannot base64 encode full string";return t.toString("binary")},n.btoa="function"==typeof btoa?function(e){return btoa(e)}:function(e){return new a(e,"binary").toString("base64")},n.fixBinary=function(e){if(!t.browser)return e;for(var n=e.length,r=new ArrayBuffer(n),o=new Uint8Array(r),i=0;n>i;i++)o[i]=e.charCodeAt(i);return r},n.readAsBinaryString=function(e,t){var r=new FileReader,o="function"==typeof r.readAsBinaryString;r.onloadend=function(e){var r=e.target.result||"";return o?t(r):void t(n.arrayBufferToBinaryString(r))},o?r.readAsBinaryString(e):r.readAsArrayBuffer(e)},n.readAsArrayBuffer=function(e,t){var n=new FileReader;n.onloadend=function(e){var n=e.target.result||new ArrayBuffer(0);t(n)},n.readAsArrayBuffer(e)},n.once=function(e){var t=!1;return n.getArguments(function(n){if(t)throw new Error("once called  more than once");t=!0,e.apply(this,n)})},n.toPromise=function(e){return n.getArguments(function(r){var o,i=this,s="function"==typeof r[r.length-1]?r.pop():!1;s&&(o=function(e,n){t.nextTick(function(){s(e,n)})});var a=new d(function(t,o){var s;try{var a=n.once(function(e,n){e?o(e):t(n)});r.push(a),s=e.apply(i,r),s&&"function"==typeof s.then&&t(s)}catch(c){o(c)}});return o&&a.then(function(e){o(null,e)},o),a.cancel=function(){return this},a})},n.adapterFun=function(t,r){function o(e,t,n){if(i.enabled){for(var r=[e._db_name,t],o=0;o<n.length-1;o++)r.push(n[o]);i.apply(null,r);var s=n[n.length-1];n[n.length-1]=function(n,r){var o=[e._db_name,t];o=o.concat(n?["error",n]:["success",r]),i.apply(null,o),s(n,r)}}}var i=e(41)("pouchdb:api");return n.toPromise(n.getArguments(function(e){if(this._closed)return d.reject(new Error("database is closed"));var i=this;return o(i,t,e),this.taskqueue.isReady?r.apply(this,e):new n.Promise(function(n,r){i.taskqueue.addTask(function(o){o?r(o):n(i[t].apply(i,e))})})}))},n.arrayBufferToBinaryString=function(e){for(var t="",n=new Uint8Array(e),r=n.byteLength,o=0;r>o;o++)t+=String.fromCharCode(n[o]);return t},n.cancellableFun=function(e,t,r){r=r?n.clone(!0,{},r):{};var o=new u,i=r.complete||function(){},s=r.complete=n.once(function(e,t){e?i(e):(o.emit("end",t),i(null,t)),o.removeAllListeners()}),a=r.onChange||function(){},c=0;t.on("destroyed",function(){o.removeAllListeners()}),r.onChange=function(e){a(e),e.seq<=c||(c=e.seq,o.emit("change",e),e.deleted?o.emit("delete",e):1===e.changes.length&&"1-"===e.changes[0].rev.slice(0,1)?o.emit("create",e):o.emit("update",e))};var f=new d(function(e,t){r.complete=function(n,r){n?t(n):e(r)}});return f.then(function(e){s(null,e)},s),f.cancel=function(){f.isCancelled=!0,t.taskqueue.isReady&&r.complete(null,{status:"cancelled"})},t.taskqueue.isReady?e(t,r,f):t.taskqueue.addTask(function(){f.isCancelled?r.complete(null,{status:"cancelled"}):e(t,r,f)}),f.on=o.on.bind(o),f.once=o.once.bind(o),f.addListener=o.addListener.bind(o),f.removeListener=o.removeListener.bind(o),f.removeAllListeners=o.removeAllListeners.bind(o),f.setMaxListeners=o.setMaxListeners.bind(o),f.listeners=o.listeners.bind(o),f.emit=o.emit.bind(o),f},n.MD5=n.toPromise(e(21)),n.explain404=function(e){t.browser&&"console"in r&&"info"in console&&console.info("The above 404 is totally normal. "+e)},n.info=function(e){"undefined"!=typeof console&&"info"in console&&console.info(e)},n.parseUri=e(24),n.compare=function(e,t){return t>e?-1:e>t?1:0},n.updateDoc=function(e,t,r,o,i,a,u){if(n.revExists(e,t.metadata.rev))return r[o]=t,i();var f=s.winningRev(e),l=n.isDeleted(e,f),d=n.isDeleted(t.metadata),p=/^1-/.test(t.metadata.rev);if(l&&!d&&u&&p){var h=t.data;h._rev=f,h._id=t.metadata.id,t=n.parseDoc(h,u)}var v=s.merge(e.rev_tree,t.metadata.rev_tree[0],1e3),_=u&&(l&&d||!l&&"new_leaf"!==v.conflicts||l&&!d&&"new_branch"===v.conflicts);if(_){var m=c.error(c.REV_CONFLICT);return r[o]=m,i()}var g=t.metadata.rev;t.metadata.rev_tree=v.tree,e.rev_map&&(t.metadata.rev_map=e.rev_map);var y=s.winningRev(t.metadata),b=n.isDeleted(t.metadata,y),E=l===b?0:b>l?-1:1,w=n.isDeleted(t.metadata,g);a(t,y,b,w,!0,E,o,i)},n.processDocs=function(e,t,r,o,i,a,u,f){function l(e,t,r){var o=s.winningRev(e.metadata),f=n.isDeleted(e.metadata,o);if("was_delete"in u&&f)return i[t]=c.error(c.MISSING_DOC,"deleted"),r();var l=f?0:1;a(e,o,f,f,!1,l,t,r)}function d(){++v===_&&f&&f()}if(e.length){var p=u.new_edits,h=new n.Map,v=0,_=e.length;e.forEach(function(e,r){if(e._id&&n.isLocalId(e._id))return void t[e._deleted?"_removeLocal":"_putLocal"](e,{ctx:o},function(e){i[r]=e?e:{ok:!0},d()});var s=e.metadata.id;h.has(s)?(_--,h.get(s).push([e,r])):h.set(s,[[e,r]])}),h.forEach(function(e,t){function o(){++c<e.length?s():d()}function s(){var s=e[c],u=s[0],f=s[1];r.has(t)?n.updateDoc(r.get(t),u,i,f,o,a,p):l(u,f,o)}var c=0;s()})}},n.preprocessAttachments=function(e,t,r){function o(e){try{return n.atob(e)}catch(t){var r=c.error(c.BAD_ARG,"Attachments need to be base64 encoded");return{error:r}}}function i(e,r){if(e.stub)return r();if("string"==typeof e.data){var i=o(e.data);if(i.error)return r(i.error);e.length=i.length,e.data="blob"===t?n.createBlob([n.fixBinary(i)],{type:e.content_type}):"base64"===t?n.btoa(i):i,n.MD5(i).then(function(t){e.digest="md5-"+t,r()})}else n.readAsArrayBuffer(e.data,function(o){"binary"===t?e.data=n.arrayBufferToBinaryString(o):"base64"===t&&(e.data=n.btoa(n.arrayBufferToBinaryString(o))),n.MD5(o).then(function(t){e.digest="md5-"+t,e.length=o.byteLength,r()})})}function s(){u++,e.length===u&&(a?r(a):r())}if(!e.length)return r();var a,u=0;e.forEach(function(e){function t(e){a=e,r++,r===n.length&&s()}var n=e.data&&e.data._attachments?Object.keys(e.data._attachments):[],r=0;if(!n.length)return s();for(var o in e.data._attachments)e.data._attachments.hasOwnProperty(o)&&i(e.data._attachments[o],t)})},n.compactTree=function(e){var t=[];return s.traverseRevTree(e.rev_tree,function(e,n,r,o,i){"available"!==i.status||e||(t.push(n+"-"+r),i.status="missing")}),t};var p=e(75);n.safeJsonParse=function(e){try{return JSON.parse(e)}catch(t){return p.parse(e)}},n.safeJsonStringify=function(e){try{return JSON.stringify(e)}catch(t){return p.stringify(e)}}}).call(this,e(40),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{17:17,18:18,19:19,20:20,21:21,22:22,24:24,27:27,30:30,37:37,39:39,40:40,41:41,44:44,48:48,65:65,66:66,75:75}],36:[function(e,t,n){t.exports="3.4.0"},{}],37:[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},{}],38:[function(e,t,n){},{}],39:[function(e,t,n){function r(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function o(e){return"function"==typeof e}function i(e){return"number"==typeof e}function 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(!i(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.prototype.emit=function(e){var t,n,r,i,c,u;if(this._events||(this._events={}),"error"===e&&(!this._events.error||s(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;throw TypeError('Uncaught, unspecified "error" event.')}if(n=this._events[e],a(n))return!1;if(o(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:for(r=arguments.length,i=new Array(r-1),c=1;r>c;c++)i[c-1]=arguments[c];n.apply(this,i)}else if(s(n)){for(r=arguments.length,i=new Array(r-1),c=1;r>c;c++)i[c-1]=arguments[c];for(u=n.slice(),r=u.length,c=0;r>c;c++)u[c].apply(this,i)}return!0},r.prototype.addListener=function(e,t){var n;if(!o(t))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,o(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){var n;n=a(this._maxListeners)?r.defaultMaxListeners:this._maxListeners,n&&n>0&&this._events[e].length>n&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace())}return 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,a;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(s(n)){for(a=i;a-->0;)if(n[a]===t||n[a].listener&&n[a].listener===t){r=a;break}if(0>r)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(r,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],o(n))this.removeListener(e,n);else for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},r.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?o(this._events[e])?[this._events[e]]:this._events[e].slice():[]},r.listenerCount=function(e,t){var n;return n=e._events&&e._events[t]?o(e._events[t])?1:e._events[t].length:0}},{}],40:[function(e,t,n){function r(){}var o=t.exports={};o.nextTick=function(){var e="undefined"!=typeof window&&window.setImmediate,t="undefined"!=typeof window&&window.MutationObserver,n="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(e)return function(e){return window.setImmediate(e)};var r=[];if(t){var o=document.createElement("div"),i=new MutationObserver(function(){var e=r.slice();r.length=0,e.forEach(function(e){e()})});return i.observe(o,{attributes:!0}),function(e){r.length||o.setAttribute("yes","no"),r.push(e)}}return n?(window.addEventListener("message",function(e){var t=e.source;if((t===window||null===t)&&"process-tick"===e.data&&(e.stopPropagation(),r.length>0)){var n=r.shift();n()}},!0),function(e){r.push(e),window.postMessage("process-tick","*")}):function(e){setTimeout(e,0)}}(),o.title="browser",o.browser=!0,o.env={},o.argv=[],o.on=r,o.addListener=r,o.once=r,o.off=r,o.removeListener=r,o.removeAllListeners=r,o.emit=r,o.binding=function(e){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(e){throw new Error("process.chdir is not supported")}},{}],41:[function(e,t,n){function r(){return"WebkitAppearance"in document.documentElement.style||window.console&&(console.firebug||console.exception&&console.table)||navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31}function o(){var e=arguments,t=this.useColors;if(e[0]=(t?"%c":"")+this.namespace+(t?" %c":" ")+e[0]+(t?"%c ":" ")+"+"+n.humanize(this.diff),!t)return e;var r="color: "+this.color;e=[e[0],r,"color: inherit"].concat(Array.prototype.slice.call(e,1));var o=0,i=0;return e[0].replace(/%[a-z%]/g,function(e){"%"!==e&&(o++,"%c"===e&&(i=o))}),e.splice(i,0,r),e}function i(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function s(e){try{null==e?u.removeItem("debug"):u.debug=e}catch(t){}}function a(){var e;try{e=u.debug}catch(t){}return e}function c(){try{return window.localStorage}catch(e){}}n=t.exports=e(42),n.log=i,n.formatArgs=o,n.save=s,n.load=a,n.useColors=r;var u;u="undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage?chrome.storage.local:c(),n.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],n.formatters.j=function(e){return JSON.stringify(e)},n.enable(a())},{42:42}],42:[function(e,t,n){function r(){return n.colors[f++%n.colors.length]}function o(e){function t(){}function o(){var e=o,t=+new Date,i=t-(u||t);e.diff=i,e.prev=u,e.curr=t,u=t,null==e.useColors&&(e.useColors=n.useColors()),null==e.color&&e.useColors&&(e.color=r());var s=Array.prototype.slice.call(arguments);s[0]=n.coerce(s[0]),"string"!=typeof s[0]&&(s=["%o"].concat(s));var a=0;s[0]=s[0].replace(/%([a-z%])/g,function(t,r){if("%"===t)return t;a++;var o=n.formatters[r];if("function"==typeof o){var i=s[a];t=o.call(e,i),s.splice(a,1),a--}return t}),"function"==typeof n.formatArgs&&(s=n.formatArgs.apply(e,s));var c=o.log||n.log||console.log.bind(console);c.apply(e,s)}t.enabled=!1,o.enabled=!0;var i=n.enabled(e)?o:t;return i.namespace=e,i}function i(e){n.save(e);for(var t=(e||"").split(/[\s,]+/),r=t.length,o=0;r>o;o++)t[o]&&(e=t[o].replace(/\*/g,".*?"),"-"===e[0]?n.skips.push(new RegExp("^"+e.substr(1)+"$")):n.names.push(new RegExp("^"+e+"$")))}function s(){n.enable("")}function a(e){var t,r;for(t=0,r=n.skips.length;r>t;t++)if(n.skips[t].test(e))return!1;for(t=0,r=n.names.length;r>t;t++)if(n.names[t].test(e))return!0;return!1}function c(e){return e instanceof Error?e.stack||e.message:e}n=t.exports=o,n.coerce=c,n.disable=s,n.enable=i,n.enabled=a,n.humanize=e(43),n.names=[],n.skips=[],n.formatters={};var u,f=0},{43:43}],43:[function(e,t,n){function r(e){var t=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(e);if(t){var n=parseFloat(t[1]),r=(t[2]||"ms").toLowerCase();switch(r){case"years":case"year":case"yrs":case"yr":case"y":return n*l;case"days":case"day":case"d":return n*f;case"hours":case"hour":case"hrs":case"hr":case"h":return n*u;case"minutes":case"minute":case"mins":case"min":case"m":return n*c;case"seconds":case"second":case"secs":case"sec":case"s":return n*a;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n}}}function o(e){return e>=f?Math.round(e/f)+"d":e>=u?Math.round(e/u)+"h":e>=c?Math.round(e/c)+"m":e>=a?Math.round(e/a)+"s":e+"ms"}function i(e){return s(e,f,"day")||s(e,u,"hour")||s(e,c,"minute")||s(e,a,"second")||e+" ms"}function s(e,t,n){return t>e?void 0:1.5*t>e?Math.floor(e/t)+" "+n:Math.ceil(e/t)+" "+n+"s"}var a=1e3,c=60*a,u=60*c,f=24*u,l=365.25*f;t.exports=function(e,t){return t=t||{},"string"==typeof e?r(e):t["long"]?i(e):o(e)}},{}],44:[function(e,t,n){t.exports="function"==typeof Object.create?function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:function(e,t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}},{}],45:[function(e,t,n){"use strict";function r(){}t.exports=r},{}],46:[function(e,t,n){"use strict";function r(e){function t(e,t){function o(e){u[t]=e,++f===n&!r&&(r=!0,c.resolve(d,u))}s(e).then(o,function(e){r||(r=!0,c.reject(d,e))})}if("[object Array]"!==Object.prototype.toString.call(e))return i(new TypeError("must be an array"));var n=e.length,r=!1;if(!n)return s([]);for(var u=new Array(n),f=0,l=-1,d=new o(a);++l<n;)t(e[l],l);return d}var o=e(49),i=e(52),s=e(53),a=e(45),c=e(47);t.exports=r},{45:45,47:47,49:49,52:52,53:53}],47:[function(e,t,n){"use strict";function r(e){var t=e&&e.then;return e&&"object"==typeof e&&"function"==typeof t?function(){t.apply(e,arguments)}:void 0}var o=e(56),i=e(54),s=e(55);n.resolve=function(e,t){var a=o(r,t);if("error"===a.status)return n.reject(e,a.value);var c=a.value;if(c)i.safely(e,c);else{e.state=s.FULFILLED,e.outcome=t;for(var u=-1,f=e.queue.length;++u<f;)e.queue[u].callFulfilled(t)}return e},n.reject=function(e,t){e.state=s.REJECTED,e.outcome=t;for(var n=-1,r=e.queue.length;++n<r;)e.queue[n].callRejected(t);return e}},{54:54,55:55,56:56}],48:[function(e,t,n){t.exports=n=e(49),n.resolve=e(53),n.reject=e(52),n.all=e(46),n.race=e(51)},{46:46,49:49,51:51,52:52,53:53}],49:[function(e,t,n){"use strict";function r(e){if(!(this instanceof r))return new r(e);if("function"!=typeof e)throw new TypeError("resolver must be a function");this.state=a.PENDING,this.queue=[],this.outcome=void 0,e!==i&&s.safely(this,e)}var o=e(57),i=e(45),s=e(54),a=e(55),c=e(50);t.exports=r,r.prototype["catch"]=function(e){return this.then(null,e)},r.prototype.then=function(e,t){if("function"!=typeof e&&this.state===a.FULFILLED||"function"!=typeof t&&this.state===a.REJECTED)return this;var n=new r(i);if(this.state!==a.PENDING){var s=this.state===a.FULFILLED?e:t;o(n,s,this.outcome)}else this.queue.push(new c(n,e,t));return n}},{45:45,50:50,54:54,55:55,57:57}],50:[function(e,t,n){"use strict";function r(e,t,n){this.promise=e,"function"==typeof t&&(this.onFulfilled=t,this.callFulfilled=this.otherCallFulfilled),"function"==typeof n&&(this.onRejected=n,this.callRejected=this.otherCallRejected)}var o=e(47),i=e(57);t.exports=r,r.prototype.callFulfilled=function(e){o.resolve(this.promise,e)},r.prototype.otherCallFulfilled=function(e){i(this.promise,this.onFulfilled,e)},r.prototype.callRejected=function(e){o.reject(this.promise,e)},r.prototype.otherCallRejected=function(e){i(this.promise,this.onRejected,e)}},{47:47,57:57}],51:[function(e,t,n){"use strict";function r(e){function t(e){s(e).then(function(e){r||(r=!0,c.resolve(f,e))},function(e){r||(r=!0,c.reject(f,e))})}if("[object Array]"!==Object.prototype.toString.call(e))return i(new TypeError("must be an array"));var n=e.length,r=!1;if(!n)return s([]);for(var u=-1,f=new o(a);++u<n;)t(e[u]);return f}var o=e(49),i=e(52),s=e(53),a=e(45),c=e(47);t.exports=r},{45:45,47:47,49:49,52:52,53:53}],52:[function(e,t,n){"use strict";function r(e){var t=new o(i);return s.reject(t,e)}var o=e(49),i=e(45),s=e(47);t.exports=r},{45:45,47:47,49:49}],53:[function(e,t,n){"use strict";function r(e){if(e)return e instanceof o?e:s.resolve(new o(i),e);var t=typeof e;switch(t){case"boolean":return a;case"undefined":return u;case"object":return c;case"number":return f;case"string":return l}}var o=e(49),i=e(45),s=e(47);t.exports=r;var a=s.resolve(new o(i),!1),c=s.resolve(new o(i),null),u=s.resolve(new o(i),void 0),f=s.resolve(new o(i),0),l=s.resolve(new o(i),"")},{45:45,47:47,49:49}],54:[function(e,t,n){"use strict";function r(e,t){function n(t){a||(a=!0,o.reject(e,t))}function r(t){a||(a=!0,o.resolve(e,t))}function s(){t(r,n)}var a=!1,c=i(s);"error"===c.status&&n(c.value)}var o=e(47),i=e(56);n.safely=r},{47:47,56:56}],55:[function(e,t,n){n.REJECTED=["REJECTED"],n.FULFILLED=["FULFILLED"],n.PENDING=["PENDING"]},{}],56:[function(e,t,n){"use strict";function r(e,t){var n={};try{n.value=e(t),n.status="success"}catch(r){n.status="error",n.value=r}return n}t.exports=r},{}],57:[function(e,t,n){"use strict";function r(e,t,n){o(function(){var r;try{r=t(n)}catch(o){return i.reject(e,o)}r===e?i.reject(e,new TypeError("Cannot resolve promise with itself")):i.resolve(e,r)})}var o=e(58),i=e(47);t.exports=r},{47:47,58:58}],58:[function(e,t,n){"use strict";function r(){i=!0;for(var e,t,n=c.length;n;){for(t=c,c=[],e=-1;++e<n;)t[e]();n=c.length}i=!1}function o(e){1!==c.push(e)||i||s()}for(var i,s,a=[e(38),e(60),e(59),e(61),e(62)],c=[],u=-1,f=a.length;++u<f;)if(a[u]&&a[u].test&&a[u].test()){s=a[u].install(r);break}t.exports=o},{38:38,59:59,60:60,61:61,62:62}],59:[function(e,t,n){(function(e){"use strict";n.test=function(){return e.setImmediate?!1:"undefined"!=typeof e.MessageChannel},n.install=function(t){var n=new e.MessageChannel;return n.port1.onmessage=t,function(){n.port2.postMessage(0)}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],60:[function(e,t,n){(function(e){"use strict";var t=e.MutationObserver||e.WebKitMutationObserver;n.test=function(){return t},n.install=function(n){var r=0,o=new t(n),i=e.document.createTextNode("");return o.observe(i,{characterData:!0}),function(){i.data=r=++r%2}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],61:[function(e,t,n){(function(e){"use strict";n.test=function(){return"document"in e&&"onreadystatechange"in e.document.createElement("script")},n.install=function(t){return function(){var n=e.document.createElement("script");return n.onreadystatechange=function(){t(),n.onreadystatechange=null,n.parentNode.removeChild(n),n=null},e.document.documentElement.appendChild(n),t}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],62:[function(e,t,n){"use strict";n.test=function(){return!0},n.install=function(e){return function(){setTimeout(e,0)}}},{}],63:[function(e,t,n){"use strict";function r(e){if(null!==e)switch(typeof e){case"boolean":return e?1:0;case"number":return f(e);case"string":return e.replace(/\u0002/g,"").replace(/\u0001/g,"").replace(/\u0000/g,"");case"object":var t=Array.isArray(e),r=t?e:Object.keys(e),o=-1,i=r.length,s="";if(t)for(;++o<i;)s+=n.toIndexableString(r[o]);else for(;++o<i;){var a=r[o];s+=n.toIndexableString(a)+n.toIndexableString(e[a])}return s}return""}function o(e,t){var n,r=t,o="1"===e[t];if(o)n=0,t++;else{var i="0"===e[t];t++;var s="",a=e.substring(t,t+d),c=parseInt(a,10)+l;for(i&&(c=-c),t+=d;;){var u=e[t];if("\x00"===u)break;s+=u,t++}s=s.split("."),n=1===s.length?parseInt(s,10):parseFloat(s[0]+"."+s[1]),i&&(n-=10),0!==c&&(n=parseFloat(n+"e"+c))}return{num:n,length:t-r}}function i(e,t){var n=e.pop();if(t.length){var r=t[t.length-1];n===r.element&&(t.pop(),r=t[t.length-1]);var o=r.element,i=r.index;if(Array.isArray(o))o.push(n);else if(i===e.length-2){var s=e.pop();o[s]=n}else e.push(n)}}function s(e,t){for(var r=Math.min(e.length,t.length),o=0;r>o;o++){var i=n.collate(e[o],t[o]);if(0!==i)return i}return e.length===t.length?0:e.length>t.length?1:-1}function a(e,t){return e===t?0:e>t?1:-1}function c(e,t){for(var r=Object.keys(e),o=Object.keys(t),i=Math.min(r.length,o.length),s=0;i>s;s++){var a=n.collate(r[s],o[s]);if(0!==a)return a;if(a=n.collate(e[r[s]],t[o[s]]),0!==a)return a}return r.length===o.length?0:r.length>o.length?1:-1}function u(e){var t=["boolean","number","string","object"],n=t.indexOf(typeof e);return~n?null===e?1:Array.isArray(e)?5:3>n?n+2:n+3:Array.isArray(e)?5:void 0}function f(e){if(0===e)return"1";var t=e.toExponential().split(/e\+?/),n=parseInt(t[1],10),r=0>e,o=r?"0":"2",i=(r?-n:n)-l,s=h.padLeft(i.toString(),"0",d);o+=p+s;var a=Math.abs(parseFloat(t[0]));r&&(a=10-a);var c=a.toFixed(20);return c=c.replace(/\.?0+$/,""),o+=p+c}var l=-324,d=3,p="",h=e(64);n.collate=function(e,t){if(e===t)return 0;e=n.normalizeKey(e),t=n.normalizeKey(t);var r=u(e),o=u(t);if(r-o!==0)return r-o;if(null===e)return 0;switch(typeof e){case"number":return e-t;case"boolean":return e===t?0:t>e?-1:1;case"string":return a(e,t)}return Array.isArray(e)?s(e,t):c(e,t)},n.normalizeKey=function(e){switch(typeof e){case"undefined":return null;case"number":return e===1/0||e===-(1/0)||isNaN(e)?null:e;case"object":var t=e;if(Array.isArray(e)){var r=e.length;e=new Array(r);for(var o=0;r>o;o++)e[o]=n.normalizeKey(t[o])}else{if(e instanceof Date)return e.toJSON();if(null!==e){e={};for(var i in t)if(t.hasOwnProperty(i)){var s=t[i];"undefined"!=typeof s&&(e[i]=n.normalizeKey(s))}}}}return e},n.toIndexableString=function(e){var t="\x00";return e=n.normalizeKey(e),u(e)+p+r(e)+t},n.parseIndexableString=function(e){for(var t=[],n=[],r=0;;){var s=e[r++];if("\x00"!==s)switch(s){case"1":t.push(null);break;case"2":t.push("1"===e[r]),r++;break;case"3":var a=o(e,r);t.push(a.num),r+=a.length;break;case"4":for(var c="";;){var u=e[r];if("\x00"===u)break;c+=u,r++}c=c.replace(/\u0001\u0001/g,"\x00").replace(/\u0001\u0002/g,"").replace(/\u0002\u0002/g,""),t.push(c);break;case"5":var f={element:[],index:t.length};t.push(f.element),n.push(f);break;case"6":var l={element:{},index:t.length};t.push(l.element),n.push(l);break;default:throw new Error("bad collationIndex or unexpectedly reached end of input: "+s)}else{if(1===t.length)return t.pop();i(t,n)}}}},{64:64}],64:[function(e,t,n){"use strict";function r(e,t,n){for(var r="",o=n-e.length;r.length<o;)r+=t;return r}n.padLeft=function(e,t,n){var o=r(e,t,n);return o+e},n.padRight=function(e,t,n){var o=r(e,t,n);return e+o},n.stringLexCompare=function(e,t){var n,r=e.length,o=t.length;for(n=0;r>n;n++){if(n===o)return 1;var i=e.charAt(n),s=t.charAt(n);if(i!==s)return s>i?-1:1}return o>r?-1:0},n.intToDecimalForm=function(e){var t=0>e,n="";do{var r=t?-Math.ceil(e%10):Math.floor(e%10);n=r+n,e=t?Math.ceil(e/10):Math.floor(e/10)}while(e);return t&&"0"!==n&&(n="-"+n),n}},{}],65:[function(e,t,n){"use strict";function r(){this.store={}}function o(e){if(this.store=new r,e&&Array.isArray(e))for(var t=0,n=e.length;n>t;t++)this.add(e[t])}n.Map=r,n.Set=o,r.prototype.mangle=function(e){if("string"!=typeof e)throw new TypeError("key must be a string but Got "+e);return"$"+e},r.prototype.unmangle=function(e){return e.substring(1)},r.prototype.get=function(e){var t=this.mangle(e);return t in this.store?this.store[t]:void 0},r.prototype.set=function(e,t){var n=this.mangle(e);return this.store[n]=t,!0},r.prototype.has=function(e){var t=this.mangle(e);return t in this.store},r.prototype["delete"]=function(e){var t=this.mangle(e);return t in this.store?(delete this.store[t],!0):!1},r.prototype.forEach=function(e){var t=this,n=Object.keys(t.store);n.forEach(function(n){var r=t.store[n];n=t.unmangle(n),e(r,n)})},o.prototype.add=function(e){return this.store.set(e,!0)},o.prototype.has=function(e){return this.store.has(e)},o.prototype["delete"]=function(e){return this.store["delete"](e)}},{}],66:[function(e,t,n){"use strict";function r(e){return null===e?String(e):"object"==typeof e||"function"==typeof e?u[p.call(e)]||"object":typeof e}function o(e){return null!==e&&e===e.window}function i(e){if(!e||"object"!==r(e)||e.nodeType||o(e))return!1;try{if(e.constructor&&!h.call(e,"constructor")&&!h.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(t){return!1}var n;for(n in e);return void 0===n||h.call(e,n)}function s(e){return"function"===r(e)}function a(){for(var e=[],t=-1,n=arguments.length,r=new Array(n);++t<n;)r[t]=arguments[t];var o={};e.push({args:r,result:{container:o,key:"key"}});for(var i;i=e.pop();)c(e,i.args,i.result);return o.key}function c(e,t,n){var r,o,a,c,u,f,l,d=t[0]||{},p=1,h=t.length,_=!1,m=/\d+/;for("boolean"==typeof d&&(_=d,d=t[1]||{},p=2),"object"==typeof d||s(d)||(d={}),h===p&&(d=this,--p);h>p;p++)if(null!=(r=t[p])){l=v(r);for(o in r)if(!(o in Object.prototype)){if(l&&!m.test(o))continue;if(a=d[o],c=r[o],d===c)continue;_&&c&&(i(c)||(u=v(c)))?(u?(u=!1,f=a&&v(a)?a:[]):f=a&&i(a)?a:{},e.push({args:[_,f,c],result:{container:d,key:o}})):void 0!==c&&(v(r)&&s(c)||(d[o]=c))}}n.container[n.key]=d}for(var u={},f=["Boolean","Number","String","Function","Array","Date","RegExp","Object","Error"],l=0;l<f.length;l++){var d=f[l];u["[object "+d+"]"]=d.toLowerCase()}var p=u.toString,h=u.hasOwnProperty,v=Array.isArray||function(e){return"array"===r(e)};t.exports=a},{}],67:[function(e,t,n){"use strict";var r=e(71),o=e(72),i=o.Promise;t.exports=function(e){var t=e.db,n=e.viewName,s=e.map,a=e.reduce,c=e.temporary,u=s.toString()+(a&&a.toString())+"undefined";if(!c&&t._cachedViews){var f=t._cachedViews[u];if(f)return i.resolve(f)}return t.info().then(function(e){function i(e){e.views=e.views||{};var t=n;-1===t.indexOf("/")&&(t=n+"/"+n);var r=e.views[t]=e.views[t]||{};if(!r[f])return r[f]=!0,e}var f=e.db_name+"-mrview-"+(c?"temp":o.MD5(u));return r(t,"_local/mrviews",i).then(function(){return t.registerDependentDatabase(f).then(function(e){var n=e.db;n.auto_compaction=!0;var r={name:f,db:n,sourceDB:t,adapter:t.adapter,mapFun:s,reduceFun:a};return r.db.get("_local/lastSeq")["catch"](function(e){if(404!==e.status)throw e}).then(function(e){return r.seq=e?e.seq:0,c||(t._cachedViews=t._cachedViews||{},t._cachedViews[u]=r,r.db.on("destroyed",function(){delete t._cachedViews[u]})),r})})})})}},{71:71,72:72}],68:[function(_dereq_,module,exports){"use strict";module.exports=function(func,emit,sum,log,isArray,toJSON){return eval("'use strict'; ("+func.replace(/;\s*$/,"")+");")}},{}],69:[function(e,t,n){(function(t){"use strict";function r(e){return-1===e.indexOf("/")?[e,e]:e.split("/")}function o(e){return 1===e.length&&/^1-/.test(e[0].rev)}function i(e,t){try{e.emit("error",t)}catch(n){console.error("The user's map/reduce function threw an uncaught error.\nYou can debug this error by doing:\nmyDatabase.on('error', function (err) { debugger; });\nPlease double-check your map/reduce function."),console.error(t)}}function s(e,t,n){try{return{output:t.apply(null,n)}}catch(r){return i(e,r),{error:r}}}function a(e,t){var n=I(e.key,t.key);return 0!==n?n:I(e.value,t.value)}function c(e,t,n){return n=n||0,"number"==typeof t?e.slice(n,t+n):n>0?e.slice(n):e}function u(e){var t=e.value,n=t&&"object"==typeof t&&t._id||e.id;return n}function f(e){var t="builtin "+e+" function requires map values to be numbers or number arrays";return new q(t)}function l(e){for(var t=0,n=0,r=e.length;r>n;n++){var o=e[n];if("number"!=typeof o){if(!Array.isArray(o))throw f("_sum");t="number"==typeof t?[t]:t;for(var i=0,s=o.length;s>i;i++){var a=o[i];if("number"!=typeof a)throw f("_sum");"undefined"==typeof t[i]?t.push(a):t[i]+=a}}else"number"==typeof t?t+=o:t[0]+=o}return t}function d(e,t,n,r){var o=t[e];"undefined"!=typeof o&&(r&&(o=encodeURIComponent(JSON.stringify(o))),n.push(e+"="+o))}function p(e,t){var n=e.descending?"endkey":"startkey",r=e.descending?"startkey":"endkey";if("undefined"!=typeof e[n]&&"undefined"!=typeof e[r]&&I(e[n],e[r])>0)throw new O("No rows can match your key range, reverse your start_key and end_key or set {descending : true}");if(t.reduce&&e.reduce!==!1){if(e.include_docs)throw new O("{include_docs:true} is invalid for reduce");if(e.keys&&e.keys.length>1&&!e.group&&!e.group_level)throw new O("Multi-key fetches for reduce views must use {group: true}")}if(e.group_level){if("number"!=typeof e.group_level)throw new O('Invalid value for integer: "'+e.group_level+'"');if(e.group_level<0)throw new O('Invalid value for positive integer: "'+e.group_level+'"');

}}function h(e,t,n){var o,i=[],s="GET";if(d("reduce",n,i),d("include_docs",n,i),d("attachments",n,i),d("limit",n,i),d("descending",n,i),d("group",n,i),d("group_level",n,i),d("skip",n,i),d("stale",n,i),d("conflicts",n,i),d("startkey",n,i,!0),d("endkey",n,i,!0),d("inclusive_end",n,i),d("key",n,i,!0),i=i.join("&"),i=""===i?"":"?"+i,"undefined"!=typeof n.keys){var a=2e3,c="keys="+encodeURIComponent(JSON.stringify(n.keys));c.length+i.length+1<=a?i+=("?"===i[0]?"&":"?")+c:(s="POST","string"==typeof t?o=JSON.stringify({keys:n.keys}):t.keys=n.keys)}if("string"==typeof t){var u=r(t);return e.request({method:s,url:"_design/"+u[0]+"/_view/"+u[1]+i,body:o})}return o=o||{},Object.keys(t).forEach(function(e){o[e]=Array.isArray(t[e])?t[e]:t[e].toString()}),e.request({method:"POST",url:"_temp_view"+i,body:o})}function v(e){return function(t){if(404===t.status)return e;throw t}}function _(e,t,n){function r(){return o(l)?P.resolve(c):t.db.get(a)["catch"](v(c))}function i(e){return e.keys.length?t.db.allDocs({keys:e.keys,include_docs:!0}):P.resolve({rows:[]})}function s(e,t){for(var n=[],r={},o=0,i=t.rows.length;i>o;o++){var s=t.rows[o],a=s.doc;if(a&&(n.push(a),r[a._id]=!0,a._deleted=!f[a._id],!a._deleted)){var c=f[a._id];"value"in c&&(a.value=c.value)}}var u=Object.keys(f);return u.forEach(function(e){if(!r[e]){var t={_id:e},o=f[e];"value"in o&&(t.value=o.value),n.push(t)}}),e.keys=F.uniq(u.concat(e.keys)),n.push(e),n}var a="_local/doc_"+e,c={_id:a,keys:[]},u=n[e],f=u.indexableKeysToKeyValues,l=u.changes;return r().then(function(e){return i(e).then(function(t){return s(e,t)})})}function m(e,t,n){var r="_local/lastSeq";return e.db.get(r)["catch"](v({_id:r,seq:0})).then(function(r){var o=Object.keys(t);return P.all(o.map(function(n){return _(n,e,t)})).then(function(t){var o=F.flatten(t);return r.seq=n,o.push(r),e.db.bulkDocs({docs:o})})})}function g(e){var t="string"==typeof e?e:e.name,n=M[t];return n||(n=M[t]=new C),n}function y(e){return F.sequentialize(g(e),function(){return b(e)})()}function b(e){function t(e,t){var n={id:o._id,key:N(e)};"undefined"!=typeof t&&null!==t&&(n.value=N(t)),r.push(n)}function n(t,n){return function(){return m(e,t,n)}}var r,o,i;if("function"==typeof e.mapFun&&2===e.mapFun.length){var c=e.mapFun;i=function(e){return c(e,t)}}else i=B(e.mapFun.toString(),t,l,R,Array.isArray,JSON.parse);var u=e.seq||0,f=new C;return new P(function(t,c){function l(){f.finish().then(function(){e.seq=u,t()})}function d(){function t(e){c(e)}e.sourceDB.changes({conflicts:!0,include_docs:!0,style:"all_docs",since:u,limit:J}).on("complete",function(t){var c=t.results;if(!c.length)return l();for(var p={},h=0,v=c.length;v>h;h++){var _=c[h];if("_"!==_.doc._id[0]){r=[],o=_.doc,o._deleted||s(e.sourceDB,i,[o]),r.sort(a);for(var m,g={},y=0,b=r.length;b>y;y++){var E=r[y],w=[E.key,E.id];0===I(E.key,m)&&w.push(y);var S=L(w);g[S]=E,m=E.key}p[_.doc._id]={indexableKeysToKeyValues:g,changes:_.changes}}u=_.seq}return f.add(n(p,u)),c.length<J?l():d()}).on("error",t)}d()})}function E(e,t,n){0===n.group_level&&delete n.group_level;var r,o=n.group||n.group_level;r=H[e.reduceFun]?H[e.reduceFun]:B(e.reduceFun.toString(),null,l,R,Array.isArray,JSON.parse);var i=[],a=n.group_level;t.forEach(function(e){var t=i[i.length-1],n=o?e.key:null;return o&&Array.isArray(n)&&"number"==typeof a&&(n=n.length>a?n.slice(0,a):n),t&&0===I(t.key[0][0],n)?(t.key.push([n,e.id]),void t.value.push(e.value)):void i.push({key:[[n,e.id]],value:[e.value]})});for(var u=0,f=i.length;f>u;u++){var d=i[u],p=s(e.sourceDB,r,[d.key,d.value,!1]);if(p.error&&p.error instanceof q)throw p.error;d.value=p.error?null:p.output,d.key=d.key[0][0]}return{rows:c(i,n.limit,n.skip)}}function w(e,t){return F.sequentialize(g(e),function(){return S(e,t)})()}function S(e,t){function n(t){return t.include_docs=!0,e.db.allDocs(t).then(function(e){return o=e.total_rows,e.rows.map(function(e){if("value"in e.doc&&"object"==typeof e.doc.value&&null!==e.doc.value){var t=Object.keys(e.doc.value).sort(),n=["id","key","value"];if(!(n>t||t>n))return e.doc.value}var r=D.parseIndexableString(e.doc._id);return{key:r[0],id:r[1],value:"value"in e.doc?e.doc.value:null}})})}function r(n){var r;if(r=i?E(e,n,t):{total_rows:o,offset:s,rows:n},t.include_docs){var a=F.uniq(n.map(u));return e.sourceDB.allDocs({keys:a,include_docs:!0,conflicts:t.conflicts,attachments:t.attachments}).then(function(e){var t={};return e.rows.forEach(function(e){e.doc&&(t["$"+e.id]=e.doc)}),n.forEach(function(e){var n=u(e),r=t["$"+n];r&&(e.doc=r)}),r})}return r}var o,i=e.reduceFun&&t.reduce!==!1,s=t.skip||0;"undefined"==typeof t.keys||t.keys.length||(t.limit=0,delete t.keys);var a=function(e){return e.reduce(function(e,t){return e.concat(t)})};if("undefined"!=typeof t.keys){var c=t.keys,f=c.map(function(e){var t={startkey:L([e]),endkey:L([e,{}])};return n(t)});return P.all(f).then(a).then(r)}var l={descending:t.descending};if("undefined"!=typeof t.startkey&&(l.startkey=L(t.descending?[t.startkey,{}]:[t.startkey])),"undefined"!=typeof t.endkey){var d=t.inclusive_end!==!1;t.descending&&(d=!d),l.endkey=L(d?[t.endkey,{}]:[t.endkey])}if("undefined"!=typeof t.key){var p=L([t.key]),h=L([t.key,{}]);l.descending?(l.endkey=p,l.startkey=h):(l.startkey=p,l.endkey=h)}return i||("number"==typeof t.limit&&(l.limit=t.limit),l.skip=s),n(l).then(r)}function T(e){return e.request({method:"POST",url:"_view_cleanup"})}function A(e){return e.get("_local/mrviews").then(function(t){var n={};Object.keys(t.views).forEach(function(e){var t=r(e),o="_design/"+t[0],i=t[1];n[o]=n[o]||{},n[o][i]=!0});var o={keys:Object.keys(n),include_docs:!0};return e.allDocs(o).then(function(r){var o={};r.rows.forEach(function(e){var r=e.key.substring(8);Object.keys(n[e.key]).forEach(function(n){var i=r+"/"+n;t.views[i]||(i=n);var s=Object.keys(t.views[i]),a=e.doc&&e.doc.views&&e.doc.views[n];s.forEach(function(e){o[e]=o[e]||a})})});var i=Object.keys(o).filter(function(e){return!o[e]}),s=i.map(function(t){return F.sequentialize(g(t),function(){return new e.constructor(t,e.__opts).destroy()})()});return P.all(s).then(function(){return{ok:!0}})})},v({ok:!0}))}function x(e,n,o){if("http"===e.type())return h(e,n,o);if("string"!=typeof n){p(o,n);var i={db:e,viewName:"temp_view/temp_view",map:n.map,reduce:n.reduce,temporary:!0};return U.add(function(){return j(i).then(function(e){function t(){return e.db.destroy()}return F.fin(y(e).then(function(){return w(e,o)}),t)})}),U.finish()}var s=n,a=r(s),c=a[0],u=a[1];return e.get("_design/"+c).then(function(n){var r=n.views&&n.views[u];if(!r||"string"!=typeof r.map)throw new k("ddoc "+c+" has no view named "+u);p(o,r);var i={db:e,viewName:s,map:r.map,reduce:r.reduce};return j(i).then(function(e){return"ok"===o.stale||"update_after"===o.stale?("update_after"===o.stale&&t.nextTick(function(){y(e)}),w(e,o)):y(e).then(function(){return w(e,o)})})})}function O(e){this.status=400,this.name="query_parse_error",this.message=e,this.error=!0;try{Error.captureStackTrace(this,O)}catch(t){}}function k(e){this.status=404,this.name="not_found",this.message=e,this.error=!0;try{Error.captureStackTrace(this,k)}catch(t){}}function q(e){this.status=500,this.name="invalid_value",this.message=e,this.error=!0;try{Error.captureStackTrace(this,q)}catch(t){}}var R,D=e(63),C=e(70),I=D.collate,L=D.toIndexableString,N=D.normalizeKey,j=e(67),B=e(68);R="undefined"!=typeof console&&"function"==typeof console.log?Function.prototype.bind.call(console.log,console):function(){};var F=e(72),P=F.Promise,M={},U=new C,J=50,H={_sum:function(e,t){return l(t)},_count:function(e,t){return t.length},_stats:function(e,t){function n(e){for(var t=0,n=0,r=e.length;r>n;n++){var o=e[n];t+=o*o}return t}return{sum:l(t),min:Math.min.apply(null,t),max:Math.max.apply(null,t),count:t.length,sumsqr:n(t)}}};n.viewCleanup=F.callbackify(function(){var e=this;return"http"===e.type()?T(e):A(e)}),n.query=function(e,t,n){"function"==typeof t&&(n=t,t={}),t=F.extend(!0,{},t),"function"==typeof e&&(e={map:e});var r=this,o=P.resolve().then(function(){return x(r,e,t)});return F.promisedCallback(o,n),o},F.inherits(O,Error),F.inherits(k,Error),F.inherits(q,Error)}).call(this,e(40))},{40:40,63:63,67:67,68:68,70:70,72:72}],70:[function(e,t,n){"use strict";function r(){this.promise=new o(function(e){e()})}var o=e(72).Promise;r.prototype.add=function(e){return this.promise=this.promise["catch"](function(){}).then(function(){return e()}),this.promise},r.prototype.finish=function(){return this.promise},t.exports=r},{72:72}],71:[function(e,t,n){"use strict";var r=e(73).upsert;t.exports=function(e,t,n){return r.apply(e,[t,n])}},{73:73}],72:[function(e,t,n){(function(t,r){"use strict";n.Promise="function"==typeof r.Promise?r.Promise:e(48),n.inherits=e(44),n.extend=e(66);var o=e(37);n.promisedCallback=function(e,n){return n&&e.then(function(e){t.nextTick(function(){n(null,e)})},function(e){t.nextTick(function(){n(e)})}),e},n.callbackify=function(e){return o(function(t){var r=t.pop(),o=e.apply(this,t);return"function"==typeof r&&n.promisedCallback(o,r),o})},n.fin=function(e,t){return e.then(function(e){var n=t();return"function"==typeof n.then?n.then(function(){return e}):e},function(e){var n=t();if("function"==typeof n.then)return n.then(function(){throw e});throw e})},n.sequentialize=function(e,t){return function(){var n=arguments,r=this;return e.add(function(){return t.apply(r,n)})}},n.flatten=function(e){for(var t=[],n=0,r=e.length;r>n;n++)t=t.concat(e[n]);return t},n.uniq=function(e){for(var t={},n=0,r=e.length;r>n;n++)t["$"+e[n]]=!0;var o=Object.keys(t),i=new Array(o.length);for(n=0,r=o.length;r>n;n++)i[n]=o[n].substring(1);return i};var i=e(38),s=e(74);n.MD5=function(e){return t.browser?s.hash(e):i.createHash("md5").update(e).digest("hex")}}).call(this,e(40),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{37:37,38:38,40:40,44:44,48:48,66:66,74:74}],73:[function(e,t,n){(function(t){"use strict";function r(e,t,n){return new i(function(r,i){return"string"!=typeof t?i(new Error("doc id is required")):void e.get(t,function(s,a){if(s){if(404!==s.status)return i(s);a={}}var c=a._rev,u=n(a);return u?(u._id=t,u._rev=c,void r(o(e,u,n))):r({updated:!1,rev:c})})})}function o(e,t,n){return e.put(t).then(function(e){return{updated:!0,rev:e.rev}},function(o){if(409!==o.status)throw o;return r(e,t._id,n)})}var i;i="undefined"!=typeof window&&window.PouchDB?window.PouchDB.utils.Promise:"function"==typeof t.Promise?t.Promise:e(48),n.upsert=function(e,t,n){var o=this,i=r(o,e,t);return"function"!=typeof n?i:void i.then(function(e){n(null,e)},n)},n.putIfNotExists=function(e,t,n){var o=this;"string"!=typeof e&&(n=t,t=e,e=t._id);var i=function(e){return e._rev?!1:t},s=r(o,e,i);return"function"!=typeof n?s:void s.then(function(e){n(null,e)},n)},"undefined"!=typeof window&&window.PouchDB&&window.PouchDB.plugin(n)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{48:48}],74:[function(e,t,n){!function(e){if("object"==typeof n)t.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var r;try{r=window}catch(o){r=self}r.SparkMD5=e()}}(function(e){"use strict";var t=function(e,t){return e+t&4294967295},n=function(e,n,r,o,i,s){return n=t(t(n,e),t(o,s)),t(n<<i|n>>>32-i,r)},r=function(e,t,r,o,i,s,a){return n(t&r|~t&o,e,t,i,s,a)},o=function(e,t,r,o,i,s,a){return n(t&o|r&~o,e,t,i,s,a)},i=function(e,t,r,o,i,s,a){return n(t^r^o,e,t,i,s,a)},s=function(e,t,r,o,i,s,a){return n(r^(t|~o),e,t,i,s,a)},a=function(e,n){var a=e[0],c=e[1],u=e[2],f=e[3];a=r(a,c,u,f,n[0],7,-680876936),f=r(f,a,c,u,n[1],12,-389564586),u=r(u,f,a,c,n[2],17,606105819),c=r(c,u,f,a,n[3],22,-1044525330),a=r(a,c,u,f,n[4],7,-176418897),f=r(f,a,c,u,n[5],12,1200080426),u=r(u,f,a,c,n[6],17,-1473231341),c=r(c,u,f,a,n[7],22,-45705983),a=r(a,c,u,f,n[8],7,1770035416),f=r(f,a,c,u,n[9],12,-1958414417),u=r(u,f,a,c,n[10],17,-42063),c=r(c,u,f,a,n[11],22,-1990404162),a=r(a,c,u,f,n[12],7,1804603682),f=r(f,a,c,u,n[13],12,-40341101),u=r(u,f,a,c,n[14],17,-1502002290),c=r(c,u,f,a,n[15],22,1236535329),a=o(a,c,u,f,n[1],5,-165796510),f=o(f,a,c,u,n[6],9,-1069501632),u=o(u,f,a,c,n[11],14,643717713),c=o(c,u,f,a,n[0],20,-373897302),a=o(a,c,u,f,n[5],5,-701558691),f=o(f,a,c,u,n[10],9,38016083),u=o(u,f,a,c,n[15],14,-660478335),c=o(c,u,f,a,n[4],20,-405537848),a=o(a,c,u,f,n[9],5,568446438),f=o(f,a,c,u,n[14],9,-1019803690),u=o(u,f,a,c,n[3],14,-187363961),c=o(c,u,f,a,n[8],20,1163531501),a=o(a,c,u,f,n[13],5,-1444681467),f=o(f,a,c,u,n[2],9,-51403784),u=o(u,f,a,c,n[7],14,1735328473),c=o(c,u,f,a,n[12],20,-1926607734),a=i(a,c,u,f,n[5],4,-378558),f=i(f,a,c,u,n[8],11,-2022574463),u=i(u,f,a,c,n[11],16,1839030562),c=i(c,u,f,a,n[14],23,-35309556),a=i(a,c,u,f,n[1],4,-1530992060),f=i(f,a,c,u,n[4],11,1272893353),u=i(u,f,a,c,n[7],16,-155497632),c=i(c,u,f,a,n[10],23,-1094730640),a=i(a,c,u,f,n[13],4,681279174),f=i(f,a,c,u,n[0],11,-358537222),u=i(u,f,a,c,n[3],16,-722521979),c=i(c,u,f,a,n[6],23,76029189),a=i(a,c,u,f,n[9],4,-640364487),f=i(f,a,c,u,n[12],11,-421815835),u=i(u,f,a,c,n[15],16,530742520),c=i(c,u,f,a,n[2],23,-995338651),a=s(a,c,u,f,n[0],6,-198630844),f=s(f,a,c,u,n[7],10,1126891415),u=s(u,f,a,c,n[14],15,-1416354905),c=s(c,u,f,a,n[5],21,-57434055),a=s(a,c,u,f,n[12],6,1700485571),f=s(f,a,c,u,n[3],10,-1894986606),u=s(u,f,a,c,n[10],15,-1051523),c=s(c,u,f,a,n[1],21,-2054922799),a=s(a,c,u,f,n[8],6,1873313359),f=s(f,a,c,u,n[15],10,-30611744),u=s(u,f,a,c,n[6],15,-1560198380),c=s(c,u,f,a,n[13],21,1309151649),a=s(a,c,u,f,n[4],6,-145523070),f=s(f,a,c,u,n[11],10,-1120210379),u=s(u,f,a,c,n[2],15,718787259),c=s(c,u,f,a,n[9],21,-343485551),e[0]=t(a,e[0]),e[1]=t(c,e[1]),e[2]=t(u,e[2]),e[3]=t(f,e[3])},c=function(e){var t,n=[];for(t=0;64>t;t+=4)n[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return n},u=function(e){var t,n=[];for(t=0;64>t;t+=4)n[t>>2]=e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24);return n},f=function(e){var t,n,r,o,i,s,u=e.length,f=[1732584193,-271733879,-1732584194,271733878];for(t=64;u>=t;t+=64)a(f,c(e.substring(t-64,t)));for(e=e.substring(t-64),n=e.length,r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;n>t;t+=1)r[t>>2]|=e.charCodeAt(t)<<(t%4<<3);if(r[t>>2]|=128<<(t%4<<3),t>55)for(a(f,r),t=0;16>t;t+=1)r[t]=0;return o=8*u,o=o.toString(16).match(/(.*?)(.{0,8})$/),i=parseInt(o[2],16),s=parseInt(o[1],16)||0,r[14]=i,r[15]=s,a(f,r),f},l=function(e){var t,n,r,o,i,s,c=e.length,f=[1732584193,-271733879,-1732584194,271733878];for(t=64;c>=t;t+=64)a(f,u(e.subarray(t-64,t)));for(e=c>t-64?e.subarray(t-64):new Uint8Array(0),n=e.length,r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;n>t;t+=1)r[t>>2]|=e[t]<<(t%4<<3);if(r[t>>2]|=128<<(t%4<<3),t>55)for(a(f,r),t=0;16>t;t+=1)r[t]=0;return o=8*c,o=o.toString(16).match(/(.*?)(.{0,8})$/),i=parseInt(o[2],16),s=parseInt(o[1],16)||0,r[14]=i,r[15]=s,a(f,r),f},d=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"],p=function(e){var t,n="";for(t=0;4>t;t+=1)n+=d[e>>8*t+4&15]+d[e>>8*t&15];return n},h=function(e){var t;for(t=0;t<e.length;t+=1)e[t]=p(e[t]);return e.join("")},v=function(e){return h(f(e))},_=function(){this.reset()};return"5d41402abc4b2a76b9719d911017c592"!==v("hello")&&(t=function(e,t){var n=(65535&e)+(65535&t),r=(e>>16)+(t>>16)+(n>>16);return r<<16|65535&n}),_.prototype.append=function(e){return/[\u0080-\uFFFF]/.test(e)&&(e=unescape(encodeURIComponent(e))),this.appendBinary(e),this},_.prototype.appendBinary=function(e){this._buff+=e,this._length+=e.length;var t,n=this._buff.length;for(t=64;n>=t;t+=64)a(this._state,c(this._buff.substring(t-64,t)));return this._buff=this._buff.substr(t-64),this},_.prototype.end=function(e){var t,n,r=this._buff,o=r.length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;o>t;t+=1)i[t>>2]|=r.charCodeAt(t)<<(t%4<<3);return this._finish(i,o),n=e?this._state:h(this._state),this.reset(),n},_.prototype._finish=function(e,t){var n,r,o,i=t;if(e[i>>2]|=128<<(i%4<<3),i>55)for(a(this._state,e),i=0;16>i;i+=1)e[i]=0;n=8*this._length,n=n.toString(16).match(/(.*?)(.{0,8})$/),r=parseInt(n[2],16),o=parseInt(n[1],16)||0,e[14]=r,e[15]=o,a(this._state,e)},_.prototype.reset=function(){return this._buff="",this._length=0,this._state=[1732584193,-271733879,-1732584194,271733878],this},_.prototype.destroy=function(){delete this._state,delete this._buff,delete this._length},_.hash=function(e,t){/[\u0080-\uFFFF]/.test(e)&&(e=unescape(encodeURIComponent(e)));var n=f(e);return t?n:h(n)},_.hashBinary=function(e,t){var n=f(e);return t?n:h(n)},_.ArrayBuffer=function(){this.reset()},_.ArrayBuffer.prototype.append=function(e){var t,n=this._concatArrayBuffer(this._buff,e),r=n.length;for(this._length+=e.byteLength,t=64;r>=t;t+=64)a(this._state,u(n.subarray(t-64,t)));return this._buff=r>t-64?n.subarray(t-64):new Uint8Array(0),this},_.ArrayBuffer.prototype.end=function(e){var t,n,r=this._buff,o=r.length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;o>t;t+=1)i[t>>2]|=r[t]<<(t%4<<3);return this._finish(i,o),n=e?this._state:h(this._state),this.reset(),n},_.ArrayBuffer.prototype._finish=_.prototype._finish,_.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._state=[1732584193,-271733879,-1732584194,271733878],this},_.ArrayBuffer.prototype.destroy=_.prototype.destroy,_.ArrayBuffer.prototype._concatArrayBuffer=function(e,t){var n=e.length,r=new Uint8Array(n+t.byteLength);return r.set(e),r.set(new Uint8Array(t),n),r},_.ArrayBuffer.hash=function(e,t){var n=l(new Uint8Array(e));return t?n:h(n)},_})},{}],75:[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 s=t.pop();o[s]=e}else t.push(e)}n.stringify=function(e){var t=[];t.push({obj:e});for(var n,r,o,i,s,a,c,u,f,l,d,p="";n=t.pop();)if(r=n.obj,o=n.prefix||"",i=n.val||"",p+=o,i)p+=i;else if("object"!=typeof r)p+="undefined"==typeof r?null:JSON.stringify(r);else if(null===r)p+="null";else if(Array.isArray(r)){for(t.push({val:"]"}),s=r.length-1;s>=0;s--)a=0===s?"":",",t.push({obj:r[s],prefix:a});t.push({val:"["})}else{c=[];for(u in r)r.hasOwnProperty(u)&&c.push(u);for(t.push({val:"}"}),s=c.length-1;s>=0;s--)f=c[s],l=r[f],d=s>0?",":"",d+=JSON.stringify(f)+":",t.push({obj:l,prefix:d});t.push({val:"{"})}return p},n.parse=function(e){for(var t,n,o,i,s,a,c,u,f,l=[],d=[],p=0;;)if(t=e[p++],"}"!==t&&"]"!==t&&"undefined"!=typeof t)switch(t){case" ":case"	":case"\n":case":":case",":break;case"n":p+=3,r(null,l,d);break;case"t":p+=3,r(!0,l,d);break;case"f":p+=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="",p--;;){if(o=e[p++],!/[\d\.\-e\+]/.test(o)){p--;break}n+=o}r(parseFloat(n),l,d);break;case'"':for(i="",s=void 0,a=0;;){if(c=e[p++],'"'===c&&("\\"!==s||a%2!==1))break;i+=c,s=c,"\\"===s?a++:a=0}r(JSON.parse('"'+i+'"'),l,d);break;case"[":u={element:[],index:l.length},l.push(u.element),d.push(u);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)}}},{}],76:[function(e,t,n){(function(n){"use strict";var r=e(32);t.exports=r,r.ajax=e(17),r.utils=e(35),r.Errors=e(20),r.replicate=e(31).replicate,r.sync=e(33),r.version=e(36);var o=e(2);if(r.adapter("http",o),r.adapter("https",o),r.adapter("idb",e(8)),r.adapter("websql",e(13)),r.plugin(e(69)),!n.browser){var i=e(38);r.adapter("ldb",i),r.adapter("leveldb",i)}}).call(this,e(40))},{13:13,17:17,2:2,20:20,31:31,32:32,33:33,35:35,36:36,38:38,40:40,69:69,8:8}]},{},[76])(76)});