Repository navigation
Conversation
liamegan
commented
Nov 26, 2026
Member
- Color.fromHSV wraps any hue, so -120 gives the same colour as 240 instead of throwing.
- Color.fromHex reads alpha from 4- and 8-digit hex, so '#ff000080' is red at about half opacity. It now throws an Error for anything that isn't hex; before, those strings gave black.
- CSS strings are now supported through a new Color.fromCSS. It reads:
- hex
- rgb() and rgba()
- hsl() and hsla(), with an optional deg on the hue
- toHex and toCSS clamp each channel to 0–1 before formatting.
- Color.fromHSV wraps any hue, so -120 gives the same colour as 240 instead of throwing. - Color.fromHex reads alpha from 4- and 8-digit hex, so '#ff000080' is red at about half opacity. It now throws an Error for anything that isn't hex; before, those strings gave black. - CSS strings are now supported through a new Color.fromCSS. It reads: - hex - rgb() and rgba() - hsl() and hsla(), with an optional deg on the hue The comma syntax (rgba(255, 136, 0, 0.5)) and the space syntax (rgb(255 136 0 / 50%)) both work, and channels can be percentages. Color.interpolate uses it for strings, so any option that takes a colour now accepts CSS strings. Named colours such as 'red' throw. - toHex and toCSS clamp each channel to 0–1 before formatting, and toCSS clamps alpha too, so they always give a valid string. The colour itself isn't changed.
| * @returns A new colour. | ||
| */ | ||
| static fromCSS(css: string): Color { | ||
| const match = /^\s*(rgba?|hsla?)\(\s*([^)]*)\)\s*$/i.exec(css); |
| if (!match) return Color.fromHex(css); | ||
|
|
||
| const fn = match[1].toLowerCase(); | ||
| const parts = match[2].split(/\s*[,/]\s*|\s+/).filter(Boolean); |
This branch has not been deployed
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.