/** A normalized merge input format (what a resolved source carries). */ export type InputFormat = 'pdf' | 'txt' | 'png' | 'jpg'; /** A format a caller may specify on an input's `format` field. `'jpeg'` is * accepted as an alias and normalized to `'jpg'` internally. */ export type AcceptedInputFormat = InputFormat | 'jpeg'; /** Normalize a caller-supplied format string, accepting the `jpeg` alias. * Returns `undefined` for anything unrecognized. */ export declare function normalizeInputFormat(format: string): InputFormat | undefined; /** Detect PDF / PNG / JPEG from the leading magic bytes. Plain text has no * reliable signature, so it returns `undefined` and must be signalled * explicitly via a `format` field. */ export declare function detectFormatFromBytes(bytes: Uint8Array): InputFormat | undefined; /** Detect a supported format from a filename / path extension. */ export declare function detectFormatFromPath(pathOrName: string): InputFormat | undefined; /** Default cap on an image's declared pixel count (width × height): 100 * megapixels. See `MergeOptions.maxImagePixels`. */ export declare const DEFAULT_MAX_IMAGE_PIXELS = 100000000; /** * Structural facts about a PNG, read without decoding any pixel data: the * IHDR header fields plus the compressed image data (IDAT) chunks. */ export interface PngInfo { width: number; height: number; bitDepth: number; colorType: number; interlaced: boolean; /** The IDAT chunk payloads, in order (views into the input, not copies). */ idat: Uint8Array[]; /** * For an animated PNG (APNG), its single frame: the rectangle pdf-lib * decodes, and the frame's own compressed data (the fdAT payloads, after * their sequence numbers) when it does not reuse the IDAT image. */ frame?: { width: number; height: number; fdat?: Uint8Array[]; }; } /** * Validate a PNG's chunk structure and read its header, without decoding any * pixel data. Returns a description of the problem instead of throwing, so * the caller can raise its own typed error. * * The rules mirror how pdf-lib's decoder walks the file, closing the gaps it * leaves open. That decoder accepts an IHDR anywhere (and uses the last one) * and decodes every animation frame at whatever size the frame declares, so * a size check that only reads the usual header position can be bypassed; * and it loops forever on a chunk cut off by the end of the file or on a text * chunk missing its separators. Here: IHDR must come first and appear once, * every chunk the decoder reads must fit inside the file, and tEXt/iTXt * chunks must contain their NUL separators. Like the decoder (and browsers), * it stops at IEND or the end of the file, ignores trailing bytes that are * not a chunk it would read, and does not check CRCs. * * Animated PNGs are handled as pdf-lib handles them, so its results do not * change: one with more than one frame is rejected (pdf-lib refuses those, * but only after decoding every frame), and a single-frame one is accepted * if its frame lies within the image, which keeps its decoding cost within * `maxImagePixels`. The frame's own data is returned for `checkPngImageData`. */ export declare function inspectPng(bytes: Uint8Array): PngInfo | string; /** The exact size of a PNG's decompressed image data: one filter byte plus * the packed samples per scanline, summed over the seven Adam7 passes when * the image is interlaced. */ export declare function pngExpectedDataLength(info: Omit): number; /** * Check that a PNG's compressed image data is a complete deflate stream that * decompresses to exactly the size its header declares, and likewise for the * frame data of a single-frame animated PNG. Returns a description of the * problem, or `undefined` when the data is safe to decode. * * pdf-lib's decoder never terminates on a stream that has no final block, so * this must pass before the image is handed to it. Like that decoder, it * skips the 2-byte zlib header and ignores the trailing checksum. A stream * that ends cleanly but short is rejected too: pdf-lib would pad the missing * rows silently, turning a corrupt image into a partly blank page. Output is * counted and discarded chunk by chunk, so memory stays small; the work is * bounded because decompression stops once it exceeds the declared size, * which is already capped by `maxImagePixels`. */ export declare function checkPngImageData(info: PngInfo): string | undefined; /** * Read a JPEG's declared dimensions from its first SOF (start-of-frame) marker * without decoding any pixel data. Walks the marker segments from SOI and * returns `undefined` if no frame header appears before the scan data or the * end of the file (the embedder will then raise its own error). */ export declare function readJpegDimensions(bytes: Uint8Array): { width: number; height: number; } | undefined;