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

Preserve rgb()/hsl() color format in expanded mode only #1634

Closed
nex3 opened this issue Feb 17, 2022 · 1 comment · Fixed by #1651
Closed

Preserve rgb()/hsl() color format in expanded mode only #1634

nex3 opened this issue Feb 17, 2022 · 1 comment · Fixed by #1651

Comments

@nex3
Copy link
Contributor

nex3 commented Feb 17, 2022

Now that >95% of browsers support hsl() (source) and hsla() (source), we can bring them into the set of color formats that we preserve in expanded mode for readability purposes.

This will require some amount of refactoring of how we handle "original colors". Currently we store the originalSpan and use its text to determine the actual format of the color, but this won't work for color functions where the source span may contain variable references and so on. While we could create a synthetic span, it's probably cleaner to change the "original representation" to an enum of different possible formats (longHex, shortHex, name (which may need a string attached since some colors have multiple names), rgb, hsl) and use those to recreate the appropriate serialization format.

Note that we should serialize these colors using the comma-separated function formats even if the author used a space-separated format since that's not yet widely supported. Similarly, we should serialize colors with non-1 alpha channels using rgba() and hsla() even though that's no longer necessary per spec.

Note: This issue does not cover emitting hsl() in the compressed output. We never intend to support that for the reasons outlined in sass/sass#469, and attempts to argue that case in this issue will be marked as spam.

@arakis
Copy link

arakis commented Feb 18, 2022

As original Author of #469, i'm glad that you try to plan to preserve the color format in expanded mode.

If I understood you correctly, you try to preserve hsl in non-compressed output, but you will omit them in compressed output? If so, this would be totally ok. In this case, it would be possible to use another minifier to compress the css, and preserving the hsl.

nex3 added a commit that referenced this issue Mar 15, 2022
This also fixes a bug where four- and eight-digit hex numbers weren't
being translated to more compatible formats.

Closes #1634
nex3 added a commit that referenced this issue Mar 17, 2022
This also fixes a bug where four- and eight-digit hex numbers weren't
being translated to more compatible formats.

Closes #1634
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants