less.js
less.js copied to clipboard
Alpha hex support
#697 proposes single and double character hex color support (eg: #E would convert to #EEEEEE).
In the spirit of this, I'm proposing support for alpha hex support.
#FF000080
The extra two hex digits at the end would represent the alpha/opacity. LESS could convert this to:
rgba(255, 0, 0, 0.5)
Producing a pure red with 50% opacity.
will this get in the way of the old IE 8 hex digits? As I remember that begins with alpha.. where as here you would expect it to end in alpha.. Plus I imagine taking an old css sheet and suddenly accepting 8 hex digits and then outputting rgba would also break things.
Yes, while I agree that #RRGGBBAA makes more sense to me, that would indeed clash with argb (#AARRGGBB) that's already in LESS. Admittedly it's done via a function, not a language construct, but it would seem to make sense to use the same format in both if we're to do that.
I didn't realize IE had 8 digit hex. LESS could still normalize this but it could potentially break existing IE-specific sheets. Somehow, I doubt many people are using said IE-specific hex values these day though.
That, or support the #AARRGGBB format throughout. But I think that is backwards-looking.
.. just recently someone went to the trouble of extending dotless to leave these type of hex values alone
https://github.com/dotless/dotless/commit/52ba9a4ccf4e9a895d557f01112ab4c7f4cad8a7
TBH I think I see more gain in allowing #E then stepping into the minefield of 8 digit hex
Yes, I don't think this is really worth doing.
Perhaps as a sub-proposal, some way of indicating that the colour is ARGB vs RGBA?
#RRGGBBAA
versus
##AARRGGBB
or
#RRGGBB,AA
#RRGGBB|AA
#RRGGBB_AA
closing due to general lack of support for this feature.
Can this be reopened bearing in mind 4 and 8-digit hex are defined in CSS Color Module Level 4 and already supported in various browsers?
I assume Less could auto-convert #RRGGBBAA to rgba()?
Yes, it's just a matter of adding add a few lines to handle #4 and #8 cases everywhere (it's not too many) #3 and #6 things are parsed.
I don't know when it happened, but at some point rgba() became able to convert #rrggbbaa colors to rgba().
Example:
box-shadow: 0 3px 6px rgba(#00000029); will output as box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16078431);
It isn't documented but it should be, so I did so in this pull request.