Repository navigation
feat(common): CSS colors and color temperature - #1
Merged
Merged
Conversation
- @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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 andtransparent,rgb()/rgba(),hsl()/hsla(),hwb(),lab(),lch(),oklab(),oklch()andcolor()in its predefined spaces. It accepts both the modern and legacy (comma) syntaxes, with percentages,none, hue angles and CSS's clamping.{ 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.rgb()for other in-gamut sRGB, ascolor(srgb …)out of gamut, and otherwise as the space's own function. Every format reads back to the same value.currentcolor, system colors,light-dark(),var()) and computed ones (color-mix(), relative colors). They'reunparseable, with a message saying why.bare(on by default) also reads00aaffand0, 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 withbare: false, sobadand123aren't hex.2700 Kstays a temperature, with the color temperature as its alternative.Test plan
bun run check: typecheck plus 6,554 tests, including 175 css-color fixtures, color-temperature fixtures, round-trips and newanythingfixturesbun run build:dist/css-color/is emitted