3bdb9554e48e78e137336502b2a73374431e8b83116cbb51a8b8b1fd4614b483398da38568f1ccd66924b60cd429f6b3cdc691613fb87f18af517f868fe8e2 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. /* test-code */
  2. if (typeof module === "object" && typeof module.exports === "object") {
  3. var jsdom = require("jsdom");
  4. var JSDOM = jsdom.JSDOM;
  5. var $ = require('jquery')((new JSDOM('<!DOCTYPE html><p>Hello world</p>')).window);
  6. }
  7. /* end-test-code */
  8. /**
  9. * Color manipulation helper class
  10. *
  11. * @param {Object|String} [val]
  12. * @param {Object} [predefinedColors]
  13. * @param {String|null} [fallbackColor]
  14. * @param {String|null} [fallbackFormat]
  15. * @param {Boolean} [hexNumberSignPrefix]
  16. * @constructor
  17. */
  18. var Color = function(
  19. val, predefinedColors, fallbackColor, fallbackFormat, hexNumberSignPrefix) {
  20. this.fallbackValue = fallbackColor ?
  21. (
  22. (typeof fallbackColor === 'string') ?
  23. this.parse(fallbackColor) :
  24. fallbackColor
  25. ) :
  26. null;
  27. this.fallbackFormat = fallbackFormat ? fallbackFormat : 'rgba';
  28. this.hexNumberSignPrefix = hexNumberSignPrefix === true;
  29. this.value = this.fallbackValue;
  30. this.origFormat = null; // original string format
  31. this.predefinedColors = predefinedColors ? predefinedColors : {};
  32. // We don't want to share aliases across instances so we extend new object
  33. this.colors = $.extend({}, Color.webColors, this.predefinedColors);
  34. if (val) {
  35. if (typeof val.h !== 'undefined') {
  36. this.value = val;
  37. } else {
  38. this.setColor(String(val));
  39. }
  40. }
  41. if (!this.value) {
  42. // Initial value is always black if no arguments are passed or val is empty
  43. this.value = {
  44. h: 0,
  45. s: 0,
  46. b: 0,
  47. a: 1
  48. };
  49. }
  50. };
  51. Color.webColors = { // 140 predefined colors from the HTML Colors spec
  52. "aliceblue": "f0f8ff",
  53. "antiquewhite": "faebd7",
  54. "aqua": "00ffff",
  55. "aquamarine": "7fffd4",
  56. "azure": "f0ffff",
  57. "beige": "f5f5dc",
  58. "bisque": "ffe4c4",
  59. "black": "000000",
  60. "blanchedalmond": "ffebcd",
  61. "blue": "0000ff",
  62. "blueviolet": "8a2be2",
  63. "brown": "a52a2a",
  64. "burlywood": "deb887",
  65. "cadetblue": "5f9ea0",
  66. "chartreuse": "7fff00",
  67. "chocolate": "d2691e",
  68. "coral": "ff7f50",
  69. "cornflowerblue": "6495ed",
  70. "cornsilk": "fff8dc",
  71. "crimson": "dc143c",
  72. "cyan": "00ffff",
  73. "darkblue": "00008b",
  74. "darkcyan": "008b8b",
  75. "darkgoldenrod": "b8860b",
  76. "darkgray": "a9a9a9",
  77. "darkgreen": "006400",
  78. "darkkhaki": "bdb76b",
  79. "darkmagenta": "8b008b",
  80. "darkolivegreen": "556b2f",
  81. "darkorange": "ff8c00",
  82. "darkorchid": "9932cc",
  83. "darkred": "8b0000",
  84. "darksalmon": "e9967a",
  85. "darkseagreen": "8fbc8f",
  86. "darkslateblue": "483d8b",
  87. "darkslategray": "2f4f4f",
  88. "darkturquoise": "00ced1",
  89. "darkviolet": "9400d3",
  90. "deeppink": "ff1493",
  91. "deepskyblue": "00bfff",
  92. "dimgray": "696969",
  93. "dodgerblue": "1e90ff",
  94. "firebrick": "b22222",
  95. "floralwhite": "fffaf0",
  96. "forestgreen": "228b22",
  97. "fuchsia": "ff00ff",
  98. "gainsboro": "dcdcdc",
  99. "ghostwhite": "f8f8ff",
  100. "gold": "ffd700",
  101. "goldenrod": "daa520",
  102. "gray": "808080",
  103. "green": "008000",
  104. "greenyellow": "adff2f",
  105. "honeydew": "f0fff0",
  106. "hotpink": "ff69b4",
  107. "indianred": "cd5c5c",
  108. "indigo": "4b0082",
  109. "ivory": "fffff0",
  110. "khaki": "f0e68c",
  111. "lavender": "e6e6fa",
  112. "lavenderblush": "fff0f5",
  113. "lawngreen": "7cfc00",
  114. "lemonchiffon": "fffacd",
  115. "lightblue": "add8e6",
  116. "lightcoral": "f08080",
  117. "lightcyan": "e0ffff",
  118. "lightgoldenrodyellow": "fafad2",
  119. "lightgrey": "d3d3d3",
  120. "lightgreen": "90ee90",
  121. "lightpink": "ffb6c1",
  122. "lightsalmon": "ffa07a",
  123. "lightseagreen": "20b2aa",
  124. "lightskyblue": "87cefa",
  125. "lightslategray": "778899",
  126. "lightsteelblue": "b0c4de",
  127. "lightyellow": "ffffe0",
  128. "lime": "00ff00",
  129. "limegreen": "32cd32",
  130. "linen": "faf0e6",
  131. "magenta": "ff00ff",
  132. "maroon": "800000",
  133. "mediumaquamarine": "66cdaa",
  134. "mediumblue": "0000cd",
  135. "mediumorchid": "ba55d3",
  136. "mediumpurple": "9370d8",
  137. "mediumseagreen": "3cb371",
  138. "mediumslateblue": "7b68ee",
  139. "mediumspringgreen": "00fa9a",
  140. "mediumturquoise": "48d1cc",
  141. "mediumvioletred": "c71585",
  142. "midnightblue": "191970",
  143. "mintcream": "f5fffa",
  144. "mistyrose": "ffe4e1",
  145. "moccasin": "ffe4b5",
  146. "navajowhite": "ffdead",
  147. "navy": "000080",
  148. "oldlace": "fdf5e6",
  149. "olive": "808000",
  150. "olivedrab": "6b8e23",
  151. "orange": "ffa500",
  152. "orangered": "ff4500",
  153. "orchid": "da70d6",
  154. "palegoldenrod": "eee8aa",
  155. "palegreen": "98fb98",
  156. "paleturquoise": "afeeee",
  157. "palevioletred": "d87093",
  158. "papayawhip": "ffefd5",
  159. "peachpuff": "ffdab9",
  160. "peru": "cd853f",
  161. "pink": "ffc0cb",
  162. "plum": "dda0dd",
  163. "powderblue": "b0e0e6",
  164. "purple": "800080",
  165. "red": "ff0000",
  166. "rosybrown": "bc8f8f",
  167. "royalblue": "4169e1",
  168. "saddlebrown": "8b4513",
  169. "salmon": "fa8072",
  170. "sandybrown": "f4a460",
  171. "seagreen": "2e8b57",
  172. "seashell": "fff5ee",
  173. "sienna": "a0522d",
  174. "silver": "c0c0c0",
  175. "skyblue": "87ceeb",
  176. "slateblue": "6a5acd",
  177. "slategray": "708090",
  178. "snow": "fffafa",
  179. "springgreen": "00ff7f",
  180. "steelblue": "4682b4",
  181. "tan": "d2b48c",
  182. "teal": "008080",
  183. "thistle": "d8bfd8",
  184. "tomato": "ff6347",
  185. "turquoise": "40e0d0",
  186. "violet": "ee82ee",
  187. "wheat": "f5deb3",
  188. "white": "ffffff",
  189. "whitesmoke": "f5f5f5",
  190. "yellow": "ffff00",
  191. "yellowgreen": "9acd32",
  192. "transparent": "transparent"
  193. };
  194. Color.prototype = {
  195. constructor: Color,
  196. colors: {}, // merged web and predefined colors
  197. predefinedColors: {},
  198. /**
  199. * @return {Object}
  200. */
  201. getValue: function() {
  202. return this.value;
  203. },
  204. /**
  205. * @param {Object} val
  206. */
  207. setValue: function(val) {
  208. this.value = val;
  209. },
  210. _sanitizeNumber: function(val) {
  211. if (typeof val === 'number') {
  212. return val;
  213. }
  214. if (isNaN(val) || (val === null) || (val === '') || (val === undefined)) {
  215. return 1;
  216. }
  217. if (val === '') {
  218. return 0;
  219. }
  220. if (typeof val.toLowerCase !== 'undefined') {
  221. if (val.match(/^\./)) {
  222. val = "0" + val;
  223. }
  224. return Math.ceil(parseFloat(val) * 100) / 100;
  225. }
  226. return 1;
  227. },
  228. isTransparent: function(strVal) {
  229. if (!strVal || !(typeof strVal === 'string' || strVal instanceof String)) {
  230. return false;
  231. }
  232. strVal = strVal.toLowerCase().trim();
  233. return (strVal === 'transparent') || (strVal.match(/#?00000000/)) || (strVal.match(/(rgba|hsla)\(0,0,0,0?\.?0\)/));
  234. },
  235. rgbaIsTransparent: function(rgba) {
  236. return ((rgba.r === 0) && (rgba.g === 0) && (rgba.b === 0) && (rgba.a === 0));
  237. },
  238. // parse a string to HSB
  239. /**
  240. * @protected
  241. * @param {String} strVal
  242. * @returns {boolean} Returns true if it could be parsed, false otherwise
  243. */
  244. setColor: function(strVal) {
  245. strVal = strVal.toLowerCase().trim();
  246. if (strVal) {
  247. if (this.isTransparent(strVal)) {
  248. this.value = {
  249. h: 0,
  250. s: 0,
  251. b: 0,
  252. a: 0
  253. };
  254. return true;
  255. } else {
  256. var parsedColor = this.parse(strVal);
  257. if (parsedColor) {
  258. this.value = this.value = {
  259. h: parsedColor.h,
  260. s: parsedColor.s,
  261. b: parsedColor.b,
  262. a: parsedColor.a
  263. };
  264. if (!this.origFormat) {
  265. this.origFormat = parsedColor.format;
  266. }
  267. } else if (this.fallbackValue) {
  268. // if parser fails, defaults to fallbackValue if defined, otherwise the value won't be changed
  269. this.value = this.fallbackValue;
  270. }
  271. }
  272. }
  273. return false;
  274. },
  275. setHue: function(h) {
  276. this.value.h = 1 - h;
  277. },
  278. setSaturation: function(s) {
  279. this.value.s = s;
  280. },
  281. setBrightness: function(b) {
  282. this.value.b = 1 - b;
  283. },
  284. setAlpha: function(a) {
  285. this.value.a = Math.round((parseInt((1 - a) * 100, 10) / 100) * 100) / 100;
  286. },
  287. toRGB: function(h, s, b, a) {
  288. if (arguments.length === 0) {
  289. h = this.value.h;
  290. s = this.value.s;
  291. b = this.value.b;
  292. a = this.value.a;
  293. }
  294. h *= 360;
  295. var R, G, B, X, C;
  296. h = (h % 360) / 60;
  297. C = b * s;
  298. X = C * (1 - Math.abs(h % 2 - 1));
  299. R = G = B = b - C;
  300. h = ~~h;
  301. R += [C, X, 0, 0, X, C][h];
  302. G += [X, C, C, X, 0, 0][h];
  303. B += [0, 0, X, C, C, X][h];
  304. return {
  305. r: Math.round(R * 255),
  306. g: Math.round(G * 255),
  307. b: Math.round(B * 255),
  308. a: a
  309. };
  310. },
  311. toHex: function(ignoreFormat, h, s, b, a) {
  312. if (arguments.length <= 1) {
  313. h = this.value.h;
  314. s = this.value.s;
  315. b = this.value.b;
  316. a = this.value.a;
  317. }
  318. var prefix = '#';
  319. var rgb = this.toRGB(h, s, b, a);
  320. if (this.rgbaIsTransparent(rgb)) {
  321. return 'transparent';
  322. }
  323. if (!ignoreFormat) {
  324. prefix = (this.hexNumberSignPrefix ? '#' : '');
  325. }
  326. var hexStr = prefix + (
  327. (1 << 24) +
  328. (parseInt(rgb.r) << 16) +
  329. (parseInt(rgb.g) << 8) +
  330. parseInt(rgb.b))
  331. .toString(16)
  332. .slice(1);
  333. return hexStr;
  334. },
  335. toHSL: function(h, s, b, a) {
  336. if (arguments.length === 0) {
  337. h = this.value.h;
  338. s = this.value.s;
  339. b = this.value.b;
  340. a = this.value.a;
  341. }
  342. var H = h,
  343. L = (2 - s) * b,
  344. S = s * b;
  345. if (L > 0 && L <= 1) {
  346. S /= L;
  347. } else {
  348. S /= 2 - L;
  349. }
  350. L /= 2;
  351. if (S > 1) {
  352. S = 1;
  353. }
  354. return {
  355. h: isNaN(H) ? 0 : H,
  356. s: isNaN(S) ? 0 : S,
  357. l: isNaN(L) ? 0 : L,
  358. a: isNaN(a) ? 0 : a
  359. };
  360. },
  361. toAlias: function(r, g, b, a) {
  362. var c, rgb = (arguments.length === 0) ? this.toHex(true) : this.toHex(true, r, g, b, a);
  363. // support predef. colors in non-hex format too, as defined in the alias itself
  364. var original = this.origFormat === 'alias' ? rgb : this.toString(false, this.origFormat);
  365. for (var alias in this.colors) {
  366. c = this.colors[alias].toLowerCase().trim();
  367. if ((c === rgb) || (c === original)) {
  368. return alias;
  369. }
  370. }
  371. return false;
  372. },
  373. RGBtoHSB: function(r, g, b, a) {
  374. r /= 255;
  375. g /= 255;
  376. b /= 255;
  377. var H, S, V, C;
  378. V = Math.max(r, g, b);
  379. C = V - Math.min(r, g, b);
  380. H = (C === 0 ? null :
  381. V === r ? (g - b) / C :
  382. V === g ? (b - r) / C + 2 :
  383. (r - g) / C + 4
  384. );
  385. H = ((H + 360) % 6) * 60 / 360;
  386. S = C === 0 ? 0 : C / V;
  387. return {
  388. h: this._sanitizeNumber(H),
  389. s: S,
  390. b: V,
  391. a: this._sanitizeNumber(a)
  392. };
  393. },
  394. HueToRGB: function(p, q, h) {
  395. if (h < 0) {
  396. h += 1;
  397. } else if (h > 1) {
  398. h -= 1;
  399. }
  400. if ((h * 6) < 1) {
  401. return p + (q - p) * h * 6;
  402. } else if ((h * 2) < 1) {
  403. return q;
  404. } else if ((h * 3) < 2) {
  405. return p + (q - p) * ((2 / 3) - h) * 6;
  406. } else {
  407. return p;
  408. }
  409. },
  410. HSLtoRGB: function(h, s, l, a) {
  411. if (s < 0) {
  412. s = 0;
  413. }
  414. var q;
  415. if (l <= 0.5) {
  416. q = l * (1 + s);
  417. } else {
  418. q = l + s - (l * s);
  419. }
  420. var p = 2 * l - q;
  421. var tr = h + (1 / 3);
  422. var tg = h;
  423. var tb = h - (1 / 3);
  424. var r = Math.round(this.HueToRGB(p, q, tr) * 255);
  425. var g = Math.round(this.HueToRGB(p, q, tg) * 255);
  426. var b = Math.round(this.HueToRGB(p, q, tb) * 255);
  427. return [r, g, b, this._sanitizeNumber(a)];
  428. },
  429. /**
  430. * @param {String} strVal
  431. * @returns {Object} Object containing h,s,b,a,format properties or FALSE if failed to parse
  432. */
  433. parse: function(strVal) {
  434. if (typeof strVal !== 'string') {
  435. return this.fallbackValue;
  436. }
  437. if (arguments.length === 0) {
  438. return false;
  439. }
  440. var that = this,
  441. result = false,
  442. isAlias = (typeof this.colors[strVal] !== 'undefined'),
  443. values, format;
  444. if (isAlias) {
  445. strVal = this.colors[strVal].toLowerCase().trim();
  446. }
  447. $.each(this.stringParsers, function(i, parser) {
  448. var match = parser.re.exec(strVal);
  449. values = match && parser.parse.apply(that, [match]);
  450. if (values) {
  451. result = {};
  452. format = (isAlias ? 'alias' : (parser.format ? parser.format : that.getValidFallbackFormat()));
  453. if (format.match(/hsla?/)) {
  454. result = that.RGBtoHSB.apply(that, that.HSLtoRGB.apply(that, values));
  455. } else {
  456. result = that.RGBtoHSB.apply(that, values);
  457. }
  458. if (result instanceof Object) {
  459. result.format = format;
  460. }
  461. return false; // stop iterating
  462. }
  463. return true;
  464. });
  465. return result;
  466. },
  467. getValidFallbackFormat: function() {
  468. var formats = [
  469. 'rgba', 'rgb', 'hex', 'hsla', 'hsl'
  470. ];
  471. if (this.origFormat && (formats.indexOf(this.origFormat) !== -1)) {
  472. return this.origFormat;
  473. }
  474. if (this.fallbackFormat && (formats.indexOf(this.fallbackFormat) !== -1)) {
  475. return this.fallbackFormat;
  476. }
  477. return 'rgba'; // By default, return a format that will not lose the alpha info
  478. },
  479. /**
  480. *
  481. * @param {string} [format] (default: rgba)
  482. * @param {boolean} [translateAlias] Return real color for pre-defined (non-standard) aliases (default: false)
  483. * @param {boolean} [forceRawValue] Forces hashtag prefix when getting hex color (default: false)
  484. * @returns {String}
  485. */
  486. toString: function(forceRawValue, format, translateAlias) {
  487. format = format || this.origFormat || this.fallbackFormat;
  488. translateAlias = translateAlias || false;
  489. var c = false;
  490. switch (format) {
  491. case 'rgb':
  492. {
  493. c = this.toRGB();
  494. if (this.rgbaIsTransparent(c)) {
  495. return 'transparent';
  496. }
  497. return 'rgb(' + c.r + ',' + c.g + ',' + c.b + ')';
  498. }
  499. break;
  500. case 'rgba':
  501. {
  502. c = this.toRGB();
  503. return 'rgba(' + c.r + ',' + c.g + ',' + c.b + ',' + c.a + ')';
  504. }
  505. break;
  506. case 'hsl':
  507. {
  508. c = this.toHSL();
  509. return 'hsl(' + Math.round(c.h * 360) + ',' + Math.round(c.s * 100) + '%,' + Math.round(c.l * 100) + '%)';
  510. }
  511. break;
  512. case 'hsla':
  513. {
  514. c = this.toHSL();
  515. return 'hsla(' + Math.round(c.h * 360) + ',' + Math.round(c.s * 100) + '%,' + Math.round(c.l * 100) + '%,' + c.a + ')';
  516. }
  517. break;
  518. case 'hex':
  519. {
  520. return this.toHex(forceRawValue);
  521. }
  522. break;
  523. case 'alias':
  524. {
  525. c = this.toAlias();
  526. if (c === false) {
  527. return this.toString(forceRawValue, this.getValidFallbackFormat());
  528. }
  529. if (translateAlias && !(c in Color.webColors) && (c in this.predefinedColors)) {
  530. return this.predefinedColors[c];
  531. }
  532. return c;
  533. }
  534. default:
  535. {
  536. return c;
  537. }
  538. break;
  539. }
  540. },
  541. // a set of RE's that can match strings and generate color tuples.
  542. // from John Resig color plugin
  543. // https://github.com/jquery/jquery-color/
  544. stringParsers: [{
  545. re: /rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*?\)/,
  546. format: 'rgb',
  547. parse: function(execResult) {
  548. return [
  549. execResult[1],
  550. execResult[2],
  551. execResult[3],
  552. 1
  553. ];
  554. }
  555. }, {
  556. re: /rgb\(\s*(\d*(?:\.\d+)?)\%\s*,\s*(\d*(?:\.\d+)?)\%\s*,\s*(\d*(?:\.\d+)?)\%\s*?\)/,
  557. format: 'rgb',
  558. parse: function(execResult) {
  559. return [
  560. 2.55 * execResult[1],
  561. 2.55 * execResult[2],
  562. 2.55 * execResult[3],
  563. 1
  564. ];
  565. }
  566. }, {
  567. re: /rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d*(?:\.\d+)?)\s*)?\)/,
  568. format: 'rgba',
  569. parse: function(execResult) {
  570. return [
  571. execResult[1],
  572. execResult[2],
  573. execResult[3],
  574. execResult[4]
  575. ];
  576. }
  577. }, {
  578. re: /rgba\(\s*(\d*(?:\.\d+)?)\%\s*,\s*(\d*(?:\.\d+)?)\%\s*,\s*(\d*(?:\.\d+)?)\%\s*(?:,\s*(\d*(?:\.\d+)?)\s*)?\)/,
  579. format: 'rgba',
  580. parse: function(execResult) {
  581. return [
  582. 2.55 * execResult[1],
  583. 2.55 * execResult[2],
  584. 2.55 * execResult[3],
  585. execResult[4]
  586. ];
  587. }
  588. }, {
  589. re: /hsl\(\s*(\d*(?:\.\d+)?)\s*,\s*(\d*(?:\.\d+)?)\%\s*,\s*(\d*(?:\.\d+)?)\%\s*?\)/,
  590. format: 'hsl',
  591. parse: function(execResult) {
  592. return [
  593. execResult[1] / 360,
  594. execResult[2] / 100,
  595. execResult[3] / 100,
  596. execResult[4]
  597. ];
  598. }
  599. }, {
  600. re: /hsla\(\s*(\d*(?:\.\d+)?)\s*,\s*(\d*(?:\.\d+)?)\%\s*,\s*(\d*(?:\.\d+)?)\%\s*(?:,\s*(\d*(?:\.\d+)?)\s*)?\)/,
  601. format: 'hsla',
  602. parse: function(execResult) {
  603. return [
  604. execResult[1] / 360,
  605. execResult[2] / 100,
  606. execResult[3] / 100,
  607. execResult[4]
  608. ];
  609. }
  610. }, {
  611. re: /#?([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/,
  612. format: 'hex',
  613. parse: function(execResult) {
  614. return [
  615. parseInt(execResult[1], 16),
  616. parseInt(execResult[2], 16),
  617. parseInt(execResult[3], 16),
  618. 1
  619. ];
  620. }
  621. }, {
  622. re: /#?([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/,
  623. format: 'hex',
  624. parse: function(execResult) {
  625. return [
  626. parseInt(execResult[1] + execResult[1], 16),
  627. parseInt(execResult[2] + execResult[2], 16),
  628. parseInt(execResult[3] + execResult[3], 16),
  629. 1
  630. ];
  631. }
  632. }],
  633. colorNameToHex: function(name) {
  634. if (typeof this.colors[name.toLowerCase()] !== 'undefined') {
  635. return this.colors[name.toLowerCase()];
  636. }
  637. return false;
  638. }
  639. };
  640. /* test-code */
  641. module.exports = Color;
  642. /* end-test-code */