import { Buffer as Buffer$1 } from 'node:buffer'; /** * Comparison methods available in blazediff */ type ComparisonMethod = "core-native" | "core" | "core-wasm" | "ssim" | "msssim" | "hitchhikers-ssim" | "gmsd"; /** * Status of a snapshot operation */ type SnapshotStatus = "added" | "matched" | "updated" | "failed"; /** * Image input - file path, raw PNG buffer, or buffer with dimensions */ type ImageInput = string | Buffer$1 | Uint8Array | { data: Uint8Array | Uint8ClampedArray | Buffer$1; width: number; height: number; }; /** * Options for the matcher */ interface MatcherOptions { /** Comparison method to use */ method: ComparisonMethod; /** * Failure threshold - number of pixels or percentage difference allowed * @default 0 */ failureThreshold?: number; /** * How to interpret failureThreshold * @default 'pixel' */ failureThresholdType?: "pixel" | "percent"; /** * Directory to store snapshots relative to test file * @default '__snapshots__' */ snapshotsDir?: string; /** * Custom identifier for the snapshot file * If not provided, derived from test name */ snapshotIdentifier?: string; /** * Snapshot update mode (following Vitest's logic) * - 'all': update all snapshots (vitest -u) * - 'new': create new snapshots only, don't update existing (default) * - 'none': don't create or update any snapshots * - true: same as 'all' (backwards compatibility) * - false: same as 'new' (backwards compatibility) * @default 'new' */ updateSnapshots?: boolean | "all" | "new" | "none"; /** * Custom update command to display in error messages * @default '--update' */ updateCommand?: string; /** * Color difference threshold for core/core-native methods (0-1) * Lower = more strict * @default 0.1 */ threshold?: number; /** * Enable anti-aliasing detection (core-native method) * @default false */ antialiasing?: boolean; /** * Include anti-aliased pixels in diff count (core method) * @default false */ includeAA?: boolean; /** * Window size for SSIM variants * @default 11 */ windowSize?: number; /** * k1 constant for SSIM * @default 0.01 */ k1?: number; /** * k2 constant for SSIM * @default 0.03 */ k2?: number; /** * Downsample factor for GMSD (0 or 1) * @default 0 */ downsample?: 0 | 1; /** * Run image I/O and comparison in a worker thread * Worker threads provide better performance by avoiding V8 heap contention * @default true */ runInWorker?: boolean; } /** * Result of a comparison operation */ interface ComparisonResult { /** Whether the comparison passed */ pass: boolean; /** Human-readable message describing the result */ message: string; /** Number of different pixels (for pixel-based methods) */ diffCount?: number; /** Percentage of different pixels */ diffPercentage?: number; /** Similarity score (for SSIM/GMSD - 1 = identical for SSIM, 0 = identical for GMSD) */ score?: number; /** Path to baseline snapshot */ baselinePath?: string; /** Path to received image (saved for debugging) */ receivedPath?: string; /** Path to diff visualization */ diffPath?: string; /** Status of the snapshot operation */ snapshotStatus?: SnapshotStatus; } /** * Context provided by test frameworks */ interface TestContext { /** Absolute path to the test file */ testPath: string; /** Name of the current test */ testName: string; } /** * Image data with dimensions */ interface ImageData { data: Uint8Array; width: number; height: number; } interface RunComparisonResult { /** Number of different pixels (for pixel-based methods) */ diffCount?: number; /** Percentage of different pixels */ diffPercentage?: number; /** Score for perceptual methods (SSIM: 1=identical, GMSD: 0=identical) */ score?: number; /** Diff visualization output buffer */ diffOutput?: Uint8Array; } /** * Validate that the comparison method supports the given input type */ declare function validateMethodSupportsInput(method: ComparisonMethod, input: ImageInput): void; /** * Run comparison using the specified method */ declare function runComparison(received: ImageInput, baseline: ImageInput, method: ComparisonMethod, options: MatcherOptions, diffOutputPath?: string): Promise; /** * Check if input is a file path */ declare function isFilePath(input: ImageInput): input is string; /** * Check if input is a raw PNG buffer (Buffer or Uint8Array without dimensions) */ declare function isRawPngBuffer(input: ImageInput): input is Buffer | Uint8Array; /** * Check if input is an image buffer with dimensions */ declare function isImageBuffer(input: ImageInput): input is { data: Uint8Array | Uint8ClampedArray | Buffer; width: number; height: number; }; /** * Type guard for ImageData */ declare function isImageData(input: ImageInput): input is ImageData; /** * Load a PNG image from file path */ declare function loadPNG(filePath: string): Promise; /** * Save image data to a PNG file */ declare function savePNG(filePath: string, data: Uint8Array | Uint8ClampedArray | Buffer, width: number, height: number): Promise; /** * Save a raw PNG buffer directly to file (no decode/encode cycle) */ declare function saveRawPNGBuffer(filePath: string, buffer: Buffer | Uint8Array): void; /** * Normalize image input to ImageData * - File path: loads the PNG * - Raw PNG buffer: decodes to get dimensions * - Buffer with dimensions: returns as-is (avoids unnecessary copy if already Uint8Array) */ declare function normalizeImageInput(input: ImageInput): Promise; /** * Check if a file exists */ declare function fileExists(filePath: string): boolean; interface FormatOptions { pass: boolean; method: ComparisonMethod; snapshotCreated: boolean; baselinePath: string; receivedPath: string; diffPath: string; diffCount?: number; diffPercentage?: number; score?: number; threshold: number; thresholdType: "pixel" | "percent"; updateCommand?: string; } declare function formatMessage(opts: FormatOptions): string; /** * Main snapshot comparison function */ declare function getOrCreateSnapshot(received: ImageInput, options: MatcherOptions, testContext: TestContext): Promise; /** * Compare two images directly without snapshot management */ declare function compareImages(received: ImageInput, baseline: ImageInput, options: MatcherOptions): Promise; declare function terminateWorker(): Promise; export { type ComparisonMethod, type ComparisonResult, type FormatOptions, type ImageData, type ImageInput, type MatcherOptions, type TestContext, compareImages, fileExists, formatMessage as formatReport, getOrCreateSnapshot, isFilePath, isImageBuffer, isImageData, isRawPngBuffer, loadPNG, normalizeImageInput, runComparison, savePNG, saveRawPNGBuffer, terminateWorker, validateMethodSupportsInput };