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

Swapping the color notation in CSS #19

Open
kizu opened this issue Oct 27, 2012 · 4 comments
Open

Swapping the color notation in CSS #19

kizu opened this issue Oct 27, 2012 · 4 comments

Comments

@kizu
Copy link
Contributor

kizu commented Oct 27, 2012

Colors in CSS can be described in different ways: Hexadecimal, rgb, rgba, hsl and hsla.

Right now the dec_max and dec_all actions are the same for the colors, so we could change one of them to the new action: rotate the notation for the color.

That way, the color described as #FFF would become rgba(255,255,255,1) and then hsla(0,0%,100%,1) (plain rgb and hsl are rarely used, so we could just forgot about them)

If the color have the alpha less than 1, we could rotate only between rgba and hsla, so we wouldn't lose the alpha occasionally.

There could still be some issues, like not every color in RGB can be described in HSL, but we could either just forgot about that, either add a comment with the initial color after the transform, that could be used to restore the color to it's previous state if it was changed. Actually, doing so we could keep the alpha for the switching to hexadecimal color.

This way the chain would look like:

  1. color: rgba(255,255,255,0.5);
  2. color: hsla(0,0%,100%,0.5);
  3. color: #FFF; /* alpha: 0.5 */
  4. color: rgba(255,255,255,0.5); again.

This would allow us to easy change the color defined in any notation using the appropriate way we want.

rmaksim added a commit that referenced this issue Oct 28, 2012
@rmaksim
Copy link
Owner

rmaksim commented Oct 28, 2012

Try to test.
Now only two transformations are available.

from:

color: rgba(0,17,34,0.4);

to:

color: #001122; /* alpha: 0.4 */

again:

color: rgba(0,17,34,0.4);

@kizu
Copy link
Contributor Author

kizu commented Oct 28, 2012

Aha, it works! Cool.

Some thoughts:

  • When the alpha: 1 the comment is unnecessary.
  • It would be cool to somehow preserve the case of the initial hexadecimal colors, however the only way to do it is to add the settings for this (two of them — the case of the letters and if they need to be shorthanded).
  • If would be nice to somehow validate the input of the rgba value: incorrect values like rgba(256,255,255,1) or rgba(-2,255,255,1) are converted too. That's not a big issue, but, well. Maybe it could be completely another issue — we could cycle the 255 to 0, so it couldn't go out of available range.

@rmaksim
Copy link
Owner

rmaksim commented Oct 28, 2012

Yeah, have been thought - but a little later.

@alexilyaev
Copy link

That's cool.

Here are some of my thoughts:

  • A color in RGB or HEX should not be converted to RGBA, and then also the comment is irrelevant (point 1 by kizu).
  • There should be a setting to use shorthand HEX values when possible.

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

No branches or pull requests

3 participants