import { type Raster, type StepClock } from '@variance-authority/core/format'; import { type CompareOptions, type DiffPolicy, type RasterComparison } from '@variance-authority/raster'; import { type DecodedImage } from './mask.js'; /** * Comparison — phase three: two images become a mask. * * A mask, not a number and not a picture. The number is what makes a pixel differ * unactionable ("5482 pixels changed" cannot be assigned to anyone) and the * picture is what makes it expensive (someone has to look). Both are derivable * from a mask; neither can produce one. So this phase stops at the last artifact * that still has *positions* in it, and the phases that turn positions into * places and places into files come after. * * `pixelmatch` does the per-pixel work. It is the differ behind most of the * ecosystem — Playwright's `toHaveScreenshot`, jest-image-snapshot — so its * metric is the one every pixel tool's numbers are in. Its default threshold is * not this project's: {@link DEFAULT_POLICY} says why. The pixel arm a * comparison against those tools runs keeps their defaults, in * `examples/todomvc/src/pixel/diff.ts`. */ /** * One decoded image: raw 8-bit RGBA, row-major, no padding. * * Declared in [`mask.ts`](./mask.js), which is the half of this package a caller * can reach without a codec, and re-exported here because this is where the * decoder seam is. */ export type { DecodedImage }; /** * How PNG bytes become pixels, so that *which* decoder is a deployment choice. * * Measured, because the difference is larger than it looks and not where it was * expected (journal 0016). Decoding is **90% of a comparison** — `pixelmatch` * itself is 9% — so this interface is where a run's raster cost actually lives. * On 1280×800: `pngjs` 22.6 ms, `sharp` 15.0 ms, and `sharp` again at **1.9 ms** * when several decode at once, because libvips runs on libuv's threadpool and * leaves the event loop free. Two wasm decoders were tried and both were * *slower* than the pure-JS one. * * Async for exactly that reason. A synchronous seam would forbid the threadpool, * which is where the order of magnitude is — not in the per-image constant. * * The default stays `pngjs` and this package keeps requiring nothing native, so * `observe` remains installable anywhere JavaScript runs. `sharp` is a native * addon that a Worker cannot load, which under ADR-0013 makes it a different * package's requirement rather than a conditional import here. */ export interface PngDecoder { decode(bytes: Buffer): Promise; } /** The portable default: no native addon, no wasm, works wherever Node does. */ export declare const pngjsDecoder: PngDecoder; /** * Compare two stored rasters, decoding both **concurrently**. * * The concurrency is the point rather than a tidy-up. Under a threadpool decoder * the two images decode on different threads and a pair costs about what one * image costs; under `pngjs` the second `await` resolves on the microtask queue * and it degrades to the sequential behaviour this always had. */ export declare function compareRasters(before: Raster, after: Raster, options?: CompareOptions & { readonly decoder?: PngDecoder; /** Takes `decode`, both images at once, and `compare`, the pixels. */ readonly steps?: StepClock; }): Promise; export declare function comparePngs(before: Buffer, after: Buffer, options?: CompareOptions): RasterComparison; /** * The comparison itself, over pixels somebody else decoded. * * Split out so that swapping the decoder cannot change a verdict: every path * above reaches this same function with the same RGBA, and the only thing a * decoder is trusted to do is produce those bytes. * `packages/png-sharp/src/decoder.test.ts` holds the decoders to exactly that, * one package over: the parity suite lives with the second decoder, because * that is the package that adds one. */ export declare function comparePixels(left: DecodedImage, right: DecodedImage, options?: CompareOptions): RasterComparison; export declare function decode(base64: string): Buffer; /** A visual diff, for the human who wants one after reading the report. */ export declare function diffImage(before: Buffer, after: Buffer, policy?: DiffPolicy): Buffer; //# sourceMappingURL=compare.d.ts.map