adjustCssVariables
adjustCssVariables changes how a theme feels without rebuilding it. Pick the tokens (surfaces, borders, the brand), pick a mode, and move their lightness, chroma or hue in OKLCH. Every other value in the file stays exactly as it was.
Example
Warm and lift the dark-mode surfaces:
import { adjustCssVariables } from 'colore-js';
const css = `:root {
--surface: oklch(0.94 0 0);
--brand: #0f766e;
}
.dark {
--surface: oklch(0.2 0 0);
}`;
const result = adjustCssVariables(css, {
groups: ['surfaces'],
modes: ['dark'],
lightness: '+0.03',
chroma: 0.015,
hue: 65,
});
console.log(result.css);
:root {
--surface: oklch(0.94 0 0);
--brand: #0f766e;
}
.dark {
--surface: oklch(0.23 0.015 65);
}
Syntax
adjustCssVariables(css: string, options: AdjustThemeOptions): ThemeEditResult
Options
Choose at least one group or token, and at least one channel.
A ChannelChange is a number to set the channel (0.015), a signed string to add or subtract ('+0.03', '-10'), or 'x' and a factor to scale it ('x0.8'). Grays have no hue, so give them some chroma when you tint them.
Results stay in the gamut the color started in, sRGB or Display P3.
Returns
A ThemeEditResult with the updated css and the list of changes, the same shape as applyThemeToCss.
Token groups
Recipes
An adjustment can lower contrast. Check the result with auditCssVariables and repair it with fixCssVariables, or use colore adjust from the CLI, which repairs and audits for you.