var e,t;e=void 0,t=function(){var e=function(e){return void 0===e&&(e="10.13"),{app:`https://www.gstatic.com/firebasejs/${e}/firebase-app-compat.js`,database:`https://www.gstatic.com/firebasejs/${e}/firebase-database-compat.js`,firestore:`https://www.gstatic.com/firebasejs/${e}/firebase-firestore-compat.js`}},t=function(e){if("object"!=typeof e||null===e)return e;if(Array.isArray(e))e.length=0;else for(var t in e)delete e[t];return e},r=function(e,r){var s=function(e,r){var s=Array.isArray(e);if(void 0===r?r=s?[]:{}:t(r),s){r.length=e.length;for(var i=0,n=e.length;i0&&this.records.length>this.maxLength&&this.records.shift()),this}clear(){return this.records.length=0,this}changeUserName(e,t){return 0===this.maxLength||this.records.forEach((function(r){r.senderID===e&&(r.senderName=t)})),this}}class f{constructor(e){var t=c(e,"eventEmitter",void 0),r=c(e,"EventEmitterClass",void 0);this.setEventEmitter(t,r),this.eventNameMap=c(e,"eventNames",I),this.database=firebase.database(),this.setRootPath(c(e,"root","")),this.skipFirst=!0,this.stamp=!1,this.userInfo={userID:"",userName:void 0},this.setSender(c(e,"senderID",""),c(e,"senderName","")),this.setReceiver(c(e,"receiverID","")),this.isReceiving=!1;var s=c(e,"history",0);!0===s?s=-1:!1===s&&(s=0),this.history=new v({maxLength:s})}shutdown(){this.stopReceiving().destroyEventEmitter()}destroy(){this.shutdown()}get userID(){return this.userInfo.userID}set userID(e){this.userInfo.userID=e}get userName(){return this.userInfo.userName}set userName(e){this.userInfo.userName=e}setRootPath(e){return this.rootPath=e,this.sendToRef=void 0,this.receiverRef=void 0,this}setSender(e,t){return d(e)?this.userInfo=e:(this.userID=e,this.userName=t),this}setReceiver(e){return this.receiverID=e,this}changeUserName(e,t){return e===this.userID&&(this.userName=t),this.history.changeUserName(e,t),this}getHistory(){return this.history.records}clearHistory(){return this.history.clear(),this}}var g={send:function(e){if(this.sendToRef&&this.sendToRef.key===this.receiverID||(this.sendToRef=this.database.ref(this.rootPath).child(this.receiverID)),void 0===e)return this.sendToRef.remove();var t={message:e,senderID:this.userID,stamp:this.stamp};return void 0!==this.userName&&(t.senderName=this.userName),this.skipFirst=!1,this.stamp=!this.stamp,this.sendToRef.set(t)}};Object.assign(f.prototype,u,l,g);const I={receive:"receive"};var p=function(e){return null==e||""===e||0===e.length},y=function(e,t,r,s){if(void 0===s&&(s="."),"object"==typeof e){if(p(t)){if(null==r)return;"object"==typeof r&&(e=r)}else{"string"==typeof t&&(t=t.split(s));var i=t.pop(),n=function(e,t,r){var s=e;if(p(t));else{var i;"string"==typeof t&&(t=t.split("."));for(var n=0,a=t.length;n=e.length)){for(var r=e.length-1,s=e[t],i=t;i * @copyright 2018 Photon Storm Ltd. * @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} */class U{constructor(e){var t=c(e,"eventEmitter",void 0),r=c(e,"EventEmitterClass",void 0);this.setEventEmitter(t,r),this.eventNameMap=c(e,"eventNames",C),this.isUpdating=!1,this.items=[],this.itemID2Index={},this.setItemIDKey(c(e,"itemIDKey","__itemID__")),this.setMode(c(e,"mode",1)),this.setGetitemCallback(c(e,"getItemCallback",L),c(e,"getItemCallbackScope",this)),this.setQuery(c(e,"query",void 0))}shutdown(){this.stopUpdate().clear()}destroy(){this.shutdown()}setItemIDKey(e){return this.keyItemID=e,this}setMode(e){return"string"==typeof e&&(e=j[e]),this.mode=e,this.updater=M[e],this}setGetitemCallback(e,t){return this.getItemCallback=e,this.getItemCallbackScope=t,this}setQuery(e){return this.query=e,this}startUpdate(e){if(e)this.setQuery(e);else{if(!this.query)return this;e=this.query}return this.stopUpdate().clear(),this.isUpdating=!0,this.updater.start.call(this,e),this}stopUpdate(){return this.query&&this.isUpdating?(this.isUpdating=!1,this.updater.stop.call(this),this):this}}var L=function(e){var t=e.val();return t[this.keyItemID]=e.key,t};Object.assign(U.prototype,u,D);const C={update:"update",add:"add",remove:"remove",change:"change"},M={0:N,1:x,2:F},j={once:0,child:1,all:2};var Q=function(e,t){var r=!1;return e.forEach((function(e){if(e.val().userID===t)return r=!0,!0})),r};class _{constructor(e){var t=c(e,"eventEmitter",void 0),r=c(e,"EventEmitterClass",void 0);this.setEventEmitter(t,r),this.database=firebase.database(),this.setRootPath(c(e,"root","")),this.userInfo={userID:"",userName:""},this.setUser(c(e,"userID",""),c(e,"userName","")),this.setMaxUsers(c(e,"maxUsers",0)),this.userList=new U({eventEmitter:this.getEventEmitter(),itemIDKey:"joinAt",eventNames:{add:c(e,"eventNames.join","join"),remove:c(e,"eventNames.leave","leave"),update:c(e,"eventNames.update","update"),change:c(e,"eventNames.change","change"),init:c(e,"eventNames.init","init"),changename:c(e,"eventNames.changename","changename")}}),this.isInList=!1,this.userID2ItemID={},this.userList.on(this.userList.eventNames.add,(function(e){this.userID2ItemID[e.userID]=e.joinAt,e.userID===this.userInfo.userID&&this.emit(this.userList.eventNames.init,this.getUsers())}),this).on(this.userList.eventNames.remove,(function(e){delete this.userID2ItemID[e.userID],e.userID===this.userID&&(this.isInList=!1)}),this).on(this.userList.eventNames.change,(function(e,t){var r=e.userID,s=e.userName,i=t.userName;s!==i&&this.emit(this.userList.eventNames.changename,r,s,i)}),this)}shutdown(){this.stopUpdate().destroyEventEmitter().leave(),this.userList.shutdown()}destroy(){this.shutdown()}get userID(){return this.userInfo.userID}set userID(e){this.userInfo.userID=e}get userName(){return this.userInfo.userName}set userName(e){this.userInfo.userName=e}setRootPath(e){return this.rootPath=e,this}get rootRef(){return this.database.ref(this.rootPath)}setUser(e,t){return d(e)?this.userInfo=e:(this.userID=e,this.userName=t),this}setMaxUsers(e){return this.maxUsers=e,this}clear(){return this.userList.clear(),this}forEach(e,t){return this.userList.forEach(e,t),this}isFull(){return 0!==this.maxUsers&&this.userList.getItems().length>=this.maxUsers}isFirstUser(e){void 0===e&&(e=this.userID);var t=this.usersList.getItems()[0];return t&&t.userID===e}getUser(e){if(void 0===e&&(e=this.userID),!this.contains(e))return null;var t=this.userID2ItemID[e];return this.userList.getItemFromItemID(t)}getUsers(){return this.userList.getItems()}get rootRef(){return this.database.ref(this.rootPath)}getUserRef(e){if(void 0===e&&(e=this.userID),!this.contains(e))return null;var t=this.userID2ItemID[e];return this.rootRef.child(t)}contains(e){return void 0===e&&(e=this.userID),this.userID2ItemID.hasOwnProperty(e)}startUpdate(){var e=this.database.ref(this.rootPath);return this.maxUsers>0&&(e=e.limitToFirst(this.maxUsers)),this.userList.startUpdate(e),this}stopUpdate(){return this.userList.stopUpdate(),this}}var $={join:function(e,t){if(void 0===e&&(e=this.userID,t=this.userName),this.contains(e))return Promise.resolve();var r={userID:e,userName:t},s=this.maxUsers,n=this.database.ref(this.rootPath),a=n.push();return a.onDisconnect().remove().then((function(){return a.set(r)})).then((function(){return i(0)})).then((function(){return 0===s?(self.isInList=!0,Promise.resolve()):n.limitToFirst(s).once("value").then((function(t){return Q(t,e)?(self.isInList=!0,Promise.resolve()):(self.isInList=!1,a.remove().then((function(){return a.onDisconnect().cancel()})).then((function(){return Promise.reject()})))}))}))},leave:function(e){if(void 0===e&&(e=this.userID),!this.contains(e))return Promise.resolve();var t=this.userID2ItemID[e];return this.database.ref(this.rootPath).child(t).remove()},changeUserName:function(e){var t=this;return new Promise((function(e,r){var s=t.getUserRef();s?e(s):t.rootRef.orderByChild("userID").equalTo(t.userID).once("child_added").then((function(t){e(t.ref)}))})).then((function(t){return t.child("userName").set(e)})).then((function(){return t.userName=e,Promise.resolve()}))}};Object.assign(_.prototype,u,$),h.register("onlineUserList",(function(e){return new _(e)})),y(window,"RexPlugins.Fire.OnlineUserList",_);var T=function(e){var t=new _({eventEmitter:this.getEventEmitter(),eventNames:{join:"userlist.join",leave:"userlist.leave",update:"userlist.update",change:"userlist.change",init:"userlist.init",changename:"userlist.changename"},userID:this.userInfo});return t.on("userlist.leave",(function(e){e.userID===this.userID&&O.call(this)}),this),this.on("room.join",(function(){t.startUpdate()})).on("room.leave",(function(){t.stopUpdate().clear()})),t},O=function(){this.emit("room.leave");var e=this;setTimeout((function(){e.roomID=void 0,e.roomName=void 0,e.doorState=void 0,e.leftRoomFlag=!1}),0)},A=function(e){return new U({eventEmitter:this.getEventEmitter(),root:this.getRoomFilterRef(),itemIDKey:"roomID",eventNames:{update:"roomlist.update",add:"roomlist.add",remove:"roomlist.remove",change:"roomlist.change"},mode:"once"})},S=function(e){var t=c(e,"broadcast",!0);if(!t)return null;var r=new f({eventEmitter:this.getEventEmitter(),eventNames:{receive:"broadcast.receive"},receiverID:"boradcast",senderID:this.userInfo,history:c(t,"history",!1)});return this.on("room.join",(function(e){r.setRootPath(this.getRoomDataPath(e.roomID)).startReceiving()}),this).on("room.leave",(function(){r.stopReceiving()}),this).on("userlist.changename",(function(e,t){r.changeUserName(e,t)}),this),r};function K(e){if(null===e||"object"!=typeof e)return e;if(Array.isArray(e))return e.map((e=>K(e)));if(e instanceof Date)return new Date(e);if(e instanceof RegExp)return new RegExp(e);if(Object.getPrototypeOf(e)!==Object.prototype)return e;const t={};for(let r in e)e.hasOwnProperty(r)&&(t[r]=K(e[r]));return t}class B{constructor(e){void 0===e&&(e={}),this.data=e,this.refPath=""}getFullPath(e){if("string"==typeof e)if("."===e)e=this.refPath;else if(e.startsWith(".."))if(""!==this.refPath){var t=this.refPath.split(".");t.pop(),e=`${t.join(".")}${e.substring(1)}`}else e=e.substring(2);else e.startsWith(".")&&(e=""!==this.refPath?`${this.refPath}${e}`:e.substring(1));return e}setRefPath(e){return void 0===e&&(e=""),this.refPath=this.getFullPath(e),this}setValue(e,t){return void 0===e?this.clear():void 0===t?this.data=e:y(this.data,this.getFullPath(e),t),this}getValue(e){return void 0===e?this.data:("string"==typeof e&&(e=this.getFullPath(e).split(".")),z(this.data,e))}cloneValue(e){return K(this.getValue(e))}removeKey(e){if(void 0===e)this.clear();else{"string"==typeof e&&(e=this.getFullPath(e).split("."));var t=e.pop(),r=z(this.data,e);q(r)&&delete r[t]}return this}hasKey(e){"string"==typeof e&&(e=this.getFullPath(e).split("."));var t=e.pop(),r=z(this.data,e);return!!q(r)&&r.hasOwnProperty(t)}clear(){return t(this.data),this}clone(e){var t=e?this.cloneValue():this.data,r=new B(t);return r.setRefPath(this.refPath),r}}var q=function(e){return null!=e&&"object"==typeof e},z=function(e,t){if(""===t[0])return e;for(var r=e,s=0,i=t.length;s0;t--){var r=Math.floor(Math.random()*(t+1)),s=e[t];e[t]=e[r],e[r]=s}}(t),ve.call(s,e,t,0)}))},leaveRoom:function(){if(!this.isInRoom())return Promise.resolve();if(this.leftRoomFlag=!0,this.isRemoveRoomWhenLeft)return this.removeRoom();var e=this.getRoomInfo();return this.userList.leave().then((function(){return Promise.resolve(e)}))},removeRoom:function(e){if(void 0===e&&(e=this.roomID),void 0===e)return Promise.resolve();var t={};t[`room-filter/${e}`]=null,t[`room-data/${e}`]=null,t[`rooms/${e}`]=null;var r=this.getRoomInfo();return this.getRootRef().update(t).then((function(){return Promise.resolve(r)}))},kickUser:function(e){return this.userList.contains(e)?e===this.userID?this.leaveRoom():this.userList.leave(e):Promise.resolve()},isRoomOpened:function(e){if(null==e)return!1;if("closed"===e.filter.split("|")[0])return!1;var t=this.userID;if(e.moderators.hasOwnProperty(t))return!0;switch(e.permission){case"black-list":var r=e["black-list"];return!(r&&r.hasOwnProperty(t));case"white-list":var s=e["white-list"];return s&&s.hasOwnProperty(t);default:return!0}},changeRoomState:function(e,t){1===arguments.length&&(t=e,e=void 0),void 0===e&&(e=this.roomID);var r=this;return this.hasRoom(e).then((function(s){if(!s)return Promise.resolve();var i=ie(t,r.roomType),n={};return n[`room-filters/${e}/filter`]=i,n[`room-data/${e}/filter`]=i,r.getRootRef().update(n)}))},changeFilterData:function(e,t){1===arguments.length&&(t=e,e=void 0),void 0===e&&(e=this.roomID);var r=this;return this.hasRoom(e).then((function(s){return s?r.getRoomFilterRef(e).child("data").update(t):Promise.resolve()}))},changeUserName:function(e){return this.userList.changeUserName(e)},changeRoomName:function(e,t){1===arguments.length&&(t=e,e=void 0),void 0===e&&(e=this.roomID);var r=this;return this.hasRoom(e).then((function(s){if(!s)return Promise.resolve();var i={};return i[`room-filters/${e}/name`]=t,i[`room-data/${e}/name`]=t,r.getRootRef().update(i)}))},openRoom:function(e){return this.setRoomState(e,"open")},closeRoom:function(e){return this.setRoomState(e,"closed")},getUserList:function(e){if(void 0===e)return this.userList.getUsers();var t=this;return new Promise((function(r,s){new U({itemIDKey:"joinAt",mode:"once"}).once("update",(function(e){r(e)})).startUpdate(t.getUserListRef(e))}))},getRoomList:function(e,t){var r=this;return new Promise((function(s,i){r.roomList.once("roomlist.update",(function(e){s(e)})).startUpdate(r.getRoomListQuery(e,t))}))},hasRoom:function(e){return e===this.roomID?Promise.resolve(!0):this.getRoomDataRef(e).once("value").then((function(e){var t=null!==e.val();return Promise.resolve(t)}))}};Object.assign(ge,fe);class Ie{constructor(e){var t=c(e,"eventEmitter",void 0),r=c(e,"EventEmitterClass",void 0);this.setEventEmitter(t,r),this.database=firebase.database(),this.rootPath=c(e,"root",""),this.userInfo={userID:"",userName:""},this.setUser(c(e,"userID",""),c(e,"userName","")),this.isRoomCreator=!1,this.roomID=void 0,this.roomName=void 0,this.roomType=void 0,this.doorState=void 0,this.leftRoomFlag=!1,this.isRemoveRoomWhenLeft=void 0,this.userList=T.call(this,e),this.roomList=A.call(this,e),this.broadcast=S.call(this,e),this.tables=re.call(this,e)}shutdown(){var e=this;this.destroyEventEmitter().leaveRoom().then((function(){e.userList.destroy(),e.userList=void 0,e.roomList.destroy(),e.roomList=void 0,e.broadcast.destroy(),e.broadcast=void 0}))}destroy(){this.shutdown()}get userID(){return this.userInfo.userID}set userID(e){this.userInfo.userID=e}get userName(){return this.userInfo.userName}set userName(e){this.userInfo.userName=e}getRoomInfo(e,t){return void 0===e&&(e=this.roomID),void 0===t&&(t=this.roomName),{roomID:e,roomName:t}}setUser(e,t){return d(e)?this.userInfo=e:(this.userID=e,this.userName=t),this}isInRoom(e){return void 0===e?void 0!==this.roomID:this.roomID===e}isFull(){return this.userList.isFull()}isFirstUser(e){return this.userList.isFirstUser(e)}getUsers(){return this.userList.getUsers()}get maxUsers(){return this.userList.maxUsers}getTable(e){return this.tables[e]}}Object.assign(Ie.prototype,u,ge),h.register("room",(function(e){return new Ie(e)})),y(window,"RexPlugins.Fire.Room",Ie);var pe=function(e){var t=new _({eventEmitter:this.getEventEmitter(),eventNames:{join:"userlist.join",leave:"userlist.leave",update:"userlist.update",change:"userlist.change",init:"userlist.init",changename:"userlist.changename"},root:this.getUserListPath(),userID:this.userInfo,maxUsers:c(e,"maxUsers",0)});return t.on("userlist.leave",(function(e){e.userID===this.userID&&ye.call(this)}),this),this.on("room.join",(function(){t.startUpdate()})).on("room.leave",(function(){t.stopUpdate().clear()})),t},ye=function(){this.emit("room.leave");var e=this;setTimeout((function(){e.leftRoomFlag=!1}),0)},De=function(e){var t=c(e,"broadcast",!0);if(!t)return null;var r=new f({eventEmitter:this.getEventEmitter(),eventNames:{receive:"broadcast.receive"},root:this.rootPath,receiverID:"broadcast",senderID:this.userInfo,history:c(t,"history",!1)});return this.on("room.join",(function(){r.startReceiving()})).on("room.leave",(function(){r.stopReceiving()})).on("userlist.changename",(function(e,t){r.changeUserName(e,t)}),this),r},Re=function(e){var t,r=c(e,"tables",void 0);if(void 0===r)return{};for(var s={},i=0,n=r.length;i0){var i=t.docs[0];r=Ae(i),s.cacheHeaders[e]=r}return Promise.resolve(r)}))};class Ke{constructor(e){this.database=firebase.firestore(),this.setRootPath(c(e,"root","")),this.cacheHeaders={},this.userInfo={userID:""},this.setOwner(c(e,"userID",""))}shutdown(){}destroy(){this.shutdown()}get userID(){return this.userInfo.userID}set userID(e){this.userInfo.userID=e}setRootPath(e){return this.rootPath=e,this.rootRef=this.database.collection(e),this}setOwner(e){var t=this.userID;return d(e)?this.userInfo=e:this.userID=e,t!==this.userID&&this.clearCache(),this}clearCache(){return t(this.cacheHeaders),this}getFileQuery(e,t,r){var s=this.rootRef;return s=e?s.where("userID","==",e):s,s=t?s.where("fileID","==",t):s,s=r?s.where("type","==",r):s}}var Be={save:function(e,t,r,s){"boolean"==typeof r&&(s=r,r=void 0),void 0===s&&(s=!1);var i=this.userID;void 0===t&&(t={}),t.userID=i,t.fileID=e,t.type="header",r&&(r.userID=i,r.fileID=e,r.type="content");var n=s?"update":"set",a=this;return Se.call(this,e).then((function(e){var s,i;e?(s=a.rootRef.doc(e.headerDocID),r&&(i=e.contentDocID?a.rootRef.doc(e.contentDocID):a.rootRef.doc())):(s=a.rootRef.doc(),r&&(i=a.rootRef.doc())),t.hasOwnProperty("headerDocID")&&delete t.headerDocID,i&&(t.contentDocID=i.id);var o=a.database.batch();return o[n](s,t),r&&o[n](i,r),o.commit()})).then((function(){return Promise.resolve({userID:i,fileID:e})})).catch((function(t){return Promise.reject({error:t,userID:i,fileID:e})}))},load:function(e){var t=this.userID;return this.getFileQuery(t,e).get().then((function(r){var s,i;return r.forEach((function(e){switch(docData.type){case"header":s=Ae(e);break;case"content":i=e.data()}})),Promise.resolve({userID:t,fileID:e,header:s,content:i})})).catch((function(){return Promise.reject({error:error,userID:t,fileID:e})}))},loadHeaders:function(){var e=this.userID,r=this;return this.getFileQuery(e,void 0,"header").get().then((function(s){var i;return t(r.cacheHeaders),s.forEach((function(e){i=Ae(e),r.cacheHeaders[i.fileID]=i})),Promise.resolve({userID:e,headers:r.cacheHeaders})})).catch((function(){return Promise.reject({error:error,userID:e})}))},delete:function(e){var t=this.userID,r=this;return LoadHeader.call(this,e).then((function(s){if(!s)return Promise.resolve({userID:t,fileID:e});var i=r.database.batch();return i.delete(r.rootRef.doc(s.headerDocID)),s.contentDocID&&i.delete(r.rootRef.doc(s.contentDocID)),i.commit()})).then((function(){return r.cacheHeaders.hasOwnProperty(e)&&delete r.cacheHeaders[e],Promise.resolve({userID:t,fileID:e})})).catch((function(r){return Promise.reject({error:r,userID:t,fileID:e})}))},clear:function(){var e=this.userID,t=this;return this.getFileQuery(e,void 0,"header").get().then((function(e){var r,s=t.database.batch();return e.forEach((function(e){r=DocToHeader(e),s.delete(t.rootRef.doc(r.headerDocID)),r.contentDocID&&s.delete(t.rootRef.doc(r.contentDocID))})),s.commit()})).then((function(){return t.clearCache(),Promise.resolve({userID:e})})).catch((function(t){return Promise.reject({error:t,userID:e})}))}};Object.assign(Ke.prototype,Be),h.register("files",(function(e){return new Ke(e)})),y(window,"RexPlugins.Fire.Files",Ke);var qe=function(e,t){var r=this;return this.database.runTransaction((function(s){var i=r.getAliasRef(t);return s.get(i).then((function(r){return r.exists?Promise.reject({id:e,alias:t}):(s.set(i,{id:e}),Promise.resolve({id:e,alias:t}))}))}))},ze=function(e,t,r,s){var i=ce(t,t,r);if(s<=0)return Promise.reject({id:e,alias:i});s--;var n=this;return qe.call(n,e,i).catch((function(){setTimeout((function(){return ze.call(n,e,t,r,s)}),0)}))};class He{constructor(e){this.database=firebase.firestore(),this.setRootPath(c(e,"root",""))}shutdown(){}destroy(){this.shutdown()}setRootPath(e){return this.rootPath=e,this.rootRef=this.database.collection(e),this}getAliasRef(e){return this.rootRef.doc(e)}}var Ve={add:function(e,t){var r=this;return this.getAlias(e).then((function(s){return s.alias?s.alias===t?Promise.resolve({id:e,alias:t}):Promise.reject({id:e,alias:t}):qe.call(r,e,t)}))},addRandom:function(e,t){var r=c(t,"digits",10),s=c(t,"candidates","0123456789"),i=c(t,"retry",1e3),n=this;return this.getAlias(e).then((function(t){if(t.alias){var a=ce(r,r,s);return t.alias===a?Promise.resolve({id:e,alias:a}):Promise.reject({id:e,alias:a})}return ze.call(n,e,r,s,i)}))},getId:function(e){return this.getAliasRef(e).get().then((function(t){var r;return t.exists&&(r=t.data().id),Promise.resolve({id:r,alias:e})}))},getAlias:function(e){return this.rootRef.where("id","==",e).limit(1).get().then((function(t){var r;return t.size>0&&(r=t.docs[0].id),Promise.resolve({id:e,alias:r})}))},getRandomAlias:function(e,t){var r=c(t,"digits",10),s=c(t,"candidates","0123456789"),i=c(t,"retry",1e3),n=this;return this.getAlias(e).then((function(t){return t.alias?Promise.resolve(t):ze.call(n,e,r,s,i)}))},remove:function(e){var t=this;return this.getAlias(e).then((function(e){return t.getAliasRef(e).delete()}))}};Object.assign(He.prototype,Ve),h.register("idAlias",(function(e){return new He(e)})),y(window,"RexPlugins.Fire.IdAlias",He);var We=function(e){var t=e?new Date(e):new Date,r=t.getFullYear(),s=t.getMonth()+1,i=t.getDate(),n=new Date(t.getFullYear(),0,1);return{d:`${r}-${s}-${i}`,w:`${r}-${Math.ceil(((t-n)/864e5+n.getDay()+1)/7)}`,m:`${r}-${s}`,y:`${r}`,a:""}},Ye={d:"tagD",w:"tagW",m:"tagM",y:"tagY",a:"tagA"},Ge={d:"scoreD",w:"scoreW",m:"scoreM",y:"scoreY",a:"scoreA"},Je={loadFirstPage(){this.resetPageQuery();var e=this;return this.page.loadFirstPage().then((function(t){return Promise.resolve(Xe.call(e,t))}))},loadNextPage(){this.resetPageQuery();var e=this;return this.page.loadNextPage().then((function(t){return Promise.resolve(Xe.call(e,t))}))},loadPreviousPage(){this.resetPageQuery();var e=this;return this.page.loadPreviousPage().then((function(t){return Promise.resolve(Xe.call(e,t))}))},loadCurrentPage(){this.resetPageQuery();var e=this;return this.page.loadCurrentPage().then((function(t){return Promise.resolve(Xe.call(e,t))}))},load(e,t){this.resetPageQuery();var r=this;return this.page.load(e,t).then((function(e){return Promise.resolve(Xe.call(r,e))}))},resetPageQuery(){return this.resetQueryFlag?(this.resetQueryFlag=!1,this.page.setQuery(this.getPageQuery()),this):this}},Xe=function(e){for(var t,r=[],s=Ge[this.timeFilterType[0]],i=0,n=e.length;i=500&&(s.push(t.commit()),t=void 0);return t&&s.push(t.commit()),Promise.all(s)}))},et={deleteUser(e){void 0===e&&(e=this.userID);var t=this.getRecordQuery(void 0,void 0,e,void 0);return Ze(t)},deleteBoard(e,t){void 0===e&&(e=this.boardID),void 0===t&&(t=this.tag);var r=this.getRecordQuery(e,t,void 0,void 0);return Ze(r)}},tt={getRecordQuery(e,t,r,s){var i=this.rootRef;return i=void 0!==e?i.where("boardID","==",e):i,i=void 0!==t?i.where("tag","==",t):i,i=void 0!==r?i.where("userID","==",r):i,void 0!==s&&(i=i.where(s[0],"==",s[1])),i},getMyRecordQuery(e){return void 0===e&&(e=this.userID),this.getRecordQuery(this.boardID,this.tag,e,void 0).limit(1)},getPageQuery(){var e,t;if(!1!==this.timeFilters){var r=this.timeFilterType[0];e=[Ye[r],We()[r]],t=Ge[r]}else e=void 0,t="score";var s=this.getRecordQuery(this.boardID,this.tag,void 0,e);return{next:s.orderBy(t,"desc"),previous:s.orderBy(t)}}};class rt{constructor(e){this.database=firebase.firestore(),this.setRootPath(c(e,"root","")),this.userInfo={userID:void 0,userName:void 0},this.setUser(c(e,"userID",""),c(e,"userName",void 0)),this.setBoardID(c(e,"boardID",void 0)),this.setTag(c(e,"tag",void 0)),this.setTimeFilters(c(e,"timeFilters",!1)),this.setTimeFilterType(c(e,"timeFilterType","year")),this.page=new $e({dataMode:"dynamic",itemCount:c(e,"pageItemCount",100)}),this.resetQueryFlag=!0}shutdown(){}destroy(){this.shutdown()}get userID(){return this.userInfo.userID}set userID(e){this.userInfo.userID=e}get userName(){return this.userInfo.userName}set userName(e){this.userInfo.userName=e}setRootPath(e){return this.resetQueryFlag|=this.rootPath!==e,this.rootPath=e,this.rootRef=this.database.collection(e),this}setUser(e,t){return d(e)?this.userInfo=e:(this.userID=e,this.userName=t),this}setBoardID(e){return this.resetQueryFlag|=this.boardID!==e,this.boardID=e,this}setTag(e){return this.resetQueryFlag|=this.tag!==e,this.tag=e,this}setTimeFilters(e){return this.timeFilters=!1!==e&&{d:c(e,"day",!0),w:c(e,"week",!0),m:c(e,"month",!0),y:c(e,"year",!0),a:c(e,"all",!0)},this}setTimeFilterType(e){return this.resetQueryFlag|=this.timeFilterType!==e,this.timeFilterType=e,this}setPageItemCount(e){return this.page.setItemCount(e),this}get pageIndex(){return this.page.pageIndex}get isFirstPage(){return 0===this.page.pageIndex}get isLastPage(){return!1===this.page.isFullPage}}var st={post:function(e,t,r){var s={userID:this.userID};void 0!==this.boardID&&(s.boardID=this.boardID),this.userName&&(s.userName=this.userName);var i=We(r);if(!1!==this.timeFilters)for(var n in this.timeFilters)this.timeFilters[n]&&(s[Ye[n]]=i[n],s[Ge[n]]=e);else s.score=e;this.tag&&(s.tag=this.tag),t&&Object.assign(s,t);var a=this;return this.getMyRecordQuery().get().then((function(e){var t,r;if(e.size>0){var i=e.docs[0];t=i.data(),r=i.id}if(t)if(!1!==a.timeFilters){for(var n in a.timeFilters)if(a.timeFilters[n]){var o=Ye[n];if(t[o]===s[o]){var h=Ge[n];s[h]=Math.max(t[h],s[h])}}}else s.score=Math.max(t.score,s.score);return void 0===r&&(r=a.rootRef.doc().id),a.rootRef.doc(r).set(s)}))},getScore:function(e){return this.getMyRecordQuery(e).get().then((function(e){var t;return e.size>0&&(t=e.docs[0].data()),Promise.resolve(t)}))},getRank:function(e){return void 0===e&&(e=this.userID),function(e,t){var r={doc:void 0,index:void 0},s=0;return we({query:e,forEachPageCallback:function(e){for(var i,n=e.docs,a=0,o=n.length;a0){var r=e.docs[0];if(r.metadata.hasPendingWrites)return void(t.skipFirst&&(t.skipFirst=!1));if(t.resetPageQuery(t.receiverID,r),t.skipFirst)t.skipFirst=!1;else{var s=nt(r);t.cacheMessages.push(s),t.emit("receive",s)}}else t.skipFirst&&(t.skipFirst=!1)}),(function(e){})),this},stopReceiving(){return this.unsubscribe&&this.unsubscribe(),this.resetQueryFlag=!0,this.cacheMessages.length=0,this},loadPreviousMessages(){this.resetPageQuery(this.receiverID);var e=this;return this.page.loadNextPage().then((function(t){for(var r=[],s=0,i=t.length;s