// Erzeugt src/styles/tokens.css aus design/tokens.json (Sanamare Design System). import { readFileSync, writeFileSync } from "node:fs"; const t = JSON.parse(readFileSync(new URL("../design/tokens.json", import.meta.url))); const themes = t.color.themes.map((x) => x.id); const first = themes[0]; const colorValue = (v, theme) => { const raw = typeof v === "string" ? v : v[theme] ?? v[first]; return raw.startsWith("{") ? `var(--${raw.slice(1, -1)})` : raw; }; const themed = (v, theme) => (typeof v === "string" ? v : v[theme] ?? v[first]); const block = (theme) => { const lines = []; for (const tok of t.color.tokens) lines.push(` --${tok.name}: ${colorValue(tok.value, theme)};`); for (const tok of t.shadow?.tokens ?? []) lines.push(` --${tok.name}: ${themed(tok.value, theme)};`); return lines.join("\n"); }; let css = `/* ${t.name} — generated from design/tokens.json (npm run tokens) */\n:root {\n`; for (const [k, v] of Object.entries(t.type.families)) css += ` --font-${k}: ${v};\n`; for (const fam of ["spacing", "radius", "layout", "breakpoint"]) for (const tok of t[fam]?.tokens ?? []) css += ` --${tok.name}: ${tok.value};\n`; css += block(first) + "\n color-scheme: light;\n}\n"; for (const th of themes.slice(1)) { css += `[data-theme="${th}"] {\n${block(th)}\n color-scheme: ${th};\n background-color: var(--surface);\n color: var(--ink);\n}\n`; } for (const g of t.type.groups) { for (const s of g.styles) { const props = [ `font-family: var(--font-${g.family})`, `font-size: ${s.fontSize}`, `line-height: ${s.lineHeight}`, `font-weight: ${s.fontWeight}`, ]; if (s.letterSpacing) props.push(`letter-spacing: ${s.letterSpacing}`); if (s.fontStyle) props.push(`font-style: ${s.fontStyle}`); if (["button", "nav", "eyebrow", "wordmark"].includes(s.name)) props.push("text-transform: uppercase"); if (s.name === "eyebrow") props.push("color: var(--gold-deep)"); if (s.name.startsWith("price")) props.push("font-variant-numeric: tabular-nums"); css += `.${s.name} { ${props.join("; ")}; }\n`; } } css += `@media (max-width: 767px) { .display-xl { font-size: 44px; line-height: 1.05; } .display-lg { font-size: 34px; } }\n`; writeFileSync(new URL("../src/styles/tokens.css", import.meta.url), css); console.log("tokens.css geschrieben");