@storyshelf/image 0.7.0 → 0.9.0-next-d2cc082
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/async.d.mts +0 -2
- package/dist/async.mjs +1 -2
- package/dist/codec.d.mts +0 -2
- package/dist/codec.mjs +1 -2
- package/dist/codecs.mjs +1 -2
- package/dist/downscale.d.mts +0 -2
- package/dist/downscale.mjs +1 -2
- package/dist/engine.d.mts +0 -2
- package/dist/engine.mjs +1 -2
- package/dist/options.d.mts +0 -2
- package/dist/options.mjs +1 -2
- package/dist/pngjs-downscale.mjs +1 -2
- package/dist/pngjs.mjs +1 -2
- package/dist/pool.mjs +1 -2
- package/dist/settings.d.mts +0 -2
- package/dist/settings.mjs +1 -2
- package/dist/sharp.mjs +1 -2
- package/dist/transfer.mjs +1 -2
- package/dist/worker.mjs +1 -2
- package/package.json +2 -11
package/dist/async.d.mts
CHANGED
|
@@ -2,7 +2,6 @@ import __tsdown_shims_path from 'node:path';
|
|
|
2
2
|
import __tsdown_shims_url from 'node:url';
|
|
3
3
|
import { DiffOptions, DiffResult } from "./options.mjs";
|
|
4
4
|
import { ImageSettings } from "./settings.mjs";
|
|
5
|
-
//#region src/async.d.ts
|
|
6
5
|
/** Environment variable overriding the pool size; `0` runs diffs in-thread. */
|
|
7
6
|
declare const DIFF_WORKERS_ENV = "STORYSHELF_DIFF_WORKERS";
|
|
8
7
|
/**
|
|
@@ -25,6 +24,5 @@ declare function configureImages(settings: ImageSettings): void;
|
|
|
25
24
|
declare function diffImagesAsync(baseline: Buffer, current: Buffer, options: DiffOptions): Promise<DiffResult>;
|
|
26
25
|
/** Stop the shared pool's workers. A later `diffImagesAsync` starts a fresh pool. */
|
|
27
26
|
declare function shutdownDiffPool(): Promise<void>;
|
|
28
|
-
//#endregion
|
|
29
27
|
export { DIFF_WORKERS_ENV, configureImages, diffImagesAsync, shutdownDiffPool };
|
|
30
28
|
//# sourceMappingURL=async.d.mts.map
|
package/dist/async.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import.meta.url;
|
|
|
4
4
|
import { DiffPool } from "./pool.mjs";
|
|
5
5
|
import { appliedImageSettings, configuredThreadCount, currentImageEngine, setImageSettings } from "./settings.mjs";
|
|
6
6
|
import { availableParallelism } from "node:os";
|
|
7
|
-
|
|
7
|
+
// src/async.ts
|
|
8
8
|
/** `diffImagesAsync`: `diffImages` on a lazily created, process-wide worker pool, plus `configureImages`. */
|
|
9
9
|
/** Environment variable overriding the pool size; `0` runs diffs in-thread. */
|
|
10
10
|
const DIFF_WORKERS_ENV = "STORYSHELF_DIFF_WORKERS";
|
|
@@ -58,7 +58,6 @@ function resolveDiffWorkers(env, parallelism = availableParallelism()) {
|
|
|
58
58
|
function defaultWorkerUrl() {
|
|
59
59
|
return import.meta.url.endsWith(".ts") ? new URL("worker.ts", import.meta.url) : new URL("worker.mjs", import.meta.url);
|
|
60
60
|
}
|
|
61
|
-
//#endregion
|
|
62
61
|
export { DIFF_WORKERS_ENV, configureImages, diffImagesAsync, resolveDiffWorkers, shutdownDiffPool };
|
|
63
62
|
|
|
64
63
|
//# sourceMappingURL=async.mjs.map
|
package/dist/codec.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import __tsdown_shims_path from 'node:path';
|
|
2
2
|
import __tsdown_shims_url from 'node:url';
|
|
3
|
-
//#region src/codec.d.ts
|
|
4
3
|
/** Image codecs: how PNGs become raw RGBA pixels and back. The comparison itself is always pixelmatch. */
|
|
5
4
|
/** Engine names accepted by `images.engine` and `STORYSHELF_IMAGE_ENGINE`. */
|
|
6
5
|
declare const IMAGE_ENGINES: readonly ["pngjs", "sharp"];
|
|
@@ -33,6 +32,5 @@ declare function isImageEngine(value: unknown): value is ImageEngine;
|
|
|
33
32
|
* missing means the default. An unknown name throws so a typo cannot silently fall back.
|
|
34
33
|
*/
|
|
35
34
|
declare function resolveImageEngine(raw: string | undefined): ImageEngine;
|
|
36
|
-
//#endregion
|
|
37
35
|
export { DEFAULT_IMAGE_ENGINE, IMAGE_ENGINES, IMAGE_ENGINE_ENV, ImageCodec, ImageEngine, RgbaImage, isImageEngine, resolveImageEngine };
|
|
38
36
|
//# sourceMappingURL=codec.d.mts.map
|
package/dist/codec.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "node:path";
|
|
2
2
|
import "node:url";
|
|
3
3
|
import.meta.url;
|
|
4
|
-
|
|
4
|
+
// src/codec.ts
|
|
5
5
|
/** Image codecs: how PNGs become raw RGBA pixels and back. The comparison itself is always pixelmatch. */
|
|
6
6
|
/** Engine names accepted by `images.engine` and `STORYSHELF_IMAGE_ENGINE`. */
|
|
7
7
|
const IMAGE_ENGINES = ["pngjs", "sharp"];
|
|
@@ -23,7 +23,6 @@ function resolveImageEngine(raw) {
|
|
|
23
23
|
if (!isImageEngine(value)) throw new Error(`Unknown image engine "${value}". Use one of: ${IMAGE_ENGINES.join(", ")}.`);
|
|
24
24
|
return value;
|
|
25
25
|
}
|
|
26
|
-
//#endregion
|
|
27
26
|
export { DEFAULT_IMAGE_ENGINE, IMAGE_ENGINES, IMAGE_ENGINE_ENV, isImageEngine, resolveImageEngine };
|
|
28
27
|
|
|
29
28
|
//# sourceMappingURL=codec.mjs.map
|
package/dist/codecs.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "node:path";
|
|
2
2
|
import "node:url";
|
|
3
3
|
import.meta.url;
|
|
4
|
-
|
|
4
|
+
// src/codecs.ts
|
|
5
5
|
const loaded = /* @__PURE__ */ new Map();
|
|
6
6
|
/** The codec for an engine, loaded once per thread. Rejects when its dependency is unavailable. */
|
|
7
7
|
async function loadCodec(engine) {
|
|
@@ -22,7 +22,6 @@ async function importPngjsCodec() {
|
|
|
22
22
|
async function importSharpCodec() {
|
|
23
23
|
return await (await import("./sharp.mjs")).createSharpCodec();
|
|
24
24
|
}
|
|
25
|
-
//#endregion
|
|
26
25
|
export { loadCodec };
|
|
27
26
|
|
|
28
27
|
//# sourceMappingURL=codecs.mjs.map
|
package/dist/downscale.d.mts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import __tsdown_shims_path from 'node:path';
|
|
2
2
|
import __tsdown_shims_url from 'node:url';
|
|
3
|
-
//#region src/downscale.d.ts
|
|
4
3
|
/** Downscale a PNG so its long edge is at most `maxEdge`, using the configured image engine. */
|
|
5
4
|
declare function downscalePng(buffer: Uint8Array, maxEdge: number): Promise<Uint8Array>;
|
|
6
|
-
//#endregion
|
|
7
5
|
export { downscalePng };
|
|
8
6
|
//# sourceMappingURL=downscale.d.mts.map
|
package/dist/downscale.mjs
CHANGED
|
@@ -3,13 +3,12 @@ import "node:url";
|
|
|
3
3
|
import.meta.url;
|
|
4
4
|
import { loadCodec } from "./codecs.mjs";
|
|
5
5
|
import { currentImageEngine } from "./settings.mjs";
|
|
6
|
-
|
|
6
|
+
// src/downscale.ts
|
|
7
7
|
/** PNG thumbnails on the configured engine (output stays PNG). */
|
|
8
8
|
/** Downscale a PNG so its long edge is at most `maxEdge`, using the configured image engine. */
|
|
9
9
|
async function downscalePng(buffer, maxEdge) {
|
|
10
10
|
return await (await loadCodec(currentImageEngine())).downscale(buffer, maxEdge);
|
|
11
11
|
}
|
|
12
|
-
//#endregion
|
|
13
12
|
export { downscalePng };
|
|
14
13
|
|
|
15
14
|
//# sourceMappingURL=downscale.mjs.map
|
package/dist/engine.d.mts
CHANGED
|
@@ -2,7 +2,6 @@ import __tsdown_shims_path from 'node:path';
|
|
|
2
2
|
import __tsdown_shims_url from 'node:url';
|
|
3
3
|
import { DiffOptions, DiffResult } from "./options.mjs";
|
|
4
4
|
import { ImageCodec } from "./codec.mjs";
|
|
5
|
-
//#region src/engine.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* Compare baseline and current screenshots, returning pass/fail and a diff image.
|
|
8
7
|
*
|
|
@@ -13,6 +12,5 @@ import { ImageCodec } from "./codec.mjs";
|
|
|
13
12
|
* @returns The diff result with pixel counts and an optional overlay image.
|
|
14
13
|
*/
|
|
15
14
|
declare function diffImages(baseline: Buffer, current: Buffer, options: DiffOptions, codec?: ImageCodec): Promise<DiffResult>;
|
|
16
|
-
//#endregion
|
|
17
15
|
export { diffImages };
|
|
18
16
|
//# sourceMappingURL=engine.d.mts.map
|
package/dist/engine.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import "node:url";
|
|
|
3
3
|
import.meta.url;
|
|
4
4
|
import { pngjsCodec } from "./pngjs.mjs";
|
|
5
5
|
import pixelmatch from "pixelmatch";
|
|
6
|
-
|
|
6
|
+
// src/engine.ts
|
|
7
7
|
/**
|
|
8
8
|
* Compare baseline and current screenshots, returning pass/fail and a diff image.
|
|
9
9
|
*
|
|
@@ -138,7 +138,6 @@ async function compareRegions({ width, height, baseline, current }, options, cod
|
|
|
138
138
|
diffImage: await codec.encode(overlay)
|
|
139
139
|
};
|
|
140
140
|
}
|
|
141
|
-
//#endregion
|
|
142
141
|
export { diffImages, identicalResult };
|
|
143
142
|
|
|
144
143
|
//# sourceMappingURL=engine.mjs.map
|
package/dist/options.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import __tsdown_shims_path from 'node:path';
|
|
2
2
|
import __tsdown_shims_url from 'node:url';
|
|
3
|
-
//#region src/options.d.ts
|
|
4
3
|
/** Options that control how two images are compared. */
|
|
5
4
|
interface DiffOptions {
|
|
6
5
|
/** Per-pixel difference threshold (0-1) above which a pixel counts as different. */
|
|
@@ -37,6 +36,5 @@ interface DiffResult {
|
|
|
37
36
|
}
|
|
38
37
|
/** Default diff settings used when no project overrides are present. */
|
|
39
38
|
declare const DEFAULT_DIFF_OPTIONS: DiffOptions;
|
|
40
|
-
//#endregion
|
|
41
39
|
export { DEFAULT_DIFF_OPTIONS, DiffOptions, DiffResult };
|
|
42
40
|
//# sourceMappingURL=options.d.mts.map
|
package/dist/options.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "node:path";
|
|
2
2
|
import "node:url";
|
|
3
3
|
import.meta.url;
|
|
4
|
-
|
|
4
|
+
// src/options.ts
|
|
5
5
|
/** Default diff settings used when no project overrides are present. */
|
|
6
6
|
const DEFAULT_DIFF_OPTIONS = {
|
|
7
7
|
pixelThreshold: .1,
|
|
@@ -9,7 +9,6 @@ const DEFAULT_DIFF_OPTIONS = {
|
|
|
9
9
|
includeAntialiasing: false,
|
|
10
10
|
failOnSizeChange: true
|
|
11
11
|
};
|
|
12
|
-
//#endregion
|
|
13
12
|
export { DEFAULT_DIFF_OPTIONS };
|
|
14
13
|
|
|
15
14
|
//# sourceMappingURL=options.mjs.map
|
package/dist/pngjs-downscale.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import "node:path";
|
|
|
2
2
|
import "node:url";
|
|
3
3
|
import.meta.url;
|
|
4
4
|
import { PNG } from "pngjs";
|
|
5
|
-
|
|
5
|
+
// src/pngjs-downscale.ts
|
|
6
6
|
/** Box-sampling PNG downscale on pngjs. */
|
|
7
7
|
/** Downscale a PNG so its long edge is at most `maxEdge` (box sampling). */
|
|
8
8
|
function downscaleWithPngjs(buffer, maxEdge) {
|
|
@@ -45,7 +45,6 @@ function writePixel(dst, col, row, rgba) {
|
|
|
45
45
|
const at = (row * dst.width + col) * 4;
|
|
46
46
|
for (let channel = 0; channel < 4; channel += 1) dst.data[at + channel] = rgba[channel] ?? 0;
|
|
47
47
|
}
|
|
48
|
-
//#endregion
|
|
49
48
|
export { downscaleWithPngjs };
|
|
50
49
|
|
|
51
50
|
//# sourceMappingURL=pngjs-downscale.mjs.map
|
package/dist/pngjs.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import "node:url";
|
|
|
3
3
|
import.meta.url;
|
|
4
4
|
import { downscaleWithPngjs } from "./pngjs-downscale.mjs";
|
|
5
5
|
import { PNG } from "pngjs";
|
|
6
|
-
|
|
6
|
+
// src/pngjs.ts
|
|
7
7
|
/** The default codec: pure JavaScript (pngjs), runs on every runtime. */
|
|
8
8
|
const pngjsCodec = {
|
|
9
9
|
name: "pngjs",
|
|
@@ -25,7 +25,6 @@ const pngjsCodec = {
|
|
|
25
25
|
},
|
|
26
26
|
downscale: downscaleWithPngjs
|
|
27
27
|
};
|
|
28
|
-
//#endregion
|
|
29
28
|
export { pngjsCodec };
|
|
30
29
|
|
|
31
30
|
//# sourceMappingURL=pngjs.mjs.map
|
package/dist/pool.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import.meta.url;
|
|
|
4
4
|
import { loadCodec } from "./codecs.mjs";
|
|
5
5
|
import { diffImages, identicalResult } from "./engine.mjs";
|
|
6
6
|
import { fromTransferred, toTransferable } from "./transfer.mjs";
|
|
7
|
-
|
|
7
|
+
// src/pool.ts
|
|
8
8
|
/** Workers dying before `ready` in a row, after one has started fine, before the pool gives up. */
|
|
9
9
|
const MAX_START_FAILURES = 3;
|
|
10
10
|
const livePools = /* @__PURE__ */ new Set();
|
|
@@ -233,7 +233,6 @@ function settle(task, message) {
|
|
|
233
233
|
error.name = message.name;
|
|
234
234
|
task.reject(error);
|
|
235
235
|
}
|
|
236
|
-
//#endregion
|
|
237
236
|
export { DiffPool };
|
|
238
237
|
|
|
239
238
|
//# sourceMappingURL=pool.mjs.map
|
package/dist/settings.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import __tsdown_shims_path from 'node:path';
|
|
2
2
|
import __tsdown_shims_url from 'node:url';
|
|
3
3
|
import { ImageEngine } from "./codec.mjs";
|
|
4
|
-
//#region src/settings.d.ts
|
|
5
4
|
/** What `createShelfApp` passes down: `images.engine` and `compare.threads`. */
|
|
6
5
|
interface ImageSettings {
|
|
7
6
|
/** Image library: `"pngjs"` (default) or `"sharp"`; falls back to `STORYSHELF_IMAGE_ENGINE`. */
|
|
@@ -17,6 +16,5 @@ declare function currentImageEngine(): ImageEngine;
|
|
|
17
16
|
* so it returns at once and never delays startup (or the first capture).
|
|
18
17
|
*/
|
|
19
18
|
declare function verifyImageEngine(): Promise<ImageEngine>;
|
|
20
|
-
//#endregion
|
|
21
19
|
export { ImageSettings, currentImageEngine, verifyImageEngine };
|
|
22
20
|
//# sourceMappingURL=settings.d.mts.map
|
package/dist/settings.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import "node:url";
|
|
|
3
3
|
import.meta.url;
|
|
4
4
|
import { loadCodec } from "./codecs.mjs";
|
|
5
5
|
import { resolveImageEngine } from "./codec.mjs";
|
|
6
|
-
|
|
6
|
+
// src/settings.ts
|
|
7
7
|
/** Process-wide image settings, set once at app boot and read by the diff pool and thumbnails. */
|
|
8
8
|
let configuredEngine;
|
|
9
9
|
let configuredThreads;
|
|
@@ -42,7 +42,6 @@ async function verifyImageEngine() {
|
|
|
42
42
|
if (engine !== "pngjs") await loadCodec(engine);
|
|
43
43
|
return engine;
|
|
44
44
|
}
|
|
45
|
-
//#endregion
|
|
46
45
|
export { appliedImageSettings, configuredThreadCount, currentImageEngine, setImageSettings, verifyImageEngine };
|
|
47
46
|
|
|
48
47
|
//# sourceMappingURL=settings.mjs.map
|
package/dist/sharp.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import "node:path";
|
|
|
2
2
|
import "node:url";
|
|
3
3
|
import.meta.url;
|
|
4
4
|
import { isMainThread } from "node:worker_threads";
|
|
5
|
-
|
|
5
|
+
// src/sharp.ts
|
|
6
6
|
/** The optional native codec: libvips via `sharp`. Several times faster than pngjs on large PNGs. */
|
|
7
7
|
/**
|
|
8
8
|
* Load `sharp` and build the codec. Throws a readable error when the optional peer is missing
|
|
@@ -54,7 +54,6 @@ async function downscaleWithSharp(sharp, png, maxEdge) {
|
|
|
54
54
|
}).png().toBuffer();
|
|
55
55
|
return new Uint8Array(out);
|
|
56
56
|
}
|
|
57
|
-
//#endregion
|
|
58
57
|
export { createSharpCodec };
|
|
59
58
|
|
|
60
59
|
//# sourceMappingURL=sharp.mjs.map
|
package/dist/transfer.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "node:path";
|
|
2
2
|
import "node:url";
|
|
3
3
|
import.meta.url;
|
|
4
|
-
|
|
4
|
+
// src/transfer.ts
|
|
5
5
|
/** Zero-copy hand-off of Buffers across the worker boundary. */
|
|
6
6
|
/**
|
|
7
7
|
* A Uint8Array that may be transferred (detached from the caller) without corrupting anything.
|
|
@@ -18,7 +18,6 @@ function toTransferable(buffer) {
|
|
|
18
18
|
function fromTransferred(bytes) {
|
|
19
19
|
return Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
20
20
|
}
|
|
21
|
-
//#endregion
|
|
22
21
|
export { fromTransferred, toTransferable };
|
|
23
22
|
|
|
24
23
|
//# sourceMappingURL=transfer.mjs.map
|
package/dist/worker.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { loadCodec } from "./codecs.mjs";
|
|
|
5
5
|
import { diffImages } from "./engine.mjs";
|
|
6
6
|
import { fromTransferred, toTransferable } from "./transfer.mjs";
|
|
7
7
|
import { parentPort } from "node:worker_threads";
|
|
8
|
-
|
|
8
|
+
// src/worker.ts
|
|
9
9
|
/** Worker-thread entry for the diff pool: runs the same `diffImages` as the in-thread path. */
|
|
10
10
|
const port = parentPort;
|
|
11
11
|
async function handle(request) {
|
|
@@ -41,7 +41,6 @@ port?.on("message", (request) => {
|
|
|
41
41
|
});
|
|
42
42
|
});
|
|
43
43
|
port?.postMessage({ type: "ready" });
|
|
44
|
-
//#endregion
|
|
45
44
|
export {};
|
|
46
45
|
|
|
47
46
|
//# sourceMappingURL=worker.mjs.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storyshelf/image",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0-next-d2cc082",
|
|
4
4
|
"description": "StoryShelf image engine: pixel diffing, overlay rendering and thumbnails on a worker-thread pool, with pngjs (default) or sharp codecs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"diff",
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
"sharp": "^0.35.5",
|
|
70
70
|
"tsdown": "^0.22.14",
|
|
71
71
|
"typescript": "^7.0.2",
|
|
72
|
-
"vitest": "^5.0.
|
|
72
|
+
"vitest": "^5.0.5"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
75
|
"sharp": ">=0.34.0"
|
|
@@ -81,14 +81,5 @@
|
|
|
81
81
|
},
|
|
82
82
|
"engines": {
|
|
83
83
|
"node": ">=24"
|
|
84
|
-
},
|
|
85
|
-
"jsr": {
|
|
86
|
-
"runtimeCompat": {
|
|
87
|
-
"node": true,
|
|
88
|
-
"deno": true,
|
|
89
|
-
"bun": true,
|
|
90
|
-
"workerd": false,
|
|
91
|
-
"browser": false
|
|
92
|
-
}
|
|
93
84
|
}
|
|
94
85
|
}
|