import { A as AbstractEventDispatcher, E as EventDispatcherInterface, a as EventListener } from './AbstractEventDispatcher-CdpR1_nX.mjs'; interface CustomEventOptions { bubbles?: boolean; cancelable?: boolean; composed?: boolean; } /** * Browser-optimized EventDispatcher. * * Philosophy: * ───────────────────────────────────────────────────────────── * dispatch() is the single entry point. It does two things in order: * * 1. Iterates the internal Map → calls subscribers/listeners registered * via addListener() / addSubscriber(), in priority order. * * 2. Fires a CustomEvent on the native EventTarget (dispatchNative) → * any code that used window.addEventListener(), document.addEventListener(), * or target.addEventListener() DIRECTLY (without going through this dispatcher) * will also receive the event automatically. * * This means the developer never needs to call dispatchNative() manually — * a single dispatcher.dispatch() notifies both worlds. * * No double-call: addListener() stores listeners in the Map only, NOT on * the native EventTarget. The native target is reserved for external listeners. * * @author AGBOKOUDJO Franck */ declare class BrowserEventDispatcher extends AbstractEventDispatcher implements EventDispatcherInterface { private readonly eventTarget; private readonly options?; private readonly listeners; private readonly sorted; private readonly listenerMap; constructor(eventTarget?: EventTarget, options?: CustomEventOptions | undefined); /** * Dispatches an event synchronously. * * Step 1 — Internal Map loop (priority order): * Calls all listeners registered via addListener() / addSubscriber(). * stopPropagation() is honoured between each listener. * Async listeners are fire-and-forget (errors logged, not thrown). * Use dispatchAsync() if you need to await async listeners. * * Step 2 — Native EventTarget (dispatchNative): * Fires a CustomEvent so that any external listener attached via * window.addEventListener() / document.addEventListener() on the same * target also receives the event — without ever registering through * this dispatcher. * * Note: stopPropagation() on YOUR event object does NOT prevent Step 2. * The CustomEvent dispatched natively is independent and can be cancelled * via nativeEvent.stopPropagation() on the browser side. */ dispatch(event: T, eventName?: string | null, _customOptions?: CustomEventOptions): T; /** * Dispatches an event and awaits all listeners sequentially (priority order). * * Step 1 — awaits each async listener in the internal Map. * Step 2 — fires the native CustomEvent (fire-and-forget, not awaited — * native EventTarget listeners are synchronous by design). * * Use this when subscribers perform async work (HTTP, file I/O…) and * you need to read results from the event object after dispatch. * * @example * const event = new InitializingUploadEvent(options); * await dispatcher.dispatchAsync(event, HttpFileUploaderEvents.INITIALIZE_UPLOAD); * const mediaId = event.mediaId; // safely populated by the subscriber */ dispatchAsync(event: T, eventName?: string | null, _customOptions?: CustomEventOptions): Promise; /** * Registers a listener in the internal Map only. * * NOT attached to the native EventTarget — that target is reserved for * external listeners (window.addEventListener, etc.) to avoid double-call. */ addListener(eventName: string, listener: EventListener, priority?: number): void; /** * Removes a listener from the internal Map only. * Has no effect on listeners attached directly via addEventListener(). */ removeListener(eventName: string, listener: EventListener): void; getListeners(eventName?: string | null): EventListener[] | Map; getListenerPriority(eventName: string, listener: EventListener): number | null; hasListeners(eventName?: string | null): boolean; /** * Returns the underlying EventTarget. * * Pass window or document in the constructor to share the same target * with the rest of your application — any addEventListener() call on * that target will automatically receive events dispatched via dispatch(). * * @example * const dispatcher = new BrowserEventDispatcher(window); * * // Somewhere else in your app — no addListener() needed * window.addEventListener('user.login', (e) => { * console.log((e as CustomEvent).detail); * }); * * // This notifies both your subscribers AND the window listener * dispatcher.dispatch(new UserLoginEvent('franck'), 'user.login'); */ getEventTarget(): EventTarget; private sortListeners; /** * Fires a CustomEvent on the native EventTarget. * * Called automatically by dispatch() and dispatchAsync(). * Can also be called manually if you want to notify native listeners * without going through the internal Map. * * External listeners receive the original event object via * `(e as CustomEvent).detail`. * * @example * // External code — no addListener() needed, works automatically * window.addEventListener('user.login', (e) => { * const event = (e as CustomEvent).detail; * console.log(event.username); * }); * * dispatcher.dispatch(new UserLoginEvent('franck'), 'user.login'); * // ↑ window listener receives the event automatically via dispatchNative */ private dispatchNative; } export { BrowserEventDispatcher, type CustomEventOptions };