Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(css/scss/less): add ansi colors #109

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions scripts/builders/npm/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,33 @@ 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.name.toLowerCase()}-${ansiColorName}`;
return sprintf(" %s: %s;", name, group.hex);
}).join("\n");
},
).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);
};