moreShopAdmin/dist/admin/assets/engine.io-client.6bbd7bb9.js

2 lines
26 KiB
JavaScript

import{n as v}from"./@babel.80d29b7b.js";import{r as M}from"./engine.io-parser.4305f785.js";import{r as J}from"./@socket.io.573b606e.js";import{r as j}from"./debug.b392f131.js";var I={},k={},W={},w={},L={},q={},R={},T={},Q;function O(){if(Q)return T;Q=1,Object.defineProperty(T,"__esModule",{value:!0}),T.defaultBinaryType=T.globalThisShim=T.nextTick=void 0,T.createCookieJar=n,T.nextTick=(()=>typeof Promise=="function"&&typeof Promise.resolve=="function"?d=>Promise.resolve().then(d):(d,l)=>l(d,0))(),T.globalThisShim=(()=>typeof self<"u"?self:typeof window<"u"?window:Function("return this")())(),T.defaultBinaryType="arraybuffer";function n(){}return T}var Y;function x(){if(Y)return R;Y=1,Object.defineProperty(R,"__esModule",{value:!0}),R.pick=y,R.installTimerFunctions=p,R.byteLength=g,R.randomString=a;const n=O();function y(i,...s){return s.reduce((h,c)=>(i.hasOwnProperty(c)&&(h[c]=i[c]),h),{})}const d=n.globalThisShim.setTimeout,l=n.globalThisShim.clearTimeout;function p(i,s){s.useNativeTimers?(i.setTimeoutFn=d.bind(n.globalThisShim),i.clearTimeoutFn=l.bind(n.globalThisShim)):(i.setTimeoutFn=n.globalThisShim.setTimeout.bind(n.globalThisShim),i.clearTimeoutFn=n.globalThisShim.clearTimeout.bind(n.globalThisShim))}const o=1.33;function g(i){return typeof i=="string"?u(i):Math.ceil((i.byteLength||i.size)*o)}function u(i){let s=0,h=0;for(let c=0,m=i.length;c<m;c++)s=i.charCodeAt(c),s<128?h+=1:s<2048?h+=2:s<55296||s>=57344?h+=3:(c++,h+=4);return h}function a(){return Date.now().toString(36).substring(3)+Math.random().toString(36).substring(2,5)}return R}var B={},Z;function pe(){if(Z)return B;Z=1,Object.defineProperty(B,"__esModule",{value:!0}),B.encode=n,B.decode=y;function n(d){let l="";for(let p in d)d.hasOwnProperty(p)&&(l.length&&(l+="&"),l+=encodeURIComponent(p)+"="+encodeURIComponent(d[p]));return l}function y(d){let l={},p=d.split("&");for(let o=0,g=p.length;o<g;o++){let u=p[o].split("=");l[decodeURIComponent(u[0])]=decodeURIComponent(u[1])}return l}return B}var ee;function N(){if(ee)return q;ee=1;var n=v&&v.__importDefault||function(i){return i&&i.__esModule?i:{default:i}};Object.defineProperty(q,"__esModule",{value:!0}),q.Transport=q.TransportError=void 0;const y=M(),d=J,l=x(),p=pe(),g=(0,n(j()).default)("engine.io-client:transport");class u extends Error{constructor(s,h,c){super(s),this.description=h,this.context=c,this.type="TransportError"}}q.TransportError=u;class a extends d.Emitter{constructor(s){super(),this.writable=!1,(0,l.installTimerFunctions)(this,s),this.opts=s,this.query=s.query,this.socket=s.socket,this.supportsBinary=!s.forceBase64}onError(s,h,c){return super.emitReserved("error",new u(s,h,c)),this}open(){return this.readyState="opening",this.doOpen(),this}close(){return(this.readyState==="opening"||this.readyState==="open")&&(this.doClose(),this.onClose()),this}send(s){this.readyState==="open"?this.write(s):g("transport is not open, discarding packets")}onOpen(){this.readyState="open",this.writable=!0,super.emitReserved("open")}onData(s){const h=(0,y.decodePacket)(s,this.socket.binaryType);this.onPacket(h)}onPacket(s){super.emitReserved("packet",s)}onClose(s){this.readyState="closed",super.emitReserved("close",s)}pause(s){}createUri(s,h={}){return s+"://"+this._hostname()+this._port()+this.opts.path+this._query(h)}_hostname(){const s=this.opts.hostname;return s.indexOf(":")===-1?s:"["+s+"]"}_port(){return this.opts.port&&(this.opts.secure&&Number(this.opts.port!==443)||!this.opts.secure&&Number(this.opts.port)!==80)?":"+this.opts.port:""}_query(s){const h=(0,p.encode)(s);return h.length?"?"+h:""}}return q.Transport=a,q}var te;function de(){if(te)return L;te=1;var n=v&&v.__importDefault||function(u){return u&&u.__esModule?u:{default:u}};Object.defineProperty(L,"__esModule",{value:!0}),L.Polling=void 0;const y=N(),d=x(),l=M(),o=(0,n(j()).default)("engine.io-client:polling");class g extends y.Transport{constructor(){super(...arguments),this._polling=!1}get name(){return"polling"}doOpen(){this._poll()}pause(a){this.readyState="pausing";const i=()=>{o("paused"),this.readyState="paused",a()};if(this._polling||!this.writable){let s=0;this._polling&&(o("we are currently polling - waiting to pause"),s++,this.once("pollComplete",function(){o("pre-pause polling complete"),--s||i()})),this.writable||(o("we are currently writing - waiting to pause"),s++,this.once("drain",function(){o("pre-pause writing complete"),--s||i()}))}else i()}_poll(){o("polling"),this._polling=!0,this.doPoll(),this.emitReserved("poll")}onData(a){o("polling got data %s",a);const i=s=>{if(this.readyState==="opening"&&s.type==="open"&&this.onOpen(),s.type==="close")return this.onClose({description:"transport closed by the server"}),!1;this.onPacket(s)};(0,l.decodePayload)(a,this.socket.binaryType).forEach(i),this.readyState!=="closed"&&(this._polling=!1,this.emitReserved("pollComplete"),this.readyState==="open"?this._poll():o('ignoring poll - transport state "%s"',this.readyState))}doClose(){const a=()=>{o("writing close packet"),this.write([{type:"close"}])};this.readyState==="open"?(o("transport open - closing"),a()):(o("transport not open - deferring close"),this.once("open",a))}write(a){this.writable=!1,(0,l.encodePayload)(a,i=>{this.doWrite(i,()=>{this.writable=!0,this.emitReserved("drain")})})}uri(){const a=this.opts.secure?"https":"http",i=this.query||{};return this.opts.timestampRequests!==!1&&(i[this.opts.timestampParam]=(0,d.randomString)()),!this.supportsBinary&&!i.sid&&(i.b64=1),this.createUri(a,i)}}return L.Polling=g,L}var H={},re;function me(){if(re)return H;re=1,Object.defineProperty(H,"__esModule",{value:!0}),H.hasCORS=void 0;let n=!1;try{n=typeof XMLHttpRequest<"u"&&"withCredentials"in new XMLHttpRequest}catch{}return H.hasCORS=n,H}var se;function A(){if(se)return w;se=1;var n=v&&v.__importDefault||function(f){return f&&f.__esModule?f:{default:f}};Object.defineProperty(w,"__esModule",{value:!0}),w.XHR=w.Request=w.BaseXHR=void 0;const y=de(),d=J,l=x(),p=O(),o=me(),u=(0,n(j()).default)("engine.io-client:polling");function a(){}class i extends y.Polling{constructor(e){if(super(e),typeof location<"u"){const t=location.protocol==="https:";let r=location.port;r||(r=t?"443":"80"),this.xd=typeof location<"u"&&e.hostname!==location.hostname||r!==e.port}}doWrite(e,t){const r=this.request({method:"POST",data:e});r.on("success",t),r.on("error",(_,P)=>{this.onError("xhr post error",_,P)})}doPoll(){u("xhr poll");const e=this.request();e.on("data",this.onData.bind(this)),e.on("error",(t,r)=>{this.onError("xhr poll error",t,r)}),this.pollXhr=e}}w.BaseXHR=i;class s extends d.Emitter{constructor(e,t,r){super(),this.createRequest=e,(0,l.installTimerFunctions)(this,r),this._opts=r,this._method=r.method||"GET",this._uri=t,this._data=r.data!==void 0?r.data:null,this._create()}_create(){var e;const t=(0,l.pick)(this._opts,"agent","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","autoUnref");t.xdomain=!!this._opts.xd;const r=this._xhr=this.createRequest(t);try{u("xhr open %s: %s",this._method,this._uri),r.open(this._method,this._uri,!0);try{if(this._opts.extraHeaders){r.setDisableHeaderCheck&&r.setDisableHeaderCheck(!0);for(let _ in this._opts.extraHeaders)this._opts.extraHeaders.hasOwnProperty(_)&&r.setRequestHeader(_,this._opts.extraHeaders[_])}}catch{}if(this._method==="POST")try{r.setRequestHeader("Content-type","text/plain;charset=UTF-8")}catch{}try{r.setRequestHeader("Accept","*/*")}catch{}(e=this._opts.cookieJar)===null||e===void 0||e.addCookies(r),"withCredentials"in r&&(r.withCredentials=this._opts.withCredentials),this._opts.requestTimeout&&(r.timeout=this._opts.requestTimeout),r.onreadystatechange=()=>{var _;r.readyState===3&&((_=this._opts.cookieJar)===null||_===void 0||_.parseCookies(r.getResponseHeader("set-cookie"))),r.readyState===4&&(r.status===200||r.status===1223?this._onLoad():this.setTimeoutFn(()=>{this._onError(typeof r.status=="number"?r.status:0)},0))},u("xhr data %s",this._data),r.send(this._data)}catch(_){this.setTimeoutFn(()=>{this._onError(_)},0);return}typeof document<"u"&&(this._index=s.requestsCount++,s.requests[this._index]=this)}_onError(e){this.emitReserved("error",e,this._xhr),this._cleanup(!0)}_cleanup(e){if(!(typeof this._xhr>"u"||this._xhr===null)){if(this._xhr.onreadystatechange=a,e)try{this._xhr.abort()}catch{}typeof document<"u"&&delete s.requests[this._index],this._xhr=null}}_onLoad(){const e=this._xhr.responseText;e!==null&&(this.emitReserved("data",e),this.emitReserved("success"),this._cleanup())}abort(){this._cleanup()}}if(w.Request=s,s.requestsCount=0,s.requests={},typeof document<"u"){if(typeof attachEvent=="function")attachEvent("onunload",h);else if(typeof addEventListener=="function"){const f="onpagehide"in p.globalThisShim?"pagehide":"unload";addEventListener(f,h,!1)}}function h(){for(let f in s.requests)s.requests.hasOwnProperty(f)&&s.requests[f].abort()}const c=function(){const f=b({xdomain:!1});return f&&f.responseType!==null}();class m extends i{constructor(e){super(e);const t=e&&e.forceBase64;this.supportsBinary=c&&!t}request(e={}){return Object.assign(e,{xd:this.xd},this.opts),new s(b,this.uri(),e)}}w.XHR=m;function b(f){const e=f.xdomain;try{if(typeof XMLHttpRequest<"u"&&(!e||o.hasCORS))return new XMLHttpRequest}catch{}if(!e)try{return new p.globalThisShim[["Active"].concat("Object").join("X")]("Microsoft.XMLHTTP")}catch{}}return w}var E={},ie;function z(){if(ie)return E;ie=1;var n=v&&v.__importDefault||function(h){return h&&h.__esModule?h:{default:h}};Object.defineProperty(E,"__esModule",{value:!0}),E.WS=E.BaseWS=void 0;const y=N(),d=x(),l=M(),p=O(),g=(0,n(j()).default)("engine.io-client:websocket"),u=typeof navigator<"u"&&typeof navigator.product=="string"&&navigator.product.toLowerCase()==="reactnative";class a extends y.Transport{get name(){return"websocket"}doOpen(){const c=this.uri(),m=this.opts.protocols,b=u?{}:(0,d.pick)(this.opts,"agent","perMessageDeflate","pfx","key","passphrase","cert","ca","ciphers","rejectUnauthorized","localAddress","protocolVersion","origin","maxPayload","family","checkServerIdentity");this.opts.extraHeaders&&(b.headers=this.opts.extraHeaders);try{this.ws=this.createSocket(c,m,b)}catch(f){return this.emitReserved("error",f)}this.ws.binaryType=this.socket.binaryType,this.addEventListeners()}addEventListeners(){this.ws.onopen=()=>{this.opts.autoUnref&&this.ws._socket.unref(),this.onOpen()},this.ws.onclose=c=>this.onClose({description:"websocket connection closed",context:c}),this.ws.onmessage=c=>this.onData(c.data),this.ws.onerror=c=>this.onError("websocket error",c)}write(c){this.writable=!1;for(let m=0;m<c.length;m++){const b=c[m],f=m===c.length-1;(0,l.encodePacket)(b,this.supportsBinary,e=>{try{this.doWrite(b,e)}catch{g("websocket closed before onclose event")}f&&(0,p.nextTick)(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){typeof this.ws<"u"&&(this.ws.onerror=()=>{},this.ws.close(),this.ws=null)}uri(){const c=this.opts.secure?"wss":"ws",m=this.query||{};return this.opts.timestampRequests&&(m[this.opts.timestampParam]=(0,d.randomString)()),this.supportsBinary||(m.b64=1),this.createUri(c,m)}}E.BaseWS=a;const i=p.globalThisShim.WebSocket||p.globalThisShim.MozWebSocket;class s extends a{createSocket(c,m,b){return u?new i(c,m,b):m?new i(c,m):new i(c)}doWrite(c,m){this.ws.send(m)}}return E.WS=s,E}var F={},ne;function fe(){if(ne)return F;ne=1;var n=v&&v.__importDefault||function(u){return u&&u.__esModule?u:{default:u}};Object.defineProperty(F,"__esModule",{value:!0}),F.WT=void 0;const y=N(),d=O(),l=M(),o=(0,n(j()).default)("engine.io-client:webtransport");class g extends y.Transport{get name(){return"webtransport"}doOpen(){try{this._transport=new WebTransport(this.createUri("https"),this.opts.transportOptions[this.name])}catch(a){return this.emitReserved("error",a)}this._transport.closed.then(()=>{o("transport closed gracefully"),this.onClose()}).catch(a=>{o("transport closed due to %s",a),this.onError("webtransport error",a)}),this._transport.ready.then(()=>{this._transport.createBidirectionalStream().then(a=>{const i=(0,l.createPacketDecoderStream)(Number.MAX_SAFE_INTEGER,this.socket.binaryType),s=a.readable.pipeThrough(i).getReader(),h=(0,l.createPacketEncoderStream)();h.readable.pipeTo(a.writable),this._writer=h.writable.getWriter();const c=()=>{s.read().then(({done:b,value:f})=>{if(b){o("session is closed");return}o("received chunk: %o",f),this.onPacket(f),c()}).catch(b=>{o("an error occurred while reading: %s",b)})};c();const m={type:"open"};this.query.sid&&(m.data=`{"sid":"${this.query.sid}"}`),this._writer.write(m).then(()=>this.onOpen())})})}write(a){this.writable=!1;for(let i=0;i<a.length;i++){const s=a[i],h=i===a.length-1;this._writer.write(s).then(()=>{h&&(0,d.nextTick)(()=>{this.writable=!0,this.emitReserved("drain")},this.setTimeoutFn)})}}doClose(){var a;(a=this._transport)===null||a===void 0||a.close()}}return F.WT=g,F}var oe;function _e(){if(oe)return W;oe=1,Object.defineProperty(W,"__esModule",{value:!0}),W.transports=void 0;const n=A(),y=z(),d=fe();return W.transports={websocket:y.WS,webtransport:d.WT,polling:n.XHR},W}var X={},ae;function ge(){if(ae)return X;ae=1,Object.defineProperty(X,"__esModule",{value:!0}),X.parse=d;const n=/^(?:(?![^:@\/?#]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@\/?#]*)(?::([^:@\/?#]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,y=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"];function d(o){if(o.length>8e3)throw"URI too long";const g=o,u=o.indexOf("["),a=o.indexOf("]");u!=-1&&a!=-1&&(o=o.substring(0,u)+o.substring(u,a).replace(/:/g,";")+o.substring(a,o.length));let i=n.exec(o||""),s={},h=14;for(;h--;)s[y[h]]=i[h]||"";return u!=-1&&a!=-1&&(s.source=g,s.host=s.host.substring(1,s.host.length-1).replace(/;/g,":"),s.authority=s.authority.replace("[","").replace("]","").replace(/;/g,":"),s.ipv6uri=!0),s.pathNames=l(s,s.path),s.queryKey=p(s,s.query),s}function l(o,g){const u=/\/{2,9}/g,a=g.replace(u,"/").split("/");return(g.slice(0,1)=="/"||g.length===0)&&a.splice(0,1),g.slice(-1)=="/"&&a.splice(a.length-1,1),a}function p(o,g){const u={};return g.replace(/(?:^|&)([^&=]*)=?([^&]*)/g,function(a,i,s){i&&(u[i]=s)}),u}return X}var ce;function he(){if(ce)return k;ce=1;var n=v&&v.__importDefault||function(f){return f&&f.__esModule?f:{default:f}};Object.defineProperty(k,"__esModule",{value:!0}),k.Socket=k.SocketWithUpgrade=k.SocketWithoutUpgrade=void 0;const y=_e(),d=x(),l=pe(),p=ge(),o=J,g=M(),u=O(),i=(0,n(j()).default)("engine.io-client:socket"),s=typeof addEventListener=="function"&&typeof removeEventListener=="function",h=[];s&&addEventListener("offline",()=>{i("closing %d connection(s) because the network was lost",h.length),h.forEach(f=>f())},!1);class c extends o.Emitter{constructor(e,t){if(super(),this.binaryType=u.defaultBinaryType,this.writeBuffer=[],this._prevBufferLen=0,this._pingInterval=-1,this._pingTimeout=-1,this._maxPayload=-1,this._pingTimeoutTime=1/0,e&&typeof e=="object"&&(t=e,e=null),e){const r=(0,p.parse)(e);t.hostname=r.host,t.secure=r.protocol==="https"||r.protocol==="wss",t.port=r.port,r.query&&(t.query=r.query)}else t.host&&(t.hostname=(0,p.parse)(t.host).host);(0,d.installTimerFunctions)(this,t),this.secure=t.secure!=null?t.secure:typeof location<"u"&&location.protocol==="https:",t.hostname&&!t.port&&(t.port=this.secure?"443":"80"),this.hostname=t.hostname||(typeof location<"u"?location.hostname:"localhost"),this.port=t.port||(typeof location<"u"&&location.port?location.port:this.secure?"443":"80"),this.transports=[],this._transportsByName={},t.transports.forEach(r=>{const _=r.prototype.name;this.transports.push(_),this._transportsByName[_]=r}),this.opts=Object.assign({path:"/engine.io",agent:!1,withCredentials:!1,upgrade:!0,timestampParam:"t",rememberUpgrade:!1,addTrailingSlash:!0,rejectUnauthorized:!0,perMessageDeflate:{threshold:1024},transportOptions:{},closeOnBeforeunload:!1},t),this.opts.path=this.opts.path.replace(/\/$/,"")+(this.opts.addTrailingSlash?"/":""),typeof this.opts.query=="string"&&(this.opts.query=(0,l.decode)(this.opts.query)),s&&(this.opts.closeOnBeforeunload&&(this._beforeunloadEventListener=()=>{this.transport&&(this.transport.removeAllListeners(),this.transport.close())},addEventListener("beforeunload",this._beforeunloadEventListener,!1)),this.hostname!=="localhost"&&(i("adding listener for the 'offline' event"),this._offlineEventListener=()=>{this._onClose("transport close",{description:"network connection lost"})},h.push(this._offlineEventListener))),this.opts.withCredentials&&(this._cookieJar=(0,u.createCookieJar)()),this._open()}createTransport(e){i('creating transport "%s"',e);const t=Object.assign({},this.opts.query);t.EIO=g.protocol,t.transport=e,this.id&&(t.sid=this.id);const r=Object.assign({},this.opts,{query:t,socket:this,hostname:this.hostname,secure:this.secure,port:this.port},this.opts.transportOptions[e]);return i("options: %j",r),new this._transportsByName[e](r)}_open(){if(this.transports.length===0){this.setTimeoutFn(()=>{this.emitReserved("error","No transports available")},0);return}const e=this.opts.rememberUpgrade&&c.priorWebsocketSuccess&&this.transports.indexOf("websocket")!==-1?"websocket":this.transports[0];this.readyState="opening";const t=this.createTransport(e);t.open(),this.setTransport(t)}setTransport(e){i("setting transport %s",e.name),this.transport&&(i("clearing existing transport %s",this.transport.name),this.transport.removeAllListeners()),this.transport=e,e.on("drain",this._onDrain.bind(this)).on("packet",this._onPacket.bind(this)).on("error",this._onError.bind(this)).on("close",t=>this._onClose("transport close",t))}onOpen(){i("socket open"),this.readyState="open",c.priorWebsocketSuccess=this.transport.name==="websocket",this.emitReserved("open"),this.flush()}_onPacket(e){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing")switch(i('socket receive: type "%s", data "%s"',e.type,e.data),this.emitReserved("packet",e),this.emitReserved("heartbeat"),e.type){case"open":this.onHandshake(JSON.parse(e.data));break;case"ping":this._sendPacket("pong"),this.emitReserved("ping"),this.emitReserved("pong"),this._resetPingTimeout();break;case"error":const t=new Error("server error");t.code=e.data,this._onError(t);break;case"message":this.emitReserved("data",e.data),this.emitReserved("message",e.data);break}else i('packet received with socket readyState "%s"',this.readyState)}onHandshake(e){this.emitReserved("handshake",e),this.id=e.sid,this.transport.query.sid=e.sid,this._pingInterval=e.pingInterval,this._pingTimeout=e.pingTimeout,this._maxPayload=e.maxPayload,this.onOpen(),this.readyState!=="closed"&&this._resetPingTimeout()}_resetPingTimeout(){this.clearTimeoutFn(this._pingTimeoutTimer);const e=this._pingInterval+this._pingTimeout;this._pingTimeoutTime=Date.now()+e,this._pingTimeoutTimer=this.setTimeoutFn(()=>{this._onClose("ping timeout")},e),this.opts.autoUnref&&this._pingTimeoutTimer.unref()}_onDrain(){this.writeBuffer.splice(0,this._prevBufferLen),this._prevBufferLen=0,this.writeBuffer.length===0?this.emitReserved("drain"):this.flush()}flush(){if(this.readyState!=="closed"&&this.transport.writable&&!this.upgrading&&this.writeBuffer.length){const e=this._getWritablePackets();i("flushing %d packets in socket",e.length),this.transport.send(e),this._prevBufferLen=e.length,this.emitReserved("flush")}}_getWritablePackets(){if(!(this._maxPayload&&this.transport.name==="polling"&&this.writeBuffer.length>1))return this.writeBuffer;let t=1;for(let r=0;r<this.writeBuffer.length;r++){const _=this.writeBuffer[r].data;if(_&&(t+=(0,d.byteLength)(_)),r>0&&t>this._maxPayload)return i("only send %d out of %d packets",r,this.writeBuffer.length),this.writeBuffer.slice(0,r);t+=2}return i("payload size is %d (max: %d)",t,this._maxPayload),this.writeBuffer}_hasPingExpired(){if(!this._pingTimeoutTime)return!0;const e=Date.now()>this._pingTimeoutTime;return e&&(i("throttled timer detected, scheduling connection close"),this._pingTimeoutTime=0,(0,u.nextTick)(()=>{this._onClose("ping timeout")},this.setTimeoutFn)),e}write(e,t,r){return this._sendPacket("message",e,t,r),this}send(e,t,r){return this._sendPacket("message",e,t,r),this}_sendPacket(e,t,r,_){if(typeof t=="function"&&(_=t,t=void 0),typeof r=="function"&&(_=r,r=null),this.readyState==="closing"||this.readyState==="closed")return;r=r||{},r.compress=r.compress!==!1;const P={type:e,data:t,options:r};this.emitReserved("packetCreate",P),this.writeBuffer.push(P),_&&this.once("flush",_),this.flush()}close(){const e=()=>{this._onClose("forced close"),i("socket closing - telling transport to close"),this.transport.close()},t=()=>{this.off("upgrade",t),this.off("upgradeError",t),e()},r=()=>{this.once("upgrade",t),this.once("upgradeError",t)};return(this.readyState==="opening"||this.readyState==="open")&&(this.readyState="closing",this.writeBuffer.length?this.once("drain",()=>{this.upgrading?r():e()}):this.upgrading?r():e()),this}_onError(e){if(i("socket error %j",e),c.priorWebsocketSuccess=!1,this.opts.tryAllTransports&&this.transports.length>1&&this.readyState==="opening")return i("trying next transport"),this.transports.shift(),this._open();this.emitReserved("error",e),this._onClose("transport error",e)}_onClose(e,t){if(this.readyState==="opening"||this.readyState==="open"||this.readyState==="closing"){if(i('socket close with reason: "%s"',e),this.clearTimeoutFn(this._pingTimeoutTimer),this.transport.removeAllListeners("close"),this.transport.close(),this.transport.removeAllListeners(),s&&(this._beforeunloadEventListener&&removeEventListener("beforeunload",this._beforeunloadEventListener,!1),this._offlineEventListener)){const r=h.indexOf(this._offlineEventListener);r!==-1&&(i("removing listener for the 'offline' event"),h.splice(r,1))}this.readyState="closed",this.id=null,this.emitReserved("close",e,t),this.writeBuffer=[],this._prevBufferLen=0}}}k.SocketWithoutUpgrade=c,c.protocol=g.protocol;class m extends c{constructor(){super(...arguments),this._upgrades=[]}onOpen(){if(super.onOpen(),this.readyState==="open"&&this.opts.upgrade){i("starting upgrade probes");for(let e=0;e<this._upgrades.length;e++)this._probe(this._upgrades[e])}}_probe(e){i('probing transport "%s"',e);let t=this.createTransport(e),r=!1;c.priorWebsocketSuccess=!1;const _=()=>{r||(i('probe transport "%s" opened',e),t.send([{type:"ping",data:"probe"}]),t.once("packet",S=>{if(!r)if(S.type==="pong"&&S.data==="probe"){if(i('probe transport "%s" pong',e),this.upgrading=!0,this.emitReserved("upgrading",t),!t)return;c.priorWebsocketSuccess=t.name==="websocket",i('pausing current transport "%s"',this.transport.name),this.transport.pause(()=>{r||this.readyState!=="closed"&&(i("changing transport and sending upgrade packet"),K(),this.setTransport(t),t.send([{type:"upgrade"}]),this.emitReserved("upgrade",t),t=null,this.upgrading=!1,this.flush())})}else{i('probe transport "%s" failed',e);const C=new Error("probe error");C.transport=t.name,this.emitReserved("upgradeError",C)}}))};function P(){r||(r=!0,K(),t.close(),t=null)}const D=S=>{const C=new Error("probe error: "+S);C.transport=t.name,P(),i('probe transport "%s" failed because of error: %s',e,S),this.emitReserved("upgradeError",C)};function G(){D("transport closed")}function $(){D("socket closed")}function V(S){t&&S.name!==t.name&&(i('"%s" works - aborting "%s"',S.name,t.name),P())}const K=()=>{t.removeListener("open",_),t.removeListener("error",D),t.removeListener("close",G),this.off("close",$),this.off("upgrading",V)};t.once("open",_),t.once("error",D),t.once("close",G),this.once("close",$),this.once("upgrading",V),this._upgrades.indexOf("webtransport")!==-1&&e!=="webtransport"?this.setTimeoutFn(()=>{r||t.open()},200):t.open()}onHandshake(e){this._upgrades=this._filterUpgrades(e.upgrades),super.onHandshake(e)}_filterUpgrades(e){const t=[];for(let r=0;r<e.length;r++)~this.transports.indexOf(e[r])&&t.push(e[r]);return t}}k.SocketWithUpgrade=m;class b extends m{constructor(e,t={}){const r=typeof e=="object"?e:t;(!r.transports||r.transports&&typeof r.transports[0]=="string")&&(r.transports=(r.transports||["polling","websocket","webtransport"]).map(_=>y.transports[_]).filter(_=>!!_)),super(e,r)}}return k.Socket=b,k}var U={},ue;function ye(){if(ue)return U;ue=1,Object.defineProperty(U,"__esModule",{value:!0}),U.Fetch=void 0;const n=de();class y extends n.Polling{doPoll(){this._fetch().then(l=>{if(!l.ok)return this.onError("fetch read error",l.status,l);l.text().then(p=>this.onData(p))}).catch(l=>{this.onError("fetch read error",l)})}doWrite(l,p){this._fetch(l).then(o=>{if(!o.ok)return this.onError("fetch write error",o.status,o);p()}).catch(o=>{this.onError("fetch write error",o)})}_fetch(l){var p;const o=l!==void 0,g=new Headers(this.opts.extraHeaders);return o&&g.set("content-type","text/plain;charset=UTF-8"),(p=this.socket._cookieJar)===null||p===void 0||p.appendCookies(g),fetch(this.uri(),{method:o?"POST":"GET",body:o?l:null,headers:g,credentials:this.opts.withCredentials?"include":"omit"}).then(u=>{var a;return(a=this.socket._cookieJar)===null||a===void 0||a.parseCookies(u.headers.getSetCookie()),u})}}return U.Fetch=y,U}var le;function we(){return le||(le=1,function(n){Object.defineProperty(n,"__esModule",{value:!0}),n.WebTransport=n.WebSocket=n.NodeWebSocket=n.XHR=n.NodeXHR=n.Fetch=n.nextTick=n.parse=n.installTimerFunctions=n.transports=n.TransportError=n.Transport=n.protocol=n.SocketWithUpgrade=n.SocketWithoutUpgrade=n.Socket=void 0;const y=he();Object.defineProperty(n,"Socket",{enumerable:!0,get:function(){return y.Socket}});var d=he();Object.defineProperty(n,"SocketWithoutUpgrade",{enumerable:!0,get:function(){return d.SocketWithoutUpgrade}}),Object.defineProperty(n,"SocketWithUpgrade",{enumerable:!0,get:function(){return d.SocketWithUpgrade}}),n.protocol=y.Socket.protocol;var l=N();Object.defineProperty(n,"Transport",{enumerable:!0,get:function(){return l.Transport}}),Object.defineProperty(n,"TransportError",{enumerable:!0,get:function(){return l.TransportError}});var p=_e();Object.defineProperty(n,"transports",{enumerable:!0,get:function(){return p.transports}});var o=x();Object.defineProperty(n,"installTimerFunctions",{enumerable:!0,get:function(){return o.installTimerFunctions}});var g=ge();Object.defineProperty(n,"parse",{enumerable:!0,get:function(){return g.parse}});var u=O();Object.defineProperty(n,"nextTick",{enumerable:!0,get:function(){return u.nextTick}});var a=ye();Object.defineProperty(n,"Fetch",{enumerable:!0,get:function(){return a.Fetch}});var i=A();Object.defineProperty(n,"NodeXHR",{enumerable:!0,get:function(){return i.XHR}});var s=A();Object.defineProperty(n,"XHR",{enumerable:!0,get:function(){return s.XHR}});var h=z();Object.defineProperty(n,"NodeWebSocket",{enumerable:!0,get:function(){return h.WS}});var c=z();Object.defineProperty(n,"WebSocket",{enumerable:!0,get:function(){return c.WS}});var m=fe();Object.defineProperty(n,"WebTransport",{enumerable:!0,get:function(){return m.WT}})}(I)),I}export{we as r};