watch-selector
Version:
Runs a function when a selector is added to dom
335 lines • 13.8 kB
TypeScript
/**
* Explicit Un-overloaded DOM Functions
*
* This module provides explicit, un-overloaded versions of all DOM manipulation
* functions for maximum flexibility and clarity. Each function has a clear,
* single purpose with no ambiguity in its signature.
*
* Naming conventions:
* - *Direct - Direct element manipulation
* - *Selector - CSS selector-based manipulation
* - *Generator - Returns ElementFn for generator use
* - *Get* - Getter variants
* - *Set* - Setter variants (when needed for clarity)
*/
import type { ElementFn } from "../types";
/**
* Sets text content directly on an element.
*/
export declare function textDirect(element: HTMLElement, content: string): void;
/**
* Sets text content on elements matching a selector.
*/
export declare function textSelector(selector: string, content: string): void;
/**
* Returns an ElementFn that sets text content (for generator use).
*/
export declare function textGenerator<El extends HTMLElement = HTMLElement>(content: string): ElementFn<El>;
/**
* Gets text content directly from an element.
*/
export declare function textGetDirect(element: HTMLElement): string;
/**
* Gets text content from the first element matching a selector.
*/
export declare function textGetSelector(selector: string): string | null;
/**
* Returns an ElementFn that gets text content (for generator use).
*/
export declare function textGetGenerator<El extends HTMLElement = HTMLElement>(): ElementFn<El, string>;
/**
* Sets HTML content directly on an element.
*/
export declare function htmlDirect(element: HTMLElement, content: string): void;
/**
* Sets HTML content on elements matching a selector.
*/
export declare function htmlSelector(selector: string, content: string): void;
/**
* Returns an ElementFn that sets HTML content (for generator use).
*/
export declare function htmlGenerator<El extends HTMLElement = HTMLElement>(content: string): ElementFn<El>;
/**
* Gets HTML content directly from an element.
*/
export declare function htmlGetDirect(element: HTMLElement): string;
/**
* Gets HTML content from the first element matching a selector.
*/
export declare function htmlGetSelector(selector: string): string | null;
/**
* Returns an ElementFn that gets HTML content (for generator use).
*/
export declare function htmlGetGenerator<El extends HTMLElement = HTMLElement>(): ElementFn<El, string>;
/**
* Sets sanitized HTML content on an element (direct element version).
* Removes dangerous elements and attributes to prevent XSS attacks.
*/
export declare function safeHtmlDirect(element: HTMLElement, content: string): void;
/**
* Sets sanitized HTML content on elements matching a CSS selector.
* Removes dangerous elements and attributes to prevent XSS attacks.
*/
export declare function safeHtmlSelector(selector: string, content: string): void;
/**
* Returns an ElementFn that sets sanitized HTML content (generator version).
* Removes dangerous elements and attributes to prevent XSS attacks.
*/
export declare function safeHtmlGenerator<El extends HTMLElement = HTMLElement>(content: string): ElementFn<El>;
/**
* Adds classes directly to an element.
*/
export declare function addClassDirect(element: HTMLElement, ...classNames: string[]): void;
/**
* Adds classes to elements matching a selector.
*/
export declare function addClassSelector(selector: string, ...classNames: string[]): void;
/**
* Returns an ElementFn that adds classes (for generator use).
*/
export declare function addClassGenerator<El extends HTMLElement = HTMLElement>(...classNames: string[]): ElementFn<El>;
/**
* Removes classes directly from an element.
*/
export declare function removeClassDirect(element: HTMLElement, ...classNames: string[]): void;
/**
* Removes classes from elements matching a selector.
*/
export declare function removeClassSelector(selector: string, ...classNames: string[]): void;
/**
* Returns an ElementFn that removes classes (for generator use).
*/
export declare function removeClassGenerator<El extends HTMLElement = HTMLElement>(...classNames: string[]): ElementFn<El>;
/**
* Toggles a class directly on an element.
*/
export declare function toggleClassDirect(element: HTMLElement, className: string, force?: boolean): boolean;
/**
* Toggles a class on elements matching a selector.
*/
export declare function toggleClassSelector(selector: string, className: string, force?: boolean): boolean;
/**
* Returns an ElementFn that toggles a class (for generator use).
*/
export declare function toggleClassGenerator<El extends HTMLElement = HTMLElement>(className: string, force?: boolean): ElementFn<El, boolean>;
/**
* Checks if an element has a class.
*/
export declare function hasClassDirect(element: HTMLElement, className: string): boolean;
/**
* Checks if an element matching a selector has a class.
*/
export declare function hasClassSelector(selector: string, className: string): boolean;
/**
* Returns an ElementFn that checks for a class (for generator use).
*/
export declare function hasClassGenerator<El extends HTMLElement = HTMLElement>(className: string): ElementFn<El, boolean>;
/**
* Sets a single style property directly on an element.
*/
export declare function styleSetDirect(element: HTMLElement, property: string, value: string): void;
/**
* Sets multiple style properties directly on an element.
*/
export declare function styleSetObjectDirect(element: HTMLElement, styles: Partial<CSSStyleDeclaration>): void;
/**
* Sets a style property on elements matching a selector.
*/
export declare function styleSetSelector(selector: string, property: string, value: string): void;
/**
* Sets multiple style properties on elements matching a selector.
*/
export declare function styleSetObjectSelector(selector: string, styles: Partial<CSSStyleDeclaration>): void;
/**
* Returns an ElementFn that sets a style property (for generator use).
*/
export declare function styleSetGenerator<El extends HTMLElement = HTMLElement>(property: string, value: string): ElementFn<El>;
/**
* Returns an ElementFn that sets multiple style properties (for generator use).
*/
export declare function styleSetObjectGenerator<El extends HTMLElement = HTMLElement>(styles: Partial<CSSStyleDeclaration>): ElementFn<El>;
/**
* Gets a style property value directly from an element.
*/
export declare function styleGetDirect(element: HTMLElement, property: string): string;
/**
* Gets a style property value from an element matching a selector.
*/
export declare function styleGetSelector(selector: string, property: string): string | null;
/**
* Returns an ElementFn that gets a style property (for generator use).
*/
export declare function styleGetGenerator<El extends HTMLElement = HTMLElement>(property: string): ElementFn<El, string>;
/**
* Sets an attribute directly on an element.
*/
export declare function attrSetDirect(element: HTMLElement, name: string, value: any): void;
/**
* Sets multiple attributes directly on an element.
*/
export declare function attrSetObjectDirect(element: HTMLElement, attrs: Record<string, any>): void;
/**
* Sets an attribute on elements matching a selector.
*/
export declare function attrSetSelector(selector: string, name: string, value: any): void;
/**
* Returns an ElementFn that sets an attribute (for generator use).
*/
export declare function attrSetGenerator<El extends HTMLElement = HTMLElement>(name: string, value: any): ElementFn<El>;
/**
* Gets an attribute value directly from an element.
*/
export declare function attrGetDirect(element: HTMLElement, name: string): string | null;
/**
* Gets an attribute value from an element matching a selector.
*/
export declare function attrGetSelector(selector: string, name: string): string | null;
/**
* Removes attributes directly from an element.
*/
export declare function removeAttrDirect(element: HTMLElement, ...names: string[]): void;
/**
* Removes attributes from elements matching a selector.
*/
export declare function removeAttrSelector(selector: string, ...names: string[]): void;
/**
* Returns an ElementFn that removes attributes (for generator use).
*/
export declare function removeAttrGenerator<El extends HTMLElement = HTMLElement>(...names: string[]): ElementFn<El>;
/**
* Sets the value directly on a form element.
*/
export declare function valueDirect(element: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement, value: string): void;
/**
* Sets the value on a form element matching a selector.
*/
export declare function valueSelector(selector: string, value: string): void;
/**
* Returns an ElementFn that sets the value (for generator use).
*/
export declare function valueGenerator<El extends HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement = HTMLInputElement>(value: string): ElementFn<El>;
/**
* Gets the value directly from a form element.
*/
export declare function valueGetDirect(element: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement): string;
/**
* Gets the value from a form element matching a selector.
*/
export declare function valueGetSelector(selector: string): string | null;
/**
* Sets the checked state directly on a checkbox/radio input.
*/
export declare function checkedDirect(element: HTMLInputElement, checked: boolean): void;
/**
* Sets the checked state on an input matching a selector.
*/
export declare function checkedSelector(selector: string, checked: boolean): void;
/**
* Returns an ElementFn that sets the checked state (for generator use).
*/
export declare function checkedGenerator<El extends HTMLInputElement = HTMLInputElement>(checked: boolean): ElementFn<El>;
/**
* Gets the checked state directly from an input.
*/
export declare function checkedGetDirect(element: HTMLInputElement): boolean;
/**
* Gets the checked state from an input matching a selector.
*/
export declare function checkedGetSelector(selector: string): boolean;
/**
* Focuses an element directly.
*/
export declare function focusDirect(element: HTMLElement): void;
/**
* Focuses an element matching a selector.
*/
export declare function focusSelector(selector: string): void;
/**
* Returns an ElementFn that focuses the element (for generator use).
*/
export declare function focusGenerator<El extends HTMLElement = HTMLElement>(): ElementFn<El>;
/**
* Blurs an element directly.
*/
export declare function blurDirect(element: HTMLElement): void;
/**
* Blurs an element matching a selector.
*/
export declare function blurSelector(selector: string): void;
/**
* Returns an ElementFn that blurs the element (for generator use).
*/
export declare function blurGenerator<El extends HTMLElement = HTMLElement>(): ElementFn<El>;
/**
* Shows an element directly.
*/
export declare function showDirect(element: HTMLElement): void;
/**
* Shows an element matching a selector.
*/
export declare function showSelector(selector: string): void;
/**
* Returns an ElementFn that shows the element (for generator use).
*/
export declare function showGenerator<El extends HTMLElement = HTMLElement>(): ElementFn<El>;
/**
* Hides an element directly.
*/
export declare function hideDirect(element: HTMLElement): void;
/**
* Hides an element matching a selector.
*/
export declare function hideSelector(selector: string): void;
/**
* Returns an ElementFn that hides the element (for generator use).
*/
export declare function hideGenerator<El extends HTMLElement = HTMLElement>(): ElementFn<El>;
/**
* Queries for a child element directly.
*/
export declare function queryDirect<T extends HTMLElement = HTMLElement>(element: HTMLElement, selector: string): T | null;
/**
* Queries for a descendant of an element matching a parent selector.
*/
export declare function querySelector<T extends HTMLElement = HTMLElement>(parentSelector: string, childSelector: string): T | null;
/**
* Returns an ElementFn that queries for a child (for generator use).
*/
export declare function queryGenerator<T extends HTMLElement = HTMLElement>(selector: string): ElementFn<HTMLElement, T | null>;
/**
* Queries for all matching child elements directly.
*/
export declare function queryAllDirect<T extends HTMLElement = HTMLElement>(element: HTMLElement, selector: string): T[];
/**
* Queries for all descendants of an element matching a parent selector.
*/
export declare function queryAllSelector<T extends HTMLElement = HTMLElement>(parentSelector: string, childSelector: string): T[];
/**
* Returns an ElementFn that queries for all children (for generator use).
*/
export declare function queryAllGenerator<T extends HTMLElement = HTMLElement>(selector: string): ElementFn<HTMLElement, T[]>;
/**
* Gets the parent element directly.
*/
export declare function parentDirect<T extends HTMLElement = HTMLElement>(element: HTMLElement, selector?: string): T | null;
/**
* Returns an ElementFn that gets the parent (for generator use).
*/
export declare function parentGenerator<T extends HTMLElement = HTMLElement>(selector?: string): ElementFn<HTMLElement, T | null>;
/**
* Gets child elements directly.
*/
export declare function childrenDirect<T extends HTMLElement = HTMLElement>(element: HTMLElement, selector?: string): T[];
/**
* Returns an ElementFn that gets children (for generator use).
*/
export declare function childrenGenerator<T extends HTMLElement = HTMLElement>(selector?: string): ElementFn<HTMLElement, T[]>;
/**
* Gets sibling elements directly.
*/
export declare function siblingsDirect<T extends HTMLElement = HTMLElement>(element: HTMLElement, selector?: string): T[];
/**
* Returns an ElementFn that gets siblings (for generator use).
*/
export declare function siblingsGenerator<T extends HTMLElement = HTMLElement>(selector?: string): ElementFn<HTMLElement, T[]>;
//# sourceMappingURL=dom-explicit.d.ts.map