import type { FreezeDryConfig, ProcessSubresourceRecurse } from './types'; import type { SubresourceLink } from './resource'; import { Resource, DomCloneResource } from './resource'; /** * Freeze-dry an HTML Document. * * Technically, this function is a convenience wrapper that instantiates and runs a {@link * FreezeDryer} instance. Use that class instead if you need more control; for example to access the * incomplete result before `freezeDry` finishes, or to obtain it as a `Document` or `Blob` rather * than a string. * * @example * Simplest use case: * ``` * const html = await freezeDry() * ``` * * With options: * * ``` * const html = await freezeDry(document, { timeout: 5000 }) * ``` * * @param document - Document to be freeze-dried. Remains unmodified. Defaults to `window.document`. * @param options - Options to customise freezeDry’s behaviour. See {@link FreezeDryConfig}. * @returns The freeze-dried document as a self-contained, static HTML string. * * @category Main */ export declare function freezeDry(document?: Document, options?: Partial): Promise; /** * Freeze-dries an HTML Document. * * For most use cases, use the {@link freezeDry} function, a convenience wrapper around this class. * * Use this class instead if you need more control; for example to access the incomplete result * before `freezeDry` finishes, or to obtain it as a `Document` or `Blob` rather than a string. * * @example * This is roughly what running `freezeDry(document, options)` does: * * ``` * const freezeDryer = new FreezeDryer(document, options) * await freezeDryier.run() * const html = freezeDryer.result.string * ``` * * @category Main */ export declare class FreezeDryer implements AbortController { /** * The `Document` that was passed to this `FreezeDryer` to be freeze-dried. */ readonly original: Document; /** * The clone of the original document. After completing {@link run}, this is the freeze-dried * result. It can also be accessed before or while `run`ning, to already obtain a partial * result if needed. */ readonly result: DomCloneResource; /** * The configuration of this `FreezeDryer` (based on the passed `options`). */ readonly config: FreezeDryConfig; private abortController; /** * @param document - Document to be freeze-dried. Remains unmodified. * @param options - Options to customise freezeDry’s behaviour. */ constructor(document: Document, options?: Partial); /** * Run the freeze-drying process. * * Starts the process of recursively crawling and drying subresources of {@link result}, then * finalises the snapshot itself. * * @returns The FreezeDryer itself. */ run(): Promise; /** Capture the DOM in its current state. (Step 1) */ protected captureDom(original: Document): DomCloneResource; /** Recurse into subresources, converting them as needed. (Step 2) */ protected crawlSubresources(): Promise; /** * Default method for processing subresources (can be overruled in `options`). * * Fetches the subresource, recurses into each of its (sub)subresources, then applies {@link * dryResource} and {@link newUrlForResource} on it. */ protected processSubresource(link: SubresourceLink, recurse: ProcessSubresourceRecurse): Promise; /** * Default method for choosing a new URL for a subresource (can be overruled in `options`). * * @returns the complete resource content encoded as a data URL (`data:mime/type;base64;………`). */ protected newUrlForResource(resource: Resource): Promise; /** * Default method for ‘drying’ a (sub)resource (can be overruled in `options`). * * Makes the resource static and context-free. (Step 3, and subresource step 3) * @param resource - The resource to be ‘dried’. * @param isRootDocument - Whether `resource` is the top-level document (rather than a subresource). */ protected dryResource(resource: Resource, isRootDocument: boolean): void; /** Finalise snapshot. (Step 4) */ protected finaliseSnapshot(): void; protected applyDefaultConfig(doc: Document, options: Partial): FreezeDryConfig; private initAbortController; /** * Abort freeze-drying. Stops further crawling of subresources, but still finishes the snapshot * using the currently available subresources. */ abort(reason?: any): Promise; /** * Signals whether freeze-drying has been aborted. * * Aborting can happen in several ways: * - This `FreezeDryer`’s {@link abort} method was called. * - The `timeout` given in `options` has been reached. * - The `signal` given in `options` was triggered. */ get signal(): AbortSignal; }