-
-
Notifications
You must be signed in to change notification settings - Fork 80
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
Some colors get rounded by iro.Color #26
Comments
Thanks for letting me know! I think it might be due to how all |
Just noticed the same issue... #FF0FF0 -> #FF0FEF and some others... |
Finally found the cause; it was a combination of excessive rounding and a strange quirk where converting decimal numbers to hex with I have a working fix in the bug/color-rounding branch if anyone wants to try it One minor side effect of this fix is that |
Okay I think I got it, the fix should be in master now. Thanks @nickpearson and @mbaierl :) |
Works great. Thank you! I agree that always using the full hex string for consistency is good. If you do happen to decide to convert to the shorthand hex value, here's a simple implementation: function shortHex(hex) {
return hex.replace(/^#([0-9a-f])\1([0-9a-f])\2([0-9a-f])\3$/, "#$1$2$3")
} shortHex("#aabbcc") //=> "#abc"
shortHex("#aabbcd") //=> "#aabbcd"
shortHex("testing") //=> "testing" (returns non-compactible values untouched)
shortHex("#abc") //=> "#abc" This implementation of course doesn't do validation and only compacts all-lowercase hex strings, but it's a start. |
iro.Color
seems to round the rgb values in some cases:You can also see this effect by modifying the CodePen Demo (linked on the intro page) to use
#eee
as thecolor
option rather than{r: 255, g: 0, b: 0}
.The text was updated successfully, but these errors were encountered: