bgrins / TinyColor

Fast, small color manipulation and conversion for JavaScript
https://bgrins.github.io/TinyColor/
MIT License
5.08k stars 438 forks source link

short hex is not understood (40ff should be understood as 04 00 ff) #58

Closed totty90 closed 10 years ago

totty90 commented 10 years ago

Use this function decimalToHex(d) { var hex = Number(d).toString(16); hex = "000000".substr(0, 6 - hex.length) + hex; return hex; }

bgrins commented 10 years ago

I don't understand the issue - a hex character should be 3 or 6 characters. If it cannot be represented with 3 characters then the input should be put into the 6 character notation. From http://www.w3.org/TR/css3-color/#rgb-color:

The format of an RGB value in hexadecimal notation is a ‘#’ immediately followed by either three or six hexadecimal characters. The three-digit RGB notation (#rgb) is converted into six-digit form (#rrggbb) by replicating digits, not by adding zeros

totty90 commented 10 years ago

There are hex that are 4 like in the example in the title. I don't know if is standard or not, but might be used in this lib to accept more input types. Not only hex3 or hex6. If not, I have to convert all the time with the function..

bgrins commented 10 years ago

I try to follow the CSS standard as closely as possible for the accepted string input to prevent any surprises. I've never seen the 4 character hex in any standard, so I'm inclined not to add it. You should be able to wrap the tinycolor function to support this use case using your example code in this issue.

totty90 commented 10 years ago

ok, no problem then. I was not using for css but I was using it for a graphical application that uses webgl... I found that lib not limited to css