Overview
Theme Gen provides a live preview system that instantly reflects all color changes across your theme in real-time. Every color adjustment, shuffle, or theme mode toggle is immediately visible, allowing you to see exactly how your theme will look before exporting.How It Works
The live preview system uses CSS custom properties (CSS variables) to dynamically update colors across the entire interface. When you modify any color in the theme customizer, the system:- Updates the theme state in React context
- Syncs CSS variables to the DOM root element
- Reflects changes instantly across all UI components
CSS Variable System
All theme colors are exposed as CSS variables on the:root element:
Implementation Details
The live preview is powered by theupdateCSSVariables function in ThemeContext.tsx:
Every color change triggers an immediate CSS variable update, ensuring zero-latency visual feedback.
Automatic Color Derivation
When you change certain colors, Theme Gen automatically derives related colors to maintain visual harmony:Border and Muted Colors
These are automatically calculated as OKLCH mixes between text and background:- Border: 82% blend toward background
- Muted: 55% blend toward background
On-Colors
For colored surfaces like buttons, Theme Gen automatically generates contrasting “on” colors:Preview Modes
The live preview works seamlessly across both light and dark modes:Mode Switching
Toggle between light and dark modes to see how your colors adapt:adaptColorsForMode function intelligently adjusts color lightness values while preserving hues.
Persistent State
Your theme changes are automatically saved tolocalStorage and synced to the URL, ensuring your work is never lost:
The live preview state persists across page refreshes and can be shared via URL.
Performance
The live preview system is optimized for performance:- CSS variable updates are batched per theme change
- Only changed properties trigger re-renders
- No full page reloads required
- Smooth transitions between color states
Related Features
- URL Sharing - Share your live preview with others
- Color Locking - Prevent specific colors from changing
- Export - Export your previewed theme to production formats