phaser3-rex-plugins
Version:
1 lines • 96.6 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();}(undefined,(function(){function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){for(var i=0;i<e.length;i++){var r=e[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,(n=r.key,s=void 0,"symbol"==typeof(s=function(t,e){if("object"!=typeof t||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var r=i.call(t,e||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return ("string"===e?String:Number)(t)}(n,"string"))?s:String(s)),r);}var n,s;}function r(t,e,r){return e&&i(t.prototype,e),r&&i(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function n(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&o(t,e);}function s(t){return s=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},s(t)}function o(t,e){return o=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},o(t,e)}function a(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function l(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return !1;if(Reflect.construct.sham)return !1;if("function"==typeof Proxy)return !0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return !1}}();return function(){var i,r=s(t);if(e){var n=s(this).constructor;i=Reflect.construct(r,arguments,n);}else i=r.apply(this,arguments);return a(this,i)}}function h(){return h="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(t,e,i){var r=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=s(t)););return t}(t,e);if(r){var n=Object.getOwnPropertyDescriptor(r,e);return n.get?n.get.call(arguments.length<3?t:i):n.value}},h.apply(this,arguments)}var c,u,d={setEventEmitter:function(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:function(){return this._eventEmitter&&this._privateEE&&this._eventEmitter.shutdown(),this},getEventEmitter:function(){return this._eventEmitter},on:function(){return this._eventEmitter&&this._eventEmitter.on.apply(this._eventEmitter,arguments),this},once:function(){return this._eventEmitter&&this._eventEmitter.once.apply(this._eventEmitter,arguments),this},off:function(){return this._eventEmitter&&this._eventEmitter.off.apply(this._eventEmitter,arguments),this},emit:function(t){return this._eventEmitter&&t&&this._eventEmitter.emit.apply(this._eventEmitter,arguments),this},addListener:function(){return this._eventEmitter&&this._eventEmitter.addListener.apply(this._eventEmitter,arguments),this},removeListener:function(){return this._eventEmitter&&this._eventEmitter.removeListener.apply(this._eventEmitter,arguments),this},removeAllListeners:function(){return this._eventEmitter&&this._eventEmitter.removeAllListeners.apply(this._eventEmitter,arguments),this},listenerCount:function(){return this._eventEmitter?this._eventEmitter.listenerCount.apply(this._eventEmitter,arguments):0},listeners:function(){return this._eventEmitter?this._eventEmitter.listeners.apply(this._eventEmitter,arguments):[]},eventNames:function(){return this._eventEmitter?this._eventEmitter.eventNames.apply(this._eventEmitter,arguments):[]}},p=Phaser.Game,f=function(t){return t instanceof p},y=Phaser.Scene,v=function(t){return t instanceof y},g=function(e){return null==e||"object"!==t(e)?null:f(e)?e:f(e.game)?e.game:v(e)?e.sys.game:v(e.scene)?e.scene.sys.game:void 0},m=function(t,e,i,r,n){if(void 0===c){var s=(o=t.manager.game,g(o).textures.getFrame("__WHITE"));c=s.cutWidth,u=s.cutHeight;}var o;return t.stamp("__WHITE",void 0,e,i,{scaleX:r/c,scaleY:n/u,originX:0,originY:0,erase:!0}),t},b=function(t,e,i,r){this.useDynamicTexture?m(this.texture,t,e,i,r):this.context.clearRect(t,e,i,r);},w=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();},I=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);},x={remove:function(t){var e=this.getFrameIndex(t);return -1===e||(this.addFrameName(e,void 0),this.texture.remove(t)),this},clear:function(){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}},O={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,h=o+a;b.call(this,s,o,this.outerCellWidth,this.outerCellHeight);var c={width:this.cellWidth,height:this.cellHeight};return (this.useDynamicTexture?I:w).call(this,l,h,c,e,i),this.texture.add(t,0,l,h,c.width,c.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(O,x);var k=Phaser.Utils.Objects.IsPlainObject,P=Phaser.Utils.Objects.GetValue,C=function(){function t(i,r,n,s,o,a,l,h){var c,u,d;if(e(this,t),k(r)){var p=r;r=P(p,"key"),n=P(p,"width"),s=P(p,"height"),o=P(p,"cellWidth"),a=P(p,"cellHeight"),d=P(p,"cellPadding",0),c=P(p,"columns"),u=P(p,"rows"),l=P(p,"fillColor"),h=P(p,"useDynamicTexture");}else "boolean"==typeof l&&(h=l,l=void 0);void 0===o&&(o=64),void 0===a&&(a=64),void 0===d&&(d=0),this.cellWidth=o,this.cellHeight=a,this.cellPadding=d,c?n=this.outerCellWidth*c:(void 0===n&&(n=4096),c=Math.floor(n/this.outerCellWidth)),u?s=this.outerCellWidth*u:(void 0===s&&(s=4096),u=Math.floor(s/this.outerCellWidth)),void 0===h&&(h=!1);var f=g(i);if(this.useDynamicTexture=h,this.texture=function(t,e,i,r,n){void 0===n&&(n=!1);var s=(t=g(t)).textures;return s.exists(e)&&s.remove(e),s[n?"addDynamicTexture":"createCanvas"](e,i,r)}(f,r,n,s,h),this.canvas=h?void 0:this.texture.getCanvas(),this.context=h?void 0:this.texture.getContext(),this.bitmapFontCache=f.cache.bitmapFont,void 0!==l)if(h)this.texture.fill(l);else {var y=this.context;y.fillStyle=l,y.fillRect(0,0,this.canvas.width,this.canvas.height);}this.key=r,this.width=n,this.height=s,this.columns=c,this.rows=u,this.totalCount=this.columns*this.rows,this.frameNames=Array(this.totalCount);for(var v=0,m=this.frameNames.length;v<m;v++)this.frameNames[v]=void 0;}return r(t,[{key:"outerCellWidth",get:function(){return this.cellWidth+2*this.cellPadding}},{key:"outerCellHeight",get:function(){return this.cellHeight+2*this.cellPadding}},{key:"destroy",value:function(){this.texture=void 0,this.canvas=void 0,this.context=void 0,this.frameNames=void 0,this.bitmapFontCache=void 0;}},{key:"getFrameIndex",value:function(t){return this.frameNames.indexOf(t)}},{key:"contains",value:function(t){return -1!==this.getFrameIndex(t)}},{key:"addFrameName",value:function(t,e){return this.frameNames[t]=e,this}},{key:"isFull",get:function(){return -1===this.getFrameIndex(void 0)}},{key:"getTopLeftPosition",value:function(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}},{key:"updateTexture",value:function(){return this.useDynamicTexture||this.texture.refresh(),this}}]),t}();Object.assign(C.prototype,O);var D=Phaser.Utils.Objects.GetValue,S="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function A(){throw new Error("setTimeout has not been defined")}function j(){throw new Error("clearTimeout has not been defined")}var E=A,$=j;function z(t){if(E===setTimeout)return setTimeout(t,0);if((E===A||!E)&&setTimeout)return E=setTimeout,setTimeout(t,0);try{return E(t,0)}catch(e){try{return E.call(null,t,0)}catch(e){return E.call(this,t,0)}}}"function"==typeof S.setTimeout&&(E=setTimeout),"function"==typeof S.clearTimeout&&($=clearTimeout);var F,M=[],q=!1,N=-1;function T(){q&&F&&(q=!1,F.length?M=F.concat(M):N=-1,M.length&&B());}function B(){if(!q){var t=z(T);q=!0;for(var e=M.length;e;){for(F=M,M=[];++N<e;)F&&F[N].run();N=-1,e=M.length;}F=null,q=!1,function(t){if($===clearTimeout)return clearTimeout(t);if(($===j||!$)&&clearTimeout)return $=clearTimeout,clearTimeout(t);try{return $(t)}catch(e){try{return $.call(null,t)}catch(e){return $.call(this,t)}}}(t);}}function R(t,e){this.fun=t,this.array=e;}R.prototype.run=function(){this.fun.apply(null,this.array);};function L(){}var _=L,V=L,W=L,J=L,K=L,U=L,H=L;var G=S.performance||{},Y=G.now||G.mozNow||G.msNow||G.oNow||G.webkitNow||function(){return (new Date).getTime()};var X=new Date;var Q={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];M.push(new R(t,e)),1!==M.length||q||z(B);},title:"browser",browser:!0,env:{},argv:[],version:"",versions:{},on:_,addListener:V,once:W,off:J,removeListener:K,removeAllListeners:U,emit:H,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*Y.call(G),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-X)/1e3}},Z="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function tt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function et(t){if(t.__esModule)return t;var e=t.default;if("function"==typeof e){var i=function t(){if(this instanceof t){var i=[null];return i.push.apply(i,arguments),new(Function.bind.apply(e,i))}return 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 it,rt={exports:{}},nt={exports:{}};function st(){return it||(it=1,function(t,e){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}();}(nt)),nt.exports}var ot=et(Object.freeze({__proto__:null,default:{}}));!function(t,e){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!==Z&&(Z.android||Z.NSObject)?"NATIVESCRIPT":"undefined"==typeof window||void 0!==Z&&Z.window&&void 0!==Q?"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=ot;}catch(t){this.fs=null;}}function k(){}function P(t,e){return this.collection=t,this.filteredrows=[],this.filterInitialized=!1,this}function C(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]=C(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 P(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 R(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 j(t){return parseFloat(t,10)}function E(t,e){return t+e}function $(t,e){return t-e}function z(t){return t.reduce(E,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 R(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 st()},w.prototype.configureOptions=function(t,e){var i={NODEJS:"fs",BROWSER:"localStorage",CORDOVA:"localStorage",MEMORY:"memory"},r={fs:O,localStorage:k,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();}));},k.prototype.loadDatabase=function(t,e){m()?e(localStorage.getItem(t)):e(new Error("localStorage is not available"));},k.prototype.saveDatabase=function(t,e,i){m()?(localStorage.setItem(t,e),i(null)):i(new Error("localStorage is not available"));},k.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.