/** * Full resolution image fetches started before the viewer opens. * * `ImageViewer` takes the entry for the file it opens and awaits the same request, so * the image downloads once even when the click lands while the warm-up is still * downloading. * * Taking an entry hands over its `AbortController` too. The viewer then owns the * download, and closing the viewer aborts it as it aborts the viewer's own request. * Entries nobody takes are aborted when they are evicted or expire. * * Whoever takes the blob creates and revokes its own object URL. * * Entries are keyed by file, collection and watermark version. The watermark is * applied server-side, so a warm-up made before a watermark config change carries * the old watermark, and a viewer opened after the change must not take it. * * The store lives on `globalThis`, not in this module. A bundler can copy a small * module into several bundles, each with its own module state, and the warm-up and * `ImageViewer` load from different bundles. The shared key gives every copy of this * file the same store. */ /** How long an untaken warm-up is held. Covers a hover followed by a click. */ export declare const WARMED_IMAGE_TTL_MS = 30000; export type WarmedImage = { image: Promise; controller: AbortController; }; /** How a warm-up left the store. */ export type WarmUpOutcome = 'taken' | 'expired' | 'evicted' | 'replaced' | 'failed'; export type WarmUpListener = { /** Called once, when the warm-up leaves the store. `blob` is set if it had downloaded. */ onEnd?: (outcome: WarmUpOutcome, blob: Blob | undefined) => void; /** Called when the request fails for a reason other than an abort. */ onError?: (error: unknown, wasTaken: boolean) => void; }; export type WarmedImageKeyParts = { id: string; collectionName?: string; /** * The `wmv` the image request carries, from `MediaClient.getImageWatermarkVersion`. * Required, so no caller can leave it out. */ watermarkVersion: string | undefined; }; export declare const getWarmedImageKey: ({ id, collectionName, watermarkVersion, }: WarmedImageKeyParts) => string; export declare const hasWarmedImage: (key: string) => boolean; /** * Whether any warm-up is held for the file, whatever its watermark version. Lets * `ImageViewer` skip resolving the version when there is nothing it could take. */ export declare const hasWarmedImageForFile: ({ id, collectionName, }: Omit) => boolean; export declare const setWarmedImage: (key: string, { image, controller }: WarmedImage, listener?: WarmUpListener) => void; /** * Removes the warm-up for `key` and hands it over. The caller owns the request from * here, including aborting it. */ export declare const takeWarmedImage: (key: string) => WarmedImage | undefined; /** Aborts and drops every warm-up without reporting an outcome. For tests. */ export declare const clearWarmedImages: () => void;