craftyjs/Crafty — pull request #770 by starwed (2014-03-30 23:05:21+00:00)
Title: Color, Tint refactoring

It seemed a bit silly to have two components which are basically the same. (I think previously the issue was that IE8 didn't support `rgba()` syntax for background color?)

This patch eliminates Tint completely, adding its functionality to Color. The existing approach of using CSS works for both DOM and Canvas Color entities, but
- wouldn't work for WebGL -- unlike canvas, it has no idea about color names.
- didn't play well with Tint
So I also added some functionality to Crafty for turning CSS-style string references to colors into the raw RGB values.

This is the function `Crafty.assignColor`. If you give it a hex string ("#FF0000") a color name ("red") or something odder (like an "hlsa()" declaration) it'll try to resolve it to rgb values.
- If it's a hex code, it just parses the hex directly. Works for the optional short form
- If it's an `rgb` or `rgba` declaration, that'll also be parsed directly to rgb.
- If it's an unknown type, it'll assign the string to an invisible div, and then parse the computed color. For efficiency, this will be stored in a dictionary object. So things like "lightsalmon" will be computed correctly, but with a small one-time performance hit.
- The dictionary is prepopulated by a short list of the 17 CSS2 colors like "red", "black", etc.

We could simply store *all* the standard CSS3 colors in the dictionary. You can see that commented out in the code. :) [This SO thread](http://stackoverflow.com/questions/1573053/javascript-function-to-convert-color-names-to-hex-codes) was super-useful in understanding the different approaches here.

This PR needs refactoring once the changes to tests go in. And I'm uncertain whether we should include all those extra colors by default.

Also, I can't test this in IE!