'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var __accessCheck = (obj, member, msg) => { if (!member.has(obj)) throw TypeError("Cannot " + msg); }; var __privateGet = (obj, member, getter) => { __accessCheck(obj, member, "read from private field"); return getter ? getter.call(obj) : member.get(obj); }; var __privateAdd = (obj, member, value) => { if (member.has(obj)) throw TypeError("Cannot add the same private member more than once"); member instanceof WeakSet ? member.add(obj) : member.set(obj, value); }; var __privateSet = (obj, member, value, setter) => { __accessCheck(obj, member, "write to private field"); setter ? setter.call(obj, value) : member.set(obj, value); return value; }; var _listenerMap, _wildcardListeners, _errorHandler; class LiteEmit { constructor(options) { __privateAdd(this, _listenerMap, /* @__PURE__ */ new Map()); __privateAdd(this, _wildcardListeners, /* @__PURE__ */ new Set()); __privateAdd(this, _errorHandler, void 0); __privateSet(this, _errorHandler, options == null ? void 0 : options.errorHandler); } on(event, listener) { if (event === "*") { __privateGet(this, _wildcardListeners).add(listener); return this; } if (!__privateGet(this, _listenerMap).has(event)) { __privateGet(this, _listenerMap).set(event, /* @__PURE__ */ new Set()); } __privateGet(this, _listenerMap).get(event).add(listener); return this; } once(event, listener) { const onceListener = (...args) => { this.off(event, onceListener); listener(...args); }; return this.on(event, onceListener); } emit(event, ...args) { var _a, _b; if (__privateGet(this, _listenerMap).has(event)) { for (const listener of __privateGet(this, _wildcardListeners)) { try { const result = listener(event, ...args); if (result instanceof Promise) { result.catch((e) => { var _a2; (_a2 = __privateGet(this, _errorHandler)) == null ? void 0 : _a2.call(this, e.message); }); } } catch (e) { (_a = __privateGet(this, _errorHandler)) == null ? void 0 : _a.call(this, e.message); } } for (const listener of __privateGet(this, _listenerMap).get(event)) { try { const result = listener(...args); if (result instanceof Promise) { result.catch((e) => { var _a2; (_a2 = __privateGet(this, _errorHandler)) == null ? void 0 : _a2.call(this, e.message); }); } } catch (e) { (_b = __privateGet(this, _errorHandler)) == null ? void 0 : _b.call(this, e.message); } } } return this; } off(event, listener) { var _a, _b; if (event === void 0) { __privateGet(this, _listenerMap).clear(); __privateGet(this, _wildcardListeners).clear(); return this; } else if (event === "*") { if (listener) { __privateGet(this, _wildcardListeners).delete(listener); } else { __privateGet(this, _wildcardListeners).clear(); } return this; } if (listener) { (_a = __privateGet(this, _listenerMap).get(event)) == null ? void 0 : _a.delete(listener); } else { (_b = __privateGet(this, _listenerMap).get(event)) == null ? void 0 : _b.clear(); } return this; } } _listenerMap = new WeakMap(); _wildcardListeners = new WeakMap(); _errorHandler = new WeakMap(); exports.LiteEmit = LiteEmit;