Color Atlas Gen Developer Reference
Published May 25, 2026 - Updated May 25, 2026
Overview
tool/color-altas-gen/package.json defines cosmic-color-engine, version 1.0.0, ESM type: module, with src/index.js as the main entry and cosmic-engine mapped to src/cli.js.
1. Package contract
+
tool/color-altas-gen/package.json defines cosmic-color-engine,
version 1.0.0, ESM type: module, with
src/index.js as the main entry and cosmic-engine mapped to
src/cli.js.
Dependencies are intentionally small: commander for CLI parsing,
js-yaml for YAML config files and ajv for JSON Schema validation.
The package has no build step.
Public exports from src/index.js are DEFAULT_CONFIG,
CONFIG_SCHEMA, resolveConfig, loadConfigFile,
deepMerge, validateConfig, generateColorUniverse and
createColorUniverse.
2. CLI entry and overrides
+
src/cli.js defines the cosmic-engine generate command with Commander.
parseCLIOverrides(opts) converts flags into partial config objects.
| Flag | Config Impact |
|---|---|
--samples, --dimension |
Override dataset.sample_count and dataset.dimension. |
--spectral, --lighting, --atmosphere, --astronomy |
Enable the corresponding top-level engines. |
--time-cycle |
Sets time.simulate_day_cycle. |
--accessibility |
Enables WCAG contrast and CVD simulation for Protanopia, Deuteranopia and Tritanopia. |
--art, --ai-labels |
Enable art metadata and AI label groups. |
--formats, --compression |
Override export formats and compression label. |
--workers, --gpu |
Set performance config values; current generation remains single-process JavaScript. |
The action resolves config from file plus CLI overrides, validates it and calls
generateColorUniverse(config, { outputDir: opts.output }). Errors are printed and
exit with status 1.
3. Config system
+
DEFAULT_CONFIG defines the baseline: one million samples, 3D dataset metadata,
RGB, HEX, HSL, Lab, OKLab, OKLCH and XYZ enabled, perception brightness/chroma/Delta E 2000
enabled and JSON export.
loadConfigFile(filePath) reads JSON, YAML or YML. deepMerge(target, source)
recursively merges objects, replaces arrays and leaves the target object untouched.
resolveConfig() applies defaults, file config, CLI overrides and API options in
that priority order.
CONFIG_SCHEMA rejects unknown top-level keys and unknown nested keys because each
section uses additionalProperties: false. It validates dimensions, wavelength
ranges, scattering model names, CVD type names, export formats and compression labels.
4. Orchestrator pipeline
+
generateColorUniverse(config, { outputDir }) in
src/orchestrator.js is the central pipeline:
- Generate base samples with
generateDataset(). - Attach requested color spaces with
computeColorSpaces(). - Optionally compute spectral data.
- Optionally compute lighting data.
- Optionally compute time-cycle data.
- Optionally compute atmosphere data.
- Optionally compute astronomy data.
- Optionally enrich samples with perception metrics.
- Optionally enrich samples with accessibility metrics.
- Optionally enrich samples with art metadata.
- Optionally enrich samples with AI labels.
- Assemble the atlas and export results.
The returned atlas always includes meta and samples. Optional
top-level sections are attached only when their engines run.
5. Dataset and Color-space engines
+
generateDataset(config) creates sample_count random RGB records shaped
as { id, r, g, b }. The current generator does not seed randomness and does not yet
use dimension, spatial resolution, time steps or neighbor metadata beyond logging.
computeColorSpaces(samples, config) shallow-copies each sample and conditionally
adds HEX, HSL, XYZ, CIE Lab, OKLab, OKLCH and CMYK. Important helpers include sRGB inverse
companding, the D65 RGB-to-XYZ matrix, CIE Lab f(t) conversion, OKLab LMS matrices
and basic CMYK decomposition.
Downstream engines assume their upstream color spaces exist. For example, Delta E metrics need Lab, OKLab chroma needs OKLab and art or AI label selection uses HSL hue and lightness.
6. Scientific Top-level engines
+| Engine | Implementation Notes |
|---|---|
spectral.js |
Generates wavelength bands, approximate RGB, frequency, photon energy and Gaussian SPD values. Uses speed of light and Planck constant. |
lighting.js |
Maps known illuminants to CCT and uses a Tanner Helland style CCT-to-RGB approximation. Also generates day-cycle CCT steps. |
atmosphere.js |
Uses lookup data for Earth, Mars, Venus and Titan and simplified Rayleigh and Mie scattering factors. |
astronomy.js |
Uses Wien's law for blackbody peak wavelength and optional OBAFGKM stellar-class lookup data. |
7. Sample enrichment engines
+
perception.js can add relative luminance, OKLab chroma, HSL vividness, Delta E
1976, Delta E 1994, simplified Delta E 2000 and a rough perceptual-uniformity score based on
distance from the L* 50 midpoint.
accessibility.js adds WCAG contrast against white and black, AA and AAA booleans
and optional Protanopia, Deuteranopia and Tritanopia simulation matrices.
art.js deterministically maps hue and lightness to emotion, art movement, design
tags and palette harmony hue relationships. aiLabels.js adds arousal/valence,
mood categories and design usage labels from deterministic hue/lightness formulas.
8. Export Engine
+
exportResults(atlas, config, outputDir) creates the output directory and writes
every requested format.
| Format | File | Behavior |
|---|---|---|
JSON |
color-atlas.json |
Streams meta, optional top-level sections and samples to JSON. |
CSV |
color-atlas.csv |
Flattens nested sample objects with dot-notation columns and streams rows. |
Parquet |
color-atlas.parquet.stub |
Writes a notice that optional Parquet support is not installed. |
Arrow |
color-atlas.arrow.stub |
Writes a notice that optional Arrow IPC support is not installed. |
compression and chunk_size are logged and validated. Actual gzip,
zstd and lz4 compression is not implemented in the current exporter.
9. Color library data and tests
+
The browser Color Library (library/color/color-library.js) loads /data/color-atlas/atlas-index.json
and sharded /data/color-atlas/detail/ files, which scripts/generate-color-atlas-index.mjs
builds from /data/color-atlas/color-atlas.json. That JSON currently contains 8,192 generated
samples with color spaces, perception, accessibility, art metadata and AI labels. If the
generated schema changes, regenerate the index and update the browser viewer and docs together.
The package test suite uses Node's built-in node:test. It covers config merge,
schema validation, engine behavior and integration generation. The integration tests write to
test_output_integration and clean it up afterward.
cd tool/color-altas-gen
npm test
10. Maintenance checklist
+- Keep
README.md, examples, schema and this documentation aligned when config fields change. - When adding an engine, export it from
src/engines/index.js, wire it in the orchestrator and add config schema fields. - When adding a per-sample field, update CSV flattening expectations and the Color Library viewer if it displays that field.
- When making dataset generation deterministic, document seed behavior and treat it as a data-version change.
- When implementing real compression, update exporter docs and tests for gzip, zstd and lz4 artifacts.
- When implementing Parquet or Arrow, replace stub tests with real file validation.
- Run
npm testintool/color-altas-genand the root site validation after docs or generated discovery files change.
For workflow-level usage, see the Color Atlas Gen User Guide.