"use strict";exports.Bus=class{constructor(){this.listeners=new Map,this.emitted=new Map,this.onceListeners=new Map}on(e,t){const s=this.listeners.get(e)||[];s.push(t),this.listeners.set(e,s),this.emitted.has(e)&&t(...this.emitted.get(e))}once(e,t){if(this.emitted.has(e))return void t(...this.emitted.get(e));const s=(...i)=>{t(...i),this.off(e,s)},i=this.onceListeners.get(e)||new Map;i.set(t,s),this.onceListeners.set(e,i),this.on(e,s)}emit(e,...t){this.emitted.set(e,t);[...this.listeners.get(e)||[]].forEach((e=>e(...t)))}off(e,t){if(t){const s=this.onceListeners.get(e);if(s&&s.has(t)){const i=s.get(t);return this._removeListener(e,i),void s.delete(t)}this._removeListener(e,t)}else this.listeners.delete(e),this.onceListeners.delete(e),this.emitted.delete(e)}_removeListener(e,t){const s=this.listeners.get(e);if(!s)return;const i=s.indexOf(t);i>-1&&(s.splice(i,1),0===s.length&&this.listeners.delete(e))}};
