@blazediff/contract 1.0.0 → 1.0.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.
- package/dist/index.d.mts +93 -0
- package/package.json +9 -4
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
type BlazeDiffErrorCode = "invalid-image" | "invalid-output" | "invalid-mask" | "invalid-option";
|
|
2
|
+
/** Thrown for invalid arguments. Comparable images never throw. */
|
|
3
|
+
declare class BlazeDiffError extends Error {
|
|
4
|
+
readonly code: BlazeDiffErrorCode;
|
|
5
|
+
constructor(code: BlazeDiffErrorCode, message: string);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** Pixel buffer accepted by every entry point (Node `Buffer` is a Uint8Array). */
|
|
9
|
+
type PixelData = Uint8Array | Uint8ClampedArray;
|
|
10
|
+
type Rgb = [number, number, number];
|
|
11
|
+
/** RGBA8 pixels, `width * height * 4` bytes. Browser `ImageData` fits as is. */
|
|
12
|
+
interface Image {
|
|
13
|
+
data: PixelData;
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
}
|
|
17
|
+
/** `yiq`: the metric pixelmatch used before v8. `oklab`: pixelmatch 8's OKLab HyAB metric. */
|
|
18
|
+
type Metric = "yiq" | "oklab";
|
|
19
|
+
interface RenderOptions {
|
|
20
|
+
/** Opacity of the unchanged image in the output (0-1). Default: 0.1 */
|
|
21
|
+
alpha?: number;
|
|
22
|
+
/** Default: [255, 0, 0] */
|
|
23
|
+
diffColor?: Rgb;
|
|
24
|
+
/** Color for pixels that get darker in `b`. Default: `diffColor` */
|
|
25
|
+
diffColorAlt?: Rgb;
|
|
26
|
+
/** Color for detected anti-aliased pixels. Default: [255, 255, 0] */
|
|
27
|
+
aaColor?: Rgb;
|
|
28
|
+
/** `faded`: a gray copy of `a` under the diff. `transparent`: the diff alone on a cleared buffer. Default: `faded` */
|
|
29
|
+
background?: "faded" | "transparent";
|
|
30
|
+
}
|
|
31
|
+
interface DiffOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Color difference threshold (0-1). Lower is stricter. Default: 0.1.
|
|
34
|
+
* With `yiq` it scales a squared distance; with `oklab`, 1 is black vs white.
|
|
35
|
+
*/
|
|
36
|
+
threshold?: number;
|
|
37
|
+
/** Detect anti-aliased pixels and leave them out of the count. Default: true */
|
|
38
|
+
antialiasing?: boolean;
|
|
39
|
+
/** Default: `yiq` */
|
|
40
|
+
metric?: Metric;
|
|
41
|
+
/** One byte per pixel (`width * height`); pixels with a non-zero byte are skipped. */
|
|
42
|
+
mask?: PixelData;
|
|
43
|
+
/** Also report the N×N window with the most diff pixels. N is clamped to [1, min(width, height)]. */
|
|
44
|
+
window?: number;
|
|
45
|
+
/** Draw the diff here. Omit for a count-only comparison. */
|
|
46
|
+
output?: Image;
|
|
47
|
+
render?: RenderOptions;
|
|
48
|
+
}
|
|
49
|
+
interface Size {
|
|
50
|
+
width: number;
|
|
51
|
+
height: number;
|
|
52
|
+
}
|
|
53
|
+
/** Top-left corner and diff count of the busiest window. */
|
|
54
|
+
interface WindowHit {
|
|
55
|
+
x: number;
|
|
56
|
+
y: number;
|
|
57
|
+
count: number;
|
|
58
|
+
}
|
|
59
|
+
type DiffResult = {
|
|
60
|
+
kind: "compared";
|
|
61
|
+
/** Pixels that differ beyond `threshold`, after the mask and AA exclusion. */
|
|
62
|
+
count: number;
|
|
63
|
+
/** `count` as a percentage of all pixels. */
|
|
64
|
+
percentage: number;
|
|
65
|
+
/** True when `count` is 0. */
|
|
66
|
+
identical: boolean;
|
|
67
|
+
/** Present when the `window` option is set. */
|
|
68
|
+
window?: WindowHit;
|
|
69
|
+
} | {
|
|
70
|
+
kind: "dimension-mismatch";
|
|
71
|
+
a: Size;
|
|
72
|
+
b: Size;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Argument checks shared by `diff` in core, core-wasm and core-native, so all
|
|
77
|
+
* three throw the same {@link BlazeDiffError} codes and messages.
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
declare function isValidImage(arr: unknown): arr is PixelData;
|
|
81
|
+
declare function assertImage(image: Image, name: string, code: BlazeDiffErrorCode): void;
|
|
82
|
+
/** Checks everything in `options` that does not depend on the image size. */
|
|
83
|
+
declare function assertOptions(options: Pick<DiffOptions, "metric" | "mask" | "render">): void;
|
|
84
|
+
/** Checks `output` and the mask length against a `width` × `height` comparison. */
|
|
85
|
+
declare function assertTargets(options: Pick<DiffOptions, "mask" | "output">, width: number, height: number): void;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Window side for the `window` option, or 0 when windowing is off.
|
|
89
|
+
* Floored and clamped to [1, min(width, height)] like pixelmatch.
|
|
90
|
+
*/
|
|
91
|
+
declare function windowSide(window: number | undefined, width: number, height: number): number;
|
|
92
|
+
|
|
93
|
+
export { BlazeDiffError, type BlazeDiffErrorCode, type DiffOptions, type DiffResult, type Image, type Metric, type PixelData, type RenderOptions, type Rgb, type Size, type WindowHit, assertImage, assertOptions, assertTargets, isValidImage, windowSide };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blazediff/contract",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Shared diff API of the BlazeDiff engines: types, errors and argument checks",
|
|
5
5
|
"private": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -11,9 +11,14 @@
|
|
|
11
11
|
"types": "dist/index.d.ts",
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
"import": {
|
|
15
|
+
"types": "./dist/index.d.mts",
|
|
16
|
+
"default": "./dist/index.mjs"
|
|
17
|
+
},
|
|
18
|
+
"require": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"default": "./dist/index.js"
|
|
21
|
+
}
|
|
17
22
|
}
|
|
18
23
|
},
|
|
19
24
|
"files": [
|