css-color-parser-js icon indicating copy to clipboard operation
css-color-parser-js copied to clipboard

Accept #rgba and #rrggbbaa notation

Open IvanSanchez opened this issue 7 years ago • 5 comments

Add parsing for the #rgba and #rrggbbaa notations.

These notations are specified in the CSS Color Module Level 4 specs (https://drafts.csswg.org/css-color/#hex-notation) , and supported by current browsers as per Chrome 52 https://www.chromestatus.com/feature/5685348285808640 , Firefox 49 https://bugzilla.mozilla.org/show_bug.cgi?id=567283 and Safari 9.1.

I added some spaces and leading zeroes around, just to improve the readability a bit and to make better sense of the bit-wise logic. I can remove those if you ask.

IvanSanchez avatar Feb 21 '17 12:02 IvanSanchez

~Wait, somehow JS assumes complement-2 signed integers, so this code fails for #rrggbbaa values where rr >= 80.~ Added 0-255 coercion (& 0xff) to the rr byte to avoid troubles with complement-2 negative numbers.

IvanSanchez avatar Feb 21 '17 13:02 IvanSanchez

I wrote a patch to support this, but I want to comment on the statement "and supported by current browsers as per Chrome 52". It is in fact not launched, see for example:

https://bugs.chromium.org/p/chromium/issues/detail?id=76362#c46

Trying a 4 digit test case in Chrome does not work on a current 56.0.2924.87, for example:

http://test.csswg.org/suites/css-color-4_dev/nightly-unstable/html/hex-004.htm

So while I have the patch sitting around for it, it seems this is in fact still a draft proposal, has possible compatibility problems, and is not standard yet. That doesn't mean I am against supporting it now or in the future, it's just not common place yet... Is there a good argument for adding it right now?

deanm avatar Feb 21 '17 20:02 deanm

Hah, I had some of the experimental flags set in my chrome, so I didn't notice that.

So far this is breaking one of my use cases (one that can be worked around by changing some backend data). I guess this doesn't count as a good argument for merging now, so this can wait.

IvanSanchez avatar Feb 22 '17 09:02 IvanSanchez

#rgba and #rrggbbaa have been supported by default by Chrome since version 62, released 3 years ago now.

Every modern browser has supported this for a while.

Should be time to apply the patch 🙂

thth avatar Nov 21 '20 00:11 thth

Hi, any update? Thanks

radoslavirha avatar Feb 10 '23 15:02 radoslavirha