Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204#!/usr/bin/env node// supram palettes. Each palette is a complete colour-token set on one shared// foundation (white page, cool-neutral greys, near-black ink, near-black dark// mode): named inks, their washes, and the same role vocabulary in every file,// light and dark, with Display P3 blocks that raise chroma only. Every value// outside a P3 block is inside sRGB (chroma clamped, lightness and hue kept).//// Writes, from the data below:// css/palettes/<name>.css tokens in @layer tokens, per-hue utilities in// @layer utilities; supram.css imports the default// css/palettes/all.css every palette scoped under :root[data-palette],// for demos and pickers, never the default import// css/supram-<name>.css an entry file per non-default palette// css/palettes/CONTRAST.txt every ink against the text it takes, the page// and the surface//// Run with `npm run palettes`. Needs culori, a devDependency. To add a// palette, add an entry to `palettes` and run it again.
import { clampChroma, formatHex, wcagContrast, inGamut, converter } from "culori";import { mkdirSync, readFileSync, writeFileSync } from "node:fs";import { join, resolve } from "node:path";
const root = resolve(new URL("..", import.meta.url).pathname);const out = join(root, "css", "palettes");const DEFAULT = "riso";
const srgb = inGamut("rgb"), p3 = inGamut("p3"), toOk = converter("oklch");const fmt = (o) => `oklch(${o.l.toFixed(3)} ${o.c.toFixed(3)} ${(o.h || 0).toFixed(0)})`;function tok(l, c, h) { let col = { mode: "oklch", l, c, h }; if (!srgb(col)) col = clampChroma(col, "oklch", "rgb"); return { css: fmt(toOk(col)), hex: formatHex(col) };}function p3tok(l, c, h) { let col = { mode: "oklch", l, c, h }; if (!p3(col)) col = clampChroma(col, "oklch", "p3"); return fmt(toOk(col));}const hex = (h) => ({ css: fmt(toOk(h)), hex: h });
// Shared foundation: white page, cool-neutral greys, near-black dark.const F = { light: { bg: tok(1, 0, 0), surface: tok(0.955, 0.004, 264), fg: tok(0.18, 0.005, 264), muted: tok(0.44, 0.008, 264), hairline: tok(0.86, 0.006, 264) }, dark: { bg: tok(0.15, 0.005, 264), surface: tok(0.19, 0.007, 264), fg: tok(0.95, 0.004, 264), muted: tok(0.73, 0.008, 264), hairline: tok(0.32, 0.008, 264) },};
// Each palette: inks (name -> {light, dark, p3Light?, p3Dark?, kind: glass|ink|tint}) and roles.// A glass is a spot ink printed solid (takes the page's ink as text); an ink// is text on the page or a deep fill (takes page-coloured text); a tint is a// pale step that takes ordinary text.const palettes = { riso: { title: "Risograph on white", summary: "Three spot inks and one deep blue. Pink is the accent, yellow marks, teal is state.", inks: { "pink-glass": { light: tok(0.70, 0.22, 355), dark: tok(0.72, 0.20, 355), p3Light: p3tok(0.70, 0.28, 355), p3Dark: p3tok(0.72, 0.26, 355), kind: "glass" }, "yellow-glass": { light: tok(0.90, 0.17, 98), dark: tok(0.86, 0.15, 98), p3Light: p3tok(0.90, 0.19, 98), p3Dark: p3tok(0.86, 0.17, 98), kind: "glass" }, "teal-glass": { light: tok(0.78, 0.13, 175), dark: tok(0.76, 0.12, 175), p3Light: p3tok(0.78, 0.18, 172), p3Dark: p3tok(0.76, 0.16, 172), kind: "glass" }, "blue-ink": { light: tok(0.46, 0.17, 262), dark: tok(0.78, 0.10, 262), kind: "ink" }, }, roles: { accent: "pink-glass", link: "blue-ink", linkHover: "pink-glass", focus: "blue-ink", selection: "yellow-glass", ok: "teal-glass", warn: "yellow-glass" }, }, neon: { title: "Neon on white", summary: "dasl.ing's six gamut-edge neons as fills and marks only; black text on them; one deep teal for links.", inks: { "yellow-glass": { light: hex("#fff500"), dark: tok(0.93, 0.19, 108), p3Light: null, p3Dark: null, kind: "glass" }, "green-glass": { light: hex("#00ff75"), dark: tok(0.85, 0.22, 150), p3Light: p3tok(0.88, 0.29, 150), p3Dark: p3tok(0.85, 0.27, 150), kind: "glass" }, "blue-glass": { light: hex("#39dbff"), dark: tok(0.82, 0.13, 220), p3Light: p3tok(0.83, 0.17, 215), p3Dark: p3tok(0.82, 0.16, 215), kind: "glass" }, "purple-glass": { light: hex("#cd76ea"), dark: tok(0.70, 0.16, 315), p3Light: p3tok(0.71, 0.21, 315), p3Dark: p3tok(0.70, 0.20, 315), kind: "glass" }, "orange-glass": { light: hex("#ffb443"), dark: tok(0.80, 0.14, 70), p3Light: p3tok(0.82, 0.17, 68), p3Dark: p3tok(0.80, 0.16, 68), kind: "glass" }, "red-glass": { light: hex("#ff5e5e"), dark: tok(0.69, 0.18, 22), p3Light: p3tok(0.70, 0.23, 22), p3Dark: p3tok(0.69, 0.22, 22), kind: "glass" }, "teal-ink": { light: tok(0.48, 0.10, 220), dark: tok(0.80, 0.10, 220), kind: "ink" }, }, roles: { accent: "yellow-glass", link: "teal-ink", linkHover: "red-glass", focus: "blue-glass", selection: "yellow-glass", ok: "green-glass", warn: "orange-glass" }, }, mono: { title: "Tinted monochrome, one accent", summary: "The quietest option: the grey ramp does everything and one cobalt accent appears in three steps.", inks: { "cobalt-glass": { light: tok(0.80, 0.13, 264), dark: tok(0.78, 0.12, 264), p3Light: p3tok(0.80, 0.15, 264), p3Dark: p3tok(0.78, 0.14, 264), kind: "glass" }, "cobalt-ink": { light: tok(0.46, 0.16, 264), dark: tok(0.80, 0.11, 264), kind: "ink" }, "cobalt-tint": { light: tok(0.95, 0.035, 264), dark: tok(0.25, 0.04, 264), kind: "tint" }, }, roles: { accent: "cobalt-glass", link: "cobalt-ink", linkHover: "cobalt-glass", focus: "cobalt-ink", selection: "cobalt-glass", ok: "cobalt-glass", warn: "cobalt-tint" }, }, duotone: { title: "Two-hue duotone", summary: "Cool cobalt means navigate, inform, ok; warm vermilion means act, attend, error. Never hue alone for meaning.", inks: { "cobalt-glass": { light: tok(0.80, 0.10, 264), dark: tok(0.78, 0.10, 264), kind: "glass" }, "cobalt-ink": { light: tok(0.45, 0.19, 264), dark: tok(0.80, 0.10, 264), kind: "ink" }, "cobalt-tint": { light: tok(0.95, 0.03, 264), dark: tok(0.25, 0.04, 264), kind: "tint" }, "vermilion-glass": { light: tok(0.80, 0.13, 55), dark: tok(0.78, 0.13, 55), p3Light: p3tok(0.80, 0.16, 55), p3Dark: p3tok(0.78, 0.16, 55), kind: "glass" }, "vermilion-ink": { light: tok(0.50, 0.18, 35), dark: tok(0.78, 0.13, 45), p3Light: p3tok(0.50, 0.21, 35), kind: "ink" }, "vermilion-tint": { light: tok(0.95, 0.03, 55), dark: tok(0.26, 0.04, 55), kind: "tint" }, }, roles: { accent: "vermilion-glass", link: "cobalt-ink", linkHover: "vermilion-ink", focus: "cobalt-ink", selection: "cobalt-glass", ok: "cobalt-glass", warn: "vermilion-glass" }, },};
const hue = (k) => k.replace(/-(glass|ink|tint)$/, "");// The text an ink takes when it is a fill.const onFill = (kind, mode) => kind === "glass" ? (mode === "light" ? "var(--fg)" : "var(--bg)") : kind === "ink" ? "var(--bg)" : "var(--fg)";
function tokens(P, mode, sel, indent) { const f = F[mode], r = P.roles; const on = (name) => onFill(P.inks[name].kind, mode); let s = `${indent}${sel} {\n`; if (mode === "light") s += `${indent} color-scheme: light dark;\n`; for (const k of ["bg", "surface", "fg", "muted", "hairline"]) s += `${indent} --${k}: ${f[k].css}; /* ${f[k].hex} */\n`; s += `${indent} --subtle: var(--surface); --rule: var(--fg);\n`; if (mode === "light") s += `${indent} --black: var(--fg); --white: var(--bg); --paper: var(--surface);\n`; for (const [k, v] of Object.entries(P.inks)) s += `${indent} --${k}: ${v[mode].css}; /* ${v[mode].hex} */\n`; s += `${indent} --on-glass: ${mode === "light" ? "var(--fg)" : "var(--bg)"}; --on-ink: var(--bg);\n`; for (const [k, v] of Object.entries(P.inks)) if (v.kind === "glass") s += `${indent} --${hue(k)}-wash: color-mix(in oklab, var(--${k}) 20%, var(--bg));\n`; s += `${indent} --accent: var(--${r.accent}); --on-accent: ${on(r.accent)}; --accent-text: var(--${r.link});\n`; s += `${indent} --link: var(--${r.link}); --link-hover: var(--${r.linkHover}); --focus: var(--${r.focus});\n`; s += `${indent} --selection: var(--${r.selection}); --on-selection: ${on(r.selection)};\n`; s += `${indent} --ok: var(--${r.ok}); --on-ok: ${on(r.ok)};\n`; s += `${indent} --warn: var(--${r.warn}); --on-warn: ${on(r.warn)};\n`; for (const role of ["accent", "selection", "ok", "warn"]) s += `${indent} --${role}-wash: color-mix(in oklab, var(--${role}) 20%, var(--bg));\n`; s += `${indent}}\n`; const p3k = mode === "light" ? "p3Light" : "p3Dark"; const over = Object.entries(P.inks).filter(([, v]) => v[p3k]); if (over.length) { s += `${indent}@media (color-gamut: p3) {\n${indent} ${sel} {\n`; for (const [k, v] of over) s += `${indent} --${k}: ${v[p3k]};\n`; s += `${indent} }\n${indent}}\n`; } return s;}
// scope is "" for the bare :root, or `[data-palette="name"]`.function tokenBlocks(P, scope) { return tokens(P, "light", `:root${scope}`, " ") + `\n @media (prefers-color-scheme: dark) {\n` + tokens(P, "dark", `:root${scope}:not([data-theme="light"])`, " ") + ` }\n\n` + tokens(P, "dark", `:root${scope}[data-theme="dark"]`, " ");}
function utilities(P, scope) { const pre = scope ? `:root${scope} ` : ""; let s = ""; for (const [k, v] of Object.entries(P.inks)) { if (v.kind === "glass") { s += ` ${pre}.bg-${hue(k)} { background: var(--${k}); color: var(--on-glass); }\n`; s += ` ${pre}.bg-${hue(k)}-wash { background: var(--${hue(k)}-wash); color: var(--fg); }\n`; } else if (v.kind === "ink") { s += ` ${pre}.bg-${k} { background: var(--${k}); color: var(--on-ink); }\n`; s += ` ${pre}.fg-${k} { color: var(--${k}); }\n`; } else { s += ` ${pre}.bg-${k} { background: var(--${k}); color: var(--fg); }\n`; } } return s;}
mkdirSync(out, { recursive: true });const report = [];let all = `/* supram palettes, every one of them, each scoped under :root[data-palette="name"] so a demo or a picker can switch at runtime. Generated by scripts/palettes.mjs. Never the default import: supram.css carries one palette; this file is linked after it, when wanted. */\n\n@layer tokens {\n`;let allUtil = `@layer utilities {\n`;
for (const [name, P] of Object.entries(palettes)) { const header = `/* supram palette: ${P.title} ${P.summary} Generated by scripts/palettes.mjs from the data there; edit that, not this. Every value outside a P3 block is inside sRGB; the P3 blocks raise chroma only, so contrast is identical on every display. Imported unlayered by the entry file: the tokens land in @layer tokens, the per-hue utilities in @layer utilities. */\n\n`; const css = header + `@layer tokens {\n` + tokenBlocks(P, "") + `}\n\n@layer utilities {\n` + utilities(P, "") + `}\n`; writeFileSync(join(out, `${name}.css`), css);
all += ` /* ── ${P.title} ── */\n` + tokenBlocks(P, `[data-palette="${name}"]`) + "\n"; allUtil += ` /* ── ${P.title} ── */\n` + utilities(P, `[data-palette="${name}"]`);
if (name !== DEFAULT) { const entry = readFileSync(join(root, "css", "supram.css"), "utf8"); const needle = `@import url("palettes/${DEFAULT}.css");`; if (!entry.includes(needle)) throw new Error(`css/supram.css must import ${needle}`); writeFileSync(join(root, "css", `supram-${name}.css`), entry .replace(needle, `@import url("palettes/${name}.css");`) .replace(" Entry point.", ` Entry point for the ${P.title} palette (generated by scripts/palettes.mjs).`)); }
for (const mode of ["light", "dark"]) { const f = F[mode]; for (const [k, v] of Object.entries(P.inks)) { const textOn = v.kind === "glass" ? (mode === "light" ? f.fg.hex : f.bg.hex) : v.kind === "ink" ? f.bg.hex : f.fg.hex; const c1 = wcagContrast(v[mode].hex, textOn).toFixed(2); const c2 = wcagContrast(v[mode].hex, f.bg.hex).toFixed(2); const c3 = wcagContrast(v[mode].hex, f.surface.hex).toFixed(2); report.push(`${name.padEnd(8)} ${mode.padEnd(5)} ${k.padEnd(16)} ${v[mode].hex} text-on-it ${c1} as-text-on-bg ${c2} on-surface ${c3}`); } }}
writeFileSync(join(out, "all.css"), all + `}\n\n` + allUtil + `}\n`);writeFileSync(join(out, "CONTRAST.txt"), report.join("\n") + "\n");console.log(`wrote ${Object.keys(palettes).length} palettes to css/palettes/, all.css, and ${Object.keys(palettes).length - 1} entry files`);console.log(report.join("\n"));