code-server
Version:
Run VS Code on a remote server.
8 lines • 101 kB
JavaScript
"use strict";var Eo=Object.create;var Me=Object.defineProperty;var vo=Object.getOwnPropertyDescriptor;var bo=Object.getOwnPropertyNames;var Co=Object.getPrototypeOf,Po=Object.prototype.hasOwnProperty;var f=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),Oo=(t,e)=>{for(var r in e)Me(t,r,{get:e[r],enumerable:!0})},Hr=(t,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of bo(e))!Po.call(t,n)&&n!==r&&Me(t,n,{get:()=>e[n],enumerable:!(s=vo(e,n))||s.enumerable});return t};var S=(t,e,r)=>(r=t!=null?Eo(Co(t)):{},Hr(e||!t||!t.__esModule?Me(r,"default",{value:t,enumerable:!0}):r,t)),To=t=>Hr(Me({},"__esModule",{value:!0}),t);var is=f((Vu,ns)=>{"use strict";var{Duplex:qo}=require("stream");function rs(t){t.emit("close")}function No(){!this.destroyed&&this._writableState.finished&&this.destroy()}function ss(t){this.removeListener("error",ss),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t)}function Mo(t,e){let r=!0,s=new qo({...e,autoDestroy:!1,emitClose:!1,objectMode:!1,writableObjectMode:!1});return t.on("message",function(i,o){let a=!o&&s._readableState.objectMode?i.toString():i;s.push(a)||t.pause()}),t.once("error",function(i){s.destroyed||(r=!1,s.destroy(i))}),t.once("close",function(){s.destroyed||s.push(null)}),s._destroy=function(n,i){if(t.readyState===t.CLOSED){i(n),process.nextTick(rs,s);return}let o=!1;t.once("error",function(c){o=!0,i(c)}),t.once("close",function(){o||i(n),process.nextTick(rs,s)}),r&&t.terminate()},s._final=function(n){if(t.readyState===t.CONNECTING){t.once("open",function(){s._final(n)});return}t._socket!==null&&(t._socket._writableState.finished?(n(),s._readableState.endEmitted&&s.destroy()):(t._socket.once("finish",function(){n()}),t.close()))},s._read=function(){t.isPaused&&t.resume()},s._write=function(n,i,o){if(t.readyState===t.CONNECTING){t.once("open",function(){s._write(n,i,o)});return}t.send(n,o)},s.on("end",No),s.on("error",ss),s}ns.exports=Mo});var U=f((zu,os)=>{"use strict";os.exports={BINARY_TYPES:["nodebuffer","arraybuffer","fragments"],EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}}});var ge=f((Ku,Ue)=>{"use strict";var{EMPTY_BUFFER:Fo}=U(),Gt=Buffer[Symbol.species];function Do(t,e){if(t.length===0)return Fo;if(t.length===1)return t[0];let r=Buffer.allocUnsafe(e),s=0;for(let n=0;n<t.length;n++){let i=t[n];r.set(i,s),s+=i.length}return s<e?new Gt(r.buffer,r.byteOffset,s):r}function as(t,e,r,s,n){for(let i=0;i<n;i++)r[s+i]=t[i]^e[i&3]}function cs(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3]}function $o(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function Wt(t){if(Wt.readOnly=!0,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new Gt(t):ArrayBuffer.isView(t)?e=new Gt(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),Wt.readOnly=!1),e}Ue.exports={concat:Do,mask:as,toArrayBuffer:$o,toBuffer:Wt,unmask:cs};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=require("bufferutil");Ue.exports.mask=function(e,r,s,n,i){i<48?as(e,r,s,n,i):t.mask(e,r,s,n,i)},Ue.exports.unmask=function(e,r){e.length<32?cs(e,r):t.unmask(e,r)}}catch{}});var fs=f((Xu,us)=>{"use strict";var ls=Symbol("kDone"),jt=Symbol("kRun"),Ht=class{constructor(e){this[ls]=()=>{this.pending--,this[jt]()},this.concurrency=e||1/0,this.jobs=[],this.pending=0}add(e){this.jobs.push(e),this[jt]()}[jt](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[ls])}}};us.exports=Ht});var we=f((Yu,ms)=>{"use strict";var ye=require("zlib"),ds=ge(),Uo=fs(),{kStatusCode:hs}=U(),Go=Buffer[Symbol.species],Wo=Buffer.from([0,0,255,255]),je=Symbol("permessage-deflate"),q=Symbol("total-length"),_e=Symbol("callback"),G=Symbol("buffers"),We=Symbol("error"),Ge,Vt=class{constructor(e,r,s){if(this._maxPayload=s|0,this._options=e||{},this._threshold=this._options.threshold!==void 0?this._options.threshold:1024,this._isServer=!!r,this._deflate=null,this._inflate=null,this.params=null,!Ge){let n=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;Ge=new Uo(n)}}static get extensionName(){return"permessage-deflate"}offer(){let e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=!0),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=!0),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(e.client_max_window_bits=!0),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[_e];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"))}}acceptAsServer(e){let r=this._options,s=e.find(n=>!(r.serverNoContextTakeover===!1&&n.server_no_context_takeover||n.server_max_window_bits&&(r.serverMaxWindowBits===!1||typeof r.serverMaxWindowBits=="number"&&r.serverMaxWindowBits>n.server_max_window_bits)||typeof r.clientMaxWindowBits=="number"&&!n.client_max_window_bits));if(!s)throw new Error("None of the extension offers can be accepted");return r.serverNoContextTakeover&&(s.server_no_context_takeover=!0),r.clientNoContextTakeover&&(s.client_no_context_takeover=!0),typeof r.serverMaxWindowBits=="number"&&(s.server_max_window_bits=r.serverMaxWindowBits),typeof r.clientMaxWindowBits=="number"?s.client_max_window_bits=r.clientMaxWindowBits:(s.client_max_window_bits===!0||r.clientMaxWindowBits===!1)&&delete s.client_max_window_bits,s}acceptAsClient(e){let r=e[0];if(this._options.clientNoContextTakeover===!1&&r.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!r.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(r.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===!1||typeof this._options.clientMaxWindowBits=="number"&&r.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return r}normalizeParams(e){return e.forEach(r=>{Object.keys(r).forEach(s=>{let n=r[s];if(n.length>1)throw new Error(`Parameter "${s}" must have only a single value`);if(n=n[0],s==="client_max_window_bits"){if(n!==!0){let i=+n;if(!Number.isInteger(i)||i<8||i>15)throw new TypeError(`Invalid value for parameter "${s}": ${n}`);n=i}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${s}": ${n}`)}else if(s==="server_max_window_bits"){let i=+n;if(!Number.isInteger(i)||i<8||i>15)throw new TypeError(`Invalid value for parameter "${s}": ${n}`);n=i}else if(s==="client_no_context_takeover"||s==="server_no_context_takeover"){if(n!==!0)throw new TypeError(`Invalid value for parameter "${s}": ${n}`)}else throw new Error(`Unknown parameter "${s}"`);r[s]=n})}),e}decompress(e,r,s){Ge.add(n=>{this._decompress(e,r,(i,o)=>{n(),s(i,o)})})}compress(e,r,s){Ge.add(n=>{this._compress(e,r,(i,o)=>{n(),s(i,o)})})}_decompress(e,r,s){let n=this._isServer?"client":"server";if(!this._inflate){let i=`${n}_max_window_bits`,o=typeof this.params[i]!="number"?ye.Z_DEFAULT_WINDOWBITS:this.params[i];this._inflate=ye.createInflateRaw({...this._options.zlibInflateOptions,windowBits:o}),this._inflate[je]=this,this._inflate[q]=0,this._inflate[G]=[],this._inflate.on("error",Ho),this._inflate.on("data",ps)}this._inflate[_e]=s,this._inflate.write(e),r&&this._inflate.write(Wo),this._inflate.flush(()=>{let i=this._inflate[We];if(i){this._inflate.close(),this._inflate=null,s(i);return}let o=ds.concat(this._inflate[G],this._inflate[q]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[q]=0,this._inflate[G]=[],r&&this.params[`${n}_no_context_takeover`]&&this._inflate.reset()),s(null,o)})}_compress(e,r,s){let n=this._isServer?"server":"client";if(!this._deflate){let i=`${n}_max_window_bits`,o=typeof this.params[i]!="number"?ye.Z_DEFAULT_WINDOWBITS:this.params[i];this._deflate=ye.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:o}),this._deflate[q]=0,this._deflate[G]=[],this._deflate.on("data",jo)}this._deflate[_e]=s,this._deflate.write(e),this._deflate.flush(ye.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let i=ds.concat(this._deflate[G],this._deflate[q]);r&&(i=new Go(i.buffer,i.byteOffset,i.length-4)),this._deflate[_e]=null,this._deflate[q]=0,this._deflate[G]=[],r&&this.params[`${n}_no_context_takeover`]&&this._deflate.reset(),s(null,i)})}};ms.exports=Vt;function jo(t){this[G].push(t),this[q]+=t.length}function ps(t){if(this[q]+=t.length,this[je]._maxPayload<1||this[q]<=this[je]._maxPayload){this[G].push(t);return}this[We]=new RangeError("Max payload size exceeded"),this[We].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[We][hs]=1009,this.removeListener("data",ps),this.reset()}function Ho(t){this[je]._inflate=null,t[hs]=1007,this[_e](t)}});var xe=f((Qu,He)=>{"use strict";var{isUtf8:gs}=require("buffer"),Vo=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0];function zo(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function zt(t){let e=t.length,r=0;for(;r<e;)if(!(t[r]&128))r++;else if((t[r]&224)===192){if(r+1===e||(t[r+1]&192)!==128||(t[r]&254)===192)return!1;r+=2}else if((t[r]&240)===224){if(r+2>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||t[r]===224&&(t[r+1]&224)===128||t[r]===237&&(t[r+1]&224)===160)return!1;r+=3}else if((t[r]&248)===240){if(r+3>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||(t[r+3]&192)!==128||t[r]===240&&(t[r+1]&240)===128||t[r]===244&&t[r+1]>143||t[r]>244)return!1;r+=4}else return!1;return!0}He.exports={isValidStatusCode:zo,isValidUTF8:zt,tokenChars:Vo};if(gs)He.exports.isValidUTF8=function(t){return t.length<24?zt(t):gs(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=require("utf-8-validate");He.exports.isValidUTF8=function(e){return e.length<32?zt(e):t(e)}}catch{}});var Zt=f((Zu,vs)=>{"use strict";var{Writable:Ko}=require("stream"),ys=we(),{BINARY_TYPES:Xo,EMPTY_BUFFER:_s,kStatusCode:Yo,kWebSocket:Qo}=U(),{concat:Kt,toArrayBuffer:Zo,unmask:Jo}=ge(),{isValidStatusCode:ea,isValidUTF8:ws}=xe(),Ve=Buffer[Symbol.species],T=0,xs=1,Ss=2,Es=3,Xt=4,Yt=5,ze=6,Qt=class extends Ko{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:!0,this._binaryType=e.binaryType||Xo[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[Qo]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=!1,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=!1,this._fin=!1,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=!1,this._loop=!1,this._state=T}_write(e,r,s){if(this._opcode===8&&this._state==T)return s();this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(s)}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let s=this._buffers[0];return this._buffers[0]=new Ve(s.buffer,s.byteOffset+e,s.length-e),new Ve(s.buffer,s.byteOffset,e)}let r=Buffer.allocUnsafe(e);do{let s=this._buffers[0],n=r.length-e;e>=s.length?r.set(this._buffers.shift(),n):(r.set(new Uint8Array(s.buffer,s.byteOffset,e),n),this._buffers[0]=new Ve(s.buffer,s.byteOffset+e,s.length-e)),e-=s.length}while(e>0);return r}startLoop(e){this._loop=!0;do switch(this._state){case T:this.getInfo(e);break;case xs:this.getPayloadLength16(e);break;case Ss:this.getPayloadLength64(e);break;case Es:this.getMask();break;case Xt:this.getData(e);break;case Yt:case ze:this._loop=!1;return}while(this._loop);this._errored||e()}getInfo(e){if(this._bufferedBytes<2){this._loop=!1;return}let r=this.consume(2);if(r[0]&48){let n=this.createError(RangeError,"RSV2 and RSV3 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(n);return}let s=(r[0]&64)===64;if(s&&!this._extensions[ys.extensionName]){let n=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(n);return}if(this._fin=(r[0]&128)===128,this._opcode=r[0]&15,this._payloadLength=r[1]&127,this._opcode===0){if(s){let n=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(n);return}if(!this._fragmented){let n=this.createError(RangeError,"invalid opcode 0",!0,1002,"WS_ERR_INVALID_OPCODE");e(n);return}this._opcode=this._fragmented}else if(this._opcode===1||this._opcode===2){if(this._fragmented){let n=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(n);return}this._compressed=s}else if(this._opcode>7&&this._opcode<11){if(!this._fin){let n=this.createError(RangeError,"FIN must be set",!0,1002,"WS_ERR_EXPECTED_FIN");e(n);return}if(s){let n=this.createError(RangeError,"RSV1 must be clear",!0,1002,"WS_ERR_UNEXPECTED_RSV_1");e(n);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){let n=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,!0,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");e(n);return}}else{let n=this.createError(RangeError,`invalid opcode ${this._opcode}`,!0,1002,"WS_ERR_INVALID_OPCODE");e(n);return}if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(r[1]&128)===128,this._isServer){if(!this._masked){let n=this.createError(RangeError,"MASK must be set",!0,1002,"WS_ERR_EXPECTED_MASK");e(n);return}}else if(this._masked){let n=this.createError(RangeError,"MASK must be clear",!0,1002,"WS_ERR_UNEXPECTED_MASK");e(n);return}this._payloadLength===126?this._state=xs:this._payloadLength===127?this._state=Ss:this.haveLength(e)}getPayloadLength16(e){if(this._bufferedBytes<2){this._loop=!1;return}this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e)}getPayloadLength64(e){if(this._bufferedBytes<8){this._loop=!1;return}let r=this.consume(8),s=r.readUInt32BE(0);if(s>Math.pow(2,21)-1){let n=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",!1,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");e(n);return}this._payloadLength=s*Math.pow(2,32)+r.readUInt32BE(4),this.haveLength(e)}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){let r=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");e(r);return}this._masked?this._state=Es:this._state=Xt}getMask(){if(this._bufferedBytes<4){this._loop=!1;return}this._mask=this.consume(4),this._state=Xt}getData(e){let r=_s;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=!1;return}r=this.consume(this._payloadLength),this._masked&&this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3]&&Jo(r,this._mask)}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=Yt,this.decompress(r,e);return}r.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(r)),this.dataMessage(e)}decompress(e,r){this._extensions[ys.extensionName].decompress(e,this._fin,(n,i)=>{if(n)return r(n);if(i.length){if(this._messageLength+=i.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let o=this.createError(RangeError,"Max payload size exceeded",!1,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");r(o);return}this._fragments.push(i)}this.dataMessage(r),this._state===T&&this.startLoop(r)})}dataMessage(e){if(!this._fin){this._state=T;return}let r=this._messageLength,s=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let n;this._binaryType==="nodebuffer"?n=Kt(s,r):this._binaryType==="arraybuffer"?n=Zo(Kt(s,r)):n=s,this._allowSynchronousEvents?(this.emit("message",n,!0),this._state=T):(this._state=ze,setImmediate(()=>{this.emit("message",n,!0),this._state=T,this.startLoop(e)}))}else{let n=Kt(s,r);if(!this._skipUTF8Validation&&!ws(n)){let i=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");e(i);return}this._state===Yt||this._allowSynchronousEvents?(this.emit("message",n,!1),this._state=T):(this._state=ze,setImmediate(()=>{this.emit("message",n,!1),this._state=T,this.startLoop(e)}))}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=!1,this.emit("conclude",1005,_s),this.end();else{let s=e.readUInt16BE(0);if(!ea(s)){let i=this.createError(RangeError,`invalid status code ${s}`,!0,1002,"WS_ERR_INVALID_CLOSE_CODE");r(i);return}let n=new Ve(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!ws(n)){let i=this.createError(Error,"invalid UTF-8 sequence",!0,1007,"WS_ERR_INVALID_UTF8");r(i);return}this._loop=!1,this.emit("conclude",s,n),this.end()}this._state=T;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=T):(this._state=ze,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=T,this.startLoop(r)}))}createError(e,r,s,n,i){this._loop=!1,this._errored=!0;let o=new e(s?`Invalid WebSocket frame: ${r}`:r);return Error.captureStackTrace(o,this.createError),o.code=i,o[Yo]=n,o}};vs.exports=Qt});var er=f((ef,Ps)=>{"use strict";var{Duplex:Ju}=require("stream"),{randomFillSync:ta}=require("crypto"),bs=we(),{EMPTY_BUFFER:ra}=U(),{isValidStatusCode:sa}=xe(),{mask:Cs,toBuffer:J}=ge(),I=Symbol("kByteLength"),na=Buffer.alloc(4),Ke=8*1024,H,ee=Ke,Jt=class t{constructor(e,r,s){this._extensions=r||{},s&&(this._generateMask=s,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=!0,this._compress=!1,this._bufferedBytes=0,this._deflating=!1,this._queue=[]}static frame(e,r){let s,n=!1,i=2,o=!1;r.mask&&(s=r.maskBuffer||na,r.generateMask?r.generateMask(s):(ee===Ke&&(H===void 0&&(H=Buffer.alloc(Ke)),ta(H,0,Ke),ee=0),s[0]=H[ee++],s[1]=H[ee++],s[2]=H[ee++],s[3]=H[ee++]),o=(s[0]|s[1]|s[2]|s[3])===0,i=6);let a;typeof e=="string"?(!r.mask||o)&&r[I]!==void 0?a=r[I]:(e=Buffer.from(e),a=e.length):(a=e.length,n=r.mask&&r.readOnly&&!o);let c=a;a>=65536?(i+=8,c=127):a>125&&(i+=2,c=126);let l=Buffer.allocUnsafe(n?a+i:i);return l[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(l[0]|=64),l[1]=c,c===126?l.writeUInt16BE(a,2):c===127&&(l[2]=l[3]=0,l.writeUIntBE(a,4,6)),r.mask?(l[1]|=128,l[i-4]=s[0],l[i-3]=s[1],l[i-2]=s[2],l[i-1]=s[3],o?[l,e]:n?(Cs(e,s,l,i,a),[l]):(Cs(e,s,e,0,a),[l,e])):[l,e]}close(e,r,s,n){let i;if(e===void 0)i=ra;else{if(typeof e!="number"||!sa(e))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)i=Buffer.allocUnsafe(2),i.writeUInt16BE(e,0);else{let a=Buffer.byteLength(r);if(a>123)throw new RangeError("The message must not be greater than 123 bytes");i=Buffer.allocUnsafe(2+a),i.writeUInt16BE(e,0),typeof r=="string"?i.write(r,2):i.set(r,2)}}let o={[I]:i.length,fin:!0,generateMask:this._generateMask,mask:s,maskBuffer:this._maskBuffer,opcode:8,readOnly:!1,rsv1:!1};this._deflating?this.enqueue([this.dispatch,i,!1,o,n]):this.sendFrame(t.frame(i,o),n)}ping(e,r,s){let n,i;if(typeof e=="string"?(n=Buffer.byteLength(e),i=!1):(e=J(e),n=e.length,i=J.readOnly),n>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[I]:n,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:i,rsv1:!1};this._deflating?this.enqueue([this.dispatch,e,!1,o,s]):this.sendFrame(t.frame(e,o),s)}pong(e,r,s){let n,i;if(typeof e=="string"?(n=Buffer.byteLength(e),i=!1):(e=J(e),n=e.length,i=J.readOnly),n>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[I]:n,fin:!0,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:i,rsv1:!1};this._deflating?this.enqueue([this.dispatch,e,!1,o,s]):this.sendFrame(t.frame(e,o),s)}send(e,r,s){let n=this._extensions[bs.extensionName],i=r.binary?2:1,o=r.compress,a,c;if(typeof e=="string"?(a=Buffer.byteLength(e),c=!1):(e=J(e),a=e.length,c=J.readOnly),this._firstFragment?(this._firstFragment=!1,o&&n&&n.params[n._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(o=a>=n._threshold),this._compress=o):(o=!1,i=0),r.fin&&(this._firstFragment=!0),n){let l={[I]:a,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:i,readOnly:c,rsv1:o};this._deflating?this.enqueue([this.dispatch,e,this._compress,l,s]):this.dispatch(e,this._compress,l,s)}else this.sendFrame(t.frame(e,{[I]:a,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:i,readOnly:c,rsv1:!1}),s)}dispatch(e,r,s,n){if(!r){this.sendFrame(t.frame(e,s),n);return}let i=this._extensions[bs.extensionName];this._bufferedBytes+=s[I],this._deflating=!0,i.compress(e,s.fin,(o,a)=>{if(this._socket.destroyed){let c=new Error("The socket was closed while data was being compressed");typeof n=="function"&&n(c);for(let l=0;l<this._queue.length;l++){let u=this._queue[l],d=u[u.length-1];typeof d=="function"&&d(c)}return}this._bufferedBytes-=s[I],this._deflating=!1,s.readOnly=!1,this.sendFrame(t.frame(a,s),n),this.dequeue()})}dequeue(){for(;!this._deflating&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][I],Reflect.apply(e[0],this,e.slice(1))}}enqueue(e){this._bufferedBytes+=e[3][I],this._queue.push(e)}sendFrame(e,r){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],r),this._socket.uncork()):this._socket.write(e[0],r)}};Ps.exports=Jt});var qs=f((tf,Bs)=>{"use strict";var{kForOnEventAttribute:Se,kListener:tr}=U(),Os=Symbol("kCode"),Ts=Symbol("kData"),ks=Symbol("kError"),Is=Symbol("kMessage"),As=Symbol("kReason"),te=Symbol("kTarget"),Ls=Symbol("kType"),Rs=Symbol("kWasClean"),N=class{constructor(e){this[te]=null,this[Ls]=e}get target(){return this[te]}get type(){return this[Ls]}};Object.defineProperty(N.prototype,"target",{enumerable:!0});Object.defineProperty(N.prototype,"type",{enumerable:!0});var V=class extends N{constructor(e,r={}){super(e),this[Os]=r.code===void 0?0:r.code,this[As]=r.reason===void 0?"":r.reason,this[Rs]=r.wasClean===void 0?!1:r.wasClean}get code(){return this[Os]}get reason(){return this[As]}get wasClean(){return this[Rs]}};Object.defineProperty(V.prototype,"code",{enumerable:!0});Object.defineProperty(V.prototype,"reason",{enumerable:!0});Object.defineProperty(V.prototype,"wasClean",{enumerable:!0});var re=class extends N{constructor(e,r={}){super(e),this[ks]=r.error===void 0?null:r.error,this[Is]=r.message===void 0?"":r.message}get error(){return this[ks]}get message(){return this[Is]}};Object.defineProperty(re.prototype,"error",{enumerable:!0});Object.defineProperty(re.prototype,"message",{enumerable:!0});var Ee=class extends N{constructor(e,r={}){super(e),this[Ts]=r.data===void 0?null:r.data}get data(){return this[Ts]}};Object.defineProperty(Ee.prototype,"data",{enumerable:!0});var ia={addEventListener(t,e,r={}){for(let n of this.listeners(t))if(!r[Se]&&n[tr]===e&&!n[Se])return;let s;if(t==="message")s=function(i,o){let a=new Ee("message",{data:o?i:i.toString()});a[te]=this,Xe(e,this,a)};else if(t==="close")s=function(i,o){let a=new V("close",{code:i,reason:o.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});a[te]=this,Xe(e,this,a)};else if(t==="error")s=function(i){let o=new re("error",{error:i,message:i.message});o[te]=this,Xe(e,this,o)};else if(t==="open")s=function(){let i=new N("open");i[te]=this,Xe(e,this,i)};else return;s[Se]=!!r[Se],s[tr]=e,r.once?this.once(t,s):this.on(t,s)},removeEventListener(t,e){for(let r of this.listeners(t))if(r[tr]===e&&!r[Se]){this.removeListener(t,r);break}}};Bs.exports={CloseEvent:V,ErrorEvent:re,Event:N,EventTarget:ia,MessageEvent:Ee};function Xe(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r)}});var rr=f((rf,Ns)=>{"use strict";var{tokenChars:ve}=xe();function L(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r)}function oa(t){let e=Object.create(null),r=Object.create(null),s=!1,n=!1,i=!1,o,a,c=-1,l=-1,u=-1,d=0;for(;d<t.length;d++)if(l=t.charCodeAt(d),o===void 0)if(u===-1&&ve[l]===1)c===-1&&(c=d);else if(d!==0&&(l===32||l===9))u===-1&&c!==-1&&(u=d);else if(l===59||l===44){if(c===-1)throw new SyntaxError(`Unexpected character at index ${d}`);u===-1&&(u=d);let g=t.slice(c,u);l===44?(L(e,g,r),r=Object.create(null)):o=g,c=u=-1}else throw new SyntaxError(`Unexpected character at index ${d}`);else if(a===void 0)if(u===-1&&ve[l]===1)c===-1&&(c=d);else if(l===32||l===9)u===-1&&c!==-1&&(u=d);else if(l===59||l===44){if(c===-1)throw new SyntaxError(`Unexpected character at index ${d}`);u===-1&&(u=d),L(r,t.slice(c,u),!0),l===44&&(L(e,o,r),r=Object.create(null),o=void 0),c=u=-1}else if(l===61&&c!==-1&&u===-1)a=t.slice(c,d),c=u=-1;else throw new SyntaxError(`Unexpected character at index ${d}`);else if(n){if(ve[l]!==1)throw new SyntaxError(`Unexpected character at index ${d}`);c===-1?c=d:s||(s=!0),n=!1}else if(i)if(ve[l]===1)c===-1&&(c=d);else if(l===34&&c!==-1)i=!1,u=d;else if(l===92)n=!0;else throw new SyntaxError(`Unexpected character at index ${d}`);else if(l===34&&t.charCodeAt(d-1)===61)i=!0;else if(u===-1&&ve[l]===1)c===-1&&(c=d);else if(c!==-1&&(l===32||l===9))u===-1&&(u=d);else if(l===59||l===44){if(c===-1)throw new SyntaxError(`Unexpected character at index ${d}`);u===-1&&(u=d);let g=t.slice(c,u);s&&(g=g.replace(/\\/g,""),s=!1),L(r,a,g),l===44&&(L(e,o,r),r=Object.create(null),o=void 0),a=void 0,c=u=-1}else throw new SyntaxError(`Unexpected character at index ${d}`);if(c===-1||i||l===32||l===9)throw new SyntaxError("Unexpected end of input");u===-1&&(u=d);let p=t.slice(c,u);return o===void 0?L(e,p,r):(a===void 0?L(r,p,!0):s?L(r,a,p.replace(/\\/g,"")):L(r,a,p),L(e,o,r)),e}function aa(t){return Object.keys(t).map(e=>{let r=t[e];return Array.isArray(r)||(r=[r]),r.map(s=>[e].concat(Object.keys(s).map(n=>{let i=s[n];return Array.isArray(i)||(i=[i]),i.map(o=>o===!0?n:`${n}=${o}`).join("; ")})).join("; ")).join(", ")}).join(", ")}Ns.exports={format:aa,parse:oa}});var ar=f((of,zs)=>{"use strict";var ca=require("events"),la=require("https"),ua=require("http"),Ds=require("net"),fa=require("tls"),{randomBytes:da,createHash:ha}=require("crypto"),{Duplex:sf,Readable:nf}=require("stream"),{URL:sr}=require("url"),W=we(),pa=Zt(),ma=er(),{BINARY_TYPES:Ms,EMPTY_BUFFER:Ye,GUID:ga,kForOnEventAttribute:nr,kListener:ya,kStatusCode:_a,kWebSocket:E,NOOP:$s}=U(),{EventTarget:{addEventListener:wa,removeEventListener:xa}}=qs(),{format:Sa,parse:Ea}=rr(),{toBuffer:va}=ge(),ba=30*1e3,Us=Symbol("kAborted"),ir=[8,13],M=["CONNECTING","OPEN","CLOSING","CLOSED"],Ca=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,w=class t extends ca{constructor(e,r,s){super(),this._binaryType=Ms[0],this._closeCode=1006,this._closeFrameReceived=!1,this._closeFrameSent=!1,this._closeMessage=Ye,this._closeTimer=null,this._extensions={},this._paused=!1,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=!1,this._redirects=0,r===void 0?r=[]:Array.isArray(r)||(typeof r=="object"&&r!==null?(s=r,r=[]):r=[r]),Gs(this,e,r,s)):(this._autoPong=s.autoPong,this._isServer=!0)}get binaryType(){return this._binaryType}set binaryType(e){Ms.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e))}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(e,r,s){let n=new pa({allowSynchronousEvents:s.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:s.maxPayload,skipUTF8Validation:s.skipUTF8Validation});this._sender=new ma(e,this._extensions,s.generateMask),this._receiver=n,this._socket=e,n[E]=this,e[E]=this,n.on("conclude",Ta),n.on("drain",ka),n.on("error",Ia),n.on("message",Aa),n.on("ping",La),n.on("pong",Ra),e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",js),e.on("data",Ze),e.on("end",Hs),e.on("error",Vs),this._readyState=t.OPEN,this.emit("open")}emitClose(){if(!this._socket){this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[W.extensionName]&&this._extensions[W.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage)}close(e,r){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){C(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,r,!this._isServer,s=>{s||(this._closeFrameSent=!0,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end())}),this._closeTimer=setTimeout(this._socket.destroy.bind(this._socket),ba)}}pause(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!0,this._socket.pause())}ping(e,r,s){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(s=e,e=r=void 0):typeof r=="function"&&(s=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){or(this,e,s);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||Ye,r,s)}pong(e,r,s){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(s=e,e=r=void 0):typeof r=="function"&&(s=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){or(this,e,s);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||Ye,r,s)}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=!1,this._receiver._writableState.needDrain||this._socket.resume())}send(e,r,s){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof r=="function"&&(s=r,r={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){or(this,e,s);return}let n={binary:typeof e!="string",mask:!this._isServer,compress:!0,fin:!0,...r};this._extensions[W.extensionName]||(n.compress=!1),this._sender.send(e||Ye,n,s)}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){C(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy())}}};Object.defineProperty(w,"CONNECTING",{enumerable:!0,value:M.indexOf("CONNECTING")});Object.defineProperty(w.prototype,"CONNECTING",{enumerable:!0,value:M.indexOf("CONNECTING")});Object.defineProperty(w,"OPEN",{enumerable:!0,value:M.indexOf("OPEN")});Object.defineProperty(w.prototype,"OPEN",{enumerable:!0,value:M.indexOf("OPEN")});Object.defineProperty(w,"CLOSING",{enumerable:!0,value:M.indexOf("CLOSING")});Object.defineProperty(w.prototype,"CLOSING",{enumerable:!0,value:M.indexOf("CLOSING")});Object.defineProperty(w,"CLOSED",{enumerable:!0,value:M.indexOf("CLOSED")});Object.defineProperty(w.prototype,"CLOSED",{enumerable:!0,value:M.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(w.prototype,t,{enumerable:!0})});["open","error","close","message"].forEach(t=>{Object.defineProperty(w.prototype,`on${t}`,{enumerable:!0,get(){for(let e of this.listeners(t))if(e[nr])return e[ya];return null},set(e){for(let r of this.listeners(t))if(r[nr]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[nr]:!0})}})});w.prototype.addEventListener=wa;w.prototype.removeEventListener=xa;zs.exports=w;function Gs(t,e,r,s){let n={allowSynchronousEvents:!0,autoPong:!0,protocolVersion:ir[1],maxPayload:104857600,skipUTF8Validation:!1,perMessageDeflate:!0,followRedirects:!1,maxRedirects:10,...s,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=n.autoPong,!ir.includes(n.protocolVersion))throw new RangeError(`Unsupported protocol version: ${n.protocolVersion} (supported versions: ${ir.join(", ")})`);let i;if(e instanceof sr)i=e;else try{i=new sr(e)}catch{throw new SyntaxError(`Invalid URL: ${e}`)}i.protocol==="http:"?i.protocol="ws:":i.protocol==="https:"&&(i.protocol="wss:"),t._url=i.href;let o=i.protocol==="wss:",a=i.protocol==="ws+unix:",c;if(i.protocol!=="ws:"&&!o&&!a?c=`The URL's protocol must be one of "ws:", "wss:", "http:", "https", or "ws+unix:"`:a&&!i.pathname?c="The URL's pathname is empty":i.hash&&(c="The URL contains a fragment identifier"),c){let h=new SyntaxError(c);if(t._redirects===0)throw h;Qe(t,h);return}let l=o?443:80,u=da(16).toString("base64"),d=o?la.request:ua.request,p=new Set,g;if(n.createConnection=n.createConnection||(o?Oa:Pa),n.defaultPort=n.defaultPort||l,n.port=i.port||l,n.host=i.hostname.startsWith("[")?i.hostname.slice(1,-1):i.hostname,n.headers={...n.headers,"Sec-WebSocket-Version":n.protocolVersion,"Sec-WebSocket-Key":u,Connection:"Upgrade",Upgrade:"websocket"},n.path=i.pathname+i.search,n.timeout=n.handshakeTimeout,n.perMessageDeflate&&(g=new W(n.perMessageDeflate!==!0?n.perMessageDeflate:{},!1,n.maxPayload),n.headers["Sec-WebSocket-Extensions"]=Sa({[W.extensionName]:g.offer()})),r.length){for(let h of r){if(typeof h!="string"||!Ca.test(h)||p.has(h))throw new SyntaxError("An invalid or duplicated subprotocol was specified");p.add(h)}n.headers["Sec-WebSocket-Protocol"]=r.join(",")}if(n.origin&&(n.protocolVersion<13?n.headers["Sec-WebSocket-Origin"]=n.origin:n.headers.Origin=n.origin),(i.username||i.password)&&(n.auth=`${i.username}:${i.password}`),a){let h=n.path.split(":");n.socketPath=h[0],n.path=h[1]}let m;if(n.followRedirects){if(t._redirects===0){t._originalIpc=a,t._originalSecure=o,t._originalHostOrSocketPath=a?n.socketPath:i.host;let h=s&&s.headers;if(s={...s,headers:{}},h)for(let[_,k]of Object.entries(h))s.headers[_.toLowerCase()]=k}else if(t.listenerCount("redirect")===0){let h=a?t._originalIpc?n.socketPath===t._originalHostOrSocketPath:!1:t._originalIpc?!1:i.host===t._originalHostOrSocketPath;(!h||t._originalSecure&&!o)&&(delete n.headers.authorization,delete n.headers.cookie,h||delete n.headers.host,n.auth=void 0)}n.auth&&!s.headers.authorization&&(s.headers.authorization="Basic "+Buffer.from(n.auth).toString("base64")),m=t._req=d(n),t._redirects&&t.emit("redirect",t.url,m)}else m=t._req=d(n);n.timeout&&m.on("timeout",()=>{C(t,m,"Opening handshake has timed out")}),m.on("error",h=>{m===null||m[Us]||(m=t._req=null,Qe(t,h))}),m.on("response",h=>{let _=h.headers.location,k=h.statusCode;if(_&&n.followRedirects&&k>=300&&k<400){if(++t._redirects>n.maxRedirects){C(t,m,"Maximum redirects exceeded");return}m.abort();let A;try{A=new sr(_,e)}catch{let B=new SyntaxError(`Invalid URL: ${_}`);Qe(t,B);return}Gs(t,A,r,s)}else t.emit("unexpected-response",m,h)||C(t,m,`Unexpected server response: ${h.statusCode}`)}),m.on("upgrade",(h,_,k)=>{if(t.emit("upgrade",h),t.readyState!==w.CONNECTING)return;m=t._req=null;let A=h.headers.upgrade;if(A===void 0||A.toLowerCase()!=="websocket"){C(t,_,"Invalid Upgrade header");return}let Ne=ha("sha1").update(u+ga).digest("base64");if(h.headers["sec-websocket-accept"]!==Ne){C(t,_,"Invalid Sec-WebSocket-Accept header");return}let B=h.headers["sec-websocket-protocol"],$;if(B!==void 0?p.size?p.has(B)||($="Server sent an invalid subprotocol"):$="Server sent a subprotocol but none was requested":p.size&&($="Server sent no subprotocol"),$){C(t,_,$);return}B&&(t._protocol=B);let pe=h.headers["sec-websocket-extensions"];if(pe!==void 0){if(!g){C(t,_,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let Z;try{Z=Ea(pe)}catch{C(t,_,"Invalid Sec-WebSocket-Extensions header");return}let jr=Object.keys(Z);if(jr.length!==1||jr[0]!==W.extensionName){C(t,_,"Server indicated an extension that was not requested");return}try{g.accept(Z[W.extensionName])}catch{C(t,_,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[W.extensionName]=g}t.setSocket(_,k,{allowSynchronousEvents:n.allowSynchronousEvents,generateMask:n.generateMask,maxPayload:n.maxPayload,skipUTF8Validation:n.skipUTF8Validation})}),n.finishRequest?n.finishRequest(m,t):m.end()}function Qe(t,e){t._readyState=w.CLOSING,t.emit("error",e),t.emitClose()}function Pa(t){return t.path=t.socketPath,Ds.connect(t)}function Oa(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=Ds.isIP(t.host)?"":t.host),fa.connect(t)}function C(t,e,r){t._readyState=w.CLOSING;let s=new Error(r);Error.captureStackTrace(s,C),e.setHeader?(e[Us]=!0,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(Qe,t,s)):(e.destroy(s),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)))}function or(t,e,r){if(e){let s=va(e).length;t._socket?t._sender._bufferedBytes+=s:t._bufferedAmount+=s}if(r){let s=new Error(`WebSocket is not open: readyState ${t.readyState} (${M[t.readyState]})`);process.nextTick(r,s)}}function Ta(t,e){let r=this[E];r._closeFrameReceived=!0,r._closeMessage=e,r._closeCode=t,r._socket[E]!==void 0&&(r._socket.removeListener("data",Ze),process.nextTick(Ws,r._socket),t===1005?r.close():r.close(t,e))}function ka(){let t=this[E];t.isPaused||t._socket.resume()}function Ia(t){let e=this[E];e._socket[E]!==void 0&&(e._socket.removeListener("data",Ze),process.nextTick(Ws,e._socket),e.close(t[_a])),e.emit("error",t)}function Fs(){this[E].emitClose()}function Aa(t,e){this[E].emit("message",t,e)}function La(t){let e=this[E];e._autoPong&&e.pong(t,!this._isServer,$s),e.emit("ping",t)}function Ra(t){this[E].emit("pong",t)}function Ws(t){t.resume()}function js(){let t=this[E];this.removeListener("close",js),this.removeListener("data",Ze),this.removeListener("end",Hs),t._readyState=w.CLOSING;let e;!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&(e=t._socket.read())!==null&&t._receiver.write(e),t._receiver.end(),this[E]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",Fs),t._receiver.on("finish",Fs))}function Ze(t){this[E]._receiver.write(t)||this.pause()}function Hs(){let t=this[E];t._readyState=w.CLOSING,t._receiver.end(),this.end()}function Vs(){let t=this[E];this.removeListener("error",Vs),this.on("error",$s),t&&(t._readyState=w.CLOSING,this.destroy())}});var Xs=f((af,Ks)=>{"use strict";var{tokenChars:Ba}=xe();function qa(t){let e=new Set,r=-1,s=-1,n=0;for(n;n<t.length;n++){let o=t.charCodeAt(n);if(s===-1&&Ba[o]===1)r===-1&&(r=n);else if(n!==0&&(o===32||o===9))s===-1&&r!==-1&&(s=n);else if(o===44){if(r===-1)throw new SyntaxError(`Unexpected character at index ${n}`);s===-1&&(s=n);let a=t.slice(r,s);if(e.has(a))throw new SyntaxError(`The "${a}" subprotocol is duplicated`);e.add(a),r=s=-1}else throw new SyntaxError(`Unexpected character at index ${n}`)}if(r===-1||s!==-1)throw new SyntaxError("Unexpected end of input");let i=t.slice(r,n);if(e.has(i))throw new SyntaxError(`The "${i}" subprotocol is duplicated`);return e.add(i),e}Ks.exports={parse:qa}});var rn=f((lf,tn)=>{"use strict";var Na=require("events"),Je=require("http"),{Duplex:cf}=require("stream"),{createHash:Ma}=require("crypto"),Ys=rr(),z=we(),Fa=Xs(),Da=ar(),{GUID:$a,kWebSocket:Ua}=U(),Ga=/^[+/0-9A-Za-z]{22}==$/,Qs=0,Zs=1,en=2,cr=class extends Na{constructor(e,r){if(super(),e={allowSynchronousEvents:!0,autoPong:!0,maxPayload:100*1024*1024,skipUTF8Validation:!1,perMessageDeflate:!1,handleProtocols:null,clientTracking:!0,verifyClient:null,noServer:!1,backlog:null,server:null,host:null,path:null,port:null,WebSocket:Da,...e},e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(e.port!=null?(this._server=Je.createServer((s,n)=>{let i=Je.STATUS_CODES[426];n.writeHead(426,{"Content-Length":i.length,"Content-Type":"text/plain"}),n.end(i)}),this._server.listen(e.port,e.host,e.backlog,r)):e.server&&(this._server=e.server),this._server){let s=this.emit.bind(this,"connection");this._removeListeners=Wa(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(n,i,o)=>{this.handleUpgrade(n,i,o,s)}})}e.perMessageDeflate===!0&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=!1),this.options=e,this._state=Qs}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(this._state===en){e&&this.once("close",()=>{e(new Error("The server is not running"))}),process.nextTick(be,this);return}if(e&&this.once("close",e),this._state!==Zs)if(this._state=Zs,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients?this.clients.size?this._shouldEmitClose=!0:process.nextTick(be,this):process.nextTick(be,this);else{let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{be(this)})}}shouldHandle(e){if(this.options.path){let r=e.url.indexOf("?");if((r!==-1?e.url.slice(0,r):e.url)!==this.options.path)return!1}return!0}handleUpgrade(e,r,s,n){r.on("error",Js);let i=e.headers["sec-websocket-key"],o=e.headers.upgrade,a=+e.headers["sec-websocket-version"];if(e.method!=="GET"){K(this,e,r,405,"Invalid HTTP method");return}if(o===void 0||o.toLowerCase()!=="websocket"){K(this,e,r,400,"Invalid Upgrade header");return}if(i===void 0||!Ga.test(i)){K(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(a!==8&&a!==13){K(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header");return}if(!this.shouldHandle(e)){Ce(r,400);return}let c=e.headers["sec-websocket-protocol"],l=new Set;if(c!==void 0)try{l=Fa.parse(c)}catch{K(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let u=e.headers["sec-websocket-extensions"],d={};if(this.options.perMessageDeflate&&u!==void 0){let p=new z(this.options.perMessageDeflate,!0,this.options.maxPayload);try{let g=Ys.parse(u);g[z.extensionName]&&(p.accept(g[z.extensionName]),d[z.extensionName]=p)}catch{K(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let p={origin:e.headers[`${a===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(p,(g,m,h,_)=>{if(!g)return Ce(r,m||401,h,_);this.completeUpgrade(d,i,l,e,r,s,n)});return}if(!this.options.verifyClient(p))return Ce(r,401)}this.completeUpgrade(d,i,l,e,r,s,n)}completeUpgrade(e,r,s,n,i,o,a){if(!i.readable||!i.writable)return i.destroy();if(i[Ua])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>Qs)return Ce(i,503);let l=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${Ma("sha1").update(r+$a).digest("base64")}`],u=new this.options.WebSocket(null,void 0,this.options);if(s.size){let d=this.options.handleProtocols?this.options.handleProtocols(s,n):s.values().next().value;d&&(l.push(`Sec-WebSocket-Protocol: ${d}`),u._protocol=d)}if(e[z.extensionName]){let d=e[z.extensionName].params,p=Ys.format({[z.extensionName]:[d]});l.push(`Sec-WebSocket-Extensions: ${p}`),u._extensions=e}this.emit("headers",l,n),i.write(l.concat(`\r
`).join(`\r
`)),i.removeListener("error",Js),u.setSocket(i,o,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(u),u.on("close",()=>{this.clients.delete(u),this._shouldEmitClose&&!this.clients.size&&process.nextTick(be,this)})),a(u,n)}};tn.exports=cr;function Wa(t,e){for(let r of Object.keys(e))t.on(r,e[r]);return function(){for(let s of Object.keys(e))t.removeListener(s,e[s])}}function be(t){t._state=en,t.emit("close")}function Js(){this.destroy()}function Ce(t,e,r,s){r=r||Je.STATUS_CODES[e],s={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(r),...s},t.once("finish",t.destroy),t.end(`HTTP/1.1 ${e} ${Je.STATUS_CODES[e]}\r
`+Object.keys(s).map(n=>`${n}: ${s[n]}`).join(`\r
`)+`\r
\r
`+r)}function K(t,e,r,s,n){if(t.listenerCount("wsClientError")){let i=new Error(n);Error.captureStackTrace(i,K),t.emit("wsClientError",i,r,e)}else Ce(r,s,n)}});var fn=f((mf,un)=>{"use strict";var{Transform:Xa}=require("stream"),{StringDecoder:Ya}=require("string_decoder"),j=Symbol("last"),rt=Symbol("decoder");function Qa(t,e,r){let s;if(this.overflow){if(s=this[rt].write(t).split(this.matcher),s.length===1)return r();s.shift(),this.overflow=!1}else this[j]+=this[rt].write(t),s=this[j].split(this.matcher);this[j]=s.pop();for(let n=0;n<s.length;n++)try{ln(this,this.mapper(s[n]))}catch(i){return r(i)}if(this.overflow=this[j].length>this.maxLength,this.overflow&&!this.skipOverflow){r(new Error("maximum buffer reached"));return}r()}function Za(t){if(this[j]+=this[rt].end(),this[j])try{ln(this,this.mapper(this[j]))}catch(e){return t(e)}t()}function ln(t,e){e!==void 0&&t.push(e)}function cn(t){return t}function Ja(t,e,r){switch(t=t||/\r?\n/,e=e||cn,r=r||{},arguments.length){case 1:typeof t=="function"?(e=t,t=/\r?\n/):typeof t=="object"&&!(t instanceof RegExp)&&!t[Symbol.split]&&(r=t,t=/\r?\n/);break;case 2:typeof t=="function"?(r=e,e=t,t=/\r?\n/):typeof e=="object"&&(r=e,e=cn)}r=Object.assign({},r),r.autoDestroy=!0,r.transform=Qa,r.flush=Za,r.readableObjectMode=!0;let s=new Xa(r);return s[j]="",s[rt]=new Ya("utf8"),s.matcher=t,s.mapper=e,s.maxLength=r.maxLength,s.skipOverflow=r.skipOverflow||!1,s.overflow=!1,s._destroy=function(n,i){this._writableState.errorEmitted=!1,i(n)},s}un.exports=Ja});var F=f(v=>{"use strict";Object.defineProperty(v,"__esModule",{value:!0});v.findWindowsCandidates=v.sort=v.preferredEdgePath=v.preferredFirefoxPath=v.preferredChromePath=v.escapeRegexSpecialChars=v.canAccess=void 0;var rc=require("path");async function Te({access:t},e){if(!e)return!1;try{return await t(e),!0}catch{return!1}}v.canAccess=Te;var sc="/\\.?*()^${}|[]+";function nc(t,e){let r=sc.split("").filter(n=>!e||e.indexOf(n)<0).join("").replace(/[\\\]]/g,"\\$&"),s=new RegExp(`[${r}]`,"g");return t.replace(s,"\\$&")}v.escapeRegexSpecialChars=nc;async function ic(t,e){if(await Te(t,e.CHROME_PATH))return e.CHROME_PATH}v.preferredChromePath=ic;async function oc(t,e){if(await Te(t,e.FIREFOX_PATH))return e.FIREFOX_PATH}v.preferredFirefoxPath=oc;async function ac(t,e){if(await Te(t,e.EDGE_PATH))return e.EDGE_PATH}v.preferredEdgePath=ac;function cc(t,e){return[...t].filter(s=>!!s).map(s=>{let n=e.find(i=>i.regex.test(s));return n?{path:s,weight:n.weight,quality:n.quality}:{path:s,weight:10,quality:"dev"}}).sort((s,n)=>n.weight-s.weight).map(s=>({path:s.path,quality:s.quality}))}v.sort=cc;async function lc(t,e,r){let s=[t.LOCALAPPDATA,t.PROGRAMFILES,t["PROGRAMFILES(X86)"]].filter(i=>!!i),n=[];for(let i of s)for(let o of r){let a=rc.win32.join(i,o.name);n.push(Te(e,a).then(c=>c?{path:a,quality:o.type}:void 0))}return(await Promise.all(n)).filter(i=>!!i)}v.findWindowsCandidates=lc});var at=f(ot=>{"use strict";Object.defineProperty(ot,"__esModule",{value:!0});ot.DarwinFinderBase=void 0;var uc=require("path"),fc=require("fs"),fr=F(),_n=/( \(0x[a-f0-9]+\))/,dr=class{constructor(e=process.env,r=fc.promises,s=s){this.env=e,this.fs=r,this.execa=s,this.lsRegisterCommand="/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump",this.wellKnownPaths=[]}async findWhere(e){for(let r of this.wellKnownPaths)if(e(r)&&await(0,fr.canAccess)(this.fs,r.path))return r;return(await this.findAll()).find(e)}findAll(){var e;return(e=this.foundAll)!==null&&e!==void 0||(this.foundAll=this.findAllInner()),this.foundAll}async findLaunchRegisteredApps(e,r,s){let{stdout:n}=await this.execa.command(`${this.lsRegisterCommand} | awk 'tolower($0) ~ /${e.toLowerCase()}${_n.source}?$/ { $1=""; print $0 }'`,{shell:!0,stdio:"pipe"}),i=[...r,...n.split(`
`).map(c=>c.trim().replace(_n,""))].filter(c=>!!c),o=this.getPreferredPath();o&&i.push(o);let a=new Set;for(let c of i)for(let l of s){let u=uc.posix.join(c.trim(),l);try{await this.fs.access(u),a.add(u)}catch{}}return a}createPriorities(e){let r=this.env.HOME&&(0,fr.escapeRegexSpecialChars)(this.env.HOME),s=this.getPreferredPath(),n=e.reduce((i,o)=>[...i,{regex:new RegExp(`^/Applications/.*${o.name}`),weight:o.weight+100,quality:o.quality},{regex:new RegExp(`^${r}/Applications/.*${o.name}`),weight:o.weight,quality:o.quality},{regex:new RegExp(`^/Volumes/.*${o.name}`),weight:o.weight-100,quality:o.quality}],[]);return s&&n.unshift({regex:new RegExp((0,fr.escapeRegexSpecialChars)(s)),weight:151,quality:"custom"}),n}};ot.DarwinFinderBase=dr});var wn=f(ct=>{"use strict";Object.defineProperty(ct,"__esModule",{value:!0});ct.DarwinChromeBrowserFinder=void 0;var dc=F()