@jokio/sdk 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4189,7 +4189,7 @@ var C;
4189
4189
  for (m = 0; m < f; m++) u[m] = b[m];
4190
4190
  or(b);
4191
4191
  });
4192
- } else typeof require < "u" && (c = require("crypto"), c && c.randomBytes && r.setPRNG(function(u, f) {
4192
+ } else typeof require < "u" && (crypto = window.crypto || globalThis.crypto, c && c.randomBytes && r.setPRNG(function(u, f) {
4193
4193
  var m, b = c.randomBytes(f);
4194
4194
  for (m = 0; m < f; m++) u[m] = b[m];
4195
4195
  or(b);
@@ -8538,7 +8538,7 @@ class Ho {
8538
8538
  const oi = {
8539
8539
  debug: !1,
8540
8540
  authUrl: "https://auth.jok.io",
8541
- natsUrl: "https://natsx.jok.io",
8541
+ natsUrl: "https://nats.jok.io",
8542
8542
  storage: new ii()
8543
8543
  }, Mr = new Fr(oi), Jo = {
8544
8544
  setup(r) {
@@ -10,7 +10,7 @@ ${t}: ${s[i]}`;return`${e}\r
10
10
  ${this.ctx.stack}`),this.cancel(t)):(this.callback(null,s),this.opts.strategy===ke.Count&&(this.max--,this.max===0&&this.cancel()),this.opts.strategy===ke.JitterTimer&&(clearTimeout(this.timer),this.timer=setTimeout(()=>{this.cancel()},this.opts.jitter||300)),this.opts.strategy===ke.SentinelMsg&&s&&s.data.length===0&&this.cancel())}}class Sr extends xr{constructor(t,s,i={timeout:1e3},n=!0){super(t,s,n);h(this,"deferred");h(this,"timer");this.deferred=z(),this.timer=Ye(i.timeout,n)}resolver(t,s){this.timer&&this.timer.cancel(),t?(this.ctx&&(t.stack+=`
11
11
 
12
12
  ${this.ctx.stack}`),this.deferred.reject(t)):this.deferred.resolve(s),this.cancel()}cancel(t){this.timer&&this.timer.cancel(),this.mux.cancel(this),this.deferred.reject(t||N.errorForCode(k.Cancelled))}}const Ki="$JS.API";function Vi(r){return r=r||{},r.domain&&(r.apiPrefix=`$JS.${r.domain}.API`,delete r.domain),Tt({apiPrefix:Ki,timeout:5e3},r)}class gt{constructor(e,t){h(this,"nc");h(this,"opts");h(this,"prefix");h(this,"timeout");h(this,"jc");this.nc=e,this.opts=Vi(t),this._parseOpts(),this.prefix=this.opts.apiPrefix,this.timeout=this.opts.timeout,this.jc=ve()}getOptions(){return Object.assign({},this.opts)}_parseOpts(){let e=this.opts.apiPrefix;if(!e||e.length===0)throw new Error("invalid empty prefix");e[e.length-1]==="."&&(e=e.substr(0,e.length-1)),this.opts.apiPrefix=e}async _request(e,t=null,s){s=s||{},s.timeout=this.timeout;let i=be;t&&(i=this.jc.encode(t));let{retries:n}=s;n=n||1,n=n===-1?Number.MAX_SAFE_INTEGER:n;const o=us();for(let a=0;a<n;a++)try{const d=await this.nc.request(e,i,s);return this.parseJsResponse(d)}catch(d){const p=d;if((p.code==="503"||p.code===k.Timeout)&&a+1<n)await Xe(o.backoff(a));else throw d}}async findStream(e){const t={subject:e},i=await this._request(`${this.prefix}.STREAM.NAMES`,t);if(!i.streams||i.streams.length!==1)throw new Error("no stream matches subject");return i.streams[0]}getConnection(){return this.nc}parseJsResponse(e){const t=this.jc.decode(e.data),s=t;if(s.error){const i=dr(s.error.code,s.error.description);if(i!==null)throw i.api_error=s.error,i}return t}}class _t{constructor(e,t,s,i){h(this,"err");h(this,"offset");h(this,"pageInfo");h(this,"subject");h(this,"jsm");h(this,"filter");h(this,"payload");if(!e)throw new Error("subject is required");this.subject=e,this.jsm=s,this.offset=0,this.pageInfo={},this.filter=t,this.payload=i||{}}async next(){if(this.err)return[];if(this.pageInfo&&this.offset>=this.pageInfo.total)return[];const e={offset:this.offset};this.payload&&Object.assign(e,this.payload);try{const t=await this.jsm._request(this.subject,e,{timeout:this.jsm.timeout});this.pageInfo=t;const s=this.countResponse(t);return s===0?[]:(this.offset+=s,this.filter(t))}catch(t){throw this.err=t,t}}countResponse(e){var t,s,i;switch(e==null?void 0:e.type){case"io.nats.jetstream.api.v1.stream_names_response":case"io.nats.jetstream.api.v1.stream_list_response":return((t=e.streams)==null?void 0:t.length)||0;case"io.nats.jetstream.api.v1.consumer_list_response":return((s=e.consumers)==null?void 0:s.length)||0;default:return console.error(`jslister.ts: unknown API response for paged output: ${e==null?void 0:e.type}`),((i=e.streams)==null?void 0:i.length)||0}return 0}async*[Symbol.asyncIterator](){let e=await this.next();for(;e.length>0;){for(const t of e)yield t;e=await this.next()}}}function Ke(r=""){const e=r.match(/(\d+).(\d+).(\d+)/);if(e)return{major:parseInt(e[1]),minor:parseInt(e[2]),micro:parseInt(e[3])};throw new Error(`'${r}' is not a semver value`)}function xs(r,e){return r.major<e.major?-1:r.major>e.major?1:r.minor<e.minor?-1:r.minor>e.minor?1:r.micro<e.micro?-1:r.micro>e.micro?1:0}var H;(function(r){r.JS_KV="js_kv",r.JS_OBJECTSTORE="js_objectstore",r.JS_PULL_MAX_BYTES="js_pull_max_bytes",r.JS_NEW_CONSUMER_CREATE_API="js_new_consumer_create",r.JS_ALLOW_DIRECT="js_allow_direct",r.JS_MULTIPLE_CONSUMER_FILTER="js_multiple_consumer_filter",r.JS_SIMPLIFICATION="js_simplification",r.JS_STREAM_CONSUMER_METADATA="js_stream_consumer_metadata",r.JS_CONSUMER_FILTER_SUBJECTS="js_consumer_filter_subjects",r.JS_STREAM_FIRST_SEQ="js_stream_first_seq",r.JS_STREAM_SUBJECT_TRANSFORM="js_stream_subject_transform",r.JS_STREAM_SOURCE_SUBJECT_TRANSFORM="js_stream_source_subject_transform",r.JS_STREAM_COMPRESSION="js_stream_compression",r.JS_DEFAULT_CONSUMER_LIMITS="js_default_consumer_limits",r.JS_BATCH_DIRECT_GET="js_batch_direct_get"})(H||(H={}));class Wi{constructor(e){h(this,"server");h(this,"features");h(this,"disabled");this.features=new Map,this.disabled=[],this.update(e)}resetDisabled(){this.disabled.length=0,this.update(this.server)}disable(e){this.disabled.push(e),this.update(this.server)}isDisabled(e){return this.disabled.indexOf(e)!==-1}update(e){typeof e=="string"&&(e=Ke(e)),this.server=e,this.set(H.JS_KV,"2.6.2"),this.set(H.JS_OBJECTSTORE,"2.6.3"),this.set(H.JS_PULL_MAX_BYTES,"2.8.3"),this.set(H.JS_NEW_CONSUMER_CREATE_API,"2.9.0"),this.set(H.JS_ALLOW_DIRECT,"2.9.0"),this.set(H.JS_MULTIPLE_CONSUMER_FILTER,"2.10.0"),this.set(H.JS_SIMPLIFICATION,"2.9.4"),this.set(H.JS_STREAM_CONSUMER_METADATA,"2.10.0"),this.set(H.JS_CONSUMER_FILTER_SUBJECTS,"2.10.0"),this.set(H.JS_STREAM_FIRST_SEQ,"2.10.0"),this.set(H.JS_STREAM_SUBJECT_TRANSFORM,"2.10.0"),this.set(H.JS_STREAM_SOURCE_SUBJECT_TRANSFORM,"2.10.0"),this.set(H.JS_STREAM_COMPRESSION,"2.10.0"),this.set(H.JS_DEFAULT_CONSUMER_LIMITS,"2.10.0"),this.set(H.JS_BATCH_DIRECT_GET,"2.11.0"),this.disabled.forEach(t=>{this.features.delete(t)})}set(e,t){this.features.set(e,{min:t,ok:xs(this.server,Ke(t))>=0})}get(e){return this.features.get(e)||{min:"unknown",ok:!1}}supports(e){var t;return((t=this.get(e))==null?void 0:t.ok)||!1}require(e){return typeof e=="string"&&(e=Ke(e)),xs(this.server,e)>=0}}class qt extends gt{constructor(e,t){super(e,t)}async add(e,t,s=Ut.Create){if(le(e),t.deliver_group&&t.flow_control)throw new Error("jetstream flow control is not supported with queue groups");if(t.deliver_group&&t.idle_heartbeat)throw new Error("jetstream idle heartbeat is not supported with queue groups");const i={};i.config=t,i.stream_name=e,i.action=s,i.config.durable_name&&Ze(i.config.durable_name);const n=this.nc;let{min:o,ok:a}=n.features.get(H.JS_NEW_CONSUMER_CREATE_API);const d=t.name===""?void 0:t.name;if(d&&!a)throw new Error(`consumer 'name' requires server ${o}`);if(d)try{$t("name",d)}catch(x){const P=x.message,I=P.indexOf("cannot contain");throw I!==-1?new Error(`consumer 'name' ${P.substring(I)}`):x}let p,_="";if(Array.isArray(t.filter_subjects)){const{min:x,ok:P}=n.features.get(H.JS_MULTIPLE_CONSUMER_FILTER);if(!P)throw new Error(`consumer 'filter_subjects' requires server ${x}`);a=!1}if(t.metadata){const{min:x,ok:P}=n.features.get(H.JS_STREAM_CONSUMER_METADATA);if(!P)throw new Error(`consumer 'metadata' requires server ${x}`)}if(a&&(_=t.name??t.durable_name??""),_!==""){let x=t.filter_subject??void 0;x===">"&&(x=void 0),p=x!==void 0?`${this.prefix}.CONSUMER.CREATE.${e}.${_}.${x}`:`${this.prefix}.CONSUMER.CREATE.${e}.${_}`}else p=t.durable_name?`${this.prefix}.CONSUMER.DURABLE.CREATE.${e}.${t.durable_name}`:`${this.prefix}.CONSUMER.CREATE.${e}`;return await this._request(p,i)}async update(e,t,s){const i=await this.info(e,t),n=s;return this.add(e,Object.assign(i.config,n),Ut.Update)}async info(e,t){return le(e),Ze(t),await this._request(`${this.prefix}.CONSUMER.INFO.${e}.${t}`)}async delete(e,t){return le(e),Ze(t),(await this._request(`${this.prefix}.CONSUMER.DELETE.${e}.${t}`)).success}list(e){le(e);const t=i=>i.consumers,s=`${this.prefix}.CONSUMER.LIST.${e}`;return new _t(s,t,this)}pause(e,t,s){const i=`${this.prefix}.CONSUMER.PAUSE.${e}.${t}`,n={pause_until:s.toISOString()};return this._request(i,n)}resume(e,t){return this.pause(e,t,new Date(0))}}function it(r,e,t=!1){if(t===!0&&!r)throw N.errorForCode(k.ApiError,new Error(`${e} is not a function`));if(r&&typeof r!="function")throw N.errorForCode(k.ApiError,new Error(`${e} is not a function`))}class Yi extends re{constructor(t,s,i){super();h(this,"sub");h(this,"adapter");h(this,"subIterDone");it(i.adapter,"adapter",!0),this.adapter=i.adapter,i.callback&&it(i.callback,"callback"),this.noIterator=typeof i.callback=="function",i.ingestionFilterFn&&(it(i.ingestionFilterFn,"ingestionFilterFn"),this.ingestionFilterFn=i.ingestionFilterFn),i.protocolFilterFn&&(it(i.protocolFilterFn,"protocolFilterFn"),this.protocolFilterFn=i.protocolFilterFn),i.dispatchedFn&&(it(i.dispatchedFn,"dispatchedFn"),this.dispatchedFn=i.dispatchedFn),i.cleanupFn&&it(i.cleanupFn,"cleanupFn");let n=(_,y)=>{this.callback(_,y)};if(i.callback){const _=i.callback;n=(y,x)=>{const[P,I]=this.adapter(y,x);if(P){_(P,null);return}const{ingest:T}=this.ingestionFilterFn?this.ingestionFilterFn(I,this):{ingest:!0};T&&(!this.protocolFilterFn||this.protocolFilterFn(I))&&(_(P,I),this.dispatchedFn&&I&&this.dispatchedFn(I))}}const{max:o,queue:a,timeout:d}=i,p={queue:a,timeout:d,callback:n};o&&o>0&&(p.max=o),this.sub=t.subscribe(s,p),i.cleanupFn&&(this.sub.cleanupFn=i.cleanupFn),this.noIterator||this.iterClosed.then(()=>{this.unsubscribe()}),this.subIterDone=z(),Promise.all([this.sub.closed,this.iterClosed]).then(()=>{this.subIterDone.resolve()}).catch(()=>{this.subIterDone.resolve()}),(async _=>{await _.closed,this.stop()})(this.sub).then().catch()}unsubscribe(t){this.sub.unsubscribe(t)}drain(){return this.sub.drain()}isDraining(){return this.sub.isDraining()}isClosed(){return this.sub.isClosed()}callback(t,s){this.sub.cancelTimeout();const[i,n]=this.adapter(t,s);i&&this.stop(i),n&&this.push(n)}getSubject(){return this.sub.getSubject()}getReceived(){return this.sub.getReceived()}getProcessed(){return this.sub.getProcessed()}getPending(){return this.sub.getPending()}getID(){return this.sub.getID()}getMax(){return this.sub.getMax()}get closed(){return this.sub.closed}}let we;function Xi(r){we=r}function vr(){return we!==void 0&&we.defaultPort!==void 0?we.defaultPort:4222}function Ss(){return we!==void 0&&we.urlParseFn?we.urlParseFn:void 0}function Zi(){if(!we||typeof we.factory!="function")throw new Error("transport fn is not set");return we.factory()}function vs(){return we!==void 0&&we.dnsResolveFn?we.dnsResolveFn:void 0}const Ft=`\r
13
- `,Bt=rt.fromAscii(Ft),Qi=new Uint8Array(Bt)[0],en=new Uint8Array(Bt)[1];function tn(r){for(let e=0;e<r.length;e++){const t=e+1;if(r.byteLength>t&&r[e]===Qi&&r[t]===en)return t+1}return 0}function sn(r){const e=tn(r);if(e>0){const s=new Uint8Array(r).slice(0,e);return ge.decode(s)}return""}const rn=4,Er=48,nn=65,on=97;function an(r,e,t,s){const i=new Uint8Array(16);return[0,0,0,0,0,0,0,0,0,0,255,255].forEach((o,a)=>{i[a]=o}),i[12]=r,i[13]=e,i[14]=t,i[15]=s,i}function Es(r){return cn(r)!==void 0}function cn(r){for(let e=0;e<r.length;e++)switch(r[e]){case".":return Ar(r);case":":return hn(r)}}function Ar(r){const e=new Uint8Array(4);for(let t=0;t<4;t++){if(r.length===0)return;if(t>0){if(r[0]!==".")return;r=r.substring(1)}const{n:s,c:i,ok:n}=un(r);if(!n||s>255)return;r=r.substring(i),e[t]=s}return an(e[0],e[1],e[2],e[3])}function hn(r){const e=new Uint8Array(16);let t=-1;if(r.length>=2&&r[0]===":"&&r[1]===":"&&(t=0,r=r.substring(2),r.length===0))return e;let s=0;for(;s<16;){const{n:i,c:n,ok:o}=ln(r);if(!o||i>65535)return;if(n<r.length&&r[n]==="."){if(t<0&&s!=12||s+4>16)return;const a=Ar(r);if(a===void 0)return;e[s]=a[12],e[s+1]=a[13],e[s+2]=a[14],e[s+3]=a[15],r="",s+=rn;break}if(e[s]=i>>8,e[s+1]=i,s+=2,r=r.substring(n),r.length===0)break;if(r[0]!==":"||r.length==1)return;if(r=r.substring(1),r[0]===":"){if(t>=0)return;if(t=s,r=r.substring(1),r.length===0)break}}if(r.length===0){if(s<16){if(t<0)return;const i=16-s;for(let n=s-1;n>=t;n--)e[n+i]=e[n];for(let n=t+i-1;n>=t;n--)e[n]=0}else if(t>=0)return;return e}}function un(r){let e=0,t=0;for(e=0;e<r.length&&48<=r.charCodeAt(e)&&r.charCodeAt(e)<=57;e++)if(t=t*10+(r.charCodeAt(e)-Er),t>=16777215)return{n:16777215,c:e,ok:!1};return e===0?{n:0,c:0,ok:!1}:{n:t,c:e,ok:!0}}function ln(r){let e=0,t=0;for(t=0;t<r.length;t++){if(48<=r.charCodeAt(t)&&r.charCodeAt(t)<=57)e*=16,e+=r.charCodeAt(t)-Er;else if(97<=r.charCodeAt(t)&&r.charCodeAt(t)<=102)e*=16,e+=r.charCodeAt(t)-on+10;else if(65<=r.charCodeAt(t)&&r.charCodeAt(t)<=70)e*=16,e+=r.charCodeAt(t)-nn+10;else break;if(e>=16777215)return{n:0,c:t,ok:!1}}return t===0?{n:0,c:t,ok:!1}:{n:e,c:t,ok:!0}}function fn(r){return r.indexOf("[")!==-1||r.indexOf("::")!==-1?!1:r.indexOf(".")!==-1||r.split(":").length<=2}function As(r){return!fn(r)}function dn(r){const e="::FFFF:",t=r.toUpperCase().indexOf(e);if(t!==-1&&r.indexOf(".")!==-1){let s=r.substring(t+e.length);return s=s.replace("[",""),s.replace("]","")}return r}function pn(r){r=r.trim(),r.match(/^(.*:\/\/)(.*)/m)&&(r=r.replace(/^(.*:\/\/)(.*)/gm,"$2")),r=dn(r),As(r)&&r.indexOf("[")===-1&&(r=`[${r}]`);const e=As(r)?r.match(/(]:)(\d+)/):r.match(/(:)(\d+)/),t=e&&e.length===3&&e[1]&&e[2]?parseInt(e[2]):4222,s=t===80?"https":"http",i=new URL(`${s}://${r}`);i.port=`${t}`;let n=i.hostname;return n.charAt(0)==="["&&(n=n.substring(1,n.length-1)),{listen:i.host,hostname:n,port:t}}class yt{constructor(e,t=!1){h(this,"src");h(this,"listen");h(this,"hostname");h(this,"port");h(this,"didConnect");h(this,"reconnects");h(this,"lastConnect");h(this,"gossiped");h(this,"tlsName");h(this,"resolves");this.src=e,this.tlsName="";const s=pn(e);this.listen=s.listen,this.hostname=s.hostname,this.port=s.port,this.didConnect=!1,this.reconnects=0,this.lastConnect=0,this.gossiped=t}toString(){return this.listen}async resolve(e){if(!e.fn||e.resolve===!1)return[this];const t=[];if(Es(this.hostname))return[this];{const s=await e.fn(this.hostname);e.debug&&console.log(`resolve ${this.hostname} = ${s.join(",")}`);for(const i of s){const n=this.port===80?"https":"http",o=new URL(`${n}://${As(i)?"["+i+"]":i}`);o.port=`${this.port}`;const a=new yt(o.host,!1);a.tlsName=this.hostname,t.push(a)}}return e.randomize&&hr(t),this.resolves=t,t}}class mn{constructor(e=[],t={}){h(this,"firstSelect");h(this,"servers");h(this,"currentServer");h(this,"tlsName");h(this,"randomize");this.firstSelect=!0,this.servers=[],this.tlsName="",this.randomize=t.randomize||!1;const s=Ss();e&&(e.forEach(i=>{i=s?s(i):i,this.servers.push(new yt(i))}),this.randomize&&(this.servers=hr(this.servers))),this.servers.length===0&&this.addServer(`${hs}:${vr()}`,!1),this.currentServer=this.servers[0]}clear(){this.servers.length=0}updateTLSName(){const e=this.getCurrentServer();Es(e.hostname)||(this.tlsName=e.hostname,this.servers.forEach(t=>{t.gossiped&&(t.tlsName=this.tlsName)}))}getCurrentServer(){return this.currentServer}addServer(e,t=!1){const s=Ss();e=s?s(e):e;const i=new yt(e,t);Es(i.hostname)&&(i.tlsName=this.tlsName),this.servers.push(i)}selectServer(){if(this.firstSelect)return this.firstSelect=!1,this.currentServer;const e=this.servers.shift();return e&&(this.servers.push(e),this.currentServer=e),e}removeCurrentServer(){this.removeServer(this.currentServer)}removeServer(e){if(e){const t=this.servers.indexOf(e);this.servers.splice(t,1)}}length(){return this.servers.length}next(){return this.servers.length?this.servers[0]:void 0}getServers(){return this.servers}update(e,t){const s=[];let i=[];const n=Ss(),o=new Map;e.connect_urls&&e.connect_urls.length>0&&e.connect_urls.forEach(d=>{d=n?n(d,t):d;const p=new yt(d,!0);o.set(d,p)});const a=[];return this.servers.forEach((d,p)=>{const _=d.listen;d.gossiped&&this.currentServer.listen!==_&&o.get(_)===void 0&&a.push(p),o.delete(_)}),a.reverse(),a.forEach(d=>{const p=this.servers.splice(d,1);i=i.concat(p[0].listen)}),o.forEach((d,p)=>{this.servers.push(d),s.push(p)}),{added:s,deleted:i}}}class bn{constructor(){h(this,"baseInbox");h(this,"reqs");this.reqs=new Map}size(){return this.reqs.size}init(e){return this.baseInbox=`${$e(e)}.`,this.baseInbox}add(e){isNaN(e.received)||(e.received=0),this.reqs.set(e.token,e)}get(e){return this.reqs.get(e)}cancel(e){this.reqs.delete(e.token)}getToken(e){const t=e.subject||"";return t.indexOf(this.baseInbox)===0?t.substring(this.baseInbox.length):null}all(){return Array.from(this.reqs.values())}handleError(e,t){if(t&&t.permissionContext){if(e)return this.all().forEach(i=>{i.resolver(t,{})}),!0;const s=t.permissionContext;if(s.operation==="publish"){const i=this.all().find(n=>n.requestSubject===s.subject);if(i)return i.resolver(t,{}),!0}}return!1}dispatcher(){return(e,t)=>{const s=this.getToken(t);if(s){const i=this.get(s);i&&(e===null&&t.headers&&(e=fr(t)),i.resolver(e,t))}}}close(){const e=N.errorForCode(k.Timeout);this.reqs.forEach(t=>{t.resolver(e,{})})}}class gn{constructor(e,t,s){h(this,"ph");h(this,"interval");h(this,"maxOut");h(this,"timer");h(this,"pendings");this.ph=e,this.interval=t,this.maxOut=s,this.pendings=[]}start(){this.cancel(),this._schedule()}cancel(e){this.timer&&(clearTimeout(this.timer),this.timer=void 0),this._reset(),e&&this.ph.disconnect()}_schedule(){this.timer=setTimeout(()=>{if(this.ph.dispatchStatus({type:Fe.PingTimer,data:`${this.pendings.length+1}`}),this.pendings.length===this.maxOut){this.cancel(!0);return}const e=z();this.ph.flush(e).then(()=>{this._reset()}).catch(()=>{this.cancel()}),this.pendings.push(e),this._schedule()},this.interval)}_reset(){this.pendings=this.pendings.filter(e=>(e.resolve(),!1))}}class _n extends Error{constructor(e){super(e),this.name="AssertionError"}}function yn(r,e="Assertion failed."){if(!r)throw new _n(e)}const Pr=32*1024,Ps=2**32-2;function Dt(r,e,t=0){const s=e.byteLength-t;return r.byteLength>s&&(r=r.subarray(0,s)),e.set(r,t),r.byteLength}class ks{constructor(e){h(this,"_buf");h(this,"_off");if(this._off=0,e==null){this._buf=new Uint8Array(0);return}this._buf=new Uint8Array(e)}bytes(e={copy:!0}){return e.copy===!1?this._buf.subarray(this._off):this._buf.slice(this._off)}empty(){return this._buf.byteLength<=this._off}get length(){return this._buf.byteLength-this._off}get capacity(){return this._buf.buffer.byteLength}truncate(e){if(e===0){this.reset();return}if(e<0||e>this.length)throw Error("bytes.Buffer: truncation out of range");this._reslice(this._off+e)}reset(){this._reslice(0),this._off=0}_tryGrowByReslice(e){const t=this._buf.byteLength;return e<=this.capacity-t?(this._reslice(t+e),t):-1}_reslice(e){yn(e<=this._buf.buffer.byteLength),this._buf=new Uint8Array(this._buf.buffer,0,e)}readByte(){const e=new Uint8Array(1);return this.read(e)?e[0]:null}read(e){if(this.empty())return this.reset(),e.byteLength===0?0:null;const t=Dt(this._buf.subarray(this._off),e);return this._off+=t,t}writeByte(e){return this.write(Uint8Array.of(e))}writeString(e){return this.write(Ge.encode(e))}write(e){const t=this._grow(e.byteLength);return Dt(e,this._buf,t)}_grow(e){const t=this.length;t===0&&this._off!==0&&this.reset();const s=this._tryGrowByReslice(e);if(s>=0)return s;const i=this.capacity;if(e<=Math.floor(i/2)-t)Dt(this._buf.subarray(this._off),this._buf);else{if(i+e>Ps)throw new Error("The buffer cannot be grown beyond the maximum size.");{const n=new Uint8Array(Math.min(2*i+e,Ps));Dt(this._buf.subarray(this._off),n),this._buf=n}}return this._off=0,this._reslice(Math.min(t+e,Ps)),t}grow(e){if(e<0)throw Error("Buffer._grow: negative count");const t=this._grow(e);this._reslice(t)}readFrom(e){let t=0;const s=new Uint8Array(Pr);for(;;){const i=this.capacity-this.length<Pr,n=i?s:new Uint8Array(this._buf.buffer,this.length),o=e.read(n);if(o===null)return t;i?this.write(n.subarray(0,o)):this._reslice(this.length+o),t+=o}}}var de;(function(r){r[r.OK=0]="OK",r[r.ERR=1]="ERR",r[r.MSG=2]="MSG",r[r.INFO=3]="INFO",r[r.PING=4]="PING",r[r.PONG=5]="PONG"})(de||(de={}));function kr(){const r={};return r.sid=-1,r.hdr=-1,r.size=-1,r}const wn=48;class Or{constructor(e){h(this,"dispatcher");h(this,"state");h(this,"as");h(this,"drop");h(this,"hdr");h(this,"ma");h(this,"argBuf");h(this,"msgBuf");this.dispatcher=e,this.state=O.OP_START,this.as=0,this.drop=0,this.hdr=0}parse(e){let t;for(t=0;t<e.length;t++){const s=e[t];switch(this.state){case O.OP_START:switch(s){case C.M:case C.m:this.state=O.OP_M,this.hdr=-1,this.ma=kr();break;case C.H:case C.h:this.state=O.OP_H,this.hdr=0,this.ma=kr();break;case C.P:case C.p:this.state=O.OP_P;break;case C.PLUS:this.state=O.OP_PLUS;break;case C.MINUS:this.state=O.OP_MINUS;break;case C.I:case C.i:this.state=O.OP_I;break;default:throw this.fail(e.subarray(t))}break;case O.OP_H:switch(s){case C.M:case C.m:this.state=O.OP_M;break;default:throw this.fail(e.subarray(t))}break;case O.OP_M:switch(s){case C.S:case C.s:this.state=O.OP_MS;break;default:throw this.fail(e.subarray(t))}break;case O.OP_MS:switch(s){case C.G:case C.g:this.state=O.OP_MSG;break;default:throw this.fail(e.subarray(t))}break;case O.OP_MSG:switch(s){case C.SPACE:case C.TAB:this.state=O.OP_MSG_SPC;break;default:throw this.fail(e.subarray(t))}break;case O.OP_MSG_SPC:switch(s){case C.SPACE:case C.TAB:continue;default:this.state=O.MSG_ARG,this.as=t}break;case O.MSG_ARG:switch(s){case C.CR:this.drop=1;break;case C.NL:{const i=this.argBuf?this.argBuf.bytes():e.subarray(this.as,t-this.drop);this.processMsgArgs(i),this.drop=0,this.as=t+1,this.state=O.MSG_PAYLOAD,t=this.as+this.ma.size-1;break}default:this.argBuf&&this.argBuf.writeByte(s)}break;case O.MSG_PAYLOAD:if(this.msgBuf)if(this.msgBuf.length>=this.ma.size){const i=this.msgBuf.bytes({copy:!1});this.dispatcher.push({kind:de.MSG,msg:this.ma,data:i}),this.argBuf=void 0,this.msgBuf=void 0,this.state=O.MSG_END}else{let i=this.ma.size-this.msgBuf.length;const n=e.length-t;n<i&&(i=n),i>0?(this.msgBuf.write(e.subarray(t,t+i)),t=t+i-1):this.msgBuf.writeByte(s)}else t-this.as>=this.ma.size&&(this.dispatcher.push({kind:de.MSG,msg:this.ma,data:e.subarray(this.as,t)}),this.argBuf=void 0,this.msgBuf=void 0,this.state=O.MSG_END);break;case O.MSG_END:switch(s){case C.NL:this.drop=0,this.as=t+1,this.state=O.OP_START;break;default:continue}break;case O.OP_PLUS:switch(s){case C.O:case C.o:this.state=O.OP_PLUS_O;break;default:throw this.fail(e.subarray(t))}break;case O.OP_PLUS_O:switch(s){case C.K:case C.k:this.state=O.OP_PLUS_OK;break;default:throw this.fail(e.subarray(t))}break;case O.OP_PLUS_OK:switch(s){case C.NL:this.dispatcher.push({kind:de.OK}),this.drop=0,this.state=O.OP_START;break}break;case O.OP_MINUS:switch(s){case C.E:case C.e:this.state=O.OP_MINUS_E;break;default:throw this.fail(e.subarray(t))}break;case O.OP_MINUS_E:switch(s){case C.R:case C.r:this.state=O.OP_MINUS_ER;break;default:throw this.fail(e.subarray(t))}break;case O.OP_MINUS_ER:switch(s){case C.R:case C.r:this.state=O.OP_MINUS_ERR;break;default:throw this.fail(e.subarray(t))}break;case O.OP_MINUS_ERR:switch(s){case C.SPACE:case C.TAB:this.state=O.OP_MINUS_ERR_SPC;break;default:throw this.fail(e.subarray(t))}break;case O.OP_MINUS_ERR_SPC:switch(s){case C.SPACE:case C.TAB:continue;default:this.state=O.MINUS_ERR_ARG,this.as=t}break;case O.MINUS_ERR_ARG:switch(s){case C.CR:this.drop=1;break;case C.NL:{let i;this.argBuf?(i=this.argBuf.bytes(),this.argBuf=void 0):i=e.subarray(this.as,t-this.drop),this.dispatcher.push({kind:de.ERR,data:i}),this.drop=0,this.as=t+1,this.state=O.OP_START;break}default:this.argBuf&&this.argBuf.write(Uint8Array.of(s))}break;case O.OP_P:switch(s){case C.I:case C.i:this.state=O.OP_PI;break;case C.O:case C.o:this.state=O.OP_PO;break;default:throw this.fail(e.subarray(t))}break;case O.OP_PO:switch(s){case C.N:case C.n:this.state=O.OP_PON;break;default:throw this.fail(e.subarray(t))}break;case O.OP_PON:switch(s){case C.G:case C.g:this.state=O.OP_PONG;break;default:throw this.fail(e.subarray(t))}break;case O.OP_PONG:switch(s){case C.NL:this.dispatcher.push({kind:de.PONG}),this.drop=0,this.state=O.OP_START;break}break;case O.OP_PI:switch(s){case C.N:case C.n:this.state=O.OP_PIN;break;default:throw this.fail(e.subarray(t))}break;case O.OP_PIN:switch(s){case C.G:case C.g:this.state=O.OP_PING;break;default:throw this.fail(e.subarray(t))}break;case O.OP_PING:switch(s){case C.NL:this.dispatcher.push({kind:de.PING}),this.drop=0,this.state=O.OP_START;break}break;case O.OP_I:switch(s){case C.N:case C.n:this.state=O.OP_IN;break;default:throw this.fail(e.subarray(t))}break;case O.OP_IN:switch(s){case C.F:case C.f:this.state=O.OP_INF;break;default:throw this.fail(e.subarray(t))}break;case O.OP_INF:switch(s){case C.O:case C.o:this.state=O.OP_INFO;break;default:throw this.fail(e.subarray(t))}break;case O.OP_INFO:switch(s){case C.SPACE:case C.TAB:this.state=O.OP_INFO_SPC;break;default:throw this.fail(e.subarray(t))}break;case O.OP_INFO_SPC:switch(s){case C.SPACE:case C.TAB:continue;default:this.state=O.INFO_ARG,this.as=t}break;case O.INFO_ARG:switch(s){case C.CR:this.drop=1;break;case C.NL:{let i;this.argBuf?(i=this.argBuf.bytes(),this.argBuf=void 0):i=e.subarray(this.as,t-this.drop),this.dispatcher.push({kind:de.INFO,data:i}),this.drop=0,this.as=t+1,this.state=O.OP_START;break}default:this.argBuf&&this.argBuf.writeByte(s)}break;default:throw this.fail(e.subarray(t))}}(this.state===O.MSG_ARG||this.state===O.MINUS_ERR_ARG||this.state===O.INFO_ARG)&&!this.argBuf&&(this.argBuf=new ks(e.subarray(this.as,t-this.drop))),this.state===O.MSG_PAYLOAD&&!this.msgBuf&&(this.argBuf||this.cloneMsgArg(),this.msgBuf=new ks(e.subarray(this.as)))}cloneMsgArg(){const e=this.ma.subject.length,t=this.ma.reply?this.ma.reply.length:0,s=new Uint8Array(e+t);s.set(this.ma.subject),this.ma.reply&&s.set(this.ma.reply,e),this.argBuf=new ks(s),this.ma.subject=s.subarray(0,e),this.ma.reply&&(this.ma.reply=s.subarray(e))}processMsgArgs(e){if(this.hdr>=0)return this.processHeaderMsgArgs(e);const t=[];let s=-1;for(let i=0;i<e.length;i++)switch(e[i]){case C.SPACE:case C.TAB:case C.CR:case C.NL:s>=0&&(t.push(e.subarray(s,i)),s=-1);break;default:s<0&&(s=i)}switch(s>=0&&t.push(e.subarray(s)),t.length){case 3:this.ma.subject=t[0],this.ma.sid=this.protoParseInt(t[1]),this.ma.reply=void 0,this.ma.size=this.protoParseInt(t[2]);break;case 4:this.ma.subject=t[0],this.ma.sid=this.protoParseInt(t[1]),this.ma.reply=t[2],this.ma.size=this.protoParseInt(t[3]);break;default:throw this.fail(e,"processMsgArgs Parse Error")}if(this.ma.sid<0)throw this.fail(e,"processMsgArgs Bad or Missing Sid Error");if(this.ma.size<0)throw this.fail(e,"processMsgArgs Bad or Missing Size Error")}fail(e,t=""){return t?t=`${t} [${this.state}]`:t=`parse error [${this.state}]`,new Error(`${t}: ${ge.decode(e)}`)}processHeaderMsgArgs(e){const t=[];let s=-1;for(let i=0;i<e.length;i++)switch(e[i]){case C.SPACE:case C.TAB:case C.CR:case C.NL:s>=0&&(t.push(e.subarray(s,i)),s=-1);break;default:s<0&&(s=i)}switch(s>=0&&t.push(e.subarray(s)),t.length){case 4:this.ma.subject=t[0],this.ma.sid=this.protoParseInt(t[1]),this.ma.reply=void 0,this.ma.hdr=this.protoParseInt(t[2]),this.ma.size=this.protoParseInt(t[3]);break;case 5:this.ma.subject=t[0],this.ma.sid=this.protoParseInt(t[1]),this.ma.reply=t[2],this.ma.hdr=this.protoParseInt(t[3]),this.ma.size=this.protoParseInt(t[4]);break;default:throw this.fail(e,"processHeaderMsgArgs Parse Error")}if(this.ma.sid<0)throw this.fail(e,"processHeaderMsgArgs Bad or Missing Sid Error");if(this.ma.hdr<0||this.ma.hdr>this.ma.size)throw this.fail(e,"processHeaderMsgArgs Bad or Missing Header Size Error");if(this.ma.size<0)throw this.fail(e,"processHeaderMsgArgs Bad or Missing Size Error")}protoParseInt(e){if(e.length===0)return-1;let t=0;for(let s=0;s<e.length;s++){if(e[s]<48||e[s]>57)return-1;t=t*10+(e[s]-wn)}return t}}var O;(function(r){r[r.OP_START=0]="OP_START",r[r.OP_PLUS=1]="OP_PLUS",r[r.OP_PLUS_O=2]="OP_PLUS_O",r[r.OP_PLUS_OK=3]="OP_PLUS_OK",r[r.OP_MINUS=4]="OP_MINUS",r[r.OP_MINUS_E=5]="OP_MINUS_E",r[r.OP_MINUS_ER=6]="OP_MINUS_ER",r[r.OP_MINUS_ERR=7]="OP_MINUS_ERR",r[r.OP_MINUS_ERR_SPC=8]="OP_MINUS_ERR_SPC",r[r.MINUS_ERR_ARG=9]="MINUS_ERR_ARG",r[r.OP_M=10]="OP_M",r[r.OP_MS=11]="OP_MS",r[r.OP_MSG=12]="OP_MSG",r[r.OP_MSG_SPC=13]="OP_MSG_SPC",r[r.MSG_ARG=14]="MSG_ARG",r[r.MSG_PAYLOAD=15]="MSG_PAYLOAD",r[r.MSG_END=16]="MSG_END",r[r.OP_H=17]="OP_H",r[r.OP_P=18]="OP_P",r[r.OP_PI=19]="OP_PI",r[r.OP_PIN=20]="OP_PIN",r[r.OP_PING=21]="OP_PING",r[r.OP_PO=22]="OP_PO",r[r.OP_PON=23]="OP_PON",r[r.OP_PONG=24]="OP_PONG",r[r.OP_I=25]="OP_I",r[r.OP_IN=26]="OP_IN",r[r.OP_INF=27]="OP_INF",r[r.OP_INFO=28]="OP_INFO",r[r.OP_INFO_SPC=29]="OP_INFO_SPC",r[r.INFO_ARG=30]="INFO_ARG"})(O||(O={}));var C;(function(r){r[r.CR=13]="CR",r[r.E=69]="E",r[r.e=101]="e",r[r.F=70]="F",r[r.f=102]="f",r[r.G=71]="G",r[r.g=103]="g",r[r.H=72]="H",r[r.h=104]="h",r[r.I=73]="I",r[r.i=105]="i",r[r.K=75]="K",r[r.k=107]="k",r[r.M=77]="M",r[r.m=109]="m",r[r.MINUS=45]="MINUS",r[r.N=78]="N",r[r.n=110]="n",r[r.NL=10]="NL",r[r.O=79]="O",r[r.o=111]="o",r[r.P=80]="P",r[r.p=112]="p",r[r.PLUS=43]="PLUS",r[r.R=82]="R",r[r.r=114]="r",r[r.S=83]="S",r[r.s=115]="s",r[r.SPACE=32]="SPACE",r[r.TAB=9]="TAB"})(C||(C={})),function(r){var e=function(c,l){this.hi=c|0,this.lo=l|0},t=function(c){var l,u=new Float64Array(16);if(c)for(l=0;l<c.length;l++)u[l]=c[l];return u},s=function(){throw new Error("no PRNG")},i=new Uint8Array(16),n=new Uint8Array(32);n[0]=9;var o=t(),a=t([1]),d=t([56129,1]),p=t([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),_=t([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),y=t([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),x=t([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),P=t([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function I(c,l){return c<<l|c>>>32-l}function T(c,l){var u=c[l+3]&255;return u=u<<8|c[l+2]&255,u=u<<8|c[l+1]&255,u<<8|c[l+0]&255}function J(c,l){var u=c[l]<<24|c[l+1]<<16|c[l+2]<<8|c[l+3],f=c[l+4]<<24|c[l+5]<<16|c[l+6]<<8|c[l+7];return new e(u,f)}function Q(c,l,u){var f;for(f=0;f<4;f++)c[l+f]=u&255,u>>>=8}function L(c,l,u){c[l]=u.hi>>24&255,c[l+1]=u.hi>>16&255,c[l+2]=u.hi>>8&255,c[l+3]=u.hi&255,c[l+4]=u.lo>>24&255,c[l+5]=u.lo>>16&255,c[l+6]=u.lo>>8&255,c[l+7]=u.lo&255}function X(c,l,u,f,m){var b,v=0;for(b=0;b<m;b++)v|=c[l+b]^u[f+b];return(1&v-1>>>8)-1}function pe(c,l,u,f){return X(c,l,u,f,16)}function w(c,l,u,f){return X(c,l,u,f,32)}function j(c,l,u,f,m){var b=new Uint32Array(16),v=new Uint32Array(16),E=new Uint32Array(16),g=new Uint32Array(4),S,M,D;for(S=0;S<4;S++)v[5*S]=T(f,4*S),v[1+S]=T(u,4*S),v[6+S]=T(l,4*S),v[11+S]=T(u,16+4*S);for(S=0;S<16;S++)E[S]=v[S];for(S=0;S<20;S++){for(M=0;M<4;M++){for(D=0;D<4;D++)g[D]=v[(5*M+4*D)%16];for(g[1]^=I(g[0]+g[3]|0,7),g[2]^=I(g[1]+g[0]|0,9),g[3]^=I(g[2]+g[1]|0,13),g[0]^=I(g[3]+g[2]|0,18),D=0;D<4;D++)b[4*M+(M+D)%4]=g[D]}for(D=0;D<16;D++)v[D]=b[D]}if(m){for(S=0;S<16;S++)v[S]=v[S]+E[S]|0;for(S=0;S<4;S++)v[5*S]=v[5*S]-T(f,4*S)|0,v[6+S]=v[6+S]-T(l,4*S)|0;for(S=0;S<4;S++)Q(c,4*S,v[5*S]),Q(c,16+4*S,v[6+S])}else for(S=0;S<16;S++)Q(c,4*S,v[S]+E[S]|0)}function F(c,l,u,f){return j(c,l,u,f,!1),0}function R(c,l,u,f){return j(c,l,u,f,!0),0}var A=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function $(c,l,u,f,m,b,v){var E=new Uint8Array(16),g=new Uint8Array(64),S,M;if(!m)return 0;for(M=0;M<16;M++)E[M]=0;for(M=0;M<8;M++)E[M]=b[M];for(;m>=64;){for(F(g,E,v,A),M=0;M<64;M++)c[l+M]=(u?u[f+M]:0)^g[M];for(S=1,M=8;M<16;M++)S=S+(E[M]&255)|0,E[M]=S&255,S>>>=8;m-=64,l+=64,u&&(f+=64)}if(m>0)for(F(g,E,v,A),M=0;M<m;M++)c[l+M]=(u?u[f+M]:0)^g[M];return 0}function q(c,l,u,f,m){return $(c,l,null,0,u,f,m)}function U(c,l,u,f,m){var b=new Uint8Array(32);return R(b,f,m,A),q(c,l,u,f.subarray(16),b)}function K(c,l,u,f,m,b,v){var E=new Uint8Array(32);return R(E,b,v,A),$(c,l,u,f,m,b.subarray(16),E)}function te(c,l){var u,f=0;for(u=0;u<17;u++)f=f+(c[u]+l[u]|0)|0,c[u]=f&255,f>>>=8}var ne=new Uint32Array([5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,252]);function se(c,l,u,f,m,b){var v,E,g,S,M=new Uint32Array(17),D=new Uint32Array(17),W=new Uint32Array(17),je=new Uint32Array(17),ht=new Uint32Array(17);for(g=0;g<17;g++)D[g]=W[g]=0;for(g=0;g<16;g++)D[g]=b[g];for(D[3]&=15,D[4]&=252,D[7]&=15,D[8]&=252,D[11]&=15,D[12]&=252,D[15]&=15;m>0;){for(g=0;g<17;g++)je[g]=0;for(g=0;g<16&&g<m;++g)je[g]=u[f+g];for(je[g]=1,f+=g,m-=g,te(W,je),E=0;E<17;E++)for(M[E]=0,g=0;g<17;g++)M[E]=M[E]+W[g]*(g<=E?D[E-g]:320*D[E+17-g]|0)|0|0;for(E=0;E<17;E++)W[E]=M[E];for(S=0,g=0;g<16;g++)S=S+W[g]|0,W[g]=S&255,S>>>=8;for(S=S+W[16]|0,W[16]=S&3,S=5*(S>>>2)|0,g=0;g<16;g++)S=S+W[g]|0,W[g]=S&255,S>>>=8;S=S+W[16]|0,W[16]=S}for(g=0;g<17;g++)ht[g]=W[g];for(te(W,ne),v=-(W[16]>>>7)|0,g=0;g<17;g++)W[g]^=v&(ht[g]^W[g]);for(g=0;g<16;g++)je[g]=b[g+16];for(je[16]=0,te(W,je),g=0;g<16;g++)c[l+g]=W[g];return 0}function oe(c,l,u,f,m,b){var v=new Uint8Array(16);return se(v,0,u,f,m,b),pe(c,l,v,0)}function he(c,l,u,f,m){var b;if(u<32)return-1;for(K(c,0,l,0,u,f,m),se(c,16,c,32,u-32,c),b=0;b<16;b++)c[b]=0;return 0}function ue(c,l,u,f,m){var b,v=new Uint8Array(32);if(u<32||(U(v,0,32,f,m),oe(l,16,l,32,u-32,v)!==0))return-1;for(K(c,0,l,0,u,f,m),b=0;b<32;b++)c[b]=0;return 0}function V(c,l){var u;for(u=0;u<16;u++)c[u]=l[u]|0}function ee(c){var l,u;for(u=0;u<16;u++)c[u]+=65536,l=Math.floor(c[u]/65536),c[(u+1)*(u<15?1:0)]+=l-1+37*(l-1)*(u===15?1:0),c[u]-=l*65536}function ae(c,l,u){for(var f,m=~(u-1),b=0;b<16;b++)f=m&(c[b]^l[b]),c[b]^=f,l[b]^=f}function ot(c,l){var u,f,m,b=t(),v=t();for(u=0;u<16;u++)v[u]=l[u];for(ee(v),ee(v),ee(v),f=0;f<2;f++){for(b[0]=v[0]-65517,u=1;u<15;u++)b[u]=v[u]-65535-(b[u-1]>>16&1),b[u-1]&=65535;b[15]=v[15]-32767-(b[14]>>16&1),m=b[15]>>16&1,b[14]&=65535,ae(v,b,1-m)}for(u=0;u<16;u++)c[2*u]=v[u]&255,c[2*u+1]=v[u]>>8}function Wr(c,l){var u=new Uint8Array(32),f=new Uint8Array(32);return ot(u,c),ot(f,l),w(u,0,f,0)}function Yr(c){var l=new Uint8Array(32);return ot(l,c),l[0]&1}function qs(c,l){var u;for(u=0;u<16;u++)c[u]=l[2*u]+(l[2*u+1]<<8);c[15]&=32767}function Ce(c,l,u){var f;for(f=0;f<16;f++)c[f]=l[f]+u[f]|0}function Ie(c,l,u){var f;for(f=0;f<16;f++)c[f]=l[f]-u[f]|0}function B(c,l,u){var f,m,b=new Float64Array(31);for(f=0;f<31;f++)b[f]=0;for(f=0;f<16;f++)for(m=0;m<16;m++)b[f+m]+=l[f]*u[m];for(f=0;f<15;f++)b[f]+=38*b[f+16];for(f=0;f<16;f++)c[f]=b[f];ee(c),ee(c)}function Pe(c,l){B(c,l,l)}function Xr(c,l){var u=t(),f;for(f=0;f<16;f++)u[f]=l[f];for(f=253;f>=0;f--)Pe(u,u),f!==2&&f!==4&&B(u,u,l);for(f=0;f<16;f++)c[f]=u[f]}function Zr(c,l){var u=t(),f;for(f=0;f<16;f++)u[f]=l[f];for(f=250;f>=0;f--)Pe(u,u),f!==1&&B(u,u,l);for(f=0;f<16;f++)c[f]=u[f]}function Yt(c,l,u){var f=new Uint8Array(32),m=new Float64Array(80),b,v,E=t(),g=t(),S=t(),M=t(),D=t(),W=t();for(v=0;v<31;v++)f[v]=l[v];for(f[31]=l[31]&127|64,f[0]&=248,qs(m,u),v=0;v<16;v++)g[v]=m[v],M[v]=E[v]=S[v]=0;for(E[0]=M[0]=1,v=254;v>=0;--v)b=f[v>>>3]>>>(v&7)&1,ae(E,g,b),ae(S,M,b),Ce(D,E,S),Ie(E,E,S),Ce(S,g,M),Ie(g,g,M),Pe(M,D),Pe(W,E),B(E,S,E),B(S,g,D),Ce(D,E,S),Ie(E,E,S),Pe(g,E),Ie(S,M,W),B(E,S,d),Ce(E,E,M),B(S,S,E),B(E,M,W),B(M,g,m),Pe(g,D),ae(E,g,b),ae(S,M,b);for(v=0;v<16;v++)m[v+16]=E[v],m[v+32]=S[v],m[v+48]=g[v],m[v+64]=M[v];var je=m.subarray(32),ht=m.subarray(16);return Xr(je,je),B(ht,ht,je),ot(c,ht),0}function Xt(c,l){return Yt(c,l,n)}function Qr(c,l){return s(l,32),Xt(c,l)}function Zt(c,l,u){var f=new Uint8Array(32);return Yt(f,u,l),R(c,i,f,A)}var ei=he,Oo=ue;function Co(c,l,u,f,m,b){var v=new Uint8Array(32);return Zt(v,m,b),ei(c,l,u,f,v)}function Io(c,l,u,f,m,b){var v=new Uint8Array(32);return Zt(v,m,b),Oo(c,l,u,f,v)}function Pt(){var c=0,l=0,u=0,f=0,m=65535,b,v,E;for(E=0;E<arguments.length;E++)b=arguments[E].lo,v=arguments[E].hi,c+=b&m,l+=b>>>16,u+=v&m,f+=v>>>16;return l+=c>>>16,u+=l>>>16,f+=u>>>16,new e(u&m|f<<16,c&m|l<<16)}function ti(c,l){return new e(c.hi>>>l,c.lo>>>l|c.hi<<32-l)}function Qt(){var c=0,l=0,u;for(u=0;u<arguments.length;u++)c^=arguments[u].lo,l^=arguments[u].hi;return new e(l,c)}function Te(c,l){var u,f,m=32-l;return l<32?(u=c.hi>>>l|c.lo<<m,f=c.lo>>>l|c.hi<<m):l<64&&(u=c.lo>>>l|c.hi<<m,f=c.hi>>>l|c.lo<<m),new e(u,f)}function jo(c,l,u){var f=c.hi&l.hi^~c.hi&u.hi,m=c.lo&l.lo^~c.lo&u.lo;return new e(f,m)}function Ro(c,l,u){var f=c.hi&l.hi^c.hi&u.hi^l.hi&u.hi,m=c.lo&l.lo^c.lo&u.lo^l.lo&u.lo;return new e(f,m)}function No(c){return Qt(Te(c,28),Te(c,34),Te(c,39))}function To(c){return Qt(Te(c,14),Te(c,18),Te(c,41))}function Mo(c){return Qt(Te(c,1),Te(c,8),ti(c,7))}function $o(c){return Qt(Te(c,19),Te(c,61),ti(c,6))}var Uo=[new e(1116352408,3609767458),new e(1899447441,602891725),new e(3049323471,3964484399),new e(3921009573,2173295548),new e(961987163,4081628472),new e(1508970993,3053834265),new e(2453635748,2937671579),new e(2870763221,3664609560),new e(3624381080,2734883394),new e(310598401,1164996542),new e(607225278,1323610764),new e(1426881987,3590304994),new e(1925078388,4068182383),new e(2162078206,991336113),new e(2614888103,633803317),new e(3248222580,3479774868),new e(3835390401,2666613458),new e(4022224774,944711139),new e(264347078,2341262773),new e(604807628,2007800933),new e(770255983,1495990901),new e(1249150122,1856431235),new e(1555081692,3175218132),new e(1996064986,2198950837),new e(2554220882,3999719339),new e(2821834349,766784016),new e(2952996808,2566594879),new e(3210313671,3203337956),new e(3336571891,1034457026),new e(3584528711,2466948901),new e(113926993,3758326383),new e(338241895,168717936),new e(666307205,1188179964),new e(773529912,1546045734),new e(1294757372,1522805485),new e(1396182291,2643833823),new e(1695183700,2343527390),new e(1986661051,1014477480),new e(2177026350,1206759142),new e(2456956037,344077627),new e(2730485921,1290863460),new e(2820302411,3158454273),new e(3259730800,3505952657),new e(3345764771,106217008),new e(3516065817,3606008344),new e(3600352804,1432725776),new e(4094571909,1467031594),new e(275423344,851169720),new e(430227734,3100823752),new e(506948616,1363258195),new e(659060556,3750685593),new e(883997877,3785050280),new e(958139571,3318307427),new e(1322822218,3812723403),new e(1537002063,2003034995),new e(1747873779,3602036899),new e(1955562222,1575990012),new e(2024104815,1125592928),new e(2227730452,2716904306),new e(2361852424,442776044),new e(2428436474,593698344),new e(2756734187,3733110249),new e(3204031479,2999351573),new e(3329325298,3815920427),new e(3391569614,3928383900),new e(3515267271,566280711),new e(3940187606,3454069534),new e(4118630271,4000239992),new e(116418474,1914138554),new e(174292421,2731055270),new e(289380356,3203993006),new e(460393269,320620315),new e(685471733,587496836),new e(852142971,1086792851),new e(1017036298,365543100),new e(1126000580,2618297676),new e(1288033470,3409855158),new e(1501505948,4234509866),new e(1607167915,987167468),new e(1816402316,1246189591)];function si(c,l,u){var f=[],m=[],b=[],v=[],E,g,S;for(g=0;g<8;g++)f[g]=b[g]=J(c,8*g);for(var M=0;u>=128;){for(g=0;g<16;g++)v[g]=J(l,8*g+M);for(g=0;g<80;g++){for(S=0;S<8;S++)m[S]=b[S];for(E=Pt(b[7],To(b[4]),jo(b[4],b[5],b[6]),Uo[g],v[g%16]),m[7]=Pt(E,No(b[0]),Ro(b[0],b[1],b[2])),m[3]=Pt(m[3],E),S=0;S<8;S++)b[(S+1)%8]=m[S];if(g%16===15)for(S=0;S<16;S++)v[S]=Pt(v[S],v[(S+9)%16],Mo(v[(S+1)%16]),$o(v[(S+14)%16]))}for(g=0;g<8;g++)b[g]=Pt(b[g],f[g]),f[g]=b[g];M+=128,u-=128}for(g=0;g<8;g++)L(c,8*g,f[g]);return u}var Lo=new Uint8Array([106,9,230,103,243,188,201,8,187,103,174,133,132,202,167,59,60,110,243,114,254,148,248,43,165,79,245,58,95,29,54,241,81,14,82,127,173,230,130,209,155,5,104,140,43,62,108,31,31,131,217,171,251,65,189,107,91,224,205,25,19,126,33,121]);function Ve(c,l,u){var f=new Uint8Array(64),m=new Uint8Array(256),b,v=u;for(b=0;b<64;b++)f[b]=Lo[b];for(si(f,l,u),u%=128,b=0;b<256;b++)m[b]=0;for(b=0;b<u;b++)m[b]=l[v-u+b];for(m[u]=128,u=256-128*(u<112?1:0),m[u-9]=0,L(m,u-8,new e(v/536870912|0,v<<3)),si(f,m,u),b=0;b<64;b++)c[b]=f[b];return 0}function es(c,l){var u=t(),f=t(),m=t(),b=t(),v=t(),E=t(),g=t(),S=t(),M=t();Ie(u,c[1],c[0]),Ie(M,l[1],l[0]),B(u,u,M),Ce(f,c[0],c[1]),Ce(M,l[0],l[1]),B(f,f,M),B(m,c[3],l[3]),B(m,m,_),B(b,c[2],l[2]),Ce(b,b,b),Ie(v,f,u),Ie(E,b,m),Ce(g,b,m),Ce(S,f,u),B(c[0],v,E),B(c[1],S,g),B(c[2],g,E),B(c[3],v,S)}function ri(c,l,u){var f;for(f=0;f<4;f++)ae(c[f],l[f],u)}function Fs(c,l){var u=t(),f=t(),m=t();Xr(m,l[2]),B(u,l[0],m),B(f,l[1],m),ot(c,f),c[31]^=Yr(u)<<7}function Bs(c,l,u){var f,m;for(V(c[0],o),V(c[1],a),V(c[2],a),V(c[3],o),m=255;m>=0;--m)f=u[m/8|0]>>(m&7)&1,ri(c,l,f),es(l,c),es(c,c),ri(c,l,f)}function ts(c,l){var u=[t(),t(),t(),t()];V(u[0],y),V(u[1],x),V(u[2],a),B(u[3],y,x),Bs(c,u,l)}function Ds(c,l,u){var f=new Uint8Array(64),m=[t(),t(),t(),t()],b;for(u||s(l,32),Ve(f,l,32),f[0]&=248,f[31]&=127,f[31]|=64,ts(m,f),Fs(c,m),b=0;b<32;b++)l[b+32]=c[b];return 0}var ss=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function Hs(c,l){var u,f,m,b;for(f=63;f>=32;--f){for(u=0,m=f-32,b=f-12;m<b;++m)l[m]+=u-16*l[f]*ss[m-(f-32)],u=Math.floor((l[m]+128)/256),l[m]-=u*256;l[m]+=u,l[f]=0}for(u=0,m=0;m<32;m++)l[m]+=u-(l[31]>>4)*ss[m],u=l[m]>>8,l[m]&=255;for(m=0;m<32;m++)l[m]-=u*ss[m];for(f=0;f<32;f++)l[f+1]+=l[f]>>8,c[f]=l[f]&255}function Js(c){var l=new Float64Array(64),u;for(u=0;u<64;u++)l[u]=c[u];for(u=0;u<64;u++)c[u]=0;Hs(c,l)}function ii(c,l,u,f){var m=new Uint8Array(64),b=new Uint8Array(64),v=new Uint8Array(64),E,g,S=new Float64Array(64),M=[t(),t(),t(),t()];Ve(m,f,32),m[0]&=248,m[31]&=127,m[31]|=64;var D=u+64;for(E=0;E<u;E++)c[64+E]=l[E];for(E=0;E<32;E++)c[32+E]=m[32+E];for(Ve(v,c.subarray(32),u+32),Js(v),ts(M,v),Fs(c,M),E=32;E<64;E++)c[E]=f[E];for(Ve(b,c,u+64),Js(b),E=0;E<64;E++)S[E]=0;for(E=0;E<32;E++)S[E]=v[E];for(E=0;E<32;E++)for(g=0;g<32;g++)S[E+g]+=b[E]*m[g];return Hs(c.subarray(32),S),D}function qo(c,l){var u=t(),f=t(),m=t(),b=t(),v=t(),E=t(),g=t();return V(c[2],a),qs(c[1],l),Pe(m,c[1]),B(b,m,p),Ie(m,m,c[2]),Ce(b,c[2],b),Pe(v,b),Pe(E,v),B(g,E,v),B(u,g,m),B(u,u,b),Zr(u,u),B(u,u,m),B(u,u,b),B(u,u,b),B(c[0],u,b),Pe(f,c[0]),B(f,f,b),Wr(f,m)&&B(c[0],c[0],P),Pe(f,c[0]),B(f,f,b),Wr(f,m)?-1:(Yr(c[0])===l[31]>>7&&Ie(c[0],o,c[0]),B(c[3],c[0],c[1]),0)}function zs(c,l,u,f){var m,b=new Uint8Array(32),v=new Uint8Array(64),E=[t(),t(),t(),t()],g=[t(),t(),t(),t()];if(u<64||qo(g,f))return-1;for(m=0;m<u;m++)c[m]=l[m];for(m=0;m<32;m++)c[m+32]=f[m];if(Ve(v,c,u),Js(v),Bs(E,g,v),ts(g,l.subarray(32)),es(E,g),Fs(b,E),u-=64,w(l,0,b,0)){for(m=0;m<u;m++)c[m]=0;return-1}for(m=0;m<u;m++)c[m]=l[m+64];return u}var Gs=32,rs=24,kt=32,at=16,Ot=32,is=32,Ct=32,It=32,Ks=32,ni=rs,Fo=kt,Bo=at,Le=64,We=32,ct=64,Vs=32,Ws=64;r.lowlevel={crypto_core_hsalsa20:R,crypto_stream_xor:K,crypto_stream:U,crypto_stream_salsa20_xor:$,crypto_stream_salsa20:q,crypto_onetimeauth:se,crypto_onetimeauth_verify:oe,crypto_verify_16:pe,crypto_verify_32:w,crypto_secretbox:he,crypto_secretbox_open:ue,crypto_scalarmult:Yt,crypto_scalarmult_base:Xt,crypto_box_beforenm:Zt,crypto_box_afternm:ei,crypto_box:Co,crypto_box_open:Io,crypto_box_keypair:Qr,crypto_hash:Ve,crypto_sign:ii,crypto_sign_keypair:Ds,crypto_sign_open:zs,crypto_secretbox_KEYBYTES:Gs,crypto_secretbox_NONCEBYTES:rs,crypto_secretbox_ZEROBYTES:kt,crypto_secretbox_BOXZEROBYTES:at,crypto_scalarmult_BYTES:Ot,crypto_scalarmult_SCALARBYTES:is,crypto_box_PUBLICKEYBYTES:Ct,crypto_box_SECRETKEYBYTES:It,crypto_box_BEFORENMBYTES:Ks,crypto_box_NONCEBYTES:ni,crypto_box_ZEROBYTES:Fo,crypto_box_BOXZEROBYTES:Bo,crypto_sign_BYTES:Le,crypto_sign_PUBLICKEYBYTES:We,crypto_sign_SECRETKEYBYTES:ct,crypto_sign_SEEDBYTES:Vs,crypto_hash_BYTES:Ws,gf:t,D:p,L:ss,pack25519:ot,unpack25519:qs,M:B,A:Ce,S:Pe,Z:Ie,pow2523:Zr,add:es,set25519:V,modL:Hs,scalarmult:Bs,scalarbase:ts};function oi(c,l){if(c.length!==Gs)throw new Error("bad key size");if(l.length!==rs)throw new Error("bad nonce size")}function Do(c,l){if(c.length!==Ct)throw new Error("bad public key size");if(l.length!==It)throw new Error("bad secret key size")}function xe(){for(var c=0;c<arguments.length;c++)if(!(arguments[c]instanceof Uint8Array))throw new TypeError("unexpected type, use Uint8Array")}function ai(c){for(var l=0;l<c.length;l++)c[l]=0}r.randomBytes=function(c){var l=new Uint8Array(c);return s(l,c),l},r.secretbox=function(c,l,u){xe(c,l,u),oi(u,l);for(var f=new Uint8Array(kt+c.length),m=new Uint8Array(f.length),b=0;b<c.length;b++)f[b+kt]=c[b];return he(m,f,f.length,l,u),m.subarray(at)},r.secretbox.open=function(c,l,u){xe(c,l,u),oi(u,l);for(var f=new Uint8Array(at+c.length),m=new Uint8Array(f.length),b=0;b<c.length;b++)f[b+at]=c[b];return f.length<32||ue(m,f,f.length,l,u)!==0?null:m.subarray(kt)},r.secretbox.keyLength=Gs,r.secretbox.nonceLength=rs,r.secretbox.overheadLength=at,r.scalarMult=function(c,l){if(xe(c,l),c.length!==is)throw new Error("bad n size");if(l.length!==Ot)throw new Error("bad p size");var u=new Uint8Array(Ot);return Yt(u,c,l),u},r.scalarMult.base=function(c){if(xe(c),c.length!==is)throw new Error("bad n size");var l=new Uint8Array(Ot);return Xt(l,c),l},r.scalarMult.scalarLength=is,r.scalarMult.groupElementLength=Ot,r.box=function(c,l,u,f){var m=r.box.before(u,f);return r.secretbox(c,l,m)},r.box.before=function(c,l){xe(c,l),Do(c,l);var u=new Uint8Array(Ks);return Zt(u,c,l),u},r.box.after=r.secretbox,r.box.open=function(c,l,u,f){var m=r.box.before(u,f);return r.secretbox.open(c,l,m)},r.box.open.after=r.secretbox.open,r.box.keyPair=function(){var c=new Uint8Array(Ct),l=new Uint8Array(It);return Qr(c,l),{publicKey:c,secretKey:l}},r.box.keyPair.fromSecretKey=function(c){if(xe(c),c.length!==It)throw new Error("bad secret key size");var l=new Uint8Array(Ct);return Xt(l,c),{publicKey:l,secretKey:new Uint8Array(c)}},r.box.publicKeyLength=Ct,r.box.secretKeyLength=It,r.box.sharedKeyLength=Ks,r.box.nonceLength=ni,r.box.overheadLength=r.secretbox.overheadLength,r.sign=function(c,l){if(xe(c,l),l.length!==ct)throw new Error("bad secret key size");var u=new Uint8Array(Le+c.length);return ii(u,c,c.length,l),u},r.sign.open=function(c,l){if(xe(c,l),l.length!==We)throw new Error("bad public key size");var u=new Uint8Array(c.length),f=zs(u,c,c.length,l);if(f<0)return null;for(var m=new Uint8Array(f),b=0;b<m.length;b++)m[b]=u[b];return m},r.sign.detached=function(c,l){for(var u=r.sign(c,l),f=new Uint8Array(Le),m=0;m<f.length;m++)f[m]=u[m];return f},r.sign.detached.verify=function(c,l,u){if(xe(c,l,u),l.length!==Le)throw new Error("bad signature size");if(u.length!==We)throw new Error("bad public key size");var f=new Uint8Array(Le+c.length),m=new Uint8Array(Le+c.length),b;for(b=0;b<Le;b++)f[b]=l[b];for(b=0;b<c.length;b++)f[b+Le]=c[b];return zs(m,f,f.length,u)>=0},r.sign.keyPair=function(){var c=new Uint8Array(We),l=new Uint8Array(ct);return Ds(c,l),{publicKey:c,secretKey:l}},r.sign.keyPair.fromSecretKey=function(c){if(xe(c),c.length!==ct)throw new Error("bad secret key size");for(var l=new Uint8Array(We),u=0;u<l.length;u++)l[u]=c[32+u];return{publicKey:l,secretKey:new Uint8Array(c)}},r.sign.keyPair.fromSeed=function(c){if(xe(c),c.length!==Vs)throw new Error("bad seed size");for(var l=new Uint8Array(We),u=new Uint8Array(ct),f=0;f<32;f++)u[f]=c[f];return Ds(l,u,!0),{publicKey:l,secretKey:u}},r.sign.publicKeyLength=We,r.sign.secretKeyLength=ct,r.sign.seedLength=Vs,r.sign.signatureLength=Le,r.hash=function(c){xe(c);var l=new Uint8Array(Ws);return Ve(l,c,c.length),l},r.hash.hashLength=Ws,r.verify=function(c,l){return xe(c,l),c.length===0||l.length===0||c.length!==l.length?!1:X(c,0,l,0,c.length)===0},r.setPRNG=function(c){s=c},function(){var c=typeof globalThis<"u"?globalThis.crypto||globalThis.msCrypto:null;if(c&&c.getRandomValues){var l=65536;r.setPRNG(function(u,f){var m,b=new Uint8Array(f);for(m=0;m<f;m+=l)c.getRandomValues(b.subarray(m,m+Math.min(f-m,l)));for(m=0;m<f;m++)u[m]=b[m];ai(b)})}else typeof require<"u"&&(c=require("crypto"),c&&c.randomBytes&&r.setPRNG(function(u,f){var m,b=c.randomBytes(f);for(m=0;m<f;m++)u[m]=b[m];ai(b)}))}()}(typeof module<"u"&&module.exports?module.exports:globalThis.nacl=globalThis.nacl||{});const Ht=typeof module<"u"&&module.exports?module.exports:globalThis.nacl;Ht.sign.keyPair.fromSeed,Ht.sign.detached,Ht.sign.detached.verify,Ht.randomBytes;var Cr;(function(r){r.InvalidPrefixByte="nkeys: invalid prefix byte",r.InvalidKey="nkeys: invalid key",r.InvalidPublicKey="nkeys: invalid public key",r.InvalidSeedLen="nkeys: invalid seed length",r.InvalidSeed="nkeys: invalid seed",r.InvalidEncoding="nkeys: invalid encoded key",r.InvalidSignature="nkeys: signature verification failed",r.CannotSign="nkeys: cannot sign, no private key available",r.PublicKeyOnly="nkeys: no seed or private key available",r.InvalidChecksum="nkeys: invalid checksum",r.SerializationError="nkeys: serialization error",r.ApiError="nkeys: api error",r.ClearedPair="nkeys: pair is cleared"})(Cr||(Cr={}));var Ir;(function(r){r[r.Seed=144]="Seed",r[r.Private=120]="Private",r[r.Operator=112]="Operator",r[r.Server=104]="Server",r[r.Cluster=16]="Cluster",r[r.Account=0]="Account",r[r.User=160]="User"})(Ir||(Ir={}));function xn(r){return e=>{let t={};return r.forEach(s=>{const i=s(e)||{};t=Object.assign(t,i)}),t}}function Sn(){return()=>{}}function vn(r,e){return()=>{const t=typeof r=="function"?r():r,s=typeof e=="function"?e():e;return{user:t,pass:s}}}function En(r){return()=>({auth_token:typeof r=="function"?r():r})}const jr=2*60*1e3,An=2,Rr=2*1e3;function Pn(){return{maxPingOut:2,maxReconnectAttempts:10,noRandomize:!1,pedantic:!1,pingInterval:jr,reconnect:!0,reconnectJitter:100,reconnectJitterTLS:1e3,reconnectTimeWait:Rr,tls:void 0,verbose:!1,waitOnFirstConnect:!1,ignoreAuthErrorAbort:!1}}function kn(r){const e=[];return typeof r.authenticator=="function"&&e.push(r.authenticator),Array.isArray(r.authenticator)&&e.push(...r.authenticator),r.token&&e.push(En(r.token)),r.user&&e.push(vn(r.user,r.pass)),e.length===0?Sn():xn(e)}function On(r){const e=`${hs}:${vr()}`;if(r=r||{servers:[e]},r.servers=r.servers||[],typeof r.servers=="string"&&(r.servers=[r.servers]),r.servers.length>0&&r.port)throw new N("port and servers options are mutually exclusive",k.InvalidOption);r.servers.length===0&&r.port&&(r.servers=[`${hs}:${r.port}`]),r.servers&&r.servers.length===0&&(r.servers=[e]);const t=Tt(Pn(),r);if(t.authenticator=kn(t),["reconnectDelayHandler","authenticator"].forEach(s=>{if(t[s]&&typeof t[s]!="function")throw new N(`${s} option should be a function`,k.NotFunction)}),t.reconnectDelayHandler||(t.reconnectDelayHandler=()=>{let s=t.tls?t.reconnectJitterTLS:t.reconnectJitter;return s&&(s++,s=Math.floor(Math.random()*s)),t.reconnectTimeWait+s}),t.inboxPrefix)try{$e(t.inboxPrefix)}catch(s){throw new N(s.message,k.ApiError)}if(t.resolve===void 0&&(t.resolve=typeof vs()=="function"),t.resolve&&typeof vs()!="function")throw new N("'resolve' is not supported on this client",k.InvalidOption);return t}function Cn(r,e){const{proto:t,tls_required:s,tls_available:i}=r;if((t===void 0||t<1)&&e.noEcho)throw new N("noEcho",k.ServerOptionNotAvailable);const n=s||i||!1;if(e.tls&&!n)throw new N("tls",k.ServerOptionNotAvailable)}const In=1024*32,jn=/^INFO\s+([^\r\n]+)\r\n/i,Rn=ft(`PONG\r
13
+ `,Bt=rt.fromAscii(Ft),Qi=new Uint8Array(Bt)[0],en=new Uint8Array(Bt)[1];function tn(r){for(let e=0;e<r.length;e++){const t=e+1;if(r.byteLength>t&&r[e]===Qi&&r[t]===en)return t+1}return 0}function sn(r){const e=tn(r);if(e>0){const s=new Uint8Array(r).slice(0,e);return ge.decode(s)}return""}const rn=4,Er=48,nn=65,on=97;function an(r,e,t,s){const i=new Uint8Array(16);return[0,0,0,0,0,0,0,0,0,0,255,255].forEach((o,a)=>{i[a]=o}),i[12]=r,i[13]=e,i[14]=t,i[15]=s,i}function Es(r){return cn(r)!==void 0}function cn(r){for(let e=0;e<r.length;e++)switch(r[e]){case".":return Ar(r);case":":return hn(r)}}function Ar(r){const e=new Uint8Array(4);for(let t=0;t<4;t++){if(r.length===0)return;if(t>0){if(r[0]!==".")return;r=r.substring(1)}const{n:s,c:i,ok:n}=un(r);if(!n||s>255)return;r=r.substring(i),e[t]=s}return an(e[0],e[1],e[2],e[3])}function hn(r){const e=new Uint8Array(16);let t=-1;if(r.length>=2&&r[0]===":"&&r[1]===":"&&(t=0,r=r.substring(2),r.length===0))return e;let s=0;for(;s<16;){const{n:i,c:n,ok:o}=ln(r);if(!o||i>65535)return;if(n<r.length&&r[n]==="."){if(t<0&&s!=12||s+4>16)return;const a=Ar(r);if(a===void 0)return;e[s]=a[12],e[s+1]=a[13],e[s+2]=a[14],e[s+3]=a[15],r="",s+=rn;break}if(e[s]=i>>8,e[s+1]=i,s+=2,r=r.substring(n),r.length===0)break;if(r[0]!==":"||r.length==1)return;if(r=r.substring(1),r[0]===":"){if(t>=0)return;if(t=s,r=r.substring(1),r.length===0)break}}if(r.length===0){if(s<16){if(t<0)return;const i=16-s;for(let n=s-1;n>=t;n--)e[n+i]=e[n];for(let n=t+i-1;n>=t;n--)e[n]=0}else if(t>=0)return;return e}}function un(r){let e=0,t=0;for(e=0;e<r.length&&48<=r.charCodeAt(e)&&r.charCodeAt(e)<=57;e++)if(t=t*10+(r.charCodeAt(e)-Er),t>=16777215)return{n:16777215,c:e,ok:!1};return e===0?{n:0,c:0,ok:!1}:{n:t,c:e,ok:!0}}function ln(r){let e=0,t=0;for(t=0;t<r.length;t++){if(48<=r.charCodeAt(t)&&r.charCodeAt(t)<=57)e*=16,e+=r.charCodeAt(t)-Er;else if(97<=r.charCodeAt(t)&&r.charCodeAt(t)<=102)e*=16,e+=r.charCodeAt(t)-on+10;else if(65<=r.charCodeAt(t)&&r.charCodeAt(t)<=70)e*=16,e+=r.charCodeAt(t)-nn+10;else break;if(e>=16777215)return{n:0,c:t,ok:!1}}return t===0?{n:0,c:t,ok:!1}:{n:e,c:t,ok:!0}}function fn(r){return r.indexOf("[")!==-1||r.indexOf("::")!==-1?!1:r.indexOf(".")!==-1||r.split(":").length<=2}function As(r){return!fn(r)}function dn(r){const e="::FFFF:",t=r.toUpperCase().indexOf(e);if(t!==-1&&r.indexOf(".")!==-1){let s=r.substring(t+e.length);return s=s.replace("[",""),s.replace("]","")}return r}function pn(r){r=r.trim(),r.match(/^(.*:\/\/)(.*)/m)&&(r=r.replace(/^(.*:\/\/)(.*)/gm,"$2")),r=dn(r),As(r)&&r.indexOf("[")===-1&&(r=`[${r}]`);const e=As(r)?r.match(/(]:)(\d+)/):r.match(/(:)(\d+)/),t=e&&e.length===3&&e[1]&&e[2]?parseInt(e[2]):4222,s=t===80?"https":"http",i=new URL(`${s}://${r}`);i.port=`${t}`;let n=i.hostname;return n.charAt(0)==="["&&(n=n.substring(1,n.length-1)),{listen:i.host,hostname:n,port:t}}class yt{constructor(e,t=!1){h(this,"src");h(this,"listen");h(this,"hostname");h(this,"port");h(this,"didConnect");h(this,"reconnects");h(this,"lastConnect");h(this,"gossiped");h(this,"tlsName");h(this,"resolves");this.src=e,this.tlsName="";const s=pn(e);this.listen=s.listen,this.hostname=s.hostname,this.port=s.port,this.didConnect=!1,this.reconnects=0,this.lastConnect=0,this.gossiped=t}toString(){return this.listen}async resolve(e){if(!e.fn||e.resolve===!1)return[this];const t=[];if(Es(this.hostname))return[this];{const s=await e.fn(this.hostname);e.debug&&console.log(`resolve ${this.hostname} = ${s.join(",")}`);for(const i of s){const n=this.port===80?"https":"http",o=new URL(`${n}://${As(i)?"["+i+"]":i}`);o.port=`${this.port}`;const a=new yt(o.host,!1);a.tlsName=this.hostname,t.push(a)}}return e.randomize&&hr(t),this.resolves=t,t}}class mn{constructor(e=[],t={}){h(this,"firstSelect");h(this,"servers");h(this,"currentServer");h(this,"tlsName");h(this,"randomize");this.firstSelect=!0,this.servers=[],this.tlsName="",this.randomize=t.randomize||!1;const s=Ss();e&&(e.forEach(i=>{i=s?s(i):i,this.servers.push(new yt(i))}),this.randomize&&(this.servers=hr(this.servers))),this.servers.length===0&&this.addServer(`${hs}:${vr()}`,!1),this.currentServer=this.servers[0]}clear(){this.servers.length=0}updateTLSName(){const e=this.getCurrentServer();Es(e.hostname)||(this.tlsName=e.hostname,this.servers.forEach(t=>{t.gossiped&&(t.tlsName=this.tlsName)}))}getCurrentServer(){return this.currentServer}addServer(e,t=!1){const s=Ss();e=s?s(e):e;const i=new yt(e,t);Es(i.hostname)&&(i.tlsName=this.tlsName),this.servers.push(i)}selectServer(){if(this.firstSelect)return this.firstSelect=!1,this.currentServer;const e=this.servers.shift();return e&&(this.servers.push(e),this.currentServer=e),e}removeCurrentServer(){this.removeServer(this.currentServer)}removeServer(e){if(e){const t=this.servers.indexOf(e);this.servers.splice(t,1)}}length(){return this.servers.length}next(){return this.servers.length?this.servers[0]:void 0}getServers(){return this.servers}update(e,t){const s=[];let i=[];const n=Ss(),o=new Map;e.connect_urls&&e.connect_urls.length>0&&e.connect_urls.forEach(d=>{d=n?n(d,t):d;const p=new yt(d,!0);o.set(d,p)});const a=[];return this.servers.forEach((d,p)=>{const _=d.listen;d.gossiped&&this.currentServer.listen!==_&&o.get(_)===void 0&&a.push(p),o.delete(_)}),a.reverse(),a.forEach(d=>{const p=this.servers.splice(d,1);i=i.concat(p[0].listen)}),o.forEach((d,p)=>{this.servers.push(d),s.push(p)}),{added:s,deleted:i}}}class bn{constructor(){h(this,"baseInbox");h(this,"reqs");this.reqs=new Map}size(){return this.reqs.size}init(e){return this.baseInbox=`${$e(e)}.`,this.baseInbox}add(e){isNaN(e.received)||(e.received=0),this.reqs.set(e.token,e)}get(e){return this.reqs.get(e)}cancel(e){this.reqs.delete(e.token)}getToken(e){const t=e.subject||"";return t.indexOf(this.baseInbox)===0?t.substring(this.baseInbox.length):null}all(){return Array.from(this.reqs.values())}handleError(e,t){if(t&&t.permissionContext){if(e)return this.all().forEach(i=>{i.resolver(t,{})}),!0;const s=t.permissionContext;if(s.operation==="publish"){const i=this.all().find(n=>n.requestSubject===s.subject);if(i)return i.resolver(t,{}),!0}}return!1}dispatcher(){return(e,t)=>{const s=this.getToken(t);if(s){const i=this.get(s);i&&(e===null&&t.headers&&(e=fr(t)),i.resolver(e,t))}}}close(){const e=N.errorForCode(k.Timeout);this.reqs.forEach(t=>{t.resolver(e,{})})}}class gn{constructor(e,t,s){h(this,"ph");h(this,"interval");h(this,"maxOut");h(this,"timer");h(this,"pendings");this.ph=e,this.interval=t,this.maxOut=s,this.pendings=[]}start(){this.cancel(),this._schedule()}cancel(e){this.timer&&(clearTimeout(this.timer),this.timer=void 0),this._reset(),e&&this.ph.disconnect()}_schedule(){this.timer=setTimeout(()=>{if(this.ph.dispatchStatus({type:Fe.PingTimer,data:`${this.pendings.length+1}`}),this.pendings.length===this.maxOut){this.cancel(!0);return}const e=z();this.ph.flush(e).then(()=>{this._reset()}).catch(()=>{this.cancel()}),this.pendings.push(e),this._schedule()},this.interval)}_reset(){this.pendings=this.pendings.filter(e=>(e.resolve(),!1))}}class _n extends Error{constructor(e){super(e),this.name="AssertionError"}}function yn(r,e="Assertion failed."){if(!r)throw new _n(e)}const Pr=32*1024,Ps=2**32-2;function Dt(r,e,t=0){const s=e.byteLength-t;return r.byteLength>s&&(r=r.subarray(0,s)),e.set(r,t),r.byteLength}class ks{constructor(e){h(this,"_buf");h(this,"_off");if(this._off=0,e==null){this._buf=new Uint8Array(0);return}this._buf=new Uint8Array(e)}bytes(e={copy:!0}){return e.copy===!1?this._buf.subarray(this._off):this._buf.slice(this._off)}empty(){return this._buf.byteLength<=this._off}get length(){return this._buf.byteLength-this._off}get capacity(){return this._buf.buffer.byteLength}truncate(e){if(e===0){this.reset();return}if(e<0||e>this.length)throw Error("bytes.Buffer: truncation out of range");this._reslice(this._off+e)}reset(){this._reslice(0),this._off=0}_tryGrowByReslice(e){const t=this._buf.byteLength;return e<=this.capacity-t?(this._reslice(t+e),t):-1}_reslice(e){yn(e<=this._buf.buffer.byteLength),this._buf=new Uint8Array(this._buf.buffer,0,e)}readByte(){const e=new Uint8Array(1);return this.read(e)?e[0]:null}read(e){if(this.empty())return this.reset(),e.byteLength===0?0:null;const t=Dt(this._buf.subarray(this._off),e);return this._off+=t,t}writeByte(e){return this.write(Uint8Array.of(e))}writeString(e){return this.write(Ge.encode(e))}write(e){const t=this._grow(e.byteLength);return Dt(e,this._buf,t)}_grow(e){const t=this.length;t===0&&this._off!==0&&this.reset();const s=this._tryGrowByReslice(e);if(s>=0)return s;const i=this.capacity;if(e<=Math.floor(i/2)-t)Dt(this._buf.subarray(this._off),this._buf);else{if(i+e>Ps)throw new Error("The buffer cannot be grown beyond the maximum size.");{const n=new Uint8Array(Math.min(2*i+e,Ps));Dt(this._buf.subarray(this._off),n),this._buf=n}}return this._off=0,this._reslice(Math.min(t+e,Ps)),t}grow(e){if(e<0)throw Error("Buffer._grow: negative count");const t=this._grow(e);this._reslice(t)}readFrom(e){let t=0;const s=new Uint8Array(Pr);for(;;){const i=this.capacity-this.length<Pr,n=i?s:new Uint8Array(this._buf.buffer,this.length),o=e.read(n);if(o===null)return t;i?this.write(n.subarray(0,o)):this._reslice(this.length+o),t+=o}}}var de;(function(r){r[r.OK=0]="OK",r[r.ERR=1]="ERR",r[r.MSG=2]="MSG",r[r.INFO=3]="INFO",r[r.PING=4]="PING",r[r.PONG=5]="PONG"})(de||(de={}));function kr(){const r={};return r.sid=-1,r.hdr=-1,r.size=-1,r}const wn=48;class Or{constructor(e){h(this,"dispatcher");h(this,"state");h(this,"as");h(this,"drop");h(this,"hdr");h(this,"ma");h(this,"argBuf");h(this,"msgBuf");this.dispatcher=e,this.state=O.OP_START,this.as=0,this.drop=0,this.hdr=0}parse(e){let t;for(t=0;t<e.length;t++){const s=e[t];switch(this.state){case O.OP_START:switch(s){case C.M:case C.m:this.state=O.OP_M,this.hdr=-1,this.ma=kr();break;case C.H:case C.h:this.state=O.OP_H,this.hdr=0,this.ma=kr();break;case C.P:case C.p:this.state=O.OP_P;break;case C.PLUS:this.state=O.OP_PLUS;break;case C.MINUS:this.state=O.OP_MINUS;break;case C.I:case C.i:this.state=O.OP_I;break;default:throw this.fail(e.subarray(t))}break;case O.OP_H:switch(s){case C.M:case C.m:this.state=O.OP_M;break;default:throw this.fail(e.subarray(t))}break;case O.OP_M:switch(s){case C.S:case C.s:this.state=O.OP_MS;break;default:throw this.fail(e.subarray(t))}break;case O.OP_MS:switch(s){case C.G:case C.g:this.state=O.OP_MSG;break;default:throw this.fail(e.subarray(t))}break;case O.OP_MSG:switch(s){case C.SPACE:case C.TAB:this.state=O.OP_MSG_SPC;break;default:throw this.fail(e.subarray(t))}break;case O.OP_MSG_SPC:switch(s){case C.SPACE:case C.TAB:continue;default:this.state=O.MSG_ARG,this.as=t}break;case O.MSG_ARG:switch(s){case C.CR:this.drop=1;break;case C.NL:{const i=this.argBuf?this.argBuf.bytes():e.subarray(this.as,t-this.drop);this.processMsgArgs(i),this.drop=0,this.as=t+1,this.state=O.MSG_PAYLOAD,t=this.as+this.ma.size-1;break}default:this.argBuf&&this.argBuf.writeByte(s)}break;case O.MSG_PAYLOAD:if(this.msgBuf)if(this.msgBuf.length>=this.ma.size){const i=this.msgBuf.bytes({copy:!1});this.dispatcher.push({kind:de.MSG,msg:this.ma,data:i}),this.argBuf=void 0,this.msgBuf=void 0,this.state=O.MSG_END}else{let i=this.ma.size-this.msgBuf.length;const n=e.length-t;n<i&&(i=n),i>0?(this.msgBuf.write(e.subarray(t,t+i)),t=t+i-1):this.msgBuf.writeByte(s)}else t-this.as>=this.ma.size&&(this.dispatcher.push({kind:de.MSG,msg:this.ma,data:e.subarray(this.as,t)}),this.argBuf=void 0,this.msgBuf=void 0,this.state=O.MSG_END);break;case O.MSG_END:switch(s){case C.NL:this.drop=0,this.as=t+1,this.state=O.OP_START;break;default:continue}break;case O.OP_PLUS:switch(s){case C.O:case C.o:this.state=O.OP_PLUS_O;break;default:throw this.fail(e.subarray(t))}break;case O.OP_PLUS_O:switch(s){case C.K:case C.k:this.state=O.OP_PLUS_OK;break;default:throw this.fail(e.subarray(t))}break;case O.OP_PLUS_OK:switch(s){case C.NL:this.dispatcher.push({kind:de.OK}),this.drop=0,this.state=O.OP_START;break}break;case O.OP_MINUS:switch(s){case C.E:case C.e:this.state=O.OP_MINUS_E;break;default:throw this.fail(e.subarray(t))}break;case O.OP_MINUS_E:switch(s){case C.R:case C.r:this.state=O.OP_MINUS_ER;break;default:throw this.fail(e.subarray(t))}break;case O.OP_MINUS_ER:switch(s){case C.R:case C.r:this.state=O.OP_MINUS_ERR;break;default:throw this.fail(e.subarray(t))}break;case O.OP_MINUS_ERR:switch(s){case C.SPACE:case C.TAB:this.state=O.OP_MINUS_ERR_SPC;break;default:throw this.fail(e.subarray(t))}break;case O.OP_MINUS_ERR_SPC:switch(s){case C.SPACE:case C.TAB:continue;default:this.state=O.MINUS_ERR_ARG,this.as=t}break;case O.MINUS_ERR_ARG:switch(s){case C.CR:this.drop=1;break;case C.NL:{let i;this.argBuf?(i=this.argBuf.bytes(),this.argBuf=void 0):i=e.subarray(this.as,t-this.drop),this.dispatcher.push({kind:de.ERR,data:i}),this.drop=0,this.as=t+1,this.state=O.OP_START;break}default:this.argBuf&&this.argBuf.write(Uint8Array.of(s))}break;case O.OP_P:switch(s){case C.I:case C.i:this.state=O.OP_PI;break;case C.O:case C.o:this.state=O.OP_PO;break;default:throw this.fail(e.subarray(t))}break;case O.OP_PO:switch(s){case C.N:case C.n:this.state=O.OP_PON;break;default:throw this.fail(e.subarray(t))}break;case O.OP_PON:switch(s){case C.G:case C.g:this.state=O.OP_PONG;break;default:throw this.fail(e.subarray(t))}break;case O.OP_PONG:switch(s){case C.NL:this.dispatcher.push({kind:de.PONG}),this.drop=0,this.state=O.OP_START;break}break;case O.OP_PI:switch(s){case C.N:case C.n:this.state=O.OP_PIN;break;default:throw this.fail(e.subarray(t))}break;case O.OP_PIN:switch(s){case C.G:case C.g:this.state=O.OP_PING;break;default:throw this.fail(e.subarray(t))}break;case O.OP_PING:switch(s){case C.NL:this.dispatcher.push({kind:de.PING}),this.drop=0,this.state=O.OP_START;break}break;case O.OP_I:switch(s){case C.N:case C.n:this.state=O.OP_IN;break;default:throw this.fail(e.subarray(t))}break;case O.OP_IN:switch(s){case C.F:case C.f:this.state=O.OP_INF;break;default:throw this.fail(e.subarray(t))}break;case O.OP_INF:switch(s){case C.O:case C.o:this.state=O.OP_INFO;break;default:throw this.fail(e.subarray(t))}break;case O.OP_INFO:switch(s){case C.SPACE:case C.TAB:this.state=O.OP_INFO_SPC;break;default:throw this.fail(e.subarray(t))}break;case O.OP_INFO_SPC:switch(s){case C.SPACE:case C.TAB:continue;default:this.state=O.INFO_ARG,this.as=t}break;case O.INFO_ARG:switch(s){case C.CR:this.drop=1;break;case C.NL:{let i;this.argBuf?(i=this.argBuf.bytes(),this.argBuf=void 0):i=e.subarray(this.as,t-this.drop),this.dispatcher.push({kind:de.INFO,data:i}),this.drop=0,this.as=t+1,this.state=O.OP_START;break}default:this.argBuf&&this.argBuf.writeByte(s)}break;default:throw this.fail(e.subarray(t))}}(this.state===O.MSG_ARG||this.state===O.MINUS_ERR_ARG||this.state===O.INFO_ARG)&&!this.argBuf&&(this.argBuf=new ks(e.subarray(this.as,t-this.drop))),this.state===O.MSG_PAYLOAD&&!this.msgBuf&&(this.argBuf||this.cloneMsgArg(),this.msgBuf=new ks(e.subarray(this.as)))}cloneMsgArg(){const e=this.ma.subject.length,t=this.ma.reply?this.ma.reply.length:0,s=new Uint8Array(e+t);s.set(this.ma.subject),this.ma.reply&&s.set(this.ma.reply,e),this.argBuf=new ks(s),this.ma.subject=s.subarray(0,e),this.ma.reply&&(this.ma.reply=s.subarray(e))}processMsgArgs(e){if(this.hdr>=0)return this.processHeaderMsgArgs(e);const t=[];let s=-1;for(let i=0;i<e.length;i++)switch(e[i]){case C.SPACE:case C.TAB:case C.CR:case C.NL:s>=0&&(t.push(e.subarray(s,i)),s=-1);break;default:s<0&&(s=i)}switch(s>=0&&t.push(e.subarray(s)),t.length){case 3:this.ma.subject=t[0],this.ma.sid=this.protoParseInt(t[1]),this.ma.reply=void 0,this.ma.size=this.protoParseInt(t[2]);break;case 4:this.ma.subject=t[0],this.ma.sid=this.protoParseInt(t[1]),this.ma.reply=t[2],this.ma.size=this.protoParseInt(t[3]);break;default:throw this.fail(e,"processMsgArgs Parse Error")}if(this.ma.sid<0)throw this.fail(e,"processMsgArgs Bad or Missing Sid Error");if(this.ma.size<0)throw this.fail(e,"processMsgArgs Bad or Missing Size Error")}fail(e,t=""){return t?t=`${t} [${this.state}]`:t=`parse error [${this.state}]`,new Error(`${t}: ${ge.decode(e)}`)}processHeaderMsgArgs(e){const t=[];let s=-1;for(let i=0;i<e.length;i++)switch(e[i]){case C.SPACE:case C.TAB:case C.CR:case C.NL:s>=0&&(t.push(e.subarray(s,i)),s=-1);break;default:s<0&&(s=i)}switch(s>=0&&t.push(e.subarray(s)),t.length){case 4:this.ma.subject=t[0],this.ma.sid=this.protoParseInt(t[1]),this.ma.reply=void 0,this.ma.hdr=this.protoParseInt(t[2]),this.ma.size=this.protoParseInt(t[3]);break;case 5:this.ma.subject=t[0],this.ma.sid=this.protoParseInt(t[1]),this.ma.reply=t[2],this.ma.hdr=this.protoParseInt(t[3]),this.ma.size=this.protoParseInt(t[4]);break;default:throw this.fail(e,"processHeaderMsgArgs Parse Error")}if(this.ma.sid<0)throw this.fail(e,"processHeaderMsgArgs Bad or Missing Sid Error");if(this.ma.hdr<0||this.ma.hdr>this.ma.size)throw this.fail(e,"processHeaderMsgArgs Bad or Missing Header Size Error");if(this.ma.size<0)throw this.fail(e,"processHeaderMsgArgs Bad or Missing Size Error")}protoParseInt(e){if(e.length===0)return-1;let t=0;for(let s=0;s<e.length;s++){if(e[s]<48||e[s]>57)return-1;t=t*10+(e[s]-wn)}return t}}var O;(function(r){r[r.OP_START=0]="OP_START",r[r.OP_PLUS=1]="OP_PLUS",r[r.OP_PLUS_O=2]="OP_PLUS_O",r[r.OP_PLUS_OK=3]="OP_PLUS_OK",r[r.OP_MINUS=4]="OP_MINUS",r[r.OP_MINUS_E=5]="OP_MINUS_E",r[r.OP_MINUS_ER=6]="OP_MINUS_ER",r[r.OP_MINUS_ERR=7]="OP_MINUS_ERR",r[r.OP_MINUS_ERR_SPC=8]="OP_MINUS_ERR_SPC",r[r.MINUS_ERR_ARG=9]="MINUS_ERR_ARG",r[r.OP_M=10]="OP_M",r[r.OP_MS=11]="OP_MS",r[r.OP_MSG=12]="OP_MSG",r[r.OP_MSG_SPC=13]="OP_MSG_SPC",r[r.MSG_ARG=14]="MSG_ARG",r[r.MSG_PAYLOAD=15]="MSG_PAYLOAD",r[r.MSG_END=16]="MSG_END",r[r.OP_H=17]="OP_H",r[r.OP_P=18]="OP_P",r[r.OP_PI=19]="OP_PI",r[r.OP_PIN=20]="OP_PIN",r[r.OP_PING=21]="OP_PING",r[r.OP_PO=22]="OP_PO",r[r.OP_PON=23]="OP_PON",r[r.OP_PONG=24]="OP_PONG",r[r.OP_I=25]="OP_I",r[r.OP_IN=26]="OP_IN",r[r.OP_INF=27]="OP_INF",r[r.OP_INFO=28]="OP_INFO",r[r.OP_INFO_SPC=29]="OP_INFO_SPC",r[r.INFO_ARG=30]="INFO_ARG"})(O||(O={}));var C;(function(r){r[r.CR=13]="CR",r[r.E=69]="E",r[r.e=101]="e",r[r.F=70]="F",r[r.f=102]="f",r[r.G=71]="G",r[r.g=103]="g",r[r.H=72]="H",r[r.h=104]="h",r[r.I=73]="I",r[r.i=105]="i",r[r.K=75]="K",r[r.k=107]="k",r[r.M=77]="M",r[r.m=109]="m",r[r.MINUS=45]="MINUS",r[r.N=78]="N",r[r.n=110]="n",r[r.NL=10]="NL",r[r.O=79]="O",r[r.o=111]="o",r[r.P=80]="P",r[r.p=112]="p",r[r.PLUS=43]="PLUS",r[r.R=82]="R",r[r.r=114]="r",r[r.S=83]="S",r[r.s=115]="s",r[r.SPACE=32]="SPACE",r[r.TAB=9]="TAB"})(C||(C={})),function(r){var e=function(c,l){this.hi=c|0,this.lo=l|0},t=function(c){var l,u=new Float64Array(16);if(c)for(l=0;l<c.length;l++)u[l]=c[l];return u},s=function(){throw new Error("no PRNG")},i=new Uint8Array(16),n=new Uint8Array(32);n[0]=9;var o=t(),a=t([1]),d=t([56129,1]),p=t([30883,4953,19914,30187,55467,16705,2637,112,59544,30585,16505,36039,65139,11119,27886,20995]),_=t([61785,9906,39828,60374,45398,33411,5274,224,53552,61171,33010,6542,64743,22239,55772,9222]),y=t([54554,36645,11616,51542,42930,38181,51040,26924,56412,64982,57905,49316,21502,52590,14035,8553]),x=t([26200,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214,26214]),P=t([41136,18958,6951,50414,58488,44335,6150,12099,55207,15867,153,11085,57099,20417,9344,11139]);function I(c,l){return c<<l|c>>>32-l}function T(c,l){var u=c[l+3]&255;return u=u<<8|c[l+2]&255,u=u<<8|c[l+1]&255,u<<8|c[l+0]&255}function J(c,l){var u=c[l]<<24|c[l+1]<<16|c[l+2]<<8|c[l+3],f=c[l+4]<<24|c[l+5]<<16|c[l+6]<<8|c[l+7];return new e(u,f)}function Q(c,l,u){var f;for(f=0;f<4;f++)c[l+f]=u&255,u>>>=8}function L(c,l,u){c[l]=u.hi>>24&255,c[l+1]=u.hi>>16&255,c[l+2]=u.hi>>8&255,c[l+3]=u.hi&255,c[l+4]=u.lo>>24&255,c[l+5]=u.lo>>16&255,c[l+6]=u.lo>>8&255,c[l+7]=u.lo&255}function X(c,l,u,f,m){var b,v=0;for(b=0;b<m;b++)v|=c[l+b]^u[f+b];return(1&v-1>>>8)-1}function pe(c,l,u,f){return X(c,l,u,f,16)}function w(c,l,u,f){return X(c,l,u,f,32)}function j(c,l,u,f,m){var b=new Uint32Array(16),v=new Uint32Array(16),E=new Uint32Array(16),g=new Uint32Array(4),S,M,D;for(S=0;S<4;S++)v[5*S]=T(f,4*S),v[1+S]=T(u,4*S),v[6+S]=T(l,4*S),v[11+S]=T(u,16+4*S);for(S=0;S<16;S++)E[S]=v[S];for(S=0;S<20;S++){for(M=0;M<4;M++){for(D=0;D<4;D++)g[D]=v[(5*M+4*D)%16];for(g[1]^=I(g[0]+g[3]|0,7),g[2]^=I(g[1]+g[0]|0,9),g[3]^=I(g[2]+g[1]|0,13),g[0]^=I(g[3]+g[2]|0,18),D=0;D<4;D++)b[4*M+(M+D)%4]=g[D]}for(D=0;D<16;D++)v[D]=b[D]}if(m){for(S=0;S<16;S++)v[S]=v[S]+E[S]|0;for(S=0;S<4;S++)v[5*S]=v[5*S]-T(f,4*S)|0,v[6+S]=v[6+S]-T(l,4*S)|0;for(S=0;S<4;S++)Q(c,4*S,v[5*S]),Q(c,16+4*S,v[6+S])}else for(S=0;S<16;S++)Q(c,4*S,v[S]+E[S]|0)}function F(c,l,u,f){return j(c,l,u,f,!1),0}function R(c,l,u,f){return j(c,l,u,f,!0),0}var A=new Uint8Array([101,120,112,97,110,100,32,51,50,45,98,121,116,101,32,107]);function $(c,l,u,f,m,b,v){var E=new Uint8Array(16),g=new Uint8Array(64),S,M;if(!m)return 0;for(M=0;M<16;M++)E[M]=0;for(M=0;M<8;M++)E[M]=b[M];for(;m>=64;){for(F(g,E,v,A),M=0;M<64;M++)c[l+M]=(u?u[f+M]:0)^g[M];for(S=1,M=8;M<16;M++)S=S+(E[M]&255)|0,E[M]=S&255,S>>>=8;m-=64,l+=64,u&&(f+=64)}if(m>0)for(F(g,E,v,A),M=0;M<m;M++)c[l+M]=(u?u[f+M]:0)^g[M];return 0}function q(c,l,u,f,m){return $(c,l,null,0,u,f,m)}function U(c,l,u,f,m){var b=new Uint8Array(32);return R(b,f,m,A),q(c,l,u,f.subarray(16),b)}function K(c,l,u,f,m,b,v){var E=new Uint8Array(32);return R(E,b,v,A),$(c,l,u,f,m,b.subarray(16),E)}function te(c,l){var u,f=0;for(u=0;u<17;u++)f=f+(c[u]+l[u]|0)|0,c[u]=f&255,f>>>=8}var ne=new Uint32Array([5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,252]);function se(c,l,u,f,m,b){var v,E,g,S,M=new Uint32Array(17),D=new Uint32Array(17),W=new Uint32Array(17),je=new Uint32Array(17),ht=new Uint32Array(17);for(g=0;g<17;g++)D[g]=W[g]=0;for(g=0;g<16;g++)D[g]=b[g];for(D[3]&=15,D[4]&=252,D[7]&=15,D[8]&=252,D[11]&=15,D[12]&=252,D[15]&=15;m>0;){for(g=0;g<17;g++)je[g]=0;for(g=0;g<16&&g<m;++g)je[g]=u[f+g];for(je[g]=1,f+=g,m-=g,te(W,je),E=0;E<17;E++)for(M[E]=0,g=0;g<17;g++)M[E]=M[E]+W[g]*(g<=E?D[E-g]:320*D[E+17-g]|0)|0|0;for(E=0;E<17;E++)W[E]=M[E];for(S=0,g=0;g<16;g++)S=S+W[g]|0,W[g]=S&255,S>>>=8;for(S=S+W[16]|0,W[16]=S&3,S=5*(S>>>2)|0,g=0;g<16;g++)S=S+W[g]|0,W[g]=S&255,S>>>=8;S=S+W[16]|0,W[16]=S}for(g=0;g<17;g++)ht[g]=W[g];for(te(W,ne),v=-(W[16]>>>7)|0,g=0;g<17;g++)W[g]^=v&(ht[g]^W[g]);for(g=0;g<16;g++)je[g]=b[g+16];for(je[16]=0,te(W,je),g=0;g<16;g++)c[l+g]=W[g];return 0}function oe(c,l,u,f,m,b){var v=new Uint8Array(16);return se(v,0,u,f,m,b),pe(c,l,v,0)}function he(c,l,u,f,m){var b;if(u<32)return-1;for(K(c,0,l,0,u,f,m),se(c,16,c,32,u-32,c),b=0;b<16;b++)c[b]=0;return 0}function ue(c,l,u,f,m){var b,v=new Uint8Array(32);if(u<32||(U(v,0,32,f,m),oe(l,16,l,32,u-32,v)!==0))return-1;for(K(c,0,l,0,u,f,m),b=0;b<32;b++)c[b]=0;return 0}function V(c,l){var u;for(u=0;u<16;u++)c[u]=l[u]|0}function ee(c){var l,u;for(u=0;u<16;u++)c[u]+=65536,l=Math.floor(c[u]/65536),c[(u+1)*(u<15?1:0)]+=l-1+37*(l-1)*(u===15?1:0),c[u]-=l*65536}function ae(c,l,u){for(var f,m=~(u-1),b=0;b<16;b++)f=m&(c[b]^l[b]),c[b]^=f,l[b]^=f}function ot(c,l){var u,f,m,b=t(),v=t();for(u=0;u<16;u++)v[u]=l[u];for(ee(v),ee(v),ee(v),f=0;f<2;f++){for(b[0]=v[0]-65517,u=1;u<15;u++)b[u]=v[u]-65535-(b[u-1]>>16&1),b[u-1]&=65535;b[15]=v[15]-32767-(b[14]>>16&1),m=b[15]>>16&1,b[14]&=65535,ae(v,b,1-m)}for(u=0;u<16;u++)c[2*u]=v[u]&255,c[2*u+1]=v[u]>>8}function Wr(c,l){var u=new Uint8Array(32),f=new Uint8Array(32);return ot(u,c),ot(f,l),w(u,0,f,0)}function Yr(c){var l=new Uint8Array(32);return ot(l,c),l[0]&1}function qs(c,l){var u;for(u=0;u<16;u++)c[u]=l[2*u]+(l[2*u+1]<<8);c[15]&=32767}function Ce(c,l,u){var f;for(f=0;f<16;f++)c[f]=l[f]+u[f]|0}function Ie(c,l,u){var f;for(f=0;f<16;f++)c[f]=l[f]-u[f]|0}function B(c,l,u){var f,m,b=new Float64Array(31);for(f=0;f<31;f++)b[f]=0;for(f=0;f<16;f++)for(m=0;m<16;m++)b[f+m]+=l[f]*u[m];for(f=0;f<15;f++)b[f]+=38*b[f+16];for(f=0;f<16;f++)c[f]=b[f];ee(c),ee(c)}function Pe(c,l){B(c,l,l)}function Xr(c,l){var u=t(),f;for(f=0;f<16;f++)u[f]=l[f];for(f=253;f>=0;f--)Pe(u,u),f!==2&&f!==4&&B(u,u,l);for(f=0;f<16;f++)c[f]=u[f]}function Zr(c,l){var u=t(),f;for(f=0;f<16;f++)u[f]=l[f];for(f=250;f>=0;f--)Pe(u,u),f!==1&&B(u,u,l);for(f=0;f<16;f++)c[f]=u[f]}function Yt(c,l,u){var f=new Uint8Array(32),m=new Float64Array(80),b,v,E=t(),g=t(),S=t(),M=t(),D=t(),W=t();for(v=0;v<31;v++)f[v]=l[v];for(f[31]=l[31]&127|64,f[0]&=248,qs(m,u),v=0;v<16;v++)g[v]=m[v],M[v]=E[v]=S[v]=0;for(E[0]=M[0]=1,v=254;v>=0;--v)b=f[v>>>3]>>>(v&7)&1,ae(E,g,b),ae(S,M,b),Ce(D,E,S),Ie(E,E,S),Ce(S,g,M),Ie(g,g,M),Pe(M,D),Pe(W,E),B(E,S,E),B(S,g,D),Ce(D,E,S),Ie(E,E,S),Pe(g,E),Ie(S,M,W),B(E,S,d),Ce(E,E,M),B(S,S,E),B(E,M,W),B(M,g,m),Pe(g,D),ae(E,g,b),ae(S,M,b);for(v=0;v<16;v++)m[v+16]=E[v],m[v+32]=S[v],m[v+48]=g[v],m[v+64]=M[v];var je=m.subarray(32),ht=m.subarray(16);return Xr(je,je),B(ht,ht,je),ot(c,ht),0}function Xt(c,l){return Yt(c,l,n)}function Qr(c,l){return s(l,32),Xt(c,l)}function Zt(c,l,u){var f=new Uint8Array(32);return Yt(f,u,l),R(c,i,f,A)}var ei=he,Oo=ue;function Co(c,l,u,f,m,b){var v=new Uint8Array(32);return Zt(v,m,b),ei(c,l,u,f,v)}function Io(c,l,u,f,m,b){var v=new Uint8Array(32);return Zt(v,m,b),Oo(c,l,u,f,v)}function Pt(){var c=0,l=0,u=0,f=0,m=65535,b,v,E;for(E=0;E<arguments.length;E++)b=arguments[E].lo,v=arguments[E].hi,c+=b&m,l+=b>>>16,u+=v&m,f+=v>>>16;return l+=c>>>16,u+=l>>>16,f+=u>>>16,new e(u&m|f<<16,c&m|l<<16)}function ti(c,l){return new e(c.hi>>>l,c.lo>>>l|c.hi<<32-l)}function Qt(){var c=0,l=0,u;for(u=0;u<arguments.length;u++)c^=arguments[u].lo,l^=arguments[u].hi;return new e(l,c)}function Te(c,l){var u,f,m=32-l;return l<32?(u=c.hi>>>l|c.lo<<m,f=c.lo>>>l|c.hi<<m):l<64&&(u=c.lo>>>l|c.hi<<m,f=c.hi>>>l|c.lo<<m),new e(u,f)}function jo(c,l,u){var f=c.hi&l.hi^~c.hi&u.hi,m=c.lo&l.lo^~c.lo&u.lo;return new e(f,m)}function Ro(c,l,u){var f=c.hi&l.hi^c.hi&u.hi^l.hi&u.hi,m=c.lo&l.lo^c.lo&u.lo^l.lo&u.lo;return new e(f,m)}function No(c){return Qt(Te(c,28),Te(c,34),Te(c,39))}function To(c){return Qt(Te(c,14),Te(c,18),Te(c,41))}function Mo(c){return Qt(Te(c,1),Te(c,8),ti(c,7))}function $o(c){return Qt(Te(c,19),Te(c,61),ti(c,6))}var Uo=[new e(1116352408,3609767458),new e(1899447441,602891725),new e(3049323471,3964484399),new e(3921009573,2173295548),new e(961987163,4081628472),new e(1508970993,3053834265),new e(2453635748,2937671579),new e(2870763221,3664609560),new e(3624381080,2734883394),new e(310598401,1164996542),new e(607225278,1323610764),new e(1426881987,3590304994),new e(1925078388,4068182383),new e(2162078206,991336113),new e(2614888103,633803317),new e(3248222580,3479774868),new e(3835390401,2666613458),new e(4022224774,944711139),new e(264347078,2341262773),new e(604807628,2007800933),new e(770255983,1495990901),new e(1249150122,1856431235),new e(1555081692,3175218132),new e(1996064986,2198950837),new e(2554220882,3999719339),new e(2821834349,766784016),new e(2952996808,2566594879),new e(3210313671,3203337956),new e(3336571891,1034457026),new e(3584528711,2466948901),new e(113926993,3758326383),new e(338241895,168717936),new e(666307205,1188179964),new e(773529912,1546045734),new e(1294757372,1522805485),new e(1396182291,2643833823),new e(1695183700,2343527390),new e(1986661051,1014477480),new e(2177026350,1206759142),new e(2456956037,344077627),new e(2730485921,1290863460),new e(2820302411,3158454273),new e(3259730800,3505952657),new e(3345764771,106217008),new e(3516065817,3606008344),new e(3600352804,1432725776),new e(4094571909,1467031594),new e(275423344,851169720),new e(430227734,3100823752),new e(506948616,1363258195),new e(659060556,3750685593),new e(883997877,3785050280),new e(958139571,3318307427),new e(1322822218,3812723403),new e(1537002063,2003034995),new e(1747873779,3602036899),new e(1955562222,1575990012),new e(2024104815,1125592928),new e(2227730452,2716904306),new e(2361852424,442776044),new e(2428436474,593698344),new e(2756734187,3733110249),new e(3204031479,2999351573),new e(3329325298,3815920427),new e(3391569614,3928383900),new e(3515267271,566280711),new e(3940187606,3454069534),new e(4118630271,4000239992),new e(116418474,1914138554),new e(174292421,2731055270),new e(289380356,3203993006),new e(460393269,320620315),new e(685471733,587496836),new e(852142971,1086792851),new e(1017036298,365543100),new e(1126000580,2618297676),new e(1288033470,3409855158),new e(1501505948,4234509866),new e(1607167915,987167468),new e(1816402316,1246189591)];function si(c,l,u){var f=[],m=[],b=[],v=[],E,g,S;for(g=0;g<8;g++)f[g]=b[g]=J(c,8*g);for(var M=0;u>=128;){for(g=0;g<16;g++)v[g]=J(l,8*g+M);for(g=0;g<80;g++){for(S=0;S<8;S++)m[S]=b[S];for(E=Pt(b[7],To(b[4]),jo(b[4],b[5],b[6]),Uo[g],v[g%16]),m[7]=Pt(E,No(b[0]),Ro(b[0],b[1],b[2])),m[3]=Pt(m[3],E),S=0;S<8;S++)b[(S+1)%8]=m[S];if(g%16===15)for(S=0;S<16;S++)v[S]=Pt(v[S],v[(S+9)%16],Mo(v[(S+1)%16]),$o(v[(S+14)%16]))}for(g=0;g<8;g++)b[g]=Pt(b[g],f[g]),f[g]=b[g];M+=128,u-=128}for(g=0;g<8;g++)L(c,8*g,f[g]);return u}var Lo=new Uint8Array([106,9,230,103,243,188,201,8,187,103,174,133,132,202,167,59,60,110,243,114,254,148,248,43,165,79,245,58,95,29,54,241,81,14,82,127,173,230,130,209,155,5,104,140,43,62,108,31,31,131,217,171,251,65,189,107,91,224,205,25,19,126,33,121]);function Ve(c,l,u){var f=new Uint8Array(64),m=new Uint8Array(256),b,v=u;for(b=0;b<64;b++)f[b]=Lo[b];for(si(f,l,u),u%=128,b=0;b<256;b++)m[b]=0;for(b=0;b<u;b++)m[b]=l[v-u+b];for(m[u]=128,u=256-128*(u<112?1:0),m[u-9]=0,L(m,u-8,new e(v/536870912|0,v<<3)),si(f,m,u),b=0;b<64;b++)c[b]=f[b];return 0}function es(c,l){var u=t(),f=t(),m=t(),b=t(),v=t(),E=t(),g=t(),S=t(),M=t();Ie(u,c[1],c[0]),Ie(M,l[1],l[0]),B(u,u,M),Ce(f,c[0],c[1]),Ce(M,l[0],l[1]),B(f,f,M),B(m,c[3],l[3]),B(m,m,_),B(b,c[2],l[2]),Ce(b,b,b),Ie(v,f,u),Ie(E,b,m),Ce(g,b,m),Ce(S,f,u),B(c[0],v,E),B(c[1],S,g),B(c[2],g,E),B(c[3],v,S)}function ri(c,l,u){var f;for(f=0;f<4;f++)ae(c[f],l[f],u)}function Fs(c,l){var u=t(),f=t(),m=t();Xr(m,l[2]),B(u,l[0],m),B(f,l[1],m),ot(c,f),c[31]^=Yr(u)<<7}function Bs(c,l,u){var f,m;for(V(c[0],o),V(c[1],a),V(c[2],a),V(c[3],o),m=255;m>=0;--m)f=u[m/8|0]>>(m&7)&1,ri(c,l,f),es(l,c),es(c,c),ri(c,l,f)}function ts(c,l){var u=[t(),t(),t(),t()];V(u[0],y),V(u[1],x),V(u[2],a),B(u[3],y,x),Bs(c,u,l)}function Ds(c,l,u){var f=new Uint8Array(64),m=[t(),t(),t(),t()],b;for(u||s(l,32),Ve(f,l,32),f[0]&=248,f[31]&=127,f[31]|=64,ts(m,f),Fs(c,m),b=0;b<32;b++)l[b+32]=c[b];return 0}var ss=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function Hs(c,l){var u,f,m,b;for(f=63;f>=32;--f){for(u=0,m=f-32,b=f-12;m<b;++m)l[m]+=u-16*l[f]*ss[m-(f-32)],u=Math.floor((l[m]+128)/256),l[m]-=u*256;l[m]+=u,l[f]=0}for(u=0,m=0;m<32;m++)l[m]+=u-(l[31]>>4)*ss[m],u=l[m]>>8,l[m]&=255;for(m=0;m<32;m++)l[m]-=u*ss[m];for(f=0;f<32;f++)l[f+1]+=l[f]>>8,c[f]=l[f]&255}function Js(c){var l=new Float64Array(64),u;for(u=0;u<64;u++)l[u]=c[u];for(u=0;u<64;u++)c[u]=0;Hs(c,l)}function ii(c,l,u,f){var m=new Uint8Array(64),b=new Uint8Array(64),v=new Uint8Array(64),E,g,S=new Float64Array(64),M=[t(),t(),t(),t()];Ve(m,f,32),m[0]&=248,m[31]&=127,m[31]|=64;var D=u+64;for(E=0;E<u;E++)c[64+E]=l[E];for(E=0;E<32;E++)c[32+E]=m[32+E];for(Ve(v,c.subarray(32),u+32),Js(v),ts(M,v),Fs(c,M),E=32;E<64;E++)c[E]=f[E];for(Ve(b,c,u+64),Js(b),E=0;E<64;E++)S[E]=0;for(E=0;E<32;E++)S[E]=v[E];for(E=0;E<32;E++)for(g=0;g<32;g++)S[E+g]+=b[E]*m[g];return Hs(c.subarray(32),S),D}function qo(c,l){var u=t(),f=t(),m=t(),b=t(),v=t(),E=t(),g=t();return V(c[2],a),qs(c[1],l),Pe(m,c[1]),B(b,m,p),Ie(m,m,c[2]),Ce(b,c[2],b),Pe(v,b),Pe(E,v),B(g,E,v),B(u,g,m),B(u,u,b),Zr(u,u),B(u,u,m),B(u,u,b),B(u,u,b),B(c[0],u,b),Pe(f,c[0]),B(f,f,b),Wr(f,m)&&B(c[0],c[0],P),Pe(f,c[0]),B(f,f,b),Wr(f,m)?-1:(Yr(c[0])===l[31]>>7&&Ie(c[0],o,c[0]),B(c[3],c[0],c[1]),0)}function zs(c,l,u,f){var m,b=new Uint8Array(32),v=new Uint8Array(64),E=[t(),t(),t(),t()],g=[t(),t(),t(),t()];if(u<64||qo(g,f))return-1;for(m=0;m<u;m++)c[m]=l[m];for(m=0;m<32;m++)c[m+32]=f[m];if(Ve(v,c,u),Js(v),Bs(E,g,v),ts(g,l.subarray(32)),es(E,g),Fs(b,E),u-=64,w(l,0,b,0)){for(m=0;m<u;m++)c[m]=0;return-1}for(m=0;m<u;m++)c[m]=l[m+64];return u}var Gs=32,rs=24,kt=32,at=16,Ot=32,is=32,Ct=32,It=32,Ks=32,ni=rs,Fo=kt,Bo=at,Le=64,We=32,ct=64,Vs=32,Ws=64;r.lowlevel={crypto_core_hsalsa20:R,crypto_stream_xor:K,crypto_stream:U,crypto_stream_salsa20_xor:$,crypto_stream_salsa20:q,crypto_onetimeauth:se,crypto_onetimeauth_verify:oe,crypto_verify_16:pe,crypto_verify_32:w,crypto_secretbox:he,crypto_secretbox_open:ue,crypto_scalarmult:Yt,crypto_scalarmult_base:Xt,crypto_box_beforenm:Zt,crypto_box_afternm:ei,crypto_box:Co,crypto_box_open:Io,crypto_box_keypair:Qr,crypto_hash:Ve,crypto_sign:ii,crypto_sign_keypair:Ds,crypto_sign_open:zs,crypto_secretbox_KEYBYTES:Gs,crypto_secretbox_NONCEBYTES:rs,crypto_secretbox_ZEROBYTES:kt,crypto_secretbox_BOXZEROBYTES:at,crypto_scalarmult_BYTES:Ot,crypto_scalarmult_SCALARBYTES:is,crypto_box_PUBLICKEYBYTES:Ct,crypto_box_SECRETKEYBYTES:It,crypto_box_BEFORENMBYTES:Ks,crypto_box_NONCEBYTES:ni,crypto_box_ZEROBYTES:Fo,crypto_box_BOXZEROBYTES:Bo,crypto_sign_BYTES:Le,crypto_sign_PUBLICKEYBYTES:We,crypto_sign_SECRETKEYBYTES:ct,crypto_sign_SEEDBYTES:Vs,crypto_hash_BYTES:Ws,gf:t,D:p,L:ss,pack25519:ot,unpack25519:qs,M:B,A:Ce,S:Pe,Z:Ie,pow2523:Zr,add:es,set25519:V,modL:Hs,scalarmult:Bs,scalarbase:ts};function oi(c,l){if(c.length!==Gs)throw new Error("bad key size");if(l.length!==rs)throw new Error("bad nonce size")}function Do(c,l){if(c.length!==Ct)throw new Error("bad public key size");if(l.length!==It)throw new Error("bad secret key size")}function xe(){for(var c=0;c<arguments.length;c++)if(!(arguments[c]instanceof Uint8Array))throw new TypeError("unexpected type, use Uint8Array")}function ai(c){for(var l=0;l<c.length;l++)c[l]=0}r.randomBytes=function(c){var l=new Uint8Array(c);return s(l,c),l},r.secretbox=function(c,l,u){xe(c,l,u),oi(u,l);for(var f=new Uint8Array(kt+c.length),m=new Uint8Array(f.length),b=0;b<c.length;b++)f[b+kt]=c[b];return he(m,f,f.length,l,u),m.subarray(at)},r.secretbox.open=function(c,l,u){xe(c,l,u),oi(u,l);for(var f=new Uint8Array(at+c.length),m=new Uint8Array(f.length),b=0;b<c.length;b++)f[b+at]=c[b];return f.length<32||ue(m,f,f.length,l,u)!==0?null:m.subarray(kt)},r.secretbox.keyLength=Gs,r.secretbox.nonceLength=rs,r.secretbox.overheadLength=at,r.scalarMult=function(c,l){if(xe(c,l),c.length!==is)throw new Error("bad n size");if(l.length!==Ot)throw new Error("bad p size");var u=new Uint8Array(Ot);return Yt(u,c,l),u},r.scalarMult.base=function(c){if(xe(c),c.length!==is)throw new Error("bad n size");var l=new Uint8Array(Ot);return Xt(l,c),l},r.scalarMult.scalarLength=is,r.scalarMult.groupElementLength=Ot,r.box=function(c,l,u,f){var m=r.box.before(u,f);return r.secretbox(c,l,m)},r.box.before=function(c,l){xe(c,l),Do(c,l);var u=new Uint8Array(Ks);return Zt(u,c,l),u},r.box.after=r.secretbox,r.box.open=function(c,l,u,f){var m=r.box.before(u,f);return r.secretbox.open(c,l,m)},r.box.open.after=r.secretbox.open,r.box.keyPair=function(){var c=new Uint8Array(Ct),l=new Uint8Array(It);return Qr(c,l),{publicKey:c,secretKey:l}},r.box.keyPair.fromSecretKey=function(c){if(xe(c),c.length!==It)throw new Error("bad secret key size");var l=new Uint8Array(Ct);return Xt(l,c),{publicKey:l,secretKey:new Uint8Array(c)}},r.box.publicKeyLength=Ct,r.box.secretKeyLength=It,r.box.sharedKeyLength=Ks,r.box.nonceLength=ni,r.box.overheadLength=r.secretbox.overheadLength,r.sign=function(c,l){if(xe(c,l),l.length!==ct)throw new Error("bad secret key size");var u=new Uint8Array(Le+c.length);return ii(u,c,c.length,l),u},r.sign.open=function(c,l){if(xe(c,l),l.length!==We)throw new Error("bad public key size");var u=new Uint8Array(c.length),f=zs(u,c,c.length,l);if(f<0)return null;for(var m=new Uint8Array(f),b=0;b<m.length;b++)m[b]=u[b];return m},r.sign.detached=function(c,l){for(var u=r.sign(c,l),f=new Uint8Array(Le),m=0;m<f.length;m++)f[m]=u[m];return f},r.sign.detached.verify=function(c,l,u){if(xe(c,l,u),l.length!==Le)throw new Error("bad signature size");if(u.length!==We)throw new Error("bad public key size");var f=new Uint8Array(Le+c.length),m=new Uint8Array(Le+c.length),b;for(b=0;b<Le;b++)f[b]=l[b];for(b=0;b<c.length;b++)f[b+Le]=c[b];return zs(m,f,f.length,u)>=0},r.sign.keyPair=function(){var c=new Uint8Array(We),l=new Uint8Array(ct);return Ds(c,l),{publicKey:c,secretKey:l}},r.sign.keyPair.fromSecretKey=function(c){if(xe(c),c.length!==ct)throw new Error("bad secret key size");for(var l=new Uint8Array(We),u=0;u<l.length;u++)l[u]=c[32+u];return{publicKey:l,secretKey:new Uint8Array(c)}},r.sign.keyPair.fromSeed=function(c){if(xe(c),c.length!==Vs)throw new Error("bad seed size");for(var l=new Uint8Array(We),u=new Uint8Array(ct),f=0;f<32;f++)u[f]=c[f];return Ds(l,u,!0),{publicKey:l,secretKey:u}},r.sign.publicKeyLength=We,r.sign.secretKeyLength=ct,r.sign.seedLength=Vs,r.sign.signatureLength=Le,r.hash=function(c){xe(c);var l=new Uint8Array(Ws);return Ve(l,c,c.length),l},r.hash.hashLength=Ws,r.verify=function(c,l){return xe(c,l),c.length===0||l.length===0||c.length!==l.length?!1:X(c,0,l,0,c.length)===0},r.setPRNG=function(c){s=c},function(){var c=typeof globalThis<"u"?globalThis.crypto||globalThis.msCrypto:null;if(c&&c.getRandomValues){var l=65536;r.setPRNG(function(u,f){var m,b=new Uint8Array(f);for(m=0;m<f;m+=l)c.getRandomValues(b.subarray(m,m+Math.min(f-m,l)));for(m=0;m<f;m++)u[m]=b[m];ai(b)})}else typeof require<"u"&&(crypto = window.crypto || globalThis.crypto,c&&c.randomBytes&&r.setPRNG(function(u,f){var m,b=c.randomBytes(f);for(m=0;m<f;m++)u[m]=b[m];ai(b)}))}()}(typeof module<"u"&&module.exports?module.exports:globalThis.nacl=globalThis.nacl||{});const Ht=typeof module<"u"&&module.exports?module.exports:globalThis.nacl;Ht.sign.keyPair.fromSeed,Ht.sign.detached,Ht.sign.detached.verify,Ht.randomBytes;var Cr;(function(r){r.InvalidPrefixByte="nkeys: invalid prefix byte",r.InvalidKey="nkeys: invalid key",r.InvalidPublicKey="nkeys: invalid public key",r.InvalidSeedLen="nkeys: invalid seed length",r.InvalidSeed="nkeys: invalid seed",r.InvalidEncoding="nkeys: invalid encoded key",r.InvalidSignature="nkeys: signature verification failed",r.CannotSign="nkeys: cannot sign, no private key available",r.PublicKeyOnly="nkeys: no seed or private key available",r.InvalidChecksum="nkeys: invalid checksum",r.SerializationError="nkeys: serialization error",r.ApiError="nkeys: api error",r.ClearedPair="nkeys: pair is cleared"})(Cr||(Cr={}));var Ir;(function(r){r[r.Seed=144]="Seed",r[r.Private=120]="Private",r[r.Operator=112]="Operator",r[r.Server=104]="Server",r[r.Cluster=16]="Cluster",r[r.Account=0]="Account",r[r.User=160]="User"})(Ir||(Ir={}));function xn(r){return e=>{let t={};return r.forEach(s=>{const i=s(e)||{};t=Object.assign(t,i)}),t}}function Sn(){return()=>{}}function vn(r,e){return()=>{const t=typeof r=="function"?r():r,s=typeof e=="function"?e():e;return{user:t,pass:s}}}function En(r){return()=>({auth_token:typeof r=="function"?r():r})}const jr=2*60*1e3,An=2,Rr=2*1e3;function Pn(){return{maxPingOut:2,maxReconnectAttempts:10,noRandomize:!1,pedantic:!1,pingInterval:jr,reconnect:!0,reconnectJitter:100,reconnectJitterTLS:1e3,reconnectTimeWait:Rr,tls:void 0,verbose:!1,waitOnFirstConnect:!1,ignoreAuthErrorAbort:!1}}function kn(r){const e=[];return typeof r.authenticator=="function"&&e.push(r.authenticator),Array.isArray(r.authenticator)&&e.push(...r.authenticator),r.token&&e.push(En(r.token)),r.user&&e.push(vn(r.user,r.pass)),e.length===0?Sn():xn(e)}function On(r){const e=`${hs}:${vr()}`;if(r=r||{servers:[e]},r.servers=r.servers||[],typeof r.servers=="string"&&(r.servers=[r.servers]),r.servers.length>0&&r.port)throw new N("port and servers options are mutually exclusive",k.InvalidOption);r.servers.length===0&&r.port&&(r.servers=[`${hs}:${r.port}`]),r.servers&&r.servers.length===0&&(r.servers=[e]);const t=Tt(Pn(),r);if(t.authenticator=kn(t),["reconnectDelayHandler","authenticator"].forEach(s=>{if(t[s]&&typeof t[s]!="function")throw new N(`${s} option should be a function`,k.NotFunction)}),t.reconnectDelayHandler||(t.reconnectDelayHandler=()=>{let s=t.tls?t.reconnectJitterTLS:t.reconnectJitter;return s&&(s++,s=Math.floor(Math.random()*s)),t.reconnectTimeWait+s}),t.inboxPrefix)try{$e(t.inboxPrefix)}catch(s){throw new N(s.message,k.ApiError)}if(t.resolve===void 0&&(t.resolve=typeof vs()=="function"),t.resolve&&typeof vs()!="function")throw new N("'resolve' is not supported on this client",k.InvalidOption);return t}function Cn(r,e){const{proto:t,tls_required:s,tls_available:i}=r;if((t===void 0||t<1)&&e.noEcho)throw new N("noEcho",k.ServerOptionNotAvailable);const n=s||i||!1;if(e.tls&&!n)throw new N("tls",k.ServerOptionNotAvailable)}const In=1024*32,jn=/^INFO\s+([^\r\n]+)\r\n/i,Rn=ft(`PONG\r
14
14
  `),Nr=ft(`PING\r
15
15
  `);class Nn{constructor(e,t,s){h(this,"echo");h(this,"no_responders");h(this,"protocol");h(this,"verbose");h(this,"pedantic");h(this,"jwt");h(this,"nkey");h(this,"sig");h(this,"user");h(this,"pass");h(this,"auth_token");h(this,"tls_required");h(this,"name");h(this,"lang");h(this,"version");h(this,"headers");this.protocol=1,this.version=e.version,this.lang=e.lang,this.echo=t.noEcho?!1:void 0,this.verbose=t.verbose,this.pedantic=t.pedantic,this.tls_required=t.tls?!0:void 0,this.name=t.name;const i=(t&&typeof t.authenticator=="function"?t.authenticator(s):{})||{};Tt(this,i)}}class Tr extends re{constructor(t,s,i={}){var o;super();h(this,"sid");h(this,"queue");h(this,"draining");h(this,"max");h(this,"subject");h(this,"drained");h(this,"protocol");h(this,"timer");h(this,"info");h(this,"cleanupFn");h(this,"closed");h(this,"requestSubject");Tt(this,i),this.protocol=t,this.subject=s,this.draining=!1,this.noIterator=typeof i.callback=="function",this.closed=z();const n=!((o=t.options)!=null&&o.noAsyncTraces);i.timeout&&(this.timer=Ye(i.timeout,n),this.timer.then(()=>{this.timer=void 0}).catch(a=>{this.stop(a),this.noIterator&&this.callback(a,{})})),this.noIterator||this.iterClosed.then(()=>{this.closed.resolve(),this.unsubscribe()})}setPrePostHandlers(t){if(this.noIterator){const s=this.callback,i=t.ingestionFilterFn?t.ingestionFilterFn:()=>({ingest:!0,protocol:!1}),n=t.protocolFilterFn?t.protocolFilterFn:()=>!0,o=t.dispatchedFn?t.dispatchedFn:()=>{};this.callback=(a,d)=>{const{ingest:p}=i(d);p&&n(d)&&(s(a,d),o(d))}}else this.protocolFilterFn=t.protocolFilterFn,this.dispatchedFn=t.dispatchedFn}callback(t,s){this.cancelTimeout(),t?this.stop(t):this.push(s)}close(){if(!this.isClosed()){this.cancelTimeout();const t=()=>{if(this.stop(),this.cleanupFn)try{this.cleanupFn(this,this.info)}catch{}this.closed.resolve()};this.noIterator?t():this.push(t)}}unsubscribe(t){this.protocol.unsubscribe(this,t)}cancelTimeout(){this.timer&&(this.timer.cancel(),this.timer=void 0)}drain(){return this.protocol.isClosed()?Promise.reject(N.errorForCode(k.ConnectionClosed)):this.isClosed()?Promise.reject(N.errorForCode(k.SubClosed)):(this.drained||(this.draining=!0,this.protocol.unsub(this),this.drained=this.protocol.flush(z()).then(()=>{this.protocol.subscriptions.cancel(this)}).catch(()=>{this.protocol.subscriptions.cancel(this)})),this.drained)}isDraining(){return this.draining}isClosed(){return this.done}getSubject(){return this.subject}getMax(){return this.max}getID(){return this.sid}}class Tn{constructor(){h(this,"mux");h(this,"subs");h(this,"sidCounter");this.sidCounter=0,this.mux=null,this.subs=new Map}size(){return this.subs.size}add(e){return this.sidCounter++,e.sid=this.sidCounter,this.subs.set(e.sid,e),e}setMux(e){return this.mux=e,e}getMux(){return this.mux}get(e){return this.subs.get(e)}resub(e){return this.sidCounter++,this.subs.delete(e.sid),e.sid=this.sidCounter,this.subs.set(e.sid,e),e}all(){return Array.from(this.subs.values())}cancel(e){e&&(e.close(),this.subs.delete(e.sid))}handleError(e){if(e&&e.permissionContext){const t=e.permissionContext,s=this.all();let i;if(t.operation==="subscription"&&(i=s.find(n=>n.subject===t.subject&&n.queue===t.queue)),t.operation==="publish"&&(i=s.find(n=>n.requestSubject===t.subject)),i)return i.callback(e,{}),i.close(),this.subs.delete(i.sid),i!==this.mux}return!1}close(){this.subs.forEach(e=>{e.close()})}}class Jt{constructor(e,t){h(this,"connected");h(this,"connectedOnce");h(this,"infoReceived");h(this,"info");h(this,"muxSubscriptions");h(this,"options");h(this,"outbound");h(this,"pongs");h(this,"subscriptions");h(this,"transport");h(this,"noMorePublishing");h(this,"connectError");h(this,"publisher");h(this,"_closed");h(this,"closed");h(this,"listeners");h(this,"heartbeats");h(this,"parser");h(this,"outMsgs");h(this,"inMsgs");h(this,"outBytes");h(this,"inBytes");h(this,"pendingLimit");h(this,"lastError");h(this,"abortReconnect");h(this,"whyClosed");h(this,"servers");h(this,"server");h(this,"features");h(this,"connectPromise");this._closed=!1,this.connected=!1,this.connectedOnce=!1,this.infoReceived=!1,this.noMorePublishing=!1,this.abortReconnect=!1,this.listeners=[],this.pendingLimit=In,this.outMsgs=0,this.inMsgs=0,this.outBytes=0,this.inBytes=0,this.options=e,this.publisher=t,this.subscriptions=new Tn,this.muxSubscriptions=new bn,this.outbound=new rt,this.pongs=[],this.whyClosed="",this.pendingLimit=e.pendingLimit||this.pendingLimit,this.features=new Wi({major:0,minor:0,micro:0}),this.connectPromise=null;const s=typeof e.servers=="string"?[e.servers]:e.servers;this.servers=new mn(s,{randomize:!e.noRandomize}),this.closed=z(),this.parser=new Or(this),this.heartbeats=new gn(this,this.options.pingInterval||jr,this.options.maxPingOut||An)}resetOutbound(){this.outbound.reset();const e=this.pongs;this.pongs=[];const t=N.errorForCode(k.Disconnect);t.stack="",e.forEach(s=>{s.reject(t)}),this.parser=new Or(this),this.infoReceived=!1}dispatchStatus(e){this.listeners.forEach(t=>{t.push(e)})}status(){const e=new re;return this.listeners.push(e),e}prepare(){this.transport&&this.transport.discard(),this.info=void 0,this.resetOutbound();const e=z();return e.catch(()=>{}),this.pongs.unshift(e),this.connectError=t=>{e.reject(t)},this.transport=Zi(),this.transport.closed().then(async t=>{if(this.connected=!1,!this.isClosed()){await this.disconnected(this.transport.closeError||this.lastError);return}}),e}disconnect(){this.dispatchStatus({type:Fe.StaleConnection,data:""}),this.transport.disconnect()}reconnect(){return this.connected&&(this.dispatchStatus({type:Fe.ClientInitiatedReconnect,data:""}),this.transport.disconnect()),Promise.resolve()}async disconnected(e){this.dispatchStatus({type:Se.Disconnect,data:this.servers.getCurrentServer().toString()}),this.options.reconnect?await this.dialLoop().then(()=>{var t;this.dispatchStatus({type:Se.Reconnect,data:this.servers.getCurrentServer().toString()}),((t=this.lastError)==null?void 0:t.code)===k.AuthenticationExpired&&(this.lastError=void 0)}).catch(t=>{this._close(t)}):await this._close(e)}async dial(e){const t=this.prepare();let s;try{s=Ye(this.options.timeout||2e4);const i=this.transport.connect(e,this.options);await Promise.race([i,s]),(async()=>{try{for await(const n of this.transport)this.parser.parse(n)}catch(n){console.log("reader closed",n)}})().then()}catch(i){t.reject(i)}try{await Promise.race([s,t]),s&&s.cancel(),this.connected=!0,this.connectError=void 0,this.sendSubscriptions(),this.connectedOnce=!0,this.server.didConnect=!0,this.server.reconnects=0,this.flushPending(),this.heartbeats.start()}catch(i){throw s&&s.cancel(),await this.transport.close(i),i}}async _doDial(e){const{resolve:t}=this.options,s=await e.resolve({fn:vs(),debug:this.options.debug,randomize:!this.options.noRandomize,resolve:t});let i=null;for(const n of s)try{i=null,this.dispatchStatus({type:Fe.Reconnecting,data:n.toString()}),await this.dial(n);return}catch(o){i=o}throw i}dialLoop(){return this.connectPromise===null&&(this.connectPromise=this.dodialLoop(),this.connectPromise.then(()=>{}).catch(()=>{}).finally(()=>{this.connectPromise=null})),this.connectPromise}async dodialLoop(){let e;for(;;){this._closed&&this.servers.clear();const t=this.options.reconnectDelayHandler?this.options.reconnectDelayHandler():Rr;let s=t;const i=this.selectServer();if(!i||this.abortReconnect)throw e||(this.lastError?this.lastError:N.errorForCode(k.ConnectionRefused));const n=Date.now();if(i.lastConnect===0||i.lastConnect+t<=n){i.lastConnect=Date.now();try{await this._doDial(i);break}catch(o){if(e=o,!this.connectedOnce){if(this.options.waitOnFirstConnect)continue;this.servers.removeCurrentServer()}i.reconnects++;const a=this.options.maxReconnectAttempts||0;a!==-1&&i.reconnects>=a&&this.servers.removeCurrentServer()}}else s=Math.min(s,i.lastConnect+t-n),await Xe(s)}}static async connect(e,t){const s=new Jt(e,t);return await s.dialLoop(),s}static toError(e){const t=e?e.toLowerCase():"";if(t.indexOf("permissions violation")!==-1){const s=new N(e,k.PermissionsViolation),i=e.match(/(Publish|Subscription) to "(\S+)"/);if(i){s.permissionContext={operation:i[1].toLowerCase(),subject:i[2],queue:void 0};const n=e.match(/using queue "(\S+)"/);n&&(s.permissionContext.queue=n[1])}return s}else return t.indexOf("authorization violation")!==-1?new N(e,k.AuthorizationViolation):t.indexOf("user authentication expired")!==-1?new N(e,k.AuthenticationExpired):t.indexOf("account authentication expired")!=-1?new N(e,k.AccountExpired):t.indexOf("authentication timeout")!==-1?new N(e,k.AuthenticationTimeout):new N(e,k.ProtocolError)}processMsg(e,t){if(this.inMsgs++,this.inBytes+=t.length,!this.subscriptions.sidCounter)return;const s=this.subscriptions.get(e.sid);s&&(s.received+=1,s.callback&&s.callback(null,new ds(e,t,this)),s.max!==void 0&&s.received>=s.max&&s.unsubscribe())}processError(e){const t=rr(e),s=Jt.toError(t),i={type:Se.Error,data:s.code};if(s.isPermissionError()){let n=!1;if(s.permissionContext){i.permissionContext=s.permissionContext;const o=this.subscriptions.getMux();n=(o==null?void 0:o.subject)===s.permissionContext.subject}this.subscriptions.handleError(s),this.muxSubscriptions.handleError(n,s),n&&this.subscriptions.setMux(null)}this.dispatchStatus(i),this.handleError(s)}handleError(e){e.isAuthError()?this.handleAuthError(e):e.isProtocolError()?this.lastError=e:e.isAuthTimeout()&&(this.lastError=e),e.isPermissionError()||(this.lastError=e)}handleAuthError(e){this.lastError&&e.code===this.lastError.code&&this.options.ignoreAuthErrorAbort===!1&&(this.abortReconnect=!0),this.connectError?this.connectError(e):this.disconnect()}processPing(){this.transport.send(Rn)}processPong(){const e=this.pongs.shift();e&&e.resolve()}processInfo(e){const t=JSON.parse(rr(e));this.info=t;const s=this.options&&this.options.ignoreClusterUpdates?void 0:this.servers.update(t,this.transport.isEncrypted());if(!this.infoReceived){this.features.update(Ke(t.version)),this.infoReceived=!0,this.transport.isEncrypted()&&this.servers.updateTLSName();const{version:n,lang:o}=this.transport;try{const a=new Nn({version:n,lang:o},this.options,t.nonce);t.headers&&(a.headers=!0,a.no_responders=!0);const d=JSON.stringify(a);this.transport.send(ft(`CONNECT ${d}${Ft}`)),this.transport.send(Nr)}catch(a){this._close(a)}}s&&this.dispatchStatus({type:Se.Update,data:s}),(t.ldm!==void 0?t.ldm:!1)&&this.dispatchStatus({type:Se.LDM,data:this.servers.getCurrentServer().toString()})}push(e){switch(e.kind){case de.MSG:{const{msg:t,data:s}=e;this.processMsg(t,s);break}case de.OK:break;case de.ERR:this.processError(e.data);break;case de.PING:this.processPing();break;case de.PONG:this.processPong();break;case de.INFO:this.processInfo(e.data);break}}sendCommand(e,...t){const s=this.outbound.length();let i;typeof e=="string"?i=ft(e):i=e,this.outbound.fill(i,...t),s===0?queueMicrotask(()=>{this.flushPending()}):this.outbound.size()>=this.pendingLimit&&this.flushPending()}publish(e,t=be,s){let i;if(t instanceof Uint8Array)i=t;else if(typeof t=="string")i=Ge.encode(t);else throw N.errorForCode(k.BadPayload);let n=i.length;s=s||{},s.reply=s.reply||"";let o=be,a=0;if(s.headers){if(this.info&&!this.info.headers)throw new N("headers",k.ServerOptionNotAvailable);o=s.headers.encode(),a=o.length,n=i.length+a}if(this.info&&n>this.info.max_payload)throw N.errorForCode(k.MaxPayloadExceeded);this.outBytes+=n,this.outMsgs++;let d;s.headers?(s.reply?d=`HPUB ${e} ${s.reply} ${a} ${n}\r
16
16
  `:d=`HPUB ${e} ${a} ${n}\r
@@ -36,4 +36,4 @@ Path:ssml\r
36
36
  Content-Type:application/json; charset=utf-8\r
37
37
  Path:speech.config\r
38
38
  \r
39
- {"context":{"synthesis":{"audio":{"metadataoptions":{"sentenceBoundaryEnabled":false,"wordBoundaryEnabled":true},"outputFormat":"audio-24khz-48kbitrate-mono-mp3"}}}}`,Eo=(r,e,t={})=>{var o;t.pitch=(o=t.pitch)==null?void 0:o.replace("hz","Hz");const s=t.pitch||"0Hz",i=t.rate||"0%",n=t.volume||"0%";return`<speak version='1.0' xml:lang='en-US'><voice name='${e}'><prosody pitch='${s}' rate='${i}' volume='${n}'>${r}</prosody></voice></speak>`};function Ao(r,e){for(let t=0;t<=r.length-e.length;t++){let s=!0;for(let i=0;i<e.length;i++)if(r[t+i]!==e[i]){s=!1;break}if(s)return t}return-1}class Po{constructor(e){this.config=e}async getAudioBuffer(e,t){const s=await fetch(`${this.config.voicevoxUrl}/audio_query?text=${encodeURIComponent(e)}&speaker=${t||3}`,{method:"POST",headers:{Accept:"application/json"}});if(!s.ok)throw new Error(`Audio query failed: ${s.statusText}`);const i=await s.json(),n=await fetch(`${this.config.voicevoxUrl}/synthesis?speaker=${t}`,{method:"POST",headers:{Accept:"audio/wav","Content-Type":"application/json"},body:JSON.stringify(i)});if(!n.body)return null;const o=n.body.getReader(),a=[];for(;;){const{done:y,value:x}=await o.read();if(y)break;a.push(x)}const d=a.reduce((y,x)=>y+x.length,0),p=new Uint8Array(d);let _=0;for(const y of a)p.set(y,_),_+=y.length;return p.buffer}async getAudio(e,t){return this.getAudioBuffer(e,t).then(s=>s?Gr(s):null)}async getVoices(){return(await fetch(`${this.config.voicevoxUrl}/speakers`).then(t=>t.json())).flatMap(t=>t.styles.map(s=>({id:s.id.toString(),locale:"ja-JP",description:`${t.name} - ${s.name}`})))}}const Kr={debug:!1,authUrl:"https://auth.jok.io",natsUrl:"https://natsx.jok.io",storage:new zr},Vr=new er(Kr),ko={setup(r){(r.authUrl||r.storage)&&(this.auth=new er({authUrl:r.authUrl??this.auth.url,storage:r.storage??this.storage})),(r.natsUrl||r.storage)&&(this.nats=new Ls({natsUrl:r.natsUrl??this.nats.url,auth:this.auth}))},auth:Vr,storage:new zr,tts:new So,nats:new Ls({...Kr,auth:Vr}),crypto:new yi};me.NatsService=Ls,me.VoicevoxTtsService=Po,me.jok=ko,Object.defineProperty(me,Symbol.toStringTag,{value:"Module"})});
39
+ {"context":{"synthesis":{"audio":{"metadataoptions":{"sentenceBoundaryEnabled":false,"wordBoundaryEnabled":true},"outputFormat":"audio-24khz-48kbitrate-mono-mp3"}}}}`,Eo=(r,e,t={})=>{var o;t.pitch=(o=t.pitch)==null?void 0:o.replace("hz","Hz");const s=t.pitch||"0Hz",i=t.rate||"0%",n=t.volume||"0%";return`<speak version='1.0' xml:lang='en-US'><voice name='${e}'><prosody pitch='${s}' rate='${i}' volume='${n}'>${r}</prosody></voice></speak>`};function Ao(r,e){for(let t=0;t<=r.length-e.length;t++){let s=!0;for(let i=0;i<e.length;i++)if(r[t+i]!==e[i]){s=!1;break}if(s)return t}return-1}class Po{constructor(e){this.config=e}async getAudioBuffer(e,t){const s=await fetch(`${this.config.voicevoxUrl}/audio_query?text=${encodeURIComponent(e)}&speaker=${t||3}`,{method:"POST",headers:{Accept:"application/json"}});if(!s.ok)throw new Error(`Audio query failed: ${s.statusText}`);const i=await s.json(),n=await fetch(`${this.config.voicevoxUrl}/synthesis?speaker=${t}`,{method:"POST",headers:{Accept:"audio/wav","Content-Type":"application/json"},body:JSON.stringify(i)});if(!n.body)return null;const o=n.body.getReader(),a=[];for(;;){const{done:y,value:x}=await o.read();if(y)break;a.push(x)}const d=a.reduce((y,x)=>y+x.length,0),p=new Uint8Array(d);let _=0;for(const y of a)p.set(y,_),_+=y.length;return p.buffer}async getAudio(e,t){return this.getAudioBuffer(e,t).then(s=>s?Gr(s):null)}async getVoices(){return(await fetch(`${this.config.voicevoxUrl}/speakers`).then(t=>t.json())).flatMap(t=>t.styles.map(s=>({id:s.id.toString(),locale:"ja-JP",description:`${t.name} - ${s.name}`})))}}const Kr={debug:!1,authUrl:"https://auth.jok.io",natsUrl:"https://nats.jok.io",storage:new zr},Vr=new er(Kr),ko={setup(r){(r.authUrl||r.storage)&&(this.auth=new er({authUrl:r.authUrl??this.auth.url,storage:r.storage??this.storage})),(r.natsUrl||r.storage)&&(this.nats=new Ls({natsUrl:r.natsUrl??this.nats.url,auth:this.auth}))},auth:Vr,storage:new zr,tts:new So,nats:new Ls({...Kr,auth:Vr}),crypto:new yi};me.NatsService=Ls,me.VoicevoxTtsService=Po,me.jok=ko,Object.defineProperty(me,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jokio/sdk",
3
3
  "description": "pure js/ts sdk for building decentralised localfirst web apps. Provides tts ai model integrations, realtime p2p communication & crypto encryptions.",
4
- "version": "0.2.2",
4
+ "version": "0.2.4",
5
5
  "license": "MIT",
6
6
  "main": "dist/jokio.sdk.umd.js",
7
7
  "module": "dist/jokio.sdk.es.js",