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

hex8 and hex4 support and formatting #82

Open
ColinLondon opened this issue Feb 25, 2015 · 4 comments
Open

hex8 and hex4 support and formatting #82

ColinLondon opened this issue Feb 25, 2015 · 4 comments

Comments

@ColinLondon
Copy link

Excellent stuff, but times move on (!)...

The latest W3C draft on CSS colour has the alpha channel of hex8 defined by the last two characters. So "00" is transparent, "80" is 50%, "FF" is opaque, etc.

http://dev.w3.org/csswg/css-color-4/#hex-notation

tinyColor formats this the other way around, with the alpha channel as the first two characters. I think that was the previous assumption.

So that also means that if we can have tinyColor accepting hex6 as shorthand for hex6, then will it be able to accept hex4 as shorthand for hex8 at some point in the future.

If anyone has a code fix for doing this NOW, you will magically appear on my Christmas Card list.

Thanks.

@bgrins
Copy link
Owner

bgrins commented Mar 4, 2015

Thanks for the info. This will be a little tricky, since IE filters use the backwards hex8 format. But I think we can special case that in the toFilter function. I doubt that too many people are using hex8 right now (it was added mainly to support toFilter), so the risk of changing the semantics is probably not too big.

@bgrins
Copy link
Owner

bgrins commented Mar 4, 2015

If you'd like to contribute these changes, I'd be happy to accept a patch. Here's what would need to be done:

  1. modify rgbaToHex to flip where transparency shows up:
    function rgbaToHex(r, g, b, a) {
    .
  2. Add an 'allow4Char' parameter to that function that behaves just like 'allow3Char' does here:
    if (allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1)) {
    .
  3. Add the 'allow4Char' parameter to toHex8() and toHex8String(). We could consider renaming it to toHexAlpha or something.
  4. Add some tests for these features:
    equal (tinycolor("rgba 255 0 0 0.5").toHex8String(), "#80ff0000");
    .
  5. We also should move the current logic in rgbaToHex into the toFilter function, since it's important the semantics stay the same for this.

@ColinLondon
Copy link
Author

Does anyone know how to code this (I do not code myself!).

Cin cin

@elvisvoer
Copy link

This is closed by #136

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