/** * @fileoverview Generic file loader for external resources. * Uses the native `fetch` API by default, but accepts any implementation * that follows the same contract: `(input, init) => Promise`. */ import TinyMediaLoader from '../TinyMediaLoader.mjs'; export type FetchResponseType = 'blob' | 'arraybuffer' | 'text' | 'json'; export type FetchLoaderOptions = { /** * - The file URL. */ src?: string; /** * - The fetch options (method, headers, body, credentials, mode, cache, redirect, referrer, referrerPolicy, integrity, keepalive). */ init?: RequestInit; /** * - A custom fetch implementation. */ fetch?: typeof fetch; /** * - The response body type (default `'blob'`). */ responseType?: FetchResponseType; /** * - Maximum time in milliseconds before the load is aborted. */ timeout?: number; /** * - Whether to perform a HEAD request before downloading. */ useHeadRequest?: boolean; /** * - The request body forwarded to the transport (ignored by `GET`/`HEAD`). */ body?: BodyInit; /** * - Whether to emit progress events (default `true`). */ progressive?: boolean; /** * - Whether concurrent loads of the same source share a single download (default `true`). */ mirror?: boolean; /** * - An optional shared memory cache. */ cache?: import('../utils/TinyMediaCache.mjs').default | null; }; export type TinyFetch = (input: string | URL | Request, init?: RequestInit) => Promise; /** * The response body types supported by the loader. * @typedef {'blob'|'arraybuffer'|'text'|'json'} FetchResponseType */ /** * Describes the configuration accepted by the {@link TinyFetchLoader} constructor. * @typedef {Object} FetchLoaderOptions * @property {string} [src] - The file URL. * @property {RequestInit} [init] - The fetch options (method, headers, body, credentials, mode, cache, redirect, referrer, referrerPolicy, integrity, keepalive). * @property {typeof fetch} [fetch] - A custom fetch implementation. * @property {FetchResponseType} [responseType] - The response body type (default `'blob'`). * @property {number} [timeout] - Maximum time in milliseconds before the load is aborted. * @property {boolean} [useHeadRequest] - Whether to perform a HEAD request before downloading. * @property {BodyInit} [body] - The request body forwarded to the transport (ignored by `GET`/`HEAD`). * @property {boolean} [progressive] - Whether to emit progress events (default `true`). * @property {boolean} [mirror] - Whether concurrent loads of the same source share a single download (default `true`). * @property {import('../utils/TinyMediaCache.mjs').default|null} [cache] - An optional shared memory cache. */ /** * The signature of the function returned by {@link TinyFetchLoader#exportFetch}. * @typedef {(input: string|URL|Request, init?: RequestInit) => Promise} TinyFetch */ /** * Loads an arbitrary file through the native `fetch` API. * * The class does not create a DOM element. It reuses the state machine, * progress tracker, cache and mirror registry of {@link TinyMediaLoader}, * and exposes the downloaded payload through {@link TinyFetchLoader#blob} * and {@link TinyFetchLoader#data}. * @extends {TinyMediaLoader} */ declare class TinyFetchLoader extends TinyMediaLoader { #private; /** * @param {FetchLoaderOptions} [options] - The loader configuration. * @throws {TypeError} If `fetch` is not a function. * @throws {TypeError} If `init` is not a plain object. * @throws {RangeError} If `responseType` is not supported. */ constructor(options?: FetchLoaderOptions); /** * The downloaded file, or null before the load finishes. * @returns {Blob|null} The raw payload. */ get blob(): Blob | null; /** * The parsed payload, in the format requested by `responseType`. * @returns {Blob|ArrayBuffer|string|unknown|null} The parsed payload. */ get data(): Blob | ArrayBuffer | string | unknown | null; /** * The response body type requested at construction time. * @returns {FetchResponseType} The response body type. */ get responseType(): FetchResponseType; /** * The fetch options forwarded to the transport. * @returns {RequestInit} A defensive copy of the fetch options. */ get init(): RequestInit; /** * Creates a new loader with the same configuration. * * The clone is fully independent: it has its own state machine, its own * abort controller and its own `blob`/`data` slots. The shared `cache` and * the custom `fetch` implementation are reused by reference, which is what * makes {@link TinyFetchLoader#exportFetch} cheap. * @param {FetchLoaderOptions} [overrides] - Values that override the cloned configuration. * @returns {TinyFetchLoader} A new, independent loader. * @throws {TypeError} If `overrides` is not a plain object. */ clone(overrides?: FetchLoaderOptions): TinyFetchLoader; /** * Returns a `fetch`-compatible function backed by this loader. * @returns {TinyFetch} A function with the same signature as `fetch`. */ exportFetch(): TinyFetch; /** * Downloads the file, consulting the shared cache first. * @protected * @returns {Promise} Resolves once the payload is ready. */ protected _startLoad(): Promise; /** * Builds the metadata descriptor for the loaded file. * @protected * @returns {import('../TinyMediaLoader.mjs').MediaMetadataDetails} The file metadata. */ protected _getMetadataDetails(): import('../TinyMediaLoader.mjs').MediaMetadataDetails; /** * `TinyFetchLoader` does not render anything, so this method always throws. * @protected * @returns {never} This method never returns. * @throws {Error} Always. */ protected _createElement(): never; } export default TinyFetchLoader; //# sourceMappingURL=TinyFetchLoader.d.mts.map