import { CSS_LENGTH_REGEX, type TCssVarsSchema } from '@documenso/lib/types/css-vars'; import { colord } from 'colord'; import { toKebabCase } from 'remeda'; export const toNativeCssVars = (vars: TCssVarsSchema) => { const cssVars: Record = {}; const { radius, ...colorVars } = vars; for (const [key, value] of Object.entries(colorVars)) { if (value) { const color = colord(value); const { h, s, l } = color.toHsl(); // Tailwind's theme.css consumes these via `hsl(var(--token))`. CSS // Color 4 space-separated `hsl()` requires `%` on saturation and // lightness — without it, the function is invalid and the property // falls back to its initial value (which is why bare numeric output // here used to silently break customer colours). cssVars[`--${toKebabCase(key)}`] = `${h} ${s}% ${l}%`; } } // Defence in depth: radius is interpolated raw into the rendered