im-browser.min.js 228 KB

123456789101112131415161718192021
  1. !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define("leancloud-realtime",["exports"],t):t((e=e||self).AV=e.AV||{})}(this,(function(e){"use strict";var t="undefined"!=typeof window&&window.process||{};t.env=t.env||{};var r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function n(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function i(e,t,r){return e(r={path:t,exports:{},require:function(e,t){return s(null==t&&r.path)}},r.exports),r.exports}function s(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}var o=i((function(e){function t(e){if(e)return function(e){for(var r in t.prototype)e[r]=t.prototype[r];return e}(e)}e.exports=t,t.prototype.on=t.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},t.prototype.once=function(e,t){function r(){this.off(e,r),t.apply(this,arguments)}return r.fn=t,this.on(e,r),this},t.prototype.off=t.prototype.removeListener=t.prototype.removeAllListeners=t.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var r,n=this._callbacks["$"+e];if(!n)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var i=0;i<n.length;i++)if((r=n[i])===t||r.fn===t){n.splice(i,1);break}return 0===n.length&&delete this._callbacks["$"+e],this},t.prototype.emit=function(e){this._callbacks=this._callbacks||{};for(var t=new Array(arguments.length-1),r=this._callbacks["$"+e],n=1;n<arguments.length;n++)t[n-1]=arguments[n];if(r){n=0;for(var i=(r=r.slice(0)).length;n<i;++n)r[n].apply(this,t)}return this},t.prototype.listeners=function(e){return this._callbacks=this._callbacks||{},this._callbacks["$"+e]||[]},t.prototype.hasListeners=function(e){return!!this.listeners(e).length}})),a=c;c.default=c,c.stable=f,c.stableStringify=f;var u=[],l=[];function c(e,t,r){var n;for(!function e(t,r,n,i){var s;if("object"==typeof t&&null!==t){for(s=0;s<n.length;s++)if(n[s]===t){var o=Object.getOwnPropertyDescriptor(i,r);return void(void 0!==o.get?o.configurable?(Object.defineProperty(i,r,{value:"[Circular]"}),u.push([i,r,t,o])):l.push([t,r]):(i[r]="[Circular]",u.push([i,r,t])))}if(n.push(t),Array.isArray(t))for(s=0;s<t.length;s++)e(t[s],s,n,t);else{var a=Object.keys(t);for(s=0;s<a.length;s++){var c=a[s];e(t[c],c,n,t)}}n.pop()}}(e,"",[],void 0),n=0===l.length?JSON.stringify(e,t,r):JSON.stringify(e,d(t),r);0!==u.length;){var i=u.pop();4===i.length?Object.defineProperty(i[0],i[1],i[3]):i[0][i[1]]=i[2]}return n}function h(e,t){return e<t?-1:e>t?1:0}function f(e,t,r){var n,i=function e(t,r,n,i){var s;if("object"==typeof t&&null!==t){for(s=0;s<n.length;s++)if(n[s]===t){var o=Object.getOwnPropertyDescriptor(i,r);return void(void 0!==o.get?o.configurable?(Object.defineProperty(i,r,{value:"[Circular]"}),u.push([i,r,t,o])):l.push([t,r]):(i[r]="[Circular]",u.push([i,r,t])))}if("function"==typeof t.toJSON)return;if(n.push(t),Array.isArray(t))for(s=0;s<t.length;s++)e(t[s],s,n,t);else{var a={},c=Object.keys(t).sort(h);for(s=0;s<c.length;s++){var f=c[s];e(t[f],f,n,t),a[f]=t[f]}if(void 0===i)return a;u.push([i,r,t]),i[r]=a}n.pop()}}(e,"",[],void 0)||e;for(n=0===l.length?JSON.stringify(i,t,r):JSON.stringify(i,d(t),r);0!==u.length;){var s=u.pop();4===s.length?Object.defineProperty(s[0],s[1],s[3]):s[0][s[1]]=s[2]}return n}function d(e){return e=void 0!==e?e:function(e,t){return t},function(t,r){if(l.length>0)for(var n=0;n<l.length;n++){var i=l[n];if(i[1]===t&&i[0]===r){r="[Circular]",l.splice(n,1);break}}return e.call(this,t,r)}}function p(e){return(p="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)}var m=function(e){return null!==e&&"object"===p(e)};function g(e){return(g="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)}var y=v;function v(e){if(e)return function(e){for(var t in v.prototype)Object.prototype.hasOwnProperty.call(v.prototype,t)&&(e[t]=v.prototype[t]);return e}(e)}v.prototype.clearTimeout=function(){return clearTimeout(this._timer),clearTimeout(this._responseTimeoutTimer),clearTimeout(this._uploadTimeoutTimer),delete this._timer,delete this._responseTimeoutTimer,delete this._uploadTimeoutTimer,this},v.prototype.parse=function(e){return this._parser=e,this},v.prototype.responseType=function(e){return this._responseType=e,this},v.prototype.serialize=function(e){return this._serializer=e,this},v.prototype.timeout=function(e){if(!e||"object"!==g(e))return this._timeout=e,this._responseTimeout=0,this._uploadTimeout=0,this;for(var t in e)if(Object.prototype.hasOwnProperty.call(e,t))switch(t){case"deadline":this._timeout=e.deadline;break;case"response":this._responseTimeout=e.response;break;case"upload":this._uploadTimeout=e.upload;break;default:console.warn("Unknown timeout option",t)}return this},v.prototype.retry=function(e,t){return 0!==arguments.length&&!0!==e||(e=1),e<=0&&(e=0),this._maxRetries=e,this._retries=0,this._retryCallback=t,this};var b=["ECONNRESET","ETIMEDOUT","EADDRINFO","ESOCKETTIMEDOUT"];v.prototype._shouldRetry=function(e,t){if(!this._maxRetries||this._retries++>=this._maxRetries)return!1;if(this._retryCallback)try{var r=this._retryCallback(e,t);if(!0===r)return!0;if(!1===r)return!1}catch(e){console.error(e)}if(t&&t.status&&t.status>=500&&501!==t.status)return!0;if(e){if(e.code&&b.includes(e.code))return!0;if(e.timeout&&"ECONNABORTED"===e.code)return!0;if(e.crossDomain)return!0}return!1},v.prototype._retry=function(){return this.clearTimeout(),this.req&&(this.req=null,this.req=this.request()),this._aborted=!1,this.timedout=!1,this.timedoutError=null,this._end()},v.prototype.then=function(e,t){var r=this;if(!this._fullfilledPromise){var n=this;this._endCalled&&console.warn("Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises"),this._fullfilledPromise=new Promise((function(e,t){n.on("abort",(function(){if(r.timedout&&r.timedoutError)t(r.timedoutError);else{var e=new Error("Aborted");e.code="ABORTED",e.status=r.status,e.method=r.method,e.url=r.url,t(e)}})),n.end((function(r,n){r?t(r):e(n)}))}))}return this._fullfilledPromise.then(e,t)},v.prototype.catch=function(e){return this.then(void 0,e)},v.prototype.use=function(e){return e(this),this},v.prototype.ok=function(e){if("function"!=typeof e)throw new Error("Callback required");return this._okCallback=e,this},v.prototype._isResponseOK=function(e){return!!e&&(this._okCallback?this._okCallback(e):e.status>=200&&e.status<300)},v.prototype.get=function(e){return this._header[e.toLowerCase()]},v.prototype.getHeader=v.prototype.get,v.prototype.set=function(e,t){if(m(e)){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&this.set(r,e[r]);return this}return this._header[e.toLowerCase()]=t,this.header[e]=t,this},v.prototype.unset=function(e){return delete this._header[e.toLowerCase()],delete this.header[e],this},v.prototype.field=function(e,t){if(null==e)throw new Error(".field(name, val) name can not be empty");if(this._data)throw new Error(".field() can't be used if .send() is used. Please use only .send() or only .field() & .attach()");if(m(e)){for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&this.field(r,e[r]);return this}if(Array.isArray(t)){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&this.field(e,t[n]);return this}if(null==t)throw new Error(".field(name, val) val can not be empty");return"boolean"==typeof t&&(t=String(t)),this._getFormData().append(e,t),this},v.prototype.abort=function(){return this._aborted||(this._aborted=!0,this.xhr&&this.xhr.abort(),this.req&&this.req.abort(),this.clearTimeout(),this.emit("abort")),this},v.prototype._auth=function(e,t,r,n){switch(r.type){case"basic":this.set("Authorization","Basic ".concat(n("".concat(e,":").concat(t))));break;case"auto":this.username=e,this.password=t;break;case"bearer":this.set("Authorization","Bearer ".concat(e))}return this},v.prototype.withCredentials=function(e){return void 0===e&&(e=!0),this._withCredentials=e,this},v.prototype.redirects=function(e){return this._maxRedirects=e,this},v.prototype.maxResponseSize=function(e){if("number"!=typeof e)throw new TypeError("Invalid argument");return this._maxResponseSize=e,this},v.prototype.toJSON=function(){return{method:this.method,url:this.url,data:this._data,headers:this._header}},v.prototype.send=function(e){var t=m(e),r=this._header["content-type"];if(this._formData)throw new Error(".send() can't be used if .attach() or .field() is used. Please use only .send() or only .field() & .attach()");if(t&&!this._data)Array.isArray(e)?this._data=[]:this._isHost(e)||(this._data={});else if(e&&this._data&&this._isHost(this._data))throw new Error("Can't merge these send calls");if(t&&m(this._data))for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(this._data[n]=e[n]);else"string"==typeof e?(r||this.type("form"),r=this._header["content-type"],this._data="application/x-www-form-urlencoded"===r?this._data?"".concat(this._data,"&").concat(e):e:(this._data||"")+e):this._data=e;return!t||this._isHost(e)||r||this.type("json"),this},v.prototype.sortQuery=function(e){return this._sort=void 0===e||e,this},v.prototype._finalizeQueryString=function(){var e=this._query.join("&");if(e&&(this.url+=(this.url.includes("?")?"&":"?")+e),this._query.length=0,this._sort){var t=this.url.indexOf("?");if(t>=0){var r=this.url.slice(t+1).split("&");"function"==typeof this._sort?r.sort(this._sort):r.sort(),this.url=this.url.slice(0,t)+"?"+r.join("&")}}},v.prototype._appendQueryString=function(){console.warn("Unsupported")},v.prototype._timeoutError=function(e,t,r){if(!this._aborted){var n=new Error("".concat(e+t,"ms exceeded"));n.timeout=t,n.code="ECONNABORTED",n.errno=r,this.timedout=!0,this.timedoutError=n,this.abort(),this.callback(n)}},v.prototype._setTimeouts=function(){var e=this;this._timeout&&!this._timer&&(this._timer=setTimeout((function(){e._timeoutError("Timeout of ",e._timeout,"ETIME")}),this._timeout)),this._responseTimeout&&!this._responseTimeoutTimer&&(this._responseTimeoutTimer=setTimeout((function(){e._timeoutError("Response timeout of ",e._responseTimeout,"ETIMEDOUT")}),this._responseTimeout))};var w=function(e){return e.split(/ *; */).shift()},_=function(e){return e.split(/ *; */).reduce((function(e,t){var r=t.split(/ *= */),n=r.shift(),i=r.shift();return n&&i&&(e[n]=i),e}),{})},E=function(e){return e.split(/ *, */).reduce((function(e,t){var r=t.split(/ *; */),n=r[0].slice(1,-1);return e[r[1].split(/ *= */)[1].slice(1,-1)]=n,e}),{})},T=S;function S(e){if(e)return function(e){for(var t in S.prototype)Object.prototype.hasOwnProperty.call(S.prototype,t)&&(e[t]=S.prototype[t]);return e}(e)}function A(e){return function(e){if(Array.isArray(e)){for(var t=0,r=new Array(e.length);t<e.length;t++)r[t]=e[t];return r}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function I(){this._defaults=[]}S.prototype.get=function(e){return this.header[e.toLowerCase()]},S.prototype._setHeaderProperties=function(e){var t=e["content-type"]||"";this.type=w(t);var r=_(t);for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(this[n]=r[n]);this.links={};try{e.link&&(this.links=E(e.link))}catch(e){}},S.prototype._setStatusProperties=function(e){var t=e/100|0;this.statusCode=e,this.status=this.statusCode,this.statusType=t,this.info=1===t,this.ok=2===t,this.redirect=3===t,this.clientError=4===t,this.serverError=5===t,this.error=(4===t||5===t)&&this.toError(),this.created=201===e,this.accepted=202===e,this.noContent=204===e,this.badRequest=400===e,this.unauthorized=401===e,this.notAcceptable=406===e,this.forbidden=403===e,this.notFound=404===e,this.unprocessableEntity=422===e},["use","on","once","set","query","type","accept","auth","withCredentials","sortQuery","retry","ok","redirects","timeout","buffer","serialize","parse","ca","key","pfx","cert","disableTLSCerts"].forEach((function(e){I.prototype[e]=function(){for(var t=arguments.length,r=new Array(t),n=0;n<t;n++)r[n]=arguments[n];return this._defaults.push({fn:e,args:r}),this}})),I.prototype._setDefaults=function(e){this._defaults.forEach((function(t){e[t.fn].apply(e,A(t.args))}))};var C=I,O=i((function(e,t){function r(e){return(r="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)}var n;function i(){}"undefined"!=typeof window?n=window:"undefined"==typeof self?(console.warn("Using browser-only version of superagent in non-browser environment"),n=void 0):n=self,e.exports=function(e,r){return"function"==typeof r?new t.Request("GET",e).end(r):1===arguments.length?new t.Request("GET",e):new t.Request(e,r)};var s=t=e.exports;t.Request=p,s.getXHR=function(){if(n.XMLHttpRequest&&(!n.location||"file:"!==n.location.protocol||!n.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(e){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(e){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(e){}throw new Error("Browser-only version of superagent could not find XHR")};var u="".trim?function(e){return e.trim()}:function(e){return e.replace(/(^\s*|\s*$)/g,"")};function l(e){if(!m(e))return e;var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&c(t,r,e[r]);return t.join("&")}function c(e,t,r){if(void 0!==r)if(null!==r)if(Array.isArray(r))r.forEach((function(r){c(e,t,r)}));else if(m(r))for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&c(e,"".concat(t,"[").concat(n,"]"),r[n]);else e.push(encodeURI(t)+"="+encodeURIComponent(r));else e.push(encodeURI(t))}function h(e){for(var t,r,n={},i=e.split("&"),s=0,o=i.length;s<o;++s)-1===(r=(t=i[s]).indexOf("="))?n[decodeURIComponent(t)]="":n[decodeURIComponent(t.slice(0,r))]=decodeURIComponent(t.slice(r+1));return n}function f(e){return/[/+]json($|[^-\w])/.test(e)}function d(e){this.req=e,this.xhr=this.req.xhr,this.text="HEAD"!==this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||void 0===this.xhr.responseType?this.xhr.responseText:null,this.statusText=this.req.xhr.statusText;var t=this.xhr.status;1223===t&&(t=204),this._setStatusProperties(t),this.headers=function(e){for(var t,r,n,i,s=e.split(/\r?\n/),o={},a=0,l=s.length;a<l;++a)-1!==(t=(r=s[a]).indexOf(":"))&&(n=r.slice(0,t).toLowerCase(),i=u(r.slice(t+1)),o[n]=i);return o}(this.xhr.getAllResponseHeaders()),this.header=this.headers,this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this._setHeaderProperties(this.header),null===this.text&&e._responseType?this.body=this.xhr.response:this.body="HEAD"===this.req.method?null:this._parseBody(this.text?this.text:this.xhr.response)}function p(e,t){var r=this;this._query=this._query||[],this.method=e,this.url=t,this.header={},this._header={},this.on("end",(function(){var e,t=null,n=null;try{n=new d(r)}catch(e){return(t=new Error("Parser is unable to parse the response")).parse=!0,t.original=e,r.xhr?(t.rawResponse=void 0===r.xhr.responseType?r.xhr.responseText:r.xhr.response,t.status=r.xhr.status?r.xhr.status:null,t.statusCode=t.status):(t.rawResponse=null,t.status=null),r.callback(t)}r.emit("response",n);try{r._isResponseOK(n)||(e=new Error(n.statusText||n.text||"Unsuccessful HTTP response"))}catch(t){e=t}e?(e.original=t,e.response=n,e.status=n.status,r.callback(e,n)):r.callback(null,n)}))}function g(e,t,r){var n=s("DELETE",e);return"function"==typeof t&&(r=t,t=null),t&&n.send(t),r&&n.end(r),n}s.serializeObject=l,s.parseString=h,s.types={html:"text/html",json:"application/json",xml:"text/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},s.serialize={"application/x-www-form-urlencoded":l,"application/json":a},s.parse={"application/x-www-form-urlencoded":h,"application/json":JSON.parse},T(d.prototype),d.prototype._parseBody=function(e){var t=s.parse[this.type];return this.req._parser?this.req._parser(this,e):(!t&&f(this.type)&&(t=s.parse["application/json"]),t&&e&&(e.length>0||e instanceof Object)?t(e):null)},d.prototype.toError=function(){var e=this.req,t=e.method,r=e.url,n="cannot ".concat(t," ").concat(r," (").concat(this.status,")"),i=new Error(n);return i.status=this.status,i.method=t,i.url=r,i},s.Response=d,o(p.prototype),y(p.prototype),p.prototype.type=function(e){return this.set("Content-Type",s.types[e]||e),this},p.prototype.accept=function(e){return this.set("Accept",s.types[e]||e),this},p.prototype.auth=function(e,t,n){1===arguments.length&&(t=""),"object"===r(t)&&null!==t&&(n=t,t=""),n||(n={type:"function"==typeof btoa?"basic":"auto"});var i=function(e){if("function"==typeof btoa)return btoa(e);throw new Error("Cannot use basic auth, btoa is not a function")};return this._auth(e,t,n,i)},p.prototype.query=function(e){return"string"!=typeof e&&(e=l(e)),e&&this._query.push(e),this},p.prototype.attach=function(e,t,r){if(t){if(this._data)throw new Error("superagent can't mix .send() and .attach()");this._getFormData().append(e,t,r||t.name)}return this},p.prototype._getFormData=function(){return this._formData||(this._formData=new n.FormData),this._formData},p.prototype.callback=function(e,t){if(this._shouldRetry(e,t))return this._retry();var r=this._callback;this.clearTimeout(),e&&(this._maxRetries&&(e.retries=this._retries-1),this.emit("error",e)),r(e,t)},p.prototype.crossDomainError=function(){var e=new Error("Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.");e.crossDomain=!0,e.status=this.status,e.method=this.method,e.url=this.url,this.callback(e)},p.prototype.agent=function(){return console.warn("This is not supported in browser version of superagent"),this},p.prototype.ca=p.prototype.agent,p.prototype.buffer=p.prototype.ca,p.prototype.write=function(){throw new Error("Streaming is not supported in browser version of superagent")},p.prototype.pipe=p.prototype.write,p.prototype._isHost=function(e){return e&&"object"===r(e)&&!Array.isArray(e)&&"[object Object]"!==Object.prototype.toString.call(e)},p.prototype.end=function(e){this._endCalled&&console.warn("Warning: .end() was called twice. This is not supported in superagent"),this._endCalled=!0,this._callback=e||i,this._finalizeQueryString(),this._end()},p.prototype._setUploadTimeout=function(){var e=this;this._uploadTimeout&&!this._uploadTimeoutTimer&&(this._uploadTimeoutTimer=setTimeout((function(){e._timeoutError("Upload timeout of ",e._uploadTimeout,"ETIMEDOUT")}),this._uploadTimeout))},p.prototype._end=function(){if(this._aborted)return this.callback(new Error("The request has been aborted even before .end() was called"));var e=this;this.xhr=s.getXHR();var t=this.xhr,r=this._formData||this._data;this._setTimeouts(),t.onreadystatechange=function(){var r=t.readyState;if(r>=2&&e._responseTimeoutTimer&&clearTimeout(e._responseTimeoutTimer),4===r){var n;try{n=t.status}catch(e){n=0}if(!n){if(e.timedout||e._aborted)return;return e.crossDomainError()}e.emit("end")}};var n=function(t,r){r.total>0&&(r.percent=r.loaded/r.total*100,100===r.percent&&clearTimeout(e._uploadTimeoutTimer)),r.direction=t,e.emit("progress",r)};if(this.hasListeners("progress"))try{t.addEventListener("progress",n.bind(null,"download")),t.upload&&t.upload.addEventListener("progress",n.bind(null,"upload"))}catch(e){}t.upload&&this._setUploadTimeout();try{this.username&&this.password?t.open(this.method,this.url,!0,this.username,this.password):t.open(this.method,this.url,!0)}catch(e){return this.callback(e)}if(this._withCredentials&&(t.withCredentials=!0),!this._formData&&"GET"!==this.method&&"HEAD"!==this.method&&"string"!=typeof r&&!this._isHost(r)){var i=this._header["content-type"],o=this._serializer||s.serialize[i?i.split(";")[0]:""];!o&&f(i)&&(o=s.serialize["application/json"]),o&&(r=o(r))}for(var a in this.header)null!==this.header[a]&&Object.prototype.hasOwnProperty.call(this.header,a)&&t.setRequestHeader(a,this.header[a]);this._responseType&&(t.responseType=this._responseType),this.emit("request",this),t.send(void 0===r?null:r)},s.agent=function(){return new C},["GET","POST","OPTIONS","PATCH","PUT","DELETE"].forEach((function(e){C.prototype[e.toLowerCase()]=function(t,r){var n=new s.Request(e,t);return this._setDefaults(n),r&&n.end(r),n}})),C.prototype.del=C.prototype.delete,s.get=function(e,t,r){var n=s("GET",e);return"function"==typeof t&&(r=t,t=null),t&&n.query(t),r&&n.end(r),n},s.head=function(e,t,r){var n=s("HEAD",e);return"function"==typeof t&&(r=t,t=null),t&&n.query(t),r&&n.end(r),n},s.options=function(e,t,r){var n=s("OPTIONS",e);return"function"==typeof t&&(r=t,t=null),t&&n.send(t),r&&n.end(r),n},s.del=g,s.delete=g,s.patch=function(e,t,r){var n=s("PATCH",e);return"function"==typeof t&&(r=t,t=null),t&&n.send(t),r&&n.end(r),n},s.post=function(e,t,r){var n=s("POST",e);return"function"==typeof t&&(r=t,t=null),t&&n.send(t),r&&n.end(r),n},s.put=function(e,t,r){var n=s("PUT",e);return"function"==typeof t&&(r=t,t=null),t&&n.send(t),r&&n.end(r),n}})),M=(O.Request,i((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.request=function(e,t){void 0===t&&(t={});var r=t.method,n=void 0===r?"GET":r,i=t.data,s=t.headers,o=t.onprogress,a=O(n,e);return s&&a.set(s),o&&a.on("progress",o),a.send(i).catch((function(e){if(e.response)return e.response;throw e})).then((function(e){return{status:e.status,ok:e.ok,headers:e.header,data:e.body}}))},t.upload=function(e,t,r){void 0===r&&(r={});var n=r.data,i=r.headers,s=r.onprogress,o=O("POST",e).attach(t.field,t.data,t.name);return n&&o.field(n),i&&o.set(i),s&&o.on("progress",s),o.catch((function(e){if(e.response)return e.response;throw e})).then((function(e){return{status:e.status,ok:e.ok,headers:e.header,data:e.body}}))}})));n(M);M.request,M.upload;var R=i((function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.request=M.request,t.upload=M.upload,t.storage=window.localStorage,t.WebSocket=window.WebSocket,t.platformInfo={name:"Browser"}}));n(R);var P,N=R.request,L=(R.upload,R.storage,R.WebSocket),x=(R.platformInfo,i((function(e){
  2. /**
  3. * @license long.js (c) 2013 Daniel Wirtz <dcode@dcode.io>
  4. * Released under the Apache License, Version 2.0
  5. * see: https://github.com/dcodeIO/long.js for details
  6. */
  7. !function(t,r){e&&e.exports?e.exports=r():(t.dcodeIO=t.dcodeIO||{}).Long=r()}(r,(function(){function e(e,t,r){this.low=0|e,this.high=0|t,this.unsigned=!!r}function t(e){return!0===(e&&e.__isLong__)}e.prototype.__isLong__,Object.defineProperty(e.prototype,"__isLong__",{value:!0,enumerable:!1,configurable:!1}),e.isLong=t;var r={},n={};function i(e,t){var i,s,a;return t?(a=0<=(e>>>=0)&&e<256)&&(s=n[e])?s:(i=o(e,(0|e)<0?-1:0,!0),a&&(n[e]=i),i):(a=-128<=(e|=0)&&e<128)&&(s=r[e])?s:(i=o(e,e<0?-1:0,!1),a&&(r[e]=i),i)}function s(e,t){if(isNaN(e)||!isFinite(e))return t?m:p;if(t){if(e<0)return m;if(e>=h)return w}else{if(e<=-f)return _;if(e+1>=f)return b}return e<0?s(-e,t).neg():o(e%c|0,e/c|0,t)}function o(t,r,n){return new e(t,r,n)}e.fromInt=i,e.fromNumber=s,e.fromBits=o;var a=Math.pow;function u(e,t,r){if(0===e.length)throw Error("empty string");if("NaN"===e||"Infinity"===e||"+Infinity"===e||"-Infinity"===e)return p;if("number"==typeof t?(r=t,t=!1):t=!!t,(r=r||10)<2||36<r)throw RangeError("radix");var n;if((n=e.indexOf("-"))>0)throw Error("interior hyphen");if(0===n)return u(e.substring(1),t,r).neg();for(var i=s(a(r,8)),o=p,l=0;l<e.length;l+=8){var c=Math.min(8,e.length-l),h=parseInt(e.substring(l,l+c),r);if(c<8){var f=s(a(r,c));o=o.mul(f).add(s(h))}else o=(o=o.mul(i)).add(s(h))}return o.unsigned=t,o}function l(t){return t instanceof e?t:"number"==typeof t?s(t):"string"==typeof t?u(t):o(t.low,t.high,t.unsigned)}e.fromString=u,e.fromValue=l;var c=4294967296,h=c*c,f=h/2,d=i(1<<24),p=i(0);e.ZERO=p;var m=i(0,!0);e.UZERO=m;var g=i(1);e.ONE=g;var y=i(1,!0);e.UONE=y;var v=i(-1);e.NEG_ONE=v;var b=o(-1,2147483647,!1);e.MAX_VALUE=b;var w=o(-1,-1,!0);e.MAX_UNSIGNED_VALUE=w;var _=o(0,-2147483648,!1);e.MIN_VALUE=_;var E=e.prototype;return E.toInt=function(){return this.unsigned?this.low>>>0:this.low},E.toNumber=function(){return this.unsigned?(this.high>>>0)*c+(this.low>>>0):this.high*c+(this.low>>>0)},E.toString=function(e){if((e=e||10)<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(_)){var t=s(e),r=this.div(t),n=r.mul(t).sub(this);return r.toString(e)+n.toInt().toString(e)}return"-"+this.neg().toString(e)}for(var i=s(a(e,6),this.unsigned),o=this,u="";;){var l=o.div(i),c=(o.sub(l.mul(i)).toInt()>>>0).toString(e);if((o=l).isZero())return c+u;for(;c.length<6;)c="0"+c;u=""+c+u}},E.getHighBits=function(){return this.high},E.getHighBitsUnsigned=function(){return this.high>>>0},E.getLowBits=function(){return this.low},E.getLowBitsUnsigned=function(){return this.low>>>0},E.getNumBitsAbs=function(){if(this.isNegative())return this.eq(_)?64:this.neg().getNumBitsAbs();for(var e=0!=this.high?this.high:this.low,t=31;t>0&&0==(e&1<<t);t--);return 0!=this.high?t+33:t+1},E.isZero=function(){return 0===this.high&&0===this.low},E.isNegative=function(){return!this.unsigned&&this.high<0},E.isPositive=function(){return this.unsigned||this.high>=0},E.isOdd=function(){return 1==(1&this.low)},E.isEven=function(){return 0==(1&this.low)},E.equals=function(e){return t(e)||(e=l(e)),(this.unsigned===e.unsigned||this.high>>>31!=1||e.high>>>31!=1)&&(this.high===e.high&&this.low===e.low)},E.eq=E.equals,E.notEquals=function(e){return!this.eq(e)},E.neq=E.notEquals,E.lessThan=function(e){return this.comp(e)<0},E.lt=E.lessThan,E.lessThanOrEqual=function(e){return this.comp(e)<=0},E.lte=E.lessThanOrEqual,E.greaterThan=function(e){return this.comp(e)>0},E.gt=E.greaterThan,E.greaterThanOrEqual=function(e){return this.comp(e)>=0},E.gte=E.greaterThanOrEqual,E.compare=function(e){if(t(e)||(e=l(e)),this.eq(e))return 0;var r=this.isNegative(),n=e.isNegative();return r&&!n?-1:!r&&n?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1},E.comp=E.compare,E.negate=function(){return!this.unsigned&&this.eq(_)?_:this.not().add(g)},E.neg=E.negate,E.add=function(e){t(e)||(e=l(e));var r=this.high>>>16,n=65535&this.high,i=this.low>>>16,s=65535&this.low,a=e.high>>>16,u=65535&e.high,c=e.low>>>16,h=0,f=0,d=0,p=0;return d+=(p+=s+(65535&e.low))>>>16,f+=(d+=i+c)>>>16,h+=(f+=n+u)>>>16,h+=r+a,o((d&=65535)<<16|(p&=65535),(h&=65535)<<16|(f&=65535),this.unsigned)},E.subtract=function(e){return t(e)||(e=l(e)),this.add(e.neg())},E.sub=E.subtract,E.multiply=function(e){if(this.isZero())return p;if(t(e)||(e=l(e)),e.isZero())return p;if(this.eq(_))return e.isOdd()?_:p;if(e.eq(_))return this.isOdd()?_:p;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(d)&&e.lt(d))return s(this.toNumber()*e.toNumber(),this.unsigned);var r=this.high>>>16,n=65535&this.high,i=this.low>>>16,a=65535&this.low,u=e.high>>>16,c=65535&e.high,h=e.low>>>16,f=65535&e.low,m=0,g=0,y=0,v=0;return y+=(v+=a*f)>>>16,g+=(y+=i*f)>>>16,y&=65535,g+=(y+=a*h)>>>16,m+=(g+=n*f)>>>16,g&=65535,m+=(g+=i*h)>>>16,g&=65535,m+=(g+=a*c)>>>16,m+=r*f+n*h+i*c+a*u,o((y&=65535)<<16|(v&=65535),(m&=65535)<<16|(g&=65535),this.unsigned)},E.mul=E.multiply,E.divide=function(e){if(t(e)||(e=l(e)),e.isZero())throw Error("division by zero");if(this.isZero())return this.unsigned?m:p;var r,n,i;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return m;if(e.gt(this.shru(1)))return y;i=m}else{if(this.eq(_))return e.eq(g)||e.eq(v)?_:e.eq(_)?g:(r=this.shr(1).div(e).shl(1)).eq(p)?e.isNegative()?g:v:(n=this.sub(e.mul(r)),i=r.add(n.div(e)));if(e.eq(_))return this.unsigned?m:p;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();i=p}for(n=this;n.gte(e);){r=Math.max(1,Math.floor(n.toNumber()/e.toNumber()));for(var o=Math.ceil(Math.log(r)/Math.LN2),u=o<=48?1:a(2,o-48),c=s(r),h=c.mul(e);h.isNegative()||h.gt(n);)h=(c=s(r-=u,this.unsigned)).mul(e);c.isZero()&&(c=g),i=i.add(c),n=n.sub(h)}return i},E.div=E.divide,E.modulo=function(e){return t(e)||(e=l(e)),this.sub(this.div(e).mul(e))},E.mod=E.modulo,E.not=function(){return o(~this.low,~this.high,this.unsigned)},E.and=function(e){return t(e)||(e=l(e)),o(this.low&e.low,this.high&e.high,this.unsigned)},E.or=function(e){return t(e)||(e=l(e)),o(this.low|e.low,this.high|e.high,this.unsigned)},E.xor=function(e){return t(e)||(e=l(e)),o(this.low^e.low,this.high^e.high,this.unsigned)},E.shiftLeft=function(e){return t(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?o(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):o(0,this.low<<e-32,this.unsigned)},E.shl=E.shiftLeft,E.shiftRight=function(e){return t(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?o(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):o(this.high>>e-32,this.high>=0?0:-1,this.unsigned)},E.shr=E.shiftRight,E.shiftRightUnsigned=function(e){if(t(e)&&(e=e.toInt()),0===(e&=63))return this;var r=this.high;return e<32?o(this.low>>>e|r<<32-e,r>>>e,this.unsigned):o(32===e?r:r>>>e-32,0,this.unsigned)},E.shru=E.shiftRightUnsigned,E.toSigned=function(){return this.unsigned?o(this.low,this.high,!1):this},E.toUnsigned=function(){return this.unsigned?this:o(this.low,this.high,!0)},E.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()},E.toBytesLE=function(){var e=this.high,t=this.low;return[255&t,t>>>8&255,t>>>16&255,t>>>24&255,255&e,e>>>8&255,e>>>16&255,e>>>24&255]},E.toBytesBE=function(){var e=this.high,t=this.low;return[e>>>24&255,e>>>16&255,e>>>8&255,255&e,t>>>24&255,t>>>16&255,t>>>8&255,255&t]},e}))}))),k=i((function(e){
  8. /**
  9. * @license bytebuffer.js (c) 2015 Daniel Wirtz <dcode@dcode.io>
  10. * Backing buffer: ArrayBuffer, Accessor: Uint8Array
  11. * Released under the Apache License, Version 2.0
  12. * see: https://github.com/dcodeIO/bytebuffer.js for details
  13. */
  14. !function(t,r){e&&e.exports?e.exports=function(){var e;try{e=x}catch(e){}return r(e)}():(t.dcodeIO=t.dcodeIO||{}).ByteBuffer=r(t.dcodeIO.Long)}(r,(function(e){var t=function(e,r,i){if(void 0===e&&(e=t.DEFAULT_CAPACITY),void 0===r&&(r=t.DEFAULT_ENDIAN),void 0===i&&(i=t.DEFAULT_NOASSERT),!i){if((e|=0)<0)throw RangeError("Illegal capacity");r=!!r,i=!!i}this.buffer=0===e?n:new ArrayBuffer(e),this.view=0===e?null:new Uint8Array(this.buffer),this.offset=0,this.markedOffset=-1,this.limit=e,this.littleEndian=r,this.noAssert=i};t.VERSION="5.0.1",t.LITTLE_ENDIAN=!0,t.BIG_ENDIAN=!1,t.DEFAULT_CAPACITY=16,t.DEFAULT_ENDIAN=t.BIG_ENDIAN,t.DEFAULT_NOASSERT=!1,t.Long=e||null;var r=t.prototype;r.__isByteBuffer__,Object.defineProperty(r,"__isByteBuffer__",{value:!0,enumerable:!1,configurable:!1});var n=new ArrayBuffer(0),i=String.fromCharCode;function s(e){var t=0;return function(){return t<e.length?e.charCodeAt(t++):null}}function o(){var e=[],t=[];return function(){if(0===arguments.length)return t.join("")+i.apply(String,e);e.length+arguments.length>1024&&(t.push(i.apply(String,e)),e.length=0),Array.prototype.push.apply(e,arguments)}}function a(e,t,r,n,i){var s,o,a=8*i-n-1,u=(1<<a)-1,l=u>>1,c=-7,h=r?i-1:0,f=r?-1:1,d=e[t+h];for(h+=f,s=d&(1<<-c)-1,d>>=-c,c+=a;c>0;s=256*s+e[t+h],h+=f,c-=8);for(o=s&(1<<-c)-1,s>>=-c,c+=n;c>0;o=256*o+e[t+h],h+=f,c-=8);if(0===s)s=1-l;else{if(s===u)return o?NaN:1/0*(d?-1:1);o+=Math.pow(2,n),s-=l}return(d?-1:1)*o*Math.pow(2,s-n)}function u(e,t,r,n,i,s){var o,a,u,l=8*s-i-1,c=(1<<l)-1,h=c>>1,f=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,d=n?0:s-1,p=n?1:-1,m=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,o=c):(o=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-o))<1&&(o--,u*=2),(t+=o+h>=1?f/u:f*Math.pow(2,1-h))*u>=2&&(o++,u/=2),o+h>=c?(a=0,o=c):o+h>=1?(a=(t*u-1)*Math.pow(2,i),o+=h):(a=t*Math.pow(2,h-1)*Math.pow(2,i),o=0));i>=8;e[r+d]=255&a,d+=p,a/=256,i-=8);for(o=o<<i|a,l+=i;l>0;e[r+d]=255&o,d+=p,o/=256,l-=8);e[r+d-p]|=128*m}t.accessor=function(){return Uint8Array},t.allocate=function(e,r,n){return new t(e,r,n)},t.concat=function(e,r,n,i){"boolean"!=typeof r&&"string"==typeof r||(i=n,n=r,r=void 0);for(var s,o=0,a=0,u=e.length;a<u;++a)t.isByteBuffer(e[a])||(e[a]=t.wrap(e[a],r)),(s=e[a].limit-e[a].offset)>0&&(o+=s);if(0===o)return new t(0,n,i);var l,c=new t(o,n,i);for(a=0;a<u;)(s=(l=e[a++]).limit-l.offset)<=0||(c.view.set(l.view.subarray(l.offset,l.limit),c.offset),c.offset+=s);return c.limit=c.offset,c.offset=0,c},t.isByteBuffer=function(e){return!0===(e&&e.__isByteBuffer__)},t.type=function(){return ArrayBuffer},t.wrap=function(e,n,i,s){if("string"!=typeof n&&(s=i,i=n,n=void 0),"string"==typeof e)switch(void 0===n&&(n="utf8"),n){case"base64":return t.fromBase64(e,i);case"hex":return t.fromHex(e,i);case"binary":return t.fromBinary(e,i);case"utf8":return t.fromUTF8(e,i);case"debug":return t.fromDebug(e,i);default:throw Error("Unsupported encoding: "+n)}if(null===e||"object"!=typeof e)throw TypeError("Illegal buffer");var o;if(t.isByteBuffer(e))return(o=r.clone.call(e)).markedOffset=-1,o;if(e instanceof Uint8Array)o=new t(0,i,s),e.length>0&&(o.buffer=e.buffer,o.offset=e.byteOffset,o.limit=e.byteOffset+e.byteLength,o.view=new Uint8Array(e.buffer));else if(e instanceof ArrayBuffer)o=new t(0,i,s),e.byteLength>0&&(o.buffer=e,o.offset=0,o.limit=e.byteLength,o.view=e.byteLength>0?new Uint8Array(e):null);else{if("[object Array]"!==Object.prototype.toString.call(e))throw TypeError("Illegal buffer");(o=new t(e.length,i,s)).limit=e.length;for(var a=0;a<e.length;++a)o.view[a]=e[a]}return o},r.writeBitSet=function(e,t){var r=void 0===t;if(r&&(t=this.offset),!this.noAssert){if(!(e instanceof Array))throw TypeError("Illegal BitSet: Not an array");if("number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}var n,i=t,s=e.length,o=s>>3,a=0;for(t+=this.writeVarint32(s,t);o--;)n=1&!!e[a++]|(1&!!e[a++])<<1|(1&!!e[a++])<<2|(1&!!e[a++])<<3|(1&!!e[a++])<<4|(1&!!e[a++])<<5|(1&!!e[a++])<<6|(1&!!e[a++])<<7,this.writeByte(n,t++);if(a<s){var u=0;for(n=0;a<s;)n|=(1&!!e[a++])<<u++;this.writeByte(n,t++)}return r?(this.offset=t,this):t-i},r.readBitSet=function(e){var t=void 0===e;t&&(e=this.offset);var r,n=this.readVarint32(e),i=n.value,s=i>>3,o=0,a=[];for(e+=n.length;s--;)r=this.readByte(e++),a[o++]=!!(1&r),a[o++]=!!(2&r),a[o++]=!!(4&r),a[o++]=!!(8&r),a[o++]=!!(16&r),a[o++]=!!(32&r),a[o++]=!!(64&r),a[o++]=!!(128&r);if(o<i){var u=0;for(r=this.readByte(e++);o<i;)a[o++]=!!(r>>u++&1)}return t&&(this.offset=e),a},r.readBytes=function(e,t){var r=void 0===t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+e>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+"+e+") <= "+this.buffer.byteLength)}var n=this.slice(t,t+e);return r&&(this.offset+=e),n},r.writeBytes=r.append,r.writeInt8=function(e,t){var r=void 0===t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e|=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=1;var n=this.buffer.byteLength;return t>n&&this.resize((n*=2)>t?n:t),t-=1,this.view[t]=e,r&&(this.offset+=1),this},r.writeByte=r.writeInt8,r.readInt8=function(e){var t=void 0===e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+1) <= "+this.buffer.byteLength)}var r=this.view[e];return 128==(128&r)&&(r=-(255-r+1)),t&&(this.offset+=1),r},r.readByte=r.readInt8,r.writeUint8=function(e,t){var r=void 0===t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e>>>=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=1;var n=this.buffer.byteLength;return t>n&&this.resize((n*=2)>t?n:t),t-=1,this.view[t]=e,r&&(this.offset+=1),this},r.writeUInt8=r.writeUint8,r.readUint8=function(e){var t=void 0===e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+1) <= "+this.buffer.byteLength)}var r=this.view[e];return t&&(this.offset+=1),r},r.readUInt8=r.readUint8,r.writeInt16=function(e,t){var r=void 0===t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e|=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=2;var n=this.buffer.byteLength;return t>n&&this.resize((n*=2)>t?n:t),t-=2,this.littleEndian?(this.view[t+1]=(65280&e)>>>8,this.view[t]=255&e):(this.view[t]=(65280&e)>>>8,this.view[t+1]=255&e),r&&(this.offset+=2),this},r.writeShort=r.writeInt16,r.readInt16=function(e){var t=void 0===e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+2>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+2) <= "+this.buffer.byteLength)}var r=0;return this.littleEndian?(r=this.view[e],r|=this.view[e+1]<<8):(r=this.view[e]<<8,r|=this.view[e+1]),32768==(32768&r)&&(r=-(65535-r+1)),t&&(this.offset+=2),r},r.readShort=r.readInt16,r.writeUint16=function(e,t){var r=void 0===t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e>>>=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=2;var n=this.buffer.byteLength;return t>n&&this.resize((n*=2)>t?n:t),t-=2,this.littleEndian?(this.view[t+1]=(65280&e)>>>8,this.view[t]=255&e):(this.view[t]=(65280&e)>>>8,this.view[t+1]=255&e),r&&(this.offset+=2),this},r.writeUInt16=r.writeUint16,r.readUint16=function(e){var t=void 0===e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+2>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+2) <= "+this.buffer.byteLength)}var r=0;return this.littleEndian?(r=this.view[e],r|=this.view[e+1]<<8):(r=this.view[e]<<8,r|=this.view[e+1]),t&&(this.offset+=2),r},r.readUInt16=r.readUint16,r.writeInt32=function(e,t){var r=void 0===t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e|=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=4;var n=this.buffer.byteLength;return t>n&&this.resize((n*=2)>t?n:t),t-=4,this.littleEndian?(this.view[t+3]=e>>>24&255,this.view[t+2]=e>>>16&255,this.view[t+1]=e>>>8&255,this.view[t]=255&e):(this.view[t]=e>>>24&255,this.view[t+1]=e>>>16&255,this.view[t+2]=e>>>8&255,this.view[t+3]=255&e),r&&(this.offset+=4),this},r.writeInt=r.writeInt32,r.readInt32=function(e){var t=void 0===e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+4) <= "+this.buffer.byteLength)}var r=0;return this.littleEndian?(r=this.view[e+2]<<16,r|=this.view[e+1]<<8,r|=this.view[e],r+=this.view[e+3]<<24>>>0):(r=this.view[e+1]<<16,r|=this.view[e+2]<<8,r|=this.view[e+3],r+=this.view[e]<<24>>>0),r|=0,t&&(this.offset+=4),r},r.readInt=r.readInt32,r.writeUint32=function(e,t){var r=void 0===t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e>>>=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=4;var n=this.buffer.byteLength;return t>n&&this.resize((n*=2)>t?n:t),t-=4,this.littleEndian?(this.view[t+3]=e>>>24&255,this.view[t+2]=e>>>16&255,this.view[t+1]=e>>>8&255,this.view[t]=255&e):(this.view[t]=e>>>24&255,this.view[t+1]=e>>>16&255,this.view[t+2]=e>>>8&255,this.view[t+3]=255&e),r&&(this.offset+=4),this},r.writeUInt32=r.writeUint32,r.readUint32=function(e){var t=void 0===e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+4) <= "+this.buffer.byteLength)}var r=0;return this.littleEndian?(r=this.view[e+2]<<16,r|=this.view[e+1]<<8,r|=this.view[e],r+=this.view[e+3]<<24>>>0):(r=this.view[e+1]<<16,r|=this.view[e+2]<<8,r|=this.view[e+3],r+=this.view[e]<<24>>>0),t&&(this.offset+=4),r},r.readUInt32=r.readUint32,e&&(r.writeInt64=function(t,r){var n=void 0===r;if(n&&(r=this.offset),!this.noAssert){if("number"==typeof t)t=e.fromNumber(t);else if("string"==typeof t)t=e.fromString(t);else if(!(t&&t instanceof e))throw TypeError("Illegal value: "+t+" (not an integer or Long)");if("number"!=typeof r||r%1!=0)throw TypeError("Illegal offset: "+r+" (not an integer)");if((r>>>=0)<0||r+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+r+" (+0) <= "+this.buffer.byteLength)}"number"==typeof t?t=e.fromNumber(t):"string"==typeof t&&(t=e.fromString(t)),r+=8;var i=this.buffer.byteLength;r>i&&this.resize((i*=2)>r?i:r),r-=8;var s=t.low,o=t.high;return this.littleEndian?(this.view[r+3]=s>>>24&255,this.view[r+2]=s>>>16&255,this.view[r+1]=s>>>8&255,this.view[r]=255&s,r+=4,this.view[r+3]=o>>>24&255,this.view[r+2]=o>>>16&255,this.view[r+1]=o>>>8&255,this.view[r]=255&o):(this.view[r]=o>>>24&255,this.view[r+1]=o>>>16&255,this.view[r+2]=o>>>8&255,this.view[r+3]=255&o,r+=4,this.view[r]=s>>>24&255,this.view[r+1]=s>>>16&255,this.view[r+2]=s>>>8&255,this.view[r+3]=255&s),n&&(this.offset+=8),this},r.writeLong=r.writeInt64,r.readInt64=function(t){var r=void 0===t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+8>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+8) <= "+this.buffer.byteLength)}var n=0,i=0;this.littleEndian?(n=this.view[t+2]<<16,n|=this.view[t+1]<<8,n|=this.view[t],n+=this.view[t+3]<<24>>>0,t+=4,i=this.view[t+2]<<16,i|=this.view[t+1]<<8,i|=this.view[t],i+=this.view[t+3]<<24>>>0):(i=this.view[t+1]<<16,i|=this.view[t+2]<<8,i|=this.view[t+3],i+=this.view[t]<<24>>>0,t+=4,n=this.view[t+1]<<16,n|=this.view[t+2]<<8,n|=this.view[t+3],n+=this.view[t]<<24>>>0);var s=new e(n,i,!1);return r&&(this.offset+=8),s},r.readLong=r.readInt64,r.writeUint64=function(t,r){var n=void 0===r;if(n&&(r=this.offset),!this.noAssert){if("number"==typeof t)t=e.fromNumber(t);else if("string"==typeof t)t=e.fromString(t);else if(!(t&&t instanceof e))throw TypeError("Illegal value: "+t+" (not an integer or Long)");if("number"!=typeof r||r%1!=0)throw TypeError("Illegal offset: "+r+" (not an integer)");if((r>>>=0)<0||r+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+r+" (+0) <= "+this.buffer.byteLength)}"number"==typeof t?t=e.fromNumber(t):"string"==typeof t&&(t=e.fromString(t)),r+=8;var i=this.buffer.byteLength;r>i&&this.resize((i*=2)>r?i:r),r-=8;var s=t.low,o=t.high;return this.littleEndian?(this.view[r+3]=s>>>24&255,this.view[r+2]=s>>>16&255,this.view[r+1]=s>>>8&255,this.view[r]=255&s,r+=4,this.view[r+3]=o>>>24&255,this.view[r+2]=o>>>16&255,this.view[r+1]=o>>>8&255,this.view[r]=255&o):(this.view[r]=o>>>24&255,this.view[r+1]=o>>>16&255,this.view[r+2]=o>>>8&255,this.view[r+3]=255&o,r+=4,this.view[r]=s>>>24&255,this.view[r+1]=s>>>16&255,this.view[r+2]=s>>>8&255,this.view[r+3]=255&s),n&&(this.offset+=8),this},r.writeUInt64=r.writeUint64,r.readUint64=function(t){var r=void 0===t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+8>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+8) <= "+this.buffer.byteLength)}var n=0,i=0;this.littleEndian?(n=this.view[t+2]<<16,n|=this.view[t+1]<<8,n|=this.view[t],n+=this.view[t+3]<<24>>>0,t+=4,i=this.view[t+2]<<16,i|=this.view[t+1]<<8,i|=this.view[t],i+=this.view[t+3]<<24>>>0):(i=this.view[t+1]<<16,i|=this.view[t+2]<<8,i|=this.view[t+3],i+=this.view[t]<<24>>>0,t+=4,n=this.view[t+1]<<16,n|=this.view[t+2]<<8,n|=this.view[t+3],n+=this.view[t]<<24>>>0);var s=new e(n,i,!0);return r&&(this.offset+=8),s},r.readUInt64=r.readUint64),r.writeFloat32=function(e,t){var r=void 0===t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof e)throw TypeError("Illegal value: "+e+" (not a number)");if("number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=4;var n=this.buffer.byteLength;return t>n&&this.resize((n*=2)>t?n:t),t-=4,u(this.view,e,t,this.littleEndian,23,4),r&&(this.offset+=4),this},r.writeFloat=r.writeFloat32,r.readFloat32=function(e){var t=void 0===e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+4) <= "+this.buffer.byteLength)}var r=a(this.view,e,this.littleEndian,23,4);return t&&(this.offset+=4),r},r.readFloat=r.readFloat32,r.writeFloat64=function(e,t){var r=void 0===t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof e)throw TypeError("Illegal value: "+e+" (not a number)");if("number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}t+=8;var n=this.buffer.byteLength;return t>n&&this.resize((n*=2)>t?n:t),t-=8,u(this.view,e,t,this.littleEndian,52,8),r&&(this.offset+=8),this},r.writeDouble=r.writeFloat64,r.readFloat64=function(e){var t=void 0===e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+8>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+8) <= "+this.buffer.byteLength)}var r=a(this.view,e,this.littleEndian,52,8);return t&&(this.offset+=8),r},r.readDouble=r.readFloat64,t.MAX_VARINT32_BYTES=5,t.calculateVarint32=function(e){return(e>>>=0)<128?1:e<16384?2:e<1<<21?3:e<1<<28?4:5},t.zigZagEncode32=function(e){return((e|=0)<<1^e>>31)>>>0},t.zigZagDecode32=function(e){return e>>>1^-(1&e)|0},r.writeVarint32=function(e,r){var n=void 0===r;if(n&&(r=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e|=0,"number"!=typeof r||r%1!=0)throw TypeError("Illegal offset: "+r+" (not an integer)");if((r>>>=0)<0||r+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+r+" (+0) <= "+this.buffer.byteLength)}var i,s=t.calculateVarint32(e);r+=s;var o=this.buffer.byteLength;for(r>o&&this.resize((o*=2)>r?o:r),r-=s,e>>>=0;e>=128;)i=127&e|128,this.view[r++]=i,e>>>=7;return this.view[r++]=e,n?(this.offset=r,this):s},r.writeVarint32ZigZag=function(e,r){return this.writeVarint32(t.zigZagEncode32(e),r)},r.readVarint32=function(e){var t=void 0===e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+1) <= "+this.buffer.byteLength)}var r,n=0,i=0;do{if(!this.noAssert&&e>this.limit){var s=Error("Truncated");throw s.truncated=!0,s}r=this.view[e++],n<5&&(i|=(127&r)<<7*n),++n}while(0!=(128&r));return i|=0,t?(this.offset=e,i):{value:i,length:n}},r.readVarint32ZigZag=function(e){var r=this.readVarint32(e);return"object"==typeof r?r.value=t.zigZagDecode32(r.value):r=t.zigZagDecode32(r),r},e&&(t.MAX_VARINT64_BYTES=10,t.calculateVarint64=function(t){"number"==typeof t?t=e.fromNumber(t):"string"==typeof t&&(t=e.fromString(t));var r=t.toInt()>>>0,n=t.shiftRightUnsigned(28).toInt()>>>0,i=t.shiftRightUnsigned(56).toInt()>>>0;return 0==i?0==n?r<16384?r<128?1:2:r<1<<21?3:4:n<16384?n<128?5:6:n<1<<21?7:8:i<128?9:10},t.zigZagEncode64=function(t){return"number"==typeof t?t=e.fromNumber(t,!1):"string"==typeof t?t=e.fromString(t,!1):!1!==t.unsigned&&(t=t.toSigned()),t.shiftLeft(1).xor(t.shiftRight(63)).toUnsigned()},t.zigZagDecode64=function(t){return"number"==typeof t?t=e.fromNumber(t,!1):"string"==typeof t?t=e.fromString(t,!1):!1!==t.unsigned&&(t=t.toSigned()),t.shiftRightUnsigned(1).xor(t.and(e.ONE).toSigned().negate()).toSigned()},r.writeVarint64=function(r,n){var i=void 0===n;if(i&&(n=this.offset),!this.noAssert){if("number"==typeof r)r=e.fromNumber(r);else if("string"==typeof r)r=e.fromString(r);else if(!(r&&r instanceof e))throw TypeError("Illegal value: "+r+" (not an integer or Long)");if("number"!=typeof n||n%1!=0)throw TypeError("Illegal offset: "+n+" (not an integer)");if((n>>>=0)<0||n+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+n+" (+0) <= "+this.buffer.byteLength)}"number"==typeof r?r=e.fromNumber(r,!1):"string"==typeof r?r=e.fromString(r,!1):!1!==r.unsigned&&(r=r.toSigned());var s=t.calculateVarint64(r),o=r.toInt()>>>0,a=r.shiftRightUnsigned(28).toInt()>>>0,u=r.shiftRightUnsigned(56).toInt()>>>0;n+=s;var l=this.buffer.byteLength;switch(n>l&&this.resize((l*=2)>n?l:n),n-=s,s){case 10:this.view[n+9]=u>>>7&1;case 9:this.view[n+8]=9!==s?128|u:127&u;case 8:this.view[n+7]=8!==s?a>>>21|128:a>>>21&127;case 7:this.view[n+6]=7!==s?a>>>14|128:a>>>14&127;case 6:this.view[n+5]=6!==s?a>>>7|128:a>>>7&127;case 5:this.view[n+4]=5!==s?128|a:127&a;case 4:this.view[n+3]=4!==s?o>>>21|128:o>>>21&127;case 3:this.view[n+2]=3!==s?o>>>14|128:o>>>14&127;case 2:this.view[n+1]=2!==s?o>>>7|128:o>>>7&127;case 1:this.view[n]=1!==s?128|o:127&o}return i?(this.offset+=s,this):s},r.writeVarint64ZigZag=function(e,r){return this.writeVarint64(t.zigZagEncode64(e),r)},r.readVarint64=function(t){var r=void 0===t;if(r&&(t=this.offset),!this.noAssert){if("number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+1) <= "+this.buffer.byteLength)}var n=t,i=0,s=0,o=0,a=0;if(i=127&(a=this.view[t++]),128&a&&(i|=(127&(a=this.view[t++]))<<7,(128&a||this.noAssert&&void 0===a)&&(i|=(127&(a=this.view[t++]))<<14,(128&a||this.noAssert&&void 0===a)&&(i|=(127&(a=this.view[t++]))<<21,(128&a||this.noAssert&&void 0===a)&&(s=127&(a=this.view[t++]),(128&a||this.noAssert&&void 0===a)&&(s|=(127&(a=this.view[t++]))<<7,(128&a||this.noAssert&&void 0===a)&&(s|=(127&(a=this.view[t++]))<<14,(128&a||this.noAssert&&void 0===a)&&(s|=(127&(a=this.view[t++]))<<21,(128&a||this.noAssert&&void 0===a)&&(o=127&(a=this.view[t++]),(128&a||this.noAssert&&void 0===a)&&(o|=(127&(a=this.view[t++]))<<7,128&a||this.noAssert&&void 0===a))))))))))throw Error("Buffer overrun");var u=e.fromBits(i|s<<28,s>>>4|o<<24,!1);return r?(this.offset=t,u):{value:u,length:t-n}},r.readVarint64ZigZag=function(r){var n=this.readVarint64(r);return n&&n.value instanceof e?n.value=t.zigZagDecode64(n.value):n=t.zigZagDecode64(n),n}),r.writeCString=function(e,t){var r=void 0===t;r&&(t=this.offset);var n,i=e.length;if(!this.noAssert){if("string"!=typeof e)throw TypeError("Illegal str: Not a string");for(n=0;n<i;++n)if(0===e.charCodeAt(n))throw RangeError("Illegal str: Contains NULL-characters");if("number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}i=c.calculateUTF16asUTF8(s(e))[1],t+=i+1;var o=this.buffer.byteLength;return t>o&&this.resize((o*=2)>t?o:t),t-=i+1,c.encodeUTF16toUTF8(s(e),function(e){this.view[t++]=e}.bind(this)),this.view[t++]=0,r?(this.offset=t,this):i},r.readCString=function(e){var t=void 0===e;if(t&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+1) <= "+this.buffer.byteLength)}var r,n=e,i=-1;return c.decodeUTF8toUTF16(function(){if(0===i)return null;if(e>=this.limit)throw RangeError("Illegal range: Truncated data, "+e+" < "+this.limit);return 0===(i=this.view[e++])?null:i}.bind(this),r=o(),!0),t?(this.offset=e,r()):{string:r(),length:e-n}},r.writeIString=function(e,t){var r=void 0===t;if(r&&(t=this.offset),!this.noAssert){if("string"!=typeof e)throw TypeError("Illegal str: Not a string");if("number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}var n,i=t;n=c.calculateUTF16asUTF8(s(e),this.noAssert)[1],t+=4+n;var o=this.buffer.byteLength;if(t>o&&this.resize((o*=2)>t?o:t),t-=4+n,this.littleEndian?(this.view[t+3]=n>>>24&255,this.view[t+2]=n>>>16&255,this.view[t+1]=n>>>8&255,this.view[t]=255&n):(this.view[t]=n>>>24&255,this.view[t+1]=n>>>16&255,this.view[t+2]=n>>>8&255,this.view[t+3]=255&n),t+=4,c.encodeUTF16toUTF8(s(e),function(e){this.view[t++]=e}.bind(this)),t!==i+4+n)throw RangeError("Illegal range: Truncated data, "+t+" == "+(t+4+n));return r?(this.offset=t,this):t-i},r.readIString=function(e){var r=void 0===e;if(r&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+4>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+4) <= "+this.buffer.byteLength)}var n=e,i=this.readUint32(e),s=this.readUTF8String(i,t.METRICS_BYTES,e+=4);return e+=s.length,r?(this.offset=e,s.string):{string:s.string,length:e-n}},t.METRICS_CHARS="c",t.METRICS_BYTES="b",r.writeUTF8String=function(e,t){var r,n=void 0===t;if(n&&(t=this.offset),!this.noAssert){if("number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: "+t+" (not an integer)");if((t>>>=0)<0||t+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+t+" (+0) <= "+this.buffer.byteLength)}var i=t;r=c.calculateUTF16asUTF8(s(e))[1],t+=r;var o=this.buffer.byteLength;return t>o&&this.resize((o*=2)>t?o:t),t-=r,c.encodeUTF16toUTF8(s(e),function(e){this.view[t++]=e}.bind(this)),n?(this.offset=t,this):t-i},r.writeString=r.writeUTF8String,t.calculateUTF8Chars=function(e){return c.calculateUTF16asUTF8(s(e))[0]},t.calculateUTF8Bytes=function(e){return c.calculateUTF16asUTF8(s(e))[1]},t.calculateString=t.calculateUTF8Bytes,r.readUTF8String=function(e,r,n){"number"==typeof r&&(n=r,r=void 0);var i=void 0===n;if(i&&(n=this.offset),void 0===r&&(r=t.METRICS_CHARS),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal length: "+e+" (not an integer)");if(e|=0,"number"!=typeof n||n%1!=0)throw TypeError("Illegal offset: "+n+" (not an integer)");if((n>>>=0)<0||n+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+n+" (+0) <= "+this.buffer.byteLength)}var s,a=0,u=n;if(r===t.METRICS_CHARS){if(s=o(),c.decodeUTF8(function(){return a<e&&n<this.limit?this.view[n++]:null}.bind(this),(function(e){++a,c.UTF8toUTF16(e,s)})),a!==e)throw RangeError("Illegal range: Truncated data, "+a+" == "+e);return i?(this.offset=n,s()):{string:s(),length:n-u}}if(r===t.METRICS_BYTES){if(!this.noAssert){if("number"!=typeof n||n%1!=0)throw TypeError("Illegal offset: "+n+" (not an integer)");if((n>>>=0)<0||n+e>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+n+" (+"+e+") <= "+this.buffer.byteLength)}var l=n+e;if(c.decodeUTF8toUTF16(function(){return n<l?this.view[n++]:null}.bind(this),s=o(),this.noAssert),n!==l)throw RangeError("Illegal range: Truncated data, "+n+" == "+l);return i?(this.offset=n,s()):{string:s(),length:n-u}}throw TypeError("Unsupported metrics: "+r)},r.readString=r.readUTF8String,r.writeVString=function(e,r){var n=void 0===r;if(n&&(r=this.offset),!this.noAssert){if("string"!=typeof e)throw TypeError("Illegal str: Not a string");if("number"!=typeof r||r%1!=0)throw TypeError("Illegal offset: "+r+" (not an integer)");if((r>>>=0)<0||r+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+r+" (+0) <= "+this.buffer.byteLength)}var i,o,a=r;i=c.calculateUTF16asUTF8(s(e),this.noAssert)[1],o=t.calculateVarint32(i),r+=o+i;var u=this.buffer.byteLength;if(r>u&&this.resize((u*=2)>r?u:r),r-=o+i,r+=this.writeVarint32(i,r),c.encodeUTF16toUTF8(s(e),function(e){this.view[r++]=e}.bind(this)),r!==a+i+o)throw RangeError("Illegal range: Truncated data, "+r+" == "+(r+i+o));return n?(this.offset=r,this):r-a},r.readVString=function(e){var r=void 0===e;if(r&&(e=this.offset),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+1>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+1) <= "+this.buffer.byteLength)}var n=e,i=this.readVarint32(e),s=this.readUTF8String(i.value,t.METRICS_BYTES,e+=i.length);return e+=s.length,r?(this.offset=e,s.string):{string:s.string,length:e-n}},r.append=function(e,r,n){"number"!=typeof r&&"string"==typeof r||(n=r,r=void 0);var i=void 0===n;if(i&&(n=this.offset),!this.noAssert){if("number"!=typeof n||n%1!=0)throw TypeError("Illegal offset: "+n+" (not an integer)");if((n>>>=0)<0||n+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+n+" (+0) <= "+this.buffer.byteLength)}e instanceof t||(e=t.wrap(e,r));var s=e.limit-e.offset;if(s<=0)return this;n+=s;var o=this.buffer.byteLength;return n>o&&this.resize((o*=2)>n?o:n),n-=s,this.view.set(e.view.subarray(e.offset,e.limit),n),e.offset+=s,i&&(this.offset+=s),this},r.appendTo=function(e,t){return e.append(this,t),this},r.assert=function(e){return this.noAssert=!e,this},r.capacity=function(){return this.buffer.byteLength},r.clear=function(){return this.offset=0,this.limit=this.buffer.byteLength,this.markedOffset=-1,this},r.clone=function(e){var r=new t(0,this.littleEndian,this.noAssert);return e?(r.buffer=new ArrayBuffer(this.buffer.byteLength),r.view=new Uint8Array(r.buffer)):(r.buffer=this.buffer,r.view=this.view),r.offset=this.offset,r.markedOffset=this.markedOffset,r.limit=this.limit,r},r.compact=function(e,t){if(void 0===e&&(e=this.offset),void 0===t&&(t=this.limit),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal begin: Not an integer");if(e>>>=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal end: Not an integer");if(t>>>=0,e<0||e>t||t>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+e+" <= "+t+" <= "+this.buffer.byteLength)}if(0===e&&t===this.buffer.byteLength)return this;var r=t-e;if(0===r)return this.buffer=n,this.view=null,this.markedOffset>=0&&(this.markedOffset-=e),this.offset=0,this.limit=0,this;var i=new ArrayBuffer(r),s=new Uint8Array(i);return s.set(this.view.subarray(e,t)),this.buffer=i,this.view=s,this.markedOffset>=0&&(this.markedOffset-=e),this.offset=0,this.limit=r,this},r.copy=function(e,r){if(void 0===e&&(e=this.offset),void 0===r&&(r=this.limit),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal begin: Not an integer");if(e>>>=0,"number"!=typeof r||r%1!=0)throw TypeError("Illegal end: Not an integer");if(r>>>=0,e<0||e>r||r>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+e+" <= "+r+" <= "+this.buffer.byteLength)}if(e===r)return new t(0,this.littleEndian,this.noAssert);var n=r-e,i=new t(n,this.littleEndian,this.noAssert);return i.offset=0,i.limit=n,i.markedOffset>=0&&(i.markedOffset-=e),this.copyTo(i,0,e,r),i},r.copyTo=function(e,r,n,i){var s,o;if(!this.noAssert&&!t.isByteBuffer(e))throw TypeError("Illegal target: Not a ByteBuffer");if(r=(o=void 0===r)?e.offset:0|r,n=(s=void 0===n)?this.offset:0|n,i=void 0===i?this.limit:0|i,r<0||r>e.buffer.byteLength)throw RangeError("Illegal target range: 0 <= "+r+" <= "+e.buffer.byteLength);if(n<0||i>this.buffer.byteLength)throw RangeError("Illegal source range: 0 <= "+n+" <= "+this.buffer.byteLength);var a=i-n;return 0===a?e:(e.ensureCapacity(r+a),e.view.set(this.view.subarray(n,i),r),s&&(this.offset+=a),o&&(e.offset+=a),this)},r.ensureCapacity=function(e){var t=this.buffer.byteLength;return t<e?this.resize((t*=2)>e?t:e):this},r.fill=function(e,t,r){var n=void 0===t;if(n&&(t=this.offset),"string"==typeof e&&e.length>0&&(e=e.charCodeAt(0)),void 0===t&&(t=this.offset),void 0===r&&(r=this.limit),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal value: "+e+" (not an integer)");if(e|=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal begin: Not an integer");if(t>>>=0,"number"!=typeof r||r%1!=0)throw TypeError("Illegal end: Not an integer");if(r>>>=0,t<0||t>r||r>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+t+" <= "+r+" <= "+this.buffer.byteLength)}if(t>=r)return this;for(;t<r;)this.view[t++]=e;return n&&(this.offset=t),this},r.flip=function(){return this.limit=this.offset,this.offset=0,this},r.mark=function(e){if(e=void 0===e?this.offset:e,!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal offset: "+e+" (not an integer)");if((e>>>=0)<0||e+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+e+" (+0) <= "+this.buffer.byteLength)}return this.markedOffset=e,this},r.order=function(e){if(!this.noAssert&&"boolean"!=typeof e)throw TypeError("Illegal littleEndian: Not a boolean");return this.littleEndian=!!e,this},r.LE=function(e){return this.littleEndian=void 0===e||!!e,this},r.BE=function(e){return this.littleEndian=void 0!==e&&!e,this},r.prepend=function(e,r,n){"number"!=typeof r&&"string"==typeof r||(n=r,r=void 0);var i=void 0===n;if(i&&(n=this.offset),!this.noAssert){if("number"!=typeof n||n%1!=0)throw TypeError("Illegal offset: "+n+" (not an integer)");if((n>>>=0)<0||n+0>this.buffer.byteLength)throw RangeError("Illegal offset: 0 <= "+n+" (+0) <= "+this.buffer.byteLength)}e instanceof t||(e=t.wrap(e,r));var s=e.limit-e.offset;if(s<=0)return this;var o=s-n;if(o>0){var a=new ArrayBuffer(this.buffer.byteLength+o),u=new Uint8Array(a);u.set(this.view.subarray(n,this.buffer.byteLength),s),this.buffer=a,this.view=u,this.offset+=o,this.markedOffset>=0&&(this.markedOffset+=o),this.limit+=o,n+=o}else new Uint8Array(this.buffer);return this.view.set(e.view.subarray(e.offset,e.limit),n-s),e.offset=e.limit,i&&(this.offset-=s),this},r.prependTo=function(e,t){return e.prepend(this,t),this},r.printDebug=function(e){"function"!=typeof e&&(e=console.log.bind(console)),e(this.toString()+"\n-------------------------------------------------------------------\n"+this.toDebug(!0))},r.remaining=function(){return this.limit-this.offset},r.reset=function(){return this.markedOffset>=0?(this.offset=this.markedOffset,this.markedOffset=-1):this.offset=0,this},r.resize=function(e){if(!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal capacity: "+e+" (not an integer)");if((e|=0)<0)throw RangeError("Illegal capacity: 0 <= "+e)}if(this.buffer.byteLength<e){var t=new ArrayBuffer(e),r=new Uint8Array(t);r.set(this.view),this.buffer=t,this.view=r}return this},r.reverse=function(e,t){if(void 0===e&&(e=this.offset),void 0===t&&(t=this.limit),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal begin: Not an integer");if(e>>>=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal end: Not an integer");if(t>>>=0,e<0||e>t||t>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+e+" <= "+t+" <= "+this.buffer.byteLength)}return e===t||Array.prototype.reverse.call(this.view.subarray(e,t)),this},r.skip=function(e){if(!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal length: "+e+" (not an integer)");e|=0}var t=this.offset+e;if(!this.noAssert&&(t<0||t>this.buffer.byteLength))throw RangeError("Illegal length: 0 <= "+this.offset+" + "+e+" <= "+this.buffer.byteLength);return this.offset=t,this},r.slice=function(e,t){if(void 0===e&&(e=this.offset),void 0===t&&(t=this.limit),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal begin: Not an integer");if(e>>>=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal end: Not an integer");if(t>>>=0,e<0||e>t||t>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+e+" <= "+t+" <= "+this.buffer.byteLength)}var r=this.clone();return r.offset=e,r.limit=t,r},r.toBuffer=function(e){var t=this.offset,r=this.limit;if(!this.noAssert){if("number"!=typeof t||t%1!=0)throw TypeError("Illegal offset: Not an integer");if(t>>>=0,"number"!=typeof r||r%1!=0)throw TypeError("Illegal limit: Not an integer");if(r>>>=0,t<0||t>r||r>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+t+" <= "+r+" <= "+this.buffer.byteLength)}if(!e&&0===t&&r===this.buffer.byteLength)return this.buffer;if(t===r)return n;var i=new ArrayBuffer(r-t);return new Uint8Array(i).set(new Uint8Array(this.buffer).subarray(t,r),0),i},r.toArrayBuffer=r.toBuffer,r.toString=function(e,t,r){if(void 0===e)return"ByteBufferAB(offset="+this.offset+",markedOffset="+this.markedOffset+",limit="+this.limit+",capacity="+this.capacity()+")";switch("number"==typeof e&&(r=t=e="utf8"),e){case"utf8":return this.toUTF8(t,r);case"base64":return this.toBase64(t,r);case"hex":return this.toHex(t,r);case"binary":return this.toBinary(t,r);case"debug":return this.toDebug();case"columns":return this.toColumns();default:throw Error("Unsupported encoding: "+e)}};var l=function(){for(var e={},t=[65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,48,49,50,51,52,53,54,55,56,57,43,47],r=[],n=0,i=t.length;n<i;++n)r[t[n]]=n;return e.encode=function(e,r){for(var n,i;null!==(n=e());)r(t[n>>2&63]),i=(3&n)<<4,null!==(n=e())?(r(t[63&((i|=n>>4&15)|n>>4&15)]),i=(15&n)<<2,null!==(n=e())?(r(t[63&(i|n>>6&3)]),r(t[63&n])):(r(t[63&i]),r(61))):(r(t[63&i]),r(61),r(61))},e.decode=function(e,t){var n,i,s;function o(e){throw Error("Illegal character code: "+e)}for(;null!==(n=e());)if(void 0===(i=r[n])&&o(n),null!==(n=e())&&(void 0===(s=r[n])&&o(n),t(i<<2>>>0|(48&s)>>4),null!==(n=e()))){if(void 0===(i=r[n])){if(61===n)break;o(n)}if(t((15&s)<<4>>>0|(60&i)>>2),null!==(n=e())){if(void 0===(s=r[n])){if(61===n)break;o(n)}t((3&i)<<6>>>0|s)}}},e.test=function(e){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(e)},e}();r.toBase64=function(e,t){if(void 0===e&&(e=this.offset),void 0===t&&(t=this.limit),t|=0,(e|=0)<0||t>this.capacity||e>t)throw RangeError("begin, end");var r;return l.encode(function(){return e<t?this.view[e++]:null}.bind(this),r=o()),r()},t.fromBase64=function(e,r){if("string"!=typeof e)throw TypeError("str");var n=new t(e.length/4*3,r),i=0;return l.decode(s(e),(function(e){n.view[i++]=e})),n.limit=i,n},t.btoa=function(e){return t.fromBinary(e).toBase64()},t.atob=function(e){return t.fromBase64(e).toBinary()},r.toBinary=function(e,t){if(void 0===e&&(e=this.offset),void 0===t&&(t=this.limit),t|=0,(e|=0)<0||t>this.capacity()||e>t)throw RangeError("begin, end");if(e===t)return"";for(var r=[],n=[];e<t;)r.push(this.view[e++]),r.length>=1024&&(n.push(String.fromCharCode.apply(String,r)),r=[]);return n.join("")+String.fromCharCode.apply(String,r)},t.fromBinary=function(e,r){if("string"!=typeof e)throw TypeError("str");for(var n,i=0,s=e.length,o=new t(s,r);i<s;){if((n=e.charCodeAt(i))>255)throw RangeError("illegal char code: "+n);o.view[i++]=n}return o.limit=s,o},r.toDebug=function(e){for(var t,r=-1,n=this.buffer.byteLength,i="",s="",o="";r<n;){if(-1!==r&&(i+=(t=this.view[r])<16?"0"+t.toString(16).toUpperCase():t.toString(16).toUpperCase(),e&&(s+=t>32&&t<127?String.fromCharCode(t):".")),++r,e&&r>0&&r%16==0&&r!==n){for(;i.length<51;)i+=" ";o+=i+s+"\n",i=s=""}r===this.offset&&r===this.limit?i+=r===this.markedOffset?"!":"|":r===this.offset?i+=r===this.markedOffset?"[":"<":r===this.limit?i+=r===this.markedOffset?"]":">":i+=r===this.markedOffset?"'":e||0!==r&&r!==n?" ":""}if(e&&" "!==i){for(;i.length<51;)i+=" ";o+=i+s+"\n"}return e?o:i},t.fromDebug=function(e,r,n){for(var i,s,o=e.length,a=new t((o+1)/3|0,r,n),u=0,l=0,c=!1,h=!1,f=!1,d=!1,p=!1;u<o;){switch(i=e.charAt(u++)){case"!":if(!n){if(h||f||d){p=!0;break}h=f=d=!0}a.offset=a.markedOffset=a.limit=l,c=!1;break;case"|":if(!n){if(h||d){p=!0;break}h=d=!0}a.offset=a.limit=l,c=!1;break;case"[":if(!n){if(h||f){p=!0;break}h=f=!0}a.offset=a.markedOffset=l,c=!1;break;case"<":if(!n){if(h){p=!0;break}h=!0}a.offset=l,c=!1;break;case"]":if(!n){if(d||f){p=!0;break}d=f=!0}a.limit=a.markedOffset=l,c=!1;break;case">":if(!n){if(d){p=!0;break}d=!0}a.limit=l,c=!1;break;case"'":if(!n){if(f){p=!0;break}f=!0}a.markedOffset=l,c=!1;break;case" ":c=!1;break;default:if(!n&&c){p=!0;break}if(s=parseInt(i+e.charAt(u++),16),!n&&(isNaN(s)||s<0||s>255))throw TypeError("Illegal str: Not a debug encoded string");a.view[l++]=s,c=!0}if(p)throw TypeError("Illegal str: Invalid symbol at "+u)}if(!n){if(!h||!d)throw TypeError("Illegal str: Missing offset or limit");if(l<a.buffer.byteLength)throw TypeError("Illegal str: Not a debug encoded string (is it hex?) "+l+" < "+o)}return a},r.toHex=function(e,t){if(e=void 0===e?this.offset:e,t=void 0===t?this.limit:t,!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal begin: Not an integer");if(e>>>=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal end: Not an integer");if(t>>>=0,e<0||e>t||t>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+e+" <= "+t+" <= "+this.buffer.byteLength)}for(var r,n=new Array(t-e);e<t;)(r=this.view[e++])<16?n.push("0",r.toString(16)):n.push(r.toString(16));return n.join("")},t.fromHex=function(e,r,n){if(!n){if("string"!=typeof e)throw TypeError("Illegal str: Not a string");if(e.length%2!=0)throw TypeError("Illegal str: Length not a multiple of 2")}for(var i,s=e.length,o=new t(s/2|0,r),a=0,u=0;a<s;a+=2){if(i=parseInt(e.substring(a,a+2),16),!n&&(!isFinite(i)||i<0||i>255))throw TypeError("Illegal str: Contains non-hex characters");o.view[u++]=i}return o.limit=u,o};var c=function(){var e={MAX_CODEPOINT:1114111,encodeUTF8:function(e,t){var r=null;for("number"==typeof e&&(r=e,e=function(){return null});null!==r||null!==(r=e());)r<128?t(127&r):r<2048?(t(r>>6&31|192),t(63&r|128)):r<65536?(t(r>>12&15|224),t(r>>6&63|128),t(63&r|128)):(t(r>>18&7|240),t(r>>12&63|128),t(r>>6&63|128),t(63&r|128)),r=null},decodeUTF8:function(e,t){for(var r,n,i,s,o=function(e){e=e.slice(0,e.indexOf(null));var t=Error(e.toString());throw t.name="TruncatedError",t.bytes=e,t};null!==(r=e());)if(0==(128&r))t(r);else if(192==(224&r))null===(n=e())&&o([r,n]),t((31&r)<<6|63&n);else if(224==(240&r))(null===(n=e())||null===(i=e()))&&o([r,n,i]),t((15&r)<<12|(63&n)<<6|63&i);else{if(240!=(248&r))throw RangeError("Illegal starting byte: "+r);(null===(n=e())||null===(i=e())||null===(s=e()))&&o([r,n,i,s]),t((7&r)<<18|(63&n)<<12|(63&i)<<6|63&s)}},UTF16toUTF8:function(e,t){for(var r,n=null;null!==(r=null!==n?n:e());)r>=55296&&r<=57343&&null!==(n=e())&&n>=56320&&n<=57343?(t(1024*(r-55296)+n-56320+65536),n=null):t(r);null!==n&&t(n)},UTF8toUTF16:function(e,t){var r=null;for("number"==typeof e&&(r=e,e=function(){return null});null!==r||null!==(r=e());)r<=65535?t(r):(t(55296+((r-=65536)>>10)),t(r%1024+56320)),r=null},encodeUTF16toUTF8:function(t,r){e.UTF16toUTF8(t,(function(t){e.encodeUTF8(t,r)}))},decodeUTF8toUTF16:function(t,r){e.decodeUTF8(t,(function(t){e.UTF8toUTF16(t,r)}))},calculateCodePoint:function(e){return e<128?1:e<2048?2:e<65536?3:4},calculateUTF8:function(e){for(var t,r=0;null!==(t=e());)r+=t<128?1:t<2048?2:t<65536?3:4;return r},calculateUTF16asUTF8:function(t){var r=0,n=0;return e.UTF16toUTF8(t,(function(e){++r,n+=e<128?1:e<2048?2:e<65536?3:4})),[r,n]}};return e}();return r.toUTF8=function(e,t){if(void 0===e&&(e=this.offset),void 0===t&&(t=this.limit),!this.noAssert){if("number"!=typeof e||e%1!=0)throw TypeError("Illegal begin: Not an integer");if(e>>>=0,"number"!=typeof t||t%1!=0)throw TypeError("Illegal end: Not an integer");if(t>>>=0,e<0||e>t||t>this.buffer.byteLength)throw RangeError("Illegal range: 0 <= "+e+" <= "+t+" <= "+this.buffer.byteLength)}var r;try{c.decodeUTF8toUTF16(function(){return e<t?this.view[e++]:null}.bind(this),r=o())}catch(r){if(e!==t)throw RangeError("Illegal range: Truncated data, "+e+" != "+t)}return r()},t.fromUTF8=function(e,r,n){if(!n&&"string"!=typeof e)throw TypeError("Illegal str: Not a string");var i=new t(c.calculateUTF16asUTF8(s(e),!0)[1],r,n),o=0;return c.encodeUTF16toUTF8(s(e),(function(e){i.view[o++]=e})),i.limit=o,i},t}))})),j=(P=Object.freeze({__proto__:null,default:{}}))&&P.default||P,D=i((function(e){
  15. /**
  16. * @license protobuf.js (c) 2013 Daniel Wirtz <dcode@dcode.io>
  17. * Released under the Apache License, Version 2.0
  18. * see: https://github.com/dcodeIO/protobuf.js for details
  19. */
  20. !function(t,r){e&&e.exports?e.exports=r(k,!0):(t.dcodeIO=t.dcodeIO||{}).ProtoBuf=r(t.dcodeIO.ByteBuffer)}(r,(function(e,r){var n,i={};return i.ByteBuffer=e,i.Long=e.Long||null,i.VERSION="5.0.3",i.WIRE_TYPES={},i.WIRE_TYPES.VARINT=0,i.WIRE_TYPES.BITS64=1,i.WIRE_TYPES.LDELIM=2,i.WIRE_TYPES.STARTGROUP=3,i.WIRE_TYPES.ENDGROUP=4,i.WIRE_TYPES.BITS32=5,i.PACKABLE_WIRE_TYPES=[i.WIRE_TYPES.VARINT,i.WIRE_TYPES.BITS64,i.WIRE_TYPES.BITS32],i.TYPES={int32:{name:"int32",wireType:i.WIRE_TYPES.VARINT,defaultValue:0},uint32:{name:"uint32",wireType:i.WIRE_TYPES.VARINT,defaultValue:0},sint32:{name:"sint32",wireType:i.WIRE_TYPES.VARINT,defaultValue:0},int64:{name:"int64",wireType:i.WIRE_TYPES.VARINT,defaultValue:i.Long?i.Long.ZERO:void 0},uint64:{name:"uint64",wireType:i.WIRE_TYPES.VARINT,defaultValue:i.Long?i.Long.UZERO:void 0},sint64:{name:"sint64",wireType:i.WIRE_TYPES.VARINT,defaultValue:i.Long?i.Long.ZERO:void 0},bool:{name:"bool",wireType:i.WIRE_TYPES.VARINT,defaultValue:!1},double:{name:"double",wireType:i.WIRE_TYPES.BITS64,defaultValue:0},string:{name:"string",wireType:i.WIRE_TYPES.LDELIM,defaultValue:""},bytes:{name:"bytes",wireType:i.WIRE_TYPES.LDELIM,defaultValue:null},fixed32:{name:"fixed32",wireType:i.WIRE_TYPES.BITS32,defaultValue:0},sfixed32:{name:"sfixed32",wireType:i.WIRE_TYPES.BITS32,defaultValue:0},fixed64:{name:"fixed64",wireType:i.WIRE_TYPES.BITS64,defaultValue:i.Long?i.Long.UZERO:void 0},sfixed64:{name:"sfixed64",wireType:i.WIRE_TYPES.BITS64,defaultValue:i.Long?i.Long.ZERO:void 0},float:{name:"float",wireType:i.WIRE_TYPES.BITS32,defaultValue:0},enum:{name:"enum",wireType:i.WIRE_TYPES.VARINT,defaultValue:0},message:{name:"message",wireType:i.WIRE_TYPES.LDELIM,defaultValue:null},group:{name:"group",wireType:i.WIRE_TYPES.STARTGROUP,defaultValue:null}},i.MAP_KEY_TYPES=[i.TYPES.int32,i.TYPES.sint32,i.TYPES.sfixed32,i.TYPES.uint32,i.TYPES.fixed32,i.TYPES.int64,i.TYPES.sint64,i.TYPES.sfixed64,i.TYPES.uint64,i.TYPES.fixed64,i.TYPES.bool,i.TYPES.string,i.TYPES.bytes],i.ID_MIN=1,i.ID_MAX=536870911,i.convertFieldsToCamelCase=!1,i.populateAccessors=!0,i.populateDefaults=!0,i.Util=((n={}).IS_NODE=!("object"!=typeof t||t+""!="[object process]"||t.browser),n.XHR=function(){for(var e=[function(){return new XMLHttpRequest},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml3.XMLHTTP")},function(){return new ActiveXObject("Microsoft.XMLHTTP")}],t=null,r=0;r<e.length;r++){try{t=e[r]()}catch(e){continue}break}if(!t)throw Error("XMLHttpRequest is not supported");return t},n.fetch=function(e,t){if(t&&"function"!=typeof t&&(t=null),n.IS_NODE){var r=j;if(t)r.readFile(e,(function(e,r){t(e?null:""+r)}));else try{return r.readFileSync(e)}catch(e){return null}}else{var i=n.XHR();if(i.open("GET",e,!!t),i.setRequestHeader("Accept","text/plain"),"function"==typeof i.overrideMimeType&&i.overrideMimeType("text/plain"),!t)return i.send(null),200==i.status||0==i.status&&"string"==typeof i.responseText?i.responseText:null;if(i.onreadystatechange=function(){4==i.readyState&&(200==i.status||0==i.status&&"string"==typeof i.responseText?t(i.responseText):t(null))},4==i.readyState)return;i.send(null)}},n.toCamelCase=function(e){return e.replace(/_([a-zA-Z])/g,(function(e,t){return t.toUpperCase()}))},n),i.Lang={DELIM:/[\s\{\}=;:\[\],'"\(\)<>]/g,RULE:/^(?:required|optional|repeated|map)$/,TYPE:/^(?:double|float|int32|uint32|sint32|int64|uint64|sint64|fixed32|sfixed32|fixed64|sfixed64|bool|string|bytes)$/,NAME:/^[a-zA-Z_][a-zA-Z_0-9]*$/,TYPEDEF:/^[a-zA-Z][a-zA-Z_0-9]*$/,TYPEREF:/^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*$/,FQTYPEREF:/^(?:\.[a-zA-Z_][a-zA-Z_0-9]*)+$/,NUMBER:/^-?(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+|([0-9]*(\.[0-9]*)?([Ee][+-]?[0-9]+)?)|inf|nan)$/,NUMBER_DEC:/^(?:[1-9][0-9]*|0)$/,NUMBER_HEX:/^0[xX][0-9a-fA-F]+$/,NUMBER_OCT:/^0[0-7]+$/,NUMBER_FLT:/^([0-9]*(\.[0-9]*)?([Ee][+-]?[0-9]+)?|inf|nan)$/,BOOL:/^(?:true|false)$/i,ID:/^(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+)$/,NEGID:/^\-?(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+)$/,WHITESPACE:/\s/,STRING:/(?:"([^"\\]*(?:\\.[^"\\]*)*)")|(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g,STRING_DQ:/(?:"([^"\\]*(?:\\.[^"\\]*)*)")/g,STRING_SQ:/(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g},i.Reflect=function(t){var r={},n=function(e,t,r){this.builder=e,this.parent=t,this.name=r,this.className},i=n.prototype;i.fqn=function(){for(var e=this.name,t=this;;){if(null==(t=t.parent))break;e=t.name+"."+e}return e},i.toString=function(e){return(e?this.className+" ":"")+this.fqn()},i.build=function(){throw Error(this.toString(!0)+" cannot be built directly")},r.T=n;var s=function(e,t,r,i,s){n.call(this,e,t,r),this.className="Namespace",this.children=[],this.options=i||{},this.syntax=s||"proto2"},o=s.prototype=Object.create(n.prototype);o.getChildren=function(e){if(null==(e=e||null))return this.children.slice();for(var t=[],r=0,n=this.children.length;r<n;++r)this.children[r]instanceof e&&t.push(this.children[r]);return t},o.addChild=function(e){var t;if(t=this.getChild(e.name))if(t instanceof c.Field&&t.name!==t.originalName&&null===this.getChild(t.originalName))t.name=t.originalName;else{if(!(e instanceof c.Field&&e.name!==e.originalName&&null===this.getChild(e.originalName)))throw Error("Duplicate name in namespace "+this.toString(!0)+": "+e.name);e.name=e.originalName}this.children.push(e)},o.getChild=function(e){for(var t="number"==typeof e?"id":"name",r=0,n=this.children.length;r<n;++r)if(this.children[r][t]===e)return this.children[r];return null},o.resolve=function(e,t){var n,i="string"==typeof e?e.split("."):e,s=this,o=0;if(""===i[o]){for(;null!==s.parent;)s=s.parent;o++}do{do{if(!(s instanceof r.Namespace)){s=null;break}if(!(n=s.getChild(i[o]))||!(n instanceof r.T)||t&&!(n instanceof r.Namespace)){s=null;break}s=n,o++}while(o<i.length);if(null!=s)break;if(null!==this.parent)return this.parent.resolve(e,t)}while(null!=s);return s},o.qn=function(e){var t=[],n=e;do{t.unshift(n.name),n=n.parent}while(null!==n);for(var i=1;i<=t.length;i++){var s=t.slice(t.length-i);if(e===this.resolve(s,e instanceof r.Namespace))return s.join(".")}return e.fqn()},o.build=function(){for(var e,t={},r=this.children,n=0,i=r.length;n<i;++n)(e=r[n])instanceof s&&(t[e.name]=e.build());return Object.defineProperty&&Object.defineProperty(t,"$options",{value:this.buildOpt()}),t},o.buildOpt=function(){for(var e={},t=Object.keys(this.options),r=0,n=t.length;r<n;++r){var i=t[r],s=this.options[t[r]];e[i]=s}return e},o.getOption=function(e){return void 0===e?this.options:void 0!==this.options[e]?this.options[e]:null},r.Namespace=s;var a=function(e,r,n,i,s){if(this.type=e,this.resolvedType=r,this.isMapKey=n,this.syntax=i,this.name=s,n&&t.MAP_KEY_TYPES.indexOf(e)<0)throw Error("Invalid map key type: "+e.name)},u=a.prototype;function l(e,r){if(e&&"number"==typeof e.low&&"number"==typeof e.high&&"boolean"==typeof e.unsigned&&e.low==e.low&&e.high==e.high)return new t.Long(e.low,e.high,void 0===r?e.unsigned:r);if("string"==typeof e)return t.Long.fromString(e,r||!1,10);if("number"==typeof e)return t.Long.fromNumber(e,r||!1);throw Error("not convertible to Long")}a.defaultFieldValue=function(r){if("string"==typeof r&&(r=t.TYPES[r]),void 0===r.defaultValue)throw Error("default value for type "+r.name+" is not supported");return r==t.TYPES.bytes?new e(0):r.defaultValue},u.toString=function(){return(this.name||"")+(this.isMapKey?"map":"value")+" element"},u.verifyValue=function(r){var n=this;function i(e,t){throw Error("Illegal value for "+n.toString(!0)+" of type "+n.type.name+": "+e+" ("+t+")")}switch(this.type){case t.TYPES.int32:case t.TYPES.sint32:case t.TYPES.sfixed32:return("number"!=typeof r||r==r&&r%1!=0)&&i(typeof r,"not an integer"),r>4294967295?0|r:r;case t.TYPES.uint32:case t.TYPES.fixed32:return("number"!=typeof r||r==r&&r%1!=0)&&i(typeof r,"not an integer"),r<0?r>>>0:r;case t.TYPES.int64:case t.TYPES.sint64:case t.TYPES.sfixed64:if(t.Long)try{return l(r,!1)}catch(e){i(typeof r,e.message)}else i(typeof r,"requires Long.js");case t.TYPES.uint64:case t.TYPES.fixed64:if(t.Long)try{return l(r,!0)}catch(e){i(typeof r,e.message)}else i(typeof r,"requires Long.js");case t.TYPES.bool:return"boolean"!=typeof r&&i(typeof r,"not a boolean"),r;case t.TYPES.float:case t.TYPES.double:return"number"!=typeof r&&i(typeof r,"not a number"),r;case t.TYPES.string:return"string"==typeof r||r&&r instanceof String||i(typeof r,"not a string"),""+r;case t.TYPES.bytes:return e.isByteBuffer(r)?r:e.wrap(r,"base64");case t.TYPES.enum:var s=this.resolvedType.getChildren(t.Reflect.Enum.Value);for(a=0;a<s.length;a++){if(s[a].name==r)return s[a].id;if(s[a].id==r)return s[a].id}if("proto3"===this.syntax)return("number"!=typeof r||r==r&&r%1!=0)&&i(typeof r,"not an integer"),(r>4294967295||r<0)&&i(typeof r,"not in range for uint32"),r;i(r,"not a valid enum value");case t.TYPES.group:case t.TYPES.message:if(r&&"object"==typeof r||i(typeof r,"object expected"),r instanceof this.resolvedType.clazz)return r;if(r instanceof t.Builder.Message){var o={};for(var a in r)r.hasOwnProperty(a)&&(o[a]=r[a]);r=o}return new this.resolvedType.clazz(r)}throw Error("[INTERNAL] Illegal value for "+this.toString(!0)+": "+r+" (undefined type "+this.type+")")},u.calculateLength=function(r,n){if(null===n)return 0;var i;switch(this.type){case t.TYPES.int32:return n<0?e.calculateVarint64(n):e.calculateVarint32(n);case t.TYPES.uint32:return e.calculateVarint32(n);case t.TYPES.sint32:return e.calculateVarint32(e.zigZagEncode32(n));case t.TYPES.fixed32:case t.TYPES.sfixed32:case t.TYPES.float:return 4;case t.TYPES.int64:case t.TYPES.uint64:return e.calculateVarint64(n);case t.TYPES.sint64:return e.calculateVarint64(e.zigZagEncode64(n));case t.TYPES.fixed64:case t.TYPES.sfixed64:return 8;case t.TYPES.bool:return 1;case t.TYPES.enum:return e.calculateVarint32(n);case t.TYPES.double:return 8;case t.TYPES.string:return i=e.calculateUTF8Bytes(n),e.calculateVarint32(i)+i;case t.TYPES.bytes:if(n.remaining()<0)throw Error("Illegal value for "+this.toString(!0)+": "+n.remaining()+" bytes remaining");return e.calculateVarint32(n.remaining())+n.remaining();case t.TYPES.message:return i=this.resolvedType.calculate(n),e.calculateVarint32(i)+i;case t.TYPES.group:return(i=this.resolvedType.calculate(n))+e.calculateVarint32(r<<3|t.WIRE_TYPES.ENDGROUP)}throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+n+" (unknown type)")},u.encodeValue=function(r,n,i){if(null===n)return i;switch(this.type){case t.TYPES.int32:n<0?i.writeVarint64(n):i.writeVarint32(n);break;case t.TYPES.uint32:i.writeVarint32(n);break;case t.TYPES.sint32:i.writeVarint32ZigZag(n);break;case t.TYPES.fixed32:i.writeUint32(n);break;case t.TYPES.sfixed32:i.writeInt32(n);break;case t.TYPES.int64:case t.TYPES.uint64:i.writeVarint64(n);break;case t.TYPES.sint64:i.writeVarint64ZigZag(n);break;case t.TYPES.fixed64:i.writeUint64(n);break;case t.TYPES.sfixed64:i.writeInt64(n);break;case t.TYPES.bool:"string"==typeof n?i.writeVarint32("false"===n.toLowerCase()?0:!!n):i.writeVarint32(n?1:0);break;case t.TYPES.enum:i.writeVarint32(n);break;case t.TYPES.float:i.writeFloat32(n);break;case t.TYPES.double:i.writeFloat64(n);break;case t.TYPES.string:i.writeVString(n);break;case t.TYPES.bytes:if(n.remaining()<0)throw Error("Illegal value for "+this.toString(!0)+": "+n.remaining()+" bytes remaining");var s=n.offset;i.writeVarint32(n.remaining()),i.append(n),n.offset=s;break;case t.TYPES.message:var o=(new e).LE();this.resolvedType.encode(n,o),i.writeVarint32(o.offset),i.append(o.flip());break;case t.TYPES.group:this.resolvedType.encode(n,i),i.writeVarint32(r<<3|t.WIRE_TYPES.ENDGROUP);break;default:throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+n+" (unknown type)")}return i},u.decode=function(e,r,n){if(r!=this.type.wireType)throw Error("Unexpected wire type for element");var i,s;switch(this.type){case t.TYPES.int32:return 0|e.readVarint32();case t.TYPES.uint32:return e.readVarint32()>>>0;case t.TYPES.sint32:return 0|e.readVarint32ZigZag();case t.TYPES.fixed32:return e.readUint32()>>>0;case t.TYPES.sfixed32:return 0|e.readInt32();case t.TYPES.int64:return e.readVarint64();case t.TYPES.uint64:return e.readVarint64().toUnsigned();case t.TYPES.sint64:return e.readVarint64ZigZag();case t.TYPES.fixed64:return e.readUint64();case t.TYPES.sfixed64:return e.readInt64();case t.TYPES.bool:return!!e.readVarint32();case t.TYPES.enum:return e.readVarint32();case t.TYPES.float:return e.readFloat();case t.TYPES.double:return e.readDouble();case t.TYPES.string:return e.readVString();case t.TYPES.bytes:if(s=e.readVarint32(),e.remaining()<s)throw Error("Illegal number of bytes for "+this.toString(!0)+": "+s+" required but got only "+e.remaining());return(i=e.clone()).limit=i.offset+s,e.offset+=s,i;case t.TYPES.message:return s=e.readVarint32(),this.resolvedType.decode(e,s);case t.TYPES.group:return this.resolvedType.decode(e,-1,n)}throw Error("[INTERNAL] Illegal decode type")},u.valueFromString=function(r){if(!this.isMapKey)throw Error("valueFromString() called on non-map-key element");switch(this.type){case t.TYPES.int32:case t.TYPES.sint32:case t.TYPES.sfixed32:case t.TYPES.uint32:case t.TYPES.fixed32:return this.verifyValue(parseInt(r));case t.TYPES.int64:case t.TYPES.sint64:case t.TYPES.sfixed64:case t.TYPES.uint64:case t.TYPES.fixed64:return this.verifyValue(r);case t.TYPES.bool:return"true"===r;case t.TYPES.string:return this.verifyValue(r);case t.TYPES.bytes:return e.fromBinary(r)}},u.valueToString=function(e){if(!this.isMapKey)throw Error("valueToString() called on non-map-key element");return this.type===t.TYPES.bytes?e.toString("binary"):e.toString()},r.Element=a;var c=function(e,t,r,n,i,o){s.call(this,e,t,r,n,o),this.className="Message",this.extensions=void 0,this.clazz=null,this.isGroup=!!i,this._fields=null,this._fieldsById=null,this._fieldsByName=null},h=c.prototype=Object.create(s.prototype);function f(e,r){var n=r.readVarint32(),i=7&n,s=n>>>3;switch(i){case t.WIRE_TYPES.VARINT:do{n=r.readUint8()}while(128==(128&n));break;case t.WIRE_TYPES.BITS64:r.offset+=8;break;case t.WIRE_TYPES.LDELIM:n=r.readVarint32(),r.offset+=n;break;case t.WIRE_TYPES.STARTGROUP:f(s,r);break;case t.WIRE_TYPES.ENDGROUP:if(s===e)return!1;throw Error("Illegal GROUPEND after unknown group: "+s+" ("+e+" expected)");case t.WIRE_TYPES.BITS32:r.offset+=4;break;default:throw Error("Illegal wire type in unknown group "+e+": "+i)}return!0}h.build=function(r){if(this.clazz&&!r)return this.clazz;var n=function(t,r){var n=r.getChildren(t.Reflect.Message.Field),i=r.getChildren(t.Reflect.Message.OneOf),s=function(o,a){t.Builder.Message.call(this);for(var u=0,l=i.length;u<l;++u)this[i[u].name]=null;for(u=0,l=n.length;u<l;++u){var c=n[u];this[c.name]=c.repeated?[]:c.map?new t.Map(c):null,!c.required&&"proto3"!==r.syntax||null===c.defaultValue||(this[c.name]=c.defaultValue)}var h;if(arguments.length>0)if(1!==arguments.length||null===o||"object"!=typeof o||!("function"!=typeof o.encode||o instanceof s)||Array.isArray(o)||o instanceof t.Map||e.isByteBuffer(o)||o instanceof ArrayBuffer||t.Long&&o instanceof t.Long)for(u=0,l=arguments.length;u<l;++u)void 0!==(h=arguments[u])&&this.$set(n[u].name,h);else this.$set(o)},o=s.prototype=Object.create(t.Builder.Message.prototype);o.add=function(e,n,i){var s=r._fieldsByName[e];if(!i){if(!s)throw Error(this+"#"+e+" is undefined");if(!(s instanceof t.Reflect.Message.Field))throw Error(this+"#"+e+" is not a field: "+s.toString(!0));if(!s.repeated)throw Error(this+"#"+e+" is not a repeated field");n=s.verifyValue(n,!0)}return null===this[e]&&(this[e]=[]),this[e].push(n),this},o.$add=o.add,o.set=function(e,n,i){if(e&&"object"==typeof e){for(var s in i=n,e)e.hasOwnProperty(s)&&void 0!==(n=e[s])&&void 0===r._oneofsByName[s]&&this.$set(s,n,i);return this}var o=r._fieldsByName[e];if(i)this[e]=n;else{if(!o)throw Error(this+"#"+e+" is not a field: undefined");if(!(o instanceof t.Reflect.Message.Field))throw Error(this+"#"+e+" is not a field: "+o.toString(!0));this[o.name]=n=o.verifyValue(n)}if(o&&o.oneof){var a=this[o.oneof.name];null!==n?(null!==a&&a!==o.name&&(this[a]=null),this[o.oneof.name]=o.name):a===e&&(this[o.oneof.name]=null)}return this},o.$set=o.set,o.get=function(e,n){if(n)return this[e];var i=r._fieldsByName[e];if(!(i&&i instanceof t.Reflect.Message.Field))throw Error(this+"#"+e+" is not a field: undefined");if(!(i instanceof t.Reflect.Message.Field))throw Error(this+"#"+e+" is not a field: "+i.toString(!0));return this[i.name]},o.$get=o.get;for(var a=0;a<n.length;a++){var u=n[a];u instanceof t.Reflect.Message.ExtensionField||r.builder.options.populateAccessors&&function(e){var t=e.originalName.replace(/(_[a-zA-Z])/g,(function(e){return e.toUpperCase().replace("_","")}));t=t.substring(0,1).toUpperCase()+t.substring(1);var n=e.originalName.replace(/([A-Z])/g,(function(e){return"_"+e})),i=function(t,r){return this[e.name]=r?t:e.verifyValue(t),this},s=function(){return this[e.name]};null===r.getChild("set"+t)&&(o["set"+t]=i),null===r.getChild("set_"+n)&&(o["set_"+n]=i),null===r.getChild("get"+t)&&(o["get"+t]=s),null===r.getChild("get_"+n)&&(o["get_"+n]=s)}(u)}function l(r,n,i,s){if(null===r||"object"!=typeof r){if(s&&s instanceof t.Reflect.Enum){var o=t.Reflect.Enum.getName(s.object,r);if(null!==o)return o}return r}if(e.isByteBuffer(r))return n?r.toBase64():r.toBuffer();if(t.Long.isLong(r))return i?r.toString():t.Long.fromValue(r);var a;if(Array.isArray(r))return a=[],r.forEach((function(e,t){a[t]=l(e,n,i,s)})),a;if(a={},r instanceof t.Map){for(var u=r.entries(),c=u.next();!c.done;c=u.next())a[r.keyElem.valueToString(c.value[0])]=l(c.value[1],n,i,r.valueElem.resolvedType);return a}var h=r.$type,f=void 0;for(var d in r)r.hasOwnProperty(d)&&(h&&(f=h.getChild(d))?a[d]=l(r[d],n,i,f.resolvedType):a[d]=l(r[d],n,i));return a}return o.encode=function(t,n){"boolean"==typeof t&&(n=t,t=void 0);var i=!1;t||(t=new e,i=!0);var s=t.littleEndian;try{return r.encode(this,t.LE(),n),(i?t.flip():t).LE(s)}catch(e){throw t.LE(s),e}},s.encode=function(e,t,r){return new s(e).encode(t,r)},o.calculate=function(){return r.calculate(this)},o.encodeDelimited=function(t,n){var i=!1;t||(t=new e,i=!0);var s=(new e).LE();return r.encode(this,s,n).flip(),t.writeVarint32(s.remaining()),t.append(s),i?t.flip():t},o.encodeAB=function(){try{return this.encode().toArrayBuffer()}catch(e){throw e.encoded&&(e.encoded=e.encoded.toArrayBuffer()),e}},o.toArrayBuffer=o.encodeAB,o.encodeNB=function(){try{return this.encode().toBuffer()}catch(e){throw e.encoded&&(e.encoded=e.encoded.toBuffer()),e}},o.toBuffer=o.encodeNB,o.encode64=function(){try{return this.encode().toBase64()}catch(e){throw e.encoded&&(e.encoded=e.encoded.toBase64()),e}},o.toBase64=o.encode64,o.encodeHex=function(){try{return this.encode().toHex()}catch(e){throw e.encoded&&(e.encoded=e.encoded.toHex()),e}},o.toHex=o.encodeHex,o.toRaw=function(e,t){return l(this,!!e,!!t,this.$type)},o.encodeJSON=function(){return JSON.stringify(l(this,!0,!0,this.$type))},s.decode=function(t,n,i){"string"==typeof n&&(i=n,n=-1),"string"==typeof t?t=e.wrap(t,i||"base64"):e.isByteBuffer(t)||(t=e.wrap(t));var s=t.littleEndian;try{var o=r.decode(t.LE(),n);return t.LE(s),o}catch(e){throw t.LE(s),e}},s.decodeDelimited=function(t,n){if("string"==typeof t?t=e.wrap(t,n||"base64"):e.isByteBuffer(t)||(t=e.wrap(t)),t.remaining()<1)return null;var i=t.offset,s=t.readVarint32();if(t.remaining()<s)return t.offset=i,null;try{var o=r.decode(t.slice(t.offset,t.offset+s).LE());return t.offset+=s,o}catch(e){throw t.offset+=s,e}},s.decode64=function(e){return s.decode(e,"base64")},s.decodeHex=function(e){return s.decode(e,"hex")},s.decodeJSON=function(e){return new s(JSON.parse(e))},o.toString=function(){return r.toString()},Object.defineProperty&&(Object.defineProperty(s,"$options",{value:r.buildOpt()}),Object.defineProperty(o,"$options",{value:s.$options}),Object.defineProperty(s,"$type",{value:r}),Object.defineProperty(o,"$type",{value:r})),s}(t,this);this._fields=[],this._fieldsById={},this._fieldsByName={},this._oneofsByName={};for(var i,s=0,o=this.children.length;s<o;s++)if((i=this.children[s])instanceof g||i instanceof c||i instanceof b){if(n.hasOwnProperty(i.name))throw Error("Illegal reflect child of "+this.toString(!0)+": "+i.toString(!0)+" cannot override static property '"+i.name+"'");n[i.name]=i.build()}else if(i instanceof c.Field)i.build(),this._fields.push(i),this._fieldsById[i.id]=i,this._fieldsByName[i.name]=i;else if(i instanceof c.OneOf)this._oneofsByName[i.name]=i;else if(!(i instanceof c.OneOf||i instanceof v))throw Error("Illegal reflect child of "+this.toString(!0)+": "+this.children[s].toString(!0));return this.clazz=n},h.encode=function(e,t,r){for(var n,i,s=null,o=0,a=this._fields.length;o<a;++o)i=e[(n=this._fields[o]).name],n.required&&null===i?null===s&&(s=n):n.encode(r?i:n.verifyValue(i),t,e);if(null!==s){var u=Error("Missing at least one required field for "+this.toString(!0)+": "+s);throw u.encoded=t,u}return t},h.calculate=function(e){for(var t,r,n=0,i=0,s=this._fields.length;i<s;++i){if(r=e[(t=this._fields[i]).name],t.required&&null===r)throw Error("Missing at least one required field for "+this.toString(!0)+": "+t);n+=t.calculate(r,e)}return n},h.decode=function(e,r,n){"number"!=typeof r&&(r=-1);for(var i,s,o,a,u=e.offset,l=new this.clazz;e.offset<u+r||-1===r&&e.remaining()>0;){if(o=(i=e.readVarint32())>>>3,(s=7&i)===t.WIRE_TYPES.ENDGROUP){if(o!==n)throw Error("Illegal group end indicator for "+this.toString(!0)+": "+o+" ("+(n?n+" expected":"not a group")+")");break}if(a=this._fieldsById[o]){if(a.repeated&&!a.options.packed)l[a.name].push(a.decode(s,e));else if(a.map){var c=a.decode(s,e);l[a.name].set(c[0],c[1])}else if(l[a.name]=a.decode(s,e),a.oneof){var h=l[a.oneof.name];null!==h&&h!==a.name&&(l[h]=null),l[a.oneof.name]=a.name}}else switch(s){case t.WIRE_TYPES.VARINT:e.readVarint32();break;case t.WIRE_TYPES.BITS32:e.offset+=4;break;case t.WIRE_TYPES.BITS64:e.offset+=8;break;case t.WIRE_TYPES.LDELIM:var d=e.readVarint32();e.offset+=d;break;case t.WIRE_TYPES.STARTGROUP:for(;f(o,e););break;default:throw Error("Illegal wire type for unknown field "+o+" in "+this.toString(!0)+"#decode: "+s)}}for(var p=0,m=this._fields.length;p<m;++p)if(null===l[(a=this._fields[p]).name])if("proto3"===this.syntax)l[a.name]=a.defaultValue;else{if(a.required){var g=Error("Missing at least one required field for "+this.toString(!0)+": "+a.name);throw g.decoded=l,g}t.populateDefaults&&null!==a.defaultValue&&(l[a.name]=a.defaultValue)}return l},r.Message=c;var d=function(e,r,i,s,o,a,u,l,h,f){n.call(this,e,r,a),this.className="Message.Field",this.required="required"===i,this.repeated="repeated"===i,this.map="map"===i,this.keyType=s||null,this.type=o,this.resolvedType=null,this.id=u,this.options=l||{},this.defaultValue=null,this.oneof=h||null,this.syntax=f||"proto2",this.originalName=this.name,this.element=null,this.keyElement=null,!this.builder.options.convertFieldsToCamelCase||this instanceof c.ExtensionField||(this.name=t.Util.toCamelCase(this.name))},p=d.prototype=Object.create(n.prototype);p.build=function(){this.element=new a(this.type,this.resolvedType,!1,this.syntax,this.name),this.map&&(this.keyElement=new a(this.keyType,void 0,!0,this.syntax,this.name)),"proto3"!==this.syntax||this.repeated||this.map?void 0!==this.options.default&&(this.defaultValue=this.verifyValue(this.options.default)):this.defaultValue=a.defaultFieldValue(this.type)},p.verifyValue=function(e,r){r=r||!1;var n,i=this;function s(e,t){throw Error("Illegal value for "+i.toString(!0)+" of type "+i.type.name+": "+e+" ("+t+")")}if(null===e)return this.required&&s(typeof e,"required"),"proto3"===this.syntax&&this.type!==t.TYPES.message&&s(typeof e,"proto3 field without field presence cannot be null"),null;if(this.repeated&&!r){Array.isArray(e)||(e=[e]);var o=[];for(n=0;n<e.length;n++)o.push(this.element.verifyValue(e[n]));return o}return this.map&&!r?e instanceof t.Map?e:(e instanceof Object||s(typeof e,"expected ProtoBuf.Map or raw object for map field"),new t.Map(this,e)):(!this.repeated&&Array.isArray(e)&&s(typeof e,"no array expected"),this.element.verifyValue(e))},p.hasWirePresence=function(e,r){if("proto3"!==this.syntax)return null!==e;if(this.oneof&&r[this.oneof.name]===this.name)return!0;switch(this.type){case t.TYPES.int32:case t.TYPES.sint32:case t.TYPES.sfixed32:case t.TYPES.uint32:case t.TYPES.fixed32:return 0!==e;case t.TYPES.int64:case t.TYPES.sint64:case t.TYPES.sfixed64:case t.TYPES.uint64:case t.TYPES.fixed64:return 0!==e.low||0!==e.high;case t.TYPES.bool:return e;case t.TYPES.float:case t.TYPES.double:return 0!==e;case t.TYPES.string:return e.length>0;case t.TYPES.bytes:return e.remaining()>0;case t.TYPES.enum:return 0!==e;case t.TYPES.message:return null!==e;default:return!0}},p.encode=function(r,n,i){if(null===this.type||"object"!=typeof this.type)throw Error("[INTERNAL] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===r||this.repeated&&0==r.length)return n;try{var s;if(this.repeated)if(this.options.packed&&t.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)>=0){n.writeVarint32(this.id<<3|t.WIRE_TYPES.LDELIM),n.ensureCapacity(n.offset+=1);var o=n.offset;for(s=0;s<r.length;s++)this.element.encodeValue(this.id,r[s],n);var a=n.offset-o,u=e.calculateVarint32(a);if(u>1){var l=n.slice(o,n.offset);o+=u-1,n.offset=o,n.append(l)}n.writeVarint32(a,o-u)}else for(s=0;s<r.length;s++)n.writeVarint32(this.id<<3|this.type.wireType),this.element.encodeValue(this.id,r[s],n);else this.map?r.forEach((function(r,i,s){var o=e.calculateVarint32(8|this.keyType.wireType)+this.keyElement.calculateLength(1,i)+e.calculateVarint32(16|this.type.wireType)+this.element.calculateLength(2,r);n.writeVarint32(this.id<<3|t.WIRE_TYPES.LDELIM),n.writeVarint32(o),n.writeVarint32(8|this.keyType.wireType),this.keyElement.encodeValue(1,i,n),n.writeVarint32(16|this.type.wireType),this.element.encodeValue(2,r,n)}),this):this.hasWirePresence(r,i)&&(n.writeVarint32(this.id<<3|this.type.wireType),this.element.encodeValue(this.id,r,n))}catch(e){throw Error("Illegal value for "+this.toString(!0)+": "+r+" ("+e+")")}return n},p.calculate=function(r,n){if(r=this.verifyValue(r),null===this.type||"object"!=typeof this.type)throw Error("[INTERNAL] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===r||this.repeated&&0==r.length)return 0;var i=0;try{var s,o;if(this.repeated)if(this.options.packed&&t.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)>=0){for(i+=e.calculateVarint32(this.id<<3|t.WIRE_TYPES.LDELIM),o=0,s=0;s<r.length;s++)o+=this.element.calculateLength(this.id,r[s]);i+=e.calculateVarint32(o),i+=o}else for(s=0;s<r.length;s++)i+=e.calculateVarint32(this.id<<3|this.type.wireType),i+=this.element.calculateLength(this.id,r[s]);else this.map?r.forEach((function(r,n,s){var o=e.calculateVarint32(8|this.keyType.wireType)+this.keyElement.calculateLength(1,n)+e.calculateVarint32(16|this.type.wireType)+this.element.calculateLength(2,r);i+=e.calculateVarint32(this.id<<3|t.WIRE_TYPES.LDELIM),i+=e.calculateVarint32(o),i+=o}),this):this.hasWirePresence(r,n)&&(i+=e.calculateVarint32(this.id<<3|this.type.wireType),i+=this.element.calculateLength(this.id,r))}catch(e){throw Error("Illegal value for "+this.toString(!0)+": "+r+" ("+e+")")}return i},p.decode=function(e,r,n){var i,s;if(!(!this.map&&e==this.type.wireType||!n&&this.repeated&&this.options.packed&&e==t.WIRE_TYPES.LDELIM||this.map&&e==t.WIRE_TYPES.LDELIM))throw Error("Illegal wire type for field "+this.toString(!0)+": "+e+" ("+this.type.wireType+" expected)");if(e==t.WIRE_TYPES.LDELIM&&this.repeated&&this.options.packed&&t.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)>=0&&!n){s=r.readVarint32(),s=r.offset+s;for(var o=[];r.offset<s;)o.push(this.decode(this.type.wireType,r,!0));return o}if(this.map){var u=a.defaultFieldValue(this.keyType);if(i=a.defaultFieldValue(this.type),s=r.readVarint32(),r.remaining()<s)throw Error("Illegal number of bytes for "+this.toString(!0)+": "+s+" required but got only "+r.remaining());var l=r.clone();for(l.limit=l.offset+s,r.offset+=s;l.remaining()>0;){var c=l.readVarint32();e=7&c;var h=c>>>3;if(1===h)u=this.keyElement.decode(l,e,h);else{if(2!==h)throw Error("Unexpected tag in map field key/value submessage");i=this.element.decode(l,e,h)}}return[u,i]}return this.element.decode(r,e,this.id)},r.Message.Field=d;var m=function(e,t,r,n,i,s,o){d.call(this,e,t,r,null,n,i,s,o),this.extension};m.prototype=Object.create(d.prototype),r.Message.ExtensionField=m;r.Message.OneOf=function(e,t,r){n.call(this,e,t,r),this.fields=[]};var g=function(e,t,r,n,i){s.call(this,e,t,r,n,i),this.className="Enum",this.object=null};g.getName=function(e,t){for(var r,n=Object.keys(e),i=0;i<n.length;++i)if(e[r=n[i]]===t)return r;return null},(g.prototype=Object.create(s.prototype)).build=function(e){if(this.object&&!e)return this.object;for(var r=new t.Builder.Enum,n=this.getChildren(g.Value),i=0,s=n.length;i<s;++i)r[n[i].name]=n[i].id;return Object.defineProperty&&Object.defineProperty(r,"$options",{value:this.buildOpt(),enumerable:!1}),this.object=r},r.Enum=g;var y=function(e,t,r,i){n.call(this,e,t,r),this.className="Enum.Value",this.id=i};y.prototype=Object.create(n.prototype),r.Enum.Value=y;var v=function(e,t,r,i){n.call(this,e,t,r),this.field=i};v.prototype=Object.create(n.prototype),r.Extension=v;var b=function(e,t,r,n){s.call(this,e,t,r,n),this.className="Service",this.clazz=null};(b.prototype=Object.create(s.prototype)).build=function(r){return this.clazz&&!r?this.clazz:this.clazz=function(t,r){for(var n=function(e){t.Builder.Service.call(this),this.rpcImpl=e||function(e,t,r){setTimeout(r.bind(this,Error("Not implemented, see: https://github.com/dcodeIO/ProtoBuf.js/wiki/Services")),0)}},i=n.prototype=Object.create(t.Builder.Service.prototype),s=r.getChildren(t.Reflect.Service.RPCMethod),o=0;o<s.length;o++)!function(t){i[t.name]=function(n,i){try{try{n=t.resolvedRequestType.clazz.decode(e.wrap(n))}catch(e){if(!(e instanceof TypeError))throw e}if(null===n||"object"!=typeof n)throw Error("Illegal arguments");n instanceof t.resolvedRequestType.clazz||(n=new t.resolvedRequestType.clazz(n)),this.rpcImpl(t.fqn(),n,(function(e,n){if(e)i(e);else{null===n&&(n="");try{n=t.resolvedResponseType.clazz.decode(n)}catch(e){}n&&n instanceof t.resolvedResponseType.clazz?i(null,n):i(Error("Illegal response type received in service method "+r.name+"#"+t.name))}}))}catch(e){setTimeout(i.bind(this,e),0)}},n[t.name]=function(e,r,i){new n(e)[t.name](r,i)},Object.defineProperty&&(Object.defineProperty(n[t.name],"$options",{value:t.buildOpt()}),Object.defineProperty(i[t.name],"$options",{value:n[t.name].$options}))}(s[o]);return Object.defineProperty&&(Object.defineProperty(n,"$options",{value:r.buildOpt()}),Object.defineProperty(i,"$options",{value:n.$options}),Object.defineProperty(n,"$type",{value:r}),Object.defineProperty(i,"$type",{value:r})),n}(t,this)},r.Service=b;var w=function(e,t,r,i){n.call(this,e,t,r),this.className="Service.Method",this.options=i||{}};(w.prototype=Object.create(n.prototype)).buildOpt=o.buildOpt,r.Service.Method=w;var _=function(e,t,r,n,i,s,o,a){w.call(this,e,t,r,a),this.className="Service.RPCMethod",this.requestName=n,this.responseName=i,this.requestStream=s,this.responseStream=o,this.resolvedRequestType=null,this.resolvedResponseType=null};return _.prototype=Object.create(w.prototype),r.Service.RPCMethod=_,r}(i),i.Builder=function(e,t,r){var n=function(e){this.ns=new r.Namespace(this,null,""),this.ptr=this.ns,this.resolved=!1,this.result=null,this.files={},this.importRoot=null,this.options=e||{}},i=n.prototype;return n.isMessage=function(e){return"string"==typeof e.name&&(void 0===e.values&&void 0===e.rpc)},n.isMessageField=function(e){return"string"==typeof e.rule&&"string"==typeof e.name&&"string"==typeof e.type&&void 0!==e.id},n.isEnum=function(e){return"string"==typeof e.name&&!(void 0===e.values||!Array.isArray(e.values)||0===e.values.length)},n.isService=function(e){return!("string"!=typeof e.name||"object"!=typeof e.rpc||!e.rpc)},n.isExtend=function(e){return"string"==typeof e.ref},i.reset=function(){return this.ptr=this.ns,this},i.define=function(e){if("string"!=typeof e||!t.TYPEREF.test(e))throw Error("illegal namespace: "+e);return e.split(".").forEach((function(e){var t=this.ptr.getChild(e);null===t&&this.ptr.addChild(t=new r.Namespace(this,this.ptr,e)),this.ptr=t}),this),this},i.create=function(t){if(!t)return this;if(Array.isArray(t)){if(0===t.length)return this;t=t.slice()}else t=[t];for(var i=[t];i.length>0;){if(t=i.pop(),!Array.isArray(t))throw Error("not a valid namespace: "+JSON.stringify(t));for(;t.length>0;){var s=t.shift();if(n.isMessage(s)){var o=new r.Message(this,this.ptr,s.name,s.options,s.isGroup,s.syntax),a={};s.oneofs&&Object.keys(s.oneofs).forEach((function(e){o.addChild(a[e]=new r.Message.OneOf(this,o,e))}),this),s.fields&&s.fields.forEach((function(e){if(null!==o.getChild(0|e.id))throw Error("duplicate or invalid field id in "+o.name+": "+e.id);if(e.options&&"object"!=typeof e.options)throw Error("illegal field options in "+o.name+"#"+e.name);var t=null;if("string"==typeof e.oneof&&!(t=a[e.oneof]))throw Error("illegal oneof in "+o.name+"#"+e.name+": "+e.oneof);e=new r.Message.Field(this,o,e.rule,e.keytype,e.type,e.name,e.id,e.options,t,s.syntax),t&&t.fields.push(e),o.addChild(e)}),this);var u=[];if(s.enums&&s.enums.forEach((function(e){u.push(e)})),s.messages&&s.messages.forEach((function(e){u.push(e)})),s.services&&s.services.forEach((function(e){u.push(e)})),s.extensions&&("number"==typeof s.extensions[0]?o.extensions=[s.extensions]:o.extensions=s.extensions),this.ptr.addChild(o),u.length>0){i.push(t),t=u,u=null,this.ptr=o,o=null;continue}u=null}else if(n.isEnum(s))o=new r.Enum(this,this.ptr,s.name,s.options,s.syntax),s.values.forEach((function(e){o.addChild(new r.Enum.Value(this,o,e.name,e.id))}),this),this.ptr.addChild(o);else if(n.isService(s))o=new r.Service(this,this.ptr,s.name,s.options),Object.keys(s.rpc).forEach((function(e){var t=s.rpc[e];o.addChild(new r.Service.RPCMethod(this,o,e,t.request,t.response,!!t.request_stream,!!t.response_stream,t.options))}),this),this.ptr.addChild(o);else{if(!n.isExtend(s))throw Error("not a valid definition: "+JSON.stringify(s));if(o=this.ptr.resolve(s.ref,!0))s.fields.forEach((function(t){if(null!==o.getChild(0|t.id))throw Error("duplicate extended field id in "+o.name+": "+t.id);if(o.extensions){var n=!1;if(o.extensions.forEach((function(e){t.id>=e[0]&&t.id<=e[1]&&(n=!0)})),!n)throw Error("illegal extended field id in "+o.name+": "+t.id+" (not within valid ranges)")}var i=t.name;this.options.convertFieldsToCamelCase&&(i=e.Util.toCamelCase(i));var s=new r.Message.ExtensionField(this,o,t.rule,t.type,this.ptr.fqn()+"."+i,t.id,t.options),a=new r.Extension(this,this.ptr,t.name,s);s.extension=a,this.ptr.addChild(a),o.addChild(s)}),this);else if(!/\.?google\.protobuf\./.test(s.ref))throw Error("extended message "+s.ref+" is not defined")}s=null,o=null}t=null,this.ptr=this.ptr.parent}return this.resolved=!1,this.result=null,this},i.import=function(t,r){var n="/";if("string"==typeof r){if(e.Util.IS_NODE&&(r=j.resolve(r)),!0===this.files[r])return this.reset();this.files[r]=!0}else if("object"==typeof r){var i,s=r.root;if(e.Util.IS_NODE&&(s=j.resolve(s)),(s.indexOf("\\")>=0||r.file.indexOf("\\")>=0)&&(n="\\"),i=e.Util.IS_NODE?j.join(s,r.file):s+n+r.file,!0===this.files[i])return this.reset();this.files[i]=!0}if(t.imports&&t.imports.length>0){var o,a=!1;"object"==typeof r?(this.importRoot=r.root,a=!0,o=this.importRoot,r=r.file,(o.indexOf("\\")>=0||r.indexOf("\\")>=0)&&(n="\\")):"string"==typeof r?this.importRoot?o=this.importRoot:r.indexOf("/")>=0?""===(o=r.replace(/\/[^\/]*$/,""))&&(o="/"):r.indexOf("\\")>=0?(o=r.replace(/\\[^\\]*$/,""),n="\\"):o=".":o=null;for(var u=0;u<t.imports.length;u++)if("string"==typeof t.imports[u]){if(!o)throw Error("cannot determine import root");var l=t.imports[u];if("google/protobuf/descriptor.proto"===l)continue;if(l=e.Util.IS_NODE?j.join(o,l):o+n+l,!0===this.files[l])continue;/\.proto$/i.test(l)&&!e.DotProto&&(l=l.replace(/\.proto$/,".json"));var c=e.Util.fetch(l);if(null===c)throw Error("failed to import '"+l+"' in '"+r+"': file not found");/\.json$/i.test(l)?this.import(JSON.parse(c+""),l):this.import(e.DotProto.Parser.parse(c),l)}else r?/\.(\w+)$/.test(r)?this.import(t.imports[u],r.replace(/^(.+)\.(\w+)$/,(function(e,t,r){return t+"_import"+u+"."+r}))):this.import(t.imports[u],r+"_import"+u):this.import(t.imports[u]);a&&(this.importRoot=null)}t.package&&this.define(t.package),t.syntax&&function e(t){t.messages&&t.messages.forEach((function(r){r.syntax=t.syntax,e(r)})),t.enums&&t.enums.forEach((function(e){e.syntax=t.syntax}))}(t);var h=this.ptr;return t.options&&Object.keys(t.options).forEach((function(e){h.options[e]=t.options[e]})),t.messages&&(this.create(t.messages),this.ptr=h),t.enums&&(this.create(t.enums),this.ptr=h),t.services&&(this.create(t.services),this.ptr=h),t.extends&&this.create(t.extends),this.reset()},i.resolveAll=function(){var n;if(null==this.ptr||"object"==typeof this.ptr.type)return this;if(this.ptr instanceof r.Namespace)this.ptr.children.forEach((function(e){this.ptr=e,this.resolveAll()}),this);else if(this.ptr instanceof r.Message.Field){if(t.TYPE.test(this.ptr.type))this.ptr.type=e.TYPES[this.ptr.type];else{if(!t.TYPEREF.test(this.ptr.type))throw Error("illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);if(!(n=(this.ptr instanceof r.Message.ExtensionField?this.ptr.extension.parent:this.ptr.parent).resolve(this.ptr.type,!0)))throw Error("unresolvable type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);if(this.ptr.resolvedType=n,n instanceof r.Enum){if(this.ptr.type=e.TYPES.enum,"proto3"===this.ptr.syntax&&"proto3"!==n.syntax)throw Error("proto3 message cannot reference proto2 enum")}else{if(!(n instanceof r.Message))throw Error("illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);this.ptr.type=n.isGroup?e.TYPES.group:e.TYPES.message}}if(this.ptr.map){if(!t.TYPE.test(this.ptr.keyType))throw Error("illegal key type for map field in "+this.ptr.toString(!0)+": "+this.ptr.keyType);this.ptr.keyType=e.TYPES[this.ptr.keyType]}"proto3"===this.ptr.syntax&&this.ptr.repeated&&void 0===this.ptr.options.packed&&-1!==e.PACKABLE_WIRE_TYPES.indexOf(this.ptr.type.wireType)&&(this.ptr.options.packed=!0)}else if(this.ptr instanceof e.Reflect.Service.Method){if(!(this.ptr instanceof e.Reflect.Service.RPCMethod))throw Error("illegal service type in "+this.ptr.toString(!0));if(!((n=this.ptr.parent.resolve(this.ptr.requestName,!0))&&n instanceof e.Reflect.Message))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.requestName);if(this.ptr.resolvedRequestType=n,!((n=this.ptr.parent.resolve(this.ptr.responseName,!0))&&n instanceof e.Reflect.Message))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.responseName);this.ptr.resolvedResponseType=n}else if(!(this.ptr instanceof e.Reflect.Message.OneOf||this.ptr instanceof e.Reflect.Extension||this.ptr instanceof e.Reflect.Enum.Value))throw Error("illegal object in namespace: "+typeof this.ptr+": "+this.ptr);return this.reset()},i.build=function(e){if(this.reset(),this.resolved||(this.resolveAll(),this.resolved=!0,this.result=null),null===this.result&&(this.result=this.ns.build()),!e)return this.result;for(var t="string"==typeof e?e.split("."):e,r=this.result,n=0;n<t.length;n++){if(!r[t[n]]){r=null;break}r=r[t[n]]}return r},i.lookup=function(e,t){return e?this.ns.resolve(e,t):this.ns},i.toString=function(){return"Builder"},n.Message=function(){},n.Enum=function(){},n.Service=function(){},n}(i,i.Lang,i.Reflect),i.Map=function(e,t){var r=function(e,r){if(!e.map)throw Error("field is not a map");if(this.field=e,this.keyElem=new t.Element(e.keyType,null,!0,e.syntax),this.valueElem=new t.Element(e.type,e.resolvedType,!1,e.syntax),this.map={},Object.defineProperty(this,"size",{get:function(){return Object.keys(this.map).length}}),r)for(var n=Object.keys(r),i=0;i<n.length;i++){var s=this.keyElem.valueFromString(n[i]),o=this.valueElem.verifyValue(r[n[i]]);this.map[this.keyElem.valueToString(s)]={key:s,value:o}}},n=r.prototype;function i(e){var t=0;return{next:function(){return t<e.length?{done:!1,value:e[t++]}:{done:!0}}}}return n.clear=function(){this.map={}},n.delete=function(e){var t=this.keyElem.valueToString(this.keyElem.verifyValue(e)),r=t in this.map;return delete this.map[t],r},n.entries=function(){for(var e,t=[],r=Object.keys(this.map),n=0;n<r.length;n++)t.push([(e=this.map[r[n]]).key,e.value]);return i(t)},n.keys=function(){for(var e=[],t=Object.keys(this.map),r=0;r<t.length;r++)e.push(this.map[t[r]].key);return i(e)},n.values=function(){for(var e=[],t=Object.keys(this.map),r=0;r<t.length;r++)e.push(this.map[t[r]].value);return i(e)},n.forEach=function(e,t){for(var r,n=Object.keys(this.map),i=0;i<n.length;i++)e.call(t,(r=this.map[n[i]]).value,r.key,this)},n.set=function(e,t){var r=this.keyElem.verifyValue(e),n=this.valueElem.verifyValue(t);return this.map[this.keyElem.valueToString(r)]={key:r,value:n},this},n.get=function(e){var t=this.keyElem.valueToString(this.keyElem.verifyValue(e));if(t in this.map)return this.map[t].value},n.has=function(e){return this.keyElem.valueToString(this.keyElem.verifyValue(e))in this.map},r}(0,i.Reflect),i.newBuilder=function(e){return void 0===(e=e||{}).convertFieldsToCamelCase&&(e.convertFieldsToCamelCase=i.convertFieldsToCamelCase),void 0===e.populateAccessors&&(e.populateAccessors=i.populateAccessors),new i.Builder(e)},i.loadJson=function(e,t,r){return("string"==typeof t||t&&"string"==typeof t.file&&"string"==typeof t.root)&&(r=t,t=null),t&&"object"==typeof t||(t=i.newBuilder()),"string"==typeof e&&(e=JSON.parse(e)),t.import(e,r),t.resolveAll(),t},i.loadJsonFile=function(e,t,r){if(t&&"object"==typeof t?(r=t,t=null):t&&"function"==typeof t||(t=null),t)return i.Util.fetch("string"==typeof e?e:e.root+"/"+e.file,(function(n){if(null!==n)try{t(null,i.loadJson(JSON.parse(n),r,e))}catch(e){t(e)}else t(Error("Failed to fetch file"))}));var n=i.Util.fetch("object"==typeof e?e.root+"/"+e.file:e);return null===n?null:i.loadJson(JSON.parse(n),r,e)},i}))})).newBuilder({}).import({package:"push_server.messages2",syntax:"proto2",options:{objc_class_prefix:"AVIM"},messages:[{name:"JsonObjectMessage",syntax:"proto2",fields:[{rule:"required",type:"string",name:"data",id:1}]},{name:"UnreadTuple",syntax:"proto2",fields:[{rule:"required",type:"string",name:"cid",id:1},{rule:"required",type:"int32",name:"unread",id:2},{rule:"optional",type:"string",name:"mid",id:3},{rule:"optional",type:"int64",name:"timestamp",id:4},{rule:"optional",type:"string",name:"from",id:5},{rule:"optional",type:"string",name:"data",id:6},{rule:"optional",type:"int64",name:"patchTimestamp",id:7},{rule:"optional",type:"bool",name:"mentioned",id:8},{rule:"optional",type:"bytes",name:"binaryMsg",id:9},{rule:"optional",type:"int32",name:"convType",id:10}]},{name:"LogItem",syntax:"proto2",fields:[{rule:"optional",type:"string",name:"from",id:1},{rule:"optional",type:"string",name:"data",id:2},{rule:"optional",type:"int64",name:"timestamp",id:3},{rule:"optional",type:"string",name:"msgId",id:4},{rule:"optional",type:"int64",name:"ackAt",id:5},{rule:"optional",type:"int64",name:"readAt",id:6},{rule:"optional",type:"int64",name:"patchTimestamp",id:7},{rule:"optional",type:"bool",name:"mentionAll",id:8},{rule:"repeated",type:"string",name:"mentionPids",id:9},{rule:"optional",type:"bool",name:"bin",id:10},{rule:"optional",type:"int32",name:"convType",id:11}]},{name:"ConvMemberInfo",syntax:"proto2",fields:[{rule:"optional",type:"string",name:"pid",id:1},{rule:"optional",type:"string",name:"role",id:2},{rule:"optional",type:"string",name:"infoId",id:3}]},{name:"DataCommand",syntax:"proto2",fields:[{rule:"repeated",type:"string",name:"ids",id:1},{rule:"repeated",type:"JsonObjectMessage",name:"msg",id:2},{rule:"optional",type:"bool",name:"offline",id:3}]},{name:"SessionCommand",syntax:"proto2",fields:[{rule:"optional",type:"int64",name:"t",id:1},{rule:"optional",type:"string",name:"n",id:2},{rule:"optional",type:"string",name:"s",id:3},{rule:"optional",type:"string",name:"ua",id:4},{rule:"optional",type:"bool",name:"r",id:5},{rule:"optional",type:"string",name:"tag",id:6},{rule:"optional",type:"string",name:"deviceId",id:7},{rule:"repeated",type:"string",name:"sessionPeerIds",id:8},{rule:"repeated",type:"string",name:"onlineSessionPeerIds",id:9},{rule:"optional",type:"string",name:"st",id:10},{rule:"optional",type:"int32",name:"stTtl",id:11},{rule:"optional",type:"int32",name:"code",id:12},{rule:"optional",type:"string",name:"reason",id:13},{rule:"optional",type:"string",name:"deviceToken",id:14},{rule:"optional",type:"bool",name:"sp",id:15},{rule:"optional",type:"string",name:"detail",id:16},{rule:"optional",type:"int64",name:"lastUnreadNotifTime",id:17},{rule:"optional",type:"int64",name:"lastPatchTime",id:18},{rule:"optional",type:"int64",name:"configBitmap",id:19}]},{name:"ErrorCommand",syntax:"proto2",fields:[{rule:"required",type:"int32",name:"code",id:1},{rule:"required",type:"string",name:"reason",id:2},{rule:"optional",type:"int32",name:"appCode",id:3},{rule:"optional",type:"string",name:"detail",id:4},{rule:"repeated",type:"string",name:"pids",id:5},{rule:"optional",type:"string",name:"appMsg",id:6}]},{name:"DirectCommand",syntax:"proto2",fields:[{rule:"optional",type:"string",name:"msg",id:1},{rule:"optional",type:"string",name:"uid",id:2},{rule:"optional",type:"string",name:"fromPeerId",id:3},{rule:"optional",type:"int64",name:"timestamp",id:4},{rule:"optional",type:"bool",name:"offline",id:5},{rule:"optional",type:"bool",name:"hasMore",id:6},{rule:"repeated",type:"string",name:"toPeerIds",id:7},{rule:"optional",type:"bool",name:"r",id:10},{rule:"optional",type:"string",name:"cid",id:11},{rule:"optional",type:"string",name:"id",id:12},{rule:"optional",type:"bool",name:"transient",id:13},{rule:"optional",type:"string",name:"dt",id:14},{rule:"optional",type:"string",name:"roomId",id:15},{rule:"optional",type:"string",name:"pushData",id:16},{rule:"optional",type:"bool",name:"will",id:17},{rule:"optional",type:"int64",name:"patchTimestamp",id:18},{rule:"optional",type:"bytes",name:"binaryMsg",id:19},{rule:"repeated",type:"string",name:"mentionPids",id:20},{rule:"optional",type:"bool",name:"mentionAll",id:21},{rule:"optional",type:"int32",name:"convType",id:22}]},{name:"AckCommand",syntax:"proto2",fields:[{rule:"optional",type:"int32",name:"code",id:1},{rule:"optional",type:"string",name:"reason",id:2},{rule:"optional",type:"string",name:"mid",id:3},{rule:"optional",type:"string",name:"cid",id:4},{rule:"optional",type:"int64",name:"t",id:5},{rule:"optional",type:"string",name:"uid",id:6},{rule:"optional",type:"int64",name:"fromts",id:7},{rule:"optional",type:"int64",name:"tots",id:8},{rule:"optional",type:"string",name:"type",id:9},{rule:"repeated",type:"string",name:"ids",id:10},{rule:"optional",type:"int32",name:"appCode",id:11},{rule:"optional",type:"string",name:"appMsg",id:12}]},{name:"UnreadCommand",syntax:"proto2",fields:[{rule:"repeated",type:"UnreadTuple",name:"convs",id:1},{rule:"optional",type:"int64",name:"notifTime",id:2}]},{name:"ConvCommand",syntax:"proto2",fields:[{rule:"repeated",type:"string",name:"m",id:1},{rule:"optional",type:"bool",name:"transient",id:2},{rule:"optional",type:"bool",name:"unique",id:3},{rule:"optional",type:"string",name:"cid",id:4},{rule:"optional",type:"string",name:"cdate",id:5},{rule:"optional",type:"string",name:"initBy",id:6},{rule:"optional",type:"string",name:"sort",id:7},{rule:"optional",type:"int32",name:"limit",id:8},{rule:"optional",type:"int32",name:"skip",id:9},{rule:"optional",type:"int32",name:"flag",id:10},{rule:"optional",type:"int32",name:"count",id:11},{rule:"optional",type:"string",name:"udate",id:12},{rule:"optional",type:"int64",name:"t",id:13},{rule:"optional",type:"string",name:"n",id:14},{rule:"optional",type:"string",name:"s",id:15},{rule:"optional",type:"bool",name:"statusSub",id:16},{rule:"optional",type:"bool",name:"statusPub",id:17},{rule:"optional",type:"int32",name:"statusTTL",id:18},{rule:"optional",type:"string",name:"uniqueId",id:19},{rule:"optional",type:"string",name:"targetClientId",id:20},{rule:"optional",type:"int64",name:"maxReadTimestamp",id:21},{rule:"optional",type:"int64",name:"maxAckTimestamp",id:22},{rule:"optional",type:"bool",name:"queryAllMembers",id:23},{rule:"repeated",type:"MaxReadTuple",name:"maxReadTuples",id:24},{rule:"repeated",type:"string",name:"cids",id:25},{rule:"optional",type:"ConvMemberInfo",name:"info",id:26},{rule:"optional",type:"bool",name:"tempConv",id:27},{rule:"optional",type:"int32",name:"tempConvTTL",id:28},{rule:"repeated",type:"string",name:"tempConvIds",id:29},{rule:"repeated",type:"string",name:"allowedPids",id:30},{rule:"repeated",type:"ErrorCommand",name:"failedPids",id:31},{rule:"optional",type:"string",name:"next",id:40},{rule:"optional",type:"JsonObjectMessage",name:"results",id:100},{rule:"optional",type:"JsonObjectMessage",name:"where",id:101},{rule:"optional",type:"JsonObjectMessage",name:"attr",id:103},{rule:"optional",type:"JsonObjectMessage",name:"attrModified",id:104}]},{name:"RoomCommand",syntax:"proto2",fields:[{rule:"optional",type:"string",name:"roomId",id:1},{rule:"optional",type:"string",name:"s",id:2},{rule:"optional",type:"int64",name:"t",id:3},{rule:"optional",type:"string",name:"n",id:4},{rule:"optional",type:"bool",name:"transient",id:5},{rule:"repeated",type:"string",name:"roomPeerIds",id:6},{rule:"optional",type:"string",name:"byPeerId",id:7}]},{name:"LogsCommand",syntax:"proto2",fields:[{rule:"optional",type:"string",name:"cid",id:1},{rule:"optional",type:"int32",name:"l",id:2},{rule:"optional",type:"int32",name:"limit",id:3},{rule:"optional",type:"int64",name:"t",id:4},{rule:"optional",type:"int64",name:"tt",id:5},{rule:"optional",type:"string",name:"tmid",id:6},{rule:"optional",type:"string",name:"mid",id:7},{rule:"optional",type:"string",name:"checksum",id:8},{rule:"optional",type:"bool",name:"stored",id:9},{rule:"optional",type:"QueryDirection",name:"direction",id:10,options:{default:"OLD"}},{rule:"optional",type:"bool",name:"tIncluded",id:11},{rule:"optional",type:"bool",name:"ttIncluded",id:12},{rule:"optional",type:"int32",name:"lctype",id:13},{rule:"repeated",type:"LogItem",name:"logs",id:105}],enums:[{name:"QueryDirection",syntax:"proto2",values:[{name:"OLD",id:1},{name:"NEW",id:2}]}]},{name:"RcpCommand",syntax:"proto2",fields:[{rule:"optional",type:"string",name:"id",id:1},{rule:"optional",type:"string",name:"cid",id:2},{rule:"optional",type:"int64",name:"t",id:3},{rule:"optional",type:"bool",name:"read",id:4},{rule:"optional",type:"string",name:"from",id:5}]},{name:"ReadTuple",syntax:"proto2",fields:[{rule:"required",type:"string",name:"cid",id:1},{rule:"optional",type:"int64",name:"timestamp",id:2},{rule:"optional",type:"string",name:"mid",id:3}]},{name:"MaxReadTuple",syntax:"proto2",fields:[{rule:"optional",type:"string",name:"pid",id:1},{rule:"optional",type:"int64",name:"maxAckTimestamp",id:2},{rule:"optional",type:"int64",name:"maxReadTimestamp",id:3}]},{name:"ReadCommand",syntax:"proto2",fields:[{rule:"optional",type:"string",name:"cid",id:1},{rule:"repeated",type:"string",name:"cids",id:2},{rule:"repeated",type:"ReadTuple",name:"convs",id:3}]},{name:"PresenceCommand",syntax:"proto2",fields:[{rule:"optional",type:"StatusType",name:"status",id:1},{rule:"repeated",type:"string",name:"sessionPeerIds",id:2},{rule:"optional",type:"string",name:"cid",id:3}]},{name:"ReportCommand",syntax:"proto2",fields:[{rule:"optional",type:"bool",name:"initiative",id:1},{rule:"optional",type:"string",name:"type",id:2},{rule:"optional",type:"string",name:"data",id:3}]},{name:"PatchItem",syntax:"proto2",fields:[{rule:"optional",type:"string",name:"cid",id:1},{rule:"optional",type:"string",name:"mid",id:2},{rule:"optional",type:"int64",name:"timestamp",id:3},{rule:"optional",type:"bool",name:"recall",id:4},{rule:"optional",type:"string",name:"data",id:5},{rule:"optional",type:"int64",name:"patchTimestamp",id:6},{rule:"optional",type:"string",name:"from",id:7},{rule:"optional",type:"bytes",name:"binaryMsg",id:8},{rule:"optional",type:"bool",name:"mentionAll",id:9},{rule:"repeated",type:"string",name:"mentionPids",id:10},{rule:"optional",type:"int64",name:"patchCode",id:11},{rule:"optional",type:"string",name:"patchReason",id:12}]},{name:"PatchCommand",syntax:"proto2",fields:[{rule:"repeated",type:"PatchItem",name:"patches",id:1},{rule:"optional",type:"int64",name:"lastPatchTime",id:2}]},{name:"PubsubCommand",syntax:"proto2",fields:[{rule:"optional",type:"string",name:"cid",id:1},{rule:"repeated",type:"string",name:"cids",id:2},{rule:"optional",type:"string",name:"topic",id:3},{rule:"optional",type:"string",name:"subtopic",id:4},{rule:"repeated",type:"string",name:"topics",id:5},{rule:"repeated",type:"string",name:"subtopics",id:6},{rule:"optional",type:"JsonObjectMessage",name:"results",id:7}]},{name:"BlacklistCommand",syntax:"proto2",fields:[{rule:"optional",type:"string",name:"srcCid",id:1},{rule:"repeated",type:"string",name:"toPids",id:2},{rule:"optional",type:"string",name:"srcPid",id:3},{rule:"repeated",type:"string",name:"toCids",id:4},{rule:"optional",type:"int32",name:"limit",id:5},{rule:"optional",type:"string",name:"next",id:6},{rule:"repeated",type:"string",name:"blockedPids",id:8},{rule:"repeated",type:"string",name:"blockedCids",id:9},{rule:"repeated",type:"string",name:"allowedPids",id:10},{rule:"repeated",type:"ErrorCommand",name:"failedPids",id:11},{rule:"optional",type:"int64",name:"t",id:12},{rule:"optional",type:"string",name:"n",id:13},{rule:"optional",type:"string",name:"s",id:14}]},{name:"GenericCommand",syntax:"proto2",fields:[{rule:"optional",type:"CommandType",name:"cmd",id:1},{rule:"optional",type:"OpType",name:"op",id:2},{rule:"optional",type:"string",name:"appId",id:3},{rule:"optional",type:"string",name:"peerId",id:4},{rule:"optional",type:"int32",name:"i",id:5},{rule:"optional",type:"string",name:"installationId",id:6},{rule:"optional",type:"int32",name:"priority",id:7},{rule:"optional",type:"int32",name:"service",id:8},{rule:"optional",type:"int64",name:"serverTs",id:9},{rule:"optional",type:"int64",name:"clientTs",id:10},{rule:"optional",type:"int32",name:"notificationType",id:11},{rule:"optional",type:"DataCommand",name:"dataMessage",id:101},{rule:"optional",type:"SessionCommand",name:"sessionMessage",id:102},{rule:"optional",type:"ErrorCommand",name:"errorMessage",id:103},{rule:"optional",type:"DirectCommand",name:"directMessage",id:104},{rule:"optional",type:"AckCommand",name:"ackMessage",id:105},{rule:"optional",type:"UnreadCommand",name:"unreadMessage",id:106},{rule:"optional",type:"ReadCommand",name:"readMessage",id:107},{rule:"optional",type:"RcpCommand",name:"rcpMessage",id:108},{rule:"optional",type:"LogsCommand",name:"logsMessage",id:109},{rule:"optional",type:"ConvCommand",name:"convMessage",id:110},{rule:"optional",type:"RoomCommand",name:"roomMessage",id:111},{rule:"optional",type:"PresenceCommand",name:"presenceMessage",id:112},{rule:"optional",type:"ReportCommand",name:"reportMessage",id:113},{rule:"optional",type:"PatchCommand",name:"patchMessage",id:114},{rule:"optional",type:"PubsubCommand",name:"pubsubMessage",id:115},{rule:"optional",type:"BlacklistCommand",name:"blacklistMessage",id:116}]}],enums:[{name:"CommandType",syntax:"proto2",values:[{name:"session",id:0},{name:"conv",id:1},{name:"direct",id:2},{name:"ack",id:3},{name:"rcp",id:4},{name:"unread",id:5},{name:"logs",id:6},{name:"error",id:7},{name:"login",id:8},{name:"data",id:9},{name:"room",id:10},{name:"read",id:11},{name:"presence",id:12},{name:"report",id:13},{name:"echo",id:14},{name:"loggedin",id:15},{name:"logout",id:16},{name:"loggedout",id:17},{name:"patch",id:18},{name:"pubsub",id:19},{name:"blacklist",id:20},{name:"goaway",id:21}]},{name:"OpType",syntax:"proto2",values:[{name:"open",id:1},{name:"add",id:2},{name:"remove",id:3},{name:"close",id:4},{name:"opened",id:5},{name:"closed",id:6},{name:"query",id:7},{name:"query_result",id:8},{name:"conflict",id:9},{name:"added",id:10},{name:"removed",id:11},{name:"refresh",id:12},{name:"refreshed",id:13},{name:"start",id:30},{name:"started",id:31},{name:"joined",id:32},{name:"members_joined",id:33},{name:"left",id:39},{name:"members_left",id:40},{name:"results",id:42},{name:"count",id:43},{name:"result",id:44},{name:"update",id:45},{name:"updated",id:46},{name:"mute",id:47},{name:"unmute",id:48},{name:"status",id:49},{name:"members",id:50},{name:"max_read",id:51},{name:"is_member",id:52},{name:"member_info_update",id:53},{name:"member_info_updated",id:54},{name:"member_info_changed",id:55},{name:"join",id:80},{name:"invite",id:81},{name:"leave",id:82},{name:"kick",id:83},{name:"reject",id:84},{name:"invited",id:85},{name:"kicked",id:86},{name:"upload",id:100},{name:"uploaded",id:101},{name:"subscribe",id:120},{name:"subscribed",id:121},{name:"unsubscribe",id:122},{name:"unsubscribed",id:123},{name:"is_subscribed",id:124},{name:"modify",id:150},{name:"modified",id:151},{name:"block",id:170},{name:"unblock",id:171},{name:"blocked",id:172},{name:"unblocked",id:173},{name:"members_blocked",id:174},{name:"members_unblocked",id:175},{name:"check_block",id:176},{name:"check_result",id:177},{name:"add_shutup",id:180},{name:"remove_shutup",id:181},{name:"query_shutup",id:182},{name:"shutup_added",id:183},{name:"shutup_removed",id:184},{name:"shutup_result",id:185},{name:"shutuped",id:186},{name:"unshutuped",id:187},{name:"members_shutuped",id:188},{name:"members_unshutuped",id:189},{name:"check_shutup",id:190}]},{name:"StatusType",syntax:"proto2",values:[{name:"on",id:1},{name:"off",id:2}]}],isNamespace:!0}).build();const{JsonObjectMessage:U,UnreadTuple:F,LogItem:B,DataCommand:V,SessionCommand:Y,ErrorCommand:q,DirectCommand:$,AckCommand:z,UnreadCommand:W,ConvCommand:G,RoomCommand:J,LogsCommand:Z,RcpCommand:H,ReadTuple:X,MaxReadTuple:K,ReadCommand:Q,PresenceCommand:ee,ReportCommand:te,GenericCommand:re,BlacklistCommand:ne,PatchCommand:ie,PatchItem:se,ConvMemberInfo:oe,CommandType:ae,OpType:ue,StatusType:le}=D.push_server.messages2;var ce=Object.freeze({__proto__:null,JsonObjectMessage:U,UnreadTuple:F,LogItem:B,DataCommand:V,SessionCommand:Y,ErrorCommand:q,DirectCommand:$,AckCommand:z,UnreadCommand:W,ConvCommand:G,RoomCommand:J,LogsCommand:Z,RcpCommand:H,ReadTuple:X,MaxReadTuple:K,ReadCommand:Q,PresenceCommand:ee,ReportCommand:te,GenericCommand:re,BlacklistCommand:ne,PatchCommand:ie,PatchItem:se,ConvMemberInfo:oe,CommandType:ae,OpType:ue,StatusType:le}),he=i((function(e){var t=Object.prototype.hasOwnProperty,r="~";function n(){}function i(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function s(e,t,n,s,o){if("function"!=typeof n)throw new TypeError("The listener must be a function");var a=new i(n,s||e,o),u=r?r+t:t;return e._events[u]?e._events[u].fn?e._events[u]=[e._events[u],a]:e._events[u].push(a):(e._events[u]=a,e._eventsCount++),e}function o(e,t){0==--e._eventsCount?e._events=new n:delete e._events[t]}function a(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(r=!1)),a.prototype.eventNames=function(){var e,n,i=[];if(0===this._eventsCount)return i;for(n in e=this._events)t.call(e,n)&&i.push(r?n.slice(1):n);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(e)):i},a.prototype.listeners=function(e){var t=r?r+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,s=n.length,o=new Array(s);i<s;i++)o[i]=n[i].fn;return o},a.prototype.listenerCount=function(e){var t=r?r+e:e,n=this._events[t];return n?n.fn?1:n.length:0},a.prototype.emit=function(e,t,n,i,s,o){var a=r?r+e:e;if(!this._events[a])return!1;var u,l,c=this._events[a],h=arguments.length;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),h){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,i),!0;case 5:return c.fn.call(c.context,t,n,i,s),!0;case 6:return c.fn.call(c.context,t,n,i,s,o),!0}for(l=1,u=new Array(h-1);l<h;l++)u[l-1]=arguments[l];c.fn.apply(c.context,u)}else{var f,d=c.length;for(l=0;l<d;l++)switch(c[l].once&&this.removeListener(e,c[l].fn,void 0,!0),h){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,t);break;case 3:c[l].fn.call(c[l].context,t,n);break;case 4:c[l].fn.call(c[l].context,t,n,i);break;default:if(!u)for(f=1,u=new Array(h-1);f<h;f++)u[f-1]=arguments[f];c[l].fn.apply(c[l].context,u)}}return!0},a.prototype.on=function(e,t,r){return s(this,e,t,r,!1)},a.prototype.once=function(e,t,r){return s(this,e,t,r,!0)},a.prototype.removeListener=function(e,t,n,i){var s=r?r+e:e;if(!this._events[s])return this;if(!t)return o(this,s),this;var a=this._events[s];if(a.fn)a.fn!==t||i&&!a.once||n&&a.context!==n||o(this,s);else{for(var u=0,l=[],c=a.length;u<c;u++)(a[u].fn!==t||i&&!a[u].once||n&&a[u].context!==n)&&l.push(a[u]);l.length?this._events[s]=1===l.length?l[0]:l:o(this,s)}return this},a.prototype.removeAllListeners=function(e){var t;return e?(t=r?r+e:e,this._events[t]&&o(this,t)):(this._events=new n,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=r,a.EventEmitter=a,e.exports=a})),fe=1e3,de=6e4,pe=60*de,me=24*pe,ge=function(e,t){t=t||{};var r=typeof e;if("string"===r&&e.length>0)return function(e){if((e=String(e)).length>100)return;var t=/^((?:\d+)?\-?\d?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(!t)return;var r=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return 315576e5*r;case"weeks":case"week":case"w":return 6048e5*r;case"days":case"day":case"d":return r*me;case"hours":case"hour":case"hrs":case"hr":case"h":return r*pe;case"minutes":case"minute":case"mins":case"min":case"m":return r*de;case"seconds":case"second":case"secs":case"sec":case"s":return r*fe;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return r;default:return}}(e);if("number"===r&&!1===isNaN(e))return t.long?function(e){var t=Math.abs(e);if(t>=me)return ye(e,t,me,"day");if(t>=pe)return ye(e,t,pe,"hour");if(t>=de)return ye(e,t,de,"minute");if(t>=fe)return ye(e,t,fe,"second");return e+" ms"}(e):function(e){var t=Math.abs(e);if(t>=me)return Math.round(e/me)+"d";if(t>=pe)return Math.round(e/pe)+"h";if(t>=de)return Math.round(e/de)+"m";if(t>=fe)return Math.round(e/fe)+"s";return e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))};function ye(e,t,r,n){var i=t>=1.5*r;return Math.round(e/r)+" "+n+(i?"s":"")}var ve=function(e){function t(e){for(var t=0,n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return r.colors[Math.abs(t)%r.colors.length]}function r(e){var s;function o(){if(o.enabled){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];var i=o,a=Number(new Date),u=a-(s||a);i.diff=u,i.prev=s,i.curr=a,s=a,t[0]=r.coerce(t[0]),"string"!=typeof t[0]&&t.unshift("%O");var l=0;t[0]=t[0].replace(/%([a-zA-Z%])/g,(function(e,n){if("%%"===e)return e;l++;var s=r.formatters[n];if("function"==typeof s){var o=t[l];e=s.call(i,o),t.splice(l,1),l--}return e})),r.formatArgs.call(i,t);var c=i.log||r.log;c.apply(i,t)}}return o.namespace=e,o.enabled=r.enabled(e),o.useColors=r.useColors(),o.color=t(e),o.destroy=n,o.extend=i,"function"==typeof r.init&&r.init(o),r.instances.push(o),o}function n(){var e=r.instances.indexOf(this);return-1!==e&&(r.instances.splice(e,1),!0)}function i(e,t){return r(this.namespace+(void 0===t?":":t)+e)}return r.debug=r,r.default=r,r.coerce=function(e){if(e instanceof Error)return e.stack||e.message;return e},r.disable=function(){r.enable("")},r.enable=function(e){var t;r.save(e),r.names=[],r.skips=[];var n=("string"==typeof e?e:"").split(/[\s,]+/),i=n.length;for(t=0;t<i;t++)n[t]&&("-"===(e=n[t].replace(/\*/g,".*?"))[0]?r.skips.push(new RegExp("^"+e.substr(1)+"$")):r.names.push(new RegExp("^"+e+"$")));for(t=0;t<r.instances.length;t++){var s=r.instances[t];s.enabled=r.enabled(s.namespace)}},r.enabled=function(e){if("*"===e[e.length-1])return!0;var t,n;for(t=0,n=r.skips.length;t<n;t++)if(r.skips[t].test(e))return!1;for(t=0,n=r.names.length;t<n;t++)if(r.names[t].test(e))return!0;return!1},r.humanize=ge,Object.keys(e).forEach((function(t){r[t]=e[t]})),r.instances=[],r.names=[],r.skips=[],r.formatters={},r.selectColor=t,r.enable(r.load()),r},be=i((function(e,r){function n(e){return(n="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)}r.log=function(){var e;return"object"===("undefined"==typeof console?"undefined":n(console))&&console.log&&(e=console).log.apply(e,arguments)},r.formatArgs=function(t){if(t[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+t[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;var r="color: "+this.color;t.splice(1,0,r,"color: inherit");var n=0,i=0;t[0].replace(/%[a-zA-Z%]/g,(function(e){"%%"!==e&&(n++,"%c"===e&&(i=n))})),t.splice(i,0,r)},r.save=function(e){try{e?r.storage.setItem("debug",e):r.storage.removeItem("debug")}catch(e){}},r.load=function(){var e;try{e=r.storage.getItem("debug")}catch(e){}!e&&void 0!==t&&"env"in t&&(e=t.env.DEBUG);return e},r.useColors=function(){if("undefined"!=typeof window&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if("undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;return"undefined"!=typeof document&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||"undefined"!=typeof window&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},r.storage=function(){try{return localStorage}catch(e){}}(),r.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],e.exports=ve(r),e.exports.formatters.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}));be.log,be.formatArgs,be.save,be.load,be.useColors,be.storage,be.colors;var we=function(e,t){var r=-1,n=e.length;for(t||(t=Array(n));++r<n;)t[r]=e[r];return t},_e=Math.floor,Ee=Math.random;var Te=function(e,t){return e+_e(Ee()*(t-e+1))};var Se=function(e,t){var r=-1,n=e.length,i=n-1;for(t=void 0===t?n:t;++r<t;){var s=Te(r,i),o=e[s];e[s]=e[r],e[r]=o}return e.length=t,e};var Ae=function(e){return Se(we(e))};var Ie=function(e,t){for(var r=-1,n=null==e?0:e.length,i=Array(n);++r<n;)i[r]=t(e[r],r,e);return i};var Ce=function(e,t){return Ie(t,(function(t){return e[t]}))};var Oe=function(e,t){for(var r=-1,n=Array(e);++r<e;)n[r]=t(r);return n},Me="object"==typeof r&&r&&r.Object===Object&&r,Re="object"==typeof self&&self&&self.Object===Object&&self,Pe=Me||Re||Function("return this")(),Ne=Pe.Symbol,Le=Object.prototype,xe=Le.hasOwnProperty,ke=Le.toString,je=Ne?Ne.toStringTag:void 0;var De=function(e){var t=xe.call(e,je),r=e[je];try{e[je]=void 0;var n=!0}catch(e){}var i=ke.call(e);return n&&(t?e[je]=r:delete e[je]),i},Ue=Object.prototype.toString;var Fe=function(e){return Ue.call(e)},Be=Ne?Ne.toStringTag:void 0;var Ve=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":Be&&Be in Object(e)?De(e):Fe(e)};var Ye=function(e){return null!=e&&"object"==typeof e};var qe=function(e){return Ye(e)&&"[object Arguments]"==Ve(e)},$e=Object.prototype,ze=$e.hasOwnProperty,We=$e.propertyIsEnumerable,Ge=qe(function(){return arguments}())?qe:function(e){return Ye(e)&&ze.call(e,"callee")&&!We.call(e,"callee")},Je=Array.isArray;var Ze=function(){return!1},He=i((function(e,t){var r=t&&!t.nodeType&&t,n=r&&e&&!e.nodeType&&e,i=n&&n.exports===r?Pe.Buffer:void 0,s=(i?i.isBuffer:void 0)||Ze;e.exports=s})),Xe=/^(?:0|[1-9]\d*)$/;var Ke=function(e,t){var r=typeof e;return!!(t=null==t?9007199254740991:t)&&("number"==r||"symbol"!=r&&Xe.test(e))&&e>-1&&e%1==0&&e<t};var Qe=function(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=9007199254740991},et={};et["[object Float32Array]"]=et["[object Float64Array]"]=et["[object Int8Array]"]=et["[object Int16Array]"]=et["[object Int32Array]"]=et["[object Uint8Array]"]=et["[object Uint8ClampedArray]"]=et["[object Uint16Array]"]=et["[object Uint32Array]"]=!0,et["[object Arguments]"]=et["[object Array]"]=et["[object ArrayBuffer]"]=et["[object Boolean]"]=et["[object DataView]"]=et["[object Date]"]=et["[object Error]"]=et["[object Function]"]=et["[object Map]"]=et["[object Number]"]=et["[object Object]"]=et["[object RegExp]"]=et["[object Set]"]=et["[object String]"]=et["[object WeakMap]"]=!1;var tt=function(e){return Ye(e)&&Qe(e.length)&&!!et[Ve(e)]};var rt=function(e){return function(t){return e(t)}},nt=i((function(e,t){var r=t&&!t.nodeType&&t,n=r&&e&&!e.nodeType&&e,i=n&&n.exports===r&&Me.process,s=function(){try{var e=n&&n.require&&n.require("util").types;return e||i&&i.binding&&i.binding("util")}catch(e){}}();e.exports=s})),it=nt&&nt.isTypedArray,st=it?rt(it):tt,ot=Object.prototype.hasOwnProperty;var at=function(e,t){var r=Je(e),n=!r&&Ge(e),i=!r&&!n&&He(e),s=!r&&!n&&!i&&st(e),o=r||n||i||s,a=o?Oe(e.length,String):[],u=a.length;for(var l in e)!t&&!ot.call(e,l)||o&&("length"==l||i&&("offset"==l||"parent"==l)||s&&("buffer"==l||"byteLength"==l||"byteOffset"==l)||Ke(l,u))||a.push(l);return a},ut=Object.prototype;var lt=function(e){var t=e&&e.constructor;return e===("function"==typeof t&&t.prototype||ut)};var ct=function(e,t){return function(r){return e(t(r))}},ht=ct(Object.keys,Object),ft=Object.prototype.hasOwnProperty;var dt=function(e){if(!lt(e))return ht(e);var t=[];for(var r in Object(e))ft.call(e,r)&&"constructor"!=r&&t.push(r);return t};var pt=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)};var mt=function(e){if(!pt(e))return!1;var t=Ve(e);return"[object Function]"==t||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t};var gt=function(e){return null!=e&&Qe(e.length)&&!mt(e)};var yt=function(e){return gt(e)?at(e):dt(e)};var vt=function(e){return null==e?[]:Ce(e,yt(e))};var bt=function(e){return Se(vt(e))};var wt=function(e){return(Je(e)?Ae:bt)(e)};function _t(e,t,r,n,i){var s={};return Object.keys(n).forEach((function(e){s[e]=n[e]})),s.enumerable=!!s.enumerable,s.configurable=!!s.configurable,("value"in s||s.initializer)&&(s.writable=!0),s=r.slice().reverse().reduce((function(r,n){return n(e,t,r)||r}),s),i&&void 0!==s.initializer&&(s.value=s.initializer?s.initializer.call(i):void 0,s.initializer=void 0),void 0===s.initializer&&(Object.defineProperty(e,t,s),s=null),s}var Et=i((function(e,t){var r;r={VERSION:"2.4.0",Result:{SUCCEEDED:1,NOTRANSITION:2,CANCELLED:3,PENDING:4},Error:{INVALID_TRANSITION:100,PENDING_TRANSITION:200,INVALID_CALLBACK:300},WILDCARD:"*",ASYNC:"async",create:function(e,t){var n="string"==typeof e.initial?{state:e.initial}:e.initial,i=e.terminal||e.final,s=t||e.target||{},o=e.events||[],a=e.callbacks||{},u={},l={},c=function(e){var t=Array.isArray(e.from)?e.from:e.from?[e.from]:[r.WILDCARD];u[e.name]=u[e.name]||{};for(var n=0;n<t.length;n++)l[t[n]]=l[t[n]]||[],l[t[n]].push(e.name),u[e.name][t[n]]=e.to||t[n];e.to&&(l[e.to]=l[e.to]||[])};n&&(n.event=n.event||"startup",c({name:n.event,from:"none",to:n.state}));for(var h=0;h<o.length;h++)c(o[h]);for(var f in u)u.hasOwnProperty(f)&&(s[f]=r.buildEvent(f,u[f]));for(var f in a)a.hasOwnProperty(f)&&(s[f]=a[f]);return s.current="none",s.is=function(e){return Array.isArray(e)?e.indexOf(this.current)>=0:this.current===e},s.can=function(e){return!this.transition&&void 0!==u[e]&&(u[e].hasOwnProperty(this.current)||u[e].hasOwnProperty(r.WILDCARD))},s.cannot=function(e){return!this.can(e)},s.transitions=function(){return(l[this.current]||[]).concat(l[r.WILDCARD]||[])},s.isFinished=function(){return this.is(i)},s.error=e.error||function(e,t,r,n,i,s,o){throw o||s},s.states=function(){return Object.keys(l).sort()},n&&!n.defer&&s[n.event](),s},doCallback:function(e,t,n,i,s,o){if(t)try{return t.apply(e,[n,i,s].concat(o))}catch(t){return e.error(n,i,s,o,r.Error.INVALID_CALLBACK,"an exception occurred in a caller-provided callback function",t)}},beforeAnyEvent:function(e,t,n,i,s){return r.doCallback(e,e.onbeforeevent,t,n,i,s)},afterAnyEvent:function(e,t,n,i,s){return r.doCallback(e,e.onafterevent||e.onevent,t,n,i,s)},leaveAnyState:function(e,t,n,i,s){return r.doCallback(e,e.onleavestate,t,n,i,s)},enterAnyState:function(e,t,n,i,s){return r.doCallback(e,e.onenterstate||e.onstate,t,n,i,s)},changeState:function(e,t,n,i,s){return r.doCallback(e,e.onchangestate,t,n,i,s)},beforeThisEvent:function(e,t,n,i,s){return r.doCallback(e,e["onbefore"+t],t,n,i,s)},afterThisEvent:function(e,t,n,i,s){return r.doCallback(e,e["onafter"+t]||e["on"+t],t,n,i,s)},leaveThisState:function(e,t,n,i,s){return r.doCallback(e,e["onleave"+n],t,n,i,s)},enterThisState:function(e,t,n,i,s){return r.doCallback(e,e["onenter"+i]||e["on"+i],t,n,i,s)},beforeEvent:function(e,t,n,i,s){if(!1===r.beforeThisEvent(e,t,n,i,s)||!1===r.beforeAnyEvent(e,t,n,i,s))return!1},afterEvent:function(e,t,n,i,s){r.afterThisEvent(e,t,n,i,s),r.afterAnyEvent(e,t,n,i,s)},leaveState:function(e,t,n,i,s){var o=r.leaveThisState(e,t,n,i,s),a=r.leaveAnyState(e,t,n,i,s);return!1!==o&&!1!==a&&(r.ASYNC===o||r.ASYNC===a?r.ASYNC:void 0)},enterState:function(e,t,n,i,s){r.enterThisState(e,t,n,i,s),r.enterAnyState(e,t,n,i,s)},buildEvent:function(e,t){return function(){var n=this.current,i=t[n]||(t[r.WILDCARD]!=r.WILDCARD?t[r.WILDCARD]:n)||n,s=Array.prototype.slice.call(arguments);if(this.transition)return this.error(e,n,i,s,r.Error.PENDING_TRANSITION,"event "+e+" inappropriate because previous transition did not complete");if(this.cannot(e))return this.error(e,n,i,s,r.Error.INVALID_TRANSITION,"event "+e+" inappropriate in current state "+this.current);if(!1===r.beforeEvent(this,e,n,i,s))return r.Result.CANCELLED;if(n===i)return r.afterEvent(this,e,n,i,s),r.Result.NOTRANSITION;var o=this;this.transition=function(){return o.transition=null,o.current=i,r.enterState(o,e,n,i,s),r.changeState(o,e,n,i,s),r.afterEvent(o,e,n,i,s),r.Result.SUCCEEDED},this.transition.cancel=function(){o.transition=null,r.afterEvent(o,e,n,i,s)};var a=r.leaveState(this,e,n,i,s);return!1===a?(this.transition=null,r.Result.CANCELLED):r.ASYNC===a?r.Result.PENDING:this.transition?this.transition():void 0}}},e.exports&&(t=e.exports=r),t.StateMachine=r}));Et.StateMachine;const Tt={},St=e=>{const t=Tt[e];if(void 0===t)throw new Error(`${e} adapter is not configured`);return t},At=e=>{Object.assign(Tt,e)};var It=ct(Object.getPrototypeOf,Object),Ct=Function.prototype,Ot=Object.prototype,Mt=Ct.toString,Rt=Ot.hasOwnProperty,Pt=Mt.call(Object);var Nt=function(e){if(!Ye(e)||"[object Object]"!=Ve(e))return!1;var t=It(e);if(null===t)return!0;var r=Rt.call(t,"constructor")&&t.constructor;return"function"==typeof r&&r instanceof r&&Mt.call(r)==Pt},Lt="undefined"!=typeof global?global:"undefined"!=typeof window?window:{};const xt=Symbol("expired"),kt=be("LC:Expirable");class jt{constructor(e,t){this.originalValue=e,"number"==typeof t&&(this.expiredAt=Date.now()+t)}get value(){const e=this.expiredAt&&this.expiredAt<=Date.now();return e&&kt(`expired: ${this.originalValue}`),e?xt:this.originalValue}}jt.EXPIRED=xt;const Dt=be("LC:Cache");class Ut{constructor(e="anonymous"){this.name=e,this._map={}}get(e){const t=this._map[e];if(t){const{value:r}=t;if(r!==jt.EXPIRED)return Dt("[%s] hit: %s",this.name,e),r;delete this._map[e]}return Dt(`[${this.name}] missed: ${e}`),null}set(e,t,r){Dt("[%s] set: %s %d",this.name,e,r),this._map[e]=new jt(t,r)}}const Ft={enable:(e="LC*")=>be.enable(e),disable:be.disable},Bt=e=>{const t=new Promise(e[0]);return 1===e.length?t:t.catch(()=>Bt(e.slice(1)))},Vt=e=>t=>(e(t),t),Yt=e=>e?"string"==typeof e||"number"==typeof e?new Date(e):"Date"===e.__type&&e.iso?new Date(e.iso):"function"==typeof e.toNumber?new Date(e.toNumber()):e:e,qt=e=>e&&e.getTime?e.getTime():void 0,$t=e=>e?"Date"===e.__type&&e.iso?new Date(e.iso):Array.isArray(e)?e.map($t):Nt(e)?Object.keys(e).reduce((t,r)=>({...t,[r]:$t(e[r])}),{}):e:e,zt=e=>e instanceof Date?{__type:"Date",iso:e.toJSON()}:Array.isArray(e)?e.map(zt):Nt(e)?Object.keys(e).reduce((t,r)=>({...t,[r]:zt(e[r])}),{}):e,Wt=(e,t)=>Object.keys(t).reduce((r,n)=>{const i=e[n]||n;return Object.assign(r,{[i]:t[n]})},{}),Gt=Lt.navigator&&Lt.navigator.userAgent&&-1!==Lt.navigator.userAgent.indexOf("MSIE 10."),Jt=(e,t)=>e[t]||(e.__proto__?Jt(e.__proto__,t):void 0),Zt=(e,t)=>Array.from(new Set([...e,...t])),Ht=(e,t)=>{return Array.from((r=new Set(t),new Set(e.filter(e=>!r.has(e)))));var r},Xt=new WeakMap,Kt=e=>(Xt.has(e)||Xt.set(e,{}),Xt.get(e)),Qt=(e,t)=>{if(!Nt(e))return e;const r={...e};return Object.keys(r).forEach(e=>{const n=r[e];n===t?delete r[e]:r[e]=Qt(n,t)}),r},er=e=>{return t=JSON.parse(JSON.stringify(e)),Qt(t,null);var t},tr=e=>Array.isArray(e)?e:null==e?[]:[e],rr=(e,t,r)=>{const n=t.split("."),i=n.pop();let s=e;return n.forEach(e=>{void 0===s[e]&&(s[e]={}),s=s[e]}),s[i]=r,e},nr="object"==typeof wx&&"function"==typeof wx.connectSocket,ir=e=>(t,r,n)=>{const i=n.value;if(i.length)throw new Error("throttled function should not accept any arguments");return{...n,value(){let{throttleMeta:t}=Kt(this);t||(t={},Kt(this).throttleMeta=t);let{[r]:n}=t;n||(n={},t[r]=n);const{previouseTimestamp:s=0,timeout:o}=n,a=Date.now(),u=e-(a-s);u<=0?(t[r].previouseTimestamp=a,i.apply(this)):o||(n.timeout=setTimeout(()=>{n.previouseTimestamp=Date.now(),delete n.timeout,i.apply(this)},u))}}};var sr;const or=be("LC:WebSocketPlus"),ar="disconnect",ur="reconnect",lr="retry",cr="schedule",hr="offline",fr="online",dr=e=>Math.min(1e3*2**e,3e5),pr=(e,t,r)=>({...r,value:function(...e){return this.checkConnectionAvailability(t),r.value.call(this,...e)}});let mr=(_t((sr=class extends he{get urls(){return this._urls}set urls(e){this._urls=tr(e)}constructor(e,t){super(),this.init(),this._protocol=t,Promise.resolve("function"==typeof e?e():e).then(tr).then(e=>(this._urls=e,this._open())).then(()=>{this.__postponeTimeoutTimer=this._postponeTimeoutTimer.bind(this),Lt.addEventListener&&(this.__pause=()=>{this.can("pause")&&this.pause()},this.__resume=()=>{this.can("resume")&&this.resume()},Lt.addEventListener("offline",this.__pause),Lt.addEventListener("online",this.__resume)),this.open()}).catch(this.throw.bind(this))}_open(){return this._createWs(this._urls,this._protocol).then(e=>{const[t,...r]=this._urls;return this._urls=[...r,t],e})}_createWs(e,t){return Bt(e.map(e=>(r,n)=>{or(`connect [${e}] ${t}`);const i=St("WebSocket"),s=t?new i(e,t):new i(e);s.binaryType=this.binaryType||"arraybuffer",s.onopen=()=>r(s),s.onclose=t=>t instanceof Error?n(t):n(new Error(`Failed to connect [${e}]`)),s.onerror=s.onclose})).then(e=>(this._ws=e,this._ws.onclose=this._handleClose.bind(this),this._ws.onmessage=this._handleMessage.bind(this),e))}_destroyWs(){const e=this._ws;e&&(e.onopen=null,e.onclose=null,e.onerror=null,e.onmessage=null,this._ws=null,e.close())}onbeforeevent(e,t,r,...n){or(`${e}: ${t} -> ${r} %o`,n)}onopen(){this.emit("open")}onconnected(){this._startConnectionKeeper()}onleaveconnected(e,t,r){this._stopConnectionKeeper(),this._destroyWs(),"offline"!==r&&"disconnected"!==r||this.emit(ar)}onpause(){this.emit(hr)}onbeforeresume(){this.emit(fr)}onreconnect(){this.emit(ur)}ondisconnected(e,t,r,n=0){const i=t===hr?0:dr.call(null,n);or(`schedule attempt=${n} delay=${i}`),this.emit(cr,n,i),this.__scheduledRetry&&clearTimeout(this.__scheduledRetry),this.__scheduledRetry=setTimeout(()=>{this.is("disconnected")&&this.retry(n)},i)}onretry(e,t,r,n=0){this.emit(lr,n),this._open().then(()=>this.can("reconnect")&&this.reconnect(),()=>this.can("fail")&&this.fail(n+1))}onerror(e,t,r,n){this.emit("error",n)}onclose(){Lt.removeEventListener&&(this.__pause&&Lt.removeEventListener("offline",this.__pause),this.__resume&&Lt.removeEventListener("online",this.__resume))}checkConnectionAvailability(e="API"){if(!this.is("connected")){const t=this.current;throw console.warn(`${e} should not be called when the connection is ${t}`),(this.is("disconnected")||this.is("reconnecting"))&&console.warn("disconnect and reconnect event should be handled to avoid such calls."),new Error("Connection unavailable")}}_ping(){or("ping");try{this.ping()}catch(e){console.warn(`websocket ping error: ${e.message}`)}}ping(){this._ws.ping?this._ws.ping():console.warn("The WebSocket implement does not support sending ping frame.\n Override ping method to use application defined ping/pong mechanism.")}_postponeTimeoutTimer(){or("_postponeTimeoutTimer"),this._clearTimeoutTimers(),this._timeoutTimer=setTimeout(()=>{or("timeout"),this.disconnect()},38e4)}_clearTimeoutTimers(){this._timeoutTimer&&clearTimeout(this._timeoutTimer)}_startConnectionKeeper(){or("start connection keeper"),this._heartbeatTimer=setInterval(this._ping.bind(this),18e4);const e=this._ws.addListener||this._ws.addEventListener;e?(e.call(this._ws,"message",this.__postponeTimeoutTimer),e.call(this._ws,"pong",this.__postponeTimeoutTimer),this._postponeTimeoutTimer()):or("connection keeper disabled due to the lack of #addEventListener.")}_stopConnectionKeeper(){or("stop connection keeper");const e=this._ws.removeListener||this._ws.removeEventListener;e&&(e.call(this._ws,"message",this.__postponeTimeoutTimer),e.call(this._ws,"pong",this.__postponeTimeoutTimer),this._clearTimeoutTimers()),this._heartbeatTimer&&clearInterval(this._heartbeatTimer)}_handleClose(e){or(`ws closed [${e.code}] ${e.reason}`),this.isFinished()||this.handleClose(e)}handleClose(){this.disconnect()}send(e){or("send",e),this._ws.send(e)}_handleMessage(e){or("message",e.data),this.handleMessage(e.data)}handleMessage(e){this.emit("message",e)}}).prototype,"_ping",[pr],Object.getOwnPropertyDescriptor(sr.prototype,"_ping"),sr.prototype),_t(sr.prototype,"send",[pr],Object.getOwnPropertyDescriptor(sr.prototype,"send"),sr.prototype),sr);Et.create({target:mr.prototype,initial:{state:"initialized",event:"init",defer:!0},terminal:"closed",events:[{name:"open",from:"initialized",to:"connected"},{name:"disconnect",from:"connected",to:"disconnected"},{name:"retry",from:"disconnected",to:"reconnecting"},{name:"fail",from:"reconnecting",to:"disconnected"},{name:"reconnect",from:"reconnecting",to:"connected"},{name:"pause",from:["connected","disconnected","reconnecting"],to:"offline"},{},{name:"resume",from:"offline",to:"disconnected"},{name:"close",from:["connected","disconnected","reconnecting","offline"],to:"closed"},{name:"throw",from:"*",to:"error"}]});const gr=Object.freeze({1e3:{name:"CLOSE_NORMAL"},1006:{name:"CLOSE_ABNORMAL"},4100:{name:"APP_NOT_AVAILABLE",message:"App not exists or realtime message service is disabled."},4102:{name:"SIGNATURE_FAILED",message:"Login signature mismatch."},4103:{name:"INVALID_LOGIN",message:"Malformed clientId."},4105:{name:"SESSION_REQUIRED",message:"Message sent before session opened."},4107:{name:"READ_TIMEOUT"},4108:{name:"LOGIN_TIMEOUT"},4109:{name:"FRAME_TOO_LONG"},4110:{name:"INVALID_ORIGIN",message:"Access denied by domain whitelist."},4111:{name:"SESSION_CONFLICT"},4112:{name:"SESSION_TOKEN_EXPIRED"},4113:{name:"APP_QUOTA_EXCEEDED",message:"The daily active users limit exceeded."},4116:{name:"MESSAGE_SENT_QUOTA_EXCEEDED",message:"Command sent too fast."},4200:{name:"INTERNAL_ERROR",message:"Internal error, please contact LeanCloud for support."},4301:{name:"CONVERSATION_API_FAILED",message:"Upstream Conversatoin API failed, see error.detail for details."},4302:{name:"CONVERSATION_SIGNATURE_FAILED",message:"Conversation action signature mismatch."},4303:{name:"CONVERSATION_NOT_FOUND"},4304:{name:"CONVERSATION_FULL"},4305:{name:"CONVERSATION_REJECTED_BY_APP",message:"Conversation action rejected by hook."},4306:{name:"CONVERSATION_UPDATE_FAILED"},4307:{name:"CONVERSATION_READ_ONLY"},4308:{name:"CONVERSATION_NOT_ALLOWED"},4309:{name:"CONVERSATION_UPDATE_REJECTED",message:"Conversation update rejected because the client is not a member."},4310:{name:"CONVERSATION_QUERY_FAILED",message:"Conversation query failed because it is too expansive."},4311:{name:"CONVERSATION_LOG_FAILED"},4312:{name:"CONVERSATION_LOG_REJECTED",message:"Message query rejected because the client is not a member of the conversation."},4313:{name:"SYSTEM_CONVERSATION_REQUIRED"},4314:{name:"NORMAL_CONVERSATION_REQUIRED"},4315:{name:"CONVERSATION_BLACKLISTED",message:"Blacklisted in the conversation."},4316:{name:"TRANSIENT_CONVERSATION_REQUIRED"},4317:{name:"CONVERSATION_MEMBERSHIP_REQUIRED"},4318:{name:"CONVERSATION_API_QUOTA_EXCEEDED",message:"LeanCloud API quota exceeded. You may upgrade your plan."},4323:{name:"TEMPORARY_CONVERSATION_EXPIRED",message:"Temporary conversation expired or does not exist."},4401:{name:"INVALID_MESSAGING_TARGET",message:"Conversation does not exist or client is not a member."},4402:{name:"MESSAGE_REJECTED_BY_APP",message:"Message rejected by hook."},4403:{name:"MESSAGE_OWNERSHIP_REQUIRED"},4404:{name:"MESSAGE_NOT_FOUND"},4405:{name:"MESSAGE_UPDATE_REJECTED_BY_APP",message:"Message update rejected by hook."},4406:{name:"MESSAGE_EDIT_DISABLED"},4407:{name:"MESSAGE_RECALL_DISABLED"},5130:{name:"OWNER_PROMOTION_NOT_ALLOWED",message:"Updating a member's role to owner is not allowed."}}),yr=Object.freeze(Object.keys(gr).reduce((e,t)=>Object.assign(e,{[gr[t].name]:Number(t)}),{})),vr=({code:e,reason:t,appCode:r,detail:n,error:i})=>{let s=t||n||i,o=t;!s&&gr[e]&&(({name:o}=gr[e]),s=gr[e].message||o),s||(s=`Unknow Error: ${e}`);const a=new Error(s);return Object.assign(a,{code:e,appCode:r,detail:n,name:o})},br=be("LC:Connection"),wr=Symbol("expire");class _r extends mr{constructor(e,{format:t,version:r}){br("initializing Connection"),super(e,`lc.${t}.${r}`),this._protocolFormat=t,this._commands={},this._serialId=0}async send(e,t=!0){let r,n,i;if(t){if((e=>!(e.cmd===ae.direct||e.cmd===ae.session&&e.op===ue.open||e.cmd===ae.conv&&(e.op===ue.start||e.op===ue.update||e.op===ue.members)))(e)){r=e.toArrayBuffer();const t=vt(this._commands).find(({buffer:t,command:n})=>n.cmd===e.cmd&&n.op===e.op&&((e,t)=>{if(!e||!t)return!1;if(e.byteLength!==t.byteLength)return!1;const r=new Uint8Array(e),n=new Uint8Array(t);return!r.some((e,t)=>e!==n[t])})(t,r));if(t)return console.warn(`Duplicated command [cmd:${e.cmd} op:${e.op}] is throttled.`),t.promise}this._serialId+=1,n=this._serialId,e.i=n}if(br.enabled&&br("↑ %O sent",er(e)),"proto2base64"===this._protocolFormat?i=e.toBase64():e.toArrayBuffer&&(i=e.toArrayBuffer()),!i)throw new TypeError(`${e} is not a GenericCommand`);if(super.send(i),!t)return;const s=new Promise((t,i)=>{this._commands[n]={command:e,buffer:r,resolve:t,reject:i,timeout:setTimeout(()=>{this._commands[n]&&(br.enabled&&br("✗ %O timeout",er(e)),i(vr({error:`Command Timeout [cmd:${e.cmd} op:${e.op}]`,name:"COMMAND_TIMEOUT"})),delete this._commands[n])},2e4)}});return this._commands[n].promise=s,s}handleMessage(e){let t;try{t=re.decode(e),br.enabled&&br("↓ %O received",er(t))}catch(t){return void console.warn("Decode message failed:",t.message,e)}const r=t.i;if(r)this._commands[r]?(clearTimeout(this._commands[r].timeout),t.cmd===ae.error?this._commands[r].reject(vr(t.errorMessage)):this._commands[r].resolve(t),delete this._commands[r]):console.warn(`Unexpected command received with serialId [${r}],\n which have timed out or never been requested.`);else switch(t.cmd){case ae.error:return void this.emit("error",vr(t.errorMessage));case ae.goaway:return void this.emit(wr);default:this.emit("message",t)}}ping(){return this.send(new re({cmd:ae.echo})).catch(e=>br("ping failed:",e))}}var Er=i((function(e){var t;e.exports.timeout=function(e,r){var n,i=new t;return Promise.race([e,new Promise((function(e,t){n=setTimeout((function(){t(i)}),r)}))]).then((function(e){return clearTimeout(n),e}),(function(e){throw clearTimeout(n),e}))};(t=e.exports.TimeoutError=function(){Error.call(this),this.stack=Error().stack,this.message="Timeout"}).prototype=Object.create(Error.prototype),t.prototype.name="TimeoutError"})),Tr=Er.timeout;Er.TimeoutError;const Sr=be("LC:request");var Ar=({method:e="GET",url:t,query:r,headers:n,data:i,timeout:s})=>{let o=t;if(r){const e=Object.keys(r).map(e=>{const t=r[e];if(void 0===t)return;const n=Nt(t)?JSON.stringify(t):t;return`${encodeURIComponent(e)}=${encodeURIComponent(n)}`}).filter(e=>e).join("&");o=`${o}?${e}`}Sr("Req: %O %O %O",e,o,{headers:n,data:i});const a=St("request")(o,{method:e,headers:n,data:i}).then(e=>{if(!1===e.ok){const t=vr(e.data);throw t.response=e,t}return Sr("Res: %O %O %O",o,e.status,e.data),e.data}).catch(e=>{throw e.response&&Sr("Error: %O %O %O",o,e.response.status,e.response.data),e});return s?Tr(a,s):a};const Ir=(e,t)=>{e&&e.forEach(e=>{try{e(t)}catch(t){throw e._pluginName&&(t.message+=`[${e._pluginName}]`),t}})},Cr=e=>t=>tr(e).reduce((e,t)=>e.then((e=>t=>{const{constructor:r}=t;return Promise.resolve(t).then(e).then(Vt(n=>null==n?console.warn(`Middleware[${e._pluginName||"anonymous plugin"}:${e.name||"anonymous middleware"}] param/return types not match. It returns ${n} while a ${t.constructor.name} expected.`):n instanceof r?0:console.warn(`Middleware[${e._pluginName||"anonymous plugin"}:${e.name||"anonymous middleware"}] param/return types not match. It returns a ${n.constructor.name} while a ${t.constructor.name} expected.`)))})(t)).catch(e=>{throw t._pluginName&&(e.message+=`[${t._pluginName}]`),e}),Promise.resolve(t)),Or=(e,t)=>tr(e).reduce((e,r)=>e.then(e=>!1!==e&&r(...t)).catch(e=>{throw r._pluginName&&(e.message+=`[${r._pluginName}]`),e}),Promise.resolve(!0));const Mr=be("LC:Realtime"),Rr=new Ut("push-router"),Pr={};class Nr extends he{constructor({plugins:e,...r}){Mr("initializing Realtime %s %O","5.0.0-rc.7",r),super();const{appId:n}=r;if("string"!=typeof n)throw new TypeError(`appId [${n}] is not a string`);if(Pr[n])throw new Error(`App [${n}] is already initialized.`);if(Pr[n]=!0,"string"!=typeof r.appKey)throw new TypeError(`appKey [${r.appKey}] is not a string`);if((e=>"-MdYXbMMI"!==e.slice(-9))(n)&&!r.server)throw new TypeError("server option is required for apps from CN region");this._options={appId:void 0,appKey:void 0,noBinary:!1,ssl:!0,RTMServerName:void 0!==t?t.env.RTM_SERVER_NAME:void 0,...r},this._cache=new Ut("endpoints");const i=Kt(this);i.clients=new Set,i.pendingClients=new Set;const s=[...tr(Nr.__preRegisteredPlugins),...tr(e)];Mr("Using plugins %o",s.map(e=>e.name)),this._plugins=s.reduce((e,t)=>(Object.keys(t).forEach(r=>{({}).hasOwnProperty.call(t,r)&&"name"!==r&&(t.name&&tr(t[r]).forEach(e=>{e._pluginName=t.name}),e[r]=tr(e[r]).concat(t[r]))}),e),{}),Ir(this._plugins.onRealtimeCreate,this)}async _request({method:e,url:t,version:r="1.1",path:n,query:i,headers:s,data:o}){let a=t;if(!a){const{appId:e,server:t}=this._options,{api:i}=await this.constructor._getServerUrls({appId:e,server:t});a=`${i}/${r}${n}`}return Ar({url:a,method:e,query:i,headers:{"X-LC-Id":this._options.appId,"X-LC-Key":this._options.appKey,...s},data:o})}_open(){if(this._openPromise)return this._openPromise;let e="protobuf2";this._options.noBinary&&(e="proto2base64");const t={format:e,version:3};return this._openPromise=new Promise((e,r)=>{Mr("No connection established, create a new one.");const n=new _r(()=>this._getRTMServers(this._options),t);n.on("open",()=>e(n)).on("error",e=>{delete this._openPromise,r(e)}).on(wr,async()=>{Mr("Connection expired. Refresh endpoints."),this._cache.set("endpoints",null,0),n.urls=await this._getRTMServers(this._options),n.disconnect()}).on("message",this._dispatchCommand.bind(this)),[ar,ur,lr,cr,hr,fr].forEach(e=>n.on(e,(...t)=>{Mr(`${e} event emitted. %o`,t),this.emit(e,...t),e!==ur&&Kt(this).clients.forEach(r=>{r.emit(e,...t)})})),n.handleClose=function(e){[yr.APP_NOT_AVAILABLE,yr.INVALID_LOGIN,yr.INVALID_ORIGIN].some(t=>t===e.code)?this.throw(vr(e)):this.disconnect()},Kt(this).connection=n}),this._openPromise}async _getRTMServers(e){if(e.RTMServers)return wt(tr(e.RTMServers));let t;const r=this._cache.get("endpoints");if(r)t=r;else{t=await this.constructor._fetchRTMServers(e);const{server:r,secondary:n,ttl:i}=t;if("string"!=typeof r&&"string"!=typeof n&&"number"!=typeof i)throw new Error(`malformed RTM route response: ${JSON.stringify(t)}`);this._cache.set("endpoints",t,1e3*t.ttl)}return Mr("endpoint info: %O",t),[t.server,t.secondary]}static async _getServerUrls({appId:e,server:t}){if(Mr("fetch server urls"),t)return"string"!=typeof t?t:{RTMRouter:t,api:t};const r=Rr.get(e);if(r)return r;return Ar({url:"https://app-router.com/2/route",query:{appId:e},timeout:2e4}).then(Vt(Mr)).then(({rtm_router_server:t,api_server:r,ttl:n=3600})=>{if(!t)throw new Error("rtm router not exists");const i={RTMRouter:`https://${t}`,api:`https://${r}`};return Rr.set(e,i,1e3*n),i}).catch(()=>{const t=e.slice(0,8).toLowerCase();return{RTMRouter:`https://${t}.rtm.lncldglobal.com`,api:`https://${t}.api.lncldglobal.com`}})}static _fetchRTMServers({appId:e,ssl:t,server:r,RTMServerName:n}){return Mr("fetch endpoint info"),this._getServerUrls({appId:e,server:r}).then(Vt(Mr)).then(({RTMRouter:r})=>Ar({url:`${r}/v1/route`,query:{appId:e,secure:t,features:nr?"wechat":void 0,server:n,_t:Date.now()},timeout:2e4}).then(Vt(Mr)))}_close(){this._openPromise&&this._openPromise.then(e=>e.close()),delete this._openPromise}retry(){const{connection:e}=Kt(this);if(!e)throw new Error("no connection established");if(e.cannot("retry"))throw new Error(`retrying not allowed when not disconnected. the connection is now ${e.current}`);return e.retry()}pause(){const{connection:e}=Kt(this);e&&e.can("pause")&&e.pause()}resume(){const{connection:e}=Kt(this);e&&e.can("resume")&&e.resume()}_registerPending(e){Kt(this).pendingClients.add(e)}_deregisterPending(e){Kt(this).pendingClients.delete(e)}_register(e){Kt(this).clients.add(e)}_deregister(e){const t=Kt(this);t.clients.delete(e),t.clients.size+t.pendingClients.size===0&&this._close()}_dispatchCommand(e){return Or(this._plugins.beforeCommandDispatch,[e,this]).then(t=>!!t&&Mr("[WARN] Unexpected message received: %O",er(e)))}}const Lr=Promise;for(var xr=i((function(e){var t="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(t){var r=new Uint8Array(16);e.exports=function(){return t(r),r}}else{var n=new Array(16);e.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),n[t]=e>>>((3&t)<<3)&255;return n}}})),kr=[],jr=0;jr<256;++jr)kr[jr]=(jr+256).toString(16).substr(1);var Dr=function(e,t){var r=t||0,n=kr;return[n[e[r++]],n[e[r++]],n[e[r++]],n[e[r++]],"-",n[e[r++]],n[e[r++]],"-",n[e[r++]],n[e[r++]],"-",n[e[r++]],n[e[r++]],"-",n[e[r++]],n[e[r++]],n[e[r++]],n[e[r++]],n[e[r++]],n[e[r++]]].join("")};var Ur=function(e,t,r){var n=t&&r||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var i=(e=e||{}).random||(e.rng||xr)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,t)for(var s=0;s<16;++s)t[n+s]=i[s];return t||Dr(i)},Fr=i((function(e,t){!function(){for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",r=new Uint8Array(256),n=0;n<e.length;n++)r[e.charCodeAt(n)]=n;t.encode=function(t){var r,n=new Uint8Array(t),i=n.length,s="";for(r=0;r<i;r+=3)s+=e[n[r]>>2],s+=e[(3&n[r])<<4|n[r+1]>>4],s+=e[(15&n[r+1])<<2|n[r+2]>>6],s+=e[63&n[r+2]];return i%3==2?s=s.substring(0,s.length-1)+"=":i%3==1&&(s=s.substring(0,s.length-2)+"=="),s},t.decode=function(e){var t,n,i,s,o,a=.75*e.length,u=e.length,l=0;"="===e[e.length-1]&&(a--,"="===e[e.length-2]&&a--);var c=new ArrayBuffer(a),h=new Uint8Array(c);for(t=0;t<u;t+=4)n=r[e.charCodeAt(t)],i=r[e.charCodeAt(t+1)],s=r[e.charCodeAt(t+2)],o=r[e.charCodeAt(t+3)],h[l++]=n<<2|i>>4,h[l++]=(15&i)<<4|s>>2,h[l++]=(3&s)<<6|63&o;return c}}()})),Br=Fr.encode,Vr=Fr.decode;var Yr=function(){this.__data__=[],this.size=0};var qr=function(e,t){return e===t||e!=e&&t!=t};var $r=function(e,t){for(var r=e.length;r--;)if(qr(e[r][0],t))return r;return-1},zr=Array.prototype.splice;var Wr=function(e){var t=this.__data__,r=$r(t,e);return!(r<0)&&(r==t.length-1?t.pop():zr.call(t,r,1),--this.size,!0)};var Gr=function(e){var t=this.__data__,r=$r(t,e);return r<0?void 0:t[r][1]};var Jr=function(e){return $r(this.__data__,e)>-1};var Zr=function(e,t){var r=this.__data__,n=$r(r,e);return n<0?(++this.size,r.push([e,t])):r[n][1]=t,this};function Hr(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}Hr.prototype.clear=Yr,Hr.prototype.delete=Wr,Hr.prototype.get=Gr,Hr.prototype.has=Jr,Hr.prototype.set=Zr;var Xr=Hr;var Kr=function(){this.__data__=new Xr,this.size=0};var Qr=function(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r};var en=function(e){return this.__data__.get(e)};var tn,rn=function(e){return this.__data__.has(e)},nn=Pe["__core-js_shared__"],sn=(tn=/[^.]+$/.exec(nn&&nn.keys&&nn.keys.IE_PROTO||""))?"Symbol(src)_1."+tn:"";var on=function(e){return!!sn&&sn in e},an=Function.prototype.toString;var un=function(e){if(null!=e){try{return an.call(e)}catch(e){}try{return e+""}catch(e){}}return""},ln=/^\[object .+?Constructor\]$/,cn=Function.prototype,hn=Object.prototype,fn=cn.toString,dn=hn.hasOwnProperty,pn=RegExp("^"+fn.call(dn).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var mn=function(e){return!(!pt(e)||on(e))&&(mt(e)?pn:ln).test(un(e))};var gn=function(e,t){return null==e?void 0:e[t]};var yn=function(e,t){var r=gn(e,t);return mn(r)?r:void 0},vn=yn(Pe,"Map"),bn=yn(Object,"create");var wn=function(){this.__data__=bn?bn(null):{},this.size=0};var _n=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},En=Object.prototype.hasOwnProperty;var Tn=function(e){var t=this.__data__;if(bn){var r=t[e];return"__lodash_hash_undefined__"===r?void 0:r}return En.call(t,e)?t[e]:void 0},Sn=Object.prototype.hasOwnProperty;var An=function(e){var t=this.__data__;return bn?void 0!==t[e]:Sn.call(t,e)};var In=function(e,t){var r=this.__data__;return this.size+=this.has(e)?0:1,r[e]=bn&&void 0===t?"__lodash_hash_undefined__":t,this};function Cn(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}Cn.prototype.clear=wn,Cn.prototype.delete=_n,Cn.prototype.get=Tn,Cn.prototype.has=An,Cn.prototype.set=In;var On=Cn;var Mn=function(){this.size=0,this.__data__={hash:new On,map:new(vn||Xr),string:new On}};var Rn=function(e){var t=typeof e;return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e};var Pn=function(e,t){var r=e.__data__;return Rn(t)?r["string"==typeof t?"string":"hash"]:r.map};var Nn=function(e){var t=Pn(this,e).delete(e);return this.size-=t?1:0,t};var Ln=function(e){return Pn(this,e).get(e)};var xn=function(e){return Pn(this,e).has(e)};var kn=function(e,t){var r=Pn(this,e),n=r.size;return r.set(e,t),this.size+=r.size==n?0:1,this};function jn(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}jn.prototype.clear=Mn,jn.prototype.delete=Nn,jn.prototype.get=Ln,jn.prototype.has=xn,jn.prototype.set=kn;var Dn=jn;var Un=function(e,t){var r=this.__data__;if(r instanceof Xr){var n=r.__data__;if(!vn||n.length<199)return n.push([e,t]),this.size=++r.size,this;r=this.__data__=new Dn(n)}return r.set(e,t),this.size=r.size,this};function Fn(e){var t=this.__data__=new Xr(e);this.size=t.size}Fn.prototype.clear=Kr,Fn.prototype.delete=Qr,Fn.prototype.get=en,Fn.prototype.has=rn,Fn.prototype.set=Un;var Bn=Fn;var Vn=function(e){return this.__data__.set(e,"__lodash_hash_undefined__"),this};var Yn=function(e){return this.__data__.has(e)};function qn(e){var t=-1,r=null==e?0:e.length;for(this.__data__=new Dn;++t<r;)this.add(e[t])}qn.prototype.add=qn.prototype.push=Vn,qn.prototype.has=Yn;var $n=qn;var zn=function(e,t){for(var r=-1,n=null==e?0:e.length;++r<n;)if(t(e[r],r,e))return!0;return!1};var Wn=function(e,t){return e.has(t)};var Gn=function(e,t,r,n,i,s){var o=1&r,a=e.length,u=t.length;if(a!=u&&!(o&&u>a))return!1;var l=s.get(e),c=s.get(t);if(l&&c)return l==t&&c==e;var h=-1,f=!0,d=2&r?new $n:void 0;for(s.set(e,t),s.set(t,e);++h<a;){var p=e[h],m=t[h];if(n)var g=o?n(m,p,h,t,e,s):n(p,m,h,e,t,s);if(void 0!==g){if(g)continue;f=!1;break}if(d){if(!zn(t,(function(e,t){if(!Wn(d,t)&&(p===e||i(p,e,r,n,s)))return d.push(t)}))){f=!1;break}}else if(p!==m&&!i(p,m,r,n,s)){f=!1;break}}return s.delete(e),s.delete(t),f},Jn=Pe.Uint8Array;var Zn=function(e){var t=-1,r=Array(e.size);return e.forEach((function(e,n){r[++t]=[n,e]})),r};var Hn=function(e){var t=-1,r=Array(e.size);return e.forEach((function(e){r[++t]=e})),r},Xn=Ne?Ne.prototype:void 0,Kn=Xn?Xn.valueOf:void 0;var Qn=function(e,t,r,n,i,s,o){switch(r){case"[object DataView]":if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case"[object ArrayBuffer]":return!(e.byteLength!=t.byteLength||!s(new Jn(e),new Jn(t)));case"[object Boolean]":case"[object Date]":case"[object Number]":return qr(+e,+t);case"[object Error]":return e.name==t.name&&e.message==t.message;case"[object RegExp]":case"[object String]":return e==t+"";case"[object Map]":var a=Zn;case"[object Set]":var u=1&n;if(a||(a=Hn),e.size!=t.size&&!u)return!1;var l=o.get(e);if(l)return l==t;n|=2,o.set(e,t);var c=Gn(a(e),a(t),n,i,s,o);return o.delete(e),c;case"[object Symbol]":if(Kn)return Kn.call(e)==Kn.call(t)}return!1};var ei=function(e,t){for(var r=-1,n=t.length,i=e.length;++r<n;)e[i+r]=t[r];return e};var ti=function(e,t,r){var n=t(e);return Je(e)?n:ei(n,r(e))};var ri=function(e,t){for(var r=-1,n=null==e?0:e.length,i=0,s=[];++r<n;){var o=e[r];t(o,r,e)&&(s[i++]=o)}return s};var ni=function(){return[]},ii=Object.prototype.propertyIsEnumerable,si=Object.getOwnPropertySymbols,oi=si?function(e){return null==e?[]:(e=Object(e),ri(si(e),(function(t){return ii.call(e,t)})))}:ni;var ai=function(e){return ti(e,yt,oi)},ui=Object.prototype.hasOwnProperty;var li=function(e,t,r,n,i,s){var o=1&r,a=ai(e),u=a.length;if(u!=ai(t).length&&!o)return!1;for(var l=u;l--;){var c=a[l];if(!(o?c in t:ui.call(t,c)))return!1}var h=s.get(e),f=s.get(t);if(h&&f)return h==t&&f==e;var d=!0;s.set(e,t),s.set(t,e);for(var p=o;++l<u;){var m=e[c=a[l]],g=t[c];if(n)var y=o?n(g,m,c,t,e,s):n(m,g,c,e,t,s);if(!(void 0===y?m===g||i(m,g,r,n,s):y)){d=!1;break}p||(p="constructor"==c)}if(d&&!p){var v=e.constructor,b=t.constructor;v==b||!("constructor"in e)||!("constructor"in t)||"function"==typeof v&&v instanceof v&&"function"==typeof b&&b instanceof b||(d=!1)}return s.delete(e),s.delete(t),d},ci=yn(Pe,"DataView"),hi=yn(Pe,"Promise"),fi=yn(Pe,"Set"),di=yn(Pe,"WeakMap"),pi=un(ci),mi=un(vn),gi=un(hi),yi=un(fi),vi=un(di),bi=Ve;(ci&&"[object DataView]"!=bi(new ci(new ArrayBuffer(1)))||vn&&"[object Map]"!=bi(new vn)||hi&&"[object Promise]"!=bi(hi.resolve())||fi&&"[object Set]"!=bi(new fi)||di&&"[object WeakMap]"!=bi(new di))&&(bi=function(e){var t=Ve(e),r="[object Object]"==t?e.constructor:void 0,n=r?un(r):"";if(n)switch(n){case pi:return"[object DataView]";case mi:return"[object Map]";case gi:return"[object Promise]";case yi:return"[object Set]";case vi:return"[object WeakMap]"}return t});var wi=bi,_i=Object.prototype.hasOwnProperty;var Ei=function(e,t,r,n,i,s){var o=Je(e),a=Je(t),u=o?"[object Array]":wi(e),l=a?"[object Array]":wi(t),c="[object Object]"==(u="[object Arguments]"==u?"[object Object]":u),h="[object Object]"==(l="[object Arguments]"==l?"[object Object]":l),f=u==l;if(f&&He(e)){if(!He(t))return!1;o=!0,c=!1}if(f&&!c)return s||(s=new Bn),o||st(e)?Gn(e,t,r,n,i,s):Qn(e,t,u,r,n,i,s);if(!(1&r)){var d=c&&_i.call(e,"__wrapped__"),p=h&&_i.call(t,"__wrapped__");if(d||p){var m=d?e.value():e,g=p?t.value():t;return s||(s=new Bn),i(m,g,r,n,s)}}return!!f&&(s||(s=new Bn),li(e,t,r,n,i,s))};var Ti=function e(t,r,n,i,s){return t===r||(null==t||null==r||!Ye(t)&&!Ye(r)?t!=t&&r!=r:Ei(t,r,n,i,e,s))};var Si=function(e,t,r,n){var i=r.length,s=i,o=!n;if(null==e)return!s;for(e=Object(e);i--;){var a=r[i];if(o&&a[2]?a[1]!==e[a[0]]:!(a[0]in e))return!1}for(;++i<s;){var u=(a=r[i])[0],l=e[u],c=a[1];if(o&&a[2]){if(void 0===l&&!(u in e))return!1}else{var h=new Bn;if(n)var f=n(l,c,u,e,t,h);if(!(void 0===f?Ti(c,l,3,n,h):f))return!1}}return!0};var Ai=function(e){return e==e&&!pt(e)};var Ii=function(e){for(var t=yt(e),r=t.length;r--;){var n=t[r],i=e[n];t[r]=[n,i,Ai(i)]}return t};var Ci=function(e,t){return function(r){return null!=r&&(r[e]===t&&(void 0!==t||e in Object(r)))}};var Oi=function(e){var t=Ii(e);return 1==t.length&&t[0][2]?Ci(t[0][0],t[0][1]):function(r){return r===e||Si(r,e,t)}};var Mi=function(e){return"symbol"==typeof e||Ye(e)&&"[object Symbol]"==Ve(e)},Ri=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Pi=/^\w*$/;var Ni=function(e,t){if(Je(e))return!1;var r=typeof e;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=e&&!Mi(e))||(Pi.test(e)||!Ri.test(e)||null!=t&&e in Object(t))};function Li(e,t){if("function"!=typeof e||null!=t&&"function"!=typeof t)throw new TypeError("Expected a function");var r=function(){var n=arguments,i=t?t.apply(this,n):n[0],s=r.cache;if(s.has(i))return s.get(i);var o=e.apply(this,n);return r.cache=s.set(i,o)||s,o};return r.cache=new(Li.Cache||Dn),r}Li.Cache=Dn;var xi=Li;var ki=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,ji=/\\(\\)?/g,Di=function(e){var t=xi(e,(function(e){return 500===r.size&&r.clear(),e})),r=t.cache;return t}((function(e){var t=[];return 46===e.charCodeAt(0)&&t.push(""),e.replace(ki,(function(e,r,n,i){t.push(n?i.replace(ji,"$1"):r||e)})),t})),Ui=Ne?Ne.prototype:void 0,Fi=Ui?Ui.toString:void 0;var Bi=function e(t){if("string"==typeof t)return t;if(Je(t))return Ie(t,e)+"";if(Mi(t))return Fi?Fi.call(t):"";var r=t+"";return"0"==r&&1/t==-1/0?"-0":r};var Vi=function(e){return null==e?"":Bi(e)};var Yi=function(e,t){return Je(e)?e:Ni(e,t)?[e]:Di(Vi(e))};var qi=function(e){if("string"==typeof e||Mi(e))return e;var t=e+"";return"0"==t&&1/e==-1/0?"-0":t};var $i=function(e,t){for(var r=0,n=(t=Yi(t,e)).length;null!=e&&r<n;)e=e[qi(t[r++])];return r&&r==n?e:void 0};var zi=function(e,t,r){var n=null==e?void 0:$i(e,t);return void 0===n?r:n};var Wi=function(e,t){return null!=e&&t in Object(e)};var Gi=function(e,t,r){for(var n=-1,i=(t=Yi(t,e)).length,s=!1;++n<i;){var o=qi(t[n]);if(!(s=null!=e&&r(e,o)))break;e=e[o]}return s||++n!=i?s:!!(i=null==e?0:e.length)&&Qe(i)&&Ke(o,i)&&(Je(e)||Ge(e))};var Ji=function(e,t){return null!=e&&Gi(e,t,Wi)};var Zi=function(e,t){return Ni(e)&&Ai(t)?Ci(qi(e),t):function(r){var n=zi(r,e);return void 0===n&&n===t?Ji(r,e):Ti(t,n,3)}};var Hi=function(e){return e};var Xi=function(e){return function(t){return null==t?void 0:t[e]}};var Ki=function(e){return function(t){return $i(t,e)}};var Qi=function(e){return Ni(e)?Xi(qi(e)):Ki(e)};var es=function(e){return"function"==typeof e?e:null==e?Hi:"object"==typeof e?Je(e)?Zi(e[0],e[1]):Oi(e):Qi(e)};var ts=function(e){var t=null==e?0:e.length;return t?e[t-1]:void 0};var rs=function(e,t,r){var n=-1,i=e.length;t<0&&(t=-t>i?0:i+t),(r=r>i?i:r)<0&&(r+=i),i=t>r?0:r-t>>>0,t>>>=0;for(var s=Array(i);++n<i;)s[n]=e[n+t];return s};var ns=function(e,t){return t.length<2?e:$i(e,rs(t,0,-1))};var is=function(e,t){return t=Yi(t,e),null==(e=ns(e,t))||delete e[qi(ts(t))]},ss=Array.prototype.splice;var os=function(e,t){for(var r=e?t.length:0,n=r-1;r--;){var i=t[r];if(r==n||i!==s){var s=i;Ke(i)?ss.call(e,i,1):is(e,i)}}return e};var as=function(e,t){var r=[];if(!e||!e.length)return r;var n=-1,i=[],s=e.length;for(t=es(t);++n<s;){var o=e[n];t(o,n,e)&&(r.push(o),i.push(n))}return os(e,i),r},us=Object.prototype.hasOwnProperty;var ls=function(e){if(null==e)return!0;if(gt(e)&&(Je(e)||"string"==typeof e||"function"==typeof e.splice||He(e)||st(e)||Ge(e)))return!e.length;var t=wi(e);if("[object Map]"==t||"[object Set]"==t)return!e.size;if(lt(e))return!dt(e).length;for(var r in e)if(us.call(e,r))return!1;return!0};var cs=function(e,t){for(var r=-1,n=null==e?0:e.length;++r<n&&!1!==t(e[r],r,e););return e},hs=function(){try{var e=yn(Object,"defineProperty");return e({},"",{}),e}catch(e){}}();var fs=function(e,t,r){"__proto__"==t&&hs?hs(e,t,{configurable:!0,enumerable:!0,value:r,writable:!0}):e[t]=r},ds=Object.prototype.hasOwnProperty;var ps=function(e,t,r){var n=e[t];ds.call(e,t)&&qr(n,r)&&(void 0!==r||t in e)||fs(e,t,r)};var ms=function(e,t,r,n){var i=!r;r||(r={});for(var s=-1,o=t.length;++s<o;){var a=t[s],u=n?n(r[a],e[a],a,r,e):void 0;void 0===u&&(u=e[a]),i?fs(r,a,u):ps(r,a,u)}return r};var gs=function(e,t){return e&&ms(t,yt(t),e)};var ys=function(e){var t=[];if(null!=e)for(var r in Object(e))t.push(r);return t},vs=Object.prototype.hasOwnProperty;var bs=function(e){if(!pt(e))return ys(e);var t=lt(e),r=[];for(var n in e)("constructor"!=n||!t&&vs.call(e,n))&&r.push(n);return r};var ws=function(e){return gt(e)?at(e,!0):bs(e)};var _s=function(e,t){return e&&ms(t,ws(t),e)},Es=i((function(e,t){var r=t&&!t.nodeType&&t,n=r&&e&&!e.nodeType&&e,i=n&&n.exports===r?Pe.Buffer:void 0,s=i?i.allocUnsafe:void 0;e.exports=function(e,t){if(t)return e.slice();var r=e.length,n=s?s(r):new e.constructor(r);return e.copy(n),n}}));var Ts=function(e,t){return ms(e,oi(e),t)},Ss=Object.getOwnPropertySymbols?function(e){for(var t=[];e;)ei(t,oi(e)),e=It(e);return t}:ni;var As=function(e,t){return ms(e,Ss(e),t)};var Is=function(e){return ti(e,ws,Ss)},Cs=Object.prototype.hasOwnProperty;var Os=function(e){var t=e.length,r=new e.constructor(t);return t&&"string"==typeof e[0]&&Cs.call(e,"index")&&(r.index=e.index,r.input=e.input),r};var Ms=function(e){var t=new e.constructor(e.byteLength);return new Jn(t).set(new Jn(e)),t};var Rs=function(e,t){var r=t?Ms(e.buffer):e.buffer;return new e.constructor(r,e.byteOffset,e.byteLength)},Ps=/\w*$/;var Ns=function(e){var t=new e.constructor(e.source,Ps.exec(e));return t.lastIndex=e.lastIndex,t},Ls=Ne?Ne.prototype:void 0,xs=Ls?Ls.valueOf:void 0;var ks=function(e){return xs?Object(xs.call(e)):{}};var js=function(e,t){var r=t?Ms(e.buffer):e.buffer;return new e.constructor(r,e.byteOffset,e.length)};var Ds=function(e,t,r){var n=e.constructor;switch(t){case"[object ArrayBuffer]":return Ms(e);case"[object Boolean]":case"[object Date]":return new n(+e);case"[object DataView]":return Rs(e,r);case"[object Float32Array]":case"[object Float64Array]":case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return js(e,r);case"[object Map]":return new n;case"[object Number]":case"[object String]":return new n(e);case"[object RegExp]":return Ns(e);case"[object Set]":return new n;case"[object Symbol]":return ks(e)}},Us=Object.create,Fs=function(){function e(){}return function(t){if(!pt(t))return{};if(Us)return Us(t);e.prototype=t;var r=new e;return e.prototype=void 0,r}}();var Bs=function(e){return"function"!=typeof e.constructor||lt(e)?{}:Fs(It(e))};var Vs=function(e){return Ye(e)&&"[object Map]"==wi(e)},Ys=nt&&nt.isMap,qs=Ys?rt(Ys):Vs;var $s=function(e){return Ye(e)&&"[object Set]"==wi(e)},zs=nt&&nt.isSet,Ws=zs?rt(zs):$s,Gs={};Gs["[object Arguments]"]=Gs["[object Array]"]=Gs["[object ArrayBuffer]"]=Gs["[object DataView]"]=Gs["[object Boolean]"]=Gs["[object Date]"]=Gs["[object Float32Array]"]=Gs["[object Float64Array]"]=Gs["[object Int8Array]"]=Gs["[object Int16Array]"]=Gs["[object Int32Array]"]=Gs["[object Map]"]=Gs["[object Number]"]=Gs["[object Object]"]=Gs["[object RegExp]"]=Gs["[object Set]"]=Gs["[object String]"]=Gs["[object Symbol]"]=Gs["[object Uint8Array]"]=Gs["[object Uint8ClampedArray]"]=Gs["[object Uint16Array]"]=Gs["[object Uint32Array]"]=!0,Gs["[object Error]"]=Gs["[object Function]"]=Gs["[object WeakMap]"]=!1;var Js=function e(t,r,n,i,s,o){var a,u=1&r,l=2&r,c=4&r;if(n&&(a=s?n(t,i,s,o):n(t)),void 0!==a)return a;if(!pt(t))return t;var h=Je(t);if(h){if(a=Os(t),!u)return we(t,a)}else{var f=wi(t),d="[object Function]"==f||"[object GeneratorFunction]"==f;if(He(t))return Es(t,u);if("[object Object]"==f||"[object Arguments]"==f||d&&!s){if(a=l||d?{}:Bs(t),!u)return l?As(t,_s(a,t)):Ts(t,gs(a,t))}else{if(!Gs[f])return s?t:{};a=Ds(t,f,u)}}o||(o=new Bn);var p=o.get(t);if(p)return p;o.set(t,a),Ws(t)?t.forEach((function(i){a.add(e(i,r,n,i,t,o))})):qs(t)&&t.forEach((function(i,s){a.set(s,e(i,r,n,s,t,o))}));var m=h?void 0:(c?l?Is:ai:l?ws:yt)(t);return cs(m||t,(function(i,s){m&&(i=t[s=i]),ps(a,s,e(i,r,n,s,t,o))})),a};var Zs=function(e){return Js(e,5)};var Hs=function(e){return function(t,r,n){var i=Object(t);if(!gt(t)){var s=es(r);t=yt(t),r=function(e){return s(i[e],e,i)}}var o=e(t,r,n);return o>-1?i[s?t[o]:o]:void 0}};var Xs=function(e,t,r,n){for(var i=e.length,s=r+(n?1:-1);n?s--:++s<i;)if(t(e[s],s,e))return s;return-1},Ks=/\s/;var Qs=function(e){for(var t=e.length;t--&&Ks.test(e.charAt(t)););return t},eo=/^\s+/;var to=function(e){return e?e.slice(0,Qs(e)+1).replace(eo,""):e},ro=/^[-+]0x[0-9a-f]+$/i,no=/^0b[01]+$/i,io=/^0o[0-7]+$/i,so=parseInt;var oo=function(e){if("number"==typeof e)return e;if(Mi(e))return NaN;if(pt(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=pt(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=to(e);var r=no.test(e);return r||io.test(e)?so(e.slice(2),r?2:8):ro.test(e)?NaN:+e};var ao=function(e){return e?(e=oo(e))===1/0||e===-1/0?17976931348623157e292*(e<0?-1:1):e==e?e:0:0===e?e:0};var uo=function(e){var t=ao(e),r=t%1;return t==t?r?t-r:t:0},lo=Math.max;var co=Hs((function(e,t,r){var n=null==e?0:e.length;if(!n)return-1;var i=null==r?0:uo(r);return i<0&&(i=lo(n+i,0)),Xs(e,es(t),i)}));var ho=Object.freeze({__proto__:null,UNREAD_MESSAGES_COUNT_UPDATE:"unreadmessagescountupdate",CLOSE:"close",CONFLICT:"conflict",CONVERSATION_INFO_UPDATED:"conversationinfoupdated",UNHANDLED_MESSAGE:"unhandledmessage",INVITED:"invited",KICKED:"kicked",MEMBERS_JOINED:"membersjoined",MEMBERS_LEFT:"membersleft",MEMBER_INFO_UPDATED:"memberinfoupdated",BLOCKED:"blocked",UNBLOCKED:"unblocked",MEMBERS_BLOCKED:"membersblocked",MEMBERS_UNBLOCKED:"membersunblocked",MUTED:"muted",UNMUTED:"unmuted",MEMBERS_MUTED:"membersmuted",MEMBERS_UNMUTED:"membersunmuted",MESSAGE:"message",MESSAGE_RECALL:"messagerecall",MESSAGE_UPDATE:"messageupdate",LAST_DELIVERED_AT_UPDATE:"lastdeliveredatupdate",LAST_READ_AT_UPDATE:"lastreadatupdate",INFO_UPDATED:"infoupdated"});const fo={NONE:Symbol("none"),SENDING:Symbol("sending"),SENT:Symbol("sent"),DELIVERED:Symbol("delivered"),FAILED:Symbol("failed")};Object.freeze(fo);const po={[fo.NONE]:!0,[fo.SENDING]:!0,[fo.SENT]:!0,[fo.DELIVERED]:!0,[fo.READ]:!0,[fo.FAILED]:!0};class mo{constructor(e){Object.assign(this,{content:e},{id:Ur(),cid:null,timestamp:new Date,from:void 0,mentionList:[],mentionedAll:!1,_mentioned:!1}),this._setStatus(fo.NONE)}getPayload(){return this.content}_toJSON(){const{id:e,cid:t,from:r,timestamp:n,deliveredAt:i,updatedAt:s,mentionList:o,mentionedAll:a,mentioned:u}=this;return{id:e,cid:t,from:r,timestamp:n,deliveredAt:i,updatedAt:s,mentionList:o,mentionedAll:a,mentioned:u}}toJSON(){return{...this._toJSON(),data:this.content}}toFullJSON(){const{content:e,id:t,cid:r,from:n,timestamp:i,deliveredAt:s,_updatedAt:o,mentionList:a,mentionedAll:u}=this;return{data:e,id:t,cid:r,from:n,timestamp:qt(i),deliveredAt:qt(s),updatedAt:qt(o),mentionList:a,mentionedAll:u}}get status(){return this._status}_setStatus(e){if(!po[e])throw new Error("Invalid message status");this._status=e}get timestamp(){return this._timestamp}set timestamp(e){this._timestamp=Yt(e)}get deliveredAt(){return this._deliveredAt}set deliveredAt(e){this._deliveredAt=Yt(e)}get updatedAt(){return this._updatedAt||this.timestamp}set updatedAt(e){this._updatedAt=Yt(e)}get mentioned(){return this._mentioned}_updateMentioned(e){this._mentioned=this.from!==e&&(this.mentionedAll||this.mentionList.indexOf(e)>-1)}getMentionList(){return this.mentionList}setMentionList(e){return this.mentionList=tr(e),this}mentionAll(e=!0){return this.mentionedAll=Boolean(e),this}static validate(){return!0}static parse(e,t){return t||new this(e)}}const go=e=>{if("number"!=typeof e)throw new TypeError(`${e} is not a Number`);return t=>{t.TYPE=e,t.validate=t=>t._lctype===e,t.prototype._getType=()=>({_lctype:e})}},yo=e=>{if("string"!=typeof e){if(!Array.isArray(e))throw new TypeError(`${e} is not an Array`);if(e.some(e=>"string"!=typeof e))throw new TypeError("fields contains non-string typed member")}return t=>{let r=Gt?Jt(t,"_customFields"):t._customFields;r=Array.isArray(r)?r:[],t._customFields=r.concat(e)}},vo=e=>{Gt&&(e.parse=Jt(e,"parse"))};var bo;let wo=yo(["_lctext","_lcattrs"])(bo=class extends mo{get type(){return this.constructor.TYPE}set text(e){return this.setText(e)}get text(){return this.getText()}set attributes(e){return this.setAttributes(e)}get attributes(){return this.getAttributes()}get summary(){return this.text}setText(e){return this._lctext=e,this}getText(){return this._lctext}setAttributes(e){return this._lcattrs=e,this}getAttributes(){return this._lcattrs}_getCustomFields(){return(Array.isArray(this.constructor._customFields)?this.constructor._customFields:[]).reduce((e,t)=>("string"!=typeof t||(e[t]=this[t]),e),{})}_getType(){throw new Error("not implemented")}getPayload(){return Qt({_lctext:this.getText(),_lcattrs:this.getAttributes(),...this._getCustomFields(),...this._getType()})}toJSON(){const{type:e,text:t,attributes:r,summary:n}=this;return{...super._toJSON(),type:e,text:t,attributes:r,summary:n}}toFullJSON(){return{...super.toFullJSON(),data:this.getPayload()}}static parse(e,t=new this){t.content=e;const r=Gt?Jt(t.constructor,"_customFields"):t.constructor._customFields;let n=Array.isArray(r)?r:[];return n=n.reduce((t,r)=>("string"!=typeof r||(t[r]=e[r]),t),{}),Object.assign(t,n),super.parse(e,t)}})||bo;var _o;let Eo=go(-127)(_o=vo(_o=class extends wo{get summary(){return"[该消息已撤回]"}})||_o)||_o;const To=be("LC:Conversation"),So=e=>{const t=e.getPayload();let r,n;return t instanceof ArrayBuffer?n=t:r="string"!=typeof t?JSON.stringify(t):t,{msg:r,binaryMsg:n}},{NEW:Ao,OLD:Io}=Z.QueryDirection,Co={NEW_TO_OLD:Io,OLD_TO_NEW:Ao};Object.freeze(Co);class Oo extends he{constructor({id:e,lastMessageAt:t,lastMessage:r,lastDeliveredAt:n,lastReadAt:i,unreadMessagesCount:s=0,members:o=[],mentioned:a=!1,...u},l){super(),Object.assign(this,{id:e,lastMessageAt:t,lastMessage:r,members:o,...u}),this.members=Array.from(new Set(this.members)),Object.assign(Kt(this),{messagesWaitingForReceipt:{},lastDeliveredAt:n,lastReadAt:i,unreadMessagesCount:s,mentioned:a}),this._client=l,To.enabled&&vt(ho).forEach(e=>this.on(e,(...t)=>this._debug(`${e} event emitted. %o`,t))),Ir(this._client._plugins.onConversationCreate,this)}get unreadMessagesMentioned(){return Kt(this).unreadMessagesMentioned}_setUnreadMessagesMentioned(e){Kt(this).unreadMessagesMentioned=Boolean(e)}set unreadMessagesCount(e){e!==this.unreadMessagesCount&&(Kt(this).unreadMessagesCount=e,this._client.emit("unreadmessagescountupdate",[this]))}get unreadMessagesCount(){return Kt(this).unreadMessagesCount}set lastMessageAt(e){const t=Yt(e);t<=this._lastMessageAt||(this._lastMessageAt=t)}get lastMessageAt(){return this._lastMessageAt}get lastDeliveredAt(){return 2!==this.members.length?null:Kt(this).lastDeliveredAt}_setLastDeliveredAt(e){const t=Yt(e);t<Kt(this).lastDeliveredAt||(Kt(this).lastDeliveredAt=t,this.emit("lastdeliveredatupdate"))}get lastReadAt(){return 2!==this.members.length?null:Kt(this).lastReadAt}_setLastReadAt(e){const t=Yt(e);t<Kt(this).lastReadAt||(Kt(this).lastReadAt=t,this.emit("lastreadatupdate"))}toFullJSON(){const{id:e,members:t,lastMessageAt:r,lastDeliveredAt:n,lastReadAt:i,lastMessage:s,unreadMessagesCount:o}=this;return{id:e,members:t,lastMessageAt:qt(r),lastDeliveredAt:qt(n),lastReadAt:qt(i),lastMessage:s?s.toFullJSON():void 0,unreadMessagesCount:o}}toJSON(){const{id:e,members:t,lastMessageAt:r,lastDeliveredAt:n,lastReadAt:i,lastMessage:s,unreadMessagesCount:o,unreadMessagesMentioned:a}=this;return{id:e,members:t,lastMessageAt:r,lastDeliveredAt:n,lastReadAt:i,lastMessage:s?s.toJSON():void 0,unreadMessagesCount:o,unreadMessagesMentioned:a}}_debug(...e){To(...e,`[${this.id}]`)}_send(e,...t){return null===e.cmd&&(e.cmd="conv"),"conv"===e.cmd&&null===e.convMessage&&(e.convMessage=new G),e.convMessage&&null===e.convMessage.cid&&(e.convMessage.cid=this.id),this._client._send(e,...t)}async send(e,t){if(this._debug(e,"send"),!(e instanceof mo))throw new TypeError(`${e} is not a Message`);const{transient:r,receipt:n,priority:i,pushData:s,will:o}={...e.constructor.sendOptions,..."function"==typeof e.constructor.getSendOptions?e.constructor.getSendOptions(e):{},...t};n&&(this.transient?console.warn("receipt option is ignored as the conversation is transient."):r?console.warn("receipt option is ignored as the message is sent transiently."):this.members.length>2&&console.warn("receipt option is recommended to be used in one-on-one conversation.")),i&&!this.transient&&console.warn("priority option is ignored as the conversation is not transient."),Object.assign(e,{cid:this.id,from:this._client.id}),e._setStatus(fo.SENDING);const{msg:a,binaryMsg:u}=So(e),l=new re({cmd:"direct",directMessage:new $({msg:a,binaryMsg:u,cid:this.id,r:n,transient:r,dt:e.id,pushData:JSON.stringify(s),will:o,mentionPids:e.mentionList,mentionAll:e.mentionedAll}),priority:i});try{const t=await this._send(l),{ackMessage:{uid:i,t:s,code:o,reason:a,appCode:u}}=t;if(null!==o)throw vr({code:o,reason:a,appCode:u});return Object.assign(e,{id:i,timestamp:s}),r||(this.lastMessage=e,this.lastMessageAt=e.timestamp),e._setStatus(fo.SENT),n&&(Kt(this).messagesWaitingForReceipt[e.id]=e),e}catch(t){throw e._setStatus(fo.FAILED),t}}async _update(e,t,r){if(this._debug("patch %O %O %O",e,t,r),e instanceof mo){if(e.from!==this._client.id)throw new Error("Updating message from others is not allowed");if(e.status!==fo.SENT&&e.status!==fo.DELIVERED)throw new Error("Message is not sent")}else if(!e.id||!e.timestamp)throw new TypeError(`${e} is not a Message`);let n,i;if(!r){const e=So(t);({msg:n,binaryMsg:i}=e)}await this._send(new re({cmd:ae.patch,op:ue.modify,patchMessage:new ie({patches:[new se({cid:this.id,mid:e.id,timestamp:Number(e.timestamp),recall:r,data:n,binaryMsg:i,mentionPids:t.mentionList,mentionAll:t.mentionedAll})],lastPatchTime:this._client._lastPatchTime})}));const{id:s,cid:o,timestamp:a,from:u,_status:l}=e;return Object.assign(t,{id:s,cid:o,timestamp:a,from:u,_status:l}),this.lastMessage&&this.lastMessage.id===t.id&&(this.lastMessage=t),t}async count(){return this._debug("count"),(await this._send(new re({op:"count"}))).convMessage.count}_addMembers(){}_removeMembers(){}async update(e,t){if(!(t instanceof mo))throw new TypeError(`${t} is not a Message`);return this._update(e,t,!1)}async recall(e){return this._update(e,new Eo,!0)}async queryMessages(e={}){this._debug("query messages %O",e);const{beforeTime:t,beforeMessageId:r,afterTime:n,afterMessageId:i,limit:s,direction:o,type:a,startTime:u,startMessageId:l,startClosed:c,endTime:h,endMessageId:f,endClosed:d}=e;if(r||t||i||n)return console.warn("DEPRECATION: queryMessages options beforeTime, beforeMessageId, afterTime and afterMessageId are deprecated in favor of startTime, startMessageId, endTime and endMessageId."),this.queryMessages({startTime:t,startMessageId:r,endTime:n,endMessageId:i,limit:s});if(l&&!u)throw new Error("query option startMessageId must be used with option startTime");if(f&&!h)throw new Error("query option endMessageId must be used with option endTime");const p={t:u,mid:l,tIncluded:c,tt:h,tmid:f,ttIncluded:d,l:s,lctype:a};p.t instanceof Date&&(p.t=p.t.getTime()),p.tt instanceof Date&&(p.tt=p.tt.getTime()),void 0!==o?p.direction=o:p.tt>p.t&&(p.direction=Co.OLD_TO_NEW);const m=await this._send(new re({cmd:"logs",logsMessage:new Z(Object.assign(p,{cid:this.id}))}));return Promise.all(m.logsMessage.logs.map(async({msgId:e,timestamp:t,patchTimestamp:r,from:n,ackAt:i,readAt:s,data:o,mentionAll:a,mentionPids:u,bin:l})=>{const c={data:o,bin:l,id:e,cid:this.id,timestamp:t,from:n,deliveredAt:i,updatedAt:r,mentionList:u,mentionedAll:a},h=await this._client.parseMessage(c);let f=fo.SENT;return 2===this.members.length&&(i&&(f=fo.DELIVERED),i&&this._setLastDeliveredAt(i),s&&this._setLastReadAt(s)),h._setStatus(f),h}))}createMessagesIterator({beforeTime:e,beforeMessageId:t,limit:r}={}){let n;return{next:()=>(n=void 0===n?this.queryMessages({limit:r,startTime:e,startMessageId:t}):n.then(e=>0===e.length||e.length<r?[]:this.queryMessages({startTime:e[0].timestamp,startMessageId:e[0].id,limit:r})),n.then(e=>({value:Array.from(e),done:0===e.length||e.length<r})))}}async read(){if(this.unreadMessagesCount=0,this._setUnreadMessagesMentioned(!1),this.transient)return this;const e=this._client;return Kt(e).readConversationsBuffer||(Kt(e).readConversationsBuffer=new Set),Kt(e).readConversationsBuffer.add(this),e._doSendRead(),this}_handleReceipt({messageId:e,timestamp:t,read:r}){r?this._setLastReadAt(t):this._setLastDeliveredAt(t);const{messagesWaitingForReceipt:n}=Kt(this),i=n[e];i&&(i._setStatus(fo.DELIVERED),i.deliveredAt=t,delete n[e])}async fetchReceiptTimestamps(){if(this.transient||this.system)return this;const{convMessage:{maxReadTimestamp:e,maxAckTimestamp:t}}=await this._send(new re({op:"max_read"}));return this._setLastDeliveredAt(t),this._setLastReadAt(e),this}_fetchAllReceiptTimestamps(){if(this.transient||this.system)return this;const e=new G({queryAllMembers:!0});return this._send(new re({op:"max_read",convMessage:e})).then(({convMessage:{maxReadTuples:e}})=>e.filter(e=>e.maxAckTimestamp||e.maxReadTimestamp).map(({pid:e,maxAckTimestamp:t,maxReadTimestamp:r})=>({pid:e,lastDeliveredAt:Yt(t),lastReadAt:Yt(r)})))}}const Mo=be("LC:SignatureFactoryRunner");function Ro(e={}){const{signature:t,timestamp:r,nonce:n}=e;if("string"!=typeof t||"number"!=typeof r||"string"!=typeof n)throw new Error("malformed signature");return{signature:t,timestamp:r,nonce:n}}var Po=(e,t)=>Promise.resolve().then(()=>(Mo("call signatureFactory with %O",t),e(...t))).then(Vt(e=>Mo("sign result %O",e)),e=>{throw e.message=`sign error: ${e.message}`,Mo(e),e}).then(Ro);const No=({allowedPids:e,failedPids:t})=>({successfulClientIds:e,failures:t.map(({pids:e,...t})=>Object.assign(vr(t),{clientIds:e}))});class Lo extends Oo{constructor(e,{creator:t,createdAt:r,updatedAt:n,transient:i=!1,system:s=!1,muted:o=!1,mutedMembers:a=[],...u},l){super({...e,creator:t,createdAt:r,updatedAt:n,mutedMembers:a,transient:i,system:s,muted:o,_attributes:u},l),this._reset()}set createdAt(e){this._createdAt=Yt(e)}get createdAt(){return this._createdAt}set updatedAt(e){this._updatedAt=Yt(e)}get updatedAt(){return this._updatedAt}get name(){return this.get("name")}set name(e){this.set("name",e)}get(e){return zi(Kt(this).currentAttributes,e)}set(e,t){this._debug(`set [${e}]: ${t}`);const{pendingAttributes:r}=Kt(this),n=Object.keys(r),i=new RegExp(`^${e}`),s=n.filter(i.test.bind(i));if(s.forEach(e=>{delete r[e]}),s.length)r[e]=t;else{const i=co(n,t=>0===e.indexOf(t));i?rr(r[i],e.slice(i.length+1),t):r[e]=t}return this._buildCurrentAttributes(),this}_buildCurrentAttributes(){const{pendingAttributes:e}=Kt(this);Kt(this).currentAttributes=Object.keys(e).reduce((t,r)=>rr(t,r,e[r]),Zs(this._attributes))}_updateServerAttributes(e){Object.keys(e).forEach(t=>rr(this._attributes,t,e[t])),this._buildCurrentAttributes()}_reset(){Object.assign(Kt(this),{pendingAttributes:{},currentAttributes:this._attributes})}async save(){this._debug("save");const e=Kt(this).pendingAttributes;if(ls(e))return this._debug("nothing touched, resolve with self"),this;this._debug("attr: %O",e);const t=new G({attr:new U({data:JSON.stringify(zt(e))})}),r=await this._send(new re({op:"update",convMessage:t}));return this.updatedAt=r.convMessage.udate,this._attributes=Kt(this).currentAttributes,Kt(this).pendingAttributes={},this}async fetch(){const e=this._client.getQuery().equalTo("objectId",this.id);return await e.find(),this}async mute(){return this._debug("mute"),await this._send(new re({op:"mute"})),this.transient||(this.muted=!0,this.mutedMembers=Zt(this.mutedMembers,[this._client.id])),this}async unmute(){return this._debug("unmute"),await this._send(new re({op:"unmute"})),this.transient||(this.muted=!1,this.mutedMembers=Ht(this.mutedMembers,[this._client.id])),this}async _appendConversationSignature(e,t,r){if(this._client.options.conversationSignatureFactory){const n=[this.id,this._client.id,r.sort(),t],i=await Po(this._client.options.conversationSignatureFactory,n);Object.assign(e.convMessage,Wt({signature:"s",timestamp:"t",nonce:"n"},i))}}async _appendBlacklistSignature(e,t,r){if(this._client.options.blacklistSignatureFactory){const n=[this.id,this._client.id,r.sort(),t],i=await Po(this._client.options.blacklistSignatureFactory,n);Object.assign(e.blacklistMessage,Wt({signature:"s",timestamp:"t",nonce:"n"},i))}}async add(e){this._debug("add",e),"string"==typeof e&&(e=[e]);const t=new re({op:"add",convMessage:new G({m:e})});await this._appendConversationSignature(t,"invite",e);const{convMessage:r,convMessage:{allowedPids:n}}=await this._send(t);return this._addMembers(n),No(r)}async remove(e){this._debug("remove",e),"string"==typeof e&&(e=[e]);const t=new re({op:"remove",convMessage:new G({m:e})});await this._appendConversationSignature(t,"kick",e);const{convMessage:r,convMessage:{allowedPids:n}}=await this._send(t);return this._removeMembers(n),No(r)}async join(){return this._debug("join"),this.add(this._client.id).then(({failures:e})=>{if(e[0])throw e[0];return this})}async quit(){return this._debug("quit"),this.remove(this._client.id).then(({failures:e})=>{if(e[0])throw e[0];return this})}async muteMembers(e){this._debug("mute",e),e=tr(e);const t=new re({op:ue.add_shutup,convMessage:new G({m:e})}),{convMessage:r}=await this._send(t);return No(r)}async unmuteMembers(e){this._debug("unmute",e),e=tr(e);const t=new re({op:ue.remove_shutup,convMessage:new G({m:e})}),{convMessage:r}=await this._send(t);return No(r)}async queryMutedMembers({limit:e,next:t}={}){this._debug("query muted: limit %O, next: %O",e,t);const r=new re({op:ue.query_shutup,convMessage:new G({limit:e,next:t})}),{convMessage:{m:n,next:i}}=await this._send(r);return{results:n,next:i}}async blockMembers(e){this._debug("block",e),e=tr(e);const t=new re({cmd:"blacklist",op:ue.block,blacklistMessage:new ne({srcCid:this.id,toPids:e})});await this._appendBlacklistSignature(t,"conversation-block-clients",e);const{blacklistMessage:r}=await this._send(t);return No(r)}async unblockMembers(e){this._debug("unblock",e),e=tr(e);const t=new re({cmd:"blacklist",op:ue.unblock,blacklistMessage:new ne({srcCid:this.id,toPids:e})});await this._appendBlacklistSignature(t,"conversation-unblock-clients",e);const{blacklistMessage:r}=await this._send(t);return No(r)}async queryBlockedMembers({limit:e,next:t}={}){this._debug("query blocked: limit %O, next: %O",e,t);const r=new re({cmd:"blacklist",op:ue.query,blacklistMessage:new ne({srcCid:this.id,limit:e,next:t})}),{blacklistMessage:{blockedPids:n,next:i}}=await this._send(r);return{results:n,next:i}}toFullJSON(){const{creator:e,system:t,transient:r,createdAt:n,updatedAt:i,_attributes:s}=this;return{...super.toFullJSON(),creator:e,system:t,transient:r,createdAt:qt(n),updatedAt:qt(i),...s}}toJSON(){const{creator:e,system:t,transient:r,muted:n,mutedMembers:i,createdAt:s,updatedAt:o,_attributes:a}=this;return{...super.toJSON(),creator:e,system:t,transient:r,muted:n,mutedMembers:i,createdAt:s,updatedAt:o,...a}}}const xo={OWNER:"Owner",MANAGER:"Manager",MEMBER:"Member"};Object.freeze(xo);class ko{constructor({conversation:e,memberId:t,role:r}){if(!e)throw new Error("conversation requried");if(!t)throw new Error("memberId requried");Object.assign(Kt(this),{conversation:e,memberId:t,role:r})}get conversationId(){return Kt(this).conversation.id}get memberId(){return Kt(this).memberId}get role(){return this.isOwner?xo.OWNER:Kt(this).role}get isOwner(){return this.memberId===Kt(this).conversation.creator}toJSON(){const{conversationId:e,memberId:t,role:r,isOwner:n}=this;return{conversationId:e,memberId:t,role:r,isOwner:n}}}class jo extends Lo{_addMembers(e){super._addMembers(e),this.members=Zt(this.members,e);const{memberInfoMap:t}=Kt(this);t&&e.forEach(e=>{t[e]=t[e]||new ko({conversation:this,memberId:e,role:xo.MEMBER})})}_removeMembers(e){super._removeMembers(e),this.members=Ht(this.members,e);const{memberInfoMap:t}=Kt(this);t&&e.forEach(e=>{delete t[e]})}async _fetchAllMemberInfo(){const e=(await this._client._requestWithSessionToken({method:"GET",path:"/classes/_ConversationMemberInfo",query:{where:{cid:this.id}}})).results.map(e=>new ko({conversation:this,memberId:e.clientId,role:e.role})),t={};return e.forEach(e=>{t[e.memberId]=e}),this.members.forEach(e=>{t[e]=t[e]||new ko({conversation:this,memberId:e,role:xo.MEMBER})}),Kt(this).memberInfoMap=t,t}async getAllMemberInfo({noCache:e=!1}={}){let{memberInfoMap:t}=Kt(this);return t&&!e||(t=await this._fetchAllMemberInfo()),this.members.map(e=>t[e])}async getMemberInfo(e){if(-1===this.members.indexOf(e))throw new Error(`${e} is not the mumber of conversation[${this.id}]`);const{memberInfoMap:t}=Kt(this);return t&&t[e]||await this.getAllMemberInfo(),Kt(this).memberInfoMap[e]}async updateMemberRole(e,t){if(this._debug("update member role"),t===xo.OWNER)throw vr({code:yr.OWNER_PROMOTION_NOT_ALLOWED});await this._send(new re({op:ue.member_info_update,convMessage:new G({targetClientId:e,info:new oe({pid:e,role:t})})}));const{memberInfos:r}=Kt(this);return r&&r[e]&&(Kt(r[e]).role=t),this}}class Do extends Lo{}class Uo extends Lo{async subscribe(){return this.join()}async unsubscribe(){return this.quit()}}const Fo=e=>e.code===yr.CONVERSATION_NOT_FOUND?vr({code:yr.TEMPORARY_CONVERSATION_EXPIRED}):e;class Bo extends Oo{constructor(e,{expiredAt:t},r){super({...e,expiredAt:t},r)}set expiredAt(e){this._expiredAt=Yt(e)}get expiredAt(){return this._expiredAt}get expired(){return this.expiredAt<new Date}async _send(...e){if(this.expired)throw vr({code:yr.TEMPORARY_CONVERSATION_EXPIRED});try{return await super._send(...e)}catch(e){throw Fo(e)}}async send(...e){try{return await super.send(...e)}catch(e){throw Fo(e)}}toFullJSON(){const{expiredAt:e}=this;return{...super.toFullJSON(),expiredAt:qt(e)}}toJSON(){const{expiredAt:e,expired:t}=this;return{...super.toJSON(),expiredAt:e,expired:t}}}const Vo=be("LC:ConversationQuery");class Yo{static _encode(e){return e instanceof Date?{__type:"Date",iso:e.toJSON()}:e instanceof RegExp?e.source:e}static _quote(e){return`\\Q${e.replace("\\E","\\E\\\\E\\Q")}\\E`}static _calculateFlag(e){return["withLastMessagesRefreshed","compact"].reduce((t,r)=>(t<<1)+Boolean(e[r]),0)}static and(...e){if(e.length<2)throw new Error("The queries must contain at least two elements");if(!e.every(e=>e instanceof Yo))throw new Error("The element of queries must be an instance of ConversationQuery");const t=new Yo(e[0]._client);return t._where.$and=e.map(e=>e._where),t}static or(...e){const t=Yo.and(...e);return t._where.$or=t._where.$and,delete t._where.$and,t}constructor(e){this._client=e,this._where={},this._extraOptions={}}_addCondition(e,t,r){return this._where[e]||(this._where[e]={}),this._where[e][t]=this.constructor._encode(r),this}toJSON(){const e={where:this._where,flag:this.constructor._calculateFlag(this._extraOptions)};return void 0!==this._skip&&(e.skip=this._skip),void 0!==this._limit&&(e.limit=this._limit),void 0!==this._order&&(e.sort=this._order),Vo(e),e}containsMembers(e){return this.containsAll("m",e)}withMembers(e,t){const r=new Set(e);return t&&r.add(this._client.id),this.sizeEqualTo("m",r.size),this.containsMembers(Array.from(r))}equalTo(e,t){return this._where[e]=this.constructor._encode(t),this}lessThan(e,t){return this._addCondition(e,"$lt",t)}lessThanOrEqualTo(e,t){return this._addCondition(e,"$lte",t)}greaterThan(e,t){return this._addCondition(e,"$gt",t)}greaterThanOrEqualTo(e,t){return this._addCondition(e,"$gte",t)}notEqualTo(e,t){return this._addCondition(e,"$ne",t)}exists(e){return this._addCondition(e,"$exists",!0)}doesNotExist(e){return this._addCondition(e,"$exists",!1)}containedIn(e,t){return this._addCondition(e,"$in",t)}notContainsIn(e,t){return this._addCondition(e,"$nin",t)}containsAll(e,t){return this._addCondition(e,"$all",t)}contains(e,t){return this._addCondition(e,"$regex",Yo._quote(t))}startsWith(e,t){return this._addCondition(e,"$regex",`^${Yo._quote(t)}`)}endsWith(e,t){return this._addCondition(e,"$regex",`${Yo._quote(t)}$`)}matches(e,t){this._addCondition(e,"$regex",t);let r="";return t.ignoreCase&&(r+="i"),t.multiline&&(r+="m"),r&&r.length&&this._addCondition(e,"$options",r),this}sizeEqualTo(e,t){return this._addCondition(e,"$size",t)}limit(e){return this._limit=e,this}skip(e){return this._skip=e,this}ascending(e){return this._order=e,this}addAscending(e){return this._order?this._order+=`,${e}`:this._order=e,this}descending(e){return this._order=`-${e}`,this}addDescending(e){return this._order?this._order+=`,-${e}`:this._order=`-${e}`,this}withLastMessagesRefreshed(e=!0){return this._extraOptions.withLastMessagesRefreshed=e,this}compact(e=!0){return this._extraOptions.compact=e,this}async find(){return this._client._executeQuery(this)}async first(){return(await this.limit(1).find())[0]}}const qo=be("LC:SessionManager");class $o{constructor({refresh:e,onBeforeGetSessionToken:t}={}){this.refresh=e,this._onBeforeGetSessionToken=t,this.setSessionToken(null,0)}setSessionToken(e,t){qo("set session token",e,t);const r=new jt(e,1e3*t);return this._sessionToken=r,delete this._pendingSessionTokenPromise,r}async setSessionTokenAsync(e){const t=this._sessionToken;return this._pendingSessionTokenPromise=e.catch(e=>{throw this._sessionToken=t,e}),this.setSessionToken(...await this._pendingSessionTokenPromise)}async getSessionToken({autoRefresh:e=!0}={}){qo("get session token"),this._onBeforeGetSessionToken&&this._onBeforeGetSessionToken(this);const{value:t,originalValue:r}=this._sessionToken||await this._pendingSessionTokenPromise;if(t===jt.EXPIRED&&e&&this.refresh){qo("refresh expired session token");const{value:e}=await this.setSessionTokenAsync(this.refresh(this,r));return qo("session token",e),e}return qo("session token",t),t}revoke(){this._sessionToken&&(this._sessionToken.expiredAt=-1)}}var zo,Wo,Go;const Jo=be("LC:IMClient"),{INVITED:Zo,KICKED:Ho,MEMBERS_JOINED:Xo,MEMBERS_LEFT:Ko,MEMBER_INFO_UPDATED:Qo,BLOCKED:ea,UNBLOCKED:ta,MEMBERS_BLOCKED:ra,MEMBERS_UNBLOCKED:na,MUTED:ia,UNMUTED:sa,MEMBERS_MUTED:oa,MEMBERS_UNMUTED:aa,MESSAGE:ua,UNREAD_MESSAGES_COUNT_UPDATE:la,CLOSE:ca,CONFLICT:ha,UNHANDLED_MESSAGE:fa,CONVERSATION_INFO_UPDATED:da,MESSAGE_RECALL:pa,MESSAGE_UPDATE:ma,INFO_UPDATED:ga}=ho,ya=e=>/^_tmp:/.test(e);let va=(zo=ir(1e3),Wo=ir(1e3),_t((Go=class extends he{constructor(e,t={},r){if(void 0!==e&&"string"!=typeof e)throw new TypeError(`Client id [${e}] is not a String`);if(super(),Object.assign(this,{id:e,options:t},r),!this._messageParser)throw new Error("IMClient must be initialized with a MessageParser");this._conversationCache=new Ut(`client:${this.id}`),this._ackMessageBuffer={},Kt(this).lastPatchTime=Date.now(),Kt(this).lastNotificationTime=void 0,Kt(this)._eventemitter=new he,Jo.enabled&&vt(ho).forEach(e=>this.on(e,(...t)=>this._debug(`${e} event emitted. %o`,t))),Ir(this._plugins.onIMClientCreate,this)}_debug(...e){Jo(...e,`[${this.id}]`)}async _dispatchCommand(e){switch(this._debug(er(e),"received"),e.serverTs&&1===e.notificationType&&(Kt(this).lastNotificationTime=qt(Yt(e.serverTs))),e.cmd){case ae.conv:return this._dispatchConvMessage(e);case ae.direct:return this._dispatchDirectMessage(e);case ae.session:return this._dispatchSessionMessage(e);case ae.unread:return this._dispatchUnreadMessage(e);case ae.rcp:return this._dispatchRcpMessage(e);case ae.patch:return this._dispatchPatchMessage(e);default:return this.emit(fa,e)}}async _dispatchSessionMessage(e){const{sessionMessage:{code:t,reason:r}}=e;switch(e.op){case ue.closed:return Kt(this)._eventemitter.emit("close"),t===yr.SESSION_CONFLICT?this.emit(ha,{reason:r}):this.emit(ca,{code:t,reason:r});default:throw this.emit(fa,e),new Error("Unrecognized session command")}}_dispatchUnreadMessage({unreadMessage:{convs:e,notifTime:t}}){return Kt(this).lastUnreadNotifTime=t,this.getConversations(e.map(e=>e.cid)).then(()=>Promise.all(e.map(({cid:e,unread:t,mid:r,timestamp:n,from:i,data:s,binaryMsg:o,patchTimestamp:a,mentioned:u})=>{const l=this._conversationCache.get(e);if(!l)return null;let c;return n&&(c=Yt(n),l.lastMessageAt=c),(r?this._messageParser.parse(o||s).then(t=>{const n={id:r,cid:e,timestamp:c,updatedAt:a,from:i};Object.assign(t,n),l.lastMessage=t}):Promise.resolve()).then(()=>(l._setUnreadMessagesMentioned(u),t===Kt(l).unreadMessagesCount?null:(Kt(l).unreadMessagesCount=t,l)))})).then(e=>e.filter(e=>e))).then(e=>{e.length&&this.emit(la,e)})}async _dispatchRcpMessage(e){const{rcpMessage:t,rcpMessage:{read:r}}=e,n=t.cid,i=t.id,s=Yt(t.t),o=this._conversationCache.get(n);o&&o._handleReceipt({messageId:i,timestamp:s,read:r})}_dispatchPatchMessage({patchMessage:{patches:e}}){return this.getConversations(e.map(e=>e.cid)).then(()=>Promise.all(e.map(({cid:e,mid:t,timestamp:r,recall:n,data:i,patchTimestamp:s,from:o,binaryMsg:a,mentionAll:u,mentionPids:l,patchCode:c,patchReason:h})=>{const f=this._conversationCache.get(e);return f?this._messageParser.parse(a||i).then(i=>{const a=qt(Yt(s)),d={id:t,cid:e,timestamp:r,updatedAt:a,from:o,mentionList:l,mentionedAll:u};let p;Object.assign(i,d),i._setStatus(fo.SENT),i._updateMentioned(this.id),Kt(this).lastPatchTime<a&&(Kt(this).lastPatchTime=a),f.lastMessage&&f.lastMessage.id===t&&(f.lastMessage=i),c&&(p={code:c.toNumber(),detail:h}),n?(this.emit(pa,i,f,p),f.emit(pa,i,p)):(this.emit(ma,i,f,p),f.emit(ma,i,p))}):null})))}async _dispatchConvMessage(e){const{convMessage:t,convMessage:{initBy:r,m:n,info:i,attr:s}}=e,o=await this.getConversation(t.cid);switch(e.op){case ue.joined:{o._addMembers([this.id]);const e={invitedBy:r};return this.emit(Zo,e,o),void o.emit(Zo,e)}case ue.left:{o._removeMembers([this.id]);const e={kickedBy:r};return this.emit(Ho,e,o),void o.emit(Ho,e)}case ue.members_joined:{o._addMembers(n);const e={invitedBy:r,members:n};return this.emit(Xo,e,o),void o.emit(Xo,e)}case ue.members_left:{o._removeMembers(n);const e={kickedBy:r,members:n};return this.emit(Ko,e,o),void o.emit(Ko,e)}case ue.members_blocked:{const e={blockedBy:r,members:n};return this.emit(ra,e,o),void o.emit(ra,e)}case ue.members_unblocked:{const e={unblockedBy:r,members:n};return this.emit(na,e,o),void o.emit(na,e)}case ue.blocked:{const e={blockedBy:r};return this.emit(ea,e,o),void o.emit(ea,e)}case ue.unblocked:{const e={unblockedBy:r};return this.emit(ta,e,o),void o.emit(ta,e)}case ue.members_shutuped:{const e={mutedBy:r,members:n};return this.emit(oa,e,o),void o.emit(oa,e)}case ue.members_unshutuped:{const e={unmutedBy:r,members:n};return this.emit(aa,e,o),void o.emit(aa,e)}case ue.shutuped:{const e={mutedBy:r};return this.emit(ia,e,o),void o.emit(ia,e)}case ue.unshutuped:{const e={unmutedBy:r};return this.emit(sa,e,o),void o.emit(sa,e)}case ue.member_info_changed:{const{pid:e,role:t}=i,{memberInfoMap:n}=Kt(o);if(!n&&!t)return;const s=await o.getMemberInfo(e);Kt(s).role=t;const a={member:e,memberInfo:s,updatedBy:r};return this.emit(Qo,a,o),void o.emit(Qo,a)}case ue.updated:{const e=$t(JSON.parse(s.data));o._updateServerAttributes(e);const t={attributes:e,updatedBy:r};return this.emit(da,t,o),void o.emit(ga,t)}default:throw this.emit(fa,e),new Error("Unrecognized conversation command")}}_dispatchDirectMessage(e){const{directMessage:t,directMessage:{id:r,cid:n,fromPeerId:i,timestamp:s,transient:o,patchTimestamp:a,mentionPids:u,mentionAll:l,binaryMsg:c,msg:h}}=e,f=c?c.toArrayBuffer():h;return Promise.all([this.getConversation(t.cid),this._messageParser.parse(f)]).then(([e,t])=>{if(!e)return;const c={id:r,cid:n,timestamp:s,updatedAt:a,from:i,mentionList:u,mentionedAll:l};return Object.assign(t,c),t._updateMentioned(this.id),t._setStatus(fo.SENT),t.from!==this.id&&(o||e.transient||this._sendAck(t)),this._dispatchParsedMessage(t,e)})}_dispatchParsedMessage(e,t){return Or(this._plugins.beforeMessageDispatch,[e,t]).then(r=>{!1!==r&&(t.lastMessage=e,t.lastMessageAt=e.timestamp,e.from!==this.id&&(t.unreadMessagesCount+=1,e.mentioned&&t._setUnreadMessagesMentioned(!0)),this.emit(ua,e,t),t.emit(ua,e))})}_sendAck(e){this._debug("send ack for %O",e);const{cid:t}=e;if(!t)throw new Error("missing cid");return this._ackMessageBuffer[t]||(this._ackMessageBuffer[t]=[]),this._ackMessageBuffer[t].push(e),this._doSendAck()}_doSendAck(){this._connection.is("connected")&&(this._debug("do send ack %O",this._ackMessageBuffer),Promise.all(Object.keys(this._ackMessageBuffer).map(e=>{const t=this._ackMessageBuffer[e],r=t.map(e=>e.timestamp),n=new re({cmd:"ack",ackMessage:new z({cid:e,fromts:Math.min.apply(null,r),tots:Math.max.apply(null,r)})});return delete this._ackMessageBuffer[e],this._send(n,!1).catch(r=>{this._debug("send ack failed: %O",r),this._ackMessageBuffer[e]=t})})))}_omitPeerId(e){Kt(this).peerIdOmittable=e}_send(e,...t){const r=e;return!Kt(this).peerIdOmittable&&this.id&&(r.peerId=this.id),this._connection.send(r,...t)}async _open(e,t,r,n=!1){this._debug("open session");const{lastUnreadNotifTime:i,lastPatchTime:s,lastNotificationTime:o}=Kt(this),a=new re({cmd:"session",op:"open",appId:e,peerId:this.id,sessionMessage:new Y({ua:"js/5.0.0-rc.7",r:n,lastUnreadNotifTime:i,lastPatchTime:s,configBitmap:187})});if(n){const e=await this._sessionManager.getSessionToken({autoRefresh:!1});e&&e!==jt.EXPIRED&&Object.assign(a.sessionMessage,{st:e})}else if(Object.assign(a.sessionMessage,er({tag:t,deviceId:r})),this.options.signatureFactory){const e=await Po(this.options.signatureFactory,[this._identity]);Object.assign(a.sessionMessage,Wt({signature:"s",timestamp:"t",nonce:"n"},e))}let u;try{u=await this._send(a)}catch(i){if(i.code===yr.SESSION_TOKEN_EXPIRED){if(!this._sessionManager)throw new Error("Unexpected session expiration");return Jo("Session token expired, reopening"),this._sessionManager.revoke(),this._open(e,t,r,n)}throw i}const{peerId:l,sessionMessage:c,sessionMessage:{st:h,stTtl:f,code:d},serverTs:p}=u;if(d)throw vr(c);if(l){this.id=l,this._identity||(this._identity=l),h&&(this._sessionManager=this._sessionManager||this._createSessionManager(),this._sessionManager.setSessionToken(h,f));const e=qt(Yt(p));p&&(Kt(this).lastPatchTime=e),o?this._syncNotifications(o).catch(e=>console.warn("Syncing notifications failed:",e)):Kt(this).lastNotificationTime=e}else console.warn("Unexpected session opened without peerId.")}async _syncNotifications(e){const{hasMore:t,notifications:r}=await this._fetchNotifications(e);if(r.forEach(e=>{const{cmd:t,op:r,serverTs:n,notificationType:i,...s}=e;this._dispatchCommand({cmd:ae[t],op:ue[r],serverTs:n,notificationType:i,[`${t}Message`]:s})}),t)return this._syncNotifications(Kt(this).lastNotificationTime)}async _fetchNotifications(e){return this._requestWithSessionToken({method:"GET",path:"/rtm/notifications",query:{start_ts:e,notification_type:"permanent"}})}_createSessionManager(){return Jo("create SessionManager"),new $o({onBeforeGetSessionToken:this._connection.checkConnectionAvailability.bind(this._connection),refresh:(e,t)=>e.setSessionTokenAsync(Promise.resolve(new re({cmd:"session",op:"refresh",sessionMessage:new Y({ua:"js/5.0.0-rc.7",st:t})})).then(async e=>{if(this.options.signatureFactory){const t=await Po(this.options.signatureFactory,[this._identity]);Object.assign(e.sessionMessage,Wt({signature:"s",timestamp:"t",nonce:"n"},t))}return e}).then(this._send.bind(this)).then(({sessionMessage:{st:e,stTtl:t}})=>[e,t]))})}async _requestWithSessionToken({headers:e,query:t,...r}){const n=await this._sessionManager.getSessionToken();return this._request({headers:{"X-LC-IM-Session-Token":n,...e},query:{client_id:this.id,...t},...r})}async close(){this._debug("close session");const e=Kt(this)._eventemitter;if(e.emit("beforeclose"),this._connection.is("connected")){const e=new re({cmd:"session",op:"close"});await this._send(e)}e.emit("close"),this.emit(ca,{code:0})}async ping(e){if(this._debug("ping"),!(e instanceof Array))throw new TypeError(`clientIds ${e} is not an Array`);if(!e.length)return Promise.resolve([]);const t=new re({cmd:"session",op:"query",sessionMessage:new Y({sessionPeerIds:e})});return(await this._send(t)).sessionMessage.onlineSessionPeerIds}async getConversation(e,t=!1){if("string"!=typeof e)throw new TypeError(`${e} is not a String`);if(!t){const t=this._conversationCache.get(e);if(t)return t}return ya(e)?(await this._getTemporaryConversations([e]))[0]||null:this.getQuery().equalTo("objectId",e).find().then(e=>e[0]||null)}async getConversations(e,t=!1){const r=t?e:e.filter(e=>null===this._conversationCache.get(e));if(r.length){const e=as(r,ya),t=[];if(r.length&&t.push(this.getQuery().containedIn("objectId",r).limit(999).find()),e.length){const r=e.map(this._getTemporaryConversations.bind(this));t.push(...r)}await Promise.all(t)}return e.map(e=>this._conversationCache.get(e))}async _getTemporaryConversations(e){const t=new re({cmd:"conv",op:"query",convMessage:new G({tempConvIds:e})}),r=await this._send(t);return this._handleQueryResults(r)}getQuery(){return new Yo(this)}getChatRoomQuery(){return this.getQuery().equalTo("tr",!0)}getServiceConversationQuery(){return this.getQuery().equalTo("sys",!0)}async _executeQuery(e){const t=e.toJSON();t.where=new U({data:JSON.stringify(zt(t.where))});const r=new re({cmd:"conv",op:"query",convMessage:new G(t)}),n=await this._send(r);return this._handleQueryResults(n)}async _handleQueryResults(e){let t;try{t=$t(JSON.parse(e.convMessage.results.data))}catch(t){const r=JSON.stringify(er(e));throw new Error(`Parse query result failed: ${t.message}. Command: ${r}`)}return t=await Promise.all(t.map(this._parseConversationFromRawData.bind(this))),t.map(this._upsertConversationToCache.bind(this))}_upsertConversationToCache(e){let t=this._conversationCache.get(e.id);return t?(this._debug("update cached conversation"),["creator","createdAt","updatedAt","lastMessageAt","lastMessage","mutedMembers","members","_attributes","transient","muted"].forEach(r=>{const n=e[r];void 0!==n&&(t[r]=n)}),t._reset&&t._reset()):(t=e,this._debug("no match, set cache"),this._conversationCache.set(e.id,e)),t}async parseMessage({data:e,bin:t=!1,...r}){const n=t?Vr(e):e,i=await this._messageParser.parse(n);return Object.assign(i,r),i._updateMentioned(this.id),i}async parseConversation({id:e,lastMessageAt:t,lastMessage:r,lastDeliveredAt:n,lastReadAt:i,unreadMessagesCount:s,members:o,mentioned:a,...u}){const l={id:e,lastMessageAt:t,lastMessage:r,lastDeliveredAt:n,lastReadAt:i,unreadMessagesCount:s,members:o,mentioned:a};r&&(l.lastMessage=await this.parseMessage(r),l.lastMessage._setStatus(fo.SENT));const{transient:c,system:h,expiredAt:f}=u;return c?new Do(l,u,this):h?new Uo(l,u,this):f||ya(e)?new Bo(l,{expiredAt:f},this):new jo(l,u,this)}async _parseConversationFromRawData(e){const t=Wt({objectId:"id",lm:"lastMessageAt",m:"members",tr:"transient",sys:"system",c:"creator",mu:"mutedMembers"},e);t.msg&&(t.lastMessage={data:t.msg,bin:t.bin,from:t.msg_from,id:t.msg_mid,timestamp:t.msg_timestamp,updatedAt:t.patch_timestamp},delete t.lastMessageFrom,delete t.lastMessageId,delete t.lastMessageTimestamp,delete t.lastMessagePatchTimestamp);const{ttl:r}=t;return r&&(t.expiredAt=Date.now()+1e3*r),this.parseConversation(t)}async createConversation({members:e,name:t,transient:r,unique:n=!0,_tempConv:i,_tempConvTTL:s,...o}={}){if(!r&&!Array.isArray(e))throw new TypeError(`conversation members ${e} is not an array`);let a=new Set(e);a.add(this.id),a=Array.from(a).sort();let u=o||{};if(t){if("string"!=typeof t)throw new TypeError(`conversation name ${t} is not a string`);u.name=t}u=new U({data:JSON.stringify(zt(u))});const l=new re({cmd:"conv",op:"start",convMessage:new G({m:a,attr:u,transient:r,unique:n,tempConv:i,tempConvTTL:s})});if(this.options.conversationSignatureFactory){const e=[null,this._identity,a,"create"],t=await Po(this.options.conversationSignatureFactory,e);Object.assign(l.convMessage,Wt({signature:"s",timestamp:"t",nonce:"n"},t))}const{convMessage:{cid:c,cdate:h,tempConvTTL:f}}=await this._send(l),d={name:t,transient:r,unique:n,id:c,createdAt:h,updatedAt:h,lastMessageAt:null,creator:this.id,members:r?[]:a,...o};f&&(d.expiredAt=Date.now()+1e3*f);const p=await this.parseConversation(d);return this._upsertConversationToCache(p)}async createChatRoom(e){return this.createConversation({...e,transient:!0,members:null,unique:!1,_tempConv:!1})}async createTemporaryConversation({ttl:e,...t}){return this.createConversation({...t,_tempConv:!0,_tempConvTTL:e})}_doSendRead(){if(!this._connection.is("connected"))return;const e=Kt(this).readConversationsBuffer,t=Array.from(e);if(!t.length)return;const r=t.map(e=>{if(!(e instanceof Oo))throw new TypeError(`${e} is not a Conversation`);return e.id});this._debug(`mark [${r}] as read`),e.clear(),this._sendReadCommand(t).catch(r=>{this._debug("send read failed: %O",r),t.forEach(e.add.bind(e))})}_sendReadCommand(e){return this._send(new re({cmd:"read",readMessage:new Q({convs:e.map(e=>new X({cid:e.id,mid:e.lastMessage&&e.lastMessage.from!==this.id?e.lastMessage.id:void 0,timestamp:(e.lastMessageAt||new Date).getTime()}))})}),!1)}}).prototype,"_doSendAck",[zo],Object.getOwnPropertyDescriptor(Go.prototype,"_doSendAck"),Go.prototype),_t(Go.prototype,"_doSendRead",[Wo],Object.getOwnPropertyDescriptor(Go.prototype,"_doSendRead"),Go.prototype),Go);var ba,wa=Object.freeze({__proto__:null,RECONNECT_ERROR:"reconnecterror",DISCONNECT:ar,RECONNECT:ur,RETRY:lr,SCHEDULE:cr,OFFLINE:hr,ONLINE:fr});let _a=vo(ba=class extends mo{constructor(e){if(!(e instanceof ArrayBuffer))throw new TypeError(`${e} is not an ArrayBuffer`);super(e)}get buffer(){return this.content}set buffer(e){this.content=e}static validate(e){return e instanceof ArrayBuffer}toJSON(){return{...super._toJSON(),data:Br(this.content)}}toFullJSON(){return{...super.toFullJSON(),bin:!0,data:Br(this.content)}}})||ba;var Ea;let Ta=go(-1)(Ea=vo(Ea=class extends wo{constructor(e=""){if("string"!=typeof e)throw new TypeError(`${e} is not a string`);super(),this.setText(e)}})||Ea)||Ea;var Sa;const Aa=be("LC:MessageParser");let Ia=(_t((Sa=class{constructor(e={}){this._plugins=e,this._messageClasses=[],this.register(e.messageClasses)}register(e){tr(e).map(e=>this._register(e))}_register(e){if(!(e&&e.parse&&e.prototype&&e.prototype.getPayload))throw new TypeError("Invalid messageClass");this._messageClasses.unshift(e)}parse(e){Aa("parsing message: %O",e);for(const t of this._messageClasses){const r=Nt(e)?{...e}:e;let n,i;try{n=t.validate(r)}catch(e){}if(n){try{i=t.parse(r)}catch(e){console.warn("parsing a valid message content error",{error:e,Klass:t,content:r})}if(void 0!==i)return Aa("parse result: %O",i),i}}throw new Error("No Message Class matched")}}).prototype,"parse",[(e,t,r)=>{const n=r.value;r.value=function(e){let t;if("string"!=typeof e)t=e;else try{t=JSON.parse(e)}catch(r){t=e}return n.call(this,t)}},(e,t,r)=>{const n=r.value;r.value=function(e){return Promise.resolve(e).then(Cr(this._plugins.beforeMessageParse)).then(e=>n.call(this,e)).then(Cr(this._plugins.afterMessageParse))}}],Object.getOwnPropertyDescriptor(Sa.prototype,"parse"),Sa.prototype),Sa);const Ca=be("LC:IMPlugin"),Oa={HIGH:1,NORMAL:2,LOW:3};Object.freeze(Oa);const Ma=(e,t={get(){return this.get(e)},set(t){this.set(e,t)}})=>{Object.defineProperty(jo.prototype,e,t)},Ra={name:"leancloud-realtime-plugin-im",onRealtimeCreate:e=>{const t=Ur();e._IMClients={},e._IMClientsCreationCount=0;const r=new Ia(e._plugins);e._messageParser=r;const n=async t=>e._request({method:"POST",path:"/rtm/sign",data:{session_token:t.getSessionToken()}}),i=r.register.bind(r);Object.assign(e,{register:i,createIMClient:async(i,{tag:s,isReconnect:o,...a}={},u)=>{let l;const c={};if(i){if("string"==typeof i)l=i;else{if(!i.id||!i.getSessionToken)throw new TypeError("Identity must be a String or an AV.User");if(({id:l}=i),!i.getSessionToken())throw new Error("User must be authenticated");c.signatureFactory=n}if(void 0!==e._IMClients[l])return e._IMClients[l]}u&&console.warn("DEPRECATION createIMClient tag param: Use options.tag instead.");const h=s||u,f=e._open().then(n=>{const s=new va(l,{...c,...a},{_connection:n,_request:e._request.bind(e),_messageParser:r,_plugins:e._plugins,_identity:i});return n.on(ur,()=>s._open(e._options.appId,h,t,!0).then(()=>s.emit(ur),e=>s.emit("reconnecterror",e))),Kt(s)._eventemitter.on("beforeclose",()=>{delete e._IMClients[s.id],e._firstIMClient===s&&delete e._firstIMClient},e),Kt(s)._eventemitter.on("close",()=>{e._deregister(s)},e),s._open(e._options.appId,h,t,o).then(()=>(e._IMClients[s.id]=s,e._IMClientsCreationCount+=1,1===e._IMClientsCreationCount?(s._omitPeerId(!0),e._firstIMClient=s):e._IMClientsCreationCount>1&&e._firstIMClient&&e._firstIMClient._omitPeerId(!1),e._register(s),s)).catch(t=>{throw delete e._IMClients[s.id],t})}).then(...(d=()=>{e._deregisterPending(f)},[e=>(d(),e),e=>{throw d(),e}])).catch(t=>{throw delete e._IMClients[l],t});var d;return i&&(e._IMClients[l]=f),e._registerPending(f),f}})},beforeCommandDispatch:(e,t)=>{if(!(null===e.service||2===e.service))return!0;const r=e.peerId?t._IMClients[e.peerId]:t._firstIMClient;return r?Promise.resolve(r).then(t=>t._dispatchCommand(e)).catch(Ca):Ca("[WARN] Unexpected message received without any live client match: %O",er(e)),!1},messageClasses:[mo,_a,Eo,Ta]};Nr.defineConversationProperty=Ma,Nr.__preRegisteredPlugins=[Ra];const Pa={...wa,...ho};At({WebSocket:L,request:N}),e.BinaryMessage=_a,e.ChatRoom=Do,e.Conversation=jo,e.ConversationMemberRole=xo,e.ConversationQuery=Yo,e.ErrorCode=yr,e.Event=Pa,e.EventEmitter=he,e.IE10Compatible=vo,e.IMPlugin=Ra,e.Message=mo,e.MessageParser=Ia,e.MessagePriority=Oa,e.MessageQueryDirection=Co,e.MessageStatus=fo,e.Promise=Lr,e.Protocals=ce,e.Protocols=ce,e.Realtime=Nr,e.RecalledMessage=Eo,e.ServiceConversation=Uo,e.TemporaryConversation=Bo,e.TextMessage=Ta,e.TypedMessage=wo,e.debug=Ft,e.defineConversationProperty=Ma,e.getAdapter=St,e.messageField=yo,e.messageType=go,e.setAdapters=At,Object.defineProperty(e,"__esModule",{value:!0})}));
  21. //# sourceMappingURL=im-browser.min.js.map