Skip to content

feat(common): CSS colors and color temperature - #1

Merged
rt2zz merged 1 commit into
mainfrom
feat/colors
Oct 3, 2026
Merged

rt2zz merged 1 commit into
mainfrom
feat/colors

Conversation

@rt2zz

@rt2zz rt2zz commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • @quantojs/common/css-color: cssColor() reads every CSS color with a value of its own: hex (3/4/6/8 digits), the 148 named colors and transparent, rgb()/rgba(), hsl()/hsla(), hwb(), lab(), lch(), oklab(), oklch() and color() in its predefined spaces. It accepts both the modern and legacy (comma) syntaxes, with percentages, none, hue angles and CSS's clamping.
    • The value is { space, coords, alpha }, kept in the space it was written in. Nothing is converted, so there's no colour-space maths and no dependency. Space names and numbers match what colorjs.io and culori take.
    • It formats as hex when the channels and alpha are whole bytes, as rgb() for other in-gamut sRGB, as color(srgb …) out of gamut, and otherwise as the space's own function. Every format reads back to the same value.
    • Left out: colors with no value of their own (currentcolor, system colors, light-dark(), var()) and computed ones (color-mix(), relative colors). They're unparseable, with a message saying why.
    • bare (on by default) also reads 00aaff and 0, 170, 255, as design tools copy them.
  • colorTemperature() in @quantojs/common: kelvins and mireds (a function unit, 10⁶/K).
  • anything() includes both. CSS colors run with bare: false, so bad and 123 aren't hex. 2700 K stays a temperature, with the color temperature as its alternative.
  • Site: both codecs in the playground and on the codecs page. Docs: DESIGN.md (new "CSS colors" section), AGENTS.md and the READMEs.

Test plan

  • bun run check: typecheck plus 6,554 tests, including 175 css-color fixtures, color-temperature fixtures, round-trips and new anything fixtures
  • bun run build: dist/css-color/ is emitted

- @quantojs/common/css-color: cssColor() reads every CSS color with a value of its own: hex, the 148
  named colors and transparent, rgb(), hsl(), hwb(), lab(), lch(), oklab(), oklch() and color() in its
  predefined spaces, in the modern and legacy syntaxes. The value is { space, coords, alpha }, kept in
  the space it was written in. It formats as hex when the channels are whole bytes, and otherwise in the
  color's own function. currentcolor, system colors, light-dark(), color-mix() and relative colors are
  unparseable, with a message saying why. `bare` (on by default) also reads 00aaff and 0, 170, 255.
- colorTemperature(): kelvins and mireds (2700 K, 153 mired), a quantity beside the other light units.
- anything() reads both: CSS colors without `bare`, and 2700 K stays a temperature, with the color
  temperature as its alternative.
- Site: both codecs in the playground and on the codecs page, under a new Colors group.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@rt2zz
rt2zz merged commit e3a755a into main Oct 3, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant