@tokenoftrust/cli 6.11.0 → 6.11.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/validate.mjs +62 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tokenoftrust/cli",
3
- "version": "6.11.0",
3
+ "version": "6.11.1",
4
4
  "description": "Token of Trust developer CLI — clone a tenant store, run it locally with save→reload, and submit it for preview. Installs the `tot` command.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Token of Trust",
package/src/validate.mjs CHANGED
@@ -17,7 +17,7 @@
17
17
  */
18
18
  import { readFileSync, existsSync, readdirSync, statSync } from "node:fs";
19
19
  import { join, relative } from "node:path";
20
- import { declaredObligations, isRegulatedCompliance, validateDeclaredConfig } from "./declared-config.mjs";
20
+ import { contrastRatio, declaredObligations, isRegulatedCompliance, validateDeclaredConfig } from "./declared-config.mjs";
21
21
  import {
22
22
  foreignTenantSegments,
23
23
  parseMappingTarget,
@@ -432,6 +432,66 @@ function validateThemeHeadings(theme, file) {
432
432
  return out;
433
433
  }
434
434
 
435
+ const THEME_HEX_RE = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
436
+ const REFERENCE_THEME_COLORS = Object.freeze({
437
+ bg: "#F4F1EA",
438
+ surface: "#FCFAF5",
439
+ text: "#1C2624",
440
+ muted: "#5C6663",
441
+ primary: "#1F3A34",
442
+ "primary-contrast": "#F4F1EA",
443
+ });
444
+ const WCAG_AA_CONTRAST = 4.5;
445
+
446
+ function hexContrastRatio(a, b) {
447
+ if (typeof a !== "string" || typeof b !== "string") return null;
448
+ const ca = a.trim();
449
+ const cb = b.trim();
450
+ if (!THEME_HEX_RE.test(ca) || !THEME_HEX_RE.test(cb)) return null;
451
+ return contrastRatio(ca, cb);
452
+ }
453
+
454
+ /**
455
+ * theme.json WCAG AA contrast: resolved foreground/background pairs (including the
456
+ * bold hero headline's `--color-primary-contrast` on `--color-primary` when
457
+ * `brand.heroVariant` is `"bold"` or omitted) must meet 4.5:1.
458
+ */
459
+ export function validateThemeContrast(theme, file) {
460
+ const out = [];
461
+ if (theme == null || typeof theme !== "object" || Array.isArray(theme)) return out;
462
+ const rawColor = theme.color && typeof theme.color === "object" && !Array.isArray(theme.color) ? theme.color : {};
463
+ const color = { ...REFERENCE_THEME_COLORS, ...rawColor };
464
+ const heroVariant = theme?.brand?.heroVariant ?? "bold";
465
+ const pairs = [
466
+ { fg: "text", bg: "bg", label: "body text (color.text on color.bg)", level: ERROR },
467
+ { fg: "text", bg: "surface", label: "surface text (color.text on color.surface)", level: ERROR },
468
+ heroVariant === "light"
469
+ ? { fg: "primary", bg: "bg", label: "light hero headline (color.primary on color.bg)", level: ERROR }
470
+ : {
471
+ fg: "primary-contrast",
472
+ bg: "primary",
473
+ label: "bold hero headline (color.primary-contrast on color.primary)",
474
+ level: ERROR,
475
+ },
476
+ { fg: "muted", bg: "bg", label: "secondary text (color.muted on color.bg)", level: WARN },
477
+ ];
478
+ for (const pair of pairs) {
479
+ const ratio = hexContrastRatio(color[pair.fg], color[pair.bg]);
480
+ if (ratio !== null && ratio < WCAG_AA_CONTRAST) {
481
+ out.push(
482
+ mk(
483
+ pair.level,
484
+ "theme-contrast",
485
+ file,
486
+ `${pair.label} contrast (${color[pair.fg]} on ${color[pair.bg]}) is ${ratio.toFixed(2)}:1 — below WCAG AA ${WCAG_AA_CONTRAST}:1`,
487
+ `adjust color.${pair.fg} or color.${pair.bg} in ${file} to achieve at least ${WCAG_AA_CONTRAST}:1 contrast`,
488
+ ),
489
+ );
490
+ }
491
+ }
492
+ return out;
493
+ }
494
+
435
495
  // Standalone published-CLI mirror. packages/cli/test/validate.test.mjs pins it
436
496
  // to extension-contract-values.mjs, the repository/runtime authority.
437
497
  export const BLOCK_PALETTE_SUPPORTED_CONTRACTS = Object.freeze([
@@ -1317,6 +1377,7 @@ export function validateTenant(tenantDir, opts = {}) {
1317
1377
  );
1318
1378
  } else {
1319
1379
  findings.push(...validateThemeHeadings(theme, rel(themePath)));
1380
+ findings.push(...validateThemeContrast(theme, rel(themePath)));
1320
1381
  }
1321
1382
  }
1322
1383