@blazediff/contract 0.0.0-stage → 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/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Teimur Gasanov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -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 };
@@ -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/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ 'use strict';var o=class extends Error{constructor(e,t){super(t),this.name="BlazeDiffError",this.code=e;}};function f(r){return ArrayBuffer.isView(r)&&r.BYTES_PER_ELEMENT===1}function d(r,e,t){if(!f(r?.data))throw new o(t,`${e}.data must be a Uint8Array, Uint8ClampedArray or Buffer.`);let{width:n,height:i,data:s}=r;if(!Number.isInteger(n)||!Number.isInteger(i)||n<0||i<0)throw new o(t,`${e} has an invalid size: ${n}x${i}.`);if(s.length!==n*i*4)throw new o(t,`${e}.data is ${s.length} bytes, expected ${n*i*4} for ${n}x${i}.`)}function u(r){let{metric:e,mask:t,render:n}=r;if(e!==void 0&&e!=="yiq"&&e!=="oklab")throw new o("invalid-option",`Unknown metric: ${e}. Expected "yiq" or "oklab".`);let i=n?.background;if(i!==void 0&&i!=="faded"&&i!=="transparent")throw new o("invalid-option",`Unknown render.background: ${i}. Expected "faded" or "transparent".`);if(a(n?.diffColor,"diffColor"),a(n?.diffColorAlt,"diffColorAlt"),a(n?.aaColor,"aaColor"),t!==void 0&&!f(t))throw new o("invalid-mask","mask must be a byte array of width * height bytes.")}function p(r,e,t){let{mask:n,output:i}=r;if(i&&(d(i,"output","invalid-output"),i.width!==e||i.height!==t))throw new o("invalid-output",`output is ${i.width}x${i.height}, expected ${e}x${t}.`);if(n!==void 0&&n.length!==e*t)throw new o("invalid-mask",`mask must be a byte array of width * height = ${e*t} bytes.`)}function a(r,e){if(r!==void 0&&(r.length!==3||r.some(t=>!Number.isInteger(t)||t<0||t>255)))throw new o("invalid-option",`render.${e} must contain three integer RGB channels.`)}function m(r,e,t){return r===void 0||!Number.isFinite(r)?0:Math.min(Math.max(Math.floor(r),1),e,t)}exports.BlazeDiffError=o;exports.assertImage=d;exports.assertOptions=u;exports.assertTargets=p;exports.isValidImage=f;exports.windowSide=m;
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ var o=class extends Error{constructor(e,t){super(t),this.name="BlazeDiffError",this.code=e;}};function f(r){return ArrayBuffer.isView(r)&&r.BYTES_PER_ELEMENT===1}function d(r,e,t){if(!f(r?.data))throw new o(t,`${e}.data must be a Uint8Array, Uint8ClampedArray or Buffer.`);let{width:n,height:i,data:s}=r;if(!Number.isInteger(n)||!Number.isInteger(i)||n<0||i<0)throw new o(t,`${e} has an invalid size: ${n}x${i}.`);if(s.length!==n*i*4)throw new o(t,`${e}.data is ${s.length} bytes, expected ${n*i*4} for ${n}x${i}.`)}function u(r){let{metric:e,mask:t,render:n}=r;if(e!==void 0&&e!=="yiq"&&e!=="oklab")throw new o("invalid-option",`Unknown metric: ${e}. Expected "yiq" or "oklab".`);let i=n?.background;if(i!==void 0&&i!=="faded"&&i!=="transparent")throw new o("invalid-option",`Unknown render.background: ${i}. Expected "faded" or "transparent".`);if(a(n?.diffColor,"diffColor"),a(n?.diffColorAlt,"diffColorAlt"),a(n?.aaColor,"aaColor"),t!==void 0&&!f(t))throw new o("invalid-mask","mask must be a byte array of width * height bytes.")}function p(r,e,t){let{mask:n,output:i}=r;if(i&&(d(i,"output","invalid-output"),i.width!==e||i.height!==t))throw new o("invalid-output",`output is ${i.width}x${i.height}, expected ${e}x${t}.`);if(n!==void 0&&n.length!==e*t)throw new o("invalid-mask",`mask must be a byte array of width * height = ${e*t} bytes.`)}function a(r,e){if(r!==void 0&&(r.length!==3||r.some(t=>!Number.isInteger(t)||t<0||t>255)))throw new o("invalid-option",`render.${e} must contain three integer RGB channels.`)}function m(r,e,t){return r===void 0||!Number.isFinite(r)?0:Math.min(Math.max(Math.floor(r),1),e,t)}export{o as BlazeDiffError,d as assertImage,u as assertOptions,p as assertTargets,f as isValidImage,m as windowSide};
package/package.json CHANGED
@@ -1,6 +1,47 @@
1
1
  {
2
2
  "name": "@blazediff/contract",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.1",
4
+ "description": "Shared diff API of the BlazeDiff engines: types, errors and argument checks",
5
+ "private": false,
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "main": "dist/index.js",
10
+ "module": "dist/index.mjs",
11
+ "types": "dist/index.d.ts",
12
+ "exports": {
13
+ ".": {
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
+ }
22
+ }
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "keywords": [
28
+ "image",
29
+ "comparison",
30
+ "diff",
31
+ "blazediff"
32
+ ],
33
+ "author": "Teimur Gasanov <me@teimurjan.dev> (https://github.com/teimurjan)",
34
+ "repository": "https://github.com/teimurjan/blazediff",
35
+ "homepage": "https://blazediff.dev",
36
+ "license": "MIT",
37
+ "devDependencies": {
38
+ "tsup": "8.5.0",
39
+ "typescript": "5.9.2"
40
+ },
41
+ "scripts": {
42
+ "typecheck": "tsc --noEmit",
43
+ "build": "tsup",
44
+ "dev": "tsup --watch",
45
+ "clean": "rm -rf dist"
46
+ }
6
47
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.