visual-regression-compare 0.0.0 → 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,94 @@
1
+ import { ManifestWriter, type Manifest, type ManifestEntry, type ManifestHeaderInput } from 'visual-regression-manifest';
2
+ import type { CompareInput, CompareResult, DiffEngine, EngineOptions, ImagePart, Layout, Limits, Matcher, OnMissingBaseline, Plugin, Reporter, SizeMismatch, Store, UpdatePolicy } from './types';
3
+ export declare const TOOL_NAME = "visual-regression-compare";
4
+ export type ComparerOptions = {
5
+ /**
6
+ * A built-in engine name, a module id (`./my-engine.mjs`, a package) or an
7
+ * engine object. Names and ids run in worker threads; an object runs in the
8
+ * main thread. Default `pixelmatch`.
9
+ */
10
+ engine?: string | DiffEngine;
11
+ /** Passed to the engine factory; must be structured-cloneable. */
12
+ engineOptions?: EngineOptions;
13
+ limits?: Limits;
14
+ /** What a screenshot without a baseline becomes: `missing-baseline` (`fail`) or a created baseline. Default `fail`. */
15
+ onMissingBaseline?: OnMissingBaseline;
16
+ /** Default `fail`: no padding, the size change itself is the result. */
17
+ onSizeMismatch?: SizeMismatch;
18
+ /** Overwrite baselines: never (default), when the comparison failed, or whenever the pixels differ. */
19
+ update?: UpdatePolicy;
20
+ store: Store;
21
+ layout?: Layout;
22
+ matcher?: Matcher;
23
+ manifest: {
24
+ /**
25
+ * A manifest writer the caller owns, for a runner that builds the header
26
+ * (CI, run and reproduction metadata, one file per worker) itself. The
27
+ * other keys of this object are then ignored.
28
+ */
29
+ writer?: ManifestWriter;
30
+ /** Where the manifest is written; default `visual-regression-manifest.compare.json` in the project root. */
31
+ path?: string;
32
+ /** Absolute path every manifest path is relative to; default the working directory. */
33
+ projectRoot?: string;
34
+ tool?: ManifestHeaderInput['tool'];
35
+ runner?: ManifestHeaderInput['runner'];
36
+ /** Metadata recorded on every entry that does not state its own. */
37
+ platform?: CompareInput['platform'];
38
+ variant?: string;
39
+ };
40
+ plugins?: Plugin[];
41
+ reporters?: Reporter[];
42
+ /**
43
+ * Worker threads for decoding and comparing, and parallel reads in
44
+ * `compareAll`. Default `1`: everything runs in the calling thread, which is
45
+ * what a runner adapter wants (its own workers already use the CPUs). The
46
+ * command line passes the CPU count.
47
+ */
48
+ concurrency?: number;
49
+ /** The built worker module; found next to this file in the published package. */
50
+ workerFile?: URL | string;
51
+ };
52
+ export declare class Comparer {
53
+ private readonly options;
54
+ readonly writer: ManifestWriter;
55
+ private readonly projectRoot;
56
+ private readonly store;
57
+ private readonly layout;
58
+ private readonly matcher;
59
+ private readonly pool;
60
+ private readonly registry;
61
+ private readonly ready;
62
+ private readonly engines;
63
+ private closed;
64
+ constructor(options: ComparerOptions);
65
+ private createWriter;
66
+ /** The comparer's settings with the overrides of one call applied. */
67
+ private settings;
68
+ /** The engine as the main thread knows it: for its name and metric, and to run it when it is an object or came from a plugin. */
69
+ private resolveEngine;
70
+ private measure;
71
+ /** Compares one screenshot, decides, writes the files and records the manifest entry. */
72
+ compareImage(input: CompareInput): Promise<ManifestEntry>;
73
+ /**
74
+ * `compareImage` that can also hand back the compared images as PNG bytes,
75
+ * for a runner that shows them (a review UI). `include` names the parts;
76
+ * the diff is encoded anyway, the other two cost nothing when the sizes
77
+ * match.
78
+ */
79
+ compare(input: CompareInput, { include }?: {
80
+ include?: ImagePart[];
81
+ }): Promise<CompareResult>;
82
+ private compareAt;
83
+ private compareWith;
84
+ /** `maxDiffRatio` of the entry: the stricter of the ratio and the pixel count, for the size actually compared. */
85
+ private limitFor;
86
+ private decide;
87
+ private record;
88
+ /** Compares every incoming image of the store against its baseline. */
89
+ compareAll(): Promise<Manifest>;
90
+ private compareIncoming;
91
+ /** Flushes the manifest and ends the reporters. Call once, after the last comparison. */
92
+ close(): Promise<Manifest>;
93
+ }
94
+ export declare const createComparer: (options: ComparerOptions) => Comparer;
@@ -0,0 +1,5 @@
1
+ import type { ConfigFile } from './options';
2
+ /** The config file named by `--config`, else the first `visual-regression.config.*` in `cwd`; `{}` when there is none. */
3
+ export declare const loadConfig: (explicit: string | undefined, cwd?: string) => Promise<ConfigFile>;
4
+ /** `--config <file>` from raw arguments, so the file can be read before the rest is parsed. */
5
+ export declare const configArg: (argv: string[]) => string | undefined;
@@ -0,0 +1,9 @@
1
+ import type { DiffEngine, EngineOptions } from '../types';
2
+ export { pixelmatchEngine, type PixelmatchOptions } from './pixelmatch';
3
+ export declare const BUILT_IN_ENGINES: string[];
4
+ /**
5
+ * Turns an engine id into an engine: a built-in name, a path to a module
6
+ * (`./my-engine.mjs`, resolved from `cwd`) or a package name. The module's
7
+ * default export is an engine or a function making one from the options.
8
+ */
9
+ export declare const loadEngine: (id: string, options?: EngineOptions, cwd?: string) => Promise<DiffEngine>;
@@ -0,0 +1,9 @@
1
+ import type { DiffEngine, EngineOptions } from '../types';
2
+ export type PixelmatchOptions = {
3
+ /** Per-pixel color tolerance, 0..1 (YIQ distance). Default `0.1`. */
4
+ threshold?: number;
5
+ /** Count anti-aliased pixels as differences. Default `false`. */
6
+ includeAA?: boolean;
7
+ };
8
+ export declare const pixelmatchEngine: ({ threshold, includeAA, }?: PixelmatchOptions) => DiffEngine;
9
+ export declare const pixelmatchFrom: (options: EngineOptions) => DiffEngine;
@@ -0,0 +1,8 @@
1
+ import type { RgbaImage } from './types';
2
+ /** Decodes a PNG. A Git LFS pointer file, which a checkout without `git lfs pull` leaves in place of an image, gets its own message. */
3
+ export declare const decodePng: (bytes: Uint8Array) => RgbaImage;
4
+ export declare const encodePng: ({ width, height, data }: RgbaImage) => Uint8Array;
5
+ /** Grows both images to the larger size with transparent pixels. */
6
+ export declare const padToSame: (a: RgbaImage, b: RgbaImage) => [RgbaImage, RgbaImage];
7
+ /** Cuts both images to the smaller size. */
8
+ export declare const cropToSame: (a: RgbaImage, b: RgbaImage) => [RgbaImage, RgbaImage];
@@ -0,0 +1,8 @@
1
+ export { Comparer, TOOL_NAME, createComparer, type ComparerOptions, } from './comparer';
2
+ export { loadEngine, pixelmatchEngine, BUILT_IN_ENGINES, type PixelmatchOptions, } from './engines';
3
+ export { fileStore, fsStore, type FsStoreOptions } from './store';
4
+ export { manifestLayout, samePathMatcher, sanitizeName, templateMatcher, } from './layout';
5
+ export { approve, type ApproveOptions, type ApproveResult, type Skipped, } from './approve';
6
+ export { consoleReporter, ctrfReporter, githubSummaryReporter, parseReporters, summaryMarkdown, } from './reporters';
7
+ export { decodePng, encodePng } from './image';
8
+ export * from './types';