How it works
Under the hood: color graphs, OKLCH transformations, and bidirectional theme generation.
The Pipeline
Nightfall follows a three-step pipeline: Scan → Analyze → Generate.
- Launch Playwright — visits each route in a headless browser
- Auto-Detect Direction — determines light or dark mode by analyzing background lightness in OKLCH
- DOM Walk — traverses every visible element, collecting background-color, color, border-color, box-shadow, and more
- Build Color Graph — creates a relationship map of what sits on what
- Classify Roles — assigns semantic roles (background.page, text.primary, brand.primary, etc.)
- Transform — applies OKLCH-space transformations based on direction
- Export — writes the theme in your chosen format
Color Graph
The color graph maps relationships between colors in your UI:
Page Background (#ffffff)
└── Card Surface (#f8f9fa)
├── Card Border (#e5e7eb)
├── Heading Text (#111827) → 18.1:1 contrast
├── Body Text (#374151) → 11.2:1 contrast
├── Muted Text (#9ca3af) → 4.6:1 contrast
└── Accent Button (#2563eb) → 4.8:1 contrast
└── Button Text (#ffffff)Each node knows its parent (what it sits on) and the contrast ratio between them. This graph is preserved during transformation.
OKLCH Color Space
All transformations happen in OKLCH — a perceptually uniform color space where equal numerical changes produce equal visual changes. This means a dark theme generated by Nightfall looks natural, not mathematically inverted.
- L — Lightness (0 = black, 1 = white)
- C — Chroma (saturation intensity)
- H — Hue (0-360 degrees)
Direction Detection
Nightfall auto-detects your theme direction by:
- Sampling the page background color
- Computing weighted average lightness of all background surfaces
- If average L > 0.6 → light mode → generates dark
- If average L < 0.4 → dark mode → generates light
- If ambiguous (0.4–0.6) → falls back to --direction flag