UNPKG

tiny-essentials

Version:

Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.

100 lines 3.21 kB
export default TinyDomReadyManager; /** * A basic function that performs a task when the system is ready. * Used for handlers in the readiness queue. */ export type Fn = () => void; /** * A function that determines whether a specific handler should be executed. * Should return `true` to allow execution, or `false` to skip the handler. */ export type FnFilter = () => boolean; export type Handler = { /** * - Function to execute when ready. */ fn: Fn; /** * - Whether to execute only once. */ once: boolean; /** * - Execution order (higher priority runs first). */ priority: number; /** * - Optional filter function to determine execution. */ filter: FnFilter | null; /** * - Whether to run as soon as DOM is ready (before full readiness). */ domOnly: boolean; }; /** * A basic function that performs a task when the system is ready. * Used for handlers in the readiness queue. * * @typedef {() => void} Fn */ /** * A function that determines whether a specific handler should be executed. * Should return `true` to allow execution, or `false` to skip the handler. * * @typedef {() => boolean} FnFilter */ /** * @typedef {Object} Handler * @property {Fn} fn - Function to execute when ready. * @property {boolean} once - Whether to execute only once. * @property {number} priority - Execution order (higher priority runs first). * @property {FnFilter|null} filter - Optional filter function to determine execution. * @property {boolean} domOnly - Whether to run as soon as DOM is ready (before full readiness). */ declare class TinyDomReadyManager { /** * Marks the system as DOM-ready and runs DOM-only handlers. * @private */ private _markDomReady; /** * Initializes the manager using `DOMContentLoaded`. */ init(): void; /** * Adds a Promise to delay full readiness. * @param {Promise<any>} promise * @throws {TypeError} */ addPromise(promise: Promise<any>): void; /** * Registers a handler to run either after DOM is ready or after full readiness. * * @param {Fn} fn - Function to execute. * @param {Object} [options] * @param {boolean} [options.once=true] - Execute only once. * @param {number} [options.priority=0] - Higher priority runs first. * @param {FnFilter|null} [options.filter=null] - Optional filter function. * @param {boolean} [options.domOnly=false] - If true, executes after DOM ready only. * @throws {TypeError} If fn is not a function. */ onReady(fn: Fn, { once, priority, filter, domOnly }?: { once?: boolean | undefined; priority?: number | undefined; filter?: FnFilter | null | undefined; domOnly?: boolean | undefined; }): void; /** * Returns whether the system is fully ready (DOM + Promises). * @returns {boolean} */ isReady(): boolean; /** * Returns whether the DOM is ready (DOMContentLoaded has fired). * Does not wait for promises. * @returns {boolean} */ isDomReady(): boolean; #private; } //# sourceMappingURL=TinyDomReadyManager.d.mts.map