/** * Event Bus — lightweight publish/subscribe event system. * * Enables decoupled communication between components across the page * without direct DOM access or custom element references. * * @example * // Publish * eventBus.emit('user:login', { userId: '123' }); * * // Subscribe * const off = eventBus.on('user:login', ({ userId }) => { ... }); * off(); // unsubscribe * * // Wait for a single event * const data = await eventBus.once('data:ready'); */ type EventHandler = (data: T) => void; declare class EventBus { private _subs; private _history; /** Subscribe to an event. Returns an unsubscribe function. */ on(event: string, handler: EventHandler): () => void; /** Subscribe to an event once. Auto-unsubscribes after first emission. */ once(event: string, handler?: EventHandler): Promise; /** Emit an event with optional data. */ emit(event: string, data?: T): void; /** Unsubscribe all handlers for an event (or all events if no event given). */ off(event?: string): void; /** Get number of subscribers for an event. */ listenerCount(event: string): number; /** Get all active event names. */ eventNames(): string[]; /** * Subscribe and immediately receive the last emitted value if available (replay). * Useful for late subscribers who may miss earlier emissions. */ replay(event: string, handler: EventHandler): () => void; /** Clear the replay history for an event. */ clearHistory(event?: string): void; } /** Global singleton event bus */ export declare const eventBus: EventBus; /** * Create a namespaced event bus — useful for scoping events per feature/module. * @example * const cartBus = createEventBus('cart'); * cartBus.emit('item:added', item); // internally emits 'cart:item:added' */ export declare function createEventBus(namespace: string): { on(event: string, handler: EventHandler): () => void; once(event: string): Promise; emit(event: string, data?: T): void; off(event?: string): void; }; export type { EventHandler }; //# sourceMappingURL=event-bus.d.ts.map