@wordpress/upload-media
Version:
Core media upload logic.
75 lines • 3.04 kB
TypeScript
/**
* Internal dependencies
*/
import type { ImageDimensions } from './get-image-dimensions';
/**
* Result of client-side media processing support detection.
*/
export interface FeatureDetectionResult {
/**
* Whether client-side media processing is supported.
*/
supported: boolean;
/**
* Reason why client-side media processing is not supported (if applicable).
*/
reason?: string;
}
/**
* Detects whether the browser supports client-side media processing.
*
* Checks (in order of evaluation):
* 1. WebAssembly support (required for wasm-vips).
* 2. SharedArrayBuffer support (required for WASM threading; relies on
* cross-origin isolation headers being set).
* 3. Web Worker support (baseline requirement for the processing worker).
* 4. Device memory: disables on devices reporting ≤ 2 GB of RAM.
* 5. Hardware concurrency: disables on devices reporting fewer than 2 CPU cores.
* 6. Network conditions: disables when the data saver flag is on, or when the
* connection's effective type is `slow-2g` or `2g`.
* 7. CSP compatibility for blob URL workers: a probe Worker is created from a
* blob: URL to confirm the site's Content Security Policy permits inline
* worker creation (`worker-src` must allow `blob:`).
*
* Results are cached after the first call. Use `clearFeatureDetectionCache()` to reset.
*
* @return Feature detection result with supported status and reason if not supported.
*/
export declare function detectClientSideMediaSupport(): FeatureDetectionResult;
/**
* Returns whether client-side media processing is supported.
*
* This is a convenience function that returns just the boolean result.
*
* @return Whether client-side media processing is supported.
*/
export declare function isClientSideMediaSupported(): boolean;
/**
* Detects whether the browser can decode HEIC images via canvas APIs.
*
* This checks for createImageBitmap and OffscreenCanvas support,
* which are sufficient to convert HEIC to JPEG without VIPS/WASM.
* Safari supports both APIs and can natively decode HEIC via
* createImageBitmap(), leveraging macOS platform codecs.
*
* @return Whether HEIC canvas-based processing is supported.
*/
export declare function isHeicCanvasSupported(): boolean;
/**
* Clears the cached feature detection result.
*
* This is primarily useful for testing purposes.
*/
export declare function clearFeatureDetectionCache(): void;
/**
* Determines whether an image is too large to process client-side.
*
* Very large images, especially interlaced/progressive ones, can exceed the
* 1 GiB wasm-vips memory cap and fail to process. Such images are better
* handled by the server, which has no comparable per-image memory ceiling.
*
* @param dimensions The image's parsed dimensions and interlacing.
* @return Whether the image's estimated memory use exceeds the client budget.
*/
export declare function exceedsClientProcessingMemory(dimensions: ImageDimensions): boolean;
//# sourceMappingURL=feature-detection.d.ts.map