function te(e){return new Error(`[unenv] ${e} is not implemented yet!`)}function w(e){return Object.assign(()=>{throw te(e)},{__unenv__:!0})}import{AsyncResource as re}from"./node_async_hooks.js";var y=10,ne=Object.getPrototypeOf(Object.getPrototypeOf(async function*(){}).prototype),G=(e,t)=>e,_=Error,ie=Error,v=Error,b=Error,se=Error,C=Symbol.for("nodejs.rejection"),f=Symbol.for("kCapture"),M=Symbol.for("events.errorMonitor"),d=Symbol.for("shapeMode"),x=Symbol.for("events.maxEventTargetListeners"),oe=Symbol.for("kEnhanceStackBeforeInspector"),ue=Symbol.for("nodejs.watermarkData"),S=Symbol.for("kEventEmitter"),h=Symbol.for("kAsyncResource"),le=Symbol.for("kFirstEventParam"),P=Symbol.for("kResistStopPropagation"),W=Symbol.for("events.maxEventTargetListenersWarned"),U=class E{_events=void 0;_eventsCount=0;_maxListeners=y;[f]=!1;[d]=!1;static captureRejectionSymbol=C;static errorMonitor=M;static kMaxEventTargetListeners=x;static kMaxEventTargetListenersWarned=W;static usingDomains=!1;static get on(){return fe}static get once(){return he}static get getEventListeners(){return ve}static get getMaxListeners(){return me}static get addAbortListener(){return X}static get EventEmitterAsyncResource(){return ae}static get EventEmitter(){return E}static setMaxListeners(t=y,...r){if(r.length===0)y=t;else for(let n of r)if(J(n))n[x]=t,n[W]=!1;else if(typeof n.setMaxListeners=="function")n.setMaxListeners(t);else throw new v("eventTargets",["EventEmitter","EventTarget"],n)}static listenerCount(t,r){if(typeof t.listenerCount=="function")return t.listenerCount(r);E.prototype.listenerCount.call(t,r)}static init(){throw new Error("EventEmitter.init() is not implemented.")}static get captureRejections(){return this[f]}static set captureRejections(t){this[f]=t}static get defaultMaxListeners(){return y}static set defaultMaxListeners(t){y=t}constructor(t){this._events===void 0||this._events===Object.getPrototypeOf(this)._events?(this._events={__proto__:null},this._eventsCount=0,this[d]=!1):this[d]=!0,this._maxListeners=this._maxListeners||void 0,t?.captureRejections?this[f]=!!t.captureRejections:this[f]=E.prototype[f]}setMaxListeners(t){return this._maxListeners=t,this}getMaxListeners(){return T(this)}emit(t,...r){let n=t==="error",i=this._events;if(i!==void 0)n&&i[M]!==void 0&&this.emit(M,...r),n=n&&i.error===void 0;else if(!n)return!1;if(n){let s;if(r.length>0&&(s=r[0]),s instanceof Error){try{let c={};Error.captureStackTrace?.(c,E.prototype.emit),Object.defineProperty(s,oe,{__proto__:null,value:Function.prototype.bind(de,this,s,c),configurable:!0})}catch{}throw s}let l;try{l=G(s)}catch{l=s}let a=new ie(l);throw a.context=s,a}let o=i[t];if(o===void 0)return!1;if(typeof o=="function"){let s=o.apply(this,r);s!=null&&K(this,s,t,r)}else{let s=o.length,l=I(o);for(let a=0;a<s;++a){let c=l[a].apply(this,r);c!=null&&K(this,c,t,r)}}return!0}addListener(t,r){return q(this,t,r,!1),this}on(t,r){return this.addListener(t,r)}prependListener(t,r){return q(this,t,r,!0),this}once(t,r){return this.on(t,z(this,t,r)),this}prependOnceListener(t,r){return this.prependListener(t,z(this,t,r)),this}removeListener(t,r){let n=this._events;if(n===void 0)return this;let i=n[t];if(i===void 0)return this;if(i===r||i.listener===r)this._eventsCount-=1,this[d]?n[t]=void 0:this._eventsCount===0?this._events={__proto__:null}:(delete n[t],n.removeListener&&this.emit("removeListener",t,i.listener||r));else if(typeof i!="function"){let o=-1;for(let s=i.length-1;s>=0;s--)if(i[s]===r||i[s].listener===r){o=s;break}if(o<0)return this;o===0?i.shift():ge(i,o),i.length===1&&(n[t]=i[0]),n.removeListener!==void 0&&this.emit("removeListener",t,r)}return this}off(t,r){return this.removeListener(t,r)}removeAllListeners(t){let r=this._events;if(r===void 0)return this;if(r.removeListener===void 0)return arguments.length===0?(this._events={__proto__:null},this._eventsCount=0):r[t]!==void 0&&(--this._eventsCount===0?this._events={__proto__:null}:delete r[t]),this[d]=!1,this;if(arguments.length===0){for(let i of Reflect.ownKeys(r))i!=="removeListener"&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events={__proto__:null},this._eventsCount=0,this[d]=!1,this}let n=r[t];if(typeof n=="function")this.removeListener(t,n);else if(n!==void 0)for(let i=n.length-1;i>=0;i--)this.removeListener(t,n[i]);return this}listeners(t){return B(this,t,!0)}rawListeners(t){return B(this,t,!1)}eventNames(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]}listenerCount(t,r){let n=this._events;if(n!==void 0){let i=n[t];if(typeof i=="function")return r!=null?r===i||r===i.listener?1:0:1;if(i!==void 0){if(r!=null){let o=0;for(let s=0,l=i.length;s<l;s++)(i[s]===r||i[s].listener===r)&&o++;return o}return i.length}}return 0}},ae=class extends U{constructor(e){let t;typeof e=="string"?(t=e,e=void 0):t=e?.name||new.target.name,super(e),this[h]=new ce(this,t,e)}emit(e,...t){if(this[h]===void 0)throw new _("EventEmitterAsyncResource");let{asyncResource:r}=this;return Array.prototype.unshift(t,super.emit,this,e),Reflect.apply(r.runInAsyncScope,r,t)}emitDestroy(){if(this[h]===void 0)throw new _("EventEmitterAsyncResource");this.asyncResource.emitDestroy()}get asyncId(){if(this[h]===void 0)throw new _("EventEmitterAsyncResource");return this.asyncResource.asyncId()}get triggerAsyncId(){if(this[h]===void 0)throw new _("EventEmitterAsyncResource");return this.asyncResource.triggerAsyncId()}get asyncResource(){if(this[h]===void 0)throw new _("EventEmitterAsyncResource");return this[h]}},ce=class extends re{constructor(e,t,r){super(t,r),this[S]=e}get eventEmitter(){if(this[S]===void 0)throw new _("EventEmitterReferencingAsyncResource");return this[S]}},fe=function(e,t,r={}){let n=r.signal;if(n?.aborted)throw new b(void 0,{cause:n?.reason});let i=r.highWaterMark??r.highWatermark??Number.MAX_SAFE_INTEGER,o=r.lowWaterMark??r.lowWatermark??1,s=new N,l=new N,a=!1,c=null,m=!1,p=0,Q=Object.setPrototypeOf({next(){if(p){let u=s.shift();return p--,a&&p<o&&(e.resume?.(),a=!1),Promise.resolve(k(u,!1))}if(c){let u=Promise.reject(c);return c=null,u}return m?L():new Promise(function(u,ee){l.push({resolve:u,reject:ee})})},return(){return L()},throw(u){if(!u||!(u instanceof Error))throw new v("EventEmitter.AsyncIterator","Error",u);R(u)},[Symbol.asyncIterator](){return this},[ue]:{get size(){return p},get low(){return o},get high(){return i},get isPaused(){return a}}},ne),{addEventListener:A,removeAll:V}=Ee();A(e,t,r[le]?$:function(...u){return $(u)}),t!=="error"&&typeof e.on=="function"&&A(e,"error",R);let F=r?.close;if(F?.length)for(let u of F)A(e,u,L);let Y=n?X(n,Z):null;return Q;function Z(){R(new b(void 0,{cause:n?.reason}))}function $(u){l.isEmpty()?(p++,!a&&p>i&&(a=!0,e.pause?.()),s.push(u)):l.shift().resolve(k(u,!1))}function R(u){l.isEmpty()?c=u:l.shift().reject(u),L()}function L(){Y?.[Symbol.dispose](),V(),m=!0;let u=k(void 0,!0);for(;!l.isEmpty();)l.shift().resolve(u);return Promise.resolve(u)}},he=async function(e,t,r={}){let n=r?.signal;if(n?.aborted)throw new b(void 0,{cause:n?.reason});return new Promise((i,o)=>{let s=m=>{typeof e.removeListener=="function"&&e.removeListener(t,l),n!=null&&g(n,"abort",c),o(m)},l=(...m)=>{typeof e.removeListener=="function"&&e.removeListener("error",s),n!=null&&g(n,"abort",c),i(m)},a={__proto__:null,once:!0,[P]:!0};O(e,t,l,a),t!=="error"&&typeof e.once=="function"&&e.once("error",s);function c(){g(e,t,l),g(e,"error",s),o(new b(void 0,{cause:n?.reason}))}n!=null&&O(n,"abort",c,{__proto__:null,once:!0,[P]:!0})})},X=function(e,t){if(e===void 0)throw new v("signal","AbortSignal",e);let r;return e.aborted?queueMicrotask(()=>t()):(e.addEventListener("abort",t,{__proto__:null,once:!0,[P]:!0}),r=()=>{e.removeEventListener("abort",t)}),{__proto__:null,[Symbol.dispose](){r?.()}}},ve=function(e,t){if(typeof e.listeners=="function")return e.listeners(t);if(J(e)){let r=e[kEvents].get(t),n=[],i=r?.next;for(;i?.listener!==void 0;){let o=i.listener?.deref?i.listener.deref():i.listener;n.push(o),i=i.next}return n}throw new v("emitter",["EventEmitter","EventTarget"],e)},me=function(e){if(typeof e?.getMaxListeners=="function")return T(e);if(e?.[x])return e[x];throw new v("emitter",["EventEmitter","EventTarget"],e)},H=2048,j=H-1,D=class{bottom;top;list;next;constructor(){this.bottom=0,this.top=0,this.list=new Array(H),this.next=null}isEmpty(){return this.top===this.bottom}isFull(){return(this.top+1&j)===this.bottom}push(e){this.list[this.top]=e,this.top=this.top+1&j}shift(){let e=this.list[this.bottom];return e===void 0?null:(this.list[this.bottom]=void 0,this.bottom=this.bottom+1&j,e)}},N=class{head;tail;constructor(){this.head=this.tail=new D}isEmpty(){return this.head.isEmpty()}push(e){this.head.isFull()&&(this.head=this.head.next=new D),this.head.push(e)}shift(){let e=this.tail,t=e.shift();return e.isEmpty()&&e.next!==null&&(this.tail=e.next,e.next=null),t}};function J(e){return typeof e?.addEventListener=="function"}function K(e,t,r,n){if(e[f])try{let i=t.then;typeof i=="function"&&i.call(t,void 0,function(o){setTimeout(pe,0,e,o,r,n)})}catch(i){e.emit("error",i)}}function pe(e,t,r,n){if(typeof e[C]=="function")e[C](t,r,...n);else{let i=e[f];try{e[f]=!1,e.emit("error",t)}finally{e[f]=i}}}function T(e){return e._maxListeners===void 0?y:e._maxListeners}function de(e,t){let r="";try{let{name:o}=this.constructor;o!=="EventEmitter"&&(r=` on ${o} instance`)}catch{}let n=`
Emitted 'error' event${r} at:
`,i=(t.stack||"").split(`
`).slice(1);return e.stack+n+i.join(`
`)}function q(e,t,r,n){let i,o,s;if(o=e._events,o===void 0?(o=e._events={__proto__:null},e._eventsCount=0):(o.newListener!==void 0&&(e.emit("newListener",t,r.listener??r),o=e._events),s=o[t]),s===void 0)o[t]=r,++e._eventsCount;else if(typeof s=="function"?s=o[t]=n?[r,s]:[s,r]:n?s.unshift(r):s.push(r),i=T(e),i>0&&s.length>i&&!s.warned){s.warned=!0;let l=new se(`Possible EventEmitter memory leak detected. ${s.length} ${String(t)} listeners added to ${G(e,{depth:-1})}. MaxListeners is ${i}. Use emitter.setMaxListeners() to increase limit`,{name:"MaxListenersExceededWarning",emitter:e,type:t,count:s.length});console.warn(l)}return e}function ye(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function z(e,t,r){let n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},i=ye.bind(n);return i.listener=r,n.wrapFn=i,i}function B(e,t,r){let n=e._events;if(n===void 0)return[];let i=n[t];return i===void 0?[]:typeof i=="function"?r?[i.listener||i]:[i]:r?_e(i):I(i)}function I(e){switch(e.length){case 2:return[e[0],e[1]];case 3:return[e[0],e[1],e[2]];case 4:return[e[0],e[1],e[2],e[3]];case 5:return[e[0],e[1],e[2],e[3],e[4]];case 6:return[e[0],e[1],e[2],e[3],e[4],e[5]]}return Array.prototype.slice.call(e)}function _e(e){let t=I(e);for(let r=0;r<t.length;++r){let n=t[r].listener;typeof n=="function"&&(t[r]=n)}return t}function k(e,t){return{value:e,done:t}}function g(e,t,r,n){if(typeof e.removeListener=="function")e.removeListener(t,r);else if(typeof e.removeEventListener=="function")e.removeEventListener(t,r,n);else throw new v("emitter","EventEmitter",e)}function O(e,t,r,n){if(typeof e.on=="function")n?.once?e.once(t,r):e.on(t,r);else if(typeof e.addEventListener=="function")e.addEventListener(t,r,n);else throw new v("emitter","EventEmitter",e)}function Ee(){let e=[];return{addEventListener(t,r,n,i){O(t,r,n,i),Array.prototype.push(e,[t,r,n,i])},removeAll(){for(;e.length>0;)Reflect.apply(g,void 0,e.pop())}}}function ge(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}var Re=!1,Me=Symbol.for("nodejs.rejection"),Se=!1,je=Symbol.for("events.errorMonitor"),ke=10,Ce=w("node:events.setMaxListeners"),Pe=w("node:events.listenerCount"),Oe=w("node:events.init"),Te=U;export{U as EventEmitter,ae as EventEmitterAsyncResource,X as addAbortListener,Me as captureRejectionSymbol,Se as captureRejections,Te as default,ke as defaultMaxListeners,je as errorMonitor,ve as getEventListeners,me as getMaxListeners,Oe as init,Pe as listenerCount,fe as on,he as once,Ce as setMaxListeners,Re as usingDomains};