A scientifically accurate color palette generator that creates perceptually uniform color scales using LAB color space mathematics.
Based on the "Simplest Color Balance" research paper, SurfaceLab uses LAB color space for perceptually uniform lightness distribution, ensuring mathematically consistent and visually smooth color progressions across all scales.
- Scientific Algorithm: Perceptually uniform lightness scaling using LAB color space
- Real-time Generation: Instant palette updates as you adjust parameters
- Multiple Export Formats: CSS custom properties, JSON, and SVG
- Responsive Design: Works seamlessly on desktop and mobile
- Accessibility: Keyboard navigation and screen reader support
- Modular Architecture: Clean, maintainable, and testable codebase
- Clone or download this repository
- Open
index.htmlin a modern web browser - Choose a base color using the color picker or hex input
- Set the number of steps (5-50 colors)
- Generate your palette and export in your preferred format
SurfaceLab/
├── index.html # Main application
├── assets/
│ ├── css/
│ │ ├── variables.css # Design tokens
│ │ ├── base.css # Base styles
│ │ ├── components.css # Component styles
│ │ └── main.css # CSS entry point
│ └── js/
│ ├── core/
│ │ ├── colorScience.js # Core color algorithms
│ │ └── paletteGenerator.js # Palette generation logic
│ ├── utils/
│ │ ├── exportUtils.js # Export functionality
│ │ └── validators.js # Input validation
│ ├── ui/
│ │ ├── ui.js # UI controller
│ │ └── notifications.js # Notification system
│ └── main.js # Application entry point
└── README.md
The heart of SurfaceLab - contains all color space conversion mathematics:
- sRGB ↔ Linear RGB: Gamma correction handling
- RGB ↔ XYZ: CIE 1931 color space (D65 illuminant)
- XYZ ↔ LAB: Perceptually uniform color space
- Hex utilities: Web-safe color format handling
Implements the scientific palette generation algorithm:
- Convert base color to LAB space
- Calculate optimal position based on lightness
- Generate colors with linear lightness distribution
- Preserve hue and chroma, vary only lightness
// Generate a 20-step palette from blue
const palette = PaletteGenerator.generateUniformScale("#3b82f6", 20);
// Each color object contains:
// {
// hex: '#1a1a2e',
// name: 'color-950',
// isBase: false,
// lightness: 15
// }When running locally, access the development API:
// Available in browser console
window.SurfaceLab.test.generatePalette("#ff0000", 10);
window.SurfaceLab.test.hexToLab("#3b82f6");:root {
--color-1000: #0a0a0f; /* L*: 5 */
--color-950: #1a1a2e; /* L*: 15 */
--color-900: #2a2a4e; /* L*: 25 */
/* ... */
}{
"color-1000": {
"hex": "#0a0a0f",
"lightness": 5,
"isBase": false
}
}Ready-to-use SVG with proper color metadata for design tools.
- Algorithm Isolation: Color science is completely independent
- Single Responsibility: Each module does one thing well
- Testability: Every module can be tested in isolation
- Progressive Enhancement: HTML works without JS
main.js (orchestrator)
├── ui.js → colorScience.js
├── exportUtils.js → (no dependencies)
└── paletteGenerator.js → colorScience.js
- Palette Generation: < 100ms for 50 steps
- Initial Load: < 2 seconds
- UI Interactions: < 16ms (60fps)
- Chrome 80+
- Firefox 75+
- Safari 13+
- Edge 80+
Requires ES6 modules support.
- Input: sRGB hex colors (#rrggbb)
- Processing: CIE LAB (D65 illuminant)
- Output: sRGB hex colors
- Minimum: L* = 5 (very dark, not pure black)
- Maximum: L* = 95 (very light, not pure white)
- Distribution: Linear interpolation for perceptual uniformity
- Automatic chroma reduction for out-of-gamut colors
- Preserves hue while ensuring valid sRGB output
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
- Use ES6+ features
- Follow JSDoc commenting
- Maintain module isolation
- Write tests for new features
MIT License - feel free to use in personal and commercial projects.
- "Simplest Color Balance" research paper
- CIE LAB color space specification
- sRGB color space standard (IEC 61966-2-1)
SurfaceLab v2.0 - Where color science meets practical design tools.