class n{constructor(){this.listeners={}}subscribe(e,t){this.registerListener(e,t)}subscribeOnce(e,t){this.registerListener(e,t,1)}unsubscribe(e,t){this.deregisterListener(e,t)}trigger(e,...t){this.triggerCallbacks(e,t)}registerListener(e,t,s){if(typeof e!="string")throw new Error("Event name must be a string");if(typeof t!="function")throw new Error("Event callback must be a function");if(s&&typeof s!="number")throw new Error("Execution limit must be a number or undefined");this.listeners[e]=this.listeners[e]??[],this.listeners[e].push({callback:t,executionLimit:s})}deregisterListener(e,t){var r;if(typeof e!="string")throw new Error("Event name must be a string");if(t&&typeof t!="function")throw new Error("Event callback must be a function");if(!t){this.listeners[e]=[];return}const s=(r=this.listeners[e])==null?void 0:r.findIndex(i=>i.callback===t);typeof s!="number"||s===-1||(this.listeners[e].splice(s,1),this.listeners[e].length===0&&delete this.listeners[e])}triggerCallbacks(e,...t){if(!this.listeners[e])return;const s=[];this.listeners[e].forEach(r=>{typeof r.executionLimit=="number"&&(r.executionCount=r.executionCount??0,r.executionCount++,r.executionCount===r.executionLimit&&s.push(r.callback)),r.callback.apply(null,...t)}),s.length&&s.forEach(r=>this.deregisterListener(e,r))}}const u=new n;export{u as E};
//# sourceMappingURL=DlYrdKHv.chunk.js.map
