/** * Reads the contents of a file using the specified FileReader method. * * @param {File|Blob} file - The file to be read. * @param {'readAsArrayBuffer'|'readAsDataURL'|'readAsText'|'readAsBinaryString'} method - * The FileReader method to use for reading the file. * @returns {Promise} - A promise that resolves with the file content, according to the chosen method. * @throws {TypeError} - If arguments don't match expected types. * @throws {Error} - If an unexpected error occurs while handling the result. * @throws {DOMException} - If the FileReader encounters an error while reading the file. */ export declare function readFileBlob(file: File | Blob, method: 'readAsArrayBuffer' | 'readAsDataURL' | 'readAsText' | 'readAsBinaryString'): Promise; /** * Reads a file as a Base64 string using FileReader, and optionally formats it as a full data URL. * * Performs strict validation to ensure the result is a valid Base64 string or a proper data URL. * * @param {File|Blob} file - The file to be read. * @param {boolean|string} [isDataUrl=false] - If true, returns a full data URL; if false, returns only the Base64 string; * if a string is passed, it is used as the MIME type in the data URL. * @returns {Promise} - A promise that resolves with the Base64 string or data URL. * * @throws {TypeError} - If the result is not a string or if `isDataUrl` is not a valid type. * @throws {Error} - If the result does not match the expected data URL format or Base64 structure. * @throws {DOMException} - If the FileReader fails to read the file. */ export declare function readBase64Blob(file: File | Blob, isDataUrl?: boolean | string): Promise; /** * Reads a file and strictly validates its content as proper JSON using FileReader. * * Performs several checks to ensure the file contains valid, parsable JSON data. * * @param {File|Blob} file - The file to be read. It must contain valid JSON as plain text. * @returns {Promise|any[]>} - A promise that resolves with the parsed JSON object. * * @throws {SyntaxError} - If the file content is not valid JSON syntax. * @throws {TypeError} - If the result is not a string or does not represent a JSON value. * @throws {Error} - If the result is empty or structurally invalid as JSON. * @throws {DOMException} - If the FileReader fails to read the file. */ export declare function readJsonBlob(file: File | Blob): Promise | any[]>; /** * Saves a JSON object as a downloadable file. * @param {string} filename * @param {any} data * @param {number} [spaces=2] * @throws {TypeError} - If arguments do not match expected types. */ export declare function saveJsonFile(filename: string, data: any, spaces?: number): void; export type FetchOnProgressResult = (loaded: number, total: number) => void; /** * Callback function used to report the progress of a data download. * * @callback FetchOnProgressResult * @param {number} loaded - The amount of bytes currently loaded. * @param {number} total - The total amount of bytes to be loaded (0 if unknown). * @returns {void} */ /** * Intercepts a standard Fetch API Response to track the download progress * of its body stream. * * This function returns a new Response object with a monitored ReadableStream, * allowing the provided callback to receive updates on the number of bytes loaded. * * @param {Response} response - The original response object to be tracked. * @param {FetchOnProgressResult} onProgress - The callback function to handle progress events. * @param {(res: Response) => ResponseInit} [returnResponse] - The callback function to return the ResponseInit to ReadableStream. * @returns {Response} A new Response object with the tracked stream. */ export declare function trackFetchProgress(response: Response, onProgress: FetchOnProgressResult, returnResponse?: (res: Response) => ResponseInit): Response; /** * Loads and parses a JSON from a remote URL using Fetch API. * * @param {string | URL | Request} url - The full URL to fetch JSON from. * @param {RequestInit|null} [options] - Optional settings. * @param {FetchOnProgressResult} [onProgress] - Track the load progress. * @returns {Promise>} Parsed JSON object. * @throws {Error} Throws if fetch fails, times out, or returns invalid JSON. */ export declare function fetchJson(url: string | URL | Request, options?: RequestInit | null, onProgress?: FetchOnProgressResult): Promise>; /** * Loads a remote file as a Blob using Fetch API. * * @param {string | URL | Request} url - The full URL to fetch the file from. * @param {string[]} [allowedMimeTypes] - Optional list of accepted MIME types (e.g., ['image/jpeg']). * @param {RequestInit|null} [options] - Optional fetch options. * @param {FetchOnProgressResult} [onProgress] - Track the load progress. * @returns {Promise} - The fetched file as a Blob. * @throws {Error} Throws if fetch fails, response is not ok, or MIME type is not allowed. */ export declare function fetchBlob(url: string | URL | Request, allowedMimeTypes?: string[], options?: RequestInit | null, onProgress?: FetchOnProgressResult): Promise; /** * Loads a remote file as a text using Fetch API. * @param {string | URL | Request} url - The full URL to fetch the file from. * @param {string[]} [allowedMimeTypes] - Optional list of accepted MIME types (e.g., ['image/jpeg']). * @param {RequestInit|null} [options] - Optional fetch options. * @param {FetchOnProgressResult} [onProgress] - Track the load progress. * @returns {Promise} - The fetched file as a text. * @throws {Error} Throws if fetch fails, response is not ok, or MIME type is not allowed. */ export declare function fetchText(url: string | URL | Request, allowedMimeTypes?: string[], options?: RequestInit | null, onProgress?: FetchOnProgressResult): Promise; export type ImageLoadResult = { /** * The image element instance used for loading. */ element: HTMLImageElement; /** * The browser event triggered by the final lifecycle state. */ event: Event; /** * The specific outcome string of the loading process. */ status: ImageLoadStatus; /** * Indicates if the image was successfully loaded without errors. */ isSuccess: boolean; /** * The total duration in milliseconds from start to finish. */ loadTimeMs: number; /** * An object containing the rendered and intrinsic sizes of the image. */ dimensions: { width: number; height: number; naturalWidth: number; naturalHeight: number; }; }; export type ImageLoadStatus = 'loaded' | 'aborted'; /** * Represents the final state and metadata of an attempted image load. * @typedef {Object} ImageLoadResult * @property {HTMLImageElement} element The image element instance used for loading. * @property {Event} event The browser event triggered by the final lifecycle state. * @property {ImageLoadStatus} status The specific outcome string of the loading process. * @property {boolean} isSuccess Indicates if the image was successfully loaded without errors. * @property {number} loadTimeMs The total duration in milliseconds from start to finish. * @property {Object} dimensions An object containing the rendered and intrinsic sizes of the image. * @property {number} dimensions.width The current layout width of the image element. * @property {number} dimensions.height The current layout height of the image element. * @property {number} dimensions.naturalWidth The intrinsic width of the image source in pixels. * @property {number} dimensions.naturalHeight The intrinsic height of the image source in pixels. */ /** * Describes the possible resolution states for the image loading attempt. * @typedef {'loaded'|'aborted'} ImageLoadStatus */ /** * Loads an image asynchronously, capturing critical lifecycle events. * It normalizes errors and success states into a consistent result structure. * * @param {Object} options * @param {string} options.url * @param {string} [options.crossOrigin="anonymous"] * @param {(event: Event, startTime: number) => void} [options.onLoading] * @returns {Promise} */ export declare function loadImage(options: { url: string; crossOrigin?: string; onLoading?: (event: Event, startTime: number) => void; }): Promise; /** * Installs a script that toggles CSS classes on a given element * based on the page's visibility or focus state, and optionally * triggers callbacks on visibility changes. * * @param {Object} [settings={}] * @param {Element} [settings.element=document.body] - The element to receive visibility classes. * @param {string} [settings.hiddenClass='windowHidden'] - CSS class applied when the page is hidden. * @param {string} [settings.visibleClass='windowVisible'] - CSS class applied when the page is visible. * @param {(data: { type: string; oldType: string; oldClass: string; }) => void} [settings.onVisible] - Callback called when page becomes visible. * @param {(data: { type: string; oldType: string; oldClass: string; }) => void} [settings.onHidden] - Callback called when page becomes hidden. * @returns {() => void} Function that removes all installed event listeners. * @throws {TypeError} If any provided setting is invalid. */ export declare function installWindowHiddenScript(settings?: { element?: Element; hiddenClass?: string; visibleClass?: string; onVisible?: (data: { type: string; oldType: string; oldClass: string; }) => void; onHidden?: (data: { type: string; oldType: string; oldClass: string; }) => void; }): () => void; //# sourceMappingURL=html.d.mts.map