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

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

Closed
totty90 opened this issue Jul 6, 2014 · 5 comments
Closed

Comments

@totty90
Copy link

totty90 commented Jul 6, 2014

No description provided.

@totty90
Copy link
Author

totty90 commented Jul 6, 2014

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

@bgrins
Copy link
Owner

bgrins commented Jul 6, 2014

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
Copy link
Author

totty90 commented Jul 6, 2014

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
Copy link
Owner

bgrins commented Jul 6, 2014

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.

@bgrins bgrins closed this as completed Jul 6, 2014
@totty90
Copy link
Author

totty90 commented Jul 6, 2014

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

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

2 participants