diff options
| author | netop://ウィビ <paul@webb.page> | 2026-04-25 12:29:59 -0700 |
|---|---|---|
| committer | netop://ウィビ <paul@webb.page> | 2026-04-25 12:29:59 -0700 |
| commit | dc5fff0c0afdf832b9b000e13ddc633f72749e01 (patch) | |
| tree | 5730bd4ea089dadbc9c7f057a3988104fb662827 /scripts/generate.ts | |
| parent | a2118aa39a00e02cdf3f6c306e17fd04676ea518 (diff) | |
| download | uchu-dc5fff0c0afdf832b9b000e13ddc633f72749e01.tar.gz uchu-dc5fff0c0afdf832b9b000e13ddc633f72749e01.zip | |
fantastic update
Diffstat (limited to '')
| -rw-r--r-- | scripts/generate.ts | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/scripts/generate.ts b/scripts/generate.ts new file mode 100644 index 0000000..f922a9d --- /dev/null +++ b/scripts/generate.ts @@ -0,0 +1,116 @@ + + + +/*** NATIVE ------------------------------------------- ***/ + +import { mkdir, writeFile } from "node:fs/promises"; + +/*** UTILITY ------------------------------------------ ***/ + +import { palette, raw, yang, yin } from "../src/colors"; +import { reduced } from "../src/index"; + +const buildScss = (): string => { + const lines: string[] = ["// Generated from src/colors.ts — do not edit by hand", ""]; + + for (const hue of Object.keys(palette).sort()) { + const shades = palette[hue as keyof typeof palette]; + + for (const shade of Object.keys(shades).sort()) { + const value = shades[Number(shade) as 1]; + lines.push(`$uchu-${hue}-${shade}-raw: ${raw[hue][shade]};`); + lines.push(`$uchu-${hue}-${shade}: ${value};`); + } + + lines.push(""); + } + + lines.push(`$uchu-yang: ${yang};`); + lines.push(`$uchu-yin: ${yin};`); + lines.push(""); + lines.push(":root {"); + + for (const hue of Object.keys(palette).sort()) { + const shades = palette[hue as keyof typeof palette]; + + for (const shade of Object.keys(shades).sort()) { + lines.push(` --uchu-${hue}-${shade}-raw: #{$uchu-${hue}-${shade}-raw};`); + lines.push(` --uchu-${hue}-${shade}: #{$uchu-${hue}-${shade}};`); + } + } + + lines.push(` --uchu-yang: #{$uchu-yang};`); + lines.push(` --uchu-yin: #{$uchu-yin};`); + lines.push("}", ""); + + return lines.join("\n"); +}; + +const buildCss = (): string => { + const lines: string[] = ["/* Generated from src/colors.ts — do not edit by hand */", "", ":root {"]; + + for (const hue of Object.keys(palette).sort()) { + const shades = palette[hue as keyof typeof palette]; + + for (const shade of Object.keys(shades).sort()) { + const value = shades[Number(shade) as 1]; + lines.push(` --uchu-${hue}-${shade}-raw: ${raw[hue][shade]};`); + lines.push(` --uchu-${hue}-${shade}: ${value};`); + } + } + + lines.push(` --uchu-yang: ${yang};`); + lines.push(` --uchu-yin: ${yin};`); + lines.push("}", ""); + + return lines.join("\n"); +}; + +const buildCssReduced = (): string => { + const lines: string[] = ["/* Generated from src/index.ts — do not edit by hand */", "", ":root {"]; + + for (const hue of Object.keys(reduced).sort()) { + const shades = reduced[hue as keyof typeof reduced]; + + for (const shade of Object.keys(shades).sort()) { + const value = shades[Number(shade) as 1]; + + switch(Number(shade)) { + case 1: { + lines.push(` --uchu-light-${hue}-raw: ${raw[hue][shade]};`); + lines.push(` --uchu-light-${hue}: ${value};`); + break; + } + + case 2: { + lines.push(` --uchu-${hue}-raw: ${raw[hue][shade]};`); + lines.push(` --uchu-${hue}: ${value};`); + break; + } + + case 3: { + lines.push(` --uchu-dark-${hue}-raw: ${raw[hue][shade]};`); + lines.push(` --uchu-dark-${hue}: ${value};`); + break; + } + } + } + } + + lines.push(` --uchu-yang: ${yang};`); + lines.push(` --uchu-yin: ${yin};`); + lines.push("}", ""); + + return lines.join("\n"); +}; + +/*** RUNTIME ------------------------------------------ ***/ + +await mkdir("dist", { recursive: true }); +await writeFile("dist/_palette.scss", buildScss()); +await writeFile("dist/uchu.css", buildCss()); +await writeFile("dist/uchu-reduced.css", buildCssReduced()); +await writeFile("demo/asset/style/uchu.css", buildCss()); +await writeFile("demo/asset/style/uchu-reduced.css", buildCssReduced()); + +console.log("Generated dist/_palette.scss and dist/uchu.css"); |