openstyles / stylus

Stylus - Userstyles Manager
https://add0n.com/stylus.html
GNU General Public License v3.0
5.45k stars 305 forks source link

[Feature request] Unify color format on beautification #846

Open stonecrusher opened 4 years ago

stonecrusher commented 4 years ago

When beautifying CSS it would be a cool feature to automatically convert the often present mess of different color formats to one preferred scheme.

So if 8-digit HEX is preferred:

#CF3                     --> #ccff33ff
#f0a                     --> #ff00aaff
#bbba                    --> #bbbbaaff
mediumblue               --> #0000cdff
rgba(0, 160, 160)        --> #00a0a0ff
rgba(0, 160, 0, 0.3)     --> #00a0004d
hsla(120, 100%, 31%, .3) --> #00a0004d

To make it easier to implement I'd only allow

So no "downconversion".

tophf commented 4 years ago

Sounds like you're ready to use a proper CSS post-processor and maybe even a standalone editor with cool CSS features. Not sure this would be useful in Stylus. For example I dislike 8-digit hex now and would usually prefer hsla which is especially awesome when you want to work with slight variations of the same color e.g. keep hue/saturation but only change lightness.

stonecrusher commented 4 years ago

I'm open to that. Can you recommend one? Atm I still heavily use Notepad++ and the editor of stylus-addon. No node.js. Regarding hsla, you're right. Personally I just use the stylus-lang color functions doing the same job.

narcolepticinsomniac commented 4 years ago

hsla (who even uses that?)

I do, almost exclusively. Easiest to tweak shades on the fly, as tophf mentioned.

As for unifying color format on beautification, it might make for an interesting option if it converted every format to the desired format, and it would also need to be disabled by default.

Depends on difficulty vs demand. Not sure about the difficulty, but I imagine the demand would be pretty low.

dzintars commented 3 years ago

Leaving my $0.0002 Consider such syntax:

:root {
  --theme-color-accent-hue: 215;
  --theme-color-accent-100: hsla(var(--theme-color-accent-hue, 215), 100%, 55%, 1);
}

html, body {
  background-color: var(--theme-color-accent-100, hsla(0, 0%, 100%, 1));
}

I think its really bad idea to hard-code HEX and i would not support such feature request.

stonecrusher commented 3 years ago

This is about "cleaning" and beautifying code snippets from elsewhere (mostly the original site's CSS or other userstyles) to a uniform format. No HEX-compulsion, don't worry.