@e2e-dev/decision 0.3.2 → 0.3.3-nightly-20261107030214

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/.build.json CHANGED
@@ -1 +1 @@
1
- {"version":"0.3.2"}
1
+ {"version":"0.3.3-nightly-20261107030214"}
package/dist/overlay.d.ts CHANGED
@@ -40,7 +40,8 @@ export interface Zoom {
40
40
  /**
41
41
  * The `box` by `box` CSS-pixel region around `center`, kept inside the
42
42
  * screenshot and enlarged `factor` times (nearest neighbor), for a finer
43
- * closer look at a drawn control. Undefined when the pixels cannot be decoded.
43
+ * closer look at a drawn control. Undefined when the pixels cannot be
44
+ * decoded or the region comes out under one pixel, which no PNG can hold.
44
45
  */
45
46
  export declare function zoomAround(screenshot: Screenshot, center: Point, box: number, factor: number): Zoom | undefined;
46
47
  /**
package/dist/overlay.js CHANGED
@@ -1,5 +1,5 @@
1
- import { PNG } from 'pngjs';
2
1
  import { fnv1a } from './hash.js';
2
+ import { decodeRgba, encodeRgba } from './png.js';
3
3
  /** The Decisions API scores at most ten levels per question. */
4
4
  const MAX_LEVELS = 10;
5
5
  /**
@@ -30,7 +30,8 @@ export function pointOf(grid, column, row) {
30
30
  /**
31
31
  * The `box` by `box` CSS-pixel region around `center`, kept inside the
32
32
  * screenshot and enlarged `factor` times (nearest neighbor), for a finer
33
- * closer look at a drawn control. Undefined when the pixels cannot be decoded.
33
+ * closer look at a drawn control. Undefined when the pixels cannot be
34
+ * decoded or the region comes out under one pixel, which no PNG can hold.
34
35
  */
35
36
  export function zoomAround(screenshot, center, box, factor) {
36
37
  const png = decode(screenshot);
@@ -45,7 +46,9 @@ export function zoomAround(screenshot, center, box, factor) {
45
46
  y: Math.round(Math.max(0, Math.min(cssHeight - side, center.y - side / 2))),
46
47
  };
47
48
  const size = Math.round(side * factor);
48
- const out = new PNG({ width: size, height: size });
49
+ if (!Number.isFinite(size) || size < 1)
50
+ return undefined;
51
+ const out = { width: size, height: size, data: new Uint8Array(size * size * 4) };
49
52
  for (let y = 0; y < size; y += 1) {
50
53
  for (let x = 0; x < size; x += 1) {
51
54
  const sx = Math.min(png.width - 1, Math.floor((origin.x + x / factor) * scale));
@@ -58,7 +61,7 @@ export function zoomAround(screenshot, center, box, factor) {
58
61
  out.data[to + 3] = 255;
59
62
  }
60
63
  }
61
- return { screenshot: { mediaType: 'image/png', data: new Uint8Array(PNG.sync.write(out)), width: size, height: size, scale: 1 }, origin, factor };
64
+ return { screenshot: { mediaType: 'image/png', data: encodeRgba(out), width: size, height: size, scale: 1 }, origin, factor };
62
65
  }
63
66
  /**
64
67
  * A hash of the `box` by `box` CSS-pixel region around `center`: what a tap
@@ -99,11 +102,11 @@ export function withGrid(screenshot, grid) {
99
102
  }
100
103
  }
101
104
  }
102
- return { ...screenshot, data: new Uint8Array(PNG.sync.write(png)) };
105
+ return { ...screenshot, data: encodeRgba(png) };
103
106
  }
104
107
  function decode(screenshot) {
105
108
  try {
106
- return PNG.sync.read(Buffer.from(screenshot.data));
109
+ return decodeRgba(screenshot.data);
107
110
  }
108
111
  catch {
109
112
  return undefined;
package/dist/png.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ /** An 8-bit RGBA image, rows top to bottom. */
2
+ export interface Rgba {
3
+ readonly width: number;
4
+ readonly height: number;
5
+ readonly data: Uint8Array;
6
+ }
7
+ /**
8
+ * Decodes PNG bytes to 8-bit RGBA, whatever the color type, bit depth, or
9
+ * palette; throws on bytes that are not a PNG. An 8-bit RGB screenshot is
10
+ * widened by the addon: opacity 1 keeps every sample and adds the opaque
11
+ * alpha channel, several times faster than `spread` does it.
12
+ */
13
+ export declare function decodeRgba(bytes: Uint8Array): Rgba;
14
+ /**
15
+ * Encodes an image as PNG bytes, each row adaptively filtered: the addon's
16
+ * default writes no filter, which makes screenshots markedly larger.
17
+ */
18
+ export declare function encodeRgba(image: Rgba): Uint8Array;
package/dist/png.js ADDED
@@ -0,0 +1,67 @@
1
+ import { endianness } from 'node:os';
2
+ import { FilterType, JsColorType, Transformer } from '@napi-rs/image';
3
+ const LITTLE_ENDIAN = endianness() === 'LE';
4
+ /** Channels per pixel, and whether each is a 16-bit sample, for every color type a decode reads: 8-bit RGB is widened by the addon before that. */
5
+ const LAYOUTS = {
6
+ [JsColorType.L8]: { channels: 1, wide: false },
7
+ [JsColorType.La8]: { channels: 2, wide: false },
8
+ [JsColorType.Rgba8]: { channels: 4, wide: false },
9
+ [JsColorType.L16]: { channels: 1, wide: true },
10
+ [JsColorType.La16]: { channels: 2, wide: true },
11
+ [JsColorType.Rgb16]: { channels: 3, wide: true },
12
+ [JsColorType.Rgba16]: { channels: 4, wide: true },
13
+ };
14
+ /**
15
+ * Decodes PNG bytes to 8-bit RGBA, whatever the color type, bit depth, or
16
+ * palette; throws on bytes that are not a PNG. An 8-bit RGB screenshot is
17
+ * widened by the addon: opacity 1 keeps every sample and adds the opaque
18
+ * alpha channel, several times faster than `spread` does it.
19
+ */
20
+ export function decodeRgba(bytes) {
21
+ const decoder = new Transformer(bytes);
22
+ const { width, height, format, colorType } = decoder.metadataSync();
23
+ if (format !== 'png')
24
+ throw new Error(`not a PNG: the bytes are ${format}`);
25
+ const rgb = colorType === JsColorType.Rgb8;
26
+ const raw = (rgb ? decoder.opacity(1) : decoder).rawPixelsSync();
27
+ const layout = LAYOUTS[rgb ? JsColorType.Rgba8 : colorType];
28
+ if (layout === undefined)
29
+ throw new Error(`unsupported PNG color type ${colorType}`);
30
+ const { channels, wide } = layout;
31
+ if (raw.length !== width * height * channels * (wide ? 2 : 1))
32
+ throw new Error('the decoded PNG pixels do not fill its size');
33
+ const samples = new Uint8Array(raw.buffer, raw.byteOffset, raw.byteLength);
34
+ if (channels === 4 && !wide)
35
+ return { width, height, data: samples };
36
+ return { width, height, data: spread(wide ? narrow(samples) : samples, channels, width * height) };
37
+ }
38
+ /**
39
+ * Encodes an image as PNG bytes, each row adaptively filtered: the addon's
40
+ * default writes no filter, which makes screenshots markedly larger.
41
+ */
42
+ export function encodeRgba(image) {
43
+ const png = Transformer.fromRgbaPixels(image.data, image.width, image.height).pngSync({ filterType: FilterType.Adaptive });
44
+ return new Uint8Array(png.buffer, png.byteOffset, png.byteLength);
45
+ }
46
+ /** 16-bit samples in native byte order as 8-bit samples, rounded. */
47
+ function narrow(bytes) {
48
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
49
+ const samples = new Uint8Array(bytes.length / 2);
50
+ for (let at = 0; at < samples.length; at += 1)
51
+ samples[at] = Math.round((view.getUint16(at * 2, LITTLE_ENDIAN) * 255) / 65535);
52
+ return samples;
53
+ }
54
+ /** 8-bit samples of `channels` per pixel (gray, gray and alpha, RGB) as RGBA; a gray or RGB image is opaque. */
55
+ function spread(samples, channels, pixels) {
56
+ const out = new Uint8Array(pixels * 4);
57
+ const gray = channels <= 2;
58
+ const alpha = channels === 2 || channels === 4;
59
+ for (let pixel = 0, from = 0, to = 0; pixel < pixels; pixel += 1, from += channels, to += 4) {
60
+ const r = samples[from];
61
+ out[to] = r;
62
+ out[to + 1] = gray ? r : samples[from + 1];
63
+ out[to + 2] = gray ? r : samples[from + 2];
64
+ out[to + 3] = alpha ? samples[from + channels - 1] : 255;
65
+ }
66
+ return out;
67
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@e2e-dev/decision",
3
- "version": "0.3.2",
3
+ "version": "0.3.3-nightly-20261107030214",
4
4
  "description": "Decision-model executors and test filters for e2e",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -25,23 +25,22 @@
25
25
  "NOTICE"
26
26
  ],
27
27
  "dependencies": {
28
- "pngjs": "7.0.0",
28
+ "@napi-rs/image": "1.16.0",
29
29
  "zod": "4.6.7"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "ai": "^7.0.134",
33
- "e2e": ">=0.21.3 <1"
33
+ "e2e": "0.23.1-nightly-20261107030214"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@ai-sdk/openai": "4.0.109",
37
37
  "@ai-sdk/typesafe-ai": "3.0.34",
38
- "@e2e-dev/web": "0.15.5",
38
+ "@e2e-dev/web": "0.15.6-nightly-20261107030214",
39
39
  "@types/node": "26.6.6",
40
- "@types/pngjs": "6.0.5",
41
40
  "ai": "7.0.163",
42
41
  "ajv": "8.20.0",
43
42
  "ajv-formats": "3.0.1",
44
- "e2e": "0.23.0",
43
+ "e2e": "0.23.1-nightly-20261107030214",
45
44
  "typescript": "7.0.2",
46
45
  "vitest": "5.1.0"
47
46
  },