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

Use a better CSS value parser to normalize values #721

Open
nmn opened this issue Oct 9, 2024 · 0 comments
Open

Use a better CSS value parser to normalize values #721

nmn opened this issue Oct 9, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@nmn
Copy link
Contributor

nmn commented Oct 9, 2024

We currently use postcss-value-parser to parse the values used in stylex.create and normalize them. However, this is a basic parser and we're mostly limited in the normalisation we can perform to being able to strip extra white space, and sometimes drop units used with 0.

We can use a more sophisticated CSS value parser that understand CSS value types to be able to normalise many more kinds of values.

Here are a few examples:

  • rgb(0 0 0 / 50%) should be normalised to rgba(0,0,0,0.5)
  • #000000 should be normalised to #000
  • We should either convert all named CSS colours to hashes or convert hash values to named values when possible.
  • @media (width >= 768px) should be normalised to @media (min-width: 768px)
  • etc.

nmn/css-value-parser is a fairly full featured parser that I worked on specifically for this purpose.

We could also consider using lightningcss if that is a good fit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant