- if (matches[1]) {
- red = toInt(matches[1]);
- green = toInt(matches[2]);
- blue = toInt(matches[3]);
- } else if (matches[4]) {
- red = toInt(matches[4], 16);
- green = toInt(matches[5], 16);
- blue = toInt(matches[6], 16);
- } else if (matches[7]) {
- red = toInt(matches[7] + matches[7], 16);
- green = toInt(matches[8] + matches[8], 16);
- blue = toInt(matches[9] + matches[9], 16);
+ red = toInt(matches[1]);
+ green = toInt(matches[2]);
+ blue = toInt(matches[3]);
+ } else {
+ matches = /^([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/.exec(color);
+
+ if (matches) {
+ red = toInt(matches[1], 16);
+ green = toInt(matches[2], 16);
+ blue = toInt(matches[3], 16);
+ } else {
+ matches = /^([0-9a-f])([0-9a-f])([0-9a-f])$/.exec(color);
+
+ if (matches) {
+ red = toInt(matches[1] + matches[1], 16);
+ green = toInt(matches[2] + matches[2], 16);
+ blue = toInt(matches[3] + matches[3], 16);
+ } else {
+ return '';
+ }