const { flavors, version: versionPalette } = require('@catppuccin/palette') const { version: versionPackage } = require('./package.json') const fs = require('node:fs/promises'); const [PREFIX = ''] = process.argv.slice(2) const INDENTATION = ' ' const COLOR_TYPE_HEX = 'hex' const COLOR_TYPE_RGB = 'rgb' const COLOR_TYPE_HSL = 'hsl' const COLOR_TYPES = [COLOR_TYPE_HEX, COLOR_TYPE_RGB, COLOR_TYPE_HSL] console.log('Generating ./theme CSS files from Catppuccin palette', versionPalette) COLOR_TYPES.forEach(color_type => { console.log('Generating color type', color_type) for (const flavorKey in flavors) { const { emoji, colors, name } = flavors[flavorKey] create_theme(name, color_type, parse_theme(color_type, colors, name, emoji)) } }) function parse_theme(color_type, colors, name, emoji) { return `/* Catppuccin CSS Theme v${versionPackage} ${color_type.toUpperCase()} from palette v${versionPalette} ${emoji} ${name} */ :root { ${cssClasses(colors, color_type)} }` } async function create_theme(name, color_type, output) { try { await fs.writeFile(`./themes/Catppuccin-${name}.${color_type}.css`, output) } catch (error) { console.error(error) } } function cssClasses(colors, color_type) { const LINE_BREAK = '\n' let result = [] for (const colorKey in colors) { result.push(cssClass(colors[colorKey].name, colors[colorKey][color_type], color_type)) } return result.join(LINE_BREAK) } function cssClass(name, color, color_type) { return `${INDENTATION}--${PREFIX.length > 0 ? PREFIX + '-' : ''}${name.toLowerCase()}: ${handle_color_type(color, color_type)};` } function handle_color_type(color, color_type) { switch (color_type) { case COLOR_TYPE_RGB: const { r, g, b } = color return `rgb(${r}, ${g}, ${b})` case COLOR_TYPE_HSL: const { h, s, l } = color return `hsl(${h}, ${s}, ${l})` } return color }