Package Exports
- hextimator
- hextimator/cli
- hextimator/react
- hextimator/tailwind.css
Readme
hextimator
One color in, whole theme out.
Your customers pick a brand color. Your app looks good. Every time. No manual tuning, no edge cases where "that shade of yellow" breaks your UI.
- Ship white-labeling without the design overhead — generate per-tenant branded themes at runtime from a single input color. No design review per customer.
- Every color just works — perceptually uniform color science (OKLCH) means electric blue looks as balanced as muted olive. No hue gets special treatment.
- Accessible by default — every foreground meets AAA contrast against its background, light and dark mode included.
hextimator.com — try it in the playground.
Installation
Add to your project:
npm i hextimatorOr quickly get a one-off theme:
npx hextimator "#ff6677"Quick start
import { hextimate } from "hextimator";
const theme = hextimate("#6A5ACD").format();With a preset
Presets configure hextimator for a specific framework in one call:
import { hextimate, presets } from "hextimator";
// shadcn/ui — generates --background, --primary, --destructive, etc.
const theme = hextimate("#6366F1")
.preset(presets.shadcn)
.format();Presets set sensible defaults but you can override anything in .format():
const theme = hextimate("#6366F1")
.preset(presets.shadcn)
.format({ colors: "hsl-raw" }); // older shadcn formatSee Presets for the full list and how to create your own.
Two-step API: generate, then format
hextimator separates palette generation (color math) from formatting (output shape). This lets you extend the palette before choosing how to serialize it.
const theme = hextimate("#6A5ACD")
.format({ as: "css", colors: "oklch" });Output formats
All formats return { light: { ... }, dark: { ... } }.
"object"(default) — plain keys:accent,accent-strong, …"css"— CSS custom properties:--accent,--accent-strong, …"tailwind"— nested tokens:{ accent: { DEFAULT, strong, … } }"tailwind-css"—@themeblock with--color-accent,--color-accent-strong, …"scss"— SCSS variables:$accent,$accent-strong, …"json"— JSON string of the plain object
Color value formats
colors |
Example output |
|---|---|
"hex" (default) |
"#6a5acd" |
"oklch" |
"oklch(0.54 0.18 276)" |
"oklch-raw" |
"0.54 0.18 276" |
"rgb" |
"rgb(106, 90, 205)" |
"rgb-raw" |
"106 90 205" |
"hsl" |
"hsl(248, 53%, 58%)" |
"hsl-raw" |
"248 53% 58%" |
"p3" |
"color(display-p3 0.39 0.34 0.79)" |
"p3-raw" |
"0.39 0.34 0.79" |
Flexible input
hextimate("#FF6666"); // hex string
hextimate("rgb(255, 102, 102)"); // CSS function
hextimate([255, 102, 102]); // RGB tuple
hextimate(0xff6666); // numeric hexNote on alpha: Alpha values are intentionally ignored —
rgba(255, 0, 0, 0.5)is treated as fully opaquergb(255, 0, 0). Alpha tokens undermine accessibility guarantees because contrast ratios depend on the background, which hextimator does not control.
How it works
- Parse any color input into a normalized
Colorobject. - Convert to OKLCH (perceptual color space) so lightness and chroma adjustments look uniform across hues.
- Generate accent, base, and semantic color scales — each with DEFAULT, strong, weak, and foreground variants.
- Gamut-map back to sRGB via binary-search chroma reduction (preserves lightness and hue).
- Format into your chosen output (CSS vars, Tailwind, SCSS, JSON, or plain object).
Utilities
hextimator also exports its parsing and conversion functions for standalone use:
import { parseColor, convertColor } from "hextimator";
const color = parseColor("rgb(255, 102, 102)");
const oklch = convertColor(color, "oklch");Documentation
- Extending the palette —
addRole,addVariant,addToken - Presets — drop-in configs for shadcn/ui, or create your own
- Multiple themes — dynamic theming and
.fork() - Customization — generation and format options reference
- Color vision deficiency — simulate and adapt for CVD
- React —
useHextimatorhook, provider, dark mode strategies - Tailwind CSS v4 — setup and usage with Tailwind
- Real-world examples — shadcn/ui, Stripe, Slack configurations
Contributing
Issues and PRs are welcome at github.com/fgrgic/hextimator.