Skip to content

Commit

Permalink
wip: generate ansi css
Browse files Browse the repository at this point in the history
  • Loading branch information
sgoudham committed Nov 1, 2024
1 parent bc3215e commit 4411eaf
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions scripts/builders/npm/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,32 @@ import { ensureDir } from "std/fs/mod.ts";
import { flavorEntries } from "@catppuccin/palette";

const template = flavorEntries
.map(([flavorName, { colorEntries }]) => {
.map(([flavorName, { colorEntries, ansiColorEntries }]) => {
const colors = colorEntries
.map(([colorName, { hex, rgb, hsl: { h, s, l } }]) => {
const name = `--ctp-${flavorName}-${colorName}`;

return [
sprintf(" %s: %s;", name, hex),
sprintf(" %s-rgb: %d %d %d;", name, ...Object.values(rgb)),
sprintf(" %s-hsl: %.3f %.3f%% %.3f%%;", name, h, s * 100, l * 100),
].join("\n");
})
.join("\n");
return `:root {\n${colors}\n}`;

const ansiColors = ansiColorEntries.map(
([ansiColorName, { normal, bright }]) => {
return [normal, bright].map((group) => {
const name = `--ctp-${flavorName}-ansi-${group}-${ansiColorName}`;
return sprintf(" %s: %s;", name, group.hex);
}).join("\n");
},
);

return `:root {\n${colors}\n${ansiColors}\n}`;
})
.join("\n\n");

export const compileCss = async (outDir: string) => {
await ensureDir(`${outDir}/css`);

Deno.writeTextFile(`${outDir}/css/catppuccin.css`, template);
};

0 comments on commit 4411eaf

Please sign in to comment.