@petkoneo/phaser3-rex-plugins
Version:
1 lines • 92.9 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).rexcharactercacheplugin=e()}(void 0,(function(){var t={setEventEmitter(t,e){return void 0===e&&(e=Phaser.Events.EventEmitter),this._privateEE=!0===t||void 0===t,this._eventEmitter=this._privateEE?new e:t,this},destroyEventEmitter(){return this._eventEmitter&&this._privateEE&&this._eventEmitter.shutdown(),this},getEventEmitter(){return this._eventEmitter},on(){return this._eventEmitter&&this._eventEmitter.on.apply(this._eventEmitter,arguments),this},once(){return this._eventEmitter&&this._eventEmitter.once.apply(this._eventEmitter,arguments),this},off(){return this._eventEmitter&&this._eventEmitter.off.apply(this._eventEmitter,arguments),this},emit(t){return this._eventEmitter&&t&&this._eventEmitter.emit.apply(this._eventEmitter,arguments),this},addListener(){return this._eventEmitter&&this._eventEmitter.addListener.apply(this._eventEmitter,arguments),this},removeListener(){return this._eventEmitter&&this._eventEmitter.removeListener.apply(this._eventEmitter,arguments),this},removeAllListeners(){return this._eventEmitter&&this._eventEmitter.removeAllListeners.apply(this._eventEmitter,arguments),this},listenerCount(){return this._eventEmitter?this._eventEmitter.listenerCount.apply(this._eventEmitter,arguments):0},listeners(){return this._eventEmitter?this._eventEmitter.listeners.apply(this._eventEmitter,arguments):[]},eventNames(){return this._eventEmitter?this._eventEmitter.eventNames.apply(this._eventEmitter,arguments):[]}};const e=Phaser.Game;var i=function(t){return t instanceof e};const r=Phaser.Scene;var n,s,o=function(t){return t instanceof r},a=function(t){return null==t||"object"!=typeof t?null:i(t)?t:i(t.game)?t.game:o(t)?t.sys.game:o(t.scene)?t.scene.sys.game:void 0},l=function(t,e,i,r,o){if(void 0===n){var l=(h=t.manager.game,a(h).textures.getFrame("__WHITE"));n=l.cutWidth,s=l.cutHeight}var h;return t.stamp("__WHITE",void 0,e,i,{scaleX:r/n,scaleY:o/s,originX:0,originY:0,erase:!0}),t},h=function(t,e,i,r){this.useDynamicTexture?l(this.texture,t,e,i,r):this.context.clearRect(t,e,i,r)},c=function(t,e,i,r,n){var s=this.context;s.save(),s.translate(t,e),n?r.call(n,this.canvas,s,i):r(this.canvas,s,i),s.restore()},u=function(t,e,i,r,n){var s=this.texture;s.camera.setScroll(-t,-e),n?r.call(n,s,i):r(s,i),s.camera.setScroll(0,0)},d={remove(t){var e=this.getFrameIndex(t);return-1===e||(this.addFrameName(e,void 0),this.texture.remove(t)),this},clear(){for(var t,e=this.frameNames.length;t<e;t++){var i=this.frameNames[t];void 0!==i&&(this.addFrameName(index,void 0),this.texture.remove(i))}return this}},p={draw:function(t,e,i){var r=this.getFrameIndex(t);if(-1===r&&(r=this.getFrameIndex(void 0)),-1===r)return console.warn("Does not have free space."),this;var n=this.getTopLeftPosition(r),s=n.x,o=n.y,a=this.cellPadding,l=s+a,d=o+a;h.call(this,s,o,this.outerCellWidth,this.outerCellHeight);var p={width:this.cellWidth,height:this.cellHeight};return(this.useDynamicTexture?u:c).call(this,l,d,p,e,i),this.texture.add(t,0,l,d,p.width,p.height),this.addFrameName(r,t),this},paste:function(t,e){var i;if(this.useDynamicTexture){var r=function(t){return void 0!==t.displayWidth?t.displayWidth:t.width}(e),n=function(t){return void 0!==t.displayHeight?t.displayHeight:t.height}(e);l=r<=this.cellWidth&&n<=this.cellHeight?1:Math.max(r/this.cellWidth,n/this.cellHeight),i=function(t,i){var s=e.originX,o=e.originY,a=e.scaleX,h=e.scaleY;e.setOrigin(0,0).setScale(l,l),t.draw(e),e.setOrigin(s,o).setScale(a,h),i.width=r/l,i.height=n/l}}else{var s=e.canvas;if(!s)return console.warn("Can't get canvas of game object."),this;var o,a;r=s.width,n=s.height;if(r<=this.cellWidth&&n<=this.cellHeight)o=r,a=n;else{var l=Math.max(r/this.cellWidth,n/this.cellHeight);o=r/l,a=n/l}i=function(t,e,i){e.drawImage(s,0,0,o,a),i.width=o,i.height=a}}return this.draw(t,i),this},addEmptyFrame:function(t,e,i){var r;return void 0===e&&(e=this.cellWidth),void 0===i&&(i=this.cellHeight),r=this.useDynamicTexture?function(t,r){r.width=e,r.height=i}:function(t,r,n){n.width=e,n.height=i},this.draw(t,r),this},addToBitmapFont:function(){var t=this.texture.key,e=this.bitmapFontCache.get(t);e||(e={data:{retroFont:!0,font:t,size:this.cellWidth,lineHeight:this.cellHeight,chars:{}},texture:t,frame:null},this.bitmapFontCache.add(t,e));for(var i=e.data.chars,r=this.frameNames,n=0,s=r.length;n<s;n++){var o=r[n];if(void 0!==o){var a=this.texture.get(o),l=a.cutX,h=a.cutY,c=a.cutWidth,u=a.cutHeight;i[o.charCodeAt(0)]={x:l,y:h,width:c,height:u,centerX:l+c/2,centerY:h+u/2,xOffset:0,yOffset:0,xAdvance:c,data:{},kerning:{},u0:a.u0,v0:a.v0,u1:a.u1,v1:a.v1}}}return this}};Object.assign(p,d);const f=Phaser.Utils.Objects.IsPlainObject,y=Phaser.Utils.Objects.GetValue;class v{constructor(t,e,i,r,n,s,o,l){var h,c,u;if(f(e)){var d=e;e=y(d,"key"),i=y(d,"width"),r=y(d,"height"),n=y(d,"cellWidth"),s=y(d,"cellHeight"),u=y(d,"cellPadding",0),h=y(d,"columns"),c=y(d,"rows"),o=y(d,"fillColor"),l=y(d,"useDynamicTexture")}else"boolean"==typeof o&&(l=o,o=void 0);void 0===n&&(n=64),void 0===s&&(s=64),void 0===u&&(u=0),this.cellWidth=n,this.cellHeight=s,this.cellPadding=u,h?i=this.outerCellWidth*h:(void 0===i&&(i=4096),h=Math.floor(i/this.outerCellWidth)),c?r=this.outerCellHeight*c:(void 0===r&&(r=4096),c=Math.floor(r/this.outerCellHeight)),void 0===l&&(l=!1);var p=a(t);if(this.useDynamicTexture=l,this.texture=function(t,e,i,r,n){void 0===n&&(n=!1);var s=(t=a(t)).textures;return s.exists(e)&&s.remove(e),s[n?"addDynamicTexture":"createCanvas"](e,i,r)}(p,e,i,r,l),this.canvas=l?void 0:this.texture.getCanvas(),this.context=l?void 0:this.texture.getContext(),this.bitmapFontCache=p.cache.bitmapFont,void 0!==o)if(l)this.texture.fill(o);else{var v=this.context;v.fillStyle=o,v.fillRect(0,0,this.canvas.width,this.canvas.height)}this.key=e,this.width=i,this.height=r,this.columns=h,this.rows=c,this.totalCount=this.columns*this.rows,this.frameNames=Array(this.totalCount);for(var g=0,m=this.frameNames.length;g<m;g++)this.frameNames[g]=void 0}get outerCellWidth(){return this.cellWidth+2*this.cellPadding}get outerCellHeight(){return this.cellHeight+2*this.cellPadding}destroy(){this.texture=void 0,this.canvas=void 0,this.context=void 0,this.frameNames=void 0,this.bitmapFontCache=void 0}getFrameIndex(t){return this.frameNames.indexOf(t)}contains(t){return-1!==this.getFrameIndex(t)}addFrameName(t,e){return this.frameNames[t]=e,this}get isFull(){return-1===this.getFrameIndex(void 0)}getTopLeftPosition(t,e){void 0===e&&(e={});var i=t%this.columns,r=Math.floor(t/this.columns);return e.x=i*(this.cellWidth+2*this.cellPadding),e.y=r*(this.cellHeight+2*this.cellPadding),e}updateTexture(){return this.useDynamicTexture||this.texture.refresh(),this}}Object.assign(v.prototype,p);const g=Phaser.Utils.Objects.GetValue;var m="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function b(){throw new Error("setTimeout has not been defined")}function w(){throw new Error("clearTimeout has not been defined")}var I=b,x=w;function O(t){if(I===setTimeout)return setTimeout(t,0);if((I===b||!I)&&setTimeout)return I=setTimeout,setTimeout(t,0);try{return I(t,0)}catch(e){try{return I.call(null,t,0)}catch(e){return I.call(this,t,0)}}}"function"==typeof m.setTimeout&&(I=setTimeout),"function"==typeof m.clearTimeout&&(x=clearTimeout);var P,C=[],k=!1,D=-1;function S(){k&&P&&(k=!1,P.length?C=P.concat(C):D=-1,C.length&&A())}function A(){if(!k){var t=O(S);k=!0;for(var e=C.length;e;){for(P=C,C=[];++D<e;)P&&P[D].run();D=-1,e=C.length}P=null,k=!1,function(t){if(x===clearTimeout)return clearTimeout(t);if((x===w||!x)&&clearTimeout)return x=clearTimeout,clearTimeout(t);try{return x(t)}catch(e){try{return x.call(null,t)}catch(e){return x.call(this,t)}}}(t)}}function E(t,e){this.fun=t,this.array=e}E.prototype.run=function(){this.fun.apply(null,this.array)};function j(){}var $=j,z=j,F=j,M=j,q=j,N=j,T=j;var B=m.performance||{},L=B.now||B.mozNow||B.msNow||B.oNow||B.webkitNow||function(){return(new Date).getTime()};var R=new Date;var V={nextTick:function(t){var e=new Array(arguments.length-1);if(arguments.length>1)for(var i=1;i<arguments.length;i++)e[i-1]=arguments[i];C.push(new E(t,e)),1!==C.length||k||O(A)},title:"browser",browser:!0,env:{},argv:[],version:"",versions:{},on:$,addListener:z,once:F,off:M,removeListener:q,removeAllListeners:N,emit:T,binding:function(t){throw new Error("process.binding is not supported")},cwd:function(){return"/"},chdir:function(t){throw new Error("process.chdir is not supported")},umask:function(){return 0},hrtime:function(t){var e=.001*L.call(B),i=Math.floor(e),r=Math.floor(e%1*1e9);return t&&(i-=t[0],(r-=t[1])<0&&(i--,r+=1e9)),[i,r]},platform:"browser",release:{},config:{},uptime:function(){return(new Date-R)/1e3}},W="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function _(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function J(t){if(t.__esModule)return t;var e=t.default;if("function"==typeof e){var i=function t(){return this instanceof t?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};i.prototype=e.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(t).forEach((function(e){var r=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(i,e,r.get?r:{enumerable:!0,get:function(){return t[e]}})})),i}var K,H={exports:{}},U={exports:{}};function G(){return K||(K=1,function(t){t.exports=function(){function t(t,e){if(this.app="loki",this.options=e||{},void 0!==t&&(this.app=t),this.catalog=null,!this.checkAvailability())throw new Error("indexedDB does not seem to be supported for your environment")}function e(t){this.db=null,this.initializeLokiCatalog(t)}return t.prototype.closeDatabase=function(){this.catalog&&this.catalog.db&&(this.catalog.db.close(),this.catalog.db=null)},t.prototype.checkAvailability=function(){return!("undefined"==typeof indexedDB||!indexedDB)},t.prototype.loadDatabase=function(t,i){var r=this.app,n=this;null!==this.catalog&&null!==this.catalog.db?this.catalog.getAppKey(r,t,(function(t){if("function"==typeof i){if(0===t.id)return void i(null);i(t.val)}else console.log(t.val)})):this.catalog=new e((function(e){n.catalog=e,n.loadDatabase(t,i)}))},t.prototype.loadKey=t.prototype.loadDatabase,t.prototype.saveDatabase=function(t,i,r){var n=this.app,s=this;function o(t){t&&!0===t.success?r(null):r(new Error("Error saving database")),s.options.closeAfterSave&&s.closeDatabase()}null!==this.catalog&&null!==this.catalog.db?this.catalog.setAppKey(n,t,i,o):this.catalog=new e((function(e){s.saveDatabase(t,i,o)}))},t.prototype.saveKey=t.prototype.saveDatabase,t.prototype.deleteDatabase=function(t,i){var r=this.app,n=this;null!==this.catalog&&null!==this.catalog.db?this.catalog.getAppKey(r,t,(function(t){var e=t.id;0!==e?n.catalog.deleteAppKey(e,i):"function"==typeof i&&i({success:!0})})):this.catalog=new e((function(e){n.catalog=e,n.deleteDatabase(t,i)}))},t.prototype.deleteKey=t.prototype.deleteDatabase,t.prototype.deleteDatabasePartitions=function(t){var e=this;this.getDatabaseList((function(i){i.forEach((function(i){i.startsWith(t)&&e.deleteDatabase(i)}))}))},t.prototype.getDatabaseList=function(t){var i=this.app,r=this;null!==this.catalog&&null!==this.catalog.db?this.catalog.getAppKeys(i,(function(e){for(var i=[],r=0;r<e.length;r++)i.push(e[r].key);"function"==typeof t?t(i):i.forEach((function(t){console.log(t)}))})):this.catalog=new e((function(e){r.catalog=e,r.getDatabaseList(t)}))},t.prototype.getKeyList=t.prototype.getDatabaseList,t.prototype.getCatalogSummary=function(t){this.app;var i=this;null!==this.catalog&&null!==this.catalog.db?this.catalog.getAllKeys((function(e){for(var i,r,n,s,o,a=[],l=0;l<e.length;l++)n=(i=e[l]).app||"",s=i.key||"",o=i.val||"",r=2*n.length+2*s.length+o.length+1,a.push({app:i.app,key:i.key,size:r});"function"==typeof t?t(a):a.forEach((function(t){console.log(t)}))})):this.catalog=new e((function(e){i.catalog=e,i.getCatalogSummary(t)}))},e.prototype.initializeLokiCatalog=function(t){var e=indexedDB.open("LokiCatalog",1),i=this;e.onupgradeneeded=function(t){var e=t.target.result;if(e.objectStoreNames.contains("LokiAKV")&&e.deleteObjectStore("LokiAKV"),!e.objectStoreNames.contains("LokiAKV")){var i=e.createObjectStore("LokiAKV",{keyPath:"id",autoIncrement:!0});i.createIndex("app","app",{unique:!1}),i.createIndex("key","key",{unique:!1}),i.createIndex("appkey","appkey",{unique:!0})}},e.onsuccess=function(e){i.db=e.target.result,"function"==typeof t&&t(i)},e.onerror=function(t){throw t}},e.prototype.getAppKey=function(t,e,i){var r,n=t+","+e,s=this.db.transaction(["LokiAKV"],"readonly").objectStore("LokiAKV").index("appkey").get(n);s.onsuccess=(r=i,function(t){var e=t.target.result;null==e&&(e={id:0,success:!1}),"function"==typeof r?r(e):console.log(e)}),s.onerror=function(t){return function(e){if("function"!=typeof t)throw e;t({id:0,success:!1})}}(i)},e.prototype.getAppKeyById=function(t,e,i){this.db.transaction(["LokiAKV"],"readonly").objectStore("LokiAKV").get(t).onsuccess=function(t,e){return function(i){"function"==typeof e?e(i.target.result,t):console.log(i.target.result)}}(i,e)},e.prototype.setAppKey=function(t,e,i,r){var n,s=this.db.transaction(["LokiAKV"],"readwrite").objectStore("LokiAKV"),o=s.index("appkey"),a=t+","+e,l=o.get(a);l.onsuccess=function(n){var o=n.target.result;null==o?o={app:t,key:e,appkey:t+","+e,val:i}:o.val=i;var a,h=s.put(o);h.onerror=(a=r,function(t){"function"==typeof a?a({success:!1}):(console.error("LokiCatalog.setAppKey (set) onerror"),console.error(l.error))}),h.onsuccess=function(t){return function(e){"function"==typeof t&&t({success:!0})}}(r)},l.onerror=(n=r,function(t){"function"==typeof n?n({success:!1}):(console.error("LokiCatalog.setAppKey (get) onerror"),console.error(l.error))})},e.prototype.deleteAppKey=function(t,e){var i,r=this.db.transaction(["LokiAKV"],"readwrite").objectStore("LokiAKV").delete(t);r.onsuccess=(i=e,function(t){"function"==typeof i&&i({success:!0})}),r.onerror=function(t){return function(e){"function"==typeof t?t({success:!1}):(console.error("LokiCatalog.deleteAppKey raised onerror"),console.error(r.error))}}(e)},e.prototype.getAppKeys=function(t,e){var i,r=this.db.transaction(["LokiAKV"],"readonly").objectStore("LokiAKV").index("app"),n=IDBKeyRange.only(t),s=r.openCursor(n),o=[];s.onsuccess=function(t,e){return function(i){var r=i.target.result;if(r){var n=r.value;t.push(n),r.continue()}else"function"==typeof e?e(t):console.log(t)}}(o,e),s.onerror=(i=e,function(t){"function"==typeof i?i(null):(console.error("LokiCatalog.getAppKeys raised onerror"),console.error(t))})},e.prototype.getAllKeys=function(t){var e,i=this.db.transaction(["LokiAKV"],"readonly").objectStore("LokiAKV").openCursor(),r=[];i.onsuccess=function(t,e){return function(i){var r=i.target.result;if(r){var n=r.value;t.push(n),r.continue()}else"function"==typeof e?e(t):console.log(t)}}(r,t),i.onerror=(e=t,function(t){"function"==typeof e&&e(null)})},t}()}(U)),U.exports}var Y=J(Object.freeze({__proto__:null,default:{}}));!function(t){t.exports=function(){var t=Object.prototype.hasOwnProperty;function e(t){var r,n;if(Array.isArray(t)){for(n=0;n<t.length;n++)e(t[n]);i(t)}else if(null!==t&&"object"==typeof t){for(r in t)t.hasOwnProperty(r)&&e(t[r]);i(t)}}function i(t){Object.isFrozen(t)||Object.freeze(t)}function r(t){return Object.isFrozen(t)?v(t,"shallow"):t}var n={copyProperties:function(t,e){var i;for(i in t)e[i]=t[i]},resolveTransformObject:function(t,e,i){var r,s;if("number"!=typeof i&&(i=0),++i>=10)return t;for(r in t)"string"==typeof t[r]&&0===t[r].indexOf("[%lktxp]")?(s=t[r].substring(8),e.hasOwnProperty(s)&&(t[r]=e[s])):"object"==typeof t[r]&&(t[r]=n.resolveTransformObject(t[r],e,i));return t},resolveTransformParams:function(t,e){var i,r,s=[];if(void 0===e)return t;for(i=0;i<t.length;i++)r=v(t[i],"shallow-recurse-objects"),s.push(n.resolveTransformObject(r,e));return s},getIn:function(t,e,i){if(null!=t){if(!i)return t[e];if("string"==typeof e&&(e=e.split(".")),!Array.isArray(e))throw new Error("path must be a string or array. Found "+typeof e);for(var r=0,n=e.length;null!=t&&r<n;)t=t[e[r++]];return r&&r==n?t:void 0}}},s={aeq:o,lt:a,gt:l};function o(t,e){var i,r,n,s;if(t===e)return!0;if(!t||!e||!0===t||!0===e||t!=t||e!=e){switch(t){case void 0:case null:n=1;break;case!1:n=3;break;case!0:n=4;break;case"":n=5;break;default:n=t==t?9:0}switch(e){case void 0:case null:s=1;break;case!1:s=3;break;case!0:s=4;break;case"":s=5;break;default:s=e==e?9:0}if(9!==n||9!==s)return n===s}return i=Number(t),r=Number(e),i==i||r==r?i===r:(i=t.toString())==(r=e.toString())}function a(t,e,i){var r,n,s,o;if(!t||!e||!0===t||!0===e||t!=t||e!=e){switch(t){case void 0:case null:s=1;break;case!1:s=3;break;case!0:s=4;break;case"":s=5;break;default:s=t==t?9:0}switch(e){case void 0:case null:o=1;break;case!1:o=3;break;case!0:o=4;break;case"":o=5;break;default:o=e==e?9:0}if(9!==s||9!==o)return s===o?i:s<o}return r=Number(t),n=Number(e),r==r&&n==n?r<n||!(r>n)&&i:r==r&&n!=n||(n!=n||r==r)&&(t<e||!(t>e)&&(t==e?i:(r=t.toString())<(n=e.toString())||r==n&&i))}function l(t,e,i){var r,n,s,o;if(!t||!e||!0===t||!0===e||t!=t||e!=e){switch(t){case void 0:case null:s=1;break;case!1:s=3;break;case!0:s=4;break;case"":s=5;break;default:s=t==t?9:0}switch(e){case void 0:case null:o=1;break;case!1:o=3;break;case!0:o=4;break;case"":o=5;break;default:o=e==e?9:0}if(9!==s||9!==o)return s===o?i:s>o}return r=Number(t),n=Number(e),r==r&&n==n?r>n||!(r<n)&&i:(r!=r||n==n)&&(n==n&&r!=r||t>e||!(t<e)&&(t==e?i:(r=t.toString())>(n=e.toString())||r==n&&i))}function h(t,e,i){return s.aeq(t,e)?0:s.lt(t,e,!1)?i?1:-1:s.gt(t,e,!1)?i?-1:1:0}function c(t,e,i){for(var r,s,o,a,l,c=0,u=0,d=t.length;u<d;u++)if(~(s=(r=t[u])[0]).indexOf(".")?(l=s.split("."),o=n.getIn(e,l,!0),a=n.getIn(i,l,!0)):(o=e[s],a=i[s]),0!==(c=h(o,a,r[1])))return c;return 0}function u(t,e,i,r,n,s){var o,a=s||0,l=e[a],h=!1;if("object"==typeof t&&l in t&&(o=t[l]),a+1>=e.length)h=i(o,r,n);else if(Array.isArray(o))for(var c=0,d=o.length;c<d&&!0!==(h=u(o[c],e,i,r,n,a+1));c+=1);else h=u(o,e,i,r,n,a+1);return h}function d(e){return"string"==typeof e||Array.isArray(e)?function(t){return-1!==e.indexOf(t)}:"object"==typeof e&&null!==e?function(i){return t.call(e,i)}:null}function p(e,i,r){for(var n in i)if(t.call(i,n))return f[n](e,i[n],r);return!1}var f={$eq:function(t,e){return t===e},$aeq:function(t,e){return t==e},$ne:function(t,e){return e!=e?t==t:t!==e},$dteq:function(t,e){return s.aeq(t,e)},$gt:function(t,e){return s.gt(t,e,!1)},$gte:function(t,e){return s.gt(t,e,!0)},$lt:function(t,e){return s.lt(t,e,!1)},$lte:function(t,e){return s.lt(t,e,!0)},$jgt:function(t,e){return t>e},$jgte:function(t,e){return t>=e},$jlt:function(t,e){return t<e},$jlte:function(t,e){return t<=e},$between:function(t,e){return null!=t&&s.gt(t,e[0],!0)&&s.lt(t,e[1],!0)},$jbetween:function(t,e){return null!=t&&t>=e[0]&&t<=e[1]},$in:function(t,e){return-1!==e.indexOf(t)},$inSet:function(t,e){return e.has(t)},$nin:function(t,e){return-1===e.indexOf(t)},$keyin:function(t,e){return t in e},$nkeyin:function(t,e){return!(t in e)},$definedin:function(t,e){return void 0!==e[t]},$undefinedin:function(t,e){return void 0===e[t]},$regex:function(t,e){return e.test(t)},$containsString:function(t,e){return"string"==typeof t&&-1!==t.indexOf(e)},$containsNone:function(t,e){return!f.$containsAny(t,e)},$containsAny:function(t,e){var i=d(t);return null!==i&&(Array.isArray(e)?e.some(i):i(e))},$contains:function(t,e){var i=d(t);return null!==i&&(Array.isArray(e)?e.every(i):i(e))},$elemMatch:function(t,e){return!!Array.isArray(t)&&t.some((function(t){return Object.keys(e).every((function(i){var r=e[i];return"object"==typeof r&&r||(r={$eq:r}),-1!==i.indexOf(".")?u(t,i.split("."),p,e[i],t):p(t[i],r,t)}))}))},$type:function(t,e,i){var r=typeof t;return"object"===r&&(Array.isArray(t)?r="array":t instanceof Date&&(r="date")),"object"!=typeof e?r===e:p(r,e,i)},$finite:function(t,e){return e===isFinite(t)},$size:function(t,e,i){return!!Array.isArray(t)&&("object"!=typeof e?t.length===e:p(t.length,e,i))},$len:function(t,e,i){return"string"==typeof t&&("object"!=typeof e?t.length===e:p(t.length,e,i))},$where:function(t,e){return!0===e(t)},$not:function(t,e,i){return!p(t,e,i)},$and:function(t,e,i){for(var r=0,n=e.length;r<n;r+=1)if(!p(t,e[r],i))return!1;return!0},$or:function(t,e,i){for(var r=0,n=e.length;r<n;r+=1)if(p(t,e[r],i))return!0;return!1},$exists:function(t,e){return e?void 0!==t:void 0===t}};["$eq","$aeq","$ne","$dteq","$gt","$gte","$lt","$lte","$jgt","$jgte","$jlt","$jlte","$type"].forEach((function(t){var e=f[t];f["$"+t]=function(t,i,r){if("string"==typeof i)return e(t,r[i]);if("function"==typeof i)return e(t,i(r));throw new Error("Invalid argument to $$ matcher")}}));var y={$eq:f.$eq,$aeq:!0,$dteq:!0,$gt:!0,$gte:!0,$lt:!0,$lte:!0,$in:!0,$between:!0};function v(t,e){if(null==t)return null;var i;switch(e||"parse-stringify"){case"parse-stringify":i=JSON.parse(JSON.stringify(t));break;case"jquery-extend-deep":i=jQuery.extend(!0,{},t);break;case"shallow":i=Object.create(t.constructor.prototype),Object.keys(t).map((function(e){i[e]=t[e]}));break;case"shallow-assign":i=Object.create(t.constructor.prototype),Object.assign(i,t);break;case"shallow-recurse-objects":i=v(t,"shallow"),Object.keys(t).forEach((function(e){"object"==typeof t[e]&&"Object"===t[e].constructor.name?i[e]=v(t[e],"shallow-recurse-objects"):Array.isArray(t[e])&&(i[e]=g(t[e],"shallow-recurse-objects"))}))}return i}function g(t,e){if("parse-stringify"==e)return v(t,e);for(var i=[],r=0,n=t.length;r<n;r++)i[r]=v(t[r],e);return i}function m(){try{return window&&void 0!==window.localStorage&&null!==window.localStorage}catch(t){return!1}}function b(){}function w(t,e){this.filename=t||"loki.db",this.collections=[],this.databaseVersion=1.5,this.engineVersion=1.5,this.autosave=!1,this.autosaveInterval=5e3,this.autosaveHandle=null,this.throttledSaves=!0,this.options={},this.persistenceMethod=null,this.persistenceAdapter=null,this.throttledSavePending=!1,this.throttledCallbacks=[],this.verbose=!(!e||!e.hasOwnProperty("verbose"))&&e.verbose,this.events={init:[],loaded:[],flushChanges:[],close:[],changes:[],warning:[]};var i=function(){return void 0!==W&&(W.android||W.NSObject)?"NATIVESCRIPT":"undefined"==typeof window||void 0!==W&&W.window&&void 0!==V?"NODEJS":"undefined"!=typeof document?-1===document.URL.indexOf("http://")&&-1===document.URL.indexOf("https://")?"CORDOVA":"BROWSER":"CORDOVA"};e&&e.hasOwnProperty("env")?this.ENV=e.env:this.ENV=i(),"undefined"===this.ENV&&(this.ENV="NODEJS"),this.configureOptions(e,!0),this.on("init",this.clearChanges)}function I(t){this.hashStore={},this.options=t||{},this.options.hasOwnProperty("asyncResponses")||(this.options.asyncResponses=!1),this.options.hasOwnProperty("asyncTimeout")||(this.options.asyncTimeout=50)}function x(t,e){if(this.mode="reference",this.adapter=null,this.options=e||{},this.dbref=null,this.dbname="",this.pageIterator={},!t)throw new Error("LokiPartitioningAdapter requires a (non-reference mode) adapter on construction");if("reference"===t.mode)throw new Error("LokiPartitioningAdapter cannot be instantiated with a reference mode adapter");this.adapter=t,this.options.hasOwnProperty("paging")||(this.options.paging=!1),this.options.hasOwnProperty("pageSize")||(this.options.pageSize=26214400),this.options.hasOwnProperty("delimiter")||(this.options.delimiter="$<\n")}function O(){try{this.fs=Y}catch(t){this.fs=null}}function P(){}function C(t,e){return this.collection=t,this.filteredrows=[],this.filterInitialized=!1,this}function k(t,e){if("$regex"===t)Array.isArray(e)?e=new RegExp(e[0],e[1]):e instanceof RegExp||(e=new RegExp(e));else if("object"==typeof e)for(var i in e)"$regex"!==i&&"object"!=typeof e[i]||(e[i]=k(i,e[i]));return e}function D(t,e,i){this.collection=t,this.name=e,this.rebuildPending=!1,this.options=i||{},this.options.hasOwnProperty("persistent")||(this.options.persistent=!1),this.options.hasOwnProperty("sortPriority")||(this.options.sortPriority="passive"),this.options.hasOwnProperty("minRebuildInterval")||(this.options.minRebuildInterval=1),this.resultset=new C(t),this.resultdata=[],this.resultsdirty=!1,this.cachedresultset=null,this.filterPipeline=[],this.collection.disableFreeze||Object.freeze(this.filterPipeline),this.sortFunction=null,this.sortCriteria=null,this.sortCriteriaSimple=null,this.sortDirty=!1,this.events={rebuild:[],filter:[],sort:[]}}function S(e,i){this.name=e,this.data=[],this.idIndex=null,this.binaryIndices={},this.constraints={unique:{},exact:{}},this.uniqueNames=[],this.transforms={},this.objType=e,this.dirty=!0,this.cachedIndex=null,this.cachedBinaryIndex=null,this.cachedData=null;var r=this;(i=i||{}).hasOwnProperty("unique")&&(Array.isArray(i.unique)||(i.unique=[i.unique]),i.unique.forEach((function(t){r.uniqueNames.push(t)}))),i.hasOwnProperty("exact")&&i.exact.forEach((function(t){r.constraints.exact[t]=new L(t)})),this.adaptiveBinaryIndices=!i.hasOwnProperty("adaptiveBinaryIndices")||i.adaptiveBinaryIndices,this.transactional=!!i.hasOwnProperty("transactional")&&i.transactional,this.cloneObjects=!!i.hasOwnProperty("clone")&&i.clone,this.cloneMethod=i.hasOwnProperty("cloneMethod")?i.cloneMethod:"parse-stringify",this.asyncListeners=!!i.hasOwnProperty("asyncListeners")&&i.asyncListeners,this.disableMeta=!!i.hasOwnProperty("disableMeta")&&i.disableMeta,this.disableChangesApi=!i.hasOwnProperty("disableChangesApi")||i.disableChangesApi,this.disableDeltaChangesApi=!i.hasOwnProperty("disableDeltaChangesApi")||i.disableDeltaChangesApi,this.disableChangesApi&&(this.disableDeltaChangesApi=!0),this.autoupdate=!!i.hasOwnProperty("autoupdate")&&i.autoupdate,this.serializableIndices=!i.hasOwnProperty("serializableIndices")||i.serializableIndices,this.disableFreeze=!i.hasOwnProperty("disableFreeze")||i.disableFreeze,this.ttl={age:null,ttlInterval:null,daemon:null},this.setTTL(i.ttl||-1,i.ttlInterval),this.maxId=0,this.DynamicViews=[],this.events={insert:[],update:[],"pre-insert":[],"pre-update":[],close:[],flushbuffer:[],error:[],delete:[],warning:[]},this.changes=[],this.dirtyIds=[];var n=[];if(i&&i.indices)if("[object Array]"===Object.prototype.toString.call(i.indices))n=i.indices;else{if("string"!=typeof i.indices)throw new TypeError("Indices needs to be a string or an array of strings");n=[i.indices]}for(var s=0;s<n.length;s++)this.ensureIndex(n[s]);function o(e){var i="function"==typeof Set?new Set:[];i.add||(i.add=function(t){return-1===this.indexOf(t)&&this.push(t),this}),e.forEach((function(t){i.add(t.object)})),i.forEach((function(e){if(!t.call(e,"$loki"))return r.removeAutoUpdateObserver(e);try{r.update(e)}catch(t){}}))}function a(t,e){return e?l(e,t):JSON.parse(JSON.stringify(t))}function l(t,e){var i=null!==e&&"object"==typeof e?Object.keys(e):null;if(i&&i.length&&["string","boolean","number"].indexOf(typeof e)<0){for(var n={},s=0;s<i.length;s++){var o=i[s];if(e.hasOwnProperty(o))if(!t.hasOwnProperty(o)||r.uniqueNames.indexOf(o)>=0||"$loki"==o||"meta"==o)n[o]=e[o];else{var a=l(t[o],e[o]);void 0!==a&&a!={}&&(n[o]=a)}}return 0===Object.keys(n).length?void 0:n}return t===e?void 0:e}function h(){r.changes=[]}this.observerCallback=o,this.getChangeDelta=a,this.getObjectDelta=l,this.getChanges=function(){return r.changes},this.flushChanges=h,this.setChangesApi=function(t){r.disableChangesApi=!t,t||(r.disableDeltaChangesApi=!1)},this.on("delete",(function(t){r.disableChangesApi||r.createChange(r.name,"R",t)})),this.on("warning",(function(t){r.lokiConsoleWrapper.warn(t)})),h()}function A(t){return-1!==t.indexOf(".")}function E(t){return parseFloat(t,10)}function j(t,e){return t+e}function $(t,e){return t-e}function z(t){return t.reduce(j,0)/t.length}function F(t){var e=z(t),i=z(t.map((function(t){var i=t-e;return i*i})));return Math.sqrt(i)}function M(t,e,i){if(!1===i)return t[e];for(var r=e.split("."),n=t;r.length>0;)n=n[r.shift()];return n}function q(t,e,i){for(var r,n,s=0,o=t.length;s<o;){if(n=s+o>>1,0===(r=i.apply(null,[e,t[n]])))return{found:!0,index:n};r<0?o=n:s=n+1}return{found:!1,index:o}}function N(t){return function(e,i){return q(e,i,t)}}function T(){}function B(t){this.field=t,this.keyMap=Object.create(null),this.lokiMap=Object.create(null)}function L(t){this.index=Object.create(null),this.field=t}return b.prototype.events={},b.prototype.asyncListeners=!1,b.prototype.on=function(t,e){var i,r=this;return Array.isArray(t)?(t.forEach((function(t){r.on(t,e)})),e):((i=this.events[t])||(i=this.events[t]=[]),i.push(e),e)},b.prototype.emit=function(t){var e,i=this;if(!t||!this.events[t])throw new Error("No event "+t+" defined");this.events[t].length&&(e=Array.prototype.slice.call(arguments,1),this.events[t].forEach((function(t){i.asyncListeners?setTimeout((function(){t.apply(i,e)}),1):t.apply(i,e)})))},b.prototype.addListener=b.prototype.on,b.prototype.removeListener=function(t,e){var i=this;if(Array.isArray(t))t.forEach((function(t){i.removeListener(t,e)}));else if(this.events[t]){var r=this.events[t];r.splice(r.indexOf(e),1)}},w.prototype=new b,w.prototype.constructor=w,w.prototype.getIndexedAdapter=function(){return G()},w.prototype.configureOptions=function(t,e){var i={NODEJS:"fs",BROWSER:"localStorage",CORDOVA:"localStorage",MEMORY:"memory"},r={fs:O,localStorage:P,memory:I};if(this.options={},this.persistenceMethod=null,this.persistenceAdapter=null,void 0!==t){if(this.options=t,this.options.hasOwnProperty("persistenceMethod")&&"function"==typeof r[t.persistenceMethod]&&(this.persistenceMethod=t.persistenceMethod,this.persistenceAdapter=new r[t.persistenceMethod]),this.options.hasOwnProperty("adapter")&&(this.persistenceMethod="adapter",this.persistenceAdapter=t.adapter,this.options.adapter=null,this.isIncremental="incremental"===this.persistenceAdapter.mode),t.autoload&&e){var n=this;setTimeout((function(){n.loadDatabase(t,t.autoloadCallback)}),1)}this.options.hasOwnProperty("autosaveInterval")&&(this.autosaveDisable(),this.autosaveInterval=parseInt(this.options.autosaveInterval,10)),this.options.hasOwnProperty("autosave")&&this.options.autosave&&(this.autosaveDisable(),this.autosave=!0,this.options.hasOwnProperty("autosaveCallback")?this.autosaveEnable(t,t.autosaveCallback):this.autosaveEnable()),this.options.hasOwnProperty("throttledSaves")&&(this.throttledSaves=this.options.throttledSaves)}this.options.hasOwnProperty("serializationMethod")||(this.options.serializationMethod="normal"),this.options.hasOwnProperty("destructureDelimiter")||(this.options.destructureDelimiter="$<\n"),null===this.persistenceAdapter&&(this.persistenceMethod=i[this.ENV],this.persistenceMethod&&(this.persistenceAdapter=new r[this.persistenceMethod]))},w.prototype.copy=function(t){var e,i,r=new w(this.filename,{env:"NA"});if(t=t||{},r.loadJSONObject(this,{retainDirtyFlags:!0}),t.hasOwnProperty("removeNonSerializable")&&!0===t.removeNonSerializable)for(r.autosaveHandle=null,r.persistenceAdapter=null,e=r.collections.length,i=0;i<e;i++)r.collections[i].constraints=null,r.collections[i].ttl=null;return r},w.prototype.addCollection=function(t,e){var i,r=this.collections.length;if(e&&!0===e.disableMeta){if(!1===e.disableChangesApi)throw new Error("disableMeta option cannot be passed as true when disableChangesApi is passed as false");if(!1===e.disableDeltaChangesApi)throw new Error("disableMeta option cannot be passed as true when disableDeltaChangesApi is passed as false");if("number"==typeof e.ttl&&e.ttl>0)throw new Error("disableMeta option cannot be passed as true when ttl is enabled")}for(i=0;i<r;i+=1)if(this.collections[i].name===t)return this.collections[i];var n=new S(t,e);return n.isIncremental=this.isIncremental,this.collections.push(n),this.verbose&&(n.lokiConsoleWrapper=console),n},w.prototype.loadCollection=function(t){if(!t.name)throw new Error("Collection must have a name property to be loaded");this.collections.push(t)},w.prototype.getCollection=function(t){var e,i=this.collections.length;for(e=0;e<i;e+=1)if(this.collections[e].name===t)return this.collections[e];return this.emit("warning","collection "+t+" not found"),null},w.prototype.renameCollection=function(t,e){var i=this.getCollection(t);return i&&(i.name=e),i},w.prototype.listCollections=function(){for(var t=this.collections.length,e=[];t--;)e.push({name:this.collections[t].name,type:this.collections[t].objType,count:this.collections[t].data.length});return e},w.prototype.removeCollection=function(t){var e,i=this.collections.length;for(e=0;e<i;e+=1)if(this.collections[e].name===t){var r=new S(t,{}),n=this.collections[e];for(var s in n)n.hasOwnProperty(s)&&r.hasOwnProperty(s)&&(n[s]=r[s]);return void this.collections.splice(e,1)}},w.prototype.getName=function(){return this.name},w.prototype.serializeReplacer=function(t,e){switch(t){case"autosaveHandle":case"persistenceAdapter":case"constraints":case"ttl":case"lokiConsoleWrapper":return null;case"throttledSavePending":case"throttledCallbacks":return;default:return e}},w.prototype.serialize=function(t){switch((t=t||{}).hasOwnProperty("serializationMethod")||(t.serializationMethod=this.options.serializationMethod),t.serializationMethod){case"normal":default:return JSON.stringify(this,this.serializeReplacer);case"pretty":return JSON.stringify(this,this.serializeReplacer,2);case"destructured":return this.serializeDestructured()}},w.prototype.toJson=w.prototype.serialize,w.prototype.serializeDestructured=function(t){var e,i,r,n,s,o=[];if((t=t||{}).hasOwnProperty("partitioned")||(t.partitioned=!1),t.hasOwnProperty("delimited")||(t.delimited=!0),t.hasOwnProperty("delimiter")||(t.delimiter=this.options.destructureDelimiter),!0===t.partitioned&&t.hasOwnProperty("partition")&&t.partition>=0)return this.serializeCollection({delimited:t.delimited,delimiter:t.delimiter,collectionIndex:t.partition});for((s=new w(this.filename)).loadJSONObject(this),e=0;e<s.collections.length;e++)s.collections[e].data=[];if(!0===t.partitioned&&-1===t.partition)return s.serialize({serializationMethod:"normal"});for(o.push(s.serialize({serializationMethod:"normal"})),s=null,e=0;e<this.collections.length;e++)if(r=this.serializeCollection({delimited:t.delimited,delimiter:t.delimiter,collectionIndex:e}),!1===t.partitioned&&!1===t.delimited){if(!Array.isArray(r))throw new Error("a nondelimited, non partitioned collection serialization did not return an expected array");for(n=r.length,i=0;i<n;i++)o.push(r[i]),r[i]=null;o.push("")}else o.push(r);return t.partitioned?(t.delimited,o):t.delimited?(o.push(""),o.join(t.delimiter)):(o.push(""),o)},w.prototype.serializeCollection=function(t){var e,i,r=[];if((t=t||{}).hasOwnProperty("delimited")||(t.delimited=!0),!t.hasOwnProperty("collectionIndex"))throw new Error("serializeCollection called without 'collectionIndex' option");for(e=this.collections[t.collectionIndex].data.length,r=[],i=0;i<e;i++)r.push(JSON.stringify(this.collections[t.collectionIndex].data[i]));return t.delimited?(r.push(""),r.join(t.delimiter)):r},w.prototype.deserializeDestructured=function(t,e){var i,r,n,s=[],o=0,a=1,l=!1;if((e=e||{}).hasOwnProperty("partitioned")||(e.partitioned=!1),e.hasOwnProperty("delimited")||(e.delimited=!0),e.hasOwnProperty("delimiter")||(e.delimiter=this.options.destructureDelimiter),e.partitioned){if(e.hasOwnProperty("partition"))return-1===e.partition?i=JSON.parse(t[0]):this.deserializeCollection(t[e.partition+1],e);for(r=(i=JSON.parse(t[0])).collections.length,o=0;o<r;o++)i.collections[o].data=this.deserializeCollection(t[o+1],e);return i}if(e.delimited){if(s=t.split(e.delimiter),t=null,0===s.length)return null}else s=t;for(r=(i=JSON.parse(s[0])).collections.length,s[0]=null;!l;)s[a],""===s[a]?++o>r&&(l=!0):(n=JSON.parse(s[a]),i.collections[o].data.push(n)),s[a++]=null;return i},w.prototype.deserializeCollection=function(t,e){var i,r,n=[];for((e=e||{}).hasOwnProperty("partitioned")||(e.partitioned=!1),e.hasOwnProperty("delimited")||(e.delimited=!0),e.hasOwnProperty("delimiter")||(e.delimiter=this.options.destructureDelimiter),e.delimited?(n=t.split(e.delimiter)).pop():n=t,r=n.length,i=0;i<r;i++)n[i]=JSON.parse(n[i]);return n},w.prototype.loadJSON=function(t,e){var i;if(0===t.length)i={};else switch(this.options.serializationMethod){case"normal":case"pretty":default:i=JSON.parse(t);break;case"destructured":i=this.deserializeDestructured(t)}this.loadJSONObject(i,e)},w.prototype.loadJSONObject=function(t,i){var r,s,o,a,l,h,c=0,u=t.collections?t.collections.length:0;function d(t){var e,r=i[t.name];return r.proto?(e=r.inflate||n.copyProperties,function(t){var i=new r.proto;return e(t,i),i}):r.inflate}for(this.name=t.name,t.hasOwnProperty("throttledSaves")&&i&&!i.hasOwnProperty("throttledSaves")&&(this.throttledSaves=t.throttledSaves),this.collections=[];c<u;c+=1){if(r=t.collections[c],(s=this.addCollection(r.name,{disableChangesApi:r.disableChangesApi,disableDeltaChangesApi:r.disableDeltaChangesApi,disableMeta:r.disableMeta,disableFreeze:!r.hasOwnProperty("disableFreeze")||r.disableFreeze})).adaptiveBinaryIndices=!!r.hasOwnProperty("adaptiveBinaryIndices")&&!0===r.adaptiveBinaryIndices,s.transactional=r.transactional,s.asyncListeners=r.asyncListeners,s.cloneObjects=r.cloneObjects,s.cloneMethod=r.cloneMethod||"parse-stringify",s.autoupdate=r.autoupdate,s.changes=r.changes,s.dirtyIds=r.dirtyIds||[],i&&!0===i.retainDirtyFlags?s.dirty=r.dirty:s.dirty=!1,o=r.data.length,a=0,i&&i.hasOwnProperty(r.name))for(l=d(r);a<o;a++)h=l(r.data[a]),s.data[a]=h,s.addAutoUpdateObserver(h),s.disableFreeze||e(s.data[a]);else for(;a<o;a++)s.data[a]=r.data[a],s.addAutoUpdateObserver(s.data[a]),s.disableFreeze||e(s.data[a]);if(s.maxId=void 0===r.maxId?0:r.maxId,void 0!==r.binaryIndices&&(s.binaryIndices=r.binaryIndices),void 0!==r.transforms&&(s.transforms=r.transforms),s.uniqueNames=[],r.hasOwnProperty("uniqueNames")&&(s.uniqueNames=r.uniqueNames),void 0!==r.DynamicViews){for(var p=0;p<r.DynamicViews.length;p++){var f=r.DynamicViews[p],y=s.addDynamicView(f.name,f.options);y.resultdata=f.resultdata,y.resultsdirty=f.resultsdirty,y.filterPipeline=f.filterPipeline,y.sortCriteriaSimple=f.sortCriteriaSimple,y.sortCriteria=f.sortCriteria,y.sortFunction=null,y.sortDirty=f.sortDirty,s.disableFreeze||(e(y.filterPipeline),y.sortCriteriaSimple?e(y.sortCriteriaSimple):y.sortCriteria&&e(y.sortCriteria)),y.resultset.filteredrows=f.resultset.filteredrows,y.resultset.filterInitialized=f.resultset.filterInitialized,y.rematerialize({removeWhereFilters:!0})}t.databaseVersion<1.5&&(s.ensureAllIndexes(!0),s.dirty=!0)}}},w.prototype.close=function(t){this.autosave&&(this.autosaveDisable(),this.autosaveDirty()&&(this.saveDatabase(t),t=void 0)),t&&this.on("close",t),this.emit("close")},w.prototype.generateChangesNotification=function(t){function e(t){return t.name}var i=[],r=t||this.collections.map(e);return this.collections.forEach((function(t){-1!==r.indexOf(e(t))&&(i=i.concat(t.getChanges()))})),i},w.prototype.serializeChanges=function(t){return JSON.stringify(this.generateChangesNotification(t))},w.prototype.clearChanges=function(){this.collections.forEach((function(t){t.flushChanges&&t.flushChanges()}))},I.prototype.loadDatabase=function(t,e){var i=this;this.options.asyncResponses?setTimeout((function(){i.hashStore.hasOwnProperty(t)?e(i.hashStore[t].value):e(null)}),this.options.asyncTimeout):this.hashStore.hasOwnProperty(t)?e(this.hashStore[t].value):e(null)},I.prototype.saveDatabase=function(t,e,i){var r,n=this;this.options.asyncResponses?setTimeout((function(){r=n.hashStore.hasOwnProperty(t)?n.hashStore[t].savecount:0,n.hashStore[t]={savecount:r+1,lastsave:new Date,value:e},i()}),this.options.asyncTimeout):(r=this.hashStore.hasOwnProperty(t)?this.hashStore[t].savecount:0,this.hashStore[t]={savecount:r+1,lastsave:new Date,value:e},i())},I.prototype.deleteDatabase=function(t,e){this.hashStore.hasOwnProperty(t)&&delete this.hashStore[t],"function"==typeof e&&e()},x.prototype.loadDatabase=function(t,e){var i=this;this.dbname=t,this.dbref=new w(t),this.adapter.loadDatabase(t,(function(t){if(t){"string"!=typeof t&&e(new Error("LokiPartitioningAdapter received an unexpected response from inner adapter loadDatabase()"));var r=JSON.parse(t);i.dbref.loadJSONObject(r),r=null,i.dbref.collections.length,0!==i.dbref.collections.length?(i.pageIterator={collection:0,pageIndex:0},i.loadNextPartition(0,(function(){e(i.dbref)}))):e(i.dbref)}else e(t)}))},x.prototype.loadNextPartition=function(t,e){var i=this.dbname+"."+t,r=this;if(!0===this.options.paging)return this.pageIterator.pageIndex=0,void this.loadNextPage(e);this.adapter.loadDatabase(i,(function(i){var n=r.dbref.deserializeCollection(i,{delimited:!0,collectionIndex:t});r.dbref.collections[t].data=n,++t<r.dbref.collections.length?r.loadNextPartition(t,e):e()}))},x.prototype.loadNextPage=function(t){var e=this.dbname+"."+this.pageIterator.collection+"."+this.pageIterator.pageIndex,i=this;this.adapter.loadDatabase(e,(function(e){var r=e.split(i.options.delimiter);e="";var n,s=r.length,o=""===r[s-1];for(o&&(r.pop(),""===r[(s=r.length)-1]&&1===s&&(r.pop(),s=r.length)),n=0;n<s;n++)i.dbref.collections[i.pageIterator.collection].data.push(JSON.parse(r[n])),r[n]=null;r=[],o?++i.pageIterator.collection<i.dbref.collections.length?i.loadNextPartition(i.pageIterator.collection,t):t():(i.pageIterator.pageIndex++,i.loadNextPage(t))}))},x.prototype.exportDatabase=function(t,e,i){var r,n=e.collections.length;for(this.dbref=e,this.dbname=t,this.dirtyPartitions=[-1],r=0;r<n;r++)e.collections[r].dirty&&this.dirtyPartitions.push(r);this.saveNextPartition((function(t){i(t)}))},x.prototype.saveNextPartition=function(t){var e=this,i=this.dirtyPartitions.shift(),r=this.dbname+(-1===i?"":"."+i);if(this.options.paging&&-1!==i)return this.pageIterator={collection:i,docIndex:0,pageIndex:0},void this.saveNextPage((function(i){0===e.dirtyPartitions.length?t(i):e.saveNextPartition(t)}));var n=this.dbref.serializeDestructured({partitioned:!0,delimited:!0,partition:i});this.adapter.saveDatabase(r,n,(function(i){i?t(i):0===e.dirtyPartitions.length?t(null):e.saveNextPartition(t)}))},x.prototype.saveNextPage=function(t){var e=this,i=this.dbref.collections[this.pageIterator.collection],r=this.dbname+"."+this.pageIterator.collection+"."+this.pageIterator.pageIndex,n=0,s=i.data.length,o=this.options.delimiter.length,a="",l="",h=!1,c=!1,u=function(i){l="",i&&t(i),h?t(null):(e.pageIterator.pageIndex++,e.saveNextPage(t))};for(0===i.data.length&&(h=!0);;)if(h||(a=JSON.stringify(i.data[this.pageIterator.docIndex]),l+=a,n+=a.length,++this.pageIterator.docIndex>=s&&(h=!0)),n>=this.options.pageSize&&(c=!0),c&&!h||(l+=this.options.delimiter,n+=o),h||c)return void this.adapter.saveDatabase(r,l,u)},O.prototype.loadDatabase=function(t,e){var i=this;this.fs.stat(t,(function(r,n){!r&&n.isFile()?i.fs.readFile(t,{encoding:"utf8"},(function(t,i){e(t?new Error(t):i)})):e(null)}))},O.prototype.saveDatabase=function(t,e,i){var r=this,n=t+"~";this.fs.writeFile(n,e,(function(e){e?i(new Error(e)):r.fs.rename(n,t,i)}))},O.prototype.deleteDatabase=function(t,e){this.fs.unlink(t,(function(t){t?e(new Error(t)):e()}))},P.prototype.loadDatabase=function(t,e){m()?e(localStorage.getItem(t)):e(new Error("localStorage is not available"))},P.prototype.saveDatabase=function(t,e,i){m()?(localStorage.setItem(t,e),i(null)):i(new Error("localStorage is not available"))},P.prototype.deleteDatabase=function(t,e){m()?(localStorage.removeItem(t),e(null)):e(new Error("localStorage is not available"))},w.prototype.throttledSaveDrain=function(t,e){var i=this,r=(new Date).getTime();if(this.throttledSaves||t(!0),(e=e||{}).hasOwnProperty("recursiveWait")||(e.recursiveWait=!0),e.hasOwnProperty("recursiveWaitLimit")||(e.recursiveWaitLimit=!1),e.hasOwnProperty("recursiveWaitLimitDuration")||(e.recursiveWaitLimitDuration=2e3),e.hasOwnProperty("started")||(e.started=(new Date).getTime()),this.throttledSaves&&this.throttledSavePending){if(!e.recursiveWait)return void this.throttledCallbacks.push(t);this.throttledCallbacks.push((function(){return i.throttledSavePending?e.recursiveWaitLimit&&r-e.started>e.recursiveWaitLimitDuration?void t(!1):void i.throttledSaveDrain(t,e):void t(!0)}))}else t(!0)},w.prototype.loadDatabaseInternal=function(t,e){var i=e||function(t,e){if(t)throw t},r=this;null!==this.persistenceAdapter?this.persistenceAdapter.loadDatabase(this.filename,(function(e){if("string"==typeof e){var n=!1;try{r.loadJSON(e,t||{}),n=!0}catch(t){i(t)}n&&(i(null),r.emit("loaded","database "+r.filename+" loaded"))}else{if(!e)return i(null),void r.emit("loaded","empty database "+r.filename+" loaded");if(e instanceof Error)return void i(e);if("object"==typeof e)return r.loadJSONObject(e,t||{}),i(null),void r.emit("loaded","database "+r.filename+" loaded");i("unexpected adapter response : "+e)}})):i(new Error("persistenceAdapter not configured"))},w.prototype.loadDatabase=function(t,e){var i=this;this.throttledSaves?this.throttledSaveDrain((function(r){if(r)return i.throttledSavePending=!0,void i.loadDatabaseInternal(t,(function(t){0===i.throttledCallbacks.length?i.throttledSavePending=!1:i.saveDatabase(),"function"==typeof e&&e(t)}));"function"==typeof e&&e(new Error("Unable to pause save throttling long enough to read database"))}),t):this.loadDatabaseInternal(t,e)},w.prototype.saveDatabaseInternal=function(t){var e,i=t||function(t){if(t)throw t},r=this;this.persistenceAdapter?"incremental"===this.persistenceAdapter.mode?(this.ignoreAutosave=!0,this.persistenceAdapter.saveDatabase(this.filename,(function(){if(r.ignoreAutosave=!1,!e){var t=r.copy({removeNonSerializable:!0});return e=r.collections.map((function(t){return[t.dirty,t.dirtyIds]})),r.collections.forEach((function(t){t.dirty=!1,t.dirtyIds=[]})),t}i(new Error("adapter error - getLokiCopy called more than once"))}),(function(t){r.ignoreAutosave=!1,t&&e&&r.collections.forEach((function(t,i){var r=e[i];t.dirty=t.dirty||r[0],t.dirtyIds=t.dirtyIds.concat(r[1])})),i(t)}))):"reference"===this.persistenceAdapter.mode&&"function"==typeof this.persistenceAdapter.exportDatabase?this.persistenceAdapter.exportDatabase(this.filename,this.copy({removeNonSerializable:!0}),(function(t){r.autosaveClearFlags(),i(t)})):(this.autosaveClearFlags(),this.persistenceAdapter.saveDatabase(this.filename,this.serialize(),(function(t){i(t)}))):i(new Error("persistenceAdapter not configured"))},w.prototype.saveDatabase=function(t){if(this.throttledSaves)if(this.throttledSavePending)this.throttledCallbacks.push(t);else{var e=this.throttledCallbacks;this.throttledCallbacks=[],e.unshift(t),this.throttledSavePending=!0;var i=this;this.saveDatabaseInternal((function(t){i.throttledSavePending=!1,e.forEach((function(e){"function"==typeof e&&setTimeout((function(){e(t)}),1)})),i.throttledCallbacks.length>0&&i.saveDatabase()}))}else this.saveDatabaseInternal(t)},w.prototype.save=w.prototype.saveDatabase,w.prototype.deleteDatabase=function(t,e){var i=e||function(t,e){if(t)throw t};"function"!=typeof t||e||(i=t),null!==this.persistenceAdapter?this.persistenceAdapter.deleteDatabase(this.filename,(function(t){i(t)})):i(new Error("persistenceAdapter not configured"))},w.prototype.autosaveDirty=function(){for(var t=0;t<this.collections.length;t++)if(this.collections[t].dirty)return!0;return!1},w.prototype.autosaveClearFlags=function(){for(var t=0;t<this.collections.length;t++)this.collections[t].dirty=!1},w.prototype.autosaveEnable=function(t,e){this.autosave=!0;var i=5e3,r=this;void 0!==this.autosaveInterval&&null!==this.autosaveInterval&&(i=this.autosaveInterval),this.autosaveHandle=setInterval((function(){r.autosaveDirty()&&!r.ignoreAutosave&&r.saveDatabase(e)}),i)},w.prototype.autosaveDisable=function(){void 0!==this.autosaveHandle&&null!==this.autosaveHandle&&(clearInterval(this.autosaveHandle),this.autosaveHandle=null)},C.prototype.reset=function(){return this.filteredrows.length>0&&(this.filteredrows=[]),this.filterInitialized=!1,this},C.prototype.toJSON=function(){var t=this.copy();return t.collection=null,t},C.prototype.limit=function(t){this.filterInitialized||0!==this.filteredrows.length||(this.filteredrows=this.collection.prepareFullDocIndex());var e=new C(this.collection);return e.filteredrows=this.filteredrows.slice(0,t),e.filterInitialized=!0,e},C.prototype.offset=function(t){this.filterInitialized||0!==this.filteredrows.length||(this.filteredrows=this.collection.prepareFullDocIndex());var e=new C(this.collection);return e.filteredrows=this.filteredrows.slice(t),e.filterInitialized=!0,e},C.prototype.copy=function(){var t=new C(this.collection);return this.filteredrows.length>0&&(t.filteredrows=this.filteredrows.slice()),t.filterInitialized=this.filterInitialized,t},C.prototype.branch=C.prototype.copy,C.prototype.transform=function(t,e){var i,r,s=this;if("string"==typeof t&&this.collection.transforms.hasOwnProperty(t)&&(t=this.collection.transforms[t]),"object"!=typeof t||!Array.isArray(t))throw new Error("Invalid transform");for(void 0!==e&&(t=n.resolveTransformParams(t,e)),i=0;i<t.length;i++)switch((r=t[i]).type){case"find":s.find(r.value);break;case"where":s.where(r.value);break;case"simplesort":s.simplesort(r.property,r.desc||r.options);break;case"compoundsort":s.compoundsort(r.value);break;case"sort":s.sort(r.value);break;case"limit":s=s.limit(r.value);break;case"offset":s=s.offset(r.value);break;case"map":s=s.map(r.value,r.dataOptions);break;case"eqJoin":s=s.eqJoin(r.joinData,r.leftJoinKey,r.rightJoinKey,r.mapFun,r.dataOptions);break;case"mapReduce":s=s.mapReduce(r.mapFunction,r.reduceFunction);break;case"update":s.update(r.value);break;case"remove":s.remove()}return s},C.prototype.sort=function(t){this.filterInitialized||0!==this.filteredrows.length||(this.filteredrows=this.collection.prepareFullDocIndex());var e,i,r=(e=t,i=this.collection.data,function(t,r){return e(i[t],i[r])});return this.filteredrows.sort(r),this},C.prototype.simplesort=function(t,e){va