index.js 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201
  1. module.exports = (function() {
  2. var __MODS__ = {};
  3. var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; };
  4. var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; };
  5. var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } };
  6. var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; };
  7. __DEFINE__(1741168270881, function(require, module, exports) {
  8. // This file is autogenerated. It's used to publish CJS to npm.
  9. (function (global, factory) {
  10. typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
  11. typeof define === 'function' && define.amd ? define(factory) :
  12. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.tinycolor = factory());
  13. })(this, (function () {
  14. function _typeof(obj) {
  15. "@babel/helpers - typeof";
  16. return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
  17. return typeof obj;
  18. } : function (obj) {
  19. return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  20. }, _typeof(obj);
  21. }
  22. // https://github.com/bgrins/TinyColor
  23. // Brian Grinstead, MIT License
  24. var trimLeft = /^\s+/;
  25. var trimRight = /\s+$/;
  26. function tinycolor(color, opts) {
  27. color = color ? color : "";
  28. opts = opts || {};
  29. // If input is already a tinycolor, return itself
  30. if (color instanceof tinycolor) {
  31. return color;
  32. }
  33. // If we are called as a function, call using new instead
  34. if (!(this instanceof tinycolor)) {
  35. return new tinycolor(color, opts);
  36. }
  37. var rgb = inputToRGB(color);
  38. this._originalInput = color, this._r = rgb.r, this._g = rgb.g, this._b = rgb.b, this._a = rgb.a, this._roundA = Math.round(100 * this._a) / 100, this._format = opts.format || rgb.format;
  39. this._gradientType = opts.gradientType;
  40. // Don't let the range of [0,255] come back in [0,1].
  41. // Potentially lose a little bit of precision here, but will fix issues where
  42. // .5 gets interpreted as half of the total, instead of half of 1
  43. // If it was supposed to be 128, this was already taken care of by `inputToRgb`
  44. if (this._r < 1) this._r = Math.round(this._r);
  45. if (this._g < 1) this._g = Math.round(this._g);
  46. if (this._b < 1) this._b = Math.round(this._b);
  47. this._ok = rgb.ok;
  48. }
  49. tinycolor.prototype = {
  50. isDark: function isDark() {
  51. return this.getBrightness() < 128;
  52. },
  53. isLight: function isLight() {
  54. return !this.isDark();
  55. },
  56. isValid: function isValid() {
  57. return this._ok;
  58. },
  59. getOriginalInput: function getOriginalInput() {
  60. return this._originalInput;
  61. },
  62. getFormat: function getFormat() {
  63. return this._format;
  64. },
  65. getAlpha: function getAlpha() {
  66. return this._a;
  67. },
  68. getBrightness: function getBrightness() {
  69. //http://www.w3.org/TR/AERT#color-contrast
  70. var rgb = this.toRgb();
  71. return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
  72. },
  73. getLuminance: function getLuminance() {
  74. //http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
  75. var rgb = this.toRgb();
  76. var RsRGB, GsRGB, BsRGB, R, G, B;
  77. RsRGB = rgb.r / 255;
  78. GsRGB = rgb.g / 255;
  79. BsRGB = rgb.b / 255;
  80. if (RsRGB <= 0.03928) R = RsRGB / 12.92;else R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);
  81. if (GsRGB <= 0.03928) G = GsRGB / 12.92;else G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);
  82. if (BsRGB <= 0.03928) B = BsRGB / 12.92;else B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);
  83. return 0.2126 * R + 0.7152 * G + 0.0722 * B;
  84. },
  85. setAlpha: function setAlpha(value) {
  86. this._a = boundAlpha(value);
  87. this._roundA = Math.round(100 * this._a) / 100;
  88. return this;
  89. },
  90. toHsv: function toHsv() {
  91. var hsv = rgbToHsv(this._r, this._g, this._b);
  92. return {
  93. h: hsv.h * 360,
  94. s: hsv.s,
  95. v: hsv.v,
  96. a: this._a
  97. };
  98. },
  99. toHsvString: function toHsvString() {
  100. var hsv = rgbToHsv(this._r, this._g, this._b);
  101. var h = Math.round(hsv.h * 360),
  102. s = Math.round(hsv.s * 100),
  103. v = Math.round(hsv.v * 100);
  104. return this._a == 1 ? "hsv(" + h + ", " + s + "%, " + v + "%)" : "hsva(" + h + ", " + s + "%, " + v + "%, " + this._roundA + ")";
  105. },
  106. toHsl: function toHsl() {
  107. var hsl = rgbToHsl(this._r, this._g, this._b);
  108. return {
  109. h: hsl.h * 360,
  110. s: hsl.s,
  111. l: hsl.l,
  112. a: this._a
  113. };
  114. },
  115. toHslString: function toHslString() {
  116. var hsl = rgbToHsl(this._r, this._g, this._b);
  117. var h = Math.round(hsl.h * 360),
  118. s = Math.round(hsl.s * 100),
  119. l = Math.round(hsl.l * 100);
  120. return this._a == 1 ? "hsl(" + h + ", " + s + "%, " + l + "%)" : "hsla(" + h + ", " + s + "%, " + l + "%, " + this._roundA + ")";
  121. },
  122. toHex: function toHex(allow3Char) {
  123. return rgbToHex(this._r, this._g, this._b, allow3Char);
  124. },
  125. toHexString: function toHexString(allow3Char) {
  126. return "#" + this.toHex(allow3Char);
  127. },
  128. toHex8: function toHex8(allow4Char) {
  129. return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
  130. },
  131. toHex8String: function toHex8String(allow4Char) {
  132. return "#" + this.toHex8(allow4Char);
  133. },
  134. toRgb: function toRgb() {
  135. return {
  136. r: Math.round(this._r),
  137. g: Math.round(this._g),
  138. b: Math.round(this._b),
  139. a: this._a
  140. };
  141. },
  142. toRgbString: function toRgbString() {
  143. return this._a == 1 ? "rgb(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ")" : "rgba(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ", " + this._roundA + ")";
  144. },
  145. toPercentageRgb: function toPercentageRgb() {
  146. return {
  147. r: Math.round(bound01(this._r, 255) * 100) + "%",
  148. g: Math.round(bound01(this._g, 255) * 100) + "%",
  149. b: Math.round(bound01(this._b, 255) * 100) + "%",
  150. a: this._a
  151. };
  152. },
  153. toPercentageRgbString: function toPercentageRgbString() {
  154. return this._a == 1 ? "rgb(" + Math.round(bound01(this._r, 255) * 100) + "%, " + Math.round(bound01(this._g, 255) * 100) + "%, " + Math.round(bound01(this._b, 255) * 100) + "%)" : "rgba(" + Math.round(bound01(this._r, 255) * 100) + "%, " + Math.round(bound01(this._g, 255) * 100) + "%, " + Math.round(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")";
  155. },
  156. toName: function toName() {
  157. if (this._a === 0) {
  158. return "transparent";
  159. }
  160. if (this._a < 1) {
  161. return false;
  162. }
  163. return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
  164. },
  165. toFilter: function toFilter(secondColor) {
  166. var hex8String = "#" + rgbaToArgbHex(this._r, this._g, this._b, this._a);
  167. var secondHex8String = hex8String;
  168. var gradientType = this._gradientType ? "GradientType = 1, " : "";
  169. if (secondColor) {
  170. var s = tinycolor(secondColor);
  171. secondHex8String = "#" + rgbaToArgbHex(s._r, s._g, s._b, s._a);
  172. }
  173. return "progid:DXImageTransform.Microsoft.gradient(" + gradientType + "startColorstr=" + hex8String + ",endColorstr=" + secondHex8String + ")";
  174. },
  175. toString: function toString(format) {
  176. var formatSet = !!format;
  177. format = format || this._format;
  178. var formattedString = false;
  179. var hasAlpha = this._a < 1 && this._a >= 0;
  180. var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
  181. if (needsAlphaFormat) {
  182. // Special case for "transparent", all other non-alpha formats
  183. // will return rgba when there is transparency.
  184. if (format === "name" && this._a === 0) {
  185. return this.toName();
  186. }
  187. return this.toRgbString();
  188. }
  189. if (format === "rgb") {
  190. formattedString = this.toRgbString();
  191. }
  192. if (format === "prgb") {
  193. formattedString = this.toPercentageRgbString();
  194. }
  195. if (format === "hex" || format === "hex6") {
  196. formattedString = this.toHexString();
  197. }
  198. if (format === "hex3") {
  199. formattedString = this.toHexString(true);
  200. }
  201. if (format === "hex4") {
  202. formattedString = this.toHex8String(true);
  203. }
  204. if (format === "hex8") {
  205. formattedString = this.toHex8String();
  206. }
  207. if (format === "name") {
  208. formattedString = this.toName();
  209. }
  210. if (format === "hsl") {
  211. formattedString = this.toHslString();
  212. }
  213. if (format === "hsv") {
  214. formattedString = this.toHsvString();
  215. }
  216. return formattedString || this.toHexString();
  217. },
  218. clone: function clone() {
  219. return tinycolor(this.toString());
  220. },
  221. _applyModification: function _applyModification(fn, args) {
  222. var color = fn.apply(null, [this].concat([].slice.call(args)));
  223. this._r = color._r;
  224. this._g = color._g;
  225. this._b = color._b;
  226. this.setAlpha(color._a);
  227. return this;
  228. },
  229. lighten: function lighten() {
  230. return this._applyModification(_lighten, arguments);
  231. },
  232. brighten: function brighten() {
  233. return this._applyModification(_brighten, arguments);
  234. },
  235. darken: function darken() {
  236. return this._applyModification(_darken, arguments);
  237. },
  238. desaturate: function desaturate() {
  239. return this._applyModification(_desaturate, arguments);
  240. },
  241. saturate: function saturate() {
  242. return this._applyModification(_saturate, arguments);
  243. },
  244. greyscale: function greyscale() {
  245. return this._applyModification(_greyscale, arguments);
  246. },
  247. spin: function spin() {
  248. return this._applyModification(_spin, arguments);
  249. },
  250. _applyCombination: function _applyCombination(fn, args) {
  251. return fn.apply(null, [this].concat([].slice.call(args)));
  252. },
  253. analogous: function analogous() {
  254. return this._applyCombination(_analogous, arguments);
  255. },
  256. complement: function complement() {
  257. return this._applyCombination(_complement, arguments);
  258. },
  259. monochromatic: function monochromatic() {
  260. return this._applyCombination(_monochromatic, arguments);
  261. },
  262. splitcomplement: function splitcomplement() {
  263. return this._applyCombination(_splitcomplement, arguments);
  264. },
  265. // Disabled until https://github.com/bgrins/TinyColor/issues/254
  266. // polyad: function (number) {
  267. // return this._applyCombination(polyad, [number]);
  268. // },
  269. triad: function triad() {
  270. return this._applyCombination(polyad, [3]);
  271. },
  272. tetrad: function tetrad() {
  273. return this._applyCombination(polyad, [4]);
  274. }
  275. };
  276. // If input is an object, force 1 into "1.0" to handle ratios properly
  277. // String input requires "1.0" as input, so 1 will be treated as 1
  278. tinycolor.fromRatio = function (color, opts) {
  279. if (_typeof(color) == "object") {
  280. var newColor = {};
  281. for (var i in color) {
  282. if (color.hasOwnProperty(i)) {
  283. if (i === "a") {
  284. newColor[i] = color[i];
  285. } else {
  286. newColor[i] = convertToPercentage(color[i]);
  287. }
  288. }
  289. }
  290. color = newColor;
  291. }
  292. return tinycolor(color, opts);
  293. };
  294. // Given a string or object, convert that input to RGB
  295. // Possible string inputs:
  296. //
  297. // "red"
  298. // "#f00" or "f00"
  299. // "#ff0000" or "ff0000"
  300. // "#ff000000" or "ff000000"
  301. // "rgb 255 0 0" or "rgb (255, 0, 0)"
  302. // "rgb 1.0 0 0" or "rgb (1, 0, 0)"
  303. // "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
  304. // "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
  305. // "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
  306. // "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
  307. // "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
  308. //
  309. function inputToRGB(color) {
  310. var rgb = {
  311. r: 0,
  312. g: 0,
  313. b: 0
  314. };
  315. var a = 1;
  316. var s = null;
  317. var v = null;
  318. var l = null;
  319. var ok = false;
  320. var format = false;
  321. if (typeof color == "string") {
  322. color = stringInputToObject(color);
  323. }
  324. if (_typeof(color) == "object") {
  325. if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
  326. rgb = rgbToRgb(color.r, color.g, color.b);
  327. ok = true;
  328. format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
  329. } else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
  330. s = convertToPercentage(color.s);
  331. v = convertToPercentage(color.v);
  332. rgb = hsvToRgb(color.h, s, v);
  333. ok = true;
  334. format = "hsv";
  335. } else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
  336. s = convertToPercentage(color.s);
  337. l = convertToPercentage(color.l);
  338. rgb = hslToRgb(color.h, s, l);
  339. ok = true;
  340. format = "hsl";
  341. }
  342. if (color.hasOwnProperty("a")) {
  343. a = color.a;
  344. }
  345. }
  346. a = boundAlpha(a);
  347. return {
  348. ok: ok,
  349. format: color.format || format,
  350. r: Math.min(255, Math.max(rgb.r, 0)),
  351. g: Math.min(255, Math.max(rgb.g, 0)),
  352. b: Math.min(255, Math.max(rgb.b, 0)),
  353. a: a
  354. };
  355. }
  356. // Conversion Functions
  357. // --------------------
  358. // `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
  359. // <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
  360. // `rgbToRgb`
  361. // Handle bounds / percentage checking to conform to CSS color spec
  362. // <http://www.w3.org/TR/css3-color/>
  363. // *Assumes:* r, g, b in [0, 255] or [0, 1]
  364. // *Returns:* { r, g, b } in [0, 255]
  365. function rgbToRgb(r, g, b) {
  366. return {
  367. r: bound01(r, 255) * 255,
  368. g: bound01(g, 255) * 255,
  369. b: bound01(b, 255) * 255
  370. };
  371. }
  372. // `rgbToHsl`
  373. // Converts an RGB color value to HSL.
  374. // *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
  375. // *Returns:* { h, s, l } in [0,1]
  376. function rgbToHsl(r, g, b) {
  377. r = bound01(r, 255);
  378. g = bound01(g, 255);
  379. b = bound01(b, 255);
  380. var max = Math.max(r, g, b),
  381. min = Math.min(r, g, b);
  382. var h,
  383. s,
  384. l = (max + min) / 2;
  385. if (max == min) {
  386. h = s = 0; // achromatic
  387. } else {
  388. var d = max - min;
  389. s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
  390. switch (max) {
  391. case r:
  392. h = (g - b) / d + (g < b ? 6 : 0);
  393. break;
  394. case g:
  395. h = (b - r) / d + 2;
  396. break;
  397. case b:
  398. h = (r - g) / d + 4;
  399. break;
  400. }
  401. h /= 6;
  402. }
  403. return {
  404. h: h,
  405. s: s,
  406. l: l
  407. };
  408. }
  409. // `hslToRgb`
  410. // Converts an HSL color value to RGB.
  411. // *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
  412. // *Returns:* { r, g, b } in the set [0, 255]
  413. function hslToRgb(h, s, l) {
  414. var r, g, b;
  415. h = bound01(h, 360);
  416. s = bound01(s, 100);
  417. l = bound01(l, 100);
  418. function hue2rgb(p, q, t) {
  419. if (t < 0) t += 1;
  420. if (t > 1) t -= 1;
  421. if (t < 1 / 6) return p + (q - p) * 6 * t;
  422. if (t < 1 / 2) return q;
  423. if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
  424. return p;
  425. }
  426. if (s === 0) {
  427. r = g = b = l; // achromatic
  428. } else {
  429. var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
  430. var p = 2 * l - q;
  431. r = hue2rgb(p, q, h + 1 / 3);
  432. g = hue2rgb(p, q, h);
  433. b = hue2rgb(p, q, h - 1 / 3);
  434. }
  435. return {
  436. r: r * 255,
  437. g: g * 255,
  438. b: b * 255
  439. };
  440. }
  441. // `rgbToHsv`
  442. // Converts an RGB color value to HSV
  443. // *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
  444. // *Returns:* { h, s, v } in [0,1]
  445. function rgbToHsv(r, g, b) {
  446. r = bound01(r, 255);
  447. g = bound01(g, 255);
  448. b = bound01(b, 255);
  449. var max = Math.max(r, g, b),
  450. min = Math.min(r, g, b);
  451. var h,
  452. s,
  453. v = max;
  454. var d = max - min;
  455. s = max === 0 ? 0 : d / max;
  456. if (max == min) {
  457. h = 0; // achromatic
  458. } else {
  459. switch (max) {
  460. case r:
  461. h = (g - b) / d + (g < b ? 6 : 0);
  462. break;
  463. case g:
  464. h = (b - r) / d + 2;
  465. break;
  466. case b:
  467. h = (r - g) / d + 4;
  468. break;
  469. }
  470. h /= 6;
  471. }
  472. return {
  473. h: h,
  474. s: s,
  475. v: v
  476. };
  477. }
  478. // `hsvToRgb`
  479. // Converts an HSV color value to RGB.
  480. // *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
  481. // *Returns:* { r, g, b } in the set [0, 255]
  482. function hsvToRgb(h, s, v) {
  483. h = bound01(h, 360) * 6;
  484. s = bound01(s, 100);
  485. v = bound01(v, 100);
  486. var i = Math.floor(h),
  487. f = h - i,
  488. p = v * (1 - s),
  489. q = v * (1 - f * s),
  490. t = v * (1 - (1 - f) * s),
  491. mod = i % 6,
  492. r = [v, q, p, p, t, v][mod],
  493. g = [t, v, v, q, p, p][mod],
  494. b = [p, p, t, v, v, q][mod];
  495. return {
  496. r: r * 255,
  497. g: g * 255,
  498. b: b * 255
  499. };
  500. }
  501. // `rgbToHex`
  502. // Converts an RGB color to hex
  503. // Assumes r, g, and b are contained in the set [0, 255]
  504. // Returns a 3 or 6 character hex
  505. function rgbToHex(r, g, b, allow3Char) {
  506. var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
  507. // Return a 3 character hex if possible
  508. if (allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1)) {
  509. return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
  510. }
  511. return hex.join("");
  512. }
  513. // `rgbaToHex`
  514. // Converts an RGBA color plus alpha transparency to hex
  515. // Assumes r, g, b are contained in the set [0, 255] and
  516. // a in [0, 1]. Returns a 4 or 8 character rgba hex
  517. function rgbaToHex(r, g, b, a, allow4Char) {
  518. var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16)), pad2(convertDecimalToHex(a))];
  519. // Return a 4 character hex if possible
  520. if (allow4Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1) && hex[3].charAt(0) == hex[3].charAt(1)) {
  521. return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
  522. }
  523. return hex.join("");
  524. }
  525. // `rgbaToArgbHex`
  526. // Converts an RGBA color to an ARGB Hex8 string
  527. // Rarely used, but required for "toFilter()"
  528. function rgbaToArgbHex(r, g, b, a) {
  529. var hex = [pad2(convertDecimalToHex(a)), pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
  530. return hex.join("");
  531. }
  532. // `equals`
  533. // Can be called with any tinycolor input
  534. tinycolor.equals = function (color1, color2) {
  535. if (!color1 || !color2) return false;
  536. return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
  537. };
  538. tinycolor.random = function () {
  539. return tinycolor.fromRatio({
  540. r: Math.random(),
  541. g: Math.random(),
  542. b: Math.random()
  543. });
  544. };
  545. // Modification Functions
  546. // ----------------------
  547. // Thanks to less.js for some of the basics here
  548. // <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>
  549. function _desaturate(color, amount) {
  550. amount = amount === 0 ? 0 : amount || 10;
  551. var hsl = tinycolor(color).toHsl();
  552. hsl.s -= amount / 100;
  553. hsl.s = clamp01(hsl.s);
  554. return tinycolor(hsl);
  555. }
  556. function _saturate(color, amount) {
  557. amount = amount === 0 ? 0 : amount || 10;
  558. var hsl = tinycolor(color).toHsl();
  559. hsl.s += amount / 100;
  560. hsl.s = clamp01(hsl.s);
  561. return tinycolor(hsl);
  562. }
  563. function _greyscale(color) {
  564. return tinycolor(color).desaturate(100);
  565. }
  566. function _lighten(color, amount) {
  567. amount = amount === 0 ? 0 : amount || 10;
  568. var hsl = tinycolor(color).toHsl();
  569. hsl.l += amount / 100;
  570. hsl.l = clamp01(hsl.l);
  571. return tinycolor(hsl);
  572. }
  573. function _brighten(color, amount) {
  574. amount = amount === 0 ? 0 : amount || 10;
  575. var rgb = tinycolor(color).toRgb();
  576. rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100))));
  577. rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100))));
  578. rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100))));
  579. return tinycolor(rgb);
  580. }
  581. function _darken(color, amount) {
  582. amount = amount === 0 ? 0 : amount || 10;
  583. var hsl = tinycolor(color).toHsl();
  584. hsl.l -= amount / 100;
  585. hsl.l = clamp01(hsl.l);
  586. return tinycolor(hsl);
  587. }
  588. // Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
  589. // Values outside of this range will be wrapped into this range.
  590. function _spin(color, amount) {
  591. var hsl = tinycolor(color).toHsl();
  592. var hue = (hsl.h + amount) % 360;
  593. hsl.h = hue < 0 ? 360 + hue : hue;
  594. return tinycolor(hsl);
  595. }
  596. // Combination Functions
  597. // ---------------------
  598. // Thanks to jQuery xColor for some of the ideas behind these
  599. // <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>
  600. function _complement(color) {
  601. var hsl = tinycolor(color).toHsl();
  602. hsl.h = (hsl.h + 180) % 360;
  603. return tinycolor(hsl);
  604. }
  605. function polyad(color, number) {
  606. if (isNaN(number) || number <= 0) {
  607. throw new Error("Argument to polyad must be a positive number");
  608. }
  609. var hsl = tinycolor(color).toHsl();
  610. var result = [tinycolor(color)];
  611. var step = 360 / number;
  612. for (var i = 1; i < number; i++) {
  613. result.push(tinycolor({
  614. h: (hsl.h + i * step) % 360,
  615. s: hsl.s,
  616. l: hsl.l
  617. }));
  618. }
  619. return result;
  620. }
  621. function _splitcomplement(color) {
  622. var hsl = tinycolor(color).toHsl();
  623. var h = hsl.h;
  624. return [tinycolor(color), tinycolor({
  625. h: (h + 72) % 360,
  626. s: hsl.s,
  627. l: hsl.l
  628. }), tinycolor({
  629. h: (h + 216) % 360,
  630. s: hsl.s,
  631. l: hsl.l
  632. })];
  633. }
  634. function _analogous(color, results, slices) {
  635. results = results || 6;
  636. slices = slices || 30;
  637. var hsl = tinycolor(color).toHsl();
  638. var part = 360 / slices;
  639. var ret = [tinycolor(color)];
  640. for (hsl.h = (hsl.h - (part * results >> 1) + 720) % 360; --results;) {
  641. hsl.h = (hsl.h + part) % 360;
  642. ret.push(tinycolor(hsl));
  643. }
  644. return ret;
  645. }
  646. function _monochromatic(color, results) {
  647. results = results || 6;
  648. var hsv = tinycolor(color).toHsv();
  649. var h = hsv.h,
  650. s = hsv.s,
  651. v = hsv.v;
  652. var ret = [];
  653. var modification = 1 / results;
  654. while (results--) {
  655. ret.push(tinycolor({
  656. h: h,
  657. s: s,
  658. v: v
  659. }));
  660. v = (v + modification) % 1;
  661. }
  662. return ret;
  663. }
  664. // Utility Functions
  665. // ---------------------
  666. tinycolor.mix = function (color1, color2, amount) {
  667. amount = amount === 0 ? 0 : amount || 50;
  668. var rgb1 = tinycolor(color1).toRgb();
  669. var rgb2 = tinycolor(color2).toRgb();
  670. var p = amount / 100;
  671. var rgba = {
  672. r: (rgb2.r - rgb1.r) * p + rgb1.r,
  673. g: (rgb2.g - rgb1.g) * p + rgb1.g,
  674. b: (rgb2.b - rgb1.b) * p + rgb1.b,
  675. a: (rgb2.a - rgb1.a) * p + rgb1.a
  676. };
  677. return tinycolor(rgba);
  678. };
  679. // Readability Functions
  680. // ---------------------
  681. // <http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef (WCAG Version 2)
  682. // `contrast`
  683. // Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2)
  684. tinycolor.readability = function (color1, color2) {
  685. var c1 = tinycolor(color1);
  686. var c2 = tinycolor(color2);
  687. return (Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05);
  688. };
  689. // `isReadable`
  690. // Ensure that foreground and background color combinations meet WCAG2 guidelines.
  691. // The third argument is an optional Object.
  692. // the 'level' property states 'AA' or 'AAA' - if missing or invalid, it defaults to 'AA';
  693. // the 'size' property states 'large' or 'small' - if missing or invalid, it defaults to 'small'.
  694. // If the entire object is absent, isReadable defaults to {level:"AA",size:"small"}.
  695. // *Example*
  696. // tinycolor.isReadable("#000", "#111") => false
  697. // tinycolor.isReadable("#000", "#111",{level:"AA",size:"large"}) => false
  698. tinycolor.isReadable = function (color1, color2, wcag2) {
  699. var readability = tinycolor.readability(color1, color2);
  700. var wcag2Parms, out;
  701. out = false;
  702. wcag2Parms = validateWCAG2Parms(wcag2);
  703. switch (wcag2Parms.level + wcag2Parms.size) {
  704. case "AAsmall":
  705. case "AAAlarge":
  706. out = readability >= 4.5;
  707. break;
  708. case "AAlarge":
  709. out = readability >= 3;
  710. break;
  711. case "AAAsmall":
  712. out = readability >= 7;
  713. break;
  714. }
  715. return out;
  716. };
  717. // `mostReadable`
  718. // Given a base color and a list of possible foreground or background
  719. // colors for that base, returns the most readable color.
  720. // Optionally returns Black or White if the most readable color is unreadable.
  721. // *Example*
  722. // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:false}).toHexString(); // "#112255"
  723. // tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:true}).toHexString(); // "#ffffff"
  724. // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(); // "#faf3f3"
  725. // tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff"
  726. tinycolor.mostReadable = function (baseColor, colorList, args) {
  727. var bestColor = null;
  728. var bestScore = 0;
  729. var readability;
  730. var includeFallbackColors, level, size;
  731. args = args || {};
  732. includeFallbackColors = args.includeFallbackColors;
  733. level = args.level;
  734. size = args.size;
  735. for (var i = 0; i < colorList.length; i++) {
  736. readability = tinycolor.readability(baseColor, colorList[i]);
  737. if (readability > bestScore) {
  738. bestScore = readability;
  739. bestColor = tinycolor(colorList[i]);
  740. }
  741. }
  742. if (tinycolor.isReadable(baseColor, bestColor, {
  743. level: level,
  744. size: size
  745. }) || !includeFallbackColors) {
  746. return bestColor;
  747. } else {
  748. args.includeFallbackColors = false;
  749. return tinycolor.mostReadable(baseColor, ["#fff", "#000"], args);
  750. }
  751. };
  752. // Big List of Colors
  753. // ------------------
  754. // <https://www.w3.org/TR/css-color-4/#named-colors>
  755. var names = tinycolor.names = {
  756. aliceblue: "f0f8ff",
  757. antiquewhite: "faebd7",
  758. aqua: "0ff",
  759. aquamarine: "7fffd4",
  760. azure: "f0ffff",
  761. beige: "f5f5dc",
  762. bisque: "ffe4c4",
  763. black: "000",
  764. blanchedalmond: "ffebcd",
  765. blue: "00f",
  766. blueviolet: "8a2be2",
  767. brown: "a52a2a",
  768. burlywood: "deb887",
  769. burntsienna: "ea7e5d",
  770. cadetblue: "5f9ea0",
  771. chartreuse: "7fff00",
  772. chocolate: "d2691e",
  773. coral: "ff7f50",
  774. cornflowerblue: "6495ed",
  775. cornsilk: "fff8dc",
  776. crimson: "dc143c",
  777. cyan: "0ff",
  778. darkblue: "00008b",
  779. darkcyan: "008b8b",
  780. darkgoldenrod: "b8860b",
  781. darkgray: "a9a9a9",
  782. darkgreen: "006400",
  783. darkgrey: "a9a9a9",
  784. darkkhaki: "bdb76b",
  785. darkmagenta: "8b008b",
  786. darkolivegreen: "556b2f",
  787. darkorange: "ff8c00",
  788. darkorchid: "9932cc",
  789. darkred: "8b0000",
  790. darksalmon: "e9967a",
  791. darkseagreen: "8fbc8f",
  792. darkslateblue: "483d8b",
  793. darkslategray: "2f4f4f",
  794. darkslategrey: "2f4f4f",
  795. darkturquoise: "00ced1",
  796. darkviolet: "9400d3",
  797. deeppink: "ff1493",
  798. deepskyblue: "00bfff",
  799. dimgray: "696969",
  800. dimgrey: "696969",
  801. dodgerblue: "1e90ff",
  802. firebrick: "b22222",
  803. floralwhite: "fffaf0",
  804. forestgreen: "228b22",
  805. fuchsia: "f0f",
  806. gainsboro: "dcdcdc",
  807. ghostwhite: "f8f8ff",
  808. gold: "ffd700",
  809. goldenrod: "daa520",
  810. gray: "808080",
  811. green: "008000",
  812. greenyellow: "adff2f",
  813. grey: "808080",
  814. honeydew: "f0fff0",
  815. hotpink: "ff69b4",
  816. indianred: "cd5c5c",
  817. indigo: "4b0082",
  818. ivory: "fffff0",
  819. khaki: "f0e68c",
  820. lavender: "e6e6fa",
  821. lavenderblush: "fff0f5",
  822. lawngreen: "7cfc00",
  823. lemonchiffon: "fffacd",
  824. lightblue: "add8e6",
  825. lightcoral: "f08080",
  826. lightcyan: "e0ffff",
  827. lightgoldenrodyellow: "fafad2",
  828. lightgray: "d3d3d3",
  829. lightgreen: "90ee90",
  830. lightgrey: "d3d3d3",
  831. lightpink: "ffb6c1",
  832. lightsalmon: "ffa07a",
  833. lightseagreen: "20b2aa",
  834. lightskyblue: "87cefa",
  835. lightslategray: "789",
  836. lightslategrey: "789",
  837. lightsteelblue: "b0c4de",
  838. lightyellow: "ffffe0",
  839. lime: "0f0",
  840. limegreen: "32cd32",
  841. linen: "faf0e6",
  842. magenta: "f0f",
  843. maroon: "800000",
  844. mediumaquamarine: "66cdaa",
  845. mediumblue: "0000cd",
  846. mediumorchid: "ba55d3",
  847. mediumpurple: "9370db",
  848. mediumseagreen: "3cb371",
  849. mediumslateblue: "7b68ee",
  850. mediumspringgreen: "00fa9a",
  851. mediumturquoise: "48d1cc",
  852. mediumvioletred: "c71585",
  853. midnightblue: "191970",
  854. mintcream: "f5fffa",
  855. mistyrose: "ffe4e1",
  856. moccasin: "ffe4b5",
  857. navajowhite: "ffdead",
  858. navy: "000080",
  859. oldlace: "fdf5e6",
  860. olive: "808000",
  861. olivedrab: "6b8e23",
  862. orange: "ffa500",
  863. orangered: "ff4500",
  864. orchid: "da70d6",
  865. palegoldenrod: "eee8aa",
  866. palegreen: "98fb98",
  867. paleturquoise: "afeeee",
  868. palevioletred: "db7093",
  869. papayawhip: "ffefd5",
  870. peachpuff: "ffdab9",
  871. peru: "cd853f",
  872. pink: "ffc0cb",
  873. plum: "dda0dd",
  874. powderblue: "b0e0e6",
  875. purple: "800080",
  876. rebeccapurple: "663399",
  877. red: "f00",
  878. rosybrown: "bc8f8f",
  879. royalblue: "4169e1",
  880. saddlebrown: "8b4513",
  881. salmon: "fa8072",
  882. sandybrown: "f4a460",
  883. seagreen: "2e8b57",
  884. seashell: "fff5ee",
  885. sienna: "a0522d",
  886. silver: "c0c0c0",
  887. skyblue: "87ceeb",
  888. slateblue: "6a5acd",
  889. slategray: "708090",
  890. slategrey: "708090",
  891. snow: "fffafa",
  892. springgreen: "00ff7f",
  893. steelblue: "4682b4",
  894. tan: "d2b48c",
  895. teal: "008080",
  896. thistle: "d8bfd8",
  897. tomato: "ff6347",
  898. turquoise: "40e0d0",
  899. violet: "ee82ee",
  900. wheat: "f5deb3",
  901. white: "fff",
  902. whitesmoke: "f5f5f5",
  903. yellow: "ff0",
  904. yellowgreen: "9acd32"
  905. };
  906. // Make it easy to access colors via `hexNames[hex]`
  907. var hexNames = tinycolor.hexNames = flip(names);
  908. // Utilities
  909. // ---------
  910. // `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }`
  911. function flip(o) {
  912. var flipped = {};
  913. for (var i in o) {
  914. if (o.hasOwnProperty(i)) {
  915. flipped[o[i]] = i;
  916. }
  917. }
  918. return flipped;
  919. }
  920. // Return a valid alpha value [0,1] with all invalid values being set to 1
  921. function boundAlpha(a) {
  922. a = parseFloat(a);
  923. if (isNaN(a) || a < 0 || a > 1) {
  924. a = 1;
  925. }
  926. return a;
  927. }
  928. // Take input from [0, n] and return it as [0, 1]
  929. function bound01(n, max) {
  930. if (isOnePointZero(n)) n = "100%";
  931. var processPercent = isPercentage(n);
  932. n = Math.min(max, Math.max(0, parseFloat(n)));
  933. // Automatically convert percentage into number
  934. if (processPercent) {
  935. n = parseInt(n * max, 10) / 100;
  936. }
  937. // Handle floating point rounding errors
  938. if (Math.abs(n - max) < 0.000001) {
  939. return 1;
  940. }
  941. // Convert into [0, 1] range if it isn't already
  942. return n % max / parseFloat(max);
  943. }
  944. // Force a number between 0 and 1
  945. function clamp01(val) {
  946. return Math.min(1, Math.max(0, val));
  947. }
  948. // Parse a base-16 hex value into a base-10 integer
  949. function parseIntFromHex(val) {
  950. return parseInt(val, 16);
  951. }
  952. // Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
  953. // <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
  954. function isOnePointZero(n) {
  955. return typeof n == "string" && n.indexOf(".") != -1 && parseFloat(n) === 1;
  956. }
  957. // Check to see if string passed in is a percentage
  958. function isPercentage(n) {
  959. return typeof n === "string" && n.indexOf("%") != -1;
  960. }
  961. // Force a hex value to have 2 characters
  962. function pad2(c) {
  963. return c.length == 1 ? "0" + c : "" + c;
  964. }
  965. // Replace a decimal with it's percentage value
  966. function convertToPercentage(n) {
  967. if (n <= 1) {
  968. n = n * 100 + "%";
  969. }
  970. return n;
  971. }
  972. // Converts a decimal to a hex value
  973. function convertDecimalToHex(d) {
  974. return Math.round(parseFloat(d) * 255).toString(16);
  975. }
  976. // Converts a hex value to a decimal
  977. function convertHexToDecimal(h) {
  978. return parseIntFromHex(h) / 255;
  979. }
  980. var matchers = function () {
  981. // <http://www.w3.org/TR/css3-values/#integers>
  982. var CSS_INTEGER = "[-\\+]?\\d+%?";
  983. // <http://www.w3.org/TR/css3-values/#number-value>
  984. var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
  985. // Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
  986. var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
  987. // Actual matching.
  988. // Parentheses and commas are optional, but not required.
  989. // Whitespace can take the place of commas or opening paren
  990. var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
  991. var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
  992. return {
  993. CSS_UNIT: new RegExp(CSS_UNIT),
  994. rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
  995. rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
  996. hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
  997. hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
  998. hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
  999. hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
  1000. hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
  1001. hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
  1002. hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
  1003. hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
  1004. };
  1005. }();
  1006. // `isValidCSSUnit`
  1007. // Take in a single string / number and check to see if it looks like a CSS unit
  1008. // (see `matchers` above for definition).
  1009. function isValidCSSUnit(color) {
  1010. return !!matchers.CSS_UNIT.exec(color);
  1011. }
  1012. // `stringInputToObject`
  1013. // Permissive string parsing. Take in a number of formats, and output an object
  1014. // based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
  1015. function stringInputToObject(color) {
  1016. color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
  1017. var named = false;
  1018. if (names[color]) {
  1019. color = names[color];
  1020. named = true;
  1021. } else if (color == "transparent") {
  1022. return {
  1023. r: 0,
  1024. g: 0,
  1025. b: 0,
  1026. a: 0,
  1027. format: "name"
  1028. };
  1029. }
  1030. // Try to match string input using regular expressions.
  1031. // Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
  1032. // Just return an object and let the conversion functions handle that.
  1033. // This way the result will be the same whether the tinycolor is initialized with string or object.
  1034. var match;
  1035. if (match = matchers.rgb.exec(color)) {
  1036. return {
  1037. r: match[1],
  1038. g: match[2],
  1039. b: match[3]
  1040. };
  1041. }
  1042. if (match = matchers.rgba.exec(color)) {
  1043. return {
  1044. r: match[1],
  1045. g: match[2],
  1046. b: match[3],
  1047. a: match[4]
  1048. };
  1049. }
  1050. if (match = matchers.hsl.exec(color)) {
  1051. return {
  1052. h: match[1],
  1053. s: match[2],
  1054. l: match[3]
  1055. };
  1056. }
  1057. if (match = matchers.hsla.exec(color)) {
  1058. return {
  1059. h: match[1],
  1060. s: match[2],
  1061. l: match[3],
  1062. a: match[4]
  1063. };
  1064. }
  1065. if (match = matchers.hsv.exec(color)) {
  1066. return {
  1067. h: match[1],
  1068. s: match[2],
  1069. v: match[3]
  1070. };
  1071. }
  1072. if (match = matchers.hsva.exec(color)) {
  1073. return {
  1074. h: match[1],
  1075. s: match[2],
  1076. v: match[3],
  1077. a: match[4]
  1078. };
  1079. }
  1080. if (match = matchers.hex8.exec(color)) {
  1081. return {
  1082. r: parseIntFromHex(match[1]),
  1083. g: parseIntFromHex(match[2]),
  1084. b: parseIntFromHex(match[3]),
  1085. a: convertHexToDecimal(match[4]),
  1086. format: named ? "name" : "hex8"
  1087. };
  1088. }
  1089. if (match = matchers.hex6.exec(color)) {
  1090. return {
  1091. r: parseIntFromHex(match[1]),
  1092. g: parseIntFromHex(match[2]),
  1093. b: parseIntFromHex(match[3]),
  1094. format: named ? "name" : "hex"
  1095. };
  1096. }
  1097. if (match = matchers.hex4.exec(color)) {
  1098. return {
  1099. r: parseIntFromHex(match[1] + "" + match[1]),
  1100. g: parseIntFromHex(match[2] + "" + match[2]),
  1101. b: parseIntFromHex(match[3] + "" + match[3]),
  1102. a: convertHexToDecimal(match[4] + "" + match[4]),
  1103. format: named ? "name" : "hex8"
  1104. };
  1105. }
  1106. if (match = matchers.hex3.exec(color)) {
  1107. return {
  1108. r: parseIntFromHex(match[1] + "" + match[1]),
  1109. g: parseIntFromHex(match[2] + "" + match[2]),
  1110. b: parseIntFromHex(match[3] + "" + match[3]),
  1111. format: named ? "name" : "hex"
  1112. };
  1113. }
  1114. return false;
  1115. }
  1116. function validateWCAG2Parms(parms) {
  1117. // return valid WCAG2 parms for isReadable.
  1118. // If input parms are invalid, return {"level":"AA", "size":"small"}
  1119. var level, size;
  1120. parms = parms || {
  1121. level: "AA",
  1122. size: "small"
  1123. };
  1124. level = (parms.level || "AA").toUpperCase();
  1125. size = (parms.size || "small").toLowerCase();
  1126. if (level !== "AA" && level !== "AAA") {
  1127. level = "AA";
  1128. }
  1129. if (size !== "small" && size !== "large") {
  1130. size = "small";
  1131. }
  1132. return {
  1133. level: level,
  1134. size: size
  1135. };
  1136. }
  1137. return tinycolor;
  1138. }));
  1139. }, function(modId) {var map = {}; return __REQUIRE__(map[modId], modId); })
  1140. return __REQUIRE__(1741168270881);
  1141. })()
  1142. //miniprogram-npm-outsideDeps=[]
  1143. //# sourceMappingURL=index.js.map