@camera.ui/server 2.0.16 → 2.0.17
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/interface/assets/{404-LqqgIXTE.js → 404-BWRNG7e3.js} +1 -1
- package/dist/interface/assets/{About-GD_Lrqmu.js → About-CWvfgUA-.js} +1 -1
- package/dist/interface/assets/{Adminpanel-D4-pJyIs.js → Adminpanel-Cat_euTC.js} +1 -1
- package/dist/interface/assets/{Automation-bXZ-tO73.js → Automation-cp0lTCAv.js} +3 -3
- package/dist/interface/assets/{AutomationImport-DVIolIko.js → AutomationImport-mCGSgys2.js} +2 -2
- package/dist/interface/assets/{AutomationStore-CbykqzIx.js → AutomationStore-udNOn3FR.js} +2 -2
- package/dist/interface/assets/{AutomationStoreDetail-BwYcPwOk.js → AutomationStoreDetail-CcVksadt.js} +2 -2
- package/dist/interface/assets/{Automations-CMIf0TNl.js → Automations-CcQLbmoN.js} +2 -2
- package/dist/interface/assets/{Camera-Ba5k3cTv.js → Camera-Cq466-gT.js} +2 -2
- package/dist/interface/assets/{CameraConsole-DYegEaD_.js → CameraConsole-A414-zXW.js} +1 -1
- package/dist/interface/assets/{Cameras-_SciBnKu.js → Cameras-CW5XnJ1g.js} +1 -1
- package/dist/interface/assets/{Camview-BORjCABo.js → Camview-zK6fnWI0.js} +1 -1
- package/dist/interface/assets/{Config-CRoCTs-d.js → Config-R2N_QUER.js} +1 -1
- package/dist/interface/assets/{ConfigActionCameraControl-BWIZ-gKx.js → ConfigActionCameraControl-DdW92QxO.js} +1 -1
- package/dist/interface/assets/{ConfigActionDelay-CBco3m5a.js → ConfigActionDelay-BiCLaHDd.js} +1 -1
- package/dist/interface/assets/{ConfigActionHttp-ChIlpuzj.js → ConfigActionHttp-BvM-8hTt.js} +1 -1
- package/dist/interface/assets/{ConfigActionImageInput-DyEXQhZ3.js → ConfigActionImageInput-CoyrNloo.js} +1 -1
- package/dist/interface/assets/{ConfigActionMqtt-D8gt7QCx.js → ConfigActionMqtt-CY8HOoug.js} +1 -1
- package/dist/interface/assets/{ConfigActionNotification-D39Vj90p.js → ConfigActionNotification-DP3dTyFB.js} +1 -1
- package/dist/interface/assets/{ConfigActionOutput-B4qOi-eO.js → ConfigActionOutput-BwYwuQ1w.js} +1 -1
- package/dist/interface/assets/{ConfigActionPlugin-g6ePZtkD.js → ConfigActionPlugin-DbhT4kyF.js} +1 -1
- package/dist/interface/assets/{ConfigActionSensor-eQwfGu5Y.js → ConfigActionSensor-_zmPKdhz.js} +1 -1
- package/dist/interface/assets/{ConfigActionSnapshot-D8wHL8Rv.js → ConfigActionSnapshot-Bc3eukMk.js} +1 -1
- package/dist/interface/assets/{ConfigActionVariable-DpHxhQ1h.js → ConfigActionVariable-BeQy6W8G.js} +1 -1
- package/dist/interface/assets/{ConfigConditionIfElse-C4rCV2CE.js → ConfigConditionIfElse-CiFC5fLv.js} +1 -1
- package/dist/interface/assets/{ConfigConditionSensorState-C2EbPfIe.js → ConfigConditionSensorState-CGeGdh0d.js} +1 -1
- package/dist/interface/assets/{ConfigConditionSwitch-Dp2bzbVu.js → ConfigConditionSwitch-BjR776j5.js} +1 -1
- package/dist/interface/assets/{ConfigConditionTime-DytGa873.js → ConfigConditionTime-BAypML9_.js} +1 -1
- package/dist/interface/assets/{ConfigSensorValueInput-3unv3LZ0.js → ConfigSensorValueInput-Dis2Kr1r.js} +1 -1
- package/dist/interface/assets/{ConfigTriggerDetection-Z-koLuOe.js → ConfigTriggerDetection-CqS3IAqj.js} +1 -1
- package/dist/interface/assets/{ConfigTriggerGeofence-BjJw12re.js → ConfigTriggerGeofence-BbNpW2l0.js} +1 -1
- package/dist/interface/assets/{ConfigTriggerManual-Bt_4XPcG.js → ConfigTriggerManual-DiyFl_g-.js} +1 -1
- package/dist/interface/assets/{ConfigTriggerMqtt-CnXIT8C_.js → ConfigTriggerMqtt-ZXEft2Hi.js} +1 -1
- package/dist/interface/assets/{ConfigTriggerSchedule-C7O4zOJF.js → ConfigTriggerSchedule-Dy3NCMvo.js} +1 -1
- package/dist/interface/assets/{ConfigTriggerSensor-B7esExEG.js → ConfigTriggerSensor-CnSSEh4s.js} +1 -1
- package/dist/interface/assets/{ConfigTriggerSystem-Cv7a4ZVP.js → ConfigTriggerSystem-CuKwsM8D.js} +1 -1
- package/dist/interface/assets/{ConfigTriggerWebhook-4lphEL8n.js → ConfigTriggerWebhook-DJPepSlC.js} +1 -1
- package/dist/interface/assets/{Console-CpZmRbco.js → Console-tfkkZnFl.js} +1 -1
- package/dist/interface/assets/{CuiAutomationRunsDialog-D8VSdGxB.js → CuiAutomationRunsDialog-o2aLvK5K.js} +1 -1
- package/dist/interface/assets/CuiBottomSheet-m_HX6x4G.js +1 -0
- package/dist/interface/assets/{CuiBottomSheet-BM3-NJdO.js → CuiBottomSheet-v2xnKGrr.js} +1 -1
- package/dist/interface/assets/{CuiCameraPipCard-CI3fhQQx.js → CuiCameraPipCard-CId6q8WW.js} +1 -1
- package/dist/interface/assets/{CuiCameraRecordings-DrdKTev4.js → CuiCameraRecordings-C_1UfpAJ.js} +1 -1
- package/dist/interface/assets/{CuiCameraShares-B5b0jALW.js → CuiCameraShares-DW_hDX2f.js} +1 -1
- package/dist/interface/assets/{CuiCameraTable-CXsNSz1o.js → CuiCameraTable-BXzZ-gIg.js} +1 -1
- package/dist/interface/assets/{CuiDataTable-DKf8iX28.js → CuiDataTable-CrL6zx3I.js} +1 -1
- package/dist/interface/assets/{CuiPluginCard-d_KDh1Yw.js → CuiPluginCard-C38Fk0bQ.js} +2 -2
- package/dist/interface/assets/{CuiPluginCategoryChip-CkO-XUg6.js → CuiPluginCategoryChip-B3XVum_D.js} +1 -1
- package/dist/interface/assets/{CuiPluginOAuthButton-Cvf2xX0t.js → CuiPluginOAuthButton-DRJnVV4F.js} +2 -2
- package/dist/interface/assets/{CuiPluginTrustBadge-DB01yKP2.js → CuiPluginTrustBadge-4xCyAUBM.js} +1 -1
- package/dist/interface/assets/{CuiQRCode-C3tuGeRr.js → CuiQRCode-DmsP4eAY.js} +1 -1
- package/dist/interface/assets/{CuiRecordingsGrid-_mLo_0zw.js → CuiRecordingsGrid-BnL8kQ29.js} +1 -1
- package/dist/interface/assets/{CuiSchema-DMm2Giz1.js → CuiSchema-D2yLW853.js} +1 -1
- package/dist/interface/assets/{CuiTopNavbarItem-BUDHIHlJ.js → CuiTopNavbarItem-_7UaVuQT.js} +1 -1
- package/dist/interface/assets/{Faces-gvZlSmMT.js → Faces-BPgUsyT0.js} +1 -1
- package/dist/interface/assets/{FirstSteps-DBfOXC9_.js → FirstSteps-CKXlbFN-.js} +1 -1
- package/dist/interface/assets/{Instances-DpfzWpgd.js → Instances-BS4UPlay.js} +1 -1
- package/dist/interface/assets/{Logs-ONd-X7Uz.js → Logs-UPgu6TsC.js} +1 -1
- package/dist/interface/assets/{Menu-DMcOQ89M.js → Menu-CdewzDV4.js} +1 -1
- package/dist/interface/assets/{OAuthDeviceFlow-BBbeSQfV.js → OAuthDeviceFlow-SGgJTWAU.js} +1 -1
- package/dist/interface/assets/{Plugin-BR0myz2R.js → Plugin-BSSYZcyQ.js} +1 -1
- package/dist/interface/assets/{PluginConsole-Ccdp0UG4.js → PluginConsole-Bm0ify7V.js} +1 -1
- package/dist/interface/assets/{PluginDetail-D7Bs2TR8.js → PluginDetail-DY6Uvu3V.js} +2 -2
- package/dist/interface/assets/{PluginSchema-CYgK5llZ.js → PluginSchema-BkM5iKma.js} +1 -1
- package/dist/interface/assets/{PluginSearch-BdNBx3a_.js → PluginSearch-4q_vZHJc.js} +2 -2
- package/dist/interface/assets/PluginSearch-BvhNP9WQ.js +1 -0
- package/dist/interface/assets/{Plugins-BGlmDYtU.js → Plugins-B1tZxl7k.js} +1 -1
- package/dist/interface/assets/{Recordings-yMAywSQr.js → Recordings-XY32_Jjt.js} +1 -1
- package/dist/interface/assets/{Settings-DgQRh-PZ.js → Settings-CXWxt73x.js} +1 -1
- package/dist/interface/assets/{SettingsAccount-BkzyYZC3.js → SettingsAccount-MLkJU79V.js} +1 -1
- package/dist/interface/assets/SettingsAccount-RGvmNkwD.js +1 -0
- package/dist/interface/assets/{SettingsAppearance-vIx-5n3S.js → SettingsAppearance-CHRnfQ4O.js} +1 -1
- package/dist/interface/assets/SettingsAppearance-CyaOt4lL.js +1 -0
- package/dist/interface/assets/{SettingsBackup-yKIvYrSF.js → SettingsBackup-Xjb4i_YZ.js} +1 -1
- package/dist/interface/assets/{SettingsMqtt-lXusRXF0.js → SettingsMqtt-CW0uvXrU.js} +1 -1
- package/dist/interface/assets/{SettingsNotifications-DtY5d3Ff.js → SettingsNotifications-BbyXpyHK.js} +1 -1
- package/dist/interface/assets/{SettingsRecordings-BnHyde5_.js → SettingsRecordings-DVZPpunU.js} +1 -1
- package/dist/interface/assets/{SettingsRemote-DFrbKuDY.js → SettingsRemote-BnFHx9_s.js} +1 -1
- package/dist/interface/assets/{SettingsSystem-9u9HwzWH.js → SettingsSystem-C1ne-w59.js} +2 -2
- package/dist/interface/assets/{SettingsUsers-QkRFOl-j.js → SettingsUsers-91m0163s.js} +1 -1
- package/dist/interface/assets/{Terminal-DfvrkyXW.js → Terminal-D_E-kRbN.js} +1 -1
- package/dist/interface/assets/{VariableInput-BYDhQLWK.js → VariableInput-BHvGHE7o.js} +1 -1
- package/dist/interface/assets/{VariableSuggestions-BQeEuD64.js → VariableSuggestions-uJAwwX7y.js} +1 -1
- package/dist/interface/assets/{VersionsHandler-C7UrObQz.js → VersionsHandler-DJ00TTHi.js} +1 -1
- package/dist/interface/assets/{Workers-CycLd7x1.js → Workers-BCBrqShK.js} +1 -1
- package/dist/interface/assets/{api-BRgblL6q.js → api-ByMXkaIi.js} +1 -1
- package/dist/interface/assets/{api-C0gnicQm.js → api-ChlkJnEG.js} +2 -2
- package/dist/interface/assets/{auth-B8R5c1jZ.js → auth-B-MND66x.js} +1 -1
- package/dist/interface/assets/{automations-CyE7C9Ua.js → automations-DvpxT4Pa.js} +1 -1
- package/dist/interface/assets/{cameras.schema-Cpe1mfEm.js → cameras.schema-2VoKYyFS.js} +1 -1
- package/dist/interface/assets/cloudHandoff-o_0n9cgb.js +1 -0
- package/dist/interface/assets/{config-61wCmCSW.js → config-UED3wn2k.js} +1 -1
- package/dist/interface/assets/{flowSchema-d_rln6ks.js → flowSchema-DyobL8Pg.js} +1 -1
- package/dist/interface/assets/{main-BL1KwJfI.js → main-Cd1DVdC9.js} +2 -2
- package/dist/interface/assets/{mqtt-gGXPp_LJ.js → mqtt-BltdxiuG.js} +1 -1
- package/dist/interface/assets/{notifications-BJiG7174.js → notifications-D4Mi4q8n.js} +1 -1
- package/dist/interface/assets/{plugins-BlciwIm6.js → plugins-DmgMSZSt.js} +1 -1
- package/dist/interface/assets/{round-restart-alt-DtBp7QJ3.js → round-restart-alt-D1SwcyIw.js} +1 -1
- package/dist/interface/assets/{server-CbcqB7XD.js → server-BBvLLocT.js} +1 -1
- package/dist/interface/assets/{theme-DbnzixCd.js → theme-CHyA8uCs.js} +1 -1
- package/dist/interface/assets/{types-CaTe8DZQ.js → types-ByD7R6WC.js} +1 -1
- package/dist/interface/assets/{types-ClrPRAlr.js → types-DRsoZjsP.js} +1 -1
- package/dist/interface/assets/{useAppVersion-CV9EQ8NP.js → useAppVersion-dQkatyRF.js} +1 -1
- package/dist/interface/assets/{useBackupRestore-CH0Ef30o.js → useBackupRestore-D6Vxck9i.js} +1 -1
- package/dist/interface/assets/{useCameraOptions-DLzh2qDi.js → useCameraOptions-zPRiut_S.js} +1 -1
- package/dist/interface/assets/{useLogsSocket-BZc09yQ1.js → useLogsSocket-DzKSWAVf.js} +1 -1
- package/dist/interface/assets/{useServerRestart-i775C31r.js → useServerRestart-DjaOOudi.js} +1 -1
- package/dist/interface/assets/{useStreamStatus-42S4V3vs.js → useStreamStatus-DpXFSeOf.js} +1 -1
- package/dist/interface/assets/{useUserOptions-CSIMtpKB.js → useUserOptions-B8T0ROJS.js} +1 -1
- package/dist/interface/assets/{vendor-cameraui-CoNnWBOZ.js → vendor-cameraui-D7o3alq7.js} +1 -1
- package/dist/interface/assets/{vendor-core-C3HwU-b4.js → vendor-core-M6N9PctY.js} +1 -1
- package/dist/interface/assets/{vendor-primevue-C9GUqb3A.js → vendor-primevue-BynQnxoR.js} +1 -1
- package/dist/interface/index.html +18 -18
- package/dist/interface/sw.js +1 -1
- package/dist/server/package.json +5 -5
- package/dist/server/requirements.txt +1 -1
- package/dist/server/src/camera/decoder/detection-coordinator.d.ts +2 -0
- package/dist/server/src/camera/decoder/detection-coordinator.js +7 -1
- package/dist/server/src/camera/decoder/detection-coordinator.js.map +1 -1
- package/dist/server/src/camera/decoder/secondary-stage.d.ts +3 -2
- package/dist/server/src/camera/decoder/secondary-stage.js +26 -14
- package/dist/server/src/camera/decoder/secondary-stage.js.map +1 -1
- package/dist/server/src/camera/decoder/stationary-suppressor.d.ts +6 -0
- package/dist/server/src/camera/decoder/stationary-suppressor.js +59 -17
- package/dist/server/src/camera/decoder/stationary-suppressor.js.map +1 -1
- package/dist/server/src/camera/streaming/fmp4-session.js +3 -0
- package/dist/server/src/camera/streaming/fmp4-session.js.map +1 -1
- package/dist/server/src/camera/streaming/rtp-session.js +9 -2
- package/dist/server/src/camera/streaming/rtp-session.js.map +1 -1
- package/package.json +5 -5
- package/dist/interface/assets/CuiBottomSheet-BpMqXUS_.js +0 -1
- package/dist/interface/assets/PluginSearch-ClUUWF-c.js +0 -1
- package/dist/interface/assets/SettingsAccount-fiExYdM8.js +0 -1
- package/dist/interface/assets/SettingsAppearance-BtX9WEUv.js +0 -1
- package/dist/interface/assets/cloudHandoff-Dwh5ja7i.js +0 -1
|
@@ -9,7 +9,7 @@ import{a as e,i as t,n,o as r,r as i,t as a}from"./rolldown-runtime-DAXXjFlN.js"
|
|
|
9
9
|
`)),this.transport.send(Ya)}catch(e){this.close(e).catch()}}if(n){let{added:e,deleted:t}=n;this.dispatchStatus({type:`update`,added:e,deleted:t})}t.ldm!==void 0&&t.ldm&&this.dispatchStatus({type:`ldm`,server:this.servers.getCurrentServer().toString()})}push(e){switch(e.kind){case Ki.MSG:{let{msg:t,data:n}=e;this.processMsg(t,n);break}case Ki.OK:break;case Ki.ERR:this.processError(e.data);break;case Ki.PING:this.processPing();break;case Ki.PONG:this.processPong();break;case Ki.INFO:this.processInfo(e.data);break}}sendCommand(e,...t){let n=this.outbound.length(),r;r=typeof e==`string`?Yn(e):e,this.outbound.fill(r,...t),n===0?queueMicrotask(()=>{this.flushPending()}):this.outbound.size()>=this.pendingLimit&&this.flushPending()}publish(e,t=Zn,n){let r;if(t instanceof Uint8Array)r=t;else if(typeof t==`string`)r=Qn.encode(t);else throw TypeError(`payload types can be strings or Uint8Array`);let i=r.length;n||={},n.reply=n.reply||``;let a=Zn,o=0;if(n.headers&&(this.info&&!this.info.headers&&nr.format(`headers`,`are not available on this server`),a=n.headers.encode(),o=a.length,i=r.length+o),this.info&&i>this.info.max_payload)throw nr.format(`payload`,`max_payload size exceeded`);this.outBytes+=i,this.outMsgs++;let s;n.headers?(s=n.reply?`HPUB ${e} ${n.reply} ${o} ${i}\r\n`:`HPUB ${e} ${o} ${i}\r\n`,this.sendCommand(s,a,r,ti)):(s=n.reply?`PUB ${e} ${n.reply} ${i}\r\n`:`PUB ${e} ${i}\r\n`,this.sendCommand(s,r,ti))}request(e){return this.initMux(),this.muxSubscriptions.add(e),e}subscribe(e){return this.subscriptions.add(e),this._subunsub(e),e}_sub(e){e.queue?this.sendCommand(`SUB ${e.subject} ${e.queue} ${e.sid}\r\n`):this.sendCommand(`SUB ${e.subject} ${e.sid}\r\n`)}_subunsub(e){return this._sub(e),e.max&&this.unsubscribe(e,e.max),e}unsubscribe(e,t){this.unsub(e,t),(e.max===void 0||e.received>=e.max)&&this.subscriptions.cancel(e)}unsub(e,t){!e||this.isClosed()||(t?this.sendCommand(`UNSUB ${e.sid} ${t}\r\n`):this.sendCommand(`UNSUB ${e.sid}\r\n`),e.max=t)}resub(e,t){!e||this.isClosed()||(this.unsub(e),e.subject=t,this.subscriptions.resub(e),this._sub(e))}flush(e){return e||=xr(),this.pongs.push(e),this.outbound.fill(Ya),this.flushPending(),e}sendSubscriptions(){let e=[];this.subscriptions.all().forEach(t=>{let n=t;n.queue?e.push(`SUB ${n.subject} ${n.queue} ${n.sid}\r
|
|
10
10
|
`):e.push(`SUB ${n.subject} ${n.sid}\r
|
|
11
11
|
`)}),e.length&&this.transport.send(Yn(e.join(``)))}async close(e){if(this._closed)return;this.whyClosed=Error(`close trace`).stack||``,this.heartbeats.cancel(),this.connectError&&=(this.connectError(e),void 0),this.muxSubscriptions.close(),this.subscriptions.close();let t=[];for(let e=0;e<this.listeners.length;e++){let n=this.listeners[e];n&&(n.push({type:`close`}),n.stop(),t.push(n.iterClosed))}t.length&&await Promise.all(t),this._closed=!0,await this.transport.close(e),this.raceTimer?.cancel(),this.dialDelay?.cancel(),this.closed.resolve(e)}abortClose(e){if(!this._closed){this.whyClosed=Error(`abortClose trace`).stack||``,this._closed=!0,this.abortReconnect=!0,this.heartbeats.cancel(),this.connectError&&=(this.connectError(e),void 0),this.muxSubscriptions.close(),this.subscriptions.close();for(let e=0;e<this.listeners.length;e++){let t=this.listeners[e];t&&(t.push({type:`close`}),t.stop())}this.raceTimer?.cancel(),this.dialDelay?.cancel();try{this.transport?.close(e)}catch{}this.closed.resolve(e)}}isClosed(){return this._closed}async drain(){let e=this.subscriptions.all(),t=[];e.forEach(e=>{t.push(e.drain())});try{await Promise.allSettled(t)}catch{}finally{this.noMorePublishing=!0,await this.flush()}return this.close()}flushPending(){if(!(!this.infoReceived||!this.connected)&&this.outbound.size()){let e=this.outbound.drain();this.transport.send(e)}}initMux(){if(!this.subscriptions.getMux()){let e=this.muxSubscriptions.init(this.options.inboxPrefix),t=new eo(this,`${e}*`);t.callback=this.muxSubscriptions.dispatcher(),this.subscriptions.setMux(t),this.subscribe(t)}}selectServer(){let e=this.servers.selectServer();if(e!==void 0)return this.server=e,this.server}getServer(){return this.server}}})),io,ao,oo,so=n((()=>{Pr(),hr(),io=class{token;received;ctx;requestSubject;mux;constructor(e,t,n=!0){this.mux=e,this.requestSubject=t,this.received=0,this.token=Or(),n&&(this.ctx=new ur)}},ao=class extends io{callback;done;timer;max;opts;constructor(e,t,n={maxWait:1e3}){if(super(e,t),this.opts=n,typeof this.opts.callback!=`function`)throw TypeError(`callback must be a function`);this.callback=this.opts.callback,this.max=typeof n.maxMessages==`number`&&n.maxMessages>0?n.maxMessages:-1,this.done=xr(),this.done.then(()=>{this.callback(null,null)}),this.timer=setTimeout(()=>{this.cancel()},n.maxWait)}cancel(e){e&&this.callback(e,null),clearTimeout(this.timer),this.mux.cancel(this),this.done.resolve()}resolver(e,t){e?(this.ctx&&(e.stack+=`\n\n${this.ctx.stack}`),this.cancel(e)):(this.callback(null,t),this.opts.strategy===`count`&&(this.max--,this.max===0&&this.cancel()),this.opts.strategy===`stall`&&(clearTimeout(this.timer),this.timer=setTimeout(()=>{this.cancel()},this.opts.stall||300)),this.opts.strategy===`sentinel`&&t&&t.data.length===0&&this.cancel())}},oo=class extends io{deferred;timer;constructor(e,t,n={timeout:1e3},r=!0){super(e,t,r),this.deferred=xr(),this.timer=vr(n.timeout,r)}resolver(e,t){this.timer&&this.timer.cancel(),e?(e instanceof dr||(this.ctx?(this.ctx.message=e.message,this.ctx.cause=e,e=this.ctx):e=new mr.RequestError(e.message,{cause:e})),this.deferred.reject(e)):this.deferred.resolve(t),this.cancel()}cancel(e){this.timer&&this.timer.cancel(),this.mux.cancel(this),this.deferred.reject(e||new ur(`cancelled`))}}})),co,lo,uo,fo=n((()=>{Pr(),ro(),er(),ra(),ua(),Ua(),Ai(),so(),Wr(),hr(),co=/[ \n\r\t]/,lo=class e{options;protocol;draining;closeListeners;constructor(e){this.draining=!1,this.options=La(e)}static connect(t={}){return new Promise((n,r)=>{let i=new e(t);no.connect(i.options,i).then(e=>{i.protocol=e,n(i)}).catch(e=>{r(e)})})}closed(){return this.protocol.closed}async close(){await this.protocol.close()}abortClose(e){this.protocol.abortClose(e)}isStale(){return!this.isClosed()&&this.protocol.isStale()}_check(e,t,n){if(this.isClosed())throw new mr.ClosedConnectionError;if(t&&this.isDraining()||n&&this.protocol.noMorePublishing)throw new mr.DrainingConnectionError;if(e||=``,e.length===0||co.test(e))throw new mr.InvalidSubjectError(e)}publish(e,t,n){if(this._check(e,!1,!0),n?.reply&&this._check(n.reply,!1,!0),typeof n?.traceOnly==`boolean`){let e=n.headers||ea();e.set(`Nats-Trace-Only`,`true`),n.headers=e}if(typeof n?.traceDestination==`string`){let e=n.headers||ea();e.set(`Nats-Trace-Dest`,n.traceDestination),n.headers=e}this.protocol.publish(e,t,n)}publishMessage(e){return this.publish(e.subject,e.data,{reply:e.reply,headers:e.headers})}respondMessage(e){return e.reply?(this.publish(e.reply,e.data,{reply:e.reply,headers:e.headers}),!0):!1}subscribe(e,t={}){this._check(e,!0,!1);let n=new eo(this.protocol,e,t);return typeof t.callback!=`function`&&typeof t.slow==`number`&&n.setSlowNotificationFn(t.slow,e=>{this.protocol.dispatchStatus({type:`slowConsumer`,sub:n,pending:e})}),this.protocol.subscribe(n),n}_resub(e,t,n){this._check(t,!0,!1);let r=e;r.max=n,n&&(r.max=n+r.received),this.protocol.resub(r,t)}requestMany(e,t=Zn,n={maxWait:1e3,maxMessages:-1}){let r=!this.protocol.options.noAsyncTraces;try{this._check(e,!0,!0)}catch(e){return Promise.reject(e)}if(n.strategy=n.strategy||`timer`,n.maxWait=n.maxWait||1e3,n.maxWait<1)return Promise.reject(nr.format(`timeout`,`must be greater than 0`));let i=new ki;function a(e){i.push(()=>{i.stop(e)})}function o(e,t){e||t===null?a(e===null?void 0:e):i.push(t)}if(n.noMux){let s=r?Error().stack:null,c=typeof n.maxMessages==`number`&&n.maxMessages>0?n.maxMessages:-1,l=this.subscribe(Br(this.options.inboxPrefix),{callback:(t,r)=>{if(r?.data?.length===0&&r?.headers?.status===`503`&&(t=new mr.NoRespondersError(e)),t){s&&(t.stack+=`\n\n${s}`),u(t);return}o(null,r),n.strategy===`count`&&(c--,c===0&&u()),n.strategy===`stall`&&(h(),m=setTimeout(()=>{u()},300)),n.strategy===`sentinel`&&r&&r.data.length===0&&u()}});l.requestSubject=e,l.closed.then(()=>{a()}).catch(e=>{i.stop(e)});let u=e=>{e&&i.push(()=>{throw e}),h(),l.drain().then(()=>{a()}).catch(e=>{a()})};i.iterClosed.then(()=>{h(),l?.unsubscribe()}).catch(e=>{h(),l?.unsubscribe()});let{headers:d,traceDestination:f,traceOnly:p}=n;try{this.publish(e,t,{reply:l.getSubject(),headers:d,traceDestination:f,traceOnly:p})}catch(e){u(e)}let m=setTimeout(()=>{u()},n.maxWait),h=()=>{m&&clearTimeout(m)}}else{let r=n;r.callback=o,i.iterClosed.then(()=>{a.cancel()}).catch(e=>{a.cancel(e)});let a=new ao(this.protocol.muxSubscriptions,e,r);this.protocol.request(a);let{headers:s,traceDestination:c,traceOnly:l}=n;try{this.publish(e,t,{reply:`${this.protocol.muxSubscriptions.baseInbox}${a.token}`,headers:s,traceDestination:c,traceOnly:l})}catch(e){a.cancel(e)}}return Promise.resolve(i)}request(e,t,n={timeout:1e3,noMux:!1}){try{this._check(e,!0,!0)}catch(e){return Promise.reject(e)}let r=!this.protocol.options.noAsyncTraces;if(n.timeout=n.timeout||1e3,n.timeout<1)return Promise.reject(nr.format(`timeout`,`must be greater than 0`));if(!n.noMux&&n.reply)return Promise.reject(nr.format([`reply`,`noMux`],`are mutually exclusive`));if(n.noMux){let i=n.reply?n.reply:Br(this.options.inboxPrefix),a=xr(),o=r?new mr.RequestError(``):null,s=this.subscribe(i,{max:1,timeout:n.timeout,callback:(t,n)=>{n&&n.data?.length===0&&n.headers?.code===503&&(t=new mr.NoRespondersError(e)),t?(t instanceof dr||(o?(o.message=t.message,o.cause=t,t=o):t=new mr.RequestError(t.message,{cause:t})),a.reject(t),s.unsubscribe()):a.resolve(n)}});return s.requestSubject=e,this.protocol.publish(e,t,{reply:i,headers:n.headers}),a}else{let i=new oo(this.protocol.muxSubscriptions,e,n,r);this.protocol.request(i);let{headers:a,traceDestination:o,traceOnly:s}=n;try{this.publish(e,t,{reply:`${this.protocol.muxSubscriptions.baseInbox}${i.token}`,headers:a,traceDestination:o,traceOnly:s})}catch(e){i.cancel(e)}let c=Promise.race([i.timer,i.deferred]);return c.catch(()=>{i.cancel()}),c}}flush(){return this.isClosed()?Promise.reject(new mr.ClosedConnectionError):this.protocol.flush()}drain(){return this.isClosed()?Promise.reject(new mr.ClosedConnectionError):this.isDraining()?Promise.reject(new mr.DrainingConnectionError):(this.draining=!0,this.protocol.drain())}async[Symbol.asyncDispose](){if(!this.isClosed()){if(this.isDraining()){await this.closed();return}await this.drain()}}isClosed(){return this.protocol.isClosed()}isDraining(){return this.draining}getServer(){let e=this.protocol.getServer();return e?e.listen:``}setServers(e){this.protocol.servers.setServers(e)}getServers(){return this.protocol.servers.snapshot()}status(){let e=new ki;return e.iterClosed.then(()=>{let t=this.protocol.listeners.indexOf(e);t>-1&&this.protocol.listeners.splice(t,1)}),this.protocol.listeners.push(e),e}get info(){return this.protocol.isClosed()?void 0:this.protocol.info}async context(){return(await this.request(`$SYS.REQ.USER.INFO`)).json((e,t)=>e===`time`?new Date(Date.parse(t)):t)}stats(){return{inBytes:this.protocol.inBytes,outBytes:this.protocol.outBytes,inMsgs:this.protocol.inMsgs,outMsgs:this.protocol.outMsgs}}getServerVersion(){let e=this.info;return e?oa(e.version):void 0}async rtt(){if(this.isClosed())throw new mr.ClosedConnectionError;if(!this.protocol.connected)throw new mr.RequestError(`connection disconnected`);let e=Date.now();return await this.flush(),Date.now()-e}get features(){return this.protocol.features}reconnect(){return this.isClosed()?Promise.reject(new mr.ClosedConnectionError):this.isDraining()?Promise.reject(new mr.DrainingConnectionError):this.protocol.reconnect()}forceReconnect(){return this.isClosed()?Promise.reject(new mr.ClosedConnectionError):this.isDraining()?Promise.reject(new mr.DrainingConnectionError):this.protocol.forceReconnect()}addCloseListener(e){this.closeListeners===void 0&&(this.closeListeners=new uo(this.closed())),this.closeListeners.add(e)}removeCloseListener(e){this.closeListeners&&this.closeListeners.remove(e)}},uo=class{listeners;constructor(e){this.listeners=[],e.then(e=>{this.notify(e)})}add(e){this.listeners.push(e)}remove(e){this.listeners=this.listeners.filter(t=>t!==e)}notify(e){this.listeners.forEach(t=>{if(typeof t.connectionClosedCallback==`function`)try{t.connectionClosedCallback(e)}catch{}}),this.listeners=[]}}})),po=n((()=>{er()}));function mo(e,t){return`${ho(e/t)}/sec`}function ho(e,t=!1){let n=t?1e3:1024,r=t?[`k`,`M`,`G`,`T`,`P`,`E`]:[`K`,`M`,`G`,`T`,`P`,`E`],i=t?`iB`:`B`;if(e<n)return`${e.toFixed(2)} ${i}`;let a=parseInt(Math.log(e)/Math.log(n)+``),o=parseInt(a-1+``);return`${(e/n**+a).toFixed(2)} ${r[o]}${i}`}function go(e){return e.toString().replace(/\B(?=(\d{3})+(?!\d))/g,`,`)}var _o,vo,yo=n((()=>{po(),Rr(),Pr(),_o=class{name;duration;date;payload;msgs;lang;version;bytes;asyncRequests;min;max;constructor(e,t){this.name=e,this.duration=t,this.date=Date.now(),this.payload=0,this.msgs=0,this.bytes=0}toString(){let e=this.duration/1e3,t=Math.round(this.msgs/e),n=this.asyncRequests?`asyncRequests`:``,r=``;return this.max&&(r=`${this.min}/${this.max}`),`${this.name}${n?` [asyncRequests]`:``} ${go(t)} msgs/sec - [${e.toFixed(2)} secs] ~ ${mo(this.bytes,e)} ${r}`}toCsv(){return`"${this.name}",${new Date(this.date).toISOString()},${this.lang},${this.version},${this.msgs},${this.payload},${this.bytes},${this.duration},${this.asyncRequests?this.asyncRequests:!1}\n`}static header(){return`Test,Date,Lang,Version,Count,MsgPayload,Bytes,Millis,Async
|
|
12
|
-
`}},vo=class{nc;callbacks;msgs;size;subject;asyncRequests;pub;sub;req;rep;perf;payload;constructor(e,t={msgs:1e5,size:128,subject:``,asyncRequests:!1,pub:!1,sub:!1,req:!1,rep:!1}){if(this.nc=e,this.callbacks=t.callbacks||!1,this.msgs=t.msgs||0,this.size=t.size||0,this.subject=t.subject||Lr.nuid.next(),this.asyncRequests=t.asyncRequests||!1,this.pub=t.pub||!1,this.sub=t.sub||!1,this.req=t.req||!1,this.rep=t.rep||!1,this.perf=new kr,this.payload=this.size?new Uint8Array(this.size):Zn,!this.pub&&!this.sub&&!this.req&&!this.rep)throw Error(`no options selected`)}async run(){return this.nc.closed().then(e=>{if(e)throw e}),this.callbacks?await this.runCallbacks():await this.runAsync(),this.processMetrics()}processMetrics(){let{lang:e,version:t}=this.nc.protocol.transport;this.pub&&this.sub&&this.perf.measure(`pubsub`,`pubStart`,`subStop`),this.req&&this.rep&&this.perf.measure(`reqrep`,`reqStart`,`reqStop`);let n=this.perf.getEntries(),r=n.find(e=>e.name===`pubsub`),i=n.find(e=>e.name===`reqrep`),a=n.find(e=>e.name===`req`),o=n.find(e=>e.name===`rep`),s=n.find(e=>e.name===`pub`),c=n.find(e=>e.name===`sub`),l=this.nc.stats(),u=[];if(r){let{name:n,duration:i}=r,a=new _o(n,i);a.msgs=this.msgs*2,a.bytes=l.inBytes+l.outBytes,a.lang=e,a.version=t,a.payload=this.payload.length,u.push(a)}if(i){let{name:n,duration:r}=i,a=new _o(n,r);a.msgs=this.msgs*2,a.bytes=l.inBytes+l.outBytes,a.lang=e,a.version=t,a.payload=this.payload.length,u.push(a)}if(s){let{name:n,duration:r}=s,i=new _o(n,r);i.msgs=this.msgs,i.bytes=l.outBytes,i.lang=e,i.version=t,i.payload=this.payload.length,u.push(i)}if(c){let{name:n,duration:r}=c,i=new _o(n,r);i.msgs=this.msgs,i.bytes=l.inBytes,i.lang=e,i.version=t,i.payload=this.payload.length,u.push(i)}if(o){let{name:n,duration:r}=o,i=new _o(n,r);i.msgs=this.msgs,i.bytes=l.inBytes+l.outBytes,i.lang=e,i.version=t,i.payload=this.payload.length,u.push(i)}if(a){let{name:n,duration:r}=a,i=new _o(n,r);i.msgs=this.msgs,i.bytes=l.inBytes+l.outBytes,i.lang=e,i.version=t,i.payload=this.payload.length,u.push(i)}return u}async runCallbacks(){let e=[];if(this.sub){let t=xr();e.push(t);let n=0;this.nc.subscribe(this.subject,{max:this.msgs,callback:()=>{n++,n===1&&this.perf.mark(`subStart`),n===this.msgs&&(this.perf.mark(`subStop`),this.perf.measure(`sub`,`subStart`,`subStop`),t.resolve())}})}if(this.rep){let t=xr();e.push(t);let n=0;this.nc.subscribe(this.subject,{max:this.msgs,callback:(e,r)=>{r.respond(this.payload),n++,n===1&&this.perf.mark(`repStart`),n===this.msgs&&(this.perf.mark(`repStop`),this.perf.measure(`rep`,`repStart`,`repStop`),t.resolve())}})}if(this.pub){let t=(async()=>{this.perf.mark(`pubStart`);for(let e=0;e<this.msgs;e++)this.nc.publish(this.subject,this.payload);await this.nc.flush(),this.perf.mark(`pubStop`),this.perf.measure(`pub`,`pubStart`,`pubStop`)})();e.push(t)}if(this.req){let t=(async()=>{if(this.asyncRequests){this.perf.mark(`reqStart`);let e=[];for(let t=0;t<this.msgs;t++)e.push(this.nc.request(this.subject,this.payload,{timeout:2e4}));await Promise.all(e),this.perf.mark(`reqStop`),this.perf.measure(`req`,`reqStart`,`reqStop`)}else{this.perf.mark(`reqStart`);for(let e=0;e<this.msgs;e++)await this.nc.request(this.subject);this.perf.mark(`reqStop`),this.perf.measure(`req`,`reqStart`,`reqStop`)}})();e.push(t)}await Promise.all(e)}async runAsync(){let e=[];if(this.rep){let t=!1,n=this.nc.subscribe(this.subject,{max:this.msgs}),r=(async()=>{for await(let e of n)t||=(this.perf.mark(`repStart`),!0),e.respond(this.payload);await this.nc.flush(),this.perf.mark(`repStop`),this.perf.measure(`rep`,`repStart`,`repStop`)})();e.push(r)}if(this.sub){let t=!1,n=this.nc.subscribe(this.subject,{max:this.msgs}),r=(async()=>{for await(let e of n)t||=(this.perf.mark(`subStart`),!0);this.perf.mark(`subStop`),this.perf.measure(`sub`,`subStart`,`subStop`)})();e.push(r)}if(this.pub){let t=(async()=>{this.perf.mark(`pubStart`);for(let e=0;e<this.msgs;e++)this.nc.publish(this.subject,this.payload);await this.nc.flush(),this.perf.mark(`pubStop`),this.perf.measure(`pub`,`pubStart`,`pubStop`)})();e.push(t)}if(this.req){let t=(async()=>{if(this.asyncRequests){this.perf.mark(`reqStart`);let e=[];for(let t=0;t<this.msgs;t++)e.push(this.nc.request(this.subject,this.payload,{timeout:2e4}));await Promise.all(e),this.perf.mark(`reqStop`),this.perf.measure(`req`,`reqStart`,`reqStop`)}else{this.perf.mark(`reqStart`);for(let e=0;e<this.msgs;e++)await this.nc.request(this.subject);this.perf.mark(`reqStop`),this.perf.measure(`req`,`reqStart`,`reqStop`)}})();e.push(t)}await Promise.all(e)}}})),bo,xo=n((()=>{bo=class{interval;maxOut;cancelAfter;timer;autoCancelTimer;last;missed;count;callback;constructor(e,t,n={maxOut:2}){this.interval=e,this.maxOut=n?.maxOut||2,this.cancelAfter=n?.cancelAfter||0,this.last=Date.now(),this.missed=0,this.count=0,this.callback=t,this._schedule()}cancel(){this.autoCancelTimer&&clearTimeout(this.autoCancelTimer),this.timer&&clearInterval(this.timer),this.timer=0,this.autoCancelTimer=0,this.missed=0}work(){this.last=Date.now(),this.missed=0}_change(e,t=0,n=2){this.interval=e,this.maxOut=n,this.cancelAfter=t,this.restart()}restart(){this.cancel(),this._schedule()}_schedule(){this.cancelAfter>0&&(this.autoCancelTimer=setTimeout(()=>{this.cancel()},this.cancelAfter)),this.timer=setInterval(()=>{if(this.count++,Date.now()-this.last>this.interval&&this.missed++,this.missed>=this.maxOut)try{this.callback(this.missed)===!0&&this.cancel()}catch(e){console.log(e)}},this.interval)}}})),So,Co=n((()=>{So=`3.4.0`}));function wo(e,t){/^(.*:\/\/)(.*)/.test(e)||(e=typeof t==`boolean`?`${t===!0?`https`:`http`}://${e}`:`https://${e}`);let n=new URL(e),r=n.protocol.toLowerCase();r===`ws:`&&(t=!1),r===`wss:`&&(t=!0),r!==`https:`&&r!==`http`&&(e=e.replace(/^(.*:\/\/)(.*)/gm,`$2`),n=new URL(`http://${e}`));let i,a,o=n.hostname,s=n.pathname,c=n.search||``;switch(r){case`http:`:case`ws:`:case`nats:`:a=n.port||`80`,i=`ws:`;break;case`https:`:case`wss:`:case`tls:`:a=n.port||`443`,i=`wss:`;break;default:a=n.port||t===!0?`443`:`80`,i=t===!0?`wss:`:`ws:`;break}return`${i}//${o}:${a}${s}${c}`}function To(e={}){return qr({defaultPort:443,urlParseFn:wo,factory:()=>{if(e.tls)throw nr.format(`tls`,`is not configurable on w3c websocket connections`);return new Oo}}),lo.connect(e)}var Eo,Do,Oo,ko=n((()=>{Pr(),ii(),Ua(),Kr(),ro(),fo(),Co(),hr(),Eo=So,Do=`nats.ws`,Oo=class{version;lang;closeError;connected;done;socket;options;socketClosed;encrypted;peeked;yields;signal;closedNotification;pendingConnect;constructor(){this.version=Eo,this.lang=Do,this.connected=!1,this.done=!1,this.socketClosed=!1,this.encrypted=!1,this.peeked=!1,this.yields=[],this.signal=xr(),this.closedNotification=xr(),this.pendingConnect=null}async connect(e,t){let n=xr();this.pendingConnect=n,this.options=t;let r=e.src;if(t.wsFactory){let{socket:n,encrypted:r}=await t.wsFactory(e.src,t);this.socket=n,this.encrypted=r}else this.encrypted=r.indexOf(`wss://`)===0,this.socket=new WebSocket(r);return this.socket.binaryType=`arraybuffer`,this.socket.onopen=()=>{this.done&&this._closed(Error(`aborted`))},this.socket.onmessage=e=>{if(this.done)return;if(this.yields.push(new Uint8Array(e.data)),this.peeked){this.signal.resolve();return}let r=Gr.concat(...this.yields),i=$r(r);if(i!==``){let e=qa.exec(i);if(!e){t.debug&&console.error(`!!!`,_r(r)),n.reject(Error(`unexpected response from server`));return}try{Ra(JSON.parse(e[1]),this.options),this.peeked=!0,this.connected=!0,this.signal.resolve(),n.resolve()}catch(e){n.reject(e);return}}},this.socket.onclose=e=>{let t;e.code>=4e3&&e.code<=4999?t=Error(e.reason||`close code ${e.code}`):!e.wasClean&&e.reason!==``&&(t=Error(e.reason)),this._closed(t),this._cleanup()},this.socket.onerror=e=>{if(this.done)return;let t=e,r=new mr.ConnectionError(t.message);n.reject(r),this._cleanup()},n}_cleanup(){this.socketClosed===!1&&(this.socketClosed=!0,this.socket.onopen=null,this.socket.onmessage=null,this.socket.onerror=null,this.socket.onclose=null,this.closedNotification.resolve(this.closeError))}disconnect(){this._closed(void 0,!0)}async _closed(e,t=!0){if(this.pendingConnect?.reject(e??new mr.ConnectionError(`transport closed during handshake`)),this.done){try{this.socket.close()}catch{}return}if(this.closeError=e,!e){let e=Date.now();for(;!this.socketClosed&&this.socket.bufferedAmount>0&&!(Date.now()-e>=3e3);)await yr(100)}this.done=!0;try{this.socket.close()}catch{}return this._cleanup(),this.closedNotification}get isClosed(){return this.done}[Symbol.asyncIterator](){return this.iterate()}async*iterate(){for(;;){if(this.done)return;this.yields.length===0&&await this.signal;let e=this.yields;this.yields=[];for(let t=0;t<e.length;t++)this.options.debug&&console.info(`> ${_r(e[t])}`),yield e[t];if(this.done)break;this.yields.length===0&&(e.length=0,this.yields=e,this.signal=xr())}}isEncrypted(){return this.connected&&this.encrypted}send(e){if(!this.done)try{this.socket.send(e.buffer),this.options.debug&&console.info(`< ${_r(e)}`);return}catch(t){this.options.debug&&console.error(`!!! ${_r(e)}: ${t}`)}}close(e){return this._closed(e,!1)}closed(){return this.closedNotification}discard(){this.socket?.close()}}})),Ao=i({AuthorizationError:()=>ar,Bench:()=>vo,ClosedConnectionError:()=>or,Connect:()=>Qa,ConnectionError:()=>cr,DEFAULT_MAX_RECONNECT_ATTEMPTS:()=>10,DataBuffer:()=>Gr,DenoBuffer:()=>Hi,DrainingConnectionError:()=>sr,Empty:()=>Zn,Feature:()=>ca,Features:()=>la,Heartbeat:()=>Ni,INFO:()=>qa,IdleHeartbeatMonitor:()=>bo,InvalidArgumentError:()=>nr,InvalidOperationError:()=>rr,InvalidSubjectError:()=>tr,Kind:()=>Ki,MAX_SIZE:()=>Vi,Match:()=>Vr,Metric:()=>_o,MsgHdrsImpl:()=>na,MsgImpl:()=>ia,MuxSubscription:()=>ji,NatsConnectionImpl:()=>lo,NoRespondersError:()=>fr,Nuid:()=>Lr.Nuid,Parser:()=>Xi,PermissionViolationError:()=>pr,ProtocolError:()=>lr,ProtocolHandler:()=>no,QueuedIteratorImpl:()=>ki,RequestError:()=>ur,RequestOne:()=>oo,Servers:()=>Di,SimpleMutex:()=>Ar,State:()=>Y,SubscriptionImpl:()=>eo,Subscriptions:()=>to,TD:()=>$n,TE:()=>Qn,TimeoutError:()=>dr,UserAuthenticationExpiredError:()=>ir,backoff:()=>Tr,buildAuthenticator:()=>Ia,canonicalMIMEHeaderKey:()=>$i,checkOptions:()=>Ra,checkUnsupportedOption:()=>za,collect:()=>Cr,compare:()=>sa,createInbox:()=>Br,credsAuthenticator:()=>Ma,deadline:()=>br,defaultOptions:()=>Pa,deferred:()=>xr,delay:()=>yr,describe:()=>Wi,errors:()=>mr,extend:()=>gr,extractProtocolMessage:()=>$r,getResolveFn:()=>Zr,hasWsProtocol:()=>Fa,headers:()=>ea,ipV4:()=>ai,isIP:()=>oi,isIPV4OrHostname:()=>Si,jwtAuthenticator:()=>ja,millis:()=>Dr,nanos:()=>Er,nkeyAuthenticator:()=>Aa,nkeys:()=>wa,nuid:()=>Lr.nuid,parseIP:()=>si,parseOptions:()=>La,parseSemVer:()=>oa,protoLen:()=>Qr,readAll:()=>Li,render:()=>_r,setTransportFactory:()=>qr,syncIterator:()=>zr,timeout:()=>vr,tokenAuthenticator:()=>ka,usernamePasswordAuthenticator:()=>Oa,writeAll:()=>Ri,wsUrlParseFn:()=>wo,wsconnect:()=>To}),jo=n((()=>{fo(),Rr(),aa(),ii(),ro(),Pr(),ra(),Pi(),Mi(),Kr(),Ua(),so(),Na(),Ta(),Ai(),Qi(),Ui(),yo(),er(),xi(),ua(),po(),Wr(),xo(),Oi(),ko(),hr()})),Mo=class{client;channelId;closed=!1;unsubscribe;initialized=!1;subject;requestSubject;handlers=new Map;closeHandlers=new Set;errorHandlers=new Set;subscriptions=[];get isClosed(){return this.closed}get id(){return this.channelId}constructor(e,t){this.client=e,this.channelId=t,this.subject=`channel.${t}`,this.requestSubject=`channel.${t}.request`}async init(){this.initialized||(this.initialized=!0,this.unsubscribe=await this.client.subscribe(this.subject,async e=>{switch(e.type){case`message`:this.emit(`message`,e.data);break;case`close`:this.handleClose();break;case`error`:this.handleError(Error(e.error??`Channel error`));break}}))}async send(e){if(this.closed)throw Error(`Channel is closed`);let t={type:`message`,data:e};await this.client.publish(this.subject,t)}async request(e,t=5e3){if(this.closed)throw Error(`Channel is closed`);return this.client.request(this.requestSubject,e,{timeout:t})}async onRequest(e){let t=this.client.onRequest(this.requestSubject,e);return this.subscriptions.push(t),t}on(e,t){e===`close`?this.closeHandlers.add(t):e===`error`?this.errorHandlers.add(t):(this.handlers.has(e)||this.handlers.set(e,new Set),this.handlers.get(e).add(t))}off(e,t){e===`close`?this.closeHandlers.delete(t):e===`error`?this.errorHandlers.delete(t):this.handlers.get(e)?.delete(t)}async close(){if(!this.closed){this.closed=!0;try{await this.client.publish(this.subject,{type:`close`})}catch{}await this.cleanup()}}handlerChain=Promise.resolve();runHandler(e,t,n){this.handlerChain=this.handlerChain.then(()=>e(t)).catch(e=>console.error(`Error in ${n}:`,e))}emit(e,t){let n=this.handlers.get(e);if(n)for(let e of n)this.runHandler(e,t,`channel handler`)}handleClose(){if(!this.closed){this.closed=!0;for(let e of this.closeHandlers)this.runHandler(()=>e(),void 0,`close handler`);this.cleanup().catch(console.error)}}handleError(e){for(let t of this.errorHandlers)this.runHandler(t,e,`error handler`)}async cleanup(){if(this.handlers.clear(),this.closeHandlers.clear(),this.errorHandlers.clear(),await Promise.allSettled(this.subscriptions.map(async e=>(await e)())),this.subscriptions=[],this.unsubscribe){try{this.unsubscribe()}catch{}this.unsubscribe=void 0}let e=this._isolatedClient;if(e)try{await e.disconnect()}catch{}}},No=class extends Mo{targetClientId;clientId;remoteClientId;privateSubject;privateRequestSubject;get remoteId(){return this.remoteClientId}constructor(e,t,n){super(e,t),this.targetClientId=n;let r=e.options.name??`client-${Date.now()}`;this.clientId=r.replace(/-(channel|private)-.*$/,``);let i=[this.clientId,this.targetClientId].sort();this.privateSubject=`channel.private.${t}.${i.join(`.`)}`,this.privateRequestSubject=`${this.privateSubject}.request`}async init(){if(!this.initialized){this.initialized=!0,this.unsubscribe=await this.client.subscribe(this.privateSubject,async e=>{if(e.sender!==this.clientId&&e.sender===this.targetClientId&&(!this.remoteClientId&&e.sender&&(this.remoteClientId=e.sender),!(this.remoteClientId&&e.sender!==this.remoteClientId)))switch(e.type){case`message`:if(e.data&&typeof e.data==`object`&&`__handshake`in e.data)return;this.emit(`message`,e.data);break;case`close`:this.handleClose();break;case`error`:this.handleError(Error(e.error??`Channel error`));break}});try{await this.sendRaw({type:`message`,data:{__handshake:!0},sender:this.clientId})}catch{}}}async send(e){if(this.closed)throw Error(`Channel is closed`);await this.sendRaw({type:`message`,data:e,sender:this.clientId})}async request(e,t=5e3){if(this.closed)throw Error(`Channel is closed`);return this.client.request(this.privateRequestSubject,e,{timeout:t})}async onRequest(e){return this.client.onRequest(this.privateRequestSubject,e)}async close(){if(!this.closed){this.closed=!0;try{await this.sendRaw({type:`close`,sender:this.clientId})}catch{}await this.cleanup()}}isConnectedTo(e){return this.remoteClientId===e}async sendRaw(e){await this.client.publish(this.privateSubject,e)}},Po;try{Po=new TextDecoder}catch{}var X,Fo,Z=0,Io=[],Lo=Io,Ro=0,zo={},Bo,Vo,Ho=0,Uo=0,Wo,Go,Ko=[],qo,Jo={useRecords:!1,mapsAsObjects:!0},Yo=class{},Xo=new Yo;Xo.name=`MessagePack 0xC1`;var Zo=!1,Qo=2,$o=class e{constructor(e){e&&(e.useRecords===!1&&e.mapsAsObjects===void 0&&(e.mapsAsObjects=!0),e.sequential&&e.trusted!==!1&&(e.trusted=!0,!e.structures&&e.useRecords!=0&&(e.structures=[],e.maxSharedStructures||=0)),e.structures?e.structures.sharedLength=e.structures.length:e.getStructures&&((e.structures=[]).uninitialized=!0,e.structures.sharedLength=0),e.int64AsNumber&&(e.int64AsType=`number`)),Object.assign(this,e)}unpack(t,n){if(X)return Os(()=>(ks(),this?this.unpack(t,n):e.prototype.unpack.call(Jo,t,n)));!t.buffer&&t.constructor===ArrayBuffer&&(t=typeof Buffer<`u`?Buffer.from(t):new Uint8Array(t)),typeof n==`object`?(Fo=n.end||t.length,Z=n.start||0):(Z=0,Fo=n>-1?n:t.length),Ro=0,Uo=0,Vo=null,Lo=Io,Wo=null,X=t;try{qo=t.dataView||=new DataView(t.buffer,t.byteOffset,t.byteLength)}catch(e){throw X=null,t instanceof Uint8Array?e:Error(`Source must be a Uint8Array or Buffer but was a `+(t&&typeof t==`object`?t.constructor.name:typeof t))}if(this instanceof e){if(zo=this,this.structures)return Bo=this.structures,es(n);(!Bo||Bo.length>0)&&(Bo=[])}else zo=Jo,(!Bo||Bo.length>0)&&(Bo=[]);return es(n)}unpackMultiple(e,t){let n,r=0;try{Zo=!0;let i=e.length,a=this?this.unpack(e,i):js.unpack(e,i);if(t){if(t(a,r,Z)===!1)return;for(;Z<i;)if(r=Z,t(es(),r,Z)===!1)return}else{for(n=[a];Z<i;)r=Z,n.push(es());return n}}catch(e){throw e.lastPosition=r,e.values=n,e}finally{Zo=!1,ks()}}_mergeStructures(e,t){this._onLoadedStructures&&(e=this._onLoadedStructures(e)),e||=[],Object.isFrozen(e)&&(e=e.map(e=>e.slice(0)));for(let t=0,n=e.length;t<n;t++){let n=e[t];n&&(n.isShared=!0,t>=32&&(n.highByte=t-32>>5))}e.sharedLength=e.length;for(let n in t||[])if(n>=0){let r=e[n],i=t[n];i&&(r&&((e.restoreStructures||=[])[n]=r),e[n]=i)}return this.structures=e}decode(e,t){return this.unpack(e,t)}};function es(e){try{if(!zo.trusted&&!Zo){let e=Bo.sharedLength||0;e<Bo.length&&(Bo.length=e)}let t;if(zo._readStruct&&X[Z]<64&&X[Z]>=32?(t=zo._readStruct(X,Z,Fo),X=null,!(e&&e.lazy)&&t&&(t=t.toJSON()),Z=Fo):t=ns(),Wo&&=(Z=Wo.postBundlePosition,null),Zo&&(Bo.restoreStructures=null),Z==Fo)Bo&&Bo.restoreStructures&&ts(),Bo=null,X=null,Go&&=null;else if(Z>Fo)throw Error(`Unexpected end of MessagePack data`);else if(!Zo){let e;try{e=JSON.stringify(t,(e,t)=>typeof t==`bigint`?`${t}n`:t).slice(0,100)}catch(t){e=`(JSON view not available `+t+`)`}throw Error(`Data read, but end of buffer not reached `+e)}return t}catch(e){throw Bo&&Bo.restoreStructures&&ts(),ks(),(e instanceof RangeError||e.message.startsWith(`Unexpected end of buffer`)||Z>Fo)&&(e.incomplete=!0),e}}function ts(){for(let e in Bo.restoreStructures)Bo[e]=Bo.restoreStructures[e];Bo.restoreStructures=null}function ns(){let e=X[Z++];if(e<160)if(e<128){if(e<64)return e;{let t=Bo[e&63]||zo.getStructures&&os()[e&63];return t?(t.read||=is(t,e&63),t.read()):e}}else if(e<144)if(e-=128,zo.mapsAsObjects){let t={};for(let n=0;n<e;n++){let e=xs();e===`__proto__`&&(e=`__proto_`),t[e]=ns()}return t}else{let t=new Map;for(let n=0;n<e;n++)t.set(ns(),ns());return t}else{e-=144;let t=Array(e);for(let n=0;n<e;n++)t[n]=ns();return zo.freezeData?Object.freeze(t):t}else if(e<192){let t=e-160;if(Uo>=Z)return Vo.slice(Z-Ho,(Z+=t)-Ho);if(Uo==0&&Fo<140){let e=t<16?gs(t):hs(t);if(e!=null)return e}return ss(t)}else{let t;switch(e){case 192:return null;case 193:return Wo?(t=ns(),t>0?Wo[1].slice(Wo.position1,Wo.position1+=t):Wo[0].slice(Wo.position0,Wo.position0-=t)):Xo;case 194:return!1;case 195:return!0;case 196:if(t=X[Z++],t===void 0)throw Error(`Unexpected end of buffer`);return vs(t);case 197:return t=qo.getUint16(Z),Z+=2,vs(t);case 198:return t=qo.getUint32(Z),Z+=4,vs(t);case 199:return ys(X[Z++]);case 200:return t=qo.getUint16(Z),Z+=2,ys(t);case 201:return t=qo.getUint32(Z),Z+=4,ys(t);case 202:if(t=qo.getFloat32(Z),zo.useFloat32>2){let e=As[(X[Z]&127)<<1|X[Z+1]>>7];return Z+=4,(e*t+(t>0?.5:-.5)>>0)/e}return Z+=4,t;case 203:return t=qo.getFloat64(Z),Z+=8,t;case 204:return X[Z++];case 205:return t=qo.getUint16(Z),Z+=2,t;case 206:return t=qo.getUint32(Z),Z+=4,t;case 207:return zo.int64AsType===`number`?(t=qo.getUint32(Z)*4294967296,t+=qo.getUint32(Z+4)):zo.int64AsType===`string`?t=qo.getBigUint64(Z).toString():zo.int64AsType===`auto`?(t=qo.getBigUint64(Z),t<=BigInt(2)<<BigInt(52)&&(t=Number(t))):t=qo.getBigUint64(Z),Z+=8,t;case 208:return qo.getInt8(Z++);case 209:return t=qo.getInt16(Z),Z+=2,t;case 210:return t=qo.getInt32(Z),Z+=4,t;case 211:return zo.int64AsType===`number`?(t=qo.getInt32(Z)*4294967296,t+=qo.getUint32(Z+4)):zo.int64AsType===`string`?t=qo.getBigInt64(Z).toString():zo.int64AsType===`auto`?(t=qo.getBigInt64(Z),t>=BigInt(-2)<<BigInt(52)&&t<=BigInt(2)<<BigInt(52)&&(t=Number(t))):t=qo.getBigInt64(Z),Z+=8,t;case 212:if(t=X[Z++],t==114)return Cs(X[Z++]&63);{let e=Ko[t];if(e)return e.read?(Z++,e.read(ns())):e.noBuffer?(Z++,e()):e(X.subarray(Z,++Z));throw Error(`Unknown extension `+t)}case 213:return t=X[Z],t==114?(Z++,Cs(X[Z++]&63,X[Z++])):ys(2);case 214:return ys(4);case 215:return ys(8);case 216:return ys(16);case 217:return t=X[Z++],Uo>=Z?Vo.slice(Z-Ho,(Z+=t)-Ho):cs(t);case 218:return t=qo.getUint16(Z),Z+=2,Uo>=Z?Vo.slice(Z-Ho,(Z+=t)-Ho):ls(t);case 219:return t=qo.getUint32(Z),Z+=4,Uo>=Z?Vo.slice(Z-Ho,(Z+=t)-Ho):us(t);case 220:return t=qo.getUint16(Z),Z+=2,fs(t);case 221:return t=qo.getUint32(Z),Z+=4,fs(t);case 222:return t=qo.getUint16(Z),Z+=2,ps(t);case 223:return t=qo.getUint32(Z),Z+=4,ps(t);default:if(e>=224)return e-256;if(e===void 0){let e=Error(`Unexpected end of MessagePack data`);throw e.incomplete=!0,e}throw Error(`Unknown MessagePack token `+e)}}}var rs=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function is(e,t){function n(){if(n.count++>Qo){let r;try{r=e.read=Function(`r`,`return function(){return `+(zo.freezeData?`Object.freeze`:``)+`({`+e.map(e=>e===`__proto__`?`__proto_:r()`:rs.test(e)?e+`:r()`:`[`+JSON.stringify(e)+`]:r()`).join(`,`)+`})}`)(ns)}catch{return Qo=1/0,n()}return e.read0=r,e.highByte===0&&(e.read=as(t,e.read)),r()}let r={};for(let t=0,n=e.length;t<n;t++){let n=e[t];n===`__proto__`&&(n=`__proto_`),r[n]=ns()}return zo.freezeData?Object.freeze(r):r}return n.count=0,e.read0=n,e.highByte===0?as(t,n):n}var as=(e,t)=>function(){let n=X[Z++];if(n===0)return t();let r=e<32?-(e+(n<<5)):e+(n<<5),i=Bo[r]||os()[r];if(!i)throw Error(`Record id is not defined for `+r);return i.read||=is(i,e),i.read()};function os(){let e=Os(()=>(X=null,zo.getStructures()));return Bo=zo._mergeStructures(e,Bo)}var ss=ds,cs=ds,ls=ds,us=ds;function ds(e){let t;if(e<16&&(t=gs(e)))return t;if(e>64&&Po)return Po.decode(X.subarray(Z,Z+=e));let n=Z+e,r=[];for(t=``;Z<n;){let e=X[Z++];if(!(e&128))r.push(e);else if((e&224)==192){let t=X[Z++]&63,n=(e&31)<<6|t;n<128?r.push(65533):r.push(n)}else if((e&240)==224){let t=X[Z++]&63,n=X[Z++]&63,i=(e&31)<<12|t<<6|n;i<2048||i>=55296&&i<=57343?r.push(65533):r.push(i)}else if((e&248)==240){let t=X[Z++]&63,n=X[Z++]&63,i=X[Z++]&63,a=(e&7)<<18|t<<12|n<<6|i;a<65536||a>1114111?r.push(65533):a>65535?(a-=65536,r.push(a>>>10&1023|55296),a=56320|a&1023,r.push(a)):r.push(a)}else r.push(65533);r.length>=4096&&(t+=ms.apply(String,r),r.length=0)}return r.length>0&&(t+=ms.apply(String,r)),t}function fs(e){let t=Array(e);for(let n=0;n<e;n++)t[n]=ns();return zo.freezeData?Object.freeze(t):t}function ps(e){if(zo.mapsAsObjects){let t={};for(let n=0;n<e;n++){let e=xs();e===`__proto__`&&(e=`__proto_`),t[e]=ns()}return t}else{let t=new Map;for(let n=0;n<e;n++)t.set(ns(),ns());return t}}var ms=String.fromCharCode;function hs(e){let t=Z,n=Array(e);for(let r=0;r<e;r++){let e=X[Z++];if((e&128)>0){Z=t;return}n[r]=e}return ms.apply(String,n)}function gs(e){if(e<4)if(e<2){if(e===0)return``;{let e=X[Z++];if((e&128)>1){--Z;return}return ms(e)}}else{let t=X[Z++],n=X[Z++];if((t&128)>0||(n&128)>0){Z-=2;return}if(e<3)return ms(t,n);let r=X[Z++];if((r&128)>0){Z-=3;return}return ms(t,n,r)}else{let t=X[Z++],n=X[Z++],r=X[Z++],i=X[Z++];if((t&128)>0||(n&128)>0||(r&128)>0||(i&128)>0){Z-=4;return}if(e<6){if(e===4)return ms(t,n,r,i);{let e=X[Z++];if((e&128)>0){Z-=5;return}return ms(t,n,r,i,e)}}else if(e<8){let a=X[Z++],o=X[Z++];if((a&128)>0||(o&128)>0){Z-=6;return}if(e<7)return ms(t,n,r,i,a,o);let s=X[Z++];if((s&128)>0){Z-=7;return}return ms(t,n,r,i,a,o,s)}else{let a=X[Z++],o=X[Z++],s=X[Z++],c=X[Z++];if((a&128)>0||(o&128)>0||(s&128)>0||(c&128)>0){Z-=8;return}if(e<10){if(e===8)return ms(t,n,r,i,a,o,s,c);{let e=X[Z++];if((e&128)>0){Z-=9;return}return ms(t,n,r,i,a,o,s,c,e)}}else if(e<12){let l=X[Z++],u=X[Z++];if((l&128)>0||(u&128)>0){Z-=10;return}if(e<11)return ms(t,n,r,i,a,o,s,c,l,u);let d=X[Z++];if((d&128)>0){Z-=11;return}return ms(t,n,r,i,a,o,s,c,l,u,d)}else{let l=X[Z++],u=X[Z++],d=X[Z++],f=X[Z++];if((l&128)>0||(u&128)>0||(d&128)>0||(f&128)>0){Z-=12;return}if(e<14){if(e===12)return ms(t,n,r,i,a,o,s,c,l,u,d,f);{let e=X[Z++];if((e&128)>0){Z-=13;return}return ms(t,n,r,i,a,o,s,c,l,u,d,f,e)}}else{let p=X[Z++],m=X[Z++];if((p&128)>0||(m&128)>0){Z-=14;return}if(e<15)return ms(t,n,r,i,a,o,s,c,l,u,d,f,p,m);let h=X[Z++];if((h&128)>0){Z-=15;return}return ms(t,n,r,i,a,o,s,c,l,u,d,f,p,m,h)}}}}}function _s(){let e=X[Z++],t;if(e<192)t=e-160;else switch(e){case 217:t=X[Z++];break;case 218:t=qo.getUint16(Z),Z+=2;break;case 219:t=qo.getUint32(Z),Z+=4;break;default:throw Error(`Expected string`)}return ds(t)}function vs(e){return zo.copyBuffers?Uint8Array.prototype.slice.call(X,Z,Z+=e):X.subarray(Z,Z+=e)}function ys(e){let t=X[Z++];if(Ko[t]){let n;return Ko[t](X.subarray(Z,n=Z+=e),e=>{Z=e;try{return ns()}finally{Z=n}})}else throw Error(`Unknown extension type `+t)}var bs=Array(4096);function xs(){let e=X[Z++];if(e>=160&&e<192){if(e-=160,Uo>=Z)return Vo.slice(Z-Ho,(Z+=e)-Ho);if(!(Uo==0&&Fo<180))return ss(e)}else return Z--,Ss(ns());let t=(e<<5^(e>1?qo.getUint16(Z):e>0?X[Z]:0))&4095,n=bs[t],r=Z,i=Z+e-3,a,o=0;if(n&&n.bytes==e){for(;r<i;){if(a=qo.getUint32(r),a!=n[o++]){r=1879048192;break}r+=4}for(i+=3;r<i;)if(a=X[r++],a!=n[o++]){r=1879048192;break}if(r===i)return Z=r,n.string;i-=3,r=Z}for(n=[],bs[t]=n,n.bytes=e;r<i;)a=qo.getUint32(r),n.push(a),r+=4;for(i+=3;r<i;)a=X[r++],n.push(a);let s=e<16?gs(e):hs(e);return s==null?n.string=ss(e):n.string=s}function Ss(e){if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`)return e.toString();if(e==null)return e+``;if(zo.allowArraysInMapKeys&&Array.isArray(e)&&e.flat().every(e=>[`string`,`number`,`boolean`,`bigint`].includes(typeof e)))return e.flat().toString();throw Error(`Invalid property type for record: ${typeof e}`)}var Cs=(e,t)=>{let n=ns().map(Ss),r=e;t!==void 0&&(e=e<32?-((t<<5)+e):(t<<5)+e,n.highByte=t);let i=Bo[e];return i&&(i.isShared||Zo)&&((Bo.restoreStructures||=[])[e]=i),Bo[e]=n,n.read=is(n,r),(n.read0||n.read)()};Ko[0]=()=>{},Ko[0].noBuffer=!0,Ko[66]=e=>{let t=e.byteLength%8||8,n=BigInt(e[0]&128?e[0]-256:e[0]);for(let r=1;r<t;r++)n<<=BigInt(8),n+=BigInt(e[r]);if(e.byteLength!==t){let r=new DataView(e.buffer,e.byteOffset,e.byteLength),i=(e,t)=>{let n=t-e;if(n<=40){let n=r.getBigUint64(e);for(let i=e+8;i<t;i+=8)n<<=BigInt(64),n|=r.getBigUint64(i);return n}let a=e+(n>>4<<3),o=i(e,a),s=i(a,t);return o<<BigInt((t-a)*8)|s};n=n<<BigInt((r.byteLength-t)*8)|i(t,r.byteLength)}return n};var ws={Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError,AggregateError:typeof AggregateError==`function`?AggregateError:null};Ko[101]=()=>{let e=ns();if(!ws[e[0]]){let t=Error(e[1],{cause:e[2]});return t.name=e[0],t}return ws[e[0]](e[1],{cause:e[2]})},Ko[105]=e=>{if(zo.structuredClone===!1)throw Error(`Structured clone extension is disabled`);let t=qo.getUint32(Z-4);Go||=new Map;let n=X[Z],r;r=n>=144&&n<160||n==220||n==221?[]:n>=128&&n<144||n==222||n==223?new Map:(n>=199&&n<=201||n>=212&&n<=216)&&X[Z+1]===115?new Set:{};let i={target:r};Go.set(t,i);let a=ns();if(i.used)Object.assign(r,a);else return i.target=a;if(r instanceof Map)for(let[e,t]of a.entries())r.set(e,t);if(r instanceof Set)for(let e of Array.from(a))r.add(e);return r},Ko[112]=e=>{if(zo.structuredClone===!1)throw Error(`Structured clone extension is disabled`);let t=qo.getUint32(Z-4),n=Go.get(t);return n.used=!0,n.target},Ko[115]=()=>new Set(ns());var Ts=[`Int8`,`Uint8`,`Uint8Clamped`,`Int16`,`Uint16`,`Int32`,`Uint32`,`Float32`,`Float64`,`BigInt64`,`BigUint64`].map(e=>e+`Array`),Es=typeof globalThis==`object`?globalThis:window;Ko[116]=e=>{let t=e[0],n=Uint8Array.prototype.slice.call(e,1).buffer,r=Ts[t];if(!r){if(t===16)return n;if(t===17)return new DataView(n);throw Error(`Could not find typed array for code `+t)}return new Es[r](n)},Ko[120]=()=>{let e=ns();return new RegExp(e[0],e[1])};var Ds=[];Ko[98]=e=>{let t=(e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3],n=Z;return Z+=t-e.length,Wo=Ds,Wo=[_s(),_s()],Wo.position0=0,Wo.position1=0,Wo.postBundlePosition=Z,Z=n,ns()},Ko[255]=e=>e.length==4?new Date((e[0]*16777216+(e[1]<<16)+(e[2]<<8)+e[3])*1e3):e.length==8?new Date(((e[0]<<22)+(e[1]<<14)+(e[2]<<6)+(e[3]>>2))/1e6+((e[3]&3)*4294967296+e[4]*16777216+(e[5]<<16)+(e[6]<<8)+e[7])*1e3):e.length==12?new Date(((e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3])/1e6+((e[4]&128?-281474976710656:0)+e[6]*1099511627776+e[7]*4294967296+e[8]*16777216+(e[9]<<16)+(e[10]<<8)+e[11])*1e3):new Date(`invalid`);function Os(e){zo&&zo._onSaveState&&zo._onSaveState();let t=Fo,n=Z,r=Ro,i=Ho,a=Uo,o=Vo,s=Lo,c=Go,l=Wo,u=new Uint8Array(X.slice(0,Fo)),d=Bo,f=Bo.slice(0,Bo.length),p=zo,m=Zo,h=e();return Fo=t,Z=n,Ro=r,Ho=i,Uo=a,Vo=o,Lo=s,Go=c,Wo=l,X=u,Zo=m,Bo=d,Bo.splice(0,Bo.length,...f),zo=p,qo=new DataView(X.buffer,X.byteOffset,X.byteLength),h}function ks(){X=null,Go=null,Bo=null}var As=Array(147);for(let e=0;e<256;e++)As[e]=+(`1e`+Math.floor(45.15-e*.30103));var js=new $o({useRecords:!1});js.unpack,js.unpackMultiple,js.unpack;var Ms={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4};new Uint8Array(new Float32Array(1).buffer,0,4),$o.SUPPORTS_STRUCT_HOOKS=!0;var Ns;try{Ns=new TextEncoder}catch{}var Ps,Fs,Is=typeof Buffer<`u`,Ls=Is?function(e){return Buffer.allocUnsafeSlow(e)}:Uint8Array,Rs=Is?Buffer:Uint8Array,zs=Is?4294967296:2144337920,Q,Bs,Vs,$=0,Hs,Us=null,Ws=21760,Gs=/[\u0080-\uFFFF]/,Ks=Symbol(`record-id`),qs=class extends $o{constructor(e){super(e),this.offset=0;let t,n,r,i,a=Rs.prototype.utf8Write?function(e,t){return Q.utf8Write(e,t,Q.byteLength-t)}:Ns&&Ns.encodeInto?function(e,t){return Ns.encodeInto(e,Q.subarray(t)).written}:!1,o=this;e||={};let s=e&&e.sequential,c=e.structures||e.saveStructures,l=e.maxSharedStructures;if(l??=c?32:0,l>8160)throw Error(`Maximum maxSharedStructure is 8160`);e.structuredClone&&e.moreTypes==null&&(this.moreTypes=!0);let u=e.maxOwnStructures;u??=c?32:64,!this.structures&&e.useRecords!=0&&(this.structures=[]);let d=l>32||u+l>64,f=l+64,p=l+u+64;if(p>8256)throw Error(`Maximum maxSharedStructure + maxOwnStructure is 8192`);let m=[],h=0,g=0;this.pack=this.encode=function(e,a){if(Q||(Q=new Ls(8192),Vs=Q.dataView||=new DataView(Q.buffer,0,8192),$=0),Hs=Q.length-10,Hs-$<2048?(Q=new Ls(Q.length),Vs=Q.dataView||=new DataView(Q.buffer,0,Q.length),Hs=Q.length-10,$=0):$=$+7&2147483640,t=$,a&2048&&($+=a&255),i=o.structuredClone?new Map:null,o.bundleStrings&&typeof e!=`string`?(Us=[],Us.size=1/0):Us=null,r=o.structures,r){r.uninitialized&&(r=o._mergeStructures(o.getStructures()));let e=r.sharedLength||0;if(e>l)throw Error(`Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to `+r.sharedLength);if(!r.transitions){r.transitions=Object.create(null);for(let t=0;t<e;t++){let e=r[t];if(!e)continue;let n,i=r.transitions;for(let t=0,r=e.length;t<r;t++){let r=e[t];n=i[r],n||=i[r]=Object.create(null),i=n}i[Ks]=t+64}this.lastNamedStructuresLength=e}s||(r.nextId=e+64)}n&&=!1;let c;try{o._writeStruct&&e&&typeof e==`object`?e.constructor===Object?w(e):e.constructor!==Map&&!Array.isArray(e)&&!Fs.some(t=>e instanceof t)?w(e.toJSON?e.toJSON():e):y(e):y(e);let n=Us;if(Us&&Qs(t,y,0),i&&i.idsToInsert){let e=i.idsToInsert.sort((e,t)=>e.offset>t.offset?1:-1),r=e.length,a=-1;for(;n&&r>0;){let i=e[--r].offset+t;i<n.stringsPosition+t&&a===-1&&(a=0),i>n.position+t?a>=0&&(a+=6):(a>=0&&(Vs.setUint32(n.position+t,Vs.getUint32(n.position+t)+a),a=-1),n=n.previous,r++)}a>=0&&n&&Vs.setUint32(n.position+t,Vs.getUint32(n.position+t)+a),$+=e.length*6,$>Hs&&T($),o.offset=$;let s=Zs(Q.subarray(t,$),e);return i=null,s}return o.offset=$,a&512?(Q.start=t,Q.end=$,Q):Q.subarray(t,$)}catch(e){throw c=e,e}finally{if(r&&(_(),n&&o.saveStructures)){let n=r.sharedLength||0,i=Q.subarray(t,$),s=(o._prepareStructures||$s)(r,o);if(!c)return o.saveStructures(s,s.isCompatible)===!1?(r.uninitialized=!0,o.pack(e,a)):(o.lastNamedStructuresLength=n,Q.length>1073741824&&(Q=null),i)}Q.length>1073741824&&(Q=null),a&1024&&($=t)}};let _=()=>{g<10&&g++;let e=r.sharedLength||0;if(r.length>e&&!s&&(r.length=e),h>1e4)r.transitions=null,g=0,h=0,m.length>0&&(m=[]);else if(m.length>0&&!s){for(let e=0,t=m.length;e<t;e++)m[e][Ks]=0;m=[]}},v=e=>{var t=e.length;t<16?Q[$++]=144|t:t<65536?(Q[$++]=220,Q[$++]=t>>8,Q[$++]=t&255):(Q[$++]=221,Vs.setUint32($,t),$+=4);for(let n=0;n<t;n++)y(e[n])},y=e=>{$>Hs&&(Q=T($));var n=typeof e,r;if(n===`string`){let n=e.length;if(Us&&n>=4&&n<4096){if((Us.size+=n)>Ws){let e,n=(Us[0]?Us[0].length*3+Us[1].length:0)+10;$+n>Hs&&(Q=T($+n));let r;Us.position?(r=Us,Q[$]=200,$+=3,Q[$++]=98,e=$-t,$+=4,Qs(t,y,0),Vs.setUint16(e+t-3,$-t-e)):(Q[$++]=214,Q[$++]=98,e=$-t,$+=4),Us=[``,``],Us.previous=r,Us.size=0,Us.position=e}let r=Gs.test(e);Us[+!r]+=e,Q[$++]=193,y(r?-n:n);return}let i;i=n<32?1:n<256?2:n<65536?3:5;let o=n*3;if($+o>Hs&&(Q=T($+o)),n<64||!a){let t,a,o,s=$+i;for(t=0;t<n;t++)a=e.charCodeAt(t),a<128?Q[s++]=a:a<2048?(Q[s++]=a>>6|192,Q[s++]=a&63|128):(a&64512)==55296&&((o=e.charCodeAt(t+1))&64512)==56320?(a=65536+((a&1023)<<10)+(o&1023),t++,Q[s++]=a>>18|240,Q[s++]=a>>12&63|128,Q[s++]=a>>6&63|128,Q[s++]=a&63|128):(Q[s++]=a>>12|224,Q[s++]=a>>6&63|128,Q[s++]=a&63|128);r=s-$-i}else r=a(e,$+i);r<32?Q[$++]=160|r:r<256?(i<2&&Q.copyWithin($+2,$+1,$+1+r),Q[$++]=217,Q[$++]=r):r<65536?(i<3&&Q.copyWithin($+3,$+2,$+2+r),Q[$++]=218,Q[$++]=r>>8,Q[$++]=r&255):(i<5&&Q.copyWithin($+5,$+3,$+3+r),Q[$++]=219,Vs.setUint32($,r),$+=4),$+=r}else if(n===`number`)if(e>>>0===e)e<32||e<128&&this.useRecords===!1||e<64&&!this._writeStruct?Q[$++]=e:e<256?(Q[$++]=204,Q[$++]=e):e<65536?(Q[$++]=205,Q[$++]=e>>8,Q[$++]=e&255):(Q[$++]=206,Vs.setUint32($,e),$+=4);else if(e>>0===e)e>=-32?Q[$++]=256+e:e>=-128?(Q[$++]=208,Q[$++]=e+256):e>=-32768?(Q[$++]=209,Vs.setInt16($,e),$+=2):(Q[$++]=210,Vs.setInt32($,e),$+=4);else{let t;if((t=this.useFloat32)>0&&e<4294967296&&e>=-2147483648){Q[$++]=202,Vs.setFloat32($,e);let n;if(t<4||(n=e*As[(Q[$]&127)<<1|Q[$+1]>>7])>>0===n){$+=4;return}else $--}Q[$++]=203,Vs.setFloat64($,e),$+=8}else if(n===`object`||n===`function`)if(!e)Q[$++]=192;else{if(i){let n=i.get(e);if(n){n.id||=(i.idsToInsert||=[]).push(n),Q[$++]=214,Q[$++]=112,Vs.setUint32($,n.id),$+=4;return}else i.set(e,{offset:$-t})}let a=e.constructor;if(a===Object)C(e);else if(a===Array)v(e);else if(a===Map)if(this.mapAsEmptyObject)Q[$++]=128;else{r=e.size,r<16?Q[$++]=128|r:r<65536?(Q[$++]=222,Q[$++]=r>>8,Q[$++]=r&255):(Q[$++]=223,Vs.setUint32($,r),$+=4);for(let[t,n]of e)y(t),y(n)}else{for(let t=0,n=Ps.length;t<n;t++){let n=Fs[t];if(e instanceof n){let n=Ps[t];if(n.write){n.type&&(Q[$++]=212,Q[$++]=n.type,Q[$++]=0);let t=n.write.call(this,e);t===e?Array.isArray(e)?v(e):C(e):y(t);return}let r=Q,i=Vs,a=$;Q=null;let o;try{o=n.pack.call(this,e,e=>(Q=r,r=null,$+=e,$>Hs&&T($),{target:Q,targetView:Vs,position:$-e}),y)}finally{r&&(Q=r,Vs=i,$=a,Hs=Q.length-10)}o&&(o.length+$>Hs&&T(o.length+$),$=Xs(o,Q,$,n.type));return}}if(Array.isArray(e))v(e);else{if(e.toJSON){let t=e.toJSON();if(t!==e)return y(t)}if(n===`function`)return y(this.writeFunction&&this.writeFunction(e));C(e)}}}else if(n===`boolean`)Q[$++]=e?195:194;else if(n===`bigint`){if(e<0x8000000000000000&&e>=-0x8000000000000000)Q[$++]=211,Vs.setBigInt64($,e);else if(e<0x10000000000000000&&e>0)Q[$++]=207,Vs.setBigUint64($,e);else if(this.largeBigIntToFloat)Q[$++]=203,Vs.setFloat64($,Number(e));else if(this.largeBigIntToString)return y(e.toString());else if(this.useBigIntExtension||this.moreTypes){let t=BigInt(e<0?-1:0),n;if(e>>BigInt(65536)===t){let r=BigInt(0x10000000000000000)-BigInt(1),i=[];for(;i.push(e&r),e>>BigInt(63)!==t;)e>>=BigInt(64);n=new Uint8Array(new BigUint64Array(i).buffer),n.reverse()}else{let t=e<0,r=(t?~e:e).toString(16);if(r.length%2?r=`0`+r:parseInt(r.charAt(0),16)>=8&&(r=`00`+r),Is)n=Buffer.from(r,`hex`);else{n=new Uint8Array(r.length/2);for(let e=0;e<n.length;e++)n[e]=parseInt(r.slice(e*2,e*2+2),16)}if(t)for(let e=0;e<n.length;e++)n[e]=~n[e]}n.length+$>Hs&&T(n.length+$),$=Xs(n,Q,$,66);return}else throw RangeError(e+` was too large to fit in MessagePack 64-bit integer format, use useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set largeBigIntToString to convert to string`);$+=8}else if(n===`undefined`)this.encodeUndefinedAsNil?Q[$++]=192:(Q[$++]=212,Q[$++]=0,Q[$++]=0);else throw Error(`Unknown type: `+n)},b=this.variableMapSize||this.coercibleKeyAsNumber||this.skipValues?e=>{let t;if(this.skipValues){t=[];for(let n in e)(typeof e.hasOwnProperty!=`function`||e.hasOwnProperty(n))&&!this.skipValues.includes(e[n])&&t.push(n)}else t=Object.keys(e);let n=t.length;n<16?Q[$++]=128|n:n<65536?(Q[$++]=222,Q[$++]=n>>8,Q[$++]=n&255):(Q[$++]=223,Vs.setUint32($,n),$+=4);let r;if(this.coercibleKeyAsNumber)for(let i=0;i<n;i++){r=t[i];let n=Number(r);y(isNaN(n)?r:n),y(e[r])}else for(let i=0;i<n;i++)y(r=t[i]),y(e[r])}:e=>{Q[$++]=222;let n=$-t;$+=2;let r=0;for(let t in e)(typeof e.hasOwnProperty!=`function`||e.hasOwnProperty(t))&&(y(t),y(e[t]),r++);if(r>65535)throw Error(`Object is too large to serialize with fast 16-bit map size, use the "variableMapSize" option to serialize this object`);Q[n+++t]=r>>8,Q[n+t]=r&255},x=this.useRecords===!1?b:e.progressiveRecords&&!d?e=>{let n,i=r.transitions||=Object.create(null),a=$++-t,o;for(let s in e)if(typeof e.hasOwnProperty!=`function`||e.hasOwnProperty(s)){if(n=i[s],n)i=n;else{let c=Object.keys(e),l=i;i=r.transitions;let u=0;for(let e=0,t=c.length;e<t;e++){let t=c[e];n=i[t],n||(n=i[t]=Object.create(null),u++),i=n}a+t+1==$?($--,E(i,c,u)):D(i,c,a,u),o=!0,i=l[s]}y(e[s])}if(!o){let n=i[Ks];n?Q[a+t]=n:D(i,Object.keys(e),a,0)}}:e=>{let t,n=r.transitions||=Object.create(null),i=0;for(let r in e)(typeof e.hasOwnProperty!=`function`||e.hasOwnProperty(r))&&(t=n[r],t||(t=n[r]=Object.create(null),i++),n=t);let a=n[Ks];a?a>=96&&d?(Q[$++]=((a-=96)&31)+96,Q[$++]=a>>5):Q[$++]=a:E(n,n.__keys__||Object.keys(e),i);for(let t in e)(typeof e.hasOwnProperty!=`function`||e.hasOwnProperty(t))&&y(e[t])},S=typeof this.useRecords==`function`&&this.useRecords,C=S?e=>{S(e)?x(e):b(e)}:x,w=e=>{let i=o._writeStruct(e,Q,t,$,r,T,(e,t,r)=>{if(r)return n=!0;$=t;let i=Q;return y(e),_(),i===Q?$:{position:$,targetView:Vs,target:Q}});if(i===0)return C(e);$=i},T=e=>{let n;if(e>16777216){if(e-t>zs)throw Error(`Packed buffer would be larger than maximum buffer size`);n=Math.min(zs,Math.round(Math.max((e-t)*(e>67108864?1.25:2),4194304)/4096)*4096)}else n=(Math.max(e-t<<2,Q.length-1)>>12)+1<<12;let r=new Ls(n);return Vs=r.dataView||=new DataView(r.buffer,0,n),e=Math.min(e,Q.length),Q.copy?Q.copy(r,0,t,e):r.set(Q.slice(t,e)),$-=t,t=0,Hs=r.length-10,Q=r},E=(e,t,i)=>{let a=r.nextId;a||=64,a<f&&this.shouldShareStructure&&!this.shouldShareStructure(t)?(a=r.nextOwnId,a<p||(a=f),r.nextOwnId=a+1):(a>=p&&(a=f),r.nextId=a+1);let o=t.highByte=a>=96&&d?a-96>>5:-1;e[Ks]=a,e.__keys__=t,r[a-64]=t,a<f?(t.isShared=!0,r.sharedLength=a-63,n=!0,o>=0?(Q[$++]=(a&31)+96,Q[$++]=o):Q[$++]=a):(o>=0?(Q[$++]=213,Q[$++]=114,Q[$++]=(a&31)+96,Q[$++]=o):(Q[$++]=212,Q[$++]=114,Q[$++]=a),i&&(h+=g*i),m.length>=u&&(m.shift()[Ks]=0),m.push(e),y(t))},D=(e,n,r,i)=>{let a=Q,o=$,s=Hs,c=t;Q=Bs,$=0,t=0,Q||(Bs=Q=new Ls(8192)),Hs=Q.length-10,E(e,n,i),Bs=Q;let l=$;if(Q=a,$=o,Hs=s,t=c,l>1){let e=$+l-1;e>Hs&&T(e);let n=r+t;Q.copyWithin(n+l,n+1,$),Q.set(Bs.slice(0,l),n),$=e}else Q[r+t]=Bs[0]}}useBuffer(e){Q=e,Q.dataView||=new DataView(Q.buffer,Q.byteOffset,Q.byteLength),Vs=Q.dataView,$=0}set position(e){$=e}get position(){return $}clearSharedData(){this.structures&&=[],this.typedStructs&&=[]}};Fs=[Date,Set,Error,RegExp,ArrayBuffer,Object.getPrototypeOf(Uint8Array.prototype).constructor,DataView,Yo],Ps=[{pack(e,t,n){let r=e.getTime()/1e3;if((this.useTimestamp32||e.getMilliseconds()===0)&&r>=0&&r<4294967296){let{target:e,targetView:n,position:i}=t(6);e[i++]=214,e[i++]=255,n.setUint32(i,r)}else if(r>0&&r<4294967296){let{target:n,targetView:i,position:a}=t(10);n[a++]=215,n[a++]=255,i.setUint32(a,e.getMilliseconds()*4e6+(r/1e3/4294967296>>0)),i.setUint32(a+4,r)}else if(isNaN(r)){if(this.onInvalidDate)return t(0),n(this.onInvalidDate());let{target:e,targetView:r,position:i}=t(3);e[i++]=212,e[i++]=255,e[i++]=255}else{let{target:n,targetView:i,position:a}=t(15);n[a++]=199,n[a++]=12,n[a++]=255,i.setUint32(a,e.getMilliseconds()*1e6),i.setBigInt64(a+4,BigInt(Math.floor(r)))}}},{pack(e,t,n){if(this.setAsEmptyObject)return t(0),n({});let r=Array.from(e),{target:i,position:a}=t(this.moreTypes?3:0);this.moreTypes&&(i[a++]=212,i[a++]=115,i[a++]=0),n(r)}},{pack(e,t,n){let{target:r,position:i}=t(this.moreTypes?3:0);this.moreTypes&&(r[i++]=212,r[i++]=101,r[i++]=0),n([e.name,e.message,e.cause])}},{pack(e,t,n){let{target:r,position:i}=t(this.moreTypes?3:0);this.moreTypes&&(r[i++]=212,r[i++]=120,r[i++]=0),n([e.source,e.flags])}},{pack(e,t){this.moreTypes?Js(e,16,t):Ys(Is?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let n=e.constructor;n!==Rs&&this.moreTypes?Js(e,Ts.indexOf(n.name),t):Ys(e,t)}},{pack(e,t){this.moreTypes?Js(e,17,t):Ys(Is?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let{target:n,position:r}=t(1);n[r]=193}}];function Js(e,t,n,r){let i=e.byteLength;if(i+1<256){var{target:a,position:o}=n(4+i);a[o++]=199,a[o++]=i+1}else if(i+1<65536){var{target:a,position:o}=n(5+i);a[o++]=200,a[o++]=i+1>>8,a[o++]=i+1&255}else{var{target:a,position:o,targetView:s}=n(7+i);a[o++]=201,s.setUint32(o,i+1),o+=4}a[o++]=116,a[o++]=t,e.buffer||(e=new Uint8Array(e)),a.set(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),o)}function Ys(e,t){let n=e.byteLength;var r,i;if(n<256){var{target:r,position:i}=t(n+2);r[i++]=196,r[i++]=n}else if(n<65536){var{target:r,position:i}=t(n+3);r[i++]=197,r[i++]=n>>8,r[i++]=n&255}else{var{target:r,position:i,targetView:a}=t(n+5);r[i++]=198,a.setUint32(i,n),i+=4}r.set(e,i)}function Xs(e,t,n,r){let i=e.length;switch(i){case 1:t[n++]=212;break;case 2:t[n++]=213;break;case 4:t[n++]=214;break;case 8:t[n++]=215;break;case 16:t[n++]=216;break;default:i<256?(t[n++]=199,t[n++]=i):i<65536?(t[n++]=200,t[n++]=i>>8,t[n++]=i&255):(t[n++]=201,t[n++]=i>>24,t[n++]=i>>16&255,t[n++]=i>>8&255,t[n++]=i&255)}return t[n++]=r,t.set(e,n),n+=i,n}function Zs(e,t){let n,r=t.length*6,i=e.length-r;for(;n=t.pop();){let t=n.offset,a=n.id;e.copyWithin(t+r,t,i),r-=6;let o=t+r;e[o++]=214,e[o++]=105,e[o++]=a>>24,e[o++]=a>>16&255,e[o++]=a>>8&255,e[o++]=a&255,i=t}return e}function Qs(e,t,n){if(Us.length>0){Vs.setUint32(Us.position+e,$+n-Us.position-e),Us.stringsPosition=$-e;let r=Us;Us=null,t(r[0]),t(r[1])}}function $s(e,t){return e.isCompatible=e=>{let n=!e||(t.lastNamedStructuresLength||0)===e.length;return n||t._mergeStructures(e),n},e}qs.SUPPORTS_STRUCT_HOOKS=!0;var ec=new qs({useRecords:!1});ec.pack,ec.pack;var{NEVER:tc,ALWAYS:nc,DECIMAL_ROUND:rc,DECIMAL_FIT:ic}=Ms,ac=new qs({useRecords:!1,bundleStrings:!1,int64AsType:`number`}),oc=new $o({useRecords:!1,bundleStrings:!1,int64AsType:`number`});function sc(e){return ac.pack(e)}function cc(e){return oc.unpack(e)}var lc=[67,85,73,66],uc=8,dc=`__cui_bin__`;function fc(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function pc(e){if(e instanceof Uint8Array)return e.byteLength>=16384?e:void 0;if(e instanceof ArrayBuffer)return e.byteLength>=16384?new Uint8Array(e):void 0}function mc(e,t){let n=pc(e);if(n){let e=t.length;return t.push(n),{[dc]:e,l:n.byteLength}}if(Array.isArray(e)){let n;for(let r=0;r<e.length;r++){let i=mc(e[r],t);i!==e[r]&&(n??=e.slice(),n[r]=i)}return n??e}if(fc(e)){let n;for(let r of Object.keys(e)){let i=mc(e[r],t);i!==e[r]&&(n??={...e},n[r]=i)}return n??e}return e}function hc(e){if(!fc(e))return!1;let t=e[dc],n=e.l;return!Number.isInteger(t)||t<0||!Number.isInteger(n)||n<0?!1:Object.keys(e).length===2}function gc(e,t,n){if(hc(e)){if(n.outOfOrder||e[dc]!==n.next)return n.outOfOrder=!0,e;let r=e.l,i=n.offset+r;if(i>t.byteLength)throw Error(`Invalid CUIB frame: segment ${n.next} exceeds payload size ${t.byteLength}`);let a=t.subarray(n.offset,i);return n.offset=i,n.next++,a}if(Array.isArray(e)){for(let r=0;r<e.length;r++)e[r]=gc(e[r],t,n);return e}if(fc(e)){for(let r of Object.keys(e))e[r]=gc(e[r],t,n);return e}return e}function _c(e,t){if(hc(e)){t[e[dc]]=e.l;return}if(Array.isArray(e)){for(let n of e)_c(n,t);return}if(fc(e))for(let n of Object.keys(e))_c(e[n],t)}function vc(e,t){if(hc(e))return t[e[dc]];if(Array.isArray(e)){for(let n=0;n<e.length;n++)e[n]=vc(e[n],t);return e}if(fc(e)){for(let n of Object.keys(e))e[n]=vc(e[n],t);return e}return e}function yc(e,t,n){let r=[];_c(e,r);let i=Array(r.length),a=n.offset;for(let e=n.next;e<r.length;e++){let n=r[e];if(n===void 0)throw Error(`Invalid CUIB frame: missing placeholder for segment ${e}`);if(a+n>t.byteLength)throw Error(`Invalid CUIB frame: segment ${e} exceeds payload size ${t.byteLength}`);i[e]=t.subarray(a,a+n),a+=n}return n.offset=a,vc(e,i)}function bc(e){let t=[],n=mc(e,t);if(t.length===0)return ac.pack(e);let r=ac.pack(n),i=r.byteLength,a=uc+i;for(let e of t)a+=e.byteLength;let o=typeof Buffer<`u`?Buffer.allocUnsafe(a):new Uint8Array(a);o[0]=lc[0],o[1]=lc[1],o[2]=lc[2],o[3]=lc[3],o[4]=i&255,o[5]=i>>>8&255,o[6]=i>>>16&255,o[7]=i>>>24&255,o.set(r,uc);let s=uc+r.byteLength;for(let e of t)o.set(e,s),s+=e.byteLength;return o}function xc(e){if(e.byteLength<uc||e[0]!==lc[0]||e[1]!==lc[1]||e[2]!==lc[2]||e[3]!==lc[3])return oc.unpack(e);let t=(e[4]|e[5]<<8|e[6]<<16)+e[7]*16777216,n=uc+t;if(n>e.byteLength)throw Error(`Invalid CUIB frame: envelope length ${t} exceeds payload size ${e.byteLength}`);let r=oc.unpack(e.subarray(uc,n)),i={offset:n,next:0,outOfOrder:!1};if(r=gc(r,e,i),i.outOfOrder&&(r=yc(r,e,i)),i.offset!==e.byteLength)throw Error(`Invalid CUIB frame: expected payload size ${i.offset}, got ${e.byteLength}`);return r}function*Sc(e,t,n){let r=e.length,i=Math.ceil(r/n);for(let a=0;a<i;a++){let o=a*n,s=Math.min(o+n,r),c=e.subarray(o,s);yield{id:t,chunkIndex:a,data:c,isLast:a===i-1}}}var Cc=class{id;buffer;receivedChunks=new Set;totalChunks=0;chunkSize=0;constructor(e,t,n,r){this.id=e,this.totalChunks=n,this.chunkSize=r??Math.ceil(t/n),this.buffer=new Uint8Array(t)}addChunk(e){if(e.id!==this.id)throw Error(`Chunk ID mismatch: expected ${this.id}, got ${e.id}`);let t=e.chunkIndex*this.chunkSize;return this.buffer.set(e.data,t),this.receivedChunks.add(e.chunkIndex),this.isComplete()}isComplete(){return this.receivedChunks.size===this.totalChunks}getData(){if(!this.isComplete())throw Error(`Not all chunks received`);return xc(this.buffer)}getProgress(){let e=this.receivedChunks.size,t=this.totalChunks;return{received:e,total:t,percentage:t>0?e/t*100:0}}},wc=class e{static STALE_TRANSFER_TTL_MS=3e4;static SWEEP_INTERVAL_MS=1e3;assemblers=new Map;completedCallbacks=new Map;errorCallbacks=new Map;lastActivity=new Map;lastSweep=0;startReceiving(e,t,n,r,i,a){this.sweepStale();let o=new Cc(e,i,t,a);this.assemblers.set(e,o),this.completedCallbacks.set(e,n),this.errorCallbacks.set(e,r),this.lastActivity.set(e,Date.now())}sweepStale(){if(this.lastActivity.size===0)return;let t=Date.now();if(t-this.lastSweep<e.SWEEP_INTERVAL_MS)return;this.lastSweep=t;let n=t-e.STALE_TRANSFER_TTL_MS;for(let[e,t]of this.lastActivity)if(t<n){let t=this.errorCallbacks.get(e);this.assemblers.delete(e),this.completedCallbacks.delete(e),this.errorCallbacks.delete(e),this.lastActivity.delete(e),t&&t(Error(`Transfer timed out`))}}processChunk(e){this.sweepStale();let t=this.assemblers.get(e.id);if(!t){console.warn(`Received chunk for unknown transfer: ${e.id}`);return}this.lastActivity.set(e.id,Date.now());try{if(t.addChunk(e)){let n=t.getData(),r=this.completedCallbacks.get(e.id);this.assemblers.delete(e.id),this.completedCallbacks.delete(e.id),this.errorCallbacks.delete(e.id),this.lastActivity.delete(e.id),r&&r(n)}}catch(t){let n=this.errorCallbacks.get(e.id);this.assemblers.delete(e.id),this.completedCallbacks.delete(e.id),this.errorCallbacks.delete(e.id),this.lastActivity.delete(e.id),n&&n(t)}}cancel(e){let t=this.errorCallbacks.get(e);this.assemblers.delete(e),this.completedCallbacks.delete(e),this.errorCallbacks.delete(e),this.lastActivity.delete(e),t&&t(Error(`Transfer cancelled`))}getProgress(e){let t=this.assemblers.get(e);return t?t.getProgress():null}};S();var Tc=Symbol(`rpc:methods`),Ec=Symbol(`rpc:nested`),Dc=Symbol(`rpc:exposeAll`);function Oc(e,t=[],n={},r=new WeakSet){if(!e||typeof e!=`object`||r.has(e))return n;r.add(e);let i=Object.getOwnPropertyNames(e),a=[],o=Object.getPrototypeOf(e);for(;o&&o!==Object.prototype;)a.push(...Object.getOwnPropertyNames(o)),o=Object.getPrototypeOf(o);let s=[...new Set([...i,...a])];for(let r of s)if(!(r===`constructor`||r.startsWith(`_`)||r.startsWith(`#`)))try{if(e.constructor&&Object.prototype.hasOwnProperty.call(e.constructor,r))continue;let i=Object.getOwnPropertyDescriptor(e,r);if(!i){let t=Object.getPrototypeOf(e);for(;t&&t!==Object.prototype&&!i;)i=Object.getOwnPropertyDescriptor(t,r),t=Object.getPrototypeOf(t)}if(i&&(i.get||i.set)&&!i.value){let i=e[r];if(typeof i==`function`){let a=[...t,r].join(`.`);n[a]=i.bind(e)}continue}let a=e[r],o=[...t,r].join(`.`);typeof a==`function`&&(n[o]=a.bind(e))}catch{}return n}function kc(e,t=[],n={},r=new WeakSet){if(r.has(e))return n;r.add(e);let i=e.constructor===Object||e.constructor===void 0,a=Object.getPrototypeOf(e),o=Reflect.hasMetadata(Tc,e)||Reflect.hasMetadata(Tc,a)||Reflect.hasMetadata(Ec,e)||Reflect.hasMetadata(Ec,a)||Reflect.hasMetadata(Dc,a);if(i&&!o){let i=Object.getOwnPropertyNames(e);for(let a of i)if(!(a===`constructor`||a.startsWith(`_`)))try{let i=e[a],o=[...t,a].join(`.`);typeof i==`function`?n[o]=i.bind(e):typeof i==`object`&&i&&!Array.isArray(i)?kc(i,[...t,a],n,r):n[o]=async()=>i}catch{}}else{let i=a&&Reflect.getMetadata(Dc,a),o=[...Reflect.getMetadata(Tc,e)??[],...(a&&Reflect.getMetadata(Tc,a))??[]],s=[...Reflect.getMetadata(Ec,e)??[],...(a&&Reflect.getMetadata(Ec,a))??[]],c=Object.getOwnPropertyNames(e);a&&c.push(...Object.getOwnPropertyNames(a).filter(e=>e!==`constructor`));for(let l of c)if(l!==`constructor`)try{let c=e[l]??a?.[l];if(!c)continue;let u=[...t,l].join(`.`);typeof c==`function`?(i&&!l.startsWith(`_`)||o.includes(l))&&(n[u]=c.bind(e)):o.includes(l)?n[u]=async()=>e[l]:typeof c==`object`&&c&&s.includes(l)&&kc(c,[...t,l],n,r)}catch{}}return n}var Ac=class e extends Error{code;data;constructor(e,t,n){super(t),this.name=`RPCException`,this.code=e,this.data=n}static fromJSON(t){return new e(t.code,t.message,t.data)}toJSON(){return{code:this.code,message:this.message,data:this.data}}};function jc(e,t,n){return new Ac(e,t,n)}var Mc={METHOD_NOT_FOUND:`METHOD_NOT_FOUND`,INVALID_PARAMS:`INVALID_PARAMS`,INTERNAL_ERROR:`INTERNAL_ERROR`,TIMEOUT:`TIMEOUT`,CONNECTION_CLOSED:`CONNECTION_CLOSED`,STREAM_ERROR:`STREAM_ERROR`,PAYLOAD_TOO_LARGE:`PAYLOAD_TOO_LARGE`,NOT_FOUND:`NOT_FOUND`},Nc=Symbol.for(`rpc.callbacks`),Pc=Symbol.for(`rpc.callbacks.oneway`);function Fc(e){return!!e&&typeof e==`object`&&e[Nc]===!0}function Ic(e){return e?.[Pc]??[]}function Lc(e){if(e instanceof Promise)return!0;if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.then==`function`&&typeof t.catch==`function`}function Rc(e,t,n=[],r=null){let i=r,a=e=>{i??=new Set(e)},o=async(t,n)=>{let{result:r,methods:o}=await e.callWithMeta(t,n,{discover:i===null});return o&&a(o),r};return new Proxy({},{get(r,a){if(a===`then`||a===`catch`||a===`finally`)return;if(typeof a==`symbol`||a===`toString`)return()=>`[RPCProxy ${t}${n.length?`.`+n.join(`.`):``}]`;if(i&&n.length===0&&!i.has(a))return;let s=[...n,a];return new Proxy(function(){},{apply(n,r,i){let c=`rpc.${t}.${s.join(`.`)}`,l=a.toLowerCase().includes(`pull`),u=i.findIndex(e=>Fc(e));if(u!==-1){let t=i[u],n=Ic(t),r=i.filter((e,t)=>t!==u);return e.callPullIteratorWithCallback(c,t,n,...r)}let d=i.findIndex(e=>typeof e==`function`);if(d!==-1){let t=i[d],n=i.filter((e,t)=>t!==d);return e.callWithCallback(c,n,t)}return a.toLowerCase().includes(`generate`)?e.callStream(c,...i):l?e.callPullIterator(c,...i):o(c,i)},get(n,r){if(r===`then`||r===`catch`||r===`finally`){let n=s.join(`.`),i=(async()=>(!e.isConnected&&!e.isClosed&&await e.connect(),o(`rpc.${t}.${n}`,[])))();return i[r].bind(i)}return Rc(e,t,s,i)[r]}})}})}function zc(e,t,n,r=[]){return new Proxy({},{get(i,a){if(a===`then`||a===`catch`||a===`finally`)return;if(typeof a==`symbol`||a===`toString`)return()=>`[ServiceProxy ${t.name}${r.length?`.`+r.join(`.`):``}]`;if(a in i)return i[a];let o=[...r,a],s=o.join(`.`),c=t.endpoints.find(e=>{if(e.subject===s)return!0;let t=e.subject.split(`.`);return t[t.length-1]===a&&t.slice(0,-1).join(`.`)===r.join(`.`)});if(c)return new Proxy(function(){},{apply(t,n,r){let i=a.toLowerCase().includes(`pull`),o=r.findIndex(e=>Fc(e));if(o!==-1){let t=r[o],n=Ic(t),i=r.filter((e,t)=>t!==o);return e.callPullIteratorWithCallback(c.subject,t,n,...i)}let s=r.findIndex(e=>typeof e==`function`);if(s!==-1){let t=r[s],n=r.filter((e,t)=>t!==s);return e.callWithCallback(c.subject,n,t)}return a.toLowerCase().includes(`generate`)?e.callStream(c.subject,...r):i?e.callPullIterator(c.subject,...r):e.call(c.subject,...r)}});let l=s+`.`;if(t.endpoints.some(e=>e.subject.startsWith(l)))return zc(e,t,n,o)}})}var Bc=36**4,Vc=Math.floor(Math.random()*36**5).toString(36).padStart(5,`0`),Hc=Math.floor(Math.random()*Bc);function Uc(e){Hc=(Hc+1)%Bc;let t=`${Date.now()}-${Vc}${Hc.toString(36).padStart(4,`0`)}`;return e?`${e}.${t}`:t}function Wc(){let e,t=globalThis.crypto;if(t?.getRandomValues){let n=new Uint8Array(6);t.getRandomValues(n),e=n.reduce((e,t)=>e*256+t,0)}else e=Math.floor(Math.random()*2**48);return e.toString(36).padStart(10,`0`)}function Gc(e){return new Promise(t=>setTimeout(t,e))}function Kc(e,t){let n=Promise.resolve(),r=0;return{dispatch:i=>{if(r===0){let a;try{a=e(i)}catch(e){t(e);return}Lc(a)&&(r++,n=a.then(()=>{r--},e=>{r--,t(e)}));return}r++,n=n.then(()=>e(i)).then(()=>{r--},e=>{r--,t(e)})},flush:()=>r===0?Promise.resolve():n}}async function qc(e,t,n,r,i){let a,o=e(...t);if(o&&typeof o.then==`function`){let e=await o;if(e&&typeof e[Symbol.asyncIterator]==`function`)a=e;else if(e&&typeof e[Symbol.iterator]==`function`)a=(async function*(){for(let t of e)yield t})();else throw jc(Mc.INTERNAL_ERROR,`Handler must return a generator for stream`)}else if(o&&typeof o[Symbol.asyncIterator]==`function`)a=o;else if(o&&typeof o[Symbol.iterator]==`function`)a=(async function*(){for(let e of o)yield e})();else throw jc(Mc.INTERNAL_ERROR,`Handler must return a generator for stream`);let s=!1,c=await i.subscribe(`${n}.cancel`,()=>{s=!0});await Gc(0);try{for await(let e of a){if(s||!i.isConnected)break;let t={id:r,type:`data`,data:e};await i.publish(n,t)}if(!s&&i.isConnected){let e={id:r,type:`end`};await i.publish(n,e)}}catch(e){if(!s&&i.isConnected)try{let t={id:r,type:`error`,error:Yc(e)};await i.publish(n,t)}catch{}}finally{if(c(),a.return)try{await a.return()}catch{}}}async function Jc(e,t){return e(...Array.isArray(t)?t:t==null?[]:[t])}function Yc(e){return e instanceof Ac?e.toJSON():{code:Mc.INTERNAL_ERROR,message:e instanceof Error?e.message:`Internal error`}}async function Xc(e,t,n,r,i){let a,o=e(...t);if(o&&typeof o.then==`function`){let e=await o;if(e&&typeof e[Symbol.asyncIterator]==`function`)a=e;else if(e&&typeof e[Symbol.iterator]==`function`)a=(async function*(){for(let t of e)yield t})();else throw jc(Mc.INTERNAL_ERROR,`Handler must return a generator for pull iterator`)}else if(o&&typeof o[Symbol.asyncIterator]==`function`)a=o;else if(o&&typeof o[Symbol.iterator]==`function`)a=(async function*(){for(let e of o)yield e})();else throw jc(Mc.INTERNAL_ERROR,`Handler must return a generator for pull iterator`);let s=`_rpc.iterator.${n}.request`,c=`_rpc.iterator.${n}.response`,l=!0,u,d=()=>{l&&(l=!1,u?.(),i?.())},f=await r.subscribe(s,async e=>{if(l)try{if(e.type===`cancel`){d(),a.return&&await a.return();let e={id:n,type:`done`};r.tryPublishSync(c,e)||await r.publish(c,e)}else if(e.type===`next`){let{value:e,done:t}=await a.next();if(t){d();let e={id:n,type:`done`};r.tryPublishSync(c,e)||await r.publish(c,e)}else{let t={id:n,type:`value`,value:e};r.tryPublishSync(c,t)||await r.publish(c,t)}}}catch(e){d();let t={id:n,type:`error`,error:Yc(e)};r.tryPublishSync(c,t)||await r.publish(c,t)}});return u=f,async()=>{if(l=!1,f(),a.return)try{await a.return()}catch{}}}async function Zc(e,t,n,r,i,a,o,s){let c=new Set(a),l={},u=!0;for(let e of i)c.has(e)?l[e]=(...t)=>{if(!u||!o.isConnected)return;let n={method:e,args:t};try{o.tryPublishSync(r,n)||o.publish(r,n).catch(()=>{})}catch{}}:l[e]=()=>{throw jc(Mc.INTERNAL_ERROR,`Request-reply callback '${e}' not supported in v1`)};let d,f=e(...t,l),p=e=>{if(e&&typeof e[Symbol.asyncIterator]==`function`)return e;if(e&&typeof e[Symbol.iterator]==`function`)return(async function*(){for(let t of e)yield t})();throw jc(Mc.INTERNAL_ERROR,`Handler must return a generator for pull-callback iterator`)};d=f&&typeof f.then==`function`?p(await f):p(f);let m=`_rpc.iterator.${n}.request`,h=`_rpc.iterator.${n}.response`,g=!0,_,v=()=>{g&&(g=!1,u=!1,_?.(),s?.())},y=await o.subscribe(m,async e=>{if(g)try{if(e.type===`cancel`){v(),d.return&&await d.return();let e={id:n,type:`done`};o.tryPublishSync(h,e)||await o.publish(h,e)}else if(e.type===`next`){let{done:e}=await d.next();if(e){v();let e={id:n,type:`done`};o.tryPublishSync(h,e)||await o.publish(h,e)}else{let e={id:n,type:`value`};o.tryPublishSync(h,e)||await o.publish(h,e)}}}catch(e){v();let t={id:n,type:`error`,error:Yc(e)};o.tryPublishSync(h,t)||await o.publish(h,t)}});return _=y,async()=>{if(g=!1,u=!1,y(),d.return)try{await d.return()}catch{}}}async function Qc(e,t,n,r,i,a){let o=async e=>{if(!i.isConnected)return;let t={id:r,type:`data`,data:e};await i.publish(n,t)},s;try{let n=e(...t,o);n&&typeof n.then==`function`?s=await n:typeof n==`function`&&(s=n)}catch(e){let t={id:r,type:`error`,error:Yc(e)};throw await i.publish(n,t),e}let c=!1,l=async()=>{c||(c=!0,s&&await s())},u;return u=await i.subscribe(`${n}.cancel`,async()=>{u?.(),a?.(),await l()}),async()=>{u?.(),await l()}}var $c=a((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ServiceVerb=e.ServiceError=e.ServiceErrorCodeHeader=e.ServiceErrorHeader=e.ServiceResponseType=void 0,e.ServiceResponseType={STATS:`io.nats.micro.v1.stats_response`,INFO:`io.nats.micro.v1.info_response`,PING:`io.nats.micro.v1.ping_response`},e.ServiceErrorHeader=`Nats-Service-Error`,e.ServiceErrorCodeHeader=`Nats-Service-Error-Code`,e.ServiceError=class t extends Error{code;constructor(e,t){super(t),this.code=e}static isServiceError(e){return t.toServiceError(e)!==null}static toServiceError(n){let r=n?.headers?.get(e.ServiceErrorCodeHeader)||``;if(r!==``){let i=parseInt(r)||400,a=n?.headers?.get(e.ServiceErrorHeader)||``;return new t(i,a.length?a:r)}return null}},e.ServiceVerb={PING:`PING`,STATS:`STATS`,INFO:`INFO`}})),el=a((t=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ServiceImpl=t.ServiceGroupImpl=t.ServiceMsgImpl=t.ServiceApiPrefix=void 0;var n=(jo(),e(Ao)),r=$c();function i(e,t=``){if(t===``)throw Error(`${e} name required`);let n=a(t);if(n.length)throw Error(`invalid ${e} name - ${e} name ${n}`)}function a(e=``){if(!e)throw Error(`name required`);let t=/^[-\w]+$/g;if(e.match(t)===null){for(let n of e.split(``))if(n.match(t)===null)return`cannot contain '${n}'`}return``}t.ServiceApiPrefix=`$SRV`;var o=class{msg;constructor(e){this.msg=e}get data(){return this.msg.data}get sid(){return this.msg.sid}get subject(){return this.msg.subject}get reply(){return this.msg.reply||``}get headers(){return this.msg.headers}respond(e,t){return this.msg.respond(e,t)}respondError(e,t,i,a){return a||={},a.headers=a.headers||(0,n.headers)(),a.headers?.set(r.ServiceErrorCodeHeader,`${e}`),a.headers?.set(r.ServiceErrorHeader,t),this.msg.respond(i,a)}json(e){return this.msg.json(e)}string(){return this.msg.string()}};t.ServiceMsgImpl=o;var s=class e{subject;queue;srv;constructor(t,n=``,r=``){n!==``&&l(`service group`,n);let i=``;if(t instanceof u)this.srv=t,i=``;else if(t instanceof e){let e=t;this.srv=e.srv,r===void 0&&(r=e.queue),i=e.subject}else throw Error(`unknown ServiceGroup type`);this.subject=this.calcSubject(i,n),this.queue=r}calcSubject(e,t=``){return t===``?e:e===``?t:`${e}.${t}`}addEndpoint(e=``,t){t||={subject:e};let n=typeof t==`function`?{handler:t,subject:e}:t;i(`endpoint`,e);let{subject:r,handler:a,metadata:o,queue:s}=n;r||=e,s||=this.queue,c(`endpoint subject`,r),r=this.calcSubject(this.subject,r);let l={name:e,subject:r,queue:s,handler:a,metadata:o};return this.srv._addEndpoint(l)}addGroup(t=``,n){return n===void 0&&(n=this.queue),new e(this,t,n)}};t.ServiceGroupImpl=s;function c(e,t){if(t===``)throw Error(`${e} cannot be empty`);if(t.indexOf(` `)!==-1)throw Error(`${e} cannot contain spaces: '${t}'`);let n=t.split(`.`);n.forEach((r,i)=>{if(r===`>`&&i!==n.length-1)throw Error(`${e} cannot have internal '>': '${t}'`)})}function l(e,t){if(t.indexOf(` `)!==-1)throw Error(`${e} cannot contain spaces: '${t}'`);t.split(`.`).forEach(n=>{if(n===`>`)throw Error(`${e} name cannot contain internal '>': '${t}'`)})}var u=class e{nc;_id;config;handlers;internal;_stopped;_done;started;closeListener;static controlSubject(e,n=``,r=``,a){let o=a??t.ServiceApiPrefix;return n===``&&r===``?`${o}.${e}`:(i(`control subject name`,n),r===``?`${o}.${e}.${n}`:(i(`control subject id`,r),`${o}.${e}.${n}.${r}`))}constructor(e,t={name:``,version:``}){this.nc=e,this.config=Object.assign({},t),this.config.queue===void 0&&(this.config.queue=`q`),t.metadata=Object.freeze(t.metadata||{}),i(`name`,this.config.name),this.config.queue&&i(`queue`,this.config.queue),(0,n.parseSemVer)(this.config.version),this._id=n.nuid.next(),this.internal=[],this._done=(0,n.deferred)(),this._stopped=!1,this.handlers=[],this.started=new Date().toISOString(),this.reset(),this.closeListener={connectionClosedCallback:e=>{this.close(e).catch()}},this.nc.addCloseListener(this.closeListener)}get subjects(){return this.handlers.filter(e=>e.internal===!1).map(e=>e.subject)}get id(){return this._id}get name(){return this.config.name}get description(){return this.config.description??``}get version(){return this.config.version}get metadata(){return this.config.metadata}errorToHeader(e){let t=(0,n.headers)();if(e instanceof r.ServiceError){let n=e;t.set(r.ServiceErrorHeader,n.message),t.set(r.ServiceErrorCodeHeader,`${n.code}`)}else t.set(r.ServiceErrorHeader,e.message),t.set(r.ServiceErrorCodeHeader,`500`);return t}setupHandler(e,t=!1){let r=t?``:e.queue?e.queue:this.config.queue,{name:i,subject:a,handler:s}=e,c=e;c.internal=t,t&&this.internal.push(c),c.stats=new d(i,a,r),c.queue=r;let l=s?(e,t)=>{if(e){this.close(e);return}let r=Date.now();try{s(e,new o(t))}catch(e){c.stats.countError(e),t?.respond(n.Empty,{headers:this.errorToHeader(e)})}finally{c.stats.countLatency(r)}}:void 0;return c.sub=this.nc.subscribe(a,{callback:l,queue:r}),c.sub.closed.then(()=>{this._stopped||this.close(Error(`required subscription ${e.subject} stopped`)).catch()}).catch(t=>{if(!this._stopped){let n=Error(`required subscription ${e.subject} errored: ${t.message}`);n.stack=t.stack,this.close(n).catch()}}),c}info(){return{type:r.ServiceResponseType.INFO,name:this.name,id:this.id,version:this.version,description:this.description,metadata:this.metadata,endpoints:this.endpoints()}}endpoints(){return this.handlers.map(e=>{let{subject:t,metadata:n,name:r,queue:i}=e;return{subject:t,metadata:n,name:r,queue_group:i}})}async stats(){let e=[];for(let t of this.handlers){if(typeof this.config.statsHandler==`function`)try{t.stats.data=await this.config.statsHandler(t)}catch(e){t.stats.countError(e)}e.push(t.stats.stats(t.qi))}return{type:r.ServiceResponseType.STATS,name:this.name,id:this.id,version:this.version,started:this.started,metadata:this.metadata,endpoints:e}}addInternalHandler(e,t){let n=`${e}`.toUpperCase();this._doAddInternalHandler(`${n}-all`,e,t),this._doAddInternalHandler(`${n}-kind`,e,t,this.name),this._doAddInternalHandler(`${n}`,e,t,this.name,this.id)}_doAddInternalHandler(t,n,r,i=``,a=``){let o={};o.name=t,o.subject=e.controlSubject(n,i,a),o.handler=r,this.setupHandler(o,!0)}start(){let e=(e,t)=>e?(this.close(e),Promise.reject(e)):this.stats().then(e=>(t?.respond(JSON.stringify(e)),Promise.resolve())),t=(e,t)=>e?(this.close(e),Promise.reject(e)):(t?.respond(JSON.stringify(this.info())),Promise.resolve()),n=JSON.stringify(this.ping());return this.addInternalHandler(r.ServiceVerb.PING,(e,t)=>e?(this.close(e).then().catch(),Promise.reject(e)):(t.respond(n),Promise.resolve())),this.addInternalHandler(r.ServiceVerb.STATS,e),this.addInternalHandler(r.ServiceVerb.INFO,t),this.handlers.forEach(e=>{let{subject:t}=e;typeof t==`string`&&e.handler!==null&&this.setupHandler(e)}),Promise.resolve(this)}close(e){if(this._stopped)return this._done;this._stopped=!0,this.nc.removeCloseListener(this.closeListener);let t=[];return this.nc.isClosed()||(t=this.handlers.concat(this.internal).map(e=>e.sub.drain())),Promise.allSettled(t).then(()=>{this._done.resolve(e||null)}),this._done}get stopped(){return this._done}get isStopped(){return this._stopped}stop(e){return this.close(e)}ping(){return{type:r.ServiceResponseType.PING,name:this.name,id:this.id,version:this.version,metadata:this.metadata}}reset(){if(this.started=new Date().toISOString(),this.handlers)for(let e of this.handlers)e.stats.reset(e.qi)}addGroup(e,t){return new s(this,e,t)}addEndpoint(e,t){return new s(this).addEndpoint(e,t)}_addEndpoint(e){let t=new n.QueuedIteratorImpl;t.profile=!0,t.noIterator=typeof e.handler==`function`,t.noIterator||(e.handler=(e,n)=>{e?this.stop(e).catch():t.push(new o(n))},t.iterClosed.then(()=>{this.close().catch()}));let r=this.setupHandler(e,!1);return r.sub.closed.then(e=>{e?this.stop(e):t.stop()}),r.qi=t,this.handlers.push(r),t}};t.ServiceImpl=u;var d=class{name;subject;average_processing_time;num_requests;processing_time;num_errors;last_error;data;metadata;queue;constructor(e,t,n=``){this.name=e,this.subject=t,this.average_processing_time=0,this.num_errors=0,this.num_requests=0,this.processing_time=0,this.queue=n}reset(e){this.num_requests=0,this.processing_time=0,this.average_processing_time=0,this.num_errors=0,this.last_error=void 0,this.data=void 0;let t=e;t&&(t.time=0,t.processed=0)}countLatency(e){this.num_requests++,this.processing_time+=(0,n.nanos)(Date.now()-e),this.average_processing_time=Math.round(this.processing_time/this.num_requests)}countError(e){this.num_errors++,this.last_error=e.message}_stats(){let{name:e,subject:t,average_processing_time:n,num_errors:r,num_requests:i,processing_time:a,last_error:o,data:s,queue:c}=this;return{name:e,subject:t,average_processing_time:n,num_errors:r,num_requests:i,processing_time:a,last_error:o,data:s,queue_group:c}}stats(e){let t=e;return t?.noIterator===!1&&(this.processing_time=(0,n.nanos)(t.time),this.num_requests=t.processed,this.average_processing_time=this.processing_time>0&&this.num_requests>0?this.processing_time/this.num_requests:0),this._stats()}}})),tl=a((t=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ServiceClientImpl=void 0;var n=(jo(),e(Ao)),r=el(),i=$c();t.ServiceClientImpl=class{nc;prefix;opts;constructor(e,t={strategy:`stall`,maxWait:2e3},n){this.nc=e,this.prefix=n,this.opts=t}ping(e=``,t=``){return this.q(i.ServiceVerb.PING,e,t)}stats(e=``,t=``){return this.q(i.ServiceVerb.STATS,e,t)}info(e=``,t=``){return this.q(i.ServiceVerb.INFO,e,t)}async q(e,t=``,i=``){let a=new n.QueuedIteratorImpl,o=r.ServiceImpl.controlSubject(e,t,i,this.prefix),s=await this.nc.requestMany(o,n.Empty,this.opts);return(async()=>{for await(let e of s)try{let t=e.json();a.push(t)}catch(e){a.push(()=>{a.stop(e)})}a.push(()=>{a.stop()})})().catch(e=>{a.stop(e)}),a}}})),nl=a((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Svcm=e.ServiceVerb=e.ServiceResponseType=e.ServiceErrorHeader=e.ServiceErrorCodeHeader=e.ServiceError=void 0;var t=el(),n=tl(),r=$c();Object.defineProperty(e,"ServiceError",{enumerable:!0,get:function(){return r.ServiceError}}),Object.defineProperty(e,"ServiceErrorCodeHeader",{enumerable:!0,get:function(){return r.ServiceErrorCodeHeader}}),Object.defineProperty(e,"ServiceErrorHeader",{enumerable:!0,get:function(){return r.ServiceErrorHeader}}),Object.defineProperty(e,"ServiceResponseType",{enumerable:!0,get:function(){return r.ServiceResponseType}}),Object.defineProperty(e,"ServiceVerb",{enumerable:!0,get:function(){return r.ServiceVerb}}),e.Svcm=class{nc;constructor(e){this.nc=e}add(e){try{return new t.ServiceImpl(this.nc,e).start()}catch(e){return Promise.reject(e)}}client(e,t){return new n.ServiceClientImpl(this.nc,e,t)}}})),rl=a((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Svcm=e.ServiceVerb=e.ServiceResponseType=e.ServiceErrorHeader=e.ServiceErrorCodeHeader=e.ServiceError=void 0;var t=nl();Object.defineProperty(e,"ServiceError",{enumerable:!0,get:function(){return t.ServiceError}}),Object.defineProperty(e,"ServiceErrorCodeHeader",{enumerable:!0,get:function(){return t.ServiceErrorCodeHeader}}),Object.defineProperty(e,"ServiceErrorHeader",{enumerable:!0,get:function(){return t.ServiceErrorHeader}}),Object.defineProperty(e,"ServiceResponseType",{enumerable:!0,get:function(){return t.ServiceResponseType}}),Object.defineProperty(e,"ServiceVerb",{enumerable:!0,get:function(){return t.ServiceVerb}}),Object.defineProperty(e,"Svcm",{enumerable:!0,get:function(){return t.Svcm}})}))(),il=class{client;svc;services=[];nc;constructor(e){this.client=e}init(e){this.nc!==e&&(this.nc=e,this.svc=new rl.Svcm(e),this.services=[])}async registerHandler(e,t,n){if(!this.svc)throw Error(`RPCService is not initialized. Call init() first.`);let r=new Map,i=this.client,a=this.svc;n?.isolatedConnection&&(i=this.client.createIsolatedClient({...this.client.options,name:`${this.client.options.name}-service-${e.name}`}),a=new rl.Svcm(await i.connect()));let o=await a.add(e);this.services.push(o),n?.isolatedConnection&&(o._isolatedClient=i);let s=kc(t),c=new Map;for(let[e,t]of Object.entries(s)){let n=e.split(`.`),a=n.pop(),s=o;if(n.length>0){let e=n.join(`.`);if(!c.has(e)){let t=o;for(let e of n)t=t.addGroup(e);c.set(e,t)}s=c.get(e)}s.addEndpoint(a,async(e,n)=>{if(e){n.respondError(500,e.message);return}try{let e=n.headers?.get(`x-chunked-transfer`);if(e===`header`){let e=cc(n.data),t=n.headers?.get(`x-chunk-id`);if(!t||e.transferId!==t){console.error(`Invalid chunk header`);return}i.chunkingManager.startReceiving(e.transferId,e.totalChunks,async e=>{await o(e,n)},e=>{console.error(`Error assembling chunks for ${a}:`,e)},e.totalSize,e.chunkSize)}else if(e===`chunk`){let e=n.headers?.get(`x-chunk-id`),t=parseInt(n.headers?.get(`x-chunk-index`)??`0`);if(!e){console.error(`Chunk missing chunk ID`);return}i.chunkingManager.processChunk({id:e,chunkIndex:t,data:n.data,isLast:!1})}else await o(xc(n.data),n)}catch(e){console.error(`Error processing message for ${a}:`,e)}async function o(e,n){let a={id:e.id};try{if(e.params?.__stream&&e.params?.__streamSubject){let n=e.params.__streamSubject,r=e.params.args??[];await qc(t,r,n,e.id,i)}else if(e.params?.__pullIterator||Array.isArray(e.params)&&e.params[0]?.__pullIterator){let o=e.params?.__pullIterator?e.params:e.params[0],s=o.args??[],c=o.__iteratorId??e.id,l=await Xc(t,s,c,i,()=>r.delete(c));r.set(c,l),a.result={iteratorId:c};let u=`${n.subject}.reply.${e.id}`;await i.publish(u,a)}else{a.result=await Jc(t,e.params);let r=`${n.subject}.reply.${e.id}`;await i.publish(r,a)}}catch(t){a.error=Yc(t);try{let t=`${n.subject}.reply.${e.id}`;await i.publish(t,a)}catch(e){if(i.isClosed)return;console.error(`Failed to send error response:`,e)}}}})}let l=o;l._pullIteratorCleanups=r;let u=o.stop.bind(o);return o.stop=async e=>(await Promise.allSettled(Array.from(r.values()).map(e=>e())),r.clear(),u(e)),new al(o)}monitor(){if(!this.svc)throw Error(`RPCService is not initialized. Call init() first.`);return this.svc.client({strategy:`stall`,stall:10,maxWait:2e3})}async stopAll(){await Promise.allSettled(this.services.map(async e=>{await e.stop();let t=e._isolatedClient;t&&await t.disconnect()})),this.services=[]}async stop(e){let t=this.services.find(t=>t.info().name===e);if(t)try{await t.stop();let e=t._isolatedClient;e&&await e.disconnect(),this.services=this.services.filter(e=>e!==t)}catch{}}getAllInfo(){return this.services.map(e=>e.info())}getInfo(e){return this.services.find(t=>t.info().name===e)?.info()}async getAllStats(){return Promise.all(this.services.map(e=>e.stats()))}async getStats(e){return this.services.find(t=>t.info().name===e)?.stats()}},al=class{natsService;get isStopped(){return this.natsService.isStopped}constructor(e){this.natsService=e}info(){return this.natsService.info()}stats(){return this.natsService.stats()}async stop(e){try{await this.natsService.stop(e)}catch{}}};ko(),Wr(),hr(),ra();function ol(e){return new cl(e)}function sl(e){return Br(e?`_INBOX.${e}`:void 0)}var cl=class e{options;service=new il(this);chunkingManager=new wc;pullIteratorCleanups=new Map;callbackCleanups=new Map;nc;subscriptionSeq=0;subscriptionEntries=new Map;pullIteratorSettles=new Set;replyPrefix;muxEntry;statusHandlers=new Map;_maxPayloadSize=1024*1024;connectionPromise;closed=!1;isolatedClients=[];pendingRequests=new Map;streamHandlers=new Map;get isConnected(){return this.nc?.isClosed()===!1}get isStale(){return this.nc?.isStale?.()??!1}get isClosed(){return this.closed}get maxPayloadSize(){return this._maxPayloadSize}status(){return this.nc?.status()}async flush(e=5e3){if(!this.nc)throw jc(Mc.CONNECTION_CLOSED,`Not connected`);let t;try{await Promise.race([this.nc.flush(),new Promise((n,r)=>{t=setTimeout(()=>r(jc(Mc.TIMEOUT,`flush() timed out after ${e}ms`)),e)})])}finally{t&&clearTimeout(t)}}constructor(e){this.options=e,this.replyPrefix=e.connId??Wc()}createIsolatedClient(t){return new e(t)}async connect(e){if(e?.signal?.aborted)throw new DOMException(`Aborted`,`AbortError`);if(this.nc&&!this.nc.isClosed())return this.nc;let t={servers:this.options.servers,user:this.options.auth?.user,pass:this.options.auth?.password,name:this.options.name,inboxPrefix:this.options.connId?`_INBOX.${this.options.connId}`:void 0,reconnect:this.options.reconnect??!0,timeout:this.options.connectTimeout??1e4,maxPingOut:this.options.maxPingOut??2,maxReconnectAttempts:this.options.maxReconnectAttempts??-1,reconnectTimeWait:this.options.reconnectTimeWait??2e3,reconnectJitter:this.options.reconnectJitter??100,reconnectJitterTLS:this.options.reconnectJitterTLS??1e3,ignoreAuthErrorAbort:this.options.ignoreAuthErrorAbort??!1,pingInterval:this.options.pingInterval??12e4,pingTimeout:this.options.pingTimeout??0,reconnectionDelayMax:this.options.reconnectionDelayMax??0,reconnectionRandomizationFactor:this.options.reconnectionRandomizationFactor??0,tls:this.options.tls,debug:this.options.debug??!1,noAsyncTraces:!0,waitOnFirstConnect:this.options.waitOnFirstConnect??!0,signal:e?.signal};this.connectionPromise??=To(t);let n=this.connectionPromise;try{this.nc=await ll(n,e?.signal)}finally{this.connectionPromise=void 0}this.closed=!1,this.service.init(this.nc);try{let e=this.nc.info;this._maxPayloadSize=e?.max_payload??this.options.maxPayloadSize??1024*1024}catch{this._maxPayloadSize=this.options.maxPayloadSize??1024*1024}this._maxPayloadSize-=8192,this.ensureMuxSubscription(!1);for(let e of this.subscriptionEntries.values())(!e.sub||e.sub.isClosed())&&this.natsSubscribe(e);return this.nc}async disconnect(){this.closed=!0;for(let[,e]of this.pendingRequests)e.timeout&&clearTimeout(e.timeout),e.cleanup?.(),e.reject(jc(Mc.CONNECTION_CLOSED,`Connection closed`));this.pendingRequests.clear(),this.statusHandlers.clear();for(let[,e]of this.streamHandlers)try{e.end()}catch{}this.streamHandlers.clear(),this.settlePullIterators(),await Promise.allSettled(Array.from(this.pullIteratorCleanups.values()).map(e=>e())),this.pullIteratorCleanups.clear(),await Promise.allSettled(Array.from(this.callbackCleanups.values()).map(e=>e())),this.callbackCleanups.clear();for(let e of this.subscriptionEntries.values())try{e.sub?.unsubscribe()}catch{}if(this.subscriptionEntries.clear(),this.muxEntry=void 0,this.chunkingManager=new wc,await Promise.allSettled(this.isolatedClients.map(e=>e.disconnect())),this.isolatedClients=[],this.nc){try{await this.nc.close()}catch{}try{let e=this.options.disconnectTimeout??2e3;await Promise.race([this.nc.closed(),new Promise(t=>setTimeout(t,e))])}catch{}this.nc=void 0}}reconfigure(e){if(this.nc&&!this.nc.isClosed())throw Error(`Cannot reconfigure while connected. Call suspend() first.`);e.servers!==void 0&&(this.options.servers=e.servers),e.auth!==void 0&&(this.options.auth=e.auth);for(let t of this.isolatedClients)t.reconfigure(e)}setServers(e){this.options.servers=e,this.nc&&!this.nc.isClosed()&&this.nc.setServers(e);for(let t of this.isolatedClients)t.setServers(e)}async forceReconnect(){let e=this.nc;if(!(!e||e.isClosed())){try{typeof e.forceReconnect==`function`?await e.forceReconnect():typeof e.reconnect==`function`&&await e.reconnect()}catch{}await Promise.allSettled(this.isolatedClients.map(e=>e.forceReconnect()))}}abortClose(e){this.closed=!0;for(let[,e]of this.pendingRequests)e.timeout&&clearTimeout(e.timeout),e.cleanup?.(),e.reject(jc(Mc.CONNECTION_CLOSED,`Connection closed`));this.pendingRequests.clear(),this.statusHandlers.clear();for(let[,e]of this.streamHandlers)try{e.end()}catch{}this.streamHandlers.clear(),this.settlePullIterators();for(let e of this.pullIteratorCleanups.values())try{e()}catch{}this.pullIteratorCleanups.clear();for(let e of this.callbackCleanups.values())try{e()}catch{}this.callbackCleanups.clear();for(let t of this.isolatedClients)try{t.abortClose(e)}catch{}this.isolatedClients=[];let t=this.nc;if(t){try{typeof t.abortClose==`function`?t.abortClose(e):t.close().catch(()=>{})}catch{}this.nc=void 0}}async suspend(){for(let[,e]of this.pendingRequests)e.timeout&&clearTimeout(e.timeout),e.cleanup?.(),e.reject(jc(Mc.CONNECTION_CLOSED,`Connection closed`));this.pendingRequests.clear(),this.statusHandlers.clear();for(let[,e]of this.streamHandlers)try{e.end()}catch{}this.streamHandlers.clear(),this.settlePullIterators(),await Promise.allSettled(Array.from(this.pullIteratorCleanups.values()).map(e=>e())),this.pullIteratorCleanups.clear(),await Promise.allSettled(Array.from(this.callbackCleanups.values()).map(e=>e())),this.callbackCleanups.clear();for(let e of this.subscriptionEntries.values()){try{e.sub?.unsubscribe()}catch{}e.sub=void 0}if(this.chunkingManager=new wc,await Promise.allSettled(this.isolatedClients.map(e=>e.suspend())),this.nc){try{await this.nc.close()}catch{}try{let e=this.options.disconnectTimeout??2e3;await Promise.race([this.nc.closed(),new Promise(t=>setTimeout(t,e))])}catch{}this.nc=void 0}this.connectionPromise=void 0}async publish(e,t,n){if(!this.nc)throw Error(`Not connected`);let r=bc(t);if(r.length<=this._maxPayloadSize){this.nc.publish(e,r,n);return}let i=Uc(),a={type:`chunked`,transferId:i,totalChunks:Math.ceil(r.length/this._maxPayloadSize),totalSize:r.length,chunkSize:this._maxPayloadSize},o=n?.headers??ea();o.set(`x-chunked-transfer`,`header`),o.set(`x-chunk-id`,i),this.nc.publish(e,sc(a),{headers:o,reply:n?.reply});let s=0;for(let t of Sc(r,i,this._maxPayloadSize)){let r=ea();r.set(`x-chunked-transfer`,`chunk`),r.set(`x-chunk-id`,i),r.set(`x-chunk-index`,s.toString()),this.nc.publish(e,t.data,{headers:r,reply:n?.reply}),s>0&&s%50==0&&await Gc(0),s++}}tryPublishSync(e,t,n){if(!this.nc)throw Error(`Not connected`);let r=bc(t);return r.length>this._maxPayloadSize?!1:(this.nc.publish(e,r,n),!0)}async subscribe(e,t,n){let{unsubscribe:r}=await this.subscribeEntry(e,t,n);return r}async subscribeEntry(e,t,n){if(!this.nc)throw Error(`Not connected`);let r=++this.subscriptionSeq,i={pattern:e,handler:t,options:n};return this.subscriptionEntries.set(r,i),this.natsSubscribe(i),{entry:i,unsubscribe:()=>{try{i.sub?.unsubscribe()}catch{}finally{this.subscriptionEntries.delete(r)}}}}natsSubscribe(e){let{pattern:t}=e;if(e.raw){e.sub=this.nc.subscribe(t,{callback:(n,r)=>{if(n){console.error(`Subscription error for ${t}:`,n);return}try{e.handler(r)}catch(e){console.error(`Error processing message for ${t}:`,e)}}});return}let n=Kc(e.handler,e=>console.error(`Error in handler for ${t}:`,e)),r=n.dispatch;e.flush=n.flush;let i=(e,n)=>{if(e){console.error(`Subscription error for ${t}:`,e);return}try{let e=n.headers?.get(`x-chunked-transfer`);if(e===`header`){let e=cc(n.data),i=n.headers?.get(`x-chunk-id`);if(!i||e.transferId!==i){console.error(`Invalid chunk header`);return}this.chunkingManager.startReceiving(e.transferId,e.totalChunks,e=>{r(e)},e=>{console.error(`Error assembling chunks for ${t}:`,e)},e.totalSize,e.chunkSize)}else if(e===`chunk`){let e=n.headers?.get(`x-chunk-id`),t=parseInt(n.headers?.get(`x-chunk-index`)??`0`);if(!e){console.error(`Chunk missing chunk ID`);return}this.chunkingManager.processChunk({id:e,chunkIndex:t,data:n.data,isLast:!1})}else{let e=xc(n.data);r(e)}}catch(e){console.error(`Error processing message for ${t}:`,e)}};e.sub=this.nc.subscribe(t,{...e.options?.queue?{queue:e.options.queue}:{},callback:i})}ensureMuxSubscription(e=!0){this.muxEntry||(this.muxEntry={pattern:`rpc.reply.${this.replyPrefix}.>`,raw:!0,handler:e=>this.handleMuxMessage(e)},this.subscriptionEntries.set(++this.subscriptionSeq,this.muxEntry)),e&&this.nc&&(!this.muxEntry.sub||this.muxEntry.sub.isClosed())&&this.natsSubscribe(this.muxEntry)}handleMuxMessage(e){if(e.data?.length===0&&e.headers?.code===503){let t=e.subject.slice(10),n=this.statusHandlers.get(t);if(n){this.statusHandlers.delete(t);try{n(new mr.NoRespondersError(t))}catch(e){console.error(`Error in no-responder status handler:`,e)}return}let r=this.pendingRequests.get(t);r&&(this.pendingRequests.delete(t),r.timeout&&clearTimeout(r.timeout),r.reject(new mr.NoRespondersError(r.subject??t)));return}let t=e.headers?.get(`x-chunked-transfer`);if(t===`header`){let t=cc(e.data),n=e.headers?.get(`x-chunk-id`);if(!n||t.transferId!==n){console.error(`Invalid chunk header on reply mux`);return}this.chunkingManager.startReceiving(t.transferId,t.totalChunks,e=>this.routeMuxResponse(e),e=>console.error(`Error assembling chunked RPC response:`,e),t.totalSize,t.chunkSize)}else if(t===`chunk`){let t=e.headers?.get(`x-chunk-id`),n=parseInt(e.headers?.get(`x-chunk-index`)??`0`);if(!t){console.error(`Chunk missing chunk ID on reply mux`);return}this.chunkingManager.processChunk({id:t,chunkIndex:n,data:e.data,isLast:!1})}else this.routeMuxResponse(xc(e.data))}routeMuxResponse(e){let t=e,n=t?.id;if(!n)return;let r=this.pendingRequests.get(n);r&&(this.pendingRequests.delete(n),r.timeout&&clearTimeout(r.timeout),t.error?r.reject(Ac.fromJSON(t.error)):r.resolve({result:t.result,methods:t.__methods}))}settlePullIterators(){for(let e of[...this.pullIteratorSettles])try{e()}catch{}this.pullIteratorSettles.clear()}async request(e,t,n){return this.withNoResponderRetry(()=>this._requestOnce(e,t,n),n?.noResponderRetry)}async _requestOnce(e,t,n){if(!this.nc)throw Error(`Not connected`);let r=n?.timeout??5e3,i=bc(t);try{let t=await this.nc.request(e,i,{timeout:r,headers:n?.headers,noMux:!1});if(t.headers?.get(`Nats-Service-Error-Code`)){let e=t.headers.get(`Nats-Service-Error-Code`)||`500`,n=t.headers.get(`Nats-Service-Error`)||`Service error`,r=null;if(t.data)try{r=xc(t.data)}catch{}throw jc(e,n,r)}let a=xc(t.data);if(a?.error)throw jc(a.code??Mc.INTERNAL_ERROR,a.error??`Unknown error`,a);return a}catch(t){throw t.code===`503`||t.message?.includes(`no responders`)?jc(Mc.NOT_FOUND,`No responders available`):t.code===`TIMEOUT`||t.message?.includes(`timeout`)?jc(Mc.TIMEOUT,`Request to "${e}" timed out after ${r}ms`):t}}async withNoResponderRetry(e,t){let n=t?.maxRetries??this.options.noResponderRetry?.maxRetries??3,r=t?.delays??this.options.noResponderRetry?.delays??[500,1e3,2e3];for(let t=0;;t++)try{return await e()}catch(e){if(!(e instanceof mr.NoRespondersError||e instanceof Ac&&e.code===Mc.NOT_FOUND)||t>=n||this.closed)throw e;let i=r[Math.min(t,r.length-1)];await Gc(i)}}async call(e,...t){let{result:n}=await this.withNoResponderRetry(()=>this._callOnce(e,t));return n}async callWithMeta(e,t=[],n){return this.withNoResponderRetry(()=>this._callOnce(e,t,n?.discover===!0))}async _callOnce(e,t,n=!1){if(!this.isConnected&&!this.isClosed&&await this.connect(),!this.nc)throw Error(`Not connected`);if(!e.startsWith(`rpc.`))return this._callOnceService(e,t);this.ensureMuxSubscription();let r=Uc(this.replyPrefix),i=this.options.timeout??3e4,a=`rpc.reply.${r}`;return new Promise((o,s)=>{let c=setTimeout(()=>{this.pendingRequests.delete(r)&&s(jc(Mc.TIMEOUT,`RPC call to "${e}" timed out after ${i}ms`))},i);this.pendingRequests.set(r,{resolve:o,reject:s,timeout:c,subject:e,cleanup:()=>{clearTimeout(c),this.pendingRequests.delete(r)}});let l={id:r,method:`call`,params:t};n&&(l.__discover=!0),this.publish(e,l,{reply:a}).catch(e=>{this.pendingRequests.delete(r)&&(clearTimeout(c),s(e))})})}async _callOnceService(e,t){let n=Uc(this.replyPrefix),r=this.options.timeout??3e4,i=`${e}.reply.${n}`;return new Promise(async(a,o)=>{let s,c,l=async()=>{if(this.pendingRequests.has(n)){let e=this.pendingRequests.get(n);e?.timeout&&clearTimeout(e.timeout),this.pendingRequests.delete(n)}if(s&&!s.isClosed())try{s.unsubscribe()}catch{}c?.()},u=setTimeout(()=>{this.pendingRequests.has(n)&&(this.pendingRequests.delete(n),l(),o(jc(Mc.TIMEOUT,`RPC call to "${e}" timed out after ${r}ms`)))},r);this.pendingRequests.set(n,{resolve:a,reject:o,timeout:u,cleanup:()=>void l()});let d=async e=>{let t=e;if(t.id===n){let e=this.pendingRequests.get(t.id);e&&(this.pendingRequests.delete(t.id),e.timeout&&clearTimeout(e.timeout),await l(),t.error?e.reject(Ac.fromJSON(t.error)):e.resolve({result:t.result,methods:t.__methods}))}},f=(t,n)=>{n&&n.data?.length===0&&n.headers?.code===503?(o(new mr.NoRespondersError(e)),l()):t&&(o(t),l())};try{c=await this.subscribe(i,d);let r=sl(this.options.connId);s=this.nc.subscribe(r,{max:1,callback:f});let a={id:n,method:`call`,params:t};await this.publish(e,a,{reply:r})}catch(e){await l(),o(e)}})}async*callStream(e,...t){let n=this.options.noResponderRetry?.maxRetries??3,r=this.options.noResponderRetry?.delays??[500,1e3,2e3];for(let i=0;;i++)try{yield*this._callStreamOnce(e,...t);return}catch(e){if(!(e instanceof mr.NoRespondersError||e instanceof Ac&&e.code===Mc.NOT_FOUND)||i>=n||this.closed)throw e;await Gc(r[Math.min(i,r.length-1)])}}_callStreamOnce(e,...t){let n=this,r=!1,i=!1,a=!1,o=!1,s=null,c=``,l=``,u,d=[],f=null,p=()=>{let e=f;e&&(f=null,e({value:void 0,done:!0}))},m={push:e=>{if(!o)if(f){let t=f;f=null,t({value:e,done:!1})}else d.push(e)},end:()=>{o=!0,p()},error:e=>{s=e,o=!0,p()}},h=async()=>{if(!a&&(a=!0,n.streamHandlers.delete(c),n.statusHandlers.delete(c),u?.(),!o)){o=!0;try{await n.publish(`${l}.cancel`,{id:c})}catch{}}},g=async e=>{if(e.id!==c)return;let t=n.streamHandlers.get(e.id);if(t)switch(e.type){case`data`:t.push(e.data);break;case`end`:t.end(),await h();break;case`error`:t.error(Ac.fromJSON(e.error)),await h();break}},_=async()=>{if(!n.isConnected&&!n.isClosed&&await n.connect(),!n.nc)throw Error(`Not connected`);n.ensureMuxSubscription(),c=Uc(n.replyPrefix),l=`stream.${e}.${c}`,n.streamHandlers.set(c,m),u=await n.subscribe(l,g),n.statusHandlers.set(c,()=>{n.streamHandlers.get(c)?.error(new mr.NoRespondersError(e)),h()});let r={id:c,method:`stream`,params:{__stream:!0,__streamSubject:l,args:t}};await n.publish(e,r,{reply:`rpc.reply.${c}`})},v={async next(){if(i)return{value:void 0,done:!0};if(!r){r=!0;try{await _()}catch(e){throw await h(),e}if(i)return await h(),{value:void 0,done:!0}}if(s)throw await h(),s;if(d.length>0)return{value:d.shift(),done:!1};if(o)return await h(),{value:void 0,done:!0};let e=await new Promise((e,t)=>{if(i){e({value:void 0,done:!0});return}if(o){e({value:void 0,done:!0});return}if(s){t(s);return}f=e});if(i)return await h(),{value:void 0,done:!0};if(e.done){if(s)throw await h(),s;return await h(),{value:void 0,done:!0}}return{value:e.value,done:!1}},async return(e){return i?{value:e,done:!0}:(i=!0,p(),r&&await h(),{value:e,done:!0})},async throw(e){throw i?e:(i=!0,p(),r&&await h(),e)},[Symbol.asyncIterator](){return v},async[Symbol.asyncDispose](){await v.return()}};return v}callPullIterator(e,...t){let n=this,r=!1,i=!1,a=!1,o=!1,s=null,c=``,l=``,u=``,d=``,f,p=[],m=null,h=()=>{let e=m;e&&(m=null,e({id:c,type:`done`}))},g=()=>{o||(o=!0,s=jc(Mc.CONNECTION_CLOSED,`Connection closed`));let e=m;e&&(m=null,e(s?{id:c,type:`error`,error:s.toJSON?.()??{code:Mc.CONNECTION_CLOSED,message:`Connection closed`}}:{id:c,type:`done`}))},_=async()=>{if(!a&&(a=!0,n.pullIteratorSettles.delete(g),n.statusHandlers.delete(c),f?.(),!o)){o=!0;try{let e={id:c,type:`cancel`};await n.publish(l,e)}catch{}}},v=async()=>{if(!n.isConnected&&!n.isClosed&&await n.connect(),!n.nc)throw Error(`Not connected`);if(n.ensureMuxSubscription(),n.pullIteratorSettles.add(g),c=Uc(n.replyPrefix),l=`_rpc.iterator.${c}.request`,u=`_rpc.iterator.${c}.response`,d=`rpc.reply.${c}`,(await n.call(e,{__pullIterator:!0,__iteratorId:c,args:t}))?.iteratorId!==c)throw Error(`Failed to initialize pull iterator`);f=await n.subscribe(u,e=>{if(e.type===`error`?(s=Ac.fromJSON(e.error),o=!0):e.type===`done`&&(o=!0),m){let t=m;m=null,t(e)}else p.push(e)}),n.statusHandlers.set(c,()=>{let t=new mr.NoRespondersError(e);o=!0,s=jc(`503`,t.message);let n={type:`error`,id:c,error:s.toJSON()};if(m){let e=m;m=null,e(n)}else p.push(n)})},y={async next(){if(i)return{value:void 0,done:!0};if(!r){r=!0;try{await v()}catch(e){throw await _(),e}if(i)return await _(),{value:void 0,done:!0}}let e={id:c,type:`next`};try{await n.publish(l,e,{reply:d})}catch(e){throw await _(),e}let t=await new Promise((e,t)=>{if(i){e({id:c,type:`done`});return}p.length>0?e(p.shift()):o&&s?t(s):o?e({id:c,type:`done`}):m=e});if(i)return await _(),{value:void 0,done:!0};if(t.type===`error`)throw await _(),Ac.fromJSON(t.error);return t.type===`done`?(await _(),{value:void 0,done:!0}):{value:t.value,done:!1}},async return(e){return i?{value:e,done:!0}:(i=!0,h(),r&&await _(),{value:e,done:!0})},async throw(e){throw i?e:(i=!0,h(),r&&await _(),e)},[Symbol.asyncIterator](){return y},async[Symbol.asyncDispose](){await y.return()}};return y}callPullIteratorWithCallback(e,t,n,...r){let i=Array.isArray(n)?void 0:n,a=Array.isArray(n)?n:n.onewayMethods,o=i?.prefetch??!1,s=this,c=!1,l=!1,u=!1,d=!1,f=null,p=``,m=``,h=``,g=``,_=``,v,y,b,x=[],S=null,C=Promise.resolve(),w=!1,T=()=>{let e=S;e&&(S=null,e({id:p,type:`done`}))},E=()=>{d||(d=!0,f=jc(Mc.CONNECTION_CLOSED,`Connection closed`));let e=S;e&&(S=null,e(f?{id:p,type:`error`,error:f.toJSON?.()??{code:Mc.CONNECTION_CLOSED,message:`Connection closed`}}:{id:p,type:`done`}))},D=async()=>{if(!u&&(u=!0,s.pullIteratorSettles.delete(E),s.statusHandlers.delete(p),v?.(),b?.(),!d)){d=!0;try{let e={id:p,type:`cancel`};await s.publish(m,e)}catch{}}},O=async()=>{if(!s.isConnected&&!s.isClosed&&await s.connect(),!s.nc)throw Error(`Not connected`);s.ensureMuxSubscription(),s.pullIteratorSettles.add(E),p=Uc(s.replyPrefix),m=`_rpc.iterator.${p}.request`,h=`_rpc.iterator.${p}.response`,g=`_rpc.cb.${p}`,_=`rpc.reply.${p}`;let n=Object.keys(t).filter(e=>typeof t[e]==`function`),i=await s.subscribeEntry(g,e=>{let n=t[e.method];if(!n){console.error(`[rpc] Pull-callback: unknown method '${e.method}'`);return}C=C.then(async()=>{try{await n(...e.args??[])}catch(t){console.error(`[rpc] Pull-callback handler '${e.method}' threw:`,t)}})});v=i.unsubscribe,y=()=>i.entry.flush?.()??Promise.resolve();let o={__pullCallback:!0,__iteratorId:p,__callbackSubject:g,__callbackMethods:n,__onewayMethods:a,args:r},c;try{c=await s.call(e,o)}catch(e){throw v?.(),v=void 0,e}if(c?.iteratorId!==p)throw v?.(),v=void 0,Error(`Failed to initialize pull-callback iterator`);b=await s.subscribe(h,e=>{if(e.type===`error`?(f=Ac.fromJSON(e.error),d=!0):e.type===`done`&&(d=!0),S){let t=S;S=null,t(e)}else x.push(e)}),s.statusHandlers.set(p,()=>{let t=new mr.NoRespondersError(e);d=!0,f=jc(`503`,t.message);let n={type:`error`,id:p,error:f.toJSON()};if(S){let e=S;S=null,e(n)}else x.push(n)})},k={async next(){if(l)return{value:void 0,done:!0};if(!c){c=!0;try{await O()}catch(e){throw await D(),e}if(l)return await D(),{value:void 0,done:!0}}if(w)w=!1;else{let e={id:p,type:`next`};try{await s.publish(m,e,{reply:_})}catch(e){throw await D(),e}}let e=await new Promise((e,t)=>{if(l){e({id:p,type:`done`});return}x.length>0?e(x.shift()):d&&f?t(f):d?e({id:p,type:`done`}):S=e});if(l)return await D(),{value:void 0,done:!0};if(e.type===`error`)throw await D(),Ac.fromJSON(e.error);if(e.type===`done`)return await y?.(),await C,await D(),{value:void 0,done:!0};if(o&&!d&&!l)try{let e={id:p,type:`next`};await s.publish(m,e,{reply:_}),w=!0}catch{w=!1}return await y?.(),await C,{value:void 0,done:!1}},async return(e){return l?{value:e,done:!0}:(l=!0,T(),c&&await D(),{value:e,done:!0})},async throw(e){throw l?e:(l=!0,T(),c&&await D(),e)},[Symbol.asyncIterator](){return k},async[Symbol.asyncDispose](){await k.return()}};return k}async callWithCallback(e,t,n){if(!this.isConnected&&!this.isClosed&&await this.connect(),!this.nc)throw Error(`Not connected`);let r=Uc(this.replyPrefix),i=`rpc.cb.${r}`,a=await this.subscribe(i,async e=>{if(e.type===`data`)try{await n(e.data)}catch(e){console.error(`[rpc] Callback error:`,e)}else e.type===`error`&&console.error(`[rpc] Callback error:`,e.error)}),o={__callback:!0,__callbackSubject:i,args:t};try{await this.call(e,o)}catch(e){throw a(),e}return()=>{this.publish(`${i}.cancel`,{id:r}).catch(()=>{}),a()}}async registerHandler(e,t,n){if(!this.nc&&!n?.isolatedConnection)throw Error(`Not connected`);let r=this;n?.isolatedConnection&&(r=this.createIsolatedClient({...this.options,name:`${this.options.name}-handler-${e}`}),await r.connect(),this.isolatedClients.push(r));let i=[],a=[],o=[],s=n?.withoutDecorators?Oc(t):kc(t),c=Object.keys(s);for(let[t,l]of Object.entries(s)){let s=`rpc.${e}.${t}`,u=await r.subscribe(s,async e=>{let n={id:e.id};e.__discover===!0&&(n.__methods=c);try{if(e.params?.__stream&&e.params?.__streamSubject){let n=e.params.__streamSubject,i=e.params.args??[];qc(l,i,n,e.id,r).catch(e=>{console.error(`Stream request error for ${t}:`,e)});return}else if(e.params?.__pullIterator||Array.isArray(e.params)&&e.params[0]?.__pullIterator){let t=e.params?.__pullIterator?e.params:e.params[0],i=t.args??[],o=t.__iteratorId??e.id,s=await Xc(l,i,o,r,()=>r.pullIteratorCleanups.delete(o));r.pullIteratorCleanups.set(o,s),a.push(o),n.result={iteratorId:o};let c=`rpc.reply.${e.id}`;await r.publish(c,n)}else if(e.params?.__pullCallback||Array.isArray(e.params)&&e.params[0]?.__pullCallback){let t=e.params?.__pullCallback?e.params:e.params[0],i=t.args??[],o=t.__iteratorId??e.id,s=t.__callbackSubject,c=t.__callbackMethods??[],u=t.__onewayMethods??[],d=await Zc(l,i,o,s,c,u,r,()=>r.pullIteratorCleanups.delete(o));r.pullIteratorCleanups.set(o,d),a.push(o),n.result={iteratorId:o};let f=`rpc.reply.${e.id}`;await r.publish(f,n)}else if(e.params&&typeof e.params==`object`&&!Array.isArray(e.params)&&e.params.__callback&&e.params.__callbackSubject||Array.isArray(e.params)&&e.params.length>0&&typeof e.params[0]==`object`&&e.params[0]?.__callback){let t=Array.isArray(e.params)&&e.params[0]?.__callback?e.params[0]:e.params,i=t.__callbackSubject,a=t.args??[],s=await Qc(l,a,i,e.id,r,()=>r.callbackCleanups.delete(e.id));r.callbackCleanups.set(e.id,s),o.push(e.id),n.result={ok:!0};let c=`rpc.reply.${e.id}`;await r.publish(c,n)}else{n.result=await Jc(l,e.params);let t=`rpc.reply.${e.id}`;await r.publish(t,n)}}catch(t){n.error=Yc(t),n.error.code===Mc.METHOD_NOT_FOUND&&(n.__methods=c);try{let t=`rpc.reply.${e.id}`;await r.publish(t,n)}catch(e){if(r.isClosed)return;console.error(`Failed to send error response:`,e)}}},n?.queue?{queue:n.queue}:void 0);i.push(u)}return async()=>{for(let e of i)e();if(await Promise.allSettled(a.map(e=>{let t=r.pullIteratorCleanups.get(e);return r.pullIteratorCleanups.delete(e),t?t():Promise.resolve()})),await Promise.allSettled(o.map(e=>{let t=r.callbackCleanups.get(e);return r.callbackCleanups.delete(e),t?t():Promise.resolve()})),n?.isolatedConnection){await r.disconnect();let e=this.isolatedClients.indexOf(r);e>=0&&this.isolatedClients.splice(e,1)}}}async onRequest(e,t){if(!this.nc)throw Error(`Not connected`);let n=this.nc.subscribe(e,{callback:(n,r)=>{(async()=>{try{let e=await t(xc(r.data));if(r.reply){let t=bc(e);r.respond(t)}}catch(t){if(r.reply){let e=bc({error:t instanceof Error?t.message:`Internal error`,code:t instanceof Ac?t.code:Mc.INTERNAL_ERROR});r.respond(e)}console.error(`Error in request handler for ${e}:`,t)}})()}});return()=>{n.unsubscribe()}}async channel(e,t){let n;t?.isolatedConnection?(n=this.createIsolatedClient({...this.options,name:`${this.options.name}-channel-${e}`}),this.isolatedClients.push(n),await n.connect()):n=this;let r=new Mo(n,e);return await r.init(),t?.isolatedConnection&&(r._isolatedClient=n),r}async privateChannel(e,t,n){let r;n?.isolatedConnection?(r=this.createIsolatedClient({...this.options,name:`${this.options.name}-private-${e}`}),this.isolatedClients.push(r),await r.connect()):r=this;let i=new No(r,e,t);return await i.init(),n?.isolatedConnection&&(i._isolatedClient=r),i}createProxy(e,t){let n;t?.isolatedConnection?(n=this.createIsolatedClient({...this.options,name:`${this.options.name}-proxy-${e}`}),this.isolatedClients.push(n)):n=this;let r=Rc(n,e);return t?.isolatedConnection?(r._isolatedClient=n,{proxy:r,close:async()=>{await n.disconnect();let e=this.isolatedClients.indexOf(n);e>=0&&this.isolatedClients.splice(e,1)}}):r}async createServiceProxy(e,t){let n;t?.isolatedConnection?(n=this.createIsolatedClient({...this.options,name:`${this.options.name}-service-${e}`}),this.isolatedClients.push(n),await n.connect()):n=this;let r=n.service.monitor(),i=[];for await(let t of await r.info(e))i.push(t);if(i.length===0){if(t?.isolatedConnection){await n.disconnect();let e=this.isolatedClients.indexOf(n);e>=0&&this.isolatedClients.splice(e,1)}throw Error(`No services found with name: ${e}`)}let a=t?.preferredId?i.find(e=>e.id===t.preferredId)??i[0]:i[0],o=zc(n,a,t?.timeout);return t?.isolatedConnection?(o._isolatedClient=n,{proxy:o,close:async()=>{await n.disconnect();let e=this.isolatedClients.indexOf(n);e>=0&&this.isolatedClients.splice(e,1)}}):o}};function ll(e,t){return t?t.aborted?(e.then(e=>ul(e)).catch(()=>{}),Promise.reject(new DOMException(`Aborted`,`AbortError`))):new Promise((n,r)=>{let i=!1,a=()=>{i||(i=!0,e.then(e=>ul(e)).catch(()=>{}),r(new DOMException(`Aborted`,`AbortError`)))};t.addEventListener(`abort`,a,{once:!0}),e.then(e=>{if(i){ul(e);return}i=!0,t.removeEventListener(`abort`,a),n(e)},e=>{i||(i=!0,t.removeEventListener(`abort`,a),r(e))})}):e}function ul(e){let t=e;try{typeof t.abortClose==`function`?t.abortClose():e.close().catch(()=>{})}catch{}}var dl={id:`nats`,kind:`persistent`,phaseGating:!0,graceMs:4e3};function fl(){let e=globalThis.crypto;if(e?.randomUUID)return e.randomUUID();if(e?.getRandomValues){let t=new Uint8Array(16);return e.getRandomValues(t),Array.from(t,e=>e.toString(16).padStart(2,`0`)).join(``)}return`${Date.now()}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`}function pl(e={}){let t={...dl,...e.spec},n=e.proxyPath??`/api/proxy`,r=e.clientName??`@camera.ui/transport/nats`,i=e.natsUser??`secret`,a=e.natsPassword??`secret`,o=e.reconnectTimeWait??1e3,s=e.reconnectionDelayMax??5e3,c=e.reconnectionRandomizationFactor??.5,l=e.timeout??1e4,u=e.connectTimeout??5e3,d=e.pingInterval??25e3,f=e.pingTimeout??2e4,p=e.maxPingOut??1,m=e.logger,h=new an,g=new Set,_=null,v=null,y={up:!1},b=null,x=!1,S=null,C=0,w=null;function T(e){let t=new URL(e.endpoint.url),r=t.protocol===`https:`?`wss:`:`ws:`,i=t.port||(t.protocol===`https:`?`443`:`80`),a=t.pathname.replace(/\/$/,``),o=new URLSearchParams({token:e.tokens.access});return e.tokens.proxySession&&o.set(`session`,e.tokens.proxySession),S&&o.set(`connId`,S),[`${r}//${t.hostname}:${i}${a}${n}?${o.toString()}`]}function E(){let e=y.up?_:null;for(let t of[...g])try{t(e)}catch{}}function D(){y.up||(y={up:!0},m?.debug(`markUp`),h.emit(`up`,void 0))}function O(e){!y.up&&y.lastError===e||(y={up:!1,lastError:e},m?.debug(`markDown (${e})`),h.emit(`down`,{reason:e}))}function k(){b?.abort(),b=null}function A(e){k();let t=new AbortController;b=t,(async()=>{let n=e.status();if(n)for await(let e of n){if(t.signal.aborted)break;switch(m?.debug(`status: ${e.type}${`server`in e&&e.server?` server=${String(e.server)}`:``}`),e.type){case`reconnect`:D(),E();break;case`disconnect`:O(`disconnect`),E();break;case`staleConnection`:O(`staleConnection`),E();break;case`error`:j(e);break}}})().catch(()=>{})}function j(e){let t=ml(e.data),n=t.toLowerCase();if(n.includes(`auth`)||n.includes(`401`)||n.includes(`forbidden`)||n.includes(`403`)){h.emit(`auth-error`,{message:t});return}O(t)}async function M(e,t){m?.debug(`rebuildClient start (epoch=${t})`);let n=Date.now();if(k(),w?.abort(),_){try{_.abortClose()}catch{}_=null,E()}S=fl();let h=ol({servers:T(e),name:r,connId:S,auth:{user:i,password:a},reconnect:!0,maxReconnectAttempts:-1,reconnectTimeWait:o,reconnectionDelayMax:s,reconnectionRandomizationFactor:c,timeout:l,connectTimeout:u,pingInterval:d,pingTimeout:f,maxPingOut:p,ignoreAuthErrorAbort:!0}),g=new AbortController;w=g;try{await h.connect({signal:g.signal})}catch(e){try{h.abortClose()}catch{}if(x||t!==C)return;let r=e instanceof Error?e.message:String(e);throw m?.debug(`rebuildClient connect FAILED after ${Date.now()-n}ms: ${r}`),O(r),e}finally{w===g&&(w=null)}if(x||t!==C){try{h.abortClose()}catch{}return}_=h,m?.debug(`rebuildClient connected in ${Date.now()-n}ms`),D(),E(),A(h)}async function N(e){if(x)throw Error(`nats-transport disposed`);if(nn(v,e))return;let t=++C,n=rn(v,e);if(v=e,!e){if(k(),w?.abort(),w=null,_){try{_.abortClose()}catch{}_=null,E()}O(`detached`);return}if(n||!_){try{await M(e,t)}catch(n){throw t===C&&v===e&&(v=null),n}return}let r=T(e);_.setServers(r)}function P(){return y.up&&_?.isStale?{up:!1,lastError:`staleConnection`}:y}function ee(e,t){return h.on(e,t)}async function F(){if(x=!0,C++,k(),w?.abort(),w=null,_){try{_.abortClose()}catch{}_=null,E()}g.clear(),y={up:!1},h.clear()}function I(){return y.up?_:null}function te(e){return g.add(e),e(y.up?_:null),()=>g.delete(e)}async function ne(e=5e3){if(!_)throw Error(`nats-transport: no client`);let t=Date.now();try{await _.flush(e),m?.debug(`probeAlive OK in ${Date.now()-t}ms`)}catch(e){throw m?.debug(`probeAlive FAILED after ${Date.now()-t}ms: ${e instanceof Error?e.message:String(e)}`),e}}async function L(){if(!_){m?.debug(`forceReconnect: no client`);return}m?.debug(`forceReconnect: issuing (up=${y.up} stale=${_.isStale})`);let e=Date.now();await _.forceReconnect(),m?.debug(`forceReconnect: returned after ${Date.now()-e}ms (up=${y.up})`)}return{spec:t,apply:N,health:P,on:ee,dispose:F,getClient:I,subscribeClient:te,probeAlive:ne,forceReconnect:L}}function ml(e){if(e instanceof Error)return e.message;if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}var hl={id:`socketio`,kind:`persistent`,phaseGating:!0,graceMs:4e3};function gl(e={}){let t={...hl,...e.spec},n=e.path??`/api/socket.io`,r=e.mainNamespace??`/camera.ui`,i=e.reconnection??!0,a=e.reconnectionDelay??1e3,o=e.reconnectionDelayMax??5e3,s=e.timeout??2e4,c=e.logger,l=new an,u=new Map,d=null,f=null,p={up:!1},m=!1;function h(e){let t={token:`Bearer ${e.tokens.access}`};return e.tokens.proxySession&&(t.session=e.tokens.proxySession),t}function _(e){let t={};return e.tokens.proxySession&&(t.session=e.tokens.proxySession),t}function v(){p.up||(p={up:!0},c?.debug(`markUp`),l.emit(`up`,void 0))}function y(e){!p.up&&p.lastError===e||(p={up:!1,lastError:e},c?.debug(`markDown (${e})`),l.emit(`down`,{reason:e}))}function b(e){let t=e.toLowerCase();return t.includes(`auth`)||t.includes(`unauthorized`)}function x(e){let t=!1;e.on(`unauthenticated`,()=>{let n=f?h(f):null,r=e.auth?.token;n&&r!==n.token?(e.auth=n,t=!0):l.emit(`auth-error`,{message:`unauthenticated`})}),e.on(`disconnect`,()=>{t&&(t=!1,e.connect())})}function S(e){e.on(`connect`,()=>v()),e.on(`disconnect`,e=>y(e)),e.on(`connect_error`,e=>{let t=e?.message??`connect_error`;if(c?.debug(`connect_error (main): ${t}`),b(t)){l.emit(`auth-error`,{message:t});return}y(t)}),x(e)}function C(e){e.on(`connect_error`,e=>{let t=e?.message??`connect_error`;b(t)&&l.emit(`auth-error`,{message:t})}),x(e)}function w(e){return new URL(e.endpoint.url).origin}function T(e){return`${new URL(e.endpoint.url).pathname.replace(/\/$/,``)}${n}`}function E(e,t){let n=ie(`${w(t)}${e}`,{path:T(t),auth:h(t),query:_(t),reconnection:i,reconnectionDelay:a,reconnectionDelayMax:o,timeout:s,rejectUnauthorized:!1,transports:[`websocket`]});return u.set(e,n),n}function D(e){O(),d=new g(w(e),{path:T(e),autoConnect:!1,reconnection:i,reconnectionDelay:a,reconnectionDelayMax:o,timeout:s,rejectUnauthorized:!1,transports:[`websocket`]}),S(E(r,e))}function O(){for(let e of u.values())e.removeAllListeners(),e.disconnect();u.clear(),d&&=(d._close(),null)}function k(e){let t=h(e);for(let e of u.values())e.auth=t,e.connected||e.connect()}async function A(e){if(m)throw Error(`socketio-transport disposed`);if(nn(f,e))return;let t=rn(f,e);if(f=e,!e){O(),y(`detached`);return}if(t||!d){D(e);return}k(e)}function j(){return p}function M(e,t){return l.on(e,t)}async function N(){m=!0,O(),f=null,p={up:!1},l.clear()}function P(e=r){return u.get(e)??null}function ee(e){if(!f)return null;let t=u.get(e);return t||(t=E(e,f),C(t)),t}function F(){if(!f)return;let e=h(f),t=0;for(let n of u.values())n.connected||(n.auth=e,n.connect(),t++);c?.debug(`reviveDeadSockets: ${t}/${u.size} reconnecting`)}return{get spec(){return t},get manager(){return d},apply:A,health:j,on:M,dispose:N,socket:P,ensureSocket:ee,reviveDeadSockets:F}}var _l={id:`ws`,kind:`per-resource`,phaseGating:!1},vl=4e3,yl=4001,bl=4002;function xl(e={}){let t={..._l,...e.spec},n=e.tokenParam??`token`,r=e.sessionParam??`session`,i=e.webSocketCtor??(typeof WebSocket<`u`?WebSocket:void 0),a=e.logger,o=new an,s=new Set,c=new WeakSet,l=null,u={up:!1},d=!1;function f(){if(!i)throw Error(`ws-transport: no WebSocket constructor available; pass webSocketCtor in non-browser environments`);return i}function p(e,t){let i=new URL(e.endpoint.url),a=i.protocol===`https:`?`wss:`:`ws:`,o=i.port||(i.protocol===`https:`?`443`:`80`),s=i.pathname.replace(/\/$/,``),c=new URLSearchParams;for(let[e,n]of Object.entries(t.query??{}))n!=null&&n!==``&&c.set(e,n);return c.set(n,e.tokens.access),e.tokens.proxySession&&c.set(r,e.tokens.proxySession),`${a}//${i.hostname}:${o}${s}${t.path}?${c.toString()}`}function m(e){if(e.code===1008||e.code===4401)return!0;if(!e.reason)return!1;let t=e.reason.toLowerCase();return t.includes(`unauthorized`)||t.includes(`forbidden`)||t.includes(`401`)||t.includes(`403`)}function h(e,t){t.onopen=()=>{if(!(e.disposed||e.ws!==t)){a?.debug(`open ${e.spec.path}`),u.up||(u={up:!0},o.emit(`up`,void 0));for(let t of[...e.listeners.open])t()}},t.onclose=n=>{let r=e.ws===t;if(r&&(e.ws=null,e.url=null),c.has(t)||(c.add(t),!r))return;a?.debug(`close ${e.spec.path} code=${n.code} clean=${n.wasClean}${n.reason?` reason=${n.reason}`:``}`),m(n)&&o.emit(`auth-error`,{message:n.reason||`ws close code ${n.code}`});let i={code:n.code,reason:n.reason,wasClean:n.wasClean};for(let t of[...e.listeners.close])t(i)},t.onmessage=n=>{if(!(e.disposed||e.ws!==t))for(let t of[...e.listeners.message])t(n)},t.onerror=n=>{if(!(e.disposed||e.ws!==t))for(let t of[...e.listeners.error])t(n)}}function g(e,t,n){let r=e.ws;if(!r)return;let i=f();if(r.readyState===i.OPEN||r.readyState===i.CONNECTING){try{r.close(t,n)}catch{}return}if(e.ws===r&&(e.ws=null,e.url=null),c.has(r))return;c.add(r);let a={code:t,reason:n,wasClean:!1};for(let t of[...e.listeners.close])t(a)}function _(e){if(e.disposed||!l)return;let t=p(l,e.spec),n=new(f())(t,e.spec.protocols);e.spec.binaryType&&(n.binaryType=e.spec.binaryType),e.ws=n,e.url=t,h(e,n)}function v(e,t){let n=[...s];a?.debug(`recycleAll (${t}) handles=${n.length}`);for(let r of n)g(r,e,t);if(u.up&&(u={up:!1,lastError:t},o.emit(`down`,{reason:t})),l)for(let e of s)e.disposed||_(e)}async function y(e){if(d)throw Error(`ws-transport disposed`);if(nn(l,e))return;let t=rn(l,e);if(l=e,!e){let e=[...s];for(let t of e)g(t,yl,`detached`);u={up:!1},o.emit(`down`,{reason:`detached`});return}t&&v(vl,`endpoint-changed`)}function b(){return u}function x(e,t){return o.on(e,t)}async function S(){d=!0;let e=[...s];for(let t of e)t.disposed=!0,t.listeners.open.clear(),t.listeners.close.clear(),t.listeners.message.clear(),t.listeners.error.clear(),g(t,bl,`disposed`);s.clear(),l=null,u={up:!1},o.clear()}function C(e){if(d)throw Error(`ws-transport disposed`);let t={api:void 0,spec:e,listeners:{open:new Set,close:new Set,message:new Set,error:new Set},ws:null,url:null,disposed:!1};function n(e){if(t.disposed)throw Error(`ws-handle disposed`);let n=t.ws;if(!n)throw Error(`ws-handle: no active socket`);if(n.readyState!==i.OPEN)throw Error(`ws-handle: socket not open`);n.send(e)}function r(e,n){g(t,e??1e3,n??``)}function a(e,n){let r=t.listeners[e];return r.add(n),()=>{r.delete(n)}}function o(){t.disposed||(t.disposed=!0,t.listeners.open.clear(),t.listeners.close.clear(),t.listeners.message.clear(),t.listeners.error.clear(),g(t,bl,`disposed`),s.delete(t))}return t.api={get readyState(){return t.ws?.readyState??i?.CLOSED??3},get url(){return t.url},send:n,close:r,on:a,dispose:o},s.add(t),l&&_(t),t.api}return{get spec(){return t},get handleCount(){return s.size},apply:y,health:b,on:x,dispose:S,open:C}}function Sl(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Cl(e){let t=e.url??``,n=e.baseURL??``;return n&&!Sl(t)?`${n.replace(/\/+$/,``)}/${t.replace(/^\/+/,``)}`:t}function wl(e){let t;try{t=new URL(e).hostname}catch{return!1}return!t||t===`localhost`||t.endsWith(`.local`)||t.includes(`:`)||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(t)?!1:t.includes(`.`)}function Tl(e){return!e.withCredentials&&wl(Cl(e))}function El(e){return async t=>{Ol(t.signal);let n=Al(t.headers);e.extraHeaders&&Object.assign(n,e.extraHeaders);let r=typeof t.timeout==`number`&&t.timeout>0?t.timeout:void 0,i=e.request({url:Cl(t),method:(t.method??`get`).toUpperCase(),headers:n,params:jl(t.params),data:Ml(t),responseType:Nl(t.responseType),connectTimeout:r,readTimeout:r}),a;try{a=await kl(i,t.signal)}catch(e){throw e instanceof se?e:new He(e instanceof Error?e.message:`Network Error`,He.ERR_NETWORK,t,i)}let o={data:a.data,status:a.status,statusText:``,headers:x.from(a.headers??{}),config:t,request:i};if(!t.validateStatus||t.validateStatus(a.status))return o;throw new He(`Request failed with status code ${a.status}`,a.status>=500?He.ERR_BAD_RESPONSE:He.ERR_BAD_REQUEST,t,i,o)}}function Dl(e,t){if(!t.enabled)return;let n=oe.getAdapter(e.defaults.adapter??oe.defaults.adapter),r=El(t);e.defaults.adapter=e=>Tl(e)?r(e):n(e)}function Ol(e){if(e?.aborted)throw new se(`canceled`)}function kl(e,t){return!t||typeof t.addEventListener!=`function`?e:t.aborted?Promise.reject(new se(`canceled`)):new Promise((n,r)=>{let i=()=>r(new se(`canceled`));t.addEventListener(`abort`,i,{once:!0});let a=()=>t.removeEventListener?.(`abort`,i);e.then(e=>{a(),n(e)},e=>{a(),r(e)})})}function Al(e){let t={};if(!e)return t;let n=x.from(e).toJSON();for(let[e,r]of Object.entries(n))r!=null&&(t[e]=Array.isArray(r)?r.join(`, `):String(r));return t}function jl(e){if(!e||typeof e!=`object`)return;let t={};for(let[n,r]of Object.entries(e))r!=null&&(t[n]=String(r));return t}function Ml(e){let t=e.data;if(typeof t!=`string`)return t;if(String(x.from(e.headers).get(`Content-Type`)??``).includes(`application/json`))try{return JSON.parse(t)}catch{}return t}function Nl(e){switch(e){case`blob`:return`blob`;case`arraybuffer`:return`arraybuffer`;default:return`text`}}function Pl(e={}){function t(e){return typeof e==`function`}let n=t(e)?{mounted:e,updated:e}:e,{mounted:r,unmounted:i}=n;if(!t(r))return e;let a=new WeakMap;return{...n,mounted(e,t,n,i){let o=a.get(e)??ke();a.set(e,o),o.run(()=>{r?.(e,t,n,i)})},unmounted(e,n,r,o){var s;(s=a.get(e))==null||s.stop(),a.delete(e),t(i)&&i(e,n,r,o)}}}function Fl(e,t){return de()?(Xe(e,t),!0):!1}var Il=new WeakMap,Ll=(...e)=>{let t=e[0],n=it()?.proxy??de();if(n==null&&!tt())throw Error(`injectLocal must be called in setup`);return n&&Il.has(n)&&t in Il.get(n)?Il.get(n)[t]:F(...e)},Rl=typeof window<`u`&&typeof document<`u`;typeof WorkerGlobalScope<`u`&&globalThis instanceof WorkerGlobalScope;var zl=e=>e!=null,Bl=Object.prototype.toString,Vl=e=>Bl.call(e)===`[object Object]`,Hl=()=>{},Ul=Wl();function Wl(){var e,t;return Rl&&!!(!((e=window)==null||(e=e.navigator)==null)&&e.userAgent)&&(/iP(?:ad|hone|od)/.test(window.navigator.userAgent)||((t=window)==null||(t=t.navigator)==null?void 0:t.maxTouchPoints)>2&&/iPad|Macintosh/.test(window?.navigator.userAgent))}function Gl(...e){if(e.length!==1)return $e(...e);let t=e[0];return typeof t==`function`?Se(We(()=>({get:t,set:Hl}))):K(t)}function Kl(e,t){function n(...n){return new Promise((r,i)=>{Promise.resolve(e(()=>t.apply(this,n),{fn:t,thisArg:this,args:n})).then(r).catch(i)})}return n}var ql=e=>e();function Jl(e,t={}){let n,r,i=Hl,a=e=>{clearTimeout(e),i(),i=Hl},o;return s=>{let c=B(e),l=B(t.maxWait);return n&&a(n),c<=0||l!==void 0&&l<=0?(r&&=(a(r),void 0),Promise.resolve(s())):new Promise((e,u)=>{i=t.rejectOnCancel?u:e,o=s,l&&!r&&(r=setTimeout(()=>{n&&a(n),r=void 0,e(o())},l)),n=setTimeout(()=>{r&&a(r),r=void 0,e(s())},c)})}}function Yl(...e){let t=0,n,r=!0,i=Hl,a,o,s,c,l;!ge(e[0])&&typeof e[0]==`object`?{delay:o,trailing:s=!0,leading:c=!0,rejectOnCancel:l=!1}=e[0]:[o,s=!0,c=!0,l=!1]=e;let u=()=>{n&&(clearTimeout(n),n=void 0,i(),i=Hl)};return e=>{let d=B(o),f=Date.now()-t,p=()=>a=e();return u(),d<=0?(t=Date.now(),p()):(f>d?(t=Date.now(),(c||!r)&&p()):s&&(a=new Promise((e,a)=>{i=l?a:e,n=setTimeout(()=>{t=Date.now(),r=!0,e(p()),u()},Math.max(0,d-f))})),!c&&!n&&(n=setTimeout(()=>r=!0,d)),r=!1,a)}}function Xl(e=ql,t={}){let{initialState:n=`active`}=t,r=Gl(n===`active`);function i(){r.value=!1}function a(){r.value=!0}return{isActive:Ee(r),pause:i,resume:a,eventFilter:(...t)=>{r.value&&e(...t)}}}function Zl(e){return e.endsWith(`rem`)?Number.parseFloat(e)*16:Number.parseFloat(e)}function Ql(e){return Array.isArray(e)?e:[e]}function $l(e){let t=Object.create(null);return(n=>t[n]||(t[n]=e(n)))}var eu=/-(\w)/g,tu=$l(e=>e.replace(eu,(e,t)=>t?t.toUpperCase():``));function nu(e){return e||it()}function ru(e){if(!Rl)return e;let t=0,n,r,i=()=>{--t,r&&t<=0&&(r.stop(),n=void 0,r=void 0)};return((...a)=>(t+=1,r||(r=ke(!0),n=r.run(()=>e(...a))),Fl(i),n))}function iu(e,t,{enumerable:n=!1,unwrap:r=!0}={}){for(let[i,a]of Object.entries(t))i!==`value`&&(ge(a)&&r?Object.defineProperty(e,i,{get(){return a.value},set(e){a.value=e},enumerable:n}):Object.defineProperty(e,i,{value:a,enumerable:n}));return e}function au(e,t){if(typeof Symbol<`u`){let n={...e};return Object.defineProperty(n,Symbol.iterator,{enumerable:!1,value(){let e=0;return{next:()=>({value:t[e++],done:e>t.length})}}}),n}else return Object.assign([...t],e)}function ou(e){return ge(e)?ye(new Proxy({},{get(t,n,r){return J(Reflect.get(e.value,n,r))},set(t,n,r){return ge(e.value[n])&&!ge(r)?e.value[n].value=r:e.value[n]=r,!0},deleteProperty(t,n){return Reflect.deleteProperty(e.value,n)},has(t,n){return Reflect.has(e.value,n)},ownKeys(){return Object.keys(e.value)},getOwnPropertyDescriptor(){return{enumerable:!0,configurable:!0}}})):ye(e)}function su(e){return ou(W(e))}function cu(e,...t){let n=t.flat(),r=n[0];return su(()=>Object.fromEntries(typeof r==`function`?Object.entries(ot(e)).filter(([e,t])=>!r(B(t),e)):Object.entries(ot(e)).filter(e=>!n.includes(e[0]))))}function lu(e,t=200,n={}){return Kl(Jl(t,n),e)}function uu(e,t=200,n=!1,r=!0,i=!1){return Kl(Yl(t,n,r,i),e)}function du(e,t={}){let n=e,r,i,a=We((e,t)=>(r=e,i=t,{get(){return o()},set(e){s(e)}}));function o(e=!0){return e&&r(),n}function s(e,r=!0){var a;if(e===n)return;let o=n;t.onBeforeChange?.call(t,e,o)!==!1&&(n=e,(a=t.onChanged)==null||a.call(t,e,o),r&&i())}return iu(a,{get:o,set:s,untrackedGet:()=>o(!1),silentSet:e=>s(e,!1),peek:()=>o(!1),lay:e=>s(e,!1)},{enumerable:!0})}function fu(e,t,n={}){let{eventFilter:r=ql,...i}=n;return A(e,Kl(r,t),i)}function pu(e,t,n={}){let{eventFilter:r,initialState:i=`active`,...a}=n,{eventFilter:o,pause:s,resume:c,isActive:l}=Xl(r,{initialState:i});return{stop:fu(e,t,{...a,eventFilter:o}),pause:s,resume:c,isActive:l}}function mu(e,t={}){if(!ge(e))return ot(e);let n=Array.isArray(e.value)?Array.from({length:e.value.length}):{};for(let r in e.value)n[r]=We(()=>({get(){return e.value[r]},set(n){if(B(t.replaceRef)??!0)if(Array.isArray(e.value)){let t=[...e.value];t[r]=n,e.value=t}else{let t={...e.value,[r]:n};Object.setPrototypeOf(t,Object.getPrototypeOf(e.value)),e.value=t}else e.value[r]=n}}));return n}function hu(e,t=!0,n){nu(n)?y(e,n):t?e():s(e)}function gu(e,t){nu(t)&&C(e,t)}var _u=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[T\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/i,vu=/[YMDHhms]o|\[([^\]]+)\]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a{1,2}|A{1,2}|m{1,2}|s{1,2}|Z{1,2}|z{1,4}|SSS/g;function yu(e,t,n,r){let i=e<12?`AM`:`PM`;return r&&(i=i.split(``).reduce((e,t)=>e+=`${t}.`,``)),n?i.toLowerCase():i}function bu(e){let t=[`th`,`st`,`nd`,`rd`],n=e%100;return e+(t[(n-20)%10]||t[n]||t[0])}function xu(e,t,n={}){let r=e.getFullYear(),i=e.getMonth(),a=e.getDate(),o=e.getHours(),s=e.getMinutes(),c=e.getSeconds(),l=e.getMilliseconds(),u=e.getDay(),d=n.customMeridiem??yu,f=e=>e.split(` `)[1]??``,p={Yo:()=>bu(r),YY:()=>String(r).slice(-2),YYYY:()=>r,M:()=>i+1,Mo:()=>bu(i+1),MM:()=>`${i+1}`.padStart(2,`0`),MMM:()=>e.toLocaleDateString(B(n.locales),{month:`short`}),MMMM:()=>e.toLocaleDateString(B(n.locales),{month:`long`}),D:()=>String(a),Do:()=>bu(a),DD:()=>`${a}`.padStart(2,`0`),H:()=>String(o),Ho:()=>bu(o),HH:()=>`${o}`.padStart(2,`0`),h:()=>`${o%12||12}`.padStart(1,`0`),ho:()=>bu(o%12||12),hh:()=>`${o%12||12}`.padStart(2,`0`),m:()=>String(s),mo:()=>bu(s),mm:()=>`${s}`.padStart(2,`0`),s:()=>String(c),so:()=>bu(c),ss:()=>`${c}`.padStart(2,`0`),SSS:()=>`${l}`.padStart(3,`0`),d:()=>u,dd:()=>e.toLocaleDateString(B(n.locales),{weekday:`narrow`}),ddd:()=>e.toLocaleDateString(B(n.locales),{weekday:`short`}),dddd:()=>e.toLocaleDateString(B(n.locales),{weekday:`long`}),A:()=>d(o,s),AA:()=>d(o,s,!1,!0),a:()=>d(o,s,!0),aa:()=>d(o,s,!0,!0),z:()=>f(e.toLocaleDateString(B(n.locales),{timeZoneName:`shortOffset`})),zz:()=>f(e.toLocaleDateString(B(n.locales),{timeZoneName:`shortOffset`})),zzz:()=>f(e.toLocaleDateString(B(n.locales),{timeZoneName:`shortOffset`})),zzzz:()=>f(e.toLocaleDateString(B(n.locales),{timeZoneName:`longOffset`}))};return t.replace(vu,(e,t)=>t??p[e]?.call(p)??e)}function Su(e){if(e===null)return new Date(NaN);if(e===void 0)return new Date;if(e instanceof Date)return new Date(e);if(typeof e==`string`&&!/Z$/i.test(e)){let t=e.match(_u);if(t){let e=t[2]-1||0,n=(t[7]||`0`).substring(0,3);return new Date(t[1],e,t[3]||1,t[4]||0,t[5]||0,t[6]||0,n)}}return new Date(e)}function Cu(e,t=`HH:mm:ss`,n={}){return W(()=>xu(Su(B(e)),B(t),n))}function wu(e,t=1e3,n={}){let{immediate:r=!0,immediateCallback:i=!1}=n,a=null,o=H(!1);function s(){a&&=(clearInterval(a),null)}function c(){o.value=!1,s()}function l(){let n=B(t);n<=0||(o.value=!0,i&&e(),s(),o.value&&(a=setInterval(e,n)))}return r&&Rl&&l(),(ge(t)||typeof t==`function`)&&Fl(A(t,()=>{o.value&&Rl&&l()})),Fl(c),{isActive:Ee(o),pause:c,resume:l}}function Tu(e,t,n={}){let{immediate:r=!0,immediateCallback:i=!1}=n,a=H(!1),o;function s(){o&&=(clearTimeout(o),void 0)}function c(){a.value=!1,s()}function l(...n){i&&e(),s(),a.value=!0,o=setTimeout(()=>{a.value=!1,o=void 0,e(...n)},B(t))}return r&&(a.value=!0,Rl&&l()),Fl(c),{isPending:Ee(a),start:l,stop:c}}function Eu(e,t,n={}){let{debounce:r=0,maxWait:i=void 0,...a}=n;return fu(e,t,{...a,eventFilter:Jl(r,{maxWait:i})})}function Du(e,t,n){return A(e,t,{...n,immediate:!0})}function Ou(e,t,n){return A(e,t,{...n,once:!0})}function ku(e,t,n={}){let{throttle:r=0,trailing:i=!0,leading:a=!0,...o}=n;return fu(e,t,{...o,eventFilter:Yl(r,i,a)})}function Au(e,t,n){let r=A(e,(e,i,a)=>{e&&(n?.once&&s(()=>r()),t(e,i,a))},{...n,once:!1});return r}function ju(e,t,n){let r;r=ge(n)?{evaluating:n}:n||{};let{lazy:i=!1,flush:a=`sync`,evaluating:s=void 0,shallow:c=!0,onError:l=globalThis.reportError??Hl}=r,u=H(!i),d=c?H(t):K(t),f=0;return o(async t=>{if(!u.value)return;f++;let n=f,r=!1;s&&Promise.resolve().then(()=>{s.value=!0});try{let i=await e(e=>{t(()=>{s&&(s.value=!1),r||e()})});n===f&&(d.value=i)}catch(e){l(e)}finally{s&&n===f&&(s.value=!1),r=!0}},{flush:a}),i?W(()=>(u.value=!0,d.value)):d}function Mu(e={}){let{inheritAttrs:t=!0,name:n=`ReusableTemplate`}=e,r=H(),i=pe({name:`${n}.define`,setup(e,{slots:t}){return()=>{r.value=t.default}}}),a=pe({inheritAttrs:t,name:`${n}.reuse`,props:e.props,setup(n,{attrs:i,slots:a}){return()=>{if(!r.value)throw Error(`[VueUse] Failed to find the definition of reusable template`);let o=r.value?.call(r,{...e.props==null?Nu(i):n,$slots:a});return t&&o?.length===1?o[0]:o}}});return au({define:i,reuse:a},[i,a])}function Nu(e){let t={};for(let n in e)t[tu(n)]=e[n];return t}var Pu=Rl?window:void 0;Rl&&window.document,Rl&&window.navigator,Rl&&window.location;function Fu(e){let t=B(e);return t?.$el??t}function Iu(...e){let t=(e,t,n,r)=>(e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)),n=W(()=>{let t=Ql(B(e[0])).filter(e=>e!=null);return t.every(e=>typeof e!=`string`)?t:void 0});return Du(()=>[n.value?.map(e=>Fu(e))??[Pu].filter(e=>e!=null),Ql(B(n.value?e[1]:e[0])),Ql(J(n.value?e[2]:e[1])),B(n.value?e[3]:e[2])],([e,n,r,i],a,o)=>{if(!e?.length||!n?.length||!r?.length)return;let s=Vl(i)?{...i}:i,c=e.flatMap(e=>n.flatMap(n=>r.map(r=>t(e,n,r,s))));o(()=>{c.forEach(e=>e())})},{flush:`post`})}var Lu=!1;function Ru(e,t,n={}){let{window:r=Pu,ignore:i=[],capture:a=!0,detectIframe:o=!1,controls:s=!1}=n;if(!r)return s?{stop:Hl,cancel:Hl,trigger:Hl}:Hl;if(Ul&&!Lu){Lu=!0;let e={passive:!0};Array.from(r.document.body.children).forEach(t=>t.addEventListener(`click`,Hl,e)),r.document.documentElement.addEventListener(`click`,Hl,e)}let c=!0,l=e=>B(i).some(t=>{if(typeof t==`string`)return Array.from(r.document.querySelectorAll(t)).some(t=>t===e.target||e.composedPath().includes(t));{let n=Fu(t);return n&&(e.target===n||e.composedPath().includes(n))}});function u(e){let t=B(e);return t&&t.$.subTree.shapeFlag===16}function d(e,t){let n=B(e),r=n.$.subTree&&n.$.subTree.children;return r==null||!Array.isArray(r)?!1:r.some(e=>e.el===t.target||t.composedPath().includes(e.el))}let f=n=>{let r=Fu(e);if(n.target!=null&&!(!(r instanceof Element)&&u(e)&&d(e,n))&&!(!r||r===n.target||n.composedPath().includes(r))){if(`detail`in n&&n.detail===0&&(c=!l(n)),!c){c=!0;return}t(n)}},p=!1,m=[Iu(r,`click`,e=>{p||(p=!0,setTimeout(()=>{p=!1},0),f(e))},{passive:!0,capture:a}),Iu(r,`pointerdown`,t=>{let n=Fu(e);c=!l(t)&&!!(n&&!t.composedPath().includes(n))},{passive:!0}),o&&Iu(r,`blur`,n=>{setTimeout(()=>{let i=Fu(e),a=r.document.activeElement;for(;a?.shadowRoot;)a=a.shadowRoot.activeElement;a?.tagName===`IFRAME`&&!i?.contains(r.document.activeElement)&&t(n)},0)},{passive:!0})].filter(Boolean),h=()=>m.forEach(e=>e());return s?{stop:h,cancel:()=>{c=!1},trigger:e=>{c=!0,f(e),c=!1}}:h}function zu(){let e=H(!1),t=it();return t&&y(()=>{e.value=!0},t),e}function Bu(e){let t=zu();return W(()=>(t.value,!!e()))}function Vu(e,t,n={}){let{window:r=Pu,...i}=n,a,o=Bu(()=>r&&`MutationObserver`in r),s=()=>{a&&=(a.disconnect(),void 0)},c=A(W(()=>{let t=Ql(B(e)).map(Fu).filter(zl);return new Set(t)}),e=>{s(),o.value&&e.size&&(a=new MutationObserver(t),e.forEach(e=>a.observe(e,i)))},{immediate:!0,flush:`post`}),l=()=>a?.takeRecords(),u=()=>{c(),s()};return Fl(u),{isSupported:o,stop:u,takeRecords:l}}function Hu(e,t,n={}){let{window:r=Pu,document:i=r?.document,flush:a=`sync`}=n;if(!r||!i)return Hl;let s,c=e=>{s?.(),s=e},l=o(()=>{let n=Fu(e);if(n){let{stop:e}=Vu(i,e=>{e.map(e=>[...e.removedNodes]).flat().some(e=>e===n||e.contains(n))&&t(e)},{window:r,childList:!0,subtree:!0});c(e)}},{flush:a}),u=()=>{l(),c()};return Fl(u),u}function Uu(e){return typeof e==`function`?e:typeof e==`string`?t=>t.key===e:Array.isArray(e)?t=>e.includes(t.key):()=>!0}function Wu(...e){let t,n,r={};e.length===3?(t=e[0],n=e[1],r=e[2]):e.length===2?typeof e[1]==`object`?(t=!0,n=e[0],r=e[1]):(t=e[0],n=e[1]):(t=!0,n=e[0]);let{target:i=Pu,eventName:a=`keydown`,passive:o=!1,dedupe:s=!1}=r,c=Uu(t);return Iu(i,a,e=>{e.repeat&&B(s)||c(e)&&n(e)},o)}var Gu=500,Ku=10;function qu(e,t,n){var r,i;let a=W(()=>Fu(e)),o,s,c,l=!1;function u(){o&&=(clearTimeout(o),void 0),s=void 0,c=void 0,l=!1}function d(e){let t=n?.delay;return typeof t==`function`?t(e):t??Gu}function f(e){var t,r,i;let[o,d,f]=[c,s,l];if(u(),!n?.onMouseUp||!d||!o||!(n==null||(t=n.modifiers)==null)&&t.self&&e.target!==a.value)return;!(n==null||(r=n.modifiers)==null)&&r.prevent&&e.preventDefault(),!(n==null||(i=n.modifiers)==null)&&i.stop&&e.stopPropagation();let p=e.x-d.x,m=e.y-d.y,h=Math.sqrt(p*p+m*m);n.onMouseUp(e.timeStamp-o,h,f,e)}function p(e){var r,i,f;!(n==null||(r=n.modifiers)==null)&&r.self&&e.target!==a.value||(u(),!(n==null||(i=n.modifiers)==null)&&i.prevent&&e.preventDefault(),!(n==null||(f=n.modifiers)==null)&&f.stop&&e.stopPropagation(),s={x:e.x,y:e.y},c=e.timeStamp,o=setTimeout(()=>{l=!0,t(e)},d(e)))}function m(e){var t,r,i;if(!(n==null||(t=n.modifiers)==null)&&t.self&&e.target!==a.value||!s||n?.distanceThreshold===!1)return;!(n==null||(r=n.modifiers)==null)&&r.prevent&&e.preventDefault(),!(n==null||(i=n.modifiers)==null)&&i.stop&&e.stopPropagation();let o=e.x-s.x,c=e.y-s.y;Math.sqrt(o*o+c*c)>=(n?.distanceThreshold??Ku)&&u()}let h={capture:n==null||(r=n.modifiers)==null?void 0:r.capture,once:n==null||(i=n.modifiers)==null?void 0:i.once},g=[Iu(a,`pointerdown`,p,h),Iu(a,`pointermove`,m,h),Iu(a,[`pointerup`,`pointerleave`],f,h)];return()=>g.forEach(e=>e())}function Ju(e,t={}){let{immediate:n=!0,fpsLimit:r=null,window:i=Pu,once:a=!1}=t,o=H(!1),s=W(()=>{let e=B(r);return e?1e3/e:null}),c=0,l=null;function u(t){if(!o.value||!i)return;c||=t;let n=t-c;if(s.value&&n<s.value){l=i.requestAnimationFrame(u);return}if(c=t,e({delta:n,timestamp:t}),a){o.value=!1,l=null;return}l=i.requestAnimationFrame(u)}function d(){!o.value&&i&&(o.value=!0,c=0,l=i.requestAnimationFrame(u))}function f(){o.value=!1,l!=null&&i&&(i.cancelAnimationFrame(l),l=null)}return n&&d(),Fl(f),{isActive:Ee(o),pause:f,resume:d}}var Yu=Symbol(`vueuse-ssr-width`);function Xu(){let e=tt()?Ll(Yu,null):null;return typeof e==`number`?e:void 0}function Zu(e,t={}){let{window:n=Pu,ssrWidth:r=Xu()}=t,i=Bu(()=>n&&`matchMedia`in n&&typeof n.matchMedia==`function`),a=H(typeof r==`number`),s=H(),c=H(!1);return o(()=>{if(a.value){a.value=!i.value,c.value=B(e).split(`,`).some(e=>{let t=e.includes(`not all`),n=e.match(/\(\s*min-width:\s*(-?\d+(?:\.\d*)?[a-z]+\s*)\)/),i=e.match(/\(\s*max-width:\s*(-?\d+(?:\.\d*)?[a-z]+\s*)\)/),a=!!(n||i);return n&&a&&(a=r>=Zl(n[1])),i&&a&&(a=r<=Zl(i[1])),t?!a:a});return}i.value&&(s.value=n.matchMedia(B(e)),c.value=s.value.matches)}),Iu(s,`change`,e=>{c.value=e.matches},{passive:!0}),W(()=>c.value)}var Qu=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{},$u=`__vueuse_ssr_handlers__`,ed=td();function td(){return $u in Qu||(Qu[$u]=Qu[$u]||{}),Qu[$u]}function nd(e,t){return ed[e]||t}function rd(e){return e==null?`any`:e instanceof Set?`set`:e instanceof Map?`map`:e instanceof Date?`date`:typeof e==`boolean`?`boolean`:typeof e==`string`?`string`:typeof e==`object`?`object`:Number.isNaN(e)?`any`:`number`}var id={boolean:{read:e=>e===`true`,write:e=>String(e)},object:{read:e=>JSON.parse(e),write:e=>JSON.stringify(e)},number:{read:e=>Number.parseFloat(e),write:e=>String(e)},any:{read:e=>e,write:e=>String(e)},string:{read:e=>e,write:e=>String(e)},map:{read:e=>new Map(JSON.parse(e)),write:e=>JSON.stringify(Array.from(e.entries()))},set:{read:e=>new Set(JSON.parse(e)),write:e=>JSON.stringify(Array.from(e))},date:{read:e=>new Date(e),write:e=>e.toISOString()}},ad=`vueuse-storage`;function od(e,t,n,r={}){let{flush:i=`pre`,deep:a=!0,listenToStorageChanges:o=!0,writeDefaults:c=!0,mergeDefaults:l=!1,shallow:u,window:d=Pu,eventFilter:f,onError:p=e=>{console.error(e)},initOnMounted:m}=r,h=(u?H:K)(typeof t==`function`?t():t),g=W(()=>B(e));if(!n)try{n=nd(`getDefaultStorage`,()=>Pu?.localStorage)()}catch(e){p(e)}if(!n)return h;let _=B(t),v=rd(_),y=r.serializer??id[v],{pause:b,resume:x}=pu(h,e=>w(e),{flush:i,deep:a,eventFilter:f});A(g,()=>E(),{flush:i});let S=!1;d&&o&&(n instanceof Storage?Iu(d,`storage`,e=>{m&&!S||E(e)},{passive:!0}):Iu(d,ad,e=>{m&&!S||D(e)})),m?hu(()=>{S=!0,E()}):E();function C(e,t){if(d){let r={key:g.value,oldValue:e,newValue:t,storageArea:n};d.dispatchEvent(n instanceof Storage?new StorageEvent(`storage`,r):new CustomEvent(ad,{detail:r}))}}function w(e){try{let t=n.getItem(g.value);if(e==null)C(t,null),n.removeItem(g.value);else{let r=y.write(e);t!==r&&(n.setItem(g.value,r),C(t,r))}}catch(e){p(e)}}function T(e){let t=e?e.newValue:n.getItem(g.value);if(t==null)return c&&_!=null&&n.setItem(g.value,y.write(_)),_;if(!e&&l){let e=y.read(t);return typeof l==`function`?l(e,_):v===`object`&&!Array.isArray(e)?{..._,...e}:e}else if(typeof t!=`string`)return t;else return y.read(t)}function E(e){if(!(e&&e.storageArea!==n)){if(e&&e.key==null){h.value=_;return}if(!(e&&e.key!==g.value)){b();try{let t=y.write(h.value);(e===void 0||e?.newValue!==t)&&(h.value=T(e))}catch(e){p(e)}finally{e?s(x):x()}}}}function D(e){E(e.detail)}return h}var sd={speed:2,margin:30,direction:`both`};function cd(e){e.scrollLeft>e.scrollWidth-e.clientWidth&&(e.scrollLeft=Math.max(0,e.scrollWidth-e.clientWidth)),e.scrollTop>e.scrollHeight-e.clientHeight&&(e.scrollTop=Math.max(0,e.scrollHeight-e.clientHeight))}function ld(e,t={}){let{pointerTypes:n,preventDefault:r,stopPropagation:i,exact:a,onMove:o,onEnd:s,onStart:c,initialValue:l,axis:u=`both`,draggingElement:d=Pu,containerElement:f,handle:p=e,buttons:m=[0],restrictInView:h,autoScroll:g=!1}=t,_=K(B(l)??{x:0,y:0}),v=K(),y=e=>!n||n.includes(e.pointerType),b=e=>{B(r)&&e.preventDefault(),B(i)&&e.stopPropagation()},x=B(g),S=typeof x==`object`?{speed:B(x.speed)??sd.speed,margin:B(x.margin)??sd.margin,direction:x.direction??sd.direction}:sd,C=e=>typeof e==`number`?[e,e]:[e.x,e.y],w=(e,t,n)=>{let{clientWidth:r,clientHeight:i,scrollLeft:a,scrollTop:o,scrollWidth:s,scrollHeight:c}=e,[l,u]=C(S.margin),[d,f]=C(S.speed),p=0,m=0;(S.direction===`x`||S.direction===`both`)&&(n.x<l&&a>0?p=-d:n.x+t.width>r-l&&a<s-r&&(p=d)),(S.direction===`y`||S.direction===`both`)&&(n.y<u&&o>0?m=-f:n.y+t.height>i-u&&o<c-i&&(m=f)),(p||m)&&e.scrollBy({left:p,top:m,behavior:`auto`})},T=null,E=()=>{let t=B(f);t&&!T&&(T=setInterval(()=>{let n=B(e).getBoundingClientRect(),{x:r,y:i}=_.value,a={x:r-t.scrollLeft,y:i-t.scrollTop};a.x>=0&&a.y>=0&&(w(t,n,a),a.x+=t.scrollLeft,a.y+=t.scrollTop,_.value=a)},1e3/60))},D=()=>{T&&=(clearInterval(T),null)},O=(e,t,n,r)=>{let[i,a]=typeof n==`number`?[n,n]:[n.x,n.y],{clientWidth:o,clientHeight:s}=t;return e.x<i||e.x+r.width>o-i||e.y<a||e.y+r.height>s-a};B(g)&&A(_,()=>{if(B(t.disabled)||!v.value)return;let n=B(f);if(!n)return;let r=B(e).getBoundingClientRect(),{x:i,y:a}=_.value;O({x:i-n.scrollLeft,y:a-n.scrollTop},n,S.margin,r)?E():D()});let k=n=>{var r;if(!B(m).includes(n.button)||B(t.disabled)||!y(n)||B(a)&&n.target!==B(e))return;let i=B(f),o=i==null||(r=i.getBoundingClientRect)==null?void 0:r.call(i),s=B(e).getBoundingClientRect(),l={x:n.clientX-(i?s.left-o.left+(g?0:i.scrollLeft):s.left),y:n.clientY-(i?s.top-o.top+(g?0:i.scrollTop):s.top)};c?.(l,n)!==!1&&(v.value=l,b(n))},j=n=>{if(B(t.disabled)||!y(n)||!v.value)return;let r=B(f);r instanceof HTMLElement&&cd(r);let i=B(e).getBoundingClientRect(),{x:a,y:s}=_.value;if((u===`x`||u===`both`)&&(a=n.clientX-v.value.x,r&&(a=Math.min(Math.max(0,a),r.scrollWidth-i.width))),(u===`y`||u===`both`)&&(s=n.clientY-v.value.y,r&&(s=Math.min(Math.max(0,s),r.scrollHeight-i.height))),B(g)&&r&&(T===null&&w(r,i,{x:a,y:s}),a+=r.scrollLeft,s+=r.scrollTop),r&&(h||g)){if(u!==`y`){let e=a-r.scrollLeft;e<0?a=r.scrollLeft:e>r.clientWidth-i.width&&(a=r.clientWidth-i.width+r.scrollLeft)}if(u!==`x`){let e=s-r.scrollTop;e<0?s=r.scrollTop:e>r.clientHeight-i.height&&(s=r.clientHeight-i.height+r.scrollTop)}}_.value={x:a,y:s},o?.(_.value,n),b(n)},M=e=>{B(t.disabled)||!y(e)||v.value&&(v.value=void 0,g&&D(),s?.(_.value,e),b(e))};if(Rl){let e=()=>({capture:t.capture??!0,passive:!B(r)});Iu(p,`pointerdown`,k,e),Iu(d,`pointermove`,j,e),Iu(d,`pointerup`,M,e)}return{...mu(_),position:_,isDragging:W(()=>!!v.value),style:W(()=>`
|
|
12
|
+
`}},vo=class{nc;callbacks;msgs;size;subject;asyncRequests;pub;sub;req;rep;perf;payload;constructor(e,t={msgs:1e5,size:128,subject:``,asyncRequests:!1,pub:!1,sub:!1,req:!1,rep:!1}){if(this.nc=e,this.callbacks=t.callbacks||!1,this.msgs=t.msgs||0,this.size=t.size||0,this.subject=t.subject||Lr.nuid.next(),this.asyncRequests=t.asyncRequests||!1,this.pub=t.pub||!1,this.sub=t.sub||!1,this.req=t.req||!1,this.rep=t.rep||!1,this.perf=new kr,this.payload=this.size?new Uint8Array(this.size):Zn,!this.pub&&!this.sub&&!this.req&&!this.rep)throw Error(`no options selected`)}async run(){return this.nc.closed().then(e=>{if(e)throw e}),this.callbacks?await this.runCallbacks():await this.runAsync(),this.processMetrics()}processMetrics(){let{lang:e,version:t}=this.nc.protocol.transport;this.pub&&this.sub&&this.perf.measure(`pubsub`,`pubStart`,`subStop`),this.req&&this.rep&&this.perf.measure(`reqrep`,`reqStart`,`reqStop`);let n=this.perf.getEntries(),r=n.find(e=>e.name===`pubsub`),i=n.find(e=>e.name===`reqrep`),a=n.find(e=>e.name===`req`),o=n.find(e=>e.name===`rep`),s=n.find(e=>e.name===`pub`),c=n.find(e=>e.name===`sub`),l=this.nc.stats(),u=[];if(r){let{name:n,duration:i}=r,a=new _o(n,i);a.msgs=this.msgs*2,a.bytes=l.inBytes+l.outBytes,a.lang=e,a.version=t,a.payload=this.payload.length,u.push(a)}if(i){let{name:n,duration:r}=i,a=new _o(n,r);a.msgs=this.msgs*2,a.bytes=l.inBytes+l.outBytes,a.lang=e,a.version=t,a.payload=this.payload.length,u.push(a)}if(s){let{name:n,duration:r}=s,i=new _o(n,r);i.msgs=this.msgs,i.bytes=l.outBytes,i.lang=e,i.version=t,i.payload=this.payload.length,u.push(i)}if(c){let{name:n,duration:r}=c,i=new _o(n,r);i.msgs=this.msgs,i.bytes=l.inBytes,i.lang=e,i.version=t,i.payload=this.payload.length,u.push(i)}if(o){let{name:n,duration:r}=o,i=new _o(n,r);i.msgs=this.msgs,i.bytes=l.inBytes+l.outBytes,i.lang=e,i.version=t,i.payload=this.payload.length,u.push(i)}if(a){let{name:n,duration:r}=a,i=new _o(n,r);i.msgs=this.msgs,i.bytes=l.inBytes+l.outBytes,i.lang=e,i.version=t,i.payload=this.payload.length,u.push(i)}return u}async runCallbacks(){let e=[];if(this.sub){let t=xr();e.push(t);let n=0;this.nc.subscribe(this.subject,{max:this.msgs,callback:()=>{n++,n===1&&this.perf.mark(`subStart`),n===this.msgs&&(this.perf.mark(`subStop`),this.perf.measure(`sub`,`subStart`,`subStop`),t.resolve())}})}if(this.rep){let t=xr();e.push(t);let n=0;this.nc.subscribe(this.subject,{max:this.msgs,callback:(e,r)=>{r.respond(this.payload),n++,n===1&&this.perf.mark(`repStart`),n===this.msgs&&(this.perf.mark(`repStop`),this.perf.measure(`rep`,`repStart`,`repStop`),t.resolve())}})}if(this.pub){let t=(async()=>{this.perf.mark(`pubStart`);for(let e=0;e<this.msgs;e++)this.nc.publish(this.subject,this.payload);await this.nc.flush(),this.perf.mark(`pubStop`),this.perf.measure(`pub`,`pubStart`,`pubStop`)})();e.push(t)}if(this.req){let t=(async()=>{if(this.asyncRequests){this.perf.mark(`reqStart`);let e=[];for(let t=0;t<this.msgs;t++)e.push(this.nc.request(this.subject,this.payload,{timeout:2e4}));await Promise.all(e),this.perf.mark(`reqStop`),this.perf.measure(`req`,`reqStart`,`reqStop`)}else{this.perf.mark(`reqStart`);for(let e=0;e<this.msgs;e++)await this.nc.request(this.subject);this.perf.mark(`reqStop`),this.perf.measure(`req`,`reqStart`,`reqStop`)}})();e.push(t)}await Promise.all(e)}async runAsync(){let e=[];if(this.rep){let t=!1,n=this.nc.subscribe(this.subject,{max:this.msgs}),r=(async()=>{for await(let e of n)t||=(this.perf.mark(`repStart`),!0),e.respond(this.payload);await this.nc.flush(),this.perf.mark(`repStop`),this.perf.measure(`rep`,`repStart`,`repStop`)})();e.push(r)}if(this.sub){let t=!1,n=this.nc.subscribe(this.subject,{max:this.msgs}),r=(async()=>{for await(let e of n)t||=(this.perf.mark(`subStart`),!0);this.perf.mark(`subStop`),this.perf.measure(`sub`,`subStart`,`subStop`)})();e.push(r)}if(this.pub){let t=(async()=>{this.perf.mark(`pubStart`);for(let e=0;e<this.msgs;e++)this.nc.publish(this.subject,this.payload);await this.nc.flush(),this.perf.mark(`pubStop`),this.perf.measure(`pub`,`pubStart`,`pubStop`)})();e.push(t)}if(this.req){let t=(async()=>{if(this.asyncRequests){this.perf.mark(`reqStart`);let e=[];for(let t=0;t<this.msgs;t++)e.push(this.nc.request(this.subject,this.payload,{timeout:2e4}));await Promise.all(e),this.perf.mark(`reqStop`),this.perf.measure(`req`,`reqStart`,`reqStop`)}else{this.perf.mark(`reqStart`);for(let e=0;e<this.msgs;e++)await this.nc.request(this.subject);this.perf.mark(`reqStop`),this.perf.measure(`req`,`reqStart`,`reqStop`)}})();e.push(t)}await Promise.all(e)}}})),bo,xo=n((()=>{bo=class{interval;maxOut;cancelAfter;timer;autoCancelTimer;last;missed;count;callback;constructor(e,t,n={maxOut:2}){this.interval=e,this.maxOut=n?.maxOut||2,this.cancelAfter=n?.cancelAfter||0,this.last=Date.now(),this.missed=0,this.count=0,this.callback=t,this._schedule()}cancel(){this.autoCancelTimer&&clearTimeout(this.autoCancelTimer),this.timer&&clearInterval(this.timer),this.timer=0,this.autoCancelTimer=0,this.missed=0}work(){this.last=Date.now(),this.missed=0}_change(e,t=0,n=2){this.interval=e,this.maxOut=n,this.cancelAfter=t,this.restart()}restart(){this.cancel(),this._schedule()}_schedule(){this.cancelAfter>0&&(this.autoCancelTimer=setTimeout(()=>{this.cancel()},this.cancelAfter)),this.timer=setInterval(()=>{if(this.count++,Date.now()-this.last>this.interval&&this.missed++,this.missed>=this.maxOut)try{this.callback(this.missed)===!0&&this.cancel()}catch(e){console.log(e)}},this.interval)}}})),So,Co=n((()=>{So=`3.4.0`}));function wo(e,t){/^(.*:\/\/)(.*)/.test(e)||(e=typeof t==`boolean`?`${t===!0?`https`:`http`}://${e}`:`https://${e}`);let n=new URL(e),r=n.protocol.toLowerCase();r===`ws:`&&(t=!1),r===`wss:`&&(t=!0),r!==`https:`&&r!==`http`&&(e=e.replace(/^(.*:\/\/)(.*)/gm,`$2`),n=new URL(`http://${e}`));let i,a,o=n.hostname,s=n.pathname,c=n.search||``;switch(r){case`http:`:case`ws:`:case`nats:`:a=n.port||`80`,i=`ws:`;break;case`https:`:case`wss:`:case`tls:`:a=n.port||`443`,i=`wss:`;break;default:a=n.port||t===!0?`443`:`80`,i=t===!0?`wss:`:`ws:`;break}return`${i}//${o}:${a}${s}${c}`}function To(e={}){return qr({defaultPort:443,urlParseFn:wo,factory:()=>{if(e.tls)throw nr.format(`tls`,`is not configurable on w3c websocket connections`);return new Oo}}),lo.connect(e)}var Eo,Do,Oo,ko=n((()=>{Pr(),ii(),Ua(),Kr(),ro(),fo(),Co(),hr(),Eo=So,Do=`nats.ws`,Oo=class{version;lang;closeError;connected;done;socket;options;socketClosed;encrypted;peeked;yields;signal;closedNotification;pendingConnect;constructor(){this.version=Eo,this.lang=Do,this.connected=!1,this.done=!1,this.socketClosed=!1,this.encrypted=!1,this.peeked=!1,this.yields=[],this.signal=xr(),this.closedNotification=xr(),this.pendingConnect=null}async connect(e,t){let n=xr();this.pendingConnect=n,this.options=t;let r=e.src;if(t.wsFactory){let{socket:n,encrypted:r}=await t.wsFactory(e.src,t);this.socket=n,this.encrypted=r}else this.encrypted=r.indexOf(`wss://`)===0,this.socket=new WebSocket(r);return this.socket.binaryType=`arraybuffer`,this.socket.onopen=()=>{this.done&&this._closed(Error(`aborted`))},this.socket.onmessage=e=>{if(this.done)return;if(this.yields.push(new Uint8Array(e.data)),this.peeked){this.signal.resolve();return}let r=Gr.concat(...this.yields),i=$r(r);if(i!==``){let e=qa.exec(i);if(!e){t.debug&&console.error(`!!!`,_r(r)),n.reject(Error(`unexpected response from server`));return}try{Ra(JSON.parse(e[1]),this.options),this.peeked=!0,this.connected=!0,this.signal.resolve(),n.resolve()}catch(e){n.reject(e);return}}},this.socket.onclose=e=>{let t;e.code>=4e3&&e.code<=4999?t=Error(e.reason||`close code ${e.code}`):!e.wasClean&&e.reason!==``&&(t=Error(e.reason)),this._closed(t),this._cleanup()},this.socket.onerror=e=>{if(this.done)return;let t=e,r=new mr.ConnectionError(t.message);n.reject(r),this._cleanup()},n}_cleanup(){this.socketClosed===!1&&(this.socketClosed=!0,this.socket.onopen=null,this.socket.onmessage=null,this.socket.onerror=null,this.socket.onclose=null,this.closedNotification.resolve(this.closeError))}disconnect(){this._closed(void 0,!0)}async _closed(e,t=!0){if(this.pendingConnect?.reject(e??new mr.ConnectionError(`transport closed during handshake`)),this.done){try{this.socket.close()}catch{}return}if(this.closeError=e,!e){let e=Date.now();for(;!this.socketClosed&&this.socket.bufferedAmount>0&&!(Date.now()-e>=3e3);)await yr(100)}this.done=!0;try{this.socket.close()}catch{}return this._cleanup(),this.closedNotification}get isClosed(){return this.done}[Symbol.asyncIterator](){return this.iterate()}async*iterate(){for(;;){if(this.done)return;this.yields.length===0&&await this.signal;let e=this.yields;this.yields=[];for(let t=0;t<e.length;t++)this.options.debug&&console.info(`> ${_r(e[t])}`),yield e[t];if(this.done)break;this.yields.length===0&&(e.length=0,this.yields=e,this.signal=xr())}}isEncrypted(){return this.connected&&this.encrypted}send(e){if(!this.done)try{this.socket.send(e.buffer),this.options.debug&&console.info(`< ${_r(e)}`);return}catch(t){this.options.debug&&console.error(`!!! ${_r(e)}: ${t}`)}}close(e){return this._closed(e,!1)}closed(){return this.closedNotification}discard(){this.socket?.close()}}})),Ao=i({AuthorizationError:()=>ar,Bench:()=>vo,ClosedConnectionError:()=>or,Connect:()=>Qa,ConnectionError:()=>cr,DEFAULT_MAX_RECONNECT_ATTEMPTS:()=>10,DataBuffer:()=>Gr,DenoBuffer:()=>Hi,DrainingConnectionError:()=>sr,Empty:()=>Zn,Feature:()=>ca,Features:()=>la,Heartbeat:()=>Ni,INFO:()=>qa,IdleHeartbeatMonitor:()=>bo,InvalidArgumentError:()=>nr,InvalidOperationError:()=>rr,InvalidSubjectError:()=>tr,Kind:()=>Ki,MAX_SIZE:()=>Vi,Match:()=>Vr,Metric:()=>_o,MsgHdrsImpl:()=>na,MsgImpl:()=>ia,MuxSubscription:()=>ji,NatsConnectionImpl:()=>lo,NoRespondersError:()=>fr,Nuid:()=>Lr.Nuid,Parser:()=>Xi,PermissionViolationError:()=>pr,ProtocolError:()=>lr,ProtocolHandler:()=>no,QueuedIteratorImpl:()=>ki,RequestError:()=>ur,RequestOne:()=>oo,Servers:()=>Di,SimpleMutex:()=>Ar,State:()=>Y,SubscriptionImpl:()=>eo,Subscriptions:()=>to,TD:()=>$n,TE:()=>Qn,TimeoutError:()=>dr,UserAuthenticationExpiredError:()=>ir,backoff:()=>Tr,buildAuthenticator:()=>Ia,canonicalMIMEHeaderKey:()=>$i,checkOptions:()=>Ra,checkUnsupportedOption:()=>za,collect:()=>Cr,compare:()=>sa,createInbox:()=>Br,credsAuthenticator:()=>Ma,deadline:()=>br,defaultOptions:()=>Pa,deferred:()=>xr,delay:()=>yr,describe:()=>Wi,errors:()=>mr,extend:()=>gr,extractProtocolMessage:()=>$r,getResolveFn:()=>Zr,hasWsProtocol:()=>Fa,headers:()=>ea,ipV4:()=>ai,isIP:()=>oi,isIPV4OrHostname:()=>Si,jwtAuthenticator:()=>ja,millis:()=>Dr,nanos:()=>Er,nkeyAuthenticator:()=>Aa,nkeys:()=>wa,nuid:()=>Lr.nuid,parseIP:()=>si,parseOptions:()=>La,parseSemVer:()=>oa,protoLen:()=>Qr,readAll:()=>Li,render:()=>_r,setTransportFactory:()=>qr,syncIterator:()=>zr,timeout:()=>vr,tokenAuthenticator:()=>ka,usernamePasswordAuthenticator:()=>Oa,writeAll:()=>Ri,wsUrlParseFn:()=>wo,wsconnect:()=>To}),jo=n((()=>{fo(),Rr(),aa(),ii(),ro(),Pr(),ra(),Pi(),Mi(),Kr(),Ua(),so(),Na(),Ta(),Ai(),Qi(),Ui(),yo(),er(),xi(),ua(),po(),Wr(),xo(),Oi(),ko(),hr()})),Mo=class{client;channelId;closed=!1;unsubscribe;initialized=!1;subject;requestSubject;handlers=new Map;closeHandlers=new Set;errorHandlers=new Set;subscriptions=[];get isClosed(){return this.closed}get id(){return this.channelId}constructor(e,t){this.client=e,this.channelId=t,this.subject=`channel.${t}`,this.requestSubject=`channel.${t}.request`}async init(){this.initialized||(this.initialized=!0,this.unsubscribe=await this.client.subscribe(this.subject,async e=>{switch(e.type){case`message`:this.emit(`message`,e.data);break;case`close`:this.handleClose();break;case`error`:this.handleError(Error(e.error??`Channel error`));break}}))}async send(e){if(this.closed)throw Error(`Channel is closed`);let t={type:`message`,data:e};await this.client.publish(this.subject,t)}async request(e,t=5e3){if(this.closed)throw Error(`Channel is closed`);return this.client.request(this.requestSubject,e,{timeout:t})}async onRequest(e){let t=this.client.onRequest(this.requestSubject,e);return this.subscriptions.push(t),t}on(e,t){e===`close`?this.closeHandlers.add(t):e===`error`?this.errorHandlers.add(t):(this.handlers.has(e)||this.handlers.set(e,new Set),this.handlers.get(e).add(t))}off(e,t){e===`close`?this.closeHandlers.delete(t):e===`error`?this.errorHandlers.delete(t):this.handlers.get(e)?.delete(t)}async close(){if(!this.closed){this.closed=!0;try{await this.client.publish(this.subject,{type:`close`})}catch{}await this.cleanup()}}handlerChain=Promise.resolve();runHandler(e,t,n){this.handlerChain=this.handlerChain.then(()=>e(t)).catch(e=>console.error(`Error in ${n}:`,e))}emit(e,t){let n=this.handlers.get(e);if(n)for(let e of n)this.runHandler(e,t,`channel handler`)}handleClose(){if(!this.closed){this.closed=!0;for(let e of this.closeHandlers)this.runHandler(()=>e(),void 0,`close handler`);this.cleanup().catch(console.error)}}handleError(e){for(let t of this.errorHandlers)this.runHandler(t,e,`error handler`)}async cleanup(){if(this.handlers.clear(),this.closeHandlers.clear(),this.errorHandlers.clear(),await Promise.allSettled(this.subscriptions.map(async e=>(await e)())),this.subscriptions=[],this.unsubscribe){try{this.unsubscribe()}catch{}this.unsubscribe=void 0}let e=this._isolatedClient;if(e)try{await e.disconnect()}catch{}}},No=class extends Mo{targetClientId;clientId;remoteClientId;privateSubject;privateRequestSubject;get remoteId(){return this.remoteClientId}constructor(e,t,n){super(e,t),this.targetClientId=n;let r=e.options.name??`client-${Date.now()}`;this.clientId=r.replace(/-(channel|private)-.*$/,``);let i=[this.clientId,this.targetClientId].sort();this.privateSubject=`channel.private.${t}.${i.join(`.`)}`,this.privateRequestSubject=`${this.privateSubject}.request`}async init(){if(!this.initialized){this.initialized=!0,this.unsubscribe=await this.client.subscribe(this.privateSubject,async e=>{if(e.sender!==this.clientId&&e.sender===this.targetClientId&&(!this.remoteClientId&&e.sender&&(this.remoteClientId=e.sender),!(this.remoteClientId&&e.sender!==this.remoteClientId)))switch(e.type){case`message`:if(e.data&&typeof e.data==`object`&&`__handshake`in e.data)return;this.emit(`message`,e.data);break;case`close`:this.handleClose();break;case`error`:this.handleError(Error(e.error??`Channel error`));break}});try{await this.sendRaw({type:`message`,data:{__handshake:!0},sender:this.clientId})}catch{}}}async send(e){if(this.closed)throw Error(`Channel is closed`);await this.sendRaw({type:`message`,data:e,sender:this.clientId})}async request(e,t=5e3){if(this.closed)throw Error(`Channel is closed`);return this.client.request(this.privateRequestSubject,e,{timeout:t})}async onRequest(e){return this.client.onRequest(this.privateRequestSubject,e)}async close(){if(!this.closed){this.closed=!0;try{await this.sendRaw({type:`close`,sender:this.clientId})}catch{}await this.cleanup()}}isConnectedTo(e){return this.remoteClientId===e}async sendRaw(e){await this.client.publish(this.privateSubject,e)}},Po;try{Po=new TextDecoder}catch{}var X,Fo,Z=0,Io=[],Lo=Io,Ro=0,zo={},Bo,Vo,Ho=0,Uo=0,Wo,Go,Ko=[],qo,Jo={useRecords:!1,mapsAsObjects:!0},Yo=class{},Xo=new Yo;Xo.name=`MessagePack 0xC1`;var Zo=!1,Qo=2,$o=class e{constructor(e){e&&(e.useRecords===!1&&e.mapsAsObjects===void 0&&(e.mapsAsObjects=!0),e.sequential&&e.trusted!==!1&&(e.trusted=!0,!e.structures&&e.useRecords!=0&&(e.structures=[],e.maxSharedStructures||=0)),e.structures?e.structures.sharedLength=e.structures.length:e.getStructures&&((e.structures=[]).uninitialized=!0,e.structures.sharedLength=0),e.int64AsNumber&&(e.int64AsType=`number`)),Object.assign(this,e)}unpack(t,n){if(X)return Os(()=>(ks(),this?this.unpack(t,n):e.prototype.unpack.call(Jo,t,n)));!t.buffer&&t.constructor===ArrayBuffer&&(t=typeof Buffer<`u`?Buffer.from(t):new Uint8Array(t)),typeof n==`object`?(Fo=n.end||t.length,Z=n.start||0):(Z=0,Fo=n>-1?n:t.length),Ro=0,Uo=0,Vo=null,Lo=Io,Wo=null,X=t;try{qo=t.dataView||=new DataView(t.buffer,t.byteOffset,t.byteLength)}catch(e){throw X=null,t instanceof Uint8Array?e:Error(`Source must be a Uint8Array or Buffer but was a `+(t&&typeof t==`object`?t.constructor.name:typeof t))}if(this instanceof e){if(zo=this,this.structures)return Bo=this.structures,es(n);(!Bo||Bo.length>0)&&(Bo=[])}else zo=Jo,(!Bo||Bo.length>0)&&(Bo=[]);return es(n)}unpackMultiple(e,t){let n,r=0;try{Zo=!0;let i=e.length,a=this?this.unpack(e,i):js.unpack(e,i);if(t){if(t(a,r,Z)===!1)return;for(;Z<i;)if(r=Z,t(es(),r,Z)===!1)return}else{for(n=[a];Z<i;)r=Z,n.push(es());return n}}catch(e){throw e.lastPosition=r,e.values=n,e}finally{Zo=!1,ks()}}_mergeStructures(e,t){this._onLoadedStructures&&(e=this._onLoadedStructures(e)),e||=[],Object.isFrozen(e)&&(e=e.map(e=>e.slice(0)));for(let t=0,n=e.length;t<n;t++){let n=e[t];n&&(n.isShared=!0,t>=32&&(n.highByte=t-32>>5))}e.sharedLength=e.length;for(let n in t||[])if(n>=0){let r=e[n],i=t[n];i&&(r&&((e.restoreStructures||=[])[n]=r),e[n]=i)}return this.structures=e}decode(e,t){return this.unpack(e,t)}};function es(e){try{if(!zo.trusted&&!Zo){let e=Bo.sharedLength||0;e<Bo.length&&(Bo.length=e)}let t;if(zo._readStruct&&X[Z]<64&&X[Z]>=32?(t=zo._readStruct(X,Z,Fo),X=null,!(e&&e.lazy)&&t&&(t=t.toJSON()),Z=Fo):t=ns(),Wo&&=(Z=Wo.postBundlePosition,null),Zo&&(Bo.restoreStructures=null),Z==Fo)Bo&&Bo.restoreStructures&&ts(),Bo=null,X=null,Go&&=null;else if(Z>Fo)throw Error(`Unexpected end of MessagePack data`);else if(!Zo){let e;try{e=JSON.stringify(t,(e,t)=>typeof t==`bigint`?`${t}n`:t).slice(0,100)}catch(t){e=`(JSON view not available `+t+`)`}throw Error(`Data read, but end of buffer not reached `+e)}return t}catch(e){throw Bo&&Bo.restoreStructures&&ts(),ks(),(e instanceof RangeError||e.message.startsWith(`Unexpected end of buffer`)||Z>Fo)&&(e.incomplete=!0),e}}function ts(){for(let e in Bo.restoreStructures)Bo[e]=Bo.restoreStructures[e];Bo.restoreStructures=null}function ns(){let e=X[Z++];if(e<160)if(e<128){if(e<64)return e;{let t=Bo[e&63]||zo.getStructures&&os()[e&63];return t?(t.read||=is(t,e&63),t.read()):e}}else if(e<144)if(e-=128,zo.mapsAsObjects){let t={};for(let n=0;n<e;n++){let e=xs();e===`__proto__`&&(e=`__proto_`),t[e]=ns()}return t}else{let t=new Map;for(let n=0;n<e;n++)t.set(ns(),ns());return t}else{e-=144;let t=Array(e);for(let n=0;n<e;n++)t[n]=ns();return zo.freezeData?Object.freeze(t):t}else if(e<192){let t=e-160;if(Uo>=Z)return Vo.slice(Z-Ho,(Z+=t)-Ho);if(Uo==0&&Fo<140){let e=t<16?gs(t):hs(t);if(e!=null)return e}return ss(t)}else{let t;switch(e){case 192:return null;case 193:return Wo?(t=ns(),t>0?Wo[1].slice(Wo.position1,Wo.position1+=t):Wo[0].slice(Wo.position0,Wo.position0-=t)):Xo;case 194:return!1;case 195:return!0;case 196:if(t=X[Z++],t===void 0)throw Error(`Unexpected end of buffer`);return vs(t);case 197:return t=qo.getUint16(Z),Z+=2,vs(t);case 198:return t=qo.getUint32(Z),Z+=4,vs(t);case 199:return ys(X[Z++]);case 200:return t=qo.getUint16(Z),Z+=2,ys(t);case 201:return t=qo.getUint32(Z),Z+=4,ys(t);case 202:if(t=qo.getFloat32(Z),zo.useFloat32>2){let e=As[(X[Z]&127)<<1|X[Z+1]>>7];return Z+=4,(e*t+(t>0?.5:-.5)>>0)/e}return Z+=4,t;case 203:return t=qo.getFloat64(Z),Z+=8,t;case 204:return X[Z++];case 205:return t=qo.getUint16(Z),Z+=2,t;case 206:return t=qo.getUint32(Z),Z+=4,t;case 207:return zo.int64AsType===`number`?(t=qo.getUint32(Z)*4294967296,t+=qo.getUint32(Z+4)):zo.int64AsType===`string`?t=qo.getBigUint64(Z).toString():zo.int64AsType===`auto`?(t=qo.getBigUint64(Z),t<=BigInt(2)<<BigInt(52)&&(t=Number(t))):t=qo.getBigUint64(Z),Z+=8,t;case 208:return qo.getInt8(Z++);case 209:return t=qo.getInt16(Z),Z+=2,t;case 210:return t=qo.getInt32(Z),Z+=4,t;case 211:return zo.int64AsType===`number`?(t=qo.getInt32(Z)*4294967296,t+=qo.getUint32(Z+4)):zo.int64AsType===`string`?t=qo.getBigInt64(Z).toString():zo.int64AsType===`auto`?(t=qo.getBigInt64(Z),t>=BigInt(-2)<<BigInt(52)&&t<=BigInt(2)<<BigInt(52)&&(t=Number(t))):t=qo.getBigInt64(Z),Z+=8,t;case 212:if(t=X[Z++],t==114)return Cs(X[Z++]&63);{let e=Ko[t];if(e)return e.read?(Z++,e.read(ns())):e.noBuffer?(Z++,e()):e(X.subarray(Z,++Z));throw Error(`Unknown extension `+t)}case 213:return t=X[Z],t==114?(Z++,Cs(X[Z++]&63,X[Z++])):ys(2);case 214:return ys(4);case 215:return ys(8);case 216:return ys(16);case 217:return t=X[Z++],Uo>=Z?Vo.slice(Z-Ho,(Z+=t)-Ho):cs(t);case 218:return t=qo.getUint16(Z),Z+=2,Uo>=Z?Vo.slice(Z-Ho,(Z+=t)-Ho):ls(t);case 219:return t=qo.getUint32(Z),Z+=4,Uo>=Z?Vo.slice(Z-Ho,(Z+=t)-Ho):us(t);case 220:return t=qo.getUint16(Z),Z+=2,fs(t);case 221:return t=qo.getUint32(Z),Z+=4,fs(t);case 222:return t=qo.getUint16(Z),Z+=2,ps(t);case 223:return t=qo.getUint32(Z),Z+=4,ps(t);default:if(e>=224)return e-256;if(e===void 0){let e=Error(`Unexpected end of MessagePack data`);throw e.incomplete=!0,e}throw Error(`Unknown MessagePack token `+e)}}}var rs=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function is(e,t){function n(){if(n.count++>Qo){let r;try{r=e.read=Function(`r`,`return function(){return `+(zo.freezeData?`Object.freeze`:``)+`({`+e.map(e=>e===`__proto__`?`__proto_:r()`:rs.test(e)?e+`:r()`:`[`+JSON.stringify(e)+`]:r()`).join(`,`)+`})}`)(ns)}catch{return Qo=1/0,n()}return e.read0=r,e.highByte===0&&(e.read=as(t,e.read)),r()}let r={};for(let t=0,n=e.length;t<n;t++){let n=e[t];n===`__proto__`&&(n=`__proto_`),r[n]=ns()}return zo.freezeData?Object.freeze(r):r}return n.count=0,e.read0=n,e.highByte===0?as(t,n):n}var as=(e,t)=>function(){let n=X[Z++];if(n===0)return t();let r=e<32?-(e+(n<<5)):e+(n<<5),i=Bo[r]||os()[r];if(!i)throw Error(`Record id is not defined for `+r);return i.read||=is(i,e),i.read()};function os(){let e=Os(()=>(X=null,zo.getStructures()));return Bo=zo._mergeStructures(e,Bo)}var ss=ds,cs=ds,ls=ds,us=ds;function ds(e){let t;if(e<16&&(t=gs(e)))return t;if(e>64&&Po)return Po.decode(X.subarray(Z,Z+=e));let n=Z+e,r=[];for(t=``;Z<n;){let e=X[Z++];if(!(e&128))r.push(e);else if((e&224)==192){let t=X[Z++]&63,n=(e&31)<<6|t;n<128?r.push(65533):r.push(n)}else if((e&240)==224){let t=X[Z++]&63,n=X[Z++]&63,i=(e&31)<<12|t<<6|n;i<2048||i>=55296&&i<=57343?r.push(65533):r.push(i)}else if((e&248)==240){let t=X[Z++]&63,n=X[Z++]&63,i=X[Z++]&63,a=(e&7)<<18|t<<12|n<<6|i;a<65536||a>1114111?r.push(65533):a>65535?(a-=65536,r.push(a>>>10&1023|55296),a=56320|a&1023,r.push(a)):r.push(a)}else r.push(65533);r.length>=4096&&(t+=ms.apply(String,r),r.length=0)}return r.length>0&&(t+=ms.apply(String,r)),t}function fs(e){let t=Array(e);for(let n=0;n<e;n++)t[n]=ns();return zo.freezeData?Object.freeze(t):t}function ps(e){if(zo.mapsAsObjects){let t={};for(let n=0;n<e;n++){let e=xs();e===`__proto__`&&(e=`__proto_`),t[e]=ns()}return t}else{let t=new Map;for(let n=0;n<e;n++)t.set(ns(),ns());return t}}var ms=String.fromCharCode;function hs(e){let t=Z,n=Array(e);for(let r=0;r<e;r++){let e=X[Z++];if((e&128)>0){Z=t;return}n[r]=e}return ms.apply(String,n)}function gs(e){if(e<4)if(e<2){if(e===0)return``;{let e=X[Z++];if((e&128)>1){--Z;return}return ms(e)}}else{let t=X[Z++],n=X[Z++];if((t&128)>0||(n&128)>0){Z-=2;return}if(e<3)return ms(t,n);let r=X[Z++];if((r&128)>0){Z-=3;return}return ms(t,n,r)}else{let t=X[Z++],n=X[Z++],r=X[Z++],i=X[Z++];if((t&128)>0||(n&128)>0||(r&128)>0||(i&128)>0){Z-=4;return}if(e<6){if(e===4)return ms(t,n,r,i);{let e=X[Z++];if((e&128)>0){Z-=5;return}return ms(t,n,r,i,e)}}else if(e<8){let a=X[Z++],o=X[Z++];if((a&128)>0||(o&128)>0){Z-=6;return}if(e<7)return ms(t,n,r,i,a,o);let s=X[Z++];if((s&128)>0){Z-=7;return}return ms(t,n,r,i,a,o,s)}else{let a=X[Z++],o=X[Z++],s=X[Z++],c=X[Z++];if((a&128)>0||(o&128)>0||(s&128)>0||(c&128)>0){Z-=8;return}if(e<10){if(e===8)return ms(t,n,r,i,a,o,s,c);{let e=X[Z++];if((e&128)>0){Z-=9;return}return ms(t,n,r,i,a,o,s,c,e)}}else if(e<12){let l=X[Z++],u=X[Z++];if((l&128)>0||(u&128)>0){Z-=10;return}if(e<11)return ms(t,n,r,i,a,o,s,c,l,u);let d=X[Z++];if((d&128)>0){Z-=11;return}return ms(t,n,r,i,a,o,s,c,l,u,d)}else{let l=X[Z++],u=X[Z++],d=X[Z++],f=X[Z++];if((l&128)>0||(u&128)>0||(d&128)>0||(f&128)>0){Z-=12;return}if(e<14){if(e===12)return ms(t,n,r,i,a,o,s,c,l,u,d,f);{let e=X[Z++];if((e&128)>0){Z-=13;return}return ms(t,n,r,i,a,o,s,c,l,u,d,f,e)}}else{let p=X[Z++],m=X[Z++];if((p&128)>0||(m&128)>0){Z-=14;return}if(e<15)return ms(t,n,r,i,a,o,s,c,l,u,d,f,p,m);let h=X[Z++];if((h&128)>0){Z-=15;return}return ms(t,n,r,i,a,o,s,c,l,u,d,f,p,m,h)}}}}}function _s(){let e=X[Z++],t;if(e<192)t=e-160;else switch(e){case 217:t=X[Z++];break;case 218:t=qo.getUint16(Z),Z+=2;break;case 219:t=qo.getUint32(Z),Z+=4;break;default:throw Error(`Expected string`)}return ds(t)}function vs(e){return zo.copyBuffers?Uint8Array.prototype.slice.call(X,Z,Z+=e):X.subarray(Z,Z+=e)}function ys(e){let t=X[Z++];if(Ko[t]){let n;return Ko[t](X.subarray(Z,n=Z+=e),e=>{Z=e;try{return ns()}finally{Z=n}})}else throw Error(`Unknown extension type `+t)}var bs=Array(4096);function xs(){let e=X[Z++];if(e>=160&&e<192){if(e-=160,Uo>=Z)return Vo.slice(Z-Ho,(Z+=e)-Ho);if(!(Uo==0&&Fo<180))return ss(e)}else return Z--,Ss(ns());let t=(e<<5^(e>1?qo.getUint16(Z):e>0?X[Z]:0))&4095,n=bs[t],r=Z,i=Z+e-3,a,o=0;if(n&&n.bytes==e){for(;r<i;){if(a=qo.getUint32(r),a!=n[o++]){r=1879048192;break}r+=4}for(i+=3;r<i;)if(a=X[r++],a!=n[o++]){r=1879048192;break}if(r===i)return Z=r,n.string;i-=3,r=Z}for(n=[],bs[t]=n,n.bytes=e;r<i;)a=qo.getUint32(r),n.push(a),r+=4;for(i+=3;r<i;)a=X[r++],n.push(a);let s=e<16?gs(e):hs(e);return s==null?n.string=ss(e):n.string=s}function Ss(e){if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`||typeof e==`bigint`)return e.toString();if(e==null)return e+``;if(zo.allowArraysInMapKeys&&Array.isArray(e)&&e.flat().every(e=>[`string`,`number`,`boolean`,`bigint`].includes(typeof e)))return e.flat().toString();throw Error(`Invalid property type for record: ${typeof e}`)}var Cs=(e,t)=>{let n=ns().map(Ss),r=e;t!==void 0&&(e=e<32?-((t<<5)+e):(t<<5)+e,n.highByte=t);let i=Bo[e];return i&&(i.isShared||Zo)&&((Bo.restoreStructures||=[])[e]=i),Bo[e]=n,n.read=is(n,r),(n.read0||n.read)()};Ko[0]=()=>{},Ko[0].noBuffer=!0,Ko[66]=e=>{let t=e.byteLength%8||8,n=BigInt(e[0]&128?e[0]-256:e[0]);for(let r=1;r<t;r++)n<<=BigInt(8),n+=BigInt(e[r]);if(e.byteLength!==t){let r=new DataView(e.buffer,e.byteOffset,e.byteLength),i=(e,t)=>{let n=t-e;if(n<=40){let n=r.getBigUint64(e);for(let i=e+8;i<t;i+=8)n<<=BigInt(64),n|=r.getBigUint64(i);return n}let a=e+(n>>4<<3),o=i(e,a),s=i(a,t);return o<<BigInt((t-a)*8)|s};n=n<<BigInt((r.byteLength-t)*8)|i(t,r.byteLength)}return n};var ws={Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError,AggregateError:typeof AggregateError==`function`?AggregateError:null};Ko[101]=()=>{let e=ns();if(!ws[e[0]]){let t=Error(e[1],{cause:e[2]});return t.name=e[0],t}return ws[e[0]](e[1],{cause:e[2]})},Ko[105]=e=>{if(zo.structuredClone===!1)throw Error(`Structured clone extension is disabled`);let t=qo.getUint32(Z-4);Go||=new Map;let n=X[Z],r;r=n>=144&&n<160||n==220||n==221?[]:n>=128&&n<144||n==222||n==223?new Map:(n>=199&&n<=201||n>=212&&n<=216)&&X[Z+1]===115?new Set:{};let i={target:r};Go.set(t,i);let a=ns();if(i.used)Object.assign(r,a);else return i.target=a;if(r instanceof Map)for(let[e,t]of a.entries())r.set(e,t);if(r instanceof Set)for(let e of Array.from(a))r.add(e);return r},Ko[112]=e=>{if(zo.structuredClone===!1)throw Error(`Structured clone extension is disabled`);let t=qo.getUint32(Z-4),n=Go.get(t);return n.used=!0,n.target},Ko[115]=()=>new Set(ns());var Ts=[`Int8`,`Uint8`,`Uint8Clamped`,`Int16`,`Uint16`,`Int32`,`Uint32`,`Float32`,`Float64`,`BigInt64`,`BigUint64`].map(e=>e+`Array`),Es=typeof globalThis==`object`?globalThis:window;Ko[116]=e=>{let t=e[0],n=Uint8Array.prototype.slice.call(e,1).buffer,r=Ts[t];if(!r){if(t===16)return n;if(t===17)return new DataView(n);throw Error(`Could not find typed array for code `+t)}return new Es[r](n)},Ko[120]=()=>{let e=ns();return new RegExp(e[0],e[1])};var Ds=[];Ko[98]=e=>{let t=(e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3],n=Z;return Z+=t-e.length,Wo=Ds,Wo=[_s(),_s()],Wo.position0=0,Wo.position1=0,Wo.postBundlePosition=Z,Z=n,ns()},Ko[255]=e=>e.length==4?new Date((e[0]*16777216+(e[1]<<16)+(e[2]<<8)+e[3])*1e3):e.length==8?new Date(((e[0]<<22)+(e[1]<<14)+(e[2]<<6)+(e[3]>>2))/1e6+((e[3]&3)*4294967296+e[4]*16777216+(e[5]<<16)+(e[6]<<8)+e[7])*1e3):e.length==12?new Date(((e[0]<<24)+(e[1]<<16)+(e[2]<<8)+e[3])/1e6+((e[4]&128?-281474976710656:0)+e[6]*1099511627776+e[7]*4294967296+e[8]*16777216+(e[9]<<16)+(e[10]<<8)+e[11])*1e3):new Date(`invalid`);function Os(e){zo&&zo._onSaveState&&zo._onSaveState();let t=Fo,n=Z,r=Ro,i=Ho,a=Uo,o=Vo,s=Lo,c=Go,l=Wo,u=new Uint8Array(X.slice(0,Fo)),d=Bo,f=Bo.slice(0,Bo.length),p=zo,m=Zo,h=e();return Fo=t,Z=n,Ro=r,Ho=i,Uo=a,Vo=o,Lo=s,Go=c,Wo=l,X=u,Zo=m,Bo=d,Bo.splice(0,Bo.length,...f),zo=p,qo=new DataView(X.buffer,X.byteOffset,X.byteLength),h}function ks(){X=null,Go=null,Bo=null}var As=Array(147);for(let e=0;e<256;e++)As[e]=+(`1e`+Math.floor(45.15-e*.30103));var js=new $o({useRecords:!1});js.unpack,js.unpackMultiple,js.unpack;var Ms={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4};new Uint8Array(new Float32Array(1).buffer,0,4),$o.SUPPORTS_STRUCT_HOOKS=!0;var Ns;try{Ns=new TextEncoder}catch{}var Ps,Fs,Is=typeof Buffer<`u`,Ls=Is?function(e){return Buffer.allocUnsafeSlow(e)}:Uint8Array,Rs=Is?Buffer:Uint8Array,zs=Is?4294967296:2144337920,Q,Bs,Vs,$=0,Hs,Us=null,Ws=21760,Gs=/[\u0080-\uFFFF]/,Ks=Symbol(`record-id`),qs=class extends $o{constructor(e){super(e),this.offset=0;let t,n,r,i,a=Rs.prototype.utf8Write?function(e,t){return Q.utf8Write(e,t,Q.byteLength-t)}:Ns&&Ns.encodeInto?function(e,t){return Ns.encodeInto(e,Q.subarray(t)).written}:!1,o=this;e||={};let s=e&&e.sequential,c=e.structures||e.saveStructures,l=e.maxSharedStructures;if(l??=c?32:0,l>8160)throw Error(`Maximum maxSharedStructure is 8160`);e.structuredClone&&e.moreTypes==null&&(this.moreTypes=!0);let u=e.maxOwnStructures;u??=c?32:64,!this.structures&&e.useRecords!=0&&(this.structures=[]);let d=l>32||u+l>64,f=l+64,p=l+u+64;if(p>8256)throw Error(`Maximum maxSharedStructure + maxOwnStructure is 8192`);let m=[],h=0,g=0;this.pack=this.encode=function(e,a){if(Q||(Q=new Ls(8192),Vs=Q.dataView||=new DataView(Q.buffer,0,8192),$=0),Hs=Q.length-10,Hs-$<2048?(Q=new Ls(Q.length),Vs=Q.dataView||=new DataView(Q.buffer,0,Q.length),Hs=Q.length-10,$=0):$=$+7&2147483640,t=$,a&2048&&($+=a&255),i=o.structuredClone?new Map:null,o.bundleStrings&&typeof e!=`string`?(Us=[],Us.size=1/0):Us=null,r=o.structures,r){r.uninitialized&&(r=o._mergeStructures(o.getStructures()));let e=r.sharedLength||0;if(e>l)throw Error(`Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to `+r.sharedLength);if(!r.transitions){r.transitions=Object.create(null);for(let t=0;t<e;t++){let e=r[t];if(!e)continue;let n,i=r.transitions;for(let t=0,r=e.length;t<r;t++){let r=e[t];n=i[r],n||=i[r]=Object.create(null),i=n}i[Ks]=t+64}this.lastNamedStructuresLength=e}s||(r.nextId=e+64)}n&&=!1;let c;try{o._writeStruct&&e&&typeof e==`object`?e.constructor===Object?w(e):e.constructor!==Map&&!Array.isArray(e)&&!Fs.some(t=>e instanceof t)?w(e.toJSON?e.toJSON():e):y(e):y(e);let n=Us;if(Us&&Qs(t,y,0),i&&i.idsToInsert){let e=i.idsToInsert.sort((e,t)=>e.offset>t.offset?1:-1),r=e.length,a=-1;for(;n&&r>0;){let i=e[--r].offset+t;i<n.stringsPosition+t&&a===-1&&(a=0),i>n.position+t?a>=0&&(a+=6):(a>=0&&(Vs.setUint32(n.position+t,Vs.getUint32(n.position+t)+a),a=-1),n=n.previous,r++)}a>=0&&n&&Vs.setUint32(n.position+t,Vs.getUint32(n.position+t)+a),$+=e.length*6,$>Hs&&T($),o.offset=$;let s=Zs(Q.subarray(t,$),e);return i=null,s}return o.offset=$,a&512?(Q.start=t,Q.end=$,Q):Q.subarray(t,$)}catch(e){throw c=e,e}finally{if(r&&(_(),n&&o.saveStructures)){let n=r.sharedLength||0,i=Q.subarray(t,$),s=(o._prepareStructures||$s)(r,o);if(!c)return o.saveStructures(s,s.isCompatible)===!1?(r.uninitialized=!0,o.pack(e,a)):(o.lastNamedStructuresLength=n,Q.length>1073741824&&(Q=null),i)}Q.length>1073741824&&(Q=null),a&1024&&($=t)}};let _=()=>{g<10&&g++;let e=r.sharedLength||0;if(r.length>e&&!s&&(r.length=e),h>1e4)r.transitions=null,g=0,h=0,m.length>0&&(m=[]);else if(m.length>0&&!s){for(let e=0,t=m.length;e<t;e++)m[e][Ks]=0;m=[]}},v=e=>{var t=e.length;t<16?Q[$++]=144|t:t<65536?(Q[$++]=220,Q[$++]=t>>8,Q[$++]=t&255):(Q[$++]=221,Vs.setUint32($,t),$+=4);for(let n=0;n<t;n++)y(e[n])},y=e=>{$>Hs&&(Q=T($));var n=typeof e,r;if(n===`string`){let n=e.length;if(Us&&n>=4&&n<4096){if((Us.size+=n)>Ws){let e,n=(Us[0]?Us[0].length*3+Us[1].length:0)+10;$+n>Hs&&(Q=T($+n));let r;Us.position?(r=Us,Q[$]=200,$+=3,Q[$++]=98,e=$-t,$+=4,Qs(t,y,0),Vs.setUint16(e+t-3,$-t-e)):(Q[$++]=214,Q[$++]=98,e=$-t,$+=4),Us=[``,``],Us.previous=r,Us.size=0,Us.position=e}let r=Gs.test(e);Us[+!r]+=e,Q[$++]=193,y(r?-n:n);return}let i;i=n<32?1:n<256?2:n<65536?3:5;let o=n*3;if($+o>Hs&&(Q=T($+o)),n<64||!a){let t,a,o,s=$+i;for(t=0;t<n;t++)a=e.charCodeAt(t),a<128?Q[s++]=a:a<2048?(Q[s++]=a>>6|192,Q[s++]=a&63|128):(a&64512)==55296&&((o=e.charCodeAt(t+1))&64512)==56320?(a=65536+((a&1023)<<10)+(o&1023),t++,Q[s++]=a>>18|240,Q[s++]=a>>12&63|128,Q[s++]=a>>6&63|128,Q[s++]=a&63|128):(Q[s++]=a>>12|224,Q[s++]=a>>6&63|128,Q[s++]=a&63|128);r=s-$-i}else r=a(e,$+i);r<32?Q[$++]=160|r:r<256?(i<2&&Q.copyWithin($+2,$+1,$+1+r),Q[$++]=217,Q[$++]=r):r<65536?(i<3&&Q.copyWithin($+3,$+2,$+2+r),Q[$++]=218,Q[$++]=r>>8,Q[$++]=r&255):(i<5&&Q.copyWithin($+5,$+3,$+3+r),Q[$++]=219,Vs.setUint32($,r),$+=4),$+=r}else if(n===`number`)if(e>>>0===e)e<32||e<128&&this.useRecords===!1||e<64&&!this._writeStruct?Q[$++]=e:e<256?(Q[$++]=204,Q[$++]=e):e<65536?(Q[$++]=205,Q[$++]=e>>8,Q[$++]=e&255):(Q[$++]=206,Vs.setUint32($,e),$+=4);else if(e>>0===e)e>=-32?Q[$++]=256+e:e>=-128?(Q[$++]=208,Q[$++]=e+256):e>=-32768?(Q[$++]=209,Vs.setInt16($,e),$+=2):(Q[$++]=210,Vs.setInt32($,e),$+=4);else{let t;if((t=this.useFloat32)>0&&e<4294967296&&e>=-2147483648){Q[$++]=202,Vs.setFloat32($,e);let n;if(t<4||(n=e*As[(Q[$]&127)<<1|Q[$+1]>>7])>>0===n){$+=4;return}else $--}Q[$++]=203,Vs.setFloat64($,e),$+=8}else if(n===`object`||n===`function`)if(!e)Q[$++]=192;else{if(i){let n=i.get(e);if(n){n.id||=(i.idsToInsert||=[]).push(n),Q[$++]=214,Q[$++]=112,Vs.setUint32($,n.id),$+=4;return}else i.set(e,{offset:$-t})}let a=e.constructor;if(a===Object)C(e);else if(a===Array)v(e);else if(a===Map)if(this.mapAsEmptyObject)Q[$++]=128;else{r=e.size,r<16?Q[$++]=128|r:r<65536?(Q[$++]=222,Q[$++]=r>>8,Q[$++]=r&255):(Q[$++]=223,Vs.setUint32($,r),$+=4);for(let[t,n]of e)y(t),y(n)}else{for(let t=0,n=Ps.length;t<n;t++){let n=Fs[t];if(e instanceof n){let n=Ps[t];if(n.write){n.type&&(Q[$++]=212,Q[$++]=n.type,Q[$++]=0);let t=n.write.call(this,e);t===e?Array.isArray(e)?v(e):C(e):y(t);return}let r=Q,i=Vs,a=$;Q=null;let o;try{o=n.pack.call(this,e,e=>(Q=r,r=null,$+=e,$>Hs&&T($),{target:Q,targetView:Vs,position:$-e}),y)}finally{r&&(Q=r,Vs=i,$=a,Hs=Q.length-10)}o&&(o.length+$>Hs&&T(o.length+$),$=Xs(o,Q,$,n.type));return}}if(Array.isArray(e))v(e);else{if(e.toJSON){let t=e.toJSON();if(t!==e)return y(t)}if(n===`function`)return y(this.writeFunction&&this.writeFunction(e));C(e)}}}else if(n===`boolean`)Q[$++]=e?195:194;else if(n===`bigint`){if(e<0x8000000000000000&&e>=-0x8000000000000000)Q[$++]=211,Vs.setBigInt64($,e);else if(e<0x10000000000000000&&e>0)Q[$++]=207,Vs.setBigUint64($,e);else if(this.largeBigIntToFloat)Q[$++]=203,Vs.setFloat64($,Number(e));else if(this.largeBigIntToString)return y(e.toString());else if(this.useBigIntExtension||this.moreTypes){let t=BigInt(e<0?-1:0),n;if(e>>BigInt(65536)===t){let r=BigInt(0x10000000000000000)-BigInt(1),i=[];for(;i.push(e&r),e>>BigInt(63)!==t;)e>>=BigInt(64);n=new Uint8Array(new BigUint64Array(i).buffer),n.reverse()}else{let t=e<0,r=(t?~e:e).toString(16);if(r.length%2?r=`0`+r:parseInt(r.charAt(0),16)>=8&&(r=`00`+r),Is)n=Buffer.from(r,`hex`);else{n=new Uint8Array(r.length/2);for(let e=0;e<n.length;e++)n[e]=parseInt(r.slice(e*2,e*2+2),16)}if(t)for(let e=0;e<n.length;e++)n[e]=~n[e]}n.length+$>Hs&&T(n.length+$),$=Xs(n,Q,$,66);return}else throw RangeError(e+` was too large to fit in MessagePack 64-bit integer format, use useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set largeBigIntToString to convert to string`);$+=8}else if(n===`undefined`)this.encodeUndefinedAsNil?Q[$++]=192:(Q[$++]=212,Q[$++]=0,Q[$++]=0);else throw Error(`Unknown type: `+n)},b=this.variableMapSize||this.coercibleKeyAsNumber||this.skipValues?e=>{let t;if(this.skipValues){t=[];for(let n in e)(typeof e.hasOwnProperty!=`function`||e.hasOwnProperty(n))&&!this.skipValues.includes(e[n])&&t.push(n)}else t=Object.keys(e);let n=t.length;n<16?Q[$++]=128|n:n<65536?(Q[$++]=222,Q[$++]=n>>8,Q[$++]=n&255):(Q[$++]=223,Vs.setUint32($,n),$+=4);let r;if(this.coercibleKeyAsNumber)for(let i=0;i<n;i++){r=t[i];let n=Number(r);y(isNaN(n)?r:n),y(e[r])}else for(let i=0;i<n;i++)y(r=t[i]),y(e[r])}:e=>{Q[$++]=222;let n=$-t;$+=2;let r=0;for(let t in e)(typeof e.hasOwnProperty!=`function`||e.hasOwnProperty(t))&&(y(t),y(e[t]),r++);if(r>65535)throw Error(`Object is too large to serialize with fast 16-bit map size, use the "variableMapSize" option to serialize this object`);Q[n+++t]=r>>8,Q[n+t]=r&255},x=this.useRecords===!1?b:e.progressiveRecords&&!d?e=>{let n,i=r.transitions||=Object.create(null),a=$++-t,o;for(let s in e)if(typeof e.hasOwnProperty!=`function`||e.hasOwnProperty(s)){if(n=i[s],n)i=n;else{let c=Object.keys(e),l=i;i=r.transitions;let u=0;for(let e=0,t=c.length;e<t;e++){let t=c[e];n=i[t],n||(n=i[t]=Object.create(null),u++),i=n}a+t+1==$?($--,E(i,c,u)):D(i,c,a,u),o=!0,i=l[s]}y(e[s])}if(!o){let n=i[Ks];n?Q[a+t]=n:D(i,Object.keys(e),a,0)}}:e=>{let t,n=r.transitions||=Object.create(null),i=0;for(let r in e)(typeof e.hasOwnProperty!=`function`||e.hasOwnProperty(r))&&(t=n[r],t||(t=n[r]=Object.create(null),i++),n=t);let a=n[Ks];a?a>=96&&d?(Q[$++]=((a-=96)&31)+96,Q[$++]=a>>5):Q[$++]=a:E(n,n.__keys__||Object.keys(e),i);for(let t in e)(typeof e.hasOwnProperty!=`function`||e.hasOwnProperty(t))&&y(e[t])},S=typeof this.useRecords==`function`&&this.useRecords,C=S?e=>{S(e)?x(e):b(e)}:x,w=e=>{let i=o._writeStruct(e,Q,t,$,r,T,(e,t,r)=>{if(r)return n=!0;$=t;let i=Q;return y(e),_(),i===Q?$:{position:$,targetView:Vs,target:Q}});if(i===0)return C(e);$=i},T=e=>{let n;if(e>16777216){if(e-t>zs)throw Error(`Packed buffer would be larger than maximum buffer size`);n=Math.min(zs,Math.round(Math.max((e-t)*(e>67108864?1.25:2),4194304)/4096)*4096)}else n=(Math.max(e-t<<2,Q.length-1)>>12)+1<<12;let r=new Ls(n);return Vs=r.dataView||=new DataView(r.buffer,0,n),e=Math.min(e,Q.length),Q.copy?Q.copy(r,0,t,e):r.set(Q.slice(t,e)),$-=t,t=0,Hs=r.length-10,Q=r},E=(e,t,i)=>{let a=r.nextId;a||=64,a<f&&this.shouldShareStructure&&!this.shouldShareStructure(t)?(a=r.nextOwnId,a<p||(a=f),r.nextOwnId=a+1):(a>=p&&(a=f),r.nextId=a+1);let o=t.highByte=a>=96&&d?a-96>>5:-1;e[Ks]=a,e.__keys__=t,r[a-64]=t,a<f?(t.isShared=!0,r.sharedLength=a-63,n=!0,o>=0?(Q[$++]=(a&31)+96,Q[$++]=o):Q[$++]=a):(o>=0?(Q[$++]=213,Q[$++]=114,Q[$++]=(a&31)+96,Q[$++]=o):(Q[$++]=212,Q[$++]=114,Q[$++]=a),i&&(h+=g*i),m.length>=u&&(m.shift()[Ks]=0),m.push(e),y(t))},D=(e,n,r,i)=>{let a=Q,o=$,s=Hs,c=t;Q=Bs,$=0,t=0,Q||(Bs=Q=new Ls(8192)),Hs=Q.length-10,E(e,n,i),Bs=Q;let l=$;if(Q=a,$=o,Hs=s,t=c,l>1){let e=$+l-1;e>Hs&&T(e);let n=r+t;Q.copyWithin(n+l,n+1,$),Q.set(Bs.slice(0,l),n),$=e}else Q[r+t]=Bs[0]}}useBuffer(e){Q=e,Q.dataView||=new DataView(Q.buffer,Q.byteOffset,Q.byteLength),Vs=Q.dataView,$=0}set position(e){$=e}get position(){return $}clearSharedData(){this.structures&&=[],this.typedStructs&&=[]}};Fs=[Date,Set,Error,RegExp,ArrayBuffer,Object.getPrototypeOf(Uint8Array.prototype).constructor,DataView,Yo],Ps=[{pack(e,t,n){let r=e.getTime()/1e3;if((this.useTimestamp32||e.getMilliseconds()===0)&&r>=0&&r<4294967296){let{target:e,targetView:n,position:i}=t(6);e[i++]=214,e[i++]=255,n.setUint32(i,r)}else if(r>0&&r<4294967296){let{target:n,targetView:i,position:a}=t(10);n[a++]=215,n[a++]=255,i.setUint32(a,e.getMilliseconds()*4e6+(r/1e3/4294967296>>0)),i.setUint32(a+4,r)}else if(isNaN(r)){if(this.onInvalidDate)return t(0),n(this.onInvalidDate());let{target:e,targetView:r,position:i}=t(3);e[i++]=212,e[i++]=255,e[i++]=255}else{let{target:n,targetView:i,position:a}=t(15);n[a++]=199,n[a++]=12,n[a++]=255,i.setUint32(a,e.getMilliseconds()*1e6),i.setBigInt64(a+4,BigInt(Math.floor(r)))}}},{pack(e,t,n){if(this.setAsEmptyObject)return t(0),n({});let r=Array.from(e),{target:i,position:a}=t(this.moreTypes?3:0);this.moreTypes&&(i[a++]=212,i[a++]=115,i[a++]=0),n(r)}},{pack(e,t,n){let{target:r,position:i}=t(this.moreTypes?3:0);this.moreTypes&&(r[i++]=212,r[i++]=101,r[i++]=0),n([e.name,e.message,e.cause])}},{pack(e,t,n){let{target:r,position:i}=t(this.moreTypes?3:0);this.moreTypes&&(r[i++]=212,r[i++]=120,r[i++]=0),n([e.source,e.flags])}},{pack(e,t){this.moreTypes?Js(e,16,t):Ys(Is?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let n=e.constructor;n!==Rs&&this.moreTypes?Js(e,Ts.indexOf(n.name),t):Ys(e,t)}},{pack(e,t){this.moreTypes?Js(e,17,t):Ys(Is?Buffer.from(e):new Uint8Array(e),t)}},{pack(e,t){let{target:n,position:r}=t(1);n[r]=193}}];function Js(e,t,n,r){let i=e.byteLength;if(i+1<256){var{target:a,position:o}=n(4+i);a[o++]=199,a[o++]=i+1}else if(i+1<65536){var{target:a,position:o}=n(5+i);a[o++]=200,a[o++]=i+1>>8,a[o++]=i+1&255}else{var{target:a,position:o,targetView:s}=n(7+i);a[o++]=201,s.setUint32(o,i+1),o+=4}a[o++]=116,a[o++]=t,e.buffer||(e=new Uint8Array(e)),a.set(new Uint8Array(e.buffer,e.byteOffset,e.byteLength),o)}function Ys(e,t){let n=e.byteLength;var r,i;if(n<256){var{target:r,position:i}=t(n+2);r[i++]=196,r[i++]=n}else if(n<65536){var{target:r,position:i}=t(n+3);r[i++]=197,r[i++]=n>>8,r[i++]=n&255}else{var{target:r,position:i,targetView:a}=t(n+5);r[i++]=198,a.setUint32(i,n),i+=4}r.set(e,i)}function Xs(e,t,n,r){let i=e.length;switch(i){case 1:t[n++]=212;break;case 2:t[n++]=213;break;case 4:t[n++]=214;break;case 8:t[n++]=215;break;case 16:t[n++]=216;break;default:i<256?(t[n++]=199,t[n++]=i):i<65536?(t[n++]=200,t[n++]=i>>8,t[n++]=i&255):(t[n++]=201,t[n++]=i>>24,t[n++]=i>>16&255,t[n++]=i>>8&255,t[n++]=i&255)}return t[n++]=r,t.set(e,n),n+=i,n}function Zs(e,t){let n,r=t.length*6,i=e.length-r;for(;n=t.pop();){let t=n.offset,a=n.id;e.copyWithin(t+r,t,i),r-=6;let o=t+r;e[o++]=214,e[o++]=105,e[o++]=a>>24,e[o++]=a>>16&255,e[o++]=a>>8&255,e[o++]=a&255,i=t}return e}function Qs(e,t,n){if(Us.length>0){Vs.setUint32(Us.position+e,$+n-Us.position-e),Us.stringsPosition=$-e;let r=Us;Us=null,t(r[0]),t(r[1])}}function $s(e,t){return e.isCompatible=e=>{let n=!e||(t.lastNamedStructuresLength||0)===e.length;return n||t._mergeStructures(e),n},e}qs.SUPPORTS_STRUCT_HOOKS=!0;var ec=new qs({useRecords:!1});ec.pack,ec.pack;var{NEVER:tc,ALWAYS:nc,DECIMAL_ROUND:rc,DECIMAL_FIT:ic}=Ms,ac=new qs({useRecords:!1,bundleStrings:!1,int64AsType:`number`}),oc=new $o({useRecords:!1,bundleStrings:!1,int64AsType:`number`});function sc(e){return ac.pack(e)}function cc(e){return oc.unpack(e)}var lc=[67,85,73,66],uc=8,dc=`__cui_bin__`;function fc(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function pc(e){if(e instanceof Uint8Array)return e.byteLength>=16384?e:void 0;if(e instanceof ArrayBuffer)return e.byteLength>=16384?new Uint8Array(e):void 0}function mc(e,t){let n=pc(e);if(n){let e=t.length;return t.push(n),{[dc]:e,l:n.byteLength}}if(Array.isArray(e)){let n;for(let r=0;r<e.length;r++){let i=mc(e[r],t);i!==e[r]&&(n??=e.slice(),n[r]=i)}return n??e}if(fc(e)){let n;for(let r of Object.keys(e)){let i=mc(e[r],t);i!==e[r]&&(n??={...e},n[r]=i)}return n??e}return e}function hc(e){if(!fc(e))return!1;let t=e[dc],n=e.l;return!Number.isInteger(t)||t<0||!Number.isInteger(n)||n<0?!1:Object.keys(e).length===2}function gc(e,t,n){if(hc(e)){if(n.outOfOrder||e[dc]!==n.next)return n.outOfOrder=!0,e;let r=e.l,i=n.offset+r;if(i>t.byteLength)throw Error(`Invalid CUIB frame: segment ${n.next} exceeds payload size ${t.byteLength}`);let a=t.subarray(n.offset,i);return n.offset=i,n.next++,a}if(Array.isArray(e)){for(let r=0;r<e.length;r++)e[r]=gc(e[r],t,n);return e}if(fc(e)){for(let r of Object.keys(e))e[r]=gc(e[r],t,n);return e}return e}function _c(e,t){if(hc(e)){t[e[dc]]=e.l;return}if(Array.isArray(e)){for(let n of e)_c(n,t);return}if(fc(e))for(let n of Object.keys(e))_c(e[n],t)}function vc(e,t){if(hc(e))return t[e[dc]];if(Array.isArray(e)){for(let n=0;n<e.length;n++)e[n]=vc(e[n],t);return e}if(fc(e)){for(let n of Object.keys(e))e[n]=vc(e[n],t);return e}return e}function yc(e,t,n){let r=[];_c(e,r);let i=Array(r.length),a=n.offset;for(let e=n.next;e<r.length;e++){let n=r[e];if(n===void 0)throw Error(`Invalid CUIB frame: missing placeholder for segment ${e}`);if(a+n>t.byteLength)throw Error(`Invalid CUIB frame: segment ${e} exceeds payload size ${t.byteLength}`);i[e]=t.subarray(a,a+n),a+=n}return n.offset=a,vc(e,i)}function bc(e){let t=[],n=mc(e,t);if(t.length===0)return ac.pack(e);let r=ac.pack(n),i=r.byteLength,a=uc+i;for(let e of t)a+=e.byteLength;let o=typeof Buffer<`u`?Buffer.allocUnsafe(a):new Uint8Array(a);o[0]=lc[0],o[1]=lc[1],o[2]=lc[2],o[3]=lc[3],o[4]=i&255,o[5]=i>>>8&255,o[6]=i>>>16&255,o[7]=i>>>24&255,o.set(r,uc);let s=uc+r.byteLength;for(let e of t)o.set(e,s),s+=e.byteLength;return o}function xc(e){if(e.byteLength<uc||e[0]!==lc[0]||e[1]!==lc[1]||e[2]!==lc[2]||e[3]!==lc[3])return oc.unpack(e);let t=(e[4]|e[5]<<8|e[6]<<16)+e[7]*16777216,n=uc+t;if(n>e.byteLength)throw Error(`Invalid CUIB frame: envelope length ${t} exceeds payload size ${e.byteLength}`);let r=oc.unpack(e.subarray(uc,n)),i={offset:n,next:0,outOfOrder:!1};if(r=gc(r,e,i),i.outOfOrder&&(r=yc(r,e,i)),i.offset!==e.byteLength)throw Error(`Invalid CUIB frame: expected payload size ${i.offset}, got ${e.byteLength}`);return r}function*Sc(e,t,n){let r=e.length,i=Math.ceil(r/n);for(let a=0;a<i;a++){let o=a*n,s=Math.min(o+n,r),c=e.subarray(o,s);yield{id:t,chunkIndex:a,data:c,isLast:a===i-1}}}var Cc=class{id;buffer;receivedChunks=new Set;totalChunks=0;chunkSize=0;constructor(e,t,n,r){this.id=e,this.totalChunks=n,this.chunkSize=r??Math.ceil(t/n),this.buffer=new Uint8Array(t)}addChunk(e){if(e.id!==this.id)throw Error(`Chunk ID mismatch: expected ${this.id}, got ${e.id}`);let t=e.chunkIndex*this.chunkSize;return this.buffer.set(e.data,t),this.receivedChunks.add(e.chunkIndex),this.isComplete()}isComplete(){return this.receivedChunks.size===this.totalChunks}getData(){if(!this.isComplete())throw Error(`Not all chunks received`);return xc(this.buffer)}getProgress(){let e=this.receivedChunks.size,t=this.totalChunks;return{received:e,total:t,percentage:t>0?e/t*100:0}}},wc=class e{static STALE_TRANSFER_TTL_MS=3e4;static SWEEP_INTERVAL_MS=1e3;assemblers=new Map;completedCallbacks=new Map;errorCallbacks=new Map;lastActivity=new Map;lastSweep=0;startReceiving(e,t,n,r,i,a){this.sweepStale();let o=new Cc(e,i,t,a);this.assemblers.set(e,o),this.completedCallbacks.set(e,n),this.errorCallbacks.set(e,r),this.lastActivity.set(e,Date.now())}sweepStale(){if(this.lastActivity.size===0)return;let t=Date.now();if(t-this.lastSweep<e.SWEEP_INTERVAL_MS)return;this.lastSweep=t;let n=t-e.STALE_TRANSFER_TTL_MS;for(let[e,t]of this.lastActivity)if(t<n){let t=this.errorCallbacks.get(e);this.assemblers.delete(e),this.completedCallbacks.delete(e),this.errorCallbacks.delete(e),this.lastActivity.delete(e),t&&t(Error(`Transfer timed out`))}}processChunk(e){this.sweepStale();let t=this.assemblers.get(e.id);if(!t){console.warn(`Received chunk for unknown transfer: ${e.id}`);return}this.lastActivity.set(e.id,Date.now());try{if(t.addChunk(e)){let n=t.getData(),r=this.completedCallbacks.get(e.id);this.assemblers.delete(e.id),this.completedCallbacks.delete(e.id),this.errorCallbacks.delete(e.id),this.lastActivity.delete(e.id),r&&r(n)}}catch(t){let n=this.errorCallbacks.get(e.id);this.assemblers.delete(e.id),this.completedCallbacks.delete(e.id),this.errorCallbacks.delete(e.id),this.lastActivity.delete(e.id),n&&n(t)}}cancel(e){let t=this.errorCallbacks.get(e);this.assemblers.delete(e),this.completedCallbacks.delete(e),this.errorCallbacks.delete(e),this.lastActivity.delete(e),t&&t(Error(`Transfer cancelled`))}getProgress(e){let t=this.assemblers.get(e);return t?t.getProgress():null}};S();var Tc=Symbol(`rpc:methods`),Ec=Symbol(`rpc:nested`),Dc=Symbol(`rpc:exposeAll`);function Oc(e,t=[],n={},r=new WeakSet){if(!e||typeof e!=`object`||r.has(e))return n;r.add(e);let i=Object.getOwnPropertyNames(e),a=[],o=Object.getPrototypeOf(e);for(;o&&o!==Object.prototype;)a.push(...Object.getOwnPropertyNames(o)),o=Object.getPrototypeOf(o);let s=[...new Set([...i,...a])];for(let r of s)if(!(r===`constructor`||r.startsWith(`_`)||r.startsWith(`#`)))try{if(e.constructor&&Object.prototype.hasOwnProperty.call(e.constructor,r))continue;let i=Object.getOwnPropertyDescriptor(e,r);if(!i){let t=Object.getPrototypeOf(e);for(;t&&t!==Object.prototype&&!i;)i=Object.getOwnPropertyDescriptor(t,r),t=Object.getPrototypeOf(t)}if(i&&(i.get||i.set)&&!i.value){let i=e[r];if(typeof i==`function`){let a=[...t,r].join(`.`);n[a]=i.bind(e)}continue}let a=e[r],o=[...t,r].join(`.`);typeof a==`function`&&(n[o]=a.bind(e))}catch{}return n}function kc(e,t=[],n={},r=new WeakSet){if(r.has(e))return n;r.add(e);let i=e.constructor===Object||e.constructor===void 0,a=Object.getPrototypeOf(e),o=Reflect.hasMetadata(Tc,e)||Reflect.hasMetadata(Tc,a)||Reflect.hasMetadata(Ec,e)||Reflect.hasMetadata(Ec,a)||Reflect.hasMetadata(Dc,a);if(i&&!o){let i=Object.getOwnPropertyNames(e);for(let a of i)if(!(a===`constructor`||a.startsWith(`_`)))try{let i=e[a],o=[...t,a].join(`.`);typeof i==`function`?n[o]=i.bind(e):typeof i==`object`&&i&&!Array.isArray(i)?kc(i,[...t,a],n,r):n[o]=async()=>i}catch{}}else{let i=a&&Reflect.getMetadata(Dc,a),o=[...Reflect.getMetadata(Tc,e)??[],...(a&&Reflect.getMetadata(Tc,a))??[]],s=[...Reflect.getMetadata(Ec,e)??[],...(a&&Reflect.getMetadata(Ec,a))??[]],c=Object.getOwnPropertyNames(e);a&&c.push(...Object.getOwnPropertyNames(a).filter(e=>e!==`constructor`));for(let l of c)if(l!==`constructor`)try{let c=e[l]??a?.[l];if(!c)continue;let u=[...t,l].join(`.`);typeof c==`function`?(i&&!l.startsWith(`_`)||o.includes(l))&&(n[u]=c.bind(e)):o.includes(l)?n[u]=async()=>e[l]:typeof c==`object`&&c&&s.includes(l)&&kc(c,[...t,l],n,r)}catch{}}return n}var Ac=class e extends Error{code;data;constructor(e,t,n){super(t),this.name=`RPCException`,this.code=e,this.data=n}static fromJSON(t){return new e(t.code,t.message,t.data)}toJSON(){return{code:this.code,message:this.message,data:this.data}}};function jc(e,t,n){return new Ac(e,t,n)}var Mc={METHOD_NOT_FOUND:`METHOD_NOT_FOUND`,INVALID_PARAMS:`INVALID_PARAMS`,INTERNAL_ERROR:`INTERNAL_ERROR`,TIMEOUT:`TIMEOUT`,CONNECTION_CLOSED:`CONNECTION_CLOSED`,STREAM_ERROR:`STREAM_ERROR`,PAYLOAD_TOO_LARGE:`PAYLOAD_TOO_LARGE`,NOT_FOUND:`NOT_FOUND`},Nc=Symbol.for(`rpc.callbacks`),Pc=Symbol.for(`rpc.callbacks.oneway`);function Fc(e){return!!e&&typeof e==`object`&&e[Nc]===!0}function Ic(e){return e?.[Pc]??[]}function Lc(e){if(e instanceof Promise)return!0;if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.then==`function`&&typeof t.catch==`function`}function Rc(e,t,n=[],r=null){let i=r,a=e=>{i??=new Set(e)},o=async(t,n)=>{let{result:r,methods:o}=await e.callWithMeta(t,n,{discover:i===null});return o&&a(o),r};return new Proxy({},{get(r,a){if(a===`then`||a===`catch`||a===`finally`)return;if(typeof a==`symbol`||a===`toString`)return()=>`[RPCProxy ${t}${n.length?`.`+n.join(`.`):``}]`;if(i&&n.length===0&&!i.has(a))return;let s=[...n,a];return new Proxy(function(){},{apply(n,r,i){let c=`rpc.${t}.${s.join(`.`)}`,l=a.toLowerCase().includes(`pull`),u=i.findIndex(e=>Fc(e));if(u!==-1){let t=i[u],n=Ic(t),r=i.filter((e,t)=>t!==u);return e.callPullIteratorWithCallback(c,t,n,...r)}let d=i.findIndex(e=>typeof e==`function`);if(d!==-1){let t=i[d],n=i.filter((e,t)=>t!==d);return e.callWithCallback(c,n,t)}return a.toLowerCase().includes(`generate`)?e.callStream(c,...i):l?e.callPullIterator(c,...i):o(c,i)},get(n,r){if(r===`then`||r===`catch`||r===`finally`){let n=s.join(`.`),i=(async()=>(!e.isConnected&&!e.isClosed&&await e.connect(),o(`rpc.${t}.${n}`,[])))();return i[r].bind(i)}return Rc(e,t,s,i)[r]}})}})}function zc(e,t,n,r=[]){return new Proxy({},{get(i,a){if(a===`then`||a===`catch`||a===`finally`)return;if(typeof a==`symbol`||a===`toString`)return()=>`[ServiceProxy ${t.name}${r.length?`.`+r.join(`.`):``}]`;if(a in i)return i[a];let o=[...r,a],s=o.join(`.`),c=t.endpoints.find(e=>{if(e.subject===s)return!0;let t=e.subject.split(`.`);return t[t.length-1]===a&&t.slice(0,-1).join(`.`)===r.join(`.`)});if(c)return new Proxy(function(){},{apply(t,n,r){let i=a.toLowerCase().includes(`pull`),o=r.findIndex(e=>Fc(e));if(o!==-1){let t=r[o],n=Ic(t),i=r.filter((e,t)=>t!==o);return e.callPullIteratorWithCallback(c.subject,t,n,...i)}let s=r.findIndex(e=>typeof e==`function`);if(s!==-1){let t=r[s],n=r.filter((e,t)=>t!==s);return e.callWithCallback(c.subject,n,t)}return a.toLowerCase().includes(`generate`)?e.callStream(c.subject,...r):i?e.callPullIterator(c.subject,...r):e.call(c.subject,...r)}});let l=s+`.`;if(t.endpoints.some(e=>e.subject.startsWith(l)))return zc(e,t,n,o)}})}var Bc=36**4,Vc=Math.floor(Math.random()*36**5).toString(36).padStart(5,`0`),Hc=Math.floor(Math.random()*Bc);function Uc(e){Hc=(Hc+1)%Bc;let t=`${Date.now()}-${Vc}${Hc.toString(36).padStart(4,`0`)}`;return e?`${e}.${t}`:t}function Wc(){let e,t=globalThis.crypto;if(t?.getRandomValues){let n=new Uint8Array(6);t.getRandomValues(n),e=n.reduce((e,t)=>e*256+t,0)}else e=Math.floor(Math.random()*2**48);return e.toString(36).padStart(10,`0`)}function Gc(e){return new Promise(t=>setTimeout(t,e))}function Kc(e,t){let n=Promise.resolve(),r=0;return{dispatch:i=>{if(r===0){let a;try{a=e(i)}catch(e){t(e);return}Lc(a)&&(r++,n=a.then(()=>{r--},e=>{r--,t(e)}));return}r++,n=n.then(()=>e(i)).then(()=>{r--},e=>{r--,t(e)})},flush:()=>r===0?Promise.resolve():n}}async function qc(e,t,n,r,i){let a,o=e(...t);if(o&&typeof o.then==`function`){let e=await o;if(e&&typeof e[Symbol.asyncIterator]==`function`)a=e;else if(e&&typeof e[Symbol.iterator]==`function`)a=(async function*(){for(let t of e)yield t})();else throw jc(Mc.INTERNAL_ERROR,`Handler must return a generator for stream`)}else if(o&&typeof o[Symbol.asyncIterator]==`function`)a=o;else if(o&&typeof o[Symbol.iterator]==`function`)a=(async function*(){for(let e of o)yield e})();else throw jc(Mc.INTERNAL_ERROR,`Handler must return a generator for stream`);let s=!1,c=await i.subscribe(`${n}.cancel`,()=>{s=!0});await Gc(0);try{for await(let e of a){if(s||!i.isConnected)break;let t={id:r,type:`data`,data:e};await i.publish(n,t)}if(!s&&i.isConnected){let e={id:r,type:`end`};await i.publish(n,e)}}catch(e){if(!s&&i.isConnected)try{let t={id:r,type:`error`,error:Yc(e)};await i.publish(n,t)}catch{}}finally{if(c(),a.return)try{await a.return()}catch{}}}async function Jc(e,t){return e(...Array.isArray(t)?t:t==null?[]:[t])}function Yc(e){return e instanceof Ac?e.toJSON():{code:Mc.INTERNAL_ERROR,message:e instanceof Error?e.message:`Internal error`}}async function Xc(e,t,n,r,i){let a,o=e(...t);if(o&&typeof o.then==`function`){let e=await o;if(e&&typeof e[Symbol.asyncIterator]==`function`)a=e;else if(e&&typeof e[Symbol.iterator]==`function`)a=(async function*(){for(let t of e)yield t})();else throw jc(Mc.INTERNAL_ERROR,`Handler must return a generator for pull iterator`)}else if(o&&typeof o[Symbol.asyncIterator]==`function`)a=o;else if(o&&typeof o[Symbol.iterator]==`function`)a=(async function*(){for(let e of o)yield e})();else throw jc(Mc.INTERNAL_ERROR,`Handler must return a generator for pull iterator`);let s=`_rpc.iterator.${n}.request`,c=`_rpc.iterator.${n}.response`,l=!0,u,d=()=>{l&&(l=!1,u?.(),i?.())},f=await r.subscribe(s,async e=>{if(l)try{if(e.type===`cancel`){d(),a.return&&await a.return();let e={id:n,type:`done`};r.tryPublishSync(c,e)||await r.publish(c,e)}else if(e.type===`next`){let{value:e,done:t}=await a.next();if(t){d();let e={id:n,type:`done`};r.tryPublishSync(c,e)||await r.publish(c,e)}else{let t={id:n,type:`value`,value:e};r.tryPublishSync(c,t)||await r.publish(c,t)}}}catch(e){d();let t={id:n,type:`error`,error:Yc(e)};r.tryPublishSync(c,t)||await r.publish(c,t)}});return u=f,async()=>{if(l=!1,f(),a.return)try{await a.return()}catch{}}}async function Zc(e,t,n,r,i,a,o,s){let c=new Set(a),l={},u=!0;for(let e of i)c.has(e)?l[e]=(...t)=>{if(!u||!o.isConnected)return;let n={method:e,args:t};try{o.tryPublishSync(r,n)||o.publish(r,n).catch(()=>{})}catch{}}:l[e]=()=>{throw jc(Mc.INTERNAL_ERROR,`Request-reply callback '${e}' not supported in v1`)};let d,f=e(...t,l),p=e=>{if(e&&typeof e[Symbol.asyncIterator]==`function`)return e;if(e&&typeof e[Symbol.iterator]==`function`)return(async function*(){for(let t of e)yield t})();throw jc(Mc.INTERNAL_ERROR,`Handler must return a generator for pull-callback iterator`)};d=f&&typeof f.then==`function`?p(await f):p(f);let m=`_rpc.iterator.${n}.request`,h=`_rpc.iterator.${n}.response`,g=!0,_,v=()=>{g&&(g=!1,u=!1,_?.(),s?.())},y=await o.subscribe(m,async e=>{if(g)try{if(e.type===`cancel`){v(),d.return&&await d.return();let e={id:n,type:`done`};o.tryPublishSync(h,e)||await o.publish(h,e)}else if(e.type===`next`){let{done:e}=await d.next();if(e){v();let e={id:n,type:`done`};o.tryPublishSync(h,e)||await o.publish(h,e)}else{let e={id:n,type:`value`};o.tryPublishSync(h,e)||await o.publish(h,e)}}}catch(e){v();let t={id:n,type:`error`,error:Yc(e)};o.tryPublishSync(h,t)||await o.publish(h,t)}});return _=y,async()=>{if(g=!1,u=!1,y(),d.return)try{await d.return()}catch{}}}async function Qc(e,t,n,r,i,a){let o=async e=>{if(!i.isConnected)return;let t={id:r,type:`data`,data:e};await i.publish(n,t)},s;try{let n=e(...t,o);n&&typeof n.then==`function`?s=await n:typeof n==`function`&&(s=n)}catch(e){let t={id:r,type:`error`,error:Yc(e)};throw await i.publish(n,t),e}let c=!1,l=async()=>{c||(c=!0,s&&await s())},u;return u=await i.subscribe(`${n}.cancel`,async()=>{u?.(),a?.(),await l()}),async()=>{u?.(),await l()}}var $c=a((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.ServiceVerb=e.ServiceError=e.ServiceErrorCodeHeader=e.ServiceErrorHeader=e.ServiceResponseType=void 0,e.ServiceResponseType={STATS:`io.nats.micro.v1.stats_response`,INFO:`io.nats.micro.v1.info_response`,PING:`io.nats.micro.v1.ping_response`},e.ServiceErrorHeader=`Nats-Service-Error`,e.ServiceErrorCodeHeader=`Nats-Service-Error-Code`,e.ServiceError=class t extends Error{code;constructor(e,t){super(t),this.code=e}static isServiceError(e){return t.toServiceError(e)!==null}static toServiceError(n){let r=n?.headers?.get(e.ServiceErrorCodeHeader)||``;if(r!==``){let i=parseInt(r)||400,a=n?.headers?.get(e.ServiceErrorHeader)||``;return new t(i,a.length?a:r)}return null}},e.ServiceVerb={PING:`PING`,STATS:`STATS`,INFO:`INFO`}})),el=a((t=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ServiceImpl=t.ServiceGroupImpl=t.ServiceMsgImpl=t.ServiceApiPrefix=void 0;var n=(jo(),e(Ao)),r=$c();function i(e,t=``){if(t===``)throw Error(`${e} name required`);let n=a(t);if(n.length)throw Error(`invalid ${e} name - ${e} name ${n}`)}function a(e=``){if(!e)throw Error(`name required`);let t=/^[-\w]+$/g;if(e.match(t)===null){for(let n of e.split(``))if(n.match(t)===null)return`cannot contain '${n}'`}return``}t.ServiceApiPrefix=`$SRV`;var o=class{msg;constructor(e){this.msg=e}get data(){return this.msg.data}get sid(){return this.msg.sid}get subject(){return this.msg.subject}get reply(){return this.msg.reply||``}get headers(){return this.msg.headers}respond(e,t){return this.msg.respond(e,t)}respondError(e,t,i,a){return a||={},a.headers=a.headers||(0,n.headers)(),a.headers?.set(r.ServiceErrorCodeHeader,`${e}`),a.headers?.set(r.ServiceErrorHeader,t),this.msg.respond(i,a)}json(e){return this.msg.json(e)}string(){return this.msg.string()}};t.ServiceMsgImpl=o;var s=class e{subject;queue;srv;constructor(t,n=``,r=``){n!==``&&l(`service group`,n);let i=``;if(t instanceof u)this.srv=t,i=``;else if(t instanceof e){let e=t;this.srv=e.srv,r===void 0&&(r=e.queue),i=e.subject}else throw Error(`unknown ServiceGroup type`);this.subject=this.calcSubject(i,n),this.queue=r}calcSubject(e,t=``){return t===``?e:e===``?t:`${e}.${t}`}addEndpoint(e=``,t){t||={subject:e};let n=typeof t==`function`?{handler:t,subject:e}:t;i(`endpoint`,e);let{subject:r,handler:a,metadata:o,queue:s}=n;r||=e,s||=this.queue,c(`endpoint subject`,r),r=this.calcSubject(this.subject,r);let l={name:e,subject:r,queue:s,handler:a,metadata:o};return this.srv._addEndpoint(l)}addGroup(t=``,n){return n===void 0&&(n=this.queue),new e(this,t,n)}};t.ServiceGroupImpl=s;function c(e,t){if(t===``)throw Error(`${e} cannot be empty`);if(t.indexOf(` `)!==-1)throw Error(`${e} cannot contain spaces: '${t}'`);let n=t.split(`.`);n.forEach((r,i)=>{if(r===`>`&&i!==n.length-1)throw Error(`${e} cannot have internal '>': '${t}'`)})}function l(e,t){if(t.indexOf(` `)!==-1)throw Error(`${e} cannot contain spaces: '${t}'`);t.split(`.`).forEach(n=>{if(n===`>`)throw Error(`${e} name cannot contain internal '>': '${t}'`)})}var u=class e{nc;_id;config;handlers;internal;_stopped;_done;started;closeListener;static controlSubject(e,n=``,r=``,a){let o=a??t.ServiceApiPrefix;return n===``&&r===``?`${o}.${e}`:(i(`control subject name`,n),r===``?`${o}.${e}.${n}`:(i(`control subject id`,r),`${o}.${e}.${n}.${r}`))}constructor(e,t={name:``,version:``}){this.nc=e,this.config=Object.assign({},t),this.config.queue===void 0&&(this.config.queue=`q`),t.metadata=Object.freeze(t.metadata||{}),i(`name`,this.config.name),this.config.queue&&i(`queue`,this.config.queue),(0,n.parseSemVer)(this.config.version),this._id=n.nuid.next(),this.internal=[],this._done=(0,n.deferred)(),this._stopped=!1,this.handlers=[],this.started=new Date().toISOString(),this.reset(),this.closeListener={connectionClosedCallback:e=>{this.close(e).catch()}},this.nc.addCloseListener(this.closeListener)}get subjects(){return this.handlers.filter(e=>e.internal===!1).map(e=>e.subject)}get id(){return this._id}get name(){return this.config.name}get description(){return this.config.description??``}get version(){return this.config.version}get metadata(){return this.config.metadata}errorToHeader(e){let t=(0,n.headers)();if(e instanceof r.ServiceError){let n=e;t.set(r.ServiceErrorHeader,n.message),t.set(r.ServiceErrorCodeHeader,`${n.code}`)}else t.set(r.ServiceErrorHeader,e.message),t.set(r.ServiceErrorCodeHeader,`500`);return t}setupHandler(e,t=!1){let r=t?``:e.queue?e.queue:this.config.queue,{name:i,subject:a,handler:s}=e,c=e;c.internal=t,t&&this.internal.push(c),c.stats=new d(i,a,r),c.queue=r;let l=s?(e,t)=>{if(e){this.close(e);return}let r=Date.now();try{s(e,new o(t))}catch(e){c.stats.countError(e),t?.respond(n.Empty,{headers:this.errorToHeader(e)})}finally{c.stats.countLatency(r)}}:void 0;return c.sub=this.nc.subscribe(a,{callback:l,queue:r}),c.sub.closed.then(()=>{this._stopped||this.close(Error(`required subscription ${e.subject} stopped`)).catch()}).catch(t=>{if(!this._stopped){let n=Error(`required subscription ${e.subject} errored: ${t.message}`);n.stack=t.stack,this.close(n).catch()}}),c}info(){return{type:r.ServiceResponseType.INFO,name:this.name,id:this.id,version:this.version,description:this.description,metadata:this.metadata,endpoints:this.endpoints()}}endpoints(){return this.handlers.map(e=>{let{subject:t,metadata:n,name:r,queue:i}=e;return{subject:t,metadata:n,name:r,queue_group:i}})}async stats(){let e=[];for(let t of this.handlers){if(typeof this.config.statsHandler==`function`)try{t.stats.data=await this.config.statsHandler(t)}catch(e){t.stats.countError(e)}e.push(t.stats.stats(t.qi))}return{type:r.ServiceResponseType.STATS,name:this.name,id:this.id,version:this.version,started:this.started,metadata:this.metadata,endpoints:e}}addInternalHandler(e,t){let n=`${e}`.toUpperCase();this._doAddInternalHandler(`${n}-all`,e,t),this._doAddInternalHandler(`${n}-kind`,e,t,this.name),this._doAddInternalHandler(`${n}`,e,t,this.name,this.id)}_doAddInternalHandler(t,n,r,i=``,a=``){let o={};o.name=t,o.subject=e.controlSubject(n,i,a),o.handler=r,this.setupHandler(o,!0)}start(){let e=(e,t)=>e?(this.close(e),Promise.reject(e)):this.stats().then(e=>(t?.respond(JSON.stringify(e)),Promise.resolve())),t=(e,t)=>e?(this.close(e),Promise.reject(e)):(t?.respond(JSON.stringify(this.info())),Promise.resolve()),n=JSON.stringify(this.ping());return this.addInternalHandler(r.ServiceVerb.PING,(e,t)=>e?(this.close(e).then().catch(),Promise.reject(e)):(t.respond(n),Promise.resolve())),this.addInternalHandler(r.ServiceVerb.STATS,e),this.addInternalHandler(r.ServiceVerb.INFO,t),this.handlers.forEach(e=>{let{subject:t}=e;typeof t==`string`&&e.handler!==null&&this.setupHandler(e)}),Promise.resolve(this)}close(e){if(this._stopped)return this._done;this._stopped=!0,this.nc.removeCloseListener(this.closeListener);let t=[];return this.nc.isClosed()||(t=this.handlers.concat(this.internal).map(e=>e.sub.drain())),Promise.allSettled(t).then(()=>{this._done.resolve(e||null)}),this._done}get stopped(){return this._done}get isStopped(){return this._stopped}stop(e){return this.close(e)}ping(){return{type:r.ServiceResponseType.PING,name:this.name,id:this.id,version:this.version,metadata:this.metadata}}reset(){if(this.started=new Date().toISOString(),this.handlers)for(let e of this.handlers)e.stats.reset(e.qi)}addGroup(e,t){return new s(this,e,t)}addEndpoint(e,t){return new s(this).addEndpoint(e,t)}_addEndpoint(e){let t=new n.QueuedIteratorImpl;t.profile=!0,t.noIterator=typeof e.handler==`function`,t.noIterator||(e.handler=(e,n)=>{e?this.stop(e).catch():t.push(new o(n))},t.iterClosed.then(()=>{this.close().catch()}));let r=this.setupHandler(e,!1);return r.sub.closed.then(e=>{e?this.stop(e):t.stop()}),r.qi=t,this.handlers.push(r),t}};t.ServiceImpl=u;var d=class{name;subject;average_processing_time;num_requests;processing_time;num_errors;last_error;data;metadata;queue;constructor(e,t,n=``){this.name=e,this.subject=t,this.average_processing_time=0,this.num_errors=0,this.num_requests=0,this.processing_time=0,this.queue=n}reset(e){this.num_requests=0,this.processing_time=0,this.average_processing_time=0,this.num_errors=0,this.last_error=void 0,this.data=void 0;let t=e;t&&(t.time=0,t.processed=0)}countLatency(e){this.num_requests++,this.processing_time+=(0,n.nanos)(Date.now()-e),this.average_processing_time=Math.round(this.processing_time/this.num_requests)}countError(e){this.num_errors++,this.last_error=e.message}_stats(){let{name:e,subject:t,average_processing_time:n,num_errors:r,num_requests:i,processing_time:a,last_error:o,data:s,queue:c}=this;return{name:e,subject:t,average_processing_time:n,num_errors:r,num_requests:i,processing_time:a,last_error:o,data:s,queue_group:c}}stats(e){let t=e;return t?.noIterator===!1&&(this.processing_time=(0,n.nanos)(t.time),this.num_requests=t.processed,this.average_processing_time=this.processing_time>0&&this.num_requests>0?this.processing_time/this.num_requests:0),this._stats()}}})),tl=a((t=>{Object.defineProperty(t,"__esModule",{value:!0}),t.ServiceClientImpl=void 0;var n=(jo(),e(Ao)),r=el(),i=$c();t.ServiceClientImpl=class{nc;prefix;opts;constructor(e,t={strategy:`stall`,maxWait:2e3},n){this.nc=e,this.prefix=n,this.opts=t}ping(e=``,t=``){return this.q(i.ServiceVerb.PING,e,t)}stats(e=``,t=``){return this.q(i.ServiceVerb.STATS,e,t)}info(e=``,t=``){return this.q(i.ServiceVerb.INFO,e,t)}async q(e,t=``,i=``){let a=new n.QueuedIteratorImpl,o=r.ServiceImpl.controlSubject(e,t,i,this.prefix),s=await this.nc.requestMany(o,n.Empty,this.opts);return(async()=>{for await(let e of s)try{let t=e.json();a.push(t)}catch(e){a.push(()=>{a.stop(e)})}a.push(()=>{a.stop()})})().catch(e=>{a.stop(e)}),a}}})),nl=a((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Svcm=e.ServiceVerb=e.ServiceResponseType=e.ServiceErrorHeader=e.ServiceErrorCodeHeader=e.ServiceError=void 0;var t=el(),n=tl(),r=$c();Object.defineProperty(e,"ServiceError",{enumerable:!0,get:function(){return r.ServiceError}}),Object.defineProperty(e,"ServiceErrorCodeHeader",{enumerable:!0,get:function(){return r.ServiceErrorCodeHeader}}),Object.defineProperty(e,"ServiceErrorHeader",{enumerable:!0,get:function(){return r.ServiceErrorHeader}}),Object.defineProperty(e,"ServiceResponseType",{enumerable:!0,get:function(){return r.ServiceResponseType}}),Object.defineProperty(e,"ServiceVerb",{enumerable:!0,get:function(){return r.ServiceVerb}}),e.Svcm=class{nc;constructor(e){this.nc=e}add(e){try{return new t.ServiceImpl(this.nc,e).start()}catch(e){return Promise.reject(e)}}client(e,t){return new n.ServiceClientImpl(this.nc,e,t)}}})),rl=a((e=>{Object.defineProperty(e,"__esModule",{value:!0}),e.Svcm=e.ServiceVerb=e.ServiceResponseType=e.ServiceErrorHeader=e.ServiceErrorCodeHeader=e.ServiceError=void 0;var t=nl();Object.defineProperty(e,"ServiceError",{enumerable:!0,get:function(){return t.ServiceError}}),Object.defineProperty(e,"ServiceErrorCodeHeader",{enumerable:!0,get:function(){return t.ServiceErrorCodeHeader}}),Object.defineProperty(e,"ServiceErrorHeader",{enumerable:!0,get:function(){return t.ServiceErrorHeader}}),Object.defineProperty(e,"ServiceResponseType",{enumerable:!0,get:function(){return t.ServiceResponseType}}),Object.defineProperty(e,"ServiceVerb",{enumerable:!0,get:function(){return t.ServiceVerb}}),Object.defineProperty(e,"Svcm",{enumerable:!0,get:function(){return t.Svcm}})}))(),il=class{client;svc;services=[];nc;constructor(e){this.client=e}init(e){this.nc!==e&&(this.nc=e,this.svc=new rl.Svcm(e),this.services=[])}async registerHandler(e,t,n){if(!this.svc)throw Error(`RPCService is not initialized. Call init() first.`);let r=new Map,i=this.client,a=this.svc;n?.isolatedConnection&&(i=this.client.createIsolatedClient({...this.client.options,name:`${this.client.options.name}-service-${e.name}`}),a=new rl.Svcm(await i.connect()));let o=await a.add(e);this.services.push(o),n?.isolatedConnection&&(o._isolatedClient=i);let s=kc(t),c=new Map;for(let[e,t]of Object.entries(s)){let n=e.split(`.`),a=n.pop(),s=o;if(n.length>0){let e=n.join(`.`);if(!c.has(e)){let t=o;for(let e of n)t=t.addGroup(e);c.set(e,t)}s=c.get(e)}s.addEndpoint(a,async(e,n)=>{if(e){n.respondError(500,e.message);return}try{let e=n.headers?.get(`x-chunked-transfer`);if(e===`header`){let e=cc(n.data),t=n.headers?.get(`x-chunk-id`);if(!t||e.transferId!==t){console.error(`Invalid chunk header`);return}i.chunkingManager.startReceiving(e.transferId,e.totalChunks,async e=>{await o(e,n)},e=>{console.error(`Error assembling chunks for ${a}:`,e)},e.totalSize,e.chunkSize)}else if(e===`chunk`){let e=n.headers?.get(`x-chunk-id`),t=parseInt(n.headers?.get(`x-chunk-index`)??`0`);if(!e){console.error(`Chunk missing chunk ID`);return}i.chunkingManager.processChunk({id:e,chunkIndex:t,data:n.data,isLast:!1})}else await o(xc(n.data),n)}catch(e){console.error(`Error processing message for ${a}:`,e)}async function o(e,n){let a={id:e.id};try{if(e.params?.__stream&&e.params?.__streamSubject){let n=e.params.__streamSubject,r=e.params.args??[];await qc(t,r,n,e.id,i)}else if(e.params?.__pullIterator||Array.isArray(e.params)&&e.params[0]?.__pullIterator){let o=e.params?.__pullIterator?e.params:e.params[0],s=o.args??[],c=o.__iteratorId??e.id,l=await Xc(t,s,c,i,()=>r.delete(c));r.set(c,l),a.result={iteratorId:c};let u=`${n.subject}.reply.${e.id}`;await i.publish(u,a)}else{a.result=await Jc(t,e.params);let r=`${n.subject}.reply.${e.id}`;await i.publish(r,a)}}catch(t){a.error=Yc(t);try{let t=`${n.subject}.reply.${e.id}`;await i.publish(t,a)}catch(e){if(i.isClosed)return;console.error(`Failed to send error response:`,e)}}}})}let l=o;l._pullIteratorCleanups=r;let u=o.stop.bind(o);return o.stop=async e=>(await Promise.allSettled(Array.from(r.values()).map(e=>e())),r.clear(),u(e)),new al(o)}monitor(){if(!this.svc)throw Error(`RPCService is not initialized. Call init() first.`);return this.svc.client({strategy:`stall`,stall:10,maxWait:2e3})}async stopAll(){await Promise.allSettled(this.services.map(async e=>{await e.stop();let t=e._isolatedClient;t&&await t.disconnect()})),this.services=[]}async stop(e){let t=this.services.find(t=>t.info().name===e);if(t)try{await t.stop();let e=t._isolatedClient;e&&await e.disconnect(),this.services=this.services.filter(e=>e!==t)}catch{}}getAllInfo(){return this.services.map(e=>e.info())}getInfo(e){return this.services.find(t=>t.info().name===e)?.info()}async getAllStats(){return Promise.all(this.services.map(e=>e.stats()))}async getStats(e){return this.services.find(t=>t.info().name===e)?.stats()}},al=class{natsService;get isStopped(){return this.natsService.isStopped}constructor(e){this.natsService=e}info(){return this.natsService.info()}stats(){return this.natsService.stats()}async stop(e){try{await this.natsService.stop(e)}catch{}}};ko(),Wr(),hr(),ra();function ol(e){return new cl(e)}function sl(e){return Br(e?`_INBOX.${e}`:void 0)}var cl=class e{options;service=new il(this);chunkingManager=new wc;pullIteratorCleanups=new Map;callbackCleanups=new Map;nc;subscriptionSeq=0;subscriptionEntries=new Map;pullIteratorSettles=new Set;replyPrefix;muxEntry;statusHandlers=new Map;_maxPayloadSize=1024*1024;connectionPromise;closed=!1;isolatedClients=[];pendingRequests=new Map;streamHandlers=new Map;get isConnected(){return this.nc?.isClosed()===!1}get isStale(){return this.nc?.isStale?.()??!1}get isClosed(){return this.closed}get maxPayloadSize(){return this._maxPayloadSize}status(){return this.nc?.status()}async flush(e=5e3){if(!this.nc)throw jc(Mc.CONNECTION_CLOSED,`Not connected`);let t;try{await Promise.race([this.nc.flush(),new Promise((n,r)=>{t=setTimeout(()=>r(jc(Mc.TIMEOUT,`flush() timed out after ${e}ms`)),e)})])}finally{t&&clearTimeout(t)}}constructor(e){this.options=e,this.replyPrefix=e.connId??Wc()}createIsolatedClient(t){return new e(t)}async connect(e){if(e?.signal?.aborted)throw new DOMException(`Aborted`,`AbortError`);if(this.nc&&!this.nc.isClosed())return this.nc;let t={servers:this.options.servers,user:this.options.auth?.user,pass:this.options.auth?.password,name:this.options.name,inboxPrefix:this.options.connId?`_INBOX.${this.options.connId}`:void 0,reconnect:this.options.reconnect??!0,timeout:this.options.connectTimeout??1e4,maxPingOut:this.options.maxPingOut??2,maxReconnectAttempts:this.options.maxReconnectAttempts??-1,reconnectTimeWait:this.options.reconnectTimeWait??2e3,reconnectJitter:this.options.reconnectJitter??100,reconnectJitterTLS:this.options.reconnectJitterTLS??1e3,ignoreAuthErrorAbort:this.options.ignoreAuthErrorAbort??!1,pingInterval:this.options.pingInterval??12e4,pingTimeout:this.options.pingTimeout??0,reconnectionDelayMax:this.options.reconnectionDelayMax??0,reconnectionRandomizationFactor:this.options.reconnectionRandomizationFactor??0,tls:this.options.tls,debug:this.options.debug??!1,noAsyncTraces:!0,waitOnFirstConnect:this.options.waitOnFirstConnect??!0,signal:e?.signal};this.connectionPromise??=To(t);let n=this.connectionPromise;try{this.nc=await ll(n,e?.signal)}finally{this.connectionPromise=void 0}this.closed=!1,this.service.init(this.nc);try{let e=this.nc.info;this._maxPayloadSize=e?.max_payload??this.options.maxPayloadSize??1024*1024}catch{this._maxPayloadSize=this.options.maxPayloadSize??1024*1024}this._maxPayloadSize-=8192,this.ensureMuxSubscription(!1);for(let e of this.subscriptionEntries.values())(!e.sub||e.sub.isClosed())&&this.natsSubscribe(e);return this.nc}async disconnect(){this.closed=!0;for(let[,e]of this.pendingRequests)e.timeout&&clearTimeout(e.timeout),e.cleanup?.(),e.reject(jc(Mc.CONNECTION_CLOSED,`Connection closed`));this.pendingRequests.clear(),this.statusHandlers.clear();for(let[,e]of this.streamHandlers)try{e.end()}catch{}this.streamHandlers.clear(),this.settlePullIterators(),await Promise.allSettled(Array.from(this.pullIteratorCleanups.values()).map(e=>e())),this.pullIteratorCleanups.clear(),await Promise.allSettled(Array.from(this.callbackCleanups.values()).map(e=>e())),this.callbackCleanups.clear();for(let e of this.subscriptionEntries.values())try{e.sub?.unsubscribe()}catch{}if(this.subscriptionEntries.clear(),this.muxEntry=void 0,this.chunkingManager=new wc,await Promise.allSettled(this.isolatedClients.map(e=>e.disconnect())),this.isolatedClients=[],this.nc){try{await this.nc.close()}catch{}try{let e=this.options.disconnectTimeout??2e3;await Promise.race([this.nc.closed(),new Promise(t=>setTimeout(t,e))])}catch{}this.nc=void 0}}reconfigure(e){if(this.nc&&!this.nc.isClosed())throw Error(`Cannot reconfigure while connected. Call suspend() first.`);e.servers!==void 0&&(this.options.servers=e.servers),e.auth!==void 0&&(this.options.auth=e.auth);for(let t of this.isolatedClients)t.reconfigure(e)}setServers(e){this.options.servers=e,this.nc&&!this.nc.isClosed()&&this.nc.setServers(e);for(let t of this.isolatedClients)t.setServers(e)}async forceReconnect(){let e=this.nc;if(!(!e||e.isClosed())){try{typeof e.forceReconnect==`function`?await e.forceReconnect():typeof e.reconnect==`function`&&await e.reconnect()}catch{}await Promise.allSettled(this.isolatedClients.map(e=>e.forceReconnect()))}}abortClose(e){this.closed=!0;for(let[,e]of this.pendingRequests)e.timeout&&clearTimeout(e.timeout),e.cleanup?.(),e.reject(jc(Mc.CONNECTION_CLOSED,`Connection closed`));this.pendingRequests.clear(),this.statusHandlers.clear();for(let[,e]of this.streamHandlers)try{e.end()}catch{}this.streamHandlers.clear(),this.settlePullIterators();for(let e of this.pullIteratorCleanups.values())try{e()}catch{}this.pullIteratorCleanups.clear();for(let e of this.callbackCleanups.values())try{e()}catch{}this.callbackCleanups.clear();for(let t of this.isolatedClients)try{t.abortClose(e)}catch{}this.isolatedClients=[];let t=this.nc;if(t){try{typeof t.abortClose==`function`?t.abortClose(e):t.close().catch(()=>{})}catch{}this.nc=void 0}}async suspend(){for(let[,e]of this.pendingRequests)e.timeout&&clearTimeout(e.timeout),e.cleanup?.(),e.reject(jc(Mc.CONNECTION_CLOSED,`Connection closed`));this.pendingRequests.clear(),this.statusHandlers.clear();for(let[,e]of this.streamHandlers)try{e.end()}catch{}this.streamHandlers.clear(),this.settlePullIterators(),await Promise.allSettled(Array.from(this.pullIteratorCleanups.values()).map(e=>e())),this.pullIteratorCleanups.clear(),await Promise.allSettled(Array.from(this.callbackCleanups.values()).map(e=>e())),this.callbackCleanups.clear();for(let e of this.subscriptionEntries.values()){try{e.sub?.unsubscribe()}catch{}e.sub=void 0}if(this.chunkingManager=new wc,await Promise.allSettled(this.isolatedClients.map(e=>e.suspend())),this.nc){try{await this.nc.close()}catch{}try{let e=this.options.disconnectTimeout??2e3;await Promise.race([this.nc.closed(),new Promise(t=>setTimeout(t,e))])}catch{}this.nc=void 0}this.connectionPromise=void 0}async publish(e,t,n){if(!this.nc)throw Error(`Not connected`);let r=bc(t);if(r.length<=this._maxPayloadSize){this.nc.publish(e,r,n);return}let i=Uc(),a={type:`chunked`,transferId:i,totalChunks:Math.ceil(r.length/this._maxPayloadSize),totalSize:r.length,chunkSize:this._maxPayloadSize},o=n?.headers??ea();o.set(`x-chunked-transfer`,`header`),o.set(`x-chunk-id`,i),this.nc.publish(e,sc(a),{headers:o,reply:n?.reply});let s=0;for(let t of Sc(r,i,this._maxPayloadSize)){let r=ea();r.set(`x-chunked-transfer`,`chunk`),r.set(`x-chunk-id`,i),r.set(`x-chunk-index`,s.toString()),this.nc.publish(e,t.data,{headers:r,reply:n?.reply}),s>0&&s%50==0&&await Gc(0),s++}}tryPublishSync(e,t,n){if(!this.nc)throw Error(`Not connected`);let r=bc(t);return r.length>this._maxPayloadSize?!1:(this.nc.publish(e,r,n),!0)}async subscribe(e,t,n){let{unsubscribe:r}=await this.subscribeEntry(e,t,n);return r}async subscribeEntry(e,t,n){if(!this.nc)throw Error(`Not connected`);let r=++this.subscriptionSeq,i={pattern:e,handler:t,options:n};return this.subscriptionEntries.set(r,i),this.natsSubscribe(i),{entry:i,unsubscribe:()=>{try{i.sub?.unsubscribe()}catch{}finally{this.subscriptionEntries.delete(r)}}}}natsSubscribe(e){let{pattern:t}=e;if(e.raw){e.sub=this.nc.subscribe(t,{callback:(n,r)=>{if(n){console.error(`Subscription error for ${t}:`,n);return}try{e.handler(r)}catch(e){console.error(`Error processing message for ${t}:`,e)}}});return}let n=Kc(e.handler,e=>console.error(`Error in handler for ${t}:`,e)),r=n.dispatch;e.flush=n.flush;let i=(e,n)=>{if(e){console.error(`Subscription error for ${t}:`,e);return}try{let e=n.headers?.get(`x-chunked-transfer`);if(e===`header`){let e=cc(n.data),i=n.headers?.get(`x-chunk-id`);if(!i||e.transferId!==i){console.error(`Invalid chunk header`);return}this.chunkingManager.startReceiving(e.transferId,e.totalChunks,e=>{r(e)},e=>{console.error(`Error assembling chunks for ${t}:`,e)},e.totalSize,e.chunkSize)}else if(e===`chunk`){let e=n.headers?.get(`x-chunk-id`),t=parseInt(n.headers?.get(`x-chunk-index`)??`0`);if(!e){console.error(`Chunk missing chunk ID`);return}this.chunkingManager.processChunk({id:e,chunkIndex:t,data:n.data,isLast:!1})}else{let e=xc(n.data);r(e)}}catch(e){console.error(`Error processing message for ${t}:`,e)}};e.sub=this.nc.subscribe(t,{...e.options?.queue?{queue:e.options.queue}:{},callback:i})}ensureMuxSubscription(e=!0){this.muxEntry||(this.muxEntry={pattern:`rpc.reply.${this.replyPrefix}.>`,raw:!0,handler:e=>this.handleMuxMessage(e)},this.subscriptionEntries.set(++this.subscriptionSeq,this.muxEntry)),e&&this.nc&&(!this.muxEntry.sub||this.muxEntry.sub.isClosed())&&this.natsSubscribe(this.muxEntry)}handleMuxMessage(e){if(e.data?.length===0&&e.headers?.code===503){let t=e.subject.slice(10),n=this.statusHandlers.get(t);if(n){this.statusHandlers.delete(t);try{n(new mr.NoRespondersError(t))}catch(e){console.error(`Error in no-responder status handler:`,e)}return}let r=this.pendingRequests.get(t);r&&(this.pendingRequests.delete(t),r.timeout&&clearTimeout(r.timeout),r.reject(new mr.NoRespondersError(r.subject??t)));return}let t=e.headers?.get(`x-chunked-transfer`);if(t===`header`){let t=cc(e.data),n=e.headers?.get(`x-chunk-id`);if(!n||t.transferId!==n){console.error(`Invalid chunk header on reply mux`);return}this.chunkingManager.startReceiving(t.transferId,t.totalChunks,e=>this.routeMuxResponse(e),e=>console.error(`Error assembling chunked RPC response:`,e),t.totalSize,t.chunkSize)}else if(t===`chunk`){let t=e.headers?.get(`x-chunk-id`),n=parseInt(e.headers?.get(`x-chunk-index`)??`0`);if(!t){console.error(`Chunk missing chunk ID on reply mux`);return}this.chunkingManager.processChunk({id:t,chunkIndex:n,data:e.data,isLast:!1})}else this.routeMuxResponse(xc(e.data))}routeMuxResponse(e){let t=e,n=t?.id;if(!n)return;let r=this.pendingRequests.get(n);r&&(this.pendingRequests.delete(n),r.timeout&&clearTimeout(r.timeout),t.error?r.reject(Ac.fromJSON(t.error)):r.resolve({result:t.result,methods:t.__methods}))}settlePullIterators(){for(let e of[...this.pullIteratorSettles])try{e()}catch{}this.pullIteratorSettles.clear()}async request(e,t,n){return this.withNoResponderRetry(()=>this._requestOnce(e,t,n),n?.noResponderRetry)}async _requestOnce(e,t,n){if(!this.nc)throw Error(`Not connected`);let r=n?.timeout??5e3,i=bc(t);try{let t=await this.nc.request(e,i,{timeout:r,headers:n?.headers,noMux:!1});if(t.headers?.get(`Nats-Service-Error-Code`)){let e=t.headers.get(`Nats-Service-Error-Code`)||`500`,n=t.headers.get(`Nats-Service-Error`)||`Service error`,r=null;if(t.data)try{r=xc(t.data)}catch{}throw jc(e,n,r)}let a=xc(t.data);if(a?.error)throw jc(a.code??Mc.INTERNAL_ERROR,a.error??`Unknown error`,a);return a}catch(t){throw t.code===`503`||t.message?.includes(`no responders`)?jc(Mc.NOT_FOUND,`No responders available`):t.code===`TIMEOUT`||t.message?.includes(`timeout`)?jc(Mc.TIMEOUT,`Request to "${e}" timed out after ${r}ms`):t}}async withNoResponderRetry(e,t){let n=t?.maxRetries??this.options.noResponderRetry?.maxRetries??3,r=t?.delays??this.options.noResponderRetry?.delays??[500,1e3,2e3];for(let t=0;;t++)try{return await e()}catch(e){if(!(e instanceof mr.NoRespondersError||e instanceof Ac&&e.code===Mc.NOT_FOUND)||t>=n||this.closed)throw e;let i=r[Math.min(t,r.length-1)];await Gc(i)}}async call(e,...t){let{result:n}=await this.withNoResponderRetry(()=>this._callOnce(e,t));return n}async callWithMeta(e,t=[],n){return this.withNoResponderRetry(()=>this._callOnce(e,t,n?.discover===!0))}async _callOnce(e,t,n=!1){if(!this.isConnected&&!this.isClosed&&await this.connect(),!this.nc)throw Error(`Not connected`);if(!e.startsWith(`rpc.`))return this._callOnceService(e,t);this.ensureMuxSubscription();let r=Uc(this.replyPrefix),i=this.options.timeout??3e4,a=`rpc.reply.${r}`;return new Promise((o,s)=>{let c=setTimeout(()=>{this.pendingRequests.delete(r)&&s(jc(Mc.TIMEOUT,`RPC call to "${e}" timed out after ${i}ms`))},i);this.pendingRequests.set(r,{resolve:o,reject:s,timeout:c,subject:e,cleanup:()=>{clearTimeout(c),this.pendingRequests.delete(r)}});let l={id:r,method:`call`,params:t};n&&(l.__discover=!0),this.publish(e,l,{reply:a}).catch(e=>{this.pendingRequests.delete(r)&&(clearTimeout(c),s(e))})})}async _callOnceService(e,t){let n=Uc(this.replyPrefix),r=this.options.timeout??3e4,i=`${e}.reply.${n}`;return new Promise(async(a,o)=>{let s,c,l=async()=>{if(this.pendingRequests.has(n)){let e=this.pendingRequests.get(n);e?.timeout&&clearTimeout(e.timeout),this.pendingRequests.delete(n)}if(s&&!s.isClosed())try{s.unsubscribe()}catch{}c?.()},u=setTimeout(()=>{this.pendingRequests.has(n)&&(this.pendingRequests.delete(n),l(),o(jc(Mc.TIMEOUT,`RPC call to "${e}" timed out after ${r}ms`)))},r);this.pendingRequests.set(n,{resolve:a,reject:o,timeout:u,cleanup:()=>void l()});let d=async e=>{let t=e;if(t.id===n){let e=this.pendingRequests.get(t.id);e&&(this.pendingRequests.delete(t.id),e.timeout&&clearTimeout(e.timeout),await l(),t.error?e.reject(Ac.fromJSON(t.error)):e.resolve({result:t.result,methods:t.__methods}))}},f=(t,n)=>{n&&n.data?.length===0&&n.headers?.code===503?(o(new mr.NoRespondersError(e)),l()):t&&(o(t),l())};try{c=await this.subscribe(i,d);let r=sl(this.options.connId);s=this.nc.subscribe(r,{max:1,callback:f});let a={id:n,method:`call`,params:t};await this.publish(e,a,{reply:r})}catch(e){await l(),o(e)}})}async*callStream(e,...t){let n=this.options.noResponderRetry?.maxRetries??3,r=this.options.noResponderRetry?.delays??[500,1e3,2e3];for(let i=0;;i++)try{yield*this._callStreamOnce(e,...t);return}catch(e){if(!(e instanceof mr.NoRespondersError||e instanceof Ac&&e.code===Mc.NOT_FOUND)||i>=n||this.closed)throw e;await Gc(r[Math.min(i,r.length-1)])}}_callStreamOnce(e,...t){let n=this,r=!1,i=!1,a=!1,o=!1,s=null,c=``,l=``,u,d=[],f=null,p=()=>{let e=f;e&&(f=null,e({value:void 0,done:!0}))},m={push:e=>{if(!o)if(f){let t=f;f=null,t({value:e,done:!1})}else d.push(e)},end:()=>{o=!0,p()},error:e=>{s=e,o=!0,p()}},h=async()=>{if(!a&&(a=!0,n.streamHandlers.delete(c),n.statusHandlers.delete(c),u?.(),!o)){o=!0;try{await n.publish(`${l}.cancel`,{id:c})}catch{}}},g=async e=>{if(e.id!==c)return;let t=n.streamHandlers.get(e.id);if(t)switch(e.type){case`data`:t.push(e.data);break;case`end`:t.end(),await h();break;case`error`:t.error(Ac.fromJSON(e.error)),await h();break}},_=async()=>{if(!n.isConnected&&!n.isClosed&&await n.connect(),!n.nc)throw Error(`Not connected`);n.ensureMuxSubscription(),c=Uc(n.replyPrefix),l=`stream.${e}.${c}`,n.streamHandlers.set(c,m),u=await n.subscribe(l,g),n.statusHandlers.set(c,()=>{n.streamHandlers.get(c)?.error(new mr.NoRespondersError(e)),h()});let r={id:c,method:`stream`,params:{__stream:!0,__streamSubject:l,args:t}};await n.publish(e,r,{reply:`rpc.reply.${c}`})},v={async next(){if(i)return{value:void 0,done:!0};if(!r){r=!0;try{await _()}catch(e){throw await h(),e}if(i)return await h(),{value:void 0,done:!0}}if(s)throw await h(),s;if(d.length>0)return{value:d.shift(),done:!1};if(o)return await h(),{value:void 0,done:!0};let e=await new Promise((e,t)=>{if(i){e({value:void 0,done:!0});return}if(o){e({value:void 0,done:!0});return}if(s){t(s);return}f=e});if(i)return await h(),{value:void 0,done:!0};if(e.done){if(s)throw await h(),s;return await h(),{value:void 0,done:!0}}return{value:e.value,done:!1}},async return(e){return i?{value:e,done:!0}:(i=!0,p(),r&&await h(),{value:e,done:!0})},async throw(e){throw i?e:(i=!0,p(),r&&await h(),e)},[Symbol.asyncIterator](){return v},async[Symbol.asyncDispose](){await v.return()}};return v}callPullIterator(e,...t){let n=this,r=!1,i=!1,a=!1,o=!1,s=null,c=``,l=``,u=``,d=``,f,p=[],m=null,h=()=>{let e=m;e&&(m=null,e({id:c,type:`done`}))},g=()=>{o||(o=!0,s=jc(Mc.CONNECTION_CLOSED,`Connection closed`));let e=m;e&&(m=null,e(s?{id:c,type:`error`,error:s.toJSON?.()??{code:Mc.CONNECTION_CLOSED,message:`Connection closed`}}:{id:c,type:`done`}))},_=async()=>{if(!a&&(a=!0,n.pullIteratorSettles.delete(g),n.statusHandlers.delete(c),f?.(),!o)){o=!0;try{let e={id:c,type:`cancel`};await n.publish(l,e)}catch{}}},v=async()=>{if(!n.isConnected&&!n.isClosed&&await n.connect(),!n.nc)throw Error(`Not connected`);if(n.ensureMuxSubscription(),n.pullIteratorSettles.add(g),c=Uc(n.replyPrefix),l=`_rpc.iterator.${c}.request`,u=`_rpc.iterator.${c}.response`,d=`rpc.reply.${c}`,(await n.call(e,{__pullIterator:!0,__iteratorId:c,args:t}))?.iteratorId!==c)throw Error(`Failed to initialize pull iterator`);f=await n.subscribe(u,e=>{if(e.type===`error`?(s=Ac.fromJSON(e.error),o=!0):e.type===`done`&&(o=!0),m){let t=m;m=null,t(e)}else p.push(e)}),n.statusHandlers.set(c,()=>{let t=new mr.NoRespondersError(e);o=!0,s=jc(`503`,t.message);let n={type:`error`,id:c,error:s.toJSON()};if(m){let e=m;m=null,e(n)}else p.push(n)})},y={async next(){if(i)return{value:void 0,done:!0};if(!r){r=!0;try{await v()}catch(e){throw await _(),e}if(i)return await _(),{value:void 0,done:!0}}let e={id:c,type:`next`};try{await n.publish(l,e,{reply:d})}catch(e){throw await _(),e}let t=await new Promise((e,t)=>{if(i){e({id:c,type:`done`});return}p.length>0?e(p.shift()):o&&s?t(s):o?e({id:c,type:`done`}):m=e});if(i)return await _(),{value:void 0,done:!0};if(t.type===`error`)throw await _(),Ac.fromJSON(t.error);return t.type===`done`?(await _(),{value:void 0,done:!0}):{value:t.value,done:!1}},async return(e){return i?{value:e,done:!0}:(i=!0,h(),r&&await _(),{value:e,done:!0})},async throw(e){throw i?e:(i=!0,h(),r&&await _(),e)},[Symbol.asyncIterator](){return y},async[Symbol.asyncDispose](){await y.return()}};return y}callPullIteratorWithCallback(e,t,n,...r){let i=Array.isArray(n)?void 0:n,a=Array.isArray(n)?n:n.onewayMethods,o=i?.prefetch??!1,s=this,c=!1,l=!1,u=!1,d=!1,f=null,p=``,m=``,h=``,g=``,_=``,v,y,b,x=[],S=null,C=Promise.resolve(),w=!1,T=()=>{let e=S;e&&(S=null,e({id:p,type:`done`}))},E=()=>{d||(d=!0,f=jc(Mc.CONNECTION_CLOSED,`Connection closed`));let e=S;e&&(S=null,e(f?{id:p,type:`error`,error:f.toJSON?.()??{code:Mc.CONNECTION_CLOSED,message:`Connection closed`}}:{id:p,type:`done`}))},D=async()=>{if(!u&&(u=!0,s.pullIteratorSettles.delete(E),s.statusHandlers.delete(p),v?.(),b?.(),!d)){d=!0;try{let e={id:p,type:`cancel`};await s.publish(m,e)}catch{}}},O=async()=>{if(!s.isConnected&&!s.isClosed&&await s.connect(),!s.nc)throw Error(`Not connected`);s.ensureMuxSubscription(),s.pullIteratorSettles.add(E),p=Uc(s.replyPrefix),m=`_rpc.iterator.${p}.request`,h=`_rpc.iterator.${p}.response`,g=`_rpc.cb.${p}`,_=`rpc.reply.${p}`;let n=Object.keys(t).filter(e=>typeof t[e]==`function`),i=await s.subscribeEntry(g,e=>{let n=t[e.method];if(!n){console.error(`[rpc] Pull-callback: unknown method '${e.method}'`);return}C=C.then(async()=>{try{await n(...e.args??[])}catch(t){console.error(`[rpc] Pull-callback handler '${e.method}' threw:`,t)}})});v=i.unsubscribe,y=()=>i.entry.flush?.()??Promise.resolve();let o={__pullCallback:!0,__iteratorId:p,__callbackSubject:g,__callbackMethods:n,__onewayMethods:a,args:r},c;try{c=await s.call(e,o)}catch(e){throw v?.(),v=void 0,e}if(c?.iteratorId!==p)throw v?.(),v=void 0,Error(`Failed to initialize pull-callback iterator`);b=await s.subscribe(h,e=>{if(e.type===`error`?(f=Ac.fromJSON(e.error),d=!0):e.type===`done`&&(d=!0),S){let t=S;S=null,t(e)}else x.push(e)}),s.statusHandlers.set(p,()=>{let t=new mr.NoRespondersError(e);d=!0,f=jc(`503`,t.message);let n={type:`error`,id:p,error:f.toJSON()};if(S){let e=S;S=null,e(n)}else x.push(n)})},k={async next(){if(l)return{value:void 0,done:!0};if(!c){c=!0;try{await O()}catch(e){throw await D(),e}if(l)return await D(),{value:void 0,done:!0}}if(w)w=!1;else{let e={id:p,type:`next`};try{await s.publish(m,e,{reply:_})}catch(e){throw await D(),e}}let e=await new Promise((e,t)=>{if(l){e({id:p,type:`done`});return}x.length>0?e(x.shift()):d&&f?t(f):d?e({id:p,type:`done`}):S=e});if(l)return await D(),{value:void 0,done:!0};if(e.type===`error`)throw await D(),Ac.fromJSON(e.error);if(e.type===`done`)return await y?.(),await C,await D(),{value:void 0,done:!0};if(o&&!d&&!l)try{let e={id:p,type:`next`};await s.publish(m,e,{reply:_}),w=!0}catch{w=!1}return await y?.(),await C,{value:void 0,done:!1}},async return(e){return l?{value:e,done:!0}:(l=!0,T(),c&&await D(),{value:e,done:!0})},async throw(e){throw l?e:(l=!0,T(),c&&await D(),e)},[Symbol.asyncIterator](){return k},async[Symbol.asyncDispose](){await k.return()}};return k}async callWithCallback(e,t,n){if(!this.isConnected&&!this.isClosed&&await this.connect(),!this.nc)throw Error(`Not connected`);let r=Uc(this.replyPrefix),i=`rpc.cb.${r}`,a=await this.subscribe(i,async e=>{if(e.type===`data`)try{await n(e.data)}catch(e){console.error(`[rpc] Callback error:`,e)}else e.type===`error`&&console.error(`[rpc] Callback error:`,e.error)}),o={__callback:!0,__callbackSubject:i,args:t};try{await this.call(e,o)}catch(e){throw a(),e}return()=>{this.publish(`${i}.cancel`,{id:r}).catch(()=>{}),a()}}async registerHandler(e,t,n){if(!this.nc&&!n?.isolatedConnection)throw Error(`Not connected`);let r=this;n?.isolatedConnection&&(r=this.createIsolatedClient({...this.options,name:`${this.options.name}-handler-${e}`}),await r.connect(),this.isolatedClients.push(r));let i=[],a=[],o=[],s=n?.withoutDecorators?Oc(t):kc(t),c=Object.keys(s);for(let[t,l]of Object.entries(s)){let s=`rpc.${e}.${t}`,u=await r.subscribe(s,async e=>{let n={id:e.id};e.__discover===!0&&(n.__methods=c);try{if(e.params?.__stream&&e.params?.__streamSubject){let n=e.params.__streamSubject,i=e.params.args??[];qc(l,i,n,e.id,r).catch(e=>{console.error(`Stream request error for ${t}:`,e)});return}else if(e.params?.__pullIterator||Array.isArray(e.params)&&e.params[0]?.__pullIterator){let t=e.params?.__pullIterator?e.params:e.params[0],i=t.args??[],o=t.__iteratorId??e.id,s=await Xc(l,i,o,r,()=>r.pullIteratorCleanups.delete(o));r.pullIteratorCleanups.set(o,s),a.push(o),n.result={iteratorId:o};let c=`rpc.reply.${e.id}`;await r.publish(c,n)}else if(e.params?.__pullCallback||Array.isArray(e.params)&&e.params[0]?.__pullCallback){let t=e.params?.__pullCallback?e.params:e.params[0],i=t.args??[],o=t.__iteratorId??e.id,s=t.__callbackSubject,c=t.__callbackMethods??[],u=t.__onewayMethods??[],d=await Zc(l,i,o,s,c,u,r,()=>r.pullIteratorCleanups.delete(o));r.pullIteratorCleanups.set(o,d),a.push(o),n.result={iteratorId:o};let f=`rpc.reply.${e.id}`;await r.publish(f,n)}else if(e.params&&typeof e.params==`object`&&!Array.isArray(e.params)&&e.params.__callback&&e.params.__callbackSubject||Array.isArray(e.params)&&e.params.length>0&&typeof e.params[0]==`object`&&e.params[0]?.__callback){let t=Array.isArray(e.params)&&e.params[0]?.__callback?e.params[0]:e.params,i=t.__callbackSubject,a=t.args??[],s=await Qc(l,a,i,e.id,r,()=>r.callbackCleanups.delete(e.id));r.callbackCleanups.set(e.id,s),o.push(e.id),n.result={ok:!0};let c=`rpc.reply.${e.id}`;await r.publish(c,n)}else{n.result=await Jc(l,e.params);let t=`rpc.reply.${e.id}`;await r.publish(t,n)}}catch(t){n.error=Yc(t),n.error.code===Mc.METHOD_NOT_FOUND&&(n.__methods=c);try{let t=`rpc.reply.${e.id}`;await r.publish(t,n)}catch(e){if(r.isClosed)return;console.error(`Failed to send error response:`,e)}}},n?.queue?{queue:n.queue}:void 0);i.push(u)}return async()=>{for(let e of i)e();if(await Promise.allSettled(a.map(e=>{let t=r.pullIteratorCleanups.get(e);return r.pullIteratorCleanups.delete(e),t?t():Promise.resolve()})),await Promise.allSettled(o.map(e=>{let t=r.callbackCleanups.get(e);return r.callbackCleanups.delete(e),t?t():Promise.resolve()})),n?.isolatedConnection){await r.disconnect();let e=this.isolatedClients.indexOf(r);e>=0&&this.isolatedClients.splice(e,1)}}}async onRequest(e,t){if(!this.nc)throw Error(`Not connected`);let n=this.nc.subscribe(e,{callback:(n,r)=>{(async()=>{try{let e=await t(xc(r.data));if(r.reply){let t=bc(e);r.respond(t)}}catch(t){if(r.reply){let e=bc({error:t instanceof Error?t.message:`Internal error`,code:t instanceof Ac?t.code:Mc.INTERNAL_ERROR});r.respond(e)}console.error(`Error in request handler for ${e}:`,t)}})()}});return()=>{n.unsubscribe()}}async channel(e,t){let n;t?.isolatedConnection?(n=this.createIsolatedClient({...this.options,name:`${this.options.name}-channel-${e}`}),this.isolatedClients.push(n),await n.connect()):n=this;let r=new Mo(n,e);return await r.init(),t?.isolatedConnection&&(r._isolatedClient=n),r}async privateChannel(e,t,n){let r;n?.isolatedConnection?(r=this.createIsolatedClient({...this.options,name:`${this.options.name}-private-${e}`}),this.isolatedClients.push(r),await r.connect()):r=this;let i=new No(r,e,t);return await i.init(),n?.isolatedConnection&&(i._isolatedClient=r),i}createProxy(e,t){let n;t?.isolatedConnection?(n=this.createIsolatedClient({...this.options,name:`${this.options.name}-proxy-${e}`}),this.isolatedClients.push(n)):n=this;let r=Rc(n,e);return t?.isolatedConnection?(r._isolatedClient=n,{proxy:r,close:async()=>{await n.disconnect();let e=this.isolatedClients.indexOf(n);e>=0&&this.isolatedClients.splice(e,1)}}):r}async createServiceProxy(e,t){let n;t?.isolatedConnection?(n=this.createIsolatedClient({...this.options,name:`${this.options.name}-service-${e}`}),this.isolatedClients.push(n),await n.connect()):n=this;let r=n.service.monitor(),i=[];for await(let t of await r.info(e))i.push(t);if(i.length===0){if(t?.isolatedConnection){await n.disconnect();let e=this.isolatedClients.indexOf(n);e>=0&&this.isolatedClients.splice(e,1)}throw Error(`No services found with name: ${e}`)}let a=t?.preferredId?i.find(e=>e.id===t.preferredId)??i[0]:i[0],o=zc(n,a,t?.timeout);return t?.isolatedConnection?(o._isolatedClient=n,{proxy:o,close:async()=>{await n.disconnect();let e=this.isolatedClients.indexOf(n);e>=0&&this.isolatedClients.splice(e,1)}}):o}};function ll(e,t){return t?t.aborted?(e.then(e=>ul(e)).catch(()=>{}),Promise.reject(new DOMException(`Aborted`,`AbortError`))):new Promise((n,r)=>{let i=!1,a=()=>{i||(i=!0,e.then(e=>ul(e)).catch(()=>{}),r(new DOMException(`Aborted`,`AbortError`)))};t.addEventListener(`abort`,a,{once:!0}),e.then(e=>{if(i){ul(e);return}i=!0,t.removeEventListener(`abort`,a),n(e)},e=>{i||(i=!0,t.removeEventListener(`abort`,a),r(e))})}):e}function ul(e){let t=e;try{typeof t.abortClose==`function`?t.abortClose():e.close().catch(()=>{})}catch{}}var dl={id:`nats`,kind:`persistent`,phaseGating:!0,graceMs:4e3};function fl(){let e=globalThis.crypto;if(e?.randomUUID)return e.randomUUID();if(e?.getRandomValues){let t=new Uint8Array(16);return e.getRandomValues(t),Array.from(t,e=>e.toString(16).padStart(2,`0`)).join(``)}return`${Date.now()}-${Math.random().toString(36).slice(2)}-${Math.random().toString(36).slice(2)}`}function pl(e={}){let t={...dl,...e.spec},n=e.proxyPath??`/api/proxy`,r=e.clientName??`@camera.ui/transport/nats`,i=e.natsUser??`secret`,a=e.natsPassword??`secret`,o=e.reconnectTimeWait??1e3,s=e.reconnectionDelayMax??5e3,c=e.reconnectionRandomizationFactor??.5,l=e.timeout??1e4,u=e.connectTimeout??5e3,d=e.pingInterval??25e3,f=e.pingTimeout??2e4,p=e.maxPingOut??1,m=e.logger,h=new an,g=new Set,_=null,v=null,y={up:!1},b=null,x=!1,S=null,C=0,w=null;function T(e){let t=new URL(e.endpoint.url),r=t.protocol===`https:`?`wss:`:`ws:`,i=t.port||(t.protocol===`https:`?`443`:`80`),a=t.pathname.replace(/\/$/,``),o=new URLSearchParams({token:e.tokens.access});return e.tokens.proxySession&&o.set(`session`,e.tokens.proxySession),S&&o.set(`connId`,S),[`${r}//${t.hostname}:${i}${a}${n}?${o.toString()}`]}function E(){let e=y.up?_:null;for(let t of[...g])try{t(e)}catch{}}function D(){y.up||(y={up:!0},m?.debug(`markUp`),h.emit(`up`,void 0))}function O(e){!y.up&&y.lastError===e||(y={up:!1,lastError:e},m?.debug(`markDown (${e})`),h.emit(`down`,{reason:e}))}function k(){b?.abort(),b=null}function A(e){k();let t=new AbortController;b=t,(async()=>{let n=e.status();if(n)for await(let e of n){if(t.signal.aborted)break;switch(m?.debug(`status: ${e.type}${`server`in e&&e.server?` server=${String(e.server)}`:``}`),e.type){case`reconnect`:D(),E();break;case`disconnect`:O(`disconnect`),E();break;case`staleConnection`:O(`staleConnection`),E();break;case`error`:j(e);break}}})().catch(()=>{})}function j(e){let t=ml(e.data),n=t.toLowerCase();if(n.includes(`auth`)||n.includes(`401`)||n.includes(`forbidden`)||n.includes(`403`)){h.emit(`auth-error`,{message:t});return}O(t)}async function M(e,t){m?.debug(`rebuildClient start (epoch=${t})`);let n=Date.now();if(k(),w?.abort(),_){try{_.abortClose()}catch{}_=null,E()}S=fl();let h=ol({servers:T(e),name:r,connId:S,auth:{user:i,password:a},reconnect:!0,maxReconnectAttempts:-1,reconnectTimeWait:o,reconnectionDelayMax:s,reconnectionRandomizationFactor:c,timeout:l,connectTimeout:u,pingInterval:d,pingTimeout:f,maxPingOut:p,ignoreAuthErrorAbort:!0}),g=new AbortController;w=g;try{await h.connect({signal:g.signal})}catch(e){try{h.abortClose()}catch{}if(x||t!==C)return;let r=e instanceof Error?e.message:String(e);throw m?.debug(`rebuildClient connect FAILED after ${Date.now()-n}ms: ${r}`),O(r),e}finally{w===g&&(w=null)}if(x||t!==C){try{h.abortClose()}catch{}return}_=h,m?.debug(`rebuildClient connected in ${Date.now()-n}ms`),D(),E(),A(h)}async function N(e){if(x)throw Error(`nats-transport disposed`);if(nn(v,e))return;let t=++C,n=rn(v,e);if(v=e,!e){if(k(),w?.abort(),w=null,_){try{_.abortClose()}catch{}_=null,E()}O(`detached`);return}if(n||!_){try{await M(e,t)}catch(n){throw t===C&&v===e&&(v=null),n}return}let r=T(e);_.setServers(r)}function P(){return y.up&&_?.isStale?{up:!1,lastError:`staleConnection`}:y}function ee(e,t){return h.on(e,t)}async function F(){if(x=!0,C++,k(),w?.abort(),w=null,_){try{_.abortClose()}catch{}_=null,E()}g.clear(),y={up:!1},h.clear()}function I(){return y.up?_:null}function te(e){return g.add(e),e(y.up?_:null),()=>g.delete(e)}async function ne(e=5e3){if(!_)throw Error(`nats-transport: no client`);let t=Date.now();try{await _.flush(e),m?.debug(`probeAlive OK in ${Date.now()-t}ms`)}catch(e){throw m?.debug(`probeAlive FAILED after ${Date.now()-t}ms: ${e instanceof Error?e.message:String(e)}`),e}}async function L(){if(!_){m?.debug(`forceReconnect: no client`);return}m?.debug(`forceReconnect: issuing (up=${y.up} stale=${_.isStale})`);let e=Date.now();await _.forceReconnect(),m?.debug(`forceReconnect: returned after ${Date.now()-e}ms (up=${y.up})`)}return{spec:t,apply:N,health:P,on:ee,dispose:F,getClient:I,subscribeClient:te,probeAlive:ne,forceReconnect:L}}function ml(e){if(e instanceof Error)return e.message;if(typeof e==`string`)return e;try{return JSON.stringify(e)}catch{return String(e)}}var hl={id:`socketio`,kind:`persistent`,phaseGating:!0,graceMs:4e3};function gl(e={}){let t={...hl,...e.spec},n=e.path??`/api/socket.io`,r=e.mainNamespace??`/camera.ui`,i=e.reconnection??!0,a=e.reconnectionDelay??1e3,o=e.reconnectionDelayMax??5e3,s=e.timeout??2e4,c=e.logger,l=new an,u=new Map,d=null,f=null,p={up:!1},m=!1;function h(e){let t={token:`Bearer ${e.tokens.access}`};return e.tokens.proxySession&&(t.session=e.tokens.proxySession),t}function _(e){let t={};return e.tokens.proxySession&&(t.session=e.tokens.proxySession),t}function v(){p.up||(p={up:!0},c?.debug(`markUp`),l.emit(`up`,void 0))}function y(e){!p.up&&p.lastError===e||(p={up:!1,lastError:e},c?.debug(`markDown (${e})`),l.emit(`down`,{reason:e}))}function b(e){let t=e.toLowerCase();return t.includes(`auth`)||t.includes(`unauthorized`)}function x(e){let t=!1;e.on(`unauthenticated`,()=>{let n=f?h(f):null,r=e.auth?.token;n&&r!==n.token?(e.auth=n,t=!0):l.emit(`auth-error`,{message:`unauthenticated`})}),e.on(`disconnect`,()=>{t&&(t=!1,e.connect())})}function S(e){e.on(`connect`,()=>v()),e.on(`disconnect`,e=>y(e)),e.on(`connect_error`,e=>{let t=e?.message??`connect_error`;if(c?.debug(`connect_error (main): ${t}`),b(t)){l.emit(`auth-error`,{message:t});return}y(t)}),x(e)}function C(e){e.on(`connect_error`,e=>{let t=e?.message??`connect_error`;b(t)&&l.emit(`auth-error`,{message:t})}),x(e)}function w(e){return new URL(e.endpoint.url).origin}function T(e){return`${new URL(e.endpoint.url).pathname.replace(/\/$/,``)}${n}`}function E(e,t){let n=ie(`${w(t)}${e}`,{path:T(t),auth:h(t),query:_(t),reconnection:i,reconnectionDelay:a,reconnectionDelayMax:o,timeout:s,rejectUnauthorized:!1,transports:[`websocket`]});return u.set(e,n),n}function D(e){O(),d=new g(w(e),{path:T(e),autoConnect:!1,reconnection:i,reconnectionDelay:a,reconnectionDelayMax:o,timeout:s,rejectUnauthorized:!1,transports:[`websocket`]}),S(E(r,e))}function O(){for(let e of u.values())e.removeAllListeners(),e.disconnect();u.clear(),d&&=(d._close(),null)}function k(e){let t=h(e);for(let e of u.values())e.auth=t,e.connected||e.connect()}async function A(e){if(m)throw Error(`socketio-transport disposed`);if(nn(f,e))return;let t=rn(f,e);if(f=e,!e){O(),y(`detached`);return}if(t||!d){D(e);return}k(e)}function j(){return p}function M(e,t){return l.on(e,t)}async function N(){m=!0,O(),f=null,p={up:!1},l.clear()}function P(e=r){return u.get(e)??null}function ee(e){if(!f)return null;let t=u.get(e);return t||(t=E(e,f),C(t)),t}function F(){if(!f)return;let e=h(f),t=0;for(let n of u.values())n.connected||(n.auth=e,n.connect(),t++);c?.debug(`reviveDeadSockets: ${t}/${u.size} reconnecting`)}return{get spec(){return t},get manager(){return d},apply:A,health:j,on:M,dispose:N,socket:P,ensureSocket:ee,reviveDeadSockets:F}}var _l={id:`ws`,kind:`per-resource`,phaseGating:!1},vl=4e3,yl=4001,bl=4002;function xl(e={}){let t={..._l,...e.spec},n=e.tokenParam??`token`,r=e.sessionParam??`session`,i=e.webSocketCtor??(typeof WebSocket<`u`?WebSocket:void 0),a=e.logger,o=new an,s=new Set,c=new WeakSet,l=null,u={up:!1},d=!1;function f(){if(!i)throw Error(`ws-transport: no WebSocket constructor available; pass webSocketCtor in non-browser environments`);return i}function p(e,t){let i=new URL(e.endpoint.url),a=i.protocol===`https:`?`wss:`:`ws:`,o=i.port||(i.protocol===`https:`?`443`:`80`),s=i.pathname.replace(/\/$/,``),c=new URLSearchParams;for(let[e,n]of Object.entries(t.query??{}))n!=null&&n!==``&&c.set(e,n);return c.set(n,e.tokens.access),e.tokens.proxySession&&c.set(r,e.tokens.proxySession),`${a}//${i.hostname}:${o}${s}${t.path}?${c.toString()}`}function m(e){if(e.code===1008||e.code===4401)return!0;if(!e.reason)return!1;let t=e.reason.toLowerCase();return t.includes(`unauthorized`)||t.includes(`forbidden`)||t.includes(`401`)||t.includes(`403`)}function h(e,t){t.onopen=()=>{if(!(e.disposed||e.ws!==t)){a?.debug(`open ${e.spec.path}`),u.up||(u={up:!0},o.emit(`up`,void 0));for(let t of[...e.listeners.open])t()}},t.onclose=n=>{let r=e.ws===t;if(r&&(e.ws=null,e.url=null),c.has(t)||(c.add(t),!r))return;a?.debug(`close ${e.spec.path} code=${n.code} clean=${n.wasClean}${n.reason?` reason=${n.reason}`:``}`),m(n)&&o.emit(`auth-error`,{message:n.reason||`ws close code ${n.code}`});let i={code:n.code,reason:n.reason,wasClean:n.wasClean};for(let t of[...e.listeners.close])t(i)},t.onmessage=n=>{if(!(e.disposed||e.ws!==t))for(let t of[...e.listeners.message])t(n)},t.onerror=n=>{if(!(e.disposed||e.ws!==t))for(let t of[...e.listeners.error])t(n)}}function g(e,t,n){let r=e.ws;if(!r)return;let i=f();if(r.readyState===i.OPEN||r.readyState===i.CONNECTING){try{r.close(t,n)}catch{}return}if(e.ws===r&&(e.ws=null,e.url=null),c.has(r))return;c.add(r);let a={code:t,reason:n,wasClean:!1};for(let t of[...e.listeners.close])t(a)}function _(e){if(e.disposed||!l)return;let t=p(l,e.spec),n=new(f())(t,e.spec.protocols);e.spec.binaryType&&(n.binaryType=e.spec.binaryType),e.ws=n,e.url=t,h(e,n)}function v(e,t){let n=[...s];a?.debug(`recycleAll (${t}) handles=${n.length}`);for(let r of n)g(r,e,t);if(u.up&&(u={up:!1,lastError:t},o.emit(`down`,{reason:t})),l)for(let e of s)e.disposed||_(e)}async function y(e){if(d)throw Error(`ws-transport disposed`);if(nn(l,e))return;let t=rn(l,e);if(l=e,!e){let e=[...s];for(let t of e)g(t,yl,`detached`);u={up:!1},o.emit(`down`,{reason:`detached`});return}t&&v(vl,`endpoint-changed`)}function b(){return u}function x(e,t){return o.on(e,t)}async function S(){d=!0;let e=[...s];for(let t of e)t.disposed=!0,t.listeners.open.clear(),t.listeners.close.clear(),t.listeners.message.clear(),t.listeners.error.clear(),g(t,bl,`disposed`);s.clear(),l=null,u={up:!1},o.clear()}function C(e){if(d)throw Error(`ws-transport disposed`);let t={api:void 0,spec:e,listeners:{open:new Set,close:new Set,message:new Set,error:new Set},ws:null,url:null,disposed:!1};function n(e){if(t.disposed)throw Error(`ws-handle disposed`);let n=t.ws;if(!n)throw Error(`ws-handle: no active socket`);if(n.readyState!==i.OPEN)throw Error(`ws-handle: socket not open`);n.send(e)}function r(e,n){g(t,e??1e3,n??``)}function a(e,n){let r=t.listeners[e];return r.add(n),()=>{r.delete(n)}}function o(){t.disposed||(t.disposed=!0,t.listeners.open.clear(),t.listeners.close.clear(),t.listeners.message.clear(),t.listeners.error.clear(),g(t,bl,`disposed`),s.delete(t))}return t.api={get readyState(){return t.ws?.readyState??i?.CLOSED??3},get url(){return t.url},send:n,close:r,on:a,dispose:o},s.add(t),l&&_(t),t.api}return{get spec(){return t},get handleCount(){return s.size},apply:y,health:b,on:x,dispose:S,open:C}}function Sl(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function Cl(e){let t=e.url??``,n=e.baseURL??``;return n&&!Sl(t)?`${n.replace(/\/+$/,``)}/${t.replace(/^\/+/,``)}`:t}function wl(e){let t;try{t=new URL(e).hostname}catch{return!1}return!t||t===`localhost`||t.endsWith(`.local`)||t.includes(`:`)||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(t)?!1:t.includes(`.`)}function Tl(e){return!e.withCredentials&&wl(Cl(e))}function El(e){return async t=>{Ol(t.signal);let n=Al(t.headers);e.extraHeaders&&Object.assign(n,e.extraHeaders);let r=typeof t.timeout==`number`&&t.timeout>0?t.timeout:void 0,i=e.request({url:Cl(t),method:(t.method??`get`).toUpperCase(),headers:n,params:jl(t.params),data:Ml(t),responseType:Nl(t.responseType),connectTimeout:r,readTimeout:r}),a;try{a=await kl(i,t.signal)}catch(e){throw e instanceof se?e:new He(e instanceof Error?e.message:`Network Error`,He.ERR_NETWORK,t,i)}let o={data:a.data,status:a.status,statusText:``,headers:x.from(a.headers??{}),config:t,request:i};if(!t.validateStatus||t.validateStatus(a.status))return o;throw new He(`Request failed with status code ${a.status}`,a.status>=500?He.ERR_BAD_RESPONSE:He.ERR_BAD_REQUEST,t,i,o)}}function Dl(e,t){if(!t.enabled)return;let n=oe.getAdapter(e.defaults.adapter??oe.defaults.adapter),r=El(t);e.defaults.adapter=e=>Tl(e)?r(e):n(e)}function Ol(e){if(e?.aborted)throw new se(`canceled`)}function kl(e,t){return!t||typeof t.addEventListener!=`function`?e:t.aborted?Promise.reject(new se(`canceled`)):new Promise((n,r)=>{let i=()=>r(new se(`canceled`));t.addEventListener(`abort`,i,{once:!0});let a=()=>t.removeEventListener?.(`abort`,i);e.then(e=>{a(),n(e)},e=>{a(),r(e)})})}function Al(e){let t={};if(!e)return t;let n=x.from(e).toJSON();for(let[e,r]of Object.entries(n))r!=null&&(t[e]=Array.isArray(r)?r.join(`, `):String(r));return t}function jl(e){if(!e||typeof e!=`object`)return;let t={};for(let[n,r]of Object.entries(e))r!=null&&(t[n]=String(r));return t}function Ml(e){let t=e.data;if(t!=null){if(typeof t!=`string`)return t;if(String(x.from(e.headers).get(`Content-Type`)??``).includes(`application/json`))try{return JSON.parse(t)}catch{}return t}}function Nl(e){switch(e){case`blob`:return`blob`;case`arraybuffer`:return`arraybuffer`;default:return`text`}}function Pl(e={}){function t(e){return typeof e==`function`}let n=t(e)?{mounted:e,updated:e}:e,{mounted:r,unmounted:i}=n;if(!t(r))return e;let a=new WeakMap;return{...n,mounted(e,t,n,i){let o=a.get(e)??ke();a.set(e,o),o.run(()=>{r?.(e,t,n,i)})},unmounted(e,n,r,o){var s;(s=a.get(e))==null||s.stop(),a.delete(e),t(i)&&i(e,n,r,o)}}}function Fl(e,t){return de()?(Xe(e,t),!0):!1}var Il=new WeakMap,Ll=(...e)=>{let t=e[0],n=it()?.proxy??de();if(n==null&&!tt())throw Error(`injectLocal must be called in setup`);return n&&Il.has(n)&&t in Il.get(n)?Il.get(n)[t]:F(...e)},Rl=typeof window<`u`&&typeof document<`u`;typeof WorkerGlobalScope<`u`&&globalThis instanceof WorkerGlobalScope;var zl=e=>e!=null,Bl=Object.prototype.toString,Vl=e=>Bl.call(e)===`[object Object]`,Hl=()=>{},Ul=Wl();function Wl(){var e,t;return Rl&&!!(!((e=window)==null||(e=e.navigator)==null)&&e.userAgent)&&(/iP(?:ad|hone|od)/.test(window.navigator.userAgent)||((t=window)==null||(t=t.navigator)==null?void 0:t.maxTouchPoints)>2&&/iPad|Macintosh/.test(window?.navigator.userAgent))}function Gl(...e){if(e.length!==1)return $e(...e);let t=e[0];return typeof t==`function`?Se(We(()=>({get:t,set:Hl}))):K(t)}function Kl(e,t){function n(...n){return new Promise((r,i)=>{Promise.resolve(e(()=>t.apply(this,n),{fn:t,thisArg:this,args:n})).then(r).catch(i)})}return n}var ql=e=>e();function Jl(e,t={}){let n,r,i=Hl,a=e=>{clearTimeout(e),i(),i=Hl},o;return s=>{let c=B(e),l=B(t.maxWait);return n&&a(n),c<=0||l!==void 0&&l<=0?(r&&=(a(r),void 0),Promise.resolve(s())):new Promise((e,u)=>{i=t.rejectOnCancel?u:e,o=s,l&&!r&&(r=setTimeout(()=>{n&&a(n),r=void 0,e(o())},l)),n=setTimeout(()=>{r&&a(r),r=void 0,e(s())},c)})}}function Yl(...e){let t=0,n,r=!0,i=Hl,a,o,s,c,l;!ge(e[0])&&typeof e[0]==`object`?{delay:o,trailing:s=!0,leading:c=!0,rejectOnCancel:l=!1}=e[0]:[o,s=!0,c=!0,l=!1]=e;let u=()=>{n&&(clearTimeout(n),n=void 0,i(),i=Hl)};return e=>{let d=B(o),f=Date.now()-t,p=()=>a=e();return u(),d<=0?(t=Date.now(),p()):(f>d?(t=Date.now(),(c||!r)&&p()):s&&(a=new Promise((e,a)=>{i=l?a:e,n=setTimeout(()=>{t=Date.now(),r=!0,e(p()),u()},Math.max(0,d-f))})),!c&&!n&&(n=setTimeout(()=>r=!0,d)),r=!1,a)}}function Xl(e=ql,t={}){let{initialState:n=`active`}=t,r=Gl(n===`active`);function i(){r.value=!1}function a(){r.value=!0}return{isActive:Ee(r),pause:i,resume:a,eventFilter:(...t)=>{r.value&&e(...t)}}}function Zl(e){return e.endsWith(`rem`)?Number.parseFloat(e)*16:Number.parseFloat(e)}function Ql(e){return Array.isArray(e)?e:[e]}function $l(e){let t=Object.create(null);return(n=>t[n]||(t[n]=e(n)))}var eu=/-(\w)/g,tu=$l(e=>e.replace(eu,(e,t)=>t?t.toUpperCase():``));function nu(e){return e||it()}function ru(e){if(!Rl)return e;let t=0,n,r,i=()=>{--t,r&&t<=0&&(r.stop(),n=void 0,r=void 0)};return((...a)=>(t+=1,r||(r=ke(!0),n=r.run(()=>e(...a))),Fl(i),n))}function iu(e,t,{enumerable:n=!1,unwrap:r=!0}={}){for(let[i,a]of Object.entries(t))i!==`value`&&(ge(a)&&r?Object.defineProperty(e,i,{get(){return a.value},set(e){a.value=e},enumerable:n}):Object.defineProperty(e,i,{value:a,enumerable:n}));return e}function au(e,t){if(typeof Symbol<`u`){let n={...e};return Object.defineProperty(n,Symbol.iterator,{enumerable:!1,value(){let e=0;return{next:()=>({value:t[e++],done:e>t.length})}}}),n}else return Object.assign([...t],e)}function ou(e){return ge(e)?ye(new Proxy({},{get(t,n,r){return J(Reflect.get(e.value,n,r))},set(t,n,r){return ge(e.value[n])&&!ge(r)?e.value[n].value=r:e.value[n]=r,!0},deleteProperty(t,n){return Reflect.deleteProperty(e.value,n)},has(t,n){return Reflect.has(e.value,n)},ownKeys(){return Object.keys(e.value)},getOwnPropertyDescriptor(){return{enumerable:!0,configurable:!0}}})):ye(e)}function su(e){return ou(W(e))}function cu(e,...t){let n=t.flat(),r=n[0];return su(()=>Object.fromEntries(typeof r==`function`?Object.entries(ot(e)).filter(([e,t])=>!r(B(t),e)):Object.entries(ot(e)).filter(e=>!n.includes(e[0]))))}function lu(e,t=200,n={}){return Kl(Jl(t,n),e)}function uu(e,t=200,n=!1,r=!0,i=!1){return Kl(Yl(t,n,r,i),e)}function du(e,t={}){let n=e,r,i,a=We((e,t)=>(r=e,i=t,{get(){return o()},set(e){s(e)}}));function o(e=!0){return e&&r(),n}function s(e,r=!0){var a;if(e===n)return;let o=n;t.onBeforeChange?.call(t,e,o)!==!1&&(n=e,(a=t.onChanged)==null||a.call(t,e,o),r&&i())}return iu(a,{get:o,set:s,untrackedGet:()=>o(!1),silentSet:e=>s(e,!1),peek:()=>o(!1),lay:e=>s(e,!1)},{enumerable:!0})}function fu(e,t,n={}){let{eventFilter:r=ql,...i}=n;return A(e,Kl(r,t),i)}function pu(e,t,n={}){let{eventFilter:r,initialState:i=`active`,...a}=n,{eventFilter:o,pause:s,resume:c,isActive:l}=Xl(r,{initialState:i});return{stop:fu(e,t,{...a,eventFilter:o}),pause:s,resume:c,isActive:l}}function mu(e,t={}){if(!ge(e))return ot(e);let n=Array.isArray(e.value)?Array.from({length:e.value.length}):{};for(let r in e.value)n[r]=We(()=>({get(){return e.value[r]},set(n){if(B(t.replaceRef)??!0)if(Array.isArray(e.value)){let t=[...e.value];t[r]=n,e.value=t}else{let t={...e.value,[r]:n};Object.setPrototypeOf(t,Object.getPrototypeOf(e.value)),e.value=t}else e.value[r]=n}}));return n}function hu(e,t=!0,n){nu(n)?y(e,n):t?e():s(e)}function gu(e,t){nu(t)&&C(e,t)}var _u=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[T\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/i,vu=/[YMDHhms]o|\[([^\]]+)\]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a{1,2}|A{1,2}|m{1,2}|s{1,2}|Z{1,2}|z{1,4}|SSS/g;function yu(e,t,n,r){let i=e<12?`AM`:`PM`;return r&&(i=i.split(``).reduce((e,t)=>e+=`${t}.`,``)),n?i.toLowerCase():i}function bu(e){let t=[`th`,`st`,`nd`,`rd`],n=e%100;return e+(t[(n-20)%10]||t[n]||t[0])}function xu(e,t,n={}){let r=e.getFullYear(),i=e.getMonth(),a=e.getDate(),o=e.getHours(),s=e.getMinutes(),c=e.getSeconds(),l=e.getMilliseconds(),u=e.getDay(),d=n.customMeridiem??yu,f=e=>e.split(` `)[1]??``,p={Yo:()=>bu(r),YY:()=>String(r).slice(-2),YYYY:()=>r,M:()=>i+1,Mo:()=>bu(i+1),MM:()=>`${i+1}`.padStart(2,`0`),MMM:()=>e.toLocaleDateString(B(n.locales),{month:`short`}),MMMM:()=>e.toLocaleDateString(B(n.locales),{month:`long`}),D:()=>String(a),Do:()=>bu(a),DD:()=>`${a}`.padStart(2,`0`),H:()=>String(o),Ho:()=>bu(o),HH:()=>`${o}`.padStart(2,`0`),h:()=>`${o%12||12}`.padStart(1,`0`),ho:()=>bu(o%12||12),hh:()=>`${o%12||12}`.padStart(2,`0`),m:()=>String(s),mo:()=>bu(s),mm:()=>`${s}`.padStart(2,`0`),s:()=>String(c),so:()=>bu(c),ss:()=>`${c}`.padStart(2,`0`),SSS:()=>`${l}`.padStart(3,`0`),d:()=>u,dd:()=>e.toLocaleDateString(B(n.locales),{weekday:`narrow`}),ddd:()=>e.toLocaleDateString(B(n.locales),{weekday:`short`}),dddd:()=>e.toLocaleDateString(B(n.locales),{weekday:`long`}),A:()=>d(o,s),AA:()=>d(o,s,!1,!0),a:()=>d(o,s,!0),aa:()=>d(o,s,!0,!0),z:()=>f(e.toLocaleDateString(B(n.locales),{timeZoneName:`shortOffset`})),zz:()=>f(e.toLocaleDateString(B(n.locales),{timeZoneName:`shortOffset`})),zzz:()=>f(e.toLocaleDateString(B(n.locales),{timeZoneName:`shortOffset`})),zzzz:()=>f(e.toLocaleDateString(B(n.locales),{timeZoneName:`longOffset`}))};return t.replace(vu,(e,t)=>t??p[e]?.call(p)??e)}function Su(e){if(e===null)return new Date(NaN);if(e===void 0)return new Date;if(e instanceof Date)return new Date(e);if(typeof e==`string`&&!/Z$/i.test(e)){let t=e.match(_u);if(t){let e=t[2]-1||0,n=(t[7]||`0`).substring(0,3);return new Date(t[1],e,t[3]||1,t[4]||0,t[5]||0,t[6]||0,n)}}return new Date(e)}function Cu(e,t=`HH:mm:ss`,n={}){return W(()=>xu(Su(B(e)),B(t),n))}function wu(e,t=1e3,n={}){let{immediate:r=!0,immediateCallback:i=!1}=n,a=null,o=H(!1);function s(){a&&=(clearInterval(a),null)}function c(){o.value=!1,s()}function l(){let n=B(t);n<=0||(o.value=!0,i&&e(),s(),o.value&&(a=setInterval(e,n)))}return r&&Rl&&l(),(ge(t)||typeof t==`function`)&&Fl(A(t,()=>{o.value&&Rl&&l()})),Fl(c),{isActive:Ee(o),pause:c,resume:l}}function Tu(e,t,n={}){let{immediate:r=!0,immediateCallback:i=!1}=n,a=H(!1),o;function s(){o&&=(clearTimeout(o),void 0)}function c(){a.value=!1,s()}function l(...n){i&&e(),s(),a.value=!0,o=setTimeout(()=>{a.value=!1,o=void 0,e(...n)},B(t))}return r&&(a.value=!0,Rl&&l()),Fl(c),{isPending:Ee(a),start:l,stop:c}}function Eu(e,t,n={}){let{debounce:r=0,maxWait:i=void 0,...a}=n;return fu(e,t,{...a,eventFilter:Jl(r,{maxWait:i})})}function Du(e,t,n){return A(e,t,{...n,immediate:!0})}function Ou(e,t,n){return A(e,t,{...n,once:!0})}function ku(e,t,n={}){let{throttle:r=0,trailing:i=!0,leading:a=!0,...o}=n;return fu(e,t,{...o,eventFilter:Yl(r,i,a)})}function Au(e,t,n){let r=A(e,(e,i,a)=>{e&&(n?.once&&s(()=>r()),t(e,i,a))},{...n,once:!1});return r}function ju(e,t,n){let r;r=ge(n)?{evaluating:n}:n||{};let{lazy:i=!1,flush:a=`sync`,evaluating:s=void 0,shallow:c=!0,onError:l=globalThis.reportError??Hl}=r,u=H(!i),d=c?H(t):K(t),f=0;return o(async t=>{if(!u.value)return;f++;let n=f,r=!1;s&&Promise.resolve().then(()=>{s.value=!0});try{let i=await e(e=>{t(()=>{s&&(s.value=!1),r||e()})});n===f&&(d.value=i)}catch(e){l(e)}finally{s&&n===f&&(s.value=!1),r=!0}},{flush:a}),i?W(()=>(u.value=!0,d.value)):d}function Mu(e={}){let{inheritAttrs:t=!0,name:n=`ReusableTemplate`}=e,r=H(),i=pe({name:`${n}.define`,setup(e,{slots:t}){return()=>{r.value=t.default}}}),a=pe({inheritAttrs:t,name:`${n}.reuse`,props:e.props,setup(n,{attrs:i,slots:a}){return()=>{if(!r.value)throw Error(`[VueUse] Failed to find the definition of reusable template`);let o=r.value?.call(r,{...e.props==null?Nu(i):n,$slots:a});return t&&o?.length===1?o[0]:o}}});return au({define:i,reuse:a},[i,a])}function Nu(e){let t={};for(let n in e)t[tu(n)]=e[n];return t}var Pu=Rl?window:void 0;Rl&&window.document,Rl&&window.navigator,Rl&&window.location;function Fu(e){let t=B(e);return t?.$el??t}function Iu(...e){let t=(e,t,n,r)=>(e.addEventListener(t,n,r),()=>e.removeEventListener(t,n,r)),n=W(()=>{let t=Ql(B(e[0])).filter(e=>e!=null);return t.every(e=>typeof e!=`string`)?t:void 0});return Du(()=>[n.value?.map(e=>Fu(e))??[Pu].filter(e=>e!=null),Ql(B(n.value?e[1]:e[0])),Ql(J(n.value?e[2]:e[1])),B(n.value?e[3]:e[2])],([e,n,r,i],a,o)=>{if(!e?.length||!n?.length||!r?.length)return;let s=Vl(i)?{...i}:i,c=e.flatMap(e=>n.flatMap(n=>r.map(r=>t(e,n,r,s))));o(()=>{c.forEach(e=>e())})},{flush:`post`})}var Lu=!1;function Ru(e,t,n={}){let{window:r=Pu,ignore:i=[],capture:a=!0,detectIframe:o=!1,controls:s=!1}=n;if(!r)return s?{stop:Hl,cancel:Hl,trigger:Hl}:Hl;if(Ul&&!Lu){Lu=!0;let e={passive:!0};Array.from(r.document.body.children).forEach(t=>t.addEventListener(`click`,Hl,e)),r.document.documentElement.addEventListener(`click`,Hl,e)}let c=!0,l=e=>B(i).some(t=>{if(typeof t==`string`)return Array.from(r.document.querySelectorAll(t)).some(t=>t===e.target||e.composedPath().includes(t));{let n=Fu(t);return n&&(e.target===n||e.composedPath().includes(n))}});function u(e){let t=B(e);return t&&t.$.subTree.shapeFlag===16}function d(e,t){let n=B(e),r=n.$.subTree&&n.$.subTree.children;return r==null||!Array.isArray(r)?!1:r.some(e=>e.el===t.target||t.composedPath().includes(e.el))}let f=n=>{let r=Fu(e);if(n.target!=null&&!(!(r instanceof Element)&&u(e)&&d(e,n))&&!(!r||r===n.target||n.composedPath().includes(r))){if(`detail`in n&&n.detail===0&&(c=!l(n)),!c){c=!0;return}t(n)}},p=!1,m=[Iu(r,`click`,e=>{p||(p=!0,setTimeout(()=>{p=!1},0),f(e))},{passive:!0,capture:a}),Iu(r,`pointerdown`,t=>{let n=Fu(e);c=!l(t)&&!!(n&&!t.composedPath().includes(n))},{passive:!0}),o&&Iu(r,`blur`,n=>{setTimeout(()=>{let i=Fu(e),a=r.document.activeElement;for(;a?.shadowRoot;)a=a.shadowRoot.activeElement;a?.tagName===`IFRAME`&&!i?.contains(r.document.activeElement)&&t(n)},0)},{passive:!0})].filter(Boolean),h=()=>m.forEach(e=>e());return s?{stop:h,cancel:()=>{c=!1},trigger:e=>{c=!0,f(e),c=!1}}:h}function zu(){let e=H(!1),t=it();return t&&y(()=>{e.value=!0},t),e}function Bu(e){let t=zu();return W(()=>(t.value,!!e()))}function Vu(e,t,n={}){let{window:r=Pu,...i}=n,a,o=Bu(()=>r&&`MutationObserver`in r),s=()=>{a&&=(a.disconnect(),void 0)},c=A(W(()=>{let t=Ql(B(e)).map(Fu).filter(zl);return new Set(t)}),e=>{s(),o.value&&e.size&&(a=new MutationObserver(t),e.forEach(e=>a.observe(e,i)))},{immediate:!0,flush:`post`}),l=()=>a?.takeRecords(),u=()=>{c(),s()};return Fl(u),{isSupported:o,stop:u,takeRecords:l}}function Hu(e,t,n={}){let{window:r=Pu,document:i=r?.document,flush:a=`sync`}=n;if(!r||!i)return Hl;let s,c=e=>{s?.(),s=e},l=o(()=>{let n=Fu(e);if(n){let{stop:e}=Vu(i,e=>{e.map(e=>[...e.removedNodes]).flat().some(e=>e===n||e.contains(n))&&t(e)},{window:r,childList:!0,subtree:!0});c(e)}},{flush:a}),u=()=>{l(),c()};return Fl(u),u}function Uu(e){return typeof e==`function`?e:typeof e==`string`?t=>t.key===e:Array.isArray(e)?t=>e.includes(t.key):()=>!0}function Wu(...e){let t,n,r={};e.length===3?(t=e[0],n=e[1],r=e[2]):e.length===2?typeof e[1]==`object`?(t=!0,n=e[0],r=e[1]):(t=e[0],n=e[1]):(t=!0,n=e[0]);let{target:i=Pu,eventName:a=`keydown`,passive:o=!1,dedupe:s=!1}=r,c=Uu(t);return Iu(i,a,e=>{e.repeat&&B(s)||c(e)&&n(e)},o)}var Gu=500,Ku=10;function qu(e,t,n){var r,i;let a=W(()=>Fu(e)),o,s,c,l=!1;function u(){o&&=(clearTimeout(o),void 0),s=void 0,c=void 0,l=!1}function d(e){let t=n?.delay;return typeof t==`function`?t(e):t??Gu}function f(e){var t,r,i;let[o,d,f]=[c,s,l];if(u(),!n?.onMouseUp||!d||!o||!(n==null||(t=n.modifiers)==null)&&t.self&&e.target!==a.value)return;!(n==null||(r=n.modifiers)==null)&&r.prevent&&e.preventDefault(),!(n==null||(i=n.modifiers)==null)&&i.stop&&e.stopPropagation();let p=e.x-d.x,m=e.y-d.y,h=Math.sqrt(p*p+m*m);n.onMouseUp(e.timeStamp-o,h,f,e)}function p(e){var r,i,f;!(n==null||(r=n.modifiers)==null)&&r.self&&e.target!==a.value||(u(),!(n==null||(i=n.modifiers)==null)&&i.prevent&&e.preventDefault(),!(n==null||(f=n.modifiers)==null)&&f.stop&&e.stopPropagation(),s={x:e.x,y:e.y},c=e.timeStamp,o=setTimeout(()=>{l=!0,t(e)},d(e)))}function m(e){var t,r,i;if(!(n==null||(t=n.modifiers)==null)&&t.self&&e.target!==a.value||!s||n?.distanceThreshold===!1)return;!(n==null||(r=n.modifiers)==null)&&r.prevent&&e.preventDefault(),!(n==null||(i=n.modifiers)==null)&&i.stop&&e.stopPropagation();let o=e.x-s.x,c=e.y-s.y;Math.sqrt(o*o+c*c)>=(n?.distanceThreshold??Ku)&&u()}let h={capture:n==null||(r=n.modifiers)==null?void 0:r.capture,once:n==null||(i=n.modifiers)==null?void 0:i.once},g=[Iu(a,`pointerdown`,p,h),Iu(a,`pointermove`,m,h),Iu(a,[`pointerup`,`pointerleave`],f,h)];return()=>g.forEach(e=>e())}function Ju(e,t={}){let{immediate:n=!0,fpsLimit:r=null,window:i=Pu,once:a=!1}=t,o=H(!1),s=W(()=>{let e=B(r);return e?1e3/e:null}),c=0,l=null;function u(t){if(!o.value||!i)return;c||=t;let n=t-c;if(s.value&&n<s.value){l=i.requestAnimationFrame(u);return}if(c=t,e({delta:n,timestamp:t}),a){o.value=!1,l=null;return}l=i.requestAnimationFrame(u)}function d(){!o.value&&i&&(o.value=!0,c=0,l=i.requestAnimationFrame(u))}function f(){o.value=!1,l!=null&&i&&(i.cancelAnimationFrame(l),l=null)}return n&&d(),Fl(f),{isActive:Ee(o),pause:f,resume:d}}var Yu=Symbol(`vueuse-ssr-width`);function Xu(){let e=tt()?Ll(Yu,null):null;return typeof e==`number`?e:void 0}function Zu(e,t={}){let{window:n=Pu,ssrWidth:r=Xu()}=t,i=Bu(()=>n&&`matchMedia`in n&&typeof n.matchMedia==`function`),a=H(typeof r==`number`),s=H(),c=H(!1);return o(()=>{if(a.value){a.value=!i.value,c.value=B(e).split(`,`).some(e=>{let t=e.includes(`not all`),n=e.match(/\(\s*min-width:\s*(-?\d+(?:\.\d*)?[a-z]+\s*)\)/),i=e.match(/\(\s*max-width:\s*(-?\d+(?:\.\d*)?[a-z]+\s*)\)/),a=!!(n||i);return n&&a&&(a=r>=Zl(n[1])),i&&a&&(a=r<=Zl(i[1])),t?!a:a});return}i.value&&(s.value=n.matchMedia(B(e)),c.value=s.value.matches)}),Iu(s,`change`,e=>{c.value=e.matches},{passive:!0}),W(()=>c.value)}var Qu=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{},$u=`__vueuse_ssr_handlers__`,ed=td();function td(){return $u in Qu||(Qu[$u]=Qu[$u]||{}),Qu[$u]}function nd(e,t){return ed[e]||t}function rd(e){return e==null?`any`:e instanceof Set?`set`:e instanceof Map?`map`:e instanceof Date?`date`:typeof e==`boolean`?`boolean`:typeof e==`string`?`string`:typeof e==`object`?`object`:Number.isNaN(e)?`any`:`number`}var id={boolean:{read:e=>e===`true`,write:e=>String(e)},object:{read:e=>JSON.parse(e),write:e=>JSON.stringify(e)},number:{read:e=>Number.parseFloat(e),write:e=>String(e)},any:{read:e=>e,write:e=>String(e)},string:{read:e=>e,write:e=>String(e)},map:{read:e=>new Map(JSON.parse(e)),write:e=>JSON.stringify(Array.from(e.entries()))},set:{read:e=>new Set(JSON.parse(e)),write:e=>JSON.stringify(Array.from(e))},date:{read:e=>new Date(e),write:e=>e.toISOString()}},ad=`vueuse-storage`;function od(e,t,n,r={}){let{flush:i=`pre`,deep:a=!0,listenToStorageChanges:o=!0,writeDefaults:c=!0,mergeDefaults:l=!1,shallow:u,window:d=Pu,eventFilter:f,onError:p=e=>{console.error(e)},initOnMounted:m}=r,h=(u?H:K)(typeof t==`function`?t():t),g=W(()=>B(e));if(!n)try{n=nd(`getDefaultStorage`,()=>Pu?.localStorage)()}catch(e){p(e)}if(!n)return h;let _=B(t),v=rd(_),y=r.serializer??id[v],{pause:b,resume:x}=pu(h,e=>w(e),{flush:i,deep:a,eventFilter:f});A(g,()=>E(),{flush:i});let S=!1;d&&o&&(n instanceof Storage?Iu(d,`storage`,e=>{m&&!S||E(e)},{passive:!0}):Iu(d,ad,e=>{m&&!S||D(e)})),m?hu(()=>{S=!0,E()}):E();function C(e,t){if(d){let r={key:g.value,oldValue:e,newValue:t,storageArea:n};d.dispatchEvent(n instanceof Storage?new StorageEvent(`storage`,r):new CustomEvent(ad,{detail:r}))}}function w(e){try{let t=n.getItem(g.value);if(e==null)C(t,null),n.removeItem(g.value);else{let r=y.write(e);t!==r&&(n.setItem(g.value,r),C(t,r))}}catch(e){p(e)}}function T(e){let t=e?e.newValue:n.getItem(g.value);if(t==null)return c&&_!=null&&n.setItem(g.value,y.write(_)),_;if(!e&&l){let e=y.read(t);return typeof l==`function`?l(e,_):v===`object`&&!Array.isArray(e)?{..._,...e}:e}else if(typeof t!=`string`)return t;else return y.read(t)}function E(e){if(!(e&&e.storageArea!==n)){if(e&&e.key==null){h.value=_;return}if(!(e&&e.key!==g.value)){b();try{let t=y.write(h.value);(e===void 0||e?.newValue!==t)&&(h.value=T(e))}catch(e){p(e)}finally{e?s(x):x()}}}}function D(e){E(e.detail)}return h}var sd={speed:2,margin:30,direction:`both`};function cd(e){e.scrollLeft>e.scrollWidth-e.clientWidth&&(e.scrollLeft=Math.max(0,e.scrollWidth-e.clientWidth)),e.scrollTop>e.scrollHeight-e.clientHeight&&(e.scrollTop=Math.max(0,e.scrollHeight-e.clientHeight))}function ld(e,t={}){let{pointerTypes:n,preventDefault:r,stopPropagation:i,exact:a,onMove:o,onEnd:s,onStart:c,initialValue:l,axis:u=`both`,draggingElement:d=Pu,containerElement:f,handle:p=e,buttons:m=[0],restrictInView:h,autoScroll:g=!1}=t,_=K(B(l)??{x:0,y:0}),v=K(),y=e=>!n||n.includes(e.pointerType),b=e=>{B(r)&&e.preventDefault(),B(i)&&e.stopPropagation()},x=B(g),S=typeof x==`object`?{speed:B(x.speed)??sd.speed,margin:B(x.margin)??sd.margin,direction:x.direction??sd.direction}:sd,C=e=>typeof e==`number`?[e,e]:[e.x,e.y],w=(e,t,n)=>{let{clientWidth:r,clientHeight:i,scrollLeft:a,scrollTop:o,scrollWidth:s,scrollHeight:c}=e,[l,u]=C(S.margin),[d,f]=C(S.speed),p=0,m=0;(S.direction===`x`||S.direction===`both`)&&(n.x<l&&a>0?p=-d:n.x+t.width>r-l&&a<s-r&&(p=d)),(S.direction===`y`||S.direction===`both`)&&(n.y<u&&o>0?m=-f:n.y+t.height>i-u&&o<c-i&&(m=f)),(p||m)&&e.scrollBy({left:p,top:m,behavior:`auto`})},T=null,E=()=>{let t=B(f);t&&!T&&(T=setInterval(()=>{let n=B(e).getBoundingClientRect(),{x:r,y:i}=_.value,a={x:r-t.scrollLeft,y:i-t.scrollTop};a.x>=0&&a.y>=0&&(w(t,n,a),a.x+=t.scrollLeft,a.y+=t.scrollTop,_.value=a)},1e3/60))},D=()=>{T&&=(clearInterval(T),null)},O=(e,t,n,r)=>{let[i,a]=typeof n==`number`?[n,n]:[n.x,n.y],{clientWidth:o,clientHeight:s}=t;return e.x<i||e.x+r.width>o-i||e.y<a||e.y+r.height>s-a};B(g)&&A(_,()=>{if(B(t.disabled)||!v.value)return;let n=B(f);if(!n)return;let r=B(e).getBoundingClientRect(),{x:i,y:a}=_.value;O({x:i-n.scrollLeft,y:a-n.scrollTop},n,S.margin,r)?E():D()});let k=n=>{var r;if(!B(m).includes(n.button)||B(t.disabled)||!y(n)||B(a)&&n.target!==B(e))return;let i=B(f),o=i==null||(r=i.getBoundingClientRect)==null?void 0:r.call(i),s=B(e).getBoundingClientRect(),l={x:n.clientX-(i?s.left-o.left+(g?0:i.scrollLeft):s.left),y:n.clientY-(i?s.top-o.top+(g?0:i.scrollTop):s.top)};c?.(l,n)!==!1&&(v.value=l,b(n))},j=n=>{if(B(t.disabled)||!y(n)||!v.value)return;let r=B(f);r instanceof HTMLElement&&cd(r);let i=B(e).getBoundingClientRect(),{x:a,y:s}=_.value;if((u===`x`||u===`both`)&&(a=n.clientX-v.value.x,r&&(a=Math.min(Math.max(0,a),r.scrollWidth-i.width))),(u===`y`||u===`both`)&&(s=n.clientY-v.value.y,r&&(s=Math.min(Math.max(0,s),r.scrollHeight-i.height))),B(g)&&r&&(T===null&&w(r,i,{x:a,y:s}),a+=r.scrollLeft,s+=r.scrollTop),r&&(h||g)){if(u!==`y`){let e=a-r.scrollLeft;e<0?a=r.scrollLeft:e>r.clientWidth-i.width&&(a=r.clientWidth-i.width+r.scrollLeft)}if(u!==`x`){let e=s-r.scrollTop;e<0?s=r.scrollTop:e>r.clientHeight-i.height&&(s=r.clientHeight-i.height+r.scrollTop)}}_.value={x:a,y:s},o?.(_.value,n),b(n)},M=e=>{B(t.disabled)||!y(e)||v.value&&(v.value=void 0,g&&D(),s?.(_.value,e),b(e))};if(Rl){let e=()=>({capture:t.capture??!0,passive:!B(r)});Iu(p,`pointerdown`,k,e),Iu(d,`pointermove`,j,e),Iu(d,`pointerup`,M,e)}return{...mu(_),position:_,isDragging:W(()=>!!v.value),style:W(()=>`
|
|
13
13
|
left: ${_.value.x}px;
|
|
14
14
|
top: ${_.value.y}px;
|
|
15
15
|
${g?`text-wrap: nowrap;`:``}
|