@a11y-pulse/browser-adaptor 0.6.0 → 0.7.0

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/README.md CHANGED
@@ -20,7 +20,7 @@ npm install @a11y-pulse/browser-adaptor
20
20
 
21
21
  | Entry | Contents |
22
22
  | --- | --- |
23
- | `@a11y-pulse/browser-adaptor` | `BrowserAdaptor`, `ElementRef`, `Rect` |
23
+ | `@a11y-pulse/browser-adaptor` | `BrowserAdaptor`, `ElementRef`, `Rect`, `bufferedClip`, `contrastRatio`, `parseOpaqueRgb`, `relativeLuminance` |
24
24
  | `@a11y-pulse/browser-adaptor/puppeteer` | `PuppeteerAdaptor` |
25
25
  | `@a11y-pulse/browser-adaptor/playwright` | `PlaywrightAdaptor` |
26
26
  | `@a11y-pulse/browser-adaptor/dom` | `getSelector`, `truncateHtml` |
@@ -0,0 +1,14 @@
1
+ export type Rgb = readonly [number, number, number];
2
+ /**
3
+ * Parse a computed `rgb()` or `rgba()` colour, or return null when it is translucent or in another
4
+ * notation.
5
+ */
6
+ export declare function parseOpaqueRgb(value: string): Rgb | null;
7
+ /**
8
+ * The WCAG relative luminance of an sRGB colour, from 0 (black) to 1 (white).
9
+ */
10
+ export declare function relativeLuminance([r, g, b]: Rgb): number;
11
+ /**
12
+ * The WCAG contrast ratio between two colours, from 1 to 21.
13
+ */
14
+ export declare function contrastRatio(a: Rgb, b: Rgb): number;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,4 @@
1
1
  export type { BrowserAdaptor, ElementRef, KeyName, Rect } from "./adaptor";
2
2
  export { bufferedClip } from "./clip";
3
+ export type { Rgb } from "./contrast";
4
+ export { contrastRatio, parseOpaqueRgb, relativeLuminance } from "./contrast";
package/dist/index.js CHANGED
@@ -11,7 +11,35 @@ function bufferedClip(rect, pageWidth, pageHeight, buffer) {
11
11
  height: rect.height + top + bottom
12
12
  };
13
13
  }
14
+
15
+ // src/contrast.ts
16
+ var RGB_PATTERN = /^rgba?\(\s*([\d.]+),\s*([\d.]+),\s*([\d.]+)(?:,\s*([\d.]+))?\s*\)$/;
17
+ function parseOpaqueRgb(value) {
18
+ const match = RGB_PATTERN.exec(value.trim());
19
+ if (!match) {
20
+ return null;
21
+ }
22
+ if (match[4] !== void 0 && Number(match[4]) < 1) {
23
+ return null;
24
+ }
25
+ return [Number(match[1]), Number(match[2]), Number(match[3])];
26
+ }
27
+ function linearise(channel) {
28
+ const c = channel / 255;
29
+ return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
30
+ }
31
+ function relativeLuminance([r, g, b]) {
32
+ return 0.2126 * linearise(r) + 0.7152 * linearise(g) + 0.0722 * linearise(b);
33
+ }
34
+ function contrastRatio(a, b) {
35
+ const la = relativeLuminance(a);
36
+ const lb = relativeLuminance(b);
37
+ return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
38
+ }
14
39
  export {
15
- bufferedClip
40
+ bufferedClip,
41
+ contrastRatio,
42
+ parseOpaqueRgb,
43
+ relativeLuminance
16
44
  };
17
45
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/clip.ts"],"sourcesContent":["import type { Rect } from \"./adaptor\";\n\n/**\n * A screenshot clip framing `rect` with up to `buffer` pixels of padding on each side, shrunk where\n * the page edges leave less room. The padding allows for indicators drawn just outside the element\n * box (outlines, shadows) and for anti-aliasing.\n */\nexport function bufferedClip(\n\trect: Rect,\n\tpageWidth: number,\n\tpageHeight: number,\n\tbuffer: number,\n): Rect {\n\tconst left = Math.max(0, Math.min(buffer, rect.x));\n\tconst top = Math.max(0, Math.min(buffer, rect.y));\n\tconst right = Math.max(0, Math.min(buffer, pageWidth - rect.x - rect.width));\n\tconst bottom = Math.max(0, Math.min(buffer, pageHeight - rect.y - rect.height));\n\n\t// Clamp to non-negative origins: an element positioned partially off the top or left of the\n\t// document has a negative page-relative rect, and Puppeteer rejects a screenshot clip with\n\t// negative x/y.\n\treturn {\n\t\tx: Math.max(0, rect.x - left),\n\t\ty: Math.max(0, rect.y - top),\n\t\twidth: rect.width + left + right,\n\t\theight: rect.height + top + bottom,\n\t};\n}\n"],"mappings":";AAOO,SAAS,aACf,MACA,WACA,YACA,QACO;AACP,QAAM,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,QAAQ,KAAK,CAAC,CAAC;AACjD,QAAM,MAAM,KAAK,IAAI,GAAG,KAAK,IAAI,QAAQ,KAAK,CAAC,CAAC;AAChD,QAAM,QAAQ,KAAK,IAAI,GAAG,KAAK,IAAI,QAAQ,YAAY,KAAK,IAAI,KAAK,KAAK,CAAC;AAC3E,QAAM,SAAS,KAAK,IAAI,GAAG,KAAK,IAAI,QAAQ,aAAa,KAAK,IAAI,KAAK,MAAM,CAAC;AAK9E,SAAO;AAAA,IACN,GAAG,KAAK,IAAI,GAAG,KAAK,IAAI,IAAI;AAAA,IAC5B,GAAG,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG;AAAA,IAC3B,OAAO,KAAK,QAAQ,OAAO;AAAA,IAC3B,QAAQ,KAAK,SAAS,MAAM;AAAA,EAC7B;AACD;","names":[]}
1
+ {"version":3,"sources":["../src/clip.ts","../src/contrast.ts"],"sourcesContent":["import type { Rect } from \"./adaptor\";\n\n/**\n * A screenshot clip framing `rect` with up to `buffer` pixels of padding on each side, shrunk where\n * the page edges leave less room. The padding allows for indicators drawn just outside the element\n * box (outlines, shadows) and for anti-aliasing.\n */\nexport function bufferedClip(\n\trect: Rect,\n\tpageWidth: number,\n\tpageHeight: number,\n\tbuffer: number,\n): Rect {\n\tconst left = Math.max(0, Math.min(buffer, rect.x));\n\tconst top = Math.max(0, Math.min(buffer, rect.y));\n\tconst right = Math.max(0, Math.min(buffer, pageWidth - rect.x - rect.width));\n\tconst bottom = Math.max(0, Math.min(buffer, pageHeight - rect.y - rect.height));\n\n\t// Clamp to non-negative origins: an element positioned partially off the top or left of the\n\t// document has a negative page-relative rect, and Puppeteer rejects a screenshot clip with\n\t// negative x/y.\n\treturn {\n\t\tx: Math.max(0, rect.x - left),\n\t\ty: Math.max(0, rect.y - top),\n\t\twidth: rect.width + left + right,\n\t\theight: rect.height + top + bottom,\n\t};\n}\n","export type Rgb = readonly [number, number, number];\n\n// Computed colours serialise as `rgb()` or `rgba()` with comma separators for sRGB values. Colours\n// authored in other spaces (oklch, display-p3) keep their own notation and are not parsed.\nconst RGB_PATTERN = /^rgba?\\(\\s*([\\d.]+),\\s*([\\d.]+),\\s*([\\d.]+)(?:,\\s*([\\d.]+))?\\s*\\)$/;\n\n/**\n * Parse a computed `rgb()` or `rgba()` colour, or return null when it is translucent or in another\n * notation.\n */\nexport function parseOpaqueRgb(value: string): Rgb | null {\n\tconst match = RGB_PATTERN.exec(value.trim());\n\n\tif (!match) {\n\t\treturn null;\n\t}\n\n\tif (match[4] !== undefined && Number(match[4]) < 1) {\n\t\treturn null;\n\t}\n\n\treturn [Number(match[1]), Number(match[2]), Number(match[3])];\n}\n\nfunction linearise(channel: number): number {\n\tconst c = channel / 255;\n\n\treturn c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n}\n\n/**\n * The WCAG relative luminance of an sRGB colour, from 0 (black) to 1 (white).\n */\nexport function relativeLuminance([r, g, b]: Rgb): number {\n\treturn 0.2126 * linearise(r) + 0.7152 * linearise(g) + 0.0722 * linearise(b);\n}\n\n/**\n * The WCAG contrast ratio between two colours, from 1 to 21.\n */\nexport function contrastRatio(a: Rgb, b: Rgb): number {\n\tconst la = relativeLuminance(a);\n\tconst lb = relativeLuminance(b);\n\n\treturn (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);\n}\n"],"mappings":";AAOO,SAAS,aACf,MACA,WACA,YACA,QACO;AACP,QAAM,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,QAAQ,KAAK,CAAC,CAAC;AACjD,QAAM,MAAM,KAAK,IAAI,GAAG,KAAK,IAAI,QAAQ,KAAK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,6 +1,6 @@
1
1
  {
2
2
  "name": "@a11y-pulse/browser-adaptor",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Shared browser adaptor primitives and DOM helpers for A11y Pulse accessibility audits.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -66,7 +66,7 @@
66
66
  },
67
67
  "peerDependencies": {
68
68
  "playwright-core": ">=1.40",
69
- "puppeteer": "^25.12.0"
69
+ "puppeteer": "^25.14.0"
70
70
  },
71
71
  "peerDependenciesMeta": {
72
72
  "playwright-core": {
@@ -78,7 +78,7 @@
78
78
  },
79
79
  "devDependencies": {
80
80
  "happy-dom": "^21.0.1",
81
- "playwright-core": "^1.63.0",
82
- "puppeteer": "^25.12.0"
81
+ "playwright-core": "^1.64.1",
82
+ "puppeteer": "^25.14.0"
83
83
  }
84
84
  }