forge
Explore
Log in

Don't you dare go Hollow

yumush

Clone
★ 0

0 watching0 forksRustAGPL-3.010.6 MiB02871e1Tahinli9 hours ago415 commits

css.ts13 lines, 985 bytesHistoryRawDownload
1import tokens from "./tokens.toml";
2
3const out: string[] = [];
4const scales = ["space", "radius", "stroke", "text", "size", "leading"] as const;
5out.push(":root{" + scales.flatMap(scale => Object.entries(tokens[scale]).map(([name, value]) => `--${scale}-${name}:${value}${scale === "leading" ? "" : "px"}`)).join(";") + "}");
6const themes = Object.entries(tokens.theme) as [string, Record<string, string | boolean | string[]>][];
7themes.forEach(([name, theme], index) => {
8 const selector = index === 0 ? `:root,[data-theme=${name}]` : `[data-theme=${name}]`;
9 const colors = Object.entries(theme).filter(([key]) => key !== "dark" && key !== "hue").map(([key, value]) => `--${key}:${value}`);
10 const hues = (theme.hue as string[]).map((value, hue) => `--h-${tokens.hues[hue]}:${value}`);
11 out.push(`${selector}{color-scheme:${theme.dark ? "dark" : "light"};${[...colors, ...hues].join(";")}}`);
12});
13await Bun.write(new URL("./tokens.css", import.meta.url), out.join("\n") + "\n");