Colore JS

Search documentation

Find a function or jump to a section.
v2.0.1

inspectCssTheme

inspectCssTheme reads a stylesheet and tells you what its color theme is made of: which kind of theme it is, which modes it covers, what the brand color is, and what a complete theme would still need. Use it before you change a theme, so the change fits the file you already have.

Example

import { inspectCssTheme } from 'colore-js';

const css = `:root {
  --bg: #ffffff;
  --text: #17212b;
  --brand: #4f46e5;
}`;

const theme = inspectCssTheme(css);

console.log(theme.kind, theme.format, theme.modes.join(', '));
console.log(theme.brand?.token, theme.brand?.hex, theme.brand?.look);
console.log(theme.missing);
css-variables hex light
--brand #4f46e5 common-default
[ 'dark mode', 'success and warning colors (optional)' ]

The indigo matches Colore’s common-default category. The report also shows that the stylesheet has only a light theme.

Syntax

inspectCssTheme(css: string): ThemeReport

Parameters

NameTypeDescription
cssstringThe contents of a stylesheet, such as globals.css.

Returns

A ThemeReport:

PropertyDescription
kind'shadcn', 'tailwind', 'css-variables' or 'none'.
formatThe main value format: 'oklch', 'hex', 'rgb', 'hsl' or 'hsl-channels' (shadcn/ui v3). Can also be 'other', 'mixed' or 'none'.
modesThe modes the file defines: 'light', 'dark' or both.
scopesThe first selector that holds colors for each mode, such as :root, .dark or @theme.
tokensEvery color token with its name (without --), its group and its original values per mode. References such as var(--primary) are left out.
brandThe brand token, its original light and dark values, hex and oklch conversions, and a look.
missingWhat a complete theme still needs, such as dark mode or shadcn/ui chart colors.

brand.look is 'neutral' for a gray brand or an untouched shadcn/ui primary from any base color, Slate and Gray included, 'common-default' for a saturated indigo to purple brand, and 'custom' for anything else.

Usage

Token groups are the same ones applyThemeToCss and adjustCssVariables accept, so the report tells you exactly which group to change. To check contrast in the same file, use auditCssVariables.

The Colore CLI runs this check across a whole project with colore inspect, and also lists colors hard-coded in components.