Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug report: New CSS color formats/syntax unknown #297

Closed
brandonmcconnell opened this issue May 4, 2022 · 4 comments · Fixed by #352 · May be fixed by WontonSam/style-dictionary#218 or WontonSam/style-dictionary#247
Closed

Bug report: New CSS color formats/syntax unknown #297

brandonmcconnell opened this issue May 4, 2022 · 4 comments · Fixed by #352 · May be fixed by WontonSam/style-dictionary#218 or WontonSam/style-dictionary#247
Labels
Milestone

Comments

@brandonmcconnell
Copy link

brandonmcconnell commented May 4, 2022

I am getting this error when using a very common (newer) CSS color syntax.

The errors

  • rgb(255 0 0) throws Uncaught Error: unknown format: rgb(255 0 0)
  • rgb(255 0 0 / .5) throws Uncaught Error: unknown format: rgb(255 0 0 / .5)
  • hsl(240deg 100% 50%) throws Uncaught Error: unknown format: hsl(240deg 100% 50%)
  • hsl(240deg 100% 50% / 25%) throws Uncaught Error: unknown format: hsl(240deg 100% 50% / 25%)

These would be their older equivalents

  • rgb(255, 0, 0) → * rgb(255 0 0)
  • rgba(255, 0, 0, .5) → * rgb(255 0 0 / .5)
  • hsl(240, 100%, 50%) → * hsl(240deg 100% 50%)
  • hsla(240, 100%, 50%, .25) → * hsl(240deg 100% 50% / 25%)

This new syntax and its different nuances should be supported. In many browsers, this new color syntax is already the default.

Gotchas

  • The final & fourth value in this new syntax (alpha channel) is a percent which can be represented either as a decimal or as a full percent, so both .25 and 25% are accepted values and are treated the same.
  • All modern browsers appear to support this new syntax even when used with the old color function keywords (e.g. rgb vs. rgba), so these would also work and be treated the same:
    • hsla(240, 100%, 50%, .25) === hsla(240deg 100% 50% / .25) === hsl(240deg 100% 50% / .25)
@wawyed
Copy link

wawyed commented Aug 12, 2022

Is this something that could be looked at? @gka

@Ambient-Impact
Copy link

I'd open a pull request if I had more experience with this package and colours in general. This really tripped me up when trying to debug why https://github.com/larsenwork/postcss-easing-gradients was failing on certain colour values, and specifically hsl()/hsla() that had the deg unit. Maybe I'll come back to this on another day and give it a shot.

@akicho8
Copy link

akicho8 commented Mar 5, 2023

I'm struggling with the same issue.
I've been using chroma.js in many places as it's very convenient.
However, it's difficult to migrate to a new format because chroma.js doesn't support it yet.

@gka
Copy link
Owner

gka commented Aug 17, 2024

I believe this is fixed in v3.0.0 which got released today. We also added support for parsing lab(), lch(), oklab(), and oklch() CSS colors.

However, I just saw that the alpha channel is also supported as a percentage, which chroma.js currently does not support. Will leave this open until the full syntax is supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment