/** * Sets up a delegated event listener that invokes `callback` whenever `eventName` fires on (or bubbles through) an * element matching `selector`. * * Internally a single document-level listener is shared across every call with the same `(eventName, capture, * passive)` triple, so the cost of registering N call sites is O(1) listeners - not O(N). When the event fires, * ancestors of `event.target` are walked from inner to outer; for each ancestor that matches `selector`, `callback` is * invoked with `event.currentTarget` patched to point at the matched ancestor. * * `event.stopPropagation()` halts further delegated dispatch on the same event. Non-bubbling events (`focus`, `blur`, * `mouseenter`, `mouseleave`, `load`, `error`, `scroll`) require `{ capture: true }` so the document listener actually * sees them. * * @param eventName - The name of the event to listen for (e.g., 'click', 'focus', 'custom-event') * @param selector - CSS selector to match elements against * @param callback - Function to invoke when the event occurs. Receives the event. * @param options - Optional event listener options. `capture`, `once`, `passive`, and `signal` are honored: * `passive` is forwarded to the shared document listener (so passive and non-passive registrations use separate * listeners), and aborting `signal` removes the registration just like calling the returned cleanup. * @returns A cleanup function that removes the registration * @throws A `SyntaxError`, with nothing registered, for a selector the browser rejects. * * @example * ```ts * // Listen for clicks on all buttons with inferred types * on('click', 'button', (event) => { * console.log('Button clicked:', event.currentTarget); * }); * * // Use event listener options * on('click', '.once-button', (event) => { * console.log('Clicked once'); * }, { once: true }); * * // Manual cleanup * const stop = on('click', 'button', (event) => { * console.log('Clicked'); * }); * stop(); * ``` */ export declare function on(eventName: E, selector: string, callback: (event: HTMLElementEventMap[E]) => void, options?: boolean | AddEventListenerOptions): () => void; export declare function on(eventName: string, selector: string, callback: (event: Ev) => void, options?: boolean | AddEventListenerOptions): () => void; /** * Dispatches a custom event from the specified target element. * * This is a convenience function for creating and dispatching CustomEvents with typed detail data. * Events are created with `bubbles: true` and `composed: true` by default, allowing them to * propagate through the DOM and cross shadow DOM boundaries. * * @param target - The element, window, or document to dispatch the event from * @param eventName - The name of the custom event * @param options - CustomEvent options including detail data and event configuration * @param options.detail - Typed detail payload attached to the event * @returns The CustomEvent that was dispatched * * @example * ```ts * // Dispatch a simple custom event * const button = document.querySelector('button')!; * emit(button, 'custom-click', { detail: { count: 1 } }); * * // Dispatch with typed detail data * interface FormData { * username: string; * email: string; * } * const form = document.querySelector('form')!; * emit(form, 'form-submit', { * detail: { username: 'john', email: 'john@example.com' } * }); * * // Dispatch without bubbling * emit(element, 'local-event', { * detail: { message: 'Hello' }, * bubbles: false * }); * * // Dispatch and access the event object * const event = emit(element, 'my-event', { detail: { success: true }, cancelable: true }); * console.log(event.defaultPrevented); * ``` */ export declare function emit>(target: Element | Window | Document, eventName: string, { detail, ...rest }?: CustomEventInit): CustomEvent; //# sourceMappingURL=events.d.ts.map