@aikaara/chat-sdk 0.8.2 → 0.8.3
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.
- package/dist/MountTenant-BCjKRkD8.cjs +978 -0
- package/dist/MountTenant-CxO7hJgs.mjs +14978 -0
- package/dist/cdn/aikaara-chat.iife.js +62 -62
- package/dist/headless.cjs +1 -1
- package/dist/headless.d.ts +316 -4
- package/dist/headless.mjs +19 -16
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +316 -4
- package/dist/index.mjs +29 -26
- package/dist/ui.cjs +1 -1
- package/dist/ui.mjs +1 -1
- package/package.json +1 -1
- package/dist/MountTenant-DvmiAoZ_.cjs +0 -978
- package/dist/MountTenant-DzNgBTiU.mjs +0 -14736
|
@@ -1,978 +0,0 @@
|
|
|
1
|
-
"use strict";class Ao{identifier;callbacks={};sendFn;constructor(e,t){this.identifier=e,this.sendFn=t}onReceived(e){return this.callbacks.received=e,this}onConnected(e){return this.callbacks.connected=e,this}onDisconnected(e){return this.callbacks.disconnected=e,this}onRejected(e){return this.callbacks.rejected=e,this}perform(e,t={}){this.sendFn({action:e,...t})}_notifyReceived(e){this.callbacks.received?.(e)}_notifyConnected(){this.callbacks.connected?.()}_notifyDisconnected(){this.callbacks.disconnected?.()}_notifyRejected(){this.callbacks.rejected?.()}}class Kr{ws=null;url;subscriptions=new Map;welcomePromise=null;pendingSubscriptions=new Map;constructor(e){this.url=e}connect(){return new Promise((e,t)=>{this.welcomePromise={resolve:e,reject:t},this.ws=new WebSocket(this.url),this.ws.onopen=()=>{},this.ws.onmessage=n=>{this.handleMessage(n)},this.ws.onerror=()=>{const n=new Error("WebSocket connection error");this.welcomePromise?.reject(n),this.welcomePromise=null},this.ws.onclose=()=>{this.subscriptions.forEach(n=>n._notifyDisconnected())}})}disconnect(){this.ws&&(this.ws.onclose=null,this.ws.close(),this.ws=null),this.subscriptions.forEach(e=>e._notifyDisconnected()),this.subscriptions.clear()}subscribe(e){const t=JSON.stringify(e),n=new Ao(t,l=>{this.send({command:"message",identifier:t,data:JSON.stringify(l)})});return this.subscriptions.set(t,n),this.send({command:"subscribe",identifier:t}),n}subscribeAsync(e){const t=this.subscribe(e),n=t.identifier;return new Promise((l,r)=>{this.pendingSubscriptions.set(n,{resolve:()=>l(t),reject:r}),setTimeout(()=>{this.pendingSubscriptions.has(n)&&(this.pendingSubscriptions.delete(n),r(new Error(`Subscription timeout for ${n}`)))},1e4)})}unsubscribe(e){this.send({command:"unsubscribe",identifier:e}),this.subscriptions.delete(e)}perform(e,t,n={}){this.send({command:"message",identifier:e,data:JSON.stringify({action:t,...n})})}get isConnected(){return this.ws?.readyState===WebSocket.OPEN}send(e){this.ws?.readyState===WebSocket.OPEN&&this.ws.send(JSON.stringify(e))}handleMessage(e){let t;try{t=JSON.parse(e.data)}catch{return}switch(t.type){case"welcome":this.welcomePromise?.resolve(),this.welcomePromise=null;break;case"ping":break;case"confirm_subscription":{const n=t.identifier;this.subscriptions.get(n)?._notifyConnected();const r=this.pendingSubscriptions.get(n);r&&(r.resolve(),this.pendingSubscriptions.delete(n));break}case"reject_subscription":{const n=t.identifier;this.subscriptions.get(n)?._notifyRejected(),this.subscriptions.delete(n);const r=this.pendingSubscriptions.get(n);r&&(r.reject(new Error(`Subscription rejected: ${n}`)),this.pendingSubscriptions.delete(n));break}case"disconnect":this.subscriptions.forEach(n=>n._notifyDisconnected());break;default:{t.identifier&&t.message!==void 0&&this.subscriptions.get(t.identifier)?._notifyReceived(t.message);break}}}}class Ki{handlers=new Map;on(e,t){return this.handlers.has(e)||this.handlers.set(e,new Set),this.handlers.get(e).add(t),()=>this.off(e,t)}off(e,t){this.handlers.get(e)?.delete(t)}emit(e,t){this.handlers.get(e)?.forEach(n=>{try{n(t)}catch(l){console.error(`Error in event handler for "${e}":`,l)}})}removeAllListeners(){this.handlers.clear()}}const $l=1e3,Wl=10,ql=400,Hl=600,cs="#6366f1",zl=12,Kl="system-ui, -apple-system, sans-serif",hs="Type a message...",Vl="bottom-right",Gl="light",Yl={x:20,y:20},Ur="aikaara_conversation_id";class Io extends Ki{client;config;state="disconnected";reconnectAttempt=0;reconnectTimer=null;constructor(e){super(),this.config=e;const t=this.buildWsUrl(e.baseUrl,e.userToken);this.client=new Kr(t)}async connect(){this.setState("connecting");try{await this.client.connect(),this.setState("connected"),this.reconnectAttempt=0}catch(e){if(this.setState("disconnected"),this.config.reconnect!==!1)this.scheduleReconnect();else throw e}}async disconnect(){this.clearReconnectTimer(),this.client.disconnect(),this.setState("disconnected")}subscribeToConversation(e){return this.client.subscribeAsync({channel:"ConversationChannel",conversation_id:e})}sendMessage(e,t){const n=JSON.stringify({channel:"ConversationChannel",conversation_id:e});this.client.perform(n,"send_message",{content:t})}sendUserEvent(e,t,n,l){const r=JSON.stringify({channel:"ConversationChannel",conversation_id:e});this.client.perform(r,"send_user_event",{event_key:t,...n&&{value:n},...l&&{source:l}})}get connectionState(){return this.state}setState(e){this.state!==e&&(this.state=e,this.emit("connection:state",e))}scheduleReconnect(){const e=this.config.maxReconnectAttempts??Wl;if(this.reconnectAttempt>=e){this.emit("error",new Error("Max reconnection attempts reached"));return}this.setState("reconnecting");const n=(this.config.reconnectInterval??$l)*Math.pow(2,this.reconnectAttempt);this.reconnectAttempt++,this.reconnectTimer=setTimeout(async()=>{try{const l=this.buildWsUrl(this.config.baseUrl,this.config.userToken);this.client=new Kr(l),await this.connect()}catch{}},n)}clearReconnectTimer(){this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null)}buildWsUrl(e,t){if(this.config.wsUrl){const l=this.config.wsUrl.includes("?")?"&":"?";return`${this.config.wsUrl}${l}token=${t}`}return`${e.replace(/^http/,"ws")}/cable?token=${t}`}}class To{baseUrl;apiKey;authToken;userToken;constructor(e,t,n,l){this.baseUrl=e,this.userToken=t,this.apiKey=n,this.authToken=l}async createConversation(e){const t={conversation:{...e.extUid&&{ext_uid:e.extUid},...e.systemPromptId&&{system_prompt_id:e.systemPromptId},...e.channel&&{channel:e.channel},...e.title&&{title:e.title}}};return this.request("POST","/api/v1/conversations",t)}async updateContext(e,t){const n=this.authToken?`/dashboard/sidekick_conversations/${e}`:`/api/v1/conversations/${e}`;await this.request("PATCH",n,t)}async getMessages(e){return(await this.request("GET",`/api/v1/conversations/${e}/messages`)).map(this.mapMessage)}mapMessage(e){return{id:String(e.id),conversationId:String(e.conversation_id),role:e.role,content:e.content||"",toolCalls:e.tool_calls?.map(t=>({id:t.id,type:t.type,function:t.function})),toolCallResults:e.tool_call_results,tokensInput:e.tokens_input,tokensOutput:e.tokens_output,metadata:e.metadata,createdAt:e.created_at,status:"complete"}}async request(e,t,n){const l={"Content-Type":"application/json",Accept:"application/json"};this.apiKey&&(l["X-Api-Key"]=this.apiKey),this.authToken&&(l.Authorization=`Bearer ${this.authToken}`);const r=`${this.baseUrl}${t}`,i={method:e,headers:l};n&&(i.body=JSON.stringify(n));const o=await fetch(r,i);if(!o.ok){const a=await o.text();let c;try{const d=JSON.parse(a);c=d.error||d.message||a}catch{c=a}throw new Error(`API error ${o.status}: ${c}`)}const s=await o.json();if(s&&typeof s=="object"&&"success"in s){if(!s.success)throw new Error(`API error: ${s.message||"Request failed"}`);return s.data}return s}}class Co{_messages=[];optimisticCounter=0;get messages(){return[...this._messages]}addOptimistic(e,t,n){const l={id:`optimistic_${++this.optimisticCounter}`,conversationId:n,role:e,content:t,createdAt:new Date().toISOString(),status:"sending"};return this._messages.push(l),l}reconcileOptimistic(e,t=3e4){const n=this._messages.findLast(l=>l.status==="sending"&&l.role===e.role&&l.content===e.content&&l.conversationId===e.conversationId&&Date.now()-new Date(l.createdAt).getTime()<t);return n?(n.status=e.status??"sent",n.externalId=e.externalId??e.id,e.template&&(n.template=e.template),e.attachments&&(n.attachments=e.attachments),e.metadata&&(n.metadata={...n.metadata??{},...e.metadata}),n):null}upsertRemoteMessage(e){const t=this.reconcileOptimistic(e);if(t)return{message:t,deduped:!0};const n=e.externalId?this._messages.find(l=>l.externalId&&l.externalId===e.externalId):void 0;return n?(Object.assign(n,e,{id:n.id}),{message:n,deduped:!0}):(this._messages.push(e),{message:e,deduped:!1})}updateMessageStatus(e,t){const n=this._messages.find(l=>l.externalId===e||l.id===e);return n&&(n.status=t),n}confirmOptimistic(e){const t=this._messages.find(n=>n.id===e);t&&(t.status="sent")}addStreamingMessage(e){const t={id:`streaming_${Date.now()}`,conversationId:e,role:"assistant",content:"",createdAt:new Date().toISOString(),status:"streaming"};return this._messages.push(t),t}updateStreaming(e){const t=this._messages.findLast(n=>n.status==="streaming");t&&(t.content=e)}appendToStreaming(e){const t=this._messages.findLast(n=>n.status==="streaming");t&&(t.content+=e)}get streamingContent(){return this._messages.findLast(t=>t.status==="streaming")?.content||""}finalizeStreaming(e){const t=this._messages.findLast(n=>n.status==="streaming");return t&&(t.status="complete",e&&(t.tokensInput=e.tokensInput,t.tokensOutput=e.tokensOutput)),t}addMessage(e){this._messages.push(e)}setMessages(e){this._messages=[...e]}clear(){this._messages=[]}}class Oo{_conversationId;persist;constructor(e,t=!0){this.persist=t,this._conversationId=e||this.loadFromStorage()}get conversationId(){return this._conversationId}set conversationId(e){this._conversationId=e,this.persist&&e&&this.saveToStorage(e)}clear(){if(this._conversationId=null,this.persist)try{localStorage.removeItem(Ur)}catch{}}loadFromStorage(){if(!this.persist)return null;try{return localStorage.getItem(Ur)}catch{return null}}saveToStorage(e){try{localStorage.setItem(Ur,e)}catch{}}}var Vi=Object.defineProperty,Ql=Object.getOwnPropertyDescriptor,Jl=Object.getOwnPropertyNames,Xl=Object.prototype.hasOwnProperty,He=(u,e)=>()=>(u&&(e=u(u=0)),e),pe=(u,e)=>()=>(e||u((e={exports:{}}).exports,e),e.exports),jt=(u,e)=>{for(var t in e)Vi(u,t,{get:e[t],enumerable:!0})},Zl=(u,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of Jl(e))!Xl.call(u,l)&&l!==t&&Vi(u,l,{get:()=>e[l],enumerable:!(n=Ql(e,l))||n.enumerable});return u},Oe=u=>Zl(Vi({},"__esModule",{value:!0}),u),le=He(()=>{}),Pe={};jt(Pe,{_debugEnd:()=>In,_debugProcess:()=>An,_events:()=>Wn,_eventsCount:()=>qn,_exiting:()=>fn,_fatalExceptions:()=>kn,_getActiveHandles:()=>Uo,_getActiveRequests:()=>No,_kill:()=>gn,_linkedBinding:()=>jo,_maxListeners:()=>$n,_preload_modules:()=>Fn,_rawDebug:()=>un,_startProfilerIdleNotifier:()=>Tn,_stopProfilerIdleNotifier:()=>Cn,_tickCallback:()=>xn,abort:()=>Rn,addListener:()=>Hn,allowedNodeEnvironmentFlags:()=>_n,arch:()=>Gr,argv:()=>Jr,argv0:()=>Bn,assert:()=>Bo,binding:()=>rn,browser:()=>ln,chdir:()=>on,config:()=>dn,cpuUsage:()=>Wt,cwd:()=>sn,debugPort:()=>Un,default:()=>Yi,dlopen:()=>Lo,domain:()=>hn,emit:()=>Yn,emitWarning:()=>tn,env:()=>Qr,execArgv:()=>Xr,execPath:()=>Nn,exit:()=>vn,features:()=>Sn,hasUncaughtExceptionCaptureCallback:()=>Fo,hrtime:()=>nr,kill:()=>yn,listeners:()=>$o,memoryUsage:()=>bn,moduleLoadList:()=>cn,nextTick:()=>Mo,off:()=>Kn,on:()=>rt,once:()=>zn,openStdin:()=>wn,pid:()=>jn,platform:()=>Yr,ppid:()=>Ln,prependListener:()=>Qn,prependOnceListener:()=>Jn,reallyExit:()=>pn,release:()=>an,removeAllListeners:()=>Gn,removeListener:()=>Vn,resourceUsage:()=>mn,setSourceMapsEnabled:()=>Dn,setUncaughtExceptionCaptureCallback:()=>En,stderr:()=>Pn,stdin:()=>Mn,stdout:()=>On,title:()=>Vr,umask:()=>nn,uptime:()=>Do,version:()=>Zr,versions:()=>en});function Gi(u){throw new Error("Node.js process "+u+" is not supported by JSPM core outside of Node.js")}function eu(){!St||!wt||(St=!1,wt.length?Ze=wt.concat(Ze):Kt=-1,Ze.length&&Po())}function Po(){if(!St){var u=setTimeout(eu,0);St=!0;for(var e=Ze.length;e;){for(wt=Ze,Ze=[];++Kt<e;)wt&&wt[Kt].run();Kt=-1,e=Ze.length}wt=null,St=!1,clearTimeout(u)}}function Mo(u){var e=new Array(arguments.length-1);if(arguments.length>1)for(var t=1;t<arguments.length;t++)e[t-1]=arguments[t];Ze.push(new Ro(u,e)),Ze.length===1&&!St&&setTimeout(Po,0)}function Ro(u,e){this.fun=u,this.array=e}function Be(){}function jo(u){Gi("_linkedBinding")}function Lo(u){Gi("dlopen")}function No(){return[]}function Uo(){return[]}function Bo(u,e){if(!u)throw new Error(e||"assertion error")}function Fo(){return!1}function Do(){return it.now()/1e3}function nr(u){var e=Math.floor((Date.now()-it.now())*.001),t=it.now()*.001,n=Math.floor(t)+e,l=Math.floor(t%1*1e9);return u&&(n=n-u[0],l=l-u[1],l<0&&(n--,l+=ir)),[n,l]}function rt(){return Yi}function $o(u){return[]}var Ze,St,wt,Kt,Vr,Gr,Yr,Qr,Jr,Xr,Zr,en,tn,rn,nn,sn,on,an,ln,un,cn,hn,fn,dn,pn,gn,Wt,mn,bn,yn,vn,wn,_n,Sn,kn,En,xn,An,In,Tn,Cn,On,Pn,Mn,Rn,jn,Ln,Nn,Un,Bn,Fn,Dn,it,Br,ir,$n,Wn,qn,Hn,zn,Kn,Vn,Gn,Yn,Qn,Jn,Yi,tu=He(()=>{le(),ce(),ue(),Ze=[],St=!1,Kt=-1,Ro.prototype.run=function(){this.fun.apply(null,this.array)},Vr="browser",Gr="x64",Yr="browser",Qr={PATH:"/usr/bin",LANG:typeof navigator<"u"?navigator.language+".UTF-8":void 0,PWD:"/",HOME:"/home",TMP:"/tmp"},Jr=["/usr/bin/node"],Xr=[],Zr="v16.8.0",en={},tn=function(u,e){console.warn((e?e+": ":"")+u)},rn=function(u){Gi("binding")},nn=function(u){return 0},sn=function(){return"/"},on=function(u){},an={name:"node",sourceUrl:"",headersUrl:"",libUrl:""},ln=!0,un=Be,cn=[],hn={},fn=!1,dn={},pn=Be,gn=Be,Wt=function(){return{}},mn=Wt,bn=Wt,yn=Be,vn=Be,wn=Be,_n={},Sn={inspector:!1,debug:!1,uv:!1,ipv6:!1,tls_alpn:!1,tls_sni:!1,tls_ocsp:!1,tls:!1,cached_builtins:!0},kn=Be,En=Be,xn=Be,An=Be,In=Be,Tn=Be,Cn=Be,On=void 0,Pn=void 0,Mn=void 0,Rn=Be,jn=2,Ln=1,Nn="/bin/usr/node",Un=9229,Bn="node",Fn=[],Dn=Be,it={now:typeof performance<"u"?performance.now.bind(performance):void 0,timing:typeof performance<"u"?performance.timing:void 0},it.now===void 0&&(Br=Date.now(),it.timing&&it.timing.navigationStart&&(Br=it.timing.navigationStart),it.now=()=>Date.now()-Br),ir=1e9,nr.bigint=function(u){var e=nr(u);return typeof BigInt>"u"?e[0]*ir+e[1]:BigInt(e[0]*ir)+BigInt(e[1])},$n=10,Wn={},qn=0,Hn=rt,zn=rt,Kn=rt,Vn=rt,Gn=rt,Yn=Be,Qn=rt,Jn=rt,Yi={version:Zr,versions:en,arch:Gr,platform:Yr,browser:ln,release:an,_rawDebug:un,moduleLoadList:cn,binding:rn,_linkedBinding:jo,_events:Wn,_eventsCount:qn,_maxListeners:$n,on:rt,addListener:Hn,once:zn,off:Kn,removeListener:Vn,removeAllListeners:Gn,emit:Yn,prependListener:Qn,prependOnceListener:Jn,listeners:$o,domain:hn,_exiting:fn,config:dn,dlopen:Lo,uptime:Do,_getActiveRequests:No,_getActiveHandles:Uo,reallyExit:pn,_kill:gn,cpuUsage:Wt,resourceUsage:mn,memoryUsage:bn,kill:yn,exit:vn,openStdin:wn,allowedNodeEnvironmentFlags:_n,assert:Bo,features:Sn,_fatalExceptions:kn,setUncaughtExceptionCaptureCallback:En,hasUncaughtExceptionCaptureCallback:Fo,emitWarning:tn,nextTick:Mo,_tickCallback:xn,_debugProcess:An,_debugEnd:In,_startProfilerIdleNotifier:Tn,_stopProfilerIdleNotifier:Cn,stdout:On,stdin:Mn,stderr:Pn,abort:Rn,umask:nn,chdir:on,cwd:sn,env:Qr,title:Vr,argv:Jr,execArgv:Xr,pid:jn,ppid:Ln,execPath:Nn,debugPort:Un,hrtime:nr,argv0:Bn,_preload_modules:Fn,setSourceMapsEnabled:Dn}}),ue=He(()=>{tu()});function ru(){if(Xn)return Ct;Xn=!0,Ct.byteLength=o,Ct.toByteArray=a,Ct.fromByteArray=p;for(var u=[],e=[],t=typeof Uint8Array<"u"?Uint8Array:Array,n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",l=0,r=n.length;l<r;++l)u[l]=n[l],e[n.charCodeAt(l)]=l;e[45]=62,e[95]=63;function i(y){var f=y.length;if(f%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var m=y.indexOf("=");m===-1&&(m=f);var b=m===f?0:4-m%4;return[m,b]}function o(y){var f=i(y),m=f[0],b=f[1];return(m+b)*3/4-b}function s(y,f,m){return(f+m)*3/4-m}function a(y){var f,m=i(y),b=m[0],_=m[1],g=new t(s(y,b,_)),S=0,x=_>0?b-4:b,v;for(v=0;v<x;v+=4)f=e[y.charCodeAt(v)]<<18|e[y.charCodeAt(v+1)]<<12|e[y.charCodeAt(v+2)]<<6|e[y.charCodeAt(v+3)],g[S++]=f>>16&255,g[S++]=f>>8&255,g[S++]=f&255;return _===2&&(f=e[y.charCodeAt(v)]<<2|e[y.charCodeAt(v+1)]>>4,g[S++]=f&255),_===1&&(f=e[y.charCodeAt(v)]<<10|e[y.charCodeAt(v+1)]<<4|e[y.charCodeAt(v+2)]>>2,g[S++]=f>>8&255,g[S++]=f&255),g}function c(y){return u[y>>18&63]+u[y>>12&63]+u[y>>6&63]+u[y&63]}function d(y,f,m){for(var b,_=[],g=f;g<m;g+=3)b=(y[g]<<16&16711680)+(y[g+1]<<8&65280)+(y[g+2]&255),_.push(c(b));return _.join("")}function p(y){for(var f,m=y.length,b=m%3,_=[],g=16383,S=0,x=m-b;S<x;S+=g)_.push(d(y,S,S+g>x?x:S+g));return b===1?(f=y[m-1],_.push(u[f>>2]+u[f<<4&63]+"==")):b===2&&(f=(y[m-2]<<8)+y[m-1],_.push(u[f>>10]+u[f>>4&63]+u[f<<2&63]+"=")),_.join("")}return Ct}function nu(){return Zn?qt:(Zn=!0,qt.read=function(u,e,t,n,l){var r,i,o=l*8-n-1,s=(1<<o)-1,a=s>>1,c=-7,d=t?l-1:0,p=t?-1:1,y=u[e+d];for(d+=p,r=y&(1<<-c)-1,y>>=-c,c+=o;c>0;r=r*256+u[e+d],d+=p,c-=8);for(i=r&(1<<-c)-1,r>>=-c,c+=n;c>0;i=i*256+u[e+d],d+=p,c-=8);if(r===0)r=1-a;else{if(r===s)return i?NaN:(y?-1:1)*(1/0);i=i+Math.pow(2,n),r=r-a}return(y?-1:1)*i*Math.pow(2,r-n)},qt.write=function(u,e,t,n,l,r){var i,o,s,a=r*8-l-1,c=(1<<a)-1,d=c>>1,p=l===23?Math.pow(2,-24)-Math.pow(2,-77):0,y=n?0:r-1,f=n?1:-1,m=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(o=isNaN(e)?1:0,i=c):(i=Math.floor(Math.log(e)/Math.LN2),e*(s=Math.pow(2,-i))<1&&(i--,s*=2),i+d>=1?e+=p/s:e+=p*Math.pow(2,1-d),e*s>=2&&(i++,s/=2),i+d>=c?(o=0,i=c):i+d>=1?(o=(e*s-1)*Math.pow(2,l),i=i+d):(o=e*Math.pow(2,d-1)*Math.pow(2,l),i=0));l>=8;u[t+y]=o&255,y+=f,o/=256,l-=8);for(i=i<<l|o,a+=l;a>0;u[t+y]=i&255,y+=f,i/=256,a-=8);u[t+y-f]|=m*128},qt)}function iu(){if(ei)return dt;ei=!0;let u=ru(),e=nu(),t=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;dt.Buffer=i,dt.SlowBuffer=_,dt.INSPECT_MAX_BYTES=50;let n=2147483647;dt.kMaxLength=n,i.TYPED_ARRAY_SUPPORT=l(),!i.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function l(){try{let h=new Uint8Array(1),w={foo:function(){return 42}};return Object.setPrototypeOf(w,Uint8Array.prototype),Object.setPrototypeOf(h,w),h.foo()===42}catch{return!1}}Object.defineProperty(i.prototype,"parent",{enumerable:!0,get:function(){if(i.isBuffer(this))return this.buffer}}),Object.defineProperty(i.prototype,"offset",{enumerable:!0,get:function(){if(i.isBuffer(this))return this.byteOffset}});function r(h){if(h>n)throw new RangeError('The value "'+h+'" is invalid for option "size"');let w=new Uint8Array(h);return Object.setPrototypeOf(w,i.prototype),w}function i(h,w,A){if(typeof h=="number"){if(typeof w=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return c(h)}return o(h,w,A)}i.poolSize=8192;function o(h,w,A){if(typeof h=="string")return d(h,w);if(ArrayBuffer.isView(h))return y(h);if(h==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof h);if(q(h,ArrayBuffer)||h&&q(h.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(q(h,SharedArrayBuffer)||h&&q(h.buffer,SharedArrayBuffer)))return f(h,w,A);if(typeof h=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let U=h.valueOf&&h.valueOf();if(U!=null&&U!==h)return i.from(U,w,A);let X=m(h);if(X)return X;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof h[Symbol.toPrimitive]=="function")return i.from(h[Symbol.toPrimitive]("string"),w,A);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof h)}i.from=function(h,w,A){return o(h,w,A)},Object.setPrototypeOf(i.prototype,Uint8Array.prototype),Object.setPrototypeOf(i,Uint8Array);function s(h){if(typeof h!="number")throw new TypeError('"size" argument must be of type number');if(h<0)throw new RangeError('The value "'+h+'" is invalid for option "size"')}function a(h,w,A){return s(h),h<=0?r(h):w!==void 0?typeof A=="string"?r(h).fill(w,A):r(h).fill(w):r(h)}i.alloc=function(h,w,A){return a(h,w,A)};function c(h){return s(h),r(h<0?0:b(h)|0)}i.allocUnsafe=function(h){return c(h)},i.allocUnsafeSlow=function(h){return c(h)};function d(h,w){if((typeof w!="string"||w==="")&&(w="utf8"),!i.isEncoding(w))throw new TypeError("Unknown encoding: "+w);let A=g(h,w)|0,U=r(A),X=U.write(h,w);return X!==A&&(U=U.slice(0,X)),U}function p(h){let w=h.length<0?0:b(h.length)|0,A=r(w);for(let U=0;U<w;U+=1)A[U]=h[U]&255;return A}function y(h){if(q(h,Uint8Array)){let w=new Uint8Array(h);return f(w.buffer,w.byteOffset,w.byteLength)}return p(h)}function f(h,w,A){if(w<0||h.byteLength<w)throw new RangeError('"offset" is outside of buffer bounds');if(h.byteLength<w+(A||0))throw new RangeError('"length" is outside of buffer bounds');let U;return w===void 0&&A===void 0?U=new Uint8Array(h):A===void 0?U=new Uint8Array(h,w):U=new Uint8Array(h,w,A),Object.setPrototypeOf(U,i.prototype),U}function m(h){if(i.isBuffer(h)){let w=b(h.length)|0,A=r(w);return A.length===0||h.copy(A,0,0,w),A}if(h.length!==void 0)return typeof h.length!="number"||ge(h.length)?r(0):p(h);if(h.type==="Buffer"&&Array.isArray(h.data))return p(h.data)}function b(h){if(h>=n)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+n.toString(16)+" bytes");return h|0}function _(h){return+h!=h&&(h=0),i.alloc(+h)}i.isBuffer=function(h){return h!=null&&h._isBuffer===!0&&h!==i.prototype},i.compare=function(h,w){if(q(h,Uint8Array)&&(h=i.from(h,h.offset,h.byteLength)),q(w,Uint8Array)&&(w=i.from(w,w.offset,w.byteLength)),!i.isBuffer(h)||!i.isBuffer(w))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(h===w)return 0;let A=h.length,U=w.length;for(let X=0,he=Math.min(A,U);X<he;++X)if(h[X]!==w[X]){A=h[X],U=w[X];break}return A<U?-1:U<A?1:0},i.isEncoding=function(h){switch(String(h).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},i.concat=function(h,w){if(!Array.isArray(h))throw new TypeError('"list" argument must be an Array of Buffers');if(h.length===0)return i.alloc(0);let A;if(w===void 0)for(w=0,A=0;A<h.length;++A)w+=h[A].length;let U=i.allocUnsafe(w),X=0;for(A=0;A<h.length;++A){let he=h[A];if(q(he,Uint8Array))X+he.length>U.length?(i.isBuffer(he)||(he=i.from(he)),he.copy(U,X)):Uint8Array.prototype.set.call(U,he,X);else if(i.isBuffer(he))he.copy(U,X);else throw new TypeError('"list" argument must be an Array of Buffers');X+=he.length}return U};function g(h,w){if(i.isBuffer(h))return h.length;if(ArrayBuffer.isView(h)||q(h,ArrayBuffer))return h.byteLength;if(typeof h!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof h);let A=h.length,U=arguments.length>2&&arguments[2]===!0;if(!U&&A===0)return 0;let X=!1;for(;;)switch(w){case"ascii":case"latin1":case"binary":return A;case"utf8":case"utf-8":return $(h).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A*2;case"hex":return A>>>1;case"base64":return de(h).length;default:if(X)return U?-1:$(h).length;w=(""+w).toLowerCase(),X=!0}}i.byteLength=g;function S(h,w,A){let U=!1;if((w===void 0||w<0)&&(w=0),w>this.length||((A===void 0||A>this.length)&&(A=this.length),A<=0)||(A>>>=0,w>>>=0,A<=w))return"";for(h||(h="utf8");;)switch(h){case"hex":return K(this,w,A);case"utf8":case"utf-8":return W(this,w,A);case"ascii":return ae(this,w,A);case"latin1":case"binary":return Y(this,w,A);case"base64":return T(this,w,A);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return re(this,w,A);default:if(U)throw new TypeError("Unknown encoding: "+h);h=(h+"").toLowerCase(),U=!0}}i.prototype._isBuffer=!0;function x(h,w,A){let U=h[w];h[w]=h[A],h[A]=U}i.prototype.swap16=function(){let h=this.length;if(h%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let w=0;w<h;w+=2)x(this,w,w+1);return this},i.prototype.swap32=function(){let h=this.length;if(h%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let w=0;w<h;w+=4)x(this,w,w+3),x(this,w+1,w+2);return this},i.prototype.swap64=function(){let h=this.length;if(h%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let w=0;w<h;w+=8)x(this,w,w+7),x(this,w+1,w+6),x(this,w+2,w+5),x(this,w+3,w+4);return this},i.prototype.toString=function(){let h=this.length;return h===0?"":arguments.length===0?W(this,0,h):S.apply(this,arguments)},i.prototype.toLocaleString=i.prototype.toString,i.prototype.equals=function(h){if(!i.isBuffer(h))throw new TypeError("Argument must be a Buffer");return this===h?!0:i.compare(this,h)===0},i.prototype.inspect=function(){let h="",w=dt.INSPECT_MAX_BYTES;return h=this.toString("hex",0,w).replace(/(.{2})/g,"$1 ").trim(),this.length>w&&(h+=" ... "),"<Buffer "+h+">"},t&&(i.prototype[t]=i.prototype.inspect),i.prototype.compare=function(h,w,A,U,X){if(q(h,Uint8Array)&&(h=i.from(h,h.offset,h.byteLength)),!i.isBuffer(h))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof h);if(w===void 0&&(w=0),A===void 0&&(A=h?h.length:0),U===void 0&&(U=0),X===void 0&&(X=this.length),w<0||A>h.length||U<0||X>this.length)throw new RangeError("out of range index");if(U>=X&&w>=A)return 0;if(U>=X)return-1;if(w>=A)return 1;if(w>>>=0,A>>>=0,U>>>=0,X>>>=0,this===h)return 0;let he=X-U,Se=A-w,z=Math.min(he,Se),ie=this.slice(U,X),xe=h.slice(w,A);for(let Ae=0;Ae<z;++Ae)if(ie[Ae]!==xe[Ae]){he=ie[Ae],Se=xe[Ae];break}return he<Se?-1:Se<he?1:0};function v(h,w,A,U,X){if(h.length===0)return-1;if(typeof A=="string"?(U=A,A=0):A>2147483647?A=2147483647:A<-2147483648&&(A=-2147483648),A=+A,ge(A)&&(A=X?0:h.length-1),A<0&&(A=h.length+A),A>=h.length){if(X)return-1;A=h.length-1}else if(A<0)if(X)A=0;else return-1;if(typeof w=="string"&&(w=i.from(w,U)),i.isBuffer(w))return w.length===0?-1:E(h,w,A,U,X);if(typeof w=="number")return w=w&255,typeof Uint8Array.prototype.indexOf=="function"?X?Uint8Array.prototype.indexOf.call(h,w,A):Uint8Array.prototype.lastIndexOf.call(h,w,A):E(h,[w],A,U,X);throw new TypeError("val must be string, number or Buffer")}function E(h,w,A,U,X){let he=1,Se=h.length,z=w.length;if(U!==void 0&&(U=String(U).toLowerCase(),U==="ucs2"||U==="ucs-2"||U==="utf16le"||U==="utf-16le")){if(h.length<2||w.length<2)return-1;he=2,Se/=2,z/=2,A/=2}function ie(Ae,Ie){return he===1?Ae[Ie]:Ae.readUInt16BE(Ie*he)}let xe;if(X){let Ae=-1;for(xe=A;xe<Se;xe++)if(ie(h,xe)===ie(w,Ae===-1?0:xe-Ae)){if(Ae===-1&&(Ae=xe),xe-Ae+1===z)return Ae*he}else Ae!==-1&&(xe-=xe-Ae),Ae=-1}else for(A+z>Se&&(A=Se-z),xe=A;xe>=0;xe--){let Ae=!0;for(let Ie=0;Ie<z;Ie++)if(ie(h,xe+Ie)!==ie(w,Ie)){Ae=!1;break}if(Ae)return xe}return-1}i.prototype.includes=function(h,w,A){return this.indexOf(h,w,A)!==-1},i.prototype.indexOf=function(h,w,A){return v(this,h,w,A,!0)},i.prototype.lastIndexOf=function(h,w,A){return v(this,h,w,A,!1)};function k(h,w,A,U){A=Number(A)||0;let X=h.length-A;U?(U=Number(U),U>X&&(U=X)):U=X;let he=w.length;U>he/2&&(U=he/2);let Se;for(Se=0;Se<U;++Se){let z=parseInt(w.substr(Se*2,2),16);if(ge(z))return Se;h[A+Se]=z}return Se}function I(h,w,A,U){return ye($(w,h.length-A),h,A,U)}function M(h,w,A,U){return ye(ee(w),h,A,U)}function O(h,w,A,U){return ye(de(w),h,A,U)}function B(h,w,A,U){return ye(fe(w,h.length-A),h,A,U)}i.prototype.write=function(h,w,A,U){if(w===void 0)U="utf8",A=this.length,w=0;else if(A===void 0&&typeof w=="string")U=w,A=this.length,w=0;else if(isFinite(w))w=w>>>0,isFinite(A)?(A=A>>>0,U===void 0&&(U="utf8")):(U=A,A=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let X=this.length-w;if((A===void 0||A>X)&&(A=X),h.length>0&&(A<0||w<0)||w>this.length)throw new RangeError("Attempt to write outside buffer bounds");U||(U="utf8");let he=!1;for(;;)switch(U){case"hex":return k(this,h,w,A);case"utf8":case"utf-8":return I(this,h,w,A);case"ascii":case"latin1":case"binary":return M(this,h,w,A);case"base64":return O(this,h,w,A);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,h,w,A);default:if(he)throw new TypeError("Unknown encoding: "+U);U=(""+U).toLowerCase(),he=!0}},i.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function T(h,w,A){return w===0&&A===h.length?u.fromByteArray(h):u.fromByteArray(h.slice(w,A))}function W(h,w,A){A=Math.min(h.length,A);let U=[],X=w;for(;X<A;){let he=h[X],Se=null,z=he>239?4:he>223?3:he>191?2:1;if(X+z<=A){let ie,xe,Ae,Ie;switch(z){case 1:he<128&&(Se=he);break;case 2:ie=h[X+1],(ie&192)===128&&(Ie=(he&31)<<6|ie&63,Ie>127&&(Se=Ie));break;case 3:ie=h[X+1],xe=h[X+2],(ie&192)===128&&(xe&192)===128&&(Ie=(he&15)<<12|(ie&63)<<6|xe&63,Ie>2047&&(Ie<55296||Ie>57343)&&(Se=Ie));break;case 4:ie=h[X+1],xe=h[X+2],Ae=h[X+3],(ie&192)===128&&(xe&192)===128&&(Ae&192)===128&&(Ie=(he&15)<<18|(ie&63)<<12|(xe&63)<<6|Ae&63,Ie>65535&&Ie<1114112&&(Se=Ie))}}Se===null?(Se=65533,z=1):Se>65535&&(Se-=65536,U.push(Se>>>10&1023|55296),Se=56320|Se&1023),U.push(Se),X+=z}return N(U)}let F=4096;function N(h){let w=h.length;if(w<=F)return String.fromCharCode.apply(String,h);let A="",U=0;for(;U<w;)A+=String.fromCharCode.apply(String,h.slice(U,U+=F));return A}function ae(h,w,A){let U="";A=Math.min(h.length,A);for(let X=w;X<A;++X)U+=String.fromCharCode(h[X]&127);return U}function Y(h,w,A){let U="";A=Math.min(h.length,A);for(let X=w;X<A;++X)U+=String.fromCharCode(h[X]);return U}function K(h,w,A){let U=h.length;(!w||w<0)&&(w=0),(!A||A<0||A>U)&&(A=U);let X="";for(let he=w;he<A;++he)X+=ve[h[he]];return X}function re(h,w,A){let U=h.slice(w,A),X="";for(let he=0;he<U.length-1;he+=2)X+=String.fromCharCode(U[he]+U[he+1]*256);return X}i.prototype.slice=function(h,w){let A=this.length;h=~~h,w=w===void 0?A:~~w,h<0?(h+=A,h<0&&(h=0)):h>A&&(h=A),w<0?(w+=A,w<0&&(w=0)):w>A&&(w=A),w<h&&(w=h);let U=this.subarray(h,w);return Object.setPrototypeOf(U,i.prototype),U};function D(h,w,A){if(h%1!==0||h<0)throw new RangeError("offset is not uint");if(h+w>A)throw new RangeError("Trying to access beyond buffer length")}i.prototype.readUintLE=i.prototype.readUIntLE=function(h,w,A){h=h>>>0,w=w>>>0,A||D(h,w,this.length);let U=this[h],X=1,he=0;for(;++he<w&&(X*=256);)U+=this[h+he]*X;return U},i.prototype.readUintBE=i.prototype.readUIntBE=function(h,w,A){h=h>>>0,w=w>>>0,A||D(h,w,this.length);let U=this[h+--w],X=1;for(;w>0&&(X*=256);)U+=this[h+--w]*X;return U},i.prototype.readUint8=i.prototype.readUInt8=function(h,w){return h=h>>>0,w||D(h,1,this.length),this[h]},i.prototype.readUint16LE=i.prototype.readUInt16LE=function(h,w){return h=h>>>0,w||D(h,2,this.length),this[h]|this[h+1]<<8},i.prototype.readUint16BE=i.prototype.readUInt16BE=function(h,w){return h=h>>>0,w||D(h,2,this.length),this[h]<<8|this[h+1]},i.prototype.readUint32LE=i.prototype.readUInt32LE=function(h,w){return h=h>>>0,w||D(h,4,this.length),(this[h]|this[h+1]<<8|this[h+2]<<16)+this[h+3]*16777216},i.prototype.readUint32BE=i.prototype.readUInt32BE=function(h,w){return h=h>>>0,w||D(h,4,this.length),this[h]*16777216+(this[h+1]<<16|this[h+2]<<8|this[h+3])},i.prototype.readBigUInt64LE=oe(function(h){h=h>>>0,Q(h,"offset");let w=this[h],A=this[h+7];(w===void 0||A===void 0)&&me(h,this.length-8);let U=w+this[++h]*2**8+this[++h]*2**16+this[++h]*2**24,X=this[++h]+this[++h]*2**8+this[++h]*2**16+A*2**24;return BigInt(U)+(BigInt(X)<<BigInt(32))}),i.prototype.readBigUInt64BE=oe(function(h){h=h>>>0,Q(h,"offset");let w=this[h],A=this[h+7];(w===void 0||A===void 0)&&me(h,this.length-8);let U=w*2**24+this[++h]*2**16+this[++h]*2**8+this[++h],X=this[++h]*2**24+this[++h]*2**16+this[++h]*2**8+A;return(BigInt(U)<<BigInt(32))+BigInt(X)}),i.prototype.readIntLE=function(h,w,A){h=h>>>0,w=w>>>0,A||D(h,w,this.length);let U=this[h],X=1,he=0;for(;++he<w&&(X*=256);)U+=this[h+he]*X;return X*=128,U>=X&&(U-=Math.pow(2,8*w)),U},i.prototype.readIntBE=function(h,w,A){h=h>>>0,w=w>>>0,A||D(h,w,this.length);let U=w,X=1,he=this[h+--U];for(;U>0&&(X*=256);)he+=this[h+--U]*X;return X*=128,he>=X&&(he-=Math.pow(2,8*w)),he},i.prototype.readInt8=function(h,w){return h=h>>>0,w||D(h,1,this.length),this[h]&128?(255-this[h]+1)*-1:this[h]},i.prototype.readInt16LE=function(h,w){h=h>>>0,w||D(h,2,this.length);let A=this[h]|this[h+1]<<8;return A&32768?A|4294901760:A},i.prototype.readInt16BE=function(h,w){h=h>>>0,w||D(h,2,this.length);let A=this[h+1]|this[h]<<8;return A&32768?A|4294901760:A},i.prototype.readInt32LE=function(h,w){return h=h>>>0,w||D(h,4,this.length),this[h]|this[h+1]<<8|this[h+2]<<16|this[h+3]<<24},i.prototype.readInt32BE=function(h,w){return h=h>>>0,w||D(h,4,this.length),this[h]<<24|this[h+1]<<16|this[h+2]<<8|this[h+3]},i.prototype.readBigInt64LE=oe(function(h){h=h>>>0,Q(h,"offset");let w=this[h],A=this[h+7];(w===void 0||A===void 0)&&me(h,this.length-8);let U=this[h+4]+this[h+5]*2**8+this[h+6]*2**16+(A<<24);return(BigInt(U)<<BigInt(32))+BigInt(w+this[++h]*2**8+this[++h]*2**16+this[++h]*2**24)}),i.prototype.readBigInt64BE=oe(function(h){h=h>>>0,Q(h,"offset");let w=this[h],A=this[h+7];(w===void 0||A===void 0)&&me(h,this.length-8);let U=(w<<24)+this[++h]*2**16+this[++h]*2**8+this[++h];return(BigInt(U)<<BigInt(32))+BigInt(this[++h]*2**24+this[++h]*2**16+this[++h]*2**8+A)}),i.prototype.readFloatLE=function(h,w){return h=h>>>0,w||D(h,4,this.length),e.read(this,h,!0,23,4)},i.prototype.readFloatBE=function(h,w){return h=h>>>0,w||D(h,4,this.length),e.read(this,h,!1,23,4)},i.prototype.readDoubleLE=function(h,w){return h=h>>>0,w||D(h,8,this.length),e.read(this,h,!0,52,8)},i.prototype.readDoubleBE=function(h,w){return h=h>>>0,w||D(h,8,this.length),e.read(this,h,!1,52,8)};function Z(h,w,A,U,X,he){if(!i.isBuffer(h))throw new TypeError('"buffer" argument must be a Buffer instance');if(w>X||w<he)throw new RangeError('"value" argument is out of bounds');if(A+U>h.length)throw new RangeError("Index out of range")}i.prototype.writeUintLE=i.prototype.writeUIntLE=function(h,w,A,U){if(h=+h,w=w>>>0,A=A>>>0,!U){let Se=Math.pow(2,8*A)-1;Z(this,h,w,A,Se,0)}let X=1,he=0;for(this[w]=h&255;++he<A&&(X*=256);)this[w+he]=h/X&255;return w+A},i.prototype.writeUintBE=i.prototype.writeUIntBE=function(h,w,A,U){if(h=+h,w=w>>>0,A=A>>>0,!U){let Se=Math.pow(2,8*A)-1;Z(this,h,w,A,Se,0)}let X=A-1,he=1;for(this[w+X]=h&255;--X>=0&&(he*=256);)this[w+X]=h/he&255;return w+A},i.prototype.writeUint8=i.prototype.writeUInt8=function(h,w,A){return h=+h,w=w>>>0,A||Z(this,h,w,1,255,0),this[w]=h&255,w+1},i.prototype.writeUint16LE=i.prototype.writeUInt16LE=function(h,w,A){return h=+h,w=w>>>0,A||Z(this,h,w,2,65535,0),this[w]=h&255,this[w+1]=h>>>8,w+2},i.prototype.writeUint16BE=i.prototype.writeUInt16BE=function(h,w,A){return h=+h,w=w>>>0,A||Z(this,h,w,2,65535,0),this[w]=h>>>8,this[w+1]=h&255,w+2},i.prototype.writeUint32LE=i.prototype.writeUInt32LE=function(h,w,A){return h=+h,w=w>>>0,A||Z(this,h,w,4,4294967295,0),this[w+3]=h>>>24,this[w+2]=h>>>16,this[w+1]=h>>>8,this[w]=h&255,w+4},i.prototype.writeUint32BE=i.prototype.writeUInt32BE=function(h,w,A){return h=+h,w=w>>>0,A||Z(this,h,w,4,4294967295,0),this[w]=h>>>24,this[w+1]=h>>>16,this[w+2]=h>>>8,this[w+3]=h&255,w+4};function P(h,w,A,U,X){G(w,U,X,h,A,7);let he=Number(w&BigInt(4294967295));h[A++]=he,he=he>>8,h[A++]=he,he=he>>8,h[A++]=he,he=he>>8,h[A++]=he;let Se=Number(w>>BigInt(32)&BigInt(4294967295));return h[A++]=Se,Se=Se>>8,h[A++]=Se,Se=Se>>8,h[A++]=Se,Se=Se>>8,h[A++]=Se,A}function J(h,w,A,U,X){G(w,U,X,h,A,7);let he=Number(w&BigInt(4294967295));h[A+7]=he,he=he>>8,h[A+6]=he,he=he>>8,h[A+5]=he,he=he>>8,h[A+4]=he;let Se=Number(w>>BigInt(32)&BigInt(4294967295));return h[A+3]=Se,Se=Se>>8,h[A+2]=Se,Se=Se>>8,h[A+1]=Se,Se=Se>>8,h[A]=Se,A+8}i.prototype.writeBigUInt64LE=oe(function(h,w=0){return P(this,h,w,BigInt(0),BigInt("0xffffffffffffffff"))}),i.prototype.writeBigUInt64BE=oe(function(h,w=0){return J(this,h,w,BigInt(0),BigInt("0xffffffffffffffff"))}),i.prototype.writeIntLE=function(h,w,A,U){if(h=+h,w=w>>>0,!U){let z=Math.pow(2,8*A-1);Z(this,h,w,A,z-1,-z)}let X=0,he=1,Se=0;for(this[w]=h&255;++X<A&&(he*=256);)h<0&&Se===0&&this[w+X-1]!==0&&(Se=1),this[w+X]=(h/he>>0)-Se&255;return w+A},i.prototype.writeIntBE=function(h,w,A,U){if(h=+h,w=w>>>0,!U){let z=Math.pow(2,8*A-1);Z(this,h,w,A,z-1,-z)}let X=A-1,he=1,Se=0;for(this[w+X]=h&255;--X>=0&&(he*=256);)h<0&&Se===0&&this[w+X+1]!==0&&(Se=1),this[w+X]=(h/he>>0)-Se&255;return w+A},i.prototype.writeInt8=function(h,w,A){return h=+h,w=w>>>0,A||Z(this,h,w,1,127,-128),h<0&&(h=255+h+1),this[w]=h&255,w+1},i.prototype.writeInt16LE=function(h,w,A){return h=+h,w=w>>>0,A||Z(this,h,w,2,32767,-32768),this[w]=h&255,this[w+1]=h>>>8,w+2},i.prototype.writeInt16BE=function(h,w,A){return h=+h,w=w>>>0,A||Z(this,h,w,2,32767,-32768),this[w]=h>>>8,this[w+1]=h&255,w+2},i.prototype.writeInt32LE=function(h,w,A){return h=+h,w=w>>>0,A||Z(this,h,w,4,2147483647,-2147483648),this[w]=h&255,this[w+1]=h>>>8,this[w+2]=h>>>16,this[w+3]=h>>>24,w+4},i.prototype.writeInt32BE=function(h,w,A){return h=+h,w=w>>>0,A||Z(this,h,w,4,2147483647,-2147483648),h<0&&(h=4294967295+h+1),this[w]=h>>>24,this[w+1]=h>>>16,this[w+2]=h>>>8,this[w+3]=h&255,w+4},i.prototype.writeBigInt64LE=oe(function(h,w=0){return P(this,h,w,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),i.prototype.writeBigInt64BE=oe(function(h,w=0){return J(this,h,w,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function be(h,w,A,U,X,he){if(A+U>h.length)throw new RangeError("Index out of range");if(A<0)throw new RangeError("Index out of range")}function te(h,w,A,U,X){return w=+w,A=A>>>0,X||be(h,w,A,4),e.write(h,w,A,U,23,4),A+4}i.prototype.writeFloatLE=function(h,w,A){return te(this,h,w,!0,A)},i.prototype.writeFloatBE=function(h,w,A){return te(this,h,w,!1,A)};function we(h,w,A,U,X){return w=+w,A=A>>>0,X||be(h,w,A,8),e.write(h,w,A,U,52,8),A+8}i.prototype.writeDoubleLE=function(h,w,A){return we(this,h,w,!0,A)},i.prototype.writeDoubleBE=function(h,w,A){return we(this,h,w,!1,A)},i.prototype.copy=function(h,w,A,U){if(!i.isBuffer(h))throw new TypeError("argument should be a Buffer");if(A||(A=0),!U&&U!==0&&(U=this.length),w>=h.length&&(w=h.length),w||(w=0),U>0&&U<A&&(U=A),U===A||h.length===0||this.length===0)return 0;if(w<0)throw new RangeError("targetStart out of bounds");if(A<0||A>=this.length)throw new RangeError("Index out of range");if(U<0)throw new RangeError("sourceEnd out of bounds");U>this.length&&(U=this.length),h.length-w<U-A&&(U=h.length-w+A);let X=U-A;return this===h&&typeof Uint8Array.prototype.copyWithin=="function"?this.copyWithin(w,A,U):Uint8Array.prototype.set.call(h,this.subarray(A,U),w),X},i.prototype.fill=function(h,w,A,U){if(typeof h=="string"){if(typeof w=="string"?(U=w,w=0,A=this.length):typeof A=="string"&&(U=A,A=this.length),U!==void 0&&typeof U!="string")throw new TypeError("encoding must be a string");if(typeof U=="string"&&!i.isEncoding(U))throw new TypeError("Unknown encoding: "+U);if(h.length===1){let he=h.charCodeAt(0);(U==="utf8"&&he<128||U==="latin1")&&(h=he)}}else typeof h=="number"?h=h&255:typeof h=="boolean"&&(h=Number(h));if(w<0||this.length<w||this.length<A)throw new RangeError("Out of range index");if(A<=w)return this;w=w>>>0,A=A===void 0?this.length:A>>>0,h||(h=0);let X;if(typeof h=="number")for(X=w;X<A;++X)this[X]=h;else{let he=i.isBuffer(h)?h:i.from(h,U),Se=he.length;if(Se===0)throw new TypeError('The value "'+h+'" is invalid for argument "value"');for(X=0;X<A-w;++X)this[X+w]=he[X%Se]}return this};let V={};function L(h,w,A){V[h]=class extends A{constructor(){super(),Object.defineProperty(this,"message",{value:w.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${h}]`,this.stack,delete this.name}get code(){return h}set code(U){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:U,writable:!0})}toString(){return`${this.name} [${h}]: ${this.message}`}}}L("ERR_BUFFER_OUT_OF_BOUNDS",function(h){return h?`${h} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),L("ERR_INVALID_ARG_TYPE",function(h,w){return`The "${h}" argument must be of type number. Received type ${typeof w}`},TypeError),L("ERR_OUT_OF_RANGE",function(h,w,A){let U=`The value of "${h}" is out of range.`,X=A;return Number.isInteger(A)&&Math.abs(A)>2**32?X=ne(String(A)):typeof A=="bigint"&&(X=String(A),(A>BigInt(2)**BigInt(32)||A<-(BigInt(2)**BigInt(32)))&&(X=ne(X)),X+="n"),U+=` It must be ${w}. Received ${X}`,U},RangeError);function ne(h){let w="",A=h.length,U=h[0]==="-"?1:0;for(;A>=U+4;A-=3)w=`_${h.slice(A-3,A)}${w}`;return`${h.slice(0,A)}${w}`}function H(h,w,A){Q(w,"offset"),(h[w]===void 0||h[w+A]===void 0)&&me(w,h.length-(A+1))}function G(h,w,A,U,X,he){if(h>A||h<w){let Se=typeof w=="bigint"?"n":"",z;throw w===0||w===BigInt(0)?z=`>= 0${Se} and < 2${Se} ** ${(he+1)*8}${Se}`:z=`>= -(2${Se} ** ${(he+1)*8-1}${Se}) and < 2 ** ${(he+1)*8-1}${Se}`,new V.ERR_OUT_OF_RANGE("value",z,h)}H(U,X,he)}function Q(h,w){if(typeof h!="number")throw new V.ERR_INVALID_ARG_TYPE(w,"number",h)}function me(h,w,A){throw Math.floor(h)!==h?(Q(h,A),new V.ERR_OUT_OF_RANGE("offset","an integer",h)):w<0?new V.ERR_BUFFER_OUT_OF_BOUNDS:new V.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${w}`,h)}let se=/[^+/0-9A-Za-z-_]/g;function R(h){if(h=h.split("=")[0],h=h.trim().replace(se,""),h.length<2)return"";for(;h.length%4!==0;)h=h+"=";return h}function $(h,w){w=w||1/0;let A,U=h.length,X=null,he=[];for(let Se=0;Se<U;++Se){if(A=h.charCodeAt(Se),A>55295&&A<57344){if(!X){if(A>56319){(w-=3)>-1&&he.push(239,191,189);continue}else if(Se+1===U){(w-=3)>-1&&he.push(239,191,189);continue}X=A;continue}if(A<56320){(w-=3)>-1&&he.push(239,191,189),X=A;continue}A=(X-55296<<10|A-56320)+65536}else X&&(w-=3)>-1&&he.push(239,191,189);if(X=null,A<128){if((w-=1)<0)break;he.push(A)}else if(A<2048){if((w-=2)<0)break;he.push(A>>6|192,A&63|128)}else if(A<65536){if((w-=3)<0)break;he.push(A>>12|224,A>>6&63|128,A&63|128)}else if(A<1114112){if((w-=4)<0)break;he.push(A>>18|240,A>>12&63|128,A>>6&63|128,A&63|128)}else throw new Error("Invalid code point")}return he}function ee(h){let w=[];for(let A=0;A<h.length;++A)w.push(h.charCodeAt(A)&255);return w}function fe(h,w){let A,U,X,he=[];for(let Se=0;Se<h.length&&!((w-=2)<0);++Se)A=h.charCodeAt(Se),U=A>>8,X=A%256,he.push(X),he.push(U);return he}function de(h){return u.toByteArray(R(h))}function ye(h,w,A,U){let X;for(X=0;X<U&&!(X+A>=w.length||X>=h.length);++X)w[X+A]=h[X];return X}function q(h,w){return h instanceof w||h!=null&&h.constructor!=null&&h.constructor.name!=null&&h.constructor.name===w.name}function ge(h){return h!==h}let ve=(function(){let h="0123456789abcdef",w=new Array(256);for(let A=0;A<16;++A){let U=A*16;for(let X=0;X<16;++X)w[U+X]=h[A]+h[X]}return w})();function oe(h){return typeof BigInt>"u"?Te:h}function Te(){throw new Error("BigInt not supported")}return dt}var Ct,Xn,qt,Zn,dt,ei,su=He(()=>{le(),ce(),ue(),Ct={},Xn=!1,qt={},Zn=!1,dt={},ei=!1}),Le={};jt(Le,{Buffer:()=>Tr,INSPECT_MAX_BYTES:()=>Wo,default:()=>nt,kMaxLength:()=>qo});var nt,Tr,Wo,qo,Ne=He(()=>{le(),ce(),ue(),su(),nt=iu(),nt.Buffer,nt.SlowBuffer,nt.INSPECT_MAX_BYTES,nt.kMaxLength,Tr=nt.Buffer,Wo=nt.INSPECT_MAX_BYTES,qo=nt.kMaxLength}),ce=He(()=>{Ne()}),Re=pe((u,e)=>{le(),ce(),ue();var t=class extends Error{constructor(n){if(!Array.isArray(n))throw new TypeError(`Expected input to be an Array, got ${typeof n}`);let l="";for(let r=0;r<n.length;r++)l+=` ${n[r].stack}
|
|
2
|
-
`;super(l),this.name="AggregateError",this.errors=n}};e.exports={AggregateError:t,ArrayIsArray(n){return Array.isArray(n)},ArrayPrototypeIncludes(n,l){return n.includes(l)},ArrayPrototypeIndexOf(n,l){return n.indexOf(l)},ArrayPrototypeJoin(n,l){return n.join(l)},ArrayPrototypeMap(n,l){return n.map(l)},ArrayPrototypePop(n,l){return n.pop(l)},ArrayPrototypePush(n,l){return n.push(l)},ArrayPrototypeSlice(n,l,r){return n.slice(l,r)},Error,FunctionPrototypeCall(n,l,...r){return n.call(l,...r)},FunctionPrototypeSymbolHasInstance(n,l){return Function.prototype[Symbol.hasInstance].call(n,l)},MathFloor:Math.floor,Number,NumberIsInteger:Number.isInteger,NumberIsNaN:Number.isNaN,NumberMAX_SAFE_INTEGER:Number.MAX_SAFE_INTEGER,NumberMIN_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,NumberParseInt:Number.parseInt,ObjectDefineProperties(n,l){return Object.defineProperties(n,l)},ObjectDefineProperty(n,l,r){return Object.defineProperty(n,l,r)},ObjectGetOwnPropertyDescriptor(n,l){return Object.getOwnPropertyDescriptor(n,l)},ObjectKeys(n){return Object.keys(n)},ObjectSetPrototypeOf(n,l){return Object.setPrototypeOf(n,l)},Promise,PromisePrototypeCatch(n,l){return n.catch(l)},PromisePrototypeThen(n,l,r){return n.then(l,r)},PromiseReject(n){return Promise.reject(n)},PromiseResolve(n){return Promise.resolve(n)},ReflectApply:Reflect.apply,RegExpPrototypeTest(n,l){return n.test(l)},SafeSet:Set,String,StringPrototypeSlice(n,l,r){return n.slice(l,r)},StringPrototypeToLowerCase(n){return n.toLowerCase()},StringPrototypeToUpperCase(n){return n.toUpperCase()},StringPrototypeTrim(n){return n.trim()},Symbol,SymbolFor:Symbol.for,SymbolAsyncIterator:Symbol.asyncIterator,SymbolHasInstance:Symbol.hasInstance,SymbolIterator:Symbol.iterator,SymbolDispose:Symbol.dispose||Symbol("Symbol.dispose"),SymbolAsyncDispose:Symbol.asyncDispose||Symbol("Symbol.asyncDispose"),TypedArrayPrototypeSet(n,l,r){return n.set(l,r)},Boolean,Uint8Array}}),Ho=pe((u,e)=>{le(),ce(),ue(),e.exports={format(t,...n){return t.replace(/%([sdifj])/g,function(...[l,r]){let i=n.shift();return r==="f"?i.toFixed(6):r==="j"?JSON.stringify(i):r==="s"&&typeof i=="object"?`${i.constructor!==Object?i.constructor.name:""} {}`.trim():i.toString()})},inspect(t){switch(typeof t){case"string":if(t.includes("'"))if(t.includes('"')){if(!t.includes("`")&&!t.includes("${"))return`\`${t}\``}else return`"${t}"`;return`'${t}'`;case"number":return isNaN(t)?"NaN":Object.is(t,-0)?String(t):t;case"bigint":return`${String(t)}n`;case"boolean":case"undefined":return String(t);case"object":return"{}"}}}}),We=pe((u,e)=>{le(),ce(),ue();var{format:t,inspect:n}=Ho(),{AggregateError:l}=Re(),r=globalThis.AggregateError||l,i=Symbol("kIsNodeError"),o=["string","function","number","object","Function","Object","boolean","bigint","symbol"],s=/^([A-Z][a-z0-9]*)+$/,a="__node_internal_",c={};function d(g,S){if(!g)throw new c.ERR_INTERNAL_ASSERTION(S)}function p(g){let S="",x=g.length,v=g[0]==="-"?1:0;for(;x>=v+4;x-=3)S=`_${g.slice(x-3,x)}${S}`;return`${g.slice(0,x)}${S}`}function y(g,S,x){if(typeof S=="function")return d(S.length<=x.length,`Code: ${g}; The provided arguments length (${x.length}) does not match the required ones (${S.length}).`),S(...x);let v=(S.match(/%[dfijoOs]/g)||[]).length;return d(v===x.length,`Code: ${g}; The provided arguments length (${x.length}) does not match the required ones (${v}).`),x.length===0?S:t(S,...x)}function f(g,S,x){x||(x=Error);class v extends x{constructor(...k){super(y(g,S,k))}toString(){return`${this.name} [${g}]: ${this.message}`}}Object.defineProperties(v.prototype,{name:{value:x.name,writable:!0,enumerable:!1,configurable:!0},toString:{value(){return`${this.name} [${g}]: ${this.message}`},writable:!0,enumerable:!1,configurable:!0}}),v.prototype.code=g,v.prototype[i]=!0,c[g]=v}function m(g){let S=a+g.name;return Object.defineProperty(g,"name",{value:S}),g}function b(g,S){if(g&&S&&g!==S){if(Array.isArray(S.errors))return S.errors.push(g),S;let x=new r([S,g],S.message);return x.code=S.code,x}return g||S}var _=class extends Error{constructor(g="The operation was aborted",S=void 0){if(S!==void 0&&typeof S!="object")throw new c.ERR_INVALID_ARG_TYPE("options","Object",S);super(g,S),this.code="ABORT_ERR",this.name="AbortError"}};f("ERR_ASSERTION","%s",Error),f("ERR_INVALID_ARG_TYPE",(g,S,x)=>{d(typeof g=="string","'name' must be a string"),Array.isArray(S)||(S=[S]);let v="The ";g.endsWith(" argument")?v+=`${g} `:v+=`"${g}" ${g.includes(".")?"property":"argument"} `,v+="must be ";let E=[],k=[],I=[];for(let O of S)d(typeof O=="string","All expected entries have to be of type string"),o.includes(O)?E.push(O.toLowerCase()):s.test(O)?k.push(O):(d(O!=="object",'The value "object" should be written as "Object"'),I.push(O));if(k.length>0){let O=E.indexOf("object");O!==-1&&(E.splice(E,O,1),k.push("Object"))}if(E.length>0){switch(E.length){case 1:v+=`of type ${E[0]}`;break;case 2:v+=`one of type ${E[0]} or ${E[1]}`;break;default:{let O=E.pop();v+=`one of type ${E.join(", ")}, or ${O}`}}(k.length>0||I.length>0)&&(v+=" or ")}if(k.length>0){switch(k.length){case 1:v+=`an instance of ${k[0]}`;break;case 2:v+=`an instance of ${k[0]} or ${k[1]}`;break;default:{let O=k.pop();v+=`an instance of ${k.join(", ")}, or ${O}`}}I.length>0&&(v+=" or ")}switch(I.length){case 0:break;case 1:I[0].toLowerCase()!==I[0]&&(v+="an "),v+=`${I[0]}`;break;case 2:v+=`one of ${I[0]} or ${I[1]}`;break;default:{let O=I.pop();v+=`one of ${I.join(", ")}, or ${O}`}}if(x==null)v+=`. Received ${x}`;else if(typeof x=="function"&&x.name)v+=`. Received function ${x.name}`;else if(typeof x=="object"){var M;if((M=x.constructor)!==null&&M!==void 0&&M.name)v+=`. Received an instance of ${x.constructor.name}`;else{let O=n(x,{depth:-1});v+=`. Received ${O}`}}else{let O=n(x,{colors:!1});O.length>25&&(O=`${O.slice(0,25)}...`),v+=`. Received type ${typeof x} (${O})`}return v},TypeError),f("ERR_INVALID_ARG_VALUE",(g,S,x="is invalid")=>{let v=n(S);return v.length>128&&(v=v.slice(0,128)+"..."),`The ${g.includes(".")?"property":"argument"} '${g}' ${x}. Received ${v}`},TypeError),f("ERR_INVALID_RETURN_VALUE",(g,S,x)=>{var v;let E=x!=null&&(v=x.constructor)!==null&&v!==void 0&&v.name?`instance of ${x.constructor.name}`:`type ${typeof x}`;return`Expected ${g} to be returned from the "${S}" function but got ${E}.`},TypeError),f("ERR_MISSING_ARGS",(...g)=>{d(g.length>0,"At least one arg needs to be specified");let S,x=g.length;switch(g=(Array.isArray(g)?g:[g]).map(v=>`"${v}"`).join(" or "),x){case 1:S+=`The ${g[0]} argument`;break;case 2:S+=`The ${g[0]} and ${g[1]} arguments`;break;default:{let v=g.pop();S+=`The ${g.join(", ")}, and ${v} arguments`}break}return`${S} must be specified`},TypeError),f("ERR_OUT_OF_RANGE",(g,S,x)=>{d(S,'Missing "range" argument');let v;if(Number.isInteger(x)&&Math.abs(x)>2**32)v=p(String(x));else if(typeof x=="bigint"){v=String(x);let E=BigInt(2)**BigInt(32);(x>E||x<-E)&&(v=p(v)),v+="n"}else v=n(x);return`The value of "${g}" is out of range. It must be ${S}. Received ${v}`},RangeError),f("ERR_MULTIPLE_CALLBACK","Callback called multiple times",Error),f("ERR_METHOD_NOT_IMPLEMENTED","The %s method is not implemented",Error),f("ERR_STREAM_ALREADY_FINISHED","Cannot call %s after a stream was finished",Error),f("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable",Error),f("ERR_STREAM_DESTROYED","Cannot call %s after a stream was destroyed",Error),f("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),f("ERR_STREAM_PREMATURE_CLOSE","Premature close",Error),f("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF",Error),f("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event",Error),f("ERR_STREAM_WRITE_AFTER_END","write after end",Error),f("ERR_UNKNOWN_ENCODING","Unknown encoding: %s",TypeError),e.exports={AbortError:_,aggregateTwoErrors:m(b),hideStackFrames:m,codes:c}}),Gt=pe((u,e)=>{le(),ce(),ue();var{AbortController:t,AbortSignal:n}=typeof self<"u"?self:typeof window<"u"?window:void 0;e.exports=t,e.exports.AbortSignal=n,e.exports.default=t}),mt={};jt(mt,{EventEmitter:()=>zo,default:()=>Ot,defaultMaxListeners:()=>Ko,init:()=>Vo,listenerCount:()=>Go,on:()=>Yo,once:()=>Qo});function ou(){if(ti)return Ht;ti=!0;var u=typeof Reflect=="object"?Reflect:null,e=u&&typeof u.apply=="function"?u.apply:function(x,v,E){return Function.prototype.apply.call(x,v,E)},t;u&&typeof u.ownKeys=="function"?t=u.ownKeys:Object.getOwnPropertySymbols?t=function(x){return Object.getOwnPropertyNames(x).concat(Object.getOwnPropertySymbols(x))}:t=function(x){return Object.getOwnPropertyNames(x)};function n(x){console&&console.warn&&console.warn(x)}var l=Number.isNaN||function(x){return x!==x};function r(){r.init.call(this)}Ht=r,Ht.once=_,r.EventEmitter=r,r.prototype._events=void 0,r.prototype._eventsCount=0,r.prototype._maxListeners=void 0;var i=10;function o(x){if(typeof x!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof x)}Object.defineProperty(r,"defaultMaxListeners",{enumerable:!0,get:function(){return i},set:function(x){if(typeof x!="number"||x<0||l(x))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+x+".");i=x}}),r.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},r.prototype.setMaxListeners=function(x){if(typeof x!="number"||x<0||l(x))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+x+".");return this._maxListeners=x,this};function s(x){return x._maxListeners===void 0?r.defaultMaxListeners:x._maxListeners}r.prototype.getMaxListeners=function(){return s(this)},r.prototype.emit=function(x){for(var v=[],E=1;E<arguments.length;E++)v.push(arguments[E]);var k=x==="error",I=this._events;if(I!==void 0)k=k&&I.error===void 0;else if(!k)return!1;if(k){var M;if(v.length>0&&(M=v[0]),M instanceof Error)throw M;var O=new Error("Unhandled error."+(M?" ("+M.message+")":""));throw O.context=M,O}var B=I[x];if(B===void 0)return!1;if(typeof B=="function")e(B,this,v);else for(var T=B.length,W=f(B,T),E=0;E<T;++E)e(W[E],this,v);return!0};function a(x,v,E,k){var I,M,O;if(o(E),M=x._events,M===void 0?(M=x._events=Object.create(null),x._eventsCount=0):(M.newListener!==void 0&&(x.emit("newListener",v,E.listener?E.listener:E),M=x._events),O=M[v]),O===void 0)O=M[v]=E,++x._eventsCount;else if(typeof O=="function"?O=M[v]=k?[E,O]:[O,E]:k?O.unshift(E):O.push(E),I=s(x),I>0&&O.length>I&&!O.warned){O.warned=!0;var B=new Error("Possible EventEmitter memory leak detected. "+O.length+" "+String(v)+" listeners added. Use emitter.setMaxListeners() to increase limit");B.name="MaxListenersExceededWarning",B.emitter=x,B.type=v,B.count=O.length,n(B)}return x}r.prototype.addListener=function(x,v){return a(this,x,v,!1)},r.prototype.on=r.prototype.addListener,r.prototype.prependListener=function(x,v){return a(this,x,v,!0)};function c(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function d(x,v,E){var k={fired:!1,wrapFn:void 0,target:x,type:v,listener:E},I=c.bind(k);return I.listener=E,k.wrapFn=I,I}r.prototype.once=function(x,v){return o(v),this.on(x,d(this,x,v)),this},r.prototype.prependOnceListener=function(x,v){return o(v),this.prependListener(x,d(this,x,v)),this},r.prototype.removeListener=function(x,v){var E,k,I,M,O;if(o(v),k=this._events,k===void 0)return this;if(E=k[x],E===void 0)return this;if(E===v||E.listener===v)--this._eventsCount===0?this._events=Object.create(null):(delete k[x],k.removeListener&&this.emit("removeListener",x,E.listener||v));else if(typeof E!="function"){for(I=-1,M=E.length-1;M>=0;M--)if(E[M]===v||E[M].listener===v){O=E[M].listener,I=M;break}if(I<0)return this;I===0?E.shift():m(E,I),E.length===1&&(k[x]=E[0]),k.removeListener!==void 0&&this.emit("removeListener",x,O||v)}return this},r.prototype.off=r.prototype.removeListener,r.prototype.removeAllListeners=function(x){var v,E,k;if(E=this._events,E===void 0)return this;if(E.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):E[x]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete E[x]),this;if(arguments.length===0){var I=Object.keys(E),M;for(k=0;k<I.length;++k)M=I[k],M!=="removeListener"&&this.removeAllListeners(M);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(v=E[x],typeof v=="function")this.removeListener(x,v);else if(v!==void 0)for(k=v.length-1;k>=0;k--)this.removeListener(x,v[k]);return this};function p(x,v,E){var k=x._events;if(k===void 0)return[];var I=k[v];return I===void 0?[]:typeof I=="function"?E?[I.listener||I]:[I]:E?b(I):f(I,I.length)}r.prototype.listeners=function(x){return p(this,x,!0)},r.prototype.rawListeners=function(x){return p(this,x,!1)},r.listenerCount=function(x,v){return typeof x.listenerCount=="function"?x.listenerCount(v):y.call(x,v)},r.prototype.listenerCount=y;function y(x){var v=this._events;if(v!==void 0){var E=v[x];if(typeof E=="function")return 1;if(E!==void 0)return E.length}return 0}r.prototype.eventNames=function(){return this._eventsCount>0?t(this._events):[]};function f(x,v){for(var E=new Array(v),k=0;k<v;++k)E[k]=x[k];return E}function m(x,v){for(;v+1<x.length;v++)x[v]=x[v+1];x.pop()}function b(x){for(var v=new Array(x.length),E=0;E<v.length;++E)v[E]=x[E].listener||x[E];return v}function _(x,v){return new Promise(function(E,k){function I(O){x.removeListener(v,M),k(O)}function M(){typeof x.removeListener=="function"&&x.removeListener("error",I),E([].slice.call(arguments))}S(x,v,M,{once:!0}),v!=="error"&&g(x,I,{once:!0})})}function g(x,v,E){typeof x.on=="function"&&S(x,"error",v,E)}function S(x,v,E,k){if(typeof x.on=="function")k.once?x.once(v,E):x.on(v,E);else if(typeof x.addEventListener=="function")x.addEventListener(v,function I(M){k.once&&x.removeEventListener(v,I),E(M)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof x)}return Ht}var Ht,ti,Ot,zo,Ko,Vo,Go,Yo,Qo,Et=He(()=>{le(),ce(),ue(),Ht={},ti=!1,Ot=ou(),Ot.once,Ot.once=function(u,e){return new Promise((t,n)=>{function l(...i){r!==void 0&&u.removeListener("error",r),t(i)}let r;e!=="error"&&(r=i=>{u.removeListener(name,l),n(i)},u.once("error",r)),u.once(e,l)})},Ot.on=function(u,e){let t=[],n=[],l=null,r=!1,i={async next(){let a=t.shift();if(a)return createIterResult(a,!1);if(l){let c=Promise.reject(l);return l=null,c}return r?createIterResult(void 0,!0):new Promise((c,d)=>n.push({resolve:c,reject:d}))},async return(){u.removeListener(e,o),u.removeListener("error",s),r=!0;for(let a of n)a.resolve(createIterResult(void 0,!0));return createIterResult(void 0,!0)},throw(a){l=a,u.removeListener(e,o),u.removeListener("error",s)},[Symbol.asyncIterator](){return this}};return u.on(e,o),u.on("error",s),i;function o(...a){let c=n.shift();c?c.resolve(createIterResult(a,!1)):t.push(a)}function s(a){r=!0;let c=n.shift();c?c.reject(a):l=a,i.return()}},{EventEmitter:zo,defaultMaxListeners:Ko,init:Vo,listenerCount:Go,on:Yo,once:Qo}=Ot}),qe=pe((u,e)=>{le(),ce(),ue();var t=(Ne(),Oe(Le)),{format:n,inspect:l}=Ho(),{codes:{ERR_INVALID_ARG_TYPE:r}}=We(),{kResistStopPropagation:i,AggregateError:o,SymbolDispose:s}=Re(),a=globalThis.AbortSignal||Gt().AbortSignal,c=globalThis.AbortController||Gt().AbortController,d=Object.getPrototypeOf(async function(){}).constructor,p=globalThis.Blob||t.Blob,y=typeof p<"u"?function(b){return b instanceof p}:function(b){return!1},f=(b,_)=>{if(b!==void 0&&(b===null||typeof b!="object"||!("aborted"in b)))throw new r(_,"AbortSignal",b)},m=(b,_)=>{if(typeof b!="function")throw new r(_,"Function",b)};e.exports={AggregateError:o,kEmptyObject:Object.freeze({}),once(b){let _=!1;return function(...g){_||(_=!0,b.apply(this,g))}},createDeferredPromise:function(){let b,_;return{promise:new Promise((g,S)=>{b=g,_=S}),resolve:b,reject:_}},promisify(b){return new Promise((_,g)=>{b((S,...x)=>S?g(S):_(...x))})},debuglog(){return function(){}},format:n,inspect:l,types:{isAsyncFunction(b){return b instanceof d},isArrayBufferView(b){return ArrayBuffer.isView(b)}},isBlob:y,deprecate(b,_){return b},addAbortListener:(Et(),Oe(mt)).addAbortListener||function(b,_){if(b===void 0)throw new r("signal","AbortSignal",b);f(b,"signal"),m(_,"listener");let g;return b.aborted?queueMicrotask(()=>_()):(b.addEventListener("abort",_,{__proto__:null,once:!0,[i]:!0}),g=()=>{b.removeEventListener("abort",_)}),{__proto__:null,[s](){var S;(S=g)===null||S===void 0||S()}}},AbortSignalAny:a.any||function(b){if(b.length===1)return b[0];let _=new c,g=()=>_.abort();return b.forEach(S=>{f(S,"signals"),S.addEventListener("abort",g,{once:!0})}),_.signal.addEventListener("abort",()=>{b.forEach(S=>S.removeEventListener("abort",g))},{once:!0}),_.signal}},e.exports.promisify.custom=Symbol.for("nodejs.util.promisify.custom")}),Yt=pe((u,e)=>{le(),ce(),ue();var{ArrayIsArray:t,ArrayPrototypeIncludes:n,ArrayPrototypeJoin:l,ArrayPrototypeMap:r,NumberIsInteger:i,NumberIsNaN:o,NumberMAX_SAFE_INTEGER:s,NumberMIN_SAFE_INTEGER:a,NumberParseInt:c,ObjectPrototypeHasOwnProperty:d,RegExpPrototypeExec:p,String:y,StringPrototypeToUpperCase:f,StringPrototypeTrim:m}=Re(),{hideStackFrames:b,codes:{ERR_SOCKET_BAD_PORT:_,ERR_INVALID_ARG_TYPE:g,ERR_INVALID_ARG_VALUE:S,ERR_OUT_OF_RANGE:x,ERR_UNKNOWN_SIGNAL:v}}=We(),{normalizeEncoding:E}=qe(),{isAsyncFunction:k,isArrayBufferView:I}=qe().types,M={};function O(q){return q===(q|0)}function B(q){return q===q>>>0}var T=/^[0-7]+$/,W="must be a 32-bit unsigned integer or an octal string";function F(q,ge,ve){if(typeof q>"u"&&(q=ve),typeof q=="string"){if(p(T,q)===null)throw new S(ge,q,W);q=c(q,8)}return Y(q,ge),q}var N=b((q,ge,ve=a,oe=s)=>{if(typeof q!="number")throw new g(ge,"number",q);if(!i(q))throw new x(ge,"an integer",q);if(q<ve||q>oe)throw new x(ge,`>= ${ve} && <= ${oe}`,q)}),ae=b((q,ge,ve=-2147483648,oe=2147483647)=>{if(typeof q!="number")throw new g(ge,"number",q);if(!i(q))throw new x(ge,"an integer",q);if(q<ve||q>oe)throw new x(ge,`>= ${ve} && <= ${oe}`,q)}),Y=b((q,ge,ve=!1)=>{if(typeof q!="number")throw new g(ge,"number",q);if(!i(q))throw new x(ge,"an integer",q);let oe=ve?1:0,Te=4294967295;if(q<oe||q>Te)throw new x(ge,`>= ${oe} && <= ${Te}`,q)});function K(q,ge){if(typeof q!="string")throw new g(ge,"string",q)}function re(q,ge,ve=void 0,oe){if(typeof q!="number")throw new g(ge,"number",q);if(ve!=null&&q<ve||oe!=null&&q>oe||(ve!=null||oe!=null)&&o(q))throw new x(ge,`${ve!=null?`>= ${ve}`:""}${ve!=null&&oe!=null?" && ":""}${oe!=null?`<= ${oe}`:""}`,q)}var D=b((q,ge,ve)=>{if(!n(ve,q)){let oe="must be one of: "+l(r(ve,Te=>typeof Te=="string"?`'${Te}'`:y(Te)),", ");throw new S(ge,q,oe)}});function Z(q,ge){if(typeof q!="boolean")throw new g(ge,"boolean",q)}function P(q,ge,ve){return q==null||!d(q,ge)?ve:q[ge]}var J=b((q,ge,ve=null)=>{let oe=P(ve,"allowArray",!1),Te=P(ve,"allowFunction",!1);if(!P(ve,"nullable",!1)&&q===null||!oe&&t(q)||typeof q!="object"&&(!Te||typeof q!="function"))throw new g(ge,"Object",q)}),be=b((q,ge)=>{if(q!=null&&typeof q!="object"&&typeof q!="function")throw new g(ge,"a dictionary",q)}),te=b((q,ge,ve=0)=>{if(!t(q))throw new g(ge,"Array",q);if(q.length<ve){let oe=`must be longer than ${ve}`;throw new S(ge,q,oe)}});function we(q,ge){te(q,ge);for(let ve=0;ve<q.length;ve++)K(q[ve],`${ge}[${ve}]`)}function V(q,ge){te(q,ge);for(let ve=0;ve<q.length;ve++)Z(q[ve],`${ge}[${ve}]`)}function L(q,ge){te(q,ge);for(let ve=0;ve<q.length;ve++){let oe=q[ve],Te=`${ge}[${ve}]`;if(oe==null)throw new g(Te,"AbortSignal",oe);me(oe,Te)}}function ne(q,ge="signal"){if(K(q,ge),M[q]===void 0)throw M[f(q)]!==void 0?new v(q+" (signals must use all capital letters)"):new v(q)}var H=b((q,ge="buffer")=>{if(!I(q))throw new g(ge,["Buffer","TypedArray","DataView"],q)});function G(q,ge){let ve=E(ge),oe=q.length;if(ve==="hex"&&oe%2!==0)throw new S("encoding",ge,`is invalid for data of length ${oe}`)}function Q(q,ge="Port",ve=!0){if(typeof q!="number"&&typeof q!="string"||typeof q=="string"&&m(q).length===0||+q!==+q>>>0||q>65535||q===0&&!ve)throw new _(ge,q,ve);return q|0}var me=b((q,ge)=>{if(q!==void 0&&(q===null||typeof q!="object"||!("aborted"in q)))throw new g(ge,"AbortSignal",q)}),se=b((q,ge)=>{if(typeof q!="function")throw new g(ge,"Function",q)}),R=b((q,ge)=>{if(typeof q!="function"||k(q))throw new g(ge,"Function",q)}),$=b((q,ge)=>{if(q!==void 0)throw new g(ge,"undefined",q)});function ee(q,ge,ve){if(!n(ve,q))throw new g(ge,`('${l(ve,"|")}')`,q)}var fe=/^(?:<[^>]*>)(?:\s*;\s*[^;"\s]+(?:=(")?[^;"\s]*\1)?)*$/;function de(q,ge){if(typeof q>"u"||!p(fe,q))throw new S(ge,q,'must be an array or string of format "</styles.css>; rel=preload; as=style"')}function ye(q){if(typeof q=="string")return de(q,"hints"),q;if(t(q)){let ge=q.length,ve="";if(ge===0)return ve;for(let oe=0;oe<ge;oe++){let Te=q[oe];de(Te,"hints"),ve+=Te,oe!==ge-1&&(ve+=", ")}return ve}throw new S("hints",q,'must be an array or string of format "</styles.css>; rel=preload; as=style"')}e.exports={isInt32:O,isUint32:B,parseFileMode:F,validateArray:te,validateStringArray:we,validateBooleanArray:V,validateAbortSignalArray:L,validateBoolean:Z,validateBuffer:H,validateDictionary:be,validateEncoding:G,validateFunction:se,validateInt32:ae,validateInteger:N,validateNumber:re,validateObject:J,validateOneOf:D,validatePlainFunction:R,validatePort:Q,validateSignalName:ne,validateString:K,validateUint32:Y,validateUndefined:$,validateUnion:ee,validateAbortSignal:me,validateLinkHeaderValue:ye}}),xt=pe((u,e)=>{le(),ce(),ue();var t=e.exports={},n,l;function r(){throw new Error("setTimeout has not been defined")}function i(){throw new Error("clearTimeout has not been defined")}(function(){try{typeof setTimeout=="function"?n=setTimeout:n=r}catch{n=r}try{typeof clearTimeout=="function"?l=clearTimeout:l=i}catch{l=i}})();function o(_){if(n===setTimeout)return setTimeout(_,0);if((n===r||!n)&&setTimeout)return n=setTimeout,setTimeout(_,0);try{return n(_,0)}catch{try{return n.call(null,_,0)}catch{return n.call(this,_,0)}}}function s(_){if(l===clearTimeout)return clearTimeout(_);if((l===i||!l)&&clearTimeout)return l=clearTimeout,clearTimeout(_);try{return l(_)}catch{try{return l.call(null,_)}catch{return l.call(this,_)}}}var a=[],c=!1,d,p=-1;function y(){!c||!d||(c=!1,d.length?a=d.concat(a):p=-1,a.length&&f())}function f(){if(!c){var _=o(y);c=!0;for(var g=a.length;g;){for(d=a,a=[];++p<g;)d&&d[p].run();p=-1,g=a.length}d=null,c=!1,s(_)}}t.nextTick=function(_){var g=new Array(arguments.length-1);if(arguments.length>1)for(var S=1;S<arguments.length;S++)g[S-1]=arguments[S];a.push(new m(_,g)),a.length===1&&!c&&o(f)};function m(_,g){this.fun=_,this.array=g}m.prototype.run=function(){this.fun.apply(null,this.array)},t.title="browser",t.browser=!0,t.env={},t.argv=[],t.version="",t.versions={};function b(){}t.on=b,t.addListener=b,t.once=b,t.off=b,t.removeListener=b,t.removeAllListeners=b,t.emit=b,t.prependListener=b,t.prependOnceListener=b,t.listeners=function(_){return[]},t.binding=function(_){throw new Error("process.binding is not supported")},t.cwd=function(){return"/"},t.chdir=function(_){throw new Error("process.chdir is not supported")},t.umask=function(){return 0}}),lt=pe((u,e)=>{le(),ce(),ue();var{SymbolAsyncIterator:t,SymbolIterator:n,SymbolFor:l}=Re(),r=l("nodejs.stream.destroyed"),i=l("nodejs.stream.errored"),o=l("nodejs.stream.readable"),s=l("nodejs.stream.writable"),a=l("nodejs.stream.disturbed"),c=l("nodejs.webstream.isClosedPromise"),d=l("nodejs.webstream.controllerErrorFunction");function p(P,J=!1){var be;return!!(P&&typeof P.pipe=="function"&&typeof P.on=="function"&&(!J||typeof P.pause=="function"&&typeof P.resume=="function")&&(!P._writableState||((be=P._readableState)===null||be===void 0?void 0:be.readable)!==!1)&&(!P._writableState||P._readableState))}function y(P){var J;return!!(P&&typeof P.write=="function"&&typeof P.on=="function"&&(!P._readableState||((J=P._writableState)===null||J===void 0?void 0:J.writable)!==!1))}function f(P){return!!(P&&typeof P.pipe=="function"&&P._readableState&&typeof P.on=="function"&&typeof P.write=="function")}function m(P){return P&&(P._readableState||P._writableState||typeof P.write=="function"&&typeof P.on=="function"||typeof P.pipe=="function"&&typeof P.on=="function")}function b(P){return!!(P&&!m(P)&&typeof P.pipeThrough=="function"&&typeof P.getReader=="function"&&typeof P.cancel=="function")}function _(P){return!!(P&&!m(P)&&typeof P.getWriter=="function"&&typeof P.abort=="function")}function g(P){return!!(P&&!m(P)&&typeof P.readable=="object"&&typeof P.writable=="object")}function S(P){return b(P)||_(P)||g(P)}function x(P,J){return P==null?!1:J===!0?typeof P[t]=="function":J===!1?typeof P[n]=="function":typeof P[t]=="function"||typeof P[n]=="function"}function v(P){if(!m(P))return null;let J=P._writableState,be=P._readableState,te=J||be;return!!(P.destroyed||P[r]||te!=null&&te.destroyed)}function E(P){if(!y(P))return null;if(P.writableEnded===!0)return!0;let J=P._writableState;return J!=null&&J.errored?!1:typeof J?.ended!="boolean"?null:J.ended}function k(P,J){if(!y(P))return null;if(P.writableFinished===!0)return!0;let be=P._writableState;return be!=null&&be.errored?!1:typeof be?.finished!="boolean"?null:!!(be.finished||J===!1&&be.ended===!0&&be.length===0)}function I(P){if(!p(P))return null;if(P.readableEnded===!0)return!0;let J=P._readableState;return!J||J.errored?!1:typeof J?.ended!="boolean"?null:J.ended}function M(P,J){if(!p(P))return null;let be=P._readableState;return be!=null&&be.errored?!1:typeof be?.endEmitted!="boolean"?null:!!(be.endEmitted||J===!1&&be.ended===!0&&be.length===0)}function O(P){return P&&P[o]!=null?P[o]:typeof P?.readable!="boolean"?null:v(P)?!1:p(P)&&P.readable&&!M(P)}function B(P){return P&&P[s]!=null?P[s]:typeof P?.writable!="boolean"?null:v(P)?!1:y(P)&&P.writable&&!E(P)}function T(P,J){return m(P)?v(P)?!0:!(J?.readable!==!1&&O(P)||J?.writable!==!1&&B(P)):null}function W(P){var J,be;return m(P)?P.writableErrored?P.writableErrored:(J=(be=P._writableState)===null||be===void 0?void 0:be.errored)!==null&&J!==void 0?J:null:null}function F(P){var J,be;return m(P)?P.readableErrored?P.readableErrored:(J=(be=P._readableState)===null||be===void 0?void 0:be.errored)!==null&&J!==void 0?J:null:null}function N(P){if(!m(P))return null;if(typeof P.closed=="boolean")return P.closed;let J=P._writableState,be=P._readableState;return typeof J?.closed=="boolean"||typeof be?.closed=="boolean"?J?.closed||be?.closed:typeof P._closed=="boolean"&&ae(P)?P._closed:null}function ae(P){return typeof P._closed=="boolean"&&typeof P._defaultKeepAlive=="boolean"&&typeof P._removedConnection=="boolean"&&typeof P._removedContLen=="boolean"}function Y(P){return typeof P._sent100=="boolean"&&ae(P)}function K(P){var J;return typeof P._consuming=="boolean"&&typeof P._dumped=="boolean"&&((J=P.req)===null||J===void 0?void 0:J.upgradeOrConnect)===void 0}function re(P){if(!m(P))return null;let J=P._writableState,be=P._readableState,te=J||be;return!te&&Y(P)||!!(te&&te.autoDestroy&&te.emitClose&&te.closed===!1)}function D(P){var J;return!!(P&&((J=P[a])!==null&&J!==void 0?J:P.readableDidRead||P.readableAborted))}function Z(P){var J,be,te,we,V,L,ne,H,G,Q;return!!(P&&((J=(be=(te=(we=(V=(L=P[i])!==null&&L!==void 0?L:P.readableErrored)!==null&&V!==void 0?V:P.writableErrored)!==null&&we!==void 0?we:(ne=P._readableState)===null||ne===void 0?void 0:ne.errorEmitted)!==null&&te!==void 0?te:(H=P._writableState)===null||H===void 0?void 0:H.errorEmitted)!==null&&be!==void 0?be:(G=P._readableState)===null||G===void 0?void 0:G.errored)!==null&&J!==void 0?J:!((Q=P._writableState)===null||Q===void 0)&&Q.errored))}e.exports={isDestroyed:v,kIsDestroyed:r,isDisturbed:D,kIsDisturbed:a,isErrored:Z,kIsErrored:i,isReadable:O,kIsReadable:o,kIsClosedPromise:c,kControllerErrorFunction:d,kIsWritable:s,isClosed:N,isDuplexNodeStream:f,isFinished:T,isIterable:x,isReadableNodeStream:p,isReadableStream:b,isReadableEnded:I,isReadableFinished:M,isReadableErrored:F,isNodeStream:m,isWebStream:S,isWritable:B,isWritableNodeStream:y,isWritableStream:_,isWritableEnded:E,isWritableFinished:k,isWritableErrored:W,isServerRequest:K,isServerResponse:Y,willEmitClose:re,isTransformStream:g}}),bt=pe((u,e)=>{le(),ce(),ue();var t=xt(),{AbortError:n,codes:l}=We(),{ERR_INVALID_ARG_TYPE:r,ERR_STREAM_PREMATURE_CLOSE:i}=l,{kEmptyObject:o,once:s}=qe(),{validateAbortSignal:a,validateFunction:c,validateObject:d,validateBoolean:p}=Yt(),{Promise:y,PromisePrototypeThen:f,SymbolDispose:m}=Re(),{isClosed:b,isReadable:_,isReadableNodeStream:g,isReadableStream:S,isReadableFinished:x,isReadableErrored:v,isWritable:E,isWritableNodeStream:k,isWritableStream:I,isWritableFinished:M,isWritableErrored:O,isNodeStream:B,willEmitClose:T,kIsClosedPromise:W}=lt(),F;function N(D){return D.setHeader&&typeof D.abort=="function"}var ae=()=>{};function Y(D,Z,P){var J,be;if(arguments.length===2?(P=Z,Z=o):Z==null?Z=o:d(Z,"options"),c(P,"callback"),a(Z.signal,"options.signal"),P=s(P),S(D)||I(D))return K(D,Z,P);if(!B(D))throw new r("stream",["ReadableStream","WritableStream","Stream"],D);let te=(J=Z.readable)!==null&&J!==void 0?J:g(D),we=(be=Z.writable)!==null&&be!==void 0?be:k(D),V=D._writableState,L=D._readableState,ne=()=>{D.writable||Q()},H=T(D)&&g(D)===te&&k(D)===we,G=M(D,!1),Q=()=>{G=!0,D.destroyed&&(H=!1),!(H&&(!D.readable||te))&&(!te||me)&&P.call(D)},me=x(D,!1),se=()=>{me=!0,D.destroyed&&(H=!1),!(H&&(!D.writable||we))&&(!we||G)&&P.call(D)},R=q=>{P.call(D,q)},$=b(D),ee=()=>{$=!0;let q=O(D)||v(D);if(q&&typeof q!="boolean")return P.call(D,q);if(te&&!me&&g(D,!0)&&!x(D,!1))return P.call(D,new i);if(we&&!G&&!M(D,!1))return P.call(D,new i);P.call(D)},fe=()=>{$=!0;let q=O(D)||v(D);if(q&&typeof q!="boolean")return P.call(D,q);P.call(D)},de=()=>{D.req.on("finish",Q)};N(D)?(D.on("complete",Q),H||D.on("abort",ee),D.req?de():D.on("request",de)):we&&!V&&(D.on("end",ne),D.on("close",ne)),!H&&typeof D.aborted=="boolean"&&D.on("aborted",ee),D.on("end",se),D.on("finish",Q),Z.error!==!1&&D.on("error",R),D.on("close",ee),$?t.nextTick(ee):V!=null&&V.errorEmitted||L!=null&&L.errorEmitted?H||t.nextTick(fe):(!te&&(!H||_(D))&&(G||E(D)===!1)||!we&&(!H||E(D))&&(me||_(D)===!1)||L&&D.req&&D.aborted)&&t.nextTick(fe);let ye=()=>{P=ae,D.removeListener("aborted",ee),D.removeListener("complete",Q),D.removeListener("abort",ee),D.removeListener("request",de),D.req&&D.req.removeListener("finish",Q),D.removeListener("end",ne),D.removeListener("close",ne),D.removeListener("finish",Q),D.removeListener("end",se),D.removeListener("error",R),D.removeListener("close",ee)};if(Z.signal&&!$){let q=()=>{let ge=P;ye(),ge.call(D,new n(void 0,{cause:Z.signal.reason}))};if(Z.signal.aborted)t.nextTick(q);else{F=F||qe().addAbortListener;let ge=F(Z.signal,q),ve=P;P=s((...oe)=>{ge[m](),ve.apply(D,oe)})}}return ye}function K(D,Z,P){let J=!1,be=ae;if(Z.signal)if(be=()=>{J=!0,P.call(D,new n(void 0,{cause:Z.signal.reason}))},Z.signal.aborted)t.nextTick(be);else{F=F||qe().addAbortListener;let we=F(Z.signal,be),V=P;P=s((...L)=>{we[m](),V.apply(D,L)})}let te=(...we)=>{J||t.nextTick(()=>P.apply(D,we))};return f(D[W].promise,te,te),ae}function re(D,Z){var P;let J=!1;return Z===null&&(Z=o),(P=Z)!==null&&P!==void 0&&P.cleanup&&(p(Z.cleanup,"cleanup"),J=Z.cleanup),new y((be,te)=>{let we=Y(D,Z,V=>{J&&we(),V?te(V):be()})})}e.exports=Y,e.exports.finished=re}),Lt=pe((u,e)=>{le(),ce(),ue();var t=xt(),{aggregateTwoErrors:n,codes:{ERR_MULTIPLE_CALLBACK:l},AbortError:r}=We(),{Symbol:i}=Re(),{kIsDestroyed:o,isDestroyed:s,isFinished:a,isServerRequest:c}=lt(),d=i("kDestroy"),p=i("kConstruct");function y(T,W,F){T&&(T.stack,W&&!W.errored&&(W.errored=T),F&&!F.errored&&(F.errored=T))}function f(T,W){let F=this._readableState,N=this._writableState,ae=N||F;return N!=null&&N.destroyed||F!=null&&F.destroyed?(typeof W=="function"&&W(),this):(y(T,N,F),N&&(N.destroyed=!0),F&&(F.destroyed=!0),ae.constructed?m(this,T,W):this.once(d,function(Y){m(this,n(Y,T),W)}),this)}function m(T,W,F){let N=!1;function ae(Y){if(N)return;N=!0;let K=T._readableState,re=T._writableState;y(Y,re,K),re&&(re.closed=!0),K&&(K.closed=!0),typeof F=="function"&&F(Y),Y?t.nextTick(b,T,Y):t.nextTick(_,T)}try{T._destroy(W||null,ae)}catch(Y){ae(Y)}}function b(T,W){g(T,W),_(T)}function _(T){let W=T._readableState,F=T._writableState;F&&(F.closeEmitted=!0),W&&(W.closeEmitted=!0),(F!=null&&F.emitClose||W!=null&&W.emitClose)&&T.emit("close")}function g(T,W){let F=T._readableState,N=T._writableState;N!=null&&N.errorEmitted||F!=null&&F.errorEmitted||(N&&(N.errorEmitted=!0),F&&(F.errorEmitted=!0),T.emit("error",W))}function S(){let T=this._readableState,W=this._writableState;T&&(T.constructed=!0,T.closed=!1,T.closeEmitted=!1,T.destroyed=!1,T.errored=null,T.errorEmitted=!1,T.reading=!1,T.ended=T.readable===!1,T.endEmitted=T.readable===!1),W&&(W.constructed=!0,W.destroyed=!1,W.closed=!1,W.closeEmitted=!1,W.errored=null,W.errorEmitted=!1,W.finalCalled=!1,W.prefinished=!1,W.ended=W.writable===!1,W.ending=W.writable===!1,W.finished=W.writable===!1)}function x(T,W,F){let N=T._readableState,ae=T._writableState;if(ae!=null&&ae.destroyed||N!=null&&N.destroyed)return this;N!=null&&N.autoDestroy||ae!=null&&ae.autoDestroy?T.destroy(W):W&&(W.stack,ae&&!ae.errored&&(ae.errored=W),N&&!N.errored&&(N.errored=W),F?t.nextTick(g,T,W):g(T,W))}function v(T,W){if(typeof T._construct!="function")return;let F=T._readableState,N=T._writableState;F&&(F.constructed=!1),N&&(N.constructed=!1),T.once(p,W),!(T.listenerCount(p)>1)&&t.nextTick(E,T)}function E(T){let W=!1;function F(N){if(W){x(T,N??new l);return}W=!0;let ae=T._readableState,Y=T._writableState,K=Y||ae;ae&&(ae.constructed=!0),Y&&(Y.constructed=!0),K.destroyed?T.emit(d,N):N?x(T,N,!0):t.nextTick(k,T)}try{T._construct(N=>{t.nextTick(F,N)})}catch(N){t.nextTick(F,N)}}function k(T){T.emit(p)}function I(T){return T?.setHeader&&typeof T.abort=="function"}function M(T){T.emit("close")}function O(T,W){T.emit("error",W),t.nextTick(M,T)}function B(T,W){!T||s(T)||(!W&&!a(T)&&(W=new r),c(T)?(T.socket=null,T.destroy(W)):I(T)?T.abort():I(T.req)?T.req.abort():typeof T.destroy=="function"?T.destroy(W):typeof T.close=="function"?T.close():W?t.nextTick(O,T,W):t.nextTick(M,T),T.destroyed||(T[o]=!0))}e.exports={construct:v,destroyer:B,destroy:f,undestroy:S,errorOrDestroy:x}}),Qi=pe((u,e)=>{le(),ce(),ue();var{ArrayIsArray:t,ObjectSetPrototypeOf:n}=Re(),{EventEmitter:l}=(Et(),Oe(mt));function r(o){l.call(this,o)}n(r.prototype,l.prototype),n(r,l),r.prototype.pipe=function(o,s){let a=this;function c(_){o.writable&&o.write(_)===!1&&a.pause&&a.pause()}a.on("data",c);function d(){a.readable&&a.resume&&a.resume()}o.on("drain",d),!o._isStdio&&(!s||s.end!==!1)&&(a.on("end",y),a.on("close",f));let p=!1;function y(){p||(p=!0,o.end())}function f(){p||(p=!0,typeof o.destroy=="function"&&o.destroy())}function m(_){b(),l.listenerCount(this,"error")===0&&this.emit("error",_)}i(a,"error",m),i(o,"error",m);function b(){a.removeListener("data",c),o.removeListener("drain",d),a.removeListener("end",y),a.removeListener("close",f),a.removeListener("error",m),o.removeListener("error",m),a.removeListener("end",b),a.removeListener("close",b),o.removeListener("close",b)}return a.on("end",b),a.on("close",b),o.on("close",b),o.emit("pipe",a),o};function i(o,s,a){if(typeof o.prependListener=="function")return o.prependListener(s,a);!o._events||!o._events[s]?o.on(s,a):t(o._events[s])?o._events[s].unshift(a):o._events[s]=[a,o._events[s]]}e.exports={Stream:r,prependListener:i}}),Pr=pe((u,e)=>{le(),ce(),ue();var{SymbolDispose:t}=Re(),{AbortError:n,codes:l}=We(),{isNodeStream:r,isWebStream:i,kControllerErrorFunction:o}=lt(),s=bt(),{ERR_INVALID_ARG_TYPE:a}=l,c,d=(p,y)=>{if(typeof p!="object"||!("aborted"in p))throw new a(y,"AbortSignal",p)};e.exports.addAbortSignal=function(p,y){if(d(p,"signal"),!r(y)&&!i(y))throw new a("stream",["ReadableStream","WritableStream","Stream"],y);return e.exports.addAbortSignalNoValidate(p,y)},e.exports.addAbortSignalNoValidate=function(p,y){if(typeof p!="object"||!("aborted"in p))return y;let f=r(y)?()=>{y.destroy(new n(void 0,{cause:p.reason}))}:()=>{y[o](new n(void 0,{cause:p.reason}))};if(p.aborted)f();else{c=c||qe().addAbortListener;let m=c(p,f);s(y,m[t])}return y}}),au=pe((u,e)=>{le(),ce(),ue();var{StringPrototypeSlice:t,SymbolIterator:n,TypedArrayPrototypeSet:l,Uint8Array:r}=Re(),{Buffer:i}=(Ne(),Oe(Le)),{inspect:o}=qe();e.exports=class{constructor(){this.head=null,this.tail=null,this.length=0}push(s){let a={data:s,next:null};this.length>0?this.tail.next=a:this.head=a,this.tail=a,++this.length}unshift(s){let a={data:s,next:this.head};this.length===0&&(this.tail=a),this.head=a,++this.length}shift(){if(this.length===0)return;let s=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,s}clear(){this.head=this.tail=null,this.length=0}join(s){if(this.length===0)return"";let a=this.head,c=""+a.data;for(;(a=a.next)!==null;)c+=s+a.data;return c}concat(s){if(this.length===0)return i.alloc(0);let a=i.allocUnsafe(s>>>0),c=this.head,d=0;for(;c;)l(a,c.data,d),d+=c.data.length,c=c.next;return a}consume(s,a){let c=this.head.data;if(s<c.length){let d=c.slice(0,s);return this.head.data=c.slice(s),d}return s===c.length?this.shift():a?this._getString(s):this._getBuffer(s)}first(){return this.head.data}*[n](){for(let s=this.head;s;s=s.next)yield s.data}_getString(s){let a="",c=this.head,d=0;do{let p=c.data;if(s>p.length)a+=p,s-=p.length;else{s===p.length?(a+=p,++d,c.next?this.head=c.next:this.head=this.tail=null):(a+=t(p,0,s),this.head=c,c.data=t(p,s));break}++d}while((c=c.next)!==null);return this.length-=d,a}_getBuffer(s){let a=i.allocUnsafe(s),c=s,d=this.head,p=0;do{let y=d.data;if(s>y.length)l(a,y,c-s),s-=y.length;else{s===y.length?(l(a,y,c-s),++p,d.next?this.head=d.next:this.head=this.tail=null):(l(a,new r(y.buffer,y.byteOffset,s),c-s),this.head=d,d.data=y.slice(s));break}++p}while((d=d.next)!==null);return this.length-=p,a}[Symbol.for("nodejs.util.inspect.custom")](s,a){return o(this,{...a,depth:0,customInspect:!1})}}}),Mr=pe((u,e)=>{le(),ce(),ue();var{MathFloor:t,NumberIsInteger:n}=Re(),{validateInteger:l}=Yt(),{ERR_INVALID_ARG_VALUE:r}=We().codes,i=16*1024,o=16;function s(p,y,f){return p.highWaterMark!=null?p.highWaterMark:y?p[f]:null}function a(p){return p?o:i}function c(p,y){l(y,"value",0),p?o=y:i=y}function d(p,y,f,m){let b=s(y,m,f);if(b!=null){if(!n(b)||b<0){let _=m?`options.${f}`:"options.highWaterMark";throw new r(_,b)}return t(b)}return a(p.objectMode)}e.exports={getHighWaterMark:d,getDefaultHighWaterMark:a,setDefaultHighWaterMark:c}}),lu=pe((u,e)=>{le(),ce(),ue();var t=(Ne(),Oe(Le)),n=t.Buffer;function l(i,o){for(var s in i)o[s]=i[s]}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?e.exports=t:(l(t,u),u.Buffer=r);function r(i,o,s){return n(i,o,s)}r.prototype=Object.create(n.prototype),l(n,r),r.from=function(i,o,s){if(typeof i=="number")throw new TypeError("Argument must not be a number");return n(i,o,s)},r.alloc=function(i,o,s){if(typeof i!="number")throw new TypeError("Argument must be a number");var a=n(i);return o!==void 0?typeof s=="string"?a.fill(o,s):a.fill(o):a.fill(0),a},r.allocUnsafe=function(i){if(typeof i!="number")throw new TypeError("Argument must be a number");return n(i)},r.allocUnsafeSlow=function(i){if(typeof i!="number")throw new TypeError("Argument must be a number");return t.SlowBuffer(i)}}),uu=pe(u=>{le(),ce(),ue();var e=lu().Buffer,t=e.isEncoding||function(g){switch(g=""+g,g&&g.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function n(g){if(!g)return"utf8";for(var S;;)switch(g){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return g;default:if(S)return;g=(""+g).toLowerCase(),S=!0}}function l(g){var S=n(g);if(typeof S!="string"&&(e.isEncoding===t||!t(g)))throw new Error("Unknown encoding: "+g);return S||g}u.StringDecoder=r;function r(g){this.encoding=l(g);var S;switch(this.encoding){case"utf16le":this.text=p,this.end=y,S=4;break;case"utf8":this.fillLast=a,S=4;break;case"base64":this.text=f,this.end=m,S=3;break;default:this.write=b,this.end=_;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=e.allocUnsafe(S)}r.prototype.write=function(g){if(g.length===0)return"";var S,x;if(this.lastNeed){if(S=this.fillLast(g),S===void 0)return"";x=this.lastNeed,this.lastNeed=0}else x=0;return x<g.length?S?S+this.text(g,x):this.text(g,x):S||""},r.prototype.end=d,r.prototype.text=c,r.prototype.fillLast=function(g){if(this.lastNeed<=g.length)return g.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);g.copy(this.lastChar,this.lastTotal-this.lastNeed,0,g.length),this.lastNeed-=g.length};function i(g){return g<=127?0:g>>5===6?2:g>>4===14?3:g>>3===30?4:g>>6===2?-1:-2}function o(g,S,x){var v=S.length-1;if(v<x)return 0;var E=i(S[v]);return E>=0?(E>0&&(g.lastNeed=E-1),E):--v<x||E===-2?0:(E=i(S[v]),E>=0?(E>0&&(g.lastNeed=E-2),E):--v<x||E===-2?0:(E=i(S[v]),E>=0?(E>0&&(E===2?E=0:g.lastNeed=E-3),E):0))}function s(g,S,x){if((S[0]&192)!==128)return g.lastNeed=0,"�";if(g.lastNeed>1&&S.length>1){if((S[1]&192)!==128)return g.lastNeed=1,"�";if(g.lastNeed>2&&S.length>2&&(S[2]&192)!==128)return g.lastNeed=2,"�"}}function a(g){var S=this.lastTotal-this.lastNeed,x=s(this,g);if(x!==void 0)return x;if(this.lastNeed<=g.length)return g.copy(this.lastChar,S,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);g.copy(this.lastChar,S,0,g.length),this.lastNeed-=g.length}function c(g,S){var x=o(this,g,S);if(!this.lastNeed)return g.toString("utf8",S);this.lastTotal=x;var v=g.length-(x-this.lastNeed);return g.copy(this.lastChar,0,v),g.toString("utf8",S,v)}function d(g){var S=g&&g.length?this.write(g):"";return this.lastNeed?S+"�":S}function p(g,S){if((g.length-S)%2===0){var x=g.toString("utf16le",S);if(x){var v=x.charCodeAt(x.length-1);if(v>=55296&&v<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=g[g.length-2],this.lastChar[1]=g[g.length-1],x.slice(0,-1)}return x}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=g[g.length-1],g.toString("utf16le",S,g.length-1)}function y(g){var S=g&&g.length?this.write(g):"";if(this.lastNeed){var x=this.lastTotal-this.lastNeed;return S+this.lastChar.toString("utf16le",0,x)}return S}function f(g,S){var x=(g.length-S)%3;return x===0?g.toString("base64",S):(this.lastNeed=3-x,this.lastTotal=3,x===1?this.lastChar[0]=g[g.length-1]:(this.lastChar[0]=g[g.length-2],this.lastChar[1]=g[g.length-1]),g.toString("base64",S,g.length-x))}function m(g){var S=g&&g.length?this.write(g):"";return this.lastNeed?S+this.lastChar.toString("base64",0,3-this.lastNeed):S}function b(g){return g.toString(this.encoding)}function _(g){return g&&g.length?this.write(g):""}}),Jo=pe((u,e)=>{le(),ce(),ue();var t=xt(),{PromisePrototypeThen:n,SymbolAsyncIterator:l,SymbolIterator:r}=Re(),{Buffer:i}=(Ne(),Oe(Le)),{ERR_INVALID_ARG_TYPE:o,ERR_STREAM_NULL_VALUES:s}=We().codes;function a(c,d,p){let y;if(typeof d=="string"||d instanceof i)return new c({objectMode:!0,...p,read(){this.push(d),this.push(null)}});let f;if(d&&d[l])f=!0,y=d[l]();else if(d&&d[r])f=!1,y=d[r]();else throw new o("iterable",["Iterable"],d);let m=new c({objectMode:!0,highWaterMark:1,...p}),b=!1;m._read=function(){b||(b=!0,g())},m._destroy=function(S,x){n(_(S),()=>t.nextTick(x,S),v=>t.nextTick(x,v||S))};async function _(S){let x=S!=null,v=typeof y.throw=="function";if(x&&v){let{value:E,done:k}=await y.throw(S);if(await E,k)return}if(typeof y.return=="function"){let{value:E}=await y.return();await E}}async function g(){for(;;){try{let{value:S,done:x}=f?await y.next():y.next();if(x)m.push(null);else{let v=S&&typeof S.then=="function"?await S:S;if(v===null)throw b=!1,new s;if(m.push(v))continue;b=!1}}catch(S){m.destroy(S)}break}}return m}e.exports=a}),Rr=pe((u,e)=>{le(),ce(),ue();var t=xt(),{ArrayPrototypeIndexOf:n,NumberIsInteger:l,NumberIsNaN:r,NumberParseInt:i,ObjectDefineProperties:o,ObjectKeys:s,ObjectSetPrototypeOf:a,Promise:c,SafeSet:d,SymbolAsyncDispose:p,SymbolAsyncIterator:y,Symbol:f}=Re();e.exports=oe,oe.ReadableState=ve;var{EventEmitter:m}=(Et(),Oe(mt)),{Stream:b,prependListener:_}=Qi(),{Buffer:g}=(Ne(),Oe(Le)),{addAbortSignal:S}=Pr(),x=bt(),v=qe().debuglog("stream",C=>{v=C}),E=au(),k=Lt(),{getHighWaterMark:I,getDefaultHighWaterMark:M}=Mr(),{aggregateTwoErrors:O,codes:{ERR_INVALID_ARG_TYPE:B,ERR_METHOD_NOT_IMPLEMENTED:T,ERR_OUT_OF_RANGE:W,ERR_STREAM_PUSH_AFTER_EOF:F,ERR_STREAM_UNSHIFT_AFTER_END_EVENT:N},AbortError:ae}=We(),{validateObject:Y}=Yt(),K=f("kPaused"),{StringDecoder:re}=uu(),D=Jo();a(oe.prototype,b.prototype),a(oe,b);var Z=()=>{},{errorOrDestroy:P}=k,J=1,be=2,te=4,we=8,V=16,L=32,ne=64,H=128,G=256,Q=512,me=1024,se=2048,R=4096,$=8192,ee=16384,fe=32768,de=65536,ye=1<<17,q=1<<18;function ge(C){return{enumerable:!1,get(){return(this.state&C)!==0},set(j){j?this.state|=C:this.state&=~C}}}o(ve.prototype,{objectMode:ge(J),ended:ge(be),endEmitted:ge(te),reading:ge(we),constructed:ge(V),sync:ge(L),needReadable:ge(ne),emittedReadable:ge(H),readableListening:ge(G),resumeScheduled:ge(Q),errorEmitted:ge(me),emitClose:ge(se),autoDestroy:ge(R),destroyed:ge($),closed:ge(ee),closeEmitted:ge(fe),multiAwaitDrain:ge(de),readingMore:ge(ye),dataEmitted:ge(q)});function ve(C,j,_e){typeof _e!="boolean"&&(_e=j instanceof ot()),this.state=se|R|V|L,C&&C.objectMode&&(this.state|=J),_e&&C&&C.readableObjectMode&&(this.state|=J),this.highWaterMark=C?I(this,C,"readableHighWaterMark",_e):M(!1),this.buffer=new E,this.length=0,this.pipes=[],this.flowing=null,this[K]=null,C&&C.emitClose===!1&&(this.state&=~se),C&&C.autoDestroy===!1&&(this.state&=~R),this.errored=null,this.defaultEncoding=C&&C.defaultEncoding||"utf8",this.awaitDrainWriters=null,this.decoder=null,this.encoding=null,C&&C.encoding&&(this.decoder=new re(C.encoding),this.encoding=C.encoding)}function oe(C){if(!(this instanceof oe))return new oe(C);let j=this instanceof ot();this._readableState=new ve(C,this,j),C&&(typeof C.read=="function"&&(this._read=C.read),typeof C.destroy=="function"&&(this._destroy=C.destroy),typeof C.construct=="function"&&(this._construct=C.construct),C.signal&&!j&&S(C.signal,this)),b.call(this,C),k.construct(this,()=>{this._readableState.needReadable&&z(this,this._readableState)})}oe.prototype.destroy=k.destroy,oe.prototype._undestroy=k.undestroy,oe.prototype._destroy=function(C,j){j(C)},oe.prototype[m.captureRejectionSymbol]=function(C){this.destroy(C)},oe.prototype[p]=function(){let C;return this.destroyed||(C=this.readableEnded?null:new ae,this.destroy(C)),new c((j,_e)=>x(this,ke=>ke&&ke!==C?_e(ke):j(null)))},oe.prototype.push=function(C,j){return Te(this,C,j,!1)},oe.prototype.unshift=function(C,j){return Te(this,C,j,!0)};function Te(C,j,_e,ke){v("readableAddChunk",j);let Ee=C._readableState,je;if((Ee.state&J)===0&&(typeof j=="string"?(_e=_e||Ee.defaultEncoding,Ee.encoding!==_e&&(ke&&Ee.encoding?j=g.from(j,_e).toString(Ee.encoding):(j=g.from(j,_e),_e=""))):j instanceof g?_e="":b._isUint8Array(j)?(j=b._uint8ArrayToBuffer(j),_e=""):j!=null&&(je=new B("chunk",["string","Buffer","Uint8Array"],j))),je)P(C,je);else if(j===null)Ee.state&=~we,X(C,Ee);else if((Ee.state&J)!==0||j&&j.length>0)if(ke)if((Ee.state&te)!==0)P(C,new N);else{if(Ee.destroyed||Ee.errored)return!1;h(C,Ee,j,!0)}else if(Ee.ended)P(C,new F);else{if(Ee.destroyed||Ee.errored)return!1;Ee.state&=~we,Ee.decoder&&!_e?(j=Ee.decoder.write(j),Ee.objectMode||j.length!==0?h(C,Ee,j,!1):z(C,Ee)):h(C,Ee,j,!1)}else ke||(Ee.state&=~we,z(C,Ee));return!Ee.ended&&(Ee.length<Ee.highWaterMark||Ee.length===0)}function h(C,j,_e,ke){j.flowing&&j.length===0&&!j.sync&&C.listenerCount("data")>0?((j.state&de)!==0?j.awaitDrainWriters.clear():j.awaitDrainWriters=null,j.dataEmitted=!0,C.emit("data",_e)):(j.length+=j.objectMode?1:_e.length,ke?j.buffer.unshift(_e):j.buffer.push(_e),(j.state&ne)!==0&&he(C)),z(C,j)}oe.prototype.isPaused=function(){let C=this._readableState;return C[K]===!0||C.flowing===!1},oe.prototype.setEncoding=function(C){let j=new re(C);this._readableState.decoder=j,this._readableState.encoding=this._readableState.decoder.encoding;let _e=this._readableState.buffer,ke="";for(let Ee of _e)ke+=j.write(Ee);return _e.clear(),ke!==""&&_e.push(ke),this._readableState.length=ke.length,this};var w=1073741824;function A(C){if(C>w)throw new W("size","<= 1GiB",C);return C--,C|=C>>>1,C|=C>>>2,C|=C>>>4,C|=C>>>8,C|=C>>>16,C++,C}function U(C,j){return C<=0||j.length===0&&j.ended?0:(j.state&J)!==0?1:r(C)?j.flowing&&j.length?j.buffer.first().length:j.length:C<=j.length?C:j.ended?j.length:0}oe.prototype.read=function(C){v("read",C),C===void 0?C=NaN:l(C)||(C=i(C,10));let j=this._readableState,_e=C;if(C>j.highWaterMark&&(j.highWaterMark=A(C)),C!==0&&(j.state&=~H),C===0&&j.needReadable&&((j.highWaterMark!==0?j.length>=j.highWaterMark:j.length>0)||j.ended))return v("read: emitReadable",j.length,j.ended),j.length===0&&j.ended?Qe(this):he(this),null;if(C=U(C,j),C===0&&j.ended)return j.length===0&&Qe(this),null;let ke=(j.state&ne)!==0;if(v("need readable",ke),(j.length===0||j.length-C<j.highWaterMark)&&(ke=!0,v("length less than watermark",ke)),j.ended||j.reading||j.destroyed||j.errored||!j.constructed)ke=!1,v("reading, ended or constructing",ke);else if(ke){v("do read"),j.state|=we|L,j.length===0&&(j.state|=ne);try{this._read(j.highWaterMark)}catch(je){P(this,je)}j.state&=~L,j.reading||(C=U(_e,j))}let Ee;return C>0?Ee=It(C,j):Ee=null,Ee===null?(j.needReadable=j.length<=j.highWaterMark,C=0):(j.length-=C,j.multiAwaitDrain?j.awaitDrainWriters.clear():j.awaitDrainWriters=null),j.length===0&&(j.ended||(j.needReadable=!0),_e!==C&&j.ended&&Qe(this)),Ee!==null&&!j.errorEmitted&&!j.closeEmitted&&(j.dataEmitted=!0,this.emit("data",Ee)),Ee};function X(C,j){if(v("onEofChunk"),!j.ended){if(j.decoder){let _e=j.decoder.end();_e&&_e.length&&(j.buffer.push(_e),j.length+=j.objectMode?1:_e.length)}j.ended=!0,j.sync?he(C):(j.needReadable=!1,j.emittedReadable=!0,Se(C))}}function he(C){let j=C._readableState;v("emitReadable",j.needReadable,j.emittedReadable),j.needReadable=!1,j.emittedReadable||(v("emitReadable",j.flowing),j.emittedReadable=!0,t.nextTick(Se,C))}function Se(C){let j=C._readableState;v("emitReadable_",j.destroyed,j.length,j.ended),!j.destroyed&&!j.errored&&(j.length||j.ended)&&(C.emit("readable"),j.emittedReadable=!1),j.needReadable=!j.flowing&&!j.ended&&j.length<=j.highWaterMark,Ge(C)}function z(C,j){!j.readingMore&&j.constructed&&(j.readingMore=!0,t.nextTick(ie,C,j))}function ie(C,j){for(;!j.reading&&!j.ended&&(j.length<j.highWaterMark||j.flowing&&j.length===0);){let _e=j.length;if(v("maybeReadMore read 0"),C.read(0),_e===j.length)break}j.readingMore=!1}oe.prototype._read=function(C){throw new T("_read()")},oe.prototype.pipe=function(C,j){let _e=this,ke=this._readableState;ke.pipes.length===1&&(ke.multiAwaitDrain||(ke.multiAwaitDrain=!0,ke.awaitDrainWriters=new d(ke.awaitDrainWriters?[ke.awaitDrainWriters]:[]))),ke.pipes.push(C),v("pipe count=%d opts=%j",ke.pipes.length,j);let Ee=(!j||j.end!==!1)&&C!==t.stdout&&C!==t.stderr?$e:vt;ke.endEmitted?t.nextTick(Ee):_e.once("end",Ee),C.on("unpipe",je);function je(Xe,tt){v("onunpipe"),Xe===_e&&tt&&tt.hasUnpiped===!1&&(tt.hasUnpiped=!0,Dt())}function $e(){v("onend"),C.end()}let Ke,Ft=!1;function Dt(){v("cleanup"),C.removeListener("close",Je),C.removeListener("finish",ht),Ke&&C.removeListener("drain",Ke),C.removeListener("error",yt),C.removeListener("unpipe",je),_e.removeListener("end",$e),_e.removeListener("end",vt),_e.removeListener("data",Xt),Ft=!0,Ke&&ke.awaitDrainWriters&&(!C._writableState||C._writableState.needDrain)&&Ke()}function $t(){Ft||(ke.pipes.length===1&&ke.pipes[0]===C?(v("false write response, pause",0),ke.awaitDrainWriters=C,ke.multiAwaitDrain=!1):ke.pipes.length>1&&ke.pipes.includes(C)&&(v("false write response, pause",ke.awaitDrainWriters.size),ke.awaitDrainWriters.add(C)),_e.pause()),Ke||(Ke=xe(_e,C),C.on("drain",Ke))}_e.on("data",Xt);function Xt(Xe){v("ondata");let tt=C.write(Xe);v("dest.write",tt),tt===!1&&$t()}function yt(Xe){if(v("onerror",Xe),vt(),C.removeListener("error",yt),C.listenerCount("error")===0){let tt=C._writableState||C._readableState;tt&&!tt.errorEmitted?P(C,Xe):C.emit("error",Xe)}}_(C,"error",yt);function Je(){C.removeListener("finish",ht),vt()}C.once("close",Je);function ht(){v("onfinish"),C.removeListener("close",Je),vt()}C.once("finish",ht);function vt(){v("unpipe"),_e.unpipe(C)}return C.emit("pipe",_e),C.writableNeedDrain===!0?$t():ke.flowing||(v("pipe resume"),_e.resume()),C};function xe(C,j){return function(){let _e=C._readableState;_e.awaitDrainWriters===j?(v("pipeOnDrain",1),_e.awaitDrainWriters=null):_e.multiAwaitDrain&&(v("pipeOnDrain",_e.awaitDrainWriters.size),_e.awaitDrainWriters.delete(j)),(!_e.awaitDrainWriters||_e.awaitDrainWriters.size===0)&&C.listenerCount("data")&&C.resume()}}oe.prototype.unpipe=function(C){let j=this._readableState,_e={hasUnpiped:!1};if(j.pipes.length===0)return this;if(!C){let Ee=j.pipes;j.pipes=[],this.pause();for(let je=0;je<Ee.length;je++)Ee[je].emit("unpipe",this,{hasUnpiped:!1});return this}let ke=n(j.pipes,C);return ke===-1?this:(j.pipes.splice(ke,1),j.pipes.length===0&&this.pause(),C.emit("unpipe",this,_e),this)},oe.prototype.on=function(C,j){let _e=b.prototype.on.call(this,C,j),ke=this._readableState;return C==="data"?(ke.readableListening=this.listenerCount("readable")>0,ke.flowing!==!1&&this.resume()):C==="readable"&&!ke.endEmitted&&!ke.readableListening&&(ke.readableListening=ke.needReadable=!0,ke.flowing=!1,ke.emittedReadable=!1,v("on readable",ke.length,ke.reading),ke.length?he(this):ke.reading||t.nextTick(Ie,this)),_e},oe.prototype.addListener=oe.prototype.on,oe.prototype.removeListener=function(C,j){let _e=b.prototype.removeListener.call(this,C,j);return C==="readable"&&t.nextTick(Ae,this),_e},oe.prototype.off=oe.prototype.removeListener,oe.prototype.removeAllListeners=function(C){let j=b.prototype.removeAllListeners.apply(this,arguments);return(C==="readable"||C===void 0)&&t.nextTick(Ae,this),j};function Ae(C){let j=C._readableState;j.readableListening=C.listenerCount("readable")>0,j.resumeScheduled&&j[K]===!1?j.flowing=!0:C.listenerCount("data")>0?C.resume():j.readableListening||(j.flowing=null)}function Ie(C){v("readable nexttick read 0"),C.read(0)}oe.prototype.resume=function(){let C=this._readableState;return C.flowing||(v("resume"),C.flowing=!C.readableListening,Ce(this,C)),C[K]=!1,this};function Ce(C,j){j.resumeScheduled||(j.resumeScheduled=!0,t.nextTick(Ve,C,j))}function Ve(C,j){v("resume",j.reading),j.reading||C.read(0),j.resumeScheduled=!1,C.emit("resume"),Ge(C),j.flowing&&!j.reading&&C.read(0)}oe.prototype.pause=function(){return v("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(v("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState[K]=!0,this};function Ge(C){let j=C._readableState;for(v("flow",j.flowing);j.flowing&&C.read()!==null;);}oe.prototype.wrap=function(C){let j=!1;C.on("data",ke=>{!this.push(ke)&&C.pause&&(j=!0,C.pause())}),C.on("end",()=>{this.push(null)}),C.on("error",ke=>{P(this,ke)}),C.on("close",()=>{this.destroy()}),C.on("destroy",()=>{this.destroy()}),this._read=()=>{j&&C.resume&&(j=!1,C.resume())};let _e=s(C);for(let ke=1;ke<_e.length;ke++){let Ee=_e[ke];this[Ee]===void 0&&typeof C[Ee]=="function"&&(this[Ee]=C[Ee].bind(C))}return this},oe.prototype[y]=function(){return Ue(this)},oe.prototype.iterator=function(C){return C!==void 0&&Y(C,"options"),Ue(this,C)};function Ue(C,j){typeof C.read!="function"&&(C=oe.wrap(C,{objectMode:!0}));let _e=Ye(C,j);return _e.stream=C,_e}async function*Ye(C,j){let _e=Z;function ke($e){this===C?(_e(),_e=Z):_e=$e}C.on("readable",ke);let Ee,je=x(C,{writable:!1},$e=>{Ee=$e?O(Ee,$e):null,_e(),_e=Z});try{for(;;){let $e=C.destroyed?null:C.read();if($e!==null)yield $e;else{if(Ee)throw Ee;if(Ee===null)return;await new c(ke)}}}catch($e){throw Ee=O(Ee,$e),Ee}finally{(Ee||j?.destroyOnReturn!==!1)&&(Ee===void 0||C._readableState.autoDestroy)?k.destroyer(C,null):(C.off("readable",ke),je())}}o(oe.prototype,{readable:{__proto__:null,get(){let C=this._readableState;return!!C&&C.readable!==!1&&!C.destroyed&&!C.errorEmitted&&!C.endEmitted},set(C){this._readableState&&(this._readableState.readable=!!C)}},readableDidRead:{__proto__:null,enumerable:!1,get:function(){return this._readableState.dataEmitted}},readableAborted:{__proto__:null,enumerable:!1,get:function(){return!!(this._readableState.readable!==!1&&(this._readableState.destroyed||this._readableState.errored)&&!this._readableState.endEmitted)}},readableHighWaterMark:{__proto__:null,enumerable:!1,get:function(){return this._readableState.highWaterMark}},readableBuffer:{__proto__:null,enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}},readableFlowing:{__proto__:null,enumerable:!1,get:function(){return this._readableState.flowing},set:function(C){this._readableState&&(this._readableState.flowing=C)}},readableLength:{__proto__:null,enumerable:!1,get(){return this._readableState.length}},readableObjectMode:{__proto__:null,enumerable:!1,get(){return this._readableState?this._readableState.objectMode:!1}},readableEncoding:{__proto__:null,enumerable:!1,get(){return this._readableState?this._readableState.encoding:null}},errored:{__proto__:null,enumerable:!1,get(){return this._readableState?this._readableState.errored:null}},closed:{__proto__:null,get(){return this._readableState?this._readableState.closed:!1}},destroyed:{__proto__:null,enumerable:!1,get(){return this._readableState?this._readableState.destroyed:!1},set(C){this._readableState&&(this._readableState.destroyed=C)}},readableEnded:{__proto__:null,enumerable:!1,get(){return this._readableState?this._readableState.endEmitted:!1}}}),o(ve.prototype,{pipesCount:{__proto__:null,get(){return this.pipes.length}},paused:{__proto__:null,get(){return this[K]!==!1},set(C){this[K]=!!C}}}),oe._fromList=It;function It(C,j){if(j.length===0)return null;let _e;return j.objectMode?_e=j.buffer.shift():!C||C>=j.length?(j.decoder?_e=j.buffer.join(""):j.buffer.length===1?_e=j.buffer.first():_e=j.buffer.concat(j.length),j.buffer.clear()):_e=j.buffer.consume(C,j.decoder),_e}function Qe(C){let j=C._readableState;v("endReadable",j.endEmitted),j.endEmitted||(j.ended=!0,t.nextTick(ze,j,C))}function ze(C,j){if(v("endReadableNT",C.endEmitted,C.length),!C.errored&&!C.closeEmitted&&!C.endEmitted&&C.length===0){if(C.endEmitted=!0,j.emit("end"),j.writable&&j.allowHalfOpen===!1)t.nextTick(Jt,j);else if(C.autoDestroy){let _e=j._writableState;(!_e||_e.autoDestroy&&(_e.finished||_e.writable===!1))&&j.destroy()}}}function Jt(C){C.writable&&!C.writableEnded&&!C.destroyed&&C.end()}oe.from=function(C,j){return D(oe,C,j)};var Tt;function Bt(){return Tt===void 0&&(Tt={}),Tt}oe.fromWeb=function(C,j){return Bt().newStreamReadableFromReadableStream(C,j)},oe.toWeb=function(C,j){return Bt().newReadableStreamFromStreamReadable(C,j)},oe.wrap=function(C,j){var _e,ke;return new oe({objectMode:(_e=(ke=C.readableObjectMode)!==null&&ke!==void 0?ke:C.objectMode)!==null&&_e!==void 0?_e:!0,...j,destroy(Ee,je){k.destroyer(C,Ee),je(Ee)}}).wrap(C)}}),Ji=pe((u,e)=>{le(),ce(),ue();var t=xt(),{ArrayPrototypeSlice:n,Error:l,FunctionPrototypeSymbolHasInstance:r,ObjectDefineProperty:i,ObjectDefineProperties:o,ObjectSetPrototypeOf:s,StringPrototypeToLowerCase:a,Symbol:c,SymbolHasInstance:d}=Re();e.exports=Y,Y.WritableState=N;var{EventEmitter:p}=(Et(),Oe(mt)),y=Qi().Stream,{Buffer:f}=(Ne(),Oe(Le)),m=Lt(),{addAbortSignal:b}=Pr(),{getHighWaterMark:_,getDefaultHighWaterMark:g}=Mr(),{ERR_INVALID_ARG_TYPE:S,ERR_METHOD_NOT_IMPLEMENTED:x,ERR_MULTIPLE_CALLBACK:v,ERR_STREAM_CANNOT_PIPE:E,ERR_STREAM_DESTROYED:k,ERR_STREAM_ALREADY_FINISHED:I,ERR_STREAM_NULL_VALUES:M,ERR_STREAM_WRITE_AFTER_END:O,ERR_UNKNOWN_ENCODING:B}=We().codes,{errorOrDestroy:T}=m;s(Y.prototype,y.prototype),s(Y,y);function W(){}var F=c("kOnFinished");function N(R,$,ee){typeof ee!="boolean"&&(ee=$ instanceof ot()),this.objectMode=!!(R&&R.objectMode),ee&&(this.objectMode=this.objectMode||!!(R&&R.writableObjectMode)),this.highWaterMark=R?_(this,R,"writableHighWaterMark",ee):g(!1),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;let fe=!!(R&&R.decodeStrings===!1);this.decodeStrings=!fe,this.defaultEncoding=R&&R.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=P.bind(void 0,$),this.writecb=null,this.writelen=0,this.afterWriteTickInfo=null,ae(this),this.pendingcb=0,this.constructed=!0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=!R||R.emitClose!==!1,this.autoDestroy=!R||R.autoDestroy!==!1,this.errored=null,this.closed=!1,this.closeEmitted=!1,this[F]=[]}function ae(R){R.buffered=[],R.bufferedIndex=0,R.allBuffers=!0,R.allNoop=!0}N.prototype.getBuffer=function(){return n(this.buffered,this.bufferedIndex)},i(N.prototype,"bufferedRequestCount",{__proto__:null,get(){return this.buffered.length-this.bufferedIndex}});function Y(R){let $=this instanceof ot();if(!$&&!r(Y,this))return new Y(R);this._writableState=new N(R,this,$),R&&(typeof R.write=="function"&&(this._write=R.write),typeof R.writev=="function"&&(this._writev=R.writev),typeof R.destroy=="function"&&(this._destroy=R.destroy),typeof R.final=="function"&&(this._final=R.final),typeof R.construct=="function"&&(this._construct=R.construct),R.signal&&b(R.signal,this)),y.call(this,R),m.construct(this,()=>{let ee=this._writableState;ee.writing||we(this,ee),H(this,ee)})}i(Y,d,{__proto__:null,value:function(R){return r(this,R)?!0:this!==Y?!1:R&&R._writableState instanceof N}}),Y.prototype.pipe=function(){T(this,new E)};function K(R,$,ee,fe){let de=R._writableState;if(typeof ee=="function")fe=ee,ee=de.defaultEncoding;else{if(!ee)ee=de.defaultEncoding;else if(ee!=="buffer"&&!f.isEncoding(ee))throw new B(ee);typeof fe!="function"&&(fe=W)}if($===null)throw new M;if(!de.objectMode)if(typeof $=="string")de.decodeStrings!==!1&&($=f.from($,ee),ee="buffer");else if($ instanceof f)ee="buffer";else if(y._isUint8Array($))$=y._uint8ArrayToBuffer($),ee="buffer";else throw new S("chunk",["string","Buffer","Uint8Array"],$);let ye;return de.ending?ye=new O:de.destroyed&&(ye=new k("write")),ye?(t.nextTick(fe,ye),T(R,ye,!0),ye):(de.pendingcb++,re(R,de,$,ee,fe))}Y.prototype.write=function(R,$,ee){return K(this,R,$,ee)===!0},Y.prototype.cork=function(){this._writableState.corked++},Y.prototype.uncork=function(){let R=this._writableState;R.corked&&(R.corked--,R.writing||we(this,R))},Y.prototype.setDefaultEncoding=function(R){if(typeof R=="string"&&(R=a(R)),!f.isEncoding(R))throw new B(R);return this._writableState.defaultEncoding=R,this};function re(R,$,ee,fe,de){let ye=$.objectMode?1:ee.length;$.length+=ye;let q=$.length<$.highWaterMark;return q||($.needDrain=!0),$.writing||$.corked||$.errored||!$.constructed?($.buffered.push({chunk:ee,encoding:fe,callback:de}),$.allBuffers&&fe!=="buffer"&&($.allBuffers=!1),$.allNoop&&de!==W&&($.allNoop=!1)):($.writelen=ye,$.writecb=de,$.writing=!0,$.sync=!0,R._write(ee,fe,$.onwrite),$.sync=!1),q&&!$.errored&&!$.destroyed}function D(R,$,ee,fe,de,ye,q){$.writelen=fe,$.writecb=q,$.writing=!0,$.sync=!0,$.destroyed?$.onwrite(new k("write")):ee?R._writev(de,$.onwrite):R._write(de,ye,$.onwrite),$.sync=!1}function Z(R,$,ee,fe){--$.pendingcb,fe(ee),te($),T(R,ee)}function P(R,$){let ee=R._writableState,fe=ee.sync,de=ee.writecb;if(typeof de!="function"){T(R,new v);return}ee.writing=!1,ee.writecb=null,ee.length-=ee.writelen,ee.writelen=0,$?($.stack,ee.errored||(ee.errored=$),R._readableState&&!R._readableState.errored&&(R._readableState.errored=$),fe?t.nextTick(Z,R,ee,$,de):Z(R,ee,$,de)):(ee.buffered.length>ee.bufferedIndex&&we(R,ee),fe?ee.afterWriteTickInfo!==null&&ee.afterWriteTickInfo.cb===de?ee.afterWriteTickInfo.count++:(ee.afterWriteTickInfo={count:1,cb:de,stream:R,state:ee},t.nextTick(J,ee.afterWriteTickInfo)):be(R,ee,1,de))}function J({stream:R,state:$,count:ee,cb:fe}){return $.afterWriteTickInfo=null,be(R,$,ee,fe)}function be(R,$,ee,fe){for(!$.ending&&!R.destroyed&&$.length===0&&$.needDrain&&($.needDrain=!1,R.emit("drain"));ee-- >0;)$.pendingcb--,fe();$.destroyed&&te($),H(R,$)}function te(R){if(R.writing)return;for(let de=R.bufferedIndex;de<R.buffered.length;++de){var $;let{chunk:ye,callback:q}=R.buffered[de],ge=R.objectMode?1:ye.length;R.length-=ge,q(($=R.errored)!==null&&$!==void 0?$:new k("write"))}let ee=R[F].splice(0);for(let de=0;de<ee.length;de++){var fe;ee[de]((fe=R.errored)!==null&&fe!==void 0?fe:new k("end"))}ae(R)}function we(R,$){if($.corked||$.bufferProcessing||$.destroyed||!$.constructed)return;let{buffered:ee,bufferedIndex:fe,objectMode:de}=$,ye=ee.length-fe;if(!ye)return;let q=fe;if($.bufferProcessing=!0,ye>1&&R._writev){$.pendingcb-=ye-1;let ge=$.allNoop?W:oe=>{for(let Te=q;Te<ee.length;++Te)ee[Te].callback(oe)},ve=$.allNoop&&q===0?ee:n(ee,q);ve.allBuffers=$.allBuffers,D(R,$,!0,$.length,ve,"",ge),ae($)}else{do{let{chunk:ge,encoding:ve,callback:oe}=ee[q];ee[q++]=null;let Te=de?1:ge.length;D(R,$,!1,Te,ge,ve,oe)}while(q<ee.length&&!$.writing);q===ee.length?ae($):q>256?(ee.splice(0,q),$.bufferedIndex=0):$.bufferedIndex=q}$.bufferProcessing=!1}Y.prototype._write=function(R,$,ee){if(this._writev)this._writev([{chunk:R,encoding:$}],ee);else throw new x("_write()")},Y.prototype._writev=null,Y.prototype.end=function(R,$,ee){let fe=this._writableState;typeof R=="function"?(ee=R,R=null,$=null):typeof $=="function"&&(ee=$,$=null);let de;if(R!=null){let ye=K(this,R,$);ye instanceof l&&(de=ye)}return fe.corked&&(fe.corked=1,this.uncork()),de||(!fe.errored&&!fe.ending?(fe.ending=!0,H(this,fe,!0),fe.ended=!0):fe.finished?de=new I("end"):fe.destroyed&&(de=new k("end"))),typeof ee=="function"&&(de||fe.finished?t.nextTick(ee,de):fe[F].push(ee)),this};function V(R){return R.ending&&!R.destroyed&&R.constructed&&R.length===0&&!R.errored&&R.buffered.length===0&&!R.finished&&!R.writing&&!R.errorEmitted&&!R.closeEmitted}function L(R,$){let ee=!1;function fe(de){if(ee){T(R,de??v());return}if(ee=!0,$.pendingcb--,de){let ye=$[F].splice(0);for(let q=0;q<ye.length;q++)ye[q](de);T(R,de,$.sync)}else V($)&&($.prefinished=!0,R.emit("prefinish"),$.pendingcb++,t.nextTick(G,R,$))}$.sync=!0,$.pendingcb++;try{R._final(fe)}catch(de){fe(de)}$.sync=!1}function ne(R,$){!$.prefinished&&!$.finalCalled&&(typeof R._final=="function"&&!$.destroyed?($.finalCalled=!0,L(R,$)):($.prefinished=!0,R.emit("prefinish")))}function H(R,$,ee){V($)&&(ne(R,$),$.pendingcb===0&&(ee?($.pendingcb++,t.nextTick((fe,de)=>{V(de)?G(fe,de):de.pendingcb--},R,$)):V($)&&($.pendingcb++,G(R,$))))}function G(R,$){$.pendingcb--,$.finished=!0;let ee=$[F].splice(0);for(let fe=0;fe<ee.length;fe++)ee[fe]();if(R.emit("finish"),$.autoDestroy){let fe=R._readableState;(!fe||fe.autoDestroy&&(fe.endEmitted||fe.readable===!1))&&R.destroy()}}o(Y.prototype,{closed:{__proto__:null,get(){return this._writableState?this._writableState.closed:!1}},destroyed:{__proto__:null,get(){return this._writableState?this._writableState.destroyed:!1},set(R){this._writableState&&(this._writableState.destroyed=R)}},writable:{__proto__:null,get(){let R=this._writableState;return!!R&&R.writable!==!1&&!R.destroyed&&!R.errored&&!R.ending&&!R.ended},set(R){this._writableState&&(this._writableState.writable=!!R)}},writableFinished:{__proto__:null,get(){return this._writableState?this._writableState.finished:!1}},writableObjectMode:{__proto__:null,get(){return this._writableState?this._writableState.objectMode:!1}},writableBuffer:{__proto__:null,get(){return this._writableState&&this._writableState.getBuffer()}},writableEnded:{__proto__:null,get(){return this._writableState?this._writableState.ending:!1}},writableNeedDrain:{__proto__:null,get(){let R=this._writableState;return R?!R.destroyed&&!R.ending&&R.needDrain:!1}},writableHighWaterMark:{__proto__:null,get(){return this._writableState&&this._writableState.highWaterMark}},writableCorked:{__proto__:null,get(){return this._writableState?this._writableState.corked:0}},writableLength:{__proto__:null,get(){return this._writableState&&this._writableState.length}},errored:{__proto__:null,enumerable:!1,get(){return this._writableState?this._writableState.errored:null}},writableAborted:{__proto__:null,enumerable:!1,get:function(){return!!(this._writableState.writable!==!1&&(this._writableState.destroyed||this._writableState.errored)&&!this._writableState.finished)}}});var Q=m.destroy;Y.prototype.destroy=function(R,$){let ee=this._writableState;return!ee.destroyed&&(ee.bufferedIndex<ee.buffered.length||ee[F].length)&&t.nextTick(te,ee),Q.call(this,R,$),this},Y.prototype._undestroy=m.undestroy,Y.prototype._destroy=function(R,$){$(R)},Y.prototype[p.captureRejectionSymbol]=function(R){this.destroy(R)};var me;function se(){return me===void 0&&(me={}),me}Y.fromWeb=function(R,$){return se().newStreamWritableFromWritableStream(R,$)},Y.toWeb=function(R){return se().newWritableStreamFromStreamWritable(R)}}),cu=pe((u,e)=>{le(),ce(),ue();var t=xt(),n=(Ne(),Oe(Le)),{isReadable:l,isWritable:r,isIterable:i,isNodeStream:o,isReadableNodeStream:s,isWritableNodeStream:a,isDuplexNodeStream:c,isReadableStream:d,isWritableStream:p}=lt(),y=bt(),{AbortError:f,codes:{ERR_INVALID_ARG_TYPE:m,ERR_INVALID_RETURN_VALUE:b}}=We(),{destroyer:_}=Lt(),g=ot(),S=Rr(),x=Ji(),{createDeferredPromise:v}=qe(),E=Jo(),k=globalThis.Blob||n.Blob,I=typeof k<"u"?function(F){return F instanceof k}:function(F){return!1},M=globalThis.AbortController||Gt().AbortController,{FunctionPrototypeCall:O}=Re(),B=class extends g{constructor(F){super(F),F?.readable===!1&&(this._readableState.readable=!1,this._readableState.ended=!0,this._readableState.endEmitted=!0),F?.writable===!1&&(this._writableState.writable=!1,this._writableState.ending=!0,this._writableState.ended=!0,this._writableState.finished=!0)}};e.exports=function F(N,ae){if(c(N))return N;if(s(N))return W({readable:N});if(a(N))return W({writable:N});if(o(N))return W({writable:!1,readable:!1});if(d(N))return W({readable:S.fromWeb(N)});if(p(N))return W({writable:x.fromWeb(N)});if(typeof N=="function"){let{value:K,write:re,final:D,destroy:Z}=T(N);if(i(K))return E(B,K,{objectMode:!0,write:re,final:D,destroy:Z});let P=K?.then;if(typeof P=="function"){let J,be=O(P,K,te=>{if(te!=null)throw new b("nully","body",te)},te=>{_(J,te)});return J=new B({objectMode:!0,readable:!1,write:re,final(te){D(async()=>{try{await be,t.nextTick(te,null)}catch(we){t.nextTick(te,we)}})},destroy:Z})}throw new b("Iterable, AsyncIterable or AsyncFunction",ae,K)}if(I(N))return F(N.arrayBuffer());if(i(N))return E(B,N,{objectMode:!0,writable:!1});if(d(N?.readable)&&p(N?.writable))return B.fromWeb(N);if(typeof N?.writable=="object"||typeof N?.readable=="object"){let K=N!=null&&N.readable?s(N?.readable)?N?.readable:F(N.readable):void 0,re=N!=null&&N.writable?a(N?.writable)?N?.writable:F(N.writable):void 0;return W({readable:K,writable:re})}let Y=N?.then;if(typeof Y=="function"){let K;return O(Y,N,re=>{re!=null&&K.push(re),K.push(null)},re=>{_(K,re)}),K=new B({objectMode:!0,writable:!1,read(){}})}throw new m(ae,["Blob","ReadableStream","WritableStream","Stream","Iterable","AsyncIterable","Function","{ readable, writable } pair","Promise"],N)};function T(F){let{promise:N,resolve:ae}=v(),Y=new M,K=Y.signal;return{value:F((async function*(){for(;;){let re=N;N=null;let{chunk:D,done:Z,cb:P}=await re;if(t.nextTick(P),Z)return;if(K.aborted)throw new f(void 0,{cause:K.reason});({promise:N,resolve:ae}=v()),yield D}})(),{signal:K}),write(re,D,Z){let P=ae;ae=null,P({chunk:re,done:!1,cb:Z})},final(re){let D=ae;ae=null,D({done:!0,cb:re})},destroy(re,D){Y.abort(),D(re)}}}function W(F){let N=F.readable&&typeof F.readable.read!="function"?S.wrap(F.readable):F.readable,ae=F.writable,Y=!!l(N),K=!!r(ae),re,D,Z,P,J;function be(te){let we=P;P=null,we?we(te):te&&J.destroy(te)}return J=new B({readableObjectMode:!!(N!=null&&N.readableObjectMode),writableObjectMode:!!(ae!=null&&ae.writableObjectMode),readable:Y,writable:K}),K&&(y(ae,te=>{K=!1,te&&_(N,te),be(te)}),J._write=function(te,we,V){ae.write(te,we)?V():re=V},J._final=function(te){ae.end(),D=te},ae.on("drain",function(){if(re){let te=re;re=null,te()}}),ae.on("finish",function(){if(D){let te=D;D=null,te()}})),Y&&(y(N,te=>{Y=!1,te&&_(N,te),be(te)}),N.on("readable",function(){if(Z){let te=Z;Z=null,te()}}),N.on("end",function(){J.push(null)}),J._read=function(){for(;;){let te=N.read();if(te===null){Z=J._read;return}if(!J.push(te))return}}),J._destroy=function(te,we){!te&&P!==null&&(te=new f),Z=null,re=null,D=null,P===null?we(te):(P=we,_(ae,te),_(N,te))},J}}),ot=pe((u,e)=>{le(),ce(),ue();var{ObjectDefineProperties:t,ObjectGetOwnPropertyDescriptor:n,ObjectKeys:l,ObjectSetPrototypeOf:r}=Re();e.exports=s;var i=Rr(),o=Ji();r(s.prototype,i.prototype),r(s,i);{let p=l(o.prototype);for(let y=0;y<p.length;y++){let f=p[y];s.prototype[f]||(s.prototype[f]=o.prototype[f])}}function s(p){if(!(this instanceof s))return new s(p);i.call(this,p),o.call(this,p),p?(this.allowHalfOpen=p.allowHalfOpen!==!1,p.readable===!1&&(this._readableState.readable=!1,this._readableState.ended=!0,this._readableState.endEmitted=!0),p.writable===!1&&(this._writableState.writable=!1,this._writableState.ending=!0,this._writableState.ended=!0,this._writableState.finished=!0)):this.allowHalfOpen=!0}t(s.prototype,{writable:{__proto__:null,...n(o.prototype,"writable")},writableHighWaterMark:{__proto__:null,...n(o.prototype,"writableHighWaterMark")},writableObjectMode:{__proto__:null,...n(o.prototype,"writableObjectMode")},writableBuffer:{__proto__:null,...n(o.prototype,"writableBuffer")},writableLength:{__proto__:null,...n(o.prototype,"writableLength")},writableFinished:{__proto__:null,...n(o.prototype,"writableFinished")},writableCorked:{__proto__:null,...n(o.prototype,"writableCorked")},writableEnded:{__proto__:null,...n(o.prototype,"writableEnded")},writableNeedDrain:{__proto__:null,...n(o.prototype,"writableNeedDrain")},destroyed:{__proto__:null,get(){return this._readableState===void 0||this._writableState===void 0?!1:this._readableState.destroyed&&this._writableState.destroyed},set(p){this._readableState&&this._writableState&&(this._readableState.destroyed=p,this._writableState.destroyed=p)}}});var a;function c(){return a===void 0&&(a={}),a}s.fromWeb=function(p,y){return c().newStreamDuplexFromReadableWritablePair(p,y)},s.toWeb=function(p){return c().newReadableWritablePairFromDuplex(p)};var d;s.from=function(p){return d||(d=cu()),d(p,"body")}}),Xo=pe((u,e)=>{le(),ce(),ue();var{ObjectSetPrototypeOf:t,Symbol:n}=Re();e.exports=s;var{ERR_METHOD_NOT_IMPLEMENTED:l}=We().codes,r=ot(),{getHighWaterMark:i}=Mr();t(s.prototype,r.prototype),t(s,r);var o=n("kCallback");function s(d){if(!(this instanceof s))return new s(d);let p=d?i(this,d,"readableHighWaterMark",!0):null;p===0&&(d={...d,highWaterMark:null,readableHighWaterMark:p,writableHighWaterMark:d.writableHighWaterMark||0}),r.call(this,d),this._readableState.sync=!1,this[o]=null,d&&(typeof d.transform=="function"&&(this._transform=d.transform),typeof d.flush=="function"&&(this._flush=d.flush)),this.on("prefinish",c)}function a(d){typeof this._flush=="function"&&!this.destroyed?this._flush((p,y)=>{if(p){d?d(p):this.destroy(p);return}y!=null&&this.push(y),this.push(null),d&&d()}):(this.push(null),d&&d())}function c(){this._final!==a&&a.call(this)}s.prototype._final=a,s.prototype._transform=function(d,p,y){throw new l("_transform()")},s.prototype._write=function(d,p,y){let f=this._readableState,m=this._writableState,b=f.length;this._transform(d,p,(_,g)=>{if(_){y(_);return}g!=null&&this.push(g),m.ended||b===f.length||f.length<f.highWaterMark?y():this[o]=y})},s.prototype._read=function(){if(this[o]){let d=this[o];this[o]=null,d()}}}),Zo=pe((u,e)=>{le(),ce(),ue();var{ObjectSetPrototypeOf:t}=Re();e.exports=l;var n=Xo();t(l.prototype,n.prototype),t(l,n);function l(r){if(!(this instanceof l))return new l(r);n.call(this,r)}l.prototype._transform=function(r,i,o){o(null,r)}}),Xi=pe((u,e)=>{le(),ce(),ue();var t=xt(),{ArrayIsArray:n,Promise:l,SymbolAsyncIterator:r,SymbolDispose:i}=Re(),o=bt(),{once:s}=qe(),a=Lt(),c=ot(),{aggregateTwoErrors:d,codes:{ERR_INVALID_ARG_TYPE:p,ERR_INVALID_RETURN_VALUE:y,ERR_MISSING_ARGS:f,ERR_STREAM_DESTROYED:m,ERR_STREAM_PREMATURE_CLOSE:b},AbortError:_}=We(),{validateFunction:g,validateAbortSignal:S}=Yt(),{isIterable:x,isReadable:v,isReadableNodeStream:E,isNodeStream:k,isTransformStream:I,isWebStream:M,isReadableStream:O,isReadableFinished:B}=lt(),T=globalThis.AbortController||Gt().AbortController,W,F,N;function ae(te,we,V){let L=!1;te.on("close",()=>{L=!0});let ne=o(te,{readable:we,writable:V},H=>{L=!H});return{destroy:H=>{L||(L=!0,a.destroyer(te,H||new m("pipe")))},cleanup:ne}}function Y(te){return g(te[te.length-1],"streams[stream.length - 1]"),te.pop()}function K(te){if(x(te))return te;if(E(te))return re(te);throw new p("val",["Readable","Iterable","AsyncIterable"],te)}async function*re(te){F||(F=Rr()),yield*F.prototype[r].call(te)}async function D(te,we,V,{end:L}){let ne,H=null,G=se=>{if(se&&(ne=se),H){let R=H;H=null,R()}},Q=()=>new l((se,R)=>{ne?R(ne):H=()=>{ne?R(ne):se()}});we.on("drain",G);let me=o(we,{readable:!1},G);try{we.writableNeedDrain&&await Q();for await(let se of te)we.write(se)||await Q();L&&(we.end(),await Q()),V()}catch(se){V(ne!==se?d(ne,se):se)}finally{me(),we.off("drain",G)}}async function Z(te,we,V,{end:L}){I(we)&&(we=we.writable);let ne=we.getWriter();try{for await(let H of te)await ne.ready,ne.write(H).catch(()=>{});await ne.ready,L&&await ne.close(),V()}catch(H){try{await ne.abort(H),V(H)}catch(G){V(G)}}}function P(...te){return J(te,s(Y(te)))}function J(te,we,V){if(te.length===1&&n(te[0])&&(te=te[0]),te.length<2)throw new f("streams");let L=new T,ne=L.signal,H=V?.signal,G=[];S(H,"options.signal");function Q(){de(new _)}N=N||qe().addAbortListener;let me;H&&(me=N(H,Q));let se,R,$=[],ee=0;function fe(ve){de(ve,--ee===0)}function de(ve,oe){var Te;if(ve&&(!se||se.code==="ERR_STREAM_PREMATURE_CLOSE")&&(se=ve),!(!se&&!oe)){for(;$.length;)$.shift()(se);(Te=me)===null||Te===void 0||Te[i](),L.abort(),oe&&(se||G.forEach(h=>h()),t.nextTick(we,se,R))}}let ye;for(let ve=0;ve<te.length;ve++){let oe=te[ve],Te=ve<te.length-1,h=ve>0,w=Te||V?.end!==!1,A=ve===te.length-1;if(k(oe)){let U=function(X){X&&X.name!=="AbortError"&&X.code!=="ERR_STREAM_PREMATURE_CLOSE"&&fe(X)};if(w){let{destroy:X,cleanup:he}=ae(oe,Te,h);$.push(X),v(oe)&&A&&G.push(he)}oe.on("error",U),v(oe)&&A&&G.push(()=>{oe.removeListener("error",U)})}if(ve===0)if(typeof oe=="function"){if(ye=oe({signal:ne}),!x(ye))throw new y("Iterable, AsyncIterable or Stream","source",ye)}else x(oe)||E(oe)||I(oe)?ye=oe:ye=c.from(oe);else if(typeof oe=="function"){if(I(ye)){var q;ye=K((q=ye)===null||q===void 0?void 0:q.readable)}else ye=K(ye);if(ye=oe(ye,{signal:ne}),Te){if(!x(ye,!0))throw new y("AsyncIterable",`transform[${ve-1}]`,ye)}else{var ge;W||(W=Zo());let U=new W({objectMode:!0}),X=(ge=ye)===null||ge===void 0?void 0:ge.then;if(typeof X=="function")ee++,X.call(ye,z=>{R=z,z!=null&&U.write(z),w&&U.end(),t.nextTick(fe)},z=>{U.destroy(z),t.nextTick(fe,z)});else if(x(ye,!0))ee++,D(ye,U,fe,{end:w});else if(O(ye)||I(ye)){let z=ye.readable||ye;ee++,D(z,U,fe,{end:w})}else throw new y("AsyncIterable or Promise","destination",ye);ye=U;let{destroy:he,cleanup:Se}=ae(ye,!1,!0);$.push(he),A&&G.push(Se)}}else if(k(oe)){if(E(ye)){ee+=2;let U=be(ye,oe,fe,{end:w});v(oe)&&A&&G.push(U)}else if(I(ye)||O(ye)){let U=ye.readable||ye;ee++,D(U,oe,fe,{end:w})}else if(x(ye))ee++,D(ye,oe,fe,{end:w});else throw new p("val",["Readable","Iterable","AsyncIterable","ReadableStream","TransformStream"],ye);ye=oe}else if(M(oe)){if(E(ye))ee++,Z(K(ye),oe,fe,{end:w});else if(O(ye)||x(ye))ee++,Z(ye,oe,fe,{end:w});else if(I(ye))ee++,Z(ye.readable,oe,fe,{end:w});else throw new p("val",["Readable","Iterable","AsyncIterable","ReadableStream","TransformStream"],ye);ye=oe}else ye=c.from(oe)}return(ne!=null&&ne.aborted||H!=null&&H.aborted)&&t.nextTick(Q),ye}function be(te,we,V,{end:L}){let ne=!1;if(we.on("close",()=>{ne||V(new b)}),te.pipe(we,{end:!1}),L){let H=function(){ne=!0,we.end()};B(te)?t.nextTick(H):te.once("end",H)}else V();return o(te,{readable:!0,writable:!1},H=>{let G=te._readableState;H&&H.code==="ERR_STREAM_PREMATURE_CLOSE"&&G&&G.ended&&!G.errored&&!G.errorEmitted?te.once("end",V).once("error",V):V(H)}),o(we,{readable:!1,writable:!0},V)}e.exports={pipelineImpl:J,pipeline:P}}),ea=pe((u,e)=>{le(),ce(),ue();var{pipeline:t}=Xi(),n=ot(),{destroyer:l}=Lt(),{isNodeStream:r,isReadable:i,isWritable:o,isWebStream:s,isTransformStream:a,isWritableStream:c,isReadableStream:d}=lt(),{AbortError:p,codes:{ERR_INVALID_ARG_VALUE:y,ERR_MISSING_ARGS:f}}=We(),m=bt();e.exports=function(...b){if(b.length===0)throw new f("streams");if(b.length===1)return n.from(b[0]);let _=[...b];if(typeof b[0]=="function"&&(b[0]=n.from(b[0])),typeof b[b.length-1]=="function"){let T=b.length-1;b[T]=n.from(b[T])}for(let T=0;T<b.length;++T)if(!(!r(b[T])&&!s(b[T]))){if(T<b.length-1&&!(i(b[T])||d(b[T])||a(b[T])))throw new y(`streams[${T}]`,_[T],"must be readable");if(T>0&&!(o(b[T])||c(b[T])||a(b[T])))throw new y(`streams[${T}]`,_[T],"must be writable")}let g,S,x,v,E;function k(T){let W=v;v=null,W?W(T):T?E.destroy(T):!B&&!O&&E.destroy()}let I=b[0],M=t(b,k),O=!!(o(I)||c(I)||a(I)),B=!!(i(M)||d(M)||a(M));if(E=new n({writableObjectMode:!!(I!=null&&I.writableObjectMode),readableObjectMode:!!(M!=null&&M.readableObjectMode),writable:O,readable:B}),O){if(r(I))E._write=function(W,F,N){I.write(W,F)?N():g=N},E._final=function(W){I.end(),S=W},I.on("drain",function(){if(g){let W=g;g=null,W()}});else if(s(I)){let W=(a(I)?I.writable:I).getWriter();E._write=async function(F,N,ae){try{await W.ready,W.write(F).catch(()=>{}),ae()}catch(Y){ae(Y)}},E._final=async function(F){try{await W.ready,W.close().catch(()=>{}),S=F}catch(N){F(N)}}}let T=a(M)?M.readable:M;m(T,()=>{if(S){let W=S;S=null,W()}})}if(B){if(r(M))M.on("readable",function(){if(x){let T=x;x=null,T()}}),M.on("end",function(){E.push(null)}),E._read=function(){for(;;){let T=M.read();if(T===null){x=E._read;return}if(!E.push(T))return}};else if(s(M)){let T=(a(M)?M.readable:M).getReader();E._read=async function(){for(;;)try{let{value:W,done:F}=await T.read();if(!E.push(W))return;if(F){E.push(null);return}}catch{return}}}}return E._destroy=function(T,W){!T&&v!==null&&(T=new p),x=null,g=null,S=null,v===null?W(T):(v=W,r(M)&&l(M,T))},E}}),hu=pe((u,e)=>{le(),ce(),ue();var t=globalThis.AbortController||Gt().AbortController,{codes:{ERR_INVALID_ARG_VALUE:n,ERR_INVALID_ARG_TYPE:l,ERR_MISSING_ARGS:r,ERR_OUT_OF_RANGE:i},AbortError:o}=We(),{validateAbortSignal:s,validateInteger:a,validateObject:c}=Yt(),d=Re().Symbol("kWeak"),p=Re().Symbol("kResistStopPropagation"),{finished:y}=bt(),f=ea(),{addAbortSignalNoValidate:m}=Pr(),{isWritable:b,isNodeStream:_}=lt(),{deprecate:g}=qe(),{ArrayPrototypePush:S,Boolean:x,MathFloor:v,Number:E,NumberIsNaN:k,Promise:I,PromiseReject:M,PromiseResolve:O,PromisePrototypeThen:B,Symbol:T}=Re(),W=T("kEmpty"),F=T("kEof");function N(H,G){if(G!=null&&c(G,"options"),G?.signal!=null&&s(G.signal,"options.signal"),_(H)&&!b(H))throw new n("stream",H,"must be writable");let Q=f(this,H);return G!=null&&G.signal&&m(G.signal,Q),Q}function ae(H,G){if(typeof H!="function")throw new l("fn",["Function","AsyncFunction"],H);G!=null&&c(G,"options"),G?.signal!=null&&s(G.signal,"options.signal");let Q=1;G?.concurrency!=null&&(Q=v(G.concurrency));let me=Q-1;return G?.highWaterMark!=null&&(me=v(G.highWaterMark)),a(Q,"options.concurrency",1),a(me,"options.highWaterMark",0),me+=Q,(async function*(){let se=qe().AbortSignalAny([G?.signal].filter(x)),R=this,$=[],ee={signal:se},fe,de,ye=!1,q=0;function ge(){ye=!0,ve()}function ve(){q-=1,oe()}function oe(){de&&!ye&&q<Q&&$.length<me&&(de(),de=null)}async function Te(){try{for await(let h of R){if(ye)return;if(se.aborted)throw new o;try{if(h=H(h,ee),h===W)continue;h=O(h)}catch(w){h=M(w)}q+=1,B(h,ve,ge),$.push(h),fe&&(fe(),fe=null),!ye&&($.length>=me||q>=Q)&&await new I(w=>{de=w})}$.push(F)}catch(h){let w=M(h);B(w,ve,ge),$.push(w)}finally{ye=!0,fe&&(fe(),fe=null)}}Te();try{for(;;){for(;$.length>0;){let h=await $[0];if(h===F)return;if(se.aborted)throw new o;h!==W&&(yield h),$.shift(),oe()}await new I(h=>{fe=h})}}finally{ye=!0,de&&(de(),de=null)}}).call(this)}function Y(H=void 0){return H!=null&&c(H,"options"),H?.signal!=null&&s(H.signal,"options.signal"),(async function*(){let G=0;for await(let me of this){var Q;if(H!=null&&(Q=H.signal)!==null&&Q!==void 0&&Q.aborted)throw new o({cause:H.signal.reason});yield[G++,me]}}).call(this)}async function K(H,G=void 0){for await(let Q of P.call(this,H,G))return!0;return!1}async function re(H,G=void 0){if(typeof H!="function")throw new l("fn",["Function","AsyncFunction"],H);return!await K.call(this,async(...Q)=>!await H(...Q),G)}async function D(H,G){for await(let Q of P.call(this,H,G))return Q}async function Z(H,G){if(typeof H!="function")throw new l("fn",["Function","AsyncFunction"],H);async function Q(me,se){return await H(me,se),W}for await(let me of ae.call(this,Q,G));}function P(H,G){if(typeof H!="function")throw new l("fn",["Function","AsyncFunction"],H);async function Q(me,se){return await H(me,se)?me:W}return ae.call(this,Q,G)}var J=class extends r{constructor(){super("reduce"),this.message="Reduce of an empty stream requires an initial value"}};async function be(H,G,Q){var me;if(typeof H!="function")throw new l("reducer",["Function","AsyncFunction"],H);Q!=null&&c(Q,"options"),Q?.signal!=null&&s(Q.signal,"options.signal");let se=arguments.length>1;if(Q!=null&&(me=Q.signal)!==null&&me!==void 0&&me.aborted){let de=new o(void 0,{cause:Q.signal.reason});throw this.once("error",()=>{}),await y(this.destroy(de)),de}let R=new t,$=R.signal;if(Q!=null&&Q.signal){let de={once:!0,[d]:this,[p]:!0};Q.signal.addEventListener("abort",()=>R.abort(),de)}let ee=!1;try{for await(let de of this){var fe;if(ee=!0,Q!=null&&(fe=Q.signal)!==null&&fe!==void 0&&fe.aborted)throw new o;se?G=await H(G,de,{signal:$}):(G=de,se=!0)}if(!ee&&!se)throw new J}finally{R.abort()}return G}async function te(H){H!=null&&c(H,"options"),H?.signal!=null&&s(H.signal,"options.signal");let G=[];for await(let me of this){var Q;if(H!=null&&(Q=H.signal)!==null&&Q!==void 0&&Q.aborted)throw new o(void 0,{cause:H.signal.reason});S(G,me)}return G}function we(H,G){let Q=ae.call(this,H,G);return(async function*(){for await(let me of Q)yield*me}).call(this)}function V(H){if(H=E(H),k(H))return 0;if(H<0)throw new i("number",">= 0",H);return H}function L(H,G=void 0){return G!=null&&c(G,"options"),G?.signal!=null&&s(G.signal,"options.signal"),H=V(H),(async function*(){var Q;if(G!=null&&(Q=G.signal)!==null&&Q!==void 0&&Q.aborted)throw new o;for await(let se of this){var me;if(G!=null&&(me=G.signal)!==null&&me!==void 0&&me.aborted)throw new o;H--<=0&&(yield se)}}).call(this)}function ne(H,G=void 0){return G!=null&&c(G,"options"),G?.signal!=null&&s(G.signal,"options.signal"),H=V(H),(async function*(){var Q;if(G!=null&&(Q=G.signal)!==null&&Q!==void 0&&Q.aborted)throw new o;for await(let se of this){var me;if(G!=null&&(me=G.signal)!==null&&me!==void 0&&me.aborted)throw new o;if(H-- >0&&(yield se),H<=0)return}}).call(this)}e.exports.streamReturningOperators={asIndexedPairs:g(Y,"readable.asIndexedPairs will be removed in a future version."),drop:L,filter:P,flatMap:we,map:ae,take:ne,compose:N},e.exports.promiseReturningOperators={every:re,forEach:Z,reduce:be,toArray:te,some:K,find:D}}),ta=pe((u,e)=>{le(),ce(),ue();var{ArrayPrototypePop:t,Promise:n}=Re(),{isIterable:l,isNodeStream:r,isWebStream:i}=lt(),{pipelineImpl:o}=Xi(),{finished:s}=bt();ra();function a(...c){return new n((d,p)=>{let y,f,m=c[c.length-1];if(m&&typeof m=="object"&&!r(m)&&!l(m)&&!i(m)){let b=t(c);y=b.signal,f=b.end}o(c,(b,_)=>{b?p(b):d(_)},{signal:y,end:f})})}e.exports={finished:s,pipeline:a}}),ra=pe((u,e)=>{le(),ce(),ue();var{Buffer:t}=(Ne(),Oe(Le)),{ObjectDefineProperty:n,ObjectKeys:l,ReflectApply:r}=Re(),{promisify:{custom:i}}=qe(),{streamReturningOperators:o,promiseReturningOperators:s}=hu(),{codes:{ERR_ILLEGAL_CONSTRUCTOR:a}}=We(),c=ea(),{setDefaultHighWaterMark:d,getDefaultHighWaterMark:p}=Mr(),{pipeline:y}=Xi(),{destroyer:f}=Lt(),m=bt(),b=ta(),_=lt(),g=e.exports=Qi().Stream;g.isDestroyed=_.isDestroyed,g.isDisturbed=_.isDisturbed,g.isErrored=_.isErrored,g.isReadable=_.isReadable,g.isWritable=_.isWritable,g.Readable=Rr();for(let x of l(o)){let v=function(...k){if(new.target)throw a();return g.Readable.from(r(E,this,k))},E=o[x];n(v,"name",{__proto__:null,value:E.name}),n(v,"length",{__proto__:null,value:E.length}),n(g.Readable.prototype,x,{__proto__:null,value:v,enumerable:!1,configurable:!0,writable:!0})}for(let x of l(s)){let v=function(...k){if(new.target)throw a();return r(E,this,k)},E=s[x];n(v,"name",{__proto__:null,value:E.name}),n(v,"length",{__proto__:null,value:E.length}),n(g.Readable.prototype,x,{__proto__:null,value:v,enumerable:!1,configurable:!0,writable:!0})}g.Writable=Ji(),g.Duplex=ot(),g.Transform=Xo(),g.PassThrough=Zo(),g.pipeline=y;var{addAbortSignal:S}=Pr();g.addAbortSignal=S,g.finished=m,g.destroy=f,g.compose=c,g.setDefaultHighWaterMark=d,g.getDefaultHighWaterMark=p,n(g,"promises",{__proto__:null,configurable:!0,enumerable:!0,get(){return b}}),n(y,i,{__proto__:null,enumerable:!0,get(){return b.pipeline}}),n(m,i,{__proto__:null,enumerable:!0,get(){return b.finished}}),g.Stream=g,g._isUint8Array=function(x){return x instanceof Uint8Array},g._uint8ArrayToBuffer=function(x){return t.from(x.buffer,x.byteOffset,x.byteLength)}}),At=pe((u,e)=>{le(),ce(),ue();var t=ra(),n=ta(),l=t.Readable.destroy;e.exports=t.Readable,e.exports._uint8ArrayToBuffer=t._uint8ArrayToBuffer,e.exports._isUint8Array=t._isUint8Array,e.exports.isDisturbed=t.isDisturbed,e.exports.isErrored=t.isErrored,e.exports.isReadable=t.isReadable,e.exports.Readable=t.Readable,e.exports.Writable=t.Writable,e.exports.Duplex=t.Duplex,e.exports.Transform=t.Transform,e.exports.PassThrough=t.PassThrough,e.exports.addAbortSignal=t.addAbortSignal,e.exports.finished=t.finished,e.exports.destroy=t.destroy,e.exports.destroy=l,e.exports.pipeline=t.pipeline,e.exports.compose=t.compose,Object.defineProperty(t,"promises",{configurable:!0,enumerable:!0,get(){return n}}),e.exports.Stream=t.Stream,e.exports.default=e.exports}),fu=pe((u,e)=>{le(),ce(),ue(),typeof Object.create=="function"?e.exports=function(t,n){n&&(t.super_=n,t.prototype=Object.create(n.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}))}:e.exports=function(t,n){if(n){t.super_=n;var l=function(){};l.prototype=n.prototype,t.prototype=new l,t.prototype.constructor=t}}}),du=pe((u,e)=>{le(),ce(),ue();var{Buffer:t}=(Ne(),Oe(Le)),n=Symbol.for("BufferList");function l(r){if(!(this instanceof l))return new l(r);l._init.call(this,r)}l._init=function(r){Object.defineProperty(this,n,{value:!0}),this._bufs=[],this.length=0,r&&this.append(r)},l.prototype._new=function(r){return new l(r)},l.prototype._offset=function(r){if(r===0)return[0,0];let i=0;for(let o=0;o<this._bufs.length;o++){let s=i+this._bufs[o].length;if(r<s||o===this._bufs.length-1)return[o,r-i];i=s}},l.prototype._reverseOffset=function(r){let i=r[0],o=r[1];for(let s=0;s<i;s++)o+=this._bufs[s].length;return o},l.prototype.getBuffers=function(){return this._bufs},l.prototype.get=function(r){if(r>this.length||r<0)return;let i=this._offset(r);return this._bufs[i[0]][i[1]]},l.prototype.slice=function(r,i){return typeof r=="number"&&r<0&&(r+=this.length),typeof i=="number"&&i<0&&(i+=this.length),this.copy(null,0,r,i)},l.prototype.copy=function(r,i,o,s){if((typeof o!="number"||o<0)&&(o=0),(typeof s!="number"||s>this.length)&&(s=this.length),o>=this.length||s<=0)return r||t.alloc(0);let a=!!r,c=this._offset(o),d=s-o,p=d,y=a&&i||0,f=c[1];if(o===0&&s===this.length){if(!a)return this._bufs.length===1?this._bufs[0]:t.concat(this._bufs,this.length);for(let m=0;m<this._bufs.length;m++)this._bufs[m].copy(r,y),y+=this._bufs[m].length;return r}if(p<=this._bufs[c[0]].length-f)return a?this._bufs[c[0]].copy(r,i,f,f+p):this._bufs[c[0]].slice(f,f+p);a||(r=t.allocUnsafe(d));for(let m=c[0];m<this._bufs.length;m++){let b=this._bufs[m].length-f;if(p>b)this._bufs[m].copy(r,y,f),y+=b;else{this._bufs[m].copy(r,y,f,f+p),y+=b;break}p-=b,f&&(f=0)}return r.length>y?r.slice(0,y):r},l.prototype.shallowSlice=function(r,i){if(r=r||0,i=typeof i!="number"?this.length:i,r<0&&(r+=this.length),i<0&&(i+=this.length),r===i)return this._new();let o=this._offset(r),s=this._offset(i),a=this._bufs.slice(o[0],s[0]+1);return s[1]===0?a.pop():a[a.length-1]=a[a.length-1].slice(0,s[1]),o[1]!==0&&(a[0]=a[0].slice(o[1])),this._new(a)},l.prototype.toString=function(r,i,o){return this.slice(i,o).toString(r)},l.prototype.consume=function(r){if(r=Math.trunc(r),Number.isNaN(r)||r<=0)return this;for(;this._bufs.length;)if(r>=this._bufs[0].length)r-=this._bufs[0].length,this.length-=this._bufs[0].length,this._bufs.shift();else{this._bufs[0]=this._bufs[0].slice(r),this.length-=r;break}return this},l.prototype.duplicate=function(){let r=this._new();for(let i=0;i<this._bufs.length;i++)r.append(this._bufs[i]);return r},l.prototype.append=function(r){return this._attach(r,l.prototype._appendBuffer)},l.prototype.prepend=function(r){return this._attach(r,l.prototype._prependBuffer,!0)},l.prototype._attach=function(r,i,o){if(r==null)return this;if(r.buffer)i.call(this,t.from(r.buffer,r.byteOffset,r.byteLength));else if(Array.isArray(r)){let[s,a]=o?[r.length-1,-1]:[0,1];for(let c=s;c>=0&&c<r.length;c+=a)this._attach(r[c],i,o)}else if(this._isBufferList(r)){let[s,a]=o?[r._bufs.length-1,-1]:[0,1];for(let c=s;c>=0&&c<r._bufs.length;c+=a)this._attach(r._bufs[c],i,o)}else typeof r=="number"&&(r=r.toString()),i.call(this,t.from(r));return this},l.prototype._appendBuffer=function(r){this._bufs.push(r),this.length+=r.length},l.prototype._prependBuffer=function(r){this._bufs.unshift(r),this.length+=r.length},l.prototype.indexOf=function(r,i,o){if(o===void 0&&typeof i=="string"&&(o=i,i=void 0),typeof r=="function"||Array.isArray(r))throw new TypeError('The "value" argument must be one of type string, Buffer, BufferList, or Uint8Array.');if(typeof r=="number"?r=t.from([r]):typeof r=="string"?r=t.from(r,o):this._isBufferList(r)?r=r.slice():Array.isArray(r.buffer)?r=t.from(r.buffer,r.byteOffset,r.byteLength):t.isBuffer(r)||(r=t.from(r)),i=Number(i||0),isNaN(i)&&(i=0),i<0&&(i=this.length+i),i<0&&(i=0),r.length===0)return i>this.length?this.length:i;let s=this._offset(i),a=s[0],c=s[1];for(;a<this._bufs.length;a++){let d=this._bufs[a];for(;c<d.length;)if(d.length-c>=r.length){let p=d.indexOf(r,c);if(p!==-1)return this._reverseOffset([a,p]);c=d.length-r.length+1}else{let p=this._reverseOffset([a,c]);if(this._match(p,r))return p;c++}c=0}return-1},l.prototype._match=function(r,i){if(this.length-r<i.length)return!1;for(let o=0;o<i.length;o++)if(this.get(r+o)!==i[o])return!1;return!0},(function(){let r={readDoubleBE:8,readDoubleLE:8,readFloatBE:4,readFloatLE:4,readBigInt64BE:8,readBigInt64LE:8,readBigUInt64BE:8,readBigUInt64LE:8,readInt32BE:4,readInt32LE:4,readUInt32BE:4,readUInt32LE:4,readInt16BE:2,readInt16LE:2,readUInt16BE:2,readUInt16LE:2,readInt8:1,readUInt8:1,readIntBE:null,readIntLE:null,readUIntBE:null,readUIntLE:null};for(let i in r)(function(o){r[o]===null?l.prototype[o]=function(s,a){return this.slice(s,s+a)[o](0,a)}:l.prototype[o]=function(s=0){return this.slice(s,s+r[o])[o](0)}})(i)})(),l.prototype._isBufferList=function(r){return r instanceof l||l.isBufferList(r)},l.isBufferList=function(r){return r!=null&&r[n]},e.exports=l}),pu=pe((u,e)=>{le(),ce(),ue();var t=At().Duplex,n=fu(),l=du();function r(i){if(!(this instanceof r))return new r(i);if(typeof i=="function"){this._callback=i;let o=(function(s){this._callback&&(this._callback(s),this._callback=null)}).bind(this);this.on("pipe",function(s){s.on("error",o)}),this.on("unpipe",function(s){s.removeListener("error",o)}),i=null}l._init.call(this,i),t.call(this)}n(r,t),Object.assign(r.prototype,l.prototype),r.prototype._new=function(i){return new r(i)},r.prototype._write=function(i,o,s){this._appendBuffer(i),typeof s=="function"&&s()},r.prototype._read=function(i){if(!this.length)return this.push(null);i=Math.min(i,this.length),this.push(this.slice(0,i)),this.consume(i)},r.prototype.end=function(i){t.prototype.end.call(this,i),this._callback&&(this._callback(null,this.slice()),this._callback=null)},r.prototype._destroy=function(i,o){this._bufs.length=0,this.length=0,o(i)},r.prototype._isBufferList=function(i){return i instanceof r||i instanceof l||r.isBufferList(i)},r.isBufferList=l.isBufferList,e.exports=r,e.exports.BufferListStream=r,e.exports.BufferList=l}),gu=pe((u,e)=>{le(),ce(),ue();var t=class{constructor(){this.cmd=null,this.retain=!1,this.qos=0,this.dup=!1,this.length=-1,this.topic=null,this.payload=null}};e.exports=t}),na=pe((u,e)=>{le(),ce(),ue();var t=e.exports,{Buffer:n}=(Ne(),Oe(Le));t.types={0:"reserved",1:"connect",2:"connack",3:"publish",4:"puback",5:"pubrec",6:"pubrel",7:"pubcomp",8:"subscribe",9:"suback",10:"unsubscribe",11:"unsuback",12:"pingreq",13:"pingresp",14:"disconnect",15:"auth"},t.requiredHeaderFlags={1:0,2:0,4:0,5:0,6:2,7:0,8:2,9:0,10:2,11:0,12:0,13:0,14:0,15:0},t.requiredHeaderFlagsErrors={};for(let r in t.requiredHeaderFlags){let i=t.requiredHeaderFlags[r];t.requiredHeaderFlagsErrors[r]="Invalid header flag bits, must be 0x"+i.toString(16)+" for "+t.types[r]+" packet"}t.codes={};for(let r in t.types){let i=t.types[r];t.codes[i]=r}t.CMD_SHIFT=4,t.CMD_MASK=240,t.DUP_MASK=8,t.QOS_MASK=3,t.QOS_SHIFT=1,t.RETAIN_MASK=1,t.VARBYTEINT_MASK=127,t.VARBYTEINT_FIN_MASK=128,t.VARBYTEINT_MAX=268435455,t.SESSIONPRESENT_MASK=1,t.SESSIONPRESENT_HEADER=n.from([t.SESSIONPRESENT_MASK]),t.CONNACK_HEADER=n.from([t.codes.connack<<t.CMD_SHIFT]),t.USERNAME_MASK=128,t.PASSWORD_MASK=64,t.WILL_RETAIN_MASK=32,t.WILL_QOS_MASK=24,t.WILL_QOS_SHIFT=3,t.WILL_FLAG_MASK=4,t.CLEAN_SESSION_MASK=2,t.CONNECT_HEADER=n.from([t.codes.connect<<t.CMD_SHIFT]),t.properties={sessionExpiryInterval:17,willDelayInterval:24,receiveMaximum:33,maximumPacketSize:39,topicAliasMaximum:34,requestResponseInformation:25,requestProblemInformation:23,userProperties:38,authenticationMethod:21,authenticationData:22,payloadFormatIndicator:1,messageExpiryInterval:2,contentType:3,responseTopic:8,correlationData:9,maximumQoS:36,retainAvailable:37,assignedClientIdentifier:18,reasonString:31,wildcardSubscriptionAvailable:40,subscriptionIdentifiersAvailable:41,sharedSubscriptionAvailable:42,serverKeepAlive:19,responseInformation:26,serverReference:28,topicAlias:35,subscriptionIdentifier:11},t.propertiesCodes={};for(let r in t.properties){let i=t.properties[r];t.propertiesCodes[i]=r}t.propertiesTypes={sessionExpiryInterval:"int32",willDelayInterval:"int32",receiveMaximum:"int16",maximumPacketSize:"int32",topicAliasMaximum:"int16",requestResponseInformation:"byte",requestProblemInformation:"byte",userProperties:"pair",authenticationMethod:"string",authenticationData:"binary",payloadFormatIndicator:"byte",messageExpiryInterval:"int32",contentType:"string",responseTopic:"string",correlationData:"binary",maximumQoS:"int8",retainAvailable:"byte",assignedClientIdentifier:"string",reasonString:"string",wildcardSubscriptionAvailable:"byte",subscriptionIdentifiersAvailable:"byte",sharedSubscriptionAvailable:"byte",serverKeepAlive:"int16",responseInformation:"string",serverReference:"string",topicAlias:"int16",subscriptionIdentifier:"var"};function l(r){return[0,1,2].map(i=>[0,1].map(o=>[0,1].map(s=>{let a=n.alloc(1);return a.writeUInt8(t.codes[r]<<t.CMD_SHIFT|(o?t.DUP_MASK:0)|i<<t.QOS_SHIFT|s,0,!0),a})))}t.PUBLISH_HEADER=l("publish"),t.SUBSCRIBE_HEADER=l("subscribe"),t.SUBSCRIBE_OPTIONS_QOS_MASK=3,t.SUBSCRIBE_OPTIONS_NL_MASK=1,t.SUBSCRIBE_OPTIONS_NL_SHIFT=2,t.SUBSCRIBE_OPTIONS_RAP_MASK=1,t.SUBSCRIBE_OPTIONS_RAP_SHIFT=3,t.SUBSCRIBE_OPTIONS_RH_MASK=3,t.SUBSCRIBE_OPTIONS_RH_SHIFT=4,t.SUBSCRIBE_OPTIONS_RH=[0,16,32],t.SUBSCRIBE_OPTIONS_NL=4,t.SUBSCRIBE_OPTIONS_RAP=8,t.SUBSCRIBE_OPTIONS_QOS=[0,1,2],t.UNSUBSCRIBE_HEADER=l("unsubscribe"),t.ACKS={unsuback:l("unsuback"),puback:l("puback"),pubcomp:l("pubcomp"),pubrel:l("pubrel"),pubrec:l("pubrec")},t.SUBACK_HEADER=n.from([t.codes.suback<<t.CMD_SHIFT]),t.VERSION3=n.from([3]),t.VERSION4=n.from([4]),t.VERSION5=n.from([5]),t.VERSION131=n.from([131]),t.VERSION132=n.from([132]),t.QOS=[0,1,2].map(r=>n.from([r])),t.EMPTY={pingreq:n.from([t.codes.pingreq<<4,0]),pingresp:n.from([t.codes.pingresp<<4,0]),disconnect:n.from([t.codes.disconnect<<4,0])},t.MQTT5_PUBACK_PUBREC_CODES={0:"Success",16:"No matching subscribers",128:"Unspecified error",131:"Implementation specific error",135:"Not authorized",144:"Topic Name invalid",145:"Packet identifier in use",151:"Quota exceeded",153:"Payload format invalid"},t.MQTT5_PUBREL_PUBCOMP_CODES={0:"Success",146:"Packet Identifier not found"},t.MQTT5_SUBACK_CODES={0:"Granted QoS 0",1:"Granted QoS 1",2:"Granted QoS 2",128:"Unspecified error",131:"Implementation specific error",135:"Not authorized",143:"Topic Filter invalid",145:"Packet Identifier in use",151:"Quota exceeded",158:"Shared Subscriptions not supported",161:"Subscription Identifiers not supported",162:"Wildcard Subscriptions not supported"},t.MQTT5_UNSUBACK_CODES={0:"Success",17:"No subscription existed",128:"Unspecified error",131:"Implementation specific error",135:"Not authorized",143:"Topic Filter invalid",145:"Packet Identifier in use"},t.MQTT5_DISCONNECT_CODES={0:"Normal disconnection",4:"Disconnect with Will Message",128:"Unspecified error",129:"Malformed Packet",130:"Protocol Error",131:"Implementation specific error",135:"Not authorized",137:"Server busy",139:"Server shutting down",141:"Keep Alive timeout",142:"Session taken over",143:"Topic Filter invalid",144:"Topic Name invalid",147:"Receive Maximum exceeded",148:"Topic Alias invalid",149:"Packet too large",150:"Message rate too high",151:"Quota exceeded",152:"Administrative action",153:"Payload format invalid",154:"Retain not supported",155:"QoS not supported",156:"Use another server",157:"Server moved",158:"Shared Subscriptions not supported",159:"Connection rate exceeded",160:"Maximum connect time",161:"Subscription Identifiers not supported",162:"Wildcard Subscriptions not supported"},t.MQTT5_AUTH_CODES={0:"Success",24:"Continue authentication",25:"Re-authenticate"}}),mu=pe((u,e)=>{le(),ce(),ue();var t=1e3,n=t*60,l=n*60,r=l*24,i=r*7,o=r*365.25;e.exports=function(p,y){y=y||{};var f=typeof p;if(f==="string"&&p.length>0)return s(p);if(f==="number"&&isFinite(p))return y.long?c(p):a(p);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(p))};function s(p){if(p=String(p),!(p.length>100)){var y=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(p);if(y){var f=parseFloat(y[1]),m=(y[2]||"ms").toLowerCase();switch(m){case"years":case"year":case"yrs":case"yr":case"y":return f*o;case"weeks":case"week":case"w":return f*i;case"days":case"day":case"d":return f*r;case"hours":case"hour":case"hrs":case"hr":case"h":return f*l;case"minutes":case"minute":case"mins":case"min":case"m":return f*n;case"seconds":case"second":case"secs":case"sec":case"s":return f*t;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return f;default:return}}}}function a(p){var y=Math.abs(p);return y>=r?Math.round(p/r)+"d":y>=l?Math.round(p/l)+"h":y>=n?Math.round(p/n)+"m":y>=t?Math.round(p/t)+"s":p+"ms"}function c(p){var y=Math.abs(p);return y>=r?d(p,y,r,"day"):y>=l?d(p,y,l,"hour"):y>=n?d(p,y,n,"minute"):y>=t?d(p,y,t,"second"):p+" ms"}function d(p,y,f,m){var b=y>=f*1.5;return Math.round(p/f)+" "+m+(b?"s":"")}}),bu=pe((u,e)=>{le(),ce(),ue();function t(n){r.debug=r,r.default=r,r.coerce=d,r.disable=a,r.enable=o,r.enabled=c,r.humanize=mu(),r.destroy=p,Object.keys(n).forEach(y=>{r[y]=n[y]}),r.names=[],r.skips=[],r.formatters={};function l(y){let f=0;for(let m=0;m<y.length;m++)f=(f<<5)-f+y.charCodeAt(m),f|=0;return r.colors[Math.abs(f)%r.colors.length]}r.selectColor=l;function r(y){let f,m=null,b,_;function g(...S){if(!g.enabled)return;let x=g,v=Number(new Date),E=v-(f||v);x.diff=E,x.prev=f,x.curr=v,f=v,S[0]=r.coerce(S[0]),typeof S[0]!="string"&&S.unshift("%O");let k=0;S[0]=S[0].replace(/%([a-zA-Z%])/g,(I,M)=>{if(I==="%%")return"%";k++;let O=r.formatters[M];if(typeof O=="function"){let B=S[k];I=O.call(x,B),S.splice(k,1),k--}return I}),r.formatArgs.call(x,S),(x.log||r.log).apply(x,S)}return g.namespace=y,g.useColors=r.useColors(),g.color=r.selectColor(y),g.extend=i,g.destroy=r.destroy,Object.defineProperty(g,"enabled",{enumerable:!0,configurable:!1,get:()=>m!==null?m:(b!==r.namespaces&&(b=r.namespaces,_=r.enabled(y)),_),set:S=>{m=S}}),typeof r.init=="function"&&r.init(g),g}function i(y,f){let m=r(this.namespace+(typeof f>"u"?":":f)+y);return m.log=this.log,m}function o(y){r.save(y),r.namespaces=y,r.names=[],r.skips=[];let f=(typeof y=="string"?y:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(let m of f)m[0]==="-"?r.skips.push(m.slice(1)):r.names.push(m)}function s(y,f){let m=0,b=0,_=-1,g=0;for(;m<y.length;)if(b<f.length&&(f[b]===y[m]||f[b]==="*"))f[b]==="*"?(_=b,g=m,b++):(m++,b++);else if(_!==-1)b=_+1,g++,m=g;else return!1;for(;b<f.length&&f[b]==="*";)b++;return b===f.length}function a(){let y=[...r.names,...r.skips.map(f=>"-"+f)].join(",");return r.enable(""),y}function c(y){for(let f of r.skips)if(s(y,f))return!1;for(let f of r.names)if(s(y,f))return!0;return!1}function d(y){return y instanceof Error?y.stack||y.message:y}function p(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")}return r.enable(r.load()),r}e.exports=t}),at=pe((u,e)=>{le(),ce(),ue(),u.formatArgs=n,u.save=l,u.load=r,u.useColors=t,u.storage=i(),u.destroy=(()=>{let s=!1;return()=>{s||(s=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),u.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"];function t(){if(typeof window<"u"&&window.process&&(window.process.type==="renderer"||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let s;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(s=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(s[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)}function n(s){if(s[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+s[0]+(this.useColors?"%c ":" ")+"+"+e.exports.humanize(this.diff),!this.useColors)return;let a="color: "+this.color;s.splice(1,0,a,"color: inherit");let c=0,d=0;s[0].replace(/%[a-zA-Z%]/g,p=>{p!=="%%"&&(c++,p==="%c"&&(d=c))}),s.splice(d,0,a)}u.log=console.debug||console.log||(()=>{});function l(s){try{s?u.storage.setItem("debug",s):u.storage.removeItem("debug")}catch{}}function r(){let s;try{s=u.storage.getItem("debug")||u.storage.getItem("DEBUG")}catch{}return!s&&typeof Pe<"u"&&"env"in Pe&&(s=Pe.env.DEBUG),s}function i(){try{return localStorage}catch{}}e.exports=bu()(u);var{formatters:o}=e.exports;o.j=function(s){try{return JSON.stringify(s)}catch(a){return"[UnexpectedJSONParseError]: "+a.message}}}),yu=pe((u,e)=>{le(),ce(),ue();var t=pu(),{EventEmitter:n}=(Et(),Oe(mt)),l=gu(),r=na(),i=at()("mqtt-packet:parser"),o=class ri extends n{constructor(){super(),this.parser=this.constructor.parser}static parser(a){return this instanceof ri?(this.settings=a||{},this._states=["_parseHeader","_parseLength","_parsePayload","_newPacket"],this._resetState(),this):new ri().parser(a)}_resetState(){i("_resetState: resetting packet, error, _list, and _stateCounter"),this.packet=new l,this.error=null,this._list=t(),this._stateCounter=0}parse(a){for(this.error&&this._resetState(),this._list.append(a),i("parse: current state: %s",this._states[this._stateCounter]);(this.packet.length!==-1||this._list.length>0)&&this[this._states[this._stateCounter]]()&&!this.error;)this._stateCounter++,i("parse: state complete. _stateCounter is now: %d",this._stateCounter),i("parse: packet.length: %d, buffer list length: %d",this.packet.length,this._list.length),this._stateCounter>=this._states.length&&(this._stateCounter=0);return i("parse: exited while loop. packet: %d, buffer list length: %d",this.packet.length,this._list.length),this._list.length}_parseHeader(){let a=this._list.readUInt8(0),c=a>>r.CMD_SHIFT;this.packet.cmd=r.types[c];let d=a&15,p=r.requiredHeaderFlags[c];return p!=null&&d!==p?this._emitError(new Error(r.requiredHeaderFlagsErrors[c])):(this.packet.retain=(a&r.RETAIN_MASK)!==0,this.packet.qos=a>>r.QOS_SHIFT&r.QOS_MASK,this.packet.qos>2?this._emitError(new Error("Packet must not have both QoS bits set to 1")):(this.packet.dup=(a&r.DUP_MASK)!==0,i("_parseHeader: packet: %o",this.packet),this._list.consume(1),!0))}_parseLength(){let a=this._parseVarByteNum(!0);return a&&(this.packet.length=a.value,this._list.consume(a.bytes)),i("_parseLength %d",a.value),!!a}_parsePayload(){i("_parsePayload: payload %O",this._list);let a=!1;if(this.packet.length===0||this._list.length>=this.packet.length){switch(this._pos=0,this.packet.cmd){case"connect":this._parseConnect();break;case"connack":this._parseConnack();break;case"publish":this._parsePublish();break;case"puback":case"pubrec":case"pubrel":case"pubcomp":this._parseConfirmation();break;case"subscribe":this._parseSubscribe();break;case"suback":this._parseSuback();break;case"unsubscribe":this._parseUnsubscribe();break;case"unsuback":this._parseUnsuback();break;case"pingreq":case"pingresp":break;case"disconnect":this._parseDisconnect();break;case"auth":this._parseAuth();break;default:this._emitError(new Error("Not supported"))}a=!0}return i("_parsePayload complete result: %s",a),a}_parseConnect(){i("_parseConnect");let a,c,d,p,y={},f=this.packet,m=this._parseString();if(m===null)return this._emitError(new Error("Cannot parse protocolId"));if(m!=="MQTT"&&m!=="MQIsdp")return this._emitError(new Error("Invalid protocolId"));if(f.protocolId=m,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(f.protocolVersion=this._list.readUInt8(this._pos),f.protocolVersion>=128&&(f.bridgeMode=!0,f.protocolVersion=f.protocolVersion-128),f.protocolVersion!==3&&f.protocolVersion!==4&&f.protocolVersion!==5)return this._emitError(new Error("Invalid protocol version"));if(this._pos++,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(this._list.readUInt8(this._pos)&1)return this._emitError(new Error("Connect flag bit 0 must be 0, but got 1"));y.username=this._list.readUInt8(this._pos)&r.USERNAME_MASK,y.password=this._list.readUInt8(this._pos)&r.PASSWORD_MASK,y.will=this._list.readUInt8(this._pos)&r.WILL_FLAG_MASK;let b=!!(this._list.readUInt8(this._pos)&r.WILL_RETAIN_MASK),_=(this._list.readUInt8(this._pos)&r.WILL_QOS_MASK)>>r.WILL_QOS_SHIFT;if(y.will)f.will={},f.will.retain=b,f.will.qos=_;else{if(b)return this._emitError(new Error("Will Retain Flag must be set to zero when Will Flag is set to 0"));if(_)return this._emitError(new Error("Will QoS must be set to zero when Will Flag is set to 0"))}if(f.clean=(this._list.readUInt8(this._pos)&r.CLEAN_SESSION_MASK)!==0,this._pos++,f.keepalive=this._parseNum(),f.keepalive===-1)return this._emitError(new Error("Packet too short"));if(f.protocolVersion===5){let S=this._parseProperties();Object.getOwnPropertyNames(S).length&&(f.properties=S)}let g=this._parseString();if(g===null)return this._emitError(new Error("Packet too short"));if(f.clientId=g,i("_parseConnect: packet.clientId: %s",f.clientId),y.will){if(f.protocolVersion===5){let S=this._parseProperties();Object.getOwnPropertyNames(S).length&&(f.will.properties=S)}if(a=this._parseString(),a===null)return this._emitError(new Error("Cannot parse will topic"));if(f.will.topic=a,i("_parseConnect: packet.will.topic: %s",f.will.topic),c=this._parseBuffer(),c===null)return this._emitError(new Error("Cannot parse will payload"));f.will.payload=c,i("_parseConnect: packet.will.paylaod: %s",f.will.payload)}if(y.username){if(p=this._parseString(),p===null)return this._emitError(new Error("Cannot parse username"));f.username=p,i("_parseConnect: packet.username: %s",f.username)}if(y.password){if(d=this._parseBuffer(),d===null)return this._emitError(new Error("Cannot parse password"));f.password=d}return this.settings=f,i("_parseConnect: complete"),f}_parseConnack(){i("_parseConnack");let a=this.packet;if(this._list.length<1)return null;let c=this._list.readUInt8(this._pos++);if(c>1)return this._emitError(new Error("Invalid connack flags, bits 7-1 must be set to 0"));if(a.sessionPresent=!!(c&r.SESSIONPRESENT_MASK),this.settings.protocolVersion===5)this._list.length>=2?a.reasonCode=this._list.readUInt8(this._pos++):a.reasonCode=0;else{if(this._list.length<2)return null;a.returnCode=this._list.readUInt8(this._pos++)}if(a.returnCode===-1||a.reasonCode===-1)return this._emitError(new Error("Cannot parse return code"));if(this.settings.protocolVersion===5){let d=this._parseProperties();Object.getOwnPropertyNames(d).length&&(a.properties=d)}i("_parseConnack: complete")}_parsePublish(){i("_parsePublish");let a=this.packet;if(a.topic=this._parseString(),a.topic===null)return this._emitError(new Error("Cannot parse topic"));if(!(a.qos>0&&!this._parseMessageId())){if(this.settings.protocolVersion===5){let c=this._parseProperties();Object.getOwnPropertyNames(c).length&&(a.properties=c)}a.payload=this._list.slice(this._pos,a.length),i("_parsePublish: payload from buffer list: %o",a.payload)}}_parseSubscribe(){i("_parseSubscribe");let a=this.packet,c,d,p,y,f,m,b;if(a.subscriptions=[],!!this._parseMessageId()){if(this.settings.protocolVersion===5){let _=this._parseProperties();Object.getOwnPropertyNames(_).length&&(a.properties=_)}if(a.length<=0)return this._emitError(new Error("Malformed subscribe, no payload specified"));for(;this._pos<a.length;){if(c=this._parseString(),c===null)return this._emitError(new Error("Cannot parse topic"));if(this._pos>=a.length)return this._emitError(new Error("Malformed Subscribe Payload"));if(d=this._parseByte(),this.settings.protocolVersion===5){if(d&192)return this._emitError(new Error("Invalid subscribe topic flag bits, bits 7-6 must be 0"))}else if(d&252)return this._emitError(new Error("Invalid subscribe topic flag bits, bits 7-2 must be 0"));if(p=d&r.SUBSCRIBE_OPTIONS_QOS_MASK,p>2)return this._emitError(new Error("Invalid subscribe QoS, must be <= 2"));if(m=(d>>r.SUBSCRIBE_OPTIONS_NL_SHIFT&r.SUBSCRIBE_OPTIONS_NL_MASK)!==0,f=(d>>r.SUBSCRIBE_OPTIONS_RAP_SHIFT&r.SUBSCRIBE_OPTIONS_RAP_MASK)!==0,y=d>>r.SUBSCRIBE_OPTIONS_RH_SHIFT&r.SUBSCRIBE_OPTIONS_RH_MASK,y>2)return this._emitError(new Error("Invalid retain handling, must be <= 2"));b={topic:c,qos:p},this.settings.protocolVersion===5?(b.nl=m,b.rap=f,b.rh=y):this.settings.bridgeMode&&(b.rh=0,b.rap=!0,b.nl=!0),i("_parseSubscribe: push subscription `%s` to subscription",b),a.subscriptions.push(b)}}}_parseSuback(){i("_parseSuback");let a=this.packet;if(this.packet.granted=[],!!this._parseMessageId()){if(this.settings.protocolVersion===5){let c=this._parseProperties();Object.getOwnPropertyNames(c).length&&(a.properties=c)}if(a.length<=0)return this._emitError(new Error("Malformed suback, no payload specified"));for(;this._pos<this.packet.length;){let c=this._list.readUInt8(this._pos++);if(this.settings.protocolVersion===5){if(!r.MQTT5_SUBACK_CODES[c])return this._emitError(new Error("Invalid suback code"))}else if(c>2&&c!==128)return this._emitError(new Error("Invalid suback QoS, must be 0, 1, 2 or 128"));this.packet.granted.push(c)}}}_parseUnsubscribe(){i("_parseUnsubscribe");let a=this.packet;if(a.unsubscriptions=[],!!this._parseMessageId()){if(this.settings.protocolVersion===5){let c=this._parseProperties();Object.getOwnPropertyNames(c).length&&(a.properties=c)}if(a.length<=0)return this._emitError(new Error("Malformed unsubscribe, no payload specified"));for(;this._pos<a.length;){let c=this._parseString();if(c===null)return this._emitError(new Error("Cannot parse topic"));i("_parseUnsubscribe: push topic `%s` to unsubscriptions",c),a.unsubscriptions.push(c)}}}_parseUnsuback(){i("_parseUnsuback");let a=this.packet;if(!this._parseMessageId())return this._emitError(new Error("Cannot parse messageId"));if((this.settings.protocolVersion===3||this.settings.protocolVersion===4)&&a.length!==2)return this._emitError(new Error("Malformed unsuback, payload length must be 2"));if(a.length<=0)return this._emitError(new Error("Malformed unsuback, no payload specified"));if(this.settings.protocolVersion===5){let c=this._parseProperties();for(Object.getOwnPropertyNames(c).length&&(a.properties=c),a.granted=[];this._pos<this.packet.length;){let d=this._list.readUInt8(this._pos++);if(!r.MQTT5_UNSUBACK_CODES[d])return this._emitError(new Error("Invalid unsuback code"));this.packet.granted.push(d)}}}_parseConfirmation(){i("_parseConfirmation: packet.cmd: `%s`",this.packet.cmd);let a=this.packet;if(this._parseMessageId(),this.settings.protocolVersion===5){if(a.length>2){switch(a.reasonCode=this._parseByte(),this.packet.cmd){case"puback":case"pubrec":if(!r.MQTT5_PUBACK_PUBREC_CODES[a.reasonCode])return this._emitError(new Error("Invalid "+this.packet.cmd+" reason code"));break;case"pubrel":case"pubcomp":if(!r.MQTT5_PUBREL_PUBCOMP_CODES[a.reasonCode])return this._emitError(new Error("Invalid "+this.packet.cmd+" reason code"));break}i("_parseConfirmation: packet.reasonCode `%d`",a.reasonCode)}else a.reasonCode=0;if(a.length>3){let c=this._parseProperties();Object.getOwnPropertyNames(c).length&&(a.properties=c)}}return!0}_parseDisconnect(){let a=this.packet;if(i("_parseDisconnect"),this.settings.protocolVersion===5){this._list.length>0?(a.reasonCode=this._parseByte(),r.MQTT5_DISCONNECT_CODES[a.reasonCode]||this._emitError(new Error("Invalid disconnect reason code"))):a.reasonCode=0;let c=this._parseProperties();Object.getOwnPropertyNames(c).length&&(a.properties=c)}return i("_parseDisconnect result: true"),!0}_parseAuth(){i("_parseAuth");let a=this.packet;if(this.settings.protocolVersion!==5)return this._emitError(new Error("Not supported auth packet for this version MQTT"));if(a.reasonCode=this._parseByte(),!r.MQTT5_AUTH_CODES[a.reasonCode])return this._emitError(new Error("Invalid auth reason code"));let c=this._parseProperties();return Object.getOwnPropertyNames(c).length&&(a.properties=c),i("_parseAuth: result: true"),!0}_parseMessageId(){let a=this.packet;return a.messageId=this._parseNum(),a.messageId===null?(this._emitError(new Error("Cannot parse messageId")),!1):(i("_parseMessageId: packet.messageId %d",a.messageId),!0)}_parseString(a){let c=this._parseNum(),d=c+this._pos;if(c===-1||d>this._list.length||d>this.packet.length)return null;let p=this._list.toString("utf8",this._pos,d);return this._pos+=c,i("_parseString: result: %s",p),p}_parseStringPair(){return i("_parseStringPair"),{name:this._parseString(),value:this._parseString()}}_parseBuffer(){let a=this._parseNum(),c=a+this._pos;if(a===-1||c>this._list.length||c>this.packet.length)return null;let d=this._list.slice(this._pos,c);return this._pos+=a,i("_parseBuffer: result: %o",d),d}_parseNum(){if(this._list.length-this._pos<2)return-1;let a=this._list.readUInt16BE(this._pos);return this._pos+=2,i("_parseNum: result: %s",a),a}_parse4ByteNum(){if(this._list.length-this._pos<4)return-1;let a=this._list.readUInt32BE(this._pos);return this._pos+=4,i("_parse4ByteNum: result: %s",a),a}_parseVarByteNum(a){i("_parseVarByteNum");let c=4,d=0,p=1,y=0,f=!1,m,b=this._pos?this._pos:0;for(;d<c&&b+d<this._list.length;){if(m=this._list.readUInt8(b+d++),y+=p*(m&r.VARBYTEINT_MASK),p*=128,(m&r.VARBYTEINT_FIN_MASK)===0){f=!0;break}if(this._list.length<=d)break}return!f&&d===c&&this._list.length>=d&&this._emitError(new Error("Invalid variable byte integer")),b&&(this._pos+=d),f?a?f={bytes:d,value:y}:f=y:f=!1,i("_parseVarByteNum: result: %o",f),f}_parseByte(){let a;return this._pos<this._list.length&&(a=this._list.readUInt8(this._pos),this._pos++),i("_parseByte: result: %o",a),a}_parseByType(a){switch(i("_parseByType: type: %s",a),a){case"byte":return this._parseByte()!==0;case"int8":return this._parseByte();case"int16":return this._parseNum();case"int32":return this._parse4ByteNum();case"var":return this._parseVarByteNum();case"string":return this._parseString();case"pair":return this._parseStringPair();case"binary":return this._parseBuffer()}}_parseProperties(){i("_parseProperties");let a=this._parseVarByteNum(),c=this._pos+a,d={};for(;this._pos<c;){let p=this._parseByte();if(!p)return this._emitError(new Error("Cannot parse property code type")),!1;let y=r.propertiesCodes[p];if(!y)return this._emitError(new Error("Unknown property")),!1;if(y==="userProperties"){d[y]||(d[y]=Object.create(null));let f=this._parseByType(r.propertiesTypes[y]);if(d[y][f.name])if(Array.isArray(d[y][f.name]))d[y][f.name].push(f.value);else{let m=d[y][f.name];d[y][f.name]=[m],d[y][f.name].push(f.value)}else d[y][f.name]=f.value;continue}d[y]?Array.isArray(d[y])?d[y].push(this._parseByType(r.propertiesTypes[y])):(d[y]=[d[y]],d[y].push(this._parseByType(r.propertiesTypes[y]))):d[y]=this._parseByType(r.propertiesTypes[y])}return d}_newPacket(){return i("_newPacket"),this.packet&&(this._list.consume(this.packet.length),i("_newPacket: parser emit packet: packet.cmd: %s, packet.payload: %s, packet.length: %d",this.packet.cmd,this.packet.payload,this.packet.length),this.emit("packet",this.packet)),i("_newPacket: new packet"),this.packet=new l,this._pos=0,!0}_emitError(a){i("_emitError",a),this.error=a,this.emit("error",a)}};e.exports=o}),vu=pe((u,e)=>{le(),ce(),ue();var{Buffer:t}=(Ne(),Oe(Le)),n=65536,l={},r=t.isBuffer(t.from([1,2]).subarray(0,1));function i(c){let d=t.allocUnsafe(2);return d.writeUInt8(c>>8,0),d.writeUInt8(c&255,1),d}function o(){for(let c=0;c<n;c++)l[c]=i(c)}function s(c){let d=0,p=0,y=t.allocUnsafe(4);do d=c%128|0,c=c/128|0,c>0&&(d=d|128),y.writeUInt8(d,p++);while(c>0&&p<4);return c>0&&(p=0),r?y.subarray(0,p):y.slice(0,p)}function a(c){let d=t.allocUnsafe(4);return d.writeUInt32BE(c,0),d}e.exports={cache:l,generateCache:o,generateNumber:i,genBufVariableByteInt:s,generate4ByteBuffer:a}}),wu=pe((u,e)=>{le(),ce(),ue(),typeof Pe>"u"||!Pe.version||Pe.version.indexOf("v0.")===0||Pe.version.indexOf("v1.")===0&&Pe.version.indexOf("v1.8.")!==0?e.exports={nextTick:t}:e.exports=Pe;function t(n,l,r,i){if(typeof n!="function")throw new TypeError('"callback" argument must be a function');var o=arguments.length,s,a;switch(o){case 0:case 1:return Pe.nextTick(n);case 2:return Pe.nextTick(function(){n.call(null,l)});case 3:return Pe.nextTick(function(){n.call(null,l,r)});case 4:return Pe.nextTick(function(){n.call(null,l,r,i)});default:for(s=new Array(o-1),a=0;a<s.length;)s[a++]=arguments[a];return Pe.nextTick(function(){n.apply(null,s)})}}}),ia=pe((u,e)=>{le(),ce(),ue();var t=na(),{Buffer:n}=(Ne(),Oe(Le)),l=n.allocUnsafe(0),r=n.from([0]),i=vu(),o=wu().nextTick,s=at()("mqtt-packet:writeToStream"),a=i.cache,c=i.generateNumber,d=i.generateCache,p=i.genBufVariableByteInt,y=i.generate4ByteBuffer,f=Y,m=!0;function b(V,L,ne){switch(s("generate called"),L.cork&&(L.cork(),o(_,L)),m&&(m=!1,d()),s("generate: packet.cmd: %s",V.cmd),V.cmd){case"connect":return g(V,L);case"connack":return S(V,L,ne);case"publish":return x(V,L,ne);case"puback":case"pubrec":case"pubrel":case"pubcomp":return v(V,L,ne);case"subscribe":return E(V,L,ne);case"suback":return k(V,L,ne);case"unsubscribe":return I(V,L,ne);case"unsuback":return M(V,L,ne);case"pingreq":case"pingresp":return O(V,L);case"disconnect":return B(V,L,ne);case"auth":return T(V,L,ne);default:return L.destroy(new Error("Unknown command")),!1}}Object.defineProperty(b,"cacheNumbers",{get(){return f===Y},set(V){V?((!a||Object.keys(a).length===0)&&(m=!0),f=Y):(m=!1,f=K)}});function _(V){V.uncork()}function g(V,L,ne){let H=V||{},G=H.protocolId||"MQTT",Q=H.protocolVersion||4,me=H.will,se=H.clean,R=H.keepalive||0,$=H.clientId||"",ee=H.username,fe=H.password,de=H.properties;se===void 0&&(se=!0);let ye=0;if(typeof G!="string"&&!n.isBuffer(G))return L.destroy(new Error("Invalid protocolId")),!1;if(ye+=G.length+2,Q!==3&&Q!==4&&Q!==5)return L.destroy(new Error("Invalid protocol version")),!1;if(ye+=1,(typeof $=="string"||n.isBuffer($))&&($||Q>=4)&&($||se))ye+=n.byteLength($)+2;else{if(Q<4)return L.destroy(new Error("clientId must be supplied before 3.1.1")),!1;if(se*1===0)return L.destroy(new Error("clientId must be given if cleanSession set to 0")),!1}if(typeof R!="number"||R<0||R>65535||R%1!==0)return L.destroy(new Error("Invalid keepalive")),!1;ye+=2,ye+=1;let q,ge;if(Q===5){if(q=Z(L,de),!q)return!1;ye+=q.length}if(me){if(typeof me!="object")return L.destroy(new Error("Invalid will")),!1;if(!me.topic||typeof me.topic!="string")return L.destroy(new Error("Invalid will topic")),!1;if(ye+=n.byteLength(me.topic)+2,ye+=2,me.payload)if(me.payload.length>=0)typeof me.payload=="string"?ye+=n.byteLength(me.payload):ye+=me.payload.length;else return L.destroy(new Error("Invalid will payload")),!1;if(ge={},Q===5){if(ge=Z(L,me.properties),!ge)return!1;ye+=ge.length}}let ve=!1;if(ee!=null)if(we(ee))ve=!0,ye+=n.byteLength(ee)+2;else return L.destroy(new Error("Invalid username")),!1;if(fe!=null){if(!ve)return L.destroy(new Error("Username is required to use password")),!1;if(we(fe))ye+=te(fe)+2;else return L.destroy(new Error("Invalid password")),!1}L.write(t.CONNECT_HEADER),F(L,ye),D(L,G),H.bridgeMode&&(Q+=128),L.write(Q===131?t.VERSION131:Q===132?t.VERSION132:Q===4?t.VERSION4:Q===5?t.VERSION5:t.VERSION3);let oe=0;return oe|=ee!=null?t.USERNAME_MASK:0,oe|=fe!=null?t.PASSWORD_MASK:0,oe|=me&&me.retain?t.WILL_RETAIN_MASK:0,oe|=me&&me.qos?me.qos<<t.WILL_QOS_SHIFT:0,oe|=me?t.WILL_FLAG_MASK:0,oe|=se?t.CLEAN_SESSION_MASK:0,L.write(n.from([oe])),f(L,R),Q===5&&q.write(),D(L,$),me&&(Q===5&&ge.write(),N(L,me.topic),D(L,me.payload)),ee!=null&&D(L,ee),fe!=null&&D(L,fe),!0}function S(V,L,ne){let H=ne?ne.protocolVersion:4,G=V||{},Q=H===5?G.reasonCode:G.returnCode,me=G.properties,se=2;if(typeof Q!="number")return L.destroy(new Error("Invalid return code")),!1;let R=null;if(H===5){if(R=Z(L,me),!R)return!1;se+=R.length}return L.write(t.CONNACK_HEADER),F(L,se),L.write(G.sessionPresent?t.SESSIONPRESENT_HEADER:r),L.write(n.from([Q])),R?.write(),!0}function x(V,L,ne){s("publish: packet: %o",V);let H=ne?ne.protocolVersion:4,G=V||{},Q=G.qos||0,me=G.retain?t.RETAIN_MASK:0,se=G.topic,R=G.payload||l,$=G.messageId,ee=G.properties,fe=0;if(typeof se=="string")fe+=n.byteLength(se)+2;else if(n.isBuffer(se))fe+=se.length+2;else return L.destroy(new Error("Invalid topic")),!1;if(n.isBuffer(R)?fe+=R.length:fe+=n.byteLength(R),Q&&typeof $!="number")return L.destroy(new Error("Invalid messageId")),!1;Q&&(fe+=2);let de=null;if(H===5){if(de=Z(L,ee),!de)return!1;fe+=de.length}return L.write(t.PUBLISH_HEADER[Q][G.dup?1:0][me?1:0]),F(L,fe),f(L,te(se)),L.write(se),Q>0&&f(L,$),de?.write(),s("publish: payload: %o",R),L.write(R)}function v(V,L,ne){let H=ne?ne.protocolVersion:4,G=V||{},Q=G.cmd||"puback",me=G.messageId,se=G.dup&&Q==="pubrel"?t.DUP_MASK:0,R=0,$=G.reasonCode,ee=G.properties,fe=H===5?3:2;if(Q==="pubrel"&&(R=1),typeof me!="number")return L.destroy(new Error("Invalid messageId")),!1;let de=null;if(H===5&&typeof ee=="object"){if(de=P(L,ee,ne,fe),!de)return!1;fe+=de.length}return L.write(t.ACKS[Q][R][se][0]),fe===3&&(fe+=$!==0?1:-1),F(L,fe),f(L,me),H===5&&fe!==2&&L.write(n.from([$])),de!==null?de.write():fe===4&&L.write(n.from([0])),!0}function E(V,L,ne){s("subscribe: packet: ");let H=ne?ne.protocolVersion:4,G=V||{},Q=G.dup?t.DUP_MASK:0,me=G.messageId,se=G.subscriptions,R=G.properties,$=0;if(typeof me!="number")return L.destroy(new Error("Invalid messageId")),!1;$+=2;let ee=null;if(H===5){if(ee=Z(L,R),!ee)return!1;$+=ee.length}if(typeof se=="object"&&se.length)for(let de=0;de<se.length;de+=1){let ye=se[de].topic,q=se[de].qos;if(typeof ye!="string")return L.destroy(new Error("Invalid subscriptions - invalid topic")),!1;if(typeof q!="number")return L.destroy(new Error("Invalid subscriptions - invalid qos")),!1;if(H===5){if(typeof(se[de].nl||!1)!="boolean")return L.destroy(new Error("Invalid subscriptions - invalid No Local")),!1;if(typeof(se[de].rap||!1)!="boolean")return L.destroy(new Error("Invalid subscriptions - invalid Retain as Published")),!1;let ge=se[de].rh||0;if(typeof ge!="number"||ge>2)return L.destroy(new Error("Invalid subscriptions - invalid Retain Handling")),!1}$+=n.byteLength(ye)+2+1}else return L.destroy(new Error("Invalid subscriptions")),!1;s("subscribe: writing to stream: %o",t.SUBSCRIBE_HEADER),L.write(t.SUBSCRIBE_HEADER[1][Q?1:0][0]),F(L,$),f(L,me),ee!==null&&ee.write();let fe=!0;for(let de of se){let ye=de.topic,q=de.qos,ge=+de.nl,ve=+de.rap,oe=de.rh,Te;N(L,ye),Te=t.SUBSCRIBE_OPTIONS_QOS[q],H===5&&(Te|=ge?t.SUBSCRIBE_OPTIONS_NL:0,Te|=ve?t.SUBSCRIBE_OPTIONS_RAP:0,Te|=oe?t.SUBSCRIBE_OPTIONS_RH[oe]:0),fe=L.write(n.from([Te]))}return fe}function k(V,L,ne){let H=ne?ne.protocolVersion:4,G=V||{},Q=G.messageId,me=G.granted,se=G.properties,R=0;if(typeof Q!="number")return L.destroy(new Error("Invalid messageId")),!1;if(R+=2,typeof me=="object"&&me.length)for(let ee=0;ee<me.length;ee+=1){if(typeof me[ee]!="number")return L.destroy(new Error("Invalid qos vector")),!1;R+=1}else return L.destroy(new Error("Invalid qos vector")),!1;let $=null;if(H===5){if($=P(L,se,ne,R),!$)return!1;R+=$.length}return L.write(t.SUBACK_HEADER),F(L,R),f(L,Q),$!==null&&$.write(),L.write(n.from(me))}function I(V,L,ne){let H=ne?ne.protocolVersion:4,G=V||{},Q=G.messageId,me=G.dup?t.DUP_MASK:0,se=G.unsubscriptions,R=G.properties,$=0;if(typeof Q!="number")return L.destroy(new Error("Invalid messageId")),!1;if($+=2,typeof se=="object"&&se.length)for(let de=0;de<se.length;de+=1){if(typeof se[de]!="string")return L.destroy(new Error("Invalid unsubscriptions")),!1;$+=n.byteLength(se[de])+2}else return L.destroy(new Error("Invalid unsubscriptions")),!1;let ee=null;if(H===5){if(ee=Z(L,R),!ee)return!1;$+=ee.length}L.write(t.UNSUBSCRIBE_HEADER[1][me?1:0][0]),F(L,$),f(L,Q),ee!==null&&ee.write();let fe=!0;for(let de=0;de<se.length;de++)fe=N(L,se[de]);return fe}function M(V,L,ne){let H=ne?ne.protocolVersion:4,G=V||{},Q=G.messageId,me=G.dup?t.DUP_MASK:0,se=G.granted,R=G.properties,$=G.cmd,ee=0,fe=2;if(typeof Q!="number")return L.destroy(new Error("Invalid messageId")),!1;if(H===5)if(typeof se=="object"&&se.length)for(let ye=0;ye<se.length;ye+=1){if(typeof se[ye]!="number")return L.destroy(new Error("Invalid qos vector")),!1;fe+=1}else return L.destroy(new Error("Invalid qos vector")),!1;let de=null;if(H===5){if(de=P(L,R,ne,fe),!de)return!1;fe+=de.length}return L.write(t.ACKS[$][ee][me][0]),F(L,fe),f(L,Q),de!==null&&de.write(),H===5&&L.write(n.from(se)),!0}function O(V,L,ne){return L.write(t.EMPTY[V.cmd])}function B(V,L,ne){let H=ne?ne.protocolVersion:4,G=V||{},Q=G.reasonCode,me=G.properties,se=H===5?1:0,R=null;if(H===5){if(R=P(L,me,ne,se),!R)return!1;se+=R.length}return L.write(n.from([t.codes.disconnect<<4])),F(L,se),H===5&&L.write(n.from([Q])),R!==null&&R.write(),!0}function T(V,L,ne){let H=ne?ne.protocolVersion:4,G=V||{},Q=G.reasonCode,me=G.properties,se=H===5?1:0;H!==5&&L.destroy(new Error("Invalid mqtt version for auth packet"));let R=P(L,me,ne,se);return R?(se+=R.length,L.write(n.from([t.codes.auth<<4])),F(L,se),L.write(n.from([Q])),R!==null&&R.write(),!0):!1}var W={};function F(V,L){if(L>t.VARBYTEINT_MAX)return V.destroy(new Error(`Invalid variable byte integer: ${L}`)),!1;let ne=W[L];return ne||(ne=p(L),L<16384&&(W[L]=ne)),s("writeVarByteInt: writing to stream: %o",ne),V.write(ne)}function N(V,L){let ne=n.byteLength(L);return f(V,ne),s("writeString: %s",L),V.write(L,"utf8")}function ae(V,L,ne){N(V,L),N(V,ne)}function Y(V,L){return s("writeNumberCached: number: %d",L),s("writeNumberCached: %o",a[L]),V.write(a[L])}function K(V,L){let ne=c(L);return s("writeNumberGenerated: %o",ne),V.write(ne)}function re(V,L){let ne=y(L);return s("write4ByteNumber: %o",ne),V.write(ne)}function D(V,L){typeof L=="string"?N(V,L):L?(f(V,L.length),V.write(L)):f(V,0)}function Z(V,L){if(typeof L!="object"||L.length!=null)return{length:1,write(){be(V,{},0)}};let ne=0;function H(G,Q){let me=t.propertiesTypes[G],se=0;switch(me){case"byte":{if(typeof Q!="boolean")return V.destroy(new Error(`Invalid ${G}: ${Q}`)),!1;se+=2;break}case"int8":{if(typeof Q!="number"||Q<0||Q>255)return V.destroy(new Error(`Invalid ${G}: ${Q}`)),!1;se+=2;break}case"binary":{if(Q&&Q===null)return V.destroy(new Error(`Invalid ${G}: ${Q}`)),!1;se+=1+n.byteLength(Q)+2;break}case"int16":{if(typeof Q!="number"||Q<0||Q>65535)return V.destroy(new Error(`Invalid ${G}: ${Q}`)),!1;se+=3;break}case"int32":{if(typeof Q!="number"||Q<0||Q>4294967295)return V.destroy(new Error(`Invalid ${G}: ${Q}`)),!1;se+=5;break}case"var":{if(typeof Q!="number"||Q<0||Q>268435455)return V.destroy(new Error(`Invalid ${G}: ${Q}`)),!1;se+=1+n.byteLength(p(Q));break}case"string":{if(typeof Q!="string")return V.destroy(new Error(`Invalid ${G}: ${Q}`)),!1;se+=3+n.byteLength(Q.toString());break}case"pair":{if(typeof Q!="object")return V.destroy(new Error(`Invalid ${G}: ${Q}`)),!1;se+=Object.getOwnPropertyNames(Q).reduce((R,$)=>{let ee=Q[$];return Array.isArray(ee)?R+=ee.reduce((fe,de)=>(fe+=3+n.byteLength($.toString())+2+n.byteLength(de.toString()),fe),0):R+=3+n.byteLength($.toString())+2+n.byteLength(Q[$].toString()),R},0);break}default:return V.destroy(new Error(`Invalid property ${G}: ${Q}`)),!1}return se}if(L)for(let G in L){let Q=0,me=0,se=L[G];if(se!==void 0){if(Array.isArray(se))for(let R=0;R<se.length;R++){if(me=H(G,se[R]),!me)return!1;Q+=me}else{if(me=H(G,se),!me)return!1;Q=me}if(!Q)return!1;ne+=Q}}return{length:n.byteLength(p(ne))+ne,write(){be(V,L,ne)}}}function P(V,L,ne,H){let G=["reasonString","userProperties"],Q=ne&&ne.properties&&ne.properties.maximumPacketSize?ne.properties.maximumPacketSize:0,me=Z(V,L);if(Q)for(;H+me.length>Q;){let se=G.shift();if(se&&L[se])delete L[se],me=Z(V,L);else return!1}return me}function J(V,L,ne){switch(t.propertiesTypes[L]){case"byte":{V.write(n.from([t.properties[L]])),V.write(n.from([+ne]));break}case"int8":{V.write(n.from([t.properties[L]])),V.write(n.from([ne]));break}case"binary":{V.write(n.from([t.properties[L]])),D(V,ne);break}case"int16":{V.write(n.from([t.properties[L]])),f(V,ne);break}case"int32":{V.write(n.from([t.properties[L]])),re(V,ne);break}case"var":{V.write(n.from([t.properties[L]])),F(V,ne);break}case"string":{V.write(n.from([t.properties[L]])),N(V,ne);break}case"pair":{Object.getOwnPropertyNames(ne).forEach(H=>{let G=ne[H];Array.isArray(G)?G.forEach(Q=>{V.write(n.from([t.properties[L]])),ae(V,H.toString(),Q.toString())}):(V.write(n.from([t.properties[L]])),ae(V,H.toString(),G.toString()))});break}default:return V.destroy(new Error(`Invalid property ${L} value: ${ne}`)),!1}}function be(V,L,ne){F(V,ne);for(let H in L)if(Object.prototype.hasOwnProperty.call(L,H)&&L[H]!=null){let G=L[H];if(Array.isArray(G))for(let Q=0;Q<G.length;Q++)J(V,H,G[Q]);else J(V,H,G)}}function te(V){return V?V instanceof n?V.length:n.byteLength(V):0}function we(V){return typeof V=="string"||V instanceof n}e.exports=b}),_u=pe((u,e)=>{le(),ce(),ue();var t=ia(),{EventEmitter:n}=(Et(),Oe(mt)),{Buffer:l}=(Ne(),Oe(Le));function r(o,s){let a=new i;return t(o,a,s),a.concat()}var i=class extends n{constructor(){super(),this._array=new Array(20),this._i=0}write(o){return this._array[this._i++]=o,!0}concat(){let o=0,s=new Array(this._array.length),a=this._array,c=0,d;for(d=0;d<a.length&&a[d]!==void 0;d++)typeof a[d]!="string"?s[d]=a[d].length:s[d]=l.byteLength(a[d]),o+=s[d];let p=l.allocUnsafe(o);for(d=0;d<a.length&&a[d]!==void 0;d++)typeof a[d]!="string"?(a[d].copy(p,c),c+=s[d]):(p.write(a[d],c),c+=s[d]);return p}destroy(o){o&&this.emit("error",o)}};e.exports=r}),Su=pe(u=>{le(),ce(),ue(),u.parser=yu().parser,u.generate=_u(),u.writeToStream=ia()}),ku=pe((u,e)=>{le(),ce(),ue(),e.exports=n;function t(r){return r instanceof Tr?Tr.from(r):new r.constructor(r.buffer.slice(),r.byteOffset,r.length)}function n(r){if(r=r||{},r.circles)return l(r);let i=new Map;if(i.set(Date,d=>new Date(d)),i.set(Map,(d,p)=>new Map(s(Array.from(d),p))),i.set(Set,(d,p)=>new Set(s(Array.from(d),p))),r.constructorHandlers)for(let d of r.constructorHandlers)i.set(d[0],d[1]);let o=null;return r.proto?c:a;function s(d,p){let y=Object.keys(d),f=new Array(y.length);for(let m=0;m<y.length;m++){let b=y[m],_=d[b];typeof _!="object"||_===null?f[b]=_:_.constructor!==Object&&(o=i.get(_.constructor))?f[b]=o(_,p):ArrayBuffer.isView(_)?f[b]=t(_):f[b]=p(_)}return f}function a(d){if(typeof d!="object"||d===null)return d;if(Array.isArray(d))return s(d,a);if(d.constructor!==Object&&(o=i.get(d.constructor)))return o(d,a);let p={};for(let y in d){if(Object.hasOwnProperty.call(d,y)===!1)continue;let f=d[y];typeof f!="object"||f===null?p[y]=f:f.constructor!==Object&&(o=i.get(f.constructor))?p[y]=o(f,a):ArrayBuffer.isView(f)?p[y]=t(f):p[y]=a(f)}return p}function c(d){if(typeof d!="object"||d===null)return d;if(Array.isArray(d))return s(d,c);if(d.constructor!==Object&&(o=i.get(d.constructor)))return o(d,c);let p={};for(let y in d){let f=d[y];typeof f!="object"||f===null?p[y]=f:f.constructor!==Object&&(o=i.get(f.constructor))?p[y]=o(f,c):ArrayBuffer.isView(f)?p[y]=t(f):p[y]=c(f)}return p}}function l(r){let i=[],o=[],s=new Map;if(s.set(Date,y=>new Date(y)),s.set(Map,(y,f)=>new Map(c(Array.from(y),f))),s.set(Set,(y,f)=>new Set(c(Array.from(y),f))),r.constructorHandlers)for(let y of r.constructorHandlers)s.set(y[0],y[1]);let a=null;return r.proto?p:d;function c(y,f){let m=Object.keys(y),b=new Array(m.length);for(let _=0;_<m.length;_++){let g=m[_],S=y[g];if(typeof S!="object"||S===null)b[g]=S;else if(S.constructor!==Object&&(a=s.get(S.constructor)))b[g]=a(S,f);else if(ArrayBuffer.isView(S))b[g]=t(S);else{let x=i.indexOf(S);x!==-1?b[g]=o[x]:b[g]=f(S)}}return b}function d(y){if(typeof y!="object"||y===null)return y;if(Array.isArray(y))return c(y,d);if(y.constructor!==Object&&(a=s.get(y.constructor)))return a(y,d);let f={};i.push(y),o.push(f);for(let m in y){if(Object.hasOwnProperty.call(y,m)===!1)continue;let b=y[m];if(typeof b!="object"||b===null)f[m]=b;else if(b.constructor!==Object&&(a=s.get(b.constructor)))f[m]=a(b,d);else if(ArrayBuffer.isView(b))f[m]=t(b);else{let _=i.indexOf(b);_!==-1?f[m]=o[_]:f[m]=d(b)}}return i.pop(),o.pop(),f}function p(y){if(typeof y!="object"||y===null)return y;if(Array.isArray(y))return c(y,p);if(y.constructor!==Object&&(a=s.get(y.constructor)))return a(y,p);let f={};i.push(y),o.push(f);for(let m in y){let b=y[m];if(typeof b!="object"||b===null)f[m]=b;else if(b.constructor!==Object&&(a=s.get(b.constructor)))f[m]=a(b,p);else if(ArrayBuffer.isView(b))f[m]=t(b);else{let _=i.indexOf(b);_!==-1?f[m]=o[_]:f[m]=p(b)}}return i.pop(),o.pop(),f}}}),Eu=pe((u,e)=>{le(),ce(),ue(),e.exports=ku()()}),sa=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"__esModule",{value:!0}),u.validateTopic=e,u.validateTopics=t;function e(n){let l=n.split("/");for(let r=0;r<l.length;r++)if(l[r]!=="+"){if(l[r]==="#")return r===l.length-1;if(l[r].indexOf("+")!==-1||l[r].indexOf("#")!==-1)return!1}return!0}function t(n){if(n.length===0)return"empty_topic_list";for(let l=0;l<n.length;l++)if(!e(n[l]))return n[l];return null}}),oa=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"__esModule",{value:!0});var e=At(),t={objectMode:!0},n={clean:!0},l=class{options;_inflights;constructor(r){this.options=r||{},this.options={...n,...r},this._inflights=new Map}put(r,i){return this._inflights.set(r.messageId,r),i&&i(),this}createStream(){let r=new e.Readable(t),i=[],o=!1,s=0;return this._inflights.forEach((a,c)=>{i.push(a)}),r._read=()=>{!o&&s<i.length?r.push(i[s++]):r.push(null)},r.destroy=a=>{if(!o)return o=!0,setTimeout(()=>{r.emit("close")},0),r},r}del(r,i){let o=this._inflights.get(r.messageId);return o?(this._inflights.delete(r.messageId),i(null,o)):i&&i(new Error("missing packet")),this}get(r,i){let o=this._inflights.get(r.messageId);return o?i(null,o):i&&i(new Error("missing packet")),this}close(r){this.options.clean&&(this._inflights=null),r&&r()}};u.default=l}),xu=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"__esModule",{value:!0});var e=[0,16,128,131,135,144,145,151,153],t=(n,l,r)=>{n.log("handlePublish: packet %o",l),r=typeof r<"u"?r:n.noop;let i=l.topic.toString(),o=l.payload,{qos:s}=l,{messageId:a}=l,{options:c}=n;if(n.options.protocolVersion===5){let d;if(l.properties&&(d=l.properties.topicAlias),typeof d<"u")if(i.length===0)if(d>0&&d<=65535){let p=n.topicAliasRecv.getTopicByAlias(d);if(p)i=p,n.log("handlePublish :: topic complemented by alias. topic: %s - alias: %d",i,d);else{n.log("handlePublish :: unregistered topic alias. alias: %d",d),n.emit("error",new Error("Received unregistered Topic Alias"));return}}else{n.log("handlePublish :: topic alias out of range. alias: %d",d),n.emit("error",new Error("Received Topic Alias is out of range"));return}else if(n.topicAliasRecv.put(i,d))n.log("handlePublish :: registered topic: %s - alias: %d",i,d);else{n.log("handlePublish :: topic alias out of range. alias: %d",d),n.emit("error",new Error("Received Topic Alias is out of range"));return}}switch(n.log("handlePublish: qos %d",s),s){case 2:{c.customHandleAcks(i,o,l,(d,p)=>{if(typeof d=="number"&&(p=d,d=null),d)return n.emit("error",d);if(e.indexOf(p)===-1)return n.emit("error",new Error("Wrong reason code for pubrec"));p?n._sendPacket({cmd:"pubrec",messageId:a,reasonCode:p},r):n.incomingStore.put(l,()=>{n._sendPacket({cmd:"pubrec",messageId:a},r)})});break}case 1:{c.customHandleAcks(i,o,l,(d,p)=>{if(typeof d=="number"&&(p=d,d=null),d)return n.emit("error",d);if(e.indexOf(p)===-1)return n.emit("error",new Error("Wrong reason code for puback"));p||n.emit("message",i,o,l),n.handleMessage(l,y=>{if(y)return r&&r(y);n._sendPacket({cmd:"puback",messageId:a,reasonCode:p},r)})});break}case 0:n.emit("message",i,o,l),n.handleMessage(l,r);break;default:n.log("handlePublish: unknown QoS. Doing nothing.");break}};u.default=t}),Au=pe((u,e)=>{e.exports={version:"5.15.0"}}),Nt=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"__esModule",{value:!0}),u.MQTTJS_VERSION=u.nextTick=u.ErrorWithSubackPacket=u.ErrorWithReasonCode=void 0,u.applyMixin=n;var e=class aa extends Error{code;constructor(r,i){super(r),this.code=i,Object.setPrototypeOf(this,aa.prototype),Object.getPrototypeOf(this).name="ErrorWithReasonCode"}};u.ErrorWithReasonCode=e;var t=class la extends Error{packet;constructor(r,i){super(r),this.packet=i,Object.setPrototypeOf(this,la.prototype),Object.getPrototypeOf(this).name="ErrorWithSubackPacket"}};u.ErrorWithSubackPacket=t;function n(l,r,i=!1){let o=[r];for(;;){let s=o[0],a=Object.getPrototypeOf(s);if(a?.prototype)o.unshift(a);else break}for(let s of o)for(let a of Object.getOwnPropertyNames(s.prototype))(i||a!=="constructor")&&Object.defineProperty(l.prototype,a,Object.getOwnPropertyDescriptor(s.prototype,a)??Object.create(null))}u.nextTick=typeof Pe?.nextTick=="function"?Pe.nextTick:l=>{setTimeout(l,0)},u.MQTTJS_VERSION=Au().version}),jr=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"__esModule",{value:!0}),u.ReasonCodes=void 0;var e=Nt();u.ReasonCodes={0:"",1:"Unacceptable protocol version",2:"Identifier rejected",3:"Server unavailable",4:"Bad username or password",5:"Not authorized",16:"No matching subscribers",17:"No subscription existed",128:"Unspecified error",129:"Malformed Packet",130:"Protocol Error",131:"Implementation specific error",132:"Unsupported Protocol Version",133:"Client Identifier not valid",134:"Bad User Name or Password",135:"Not authorized",136:"Server unavailable",137:"Server busy",138:"Banned",139:"Server shutting down",140:"Bad authentication method",141:"Keep Alive timeout",142:"Session taken over",143:"Topic Filter invalid",144:"Topic Name invalid",145:"Packet identifier in use",146:"Packet Identifier not found",147:"Receive Maximum exceeded",148:"Topic Alias invalid",149:"Packet too large",150:"Message rate too high",151:"Quota exceeded",152:"Administrative action",153:"Payload format invalid",154:"Retain not supported",155:"QoS not supported",156:"Use another server",157:"Server moved",158:"Shared Subscriptions not supported",159:"Connection rate exceeded",160:"Maximum connect time",161:"Subscription Identifiers not supported",162:"Wildcard Subscriptions not supported"};var t=(n,l)=>{let{messageId:r}=l,i=l.cmd,o=null,s=n.outgoing[r]?n.outgoing[r].cb:null,a=null;if(!s){n.log("_handleAck :: Server sent an ack in error. Ignoring.");return}switch(n.log("_handleAck :: packet type",i),i){case"pubcomp":case"puback":{let c=l.reasonCode;c&&c>0&&c!==16?(a=new e.ErrorWithReasonCode(`Publish error: ${u.ReasonCodes[c]}`,c),n._removeOutgoingAndStoreMessage(r,()=>{s(a,l)})):n._removeOutgoingAndStoreMessage(r,s);break}case"pubrec":{o={cmd:"pubrel",qos:2,messageId:r};let c=l.reasonCode;c&&c>0&&c!==16?(a=new e.ErrorWithReasonCode(`Publish error: ${u.ReasonCodes[c]}`,c),n._removeOutgoingAndStoreMessage(r,()=>{s(a,l)})):n._sendPacket(o);break}case"suback":{delete n.outgoing[r],n.messageIdProvider.deallocate(r);let c=l.granted;for(let d=0;d<c.length;d++){let p=c[d];if((p&128)!==0){a=new Error(`Subscribe error: ${u.ReasonCodes[p]}`),a.code=p;let y=n.messageIdToTopic[r];y&&y.forEach(f=>{delete n._resubscribeTopics[f]})}}delete n.messageIdToTopic[r],n._invokeStoreProcessingQueue(),s(a,l);break}case"unsuback":{delete n.outgoing[r],n.messageIdProvider.deallocate(r),n._invokeStoreProcessingQueue(),s(null,l);break}default:n.emit("error",new Error("unrecognized packet type"))}n.disconnecting&&Object.keys(n.outgoing).length===0&&n.emit("outgoingEmpty")};u.default=t}),Iu=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"__esModule",{value:!0});var e=Nt(),t=jr(),n=(l,r)=>{let{options:i}=l,o=i.protocolVersion,s=o===5?r.reasonCode:r.returnCode;if(o!==5){let a=new e.ErrorWithReasonCode(`Protocol error: Auth packets are only supported in MQTT 5. Your version:${o}`,s);l.emit("error",a);return}l.handleAuth(r,(a,c)=>{if(a){l.emit("error",a);return}if(s===24)l.reconnecting=!1,l._sendPacket(c);else{let d=new e.ErrorWithReasonCode(`Connection refused: ${t.ReasonCodes[s]}`,s);l.emit("error",d)}})};u.default=n}),Tu=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"__esModule",{value:!0}),u.LRUCache=void 0;var e=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date,t=new Set,n=typeof Pe=="object"&&Pe?Pe:{},l=(y,f,m,b)=>{typeof n.emitWarning=="function"?n.emitWarning(y,f,m,b):console.error(`[${m}] ${f}: ${y}`)},r=globalThis.AbortController,i=globalThis.AbortSignal;if(typeof r>"u"){i=class{onabort;_onabort=[];reason;aborted=!1;addEventListener(m,b){this._onabort.push(b)}},r=class{constructor(){f()}signal=new i;abort(m){if(!this.signal.aborted){this.signal.reason=m,this.signal.aborted=!0;for(let b of this.signal._onabort)b(m);this.signal.onabort?.(m)}}};let y=n.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",f=()=>{y&&(y=!1,l("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",f))}}var o=y=>!t.has(y),s=y=>y&&y===Math.floor(y)&&y>0&&isFinite(y),a=y=>s(y)?y<=Math.pow(2,8)?Uint8Array:y<=Math.pow(2,16)?Uint16Array:y<=Math.pow(2,32)?Uint32Array:y<=Number.MAX_SAFE_INTEGER?c:null:null,c=class extends Array{constructor(y){super(y),this.fill(0)}},d=class zt{heap;length;static#l=!1;static create(f){let m=a(f);if(!m)return[];zt.#l=!0;let b=new zt(f,m);return zt.#l=!1,b}constructor(f,m){if(!zt.#l)throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new m(f),this.length=0}push(f){this.heap[this.length++]=f}pop(){return this.heap[--this.length]}},p=class ua{#l;#h;#g;#m;#O;#P;ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;#i;#b;#n;#r;#e;#u;#f;#a;#s;#y;#o;#v;#w;#d;#_;#A;#c;static unsafeExposeInternals(f){return{starts:f.#w,ttls:f.#d,sizes:f.#v,keyMap:f.#n,keyList:f.#r,valList:f.#e,next:f.#u,prev:f.#f,get head(){return f.#a},get tail(){return f.#s},free:f.#y,isBackgroundFetch:m=>f.#t(m),backgroundFetch:(m,b,_,g)=>f.#j(m,b,_,g),moveToTail:m=>f.#C(m),indexes:m=>f.#S(m),rindexes:m=>f.#k(m),isStale:m=>f.#p(m)}}get max(){return this.#l}get maxSize(){return this.#h}get calculatedSize(){return this.#b}get size(){return this.#i}get fetchMethod(){return this.#O}get memoMethod(){return this.#P}get dispose(){return this.#g}get disposeAfter(){return this.#m}constructor(f){let{max:m=0,ttl:b,ttlResolution:_=1,ttlAutopurge:g,updateAgeOnGet:S,updateAgeOnHas:x,allowStale:v,dispose:E,disposeAfter:k,noDisposeOnSet:I,noUpdateTTL:M,maxSize:O=0,maxEntrySize:B=0,sizeCalculation:T,fetchMethod:W,memoMethod:F,noDeleteOnFetchRejection:N,noDeleteOnStaleGet:ae,allowStaleOnFetchRejection:Y,allowStaleOnFetchAbort:K,ignoreFetchAbort:re}=f;if(m!==0&&!s(m))throw new TypeError("max option must be a nonnegative integer");let D=m?a(m):Array;if(!D)throw new Error("invalid max value: "+m);if(this.#l=m,this.#h=O,this.maxEntrySize=B||this.#h,this.sizeCalculation=T,this.sizeCalculation){if(!this.#h&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if(typeof this.sizeCalculation!="function")throw new TypeError("sizeCalculation set to non-function")}if(F!==void 0&&typeof F!="function")throw new TypeError("memoMethod must be a function if defined");if(this.#P=F,W!==void 0&&typeof W!="function")throw new TypeError("fetchMethod must be a function if specified");if(this.#O=W,this.#A=!!W,this.#n=new Map,this.#r=new Array(m).fill(void 0),this.#e=new Array(m).fill(void 0),this.#u=new D(m),this.#f=new D(m),this.#a=0,this.#s=0,this.#y=d.create(m),this.#i=0,this.#b=0,typeof E=="function"&&(this.#g=E),typeof k=="function"?(this.#m=k,this.#o=[]):(this.#m=void 0,this.#o=void 0),this.#_=!!this.#g,this.#c=!!this.#m,this.noDisposeOnSet=!!I,this.noUpdateTTL=!!M,this.noDeleteOnFetchRejection=!!N,this.allowStaleOnFetchRejection=!!Y,this.allowStaleOnFetchAbort=!!K,this.ignoreFetchAbort=!!re,this.maxEntrySize!==0){if(this.#h!==0&&!s(this.#h))throw new TypeError("maxSize must be a positive integer if specified");if(!s(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.#$()}if(this.allowStale=!!v,this.noDeleteOnStaleGet=!!ae,this.updateAgeOnGet=!!S,this.updateAgeOnHas=!!x,this.ttlResolution=s(_)||_===0?_:1,this.ttlAutopurge=!!g,this.ttl=b||0,this.ttl){if(!s(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.#L()}if(this.#l===0&&this.ttl===0&&this.#h===0)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.#l&&!this.#h){let Z="LRU_CACHE_UNBOUNDED";o(Z)&&(t.add(Z),l("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",Z,ua))}}getRemainingTTL(f){return this.#n.has(f)?1/0:0}#L(){let f=new c(this.#l),m=new c(this.#l);this.#d=f,this.#w=m,this.#N=(g,S,x=e.now())=>{if(m[g]=S!==0?x:0,f[g]=S,S!==0&&this.ttlAutopurge){let v=setTimeout(()=>{this.#p(g)&&this.#E(this.#r[g],"expire")},S+1);v.unref&&v.unref()}},this.#I=g=>{m[g]=f[g]!==0?e.now():0},this.#x=(g,S)=>{if(f[S]){let x=f[S],v=m[S];if(!x||!v)return;g.ttl=x,g.start=v,g.now=b||_();let E=g.now-v;g.remainingTTL=x-E}};let b=0,_=()=>{let g=e.now();if(this.ttlResolution>0){b=g;let S=setTimeout(()=>b=0,this.ttlResolution);S.unref&&S.unref()}return g};this.getRemainingTTL=g=>{let S=this.#n.get(g);if(S===void 0)return 0;let x=f[S],v=m[S];if(!x||!v)return 1/0;let E=(b||_())-v;return x-E},this.#p=g=>{let S=m[g],x=f[g];return!!x&&!!S&&(b||_())-S>x}}#I=()=>{};#x=()=>{};#N=()=>{};#p=()=>!1;#$(){let f=new c(this.#l);this.#b=0,this.#v=f,this.#T=m=>{this.#b-=f[m],f[m]=0},this.#U=(m,b,_,g)=>{if(this.#t(b))return 0;if(!s(_))if(g){if(typeof g!="function")throw new TypeError("sizeCalculation must be a function");if(_=g(b,m),!s(_))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}else throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");return _},this.#M=(m,b,_)=>{if(f[m]=b,this.#h){let g=this.#h-f[m];for(;this.#b>g;)this.#R(!0)}this.#b+=f[m],_&&(_.entrySize=b,_.totalCalculatedSize=this.#b)}}#T=f=>{};#M=(f,m,b)=>{};#U=(f,m,b,_)=>{if(b||_)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0};*#S({allowStale:f=this.allowStale}={}){if(this.#i)for(let m=this.#s;!(!this.#B(m)||((f||!this.#p(m))&&(yield m),m===this.#a));)m=this.#f[m]}*#k({allowStale:f=this.allowStale}={}){if(this.#i)for(let m=this.#a;!(!this.#B(m)||((f||!this.#p(m))&&(yield m),m===this.#s));)m=this.#u[m]}#B(f){return f!==void 0&&this.#n.get(this.#r[f])===f}*entries(){for(let f of this.#S())this.#e[f]!==void 0&&this.#r[f]!==void 0&&!this.#t(this.#e[f])&&(yield[this.#r[f],this.#e[f]])}*rentries(){for(let f of this.#k())this.#e[f]!==void 0&&this.#r[f]!==void 0&&!this.#t(this.#e[f])&&(yield[this.#r[f],this.#e[f]])}*keys(){for(let f of this.#S()){let m=this.#r[f];m!==void 0&&!this.#t(this.#e[f])&&(yield m)}}*rkeys(){for(let f of this.#k()){let m=this.#r[f];m!==void 0&&!this.#t(this.#e[f])&&(yield m)}}*values(){for(let f of this.#S())this.#e[f]!==void 0&&!this.#t(this.#e[f])&&(yield this.#e[f])}*rvalues(){for(let f of this.#k())this.#e[f]!==void 0&&!this.#t(this.#e[f])&&(yield this.#e[f])}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]="LRUCache";find(f,m={}){for(let b of this.#S()){let _=this.#e[b],g=this.#t(_)?_.__staleWhileFetching:_;if(g!==void 0&&f(g,this.#r[b],this))return this.get(this.#r[b],m)}}forEach(f,m=this){for(let b of this.#S()){let _=this.#e[b],g=this.#t(_)?_.__staleWhileFetching:_;g!==void 0&&f.call(m,g,this.#r[b],this)}}rforEach(f,m=this){for(let b of this.#k()){let _=this.#e[b],g=this.#t(_)?_.__staleWhileFetching:_;g!==void 0&&f.call(m,g,this.#r[b],this)}}purgeStale(){let f=!1;for(let m of this.#k({allowStale:!0}))this.#p(m)&&(this.#E(this.#r[m],"expire"),f=!0);return f}info(f){let m=this.#n.get(f);if(m===void 0)return;let b=this.#e[m],_=this.#t(b)?b.__staleWhileFetching:b;if(_===void 0)return;let g={value:_};if(this.#d&&this.#w){let S=this.#d[m],x=this.#w[m];if(S&&x){let v=S-(e.now()-x);g.ttl=v,g.start=Date.now()}}return this.#v&&(g.size=this.#v[m]),g}dump(){let f=[];for(let m of this.#S({allowStale:!0})){let b=this.#r[m],_=this.#e[m],g=this.#t(_)?_.__staleWhileFetching:_;if(g===void 0||b===void 0)continue;let S={value:g};if(this.#d&&this.#w){S.ttl=this.#d[m];let x=e.now()-this.#w[m];S.start=Math.floor(Date.now()-x)}this.#v&&(S.size=this.#v[m]),f.unshift([b,S])}return f}load(f){this.clear();for(let[m,b]of f){if(b.start){let _=Date.now()-b.start;b.start=e.now()-_}this.set(m,b.value,b)}}set(f,m,b={}){if(m===void 0)return this.delete(f),this;let{ttl:_=this.ttl,start:g,noDisposeOnSet:S=this.noDisposeOnSet,sizeCalculation:x=this.sizeCalculation,status:v}=b,{noUpdateTTL:E=this.noUpdateTTL}=b,k=this.#U(f,m,b.size||0,x);if(this.maxEntrySize&&k>this.maxEntrySize)return v&&(v.set="miss",v.maxEntrySizeExceeded=!0),this.#E(f,"set"),this;let I=this.#i===0?void 0:this.#n.get(f);if(I===void 0)I=this.#i===0?this.#s:this.#y.length!==0?this.#y.pop():this.#i===this.#l?this.#R(!1):this.#i,this.#r[I]=f,this.#e[I]=m,this.#n.set(f,I),this.#u[this.#s]=I,this.#f[I]=this.#s,this.#s=I,this.#i++,this.#M(I,k,v),v&&(v.set="add"),E=!1;else{this.#C(I);let M=this.#e[I];if(m!==M){if(this.#A&&this.#t(M)){M.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:O}=M;O!==void 0&&!S&&(this.#_&&this.#g?.(O,f,"set"),this.#c&&this.#o?.push([O,f,"set"]))}else S||(this.#_&&this.#g?.(M,f,"set"),this.#c&&this.#o?.push([M,f,"set"]));if(this.#T(I),this.#M(I,k,v),this.#e[I]=m,v){v.set="replace";let O=M&&this.#t(M)?M.__staleWhileFetching:M;O!==void 0&&(v.oldValue=O)}}else v&&(v.set="update")}if(_!==0&&!this.#d&&this.#L(),this.#d&&(E||this.#N(I,_,g),v&&this.#x(v,I)),!S&&this.#c&&this.#o){let M=this.#o,O;for(;O=M?.shift();)this.#m?.(...O)}return this}pop(){try{for(;this.#i;){let f=this.#e[this.#a];if(this.#R(!0),this.#t(f)){if(f.__staleWhileFetching)return f.__staleWhileFetching}else if(f!==void 0)return f}}finally{if(this.#c&&this.#o){let f=this.#o,m;for(;m=f?.shift();)this.#m?.(...m)}}}#R(f){let m=this.#a,b=this.#r[m],_=this.#e[m];return this.#A&&this.#t(_)?_.__abortController.abort(new Error("evicted")):(this.#_||this.#c)&&(this.#_&&this.#g?.(_,b,"evict"),this.#c&&this.#o?.push([_,b,"evict"])),this.#T(m),f&&(this.#r[m]=void 0,this.#e[m]=void 0,this.#y.push(m)),this.#i===1?(this.#a=this.#s=0,this.#y.length=0):this.#a=this.#u[m],this.#n.delete(b),this.#i--,m}has(f,m={}){let{updateAgeOnHas:b=this.updateAgeOnHas,status:_}=m,g=this.#n.get(f);if(g!==void 0){let S=this.#e[g];if(this.#t(S)&&S.__staleWhileFetching===void 0)return!1;if(this.#p(g))_&&(_.has="stale",this.#x(_,g));else return b&&this.#I(g),_&&(_.has="hit",this.#x(_,g)),!0}else _&&(_.has="miss");return!1}peek(f,m={}){let{allowStale:b=this.allowStale}=m,_=this.#n.get(f);if(_===void 0||!b&&this.#p(_))return;let g=this.#e[_];return this.#t(g)?g.__staleWhileFetching:g}#j(f,m,b,_){let g=m===void 0?void 0:this.#e[m];if(this.#t(g))return g;let S=new r,{signal:x}=b;x?.addEventListener("abort",()=>S.abort(x.reason),{signal:S.signal});let v={signal:S.signal,options:b,context:_},E=(T,W=!1)=>{let{aborted:F}=S.signal,N=b.ignoreFetchAbort&&T!==void 0;if(b.status&&(F&&!W?(b.status.fetchAborted=!0,b.status.fetchError=S.signal.reason,N&&(b.status.fetchAbortIgnored=!0)):b.status.fetchResolved=!0),F&&!N&&!W)return I(S.signal.reason);let ae=O;return this.#e[m]===O&&(T===void 0?ae.__staleWhileFetching?this.#e[m]=ae.__staleWhileFetching:this.#E(f,"fetch"):(b.status&&(b.status.fetchUpdated=!0),this.set(f,T,v.options))),T},k=T=>(b.status&&(b.status.fetchRejected=!0,b.status.fetchError=T),I(T)),I=T=>{let{aborted:W}=S.signal,F=W&&b.allowStaleOnFetchAbort,N=F||b.allowStaleOnFetchRejection,ae=N||b.noDeleteOnFetchRejection,Y=O;if(this.#e[m]===O&&(!ae||Y.__staleWhileFetching===void 0?this.#E(f,"fetch"):F||(this.#e[m]=Y.__staleWhileFetching)),N)return b.status&&Y.__staleWhileFetching!==void 0&&(b.status.returnedStale=!0),Y.__staleWhileFetching;if(Y.__returned===Y)throw T},M=(T,W)=>{let F=this.#O?.(f,g,v);F&&F instanceof Promise&&F.then(N=>T(N===void 0?void 0:N),W),S.signal.addEventListener("abort",()=>{(!b.ignoreFetchAbort||b.allowStaleOnFetchAbort)&&(T(void 0),b.allowStaleOnFetchAbort&&(T=N=>E(N,!0)))})};b.status&&(b.status.fetchDispatched=!0);let O=new Promise(M).then(E,k),B=Object.assign(O,{__abortController:S,__staleWhileFetching:g,__returned:void 0});return m===void 0?(this.set(f,B,{...v.options,status:void 0}),m=this.#n.get(f)):this.#e[m]=B,B}#t(f){if(!this.#A)return!1;let m=f;return!!m&&m instanceof Promise&&m.hasOwnProperty("__staleWhileFetching")&&m.__abortController instanceof r}async fetch(f,m={}){let{allowStale:b=this.allowStale,updateAgeOnGet:_=this.updateAgeOnGet,noDeleteOnStaleGet:g=this.noDeleteOnStaleGet,ttl:S=this.ttl,noDisposeOnSet:x=this.noDisposeOnSet,size:v=0,sizeCalculation:E=this.sizeCalculation,noUpdateTTL:k=this.noUpdateTTL,noDeleteOnFetchRejection:I=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:M=this.allowStaleOnFetchRejection,ignoreFetchAbort:O=this.ignoreFetchAbort,allowStaleOnFetchAbort:B=this.allowStaleOnFetchAbort,context:T,forceRefresh:W=!1,status:F,signal:N}=m;if(!this.#A)return F&&(F.fetch="get"),this.get(f,{allowStale:b,updateAgeOnGet:_,noDeleteOnStaleGet:g,status:F});let ae={allowStale:b,updateAgeOnGet:_,noDeleteOnStaleGet:g,ttl:S,noDisposeOnSet:x,size:v,sizeCalculation:E,noUpdateTTL:k,noDeleteOnFetchRejection:I,allowStaleOnFetchRejection:M,allowStaleOnFetchAbort:B,ignoreFetchAbort:O,status:F,signal:N},Y=this.#n.get(f);if(Y===void 0){F&&(F.fetch="miss");let K=this.#j(f,Y,ae,T);return K.__returned=K}else{let K=this.#e[Y];if(this.#t(K)){let P=b&&K.__staleWhileFetching!==void 0;return F&&(F.fetch="inflight",P&&(F.returnedStale=!0)),P?K.__staleWhileFetching:K.__returned=K}let re=this.#p(Y);if(!W&&!re)return F&&(F.fetch="hit"),this.#C(Y),_&&this.#I(Y),F&&this.#x(F,Y),K;let D=this.#j(f,Y,ae,T),Z=D.__staleWhileFetching!==void 0&&b;return F&&(F.fetch=re?"stale":"refresh",Z&&re&&(F.returnedStale=!0)),Z?D.__staleWhileFetching:D.__returned=D}}async forceFetch(f,m={}){let b=await this.fetch(f,m);if(b===void 0)throw new Error("fetch() returned undefined");return b}memo(f,m={}){let b=this.#P;if(!b)throw new Error("no memoMethod provided to constructor");let{context:_,forceRefresh:g,...S}=m,x=this.get(f,S);if(!g&&x!==void 0)return x;let v=b(f,x,{options:S,context:_});return this.set(f,v,S),v}get(f,m={}){let{allowStale:b=this.allowStale,updateAgeOnGet:_=this.updateAgeOnGet,noDeleteOnStaleGet:g=this.noDeleteOnStaleGet,status:S}=m,x=this.#n.get(f);if(x!==void 0){let v=this.#e[x],E=this.#t(v);return S&&this.#x(S,x),this.#p(x)?(S&&(S.get="stale"),E?(S&&b&&v.__staleWhileFetching!==void 0&&(S.returnedStale=!0),b?v.__staleWhileFetching:void 0):(g||this.#E(f,"expire"),S&&b&&(S.returnedStale=!0),b?v:void 0)):(S&&(S.get="hit"),E?v.__staleWhileFetching:(this.#C(x),_&&this.#I(x),v))}else S&&(S.get="miss")}#F(f,m){this.#f[m]=f,this.#u[f]=m}#C(f){f!==this.#s&&(f===this.#a?this.#a=this.#u[f]:this.#F(this.#f[f],this.#u[f]),this.#F(this.#s,f),this.#s=f)}delete(f){return this.#E(f,"delete")}#E(f,m){let b=!1;if(this.#i!==0){let _=this.#n.get(f);if(_!==void 0)if(b=!0,this.#i===1)this.#D(m);else{this.#T(_);let g=this.#e[_];if(this.#t(g)?g.__abortController.abort(new Error("deleted")):(this.#_||this.#c)&&(this.#_&&this.#g?.(g,f,m),this.#c&&this.#o?.push([g,f,m])),this.#n.delete(f),this.#r[_]=void 0,this.#e[_]=void 0,_===this.#s)this.#s=this.#f[_];else if(_===this.#a)this.#a=this.#u[_];else{let S=this.#f[_];this.#u[S]=this.#u[_];let x=this.#u[_];this.#f[x]=this.#f[_]}this.#i--,this.#y.push(_)}}if(this.#c&&this.#o?.length){let _=this.#o,g;for(;g=_?.shift();)this.#m?.(...g)}return b}clear(){return this.#D("delete")}#D(f){for(let m of this.#k({allowStale:!0})){let b=this.#e[m];if(this.#t(b))b.__abortController.abort(new Error("deleted"));else{let _=this.#r[m];this.#_&&this.#g?.(b,_,f),this.#c&&this.#o?.push([b,_,f])}}if(this.#n.clear(),this.#e.fill(void 0),this.#r.fill(void 0),this.#d&&this.#w&&(this.#d.fill(0),this.#w.fill(0)),this.#v&&this.#v.fill(0),this.#a=0,this.#s=0,this.#y.length=0,this.#b=0,this.#i=0,this.#c&&this.#o){let m=this.#o,b;for(;b=m?.shift();)this.#m?.(...b)}}};u.LRUCache=p}),ut=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"t",{value:!0}),u.ContainerIterator=u.Container=u.Base=void 0;var e=class{constructor(l=0){this.iteratorType=l}equals(l){return this.o===l.o}};u.ContainerIterator=e;var t=class{constructor(){this.i=0}get length(){return this.i}size(){return this.i}empty(){return this.i===0}};u.Base=t;var n=class extends t{};u.Container=n}),Cu=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"t",{value:!0}),u.default=void 0;var e=ut(),t=class extends e.Base{constructor(l=[]){super(),this.S=[];let r=this;l.forEach(function(i){r.push(i)})}clear(){this.i=0,this.S=[]}push(l){return this.S.push(l),this.i+=1,this.i}pop(){if(this.i!==0)return this.i-=1,this.S.pop()}top(){return this.S[this.i-1]}},n=t;u.default=n}),Ou=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"t",{value:!0}),u.default=void 0;var e=ut(),t=class extends e.Base{constructor(l=[]){super(),this.j=0,this.q=[];let r=this;l.forEach(function(i){r.push(i)})}clear(){this.q=[],this.i=this.j=0}push(l){let r=this.q.length;if(this.j/r>.5&&this.j+this.i>=r&&r>4096){let i=this.i;for(let o=0;o<i;++o)this.q[o]=this.q[this.j+o];this.j=0,this.q[this.i]=l}else this.q[this.j+this.i]=l;return++this.i}pop(){if(this.i===0)return;let l=this.q[this.j++];return this.i-=1,l}front(){if(this.i!==0)return this.q[this.j]}},n=t;u.default=n}),Pu=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"t",{value:!0}),u.default=void 0;var e=ut(),t=class extends e.Base{constructor(l=[],r=function(o,s){return o>s?-1:o<s?1:0},i=!0){if(super(),this.v=r,Array.isArray(l))this.C=i?[...l]:l;else{this.C=[];let s=this;l.forEach(function(a){s.C.push(a)})}this.i=this.C.length;let o=this.i>>1;for(let s=this.i-1>>1;s>=0;--s)this.k(s,o)}m(l){let r=this.C[l];for(;l>0;){let i=l-1>>1,o=this.C[i];if(this.v(o,r)<=0)break;this.C[l]=o,l=i}this.C[l]=r}k(l,r){let i=this.C[l];for(;l<r;){let o=l<<1|1,s=o+1,a=this.C[o];if(s<this.i&&this.v(a,this.C[s])>0&&(o=s,a=this.C[s]),this.v(a,i)>=0)break;this.C[l]=a,l=o}this.C[l]=i}clear(){this.i=0,this.C.length=0}push(l){this.C.push(l),this.m(this.i),this.i+=1}pop(){if(this.i===0)return;let l=this.C[0],r=this.C.pop();return this.i-=1,this.i&&(this.C[0]=r,this.k(0,this.i>>1)),l}top(){return this.C[0]}find(l){return this.C.indexOf(l)>=0}remove(l){let r=this.C.indexOf(l);return r<0?!1:(r===0?this.pop():r===this.i-1?(this.C.pop(),this.i-=1):(this.C.splice(r,1,this.C.pop()),this.i-=1,this.m(r),this.k(r,this.i>>1)),!0)}updateItem(l){let r=this.C.indexOf(l);return r<0?!1:(this.m(r),this.k(r,this.i>>1),!0)}toArray(){return[...this.C]}},n=t;u.default=n}),Zi=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"t",{value:!0}),u.default=void 0;var e=ut(),t=class extends e.Container{},n=t;u.default=n}),ct=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"t",{value:!0}),u.throwIteratorAccessError=e;function e(){throw new RangeError("Iterator access denied!")}}),ca=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"t",{value:!0}),u.RandomIterator=void 0;var e=ut(),t=ct(),n=class extends e.ContainerIterator{constructor(l,r){super(r),this.o=l,this.iteratorType===0?(this.pre=function(){return this.o===0&&(0,t.throwIteratorAccessError)(),this.o-=1,this},this.next=function(){return this.o===this.container.size()&&(0,t.throwIteratorAccessError)(),this.o+=1,this}):(this.pre=function(){return this.o===this.container.size()-1&&(0,t.throwIteratorAccessError)(),this.o+=1,this},this.next=function(){return this.o===-1&&(0,t.throwIteratorAccessError)(),this.o-=1,this})}get pointer(){return this.container.getElementByPos(this.o)}set pointer(l){this.container.setElementByPos(this.o,l)}};u.RandomIterator=n}),Mu=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"t",{value:!0}),u.default=void 0;var e=n(Zi()),t=ca();function n(o){return o&&o.t?o:{default:o}}var l=class ha extends t.RandomIterator{constructor(s,a,c){super(s,c),this.container=a}copy(){return new ha(this.o,this.container,this.iteratorType)}},r=class extends e.default{constructor(o=[],s=!0){if(super(),Array.isArray(o))this.J=s?[...o]:o,this.i=o.length;else{this.J=[];let a=this;o.forEach(function(c){a.pushBack(c)})}}clear(){this.i=0,this.J.length=0}begin(){return new l(0,this)}end(){return new l(this.i,this)}rBegin(){return new l(this.i-1,this,1)}rEnd(){return new l(-1,this,1)}front(){return this.J[0]}back(){return this.J[this.i-1]}getElementByPos(o){if(o<0||o>this.i-1)throw new RangeError;return this.J[o]}eraseElementByPos(o){if(o<0||o>this.i-1)throw new RangeError;return this.J.splice(o,1),this.i-=1,this.i}eraseElementByValue(o){let s=0;for(let a=0;a<this.i;++a)this.J[a]!==o&&(this.J[s++]=this.J[a]);return this.i=this.J.length=s,this.i}eraseElementByIterator(o){let s=o.o;return o=o.next(),this.eraseElementByPos(s),o}pushBack(o){return this.J.push(o),this.i+=1,this.i}popBack(){if(this.i!==0)return this.i-=1,this.J.pop()}setElementByPos(o,s){if(o<0||o>this.i-1)throw new RangeError;this.J[o]=s}insert(o,s,a=1){if(o<0||o>this.i)throw new RangeError;return this.J.splice(o,0,...new Array(a).fill(s)),this.i+=a,this.i}find(o){for(let s=0;s<this.i;++s)if(this.J[s]===o)return new l(s,this);return this.end()}reverse(){this.J.reverse()}unique(){let o=1;for(let s=1;s<this.i;++s)this.J[s]!==this.J[s-1]&&(this.J[o++]=this.J[s]);return this.i=this.J.length=o,this.i}sort(o){this.J.sort(o)}forEach(o){for(let s=0;s<this.i;++s)o(this.J[s],s,this)}[Symbol.iterator](){return(function*(){yield*this.J}).bind(this)()}},i=r;u.default=i}),Ru=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"t",{value:!0}),u.default=void 0;var e=l(Zi()),t=ut(),n=ct();function l(s){return s&&s.t?s:{default:s}}var r=class fa extends t.ContainerIterator{constructor(a,c,d,p){super(p),this.o=a,this.h=c,this.container=d,this.iteratorType===0?(this.pre=function(){return this.o.L===this.h&&(0,n.throwIteratorAccessError)(),this.o=this.o.L,this},this.next=function(){return this.o===this.h&&(0,n.throwIteratorAccessError)(),this.o=this.o.B,this}):(this.pre=function(){return this.o.B===this.h&&(0,n.throwIteratorAccessError)(),this.o=this.o.B,this},this.next=function(){return this.o===this.h&&(0,n.throwIteratorAccessError)(),this.o=this.o.L,this})}get pointer(){return this.o===this.h&&(0,n.throwIteratorAccessError)(),this.o.l}set pointer(a){this.o===this.h&&(0,n.throwIteratorAccessError)(),this.o.l=a}copy(){return new fa(this.o,this.h,this.container,this.iteratorType)}},i=class extends e.default{constructor(s=[]){super(),this.h={},this.p=this._=this.h.L=this.h.B=this.h;let a=this;s.forEach(function(c){a.pushBack(c)})}V(s){let{L:a,B:c}=s;a.B=c,c.L=a,s===this.p&&(this.p=c),s===this._&&(this._=a),this.i-=1}G(s,a){let c=a.B,d={l:s,L:a,B:c};a.B=d,c.L=d,a===this.h&&(this.p=d),c===this.h&&(this._=d),this.i+=1}clear(){this.i=0,this.p=this._=this.h.L=this.h.B=this.h}begin(){return new r(this.p,this.h,this)}end(){return new r(this.h,this.h,this)}rBegin(){return new r(this._,this.h,this,1)}rEnd(){return new r(this.h,this.h,this,1)}front(){return this.p.l}back(){return this._.l}getElementByPos(s){if(s<0||s>this.i-1)throw new RangeError;let a=this.p;for(;s--;)a=a.B;return a.l}eraseElementByPos(s){if(s<0||s>this.i-1)throw new RangeError;let a=this.p;for(;s--;)a=a.B;return this.V(a),this.i}eraseElementByValue(s){let a=this.p;for(;a!==this.h;)a.l===s&&this.V(a),a=a.B;return this.i}eraseElementByIterator(s){let a=s.o;return a===this.h&&(0,n.throwIteratorAccessError)(),s=s.next(),this.V(a),s}pushBack(s){return this.G(s,this._),this.i}popBack(){if(this.i===0)return;let s=this._.l;return this.V(this._),s}pushFront(s){return this.G(s,this.h),this.i}popFront(){if(this.i===0)return;let s=this.p.l;return this.V(this.p),s}setElementByPos(s,a){if(s<0||s>this.i-1)throw new RangeError;let c=this.p;for(;s--;)c=c.B;c.l=a}insert(s,a,c=1){if(s<0||s>this.i)throw new RangeError;if(c<=0)return this.i;if(s===0)for(;c--;)this.pushFront(a);else if(s===this.i)for(;c--;)this.pushBack(a);else{let d=this.p;for(let y=1;y<s;++y)d=d.B;let p=d.B;for(this.i+=c;c--;)d.B={l:a,L:d},d.B.L=d,d=d.B;d.B=p,p.L=d}return this.i}find(s){let a=this.p;for(;a!==this.h;){if(a.l===s)return new r(a,this.h,this);a=a.B}return this.end()}reverse(){if(this.i<=1)return;let s=this.p,a=this._,c=0;for(;c<<1<this.i;){let d=s.l;s.l=a.l,a.l=d,s=s.B,a=a.L,c+=1}}unique(){if(this.i<=1)return this.i;let s=this.p;for(;s!==this.h;){let a=s;for(;a.B!==this.h&&a.l===a.B.l;)a=a.B,this.i-=1;s.B=a.B,s.B.L=s,s=s.B}return this.i}sort(s){if(this.i<=1)return;let a=[];this.forEach(function(d){a.push(d)}),a.sort(s);let c=this.p;a.forEach(function(d){c.l=d,c=c.B})}merge(s){let a=this;if(this.i===0)s.forEach(function(c){a.pushBack(c)});else{let c=this.p;s.forEach(function(d){for(;c!==a.h&&c.l<=d;)c=c.B;a.G(d,c.L)})}return this.i}forEach(s){let a=this.p,c=0;for(;a!==this.h;)s(a.l,c++,this),a=a.B}[Symbol.iterator](){return(function*(){if(this.i===0)return;let s=this.p;for(;s!==this.h;)yield s.l,s=s.B}).bind(this)()}},o=i;u.default=o}),ju=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"t",{value:!0}),u.default=void 0;var e=n(Zi()),t=ca();function n(o){return o&&o.t?o:{default:o}}var l=class da extends t.RandomIterator{constructor(s,a,c){super(s,c),this.container=a}copy(){return new da(this.o,this.container,this.iteratorType)}},r=class extends e.default{constructor(o=[],s=4096){super(),this.j=0,this.D=0,this.R=0,this.N=0,this.P=0,this.A=[];let a=(()=>{if(typeof o.length=="number")return o.length;if(typeof o.size=="number")return o.size;if(typeof o.size=="function")return o.size();throw new TypeError("Cannot get the length or size of the container")})();this.F=s,this.P=Math.max(Math.ceil(a/this.F),1);for(let p=0;p<this.P;++p)this.A.push(new Array(this.F));let c=Math.ceil(a/this.F);this.j=this.R=(this.P>>1)-(c>>1),this.D=this.N=this.F-a%this.F>>1;let d=this;o.forEach(function(p){d.pushBack(p)})}T(){let o=[],s=Math.max(this.P>>1,1);for(let a=0;a<s;++a)o[a]=new Array(this.F);for(let a=this.j;a<this.P;++a)o[o.length]=this.A[a];for(let a=0;a<this.R;++a)o[o.length]=this.A[a];o[o.length]=[...this.A[this.R]],this.j=s,this.R=o.length-1;for(let a=0;a<s;++a)o[o.length]=new Array(this.F);this.A=o,this.P=o.length}O(o){let s=this.D+o+1,a=s%this.F,c=a-1,d=this.j+(s-a)/this.F;return a===0&&(d-=1),d%=this.P,c<0&&(c+=this.F),{curNodeBucketIndex:d,curNodePointerIndex:c}}clear(){this.A=[new Array(this.F)],this.P=1,this.j=this.R=this.i=0,this.D=this.N=this.F>>1}begin(){return new l(0,this)}end(){return new l(this.i,this)}rBegin(){return new l(this.i-1,this,1)}rEnd(){return new l(-1,this,1)}front(){if(this.i!==0)return this.A[this.j][this.D]}back(){if(this.i!==0)return this.A[this.R][this.N]}pushBack(o){return this.i&&(this.N<this.F-1?this.N+=1:this.R<this.P-1?(this.R+=1,this.N=0):(this.R=0,this.N=0),this.R===this.j&&this.N===this.D&&this.T()),this.i+=1,this.A[this.R][this.N]=o,this.i}popBack(){if(this.i===0)return;let o=this.A[this.R][this.N];return this.i!==1&&(this.N>0?this.N-=1:this.R>0?(this.R-=1,this.N=this.F-1):(this.R=this.P-1,this.N=this.F-1)),this.i-=1,o}pushFront(o){return this.i&&(this.D>0?this.D-=1:this.j>0?(this.j-=1,this.D=this.F-1):(this.j=this.P-1,this.D=this.F-1),this.j===this.R&&this.D===this.N&&this.T()),this.i+=1,this.A[this.j][this.D]=o,this.i}popFront(){if(this.i===0)return;let o=this.A[this.j][this.D];return this.i!==1&&(this.D<this.F-1?this.D+=1:this.j<this.P-1?(this.j+=1,this.D=0):(this.j=0,this.D=0)),this.i-=1,o}getElementByPos(o){if(o<0||o>this.i-1)throw new RangeError;let{curNodeBucketIndex:s,curNodePointerIndex:a}=this.O(o);return this.A[s][a]}setElementByPos(o,s){if(o<0||o>this.i-1)throw new RangeError;let{curNodeBucketIndex:a,curNodePointerIndex:c}=this.O(o);this.A[a][c]=s}insert(o,s,a=1){if(o<0||o>this.i)throw new RangeError;if(o===0)for(;a--;)this.pushFront(s);else if(o===this.i)for(;a--;)this.pushBack(s);else{let c=[];for(let d=o;d<this.i;++d)c.push(this.getElementByPos(d));this.cut(o-1);for(let d=0;d<a;++d)this.pushBack(s);for(let d=0;d<c.length;++d)this.pushBack(c[d])}return this.i}cut(o){if(o<0)return this.clear(),0;let{curNodeBucketIndex:s,curNodePointerIndex:a}=this.O(o);return this.R=s,this.N=a,this.i=o+1,this.i}eraseElementByPos(o){if(o<0||o>this.i-1)throw new RangeError;if(o===0)this.popFront();else if(o===this.i-1)this.popBack();else{let s=[];for(let c=o+1;c<this.i;++c)s.push(this.getElementByPos(c));this.cut(o),this.popBack();let a=this;s.forEach(function(c){a.pushBack(c)})}return this.i}eraseElementByValue(o){if(this.i===0)return 0;let s=[];for(let c=0;c<this.i;++c){let d=this.getElementByPos(c);d!==o&&s.push(d)}let a=s.length;for(let c=0;c<a;++c)this.setElementByPos(c,s[c]);return this.cut(a-1)}eraseElementByIterator(o){let s=o.o;return this.eraseElementByPos(s),o=o.next(),o}find(o){for(let s=0;s<this.i;++s)if(this.getElementByPos(s)===o)return new l(s,this);return this.end()}reverse(){let o=0,s=this.i-1;for(;o<s;){let a=this.getElementByPos(o);this.setElementByPos(o,this.getElementByPos(s)),this.setElementByPos(s,a),o+=1,s-=1}}unique(){if(this.i<=1)return this.i;let o=1,s=this.getElementByPos(0);for(let a=1;a<this.i;++a){let c=this.getElementByPos(a);c!==s&&(s=c,this.setElementByPos(o++,c))}for(;this.i>o;)this.popBack();return this.i}sort(o){let s=[];for(let a=0;a<this.i;++a)s.push(this.getElementByPos(a));s.sort(o);for(let a=0;a<this.i;++a)this.setElementByPos(a,s[a])}shrinkToFit(){if(this.i===0)return;let o=[];this.forEach(function(s){o.push(s)}),this.P=Math.max(Math.ceil(this.i/this.F),1),this.i=this.j=this.R=this.D=this.N=0,this.A=[];for(let s=0;s<this.P;++s)this.A.push(new Array(this.F));for(let s=0;s<o.length;++s)this.pushBack(o[s])}forEach(o){for(let s=0;s<this.i;++s)o(this.getElementByPos(s),s,this)}[Symbol.iterator](){return(function*(){for(let o=0;o<this.i;++o)yield this.getElementByPos(o)}).bind(this)()}},i=r;u.default=i}),Lu=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"t",{value:!0}),u.TreeNodeEnableIndex=u.TreeNode=void 0;var e=class{constructor(n,l){this.ee=1,this.u=void 0,this.l=void 0,this.U=void 0,this.W=void 0,this.tt=void 0,this.u=n,this.l=l}L(){let n=this;if(n.ee===1&&n.tt.tt===n)n=n.W;else if(n.U)for(n=n.U;n.W;)n=n.W;else{let l=n.tt;for(;l.U===n;)n=l,l=n.tt;n=l}return n}B(){let n=this;if(n.W){for(n=n.W;n.U;)n=n.U;return n}else{let l=n.tt;for(;l.W===n;)n=l,l=n.tt;return n.W!==l?l:n}}te(){let n=this.tt,l=this.W,r=l.U;return n.tt===this?n.tt=l:n.U===this?n.U=l:n.W=l,l.tt=n,l.U=this,this.tt=l,this.W=r,r&&(r.tt=this),l}se(){let n=this.tt,l=this.U,r=l.W;return n.tt===this?n.tt=l:n.U===this?n.U=l:n.W=l,l.tt=n,l.W=this,this.tt=l,this.U=r,r&&(r.tt=this),l}};u.TreeNode=e;var t=class extends e{constructor(){super(...arguments),this.rt=1}te(){let n=super.te();return this.ie(),n.ie(),n}se(){let n=super.se();return this.ie(),n.ie(),n}ie(){this.rt=1,this.U&&(this.rt+=this.U.rt),this.W&&(this.rt+=this.W.rt)}};u.TreeNodeEnableIndex=t}),pa=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"t",{value:!0}),u.default=void 0;var e=Lu(),t=ut(),n=ct(),l=class extends t.Container{constructor(i=function(s,a){return s<a?-1:s>a?1:0},o=!1){super(),this.Y=void 0,this.v=i,o?(this.re=e.TreeNodeEnableIndex,this.M=function(s,a,c){let d=this.ne(s,a,c);if(d){let p=d.tt;for(;p!==this.h;)p.rt+=1,p=p.tt;let y=this.he(d);if(y){let{parentNode:f,grandParent:m,curNode:b}=y;f.ie(),m.ie(),b.ie()}}return this.i},this.V=function(s){let a=this.fe(s);for(;a!==this.h;)a.rt-=1,a=a.tt}):(this.re=e.TreeNode,this.M=function(s,a,c){let d=this.ne(s,a,c);return d&&this.he(d),this.i},this.V=this.fe),this.h=new this.re}X(i,o){let s=this.h;for(;i;){let a=this.v(i.u,o);if(a<0)i=i.W;else if(a>0)s=i,i=i.U;else return i}return s}Z(i,o){let s=this.h;for(;i;)this.v(i.u,o)<=0?i=i.W:(s=i,i=i.U);return s}$(i,o){let s=this.h;for(;i;){let a=this.v(i.u,o);if(a<0)s=i,i=i.W;else if(a>0)i=i.U;else return i}return s}rr(i,o){let s=this.h;for(;i;)this.v(i.u,o)<0?(s=i,i=i.W):i=i.U;return s}ue(i){for(;;){let o=i.tt;if(o===this.h)return;if(i.ee===1){i.ee=0;return}if(i===o.U){let s=o.W;if(s.ee===1)s.ee=0,o.ee=1,o===this.Y?this.Y=o.te():o.te();else if(s.W&&s.W.ee===1){s.ee=o.ee,o.ee=0,s.W.ee=0,o===this.Y?this.Y=o.te():o.te();return}else s.U&&s.U.ee===1?(s.ee=1,s.U.ee=0,s.se()):(s.ee=1,i=o)}else{let s=o.U;if(s.ee===1)s.ee=0,o.ee=1,o===this.Y?this.Y=o.se():o.se();else if(s.U&&s.U.ee===1){s.ee=o.ee,o.ee=0,s.U.ee=0,o===this.Y?this.Y=o.se():o.se();return}else s.W&&s.W.ee===1?(s.ee=1,s.W.ee=0,s.te()):(s.ee=1,i=o)}}}fe(i){if(this.i===1)return this.clear(),this.h;let o=i;for(;o.U||o.W;){if(o.W)for(o=o.W;o.U;)o=o.U;else o=o.U;[i.u,o.u]=[o.u,i.u],[i.l,o.l]=[o.l,i.l],i=o}this.h.U===o?this.h.U=o.tt:this.h.W===o&&(this.h.W=o.tt),this.ue(o);let s=o.tt;return o===s.U?s.U=void 0:s.W=void 0,this.i-=1,this.Y.ee=0,s}oe(i,o){return i===void 0?!1:this.oe(i.U,o)||o(i)?!0:this.oe(i.W,o)}he(i){for(;;){let o=i.tt;if(o.ee===0)return;let s=o.tt;if(o===s.U){let a=s.W;if(a&&a.ee===1){if(a.ee=o.ee=0,s===this.Y)return;s.ee=1,i=s;continue}else if(i===o.W){if(i.ee=0,i.U&&(i.U.tt=o),i.W&&(i.W.tt=s),o.W=i.U,s.U=i.W,i.U=o,i.W=s,s===this.Y)this.Y=i,this.h.tt=i;else{let c=s.tt;c.U===s?c.U=i:c.W=i}return i.tt=s.tt,o.tt=i,s.tt=i,s.ee=1,{parentNode:o,grandParent:s,curNode:i}}else o.ee=0,s===this.Y?this.Y=s.se():s.se(),s.ee=1}else{let a=s.U;if(a&&a.ee===1){if(a.ee=o.ee=0,s===this.Y)return;s.ee=1,i=s;continue}else if(i===o.U){if(i.ee=0,i.U&&(i.U.tt=s),i.W&&(i.W.tt=o),s.W=i.U,o.U=i.W,i.U=s,i.W=o,s===this.Y)this.Y=i,this.h.tt=i;else{let c=s.tt;c.U===s?c.U=i:c.W=i}return i.tt=s.tt,o.tt=i,s.tt=i,s.ee=1,{parentNode:o,grandParent:s,curNode:i}}else o.ee=0,s===this.Y?this.Y=s.te():s.te(),s.ee=1}return}}ne(i,o,s){if(this.Y===void 0){this.i+=1,this.Y=new this.re(i,o),this.Y.ee=0,this.Y.tt=this.h,this.h.tt=this.Y,this.h.U=this.Y,this.h.W=this.Y;return}let a,c=this.h.U,d=this.v(c.u,i);if(d===0){c.l=o;return}else if(d>0)c.U=new this.re(i,o),c.U.tt=c,a=c.U,this.h.U=a;else{let p=this.h.W,y=this.v(p.u,i);if(y===0){p.l=o;return}else if(y<0)p.W=new this.re(i,o),p.W.tt=p,a=p.W,this.h.W=a;else{if(s!==void 0){let f=s.o;if(f!==this.h){let m=this.v(f.u,i);if(m===0){f.l=o;return}else if(m>0){let b=f.L(),_=this.v(b.u,i);if(_===0){b.l=o;return}else _<0&&(a=new this.re(i,o),b.W===void 0?(b.W=a,a.tt=b):(f.U=a,a.tt=f))}}}if(a===void 0)for(a=this.Y;;){let f=this.v(a.u,i);if(f>0){if(a.U===void 0){a.U=new this.re(i,o),a.U.tt=a,a=a.U;break}a=a.U}else if(f<0){if(a.W===void 0){a.W=new this.re(i,o),a.W.tt=a,a=a.W;break}a=a.W}else{a.l=o;return}}}}return this.i+=1,a}I(i,o){for(;i;){let s=this.v(i.u,o);if(s<0)i=i.W;else if(s>0)i=i.U;else return i}return i||this.h}clear(){this.i=0,this.Y=void 0,this.h.tt=void 0,this.h.U=this.h.W=void 0}updateKeyByIterator(i,o){let s=i.o;if(s===this.h&&(0,n.throwIteratorAccessError)(),this.i===1)return s.u=o,!0;if(s===this.h.U)return this.v(s.B().u,o)>0?(s.u=o,!0):!1;if(s===this.h.W)return this.v(s.L().u,o)<0?(s.u=o,!0):!1;let a=s.L().u;if(this.v(a,o)>=0)return!1;let c=s.B().u;return this.v(c,o)<=0?!1:(s.u=o,!0)}eraseElementByPos(i){if(i<0||i>this.i-1)throw new RangeError;let o=0,s=this;return this.oe(this.Y,function(a){return i===o?(s.V(a),!0):(o+=1,!1)}),this.i}eraseElementByKey(i){if(this.i===0)return!1;let o=this.I(this.Y,i);return o===this.h?!1:(this.V(o),!0)}eraseElementByIterator(i){let o=i.o;o===this.h&&(0,n.throwIteratorAccessError)();let s=o.W===void 0;return i.iteratorType===0?s&&i.next():(!s||o.U===void 0)&&i.next(),this.V(o),i}forEach(i){let o=0;for(let s of this)i(s,o++,this)}getElementByPos(i){if(i<0||i>this.i-1)throw new RangeError;let o,s=0;for(let a of this){if(s===i){o=a;break}s+=1}return o}getHeight(){if(this.i===0)return 0;let i=function(o){return o?Math.max(i(o.U),i(o.W))+1:0};return i(this.Y)}},r=l;u.default=r}),ga=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"t",{value:!0}),u.default=void 0;var e=ut(),t=ct(),n=class extends e.ContainerIterator{constructor(r,i,o){super(o),this.o=r,this.h=i,this.iteratorType===0?(this.pre=function(){return this.o===this.h.U&&(0,t.throwIteratorAccessError)(),this.o=this.o.L(),this},this.next=function(){return this.o===this.h&&(0,t.throwIteratorAccessError)(),this.o=this.o.B(),this}):(this.pre=function(){return this.o===this.h.W&&(0,t.throwIteratorAccessError)(),this.o=this.o.B(),this},this.next=function(){return this.o===this.h&&(0,t.throwIteratorAccessError)(),this.o=this.o.L(),this})}get index(){let r=this.o,i=this.h.tt;if(r===this.h)return i?i.rt-1:0;let o=0;for(r.U&&(o+=r.U.rt);r!==i;){let s=r.tt;r===s.W&&(o+=1,s.U&&(o+=s.U.rt)),r=s}return o}},l=n;u.default=l}),Nu=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"t",{value:!0}),u.default=void 0;var e=l(pa()),t=l(ga()),n=ct();function l(s){return s&&s.t?s:{default:s}}var r=class ma extends t.default{constructor(a,c,d,p){super(a,c,p),this.container=d}get pointer(){return this.o===this.h&&(0,n.throwIteratorAccessError)(),this.o.u}copy(){return new ma(this.o,this.h,this.container,this.iteratorType)}},i=class extends e.default{constructor(s=[],a,c){super(a,c);let d=this;s.forEach(function(p){d.insert(p)})}*K(s){s!==void 0&&(yield*this.K(s.U),yield s.u,yield*this.K(s.W))}begin(){return new r(this.h.U||this.h,this.h,this)}end(){return new r(this.h,this.h,this)}rBegin(){return new r(this.h.W||this.h,this.h,this,1)}rEnd(){return new r(this.h,this.h,this,1)}front(){return this.h.U?this.h.U.u:void 0}back(){return this.h.W?this.h.W.u:void 0}insert(s,a){return this.M(s,void 0,a)}find(s){let a=this.I(this.Y,s);return new r(a,this.h,this)}lowerBound(s){let a=this.X(this.Y,s);return new r(a,this.h,this)}upperBound(s){let a=this.Z(this.Y,s);return new r(a,this.h,this)}reverseLowerBound(s){let a=this.$(this.Y,s);return new r(a,this.h,this)}reverseUpperBound(s){let a=this.rr(this.Y,s);return new r(a,this.h,this)}union(s){let a=this;return s.forEach(function(c){a.insert(c)}),this.i}[Symbol.iterator](){return this.K(this.Y)}},o=i;u.default=o}),Uu=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"t",{value:!0}),u.default=void 0;var e=l(pa()),t=l(ga()),n=ct();function l(s){return s&&s.t?s:{default:s}}var r=class ba extends t.default{constructor(a,c,d,p){super(a,c,p),this.container=d}get pointer(){this.o===this.h&&(0,n.throwIteratorAccessError)();let a=this;return new Proxy([],{get(c,d){if(d==="0")return a.o.u;if(d==="1")return a.o.l},set(c,d,p){if(d!=="1")throw new TypeError("props must be 1");return a.o.l=p,!0}})}copy(){return new ba(this.o,this.h,this.container,this.iteratorType)}},i=class extends e.default{constructor(s=[],a,c){super(a,c);let d=this;s.forEach(function(p){d.setElement(p[0],p[1])})}*K(s){s!==void 0&&(yield*this.K(s.U),yield[s.u,s.l],yield*this.K(s.W))}begin(){return new r(this.h.U||this.h,this.h,this)}end(){return new r(this.h,this.h,this)}rBegin(){return new r(this.h.W||this.h,this.h,this,1)}rEnd(){return new r(this.h,this.h,this,1)}front(){if(this.i===0)return;let s=this.h.U;return[s.u,s.l]}back(){if(this.i===0)return;let s=this.h.W;return[s.u,s.l]}lowerBound(s){let a=this.X(this.Y,s);return new r(a,this.h,this)}upperBound(s){let a=this.Z(this.Y,s);return new r(a,this.h,this)}reverseLowerBound(s){let a=this.$(this.Y,s);return new r(a,this.h,this)}reverseUpperBound(s){let a=this.rr(this.Y,s);return new r(a,this.h,this)}setElement(s,a,c){return this.M(s,a,c)}find(s){let a=this.I(this.Y,s);return new r(a,this.h,this)}getElementByKey(s){return this.I(this.Y,s).l}union(s){let a=this;return s.forEach(function(c){a.setElement(c[0],c[1])}),this.i}[Symbol.iterator](){return this.K(this.Y)}},o=i;u.default=o}),ya=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"t",{value:!0}),u.default=e;function e(t){let n=typeof t;return n==="object"&&t!==null||n==="function"}}),va=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"t",{value:!0}),u.HashContainerIterator=u.HashContainer=void 0;var e=ut(),t=l(ya()),n=ct();function l(o){return o&&o.t?o:{default:o}}var r=class extends e.ContainerIterator{constructor(o,s,a){super(a),this.o=o,this.h=s,this.iteratorType===0?(this.pre=function(){return this.o.L===this.h&&(0,n.throwIteratorAccessError)(),this.o=this.o.L,this},this.next=function(){return this.o===this.h&&(0,n.throwIteratorAccessError)(),this.o=this.o.B,this}):(this.pre=function(){return this.o.B===this.h&&(0,n.throwIteratorAccessError)(),this.o=this.o.B,this},this.next=function(){return this.o===this.h&&(0,n.throwIteratorAccessError)(),this.o=this.o.L,this})}};u.HashContainerIterator=r;var i=class extends e.Container{constructor(){super(),this.H=[],this.g={},this.HASH_TAG=Symbol("@@HASH_TAG"),Object.setPrototypeOf(this.g,null),this.h={},this.h.L=this.h.B=this.p=this._=this.h}V(o){let{L:s,B:a}=o;s.B=a,a.L=s,o===this.p&&(this.p=a),o===this._&&(this._=s),this.i-=1}M(o,s,a){a===void 0&&(a=(0,t.default)(o));let c;if(a){let d=o[this.HASH_TAG];if(d!==void 0)return this.H[d].l=s,this.i;Object.defineProperty(o,this.HASH_TAG,{value:this.H.length,configurable:!0}),c={u:o,l:s,L:this._,B:this.h},this.H.push(c)}else{let d=this.g[o];if(d)return d.l=s,this.i;c={u:o,l:s,L:this._,B:this.h},this.g[o]=c}return this.i===0?(this.p=c,this.h.B=c):this._.B=c,this._=c,this.h.L=c,++this.i}I(o,s){if(s===void 0&&(s=(0,t.default)(o)),s){let a=o[this.HASH_TAG];return a===void 0?this.h:this.H[a]}else return this.g[o]||this.h}clear(){let o=this.HASH_TAG;this.H.forEach(function(s){delete s.u[o]}),this.H=[],this.g={},Object.setPrototypeOf(this.g,null),this.i=0,this.p=this._=this.h.L=this.h.B=this.h}eraseElementByKey(o,s){let a;if(s===void 0&&(s=(0,t.default)(o)),s){let c=o[this.HASH_TAG];if(c===void 0)return!1;delete o[this.HASH_TAG],a=this.H[c],delete this.H[c]}else{if(a=this.g[o],a===void 0)return!1;delete this.g[o]}return this.V(a),!0}eraseElementByIterator(o){let s=o.o;return s===this.h&&(0,n.throwIteratorAccessError)(),this.V(s),o.next()}eraseElementByPos(o){if(o<0||o>this.i-1)throw new RangeError;let s=this.p;for(;o--;)s=s.B;return this.V(s),this.i}};u.HashContainer=i}),Bu=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"t",{value:!0}),u.default=void 0;var e=va(),t=ct(),n=class wa extends e.HashContainerIterator{constructor(o,s,a,c){super(o,s,c),this.container=a}get pointer(){return this.o===this.h&&(0,t.throwIteratorAccessError)(),this.o.u}copy(){return new wa(this.o,this.h,this.container,this.iteratorType)}},l=class extends e.HashContainer{constructor(i=[]){super();let o=this;i.forEach(function(s){o.insert(s)})}begin(){return new n(this.p,this.h,this)}end(){return new n(this.h,this.h,this)}rBegin(){return new n(this._,this.h,this,1)}rEnd(){return new n(this.h,this.h,this,1)}front(){return this.p.u}back(){return this._.u}insert(i,o){return this.M(i,void 0,o)}getElementByPos(i){if(i<0||i>this.i-1)throw new RangeError;let o=this.p;for(;i--;)o=o.B;return o.u}find(i,o){let s=this.I(i,o);return new n(s,this.h,this)}forEach(i){let o=0,s=this.p;for(;s!==this.h;)i(s.u,o++,this),s=s.B}[Symbol.iterator](){return(function*(){let i=this.p;for(;i!==this.h;)yield i.u,i=i.B}).bind(this)()}},r=l;u.default=r}),Fu=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"t",{value:!0}),u.default=void 0;var e=va(),t=l(ya()),n=ct();function l(s){return s&&s.t?s:{default:s}}var r=class _a extends e.HashContainerIterator{constructor(a,c,d,p){super(a,c,p),this.container=d}get pointer(){this.o===this.h&&(0,n.throwIteratorAccessError)();let a=this;return new Proxy([],{get(c,d){if(d==="0")return a.o.u;if(d==="1")return a.o.l},set(c,d,p){if(d!=="1")throw new TypeError("props must be 1");return a.o.l=p,!0}})}copy(){return new _a(this.o,this.h,this.container,this.iteratorType)}},i=class extends e.HashContainer{constructor(s=[]){super();let a=this;s.forEach(function(c){a.setElement(c[0],c[1])})}begin(){return new r(this.p,this.h,this)}end(){return new r(this.h,this.h,this)}rBegin(){return new r(this._,this.h,this,1)}rEnd(){return new r(this.h,this.h,this,1)}front(){if(this.i!==0)return[this.p.u,this.p.l]}back(){if(this.i!==0)return[this._.u,this._.l]}setElement(s,a,c){return this.M(s,a,c)}getElementByKey(s,a){if(a===void 0&&(a=(0,t.default)(s)),a){let d=s[this.HASH_TAG];return d!==void 0?this.H[d].l:void 0}let c=this.g[s];return c?c.l:void 0}getElementByPos(s){if(s<0||s>this.i-1)throw new RangeError;let a=this.p;for(;s--;)a=a.B;return[a.u,a.l]}find(s,a){let c=this.I(s,a);return new r(c,this.h,this)}forEach(s){let a=0,c=this.p;for(;c!==this.h;)s([c.u,c.l],a++,this),c=c.B}[Symbol.iterator](){return(function*(){let s=this.p;for(;s!==this.h;)yield[s.u,s.l],s=s.B}).bind(this)()}},o=i;u.default=o}),Du=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"t",{value:!0}),Object.defineProperty(u,"Deque",{enumerable:!0,get:function(){return i.default}}),Object.defineProperty(u,"HashMap",{enumerable:!0,get:function(){return c.default}}),Object.defineProperty(u,"HashSet",{enumerable:!0,get:function(){return a.default}}),Object.defineProperty(u,"LinkList",{enumerable:!0,get:function(){return r.default}}),Object.defineProperty(u,"OrderedMap",{enumerable:!0,get:function(){return s.default}}),Object.defineProperty(u,"OrderedSet",{enumerable:!0,get:function(){return o.default}}),Object.defineProperty(u,"PriorityQueue",{enumerable:!0,get:function(){return n.default}}),Object.defineProperty(u,"Queue",{enumerable:!0,get:function(){return t.default}}),Object.defineProperty(u,"Stack",{enumerable:!0,get:function(){return e.default}}),Object.defineProperty(u,"Vector",{enumerable:!0,get:function(){return l.default}});var e=d(Cu()),t=d(Ou()),n=d(Pu()),l=d(Mu()),r=d(Ru()),i=d(ju()),o=d(Nu()),s=d(Uu()),a=d(Bu()),c=d(Fu());function d(p){return p&&p.t?p:{default:p}}}),$u=pe((u,e)=>{le(),ce(),ue();var t=Du().OrderedSet,n=at()("number-allocator:trace"),l=at()("number-allocator:error");function r(o,s){this.low=o,this.high=s}r.prototype.equals=function(o){return this.low===o.low&&this.high===o.high},r.prototype.compare=function(o){return this.low<o.low&&this.high<o.low?-1:o.low<this.low&&o.high<this.low?1:0};function i(o,s){if(!(this instanceof i))return new i(o,s);this.min=o,this.max=s,this.ss=new t([],(a,c)=>a.compare(c)),n("Create"),this.clear()}i.prototype.firstVacant=function(){return this.ss.size()===0?null:this.ss.front().low},i.prototype.alloc=function(){if(this.ss.size()===0)return n("alloc():empty"),null;let o=this.ss.begin(),s=o.pointer.low,a=o.pointer.high,c=s;return c+1<=a?this.ss.updateKeyByIterator(o,new r(s+1,a)):this.ss.eraseElementByPos(0),n("alloc():"+c),c},i.prototype.use=function(o){let s=new r(o,o),a=this.ss.lowerBound(s);if(!a.equals(this.ss.end())){let c=a.pointer.low,d=a.pointer.high;return a.pointer.equals(s)?(this.ss.eraseElementByIterator(a),n("use():"+o),!0):c>o?!1:c===o?(this.ss.updateKeyByIterator(a,new r(c+1,d)),n("use():"+o),!0):d===o?(this.ss.updateKeyByIterator(a,new r(c,d-1)),n("use():"+o),!0):(this.ss.updateKeyByIterator(a,new r(o+1,d)),this.ss.insert(new r(c,o-1)),n("use():"+o),!0)}return n("use():failed"),!1},i.prototype.free=function(o){if(o<this.min||o>this.max){l("free():"+o+" is out of range");return}let s=new r(o,o),a=this.ss.upperBound(s);if(a.equals(this.ss.end())){if(a.equals(this.ss.begin())){this.ss.insert(s);return}a.pre();let c=a.pointer.high;a.pointer.high+1===o?this.ss.updateKeyByIterator(a,new r(c,o)):this.ss.insert(s)}else if(a.equals(this.ss.begin()))if(o+1===a.pointer.low){let c=a.pointer.high;this.ss.updateKeyByIterator(a,new r(o,c))}else this.ss.insert(s);else{let c=a.pointer.low,d=a.pointer.high;a.pre();let p=a.pointer.low;a.pointer.high+1===o?o+1===c?(this.ss.eraseElementByIterator(a),this.ss.updateKeyByIterator(a,new r(p,d))):this.ss.updateKeyByIterator(a,new r(p,o)):o+1===c?(this.ss.eraseElementByIterator(a.next()),this.ss.insert(new r(o,d))):this.ss.insert(s)}n("free():"+o)},i.prototype.clear=function(){n("clear()"),this.ss.clear(),this.ss.insert(new r(this.min,this.max))},i.prototype.intervalCount=function(){return this.ss.size()},i.prototype.dump=function(){console.log("length:"+this.ss.size());for(let o of this.ss)console.log(o)},e.exports=i}),Sa=pe((u,e)=>{le(),ce(),ue();var t=$u();e.exports.NumberAllocator=t}),Wu=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"__esModule",{value:!0});var e=Tu(),t=Sa(),n=class{aliasToTopic;topicToAlias;max;numberAllocator;length;constructor(l){l>0&&(this.aliasToTopic=new e.LRUCache({max:l}),this.topicToAlias={},this.numberAllocator=new t.NumberAllocator(1,l),this.max=l,this.length=0)}put(l,r){if(r===0||r>this.max)return!1;let i=this.aliasToTopic.get(r);return i&&delete this.topicToAlias[i],this.aliasToTopic.set(r,l),this.topicToAlias[l]=r,this.numberAllocator.use(r),this.length=this.aliasToTopic.size,!0}getTopicByAlias(l){return this.aliasToTopic.get(l)}getAliasByTopic(l){let r=this.topicToAlias[l];return typeof r<"u"&&this.aliasToTopic.get(r),r}clear(){this.aliasToTopic.clear(),this.topicToAlias={},this.numberAllocator.clear(),this.length=0}getLruAlias(){return this.numberAllocator.firstVacant()||[...this.aliasToTopic.keys()][this.aliasToTopic.size-1]}};u.default=n}),qu=pe(u=>{le(),ce(),ue();var e=u&&u.__importDefault||function(i){return i&&i.__esModule?i:{default:i}};Object.defineProperty(u,"__esModule",{value:!0});var t=jr(),n=e(Wu()),l=Nt(),r=(i,o)=>{i.log("_handleConnack");let{options:s}=i,a=s.protocolVersion===5?o.reasonCode:o.returnCode;if(clearTimeout(i.connackTimer),delete i.topicAliasSend,o.properties){if(o.properties.topicAliasMaximum){if(o.properties.topicAliasMaximum>65535){i.emit("error",new Error("topicAliasMaximum from broker is out of range"));return}o.properties.topicAliasMaximum>0&&(i.topicAliasSend=new n.default(o.properties.topicAliasMaximum))}o.properties.serverKeepAlive&&s.keepalive&&(s.keepalive=o.properties.serverKeepAlive),o.properties.maximumPacketSize&&(s.properties||(s.properties={}),s.properties.maximumPacketSize=o.properties.maximumPacketSize)}if(a===0)i.reconnecting=!1,i._onConnect(o);else if(a>0){let c=new l.ErrorWithReasonCode(`Connection refused: ${t.ReasonCodes[a]}`,a);i.emit("error",c),i.options.reconnectOnConnackError&&i._cleanUp(!0)}};u.default=r}),Hu=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"__esModule",{value:!0});var e=(t,n,l)=>{t.log("handling pubrel packet");let r=typeof l<"u"?l:t.noop,{messageId:i}=n,o={cmd:"pubcomp",messageId:i};t.incomingStore.get(n,(s,a)=>{s?t._sendPacket(o,r):(t.emit("message",a.topic,a.payload,a),t.handleMessage(a,c=>{if(c)return r(c);t.incomingStore.del(a,t.noop),t._sendPacket(o,r)}))})};u.default=e}),zu=pe(u=>{le(),ce(),ue();var e=u&&u.__importDefault||function(s){return s&&s.__esModule?s:{default:s}};Object.defineProperty(u,"__esModule",{value:!0});var t=e(xu()),n=e(Iu()),l=e(qu()),r=e(jr()),i=e(Hu()),o=(s,a,c)=>{let{options:d}=s;if(d.protocolVersion===5&&d.properties&&d.properties.maximumPacketSize&&d.properties.maximumPacketSize<a.length)return s.emit("error",new Error(`exceeding packets size ${a.cmd}`)),s.end({reasonCode:149,properties:{reasonString:"Maximum packet size was exceeded"}}),s;switch(s.log("_handlePacket :: emitting packetreceive"),s.emit("packetreceive",a),a.cmd){case"publish":(0,t.default)(s,a,c);break;case"puback":case"pubrec":case"pubcomp":case"suback":case"unsuback":s.reschedulePing(),(0,r.default)(s,a),c();break;case"pubrel":s.reschedulePing(),(0,i.default)(s,a,c);break;case"connack":(0,l.default)(s,a),c();break;case"auth":s.reschedulePing(),(0,n.default)(s,a),c();break;case"pingresp":s.log("_handlePacket :: received pingresp"),s.reschedulePing(!0),c();break;case"disconnect":s.emit("disconnect",a),c();break;default:s.log("_handlePacket :: unknown command"),c();break}};u.default=o}),ka=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"__esModule",{value:!0});var e=class{nextId;constructor(){this.nextId=Math.max(1,Math.floor(Math.random()*65535))}allocate(){let t=this.nextId++;return this.nextId===65536&&(this.nextId=1),t}getLastAllocated(){return this.nextId===1?65535:this.nextId-1}register(t){return!0}deallocate(t){}clear(){}};u.default=e}),Ku=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"__esModule",{value:!0});var e=class{aliasToTopic;max;length;constructor(t){this.aliasToTopic={},this.max=t}put(t,n){return n===0||n>this.max?!1:(this.aliasToTopic[n]=t,this.length=Object.keys(this.aliasToTopic).length,!0)}getTopicByAlias(t){return this.aliasToTopic[t]}clear(){this.aliasToTopic={}}};u.default=e}),Vu=pe(u=>{le(),ce(),ue();var e=u&&u.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(u,"__esModule",{value:!0}),u.TypedEventEmitter=void 0;var t=e((Et(),Oe(mt))),n=Nt(),l=class{};u.TypedEventEmitter=l,(0,n.applyMixin)(l,t.default)}),Lr=pe((u,e)=>{le(),ce(),ue();function t(n){"@babel/helpers - typeof";return e.exports=t=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(l){return typeof l}:function(l){return l&&typeof Symbol=="function"&&l.constructor===Symbol&&l!==Symbol.prototype?"symbol":typeof l},e.exports.__esModule=!0,e.exports.default=e.exports,t(n)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}),Gu=pe((u,e)=>{le(),ce(),ue();var t=Lr().default;function n(l,r){if(t(l)!="object"||!l)return l;var i=l[Symbol.toPrimitive];if(i!==void 0){var o=i.call(l,r||"default");if(t(o)!="object")return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return(r==="string"?String:Number)(l)}e.exports=n,e.exports.__esModule=!0,e.exports.default=e.exports}),Yu=pe((u,e)=>{le(),ce(),ue();var t=Lr().default,n=Gu();function l(r){var i=n(r,"string");return t(i)=="symbol"?i:i+""}e.exports=l,e.exports.__esModule=!0,e.exports.default=e.exports}),Qu=pe((u,e)=>{le(),ce(),ue();var t=Yu();function n(l,r,i){return(r=t(r))in l?Object.defineProperty(l,r,{value:i,enumerable:!0,configurable:!0,writable:!0}):l[r]=i,l}e.exports=n,e.exports.__esModule=!0,e.exports.default=e.exports}),Ju=pe((u,e)=>{le(),ce(),ue();function t(n){if(Array.isArray(n))return n}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}),Xu=pe((u,e)=>{le(),ce(),ue();function t(n,l){var r=n==null?null:typeof Symbol<"u"&&n[Symbol.iterator]||n["@@iterator"];if(r!=null){var i,o,s,a,c=[],d=!0,p=!1;try{if(s=(r=r.call(n)).next,l===0){if(Object(r)!==r)return;d=!1}else for(;!(d=(i=s.call(r)).done)&&(c.push(i.value),c.length!==l);d=!0);}catch(y){p=!0,o=y}finally{try{if(!d&&r.return!=null&&(a=r.return(),Object(a)!==a))return}finally{if(p)throw o}}return c}}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}),Zu=pe((u,e)=>{le(),ce(),ue();function t(n,l){(l==null||l>n.length)&&(l=n.length);for(var r=0,i=Array(l);r<l;r++)i[r]=n[r];return i}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}),ec=pe((u,e)=>{le(),ce(),ue();var t=Zu();function n(l,r){if(l){if(typeof l=="string")return t(l,r);var i={}.toString.call(l).slice(8,-1);return i==="Object"&&l.constructor&&(i=l.constructor.name),i==="Map"||i==="Set"?Array.from(l):i==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?t(l,r):void 0}}e.exports=n,e.exports.__esModule=!0,e.exports.default=e.exports}),tc=pe((u,e)=>{le(),ce(),ue();function t(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
3
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}),rc=pe((u,e)=>{le(),ce(),ue();var t=Ju(),n=Xu(),l=ec(),r=tc();function i(o,s){return t(o)||n(o,s)||l(o,s)||r()}e.exports=i,e.exports.__esModule=!0,e.exports.default=e.exports}),Ea=pe((u,e)=>{le(),ce(),ue(),(function(t,n){typeof u=="object"&&typeof e<"u"?n(u):typeof define=="function"&&define.amd?define(["exports"],n):(t=typeof globalThis<"u"?globalThis:t||self,n(t.fastUniqueNumbers={}))})(u,function(t){var n=function(y){return function(f){var m=y(f);return f.add(m),m}},l=function(y){return function(f,m){return y.set(f,m),m}},r=Number.MAX_SAFE_INTEGER===void 0?9007199254740991:Number.MAX_SAFE_INTEGER,i=536870912,o=i*2,s=function(y,f){return function(m){var b=f.get(m),_=b===void 0?m.size:b<o?b+1:0;if(!m.has(_))return y(m,_);if(m.size<i){for(;m.has(_);)_=Math.floor(Math.random()*o);return y(m,_)}if(m.size>r)throw new Error("Congratulations, you created a collection of unique numbers which uses all available integers!");for(;m.has(_);)_=Math.floor(Math.random()*r);return y(m,_)}},a=new WeakMap,c=l(a),d=s(c,a),p=n(d);t.addUniqueNumber=p,t.generateUniqueNumber=d})}),nc=pe((u,e)=>{le(),ce(),ue();function t(l,r,i,o,s,a,c){try{var d=l[a](c),p=d.value}catch(y){return void i(y)}d.done?r(p):Promise.resolve(p).then(o,s)}function n(l){return function(){var r=this,i=arguments;return new Promise(function(o,s){var a=l.apply(r,i);function c(p){t(a,o,s,c,d,"next",p)}function d(p){t(a,o,s,c,d,"throw",p)}c(void 0)})}}e.exports=n,e.exports.__esModule=!0,e.exports.default=e.exports}),xa=pe((u,e)=>{le(),ce(),ue();function t(n,l){this.v=n,this.k=l}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}),Aa=pe((u,e)=>{le(),ce(),ue();function t(n,l,r,i){var o=Object.defineProperty;try{o({},"",{})}catch{o=0}e.exports=t=function(s,a,c,d){function p(y,f){t(s,y,function(m){return this._invoke(y,f,m)})}a?o?o(s,a,{value:c,enumerable:!d,configurable:!d,writable:!d}):s[a]=c:(p("next",0),p("throw",1),p("return",2))},e.exports.__esModule=!0,e.exports.default=e.exports,t(n,l,r,i)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}),Ia=pe((u,e)=>{le(),ce(),ue();var t=Aa();function n(){var l,r,i=typeof Symbol=="function"?Symbol:{},o=i.iterator||"@@iterator",s=i.toStringTag||"@@toStringTag";function a(_,g,S,x){var v=g&&g.prototype instanceof d?g:d,E=Object.create(v.prototype);return t(E,"_invoke",(function(k,I,M){var O,B,T,W=0,F=M||[],N=!1,ae={p:0,n:0,v:l,a:Y,f:Y.bind(l,4),d:function(K,re){return O=K,B=0,T=l,ae.n=re,c}};function Y(K,re){for(B=K,T=re,r=0;!N&&W&&!D&&r<F.length;r++){var D,Z=F[r],P=ae.p,J=Z[2];K>3?(D=J===re)&&(T=Z[(B=Z[4])?5:(B=3,3)],Z[4]=Z[5]=l):Z[0]<=P&&((D=K<2&&P<Z[1])?(B=0,ae.v=re,ae.n=Z[1]):P<J&&(D=K<3||Z[0]>re||re>J)&&(Z[4]=K,Z[5]=re,ae.n=J,B=0))}if(D||K>1)return c;throw N=!0,re}return function(K,re,D){if(W>1)throw TypeError("Generator is already running");for(N&&re===1&&Y(re,D),B=re,T=D;(r=B<2?l:T)||!N;){O||(B?B<3?(B>1&&(ae.n=-1),Y(B,T)):ae.n=T:ae.v=T);try{if(W=2,O){if(B||(K="next"),r=O[K]){if(!(r=r.call(O,T)))throw TypeError("iterator result is not an object");if(!r.done)return r;T=r.value,B<2&&(B=0)}else B===1&&(r=O.return)&&r.call(O),B<2&&(T=TypeError("The iterator does not provide a '"+K+"' method"),B=1);O=l}else if((r=(N=ae.n<0)?T:k.call(I,ae))!==c)break}catch(Z){O=l,B=1,T=Z}finally{W=1}}return{value:r,done:N}}})(_,S,x),!0),E}var c={};function d(){}function p(){}function y(){}r=Object.getPrototypeOf;var f=[][o]?r(r([][o]())):(t(r={},o,function(){return this}),r),m=y.prototype=d.prototype=Object.create(f);function b(_){return Object.setPrototypeOf?Object.setPrototypeOf(_,y):(_.__proto__=y,t(_,s,"GeneratorFunction")),_.prototype=Object.create(m),_}return p.prototype=y,t(m,"constructor",y),t(y,"constructor",p),p.displayName="GeneratorFunction",t(y,s,"GeneratorFunction"),t(m),t(m,s,"Generator"),t(m,o,function(){return this}),t(m,"toString",function(){return"[object Generator]"}),(e.exports=n=function(){return{w:a,m:b}},e.exports.__esModule=!0,e.exports.default=e.exports)()}e.exports=n,e.exports.__esModule=!0,e.exports.default=e.exports}),Ta=pe((u,e)=>{le(),ce(),ue();var t=xa(),n=Aa();function l(r,i){function o(a,c,d,p){try{var y=r[a](c),f=y.value;return f instanceof t?i.resolve(f.v).then(function(m){o("next",m,d,p)},function(m){o("throw",m,d,p)}):i.resolve(f).then(function(m){y.value=m,d(y)},function(m){return o("throw",m,d,p)})}catch(m){p(m)}}var s;this.next||(n(l.prototype),n(l.prototype,typeof Symbol=="function"&&Symbol.asyncIterator||"@asyncIterator",function(){return this})),n(this,"_invoke",function(a,c,d){function p(){return new i(function(y,f){o(a,d,y,f)})}return s=s?s.then(p,p):p()},!0)}e.exports=l,e.exports.__esModule=!0,e.exports.default=e.exports}),Ca=pe((u,e)=>{le(),ce(),ue();var t=Ia(),n=Ta();function l(r,i,o,s,a){return new n(t().w(r,i,o,s),a||Promise)}e.exports=l,e.exports.__esModule=!0,e.exports.default=e.exports}),ic=pe((u,e)=>{le(),ce(),ue();var t=Ca();function n(l,r,i,o,s){var a=t(l,r,i,o,s);return a.next().then(function(c){return c.done?c.value:a.next()})}e.exports=n,e.exports.__esModule=!0,e.exports.default=e.exports}),sc=pe((u,e)=>{le(),ce(),ue();function t(n){var l=Object(n),r=[];for(var i in l)r.unshift(i);return function o(){for(;r.length;)if((i=r.pop())in l)return o.value=i,o.done=!1,o;return o.done=!0,o}}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}),oc=pe((u,e)=>{le(),ce(),ue();var t=Lr().default;function n(l){if(l!=null){var r=l[typeof Symbol=="function"&&Symbol.iterator||"@@iterator"],i=0;if(r)return r.call(l);if(typeof l.next=="function")return l;if(!isNaN(l.length))return{next:function(){return l&&i>=l.length&&(l=void 0),{value:l&&l[i++],done:!l}}}}throw new TypeError(t(l)+" is not iterable")}e.exports=n,e.exports.__esModule=!0,e.exports.default=e.exports}),ac=pe((u,e)=>{le(),ce(),ue();var t=xa(),n=Ia(),l=ic(),r=Ca(),i=Ta(),o=sc(),s=oc();function a(){var c=n(),d=c.m(a),p=(Object.getPrototypeOf?Object.getPrototypeOf(d):d.__proto__).constructor;function y(b){var _=typeof b=="function"&&b.constructor;return!!_&&(_===p||(_.displayName||_.name)==="GeneratorFunction")}var f={throw:1,return:2,break:3,continue:3};function m(b){var _,g;return function(S){_||(_={stop:function(){return g(S.a,2)},catch:function(){return S.v},abrupt:function(x,v){return g(S.a,f[x],v)},delegateYield:function(x,v,E){return _.resultName=v,g(S.d,s(x),E)},finish:function(x){return g(S.f,x)}},g=function(x,v,E){S.p=_.prev,S.n=_.next;try{return x(v,E)}finally{_.next=S.n}}),_.resultName&&(_[_.resultName]=S.v,_.resultName=void 0),_.sent=S.v,_.next=S.n;try{return b.call(this,_)}finally{S.p=_.prev,S.n=_.next}}}return(e.exports=a=function(){return{wrap:function(b,_,g,S){return c.w(m(b),_,g,S&&S.reverse())},isGeneratorFunction:y,mark:c.m,awrap:function(b,_){return new t(b,_)},AsyncIterator:i,async:function(b,_,g,S,x){return(y(_)?r:l)(m(b),_,g,S,x)},keys:o,values:s}},e.exports.__esModule=!0,e.exports.default=e.exports)()}e.exports=a,e.exports.__esModule=!0,e.exports.default=e.exports}),lc=pe((u,e)=>{le(),ce(),ue();var t=ac()();e.exports=t;try{regeneratorRuntime=t}catch{typeof globalThis=="object"?globalThis.regeneratorRuntime=t:Function("r","regeneratorRuntime = r")(t)}}),uc=pe((u,e)=>{le(),ce(),ue(),(function(t,n){typeof u=="object"&&typeof e<"u"?n(u,Qu(),rc(),Ea(),nc(),lc()):typeof define=="function"&&define.amd?define(["exports","@babel/runtime/helpers/defineProperty","@babel/runtime/helpers/slicedToArray","fast-unique-numbers","@babel/runtime/helpers/asyncToGenerator","@babel/runtime/regenerator"],n):(t=typeof globalThis<"u"?globalThis:t||self,n(t.brokerFactory={},t._defineProperty,t._slicedToArray,t.fastUniqueNumbers,t._asyncToGenerator,t._regeneratorRuntime))})(u,function(t,n,l,r,i,o){var s=function(g){return typeof g.start=="function"},a=new WeakMap;function c(g,S){var x=Object.keys(g);if(Object.getOwnPropertySymbols){var v=Object.getOwnPropertySymbols(g);S&&(v=v.filter(function(E){return Object.getOwnPropertyDescriptor(g,E).enumerable})),x.push.apply(x,v)}return x}function d(g){for(var S=1;S<arguments.length;S++){var x=arguments[S]!=null?arguments[S]:{};S%2?c(Object(x),!0).forEach(function(v){n(g,v,x[v])}):Object.getOwnPropertyDescriptors?Object.defineProperties(g,Object.getOwnPropertyDescriptors(x)):c(Object(x)).forEach(function(v){Object.defineProperty(g,v,Object.getOwnPropertyDescriptor(x,v))})}return g}var p=function(g){return d(d({},g),{},{connect:function(S){var x=S.call;return i(o.mark(function v(){var E,k,I,M;return o.wrap(function(O){for(;;)switch(O.prev=O.next){case 0:return E=new MessageChannel,k=E.port1,I=E.port2,O.next=1,x("connect",{port:k},[k]);case 1:return M=O.sent,a.set(I,M),O.abrupt("return",I);case 2:case"end":return O.stop()}},v)}))},disconnect:function(S){var x=S.call;return(function(){var v=i(o.mark(function E(k){var I;return o.wrap(function(M){for(;;)switch(M.prev=M.next){case 0:if(I=a.get(k),I!==void 0){M.next=1;break}throw new Error("The given port is not connected.");case 1:return M.next=2,x("disconnect",{portId:I});case 2:case"end":return M.stop()}},E)}));return function(E){return v.apply(this,arguments)}})()},isSupported:function(S){var x=S.call;return function(){return x("isSupported")}}})};function y(g,S){var x=Object.keys(g);if(Object.getOwnPropertySymbols){var v=Object.getOwnPropertySymbols(g);S&&(v=v.filter(function(E){return Object.getOwnPropertyDescriptor(g,E).enumerable})),x.push.apply(x,v)}return x}function f(g){for(var S=1;S<arguments.length;S++){var x=arguments[S]!=null?arguments[S]:{};S%2?y(Object(x),!0).forEach(function(v){n(g,v,x[v])}):Object.getOwnPropertyDescriptors?Object.defineProperties(g,Object.getOwnPropertyDescriptors(x)):y(Object(x)).forEach(function(v){Object.defineProperty(g,v,Object.getOwnPropertyDescriptor(x,v))})}return g}var m=new WeakMap,b=function(g){if(m.has(g))return m.get(g);var S=new Map;return m.set(g,S),S},_=function(g){var S=p(g);return function(x){var v=b(x);x.addEventListener("message",function(F){var N=F.data,ae=N.id;if(ae!==null&&v.has(ae)){var Y=v.get(ae),K=Y.reject,re=Y.resolve;v.delete(ae),N.error===void 0?re(N.result):K(new Error(N.error.message))}}),s(x)&&x.start();for(var E=function(F){var N=arguments.length>1&&arguments[1]!==void 0?arguments[1]:null,ae=arguments.length>2&&arguments[2]!==void 0?arguments[2]:[];return new Promise(function(Y,K){var re=r.generateUniqueNumber(v);v.set(re,{reject:K,resolve:Y}),N===null?x.postMessage({id:re,method:F},ae):x.postMessage({id:re,method:F,params:N},ae)})},k=function(F,N){var ae=arguments.length>2&&arguments[2]!==void 0?arguments[2]:[];x.postMessage({id:null,method:F,params:N},ae)},I={},M=0,O=Object.entries(S);M<O.length;M++){var B=l(O[M],2),T=B[0],W=B[1];I=f(f({},I),{},n({},T,W({call:E,notify:k})))}return f({},I)}};t.createBroker=_})}),cc=pe((u,e)=>{le(),ce(),ue(),(function(t,n){typeof u=="object"&&typeof e<"u"?n(u,Lr(),uc(),Ea()):typeof define=="function"&&define.amd?define(["exports","@babel/runtime/helpers/typeof","broker-factory","fast-unique-numbers"],n):(t=typeof globalThis<"u"?globalThis:t||self,n(t.workerTimersBroker={},t._typeof,t.brokerFactory,t.fastUniqueNumbers))})(u,function(t,n,l,r){var i=new Map([[0,null]]),o=new Map([[0,null]]),s=l.createBroker({clearInterval:function(c){var d=c.call;return function(p){n(i.get(p))==="symbol"&&(i.set(p,null),d("clear",{timerId:p,timerType:"interval"}).then(function(){i.delete(p)}))}},clearTimeout:function(c){var d=c.call;return function(p){n(o.get(p))==="symbol"&&(o.set(p,null),d("clear",{timerId:p,timerType:"timeout"}).then(function(){o.delete(p)}))}},setInterval:function(c){var d=c.call;return function(p){for(var y=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,f=arguments.length,m=new Array(f>2?f-2:0),b=2;b<f;b++)m[b-2]=arguments[b];var _=Symbol(),g=r.generateUniqueNumber(i);i.set(g,_);var S=function(){return d("set",{delay:y,now:performance.timeOrigin+performance.now(),timerId:g,timerType:"interval"}).then(function(){var x=i.get(g);if(x===void 0)throw new Error("The timer is in an undefined state.");x===_&&(p.apply(void 0,m),i.get(g)===_&&S())})};return S(),g}},setTimeout:function(c){var d=c.call;return function(p){for(var y=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,f=arguments.length,m=new Array(f>2?f-2:0),b=2;b<f;b++)m[b-2]=arguments[b];var _=Symbol(),g=r.generateUniqueNumber(o);return o.set(g,_),d("set",{delay:y,now:performance.timeOrigin+performance.now(),timerId:g,timerType:"timeout"}).then(function(){var S=o.get(g);if(S===void 0)throw new Error("The timer is in an undefined state.");S===_&&(o.delete(g),p.apply(void 0,m))}),g}}}),a=function(c){var d=new Worker(c);return s(d)};t.load=a,t.wrap=s})}),hc=pe((u,e)=>{le(),ce(),ue(),(function(t,n){typeof u=="object"&&typeof e<"u"?n(u,cc()):typeof define=="function"&&define.amd?define(["exports","worker-timers-broker"],n):(t=typeof globalThis<"u"?globalThis:t||self,n(t.workerTimers={},t.workerTimersBroker))})(u,function(t,n){var l=function(d,p){var y=null;return function(){if(y!==null)return y;var f=new Blob([p],{type:"application/javascript; charset=utf-8"}),m=URL.createObjectURL(f);return y=d(m),setTimeout(function(){return URL.revokeObjectURL(m)}),y}},r=`(()=>{var e={45:(e,t,r)=>{var n=r(738).default;e.exports=function(e,t){if("object"!=n(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var o=r.call(e,t||"default");if("object"!=n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)},e.exports.__esModule=!0,e.exports.default=e.exports},79:e=>{e.exports=function(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n},e.exports.__esModule=!0,e.exports.default=e.exports},122:(e,t,r)=>{var n=r(79);e.exports=function(e,t){if(e){if("string"==typeof e)return n(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}},e.exports.__esModule=!0,e.exports.default=e.exports},156:e=>{e.exports=function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,u,a,i=[],s=!0,c=!1;try{if(u=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=u.call(r)).done)&&(i.push(n.value),i.length!==t);s=!0);}catch(e){c=!0,o=e}finally{try{if(!s&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(c)throw o}}return i}},e.exports.__esModule=!0,e.exports.default=e.exports},172:e=>{e.exports=function(e,t){this.v=e,this.k=t},e.exports.__esModule=!0,e.exports.default=e.exports},293:e=>{function t(e,t,r,n,o,u,a){try{var i=e[u](a),s=i.value}catch(e){return void r(e)}i.done?t(s):Promise.resolve(s).then(n,o)}e.exports=function(e){return function(){var r=this,n=arguments;return new Promise((function(o,u){var a=e.apply(r,n);function i(e){t(a,o,u,i,s,"next",e)}function s(e){t(a,o,u,i,s,"throw",e)}i(void 0)}))}},e.exports.__esModule=!0,e.exports.default=e.exports},373:e=>{e.exports=function(e){var t=Object(e),r=[];for(var n in t)r.unshift(n);return function e(){for(;r.length;)if((n=r.pop())in t)return e.value=n,e.done=!1,e;return e.done=!0,e}},e.exports.__esModule=!0,e.exports.default=e.exports},389:function(e,t){!function(e){"use strict";var t=function(e){return function(t){var r=e(t);return t.add(r),r}},r=function(e){return function(t,r){return e.set(t,r),r}},n=void 0===Number.MAX_SAFE_INTEGER?9007199254740991:Number.MAX_SAFE_INTEGER,o=536870912,u=2*o,a=function(e,t){return function(r){var a=t.get(r),i=void 0===a?r.size:a<u?a+1:0;if(!r.has(i))return e(r,i);if(r.size<o){for(;r.has(i);)i=Math.floor(Math.random()*u);return e(r,i)}if(r.size>n)throw new Error("Congratulations, you created a collection of unique numbers which uses all available integers!");for(;r.has(i);)i=Math.floor(Math.random()*n);return e(r,i)}},i=new WeakMap,s=r(i),c=a(s,i),f=t(c);e.addUniqueNumber=f,e.generateUniqueNumber=c}(t)},472:function(e,t,r){!function(e,t,r,n){"use strict";var o=function(e,t){return function(r){var o=t.get(r);if(void 0===o)return Promise.resolve(!1);var u=n(o,2),a=u[0],i=u[1];return e(a),t.delete(r),i(!1),Promise.resolve(!0)}},u=function(e,t){var r=function(n,o,u,a){var i=n-e.now();i>0?o.set(a,[t(r,i,n,o,u,a),u]):(o.delete(a),u(!0))};return r},a=function(e,t,r,n){return function(o,u,a){var i=o+u-t.timeOrigin,s=i-t.now();return new Promise((function(t){e.set(a,[r(n,s,i,e,t,a),t])}))}},i=new Map,s=o(globalThis.clearTimeout,i),c=new Map,f=o(globalThis.clearTimeout,c),l=u(performance,globalThis.setTimeout),p=a(i,performance,globalThis.setTimeout,l),d=a(c,performance,globalThis.setTimeout,l);r.createWorker(self,{clear:function(){var r=e(t.mark((function e(r){var n,o,u;return t.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.timerId,o=r.timerType,e.next=1,"interval"===o?s(n):f(n);case 1:return u=e.sent,e.abrupt("return",{result:u});case 2:case"end":return e.stop()}}),e)})));function n(e){return r.apply(this,arguments)}return n}(),set:function(){var r=e(t.mark((function e(r){var n,o,u,a,i;return t.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.delay,o=r.now,u=r.timerId,a=r.timerType,e.next=1,("interval"===a?p:d)(n,o,u);case 1:return i=e.sent,e.abrupt("return",{result:i});case 2:case"end":return e.stop()}}),e)})));function n(e){return r.apply(this,arguments)}return n}()})}(r(293),r(756),r(623),r(715))},546:e=>{function t(r,n,o,u){var a=Object.defineProperty;try{a({},"",{})}catch(r){a=0}e.exports=t=function(e,r,n,o){if(r)a?a(e,r,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[r]=n;else{var u=function(r,n){t(e,r,(function(e){return this._invoke(r,n,e)}))};u("next",0),u("throw",1),u("return",2)}},e.exports.__esModule=!0,e.exports.default=e.exports,t(r,n,o,u)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports},579:(e,t,r)=>{var n=r(738).default;e.exports=function(e){if(null!=e){var t=e["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],r=0;if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length))return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}throw new TypeError(n(e)+" is not iterable")},e.exports.__esModule=!0,e.exports.default=e.exports},623:function(e,t,r){!function(e,t,r,n,o){"use strict";var u={INTERNAL_ERROR:-32603,INVALID_PARAMS:-32602,METHOD_NOT_FOUND:-32601},a=function(e,t){return Object.assign(new Error(e),{status:t})},i=function(e){return a('The requested method called "'.concat(e,'" is not supported.'),u.METHOD_NOT_FOUND)},s=function(e){return a('The handler of the method called "'.concat(e,'" returned no required result.'),u.INTERNAL_ERROR)},c=function(e){return a('The handler of the method called "'.concat(e,'" returned an unexpected result.'),u.INTERNAL_ERROR)},f=function(e){return a('The specified parameter called "portId" with the given value "'.concat(e,'" does not identify a port connected to this worker.'),u.INVALID_PARAMS)},l=function(e,n){return function(){var o=t(r.mark((function t(o){var u,a,f,l,p,d,v,x,y,b,h,m,_,g,w;return r.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(u=o.data,a=u.id,f=u.method,l=u.params,p=n[f],t.prev=1,void 0!==p){t.next=2;break}throw i(f);case 2:if(void 0!==(d=void 0===l?p():p(l))){t.next=3;break}throw s(f);case 3:if(!(d instanceof Promise)){t.next=5;break}return t.next=4,d;case 4:g=t.sent,t.next=6;break;case 5:g=d;case 6:if(v=g,null!==a){t.next=8;break}if(void 0===v.result){t.next=7;break}throw c(f);case 7:t.next=10;break;case 8:if(void 0!==v.result){t.next=9;break}throw c(f);case 9:x=v.result,y=v.transferables,b=void 0===y?[]:y,e.postMessage({id:a,result:x},b);case 10:t.next=12;break;case 11:t.prev=11,w=t.catch(1),h=w.message,m=w.status,_=void 0===m?-32603:m,e.postMessage({error:{code:_,message:h},id:a});case 12:case"end":return t.stop()}}),t,null,[[1,11]])})));return function(e){return o.apply(this,arguments)}}()},p=function(){return new Promise((function(e){var t=new ArrayBuffer(0),r=new MessageChannel,n=r.port1,o=r.port2;n.onmessage=function(t){var r=t.data;return e(null!==r)},o.postMessage(t,[t])}))};function d(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function v(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?d(Object(r),!0).forEach((function(t){n(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):d(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var x=new Map,y=function(e,n,u){return v(v({},n),{},{connect:function(t){var r=t.port;r.start();var u=e(r,n),a=o.generateUniqueNumber(x);return x.set(a,(function(){u(),r.close(),x.delete(a)})),{result:a}},disconnect:function(e){var t=e.portId,r=x.get(t);if(void 0===r)throw f(t);return r(),{result:null}},isSupported:function(){var e=t(r.mark((function e(){var t,n,o;return r.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,p();case 1:if(!e.sent){e.next=5;break}if(!((t=u())instanceof Promise)){e.next=3;break}return e.next=2,t;case 2:o=e.sent,e.next=4;break;case 3:o=t;case 4:return n=o,e.abrupt("return",{result:n});case 5:return e.abrupt("return",{result:!1});case 6:case"end":return e.stop()}}),e)})));function n(){return e.apply(this,arguments)}return n}()})},b=function(e,t){var r=y(b,t,arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){return!0}),n=l(e,r);return e.addEventListener("message",n),function(){return e.removeEventListener("message",n)}};e.createWorker=b,e.isSupported=p}(t,r(293),r(756),r(693),r(389))},633:(e,t,r)=>{var n=r(172),o=r(993),u=r(869),a=r(887),i=r(791),s=r(373),c=r(579);function f(){"use strict";var t=o(),r=t.m(f),l=(Object.getPrototypeOf?Object.getPrototypeOf(r):r.__proto__).constructor;function p(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===l||"GeneratorFunction"===(t.displayName||t.name))}var d={throw:1,return:2,break:3,continue:3};function v(e){var t,r;return function(n){t||(t={stop:function(){return r(n.a,2)},catch:function(){return n.v},abrupt:function(e,t){return r(n.a,d[e],t)},delegateYield:function(e,o,u){return t.resultName=o,r(n.d,c(e),u)},finish:function(e){return r(n.f,e)}},r=function(e,r,o){n.p=t.prev,n.n=t.next;try{return e(r,o)}finally{t.next=n.n}}),t.resultName&&(t[t.resultName]=n.v,t.resultName=void 0),t.sent=n.v,t.next=n.n;try{return e.call(this,t)}finally{n.p=t.prev,n.n=t.next}}}return(e.exports=f=function(){return{wrap:function(e,r,n,o){return t.w(v(e),r,n,o&&o.reverse())},isGeneratorFunction:p,mark:t.m,awrap:function(e,t){return new n(e,t)},AsyncIterator:i,async:function(e,t,r,n,o){return(p(t)?a:u)(v(e),t,r,n,o)},keys:s,values:c}},e.exports.__esModule=!0,e.exports.default=e.exports)()}e.exports=f,e.exports.__esModule=!0,e.exports.default=e.exports},693:(e,t,r)=>{var n=r(736);e.exports=function(e,t,r){return(t=n(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e},e.exports.__esModule=!0,e.exports.default=e.exports},715:(e,t,r)=>{var n=r(987),o=r(156),u=r(122),a=r(752);e.exports=function(e,t){return n(e)||o(e,t)||u(e,t)||a()},e.exports.__esModule=!0,e.exports.default=e.exports},736:(e,t,r)=>{var n=r(738).default,o=r(45);e.exports=function(e){var t=o(e,"string");return"symbol"==n(t)?t:t+""},e.exports.__esModule=!0,e.exports.default=e.exports},738:e=>{function t(r){return e.exports=t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.__esModule=!0,e.exports.default=e.exports,t(r)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports},752:e=>{e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.__esModule=!0,e.exports.default=e.exports},756:(e,t,r)=>{var n=r(633)();e.exports=n;try{regeneratorRuntime=n}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=n:Function("r","regeneratorRuntime = r")(n)}},791:(e,t,r)=>{var n=r(172),o=r(546);e.exports=function e(t,r){function u(e,o,a,i){try{var s=t[e](o),c=s.value;return c instanceof n?r.resolve(c.v).then((function(e){u("next",e,a,i)}),(function(e){u("throw",e,a,i)})):r.resolve(c).then((function(e){s.value=e,a(s)}),(function(e){return u("throw",e,a,i)}))}catch(e){i(e)}}var a;this.next||(o(e.prototype),o(e.prototype,"function"==typeof Symbol&&Symbol.asyncIterator||"@asyncIterator",(function(){return this}))),o(this,"_invoke",(function(e,t,n){function o(){return new r((function(t,r){u(e,n,t,r)}))}return a=a?a.then(o,o):o()}),!0)},e.exports.__esModule=!0,e.exports.default=e.exports},869:(e,t,r)=>{var n=r(887);e.exports=function(e,t,r,o,u){var a=n(e,t,r,o,u);return a.next().then((function(e){return e.done?e.value:a.next()}))},e.exports.__esModule=!0,e.exports.default=e.exports},887:(e,t,r)=>{var n=r(993),o=r(791);e.exports=function(e,t,r,u,a){return new o(n().w(e,t,r,u),a||Promise)},e.exports.__esModule=!0,e.exports.default=e.exports},987:e=>{e.exports=function(e){if(Array.isArray(e))return e},e.exports.__esModule=!0,e.exports.default=e.exports},993:(e,t,r)=>{var n=r(546);function o(){var t,r,u="function"==typeof Symbol?Symbol:{},a=u.iterator||"@@iterator",i=u.toStringTag||"@@toStringTag";function s(e,o,u,a){var i=o&&o.prototype instanceof f?o:f,s=Object.create(i.prototype);return n(s,"_invoke",function(e,n,o){var u,a,i,s=0,f=o||[],l=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,r){return u=e,a=0,i=t,p.n=r,c}};function d(e,n){for(a=e,i=n,r=0;!l&&s&&!o&&r<f.length;r++){var o,u=f[r],d=p.p,v=u[2];e>3?(o=v===n)&&(i=u[(a=u[4])?5:(a=3,3)],u[4]=u[5]=t):u[0]<=d&&((o=e<2&&d<u[1])?(a=0,p.v=n,p.n=u[1]):d<v&&(o=e<3||u[0]>n||n>v)&&(u[4]=e,u[5]=n,p.n=v,a=0))}if(o||e>1)return c;throw l=!0,n}return function(o,f,v){if(s>1)throw TypeError("Generator is already running");for(l&&1===f&&d(f,v),a=f,i=v;(r=a<2?t:i)||!l;){u||(a?a<3?(a>1&&(p.n=-1),d(a,i)):p.n=i:p.v=i);try{if(s=2,u){if(a||(o="next"),r=u[o]){if(!(r=r.call(u,i)))throw TypeError("iterator result is not an object");if(!r.done)return r;i=r.value,a<2&&(a=0)}else 1===a&&(r=u.return)&&r.call(u),a<2&&(i=TypeError("The iterator does not provide a '"+o+"' method"),a=1);u=t}else if((r=(l=p.n<0)?i:e.call(n,p))!==c)break}catch(e){u=t,a=1,i=e}finally{s=1}}return{value:r,done:l}}}(e,u,a),!0),s}var c={};function f(){}function l(){}function p(){}r=Object.getPrototypeOf;var d=[][a]?r(r([][a]())):(n(r={},a,(function(){return this})),r),v=p.prototype=f.prototype=Object.create(d);function x(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,p):(e.__proto__=p,n(e,i,"GeneratorFunction")),e.prototype=Object.create(v),e}return l.prototype=p,n(v,"constructor",p),n(p,"constructor",l),l.displayName="GeneratorFunction",n(p,i,"GeneratorFunction"),n(v),n(v,i,"Generator"),n(v,a,(function(){return this})),n(v,"toString",(function(){return"[object Generator]"})),(e.exports=o=function(){return{w:s,m:x}},e.exports.__esModule=!0,e.exports.default=e.exports)()}e.exports=o,e.exports.__esModule=!0,e.exports.default=e.exports}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var u=t[n]={exports:{}};return e[n].call(u.exports,u,u.exports,r),u.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";r(472)})()})();`,i=l(n.load,r),o=function(d){return i().clearInterval(d)},s=function(d){return i().clearTimeout(d)},a=function(){var d;return(d=i()).setInterval.apply(d,arguments)},c=function(){var d;return(d=i()).setTimeout.apply(d,arguments)};t.clearInterval=o,t.clearTimeout=s,t.setInterval=a,t.setTimeout=c})}),Nr=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"__esModule",{value:!0}),u.isReactNativeBrowser=u.isWebWorker=void 0;var e=()=>typeof window<"u"?typeof navigator<"u"&&navigator.userAgent?.toLowerCase().indexOf(" electron/")>-1&&Pe?.versions?!Object.prototype.hasOwnProperty.call(Pe.versions,"electron"):typeof window.document<"u":!1,t=()=>!!(typeof self=="object"&&self?.constructor?.name?.includes("WorkerGlobalScope")&&typeof Deno>"u"),n=()=>typeof navigator<"u"&&navigator.product==="ReactNative",l=e()||t()||n();u.isWebWorker=t(),u.isReactNativeBrowser=n(),u.default=l}),fc=pe(u=>{le(),ce(),ue();var e=u&&u.__createBinding||(Object.create?function(a,c,d,p){p===void 0&&(p=d);var y=Object.getOwnPropertyDescriptor(c,d);(!y||("get"in y?!c.__esModule:y.writable||y.configurable))&&(y={enumerable:!0,get:function(){return c[d]}}),Object.defineProperty(a,p,y)}:function(a,c,d,p){p===void 0&&(p=d),a[p]=c[d]}),t=u&&u.__setModuleDefault||(Object.create?function(a,c){Object.defineProperty(a,"default",{enumerable:!0,value:c})}:function(a,c){a.default=c}),n=u&&u.__importStar||(function(){var a=function(c){return a=Object.getOwnPropertyNames||function(d){var p=[];for(var y in d)Object.prototype.hasOwnProperty.call(d,y)&&(p[p.length]=y);return p},a(c)};return function(c){if(c&&c.__esModule)return c;var d={};if(c!=null)for(var p=a(c),y=0;y<p.length;y++)p[y]!=="default"&&e(d,c,p[y]);return t(d,c),d}})();Object.defineProperty(u,"__esModule",{value:!0});var l=hc(),r=n(Nr()),i={set:l.setInterval,clear:l.clearInterval},o={set:(a,c)=>setInterval(a,c),clear:a=>clearInterval(a)},s=a=>{switch(a){case"native":return o;case"worker":return i;default:return r.default&&!r.isWebWorker&&!r.isReactNativeBrowser?i:o}};u.default=s}),Oa=pe(u=>{le(),ce(),ue();var e=u&&u.__importDefault||function(l){return l&&l.__esModule?l:{default:l}};Object.defineProperty(u,"__esModule",{value:!0});var t=e(fc()),n=class{_keepalive;timerId;timer;destroyed=!1;counter;client;_keepaliveTimeoutTimestamp;_intervalEvery;get keepaliveTimeoutTimestamp(){return this._keepaliveTimeoutTimestamp}get intervalEvery(){return this._intervalEvery}get keepalive(){return this._keepalive}constructor(l,r){this.client=l,this.timer=typeof r=="object"&&"set"in r&&"clear"in r?r:(0,t.default)(r),this.setKeepalive(l.options.keepalive)}clear(){this.timerId&&(this.timer.clear(this.timerId),this.timerId=null)}setKeepalive(l){if(l*=1e3,isNaN(l)||l<=0||l>2147483647)throw new Error(`Keepalive value must be an integer between 0 and 2147483647. Provided value is ${l}`);this._keepalive=l,this.reschedule(),this.client.log(`KeepaliveManager: set keepalive to ${l}ms`)}destroy(){this.clear(),this.destroyed=!0}reschedule(){if(this.destroyed)return;this.clear(),this.counter=0;let l=Math.ceil(this._keepalive*1.5);this._keepaliveTimeoutTimestamp=Date.now()+l,this._intervalEvery=Math.ceil(this._keepalive/2),this.timerId=this.timer.set(()=>{this.destroyed||(this.counter+=1,this.counter===2?this.client.sendPing():this.counter>2&&this.client.onKeepaliveTimeout())},this._intervalEvery)}};u.default=n}),ni=pe(u=>{le(),ce(),ue();var e=u&&u.__createBinding||(Object.create?function(v,E,k,I){I===void 0&&(I=k);var M=Object.getOwnPropertyDescriptor(E,k);(!M||("get"in M?!E.__esModule:M.writable||M.configurable))&&(M={enumerable:!0,get:function(){return E[k]}}),Object.defineProperty(v,I,M)}:function(v,E,k,I){I===void 0&&(I=k),v[I]=E[k]}),t=u&&u.__setModuleDefault||(Object.create?function(v,E){Object.defineProperty(v,"default",{enumerable:!0,value:E})}:function(v,E){v.default=E}),n=u&&u.__importStar||(function(){var v=function(E){return v=Object.getOwnPropertyNames||function(k){var I=[];for(var M in k)Object.prototype.hasOwnProperty.call(k,M)&&(I[I.length]=M);return I},v(E)};return function(E){if(E&&E.__esModule)return E;var k={};if(E!=null)for(var I=v(E),M=0;M<I.length;M++)I[M]!=="default"&&e(k,E,I[M]);return t(k,E),k}})(),l=u&&u.__importDefault||function(v){return v&&v.__esModule?v:{default:v}};Object.defineProperty(u,"__esModule",{value:!0});var r=l(Su()),i=At(),o=l(Eu()),s=l(at()),a=n(sa()),c=l(oa()),d=l(zu()),p=l(ka()),y=l(Ku()),f=Nt(),m=Vu(),b=l(Oa()),_=n(Nr()),g=globalThis.setImmediate||((...v)=>{let E=v.shift();(0,f.nextTick)(()=>{E(...v)})}),S={keepalive:60,reschedulePings:!0,protocolId:"MQTT",protocolVersion:4,reconnectPeriod:1e3,connectTimeout:30*1e3,clean:!0,resubscribe:!0,subscribeBatchSize:null,writeCache:!0,timerVariant:"auto"},x=class ii extends m.TypedEventEmitter{static VERSION=f.MQTTJS_VERSION;connected;disconnecting;disconnected;reconnecting;incomingStore;outgoingStore;options;queueQoSZero;_reconnectCount;log;messageIdProvider;outgoing;messageIdToTopic;noop;keepaliveManager;stream;queue;streamBuilder;_resubscribeTopics;connackTimer;reconnectTimer;_storeProcessing;_packetIdsDuringStoreProcessing;_storeProcessingQueue;_firstConnection;topicAliasRecv;topicAliasSend;_deferredReconnect;connackPacket;static defaultId(){return`mqttjs_${Math.random().toString(16).substr(2,8)}`}constructor(E,k){super(),this.options=k||{};for(let I in S)typeof this.options[I]>"u"?this.options[I]=S[I]:this.options[I]=k[I];this.log=this.options.log||(0,s.default)("mqttjs:client"),this.noop=this._noop.bind(this),this.log("MqttClient :: version:",ii.VERSION),_.isWebWorker?this.log("MqttClient :: environment","webworker"):this.log("MqttClient :: environment",_.default?"browser":"node"),this.log("MqttClient :: options.protocol",k.protocol),this.log("MqttClient :: options.protocolVersion",k.protocolVersion),this.log("MqttClient :: options.username",k.username),this.log("MqttClient :: options.keepalive",k.keepalive),this.log("MqttClient :: options.reconnectPeriod",k.reconnectPeriod),this.log("MqttClient :: options.rejectUnauthorized",k.rejectUnauthorized),this.log("MqttClient :: options.properties.topicAliasMaximum",k.properties?k.properties.topicAliasMaximum:void 0),this.options.clientId=typeof k.clientId=="string"?k.clientId:ii.defaultId(),this.log("MqttClient :: clientId",this.options.clientId),this.options.customHandleAcks=k.protocolVersion===5&&k.customHandleAcks?k.customHandleAcks:(...I)=>{I[3](null,0)},this.options.writeCache||(r.default.writeToStream.cacheNumbers=!1),this.streamBuilder=E,this.messageIdProvider=typeof this.options.messageIdProvider>"u"?new p.default:this.options.messageIdProvider,this.outgoingStore=k.outgoingStore||new c.default,this.incomingStore=k.incomingStore||new c.default,this.queueQoSZero=k.queueQoSZero===void 0?!0:k.queueQoSZero,this._resubscribeTopics={},this.messageIdToTopic={},this.keepaliveManager=null,this.connected=!1,this.disconnecting=!1,this.reconnecting=!1,this.queue=[],this.connackTimer=null,this.reconnectTimer=null,this._storeProcessing=!1,this._packetIdsDuringStoreProcessing={},this._storeProcessingQueue=[],this.outgoing={},this._firstConnection=!0,k.properties&&k.properties.topicAliasMaximum>0&&(k.properties.topicAliasMaximum>65535?this.log("MqttClient :: options.properties.topicAliasMaximum is out of range"):this.topicAliasRecv=new y.default(k.properties.topicAliasMaximum)),this.on("connect",()=>{let{queue:I}=this,M=()=>{let O=I.shift();this.log("deliver :: entry %o",O);let B=null;if(!O){this._resubscribe();return}B=O.packet,this.log("deliver :: call _sendPacket for %o",B);let T=!0;B.messageId&&B.messageId!==0&&(this.messageIdProvider.register(B.messageId)||(T=!1)),T?this._sendPacket(B,W=>{O.cb&&O.cb(W),M()}):(this.log("messageId: %d has already used. The message is skipped and removed.",B.messageId),M())};this.log("connect :: sending queued packets"),M()}),this.on("close",()=>{this.log("close :: connected set to `false`"),this.connected=!1,this.log("close :: clearing connackTimer"),clearTimeout(this.connackTimer),this._destroyKeepaliveManager(),this.topicAliasRecv&&this.topicAliasRecv.clear(),this.log("close :: calling _setupReconnect"),this._setupReconnect()}),this.options.manualConnect||(this.log("MqttClient :: setting up stream"),this.connect())}handleAuth(E,k){k()}handleMessage(E,k){k()}_nextId(){return this.messageIdProvider.allocate()}getLastMessageId(){return this.messageIdProvider.getLastAllocated()}connect(){let E=new i.Writable,k=r.default.parser(this.options),I=null,M=[];this.log("connect :: calling method to clear reconnect"),this._clearReconnect(),this.disconnected&&!this.reconnecting&&(this.incomingStore=this.options.incomingStore||new c.default,this.outgoingStore=this.options.outgoingStore||new c.default,this.disconnecting=!1,this.disconnected=!1),this.log("connect :: using streamBuilder provided to client to create stream"),this.stream=this.streamBuilder(this),k.on("packet",F=>{this.log("parser :: on packet push to packets array."),M.push(F)});let O=()=>{this.log("work :: getting next packet in queue");let F=M.shift();if(F)this.log("work :: packet pulled from queue"),(0,d.default)(this,F,B);else{this.log("work :: no packets in queue");let N=I;I=null,this.log("work :: done flag is %s",!!N),N&&N()}},B=()=>{if(M.length)(0,f.nextTick)(O);else{let F=I;I=null,F()}};E._write=(F,N,ae)=>{I=ae,this.log("writable stream :: parsing buffer"),k.parse(F),O()};let T=F=>{this.log("streamErrorHandler :: error",F.message),F.code?(this.log("streamErrorHandler :: emitting error"),this.emit("error",F)):this.noop(F)};this.log("connect :: pipe stream to writable stream"),this.stream.pipe(E),this.stream.on("error",T),this.stream.on("close",()=>{this.log("(%s)stream :: on close",this.options.clientId),this._flushVolatile(),this.log("stream: emit close to MqttClient"),this.emit("close")}),this.log("connect: sending packet `connect`");let W={cmd:"connect",protocolId:this.options.protocolId,protocolVersion:this.options.protocolVersion,clean:this.options.clean,clientId:this.options.clientId,keepalive:this.options.keepalive,username:this.options.username,password:this.options.password,properties:this.options.properties};if(this.options.will&&(W.will={...this.options.will,payload:this.options.will?.payload}),this.topicAliasRecv&&(W.properties||(W.properties={}),this.topicAliasRecv&&(W.properties.topicAliasMaximum=this.topicAliasRecv.max)),this._writePacket(W),k.on("error",this.emit.bind(this,"error")),this.options.properties){if(!this.options.properties.authenticationMethod&&this.options.properties.authenticationData)return this.end(()=>this.emit("error",new Error("Packet has no Authentication Method"))),this;if(this.options.properties.authenticationMethod&&this.options.authPacket&&typeof this.options.authPacket=="object"){let F={cmd:"auth",reasonCode:0,...this.options.authPacket};this._writePacket(F)}}return this.stream.setMaxListeners(1e3),clearTimeout(this.connackTimer),this.connackTimer=setTimeout(()=>{this.log("!!connectTimeout hit!! Calling _cleanUp with force `true`"),this.emit("error",new Error("connack timeout")),this._cleanUp(!0)},this.options.connectTimeout),this}publish(E,k,I,M){this.log("publish :: message `%s` to topic `%s`",k,E);let{options:O}=this;typeof I=="function"&&(M=I,I=null),I=I||{},I={qos:0,retain:!1,dup:!1,...I};let{qos:B,retain:T,dup:W,properties:F,cbStorePut:N}=I;if(this._checkDisconnecting(M))return this;let ae=()=>{let Y=0;if((B===1||B===2)&&(Y=this._nextId(),Y===null))return this.log("No messageId left"),!1;let K={cmd:"publish",topic:E,payload:k,qos:B,retain:T,messageId:Y,dup:W};switch(O.protocolVersion===5&&(K.properties=F),this.log("publish :: qos",B),B){case 1:case 2:this.outgoing[K.messageId]={volatile:!1,cb:M||this.noop},this.log("MqttClient:publish: packet cmd: %s",K.cmd),this._sendPacket(K,void 0,N);break;default:this.log("MqttClient:publish: packet cmd: %s",K.cmd),this._sendPacket(K,M,N);break}return!0};return(this._storeProcessing||this._storeProcessingQueue.length>0||!ae())&&this._storeProcessingQueue.push({invoke:ae,cbStorePut:I.cbStorePut,callback:M}),this}publishAsync(E,k,I){return new Promise((M,O)=>{this.publish(E,k,I,(B,T)=>{B?O(B):M(T)})})}subscribe(E,k,I){let M=this.options.protocolVersion;typeof k=="function"&&(I=k),I=I||this.noop;let O=!1,B=[];typeof E=="string"?(E=[E],B=E):Array.isArray(E)?B=E:typeof E=="object"&&(O=E.resubscribe,delete E.resubscribe,B=Object.keys(E));let T=a.validateTopics(B);if(T!==null)return g(I,new Error(`Invalid topic ${T}`)),this;if(this._checkDisconnecting(I))return this.log("subscribe: discconecting true"),this;let W={qos:0};M===5&&(W.nl=!1,W.rap=!1,W.rh=0),k={...W,...k};let{properties:F}=k,N=[],ae=(re,D)=>{if(D=D||k,!Object.prototype.hasOwnProperty.call(this._resubscribeTopics,re)||this._resubscribeTopics[re].qos<D.qos||O){let Z={topic:re,qos:D.qos};M===5&&(Z.nl=D.nl,Z.rap=D.rap,Z.rh=D.rh,Z.properties=F),this.log("subscribe: pushing topic `%s` and qos `%s` to subs list",Z.topic,Z.qos),N.push(Z)}};if(Array.isArray(E)?E.forEach(re=>{this.log("subscribe: array topic %s",re),ae(re)}):Object.keys(E).forEach(re=>{this.log("subscribe: object topic %s, %o",re,E[re]),ae(re,E[re])}),!N.length)return I(null,[]),this;let Y=(re,D)=>{let Z={cmd:"subscribe",subscriptions:re,messageId:D};if(F&&(Z.properties=F),this.options.resubscribe){this.log("subscribe :: resubscribe true");let J=[];re.forEach(be=>{if(this.options.reconnectPeriod>0){let te={qos:be.qos};M===5&&(te.nl=be.nl||!1,te.rap=be.rap||!1,te.rh=be.rh||0,te.properties=be.properties),this._resubscribeTopics[be.topic]=te,J.push(be.topic)}}),this.messageIdToTopic[Z.messageId]=J}let P=new Promise((J,be)=>{this.outgoing[Z.messageId]={volatile:!0,cb(te,we){if(!te){let{granted:V}=we;for(let L=0;L<V.length;L+=1)re[L].qos=V[L]}te?be(new f.ErrorWithSubackPacket(te.message,we)):J(we)}}});return this.log("subscribe :: call _sendPacket"),this._sendPacket(Z),P},K=()=>{let re=this.options.subscribeBatchSize??N.length,D=[];for(let Z=0;Z<N.length;Z+=re){let P=N.slice(Z,Z+re),J=this._nextId();if(J===null)return this.log("No messageId left"),!1;D.push(Y(P,J))}return Promise.all(D).then(Z=>{I(null,N,Z.at(-1))}).catch(Z=>{I(Z,N,Z.packet)}),!0};return(this._storeProcessing||this._storeProcessingQueue.length>0||!K())&&this._storeProcessingQueue.push({invoke:K,callback:I}),this}subscribeAsync(E,k){return new Promise((I,M)=>{this.subscribe(E,k,(O,B)=>{O?M(O):I(B)})})}unsubscribe(E,k,I){typeof E=="string"&&(E=[E]),typeof k=="function"&&(I=k),I=I||this.noop;let M=a.validateTopics(E);if(M!==null)return g(I,new Error(`Invalid topic ${M}`)),this;if(this._checkDisconnecting(I))return this;let O=()=>{let B=this._nextId();if(B===null)return this.log("No messageId left"),!1;let T={cmd:"unsubscribe",messageId:B,unsubscriptions:[]};return typeof E=="string"?T.unsubscriptions=[E]:Array.isArray(E)&&(T.unsubscriptions=E),this.options.resubscribe&&T.unsubscriptions.forEach(W=>{delete this._resubscribeTopics[W]}),typeof k=="object"&&k.properties&&(T.properties=k.properties),this.outgoing[T.messageId]={volatile:!0,cb:I},this.log("unsubscribe: call _sendPacket"),this._sendPacket(T),!0};return(this._storeProcessing||this._storeProcessingQueue.length>0||!O())&&this._storeProcessingQueue.push({invoke:O,callback:I}),this}unsubscribeAsync(E,k){return new Promise((I,M)=>{this.unsubscribe(E,k,(O,B)=>{O?M(O):I(B)})})}end(E,k,I){this.log("end :: (%s)",this.options.clientId),(E==null||typeof E!="boolean")&&(I=I||k,k=E,E=!1),typeof k!="object"&&(I=I||k,k=null),this.log("end :: cb? %s",!!I),(!I||typeof I!="function")&&(I=this.noop);let M=()=>{this.log("end :: closeStores: closing incoming and outgoing stores"),this.disconnected=!0,this.incomingStore.close(B=>{this.outgoingStore.close(T=>{if(this.log("end :: closeStores: emitting end"),this.emit("end"),I){let W=B||T;this.log("end :: closeStores: invoking callback with args"),I(W)}})}),this._deferredReconnect?this._deferredReconnect():(this.options.reconnectPeriod===0||this.options.manualConnect)&&(this.disconnecting=!1)},O=()=>{this.log("end :: (%s) :: finish :: calling _cleanUp with force %s",this.options.clientId,E),this._cleanUp(E,()=>{this.log("end :: finish :: calling process.nextTick on closeStores"),(0,f.nextTick)(M)},k)};return this.disconnecting?(I(),this):(this._clearReconnect(),this.disconnecting=!0,!E&&Object.keys(this.outgoing).length>0?(this.log("end :: (%s) :: calling finish in 10ms once outgoing is empty",this.options.clientId),this.once("outgoingEmpty",setTimeout.bind(null,O,10))):(this.log("end :: (%s) :: immediately calling finish",this.options.clientId),O()),this)}endAsync(E,k){return new Promise((I,M)=>{this.end(E,k,O=>{O?M(O):I()})})}removeOutgoingMessage(E){if(this.outgoing[E]){let{cb:k}=this.outgoing[E];this._removeOutgoingAndStoreMessage(E,()=>{k(new Error("Message removed"))})}return this}reconnect(E){this.log("client reconnect");let k=()=>{E?(this.options.incomingStore=E.incomingStore,this.options.outgoingStore=E.outgoingStore):(this.options.incomingStore=null,this.options.outgoingStore=null),this.incomingStore=this.options.incomingStore||new c.default,this.outgoingStore=this.options.outgoingStore||new c.default,this.disconnecting=!1,this.disconnected=!1,this._deferredReconnect=null,this._reconnect()};return this.disconnecting&&!this.disconnected?this._deferredReconnect=k:k(),this}_flushVolatile(){this.outgoing&&(this.log("_flushVolatile :: deleting volatile messages from the queue and setting their callbacks as error function"),Object.keys(this.outgoing).forEach(E=>{this.outgoing[E].volatile&&typeof this.outgoing[E].cb=="function"&&(this.outgoing[E].cb(new Error("Connection closed")),delete this.outgoing[E])}))}_flush(){this.outgoing&&(this.log("_flush: queue exists? %b",!!this.outgoing),Object.keys(this.outgoing).forEach(E=>{typeof this.outgoing[E].cb=="function"&&(this.outgoing[E].cb(new Error("Connection closed")),delete this.outgoing[E])}))}_removeTopicAliasAndRecoverTopicName(E){let k;E.properties&&(k=E.properties.topicAlias);let I=E.topic.toString();if(this.log("_removeTopicAliasAndRecoverTopicName :: alias %d, topic %o",k,I),I.length===0){if(typeof k>"u")return new Error("Unregistered Topic Alias");if(I=this.topicAliasSend.getTopicByAlias(k),typeof I>"u")return new Error("Unregistered Topic Alias");E.topic=I}k&&delete E.properties.topicAlias}_checkDisconnecting(E){return this.disconnecting&&(E&&E!==this.noop?E(new Error("client disconnecting")):this.emit("error",new Error("client disconnecting"))),this.disconnecting}_reconnect(){this.log("_reconnect: emitting reconnect to client"),this.emit("reconnect"),this.connected?(this.end(()=>{this.connect()}),this.log("client already connected. disconnecting first.")):(this.log("_reconnect: calling connect"),this.connect())}_setupReconnect(){!this.disconnecting&&!this.reconnectTimer&&this.options.reconnectPeriod>0?(this.reconnecting||(this.log("_setupReconnect :: emit `offline` state"),this.emit("offline"),this.log("_setupReconnect :: set `reconnecting` to `true`"),this.reconnecting=!0),this.log("_setupReconnect :: setting reconnectTimer for %d ms",this.options.reconnectPeriod),this.reconnectTimer=setInterval(()=>{this.log("reconnectTimer :: reconnect triggered!"),this._reconnect()},this.options.reconnectPeriod)):this.log("_setupReconnect :: doing nothing...")}_clearReconnect(){this.log("_clearReconnect : clearing reconnect timer"),this.reconnectTimer&&(clearInterval(this.reconnectTimer),this.reconnectTimer=null)}_cleanUp(E,k,I={}){if(k&&(this.log("_cleanUp :: done callback provided for on stream close"),this.stream.on("close",k)),this.log("_cleanUp :: forced? %s",E),E)this.options.reconnectPeriod===0&&this.options.clean&&this._flush(),this.log("_cleanUp :: (%s) :: destroying stream",this.options.clientId),this.stream.destroy();else{let M={cmd:"disconnect",...I};this.log("_cleanUp :: (%s) :: call _sendPacket with disconnect packet",this.options.clientId),this._sendPacket(M,()=>{this.log("_cleanUp :: (%s) :: destroying stream",this.options.clientId),g(()=>{this.stream.end(()=>{this.log("_cleanUp :: (%s) :: stream destroyed",this.options.clientId)})})})}!this.disconnecting&&!this.reconnecting&&(this.log("_cleanUp :: client not disconnecting/reconnecting. Clearing and resetting reconnect."),this._clearReconnect(),this._setupReconnect()),this._destroyKeepaliveManager(),k&&!this.connected&&(this.log("_cleanUp :: (%s) :: removing stream `done` callback `close` listener",this.options.clientId),this.stream.removeListener("close",k),k())}_storeAndSend(E,k,I){this.log("storeAndSend :: store packet with cmd %s to outgoingStore",E.cmd);let M=E,O;if(M.cmd==="publish"&&(M=(0,o.default)(E),O=this._removeTopicAliasAndRecoverTopicName(M),O))return k&&k(O);this.outgoingStore.put(M,B=>{if(B)return k&&k(B);I(),this._writePacket(E,k)})}_applyTopicAlias(E){if(this.options.protocolVersion===5&&E.cmd==="publish"){let k;E.properties&&(k=E.properties.topicAlias);let I=E.topic.toString();if(this.topicAliasSend)if(k){if(I.length!==0&&(this.log("applyTopicAlias :: register topic: %s - alias: %d",I,k),!this.topicAliasSend.put(I,k)))return this.log("applyTopicAlias :: error out of range. topic: %s - alias: %d",I,k),new Error("Sending Topic Alias out of range")}else I.length!==0&&(this.options.autoAssignTopicAlias?(k=this.topicAliasSend.getAliasByTopic(I),k?(E.topic="",E.properties={...E.properties,topicAlias:k},this.log("applyTopicAlias :: auto assign(use) topic: %s - alias: %d",I,k)):(k=this.topicAliasSend.getLruAlias(),this.topicAliasSend.put(I,k),E.properties={...E.properties,topicAlias:k},this.log("applyTopicAlias :: auto assign topic: %s - alias: %d",I,k))):this.options.autoUseTopicAlias&&(k=this.topicAliasSend.getAliasByTopic(I),k&&(E.topic="",E.properties={...E.properties,topicAlias:k},this.log("applyTopicAlias :: auto use topic: %s - alias: %d",I,k))));else if(k)return this.log("applyTopicAlias :: error out of range. topic: %s - alias: %d",I,k),new Error("Sending Topic Alias out of range")}}_noop(E){this.log("noop ::",E)}_writePacket(E,k){this.log("_writePacket :: packet: %O",E),this.log("_writePacket :: emitting `packetsend`"),this.emit("packetsend",E),this.log("_writePacket :: writing to stream");let I=r.default.writeToStream(E,this.stream,this.options);this.log("_writePacket :: writeToStream result %s",I),!I&&k&&k!==this.noop?(this.log("_writePacket :: handle events on `drain` once through callback."),this.stream.once("drain",k)):k&&(this.log("_writePacket :: invoking cb"),k())}_sendPacket(E,k,I,M){this.log("_sendPacket :: (%s) :: start",this.options.clientId),I=I||this.noop,k=k||this.noop;let O=this._applyTopicAlias(E);if(O){k(O);return}if(!this.connected){if(E.cmd==="auth"){this._writePacket(E,k);return}this.log("_sendPacket :: client not connected. Storing packet offline."),this._storePacket(E,k,I);return}if(M){this._writePacket(E,k);return}switch(E.cmd){case"publish":break;case"pubrel":this._storeAndSend(E,k,I);return;default:this._writePacket(E,k);return}switch(E.qos){case 2:case 1:this._storeAndSend(E,k,I);break;default:this._writePacket(E,k);break}this.log("_sendPacket :: (%s) :: end",this.options.clientId)}_storePacket(E,k,I){this.log("_storePacket :: packet: %o",E),this.log("_storePacket :: cb? %s",!!k),I=I||this.noop;let M=E;if(M.cmd==="publish"){M=(0,o.default)(E);let B=this._removeTopicAliasAndRecoverTopicName(M);if(B)return k&&k(B)}let O=M.qos||0;O===0&&this.queueQoSZero||M.cmd!=="publish"?this.queue.push({packet:M,cb:k}):O>0?(k=this.outgoing[M.messageId]?this.outgoing[M.messageId].cb:null,this.outgoingStore.put(M,B=>{if(B)return k&&k(B);I()})):k&&k(new Error("No connection to broker"))}_setupKeepaliveManager(){this.log("_setupKeepaliveManager :: keepalive %d (seconds)",this.options.keepalive),!this.keepaliveManager&&this.options.keepalive&&(this.keepaliveManager=new b.default(this,this.options.timerVariant))}_destroyKeepaliveManager(){this.keepaliveManager&&(this.log("_destroyKeepaliveManager :: destroying keepalive manager"),this.keepaliveManager.destroy(),this.keepaliveManager=null)}reschedulePing(E=!1){this.keepaliveManager&&this.options.keepalive&&(E||this.options.reschedulePings)&&this._reschedulePing()}_reschedulePing(){this.log("_reschedulePing :: rescheduling ping"),this.keepaliveManager.reschedule()}sendPing(){this.log("_sendPing :: sending pingreq"),this._sendPacket({cmd:"pingreq"})}onKeepaliveTimeout(){this.emit("error",new Error("Keepalive timeout")),this.log("onKeepaliveTimeout :: calling _cleanUp with force true"),this._cleanUp(!0)}_resubscribe(){this.log("_resubscribe");let E=Object.keys(this._resubscribeTopics);if(!this._firstConnection&&(this.options.clean||this.options.protocolVersion>=4&&!this.connackPacket.sessionPresent)&&E.length>0)if(this.options.resubscribe)if(this.options.protocolVersion===5){this.log("_resubscribe: protocolVersion 5");for(let k=0;k<E.length;k++){let I={};I[E[k]]=this._resubscribeTopics[E[k]],I.resubscribe=!0,this.subscribe(I,{properties:I[E[k]].properties})}}else this._resubscribeTopics.resubscribe=!0,this.subscribe(this._resubscribeTopics);else this._resubscribeTopics={};this._firstConnection=!1}_onConnect(E){if(this.disconnected){this.emit("connect",E);return}this.connackPacket=E,this.messageIdProvider.clear(),this._setupKeepaliveManager(),this.connected=!0;let k=()=>{let I=this.outgoingStore.createStream(),M=()=>{I.destroy(),I=null,this._flushStoreProcessingQueue(),O()},O=()=>{this._storeProcessing=!1,this._packetIdsDuringStoreProcessing={}};this.once("close",M),I.on("error",T=>{O(),this._flushStoreProcessingQueue(),this.removeListener("close",M),this.emit("error",T)});let B=()=>{if(!I)return;let T=I.read(1),W;if(!T){I.once("readable",B);return}if(this._storeProcessing=!0,this._packetIdsDuringStoreProcessing[T.messageId]){B();return}!this.disconnecting&&!this.reconnectTimer?(W=this.outgoing[T.messageId]?this.outgoing[T.messageId].cb:null,this.outgoing[T.messageId]={volatile:!1,cb(F,N){W&&W(F,N),B()}},this._packetIdsDuringStoreProcessing[T.messageId]=!0,this.messageIdProvider.register(T.messageId)?this._sendPacket(T,void 0,void 0,!0):this.log("messageId: %d has already used.",T.messageId)):I.destroy&&I.destroy()};I.on("end",()=>{let T=!0;for(let W in this._packetIdsDuringStoreProcessing)if(!this._packetIdsDuringStoreProcessing[W]){T=!1;break}this.removeListener("close",M),T?(O(),this._invokeAllStoreProcessingQueue(),this.emit("connect",E)):k()}),B()};k()}_invokeStoreProcessingQueue(){if(!this._storeProcessing&&this._storeProcessingQueue.length>0){let E=this._storeProcessingQueue[0];if(E&&E.invoke())return this._storeProcessingQueue.shift(),!0}return!1}_invokeAllStoreProcessingQueue(){for(;this._invokeStoreProcessingQueue(););}_flushStoreProcessingQueue(){for(let E of this._storeProcessingQueue)E.cbStorePut&&E.cbStorePut(new Error("Connection closed")),E.callback&&E.callback(new Error("Connection closed"));this._storeProcessingQueue.splice(0)}_removeOutgoingAndStoreMessage(E,k){delete this.outgoing[E],this.outgoingStore.del({messageId:E},(I,M)=>{k(I,M),this.messageIdProvider.deallocate(E),this._invokeStoreProcessingQueue()})}};u.default=x}),dc=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"__esModule",{value:!0});var e=Sa(),t=class{numberAllocator;lastId;constructor(){this.numberAllocator=new e.NumberAllocator(1,65535)}allocate(){return this.lastId=this.numberAllocator.alloc(),this.lastId}getLastAllocated(){return this.lastId}register(n){return this.numberAllocator.use(n)}deallocate(n){this.numberAllocator.free(n)}clear(){this.numberAllocator.clear()}};u.default=t});function pc(){if(si)return sr;si=!0;let u=2147483647,e=36,t=1,n=26,l=38,r=700,i=72,o=128,s="-",a=/^xn--/,c=/[^\0-\x7F]/,d=/[\x2E\u3002\uFF0E\uFF61]/g,p={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},y=e-t,f=Math.floor,m=String.fromCharCode;function b(O){throw new RangeError(p[O])}function _(O,B){let T=[],W=O.length;for(;W--;)T[W]=B(O[W]);return T}function g(O,B){let T=O.split("@"),W="";T.length>1&&(W=T[0]+"@",O=T[1]),O=O.replace(d,".");let F=O.split("."),N=_(F,B).join(".");return W+N}function S(O){let B=[],T=0,W=O.length;for(;T<W;){let F=O.charCodeAt(T++);if(F>=55296&&F<=56319&&T<W){let N=O.charCodeAt(T++);(N&64512)==56320?B.push(((F&1023)<<10)+(N&1023)+65536):(B.push(F),T--)}else B.push(F)}return B}let x=O=>String.fromCodePoint(...O),v=function(O){return O>=48&&O<58?26+(O-48):O>=65&&O<91?O-65:O>=97&&O<123?O-97:e},E=function(O,B){return O+22+75*(O<26)-((B!=0)<<5)},k=function(O,B,T){let W=0;for(O=T?f(O/r):O>>1,O+=f(O/B);O>y*n>>1;W+=e)O=f(O/y);return f(W+(y+1)*O/(O+l))},I=function(O){let B=[],T=O.length,W=0,F=o,N=i,ae=O.lastIndexOf(s);ae<0&&(ae=0);for(let Y=0;Y<ae;++Y)O.charCodeAt(Y)>=128&&b("not-basic"),B.push(O.charCodeAt(Y));for(let Y=ae>0?ae+1:0;Y<T;){let K=W;for(let D=1,Z=e;;Z+=e){Y>=T&&b("invalid-input");let P=v(O.charCodeAt(Y++));P>=e&&b("invalid-input"),P>f((u-W)/D)&&b("overflow"),W+=P*D;let J=Z<=N?t:Z>=N+n?n:Z-N;if(P<J)break;let be=e-J;D>f(u/be)&&b("overflow"),D*=be}let re=B.length+1;N=k(W-K,re,K==0),f(W/re)>u-F&&b("overflow"),F+=f(W/re),W%=re,B.splice(W++,0,F)}return String.fromCodePoint(...B)},M=function(O){let B=[];O=S(O);let T=O.length,W=o,F=0,N=i;for(let K of O)K<128&&B.push(m(K));let ae=B.length,Y=ae;for(ae&&B.push(s);Y<T;){let K=u;for(let D of O)D>=W&&D<K&&(K=D);let re=Y+1;K-W>f((u-F)/re)&&b("overflow"),F+=(K-W)*re,W=K;for(let D of O)if(D<W&&++F>u&&b("overflow"),D===W){let Z=F;for(let P=e;;P+=e){let J=P<=N?t:P>=N+n?n:P-N;if(Z<J)break;let be=Z-J,te=e-J;B.push(m(E(J+be%te,0))),Z=f(be/te)}B.push(m(E(Z,0))),N=k(F,re,Y===ae),F=0,++Y}++F,++W}return B.join("")};return sr={version:"2.3.1",ucs2:{decode:S,encode:x},decode:I,encode:M,toASCII:function(O){return g(O,function(B){return c.test(B)?"xn--"+M(B):B})},toUnicode:function(O){return g(O,function(B){return a.test(B)?I(B.slice(4).toLowerCase()):B})}},sr}var sr,si,pt,gc=He(()=>{le(),ce(),ue(),sr={},si=!1,pt=pc(),pt.decode,pt.encode,pt.toASCII,pt.toUnicode,pt.ucs2,pt.version});function mc(){return ai||(ai=!0,oi=function(){if(typeof Symbol!="function"||typeof Object.getOwnPropertySymbols!="function")return!1;if(typeof Symbol.iterator=="symbol")return!0;var u={},e=Symbol("test"),t=Object(e);if(typeof e=="string"||Object.prototype.toString.call(e)!=="[object Symbol]"||Object.prototype.toString.call(t)!=="[object Symbol]")return!1;var n=42;u[e]=n;for(e in u)return!1;if(typeof Object.keys=="function"&&Object.keys(u).length!==0||typeof Object.getOwnPropertyNames=="function"&&Object.getOwnPropertyNames(u).length!==0)return!1;var l=Object.getOwnPropertySymbols(u);if(l.length!==1||l[0]!==e||!Object.prototype.propertyIsEnumerable.call(u,e))return!1;if(typeof Object.getOwnPropertyDescriptor=="function"){var r=Object.getOwnPropertyDescriptor(u,e);if(r.value!==n||r.enumerable!==!0)return!1}return!0}),oi}function bc(){return ui||(ui=!0,li=Error),li}function yc(){return hi||(hi=!0,ci=EvalError),ci}function vc(){return di||(di=!0,fi=RangeError),fi}function wc(){return gi||(gi=!0,pi=ReferenceError),pi}function Pa(){return bi||(bi=!0,mi=SyntaxError),mi}function Qt(){return vi||(vi=!0,yi=TypeError),yi}function _c(){return _i||(_i=!0,wi=URIError),wi}function Sc(){if(Si)return or;Si=!0;var u=typeof Symbol<"u"&&Symbol,e=mc();return or=function(){return typeof u!="function"||typeof Symbol!="function"||typeof u("foo")!="symbol"||typeof Symbol("bar")!="symbol"?!1:e()},or}function kc(){if(ki)return ar;ki=!0;var u={__proto__:null,foo:{}},e=Object;return ar=function(){return{__proto__:u}.foo===u.foo&&!(u instanceof e)},ar}function Ec(){if(Ei)return lr;Ei=!0;var u="Function.prototype.bind called on incompatible ",e=Object.prototype.toString,t=Math.max,n="[object Function]",l=function(o,s){for(var a=[],c=0;c<o.length;c+=1)a[c]=o[c];for(var d=0;d<s.length;d+=1)a[d+o.length]=s[d];return a},r=function(o,s){for(var a=[],c=s,d=0;c<o.length;c+=1,d+=1)a[d]=o[c];return a},i=function(o,s){for(var a="",c=0;c<o.length;c+=1)a+=o[c],c+1<o.length&&(a+=s);return a};return lr=function(o){var s=this;if(typeof s!="function"||e.apply(s)!==n)throw new TypeError(u+s);for(var a=r(arguments,1),c,d=function(){if(this instanceof c){var b=s.apply(this,l(a,arguments));return Object(b)===b?b:this}return s.apply(o,l(a,arguments))},p=t(0,s.length-a.length),y=[],f=0;f<p;f++)y[f]="$"+f;if(c=Function("binder","return function ("+i(y,",")+"){ return binder.apply(this,arguments); }")(d),s.prototype){var m=function(){};m.prototype=s.prototype,c.prototype=new m,m.prototype=null}return c},lr}function es(){if(xi)return ur;xi=!0;var u=Ec();return ur=Function.prototype.bind||u,ur}function xc(){if(Ai)return cr;Ai=!0;var u=Function.prototype.call,e=Object.prototype.hasOwnProperty,t=es();return cr=t.call(u,e),cr}function Ut(){if(Ii)return hr;Ii=!0;var u,e=bc(),t=yc(),n=vc(),l=wc(),r=Pa(),i=Qt(),o=_c(),s=Function,a=function(Y){try{return s('"use strict"; return ('+Y+").constructor;")()}catch{}},c=Object.getOwnPropertyDescriptor;if(c)try{c({},"")}catch{c=null}var d=function(){throw new i},p=c?(function(){try{return arguments.callee,d}catch{try{return c(arguments,"callee").get}catch{return d}}})():d,y=Sc()(),f=kc()(),m=Object.getPrototypeOf||(f?function(Y){return Y.__proto__}:null),b={},_=typeof Uint8Array>"u"||!m?u:m(Uint8Array),g={__proto__:null,"%AggregateError%":typeof AggregateError>"u"?u:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?u:ArrayBuffer,"%ArrayIteratorPrototype%":y&&m?m([][Symbol.iterator]()):u,"%AsyncFromSyncIteratorPrototype%":u,"%AsyncFunction%":b,"%AsyncGenerator%":b,"%AsyncGeneratorFunction%":b,"%AsyncIteratorPrototype%":b,"%Atomics%":typeof Atomics>"u"?u:Atomics,"%BigInt%":typeof BigInt>"u"?u:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?u:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?u:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?u:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":e,"%eval%":eval,"%EvalError%":t,"%Float32Array%":typeof Float32Array>"u"?u:Float32Array,"%Float64Array%":typeof Float64Array>"u"?u:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?u:FinalizationRegistry,"%Function%":s,"%GeneratorFunction%":b,"%Int8Array%":typeof Int8Array>"u"?u:Int8Array,"%Int16Array%":typeof Int16Array>"u"?u:Int16Array,"%Int32Array%":typeof Int32Array>"u"?u:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":y&&m?m(m([][Symbol.iterator]())):u,"%JSON%":typeof JSON=="object"?JSON:u,"%Map%":typeof Map>"u"?u:Map,"%MapIteratorPrototype%":typeof Map>"u"||!y||!m?u:m(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":Object,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?u:Promise,"%Proxy%":typeof Proxy>"u"?u:Proxy,"%RangeError%":n,"%ReferenceError%":l,"%Reflect%":typeof Reflect>"u"?u:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?u:Set,"%SetIteratorPrototype%":typeof Set>"u"||!y||!m?u:m(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?u:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":y&&m?m(""[Symbol.iterator]()):u,"%Symbol%":y?Symbol:u,"%SyntaxError%":r,"%ThrowTypeError%":p,"%TypedArray%":_,"%TypeError%":i,"%Uint8Array%":typeof Uint8Array>"u"?u:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?u:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?u:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?u:Uint32Array,"%URIError%":o,"%WeakMap%":typeof WeakMap>"u"?u:WeakMap,"%WeakRef%":typeof WeakRef>"u"?u:WeakRef,"%WeakSet%":typeof WeakSet>"u"?u:WeakSet};if(m)try{null.error}catch(Y){var S=m(m(Y));g["%Error.prototype%"]=S}var x=function Y(K){var re;if(K==="%AsyncFunction%")re=a("async function () {}");else if(K==="%GeneratorFunction%")re=a("function* () {}");else if(K==="%AsyncGeneratorFunction%")re=a("async function* () {}");else if(K==="%AsyncGenerator%"){var D=Y("%AsyncGeneratorFunction%");D&&(re=D.prototype)}else if(K==="%AsyncIteratorPrototype%"){var Z=Y("%AsyncGenerator%");Z&&m&&(re=m(Z.prototype))}return g[K]=re,re},v={__proto__:null,"%ArrayBufferPrototype%":["ArrayBuffer","prototype"],"%ArrayPrototype%":["Array","prototype"],"%ArrayProto_entries%":["Array","prototype","entries"],"%ArrayProto_forEach%":["Array","prototype","forEach"],"%ArrayProto_keys%":["Array","prototype","keys"],"%ArrayProto_values%":["Array","prototype","values"],"%AsyncFunctionPrototype%":["AsyncFunction","prototype"],"%AsyncGenerator%":["AsyncGeneratorFunction","prototype"],"%AsyncGeneratorPrototype%":["AsyncGeneratorFunction","prototype","prototype"],"%BooleanPrototype%":["Boolean","prototype"],"%DataViewPrototype%":["DataView","prototype"],"%DatePrototype%":["Date","prototype"],"%ErrorPrototype%":["Error","prototype"],"%EvalErrorPrototype%":["EvalError","prototype"],"%Float32ArrayPrototype%":["Float32Array","prototype"],"%Float64ArrayPrototype%":["Float64Array","prototype"],"%FunctionPrototype%":["Function","prototype"],"%Generator%":["GeneratorFunction","prototype"],"%GeneratorPrototype%":["GeneratorFunction","prototype","prototype"],"%Int8ArrayPrototype%":["Int8Array","prototype"],"%Int16ArrayPrototype%":["Int16Array","prototype"],"%Int32ArrayPrototype%":["Int32Array","prototype"],"%JSONParse%":["JSON","parse"],"%JSONStringify%":["JSON","stringify"],"%MapPrototype%":["Map","prototype"],"%NumberPrototype%":["Number","prototype"],"%ObjectPrototype%":["Object","prototype"],"%ObjProto_toString%":["Object","prototype","toString"],"%ObjProto_valueOf%":["Object","prototype","valueOf"],"%PromisePrototype%":["Promise","prototype"],"%PromiseProto_then%":["Promise","prototype","then"],"%Promise_all%":["Promise","all"],"%Promise_reject%":["Promise","reject"],"%Promise_resolve%":["Promise","resolve"],"%RangeErrorPrototype%":["RangeError","prototype"],"%ReferenceErrorPrototype%":["ReferenceError","prototype"],"%RegExpPrototype%":["RegExp","prototype"],"%SetPrototype%":["Set","prototype"],"%SharedArrayBufferPrototype%":["SharedArrayBuffer","prototype"],"%StringPrototype%":["String","prototype"],"%SymbolPrototype%":["Symbol","prototype"],"%SyntaxErrorPrototype%":["SyntaxError","prototype"],"%TypedArrayPrototype%":["TypedArray","prototype"],"%TypeErrorPrototype%":["TypeError","prototype"],"%Uint8ArrayPrototype%":["Uint8Array","prototype"],"%Uint8ClampedArrayPrototype%":["Uint8ClampedArray","prototype"],"%Uint16ArrayPrototype%":["Uint16Array","prototype"],"%Uint32ArrayPrototype%":["Uint32Array","prototype"],"%URIErrorPrototype%":["URIError","prototype"],"%WeakMapPrototype%":["WeakMap","prototype"],"%WeakSetPrototype%":["WeakSet","prototype"]},E=es(),k=xc(),I=E.call(Function.call,Array.prototype.concat),M=E.call(Function.apply,Array.prototype.splice),O=E.call(Function.call,String.prototype.replace),B=E.call(Function.call,String.prototype.slice),T=E.call(Function.call,RegExp.prototype.exec),W=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,F=/\\(\\)?/g,N=function(Y){var K=B(Y,0,1),re=B(Y,-1);if(K==="%"&&re!=="%")throw new r("invalid intrinsic syntax, expected closing `%`");if(re==="%"&&K!=="%")throw new r("invalid intrinsic syntax, expected opening `%`");var D=[];return O(Y,W,function(Z,P,J,be){D[D.length]=J?O(be,F,"$1"):P||Z}),D},ae=function(Y,K){var re=Y,D;if(k(v,re)&&(D=v[re],re="%"+D[0]+"%"),k(g,re)){var Z=g[re];if(Z===b&&(Z=x(re)),typeof Z>"u"&&!K)throw new i("intrinsic "+Y+" exists, but is not available. Please file an issue!");return{alias:D,name:re,value:Z}}throw new r("intrinsic "+Y+" does not exist!")};return hr=function(Y,K){if(typeof Y!="string"||Y.length===0)throw new i("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof K!="boolean")throw new i('"allowMissing" argument must be a boolean');if(T(/^%?[^%]*%?$/,Y)===null)throw new r("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var re=N(Y),D=re.length>0?re[0]:"",Z=ae("%"+D+"%",K),P=Z.name,J=Z.value,be=!1,te=Z.alias;te&&(D=te[0],M(re,I([0,1],te)));for(var we=1,V=!0;we<re.length;we+=1){var L=re[we],ne=B(L,0,1),H=B(L,-1);if((ne==='"'||ne==="'"||ne==="`"||H==='"'||H==="'"||H==="`")&&ne!==H)throw new r("property names with quotes must have matching quotes");if((L==="constructor"||!V)&&(be=!0),D+="."+L,P="%"+D+"%",k(g,P))J=g[P];else if(J!=null){if(!(L in J)){if(!K)throw new i("base intrinsic for "+Y+" exists, but the property is not available.");return}if(c&&we+1>=re.length){var G=c(J,L);V=!!G,V&&"get"in G&&!("originalValue"in G.get)?J=G.get:J=J[L]}else V=k(J,L),J=J[L];V&&!be&&(g[P]=J)}}return J},hr}function ts(){if(Ti)return fr;Ti=!0;var u=Ut(),e=u("%Object.defineProperty%",!0)||!1;if(e)try{e({},"a",{value:1})}catch{e=!1}return fr=e,fr}function Ma(){if(Ci)return dr;Ci=!0;var u=Ut(),e=u("%Object.getOwnPropertyDescriptor%",!0);if(e)try{e([],"length")}catch{e=null}return dr=e,dr}function Ac(){if(Oi)return pr;Oi=!0;var u=ts(),e=Pa(),t=Qt(),n=Ma();return pr=function(l,r,i){if(!l||typeof l!="object"&&typeof l!="function")throw new t("`obj` must be an object or a function`");if(typeof r!="string"&&typeof r!="symbol")throw new t("`property` must be a string or a symbol`");if(arguments.length>3&&typeof arguments[3]!="boolean"&&arguments[3]!==null)throw new t("`nonEnumerable`, if provided, must be a boolean or null");if(arguments.length>4&&typeof arguments[4]!="boolean"&&arguments[4]!==null)throw new t("`nonWritable`, if provided, must be a boolean or null");if(arguments.length>5&&typeof arguments[5]!="boolean"&&arguments[5]!==null)throw new t("`nonConfigurable`, if provided, must be a boolean or null");if(arguments.length>6&&typeof arguments[6]!="boolean")throw new t("`loose`, if provided, must be a boolean");var o=arguments.length>3?arguments[3]:null,s=arguments.length>4?arguments[4]:null,a=arguments.length>5?arguments[5]:null,c=arguments.length>6?arguments[6]:!1,d=!!n&&n(l,r);if(u)u(l,r,{configurable:a===null&&d?d.configurable:!a,enumerable:o===null&&d?d.enumerable:!o,value:i,writable:s===null&&d?d.writable:!s});else if(c||!o&&!s&&!a)l[r]=i;else throw new e("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.")},pr}function Ic(){if(Pi)return gr;Pi=!0;var u=ts(),e=function(){return!!u};return e.hasArrayLengthDefineBug=function(){if(!u)return null;try{return u([],"length",{value:1}).length!==1}catch{return!0}},gr=e,gr}function Tc(){if(Mi)return mr;Mi=!0;var u=Ut(),e=Ac(),t=Ic()(),n=Ma(),l=Qt(),r=u("%Math.floor%");return mr=function(i,o){if(typeof i!="function")throw new l("`fn` is not a function");if(typeof o!="number"||o<0||o>4294967295||r(o)!==o)throw new l("`length` must be a positive 32-bit integer");var s=arguments.length>2&&!!arguments[2],a=!0,c=!0;if("length"in i&&n){var d=n(i,"length");d&&!d.configurable&&(a=!1),d&&!d.writable&&(c=!1)}return(a||c||!s)&&(t?e(i,"length",o,!0,!0):e(i,"length",o)),i},mr}function Cc(){if(Ri)return Pt;Ri=!0;var u=es(),e=Ut(),t=Tc(),n=Qt(),l=e("%Function.prototype.apply%"),r=e("%Function.prototype.call%"),i=e("%Reflect.apply%",!0)||u.call(r,l),o=ts(),s=e("%Math.max%");Pt=function(c){if(typeof c!="function")throw new n("a function is required");var d=i(u,r,arguments);return t(d,1+s(0,c.length-(arguments.length-1)),!0)};var a=function(){return i(u,l,arguments)};return o?o(Pt,"apply",{value:a}):Pt.apply=a,Pt}function Oc(){if(ji)return br;ji=!0;var u=Ut(),e=Cc(),t=e(u("String.prototype.indexOf"));return br=function(n,l){var r=u(n,!!l);return typeof r=="function"&&t(n,".prototype.")>-1?e(r):r},br}var oi,ai,li,ui,ci,hi,fi,di,pi,gi,mi,bi,yi,vi,wi,_i,or,Si,ar,ki,lr,Ei,ur,xi,cr,Ai,hr,Ii,fr,Ti,dr,Ci,pr,Oi,gr,Pi,mr,Mi,Pt,Ri,br,ji,Pc=He(()=>{le(),ce(),ue(),oi={},ai=!1,li={},ui=!1,ci={},hi=!1,fi={},di=!1,pi={},gi=!1,mi={},bi=!1,yi={},vi=!1,wi={},_i=!1,or={},Si=!1,ar={},ki=!1,lr={},Ei=!1,ur={},xi=!1,cr={},Ai=!1,hr={},Ii=!1,fr={},Ti=!1,dr={},Ci=!1,pr={},Oi=!1,gr={},Pi=!1,mr={},Mi=!1,Pt={},Ri=!1,br={},ji=!1});function rs(u){throw new Error("Node.js process "+u+" is not supported by JSPM core outside of Node.js")}function Mc(){!kt||!_t||(kt=!1,_t.length?et=_t.concat(et):Vt=-1,et.length&&Ra())}function Ra(){if(!kt){var u=setTimeout(Mc,0);kt=!0;for(var e=et.length;e;){for(_t=et,et=[];++Vt<e;)_t&&_t[Vt].run();Vt=-1,e=et.length}_t=null,kt=!1,clearTimeout(u)}}function Rc(u){var e=new Array(arguments.length-1);if(arguments.length>1)for(var t=1;t<arguments.length;t++)e[t-1]=arguments[t];et.push(new ja(u,e)),et.length===1&&!kt&&setTimeout(Ra,0)}function ja(u,e){this.fun=u,this.array=e}function Fe(){}function jc(u){rs("_linkedBinding")}function Lc(u){rs("dlopen")}function Nc(){return[]}function Uc(){return[]}function Bc(u,e){if(!u)throw new Error(e||"assertion error")}function Fc(){return!1}function Dc(){return st.now()/1e3}function Fr(u){var e=Math.floor((Date.now()-st.now())*.001),t=st.now()*.001,n=Math.floor(t)+e,l=Math.floor(t%1*1e9);return u&&(n=n-u[0],l=l-u[1],l<0&&(n--,l+=yr)),[n,l]}function ft(){return ns}function $c(u){return[]}var et,kt,_t,Vt,fs,ds,ps,gs,ms,bs,ys,vs,ws,_s,Ss,ks,Es,xs,As,Is,Ts,Cs,Os,Ps,Ms,Zt,Rs,js,Ls,Ns,Us,Bs,Fs,Ds,$s,Ws,qs,Hs,zs,Ks,Vs,Gs,Ys,Qs,Js,Xs,Zs,eo,to,ro,no,st,Dr,yr,io,so,oo,ao,lo,uo,co,ho,fo,po,go,ns,La=He(()=>{le(),ce(),ue(),et=[],kt=!1,Vt=-1,ja.prototype.run=function(){this.fun.apply(null,this.array)},fs="browser",ds="x64",ps="browser",gs={PATH:"/usr/bin",LANG:navigator.language+".UTF-8",PWD:"/",HOME:"/home",TMP:"/tmp"},ms=["/usr/bin/node"],bs=[],ys="v16.8.0",vs={},ws=function(u,e){console.warn((e?e+": ":"")+u)},_s=function(u){rs("binding")},Ss=function(u){return 0},ks=function(){return"/"},Es=function(u){},xs={name:"node",sourceUrl:"",headersUrl:"",libUrl:""},As=Fe,Is=[],Ts={},Cs=!1,Os={},Ps=Fe,Ms=Fe,Zt=function(){return{}},Rs=Zt,js=Zt,Ls=Fe,Ns=Fe,Us=Fe,Bs={},Fs={inspector:!1,debug:!1,uv:!1,ipv6:!1,tls_alpn:!1,tls_sni:!1,tls_ocsp:!1,tls:!1,cached_builtins:!0},Ds=Fe,$s=Fe,Ws=Fe,qs=Fe,Hs=Fe,zs=Fe,Ks=Fe,Vs=void 0,Gs=void 0,Ys=void 0,Qs=Fe,Js=2,Xs=1,Zs="/bin/usr/node",eo=9229,to="node",ro=[],no=Fe,st={now:typeof performance<"u"?performance.now.bind(performance):void 0,timing:typeof performance<"u"?performance.timing:void 0},st.now===void 0&&(Dr=Date.now(),st.timing&&st.timing.navigationStart&&(Dr=st.timing.navigationStart),st.now=()=>Date.now()-Dr),yr=1e9,Fr.bigint=function(u){var e=Fr(u);return typeof BigInt>"u"?e[0]*yr+e[1]:BigInt(e[0]*yr)+BigInt(e[1])},io=10,so={},oo=0,ao=ft,lo=ft,uo=ft,co=ft,ho=ft,fo=Fe,po=ft,go=ft,ns={version:ys,versions:vs,arch:ds,platform:ps,release:xs,_rawDebug:As,moduleLoadList:Is,binding:_s,_linkedBinding:jc,_events:so,_eventsCount:oo,_maxListeners:io,on:ft,addListener:ao,once:lo,off:uo,removeListener:co,removeAllListeners:ho,emit:fo,prependListener:po,prependOnceListener:go,listeners:$c,domain:Ts,_exiting:Cs,config:Os,dlopen:Lc,uptime:Dc,_getActiveRequests:Nc,_getActiveHandles:Uc,reallyExit:Ps,_kill:Ms,cpuUsage:Zt,resourceUsage:Rs,memoryUsage:js,kill:Ls,exit:Ns,openStdin:Us,allowedNodeEnvironmentFlags:Bs,assert:Bc,features:Fs,_fatalExceptions:Ds,setUncaughtExceptionCaptureCallback:$s,hasUncaughtExceptionCaptureCallback:Fc,emitWarning:ws,nextTick:Rc,_tickCallback:Ws,_debugProcess:qs,_debugEnd:Hs,_startProfilerIdleNotifier:zs,_stopProfilerIdleNotifier:Ks,stdout:Vs,stdin:Ys,stderr:Gs,abort:Qs,umask:Ss,chdir:Es,cwd:ks,env:gs,title:fs,argv:ms,execArgv:bs,pid:Js,ppid:Xs,execPath:Zs,debugPort:eo,hrtime:Fr,argv0:to,_preload_modules:ro,setSourceMapsEnabled:no}});function Wc(){if(Li)return vr;Li=!0;var u=ns;function e(r){if(typeof r!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(r))}function t(r,i){for(var o="",s=0,a=-1,c=0,d,p=0;p<=r.length;++p){if(p<r.length)d=r.charCodeAt(p);else{if(d===47)break;d=47}if(d===47){if(!(a===p-1||c===1))if(a!==p-1&&c===2){if(o.length<2||s!==2||o.charCodeAt(o.length-1)!==46||o.charCodeAt(o.length-2)!==46){if(o.length>2){var y=o.lastIndexOf("/");if(y!==o.length-1){y===-1?(o="",s=0):(o=o.slice(0,y),s=o.length-1-o.lastIndexOf("/")),a=p,c=0;continue}}else if(o.length===2||o.length===1){o="",s=0,a=p,c=0;continue}}i&&(o.length>0?o+="/..":o="..",s=2)}else o.length>0?o+="/"+r.slice(a+1,p):o=r.slice(a+1,p),s=p-a-1;a=p,c=0}else d===46&&c!==-1?++c:c=-1}return o}function n(r,i){var o=i.dir||i.root,s=i.base||(i.name||"")+(i.ext||"");return o?o===i.root?o+s:o+r+s:s}var l={resolve:function(){for(var r="",i=!1,o,s=arguments.length-1;s>=-1&&!i;s--){var a;s>=0?a=arguments[s]:(o===void 0&&(o=u.cwd()),a=o),e(a),a.length!==0&&(r=a+"/"+r,i=a.charCodeAt(0)===47)}return r=t(r,!i),i?r.length>0?"/"+r:"/":r.length>0?r:"."},normalize:function(r){if(e(r),r.length===0)return".";var i=r.charCodeAt(0)===47,o=r.charCodeAt(r.length-1)===47;return r=t(r,!i),r.length===0&&!i&&(r="."),r.length>0&&o&&(r+="/"),i?"/"+r:r},isAbsolute:function(r){return e(r),r.length>0&&r.charCodeAt(0)===47},join:function(){if(arguments.length===0)return".";for(var r,i=0;i<arguments.length;++i){var o=arguments[i];e(o),o.length>0&&(r===void 0?r=o:r+="/"+o)}return r===void 0?".":l.normalize(r)},relative:function(r,i){if(e(r),e(i),r===i||(r=l.resolve(r),i=l.resolve(i),r===i))return"";for(var o=1;o<r.length&&r.charCodeAt(o)===47;++o);for(var s=r.length,a=s-o,c=1;c<i.length&&i.charCodeAt(c)===47;++c);for(var d=i.length,p=d-c,y=a<p?a:p,f=-1,m=0;m<=y;++m){if(m===y){if(p>y){if(i.charCodeAt(c+m)===47)return i.slice(c+m+1);if(m===0)return i.slice(c+m)}else a>y&&(r.charCodeAt(o+m)===47?f=m:m===0&&(f=0));break}var b=r.charCodeAt(o+m),_=i.charCodeAt(c+m);if(b!==_)break;b===47&&(f=m)}var g="";for(m=o+f+1;m<=s;++m)(m===s||r.charCodeAt(m)===47)&&(g.length===0?g+="..":g+="/..");return g.length>0?g+i.slice(c+f):(c+=f,i.charCodeAt(c)===47&&++c,i.slice(c))},_makeLong:function(r){return r},dirname:function(r){if(e(r),r.length===0)return".";for(var i=r.charCodeAt(0),o=i===47,s=-1,a=!0,c=r.length-1;c>=1;--c)if(i=r.charCodeAt(c),i===47){if(!a){s=c;break}}else a=!1;return s===-1?o?"/":".":o&&s===1?"//":r.slice(0,s)},basename:function(r,i){if(i!==void 0&&typeof i!="string")throw new TypeError('"ext" argument must be a string');e(r);var o=0,s=-1,a=!0,c;if(i!==void 0&&i.length>0&&i.length<=r.length){if(i.length===r.length&&i===r)return"";var d=i.length-1,p=-1;for(c=r.length-1;c>=0;--c){var y=r.charCodeAt(c);if(y===47){if(!a){o=c+1;break}}else p===-1&&(a=!1,p=c+1),d>=0&&(y===i.charCodeAt(d)?--d===-1&&(s=c):(d=-1,s=p))}return o===s?s=p:s===-1&&(s=r.length),r.slice(o,s)}else{for(c=r.length-1;c>=0;--c)if(r.charCodeAt(c)===47){if(!a){o=c+1;break}}else s===-1&&(a=!1,s=c+1);return s===-1?"":r.slice(o,s)}},extname:function(r){e(r);for(var i=-1,o=0,s=-1,a=!0,c=0,d=r.length-1;d>=0;--d){var p=r.charCodeAt(d);if(p===47){if(!a){o=d+1;break}continue}s===-1&&(a=!1,s=d+1),p===46?i===-1?i=d:c!==1&&(c=1):i!==-1&&(c=-1)}return i===-1||s===-1||c===0||c===1&&i===s-1&&i===o+1?"":r.slice(i,s)},format:function(r){if(r===null||typeof r!="object")throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof r);return n("/",r)},parse:function(r){e(r);var i={root:"",dir:"",base:"",ext:"",name:""};if(r.length===0)return i;var o=r.charCodeAt(0),s=o===47,a;s?(i.root="/",a=1):a=0;for(var c=-1,d=0,p=-1,y=!0,f=r.length-1,m=0;f>=a;--f){if(o=r.charCodeAt(f),o===47){if(!y){d=f+1;break}continue}p===-1&&(y=!1,p=f+1),o===46?c===-1?c=f:m!==1&&(m=1):c!==-1&&(m=-1)}return c===-1||p===-1||m===0||m===1&&c===p-1&&c===d+1?p!==-1&&(d===0&&s?i.base=i.name=r.slice(1,p):i.base=i.name=r.slice(d,p)):(d===0&&s?(i.name=r.slice(1,c),i.base=r.slice(1,p)):(i.name=r.slice(d,c),i.base=r.slice(d,p)),i.ext=r.slice(c,p)),d>0?i.dir=r.slice(0,d-1):s&&(i.dir="/"),i},sep:"/",delimiter:":",win32:null,posix:null};return l.posix=l,vr=l,vr}var vr,Li,Ni,qc=He(()=>{le(),ce(),ue(),La(),vr={},Li=!1,Ni=Wc()}),Na={};jt(Na,{URL:()=>Ka,Url:()=>$a,default:()=>De,fileURLToPath:()=>Ba,format:()=>Wa,parse:()=>za,pathToFileURL:()=>Fa,resolve:()=>qa,resolveObject:()=>Ha});function Hc(){if(Ui)return wr;Ui=!0;var u=typeof Map=="function"&&Map.prototype,e=Object.getOwnPropertyDescriptor&&u?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,t=u&&e&&typeof e.get=="function"?e.get:null,n=u&&Map.prototype.forEach,l=typeof Set=="function"&&Set.prototype,r=Object.getOwnPropertyDescriptor&&l?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,i=l&&r&&typeof r.get=="function"?r.get:null,o=l&&Set.prototype.forEach,s=typeof WeakMap=="function"&&WeakMap.prototype,a=s?WeakMap.prototype.has:null,c=typeof WeakSet=="function"&&WeakSet.prototype,d=c?WeakSet.prototype.has:null,p=typeof WeakRef=="function"&&WeakRef.prototype,y=p?WeakRef.prototype.deref:null,f=Boolean.prototype.valueOf,m=Object.prototype.toString,b=Function.prototype.toString,_=String.prototype.match,g=String.prototype.slice,S=String.prototype.replace,x=String.prototype.toUpperCase,v=String.prototype.toLowerCase,E=RegExp.prototype.test,k=Array.prototype.concat,I=Array.prototype.join,M=Array.prototype.slice,O=Math.floor,B=typeof BigInt=="function"?BigInt.prototype.valueOf:null,T=Object.getOwnPropertySymbols,W=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,F=typeof Symbol=="function"&&typeof Symbol.iterator=="object",N=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===F||!0)?Symbol.toStringTag:null,ae=Object.prototype.propertyIsEnumerable,Y=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(z){return z.__proto__}:null);function K(z,ie){if(z===1/0||z===-1/0||z!==z||z&&z>-1e3&&z<1e3||E.call(/e/,ie))return ie;var xe=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof z=="number"){var Ae=z<0?-O(-z):O(z);if(Ae!==z){var Ie=String(Ae),Ce=g.call(ie,Ie.length+1);return S.call(Ie,xe,"$&_")+"."+S.call(S.call(Ce,/([0-9]{3})/g,"$&_"),/_$/,"")}}return S.call(ie,xe,"$&_")}var re=Da,D=re.custom,Z=G(D)?D:null;wr=function z(ie,xe,Ae,Ie){var Ce=xe||{};if(se(Ce,"quoteStyle")&&Ce.quoteStyle!=="single"&&Ce.quoteStyle!=="double")throw new TypeError('option "quoteStyle" must be "single" or "double"');if(se(Ce,"maxStringLength")&&(typeof Ce.maxStringLength=="number"?Ce.maxStringLength<0&&Ce.maxStringLength!==1/0:Ce.maxStringLength!==null))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var Ve=se(Ce,"customInspect")?Ce.customInspect:!0;if(typeof Ve!="boolean"&&Ve!=="symbol")throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(se(Ce,"indent")&&Ce.indent!==null&&Ce.indent!==" "&&!(parseInt(Ce.indent,10)===Ce.indent&&Ce.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(se(Ce,"numericSeparator")&&typeof Ce.numericSeparator!="boolean")throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var Ge=Ce.numericSeparator;if(typeof ie>"u")return"undefined";if(ie===null)return"null";if(typeof ie=="boolean")return ie?"true":"false";if(typeof ie=="string")return oe(ie,Ce);if(typeof ie=="number"){if(ie===0)return 1/0/ie>0?"0":"-0";var Ue=String(ie);return Ge?K(ie,Ue):Ue}if(typeof ie=="bigint"){var Ye=String(ie)+"n";return Ge?K(ie,Ye):Ye}var It=typeof Ce.depth>"u"?5:Ce.depth;if(typeof Ae>"u"&&(Ae=0),Ae>=It&&It>0&&typeof ie=="object")return be(ie)?"[Array]":"[Object]";var Qe=X(Ce,Ae);if(typeof Ie>"u")Ie=[];else if(ee(Ie,ie)>=0)return"[Circular]";function ze(Je,ht,vt){if(ht&&(Ie=M.call(Ie),Ie.push(ht)),vt){var Xe={depth:Ce.depth};return se(Ce,"quoteStyle")&&(Xe.quoteStyle=Ce.quoteStyle),z(Je,Xe,Ae+1,Ie)}return z(Je,Ce,Ae+1,Ie)}if(typeof ie=="function"&&!we(ie)){var Jt=$(ie),Tt=Se(ie,ze);return"[Function"+(Jt?": "+Jt:" (anonymous)")+"]"+(Tt.length>0?" { "+I.call(Tt,", ")+" }":"")}if(G(ie)){var Bt=F?S.call(String(ie),/^(Symbol\(.*\))_[^)]*$/,"$1"):W.call(ie);return typeof ie=="object"&&!F?h(Bt):Bt}if(ve(ie)){for(var C="<"+v.call(String(ie.nodeName)),j=ie.attributes||[],_e=0;_e<j.length;_e++)C+=" "+j[_e].name+"="+P(J(j[_e].value),"double",Ce);return C+=">",ie.childNodes&&ie.childNodes.length&&(C+="..."),C+="</"+v.call(String(ie.nodeName))+">",C}if(be(ie)){if(ie.length===0)return"[]";var ke=Se(ie,ze);return Qe&&!U(ke)?"["+he(ke,Qe)+"]":"[ "+I.call(ke,", ")+" ]"}if(V(ie)){var Ee=Se(ie,ze);return!("cause"in Error.prototype)&&"cause"in ie&&!ae.call(ie,"cause")?"{ ["+String(ie)+"] "+I.call(k.call("[cause]: "+ze(ie.cause),Ee),", ")+" }":Ee.length===0?"["+String(ie)+"]":"{ ["+String(ie)+"] "+I.call(Ee,", ")+" }"}if(typeof ie=="object"&&Ve){if(Z&&typeof ie[Z]=="function"&&re)return re(ie,{depth:It-Ae});if(Ve!=="symbol"&&typeof ie.inspect=="function")return ie.inspect()}if(fe(ie)){var je=[];return n&&n.call(ie,function(Je,ht){je.push(ze(ht,ie,!0)+" => "+ze(Je,ie))}),A("Map",t.call(ie),je,Qe)}if(q(ie)){var $e=[];return o&&o.call(ie,function(Je){$e.push(ze(Je,ie))}),A("Set",i.call(ie),$e,Qe)}if(de(ie))return w("WeakMap");if(ge(ie))return w("WeakSet");if(ye(ie))return w("WeakRef");if(ne(ie))return h(ze(Number(ie)));if(Q(ie))return h(ze(B.call(ie)));if(H(ie))return h(f.call(ie));if(L(ie))return h(ze(String(ie)));if(typeof window<"u"&&ie===window)return"{ [object Window] }";if(typeof globalThis<"u"&&ie===globalThis||typeof _r<"u"&&ie===_r)return"{ [object globalThis] }";if(!te(ie)&&!we(ie)){var Ke=Se(ie,ze),Ft=Y?Y(ie)===Object.prototype:ie instanceof Object||ie.constructor===Object,Dt=ie instanceof Object?"":"null prototype",$t=!Ft&&N&&Object(ie)===ie&&N in ie?g.call(R(ie),8,-1):Dt?"Object":"",Xt=Ft||typeof ie.constructor!="function"?"":ie.constructor.name?ie.constructor.name+" ":"",yt=Xt+($t||Dt?"["+I.call(k.call([],$t||[],Dt||[]),": ")+"] ":"");return Ke.length===0?yt+"{}":Qe?yt+"{"+he(Ke,Qe)+"}":yt+"{ "+I.call(Ke,", ")+" }"}return String(ie)};function P(z,ie,xe){var Ae=(xe.quoteStyle||ie)==="double"?'"':"'";return Ae+z+Ae}function J(z){return S.call(String(z),/"/g,""")}function be(z){return R(z)==="[object Array]"&&(!N||!(typeof z=="object"&&N in z))}function te(z){return R(z)==="[object Date]"&&(!N||!(typeof z=="object"&&N in z))}function we(z){return R(z)==="[object RegExp]"&&(!N||!(typeof z=="object"&&N in z))}function V(z){return R(z)==="[object Error]"&&(!N||!(typeof z=="object"&&N in z))}function L(z){return R(z)==="[object String]"&&(!N||!(typeof z=="object"&&N in z))}function ne(z){return R(z)==="[object Number]"&&(!N||!(typeof z=="object"&&N in z))}function H(z){return R(z)==="[object Boolean]"&&(!N||!(typeof z=="object"&&N in z))}function G(z){if(F)return z&&typeof z=="object"&&z instanceof Symbol;if(typeof z=="symbol")return!0;if(!z||typeof z!="object"||!W)return!1;try{return W.call(z),!0}catch{}return!1}function Q(z){if(!z||typeof z!="object"||!B)return!1;try{return B.call(z),!0}catch{}return!1}var me=Object.prototype.hasOwnProperty||function(z){return z in(this||_r)};function se(z,ie){return me.call(z,ie)}function R(z){return m.call(z)}function $(z){if(z.name)return z.name;var ie=_.call(b.call(z),/^function\s*([\w$]+)/);return ie?ie[1]:null}function ee(z,ie){if(z.indexOf)return z.indexOf(ie);for(var xe=0,Ae=z.length;xe<Ae;xe++)if(z[xe]===ie)return xe;return-1}function fe(z){if(!t||!z||typeof z!="object")return!1;try{t.call(z);try{i.call(z)}catch{return!0}return z instanceof Map}catch{}return!1}function de(z){if(!a||!z||typeof z!="object")return!1;try{a.call(z,a);try{d.call(z,d)}catch{return!0}return z instanceof WeakMap}catch{}return!1}function ye(z){if(!y||!z||typeof z!="object")return!1;try{return y.call(z),!0}catch{}return!1}function q(z){if(!i||!z||typeof z!="object")return!1;try{i.call(z);try{t.call(z)}catch{return!0}return z instanceof Set}catch{}return!1}function ge(z){if(!d||!z||typeof z!="object")return!1;try{d.call(z,d);try{a.call(z,a)}catch{return!0}return z instanceof WeakSet}catch{}return!1}function ve(z){return!z||typeof z!="object"?!1:typeof HTMLElement<"u"&&z instanceof HTMLElement?!0:typeof z.nodeName=="string"&&typeof z.getAttribute=="function"}function oe(z,ie){if(z.length>ie.maxStringLength){var xe=z.length-ie.maxStringLength,Ae="... "+xe+" more character"+(xe>1?"s":"");return oe(g.call(z,0,ie.maxStringLength),ie)+Ae}var Ie=S.call(S.call(z,/(['\\])/g,"\\$1"),/[\x00-\x1f]/g,Te);return P(Ie,"single",ie)}function Te(z){var ie=z.charCodeAt(0),xe={8:"b",9:"t",10:"n",12:"f",13:"r"}[ie];return xe?"\\"+xe:"\\x"+(ie<16?"0":"")+x.call(ie.toString(16))}function h(z){return"Object("+z+")"}function w(z){return z+" { ? }"}function A(z,ie,xe,Ae){var Ie=Ae?he(xe,Ae):I.call(xe,", ");return z+" ("+ie+") {"+Ie+"}"}function U(z){for(var ie=0;ie<z.length;ie++)if(ee(z[ie],`
|
|
4
|
-
`)>=0)return!1;return!0}function X(z,ie){var xe;if(z.indent===" ")xe=" ";else if(typeof z.indent=="number"&&z.indent>0)xe=I.call(Array(z.indent+1)," ");else return null;return{base:xe,prev:I.call(Array(ie+1),xe)}}function he(z,ie){if(z.length===0)return"";var xe=`
|
|
5
|
-
`+ie.prev+ie.base;return xe+I.call(z,","+xe)+`
|
|
6
|
-
`+ie.prev}function Se(z,ie){var xe=be(z),Ae=[];if(xe){Ae.length=z.length;for(var Ie=0;Ie<z.length;Ie++)Ae[Ie]=se(z,Ie)?ie(z[Ie],z):""}var Ce=typeof T=="function"?T(z):[],Ve;if(F){Ve={};for(var Ge=0;Ge<Ce.length;Ge++)Ve["$"+Ce[Ge]]=Ce[Ge]}for(var Ue in z)se(z,Ue)&&(xe&&String(Number(Ue))===Ue&&Ue<z.length||F&&Ve["$"+Ue]instanceof Symbol||(E.call(/[^\w$]/,Ue)?Ae.push(ie(Ue,z)+": "+ie(z[Ue],z)):Ae.push(Ue+": "+ie(z[Ue],z))));if(typeof T=="function")for(var Ye=0;Ye<Ce.length;Ye++)ae.call(z,Ce[Ye])&&Ae.push("["+ie(Ce[Ye])+"]: "+ie(z[Ce[Ye]],z));return Ae}return wr}function zc(){if(Bi)return Sr;Bi=!0;var u=Ut(),e=Oc(),t=Hc(),n=Qt(),l=u("%WeakMap%",!0),r=u("%Map%",!0),i=e("WeakMap.prototype.get",!0),o=e("WeakMap.prototype.set",!0),s=e("WeakMap.prototype.has",!0),a=e("Map.prototype.get",!0),c=e("Map.prototype.set",!0),d=e("Map.prototype.has",!0),p=function(b,_){for(var g=b,S;(S=g.next)!==null;g=S)if(S.key===_)return g.next=S.next,S.next=b.next,b.next=S,S},y=function(b,_){var g=p(b,_);return g&&g.value},f=function(b,_,g){var S=p(b,_);S?S.value=g:b.next={key:_,next:b.next,value:g}},m=function(b,_){return!!p(b,_)};return Sr=function(){var b,_,g,S={assert:function(x){if(!S.has(x))throw new n("Side channel does not contain "+t(x))},get:function(x){if(l&&x&&(typeof x=="object"||typeof x=="function")){if(b)return i(b,x)}else if(r){if(_)return a(_,x)}else if(g)return y(g,x)},has:function(x){if(l&&x&&(typeof x=="object"||typeof x=="function")){if(b)return s(b,x)}else if(r){if(_)return d(_,x)}else if(g)return m(g,x);return!1},set:function(x,v){l&&x&&(typeof x=="object"||typeof x=="function")?(b||(b=new l),o(b,x,v)):r?(_||(_=new r),c(_,x,v)):(g||(g={key:{},next:null}),f(g,x,v))}};return S},Sr}function is(){if(Fi)return kr;Fi=!0;var u=String.prototype.replace,e=/%20/g,t={RFC1738:"RFC1738",RFC3986:"RFC3986"};return kr={default:t.RFC3986,formatters:{RFC1738:function(n){return u.call(n,e,"+")},RFC3986:function(n){return String(n)}},RFC1738:t.RFC1738,RFC3986:t.RFC3986},kr}function Ua(){if(Di)return Er;Di=!0;var u=is(),e=Object.prototype.hasOwnProperty,t=Array.isArray,n=(function(){for(var b=[],_=0;_<256;++_)b.push("%"+((_<16?"0":"")+_.toString(16)).toUpperCase());return b})(),l=function(b){for(;b.length>1;){var _=b.pop(),g=_.obj[_.prop];if(t(g)){for(var S=[],x=0;x<g.length;++x)typeof g[x]<"u"&&S.push(g[x]);_.obj[_.prop]=S}}},r=function(b,_){for(var g=_&&_.plainObjects?Object.create(null):{},S=0;S<b.length;++S)typeof b[S]<"u"&&(g[S]=b[S]);return g},i=function b(_,g,S){if(!g)return _;if(typeof g!="object"){if(t(_))_.push(g);else if(_&&typeof _=="object")(S&&(S.plainObjects||S.allowPrototypes)||!e.call(Object.prototype,g))&&(_[g]=!0);else return[_,g];return _}if(!_||typeof _!="object")return[_].concat(g);var x=_;return t(_)&&!t(g)&&(x=r(_,S)),t(_)&&t(g)?(g.forEach(function(v,E){if(e.call(_,E)){var k=_[E];k&&typeof k=="object"&&v&&typeof v=="object"?_[E]=b(k,v,S):_.push(v)}else _[E]=v}),_):Object.keys(g).reduce(function(v,E){var k=g[E];return e.call(v,E)?v[E]=b(v[E],k,S):v[E]=k,v},x)},o=function(b,_){return Object.keys(_).reduce(function(g,S){return g[S]=_[S],g},b)},s=function(b,_,g){var S=b.replace(/\+/g," ");if(g==="iso-8859-1")return S.replace(/%[0-9a-f]{2}/gi,unescape);try{return decodeURIComponent(S)}catch{return S}},a=1024,c=function(b,_,g,S,x){if(b.length===0)return b;var v=b;if(typeof b=="symbol"?v=Symbol.prototype.toString.call(b):typeof b!="string"&&(v=String(b)),g==="iso-8859-1")return escape(v).replace(/%u[0-9a-f]{4}/gi,function(T){return"%26%23"+parseInt(T.slice(2),16)+"%3B"});for(var E="",k=0;k<v.length;k+=a){for(var I=v.length>=a?v.slice(k,k+a):v,M=[],O=0;O<I.length;++O){var B=I.charCodeAt(O);if(B===45||B===46||B===95||B===126||B>=48&&B<=57||B>=65&&B<=90||B>=97&&B<=122||x===u.RFC1738&&(B===40||B===41)){M[M.length]=I.charAt(O);continue}if(B<128){M[M.length]=n[B];continue}if(B<2048){M[M.length]=n[192|B>>6]+n[128|B&63];continue}if(B<55296||B>=57344){M[M.length]=n[224|B>>12]+n[128|B>>6&63]+n[128|B&63];continue}O+=1,B=65536+((B&1023)<<10|I.charCodeAt(O)&1023),M[M.length]=n[240|B>>18]+n[128|B>>12&63]+n[128|B>>6&63]+n[128|B&63]}E+=M.join("")}return E},d=function(b){for(var _=[{obj:{o:b},prop:"o"}],g=[],S=0;S<_.length;++S)for(var x=_[S],v=x.obj[x.prop],E=Object.keys(v),k=0;k<E.length;++k){var I=E[k],M=v[I];typeof M=="object"&&M!==null&&g.indexOf(M)===-1&&(_.push({obj:v,prop:I}),g.push(M))}return l(_),b},p=function(b){return Object.prototype.toString.call(b)==="[object RegExp]"},y=function(b){return!b||typeof b!="object"?!1:!!(b.constructor&&b.constructor.isBuffer&&b.constructor.isBuffer(b))},f=function(b,_){return[].concat(b,_)},m=function(b,_){if(t(b)){for(var g=[],S=0;S<b.length;S+=1)g.push(_(b[S]));return g}return _(b)};return Er={arrayToObject:r,assign:o,combine:f,compact:d,decode:s,encode:c,isBuffer:y,isRegExp:p,maybeMap:m,merge:i},Er}function Kc(){if($i)return xr;$i=!0;var u=zc(),e=Ua(),t=is(),n=Object.prototype.hasOwnProperty,l={brackets:function(m){return m+"[]"},comma:"comma",indices:function(m,b){return m+"["+b+"]"},repeat:function(m){return m}},r=Array.isArray,i=Array.prototype.push,o=function(m,b){i.apply(m,r(b)?b:[b])},s=Date.prototype.toISOString,a=t.default,c={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:e.encode,encodeValuesOnly:!1,format:a,formatter:t.formatters[a],indices:!1,serializeDate:function(m){return s.call(m)},skipNulls:!1,strictNullHandling:!1},d=function(m){return typeof m=="string"||typeof m=="number"||typeof m=="boolean"||typeof m=="symbol"||typeof m=="bigint"},p={},y=function m(b,_,g,S,x,v,E,k,I,M,O,B,T,W,F,N,ae,Y){for(var K=b,re=Y,D=0,Z=!1;(re=re.get(p))!==void 0&&!Z;){var P=re.get(b);if(D+=1,typeof P<"u"){if(P===D)throw new RangeError("Cyclic object value");Z=!0}typeof re.get(p)>"u"&&(D=0)}if(typeof M=="function"?K=M(_,K):K instanceof Date?K=T(K):g==="comma"&&r(K)&&(K=e.maybeMap(K,function(R){return R instanceof Date?T(R):R})),K===null){if(v)return I&&!N?I(_,c.encoder,ae,"key",W):_;K=""}if(d(K)||e.isBuffer(K)){if(I){var J=N?_:I(_,c.encoder,ae,"key",W);return[F(J)+"="+F(I(K,c.encoder,ae,"value",W))]}return[F(_)+"="+F(String(K))]}var be=[];if(typeof K>"u")return be;var te;if(g==="comma"&&r(K))N&&I&&(K=e.maybeMap(K,I)),te=[{value:K.length>0?K.join(",")||null:void 0}];else if(r(M))te=M;else{var we=Object.keys(K);te=O?we.sort(O):we}var V=k?_.replace(/\./g,"%2E"):_,L=S&&r(K)&&K.length===1?V+"[]":V;if(x&&r(K)&&K.length===0)return L+"[]";for(var ne=0;ne<te.length;++ne){var H=te[ne],G=typeof H=="object"&&typeof H.value<"u"?H.value:K[H];if(!(E&&G===null)){var Q=B&&k?H.replace(/\./g,"%2E"):H,me=r(K)?typeof g=="function"?g(L,Q):L:L+(B?"."+Q:"["+Q+"]");Y.set(b,D);var se=u();se.set(p,Y),o(be,m(G,me,g,S,x,v,E,k,g==="comma"&&N&&r(K)?null:I,M,O,B,T,W,F,N,ae,se))}}return be},f=function(m){if(!m)return c;if(typeof m.allowEmptyArrays<"u"&&typeof m.allowEmptyArrays!="boolean")throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(typeof m.encodeDotInKeys<"u"&&typeof m.encodeDotInKeys!="boolean")throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(m.encoder!==null&&typeof m.encoder<"u"&&typeof m.encoder!="function")throw new TypeError("Encoder has to be a function.");var b=m.charset||c.charset;if(typeof m.charset<"u"&&m.charset!=="utf-8"&&m.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var _=t.default;if(typeof m.format<"u"){if(!n.call(t.formatters,m.format))throw new TypeError("Unknown format option provided.");_=m.format}var g=t.formatters[_],S=c.filter;(typeof m.filter=="function"||r(m.filter))&&(S=m.filter);var x;if(m.arrayFormat in l?x=m.arrayFormat:"indices"in m?x=m.indices?"indices":"repeat":x=c.arrayFormat,"commaRoundTrip"in m&&typeof m.commaRoundTrip!="boolean")throw new TypeError("`commaRoundTrip` must be a boolean, or absent");var v=typeof m.allowDots>"u"?m.encodeDotInKeys===!0?!0:c.allowDots:!!m.allowDots;return{addQueryPrefix:typeof m.addQueryPrefix=="boolean"?m.addQueryPrefix:c.addQueryPrefix,allowDots:v,allowEmptyArrays:typeof m.allowEmptyArrays=="boolean"?!!m.allowEmptyArrays:c.allowEmptyArrays,arrayFormat:x,charset:b,charsetSentinel:typeof m.charsetSentinel=="boolean"?m.charsetSentinel:c.charsetSentinel,commaRoundTrip:m.commaRoundTrip,delimiter:typeof m.delimiter>"u"?c.delimiter:m.delimiter,encode:typeof m.encode=="boolean"?m.encode:c.encode,encodeDotInKeys:typeof m.encodeDotInKeys=="boolean"?m.encodeDotInKeys:c.encodeDotInKeys,encoder:typeof m.encoder=="function"?m.encoder:c.encoder,encodeValuesOnly:typeof m.encodeValuesOnly=="boolean"?m.encodeValuesOnly:c.encodeValuesOnly,filter:S,format:_,formatter:g,serializeDate:typeof m.serializeDate=="function"?m.serializeDate:c.serializeDate,skipNulls:typeof m.skipNulls=="boolean"?m.skipNulls:c.skipNulls,sort:typeof m.sort=="function"?m.sort:null,strictNullHandling:typeof m.strictNullHandling=="boolean"?m.strictNullHandling:c.strictNullHandling}};return xr=function(m,b){var _=m,g=f(b),S,x;typeof g.filter=="function"?(x=g.filter,_=x("",_)):r(g.filter)&&(x=g.filter,S=x);var v=[];if(typeof _!="object"||_===null)return"";var E=l[g.arrayFormat],k=E==="comma"&&g.commaRoundTrip;S||(S=Object.keys(_)),g.sort&&S.sort(g.sort);for(var I=u(),M=0;M<S.length;++M){var O=S[M];g.skipNulls&&_[O]===null||o(v,y(_[O],O,E,k,g.allowEmptyArrays,g.strictNullHandling,g.skipNulls,g.encodeDotInKeys,g.encode?g.encoder:null,g.filter,g.sort,g.allowDots,g.serializeDate,g.format,g.formatter,g.encodeValuesOnly,g.charset,I))}var B=v.join(g.delimiter),T=g.addQueryPrefix===!0?"?":"";return g.charsetSentinel&&(g.charset==="iso-8859-1"?T+="utf8=%26%2310003%3B&":T+="utf8=%E2%9C%93&"),B.length>0?T+B:""},xr}function Vc(){if(Wi)return Ar;Wi=!0;var u=Ua(),e=Object.prototype.hasOwnProperty,t=Array.isArray,n={allowDots:!1,allowEmptyArrays:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decodeDotInKeys:!1,decoder:u.decode,delimiter:"&",depth:5,duplicates:"combine",ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictDepth:!1,strictNullHandling:!1},l=function(p){return p.replace(/&#(\d+);/g,function(y,f){return String.fromCharCode(parseInt(f,10))})},r=function(p,y){return p&&typeof p=="string"&&y.comma&&p.indexOf(",")>-1?p.split(","):p},i="utf8=%26%2310003%3B",o="utf8=%E2%9C%93",s=function(p,y){var f={__proto__:null},m=y.ignoreQueryPrefix?p.replace(/^\?/,""):p;m=m.replace(/%5B/gi,"[").replace(/%5D/gi,"]");var b=y.parameterLimit===1/0?void 0:y.parameterLimit,_=m.split(y.delimiter,b),g=-1,S,x=y.charset;if(y.charsetSentinel)for(S=0;S<_.length;++S)_[S].indexOf("utf8=")===0&&(_[S]===o?x="utf-8":_[S]===i&&(x="iso-8859-1"),g=S,S=_.length);for(S=0;S<_.length;++S)if(S!==g){var v=_[S],E=v.indexOf("]="),k=E===-1?v.indexOf("="):E+1,I,M;k===-1?(I=y.decoder(v,n.decoder,x,"key"),M=y.strictNullHandling?null:""):(I=y.decoder(v.slice(0,k),n.decoder,x,"key"),M=u.maybeMap(r(v.slice(k+1),y),function(B){return y.decoder(B,n.decoder,x,"value")})),M&&y.interpretNumericEntities&&x==="iso-8859-1"&&(M=l(M)),v.indexOf("[]=")>-1&&(M=t(M)?[M]:M);var O=e.call(f,I);O&&y.duplicates==="combine"?f[I]=u.combine(f[I],M):(!O||y.duplicates==="last")&&(f[I]=M)}return f},a=function(p,y,f,m){for(var b=m?y:r(y,f),_=p.length-1;_>=0;--_){var g,S=p[_];if(S==="[]"&&f.parseArrays)g=f.allowEmptyArrays&&(b===""||f.strictNullHandling&&b===null)?[]:[].concat(b);else{g=f.plainObjects?Object.create(null):{};var x=S.charAt(0)==="["&&S.charAt(S.length-1)==="]"?S.slice(1,-1):S,v=f.decodeDotInKeys?x.replace(/%2E/g,"."):x,E=parseInt(v,10);!f.parseArrays&&v===""?g={0:b}:!isNaN(E)&&S!==v&&String(E)===v&&E>=0&&f.parseArrays&&E<=f.arrayLimit?(g=[],g[E]=b):v!=="__proto__"&&(g[v]=b)}b=g}return b},c=function(p,y,f,m){if(p){var b=f.allowDots?p.replace(/\.([^.[]+)/g,"[$1]"):p,_=/(\[[^[\]]*])/,g=/(\[[^[\]]*])/g,S=f.depth>0&&_.exec(b),x=S?b.slice(0,S.index):b,v=[];if(x){if(!f.plainObjects&&e.call(Object.prototype,x)&&!f.allowPrototypes)return;v.push(x)}for(var E=0;f.depth>0&&(S=g.exec(b))!==null&&E<f.depth;){if(E+=1,!f.plainObjects&&e.call(Object.prototype,S[1].slice(1,-1))&&!f.allowPrototypes)return;v.push(S[1])}if(S){if(f.strictDepth===!0)throw new RangeError("Input depth exceeded depth option of "+f.depth+" and strictDepth is true");v.push("["+b.slice(S.index)+"]")}return a(v,y,f,m)}},d=function(p){if(!p)return n;if(typeof p.allowEmptyArrays<"u"&&typeof p.allowEmptyArrays!="boolean")throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(typeof p.decodeDotInKeys<"u"&&typeof p.decodeDotInKeys!="boolean")throw new TypeError("`decodeDotInKeys` option can only be `true` or `false`, when provided");if(p.decoder!==null&&typeof p.decoder<"u"&&typeof p.decoder!="function")throw new TypeError("Decoder has to be a function.");if(typeof p.charset<"u"&&p.charset!=="utf-8"&&p.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var y=typeof p.charset>"u"?n.charset:p.charset,f=typeof p.duplicates>"u"?n.duplicates:p.duplicates;if(f!=="combine"&&f!=="first"&&f!=="last")throw new TypeError("The duplicates option must be either combine, first, or last");var m=typeof p.allowDots>"u"?p.decodeDotInKeys===!0?!0:n.allowDots:!!p.allowDots;return{allowDots:m,allowEmptyArrays:typeof p.allowEmptyArrays=="boolean"?!!p.allowEmptyArrays:n.allowEmptyArrays,allowPrototypes:typeof p.allowPrototypes=="boolean"?p.allowPrototypes:n.allowPrototypes,allowSparse:typeof p.allowSparse=="boolean"?p.allowSparse:n.allowSparse,arrayLimit:typeof p.arrayLimit=="number"?p.arrayLimit:n.arrayLimit,charset:y,charsetSentinel:typeof p.charsetSentinel=="boolean"?p.charsetSentinel:n.charsetSentinel,comma:typeof p.comma=="boolean"?p.comma:n.comma,decodeDotInKeys:typeof p.decodeDotInKeys=="boolean"?p.decodeDotInKeys:n.decodeDotInKeys,decoder:typeof p.decoder=="function"?p.decoder:n.decoder,delimiter:typeof p.delimiter=="string"||u.isRegExp(p.delimiter)?p.delimiter:n.delimiter,depth:typeof p.depth=="number"||p.depth===!1?+p.depth:n.depth,duplicates:f,ignoreQueryPrefix:p.ignoreQueryPrefix===!0,interpretNumericEntities:typeof p.interpretNumericEntities=="boolean"?p.interpretNumericEntities:n.interpretNumericEntities,parameterLimit:typeof p.parameterLimit=="number"?p.parameterLimit:n.parameterLimit,parseArrays:p.parseArrays!==!1,plainObjects:typeof p.plainObjects=="boolean"?p.plainObjects:n.plainObjects,strictDepth:typeof p.strictDepth=="boolean"?!!p.strictDepth:n.strictDepth,strictNullHandling:typeof p.strictNullHandling=="boolean"?p.strictNullHandling:n.strictNullHandling}};return Ar=function(p,y){var f=d(y);if(p===""||p===null||typeof p>"u")return f.plainObjects?Object.create(null):{};for(var m=typeof p=="string"?s(p,f):p,b=f.plainObjects?Object.create(null):{},_=Object.keys(m),g=0;g<_.length;++g){var S=_[g],x=c(S,m[S],f,typeof p=="string");b=u.merge(b,x,f)}return f.allowSparse===!0?b:u.compact(b)},Ar}function Gc(){if(qi)return Ir;qi=!0;var u=Kc(),e=Vc(),t=is();return Ir={formats:t,parse:e,stringify:u},Ir}function Yc(){if(Hi)return gt;Hi=!0;var u=pt;function e(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}var t=/^([a-z0-9.+-]+:)/i,n=/:[0-9]*$/,l=/^(\/\/?(?!\/)[^?\s]*)(\?[^\s]*)?$/,r=["<",">",'"',"`"," ","\r",`
|
|
7
|
-
`," "],i=["{","}","|","\\","^","`"].concat(r),o=["'"].concat(i),s=["%","/","?",";","#"].concat(o),a=["/","?","#"],c=255,d=/^[+a-z0-9A-Z_-]{0,63}$/,p=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,y={javascript:!0,"javascript:":!0},f={javascript:!0,"javascript:":!0},m={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},b=Gc();function _(v,E,k){if(v&&typeof v=="object"&&v instanceof e)return v;var I=new e;return I.parse(v,E,k),I}e.prototype.parse=function(v,E,k){if(typeof v!="string")throw new TypeError("Parameter 'url' must be a string, not "+typeof v);var I=v.indexOf("?"),M=I!==-1&&I<v.indexOf("#")?"?":"#",O=v.split(M),B=/\\/g;O[0]=O[0].replace(B,"/"),v=O.join(M);var T=v;if(T=T.trim(),!k&&v.split("#").length===1){var W=l.exec(T);if(W)return this.path=T,this.href=T,this.pathname=W[1],W[2]?(this.search=W[2],E?this.query=b.parse(this.search.substr(1)):this.query=this.search.substr(1)):E&&(this.search="",this.query={}),this}var F=t.exec(T);if(F){F=F[0];var N=F.toLowerCase();this.protocol=N,T=T.substr(F.length)}if(k||F||T.match(/^\/\/[^@/]+@[^@/]+/)){var ae=T.substr(0,2)==="//";ae&&!(F&&f[F])&&(T=T.substr(2),this.slashes=!0)}if(!f[F]&&(ae||F&&!m[F])){for(var Y=-1,K=0;K<a.length;K++){var re=T.indexOf(a[K]);re!==-1&&(Y===-1||re<Y)&&(Y=re)}var D,Z;Y===-1?Z=T.lastIndexOf("@"):Z=T.lastIndexOf("@",Y),Z!==-1&&(D=T.slice(0,Z),T=T.slice(Z+1),this.auth=decodeURIComponent(D)),Y=-1;for(var K=0;K<s.length;K++){var re=T.indexOf(s[K]);re!==-1&&(Y===-1||re<Y)&&(Y=re)}Y===-1&&(Y=T.length),this.host=T.slice(0,Y),T=T.slice(Y),this.parseHost(),this.hostname=this.hostname||"";var P=this.hostname[0]==="["&&this.hostname[this.hostname.length-1]==="]";if(!P)for(var J=this.hostname.split(/\./),K=0,be=J.length;K<be;K++){var te=J[K];if(te&&!te.match(d)){for(var we="",V=0,L=te.length;V<L;V++)te.charCodeAt(V)>127?we+="x":we+=te[V];if(!we.match(d)){var ne=J.slice(0,K),H=J.slice(K+1),G=te.match(p);G&&(ne.push(G[1]),H.unshift(G[2])),H.length&&(T="/"+H.join(".")+T),this.hostname=ne.join(".");break}}}this.hostname.length>c?this.hostname="":this.hostname=this.hostname.toLowerCase(),P||(this.hostname=u.toASCII(this.hostname));var Q=this.port?":"+this.port:"",me=this.hostname||"";this.host=me+Q,this.href+=this.host,P&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),T[0]!=="/"&&(T="/"+T))}if(!y[N])for(var K=0,be=o.length;K<be;K++){var se=o[K];if(T.indexOf(se)!==-1){var R=encodeURIComponent(se);R===se&&(R=escape(se)),T=T.split(se).join(R)}}var $=T.indexOf("#");$!==-1&&(this.hash=T.substr($),T=T.slice(0,$));var ee=T.indexOf("?");if(ee!==-1?(this.search=T.substr(ee),this.query=T.substr(ee+1),E&&(this.query=b.parse(this.query)),T=T.slice(0,ee)):E&&(this.search="",this.query={}),T&&(this.pathname=T),m[N]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){var Q=this.pathname||"",fe=this.search||"";this.path=Q+fe}return this.href=this.format(),this};function g(v){return typeof v=="string"&&(v=_(v)),v instanceof e?v.format():e.prototype.format.call(v)}e.prototype.format=function(){var v=this.auth||"";v&&(v=encodeURIComponent(v),v=v.replace(/%3A/i,":"),v+="@");var E=this.protocol||"",k=this.pathname||"",I=this.hash||"",M=!1,O="";this.host?M=v+this.host:this.hostname&&(M=v+(this.hostname.indexOf(":")===-1?this.hostname:"["+this.hostname+"]"),this.port&&(M+=":"+this.port)),this.query&&typeof this.query=="object"&&Object.keys(this.query).length&&(O=b.stringify(this.query,{arrayFormat:"repeat",addQueryPrefix:!1}));var B=this.search||O&&"?"+O||"";return E&&E.substr(-1)!==":"&&(E+=":"),this.slashes||(!E||m[E])&&M!==!1?(M="//"+(M||""),k&&k.charAt(0)!=="/"&&(k="/"+k)):M||(M=""),I&&I.charAt(0)!=="#"&&(I="#"+I),B&&B.charAt(0)!=="?"&&(B="?"+B),k=k.replace(/[?#]/g,function(T){return encodeURIComponent(T)}),B=B.replace("#","%23"),E+M+k+B+I};function S(v,E){return _(v,!1,!0).resolve(E)}e.prototype.resolve=function(v){return this.resolveObject(_(v,!1,!0)).format()};function x(v,E){return v?_(v,!1,!0).resolveObject(E):E}return e.prototype.resolveObject=function(v){if(typeof v=="string"){var E=new e;E.parse(v,!1,!0),v=E}for(var k=new e,I=Object.keys(this),M=0;M<I.length;M++){var O=I[M];k[O]=this[O]}if(k.hash=v.hash,v.href==="")return k.href=k.format(),k;if(v.slashes&&!v.protocol){for(var B=Object.keys(v),T=0;T<B.length;T++){var W=B[T];W!=="protocol"&&(k[W]=v[W])}return m[k.protocol]&&k.hostname&&!k.pathname&&(k.pathname="/",k.path=k.pathname),k.href=k.format(),k}if(v.protocol&&v.protocol!==k.protocol){if(!m[v.protocol]){for(var F=Object.keys(v),N=0;N<F.length;N++){var ae=F[N];k[ae]=v[ae]}return k.href=k.format(),k}if(k.protocol=v.protocol,!v.host&&!f[v.protocol]){for(var be=(v.pathname||"").split("/");be.length&&!(v.host=be.shift()););v.host||(v.host=""),v.hostname||(v.hostname=""),be[0]!==""&&be.unshift(""),be.length<2&&be.unshift(""),k.pathname=be.join("/")}else k.pathname=v.pathname;if(k.search=v.search,k.query=v.query,k.host=v.host||"",k.auth=v.auth,k.hostname=v.hostname||v.host,k.port=v.port,k.pathname||k.search){var Y=k.pathname||"",K=k.search||"";k.path=Y+K}return k.slashes=k.slashes||v.slashes,k.href=k.format(),k}var re=k.pathname&&k.pathname.charAt(0)==="/",D=v.host||v.pathname&&v.pathname.charAt(0)==="/",Z=D||re||k.host&&v.pathname,P=Z,J=k.pathname&&k.pathname.split("/")||[],be=v.pathname&&v.pathname.split("/")||[],te=k.protocol&&!m[k.protocol];if(te&&(k.hostname="",k.port=null,k.host&&(J[0]===""?J[0]=k.host:J.unshift(k.host)),k.host="",v.protocol&&(v.hostname=null,v.port=null,v.host&&(be[0]===""?be[0]=v.host:be.unshift(v.host)),v.host=null),Z=Z&&(be[0]===""||J[0]==="")),D)k.host=v.host||v.host===""?v.host:k.host,k.hostname=v.hostname||v.hostname===""?v.hostname:k.hostname,k.search=v.search,k.query=v.query,J=be;else if(be.length)J||(J=[]),J.pop(),J=J.concat(be),k.search=v.search,k.query=v.query;else if(v.search!=null){if(te){k.host=J.shift(),k.hostname=k.host;var we=k.host&&k.host.indexOf("@")>0?k.host.split("@"):!1;we&&(k.auth=we.shift(),k.hostname=we.shift(),k.host=k.hostname)}return k.search=v.search,k.query=v.query,(k.pathname!==null||k.search!==null)&&(k.path=(k.pathname?k.pathname:"")+(k.search?k.search:"")),k.href=k.format(),k}if(!J.length)return k.pathname=null,k.search?k.path="/"+k.search:k.path=null,k.href=k.format(),k;for(var V=J.slice(-1)[0],L=(k.host||v.host||J.length>1)&&(V==="."||V==="..")||V==="",ne=0,H=J.length;H>=0;H--)V=J[H],V==="."?J.splice(H,1):V===".."?(J.splice(H,1),ne++):ne&&(J.splice(H,1),ne--);if(!Z&&!P)for(;ne--;ne)J.unshift("..");Z&&J[0]!==""&&(!J[0]||J[0].charAt(0)!=="/")&&J.unshift(""),L&&J.join("/").substr(-1)!=="/"&&J.push("");var G=J[0]===""||J[0]&&J[0].charAt(0)==="/";if(te){k.hostname=G?"":J.length?J.shift():"",k.host=k.hostname;var we=k.host&&k.host.indexOf("@")>0?k.host.split("@"):!1;we&&(k.auth=we.shift(),k.hostname=we.shift(),k.host=k.hostname)}return Z=Z||k.host&&J.length,Z&&!G&&J.unshift(""),J.length>0?k.pathname=J.join("/"):(k.pathname=null,k.path=null),(k.pathname!==null||k.search!==null)&&(k.path=(k.pathname?k.pathname:"")+(k.search?k.search:"")),k.auth=v.auth||k.auth,k.slashes=k.slashes||v.slashes,k.href=k.format(),k},e.prototype.parseHost=function(){var v=this.host,E=n.exec(v);E&&(E=E[0],E!==":"&&(this.port=E.substr(1)),v=v.substr(0,v.length-E.length)),v&&(this.hostname=v)},gt.parse=_,gt.resolve=S,gt.resolveObject=x,gt.format=g,gt.Url=e,gt}function Ba(u){if(typeof u=="string")u=new URL(u);else if(!(u instanceof URL))throw new Deno.errors.InvalidData("invalid argument path , must be a string or URL");if(u.protocol!=="file:")throw new Deno.errors.InvalidData("invalid url scheme");return Cr?Qc(u):Jc(u)}function Qc(u){let e=u.hostname,t=u.pathname;for(let n=0;n<t.length;n++)if(t[n]==="%"){let l=t.codePointAt(n+2)||32;if(t[n+1]==="2"&&l===102||t[n+1]==="5"&&l===99)throw new Deno.errors.InvalidData("must not include encoded \\ or / characters")}if(t=t.replace(Ja,"\\"),t=decodeURIComponent(t),e!=="")return`\\\\${e}${t}`;{let n=t.codePointAt(1)|32,l=t[2];if(n<Ya||n>Qa||l!==":")throw new Deno.errors.InvalidData("file url path must be absolute");return t.slice(1)}}function Jc(u){if(u.hostname!=="")throw new Deno.errors.InvalidData("invalid file url hostname");let e=u.pathname;for(let t=0;t<e.length;t++)if(e[t]==="%"){let n=e.codePointAt(t+2)||32;if(e[t+1]==="2"&&n===102)throw new Deno.errors.InvalidData("must not include encoded / characters")}return decodeURIComponent(e)}function Fa(u){let e=Ni.resolve(u),t=u.charCodeAt(u.length-1);(t===Ga||Cr&&t===Va)&&e[e.length-1]!==Ni.sep&&(e+="/");let n=new URL("file://");return e.includes("%")&&(e=e.replace(Xa,"%25")),!Cr&&e.includes("\\")&&(e=e.replace(Za,"%5C")),e.includes(`
|
|
8
|
-
`)&&(e=e.replace(el,"%0A")),e.includes("\r")&&(e=e.replace(tl,"%0D")),e.includes(" ")&&(e=e.replace(rl,"%09")),n.pathname=e,n}var Da,wr,Ui,_r,Sr,Bi,kr,Fi,Er,Di,xr,$i,Ar,Wi,Ir,qi,gt,Hi,De,mo,$a,Wa,qa,Ha,za,Ka,Va,Ga,Ya,Qa,Cr,Ja,Xa,Za,el,tl,rl,Xc=He(()=>{le(),ce(),ue(),gc(),Pc(),qc(),La(),Da=Object.freeze(Object.create(null)),wr={},Ui=!1,_r=typeof globalThis<"u"?globalThis:typeof self<"u"?self:global,Sr={},Bi=!1,kr={},Fi=!1,Er={},Di=!1,xr={},$i=!1,Ar={},Wi=!1,Ir={},qi=!1,gt={},Hi=!1,De=Yc(),De.parse,De.resolve,De.resolveObject,De.format,De.Url,mo=typeof Deno<"u"?Deno.build.os==="windows"?"win32":Deno.build.os:void 0,De.URL=typeof URL<"u"?URL:null,De.pathToFileURL=Fa,De.fileURLToPath=Ba,$a=De.Url,Wa=De.format,qa=De.resolve,Ha=De.resolveObject,za=De.parse,Ka=De.URL,Va=92,Ga=47,Ya=97,Qa=122,Cr=mo==="win32",Ja=/\//g,Xa=/%/g,Za=/\\/g,el=/\n/g,tl=/\r/g,rl=/\t/g}),Zc=pe((u,e)=>{le(),ce(),ue(),e.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}}),ss=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"__esModule",{value:!0}),u.BufferedDuplex=void 0,u.writev=n;var e=At(),t=(Ne(),Oe(Le));function n(r,i){let o=new Array(r.length);for(let s=0;s<r.length;s++)typeof r[s].chunk=="string"?o[s]=t.Buffer.from(r[s].chunk,"utf8"):o[s]=r[s].chunk;this._write(t.Buffer.concat(o),"binary",i)}var l=class extends e.Duplex{socket;proxy;isSocketOpen;writeQueue;constructor(r,i,o){super({objectMode:!0}),this.proxy=i,this.socket=o,this.writeQueue=[],r.objectMode||(this._writev=n.bind(this)),this.isSocketOpen=!1,this.proxy.on("data",s=>{!this.destroyed&&this.readable&&this.push(s)})}_read(r){this.proxy.read(r)}_write(r,i,o){this.isSocketOpen?this.writeToProxy(r,i,o):this.writeQueue.push({chunk:r,encoding:i,cb:o})}_final(r){this.writeQueue=[],this.proxy.end(r)}_destroy(r,i){this.writeQueue=[],this.proxy.destroy(),i(r)}socketReady(){this.emit("connect"),this.isSocketOpen=!0,this.processWriteQueue()}writeToProxy(r,i,o){this.proxy.write(r,i)===!1?this.proxy.once("drain",o):o()}processWriteQueue(){for(;this.writeQueue.length>0;){let{chunk:r,encoding:i,cb:o}=this.writeQueue.shift();this.writeToProxy(r,i,o)}}};u.BufferedDuplex=l}),er=pe(u=>{le(),ce(),ue();var e=u&&u.__importDefault||function(_){return _&&_.__esModule?_:{default:_}};Object.defineProperty(u,"__esModule",{value:!0}),u.streamBuilder=u.browserStreamBuilder=void 0;var t=(Ne(),Oe(Le)),n=e(Zc()),l=e(at()),r=At(),i=e(Nr()),o=ss(),s=(0,l.default)("mqttjs:ws"),a=["rejectUnauthorized","ca","cert","key","pfx","passphrase"];function c(_,g){let S=`${_.protocol}://${_.hostname}:${_.port}${_.path}`;return typeof _.transformWsUrl=="function"&&(S=_.transformWsUrl(S,_,g)),S}function d(_){let g=_;return _.port||(_.protocol==="wss"?g.port=443:g.port=80),_.path||(g.path="/"),_.wsOptions||(g.wsOptions={}),!i.default&&!_.forceNativeWebSocket&&_.protocol==="wss"&&a.forEach(S=>{Object.prototype.hasOwnProperty.call(_,S)&&!Object.prototype.hasOwnProperty.call(_.wsOptions,S)&&(g.wsOptions[S]=_[S])}),g}function p(_){let g=d(_);if(g.hostname||(g.hostname=g.host),!g.hostname){if(typeof document>"u")throw new Error("Could not determine host. Specify host manually.");let S=new URL(document.URL);g.hostname=S.hostname,g.port||(g.port=Number(S.port))}return g.objectMode===void 0&&(g.objectMode=!(g.binary===!0||g.binary===void 0)),g}function y(_,g,S){s("createWebSocket"),s(`protocol: ${S.protocolId} ${S.protocolVersion}`);let x=S.protocolId==="MQIsdp"&&S.protocolVersion===3?"mqttv3.1":"mqtt";s(`creating new Websocket for url: ${g} and protocol: ${x}`);let v;return S.createWebsocket?v=S.createWebsocket(g,[x],S):v=new n.default(g,[x],S.wsOptions),v}function f(_,g){let S=g.protocolId==="MQIsdp"&&g.protocolVersion===3?"mqttv3.1":"mqtt",x=c(g,_),v;return g.createWebsocket?v=g.createWebsocket(x,[S],g):v=new WebSocket(x,[S]),v.binaryType="arraybuffer",v}var m=(_,g)=>{s("streamBuilder");let S=d(g);S.hostname=S.hostname||S.host||"localhost";let x=c(S,_),v=y(_,x,S),E=n.default.createWebSocketStream(v,S.wsOptions);return E.url=x,v.on("close",()=>{E.destroy()}),E};u.streamBuilder=m;var b=(_,g)=>{s("browserStreamBuilder");let S,x=p(g).browserBufferSize||1024*512,v=g.browserBufferTimeout||1e3,E=!g.objectMode,k=f(_,g),I=O(g,N,ae);g.objectMode||(I._writev=o.writev.bind(I)),I.on("close",()=>{k.close()});let M=typeof k.addEventListener<"u";k.readyState===k.OPEN?(S=I,S.socket=k):(S=new o.BufferedDuplex(g,I,k),M?k.addEventListener("open",B):k.onopen=B),M?(k.addEventListener("close",T),k.addEventListener("error",W),k.addEventListener("message",F)):(k.onclose=T,k.onerror=W,k.onmessage=F);function O(Y,K,re){let D=new r.Transform({objectMode:Y.objectMode});return D._write=K,D._flush=re,D}function B(){s("WebSocket onOpen"),S instanceof o.BufferedDuplex&&S.socketReady()}function T(Y){s("WebSocket onClose",Y),S.end(),S.destroy()}function W(Y){s("WebSocket onError",Y);let K=new Error("WebSocket error");K.event=Y,S.destroy(K)}async function F(Y){if(!I||!I.readable||!I.writable)return;let{data:K}=Y;K instanceof ArrayBuffer?K=t.Buffer.from(K):K instanceof Blob?K=t.Buffer.from(await new Response(K).arrayBuffer()):K=t.Buffer.from(K,"utf8"),I.push(K)}function N(Y,K,re){if(k.bufferedAmount>x){setTimeout(N,v,Y,K,re);return}E&&typeof Y=="string"&&(Y=t.Buffer.from(Y,"utf8"));try{k.send(Y)}catch(D){return re(D)}re()}function ae(Y){k.close(),Y()}return S};u.browserStreamBuilder=b}),os={};jt(os,{Server:()=>Me,Socket:()=>Me,Stream:()=>Me,_createServerHandle:()=>Me,_normalizeArgs:()=>Me,_setSimultaneousAccepts:()=>Me,connect:()=>Me,createConnection:()=>Me,createServer:()=>Me,default:()=>nl,isIP:()=>Me,isIPv4:()=>Me,isIPv6:()=>Me});function Me(){throw new Error("Node.js net module is not supported by JSPM core outside of Node.js")}var nl,il=He(()=>{le(),ce(),ue(),nl={_createServerHandle:Me,_normalizeArgs:Me,_setSimultaneousAccepts:Me,connect:Me,createConnection:Me,createServer:Me,isIP:Me,isIPv4:Me,isIPv6:Me,Server:Me,Socket:Me,Stream:Me}}),sl=pe((u,e)=>{le(),ce(),ue(),e.exports={}}),bo=pe(u=>{le(),ce(),ue();var e=u&&u.__importDefault||function(o){return o&&o.__esModule?o:{default:o}};Object.defineProperty(u,"__esModule",{value:!0});var t=e((il(),Oe(os))),n=e(at()),l=e(sl()),r=(0,n.default)("mqttjs:tcp"),i=(o,s)=>{if(s.port=s.port||1883,s.hostname=s.hostname||s.host||"localhost",s.socksProxy)return(0,l.default)(s.hostname,s.port,s.socksProxy,{timeout:s.socksTimeout});let{port:a,path:c}=s,d=s.hostname;return r("port %d and host %s",a,d),t.default.createConnection({port:a,host:d,path:c})};u.default=i}),ol={};jt(ol,{default:()=>al});var al,eh=He(()=>{le(),ce(),ue(),al={}}),yo=pe(u=>{le(),ce(),ue();var e=u&&u.__importDefault||function(a){return a&&a.__esModule?a:{default:a}};Object.defineProperty(u,"__esModule",{value:!0});var t=(eh(),Oe(ol)),n=e((il(),Oe(os))),l=e(at()),r=e(sl()),i=(0,l.default)("mqttjs:tls");function o(a){let{host:c,port:d,socksProxy:p,...y}=a;if(p!==void 0){let f=(0,r.default)(c,d,p,{timeout:a.socksTimeout});return(0,t.connect)({...y,socket:f})}return(0,t.connect)(a)}var s=(a,c)=>{c.port=c.port||8883,c.host=c.hostname||c.host||"localhost",n.default.isIP(c.host)===0&&(c.servername=c.host),c.rejectUnauthorized=c.rejectUnauthorized!==!1,delete c.path,i("port %d host %s rejectUnauthorized %b",c.port,c.host,c.rejectUnauthorized);let d=o(c);d.on("secureConnect",()=>{c.rejectUnauthorized&&!d.authorized?d.emit("error",new Error("TLS not authorized")):d.removeListener("error",p)});function p(y){c.rejectUnauthorized&&a.emit("error",y),d.end()}return d.on("error",p),d};u.default=s}),vo=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"__esModule",{value:!0});var e=(Ne(),Oe(Le)),t=At(),n=ss(),l,r,i;function o(){let p=new t.Transform;return p._write=(y,f,m)=>{l.send({data:y.buffer,success(){m()},fail(b){m(new Error(b))}})},p._flush=y=>{l.close({success(){y()}})},p}function s(p){p.hostname||(p.hostname="localhost"),p.path||(p.path="/"),p.wsOptions||(p.wsOptions={})}function a(p,y){let f=p.protocol==="wxs"?"wss":"ws",m=`${f}://${p.hostname}${p.path}`;return p.port&&p.port!==80&&p.port!==443&&(m=`${f}://${p.hostname}:${p.port}${p.path}`),typeof p.transformWsUrl=="function"&&(m=p.transformWsUrl(m,p,y)),m}function c(){l.onOpen(()=>{i.socketReady()}),l.onMessage(p=>{let{data:y}=p;y instanceof ArrayBuffer?y=e.Buffer.from(y):y=e.Buffer.from(y,"utf8"),r.push(y)}),l.onClose(()=>{i.emit("close"),i.end(),i.destroy()}),l.onError(p=>{let y=new Error(p.errMsg);i.destroy(y)})}var d=(p,y)=>{if(y.hostname=y.hostname||y.host,!y.hostname)throw new Error("Could not determine host. Specify host manually.");let f=y.protocolId==="MQIsdp"&&y.protocolVersion===3?"mqttv3.1":"mqtt";s(y);let m=a(y,p);l=wx.connectSocket({url:m,protocols:[f]}),r=o(),i=new n.BufferedDuplex(y,r,l),i._destroy=(_,g)=>{l.close({success(){g&&g(_)}})};let b=i.destroy;return i.destroy=(_,g)=>(i.destroy=b,setTimeout(()=>{l.close({fail(){i._destroy(_,g)}})},0),i),c(),i};u.default=d}),wo=pe(u=>{le(),ce(),ue(),Object.defineProperty(u,"__esModule",{value:!0});var e=(Ne(),Oe(Le)),t=At(),n=ss(),l,r,i,o=!1;function s(){let y=new t.Transform;return y._write=(f,m,b)=>{l.sendSocketMessage({data:f.buffer,success(){b()},fail(){b(new Error)}})},y._flush=f=>{l.closeSocket({success(){f()}})},y}function a(y){y.hostname||(y.hostname="localhost"),y.path||(y.path="/"),y.wsOptions||(y.wsOptions={})}function c(y,f){let m=y.protocol==="alis"?"wss":"ws",b=`${m}://${y.hostname}${y.path}`;return y.port&&y.port!==80&&y.port!==443&&(b=`${m}://${y.hostname}:${y.port}${y.path}`),typeof y.transformWsUrl=="function"&&(b=y.transformWsUrl(b,y,f)),b}function d(){o||(o=!0,l.onSocketOpen(()=>{i.socketReady()}),l.onSocketMessage(y=>{if(typeof y.data=="string"){let f=e.Buffer.from(y.data,"base64");r.push(f)}else{let f=new FileReader;f.addEventListener("load",()=>{if(f.result instanceof ArrayBuffer){r.push(e.Buffer.from(f.result));return}r.push(e.Buffer.from(f.result,"utf-8"))}),f.readAsArrayBuffer(y.data)}}),l.onSocketClose(()=>{i.end(),i.destroy()}),l.onSocketError(y=>{i.destroy(y)}))}var p=(y,f)=>{if(f.hostname=f.hostname||f.host,!f.hostname)throw new Error("Could not determine host. Specify host manually.");let m=f.protocolId==="MQIsdp"&&f.protocolVersion===3?"mqttv3.1":"mqtt";a(f);let b=c(f,y);return l=f.my,l.connectSocket({url:b,protocols:m}),r=s(),i=new n.BufferedDuplex(f,r,l),d(),i};u.default=p}),th=pe(u=>{le(),ce(),ue();var e=u&&u.__importDefault||function(d){return d&&d.__esModule?d:{default:d}};Object.defineProperty(u,"__esModule",{value:!0}),u.connectAsync=c;var t=e(at()),n=e((Xc(),Oe(Na))),l=e(ni()),r=e(Nr());typeof Pe?.nextTick!="function"&&(Pe.nextTick=setImmediate);var i=(0,t.default)("mqttjs"),o=null;function s(d){let p;if(d.auth)if(p=d.auth.match(/^(.+):(.+)$/),p){let[,y,f]=p;d.username=y,d.password=f}else d.username=d.auth}function a(d,p){if(i("connecting to an MQTT broker..."),typeof d=="object"&&!p&&(p=d,d=""),p=p||{},d&&typeof d=="string"){let m=n.default.parse(d,!0),b={};if(m.port!=null&&(b.port=Number(m.port)),b.host=m.hostname,b.query=m.query,b.auth=m.auth,b.protocol=m.protocol,b.path=m.path,p={...b,...p},!p.protocol)throw new Error("Missing protocol");p.protocol=p.protocol.replace(/:$/,"")}if(p.unixSocket=p.unixSocket||p.protocol?.includes("+unix"),p.unixSocket?p.protocol=p.protocol.replace("+unix",""):!p.protocol?.startsWith("ws")&&!p.protocol?.startsWith("wx")&&delete p.path,s(p),p.query&&typeof p.query.clientId=="string"&&(p.clientId=p.query.clientId),r.default||p.unixSocket?p.socksProxy=void 0:p.socksProxy===void 0&&typeof Pe<"u"&&(p.socksProxy=Pe.env.MQTTJS_SOCKS_PROXY),p.cert&&p.key)if(p.protocol){if(["mqtts","wss","wxs","alis"].indexOf(p.protocol)===-1)switch(p.protocol){case"mqtt":p.protocol="mqtts";break;case"ws":p.protocol="wss";break;case"wx":p.protocol="wxs";break;case"ali":p.protocol="alis";break;default:throw new Error(`Unknown protocol for secure connection: "${p.protocol}"!`)}}else throw new Error("Missing secure protocol key");if(o||(o={},!r.default&&!p.forceNativeWebSocket?(o.ws=er().streamBuilder,o.wss=er().streamBuilder,o.mqtt=bo().default,o.tcp=bo().default,o.ssl=yo().default,o.tls=o.ssl,o.mqtts=yo().default):(o.ws=er().browserStreamBuilder,o.wss=er().browserStreamBuilder,o.wx=vo().default,o.wxs=vo().default,o.ali=wo().default,o.alis=wo().default)),!o[p.protocol]){let m=["mqtts","wss"].indexOf(p.protocol)!==-1;p.protocol=["mqtt","mqtts","ws","wss","wx","wxs","ali","alis"].filter((b,_)=>m&&_%2===0?!1:typeof o[b]=="function")[0]}if(p.clean===!1&&!p.clientId)throw new Error("Missing clientId for unclean clients");p.protocol&&(p.defaultProtocol=p.protocol);function y(m){return p.servers&&((!m._reconnectCount||m._reconnectCount===p.servers.length)&&(m._reconnectCount=0),p.host=p.servers[m._reconnectCount].host,p.port=p.servers[m._reconnectCount].port,p.protocol=p.servers[m._reconnectCount].protocol?p.servers[m._reconnectCount].protocol:p.defaultProtocol,p.hostname=p.host,m._reconnectCount++),i("calling streambuilder for",p.protocol),o[p.protocol](m,p)}let f=new l.default(y,p);return f.on("error",()=>{}),f}function c(d,p,y=!0){return new Promise((f,m)=>{let b=a(d,p),_={connect:S=>{g(),f(b)},end:()=>{g(),f(b)},error:S=>{g(),b.end(),m(S)}};y===!1&&(_.close=()=>{_.error(new Error("Couldn't connect to server"))});function g(){Object.keys(_).forEach(S=>{b.off(S,_[S])})}Object.keys(_).forEach(S=>{b.on(S,_[S])})})}u.default=a}),_o=pe(u=>{le(),ce(),ue();var e=u&&u.__createBinding||(Object.create?function(y,f,m,b){b===void 0&&(b=m);var _=Object.getOwnPropertyDescriptor(f,m);(!_||("get"in _?!f.__esModule:_.writable||_.configurable))&&(_={enumerable:!0,get:function(){return f[m]}}),Object.defineProperty(y,b,_)}:function(y,f,m,b){b===void 0&&(b=m),y[b]=f[m]}),t=u&&u.__setModuleDefault||(Object.create?function(y,f){Object.defineProperty(y,"default",{enumerable:!0,value:f})}:function(y,f){y.default=f}),n=u&&u.__importStar||(function(){var y=function(f){return y=Object.getOwnPropertyNames||function(m){var b=[];for(var _ in m)Object.prototype.hasOwnProperty.call(m,_)&&(b[b.length]=_);return b},y(f)};return function(f){if(f&&f.__esModule)return f;var m={};if(f!=null)for(var b=y(f),_=0;_<b.length;_++)b[_]!=="default"&&e(m,f,b[_]);return t(m,f),m}})(),l=u&&u.__exportStar||function(y,f){for(var m in y)m!=="default"&&!Object.prototype.hasOwnProperty.call(f,m)&&e(f,y,m)},r=u&&u.__importDefault||function(y){return y&&y.__esModule?y:{default:y}};Object.defineProperty(u,"__esModule",{value:!0}),u.ReasonCodes=u.KeepaliveManager=u.UniqueMessageIdProvider=u.DefaultMessageIdProvider=u.Store=u.MqttClient=u.connectAsync=u.connect=u.Client=void 0;var i=r(ni());u.MqttClient=i.default;var o=r(ka());u.DefaultMessageIdProvider=o.default;var s=r(dc());u.UniqueMessageIdProvider=s.default;var a=r(oa());u.Store=a.default;var c=n(th());u.connect=c.default,Object.defineProperty(u,"connectAsync",{enumerable:!0,get:function(){return c.connectAsync}});var d=r(Oa());u.KeepaliveManager=d.default,u.Client=i.default,l(ni(),u),l(Nt(),u),l(sa(),u);var p=jr();Object.defineProperty(u,"ReasonCodes",{enumerable:!0,get:function(){return p.ReasonCodes}})}),rh=pe(u=>{le(),ce(),ue();var e=u&&u.__createBinding||(Object.create?function(i,o,s,a){a===void 0&&(a=s);var c=Object.getOwnPropertyDescriptor(o,s);(!c||("get"in c?!o.__esModule:c.writable||c.configurable))&&(c={enumerable:!0,get:function(){return o[s]}}),Object.defineProperty(i,a,c)}:function(i,o,s,a){a===void 0&&(a=s),i[a]=o[s]}),t=u&&u.__setModuleDefault||(Object.create?function(i,o){Object.defineProperty(i,"default",{enumerable:!0,value:o})}:function(i,o){i.default=o}),n=u&&u.__importStar||(function(){var i=function(o){return i=Object.getOwnPropertyNames||function(s){var a=[];for(var c in s)Object.prototype.hasOwnProperty.call(s,c)&&(a[a.length]=c);return a},i(o)};return function(o){if(o&&o.__esModule)return o;var s={};if(o!=null)for(var a=i(o),c=0;c<a.length;c++)a[c]!=="default"&&e(s,o,a[c]);return t(s,o),s}})(),l=u&&u.__exportStar||function(i,o){for(var s in i)s!=="default"&&!Object.prototype.hasOwnProperty.call(o,s)&&e(o,i,s)};Object.defineProperty(u,"__esModule",{value:!0});var r=n(_o());u.default=r,l(_o(),u)});const nh=rh();const ih={inbound:"apps/{appId}/users/{userId}/messages/{conversationId}/clientadded",inboundUpdate:"apps/{appId}/users/{userId}/messages/{conversationId}/{messageId}/update",outbound:"apps/{appId}/outgoing/users/{userId}/messages/{conversationId}/outgoing",presence:"apps/{appId}/users/{userId}/presence/{clientId}",wildcardSubscribe:"apps/{appId}/users/{userId}/#"},sh=300,oh={templateId:"7",type:"link",isDeepLink:!0},ah={channelType:"group",channel:"chat21",requestChannel:"chat21",platform:"WEBSITE",medium:"CHATBUDDY"};class ll{client=null;config;currentToken;clientId;appId;topics;messageHandlers=[];stateHandlers=[];statusUpdateHandlers=[];subscribedTopics=new Set;reconnectAttempt=0;maxReconnectAttempts;reconnectMaxDelayMs;disposed=!1;reconnectTimer=null;inboundRegex;inboundUpdateRegex;constructor(e){this.config=e,this.currentToken=e.jwtToken,this.appId=e.appId??"tilechat",this.clientId=e.clientId??`aikaara_${e.userId}_${Date.now()}`,this.topics={...ih,...e.topicTemplates??{}},this.maxReconnectAttempts=e.maxReconnectAttempts??10,this.reconnectMaxDelayMs=e.reconnectMaxDelayMs??3e4,this.inboundRegex=this.buildTopicRegex(this.topics.inbound,["conversationId"]),this.inboundUpdateRegex=this.buildTopicRegex(this.topics.inboundUpdate,["conversationId","messageId"])}async connect(){if(this.disposed)return;const e=this.renderPresenceTopic(),t=this.config.presencePayloadDisconnected??{disconnected:!0},n={clientId:this.clientId,username:this.config.mqttUsername??"JWT",password:this.currentToken,clean:!0,reconnectPeriod:0,connectTimeout:this.config.connectTimeoutMs??1e4,keepalive:this.config.keepAliveSec??60,protocolVersion:this.config.protocolVersion??3,protocolId:this.config.protocolId??"MQIsdp"};return this.config.enablePresence!==!1&&(n.will={topic:e,payload:JSON.stringify(t),qos:0,retain:!1}),new Promise((l,r)=>{this.client=nh.connect(this.config.mqttEndpoint,n),this.client.on("connect",()=>{if(this.reconnectAttempt=0,this.debugLog("CONNECT",{endpoint:this.config.mqttEndpoint,clientId:this.clientId}),this.notifyStateChange(!0),this.config.enablePresence!==!1){const i=this.config.presencePayloadConnected??{connected:!0};this.client.publish(e,JSON.stringify(i),{qos:0,retain:!1}),this.debugLog("PUBLISH",{topic:e,payload:i})}l()}),this.client.on("message",(i,o)=>{this.dispatchInbound(i,o)}),this.client.on("close",()=>{this.debugLog("CLOSE",{}),this.notifyStateChange(!1),this.disposed||this.scheduleReconnect()}),this.client.on("error",i=>{this.debugLog("ERROR",{message:i.message}),this.reconnectAttempt===0&&r(i)}),this.client.on("packetsend",i=>{(i.cmd==="subscribe"||i.cmd==="unsubscribe"||i.cmd==="pingreq")&&this.debugLog(i.cmd.toUpperCase(),{topic:i.topic,packetId:i.messageId})})})}debugLog(e,t){if(!this.config.debug)return;const n={};for(const[l,r]of Object.entries(t))typeof r=="string"&&r.length>200?n[l]=`${r.slice(0,200)}…(${r.length})`:n[l]=r;console.info(`[tiledesk-mqtt] ${e}`,n)}subscribeWildcard(){if(!this.client)return;const e=this.renderTemplate(this.topics.wildcardSubscribe,{});this.subscribedTopics.has(e)||(this.client.subscribe(e,{qos:this.config.subscribeQos??2}),this.subscribedTopics.add(e))}subscribeToConversation(e){if(!this.client)return;if(this.config.wildcardSubscribe){this.subscribeWildcard();return}const t=this.renderInboundTopic(e);this.subscribedTopics.has(t)||(this.client.subscribe(t,{qos:this.config.subscribeQos??2}),this.subscribedTopics.add(t))}unsubscribeFromConversation(e){if(!this.client)return;const t=this.renderInboundTopic(e);this.subscribedTopics.has(t)&&(this.client.unsubscribe(t),this.subscribedTopics.delete(t))}publishMessage(e,t,n={}){if(!this.client)return;const l=this.buildOutgoingEnvelope(e,{text:t,type:"text",...n});this.publishEnvelope(e,l)}publishFileMessage(e,t){if(!this.client)return;const n={...oh,...this.config.fileTemplate??{},...lh(t)},l={metadata:{contentType:"300",templateId:n.templateId,payload:{...n.headerImgSrc?{headerImgSrc:n.headerImgSrc}:{},elements:[{description:t.description??t.fileName,action:{url:t.fileUrl,type:n.type??"link",isDeepLink:n.isDeepLink??!0}}]},...t.metadata??{}}},r={fileMessage:!0,...t.cloudFileId?{cloudFileId:t.cloudFileId}:{},...t.attributes??{}},i=this.buildOutgoingEnvelope(e,{text:JSON.stringify(l),type:"html",attributes:r,metadata:l.metadata});this.publishEnvelope(e,i)}publishRaw(e,t){this.client&&this.publishEnvelope(e,t)}publishReadReceipt(e,t,n=sh){if(!this.client)return;const l=this.renderTemplate(this.topics.inboundUpdate,{conversationId:e,messageId:t});this.client.publish(l,JSON.stringify({status:n}),{qos:this.config.publishQos??0,retain:!1})}publishChatInitiated(e,t={}){if(!this.client)return;const n=this.buildOutgoingEnvelope(e,{text:"CHAT_INITIATED",type:"text",attributes:{subtype:"info",...t}});this.publishEnvelope(e,n)}onMessage(e){return this.messageHandlers.push(e),()=>{this.messageHandlers=this.messageHandlers.filter(t=>t!==e)}}onStateChange(e){return this.stateHandlers.push(e),()=>{this.stateHandlers=this.stateHandlers.filter(t=>t!==e)}}onStatusUpdate(e){return this.statusUpdateHandlers.push(e),()=>{this.statusUpdateHandlers=this.statusUpdateHandlers.filter(t=>t!==e)}}disconnect(){this.disposed=!0,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.client&&(this.subscribedTopics.forEach(e=>this.client.unsubscribe(e)),this.subscribedTopics.clear(),this.client.end(!0),this.client=null),this.messageHandlers=[],this.stateHandlers=[],this.statusUpdateHandlers=[]}get isConnected(){return this.client?.connected??!1}async scheduleReconnect(){if(this.reconnectAttempt>=this.maxReconnectAttempts||this.disposed)return;const e=Math.min(1e3*Math.pow(2,this.reconnectAttempt),this.reconnectMaxDelayMs);this.reconnectAttempt++,this.reconnectTimer=setTimeout(async()=>{if(!this.disposed){if(this.config.tokenProvider)try{this.currentToken=await this.config.tokenProvider()}catch{}try{await this.connect();const t=[...this.subscribedTopics];this.subscribedTopics.clear(),t.forEach(n=>{this.client&&(this.client.subscribe(n,{qos:this.config.subscribeQos??2}),this.subscribedTopics.add(n))})}catch{}}},e)}notifyStateChange(e){this.stateHandlers.forEach(t=>t(e))}dispatchInbound(e,t){const n=t.toString();let l=null;try{l=JSON.parse(n)}catch{this.debugLog("RECV (non-json)",{topic:e,raw:n});return}if(!l)return;this.debugLog("RECV",{topic:e,sender:l.sender,type:l.type,contentType:l.metadata?.contentType,templateId:l.metadata?.templateId,messageId:l.message_id,text:typeof l.text=="string"?l.text:void 0});const r=e.match(this.inboundUpdateRegex);if(r){const a=r.groups?.conversationId??"",c=r.groups?.messageId??"",d=typeof l.status=="number"?l.status:Number(l.status??0),p={conversationId:a,messageId:c,status:d,raw:l};this.statusUpdateHandlers.forEach(y=>y(p)),this.messageHandlers.forEach(y=>y(l,{topic:e,conversationId:a,messageId:c,kind:"update"}));return}const i=e.match(this.inboundRegex),o=i?.groups?.conversationId,s={topic:e,conversationId:o,messageId:typeof l.message_id=="string"?l.message_id:void 0,kind:i?"clientadded":"unknown"};this.messageHandlers.forEach(a=>a(l,s))}buildOutgoingEnvelope(e,t){const n={...ah,...this.config.messageDefaults??{}},l=this.config.senderFullname??this.config.userName??this.config.userId,r=this.config.recipientFullnameResolver?.(e),i={projectId:this.config.projectId,...n.departmentId?{departmentId:n.departmentId}:{},...this.config.userName?{userFullname:this.config.userName}:{},...n.channel?{channel:n.channel}:{},...n.requestChannel?{request_channel:n.requestChannel}:{},...n.attributes??{},...t.attributes??{}};return{type:"text",sender:this.config.userId,sender_fullname:l,senderFullname:l,recipient:e,...r?{recipient_fullname:r}:{},...n.channelType?{channel_type:n.channelType}:{},...n.medium?{medium:n.medium}:{},...n.platform?{platform:n.platform}:{},app_id:this.appId,timestamp:Date.now(),...t,attributes:i}}publishEnvelope(e,t){if(!this.client)return;const n=this.renderOutboundTopic(e);this.client.publish(n,JSON.stringify(t),{qos:this.config.publishQos??0,retain:this.config.publishRetain??!1}),this.debugLog("SEND",{topic:n,type:t.type,sender:t.sender,text:typeof t.text=="string"?t.text:void 0,contentType:t.metadata?.contentType,templateId:t.metadata?.templateId})}renderInboundTopic(e){return this.renderTemplate(this.topics.inbound,{conversationId:e})}renderOutboundTopic(e){return this.renderTemplate(this.topics.outbound,{conversationId:e})}renderPresenceTopic(){return this.renderTemplate(this.topics.presence,{})}renderTemplate(e,t){const n={appId:this.appId,userId:this.config.userId,projectId:this.config.projectId,clientId:this.clientId,...t};return e.replace(/\{(\w+)\}/g,(l,r)=>n[r]??"")}buildTopicRegex(e,t){const n=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/\\\{(\w+)\\\}/g,(l,r)=>{const i={appId:this.appId,userId:this.config.userId,projectId:this.config.projectId,clientId:this.clientId};if(t.includes(r))return`(?<${r}>[^/]+)`;const o=i[r];return o?o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"):"[^/]+"});return new RegExp(`^${n}$`)}}function lh(u){const e={};for(const[t,n]of Object.entries(u))n!==void 0&&(e[t]=n);return e}function ul(u,e){return(u.sender??"").toString()===e}function cl(u,e){const t=(u.sender??"").toString(),n=e.systemSenders??["metadata","system"],l=e.botSenderPrefix??"bot_";return t?t===e.userId?"user":t.startsWith(l)?"assistant":n.includes(t)?"system":"agent":"system"}function as(u){const e={raw:u},t=u.metadata;if(t&&typeof t=="object"&&(typeof t.contentType=="string"&&(e.contentType=t.contentType),typeof t.templateId=="string"&&(e.templateId=t.templateId),t.payload!==void 0&&(e.payload=t.payload)),typeof u.text=="string"&&u.text.trim().startsWith("{"))try{const n=JSON.parse(u.text);typeof n.message=="string"&&(e.innerMessage=n.message);const l=n.metadata;l&&typeof l=="object"&&(!e.contentType&&typeof l.contentType=="string"&&(e.contentType=l.contentType),!e.templateId&&typeof l.templateId=="string"&&(e.templateId=l.templateId),e.payload===void 0&&l.payload!==void 0&&(e.payload=l.payload))}catch{}return e}function hl(u){const e=as(u);if(e.contentType!=="300")return null;const t=e.payload,n=t&&Array.isArray(t.elements)?t.elements:null;if(!n||n.length===0)return null;const l=n[0],r=l.action,i=r&&typeof r.url=="string"?r.url:void 0,o=typeof l.description=="string"?l.description:void 0,s=u.attributes,a=s&&typeof s.cloudFileId=="string"?s.cloudFileId:void 0;return!i&&!o?null:{fileName:o,fileUrl:i,cloudFileId:a,templateId:e.templateId}}function So(u,e,t){const n=cl(u,t),l=as(u),r=hl(u);let i="";l.innerMessage?i=l.innerMessage:typeof u.text=="string"&&(u.text.trim().startsWith("{")?l.contentType!=="300"&&(i=u.text):i=u.text);const o=typeof u.message_id=="string"?u.message_id:`td_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,s=typeof u.timestamp=="number"?new Date(u.timestamp).toISOString():new Date().toISOString(),a=n==="assistant"?"assistant":n==="agent"?"agent":n==="system"?"system":"user",c=typeof u.status=="number"?uh(u.status):"delivered",d={id:o,externalId:o,conversationId:e,role:a,content:i,createdAt:s,status:c,metadata:{sender:u.sender,sender_fullname:u.sender_fullname??u.senderFullname,app_id:u.app_id,attributes:u.attributes}};return l.contentType&&(d.template={contentType:l.contentType,templateId:l.templateId,payload:l.payload}),r?.fileUrl&&(d.attachments=[{fileName:r.fileName??"file",fileUrl:r.fileUrl,cloudFileId:r.cloudFileId}]),{message:d,template:l}}function uh(u){return u<0?"error":u>=250?"read":u>=150?"delivered":"sent"}class fl extends Ki{connection=null;tiledesk=null;api;messageStore;conversationManager;subscription=null;config;mode;uploadAdapter;historyAdapter;tiledeskUnsubs=[];constructor(e,t){super(),this.config=e,this.mode=e.transport??"aikaara",this.uploadAdapter=t?.uploadAdapter??null,this.historyAdapter=t?.historyAdapter??null,this.api=new To(e.baseUrl,e.userToken,e.apiKey,e.authToken),this.messageStore=new Co,this.conversationManager=new Oo(e.conversationId),this.usesAikaara()&&(this.connection=new Io(e),this.connection.on("connection:state",n=>{this.emit("connection:state",n),this.config.onConnectionStateChange?.(n)}),this.connection.on("error",n=>{this.emit("error",n),this.config.onError?.(n)})),this.usesTiledesk()&&this.initTiledeskTransport()}usesAikaara(){return this.mode==="aikaara"||this.mode==="dual"}usesTiledesk(){return this.mode==="tiledesk"||this.mode==="dual"}initTiledeskTransport(){const e=this.config.tiledesk,t=this.config.tiledeskIdentity;if(!e)throw new Error("AikaaraChatClient: tiledesk transport requires `config.tiledesk` (TiledeskTransportConfig)");if(!t?.userId)throw new Error("AikaaraChatClient: tiledesk transport requires `config.tiledeskIdentity.userId`");this.tiledesk=new ll({...e,userId:t.userId,userName:t.userName??e.userName,senderFullname:t.senderFullname??e.senderFullname,messageDefaults:{...e.messageDefaults,departmentId:t.departmentId??e.messageDefaults?.departmentId}}),this.tiledeskUnsubs.push(this.tiledesk.onStateChange(n=>{const l=n?"connected":"disconnected";this.emit("connection:state",l),this.config.onConnectionStateChange?.(l)})),this.tiledeskUnsubs.push(this.tiledesk.onMessage((n,l)=>this.handleTiledeskMessage(n,l))),this.tiledeskUnsubs.push(this.tiledesk.onStatusUpdate(n=>this.handleTiledeskStatusUpdate(n)))}async connect(){if(this.usesAikaara()&&this.connection){if(await this.connection.connect(),!this.conversationManager.conversationId){const e=await this.api.createConversation({systemPromptId:this.config.systemPromptId,channel:this.config.channel||"widget",extUid:this.config.extUid});this.conversationManager.conversationId=String(e.id)}this.subscription=await this.connection.subscribeToConversation(this.conversationManager.conversationId),this.subscription.onReceived(e=>{this.handleBroadcast(e)}),await this.loadHistory()}if(this.usesTiledesk()&&this.tiledesk){await this.tiledesk.connect(),this.config.tiledesk?.wildcardSubscribe??!0?this.tiledesk.subscribeWildcard():this.conversationManager.conversationId&&this.tiledesk.subscribeToConversation(this.conversationManager.conversationId);const t=this.conversationManager.conversationId;if(t){const n=await this.hydrateTiledeskHistory(t),l=this.config.tiledesk?.autoInitiateOnEmpty??!0;n==="empty"&&l&&this.tiledesk.publishChatInitiated(t,this.config.tiledesk?.chatInitiatedAttributes??{})}}}async hydrateTiledeskHistory(e){if(!this.historyAdapter)return"unknown";const t=this.config.tiledeskIdentity?.userId??"";let n;try{n=await this.historyAdapter.fetchMessages(e,{userId:t,appId:this.config.tiledesk?.appId,projectId:this.config.tiledesk?.projectId})}catch(o){return this.config.onError?.(o instanceof Error?o:new Error(String(o))),"unknown"}if(!n.length)return"empty";const l=n.map(o=>So(o,e,{userId:t}).message).sort((o,s)=>new Date(o.createdAt).getTime()-new Date(s.createdAt).getTime()),r=this.messageStore.messages,i=[...l,...r.filter(o=>!l.some(s=>s.externalId&&s.externalId===o.externalId))];if(this.messageStore.setMessages(i),this.config.onMessage)for(const o of l)try{this.config.onMessage(o)}catch(s){console.warn("[aikaara-chat-sdk] onMessage threw on history replay",s)}return"has-history"}async sendMessage(e,t={}){const n=this.conversationManager.conversationId;if(!n)throw new Error("No active conversation");const l=this.messageStore.addOptimistic("user",e,n);this.emit("message:sent",l),this.config.onMessage?.(l);const r={};if(t.attributes&&(r.attributes=t.attributes),t.metadata&&(r.metadata=t.metadata),this.mode==="tiledesk"&&this.tiledesk){this.tiledesk.publishMessage(n,e,r);return}this.mode==="dual"&&this.tiledesk&&this.tiledesk.publishMessage(n,e,r),this.usesAikaara()&&this.connection&&this.connection.sendMessage(n,e)}async sendFile(e,t){if(!this.uploadAdapter)throw new Error("AikaaraChatClient: sendFile requires an UploadAdapter");const n=this.conversationManager.conversationId;if(!n)throw new Error("No active conversation");const l=await this.uploadAdapter.upload(e,{conversationId:n,userId:this.config.tiledeskIdentity?.userId??this.config.userToken,projectId:this.config.tiledesk?.projectId,appId:this.config.tiledesk?.appId});if(this.usesTiledesk()&&this.tiledesk){const r={fileName:l.fileName,fileUrl:l.url,cloudFileId:l.cloudFileId};this.tiledesk.publishFileMessage(n,r)}t?.caption&&await this.sendMessage(t.caption)}initiateTiledeskChat(e={}){const t=this.conversationManager.conversationId;!this.tiledesk||!t||this.tiledesk.publishChatInitiated(t,e)}markTiledeskRead(e){const t=this.conversationManager.conversationId;!this.tiledesk||!t||this.tiledesk.publishReadReceipt(t,e)}setUploadAdapter(e){this.uploadAdapter=e}async sendUserEvent(e,t,n){const l=this.conversationManager.conversationId;if(!l)throw new Error("No active conversation");this.connection&&this.connection.sendUserEvent(l,e,t,n)}async loadHistory(){const e=this.conversationManager.conversationId;if(!e)return[];try{const t=await this.api.getMessages(e);return this.messageStore.setMessages(t),t}catch{return[]}}get messages(){return this.messageStore.messages}get conversationId(){return this.conversationManager.conversationId}get isConnected(){if(this.mode==="tiledesk")return this.tiledesk?.isConnected??!1;if(this.mode==="dual"){const e=this.connection?.connectionState==="connected",t=this.tiledesk?.isConnected??!1;return e&&t}return this.connection?.connectionState==="connected"}async setContext(e){const t=this.conversationManager.conversationId;t&&await this.api.updateContext(t,{current_page:e.currentPage,entity_type:e.entityType,entity_id:e.entityId,project_id:e.projectId,available_routes:e.availableRoutes,custom_context:e.custom})}async disconnect(){this.subscription&&(this.subscription=null),this.connection&&await this.connection.disconnect(),this.tiledesk&&(this.tiledeskUnsubs.forEach(e=>e()),this.tiledeskUnsubs=[],this.tiledesk.disconnect(),this.tiledesk=null)}handleTiledeskMessage(e,t){if(t.kind==="update")return;const n=t.conversationId??this.conversationManager.conversationId;if(!n)return;const l=this.config.tiledeskIdentity?.userId??"",{message:r,template:i}=So(e,n,{userId:l,systemSenders:this.config.tiledesk?.messageDefaults?.attributes?.systemSenders});if(this.mode==="dual"&&r.role==="assistant")return;if(ul(e,l)){const a=this.messageStore.reconcileOptimistic(r);if(a){this.emit("message:updated",a);return}}const{message:o,deduped:s}=this.messageStore.upsertRemoteMessage(r);if(s?this.emit("message:updated",o):(this.emit("message:received",o),this.config.onMessage?.(o)),i.contentType){const a={messageId:o.id,conversationId:n,role:r.role==="tool"?"system":r.role,contentType:i.contentType,templateId:i.templateId,payload:i.payload,innerMessage:i.innerMessage,raw:e};this.config.onTemplateMessage?.(a)}}handleTiledeskStatusUpdate(e){e.status>=250?this.messageStore.updateMessageStatus(e.messageId,"read"):e.status>=150&&this.messageStore.updateMessageStatus(e.messageId,"delivered")}parseActionResult(e){try{const t=typeof e=="string"?JSON.parse(e):e;if(!t||typeof t!="object")return;t.navigate_to?this.emit("action:navigate",t):t.action==="edit_entity"?this.emit("action:edit_entity",t):t.action==="save_entity"?this.emit("action:save_entity",t):t.action==="test_tool"&&this.emit("action:test_tool",t)}catch{}}handleBroadcast(e){const t=this.conversationManager.conversationId;switch(e.type){case"status":{const n=e.status;this.emit("status",n),this.config.onStatusChange?.(n),n==="processing"&&this.emit("typing:start",void 0);break}case"error":{const n=new Error(e.message||"Unknown error");this.emit("error",n),this.config.onError?.(n);break}case"message_start":{if(e.role==="assistant"){const n=this.messageStore.addStreamingMessage(t);this.emit("stream:start",{messageId:n.id}),this.emit("typing:start",void 0)}break}case"message_update":{const n=e.delta||"",l=e.content||"";l?this.messageStore.updateStreaming(l):n&&this.messageStore.appendToStreaming(n);const r=this.messageStore.streamingContent;this.emit("stream:update",{delta:n,content:r}),this.config.onStreamUpdate?.(n,r);break}case"message_end":{const n=e.usage,l=this.messageStore.finalizeStreaming(n?{tokensInput:n.tokens_input||0,tokensOutput:n.tokens_output||0}:void 0);this.emit("typing:stop",void 0),l&&(this.emit("stream:end",{messageId:l.id,usage:n?{tokensInput:n.tokens_input||0,tokensOutput:n.tokens_output||0}:void 0}),this.emit("message:received",l),this.config.onMessage?.(l));break}case"message_queued":{const n=this.messageStore.messages.findLast(l=>l.status==="sending");n&&this.messageStore.confirmOptimistic(n.id);break}case"tool_execution_start":{this.emit("tool:start",{toolName:e.tool_name||"",args:e.args||{}}),this.emit("status",e.type);break}case"tool_execution_end":{this.emit("tool:end",{toolName:e.tool_name||"",result:e.result,isError:!!e.is_error}),this.emit("status",e.type),this.parseActionResult(e.result);break}case"tool_execution_update":case"agent_start":case"agent_end":case"turn_start":case"turn_end":case"auto_retry_start":case"auto_retry_end":case"cancelled":this.emit("status",e.type);break}}}function $r(u,e){return u.replace(/\{(\w+)\}/g,(t,n)=>e[n]??"")}function ch(u,e){const t=e.split(".");let n=u;for(const l of t)if(n&&typeof n=="object"&&l in n)n=n[l];else return"";return typeof n=="string"?n:""}function dl(u){const e=u.signedUrlPath??"data.s3SignedUrl";return{async upload(t,n){const l=t.name||`upload-${Date.now()}`,r={fileName:l,userId:n.userId,requestId:n.conversationId,conversationId:n.conversationId},i=u.authHeader?await u.authHeader():void 0,o={accept:"application/json",...u.extraHeaders??{},...i?{authorization:i}:{}},s=$r(u.signEndpoint.includes("{")?u.signEndpoint:`${u.signEndpoint}?fileName={fileName}`,r),a=await fetch(s,{method:u.signMethod??"GET",headers:o});if(!a.ok)throw new Error(`Sign request failed: ${a.status}`);const c=await a.json().catch(()=>({})),d=ch(c,e);if(!d)throw new Error(`Sign response missing path "${e}"`);const p=u.s3HostRewrite?d.replace(/^https:\/\/[^/]+/i,u.s3HostRewrite):d,y=await fetch(p,{method:"PUT",headers:{"content-type":t.type||"application/octet-stream"},body:t});if(!y.ok){const m=await y.text().catch(()=>"");throw new Error(`S3 PUT failed: ${y.status} ${m.slice(0,200)}`)}if(u.registerEndpoint){const m=JSON.parse($r(JSON.stringify(u.registerBody??{}),r)),b=await fetch(u.registerEndpoint,{method:"POST",headers:{...o,"content-type":"application/json"},body:JSON.stringify(m)});if(!b.ok){const _=await b.text().catch(()=>"");throw new Error(`Register failed: ${b.status} ${_.slice(0,200)}`)}}return{url:u.viewerTemplate?$r(u.viewerTemplate,r):d.split("?")[0],fileName:l,contentType:t.type,byteSize:t.size,meta:{requestId:n.conversationId}}}}}function ls(u){return{async upload(e,t){const n=new FormData,l=u.fieldName??"file";n.append(l,e,e.name);const r=typeof u.extraFields=="function"?u.extraFields(t):u.extraFields;if(r)for(const[p,y]of Object.entries(r))n.append(p,y);n.append("conversationId",t.conversationId),n.append("userId",t.userId),t.projectId&&n.append("projectId",t.projectId);const i=typeof u.headers=="function"?await u.headers():u.headers??{},o=await fetch(u.endpoint,{method:u.method??"POST",body:n,headers:i,credentials:u.credentials});if(!o.ok)throw new Error(`Upload failed: ${o.status} ${o.statusText}`);const s=await o.json().catch(()=>({}));if(u.parseResponse)return u.parseResponse(s,t);const a=s,c=a.url??a.fileUrl??a.publicUrl,d=a.fileName??a.name??e.name;if(!c)throw new Error('Upload response missing "url" / "fileUrl" / "publicUrl"');return{url:c,fileName:d,cloudFileId:typeof a.cloudFileId=="string"?a.cloudFileId:void 0,relativePath:typeof a.path=="string"?a.path:void 0,contentType:typeof a.contentType=="string"?a.contentType:void 0,byteSize:typeof a.byteSize=="number"?a.byteSize:void 0,meta:a}}}}const hh="/tilechat/{userId}/conversations/{conversationId}/messages?pageSize={pageSize}";function pl(u){const e=u.apiBase.replace(/\/$/,""),t=u.pageSize??200,n=u.pathTemplate??hh;return{async fetchMessages(l,r){const i=n.replace("{userId}",encodeURIComponent(r.userId)).replace("{conversationId}",encodeURIComponent(l)).replace("{appId}",encodeURIComponent(r.appId??"tilechat")).replace("{projectId}",encodeURIComponent(r.projectId??"")).replace("{pageSize}",String(t)),o=i.startsWith("http")?i:`${e}${i.startsWith("/")?i:`/${i}`}`,s={accept:"application/json","content-type":"application/json",...u.extraHeaders??{}};if(u.getToken){const p=await u.getToken();p&&(s.authorization=p)}const a=await fetch(o,{method:"GET",headers:s}),c=await a.json().catch(()=>null);if(u.parseResponse&&c)return u.parseResponse(c);const d=c;if(d&&Array.isArray(d.result))return d.result;if(!a.ok)throw new Error(`History fetch failed: ${a.status} ${a.statusText}`);return[]}}}class fh{client;panel;bubble;header;messageList;input;errorBanner;isOpen=!1;isEmbed=!1;constructor(e,t,n){this.client=new fl(e,{uploadAdapter:n?.uploadAdapter,historyAdapter:n?.historyAdapter}),this.isEmbed=e.display==="embed",this.bubble=t.querySelector("aikaara-chat-bubble"),this.panel=t.querySelector(".aikaara-panel"),this.header=t.querySelector("aikaara-chat-header"),this.messageList=t.querySelector("aikaara-message-list"),this.input=t.querySelector("aikaara-chat-input"),this.errorBanner=t.querySelector("aikaara-error-banner"),e.welcomeMessage&&this.messageList.setWelcomeMessage(e.welcomeMessage),e.showTimestamps!==void 0&&this.messageList.setShowTimestamps(e.showTimestamps),(e.linkHandlers||e.getLinkBearer)&&this.messageList.setLinkConfig(e.linkHandlers??[],e.getLinkBearer),this.wireEvents()}async connect(){try{await this.client.connect(),this.messageList.renderMessages(this.client.messages)}catch{this.errorBanner.show("Failed to connect. Retrying...",5e3)}}async disconnect(){await this.client.disconnect()}wireEvents(){this.bubble?.addEventListener("toggle",()=>{this.togglePanel()}),this.isEmbed||this.header.addEventListener("header-close",()=>{this.togglePanel(!1)}),this.input.addEventListener("send",(e=>{this.handleSend(e.detail.content)})),this.input.addEventListener("file-pick",(e=>{this.handleFile(e.detail.file)})),this.client.on("message:sent",e=>{this.messageList.addMessage(e)}),this.client.on("stream:start",()=>{this.messageList.removeTypingIndicator();const e=this.client.messages[this.client.messages.length-1];e&&this.messageList.addMessage(e)}),this.client.on("stream:update",({content:e})=>{this.messageList.updateStreamingContent(e)}),this.client.on("stream:end",()=>{this.messageList.finalizeStreaming()}),this.client.on("typing:start",()=>{const e=this.client.messages,t=e[e.length-1];(!t||t.status!=="streaming")&&this.messageList.showTypingIndicator()}),this.client.on("typing:stop",()=>{this.messageList.removeTypingIndicator()}),this.client.on("connection:state",e=>{this.header.setStatus(e),e==="connected"?(this.errorBanner.hide(),this.input.disabled=!1):e==="reconnecting"?(this.errorBanner.show("Connection lost. Reconnecting..."),this.input.disabled=!0):e==="disconnected"&&(this.input.disabled=!0)}),this.client.on("error",e=>{this.errorBanner.show(e.message,5e3)}),this.client.on("message:received",e=>{this.messageList.upsertMessage(e)}),this.client.on("message:updated",e=>{this.messageList.upsertMessage(e)}),this.messageList.addEventListener("message-action",e=>{const t=e.detail;if(!t?.text)return;const n=this.client.config.templateActionAttributes??{},l=t.attributes?.action??{},r={...t.attributes,action:{...n,...l}};this.handleSend(t.text,r)})}async handleSend(e,t){try{await this.client.sendMessage(e,t?{attributes:t}:void 0)}catch{this.errorBanner.show("Failed to send message",3e3)}}async handleFile(e){this.input.uploading=!0;try{await this.client.sendFile(e)}catch(t){this.errorBanner.show(t instanceof Error?`Upload failed: ${t.message}`:"Upload failed",4e3)}finally{this.input.uploading=!1}}sendUserEvent(e,t,n){this.client.sendUserEvent(e,t,n)}getClient(){return this.client}togglePanel(e){this.isEmbed||(this.isOpen=e!==void 0?e:!this.isOpen,this.isOpen?(this.panel.removeAttribute("hidden"),requestAnimationFrame(()=>{this.panel.classList.remove("entering"),this.panel.classList.add("visible"),this.input.focus()})):(this.panel.classList.remove("visible"),this.panel.classList.add("entering"),setTimeout(()=>{this.panel.setAttribute("hidden","")},200)))}}class gl extends HTMLElement{shadow;controller=null;_config={};static get observedAttributes(){return["base-url","ws-url","user-token","api-key","title","subtitle","theme","primary-color","position","width","height","placeholder","welcome-message","avatar-url","display"]}constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render(),this.initController()}disconnectedCallback(){this.controller?.disconnect()}attributeChangedCallback(e,t,n){t!==n&&this.controller&&(this.render(),this.initController())}configure(e){this._config={...this._config,...e}}getConfig(){return{baseUrl:this.getAttribute("base-url")||this._config.baseUrl||"",wsUrl:this.getAttribute("ws-url")||this._config.wsUrl,userToken:this.getAttribute("user-token")||this._config.userToken||"",apiKey:this.getAttribute("api-key")||this._config.apiKey,title:this.getAttribute("title")||this._config.title||"Chat",subtitle:this.getAttribute("subtitle")||this._config.subtitle,theme:this.getAttribute("theme")||this._config.theme||Gl,primaryColor:this.getAttribute("primary-color")||this._config.primaryColor||cs,position:this.getAttribute("position")||this._config.position||Vl,width:Number(this.getAttribute("width"))||this._config.width||ql,height:Number(this.getAttribute("height"))||this._config.height||Hl,fontFamily:this._config.fontFamily||Kl,borderRadius:this._config.borderRadius??zl,placeholder:this.getAttribute("placeholder")||this._config.placeholder||hs,welcomeMessage:this.getAttribute("welcome-message")||this._config.welcomeMessage,avatarUrl:this.getAttribute("avatar-url")||this._config.avatarUrl,showTimestamps:this._config.showTimestamps??!0,persistConversation:this._config.persistConversation??!0,showHeader:this._config.showHeader??!0,hideSystemMessages:this._config.hideSystemMessages,timestampFormat:this._config.timestampFormat,input:this._config.input,templateLayout:this._config.templateLayout,showBubble:this._config.showBubble??!0,display:(this.getAttribute("display")||this._config.display)??"popup",offset:this._config.offset||Yl,conversationId:this._config.conversationId,systemPromptId:this._config.systemPromptId,channel:this._config.channel,extUid:this._config.extUid,transport:this._config.transport,tiledesk:this._config.tiledesk,tiledeskIdentity:this._config.tiledeskIdentity,onMessage:this._config.onMessage,onStatusChange:this._config.onStatusChange,onError:this._config.onError,onStreamUpdate:this._config.onStreamUpdate,onConnectionStateChange:this._config.onConnectionStateChange,onTemplateMessage:this._config.onTemplateMessage,themeTokens:this._config.themeTokens,linkHandlers:this._config.linkHandlers,getLinkBearer:this._config.getLinkBearer}}propagateThemeToDocument(e,t,n,l){if(typeof document>"u")return;const r=document.documentElement,i=(o,s)=>{s!==void 0&&s!==""&&r.style.setProperty(`--aikaara-${o}`,s)};i("primary",e?.primary??t),i("primary-hover",e?.primaryHover),i("primary-contrast",e?.primaryContrast),i("surface",e?.surface),i("surface-muted",e?.surfaceMuted),i("border",e?.border),i("text",e?.text),i("text-muted",e?.textMuted),i("font",e?.font??l),i("radius",e?.radius!=null?`${e.radius}px`:n!=null?`${n}px`:void 0),i("bubble-radius",e?.bubbleRadius!=null?`${e.bubbleRadius}px`:void 0),i("button-radius",e?.buttonRadius!=null?`${e.buttonRadius}px`:void 0),i("user-bubble-bg",e?.userBubbleBg),i("user-bubble-text",e?.userBubbleText),i("bot-bubble-bg",e?.botBubbleBg),i("bot-bubble-text",e?.botBubbleText),i("modal-width",e?.modalWidth),i("modal-height",e?.modalHeight),i("modal-max-width",e?.modalMaxWidth),i("modal-max-height",e?.modalMaxHeight),i("modal-padding",e?.modalPadding)}themeVars(e){if(!e)return"";const t=l=>typeof l=="number"?`${l}px`:void 0,n={primary:e.primary,"primary-hover":e.primaryHover,"primary-contrast":e.primaryContrast,surface:e.surface,"surface-muted":e.surfaceMuted,border:e.border,text:e.text,"text-muted":e.textMuted,font:e.font,radius:t(e.radius),"bubble-radius":t(e.bubbleRadius),"button-radius":t(e.buttonRadius),"user-bubble-bg":e.userBubbleBg,"user-bubble-text":e.userBubbleText,"bot-bubble-bg":e.botBubbleBg,"bot-bubble-text":e.botBubbleText,"modal-width":e.modalWidth,"modal-height":e.modalHeight,"modal-max-width":e.modalMaxWidth,"modal-max-height":e.modalMaxHeight,"modal-padding":e.modalPadding};return Object.entries(n).filter(([,l])=>l!==void 0&&l!=="").map(([l,r])=>`--aikaara-${l}: ${r};`).join(`
|
|
9
|
-
`)}setUploadAdapter(e){this._config.uploadAdapter=e,this.controller?.getClient().setUploadAdapter(e)}setHistoryAdapter(e){this._config.historyAdapter=e}render(){const e=this.getConfig(),t=e.display==="embed";this.propagateThemeToDocument(e.themeTokens,e.primaryColor,e.borderRadius,e.fontFamily);const n=`
|
|
10
|
-
font-family: var(--aikaara-font);
|
|
11
|
-
position: fixed;
|
|
12
|
-
z-index: 9999;
|
|
13
|
-
bottom: var(--aikaara-offset-y);
|
|
14
|
-
${e.position==="bottom-left"?"left":"right"}: var(--aikaara-offset-x);
|
|
15
|
-
`,l=`
|
|
16
|
-
font-family: var(--aikaara-font);
|
|
17
|
-
display: flex;
|
|
18
|
-
flex-direction: column;
|
|
19
|
-
width: 100%;
|
|
20
|
-
height: 100%;
|
|
21
|
-
min-height: var(--aikaara-embed-min-height, 560px);
|
|
22
|
-
`,r=`
|
|
23
|
-
width: var(--aikaara-panel-width);
|
|
24
|
-
height: var(--aikaara-panel-height);
|
|
25
|
-
max-height: calc(100vh - 100px);
|
|
26
|
-
border-radius: var(--aikaara-radius);
|
|
27
|
-
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
|
|
28
|
-
border: 1px solid var(--aikaara-border);
|
|
29
|
-
position: absolute;
|
|
30
|
-
bottom: calc(var(--aikaara-bubble-size) + 16px);
|
|
31
|
-
${e.position==="bottom-left"?"left":"right"}: 0;
|
|
32
|
-
transition: opacity 200ms ease, transform 200ms ease;
|
|
33
|
-
`,i=`
|
|
34
|
-
width: 100%;
|
|
35
|
-
flex: 1 1 auto;
|
|
36
|
-
min-height: 0;
|
|
37
|
-
border-radius: var(--aikaara-radius);
|
|
38
|
-
border: 1px solid var(--aikaara-border);
|
|
39
|
-
position: relative;
|
|
40
|
-
`;this.shadow.innerHTML=`
|
|
41
|
-
<style>
|
|
42
|
-
:host {
|
|
43
|
-
--aikaara-primary: ${e.primaryColor};
|
|
44
|
-
--aikaara-primary-hover: ${this.darkenColor(e.primaryColor||cs)};
|
|
45
|
-
--aikaara-bg: #ffffff;
|
|
46
|
-
--aikaara-bg-secondary: #f9fafb;
|
|
47
|
-
--aikaara-text: #1f2937;
|
|
48
|
-
--aikaara-text-secondary: #6b7280;
|
|
49
|
-
--aikaara-border: #e5e7eb;
|
|
50
|
-
--aikaara-radius: ${e.borderRadius}px;
|
|
51
|
-
--aikaara-font: ${e.fontFamily};
|
|
52
|
-
--aikaara-panel-width: ${e.width}px;
|
|
53
|
-
--aikaara-panel-height: ${e.height}px;
|
|
54
|
-
--aikaara-bubble-size: 60px;
|
|
55
|
-
--aikaara-offset-x: ${e.offset?.x??20}px;
|
|
56
|
-
--aikaara-offset-y: ${e.offset?.y??20}px;
|
|
57
|
-
${this.themeVars(e.themeTokens)}
|
|
58
|
-
${t?l:n}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
.aikaara-panel {
|
|
62
|
-
background: var(--aikaara-bg);
|
|
63
|
-
display: flex;
|
|
64
|
-
flex-direction: column;
|
|
65
|
-
overflow: hidden;
|
|
66
|
-
${t?i:r}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
.aikaara-panel[hidden] {
|
|
70
|
-
display: none;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
.aikaara-panel.entering {
|
|
74
|
-
opacity: 0;
|
|
75
|
-
transform: translateY(8px) scale(0.98);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
.aikaara-panel.visible {
|
|
79
|
-
opacity: 1;
|
|
80
|
-
transform: translateY(0) scale(1);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
aikaara-chat-header,
|
|
84
|
-
aikaara-message-list,
|
|
85
|
-
aikaara-chat-input,
|
|
86
|
-
aikaara-error-banner {
|
|
87
|
-
display: block;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
aikaara-message-list {
|
|
91
|
-
flex: 1;
|
|
92
|
-
overflow: scroll;
|
|
93
|
-
min-height: 0;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
aikaara-chat-input { flex-shrink: 0; }
|
|
97
|
-
aikaara-chat-header { flex-shrink: 0; }
|
|
98
|
-
</style>
|
|
99
|
-
|
|
100
|
-
${t?"":"<aikaara-chat-bubble></aikaara-chat-bubble>"}
|
|
101
|
-
|
|
102
|
-
<div class="aikaara-panel ${t?"visible":"entering"}" ${t?"":"hidden"} role="${t?"region":"dialog"}" aria-label="Chat">
|
|
103
|
-
${e.showHeader===!1?"":`<aikaara-chat-header
|
|
104
|
-
title="${e.title||"Chat"}"
|
|
105
|
-
${e.subtitle?`subtitle="${e.subtitle}"`:""}
|
|
106
|
-
${e.avatarUrl?`avatar-url="${e.avatarUrl}"`:""}
|
|
107
|
-
></aikaara-chat-header>`}
|
|
108
|
-
<aikaara-message-list></aikaara-message-list>
|
|
109
|
-
<aikaara-chat-input
|
|
110
|
-
placeholder="${e.placeholder||hs}"
|
|
111
|
-
${this._config.uploadAdapter?"":"disable-attach"}
|
|
112
|
-
${e.input?.attachPosition==="right"?'attach-position="right"':""}
|
|
113
|
-
${e.input?.sendButtonShape==="square"?'send-shape="square"':""}
|
|
114
|
-
></aikaara-chat-input>
|
|
115
|
-
<aikaara-error-banner></aikaara-error-banner>
|
|
116
|
-
</div>
|
|
117
|
-
`;const o=this.shadow.querySelector("aikaara-message-list");if(o){e.hideSystemMessages?.length&&o.setHideSystemMessages?.(e.hideSystemMessages),e.timestampFormat&&o.setTimestampFormat?.(e.timestampFormat);const s=e.templateLayout;s&&o.setTemplateLayout?.(s)}}async initController(){const e=this.getConfig(),t=e.transport??"aikaara";(t==="aikaara"||t==="dual")&&(!e.baseUrl||!e.userToken)||(this.controller?.disconnect(),this.controller=new fh(e,this.shadow,{uploadAdapter:this._config.uploadAdapter,historyAdapter:this._config.historyAdapter}),await this.controller.connect())}sendUserEvent(e,t,n){this.controller?.sendUserEvent(e,t,n)}getClient(){return this.controller?.getClient()??null}darkenColor(e){try{const t=parseInt(e.replace("#",""),16),n=Math.max(0,(t>>16)-20),l=Math.max(0,(t>>8&255)-20),r=Math.max(0,(t&255)-20);return`#${(n<<16|l<<8|r).toString(16).padStart(6,"0")}`}catch{return e}}}class ml extends HTMLElement{shadow;constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render(),this.shadow.querySelector(".bubble")?.addEventListener("click",()=>{this.dispatchEvent(new CustomEvent("toggle",{bubbles:!0,composed:!0}))})}render(){this.shadow.innerHTML=`
|
|
118
|
-
<style>
|
|
119
|
-
.bubble {
|
|
120
|
-
width: var(--aikaara-bubble-size, 60px);
|
|
121
|
-
height: var(--aikaara-bubble-size, 60px);
|
|
122
|
-
border-radius: 50%;
|
|
123
|
-
background: var(--aikaara-primary, #6366f1);
|
|
124
|
-
color: #ffffff;
|
|
125
|
-
border: none;
|
|
126
|
-
cursor: pointer;
|
|
127
|
-
display: flex;
|
|
128
|
-
align-items: center;
|
|
129
|
-
justify-content: center;
|
|
130
|
-
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
|
131
|
-
transition: transform 200ms ease, box-shadow 200ms ease;
|
|
132
|
-
}
|
|
133
|
-
.bubble:hover {
|
|
134
|
-
transform: scale(1.05);
|
|
135
|
-
box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
|
|
136
|
-
}
|
|
137
|
-
.bubble svg {
|
|
138
|
-
width: 28px;
|
|
139
|
-
height: 28px;
|
|
140
|
-
}
|
|
141
|
-
.bubble-text {
|
|
142
|
-
font-family: var(--aikaara-font, system-ui, sans-serif);
|
|
143
|
-
font-size: 12px;
|
|
144
|
-
font-weight: 500;
|
|
145
|
-
}
|
|
146
|
-
</style>
|
|
147
|
-
<button class="bubble" aria-label="Open chat">
|
|
148
|
-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
149
|
-
<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/>
|
|
150
|
-
</svg>
|
|
151
|
-
</button>
|
|
152
|
-
`}setIcon(e){const t=this.shadow.querySelector(".bubble");t&&(t.innerHTML=e)}}class bl extends HTMLElement{shadow;static get observedAttributes(){return["title","subtitle","avatar-url","status"]}constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render(),this.bindClose()}attributeChangedCallback(){this.render(),this.bindClose()}bindClose(){this.shadow.querySelector(".close-btn")?.addEventListener("click",()=>{this.dispatchEvent(new CustomEvent("header-close",{bubbles:!0,composed:!0}))})}render(){const e=this.getAttribute("title")||"Chat",t=this.getAttribute("subtitle")||"",n=this.getAttribute("avatar-url"),l=this.getAttribute("status")||"connected",r=l==="connected"?"#10b981":l==="connecting"||l==="reconnecting"?"#f59e0b":"#ef4444";this.shadow.innerHTML=`
|
|
153
|
-
<style>
|
|
154
|
-
.header {
|
|
155
|
-
display: flex;
|
|
156
|
-
align-items: center;
|
|
157
|
-
gap: 12px;
|
|
158
|
-
padding: 14px 16px;
|
|
159
|
-
background: var(--aikaara-primary, #6366f1);
|
|
160
|
-
color: #ffffff;
|
|
161
|
-
flex-shrink: 0;
|
|
162
|
-
}
|
|
163
|
-
.avatar {
|
|
164
|
-
width: 36px;
|
|
165
|
-
height: 36px;
|
|
166
|
-
border-radius: 50%;
|
|
167
|
-
background: rgba(255,255,255,0.2);
|
|
168
|
-
display: flex;
|
|
169
|
-
align-items: center;
|
|
170
|
-
justify-content: center;
|
|
171
|
-
flex-shrink: 0;
|
|
172
|
-
overflow: hidden;
|
|
173
|
-
}
|
|
174
|
-
.avatar img {
|
|
175
|
-
width: 100%;
|
|
176
|
-
height: 100%;
|
|
177
|
-
object-fit: cover;
|
|
178
|
-
}
|
|
179
|
-
.avatar svg {
|
|
180
|
-
width: 20px;
|
|
181
|
-
height: 20px;
|
|
182
|
-
}
|
|
183
|
-
.info {
|
|
184
|
-
flex: 1;
|
|
185
|
-
min-width: 0;
|
|
186
|
-
}
|
|
187
|
-
.title {
|
|
188
|
-
font-size: 15px;
|
|
189
|
-
font-weight: 600;
|
|
190
|
-
line-height: 1.2;
|
|
191
|
-
display: flex;
|
|
192
|
-
align-items: center;
|
|
193
|
-
gap: 6px;
|
|
194
|
-
}
|
|
195
|
-
.status-dot {
|
|
196
|
-
width: 8px;
|
|
197
|
-
height: 8px;
|
|
198
|
-
border-radius: 50%;
|
|
199
|
-
flex-shrink: 0;
|
|
200
|
-
}
|
|
201
|
-
.subtitle {
|
|
202
|
-
font-size: 12px;
|
|
203
|
-
opacity: 0.85;
|
|
204
|
-
white-space: nowrap;
|
|
205
|
-
overflow: hidden;
|
|
206
|
-
text-overflow: ellipsis;
|
|
207
|
-
}
|
|
208
|
-
.close-btn {
|
|
209
|
-
background: none;
|
|
210
|
-
border: none;
|
|
211
|
-
color: #ffffff;
|
|
212
|
-
cursor: pointer;
|
|
213
|
-
padding: 4px;
|
|
214
|
-
border-radius: 4px;
|
|
215
|
-
display: flex;
|
|
216
|
-
align-items: center;
|
|
217
|
-
justify-content: center;
|
|
218
|
-
opacity: 0.8;
|
|
219
|
-
transition: opacity 200ms;
|
|
220
|
-
}
|
|
221
|
-
.close-btn:hover {
|
|
222
|
-
opacity: 1;
|
|
223
|
-
}
|
|
224
|
-
.close-btn svg {
|
|
225
|
-
width: 20px;
|
|
226
|
-
height: 20px;
|
|
227
|
-
}
|
|
228
|
-
</style>
|
|
229
|
-
<div class="header">
|
|
230
|
-
<div class="avatar">
|
|
231
|
-
${n?`<img src="${n}" alt="Avatar" />`:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg>'}
|
|
232
|
-
</div>
|
|
233
|
-
<div class="info">
|
|
234
|
-
<div class="title">
|
|
235
|
-
${e}
|
|
236
|
-
<span class="status-dot" style="background:${r}"></span>
|
|
237
|
-
</div>
|
|
238
|
-
${t?`<div class="subtitle">${t}</div>`:""}
|
|
239
|
-
</div>
|
|
240
|
-
<button class="close-btn" aria-label="Close chat">
|
|
241
|
-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
242
|
-
<line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/>
|
|
243
|
-
</svg>
|
|
244
|
-
</button>
|
|
245
|
-
</div>
|
|
246
|
-
`}setStatus(e){this.setAttribute("status",e)}}const dh=/<\s*(br|i|b|em|strong|small|sub|sup|p|div|span|ul|ol|li|a|img|code|pre)\b/i;function Mt(u){if(dh.test(u))return u;let e=ph(u);return e=e.replace(/```(\w*)\n([\s\S]*?)```/g,(t,n,l)=>`<pre><code>${l.trim()}</code></pre>`),e=e.replace(/`([^`]+)`/g,"<code>$1</code>"),e=e.replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>"),e=e.replace(/\*(.+?)\*/g,"<em>$1</em>"),e=e.replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g,'<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>'),e=e.replace(/\n/g,"<br>"),e}function ph(u){const e={"&":"&","<":"<",">":">",'"':""","'":"'"};return u.replace(/[&<>"']/g,t=>e[t])}const gh=new Set(["p","br","hr","strong","em","b","i","u","s","small","sub","sup","code","pre","a","img","ul","ol","li","blockquote","h1","h2","h3","h4","h5","h6","span","div","table","thead","tbody","tr","th","td"]),mh={a:new Set(["href","target","rel"]),img:new Set(["src","alt","width","height"]),code:new Set(["class"]),pre:new Set(["class"]),span:new Set(["class"]),div:new Set(["class"])};function Rt(u){const e=document.createElement("template");return e.innerHTML=u,yl(e.content),e.innerHTML}function yl(u){const e=Array.from(u.childNodes);for(const t of e)if(t.nodeType===Node.ELEMENT_NODE){const n=t,l=n.tagName.toLowerCase();if(!gh.has(l)){const o=document.createTextNode(n.textContent||"");u.replaceChild(o,t);continue}const r=mh[l]||new Set,i=Array.from(n.attributes);for(const o of i)r.has(o.name)||n.removeAttribute(o.name);if(n.hasAttribute("href")){const o=n.getAttribute("href")||"";!o.startsWith("http://")&&!o.startsWith("https://")&&!o.startsWith("/")&&n.removeAttribute("href")}yl(t)}}class vl extends HTMLElement{shadow;container;welcomeMessage="";showTimestamps=!0;timestampFormat="time";hideSystemMessages=[];linkHandlers=[];getLinkBearer=null;setHideSystemMessages(e){this.hideSystemMessages=(e??[]).map(t=>t.toLowerCase())}setTimestampFormat(e){this.timestampFormat=e,e==="none"&&(this.showTimestamps=!1)}templateLayout="inside";setTemplateLayout(e){this.templateLayout=e}shouldHideMessage(e){if(!this.hideSystemMessages.length||!e)return!1;const t=e.trim().toLowerCase();return this.hideSystemMessages.some(n=>t.includes(n))}setLinkConfig(e,t){this.linkHandlers=e,this.getLinkBearer=t??null}constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.addEventListener("template-action",e=>{const t=e.detail;this.dispatchEvent(new CustomEvent("message-action",{detail:t,bubbles:!0,composed:!0}))}),this.addEventListener("click",e=>{const t=e.composedPath?.()??[],n=t.find(r=>r&&r.tagName==="A");!n||!n.href||n.dataset.noModal!==void 0||t.some(r=>{if(!r||!r.classList)return!1;const i=r.classList;return i.contains("bubble")&&i.contains("user")})||/^https?:\/\//i.test(n.href)&&(e.preventDefault(),this.handleLinkClick(n.href,n.textContent?.trim()||void 0))}),this.shadow.innerHTML=`
|
|
247
|
-
<style>
|
|
248
|
-
:host {
|
|
249
|
-
display: flex;
|
|
250
|
-
flex-direction: column;
|
|
251
|
-
min-height: 0;
|
|
252
|
-
}
|
|
253
|
-
.message-list {
|
|
254
|
-
flex: 1;
|
|
255
|
-
overflow-y: auto;
|
|
256
|
-
padding: 16px;
|
|
257
|
-
display: flex;
|
|
258
|
-
flex-direction: column;
|
|
259
|
-
gap: 8px;
|
|
260
|
-
scroll-behavior: smooth;
|
|
261
|
-
}
|
|
262
|
-
.message-list::-webkit-scrollbar { width: 6px; }
|
|
263
|
-
.message-list::-webkit-scrollbar-track { background: transparent; }
|
|
264
|
-
.message-list::-webkit-scrollbar-thumb { background: var(--aikaara-border, #e5e7eb); border-radius: 3px; }
|
|
265
|
-
.message-wrap { display: flex; flex-direction: column; }
|
|
266
|
-
.message-wrap.user { align-items: flex-end; }
|
|
267
|
-
.message-wrap.assistant,
|
|
268
|
-
.message-wrap.agent { align-items: flex-start; }
|
|
269
|
-
.message-wrap.system { align-items: center; text-align: center; }
|
|
270
|
-
.message-wrap.system .bubble {
|
|
271
|
-
background: transparent;
|
|
272
|
-
color: var(--aikaara-text-secondary, #6b7280);
|
|
273
|
-
font-size: 12px;
|
|
274
|
-
font-style: italic;
|
|
275
|
-
padding: 4px 0;
|
|
276
|
-
}
|
|
277
|
-
.attachments {
|
|
278
|
-
display: flex;
|
|
279
|
-
flex-direction: column;
|
|
280
|
-
gap: 4px;
|
|
281
|
-
margin-top: 6px;
|
|
282
|
-
}
|
|
283
|
-
.attachment {
|
|
284
|
-
display: inline-flex;
|
|
285
|
-
align-items: center;
|
|
286
|
-
gap: 6px;
|
|
287
|
-
padding: 6px 10px;
|
|
288
|
-
background: rgba(0,0,0,0.05);
|
|
289
|
-
border-radius: 8px;
|
|
290
|
-
font-size: 12px;
|
|
291
|
-
color: inherit;
|
|
292
|
-
text-decoration: none;
|
|
293
|
-
}
|
|
294
|
-
.attachment:hover { background: rgba(0,0,0,0.08); }
|
|
295
|
-
.status-tick {
|
|
296
|
-
font-size: 10px;
|
|
297
|
-
margin-left: 4px;
|
|
298
|
-
color: var(--aikaara-text-secondary, #6b7280);
|
|
299
|
-
}
|
|
300
|
-
.status-tick.read { color: var(--aikaara-primary, #6366f1); }
|
|
301
|
-
aikaara-template-renderer { display: block; margin-top: 6px; }
|
|
302
|
-
.bubble {
|
|
303
|
-
max-width: 85%;
|
|
304
|
-
padding: 10px 14px;
|
|
305
|
-
border-radius: var(--aikaara-radius, 12px);
|
|
306
|
-
font-size: 14px;
|
|
307
|
-
line-height: 1.5;
|
|
308
|
-
word-wrap: break-word;
|
|
309
|
-
overflow-wrap: break-word;
|
|
310
|
-
}
|
|
311
|
-
.bubble.user {
|
|
312
|
-
background: var(--aikaara-user-bubble-bg, var(--aikaara-primary, #6366f1));
|
|
313
|
-
color: var(--aikaara-user-bubble-text, var(--aikaara-primary-contrast, #ffffff));
|
|
314
|
-
border-bottom-right-radius: 4px;
|
|
315
|
-
}
|
|
316
|
-
.bubble.assistant, .bubble.agent {
|
|
317
|
-
background: var(--aikaara-bot-bubble-bg, var(--aikaara-bg-secondary, #f9fafb));
|
|
318
|
-
color: var(--aikaara-bot-bubble-text, var(--aikaara-text, #1f2937));
|
|
319
|
-
border-bottom-left-radius: 4px;
|
|
320
|
-
}
|
|
321
|
-
/* Tenant-style: template chips render below bubble as a sibling
|
|
322
|
-
(templateLayout='outside'). Full content width, no clamp. */
|
|
323
|
-
aikaara-template-renderer.template-outside {
|
|
324
|
-
align-self: stretch;
|
|
325
|
-
width: 100%;
|
|
326
|
-
margin-top: 8px;
|
|
327
|
-
background: transparent;
|
|
328
|
-
}
|
|
329
|
-
.bubble pre {
|
|
330
|
-
background: rgba(0,0,0,0.06);
|
|
331
|
-
padding: 8px 12px;
|
|
332
|
-
border-radius: 6px;
|
|
333
|
-
overflow-x: auto;
|
|
334
|
-
font-size: 13px;
|
|
335
|
-
margin: 8px 0;
|
|
336
|
-
}
|
|
337
|
-
.bubble code {
|
|
338
|
-
font-family: 'SF Mono', 'Fira Code', monospace;
|
|
339
|
-
font-size: 13px;
|
|
340
|
-
}
|
|
341
|
-
.bubble.assistant code:not(pre code) {
|
|
342
|
-
background: rgba(0,0,0,0.06);
|
|
343
|
-
padding: 2px 4px;
|
|
344
|
-
border-radius: 3px;
|
|
345
|
-
}
|
|
346
|
-
.bubble a { color: inherit; text-decoration: underline; }
|
|
347
|
-
.timestamp {
|
|
348
|
-
font-size: 11px;
|
|
349
|
-
color: var(--aikaara-text-secondary, #6b7280);
|
|
350
|
-
margin-top: 2px;
|
|
351
|
-
padding: 0 4px;
|
|
352
|
-
}
|
|
353
|
-
.welcome {
|
|
354
|
-
text-align: center;
|
|
355
|
-
color: var(--aikaara-text-secondary, #6b7280);
|
|
356
|
-
font-size: 14px;
|
|
357
|
-
padding: 24px 16px;
|
|
358
|
-
}
|
|
359
|
-
.streaming-cursor::after {
|
|
360
|
-
content: '\\25CF';
|
|
361
|
-
animation: blink 1s infinite;
|
|
362
|
-
margin-left: 2px;
|
|
363
|
-
font-size: 10px;
|
|
364
|
-
vertical-align: middle;
|
|
365
|
-
}
|
|
366
|
-
@keyframes blink {
|
|
367
|
-
0%, 100% { opacity: 1; }
|
|
368
|
-
50% { opacity: 0; }
|
|
369
|
-
}
|
|
370
|
-
.typing-indicator {
|
|
371
|
-
display: flex;
|
|
372
|
-
align-items: center;
|
|
373
|
-
gap: 4px;
|
|
374
|
-
padding: 10px 14px;
|
|
375
|
-
align-self: flex-start;
|
|
376
|
-
background: var(--aikaara-bot-bubble-bg, var(--aikaara-bg-secondary, #f9fafb));
|
|
377
|
-
border-radius: var(--aikaara-radius, 12px);
|
|
378
|
-
border-bottom-left-radius: 4px;
|
|
379
|
-
}
|
|
380
|
-
.typing-indicator .dot {
|
|
381
|
-
width: 6px;
|
|
382
|
-
height: 6px;
|
|
383
|
-
border-radius: 50%;
|
|
384
|
-
background: var(--aikaara-text-secondary, #6b7280);
|
|
385
|
-
animation: typing-bounce 1.4s infinite ease-in-out;
|
|
386
|
-
}
|
|
387
|
-
.typing-indicator .dot:nth-child(1) { animation-delay: 0ms; }
|
|
388
|
-
.typing-indicator .dot:nth-child(2) { animation-delay: 200ms; }
|
|
389
|
-
.typing-indicator .dot:nth-child(3) { animation-delay: 400ms; }
|
|
390
|
-
@keyframes typing-bounce {
|
|
391
|
-
0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
|
|
392
|
-
30% { transform: translateY(-4px); opacity: 1; }
|
|
393
|
-
}
|
|
394
|
-
</style>
|
|
395
|
-
<div class="message-list"></div>
|
|
396
|
-
`,this.container=this.shadow.querySelector(".message-list"),this.welcomeMessage&&this.renderMessages([])}setWelcomeMessage(e){this.welcomeMessage=e}setShowTimestamps(e){this.showTimestamps=e}renderMessages(e){if(!this.container)return;if(this.container.innerHTML="",e.length===0&&this.welcomeMessage){this.container.innerHTML=`<div class="welcome">${Rt(Mt(this.welcomeMessage))}</div>`;return}const t=this.computeConsumedIds(e);for(const n of e)this.appendMessageElement(n,t.has(n.externalId??n.id));this.scrollToBottom()}computeConsumedIds(e){const t=new Set;let n=-1;for(let l=e.length-1;l>=0;l--)if(e[l].role==="user"){n=l;break}for(let l=0;l<e.length;l++){const r=e[l];if(r.role==="user"){const i=r.metadata?.attributes?.action;i?.message_id&&t.add(i.message_id)}r.role!=="user"&&r.template?.contentType&&l<n&&t.add(r.externalId??r.id)}return t}addMessage(e){const t=this.container.querySelector(".welcome");t&&t.remove(),this.appendMessageElement(e),this.scrollToBottom()}updateStreamingContent(e){const t=this.container.querySelector('[data-streaming="true"] .bubble');t&&(t.innerHTML=Rt(Mt(e)),t.classList.add("streaming-cursor"),this.scrollToBottom())}finalizeStreaming(){const e=this.container.querySelector('[data-streaming="true"]');e&&(e.removeAttribute("data-streaming"),e.querySelector(".bubble")?.classList.remove("streaming-cursor"))}showTypingIndicator(){this.removeTypingIndicator();const e=document.createElement("div");e.classList.add("typing-indicator"),e.setAttribute("data-typing","true"),e.innerHTML='<span class="dot"></span><span class="dot"></span><span class="dot"></span>',this.container.appendChild(e),this.scrollToBottom()}removeTypingIndicator(){this.container.querySelector('[data-typing="true"]')?.remove()}appendMessageElement(e,t=!1){if(e.role==="user"&&e.content?.trim()==="CHAT_INITIATED"||this.shouldHideMessage(e.content))return;if(e.role==="system"){const s=document.createElement("div");s.classList.add("message-wrap","system"),s.dataset.messageId=e.id,e.externalId&&(s.dataset.externalId=e.externalId);const a=document.createElement("aikaara-system-pill");a.setAttribute("text",e.content||""),this.showTimestamps&&e.createdAt&&a.setAttribute("subtext",this.formatTime(e.createdAt)),s.appendChild(a),this.container.appendChild(s);return}const n=document.createElement("div");n.classList.add("message-wrap",e.role),e.status==="streaming"&&n.setAttribute("data-streaming","true"),e.externalId&&(n.dataset.externalId=e.externalId),n.dataset.messageId=e.id;const l=document.createElement("div");l.classList.add("bubble",e.role);const i=!!e.template?.contentType&&e.role!=="user";e.role==="user"?l.textContent=e.content:i?e.content&&(l.innerHTML=Rt(Mt(e.content))):(l.innerHTML=Rt(Mt(e.content||"")),e.status==="streaming"&&l.classList.add("streaming-cursor"));let o=null;if(e.template?.contentType){const s=document.createElement("aikaara-template-renderer");s.setAttribute("content-type",e.template.contentType),e.template.templateId&&s.setAttribute("template-id",e.template.templateId);const a=e.externalId??e.id;a&&s.setAttribute("message-id",a),s.setPayload(e.template.payload),t&&(s.dataset.consumed="true"),this.templateLayout==="outside"?(s.classList.add("template-outside"),o=s):l.appendChild(s)}if(e.attachments?.length){const s=document.createElement("div");s.classList.add("attachments");for(const a of e.attachments){const c=document.createElement("a");c.classList.add("attachment"),c.href=a.fileUrl,c.target="_blank",c.rel="noopener noreferrer",c.textContent=`📎 ${a.fileName}`,s.appendChild(c)}l.appendChild(s)}if(n.appendChild(l),o&&n.appendChild(o),this.showTimestamps&&e.createdAt||e.role==="user"&&e.status){const s=document.createElement("div");if(s.classList.add("timestamp"),this.showTimestamps&&e.createdAt&&(s.textContent=this.formatTime(e.createdAt)),e.role==="user"&&e.status){const a=document.createElement("span");a.classList.add("status-tick"),e.status==="read"&&a.classList.add("read"),a.textContent={sending:" ○",sent:" ✓",delivered:" ✓✓",read:" ✓✓"}[e.status]??"",s.appendChild(a)}n.appendChild(s)}this.container.appendChild(n)}upsertMessage(e){const t=this.findRenderedMessage(e);t&&t.remove(),this.appendMessageElement(e),this.scrollToBottom()}findRenderedMessage(e){if(e.externalId){const t=this.container.querySelector(`[data-external-id="${CSS.escape(e.externalId)}"]`);if(t)return t}return this.container.querySelector(`[data-message-id="${CSS.escape(e.id)}"]`)}scrollToBottom(){requestAnimationFrame(()=>{this.container.scrollTop=this.container.scrollHeight})}formatTime(e){try{const t=new Date(e);switch(this.timestampFormat){case"datetime":return`${t.toLocaleDateString(void 0,{month:"short",day:"2-digit"})}, ${t.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"})}`;case"date":return t.toLocaleDateString(void 0,{month:"short",day:"2-digit"});case"none":return"";default:return t.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"})}}catch{return""}}async handleLinkClick(e,t){const n=this.linkHandlers.find(y=>bh(e,y.match)),l=n?.target??"iframe";if(l==="tab"){window.open(e,"_blank","noopener,noreferrer");return}const r=this.getOrCreateModal(),i=n?.title??t??"Link";if(l==="iframe"||!n?.fetch||!n.render){requestAnimationFrame(()=>r.show?.(e,i));return}const o=yh(e),s=wl(n.fetch.url,o),a={accept:"application/json",...n.fetch.headers??{}},c=n.fetch.authHeader??"session";if(c!=="none"&&this.getLinkBearer){const y=await this.getLinkBearer(c);y&&(a.authorization=`Bearer ${y}`)}const d={method:n.fetch.method??"GET",headers:a};n.fetch.body&&(a["content-type"]="application/json",d.body=JSON.stringify(zi(n.fetch.body,o)));let p=null;try{const y=await fetch(s,d);y.ok&&(p=await y.json().catch(()=>null))}catch(y){console.warn("[aikaara-chat-sdk] linkHandler fetch failed",y)}requestAnimationFrame(()=>{r.showElement?.(n.render,i,y=>{const f=n.props??{setData:p};for(const[b,_]of Object.entries(f)){const g=y[b];typeof g=="function"&&g.call(y,_)}const m=b=>{const _=b,g=_.detail?.message??_.detail?.label;g&&(r.close?.(),this.dispatchEvent(new CustomEvent("message-action",{detail:{text:g,attributes:{..._.detail?.attributes??{}}},bubbles:!0,composed:!0})))};y.addEventListener("aikaara-plan-select",m),y.addEventListener("aikaara-select",m)})})}getOrCreateModal(){let e=document.querySelector("aikaara-link-modal");return e||(e=document.createElement("aikaara-link-modal"),document.body.appendChild(e)),e}}function bh(u,e){const t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&");return new RegExp("^"+t.replace(/\*/g,".*").replace(/\?/g,".")+"$","i").test(u)}function yh(u){try{const e=new URL(u),t={};return e.searchParams.forEach((n,l)=>{t[l]=n}),t}catch{return{}}}function wl(u,e){return u.replace(/\{(\w+)\}/g,(t,n)=>e[n]??"")}function zi(u,e){if(typeof u=="string")return wl(u,e);if(Array.isArray(u))return u.map(t=>zi(t,e));if(u&&typeof u=="object"){const t={};for(const[n,l]of Object.entries(u))t[n]=zi(l,e);return t}return u}class _l extends HTMLElement{shadow;templatePayload=null;attachments=[];static get observedAttributes(){return["role","content","timestamp","content-type","template-id","inner-message","message-id","status"]}constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render()}attributeChangedCallback(){this.render()}setTemplatePayload(e){this.templatePayload=e,this.render()}setAttachments(e){this.attachments=e,this.render()}render(){const e=this.getAttribute("role")||"user",t=this.getAttribute("content")||"",n=this.getAttribute("timestamp")||"",l=this.getAttribute("status")||"",r=this.getAttribute("content-type")||"",i=this.getAttribute("template-id")||"",o=this.getAttribute("inner-message")||"",s=e==="user"?document.createTextNode(t).textContent||"":Rt(Mt(t)),a=e==="user"&&l,c=l==="sending"?"○":l==="sent"?"✓":l==="delivered"||l==="read"?"✓✓":"";this.shadow.innerHTML=`
|
|
397
|
-
<style>
|
|
398
|
-
:host { display: flex; flex-direction: column; }
|
|
399
|
-
:host([role="user"]) { align-items: flex-end; }
|
|
400
|
-
:host([role="assistant"]),
|
|
401
|
-
:host([role="agent"]),
|
|
402
|
-
:host([role="system"]) { align-items: flex-start; }
|
|
403
|
-
.bubble {
|
|
404
|
-
max-width: 85%;
|
|
405
|
-
padding: 10px 14px;
|
|
406
|
-
border-radius: var(--aikaara-bubble-radius, var(--aikaara-radius, 12px));
|
|
407
|
-
font-size: 14px;
|
|
408
|
-
line-height: 1.5;
|
|
409
|
-
word-wrap: break-word;
|
|
410
|
-
}
|
|
411
|
-
.bubble.user {
|
|
412
|
-
background: var(--aikaara-user-bubble-bg, var(--aikaara-primary, #6366f1));
|
|
413
|
-
color: var(--aikaara-user-bubble-text, var(--aikaara-primary-contrast, #fff));
|
|
414
|
-
border-bottom-right-radius: 4px;
|
|
415
|
-
}
|
|
416
|
-
.bubble.assistant, .bubble.agent {
|
|
417
|
-
background: var(--aikaara-bot-bubble-bg, var(--aikaara-bg-secondary, #f9fafb));
|
|
418
|
-
color: var(--aikaara-bot-bubble-text, var(--aikaara-text, #1f2937));
|
|
419
|
-
border-bottom-left-radius: 4px;
|
|
420
|
-
}
|
|
421
|
-
.bubble.system {
|
|
422
|
-
background: transparent;
|
|
423
|
-
color: var(--aikaara-text-secondary, #6b7280);
|
|
424
|
-
font-size: 12px;
|
|
425
|
-
font-style: italic;
|
|
426
|
-
}
|
|
427
|
-
.timestamp {
|
|
428
|
-
font-size: 11px;
|
|
429
|
-
color: var(--aikaara-text-secondary, #6b7280);
|
|
430
|
-
margin-top: 2px;
|
|
431
|
-
padding: 0 4px;
|
|
432
|
-
}
|
|
433
|
-
.status {
|
|
434
|
-
font-size: 10px;
|
|
435
|
-
color: ${l==="read"?"var(--aikaara-primary, #6366f1)":"var(--aikaara-text-secondary, #6b7280)"};
|
|
436
|
-
margin-left: 4px;
|
|
437
|
-
}
|
|
438
|
-
.attachments {
|
|
439
|
-
display: flex;
|
|
440
|
-
flex-direction: column;
|
|
441
|
-
gap: 6px;
|
|
442
|
-
margin-top: 8px;
|
|
443
|
-
}
|
|
444
|
-
.attachment {
|
|
445
|
-
display: inline-flex;
|
|
446
|
-
align-items: center;
|
|
447
|
-
gap: 6px;
|
|
448
|
-
padding: 6px 10px;
|
|
449
|
-
background: rgba(0,0,0,0.05);
|
|
450
|
-
border-radius: 8px;
|
|
451
|
-
font-size: 12px;
|
|
452
|
-
color: inherit;
|
|
453
|
-
text-decoration: none;
|
|
454
|
-
max-width: 100%;
|
|
455
|
-
}
|
|
456
|
-
.attachment:hover { background: rgba(0,0,0,0.08); }
|
|
457
|
-
aikaara-template-renderer { display: block; margin-top: 6px; }
|
|
458
|
-
</style>
|
|
459
|
-
<div class="bubble ${e}">
|
|
460
|
-
<div class="content">${s}</div>
|
|
461
|
-
${r?`<aikaara-template-renderer
|
|
462
|
-
content-type="${r}"
|
|
463
|
-
template-id="${i}"
|
|
464
|
-
inner-message="${ko(o)}"
|
|
465
|
-
></aikaara-template-renderer>`:""}
|
|
466
|
-
${this.renderAttachments()}
|
|
467
|
-
</div>
|
|
468
|
-
${n||a?`
|
|
469
|
-
<div class="timestamp">
|
|
470
|
-
${n}${a?`<span class="status">${c}</span>`:""}
|
|
471
|
-
</div>
|
|
472
|
-
`:""}
|
|
473
|
-
`;const d=this.shadow.querySelector("aikaara-template-renderer");d&&this.templatePayload!==null&&d.setPayload(this.templatePayload,o),d&&d.addEventListener("template-action",p=>{this.dispatchEvent(new CustomEvent("message-action",{detail:p.detail,bubbles:!0,composed:!0}))})}renderAttachments(){return this.attachments.length?`<div class="attachments">${this.attachments.map(t=>`<a class="attachment" href="${ko(t.fileUrl)}" target="_blank" rel="noopener noreferrer">
|
|
474
|
-
📎 ${vh(t.fileName)}
|
|
475
|
-
</a>`).join("")}</div>`:""}}function ko(u){return String(u).replace(/[&<>"']/g,e=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[e])}function vh(u){return String(u).replace(/[&<>]/g,e=>({"&":"&","<":"<",">":">"})[e])}class Sl extends HTMLElement{shadow;textarea;sendBtn;attachBtn;fileInput;_disabled=!1;_uploading=!1;constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}static get observedAttributes(){return["placeholder","disable-attach","accept","multiple","attach-position","send-shape"]}connectedCallback(){const e=this.getAttribute("placeholder")||"Type a message...",t=!this.hasAttribute("disable-attach"),n=this.getAttribute("accept")??"",l=this.hasAttribute("multiple"),r=this.getAttribute("attach-position")==="right",i=this.getAttribute("send-shape")==="square",o=t?`
|
|
476
|
-
<button class="attach-btn" aria-label="Attach file" type="button">
|
|
477
|
-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
478
|
-
<path d="M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"/>
|
|
479
|
-
</svg>
|
|
480
|
-
</button>
|
|
481
|
-
<input type="file" ${n?`accept="${n}"`:""} ${l?"multiple":""} />`:"",s=`
|
|
482
|
-
<button class="send-btn" aria-label="Send message" type="button" disabled>
|
|
483
|
-
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
484
|
-
<line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/>
|
|
485
|
-
</svg>
|
|
486
|
-
</button>`,a=i?"border-radius: var(--aikaara-button-radius, 8px);":"border-radius: 50%;";this.shadow.innerHTML=`
|
|
487
|
-
<style>
|
|
488
|
-
.input-container {
|
|
489
|
-
display: flex;
|
|
490
|
-
align-items: flex-end;
|
|
491
|
-
gap: 8px;
|
|
492
|
-
padding: 12px 16px;
|
|
493
|
-
border-top: 1px solid var(--aikaara-border, #e5e7eb);
|
|
494
|
-
background: var(--aikaara-bg, #ffffff);
|
|
495
|
-
}
|
|
496
|
-
textarea {
|
|
497
|
-
flex: 1;
|
|
498
|
-
resize: none;
|
|
499
|
-
border: 1px solid var(--aikaara-border, #e5e7eb);
|
|
500
|
-
border-radius: 8px;
|
|
501
|
-
padding: 10px 12px;
|
|
502
|
-
font-family: var(--aikaara-font, system-ui, sans-serif);
|
|
503
|
-
font-size: 14px;
|
|
504
|
-
color: var(--aikaara-text, #1f2937);
|
|
505
|
-
background: var(--aikaara-bg, #ffffff);
|
|
506
|
-
outline: none;
|
|
507
|
-
min-height: 40px;
|
|
508
|
-
max-height: 120px;
|
|
509
|
-
line-height: 1.4;
|
|
510
|
-
transition: border-color 200ms ease;
|
|
511
|
-
}
|
|
512
|
-
textarea:focus { border-color: var(--aikaara-primary, #6366f1); }
|
|
513
|
-
textarea::placeholder { color: var(--aikaara-text-secondary, #6b7280); }
|
|
514
|
-
button {
|
|
515
|
-
width: 40px;
|
|
516
|
-
height: 40px;
|
|
517
|
-
border: none;
|
|
518
|
-
cursor: pointer;
|
|
519
|
-
display: flex;
|
|
520
|
-
align-items: center;
|
|
521
|
-
justify-content: center;
|
|
522
|
-
flex-shrink: 0;
|
|
523
|
-
transition: background 200ms, opacity 200ms, color 200ms;
|
|
524
|
-
font-family: inherit;
|
|
525
|
-
}
|
|
526
|
-
.attach-btn {
|
|
527
|
-
background: transparent;
|
|
528
|
-
color: var(--aikaara-text-secondary, #6b7280);
|
|
529
|
-
border-radius: 50%;
|
|
530
|
-
}
|
|
531
|
-
.attach-btn:hover {
|
|
532
|
-
background: rgba(0,0,0,0.05);
|
|
533
|
-
color: var(--aikaara-primary, #6366f1);
|
|
534
|
-
}
|
|
535
|
-
.attach-btn[data-uploading="true"] svg { animation: spin 1s linear infinite; }
|
|
536
|
-
.send-btn {
|
|
537
|
-
background: var(--aikaara-primary, #6366f1);
|
|
538
|
-
color: #ffffff;
|
|
539
|
-
${a}
|
|
540
|
-
}
|
|
541
|
-
.send-btn:hover { background: var(--aikaara-primary-hover, #4f46e5); }
|
|
542
|
-
button:disabled { opacity: 0.5; cursor: not-allowed; }
|
|
543
|
-
button svg { width: 18px; height: 18px; }
|
|
544
|
-
input[type="file"] { display: none; }
|
|
545
|
-
@keyframes spin { to { transform: rotate(360deg); } }
|
|
546
|
-
</style>
|
|
547
|
-
<div class="input-container">
|
|
548
|
-
${r?"":o}
|
|
549
|
-
<textarea rows="1" placeholder="${e}"></textarea>
|
|
550
|
-
${r?o:""}
|
|
551
|
-
${s}
|
|
552
|
-
</div>
|
|
553
|
-
`,this.textarea=this.shadow.querySelector("textarea"),this.sendBtn=this.shadow.querySelector(".send-btn"),this.attachBtn=this.shadow.querySelector(".attach-btn"),this.fileInput=this.shadow.querySelector('input[type="file"]'),this.textarea.addEventListener("input",()=>{this.autoGrow(),this.refreshSendDisabled()}),this.textarea.addEventListener("keydown",c=>{c.key==="Enter"&&!c.shiftKey&&(c.preventDefault(),this.handleSend())}),this.sendBtn.addEventListener("click",()=>this.handleSend()),this.attachBtn?.addEventListener("click",()=>{this._disabled||this._uploading||this.fileInput?.click()}),this.fileInput?.addEventListener("change",()=>{const c=this.fileInput?.files;if(c?.length){for(const d of Array.from(c))this.dispatchEvent(new CustomEvent("file-pick",{detail:{file:d},bubbles:!0,composed:!0}));this.fileInput&&(this.fileInput.value="")}})}set disabled(e){this._disabled=e,this.textarea&&(this.textarea.disabled=e),this.attachBtn&&(this.attachBtn.disabled=e||this._uploading),this.refreshSendDisabled()}get disabled(){return this._disabled}set uploading(e){this._uploading=e,this.attachBtn&&(this.attachBtn.dataset.uploading=String(e),this.attachBtn.disabled=this._disabled||e)}get uploading(){return this._uploading}focus(){this.textarea?.focus()}clear(){this.textarea&&(this.textarea.value="",this.textarea.style.height="auto",this.refreshSendDisabled())}refreshSendDisabled(){this.sendBtn&&(this.sendBtn.disabled=this._disabled||this._uploading||!this.textarea.value.trim())}handleSend(){const e=this.textarea.value.trim();!e||this._disabled||(this.dispatchEvent(new CustomEvent("send",{detail:{content:e},bubbles:!0,composed:!0})),this.clear(),this.textarea.focus())}autoGrow(){this.textarea.style.height="auto",this.textarea.style.height=Math.min(this.textarea.scrollHeight,120)+"px"}}class kl extends HTMLElement{shadow;constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.shadow.innerHTML=`
|
|
554
|
-
<style>
|
|
555
|
-
:host { display: none; }
|
|
556
|
-
:host([visible]) { display: block; }
|
|
557
|
-
.typing {
|
|
558
|
-
display: flex;
|
|
559
|
-
align-items: center;
|
|
560
|
-
gap: 4px;
|
|
561
|
-
padding: 10px 14px;
|
|
562
|
-
background: var(--aikaara-bg-secondary, #f9fafb);
|
|
563
|
-
border-radius: var(--aikaara-radius, 12px);
|
|
564
|
-
border-bottom-left-radius: 4px;
|
|
565
|
-
width: fit-content;
|
|
566
|
-
}
|
|
567
|
-
.dot {
|
|
568
|
-
width: 6px;
|
|
569
|
-
height: 6px;
|
|
570
|
-
border-radius: 50%;
|
|
571
|
-
background: var(--aikaara-text-secondary, #6b7280);
|
|
572
|
-
animation: bounce 1.4s infinite ease-in-out;
|
|
573
|
-
}
|
|
574
|
-
.dot:nth-child(1) { animation-delay: 0ms; }
|
|
575
|
-
.dot:nth-child(2) { animation-delay: 200ms; }
|
|
576
|
-
.dot:nth-child(3) { animation-delay: 400ms; }
|
|
577
|
-
@keyframes bounce {
|
|
578
|
-
0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
|
|
579
|
-
30% { transform: translateY(-4px); opacity: 1; }
|
|
580
|
-
}
|
|
581
|
-
</style>
|
|
582
|
-
<div class="typing">
|
|
583
|
-
<span class="dot"></span>
|
|
584
|
-
<span class="dot"></span>
|
|
585
|
-
<span class="dot"></span>
|
|
586
|
-
</div>
|
|
587
|
-
`}show(){this.setAttribute("visible","")}hide(){this.removeAttribute("visible")}}class El extends HTMLElement{shadow;bubble;constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.shadow.innerHTML=`
|
|
588
|
-
<style>
|
|
589
|
-
:host {
|
|
590
|
-
display: flex;
|
|
591
|
-
flex-direction: column;
|
|
592
|
-
align-items: flex-start;
|
|
593
|
-
}
|
|
594
|
-
.bubble {
|
|
595
|
-
max-width: 85%;
|
|
596
|
-
padding: 10px 14px;
|
|
597
|
-
border-radius: var(--aikaara-bubble-radius, var(--aikaara-radius, 12px));
|
|
598
|
-
border-bottom-left-radius: 4px;
|
|
599
|
-
background: var(--aikaara-bot-bubble-bg, var(--aikaara-bg-secondary, #f9fafb));
|
|
600
|
-
color: var(--aikaara-bot-bubble-text, var(--aikaara-text, #1f2937));
|
|
601
|
-
font-size: 14px;
|
|
602
|
-
line-height: 1.5;
|
|
603
|
-
word-wrap: break-word;
|
|
604
|
-
min-height: 20px;
|
|
605
|
-
}
|
|
606
|
-
.bubble pre {
|
|
607
|
-
background: rgba(0,0,0,0.06);
|
|
608
|
-
padding: 8px 12px;
|
|
609
|
-
border-radius: 6px;
|
|
610
|
-
overflow-x: auto;
|
|
611
|
-
font-size: 13px;
|
|
612
|
-
margin: 8px 0;
|
|
613
|
-
}
|
|
614
|
-
.bubble code {
|
|
615
|
-
font-family: 'SF Mono', 'Fira Code', monospace;
|
|
616
|
-
font-size: 13px;
|
|
617
|
-
}
|
|
618
|
-
.bubble code:not(pre code) {
|
|
619
|
-
background: rgba(0,0,0,0.06);
|
|
620
|
-
padding: 2px 4px;
|
|
621
|
-
border-radius: 3px;
|
|
622
|
-
}
|
|
623
|
-
.cursor::after {
|
|
624
|
-
content: '\\25CF';
|
|
625
|
-
animation: blink 1s infinite;
|
|
626
|
-
margin-left: 2px;
|
|
627
|
-
font-size: 10px;
|
|
628
|
-
vertical-align: middle;
|
|
629
|
-
}
|
|
630
|
-
@keyframes blink {
|
|
631
|
-
0%, 100% { opacity: 1; }
|
|
632
|
-
50% { opacity: 0; }
|
|
633
|
-
}
|
|
634
|
-
</style>
|
|
635
|
-
<div class="bubble cursor"></div>
|
|
636
|
-
`,this.bubble=this.shadow.querySelector(".bubble")}updateContent(e){this.bubble&&(this.bubble.innerHTML=Rt(Mt(e)),this.bubble.classList.add("cursor"))}finalize(){this.bubble?.classList.remove("cursor")}}class xl extends HTMLElement{shadow;container;dismissTimer=null;constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.shadow.innerHTML=`
|
|
637
|
-
<style>
|
|
638
|
-
.banner {
|
|
639
|
-
display: none;
|
|
640
|
-
padding: 8px 16px;
|
|
641
|
-
background: #fef2f2;
|
|
642
|
-
color: #dc2626;
|
|
643
|
-
font-size: 13px;
|
|
644
|
-
text-align: center;
|
|
645
|
-
border-top: 1px solid #fecaca;
|
|
646
|
-
}
|
|
647
|
-
.banner.visible {
|
|
648
|
-
display: block;
|
|
649
|
-
}
|
|
650
|
-
.dismiss {
|
|
651
|
-
background: none;
|
|
652
|
-
border: none;
|
|
653
|
-
color: #dc2626;
|
|
654
|
-
cursor: pointer;
|
|
655
|
-
font-size: 12px;
|
|
656
|
-
text-decoration: underline;
|
|
657
|
-
margin-left: 8px;
|
|
658
|
-
}
|
|
659
|
-
</style>
|
|
660
|
-
<div class="banner">
|
|
661
|
-
<span class="message"></span>
|
|
662
|
-
<button class="dismiss">Dismiss</button>
|
|
663
|
-
</div>
|
|
664
|
-
`,this.container=this.shadow.querySelector(".banner"),this.shadow.querySelector(".dismiss")?.addEventListener("click",()=>this.hide())}show(e,t){const n=this.container.querySelector(".message");n&&(n.textContent=e),this.container.classList.add("visible"),this.dismissTimer&&clearTimeout(this.dismissTimer),t&&(this.dismissTimer=setTimeout(()=>this.hide(),t))}hide(){this.container.classList.remove("visible"),this.dismissTimer&&(clearTimeout(this.dismissTimer),this.dismissTimer=null)}}const Wr=new Map;function wh(u){const e=Wr.get(u);if(e)return e;const t=new Promise((n,l)=>{const r=document.querySelector(`script[data-aikaara-src="${CSS.escape(u)}"]`);if(r){r.dataset.aikaaraReady==="1"?n():(r.addEventListener("load",()=>n(),{once:!0}),r.addEventListener("error",()=>l(new Error(`Failed to load ${u}`)),{once:!0}));return}const i=document.createElement("script");i.src=u,i.async=!0,i.crossOrigin="anonymous",i.dataset.aikaaraSrc=u,i.addEventListener("load",()=>{i.dataset.aikaaraReady="1",n()},{once:!0}),i.addEventListener("error",()=>{Wr.delete(u),l(new Error(`Failed to load ${u}`))},{once:!0}),document.head.appendChild(i)});return Wr.set(u,t),t}function _h(u,e=5e3){return new Promise((t,n)=>{const l=setTimeout(()=>n(new Error(`Custom element <${u}> not registered within ${e}ms`)),e);customElements.whenDefined(u).then(()=>{clearTimeout(l),t()})})}function Sh(u){const e=`template:${u}`,t=window.__aikaara_descriptor__?.components?.[e];return t&&t.kind==="iife-element"?{render:t.tag,scriptUrl:t.scriptUrl,props:t.props}:window.__aikaara_descriptor__?.templates?.[u]}class Al extends HTMLElement{shadow;payloadData=null;innerMessage="";static get observedAttributes(){return["content-type","template-id","message-id"]}constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render(),this.addEventListener("template-action",()=>{this.dataset.consumed="true"})}attributeChangedCallback(){this.render()}setPayload(e,t){this.payloadData=e,t!==void 0&&(this.innerMessage=t),this.render()}render(){const e=this.getAttribute("content-type")??"",t=this.getAttribute("template-id")??"";for(this.shadow.innerHTML=`
|
|
665
|
-
<style>
|
|
666
|
-
:host { display: block; }
|
|
667
|
-
:host([data-consumed]) ::slotted(*) { display: none !important; }
|
|
668
|
-
::slotted(*) { display: block; }
|
|
669
|
-
</style>
|
|
670
|
-
<slot></slot>
|
|
671
|
-
`;this.firstChild;)this.removeChild(this.firstChild);if(!e)return;const n=t?Sh(t):void 0,l=n?.render??(t?`aikaara-template-${t}`:`aikaara-template-${e}`);if(n?.scriptUrl&&!customElements.get(l)&&wh(n.scriptUrl).then(()=>_h(l)).then(()=>this.render()).catch(r=>console.warn(`[aikaara-template-renderer] failed to lazy-load ${n.scriptUrl}`,r)),customElements.get(l)){const r=document.createElement(l);if(n?.props){for(const[i,o]of Object.entries(n.props))if(typeof r[i]=="function")try{r[i](o)}catch(s){console.warn(`[aikaara-template-renderer] props.${i} threw on <${l}>`,s)}}r.setPayload?.(this.payloadData,this.innerMessage),this.appendChild(r);return}if(Array.isArray(this.payloadData)){const r=this.payloadData;if(r.length>0&&r.every(o=>o&&typeof o=="object"&&!Array.isArray(o)&&!("type"in o)&&!("data"in o)&&typeof o.message=="string")){const o=document.createElement("aikaara-option-list");o.setPayload({name:"quick-reply",type:"button",options:r.map(s=>{const a=typeof s.title=="string"?s.title:"",c=s.message;return{label:a||c,value:c}})}),this.appendChild(o);return}for(const o of r)this.mountField(o)}else if(this.payloadData&&typeof this.payloadData=="object"){const r=this.payloadData;typeof r.message=="string"&&(r.okLabel||r.action||r.ok)&&this.mountModal(r)}}mountField(e){if(!e||typeof e!="object")return;const t=e.type??e.data?.type;if(t==="link"){this.mountLinkButton(e);return}const n=e.data;if(n){if(t==="checkbox"||t==="radio"||t==="button"){const l=document.createElement("aikaara-option-list");l.setPayload({name:n.name??"",title:n.title,options:n.options??[],type:t}),this.appendChild(l);return}if(t==="submit"){const l=document.createElement("aikaara-submit-action"),r=this.getAttribute("message-id")??void 0;l.setPayload({name:n.name??"Submit",action:n.action??{message:n.name??"Submit"},messageId:r}),this.appendChild(l);return}t==="modal"&&this.mountModal({message:n.message??"",okLabel:n.okLabel,cancelLabel:n.cancelLabel,action:n.action})}}mountLinkButton(e){Promise.resolve().then(()=>require("./AikaaraLinkButton-VDNx7RfC.cjs")).then(({registerAikaaraLinkButton:t,AikaaraLinkButton:n})=>{t();const l=document.createElement("aikaara-link-button");l.setPayload({name:e.name??"Open",url:e.url??"",openLinkInNewTab:e.openLinkInNewTab,orderId:e.orderId,extra:Eh(e),messageId:this.getAttribute("message-id")??void 0}),this.appendChild(l)})}mountModal(e){const t=document.createElement("aikaara-modal-action");t.setPayload(e),this.appendChild(t)}}const kh=new Set(["type","url","name","openLinkInNewTab","orderId"]);function Eh(u){const e={};for(const[t,n]of Object.entries(u))kh.has(t)||(e[t]=n);return e}class Il extends HTMLElement{shadow;static get observedAttributes(){return["text","subtext"]}constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render()}attributeChangedCallback(){this.render()}render(){const e=this.getAttribute("text")??this.textContent??"",t=this.getAttribute("subtext")??"";this.shadow.innerHTML=`
|
|
672
|
-
<style>
|
|
673
|
-
:host {
|
|
674
|
-
display: flex;
|
|
675
|
-
flex-direction: column;
|
|
676
|
-
align-items: center;
|
|
677
|
-
gap: 2px;
|
|
678
|
-
padding: 6px 0;
|
|
679
|
-
}
|
|
680
|
-
.pill {
|
|
681
|
-
display: inline-block;
|
|
682
|
-
background: var(--aikaara-system-pill-bg, rgba(0,0,0,0.06));
|
|
683
|
-
color: var(--aikaara-system-pill-color, var(--aikaara-text-secondary, #6b7280));
|
|
684
|
-
padding: var(--aikaara-system-pill-padding, 6px 14px);
|
|
685
|
-
border-radius: var(--aikaara-system-pill-radius, 9999px);
|
|
686
|
-
font-size: var(--aikaara-system-pill-font-size, 12px);
|
|
687
|
-
font-weight: var(--aikaara-system-pill-font-weight, 500);
|
|
688
|
-
border: var(--aikaara-system-pill-border, none);
|
|
689
|
-
line-height: 1.3;
|
|
690
|
-
}
|
|
691
|
-
.sub {
|
|
692
|
-
font-size: 11px;
|
|
693
|
-
color: var(--aikaara-text-secondary, #9ca3af);
|
|
694
|
-
}
|
|
695
|
-
</style>
|
|
696
|
-
<span class="pill">${Eo(e)}</span>
|
|
697
|
-
${t?`<span class="sub">${Eo(t)}</span>`:""}
|
|
698
|
-
`}}function Eo(u){return String(u).replace(/[&<>]/g,e=>({"&":"&","<":"<",">":">"})[e])}class Tl extends HTMLElement{shadow;data=null;selected=new Set;constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render()}setPayload(e){this.data=e,this.selected.clear(),this.render()}getValues(){return{name:this.data?.name??"",values:[...this.selected],type:this.data?.type??"checkbox"}}toggle(e){this.data&&(this.data.type==="radio"||this.data.type==="button"?(this.selected.clear(),this.selected.add(e)):this.selected.has(e)?this.selected.delete(e):this.selected.add(e),this.data.type==="button"?this.dispatchEvent(new CustomEvent("template-action",{detail:{text:e,attributes:{action:{[this.data.name]:e}}},bubbles:!0,composed:!0})):this.dispatchEvent(new CustomEvent("option-change",{detail:this.getValues(),bubbles:!0,composed:!0})),this.render())}render(){if(!this.data){this.shadow.innerHTML="";return}const{title:e,options:t,type:n}=this.data,l=n==="checkbox";if(n==="checkbox"&&t.length===1&&(t[0]?.label??"").trim()===""&&(e??"").trim()!==""){const i=t[0],o=this.selected.has(i.value);this.shadow.innerHTML=`
|
|
699
|
-
<style>
|
|
700
|
-
:host { display: block; margin: 8px 0; }
|
|
701
|
-
.row {
|
|
702
|
-
display: flex; align-items: flex-start; gap: 10px;
|
|
703
|
-
cursor: pointer;
|
|
704
|
-
font-family: inherit;
|
|
705
|
-
color: var(--aikaara-text, #1f2937);
|
|
706
|
-
font-size: var(--aikaara-option-title-font-size, 14px);
|
|
707
|
-
line-height: 1.5;
|
|
708
|
-
}
|
|
709
|
-
.row:focus-visible { outline: 2px solid var(--aikaara-primary, #6366f1); outline-offset: 2px; border-radius: 4px; }
|
|
710
|
-
.box {
|
|
711
|
-
flex-shrink: 0;
|
|
712
|
-
width: 18px; height: 18px;
|
|
713
|
-
border: 1.5px solid var(--aikaara-primary, #6366f1);
|
|
714
|
-
border-radius: 4px;
|
|
715
|
-
margin-top: 3px;
|
|
716
|
-
background: var(--aikaara-option-bg, transparent);
|
|
717
|
-
display: grid; place-items: center;
|
|
718
|
-
transition: background 120ms, border-color 120ms;
|
|
719
|
-
}
|
|
720
|
-
.row[aria-checked="true"] .box {
|
|
721
|
-
background: var(--aikaara-primary, #6366f1);
|
|
722
|
-
border-color: var(--aikaara-primary, #6366f1);
|
|
723
|
-
}
|
|
724
|
-
.check {
|
|
725
|
-
width: 11px; height: 11px;
|
|
726
|
-
stroke: #fff;
|
|
727
|
-
opacity: 0;
|
|
728
|
-
transition: opacity 120ms;
|
|
729
|
-
}
|
|
730
|
-
.row[aria-checked="true"] .check { opacity: 1; }
|
|
731
|
-
.text { flex: 1; }
|
|
732
|
-
</style>
|
|
733
|
-
<div class="row" role="checkbox" tabindex="0" aria-checked="${o}" data-value="${xo(i.value)}">
|
|
734
|
-
<span class="box" aria-hidden="true">
|
|
735
|
-
<svg class="check" viewBox="0 0 16 16" fill="none" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
|
|
736
|
-
<path d="M3 8 L7 12 L13 4" />
|
|
737
|
-
</svg>
|
|
738
|
-
</span>
|
|
739
|
-
<span class="text">${tr(e)}</span>
|
|
740
|
-
</div>
|
|
741
|
-
`;const s=this.shadow.querySelector(".row");if(s){const a=()=>this.toggle(i.value);s.addEventListener("click",a),s.addEventListener("keydown",c=>{(c.key===" "||c.key==="Enter")&&(c.preventDefault(),a())})}return}this.shadow.innerHTML=`
|
|
742
|
-
<style>
|
|
743
|
-
:host { display: block; margin: 8px 0; }
|
|
744
|
-
.title {
|
|
745
|
-
color: var(--aikaara-option-title-color, var(--aikaara-text, #111827));
|
|
746
|
-
font-size: var(--aikaara-option-title-font-size, 14px);
|
|
747
|
-
font-weight: var(--aikaara-option-title-font-weight, 600);
|
|
748
|
-
margin-bottom: 8px;
|
|
749
|
-
}
|
|
750
|
-
.grid {
|
|
751
|
-
display: flex;
|
|
752
|
-
flex-wrap: wrap;
|
|
753
|
-
gap: var(--aikaara-option-gap, 8px);
|
|
754
|
-
}
|
|
755
|
-
button.opt {
|
|
756
|
-
background: var(--aikaara-option-bg, transparent);
|
|
757
|
-
color: var(--aikaara-option-color, var(--aikaara-text, #1f2937));
|
|
758
|
-
border: var(--aikaara-option-border, 1.5px solid var(--aikaara-primary, #6366f1));
|
|
759
|
-
border-radius: var(--aikaara-option-radius, 10px);
|
|
760
|
-
padding: var(--aikaara-option-padding, 10px 16px);
|
|
761
|
-
font-size: 14px;
|
|
762
|
-
font-family: inherit;
|
|
763
|
-
cursor: pointer;
|
|
764
|
-
transition: background 120ms, color 120ms, border-color 120ms;
|
|
765
|
-
line-height: 1.2;
|
|
766
|
-
}
|
|
767
|
-
button.opt:hover { filter: brightness(0.96); }
|
|
768
|
-
button.opt[aria-pressed="true"] {
|
|
769
|
-
background: var(--aikaara-option-selected-bg, var(--aikaara-primary, #6366f1));
|
|
770
|
-
color: var(--aikaara-option-selected-color, #fff);
|
|
771
|
-
border-color: var(--aikaara-option-selected-border, var(--aikaara-primary, #6366f1));
|
|
772
|
-
}
|
|
773
|
-
</style>
|
|
774
|
-
${e?`<div class="title">${tr(e)}</div>`:""}
|
|
775
|
-
<div class="grid" role="${l?"group":"radiogroup"}" aria-label="${tr(e??this.data.name)}">
|
|
776
|
-
${t.map(i=>`
|
|
777
|
-
<button class="opt" type="button"
|
|
778
|
-
data-value="${xo(i.value)}"
|
|
779
|
-
role="${l?"checkbox":"radio"}"
|
|
780
|
-
aria-pressed="${this.selected.has(i.value)}">
|
|
781
|
-
${tr(i.label)}
|
|
782
|
-
</button>`).join("")}
|
|
783
|
-
</div>
|
|
784
|
-
`,this.shadow.querySelectorAll("button.opt").forEach(i=>{i.addEventListener("click",()=>this.toggle(i.dataset.value||""))})}}function tr(u){return String(u).replace(/[&<>]/g,e=>({"&":"&","<":"<",">":">"})[e])}function xo(u){return String(u).replace(/[&<>"']/g,e=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[e])}class Cl extends HTMLElement{shadow;data=null;constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render()}setPayload(e){this.data=e,this.render()}collectFormValues(){const e={},t=this.closest("aikaara-template-renderer")??this.parentElement;return t&&t.querySelectorAll("aikaara-option-list").forEach(n=>{const l=n.getValues?.();l?.name&&(e[l.name]=l.values)}),e}handleClick(){if(!this.data)return;const e=this.data.action??{message:this.data.name},t=this.collectFormValues(),n={...this.data.messageId?{message_id:this.data.messageId}:{},...t};e.formAction&&(n.formAction=e.formAction),e.requestType&&(n.requestType=e.requestType),this.dispatchEvent(new CustomEvent("template-action",{detail:{text:e.message,attributes:{action:n}},bubbles:!0,composed:!0}))}render(){if(!this.data){this.shadow.innerHTML="";return}const e=this.data.name;this.shadow.innerHTML=`
|
|
785
|
-
<style>
|
|
786
|
-
:host { display: block; margin: 12px 0 4px; }
|
|
787
|
-
button {
|
|
788
|
-
font-family: inherit;
|
|
789
|
-
background: var(--aikaara-submit-bg, var(--aikaara-primary, #6366f1));
|
|
790
|
-
color: var(--aikaara-submit-color, #ffffff);
|
|
791
|
-
border: var(--aikaara-submit-border, none);
|
|
792
|
-
border-radius: var(--aikaara-submit-radius, 10px);
|
|
793
|
-
padding: var(--aikaara-submit-padding, 12px 22px);
|
|
794
|
-
font-size: var(--aikaara-submit-font-size, 14px);
|
|
795
|
-
font-weight: var(--aikaara-submit-font-weight, 600);
|
|
796
|
-
cursor: pointer;
|
|
797
|
-
transition: background 120ms, opacity 120ms;
|
|
798
|
-
}
|
|
799
|
-
button:hover { background: var(--aikaara-submit-hover-bg, var(--aikaara-primary-hover, #4f46e5)); }
|
|
800
|
-
button:disabled { opacity: var(--aikaara-submit-disabled-opacity, 0.5); cursor: not-allowed; }
|
|
801
|
-
</style>
|
|
802
|
-
<button type="button">${xh(e)}</button>
|
|
803
|
-
`,this.shadow.querySelector("button").addEventListener("click",()=>this.handleClick())}}function xh(u){return String(u).replace(/[&<>]/g,e=>({"&":"&","<":"<",">":">"})[e])}class Ol extends HTMLElement{shadow;data=null;dismissed=!1;constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render()}setPayload(e){this.data=e,this.dismissed=!1,this.render()}dismiss(){this.dismissed=!0,this.render()}handleOk(){if(!this.data)return;const e=this.data.action;this.dispatchEvent(new CustomEvent("template-action",{detail:{text:e?.message??this.data.message,attributes:{action:{confirmed:!0,requestType:e?.requestType??"postBackToBotPlatform"}}},bubbles:!0,composed:!0})),this.dismiss()}render(){if(!this.data||this.dismissed){this.shadow.innerHTML="";return}const e=this.data.okLabel??"Ok",t=this.data.cancelLabel;this.shadow.innerHTML=`
|
|
804
|
-
<style>
|
|
805
|
-
:host { all: initial; }
|
|
806
|
-
.overlay {
|
|
807
|
-
position: fixed; inset: 0;
|
|
808
|
-
background: var(--aikaara-modal-overlay-bg, rgba(15, 23, 42, 0.45));
|
|
809
|
-
display: flex; align-items: center; justify-content: center;
|
|
810
|
-
z-index: 99999;
|
|
811
|
-
font-family: var(--aikaara-font, inherit);
|
|
812
|
-
}
|
|
813
|
-
.modal {
|
|
814
|
-
background: var(--aikaara-modal-bg, #ffffff);
|
|
815
|
-
color: var(--aikaara-modal-color, #1f2937);
|
|
816
|
-
border-radius: var(--aikaara-modal-radius, 14px);
|
|
817
|
-
padding: var(--aikaara-modal-padding, 24px 28px);
|
|
818
|
-
box-shadow: var(--aikaara-modal-shadow, 0 10px 40px rgba(15, 23, 42, 0.18));
|
|
819
|
-
max-width: 360px;
|
|
820
|
-
text-align: center;
|
|
821
|
-
}
|
|
822
|
-
.msg { font-size: 14px; line-height: 1.5; margin-bottom: 18px; }
|
|
823
|
-
.actions { display: flex; gap: 10px; justify-content: center; }
|
|
824
|
-
button {
|
|
825
|
-
font-family: inherit;
|
|
826
|
-
padding: 8px 22px;
|
|
827
|
-
font-size: 13px;
|
|
828
|
-
font-weight: 500;
|
|
829
|
-
border-radius: var(--aikaara-modal-button-radius, 10px);
|
|
830
|
-
cursor: pointer;
|
|
831
|
-
border: none;
|
|
832
|
-
}
|
|
833
|
-
button.ok {
|
|
834
|
-
background: var(--aikaara-modal-button-bg, var(--aikaara-primary, #6366f1));
|
|
835
|
-
color: var(--aikaara-modal-button-color, #ffffff);
|
|
836
|
-
}
|
|
837
|
-
button.cancel {
|
|
838
|
-
background: transparent;
|
|
839
|
-
color: var(--aikaara-modal-cancel-color, var(--aikaara-text-secondary, #6b7280));
|
|
840
|
-
}
|
|
841
|
-
</style>
|
|
842
|
-
<div class="overlay" role="dialog" aria-modal="true">
|
|
843
|
-
<div class="modal">
|
|
844
|
-
<div class="msg">${qr(this.data.message)}</div>
|
|
845
|
-
<div class="actions">
|
|
846
|
-
${t?`<button class="cancel" type="button">${qr(t)}</button>`:""}
|
|
847
|
-
<button class="ok" type="button">${qr(e)}</button>
|
|
848
|
-
</div>
|
|
849
|
-
</div>
|
|
850
|
-
</div>
|
|
851
|
-
`,this.shadow.querySelector("button.ok").addEventListener("click",()=>this.handleOk()),this.shadow.querySelector("button.cancel")?.addEventListener("click",()=>this.dismiss())}}function qr(u){return String(u).replace(/[&<>]/g,e=>({"&":"&","<":"<",">":">"})[e])}class Pl extends HTMLElement{static get observedAttributes(){return["slug","user-id","user-name","user-token","department-id","config-base","api-key"]}tokenGetter;apiKey;configHeaders;identity;credentialProviders;mounted=null;mountInflight=null;connectedCallback(){this.style.display||(this.style.display="flex"),this.style.flexDirection||(this.style.flexDirection="column"),this.style.minHeight||(this.style.minHeight="0"),this.tryMount()}disconnectedCallback(){this.mounted?.destroy(),this.mounted=null}attributeChangedCallback(){this.isConnected&&(this.mounted?.destroy(),this.mounted=null,this.tryMount())}async refreshAuth(){await this.mounted?.refreshAuth()}async tryMount(){if(this.mountInflight)return this.mountInflight;const e=this.getAttribute("slug"),t=this.getAttribute("user-id");if(!e||!t)return;const n=this.getAttribute("user-token"),l=this.tokenGetter??n;if(!l){this.dispatchEvent(new CustomEvent("error",{detail:new Error("aikaara-chat: user-token attribute or tokenGetter property required")}));return}const r={...this.configHeaders??{}},i=Object.keys(r).find(a=>a.toLowerCase()==="x-api-key"),o=this.apiKey??this.getAttribute("api-key")??(i?r[i]:void 0);o&&(i&&i!=="X-Api-Key"&&delete r[i],r["X-Api-Key"]=o);const s=Object.keys(r).length>0?r:void 0;return this.mountInflight=(async()=>{try{this.mounted=await Dl({container:this,slug:e,configBase:this.getAttribute("config-base")??void 0,configHeaders:s,user:{id:t,name:this.getAttribute("user-name")??void 0,departmentId:this.getAttribute("department-id")??void 0,token:l,identity:this.identity,credentialProviders:this.credentialProviders},hooks:{onError:a=>this.dispatchEvent(new CustomEvent("error",{detail:a}))}}),this.dispatchEvent(new CustomEvent("ready",{detail:{requestId:this.mounted.requestId,fullName:this.mounted.fullName}}))}catch(a){this.dispatchEvent(new CustomEvent("error",{detail:a}))}finally{this.mountInflight=null}})(),this.mountInflight}}class Ml extends HTMLElement{shadow;root=null;iframe=null;fallbackTimer=null;constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.root||this.render()}show(e,t){if(this.root||this.render(),!this.root||!this.iframe)return;const n=this.shadow.querySelector(".modal-title");n&&(n.textContent=t||"Link"),this.swapBody("iframe"),this.iframe.src=e,this.root.classList.add("open"),this.dispatchEvent(new CustomEvent("aikaara-link-modal-open",{detail:{url:e},bubbles:!0,composed:!0})),this.fallbackTimer&&window.clearTimeout(this.fallbackTimer);let l=!1;this.iframe.addEventListener("load",()=>{l=!0},{once:!0}),this.fallbackTimer=window.setTimeout(()=>{l||(this.close(),window.open(e,"_blank","noopener,noreferrer"))},3500)}showElement(e,t,n){if(this.root||this.render(),!this.root)return;const l=this.shadow.querySelector(".modal-title");l&&(l.textContent=t||"Details"),this.swapBody("element");const r=this.shadow.querySelector(".modal-body-element");if(r){r.innerHTML="";const i=document.createElement(e);r.appendChild(i),requestAnimationFrame(()=>n?.(i))}this.root.classList.add("open"),this.dispatchEvent(new CustomEvent("aikaara-link-modal-open",{detail:{element:e},bubbles:!0,composed:!0}))}swapBody(e){if(!this.iframe)return;const t=this.shadow.querySelector(".modal-body-element");e==="iframe"?(this.iframe.style.display="",t&&(t.style.display="none")):(this.iframe.style.display="none",t&&(t.style.display=""))}close(){this.root&&(this.root.classList.remove("open"),this.iframe&&(this.iframe.src="about:blank"),this.fallbackTimer&&(window.clearTimeout(this.fallbackTimer),this.fallbackTimer=null),this.dispatchEvent(new CustomEvent("aikaara-link-modal-close",{bubbles:!0,composed:!0})))}render(){this.shadow.innerHTML=`
|
|
852
|
-
<style>
|
|
853
|
-
:host { display: block; }
|
|
854
|
-
.backdrop {
|
|
855
|
-
position: fixed; inset: 0; z-index: 10000;
|
|
856
|
-
background: rgba(0,0,0,0.45);
|
|
857
|
-
display: none; align-items: center; justify-content: center;
|
|
858
|
-
padding: var(--aikaara-modal-padding, 24px);
|
|
859
|
-
font-family: var(--aikaara-font, system-ui, sans-serif);
|
|
860
|
-
}
|
|
861
|
-
:host(.open) .backdrop, .backdrop.open { display: flex; }
|
|
862
|
-
.modal {
|
|
863
|
-
background: var(--aikaara-surface, #fff);
|
|
864
|
-
border-radius: var(--aikaara-radius, 12px);
|
|
865
|
-
width: var(--aikaara-modal-width, min(900px, 100%));
|
|
866
|
-
height: var(--aikaara-modal-height, min(720px, 90vh));
|
|
867
|
-
max-width: var(--aikaara-modal-max-width, 100%);
|
|
868
|
-
max-height: var(--aikaara-modal-max-height, 90vh);
|
|
869
|
-
display: flex; flex-direction: column;
|
|
870
|
-
overflow: hidden;
|
|
871
|
-
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
|
|
872
|
-
}
|
|
873
|
-
.modal-header {
|
|
874
|
-
display: flex; align-items: center; justify-content: space-between;
|
|
875
|
-
padding: 12px 16px;
|
|
876
|
-
background: var(--aikaara-primary, #0f2e5c);
|
|
877
|
-
color: var(--aikaara-primary-contrast, #fff);
|
|
878
|
-
font-size: 14px; font-weight: 600;
|
|
879
|
-
}
|
|
880
|
-
.modal-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
881
|
-
.modal-close {
|
|
882
|
-
background: transparent; border: none; color: inherit;
|
|
883
|
-
font-size: 22px; line-height: 1; cursor: pointer;
|
|
884
|
-
padding: 4px 8px; border-radius: 4px;
|
|
885
|
-
}
|
|
886
|
-
.modal-close:hover { background: rgba(255,255,255,0.15); }
|
|
887
|
-
iframe {
|
|
888
|
-
flex: 1; border: 0; width: 100%; height: 100%;
|
|
889
|
-
}
|
|
890
|
-
</style>
|
|
891
|
-
<div class="backdrop" part="backdrop">
|
|
892
|
-
<div class="modal" role="dialog" aria-modal="true">
|
|
893
|
-
<div class="modal-header">
|
|
894
|
-
<span class="modal-title">Link</span>
|
|
895
|
-
<button class="modal-close" aria-label="Close" type="button">×</button>
|
|
896
|
-
</div>
|
|
897
|
-
<iframe sandbox="allow-scripts allow-same-origin allow-forms allow-popups allow-top-navigation-by-user-activation" referrerpolicy="no-referrer-when-downgrade" loading="lazy"></iframe>
|
|
898
|
-
<div class="modal-body-element" style="display:none; flex:1; overflow:auto; padding:18px;"></div>
|
|
899
|
-
</div>
|
|
900
|
-
</div>
|
|
901
|
-
`,this.root=this.shadow.querySelector(".backdrop"),this.iframe=this.shadow.querySelector("iframe"),this.shadow.querySelector(".modal-close")?.addEventListener("click",()=>this.close()),this.root?.addEventListener("click",t=>{t.target===this.root&&this.close()}),document.addEventListener("keydown",t=>{t.key==="Escape"&&this.classList.contains("open")&&this.close()})}}const Ah=[{label:"Self-filing guidance"},{label:"Smart tax suggestions"},{label:"Auto-fetch 26AS / AIS"},{label:"Notice management"},{label:"Dedicated tax expert"},{label:"End-to-end filing"},{label:"Document handling"}],Ih=[{label:"DIY",match:["DIY","DIY_SALARY"],selectLabel:"Select DIY — Without Notice (₹{price}/yr)",postback:"Without Notice",features:[!0,!0,!0,!1,!1,!1,!1]},{label:"DIY + Notice",match:["NOTICE_DIY","DIY_NOTICE"],selectLabel:"Select DIY — With Notice (₹{price}/yr)",postback:"With Notice",features:[!0,!0,!0,!0,!1,!1,!1]},{label:"Assisted",match:["ASSISTED"],selectLabel:"Switch to Assisted (₹{price}/yr)",postback:"Assisted",features:[!0,!0,!0,!0,!0,!0,!0]}];class Rl extends HTMLElement{shadow;data=null;columns=Ih;features=Ah;constructor(){super(),this.shadow=this.attachShadow({mode:"open"})}connectedCallback(){this.render()}setData(e){this.data=e,this.render()}setColumns(e){this.columns=e,this.render()}setFeatures(e){this.features=e,this.render()}priceFor(e){if(!this.data?.data)return null;for(const t of this.data.data)if(e.match.includes(t.planType))return t.planMaster?.basePrice??null;return null}render(){const e=this.columns,t=this.features;this.shadow.innerHTML=`
|
|
902
|
-
<style>
|
|
903
|
-
:host {
|
|
904
|
-
display: block;
|
|
905
|
-
font-family: var(--aikaara-font, system-ui, sans-serif);
|
|
906
|
-
color: var(--aikaara-text, #0f2e5c);
|
|
907
|
-
}
|
|
908
|
-
table {
|
|
909
|
-
width: 100%;
|
|
910
|
-
border-collapse: collapse;
|
|
911
|
-
font-size: 14px;
|
|
912
|
-
border-radius: var(--aikaara-radius, 12px);
|
|
913
|
-
overflow: hidden;
|
|
914
|
-
}
|
|
915
|
-
thead th {
|
|
916
|
-
background: var(--aikaara-primary, #0f2e5c);
|
|
917
|
-
color: var(--aikaara-primary-contrast, #fff);
|
|
918
|
-
padding: 12px 14px;
|
|
919
|
-
text-align: left;
|
|
920
|
-
font-weight: 600;
|
|
921
|
-
}
|
|
922
|
-
thead th + th { text-align: center; }
|
|
923
|
-
tbody td {
|
|
924
|
-
padding: 11px 14px;
|
|
925
|
-
border-bottom: 1px solid var(--aikaara-border, #e5e7eb);
|
|
926
|
-
background: var(--aikaara-surface, #fff);
|
|
927
|
-
}
|
|
928
|
-
tbody tr:nth-child(even) td {
|
|
929
|
-
background: var(--aikaara-surface-muted, #f6fafb);
|
|
930
|
-
}
|
|
931
|
-
tbody td + td { text-align: center; }
|
|
932
|
-
.check { color: #16a34a; font-weight: 700; }
|
|
933
|
-
.cross { color: #dc2626; font-weight: 700; }
|
|
934
|
-
.price-row td { font-weight: 600; }
|
|
935
|
-
.actions {
|
|
936
|
-
display: flex; flex-direction: column; gap: 8px;
|
|
937
|
-
margin-top: 12px;
|
|
938
|
-
}
|
|
939
|
-
button.action {
|
|
940
|
-
display: flex; justify-content: space-between; align-items: center;
|
|
941
|
-
padding: 12px 14px;
|
|
942
|
-
background: var(--aikaara-primary, #0f2e5c);
|
|
943
|
-
color: var(--aikaara-primary-contrast, #fff);
|
|
944
|
-
border: none;
|
|
945
|
-
border-radius: var(--aikaara-button-radius, 8px);
|
|
946
|
-
font-size: 14px; font-weight: 600;
|
|
947
|
-
cursor: pointer;
|
|
948
|
-
width: 100%; text-align: left;
|
|
949
|
-
}
|
|
950
|
-
button.action:hover { background: var(--aikaara-primary-hover, #0a2347); }
|
|
951
|
-
button.action small { font-weight: 400; opacity: 0.8; font-size: 12px; }
|
|
952
|
-
</style>
|
|
953
|
-
<table>
|
|
954
|
-
<thead>
|
|
955
|
-
<tr>
|
|
956
|
-
<th>Feature</th>
|
|
957
|
-
${e.map(n=>`<th>${Hr(n.label)}</th>`).join("")}
|
|
958
|
-
</tr>
|
|
959
|
-
</thead>
|
|
960
|
-
<tbody>
|
|
961
|
-
${t.map((n,l)=>`
|
|
962
|
-
<tr>
|
|
963
|
-
<td>${Hr(n.label)}</td>
|
|
964
|
-
${e.map(r=>r.features[l]?'<td><span class="check">✓</span></td>':'<td><span class="cross">✕</span></td>').join("")}
|
|
965
|
-
</tr>`).join("")}
|
|
966
|
-
<tr class="price-row">
|
|
967
|
-
<td>Price (excl. GST)</td>
|
|
968
|
-
${e.map(n=>{const l=this.priceFor(n);return`<td>${l!=null?"₹"+Math.round(l):"—"}</td>`}).join("")}
|
|
969
|
-
</tr>
|
|
970
|
-
</tbody>
|
|
971
|
-
</table>
|
|
972
|
-
<div class="actions">
|
|
973
|
-
${e.map((n,l)=>{const r=this.priceFor(n),i=n.selectLabel.replace("{price}",r!=null?String(Math.round(r)):"—");return`<button class="action" data-col="${l}" type="button">
|
|
974
|
-
<span>${Hr(i)}</span>
|
|
975
|
-
<small>Tap to select</small>
|
|
976
|
-
</button>`}).join("")}
|
|
977
|
-
</div>
|
|
978
|
-
`,this.shadow.querySelectorAll("button.action").forEach(n=>{n.addEventListener("click",()=>{const l=Number(n.dataset.col),r=e[l];r&&this.dispatchEvent(new CustomEvent("aikaara-plan-select",{detail:{planType:r.match[0],message:r.postback,label:r.label},bubbles:!0,composed:!0}))})})}}function Hr(u){return u.replace(/[&<>"']/g,e=>({"&":"&","<":"<",">":">",'"':""","'":"'"})[e])}function jl(){const u=[["aikaara-chat-widget",gl],["aikaara-chat-bubble",ml],["aikaara-chat-header",bl],["aikaara-message-list",vl],["aikaara-message-bubble",_l],["aikaara-chat-input",Sl],["aikaara-typing-indicator",kl],["aikaara-streaming-message",El],["aikaara-error-banner",xl],["aikaara-template-renderer",Al],["aikaara-system-pill",Il],["aikaara-option-list",Tl],["aikaara-submit-action",Cl],["aikaara-modal-action",Ol],["aikaara-chat",Pl],["aikaara-link-modal",Ml],["aikaara-compare-plans",Rl]];for(const[e,t]of u)customElements.get(e)||customElements.define(e,t)}jl();function zr(u,e,t=""){if(!e)return t;const n=e.split(".");let l=u;for(const r of n)if(l&&typeof l=="object"&&r in l)l=l[r];else return t;return typeof l=="string"?l:t}function Th(u){try{const e=u.split(".")[1];if(!e)return 0;const t=JSON.parse(atob(e.replace(/-/g,"+").replace(/_/g,"/")));return typeof t.exp=="number"?t.exp*1e3:0}catch{return 0}}async function Or(u){return typeof u=="function"?await u():u}class Ll{constructor(e,t){this.descriptor=e,this.sessionToken=t}cache=null;inflight=null;reset(){this.cache=null,this.inflight=null}async get(){const e=this.descriptor.expiryBufferMs??6e4,t=Date.now();return this.cache&&this.cache.expiresAt>t+e?this.cache:this.inflight?this.inflight:(this.inflight=this.fetchOnce().finally(()=>{this.inflight=null}),this.inflight)}async fetchOnce(){const e=await Or(this.sessionToken),t=this.descriptor.authHeader??"Authorization",n=this.descriptor.authHeaderTemplate??"Bearer {token}",l={accept:"application/json",...this.descriptor.headers??{},[t]:n.replace("{token}",e)},r=this.descriptor.method??"POST",i={method:r,headers:l};r==="POST"&&(l["content-type"]="application/json",i.body=JSON.stringify(this.descriptor.body??{}));const o=await fetch(this.descriptor.endpoint,i);if(!o.ok){const b=await o.text().catch(()=>"");throw new Error(`Session auth failed: ${o.status} ${b.slice(0,200)}`)}const s=await o.json().catch(()=>({})),a=zr(s,this.descriptor.tokenPath??"data.token"),c=this.descriptor.tokenStripPrefix,d=c?a.replace(new RegExp(`^${c}`,"i"),"").trim():a;if(!d)throw new Error("Session auth response missing token");const p=zr(s,this.descriptor.requestIdPath??"data.requestId"),y=this.cache?.requestId||p;if(!y)throw new Error("Session auth response missing requestId");const f=zr(s,this.descriptor.fullNamePath??"data.fullName"),m=Th(d)||Date.now()+3600*1e3;return this.cache={token:d,requestId:y,fullName:f,expiresAt:m},this.cache}}async function Nl(u){const e={};for(const t of u.spec){const n=await Ch(t,u.providers);if(n!==void 0&&n!=="")e[t.name]=n;else{if(t.required)throw new Error(`[aikaara-chat-sdk] SSO credential "${t.name}" is required but ${t.source}`+(t.key?`[${t.key}]`:"")+" returned no value");t.default!==void 0&&(e[t.name]=t.default)}}return e}async function Ch(u,e){const t=u.key??u.name;switch(u.source){case"cookie":return Oh(t);case"localStorage":return rr(()=>window.localStorage.getItem(t)??void 0);case"sessionStorage":return rr(()=>window.sessionStorage.getItem(t)??void 0);case"url_param":return rr(()=>new URL(window.location.href).searchParams.get(t)??void 0);case"header_meta":return rr(()=>document.querySelector(`meta[name="${Ph(t)}"]`)?.content??void 0);case"callback":{const n=e?.[u.name];if(!n)return;const l=await n();return typeof l=="string"?l:void 0}default:return}}function Oh(u){if(typeof document>"u")return;const e=encodeURIComponent(u),t=document.cookie?document.cookie.split("; "):[];for(const n of t){const l=n.indexOf("=");if(l===-1)continue;const r=n.slice(0,l);if(r===u||r===e)try{return decodeURIComponent(n.slice(l+1))}catch{return n.slice(l+1)}}}function rr(u){try{return u()}catch{return}}function Ph(u){return u.replace(/["\\]/g,"\\$&")}const Mh=1800;class Ul{constructor(e){this.opts=e,this.cache=this.loadCache()}cache=null;inflight=null;reset(){this.cache=null,this.inflight=null,this.clearCache()}async get(e=!1){if(!e){const t=this.cache;if(t&&(!t.expiresAt||t.expiresAt>Date.now()))return t}return this.inflight?this.inflight:(this.inflight=this.exchange().finally(()=>{this.inflight=null}),this.inflight)}async exchange(){const e=await Nl({spec:this.opts.descriptor.collect,providers:this.opts.providers}),t=JSON.stringify({credentials:e}),n={accept:"application/json","content-type":"application/json",...this.opts.descriptor.headers??{}};this.opts.descriptor.apiKey&&(n["X-Api-Key"]=this.opts.descriptor.apiKey);const l=this.opts.descriptor.exchangeEndpoint||this.opts.exchangeUrl;if(!l)throw new Error("[aikaara-chat-sdk] SSO exchange URL not resolved — set descriptor.sso.exchangeEndpoint or pass `exchangeUrl` (mountFromSlug derives it from configBase + slug).");const r=await fetch(l,{method:"POST",headers:n,body:t});if(!r.ok){const d=await r.text().catch(()=>"");throw new Error(`SSO exchange failed: ${r.status} ${d.slice(0,240)}`)}const o=(await r.json().catch(()=>({}))).user??{},s=String(o.ext_uid??o.extUid??""),a=String(o.token??o.user_token??o.userToken??"");if(!s)throw new Error("SSO exchange response missing user.ext_uid");if(!a)throw new Error("SSO exchange response missing user.token");const c={id:o.id,extUid:s,userToken:a,email:typeof o.email=="string"?o.email:void 0,displayName:typeof o.display_name=="string"?o.display_name:typeof o.displayName=="string"?o.displayName:void 0,properties:o.properties&&typeof o.properties=="object"?o.properties:void 0,expiresAt:this.computeExpiry()};return this.cache=c,this.persistCache(c),c}computeExpiry(){const e=this.opts.descriptor.cacheTtlSec??Mh;if(!(!this.opts.descriptor.cacheKey||e<=0))return Date.now()+e*1e3}loadCache(){const e=this.opts.descriptor.cacheKey;if(!e)return null;try{const t=window.localStorage.getItem(e);if(!t)return null;const n=JSON.parse(t);return n.expiresAt&&n.expiresAt<Date.now()?(window.localStorage.removeItem(e),null):n}catch{return null}}persistCache(e){const t=this.opts.descriptor.cacheKey;if(t)try{window.localStorage.setItem(t,JSON.stringify(e))}catch{}}clearCache(){const e=this.opts.descriptor.cacheKey;if(e)try{window.localStorage.removeItem(e)}catch{}}}function Rh(){const u=typeof crypto<"u"?crypto:null;if(u?.randomUUID)return u.randomUUID();if(u?.getRandomValues){const e=new Uint8Array(16);u.getRandomValues(e),e[6]=e[6]&15|64,e[8]=e[8]&63|128;const t=[...e].map(n=>n.toString(16).padStart(2,"0")).join("");return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}return"xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=Math.random()*16|0;return(e==="x"?t:t&3|8).toString(16)})}const jh="aikaara_chat:requestId";function us(u,e){return`${jh}:${u}:${e}`}function Lh(u,e){try{return localStorage.getItem(us(u,e))}catch{return null}}function Nh(u,e,t){try{localStorage.setItem(us(u,e),t)}catch{}}function Uh(u,e){try{localStorage.removeItem(us(u,e))}catch{}}async function Bh(u,e){console.log("[aikaara-chat-sdk] preflight running",u.length,"steps");const t={userId:e.userId,projectId:e.projectId,slug:e.slug};if(e.identity)for(const[o,s]of Object.entries(e.identity))typeof s=="string"&&(t[o]=s);const n=o=>o.replace(/\{(\w+)\}/g,(s,a)=>a in t?t[a]:""),l=o=>{if(typeof o=="string")return n(o);if(Array.isArray(o))return o.map(l);if(o&&typeof o=="object"){const s={};for(const[a,c]of Object.entries(o))s[a]=l(c);return s}return o},r=await Or(e.sessionToken),i=[800,1500,3e3,5e3,8e3];for(let o=0;o<u.length;o++){const s=u[o],a=n(s.url),c=s.method??(s.body?"POST":"GET"),d={accept:"application/json",...s.headers??{}};if((s.authHeader??"session")==="session"){const b=s.authHeaderTemplate??"Bearer {token}";d.authorization=b.replace("{token}",r)}const p={method:c,headers:d};s.body&&(d["content-type"]="application/json",p.body=JSON.stringify(l(s.body)));let y=0,f="",m=0;for(;;)try{const b=await fetch(a,p);if(b.ok)break;if(y=b.status,f=await b.text().catch(()=>""),m<i.length&&Fh(y,f)){const g=i[m++];console.warn(`[aikaara-chat-sdk] preflight #${o} ${c} ${a} → ${y} (transient). Retry #${m} in ${g}ms.`),await new Promise(S=>setTimeout(S,g));continue}const _=`Preflight #${o} ${c} ${a} → ${y} ${f.slice(0,200)}`;if(s.soft){console.warn("[aikaara-chat-sdk]",_);break}throw new Error(_)}catch(b){if(m<i.length){const _=i[m++];console.warn(`[aikaara-chat-sdk] preflight #${o} threw, retry #${m} in ${_}ms`,b),await new Promise(g=>setTimeout(g,_));continue}if(s.soft){console.warn(`[aikaara-chat-sdk] preflight #${o} soft-failed:`,b);break}throw b}}}function Fh(u,e){if(u===503||u===504||u===502)return!0;if(u===401||u===403)return e.trim().length===0;if(u===500){const t=e.toLowerCase();return t.includes("customernew")||t.includes("is null")||t.includes("not yet ready")}return!1}async function Bl(u,e){const t=await fetch(u,{method:"GET",headers:{accept:"application/json",...e??{}}});if(!t.ok){const l=await t.text().catch(()=>"");throw new Error(`Widget config fetch failed: ${t.status} ${t.statusText} ${l.slice(0,200)}`)}const n=await t.json();if(n&&typeof n=="object"){if("config"in n)return n.config;if("data"in n)return n.data}return n}function Dh(u,e){return u.replace("{projectId}",e).replace("{uuid}",Rh().replace(/-/g,""))}async function Fl(u){const e={...u.config??(u.configUrl?await Bl(u.configUrl,u.configHeaders):{}),...u.overrides??{}},t=e.transport??"tiledesk",n=e.tiledesk;if((t==="tiledesk"||t==="dual")&&!n)throw new Error("mount: descriptor.tiledesk is required for tiledesk/dual transport");const l=n?.projectId??"",r=u.identity.userId,i=u.forceNewConversation?null:Lh(r,l),o=n?.requestIdTemplate??"support-group-{projectId}-{uuid}",s=u.conversationId??i??Dh(o,l);(!i||u.forceNewConversation)&&l&&Nh(r,l,s);const a=await u.tokenProvider(),c=u.tokenProvider,d=u.historyTokenProvider??c,p=n?{mqttEndpoint:n.mqttEndpoint,jwtToken:a,userId:r,userName:u.identity.userName,projectId:n.projectId,appId:n.appId,mqttUsername:n.mqttUsername,protocolId:n.protocolId,protocolVersion:n.protocolVersion,keepAliveSec:n.keepAliveSec,connectTimeoutMs:n.connectTimeoutMs,maxReconnectAttempts:n.maxReconnectAttempts,reconnectMaxDelayMs:n.reconnectMaxDelayMs,wildcardSubscribe:n.wildcardSubscribe,enablePresence:n.enablePresence,autoInitiateOnEmpty:n.autoInitiateOnEmpty,chatInitiatedAttributes:n.chatInitiatedAttributes,messageDefaults:{...n.messageDefaults,...u.identity.departmentId?{departmentId:u.identity.departmentId}:n.messageDefaults?.departmentId?{departmentId:n.messageDefaults.departmentId}:{}},fileTemplate:n.fileTemplate,topicTemplates:n.topicTemplates,debug:n.debug,senderFullname:u.identity.senderFullname??u.identity.userName,tokenProvider:c}:void 0,y=u.uploadAdapter??(e.uploadEndpoint?ls({endpoint:e.uploadEndpoint,fieldName:e.uploadFieldName,extraFields:e.uploadExtraFields}):void 0),f=u.historyAdapter??(e.historyApiBase?pl({apiBase:e.historyApiBase,pageSize:e.historyPageSize??200,pathTemplate:e.historyPathTemplate,extraHeaders:e.historyHeaders,getToken:d}):void 0),m={transport:t,baseUrl:"",userToken:u.userToken??r,conversationId:s,display:e.display??"embed",position:e.position,primaryColor:e.theme?.primary??e.primaryColor,title:e.title,subtitle:e.subtitle,avatarUrl:e.avatarUrl,width:e.width,height:e.height,borderRadius:e.theme?.radius??e.borderRadius,fontFamily:e.theme?.font??e.fontFamily,themeTokens:e.theme,linkHandlers:e.linkHandlers,getLinkBearer:u.getLinkBearer,welcomeMessage:e.welcomeMessage,placeholder:e.placeholder,showTimestamps:e.showTimestamps,persistConversation:e.persistConversation,showHeader:e.showHeader,hideSystemMessages:e.hideSystemMessages,timestampFormat:e.timestampFormat,input:e.input,templateLayout:e.templateLayout,tiledesk:p,tiledeskIdentity:{userId:r,userName:u.identity.userName,departmentId:u.identity.departmentId,senderFullname:u.identity.senderFullname??u.identity.userName},templateActionAttributes:e.templateActionAttributes,uploadAdapter:y,historyAdapter:f,onError:u.onError,onMessage:u.onMessage},b=document.createElement("aikaara-chat-widget");return b.configure(m),m.title&&b.setAttribute("title",m.title),m.primaryColor&&b.setAttribute("primary-color",m.primaryColor),m.display&&b.setAttribute("display",m.display),m.display==="embed"&&(b.style.cssText="display:flex;flex-direction:column;width:100%;height:100%;min-height:0;"),u.container.appendChild(b),{widget:b,requestId:s,config:m,destroy(){b.remove()}}}function $h(u){if(typeof u!="string")return u;const e=document.querySelector(u);if(!e)throw new Error(`mountFromSlug: container "${u}" not found`);return e}async function Dl(u){const e=(u.configBase??"https://api.aikaara.com").replace(/\/$/,""),t=`${e}/api/v1/widget_configs/${encodeURIComponent(u.slug)}`;let n=null;try{n=await Bl(t,u.configHeaders)}catch(b){if(!u.fallbackConfig)throw b;console.warn(`[aikaara-chat-sdk] Widget config fetch failed for slug "${u.slug}" — using fallbackConfig.`,b)}const l={...u.fallbackConfig??{},...n??{},...u.overrides??{}};if(l.templates&&Object.keys(l.templates).length>0){l.components={...l.components??{}};for(const[b,_]of Object.entries(l.templates)){const g=`template:${b}`;l.components[g]||!_?.scriptUrl||!_?.render||(l.components[g]={kind:"iife-element",scriptUrl:_.scriptUrl,tag:_.render,..._.props?{props:_.props}:{}})}}if(window.__aikaara_descriptor__={templates:l.templates,components:l.components},!l.auth)throw new Error(`mountFromSlug: widget_configs/${u.slug} descriptor must include "auth" block`);let r=null,i=u.user.id,o=u.user.name,s="";if(l.sso){const b=`${e}/api/v1/projects/by-slug/${encodeURIComponent(u.slug)}/sso_exchange`;r=await new Ul({descriptor:l.sso,providers:u.user.credentialProviders,exchangeUrl:b}).get(),i=r.extUid||i,o=o??r.displayName,s=r.userToken}l.preflight&&l.preflight.length&&await Bh(l.preflight,{sessionToken:u.user.token,userId:i,projectId:l.tiledesk?.projectId??"",slug:u.slug,identity:u.user.identity});const a=new Ll(l.auth,u.user.token),c=await a.get(),d=c.fullName||o||i,p=l.upload,y=async()=>`Bearer ${p&&"tokenSource"in p&&p.tokenSource==="chat"?(await a.get()).token:await Or(u.user.token)}`,f=u.hooks?.upload??(p&&p.mode==="presigned-3step"?dl({...p,authHeader:y}):p&&p.mode==="direct"?ls({endpoint:p.endpoint,fieldName:p.fieldName,extraFields:p.extraFields,headers:async()=>({authorization:await y()})}):void 0),m=await Fl({container:$h(u.container),config:l,userToken:s||void 0,identity:{userId:i,userName:d,departmentId:u.user.departmentId,senderFullname:d},tokenProvider:async()=>(await a.get()).token,historyTokenProvider:async()=>(await a.get()).token,uploadAdapter:f,historyAdapter:u.hooks?.history,conversationId:c.requestId,onError:u.hooks?.onError,onMessage:u.hooks?.onMessage,getLinkBearer:async b=>b==="none"?null:b==="chat"?(await a.get()).token:Or(u.user.token)});return Object.assign(m,{fullName:d,requestId:c.requestId,descriptor:l,async refreshAuth(){a.reset(),await a.get()}})}exports.ActionCableClient=Kr;exports.AikaaraChat=Pl;exports.AikaaraChatBubble=ml;exports.AikaaraChatClient=fl;exports.AikaaraChatHeader=bl;exports.AikaaraChatInput=Sl;exports.AikaaraChatWidget=gl;exports.AikaaraComparePlans=Rl;exports.AikaaraErrorBanner=xl;exports.AikaaraLinkModal=Ml;exports.AikaaraMessageBubble=_l;exports.AikaaraMessageList=vl;exports.AikaaraModalAction=Ol;exports.AikaaraOptionList=Tl;exports.AikaaraStreamingMessage=El;exports.AikaaraSubmitAction=Cl;exports.AikaaraSystemPill=Il;exports.AikaaraTemplateRenderer=Al;exports.AikaaraTypingIndicator=kl;exports.ApiClient=To;exports.ChannelSubscription=Ao;exports.ConnectionManager=Io;exports.ConversationManager=Oo;exports.EventEmitter=Ki;exports.MessageStore=Co;exports.SessionAuthAdapter=Ll;exports.SsoExchangeAdapter=Ul;exports.TiledeskTransport=ll;exports.clearPersistedConversationId=Uh;exports.collectSsoCredentials=Nl;exports.createFetchUploadAdapter=ls;exports.createPresigned3StepUploadAdapter=dl;exports.createTiledeskHistoryAdapter=pl;exports.extractTiledeskFileEnvelope=hl;exports.inferTiledeskRole=cl;exports.isTiledeskSelfEcho=ul;exports.mount=Fl;exports.mountFromSlug=Dl;exports.parseTiledeskTemplate=as;exports.registerComponents=jl;
|