59 lines
2.0 KiB
JavaScript
59 lines
2.0 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import { readFile, mkdir, writeFile } from "node:fs/promises";
|
|
import { concepts, tokensFor, cssVars } from "../concepts/registry.js";
|
|
assert.equal(concepts.length, 6);
|
|
assert.equal(new Set(concepts.map((c) => c.layout)).size, 6);
|
|
const luminance = (hex) =>
|
|
hex
|
|
.match(/\w\w/g)
|
|
.map((x) => parseInt(x, 16) / 255)
|
|
.map((x) => (x <= 0.04045 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4))
|
|
.reduce((s, v, i) => s + v * [0.2126, 0.7152, 0.0722][i], 0);
|
|
const contrast = (a, b) => {
|
|
const x = luminance(a),
|
|
y = luminance(b);
|
|
return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05);
|
|
};
|
|
for (const c of concepts)
|
|
for (const theme of ["light", "dark"])
|
|
for (const density of ["compact", "normal", "relaxed"]) {
|
|
const t = tokensFor(c.id, theme, undefined, density);
|
|
for (const bg of ["color.bg", "color.surface"])
|
|
for (const fg of [
|
|
"color.text",
|
|
"color.muted",
|
|
"color.danger",
|
|
"color.success",
|
|
"color.accent",
|
|
])
|
|
assert.ok(
|
|
contrast(t[fg], t[bg]) >= 4.5,
|
|
`${c.id}/${theme}/${fg} contrast ${contrast(t[fg], t[bg])}`,
|
|
);
|
|
assert.ok(contrast(t["color.accent"], t["color.on-accent"]) >= 4.5);
|
|
}
|
|
for (const c of concepts)
|
|
for (const theme of ["light", "dark"]) {
|
|
const tokens = tokensFor(c.id, theme);
|
|
await mkdir(`tokens/${c.id}`, { recursive: true });
|
|
await writeFile(
|
|
`tokens/${c.id}/${theme}.json`,
|
|
JSON.stringify(tokens, null, 2) + "\n",
|
|
);
|
|
await writeFile(
|
|
`tokens/${c.id}/${theme}.css`,
|
|
`:root {\n${cssVars(tokens)}\n}\n`,
|
|
);
|
|
}
|
|
for (const file of [
|
|
"playground/index.html",
|
|
"playground/frame.html",
|
|
"components/system.css",
|
|
"playground/frame.js",
|
|
"playground/gallery.js",
|
|
])
|
|
assert.ok((await readFile(file, "utf8")).length > 100);
|
|
console.log(
|
|
"PASS: six layout grammars, 36 token sets, default text contrast, generated CSS/JSON.",
|
|
);
|