yumush
Clone
https://git.tahinli.com/Tahinli/yumush.git
0 watching0 forksRustAGPL-3.010.6 MiB02871e1Tahinli9 hours ago415 commits
| 1 | import tokens from "./tokens.toml"; |
| 2 | |
| 3 | const out: string[] = []; |
| 4 | const scales = ["space", "radius", "stroke", "text", "size", "leading"] as const; |
| 5 | out.push(":root{" + scales.flatMap(scale => Object.entries(tokens[scale]).map(([name, value]) => `--${scale}-${name}:${value}${scale === "leading" ? "" : "px"}`)).join(";") + "}"); |
| 6 | const themes = Object.entries(tokens.theme) as [string, Record<string, string | boolean | string[]>][]; |
| 7 | themes.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 | }); |
| 13 | await Bun.write(new URL("./tokens.css", import.meta.url), out.join("\n") + "\n"); |