import { Prefix } from '../constants'; import { getVarName, hexToRgb, rgbToHsl } from '../helpers'; import { GumColorVarGenerator } from '../models'; /** * Generates color palette based on the base color variables */ export const generateColorVariations: GumColorVarGenerator = (colors) => { const variations: string[] = []; for (const key in colors) { if (colors.hasOwnProperty(key)) { const [r, g, b] = hexToRgb(colors[key]); const [h, s, l] = rgbToHsl(r, g, b); const baseLuminosity = l % 10; const baseVarName = getVarName(Prefix.color, key); for (let i = 0; i <= 10; i++) { const newL = Math.round((baseLuminosity + i * 10) * 100) / 100; variations.push( `${baseVarName}-${i + 1}: ${h}, ${s}%, ${newL > 100 ? 100 : newL}%;`, ); } } } return variations; };