Color.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. /*
  2. * Copyright (C) 2009, 2013 Apple Inc. All rights reserved.
  3. * Copyright (C) 2009 Joseph Pecoraro
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  15. * its contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  19. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. /**
  30. * @constructor
  31. */
  32. WebInspector.Color = function(str)
  33. {
  34. this.value = str;
  35. this._parse();
  36. }
  37. WebInspector.Color.Format = {
  38. Original: "color-format-original",
  39. Nickname: "color-format-nickname",
  40. HEX: "color-format-hex",
  41. ShortHEX: "color-format-short-hex",
  42. RGB: "color-format-rgb",
  43. RGBA: "color-format-rgba",
  44. HSL: "color-format-hsl",
  45. HSLA: "color-format-hsla"
  46. };
  47. /**
  48. * @param {number=} a
  49. */
  50. WebInspector.Color.fromRGBA = function(r, g, b, a)
  51. {
  52. return new WebInspector.Color("rgba(" + r + "," + g + "," + b + "," + (typeof a === "undefined" ? 1 : a) + ")");
  53. }
  54. WebInspector.Color.fromRGB = function(r, g, b)
  55. {
  56. return new WebInspector.Color("rgb(" + r + "," + g + "," + b + ")");
  57. }
  58. WebInspector.Color.prototype = {
  59. nextFormat: function(format)
  60. {
  61. format = format || this.format;
  62. switch (format) {
  63. case WebInspector.Color.Format.Original:
  64. return this.simple ? WebInspector.Color.Format.RGB : WebInspector.Color.Format.RGBA;
  65. case WebInspector.Color.Format.RGB:
  66. case WebInspector.Color.Format.RGBA:
  67. return this.simple ? WebInspector.Color.Format.HSL : WebInspector.Color.Format.HSLA;
  68. case WebInspector.Color.Format.HSL:
  69. case WebInspector.Color.Format.HSLA:
  70. if (this.nickname)
  71. return WebInspector.Color.Format.Nickname;
  72. if (this.simple)
  73. return this.hasShortHex() ? WebInspector.Color.Format.ShortHEX : WebInspector.Color.Format.HEX;
  74. else
  75. return WebInspector.Color.Format.Original;
  76. case WebInspector.Color.Format.ShortHEX:
  77. return WebInspector.Color.Format.HEX;
  78. case WebInspector.Color.Format.HEX:
  79. return WebInspector.Color.Format.Original;
  80. case WebInspector.Color.Format.Nickname:
  81. if (this.simple)
  82. return this.hasShortHex() ? WebInspector.Color.Format.ShortHEX : WebInspector.Color.Format.HEX;
  83. else
  84. return WebInspector.Color.Format.Original;
  85. default:
  86. console.error("Unknown color format.");
  87. return null;
  88. }
  89. },
  90. /**
  91. * @return {string}
  92. */
  93. get shorthex()
  94. {
  95. if ("_short" in this)
  96. return this._short;
  97. if (!this.simple)
  98. return "";
  99. var hex = this.hex;
  100. if (hex.charAt(0) === hex.charAt(1) && hex.charAt(2) === hex.charAt(3) && hex.charAt(4) === hex.charAt(5))
  101. this._short = hex.charAt(0) + hex.charAt(2) + hex.charAt(4);
  102. else
  103. this._short = hex;
  104. return this._short;
  105. },
  106. /**
  107. * @return {string}
  108. */
  109. get hex()
  110. {
  111. if (!this.simple)
  112. return "";
  113. return this._hex;
  114. },
  115. set hex(x)
  116. {
  117. this._hex = x;
  118. },
  119. /**
  120. * @return {Array.<number>}
  121. */
  122. get rgb()
  123. {
  124. if (this._rgb)
  125. return this._rgb;
  126. if (this.simple)
  127. this._rgb = this._hexToRGB(this.hex);
  128. else {
  129. var rgba = this.rgba;
  130. this._rgb = [rgba[0], rgba[1], rgba[2]];
  131. }
  132. return this._rgb;
  133. },
  134. set rgb(x)
  135. {
  136. this._rgb = x;
  137. },
  138. /**
  139. * @return {Array.<number>}
  140. */
  141. get hsl()
  142. {
  143. if (this._hsl)
  144. return this._hsl;
  145. this._hsl = this._rgbToHSL(this.rgb);
  146. return this._hsl;
  147. },
  148. set hsl(x)
  149. {
  150. this._hsl = x;
  151. },
  152. /**
  153. * @return {string}
  154. */
  155. get nickname()
  156. {
  157. if (typeof this._nickname !== "undefined") // would be set on parse if there was a nickname
  158. return this._nickname;
  159. else
  160. return "";
  161. },
  162. set nickname(x)
  163. {
  164. this._nickname = x;
  165. },
  166. /**
  167. * @return {Array.<number>}
  168. */
  169. get rgba()
  170. {
  171. return this._rgba;
  172. },
  173. set rgba(x)
  174. {
  175. this._rgba = x;
  176. },
  177. /**
  178. * @return {Array.<number>}
  179. */
  180. get hsla()
  181. {
  182. return this._hsla;
  183. },
  184. set hsla(x)
  185. {
  186. this._hsla = x;
  187. },
  188. /**
  189. * @return {boolean}
  190. */
  191. hasShortHex: function()
  192. {
  193. var shorthex = this.shorthex;
  194. return (!!shorthex && shorthex.length === 3);
  195. },
  196. /**
  197. * @return {string}
  198. */
  199. toString: function(format)
  200. {
  201. if (!format)
  202. format = this.format;
  203. switch (format) {
  204. case WebInspector.Color.Format.Original:
  205. return this.value;
  206. case WebInspector.Color.Format.RGB:
  207. return "rgb(" + this.rgb.join(", ") + ")";
  208. case WebInspector.Color.Format.RGBA:
  209. return "rgba(" + this.rgba.join(", ") + ")";
  210. case WebInspector.Color.Format.HSL:
  211. var hsl = this.hsl;
  212. return "hsl(" + hsl[0] + ", " + hsl[1] + "%, " + hsl[2] + "%)";
  213. case WebInspector.Color.Format.HSLA:
  214. var hsla = this.hsla;
  215. return "hsla(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%, " + hsla[3] + ")";
  216. case WebInspector.Color.Format.HEX:
  217. return "#" + this.hex;
  218. case WebInspector.Color.Format.ShortHEX:
  219. return "#" + this.shorthex;
  220. case WebInspector.Color.Format.Nickname:
  221. return this.nickname;
  222. }
  223. throw "invalid color format";
  224. },
  225. /**
  226. * @return {Object}
  227. */
  228. toProtocolRGBA: function()
  229. {
  230. if (this._protocolRGBA)
  231. return this._protocolRGBA;
  232. var components = this.rgba;
  233. if (components)
  234. this._protocolRGBA = { r: Number(components[0]), g: Number(components[1]), b: Number(components[2]), a: Number(components[3]) };
  235. else {
  236. components = this.rgb;
  237. this._protocolRGBA = { r: Number(components[0]), g: Number(components[1]), b: Number(components[2]) };
  238. }
  239. return this._protocolRGBA;
  240. },
  241. /**
  242. * @param {number} value
  243. * @param {number} min
  244. * @param {number} max
  245. * @return {number}
  246. */
  247. _clamp: function(value, min, max)
  248. {
  249. if (value < min)
  250. return min;
  251. if (value > max)
  252. return max;
  253. return value;
  254. },
  255. /**
  256. * @param {number|string} rgbValue
  257. * @return {number}
  258. */
  259. _individualRGBValueToFloatValue: function(rgbValue)
  260. {
  261. if (typeof rgbValue === "number")
  262. return this._clamp(rgbValue, 0, 255);
  263. if (rgbValue.indexOf("%") === -1) {
  264. var intValue = parseInt(rgbValue, 10);
  265. return this._clamp(intValue, 0, 255);
  266. }
  267. var percentValue = parseFloat(rgbValue);
  268. return this._clamp(percentValue, 0, 100) * 2.55;
  269. },
  270. /**
  271. * @param {number|string} rgbValue
  272. * @return {string}
  273. */
  274. _individualRGBValueToHexValue: function(rgbValue)
  275. {
  276. var floatValue = this._individualRGBValueToFloatValue(rgbValue);
  277. var hex = Math.round(floatValue).toString(16);
  278. if (hex.length === 1)
  279. hex = "0" + hex;
  280. return hex;
  281. },
  282. /**
  283. * @param {Array.<string>} rgb
  284. * @return {string}
  285. */
  286. _rgbStringsToHex: function(rgb)
  287. {
  288. var r = this._individualRGBValueToHexValue(rgb[0]);
  289. var g = this._individualRGBValueToHexValue(rgb[1]);
  290. var b = this._individualRGBValueToHexValue(rgb[2]);
  291. return (r + g + b).toUpperCase();
  292. },
  293. /**
  294. * @param {Array.<number>} rgb
  295. * @return {string}
  296. */
  297. _rgbToHex: function(rgb)
  298. {
  299. var r = this._individualRGBValueToHexValue(rgb[0]);
  300. var g = this._individualRGBValueToHexValue(rgb[1]);
  301. var b = this._individualRGBValueToHexValue(rgb[2]);
  302. return (r + g + b).toUpperCase();
  303. },
  304. /**
  305. * @param {string} hex
  306. * @return {Array.<number>}
  307. */
  308. _hexToRGB: function(hex)
  309. {
  310. var r = parseInt(hex.substring(0,2), 16);
  311. var g = parseInt(hex.substring(2,4), 16);
  312. var b = parseInt(hex.substring(4,6), 16);
  313. return [r, g, b];
  314. },
  315. /**
  316. * @param {Array.<string|number>} rgb
  317. * @return {Array.<number>}
  318. */
  319. _rgbToHSL: function(rgb)
  320. {
  321. var r = this._individualRGBValueToFloatValue(rgb[0]) / 255;
  322. var g = this._individualRGBValueToFloatValue(rgb[1]) / 255;
  323. var b = this._individualRGBValueToFloatValue(rgb[2]) / 255;
  324. var max = Math.max(r, g, b);
  325. var min = Math.min(r, g, b);
  326. var diff = max - min;
  327. var add = max + min;
  328. if (min === max)
  329. var h = 0;
  330. else if (r === max)
  331. var h = ((60 * (g - b) / diff) + 360) % 360;
  332. else if (g === max)
  333. var h = (60 * (b - r) / diff) + 120;
  334. else
  335. var h = (60 * (r - g) / diff) + 240;
  336. var l = 0.5 * add;
  337. if (l === 0)
  338. var s = 0;
  339. else if (l === 1)
  340. var s = 1;
  341. else if (l <= 0.5)
  342. var s = diff / add;
  343. else
  344. var s = diff / (2 - add);
  345. h = Math.round(h);
  346. s = Math.round(s*100);
  347. l = Math.round(l*100);
  348. return [h, s, l];
  349. },
  350. /**
  351. * @param {Array.<number>} hsl
  352. * @return {Array.<number>}
  353. */
  354. _hslToRGB: function(hsl)
  355. {
  356. var h = parseFloat(hsl[0]) / 360;
  357. var s = parseFloat(hsl[1]) / 100;
  358. var l = parseFloat(hsl[2]) / 100;
  359. if (s < 0)
  360. s = 0;
  361. if (l <= 0.5)
  362. var q = l * (1 + s);
  363. else
  364. var q = l + s - (l * s);
  365. var p = 2 * l - q;
  366. var tr = h + (1 / 3);
  367. var tg = h;
  368. var tb = h - (1 / 3);
  369. var r = Math.round(hueToRGB(p, q, tr) * 255);
  370. var g = Math.round(hueToRGB(p, q, tg) * 255);
  371. var b = Math.round(hueToRGB(p, q, tb) * 255);
  372. return [r, g, b];
  373. function hueToRGB(p, q, h) {
  374. if (h < 0)
  375. h += 1;
  376. else if (h > 1)
  377. h -= 1;
  378. if ((h * 6) < 1)
  379. return p + (q - p) * h * 6;
  380. else if ((h * 2) < 1)
  381. return q;
  382. else if ((h * 3) < 2)
  383. return p + (q - p) * ((2 / 3) - h) * 6;
  384. else
  385. return p;
  386. }
  387. },
  388. /**
  389. * @param {Array.<number>} rgba
  390. * @return {Array.<number>}
  391. */
  392. _rgbaToHSLA: function(rgba, alpha)
  393. {
  394. var hsl = this._rgbToHSL(rgba)
  395. hsl.push(alpha);
  396. return hsl;
  397. },
  398. /**
  399. * @param {Array.<number>} hsla
  400. * @param {number} alpha
  401. * @return {Array.<number>}
  402. */
  403. _hslaToRGBA: function(hsla, alpha)
  404. {
  405. var rgb = this._hslToRGB(hsla);
  406. rgb.push(alpha);
  407. return rgb;
  408. },
  409. _parse: function()
  410. {
  411. // Special Values - Advanced but Must Be Parsed First - transparent
  412. var value = this.value.toLowerCase().replace(/%|\s+/g, "");
  413. if (value in WebInspector.Color.AdvancedNickNames) {
  414. this.format = WebInspector.Color.Format.Nickname;
  415. var set = WebInspector.Color.AdvancedNickNames[value];
  416. this.simple = false;
  417. this.rgba = set[0];
  418. this.hsla = set[1];
  419. this.nickname = set[2];
  420. this.alpha = set[0][3];
  421. return;
  422. }
  423. // Simple - #hex, rgb(), nickname, hsl()
  424. var simple = /^(?:#([0-9a-f]{3,6})|rgb\(([^)]+)\)|(\w+)|hsl\(([^)]+)\))$/i;
  425. var match = this.value.match(simple);
  426. if (match) {
  427. this.simple = true;
  428. if (match[1]) { // hex
  429. var hex = match[1].toUpperCase();
  430. if (hex.length === 3) {
  431. this.format = WebInspector.Color.Format.ShortHEX;
  432. this.hex = hex.charAt(0) + hex.charAt(0) + hex.charAt(1) + hex.charAt(1) + hex.charAt(2) + hex.charAt(2);
  433. } else {
  434. this.format = WebInspector.Color.Format.HEX;
  435. this.hex = hex;
  436. }
  437. } else if (match[2]) { // rgb
  438. this.format = WebInspector.Color.Format.RGB;
  439. var rgb = match[2].split(/\s*,\s*/);
  440. this.rgb = rgb;
  441. this.hex = this._rgbStringsToHex(rgb);
  442. } else if (match[3]) { // nickname
  443. var nickname = match[3].toLowerCase();
  444. if (nickname in WebInspector.Color.Nicknames) {
  445. this.format = WebInspector.Color.Format.Nickname;
  446. this.hex = WebInspector.Color.Nicknames[nickname];
  447. } else // unknown name
  448. throw "unknown color name";
  449. } else if (match[4]) { // hsl
  450. this.format = WebInspector.Color.Format.HSL;
  451. var hsl = match[4].replace(/%/g, "").split(/\s*,\s*/);
  452. this.hsl = hsl;
  453. this.rgb = this._hslToRGB(hsl);
  454. this.hex = this._rgbToHex(this.rgb);
  455. }
  456. // Fill in the values if this is a known hex color
  457. var hex = this.hex;
  458. if (hex && hex in WebInspector.Color.HexTable) {
  459. var set = WebInspector.Color.HexTable[hex];
  460. this.rgb = set[0];
  461. this.hsl = set[1];
  462. this.nickname = set[2];
  463. }
  464. return;
  465. }
  466. // Advanced - rgba(), hsla()
  467. var advanced = /^(?:rgba\(([^)]+)\)|hsla\(([^)]+)\))$/;
  468. match = this.value.match(advanced);
  469. if (match) {
  470. this.simple = false;
  471. if (match[1]) { // rgba
  472. this.format = WebInspector.Color.Format.RGBA;
  473. this.rgba = match[1].split(/\s*,\s*/);
  474. this.rgba[3] = this.alpha = this._clamp(this.rgba[3], 0, 1);
  475. this.hsla = this._rgbaToHSLA(this.rgba, this.alpha);
  476. } else if (match[2]) { // hsla
  477. this.format = WebInspector.Color.Format.HSLA;
  478. this.hsla = match[2].replace(/%/g, "").split(/\s*,\s*/);
  479. this.hsla[3] = this.alpha = this._clamp(this.hsla[3], 0, 1);
  480. this.rgba = this._hslaToRGBA(this.hsla, this.alpha);
  481. }
  482. return;
  483. }
  484. // Could not parse as a valid color
  485. throw "could not parse color";
  486. }
  487. }
  488. // Simple Values: [rgb, hsl, nickname]
  489. WebInspector.Color.HexTable = {
  490. "000000": [[0, 0, 0], [0, 0, 0], "black"],
  491. "000080": [[0, 0, 128], [240, 100, 25], "navy"],
  492. "00008B": [[0, 0, 139], [240, 100, 27], "darkBlue"],
  493. "0000CD": [[0, 0, 205], [240, 100, 40], "mediumBlue"],
  494. "0000FF": [[0, 0, 255], [240, 100, 50], "blue"],
  495. "006400": [[0, 100, 0], [120, 100, 20], "darkGreen"],
  496. "008000": [[0, 128, 0], [120, 100, 25], "green"],
  497. "008080": [[0, 128, 128], [180, 100, 25], "teal"],
  498. "008B8B": [[0, 139, 139], [180, 100, 27], "darkCyan"],
  499. "00BFFF": [[0, 191, 255], [195, 100, 50], "deepSkyBlue"],
  500. "00CED1": [[0, 206, 209], [181, 100, 41], "darkTurquoise"],
  501. "00FA9A": [[0, 250, 154], [157, 100, 49], "mediumSpringGreen"],
  502. "00FF00": [[0, 255, 0], [120, 100, 50], "lime"],
  503. "00FF7F": [[0, 255, 127], [150, 100, 50], "springGreen"],
  504. "00FFFF": [[0, 255, 255], [180, 100, 50], "cyan"],
  505. "191970": [[25, 25, 112], [240, 64, 27], "midnightBlue"],
  506. "1E90FF": [[30, 144, 255], [210, 100, 56], "dodgerBlue"],
  507. "20B2AA": [[32, 178, 170], [177, 70, 41], "lightSeaGreen"],
  508. "228B22": [[34, 139, 34], [120, 61, 34], "forestGreen"],
  509. "2E8B57": [[46, 139, 87], [146, 50, 36], "seaGreen"],
  510. "2F4F4F": [[47, 79, 79], [180, 25, 25], "darkSlateGray"],
  511. "32CD32": [[50, 205, 50], [120, 61, 50], "limeGreen"],
  512. "3CB371": [[60, 179, 113], [147, 50, 47], "mediumSeaGreen"],
  513. "40E0D0": [[64, 224, 208], [174, 72, 56], "turquoise"],
  514. "4169E1": [[65, 105, 225], [225, 73, 57], "royalBlue"],
  515. "4682B4": [[70, 130, 180], [207, 44, 49], "steelBlue"],
  516. "483D8B": [[72, 61, 139], [248, 39, 39], "darkSlateBlue"],
  517. "48D1CC": [[72, 209, 204], [178, 60, 55], "mediumTurquoise"],
  518. "4B0082": [[75, 0, 130], [275, 100, 25], "indigo"],
  519. "556B2F": [[85, 107, 47], [82, 39, 30], "darkOliveGreen"],
  520. "5F9EA0": [[95, 158, 160], [182, 25, 50], "cadetBlue"],
  521. "6495ED": [[100, 149, 237], [219, 79, 66], "cornflowerBlue"],
  522. "66CDAA": [[102, 205, 170], [160, 51, 60], "mediumAquaMarine"],
  523. "696969": [[105, 105, 105], [0, 0, 41], "dimGray"],
  524. "6A5ACD": [[106, 90, 205], [248, 53, 58], "slateBlue"],
  525. "6B8E23": [[107, 142, 35], [80, 60, 35], "oliveDrab"],
  526. "708090": [[112, 128, 144], [210, 13, 50], "slateGray"],
  527. "778899": [[119, 136, 153], [210, 14, 53], "lightSlateGray"],
  528. "7B68EE": [[123, 104, 238], [249, 80, 67], "mediumSlateBlue"],
  529. "7CFC00": [[124, 252, 0], [90, 100, 49], "lawnGreen"],
  530. "7FFF00": [[127, 255, 0], [90, 100, 50], "chartreuse"],
  531. "7FFFD4": [[127, 255, 212], [160, 100, 75], "aquamarine"],
  532. "800000": [[128, 0, 0], [0, 100, 25], "maroon"],
  533. "800080": [[128, 0, 128], [300, 100, 25], "purple"],
  534. "808000": [[128, 128, 0], [60, 100, 25], "olive"],
  535. "808080": [[128, 128, 128], [0, 0, 50], "gray"],
  536. "87CEEB": [[135, 206, 235], [197, 71, 73], "skyBlue"],
  537. "87CEFA": [[135, 206, 250], [203, 92, 75], "lightSkyBlue"],
  538. "8A2BE2": [[138, 43, 226], [271, 76, 53], "blueViolet"],
  539. "8B0000": [[139, 0, 0], [0, 100, 27], "darkRed"],
  540. "8B008B": [[139, 0, 139], [300, 100, 27], "darkMagenta"],
  541. "8B4513": [[139, 69, 19], [25, 76, 31], "saddleBrown"],
  542. "8FBC8F": [[143, 188, 143], [120, 25, 65], "darkSeaGreen"],
  543. "90EE90": [[144, 238, 144], [120, 73, 75], "lightGreen"],
  544. "9370D8": [[147, 112, 219], [260, 60, 65], "mediumPurple"],
  545. "9400D3": [[148, 0, 211], [282, 100, 41], "darkViolet"],
  546. "98FB98": [[152, 251, 152], [120, 93, 79], "paleGreen"],
  547. "9932CC": [[153, 50, 204], [280, 61, 50], "darkOrchid"],
  548. "9ACD32": [[154, 205, 50], [80, 61, 50], "yellowGreen"],
  549. "A0522D": [[160, 82, 45], [19, 56, 40], "sienna"],
  550. "A52A2A": [[165, 42, 42], [0, 59, 41], "brown"],
  551. "A9A9A9": [[169, 169, 169], [0, 0, 66], "darkGray"],
  552. "ADD8E6": [[173, 216, 230], [195, 53, 79], "lightBlue"],
  553. "ADFF2F": [[173, 255, 47], [84, 100, 59], "greenYellow"],
  554. "AFEEEE": [[175, 238, 238], [180, 65, 81], "paleTurquoise"],
  555. "B0C4DE": [[176, 196, 222], [214, 41, 78], "lightSteelBlue"],
  556. "B0E0E6": [[176, 224, 230], [187, 52, 80], "powderBlue"],
  557. "B22222": [[178, 34, 34], [0, 68, 42], "fireBrick"],
  558. "B8860B": [[184, 134, 11], [43, 89, 38], "darkGoldenrod"],
  559. "BA55D3": [[186, 85, 211], [288, 59, 58], "mediumOrchid"],
  560. "BC8F8F": [[188, 143, 143], [0, 25, 65], "rosyBrown"],
  561. "BDB76B": [[189, 183, 107], [56, 38, 58], "darkKhaki"],
  562. "C0C0C0": [[192, 192, 192], [0, 0, 75], "silver"],
  563. "C71585": [[199, 21, 133], [322, 81, 43], "mediumVioletRed"],
  564. "CD5C5C": [[205, 92, 92], [0, 53, 58], "indianRed"],
  565. "CD853F": [[205, 133, 63], [30, 59, 53], "peru"],
  566. "D2691E": [[210, 105, 30], [25, 75, 47], "chocolate"],
  567. "D2B48C": [[210, 180, 140], [34, 44, 69], "tan"],
  568. "D3D3D3": [[211, 211, 211], [0, 0, 83], "lightGrey"],
  569. "D87093": [[219, 112, 147], [340, 60, 65], "paleVioletRed"],
  570. "D8BFD8": [[216, 191, 216], [300, 24, 80], "thistle"],
  571. "DA70D6": [[218, 112, 214], [302, 59, 65], "orchid"],
  572. "DAA520": [[218, 165, 32], [43, 74, 49], "goldenrod"],
  573. "DC143C": [[237, 164, 61], [35, 83, 58], "crimson"],
  574. "DCDCDC": [[220, 220, 220], [0, 0, 86], "gainsboro"],
  575. "DDA0DD": [[221, 160, 221], [300, 47, 75], "plum"],
  576. "DEB887": [[222, 184, 135], [34, 57, 70], "burlyWood"],
  577. "E0FFFF": [[224, 255, 255], [180, 100, 94], "lightCyan"],
  578. "E6E6FA": [[230, 230, 250], [240, 67, 94], "lavender"],
  579. "E9967A": [[233, 150, 122], [15, 72, 70], "darkSalmon"],
  580. "EE82EE": [[238, 130, 238], [300, 76, 72], "violet"],
  581. "EEE8AA": [[238, 232, 170], [55, 67, 80], "paleGoldenrod"],
  582. "F08080": [[240, 128, 128], [0, 79, 72], "lightCoral"],
  583. "F0E68C": [[240, 230, 140], [54, 77, 75], "khaki"],
  584. "F0F8FF": [[240, 248, 255], [208, 100, 97], "aliceBlue"],
  585. "F0FFF0": [[240, 255, 240], [120, 100, 97], "honeyDew"],
  586. "F0FFFF": [[240, 255, 255], [180, 100, 97], "azure"],
  587. "F4A460": [[244, 164, 96], [28, 87, 67], "sandyBrown"],
  588. "F5DEB3": [[245, 222, 179], [39, 77, 83], "wheat"],
  589. "F5F5DC": [[245, 245, 220], [60, 56, 91], "beige"],
  590. "F5F5F5": [[245, 245, 245], [0, 0, 96], "whiteSmoke"],
  591. "F5FFFA": [[245, 255, 250], [150, 100, 98], "mintCream"],
  592. "F8F8FF": [[248, 248, 255], [240, 100, 99], "ghostWhite"],
  593. "FA8072": [[250, 128, 114], [6, 93, 71], "salmon"],
  594. "FAEBD7": [[250, 235, 215], [34, 78, 91], "antiqueWhite"],
  595. "FAF0E6": [[250, 240, 230], [30, 67, 94], "linen"],
  596. "FAFAD2": [[250, 250, 210], [60, 80, 90], "lightGoldenrodYellow"],
  597. "FDF5E6": [[253, 245, 230], [39, 85, 95], "oldLace"],
  598. "FF0000": [[255, 0, 0], [0, 100, 50], "red"],
  599. "FF00FF": [[255, 0, 255], [300, 100, 50], "magenta"],
  600. "FF1493": [[255, 20, 147], [328, 100, 54], "deepPink"],
  601. "FF4500": [[255, 69, 0], [16, 100, 50], "orangeRed"],
  602. "FF6347": [[255, 99, 71], [9, 100, 64], "tomato"],
  603. "FF69B4": [[255, 105, 180], [330, 100, 71], "hotPink"],
  604. "FF7F50": [[255, 127, 80], [16, 100, 66], "coral"],
  605. "FF8C00": [[255, 140, 0], [33, 100, 50], "darkOrange"],
  606. "FFA07A": [[255, 160, 122], [17, 100, 74], "lightSalmon"],
  607. "FFA500": [[255, 165, 0], [39, 100, 50], "orange"],
  608. "FFB6C1": [[255, 182, 193], [351, 100, 86], "lightPink"],
  609. "FFC0CB": [[255, 192, 203], [350, 100, 88], "pink"],
  610. "FFD700": [[255, 215, 0], [51, 100, 50], "gold"],
  611. "FFDAB9": [[255, 218, 185], [28, 100, 86], "peachPuff"],
  612. "FFDEAD": [[255, 222, 173], [36, 100, 84], "navajoWhite"],
  613. "FFE4B5": [[255, 228, 181], [38, 100, 85], "moccasin"],
  614. "FFE4C4": [[255, 228, 196], [33, 100, 88], "bisque"],
  615. "FFE4E1": [[255, 228, 225], [6, 100, 94], "mistyRose"],
  616. "FFEBCD": [[255, 235, 205], [36, 100, 90], "blanchedAlmond"],
  617. "FFEFD5": [[255, 239, 213], [37, 100, 92], "papayaWhip"],
  618. "FFF0F5": [[255, 240, 245], [340, 100, 97], "lavenderBlush"],
  619. "FFF5EE": [[255, 245, 238], [25, 100, 97], "seaShell"],
  620. "FFF8DC": [[255, 248, 220], [48, 100, 93], "cornsilk"],
  621. "FFFACD": [[255, 250, 205], [54, 100, 90], "lemonChiffon"],
  622. "FFFAF0": [[255, 250, 240], [40, 100, 97], "floralWhite"],
  623. "FFFAFA": [[255, 250, 250], [0, 100, 99], "snow"],
  624. "FFFF00": [[255, 255, 0], [60, 100, 50], "yellow"],
  625. "FFFFE0": [[255, 255, 224], [60, 100, 94], "lightYellow"],
  626. "FFFFF0": [[255, 255, 240], [60, 100, 97], "ivory"],
  627. "FFFFFF": [[255, 255, 255], [0, 100, 100], "white"]
  628. };
  629. // Simple Values
  630. WebInspector.Color.Nicknames = {
  631. "aliceblue": "F0F8FF",
  632. "antiquewhite": "FAEBD7",
  633. "aqua": "00FFFF",
  634. "aquamarine": "7FFFD4",
  635. "azure": "F0FFFF",
  636. "beige": "F5F5DC",
  637. "bisque": "FFE4C4",
  638. "black": "000000",
  639. "blanchedalmond": "FFEBCD",
  640. "blue": "0000FF",
  641. "blueviolet": "8A2BE2",
  642. "brown": "A52A2A",
  643. "burlywood": "DEB887",
  644. "cadetblue": "5F9EA0",
  645. "chartreuse": "7FFF00",
  646. "chocolate": "D2691E",
  647. "coral": "FF7F50",
  648. "cornflowerblue": "6495ED",
  649. "cornsilk": "FFF8DC",
  650. "crimson": "DC143C",
  651. "cyan": "00FFFF",
  652. "darkblue": "00008B",
  653. "darkcyan": "008B8B",
  654. "darkgoldenrod": "B8860B",
  655. "darkgray": "A9A9A9",
  656. "darkgreen": "006400",
  657. "darkkhaki": "BDB76B",
  658. "darkmagenta": "8B008B",
  659. "darkolivegreen": "556B2F",
  660. "darkorange": "FF8C00",
  661. "darkorchid": "9932CC",
  662. "darkred": "8B0000",
  663. "darksalmon": "E9967A",
  664. "darkseagreen": "8FBC8F",
  665. "darkslateblue": "483D8B",
  666. "darkslategray": "2F4F4F",
  667. "darkturquoise": "00CED1",
  668. "darkviolet": "9400D3",
  669. "deeppink": "FF1493",
  670. "deepskyblue": "00BFFF",
  671. "dimgray": "696969",
  672. "dodgerblue": "1E90FF",
  673. "firebrick": "B22222",
  674. "floralwhite": "FFFAF0",
  675. "forestgreen": "228B22",
  676. "fuchsia": "FF00FF",
  677. "gainsboro": "DCDCDC",
  678. "ghostwhite": "F8F8FF",
  679. "gold": "FFD700",
  680. "goldenrod": "DAA520",
  681. "gray": "808080",
  682. "green": "008000",
  683. "greenyellow": "ADFF2F",
  684. "honeydew": "F0FFF0",
  685. "hotpink": "FF69B4",
  686. "indianred": "CD5C5C",
  687. "indigo": "4B0082",
  688. "ivory": "FFFFF0",
  689. "khaki": "F0E68C",
  690. "lavender": "E6E6FA",
  691. "lavenderblush": "FFF0F5",
  692. "lawngreen": "7CFC00",
  693. "lemonchiffon": "FFFACD",
  694. "lightblue": "ADD8E6",
  695. "lightcoral": "F08080",
  696. "lightcyan": "E0FFFF",
  697. "lightgoldenrodyellow": "FAFAD2",
  698. "lightgreen": "90EE90",
  699. "lightgrey": "D3D3D3",
  700. "lightpink": "FFB6C1",
  701. "lightsalmon": "FFA07A",
  702. "lightseagreen": "20B2AA",
  703. "lightskyblue": "87CEFA",
  704. "lightslategray": "778899",
  705. "lightsteelblue": "B0C4DE",
  706. "lightyellow": "FFFFE0",
  707. "lime": "00FF00",
  708. "limegreen": "32CD32",
  709. "linen": "FAF0E6",
  710. "magenta": "FF00FF",
  711. "maroon": "800000",
  712. "mediumaquamarine": "66CDAA",
  713. "mediumblue": "0000CD",
  714. "mediumorchid": "BA55D3",
  715. "mediumpurple": "9370DB",
  716. "mediumseagreen": "3CB371",
  717. "mediumslateblue": "7B68EE",
  718. "mediumspringgreen": "00FA9A",
  719. "mediumturquoise": "48D1CC",
  720. "mediumvioletred": "C71585",
  721. "midnightblue": "191970",
  722. "mintcream": "F5FFFA",
  723. "mistyrose": "FFE4E1",
  724. "moccasin": "FFE4B5",
  725. "navajowhite": "FFDEAD",
  726. "navy": "000080",
  727. "oldlace": "FDF5E6",
  728. "olive": "808000",
  729. "olivedrab": "6B8E23",
  730. "orange": "FFA500",
  731. "orangered": "FF4500",
  732. "orchid": "DA70D6",
  733. "palegoldenrod": "EEE8AA",
  734. "palegreen": "98FB98",
  735. "paleturquoise": "AFEEEE",
  736. "palevioletred": "DB7093",
  737. "papayawhip": "FFEFD5",
  738. "peachpuff": "FFDAB9",
  739. "peru": "CD853F",
  740. "pink": "FFC0CB",
  741. "plum": "DDA0DD",
  742. "powderblue": "B0E0E6",
  743. "purple": "800080",
  744. "red": "FF0000",
  745. "rosybrown": "BC8F8F",
  746. "royalblue": "4169E1",
  747. "saddlebrown": "8B4513",
  748. "salmon": "FA8072",
  749. "sandybrown": "F4A460",
  750. "seagreen": "2E8B57",
  751. "seashell": "FFF5EE",
  752. "sienna": "A0522D",
  753. "silver": "C0C0C0",
  754. "skyblue": "87CEEB",
  755. "slateblue": "6A5ACD",
  756. "slategray": "708090",
  757. "snow": "FFFAFA",
  758. "springgreen": "00FF7F",
  759. "steelblue": "4682B4",
  760. "tan": "D2B48C",
  761. "teal": "008080",
  762. "thistle": "D8BFD8",
  763. "tomato": "FF6347",
  764. "turquoise": "40E0D0",
  765. "violet": "EE82EE",
  766. "wheat": "F5DEB3",
  767. "white": "FFFFFF",
  768. "whitesmoke": "F5F5F5",
  769. "yellow": "FFFF00",
  770. "yellowgreen": "9ACD32"
  771. };
  772. // Advanced Values [rgba, hsla, nickname]
  773. WebInspector.Color.AdvancedNickNames = {
  774. "transparent": [[0, 0, 0, 0], [0, 0, 0, 0], "transparent"],
  775. "rgba(0,0,0,0)": [[0, 0, 0, 0], [0, 0, 0, 0], "transparent"],
  776. "hsla(0,0,0,0)": [[0, 0, 0, 0], [0, 0, 0, 0], "transparent"],
  777. };