1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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");
|