diagnostics.js 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051
  1. (function(f){var g;if(typeof window!=='undefined'){g=window}else if(typeof self!=='undefined'){g=self}g.diagnostics=f()})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(_dereq_,module,exports){
  2. 'use strict';
  3. var colorspace = _dereq_('colorspace');
  4. var enabled = _dereq_('enabled');
  5. /**
  6. * Bare minimum browser version of diagnostics. It doesn't need fancy pancy
  7. * detection algorithms. The code is only enabled when *you* enable it for
  8. * debugging purposes.
  9. *
  10. * @param {String} name Namespace of the diagnostics instance.
  11. * @returns {Function} The logger.
  12. * @public
  13. */
  14. module.exports = function factory(name) {
  15. if (!enabled(name)) return function diagnopes() {};
  16. //
  17. // The color for the namespace.
  18. //
  19. var color = colorspace(name);
  20. /**
  21. * The actual function that does the logging.
  22. *
  23. * @param {...args} args The data that needs to be logged.
  24. * @public
  25. */
  26. return function diagnostics() {
  27. var args = Array.prototype.slice.call(arguments, 0);
  28. //
  29. // We cannot push a value as first argument of the argument array as
  30. // console's formatting %s, %d only works on the first argument it receives.
  31. // So in order to prepend our namespace we need to override and prefix the
  32. // first argument.
  33. //
  34. args[0] = '%c'+ name +'%c: '+ args[0];
  35. //
  36. // Now we want to inject the colors to the arguments, so they get colored.
  37. // The last empty argh here is to remove the color again so the log message
  38. // is not colored.
  39. //
  40. args.splice(1, 0, 'color:'+ color, '');
  41. //
  42. // So yea. IE8 doesn't have an apply so we need a work around to puke the
  43. // arguments in place.
  44. //
  45. try { Function.prototype.apply.call(console.log, console, args); }
  46. catch (e) {}
  47. };
  48. };
  49. },{"colorspace":7,"enabled":8}],2:[function(_dereq_,module,exports){
  50. /* MIT license */
  51. module.exports = {
  52. rgb2hsl: rgb2hsl,
  53. rgb2hsv: rgb2hsv,
  54. rgb2hwb: rgb2hwb,
  55. rgb2cmyk: rgb2cmyk,
  56. rgb2keyword: rgb2keyword,
  57. rgb2xyz: rgb2xyz,
  58. rgb2lab: rgb2lab,
  59. rgb2lch: rgb2lch,
  60. hsl2rgb: hsl2rgb,
  61. hsl2hsv: hsl2hsv,
  62. hsl2hwb: hsl2hwb,
  63. hsl2cmyk: hsl2cmyk,
  64. hsl2keyword: hsl2keyword,
  65. hsv2rgb: hsv2rgb,
  66. hsv2hsl: hsv2hsl,
  67. hsv2hwb: hsv2hwb,
  68. hsv2cmyk: hsv2cmyk,
  69. hsv2keyword: hsv2keyword,
  70. hwb2rgb: hwb2rgb,
  71. hwb2hsl: hwb2hsl,
  72. hwb2hsv: hwb2hsv,
  73. hwb2cmyk: hwb2cmyk,
  74. hwb2keyword: hwb2keyword,
  75. cmyk2rgb: cmyk2rgb,
  76. cmyk2hsl: cmyk2hsl,
  77. cmyk2hsv: cmyk2hsv,
  78. cmyk2hwb: cmyk2hwb,
  79. cmyk2keyword: cmyk2keyword,
  80. keyword2rgb: keyword2rgb,
  81. keyword2hsl: keyword2hsl,
  82. keyword2hsv: keyword2hsv,
  83. keyword2hwb: keyword2hwb,
  84. keyword2cmyk: keyword2cmyk,
  85. keyword2lab: keyword2lab,
  86. keyword2xyz: keyword2xyz,
  87. xyz2rgb: xyz2rgb,
  88. xyz2lab: xyz2lab,
  89. xyz2lch: xyz2lch,
  90. lab2xyz: lab2xyz,
  91. lab2rgb: lab2rgb,
  92. lab2lch: lab2lch,
  93. lch2lab: lch2lab,
  94. lch2xyz: lch2xyz,
  95. lch2rgb: lch2rgb
  96. }
  97. function rgb2hsl(rgb) {
  98. var r = rgb[0]/255,
  99. g = rgb[1]/255,
  100. b = rgb[2]/255,
  101. min = Math.min(r, g, b),
  102. max = Math.max(r, g, b),
  103. delta = max - min,
  104. h, s, l;
  105. if (max == min)
  106. h = 0;
  107. else if (r == max)
  108. h = (g - b) / delta;
  109. else if (g == max)
  110. h = 2 + (b - r) / delta;
  111. else if (b == max)
  112. h = 4 + (r - g)/ delta;
  113. h = Math.min(h * 60, 360);
  114. if (h < 0)
  115. h += 360;
  116. l = (min + max) / 2;
  117. if (max == min)
  118. s = 0;
  119. else if (l <= 0.5)
  120. s = delta / (max + min);
  121. else
  122. s = delta / (2 - max - min);
  123. return [h, s * 100, l * 100];
  124. }
  125. function rgb2hsv(rgb) {
  126. var r = rgb[0],
  127. g = rgb[1],
  128. b = rgb[2],
  129. min = Math.min(r, g, b),
  130. max = Math.max(r, g, b),
  131. delta = max - min,
  132. h, s, v;
  133. if (max == 0)
  134. s = 0;
  135. else
  136. s = (delta/max * 1000)/10;
  137. if (max == min)
  138. h = 0;
  139. else if (r == max)
  140. h = (g - b) / delta;
  141. else if (g == max)
  142. h = 2 + (b - r) / delta;
  143. else if (b == max)
  144. h = 4 + (r - g) / delta;
  145. h = Math.min(h * 60, 360);
  146. if (h < 0)
  147. h += 360;
  148. v = ((max / 255) * 1000) / 10;
  149. return [h, s, v];
  150. }
  151. function rgb2hwb(rgb) {
  152. var r = rgb[0],
  153. g = rgb[1],
  154. b = rgb[2],
  155. h = rgb2hsl(rgb)[0],
  156. w = 1/255 * Math.min(r, Math.min(g, b)),
  157. b = 1 - 1/255 * Math.max(r, Math.max(g, b));
  158. return [h, w * 100, b * 100];
  159. }
  160. function rgb2cmyk(rgb) {
  161. var r = rgb[0] / 255,
  162. g = rgb[1] / 255,
  163. b = rgb[2] / 255,
  164. c, m, y, k;
  165. k = Math.min(1 - r, 1 - g, 1 - b);
  166. c = (1 - r - k) / (1 - k) || 0;
  167. m = (1 - g - k) / (1 - k) || 0;
  168. y = (1 - b - k) / (1 - k) || 0;
  169. return [c * 100, m * 100, y * 100, k * 100];
  170. }
  171. function rgb2keyword(rgb) {
  172. return reverseKeywords[JSON.stringify(rgb)];
  173. }
  174. function rgb2xyz(rgb) {
  175. var r = rgb[0] / 255,
  176. g = rgb[1] / 255,
  177. b = rgb[2] / 255;
  178. // assume sRGB
  179. r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055), 2.4) : (r / 12.92);
  180. g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055), 2.4) : (g / 12.92);
  181. b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055), 2.4) : (b / 12.92);
  182. var x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805);
  183. var y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722);
  184. var z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505);
  185. return [x * 100, y *100, z * 100];
  186. }
  187. function rgb2lab(rgb) {
  188. var xyz = rgb2xyz(rgb),
  189. x = xyz[0],
  190. y = xyz[1],
  191. z = xyz[2],
  192. l, a, b;
  193. x /= 95.047;
  194. y /= 100;
  195. z /= 108.883;
  196. x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116);
  197. y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116);
  198. z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116);
  199. l = (116 * y) - 16;
  200. a = 500 * (x - y);
  201. b = 200 * (y - z);
  202. return [l, a, b];
  203. }
  204. function rgb2lch(args) {
  205. return lab2lch(rgb2lab(args));
  206. }
  207. function hsl2rgb(hsl) {
  208. var h = hsl[0] / 360,
  209. s = hsl[1] / 100,
  210. l = hsl[2] / 100,
  211. t1, t2, t3, rgb, val;
  212. if (s == 0) {
  213. val = l * 255;
  214. return [val, val, val];
  215. }
  216. if (l < 0.5)
  217. t2 = l * (1 + s);
  218. else
  219. t2 = l + s - l * s;
  220. t1 = 2 * l - t2;
  221. rgb = [0, 0, 0];
  222. for (var i = 0; i < 3; i++) {
  223. t3 = h + 1 / 3 * - (i - 1);
  224. t3 < 0 && t3++;
  225. t3 > 1 && t3--;
  226. if (6 * t3 < 1)
  227. val = t1 + (t2 - t1) * 6 * t3;
  228. else if (2 * t3 < 1)
  229. val = t2;
  230. else if (3 * t3 < 2)
  231. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  232. else
  233. val = t1;
  234. rgb[i] = val * 255;
  235. }
  236. return rgb;
  237. }
  238. function hsl2hsv(hsl) {
  239. var h = hsl[0],
  240. s = hsl[1] / 100,
  241. l = hsl[2] / 100,
  242. sv, v;
  243. if(l === 0) {
  244. // no need to do calc on black
  245. // also avoids divide by 0 error
  246. return [0, 0, 0];
  247. }
  248. l *= 2;
  249. s *= (l <= 1) ? l : 2 - l;
  250. v = (l + s) / 2;
  251. sv = (2 * s) / (l + s);
  252. return [h, sv * 100, v * 100];
  253. }
  254. function hsl2hwb(args) {
  255. return rgb2hwb(hsl2rgb(args));
  256. }
  257. function hsl2cmyk(args) {
  258. return rgb2cmyk(hsl2rgb(args));
  259. }
  260. function hsl2keyword(args) {
  261. return rgb2keyword(hsl2rgb(args));
  262. }
  263. function hsv2rgb(hsv) {
  264. var h = hsv[0] / 60,
  265. s = hsv[1] / 100,
  266. v = hsv[2] / 100,
  267. hi = Math.floor(h) % 6;
  268. var f = h - Math.floor(h),
  269. p = 255 * v * (1 - s),
  270. q = 255 * v * (1 - (s * f)),
  271. t = 255 * v * (1 - (s * (1 - f))),
  272. v = 255 * v;
  273. switch(hi) {
  274. case 0:
  275. return [v, t, p];
  276. case 1:
  277. return [q, v, p];
  278. case 2:
  279. return [p, v, t];
  280. case 3:
  281. return [p, q, v];
  282. case 4:
  283. return [t, p, v];
  284. case 5:
  285. return [v, p, q];
  286. }
  287. }
  288. function hsv2hsl(hsv) {
  289. var h = hsv[0],
  290. s = hsv[1] / 100,
  291. v = hsv[2] / 100,
  292. sl, l;
  293. l = (2 - s) * v;
  294. sl = s * v;
  295. sl /= (l <= 1) ? l : 2 - l;
  296. sl = sl || 0;
  297. l /= 2;
  298. return [h, sl * 100, l * 100];
  299. }
  300. function hsv2hwb(args) {
  301. return rgb2hwb(hsv2rgb(args))
  302. }
  303. function hsv2cmyk(args) {
  304. return rgb2cmyk(hsv2rgb(args));
  305. }
  306. function hsv2keyword(args) {
  307. return rgb2keyword(hsv2rgb(args));
  308. }
  309. // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  310. function hwb2rgb(hwb) {
  311. var h = hwb[0] / 360,
  312. wh = hwb[1] / 100,
  313. bl = hwb[2] / 100,
  314. ratio = wh + bl,
  315. i, v, f, n;
  316. // wh + bl cant be > 1
  317. if (ratio > 1) {
  318. wh /= ratio;
  319. bl /= ratio;
  320. }
  321. i = Math.floor(6 * h);
  322. v = 1 - bl;
  323. f = 6 * h - i;
  324. if ((i & 0x01) != 0) {
  325. f = 1 - f;
  326. }
  327. n = wh + f * (v - wh); // linear interpolation
  328. switch (i) {
  329. default:
  330. case 6:
  331. case 0: r = v; g = n; b = wh; break;
  332. case 1: r = n; g = v; b = wh; break;
  333. case 2: r = wh; g = v; b = n; break;
  334. case 3: r = wh; g = n; b = v; break;
  335. case 4: r = n; g = wh; b = v; break;
  336. case 5: r = v; g = wh; b = n; break;
  337. }
  338. return [r * 255, g * 255, b * 255];
  339. }
  340. function hwb2hsl(args) {
  341. return rgb2hsl(hwb2rgb(args));
  342. }
  343. function hwb2hsv(args) {
  344. return rgb2hsv(hwb2rgb(args));
  345. }
  346. function hwb2cmyk(args) {
  347. return rgb2cmyk(hwb2rgb(args));
  348. }
  349. function hwb2keyword(args) {
  350. return rgb2keyword(hwb2rgb(args));
  351. }
  352. function cmyk2rgb(cmyk) {
  353. var c = cmyk[0] / 100,
  354. m = cmyk[1] / 100,
  355. y = cmyk[2] / 100,
  356. k = cmyk[3] / 100,
  357. r, g, b;
  358. r = 1 - Math.min(1, c * (1 - k) + k);
  359. g = 1 - Math.min(1, m * (1 - k) + k);
  360. b = 1 - Math.min(1, y * (1 - k) + k);
  361. return [r * 255, g * 255, b * 255];
  362. }
  363. function cmyk2hsl(args) {
  364. return rgb2hsl(cmyk2rgb(args));
  365. }
  366. function cmyk2hsv(args) {
  367. return rgb2hsv(cmyk2rgb(args));
  368. }
  369. function cmyk2hwb(args) {
  370. return rgb2hwb(cmyk2rgb(args));
  371. }
  372. function cmyk2keyword(args) {
  373. return rgb2keyword(cmyk2rgb(args));
  374. }
  375. function xyz2rgb(xyz) {
  376. var x = xyz[0] / 100,
  377. y = xyz[1] / 100,
  378. z = xyz[2] / 100,
  379. r, g, b;
  380. r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986);
  381. g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415);
  382. b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570);
  383. // assume sRGB
  384. r = r > 0.0031308 ? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055)
  385. : r = (r * 12.92);
  386. g = g > 0.0031308 ? ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055)
  387. : g = (g * 12.92);
  388. b = b > 0.0031308 ? ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055)
  389. : b = (b * 12.92);
  390. r = Math.min(Math.max(0, r), 1);
  391. g = Math.min(Math.max(0, g), 1);
  392. b = Math.min(Math.max(0, b), 1);
  393. return [r * 255, g * 255, b * 255];
  394. }
  395. function xyz2lab(xyz) {
  396. var x = xyz[0],
  397. y = xyz[1],
  398. z = xyz[2],
  399. l, a, b;
  400. x /= 95.047;
  401. y /= 100;
  402. z /= 108.883;
  403. x = x > 0.008856 ? Math.pow(x, 1/3) : (7.787 * x) + (16 / 116);
  404. y = y > 0.008856 ? Math.pow(y, 1/3) : (7.787 * y) + (16 / 116);
  405. z = z > 0.008856 ? Math.pow(z, 1/3) : (7.787 * z) + (16 / 116);
  406. l = (116 * y) - 16;
  407. a = 500 * (x - y);
  408. b = 200 * (y - z);
  409. return [l, a, b];
  410. }
  411. function xyz2lch(args) {
  412. return lab2lch(xyz2lab(args));
  413. }
  414. function lab2xyz(lab) {
  415. var l = lab[0],
  416. a = lab[1],
  417. b = lab[2],
  418. x, y, z, y2;
  419. if (l <= 8) {
  420. y = (l * 100) / 903.3;
  421. y2 = (7.787 * (y / 100)) + (16 / 116);
  422. } else {
  423. y = 100 * Math.pow((l + 16) / 116, 3);
  424. y2 = Math.pow(y / 100, 1/3);
  425. }
  426. x = x / 95.047 <= 0.008856 ? x = (95.047 * ((a / 500) + y2 - (16 / 116))) / 7.787 : 95.047 * Math.pow((a / 500) + y2, 3);
  427. z = z / 108.883 <= 0.008859 ? z = (108.883 * (y2 - (b / 200) - (16 / 116))) / 7.787 : 108.883 * Math.pow(y2 - (b / 200), 3);
  428. return [x, y, z];
  429. }
  430. function lab2lch(lab) {
  431. var l = lab[0],
  432. a = lab[1],
  433. b = lab[2],
  434. hr, h, c;
  435. hr = Math.atan2(b, a);
  436. h = hr * 360 / 2 / Math.PI;
  437. if (h < 0) {
  438. h += 360;
  439. }
  440. c = Math.sqrt(a * a + b * b);
  441. return [l, c, h];
  442. }
  443. function lab2rgb(args) {
  444. return xyz2rgb(lab2xyz(args));
  445. }
  446. function lch2lab(lch) {
  447. var l = lch[0],
  448. c = lch[1],
  449. h = lch[2],
  450. a, b, hr;
  451. hr = h / 360 * 2 * Math.PI;
  452. a = c * Math.cos(hr);
  453. b = c * Math.sin(hr);
  454. return [l, a, b];
  455. }
  456. function lch2xyz(args) {
  457. return lab2xyz(lch2lab(args));
  458. }
  459. function lch2rgb(args) {
  460. return lab2rgb(lch2lab(args));
  461. }
  462. function keyword2rgb(keyword) {
  463. return cssKeywords[keyword];
  464. }
  465. function keyword2hsl(args) {
  466. return rgb2hsl(keyword2rgb(args));
  467. }
  468. function keyword2hsv(args) {
  469. return rgb2hsv(keyword2rgb(args));
  470. }
  471. function keyword2hwb(args) {
  472. return rgb2hwb(keyword2rgb(args));
  473. }
  474. function keyword2cmyk(args) {
  475. return rgb2cmyk(keyword2rgb(args));
  476. }
  477. function keyword2lab(args) {
  478. return rgb2lab(keyword2rgb(args));
  479. }
  480. function keyword2xyz(args) {
  481. return rgb2xyz(keyword2rgb(args));
  482. }
  483. var cssKeywords = {
  484. aliceblue: [240,248,255],
  485. antiquewhite: [250,235,215],
  486. aqua: [0,255,255],
  487. aquamarine: [127,255,212],
  488. azure: [240,255,255],
  489. beige: [245,245,220],
  490. bisque: [255,228,196],
  491. black: [0,0,0],
  492. blanchedalmond: [255,235,205],
  493. blue: [0,0,255],
  494. blueviolet: [138,43,226],
  495. brown: [165,42,42],
  496. burlywood: [222,184,135],
  497. cadetblue: [95,158,160],
  498. chartreuse: [127,255,0],
  499. chocolate: [210,105,30],
  500. coral: [255,127,80],
  501. cornflowerblue: [100,149,237],
  502. cornsilk: [255,248,220],
  503. crimson: [220,20,60],
  504. cyan: [0,255,255],
  505. darkblue: [0,0,139],
  506. darkcyan: [0,139,139],
  507. darkgoldenrod: [184,134,11],
  508. darkgray: [169,169,169],
  509. darkgreen: [0,100,0],
  510. darkgrey: [169,169,169],
  511. darkkhaki: [189,183,107],
  512. darkmagenta: [139,0,139],
  513. darkolivegreen: [85,107,47],
  514. darkorange: [255,140,0],
  515. darkorchid: [153,50,204],
  516. darkred: [139,0,0],
  517. darksalmon: [233,150,122],
  518. darkseagreen: [143,188,143],
  519. darkslateblue: [72,61,139],
  520. darkslategray: [47,79,79],
  521. darkslategrey: [47,79,79],
  522. darkturquoise: [0,206,209],
  523. darkviolet: [148,0,211],
  524. deeppink: [255,20,147],
  525. deepskyblue: [0,191,255],
  526. dimgray: [105,105,105],
  527. dimgrey: [105,105,105],
  528. dodgerblue: [30,144,255],
  529. firebrick: [178,34,34],
  530. floralwhite: [255,250,240],
  531. forestgreen: [34,139,34],
  532. fuchsia: [255,0,255],
  533. gainsboro: [220,220,220],
  534. ghostwhite: [248,248,255],
  535. gold: [255,215,0],
  536. goldenrod: [218,165,32],
  537. gray: [128,128,128],
  538. green: [0,128,0],
  539. greenyellow: [173,255,47],
  540. grey: [128,128,128],
  541. honeydew: [240,255,240],
  542. hotpink: [255,105,180],
  543. indianred: [205,92,92],
  544. indigo: [75,0,130],
  545. ivory: [255,255,240],
  546. khaki: [240,230,140],
  547. lavender: [230,230,250],
  548. lavenderblush: [255,240,245],
  549. lawngreen: [124,252,0],
  550. lemonchiffon: [255,250,205],
  551. lightblue: [173,216,230],
  552. lightcoral: [240,128,128],
  553. lightcyan: [224,255,255],
  554. lightgoldenrodyellow: [250,250,210],
  555. lightgray: [211,211,211],
  556. lightgreen: [144,238,144],
  557. lightgrey: [211,211,211],
  558. lightpink: [255,182,193],
  559. lightsalmon: [255,160,122],
  560. lightseagreen: [32,178,170],
  561. lightskyblue: [135,206,250],
  562. lightslategray: [119,136,153],
  563. lightslategrey: [119,136,153],
  564. lightsteelblue: [176,196,222],
  565. lightyellow: [255,255,224],
  566. lime: [0,255,0],
  567. limegreen: [50,205,50],
  568. linen: [250,240,230],
  569. magenta: [255,0,255],
  570. maroon: [128,0,0],
  571. mediumaquamarine: [102,205,170],
  572. mediumblue: [0,0,205],
  573. mediumorchid: [186,85,211],
  574. mediumpurple: [147,112,219],
  575. mediumseagreen: [60,179,113],
  576. mediumslateblue: [123,104,238],
  577. mediumspringgreen: [0,250,154],
  578. mediumturquoise: [72,209,204],
  579. mediumvioletred: [199,21,133],
  580. midnightblue: [25,25,112],
  581. mintcream: [245,255,250],
  582. mistyrose: [255,228,225],
  583. moccasin: [255,228,181],
  584. navajowhite: [255,222,173],
  585. navy: [0,0,128],
  586. oldlace: [253,245,230],
  587. olive: [128,128,0],
  588. olivedrab: [107,142,35],
  589. orange: [255,165,0],
  590. orangered: [255,69,0],
  591. orchid: [218,112,214],
  592. palegoldenrod: [238,232,170],
  593. palegreen: [152,251,152],
  594. paleturquoise: [175,238,238],
  595. palevioletred: [219,112,147],
  596. papayawhip: [255,239,213],
  597. peachpuff: [255,218,185],
  598. peru: [205,133,63],
  599. pink: [255,192,203],
  600. plum: [221,160,221],
  601. powderblue: [176,224,230],
  602. purple: [128,0,128],
  603. rebeccapurple: [102, 51, 153],
  604. red: [255,0,0],
  605. rosybrown: [188,143,143],
  606. royalblue: [65,105,225],
  607. saddlebrown: [139,69,19],
  608. salmon: [250,128,114],
  609. sandybrown: [244,164,96],
  610. seagreen: [46,139,87],
  611. seashell: [255,245,238],
  612. sienna: [160,82,45],
  613. silver: [192,192,192],
  614. skyblue: [135,206,235],
  615. slateblue: [106,90,205],
  616. slategray: [112,128,144],
  617. slategrey: [112,128,144],
  618. snow: [255,250,250],
  619. springgreen: [0,255,127],
  620. steelblue: [70,130,180],
  621. tan: [210,180,140],
  622. teal: [0,128,128],
  623. thistle: [216,191,216],
  624. tomato: [255,99,71],
  625. turquoise: [64,224,208],
  626. violet: [238,130,238],
  627. wheat: [245,222,179],
  628. white: [255,255,255],
  629. whitesmoke: [245,245,245],
  630. yellow: [255,255,0],
  631. yellowgreen: [154,205,50]
  632. };
  633. var reverseKeywords = {};
  634. for (var key in cssKeywords) {
  635. reverseKeywords[JSON.stringify(cssKeywords[key])] = key;
  636. }
  637. },{}],3:[function(_dereq_,module,exports){
  638. var conversions = _dereq_("./conversions");
  639. var convert = function() {
  640. return new Converter();
  641. }
  642. for (var func in conversions) {
  643. // export Raw versions
  644. convert[func + "Raw"] = (function(func) {
  645. // accept array or plain args
  646. return function(arg) {
  647. if (typeof arg == "number")
  648. arg = Array.prototype.slice.call(arguments);
  649. return conversions[func](arg);
  650. }
  651. })(func);
  652. var pair = /(\w+)2(\w+)/.exec(func),
  653. from = pair[1],
  654. to = pair[2];
  655. // export rgb2hsl and ["rgb"]["hsl"]
  656. convert[from] = convert[from] || {};
  657. convert[from][to] = convert[func] = (function(func) {
  658. return function(arg) {
  659. if (typeof arg == "number")
  660. arg = Array.prototype.slice.call(arguments);
  661. var val = conversions[func](arg);
  662. if (typeof val == "string" || val === undefined)
  663. return val; // keyword
  664. for (var i = 0; i < val.length; i++)
  665. val[i] = Math.round(val[i]);
  666. return val;
  667. }
  668. })(func);
  669. }
  670. /* Converter does lazy conversion and caching */
  671. var Converter = function() {
  672. this.convs = {};
  673. };
  674. /* Either get the values for a space or
  675. set the values for a space, depending on args */
  676. Converter.prototype.routeSpace = function(space, args) {
  677. var values = args[0];
  678. if (values === undefined) {
  679. // color.rgb()
  680. return this.getValues(space);
  681. }
  682. // color.rgb(10, 10, 10)
  683. if (typeof values == "number") {
  684. values = Array.prototype.slice.call(args);
  685. }
  686. return this.setValues(space, values);
  687. };
  688. /* Set the values for a space, invalidating cache */
  689. Converter.prototype.setValues = function(space, values) {
  690. this.space = space;
  691. this.convs = {};
  692. this.convs[space] = values;
  693. return this;
  694. };
  695. /* Get the values for a space. If there's already
  696. a conversion for the space, fetch it, otherwise
  697. compute it */
  698. Converter.prototype.getValues = function(space) {
  699. var vals = this.convs[space];
  700. if (!vals) {
  701. var fspace = this.space,
  702. from = this.convs[fspace];
  703. vals = convert[fspace][space](from);
  704. this.convs[space] = vals;
  705. }
  706. return vals;
  707. };
  708. ["rgb", "hsl", "hsv", "cmyk", "keyword"].forEach(function(space) {
  709. Converter.prototype[space] = function(vals) {
  710. return this.routeSpace(space, arguments);
  711. }
  712. });
  713. module.exports = convert;
  714. },{"./conversions":2}],4:[function(_dereq_,module,exports){
  715. 'use strict'
  716. module.exports = {
  717. "aliceblue": [240, 248, 255],
  718. "antiquewhite": [250, 235, 215],
  719. "aqua": [0, 255, 255],
  720. "aquamarine": [127, 255, 212],
  721. "azure": [240, 255, 255],
  722. "beige": [245, 245, 220],
  723. "bisque": [255, 228, 196],
  724. "black": [0, 0, 0],
  725. "blanchedalmond": [255, 235, 205],
  726. "blue": [0, 0, 255],
  727. "blueviolet": [138, 43, 226],
  728. "brown": [165, 42, 42],
  729. "burlywood": [222, 184, 135],
  730. "cadetblue": [95, 158, 160],
  731. "chartreuse": [127, 255, 0],
  732. "chocolate": [210, 105, 30],
  733. "coral": [255, 127, 80],
  734. "cornflowerblue": [100, 149, 237],
  735. "cornsilk": [255, 248, 220],
  736. "crimson": [220, 20, 60],
  737. "cyan": [0, 255, 255],
  738. "darkblue": [0, 0, 139],
  739. "darkcyan": [0, 139, 139],
  740. "darkgoldenrod": [184, 134, 11],
  741. "darkgray": [169, 169, 169],
  742. "darkgreen": [0, 100, 0],
  743. "darkgrey": [169, 169, 169],
  744. "darkkhaki": [189, 183, 107],
  745. "darkmagenta": [139, 0, 139],
  746. "darkolivegreen": [85, 107, 47],
  747. "darkorange": [255, 140, 0],
  748. "darkorchid": [153, 50, 204],
  749. "darkred": [139, 0, 0],
  750. "darksalmon": [233, 150, 122],
  751. "darkseagreen": [143, 188, 143],
  752. "darkslateblue": [72, 61, 139],
  753. "darkslategray": [47, 79, 79],
  754. "darkslategrey": [47, 79, 79],
  755. "darkturquoise": [0, 206, 209],
  756. "darkviolet": [148, 0, 211],
  757. "deeppink": [255, 20, 147],
  758. "deepskyblue": [0, 191, 255],
  759. "dimgray": [105, 105, 105],
  760. "dimgrey": [105, 105, 105],
  761. "dodgerblue": [30, 144, 255],
  762. "firebrick": [178, 34, 34],
  763. "floralwhite": [255, 250, 240],
  764. "forestgreen": [34, 139, 34],
  765. "fuchsia": [255, 0, 255],
  766. "gainsboro": [220, 220, 220],
  767. "ghostwhite": [248, 248, 255],
  768. "gold": [255, 215, 0],
  769. "goldenrod": [218, 165, 32],
  770. "gray": [128, 128, 128],
  771. "green": [0, 128, 0],
  772. "greenyellow": [173, 255, 47],
  773. "grey": [128, 128, 128],
  774. "honeydew": [240, 255, 240],
  775. "hotpink": [255, 105, 180],
  776. "indianred": [205, 92, 92],
  777. "indigo": [75, 0, 130],
  778. "ivory": [255, 255, 240],
  779. "khaki": [240, 230, 140],
  780. "lavender": [230, 230, 250],
  781. "lavenderblush": [255, 240, 245],
  782. "lawngreen": [124, 252, 0],
  783. "lemonchiffon": [255, 250, 205],
  784. "lightblue": [173, 216, 230],
  785. "lightcoral": [240, 128, 128],
  786. "lightcyan": [224, 255, 255],
  787. "lightgoldenrodyellow": [250, 250, 210],
  788. "lightgray": [211, 211, 211],
  789. "lightgreen": [144, 238, 144],
  790. "lightgrey": [211, 211, 211],
  791. "lightpink": [255, 182, 193],
  792. "lightsalmon": [255, 160, 122],
  793. "lightseagreen": [32, 178, 170],
  794. "lightskyblue": [135, 206, 250],
  795. "lightslategray": [119, 136, 153],
  796. "lightslategrey": [119, 136, 153],
  797. "lightsteelblue": [176, 196, 222],
  798. "lightyellow": [255, 255, 224],
  799. "lime": [0, 255, 0],
  800. "limegreen": [50, 205, 50],
  801. "linen": [250, 240, 230],
  802. "magenta": [255, 0, 255],
  803. "maroon": [128, 0, 0],
  804. "mediumaquamarine": [102, 205, 170],
  805. "mediumblue": [0, 0, 205],
  806. "mediumorchid": [186, 85, 211],
  807. "mediumpurple": [147, 112, 219],
  808. "mediumseagreen": [60, 179, 113],
  809. "mediumslateblue": [123, 104, 238],
  810. "mediumspringgreen": [0, 250, 154],
  811. "mediumturquoise": [72, 209, 204],
  812. "mediumvioletred": [199, 21, 133],
  813. "midnightblue": [25, 25, 112],
  814. "mintcream": [245, 255, 250],
  815. "mistyrose": [255, 228, 225],
  816. "moccasin": [255, 228, 181],
  817. "navajowhite": [255, 222, 173],
  818. "navy": [0, 0, 128],
  819. "oldlace": [253, 245, 230],
  820. "olive": [128, 128, 0],
  821. "olivedrab": [107, 142, 35],
  822. "orange": [255, 165, 0],
  823. "orangered": [255, 69, 0],
  824. "orchid": [218, 112, 214],
  825. "palegoldenrod": [238, 232, 170],
  826. "palegreen": [152, 251, 152],
  827. "paleturquoise": [175, 238, 238],
  828. "palevioletred": [219, 112, 147],
  829. "papayawhip": [255, 239, 213],
  830. "peachpuff": [255, 218, 185],
  831. "peru": [205, 133, 63],
  832. "pink": [255, 192, 203],
  833. "plum": [221, 160, 221],
  834. "powderblue": [176, 224, 230],
  835. "purple": [128, 0, 128],
  836. "rebeccapurple": [102, 51, 153],
  837. "red": [255, 0, 0],
  838. "rosybrown": [188, 143, 143],
  839. "royalblue": [65, 105, 225],
  840. "saddlebrown": [139, 69, 19],
  841. "salmon": [250, 128, 114],
  842. "sandybrown": [244, 164, 96],
  843. "seagreen": [46, 139, 87],
  844. "seashell": [255, 245, 238],
  845. "sienna": [160, 82, 45],
  846. "silver": [192, 192, 192],
  847. "skyblue": [135, 206, 235],
  848. "slateblue": [106, 90, 205],
  849. "slategray": [112, 128, 144],
  850. "slategrey": [112, 128, 144],
  851. "snow": [255, 250, 250],
  852. "springgreen": [0, 255, 127],
  853. "steelblue": [70, 130, 180],
  854. "tan": [210, 180, 140],
  855. "teal": [0, 128, 128],
  856. "thistle": [216, 191, 216],
  857. "tomato": [255, 99, 71],
  858. "turquoise": [64, 224, 208],
  859. "violet": [238, 130, 238],
  860. "wheat": [245, 222, 179],
  861. "white": [255, 255, 255],
  862. "whitesmoke": [245, 245, 245],
  863. "yellow": [255, 255, 0],
  864. "yellowgreen": [154, 205, 50]
  865. };
  866. },{}],5:[function(_dereq_,module,exports){
  867. /* MIT license */
  868. var colorNames = _dereq_('color-name');
  869. module.exports = {
  870. getRgba: getRgba,
  871. getHsla: getHsla,
  872. getRgb: getRgb,
  873. getHsl: getHsl,
  874. getHwb: getHwb,
  875. getAlpha: getAlpha,
  876. hexString: hexString,
  877. rgbString: rgbString,
  878. rgbaString: rgbaString,
  879. percentString: percentString,
  880. percentaString: percentaString,
  881. hslString: hslString,
  882. hslaString: hslaString,
  883. hwbString: hwbString,
  884. keyword: keyword
  885. }
  886. function getRgba(string) {
  887. if (!string) {
  888. return;
  889. }
  890. var abbr = /^#([a-fA-F0-9]{3})$/,
  891. hex = /^#([a-fA-F0-9]{6})$/,
  892. rgba = /^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/,
  893. per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/,
  894. keyword = /(\D+)/;
  895. var rgb = [0, 0, 0],
  896. a = 1,
  897. match = string.match(abbr);
  898. if (match) {
  899. match = match[1];
  900. for (var i = 0; i < rgb.length; i++) {
  901. rgb[i] = parseInt(match[i] + match[i], 16);
  902. }
  903. }
  904. else if (match = string.match(hex)) {
  905. match = match[1];
  906. for (var i = 0; i < rgb.length; i++) {
  907. rgb[i] = parseInt(match.slice(i * 2, i * 2 + 2), 16);
  908. }
  909. }
  910. else if (match = string.match(rgba)) {
  911. for (var i = 0; i < rgb.length; i++) {
  912. rgb[i] = parseInt(match[i + 1]);
  913. }
  914. a = parseFloat(match[4]);
  915. }
  916. else if (match = string.match(per)) {
  917. for (var i = 0; i < rgb.length; i++) {
  918. rgb[i] = Math.round(parseFloat(match[i + 1]) * 2.55);
  919. }
  920. a = parseFloat(match[4]);
  921. }
  922. else if (match = string.match(keyword)) {
  923. if (match[1] == "transparent") {
  924. return [0, 0, 0, 0];
  925. }
  926. rgb = colorNames[match[1]];
  927. if (!rgb) {
  928. return;
  929. }
  930. }
  931. for (var i = 0; i < rgb.length; i++) {
  932. rgb[i] = scale(rgb[i], 0, 255);
  933. }
  934. if (!a && a != 0) {
  935. a = 1;
  936. }
  937. else {
  938. a = scale(a, 0, 1);
  939. }
  940. rgb[3] = a;
  941. return rgb;
  942. }
  943. function getHsla(string) {
  944. if (!string) {
  945. return;
  946. }
  947. var hsl = /^hsla?\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/;
  948. var match = string.match(hsl);
  949. if (match) {
  950. var alpha = parseFloat(match[4]);
  951. var h = scale(parseInt(match[1]), 0, 360),
  952. s = scale(parseFloat(match[2]), 0, 100),
  953. l = scale(parseFloat(match[3]), 0, 100),
  954. a = scale(isNaN(alpha) ? 1 : alpha, 0, 1);
  955. return [h, s, l, a];
  956. }
  957. }
  958. function getHwb(string) {
  959. if (!string) {
  960. return;
  961. }
  962. var hwb = /^hwb\(\s*([+-]?\d+)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)/;
  963. var match = string.match(hwb);
  964. if (match) {
  965. var alpha = parseFloat(match[4]);
  966. var h = scale(parseInt(match[1]), 0, 360),
  967. w = scale(parseFloat(match[2]), 0, 100),
  968. b = scale(parseFloat(match[3]), 0, 100),
  969. a = scale(isNaN(alpha) ? 1 : alpha, 0, 1);
  970. return [h, w, b, a];
  971. }
  972. }
  973. function getRgb(string) {
  974. var rgba = getRgba(string);
  975. return rgba && rgba.slice(0, 3);
  976. }
  977. function getHsl(string) {
  978. var hsla = getHsla(string);
  979. return hsla && hsla.slice(0, 3);
  980. }
  981. function getAlpha(string) {
  982. var vals = getRgba(string);
  983. if (vals) {
  984. return vals[3];
  985. }
  986. else if (vals = getHsla(string)) {
  987. return vals[3];
  988. }
  989. else if (vals = getHwb(string)) {
  990. return vals[3];
  991. }
  992. }
  993. // generators
  994. function hexString(rgb) {
  995. return "#" + hexDouble(rgb[0]) + hexDouble(rgb[1])
  996. + hexDouble(rgb[2]);
  997. }
  998. function rgbString(rgba, alpha) {
  999. if (alpha < 1 || (rgba[3] && rgba[3] < 1)) {
  1000. return rgbaString(rgba, alpha);
  1001. }
  1002. return "rgb(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2] + ")";
  1003. }
  1004. function rgbaString(rgba, alpha) {
  1005. if (alpha === undefined) {
  1006. alpha = (rgba[3] !== undefined ? rgba[3] : 1);
  1007. }
  1008. return "rgba(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2]
  1009. + ", " + alpha + ")";
  1010. }
  1011. function percentString(rgba, alpha) {
  1012. if (alpha < 1 || (rgba[3] && rgba[3] < 1)) {
  1013. return percentaString(rgba, alpha);
  1014. }
  1015. var r = Math.round(rgba[0]/255 * 100),
  1016. g = Math.round(rgba[1]/255 * 100),
  1017. b = Math.round(rgba[2]/255 * 100);
  1018. return "rgb(" + r + "%, " + g + "%, " + b + "%)";
  1019. }
  1020. function percentaString(rgba, alpha) {
  1021. var r = Math.round(rgba[0]/255 * 100),
  1022. g = Math.round(rgba[1]/255 * 100),
  1023. b = Math.round(rgba[2]/255 * 100);
  1024. return "rgba(" + r + "%, " + g + "%, " + b + "%, " + (alpha || rgba[3] || 1) + ")";
  1025. }
  1026. function hslString(hsla, alpha) {
  1027. if (alpha < 1 || (hsla[3] && hsla[3] < 1)) {
  1028. return hslaString(hsla, alpha);
  1029. }
  1030. return "hsl(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%)";
  1031. }
  1032. function hslaString(hsla, alpha) {
  1033. if (alpha === undefined) {
  1034. alpha = (hsla[3] !== undefined ? hsla[3] : 1);
  1035. }
  1036. return "hsla(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%, "
  1037. + alpha + ")";
  1038. }
  1039. // hwb is a bit different than rgb(a) & hsl(a) since there is no alpha specific syntax
  1040. // (hwb have alpha optional & 1 is default value)
  1041. function hwbString(hwb, alpha) {
  1042. if (alpha === undefined) {
  1043. alpha = (hwb[3] !== undefined ? hwb[3] : 1);
  1044. }
  1045. return "hwb(" + hwb[0] + ", " + hwb[1] + "%, " + hwb[2] + "%"
  1046. + (alpha !== undefined && alpha !== 1 ? ", " + alpha : "") + ")";
  1047. }
  1048. function keyword(rgb) {
  1049. return reverseNames[rgb.slice(0, 3)];
  1050. }
  1051. // helpers
  1052. function scale(num, min, max) {
  1053. return Math.min(Math.max(min, num), max);
  1054. }
  1055. function hexDouble(num) {
  1056. var str = num.toString(16).toUpperCase();
  1057. return (str.length < 2) ? "0" + str : str;
  1058. }
  1059. //create a list of reverse color names
  1060. var reverseNames = {};
  1061. for (var name in colorNames) {
  1062. reverseNames[colorNames[name]] = name;
  1063. }
  1064. },{"color-name":4}],6:[function(_dereq_,module,exports){
  1065. /* MIT license */
  1066. var convert = _dereq_("color-convert"),
  1067. string = _dereq_("color-string");
  1068. var Color = function(obj) {
  1069. if (obj instanceof Color) return obj;
  1070. if (! (this instanceof Color)) return new Color(obj);
  1071. this.values = {
  1072. rgb: [0, 0, 0],
  1073. hsl: [0, 0, 0],
  1074. hsv: [0, 0, 0],
  1075. hwb: [0, 0, 0],
  1076. cmyk: [0, 0, 0, 0],
  1077. alpha: 1
  1078. }
  1079. // parse Color() argument
  1080. if (typeof obj == "string") {
  1081. var vals = string.getRgba(obj);
  1082. if (vals) {
  1083. this.setValues("rgb", vals);
  1084. }
  1085. else if(vals = string.getHsla(obj)) {
  1086. this.setValues("hsl", vals);
  1087. }
  1088. else if(vals = string.getHwb(obj)) {
  1089. this.setValues("hwb", vals);
  1090. }
  1091. else {
  1092. throw new Error("Unable to parse color from string \"" + obj + "\"");
  1093. }
  1094. }
  1095. else if (typeof obj == "object") {
  1096. var vals = obj;
  1097. if(vals["r"] !== undefined || vals["red"] !== undefined) {
  1098. this.setValues("rgb", vals)
  1099. }
  1100. else if(vals["l"] !== undefined || vals["lightness"] !== undefined) {
  1101. this.setValues("hsl", vals)
  1102. }
  1103. else if(vals["v"] !== undefined || vals["value"] !== undefined) {
  1104. this.setValues("hsv", vals)
  1105. }
  1106. else if(vals["w"] !== undefined || vals["whiteness"] !== undefined) {
  1107. this.setValues("hwb", vals)
  1108. }
  1109. else if(vals["c"] !== undefined || vals["cyan"] !== undefined) {
  1110. this.setValues("cmyk", vals)
  1111. }
  1112. else {
  1113. throw new Error("Unable to parse color from object " + JSON.stringify(obj));
  1114. }
  1115. }
  1116. }
  1117. Color.prototype = {
  1118. rgb: function (vals) {
  1119. return this.setSpace("rgb", arguments);
  1120. },
  1121. hsl: function(vals) {
  1122. return this.setSpace("hsl", arguments);
  1123. },
  1124. hsv: function(vals) {
  1125. return this.setSpace("hsv", arguments);
  1126. },
  1127. hwb: function(vals) {
  1128. return this.setSpace("hwb", arguments);
  1129. },
  1130. cmyk: function(vals) {
  1131. return this.setSpace("cmyk", arguments);
  1132. },
  1133. rgbArray: function() {
  1134. return this.values.rgb;
  1135. },
  1136. hslArray: function() {
  1137. return this.values.hsl;
  1138. },
  1139. hsvArray: function() {
  1140. return this.values.hsv;
  1141. },
  1142. hwbArray: function() {
  1143. if (this.values.alpha !== 1) {
  1144. return this.values.hwb.concat([this.values.alpha])
  1145. }
  1146. return this.values.hwb;
  1147. },
  1148. cmykArray: function() {
  1149. return this.values.cmyk;
  1150. },
  1151. rgbaArray: function() {
  1152. var rgb = this.values.rgb;
  1153. return rgb.concat([this.values.alpha]);
  1154. },
  1155. hslaArray: function() {
  1156. var hsl = this.values.hsl;
  1157. return hsl.concat([this.values.alpha]);
  1158. },
  1159. alpha: function(val) {
  1160. if (val === undefined) {
  1161. return this.values.alpha;
  1162. }
  1163. this.setValues("alpha", val);
  1164. return this;
  1165. },
  1166. red: function(val) {
  1167. return this.setChannel("rgb", 0, val);
  1168. },
  1169. green: function(val) {
  1170. return this.setChannel("rgb", 1, val);
  1171. },
  1172. blue: function(val) {
  1173. return this.setChannel("rgb", 2, val);
  1174. },
  1175. hue: function(val) {
  1176. return this.setChannel("hsl", 0, val);
  1177. },
  1178. saturation: function(val) {
  1179. return this.setChannel("hsl", 1, val);
  1180. },
  1181. lightness: function(val) {
  1182. return this.setChannel("hsl", 2, val);
  1183. },
  1184. saturationv: function(val) {
  1185. return this.setChannel("hsv", 1, val);
  1186. },
  1187. whiteness: function(val) {
  1188. return this.setChannel("hwb", 1, val);
  1189. },
  1190. blackness: function(val) {
  1191. return this.setChannel("hwb", 2, val);
  1192. },
  1193. value: function(val) {
  1194. return this.setChannel("hsv", 2, val);
  1195. },
  1196. cyan: function(val) {
  1197. return this.setChannel("cmyk", 0, val);
  1198. },
  1199. magenta: function(val) {
  1200. return this.setChannel("cmyk", 1, val);
  1201. },
  1202. yellow: function(val) {
  1203. return this.setChannel("cmyk", 2, val);
  1204. },
  1205. black: function(val) {
  1206. return this.setChannel("cmyk", 3, val);
  1207. },
  1208. hexString: function() {
  1209. return string.hexString(this.values.rgb);
  1210. },
  1211. rgbString: function() {
  1212. return string.rgbString(this.values.rgb, this.values.alpha);
  1213. },
  1214. rgbaString: function() {
  1215. return string.rgbaString(this.values.rgb, this.values.alpha);
  1216. },
  1217. percentString: function() {
  1218. return string.percentString(this.values.rgb, this.values.alpha);
  1219. },
  1220. hslString: function() {
  1221. return string.hslString(this.values.hsl, this.values.alpha);
  1222. },
  1223. hslaString: function() {
  1224. return string.hslaString(this.values.hsl, this.values.alpha);
  1225. },
  1226. hwbString: function() {
  1227. return string.hwbString(this.values.hwb, this.values.alpha);
  1228. },
  1229. keyword: function() {
  1230. return string.keyword(this.values.rgb, this.values.alpha);
  1231. },
  1232. rgbNumber: function() {
  1233. return (this.values.rgb[0] << 16) | (this.values.rgb[1] << 8) | this.values.rgb[2];
  1234. },
  1235. luminosity: function() {
  1236. // http://www.w3.org/TR/WCAG20/#relativeluminancedef
  1237. var rgb = this.values.rgb;
  1238. var lum = [];
  1239. for (var i = 0; i < rgb.length; i++) {
  1240. var chan = rgb[i] / 255;
  1241. lum[i] = (chan <= 0.03928) ? chan / 12.92
  1242. : Math.pow(((chan + 0.055) / 1.055), 2.4)
  1243. }
  1244. return 0.2126 * lum[0] + 0.7152 * lum[1] + 0.0722 * lum[2];
  1245. },
  1246. contrast: function(color2) {
  1247. // http://www.w3.org/TR/WCAG20/#contrast-ratiodef
  1248. var lum1 = this.luminosity();
  1249. var lum2 = color2.luminosity();
  1250. if (lum1 > lum2) {
  1251. return (lum1 + 0.05) / (lum2 + 0.05)
  1252. };
  1253. return (lum2 + 0.05) / (lum1 + 0.05);
  1254. },
  1255. level: function(color2) {
  1256. var contrastRatio = this.contrast(color2);
  1257. return (contrastRatio >= 7.1)
  1258. ? 'AAA'
  1259. : (contrastRatio >= 4.5)
  1260. ? 'AA'
  1261. : '';
  1262. },
  1263. dark: function() {
  1264. // YIQ equation from http://24ways.org/2010/calculating-color-contrast
  1265. var rgb = this.values.rgb,
  1266. yiq = (rgb[0] * 299 + rgb[1] * 587 + rgb[2] * 114) / 1000;
  1267. return yiq < 128;
  1268. },
  1269. light: function() {
  1270. return !this.dark();
  1271. },
  1272. negate: function() {
  1273. var rgb = []
  1274. for (var i = 0; i < 3; i++) {
  1275. rgb[i] = 255 - this.values.rgb[i];
  1276. }
  1277. this.setValues("rgb", rgb);
  1278. return this;
  1279. },
  1280. lighten: function(ratio) {
  1281. this.values.hsl[2] += this.values.hsl[2] * ratio;
  1282. this.setValues("hsl", this.values.hsl);
  1283. return this;
  1284. },
  1285. darken: function(ratio) {
  1286. this.values.hsl[2] -= this.values.hsl[2] * ratio;
  1287. this.setValues("hsl", this.values.hsl);
  1288. return this;
  1289. },
  1290. saturate: function(ratio) {
  1291. this.values.hsl[1] += this.values.hsl[1] * ratio;
  1292. this.setValues("hsl", this.values.hsl);
  1293. return this;
  1294. },
  1295. desaturate: function(ratio) {
  1296. this.values.hsl[1] -= this.values.hsl[1] * ratio;
  1297. this.setValues("hsl", this.values.hsl);
  1298. return this;
  1299. },
  1300. whiten: function(ratio) {
  1301. this.values.hwb[1] += this.values.hwb[1] * ratio;
  1302. this.setValues("hwb", this.values.hwb);
  1303. return this;
  1304. },
  1305. blacken: function(ratio) {
  1306. this.values.hwb[2] += this.values.hwb[2] * ratio;
  1307. this.setValues("hwb", this.values.hwb);
  1308. return this;
  1309. },
  1310. greyscale: function() {
  1311. var rgb = this.values.rgb;
  1312. // http://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale
  1313. var val = rgb[0] * 0.3 + rgb[1] * 0.59 + rgb[2] * 0.11;
  1314. this.setValues("rgb", [val, val, val]);
  1315. return this;
  1316. },
  1317. clearer: function(ratio) {
  1318. this.setValues("alpha", this.values.alpha - (this.values.alpha * ratio));
  1319. return this;
  1320. },
  1321. opaquer: function(ratio) {
  1322. this.setValues("alpha", this.values.alpha + (this.values.alpha * ratio));
  1323. return this;
  1324. },
  1325. rotate: function(degrees) {
  1326. var hue = this.values.hsl[0];
  1327. hue = (hue + degrees) % 360;
  1328. hue = hue < 0 ? 360 + hue : hue;
  1329. this.values.hsl[0] = hue;
  1330. this.setValues("hsl", this.values.hsl);
  1331. return this;
  1332. },
  1333. mix: function(color2, weight) {
  1334. weight = 1 - (weight == null ? 0.5 : weight);
  1335. // algorithm from Sass's mix(). Ratio of first color in mix is
  1336. // determined by the alphas of both colors and the weight
  1337. var t1 = weight * 2 - 1,
  1338. d = this.alpha() - color2.alpha();
  1339. var weight1 = (((t1 * d == -1) ? t1 : (t1 + d) / (1 + t1 * d)) + 1) / 2;
  1340. var weight2 = 1 - weight1;
  1341. var rgb = this.rgbArray();
  1342. var rgb2 = color2.rgbArray();
  1343. for (var i = 0; i < rgb.length; i++) {
  1344. rgb[i] = rgb[i] * weight1 + rgb2[i] * weight2;
  1345. }
  1346. this.setValues("rgb", rgb);
  1347. var alpha = this.alpha() * weight + color2.alpha() * (1 - weight);
  1348. this.setValues("alpha", alpha);
  1349. return this;
  1350. },
  1351. toJSON: function() {
  1352. return this.rgb();
  1353. },
  1354. clone: function() {
  1355. return new Color(this.rgb());
  1356. }
  1357. }
  1358. Color.prototype.getValues = function(space) {
  1359. var vals = {};
  1360. for (var i = 0; i < space.length; i++) {
  1361. vals[space.charAt(i)] = this.values[space][i];
  1362. }
  1363. if (this.values.alpha != 1) {
  1364. vals["a"] = this.values.alpha;
  1365. }
  1366. // {r: 255, g: 255, b: 255, a: 0.4}
  1367. return vals;
  1368. }
  1369. Color.prototype.setValues = function(space, vals) {
  1370. var spaces = {
  1371. "rgb": ["red", "green", "blue"],
  1372. "hsl": ["hue", "saturation", "lightness"],
  1373. "hsv": ["hue", "saturation", "value"],
  1374. "hwb": ["hue", "whiteness", "blackness"],
  1375. "cmyk": ["cyan", "magenta", "yellow", "black"]
  1376. };
  1377. var maxes = {
  1378. "rgb": [255, 255, 255],
  1379. "hsl": [360, 100, 100],
  1380. "hsv": [360, 100, 100],
  1381. "hwb": [360, 100, 100],
  1382. "cmyk": [100, 100, 100, 100]
  1383. };
  1384. var alpha = 1;
  1385. if (space == "alpha") {
  1386. alpha = vals;
  1387. }
  1388. else if (vals.length) {
  1389. // [10, 10, 10]
  1390. this.values[space] = vals.slice(0, space.length);
  1391. alpha = vals[space.length];
  1392. }
  1393. else if (vals[space.charAt(0)] !== undefined) {
  1394. // {r: 10, g: 10, b: 10}
  1395. for (var i = 0; i < space.length; i++) {
  1396. this.values[space][i] = vals[space.charAt(i)];
  1397. }
  1398. alpha = vals.a;
  1399. }
  1400. else if (vals[spaces[space][0]] !== undefined) {
  1401. // {red: 10, green: 10, blue: 10}
  1402. var chans = spaces[space];
  1403. for (var i = 0; i < space.length; i++) {
  1404. this.values[space][i] = vals[chans[i]];
  1405. }
  1406. alpha = vals.alpha;
  1407. }
  1408. this.values.alpha = Math.max(0, Math.min(1, (alpha !== undefined ? alpha : this.values.alpha) ));
  1409. if (space == "alpha") {
  1410. return;
  1411. }
  1412. // cap values of the space prior converting all values
  1413. for (var i = 0; i < space.length; i++) {
  1414. var capped = Math.max(0, Math.min(maxes[space][i], this.values[space][i]));
  1415. this.values[space][i] = Math.round(capped);
  1416. }
  1417. // convert to all the other color spaces
  1418. for (var sname in spaces) {
  1419. if (sname != space) {
  1420. this.values[sname] = convert[space][sname](this.values[space])
  1421. }
  1422. // cap values
  1423. for (var i = 0; i < sname.length; i++) {
  1424. var capped = Math.max(0, Math.min(maxes[sname][i], this.values[sname][i]));
  1425. this.values[sname][i] = Math.round(capped);
  1426. }
  1427. }
  1428. return true;
  1429. }
  1430. Color.prototype.setSpace = function(space, args) {
  1431. var vals = args[0];
  1432. if (vals === undefined) {
  1433. // color.rgb()
  1434. return this.getValues(space);
  1435. }
  1436. // color.rgb(10, 10, 10)
  1437. if (typeof vals == "number") {
  1438. vals = Array.prototype.slice.call(args);
  1439. }
  1440. this.setValues(space, vals);
  1441. return this;
  1442. }
  1443. Color.prototype.setChannel = function(space, index, val) {
  1444. if (val === undefined) {
  1445. // color.red()
  1446. return this.values[space][index];
  1447. }
  1448. // color.red(100)
  1449. this.values[space][index] = val;
  1450. this.setValues(space, this.values[space]);
  1451. return this;
  1452. }
  1453. module.exports = Color;
  1454. },{"color-convert":3,"color-string":5}],7:[function(_dereq_,module,exports){
  1455. 'use strict';
  1456. var colorjs = _dereq_('color')
  1457. , hex = _dereq_('text-hex');
  1458. /**
  1459. * Generate a color for a given name. But be reasonably smart about it by
  1460. * understanding name spaces and coloring each namespace a bit lighter so they
  1461. * still have the same base color as the root.
  1462. *
  1463. * @param {String} name The namespace
  1464. * @returns {String} color
  1465. * @api private
  1466. */
  1467. module.exports = function colorspace(namespace, delimiter) {
  1468. namespace = namespace.split(delimiter || ':');
  1469. for (var base = hex(namespace[0]), i = 0, l = namespace.length - 1; i < l; i++) {
  1470. base = colorjs(base).mix(colorjs(hex(namespace[i + 1]))).saturate(1).hexString();
  1471. }
  1472. return base;
  1473. };
  1474. },{"color":6,"text-hex":11}],8:[function(_dereq_,module,exports){
  1475. 'use strict';
  1476. var env = _dereq_('env-variable');
  1477. /**
  1478. * Checks if a given namespace is allowed by the environment variables.
  1479. *
  1480. * @param {String} name namespace that should be included.
  1481. * @param {Array} variables
  1482. * @returns {Boolean}
  1483. * @api public
  1484. */
  1485. module.exports = function enabled(name, variables) {
  1486. var envy = env()
  1487. , variable
  1488. , i = 0;
  1489. variables = variables || ['diagnostics', 'debug'];
  1490. for (; i < variables.length; i++) {
  1491. if ((variable = envy[variables[i]])) break;
  1492. }
  1493. if (!variable) return false;
  1494. variables = variable.split(/[\s,]+/);
  1495. i = 0;
  1496. for (; i < variables.length; i++) {
  1497. variable = variables[i].replace('*', '.*?');
  1498. if ('-' === variable.charAt(0)) {
  1499. if ((new RegExp('^'+ variable.substr(1) +'$')).test(name)) {
  1500. return false;
  1501. }
  1502. continue;
  1503. }
  1504. if ((new RegExp('^'+ variable +'$')).test(name)) {
  1505. return true;
  1506. }
  1507. }
  1508. return false;
  1509. };
  1510. },{"env-variable":9}],9:[function(_dereq_,module,exports){
  1511. (function (process){
  1512. 'use strict';
  1513. var has = Object.prototype.hasOwnProperty;
  1514. /**
  1515. * Gather environment variables from various locations.
  1516. *
  1517. * @param {Object} environment The default environment variables.
  1518. * @returns {Object} environment.
  1519. * @api public
  1520. */
  1521. function env(environment) {
  1522. environment = environment || {};
  1523. if ('object' === typeof process && 'object' === typeof process.env) {
  1524. env.merge(environment, process.env);
  1525. }
  1526. if ('undefined' !== typeof window) {
  1527. if ('string' === window.name && window.name.length) {
  1528. env.merge(environment, env.parse(window.name));
  1529. }
  1530. if (window.localStorage) {
  1531. try { env.merge(environment, env.parse(window.localStorage.env || window.localStorage.debug)); }
  1532. catch (e) {}
  1533. }
  1534. if (
  1535. 'object' === typeof window.location
  1536. && 'string' === typeof window.location.hash
  1537. && window.location.hash.length
  1538. ) {
  1539. env.merge(environment, env.parse(window.location.hash.charAt(0) === '#'
  1540. ? window.location.hash.slice(1)
  1541. : window.location.hash
  1542. ));
  1543. }
  1544. }
  1545. //
  1546. // Also add lower case variants to the object for easy access.
  1547. //
  1548. var key, lower;
  1549. for (key in environment) {
  1550. lower = key.toLowerCase();
  1551. if (!(lower in environment)) {
  1552. environment[lower] = environment[key];
  1553. }
  1554. }
  1555. return environment;
  1556. }
  1557. /**
  1558. * A poor man's merge utility.
  1559. *
  1560. * @param {Object} base Object where the add object is merged in.
  1561. * @param {Object} add Object that needs to be added to the base object.
  1562. * @returns {Object} base
  1563. * @api private
  1564. */
  1565. env.merge = function merge(base, add) {
  1566. for (var key in add) {
  1567. if (has.call(add, key)) {
  1568. base[key] = add[key];
  1569. }
  1570. }
  1571. return base;
  1572. };
  1573. /**
  1574. * A poor man's query string parser.
  1575. *
  1576. * @param {String} query The query string that needs to be parsed.
  1577. * @returns {Object} Key value mapped query string.
  1578. * @api private
  1579. */
  1580. env.parse = function parse(query) {
  1581. var parser = /([^=?&]+)=([^&]*)/g
  1582. , result = {}
  1583. , part;
  1584. if (!query) return result;
  1585. for (;
  1586. part = parser.exec(query);
  1587. result[decodeURIComponent(part[1])] = decodeURIComponent(part[2])
  1588. );
  1589. return result.env || result;
  1590. };
  1591. //
  1592. // Expose the module
  1593. //
  1594. module.exports = env;
  1595. }).call(this,_dereq_('_process'))
  1596. },{"_process":10}],10:[function(_dereq_,module,exports){
  1597. // shim for using process in browser
  1598. var process = module.exports = {};
  1599. // cached from whatever global is present so that test runners that stub it
  1600. // don't break things. But we need to wrap it in a try catch in case it is
  1601. // wrapped in strict mode code which doesn't define any globals. It's inside a
  1602. // function because try/catches deoptimize in certain engines.
  1603. var cachedSetTimeout;
  1604. var cachedClearTimeout;
  1605. function defaultSetTimout() {
  1606. throw new Error('setTimeout has not been defined');
  1607. }
  1608. function defaultClearTimeout () {
  1609. throw new Error('clearTimeout has not been defined');
  1610. }
  1611. (function () {
  1612. try {
  1613. if (typeof setTimeout === 'function') {
  1614. cachedSetTimeout = setTimeout;
  1615. } else {
  1616. cachedSetTimeout = defaultSetTimout;
  1617. }
  1618. } catch (e) {
  1619. cachedSetTimeout = defaultSetTimout;
  1620. }
  1621. try {
  1622. if (typeof clearTimeout === 'function') {
  1623. cachedClearTimeout = clearTimeout;
  1624. } else {
  1625. cachedClearTimeout = defaultClearTimeout;
  1626. }
  1627. } catch (e) {
  1628. cachedClearTimeout = defaultClearTimeout;
  1629. }
  1630. } ())
  1631. function runTimeout(fun) {
  1632. if (cachedSetTimeout === setTimeout) {
  1633. //normal enviroments in sane situations
  1634. return setTimeout(fun, 0);
  1635. }
  1636. // if setTimeout wasn't available but was latter defined
  1637. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  1638. cachedSetTimeout = setTimeout;
  1639. return setTimeout(fun, 0);
  1640. }
  1641. try {
  1642. // when when somebody has screwed with setTimeout but no I.E. maddness
  1643. return cachedSetTimeout(fun, 0);
  1644. } catch(e){
  1645. try {
  1646. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  1647. return cachedSetTimeout.call(null, fun, 0);
  1648. } catch(e){
  1649. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  1650. return cachedSetTimeout.call(this, fun, 0);
  1651. }
  1652. }
  1653. }
  1654. function runClearTimeout(marker) {
  1655. if (cachedClearTimeout === clearTimeout) {
  1656. //normal enviroments in sane situations
  1657. return clearTimeout(marker);
  1658. }
  1659. // if clearTimeout wasn't available but was latter defined
  1660. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  1661. cachedClearTimeout = clearTimeout;
  1662. return clearTimeout(marker);
  1663. }
  1664. try {
  1665. // when when somebody has screwed with setTimeout but no I.E. maddness
  1666. return cachedClearTimeout(marker);
  1667. } catch (e){
  1668. try {
  1669. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  1670. return cachedClearTimeout.call(null, marker);
  1671. } catch (e){
  1672. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  1673. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  1674. return cachedClearTimeout.call(this, marker);
  1675. }
  1676. }
  1677. }
  1678. var queue = [];
  1679. var draining = false;
  1680. var currentQueue;
  1681. var queueIndex = -1;
  1682. function cleanUpNextTick() {
  1683. if (!draining || !currentQueue) {
  1684. return;
  1685. }
  1686. draining = false;
  1687. if (currentQueue.length) {
  1688. queue = currentQueue.concat(queue);
  1689. } else {
  1690. queueIndex = -1;
  1691. }
  1692. if (queue.length) {
  1693. drainQueue();
  1694. }
  1695. }
  1696. function drainQueue() {
  1697. if (draining) {
  1698. return;
  1699. }
  1700. var timeout = runTimeout(cleanUpNextTick);
  1701. draining = true;
  1702. var len = queue.length;
  1703. while(len) {
  1704. currentQueue = queue;
  1705. queue = [];
  1706. while (++queueIndex < len) {
  1707. if (currentQueue) {
  1708. currentQueue[queueIndex].run();
  1709. }
  1710. }
  1711. queueIndex = -1;
  1712. len = queue.length;
  1713. }
  1714. currentQueue = null;
  1715. draining = false;
  1716. runClearTimeout(timeout);
  1717. }
  1718. process.nextTick = function (fun) {
  1719. var args = new Array(arguments.length - 1);
  1720. if (arguments.length > 1) {
  1721. for (var i = 1; i < arguments.length; i++) {
  1722. args[i - 1] = arguments[i];
  1723. }
  1724. }
  1725. queue.push(new Item(fun, args));
  1726. if (queue.length === 1 && !draining) {
  1727. runTimeout(drainQueue);
  1728. }
  1729. };
  1730. // v8 likes predictible objects
  1731. function Item(fun, array) {
  1732. this.fun = fun;
  1733. this.array = array;
  1734. }
  1735. Item.prototype.run = function () {
  1736. this.fun.apply(null, this.array);
  1737. };
  1738. process.title = 'browser';
  1739. process.browser = true;
  1740. process.env = {};
  1741. process.argv = [];
  1742. process.version = ''; // empty string to avoid regexp issues
  1743. process.versions = {};
  1744. function noop() {}
  1745. process.on = noop;
  1746. process.addListener = noop;
  1747. process.once = noop;
  1748. process.off = noop;
  1749. process.removeListener = noop;
  1750. process.removeAllListeners = noop;
  1751. process.emit = noop;
  1752. process.prependListener = noop;
  1753. process.prependOnceListener = noop;
  1754. process.listeners = function (name) { return [] }
  1755. process.binding = function (name) {
  1756. throw new Error('process.binding is not supported');
  1757. };
  1758. process.cwd = function () { return '/' };
  1759. process.chdir = function (dir) {
  1760. throw new Error('process.chdir is not supported');
  1761. };
  1762. process.umask = function() { return 0; };
  1763. },{}],11:[function(_dereq_,module,exports){
  1764. 'use strict';
  1765. /***
  1766. * Convert string to hex color.
  1767. *
  1768. * @param {String} str Text to hash and convert to hex.
  1769. * @returns {String}
  1770. * @api public
  1771. */
  1772. module.exports = function hex(str) {
  1773. for (
  1774. var i = 0, hash = 0;
  1775. i < str.length;
  1776. hash = str.charCodeAt(i++) + ((hash << 5) - hash)
  1777. );
  1778. var color = Math.floor(
  1779. Math.abs(
  1780. (Math.sin(hash) * 10000) % 1 * 16777216
  1781. )
  1782. ).toString(16);
  1783. return '#' + Array(6 - color.length + 1).join('0') + color;
  1784. };
  1785. },{}]},{},[1])(1)
  1786. });