Files
github-actions[bot] 70d35bab31
Merge-upstream / merge (push) Canceled after 0s
🗽 Sync 2026-09-13 02:49:28
2026-09-13 02:49:28 +08:00

42 lines
989 B
JavaScript

/**
* Copyright (C) 2025 eamonxg <eamonxiong@gmail.com>
* Licensed under the Apache License, Version 2.0.
*/
import Color from "colorjs.io";
import { resolveMode } from "../tokens/resolve.js";
const MIN_TEXT_CONTRAST = 4.5;
const checks = [
["muted_foreground", "background"],
["sidebar_muted", "sidebar_bg"],
];
const failures = [];
for (const mode of ["light", "dark"]) {
const tokens = resolveMode(mode);
for (const [foreground, background] of checks) {
const ratio = Color.contrast(
new Color(tokens[background]),
new Color(tokens[foreground]),
"WCAG21",
);
if (ratio < MIN_TEXT_CONTRAST) {
failures.push(
`${mode}: ${foreground} on ${background} is ${ratio.toFixed(2)}:1`,
);
}
}
}
if (failures.length > 0) {
console.error(
`Text token contrast must be at least ${MIN_TEXT_CONTRAST}:1:\n${failures.join("\n")}`,
);
process.exitCode = 1;
} else {
console.log("Text token contrast meets WCAG AA.");
}