holosun
Version:
An events API with delegation and type declarations.
242 lines (241 loc) • 22.9 kB
TypeScript
/**
* Attach an event listener that will be called once whenever any of the specified event types are delivered to the given target.
*
* @param target - The target on which the event listener is attached.
* @param types - A case-sensitive string representing the {@link https://developer.mozilla.org/en-US/docs/Web/Events|event type}s to listen for.
* @param listener - The object that receives a notification (an object that implements the {@link https://developer.mozilla.org/en-US/docs/Web/API/Event|Event} interface) when an event of a specified type occurs. This must be an object implementing the {@link https://developer.mozilla.org/en-US/docs/Web/API/EventListener|EventListener} interface, or a function.
* @param useCapture - Whether or not events of these types will be dispatched to the registered listener before being dispatched to any target beneath it in the DOM tree.
*
* @returns The provided listener when successfully attached; otherwise, `undefined`.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#the_event_listener_callback} The event listener callback for details on the callback itself.
*/
declare function any(target: EventTarget, types: string, listener: EventListenerOrEventListenerObject | null, useCapture?: boolean): EventListenerOrEventListenerObject | null | undefined;
/**
* Attach an event listener that will be called once whenever any of the specified event types are delivered to the given target.
*
* @param target - The target on which the event listener is attached.
* @param types - A case-sensitive string representing the {@link https://developer.mozilla.org/en-US/docs/Web/Events|event type}s to listen for.
* @param listener - The object that receives a notification (an object that implements the {@link https://developer.mozilla.org/en-US/docs/Web/API/Event|Event} interface) when an event of a specified type occurs. This must be an object implementing the {@link https://developer.mozilla.org/en-US/docs/Web/API/EventListener|EventListener} interface, or a function.
* @param options - An {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#parameters|options object} specifying characteristics about the event listener.
*
* @returns The provided listener when successfully attached; otherwise, `undefined`.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#the_event_listener_callback} The event listener callback for details on the callback itself.
*/
declare function any(target: EventTarget, types: string, listener: EventListenerOrEventListenerObject | null, options: AddEventListenerOptions): EventListenerOrEventListenerObject | null | undefined;
/**
* Attach an event listener that will be called once whenever any of the specified event types are delivered to the given node from specific descendants.
*
* @param node - The node on which the event listener is attached.
* @param selector - A selector string to filter the descendants of the given node that trigger the event.
* @param types - A case-sensitive string representing the {@link https://developer.mozilla.org/en-US/docs/Web/Events|event type}s to listen for.
* @param listener - The object that receives a notification (an object that implements the {@link https://developer.mozilla.org/en-US/docs/Web/API/Event|Event} interface) when an event of a specified type occurs. This must be an object implementing the {@link https://developer.mozilla.org/en-US/docs/Web/API/EventListener|EventListener} interface, or a function.
* @param useCapture - Whether or not events of these types will be dispatched to the registered listener before being dispatched to any target beneath it in the DOM tree.
*
* @returns The provided listener when successfully attached; otherwise, `undefined`.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#the_event_listener_callback} The event listener callback for details on the callback itself.
*/
declare function any(node: Node, selector: string, types: string, listener: EventListenerOrEventListenerObject | null, useCapture?: boolean): EventListenerOrEventListenerObject | null | undefined;
/**
* Attach an event listener that will be called once whenever any of the specified event types are delivered to the given node from specific descendants.
*
* @param node - The node on which the event listener is attached.
* @param selector - A selector string to filter the descendants of the given node that trigger the event.
* @param types - A case-sensitive string representing the {@link https://developer.mozilla.org/en-US/docs/Web/Events|event type}s to listen for.
* @param listener - The object that receives a notification (an object that implements the {@link https://developer.mozilla.org/en-US/docs/Web/API/Event|Event} interface) when an event of a specified type occurs. This must be an object implementing the {@link https://developer.mozilla.org/en-US/docs/Web/API/EventListener|EventListener} interface, or a function.
* @param options - An {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#parameters|options object} specifying characteristics about the event listener.
*
* @returns The provided listener when successfully attached; otherwise, `undefined`.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#the_event_listener_callback} The event listener callback for details on the callback itself.
*/
declare function any(node: Node, selector: string, types: string, listener: EventListenerOrEventListenerObject | null, options: AddEventListenerOptions): EventListenerOrEventListenerObject | null | undefined;
/**
* Detach all event listeners of the specified event types from the given target.
*
* @param target - The target from which the event listener is detached.
* @param types - A case-sensitive string representing the {@link https://developer.mozilla.org/en-US/docs/Web/Events|event type}s to detach.
*
* @returns `true` when successfully detached at least one listener; otherwise, `false`.
*/
declare function off(target: EventTarget, types: string): boolean;
/**
* Detach an event listener of the specified event types from the given target.
*
* @param target - The target from which the event listener is detached.
* @param types - A case-sensitive string representing the {@link https://developer.mozilla.org/en-US/docs/Web/Events|event type}s to detach.
* @param listener - The {@link https://developer.mozilla.org/en-US/docs/Web/API/EventListener|event listener} to detach from the event target.
* @param useCapture - Whether or not the EventListener to be detached is registered as a capturing listener.
*
* @returns `true` when successfully detached at least one listener; otherwise, `false`.
*/
declare function off(target: EventTarget, types: string, listener: EventListenerOrEventListenerObject | null, useCapture?: boolean): boolean;
/**
* Detach an event listener of the specified event types from the given target.
*
* @param target - The target from which the event listener is detached.
* @param types - A case-sensitive string representing the {@link https://developer.mozilla.org/en-US/docs/Web/Events|event type}s to detach.
* @param listener - The {@link https://developer.mozilla.org/en-US/docs/Web/API/EventListener|event listener} to detach from the event target.
* @param options - An {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener#parameters|options object} specifying characteristics about the event listener.
*
* @returns `true` when successfully detached at least one listener; otherwise, `false`.
*/
declare function off(target: EventTarget, types: string, listener: EventListenerOrEventListenerObject | null, options: EventListenerOptions): boolean;
/**
* Detach all event listeners of the specified event types from the given node for the specified selector.
*
* @param node - The node from which the event listener is detached.
* @param selector - A selector which should match the one used when attaching event listeners.
* @param types - A case-sensitive string representing the {@link https://developer.mozilla.org/en-US/docs/Web/Events|event type}s to detach.
*
* @returns `true` when successfully detached at least one listener; otherwise, `false`.
*/
declare function off(node: Node, selector: string, types: string): boolean;
/**
* Detach an event listener of the specified event types from the given node for the specified selector.
*
* @param node - The node from which the event listener is detached.
* @param selector - A selector which should match the one used when attaching event listeners.
* @param types - A case-sensitive string representing the {@link https://developer.mozilla.org/en-US/docs/Web/Events|event type}s to detach.
* @param listener - The {@link https://developer.mozilla.org/en-US/docs/Web/API/EventListener|event listener} to detach from the event target.
* @param useCapture - Whether or not the EventListener to be detached is registered as a capturing listener.
*
* @returns `true` when successfully detached at least one listener; otherwise, `false`.
*/
declare function off(node: Node, selector: string, types: string, listener: EventListenerOrEventListenerObject | null, useCapture?: boolean): boolean;
/**
* Detach an event listener of the specified event types from the given node for the specified selector.
*
* @param node - The node from which the event listener is detached.
* @param selector - A selector which should match the one used when attaching event listeners.
* @param types - A case-sensitive string representing the {@link https://developer.mozilla.org/en-US/docs/Web/Events|event type}s to detach.
* @param listener - The {@link https://developer.mozilla.org/en-US/docs/Web/API/EventListener|event listener} to detach from the event target.
* @param options - An {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener#parameters|options object} specifying characteristics about the event listener.
*
* @returns `true` when successfully detached at least one listener; otherwise, `false`.
*/
declare function off(node: Node, selector: string, types: string, listener: EventListenerOrEventListenerObject | null, options: EventListenerOptions): boolean;
/**
* Attach an event listener that will be called whenever a specified event type is delivered to the given target.
*
* @param target - The target on which the event listener is attached.
* @param types - A case-sensitive string representing the {@link https://developer.mozilla.org/en-US/docs/Web/Events|event type}s to listen for.
* @param listener - The object that receives a notification (an object that implements the {@link https://developer.mozilla.org/en-US/docs/Web/API/Event|Event} interface) when an event of a specified type occurs. This must be an object implementing the {@link https://developer.mozilla.org/en-US/docs/Web/API/EventListener|EventListener} interface, or a function.
* @param useCapture - Whether or not events of these types will be dispatched to the registered listener before being dispatched to any target beneath it in the DOM tree.
*
* @returns The provided listener when successfully attached; otherwise, `undefined`.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#the_event_listener_callback} The event listener callback for details on the callback itself.
*/
declare function on(target: EventTarget, types: string, listener: EventListenerOrEventListenerObject | null, useCapture?: boolean): EventListenerOrEventListenerObject | null | undefined;
/**
* Attach an event listener that will be called whenever a specified event type is delivered to the given target.
*
* @param target - The target on which the event listener is attached.
* @param types - A case-sensitive string representing the {@link https://developer.mozilla.org/en-US/docs/Web/Events|event type}s to listen for.
* @param listener - The object that receives a notification (an object that implements the {@link https://developer.mozilla.org/en-US/docs/Web/API/Event|Event} interface) when an event of a specified type occurs. This must be an object implementing the {@link https://developer.mozilla.org/en-US/docs/Web/API/EventListener|EventListener} interface, or a function.
* @param options - An {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#parameters|options object} specifying characteristics about the event listener.
*
* @returns The provided listener when successfully attached; otherwise, `undefined`.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#the_event_listener_callback} The event listener callback for details on the callback itself.
*/
declare function on(target: EventTarget, types: string, listener: EventListenerOrEventListenerObject | null, options: AddEventListenerOptions): EventListenerOrEventListenerObject | null | undefined;
/**
* Attach an event listener that will be called whenever a specified event type is delivered to the given node from specific descendants.
*
* @param node - The node on which the event listener is attached.
* @param selector - A selector string to filter the descendants of the given node that trigger the event.
* @param types - A case-sensitive string representing the {@link https://developer.mozilla.org/en-US/docs/Web/Events|event type}s to listen for.
* @param listener - The object that receives a notification (an object that implements the {@link https://developer.mozilla.org/en-US/docs/Web/API/Event|Event} interface) when an event of a specified type occurs. This must be an object implementing the {@link https://developer.mozilla.org/en-US/docs/Web/API/EventListener|EventListener} interface, or a function.
* @param useCapture - Whether or not events of these types will be dispatched to the registered listener before being dispatched to any target beneath it in the DOM tree.
*
* @returns The provided listener when successfully attached; otherwise, `undefined`.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#the_event_listener_callback} The event listener callback for details on the callback itself.
*/
declare function on(node: Node, selector: string, types: string, listener: EventListenerOrEventListenerObject | null, useCapture?: boolean): EventListenerOrEventListenerObject | null | undefined;
/**
* Attach an event listener that will be called whenever a specified event type is delivered to the given node from specific descendants.
*
* @param node - The node on which the event listener is attached.
* @param selector - A selector string to filter the descendants of the given node that trigger the event.
* @param types - A case-sensitive string representing the {@link https://developer.mozilla.org/en-US/docs/Web/Events|event type}s to listen for.
* @param listener - The object that receives a notification (an object that implements the {@link https://developer.mozilla.org/en-US/docs/Web/API/Event|Event} interface) when an event of a specified type occurs. This must be an object implementing the {@link https://developer.mozilla.org/en-US/docs/Web/API/EventListener|EventListener} interface, or a function.
* @param options - An {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#parameters|options object} specifying characteristics about the event listener.
*
* @returns The provided listener when successfully attached; otherwise, `undefined`.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#the_event_listener_callback} The event listener callback for details on the callback itself.
*/
declare function on(node: Node, selector: string, types: string, listener: EventListenerOrEventListenerObject | null, options: AddEventListenerOptions): EventListenerOrEventListenerObject | null | undefined;
/**
* Attach an event listener that will be called once whenever each of the specified event types are delivered to the given target.
*
* @param target - The target on which the event listener is attached.
* @param types - A case-sensitive string representing the {@link https://developer.mozilla.org/en-US/docs/Web/Events|event type}s to listen for.
* @param listener - The object that receives a notification (an object that implements the {@link https://developer.mozilla.org/en-US/docs/Web/API/Event|Event} interface) when an event of a specified type occurs. This must be an object implementing the {@link https://developer.mozilla.org/en-US/docs/Web/API/EventListener|EventListener} interface, or a function.
* @param useCapture - Whether or not events of these types will be dispatched to the registered listener before being dispatched to any target beneath it in the DOM tree.
*
* @returns The provided listener when successfully attached; otherwise, `undefined`.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#the_event_listener_callback} The event listener callback for details on the callback itself.
*/
declare function one(target: EventTarget, types: string, listener: EventListenerOrEventListenerObject | null, useCapture?: boolean): EventListenerOrEventListenerObject | null | undefined;
/**
* Attach an event listener that will be called once whenever each of the specified event types are delivered to the given target.
*
* @param target - The target on which the event listener is attached.
* @param types - A case-sensitive string representing the {@link https://developer.mozilla.org/en-US/docs/Web/Events|event type}s to listen for.
* @param listener - The object that receives a notification (an object that implements the {@link https://developer.mozilla.org/en-US/docs/Web/API/Event|Event} interface) when an event of a specified type occurs. This must be an object implementing the {@link https://developer.mozilla.org/en-US/docs/Web/API/EventListener|EventListener} interface, or a function.
* @param options - An {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#parameters|options object} specifying characteristics about the event listener.
*
* @returns The provided listener when successfully attached; otherwise, `undefined`.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#the_event_listener_callback} The event listener callback for details on the callback itself.
*/
declare function one(target: EventTarget, types: string, listener: EventListenerOrEventListenerObject | null, options: AddEventListenerOptions): EventListenerOrEventListenerObject | null | undefined;
/**
* Attach an event listener that will be called once whenever each of the specified event types are delivered to the given node from specific descendants.
*
* @param node - The node on which the event listener is attached.
* @param selector - A selector string to filter the descendants of the given node that trigger the event.
* @param types - A case-sensitive string representing the {@link https://developer.mozilla.org/en-US/docs/Web/Events|event type}s to listen for.
* @param listener - The object that receives a notification (an object that implements the {@link https://developer.mozilla.org/en-US/docs/Web/API/Event|Event} interface) when an event of a specified type occurs. This must be an object implementing the {@link https://developer.mozilla.org/en-US/docs/Web/API/EventListener|EventListener} interface, or a function.
* @param useCapture - Whether or not events of these types will be dispatched to the registered listener before being dispatched to any target beneath it in the DOM tree.
*
* @returns The provided listener when successfully attached; otherwise, `undefined`.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#the_event_listener_callback} The event listener callback for details on the callback itself.
*/
declare function one(node: Node, selector: string, types: string, listener: EventListenerOrEventListenerObject | null, useCapture?: boolean): EventListenerOrEventListenerObject | null | undefined;
/**
* Attach an event listener that will be called once whenever each of the specified event types are delivered to the given node from specific descendants.
*
* @param node - The node on which the event listener is attached.
* @param selector - A selector string to filter the descendants of the given node that trigger the event.
* @param types - A case-sensitive string representing the {@link https://developer.mozilla.org/en-US/docs/Web/Events|event type}s to listen for.
* @param listener - The object that receives a notification (an object that implements the {@link https://developer.mozilla.org/en-US/docs/Web/API/Event|Event} interface) when an event of a specified type occurs. This must be an object implementing the {@link https://developer.mozilla.org/en-US/docs/Web/API/EventListener|EventListener} interface, or a function.
* @param options - An {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#parameters|options object} specifying characteristics about the event listener.
*
* @returns The provided listener when successfully attached; otherwise, `undefined`.
*
* @see {@link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#the_event_listener_callback} The event listener callback for details on the callback itself.
*/
declare function one(node: Node, selector: string, types: string, listener: EventListenerOrEventListenerObject | null, options: AddEventListenerOptions): EventListenerOrEventListenerObject | null | undefined;
/**
* Executes all listeners attached to the given target for the specified event types.
*
* @param target - The target on which the specified events are executed.
* @param types - A case-sensitive string representing the {@link https://developer.mozilla.org/en-US/docs/Web/Events|event type}s to execute.
* @param options - An {@link https://developer.mozilla.org/en-US/docs/Web/API/Event/Event#values|options object} specifying characteristics about the triggered event.
*
* @returns A list of tuples, where the first value is the event type and the second is `true`; unless the event is cancelable and at least one of the event listeners which received the event called {@link https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault|`Event.preventDefault()`}, the second value is `false`.
*/
declare function trigger(target: EventTarget, types: string, options?: EventInit): Array<[
string,
boolean
]>;
export { any, off, on, one, trigger };