/** * Screenshot recompression core: the encode ladder shared by the in-process * path and the image worker subprocess. * * This is the only module in the package that touches Sharp, and it reaches * Sharp through a dynamic import, so a host that must not load the native * module (Electron on Linux) never links it. Both paths run this same ladder, * so they produce identical bytes for identical jobs. * * The ladder is ported verbatim from the previous in-process implementation in * `image.ts`: PNG/JPEG(/WebP) candidates at the target size, then a quality * ladder, then a dimension ladder, while the result stays over budget. */ /** Output encodings the ladder can produce. */ export type ImageFormat = "png" | "jpeg" | "webp"; /** Encoded image bytes beside the media type they were produced as. */ export interface EncodedImage { buffer: Uint8Array; mimeType: string; } /** One recompression job; every field except the source bytes travels as the worker frame header. */ export interface EncodeJob { /** Complete source image bytes (PNG or JPEG). */ source: Uint8Array; /** Media type kept when every candidate fails and the source passes through. */ sourceMime: string; /** Width the first pass encodes at, before the dimension ladder may shrink it. */ targetWidth: number; /** Height the first pass encodes at, before the dimension ladder may shrink it. */ targetHeight: number; /** Byte budget the result should fit; the smallest candidate is kept when none fits. */ maxBytes: number; /** Quality of every first-pass candidate, and the base of the quality ladder. */ jpegQuality: number; /** Whether WebP candidates are excluded, because the caller will not accept WebP. */ excludeWebP: boolean; } /** * Whether Sharp loaded in this process. * @returns true after a successful load, false after a failed one, undefined before the first attempt. */ export declare function sharpLoadState(): boolean | undefined; /** * Recompress one image to fit its byte budget. * * The first pass encodes the target size as PNG, JPEG, and (unless excluded) * WebP and keeps the smallest; a candidate whose encode throws is skipped. When * the winner still exceeds the budget, lower JPEG qualities are tried first and * a shrunk size afterwards; only strictly smaller results are accepted, and the * cheapest candidate is returned when nothing fits. * @param job - source bytes and ladder knobs. * @returns the smallest encoding produced, or null when Sharp cannot be loaded here. */ export declare function encodeBest(job: EncodeJob): Promise;