text: !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).rexparse=t()}(this,function(){"use strict";function u(e){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function s(e,t,r){return t&&i(e.prototype,t),r&&i(e,r),e}function o(e){return function(e){if(Array.isArray(e))return a(e)}(e)||function(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return a(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return a(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function r(r){return new Promise(function(e,t){!function(e,t){for(var r=document.getElementsByTagName("script"),n=0,i=r.length;n<i;n++)if(-1!=r[n].src.indexOf(e))return t&&t();var s=document.createElement("script");s.setAttribute("src",e),t&&(s.onload=t),document.head.appendChild(s)}(r,e)})}function c(e){return void 0===e.startIndex&&(e.startIndex=0),void 0===e.totalLines&&(e.totalLines=1/0),void 0===e.linesPerPage&&(e.linesPerPage=1e3),e.remainderLines=e.totalLines,d(e)}function l(e,t,r){var n=[];return c({query:e,startIndex:t,totalLines:r,forEachPageCallback:function(e){n.push.apply(n,o(e))},resolveCallback:function(){return n}})}var t=function(){function r(){n(this,r)}return s(r,[{key:"initializeApp",value:function(e){return firebase.initializeApp(e),this}}],[{key:"register",value:function(e,t){r.prototype[e]=t}}]),r}(),h="https://npmcdn.com/parse@".concat("2.11.0","/dist/parse.min.js"),f=function(e,t,r){if(e&&"number"!=typeof e){if(e.hasOwnProperty(t))return e[t];if(-1===t.indexOf("."))return r;for(var n=t.split("."),i=e,s=r,o=0;o<n.length;o++){if(!i.hasOwnProperty(n[o])){s=r;break}s=i[n[o]],i=i[n[o]]}return s}return r},d=function n(i){var e=i.query,s=Math.min(i.remainderLines,i.linesPerPage);return i.remainderLines-=s,e.skip(i.startIndex).limit(s).find().then(function(e){var t,r=0===i.remainderLines||e.length<s;return i.forEachPageCallback&&(r|=!!i.forEachPageCallback(e)),r?(i.resolveCallback&&(t=i.resolveCallback()),Promise.resolve(t)):(i.startIndex+=e.length,n(i))})},e={loadItems:function(t,r){void 0===t&&(t=0),void 0===r&&(r=1/0),this.items.length=0;var n=this;return l(this.query,t,r).then(function(e){return n.items=e,n.startIndex=t,n.pageIndex=Math.floor(t/n.itemCount),n.isFullPage=r===1/0||r===e.length,Promise.resolve(e)}).catch(function(e){return n.isFullPage=!1,Promise.reject(e)})},loadPage:function(e){var t=e*this.itemCount;return this.loadItems(t,this.itemCount)},loadFirstPage:function(){return this.loadItems(0,this.itemCount)},loadCurrentPage:function(){return this.loadItems(this.startIndex,this.itemCount)},loadNextPage:function(){var e=this.startIndex+this.itemCount;return this.loadItems(e,this.itemCount)},loadPreviousPage:function(){var e=this.startIndex-this.itemCount;return this.loadItems(e,this.itemCount)}},g=function(){function t(e){n(this,t),this.items=[],this.startIndex=0,this.pageIndex=0,this.isFullPage=!1,this.setItemCount(f(e,"itemCount",100)),this.setQuery(f(e,"query",void 0))}return s(t,[{key:"setItemCount",value:function(e){return this.itemCount=e,this.pageIndex=Math.floor(this.startIndex/e),this}},{key:"setQuery",value:function(e){return this.query=e,this}},{key:"getItem",value:function(e){return this.items[e-this.startIndex]}},{key:"findFirst",value:function(e,t){for(var r,n=this.items.length;r<n;r++)if(this.items[r].get(e)===t)return r+this.startIndex;return-1}}]),t}();Object.assign(g.prototype,e);function y(e){return null==e||""===e||0===e.length}function m(e,t,r){if("object"===u(e)){if(y(t)){if(null==r)return;"object"===u(r)&&(e=r)}else{"string"==typeof t&&(t=t.split("."));var n=t.pop();(function(e,t,r){var n=e;if(!y(t)){var i;"string"==typeof t&&(t=t.split("."));for(var s=0,o=t.length;s<o;s++){var a;if(null==n[i=t[s]]||"object"!==u(n[i]))a=s!==o-1||void 0===r?{}:r,n[i]=a;n=n[i]}}return n})(e,t)[n]=r}return e}}t.register("pageLoader",function(e){return new g(e)}),m(window,"RexPlugins.Parse.PageLoader",g);function v(e){return e.select("id"),l(e).then(function(e){return 0===e.length?Promise.resolve():Parse.Object.destroyAll(e)})}function p(e,t,r){return(r=r||new t).set(e),r}function P(e,t,r){if(!t&&!r)return e;var n=Parse.User.current();if(!n)return e;var i=new Parse.ACL(n);return r||i.setPublicWriteAccess(!0),t||i.setPublicReadAccess(!0),e.setACL(i),e}var I=function(e){for(var t=e.length-1;0<t;t--){var r=Math.floor(Math.random()*(t+1)),n=e[t];e[t]=e[r],e[r]=n}return e},b={loadItem:function(e,t){if("string"==typeof e){var r=this.baseQuery;return t&&(r=r.select(t)),r.get(e)}r=this.getQuery(e).limit(1);return t&&(r=r.select(t)),r.find().then(function(e){return Promise.resolve(e[0])})},loadPage:function(e){return this.pageLoader.loadPage(e)},loadCurrentPage:function(){return this.pageLoader.loadCurrentPage()},loadNextPage:function(){return this.pageLoader.loadNextPage()},loadPreviousPage:function(){return this.pageLoader.loadPreviousPage()},loadItems:function(e,t){return this.pageLoader.loadItems(e,t)},load:function(e){return void 0===e&&(e=this.baseQuery),l(e)},loadRandomItems:function(n,i){"number"==typeof n&&(i=n,n=void 0),void 0===n&&(n=this.baseQuery),void 0===i&&(i=1),n.select("id");var s=this;return l(n).then(function(e){I(e),i=Math.min(i,e.length);for(var t=[],r=0;r<i;r++)t.push(e[r].id);return n=s.baseQuery.containedIn("objectId",t),l(n)})}},w={deleteItem:function(e){return this.createItem().set("id",e).destroy()},delete:function(e){return void 0===e&&(e=this.baseQuery),v(e)}},C=function(){function r(e){n(this,r),this.pageLoader=new g,this.setClassName(f(e,"className","Item")),this.setItemCount(f(e,"itemCount",100)),this.setQuery(),this.primaryKeys=[];var t=f(e,"primaryKeys",void 0);t&&this.setPrimaryKey(t),this.setOwnerReadMode(f(e,"ownerRead",void 0)),this.setOwnerWriteMode(f(e,"ownerWrite",void 0))}return s(r,[{key:"setClassName",value:function(e){return this.customClass=Parse.Object.extend(e),this}},{key:"setPrimaryKey",value:function(e){return e?"string"==typeof e?(this.primaryKeys.length=1,this.primaryKeys[0]=e):function(e,t,r,n){void 0===r&&(r=0),void 0===n&&(n=t.length),e.length=n-r;for(var i=0,s=e.length;i<s;i++)e[i]=t[i+r]}(this.primaryKeys,e):this.primaryKeys.length=0,this}},{key:"setOwnerReadMode",value:function(e){return this.ownerRead=e,this}},{key:"setOwnerWriteMode",value:function(e){return this.ownerWrite=e,this}},{key:"createItem",value:function(){return new this.customClass}},{key:"setItemCount",value:function(e){return this.pageLoader.setItemCount(e),this}},{key:"setQuery",value:function(e){return void 0===e&&(e=this.baseQuery),this.pageLoader.setQuery(e),this}},{key:"baseQuery",get:function(){return new Parse.Query(this.customClass)}},{key:"startIndex",get:function(){return this.pageLoader.startIndex}},{key:"pageIndex",get:function(){return this.pageLoader.pageIndex}},{key:"isLastPage",get:function(){return this.pageLoader.isLastPage}}]),r}(),k={getQuery:function(e){for(var t,r,n=this.baseQuery,i=e instanceof this.customClass,s=0,o=this.primaryKeys.length;s<o;s++)t=this.primaryKeys[s],r=i?e.get(t):e[t],n.equalTo(t,r);return n},save:function(r){if(e=r,"[object Array]"===Object.prototype.toString.call(e))return this.saveItems(r);var e,n=this;return new Promise(function(e,t){if(!(0<n.primaryKeys.length))return e();n.loadItem(r,"id").then(e,t)}).then(function(e){return e=p(r,n.customClass,e),P(e,n.ownerRead,n.ownerWrite),e.save()})},saveItems:function(c){var l=this;return new Promise(function(e,t){var r=[];if(!(0<l.primaryKeys.length)){for(a=0,u=c.length;a<u;a++){var n=p(c[a],l.customClass);P(n,l.ownerRead,l.ownerWrite),r.push(n)}return e(r)}for(var i,s=[],o=function(){var t=c[a];i=l.loadItem(t,"id").then(function(e){e=p(t,l.customClass,e),P(e,l.ownerRead,l.ownerWrite),r.push(e)}),s.push(i)},a=0,u=c.length;a<u;a++)o();Promise.all(s).then(function(){return e(r)}).catch(t)}).then(function(e){return Parse.Object.saveAll(e)})},getItemCount:function(e){return void 0===e&&(e=this.baseQuery),e.count()}};Object.assign(C.prototype,b,w,k),t.register("itemTable",function(e){return new C(e)}),m(window,"RexPlugins.Parse.ItemTable",C);function Q(e){var t=e?new Date(e):new Date,r=t.getFullYear(),n=t.getMonth()+1,i=t.getDate(),s=new Date(t.getFullYear(),0,1),o=Math.ceil(((t-s)/864e5+s.getDay()+1)/7);return{d:"".concat(r,"-").concat(n,"-").concat(i),w:"".concat(r,"-").concat(o),m:"".concat(r,"-").concat(n),y:"".concat(r)}}var x=function(e){if("object"!==u(e)||e.nodeType||e===e.window)return!1;try{if(e.constructor&&!{}.hasOwnProperty.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(e){return!1}return!0},F={d:"tagD",w:"tagW",m:"tagM",y:"tagY"},D={d:"scoreD",w:"scoreW",m:"scoreM",y:"scoreY"},L={loadFirstPage:function(){this.resetPageQuery();var t=this;return this.page.loadFirstPage().then(function(e){return Promise.resolve(O.call(t,e))})},loadNextPage:function(){this.resetPageQuery();var t=this;return this.page.loadNextPage().then(function(e){return Promise.resolve(O.call(t,e))})},loadPreviousPage:function(){this.resetPageQuery();var t=this;return this.page.loadPreviousPage().then(function(e){return Promise.resolve(O.call(t,e))})},loadCurrentPage:function(){this.resetPageQuery();var t=this;return this.page.loadCurrentPage().then(function(e){return Promise.resolve(O.call(t,e))})},load:function(e,t){this.resetPageQuery();var r=this;return this.page.load(e,t).then(function(e){return Promise.resolve(O.call(r,e))})},resetPageQuery:function(){return this.resetQueryFlag&&(this.resetQueryFlag=!1,this.page.setQuery(this.getPageQuery())),this}},O=function(e){for(var t,r=[],n=D[this.timeFilterType[0]],i=0,s=e.length;i<s;i++){if(t=e[i].toJSON(),!1!==this.timeFilters)for(var o in t.score=t[n],this.timeFilters)delete t[F[o]],delete t[D[o]];r.push(t)}return r},T={deleteUser:function(e){void 0===e&&(e=this.userID);var t=this.getRecordQuery(void 0,void 0,e,void 0);return v(t)},deleteBoard:function(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 v(r)}},j={getRecordQuery:function(e,t,r,n){var i=this.baseQuery;return i=void 0!==e?i.equalTo("boardID",e):i,i=void 0!==t?i.equalTo("tag",t):i,i=void 0!==r?i.equalTo("userID",r):i,void 0!==n&&(i=i.equalTo(n[0],n[1])),i},getMyRecordQuery:function(e){return void 0===e&&(e=this.userID),this.getRecordQuery(this.boardID,this.tag,e,void 0).limit(1)},getPageQuery:function(){var e,t;if(!1!==this.timeFilters){var r=this.timeFilterType[0];e=[F[r],Q()[r]],t=D[r]}else e=void 0,t="score";var n=this.getRecordQuery(this.boardID,this.tag,void 0,e);return n=n.descending(t)}},N=function(){function t(e){n(this,t),this.setClassName(f(e,"className","Item")),this.userInfo={userID:void 0,userName:void 0},this.setUser(f(e,"userID",""),f(e,"userName",void 0)),this.setBoardID(f(e,"boardID",void 0)),this.setTag(f(e,"tag",void 0)),this.setTimeFilters(f(e,"timeFilters",!1)),this.setTimeFilterType(f(e,"timeFilterType","year")),this.page=new g({itemCount:f(e,"pageItemCount",100)}),this.resetQueryFlag=!0}return s(t,[{key:"shutdown",value:function(){}},{key:"destroy",value:function(){this.shutdown()}},{key:"userID",get:function(){return this.userInfo.userID},set:function(e){this.userInfo.userID=e}},{key:"userName",get:function(){return this.userInfo.userName},set:function(e){this.userInfo.userName=e}},{key:"setClassName",value:function(e){return this.resetQueryFlag=!0,this.customClass=Parse.Object.extend(e),this}},{key:"setUser",value:function(e,t){return x(e)?this.userInfo=e:(this.userID=e,this.userName=t),this}},{key:"setBoardID",value:function(e){return this.resetQueryFlag|=this.boardID!==e,this.boardID=e,this}},{key:"setTag",value:function(e){return this.resetQueryFlag|=this.tag!==e,this.tag=e,this}},{key:"setTimeFilters",value:function(e){return this.timeFilters=!1!==e&&{d:f(e,"day",!0),w:f(e,"week",!0),m:f(e,"month",!0),y:f(e,"year",!0)},this}},{key:"setTimeFilterType",value:function(e){return this.resetQueryFlag|=this.timeFilterType!==e,this.timeFilterType=e,this}},{key:"setPageItemCount",value:function(e){return this.page.setItemCount(e),this}},{key:"baseQuery",get:function(){return new Parse.Query(this.customClass)}},{key:"pageIndex",get:function(){return this.page.pageIndex}},{key:"isFirstPage",get:function(){return 0===this.page.pageIndex}},{key:"isLastPage",get:function(){return!1===this.page.isFullPage}}]),t}(),R={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 n=Q(r);if(!1!==this.timeFilters)for(var i in this.timeFilters)this.timeFilters[i]&&(s[F[i]]=n[i],s[D[i]]=e);else s.score=e;this.tag&&(s.tag=this.tag),t&&Object.assign(s,t);n=Q();var o=this;return this.getMyRecordQuery().find().then(function(e){var t=e[0];if(t)if(!1!==o.timeFilters){for(var r in o.timeFilters)if(o.timeFilters[r]){var n=F[r];if(t.get(n)===s[n]){var i=D[r];s[i]=Math.max(t.get(i),s[i])}}}else s.score=Math.max(t.get("score"),s.score);return p(s,o.customClass,t).save()})},getScore:function(e){return this.getMyRecordQuery(e).find().then(function(e){var t=e[0];return t=t&&t.toJSON(),Promise.resolve(t)})},getRank:function(t){void 0===t&&(t=this.userID);var i,s,o,e=this.getPageQuery();return i=function(e){return e.get("userID")===t},s={item:void 0,index:void 0},o=0,c({query:e,forEachPageCallback:function(e){for(var t,r=0,n=e.length;r<n;r++)if(t=e[r],i(t))return s.item=t,s.index=o+r,!0;o+=e.length},resolveCallback:function(){return s}}).then(function(e){return Promise.resolve({userID:t,rank:e.index})})}};Object.assign(N.prototype,R,j,L,T),t.register("leaderBoard",function(e){return new N(e)}),m(window,"RexPlugins.Parse.Leaderboard",N);var M=function(e,t){var r=new Parse.User;return r.set("username",e).set("password",t),r.signUp().then(function(){return Parse.User.logIn(e,t)})},A=function(){function e(){n(this,e),this.add=new t}return s(e,[{key:"preload",value:function(e){return void 0===(t=e)&&(t=h),r(t);var t}}]),e}(),S={quickLogin:function(e,t){return Parse.User.logOut().then(function(){return Parse.User.logIn(e,t)}).catch(function(){return M(e,t)})}};return Object.assign(A.prototype,S),A});
  