@rivium/push-web 0.1.1 → 0.1.2

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/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("@rivium/pn-protocol");exports.RiviumPushErrorCode=void 0,(e=exports.RiviumPushErrorCode||(exports.RiviumPushErrorCode={}))[e.CONNECTION_FAILED=1e3]="CONNECTION_FAILED",e[e.CONNECTION_TIMEOUT=1001]="CONNECTION_TIMEOUT",e[e.CONNECTION_LOST=1002]="CONNECTION_LOST",e[e.CONNECTION_REFUSED=1003]="CONNECTION_REFUSED",e[e.AUTHENTICATION_FAILED=1004]="AUTHENTICATION_FAILED",e[e.SSL_ERROR=1005]="SSL_ERROR",e[e.BROKER_UNAVAILABLE=1006]="BROKER_UNAVAILABLE",e[e.SUBSCRIPTION_FAILED=1100]="SUBSCRIPTION_FAILED",e[e.UNSUBSCRIPTION_FAILED=1101]="UNSUBSCRIPTION_FAILED",e[e.INVALID_TOPIC=1102]="INVALID_TOPIC",e[e.MESSAGE_DELIVERY_FAILED=1200]="MESSAGE_DELIVERY_FAILED",e[e.MESSAGE_PARSE_ERROR=1201]="MESSAGE_PARSE_ERROR",e[e.MESSAGE_TIMEOUT=1202]="MESSAGE_TIMEOUT",e[e.INVALID_CONFIG=1300]="INVALID_CONFIG",e[e.MISSING_API_KEY=1301]="MISSING_API_KEY",e[e.MISSING_SERVER_URL=1302]="MISSING_SERVER_URL",e[e.INVALID_CREDENTIALS=1303]="INVALID_CREDENTIALS",e[e.REGISTRATION_FAILED=1400]="REGISTRATION_FAILED",e[e.DEVICE_ID_GENERATION_FAILED=1401]="DEVICE_ID_GENERATION_FAILED",e[e.SERVER_ERROR=1402]="SERVER_ERROR",e[e.NETWORK_ERROR=1403]="NETWORK_ERROR",e[e.NOT_INITIALIZED=1500]="NOT_INITIALIZED",e[e.NOT_CONNECTED=1501]="NOT_CONNECTED",e[e.ALREADY_CONNECTED=1502]="ALREADY_CONNECTED",e[e.SERVICE_NOT_RUNNING=1503]="SERVICE_NOT_RUNNING",e[e.PERMISSION_DENIED=1600]="PERMISSION_DENIED",e[e.PERMISSION_DISMISSED=1601]="PERMISSION_DISMISSED",e[e.UNKNOWN_ERROR=9999]="UNKNOWN_ERROR";const i={[exports.RiviumPushErrorCode.CONNECTION_FAILED]:"Failed to connect to MQTT broker",[exports.RiviumPushErrorCode.CONNECTION_TIMEOUT]:"Connection timed out",[exports.RiviumPushErrorCode.CONNECTION_LOST]:"Connection to server was lost",[exports.RiviumPushErrorCode.CONNECTION_REFUSED]:"Connection was refused by server",[exports.RiviumPushErrorCode.AUTHENTICATION_FAILED]:"Authentication failed - invalid credentials",[exports.RiviumPushErrorCode.SSL_ERROR]:"SSL/TLS handshake failed",[exports.RiviumPushErrorCode.BROKER_UNAVAILABLE]:"MQTT broker is unavailable",[exports.RiviumPushErrorCode.SUBSCRIPTION_FAILED]:"Failed to subscribe to topic",[exports.RiviumPushErrorCode.UNSUBSCRIPTION_FAILED]:"Failed to unsubscribe from topic",[exports.RiviumPushErrorCode.INVALID_TOPIC]:"Invalid topic format",[exports.RiviumPushErrorCode.MESSAGE_DELIVERY_FAILED]:"Failed to deliver message",[exports.RiviumPushErrorCode.MESSAGE_PARSE_ERROR]:"Failed to parse message payload",[exports.RiviumPushErrorCode.MESSAGE_TIMEOUT]:"Message delivery timed out",[exports.RiviumPushErrorCode.INVALID_CONFIG]:"Invalid configuration",[exports.RiviumPushErrorCode.MISSING_API_KEY]:"API key is missing",[exports.RiviumPushErrorCode.MISSING_SERVER_URL]:"Server URL is missing",[exports.RiviumPushErrorCode.INVALID_CREDENTIALS]:"Invalid MQTT credentials",[exports.RiviumPushErrorCode.REGISTRATION_FAILED]:"Device registration failed",[exports.RiviumPushErrorCode.DEVICE_ID_GENERATION_FAILED]:"Failed to generate device ID",[exports.RiviumPushErrorCode.SERVER_ERROR]:"Server returned an error",[exports.RiviumPushErrorCode.NETWORK_ERROR]:"Network request failed",[exports.RiviumPushErrorCode.NOT_INITIALIZED]:"SDK is not initialized",[exports.RiviumPushErrorCode.NOT_CONNECTED]:"Not connected to server",[exports.RiviumPushErrorCode.ALREADY_CONNECTED]:"Already connected to server",[exports.RiviumPushErrorCode.SERVICE_NOT_RUNNING]:"Service worker is not running",[exports.RiviumPushErrorCode.PERMISSION_DENIED]:"Notification permission denied",[exports.RiviumPushErrorCode.PERMISSION_DISMISSED]:"Notification permission dismissed",[exports.RiviumPushErrorCode.UNKNOWN_ERROR]:"An unknown error occurred"};class s extends Error{constructor(e,t){super(i[e]||"Unknown error"),this.name="RiviumPushError",this.code=e,this.details=t}toJSON(){return{code:this.code,message:this.message,details:this.details}}}var o,n,r;exports.RiviumPushAnalyticsEvent=void 0,(o=exports.RiviumPushAnalyticsEvent||(exports.RiviumPushAnalyticsEvent={})).SDK_INITIALIZED="sdkInitialized",o.DEVICE_REGISTERED="deviceRegistered",o.DEVICE_UNREGISTERED="deviceUnregistered",o.MESSAGE_RECEIVED="messageReceived",o.MESSAGE_DISPLAYED="messageDisplayed",o.NOTIFICATION_CLICKED="notificationClicked",o.ACTION_CLICKED="actionClicked",o.CONNECTED="connected",o.DISCONNECTED="disconnected",o.CONNECTION_ERROR="connectionError",o.RETRY_STARTED="retryStarted",o.TOPIC_SUBSCRIBED="topicSubscribed",o.TOPIC_UNSUBSCRIBED="topicUnsubscribed",o.NETWORK_STATE_CHANGED="networkStateChanged",o.APP_STATE_CHANGED="appStateChanged",o.PERMISSION_REQUESTED="permissionRequested",o.PERMISSION_GRANTED="permissionGranted",o.PERMISSION_DENIED="permissionDenied",exports.RiviumPushLogLevel=void 0,(n=exports.RiviumPushLogLevel||(exports.RiviumPushLogLevel={}))[n.NONE=0]="NONE",n[n.ERROR=1]="ERROR",n[n.WARNING=2]="WARNING",n[n.INFO=3]="INFO",n[n.DEBUG=4]="DEBUG",n[n.VERBOSE=5]="VERBOSE",exports.NetworkType=void 0,(r=exports.NetworkType||(exports.NetworkType={})).WIFI="wifi",r.CELLULAR="cellular",r.ETHERNET="ethernet",r.NONE="none",r.UNKNOWN="unknown";const a="https://push-api.rivium.co";class c{constructor(e){var t;if(this.deviceId=null,this.subscriptionId=null,this.userId=null,this.pnSocket=null,this.serviceWorkerRegistration=null,this.pushSubscription=null,this.connectionState="disconnected",this.reconnectAttempts=0,this.maxReconnectAttempts=10,this.reconnectTimer=null,this.subscribedTopics=new Set,this.badgeCount=0,this.initialized=!1,this.initialMessage=null,this.mqttConfig=null,this.mqttConfigFetched=!1,this.appId=null,this.appIdentifier=null,this.vapidPublicKey=null,this.logLevel=exports.RiviumPushLogLevel.DEBUG,this.analyticsCallback=null,this.analyticsEnabled=!1,this.onMessageCallback=null,this.onConnectionStateCallback=null,this.onRegisteredCallback=null,this.onErrorCallback=null,this.onDetailedErrorCallback=null,this.onNotificationClickCallback=null,this.onActionClickedCallback=null,this.onReconnectingCallback=null,this.onNetworkStateCallback=null,this.onAppStateCallback=null,!e.apiKey)throw new Error("RiviumPush: apiKey is required");this.config={serviceWorkerPath:"/rivium-push-sw.js",autoRegisterServiceWorker:!0,mqttQos:1,maxReconnectAttempts:10,logLevel:exports.RiviumPushLogLevel.ERROR,...e},this.maxReconnectAttempts=this.config.maxReconnectAttempts,this.logLevel=this.config.logLevel,"undefined"!=typeof window?(this.deviceId=this.getOrCreateDeviceId(),this.subscriptionId=localStorage.getItem("rivium_push_subscription_id")||null,this.userId=localStorage.getItem("rivium_push_user_id")||null,this.badgeCount=parseInt(localStorage.getItem("rivium_push_badge_count")||"0",10),this.checkInitialMessage(),"serviceWorker"in navigator&&navigator.serviceWorker.addEventListener("message",this.handleServiceWorkerMessage.bind(this)),document.addEventListener("visibilitychange",this.handleVisibilityChange.bind(this)),"connection"in navigator&&(null===(t=navigator.connection)||void 0===t||t.addEventListener("change",this.handleNetworkChange.bind(this))),window.addEventListener("online",this.handleOnline.bind(this)),window.addEventListener("offline",this.handleOffline.bind(this)),this.initialized=!0,this.trackEvent(exports.RiviumPushAnalyticsEvent.SDK_INITIALIZED),this.log(exports.RiviumPushLogLevel.INFO,"RiviumPush SDK initialized"),this.fetchMqttConfig()):this.initialized=!0}async fetchMqttConfig(){try{this.log(exports.RiviumPushLogLevel.DEBUG,"Fetching config from server...");const e=await fetch(`${a}/devices/config`,{method:"GET",headers:{"Content-Type":"application/json","x-api-key":this.config.apiKey}});if(!e.ok)throw new Error(`HTTP ${e.status}`);const t=await e.json();this.mqttConfig=t.mqtt,this.mqttConfigFetched=!0,t.vapidPublicKey&&(this.vapidPublicKey=t.vapidPublicKey,this.log(exports.RiviumPushLogLevel.DEBUG,"VAPID public key received from server")),this.log(exports.RiviumPushLogLevel.INFO,`Config fetched successfully, vapid=${!!this.vapidPublicKey}`)}catch(e){this.log(exports.RiviumPushLogLevel.ERROR,"Failed to fetch config:",e),this.emitError(exports.RiviumPushErrorCode.INVALID_CONFIG,`Failed to fetch config: ${e.message}`)}}log(e,t,...i){if(e>this.logLevel)return;const s="[RiviumPush]";switch(e){case exports.RiviumPushLogLevel.ERROR:console.error(s,t,...i);break;case exports.RiviumPushLogLevel.WARNING:console.warn(s,t,...i);break;case exports.RiviumPushLogLevel.INFO:console.info(s,t,...i);break;case exports.RiviumPushLogLevel.DEBUG:case exports.RiviumPushLogLevel.VERBOSE:console.log(s,t,...i)}}setLogLevel(e){this.logLevel=e,this.log(exports.RiviumPushLogLevel.INFO,`Log level set to ${exports.RiviumPushLogLevel[e]}`)}getLogLevel(){return this.logLevel}trackEvent(e,t){if(this.analyticsEnabled&&this.analyticsCallback)try{this.analyticsCallback(e,t)}catch(e){this.log(exports.RiviumPushLogLevel.ERROR,"Analytics callback error:",e)}this.log(exports.RiviumPushLogLevel.VERBOSE,`Analytics event: ${e}`,t)}setAnalyticsHandler(e){this.analyticsCallback=e,this.analyticsEnabled=!0,this.log(exports.RiviumPushLogLevel.INFO,"Analytics handler set")}disableAnalytics(){this.analyticsCallback=null,this.analyticsEnabled=!1,this.log(exports.RiviumPushLogLevel.INFO,"Analytics disabled")}isAnalyticsEnabled(){return this.analyticsEnabled}emitError(e,t){const i=new s(e,t);this.log(exports.RiviumPushLogLevel.ERROR,`Error [${e}]: ${i.message}`,t),this.onDetailedErrorCallback&&this.onDetailedErrorCallback(i),this.onErrorCallback&&this.onErrorCallback(i),this.trackEvent(exports.RiviumPushAnalyticsEvent.CONNECTION_ERROR,{errorCode:e,errorMessage:i.message,details:t})}async register(e){var t,i;try{this.mqttConfigFetched||(this.log(exports.RiviumPushLogLevel.DEBUG,"Waiting for server config..."),await this.waitForConfig()),this.config.autoRegisterServiceWorker&&await this.registerServiceWorker(),this.trackEvent(exports.RiviumPushAnalyticsEvent.PERMISSION_REQUESTED);const o=await this.requestNotificationPermission();if("denied"===o)throw this.trackEvent(exports.RiviumPushAnalyticsEvent.PERMISSION_DENIED),this.emitError(exports.RiviumPushErrorCode.PERMISSION_DENIED),new s(exports.RiviumPushErrorCode.PERMISSION_DENIED);if("default"===o)throw this.trackEvent(exports.RiviumPushAnalyticsEvent.PERMISSION_DENIED),this.emitError(exports.RiviumPushErrorCode.PERMISSION_DISMISSED,"User dismissed the permission prompt"),new s(exports.RiviumPushErrorCode.PERMISSION_DISMISSED);this.trackEvent(exports.RiviumPushAnalyticsEvent.PERMISSION_GRANTED);const n=this.vapidPublicKey||this.config.vapidPublicKey;if(n&&this.serviceWorkerRegistration)try{this.pushSubscription=await this.subscribeToPush(n),this.log(exports.RiviumPushLogLevel.INFO,"Web Push subscription created for background notifications")}catch(e){this.log(exports.RiviumPushLogLevel.WARNING,"Web Push subscription failed (will use MQTT only):",e)}const r={...e,userId:null!==(i=null!==(t=null==e?void 0:e.userId)&&void 0!==t?t:this.userId)&&void 0!==i?i:void 0},a=await this.registerDevice(r);return this.deviceId=a.deviceId,this.connectToGateway(),this.onRegisteredCallback&&this.onRegisteredCallback(a.deviceId),this.trackEvent(exports.RiviumPushAnalyticsEvent.DEVICE_REGISTERED,{deviceId:a.deviceId,userId:null==e?void 0:e.userId,hasWebPush:!!this.pushSubscription}),this.log(exports.RiviumPushLogLevel.INFO,"Registered with device ID:",a.deviceId,"Web Push:",!!this.pushSubscription),a.deviceId}catch(e){if(e instanceof s)throw e;throw this.log(exports.RiviumPushLogLevel.ERROR,"Registration failed:",e),this.emitError(exports.RiviumPushErrorCode.REGISTRATION_FAILED,e.message),e}}async waitForConfig(e=5e3){const t=Date.now();for(;!this.mqttConfigFetched&&Date.now()-t<e;)await new Promise(e=>setTimeout(e,100));this.mqttConfigFetched||this.log(exports.RiviumPushLogLevel.WARNING,"Config fetch timed out, continuing without it")}async unregister(){this.disconnectFromGateway(),this.pushSubscription&&(await this.pushSubscription.unsubscribe(),this.pushSubscription=null),this.trackEvent(exports.RiviumPushAnalyticsEvent.DEVICE_UNREGISTERED,{deviceId:this.deviceId}),this.log(exports.RiviumPushLogLevel.INFO,"Unregistered")}async subscribeTopic(e){if(e&&""!==e.trim()){if(this.subscribedTopics.add(e),this.deviceId)try{await fetch(`${a}/topics/subscribe`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.config.apiKey},body:JSON.stringify({deviceId:this.deviceId,topic:e})})}catch(e){this.log(exports.RiviumPushLogLevel.WARNING,"Failed to register topic on server:",e)}if(this.pnSocket&&this.pnSocket.isConnected()){const t=`rivium_push/${this.config.apiKey.substring(0,16)}/topic/${e}`;this.pnSocket.stream(t,e=>{this.handlePNMessage(e)},this.config.mqttQos),this.log(exports.RiviumPushLogLevel.INFO,"Subscribed to topic:",e),this.trackEvent(exports.RiviumPushAnalyticsEvent.TOPIC_SUBSCRIBED,{topic:e})}}else this.emitError(exports.RiviumPushErrorCode.INVALID_TOPIC,"Topic cannot be empty")}async unsubscribeTopic(e){if(this.subscribedTopics.delete(e),this.deviceId)try{await fetch(`${a}/topics/unsubscribe`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.config.apiKey},body:JSON.stringify({deviceId:this.deviceId,topic:e})})}catch(e){this.log(exports.RiviumPushLogLevel.WARNING,"Failed to unregister topic on server:",e)}if(this.pnSocket&&this.pnSocket.isConnected()){const t=`rivium_push/${this.config.apiKey.substring(0,16)}/topic/${e}`;this.pnSocket.detach(t),this.log(exports.RiviumPushLogLevel.INFO,"Unsubscribed from topic:",e),this.trackEvent(exports.RiviumPushAnalyticsEvent.TOPIC_UNSUBSCRIBED,{topic:e})}}isConnected(){return"connected"===this.connectionState}getDeviceId(){return this.deviceId}getSubscriptionId(){return this.subscriptionId}async setUserId(e){this.userId=e,localStorage.setItem("rivium_push_user_id",e),await this.registerDevice({userId:e}),this.log(exports.RiviumPushLogLevel.INFO,"User ID set:",e)}clearUserId(){this.userId=null,localStorage.removeItem("rivium_push_user_id"),this.log(exports.RiviumPushLogLevel.INFO,"User ID cleared")}getUserId(){return this.userId}getInitialMessage(){return this.initialMessage}getBadgeCount(){return this.badgeCount}setBadgeCount(e){this.badgeCount=Math.max(0,e),localStorage.setItem("rivium_push_badge_count",this.badgeCount.toString()),this.updateFaviconBadge(this.badgeCount),"setAppBadge"in navigator&&(this.badgeCount>0?navigator.setAppBadge(this.badgeCount):navigator.clearAppBadge())}clearBadge(){this.setBadgeCount(0)}async refreshMqttToken(){if(!this.deviceId)throw new s(exports.RiviumPushErrorCode.NOT_INITIALIZED,"Device not registered");try{const e=await fetch(`${a}/devices/${this.deviceId}/mqtt-token/refresh`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.config.apiKey}});if(!e.ok){const t=await e.json().catch(()=>({}));throw new s(exports.RiviumPushErrorCode.SERVER_ERROR,t.message||`HTTP ${e.status}`)}const t=await e.json();t.token&&this.mqttConfig&&(this.mqttConfig.token=t.token,this.log(exports.RiviumPushLogLevel.INFO,"MQTT token refreshed successfully"))}catch(e){if(e instanceof s)throw e;throw new s(exports.RiviumPushErrorCode.NETWORK_ERROR,e.message)}}getNetworkState(){const e=navigator.connection;return{isAvailable:navigator.onLine,networkType:this.detectNetworkType(),effectiveType:null==e?void 0:e.effectiveType,downlink:null==e?void 0:e.downlink,rtt:null==e?void 0:e.rtt}}getAppState(){return{isVisible:"visible"===document.visibilityState,visibilityState:document.visibilityState}}static isSupported(){return"undefined"!=typeof window&&"Notification"in window&&"serviceWorker"in navigator}static getPermissionStatus(){return"undefined"==typeof Notification?"denied":Notification.permission}onMessage(e){return this.onMessageCallback=e,()=>{this.onMessageCallback=null}}onConnectionState(e){return this.onConnectionStateCallback=e,()=>{this.onConnectionStateCallback=null}}onRegistered(e){return this.onRegisteredCallback=e,()=>{this.onRegisteredCallback=null}}onError(e){return this.onErrorCallback=e,()=>{this.onErrorCallback=null}}onDetailedError(e){return this.onDetailedErrorCallback=e,()=>{this.onDetailedErrorCallback=null}}onNotificationClick(e){return this.onNotificationClickCallback=e,()=>{this.onNotificationClickCallback=null}}onActionClicked(e){return this.onActionClickedCallback=e,()=>{this.onActionClickedCallback=null}}onReconnecting(e){return this.onReconnectingCallback=e,()=>{this.onReconnectingCallback=null}}onNetworkState(e){return this.onNetworkStateCallback=e,()=>{this.onNetworkStateCallback=null}}onAppState(e){return this.onAppStateCallback=e,()=>{this.onAppStateCallback=null}}detectNetworkType(){const e=navigator.connection;if(!e)return exports.NetworkType.UNKNOWN;switch(e.type){case"wifi":return exports.NetworkType.WIFI;case"cellular":return exports.NetworkType.CELLULAR;case"ethernet":return exports.NetworkType.ETHERNET;case"none":return exports.NetworkType.NONE;default:return exports.NetworkType.UNKNOWN}}handleNetworkChange(){const e=this.getNetworkState();this.log(exports.RiviumPushLogLevel.DEBUG,"Network state changed:",e),this.onNetworkStateCallback&&this.onNetworkStateCallback(e),this.trackEvent(exports.RiviumPushAnalyticsEvent.NETWORK_STATE_CHANGED,{isAvailable:e.isAvailable,networkType:e.networkType,effectiveType:e.effectiveType})}handleOnline(){this.log(exports.RiviumPushLogLevel.INFO,"Network online"),this.handleNetworkChange(),"disconnected"===this.connectionState&&this.deviceId&&(this.log(exports.RiviumPushLogLevel.INFO,"Reconnecting after network restored"),this.connectToGateway())}handleOffline(){this.log(exports.RiviumPushLogLevel.INFO,"Network offline"),this.handleNetworkChange()}handleVisibilityChange(){const e=this.getAppState();this.log(exports.RiviumPushLogLevel.DEBUG,"App state changed:",e),this.onAppStateCallback&&this.onAppStateCallback(e),this.trackEvent(exports.RiviumPushAnalyticsEvent.APP_STATE_CHANGED,{isVisible:e.isVisible,visibilityState:e.visibilityState}),e.isVisible&&"disconnected"===this.connectionState&&this.deviceId&&(this.log(exports.RiviumPushLogLevel.INFO,"Reconnecting after becoming visible"),this.connectToGateway())}checkInitialMessage(){if("undefined"!=typeof window){const e=new URLSearchParams(window.location.search).get("rivium_push_notification");if(e)try{this.initialMessage=JSON.parse(decodeURIComponent(e)),this.log(exports.RiviumPushLogLevel.INFO,"Initial message found:",this.initialMessage)}catch(e){this.log(exports.RiviumPushLogLevel.WARNING,"Failed to parse initial message:",e)}const t=sessionStorage.getItem("rivium_push_initial_message");if(t&&!this.initialMessage)try{this.initialMessage=JSON.parse(t),sessionStorage.removeItem("rivium_push_initial_message"),this.log(exports.RiviumPushLogLevel.INFO,"Initial message from session:",this.initialMessage)}catch(e){this.log(exports.RiviumPushLogLevel.WARNING,"Failed to parse stored message:",e)}}}async registerServiceWorker(){if(!("serviceWorker"in navigator))throw new s(exports.RiviumPushErrorCode.SERVICE_NOT_RUNNING,"Service Workers not supported");try{this.serviceWorkerRegistration=await navigator.serviceWorker.register(this.config.serviceWorkerPath,{scope:"/"}),this.log(exports.RiviumPushLogLevel.INFO,"Service Worker registered")}catch(e){throw this.log(exports.RiviumPushLogLevel.ERROR,"Service Worker registration failed:",e),new s(exports.RiviumPushErrorCode.SERVICE_NOT_RUNNING,e.message)}}async requestNotificationPermission(){return"undefined"==typeof Notification?"denied":"granted"===Notification.permission?"granted":await Notification.requestPermission()}async subscribeToPush(e){if(!this.serviceWorkerRegistration)throw new s(exports.RiviumPushErrorCode.SERVICE_NOT_RUNNING,"Service Worker not registered");const t=await this.serviceWorkerRegistration.pushManager.getSubscription();if(t)return this.log(exports.RiviumPushLogLevel.DEBUG,"Using existing Push subscription"),t;const i=await this.serviceWorkerRegistration.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:this.urlBase64ToUint8Array(e)});return this.log(exports.RiviumPushLogLevel.INFO,"Push subscription created"),i}async registerDevice(e){var t,i,o;try{const n={deviceId:this.deviceId,platform:"web",userId:null==e?void 0:e.userId,appIdentifier:"undefined"!=typeof window?window.location.origin:void 0,metadata:{...null==e?void 0:e.metadata,userAgent:navigator.userAgent,language:navigator.language,url:window.location.origin}};if(this.pushSubscription){const e=this.pushSubscription.toJSON();n.webPushSubscription={endpoint:e.endpoint,keys:{p256dh:(null===(t=e.keys)||void 0===t?void 0:t.p256dh)||"",auth:(null===(i=e.keys)||void 0===i?void 0:i.auth)||""}},this.log(exports.RiviumPushLogLevel.DEBUG,"Sending Web Push subscription to server")}const r=await fetch(`${a}/devices/register`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.config.apiKey},body:JSON.stringify(n)});if(!r.ok){const e=await r.json().catch(()=>({}));throw new s(exports.RiviumPushErrorCode.SERVER_ERROR,e.message||`HTTP ${r.status}`)}const c=await r.json();return c.appId&&(this.appId=c.appId),c.subscriptionId&&(this.subscriptionId=c.subscriptionId,localStorage.setItem("rivium_push_subscription_id",c.subscriptionId),this.log(exports.RiviumPushLogLevel.DEBUG,`Stored subscriptionId: ${c.subscriptionId}`)),c.appIdentifier&&(this.appIdentifier=c.appIdentifier),(null===(o=c.mqtt)||void 0===o?void 0:o.token)&&this.mqttConfig&&(this.mqttConfig.token=c.mqtt.token,this.log(exports.RiviumPushLogLevel.DEBUG,"Connection token received from registration")),c}catch(e){if(e instanceof s)throw e;throw new s(exports.RiviumPushErrorCode.NETWORK_ERROR,e.message)}}connectToGateway(){if(this.pnSocket&&this.pnSocket.close(),this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),!this.mqttConfig)return this.log(exports.RiviumPushLogLevel.WARNING,"Gateway config not available, retrying in 2s..."),void setTimeout(()=>this.connectToGateway(),2e3);if(!this.mqttConfig.token)return this.log(exports.RiviumPushLogLevel.ERROR,"Connection token not available. Device must be registered first."),void this.emitError(exports.RiviumPushErrorCode.AUTHENTICATION_FAILED,"Connection token not available");this.setConnectionState("connecting");const e=this.mqttConfig.wsHost||this.mqttConfig.host,i=this.mqttConfig.wsPort,s="undefined"!=typeof window&&"https:"===window.location.protocol||443===i;this.log(exports.RiviumPushLogLevel.DEBUG,`Connecting to gateway (secure: ${s})`);const o=`rivium_push_${this.appId}_${this.deviceId}`,n=(new t.PNConfigBuilder).gateway(e).port(i).clientId(o).auth(t.PNAuthFactory.token(this.mqttConfig.token)).secure(s).freshStart(!1).autoReconnect(!1).connectionTimeout(10).build();this.pnSocket=new t.PNSocket(n);const r={onStateChanged:e=>{this.log(exports.RiviumPushLogLevel.DEBUG,`Connection state changed: ${e}`)},onConnected:()=>{this.log(exports.RiviumPushLogLevel.INFO,"Connected to gateway"),this.setConnectionState("connected"),this.reconnectAttempts=0,this.trackEvent(exports.RiviumPushAnalyticsEvent.CONNECTED);const e=this.config.apiKey.substring(0,16),t=this.appIdentifier||("undefined"!=typeof window?window.location.origin:"_default");if(this.subscriptionId){const t=`rivium_push/${e}/sub/${this.subscriptionId}`;this.pnSocket.stream(t,e=>{this.handlePNMessage(e)},this.config.mqttQos),this.log(exports.RiviumPushLogLevel.DEBUG,`Streaming from subscription channel ${t}`)}const i=`rivium_push/${e}/broadcast`;this.pnSocket.stream(i,e=>{this.handlePNMessage(e)},this.config.mqttQos),this.log(exports.RiviumPushLogLevel.DEBUG,"Streaming from broadcast channel");const s=`rivium_push/${e}/${this.deviceId}/${t}`;this.pnSocket.stream(s,e=>{this.handlePNMessage(e)},this.config.mqttQos),this.log(exports.RiviumPushLogLevel.DEBUG,"Streaming from (deprecated) device channel"),this.subscribedTopics.forEach(t=>{const i=`rivium_push/${e}/topic/${t}`;this.pnSocket.stream(i,e=>{this.handlePNMessage(e)},this.config.mqttQos)})},onDisconnected:e=>{this.log(exports.RiviumPushLogLevel.INFO,"Disconnected from gateway",e||""),this.setConnectionState("disconnected"),this.trackEvent(exports.RiviumPushAnalyticsEvent.DISCONNECTED),this.scheduleReconnect()},onReconnecting:(e,t)=>{this.log(exports.RiviumPushLogLevel.INFO,`Reconnecting attempt ${e} in ${t}ms`)}};this.pnSocket.addConnectionListener(r),this.pnSocket.addErrorListener(e=>{this.log(exports.RiviumPushLogLevel.ERROR,"Gateway error:",e.message),this.setConnectionState("error");let t=exports.RiviumPushErrorCode.CONNECTION_FAILED;const i=e.message.toLowerCase();if(i.includes("timeout"))t=exports.RiviumPushErrorCode.CONNECTION_TIMEOUT;else if(i.includes("refused")||i.includes("not authorized")){if(t=exports.RiviumPushErrorCode.CONNECTION_REFUSED,i.includes("not authorized"))return this.log(exports.RiviumPushLogLevel.INFO,"Token may be expired, attempting refresh..."),void this.refreshMqttToken().then(()=>{this.log(exports.RiviumPushLogLevel.INFO,"Token refreshed, reconnecting..."),this.connectToGateway()}).catch(e=>{this.log(exports.RiviumPushLogLevel.ERROR,"Token refresh failed:",e),this.emitError(exports.RiviumPushErrorCode.AUTHENTICATION_FAILED,"Token expired and refresh failed")})}else i.includes("auth")||i.includes("credential")?t=exports.RiviumPushErrorCode.AUTHENTICATION_FAILED:(i.includes("ssl")||i.includes("tls"))&&(t=exports.RiviumPushErrorCode.SSL_ERROR);this.emitError(t,e.message)}),this.log(exports.RiviumPushLogLevel.DEBUG,"Opening connection to gateway..."),this.pnSocket.open()}handlePNMessage(e){try{const t=e.payloadAsJson();this.handleMqttMessage(e.channel,t)}catch(e){this.log(exports.RiviumPushLogLevel.ERROR,"Message parse error:",e),this.emitError(exports.RiviumPushErrorCode.MESSAGE_PARSE_ERROR,e.message)}}disconnectFromGateway(){this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.pnSocket&&(this.pnSocket.close(),this.pnSocket=null),this.setConnectionState("disconnected")}scheduleReconnect(){if(this.reconnectAttempts>=this.maxReconnectAttempts)return this.log(exports.RiviumPushLogLevel.WARNING,"Max reconnect attempts reached"),void this.emitError(exports.RiviumPushErrorCode.CONNECTION_FAILED,"Max reconnect attempts reached");if(!navigator.onLine)return void this.log(exports.RiviumPushLogLevel.DEBUG,"Offline, skipping reconnect");const e=Math.min(1e3*Math.pow(2,this.reconnectAttempts),3e4);this.reconnectAttempts++,this.log(exports.RiviumPushLogLevel.INFO,`Reconnecting in ${e}ms (attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts})`);const t={retryAttempt:this.reconnectAttempts,nextRetryMs:e,maxRetryAttempts:this.maxReconnectAttempts};this.onReconnectingCallback&&this.onReconnectingCallback(t),this.trackEvent(exports.RiviumPushAnalyticsEvent.RETRY_STARTED,{retryAttempt:this.reconnectAttempts,nextRetryMs:e}),this.reconnectTimer=setTimeout(()=>{this.connectToGateway()},e)}handleMqttMessage(e,t){var i;const s=this.normalizeMessage(t);this.log(exports.RiviumPushLogLevel.DEBUG,"Message received:",s.title),this.trackEvent(exports.RiviumPushAnalyticsEvent.MESSAGE_RECEIVED,{messageId:s.messageId,title:s.title,silent:s.silent,hasImage:!!s.imageUrl,hasActions:!!(null===(i=s.actions)||void 0===i?void 0:i.length)}),this.handleBadge(s),s.silent||"visible"===document.visibilityState||(this.showRichNotification(s),this.trackEvent(exports.RiviumPushAnalyticsEvent.MESSAGE_DISPLAYED,{messageId:s.messageId,title:s.title})),this.onMessageCallback&&this.onMessageCallback(s)}normalizeMessage(e){const t=this.getLocalizedContent(e,"title"),i=this.getLocalizedContent(e,"body");return{title:t||e.title||"",body:i||e.body||"",data:e.data,silent:e.silent,imageUrl:e.imageUrl||e.image,iconUrl:e.iconUrl||e.icon,actions:e.actions,deepLink:e.deepLink,badge:e.badge,badgeAction:e.badgeAction,sound:e.sound,threadId:e.threadId,collapseKey:e.collapseKey,category:e.category,priority:e.priority,ttl:e.ttl,localizations:e.localizations,timezone:e.timezone,messageId:e.messageId,campaignId:e.campaignId,icon:e.iconUrl||e.icon,image:e.imageUrl||e.image,tag:e.tag||e.collapseKey||e.threadId}}getLocalizedContent(e,t){if(!e.localizations||!Array.isArray(e.localizations))return null;const i=navigator.language.split("-")[0].toLowerCase(),s=e.localizations.find(e=>e.locale.toLowerCase().startsWith(i));return s?s[t]:null}handleBadge(e){if(void 0===e.badge&&!e.badgeAction)return;const t=e.badgeAction||"set";let i=e.badge||0;switch(t){case"set":i=e.badge||0;break;case"increment":i=this.badgeCount+(e.badge||1);break;case"decrement":i=Math.max(0,this.badgeCount-(e.badge||1));break;case"clear":i=0}this.setBadgeCount(i)}handleServiceWorkerMessage(e){var t;const i=e.data;if("push-message"===i.type){this.log(exports.RiviumPushLogLevel.DEBUG,"Push message received from SW:",null===(t=i.message)||void 0===t?void 0:t.title);const e=this.normalizeMessage(i.message);this.trackEvent(exports.RiviumPushAnalyticsEvent.MESSAGE_RECEIVED,{messageId:e.messageId,title:e.title,source:"web-push"}),this.handleBadge(e),this.onMessageCallback&&this.onMessageCallback(e)}else if("notification-click"===i.type){this.log(exports.RiviumPushLogLevel.INFO,"Notification clicked from SW");const e=this.normalizeMessage(i.message||{});this.trackEvent(exports.RiviumPushAnalyticsEvent.NOTIFICATION_CLICKED,{messageId:e.messageId,title:e.title,action:i.action}),this.onNotificationClickCallback&&this.onNotificationClickCallback(e,i.action)}else if("action-clicked"===i.type){this.log(exports.RiviumPushLogLevel.INFO,"Action clicked from SW:",i.actionId);const e=this.normalizeMessage(i.message||{});this.trackEvent(exports.RiviumPushAnalyticsEvent.ACTION_CLICKED,{actionId:i.actionId,messageId:e.messageId,title:e.title}),this.onActionClickedCallback&&this.onActionClickedCallback(i.actionId,e)}else"initial-message"===i.type?(this.log(exports.RiviumPushLogLevel.INFO,"Initial message received from SW"),this.initialMessage=this.normalizeMessage(i.message||{}),this.onNotificationClickCallback&&this.initialMessage&&this.onNotificationClickCallback(this.initialMessage,void 0)):"navigate"===i.type&&(this.log(exports.RiviumPushLogLevel.INFO,"Navigating to:",i.url),i.url&&"undefined"!=typeof window&&(window.location.href=i.url))}showRichNotification(e){if("granted"!==Notification.permission)return;const t={body:e.body,icon:e.iconUrl||e.icon,badge:e.iconUrl||e.icon,image:e.imageUrl||e.image,tag:e.tag||e.collapseKey||e.threadId,data:{...e.data,deepLink:e.deepLink,messageId:e.messageId,campaignId:e.campaignId,riviumPushMessage:e},requireInteraction:"high"===e.priority,silent:"none"===e.sound};if(e.actions&&e.actions.length>0){const i=e.actions.slice(0,2).map(e=>({action:e.id,title:e.title,icon:e.icon}));this.serviceWorkerRegistration&&(t.actions=i)}if(this.serviceWorkerRegistration)this.serviceWorkerRegistration.showNotification(e.title,t);else{const i=new Notification(e.title,t);i.onclick=()=>{window.focus(),e.deepLink&&(window.location.href=e.deepLink),this.onNotificationClickCallback&&this.onNotificationClickCallback(e),this.trackEvent(exports.RiviumPushAnalyticsEvent.NOTIFICATION_CLICKED,{messageId:e.messageId,title:e.title}),i.close()}}}updateFaviconBadge(e){try{const t=document.createElement("canvas"),i=t.getContext("2d");if(!i)return;const s=32;t.width=s,t.height=s;const o=document.querySelector('link[rel="icon"]'),n=(null==o?void 0:o.href)||"/favicon.ico",r=new Image;r.crossOrigin="anonymous",r.onload=()=>{if(i.drawImage(r,0,0,s,s),e>0){const t=14,o=s-t/2,n=t/2;i.beginPath(),i.arc(o,n,t/2+1,0,2*Math.PI),i.fillStyle="#ef4444",i.fill(),i.fillStyle="#ffffff",i.font="bold 10px sans-serif",i.textAlign="center",i.textBaseline="middle",i.fillText(e>99?"99+":e.toString(),o,n)}const n=document.createElement("link");n.rel="icon",n.href=t.toDataURL("image/png"),o&&o.remove(),document.head.appendChild(n)},r.src=n}catch(e){this.log(exports.RiviumPushLogLevel.WARNING,"Could not update favicon badge:",e)}}setConnectionState(e){this.connectionState=e,this.onConnectionStateCallback&&this.onConnectionStateCallback(e)}getOrCreateDeviceId(){const e="rivium_push_device_id";let t=localStorage.getItem(e);return t||(t="web_"+this.generateUUID(),localStorage.setItem(e,t)),t}generateUUID(){return"undefined"!=typeof crypto&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}urlBase64ToUint8Array(e){const t=(e+"=".repeat((4-e.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/"),i=window.atob(t),s=new Uint8Array(i.length);for(let e=0;e<i.length;++e)s[e]=i.charCodeAt(e);return s}}exports.RiviumPush=c,exports.RiviumPushError=s,exports.default=c;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=Object.defineProperty,t=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,n=Object.prototype.hasOwnProperty,i=(e,t)=>()=>(e&&(t=e(e=0)),t),o=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),s=(t,r)=>{for(var n in r)e(t,n,{get:r[n],enumerable:!0})},a=i=>((i,o,s,a)=>{if(o&&"object"==typeof o||"function"==typeof o)for(let l of r(o))!n.call(i,l)&&l!==s&&e(i,l,{get:()=>o[l],enumerable:!(a=t(o,l))||a.enumerable});return i})(e({},"__esModule",{value:!0}),i),l=i(()=>{}),u={};function c(e){throw new Error("Node.js process "+e+" is not supported by JSPM core outside of Node.js")}function h(){!O||!k||(O=!1,k.length?R=k.concat(R):x=-1,R.length&&f())}function f(){if(!O){var e=setTimeout(h,0);O=!0;for(var t=R.length;t;){for(k=R,R=[];++x<t;)k&&k[x].run();x=-1,t=R.length}k=null,O=!1,clearTimeout(e)}}function p(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];R.push(new d(e,t)),1===R.length&&!O&&setTimeout(f,0)}function d(e,t){this.fun=e,this.array=t}function g(){}function y(e){c("_linkedBinding")}function m(e){c("dlopen")}function b(){return[]}function v(){return[]}function w(e,t){if(!e)throw new Error(t||"assertion error")}function _(){return!1}function E(){return Ie.now()/1e3}function S(e){var t=Math.floor(.001*(Date.now()-Ie.now())),r=.001*Ie.now(),n=Math.floor(r)+t,i=Math.floor(r%1*1e9);return e&&(n-=e[0],(i-=e[1])<0&&(n--,i+=Re)),[n,i]}function I(){return je}function A(e){return[]}s(u,{_debugEnd:()=>ce,_debugProcess:()=>ue,_events:()=>ke,_eventsCount:()=>xe,_exiting:()=>z,_fatalExceptions:()=>se,_getActiveHandles:()=>v,_getActiveRequests:()=>b,_kill:()=>J,_linkedBinding:()=>y,_maxListeners:()=>Oe,_preload_modules:()=>Ee,_rawDebug:()=>V,_startProfilerIdleNotifier:()=>he,_stopProfilerIdleNotifier:()=>fe,_tickCallback:()=>le,abort:()=>ye,addListener:()=>Te,allowedNodeEnvironmentFlags:()=>ie,arch:()=>C,argv:()=>L,argv0:()=>_e,assert:()=>w,binding:()=>U,browser:()=>G,chdir:()=>$,config:()=>Q,cpuUsage:()=>X,cwd:()=>W,debugPort:()=>we,default:()=>je,dlopen:()=>m,domain:()=>K,emit:()=>Me,emitWarning:()=>j,env:()=>N,execArgv:()=>M,execPath:()=>ve,exit:()=>re,features:()=>oe,hasUncaughtExceptionCaptureCallback:()=>_,hrtime:()=>S,kill:()=>te,listeners:()=>A,memoryUsage:()=>ee,moduleLoadList:()=>H,nextTick:()=>p,off:()=>Pe,on:()=>I,once:()=>Ce,openStdin:()=>ne,pid:()=>me,platform:()=>P,ppid:()=>be,prependListener:()=>Be,prependOnceListener:()=>De,reallyExit:()=>Y,release:()=>q,removeAllListeners:()=>Le,removeListener:()=>Ne,resourceUsage:()=>Z,setSourceMapsEnabled:()=>Se,setUncaughtExceptionCaptureCallback:()=>ae,stderr:()=>de,stdin:()=>ge,stdout:()=>pe,title:()=>T,umask:()=>F,uptime:()=>E,version:()=>B,versions:()=>D});var R,O,k,x,T,C,P,N,L,M,B,D,j,U,F,W,$,q,G,V,H,K,z,Q,Y,J,X,Z,ee,te,re,ne,ie,oe,se,ae,le,ue,ce,he,fe,pe,de,ge,ye,me,be,ve,we,_e,Ee,Se,Ie,Ae,Re,Oe,ke,xe,Te,Ce,Pe,Ne,Le,Me,Be,De,je,Ue=i(()=>{l(),tt(),Fe(),R=[],O=!1,x=-1,d.prototype.run=function(){this.fun.apply(null,this.array)},T="browser",C="x64",P="browser",N={PATH:"/usr/bin",LANG:typeof navigator<"u"?navigator.language+".UTF-8":void 0,PWD:"/",HOME:"/home",TMP:"/tmp"},L=["/usr/bin/node"],M=[],B="v16.8.0",D={},j=function(e,t){console.warn((t?t+": ":"")+e)},U=function(e){c("binding")},F=function(e){return 0},W=function(){return"/"},$=function(e){},q={name:"node",sourceUrl:"",headersUrl:"",libUrl:""},G=!0,V=g,H=[],K={},z=!1,Q={},Y=g,J=g,Z=X=function(){return{}},ee=X,te=g,re=g,ne=g,ie={},oe={inspector:!1,debug:!1,uv:!1,ipv6:!1,tls_alpn:!1,tls_sni:!1,tls_ocsp:!1,tls:!1,cached_builtins:!0},se=g,ae=g,le=g,ue=g,ce=g,he=g,fe=g,pe=void 0,de=void 0,ge=void 0,ye=g,me=2,be=1,ve="/bin/usr/node",we=9229,_e="node",Ee=[],Se=g,void 0===(Ie={now:typeof performance<"u"?performance.now.bind(performance):void 0,timing:typeof performance<"u"?performance.timing:void 0}).now&&(Ae=Date.now(),Ie.timing&&Ie.timing.navigationStart&&(Ae=Ie.timing.navigationStart),Ie.now=()=>Date.now()-Ae),Re=1e9,S.bigint=function(e){var t=S(e);return typeof BigInt>"u"?t[0]*Re+t[1]:BigInt(t[0]*Re)+BigInt(t[1])},je={version:B,versions:D,arch:C,platform:P,browser:G,release:q,_rawDebug:V,moduleLoadList:H,binding:U,_linkedBinding:y,_events:ke={},_eventsCount:xe=0,_maxListeners:Oe=10,on:I,addListener:Te=I,once:Ce=I,off:Pe=I,removeListener:Ne=I,removeAllListeners:Le=I,emit:Me=g,prependListener:Be=I,prependOnceListener:De=I,listeners:A,domain:K,_exiting:z,config:Q,dlopen:m,uptime:E,_getActiveRequests:b,_getActiveHandles:v,reallyExit:Y,_kill:J,cpuUsage:X,resourceUsage:Z,memoryUsage:ee,kill:te,exit:re,openStdin:ne,allowedNodeEnvironmentFlags:ie,assert:w,features:oe,_fatalExceptions:se,setUncaughtExceptionCaptureCallback:ae,hasUncaughtExceptionCaptureCallback:_,emitWarning:j,nextTick:p,_tickCallback:le,_debugProcess:ue,_debugEnd:ce,_startProfilerIdleNotifier:he,_stopProfilerIdleNotifier:fe,stdout:pe,stdin:ge,stderr:de,abort:ye,umask:F,chdir:$,cwd:W,env:N,title:T,argv:L,execArgv:M,pid:me,ppid:be,execPath:ve,debugPort:we,hrtime:S,argv0:_e,_preload_modules:Ee,setSourceMapsEnabled:Se}}),Fe=i(()=>{Ue()});function We(){if(Ke)return He;Ke=!0;let e=function(){if(qe)return $e;qe=!0,$e.byteLength=function(e){var t=o(e),r=t[0],n=t[1];return 3*(r+n)/4-n},$e.toByteArray=function(e){var n,i,s=o(e),a=s[0],l=s[1],u=new r(function(e,t,r){return 3*(t+r)/4-r}(0,a,l)),c=0,h=l>0?a-4:a;for(i=0;i<h;i+=4)n=t[e.charCodeAt(i)]<<18|t[e.charCodeAt(i+1)]<<12|t[e.charCodeAt(i+2)]<<6|t[e.charCodeAt(i+3)],u[c++]=n>>16&255,u[c++]=n>>8&255,u[c++]=255&n;return 2===l&&(n=t[e.charCodeAt(i)]<<2|t[e.charCodeAt(i+1)]>>4,u[c++]=255&n),1===l&&(n=t[e.charCodeAt(i)]<<10|t[e.charCodeAt(i+1)]<<4|t[e.charCodeAt(i+2)]>>2,u[c++]=n>>8&255,u[c++]=255&n),u},$e.fromByteArray=function(t){for(var r,n=t.length,i=n%3,o=[],s=16383,l=0,u=n-i;l<u;l+=s)o.push(a(t,l,l+s>u?u:l+s));return 1===i?(r=t[n-1],o.push(e[r>>2]+e[r<<4&63]+"==")):2===i&&(r=(t[n-2]<<8)+t[n-1],o.push(e[r>>10]+e[r>>4&63]+e[r<<2&63]+"=")),o.join("")};for(var e=[],t=[],r=typeof Uint8Array<"u"?Uint8Array:Array,n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=0;i<64;++i)e[i]=n[i],t[n.charCodeAt(i)]=i;function o(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function s(t){return e[t>>18&63]+e[t>>12&63]+e[t>>6&63]+e[63&t]}function a(e,t,r){for(var n,i=[],o=t;o<r;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(255&e[o+2]),i.push(s(n));return i.join("")}return t[45]=62,t[95]=63,$e}(),t=(Ve||(Ve=!0,Ge.read=function(e,t,r,n,i){var o,s,a=8*i-n-1,l=(1<<a)-1,u=l>>1,c=-7,h=r?i-1:0,f=r?-1:1,p=e[t+h];for(h+=f,o=p&(1<<-c)-1,p>>=-c,c+=a;c>0;o=256*o+e[t+h],h+=f,c-=8);for(s=o&(1<<-c)-1,o>>=-c,c+=n;c>0;s=256*s+e[t+h],h+=f,c-=8);if(0===o)o=1-u;else{if(o===l)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,n),o-=u}return(p?-1:1)*s*Math.pow(2,o-n)},Ge.write=function(e,t,r,n,i,o){var s,a,l,u=8*o-i-1,c=(1<<u)-1,h=c>>1,f=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,d=n?1:-1,g=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=c):(s=Math.floor(Math.log(t)/Math.LN2),t*(l=Math.pow(2,-s))<1&&(s--,l*=2),(t+=s+h>=1?f/l:f*Math.pow(2,1-h))*l>=2&&(s++,l/=2),s+h>=c?(a=0,s=c):s+h>=1?(a=(t*l-1)*Math.pow(2,i),s+=h):(a=t*Math.pow(2,h-1)*Math.pow(2,i),s=0));i>=8;e[r+p]=255&a,p+=d,a/=256,i-=8);for(s=s<<i|a,u+=i;u>0;e[r+p]=255&s,p+=d,s/=256,u-=8);e[r+p-d]|=128*g}),Ge),r="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;He.Buffer=o,He.SlowBuffer=function(e){return+e!=e&&(e=0),o.alloc(+e)},He.INSPECT_MAX_BYTES=50;let n=2147483647;function i(e){if(e>n)throw new RangeError('The value "'+e+'" is invalid for option "size"');let t=new Uint8Array(e);return Object.setPrototypeOf(t,o.prototype),t}function o(e,t,r){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return l(e)}return s(e,t,r)}function s(e,t,r){if("string"==typeof e)return function(e,t){if(("string"!=typeof t||""===t)&&(t="utf8"),!o.isEncoding(t))throw new TypeError("Unknown encoding: "+t);let r=0|f(e,t),n=i(r),s=n.write(e,t);return s!==r&&(n=n.slice(0,s)),n}(e,t);if(ArrayBuffer.isView(e))return function(e){if(H(e,Uint8Array)){let t=new Uint8Array(e);return c(t.buffer,t.byteOffset,t.byteLength)}return u(e)}(e);if(null==e)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(H(e,ArrayBuffer)||e&&H(e.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(H(e,SharedArrayBuffer)||e&&H(e.buffer,SharedArrayBuffer)))return c(e,t,r);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');let n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return o.from(n,t,r);let s=function(e){if(o.isBuffer(e)){let t=0|h(e.length),r=i(t);return 0===r.length||e.copy(r,0,0,t),r}if(void 0!==e.length)return"number"!=typeof e.length||K(e.length)?i(0):u(e);if("Buffer"===e.type&&Array.isArray(e.data))return u(e.data)}(e);if(s)return s;if(typeof Symbol<"u"&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return o.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function a(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function l(e){return a(e),i(e<0?0:0|h(e))}function u(e){let t=e.length<0?0:0|h(e.length),r=i(t);for(let n=0;n<t;n+=1)r[n]=255&e[n];return r}function c(e,t,r){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');let n;return n=void 0===t&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,t):new Uint8Array(e,t,r),Object.setPrototypeOf(n,o.prototype),n}function h(e){if(e>=n)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+n.toString(16)+" bytes");return 0|e}function f(e,t){if(o.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||H(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);let r=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;let i=!1;for(;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return q(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return G(e).length;default:if(i)return n?-1:q(e).length;t=(""+t).toLowerCase(),i=!0}}function p(e,t,r){let n=!1;if((void 0===t||t<0)&&(t=0),t>this.length||((void 0===r||r>this.length)&&(r=this.length),r<=0)||(r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return O(this,t,r);case"utf8":case"utf-8":return S(this,t,r);case"ascii":return A(this,t,r);case"latin1":case"binary":return R(this,t,r);case"base64":return E(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return k(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function d(e,t,r){let n=e[t];e[t]=e[r],e[r]=n}function g(e,t,r,n,i){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),K(r=+r)&&(r=i?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0){if(!i)return-1;r=0}if("string"==typeof t&&(t=o.from(t,n)),o.isBuffer(t))return 0===t.length?-1:y(e,t,r,n,i);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):y(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function y(e,t,r,n,i){let o,s=1,a=e.length,l=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;s=2,a/=2,l/=2,r/=2}function u(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(i){let n=-1;for(o=r;o<a;o++)if(u(e,o)===u(t,-1===n?0:o-n)){if(-1===n&&(n=o),o-n+1===l)return n*s}else-1!==n&&(o-=o-n),n=-1}else for(r+l>a&&(r=a-l),o=r;o>=0;o--){let r=!0;for(let n=0;n<l;n++)if(u(e,o+n)!==u(t,n)){r=!1;break}if(r)return o}return-1}function m(e,t,r,n){r=Number(r)||0;let i=e.length-r;n?(n=Number(n))>i&&(n=i):n=i;let o,s=t.length;for(n>s/2&&(n=s/2),o=0;o<n;++o){let n=parseInt(t.substr(2*o,2),16);if(K(n))return o;e[r+o]=n}return o}function b(e,t,r,n){return V(q(t,e.length-r),e,r,n)}function v(e,t,r,n){return V(function(e){let t=[];for(let r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function w(e,t,r,n){return V(G(t),e,r,n)}function _(e,t,r,n){return V(function(e,t){let r,n,i,o=[];for(let s=0;s<e.length&&!((t-=2)<0);++s)r=e.charCodeAt(s),n=r>>8,i=r%256,o.push(i),o.push(n);return o}(t,e.length-r),e,r,n)}function E(t,r,n){return 0===r&&n===t.length?e.fromByteArray(t):e.fromByteArray(t.slice(r,n))}function S(e,t,r){r=Math.min(e.length,r);let n=[],i=t;for(;i<r;){let t=e[i],o=null,s=t>239?4:t>223?3:t>191?2:1;if(i+s<=r){let r,n,a,l;switch(s){case 1:t<128&&(o=t);break;case 2:r=e[i+1],128==(192&r)&&(l=(31&t)<<6|63&r,l>127&&(o=l));break;case 3:r=e[i+1],n=e[i+2],128==(192&r)&&128==(192&n)&&(l=(15&t)<<12|(63&r)<<6|63&n,l>2047&&(l<55296||l>57343)&&(o=l));break;case 4:r=e[i+1],n=e[i+2],a=e[i+3],128==(192&r)&&128==(192&n)&&128==(192&a)&&(l=(15&t)<<18|(63&r)<<12|(63&n)<<6|63&a,l>65535&&l<1114112&&(o=l))}}null===o?(o=65533,s=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|1023&o),n.push(o),i+=s}return function(e){let t=e.length;if(t<=I)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=I));return r}(n)}He.kMaxLength=n,o.TYPED_ARRAY_SUPPORT=function(){try{let e=new Uint8Array(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,Uint8Array.prototype),Object.setPrototypeOf(e,t),42===e.foo()}catch{return!1}}(),!o.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&"function"==typeof console.error&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(o.prototype,"parent",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.buffer}}),Object.defineProperty(o.prototype,"offset",{enumerable:!0,get:function(){if(o.isBuffer(this))return this.byteOffset}}),o.poolSize=8192,o.from=function(e,t,r){return s(e,t,r)},Object.setPrototypeOf(o.prototype,Uint8Array.prototype),Object.setPrototypeOf(o,Uint8Array),o.alloc=function(e,t,r){return function(e,t,r){return a(e),e<=0?i(e):void 0!==t?"string"==typeof r?i(e).fill(t,r):i(e).fill(t):i(e)}(e,t,r)},o.allocUnsafe=function(e){return l(e)},o.allocUnsafeSlow=function(e){return l(e)},o.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==o.prototype},o.compare=function(e,t){if(H(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),H(t,Uint8Array)&&(t=o.from(t,t.offset,t.byteLength)),!o.isBuffer(e)||!o.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let r=e.length,n=t.length;for(let i=0,o=Math.min(r,n);i<o;++i)if(e[i]!==t[i]){r=e[i],n=t[i];break}return r<n?-1:n<r?1:0},o.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},o.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return o.alloc(0);let r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;let n=o.allocUnsafe(t),i=0;for(r=0;r<e.length;++r){let t=e[r];if(H(t,Uint8Array))i+t.length>n.length?(o.isBuffer(t)||(t=o.from(t)),t.copy(n,i)):Uint8Array.prototype.set.call(n,t,i);else{if(!o.isBuffer(t))throw new TypeError('"list" argument must be an Array of Buffers');t.copy(n,i)}i+=t.length}return n},o.byteLength=f,o.prototype._isBuffer=!0,o.prototype.swap16=function(){let e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;t<e;t+=2)d(this,t,t+1);return this},o.prototype.swap32=function(){let e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let t=0;t<e;t+=4)d(this,t,t+3),d(this,t+1,t+2);return this},o.prototype.swap64=function(){let e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let t=0;t<e;t+=8)d(this,t,t+7),d(this,t+1,t+6),d(this,t+2,t+5),d(this,t+3,t+4);return this},o.prototype.toString=function(){let e=this.length;return 0===e?"":0===arguments.length?S(this,0,e):p.apply(this,arguments)},o.prototype.toLocaleString=o.prototype.toString,o.prototype.equals=function(e){if(!o.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===o.compare(this,e)},o.prototype.inspect=function(){let e="",t=He.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"},r&&(o.prototype[r]=o.prototype.inspect),o.prototype.compare=function(e,t,r,n,i){if(H(e,Uint8Array)&&(e=o.from(e,e.offset,e.byteLength)),!o.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),t<0||r>e.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&t>=r)return 0;if(n>=i)return-1;if(t>=r)return 1;if(this===e)return 0;let s=(i>>>=0)-(n>>>=0),a=(r>>>=0)-(t>>>=0),l=Math.min(s,a),u=this.slice(n,i),c=e.slice(t,r);for(let e=0;e<l;++e)if(u[e]!==c[e]){s=u[e],a=c[e];break}return s<a?-1:a<s?1:0},o.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},o.prototype.indexOf=function(e,t,r){return g(this,e,t,r,!0)},o.prototype.lastIndexOf=function(e,t,r){return g(this,e,t,r,!1)},o.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}let i=this.length-t;if((void 0===r||r>i)&&(r=i),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");let o=!1;for(;;)switch(n){case"hex":return m(this,e,t,r);case"utf8":case"utf-8":return b(this,e,t,r);case"ascii":case"latin1":case"binary":return v(this,e,t,r);case"base64":return w(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return _(this,e,t,r);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};let I=4096;function A(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(127&e[i]);return n}function R(e,t,r){let n="";r=Math.min(e.length,r);for(let i=t;i<r;++i)n+=String.fromCharCode(e[i]);return n}function O(e,t,r){let n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);let i="";for(let n=t;n<r;++n)i+=z[e[n]];return i}function k(e,t,r){let n=e.slice(t,r),i="";for(let e=0;e<n.length-1;e+=2)i+=String.fromCharCode(n[e]+256*n[e+1]);return i}function x(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function T(e,t,r,n,i,s){if(!o.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<s)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}function C(e,t,r,n,i){U(t,n,i,e,r,7);let o=Number(t&BigInt(4294967295));e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o,o>>=8,e[r++]=o;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s,s>>=8,e[r++]=s,r}function P(e,t,r,n,i){U(t,n,i,e,r,7);let o=Number(t&BigInt(4294967295));e[r+7]=o,o>>=8,e[r+6]=o,o>>=8,e[r+5]=o,o>>=8,e[r+4]=o;let s=Number(t>>BigInt(32)&BigInt(4294967295));return e[r+3]=s,s>>=8,e[r+2]=s,s>>=8,e[r+1]=s,s>>=8,e[r]=s,r+8}function N(e,t,r,n,i,o){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function L(e,r,n,i,o){return r=+r,n>>>=0,o||N(e,0,n,4),t.write(e,r,n,i,23,4),n+4}function M(e,r,n,i,o){return r=+r,n>>>=0,o||N(e,0,n,8),t.write(e,r,n,i,52,8),n+8}o.prototype.slice=function(e,t){let r=this.length;(e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e);let n=this.subarray(e,t);return Object.setPrototypeOf(n,o.prototype),n},o.prototype.readUintLE=o.prototype.readUIntLE=function(e,t,r){e>>>=0,t>>>=0,r||x(e,t,this.length);let n=this[e],i=1,o=0;for(;++o<t&&(i*=256);)n+=this[e+o]*i;return n},o.prototype.readUintBE=o.prototype.readUIntBE=function(e,t,r){e>>>=0,t>>>=0,r||x(e,t,this.length);let n=this[e+--t],i=1;for(;t>0&&(i*=256);)n+=this[e+--t]*i;return n},o.prototype.readUint8=o.prototype.readUInt8=function(e,t){return e>>>=0,t||x(e,1,this.length),this[e]},o.prototype.readUint16LE=o.prototype.readUInt16LE=function(e,t){return e>>>=0,t||x(e,2,this.length),this[e]|this[e+1]<<8},o.prototype.readUint16BE=o.prototype.readUInt16BE=function(e,t){return e>>>=0,t||x(e,2,this.length),this[e]<<8|this[e+1]},o.prototype.readUint32LE=o.prototype.readUInt32LE=function(e,t){return e>>>=0,t||x(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},o.prototype.readUint32BE=o.prototype.readUInt32BE=function(e,t){return e>>>=0,t||x(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},o.prototype.readBigUInt64LE=Q(function(e){F(e>>>=0,"offset");let t=this[e],r=this[e+7];(void 0===t||void 0===r)&&W(e,this.length-8);let n=t+256*this[++e]+65536*this[++e]+this[++e]*2**24,i=this[++e]+256*this[++e]+65536*this[++e]+r*2**24;return BigInt(n)+(BigInt(i)<<BigInt(32))}),o.prototype.readBigUInt64BE=Q(function(e){F(e>>>=0,"offset");let t=this[e],r=this[e+7];(void 0===t||void 0===r)&&W(e,this.length-8);let n=t*2**24+65536*this[++e]+256*this[++e]+this[++e],i=this[++e]*2**24+65536*this[++e]+256*this[++e]+r;return(BigInt(n)<<BigInt(32))+BigInt(i)}),o.prototype.readIntLE=function(e,t,r){e>>>=0,t>>>=0,r||x(e,t,this.length);let n=this[e],i=1,o=0;for(;++o<t&&(i*=256);)n+=this[e+o]*i;return i*=128,n>=i&&(n-=Math.pow(2,8*t)),n},o.prototype.readIntBE=function(e,t,r){e>>>=0,t>>>=0,r||x(e,t,this.length);let n=t,i=1,o=this[e+--n];for(;n>0&&(i*=256);)o+=this[e+--n]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*t)),o},o.prototype.readInt8=function(e,t){return e>>>=0,t||x(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},o.prototype.readInt16LE=function(e,t){e>>>=0,t||x(e,2,this.length);let r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt16BE=function(e,t){e>>>=0,t||x(e,2,this.length);let r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},o.prototype.readInt32LE=function(e,t){return e>>>=0,t||x(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},o.prototype.readInt32BE=function(e,t){return e>>>=0,t||x(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},o.prototype.readBigInt64LE=Q(function(e){F(e>>>=0,"offset");let t=this[e],r=this[e+7];(void 0===t||void 0===r)&&W(e,this.length-8);let n=this[e+4]+256*this[e+5]+65536*this[e+6]+(r<<24);return(BigInt(n)<<BigInt(32))+BigInt(t+256*this[++e]+65536*this[++e]+this[++e]*2**24)}),o.prototype.readBigInt64BE=Q(function(e){F(e>>>=0,"offset");let t=this[e],r=this[e+7];(void 0===t||void 0===r)&&W(e,this.length-8);let n=(t<<24)+65536*this[++e]+256*this[++e]+this[++e];return(BigInt(n)<<BigInt(32))+BigInt(this[++e]*2**24+65536*this[++e]+256*this[++e]+r)}),o.prototype.readFloatLE=function(e,r){return e>>>=0,r||x(e,4,this.length),t.read(this,e,!0,23,4)},o.prototype.readFloatBE=function(e,r){return e>>>=0,r||x(e,4,this.length),t.read(this,e,!1,23,4)},o.prototype.readDoubleLE=function(e,r){return e>>>=0,r||x(e,8,this.length),t.read(this,e,!0,52,8)},o.prototype.readDoubleBE=function(e,r){return e>>>=0,r||x(e,8,this.length),t.read(this,e,!1,52,8)},o.prototype.writeUintLE=o.prototype.writeUIntLE=function(e,t,r,n){if(e=+e,t>>>=0,r>>>=0,!n){T(this,e,t,r,Math.pow(2,8*r)-1,0)}let i=1,o=0;for(this[t]=255&e;++o<r&&(i*=256);)this[t+o]=e/i&255;return t+r},o.prototype.writeUintBE=o.prototype.writeUIntBE=function(e,t,r,n){if(e=+e,t>>>=0,r>>>=0,!n){T(this,e,t,r,Math.pow(2,8*r)-1,0)}let i=r-1,o=1;for(this[t+i]=255&e;--i>=0&&(o*=256);)this[t+i]=e/o&255;return t+r},o.prototype.writeUint8=o.prototype.writeUInt8=function(e,t,r){return e=+e,t>>>=0,r||T(this,e,t,1,255,0),this[t]=255&e,t+1},o.prototype.writeUint16LE=o.prototype.writeUInt16LE=function(e,t,r){return e=+e,t>>>=0,r||T(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},o.prototype.writeUint16BE=o.prototype.writeUInt16BE=function(e,t,r){return e=+e,t>>>=0,r||T(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},o.prototype.writeUint32LE=o.prototype.writeUInt32LE=function(e,t,r){return e=+e,t>>>=0,r||T(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},o.prototype.writeUint32BE=o.prototype.writeUInt32BE=function(e,t,r){return e=+e,t>>>=0,r||T(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},o.prototype.writeBigUInt64LE=Q(function(e,t=0){return C(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),o.prototype.writeBigUInt64BE=Q(function(e,t=0){return P(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))}),o.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t>>>=0,!n){let n=Math.pow(2,8*r-1);T(this,e,t,r,n-1,-n)}let i=0,o=1,s=0;for(this[t]=255&e;++i<r&&(o*=256);)e<0&&0===s&&0!==this[t+i-1]&&(s=1),this[t+i]=(e/o|0)-s&255;return t+r},o.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t>>>=0,!n){let n=Math.pow(2,8*r-1);T(this,e,t,r,n-1,-n)}let i=r-1,o=1,s=0;for(this[t+i]=255&e;--i>=0&&(o*=256);)e<0&&0===s&&0!==this[t+i+1]&&(s=1),this[t+i]=(e/o|0)-s&255;return t+r},o.prototype.writeInt8=function(e,t,r){return e=+e,t>>>=0,r||T(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},o.prototype.writeInt16LE=function(e,t,r){return e=+e,t>>>=0,r||T(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},o.prototype.writeInt16BE=function(e,t,r){return e=+e,t>>>=0,r||T(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},o.prototype.writeInt32LE=function(e,t,r){return e=+e,t>>>=0,r||T(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},o.prototype.writeInt32BE=function(e,t,r){return e=+e,t>>>=0,r||T(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},o.prototype.writeBigInt64LE=Q(function(e,t=0){return C(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),o.prototype.writeBigInt64BE=Q(function(e,t=0){return P(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))}),o.prototype.writeFloatLE=function(e,t,r){return L(this,e,t,!0,r)},o.prototype.writeFloatBE=function(e,t,r){return L(this,e,t,!1,r)},o.prototype.writeDoubleLE=function(e,t,r){return M(this,e,t,!0,r)},o.prototype.writeDoubleBE=function(e,t,r){return M(this,e,t,!1,r)},o.prototype.copy=function(e,t,r,n){if(!o.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),!n&&0!==n&&(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r||0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-r&&(n=e.length-t+r);let i=n-r;return this===e&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(t,r,n):Uint8Array.prototype.set.call(e,this.subarray(r,n),t),i},o.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!o.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===e.length){let t=e.charCodeAt(0);("utf8"===n&&t<128||"latin1"===n)&&(e=t)}}else"number"==typeof e?e&=255:"boolean"==typeof e&&(e=Number(e));if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;let i;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(i=t;i<r;++i)this[i]=e;else{let s=o.isBuffer(e)?e:o.from(e,n),a=s.length;if(0===a)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(i=0;i<r-t;++i)this[i+t]=s[i%a]}return this};let B={};function D(e,t,r){B[e]=class extends r{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(e){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:e,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}function j(e){let t="",r=e.length,n="-"===e[0]?1:0;for(;r>=n+4;r-=3)t=`_${e.slice(r-3,r)}${t}`;return`${e.slice(0,r)}${t}`}function U(e,t,r,n,i,o){if(e>r||e<t){let r,n="bigint"==typeof t?"n":"";throw r=0===t||t===BigInt(0)?`>= 0${n} and < 2${n} ** ${8*(o+1)}${n}`:`>= -(2${n} ** ${8*(o+1)-1}${n}) and < 2 ** ${8*(o+1)-1}${n}`,new B.ERR_OUT_OF_RANGE("value",r,e)}!function(e,t,r){F(t,"offset"),(void 0===e[t]||void 0===e[t+r])&&W(t,e.length-(r+1))}(n,i,o)}function F(e,t){if("number"!=typeof e)throw new B.ERR_INVALID_ARG_TYPE(t,"number",e)}function W(e,t,r){throw Math.floor(e)!==e?(F(e,r),new B.ERR_OUT_OF_RANGE("offset","an integer",e)):t<0?new B.ERR_BUFFER_OUT_OF_BOUNDS:new B.ERR_OUT_OF_RANGE("offset",`>= 0 and <= ${t}`,e)}D("ERR_BUFFER_OUT_OF_BOUNDS",function(e){return e?`${e} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"},RangeError),D("ERR_INVALID_ARG_TYPE",function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`},TypeError),D("ERR_OUT_OF_RANGE",function(e,t,r){let n=`The value of "${e}" is out of range.`,i=r;return Number.isInteger(r)&&Math.abs(r)>2**32?i=j(String(r)):"bigint"==typeof r&&(i=String(r),(r>BigInt(2)**BigInt(32)||r<-(BigInt(2)**BigInt(32)))&&(i=j(i)),i+="n"),n+=` It must be ${t}. Received ${i}`,n},RangeError);let $=/[^+/0-9A-Za-z-_]/g;function q(e,t){t=t||1/0;let r,n=e.length,i=null,o=[];for(let s=0;s<n;++s){if(r=e.charCodeAt(s),r>55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&o.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&o.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&o.push(239,191,189),i=r;continue}r=65536+(i-55296<<10|r-56320)}else i&&(t-=3)>-1&&o.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;o.push(r)}else if(r<2048){if((t-=2)<0)break;o.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;o.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;o.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return o}function G(t){return e.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace($,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(t))}function V(e,t,r,n){let i;for(i=0;i<n&&!(i+r>=t.length||i>=e.length);++i)t[i+r]=e[i];return i}function H(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function K(e){return e!=e}let z=function(){let e="0123456789abcdef",t=new Array(256);for(let r=0;r<16;++r){let n=16*r;for(let i=0;i<16;++i)t[n+i]=e[r]+e[i]}return t}();function Q(e){return typeof BigInt>"u"?Y:e}function Y(){throw new Error("BigInt not supported")}return He}var $e,qe,Ge,Ve,He,Ke,ze=i(()=>{l(),tt(),Fe(),$e={},qe=!1,Ge={},Ve=!1,He={},Ke=!1}),Qe={};s(Qe,{Buffer:()=>Je,INSPECT_MAX_BYTES:()=>Xe,default:()=>Ye,kMaxLength:()=>Ze});var Ye,Je,Xe,Ze,et=i(()=>{l(),tt(),Fe(),ze(),(Ye=We()).Buffer,Ye.SlowBuffer,Ye.INSPECT_MAX_BYTES,Ye.kMaxLength,Je=Ye.Buffer,Xe=Ye.INSPECT_MAX_BYTES,Ze=Ye.kMaxLength}),tt=i(()=>{et()}),rt=o((e,t)=>{l(),tt(),Fe();var r=class extends Error{constructor(e){if(!Array.isArray(e))throw new TypeError("Expected input to be an Array, got "+typeof e);let t="";for(let r=0;r<e.length;r++)t+=` ${e[r].stack}\n`;super(t),this.name="AggregateError",this.errors=e}};t.exports={AggregateError:r,ArrayIsArray:e=>Array.isArray(e),ArrayPrototypeIncludes:(e,t)=>e.includes(t),ArrayPrototypeIndexOf:(e,t)=>e.indexOf(t),ArrayPrototypeJoin:(e,t)=>e.join(t),ArrayPrototypeMap:(e,t)=>e.map(t),ArrayPrototypePop:(e,t)=>e.pop(t),ArrayPrototypePush:(e,t)=>e.push(t),ArrayPrototypeSlice:(e,t,r)=>e.slice(t,r),Error:Error,FunctionPrototypeCall:(e,t,...r)=>e.call(t,...r),FunctionPrototypeSymbolHasInstance:(e,t)=>Function.prototype[Symbol.hasInstance].call(e,t),MathFloor:Math.floor,Number:Number,NumberIsInteger:Number.isInteger,NumberIsNaN:Number.isNaN,NumberMAX_SAFE_INTEGER:Number.MAX_SAFE_INTEGER,NumberMIN_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,NumberParseInt:Number.parseInt,ObjectDefineProperties:(e,t)=>Object.defineProperties(e,t),ObjectDefineProperty:(e,t,r)=>Object.defineProperty(e,t,r),ObjectGetOwnPropertyDescriptor:(e,t)=>Object.getOwnPropertyDescriptor(e,t),ObjectKeys:e=>Object.keys(e),ObjectSetPrototypeOf:(e,t)=>Object.setPrototypeOf(e,t),Promise:Promise,PromisePrototypeCatch:(e,t)=>e.catch(t),PromisePrototypeThen:(e,t,r)=>e.then(t,r),PromiseReject:e=>Promise.reject(e),PromiseResolve:e=>Promise.resolve(e),ReflectApply:Reflect.apply,RegExpPrototypeTest:(e,t)=>e.test(t),SafeSet:Set,String:String,StringPrototypeSlice:(e,t,r)=>e.slice(t,r),StringPrototypeToLowerCase:e=>e.toLowerCase(),StringPrototypeToUpperCase:e=>e.toUpperCase(),StringPrototypeTrim:e=>e.trim(),Symbol:Symbol,SymbolFor:Symbol.for,SymbolAsyncIterator:Symbol.asyncIterator,SymbolHasInstance:Symbol.hasInstance,SymbolIterator:Symbol.iterator,SymbolDispose:Symbol.dispose||Symbol("Symbol.dispose"),SymbolAsyncDispose:Symbol.asyncDispose||Symbol("Symbol.asyncDispose"),TypedArrayPrototypeSet:(e,t,r)=>e.set(t,r),Boolean:Boolean,Uint8Array:Uint8Array}}),nt=o((e,t)=>{l(),tt(),Fe(),t.exports={format:(e,...t)=>e.replace(/%([sdifj])/g,function(...[e,r]){let n=t.shift();return"f"===r?n.toFixed(6):"j"===r?JSON.stringify(n):"s"===r&&"object"==typeof n?`${n.constructor!==Object?n.constructor.name:""} {}`.trim():n.toString()}),inspect(e){switch(typeof e){case"string":if(e.includes("'")){if(!e.includes('"'))return`"${e}"`;if(!e.includes("`")&&!e.includes("${"))return`\`${e}\``}return`'${e}'`;case"number":return isNaN(e)?"NaN":Object.is(e,-0)?String(e):e;case"bigint":return`${String(e)}n`;case"boolean":case"undefined":return String(e);case"object":return"{}"}}}}),it=o((e,t)=>{l(),tt(),Fe();var{format:r,inspect:n}=nt(),{AggregateError:i}=rt(),o=globalThis.AggregateError||i,s=Symbol("kIsNodeError"),a=["string","function","number","object","Function","Object","boolean","bigint","symbol"],u=/^([A-Z][a-z0-9]*)+$/,c={};function h(e,t){if(!e)throw new c.ERR_INTERNAL_ASSERTION(t)}function f(e){let t="",r=e.length,n="-"===e[0]?1:0;for(;r>=n+4;r-=3)t=`_${e.slice(r-3,r)}${t}`;return`${e.slice(0,r)}${t}`}function p(e,t,n){n||(n=Error);class i extends n{constructor(...n){super(function(e,t,n){if("function"==typeof t)return h(t.length<=n.length,`Code: ${e}; The provided arguments length (${n.length}) does not match the required ones (${t.length}).`),t(...n);let i=(t.match(/%[dfijoOs]/g)||[]).length;return h(i===n.length,`Code: ${e}; The provided arguments length (${n.length}) does not match the required ones (${i}).`),0===n.length?t:r(t,...n)}(e,t,n))}toString(){return`${this.name} [${e}]: ${this.message}`}}Object.defineProperties(i.prototype,{name:{value:n.name,writable:!0,enumerable:!1,configurable:!0},toString:{value(){return`${this.name} [${e}]: ${this.message}`},writable:!0,enumerable:!1,configurable:!0}}),i.prototype.code=e,i.prototype[s]=!0,c[e]=i}function d(e){let t="__node_internal_"+e.name;return Object.defineProperty(e,"name",{value:t}),e}var g=class extends Error{constructor(e="The operation was aborted",t=void 0){if(void 0!==t&&"object"!=typeof t)throw new c.ERR_INVALID_ARG_TYPE("options","Object",t);super(e,t),this.code="ABORT_ERR",this.name="AbortError"}};p("ERR_ASSERTION","%s",Error),p("ERR_INVALID_ARG_TYPE",(e,t,r)=>{h("string"==typeof e,"'name' must be a string"),Array.isArray(t)||(t=[t]);let i="The ";e.endsWith(" argument")?i+=`${e} `:i+=`"${e}" ${e.includes(".")?"property":"argument"} `,i+="must be ";let o=[],s=[],l=[];for(let e of t)h("string"==typeof e,"All expected entries have to be of type string"),a.includes(e)?o.push(e.toLowerCase()):u.test(e)?s.push(e):(h("object"!==e,'The value "object" should be written as "Object"'),l.push(e));if(s.length>0){let e=o.indexOf("object");-1!==e&&(o.splice(o,e,1),s.push("Object"))}if(o.length>0){switch(o.length){case 1:i+=`of type ${o[0]}`;break;case 2:i+=`one of type ${o[0]} or ${o[1]}`;break;default:{let e=o.pop();i+=`one of type ${o.join(", ")}, or ${e}`}}(s.length>0||l.length>0)&&(i+=" or ")}if(s.length>0){switch(s.length){case 1:i+=`an instance of ${s[0]}`;break;case 2:i+=`an instance of ${s[0]} or ${s[1]}`;break;default:{let e=s.pop();i+=`an instance of ${s.join(", ")}, or ${e}`}}l.length>0&&(i+=" or ")}switch(l.length){case 0:break;case 1:l[0].toLowerCase()!==l[0]&&(i+="an "),i+=`${l[0]}`;break;case 2:i+=`one of ${l[0]} or ${l[1]}`;break;default:{let e=l.pop();i+=`one of ${l.join(", ")}, or ${e}`}}if(null==r)i+=`. Received ${r}`;else if("function"==typeof r&&r.name)i+=`. Received function ${r.name}`;else if("object"==typeof r){var c;if(null!==(c=r.constructor)&&void 0!==c&&c.name)i+=`. Received an instance of ${r.constructor.name}`;else{i+=`. Received ${n(r,{depth:-1})}`}}else{let e=n(r,{colors:!1});e.length>25&&(e=`${e.slice(0,25)}...`),i+=`. Received type ${typeof r} (${e})`}return i},TypeError),p("ERR_INVALID_ARG_VALUE",(e,t,r="is invalid")=>{let i=n(t);return i.length>128&&(i=i.slice(0,128)+"..."),`The ${e.includes(".")?"property":"argument"} '${e}' ${r}. Received ${i}`},TypeError),p("ERR_INVALID_RETURN_VALUE",(e,t,r)=>{var n;return`Expected ${e} to be returned from the "${t}" function but got ${null!=r&&null!==(n=r.constructor)&&void 0!==n&&n.name?`instance of ${r.constructor.name}`:"type "+typeof r}.`},TypeError),p("ERR_MISSING_ARGS",(...e)=>{h(e.length>0,"At least one arg needs to be specified");let t,r=e.length;switch(e=(Array.isArray(e)?e:[e]).map(e=>`"${e}"`).join(" or "),r){case 1:t+=`The ${e[0]} argument`;break;case 2:t+=`The ${e[0]} and ${e[1]} arguments`;break;default:{let r=e.pop();t+=`The ${e.join(", ")}, and ${r} arguments`}}return`${t} must be specified`},TypeError),p("ERR_OUT_OF_RANGE",(e,t,r)=>{let i;if(h(t,'Missing "range" argument'),Number.isInteger(r)&&Math.abs(r)>2**32)i=f(String(r));else if("bigint"==typeof r){i=String(r);let e=BigInt(2)**BigInt(32);(r>e||r<-e)&&(i=f(i)),i+="n"}else i=n(r);return`The value of "${e}" is out of range. It must be ${t}. Received ${i}`},RangeError),p("ERR_MULTIPLE_CALLBACK","Callback called multiple times",Error),p("ERR_METHOD_NOT_IMPLEMENTED","The %s method is not implemented",Error),p("ERR_STREAM_ALREADY_FINISHED","Cannot call %s after a stream was finished",Error),p("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable",Error),p("ERR_STREAM_DESTROYED","Cannot call %s after a stream was destroyed",Error),p("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),p("ERR_STREAM_PREMATURE_CLOSE","Premature close",Error),p("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF",Error),p("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event",Error),p("ERR_STREAM_WRITE_AFTER_END","write after end",Error),p("ERR_UNKNOWN_ENCODING","Unknown encoding: %s",TypeError),t.exports={AbortError:g,aggregateTwoErrors:d(function(e,t){if(e&&t&&e!==t){if(Array.isArray(t.errors))return t.errors.push(e),t;let r=new o([t,e],t.message);return r.code=t.code,r}return e||t}),hideStackFrames:d,codes:c}}),ot=o((e,t)=>{l(),tt(),Fe();var{AbortController:r,AbortSignal:n}=typeof self<"u"?self:typeof window<"u"?window:void 0;t.exports=r,t.exports.AbortSignal=n,t.exports.default=r}),st={};function at(){if(ut)return lt;ut=!0;var e,t="object"==typeof Reflect?Reflect:null,r=t&&"function"==typeof t.apply?t.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};e=t&&"function"==typeof t.ownKeys?t.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var n=Number.isNaN||function(e){return e!=e};function i(){i.init.call(this)}(lt=i).once=function(e,t){return new Promise(function(r,n){function i(r){e.removeListener(t,o),n(r)}function o(){"function"==typeof e.removeListener&&e.removeListener("error",i),r([].slice.call(arguments))}d(e,t,o,{once:!0}),"error"!==t&&function(e,t,r){"function"==typeof e.on&&d(e,"error",t,r)}(e,i,{once:!0})})},i.EventEmitter=i,i.prototype._events=void 0,i.prototype._eventsCount=0,i.prototype._maxListeners=void 0;var o=10;function s(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function a(e){return void 0===e._maxListeners?i.defaultMaxListeners:e._maxListeners}function l(e,t,r,n){var i,o,l;if(s(r),void 0===(o=e._events)?(o=e._events=Object.create(null),e._eventsCount=0):(void 0!==o.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),o=e._events),l=o[t]),void 0===l)l=o[t]=r,++e._eventsCount;else if("function"==typeof l?l=o[t]=n?[r,l]:[l,r]:n?l.unshift(r):l.push(r),(i=a(e))>0&&l.length>i&&!l.warned){l.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+l.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=l.length,function(e){console&&console.warn&&console.warn(e)}(u)}return e}function u(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function c(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=u.bind(n);return i.listener=r,n.wrapFn=i,i}function h(e,t,r){var n=e._events;if(void 0===n)return[];var i=n[t];return void 0===i?[]:"function"==typeof i?r?[i.listener||i]:[i]:r?function(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}(i):p(i,i.length)}function f(e){var t=this._events;if(void 0!==t){var r=t[e];if("function"==typeof r)return 1;if(void 0!==r)return r.length}return 0}function p(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function d(e,t,r,n){if("function"==typeof e.on)n.once?e.once(t,r):e.on(t,r);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,function i(o){n.once&&e.removeEventListener(t,i),r(o)})}}return Object.defineProperty(i,"defaultMaxListeners",{enumerable:!0,get:function(){return o},set:function(e){if("number"!=typeof e||e<0||n(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");o=e}}),i.init=function(){(void 0===this._events||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},i.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||n(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},i.prototype.getMaxListeners=function(){return a(this)},i.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var i="error"===e,o=this._events;if(void 0!==o)i=i&&void 0===o.error;else if(!i)return!1;if(i){var s;if(t.length>0&&(s=t[0]),s instanceof Error)throw s;var a=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw a.context=s,a}var l=o[e];if(void 0===l)return!1;if("function"==typeof l)r(l,this,t);else{var u=l.length,c=p(l,u);for(n=0;n<u;++n)r(c[n],this,t)}return!0},i.prototype.addListener=function(e,t){return l(this,e,t,!1)},i.prototype.on=i.prototype.addListener,i.prototype.prependListener=function(e,t){return l(this,e,t,!0)},i.prototype.once=function(e,t){return s(t),this.on(e,c(this,e,t)),this},i.prototype.prependOnceListener=function(e,t){return s(t),this.prependListener(e,c(this,e,t)),this},i.prototype.removeListener=function(e,t){var r,n,i,o,a;if(s(t),void 0===(n=this._events))return this;if(void 0===(r=n[e]))return this;if(r===t||r.listener===t)0===--this._eventsCount?this._events=Object.create(null):(delete n[e],n.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(i=-1,o=r.length-1;o>=0;o--)if(r[o]===t||r[o].listener===t){a=r[o].listener,i=o;break}if(i<0)return this;0===i?r.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(r,i),1===r.length&&(n[e]=r[0]),void 0!==n.removeListener&&this.emit("removeListener",e,a||t)}return this},i.prototype.off=i.prototype.removeListener,i.prototype.removeAllListeners=function(e){var t,r,n;if(void 0===(r=this._events))return this;if(void 0===r.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==r[e]&&(0===--this._eventsCount?this._events=Object.create(null):delete r[e]),this;if(0===arguments.length){var i,o=Object.keys(r);for(n=0;n<o.length;++n)"removeListener"!==(i=o[n])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(void 0!==t)for(n=t.length-1;n>=0;n--)this.removeListener(e,t[n]);return this},i.prototype.listeners=function(e){return h(this,e,!0)},i.prototype.rawListeners=function(e){return h(this,e,!1)},i.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):f.call(e,t)},i.prototype.listenerCount=f,i.prototype.eventNames=function(){return this._eventsCount>0?e(this._events):[]},lt}s(st,{EventEmitter:()=>ht,default:()=>ct,defaultMaxListeners:()=>ft,init:()=>pt,listenerCount:()=>dt,on:()=>gt,once:()=>yt});var lt,ut,ct,ht,ft,pt,dt,gt,yt,mt=i(()=>{l(),tt(),Fe(),lt={},ut=!1,(ct=at()).once,ct.once=function(e,t){return new Promise((r,n)=>{function i(...t){void 0!==o&&e.removeListener("error",o),r(t)}let o;"error"!==t&&(o=t=>{e.removeListener(name,i),n(t)},e.once("error",o)),e.once(t,i)})},ct.on=function(e,t){let r=[],n=[],i=null,o=!1,s={async next(){let e=r.shift();if(e)return createIterResult(e,!1);if(i){let e=Promise.reject(i);return i=null,e}return o?createIterResult(void 0,!0):new Promise((e,t)=>n.push({resolve:e,reject:t}))},async return(){e.removeListener(t,a),e.removeListener("error",l),o=!0;for(let e of n)e.resolve(createIterResult(void 0,!0));return createIterResult(void 0,!0)},throw(r){i=r,e.removeListener(t,a),e.removeListener("error",l)},[Symbol.asyncIterator](){return this}};return e.on(t,a),e.on("error",l),s;function a(...e){let t=n.shift();t?t.resolve(createIterResult(e,!1)):r.push(e)}function l(e){o=!0;let t=n.shift();t?t.reject(e):i=e,s.return()}},({EventEmitter:ht,defaultMaxListeners:ft,init:pt,listenerCount:dt,on:gt,once:yt}=ct)}),bt=o((e,t)=>{l(),tt(),Fe();var r=(et(),a(Qe)),{format:n,inspect:i}=nt(),{codes:{ERR_INVALID_ARG_TYPE:o}}=it(),{kResistStopPropagation:s,AggregateError:u,SymbolDispose:c}=rt(),h=globalThis.AbortSignal||ot().AbortSignal,f=globalThis.AbortController||ot().AbortController,p=Object.getPrototypeOf(async function(){}).constructor,d=globalThis.Blob||r.Blob,g=typeof d<"u"?function(e){return e instanceof d}:function(e){return!1},y=(e,t)=>{if(void 0!==e&&(null===e||"object"!=typeof e||!("aborted"in e)))throw new o(t,"AbortSignal",e)};t.exports={AggregateError:u,kEmptyObject:Object.freeze({}),once(e){let t=!1;return function(...r){t||(t=!0,e.apply(this,r))}},createDeferredPromise:function(){let e,t;return{promise:new Promise((r,n)=>{e=r,t=n}),resolve:e,reject:t}},promisify:e=>new Promise((t,r)=>{e((e,...n)=>e?r(e):t(...n))}),debuglog:()=>function(){},format:n,inspect:i,types:{isAsyncFunction:e=>e instanceof p,isArrayBufferView:e=>ArrayBuffer.isView(e)},isBlob:g,deprecate:(e,t)=>e,addAbortListener:(mt(),a(st)).addAbortListener||function(e,t){if(void 0===e)throw new o("signal","AbortSignal",e);let r;return y(e,"signal"),((e,t)=>{if("function"!=typeof e)throw new o(t,"Function",e)})(t,"listener"),e.aborted?queueMicrotask(()=>t()):(e.addEventListener("abort",t,{__proto__:null,once:!0,[s]:!0}),r=()=>{e.removeEventListener("abort",t)}),{__proto__:null,[c](){var e;null===(e=r)||void 0===e||e()}}},AbortSignalAny:h.any||function(e){if(1===e.length)return e[0];let t=new f,r=()=>t.abort();return e.forEach(e=>{y(e,"signals"),e.addEventListener("abort",r,{once:!0})}),t.signal.addEventListener("abort",()=>{e.forEach(e=>e.removeEventListener("abort",r))},{once:!0}),t.signal}},t.exports.promisify.custom=Symbol.for("nodejs.util.promisify.custom")}),vt=o((e,t)=>{l(),tt(),Fe();var{ArrayIsArray:r,ArrayPrototypeIncludes:n,ArrayPrototypeJoin:i,ArrayPrototypeMap:o,NumberIsInteger:s,NumberIsNaN:a,NumberMAX_SAFE_INTEGER:u,NumberMIN_SAFE_INTEGER:c,NumberParseInt:h,ObjectPrototypeHasOwnProperty:f,RegExpPrototypeExec:p,String:d,StringPrototypeToUpperCase:g,StringPrototypeTrim:y}=rt(),{hideStackFrames:m,codes:{ERR_SOCKET_BAD_PORT:b,ERR_INVALID_ARG_TYPE:v,ERR_INVALID_ARG_VALUE:w,ERR_OUT_OF_RANGE:_,ERR_UNKNOWN_SIGNAL:E}}=it(),{normalizeEncoding:S}=bt(),{isAsyncFunction:I,isArrayBufferView:A}=bt().types,R={};var O=/^[0-7]+$/;var k=m((e,t,r=c,n=u)=>{if("number"!=typeof e)throw new v(t,"number",e);if(!s(e))throw new _(t,"an integer",e);if(e<r||e>n)throw new _(t,`>= ${r} && <= ${n}`,e)}),x=m((e,t,r=-2147483648,n=2147483647)=>{if("number"!=typeof e)throw new v(t,"number",e);if(!s(e))throw new _(t,"an integer",e);if(e<r||e>n)throw new _(t,`>= ${r} && <= ${n}`,e)}),T=m((e,t,r=!1)=>{if("number"!=typeof e)throw new v(t,"number",e);if(!s(e))throw new _(t,"an integer",e);let n=r?1:0,i=4294967295;if(e<n||e>i)throw new _(t,`>= ${n} && <= ${i}`,e)});function C(e,t){if("string"!=typeof e)throw new v(t,"string",e)}var P=m((e,t,r)=>{if(!n(r,e)){let n="must be one of: "+i(o(r,e=>"string"==typeof e?`'${e}'`:d(e)),", ");throw new w(t,e,n)}});function N(e,t){if("boolean"!=typeof e)throw new v(t,"boolean",e)}function L(e,t,r){return null!=e&&f(e,t)?e[t]:r}var M=m((e,t,n=null)=>{let i=L(n,"allowArray",!1),o=L(n,"allowFunction",!1);if(!L(n,"nullable",!1)&&null===e||!i&&r(e)||"object"!=typeof e&&(!o||"function"!=typeof e))throw new v(t,"Object",e)}),B=m((e,t)=>{if(null!=e&&"object"!=typeof e&&"function"!=typeof e)throw new v(t,"a dictionary",e)}),D=m((e,t,n=0)=>{if(!r(e))throw new v(t,"Array",e);if(e.length<n){throw new w(t,e,`must be longer than ${n}`)}});var j=m((e,t="buffer")=>{if(!A(e))throw new v(t,["Buffer","TypedArray","DataView"],e)});var U=m((e,t)=>{if(void 0!==e&&(null===e||"object"!=typeof e||!("aborted"in e)))throw new v(t,"AbortSignal",e)}),F=m((e,t)=>{if("function"!=typeof e)throw new v(t,"Function",e)}),W=m((e,t)=>{if("function"!=typeof e||I(e))throw new v(t,"Function",e)}),$=m((e,t)=>{if(void 0!==e)throw new v(t,"undefined",e)});var q=/^(?:<[^>]*>)(?:\s*;\s*[^;"\s]+(?:=(")?[^;"\s]*\1)?)*$/;function G(e,t){if(typeof e>"u"||!p(q,e))throw new w(t,e,'must be an array or string of format "</styles.css>; rel=preload; as=style"')}t.exports={isInt32:function(e){return e===(0|e)},isUint32:function(e){return e===e>>>0},parseFileMode:function(e,t,r){if(typeof e>"u"&&(e=r),"string"==typeof e){if(null===p(O,e))throw new w(t,e,"must be a 32-bit unsigned integer or an octal string");e=h(e,8)}return T(e,t),e},validateArray:D,validateStringArray:function(e,t){D(e,t);for(let r=0;r<e.length;r++)C(e[r],`${t}[${r}]`)},validateBooleanArray:function(e,t){D(e,t);for(let r=0;r<e.length;r++)N(e[r],`${t}[${r}]`)},validateAbortSignalArray:function(e,t){D(e,t);for(let r=0;r<e.length;r++){let n=e[r],i=`${t}[${r}]`;if(null==n)throw new v(i,"AbortSignal",n);U(n,i)}},validateBoolean:N,validateBuffer:j,validateDictionary:B,validateEncoding:function(e,t){let r=S(t),n=e.length;if("hex"===r&&n%2!=0)throw new w("encoding",t,`is invalid for data of length ${n}`)},validateFunction:F,validateInt32:x,validateInteger:k,validateNumber:function(e,t,r=void 0,n){if("number"!=typeof e)throw new v(t,"number",e);if(null!=r&&e<r||null!=n&&e>n||(null!=r||null!=n)&&a(e))throw new _(t,`${null!=r?`>= ${r}`:""}${null!=r&&null!=n?" && ":""}${null!=n?`<= ${n}`:""}`,e)},validateObject:M,validateOneOf:P,validatePlainFunction:W,validatePort:function(e,t="Port",r=!0){if("number"!=typeof e&&"string"!=typeof e||"string"==typeof e&&0===y(e).length||+e!==+e>>>0||e>65535||0===e&&!r)throw new b(t,e,r);return 0|e},validateSignalName:function(e,t="signal"){if(C(e,t),void 0===R[e])throw void 0!==R[g(e)]?new E(e+" (signals must use all capital letters)"):new E(e)},validateString:C,validateUint32:T,validateUndefined:$,validateUnion:function(e,t,r){if(!n(r,e))throw new v(t,`('${i(r,"|")}')`,e)},validateAbortSignal:U,validateLinkHeaderValue:function(e){if("string"==typeof e)return G(e,"hints"),e;if(r(e)){let t=e.length,r="";if(0===t)return r;for(let n=0;n<t;n++){let i=e[n];G(i,"hints"),r+=i,n!==t-1&&(r+=", ")}return r}throw new w("hints",e,'must be an array or string of format "</styles.css>; rel=preload; as=style"')}}}),wt=o((e,t)=>{l(),tt(),Fe();var r,n,i=t.exports={};function o(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function a(e){if(r===setTimeout)return setTimeout(e,0);if((r===o||!r)&&setTimeout)return r=setTimeout,setTimeout(e,0);try{return r(e,0)}catch{try{return r.call(null,e,0)}catch{return r.call(this,e,0)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:o}catch{r=o}try{n="function"==typeof clearTimeout?clearTimeout:s}catch{n=s}}();var u,c=[],h=!1,f=-1;function p(){!h||!u||(h=!1,u.length?c=u.concat(c):f=-1,c.length&&d())}function d(){if(!h){var e=a(p);h=!0;for(var t=c.length;t;){for(u=c,c=[];++f<t;)u&&u[f].run();f=-1,t=c.length}u=null,h=!1,function(e){if(n===clearTimeout)return clearTimeout(e);if((n===s||!n)&&clearTimeout)return n=clearTimeout,clearTimeout(e);try{return n(e)}catch{try{return n.call(null,e)}catch{return n.call(this,e)}}}(e)}}function g(e,t){this.fun=e,this.array=t}function y(){}i.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];c.push(new g(e,t)),1===c.length&&!h&&a(d)},g.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=y,i.addListener=y,i.once=y,i.off=y,i.removeListener=y,i.removeAllListeners=y,i.emit=y,i.prependListener=y,i.prependOnceListener=y,i.listeners=function(e){return[]},i.binding=function(e){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(e){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}}),_t=o((e,t)=>{l(),tt(),Fe();var{SymbolAsyncIterator:r,SymbolIterator:n,SymbolFor:i}=rt(),o=i("nodejs.stream.destroyed"),s=i("nodejs.stream.errored"),a=i("nodejs.stream.readable"),u=i("nodejs.stream.writable"),c=i("nodejs.stream.disturbed"),h=i("nodejs.webstream.isClosedPromise"),f=i("nodejs.webstream.controllerErrorFunction");function p(e,t=!1){var r;return!(!e||"function"!=typeof e.pipe||"function"!=typeof e.on||t&&("function"!=typeof e.pause||"function"!=typeof e.resume)||e._writableState&&!1===(null===(r=e._readableState)||void 0===r?void 0:r.readable)||e._writableState&&!e._readableState)}function d(e){var t;return!(!e||"function"!=typeof e.write||"function"!=typeof e.on||e._readableState&&!1===(null===(t=e._writableState)||void 0===t?void 0:t.writable))}function g(e){return e&&(e._readableState||e._writableState||"function"==typeof e.write&&"function"==typeof e.on||"function"==typeof e.pipe&&"function"==typeof e.on)}function y(e){return!(!e||g(e)||"function"!=typeof e.pipeThrough||"function"!=typeof e.getReader||"function"!=typeof e.cancel)}function m(e){return!(!e||g(e)||"function"!=typeof e.getWriter||"function"!=typeof e.abort)}function b(e){return!(!e||g(e)||"object"!=typeof e.readable||"object"!=typeof e.writable)}function v(e){if(!g(e))return null;let t=e._writableState,r=e._readableState,n=t||r;return!!(e.destroyed||e[o]||null!=n&&n.destroyed)}function w(e){if(!d(e))return null;if(!0===e.writableEnded)return!0;let t=e._writableState;return(null==t||!t.errored)&&("boolean"!=typeof t?.ended?null:t.ended)}function _(e,t){if(!p(e))return null;let r=e._readableState;return(null==r||!r.errored)&&("boolean"!=typeof r?.endEmitted?null:!!(r.endEmitted||!1===t&&!0===r.ended&&0===r.length))}function E(e){return e&&null!=e[a]?e[a]:"boolean"!=typeof e?.readable?null:!v(e)&&(p(e)&&e.readable&&!_(e))}function S(e){return e&&null!=e[u]?e[u]:"boolean"!=typeof e?.writable?null:!v(e)&&(d(e)&&e.writable&&!w(e))}function I(e){return"boolean"==typeof e._closed&&"boolean"==typeof e._defaultKeepAlive&&"boolean"==typeof e._removedConnection&&"boolean"==typeof e._removedContLen}function A(e){return"boolean"==typeof e._sent100&&I(e)}t.exports={isDestroyed:v,kIsDestroyed:o,isDisturbed:function(e){var t;return!(!e||!(null!==(t=e[c])&&void 0!==t?t:e.readableDidRead||e.readableAborted))},kIsDisturbed:c,isErrored:function(e){var t,r,n,i,o,a,l,u,c,h;return!(!e||!(null!==(t=null!==(r=null!==(n=null!==(i=null!==(o=null!==(a=e[s])&&void 0!==a?a:e.readableErrored)&&void 0!==o?o:e.writableErrored)&&void 0!==i?i:null===(l=e._readableState)||void 0===l?void 0:l.errorEmitted)&&void 0!==n?n:null===(u=e._writableState)||void 0===u?void 0:u.errorEmitted)&&void 0!==r?r:null===(c=e._readableState)||void 0===c?void 0:c.errored)&&void 0!==t?t:null!==(h=e._writableState)&&void 0!==h&&h.errored))},kIsErrored:s,isReadable:E,kIsReadable:a,kIsClosedPromise:h,kControllerErrorFunction:f,kIsWritable:u,isClosed:function(e){if(!g(e))return null;if("boolean"==typeof e.closed)return e.closed;let t=e._writableState,r=e._readableState;return"boolean"==typeof t?.closed||"boolean"==typeof r?.closed?t?.closed||r?.closed:"boolean"==typeof e._closed&&I(e)?e._closed:null},isDuplexNodeStream:function(e){return!(!e||"function"!=typeof e.pipe||!e._readableState||"function"!=typeof e.on||"function"!=typeof e.write)},isFinished:function(e,t){return g(e)?!!v(e)||!(!1!==t?.readable&&E(e)||!1!==t?.writable&&S(e)):null},isIterable:function(e,t){return null!=e&&(!0===t?"function"==typeof e[r]:!1===t?"function"==typeof e[n]:"function"==typeof e[r]||"function"==typeof e[n])},isReadableNodeStream:p,isReadableStream:y,isReadableEnded:function(e){if(!p(e))return null;if(!0===e.readableEnded)return!0;let t=e._readableState;return!(!t||t.errored)&&("boolean"!=typeof t?.ended?null:t.ended)},isReadableFinished:_,isReadableErrored:function(e){var t,r;return g(e)?e.readableErrored?e.readableErrored:null!==(t=null===(r=e._readableState)||void 0===r?void 0:r.errored)&&void 0!==t?t:null:null},isNodeStream:g,isWebStream:function(e){return y(e)||m(e)||b(e)},isWritable:S,isWritableNodeStream:d,isWritableStream:m,isWritableEnded:w,isWritableFinished:function(e,t){if(!d(e))return null;if(!0===e.writableFinished)return!0;let r=e._writableState;return(null==r||!r.errored)&&("boolean"!=typeof r?.finished?null:!!(r.finished||!1===t&&!0===r.ended&&0===r.length))},isWritableErrored:function(e){var t,r;return g(e)?e.writableErrored?e.writableErrored:null!==(t=null===(r=e._writableState)||void 0===r?void 0:r.errored)&&void 0!==t?t:null:null},isServerRequest:function(e){var t;return"boolean"==typeof e._consuming&&"boolean"==typeof e._dumped&&void 0===(null===(t=e.req)||void 0===t?void 0:t.upgradeOrConnect)},isServerResponse:A,willEmitClose:function(e){if(!g(e))return null;let t=e._writableState,r=e._readableState,n=t||r;return!n&&A(e)||!!(n&&n.autoDestroy&&n.emitClose&&!1===n.closed)},isTransformStream:b}}),Et=o((e,t)=>{l(),tt(),Fe();var r,n=wt(),{AbortError:i,codes:o}=it(),{ERR_INVALID_ARG_TYPE:s,ERR_STREAM_PREMATURE_CLOSE:a}=o,{kEmptyObject:u,once:c}=bt(),{validateAbortSignal:h,validateFunction:f,validateObject:p,validateBoolean:d}=vt(),{Promise:g,PromisePrototypeThen:y,SymbolDispose:m}=rt(),{isClosed:b,isReadable:v,isReadableNodeStream:w,isReadableStream:_,isReadableFinished:E,isReadableErrored:S,isWritable:I,isWritableNodeStream:A,isWritableStream:R,isWritableFinished:O,isWritableErrored:k,isNodeStream:x,willEmitClose:T,kIsClosedPromise:C}=_t();var P=()=>{};function N(e,t,o){var l,d;if(2===arguments.length?(o=t,t=u):null==t?t=u:p(t,"options"),f(o,"callback"),h(t.signal,"options.signal"),o=c(o),_(e)||R(e))return function(e,t,o){let s=!1,a=P;if(t.signal)if(a=()=>{s=!0,o.call(e,new i(void 0,{cause:t.signal.reason}))},t.signal.aborted)n.nextTick(a);else{let n=(r=r||bt().addAbortListener)(t.signal,a),i=o;o=c((...t)=>{n[m](),i.apply(e,t)})}let l=(...t)=>{s||n.nextTick(()=>o.apply(e,t))};return y(e[C].promise,l,l),P}(e,t,o);if(!x(e))throw new s("stream",["ReadableStream","WritableStream","Stream"],e);let g=null!==(l=t.readable)&&void 0!==l?l:w(e),N=null!==(d=t.writable)&&void 0!==d?d:A(e),L=e._writableState,M=e._readableState,B=()=>{e.writable||U()},D=T(e)&&w(e)===g&&A(e)===N,j=O(e,!1),U=()=>{j=!0,e.destroyed&&(D=!1),(!D||e.readable&&!g)&&(!g||F)&&o.call(e)},F=E(e,!1),W=()=>{F=!0,e.destroyed&&(D=!1),(!D||e.writable&&!N)&&(!N||j)&&o.call(e)},$=t=>{o.call(e,t)},q=b(e),G=()=>{q=!0;let t=k(e)||S(e);return t&&"boolean"!=typeof t?o.call(e,t):g&&!F&&w(e,!0)&&!E(e,!1)?o.call(e,new a):!N||j||O(e,!1)?void o.call(e):o.call(e,new a)},V=()=>{q=!0;let t=k(e)||S(e);if(t&&"boolean"!=typeof t)return o.call(e,t);o.call(e)},H=()=>{e.req.on("finish",U)};!function(e){return e.setHeader&&"function"==typeof e.abort}(e)?N&&!L&&(e.on("end",B),e.on("close",B)):(e.on("complete",U),D||e.on("abort",G),e.req?H():e.on("request",H)),!D&&"boolean"==typeof e.aborted&&e.on("aborted",G),e.on("end",W),e.on("finish",U),!1!==t.error&&e.on("error",$),e.on("close",G),q?n.nextTick(G):null!=L&&L.errorEmitted||null!=M&&M.errorEmitted?D||n.nextTick(V):(!g&&(!D||v(e))&&(j||!1===I(e))||!N&&(!D||I(e))&&(F||!1===v(e))||M&&e.req&&e.aborted)&&n.nextTick(V);let K=()=>{o=P,e.removeListener("aborted",G),e.removeListener("complete",U),e.removeListener("abort",G),e.removeListener("request",H),e.req&&e.req.removeListener("finish",U),e.removeListener("end",B),e.removeListener("close",B),e.removeListener("finish",U),e.removeListener("end",W),e.removeListener("error",$),e.removeListener("close",G)};if(t.signal&&!q){let s=()=>{let r=o;K(),r.call(e,new i(void 0,{cause:t.signal.reason}))};if(t.signal.aborted)n.nextTick(s);else{let n=(r=r||bt().addAbortListener)(t.signal,s),i=o;o=c((...t)=>{n[m](),i.apply(e,t)})}}return K}t.exports=N,t.exports.finished=function(e,t){var r;let n=!1;return null===t&&(t=u),null!==(r=t)&&void 0!==r&&r.cleanup&&(d(t.cleanup,"cleanup"),n=t.cleanup),new g((r,i)=>{let o=N(e,t,e=>{n&&o(),e?i(e):r()})})}}),St=o((e,t)=>{l(),tt(),Fe();var r=wt(),{aggregateTwoErrors:n,codes:{ERR_MULTIPLE_CALLBACK:i},AbortError:o}=it(),{Symbol:s}=rt(),{kIsDestroyed:a,isDestroyed:u,isFinished:c,isServerRequest:h}=_t(),f=s("kDestroy"),p=s("kConstruct");function d(e,t,r){e&&(e.stack,t&&!t.errored&&(t.errored=e),r&&!r.errored&&(r.errored=e))}function g(e,t,n){let i=!1;function o(t){if(i)return;i=!0;let o=e._readableState,s=e._writableState;d(t,s,o),s&&(s.closed=!0),o&&(o.closed=!0),"function"==typeof n&&n(t),t?r.nextTick(y,e,t):r.nextTick(m,e)}try{e._destroy(t||null,o)}catch(e){o(e)}}function y(e,t){b(e,t),m(e)}function m(e){let t=e._readableState,r=e._writableState;r&&(r.closeEmitted=!0),t&&(t.closeEmitted=!0),(null!=r&&r.emitClose||null!=t&&t.emitClose)&&e.emit("close")}function b(e,t){let r=e._readableState,n=e._writableState;null!=n&&n.errorEmitted||null!=r&&r.errorEmitted||(n&&(n.errorEmitted=!0),r&&(r.errorEmitted=!0),e.emit("error",t))}function v(e,t,n){let i=e._readableState,o=e._writableState;if(null!=o&&o.destroyed||null!=i&&i.destroyed)return this;null!=i&&i.autoDestroy||null!=o&&o.autoDestroy?e.destroy(t):t&&(t.stack,o&&!o.errored&&(o.errored=t),i&&!i.errored&&(i.errored=t),n?r.nextTick(b,e,t):b(e,t))}function w(e){let t=!1;function n(n){if(t)return void v(e,n??new i);t=!0;let o=e._readableState,s=e._writableState,a=s||o;o&&(o.constructed=!0),s&&(s.constructed=!0),a.destroyed?e.emit(f,n):n?v(e,n,!0):r.nextTick(_,e)}try{e._construct(e=>{r.nextTick(n,e)})}catch(e){r.nextTick(n,e)}}function _(e){e.emit(p)}function E(e){return e?.setHeader&&"function"==typeof e.abort}function S(e){e.emit("close")}function I(e,t){e.emit("error",t),r.nextTick(S,e)}t.exports={construct:function(e,t){if("function"!=typeof e._construct)return;let n=e._readableState,i=e._writableState;n&&(n.constructed=!1),i&&(i.constructed=!1),e.once(p,t),!(e.listenerCount(p)>1)&&r.nextTick(w,e)},destroyer:function(e,t){!e||u(e)||(!t&&!c(e)&&(t=new o),h(e)?(e.socket=null,e.destroy(t)):E(e)?e.abort():E(e.req)?e.req.abort():"function"==typeof e.destroy?e.destroy(t):"function"==typeof e.close?e.close():t?r.nextTick(I,e,t):r.nextTick(S,e),e.destroyed||(e[a]=!0))},destroy:function(e,t){let r=this._readableState,i=this._writableState,o=i||r;return null!=i&&i.destroyed||null!=r&&r.destroyed?("function"==typeof t&&t(),this):(d(e,i,r),i&&(i.destroyed=!0),r&&(r.destroyed=!0),o.constructed?g(this,e,t):this.once(f,function(r){g(this,n(r,e),t)}),this)},undestroy:function(){let e=this._readableState,t=this._writableState;e&&(e.constructed=!0,e.closed=!1,e.closeEmitted=!1,e.destroyed=!1,e.errored=null,e.errorEmitted=!1,e.reading=!1,e.ended=!1===e.readable,e.endEmitted=!1===e.readable),t&&(t.constructed=!0,t.destroyed=!1,t.closed=!1,t.closeEmitted=!1,t.errored=null,t.errorEmitted=!1,t.finalCalled=!1,t.prefinished=!1,t.ended=!1===t.writable,t.ending=!1===t.writable,t.finished=!1===t.writable)},errorOrDestroy:v}}),It=o((e,t)=>{l(),tt(),Fe();var{ArrayIsArray:r,ObjectSetPrototypeOf:n}=rt(),{EventEmitter:i}=(mt(),a(st));function o(e){i.call(this,e)}function s(e,t,n){if("function"==typeof e.prependListener)return e.prependListener(t,n);e._events&&e._events[t]?r(e._events[t])?e._events[t].unshift(n):e._events[t]=[n,e._events[t]]:e.on(t,n)}n(o.prototype,i.prototype),n(o,i),o.prototype.pipe=function(e,t){let r=this;function n(t){e.writable&&!1===e.write(t)&&r.pause&&r.pause()}function o(){r.readable&&r.resume&&r.resume()}r.on("data",n),e.on("drain",o),!e._isStdio&&(!t||!1!==t.end)&&(r.on("end",l),r.on("close",u));let a=!1;function l(){a||(a=!0,e.end())}function u(){a||(a=!0,"function"==typeof e.destroy&&e.destroy())}function c(e){h(),0===i.listenerCount(this,"error")&&this.emit("error",e)}function h(){r.removeListener("data",n),e.removeListener("drain",o),r.removeListener("end",l),r.removeListener("close",u),r.removeListener("error",c),e.removeListener("error",c),r.removeListener("end",h),r.removeListener("close",h),e.removeListener("close",h)}return s(r,"error",c),s(e,"error",c),r.on("end",h),r.on("close",h),e.on("close",h),e.emit("pipe",r),e},t.exports={Stream:o,prependListener:s}}),At=o((e,t)=>{l(),tt(),Fe();var r,{SymbolDispose:n}=rt(),{AbortError:i,codes:o}=it(),{isNodeStream:s,isWebStream:a,kControllerErrorFunction:u}=_t(),c=Et(),{ERR_INVALID_ARG_TYPE:h}=o;t.exports.addAbortSignal=function(e,r){if(((e,t)=>{if("object"!=typeof e||!("aborted"in e))throw new h(t,"AbortSignal",e)})(e,"signal"),!s(r)&&!a(r))throw new h("stream",["ReadableStream","WritableStream","Stream"],r);return t.exports.addAbortSignalNoValidate(e,r)},t.exports.addAbortSignalNoValidate=function(e,t){if("object"!=typeof e||!("aborted"in e))return t;let o=s(t)?()=>{t.destroy(new i(void 0,{cause:e.reason}))}:()=>{t[u](new i(void 0,{cause:e.reason}))};if(e.aborted)o();else{let i=(r=r||bt().addAbortListener)(e,o);c(t,i[n])}return t}}),Rt=o((e,t)=>{l(),tt(),Fe();var{StringPrototypeSlice:r,SymbolIterator:n,TypedArrayPrototypeSet:i,Uint8Array:o}=rt(),{Buffer:s}=(et(),a(Qe)),{inspect:u}=bt();t.exports=class{constructor(){this.head=null,this.tail=null,this.length=0}push(e){let t={data:e,next:null};this.length>0?this.tail.next=t:this.head=t,this.tail=t,++this.length}unshift(e){let t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length}shift(){if(0===this.length)return;let e=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,e}clear(){this.head=this.tail=null,this.length=0}join(e){if(0===this.length)return"";let t=this.head,r=""+t.data;for(;null!==(t=t.next);)r+=e+t.data;return r}concat(e){if(0===this.length)return s.alloc(0);let t=s.allocUnsafe(e>>>0),r=this.head,n=0;for(;r;)i(t,r.data,n),n+=r.data.length,r=r.next;return t}consume(e,t){let r=this.head.data;if(e<r.length){let t=r.slice(0,e);return this.head.data=r.slice(e),t}return e===r.length?this.shift():t?this._getString(e):this._getBuffer(e)}first(){return this.head.data}*[n](){for(let e=this.head;e;e=e.next)yield e.data}_getString(e){let t="",n=this.head,i=0;do{let o=n.data;if(!(e>o.length)){e===o.length?(t+=o,++i,n.next?this.head=n.next:this.head=this.tail=null):(t+=r(o,0,e),this.head=n,n.data=r(o,e));break}t+=o,e-=o.length,++i}while(null!==(n=n.next));return this.length-=i,t}_getBuffer(e){let t=s.allocUnsafe(e),r=e,n=this.head,a=0;do{let s=n.data;if(!(e>s.length)){e===s.length?(i(t,s,r-e),++a,n.next?this.head=n.next:this.head=this.tail=null):(i(t,new o(s.buffer,s.byteOffset,e),r-e),this.head=n,n.data=s.slice(e));break}i(t,s,r-e),e-=s.length,++a}while(null!==(n=n.next));return this.length-=a,t}[Symbol.for("nodejs.util.inspect.custom")](e,t){return u(this,{...t,depth:0,customInspect:!1})}}}),Ot=o((e,t)=>{l(),tt(),Fe();var{MathFloor:r,NumberIsInteger:n}=rt(),{validateInteger:i}=vt(),{ERR_INVALID_ARG_VALUE:o}=it().codes,s=16384,a=16;function u(e){return e?a:s}t.exports={getHighWaterMark:function(e,t,i,s){let a=function(e,t,r){return null!=e.highWaterMark?e.highWaterMark:t?e[r]:null}(t,s,i);if(null!=a){if(!n(a)||a<0){throw new o(s?`options.${i}`:"options.highWaterMark",a)}return r(a)}return u(e.objectMode)},getDefaultHighWaterMark:u,setDefaultHighWaterMark:function(e,t){i(t,"value",0),e?a=t:s=t}}}),kt=o((e,t)=>{l(),tt(),Fe();var r=(et(),a(Qe)),n=r.Buffer;function i(e,t){for(var r in e)t[r]=e[r]}function o(e,t,r){return n(e,t,r)}n.from&&n.alloc&&n.allocUnsafe&&n.allocUnsafeSlow?t.exports=r:(i(r,e),e.Buffer=o),o.prototype=Object.create(n.prototype),i(n,o),o.from=function(e,t,r){if("number"==typeof e)throw new TypeError("Argument must not be a number");return n(e,t,r)},o.alloc=function(e,t,r){if("number"!=typeof e)throw new TypeError("Argument must be a number");var i=n(e);return void 0!==t?"string"==typeof r?i.fill(t,r):i.fill(t):i.fill(0),i},o.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return n(e)},o.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return r.SlowBuffer(e)}}),xt=o(e=>{l(),tt(),Fe();var t=kt().Buffer,r=t.isEncoding||function(e){switch((e=""+e)&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function n(e){var n;switch(this.encoding=function(e){var n=function(e){if(!e)return"utf8";for(var t;;)switch(e){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return e;default:if(t)return;e=(""+e).toLowerCase(),t=!0}}(e);if("string"!=typeof n&&(t.isEncoding===r||!r(e)))throw new Error("Unknown encoding: "+e);return n||e}(e),this.encoding){case"utf16le":this.text=s,this.end=a,n=4;break;case"utf8":this.fillLast=o,n=4;break;case"base64":this.text=u,this.end=c,n=3;break;default:return this.write=h,void(this.end=f)}this.lastNeed=0,this.lastTotal=0,this.lastChar=t.allocUnsafe(n)}function i(e){return e<=127?0:e>>5==6?2:e>>4==14?3:e>>3==30?4:e>>6==2?-1:-2}function o(e){var t=this.lastTotal-this.lastNeed,r=function(e,t){if(128!=(192&t[0]))return e.lastNeed=0,"�";if(e.lastNeed>1&&t.length>1){if(128!=(192&t[1]))return e.lastNeed=1,"�";if(e.lastNeed>2&&t.length>2&&128!=(192&t[2]))return e.lastNeed=2,"�"}}(this,e);return void 0!==r?r:this.lastNeed<=e.length?(e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(e.copy(this.lastChar,t,0,e.length),void(this.lastNeed-=e.length))}function s(e,t){if((e.length-t)%2==0){var r=e.toString("utf16le",t);if(r){var n=r.charCodeAt(r.length-1);if(n>=55296&&n<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],r.slice(0,-1)}return r}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString("utf16le",t,e.length-1)}function a(e){var t=e&&e.length?this.write(e):"";if(this.lastNeed){var r=this.lastTotal-this.lastNeed;return t+this.lastChar.toString("utf16le",0,r)}return t}function u(e,t){var r=(e.length-t)%3;return 0===r?e.toString("base64",t):(this.lastNeed=3-r,this.lastTotal=3,1===r?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString("base64",t,e.length-r))}function c(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+this.lastChar.toString("base64",0,3-this.lastNeed):t}function h(e){return e.toString(this.encoding)}function f(e){return e&&e.length?this.write(e):""}e.StringDecoder=n,n.prototype.write=function(e){if(0===e.length)return"";var t,r;if(this.lastNeed){if(void 0===(t=this.fillLast(e)))return"";r=this.lastNeed,this.lastNeed=0}else r=0;return r<e.length?t?t+this.text(e,r):this.text(e,r):t||""},n.prototype.end=function(e){var t=e&&e.length?this.write(e):"";return this.lastNeed?t+"�":t},n.prototype.text=function(e,t){var r=function(e,t,r){var n=t.length-1;if(n<r)return 0;var o=i(t[n]);return o>=0?(o>0&&(e.lastNeed=o-1),o):--n<r||-2===o?0:(o=i(t[n]),o>=0?(o>0&&(e.lastNeed=o-2),o):--n<r||-2===o?0:(o=i(t[n]),o>=0?(o>0&&(2===o?o=0:e.lastNeed=o-3),o):0))}(this,e,t);if(!this.lastNeed)return e.toString("utf8",t);this.lastTotal=r;var n=e.length-(r-this.lastNeed);return e.copy(this.lastChar,0,n),e.toString("utf8",t,n)},n.prototype.fillLast=function(e){if(this.lastNeed<=e.length)return e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length}}),Tt=o((e,t)=>{l(),tt(),Fe();var r=wt(),{PromisePrototypeThen:n,SymbolAsyncIterator:i,SymbolIterator:o}=rt(),{Buffer:s}=(et(),a(Qe)),{ERR_INVALID_ARG_TYPE:u,ERR_STREAM_NULL_VALUES:c}=it().codes;t.exports=function(e,t,a){let l,h;if("string"==typeof t||t instanceof s)return new e({objectMode:!0,...a,read(){this.push(t),this.push(null)}});if(t&&t[i])h=!0,l=t[i]();else{if(!t||!t[o])throw new u("iterable",["Iterable"],t);h=!1,l=t[o]()}let f=new e({objectMode:!0,highWaterMark:1,...a}),p=!1;return f._read=function(){p||(p=!0,async function(){for(;;){try{let{value:e,done:t}=h?await l.next():l.next();if(t)f.push(null);else{let t=e&&"function"==typeof e.then?await e:e;if(null===t)throw p=!1,new c;if(f.push(t))continue;p=!1}}catch(e){f.destroy(e)}break}}())},f._destroy=function(e,t){n(async function(e){let t=null!=e,r="function"==typeof l.throw;if(t&&r){let{value:t,done:r}=await l.throw(e);if(await t,r)return}if("function"==typeof l.return){let{value:e}=await l.return();await e}}(e),()=>r.nextTick(t,e),n=>r.nextTick(t,n||e))},f}}),Ct=o((e,t)=>{l(),tt(),Fe();var r=wt(),{ArrayPrototypeIndexOf:n,NumberIsInteger:i,NumberIsNaN:o,NumberParseInt:s,ObjectDefineProperties:u,ObjectKeys:c,ObjectSetPrototypeOf:h,Promise:f,SafeSet:p,SymbolAsyncDispose:d,SymbolAsyncIterator:g,Symbol:y}=rt();t.exports=z,z.ReadableState=K;var{EventEmitter:m}=(mt(),a(st)),{Stream:b,prependListener:v}=It(),{Buffer:w}=(et(),a(Qe)),{addAbortSignal:_}=At(),E=Et(),S=bt().debuglog("stream",e=>{S=e}),I=Rt(),A=St(),{getHighWaterMark:R,getDefaultHighWaterMark:O}=Ot(),{aggregateTwoErrors:k,codes:{ERR_INVALID_ARG_TYPE:x,ERR_METHOD_NOT_IMPLEMENTED:T,ERR_OUT_OF_RANGE:C,ERR_STREAM_PUSH_AFTER_EOF:P,ERR_STREAM_UNSHIFT_AFTER_END_EVENT:N},AbortError:L}=it(),{validateObject:M}=vt(),B=y("kPaused"),{StringDecoder:D}=xt(),j=Tt();h(z.prototype,b.prototype),h(z,b);var U=()=>{},{errorOrDestroy:F}=A,W=1,$=16,q=32,G=2048,V=4096;function H(e){return{enumerable:!1,get(){return 0!==(this.state&e)},set(t){t?this.state|=e:this.state&=~e}}}function K(e,t,r){"boolean"!=typeof r&&(r=t instanceof Lt()),this.state=G|V|$|q,e&&e.objectMode&&(this.state|=W),r&&e&&e.readableObjectMode&&(this.state|=W),this.highWaterMark=e?R(this,e,"readableHighWaterMark",r):O(!1),this.buffer=new I,this.length=0,this.pipes=[],this.flowing=null,this[B]=null,e&&!1===e.emitClose&&(this.state&=~G),e&&!1===e.autoDestroy&&(this.state&=~V),this.errored=null,this.defaultEncoding=e&&e.defaultEncoding||"utf8",this.awaitDrainWriters=null,this.decoder=null,this.encoding=null,e&&e.encoding&&(this.decoder=new D(e.encoding),this.encoding=e.encoding)}function z(e){if(!(this instanceof z))return new z(e);let t=this instanceof Lt();this._readableState=new K(e,this,t),e&&("function"==typeof e.read&&(this._read=e.read),"function"==typeof e.destroy&&(this._destroy=e.destroy),"function"==typeof e.construct&&(this._construct=e.construct),e.signal&&!t&&_(e.signal,this)),b.call(this,e),A.construct(this,()=>{this._readableState.needReadable&&te(this,this._readableState)})}function Q(e,t,r,n){S("readableAddChunk",t);let i,o=e._readableState;if(0===(o.state&W)&&("string"==typeof t?(r=r||o.defaultEncoding,o.encoding!==r&&(n&&o.encoding?t=w.from(t,r).toString(o.encoding):(t=w.from(t,r),r=""))):t instanceof w?r="":b._isUint8Array(t)?(t=b._uint8ArrayToBuffer(t),r=""):null!=t&&(i=new x("chunk",["string","Buffer","Uint8Array"],t))),i)F(e,i);else if(null===t)o.state&=-9,function(e,t){if(S("onEofChunk"),!t.ended){if(t.decoder){let e=t.decoder.end();e&&e.length&&(t.buffer.push(e),t.length+=t.objectMode?1:e.length)}t.ended=!0,t.sync?Z(e):(t.needReadable=!1,t.emittedReadable=!0,ee(e))}}(e,o);else if(0!==(o.state&W)||t&&t.length>0)if(n)if(4&o.state)F(e,new N);else{if(o.destroyed||o.errored)return!1;Y(e,o,t,!0)}else if(o.ended)F(e,new P);else{if(o.destroyed||o.errored)return!1;o.state&=-9,o.decoder&&!r?(t=o.decoder.write(t),o.objectMode||0!==t.length?Y(e,o,t,!1):te(e,o)):Y(e,o,t,!1)}else n||(o.state&=-9,te(e,o));return!o.ended&&(o.length<o.highWaterMark||0===o.length)}function Y(e,t,r,n){t.flowing&&0===t.length&&!t.sync&&e.listenerCount("data")>0?(65536&t.state?t.awaitDrainWriters.clear():t.awaitDrainWriters=null,t.dataEmitted=!0,e.emit("data",r)):(t.length+=t.objectMode?1:r.length,n?t.buffer.unshift(r):t.buffer.push(r),!!(64&t.state)&&Z(e)),te(e,t)}u(K.prototype,{objectMode:H(W),ended:H(2),endEmitted:H(4),reading:H(8),constructed:H($),sync:H(q),needReadable:H(64),emittedReadable:H(128),readableListening:H(256),resumeScheduled:H(512),errorEmitted:H(1024),emitClose:H(G),autoDestroy:H(V),destroyed:H(8192),closed:H(16384),closeEmitted:H(32768),multiAwaitDrain:H(65536),readingMore:H(1<<17),dataEmitted:H(1<<18)}),z.prototype.destroy=A.destroy,z.prototype._undestroy=A.undestroy,z.prototype._destroy=function(e,t){t(e)},z.prototype[m.captureRejectionSymbol]=function(e){this.destroy(e)},z.prototype[d]=function(){let e;return this.destroyed||(e=this.readableEnded?null:new L,this.destroy(e)),new f((t,r)=>E(this,n=>n&&n!==e?r(n):t(null)))},z.prototype.push=function(e,t){return Q(this,e,t,!1)},z.prototype.unshift=function(e,t){return Q(this,e,t,!0)},z.prototype.isPaused=function(){let e=this._readableState;return!0===e[B]||!1===e.flowing},z.prototype.setEncoding=function(e){let t=new D(e);this._readableState.decoder=t,this._readableState.encoding=this._readableState.decoder.encoding;let r=this._readableState.buffer,n="";for(let e of r)n+=t.write(e);return r.clear(),""!==n&&r.push(n),this._readableState.length=n.length,this};var J;function X(e,t){return e<=0||0===t.length&&t.ended?0:0!==(t.state&W)?1:o(e)?t.flowing&&t.length?t.buffer.first().length:t.length:e<=t.length?e:t.ended?t.length:0}function Z(e){let t=e._readableState;S("emitReadable",t.needReadable,t.emittedReadable),t.needReadable=!1,t.emittedReadable||(S("emitReadable",t.flowing),t.emittedReadable=!0,r.nextTick(ee,e))}function ee(e){let t=e._readableState;S("emitReadable_",t.destroyed,t.length,t.ended),!t.destroyed&&!t.errored&&(t.length||t.ended)&&(e.emit("readable"),t.emittedReadable=!1),t.needReadable=!t.flowing&&!t.ended&&t.length<=t.highWaterMark,se(e)}function te(e,t){!t.readingMore&&t.constructed&&(t.readingMore=!0,r.nextTick(re,e,t))}function re(e,t){for(;!t.reading&&!t.ended&&(t.length<t.highWaterMark||t.flowing&&0===t.length);){let r=t.length;if(S("maybeReadMore read 0"),e.read(0),r===t.length)break}t.readingMore=!1}function ne(e){let t=e._readableState;t.readableListening=e.listenerCount("readable")>0,t.resumeScheduled&&!1===t[B]?t.flowing=!0:e.listenerCount("data")>0?e.resume():t.readableListening||(t.flowing=null)}function ie(e){S("readable nexttick read 0"),e.read(0)}function oe(e,t){S("resume",t.reading),t.reading||e.read(0),t.resumeScheduled=!1,e.emit("resume"),se(e),t.flowing&&!t.reading&&e.read(0)}function se(e){let t=e._readableState;for(S("flow",t.flowing);t.flowing&&null!==e.read(););}function ae(e,t){"function"!=typeof e.read&&(e=z.wrap(e,{objectMode:!0}));let r=async function*(e,t){let r=U;function n(t){this===e?(r(),r=U):r=t}e.on("readable",n);let i,o=E(e,{writable:!1},e=>{i=e?k(i,e):null,r(),r=U});try{for(;;){let t=e.destroyed?null:e.read();if(null!==t)yield t;else{if(i)throw i;if(null===i)return;await new f(n)}}}catch(e){throw i=k(i,e),i}finally{!i&&!1===t?.destroyOnReturn||void 0!==i&&!e._readableState.autoDestroy?(e.off("readable",n),o()):A.destroyer(e,null)}}(e,t);return r.stream=e,r}function le(e,t){if(0===t.length)return null;let r;return t.objectMode?r=t.buffer.shift():!e||e>=t.length?(r=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.first():t.buffer.concat(t.length),t.buffer.clear()):r=t.buffer.consume(e,t.decoder),r}function ue(e){let t=e._readableState;S("endReadable",t.endEmitted),t.endEmitted||(t.ended=!0,r.nextTick(ce,t,e))}function ce(e,t){if(S("endReadableNT",e.endEmitted,e.length),!e.errored&&!e.closeEmitted&&!e.endEmitted&&0===e.length)if(e.endEmitted=!0,t.emit("end"),t.writable&&!1===t.allowHalfOpen)r.nextTick(he,t);else if(e.autoDestroy){let e=t._writableState;(!e||e.autoDestroy&&(e.finished||!1===e.writable))&&t.destroy()}}function he(e){e.writable&&!e.writableEnded&&!e.destroyed&&e.end()}function fe(){return void 0===J&&(J={}),J}z.prototype.read=function(e){S("read",e),void 0===e?e=NaN:i(e)||(e=s(e,10));let t=this._readableState,r=e;if(e>t.highWaterMark&&(t.highWaterMark=function(e){if(e>1073741824)throw new C("size","<= 1GiB",e);return e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,++e}(e)),0!==e&&(t.state&=-129),0===e&&t.needReadable&&((0!==t.highWaterMark?t.length>=t.highWaterMark:t.length>0)||t.ended))return S("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?ue(this):Z(this),null;if(0===(e=X(e,t))&&t.ended)return 0===t.length&&ue(this),null;let n,o=!!(64&t.state);if(S("need readable",o),(0===t.length||t.length-e<t.highWaterMark)&&(o=!0,S("length less than watermark",o)),t.ended||t.reading||t.destroyed||t.errored||!t.constructed)o=!1,S("reading, ended or constructing",o);else if(o){S("do read"),t.state|=8|q,0===t.length&&(t.state|=64);try{this._read(t.highWaterMark)}catch(e){F(this,e)}t.state&=~q,t.reading||(e=X(r,t))}return n=e>0?le(e,t):null,null===n?(t.needReadable=t.length<=t.highWaterMark,e=0):(t.length-=e,t.multiAwaitDrain?t.awaitDrainWriters.clear():t.awaitDrainWriters=null),0===t.length&&(t.ended||(t.needReadable=!0),r!==e&&t.ended&&ue(this)),null!==n&&!t.errorEmitted&&!t.closeEmitted&&(t.dataEmitted=!0,this.emit("data",n)),n},z.prototype._read=function(e){throw new T("_read()")},z.prototype.pipe=function(e,t){let n=this,i=this._readableState;1===i.pipes.length&&(i.multiAwaitDrain||(i.multiAwaitDrain=!0,i.awaitDrainWriters=new p(i.awaitDrainWriters?[i.awaitDrainWriters]:[]))),i.pipes.push(e),S("pipe count=%d opts=%j",i.pipes.length,t);let o=t&&!1===t.end||e===r.stdout||e===r.stderr?y:a;function s(t,r){S("onunpipe"),t===n&&r&&!1===r.hasUnpiped&&(r.hasUnpiped=!0,S("cleanup"),e.removeListener("close",d),e.removeListener("finish",g),l&&e.removeListener("drain",l),e.removeListener("error",f),e.removeListener("unpipe",s),n.removeListener("end",a),n.removeListener("end",y),n.removeListener("data",h),u=!0,l&&i.awaitDrainWriters&&(!e._writableState||e._writableState.needDrain)&&l())}function a(){S("onend"),e.end()}i.endEmitted?r.nextTick(o):n.once("end",o),e.on("unpipe",s);let l,u=!1;function c(){u||(1===i.pipes.length&&i.pipes[0]===e?(S("false write response, pause",0),i.awaitDrainWriters=e,i.multiAwaitDrain=!1):i.pipes.length>1&&i.pipes.includes(e)&&(S("false write response, pause",i.awaitDrainWriters.size),i.awaitDrainWriters.add(e)),n.pause()),l||(l=function(e,t){return function(){let r=e._readableState;r.awaitDrainWriters===t?(S("pipeOnDrain",1),r.awaitDrainWriters=null):r.multiAwaitDrain&&(S("pipeOnDrain",r.awaitDrainWriters.size),r.awaitDrainWriters.delete(t)),(!r.awaitDrainWriters||0===r.awaitDrainWriters.size)&&e.listenerCount("data")&&e.resume()}}(n,e),e.on("drain",l))}function h(t){S("ondata");let r=e.write(t);S("dest.write",r),!1===r&&c()}function f(t){if(S("onerror",t),y(),e.removeListener("error",f),0===e.listenerCount("error")){let r=e._writableState||e._readableState;r&&!r.errorEmitted?F(e,t):e.emit("error",t)}}function d(){e.removeListener("finish",g),y()}function g(){S("onfinish"),e.removeListener("close",d),y()}function y(){S("unpipe"),n.unpipe(e)}return n.on("data",h),v(e,"error",f),e.once("close",d),e.once("finish",g),e.emit("pipe",n),!0===e.writableNeedDrain?c():i.flowing||(S("pipe resume"),n.resume()),e},z.prototype.unpipe=function(e){let t=this._readableState;if(0===t.pipes.length)return this;if(!e){let e=t.pipes;t.pipes=[],this.pause();for(let t=0;t<e.length;t++)e[t].emit("unpipe",this,{hasUnpiped:!1});return this}let r=n(t.pipes,e);return-1===r||(t.pipes.splice(r,1),0===t.pipes.length&&this.pause(),e.emit("unpipe",this,{hasUnpiped:!1})),this},z.prototype.on=function(e,t){let n=b.prototype.on.call(this,e,t),i=this._readableState;return"data"===e?(i.readableListening=this.listenerCount("readable")>0,!1!==i.flowing&&this.resume()):"readable"===e&&!i.endEmitted&&!i.readableListening&&(i.readableListening=i.needReadable=!0,i.flowing=!1,i.emittedReadable=!1,S("on readable",i.length,i.reading),i.length?Z(this):i.reading||r.nextTick(ie,this)),n},z.prototype.addListener=z.prototype.on,z.prototype.removeListener=function(e,t){let n=b.prototype.removeListener.call(this,e,t);return"readable"===e&&r.nextTick(ne,this),n},z.prototype.off=z.prototype.removeListener,z.prototype.removeAllListeners=function(e){let t=b.prototype.removeAllListeners.apply(this,arguments);return("readable"===e||void 0===e)&&r.nextTick(ne,this),t},z.prototype.resume=function(){let e=this._readableState;return e.flowing||(S("resume"),e.flowing=!e.readableListening,function(e,t){t.resumeScheduled||(t.resumeScheduled=!0,r.nextTick(oe,e,t))}(this,e)),e[B]=!1,this},z.prototype.pause=function(){return S("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(S("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState[B]=!0,this},z.prototype.wrap=function(e){let t=!1;e.on("data",r=>{!this.push(r)&&e.pause&&(t=!0,e.pause())}),e.on("end",()=>{this.push(null)}),e.on("error",e=>{F(this,e)}),e.on("close",()=>{this.destroy()}),e.on("destroy",()=>{this.destroy()}),this._read=()=>{t&&e.resume&&(t=!1,e.resume())};let r=c(e);for(let t=1;t<r.length;t++){let n=r[t];void 0===this[n]&&"function"==typeof e[n]&&(this[n]=e[n].bind(e))}return this},z.prototype[g]=function(){return ae(this)},z.prototype.iterator=function(e){return void 0!==e&&M(e,"options"),ae(this,e)},u(z.prototype,{readable:{__proto__:null,get(){let e=this._readableState;return!(!e||!1===e.readable||e.destroyed||e.errorEmitted||e.endEmitted)},set(e){this._readableState&&(this._readableState.readable=!!e)}},readableDidRead:{__proto__:null,enumerable:!1,get:function(){return this._readableState.dataEmitted}},readableAborted:{__proto__:null,enumerable:!1,get:function(){return!(!1===this._readableState.readable||!this._readableState.destroyed&&!this._readableState.errored||this._readableState.endEmitted)}},readableHighWaterMark:{__proto__:null,enumerable:!1,get:function(){return this._readableState.highWaterMark}},readableBuffer:{__proto__:null,enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}},readableFlowing:{__proto__:null,enumerable:!1,get:function(){return this._readableState.flowing},set:function(e){this._readableState&&(this._readableState.flowing=e)}},readableLength:{__proto__:null,enumerable:!1,get(){return this._readableState.length}},readableObjectMode:{__proto__:null,enumerable:!1,get(){return!!this._readableState&&this._readableState.objectMode}},readableEncoding:{__proto__:null,enumerable:!1,get(){return this._readableState?this._readableState.encoding:null}},errored:{__proto__:null,enumerable:!1,get(){return this._readableState?this._readableState.errored:null}},closed:{__proto__:null,get(){return!!this._readableState&&this._readableState.closed}},destroyed:{__proto__:null,enumerable:!1,get(){return!!this._readableState&&this._readableState.destroyed},set(e){this._readableState&&(this._readableState.destroyed=e)}},readableEnded:{__proto__:null,enumerable:!1,get(){return!!this._readableState&&this._readableState.endEmitted}}}),u(K.prototype,{pipesCount:{__proto__:null,get(){return this.pipes.length}},paused:{__proto__:null,get(){return!1!==this[B]},set(e){this[B]=!!e}}}),z._fromList=le,z.from=function(e,t){return j(z,e,t)},z.fromWeb=function(e,t){return fe().newStreamReadableFromReadableStream(e,t)},z.toWeb=function(e,t){return fe().newReadableStreamFromStreamReadable(e,t)},z.wrap=function(e,t){var r,n;return new z({objectMode:null===(r=null!==(n=e.readableObjectMode)&&void 0!==n?n:e.objectMode)||void 0===r||r,...t,destroy(t,r){A.destroyer(e,t),r(t)}}).wrap(e)}}),Pt=o((e,t)=>{l(),tt(),Fe();var r=wt(),{ArrayPrototypeSlice:n,Error:i,FunctionPrototypeSymbolHasInstance:o,ObjectDefineProperty:s,ObjectDefineProperties:u,ObjectSetPrototypeOf:c,StringPrototypeToLowerCase:h,Symbol:f,SymbolHasInstance:p}=rt();t.exports=M,M.WritableState=N;var{EventEmitter:d}=(mt(),a(st)),g=It().Stream,{Buffer:y}=(et(),a(Qe)),m=St(),{addAbortSignal:b}=At(),{getHighWaterMark:v,getDefaultHighWaterMark:w}=Ot(),{ERR_INVALID_ARG_TYPE:_,ERR_METHOD_NOT_IMPLEMENTED:E,ERR_MULTIPLE_CALLBACK:S,ERR_STREAM_CANNOT_PIPE:I,ERR_STREAM_DESTROYED:A,ERR_STREAM_ALREADY_FINISHED:R,ERR_STREAM_NULL_VALUES:O,ERR_STREAM_WRITE_AFTER_END:k,ERR_UNKNOWN_ENCODING:x}=it().codes,{errorOrDestroy:T}=m;function C(){}c(M.prototype,g.prototype),c(M,g);var P=f("kOnFinished");function N(e,t,r){"boolean"!=typeof r&&(r=t instanceof Lt()),this.objectMode=!(!e||!e.objectMode),r&&(this.objectMode=this.objectMode||!(!e||!e.writableObjectMode)),this.highWaterMark=e?v(this,e,"writableHighWaterMark",r):w(!1),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;let n=!(!e||!1!==e.decodeStrings);this.decodeStrings=!n,this.defaultEncoding=e&&e.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=U.bind(void 0,t),this.writecb=null,this.writelen=0,this.afterWriteTickInfo=null,L(this),this.pendingcb=0,this.constructed=!0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=!e||!1!==e.emitClose,this.autoDestroy=!e||!1!==e.autoDestroy,this.errored=null,this.closed=!1,this.closeEmitted=!1,this[P]=[]}function L(e){e.buffered=[],e.bufferedIndex=0,e.allBuffers=!0,e.allNoop=!0}function M(e){let t=this instanceof Lt();if(!t&&!o(M,this))return new M(e);this._writableState=new N(e,this,t),e&&("function"==typeof e.write&&(this._write=e.write),"function"==typeof e.writev&&(this._writev=e.writev),"function"==typeof e.destroy&&(this._destroy=e.destroy),"function"==typeof e.final&&(this._final=e.final),"function"==typeof e.construct&&(this._construct=e.construct),e.signal&&b(e.signal,this)),g.call(this,e),m.construct(this,()=>{let e=this._writableState;e.writing||q(this,e),H(this,e)})}function B(e,t,n,i){let o,s=e._writableState;if("function"==typeof n)i=n,n=s.defaultEncoding;else{if(n){if("buffer"!==n&&!y.isEncoding(n))throw new x(n)}else n=s.defaultEncoding;"function"!=typeof i&&(i=C)}if(null===t)throw new O;if(!s.objectMode)if("string"==typeof t)!1!==s.decodeStrings&&(t=y.from(t,n),n="buffer");else if(t instanceof y)n="buffer";else{if(!g._isUint8Array(t))throw new _("chunk",["string","Buffer","Uint8Array"],t);t=g._uint8ArrayToBuffer(t),n="buffer"}return s.ending?o=new k:s.destroyed&&(o=new A("write")),o?(r.nextTick(i,o),T(e,o,!0),o):(s.pendingcb++,function(e,t,r,n,i){let o=t.objectMode?1:r.length;t.length+=o;let s=t.length<t.highWaterMark;return s||(t.needDrain=!0),t.writing||t.corked||t.errored||!t.constructed?(t.buffered.push({chunk:r,encoding:n,callback:i}),t.allBuffers&&"buffer"!==n&&(t.allBuffers=!1),t.allNoop&&i!==C&&(t.allNoop=!1)):(t.writelen=o,t.writecb=i,t.writing=!0,t.sync=!0,e._write(r,n,t.onwrite),t.sync=!1),s&&!t.errored&&!t.destroyed}(e,s,t,n,i))}function D(e,t,r,n,i,o,s){t.writelen=n,t.writecb=s,t.writing=!0,t.sync=!0,t.destroyed?t.onwrite(new A("write")):r?e._writev(i,t.onwrite):e._write(i,o,t.onwrite),t.sync=!1}function j(e,t,r,n){--t.pendingcb,n(r),$(t),T(e,r)}function U(e,t){let n=e._writableState,i=n.sync,o=n.writecb;"function"==typeof o?(n.writing=!1,n.writecb=null,n.length-=n.writelen,n.writelen=0,t?(t.stack,n.errored||(n.errored=t),e._readableState&&!e._readableState.errored&&(e._readableState.errored=t),i?r.nextTick(j,e,n,t,o):j(e,n,t,o)):(n.buffered.length>n.bufferedIndex&&q(e,n),i?null!==n.afterWriteTickInfo&&n.afterWriteTickInfo.cb===o?n.afterWriteTickInfo.count++:(n.afterWriteTickInfo={count:1,cb:o,stream:e,state:n},r.nextTick(F,n.afterWriteTickInfo)):W(e,n,1,o))):T(e,new S)}function F({stream:e,state:t,count:r,cb:n}){return t.afterWriteTickInfo=null,W(e,t,r,n)}function W(e,t,r,n){for(!t.ending&&!e.destroyed&&0===t.length&&t.needDrain&&(t.needDrain=!1,e.emit("drain"));r-- >0;)t.pendingcb--,n();t.destroyed&&$(t),H(e,t)}function $(e){if(e.writing)return;for(let r=e.bufferedIndex;r<e.buffered.length;++r){var t;let{chunk:n,callback:i}=e.buffered[r],o=e.objectMode?1:n.length;e.length-=o,i(null!==(t=e.errored)&&void 0!==t?t:new A("write"))}let r=e[P].splice(0);for(let t=0;t<r.length;t++){var n;r[t](null!==(n=e.errored)&&void 0!==n?n:new A("end"))}L(e)}function q(e,t){if(t.corked||t.bufferProcessing||t.destroyed||!t.constructed)return;let{buffered:r,bufferedIndex:i,objectMode:o}=t,s=r.length-i;if(!s)return;let a=i;if(t.bufferProcessing=!0,s>1&&e._writev){t.pendingcb-=s-1;let i=t.allNoop?C:e=>{for(let t=a;t<r.length;++t)r[t].callback(e)},o=t.allNoop&&0===a?r:n(r,a);o.allBuffers=t.allBuffers,D(e,t,!0,t.length,o,"",i),L(t)}else{do{let{chunk:n,encoding:i,callback:s}=r[a];r[a++]=null,D(e,t,!1,o?1:n.length,n,i,s)}while(a<r.length&&!t.writing);a===r.length?L(t):a>256?(r.splice(0,a),t.bufferedIndex=0):t.bufferedIndex=a}t.bufferProcessing=!1}function G(e){return e.ending&&!e.destroyed&&e.constructed&&0===e.length&&!e.errored&&0===e.buffered.length&&!e.finished&&!e.writing&&!e.errorEmitted&&!e.closeEmitted}function V(e,t){!t.prefinished&&!t.finalCalled&&("function"!=typeof e._final||t.destroyed?(t.prefinished=!0,e.emit("prefinish")):(t.finalCalled=!0,function(e,t){let n=!1;function i(i){if(n)T(e,i??S());else if(n=!0,t.pendingcb--,i){let r=t[P].splice(0);for(let e=0;e<r.length;e++)r[e](i);T(e,i,t.sync)}else G(t)&&(t.prefinished=!0,e.emit("prefinish"),t.pendingcb++,r.nextTick(K,e,t))}t.sync=!0,t.pendingcb++;try{e._final(i)}catch(e){i(e)}t.sync=!1}(e,t)))}function H(e,t,n){G(t)&&(V(e,t),0===t.pendingcb&&(n?(t.pendingcb++,r.nextTick((e,t)=>{G(t)?K(e,t):t.pendingcb--},e,t)):G(t)&&(t.pendingcb++,K(e,t))))}function K(e,t){t.pendingcb--,t.finished=!0;let r=t[P].splice(0);for(let e=0;e<r.length;e++)r[e]();if(e.emit("finish"),t.autoDestroy){let t=e._readableState;(!t||t.autoDestroy&&(t.endEmitted||!1===t.readable))&&e.destroy()}}N.prototype.getBuffer=function(){return n(this.buffered,this.bufferedIndex)},s(N.prototype,"bufferedRequestCount",{__proto__:null,get(){return this.buffered.length-this.bufferedIndex}}),s(M,p,{__proto__:null,value:function(e){return!!o(this,e)||this===M&&(e&&e._writableState instanceof N)}}),M.prototype.pipe=function(){T(this,new I)},M.prototype.write=function(e,t,r){return!0===B(this,e,t,r)},M.prototype.cork=function(){this._writableState.corked++},M.prototype.uncork=function(){let e=this._writableState;e.corked&&(e.corked--,e.writing||q(this,e))},M.prototype.setDefaultEncoding=function(e){if("string"==typeof e&&(e=h(e)),!y.isEncoding(e))throw new x(e);return this._writableState.defaultEncoding=e,this},M.prototype._write=function(e,t,r){if(!this._writev)throw new E("_write()");this._writev([{chunk:e,encoding:t}],r)},M.prototype._writev=null,M.prototype.end=function(e,t,n){let o,s=this._writableState;if("function"==typeof e?(n=e,e=null,t=null):"function"==typeof t&&(n=t,t=null),null!=e){let r=B(this,e,t);r instanceof i&&(o=r)}return s.corked&&(s.corked=1,this.uncork()),o||(s.errored||s.ending?s.finished?o=new R("end"):s.destroyed&&(o=new A("end")):(s.ending=!0,H(this,s,!0),s.ended=!0)),"function"==typeof n&&(o||s.finished?r.nextTick(n,o):s[P].push(n)),this},u(M.prototype,{closed:{__proto__:null,get(){return!!this._writableState&&this._writableState.closed}},destroyed:{__proto__:null,get(){return!!this._writableState&&this._writableState.destroyed},set(e){this._writableState&&(this._writableState.destroyed=e)}},writable:{__proto__:null,get(){let e=this._writableState;return!(!e||!1===e.writable||e.destroyed||e.errored||e.ending||e.ended)},set(e){this._writableState&&(this._writableState.writable=!!e)}},writableFinished:{__proto__:null,get(){return!!this._writableState&&this._writableState.finished}},writableObjectMode:{__proto__:null,get(){return!!this._writableState&&this._writableState.objectMode}},writableBuffer:{__proto__:null,get(){return this._writableState&&this._writableState.getBuffer()}},writableEnded:{__proto__:null,get(){return!!this._writableState&&this._writableState.ending}},writableNeedDrain:{__proto__:null,get(){let e=this._writableState;return!!e&&(!e.destroyed&&!e.ending&&e.needDrain)}},writableHighWaterMark:{__proto__:null,get(){return this._writableState&&this._writableState.highWaterMark}},writableCorked:{__proto__:null,get(){return this._writableState?this._writableState.corked:0}},writableLength:{__proto__:null,get(){return this._writableState&&this._writableState.length}},errored:{__proto__:null,enumerable:!1,get(){return this._writableState?this._writableState.errored:null}},writableAborted:{__proto__:null,enumerable:!1,get:function(){return!(!1===this._writableState.writable||!this._writableState.destroyed&&!this._writableState.errored||this._writableState.finished)}}});var z,Q=m.destroy;function Y(){return void 0===z&&(z={}),z}M.prototype.destroy=function(e,t){let n=this._writableState;return!n.destroyed&&(n.bufferedIndex<n.buffered.length||n[P].length)&&r.nextTick($,n),Q.call(this,e,t),this},M.prototype._undestroy=m.undestroy,M.prototype._destroy=function(e,t){t(e)},M.prototype[d.captureRejectionSymbol]=function(e){this.destroy(e)},M.fromWeb=function(e,t){return Y().newStreamWritableFromWritableStream(e,t)},M.toWeb=function(e){return Y().newWritableStreamFromStreamWritable(e)}}),Nt=o((e,t)=>{l(),tt(),Fe();var r=wt(),n=(et(),a(Qe)),{isReadable:i,isWritable:o,isIterable:s,isNodeStream:u,isReadableNodeStream:c,isWritableNodeStream:h,isDuplexNodeStream:f,isReadableStream:p,isWritableStream:d}=_t(),g=Et(),{AbortError:y,codes:{ERR_INVALID_ARG_TYPE:m,ERR_INVALID_RETURN_VALUE:b}}=it(),{destroyer:v}=St(),w=Lt(),_=Ct(),E=Pt(),{createDeferredPromise:S}=bt(),I=Tt(),A=globalThis.Blob||n.Blob,R=typeof A<"u"?function(e){return e instanceof A}:function(e){return!1},O=globalThis.AbortController||ot().AbortController,{FunctionPrototypeCall:k}=rt(),x=class extends w{constructor(e){super(e),!1===e?.readable&&(this._readableState.readable=!1,this._readableState.ended=!0,this._readableState.endEmitted=!0),!1===e?.writable&&(this._writableState.writable=!1,this._writableState.ending=!0,this._writableState.ended=!0,this._writableState.finished=!0)}};function T(e){let t,r,n,s,a,l=e.readable&&"function"!=typeof e.readable.read?_.wrap(e.readable):e.readable,u=e.writable,c=!!i(l),h=!!o(u);function f(e){let t=s;s=null,t?t(e):e&&a.destroy(e)}return a=new x({readableObjectMode:!(null==l||!l.readableObjectMode),writableObjectMode:!(null==u||!u.writableObjectMode),readable:c,writable:h}),h&&(g(u,e=>{h=!1,e&&v(l,e),f(e)}),a._write=function(e,r,n){u.write(e,r)?n():t=n},a._final=function(e){u.end(),r=e},u.on("drain",function(){if(t){let e=t;t=null,e()}}),u.on("finish",function(){if(r){let e=r;r=null,e()}})),c&&(g(l,e=>{c=!1,e&&v(l,e),f(e)}),l.on("readable",function(){if(n){let e=n;n=null,e()}}),l.on("end",function(){a.push(null)}),a._read=function(){for(;;){let e=l.read();if(null===e)return void(n=a._read);if(!a.push(e))return}}),a._destroy=function(e,i){!e&&null!==s&&(e=new y),n=null,t=null,r=null,null===s?i(e):(s=i,v(u,e),v(l,e))},a}t.exports=function e(t,n){if(f(t))return t;if(c(t))return T({readable:t});if(h(t))return T({writable:t});if(u(t))return T({writable:!1,readable:!1});if(p(t))return T({readable:_.fromWeb(t)});if(d(t))return T({writable:E.fromWeb(t)});if("function"==typeof t){let{value:e,write:i,final:o,destroy:a}=function(e){let{promise:t,resolve:n}=S(),i=new O,o=i.signal;return{value:e(async function*(){for(;;){let e=t;t=null;let{chunk:i,done:s,cb:a}=await e;if(r.nextTick(a),s)return;if(o.aborted)throw new y(void 0,{cause:o.reason});({promise:t,resolve:n}=S()),yield i}}(),{signal:o}),write(e,t,r){let i=n;n=null,i({chunk:e,done:!1,cb:r})},final(e){let t=n;n=null,t({done:!0,cb:e})},destroy(e,t){i.abort(),t(e)}}}(t);if(s(e))return I(x,e,{objectMode:!0,write:i,final:o,destroy:a});let l=e?.then;if("function"==typeof l){let t,n=k(l,e,e=>{if(null!=e)throw new b("nully","body",e)},e=>{v(t,e)});return t=new x({objectMode:!0,readable:!1,write:i,final(e){o(async()=>{try{await n,r.nextTick(e,null)}catch(t){r.nextTick(e,t)}})},destroy:a})}throw new b("Iterable, AsyncIterable or AsyncFunction",n,e)}if(R(t))return e(t.arrayBuffer());if(s(t))return I(x,t,{objectMode:!0,writable:!1});if(p(t?.readable)&&d(t?.writable))return x.fromWeb(t);if("object"==typeof t?.writable||"object"==typeof t?.readable){return T({readable:null!=t&&t.readable?c(t?.readable)?t?.readable:e(t.readable):void 0,writable:null!=t&&t.writable?h(t?.writable)?t?.writable:e(t.writable):void 0})}let i=t?.then;if("function"==typeof i){let e;return k(i,t,t=>{null!=t&&e.push(t),e.push(null)},t=>{v(e,t)}),e=new x({objectMode:!0,writable:!1,read(){}})}throw new m(n,["Blob","ReadableStream","WritableStream","Stream","Iterable","AsyncIterable","Function","{ readable, writable } pair","Promise"],t)}}),Lt=o((e,t)=>{l(),tt(),Fe();var{ObjectDefineProperties:r,ObjectGetOwnPropertyDescriptor:n,ObjectKeys:i,ObjectSetPrototypeOf:o}=rt();t.exports=h;var s,a,u=Ct(),c=Pt();o(h.prototype,u.prototype),o(h,u);{let e=i(c.prototype);for(let t=0;t<e.length;t++){let r=e[t];h.prototype[r]||(h.prototype[r]=c.prototype[r])}}function h(e){if(!(this instanceof h))return new h(e);u.call(this,e),c.call(this,e),e?(this.allowHalfOpen=!1!==e.allowHalfOpen,!1===e.readable&&(this._readableState.readable=!1,this._readableState.ended=!0,this._readableState.endEmitted=!0),!1===e.writable&&(this._writableState.writable=!1,this._writableState.ending=!0,this._writableState.ended=!0,this._writableState.finished=!0)):this.allowHalfOpen=!0}function f(){return void 0===s&&(s={}),s}r(h.prototype,{writable:{__proto__:null,...n(c.prototype,"writable")},writableHighWaterMark:{__proto__:null,...n(c.prototype,"writableHighWaterMark")},writableObjectMode:{__proto__:null,...n(c.prototype,"writableObjectMode")},writableBuffer:{__proto__:null,...n(c.prototype,"writableBuffer")},writableLength:{__proto__:null,...n(c.prototype,"writableLength")},writableFinished:{__proto__:null,...n(c.prototype,"writableFinished")},writableCorked:{__proto__:null,...n(c.prototype,"writableCorked")},writableEnded:{__proto__:null,...n(c.prototype,"writableEnded")},writableNeedDrain:{__proto__:null,...n(c.prototype,"writableNeedDrain")},destroyed:{__proto__:null,get(){return void 0!==this._readableState&&void 0!==this._writableState&&(this._readableState.destroyed&&this._writableState.destroyed)},set(e){this._readableState&&this._writableState&&(this._readableState.destroyed=e,this._writableState.destroyed=e)}}}),h.fromWeb=function(e,t){return f().newStreamDuplexFromReadableWritablePair(e,t)},h.toWeb=function(e){return f().newReadableWritablePairFromDuplex(e)},h.from=function(e){return a||(a=Nt()),a(e,"body")}}),Mt=o((e,t)=>{l(),tt(),Fe();var{ObjectSetPrototypeOf:r,Symbol:n}=rt();t.exports=u;var{ERR_METHOD_NOT_IMPLEMENTED:i}=it().codes,o=Lt(),{getHighWaterMark:s}=Ot();r(u.prototype,o.prototype),r(u,o);var a=n("kCallback");function u(e){if(!(this instanceof u))return new u(e);let t=e?s(this,e,"readableHighWaterMark",!0):null;0===t&&(e={...e,highWaterMark:null,readableHighWaterMark:t,writableHighWaterMark:e.writableHighWaterMark||0}),o.call(this,e),this._readableState.sync=!1,this[a]=null,e&&("function"==typeof e.transform&&(this._transform=e.transform),"function"==typeof e.flush&&(this._flush=e.flush)),this.on("prefinish",h)}function c(e){"function"!=typeof this._flush||this.destroyed?(this.push(null),e&&e()):this._flush((t,r)=>{t?e?e(t):this.destroy(t):(null!=r&&this.push(r),this.push(null),e&&e())})}function h(){this._final!==c&&c.call(this)}u.prototype._final=c,u.prototype._transform=function(e,t,r){throw new i("_transform()")},u.prototype._write=function(e,t,r){let n=this._readableState,i=this._writableState,o=n.length;this._transform(e,t,(e,t)=>{e?r(e):(null!=t&&this.push(t),i.ended||o===n.length||n.length<n.highWaterMark?r():this[a]=r)})},u.prototype._read=function(){if(this[a]){let e=this[a];this[a]=null,e()}}}),Bt=o((e,t)=>{l(),tt(),Fe();var{ObjectSetPrototypeOf:r}=rt();t.exports=i;var n=Mt();function i(e){if(!(this instanceof i))return new i(e);n.call(this,e)}r(i.prototype,n.prototype),r(i,n),i.prototype._transform=function(e,t,r){r(null,e)}}),Dt=o((e,t)=>{l(),tt(),Fe();var r,n,i,o=wt(),{ArrayIsArray:s,Promise:a,SymbolAsyncIterator:u,SymbolDispose:c}=rt(),h=Et(),{once:f}=bt(),p=St(),d=Lt(),{aggregateTwoErrors:g,codes:{ERR_INVALID_ARG_TYPE:y,ERR_INVALID_RETURN_VALUE:m,ERR_MISSING_ARGS:b,ERR_STREAM_DESTROYED:v,ERR_STREAM_PREMATURE_CLOSE:w},AbortError:_}=it(),{validateFunction:E,validateAbortSignal:S}=vt(),{isIterable:I,isReadable:A,isReadableNodeStream:R,isNodeStream:O,isTransformStream:k,isWebStream:x,isReadableStream:T,isReadableFinished:C}=_t(),P=globalThis.AbortController||ot().AbortController;function N(e,t,r){let n=!1;return e.on("close",()=>{n=!0}),{destroy:t=>{n||(n=!0,p.destroyer(e,t||new v("pipe")))},cleanup:h(e,{readable:t,writable:r},e=>{n=!e})}}function L(e){if(I(e))return e;if(R(e))return async function*(e){n||(n=Ct()),yield*n.prototype[u].call(e)}(e);throw new y("val",["Readable","Iterable","AsyncIterable"],e)}async function M(e,t,r,{end:n}){let i,o=null,s=e=>{if(e&&(i=e),o){let e=o;o=null,e()}},l=()=>new a((e,t)=>{i?t(i):o=()=>{i?t(i):e()}});t.on("drain",s);let u=h(t,{readable:!1},s);try{t.writableNeedDrain&&await l();for await(let r of e)t.write(r)||await l();n&&(t.end(),await l()),r()}catch(e){r(i!==e?g(i,e):e)}finally{u(),t.off("drain",s)}}async function B(e,t,r,{end:n}){k(t)&&(t=t.writable);let i=t.getWriter();try{for await(let t of e)await i.ready,i.write(t).catch(()=>{});await i.ready,n&&await i.close(),r()}catch(e){try{await i.abort(e),r(e)}catch(e){r(e)}}}function D(e,t,n){if(1===e.length&&s(e[0])&&(e=e[0]),e.length<2)throw new b("streams");let a,l=new P,u=l.signal,h=n?.signal,f=[];function p(){U(new _)}S(h,"options.signal"),i=i||bt().addAbortListener,h&&(a=i(h,p));let g,v,w,E=[],C=0;function D(e){U(e,0===--C)}function U(e,r){var n;if(e&&(!g||"ERR_STREAM_PREMATURE_CLOSE"===g.code)&&(g=e),g||r){for(;E.length;)E.shift()(g);null===(n=a)||void 0===n||n[c](),l.abort(),r&&(g||f.forEach(e=>e()),o.nextTick(t,g,v))}}for(let t=0;t<e.length;t++){let i=e[t],s=t<e.length-1,a=t>0,l=s||!1!==n?.end,c=t===e.length-1;if(O(i)){let e=function(e){e&&"AbortError"!==e.name&&"ERR_STREAM_PREMATURE_CLOSE"!==e.code&&D(e)};if(l){let{destroy:e,cleanup:t}=N(i,s,a);E.push(e),A(i)&&c&&f.push(t)}i.on("error",e),A(i)&&c&&f.push(()=>{i.removeListener("error",e)})}if(0===t)if("function"==typeof i){if(w=i({signal:u}),!I(w))throw new m("Iterable, AsyncIterable or Stream","source",w)}else w=I(i)||R(i)||k(i)?i:d.from(i);else if("function"==typeof i){var F;if(k(w))w=L(null===(F=w)||void 0===F?void 0:F.readable);else w=L(w);if(w=i(w,{signal:u}),s){if(!I(w,!0))throw new m("AsyncIterable",`transform[${t-1}]`,w)}else{var W;r||(r=Bt());let e=new r({objectMode:!0}),t=null===(W=w)||void 0===W?void 0:W.then;if("function"==typeof t)C++,t.call(w,t=>{v=t,null!=t&&e.write(t),l&&e.end(),o.nextTick(D)},t=>{e.destroy(t),o.nextTick(D,t)});else if(I(w,!0))C++,M(w,e,D,{end:l});else{if(!T(w)&&!k(w))throw new m("AsyncIterable or Promise","destination",w);{let t=w.readable||w;C++,M(t,e,D,{end:l})}}w=e;let{destroy:n,cleanup:i}=N(w,!1,!0);E.push(n),c&&f.push(i)}}else if(O(i)){if(R(w)){C+=2;let e=j(w,i,D,{end:l});A(i)&&c&&f.push(e)}else if(k(w)||T(w)){let e=w.readable||w;C++,M(e,i,D,{end:l})}else{if(!I(w))throw new y("val",["Readable","Iterable","AsyncIterable","ReadableStream","TransformStream"],w);C++,M(w,i,D,{end:l})}w=i}else if(x(i)){if(R(w))C++,B(L(w),i,D,{end:l});else if(T(w)||I(w))C++,B(w,i,D,{end:l});else{if(!k(w))throw new y("val",["Readable","Iterable","AsyncIterable","ReadableStream","TransformStream"],w);C++,B(w.readable,i,D,{end:l})}w=i}else w=d.from(i)}return(null!=u&&u.aborted||null!=h&&h.aborted)&&o.nextTick(p),w}function j(e,t,r,{end:n}){let i=!1;if(t.on("close",()=>{i||r(new w)}),e.pipe(t,{end:!1}),n){let r=function(){i=!0,t.end()};C(e)?o.nextTick(r):e.once("end",r)}else r();return h(e,{readable:!0,writable:!1},t=>{let n=e._readableState;t&&"ERR_STREAM_PREMATURE_CLOSE"===t.code&&n&&n.ended&&!n.errored&&!n.errorEmitted?e.once("end",r).once("error",r):r(t)}),h(t,{readable:!1,writable:!0},r)}t.exports={pipelineImpl:D,pipeline:function(...e){return D(e,f(function(e){return E(e[e.length-1],"streams[stream.length - 1]"),e.pop()}(e)))}}}),jt=o((e,t)=>{l(),tt(),Fe();var{pipeline:r}=Dt(),n=Lt(),{destroyer:i}=St(),{isNodeStream:o,isReadable:s,isWritable:a,isWebStream:u,isTransformStream:c,isWritableStream:h,isReadableStream:f}=_t(),{AbortError:p,codes:{ERR_INVALID_ARG_VALUE:d,ERR_MISSING_ARGS:g}}=it(),y=Et();t.exports=function(...e){if(0===e.length)throw new g("streams");if(1===e.length)return n.from(e[0]);let t,l,m,b,v,w=[...e];if("function"==typeof e[0]&&(e[0]=n.from(e[0])),"function"==typeof e[e.length-1]){let t=e.length-1;e[t]=n.from(e[t])}for(let t=0;t<e.length;++t)if(o(e[t])||u(e[t])){if(t<e.length-1&&!(s(e[t])||f(e[t])||c(e[t])))throw new d(`streams[${t}]`,w[t],"must be readable");if(t>0&&!(a(e[t])||h(e[t])||c(e[t])))throw new d(`streams[${t}]`,w[t],"must be writable")}let _=e[0],E=r(e,function(e){let t=b;b=null,t?t(e):e?v.destroy(e):!I&&!S&&v.destroy()}),S=!!(a(_)||h(_)||c(_)),I=!!(s(E)||f(E)||c(E));if(v=new n({writableObjectMode:!(null==_||!_.writableObjectMode),readableObjectMode:!(null==E||!E.readableObjectMode),writable:S,readable:I}),S){if(o(_))v._write=function(e,r,n){_.write(e,r)?n():t=n},v._final=function(e){_.end(),l=e},_.on("drain",function(){if(t){let e=t;t=null,e()}});else if(u(_)){let e=(c(_)?_.writable:_).getWriter();v._write=async function(t,r,n){try{await e.ready,e.write(t).catch(()=>{}),n()}catch(e){n(e)}},v._final=async function(t){try{await e.ready,e.close().catch(()=>{}),l=t}catch(e){t(e)}}}let e=c(E)?E.readable:E;y(e,()=>{if(l){let e=l;l=null,e()}})}if(I)if(o(E))E.on("readable",function(){if(m){let e=m;m=null,e()}}),E.on("end",function(){v.push(null)}),v._read=function(){for(;;){let e=E.read();if(null===e)return void(m=v._read);if(!v.push(e))return}};else if(u(E)){let e=(c(E)?E.readable:E).getReader();v._read=async function(){for(;;)try{let{value:t,done:r}=await e.read();if(!v.push(t))return;if(r)return void v.push(null)}catch{return}}}return v._destroy=function(e,r){!e&&null!==b&&(e=new p),m=null,t=null,l=null,null===b?r(e):(b=r,o(E)&&i(E,e))},v}}),Ut=o((e,t)=>{l(),tt(),Fe();var r=globalThis.AbortController||ot().AbortController,{codes:{ERR_INVALID_ARG_VALUE:n,ERR_INVALID_ARG_TYPE:i,ERR_MISSING_ARGS:o,ERR_OUT_OF_RANGE:s},AbortError:a}=it(),{validateAbortSignal:u,validateInteger:c,validateObject:h}=vt(),f=rt().Symbol("kWeak"),p=rt().Symbol("kResistStopPropagation"),{finished:d}=Et(),g=jt(),{addAbortSignalNoValidate:y}=At(),{isWritable:m,isNodeStream:b}=_t(),{deprecate:v}=bt(),{ArrayPrototypePush:w,Boolean:_,MathFloor:E,Number:S,NumberIsNaN:I,Promise:A,PromiseReject:R,PromiseResolve:O,PromisePrototypeThen:k,Symbol:x}=rt(),T=x("kEmpty"),C=x("kEof");function P(e,t){if("function"!=typeof e)throw new i("fn",["Function","AsyncFunction"],e);null!=t&&h(t,"options"),null!=t?.signal&&u(t.signal,"options.signal");let r=1;null!=t?.concurrency&&(r=E(t.concurrency));let n=r-1;return null!=t?.highWaterMark&&(n=E(t.highWaterMark)),c(r,"options.concurrency",1),c(n,"options.highWaterMark",0),n+=r,async function*(){let i,o,s=bt().AbortSignalAny([t?.signal].filter(_)),l=this,u=[],c={signal:s},h=!1,f=0;function p(){h=!0,d()}function d(){f-=1,g()}function g(){o&&!h&&f<r&&u.length<n&&(o(),o=null)}!async function(){try{for await(let t of l){if(h)return;if(s.aborted)throw new a;try{if(t=e(t,c),t===T)continue;t=O(t)}catch(e){t=R(e)}f+=1,k(t,d,p),u.push(t),i&&(i(),i=null),!h&&(u.length>=n||f>=r)&&await new A(e=>{o=e})}u.push(C)}catch(e){let t=R(e);k(t,d,p),u.push(t)}finally{h=!0,i&&(i(),i=null)}}();try{for(;;){for(;u.length>0;){let e=await u[0];if(e===C)return;if(s.aborted)throw new a;e!==T&&(yield e),u.shift(),g()}await new A(e=>{i=e})}}finally{h=!0,o&&(o(),o=null)}}.call(this)}async function N(e,t=void 0){for await(let r of L.call(this,e,t))return!0;return!1}function L(e,t){if("function"!=typeof e)throw new i("fn",["Function","AsyncFunction"],e);return P.call(this,async function(t,r){return await e(t,r)?t:T},t)}var M=class extends o{constructor(){super("reduce"),this.message="Reduce of an empty stream requires an initial value"}};function B(e){if(e=S(e),I(e))return 0;if(e<0)throw new s("number",">= 0",e);return e}t.exports.streamReturningOperators={asIndexedPairs:v(function(e=void 0){return null!=e&&h(e,"options"),null!=e?.signal&&u(e.signal,"options.signal"),async function*(){let t=0;for await(let n of this){var r;if(null!=e&&null!==(r=e.signal)&&void 0!==r&&r.aborted)throw new a({cause:e.signal.reason});yield[t++,n]}}.call(this)},"readable.asIndexedPairs will be removed in a future version."),drop:function(e,t=void 0){return null!=t&&h(t,"options"),null!=t?.signal&&u(t.signal,"options.signal"),e=B(e),async function*(){var r;if(null!=t&&null!==(r=t.signal)&&void 0!==r&&r.aborted)throw new a;for await(let r of this){var n;if(null!=t&&null!==(n=t.signal)&&void 0!==n&&n.aborted)throw new a;e--<=0&&(yield r)}}.call(this)},filter:L,flatMap:function(e,t){let r=P.call(this,e,t);return async function*(){for await(let e of r)yield*e}.call(this)},map:P,take:function(e,t=void 0){return null!=t&&h(t,"options"),null!=t?.signal&&u(t.signal,"options.signal"),e=B(e),async function*(){var r;if(null!=t&&null!==(r=t.signal)&&void 0!==r&&r.aborted)throw new a;for await(let r of this){var n;if(null!=t&&null!==(n=t.signal)&&void 0!==n&&n.aborted)throw new a;if(e-- >0&&(yield r),e<=0)return}}.call(this)},compose:function(e,t){if(null!=t&&h(t,"options"),null!=t?.signal&&u(t.signal,"options.signal"),b(e)&&!m(e))throw new n("stream",e,"must be writable");let r=g(this,e);return null!=t&&t.signal&&y(t.signal,r),r}},t.exports.promiseReturningOperators={every:async function(e,t=void 0){if("function"!=typeof e)throw new i("fn",["Function","AsyncFunction"],e);return!await N.call(this,async(...t)=>!await e(...t),t)},forEach:async function(e,t){if("function"!=typeof e)throw new i("fn",["Function","AsyncFunction"],e);for await(let r of P.call(this,async function(t,r){return await e(t,r),T},t));},reduce:async function(e,t,n){var o;if("function"!=typeof e)throw new i("reducer",["Function","AsyncFunction"],e);null!=n&&h(n,"options"),null!=n?.signal&&u(n.signal,"options.signal");let s=arguments.length>1;if(null!=n&&null!==(o=n.signal)&&void 0!==o&&o.aborted){let e=new a(void 0,{cause:n.signal.reason});throw this.once("error",()=>{}),await d(this.destroy(e)),e}let l=new r,c=l.signal;if(null!=n&&n.signal){let e={once:!0,[f]:this,[p]:!0};n.signal.addEventListener("abort",()=>l.abort(),e)}let g=!1;try{for await(let r of this){var y;if(g=!0,null!=n&&null!==(y=n.signal)&&void 0!==y&&y.aborted)throw new a;s?t=await e(t,r,{signal:c}):(t=r,s=!0)}if(!g&&!s)throw new M}finally{l.abort()}return t},toArray:async function(e){null!=e&&h(e,"options"),null!=e?.signal&&u(e.signal,"options.signal");let t=[];for await(let n of this){var r;if(null!=e&&null!==(r=e.signal)&&void 0!==r&&r.aborted)throw new a(void 0,{cause:e.signal.reason});w(t,n)}return t},some:N,find:async function(e,t){for await(let r of L.call(this,e,t))return r}}}),Ft=o((e,t)=>{l(),tt(),Fe();var{ArrayPrototypePop:r,Promise:n}=rt(),{isIterable:i,isNodeStream:o,isWebStream:s}=_t(),{pipelineImpl:a}=Dt(),{finished:u}=Et();Wt(),t.exports={finished:u,pipeline:function(...e){return new n((t,n)=>{let l,u,c=e[e.length-1];if(c&&"object"==typeof c&&!o(c)&&!i(c)&&!s(c)){let t=r(e);l=t.signal,u=t.end}a(e,(e,r)=>{e?n(e):t(r)},{signal:l,end:u})})}}}),Wt=o((e,t)=>{l(),tt(),Fe();var{Buffer:r}=(et(),a(Qe)),{ObjectDefineProperty:n,ObjectKeys:i,ReflectApply:o}=rt(),{promisify:{custom:s}}=bt(),{streamReturningOperators:u,promiseReturningOperators:c}=Ut(),{codes:{ERR_ILLEGAL_CONSTRUCTOR:h}}=it(),f=jt(),{setDefaultHighWaterMark:p,getDefaultHighWaterMark:d}=Ot(),{pipeline:g}=Dt(),{destroyer:y}=St(),m=Et(),b=Ft(),v=_t(),w=t.exports=It().Stream;w.isDestroyed=v.isDestroyed,w.isDisturbed=v.isDisturbed,w.isErrored=v.isErrored,w.isReadable=v.isReadable,w.isWritable=v.isWritable,w.Readable=Ct();for(let e of i(u)){let t=function(...e){if(new.target)throw h();return w.Readable.from(o(r,this,e))},r=u[e];n(t,"name",{__proto__:null,value:r.name}),n(t,"length",{__proto__:null,value:r.length}),n(w.Readable.prototype,e,{__proto__:null,value:t,enumerable:!1,configurable:!0,writable:!0})}for(let e of i(c)){let t=function(...e){if(new.target)throw h();return o(r,this,e)},r=c[e];n(t,"name",{__proto__:null,value:r.name}),n(t,"length",{__proto__:null,value:r.length}),n(w.Readable.prototype,e,{__proto__:null,value:t,enumerable:!1,configurable:!0,writable:!0})}w.Writable=Pt(),w.Duplex=Lt(),w.Transform=Mt(),w.PassThrough=Bt(),w.pipeline=g;var{addAbortSignal:_}=At();w.addAbortSignal=_,w.finished=m,w.destroy=y,w.compose=f,w.setDefaultHighWaterMark=p,w.getDefaultHighWaterMark=d,n(w,"promises",{__proto__:null,configurable:!0,enumerable:!0,get:()=>b}),n(g,s,{__proto__:null,enumerable:!0,get:()=>b.pipeline}),n(m,s,{__proto__:null,enumerable:!0,get:()=>b.finished}),w.Stream=w,w._isUint8Array=function(e){return e instanceof Uint8Array},w._uint8ArrayToBuffer=function(e){return r.from(e.buffer,e.byteOffset,e.byteLength)}}),$t=o((e,t)=>{l(),tt(),Fe();var r=Wt(),n=Ft(),i=r.Readable.destroy;t.exports=r.Readable,t.exports._uint8ArrayToBuffer=r._uint8ArrayToBuffer,t.exports._isUint8Array=r._isUint8Array,t.exports.isDisturbed=r.isDisturbed,t.exports.isErrored=r.isErrored,t.exports.isReadable=r.isReadable,t.exports.Readable=r.Readable,t.exports.Writable=r.Writable,t.exports.Duplex=r.Duplex,t.exports.Transform=r.Transform,t.exports.PassThrough=r.PassThrough,t.exports.addAbortSignal=r.addAbortSignal,t.exports.finished=r.finished,t.exports.destroy=r.destroy,t.exports.destroy=i,t.exports.pipeline=r.pipeline,t.exports.compose=r.compose,Object.defineProperty(r,"promises",{configurable:!0,enumerable:!0,get:()=>n}),t.exports.Stream=r.Stream,t.exports.default=t.exports}),qt=o((e,t)=>{l(),tt(),Fe(),"function"==typeof Object.create?t.exports=function(e,t){t&&(e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}))}:t.exports=function(e,t){if(t){e.super_=t;var r=function(){};r.prototype=t.prototype,e.prototype=new r,e.prototype.constructor=e}}}),Gt=o((e,t)=>{l(),tt(),Fe();var{Buffer:r}=(et(),a(Qe)),n=Symbol.for("BufferList");function i(e){if(!(this instanceof i))return new i(e);i._init.call(this,e)}i._init=function(e){Object.defineProperty(this,n,{value:!0}),this._bufs=[],this.length=0,e&&this.append(e)},i.prototype._new=function(e){return new i(e)},i.prototype._offset=function(e){if(0===e)return[0,0];let t=0;for(let r=0;r<this._bufs.length;r++){let n=t+this._bufs[r].length;if(e<n||r===this._bufs.length-1)return[r,e-t];t=n}},i.prototype._reverseOffset=function(e){let t=e[0],r=e[1];for(let e=0;e<t;e++)r+=this._bufs[e].length;return r},i.prototype.getBuffers=function(){return this._bufs},i.prototype.get=function(e){if(e>this.length||e<0)return;let t=this._offset(e);return this._bufs[t[0]][t[1]]},i.prototype.slice=function(e,t){return"number"==typeof e&&e<0&&(e+=this.length),"number"==typeof t&&t<0&&(t+=this.length),this.copy(null,0,e,t)},i.prototype.copy=function(e,t,n,i){if(("number"!=typeof n||n<0)&&(n=0),("number"!=typeof i||i>this.length)&&(i=this.length),n>=this.length||i<=0)return e||r.alloc(0);let o=!!e,s=this._offset(n),a=i-n,l=a,u=o&&t||0,c=s[1];if(0===n&&i===this.length){if(!o)return 1===this._bufs.length?this._bufs[0]:r.concat(this._bufs,this.length);for(let t=0;t<this._bufs.length;t++)this._bufs[t].copy(e,u),u+=this._bufs[t].length;return e}if(l<=this._bufs[s[0]].length-c)return o?this._bufs[s[0]].copy(e,t,c,c+l):this._bufs[s[0]].slice(c,c+l);o||(e=r.allocUnsafe(a));for(let t=s[0];t<this._bufs.length;t++){let r=this._bufs[t].length-c;if(!(l>r)){this._bufs[t].copy(e,u,c,c+l),u+=r;break}this._bufs[t].copy(e,u,c),u+=r,l-=r,c&&(c=0)}return e.length>u?e.slice(0,u):e},i.prototype.shallowSlice=function(e,t){if(e=e||0,t="number"!=typeof t?this.length:t,e<0&&(e+=this.length),t<0&&(t+=this.length),e===t)return this._new();let r=this._offset(e),n=this._offset(t),i=this._bufs.slice(r[0],n[0]+1);return 0===n[1]?i.pop():i[i.length-1]=i[i.length-1].slice(0,n[1]),0!==r[1]&&(i[0]=i[0].slice(r[1])),this._new(i)},i.prototype.toString=function(e,t,r){return this.slice(t,r).toString(e)},i.prototype.consume=function(e){if(e=Math.trunc(e),Number.isNaN(e)||e<=0)return this;for(;this._bufs.length;){if(!(e>=this._bufs[0].length)){this._bufs[0]=this._bufs[0].slice(e),this.length-=e;break}e-=this._bufs[0].length,this.length-=this._bufs[0].length,this._bufs.shift()}return this},i.prototype.duplicate=function(){let e=this._new();for(let t=0;t<this._bufs.length;t++)e.append(this._bufs[t]);return e},i.prototype.append=function(e){return this._attach(e,i.prototype._appendBuffer)},i.prototype.prepend=function(e){return this._attach(e,i.prototype._prependBuffer,!0)},i.prototype._attach=function(e,t,n){if(null==e)return this;if(e.buffer)t.call(this,r.from(e.buffer,e.byteOffset,e.byteLength));else if(Array.isArray(e)){let[r,i]=n?[e.length-1,-1]:[0,1];for(let o=r;o>=0&&o<e.length;o+=i)this._attach(e[o],t,n)}else if(this._isBufferList(e)){let[r,i]=n?[e._bufs.length-1,-1]:[0,1];for(let o=r;o>=0&&o<e._bufs.length;o+=i)this._attach(e._bufs[o],t,n)}else"number"==typeof e&&(e=e.toString()),t.call(this,r.from(e));return this},i.prototype._appendBuffer=function(e){this._bufs.push(e),this.length+=e.length},i.prototype._prependBuffer=function(e){this._bufs.unshift(e),this.length+=e.length},i.prototype.indexOf=function(e,t,n){if(void 0===n&&"string"==typeof t&&(n=t,t=void 0),"function"==typeof e||Array.isArray(e))throw new TypeError('The "value" argument must be one of type string, Buffer, BufferList, or Uint8Array.');if("number"==typeof e?e=r.from([e]):"string"==typeof e?e=r.from(e,n):this._isBufferList(e)?e=e.slice():Array.isArray(e.buffer)?e=r.from(e.buffer,e.byteOffset,e.byteLength):r.isBuffer(e)||(e=r.from(e)),t=Number(t||0),isNaN(t)&&(t=0),t<0&&(t=this.length+t),t<0&&(t=0),0===e.length)return t>this.length?this.length:t;let i=this._offset(t),o=i[0],s=i[1];for(;o<this._bufs.length;o++){let t=this._bufs[o];for(;s<t.length;)if(t.length-s>=e.length){let r=t.indexOf(e,s);if(-1!==r)return this._reverseOffset([o,r]);s=t.length-e.length+1}else{let t=this._reverseOffset([o,s]);if(this._match(t,e))return t;s++}s=0}return-1},i.prototype._match=function(e,t){if(this.length-e<t.length)return!1;for(let r=0;r<t.length;r++)if(this.get(e+r)!==t[r])return!1;return!0},function(){let e={readDoubleBE:8,readDoubleLE:8,readFloatBE:4,readFloatLE:4,readBigInt64BE:8,readBigInt64LE:8,readBigUInt64BE:8,readBigUInt64LE:8,readInt32BE:4,readInt32LE:4,readUInt32BE:4,readUInt32LE:4,readInt16BE:2,readInt16LE:2,readUInt16BE:2,readUInt16LE:2,readInt8:1,readUInt8:1,readIntBE:null,readIntLE:null,readUIntBE:null,readUIntLE:null};for(let t in e)(function(t){i.prototype[t]=null===e[t]?function(e,r){return this.slice(e,e+r)[t](0,r)}:function(r=0){return this.slice(r,r+e[t])[t](0)}})(t)}(),i.prototype._isBufferList=function(e){return e instanceof i||i.isBufferList(e)},i.isBufferList=function(e){return null!=e&&e[n]},t.exports=i}),Vt=o((e,t)=>{l(),tt(),Fe();var r=$t().Duplex,n=qt(),i=Gt();function o(e){if(!(this instanceof o))return new o(e);if("function"==typeof e){this._callback=e;let t=function(e){this._callback&&(this._callback(e),this._callback=null)}.bind(this);this.on("pipe",function(e){e.on("error",t)}),this.on("unpipe",function(e){e.removeListener("error",t)}),e=null}i._init.call(this,e),r.call(this)}n(o,r),Object.assign(o.prototype,i.prototype),o.prototype._new=function(e){return new o(e)},o.prototype._write=function(e,t,r){this._appendBuffer(e),"function"==typeof r&&r()},o.prototype._read=function(e){if(!this.length)return this.push(null);e=Math.min(e,this.length),this.push(this.slice(0,e)),this.consume(e)},o.prototype.end=function(e){r.prototype.end.call(this,e),this._callback&&(this._callback(null,this.slice()),this._callback=null)},o.prototype._destroy=function(e,t){this._bufs.length=0,this.length=0,t(e)},o.prototype._isBufferList=function(e){return e instanceof o||e instanceof i||o.isBufferList(e)},o.isBufferList=i.isBufferList,t.exports=o,t.exports.BufferListStream=o,t.exports.BufferList=i}),Ht=o((e,t)=>{l(),tt(),Fe();t.exports=class{constructor(){this.cmd=null,this.retain=!1,this.qos=0,this.dup=!1,this.length=-1,this.topic=null,this.payload=null}}}),Kt=o((e,t)=>{l(),tt(),Fe();var r=t.exports,{Buffer:n}=(et(),a(Qe));r.types={0:"reserved",1:"connect",2:"connack",3:"publish",4:"puback",5:"pubrec",6:"pubrel",7:"pubcomp",8:"subscribe",9:"suback",10:"unsubscribe",11:"unsuback",12:"pingreq",13:"pingresp",14:"disconnect",15:"auth"},r.requiredHeaderFlags={1:0,2:0,4:0,5:0,6:2,7:0,8:2,9:0,10:2,11:0,12:0,13:0,14:0,15:0},r.requiredHeaderFlagsErrors={};for(let e in r.requiredHeaderFlags){let t=r.requiredHeaderFlags[e];r.requiredHeaderFlagsErrors[e]="Invalid header flag bits, must be 0x"+t.toString(16)+" for "+r.types[e]+" packet"}r.codes={};for(let e in r.types){let t=r.types[e];r.codes[t]=e}r.CMD_SHIFT=4,r.CMD_MASK=240,r.DUP_MASK=8,r.QOS_MASK=3,r.QOS_SHIFT=1,r.RETAIN_MASK=1,r.VARBYTEINT_MASK=127,r.VARBYTEINT_FIN_MASK=128,r.VARBYTEINT_MAX=268435455,r.SESSIONPRESENT_MASK=1,r.SESSIONPRESENT_HEADER=n.from([r.SESSIONPRESENT_MASK]),r.CONNACK_HEADER=n.from([r.codes.connack<<r.CMD_SHIFT]),r.USERNAME_MASK=128,r.PASSWORD_MASK=64,r.WILL_RETAIN_MASK=32,r.WILL_QOS_MASK=24,r.WILL_QOS_SHIFT=3,r.WILL_FLAG_MASK=4,r.CLEAN_SESSION_MASK=2,r.CONNECT_HEADER=n.from([r.codes.connect<<r.CMD_SHIFT]),r.properties={sessionExpiryInterval:17,willDelayInterval:24,receiveMaximum:33,maximumPacketSize:39,topicAliasMaximum:34,requestResponseInformation:25,requestProblemInformation:23,userProperties:38,authenticationMethod:21,authenticationData:22,payloadFormatIndicator:1,messageExpiryInterval:2,contentType:3,responseTopic:8,correlationData:9,maximumQoS:36,retainAvailable:37,assignedClientIdentifier:18,reasonString:31,wildcardSubscriptionAvailable:40,subscriptionIdentifiersAvailable:41,sharedSubscriptionAvailable:42,serverKeepAlive:19,responseInformation:26,serverReference:28,topicAlias:35,subscriptionIdentifier:11},r.propertiesCodes={};for(let e in r.properties){let t=r.properties[e];r.propertiesCodes[t]=e}function i(e){return[0,1,2].map(t=>[0,1].map(i=>[0,1].map(o=>{let s=n.alloc(1);return s.writeUInt8(r.codes[e]<<r.CMD_SHIFT|(i?r.DUP_MASK:0)|t<<r.QOS_SHIFT|o,0,!0),s})))}r.propertiesTypes={sessionExpiryInterval:"int32",willDelayInterval:"int32",receiveMaximum:"int16",maximumPacketSize:"int32",topicAliasMaximum:"int16",requestResponseInformation:"byte",requestProblemInformation:"byte",userProperties:"pair",authenticationMethod:"string",authenticationData:"binary",payloadFormatIndicator:"byte",messageExpiryInterval:"int32",contentType:"string",responseTopic:"string",correlationData:"binary",maximumQoS:"int8",retainAvailable:"byte",assignedClientIdentifier:"string",reasonString:"string",wildcardSubscriptionAvailable:"byte",subscriptionIdentifiersAvailable:"byte",sharedSubscriptionAvailable:"byte",serverKeepAlive:"int16",responseInformation:"string",serverReference:"string",topicAlias:"int16",subscriptionIdentifier:"var"},r.PUBLISH_HEADER=i("publish"),r.SUBSCRIBE_HEADER=i("subscribe"),r.SUBSCRIBE_OPTIONS_QOS_MASK=3,r.SUBSCRIBE_OPTIONS_NL_MASK=1,r.SUBSCRIBE_OPTIONS_NL_SHIFT=2,r.SUBSCRIBE_OPTIONS_RAP_MASK=1,r.SUBSCRIBE_OPTIONS_RAP_SHIFT=3,r.SUBSCRIBE_OPTIONS_RH_MASK=3,r.SUBSCRIBE_OPTIONS_RH_SHIFT=4,r.SUBSCRIBE_OPTIONS_RH=[0,16,32],r.SUBSCRIBE_OPTIONS_NL=4,r.SUBSCRIBE_OPTIONS_RAP=8,r.SUBSCRIBE_OPTIONS_QOS=[0,1,2],r.UNSUBSCRIBE_HEADER=i("unsubscribe"),r.ACKS={unsuback:i("unsuback"),puback:i("puback"),pubcomp:i("pubcomp"),pubrel:i("pubrel"),pubrec:i("pubrec")},r.SUBACK_HEADER=n.from([r.codes.suback<<r.CMD_SHIFT]),r.VERSION3=n.from([3]),r.VERSION4=n.from([4]),r.VERSION5=n.from([5]),r.VERSION131=n.from([131]),r.VERSION132=n.from([132]),r.QOS=[0,1,2].map(e=>n.from([e])),r.EMPTY={pingreq:n.from([r.codes.pingreq<<4,0]),pingresp:n.from([r.codes.pingresp<<4,0]),disconnect:n.from([r.codes.disconnect<<4,0])},r.MQTT5_PUBACK_PUBREC_CODES={0:"Success",16:"No matching subscribers",128:"Unspecified error",131:"Implementation specific error",135:"Not authorized",144:"Topic Name invalid",145:"Packet identifier in use",151:"Quota exceeded",153:"Payload format invalid"},r.MQTT5_PUBREL_PUBCOMP_CODES={0:"Success",146:"Packet Identifier not found"},r.MQTT5_SUBACK_CODES={0:"Granted QoS 0",1:"Granted QoS 1",2:"Granted QoS 2",128:"Unspecified error",131:"Implementation specific error",135:"Not authorized",143:"Topic Filter invalid",145:"Packet Identifier in use",151:"Quota exceeded",158:"Shared Subscriptions not supported",161:"Subscription Identifiers not supported",162:"Wildcard Subscriptions not supported"},r.MQTT5_UNSUBACK_CODES={0:"Success",17:"No subscription existed",128:"Unspecified error",131:"Implementation specific error",135:"Not authorized",143:"Topic Filter invalid",145:"Packet Identifier in use"},r.MQTT5_DISCONNECT_CODES={0:"Normal disconnection",4:"Disconnect with Will Message",128:"Unspecified error",129:"Malformed Packet",130:"Protocol Error",131:"Implementation specific error",135:"Not authorized",137:"Server busy",139:"Server shutting down",141:"Keep Alive timeout",142:"Session taken over",143:"Topic Filter invalid",144:"Topic Name invalid",147:"Receive Maximum exceeded",148:"Topic Alias invalid",149:"Packet too large",150:"Message rate too high",151:"Quota exceeded",152:"Administrative action",153:"Payload format invalid",154:"Retain not supported",155:"QoS not supported",156:"Use another server",157:"Server moved",158:"Shared Subscriptions not supported",159:"Connection rate exceeded",160:"Maximum connect time",161:"Subscription Identifiers not supported",162:"Wildcard Subscriptions not supported"},r.MQTT5_AUTH_CODES={0:"Success",24:"Continue authentication",25:"Re-authenticate"}}),zt=o((e,t)=>{l(),tt(),Fe();var r=1e3,n=6e4,i=60*n,o=24*i,s=7*o,a=365.25*o;function u(e,t,r,n){var i=t>=1.5*r;return Math.round(e/r)+" "+n+(i?"s":"")}t.exports=function(e,t){t=t||{};var l=typeof e;if("string"===l&&e.length>0)return function(e){if(e=String(e),!(e.length>100)){var t=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(e);if(t){var l=parseFloat(t[1]);switch((t[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return l*a;case"weeks":case"week":case"w":return l*s;case"days":case"day":case"d":return l*o;case"hours":case"hour":case"hrs":case"hr":case"h":return l*i;case"minutes":case"minute":case"mins":case"min":case"m":return l*n;case"seconds":case"second":case"secs":case"sec":case"s":return l*r;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return l;default:return}}}}(e);if("number"===l&&isFinite(e))return t.long?function(e){var t=Math.abs(e);return t>=o?u(e,t,o,"day"):t>=i?u(e,t,i,"hour"):t>=n?u(e,t,n,"minute"):t>=r?u(e,t,r,"second"):e+" ms"}(e):function(e){var t=Math.abs(e);return t>=o?Math.round(e/o)+"d":t>=i?Math.round(e/i)+"h":t>=n?Math.round(e/n)+"m":t>=r?Math.round(e/r)+"s":e+"ms"}(e);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(e))}}),Qt=o((e,t)=>{l(),tt(),Fe(),t.exports=function(e){function t(e){let n,i,o,s=null;function a(...e){if(!a.enabled)return;let r=a,i=Number(new Date),o=i-(n||i);r.diff=o,r.prev=n,r.curr=i,n=i,e[0]=t.coerce(e[0]),"string"!=typeof e[0]&&e.unshift("%O");let s=0;e[0]=e[0].replace(/%([a-zA-Z%])/g,(n,i)=>{if("%%"===n)return"%";s++;let o=t.formatters[i];if("function"==typeof o){let t=e[s];n=o.call(r,t),e.splice(s,1),s--}return n}),t.formatArgs.call(r,e),(r.log||t.log).apply(r,e)}return a.namespace=e,a.useColors=t.useColors(),a.color=t.selectColor(e),a.extend=r,a.destroy=t.destroy,Object.defineProperty(a,"enabled",{enumerable:!0,configurable:!1,get:()=>null!==s?s:(i!==t.namespaces&&(i=t.namespaces,o=t.enabled(e)),o),set:e=>{s=e}}),"function"==typeof t.init&&t.init(a),a}function r(e,r){let n=t(this.namespace+(typeof r>"u"?":":r)+e);return n.log=this.log,n}function n(e,t){let r=0,n=0,i=-1,o=0;for(;r<e.length;)if(n<t.length&&(t[n]===e[r]||"*"===t[n]))"*"===t[n]?(i=n,o=r,n++):(r++,n++);else{if(-1===i)return!1;n=i+1,o++,r=o}for(;n<t.length&&"*"===t[n];)n++;return n===t.length}return t.debug=t,t.default=t,t.coerce=function(e){return e instanceof Error?e.stack||e.message:e},t.disable=function(){let e=[...t.names,...t.skips.map(e=>"-"+e)].join(",");return t.enable(""),e},t.enable=function(e){t.save(e),t.namespaces=e,t.names=[],t.skips=[];let r=("string"==typeof e?e:"").trim().replace(/\s+/g,",").split(",").filter(Boolean);for(let e of r)"-"===e[0]?t.skips.push(e.slice(1)):t.names.push(e)},t.enabled=function(e){for(let r of t.skips)if(n(e,r))return!1;for(let r of t.names)if(n(e,r))return!0;return!1},t.humanize=zt(),t.destroy=function(){console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")},Object.keys(e).forEach(r=>{t[r]=e[r]}),t.names=[],t.skips=[],t.formatters={},t.selectColor=function(e){let r=0;for(let t=0;t<e.length;t++)r=(r<<5)-r+e.charCodeAt(t),r|=0;return t.colors[Math.abs(r)%t.colors.length]},t.enable(t.load()),t}}),Yt=o((e,t)=>{l(),tt(),Fe(),e.formatArgs=function(e){if(e[0]=(this.useColors?"%c":"")+this.namespace+(this.useColors?" %c":" ")+e[0]+(this.useColors?"%c ":" ")+"+"+t.exports.humanize(this.diff),!this.useColors)return;let r="color: "+this.color;e.splice(1,0,r,"color: inherit");let n=0,i=0;e[0].replace(/%[a-zA-Z%]/g,e=>{"%%"!==e&&(n++,"%c"===e&&(i=n))}),e.splice(i,0,r)},e.save=function(t){try{t?e.storage.setItem("debug",t):e.storage.removeItem("debug")}catch{}},e.load=function(){let t;try{t=e.storage.getItem("debug")||e.storage.getItem("DEBUG")}catch{}return!t&&typeof u<"u"&&"env"in u&&(t=u.env.DEBUG),t},e.useColors=function(){if(typeof window<"u"&&window.process&&("renderer"===window.process.type||window.process.__nwjs))return!0;if(typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/))return!1;let e;return typeof document<"u"&&document.documentElement&&document.documentElement.style&&document.documentElement.style.WebkitAppearance||typeof window<"u"&&window.console&&(window.console.firebug||window.console.exception&&window.console.table)||typeof navigator<"u"&&navigator.userAgent&&(e=navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/))&&parseInt(e[1],10)>=31||typeof navigator<"u"&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/)},e.storage=function(){try{return localStorage}catch{}}(),e.destroy=(()=>{let e=!1;return()=>{e||(e=!0,console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."))}})(),e.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],e.log=console.debug||console.log||(()=>{}),t.exports=Qt()(e);var{formatters:r}=t.exports;r.j=function(e){try{return JSON.stringify(e)}catch(e){return"[UnexpectedJSONParseError]: "+e.message}}}),Jt=o((e,t)=>{l(),tt(),Fe();var r=Vt(),{EventEmitter:n}=(mt(),a(st)),i=Ht(),o=Kt(),s=Yt()("mqtt-packet:parser");t.exports=class e extends n{constructor(){super(),this.parser=this.constructor.parser}static parser(t){return this instanceof e?(this.settings=t||{},this._states=["_parseHeader","_parseLength","_parsePayload","_newPacket"],this._resetState(),this):(new e).parser(t)}_resetState(){s("_resetState: resetting packet, error, _list, and _stateCounter"),this.packet=new i,this.error=null,this._list=r(),this._stateCounter=0}parse(e){for(this.error&&this._resetState(),this._list.append(e),s("parse: current state: %s",this._states[this._stateCounter]);(-1!==this.packet.length||this._list.length>0)&&this[this._states[this._stateCounter]]()&&!this.error;)this._stateCounter++,s("parse: state complete. _stateCounter is now: %d",this._stateCounter),s("parse: packet.length: %d, buffer list length: %d",this.packet.length,this._list.length),this._stateCounter>=this._states.length&&(this._stateCounter=0);return s("parse: exited while loop. packet: %d, buffer list length: %d",this.packet.length,this._list.length),this._list.length}_parseHeader(){let e=this._list.readUInt8(0),t=e>>o.CMD_SHIFT;this.packet.cmd=o.types[t];let r=15&e,n=o.requiredHeaderFlags[t];return null!=n&&r!==n?this._emitError(new Error(o.requiredHeaderFlagsErrors[t])):(this.packet.retain=0!==(e&o.RETAIN_MASK),this.packet.qos=e>>o.QOS_SHIFT&o.QOS_MASK,this.packet.qos>2?this._emitError(new Error("Packet must not have both QoS bits set to 1")):(this.packet.dup=0!==(e&o.DUP_MASK),s("_parseHeader: packet: %o",this.packet),this._list.consume(1),!0))}_parseLength(){let e=this._parseVarByteNum(!0);return e&&(this.packet.length=e.value,this._list.consume(e.bytes)),s("_parseLength %d",e.value),!!e}_parsePayload(){s("_parsePayload: payload %O",this._list);let e=!1;if(0===this.packet.length||this._list.length>=this.packet.length){switch(this._pos=0,this.packet.cmd){case"connect":this._parseConnect();break;case"connack":this._parseConnack();break;case"publish":this._parsePublish();break;case"puback":case"pubrec":case"pubrel":case"pubcomp":this._parseConfirmation();break;case"subscribe":this._parseSubscribe();break;case"suback":this._parseSuback();break;case"unsubscribe":this._parseUnsubscribe();break;case"unsuback":this._parseUnsuback();break;case"pingreq":case"pingresp":break;case"disconnect":this._parseDisconnect();break;case"auth":this._parseAuth();break;default:this._emitError(new Error("Not supported"))}e=!0}return s("_parsePayload complete result: %s",e),e}_parseConnect(){s("_parseConnect");let e,t,r,n,i={},a=this.packet,l=this._parseString();if(null===l)return this._emitError(new Error("Cannot parse protocolId"));if("MQTT"!==l&&"MQIsdp"!==l)return this._emitError(new Error("Invalid protocolId"));if(a.protocolId=l,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(a.protocolVersion=this._list.readUInt8(this._pos),a.protocolVersion>=128&&(a.bridgeMode=!0,a.protocolVersion=a.protocolVersion-128),3!==a.protocolVersion&&4!==a.protocolVersion&&5!==a.protocolVersion)return this._emitError(new Error("Invalid protocol version"));if(this._pos++,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(1&this._list.readUInt8(this._pos))return this._emitError(new Error("Connect flag bit 0 must be 0, but got 1"));i.username=this._list.readUInt8(this._pos)&o.USERNAME_MASK,i.password=this._list.readUInt8(this._pos)&o.PASSWORD_MASK,i.will=this._list.readUInt8(this._pos)&o.WILL_FLAG_MASK;let u=!!(this._list.readUInt8(this._pos)&o.WILL_RETAIN_MASK),c=(this._list.readUInt8(this._pos)&o.WILL_QOS_MASK)>>o.WILL_QOS_SHIFT;if(i.will)a.will={},a.will.retain=u,a.will.qos=c;else{if(u)return this._emitError(new Error("Will Retain Flag must be set to zero when Will Flag is set to 0"));if(c)return this._emitError(new Error("Will QoS must be set to zero when Will Flag is set to 0"))}if(a.clean=0!==(this._list.readUInt8(this._pos)&o.CLEAN_SESSION_MASK),this._pos++,a.keepalive=this._parseNum(),-1===a.keepalive)return this._emitError(new Error("Packet too short"));if(5===a.protocolVersion){let e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(a.properties=e)}let h=this._parseString();if(null===h)return this._emitError(new Error("Packet too short"));if(a.clientId=h,s("_parseConnect: packet.clientId: %s",a.clientId),i.will){if(5===a.protocolVersion){let e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(a.will.properties=e)}if(e=this._parseString(),null===e)return this._emitError(new Error("Cannot parse will topic"));if(a.will.topic=e,s("_parseConnect: packet.will.topic: %s",a.will.topic),t=this._parseBuffer(),null===t)return this._emitError(new Error("Cannot parse will payload"));a.will.payload=t,s("_parseConnect: packet.will.paylaod: %s",a.will.payload)}if(i.username){if(n=this._parseString(),null===n)return this._emitError(new Error("Cannot parse username"));a.username=n,s("_parseConnect: packet.username: %s",a.username)}if(i.password){if(r=this._parseBuffer(),null===r)return this._emitError(new Error("Cannot parse password"));a.password=r}return this.settings=a,s("_parseConnect: complete"),a}_parseConnack(){s("_parseConnack");let e=this.packet;if(this._list.length<1)return null;let t=this._list.readUInt8(this._pos++);if(t>1)return this._emitError(new Error("Invalid connack flags, bits 7-1 must be set to 0"));if(e.sessionPresent=!!(t&o.SESSIONPRESENT_MASK),5===this.settings.protocolVersion)this._list.length>=2?e.reasonCode=this._list.readUInt8(this._pos++):e.reasonCode=0;else{if(this._list.length<2)return null;e.returnCode=this._list.readUInt8(this._pos++)}if(-1===e.returnCode||-1===e.reasonCode)return this._emitError(new Error("Cannot parse return code"));if(5===this.settings.protocolVersion){let t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}s("_parseConnack: complete")}_parsePublish(){s("_parsePublish");let e=this.packet;if(e.topic=this._parseString(),null===e.topic)return this._emitError(new Error("Cannot parse topic"));if(!(e.qos>0)||this._parseMessageId()){if(5===this.settings.protocolVersion){let t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}e.payload=this._list.slice(this._pos,e.length),s("_parsePublish: payload from buffer list: %o",e.payload)}}_parseSubscribe(){s("_parseSubscribe");let e,t,r,n,i,a,l,u=this.packet;if(u.subscriptions=[],this._parseMessageId()){if(5===this.settings.protocolVersion){let e=this._parseProperties();Object.getOwnPropertyNames(e).length&&(u.properties=e)}if(u.length<=0)return this._emitError(new Error("Malformed subscribe, no payload specified"));for(;this._pos<u.length;){if(e=this._parseString(),null===e)return this._emitError(new Error("Cannot parse topic"));if(this._pos>=u.length)return this._emitError(new Error("Malformed Subscribe Payload"));if(t=this._parseByte(),5===this.settings.protocolVersion){if(192&t)return this._emitError(new Error("Invalid subscribe topic flag bits, bits 7-6 must be 0"))}else if(252&t)return this._emitError(new Error("Invalid subscribe topic flag bits, bits 7-2 must be 0"));if(r=t&o.SUBSCRIBE_OPTIONS_QOS_MASK,r>2)return this._emitError(new Error("Invalid subscribe QoS, must be <= 2"));if(a=0!==(t>>o.SUBSCRIBE_OPTIONS_NL_SHIFT&o.SUBSCRIBE_OPTIONS_NL_MASK),i=0!==(t>>o.SUBSCRIBE_OPTIONS_RAP_SHIFT&o.SUBSCRIBE_OPTIONS_RAP_MASK),n=t>>o.SUBSCRIBE_OPTIONS_RH_SHIFT&o.SUBSCRIBE_OPTIONS_RH_MASK,n>2)return this._emitError(new Error("Invalid retain handling, must be <= 2"));l={topic:e,qos:r},5===this.settings.protocolVersion?(l.nl=a,l.rap=i,l.rh=n):this.settings.bridgeMode&&(l.rh=0,l.rap=!0,l.nl=!0),s("_parseSubscribe: push subscription `%s` to subscription",l),u.subscriptions.push(l)}}}_parseSuback(){s("_parseSuback");let e=this.packet;if(this.packet.granted=[],this._parseMessageId()){if(5===this.settings.protocolVersion){let t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}if(e.length<=0)return this._emitError(new Error("Malformed suback, no payload specified"));for(;this._pos<this.packet.length;){let e=this._list.readUInt8(this._pos++);if(5===this.settings.protocolVersion){if(!o.MQTT5_SUBACK_CODES[e])return this._emitError(new Error("Invalid suback code"))}else if(e>2&&128!==e)return this._emitError(new Error("Invalid suback QoS, must be 0, 1, 2 or 128"));this.packet.granted.push(e)}}}_parseUnsubscribe(){s("_parseUnsubscribe");let e=this.packet;if(e.unsubscriptions=[],this._parseMessageId()){if(5===this.settings.protocolVersion){let t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}if(e.length<=0)return this._emitError(new Error("Malformed unsubscribe, no payload specified"));for(;this._pos<e.length;){let t=this._parseString();if(null===t)return this._emitError(new Error("Cannot parse topic"));s("_parseUnsubscribe: push topic `%s` to unsubscriptions",t),e.unsubscriptions.push(t)}}}_parseUnsuback(){s("_parseUnsuback");let e=this.packet;if(!this._parseMessageId())return this._emitError(new Error("Cannot parse messageId"));if((3===this.settings.protocolVersion||4===this.settings.protocolVersion)&&2!==e.length)return this._emitError(new Error("Malformed unsuback, payload length must be 2"));if(e.length<=0)return this._emitError(new Error("Malformed unsuback, no payload specified"));if(5===this.settings.protocolVersion){let t=this._parseProperties();for(Object.getOwnPropertyNames(t).length&&(e.properties=t),e.granted=[];this._pos<this.packet.length;){let e=this._list.readUInt8(this._pos++);if(!o.MQTT5_UNSUBACK_CODES[e])return this._emitError(new Error("Invalid unsuback code"));this.packet.granted.push(e)}}}_parseConfirmation(){s("_parseConfirmation: packet.cmd: `%s`",this.packet.cmd);let e=this.packet;if(this._parseMessageId(),5===this.settings.protocolVersion){if(e.length>2){switch(e.reasonCode=this._parseByte(),this.packet.cmd){case"puback":case"pubrec":if(!o.MQTT5_PUBACK_PUBREC_CODES[e.reasonCode])return this._emitError(new Error("Invalid "+this.packet.cmd+" reason code"));break;case"pubrel":case"pubcomp":if(!o.MQTT5_PUBREL_PUBCOMP_CODES[e.reasonCode])return this._emitError(new Error("Invalid "+this.packet.cmd+" reason code"))}s("_parseConfirmation: packet.reasonCode `%d`",e.reasonCode)}else e.reasonCode=0;if(e.length>3){let t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}}return!0}_parseDisconnect(){let e=this.packet;if(s("_parseDisconnect"),5===this.settings.protocolVersion){this._list.length>0?(e.reasonCode=this._parseByte(),o.MQTT5_DISCONNECT_CODES[e.reasonCode]||this._emitError(new Error("Invalid disconnect reason code"))):e.reasonCode=0;let t=this._parseProperties();Object.getOwnPropertyNames(t).length&&(e.properties=t)}return s("_parseDisconnect result: true"),!0}_parseAuth(){s("_parseAuth");let e=this.packet;if(5!==this.settings.protocolVersion)return this._emitError(new Error("Not supported auth packet for this version MQTT"));if(e.reasonCode=this._parseByte(),!o.MQTT5_AUTH_CODES[e.reasonCode])return this._emitError(new Error("Invalid auth reason code"));let t=this._parseProperties();return Object.getOwnPropertyNames(t).length&&(e.properties=t),s("_parseAuth: result: true"),!0}_parseMessageId(){let e=this.packet;return e.messageId=this._parseNum(),null===e.messageId?(this._emitError(new Error("Cannot parse messageId")),!1):(s("_parseMessageId: packet.messageId %d",e.messageId),!0)}_parseString(e){let t=this._parseNum(),r=t+this._pos;if(-1===t||r>this._list.length||r>this.packet.length)return null;let n=this._list.toString("utf8",this._pos,r);return this._pos+=t,s("_parseString: result: %s",n),n}_parseStringPair(){return s("_parseStringPair"),{name:this._parseString(),value:this._parseString()}}_parseBuffer(){let e=this._parseNum(),t=e+this._pos;if(-1===e||t>this._list.length||t>this.packet.length)return null;let r=this._list.slice(this._pos,t);return this._pos+=e,s("_parseBuffer: result: %o",r),r}_parseNum(){if(this._list.length-this._pos<2)return-1;let e=this._list.readUInt16BE(this._pos);return this._pos+=2,s("_parseNum: result: %s",e),e}_parse4ByteNum(){if(this._list.length-this._pos<4)return-1;let e=this._list.readUInt32BE(this._pos);return this._pos+=4,s("_parse4ByteNum: result: %s",e),e}_parseVarByteNum(e){s("_parseVarByteNum");let t,r=0,n=1,i=0,a=!1,l=this._pos?this._pos:0;for(;r<4&&l+r<this._list.length;){if(t=this._list.readUInt8(l+r++),i+=n*(t&o.VARBYTEINT_MASK),n*=128,0===(t&o.VARBYTEINT_FIN_MASK)){a=!0;break}if(this._list.length<=r)break}return!a&&4===r&&this._list.length>=r&&this._emitError(new Error("Invalid variable byte integer")),l&&(this._pos+=r),a=!!a&&(e?{bytes:r,value:i}:i),s("_parseVarByteNum: result: %o",a),a}_parseByte(){let e;return this._pos<this._list.length&&(e=this._list.readUInt8(this._pos),this._pos++),s("_parseByte: result: %o",e),e}_parseByType(e){switch(s("_parseByType: type: %s",e),e){case"byte":return 0!==this._parseByte();case"int8":return this._parseByte();case"int16":return this._parseNum();case"int32":return this._parse4ByteNum();case"var":return this._parseVarByteNum();case"string":return this._parseString();case"pair":return this._parseStringPair();case"binary":return this._parseBuffer()}}_parseProperties(){s("_parseProperties");let e=this._parseVarByteNum(),t=this._pos+e,r={};for(;this._pos<t;){let e=this._parseByte();if(!e)return this._emitError(new Error("Cannot parse property code type")),!1;let t=o.propertiesCodes[e];if(!t)return this._emitError(new Error("Unknown property")),!1;if("userProperties"===t){r[t]||(r[t]=Object.create(null));let e=this._parseByType(o.propertiesTypes[t]);if(r[t][e.name])if(Array.isArray(r[t][e.name]))r[t][e.name].push(e.value);else{let n=r[t][e.name];r[t][e.name]=[n],r[t][e.name].push(e.value)}else r[t][e.name]=e.value;continue}r[t]?(Array.isArray(r[t])||(r[t]=[r[t]]),r[t].push(this._parseByType(o.propertiesTypes[t]))):r[t]=this._parseByType(o.propertiesTypes[t])}return r}_newPacket(){return s("_newPacket"),this.packet&&(this._list.consume(this.packet.length),s("_newPacket: parser emit packet: packet.cmd: %s, packet.payload: %s, packet.length: %d",this.packet.cmd,this.packet.payload,this.packet.length),this.emit("packet",this.packet)),s("_newPacket: new packet"),this.packet=new i,this._pos=0,!0}_emitError(e){s("_emitError",e),this.error=e,this.emit("error",e)}}}),Xt=o((e,t)=>{l(),tt(),Fe();var{Buffer:r}=(et(),a(Qe)),n={},i=r.isBuffer(r.from([1,2]).subarray(0,1));function o(e){let t=r.allocUnsafe(2);return t.writeUInt8(e>>8,0),t.writeUInt8(255&e,1),t}t.exports={cache:n,generateCache:function(){for(let e=0;e<65536;e++)n[e]=o(e)},generateNumber:o,genBufVariableByteInt:function(e){let t=0,n=0,o=r.allocUnsafe(4);do{t=e%128|0,(e=e/128|0)>0&&(t|=128),o.writeUInt8(t,n++)}while(e>0&&n<4);return e>0&&(n=0),i?o.subarray(0,n):o.slice(0,n)},generate4ByteBuffer:function(e){let t=r.allocUnsafe(4);return t.writeUInt32BE(e,0),t}}}),Zt=o((e,t)=>{l(),tt(),Fe(),typeof u>"u"||!u.version||0===u.version.indexOf("v0.")||0===u.version.indexOf("v1.")&&0!==u.version.indexOf("v1.8.")?t.exports={nextTick:function(e,t,r,n){if("function"!=typeof e)throw new TypeError('"callback" argument must be a function');var i,o,s=arguments.length;switch(s){case 0:case 1:return u.nextTick(e);case 2:return u.nextTick(function(){e.call(null,t)});case 3:return u.nextTick(function(){e.call(null,t,r)});case 4:return u.nextTick(function(){e.call(null,t,r,n)});default:for(i=new Array(s-1),o=0;o<i.length;)i[o++]=arguments[o];return u.nextTick(function(){e.apply(null,i)})}}}:t.exports=u}),er=o((e,t)=>{l(),tt(),Fe();var r=Kt(),{Buffer:n}=(et(),a(Qe)),i=n.allocUnsafe(0),o=n.from([0]),s=Xt(),u=Zt().nextTick,c=Yt()("mqtt-packet:writeToStream"),h=s.cache,f=s.generateNumber,p=s.generateCache,d=s.genBufVariableByteInt,g=s.generate4ByteBuffer,y=I,m=!0;function b(e,t,s){switch(c("generate called"),t.cork&&(t.cork(),u(v,t)),m&&(m=!1,p()),c("generate: packet.cmd: %s",e.cmd),e.cmd){case"connect":return function(e,t){let i=e||{},o=i.protocolId||"MQTT",s=i.protocolVersion||4,a=i.will,l=i.clean,u=i.keepalive||0,c=i.clientId||"",h=i.username,f=i.password,p=i.properties;void 0===l&&(l=!0);let d,g,m=0;if("string"!=typeof o&&!n.isBuffer(o))return t.destroy(new Error("Invalid protocolId")),!1;if(m+=o.length+2,3!==s&&4!==s&&5!==s)return t.destroy(new Error("Invalid protocol version")),!1;if(m+=1,("string"==typeof c||n.isBuffer(c))&&(c||s>=4)&&(c||l))m+=n.byteLength(c)+2;else{if(s<4)return t.destroy(new Error("clientId must be supplied before 3.1.1")),!1;if(1*l==0)return t.destroy(new Error("clientId must be given if cleanSession set to 0")),!1}if("number"!=typeof u||u<0||u>65535||u%1!=0)return t.destroy(new Error("Invalid keepalive")),!1;if(m+=2,m+=1,5===s){if(d=O(t,p),!d)return!1;m+=d.length}if(a){if("object"!=typeof a)return t.destroy(new Error("Invalid will")),!1;if(!a.topic||"string"!=typeof a.topic)return t.destroy(new Error("Invalid will topic")),!1;if(m+=n.byteLength(a.topic)+2,m+=2,a.payload){if(!(a.payload.length>=0))return t.destroy(new Error("Invalid will payload")),!1;"string"==typeof a.payload?m+=n.byteLength(a.payload):m+=a.payload.length}if(g={},5===s){if(g=O(t,a.properties),!g)return!1;m+=g.length}}let b=!1;if(null!=h){if(!P(h))return t.destroy(new Error("Invalid username")),!1;b=!0,m+=n.byteLength(h)+2}if(null!=f){if(!b)return t.destroy(new Error("Username is required to use password")),!1;if(!P(f))return t.destroy(new Error("Invalid password")),!1;m+=C(f)+2}t.write(r.CONNECT_HEADER),_(t,m),R(t,o),i.bridgeMode&&(s+=128),t.write(131===s?r.VERSION131:132===s?r.VERSION132:4===s?r.VERSION4:5===s?r.VERSION5:r.VERSION3);let v=0;return v|=null!=h?r.USERNAME_MASK:0,v|=null!=f?r.PASSWORD_MASK:0,v|=a&&a.retain?r.WILL_RETAIN_MASK:0,v|=a&&a.qos?a.qos<<r.WILL_QOS_SHIFT:0,v|=a?r.WILL_FLAG_MASK:0,v|=l?r.CLEAN_SESSION_MASK:0,t.write(n.from([v])),y(t,u),5===s&&d.write(),R(t,c),a&&(5===s&&g.write(),E(t,a.topic),R(t,a.payload)),null!=h&&R(t,h),null!=f&&R(t,f),!0}(e,t);case"connack":return function(e,t,i){let s=i?i.protocolVersion:4,a=e||{},l=5===s?a.reasonCode:a.returnCode,u=a.properties,c=2;if("number"!=typeof l)return t.destroy(new Error("Invalid return code")),!1;let h=null;if(5===s){if(h=O(t,u),!h)return!1;c+=h.length}return t.write(r.CONNACK_HEADER),_(t,c),t.write(a.sessionPresent?r.SESSIONPRESENT_HEADER:o),t.write(n.from([l])),h?.write(),!0}(e,t,s);case"publish":return function(e,t,o){c("publish: packet: %o",e);let s=o?o.protocolVersion:4,a=e||{},l=a.qos||0,u=a.retain?r.RETAIN_MASK:0,h=a.topic,f=a.payload||i,p=a.messageId,d=a.properties,g=0;if("string"==typeof h)g+=n.byteLength(h)+2;else{if(!n.isBuffer(h))return t.destroy(new Error("Invalid topic")),!1;g+=h.length+2}if(n.isBuffer(f)?g+=f.length:g+=n.byteLength(f),l&&"number"!=typeof p)return t.destroy(new Error("Invalid messageId")),!1;l&&(g+=2);let m=null;if(5===s){if(m=O(t,d),!m)return!1;g+=m.length}return t.write(r.PUBLISH_HEADER[l][a.dup?1:0][u?1:0]),_(t,g),y(t,C(h)),t.write(h),l>0&&y(t,p),m?.write(),c("publish: payload: %o",f),t.write(f)}(e,t,s);case"puback":case"pubrec":case"pubrel":case"pubcomp":return function(e,t,i){let o=i?i.protocolVersion:4,s=e||{},a=s.cmd||"puback",l=s.messageId,u=s.dup&&"pubrel"===a?r.DUP_MASK:0,c=0,h=s.reasonCode,f=s.properties,p=5===o?3:2;if("pubrel"===a&&(c=1),"number"!=typeof l)return t.destroy(new Error("Invalid messageId")),!1;let d=null;if(5===o&&"object"==typeof f){if(d=k(t,f,i,p),!d)return!1;p+=d.length}return t.write(r.ACKS[a][c][u][0]),3===p&&(p+=0!==h?1:-1),_(t,p),y(t,l),5===o&&2!==p&&t.write(n.from([h])),null!==d?d.write():4===p&&t.write(n.from([0])),!0}(e,t,s);case"subscribe":return function(e,t,i){c("subscribe: packet: ");let o=i?i.protocolVersion:4,s=e||{},a=s.dup?r.DUP_MASK:0,l=s.messageId,u=s.subscriptions,h=s.properties,f=0;if("number"!=typeof l)return t.destroy(new Error("Invalid messageId")),!1;f+=2;let p=null;if(5===o){if(p=O(t,h),!p)return!1;f+=p.length}if("object"!=typeof u||!u.length)return t.destroy(new Error("Invalid subscriptions")),!1;for(let e=0;e<u.length;e+=1){let r=u[e].topic,i=u[e].qos;if("string"!=typeof r)return t.destroy(new Error("Invalid subscriptions - invalid topic")),!1;if("number"!=typeof i)return t.destroy(new Error("Invalid subscriptions - invalid qos")),!1;if(5===o){if("boolean"!=typeof(u[e].nl||!1))return t.destroy(new Error("Invalid subscriptions - invalid No Local")),!1;if("boolean"!=typeof(u[e].rap||!1))return t.destroy(new Error("Invalid subscriptions - invalid Retain as Published")),!1;let r=u[e].rh||0;if("number"!=typeof r||r>2)return t.destroy(new Error("Invalid subscriptions - invalid Retain Handling")),!1}f+=n.byteLength(r)+2+1}c("subscribe: writing to stream: %o",r.SUBSCRIBE_HEADER),t.write(r.SUBSCRIBE_HEADER[1][a?1:0][0]),_(t,f),y(t,l),null!==p&&p.write();let d=!0;for(let e of u){let i,s=e.topic,a=e.qos,l=+e.nl,u=+e.rap,c=e.rh;E(t,s),i=r.SUBSCRIBE_OPTIONS_QOS[a],5===o&&(i|=l?r.SUBSCRIBE_OPTIONS_NL:0,i|=u?r.SUBSCRIBE_OPTIONS_RAP:0,i|=c?r.SUBSCRIBE_OPTIONS_RH[c]:0),d=t.write(n.from([i]))}return d}(e,t,s);case"suback":return function(e,t,i){let o=i?i.protocolVersion:4,s=e||{},a=s.messageId,l=s.granted,u=s.properties,c=0;if("number"!=typeof a)return t.destroy(new Error("Invalid messageId")),!1;if(c+=2,"object"!=typeof l||!l.length)return t.destroy(new Error("Invalid qos vector")),!1;for(let e=0;e<l.length;e+=1){if("number"!=typeof l[e])return t.destroy(new Error("Invalid qos vector")),!1;c+=1}let h=null;if(5===o){if(h=k(t,u,i,c),!h)return!1;c+=h.length}return t.write(r.SUBACK_HEADER),_(t,c),y(t,a),null!==h&&h.write(),t.write(n.from(l))}(e,t,s);case"unsubscribe":return function(e,t,i){let o=i?i.protocolVersion:4,s=e||{},a=s.messageId,l=s.dup?r.DUP_MASK:0,u=s.unsubscriptions,c=s.properties,h=0;if("number"!=typeof a)return t.destroy(new Error("Invalid messageId")),!1;if(h+=2,"object"!=typeof u||!u.length)return t.destroy(new Error("Invalid unsubscriptions")),!1;for(let e=0;e<u.length;e+=1){if("string"!=typeof u[e])return t.destroy(new Error("Invalid unsubscriptions")),!1;h+=n.byteLength(u[e])+2}let f=null;if(5===o){if(f=O(t,c),!f)return!1;h+=f.length}t.write(r.UNSUBSCRIBE_HEADER[1][l?1:0][0]),_(t,h),y(t,a),null!==f&&f.write();let p=!0;for(let e=0;e<u.length;e++)p=E(t,u[e]);return p}(e,t,s);case"unsuback":return function(e,t,i){let o=i?i.protocolVersion:4,s=e||{},a=s.messageId,l=s.dup?r.DUP_MASK:0,u=s.granted,c=s.properties,h=s.cmd,f=0,p=2;if("number"!=typeof a)return t.destroy(new Error("Invalid messageId")),!1;if(5===o){if("object"!=typeof u||!u.length)return t.destroy(new Error("Invalid qos vector")),!1;for(let e=0;e<u.length;e+=1){if("number"!=typeof u[e])return t.destroy(new Error("Invalid qos vector")),!1;p+=1}}let d=null;if(5===o){if(d=k(t,c,i,p),!d)return!1;p+=d.length}return t.write(r.ACKS[h][f][l][0]),_(t,p),y(t,a),null!==d&&d.write(),5===o&&t.write(n.from(u)),!0}(e,t,s);case"pingreq":case"pingresp":return function(e,t){return t.write(r.EMPTY[e.cmd])}(e,t);case"disconnect":return function(e,t,i){let o=i?i.protocolVersion:4,s=e||{},a=s.reasonCode,l=s.properties,u=5===o?1:0,c=null;if(5===o){if(c=k(t,l,i,u),!c)return!1;u+=c.length}return t.write(n.from([r.codes.disconnect<<4])),_(t,u),5===o&&t.write(n.from([a])),null!==c&&c.write(),!0}(e,t,s);case"auth":return function(e,t,i){let o=i?i.protocolVersion:4,s=e||{},a=s.reasonCode,l=s.properties,u=5===o?1:0;5!==o&&t.destroy(new Error("Invalid mqtt version for auth packet"));let c=k(t,l,i,u);return!!c&&(u+=c.length,t.write(n.from([r.codes.auth<<4])),_(t,u),t.write(n.from([a])),null!==c&&c.write(),!0)}(e,t,s);default:return t.destroy(new Error("Unknown command")),!1}}function v(e){e.uncork()}Object.defineProperty(b,"cacheNumbers",{get:()=>y===I,set(e){e?((!h||0===Object.keys(h).length)&&(m=!0),y=I):(m=!1,y=A)}});var w={};function _(e,t){if(t>r.VARBYTEINT_MAX)return e.destroy(new Error(`Invalid variable byte integer: ${t}`)),!1;let n=w[t];return n||(n=d(t),t<16384&&(w[t]=n)),c("writeVarByteInt: writing to stream: %o",n),e.write(n)}function E(e,t){let r=n.byteLength(t);return y(e,r),c("writeString: %s",t),e.write(t,"utf8")}function S(e,t,r){E(e,t),E(e,r)}function I(e,t){return c("writeNumberCached: number: %d",t),c("writeNumberCached: %o",h[t]),e.write(h[t])}function A(e,t){let r=f(t);return c("writeNumberGenerated: %o",r),e.write(r)}function R(e,t){"string"==typeof t?E(e,t):t?(y(e,t.length),e.write(t)):y(e,0)}function O(e,t){if("object"!=typeof t||null!=t.length)return{length:1,write(){T(e,{},0)}};let i=0;function o(t,i){let o=0;switch(r.propertiesTypes[t]){case"byte":if("boolean"!=typeof i)return e.destroy(new Error(`Invalid ${t}: ${i}`)),!1;o+=2;break;case"int8":if("number"!=typeof i||i<0||i>255)return e.destroy(new Error(`Invalid ${t}: ${i}`)),!1;o+=2;break;case"binary":if(i&&null===i)return e.destroy(new Error(`Invalid ${t}: ${i}`)),!1;o+=1+n.byteLength(i)+2;break;case"int16":if("number"!=typeof i||i<0||i>65535)return e.destroy(new Error(`Invalid ${t}: ${i}`)),!1;o+=3;break;case"int32":if("number"!=typeof i||i<0||i>4294967295)return e.destroy(new Error(`Invalid ${t}: ${i}`)),!1;o+=5;break;case"var":if("number"!=typeof i||i<0||i>268435455)return e.destroy(new Error(`Invalid ${t}: ${i}`)),!1;o+=1+n.byteLength(d(i));break;case"string":if("string"!=typeof i)return e.destroy(new Error(`Invalid ${t}: ${i}`)),!1;o+=3+n.byteLength(i.toString());break;case"pair":if("object"!=typeof i)return e.destroy(new Error(`Invalid ${t}: ${i}`)),!1;o+=Object.getOwnPropertyNames(i).reduce((e,t)=>{let r=i[t];return Array.isArray(r)?e+=r.reduce((e,r)=>e+=3+n.byteLength(t.toString())+2+n.byteLength(r.toString()),0):e+=3+n.byteLength(t.toString())+2+n.byteLength(i[t].toString()),e},0);break;default:return e.destroy(new Error(`Invalid property ${t}: ${i}`)),!1}return o}if(t)for(let e in t){let r=0,n=0,s=t[e];if(void 0!==s){if(Array.isArray(s))for(let t=0;t<s.length;t++){if(n=o(e,s[t]),!n)return!1;r+=n}else{if(n=o(e,s),!n)return!1;r=n}if(!r)return!1;i+=r}}return{length:n.byteLength(d(i))+i,write(){T(e,t,i)}}}function k(e,t,r,n){let i=["reasonString","userProperties"],o=r&&r.properties&&r.properties.maximumPacketSize?r.properties.maximumPacketSize:0,s=O(e,t);if(o)for(;n+s.length>o;){let r=i.shift();if(!r||!t[r])return!1;delete t[r],s=O(e,t)}return s}function x(e,t,i){switch(r.propertiesTypes[t]){case"byte":e.write(n.from([r.properties[t]])),e.write(n.from([+i]));break;case"int8":e.write(n.from([r.properties[t]])),e.write(n.from([i]));break;case"binary":e.write(n.from([r.properties[t]])),R(e,i);break;case"int16":e.write(n.from([r.properties[t]])),y(e,i);break;case"int32":e.write(n.from([r.properties[t]])),function(e,t){let r=g(t);c("write4ByteNumber: %o",r),e.write(r)}(e,i);break;case"var":e.write(n.from([r.properties[t]])),_(e,i);break;case"string":e.write(n.from([r.properties[t]])),E(e,i);break;case"pair":Object.getOwnPropertyNames(i).forEach(o=>{let s=i[o];Array.isArray(s)?s.forEach(i=>{e.write(n.from([r.properties[t]])),S(e,o.toString(),i.toString())}):(e.write(n.from([r.properties[t]])),S(e,o.toString(),s.toString()))});break;default:return e.destroy(new Error(`Invalid property ${t} value: ${i}`)),!1}}function T(e,t,r){_(e,r);for(let r in t)if(Object.prototype.hasOwnProperty.call(t,r)&&null!=t[r]){let n=t[r];if(Array.isArray(n))for(let t=0;t<n.length;t++)x(e,r,n[t]);else x(e,r,n)}}function C(e){return e?e instanceof n?e.length:n.byteLength(e):0}function P(e){return"string"==typeof e||e instanceof n}t.exports=b}),tr=o((e,t)=>{l(),tt(),Fe();var r=er(),{EventEmitter:n}=(mt(),a(st)),{Buffer:i}=(et(),a(Qe));var o=class extends n{constructor(){super(),this._array=new Array(20),this._i=0}write(e){return this._array[this._i++]=e,!0}concat(){let e,t=0,r=new Array(this._array.length),n=this._array,o=0;for(e=0;e<n.length&&void 0!==n[e];e++)"string"!=typeof n[e]?r[e]=n[e].length:r[e]=i.byteLength(n[e]),t+=r[e];let s=i.allocUnsafe(t);for(e=0;e<n.length&&void 0!==n[e];e++)"string"!=typeof n[e]?(n[e].copy(s,o),o+=r[e]):(s.write(n[e],o),o+=r[e]);return s}destroy(e){e&&this.emit("error",e)}};t.exports=function(e,t){let n=new o;return r(e,n,t),n.concat()}}),rr=o(e=>{l(),tt(),Fe(),e.parser=Jt().parser,e.generate=tr(),e.writeToStream=er()}),nr=o((e,t)=>{function r(e){return e instanceof Je?Je.from(e):new e.constructor(e.buffer.slice(),e.byteOffset,e.length)}l(),tt(),Fe(),t.exports=function(e){if((e=e||{}).circles)return function(e){let t=[],n=[],i=new Map;if(i.set(Date,e=>new Date(e)),i.set(Map,(e,t)=>new Map(s(Array.from(e),t))),i.set(Set,(e,t)=>new Set(s(Array.from(e),t))),e.constructorHandlers)for(let t of e.constructorHandlers)i.set(t[0],t[1]);let o=null;return e.proto?l:a;function s(e,s){let a=Object.keys(e),l=new Array(a.length);for(let u=0;u<a.length;u++){let c=a[u],h=e[c];if("object"!=typeof h||null===h)l[c]=h;else if(h.constructor!==Object&&(o=i.get(h.constructor)))l[c]=o(h,s);else if(ArrayBuffer.isView(h))l[c]=r(h);else{let e=t.indexOf(h);l[c]=-1!==e?n[e]:s(h)}}return l}function a(e){if("object"!=typeof e||null===e)return e;if(Array.isArray(e))return s(e,a);if(e.constructor!==Object&&(o=i.get(e.constructor)))return o(e,a);let l={};t.push(e),n.push(l);for(let s in e){if(!1===Object.hasOwnProperty.call(e,s))continue;let u=e[s];if("object"!=typeof u||null===u)l[s]=u;else if(u.constructor!==Object&&(o=i.get(u.constructor)))l[s]=o(u,a);else if(ArrayBuffer.isView(u))l[s]=r(u);else{let e=t.indexOf(u);l[s]=-1!==e?n[e]:a(u)}}return t.pop(),n.pop(),l}function l(e){if("object"!=typeof e||null===e)return e;if(Array.isArray(e))return s(e,l);if(e.constructor!==Object&&(o=i.get(e.constructor)))return o(e,l);let a={};t.push(e),n.push(a);for(let s in e){let u=e[s];if("object"!=typeof u||null===u)a[s]=u;else if(u.constructor!==Object&&(o=i.get(u.constructor)))a[s]=o(u,l);else if(ArrayBuffer.isView(u))a[s]=r(u);else{let e=t.indexOf(u);a[s]=-1!==e?n[e]:l(u)}}return t.pop(),n.pop(),a}}(e);let t=new Map;if(t.set(Date,e=>new Date(e)),t.set(Map,(e,t)=>new Map(i(Array.from(e),t))),t.set(Set,(e,t)=>new Set(i(Array.from(e),t))),e.constructorHandlers)for(let r of e.constructorHandlers)t.set(r[0],r[1]);let n=null;return e.proto?function e(o){if("object"!=typeof o||null===o)return o;if(Array.isArray(o))return i(o,e);if(o.constructor!==Object&&(n=t.get(o.constructor)))return n(o,e);let s={};for(let i in o){let a=o[i];"object"!=typeof a||null===a?s[i]=a:a.constructor!==Object&&(n=t.get(a.constructor))?s[i]=n(a,e):ArrayBuffer.isView(a)?s[i]=r(a):s[i]=e(a)}return s}:function e(o){if("object"!=typeof o||null===o)return o;if(Array.isArray(o))return i(o,e);if(o.constructor!==Object&&(n=t.get(o.constructor)))return n(o,e);let s={};for(let i in o){if(!1===Object.hasOwnProperty.call(o,i))continue;let a=o[i];"object"!=typeof a||null===a?s[i]=a:a.constructor!==Object&&(n=t.get(a.constructor))?s[i]=n(a,e):ArrayBuffer.isView(a)?s[i]=r(a):s[i]=e(a)}return s};function i(e,i){let o=Object.keys(e),s=new Array(o.length);for(let a=0;a<o.length;a++){let l=o[a],u=e[l];"object"!=typeof u||null===u?s[l]=u:u.constructor!==Object&&(n=t.get(u.constructor))?s[l]=n(u,i):ArrayBuffer.isView(u)?s[l]=r(u):s[l]=i(u)}return s}}}),ir=o((e,t)=>{l(),tt(),Fe(),t.exports=nr()()}),or=o(e=>{function t(e){let t=e.split("/");for(let e=0;e<t.length;e++)if("+"!==t[e]){if("#"===t[e])return e===t.length-1;if(-1!==t[e].indexOf("+")||-1!==t[e].indexOf("#"))return!1}return!0}l(),tt(),Fe(),Object.defineProperty(e,"__esModule",{value:!0}),e.validateTopic=t,e.validateTopics=function(e){if(0===e.length)return"empty_topic_list";for(let r=0;r<e.length;r++)if(!t(e[r]))return e[r];return null}}),sr=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"__esModule",{value:!0});var t=$t(),r={objectMode:!0},n={clean:!0};e.default=class{options;_inflights;constructor(e){this.options=e||{},this.options={...n,...e},this._inflights=new Map}put(e,t){return this._inflights.set(e.messageId,e),t&&t(),this}createStream(){let e=new t.Readable(r),n=[],i=!1,o=0;return this._inflights.forEach((e,t)=>{n.push(e)}),e._read=()=>{!i&&o<n.length?e.push(n[o++]):e.push(null)},e.destroy=t=>{if(!i)return i=!0,setTimeout(()=>{e.emit("close")},0),e},e}del(e,t){let r=this._inflights.get(e.messageId);return r?(this._inflights.delete(e.messageId),t(null,r)):t&&t(new Error("missing packet")),this}get(e,t){let r=this._inflights.get(e.messageId);return r?t(null,r):t&&t(new Error("missing packet")),this}close(e){this.options.clean&&(this._inflights=null),e&&e()}}}),ar=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"__esModule",{value:!0});var t=[0,16,128,131,135,144,145,151,153];e.default=(e,r,n)=>{e.log("handlePublish: packet %o",r),n=typeof n<"u"?n:e.noop;let i=r.topic.toString(),o=r.payload,{qos:s}=r,{messageId:a}=r,{options:l}=e;if(5===e.options.protocolVersion){let t;if(r.properties&&(t=r.properties.topicAlias),typeof t<"u")if(0===i.length){if(!(t>0&&t<=65535))return e.log("handlePublish :: topic alias out of range. alias: %d",t),void e.emit("error",new Error("Received Topic Alias is out of range"));{let r=e.topicAliasRecv.getTopicByAlias(t);if(!r)return e.log("handlePublish :: unregistered topic alias. alias: %d",t),void e.emit("error",new Error("Received unregistered Topic Alias"));i=r,e.log("handlePublish :: topic complemented by alias. topic: %s - alias: %d",i,t)}}else{if(!e.topicAliasRecv.put(i,t))return e.log("handlePublish :: topic alias out of range. alias: %d",t),void e.emit("error",new Error("Received Topic Alias is out of range"));e.log("handlePublish :: registered topic: %s - alias: %d",i,t)}}switch(e.log("handlePublish: qos %d",s),s){case 2:l.customHandleAcks(i,o,r,(i,o)=>("number"==typeof i&&(o=i,i=null),i?e.emit("error",i):-1===t.indexOf(o)?e.emit("error",new Error("Wrong reason code for pubrec")):void(o?e._sendPacket({cmd:"pubrec",messageId:a,reasonCode:o},n):e.incomingStore.put(r,()=>{e._sendPacket({cmd:"pubrec",messageId:a},n)}))));break;case 1:l.customHandleAcks(i,o,r,(s,l)=>("number"==typeof s&&(l=s,s=null),s?e.emit("error",s):-1===t.indexOf(l)?e.emit("error",new Error("Wrong reason code for puback")):(l||e.emit("message",i,o,r),void e.handleMessage(r,t=>{if(t)return n&&n(t);e._sendPacket({cmd:"puback",messageId:a,reasonCode:l},n)}))));break;case 0:e.emit("message",i,o,r),e.handleMessage(r,n);break;default:e.log("handlePublish: unknown QoS. Doing nothing.")}}}),lr=o((e,t)=>{t.exports={version:"5.15.2"}}),ur=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"__esModule",{value:!0}),e.MQTTJS_VERSION=e.nextTick=e.ErrorWithSubackPacket=e.ErrorWithReasonCode=void 0,e.applyMixin=function(e,t,r=!1){let n=[t];for(;;){let e=n[0],t=Object.getPrototypeOf(e);if(!t?.prototype)break;n.unshift(t)}for(let t of n)for(let n of Object.getOwnPropertyNames(t.prototype))(r||"constructor"!==n)&&Object.defineProperty(e.prototype,n,Object.getOwnPropertyDescriptor(t.prototype,n)??Object.create(null))};var t=class e extends Error{code;constructor(t,r){super(t),this.code=r,Object.setPrototypeOf(this,e.prototype),Object.getPrototypeOf(this).name="ErrorWithReasonCode"}};e.ErrorWithReasonCode=t;var r=class e extends Error{packet;constructor(t,r){super(t),this.packet=r,Object.setPrototypeOf(this,e.prototype),Object.getPrototypeOf(this).name="ErrorWithSubackPacket"}};e.ErrorWithSubackPacket=r,e.nextTick="function"==typeof u?.nextTick?u.nextTick:e=>{setTimeout(e,0)},e.MQTTJS_VERSION=lr().version}),cr=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"__esModule",{value:!0}),e.ReasonCodes=void 0;var t=ur();e.ReasonCodes={0:"",1:"Unacceptable protocol version",2:"Identifier rejected",3:"Server unavailable",4:"Bad username or password",5:"Not authorized",16:"No matching subscribers",17:"No subscription existed",128:"Unspecified error",129:"Malformed Packet",130:"Protocol Error",131:"Implementation specific error",132:"Unsupported Protocol Version",133:"Client Identifier not valid",134:"Bad User Name or Password",135:"Not authorized",136:"Server unavailable",137:"Server busy",138:"Banned",139:"Server shutting down",140:"Bad authentication method",141:"Keep Alive timeout",142:"Session taken over",143:"Topic Filter invalid",144:"Topic Name invalid",145:"Packet identifier in use",146:"Packet Identifier not found",147:"Receive Maximum exceeded",148:"Topic Alias invalid",149:"Packet too large",150:"Message rate too high",151:"Quota exceeded",152:"Administrative action",153:"Payload format invalid",154:"Retain not supported",155:"QoS not supported",156:"Use another server",157:"Server moved",158:"Shared Subscriptions not supported",159:"Connection rate exceeded",160:"Maximum connect time",161:"Subscription Identifiers not supported",162:"Wildcard Subscriptions not supported"};e.default=(r,n)=>{let{messageId:i}=n,o=n.cmd,s=null,a=r.outgoing[i]?r.outgoing[i].cb:null,l=null;if(a){switch(r.log("_handleAck :: packet type",o),o){case"pubcomp":case"puback":{let o=n.reasonCode;o&&o>0&&16!==o?(l=new t.ErrorWithReasonCode(`Publish error: ${e.ReasonCodes[o]}`,o),r._removeOutgoingAndStoreMessage(i,()=>{a(l,n)})):r._removeOutgoingAndStoreMessage(i,a);break}case"pubrec":{s={cmd:"pubrel",qos:2,messageId:i};let o=n.reasonCode;o&&o>0&&16!==o?(l=new t.ErrorWithReasonCode(`Publish error: ${e.ReasonCodes[o]}`,o),r._removeOutgoingAndStoreMessage(i,()=>{a(l,n)})):r._sendPacket(s);break}case"suback":{delete r.outgoing[i],r.messageIdProvider.deallocate(i);let t=n.granted;for(let n=0;n<t.length;n++){let o=t[n];if(128&o){l=new Error(`Subscribe error: ${e.ReasonCodes[o]}`),l.code=o;let t=r.messageIdToTopic[i];t&&t.forEach(e=>{delete r._resubscribeTopics[e]})}}delete r.messageIdToTopic[i],r._invokeStoreProcessingQueue(),a(l,n);break}case"unsuback":delete r.outgoing[i],r.messageIdProvider.deallocate(i),r._invokeStoreProcessingQueue(),a(null,n);break;default:r.emit("error",new Error("unrecognized packet type"))}r.disconnecting&&0===Object.keys(r.outgoing).length&&r.emit("outgoingEmpty")}else r.log("_handleAck :: Server sent an ack in error. Ignoring.")}}),hr=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"__esModule",{value:!0});var t=ur(),r=cr();e.default=(e,n)=>{let{options:i}=e,o=i.protocolVersion,s=5===o?n.reasonCode:n.returnCode;if(5!==o){let r=new t.ErrorWithReasonCode(`Protocol error: Auth packets are only supported in MQTT 5. Your version:${o}`,s);return void e.emit("error",r)}e.handleAuth(n,(n,i)=>{if(n)e.emit("error",n);else if(24===s)e.reconnecting=!1,e._sendPacket(i);else{let n=new t.ErrorWithReasonCode(`Connection refused: ${r.ReasonCodes[s]}`,s);e.emit("error",n)}})}}),fr=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"__esModule",{value:!0}),e.LRUCache=void 0;var t="object"==typeof performance&&performance&&"function"==typeof performance.now?performance:Date,r=new Set,n="object"==typeof u&&u?u:{},i=(e,t,r,i)=>{"function"==typeof n.emitWarning?n.emitWarning(e,t,r,i):console.error(`[${r}] ${t}: ${e}`)},o=globalThis.AbortController,s=globalThis.AbortSignal;if(typeof o>"u"){s=class{onabort;_onabort=[];reason;aborted=!1;addEventListener(e,t){this._onabort.push(t)}},o=class{constructor(){t()}signal=new s;abort(e){if(!this.signal.aborted){this.signal.reason=e,this.signal.aborted=!0;for(let t of this.signal._onabort)t(e);this.signal.onabort?.(e)}}};let e="1"!==n.env?.LRU_CACHE_IGNORE_AC_WARNING,t=()=>{e&&(e=!1,i("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",t))}}var a=e=>e&&e===Math.floor(e)&&e>0&&isFinite(e),c=e=>a(e)?e<=Math.pow(2,8)?Uint8Array:e<=Math.pow(2,16)?Uint16Array:e<=Math.pow(2,32)?Uint32Array:e<=Number.MAX_SAFE_INTEGER?h:null:null,h=class extends Array{constructor(e){super(e),this.fill(0)}},f=class e{heap;length;static#e=!1;static create(t){let r=c(t);if(!r)return[];e.#e=!0;let n=new e(t,r);return e.#e=!1,n}constructor(t,r){if(!e.#e)throw new TypeError("instantiate Stack using Stack.create(n)");this.heap=new r(t),this.length=0}push(e){this.heap[this.length++]=e}pop(){return this.heap[--this.length]}},p=class e{#e;#t;#r;#n;#i;#o;ttl;ttlResolution;ttlAutopurge;updateAgeOnGet;updateAgeOnHas;allowStale;noDisposeOnSet;noUpdateTTL;maxEntrySize;sizeCalculation;noDeleteOnFetchRejection;noDeleteOnStaleGet;allowStaleOnFetchAbort;allowStaleOnFetchRejection;ignoreFetchAbort;#s;#a;#l;#u;#c;#h;#f;#p;#d;#g;#y;#m;#b;#v;#w;#_;#E;static unsafeExposeInternals(e){return{starts:e.#b,ttls:e.#v,sizes:e.#m,keyMap:e.#l,keyList:e.#u,valList:e.#c,next:e.#h,prev:e.#f,get head(){return e.#p},get tail(){return e.#d},free:e.#g,isBackgroundFetch:t=>e.#S(t),backgroundFetch:(t,r,n,i)=>e.#I(t,r,n,i),moveToTail:t=>e.#A(t),indexes:t=>e.#R(t),rindexes:t=>e.#O(t),isStale:t=>e.#k(t)}}get max(){return this.#e}get maxSize(){return this.#t}get calculatedSize(){return this.#a}get size(){return this.#s}get fetchMethod(){return this.#i}get memoMethod(){return this.#o}get dispose(){return this.#r}get disposeAfter(){return this.#n}constructor(t){let{max:n=0,ttl:o,ttlResolution:s=1,ttlAutopurge:l,updateAgeOnGet:u,updateAgeOnHas:h,allowStale:p,dispose:d,disposeAfter:g,noDisposeOnSet:y,noUpdateTTL:m,maxSize:b=0,maxEntrySize:v=0,sizeCalculation:w,fetchMethod:_,memoMethod:E,noDeleteOnFetchRejection:S,noDeleteOnStaleGet:I,allowStaleOnFetchRejection:A,allowStaleOnFetchAbort:R,ignoreFetchAbort:O}=t;if(0!==n&&!a(n))throw new TypeError("max option must be a nonnegative integer");let k=n?c(n):Array;if(!k)throw new Error("invalid max value: "+n);if(this.#e=n,this.#t=b,this.maxEntrySize=v||this.#t,this.sizeCalculation=w,this.sizeCalculation){if(!this.#t&&!this.maxEntrySize)throw new TypeError("cannot set sizeCalculation without setting maxSize or maxEntrySize");if("function"!=typeof this.sizeCalculation)throw new TypeError("sizeCalculation set to non-function")}if(void 0!==E&&"function"!=typeof E)throw new TypeError("memoMethod must be a function if defined");if(this.#o=E,void 0!==_&&"function"!=typeof _)throw new TypeError("fetchMethod must be a function if specified");if(this.#i=_,this.#_=!!_,this.#l=new Map,this.#u=new Array(n).fill(void 0),this.#c=new Array(n).fill(void 0),this.#h=new k(n),this.#f=new k(n),this.#p=0,this.#d=0,this.#g=f.create(n),this.#s=0,this.#a=0,"function"==typeof d&&(this.#r=d),"function"==typeof g?(this.#n=g,this.#y=[]):(this.#n=void 0,this.#y=void 0),this.#w=!!this.#r,this.#E=!!this.#n,this.noDisposeOnSet=!!y,this.noUpdateTTL=!!m,this.noDeleteOnFetchRejection=!!S,this.allowStaleOnFetchRejection=!!A,this.allowStaleOnFetchAbort=!!R,this.ignoreFetchAbort=!!O,0!==this.maxEntrySize){if(0!==this.#t&&!a(this.#t))throw new TypeError("maxSize must be a positive integer if specified");if(!a(this.maxEntrySize))throw new TypeError("maxEntrySize must be a positive integer if specified");this.#x()}if(this.allowStale=!!p,this.noDeleteOnStaleGet=!!I,this.updateAgeOnGet=!!u,this.updateAgeOnHas=!!h,this.ttlResolution=a(s)||0===s?s:1,this.ttlAutopurge=!!l,this.ttl=o||0,this.ttl){if(!a(this.ttl))throw new TypeError("ttl must be a positive integer if specified");this.#T()}if(0===this.#e&&0===this.ttl&&0===this.#t)throw new TypeError("At least one of max, maxSize, or ttl is required");if(!this.ttlAutopurge&&!this.#e&&!this.#t){let t="LRU_CACHE_UNBOUNDED";(e=>!r.has(e))(t)&&(r.add(t),i("TTL caching without ttlAutopurge, max, or maxSize can result in unbounded memory consumption.","UnboundedCacheWarning",t,e))}}getRemainingTTL(e){return this.#l.has(e)?1/0:0}#T(){let e=new h(this.#e),r=new h(this.#e);this.#v=e,this.#b=r,this.#C=(n,i,o=t.now())=>{if(r[n]=0!==i?o:0,e[n]=i,0!==i&&this.ttlAutopurge){let e=setTimeout(()=>{this.#k(n)&&this.#P(this.#u[n],"expire")},i+1);e.unref&&e.unref()}},this.#N=n=>{r[n]=0!==e[n]?t.now():0},this.#L=(t,o)=>{if(e[o]){let s=e[o],a=r[o];if(!s||!a)return;t.ttl=s,t.start=a,t.now=n||i();let l=t.now-a;t.remainingTTL=s-l}};let n=0,i=()=>{let e=t.now();if(this.ttlResolution>0){n=e;let t=setTimeout(()=>n=0,this.ttlResolution);t.unref&&t.unref()}return e};this.getRemainingTTL=t=>{let o=this.#l.get(t);if(void 0===o)return 0;let s=e[o],a=r[o];return s&&a?s-((n||i())-a):1/0},this.#k=t=>{let o=r[t],s=e[t];return!!s&&!!o&&(n||i())-o>s}}#N=()=>{};#L=()=>{};#C=()=>{};#k=()=>!1;#x(){let e=new h(this.#e);this.#a=0,this.#m=e,this.#M=t=>{this.#a-=e[t],e[t]=0},this.#B=(e,t,r,n)=>{if(this.#S(t))return 0;if(!a(r)){if(!n)throw new TypeError("invalid size value (must be positive integer). When maxSize or maxEntrySize is used, sizeCalculation or size must be set.");if("function"!=typeof n)throw new TypeError("sizeCalculation must be a function");if(r=n(t,e),!a(r))throw new TypeError("sizeCalculation return invalid (expect positive integer)")}return r},this.#D=(t,r,n)=>{if(e[t]=r,this.#t){let r=this.#t-e[t];for(;this.#a>r;)this.#j(!0)}this.#a+=e[t],n&&(n.entrySize=r,n.totalCalculatedSize=this.#a)}}#M=e=>{};#D=(e,t,r)=>{};#B=(e,t,r,n)=>{if(r||n)throw new TypeError("cannot set size without setting maxSize or maxEntrySize on cache");return 0};*#R({allowStale:e=this.allowStale}={}){if(this.#s)for(let t=this.#d;this.#U(t)&&((e||!this.#k(t))&&(yield t),t!==this.#p);)t=this.#f[t]}*#O({allowStale:e=this.allowStale}={}){if(this.#s)for(let t=this.#p;this.#U(t)&&((e||!this.#k(t))&&(yield t),t!==this.#d);)t=this.#h[t]}#U(e){return void 0!==e&&this.#l.get(this.#u[e])===e}*entries(){for(let e of this.#R())void 0!==this.#c[e]&&void 0!==this.#u[e]&&!this.#S(this.#c[e])&&(yield[this.#u[e],this.#c[e]])}*rentries(){for(let e of this.#O())void 0!==this.#c[e]&&void 0!==this.#u[e]&&!this.#S(this.#c[e])&&(yield[this.#u[e],this.#c[e]])}*keys(){for(let e of this.#R()){let t=this.#u[e];void 0!==t&&!this.#S(this.#c[e])&&(yield t)}}*rkeys(){for(let e of this.#O()){let t=this.#u[e];void 0!==t&&!this.#S(this.#c[e])&&(yield t)}}*values(){for(let e of this.#R())void 0!==this.#c[e]&&!this.#S(this.#c[e])&&(yield this.#c[e])}*rvalues(){for(let e of this.#O())void 0!==this.#c[e]&&!this.#S(this.#c[e])&&(yield this.#c[e])}[Symbol.iterator](){return this.entries()}[Symbol.toStringTag]="LRUCache";find(e,t={}){for(let r of this.#R()){let n=this.#c[r],i=this.#S(n)?n.__staleWhileFetching:n;if(void 0!==i&&e(i,this.#u[r],this))return this.get(this.#u[r],t)}}forEach(e,t=this){for(let r of this.#R()){let n=this.#c[r],i=this.#S(n)?n.__staleWhileFetching:n;void 0!==i&&e.call(t,i,this.#u[r],this)}}rforEach(e,t=this){for(let r of this.#O()){let n=this.#c[r],i=this.#S(n)?n.__staleWhileFetching:n;void 0!==i&&e.call(t,i,this.#u[r],this)}}purgeStale(){let e=!1;for(let t of this.#O({allowStale:!0}))this.#k(t)&&(this.#P(this.#u[t],"expire"),e=!0);return e}info(e){let r=this.#l.get(e);if(void 0===r)return;let n=this.#c[r],i=this.#S(n)?n.__staleWhileFetching:n;if(void 0===i)return;let o={value:i};if(this.#v&&this.#b){let e=this.#v[r],n=this.#b[r];if(e&&n){let r=e-(t.now()-n);o.ttl=r,o.start=Date.now()}}return this.#m&&(o.size=this.#m[r]),o}dump(){let e=[];for(let r of this.#R({allowStale:!0})){let n=this.#u[r],i=this.#c[r],o=this.#S(i)?i.__staleWhileFetching:i;if(void 0===o||void 0===n)continue;let s={value:o};if(this.#v&&this.#b){s.ttl=this.#v[r];let e=t.now()-this.#b[r];s.start=Math.floor(Date.now()-e)}this.#m&&(s.size=this.#m[r]),e.unshift([n,s])}return e}load(e){this.clear();for(let[r,n]of e){if(n.start){let e=Date.now()-n.start;n.start=t.now()-e}this.set(r,n.value,n)}}set(e,t,r={}){if(void 0===t)return this.delete(e),this;let{ttl:n=this.ttl,start:i,noDisposeOnSet:o=this.noDisposeOnSet,sizeCalculation:s=this.sizeCalculation,status:a}=r,{noUpdateTTL:l=this.noUpdateTTL}=r,u=this.#B(e,t,r.size||0,s);if(this.maxEntrySize&&u>this.maxEntrySize)return a&&(a.set="miss",a.maxEntrySizeExceeded=!0),this.#P(e,"set"),this;let c=0===this.#s?void 0:this.#l.get(e);if(void 0===c)c=0===this.#s?this.#d:0!==this.#g.length?this.#g.pop():this.#s===this.#e?this.#j(!1):this.#s,this.#u[c]=e,this.#c[c]=t,this.#l.set(e,c),this.#h[this.#d]=c,this.#f[c]=this.#d,this.#d=c,this.#s++,this.#D(c,u,a),a&&(a.set="add"),l=!1;else{this.#A(c);let r=this.#c[c];if(t!==r){if(this.#_&&this.#S(r)){r.__abortController.abort(new Error("replaced"));let{__staleWhileFetching:t}=r;void 0!==t&&!o&&(this.#w&&this.#r?.(t,e,"set"),this.#E&&this.#y?.push([t,e,"set"]))}else o||(this.#w&&this.#r?.(r,e,"set"),this.#E&&this.#y?.push([r,e,"set"]));if(this.#M(c),this.#D(c,u,a),this.#c[c]=t,a){a.set="replace";let e=r&&this.#S(r)?r.__staleWhileFetching:r;void 0!==e&&(a.oldValue=e)}}else a&&(a.set="update")}if(0!==n&&!this.#v&&this.#T(),this.#v&&(l||this.#C(c,n,i),a&&this.#L(a,c)),!o&&this.#E&&this.#y){let e,t=this.#y;for(;e=t?.shift();)this.#n?.(...e)}return this}pop(){try{for(;this.#s;){let e=this.#c[this.#p];if(this.#j(!0),this.#S(e)){if(e.__staleWhileFetching)return e.__staleWhileFetching}else if(void 0!==e)return e}}finally{if(this.#E&&this.#y){let e,t=this.#y;for(;e=t?.shift();)this.#n?.(...e)}}}#j(e){let t=this.#p,r=this.#u[t],n=this.#c[t];return this.#_&&this.#S(n)?n.__abortController.abort(new Error("evicted")):(this.#w||this.#E)&&(this.#w&&this.#r?.(n,r,"evict"),this.#E&&this.#y?.push([n,r,"evict"])),this.#M(t),e&&(this.#u[t]=void 0,this.#c[t]=void 0,this.#g.push(t)),1===this.#s?(this.#p=this.#d=0,this.#g.length=0):this.#p=this.#h[t],this.#l.delete(r),this.#s--,t}has(e,t={}){let{updateAgeOnHas:r=this.updateAgeOnHas,status:n}=t,i=this.#l.get(e);if(void 0!==i){let e=this.#c[i];if(this.#S(e)&&void 0===e.__staleWhileFetching)return!1;if(!this.#k(i))return r&&this.#N(i),n&&(n.has="hit",this.#L(n,i)),!0;n&&(n.has="stale",this.#L(n,i))}else n&&(n.has="miss");return!1}peek(e,t={}){let{allowStale:r=this.allowStale}=t,n=this.#l.get(e);if(void 0===n||!r&&this.#k(n))return;let i=this.#c[n];return this.#S(i)?i.__staleWhileFetching:i}#I(e,t,r,n){let i=void 0===t?void 0:this.#c[t];if(this.#S(i))return i;let s=new o,{signal:a}=r;a?.addEventListener("abort",()=>s.abort(a.reason),{signal:s.signal});let l={signal:s.signal,options:r,context:n},u=(n,i=!1)=>{let{aborted:o}=s.signal,a=r.ignoreFetchAbort&&void 0!==n;if(r.status&&(o&&!i?(r.status.fetchAborted=!0,r.status.fetchError=s.signal.reason,a&&(r.status.fetchAbortIgnored=!0)):r.status.fetchResolved=!0),o&&!a&&!i)return c(s.signal.reason);let u=h;return this.#c[t]===h&&(void 0===n?u.__staleWhileFetching?this.#c[t]=u.__staleWhileFetching:this.#P(e,"fetch"):(r.status&&(r.status.fetchUpdated=!0),this.set(e,n,l.options))),n},c=n=>{let{aborted:i}=s.signal,o=i&&r.allowStaleOnFetchAbort,a=o||r.allowStaleOnFetchRejection,l=a||r.noDeleteOnFetchRejection,u=h;if(this.#c[t]===h&&(l&&void 0!==u.__staleWhileFetching?o||(this.#c[t]=u.__staleWhileFetching):this.#P(e,"fetch")),a)return r.status&&void 0!==u.__staleWhileFetching&&(r.status.returnedStale=!0),u.__staleWhileFetching;if(u.__returned===u)throw n};r.status&&(r.status.fetchDispatched=!0);let h=new Promise((t,n)=>{let o=this.#i?.(e,i,l);o&&o instanceof Promise&&o.then(e=>t(void 0===e?void 0:e),n),s.signal.addEventListener("abort",()=>{(!r.ignoreFetchAbort||r.allowStaleOnFetchAbort)&&(t(void 0),r.allowStaleOnFetchAbort&&(t=e=>u(e,!0)))})}).then(u,e=>(r.status&&(r.status.fetchRejected=!0,r.status.fetchError=e),c(e))),f=Object.assign(h,{__abortController:s,__staleWhileFetching:i,__returned:void 0});return void 0===t?(this.set(e,f,{...l.options,status:void 0}),t=this.#l.get(e)):this.#c[t]=f,f}#S(e){if(!this.#_)return!1;let t=e;return!!t&&t instanceof Promise&&t.hasOwnProperty("__staleWhileFetching")&&t.__abortController instanceof o}async fetch(e,t={}){let{allowStale:r=this.allowStale,updateAgeOnGet:n=this.updateAgeOnGet,noDeleteOnStaleGet:i=this.noDeleteOnStaleGet,ttl:o=this.ttl,noDisposeOnSet:s=this.noDisposeOnSet,size:a=0,sizeCalculation:l=this.sizeCalculation,noUpdateTTL:u=this.noUpdateTTL,noDeleteOnFetchRejection:c=this.noDeleteOnFetchRejection,allowStaleOnFetchRejection:h=this.allowStaleOnFetchRejection,ignoreFetchAbort:f=this.ignoreFetchAbort,allowStaleOnFetchAbort:p=this.allowStaleOnFetchAbort,context:d,forceRefresh:g=!1,status:y,signal:m}=t;if(!this.#_)return y&&(y.fetch="get"),this.get(e,{allowStale:r,updateAgeOnGet:n,noDeleteOnStaleGet:i,status:y});let b={allowStale:r,updateAgeOnGet:n,noDeleteOnStaleGet:i,ttl:o,noDisposeOnSet:s,size:a,sizeCalculation:l,noUpdateTTL:u,noDeleteOnFetchRejection:c,allowStaleOnFetchRejection:h,allowStaleOnFetchAbort:p,ignoreFetchAbort:f,status:y,signal:m},v=this.#l.get(e);if(void 0===v){y&&(y.fetch="miss");let t=this.#I(e,v,b,d);return t.__returned=t}{let t=this.#c[v];if(this.#S(t)){let e=r&&void 0!==t.__staleWhileFetching;return y&&(y.fetch="inflight",e&&(y.returnedStale=!0)),e?t.__staleWhileFetching:t.__returned=t}let i=this.#k(v);if(!g&&!i)return y&&(y.fetch="hit"),this.#A(v),n&&this.#N(v),y&&this.#L(y,v),t;let o=this.#I(e,v,b,d),s=void 0!==o.__staleWhileFetching&&r;return y&&(y.fetch=i?"stale":"refresh",s&&i&&(y.returnedStale=!0)),s?o.__staleWhileFetching:o.__returned=o}}async forceFetch(e,t={}){let r=await this.fetch(e,t);if(void 0===r)throw new Error("fetch() returned undefined");return r}memo(e,t={}){let r=this.#o;if(!r)throw new Error("no memoMethod provided to constructor");let{context:n,forceRefresh:i,...o}=t,s=this.get(e,o);if(!i&&void 0!==s)return s;let a=r(e,s,{options:o,context:n});return this.set(e,a,o),a}get(e,t={}){let{allowStale:r=this.allowStale,updateAgeOnGet:n=this.updateAgeOnGet,noDeleteOnStaleGet:i=this.noDeleteOnStaleGet,status:o}=t,s=this.#l.get(e);if(void 0!==s){let t=this.#c[s],a=this.#S(t);return o&&this.#L(o,s),this.#k(s)?(o&&(o.get="stale"),a?(o&&r&&void 0!==t.__staleWhileFetching&&(o.returnedStale=!0),r?t.__staleWhileFetching:void 0):(i||this.#P(e,"expire"),o&&r&&(o.returnedStale=!0),r?t:void 0)):(o&&(o.get="hit"),a?t.__staleWhileFetching:(this.#A(s),n&&this.#N(s),t))}o&&(o.get="miss")}#F(e,t){this.#f[t]=e,this.#h[e]=t}#A(e){e!==this.#d&&(e===this.#p?this.#p=this.#h[e]:this.#F(this.#f[e],this.#h[e]),this.#F(this.#d,e),this.#d=e)}delete(e){return this.#P(e,"delete")}#P(e,t){let r=!1;if(0!==this.#s){let n=this.#l.get(e);if(void 0!==n)if(r=!0,1===this.#s)this.#W(t);else{this.#M(n);let r=this.#c[n];if(this.#S(r)?r.__abortController.abort(new Error("deleted")):(this.#w||this.#E)&&(this.#w&&this.#r?.(r,e,t),this.#E&&this.#y?.push([r,e,t])),this.#l.delete(e),this.#u[n]=void 0,this.#c[n]=void 0,n===this.#d)this.#d=this.#f[n];else if(n===this.#p)this.#p=this.#h[n];else{let e=this.#f[n];this.#h[e]=this.#h[n];let t=this.#h[n];this.#f[t]=this.#f[n]}this.#s--,this.#g.push(n)}}if(this.#E&&this.#y?.length){let e,t=this.#y;for(;e=t?.shift();)this.#n?.(...e)}return r}clear(){return this.#W("delete")}#W(e){for(let t of this.#O({allowStale:!0})){let r=this.#c[t];if(this.#S(r))r.__abortController.abort(new Error("deleted"));else{let n=this.#u[t];this.#w&&this.#r?.(r,n,e),this.#E&&this.#y?.push([r,n,e])}}if(this.#l.clear(),this.#c.fill(void 0),this.#u.fill(void 0),this.#v&&this.#b&&(this.#v.fill(0),this.#b.fill(0)),this.#m&&this.#m.fill(0),this.#p=0,this.#d=0,this.#g.length=0,this.#a=0,this.#s=0,this.#E&&this.#y){let e,t=this.#y;for(;e=t?.shift();)this.#n?.(...e)}}};e.LRUCache=p}),pr=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"t",{value:!0}),e.ContainerIterator=e.Container=e.Base=void 0;e.ContainerIterator=class{constructor(e=0){this.iteratorType=e}equals(e){return this.o===e.o}};var t=class{constructor(){this.i=0}get length(){return this.i}size(){return this.i}empty(){return 0===this.i}};e.Base=t;e.Container=class extends t{}}),dr=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"t",{value:!0}),e.default=void 0;var t=pr(),r=class extends t.Base{constructor(e=[]){super(),this.S=[];let t=this;e.forEach(function(e){t.push(e)})}clear(){this.i=0,this.S=[]}push(e){return this.S.push(e),this.i+=1,this.i}pop(){if(0!==this.i)return this.i-=1,this.S.pop()}top(){return this.S[this.i-1]}};e.default=r}),gr=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"t",{value:!0}),e.default=void 0;var t=pr(),r=class extends t.Base{constructor(e=[]){super(),this.j=0,this.q=[];let t=this;e.forEach(function(e){t.push(e)})}clear(){this.q=[],this.i=this.j=0}push(e){let t=this.q.length;if(this.j/t>.5&&this.j+this.i>=t&&t>4096){let t=this.i;for(let e=0;e<t;++e)this.q[e]=this.q[this.j+e];this.j=0,this.q[this.i]=e}else this.q[this.j+this.i]=e;return++this.i}pop(){if(0===this.i)return;let e=this.q[this.j++];return this.i-=1,e}front(){if(0!==this.i)return this.q[this.j]}};e.default=r}),yr=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"t",{value:!0}),e.default=void 0;var t=pr(),r=class extends t.Base{constructor(e=[],t=function(e,t){return e>t?-1:e<t?1:0},r=!0){if(super(),this.v=t,Array.isArray(e))this.C=r?[...e]:e;else{this.C=[];let t=this;e.forEach(function(e){t.C.push(e)})}this.i=this.C.length;let n=this.i>>1;for(let e=this.i-1>>1;e>=0;--e)this.k(e,n)}m(e){let t=this.C[e];for(;e>0;){let r=e-1>>1,n=this.C[r];if(this.v(n,t)<=0)break;this.C[e]=n,e=r}this.C[e]=t}k(e,t){let r=this.C[e];for(;e<t;){let t=e<<1|1,n=t+1,i=this.C[t];if(n<this.i&&this.v(i,this.C[n])>0&&(t=n,i=this.C[n]),this.v(i,r)>=0)break;this.C[e]=i,e=t}this.C[e]=r}clear(){this.i=0,this.C.length=0}push(e){this.C.push(e),this.m(this.i),this.i+=1}pop(){if(0===this.i)return;let e=this.C[0],t=this.C.pop();return this.i-=1,this.i&&(this.C[0]=t,this.k(0,this.i>>1)),e}top(){return this.C[0]}find(e){return this.C.indexOf(e)>=0}remove(e){let t=this.C.indexOf(e);return!(t<0)&&(0===t?this.pop():t===this.i-1?(this.C.pop(),this.i-=1):(this.C.splice(t,1,this.C.pop()),this.i-=1,this.m(t),this.k(t,this.i>>1)),!0)}updateItem(e){let t=this.C.indexOf(e);return!(t<0)&&(this.m(t),this.k(t,this.i>>1),!0)}toArray(){return[...this.C]}};e.default=r}),mr=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"t",{value:!0}),e.default=void 0;var t=pr(),r=class extends t.Container{};e.default=r}),br=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"t",{value:!0}),e.throwIteratorAccessError=function(){throw new RangeError("Iterator access denied!")}}),vr=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"t",{value:!0}),e.RandomIterator=void 0;var t=pr(),r=br(),n=class extends t.ContainerIterator{constructor(e,t){super(t),this.o=e,0===this.iteratorType?(this.pre=function(){return 0===this.o&&(0,r.throwIteratorAccessError)(),this.o-=1,this},this.next=function(){return this.o===this.container.size()&&(0,r.throwIteratorAccessError)(),this.o+=1,this}):(this.pre=function(){return this.o===this.container.size()-1&&(0,r.throwIteratorAccessError)(),this.o+=1,this},this.next=function(){return-1===this.o&&(0,r.throwIteratorAccessError)(),this.o-=1,this})}get pointer(){return this.container.getElementByPos(this.o)}set pointer(e){this.container.setElementByPos(this.o,e)}};e.RandomIterator=n}),wr=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"t",{value:!0}),e.default=void 0;var t,r=(t=mr())&&t.t?t:{default:t},n=vr();var i=class e extends n.RandomIterator{constructor(e,t,r){super(e,r),this.container=t}copy(){return new e(this.o,this.container,this.iteratorType)}},o=class extends r.default{constructor(e=[],t=!0){if(super(),Array.isArray(e))this.J=t?[...e]:e,this.i=e.length;else{this.J=[];let t=this;e.forEach(function(e){t.pushBack(e)})}}clear(){this.i=0,this.J.length=0}begin(){return new i(0,this)}end(){return new i(this.i,this)}rBegin(){return new i(this.i-1,this,1)}rEnd(){return new i(-1,this,1)}front(){return this.J[0]}back(){return this.J[this.i-1]}getElementByPos(e){if(e<0||e>this.i-1)throw new RangeError;return this.J[e]}eraseElementByPos(e){if(e<0||e>this.i-1)throw new RangeError;return this.J.splice(e,1),this.i-=1,this.i}eraseElementByValue(e){let t=0;for(let r=0;r<this.i;++r)this.J[r]!==e&&(this.J[t++]=this.J[r]);return this.i=this.J.length=t,this.i}eraseElementByIterator(e){let t=e.o;return e=e.next(),this.eraseElementByPos(t),e}pushBack(e){return this.J.push(e),this.i+=1,this.i}popBack(){if(0!==this.i)return this.i-=1,this.J.pop()}setElementByPos(e,t){if(e<0||e>this.i-1)throw new RangeError;this.J[e]=t}insert(e,t,r=1){if(e<0||e>this.i)throw new RangeError;return this.J.splice(e,0,...new Array(r).fill(t)),this.i+=r,this.i}find(e){for(let t=0;t<this.i;++t)if(this.J[t]===e)return new i(t,this);return this.end()}reverse(){this.J.reverse()}unique(){let e=1;for(let t=1;t<this.i;++t)this.J[t]!==this.J[t-1]&&(this.J[e++]=this.J[t]);return this.i=this.J.length=e,this.i}sort(e){this.J.sort(e)}forEach(e){for(let t=0;t<this.i;++t)e(this.J[t],t,this)}[Symbol.iterator](){return function*(){yield*this.J}.bind(this)()}};e.default=o}),_r=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"t",{value:!0}),e.default=void 0;var t,r=(t=mr())&&t.t?t:{default:t},n=pr(),i=br();var o=class e extends n.ContainerIterator{constructor(e,t,r,n){super(n),this.o=e,this.h=t,this.container=r,0===this.iteratorType?(this.pre=function(){return this.o.L===this.h&&(0,i.throwIteratorAccessError)(),this.o=this.o.L,this},this.next=function(){return this.o===this.h&&(0,i.throwIteratorAccessError)(),this.o=this.o.B,this}):(this.pre=function(){return this.o.B===this.h&&(0,i.throwIteratorAccessError)(),this.o=this.o.B,this},this.next=function(){return this.o===this.h&&(0,i.throwIteratorAccessError)(),this.o=this.o.L,this})}get pointer(){return this.o===this.h&&(0,i.throwIteratorAccessError)(),this.o.l}set pointer(e){this.o===this.h&&(0,i.throwIteratorAccessError)(),this.o.l=e}copy(){return new e(this.o,this.h,this.container,this.iteratorType)}},s=class extends r.default{constructor(e=[]){super(),this.h={},this.p=this._=this.h.L=this.h.B=this.h;let t=this;e.forEach(function(e){t.pushBack(e)})}V(e){let{L:t,B:r}=e;t.B=r,r.L=t,e===this.p&&(this.p=r),e===this._&&(this._=t),this.i-=1}G(e,t){let r=t.B,n={l:e,L:t,B:r};t.B=n,r.L=n,t===this.h&&(this.p=n),r===this.h&&(this._=n),this.i+=1}clear(){this.i=0,this.p=this._=this.h.L=this.h.B=this.h}begin(){return new o(this.p,this.h,this)}end(){return new o(this.h,this.h,this)}rBegin(){return new o(this._,this.h,this,1)}rEnd(){return new o(this.h,this.h,this,1)}front(){return this.p.l}back(){return this._.l}getElementByPos(e){if(e<0||e>this.i-1)throw new RangeError;let t=this.p;for(;e--;)t=t.B;return t.l}eraseElementByPos(e){if(e<0||e>this.i-1)throw new RangeError;let t=this.p;for(;e--;)t=t.B;return this.V(t),this.i}eraseElementByValue(e){let t=this.p;for(;t!==this.h;)t.l===e&&this.V(t),t=t.B;return this.i}eraseElementByIterator(e){let t=e.o;return t===this.h&&(0,i.throwIteratorAccessError)(),e=e.next(),this.V(t),e}pushBack(e){return this.G(e,this._),this.i}popBack(){if(0===this.i)return;let e=this._.l;return this.V(this._),e}pushFront(e){return this.G(e,this.h),this.i}popFront(){if(0===this.i)return;let e=this.p.l;return this.V(this.p),e}setElementByPos(e,t){if(e<0||e>this.i-1)throw new RangeError;let r=this.p;for(;e--;)r=r.B;r.l=t}insert(e,t,r=1){if(e<0||e>this.i)throw new RangeError;if(r<=0)return this.i;if(0===e)for(;r--;)this.pushFront(t);else if(e===this.i)for(;r--;)this.pushBack(t);else{let n=this.p;for(let t=1;t<e;++t)n=n.B;let i=n.B;for(this.i+=r;r--;)n.B={l:t,L:n},n.B.L=n,n=n.B;n.B=i,i.L=n}return this.i}find(e){let t=this.p;for(;t!==this.h;){if(t.l===e)return new o(t,this.h,this);t=t.B}return this.end()}reverse(){if(this.i<=1)return;let e=this.p,t=this._,r=0;for(;r<<1<this.i;){let n=e.l;e.l=t.l,t.l=n,e=e.B,t=t.L,r+=1}}unique(){if(this.i<=1)return this.i;let e=this.p;for(;e!==this.h;){let t=e;for(;t.B!==this.h&&t.l===t.B.l;)t=t.B,this.i-=1;e.B=t.B,e.B.L=e,e=e.B}return this.i}sort(e){if(this.i<=1)return;let t=[];this.forEach(function(e){t.push(e)}),t.sort(e);let r=this.p;t.forEach(function(e){r.l=e,r=r.B})}merge(e){let t=this;if(0===this.i)e.forEach(function(e){t.pushBack(e)});else{let r=this.p;e.forEach(function(e){for(;r!==t.h&&r.l<=e;)r=r.B;t.G(e,r.L)})}return this.i}forEach(e){let t=this.p,r=0;for(;t!==this.h;)e(t.l,r++,this),t=t.B}[Symbol.iterator](){return function*(){if(0===this.i)return;let e=this.p;for(;e!==this.h;)yield e.l,e=e.B}.bind(this)()}};e.default=s}),Er=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"t",{value:!0}),e.default=void 0;var t,r=(t=mr())&&t.t?t:{default:t},n=vr();var i=class e extends n.RandomIterator{constructor(e,t,r){super(e,r),this.container=t}copy(){return new e(this.o,this.container,this.iteratorType)}},o=class extends r.default{constructor(e=[],t=4096){super(),this.j=0,this.D=0,this.R=0,this.N=0,this.P=0,this.A=[];let r=(()=>{if("number"==typeof e.length)return e.length;if("number"==typeof e.size)return e.size;if("function"==typeof e.size)return e.size();throw new TypeError("Cannot get the length or size of the container")})();this.F=t,this.P=Math.max(Math.ceil(r/this.F),1);for(let e=0;e<this.P;++e)this.A.push(new Array(this.F));let n=Math.ceil(r/this.F);this.j=this.R=(this.P>>1)-(n>>1),this.D=this.N=this.F-r%this.F>>1;let i=this;e.forEach(function(e){i.pushBack(e)})}T(){let e=[],t=Math.max(this.P>>1,1);for(let r=0;r<t;++r)e[r]=new Array(this.F);for(let t=this.j;t<this.P;++t)e[e.length]=this.A[t];for(let t=0;t<this.R;++t)e[e.length]=this.A[t];e[e.length]=[...this.A[this.R]],this.j=t,this.R=e.length-1;for(let r=0;r<t;++r)e[e.length]=new Array(this.F);this.A=e,this.P=e.length}O(e){let t=this.D+e+1,r=t%this.F,n=r-1,i=this.j+(t-r)/this.F;return 0===r&&(i-=1),i%=this.P,n<0&&(n+=this.F),{curNodeBucketIndex:i,curNodePointerIndex:n}}clear(){this.A=[new Array(this.F)],this.P=1,this.j=this.R=this.i=0,this.D=this.N=this.F>>1}begin(){return new i(0,this)}end(){return new i(this.i,this)}rBegin(){return new i(this.i-1,this,1)}rEnd(){return new i(-1,this,1)}front(){if(0!==this.i)return this.A[this.j][this.D]}back(){if(0!==this.i)return this.A[this.R][this.N]}pushBack(e){return this.i&&(this.N<this.F-1?this.N+=1:this.R<this.P-1?(this.R+=1,this.N=0):(this.R=0,this.N=0),this.R===this.j&&this.N===this.D&&this.T()),this.i+=1,this.A[this.R][this.N]=e,this.i}popBack(){if(0===this.i)return;let e=this.A[this.R][this.N];return 1!==this.i&&(this.N>0?this.N-=1:this.R>0?(this.R-=1,this.N=this.F-1):(this.R=this.P-1,this.N=this.F-1)),this.i-=1,e}pushFront(e){return this.i&&(this.D>0?this.D-=1:this.j>0?(this.j-=1,this.D=this.F-1):(this.j=this.P-1,this.D=this.F-1),this.j===this.R&&this.D===this.N&&this.T()),this.i+=1,this.A[this.j][this.D]=e,this.i}popFront(){if(0===this.i)return;let e=this.A[this.j][this.D];return 1!==this.i&&(this.D<this.F-1?this.D+=1:this.j<this.P-1?(this.j+=1,this.D=0):(this.j=0,this.D=0)),this.i-=1,e}getElementByPos(e){if(e<0||e>this.i-1)throw new RangeError;let{curNodeBucketIndex:t,curNodePointerIndex:r}=this.O(e);return this.A[t][r]}setElementByPos(e,t){if(e<0||e>this.i-1)throw new RangeError;let{curNodeBucketIndex:r,curNodePointerIndex:n}=this.O(e);this.A[r][n]=t}insert(e,t,r=1){if(e<0||e>this.i)throw new RangeError;if(0===e)for(;r--;)this.pushFront(t);else if(e===this.i)for(;r--;)this.pushBack(t);else{let n=[];for(let t=e;t<this.i;++t)n.push(this.getElementByPos(t));this.cut(e-1);for(let e=0;e<r;++e)this.pushBack(t);for(let e=0;e<n.length;++e)this.pushBack(n[e])}return this.i}cut(e){if(e<0)return this.clear(),0;let{curNodeBucketIndex:t,curNodePointerIndex:r}=this.O(e);return this.R=t,this.N=r,this.i=e+1,this.i}eraseElementByPos(e){if(e<0||e>this.i-1)throw new RangeError;if(0===e)this.popFront();else if(e===this.i-1)this.popBack();else{let t=[];for(let r=e+1;r<this.i;++r)t.push(this.getElementByPos(r));this.cut(e),this.popBack();let r=this;t.forEach(function(e){r.pushBack(e)})}return this.i}eraseElementByValue(e){if(0===this.i)return 0;let t=[];for(let r=0;r<this.i;++r){let n=this.getElementByPos(r);n!==e&&t.push(n)}let r=t.length;for(let e=0;e<r;++e)this.setElementByPos(e,t[e]);return this.cut(r-1)}eraseElementByIterator(e){let t=e.o;return this.eraseElementByPos(t),e=e.next()}find(e){for(let t=0;t<this.i;++t)if(this.getElementByPos(t)===e)return new i(t,this);return this.end()}reverse(){let e=0,t=this.i-1;for(;e<t;){let r=this.getElementByPos(e);this.setElementByPos(e,this.getElementByPos(t)),this.setElementByPos(t,r),e+=1,t-=1}}unique(){if(this.i<=1)return this.i;let e=1,t=this.getElementByPos(0);for(let r=1;r<this.i;++r){let n=this.getElementByPos(r);n!==t&&(t=n,this.setElementByPos(e++,n))}for(;this.i>e;)this.popBack();return this.i}sort(e){let t=[];for(let e=0;e<this.i;++e)t.push(this.getElementByPos(e));t.sort(e);for(let e=0;e<this.i;++e)this.setElementByPos(e,t[e])}shrinkToFit(){if(0===this.i)return;let e=[];this.forEach(function(t){e.push(t)}),this.P=Math.max(Math.ceil(this.i/this.F),1),this.i=this.j=this.R=this.D=this.N=0,this.A=[];for(let e=0;e<this.P;++e)this.A.push(new Array(this.F));for(let t=0;t<e.length;++t)this.pushBack(e[t])}forEach(e){for(let t=0;t<this.i;++t)e(this.getElementByPos(t),t,this)}[Symbol.iterator](){return function*(){for(let e=0;e<this.i;++e)yield this.getElementByPos(e)}.bind(this)()}};e.default=o}),Sr=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"t",{value:!0}),e.TreeNodeEnableIndex=e.TreeNode=void 0;var t=class{constructor(e,t){this.ee=1,this.u=void 0,this.l=void 0,this.U=void 0,this.W=void 0,this.tt=void 0,this.u=e,this.l=t}L(){let e=this;if(1===e.ee&&e.tt.tt===e)e=e.W;else if(e.U)for(e=e.U;e.W;)e=e.W;else{let t=e.tt;for(;t.U===e;)e=t,t=e.tt;e=t}return e}B(){let e=this;if(e.W){for(e=e.W;e.U;)e=e.U;return e}{let t=e.tt;for(;t.W===e;)e=t,t=e.tt;return e.W!==t?t:e}}te(){let e=this.tt,t=this.W,r=t.U;return e.tt===this?e.tt=t:e.U===this?e.U=t:e.W=t,t.tt=e,t.U=this,this.tt=t,this.W=r,r&&(r.tt=this),t}se(){let e=this.tt,t=this.U,r=t.W;return e.tt===this?e.tt=t:e.U===this?e.U=t:e.W=t,t.tt=e,t.W=this,this.tt=t,this.U=r,r&&(r.tt=this),t}};e.TreeNode=t;e.TreeNodeEnableIndex=class extends t{constructor(){super(...arguments),this.rt=1}te(){let e=super.te();return this.ie(),e.ie(),e}se(){let e=super.se();return this.ie(),e.ie(),e}ie(){this.rt=1,this.U&&(this.rt+=this.U.rt),this.W&&(this.rt+=this.W.rt)}}}),Ir=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"t",{value:!0}),e.default=void 0;var t=Sr(),r=pr(),n=br(),i=class extends r.Container{constructor(e=function(e,t){return e<t?-1:e>t?1:0},r=!1){super(),this.Y=void 0,this.v=e,r?(this.re=t.TreeNodeEnableIndex,this.M=function(e,t,r){let n=this.ne(e,t,r);if(n){let e=n.tt;for(;e!==this.h;)e.rt+=1,e=e.tt;let t=this.he(n);if(t){let{parentNode:e,grandParent:r,curNode:n}=t;e.ie(),r.ie(),n.ie()}}return this.i},this.V=function(e){let t=this.fe(e);for(;t!==this.h;)t.rt-=1,t=t.tt}):(this.re=t.TreeNode,this.M=function(e,t,r){let n=this.ne(e,t,r);return n&&this.he(n),this.i},this.V=this.fe),this.h=new this.re}X(e,t){let r=this.h;for(;e;){let n=this.v(e.u,t);if(n<0)e=e.W;else{if(!(n>0))return e;r=e,e=e.U}}return r}Z(e,t){let r=this.h;for(;e;)this.v(e.u,t)<=0?e=e.W:(r=e,e=e.U);return r}$(e,t){let r=this.h;for(;e;){let n=this.v(e.u,t);if(n<0)r=e,e=e.W;else{if(!(n>0))return e;e=e.U}}return r}rr(e,t){let r=this.h;for(;e;)this.v(e.u,t)<0?(r=e,e=e.W):e=e.U;return r}ue(e){for(;;){let t=e.tt;if(t===this.h)return;if(1===e.ee)return void(e.ee=0);if(e===t.U){let r=t.W;if(1===r.ee)r.ee=0,t.ee=1,t===this.Y?this.Y=t.te():t.te();else{if(r.W&&1===r.W.ee)return r.ee=t.ee,t.ee=0,r.W.ee=0,void(t===this.Y?this.Y=t.te():t.te());r.U&&1===r.U.ee?(r.ee=1,r.U.ee=0,r.se()):(r.ee=1,e=t)}}else{let r=t.U;if(1===r.ee)r.ee=0,t.ee=1,t===this.Y?this.Y=t.se():t.se();else{if(r.U&&1===r.U.ee)return r.ee=t.ee,t.ee=0,r.U.ee=0,void(t===this.Y?this.Y=t.se():t.se());r.W&&1===r.W.ee?(r.ee=1,r.W.ee=0,r.te()):(r.ee=1,e=t)}}}}fe(e){if(1===this.i)return this.clear(),this.h;let t=e;for(;t.U||t.W;){if(t.W)for(t=t.W;t.U;)t=t.U;else t=t.U;[e.u,t.u]=[t.u,e.u],[e.l,t.l]=[t.l,e.l],e=t}this.h.U===t?this.h.U=t.tt:this.h.W===t&&(this.h.W=t.tt),this.ue(t);let r=t.tt;return t===r.U?r.U=void 0:r.W=void 0,this.i-=1,this.Y.ee=0,r}oe(e,t){return void 0!==e&&(!(!this.oe(e.U,t)&&!t(e))||this.oe(e.W,t))}he(e){for(;;){let t=e.tt;if(0===t.ee)return;let r=t.tt;if(t===r.U){let n=r.W;if(n&&1===n.ee){if(n.ee=t.ee=0,r===this.Y)return;r.ee=1,e=r;continue}if(e===t.W){if(e.ee=0,e.U&&(e.U.tt=t),e.W&&(e.W.tt=r),t.W=e.U,r.U=e.W,e.U=t,e.W=r,r===this.Y)this.Y=e,this.h.tt=e;else{let t=r.tt;t.U===r?t.U=e:t.W=e}return e.tt=r.tt,t.tt=e,r.tt=e,r.ee=1,{parentNode:t,grandParent:r,curNode:e}}t.ee=0,r===this.Y?this.Y=r.se():r.se(),r.ee=1}else{let n=r.U;if(n&&1===n.ee){if(n.ee=t.ee=0,r===this.Y)return;r.ee=1,e=r;continue}if(e===t.U){if(e.ee=0,e.U&&(e.U.tt=r),e.W&&(e.W.tt=t),r.W=e.U,t.U=e.W,e.U=r,e.W=t,r===this.Y)this.Y=e,this.h.tt=e;else{let t=r.tt;t.U===r?t.U=e:t.W=e}return e.tt=r.tt,t.tt=e,r.tt=e,r.ee=1,{parentNode:t,grandParent:r,curNode:e}}t.ee=0,r===this.Y?this.Y=r.te():r.te(),r.ee=1}return}}ne(e,t,r){if(void 0===this.Y)return this.i+=1,this.Y=new this.re(e,t),this.Y.ee=0,this.Y.tt=this.h,this.h.tt=this.Y,this.h.U=this.Y,void(this.h.W=this.Y);let n,i=this.h.U,o=this.v(i.u,e);if(0!==o){if(o>0)i.U=new this.re(e,t),i.U.tt=i,n=i.U,this.h.U=n;else{let i=this.h.W,o=this.v(i.u,e);if(0===o)return void(i.l=t);if(o<0)i.W=new this.re(e,t),i.W.tt=i,n=i.W,this.h.W=n;else{if(void 0!==r){let i=r.o;if(i!==this.h){let r=this.v(i.u,e);if(0===r)return void(i.l=t);if(r>0){let r=i.L(),o=this.v(r.u,e);if(0===o)return void(r.l=t);o<0&&(n=new this.re(e,t),void 0===r.W?(r.W=n,n.tt=r):(i.U=n,n.tt=i))}}}if(void 0===n)for(n=this.Y;;){let r=this.v(n.u,e);if(r>0){if(void 0===n.U){n.U=new this.re(e,t),n.U.tt=n,n=n.U;break}n=n.U}else{if(!(r<0))return void(n.l=t);if(void 0===n.W){n.W=new this.re(e,t),n.W.tt=n,n=n.W;break}n=n.W}}}}return this.i+=1,n}i.l=t}I(e,t){for(;e;){let r=this.v(e.u,t);if(r<0)e=e.W;else{if(!(r>0))return e;e=e.U}}return e||this.h}clear(){this.i=0,this.Y=void 0,this.h.tt=void 0,this.h.U=this.h.W=void 0}updateKeyByIterator(e,t){let r=e.o;if(r===this.h&&(0,n.throwIteratorAccessError)(),1===this.i)return r.u=t,!0;if(r===this.h.U)return this.v(r.B().u,t)>0&&(r.u=t,!0);if(r===this.h.W)return this.v(r.L().u,t)<0&&(r.u=t,!0);let i=r.L().u;if(this.v(i,t)>=0)return!1;let o=r.B().u;return!(this.v(o,t)<=0)&&(r.u=t,!0)}eraseElementByPos(e){if(e<0||e>this.i-1)throw new RangeError;let t=0,r=this;return this.oe(this.Y,function(n){return e===t?(r.V(n),!0):(t+=1,!1)}),this.i}eraseElementByKey(e){if(0===this.i)return!1;let t=this.I(this.Y,e);return t!==this.h&&(this.V(t),!0)}eraseElementByIterator(e){let t=e.o;t===this.h&&(0,n.throwIteratorAccessError)();let r=void 0===t.W;return 0===e.iteratorType?r&&e.next():(!r||void 0===t.U)&&e.next(),this.V(t),e}forEach(e){let t=0;for(let r of this)e(r,t++,this)}getElementByPos(e){if(e<0||e>this.i-1)throw new RangeError;let t,r=0;for(let n of this){if(r===e){t=n;break}r+=1}return t}getHeight(){if(0===this.i)return 0;let e=function(t){return t?Math.max(e(t.U),e(t.W))+1:0};return e(this.Y)}};e.default=i}),Ar=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"t",{value:!0}),e.default=void 0;var t=pr(),r=br(),n=class extends t.ContainerIterator{constructor(e,t,n){super(n),this.o=e,this.h=t,0===this.iteratorType?(this.pre=function(){return this.o===this.h.U&&(0,r.throwIteratorAccessError)(),this.o=this.o.L(),this},this.next=function(){return this.o===this.h&&(0,r.throwIteratorAccessError)(),this.o=this.o.B(),this}):(this.pre=function(){return this.o===this.h.W&&(0,r.throwIteratorAccessError)(),this.o=this.o.B(),this},this.next=function(){return this.o===this.h&&(0,r.throwIteratorAccessError)(),this.o=this.o.L(),this})}get index(){let e=this.o,t=this.h.tt;if(e===this.h)return t?t.rt-1:0;let r=0;for(e.U&&(r+=e.U.rt);e!==t;){let t=e.tt;e===t.W&&(r+=1,t.U&&(r+=t.U.rt)),e=t}return r}};e.default=n}),Rr=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"t",{value:!0}),e.default=void 0;var t=i(Ir()),r=i(Ar()),n=br();function i(e){return e&&e.t?e:{default:e}}var o=class e extends r.default{constructor(e,t,r,n){super(e,t,n),this.container=r}get pointer(){return this.o===this.h&&(0,n.throwIteratorAccessError)(),this.o.u}copy(){return new e(this.o,this.h,this.container,this.iteratorType)}},s=class extends t.default{constructor(e=[],t,r){super(t,r);let n=this;e.forEach(function(e){n.insert(e)})}*K(e){void 0!==e&&(yield*this.K(e.U),yield e.u,yield*this.K(e.W))}begin(){return new o(this.h.U||this.h,this.h,this)}end(){return new o(this.h,this.h,this)}rBegin(){return new o(this.h.W||this.h,this.h,this,1)}rEnd(){return new o(this.h,this.h,this,1)}front(){return this.h.U?this.h.U.u:void 0}back(){return this.h.W?this.h.W.u:void 0}insert(e,t){return this.M(e,void 0,t)}find(e){let t=this.I(this.Y,e);return new o(t,this.h,this)}lowerBound(e){let t=this.X(this.Y,e);return new o(t,this.h,this)}upperBound(e){let t=this.Z(this.Y,e);return new o(t,this.h,this)}reverseLowerBound(e){let t=this.$(this.Y,e);return new o(t,this.h,this)}reverseUpperBound(e){let t=this.rr(this.Y,e);return new o(t,this.h,this)}union(e){let t=this;return e.forEach(function(e){t.insert(e)}),this.i}[Symbol.iterator](){return this.K(this.Y)}};e.default=s}),Or=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"t",{value:!0}),e.default=void 0;var t=i(Ir()),r=i(Ar()),n=br();function i(e){return e&&e.t?e:{default:e}}var o=class e extends r.default{constructor(e,t,r,n){super(e,t,n),this.container=r}get pointer(){this.o===this.h&&(0,n.throwIteratorAccessError)();let e=this;return new Proxy([],{get:(t,r)=>"0"===r?e.o.u:"1"===r?e.o.l:void 0,set(t,r,n){if("1"!==r)throw new TypeError("props must be 1");return e.o.l=n,!0}})}copy(){return new e(this.o,this.h,this.container,this.iteratorType)}},s=class extends t.default{constructor(e=[],t,r){super(t,r);let n=this;e.forEach(function(e){n.setElement(e[0],e[1])})}*K(e){void 0!==e&&(yield*this.K(e.U),yield[e.u,e.l],yield*this.K(e.W))}begin(){return new o(this.h.U||this.h,this.h,this)}end(){return new o(this.h,this.h,this)}rBegin(){return new o(this.h.W||this.h,this.h,this,1)}rEnd(){return new o(this.h,this.h,this,1)}front(){if(0===this.i)return;let e=this.h.U;return[e.u,e.l]}back(){if(0===this.i)return;let e=this.h.W;return[e.u,e.l]}lowerBound(e){let t=this.X(this.Y,e);return new o(t,this.h,this)}upperBound(e){let t=this.Z(this.Y,e);return new o(t,this.h,this)}reverseLowerBound(e){let t=this.$(this.Y,e);return new o(t,this.h,this)}reverseUpperBound(e){let t=this.rr(this.Y,e);return new o(t,this.h,this)}setElement(e,t,r){return this.M(e,t,r)}find(e){let t=this.I(this.Y,e);return new o(t,this.h,this)}getElementByKey(e){return this.I(this.Y,e).l}union(e){let t=this;return e.forEach(function(e){t.setElement(e[0],e[1])}),this.i}[Symbol.iterator](){return this.K(this.Y)}};e.default=s}),kr=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"t",{value:!0}),e.default=function(e){let t=typeof e;return"object"===t&&null!==e||"function"===t}}),xr=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"t",{value:!0}),e.HashContainerIterator=e.HashContainer=void 0;var t,r=pr(),n=(t=kr())&&t.t?t:{default:t},i=br();var o=class extends r.ContainerIterator{constructor(e,t,r){super(r),this.o=e,this.h=t,0===this.iteratorType?(this.pre=function(){return this.o.L===this.h&&(0,i.throwIteratorAccessError)(),this.o=this.o.L,this},this.next=function(){return this.o===this.h&&(0,i.throwIteratorAccessError)(),this.o=this.o.B,this}):(this.pre=function(){return this.o.B===this.h&&(0,i.throwIteratorAccessError)(),this.o=this.o.B,this},this.next=function(){return this.o===this.h&&(0,i.throwIteratorAccessError)(),this.o=this.o.L,this})}};e.HashContainerIterator=o;var s=class extends r.Container{constructor(){super(),this.H=[],this.g={},this.HASH_TAG=Symbol("@@HASH_TAG"),Object.setPrototypeOf(this.g,null),this.h={},this.h.L=this.h.B=this.p=this._=this.h}V(e){let{L:t,B:r}=e;t.B=r,r.L=t,e===this.p&&(this.p=r),e===this._&&(this._=t),this.i-=1}M(e,t,r){let i;if(void 0===r&&(r=(0,n.default)(e)),r){let r=e[this.HASH_TAG];if(void 0!==r)return this.H[r].l=t,this.i;Object.defineProperty(e,this.HASH_TAG,{value:this.H.length,configurable:!0}),i={u:e,l:t,L:this._,B:this.h},this.H.push(i)}else{let r=this.g[e];if(r)return r.l=t,this.i;i={u:e,l:t,L:this._,B:this.h},this.g[e]=i}return 0===this.i?(this.p=i,this.h.B=i):this._.B=i,this._=i,this.h.L=i,++this.i}I(e,t){if(void 0===t&&(t=(0,n.default)(e)),t){let t=e[this.HASH_TAG];return void 0===t?this.h:this.H[t]}return this.g[e]||this.h}clear(){let e=this.HASH_TAG;this.H.forEach(function(t){delete t.u[e]}),this.H=[],this.g={},Object.setPrototypeOf(this.g,null),this.i=0,this.p=this._=this.h.L=this.h.B=this.h}eraseElementByKey(e,t){let r;if(void 0===t&&(t=(0,n.default)(e)),t){let t=e[this.HASH_TAG];if(void 0===t)return!1;delete e[this.HASH_TAG],r=this.H[t],delete this.H[t]}else{if(r=this.g[e],void 0===r)return!1;delete this.g[e]}return this.V(r),!0}eraseElementByIterator(e){let t=e.o;return t===this.h&&(0,i.throwIteratorAccessError)(),this.V(t),e.next()}eraseElementByPos(e){if(e<0||e>this.i-1)throw new RangeError;let t=this.p;for(;e--;)t=t.B;return this.V(t),this.i}};e.HashContainer=s}),Tr=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"t",{value:!0}),e.default=void 0;var t=xr(),r=br(),n=class e extends t.HashContainerIterator{constructor(e,t,r,n){super(e,t,n),this.container=r}get pointer(){return this.o===this.h&&(0,r.throwIteratorAccessError)(),this.o.u}copy(){return new e(this.o,this.h,this.container,this.iteratorType)}},i=class extends t.HashContainer{constructor(e=[]){super();let t=this;e.forEach(function(e){t.insert(e)})}begin(){return new n(this.p,this.h,this)}end(){return new n(this.h,this.h,this)}rBegin(){return new n(this._,this.h,this,1)}rEnd(){return new n(this.h,this.h,this,1)}front(){return this.p.u}back(){return this._.u}insert(e,t){return this.M(e,void 0,t)}getElementByPos(e){if(e<0||e>this.i-1)throw new RangeError;let t=this.p;for(;e--;)t=t.B;return t.u}find(e,t){let r=this.I(e,t);return new n(r,this.h,this)}forEach(e){let t=0,r=this.p;for(;r!==this.h;)e(r.u,t++,this),r=r.B}[Symbol.iterator](){return function*(){let e=this.p;for(;e!==this.h;)yield e.u,e=e.B}.bind(this)()}};e.default=i}),Cr=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"t",{value:!0}),e.default=void 0;var t,r=xr(),n=(t=kr())&&t.t?t:{default:t},i=br();var o=class e extends r.HashContainerIterator{constructor(e,t,r,n){super(e,t,n),this.container=r}get pointer(){this.o===this.h&&(0,i.throwIteratorAccessError)();let e=this;return new Proxy([],{get:(t,r)=>"0"===r?e.o.u:"1"===r?e.o.l:void 0,set(t,r,n){if("1"!==r)throw new TypeError("props must be 1");return e.o.l=n,!0}})}copy(){return new e(this.o,this.h,this.container,this.iteratorType)}},s=class extends r.HashContainer{constructor(e=[]){super();let t=this;e.forEach(function(e){t.setElement(e[0],e[1])})}begin(){return new o(this.p,this.h,this)}end(){return new o(this.h,this.h,this)}rBegin(){return new o(this._,this.h,this,1)}rEnd(){return new o(this.h,this.h,this,1)}front(){if(0!==this.i)return[this.p.u,this.p.l]}back(){if(0!==this.i)return[this._.u,this._.l]}setElement(e,t,r){return this.M(e,t,r)}getElementByKey(e,t){if(void 0===t&&(t=(0,n.default)(e)),t){let t=e[this.HASH_TAG];return void 0!==t?this.H[t].l:void 0}let r=this.g[e];return r?r.l:void 0}getElementByPos(e){if(e<0||e>this.i-1)throw new RangeError;let t=this.p;for(;e--;)t=t.B;return[t.u,t.l]}find(e,t){let r=this.I(e,t);return new o(r,this.h,this)}forEach(e){let t=0,r=this.p;for(;r!==this.h;)e([r.u,r.l],t++,this),r=r.B}[Symbol.iterator](){return function*(){let e=this.p;for(;e!==this.h;)yield[e.u,e.l],e=e.B}.bind(this)()}};e.default=s}),Pr=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"t",{value:!0}),Object.defineProperty(e,"Deque",{enumerable:!0,get:function(){return s.default}}),Object.defineProperty(e,"HashMap",{enumerable:!0,get:function(){return h.default}}),Object.defineProperty(e,"HashSet",{enumerable:!0,get:function(){return c.default}}),Object.defineProperty(e,"LinkList",{enumerable:!0,get:function(){return o.default}}),Object.defineProperty(e,"OrderedMap",{enumerable:!0,get:function(){return u.default}}),Object.defineProperty(e,"OrderedSet",{enumerable:!0,get:function(){return a.default}}),Object.defineProperty(e,"PriorityQueue",{enumerable:!0,get:function(){return n.default}}),Object.defineProperty(e,"Queue",{enumerable:!0,get:function(){return r.default}}),Object.defineProperty(e,"Stack",{enumerable:!0,get:function(){return t.default}}),Object.defineProperty(e,"Vector",{enumerable:!0,get:function(){return i.default}});var t=f(dr()),r=f(gr()),n=f(yr()),i=f(wr()),o=f(_r()),s=f(Er()),a=f(Rr()),u=f(Or()),c=f(Tr()),h=f(Cr());function f(e){return e&&e.t?e:{default:e}}}),Nr=o((e,t)=>{l(),tt(),Fe();var r=Pr().OrderedSet,n=Yt()("number-allocator:trace"),i=Yt()("number-allocator:error");function o(e,t){this.low=e,this.high=t}function s(e,t){if(!(this instanceof s))return new s(e,t);this.min=e,this.max=t,this.ss=new r([],(e,t)=>e.compare(t)),n("Create"),this.clear()}o.prototype.equals=function(e){return this.low===e.low&&this.high===e.high},o.prototype.compare=function(e){return this.low<e.low&&this.high<e.low?-1:e.low<this.low&&e.high<this.low?1:0},s.prototype.firstVacant=function(){return 0===this.ss.size()?null:this.ss.front().low},s.prototype.alloc=function(){if(0===this.ss.size())return n("alloc():empty"),null;let e=this.ss.begin(),t=e.pointer.low,r=e.pointer.high,i=t;return i+1<=r?this.ss.updateKeyByIterator(e,new o(t+1,r)):this.ss.eraseElementByPos(0),n("alloc():"+i),i},s.prototype.use=function(e){let t=new o(e,e),r=this.ss.lowerBound(t);if(!r.equals(this.ss.end())){let i=r.pointer.low,s=r.pointer.high;return r.pointer.equals(t)?(this.ss.eraseElementByIterator(r),n("use():"+e),!0):!(i>e)&&(i===e?(this.ss.updateKeyByIterator(r,new o(i+1,s)),n("use():"+e),!0):s===e?(this.ss.updateKeyByIterator(r,new o(i,s-1)),n("use():"+e),!0):(this.ss.updateKeyByIterator(r,new o(e+1,s)),this.ss.insert(new o(i,e-1)),n("use():"+e),!0))}return n("use():failed"),!1},s.prototype.free=function(e){if(e<this.min||e>this.max)return void i("free():"+e+" is out of range");let t=new o(e,e),r=this.ss.upperBound(t);if(r.equals(this.ss.end())){if(r.equals(this.ss.begin()))return void this.ss.insert(t);r.pre();let n=r.pointer.high;r.pointer.high+1===e?this.ss.updateKeyByIterator(r,new o(n,e)):this.ss.insert(t)}else if(r.equals(this.ss.begin()))if(e+1===r.pointer.low){let t=r.pointer.high;this.ss.updateKeyByIterator(r,new o(e,t))}else this.ss.insert(t);else{let n=r.pointer.low,i=r.pointer.high;r.pre();let s=r.pointer.low;r.pointer.high+1===e?e+1===n?(this.ss.eraseElementByIterator(r),this.ss.updateKeyByIterator(r,new o(s,i))):this.ss.updateKeyByIterator(r,new o(s,e)):e+1===n?(this.ss.eraseElementByIterator(r.next()),this.ss.insert(new o(e,i))):this.ss.insert(t)}n("free():"+e)},s.prototype.clear=function(){n("clear()"),this.ss.clear(),this.ss.insert(new o(this.min,this.max))},s.prototype.intervalCount=function(){return this.ss.size()},s.prototype.dump=function(){console.log("length:"+this.ss.size());for(let e of this.ss)console.log(e)},t.exports=s}),Lr=o((e,t)=>{l(),tt(),Fe();var r=Nr();t.exports.NumberAllocator=r}),Mr=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"__esModule",{value:!0});var t=fr(),r=Lr();e.default=class{aliasToTopic;topicToAlias;max;numberAllocator;length;constructor(e){e>0&&(this.aliasToTopic=new t.LRUCache({max:e}),this.topicToAlias={},this.numberAllocator=new r.NumberAllocator(1,e),this.max=e,this.length=0)}put(e,t){if(0===t||t>this.max)return!1;let r=this.aliasToTopic.get(t);return r&&delete this.topicToAlias[r],this.aliasToTopic.set(t,e),this.topicToAlias[e]=t,this.numberAllocator.use(t),this.length=this.aliasToTopic.size,!0}getTopicByAlias(e){return this.aliasToTopic.get(e)}getAliasByTopic(e){let t=this.topicToAlias[e];return typeof t<"u"&&this.aliasToTopic.get(t),t}clear(){this.aliasToTopic.clear(),this.topicToAlias={},this.numberAllocator.clear(),this.length=0}getLruAlias(){return this.numberAllocator.firstVacant()||[...this.aliasToTopic.keys()][this.aliasToTopic.size-1]}}}),Br=o(e=>{l(),tt(),Fe();var t=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0});var r=cr(),n=t(Mr()),i=ur();e.default=(e,t)=>{e.log("_handleConnack");let{options:o}=e,s=5===o.protocolVersion?t.reasonCode:t.returnCode;if(clearTimeout(e.connackTimer),delete e.topicAliasSend,t.properties){if(t.properties.topicAliasMaximum){if(t.properties.topicAliasMaximum>65535)return void e.emit("error",new Error("topicAliasMaximum from broker is out of range"));t.properties.topicAliasMaximum>0&&(e.topicAliasSend=new n.default(t.properties.topicAliasMaximum))}t.properties.serverKeepAlive&&o.keepalive&&(o.keepalive=t.properties.serverKeepAlive),t.properties.maximumPacketSize&&(o.properties||(o.properties={}),o.properties.maximumPacketSize=t.properties.maximumPacketSize)}if(0===s)e.reconnecting=!1,e._onConnect(t);else if(s>0){let t=new i.ErrorWithReasonCode(`Connection refused: ${r.ReasonCodes[s]}`,s);e.emit("error",t),e.options.reconnectOnConnackError&&e._cleanUp(!0)}}}),Dr=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"__esModule",{value:!0});e.default=(e,t,r)=>{e.log("handling pubrel packet");let n=typeof r<"u"?r:e.noop,{messageId:i}=t,o={cmd:"pubcomp",messageId:i};e.incomingStore.get(t,(t,r)=>{t?e._sendPacket(o,n):(e.emit("message",r.topic,r.payload,r),e.handleMessage(r,t=>{if(t)return n(t);e.incomingStore.del(r,e.noop),e._sendPacket(o,n)}))})}}),jr=o(e=>{l(),tt(),Fe();var t=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0});var r=t(ar()),n=t(hr()),i=t(Br()),o=t(cr()),s=t(Dr());e.default=(e,t,a)=>{let{options:l}=e;if(5===l.protocolVersion&&l.properties&&l.properties.maximumPacketSize&&l.properties.maximumPacketSize<t.length)return e.emit("error",new Error(`exceeding packets size ${t.cmd}`)),e.end({reasonCode:149,properties:{reasonString:"Maximum packet size was exceeded"}}),e;switch(e.log("_handlePacket :: emitting packetreceive"),e.emit("packetreceive",t),t.cmd){case"publish":(0,r.default)(e,t,a);break;case"puback":case"pubrec":case"pubcomp":case"suback":case"unsuback":e.reschedulePing(),(0,o.default)(e,t),a();break;case"pubrel":e.reschedulePing(),(0,s.default)(e,t,a);break;case"connack":(0,i.default)(e,t),a();break;case"auth":e.reschedulePing(),(0,n.default)(e,t),a();break;case"pingresp":e.log("_handlePacket :: received pingresp"),e.reschedulePing(!0),a();break;case"disconnect":e.emit("disconnect",t),a();break;default:e.log("_handlePacket :: unknown command"),a()}}}),Ur=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"__esModule",{value:!0});e.default=class{nextId;constructor(){this.nextId=Math.max(1,Math.floor(65535*Math.random()))}allocate(){let e=this.nextId++;return 65536===this.nextId&&(this.nextId=1),e}getLastAllocated(){return 1===this.nextId?65535:this.nextId-1}register(e){return!0}deallocate(e){}clear(){}}}),Fr=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"__esModule",{value:!0});e.default=class{aliasToTopic;max;length;constructor(e){this.aliasToTopic={},this.max=e}put(e,t){return!(0===t||t>this.max)&&(this.aliasToTopic[t]=e,this.length=Object.keys(this.aliasToTopic).length,!0)}getTopicByAlias(e){return this.aliasToTopic[e]}clear(){this.aliasToTopic={}}}}),Wr=o(e=>{l(),tt(),Fe();var t=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.TypedEventEmitter=void 0;var r=t((mt(),a(st))),n=ur(),i=class{};e.TypedEventEmitter=i,(0,n.applyMixin)(i,r.default)}),$r=o((e,t)=>{var r,n;l(),tt(),Fe(),r=e,n=function(e){var t,r=void 0===Number.MAX_SAFE_INTEGER?9007199254740991:Number.MAX_SAFE_INTEGER,n=536870912,i=2*n,o=new WeakMap,s=function(e,t){return function(o){var s=t.get(o),a=void 0===s?o.size:s<i?s+1:0;if(!o.has(a))return e(o,a);if(o.size<n){for(;o.has(a);)a=Math.floor(Math.random()*i);return e(o,a)}if(o.size>r)throw new Error("Congratulations, you created a collection of unique numbers which uses all available integers!");for(;o.has(a);)a=Math.floor(Math.random()*r);return e(o,a)}}((t=o,function(e,r){return t.set(e,r),r}),o),a=function(e){return function(t){var r=e(t);return t.add(r),r}}(s);e.addUniqueNumber=a,e.generateUniqueNumber=s},"object"==typeof e&&typeof t<"u"?n(e):"function"==typeof define&&define.amd?define(["exports"],n):n((r=typeof globalThis<"u"?globalThis:r||self).fastUniqueNumbers={})}),qr=o((e,t)=>{function r(e){return t.exports=r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},t.exports.__esModule=!0,t.exports.default=t.exports,r(e)}l(),tt(),Fe(),t.exports=r,t.exports.__esModule=!0,t.exports.default=t.exports}),Gr=o((e,t)=>{l(),tt(),Fe();var r=qr().default;t.exports=function(e,t){if("object"!=r(e)||!e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var i=n.call(e,t||"default");if("object"!=r(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)},t.exports.__esModule=!0,t.exports.default=t.exports}),Vr=o((e,t)=>{l(),tt(),Fe();var r=qr().default,n=Gr();t.exports=function(e){var t=n(e,"string");return"symbol"==r(t)?t:t+""},t.exports.__esModule=!0,t.exports.default=t.exports}),Hr=o((e,t)=>{l(),tt(),Fe();var r=Vr();t.exports=function(e,t,n){return(t=r(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e},t.exports.__esModule=!0,t.exports.default=t.exports}),Kr=o((e,t)=>{l(),tt(),Fe(),t.exports=function(e){if(Array.isArray(e))return e},t.exports.__esModule=!0,t.exports.default=t.exports}),zr=o((e,t)=>{l(),tt(),Fe(),t.exports=function(e,t){var r=null==e?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,i,o,s,a=[],l=!0,u=!1;try{if(o=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;l=!1}else for(;!(l=(n=o.call(r)).done)&&(a.push(n.value),a.length!==t);l=!0);}catch(e){u=!0,i=e}finally{try{if(!l&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(u)throw i}}return a}},t.exports.__esModule=!0,t.exports.default=t.exports}),Qr=o((e,t)=>{l(),tt(),Fe(),t.exports=function(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n},t.exports.__esModule=!0,t.exports.default=t.exports}),Yr=o((e,t)=>{l(),tt(),Fe();var r=Qr();t.exports=function(e,t){if(e){if("string"==typeof e)return r(e,t);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}},t.exports.__esModule=!0,t.exports.default=t.exports}),Jr=o((e,t)=>{l(),tt(),Fe(),t.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},t.exports.__esModule=!0,t.exports.default=t.exports}),Xr=o((e,t)=>{l(),tt(),Fe();var r=Kr(),n=zr(),i=Yr(),o=Jr();t.exports=function(e,t){return r(e)||n(e,t)||i(e,t)||o()},t.exports.__esModule=!0,t.exports.default=t.exports}),Zr=o((e,t)=>{function r(e,t,r,n,i,o,s){try{var a=e[o](s),l=a.value}catch(e){return void r(e)}a.done?t(l):Promise.resolve(l).then(n,i)}l(),tt(),Fe(),t.exports=function(e){return function(){var t=this,n=arguments;return new Promise(function(i,o){var s=e.apply(t,n);function a(e){r(s,i,o,a,l,"next",e)}function l(e){r(s,i,o,a,l,"throw",e)}a(void 0)})}},t.exports.__esModule=!0,t.exports.default=t.exports}),en=o((e,t)=>{l(),tt(),Fe(),t.exports=function(e,t){this.v=e,this.k=t},t.exports.__esModule=!0,t.exports.default=t.exports}),tn=o((e,t)=>{function r(e,n,i,o){var s=Object.defineProperty;try{s({},"",{})}catch{s=0}t.exports=r=function(e,t,n,i){function o(t,n){r(e,t,function(e){return this._invoke(t,n,e)})}t?s?s(e,t,{value:n,enumerable:!i,configurable:!i,writable:!i}):e[t]=n:(o("next",0),o("throw",1),o("return",2))},t.exports.__esModule=!0,t.exports.default=t.exports,r(e,n,i,o)}l(),tt(),Fe(),t.exports=r,t.exports.__esModule=!0,t.exports.default=t.exports}),rn=o((e,t)=>{l(),tt(),Fe();var r=tn();function n(){var e,i,o="function"==typeof Symbol?Symbol:{},s=o.iterator||"@@iterator",a=o.toStringTag||"@@toStringTag";function l(t,n,o,s){var a=n&&n.prototype instanceof c?n:c,l=Object.create(a.prototype);return r(l,"_invoke",function(t,r,n){var o,s,a,l=0,c=n||[],h=!1,f={p:0,n:0,v:e,a:p,f:p.bind(e,4),d:function(t,r){return o=t,s=0,a=e,f.n=r,u}};function p(t,r){for(s=t,a=r,i=0;!h&&l&&!n&&i<c.length;i++){var n,o=c[i],p=f.p,d=o[2];t>3?(n=d===r)&&(a=o[(s=o[4])?5:(s=3,3)],o[4]=o[5]=e):o[0]<=p&&((n=t<2&&p<o[1])?(s=0,f.v=r,f.n=o[1]):p<d&&(n=t<3||o[0]>r||r>d)&&(o[4]=t,o[5]=r,f.n=d,s=0))}if(n||t>1)return u;throw h=!0,r}return function(n,c,d){if(l>1)throw TypeError("Generator is already running");for(h&&1===c&&p(c,d),s=c,a=d;(i=s<2?e:a)||!h;){o||(s?s<3?(s>1&&(f.n=-1),p(s,a)):f.n=a:f.v=a);try{if(l=2,o){if(s||(n="next"),i=o[n]){if(!(i=i.call(o,a)))throw TypeError("iterator result is not an object");if(!i.done)return i;a=i.value,s<2&&(s=0)}else 1===s&&(i=o.return)&&i.call(o),s<2&&(a=TypeError("The iterator does not provide a '"+n+"' method"),s=1);o=e}else if((i=(h=f.n<0)?a:t.call(r,f))!==u)break}catch(t){o=e,s=1,a=t}finally{l=1}}return{value:i,done:h}}}(t,o,s),!0),l}var u={};function c(){}function h(){}function f(){}i=Object.getPrototypeOf;var p=[][s]?i(i([][s]())):(r(i={},s,function(){return this}),i),d=f.prototype=c.prototype=Object.create(p);function g(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,f):(e.__proto__=f,r(e,a,"GeneratorFunction")),e.prototype=Object.create(d),e}return h.prototype=f,r(d,"constructor",f),r(f,"constructor",h),h.displayName="GeneratorFunction",r(f,a,"GeneratorFunction"),r(d),r(d,a,"Generator"),r(d,s,function(){return this}),r(d,"toString",function(){return"[object Generator]"}),(t.exports=n=function(){return{w:l,m:g}},t.exports.__esModule=!0,t.exports.default=t.exports)()}t.exports=n,t.exports.__esModule=!0,t.exports.default=t.exports}),nn=o((e,t)=>{l(),tt(),Fe();var r=en(),n=tn();t.exports=function e(t,i){function o(e,n,s,a){try{var l=t[e](n),u=l.value;return u instanceof r?i.resolve(u.v).then(function(e){o("next",e,s,a)},function(e){o("throw",e,s,a)}):i.resolve(u).then(function(e){l.value=e,s(l)},function(e){return o("throw",e,s,a)})}catch(e){a(e)}}var s;this.next||(n(e.prototype),n(e.prototype,"function"==typeof Symbol&&Symbol.asyncIterator||"@asyncIterator",function(){return this})),n(this,"_invoke",function(e,t,r){function n(){return new i(function(t,n){o(e,r,t,n)})}return s=s?s.then(n,n):n()},!0)},t.exports.__esModule=!0,t.exports.default=t.exports}),on=o((e,t)=>{l(),tt(),Fe();var r=rn(),n=nn();t.exports=function(e,t,i,o,s){return new n(r().w(e,t,i,o),s||Promise)},t.exports.__esModule=!0,t.exports.default=t.exports}),sn=o((e,t)=>{l(),tt(),Fe();var r=on();t.exports=function(e,t,n,i,o){var s=r(e,t,n,i,o);return s.next().then(function(e){return e.done?e.value:s.next()})},t.exports.__esModule=!0,t.exports.default=t.exports}),an=o((e,t)=>{l(),tt(),Fe(),t.exports=function(e){var t=Object(e),r=[];for(var n in t)r.unshift(n);return function e(){for(;r.length;)if((n=r.pop())in t)return e.value=n,e.done=!1,e;return e.done=!0,e}},t.exports.__esModule=!0,t.exports.default=t.exports}),ln=o((e,t)=>{l(),tt(),Fe();var r=qr().default;t.exports=function(e){if(null!=e){var t=e["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],n=0;if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length))return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}throw new TypeError(r(e)+" is not iterable")},t.exports.__esModule=!0,t.exports.default=t.exports}),un=o((e,t)=>{l(),tt(),Fe();var r=en(),n=rn(),i=sn(),o=on(),s=nn(),a=an(),u=ln();function c(){var e=n(),l=e.m(c),h=(Object.getPrototypeOf?Object.getPrototypeOf(l):l.__proto__).constructor;function f(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===h||"GeneratorFunction"===(t.displayName||t.name))}var p={throw:1,return:2,break:3,continue:3};function d(e){var t,r;return function(n){t||(t={stop:function(){return r(n.a,2)},catch:function(){return n.v},abrupt:function(e,t){return r(n.a,p[e],t)},delegateYield:function(e,i,o){return t.resultName=i,r(n.d,u(e),o)},finish:function(e){return r(n.f,e)}},r=function(e,r,i){n.p=t.prev,n.n=t.next;try{return e(r,i)}finally{t.next=n.n}}),t.resultName&&(t[t.resultName]=n.v,t.resultName=void 0),t.sent=n.v,t.next=n.n;try{return e.call(this,t)}finally{n.p=t.prev,n.n=t.next}}}return(t.exports=c=function(){return{wrap:function(t,r,n,i){return e.w(d(t),r,n,i&&i.reverse())},isGeneratorFunction:f,mark:e.m,awrap:function(e,t){return new r(e,t)},AsyncIterator:s,async:function(e,t,r,n,s){return(f(t)?o:i)(d(e),t,r,n,s)},keys:a,values:u}},t.exports.__esModule=!0,t.exports.default=t.exports)()}t.exports=c,t.exports.__esModule=!0,t.exports.default=t.exports}),cn=o((e,t)=>{l(),tt(),Fe();var r=un()();t.exports=r;try{regeneratorRuntime=r}catch{"object"==typeof globalThis?globalThis.regeneratorRuntime=r:Function("r","regeneratorRuntime = r")(r)}}),hn=o((e,t)=>{var r,n;l(),tt(),Fe(),r=e,n=function(e,t,r,n,i,o){function s(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function a(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?s(Object(n),!0).forEach(function(t){r(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):s(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function u(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?l(Object(n),!0).forEach(function(t){r(e,t,n[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):l(Object(n)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))})}return e}var c,h=function(e,t,i,o){return function(s){var l=t(s);return function(t){var s=e(t);t.addEventListener("message",function(e){var t=e.data,r=t.id;if(null!==r&&s.has(r)){var n=s.get(r),i=n.reject,o=n.resolve;s.delete(r),void 0===t.error?o(t.result):i(new Error(t.error.message))}}),o(t)&&t.start();for(var u=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];return new Promise(function(o,a){var l=i(s);s.set(l,{reject:a,resolve:o}),null===r?t.postMessage({id:l,method:e},n):t.postMessage({id:l,method:e,params:r},n)})},c=function(e,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];t.postMessage({id:null,method:e,params:r},n)},h={},f=0,p=Object.entries(l);f<p.length;f++){var d=n(p[f],2),g=d[0],y=d[1];h=a(a({},h),{},r({},g,y({call:u,notify:c})))}return a({},h)}}}((c=new WeakMap,function(e){if(c.has(e))return c.get(e);var t=new Map;return c.set(e,t),t}),function(e){return function(t){return u(u({},t),{},{connect:function(t){var r=t.call;return i(o.mark(function t(){var n,i,s,a;return o.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return n=new MessageChannel,i=n.port1,s=n.port2,t.next=1,r("connect",{port:i},[i]);case 1:return a=t.sent,e.set(s,a),t.abrupt("return",s);case 2:case"end":return t.stop()}},t)}))},disconnect:function(t){var r,n=t.call;return r=i(o.mark(function t(r){var i;return o.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0!==(i=e.get(r))){t.next=1;break}throw new Error("The given port is not connected.");case 1:return t.next=2,n("disconnect",{portId:i});case 2:case"end":return t.stop()}},t)})),function(e){return r.apply(this,arguments)}},isSupported:function(e){var t=e.call;return function(){return t("isSupported")}}})}}(new WeakMap),t.generateUniqueNumber,function(e){return"function"==typeof e.start});e.createBroker=h},"object"==typeof e&&typeof t<"u"?n(e,$r(),Hr(),Xr(),Zr(),cn()):"function"==typeof define&&define.amd?define(["exports","fast-unique-numbers","@babel/runtime/helpers/defineProperty","@babel/runtime/helpers/slicedToArray","@babel/runtime/helpers/asyncToGenerator","@babel/runtime/regenerator"],n):n((r=typeof globalThis<"u"?globalThis:r||self).brokerFactory={},r.fastUniqueNumbers,r._defineProperty,r._slicedToArray,r._asyncToGenerator,r._regeneratorRuntime)}),fn=o((e,t)=>{var r,n;l(),tt(),Fe(),r=e,n=function(e,t,r,n){var i,o=new Map([[0,null]]),s=new Map([[0,null]]),a=(i=o,function(e){return function(t){"symbol"===n(i.get(t))&&(i.set(t,null),e(t).then(function(){i.delete(t)}))}}),l=function(e){return function(t){return function(r){"symbol"===n(e.get(r))&&(e.set(r,null),t(r).then(function(){e.delete(r)}))}}}(s),u=function(e,t){return function(r){return function(n){for(var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=arguments.length,s=new Array(o>2?o-2:0),a=2;a<o;a++)s[a-2]=arguments[a];var l=Symbol(),u=e(t);t.set(u,l);var c=function(){return r(i,u).then(function(){var e=t.get(u);if(void 0===e)throw new Error("The timer is in an undefined state.");e===l&&(n.apply(void 0,s),t.get(u)===l&&c())})};return c(),u}}}(r.generateUniqueNumber,o),c=function(e,t){return function(r){return function(n){for(var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=arguments.length,s=new Array(o>2?o-2:0),a=2;a<o;a++)s[a-2]=arguments[a];var l=Symbol(),u=e(t);return t.set(u,l),r(i,u).then(function(){var e=t.get(u);if(void 0===e)throw new Error("The timer is in an undefined state.");e===l&&(t.delete(u),n.apply(void 0,s))}),u}}}(r.generateUniqueNumber,s),h=t.createBroker({clearInterval:function(e){var t=e.call;return a(function(e){return t("clear",{timerId:e,timerType:"interval"})})},clearTimeout:function(e){var t=e.call;return l(function(e){return t("clear",{timerId:e,timerType:"timeout"})})},setInterval:function(e){var t=e.call;return u(function(e,r){return t("set",{delay:e,now:performance.timeOrigin+performance.now(),timerId:r,timerType:"interval"})})},setTimeout:function(e){var t=e.call;return c(function(e,r){return t("set",{delay:e,now:performance.timeOrigin+performance.now(),timerId:r,timerType:"timeout"})})}});e.load=function(e){var t=new Worker(e);return h(t)},e.wrap=h},"object"==typeof e&&typeof t<"u"?n(e,hn(),$r(),qr()):"function"==typeof define&&define.amd?define(["exports","broker-factory","fast-unique-numbers","@babel/runtime/helpers/typeof"],n):n((r=typeof globalThis<"u"?globalThis:r||self).workerTimersBroker={},r.brokerFactory,r.fastUniqueNumbers,r._typeof)}),pn=o((e,t)=>{var r,n;l(),tt(),Fe(),r=e,n=function(e,t){var r,n,i,o=(r=t.load,n='(()=>{var e={389(e,t){!function(e){"use strict";var t=function(e){return function(t){var r=e(t);return t.add(r),r}},r=function(e){return function(t,r){return e.set(t,r),r}},n=void 0===Number.MAX_SAFE_INTEGER?9007199254740991:Number.MAX_SAFE_INTEGER,o=536870912,u=2*o,a=function(e,t){return function(r){var a=t.get(r),i=void 0===a?r.size:a<u?a+1:0;if(!r.has(i))return e(r,i);if(r.size<o){for(;r.has(i);)i=Math.floor(Math.random()*u);return e(r,i)}if(r.size>n)throw new Error("Congratulations, you created a collection of unique numbers which uses all available integers!");for(;r.has(i);)i=Math.floor(Math.random()*n);return e(r,i)}},i=new WeakMap,s=r(i),c=a(s,i),f=t(c);e.addUniqueNumber=f,e.generateUniqueNumber=c}(t)},623(e,t,r){!function(e,t,r,n,o){"use strict";var u={INTERNAL_ERROR:-32603,INVALID_PARAMS:-32602,METHOD_NOT_FOUND:-32601},a=function(e,t){return Object.assign(new Error(e),{status:t})},i=function(e){return a(\'The requested method called "\'.concat(e,\'" is not supported.\'),u.METHOD_NOT_FOUND)},s=function(e){return a(\'The handler of the method called "\'.concat(e,\'" returned no required result.\'),u.INTERNAL_ERROR)},c=function(e){return a(\'The handler of the method called "\'.concat(e,\'" returned an unexpected result.\'),u.INTERNAL_ERROR)},f=function(e){return a(\'The specified parameter called "portId" with the given value "\'.concat(e,\'" does not identify a port connected to this worker.\'),u.INVALID_PARAMS)},l=function(e,n){return function(){var o=t(r.mark(function t(o){var u,a,f,l,p,d,v,x,y,b,h,m,_,g,w;return r.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(u=o.data,a=u.id,f=u.method,l=u.params,p=n[f],t.prev=1,void 0!==p){t.next=2;break}throw i(f);case 2:if(void 0!==(d=void 0===l?p():p(l))){t.next=3;break}throw s(f);case 3:if(!(d instanceof Promise)){t.next=5;break}return t.next=4,d;case 4:g=t.sent,t.next=6;break;case 5:g=d;case 6:if(v=g,null!==a){t.next=8;break}if(void 0===v.result){t.next=7;break}throw c(f);case 7:t.next=10;break;case 8:if(void 0!==v.result){t.next=9;break}throw c(f);case 9:x=v.result,y=v.transferables,b=void 0===y?[]:y,e.postMessage({id:a,result:x},b);case 10:t.next=12;break;case 11:t.prev=11,w=t.catch(1),h=w.message,m=w.status,_=void 0===m?-32603:m,e.postMessage({error:{code:_,message:h},id:a});case 12:case"end":return t.stop()}},t,null,[[1,11]])}));return function(e){return o.apply(this,arguments)}}()},p=function(){return new Promise(function(e){var t=new ArrayBuffer(0),r=new MessageChannel,n=r.port1,o=r.port2;n.onmessage=function(t){var r=t.data;return e(null!==r)},o.postMessage(t,[t])})};function d(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function v(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?d(Object(r),!0).forEach(function(t){n(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):d(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}var x=new Map,y=function(e,n,u){return v(v({},n),{},{connect:function(t){var r=t.port;r.start();var u=e(r,n),a=o.generateUniqueNumber(x);return x.set(a,function(){u(),r.close(),x.delete(a)}),{result:a}},disconnect:function(e){var t=e.portId,r=x.get(t);if(void 0===r)throw f(t);return r(),{result:null}},isSupported:function(){var e=t(r.mark(function e(){var t,n,o;return r.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,p();case 1:if(!e.sent){e.next=5;break}if(!((t=u())instanceof Promise)){e.next=3;break}return e.next=2,t;case 2:o=e.sent,e.next=4;break;case 3:o=t;case 4:return n=o,e.abrupt("return",{result:n});case 5:return e.abrupt("return",{result:!1});case 6:case"end":return e.stop()}},e)}));function n(){return e.apply(this,arguments)}return n}()})},b=function(e,t){var r=y(b,t,arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){return!0}),n=l(e,r);return e.addEventListener("message",n),function(){return e.removeEventListener("message",n)}};e.createWorker=b,e.isSupported=p}(t,r(293),r(756),r(693),r(389))},472(e,t,r){!function(e,t,r,n){"use strict";var o=function(e,t){return function(r){var o=t.get(r);if(void 0===o)return Promise.resolve(!1);var u=n(o,2),a=u[0],i=u[1];return e(a),t.delete(r),i(!1),Promise.resolve(!0)}},u=function(e,t){var r=function(n,o,u,a){var i=n-e.now();i>0?o.set(a,[t(r,i,n,o,u,a),u]):(o.delete(a),u(!0))};return r},a=function(e,t,r,n){return function(o,u,a){var i=o+u-t.timeOrigin,s=i-t.now();return new Promise(function(t){e.set(a,[r(n,s,i,e,t,a),t])})}},i=new Map,s=o(globalThis.clearTimeout,i),c=new Map,f=o(globalThis.clearTimeout,c),l=u(performance,globalThis.setTimeout),p=a(i,performance,globalThis.setTimeout,l),d=a(c,performance,globalThis.setTimeout,l);r.createWorker(self,{clear:function(){var r=e(t.mark(function e(r){var n,o,u;return t.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.timerId,o=r.timerType,e.next=1,"interval"===o?s(n):f(n);case 1:return u=e.sent,e.abrupt("return",{result:u});case 2:case"end":return e.stop()}},e)}));function n(e){return r.apply(this,arguments)}return n}(),set:function(){var r=e(t.mark(function e(r){var n,o,u,a,i;return t.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.delay,o=r.now,u=r.timerId,a=r.timerType,e.next=1,("interval"===a?p:d)(n,o,u);case 1:return i=e.sent,e.abrupt("return",{result:i});case 2:case"end":return e.stop()}},e)}));function n(e){return r.apply(this,arguments)}return n}()})}(r(293),r(756),r(623),r(715))},172(e){e.exports=function(e,t){this.v=e,this.k=t},e.exports.__esModule=!0,e.exports.default=e.exports},79(e){e.exports=function(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n},e.exports.__esModule=!0,e.exports.default=e.exports},987(e){e.exports=function(e){if(Array.isArray(e))return e},e.exports.__esModule=!0,e.exports.default=e.exports},293(e){function t(e,t,r,n,o,u,a){try{var i=e[u](a),s=i.value}catch(e){return void r(e)}i.done?t(s):Promise.resolve(s).then(n,o)}e.exports=function(e){return function(){var r=this,n=arguments;return new Promise(function(o,u){var a=e.apply(r,n);function i(e){t(a,o,u,i,s,"next",e)}function s(e){t(a,o,u,i,s,"throw",e)}i(void 0)})}},e.exports.__esModule=!0,e.exports.default=e.exports},693(e,t,r){var n=r(736);e.exports=function(e,t,r){return(t=n(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e},e.exports.__esModule=!0,e.exports.default=e.exports},156(e){e.exports=function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,u,a,i=[],s=!0,c=!1;try{if(u=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;s=!1}else for(;!(s=(n=u.call(r)).done)&&(i.push(n.value),i.length!==t);s=!0);}catch(e){c=!0,o=e}finally{try{if(!s&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(c)throw o}}return i}},e.exports.__esModule=!0,e.exports.default=e.exports},752(e){e.exports=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")},e.exports.__esModule=!0,e.exports.default=e.exports},993(e,t,r){var n=r(546);function o(){var t,r,u="function"==typeof Symbol?Symbol:{},a=u.iterator||"@@iterator",i=u.toStringTag||"@@toStringTag";function s(e,o,u,a){var i=o&&o.prototype instanceof f?o:f,s=Object.create(i.prototype);return n(s,"_invoke",function(e,n,o){var u,a,i,s=0,f=o||[],l=!1,p={p:0,n:0,v:t,a:d,f:d.bind(t,4),d:function(e,r){return u=e,a=0,i=t,p.n=r,c}};function d(e,n){for(a=e,i=n,r=0;!l&&s&&!o&&r<f.length;r++){var o,u=f[r],d=p.p,v=u[2];e>3?(o=v===n)&&(i=u[(a=u[4])?5:(a=3,3)],u[4]=u[5]=t):u[0]<=d&&((o=e<2&&d<u[1])?(a=0,p.v=n,p.n=u[1]):d<v&&(o=e<3||u[0]>n||n>v)&&(u[4]=e,u[5]=n,p.n=v,a=0))}if(o||e>1)return c;throw l=!0,n}return function(o,f,v){if(s>1)throw TypeError("Generator is already running");for(l&&1===f&&d(f,v),a=f,i=v;(r=a<2?t:i)||!l;){u||(a?a<3?(a>1&&(p.n=-1),d(a,i)):p.n=i:p.v=i);try{if(s=2,u){if(a||(o="next"),r=u[o]){if(!(r=r.call(u,i)))throw TypeError("iterator result is not an object");if(!r.done)return r;i=r.value,a<2&&(a=0)}else 1===a&&(r=u.return)&&r.call(u),a<2&&(i=TypeError("The iterator does not provide a \'"+o+"\' method"),a=1);u=t}else if((r=(l=p.n<0)?i:e.call(n,p))!==c)break}catch(e){u=t,a=1,i=e}finally{s=1}}return{value:r,done:l}}}(e,u,a),!0),s}var c={};function f(){}function l(){}function p(){}r=Object.getPrototypeOf;var d=[][a]?r(r([][a]())):(n(r={},a,function(){return this}),r),v=p.prototype=f.prototype=Object.create(d);function x(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,p):(e.__proto__=p,n(e,i,"GeneratorFunction")),e.prototype=Object.create(v),e}return l.prototype=p,n(v,"constructor",p),n(p,"constructor",l),l.displayName="GeneratorFunction",n(p,i,"GeneratorFunction"),n(v),n(v,i,"Generator"),n(v,a,function(){return this}),n(v,"toString",function(){return"[object Generator]"}),(e.exports=o=function(){return{w:s,m:x}},e.exports.__esModule=!0,e.exports.default=e.exports)()}e.exports=o,e.exports.__esModule=!0,e.exports.default=e.exports},869(e,t,r){var n=r(887);e.exports=function(e,t,r,o,u){var a=n(e,t,r,o,u);return a.next().then(function(e){return e.done?e.value:a.next()})},e.exports.__esModule=!0,e.exports.default=e.exports},887(e,t,r){var n=r(993),o=r(791);e.exports=function(e,t,r,u,a){return new o(n().w(e,t,r,u),a||Promise)},e.exports.__esModule=!0,e.exports.default=e.exports},791(e,t,r){var n=r(172),o=r(546);e.exports=function e(t,r){function u(e,o,a,i){try{var s=t[e](o),c=s.value;return c instanceof n?r.resolve(c.v).then(function(e){u("next",e,a,i)},function(e){u("throw",e,a,i)}):r.resolve(c).then(function(e){s.value=e,a(s)},function(e){return u("throw",e,a,i)})}catch(e){i(e)}}var a;this.next||(o(e.prototype),o(e.prototype,"function"==typeof Symbol&&Symbol.asyncIterator||"@asyncIterator",function(){return this})),o(this,"_invoke",function(e,t,n){function o(){return new r(function(t,r){u(e,n,t,r)})}return a=a?a.then(o,o):o()},!0)},e.exports.__esModule=!0,e.exports.default=e.exports},546(e){function t(r,n,o,u){var a=Object.defineProperty;try{a({},"",{})}catch(r){a=0}e.exports=t=function(e,r,n,o){function u(r,n){t(e,r,function(e){return this._invoke(r,n,e)})}r?a?a(e,r,{value:n,enumerable:!o,configurable:!o,writable:!o}):e[r]=n:(u("next",0),u("throw",1),u("return",2))},e.exports.__esModule=!0,e.exports.default=e.exports,t(r,n,o,u)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports},373(e){e.exports=function(e){var t=Object(e),r=[];for(var n in t)r.unshift(n);return function e(){for(;r.length;)if((n=r.pop())in t)return e.value=n,e.done=!1,e;return e.done=!0,e}},e.exports.__esModule=!0,e.exports.default=e.exports},633(e,t,r){var n=r(172),o=r(993),u=r(869),a=r(887),i=r(791),s=r(373),c=r(579);function f(){"use strict";var t=o(),r=t.m(f),l=(Object.getPrototypeOf?Object.getPrototypeOf(r):r.__proto__).constructor;function p(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===l||"GeneratorFunction"===(t.displayName||t.name))}var d={throw:1,return:2,break:3,continue:3};function v(e){var t,r;return function(n){t||(t={stop:function(){return r(n.a,2)},catch:function(){return n.v},abrupt:function(e,t){return r(n.a,d[e],t)},delegateYield:function(e,o,u){return t.resultName=o,r(n.d,c(e),u)},finish:function(e){return r(n.f,e)}},r=function(e,r,o){n.p=t.prev,n.n=t.next;try{return e(r,o)}finally{t.next=n.n}}),t.resultName&&(t[t.resultName]=n.v,t.resultName=void 0),t.sent=n.v,t.next=n.n;try{return e.call(this,t)}finally{n.p=t.prev,n.n=t.next}}}return(e.exports=f=function(){return{wrap:function(e,r,n,o){return t.w(v(e),r,n,o&&o.reverse())},isGeneratorFunction:p,mark:t.m,awrap:function(e,t){return new n(e,t)},AsyncIterator:i,async:function(e,t,r,n,o){return(p(t)?a:u)(v(e),t,r,n,o)},keys:s,values:c}},e.exports.__esModule=!0,e.exports.default=e.exports)()}e.exports=f,e.exports.__esModule=!0,e.exports.default=e.exports},579(e,t,r){var n=r(738).default;e.exports=function(e){if(null!=e){var t=e["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],r=0;if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length))return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}throw new TypeError(n(e)+" is not iterable")},e.exports.__esModule=!0,e.exports.default=e.exports},715(e,t,r){var n=r(987),o=r(156),u=r(122),a=r(752);e.exports=function(e,t){return n(e)||o(e,t)||u(e,t)||a()},e.exports.__esModule=!0,e.exports.default=e.exports},45(e,t,r){var n=r(738).default;e.exports=function(e,t){if("object"!=n(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var o=r.call(e,t||"default");if("object"!=n(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)},e.exports.__esModule=!0,e.exports.default=e.exports},736(e,t,r){var n=r(738).default,o=r(45);e.exports=function(e){var t=o(e,"string");return"symbol"==n(t)?t:t+""},e.exports.__esModule=!0,e.exports.default=e.exports},738(e){function t(r){return e.exports=t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.__esModule=!0,e.exports.default=e.exports,t(r)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports},122(e,t,r){var n=r(79);e.exports=function(e,t){if(e){if("string"==typeof e)return n(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}},e.exports.__esModule=!0,e.exports.default=e.exports},756(e,t,r){var n=r(633)();e.exports=n;try{regeneratorRuntime=n}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=n:Function("r","regeneratorRuntime = r")(n)}}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var u=t[n]={exports:{}};return e[n].call(u.exports,u,u.exports,r),u.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),(()=>{"use strict";r(472)})()})();',i=null,function(){if(null!==i)return i;var e=new Blob([n],{type:"application/javascript; charset=utf-8"}),t=URL.createObjectURL(e);return i=r(t),setTimeout(function(){return URL.revokeObjectURL(t)}),i});e.clearInterval=function(e){return o().clearInterval(e)},e.clearTimeout=function(e){return o().clearTimeout(e)},e.setInterval=function(){var e;return(e=o()).setInterval.apply(e,arguments)},e.setTimeout=function(){var e;return(e=o()).setTimeout.apply(e,arguments)}},"object"==typeof e&&typeof t<"u"?n(e,fn()):"function"==typeof define&&define.amd?define(["exports","worker-timers-broker"],n):n((r=typeof globalThis<"u"?globalThis:r||self).workerTimers={},r.workerTimersBroker)}),dn=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"__esModule",{value:!0}),e.isReactNativeBrowser=e.isWebWorker=void 0;var t=()=>!!("object"==typeof self&&self?.constructor?.name?.includes("WorkerGlobalScope")&&typeof Deno>"u"),r=()=>typeof navigator<"u"&&"ReactNative"===navigator.product,n=typeof window<"u"&&(typeof navigator<"u"&&navigator.userAgent?.toLowerCase().indexOf(" electron/")>-1&&u?.versions?!Object.prototype.hasOwnProperty.call(u.versions,"electron"):typeof window.document<"u")||t()||r();e.isWebWorker=t(),e.isReactNativeBrowser=r(),e.default=n}),gn=o(e=>{l(),tt(),Fe();var t,r=e&&e.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);(!i||("get"in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),n=e&&e.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=e&&e.__importStar||(t=function(e){return(t=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t})(e)},function(e){if(e&&e.__esModule)return e;var i={};if(null!=e)for(var o=t(e),s=0;s<o.length;s++)"default"!==o[s]&&r(i,e,o[s]);return n(i,e),i});Object.defineProperty(e,"__esModule",{value:!0});var o=pn(),s=i(dn()),a={set:o.setInterval,clear:o.clearInterval},u={set:(e,t)=>setInterval(e,t),clear:e=>clearInterval(e)};e.default=e=>{switch(e){case"native":return u;case"worker":return a;default:return!s.default||s.isWebWorker||s.isReactNativeBrowser?u:a}}}),yn=o(e=>{l(),tt(),Fe();var t=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0});var r=t(gn());e.default=class{_keepalive;timerId;timer;destroyed=!1;counter;client;_keepaliveTimeoutTimestamp;_intervalEvery;get keepaliveTimeoutTimestamp(){return this._keepaliveTimeoutTimestamp}get intervalEvery(){return this._intervalEvery}get keepalive(){return this._keepalive}constructor(e,t){this.client=e,this.timer="object"==typeof t&&"set"in t&&"clear"in t?t:(0,r.default)(t),this.setKeepalive(e.options.keepalive)}clear(){this.timerId&&(this.timer.clear(this.timerId),this.timerId=null)}setKeepalive(e){if(e*=1e3,isNaN(e)||e<=0||e>2147483647)throw new Error(`Keepalive value must be an integer between 0 and 2147483647. Provided value is ${e}`);this._keepalive=e,this.reschedule(),this.client.log(`KeepaliveManager: set keepalive to ${e}ms`)}destroy(){this.clear(),this.destroyed=!0}reschedule(){if(this.destroyed)return;this.clear(),this.counter=0;let e=Math.ceil(1.5*this._keepalive);this._keepaliveTimeoutTimestamp=Date.now()+e,this._intervalEvery=Math.ceil(this._keepalive/2),this.timerId=this.timer.set(()=>{this.destroyed||(this.counter+=1,2===this.counter?this.client.sendPing():this.counter>2&&this.client.onKeepaliveTimeout())},this._intervalEvery)}}}),mn=o(e=>{l(),tt(),Fe();var t,r=e&&e.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);(!i||("get"in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),n=e&&e.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=e&&e.__importStar||(t=function(e){return(t=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t})(e)},function(e){if(e&&e.__esModule)return e;var i={};if(null!=e)for(var o=t(e),s=0;s<o.length;s++)"default"!==o[s]&&r(i,e,o[s]);return n(i,e),i}),o=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0});var s=o(rr()),a=$t(),u=o(ir()),c=o(Yt()),h=i(or()),f=o(sr()),p=o(jr()),d=o(Ur()),g=o(Fr()),y=ur(),m=Wr(),b=o(yn()),v=i(dn()),w=globalThis.setImmediate||((...e)=>{let t=e.shift();(0,y.nextTick)(()=>{t(...e)})}),_={keepalive:60,reschedulePings:!0,protocolId:"MQTT",protocolVersion:4,reconnectPeriod:1e3,connectTimeout:3e4,clean:!0,resubscribe:!0,subscribeBatchSize:null,writeCache:!0,timerVariant:"auto"},E=class e extends m.TypedEventEmitter{static VERSION=y.MQTTJS_VERSION;connected;disconnecting;disconnected;reconnecting;incomingStore;outgoingStore;options;queueQoSZero;_reconnectCount;log;messageIdProvider;outgoing;messageIdToTopic;noop;keepaliveManager;stream;queue;streamBuilder;_resubscribeTopics;connackTimer;reconnectTimer;_storeProcessing;_packetIdsDuringStoreProcessing;_storeProcessingQueue;_firstConnection;topicAliasRecv;topicAliasSend;_deferredReconnect;connackPacket;static defaultId(){return`mqttjs_${Math.random().toString(16).substr(2,8)}`}constructor(t,r){super(),this.options=r||{};for(let e in _)typeof this.options[e]>"u"?this.options[e]=_[e]:this.options[e]=r[e];this.log=this.options.log||(0,c.default)("mqttjs:client"),this.noop=this._noop.bind(this),this.log("MqttClient :: version:",e.VERSION),v.isWebWorker?this.log("MqttClient :: environment","webworker"):this.log("MqttClient :: environment",v.default?"browser":"node"),this.log("MqttClient :: options.protocol",r.protocol),this.log("MqttClient :: options.protocolVersion",r.protocolVersion),this.log("MqttClient :: options.username",r.username),this.log("MqttClient :: options.keepalive",r.keepalive),this.log("MqttClient :: options.reconnectPeriod",r.reconnectPeriod),this.log("MqttClient :: options.rejectUnauthorized",r.rejectUnauthorized),this.log("MqttClient :: options.properties.topicAliasMaximum",r.properties?r.properties.topicAliasMaximum:void 0),this.options.clientId="string"==typeof r.clientId?r.clientId:e.defaultId(),this.log("MqttClient :: clientId",this.options.clientId),this.options.customHandleAcks=5===r.protocolVersion&&r.customHandleAcks?r.customHandleAcks:(...e)=>{e[3](null,0)},this.options.writeCache||(s.default.writeToStream.cacheNumbers=!1),this.streamBuilder=t,this.messageIdProvider=typeof this.options.messageIdProvider>"u"?new d.default:this.options.messageIdProvider,this.outgoingStore=r.outgoingStore||new f.default,this.incomingStore=r.incomingStore||new f.default,this.queueQoSZero=void 0===r.queueQoSZero||r.queueQoSZero,this._resubscribeTopics={},this.messageIdToTopic={},this.keepaliveManager=null,this.connected=!1,this.disconnecting=!1,this.reconnecting=!1,this.queue=[],this.connackTimer=null,this.reconnectTimer=null,this._storeProcessing=!1,this._packetIdsDuringStoreProcessing={},this._storeProcessingQueue=[],this.outgoing={},this._firstConnection=!0,r.properties&&r.properties.topicAliasMaximum>0&&(r.properties.topicAliasMaximum>65535?this.log("MqttClient :: options.properties.topicAliasMaximum is out of range"):this.topicAliasRecv=new g.default(r.properties.topicAliasMaximum)),this.on("connect",()=>{let{queue:e}=this,t=()=>{let r=e.shift();this.log("deliver :: entry %o",r);let n=null;if(!r)return void this._resubscribe();n=r.packet,this.log("deliver :: call _sendPacket for %o",n);let i=!0;n.messageId&&0!==n.messageId&&(this.messageIdProvider.register(n.messageId)||(i=!1)),i?this._sendPacket(n,e=>{r.cb&&r.cb(e),t()}):(this.log("messageId: %d has already used. The message is skipped and removed.",n.messageId),t())};this.log("connect :: sending queued packets"),t()}),this.on("close",()=>{this.log("close :: connected set to `false`"),this.connected=!1,this.log("close :: clearing connackTimer"),clearTimeout(this.connackTimer),this._destroyKeepaliveManager(),this.topicAliasRecv&&this.topicAliasRecv.clear(),this.log("close :: calling _setupReconnect"),this._setupReconnect()}),this.options.manualConnect||(this.log("MqttClient :: setting up stream"),this.connect())}handleAuth(e,t){t()}handleMessage(e,t){t()}_nextId(){return this.messageIdProvider.allocate()}getLastMessageId(){return this.messageIdProvider.getLastAllocated()}connect(){let e=new a.Writable,t=s.default.parser(this.options),r=null,n=[];this.log("connect :: calling method to clear reconnect"),this._clearReconnect(),this.disconnected&&!this.reconnecting&&(this.incomingStore=this.options.incomingStore||new f.default,this.outgoingStore=this.options.outgoingStore||new f.default,this.disconnecting=!1,this.disconnected=!1),this.log("connect :: using streamBuilder provided to client to create stream"),this.stream=this.streamBuilder(this),t.on("packet",e=>{this.log("parser :: on packet push to packets array."),n.push(e)});let i=()=>{this.log("work :: getting next packet in queue");let e=n.shift();if(e)this.log("work :: packet pulled from queue"),(0,p.default)(this,e,o);else{this.log("work :: no packets in queue");let e=r;r=null,this.log("work :: done flag is %s",!!e),e&&e()}},o=()=>{if(n.length)(0,y.nextTick)(i);else{let e=r;r=null,e()}};e._write=(e,n,o)=>{r=o,this.log("writable stream :: parsing buffer"),t.parse(e),i()};this.log("connect :: pipe stream to writable stream"),this.stream.pipe(e),this.stream.on("error",e=>{this.log("streamErrorHandler :: error",e.message),e.code?(this.log("streamErrorHandler :: emitting error"),this.emit("error",e)):this.noop(e)}),this.stream.on("close",()=>{this.log("(%s)stream :: on close",this.options.clientId),this._flushVolatile(),this.log("stream: emit close to MqttClient"),this.emit("close")}),this.log("connect: sending packet `connect`");let l={cmd:"connect",protocolId:this.options.protocolId,protocolVersion:this.options.protocolVersion,clean:this.options.clean,clientId:this.options.clientId,keepalive:this.options.keepalive,username:this.options.username,password:this.options.password,properties:this.options.properties};if(this.options.will&&(l.will={...this.options.will,payload:this.options.will?.payload}),this.topicAliasRecv&&(l.properties||(l.properties={}),this.topicAliasRecv&&(l.properties.topicAliasMaximum=this.topicAliasRecv.max)),this._writePacket(l),t.on("error",this.emit.bind(this,"error")),this.options.properties){if(!this.options.properties.authenticationMethod&&this.options.properties.authenticationData)return this.end(()=>this.emit("error",new Error("Packet has no Authentication Method"))),this;if(this.options.properties.authenticationMethod&&this.options.authPacket&&"object"==typeof this.options.authPacket){let e={cmd:"auth",reasonCode:0,...this.options.authPacket};this._writePacket(e)}}return this.stream.setMaxListeners(1e3),clearTimeout(this.connackTimer),this.connackTimer=setTimeout(()=>{this.log("!!connectTimeout hit!! Calling _cleanUp with force `true`"),this.emit("error",new Error("connack timeout")),this._cleanUp(!0)},this.options.connectTimeout),this}publish(e,t,r,n){this.log("publish :: message `%s` to topic `%s`",t,e);let{options:i}=this;"function"==typeof r&&(n=r,r=null),r=r||{},r={qos:0,retain:!1,dup:!1,...r};let{qos:o,retain:s,dup:a,properties:l,cbStorePut:u}=r;if(this._checkDisconnecting(n))return this;let c=()=>{let r=0;if((1===o||2===o)&&(r=this._nextId(),null===r))return this.log("No messageId left"),!1;let c={cmd:"publish",topic:e,payload:t,qos:o,retain:s,messageId:r,dup:a};switch(5===i.protocolVersion&&(c.properties=l),this.log("publish :: qos",o),o){case 1:case 2:this.outgoing[c.messageId]={volatile:!1,cb:n||this.noop},this.log("MqttClient:publish: packet cmd: %s",c.cmd),this._sendPacket(c,void 0,u);break;default:this.log("MqttClient:publish: packet cmd: %s",c.cmd),this._sendPacket(c,n,u)}return!0};return(this._storeProcessing||this._storeProcessingQueue.length>0||!c())&&this._storeProcessingQueue.push({invoke:c,cbStorePut:r.cbStorePut,callback:n}),this}publishAsync(e,t,r){return new Promise((n,i)=>{this.publish(e,t,r,(e,t)=>{e?i(e):n(t)})})}subscribe(e,t,r){let n=this.options.protocolVersion;"function"==typeof t&&(r=t),r=r||this.noop;let i=!1,o=[];"string"==typeof e?o=e=[e]:Array.isArray(e)?o=e:"object"==typeof e&&(i=e.resubscribe,delete e.resubscribe,o=Object.keys(e));let s=h.validateTopics(o);if(null!==s)return w(r,new Error(`Invalid topic ${s}`)),this;if(this._checkDisconnecting(r))return this.log("subscribe: discconecting true"),this;let a={qos:0};5===n&&(a.nl=!1,a.rap=!1,a.rh=0),t={...a,...t};let{properties:l}=t,u=[],c=(e,r)=>{if(r=r||t,!Object.prototype.hasOwnProperty.call(this._resubscribeTopics,e)||this._resubscribeTopics[e].qos<r.qos||i){let t={topic:e,qos:r.qos};5===n&&(t.nl=r.nl,t.rap=r.rap,t.rh=r.rh,t.properties=l),this.log("subscribe: pushing topic `%s` and qos `%s` to subs list",t.topic,t.qos),u.push(t)}};if(Array.isArray(e)?e.forEach(e=>{this.log("subscribe: array topic %s",e),c(e)}):Object.keys(e).forEach(t=>{this.log("subscribe: object topic %s, %o",t,e[t]),c(t,e[t])}),!u.length)return r(null,[]),this;let f=(e,t)=>{let r={cmd:"subscribe",subscriptions:e,messageId:t};if(l&&(r.properties=l),this.options.resubscribe){this.log("subscribe :: resubscribe true");let t=[];e.forEach(e=>{if(this.options.reconnectPeriod>0){let r={qos:e.qos};5===n&&(r.nl=e.nl||!1,r.rap=e.rap||!1,r.rh=e.rh||0,r.properties=e.properties),this._resubscribeTopics[e.topic]=r,t.push(e.topic)}}),this.messageIdToTopic[r.messageId]=t}let i=new Promise((t,n)=>{this.outgoing[r.messageId]={volatile:!0,cb(r,i){if(!r){let{granted:t}=i;for(let r=0;r<t.length;r+=1)e[r].qos=t[r]}r?n(new y.ErrorWithSubackPacket(r.message,i)):t(i)}}});return this.log("subscribe :: call _sendPacket"),this._sendPacket(r),i},p=()=>{let e=this.options.subscribeBatchSize??u.length,t=[];for(let r=0;r<u.length;r+=e){let n=u.slice(r,r+e),i=this._nextId();if(null===i)return this.log("No messageId left"),!1;t.push(f(n,i))}return Promise.all(t).then(e=>{r(null,u,e.at(-1))}).catch(e=>{r(e,u,e.packet)}),!0};return(this._storeProcessing||this._storeProcessingQueue.length>0||!p())&&this._storeProcessingQueue.push({invoke:p,callback:r}),this}subscribeAsync(e,t){return new Promise((r,n)=>{this.subscribe(e,t,(e,t)=>{e?n(e):r(t)})})}unsubscribe(e,t,r){"string"==typeof e&&(e=[e]),"function"==typeof t&&(r=t),r=r||this.noop;let n=h.validateTopics(e);if(null!==n)return w(r,new Error(`Invalid topic ${n}`)),this;if(this._checkDisconnecting(r))return this;let i=()=>{let n=this._nextId();if(null===n)return this.log("No messageId left"),!1;let i={cmd:"unsubscribe",messageId:n,unsubscriptions:[]};return"string"==typeof e?i.unsubscriptions=[e]:Array.isArray(e)&&(i.unsubscriptions=e),this.options.resubscribe&&i.unsubscriptions.forEach(e=>{delete this._resubscribeTopics[e]}),"object"==typeof t&&t.properties&&(i.properties=t.properties),this.outgoing[i.messageId]={volatile:!0,cb:r},this.log("unsubscribe: call _sendPacket"),this._sendPacket(i),!0};return(this._storeProcessing||this._storeProcessingQueue.length>0||!i())&&this._storeProcessingQueue.push({invoke:i,callback:r}),this}unsubscribeAsync(e,t){return new Promise((r,n)=>{this.unsubscribe(e,t,(e,t)=>{e?n(e):r(t)})})}end(e,t,r){this.log("end :: (%s)",this.options.clientId),(null==e||"boolean"!=typeof e)&&(r=r||t,t=e,e=!1),"object"!=typeof t&&(r=r||t,t=null),this.log("end :: cb? %s",!!r),(!r||"function"!=typeof r)&&(r=this.noop);let n=()=>{this.log("end :: closeStores: closing incoming and outgoing stores"),this.disconnected=!0,this.incomingStore.close(e=>{this.outgoingStore.close(t=>{if(this.log("end :: closeStores: emitting end"),this.emit("end"),r){let n=e||t;this.log("end :: closeStores: invoking callback with args"),r(n)}})}),this._deferredReconnect?this._deferredReconnect():(0===this.options.reconnectPeriod||this.options.manualConnect)&&(this.disconnecting=!1)},i=()=>{this.log("end :: (%s) :: finish :: calling _cleanUp with force %s",this.options.clientId,e),this._cleanUp(e,()=>{this.log("end :: finish :: calling process.nextTick on closeStores"),(0,y.nextTick)(n)},t)};return this.disconnecting?(r(),this):(this._clearReconnect(),this.disconnecting=!0,!e&&Object.keys(this.outgoing).length>0?(this.log("end :: (%s) :: calling finish in 10ms once outgoing is empty",this.options.clientId),this.once("outgoingEmpty",setTimeout.bind(null,i,10))):(this.log("end :: (%s) :: immediately calling finish",this.options.clientId),i()),this)}endAsync(e,t){return new Promise((r,n)=>{this.end(e,t,e=>{e?n(e):r()})})}removeOutgoingMessage(e){if(this.outgoing[e]){let{cb:t}=this.outgoing[e];this._removeOutgoingAndStoreMessage(e,()=>{t(new Error("Message removed"))})}return this}reconnect(e){this.log("client reconnect");let t=()=>{e?(this.options.incomingStore=e.incomingStore,this.options.outgoingStore=e.outgoingStore):(this.options.incomingStore=null,this.options.outgoingStore=null),this.incomingStore=this.options.incomingStore||new f.default,this.outgoingStore=this.options.outgoingStore||new f.default,this.disconnecting=!1,this.disconnected=!1,this._deferredReconnect=null,this._reconnect()};return this.disconnecting&&!this.disconnected?this._deferredReconnect=t:t(),this}_flushVolatile(){this.outgoing&&(this.log("_flushVolatile :: deleting volatile messages from the queue and setting their callbacks as error function"),Object.keys(this.outgoing).forEach(e=>{this.outgoing[e].volatile&&"function"==typeof this.outgoing[e].cb&&(this.outgoing[e].cb(new Error("Connection closed")),delete this.outgoing[e])}))}_flush(){this.outgoing&&(this.log("_flush: queue exists? %b",!!this.outgoing),Object.keys(this.outgoing).forEach(e=>{"function"==typeof this.outgoing[e].cb&&(this.outgoing[e].cb(new Error("Connection closed")),delete this.outgoing[e])}))}_removeTopicAliasAndRecoverTopicName(e){let t;e.properties&&(t=e.properties.topicAlias);let r=e.topic.toString();if(this.log("_removeTopicAliasAndRecoverTopicName :: alias %d, topic %o",t,r),0===r.length){if(typeof t>"u")return new Error("Unregistered Topic Alias");if(r=this.topicAliasSend.getTopicByAlias(t),typeof r>"u")return new Error("Unregistered Topic Alias");e.topic=r}t&&delete e.properties.topicAlias}_checkDisconnecting(e){return this.disconnecting&&(e&&e!==this.noop?e(new Error("client disconnecting")):this.emit("error",new Error("client disconnecting"))),this.disconnecting}_reconnect(){this.log("_reconnect: emitting reconnect to client"),this.emit("reconnect"),this.connected?(this.end(()=>{this.connect()}),this.log("client already connected. disconnecting first.")):(this.log("_reconnect: calling connect"),this.connect())}_setupReconnect(){!this.disconnecting&&!this.reconnectTimer&&this.options.reconnectPeriod>0?(this.reconnecting||(this.log("_setupReconnect :: emit `offline` state"),this.emit("offline"),this.log("_setupReconnect :: set `reconnecting` to `true`"),this.reconnecting=!0),this.log("_setupReconnect :: setting reconnectTimer for %d ms",this.options.reconnectPeriod),this.reconnectTimer=setInterval(()=>{this.log("reconnectTimer :: reconnect triggered!"),this._reconnect()},this.options.reconnectPeriod)):this.log("_setupReconnect :: doing nothing...")}_clearReconnect(){this.log("_clearReconnect : clearing reconnect timer"),this.reconnectTimer&&(clearInterval(this.reconnectTimer),this.reconnectTimer=null)}_cleanUp(e,t,r={}){if(t&&(this.log("_cleanUp :: done callback provided for on stream close"),this.stream.on("close",t)),this.log("_cleanUp :: forced? %s",e),e)0===this.options.reconnectPeriod&&this.options.clean&&this._flush(),this.log("_cleanUp :: (%s) :: destroying stream",this.options.clientId),this.stream.destroy();else{let e={cmd:"disconnect",...r};this.log("_cleanUp :: (%s) :: call _sendPacket with disconnect packet",this.options.clientId),this._sendPacket(e,()=>{this.log("_cleanUp :: (%s) :: destroying stream",this.options.clientId),w(()=>{this.stream.end(()=>{this.log("_cleanUp :: (%s) :: stream destroyed",this.options.clientId)})})})}!this.disconnecting&&!this.reconnecting&&(this.log("_cleanUp :: client not disconnecting/reconnecting. Clearing and resetting reconnect."),this._clearReconnect(),this._setupReconnect()),this._destroyKeepaliveManager(),t&&!this.connected&&(this.log("_cleanUp :: (%s) :: removing stream `done` callback `close` listener",this.options.clientId),this.stream.removeListener("close",t),t())}_storeAndSend(e,t,r){this.log("storeAndSend :: store packet with cmd %s to outgoingStore",e.cmd);let n,i=e;if("publish"===i.cmd&&(i=(0,u.default)(e),n=this._removeTopicAliasAndRecoverTopicName(i),n))return t&&t(n);this.outgoingStore.put(i,n=>{if(n)return t&&t(n);r(),this._writePacket(e,t)})}_applyTopicAlias(e){if(5===this.options.protocolVersion&&"publish"===e.cmd){let t;e.properties&&(t=e.properties.topicAlias);let r=e.topic.toString();if(this.topicAliasSend)if(t){if(0!==r.length&&(this.log("applyTopicAlias :: register topic: %s - alias: %d",r,t),!this.topicAliasSend.put(r,t)))return this.log("applyTopicAlias :: error out of range. topic: %s - alias: %d",r,t),new Error("Sending Topic Alias out of range")}else 0!==r.length&&(this.options.autoAssignTopicAlias?(t=this.topicAliasSend.getAliasByTopic(r),t?(e.topic="",e.properties={...e.properties,topicAlias:t},this.log("applyTopicAlias :: auto assign(use) topic: %s - alias: %d",r,t)):(t=this.topicAliasSend.getLruAlias(),this.topicAliasSend.put(r,t),e.properties={...e.properties,topicAlias:t},this.log("applyTopicAlias :: auto assign topic: %s - alias: %d",r,t))):this.options.autoUseTopicAlias&&(t=this.topicAliasSend.getAliasByTopic(r),t&&(e.topic="",e.properties={...e.properties,topicAlias:t},this.log("applyTopicAlias :: auto use topic: %s - alias: %d",r,t))));else if(t)return this.log("applyTopicAlias :: error out of range. topic: %s - alias: %d",r,t),new Error("Sending Topic Alias out of range")}}_noop(e){this.log("noop ::",e)}_writePacket(e,t){this.log("_writePacket :: packet: %O",e),this.log("_writePacket :: emitting `packetsend`"),this.emit("packetsend",e),this.log("_writePacket :: writing to stream");let r=s.default.writeToStream(e,this.stream,this.options);this.log("_writePacket :: writeToStream result %s",r),!r&&t&&t!==this.noop?(this.log("_writePacket :: handle events on `drain` once through callback."),this.stream.once("drain",t)):t&&(this.log("_writePacket :: invoking cb"),t())}_sendPacket(e,t,r,n){this.log("_sendPacket :: (%s) :: start",this.options.clientId),r=r||this.noop,t=t||this.noop;let i=this._applyTopicAlias(e);if(i)t(i);else{if(!this.connected)return"auth"===e.cmd?void this._writePacket(e,t):(this.log("_sendPacket :: client not connected. Storing packet offline."),void this._storePacket(e,t,r));if(n)this._writePacket(e,t);else{switch(e.cmd){case"publish":break;case"pubrel":return void this._storeAndSend(e,t,r);default:return void this._writePacket(e,t)}switch(e.qos){case 2:case 1:this._storeAndSend(e,t,r);break;default:this._writePacket(e,t)}this.log("_sendPacket :: (%s) :: end",this.options.clientId)}}}_storePacket(e,t,r){this.log("_storePacket :: packet: %o",e),this.log("_storePacket :: cb? %s",!!t),r=r||this.noop;let n=e;if("publish"===n.cmd){n=(0,u.default)(e);let r=this._removeTopicAliasAndRecoverTopicName(n);if(r)return t&&t(r)}let i=n.qos||0;0===i&&this.queueQoSZero||"publish"!==n.cmd?this.queue.push({packet:n,cb:t}):i>0?(t=this.outgoing[n.messageId]?this.outgoing[n.messageId].cb:null,this.outgoingStore.put(n,e=>{if(e)return t&&t(e);r()})):t&&t(new Error("No connection to broker"))}_setupKeepaliveManager(){this.log("_setupKeepaliveManager :: keepalive %d (seconds)",this.options.keepalive),!this.keepaliveManager&&this.options.keepalive&&(this.keepaliveManager=new b.default(this,this.options.timerVariant))}_destroyKeepaliveManager(){this.keepaliveManager&&(this.log("_destroyKeepaliveManager :: destroying keepalive manager"),this.keepaliveManager.destroy(),this.keepaliveManager=null)}reschedulePing(e=!1){this.keepaliveManager&&this.options.keepalive&&(e||this.options.reschedulePings)&&this._reschedulePing()}_reschedulePing(){this.log("_reschedulePing :: rescheduling ping"),this.keepaliveManager.reschedule()}sendPing(){this.log("_sendPing :: sending pingreq"),this._sendPacket({cmd:"pingreq"})}onKeepaliveTimeout(){this.emit("error",new Error("Keepalive timeout")),this.log("onKeepaliveTimeout :: calling _cleanUp with force true"),this._cleanUp(!0)}_resubscribe(){this.log("_resubscribe");let e=Object.keys(this._resubscribeTopics);if(!this._firstConnection&&(this.options.clean||this.options.protocolVersion>=4&&!this.connackPacket.sessionPresent)&&e.length>0)if(this.options.resubscribe)if(5===this.options.protocolVersion){this.log("_resubscribe: protocolVersion 5");for(let t=0;t<e.length;t++){let r={};r[e[t]]=this._resubscribeTopics[e[t]],r.resubscribe=!0,this.subscribe(r,{properties:r[e[t]].properties})}}else this._resubscribeTopics.resubscribe=!0,this.subscribe(this._resubscribeTopics);else this._resubscribeTopics={};this._firstConnection=!1}_onConnect(e){if(this.disconnected)return void this.emit("connect",e);this.connackPacket=e,this.messageIdProvider.clear(),this._setupKeepaliveManager(),this.connected=!0;let t=()=>{let r=this.outgoingStore.createStream(),n=()=>{r.destroy(),r=null,this._flushStoreProcessingQueue(),i()},i=()=>{this._storeProcessing=!1,this._packetIdsDuringStoreProcessing={}};this.once("close",n),r.on("error",e=>{i(),this._flushStoreProcessingQueue(),this.removeListener("close",n),this.emit("error",e)});let o=()=>{if(!r)return;let e,t=r.read(1);t?(this._storeProcessing=!0,this._packetIdsDuringStoreProcessing[t.messageId]?o():this.disconnecting||this.reconnectTimer?r.destroy&&r.destroy():(e=this.outgoing[t.messageId]?this.outgoing[t.messageId].cb:null,this.outgoing[t.messageId]={volatile:!1,cb(t,r){e&&e(t,r),o()}},this._packetIdsDuringStoreProcessing[t.messageId]=!0,this.messageIdProvider.register(t.messageId)?this._sendPacket(t,void 0,void 0,!0):this.log("messageId: %d has already used.",t.messageId))):r.once("readable",o)};r.on("end",()=>{let r=!0;for(let e in this._packetIdsDuringStoreProcessing)if(!this._packetIdsDuringStoreProcessing[e]){r=!1;break}this.removeListener("close",n),r?(i(),this._invokeAllStoreProcessingQueue(),this.emit("connect",e)):t()}),o()};t()}_invokeStoreProcessingQueue(){if(!this._storeProcessing&&this._storeProcessingQueue.length>0){let e=this._storeProcessingQueue[0];if(e&&e.invoke())return this._storeProcessingQueue.shift(),!0}return!1}_invokeAllStoreProcessingQueue(){for(;this._invokeStoreProcessingQueue(););}_flushStoreProcessingQueue(){for(let e of this._storeProcessingQueue)e.cbStorePut&&e.cbStorePut(new Error("Connection closed")),e.callback&&e.callback(new Error("Connection closed"));this._storeProcessingQueue.splice(0)}_removeOutgoingAndStoreMessage(e,t){delete this.outgoing[e],this.outgoingStore.del({messageId:e},(r,n)=>{t(r,n),this.messageIdProvider.deallocate(e),this._invokeStoreProcessingQueue()})}};e.default=E}),bn=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"__esModule",{value:!0});var t=Lr();e.default=class{numberAllocator;lastId;constructor(){this.numberAllocator=new t.NumberAllocator(1,65535)}allocate(){return this.lastId=this.numberAllocator.alloc(),this.lastId}getLastAllocated(){return this.lastId}register(e){return this.numberAllocator.use(e)}deallocate(e){this.numberAllocator.free(e)}clear(){this.numberAllocator.clear()}}});var vn,wn,_n,En=i(()=>{l(),tt(),Fe(),vn={},wn=!1,(_n=function(){if(wn)return vn;wn=!0;let e=2147483647,t=36,r=/^xn--/,n=/[^\0-\x7F]/,i=/[\x2E\u3002\uFF0E\uFF61]/g,o={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},s=Math.floor,a=String.fromCharCode;function l(e){throw new RangeError(o[e])}function u(e,t){let r=e.split("@"),n="";r.length>1&&(n=r[0]+"@",e=r[1]);let o=function(e,t){let r=[],n=e.length;for(;n--;)r[n]=t(e[n]);return r}((e=e.replace(i,".")).split("."),t).join(".");return n+o}function c(e){let t=[],r=0,n=e.length;for(;r<n;){let i=e.charCodeAt(r++);if(i>=55296&&i<=56319&&r<n){let n=e.charCodeAt(r++);56320==(64512&n)?t.push(((1023&i)<<10)+(1023&n)+65536):(t.push(i),r--)}else t.push(i)}return t}let h=function(e){return e>=48&&e<58?e-48+26:e>=65&&e<91?e-65:e>=97&&e<123?e-97:t},f=function(e,t){return e+22+75*(e<26)-((0!=t)<<5)},p=function(e,r,n){let i=0;for(e=n?s(e/700):e>>1,e+=s(e/r);e>455;i+=t)e=s(e/35);return s(i+36*e/(e+38))},d=function(r){let n=[],i=r.length,o=0,a=128,u=72,c=r.lastIndexOf("-");c<0&&(c=0);for(let e=0;e<c;++e)r.charCodeAt(e)>=128&&l("not-basic"),n.push(r.charCodeAt(e));for(let f=c>0?c+1:0;f<i;){let c=o;for(let n=1,a=t;;a+=t){f>=i&&l("invalid-input");let c=h(r.charCodeAt(f++));c>=t&&l("invalid-input"),c>s((e-o)/n)&&l("overflow"),o+=c*n;let p=a<=u?1:a>=u+26?26:a-u;if(c<p)break;let d=t-p;n>s(e/d)&&l("overflow"),n*=d}let d=n.length+1;u=p(o-c,d,0==c),s(o/d)>e-a&&l("overflow"),a+=s(o/d),o%=d,n.splice(o++,0,a)}return String.fromCodePoint(...n)},g=function(r){let n=[],i=(r=c(r)).length,o=128,u=0,h=72;for(let e of r)e<128&&n.push(a(e));let d=n.length,g=d;for(d&&n.push("-");g<i;){let i=e;for(let e of r)e>=o&&e<i&&(i=e);let c=g+1;i-o>s((e-u)/c)&&l("overflow"),u+=(i-o)*c,o=i;for(let i of r)if(i<o&&++u>e&&l("overflow"),i===o){let e=u;for(let r=t;;r+=t){let i=r<=h?1:r>=h+26?26:r-h;if(e<i)break;let o=e-i,l=t-i;n.push(a(f(i+o%l,0))),e=s(o/l)}n.push(a(f(e,0))),h=p(u,c,g===d),u=0,++g}++u,++o}return n.join("")};return vn={version:"2.3.1",ucs2:{decode:c,encode:e=>String.fromCodePoint(...e)},decode:d,encode:g,toASCII:function(e){return u(e,function(e){return n.test(e)?"xn--"+g(e):e})},toUnicode:function(e){return u(e,function(e){return r.test(e)?d(e.slice(4).toLowerCase()):e})}}}()).decode,_n.encode,_n.toASCII,_n.toUnicode,_n.ucs2,_n.version});function Sn(){return qn||(qn=!0,$n=SyntaxError),$n}function In(){return Vn||(Vn=!0,Gn=TypeError),Gn}function An(){if(Qn)return zn;Qn=!0;var e=typeof Symbol<"u"&&Symbol,t=(Nn||(Nn=!0,Pn=function(){if("function"!=typeof Symbol||"function"!=typeof Object.getOwnPropertySymbols)return!1;if("symbol"==typeof Symbol.iterator)return!0;var e={},t=Symbol("test"),r=Object(t);if("string"==typeof t||"[object Symbol]"!==Object.prototype.toString.call(t)||"[object Symbol]"!==Object.prototype.toString.call(r))return!1;for(t in e[t]=42,e)return!1;if("function"==typeof Object.keys&&0!==Object.keys(e).length||"function"==typeof Object.getOwnPropertyNames&&0!==Object.getOwnPropertyNames(e).length)return!1;var n=Object.getOwnPropertySymbols(e);if(1!==n.length||n[0]!==t||!Object.prototype.propertyIsEnumerable.call(e,t))return!1;if("function"==typeof Object.getOwnPropertyDescriptor){var i=Object.getOwnPropertyDescriptor(e,t);if(42!==i.value||!0!==i.enumerable)return!1}return!0}),Pn);return zn=function(){return"function"==typeof e&&"function"==typeof Symbol&&"symbol"==typeof e("foo")&&"symbol"==typeof Symbol("bar")&&t()}}function Rn(){if(ti)return ei;ti=!0;var e=function(){if(Zn)return Xn;Zn=!0;var e=Object.prototype.toString,t=Math.max,r=function(e,t){for(var r=[],n=0;n<e.length;n+=1)r[n]=e[n];for(var i=0;i<t.length;i+=1)r[i+e.length]=t[i];return r};return Xn=function(n){var i=this;if("function"!=typeof i||"[object Function]"!==e.apply(i))throw new TypeError("Function.prototype.bind called on incompatible "+i);for(var o,s=function(e){for(var t=[],r=1,n=0;r<e.length;r+=1,n+=1)t[n]=e[r];return t}(arguments),a=t(0,i.length-s.length),l=[],u=0;u<a;u++)l[u]="$"+u;if(o=Function("binder","return function ("+function(e,t){for(var r="",n=0;n<e.length;n+=1)r+=e[n],n+1<e.length&&(r+=t);return r}(l,",")+"){ return binder.apply(this,arguments); }")(function(){if(this instanceof o){var e=i.apply(this,r(s,arguments));return Object(e)===e?e:this}return i.apply(n,r(s,arguments))}),i.prototype){var c=function(){};c.prototype=i.prototype,o.prototype=new c,c.prototype=null}return o},Xn}();return ei=Function.prototype.bind||e}function On(){if(oi)return ii;oi=!0;var e,t=(Mn||(Mn=!0,Ln=Error),Ln),r=(Dn||(Dn=!0,Bn=EvalError),Bn),n=(Un||(Un=!0,jn=RangeError),jn),i=(Wn||(Wn=!0,Fn=ReferenceError),Fn),o=Sn(),s=In(),a=(Kn||(Kn=!0,Hn=URIError),Hn),l=Function,u=function(e){try{return l('"use strict"; return ('+e+").constructor;")()}catch{}},c=Object.getOwnPropertyDescriptor;if(c)try{c({},"")}catch{c=null}var h=function(){throw new s},f=c?function(){try{return h}catch{try{return c(arguments,"callee").get}catch{return h}}}():h,p=An()(),d=function(){if(Jn)return Yn;Jn=!0;var e={__proto__:null,foo:{}},t=Object;return Yn=function(){return{__proto__:e}.foo===e.foo&&!(e instanceof t)}}()(),g=Object.getPrototypeOf||(d?function(e){return e.__proto__}:null),y={},m=typeof Uint8Array>"u"||!g?e:g(Uint8Array),b={__proto__:null,"%AggregateError%":typeof AggregateError>"u"?e:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?e:ArrayBuffer,"%ArrayIteratorPrototype%":p&&g?g([][Symbol.iterator]()):e,"%AsyncFromSyncIteratorPrototype%":e,"%AsyncFunction%":y,"%AsyncGenerator%":y,"%AsyncGeneratorFunction%":y,"%AsyncIteratorPrototype%":y,"%Atomics%":typeof Atomics>"u"?e:Atomics,"%BigInt%":typeof BigInt>"u"?e:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?e:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?e:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?e:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":t,"%eval%":eval,"%EvalError%":r,"%Float32Array%":typeof Float32Array>"u"?e:Float32Array,"%Float64Array%":typeof Float64Array>"u"?e:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?e:FinalizationRegistry,"%Function%":l,"%GeneratorFunction%":y,"%Int8Array%":typeof Int8Array>"u"?e:Int8Array,"%Int16Array%":typeof Int16Array>"u"?e:Int16Array,"%Int32Array%":typeof Int32Array>"u"?e:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":p&&g?g(g([][Symbol.iterator]())):e,"%JSON%":"object"==typeof JSON?JSON:e,"%Map%":typeof Map>"u"?e:Map,"%MapIteratorPrototype%":typeof Map>"u"||!p||!g?e:g((new Map)[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":Object,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?e:Promise,"%Proxy%":typeof Proxy>"u"?e:Proxy,"%RangeError%":n,"%ReferenceError%":i,"%Reflect%":typeof Reflect>"u"?e:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?e:Set,"%SetIteratorPrototype%":typeof Set>"u"||!p||!g?e:g((new Set)[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?e:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":p&&g?g(""[Symbol.iterator]()):e,"%Symbol%":p?Symbol:e,"%SyntaxError%":o,"%ThrowTypeError%":f,"%TypedArray%":m,"%TypeError%":s,"%Uint8Array%":typeof Uint8Array>"u"?e:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?e:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?e:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?e:Uint32Array,"%URIError%":a,"%WeakMap%":typeof WeakMap>"u"?e:WeakMap,"%WeakRef%":typeof WeakRef>"u"?e:WeakRef,"%WeakSet%":typeof WeakSet>"u"?e:WeakSet};if(g)try{null.error}catch(e){var v=g(g(e));b["%Error.prototype%"]=v}var w=function e(t){var r;if("%AsyncFunction%"===t)r=u("async function () {}");else if("%GeneratorFunction%"===t)r=u("function* () {}");else if("%AsyncGeneratorFunction%"===t)r=u("async function* () {}");else if("%AsyncGenerator%"===t){var n=e("%AsyncGeneratorFunction%");n&&(r=n.prototype)}else if("%AsyncIteratorPrototype%"===t){var i=e("%AsyncGenerator%");i&&g&&(r=g(i.prototype))}return b[t]=r,r},_={__proto__:null,"%ArrayBufferPrototype%":["ArrayBuffer","prototype"],"%ArrayPrototype%":["Array","prototype"],"%ArrayProto_entries%":["Array","prototype","entries"],"%ArrayProto_forEach%":["Array","prototype","forEach"],"%ArrayProto_keys%":["Array","prototype","keys"],"%ArrayProto_values%":["Array","prototype","values"],"%AsyncFunctionPrototype%":["AsyncFunction","prototype"],"%AsyncGenerator%":["AsyncGeneratorFunction","prototype"],"%AsyncGeneratorPrototype%":["AsyncGeneratorFunction","prototype","prototype"],"%BooleanPrototype%":["Boolean","prototype"],"%DataViewPrototype%":["DataView","prototype"],"%DatePrototype%":["Date","prototype"],"%ErrorPrototype%":["Error","prototype"],"%EvalErrorPrototype%":["EvalError","prototype"],"%Float32ArrayPrototype%":["Float32Array","prototype"],"%Float64ArrayPrototype%":["Float64Array","prototype"],"%FunctionPrototype%":["Function","prototype"],"%Generator%":["GeneratorFunction","prototype"],"%GeneratorPrototype%":["GeneratorFunction","prototype","prototype"],"%Int8ArrayPrototype%":["Int8Array","prototype"],"%Int16ArrayPrototype%":["Int16Array","prototype"],"%Int32ArrayPrototype%":["Int32Array","prototype"],"%JSONParse%":["JSON","parse"],"%JSONStringify%":["JSON","stringify"],"%MapPrototype%":["Map","prototype"],"%NumberPrototype%":["Number","prototype"],"%ObjectPrototype%":["Object","prototype"],"%ObjProto_toString%":["Object","prototype","toString"],"%ObjProto_valueOf%":["Object","prototype","valueOf"],"%PromisePrototype%":["Promise","prototype"],"%PromiseProto_then%":["Promise","prototype","then"],"%Promise_all%":["Promise","all"],"%Promise_reject%":["Promise","reject"],"%Promise_resolve%":["Promise","resolve"],"%RangeErrorPrototype%":["RangeError","prototype"],"%ReferenceErrorPrototype%":["ReferenceError","prototype"],"%RegExpPrototype%":["RegExp","prototype"],"%SetPrototype%":["Set","prototype"],"%SharedArrayBufferPrototype%":["SharedArrayBuffer","prototype"],"%StringPrototype%":["String","prototype"],"%SymbolPrototype%":["Symbol","prototype"],"%SyntaxErrorPrototype%":["SyntaxError","prototype"],"%TypedArrayPrototype%":["TypedArray","prototype"],"%TypeErrorPrototype%":["TypeError","prototype"],"%Uint8ArrayPrototype%":["Uint8Array","prototype"],"%Uint8ClampedArrayPrototype%":["Uint8ClampedArray","prototype"],"%Uint16ArrayPrototype%":["Uint16Array","prototype"],"%Uint32ArrayPrototype%":["Uint32Array","prototype"],"%URIErrorPrototype%":["URIError","prototype"],"%WeakMapPrototype%":["WeakMap","prototype"],"%WeakSetPrototype%":["WeakSet","prototype"]},E=Rn(),S=function(){if(ni)return ri;ni=!0;var e=Function.prototype.call,t=Object.prototype.hasOwnProperty,r=Rn();return ri=r.call(e,t)}(),I=E.call(Function.call,Array.prototype.concat),A=E.call(Function.apply,Array.prototype.splice),R=E.call(Function.call,String.prototype.replace),O=E.call(Function.call,String.prototype.slice),k=E.call(Function.call,RegExp.prototype.exec),x=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,T=/\\(\\)?/g,C=function(e,t){var r,n=e;if(S(_,n)&&(n="%"+(r=_[n])[0]+"%"),S(b,n)){var i=b[n];if(i===y&&(i=w(n)),typeof i>"u"&&!t)throw new s("intrinsic "+e+" exists, but is not available. Please file an issue!");return{alias:r,name:n,value:i}}throw new o("intrinsic "+e+" does not exist!")};return ii=function(e,t){if("string"!=typeof e||0===e.length)throw new s("intrinsic name must be a non-empty string");if(arguments.length>1&&"boolean"!=typeof t)throw new s('"allowMissing" argument must be a boolean');if(null===k(/^%?[^%]*%?$/,e))throw new o("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var r=function(e){var t=O(e,0,1),r=O(e,-1);if("%"===t&&"%"!==r)throw new o("invalid intrinsic syntax, expected closing `%`");if("%"===r&&"%"!==t)throw new o("invalid intrinsic syntax, expected opening `%`");var n=[];return R(e,x,function(e,t,r,i){n[n.length]=r?R(i,T,"$1"):t||e}),n}(e),n=r.length>0?r[0]:"",i=C("%"+n+"%",t),a=i.name,l=i.value,u=!1,h=i.alias;h&&(n=h[0],A(r,I([0,1],h)));for(var f=1,p=!0;f<r.length;f+=1){var d=r[f],g=O(d,0,1),y=O(d,-1);if(('"'===g||"'"===g||"`"===g||'"'===y||"'"===y||"`"===y)&&g!==y)throw new o("property names with quotes must have matching quotes");if(("constructor"===d||!p)&&(u=!0),S(b,a="%"+(n+="."+d)+"%"))l=b[a];else if(null!=l){if(!(d in l)){if(!t)throw new s("base intrinsic for "+e+" exists, but the property is not available.");return}if(c&&f+1>=r.length){var m=c(l,d);l=(p=!!m)&&"get"in m&&!("originalValue"in m.get)?m.get:l[d]}else p=S(l,d),l=l[d];p&&!u&&(b[a]=l)}}return l},ii}function kn(){if(ai)return si;ai=!0;var e=On()("%Object.defineProperty%",!0)||!1;if(e)try{e({},"a",{value:1})}catch{e=!1}return si=e}function xn(){if(ui)return li;ui=!0;var e=On()("%Object.getOwnPropertyDescriptor%",!0);if(e)try{e([],"length")}catch{e=null}return li=e}function Tn(){if(gi)return di;gi=!0;var e=On(),t=function(){if(hi)return ci;hi=!0;var e=kn(),t=Sn(),r=In(),n=xn();return ci=function(i,o,s){if(!i||"object"!=typeof i&&"function"!=typeof i)throw new r("`obj` must be an object or a function`");if("string"!=typeof o&&"symbol"!=typeof o)throw new r("`property` must be a string or a symbol`");if(arguments.length>3&&"boolean"!=typeof arguments[3]&&null!==arguments[3])throw new r("`nonEnumerable`, if provided, must be a boolean or null");if(arguments.length>4&&"boolean"!=typeof arguments[4]&&null!==arguments[4])throw new r("`nonWritable`, if provided, must be a boolean or null");if(arguments.length>5&&"boolean"!=typeof arguments[5]&&null!==arguments[5])throw new r("`nonConfigurable`, if provided, must be a boolean or null");if(arguments.length>6&&"boolean"!=typeof arguments[6])throw new r("`loose`, if provided, must be a boolean");var a=arguments.length>3?arguments[3]:null,l=arguments.length>4?arguments[4]:null,u=arguments.length>5?arguments[5]:null,c=arguments.length>6&&arguments[6],h=!!n&&n(i,o);if(e)e(i,o,{configurable:null===u&&h?h.configurable:!u,enumerable:null===a&&h?h.enumerable:!a,value:s,writable:null===l&&h?h.writable:!l});else{if(!c&&(a||l||u))throw new t("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.");i[o]=s}},ci}(),r=function(){if(pi)return fi;pi=!0;var e=kn(),t=function(){return!!e};return t.hasArrayLengthDefineBug=function(){if(!e)return null;try{return 1!==e([],"length",{value:1}).length}catch{return!0}},fi=t}()(),n=xn(),i=In(),o=e("%Math.floor%");return di=function(e,s){if("function"!=typeof e)throw new i("`fn` is not a function");if("number"!=typeof s||s<0||s>4294967295||o(s)!==s)throw new i("`length` must be a positive 32-bit integer");var a=arguments.length>2&&!!arguments[2],l=!0,u=!0;if("length"in e&&n){var c=n(e,"length");c&&!c.configurable&&(l=!1),c&&!c.writable&&(u=!1)}return(l||u||!a)&&(r?t(e,"length",s,!0,!0):t(e,"length",s)),e},di}function Cn(){if(vi)return bi;vi=!0;var e=On(),t=function(){if(mi)return yi;mi=!0;var e=Rn(),t=On(),r=Tn(),n=In(),i=t("%Function.prototype.apply%"),o=t("%Function.prototype.call%"),s=t("%Reflect.apply%",!0)||e.call(o,i),a=kn(),l=t("%Math.max%");yi=function(t){if("function"!=typeof t)throw new n("a function is required");var i=s(e,o,arguments);return r(i,1+l(0,t.length-(arguments.length-1)),!0)};var u=function(){return s(e,i,arguments)};return a?a(yi,"apply",{value:u}):yi.apply=u,yi}(),r=t(e("String.prototype.indexOf"));return bi=function(n,i){var o=e(n,!!i);return"function"==typeof o&&r(n,".prototype.")>-1?t(o):o}}var Pn,Nn,Ln,Mn,Bn,Dn,jn,Un,Fn,Wn,$n,qn,Gn,Vn,Hn,Kn,zn,Qn,Yn,Jn,Xn,Zn,ei,ti,ri,ni,ii,oi,si,ai,li,ui,ci,hi,fi,pi,di,gi,yi,mi,bi,vi,wi=i(()=>{l(),tt(),Fe(),Pn={},Nn=!1,Ln={},Mn=!1,Bn={},Dn=!1,jn={},Un=!1,Fn={},Wn=!1,$n={},qn=!1,Gn={},Vn=!1,Hn={},Kn=!1,zn={},Qn=!1,Yn={},Jn=!1,Xn={},Zn=!1,ei={},ti=!1,ri={},ni=!1,ii={},oi=!1,si={},ai=!1,li={},ui=!1,ci={},hi=!1,fi={},pi=!1,di={},gi=!1,yi={},mi=!1,bi={},vi=!1});function _i(e){throw new Error("Node.js process "+e+" is not supported by JSPM core outside of Node.js")}function Ei(){!ji||!Ui||(ji=!1,Ui.length?Di=Ui.concat(Di):Fi=-1,Di.length&&Si())}function Si(){if(!ji){var e=setTimeout(Ei,0);ji=!0;for(var t=Di.length;t;){for(Ui=Di,Di=[];++Fi<t;)Ui&&Ui[Fi].run();Fi=-1,t=Di.length}Ui=null,ji=!1,clearTimeout(e)}}function Ii(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];Di.push(new Ai(e,t)),1===Di.length&&!ji&&setTimeout(Si,0)}function Ai(e,t){this.fun=e,this.array=t}function Ri(){}function Oi(e){_i("_linkedBinding")}function ki(e){_i("dlopen")}function xi(){return[]}function Ti(){return[]}function Ci(e,t){if(!e)throw new Error(t||"assertion error")}function Pi(){return!1}function Ni(){return Eo.now()/1e3}function Li(e){var t=Math.floor(.001*(Date.now()-Eo.now())),r=.001*Eo.now(),n=Math.floor(r)+t,i=Math.floor(r%1*1e9);return e&&(n-=e[0],(i-=e[1])<0&&(n--,i+=Io)),[n,i]}function Mi(){return Ao}function Bi(e){return[]}var Di,ji,Ui,Fi,Wi,$i,qi,Gi,Vi,Hi,Ki,zi,Qi,Yi,Ji,Xi,Zi,eo,to,ro,no,io,oo,so,ao,lo,uo,co,ho,fo,po,go,yo,mo,bo,vo,wo,_o,Eo,So,Io,Ao,Ro=i(()=>{l(),tt(),Fe(),Di=[],ji=!1,Fi=-1,Ai.prototype.run=function(){this.fun.apply(null,this.array)},Wi={PATH:"/usr/bin",LANG:navigator.language+".UTF-8",PWD:"/",HOME:"/home",TMP:"/tmp"},$i=["/usr/bin/node"],qi=[],Gi={},Vi=function(e,t){console.warn((t?t+": ":"")+e)},Hi=function(e){_i("binding")},Ki=function(e){return 0},zi=function(){return"/"},Qi=function(e){},Yi={name:"node",sourceUrl:"",headersUrl:"",libUrl:""},Ji=Ri,Xi=[],Zi={},eo={},to=Ri,ro=Ri,io=no=function(){return{}},oo=no,so=Ri,ao=Ri,lo=Ri,uo={},co={inspector:!1,debug:!1,uv:!1,ipv6:!1,tls_alpn:!1,tls_sni:!1,tls_ocsp:!1,tls:!1,cached_builtins:!0},ho=Ri,fo=Ri,po=Ri,go=Ri,yo=Ri,mo=Ri,bo=Ri,vo=Ri,wo=[],_o=Ri,void 0===(Eo={now:typeof performance<"u"?performance.now.bind(performance):void 0,timing:typeof performance<"u"?performance.timing:void 0}).now&&(So=Date.now(),Eo.timing&&Eo.timing.navigationStart&&(So=Eo.timing.navigationStart),Eo.now=()=>Date.now()-So),Io=1e9,Li.bigint=function(e){var t=Li(e);return typeof BigInt>"u"?t[0]*Io+t[1]:BigInt(t[0]*Io)+BigInt(t[1])},Ao={version:"v16.8.0",versions:Gi,arch:"x64",platform:"browser",release:Yi,_rawDebug:Ji,moduleLoadList:Xi,binding:Hi,_linkedBinding:Oi,_events:{},_eventsCount:0,_maxListeners:10,on:Mi,addListener:Mi,once:Mi,off:Mi,removeListener:Mi,removeAllListeners:Mi,emit:Ri,prependListener:Mi,prependOnceListener:Mi,listeners:Bi,domain:Zi,_exiting:false,config:eo,dlopen:ki,uptime:Ni,_getActiveRequests:xi,_getActiveHandles:Ti,reallyExit:to,_kill:ro,cpuUsage:no,resourceUsage:io,memoryUsage:oo,kill:so,exit:ao,openStdin:lo,allowedNodeEnvironmentFlags:uo,assert:Ci,features:co,_fatalExceptions:ho,setUncaughtExceptionCaptureCallback:fo,hasUncaughtExceptionCaptureCallback:Pi,emitWarning:Vi,nextTick:Ii,_tickCallback:po,_debugProcess:go,_debugEnd:yo,_startProfilerIdleNotifier:mo,_stopProfilerIdleNotifier:bo,stdout:void 0,stdin:void 0,stderr:void 0,abort:vo,umask:Ki,chdir:Qi,cwd:zi,env:Wi,title:"browser",argv:$i,execArgv:qi,pid:2,ppid:1,execPath:"/bin/usr/node",debugPort:9229,hrtime:Li,argv0:"node",_preload_modules:wo,setSourceMapsEnabled:_o}});var Oo,ko,xo,To=i(()=>{l(),tt(),Fe(),Ro(),Oo={},ko=!1,xo=function(){if(ko)return Oo;ko=!0;var e=Ao;function t(e){if("string"!=typeof e)throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}function r(e,t){for(var r,n="",i=0,o=-1,s=0,a=0;a<=e.length;++a){if(a<e.length)r=e.charCodeAt(a);else{if(47===r)break;r=47}if(47===r){if(o!==a-1&&1!==s)if(o!==a-1&&2===s){if(n.length<2||2!==i||46!==n.charCodeAt(n.length-1)||46!==n.charCodeAt(n.length-2))if(n.length>2){var l=n.lastIndexOf("/");if(l!==n.length-1){-1===l?(n="",i=0):i=(n=n.slice(0,l)).length-1-n.lastIndexOf("/"),o=a,s=0;continue}}else if(2===n.length||1===n.length){n="",i=0,o=a,s=0;continue}t&&(n.length>0?n+="/..":n="..",i=2)}else n.length>0?n+="/"+e.slice(o+1,a):n=e.slice(o+1,a),i=a-o-1;o=a,s=0}else 46===r&&-1!==s?++s:s=-1}return n}var n={resolve:function(){for(var n,i="",o=!1,s=arguments.length-1;s>=-1&&!o;s--){var a;s>=0?a=arguments[s]:(void 0===n&&(n=e.cwd()),a=n),t(a),0!==a.length&&(i=a+"/"+i,o=47===a.charCodeAt(0))}return i=r(i,!o),o?i.length>0?"/"+i:"/":i.length>0?i:"."},normalize:function(e){if(t(e),0===e.length)return".";var n=47===e.charCodeAt(0),i=47===e.charCodeAt(e.length-1);return 0===(e=r(e,!n)).length&&!n&&(e="."),e.length>0&&i&&(e+="/"),n?"/"+e:e},isAbsolute:function(e){return t(e),e.length>0&&47===e.charCodeAt(0)},join:function(){if(0===arguments.length)return".";for(var e,r=0;r<arguments.length;++r){var i=arguments[r];t(i),i.length>0&&(void 0===e?e=i:e+="/"+i)}return void 0===e?".":n.normalize(e)},relative:function(e,r){if(t(e),t(r),e===r||(e=n.resolve(e))===(r=n.resolve(r)))return"";for(var i=1;i<e.length&&47===e.charCodeAt(i);++i);for(var o=e.length,s=o-i,a=1;a<r.length&&47===r.charCodeAt(a);++a);for(var l=r.length-a,u=s<l?s:l,c=-1,h=0;h<=u;++h){if(h===u){if(l>u){if(47===r.charCodeAt(a+h))return r.slice(a+h+1);if(0===h)return r.slice(a+h)}else s>u&&(47===e.charCodeAt(i+h)?c=h:0===h&&(c=0));break}var f=e.charCodeAt(i+h);if(f!==r.charCodeAt(a+h))break;47===f&&(c=h)}var p="";for(h=i+c+1;h<=o;++h)(h===o||47===e.charCodeAt(h))&&(0===p.length?p+="..":p+="/..");return p.length>0?p+r.slice(a+c):(a+=c,47===r.charCodeAt(a)&&++a,r.slice(a))},_makeLong:function(e){return e},dirname:function(e){if(t(e),0===e.length)return".";for(var r=e.charCodeAt(0),n=47===r,i=-1,o=!0,s=e.length-1;s>=1;--s)if(47===(r=e.charCodeAt(s))){if(!o){i=s;break}}else o=!1;return-1===i?n?"/":".":n&&1===i?"//":e.slice(0,i)},basename:function(e,r){if(void 0!==r&&"string"!=typeof r)throw new TypeError('"ext" argument must be a string');t(e);var n,i=0,o=-1,s=!0;if(void 0!==r&&r.length>0&&r.length<=e.length){if(r.length===e.length&&r===e)return"";var a=r.length-1,l=-1;for(n=e.length-1;n>=0;--n){var u=e.charCodeAt(n);if(47===u){if(!s){i=n+1;break}}else-1===l&&(s=!1,l=n+1),a>=0&&(u===r.charCodeAt(a)?-1===--a&&(o=n):(a=-1,o=l))}return i===o?o=l:-1===o&&(o=e.length),e.slice(i,o)}for(n=e.length-1;n>=0;--n)if(47===e.charCodeAt(n)){if(!s){i=n+1;break}}else-1===o&&(s=!1,o=n+1);return-1===o?"":e.slice(i,o)},extname:function(e){t(e);for(var r=-1,n=0,i=-1,o=!0,s=0,a=e.length-1;a>=0;--a){var l=e.charCodeAt(a);if(47!==l)-1===i&&(o=!1,i=a+1),46===l?-1===r?r=a:1!==s&&(s=1):-1!==r&&(s=-1);else if(!o){n=a+1;break}}return-1===r||-1===i||0===s||1===s&&r===i-1&&r===n+1?"":e.slice(r,i)},format:function(e){if(null===e||"object"!=typeof e)throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof e);return function(e,t){var r=t.dir||t.root,n=t.base||(t.name||"")+(t.ext||"");return r?r===t.root?r+n:r+e+n:n}("/",e)},parse:function(e){t(e);var r={root:"",dir:"",base:"",ext:"",name:""};if(0===e.length)return r;var n,i=e.charCodeAt(0),o=47===i;o?(r.root="/",n=1):n=0;for(var s=-1,a=0,l=-1,u=!0,c=e.length-1,h=0;c>=n;--c)if(47!==(i=e.charCodeAt(c)))-1===l&&(u=!1,l=c+1),46===i?-1===s?s=c:1!==h&&(h=1):-1!==s&&(h=-1);else if(!u){a=c+1;break}return-1===s||-1===l||0===h||1===h&&s===l-1&&s===a+1?-1!==l&&(r.base=r.name=0===a&&o?e.slice(1,l):e.slice(a,l)):(0===a&&o?(r.name=e.slice(1,s),r.base=e.slice(1,l)):(r.name=e.slice(a,s),r.base=e.slice(a,l)),r.ext=e.slice(s,l)),a>0?r.dir=e.slice(0,a-1):o&&(r.dir="/"),r},sep:"/",delimiter:":",win32:null,posix:null};return n.posix=n,Oo=n}()}),Co={};function Po(){if(qo)return $o;qo=!0;var e="function"==typeof Map&&Map.prototype,t=Object.getOwnPropertyDescriptor&&e?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,r=e&&t&&"function"==typeof t.get?t.get:null,n=e&&Map.prototype.forEach,i="function"==typeof Set&&Set.prototype,o=Object.getOwnPropertyDescriptor&&i?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,s=i&&o&&"function"==typeof o.get?o.get:null,a=i&&Set.prototype.forEach,l="function"==typeof WeakMap&&WeakMap.prototype?WeakMap.prototype.has:null,u="function"==typeof WeakSet&&WeakSet.prototype?WeakSet.prototype.has:null,c="function"==typeof WeakRef&&WeakRef.prototype?WeakRef.prototype.deref:null,h=Boolean.prototype.valueOf,f=Object.prototype.toString,p=Function.prototype.toString,d=String.prototype.match,g=String.prototype.slice,y=String.prototype.replace,m=String.prototype.toUpperCase,b=String.prototype.toLowerCase,v=RegExp.prototype.test,w=Array.prototype.concat,_=Array.prototype.join,E=Array.prototype.slice,S=Math.floor,I="function"==typeof BigInt?BigInt.prototype.valueOf:null,A=Object.getOwnPropertySymbols,R="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?Symbol.prototype.toString:null,O="function"==typeof Symbol&&"object"==typeof Symbol.iterator,k="function"==typeof Symbol&&Symbol.toStringTag&&(Symbol.toStringTag,1)?Symbol.toStringTag:null,x=Object.prototype.propertyIsEnumerable,T=("function"==typeof Reflect?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(e){return e.__proto__}:null);function C(e,t){if(e===1/0||e===-1/0||e!=e||e&&e>-1e3&&e<1e3||v.call(/e/,t))return t;var r=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if("number"==typeof e){var n=e<0?-S(-e):S(e);if(n!==e){var i=String(n),o=g.call(t,i.length+1);return y.call(i,r,"$&_")+"."+y.call(y.call(o,/([0-9]{3})/g,"$&_"),/_$/,"")}}return y.call(t,r,"$&_")}var P=Wo,N=P.custom,L=U(N)?N:null;function M(e,t,r){var n="double"===(r.quoteStyle||t)?'"':"'";return n+e+n}function B(e){return y.call(String(e),/"/g,"&quot;")}function D(e){return!("[object Array]"!==$(e)||k&&"object"==typeof e&&k in e)}function j(e){return!("[object RegExp]"!==$(e)||k&&"object"==typeof e&&k in e)}function U(e){if(O)return e&&"object"==typeof e&&e instanceof Symbol;if("symbol"==typeof e)return!0;if(!e||"object"!=typeof e||!R)return!1;try{return R.call(e),!0}catch{}return!1}$o=function e(t,i,o,f){var m=i||{};if(W(m,"quoteStyle")&&"single"!==m.quoteStyle&&"double"!==m.quoteStyle)throw new TypeError('option "quoteStyle" must be "single" or "double"');if(W(m,"maxStringLength")&&("number"==typeof m.maxStringLength?m.maxStringLength<0&&m.maxStringLength!==1/0:null!==m.maxStringLength))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var v=!W(m,"customInspect")||m.customInspect;if("boolean"!=typeof v&&"symbol"!==v)throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(W(m,"indent")&&null!==m.indent&&"\t"!==m.indent&&!(parseInt(m.indent,10)===m.indent&&m.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(W(m,"numericSeparator")&&"boolean"!=typeof m.numericSeparator)throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var S=m.numericSeparator;if(typeof t>"u")return"undefined";if(null===t)return"null";if("boolean"==typeof t)return t?"true":"false";if("string"==typeof t)return G(t,m);if("number"==typeof t){if(0===t)return 1/0/t>0?"0":"-0";var A=String(t);return S?C(t,A):A}if("bigint"==typeof t){var N=String(t)+"n";return S?C(t,N):N}var F=typeof m.depth>"u"?5:m.depth;if(typeof o>"u"&&(o=0),o>=F&&F>0&&"object"==typeof t)return D(t)?"[Array]":"[Object]";var V=function(e,t){var r;if("\t"===e.indent)r="\t";else{if(!("number"==typeof e.indent&&e.indent>0))return null;r=_.call(Array(e.indent+1)," ")}return{base:r,prev:_.call(Array(t+1),r)}}(m,o);if(typeof f>"u")f=[];else if(q(f,t)>=0)return"[Circular]";function J(t,r,n){if(r&&(f=E.call(f)).push(r),n){var i={depth:m.depth};return W(m,"quoteStyle")&&(i.quoteStyle=m.quoteStyle),e(t,i,o+1,f)}return e(t,m,o+1,f)}if("function"==typeof t&&!j(t)){var X=function(e){if(e.name)return e.name;var t=d.call(p.call(e),/^function\s*([\w$]+)/);return t?t[1]:null}(t),Z=Y(t,J);return"[Function"+(X?": "+X:" (anonymous)")+"]"+(Z.length>0?" { "+_.call(Z,", ")+" }":"")}if(U(t)){var ee=O?y.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):R.call(t);return"object"!=typeof t||O?ee:H(ee)}if(function(e){return!(!e||"object"!=typeof e)&&(typeof HTMLElement<"u"&&e instanceof HTMLElement||"string"==typeof e.nodeName&&"function"==typeof e.getAttribute)}(t)){for(var te="<"+b.call(String(t.nodeName)),re=t.attributes||[],ne=0;ne<re.length;ne++)te+=" "+re[ne].name+"="+M(B(re[ne].value),"double",m);return te+=">",t.childNodes&&t.childNodes.length&&(te+="..."),te+="</"+b.call(String(t.nodeName))+">"}if(D(t)){if(0===t.length)return"[]";var ie=Y(t,J);return V&&!function(e){for(var t=0;t<e.length;t++)if(q(e[t],"\n")>=0)return!1;return!0}(ie)?"["+Q(ie,V)+"]":"[ "+_.call(ie,", ")+" ]"}if(function(e){return!("[object Error]"!==$(e)||k&&"object"==typeof e&&k in e)}(t)){var oe=Y(t,J);return"cause"in Error.prototype||!("cause"in t)||x.call(t,"cause")?0===oe.length?"["+String(t)+"]":"{ ["+String(t)+"] "+_.call(oe,", ")+" }":"{ ["+String(t)+"] "+_.call(w.call("[cause]: "+J(t.cause),oe),", ")+" }"}if("object"==typeof t&&v){if(L&&"function"==typeof t[L]&&P)return P(t,{depth:F-o});if("symbol"!==v&&"function"==typeof t.inspect)return t.inspect()}if(function(e){if(!r||!e||"object"!=typeof e)return!1;try{r.call(e);try{s.call(e)}catch{return!0}return e instanceof Map}catch{}return!1}(t)){var se=[];return n&&n.call(t,function(e,r){se.push(J(r,t,!0)+" => "+J(e,t))}),z("Map",r.call(t),se,V)}if(function(e){if(!s||!e||"object"!=typeof e)return!1;try{s.call(e);try{r.call(e)}catch{return!0}return e instanceof Set}catch{}return!1}(t)){var ae=[];return a&&a.call(t,function(e){ae.push(J(e,t))}),z("Set",s.call(t),ae,V)}if(function(e){if(!l||!e||"object"!=typeof e)return!1;try{l.call(e,l);try{u.call(e,u)}catch{return!0}return e instanceof WeakMap}catch{}return!1}(t))return K("WeakMap");if(function(e){if(!u||!e||"object"!=typeof e)return!1;try{u.call(e,u);try{l.call(e,l)}catch{return!0}return e instanceof WeakSet}catch{}return!1}(t))return K("WeakSet");if(function(e){if(!c||!e||"object"!=typeof e)return!1;try{return c.call(e),!0}catch{}return!1}(t))return K("WeakRef");if(function(e){return!("[object Number]"!==$(e)||k&&"object"==typeof e&&k in e)}(t))return H(J(Number(t)));if(function(e){if(!e||"object"!=typeof e||!I)return!1;try{return I.call(e),!0}catch{}return!1}(t))return H(J(I.call(t)));if(function(e){return!("[object Boolean]"!==$(e)||k&&"object"==typeof e&&k in e)}(t))return H(h.call(t));if(function(e){return!("[object String]"!==$(e)||k&&"object"==typeof e&&k in e)}(t))return H(J(String(t)));if(typeof window<"u"&&t===window)return"{ [object Window] }";if(typeof globalThis<"u"&&t===globalThis||typeof Go<"u"&&t===Go)return"{ [object globalThis] }";if(!function(e){return!("[object Date]"!==$(e)||k&&"object"==typeof e&&k in e)}(t)&&!j(t)){var le=Y(t,J),ue=T?T(t)===Object.prototype:t instanceof Object||t.constructor===Object,ce=t instanceof Object?"":"null prototype",he=!ue&&k&&Object(t)===t&&k in t?g.call($(t),8,-1):ce?"Object":"",fe=(ue||"function"!=typeof t.constructor?"":t.constructor.name?t.constructor.name+" ":"")+(he||ce?"["+_.call(w.call([],he||[],ce||[]),": ")+"] ":"");return 0===le.length?fe+"{}":V?fe+"{"+Q(le,V)+"}":fe+"{ "+_.call(le,", ")+" }"}return String(t)};var F=Object.prototype.hasOwnProperty||function(e){return e in(this||Go)};function W(e,t){return F.call(e,t)}function $(e){return f.call(e)}function q(e,t){if(e.indexOf)return e.indexOf(t);for(var r=0,n=e.length;r<n;r++)if(e[r]===t)return r;return-1}function G(e,t){if(e.length>t.maxStringLength){var r=e.length-t.maxStringLength,n="... "+r+" more character"+(r>1?"s":"");return G(g.call(e,0,t.maxStringLength),t)+n}return M(y.call(y.call(e,/(['\\])/g,"\\$1"),/[\x00-\x1f]/g,V),"single",t)}function V(e){var t=e.charCodeAt(0),r={8:"b",9:"t",10:"n",12:"f",13:"r"}[t];return r?"\\"+r:"\\x"+(t<16?"0":"")+m.call(t.toString(16))}function H(e){return"Object("+e+")"}function K(e){return e+" { ? }"}function z(e,t,r,n){return e+" ("+t+") {"+(n?Q(r,n):_.call(r,", "))+"}"}function Q(e,t){if(0===e.length)return"";var r="\n"+t.prev+t.base;return r+_.call(e,","+r)+"\n"+t.prev}function Y(e,t){var r=D(e),n=[];if(r){n.length=e.length;for(var i=0;i<e.length;i++)n[i]=W(e,i)?t(e[i],e):""}var o,s="function"==typeof A?A(e):[];if(O){o={};for(var a=0;a<s.length;a++)o["$"+s[a]]=s[a]}for(var l in e)W(e,l)&&(r&&String(Number(l))===l&&l<e.length||O&&o["$"+l]instanceof Symbol||(v.call(/[^\w$]/,l)?n.push(t(l,e)+": "+t(e[l],e)):n.push(l+": "+t(e[l],e))));if("function"==typeof A)for(var u=0;u<s.length;u++)x.call(e,s[u])&&n.push("["+t(s[u])+"]: "+t(e[s[u]],e));return n}return $o}function No(){if(Ho)return Vo;Ho=!0;var e=On(),t=Cn(),r=Po(),n=In(),i=e("%WeakMap%",!0),o=e("%Map%",!0),s=t("WeakMap.prototype.get",!0),a=t("WeakMap.prototype.set",!0),l=t("WeakMap.prototype.has",!0),u=t("Map.prototype.get",!0),c=t("Map.prototype.set",!0),h=t("Map.prototype.has",!0),f=function(e,t){for(var r,n=e;null!==(r=n.next);n=r)if(r.key===t)return n.next=r.next,r.next=e.next,e.next=r,r};return Vo=function(){var e,t,p,d={assert:function(e){if(!d.has(e))throw new n("Side channel does not contain "+r(e))},get:function(r){if(i&&r&&("object"==typeof r||"function"==typeof r)){if(e)return s(e,r)}else if(o){if(t)return u(t,r)}else if(p)return function(e,t){var r=f(e,t);return r&&r.value}(p,r)},has:function(r){if(i&&r&&("object"==typeof r||"function"==typeof r)){if(e)return l(e,r)}else if(o){if(t)return h(t,r)}else if(p)return function(e,t){return!!f(e,t)}(p,r);return!1},set:function(r,n){i&&r&&("object"==typeof r||"function"==typeof r)?(e||(e=new i),a(e,r,n)):o?(t||(t=new o),c(t,r,n)):(p||(p={key:{},next:null}),function(e,t,r){var n=f(e,t);n?n.value=r:e.next={key:t,next:e.next,value:r}}(p,r,n))}};return d}}function Lo(){if(zo)return Ko;zo=!0;var e=String.prototype.replace,t=/%20/g,r="RFC3986";return Ko={default:r,formatters:{RFC1738:function(r){return e.call(r,t,"+")},RFC3986:function(e){return String(e)}},RFC1738:"RFC1738",RFC3986:r}}function Mo(){if(Yo)return Qo;Yo=!0;var e=Lo(),t=Object.prototype.hasOwnProperty,r=Array.isArray,n=function(){for(var e=[],t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e}(),i=function(e,t){for(var r=t&&t.plainObjects?Object.create(null):{},n=0;n<e.length;++n)typeof e[n]<"u"&&(r[n]=e[n]);return r},o=1024;return Qo={arrayToObject:i,assign:function(e,t){return Object.keys(t).reduce(function(e,r){return e[r]=t[r],e},e)},combine:function(e,t){return[].concat(e,t)},compact:function(e){for(var t=[{obj:{o:e},prop:"o"}],n=[],i=0;i<t.length;++i)for(var o=t[i],s=o.obj[o.prop],a=Object.keys(s),l=0;l<a.length;++l){var u=a[l],c=s[u];"object"==typeof c&&null!==c&&-1===n.indexOf(c)&&(t.push({obj:s,prop:u}),n.push(c))}return function(e){for(;e.length>1;){var t=e.pop(),n=t.obj[t.prop];if(r(n)){for(var i=[],o=0;o<n.length;++o)typeof n[o]<"u"&&i.push(n[o]);t.obj[t.prop]=i}}}(t),e},decode:function(e,t,r){var n=e.replace(/\+/g," ");if("iso-8859-1"===r)return n.replace(/%[0-9a-f]{2}/gi,unescape);try{return decodeURIComponent(n)}catch{return n}},encode:function(t,r,i,s,a){if(0===t.length)return t;var l=t;if("symbol"==typeof t?l=Symbol.prototype.toString.call(t):"string"!=typeof t&&(l=String(t)),"iso-8859-1"===i)return escape(l).replace(/%u[0-9a-f]{4}/gi,function(e){return"%26%23"+parseInt(e.slice(2),16)+"%3B"});for(var u="",c=0;c<l.length;c+=o){for(var h=l.length>=o?l.slice(c,c+o):l,f=[],p=0;p<h.length;++p){var d=h.charCodeAt(p);45===d||46===d||95===d||126===d||d>=48&&d<=57||d>=65&&d<=90||d>=97&&d<=122||a===e.RFC1738&&(40===d||41===d)?f[f.length]=h.charAt(p):d<128?f[f.length]=n[d]:d<2048?f[f.length]=n[192|d>>6]+n[128|63&d]:d<55296||d>=57344?f[f.length]=n[224|d>>12]+n[128|d>>6&63]+n[128|63&d]:(p+=1,d=65536+((1023&d)<<10|1023&h.charCodeAt(p)),f[f.length]=n[240|d>>18]+n[128|d>>12&63]+n[128|d>>6&63]+n[128|63&d])}u+=f.join("")}return u},isBuffer:function(e){return!(!e||"object"!=typeof e)&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isRegExp:function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},maybeMap:function(e,t){if(r(e)){for(var n=[],i=0;i<e.length;i+=1)n.push(t(e[i]));return n}return t(e)},merge:function e(n,o,s){if(!o)return n;if("object"!=typeof o){if(r(n))n.push(o);else{if(!n||"object"!=typeof n)return[n,o];(s&&(s.plainObjects||s.allowPrototypes)||!t.call(Object.prototype,o))&&(n[o]=!0)}return n}if(!n||"object"!=typeof n)return[n].concat(o);var a=n;return r(n)&&!r(o)&&(a=i(n,s)),r(n)&&r(o)?(o.forEach(function(r,i){if(t.call(n,i)){var o=n[i];o&&"object"==typeof o&&r&&"object"==typeof r?n[i]=e(o,r,s):n.push(r)}else n[i]=r}),n):Object.keys(o).reduce(function(r,n){var i=o[n];return t.call(r,n)?r[n]=e(r[n],i,s):r[n]=i,r},a)}}}function Bo(){if(Xo)return Jo;Xo=!0;var e=No(),t=Mo(),r=Lo(),n=Object.prototype.hasOwnProperty,i={brackets:function(e){return e+"[]"},comma:"comma",indices:function(e,t){return e+"["+t+"]"},repeat:function(e){return e}},o=Array.isArray,s=Array.prototype.push,a=function(e,t){s.apply(e,o(t)?t:[t])},l=Date.prototype.toISOString,u=r.default,c={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:t.encode,encodeValuesOnly:!1,format:u,formatter:r.formatters[u],indices:!1,serializeDate:function(e){return l.call(e)},skipNulls:!1,strictNullHandling:!1},h={},f=function r(n,i,s,l,u,f,p,d,g,y,m,b,v,w,_,E,S,I){for(var A=n,R=I,O=0,k=!1;void 0!==(R=R.get(h))&&!k;){var x=R.get(n);if(O+=1,typeof x<"u"){if(x===O)throw new RangeError("Cyclic object value");k=!0}typeof R.get(h)>"u"&&(O=0)}if("function"==typeof y?A=y(i,A):A instanceof Date?A=v(A):"comma"===s&&o(A)&&(A=t.maybeMap(A,function(e){return e instanceof Date?v(e):e})),null===A){if(f)return g&&!E?g(i,c.encoder,S,"key",w):i;A=""}if(function(e){return"string"==typeof e||"number"==typeof e||"boolean"==typeof e||"symbol"==typeof e||"bigint"==typeof e}(A)||t.isBuffer(A))return g?[_(E?i:g(i,c.encoder,S,"key",w))+"="+_(g(A,c.encoder,S,"value",w))]:[_(i)+"="+_(String(A))];var T,C=[];if(typeof A>"u")return C;if("comma"===s&&o(A))E&&g&&(A=t.maybeMap(A,g)),T=[{value:A.length>0?A.join(",")||null:void 0}];else if(o(y))T=y;else{var P=Object.keys(A);T=m?P.sort(m):P}var N=d?i.replace(/\./g,"%2E"):i,L=l&&o(A)&&1===A.length?N+"[]":N;if(u&&o(A)&&0===A.length)return L+"[]";for(var M=0;M<T.length;++M){var B=T[M],D="object"==typeof B&&typeof B.value<"u"?B.value:A[B];if(!p||null!==D){var j=b&&d?B.replace(/\./g,"%2E"):B,U=o(A)?"function"==typeof s?s(L,j):L:L+(b?"."+j:"["+j+"]");I.set(n,O);var F=e();F.set(h,I),a(C,r(D,U,s,l,u,f,p,d,"comma"===s&&E&&o(A)?null:g,y,m,b,v,w,_,E,S,F))}}return C};return Jo=function(t,s){var l,u=t,h=function(e){if(!e)return c;if(typeof e.allowEmptyArrays<"u"&&"boolean"!=typeof e.allowEmptyArrays)throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(typeof e.encodeDotInKeys<"u"&&"boolean"!=typeof e.encodeDotInKeys)throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(null!==e.encoder&&typeof e.encoder<"u"&&"function"!=typeof e.encoder)throw new TypeError("Encoder has to be a function.");var t=e.charset||c.charset;if(typeof e.charset<"u"&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var s=r.default;if(typeof e.format<"u"){if(!n.call(r.formatters,e.format))throw new TypeError("Unknown format option provided.");s=e.format}var a,l=r.formatters[s],u=c.filter;if(("function"==typeof e.filter||o(e.filter))&&(u=e.filter),a=e.arrayFormat in i?e.arrayFormat:"indices"in e?e.indices?"indices":"repeat":c.arrayFormat,"commaRoundTrip"in e&&"boolean"!=typeof e.commaRoundTrip)throw new TypeError("`commaRoundTrip` must be a boolean, or absent");var h=typeof e.allowDots>"u"?!0===e.encodeDotInKeys||c.allowDots:!!e.allowDots;return{addQueryPrefix:"boolean"==typeof e.addQueryPrefix?e.addQueryPrefix:c.addQueryPrefix,allowDots:h,allowEmptyArrays:"boolean"==typeof e.allowEmptyArrays?!!e.allowEmptyArrays:c.allowEmptyArrays,arrayFormat:a,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:c.charsetSentinel,commaRoundTrip:e.commaRoundTrip,delimiter:typeof e.delimiter>"u"?c.delimiter:e.delimiter,encode:"boolean"==typeof e.encode?e.encode:c.encode,encodeDotInKeys:"boolean"==typeof e.encodeDotInKeys?e.encodeDotInKeys:c.encodeDotInKeys,encoder:"function"==typeof e.encoder?e.encoder:c.encoder,encodeValuesOnly:"boolean"==typeof e.encodeValuesOnly?e.encodeValuesOnly:c.encodeValuesOnly,filter:u,format:s,formatter:l,serializeDate:"function"==typeof e.serializeDate?e.serializeDate:c.serializeDate,skipNulls:"boolean"==typeof e.skipNulls?e.skipNulls:c.skipNulls,sort:"function"==typeof e.sort?e.sort:null,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:c.strictNullHandling}}(s);"function"==typeof h.filter?u=(0,h.filter)("",u):o(h.filter)&&(l=h.filter);var p=[];if("object"!=typeof u||null===u)return"";var d=i[h.arrayFormat],g="comma"===d&&h.commaRoundTrip;l||(l=Object.keys(u)),h.sort&&l.sort(h.sort);for(var y=e(),m=0;m<l.length;++m){var b=l[m];h.skipNulls&&null===u[b]||a(p,f(u[b],b,d,g,h.allowEmptyArrays,h.strictNullHandling,h.skipNulls,h.encodeDotInKeys,h.encode?h.encoder:null,h.filter,h.sort,h.allowDots,h.serializeDate,h.format,h.formatter,h.encodeValuesOnly,h.charset,y))}var v=p.join(h.delimiter),w=!0===h.addQueryPrefix?"?":"";return h.charsetSentinel&&("iso-8859-1"===h.charset?w+="utf8=%26%2310003%3B&":w+="utf8=%E2%9C%93&"),v.length>0?w+v:""}}function Do(){if(es)return Zo;es=!0;var e=Mo(),t=Object.prototype.hasOwnProperty,r=Array.isArray,n={allowDots:!1,allowEmptyArrays:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decodeDotInKeys:!1,decoder:e.decode,delimiter:"&",depth:5,duplicates:"combine",ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictDepth:!1,strictNullHandling:!1},i=function(e){return e.replace(/&#(\d+);/g,function(e,t){return String.fromCharCode(parseInt(t,10))})},o=function(e,t){return e&&"string"==typeof e&&t.comma&&e.indexOf(",")>-1?e.split(","):e},s=function(e,r,n,i){if(e){var s=n.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,a=/(\[[^[\]]*])/g,l=n.depth>0&&/(\[[^[\]]*])/.exec(s),u=l?s.slice(0,l.index):s,c=[];if(u){if(!n.plainObjects&&t.call(Object.prototype,u)&&!n.allowPrototypes)return;c.push(u)}for(var h=0;n.depth>0&&null!==(l=a.exec(s))&&h<n.depth;){if(h+=1,!n.plainObjects&&t.call(Object.prototype,l[1].slice(1,-1))&&!n.allowPrototypes)return;c.push(l[1])}if(l){if(!0===n.strictDepth)throw new RangeError("Input depth exceeded depth option of "+n.depth+" and strictDepth is true");c.push("["+s.slice(l.index)+"]")}return function(e,t,r,n){for(var i=n?t:o(t,r),s=e.length-1;s>=0;--s){var a,l=e[s];if("[]"===l&&r.parseArrays)a=r.allowEmptyArrays&&(""===i||r.strictNullHandling&&null===i)?[]:[].concat(i);else{a=r.plainObjects?Object.create(null):{};var u="["===l.charAt(0)&&"]"===l.charAt(l.length-1)?l.slice(1,-1):l,c=r.decodeDotInKeys?u.replace(/%2E/g,"."):u,h=parseInt(c,10);r.parseArrays||""!==c?!isNaN(h)&&l!==c&&String(h)===c&&h>=0&&r.parseArrays&&h<=r.arrayLimit?(a=[])[h]=i:"__proto__"!==c&&(a[c]=i):a={0:i}}i=a}return i}(c,r,n,i)}};return Zo=function(a,l){var u=function(t){if(!t)return n;if(typeof t.allowEmptyArrays<"u"&&"boolean"!=typeof t.allowEmptyArrays)throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(typeof t.decodeDotInKeys<"u"&&"boolean"!=typeof t.decodeDotInKeys)throw new TypeError("`decodeDotInKeys` option can only be `true` or `false`, when provided");if(null!==t.decoder&&typeof t.decoder<"u"&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(typeof t.charset<"u"&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var r=typeof t.charset>"u"?n.charset:t.charset,i=typeof t.duplicates>"u"?n.duplicates:t.duplicates;if("combine"!==i&&"first"!==i&&"last"!==i)throw new TypeError("The duplicates option must be either combine, first, or last");return{allowDots:typeof t.allowDots>"u"?!0===t.decodeDotInKeys||n.allowDots:!!t.allowDots,allowEmptyArrays:"boolean"==typeof t.allowEmptyArrays?!!t.allowEmptyArrays:n.allowEmptyArrays,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:n.allowPrototypes,allowSparse:"boolean"==typeof t.allowSparse?t.allowSparse:n.allowSparse,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:n.arrayLimit,charset:r,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:n.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:n.comma,decodeDotInKeys:"boolean"==typeof t.decodeDotInKeys?t.decodeDotInKeys:n.decodeDotInKeys,decoder:"function"==typeof t.decoder?t.decoder:n.decoder,delimiter:"string"==typeof t.delimiter||e.isRegExp(t.delimiter)?t.delimiter:n.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:n.depth,duplicates:i,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:n.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:n.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:n.plainObjects,strictDepth:"boolean"==typeof t.strictDepth?!!t.strictDepth:n.strictDepth,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:n.strictNullHandling}}(l);if(""===a||null===a||typeof a>"u")return u.plainObjects?Object.create(null):{};for(var c="string"==typeof a?function(s,a){var l={__proto__:null},u=a.ignoreQueryPrefix?s.replace(/^\?/,""):s;u=u.replace(/%5B/gi,"[").replace(/%5D/gi,"]");var c,h=a.parameterLimit===1/0?void 0:a.parameterLimit,f=u.split(a.delimiter,h),p=-1,d=a.charset;if(a.charsetSentinel)for(c=0;c<f.length;++c)0===f[c].indexOf("utf8=")&&("utf8=%E2%9C%93"===f[c]?d="utf-8":"utf8=%26%2310003%3B"===f[c]&&(d="iso-8859-1"),p=c,c=f.length);for(c=0;c<f.length;++c)if(c!==p){var g,y,m=f[c],b=m.indexOf("]="),v=-1===b?m.indexOf("="):b+1;-1===v?(g=a.decoder(m,n.decoder,d,"key"),y=a.strictNullHandling?null:""):(g=a.decoder(m.slice(0,v),n.decoder,d,"key"),y=e.maybeMap(o(m.slice(v+1),a),function(e){return a.decoder(e,n.decoder,d,"value")})),y&&a.interpretNumericEntities&&"iso-8859-1"===d&&(y=i(y)),m.indexOf("[]=")>-1&&(y=r(y)?[y]:y);var w=t.call(l,g);w&&"combine"===a.duplicates?l[g]=e.combine(l[g],y):(!w||"last"===a.duplicates)&&(l[g]=y)}return l}(a,u):a,h=u.plainObjects?Object.create(null):{},f=Object.keys(c),p=0;p<f.length;++p){var d=f[p],g=s(d,c[d],u,"string"==typeof a);h=e.merge(h,g,u)}return!0===u.allowSparse?h:e.compact(h)}}function jo(){if(is)return ns;is=!0;var e=_n;function t(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}var r=/^([a-z0-9.+-]+:)/i,n=/:[0-9]*$/,i=/^(\/\/?(?!\/)[^?\s]*)(\?[^\s]*)?$/,o=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n","\t"]),s=["'"].concat(o),a=["%","/","?",";","#"].concat(s),l=["/","?","#"],u=/^[+a-z0-9A-Z_-]{0,63}$/,c=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,h={javascript:!0,"javascript:":!0},f={javascript:!0,"javascript:":!0},p={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},d=function(){if(rs)return ts;rs=!0;var e=Bo(),t=Do(),r=Lo();return ts={formats:r,parse:t,stringify:e}}();function g(e,r,n){if(e&&"object"==typeof e&&e instanceof t)return e;var i=new t;return i.parse(e,r,n),i}return t.prototype.parse=function(t,n,o){if("string"!=typeof t)throw new TypeError("Parameter 'url' must be a string, not "+typeof t);var g=t.indexOf("?"),y=-1!==g&&g<t.indexOf("#")?"?":"#",m=t.split(y);m[0]=m[0].replace(/\\/g,"/");var b=t=m.join(y);if(b=b.trim(),!o&&1===t.split("#").length){var v=i.exec(b);if(v)return this.path=b,this.href=b,this.pathname=v[1],v[2]?(this.search=v[2],this.query=n?d.parse(this.search.substr(1)):this.search.substr(1)):n&&(this.search="",this.query={}),this}var w=r.exec(b);if(w){var _=(w=w[0]).toLowerCase();this.protocol=_,b=b.substr(w.length)}if(o||w||b.match(/^\/\/[^@/]+@[^@/]+/)){var E="//"===b.substr(0,2);E&&(!w||!f[w])&&(b=b.substr(2),this.slashes=!0)}if(!f[w]&&(E||w&&!p[w])){for(var S=-1,I=0;I<l.length;I++){-1!==(O=b.indexOf(l[I]))&&(-1===S||O<S)&&(S=O)}var A,R;-1!==(R=-1===S?b.lastIndexOf("@"):b.lastIndexOf("@",S))&&(A=b.slice(0,R),b=b.slice(R+1),this.auth=decodeURIComponent(A)),S=-1;for(I=0;I<a.length;I++){var O;-1!==(O=b.indexOf(a[I]))&&(-1===S||O<S)&&(S=O)}-1===S&&(S=b.length),this.host=b.slice(0,S),b=b.slice(S),this.parseHost(),this.hostname=this.hostname||"";var k="["===this.hostname[0]&&"]"===this.hostname[this.hostname.length-1];if(!k)for(var x=this.hostname.split(/\./),T=(I=0,x.length);I<T;I++){var C=x[I];if(C&&!C.match(u)){for(var P="",N=0,L=C.length;N<L;N++)C.charCodeAt(N)>127?P+="x":P+=C[N];if(!P.match(u)){var M=x.slice(0,I),B=x.slice(I+1),D=C.match(c);D&&(M.push(D[1]),B.unshift(D[2])),B.length&&(b="/"+B.join(".")+b),this.hostname=M.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),k||(this.hostname=e.toASCII(this.hostname));var j=this.port?":"+this.port:"",U=this.hostname||"";this.host=U+j,this.href+=this.host,k&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==b[0]&&(b="/"+b))}if(!h[_])for(I=0,T=s.length;I<T;I++){var F=s[I];if(-1!==b.indexOf(F)){var W=encodeURIComponent(F);W===F&&(W=escape(F)),b=b.split(F).join(W)}}var $=b.indexOf("#");-1!==$&&(this.hash=b.substr($),b=b.slice(0,$));var q=b.indexOf("?");if(-1!==q?(this.search=b.substr(q),this.query=b.substr(q+1),n&&(this.query=d.parse(this.query)),b=b.slice(0,q)):n&&(this.search="",this.query={}),b&&(this.pathname=b),p[_]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){j=this.pathname||"";var G=this.search||"";this.path=j+G}return this.href=this.format(),this},t.prototype.format=function(){var e=this.auth||"";e&&(e=(e=encodeURIComponent(e)).replace(/%3A/i,":"),e+="@");var t=this.protocol||"",r=this.pathname||"",n=this.hash||"",i=!1,o="";this.host?i=e+this.host:this.hostname&&(i=e+(-1===this.hostname.indexOf(":")?this.hostname:"["+this.hostname+"]"),this.port&&(i+=":"+this.port)),this.query&&"object"==typeof this.query&&Object.keys(this.query).length&&(o=d.stringify(this.query,{arrayFormat:"repeat",addQueryPrefix:!1}));var s=this.search||o&&"?"+o||"";return t&&":"!==t.substr(-1)&&(t+=":"),this.slashes||(!t||p[t])&&!1!==i?(i="//"+(i||""),r&&"/"!==r.charAt(0)&&(r="/"+r)):i||(i=""),n&&"#"!==n.charAt(0)&&(n="#"+n),s&&"?"!==s.charAt(0)&&(s="?"+s),t+i+(r=r.replace(/[?#]/g,function(e){return encodeURIComponent(e)}))+(s=s.replace("#","%23"))+n},t.prototype.resolve=function(e){return this.resolveObject(g(e,!1,!0)).format()},t.prototype.resolveObject=function(e){if("string"==typeof e){var r=new t;r.parse(e,!1,!0),e=r}for(var n=new t,i=Object.keys(this),o=0;o<i.length;o++){var s=i[o];n[s]=this[s]}if(n.hash=e.hash,""===e.href)return n.href=n.format(),n;if(e.slashes&&!e.protocol){for(var a=Object.keys(e),l=0;l<a.length;l++){var u=a[l];"protocol"!==u&&(n[u]=e[u])}return p[n.protocol]&&n.hostname&&!n.pathname&&(n.pathname="/",n.path=n.pathname),n.href=n.format(),n}if(e.protocol&&e.protocol!==n.protocol){if(!p[e.protocol]){for(var c=Object.keys(e),h=0;h<c.length;h++){var d=c[h];n[d]=e[d]}return n.href=n.format(),n}if(n.protocol=e.protocol,e.host||f[e.protocol])n.pathname=e.pathname;else{for(var g=(e.pathname||"").split("/");g.length&&!(e.host=g.shift()););e.host||(e.host=""),e.hostname||(e.hostname=""),""!==g[0]&&g.unshift(""),g.length<2&&g.unshift(""),n.pathname=g.join("/")}if(n.search=e.search,n.query=e.query,n.host=e.host||"",n.auth=e.auth,n.hostname=e.hostname||e.host,n.port=e.port,n.pathname||n.search){var y=n.pathname||"",m=n.search||"";n.path=y+m}return n.slashes=n.slashes||e.slashes,n.href=n.format(),n}var b=n.pathname&&"/"===n.pathname.charAt(0),v=e.host||e.pathname&&"/"===e.pathname.charAt(0),w=v||b||n.host&&e.pathname,_=w,E=n.pathname&&n.pathname.split("/")||[],S=(g=e.pathname&&e.pathname.split("/")||[],n.protocol&&!p[n.protocol]);if(S&&(n.hostname="",n.port=null,n.host&&(""===E[0]?E[0]=n.host:E.unshift(n.host)),n.host="",e.protocol&&(e.hostname=null,e.port=null,e.host&&(""===g[0]?g[0]=e.host:g.unshift(e.host)),e.host=null),w=w&&(""===g[0]||""===E[0])),v)n.host=e.host||""===e.host?e.host:n.host,n.hostname=e.hostname||""===e.hostname?e.hostname:n.hostname,n.search=e.search,n.query=e.query,E=g;else if(g.length)E||(E=[]),E.pop(),E=E.concat(g),n.search=e.search,n.query=e.query;else if(null!=e.search){if(S)n.host=E.shift(),n.hostname=n.host,(k=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=k.shift(),n.hostname=k.shift(),n.host=n.hostname);return n.search=e.search,n.query=e.query,(null!==n.pathname||null!==n.search)&&(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.href=n.format(),n}if(!E.length)return n.pathname=null,n.search?n.path="/"+n.search:n.path=null,n.href=n.format(),n;for(var I=E.slice(-1)[0],A=(n.host||e.host||E.length>1)&&("."===I||".."===I)||""===I,R=0,O=E.length;O>=0;O--)"."===(I=E[O])?E.splice(O,1):".."===I?(E.splice(O,1),R++):R&&(E.splice(O,1),R--);if(!w&&!_)for(;R--;R)E.unshift("..");w&&""!==E[0]&&(!E[0]||"/"!==E[0].charAt(0))&&E.unshift(""),A&&"/"!==E.join("/").substr(-1)&&E.push("");var k,x=""===E[0]||E[0]&&"/"===E[0].charAt(0);S&&(n.hostname=x?"":E.length?E.shift():"",n.host=n.hostname,(k=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@"))&&(n.auth=k.shift(),n.hostname=k.shift(),n.host=n.hostname));return(w=w||n.host&&E.length)&&!x&&E.unshift(""),E.length>0?n.pathname=E.join("/"):(n.pathname=null,n.path=null),(null!==n.pathname||null!==n.search)&&(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.auth=e.auth||n.auth,n.slashes=n.slashes||e.slashes,n.href=n.format(),n},t.prototype.parseHost=function(){var e=this.host,t=n.exec(e);t&&(":"!==(t=t[0])&&(this.port=t.substr(1)),e=e.substr(0,e.length-t.length)),e&&(this.hostname=e)},ns.parse=g,ns.resolve=function(e,t){return g(e,!1,!0).resolve(t)},ns.resolveObject=function(e,t){return e?g(e,!1,!0).resolveObject(t):t},ns.format=function(e){return"string"==typeof e&&(e=g(e)),e instanceof t?e.format():t.prototype.format.call(e)},ns.Url=t,ns}function Uo(e){if("string"==typeof e)e=new URL(e);else if(!(e instanceof URL))throw new Deno.errors.InvalidData("invalid argument path , must be a string or URL");if("file:"!==e.protocol)throw new Deno.errors.InvalidData("invalid url scheme");return ms?function(e){let t=e.hostname,r=e.pathname;for(let e=0;e<r.length;e++)if("%"===r[e]){let t=r.codePointAt(e+2)||32;if("2"===r[e+1]&&102===t||"5"===r[e+1]&&99===t)throw new Deno.errors.InvalidData("must not include encoded \\ or / characters")}if(r=r.replace(bs,"\\"),r=decodeURIComponent(r),""!==t)return`\\\\${t}${r}`;{let e=32|r.codePointAt(1),t=r[2];if(e<gs||e>ys||":"!==t)throw new Deno.errors.InvalidData("file url path must be absolute");return r.slice(1)}}(e):function(e){if(""!==e.hostname)throw new Deno.errors.InvalidData("invalid file url hostname");let t=e.pathname;for(let e=0;e<t.length;e++)if("%"===t[e]){let r=t.codePointAt(e+2)||32;if("2"===t[e+1]&&102===r)throw new Deno.errors.InvalidData("must not include encoded / characters")}return decodeURIComponent(t)}(e)}function Fo(e){let t=xo.resolve(e),r=e.charCodeAt(e.length-1);(r===ds||ms&&r===ps)&&t[t.length-1]!==xo.sep&&(t+="/");let n=new URL("file://");return t.includes("%")&&(t=t.replace(vs,"%25")),!ms&&t.includes("\\")&&(t=t.replace(ws,"%5C")),t.includes("\n")&&(t=t.replace(_s,"%0A")),t.includes("\r")&&(t=t.replace(Es,"%0D")),t.includes("\t")&&(t=t.replace(Ss,"%09")),n.pathname=t,n}s(Co,{URL:()=>fs,Url:()=>as,default:()=>os,fileURLToPath:()=>Uo,format:()=>ls,parse:()=>hs,pathToFileURL:()=>Fo,resolve:()=>us,resolveObject:()=>cs});var Wo,$o,qo,Go,Vo,Ho,Ko,zo,Qo,Yo,Jo,Xo,Zo,es,ts,rs,ns,is,os,ss,as,ls,us,cs,hs,fs,ps,ds,gs,ys,ms,bs,vs,ws,_s,Es,Ss,Is=i(()=>{l(),tt(),Fe(),En(),wi(),To(),Ro(),Wo=Object.freeze(Object.create(null)),$o={},qo=!1,Go=typeof globalThis<"u"?globalThis:typeof self<"u"?self:global,Vo={},Ho=!1,Ko={},zo=!1,Qo={},Yo=!1,Jo={},Xo=!1,Zo={},es=!1,ts={},rs=!1,ns={},is=!1,(os=jo()).parse,os.resolve,os.resolveObject,os.format,os.Url,ss=typeof Deno<"u"?"windows"===Deno.build.os?"win32":Deno.build.os:void 0,os.URL=typeof URL<"u"?URL:null,os.pathToFileURL=Fo,os.fileURLToPath=Uo,as=os.Url,ls=os.format,us=os.resolve,cs=os.resolveObject,hs=os.parse,fs=os.URL,ps=92,ds=47,gs=97,ys=122,ms="win32"===ss,bs=/\//g,vs=/%/g,ws=/\\/g,_s=/\n/g,Es=/\r/g,Ss=/\t/g}),As=o((e,t)=>{l(),tt(),Fe(),t.exports=function(){throw new Error("ws does not work in the browser. Browser clients must use the native WebSocket object")}}),Rs=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"__esModule",{value:!0}),e.BufferedDuplex=void 0,e.writev=n;var t=$t(),r=(et(),a(Qe));function n(e,t){let n=new Array(e.length);for(let t=0;t<e.length;t++)"string"==typeof e[t].chunk?n[t]=r.Buffer.from(e[t].chunk,"utf8"):n[t]=e[t].chunk;this._write(r.Buffer.concat(n),"binary",t)}var i=class extends t.Duplex{socket;proxy;isSocketOpen;writeQueue;constructor(e,t,r){super({objectMode:!0}),this.proxy=t,this.socket=r,this.writeQueue=[],e.objectMode||(this._writev=n.bind(this)),this.isSocketOpen=!1,this.proxy.on("data",e=>{!this.destroyed&&this.readable&&this.push(e)})}_read(e){this.proxy.read(e)}_write(e,t,r){this.isSocketOpen?this.writeToProxy(e,t,r):this.writeQueue.push({chunk:e,encoding:t,cb:r})}_final(e){this.writeQueue=[],this.proxy.end(e)}_destroy(e,t){this.writeQueue=[],this.proxy.destroy(),t(e)}socketReady(){this.emit("connect"),this.isSocketOpen=!0,this.processWriteQueue()}writeToProxy(e,t,r){!1===this.proxy.write(e,t)?this.proxy.once("drain",r):r()}processWriteQueue(){for(;this.writeQueue.length>0;){let{chunk:e,encoding:t,cb:r}=this.writeQueue.shift();this.writeToProxy(e,t,r)}}};e.BufferedDuplex=i}),Os=o(e=>{l(),tt(),Fe();var t=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.streamBuilder=e.browserStreamBuilder=void 0;var r=(et(),a(Qe)),n=t(As()),i=t(Yt()),o=$t(),s=t(dn()),u=Rs(),c=(0,i.default)("mqttjs:ws"),h=["rejectUnauthorized","ca","cert","key","pfx","passphrase"];function f(e,t){let r=`${e.protocol}://${e.hostname}:${e.port}${e.path}`;return"function"==typeof e.transformWsUrl&&(r=e.transformWsUrl(r,e,t)),r}function p(e){let t=e;return e.port||("wss"===e.protocol?t.port=443:t.port=80),e.path||(t.path="/"),e.wsOptions||(t.wsOptions={}),!s.default&&!e.forceNativeWebSocket&&"wss"===e.protocol&&h.forEach(r=>{Object.prototype.hasOwnProperty.call(e,r)&&!Object.prototype.hasOwnProperty.call(e.wsOptions,r)&&(t.wsOptions[r]=e[r])}),t}e.streamBuilder=(e,t)=>{c("streamBuilder");let r=p(t);r.hostname=r.hostname||r.host||"localhost";let i=f(r,e),o=function(e,t,r){c("createWebSocket"),c(`protocol: ${r.protocolId} ${r.protocolVersion}`);let i,o="MQIsdp"===r.protocolId&&3===r.protocolVersion?"mqttv3.1":"mqtt";return c(`creating new Websocket for url: ${t} and protocol: ${o}`),i=r.createWebsocket?r.createWebsocket(t,[o],r):new n.default(t,[o],r.wsOptions),i}(0,i,r),s=n.default.createWebSocketStream(o,r.wsOptions);return s.url=i,o.on("close",()=>{s.destroy()}),s};e.browserStreamBuilder=(e,t)=>{c("browserStreamBuilder");let n,i=function(e){let t=p(e);if(t.hostname||(t.hostname=t.host),!t.hostname){if(typeof document>"u")throw new Error("Could not determine host. Specify host manually.");let e=new URL(document.URL);t.hostname=e.hostname,t.port||(t.port=Number(e.port))}return void 0===t.objectMode&&(t.objectMode=!(!0===t.binary||void 0===t.binary)),t}(t).browserBufferSize||524288,s=t.browserBufferTimeout||1e3,a=!t.objectMode,l=function(e,t){let r,n="MQIsdp"===t.protocolId&&3===t.protocolVersion?"mqttv3.1":"mqtt",i=f(t,e);return r=t.createWebsocket?t.createWebsocket(i,[n],t):new WebSocket(i,[n]),r.binaryType="arraybuffer",r}(e,t),h=function(e,t,r){let n=new o.Transform({objectMode:e.objectMode});return n._write=t,n._flush=r,n}(t,function e(t,n,o){if(l.bufferedAmount>i)return void setTimeout(e,s,t,n,o);a&&"string"==typeof t&&(t=r.Buffer.from(t,"utf8"));try{l.send(t)}catch(e){return o(e)}o()},function(e){l.close(),e()});t.objectMode||(h._writev=u.writev.bind(h)),h.on("close",()=>{l.close()});let d=typeof l.addEventListener<"u";function g(){c("WebSocket onOpen"),n instanceof u.BufferedDuplex&&n.socketReady()}function y(e){c("WebSocket onClose",e),n.end(),n.destroy()}function m(e){c("WebSocket onError",e);let t=new Error("WebSocket error");t.event=e,n.destroy(t)}async function b(e){if(!h||!h.readable||!h.writable)return;let{data:t}=e;t=t instanceof ArrayBuffer?r.Buffer.from(t):t instanceof Blob?r.Buffer.from(await new Response(t).arrayBuffer()):r.Buffer.from(t,"utf8"),h.push(t)}return l.readyState===l.OPEN?(n=h,n.socket=l):(n=new u.BufferedDuplex(t,h,l),d?l.addEventListener("open",g):l.onopen=g),d?(l.addEventListener("close",y),l.addEventListener("error",m),l.addEventListener("message",b)):(l.onclose=y,l.onerror=m,l.onmessage=b),n}}),ks={};function xs(){throw new Error("Node.js net module is not supported by JSPM core outside of Node.js")}s(ks,{Server:()=>xs,Socket:()=>xs,Stream:()=>xs,_createServerHandle:()=>xs,_normalizeArgs:()=>xs,_setSimultaneousAccepts:()=>xs,connect:()=>xs,createConnection:()=>xs,createServer:()=>xs,default:()=>Ts,isIP:()=>xs,isIPv4:()=>xs,isIPv6:()=>xs});var Ts,Cs=i(()=>{l(),tt(),Fe(),Ts={_createServerHandle:xs,_normalizeArgs:xs,_setSimultaneousAccepts:xs,connect:xs,createConnection:xs,createServer:xs,isIP:xs,isIPv4:xs,isIPv6:xs,Server:xs,Socket:xs,Stream:xs}}),Ps=o((e,t)=>{l(),tt(),Fe(),t.exports={}}),Ns=o(e=>{l(),tt(),Fe();var t=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0});var r=t((Cs(),a(ks))),n=t(Yt()),i=t(Ps()),o=(0,n.default)("mqttjs:tcp");e.default=(e,t)=>{if(t.port=t.port||1883,t.hostname=t.hostname||t.host||"localhost",t.socksProxy)return(0,i.default)(t.hostname,t.port,t.socksProxy,{timeout:t.socksTimeout});let{port:n,path:s}=t,a=t.hostname;return o("port %d and host %s",n,a),r.default.createConnection({port:n,host:a,path:s})}}),Ls={};s(Ls,{default:()=>Ms});var Ms,Bs,Ds,js,Us=i(()=>{l(),tt(),Fe(),Ms={}}),Fs=o(e=>{l(),tt(),Fe();var t=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0});var r=(Us(),a(Ls)),n=t((Cs(),a(ks))),i=t(Yt()),o=t(Ps()),s=(0,i.default)("mqttjs:tls");e.default=(e,t)=>{t.port=t.port||8883,t.host=t.hostname||t.host||"localhost",0===n.default.isIP(t.host)&&!t.servername&&(t.servername=t.host),t.rejectUnauthorized=!1!==t.rejectUnauthorized,delete t.path,s("port %d host %s rejectUnauthorized %b",t.port,t.host,t.rejectUnauthorized);let i=function(e){let{host:t,port:n,socksProxy:i,...s}=e;if(void 0!==i){let a=(0,o.default)(t,n,i,{timeout:e.socksTimeout});return(0,r.connect)({...s,socket:a})}return(0,r.connect)(e)}(t);function a(r){t.rejectUnauthorized&&e.emit("error",r),i.end()}return i.on("secureConnect",()=>{t.rejectUnauthorized&&!i.authorized?i.emit("error",new Error("TLS not authorized")):i.removeListener("error",a)}),i.on("error",a),i}}),Ws=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"__esModule",{value:!0});var t,r,n,i=(et(),a(Qe)),o=$t(),s=Rs();e.default=(e,a)=>{if(a.hostname=a.hostname||a.host,!a.hostname)throw new Error("Could not determine host. Specify host manually.");let l="MQIsdp"===a.protocolId&&3===a.protocolVersion?"mqttv3.1":"mqtt";!function(e){e.hostname||(e.hostname="localhost"),e.path||(e.path="/"),e.wsOptions||(e.wsOptions={})}(a);let u=function(e,t){let r="wxs"===e.protocol?"wss":"ws",n=`${r}://${e.hostname}${e.path}`;return e.port&&80!==e.port&&443!==e.port&&(n=`${r}://${e.hostname}:${e.port}${e.path}`),"function"==typeof e.transformWsUrl&&(n=e.transformWsUrl(n,e,t)),n}(a,e);t=wx.connectSocket({url:u,protocols:[l]}),r=function(){let e=new o.Transform;return e._write=(e,r,n)=>{t.send({data:e.buffer,success(){n()},fail(e){n(new Error(e))}})},e._flush=e=>{t.close({success(){e()}})},e}(),(n=new s.BufferedDuplex(a,r,t))._destroy=(e,r)=>{t.close({success(){r&&r(e)}})};let c=n.destroy;return n.destroy=(e,r)=>(n.destroy=c,setTimeout(()=>{t.close({fail(){n._destroy(e,r)}})},0),n),t.onOpen(()=>{n.socketReady()}),t.onMessage(e=>{let{data:t}=e;t=t instanceof ArrayBuffer?i.Buffer.from(t):i.Buffer.from(t,"utf8"),r.push(t)}),t.onClose(()=>{n.emit("close"),n.end(),n.destroy()}),t.onError(e=>{let t=new Error(e.errMsg);n.destroy(t)}),n}}),$s=o(e=>{l(),tt(),Fe(),Object.defineProperty(e,"__esModule",{value:!0});var t,r,n,i=(et(),a(Qe)),o=$t(),s=Rs(),u=!1;e.default=(e,a)=>{if(a.hostname=a.hostname||a.host,!a.hostname)throw new Error("Could not determine host. Specify host manually.");let l="MQIsdp"===a.protocolId&&3===a.protocolVersion?"mqttv3.1":"mqtt";!function(e){e.hostname||(e.hostname="localhost"),e.path||(e.path="/"),e.wsOptions||(e.wsOptions={})}(a);let c=function(e,t){let r="alis"===e.protocol?"wss":"ws",n=`${r}://${e.hostname}${e.path}`;return e.port&&80!==e.port&&443!==e.port&&(n=`${r}://${e.hostname}:${e.port}${e.path}`),"function"==typeof e.transformWsUrl&&(n=e.transformWsUrl(n,e,t)),n}(a,e);return(t=a.my).connectSocket({url:c,protocols:l}),r=function(){let e=new o.Transform;return e._write=(e,r,n)=>{t.sendSocketMessage({data:e.buffer,success(){n()},fail(){n(new Error)}})},e._flush=e=>{t.closeSocket({success(){e()}})},e}(),n=new s.BufferedDuplex(a,r,t),u||(u=!0,t.onSocketOpen(()=>{n.socketReady()}),t.onSocketMessage(e=>{if("string"==typeof e.data){let t=i.Buffer.from(e.data,"base64");r.push(t)}else{let t=new FileReader;t.addEventListener("load",()=>{t.result instanceof ArrayBuffer?r.push(i.Buffer.from(t.result)):r.push(i.Buffer.from(t.result,"utf-8"))}),t.readAsArrayBuffer(e.data)}}),t.onSocketClose(()=>{n.end(),n.destroy()}),t.onSocketError(e=>{n.destroy(e)})),n}}),qs=o(e=>{l(),tt(),Fe();var t=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.connectAsync=function(e,t,r=!0){return new Promise((n,i)=>{let o=h(e,t),s={connect:e=>{a(),n(o)},end:()=>{a(),n(o)},error:e=>{a(),o.end(),i(e)}};function a(){Object.keys(s).forEach(e=>{o.off(e,s[e])})}!1===r&&(s.close=()=>{s.error(new Error("Couldn't connect to server"))}),Object.keys(s).forEach(e=>{o.on(e,s[e])})})};var r=t(Yt()),n=t((Is(),a(Co))),i=t(mn()),o=t(dn());"function"!=typeof u?.nextTick&&(u.nextTick=setImmediate);var s=(0,r.default)("mqttjs"),c=null;function h(e,t){if(s("connecting to an MQTT broker..."),"object"==typeof e&&!t&&(t=e,e=""),t=t||{},e&&"string"==typeof e){let r=n.default.parse(e,!0),i={},s=!r.protocol&&!r.hostname&&r.path?.startsWith("/")&&(o.default||t.forceNativeWebSocket);if(null!=r.port&&(i.port=Number(r.port)),i.host=r.hostname,i.query=r.query,i.auth=r.auth,i.protocol=r.protocol,i.path=r.path,!(t={...i,...t}).protocol&&!s)throw new Error("Missing protocol");t.protocol=(t.protocol||(typeof location<"u"?"https:"===location.protocol?"wss":"ws":typeof document<"u"&&"https:"===new URL(document.URL).protocol?"wss":"ws")).replace(/:$/,"")}if(t.unixSocket=t.unixSocket||t.protocol?.includes("+unix"),t.unixSocket?t.protocol=t.protocol.replace("+unix",""):!t.protocol?.startsWith("ws")&&!t.protocol?.startsWith("wx")&&delete t.path,function(e){let t;if(e.auth)if(t=e.auth.match(/^(.+):(.+)$/),t){let[,r,n]=t;e.username=r,e.password=n}else e.username=e.auth}(t),t.query&&"string"==typeof t.query.clientId&&(t.clientId=t.query.clientId),o.default||t.unixSocket?t.socksProxy=void 0:void 0===t.socksProxy&&typeof u<"u"&&(t.socksProxy=u.env.MQTTJS_SOCKS_PROXY),t.cert&&t.key){if(!t.protocol)throw new Error("Missing secure protocol key");if(-1===["mqtts","wss","wxs","alis"].indexOf(t.protocol))switch(t.protocol){case"mqtt":t.protocol="mqtts";break;case"ws":t.protocol="wss";break;case"wx":t.protocol="wxs";break;case"ali":t.protocol="alis";break;default:throw new Error(`Unknown protocol for secure connection: "${t.protocol}"!`)}}if(c||(c={},o.default||t.forceNativeWebSocket?(c.ws=Os().browserStreamBuilder,c.wss=Os().browserStreamBuilder,c.wx=Ws().default,c.wxs=Ws().default,c.ali=$s().default,c.alis=$s().default):(c.ws=Os().streamBuilder,c.wss=Os().streamBuilder,c.mqtt=Ns().default,c.tcp=Ns().default,c.ssl=Fs().default,c.tls=c.ssl,c.mqtts=Fs().default)),!c[t.protocol]){let e=-1!==["mqtts","wss"].indexOf(t.protocol);t.protocol=["mqtt","mqtts","ws","wss","wx","wxs","ali","alis"].filter((t,r)=>(!e||r%2!=0)&&"function"==typeof c[t])[0]}if(!1===t.clean&&!t.clientId)throw new Error("Missing clientId for unclean clients");t.protocol&&(t.defaultProtocol=t.protocol);let r=new i.default(function(e){return t.servers&&((!e._reconnectCount||e._reconnectCount===t.servers.length)&&(e._reconnectCount=0),t.host=t.servers[e._reconnectCount].host,t.port=t.servers[e._reconnectCount].port,t.protocol=t.servers[e._reconnectCount].protocol?t.servers[e._reconnectCount].protocol:t.defaultProtocol,t.hostname=t.host,e._reconnectCount++),s("calling streambuilder for",t.protocol),c[t.protocol](e,t)},t);return r.on("error",()=>{}),r}e.default=h}),Gs=o(e=>{l(),tt(),Fe();var t,r=e&&e.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);(!i||("get"in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),n=e&&e.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=e&&e.__importStar||(t=function(e){return(t=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t})(e)},function(e){if(e&&e.__esModule)return e;var i={};if(null!=e)for(var o=t(e),s=0;s<o.length;s++)"default"!==o[s]&&r(i,e,o[s]);return n(i,e),i}),o=e&&e.__exportStar||function(e,t){for(var n in e)"default"!==n&&!Object.prototype.hasOwnProperty.call(t,n)&&r(t,e,n)},s=e&&e.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(e,"__esModule",{value:!0}),e.ReasonCodes=e.KeepaliveManager=e.UniqueMessageIdProvider=e.DefaultMessageIdProvider=e.Store=e.MqttClient=e.connectAsync=e.connect=e.Client=void 0;var a=s(mn());e.MqttClient=a.default;var u=s(Ur());e.DefaultMessageIdProvider=u.default;var c=s(bn());e.UniqueMessageIdProvider=c.default;var h=s(sr());e.Store=h.default;var f=i(qs());e.connect=f.default,Object.defineProperty(e,"connectAsync",{enumerable:!0,get:function(){return f.connectAsync}});var p=s(yn());e.KeepaliveManager=p.default,e.Client=a.default,o(mn(),e),o(ur(),e),o(or(),e);var d=cr();Object.defineProperty(e,"ReasonCodes",{enumerable:!0,get:function(){return d.ReasonCodes}})}),Vs=o(e=>{l(),tt(),Fe();var t,r=e&&e.__createBinding||(Object.create?function(e,t,r,n){void 0===n&&(n=r);var i=Object.getOwnPropertyDescriptor(t,r);(!i||("get"in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[r]}}),Object.defineProperty(e,n,i)}:function(e,t,r,n){void 0===n&&(n=r),e[n]=t[r]}),n=e&&e.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),i=e&&e.__importStar||(t=function(e){return(t=Object.getOwnPropertyNames||function(e){var t=[];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[t.length]=r);return t})(e)},function(e){if(e&&e.__esModule)return e;var i={};if(null!=e)for(var o=t(e),s=0;s<o.length;s++)"default"!==o[s]&&r(i,e,o[s]);return n(i,e),i}),o=e&&e.__exportStar||function(e,t){for(var n in e)"default"!==n&&!Object.prototype.hasOwnProperty.call(t,n)&&r(t,e,n)};Object.defineProperty(e,"__esModule",{value:!0});var s=i(Gs());e.default=s,o(Gs(),e)})();!function(e){e.DISCONNECTED="disconnected",e.CONNECTING="connecting",e.CONNECTED="connected",e.RECONNECTING="reconnecting",e.DISCONNECTING="disconnecting"}(Bs||(Bs={})),function(e){e[e.FAST=0]="FAST",e[e.RELIABLE=1]="RELIABLE",e[e.EXACT_ONCE=2]="EXACT_ONCE"}(Ds||(Ds={}));class Hs{constructor(e,t,r=Ds.RELIABLE,n=!1,i,o){this.channel=e,this.payload="string"==typeof t?(new TextEncoder).encode(t):t,this.mode=r,this.persist=n,this.timestamp=i??Date.now(),this.id=o??crypto.randomUUID()}payloadAsString(){return(new TextDecoder).decode(this.payload)}payloadAsJson(){return JSON.parse(this.payloadAsString())}toString(){return`PNMessage(id='${this.id}', channel='${this.channel}', mode=${this.mode}, size=${this.payload.length})`}static text(e,t,r=Ds.RELIABLE){return new Hs(e,t,r)}static json(e,t,r=Ds.RELIABLE){return new Hs(e,JSON.stringify(t),r)}static fromInternal(e,t,r,n){return new Hs(e,t,function(e){switch(e){case 0:return Ds.FAST;case 2:return Ds.EXACT_ONCE;default:return Ds.RELIABLE}}(r),n)}}!function(e){e[e.UNKNOWN=0]="UNKNOWN",e[e.CONNECTION_FAILED=100]="CONNECTION_FAILED",e[e.CONNECTION_LOST=101]="CONNECTION_LOST",e[e.CONNECTION_TIMEOUT=102]="CONNECTION_TIMEOUT",e[e.AUTH_FAILED=200]="AUTH_FAILED",e[e.AUTH_EXPIRED=201]="AUTH_EXPIRED",e[e.STREAM_FAILED=300]="STREAM_FAILED",e[e.DETACH_FAILED=301]="DETACH_FAILED",e[e.DISPATCH_FAILED=400]="DISPATCH_FAILED",e[e.INVALID_CONFIG=500]="INVALID_CONFIG",e[e.INVALID_MESSAGE=501]="INVALID_MESSAGE",e[e.NOT_CONNECTED=600]="NOT_CONNECTED"}(js||(js={}));class Ks extends Error{constructor(e,t,r){super(t),this.name="PNError",this.code=e,this.details=r}toString(){return`PNError(code=${this.code}, message='${this.message}')`}static connectionFailed(e,t){return new Ks(js.CONNECTION_FAILED,e,t)}static connectionLost(e,t){return new Ks(js.CONNECTION_LOST,e,t)}static connectionTimeout(e){return new Ks(js.CONNECTION_TIMEOUT,e)}static authFailed(e,t){return new Ks(js.AUTH_FAILED,e,t)}static authExpired(e){return new Ks(js.AUTH_EXPIRED,e)}static notConnected(){return new Ks(js.NOT_CONNECTED,"Not connected. Call open() first.")}static invalidConfig(e){return new Ks(js.INVALID_CONFIG,e)}static fromException(e,t="Unknown error"){return new Ks(js.UNKNOWN,e.message||t,e.stack)}}const zs="PNSocket",Qs=(e,t)=>{"undefined"!=typeof console&&(()=>{try{if("undefined"!=typeof process&&process.env?.NODE_ENV)return"production"!==process.env.NODE_ENV}catch{}return!0})()&&console.log(`[${e}] ${t}`)},Ys=(e,t)=>{"undefined"!=typeof console&&console.error(`[${e}] ERROR: ${t}`)};class Js{constructor(e){this.client=null,this._state=Bs.DISCONNECTED,this.activeChannels=new Set,this.connectionListeners=[],this.messageListeners=new Map,this.errorListeners=[],this.retryAttempt=0,this.isRetrying=!1,this.manualDisconnect=!1,this.retryTimer=null,this.config=e}get state(){return this._state}open(){return this._state===Bs.CONNECTED||this._state===Bs.CONNECTING||(this.manualDisconnect=!1,this.resetRetryState(),this.connectInternal()),this}close(){return this._state===Bs.DISCONNECTED||(Qs(zs,"Closing connection"),this.manualDisconnect=!0,this.cancelRetry(),this.setState(Bs.DISCONNECTING),this.client?.end(!0),this.client=null,this.activeChannels.clear(),this.setState(Bs.DISCONNECTED)),this}stream(e,t,r=Ds.RELIABLE){if(this._state!==Bs.CONNECTED){const e=Ks.notConnected();return this.notifyError(e),this}return this.messageListeners.has(e)||this.messageListeners.set(e,[]),this.messageListeners.get(e).push(t),this.activeChannels.has(e)||(this.client?.subscribe(e,{qos:r}),this.activeChannels.add(e),Qs(zs,`Streaming from channel: ${e}`)),this}streamPattern(e,t,r=Ds.RELIABLE){return this.stream(e,t,r)}detach(e){return this.activeChannels.has(e)?(this.client?.unsubscribe(e),this.activeChannels.delete(e),this.messageListeners.delete(e),Qs(zs,`Detached from channel: ${e}`),this):this}dispatch(e){if(this._state!==Bs.CONNECTED){const e=Ks.notConnected();return this.notifyError(e),this}return this.client?.publish(e.channel,Buffer.from(e.payload),{qos:e.mode,retain:e.persist}),Qs(zs,`Dispatched message to ${e.channel}`),this}dispatchText(e,t,r=Ds.RELIABLE){return this.dispatch(Hs.text(e,t,r))}dispatchJson(e,t,r=Ds.RELIABLE){return this.dispatch(Hs.json(e,t,r))}isConnected(){return this._state===Bs.CONNECTED&&!0===this.client?.connected}getActiveChannels(){return new Set(this.activeChannels)}addConnectionListener(e){return this.connectionListeners.push(e),this}removeConnectionListener(e){const t=this.connectionListeners.indexOf(e);return-1!==t&&this.connectionListeners.splice(t,1),this}addErrorListener(e){return this.errorListeners.push(e),this}removeErrorListener(e){const t=this.errorListeners.indexOf(e);return-1!==t&&this.errorListeners.splice(t,1),this}connectInternal(){this.setState(Bs.CONNECTING);const{gateway:e,port:t=443,clientId:r,secure:n=!0,wsPath:i="/mqtt"}=this.config,o=`${n?"wss":"ws"}://${e}:${t}${i}`;Qs(zs,`Connecting to gateway: ${o} (clientId: ${r})`);const s={clientId:r,clean:this.config.freshStart??!0,keepalive:this.config.heartbeatInterval??60,connectTimeout:1e3*(this.config.connectionTimeout??30),reconnectPeriod:0,protocolVersion:5};if(this.config.auth&&("basic"===this.config.auth.type?(s.username=this.config.auth.username,s.password=this.config.auth.password):"token"===this.config.auth.type&&(s.username="jwt",s.password=this.config.auth.token)),this.config.exitSignal){const e="string"==typeof this.config.exitSignal.payload?(new TextEncoder).encode(this.config.exitSignal.payload):this.config.exitSignal.payload;s.will={topic:this.config.exitSignal.channel,payload:Buffer.from(e),qos:this.config.exitSignal.mode??Ds.RELIABLE,retain:this.config.exitSignal.persist??!1}}this.client=Vs.connect(o,s),this.client.on("connect",()=>{Qs(zs,"Connected to gateway"),this.resetRetryState(),this.setState(Bs.CONNECTED),this.notifyConnected(),this.resubscribeChannels()}),this.client.on("message",(e,t)=>{const r=Hs.fromInternal(e,new Uint8Array(t),1,!1);Qs(zs,`Message received on channel: ${e}`),this.notifyMessage(r)}),this.client.on("close",()=>{Qs(zs,`Connection closed (manualDisconnect: ${this.manualDisconnect})`),this.setState(Bs.DISCONNECTED),this.notifyDisconnected(),!this.manualDisconnect&&this.config.autoReconnect&&this.scheduleRetry()}),this.client.on("disconnect",e=>{Qs(zs,`Disconnect packet received: ${JSON.stringify(e)}`)}),this.client.on("error",e=>{Ys(zs,`Connection error: ${e.message}`);const t=Ks.connectionFailed(e.message);this.notifyError(t),!this.manualDisconnect&&this.config.autoReconnect&&this.scheduleRetry()}),this.client.on("offline",()=>{Qs(zs,"Client offline"),this._state!==Bs.DISCONNECTING&&this.setState(Bs.DISCONNECTED)})}resubscribeChannels(){if(0!==this.activeChannels.size){for(const e of this.activeChannels)this.client?.subscribe(e,{qos:Ds.RELIABLE});Qs(zs,`Resubscribed to ${this.activeChannels.size} channels`)}}calculateRetryDelay(e){const t=(this.config.reconnectDelay??1e3)*Math.pow(2,e),r=Math.min(t,this.config.maxReconnectDelay??3e5);return r+.2*r*(2*Math.random()-1)}scheduleRetry(){if(this.manualDisconnect)return;const e=this.config.maxReconnectAttempts??10;if(e>0&&this.retryAttempt>=e){Ys(zs,`Max retry attempts (${e}) reached`);const t=Ks.connectionFailed(`Max retry attempts reached after ${this.retryAttempt} attempts`);return void this.notifyError(t)}const t=this.calculateRetryDelay(this.retryAttempt);Qs(zs,`Scheduling retry ${this.retryAttempt+1} in ${t}ms`),this.setState(Bs.RECONNECTING),this.notifyReconnecting(this.retryAttempt,t),this.isRetrying=!0,this.retryTimer=setTimeout(()=>{this.retryAttempt++,Qs(zs,`Executing retry attempt ${this.retryAttempt}`),this.connectInternal()},t)}cancelRetry(){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=null),this.isRetrying=!1}resetRetryState(){this.retryAttempt=0,this.isRetrying=!1,this.cancelRetry()}setState(e){this._state=e,this.connectionListeners.forEach(t=>t.onStateChanged?.(e))}notifyConnected(){this.connectionListeners.forEach(e=>e.onConnected?.())}notifyDisconnected(e){this.connectionListeners.forEach(t=>t.onDisconnected?.(e))}notifyReconnecting(e,t){this.connectionListeners.forEach(r=>r.onReconnecting?.(e,t))}notifyError(e){this.errorListeners.forEach(t=>t(e))}notifyMessage(e){const t=this.messageListeners.get(e.channel);t?.forEach(t=>t(e));for(const[t,r]of this.messageListeners)t!==e.channel&&this.matchesPattern(t,e.channel)&&r.forEach(t=>t(e))}matchesPattern(e,t){if(!e.includes("+")&&!e.includes("#"))return e===t;const r=e.split("/"),n=t.split("/");let i=0;for(const e of r){if("#"===e)return!0;if("+"!==e){if(i>=n.length||n[i]!==e)return!1;i++}else i++}return i===n.length}}const Xs={basic:(e,t)=>({type:"basic",username:e,password:t}),token:e=>({type:"token",token:e})};class Zs{constructor(){this.config={port:443,heartbeatInterval:60,connectionTimeout:30,freshStart:!0,autoReconnect:!0,maxReconnectAttempts:10,reconnectDelay:1e3,maxReconnectDelay:3e5,secure:!0,wsPath:"/mqtt"}}gateway(e){return this.config.gateway=e,this}port(e){return this.config.port=e,this}clientId(e){return this.config.clientId=e,this}auth(e){return this.config.auth=e,this}heartbeatInterval(e){return this.config.heartbeatInterval=e,this}connectionTimeout(e){return this.config.connectionTimeout=e,this}freshStart(e){return this.config.freshStart=e,this}autoReconnect(e){return this.config.autoReconnect=e,this}maxReconnectAttempts(e){return this.config.maxReconnectAttempts=e,this}reconnectDelay(e){return this.config.reconnectDelay=e,this}maxReconnectDelay(e){return this.config.maxReconnectDelay=e,this}exitSignal(e){return this.config.exitSignal=e,this}secure(e){return this.config.secure=e,this}wsPath(e){return this.config.wsPath=e,this}build(){if(!this.config.gateway)throw new Error("Gateway is required");if(!this.config.clientId)throw new Error("Client ID is required");return this.config}}var ea;exports.RiviumPushErrorCode=void 0,(ea=exports.RiviumPushErrorCode||(exports.RiviumPushErrorCode={}))[ea.CONNECTION_FAILED=1e3]="CONNECTION_FAILED",ea[ea.CONNECTION_TIMEOUT=1001]="CONNECTION_TIMEOUT",ea[ea.CONNECTION_LOST=1002]="CONNECTION_LOST",ea[ea.CONNECTION_REFUSED=1003]="CONNECTION_REFUSED",ea[ea.AUTHENTICATION_FAILED=1004]="AUTHENTICATION_FAILED",ea[ea.SSL_ERROR=1005]="SSL_ERROR",ea[ea.BROKER_UNAVAILABLE=1006]="BROKER_UNAVAILABLE",ea[ea.SUBSCRIPTION_FAILED=1100]="SUBSCRIPTION_FAILED",ea[ea.UNSUBSCRIPTION_FAILED=1101]="UNSUBSCRIPTION_FAILED",ea[ea.INVALID_TOPIC=1102]="INVALID_TOPIC",ea[ea.MESSAGE_DELIVERY_FAILED=1200]="MESSAGE_DELIVERY_FAILED",ea[ea.MESSAGE_PARSE_ERROR=1201]="MESSAGE_PARSE_ERROR",ea[ea.MESSAGE_TIMEOUT=1202]="MESSAGE_TIMEOUT",ea[ea.INVALID_CONFIG=1300]="INVALID_CONFIG",ea[ea.MISSING_API_KEY=1301]="MISSING_API_KEY",ea[ea.MISSING_SERVER_URL=1302]="MISSING_SERVER_URL",ea[ea.INVALID_CREDENTIALS=1303]="INVALID_CREDENTIALS",ea[ea.REGISTRATION_FAILED=1400]="REGISTRATION_FAILED",ea[ea.DEVICE_ID_GENERATION_FAILED=1401]="DEVICE_ID_GENERATION_FAILED",ea[ea.SERVER_ERROR=1402]="SERVER_ERROR",ea[ea.NETWORK_ERROR=1403]="NETWORK_ERROR",ea[ea.NOT_INITIALIZED=1500]="NOT_INITIALIZED",ea[ea.NOT_CONNECTED=1501]="NOT_CONNECTED",ea[ea.ALREADY_CONNECTED=1502]="ALREADY_CONNECTED",ea[ea.SERVICE_NOT_RUNNING=1503]="SERVICE_NOT_RUNNING",ea[ea.PERMISSION_DENIED=1600]="PERMISSION_DENIED",ea[ea.PERMISSION_DISMISSED=1601]="PERMISSION_DISMISSED",ea[ea.UNKNOWN_ERROR=9999]="UNKNOWN_ERROR";const ta={[exports.RiviumPushErrorCode.CONNECTION_FAILED]:"Failed to connect to MQTT broker",[exports.RiviumPushErrorCode.CONNECTION_TIMEOUT]:"Connection timed out",[exports.RiviumPushErrorCode.CONNECTION_LOST]:"Connection to server was lost",[exports.RiviumPushErrorCode.CONNECTION_REFUSED]:"Connection was refused by server",[exports.RiviumPushErrorCode.AUTHENTICATION_FAILED]:"Authentication failed - invalid credentials",[exports.RiviumPushErrorCode.SSL_ERROR]:"SSL/TLS handshake failed",[exports.RiviumPushErrorCode.BROKER_UNAVAILABLE]:"MQTT broker is unavailable",[exports.RiviumPushErrorCode.SUBSCRIPTION_FAILED]:"Failed to subscribe to topic",[exports.RiviumPushErrorCode.UNSUBSCRIPTION_FAILED]:"Failed to unsubscribe from topic",[exports.RiviumPushErrorCode.INVALID_TOPIC]:"Invalid topic format",[exports.RiviumPushErrorCode.MESSAGE_DELIVERY_FAILED]:"Failed to deliver message",[exports.RiviumPushErrorCode.MESSAGE_PARSE_ERROR]:"Failed to parse message payload",[exports.RiviumPushErrorCode.MESSAGE_TIMEOUT]:"Message delivery timed out",[exports.RiviumPushErrorCode.INVALID_CONFIG]:"Invalid configuration",[exports.RiviumPushErrorCode.MISSING_API_KEY]:"API key is missing",[exports.RiviumPushErrorCode.MISSING_SERVER_URL]:"Server URL is missing",[exports.RiviumPushErrorCode.INVALID_CREDENTIALS]:"Invalid MQTT credentials",[exports.RiviumPushErrorCode.REGISTRATION_FAILED]:"Device registration failed",[exports.RiviumPushErrorCode.DEVICE_ID_GENERATION_FAILED]:"Failed to generate device ID",[exports.RiviumPushErrorCode.SERVER_ERROR]:"Server returned an error",[exports.RiviumPushErrorCode.NETWORK_ERROR]:"Network request failed",[exports.RiviumPushErrorCode.NOT_INITIALIZED]:"SDK is not initialized",[exports.RiviumPushErrorCode.NOT_CONNECTED]:"Not connected to server",[exports.RiviumPushErrorCode.ALREADY_CONNECTED]:"Already connected to server",[exports.RiviumPushErrorCode.SERVICE_NOT_RUNNING]:"Service worker is not running",[exports.RiviumPushErrorCode.PERMISSION_DENIED]:"Notification permission denied",[exports.RiviumPushErrorCode.PERMISSION_DISMISSED]:"Notification permission dismissed",[exports.RiviumPushErrorCode.UNKNOWN_ERROR]:"An unknown error occurred"};class ra extends Error{constructor(e,t){super(ta[e]||"Unknown error"),this.name="RiviumPushError",this.code=e,this.details=t}toJSON(){return{code:this.code,message:this.message,details:this.details}}}var na,ia,oa;exports.RiviumPushAnalyticsEvent=void 0,(na=exports.RiviumPushAnalyticsEvent||(exports.RiviumPushAnalyticsEvent={})).SDK_INITIALIZED="sdkInitialized",na.DEVICE_REGISTERED="deviceRegistered",na.DEVICE_UNREGISTERED="deviceUnregistered",na.MESSAGE_RECEIVED="messageReceived",na.MESSAGE_DISPLAYED="messageDisplayed",na.NOTIFICATION_CLICKED="notificationClicked",na.ACTION_CLICKED="actionClicked",na.CONNECTED="connected",na.DISCONNECTED="disconnected",na.CONNECTION_ERROR="connectionError",na.RETRY_STARTED="retryStarted",na.TOPIC_SUBSCRIBED="topicSubscribed",na.TOPIC_UNSUBSCRIBED="topicUnsubscribed",na.NETWORK_STATE_CHANGED="networkStateChanged",na.APP_STATE_CHANGED="appStateChanged",na.PERMISSION_REQUESTED="permissionRequested",na.PERMISSION_GRANTED="permissionGranted",na.PERMISSION_DENIED="permissionDenied",exports.RiviumPushLogLevel=void 0,(ia=exports.RiviumPushLogLevel||(exports.RiviumPushLogLevel={}))[ia.NONE=0]="NONE",ia[ia.ERROR=1]="ERROR",ia[ia.WARNING=2]="WARNING",ia[ia.INFO=3]="INFO",ia[ia.DEBUG=4]="DEBUG",ia[ia.VERBOSE=5]="VERBOSE",exports.NetworkType=void 0,(oa=exports.NetworkType||(exports.NetworkType={})).WIFI="wifi",oa.CELLULAR="cellular",oa.ETHERNET="ethernet",oa.NONE="none",oa.UNKNOWN="unknown";const sa="https://push-api.rivium.co";class aa{constructor(e){var t;if(this.deviceId=null,this.subscriptionId=null,this.userId=null,this.pnSocket=null,this.serviceWorkerRegistration=null,this.pushSubscription=null,this.connectionState="disconnected",this.reconnectAttempts=0,this.maxReconnectAttempts=10,this.reconnectTimer=null,this.subscribedTopics=new Set,this.badgeCount=0,this.initialized=!1,this.initialMessage=null,this.mqttConfig=null,this.mqttConfigFetched=!1,this.appId=null,this.appIdentifier=null,this.vapidPublicKey=null,this.logLevel=exports.RiviumPushLogLevel.DEBUG,this.analyticsCallback=null,this.analyticsEnabled=!1,this.onMessageCallback=null,this.onConnectionStateCallback=null,this.onRegisteredCallback=null,this.onErrorCallback=null,this.onDetailedErrorCallback=null,this.onNotificationClickCallback=null,this.onActionClickedCallback=null,this.onReconnectingCallback=null,this.onNetworkStateCallback=null,this.onAppStateCallback=null,!e.apiKey)throw new Error("RiviumPush: apiKey is required");this.config={serviceWorkerPath:"/rivium-push-sw.js",autoRegisterServiceWorker:!0,mqttQos:1,maxReconnectAttempts:10,logLevel:exports.RiviumPushLogLevel.ERROR,...e},this.maxReconnectAttempts=this.config.maxReconnectAttempts,this.logLevel=this.config.logLevel,"undefined"!=typeof window?(this.deviceId=this.getOrCreateDeviceId(),this.subscriptionId=localStorage.getItem("rivium_push_subscription_id")||null,this.userId=localStorage.getItem("rivium_push_user_id")||null,this.badgeCount=parseInt(localStorage.getItem("rivium_push_badge_count")||"0",10),this.checkInitialMessage(),"serviceWorker"in navigator&&navigator.serviceWorker.addEventListener("message",this.handleServiceWorkerMessage.bind(this)),document.addEventListener("visibilitychange",this.handleVisibilityChange.bind(this)),"connection"in navigator&&(null===(t=navigator.connection)||void 0===t||t.addEventListener("change",this.handleNetworkChange.bind(this))),window.addEventListener("online",this.handleOnline.bind(this)),window.addEventListener("offline",this.handleOffline.bind(this)),this.initialized=!0,this.trackEvent(exports.RiviumPushAnalyticsEvent.SDK_INITIALIZED),this.log(exports.RiviumPushLogLevel.INFO,"RiviumPush SDK initialized"),this.fetchMqttConfig()):this.initialized=!0}async fetchMqttConfig(){try{this.log(exports.RiviumPushLogLevel.DEBUG,"Fetching config from server...");const e=await fetch(`${sa}/devices/config`,{method:"GET",headers:{"Content-Type":"application/json","x-api-key":this.config.apiKey}});if(!e.ok)throw new Error(`HTTP ${e.status}`);const t=await e.json();this.mqttConfig=t.mqtt,this.mqttConfigFetched=!0,t.vapidPublicKey&&(this.vapidPublicKey=t.vapidPublicKey,this.log(exports.RiviumPushLogLevel.DEBUG,"VAPID public key received from server")),this.log(exports.RiviumPushLogLevel.INFO,`Config fetched successfully, vapid=${!!this.vapidPublicKey}`)}catch(e){this.log(exports.RiviumPushLogLevel.ERROR,"Failed to fetch config:",e),this.emitError(exports.RiviumPushErrorCode.INVALID_CONFIG,`Failed to fetch config: ${e.message}`)}}log(e,t,...r){if(e>this.logLevel)return;const n="[RiviumPush]";switch(e){case exports.RiviumPushLogLevel.ERROR:console.error(n,t,...r);break;case exports.RiviumPushLogLevel.WARNING:console.warn(n,t,...r);break;case exports.RiviumPushLogLevel.INFO:console.info(n,t,...r);break;case exports.RiviumPushLogLevel.DEBUG:case exports.RiviumPushLogLevel.VERBOSE:console.log(n,t,...r)}}setLogLevel(e){this.logLevel=e,this.log(exports.RiviumPushLogLevel.INFO,`Log level set to ${exports.RiviumPushLogLevel[e]}`)}getLogLevel(){return this.logLevel}trackEvent(e,t){if(this.analyticsEnabled&&this.analyticsCallback)try{this.analyticsCallback(e,t)}catch(e){this.log(exports.RiviumPushLogLevel.ERROR,"Analytics callback error:",e)}this.log(exports.RiviumPushLogLevel.VERBOSE,`Analytics event: ${e}`,t)}setAnalyticsHandler(e){this.analyticsCallback=e,this.analyticsEnabled=!0,this.log(exports.RiviumPushLogLevel.INFO,"Analytics handler set")}disableAnalytics(){this.analyticsCallback=null,this.analyticsEnabled=!1,this.log(exports.RiviumPushLogLevel.INFO,"Analytics disabled")}isAnalyticsEnabled(){return this.analyticsEnabled}emitError(e,t){const r=new ra(e,t);this.log(exports.RiviumPushLogLevel.ERROR,`Error [${e}]: ${r.message}`,t),this.onDetailedErrorCallback&&this.onDetailedErrorCallback(r),this.onErrorCallback&&this.onErrorCallback(r),this.trackEvent(exports.RiviumPushAnalyticsEvent.CONNECTION_ERROR,{errorCode:e,errorMessage:r.message,details:t})}async register(e){var t,r;try{this.mqttConfigFetched||(this.log(exports.RiviumPushLogLevel.DEBUG,"Waiting for server config..."),await this.waitForConfig()),this.config.autoRegisterServiceWorker&&await this.registerServiceWorker(),this.trackEvent(exports.RiviumPushAnalyticsEvent.PERMISSION_REQUESTED);const n=await this.requestNotificationPermission();if("denied"===n)throw this.trackEvent(exports.RiviumPushAnalyticsEvent.PERMISSION_DENIED),this.emitError(exports.RiviumPushErrorCode.PERMISSION_DENIED),new ra(exports.RiviumPushErrorCode.PERMISSION_DENIED);if("default"===n)throw this.trackEvent(exports.RiviumPushAnalyticsEvent.PERMISSION_DENIED),this.emitError(exports.RiviumPushErrorCode.PERMISSION_DISMISSED,"User dismissed the permission prompt"),new ra(exports.RiviumPushErrorCode.PERMISSION_DISMISSED);this.trackEvent(exports.RiviumPushAnalyticsEvent.PERMISSION_GRANTED);const i=this.vapidPublicKey||this.config.vapidPublicKey;if(i&&this.serviceWorkerRegistration)try{this.pushSubscription=await this.subscribeToPush(i),this.log(exports.RiviumPushLogLevel.INFO,"Web Push subscription created for background notifications")}catch(e){this.log(exports.RiviumPushLogLevel.WARNING,"Web Push subscription failed (will use MQTT only):",e)}const o={...e,userId:null!==(r=null!==(t=null==e?void 0:e.userId)&&void 0!==t?t:this.userId)&&void 0!==r?r:void 0},s=await this.registerDevice(o);return this.deviceId=s.deviceId,this.connectToGateway(),this.onRegisteredCallback&&this.onRegisteredCallback(s.deviceId),this.trackEvent(exports.RiviumPushAnalyticsEvent.DEVICE_REGISTERED,{deviceId:s.deviceId,userId:null==e?void 0:e.userId,hasWebPush:!!this.pushSubscription}),this.log(exports.RiviumPushLogLevel.INFO,"Registered with device ID:",s.deviceId,"Web Push:",!!this.pushSubscription),s.deviceId}catch(e){if(e instanceof ra)throw e;throw this.log(exports.RiviumPushLogLevel.ERROR,"Registration failed:",e),this.emitError(exports.RiviumPushErrorCode.REGISTRATION_FAILED,e.message),e}}async waitForConfig(e=5e3){const t=Date.now();for(;!this.mqttConfigFetched&&Date.now()-t<e;)await new Promise(e=>setTimeout(e,100));this.mqttConfigFetched||this.log(exports.RiviumPushLogLevel.WARNING,"Config fetch timed out, continuing without it")}async unregister(){this.disconnectFromGateway(),this.pushSubscription&&(await this.pushSubscription.unsubscribe(),this.pushSubscription=null),this.trackEvent(exports.RiviumPushAnalyticsEvent.DEVICE_UNREGISTERED,{deviceId:this.deviceId}),this.log(exports.RiviumPushLogLevel.INFO,"Unregistered")}async subscribeTopic(e){if(e&&""!==e.trim()){if(this.subscribedTopics.add(e),this.deviceId)try{await fetch(`${sa}/topics/subscribe`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.config.apiKey},body:JSON.stringify({deviceId:this.deviceId,topic:e})})}catch(e){this.log(exports.RiviumPushLogLevel.WARNING,"Failed to register topic on server:",e)}if(this.pnSocket&&this.pnSocket.isConnected()){const t=`rivium_push/${this.config.apiKey.substring(0,16)}/topic/${e}`;this.pnSocket.stream(t,e=>{this.handlePNMessage(e)},this.config.mqttQos),this.log(exports.RiviumPushLogLevel.INFO,"Subscribed to topic:",e),this.trackEvent(exports.RiviumPushAnalyticsEvent.TOPIC_SUBSCRIBED,{topic:e})}}else this.emitError(exports.RiviumPushErrorCode.INVALID_TOPIC,"Topic cannot be empty")}async unsubscribeTopic(e){if(this.subscribedTopics.delete(e),this.deviceId)try{await fetch(`${sa}/topics/unsubscribe`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.config.apiKey},body:JSON.stringify({deviceId:this.deviceId,topic:e})})}catch(e){this.log(exports.RiviumPushLogLevel.WARNING,"Failed to unregister topic on server:",e)}if(this.pnSocket&&this.pnSocket.isConnected()){const t=`rivium_push/${this.config.apiKey.substring(0,16)}/topic/${e}`;this.pnSocket.detach(t),this.log(exports.RiviumPushLogLevel.INFO,"Unsubscribed from topic:",e),this.trackEvent(exports.RiviumPushAnalyticsEvent.TOPIC_UNSUBSCRIBED,{topic:e})}}isConnected(){return"connected"===this.connectionState}getDeviceId(){return this.deviceId}getSubscriptionId(){return this.subscriptionId}async setUserId(e){this.userId=e,localStorage.setItem("rivium_push_user_id",e),await this.registerDevice({userId:e}),this.log(exports.RiviumPushLogLevel.INFO,"User ID set:",e)}clearUserId(){this.userId=null,localStorage.removeItem("rivium_push_user_id"),this.log(exports.RiviumPushLogLevel.INFO,"User ID cleared")}getUserId(){return this.userId}getInitialMessage(){return this.initialMessage}getBadgeCount(){return this.badgeCount}setBadgeCount(e){this.badgeCount=Math.max(0,e),localStorage.setItem("rivium_push_badge_count",this.badgeCount.toString()),this.updateFaviconBadge(this.badgeCount),"setAppBadge"in navigator&&(this.badgeCount>0?navigator.setAppBadge(this.badgeCount):navigator.clearAppBadge())}clearBadge(){this.setBadgeCount(0)}async refreshMqttToken(){if(!this.deviceId)throw new ra(exports.RiviumPushErrorCode.NOT_INITIALIZED,"Device not registered");try{const e=await fetch(`${sa}/devices/${this.deviceId}/mqtt-token/refresh`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.config.apiKey}});if(!e.ok){const t=await e.json().catch(()=>({}));throw new ra(exports.RiviumPushErrorCode.SERVER_ERROR,t.message||`HTTP ${e.status}`)}const t=await e.json();t.token&&this.mqttConfig&&(this.mqttConfig.token=t.token,this.log(exports.RiviumPushLogLevel.INFO,"MQTT token refreshed successfully"))}catch(e){if(e instanceof ra)throw e;throw new ra(exports.RiviumPushErrorCode.NETWORK_ERROR,e.message)}}getNetworkState(){const e=navigator.connection;return{isAvailable:navigator.onLine,networkType:this.detectNetworkType(),effectiveType:null==e?void 0:e.effectiveType,downlink:null==e?void 0:e.downlink,rtt:null==e?void 0:e.rtt}}getAppState(){return{isVisible:"visible"===document.visibilityState,visibilityState:document.visibilityState}}static isSupported(){return"undefined"!=typeof window&&"Notification"in window&&"serviceWorker"in navigator}static getPermissionStatus(){return"undefined"==typeof Notification?"denied":Notification.permission}onMessage(e){return this.onMessageCallback=e,()=>{this.onMessageCallback=null}}onConnectionState(e){return this.onConnectionStateCallback=e,()=>{this.onConnectionStateCallback=null}}onRegistered(e){return this.onRegisteredCallback=e,()=>{this.onRegisteredCallback=null}}onError(e){return this.onErrorCallback=e,()=>{this.onErrorCallback=null}}onDetailedError(e){return this.onDetailedErrorCallback=e,()=>{this.onDetailedErrorCallback=null}}onNotificationClick(e){return this.onNotificationClickCallback=e,()=>{this.onNotificationClickCallback=null}}onActionClicked(e){return this.onActionClickedCallback=e,()=>{this.onActionClickedCallback=null}}onReconnecting(e){return this.onReconnectingCallback=e,()=>{this.onReconnectingCallback=null}}onNetworkState(e){return this.onNetworkStateCallback=e,()=>{this.onNetworkStateCallback=null}}onAppState(e){return this.onAppStateCallback=e,()=>{this.onAppStateCallback=null}}detectNetworkType(){const e=navigator.connection;if(!e)return exports.NetworkType.UNKNOWN;switch(e.type){case"wifi":return exports.NetworkType.WIFI;case"cellular":return exports.NetworkType.CELLULAR;case"ethernet":return exports.NetworkType.ETHERNET;case"none":return exports.NetworkType.NONE;default:return exports.NetworkType.UNKNOWN}}handleNetworkChange(){const e=this.getNetworkState();this.log(exports.RiviumPushLogLevel.DEBUG,"Network state changed:",e),this.onNetworkStateCallback&&this.onNetworkStateCallback(e),this.trackEvent(exports.RiviumPushAnalyticsEvent.NETWORK_STATE_CHANGED,{isAvailable:e.isAvailable,networkType:e.networkType,effectiveType:e.effectiveType})}handleOnline(){this.log(exports.RiviumPushLogLevel.INFO,"Network online"),this.handleNetworkChange(),"disconnected"===this.connectionState&&this.deviceId&&(this.log(exports.RiviumPushLogLevel.INFO,"Reconnecting after network restored"),this.connectToGateway())}handleOffline(){this.log(exports.RiviumPushLogLevel.INFO,"Network offline"),this.handleNetworkChange()}handleVisibilityChange(){const e=this.getAppState();this.log(exports.RiviumPushLogLevel.DEBUG,"App state changed:",e),this.onAppStateCallback&&this.onAppStateCallback(e),this.trackEvent(exports.RiviumPushAnalyticsEvent.APP_STATE_CHANGED,{isVisible:e.isVisible,visibilityState:e.visibilityState}),e.isVisible&&("disconnected"===this.connectionState||"error"===this.connectionState)&&this.deviceId&&(this.reconnectAttempts=0,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.log(exports.RiviumPushLogLevel.INFO,"Reconnecting after becoming visible"),this.connectToGateway())}checkInitialMessage(){if("undefined"!=typeof window){const e=new URLSearchParams(window.location.search).get("rivium_push_notification");if(e)try{this.initialMessage=JSON.parse(decodeURIComponent(e)),this.log(exports.RiviumPushLogLevel.INFO,"Initial message found:",this.initialMessage)}catch(e){this.log(exports.RiviumPushLogLevel.WARNING,"Failed to parse initial message:",e)}const t=sessionStorage.getItem("rivium_push_initial_message");if(t&&!this.initialMessage)try{this.initialMessage=JSON.parse(t),sessionStorage.removeItem("rivium_push_initial_message"),this.log(exports.RiviumPushLogLevel.INFO,"Initial message from session:",this.initialMessage)}catch(e){this.log(exports.RiviumPushLogLevel.WARNING,"Failed to parse stored message:",e)}}}async registerServiceWorker(){if(!("serviceWorker"in navigator))throw new ra(exports.RiviumPushErrorCode.SERVICE_NOT_RUNNING,"Service Workers not supported");try{this.serviceWorkerRegistration=await navigator.serviceWorker.register(this.config.serviceWorkerPath,{scope:"/"}),this.log(exports.RiviumPushLogLevel.INFO,"Service Worker registered")}catch(e){throw this.log(exports.RiviumPushLogLevel.ERROR,"Service Worker registration failed:",e),new ra(exports.RiviumPushErrorCode.SERVICE_NOT_RUNNING,e.message)}}async requestNotificationPermission(){return"undefined"==typeof Notification?"denied":"granted"===Notification.permission?"granted":await Notification.requestPermission()}async subscribeToPush(e){if(!this.serviceWorkerRegistration)throw new ra(exports.RiviumPushErrorCode.SERVICE_NOT_RUNNING,"Service Worker not registered");const t=await this.serviceWorkerRegistration.pushManager.getSubscription();if(t)return this.log(exports.RiviumPushLogLevel.DEBUG,"Using existing Push subscription"),t;const r=await this.serviceWorkerRegistration.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:this.urlBase64ToUint8Array(e)});return this.log(exports.RiviumPushLogLevel.INFO,"Push subscription created"),r}async registerDevice(e){var t,r,n;try{const i={deviceId:this.deviceId,platform:"web",userId:null==e?void 0:e.userId,appIdentifier:"undefined"!=typeof window?window.location.origin:void 0,metadata:{...null==e?void 0:e.metadata,userAgent:navigator.userAgent,language:navigator.language,url:window.location.origin}};if(this.pushSubscription){const e=this.pushSubscription.toJSON();i.webPushSubscription={endpoint:e.endpoint,keys:{p256dh:(null===(t=e.keys)||void 0===t?void 0:t.p256dh)||"",auth:(null===(r=e.keys)||void 0===r?void 0:r.auth)||""}},this.log(exports.RiviumPushLogLevel.DEBUG,"Sending Web Push subscription to server")}const o=await fetch(`${sa}/devices/register`,{method:"POST",headers:{"Content-Type":"application/json","x-api-key":this.config.apiKey},body:JSON.stringify(i)});if(!o.ok){const e=await o.json().catch(()=>({}));throw new ra(exports.RiviumPushErrorCode.SERVER_ERROR,e.message||`HTTP ${o.status}`)}const s=await o.json();return s.appId&&(this.appId=s.appId),s.subscriptionId&&(this.subscriptionId=s.subscriptionId,localStorage.setItem("rivium_push_subscription_id",s.subscriptionId),this.log(exports.RiviumPushLogLevel.DEBUG,`Stored subscriptionId: ${s.subscriptionId}`)),s.appIdentifier&&(this.appIdentifier=s.appIdentifier),(null===(n=s.mqtt)||void 0===n?void 0:n.token)&&this.mqttConfig&&(this.mqttConfig.token=s.mqtt.token,this.log(exports.RiviumPushLogLevel.DEBUG,"Connection token received from registration")),s}catch(e){if(e instanceof ra)throw e;throw new ra(exports.RiviumPushErrorCode.NETWORK_ERROR,e.message)}}connectToGateway(){if(this.pnSocket&&this.pnSocket.close(),this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),!this.mqttConfig)return this.log(exports.RiviumPushLogLevel.WARNING,"Gateway config not available, retrying in 2s..."),void setTimeout(()=>this.connectToGateway(),2e3);if(!this.mqttConfig.token)return this.log(exports.RiviumPushLogLevel.ERROR,"Connection token not available. Device must be registered first."),void this.emitError(exports.RiviumPushErrorCode.AUTHENTICATION_FAILED,"Connection token not available");this.setConnectionState("connecting");const e=this.mqttConfig.wsHost||this.mqttConfig.host,t=this.mqttConfig.wsPort,r="undefined"!=typeof window&&"https:"===window.location.protocol||443===t;this.log(exports.RiviumPushLogLevel.DEBUG,`Connecting to gateway (secure: ${r})`);const n=`rivium_push_${this.appId}_${this.deviceId}`,i=(new Zs).gateway(e).port(t).clientId(n).auth(Xs.token(this.mqttConfig.token)).secure(r).freshStart(!1).autoReconnect(!1).connectionTimeout(10).build();this.pnSocket=new Js(i);const o={onStateChanged:e=>{this.log(exports.RiviumPushLogLevel.DEBUG,`Connection state changed: ${e}`)},onConnected:()=>{this.log(exports.RiviumPushLogLevel.INFO,"Connected to gateway"),this.setConnectionState("connected"),this.reconnectAttempts=0,this.trackEvent(exports.RiviumPushAnalyticsEvent.CONNECTED);const e=this.config.apiKey.substring(0,16),t=this.appIdentifier||("undefined"!=typeof window?window.location.origin:"_default");if(this.subscriptionId){const t=`rivium_push/${e}/sub/${this.subscriptionId}`;this.pnSocket.stream(t,e=>{this.handlePNMessage(e)},this.config.mqttQos),this.log(exports.RiviumPushLogLevel.DEBUG,`Streaming from subscription channel ${t}`)}const r=`rivium_push/${e}/broadcast`;this.pnSocket.stream(r,e=>{this.handlePNMessage(e)},this.config.mqttQos),this.log(exports.RiviumPushLogLevel.DEBUG,"Streaming from broadcast channel");const n=`rivium_push/${e}/${this.deviceId}/${t}`;this.pnSocket.stream(n,e=>{this.handlePNMessage(e)},this.config.mqttQos),this.log(exports.RiviumPushLogLevel.DEBUG,"Streaming from (deprecated) device channel"),this.subscribedTopics.forEach(t=>{const r=`rivium_push/${e}/topic/${t}`;this.pnSocket.stream(r,e=>{this.handlePNMessage(e)},this.config.mqttQos)})},onDisconnected:e=>{this.log(exports.RiviumPushLogLevel.INFO,"Disconnected from gateway",e||""),this.setConnectionState("disconnected"),this.trackEvent(exports.RiviumPushAnalyticsEvent.DISCONNECTED),this.scheduleReconnect()},onReconnecting:(e,t)=>{this.log(exports.RiviumPushLogLevel.INFO,`Reconnecting attempt ${e} in ${t}ms`)}};this.pnSocket.addConnectionListener(o),this.pnSocket.addErrorListener(e=>{const t="undefined"!=typeof document&&document.hidden;this.log(t?exports.RiviumPushLogLevel.DEBUG:exports.RiviumPushLogLevel.ERROR,"Gateway error:",e.message),this.setConnectionState("error");let r=exports.RiviumPushErrorCode.CONNECTION_FAILED;const n=e.message.toLowerCase();if(n.includes("timeout"))r=exports.RiviumPushErrorCode.CONNECTION_TIMEOUT;else if(n.includes("refused")||n.includes("not authorized")){if(r=exports.RiviumPushErrorCode.CONNECTION_REFUSED,n.includes("not authorized"))return this.log(exports.RiviumPushLogLevel.INFO,"Token may be expired, attempting refresh..."),void this.refreshMqttToken().then(()=>{this.log(exports.RiviumPushLogLevel.INFO,"Token refreshed, reconnecting..."),this.connectToGateway()}).catch(e=>{this.log(exports.RiviumPushLogLevel.ERROR,"Token refresh failed:",e),this.emitError(exports.RiviumPushErrorCode.AUTHENTICATION_FAILED,"Token expired and refresh failed")})}else n.includes("auth")||n.includes("credential")?r=exports.RiviumPushErrorCode.AUTHENTICATION_FAILED:(n.includes("ssl")||n.includes("tls"))&&(r=exports.RiviumPushErrorCode.SSL_ERROR);this.emitError(r,e.message)}),this.log(exports.RiviumPushLogLevel.DEBUG,"Opening connection to gateway..."),this.pnSocket.open()}handlePNMessage(e){try{const t=e.payloadAsJson();this.handleMqttMessage(e.channel,t)}catch(e){this.log(exports.RiviumPushLogLevel.ERROR,"Message parse error:",e),this.emitError(exports.RiviumPushErrorCode.MESSAGE_PARSE_ERROR,e.message)}}disconnectFromGateway(){this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.pnSocket&&(this.pnSocket.close(),this.pnSocket=null),this.setConnectionState("disconnected")}scheduleReconnect(){if(this.reconnectAttempts>=this.maxReconnectAttempts)return this.log(exports.RiviumPushLogLevel.WARNING,"Max reconnect attempts reached"),void this.emitError(exports.RiviumPushErrorCode.CONNECTION_FAILED,"Max reconnect attempts reached");if(!navigator.onLine)return void this.log(exports.RiviumPushLogLevel.DEBUG,"Offline, skipping reconnect");if("undefined"!=typeof document&&document.hidden)return void this.log(exports.RiviumPushLogLevel.DEBUG,"App hidden, skipping reconnect (will retry on visibilitychange)");const e=Math.min(1e3*Math.pow(2,this.reconnectAttempts),3e4);this.reconnectAttempts++,this.log(exports.RiviumPushLogLevel.INFO,`Reconnecting in ${e}ms (attempt ${this.reconnectAttempts}/${this.maxReconnectAttempts})`);const t={retryAttempt:this.reconnectAttempts,nextRetryMs:e,maxRetryAttempts:this.maxReconnectAttempts};this.onReconnectingCallback&&this.onReconnectingCallback(t),this.trackEvent(exports.RiviumPushAnalyticsEvent.RETRY_STARTED,{retryAttempt:this.reconnectAttempts,nextRetryMs:e}),this.reconnectTimer=setTimeout(()=>{this.connectToGateway()},e)}handleMqttMessage(e,t){var r;const n=this.normalizeMessage(t);this.log(exports.RiviumPushLogLevel.DEBUG,"Message received:",n.title),this.trackEvent(exports.RiviumPushAnalyticsEvent.MESSAGE_RECEIVED,{messageId:n.messageId,title:n.title,silent:n.silent,hasImage:!!n.imageUrl,hasActions:!!(null===(r=n.actions)||void 0===r?void 0:r.length)}),this.handleBadge(n),n.silent||"visible"===document.visibilityState||(this.showRichNotification(n),this.trackEvent(exports.RiviumPushAnalyticsEvent.MESSAGE_DISPLAYED,{messageId:n.messageId,title:n.title})),this.onMessageCallback&&this.onMessageCallback(n)}normalizeMessage(e){const t=this.getLocalizedContent(e,"title"),r=this.getLocalizedContent(e,"body");return{title:t||e.title||"",body:r||e.body||"",data:e.data,silent:e.silent,imageUrl:e.imageUrl||e.image,iconUrl:e.iconUrl||e.icon,actions:e.actions,deepLink:e.deepLink,badge:e.badge,badgeAction:e.badgeAction,sound:e.sound,threadId:e.threadId,collapseKey:e.collapseKey,category:e.category,priority:e.priority,ttl:e.ttl,localizations:e.localizations,timezone:e.timezone,messageId:e.messageId,campaignId:e.campaignId,icon:e.iconUrl||e.icon,image:e.imageUrl||e.image,tag:e.tag||e.collapseKey||e.threadId}}getLocalizedContent(e,t){if(!e.localizations||!Array.isArray(e.localizations))return null;const r=navigator.language.split("-")[0].toLowerCase(),n=e.localizations.find(e=>e.locale.toLowerCase().startsWith(r));return n?n[t]:null}handleBadge(e){if(void 0===e.badge&&!e.badgeAction)return;const t=e.badgeAction||"set";let r=e.badge||0;switch(t){case"set":r=e.badge||0;break;case"increment":r=this.badgeCount+(e.badge||1);break;case"decrement":r=Math.max(0,this.badgeCount-(e.badge||1));break;case"clear":r=0}this.setBadgeCount(r)}handleServiceWorkerMessage(e){var t;const r=e.data;if("push-message"===r.type){this.log(exports.RiviumPushLogLevel.DEBUG,"Push message received from SW:",null===(t=r.message)||void 0===t?void 0:t.title);const e=this.normalizeMessage(r.message);this.trackEvent(exports.RiviumPushAnalyticsEvent.MESSAGE_RECEIVED,{messageId:e.messageId,title:e.title,source:"web-push"}),this.handleBadge(e),this.onMessageCallback&&this.onMessageCallback(e)}else if("notification-click"===r.type){this.log(exports.RiviumPushLogLevel.INFO,"Notification clicked from SW");const e=this.normalizeMessage(r.message||{});this.trackEvent(exports.RiviumPushAnalyticsEvent.NOTIFICATION_CLICKED,{messageId:e.messageId,title:e.title,action:r.action}),this.onNotificationClickCallback&&this.onNotificationClickCallback(e,r.action)}else if("action-clicked"===r.type){this.log(exports.RiviumPushLogLevel.INFO,"Action clicked from SW:",r.actionId);const e=this.normalizeMessage(r.message||{});this.trackEvent(exports.RiviumPushAnalyticsEvent.ACTION_CLICKED,{actionId:r.actionId,messageId:e.messageId,title:e.title}),this.onActionClickedCallback&&this.onActionClickedCallback(r.actionId,e)}else"initial-message"===r.type?(this.log(exports.RiviumPushLogLevel.INFO,"Initial message received from SW"),this.initialMessage=this.normalizeMessage(r.message||{}),this.onNotificationClickCallback&&this.initialMessage&&this.onNotificationClickCallback(this.initialMessage,void 0)):"navigate"===r.type&&(this.log(exports.RiviumPushLogLevel.INFO,"Navigating to:",r.url),r.url&&"undefined"!=typeof window&&(window.location.href=r.url))}showRichNotification(e){if("granted"!==Notification.permission)return;const t={body:e.body,icon:e.iconUrl||e.icon,badge:e.iconUrl||e.icon,image:e.imageUrl||e.image,tag:e.tag||e.collapseKey||e.threadId,data:{...e.data,deepLink:e.deepLink,messageId:e.messageId,campaignId:e.campaignId,riviumPushMessage:e},requireInteraction:"high"===e.priority,silent:"none"===e.sound};if(e.actions&&e.actions.length>0){const r=e.actions.slice(0,2).map(e=>({action:e.id,title:e.title,icon:e.icon}));this.serviceWorkerRegistration&&(t.actions=r)}if(this.serviceWorkerRegistration)this.serviceWorkerRegistration.showNotification(e.title,t);else{const r=new Notification(e.title,t);r.onclick=()=>{window.focus(),e.deepLink&&(window.location.href=e.deepLink),this.onNotificationClickCallback&&this.onNotificationClickCallback(e),this.trackEvent(exports.RiviumPushAnalyticsEvent.NOTIFICATION_CLICKED,{messageId:e.messageId,title:e.title}),r.close()}}}updateFaviconBadge(e){try{const t=document.createElement("canvas"),r=t.getContext("2d");if(!r)return;const n=32;t.width=n,t.height=n;const i=document.querySelector('link[rel="icon"]'),o=(null==i?void 0:i.href)||"/favicon.ico",s=new Image;s.crossOrigin="anonymous",s.onload=()=>{if(r.drawImage(s,0,0,n,n),e>0){const t=14,i=n-t/2,o=t/2;r.beginPath(),r.arc(i,o,t/2+1,0,2*Math.PI),r.fillStyle="#ef4444",r.fill(),r.fillStyle="#ffffff",r.font="bold 10px sans-serif",r.textAlign="center",r.textBaseline="middle",r.fillText(e>99?"99+":e.toString(),i,o)}const o=document.createElement("link");o.rel="icon",o.href=t.toDataURL("image/png"),i&&i.remove(),document.head.appendChild(o)},s.src=o}catch(e){this.log(exports.RiviumPushLogLevel.WARNING,"Could not update favicon badge:",e)}}setConnectionState(e){this.connectionState=e,this.onConnectionStateCallback&&this.onConnectionStateCallback(e)}getOrCreateDeviceId(){const e="rivium_push_device_id";let t=localStorage.getItem(e);return t||(t="web_"+this.generateUUID(),localStorage.setItem(e,t)),t}generateUUID(){return"undefined"!=typeof crypto&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}urlBase64ToUint8Array(e){const t=(e+"=".repeat((4-e.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/"),r=window.atob(t),n=new Uint8Array(r.length);for(let e=0;e<r.length;++e)n[e]=r.charCodeAt(e);return n}}exports.RiviumPush=aa,exports.RiviumPushError=ra,exports.default=aa;
2
2
  //# sourceMappingURL=index.js.map