UNPKG

shadecli

Version:

CLI tool to generate Tailwind color palettes and update Tailwind config files

42 lines 1.61 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateColorShades = void 0; const chroma_js_1 = __importDefault(require("chroma-js")); /** * Generates a series of color shades from light to dark, including a base color. * @param color - The primary color in HEX or RGB format. * @returns An object representing the color shades. */ function generateColorShades(color) { if (!chroma_js_1.default.valid(color)) { throw new Error('Invalid color format'); } // Generate a color scale using the base color and creating a smooth transition from light to dark const scale = chroma_js_1.default .scale([ (0, chroma_js_1.default)(color).set('hsl.l', 0.9).hex(), color, (0, chroma_js_1.default)(color).set('hsl.l', 0.1).hex(), // Darker shade ]) .mode('lab') // Lab mode for smoother color transitions .colors(10); // Generate 10 shades in the scale // Map the generated scale to the shade values, with base at index 5 const shades = { '50': scale[0], '100': scale[1], '200': scale[2], '300': scale[3], '400': scale[4], '500': scale[5], '600': scale[6], '700': scale[7], '800': scale[8], '900': scale[9], // Darkest }; return shades; } exports.generateColorShades = generateColorShades; //# sourceMappingURL=colorGenerator.js.map