89fc440520c39c0f219eb2083709de2a689a3a11de8a1d7615a93f5046589e7c958dc37827980b4e8d3ebf3c4f806fde7e23e404caf4ce2179b1a134fdf8bc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. # tinycolor
  2. [![npm](https://badgen.net/npm/v/@ctrl/tinycolor)](https://www.npmjs.com/package/@ctrl/tinycolor)
  3. [![CircleCI](https://badgen.net/circleci/github/scttcper/tinycolor)](https://circleci.com/gh/scttcper/tinycolor)
  4. [![coverage](https://badgen.net/codecov/c/github/scttcper/tinycolor)](https://codecov.io/gh/scttcper/tinycolor)
  5. [![bundlesize](https://badgen.net/bundlephobia/min/@ctrl/tinycolor)](https://bundlephobia.com/result?p=@ctrl/tinycolor)
  6. > TinyColor is a small library for color manipulation and conversion
  7. A fork of [tinycolor2](https://github.com/bgrins/TinyColor) by [Brian Grinstead](https://github.com/bgrins)
  8. __DEMO__: https://tinycolor.vercel.app
  9. ### Changes from tinycolor2
  10. * reformatted into TypeScript / es2015 and requires node >= 8
  11. * tree shakeable "module" export and no package `sideEffects`
  12. * `tinycolor` is now exported as a class called `TinyColor`
  13. * new `random`, an implementation of [randomColor](https://github.com/davidmerfield/randomColor/) by David Merfield that returns a TinyColor object
  14. * several functions moved out of the tinycolor class and are no longer `TinyColor.<function>`
  15. * `readability`, `fromRatio` moved out
  16. * `random` moved out and renamed to `legacyRandom`
  17. * `toFilter` has been moved out and renamed to `toMsFilter`
  18. * `mix`, `equals` use the current TinyColor object as the first parameter
  19. * added polyad colors tinycolor PR [126](https://github.com/bgrins/TinyColor/pull/126)
  20. * color wheel values (360) are allowed to over or under-spin and still return valid colors tinycolor PR [108](https://github.com/bgrins/TinyColor/pull/108)
  21. * added `tint()` and `shade()` tinycolor PR [159](https://github.com/bgrins/TinyColor/pull/159)
  22. * `isValid`, `format` are now propertys instead of a function
  23. ## Install
  24. ```sh
  25. npm install @ctrl/tinycolor
  26. ```
  27. ## Use
  28. ```ts
  29. import { TinyColor } from '@ctrl/tinycolor';
  30. const color = new TinyColor('red').toHexString(); // '#ff0000'
  31. ```
  32. ## Accepted String Input
  33. The string parsing is very permissive. It is meant to make typing a color as input as easy as possible. All commas, percentages, parenthesis are optional, and most input allow either 0-1, 0%-100%, or 0-n (where n is either 100, 255, or 360 depending on the value).
  34. HSL and HSV both require either 0%-100% or 0-1 for the `S`/`L`/`V` properties. The `H` (hue) can have values between 0%-100% or 0-360.
  35. RGB input requires either 0-255 or 0%-100%.
  36. If you call `tinycolor.fromRatio`, RGB and Hue input can also accept 0-1.
  37. Here are some examples of string input:
  38. ### Hex, 8-digit (RGBA) Hex
  39. ```ts
  40. new TinyColor('#000');
  41. new TinyColor('000');
  42. new TinyColor('#369C');
  43. new TinyColor('369C');
  44. new TinyColor('#f0f0f6');
  45. new TinyColor('f0f0f6');
  46. new TinyColor('#f0f0f688');
  47. new TinyColor('f0f0f688');
  48. ```
  49. ### RGB, RGBA
  50. ```ts
  51. new TinyColor('rgb (255, 0, 0)');
  52. new TinyColor('rgb 255 0 0');
  53. new TinyColor('rgba (255, 0, 0, .5)');
  54. new TinyColor({ r: 255, g: 0, b: 0 });
  55. import { fromRatio } from '@ctrl/tinycolor';
  56. fromRatio({ r: 1, g: 0, b: 0 });
  57. fromRatio({ r: 0.5, g: 0.5, b: 0.5 });
  58. ```
  59. ### HSL, HSLA
  60. ```ts
  61. new TinyColor('hsl(0, 100%, 50%)');
  62. new TinyColor('hsla(0, 100%, 50%, .5)');
  63. new TinyColor('hsl(0, 100%, 50%)');
  64. new TinyColor('hsl 0 1.0 0.5');
  65. new TinyColor({ h: 0, s: 1, l: 0.5 });
  66. ```
  67. ### HSV, HSVA
  68. ```ts
  69. new TinyColor('hsv(0, 100%, 100%)');
  70. new TinyColor('hsva(0, 100%, 100%, .5)');
  71. new TinyColor('hsv (0 100% 100%)');
  72. new TinyColor('hsv 0 1 1');
  73. new TinyColor({ h: 0, s: 100, v: 100 });
  74. ```
  75. ### Named
  76. ```ts
  77. new TinyColor('RED');
  78. new TinyColor('blanchedalmond');
  79. new TinyColor('darkblue');
  80. ```
  81. ### Number
  82. ```ts
  83. new TinyColor(0x0);
  84. new TinyColor(0xaabbcc);
  85. ```
  86. ### Accepted Object Input
  87. If you are calling this from code, you may want to use object input. Here are some examples of the different types of accepted object inputs:
  88. ```ts
  89. { r: 255, g: 0, b: 0 }
  90. { r: 255, g: 0, b: 0, a: .5 }
  91. { h: 0, s: 100, l: 50 }
  92. { h: 0, s: 100, v: 100 }
  93. ```
  94. ## Properties
  95. ### originalInput
  96. The original input passed into the constructer used to create the tinycolor instance
  97. ```ts
  98. const color = new TinyColor('red');
  99. color.originalInput; // "red"
  100. color = new TinyColor({ r: 255, g: 255, b: 255 });
  101. color.originalInput; // "{r: 255, g: 255, b: 255}"
  102. ```
  103. ### format
  104. Returns the format used to create the tinycolor instance
  105. ```ts
  106. const color = new TinyColor('red');
  107. color.format; // "name"
  108. color = new TinyColor({ r: 255, g: 255, b: 255 });
  109. color.format; // "rgb"
  110. ```
  111. ### isValid
  112. A boolean indicating whether the color was successfully parsed. Note: if the color is not valid then it will act like `black` when being used with other methods.
  113. ```ts
  114. const color1 = new TinyColor('red');
  115. color1.isValid; // true
  116. color1.toHexString(); // "#ff0000"
  117. const color2 = new TinyColor('not a color');
  118. color2.isValid; // false
  119. color2.toString(); // "#000000"
  120. ```
  121. ## Methods
  122. ### getBrightness
  123. Returns the perceived brightness of a color, from `0-255`, as defined by [Web Content Accessibility Guidelines (Version 1.0)](http://www.w3.org/TR/AERT#color-contrast).
  124. ```ts
  125. const color1 = new TinyColor('#fff');
  126. color1.getBrightness(); // 255
  127. const color2 = new TinyColor('#000');
  128. color2.getBrightness(); // 0
  129. ```
  130. ### isLight
  131. Return a boolean indicating whether the color's perceived brightness is light.
  132. ```ts
  133. const color1 = new TinyColor('#fff');
  134. color1.isLight(); // true
  135. const color2 = new TinyColor('#000');
  136. color2.isLight(); // false
  137. ```
  138. ### isDark
  139. Return a boolean indicating whether the color's perceived brightness is dark.
  140. ```ts
  141. const color1 = new TinyColor('#fff');
  142. color1.isDark(); // false
  143. const color2 = new TinyColor('#000');
  144. color2.isDark(); // true
  145. ```
  146. ### getLuminance
  147. Returns the perceived luminance of a color, from `0-1` as defined by [Web Content Accessibility Guidelines (Version 2.0).](http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef)
  148. ```ts
  149. const color1 = new TinyColor('#fff');
  150. color1.getLuminance(); // 1
  151. const color2 = new TinyColor('#000');
  152. color2.getLuminance(); // 0
  153. ```
  154. ### getAlpha
  155. Returns the alpha value of a color, from `0-1`.
  156. ```ts
  157. const color1 = new TinyColor('rgba(255, 0, 0, .5)');
  158. color1.getAlpha(); // 0.5
  159. const color2 = new TinyColor('rgb(255, 0, 0)');
  160. color2.getAlpha(); // 1
  161. const color3 = new TinyColor('transparent');
  162. color3.getAlpha(); // 0
  163. ```
  164. ### setAlpha
  165. Sets the alpha value on a current color. Accepted range is in between `0-1`.
  166. ```ts
  167. const color = new TinyColor('red');
  168. color.getAlpha(); // 1
  169. color.setAlpha(0.5);
  170. color.getAlpha(); // .5
  171. color.toRgbString(); // "rgba(255, 0, 0, .5)"
  172. ```
  173. ### onBackground
  174. Compute how the color would appear on a background. When the color is fully transparent (i.e. `getAlpha() == 0`), the result will be the background color. When the color is not transparent at all (i.e. `getAlpha() == 1`), the result will be the color itself. Otherwise you will get a computed result.
  175. ```ts
  176. const color = new TinyColor('rgba(255, 0, 0, .5)');
  177. const computedColor = color.onBackground('rgb(0, 0, 255)');
  178. computedColor.toRgbString(); // "rgb(128, 0, 128)"
  179. ```
  180. ### String Representations
  181. The following methods will return a property for the `alpha` value, which can be ignored: `toHsv`, `toHsl`, `toRgb`
  182. ### toHsv
  183. ```ts
  184. const color = new TinyColor('red');
  185. color.toHsv(); // { h: 0, s: 1, v: 1, a: 1 }
  186. ```
  187. ### toHsvString
  188. ```ts
  189. const color = new TinyColor('red');
  190. color.toHsvString(); // "hsv(0, 100%, 100%)"
  191. color.setAlpha(0.5);
  192. color.toHsvString(); // "hsva(0, 100%, 100%, 0.5)"
  193. ```
  194. ### toHsl
  195. ```ts
  196. const color = new TinyColor('red');
  197. color.toHsl(); // { h: 0, s: 1, l: 0.5, a: 1 }
  198. ```
  199. ### toHslString
  200. ```ts
  201. const color = new TinyColor('red');
  202. color.toHslString(); // "hsl(0, 100%, 50%)"
  203. color.setAlpha(0.5);
  204. color.toHslString(); // "hsla(0, 100%, 50%, 0.5)"
  205. ```
  206. ### toNumber
  207. ```ts
  208. new TinyColor('#aabbcc').toNumber() === 0xaabbcc // true
  209. new TinyColor('rgb(1, 1, 1)').toNumber() === (1 << 16) + (1 << 8) + 1 // true
  210. ```
  211. ### toHex
  212. ```ts
  213. const color = new TinyColor('red');
  214. color.toHex(); // "ff0000"
  215. ```
  216. ### toHexString
  217. ```ts
  218. const color = new TinyColor('red');
  219. color.toHexString(); // "#ff0000"
  220. ```
  221. ### toHex8
  222. ```ts
  223. const color = new TinyColor('red');
  224. color.toHex8(); // "ff0000ff"
  225. ```
  226. ### toHex8String
  227. ```ts
  228. const color = new TinyColor('red');
  229. color.toHex8String(); // "#ff0000ff"
  230. ```
  231. ### toHexShortString
  232. ```ts
  233. const color1 = new TinyColor('#ff000000');
  234. color1.toHexShortString(); // "#ff000000"
  235. color1.toHexShortString(true); // "#f000"
  236. const color2 = new TinyColor('#ff0000ff');
  237. color2.toHexShortString(); // "#ff0000"
  238. color2.toHexShortString(true); // "#f00"
  239. ```
  240. ### toRgb
  241. ```ts
  242. const color = new TinyColor('red');
  243. color.toRgb(); // { r: 255, g: 0, b: 0, a: 1 }
  244. ```
  245. ### toRgbString
  246. ```ts
  247. const color = new TinyColor('red');
  248. color.toRgbString(); // "rgb(255, 0, 0)"
  249. color.setAlpha(0.5);
  250. color.toRgbString(); // "rgba(255, 0, 0, 0.5)"
  251. ```
  252. ### toPercentageRgb
  253. ```ts
  254. const color = new TinyColor('red');
  255. color.toPercentageRgb(); // { r: "100%", g: "0%", b: "0%", a: 1 }
  256. ```
  257. ### toPercentageRgbString
  258. ```ts
  259. const color = new TinyColor('red');
  260. color.toPercentageRgbString(); // "rgb(100%, 0%, 0%)"
  261. color.setAlpha(0.5);
  262. color.toPercentageRgbString(); // "rgba(100%, 0%, 0%, 0.5)"
  263. ```
  264. ### toName
  265. ```ts
  266. const color = new TinyColor('red');
  267. color.toName(); // "red"
  268. ```
  269. ### toFilter
  270. ```ts
  271. import { toMsFilter } from '@ctrl/tinycolor';
  272. toMsFilter('red', 'blue'); // 'progid:DXImageTransform.Microsoft.gradient(startColorstr=#ffff0000,endColorstr=#ff0000ff)'
  273. ```
  274. ### toString
  275. Print to a string, depending on the input format. You can also override this by passing one of `"rgb", "prgb", "hex6", "hex3", "hex8", "name", "hsl", "hsv"` into the function.
  276. ```ts
  277. const color1 = new TinyColor('red');
  278. color1.toString(); // "red"
  279. color1.toString('hsv'); // "hsv(0, 100%, 100%)"
  280. const color2 = new TinyColor('rgb(255, 0, 0)');
  281. color2.toString(); // "rgb(255, 0, 0)"
  282. color2.setAlpha(0.5);
  283. color2.toString(); // "rgba(255, 0, 0, 0.5)"
  284. ```
  285. ### Color Modification
  286. These methods manipulate the current color, and return it for chaining. For instance:
  287. ```ts
  288. new TinyColor('red')
  289. .lighten()
  290. .desaturate()
  291. .toHexString(); // '#f53d3d'
  292. ```
  293. ### lighten
  294. `lighten: function(amount = 10) -> TinyColor`. Lighten the color a given amount, from 0 to 100. Providing 100 will always return white.
  295. ```ts
  296. new TinyColor('#f00').lighten().toString(); // '#ff3333'
  297. new TinyColor('#f00').lighten(100).toString(); // '#ffffff'
  298. ```
  299. ### brighten
  300. `brighten: function(amount = 10) -> TinyColor`. Brighten the color a given amount, from 0 to 100.
  301. ```ts
  302. new TinyColor('#f00').brighten().toString(); // '#ff1919'
  303. ```
  304. ### darken
  305. `darken: function(amount = 10) -> TinyColor`. Darken the color a given amount, from 0 to 100. Providing 100 will always return black.
  306. ```ts
  307. new TinyColor('#f00').darken().toString(); // '#cc0000'
  308. new TinyColor('#f00').darken(100).toString(); // '#000000'
  309. ```
  310. ### tint
  311. Mix the color with pure white, from 0 to 100. Providing 0 will do nothing, providing 100 will always return white.
  312. ```ts
  313. new TinyColor('#f00').tint().toString(); // "#ff1a1a"
  314. new TinyColor('#f00').tint(100).toString(); // "#ffffff"
  315. ```
  316. ### shade
  317. Mix the color with pure black, from 0 to 100. Providing 0 will do nothing, providing 100 will always return black.
  318. ```ts
  319. new TinyColor('#f00').shade().toString(); // "#e60000"
  320. new TinyColor('#f00').shade(100).toString(); // "#000000"
  321. ```
  322. ### desaturate
  323. `desaturate: function(amount = 10) -> TinyColor`. Desaturate the color a given amount, from 0 to 100. Providing 100 will is the same as calling `greyscale`.
  324. ```ts
  325. new TinyColor('#f00').desaturate().toString(); // "#f20d0d"
  326. new TinyColor('#f00').desaturate(100).toString(); // "#808080"
  327. ```
  328. ### saturate
  329. `saturate: function(amount = 10) -> TinyColor`. Saturate the color a given amount, from 0 to 100.
  330. ```ts
  331. new TinyColor('hsl(0, 10%, 50%)').saturate().toString(); // "hsl(0, 20%, 50%)"
  332. ```
  333. ### greyscale
  334. `greyscale: function() -> TinyColor`. Completely desaturates a color into greyscale. Same as calling `desaturate(100)`.
  335. ```ts
  336. new TinyColor('#f00').greyscale().toString(); // "#808080"
  337. ```
  338. ### spin
  339. `spin: function(amount = 0) -> TinyColor`. Spin the hue a given amount, from -360 to 360. Calling with 0, 360, or -360 will do nothing (since it sets the hue back to what it was before).
  340. ```ts
  341. new TinyColor('#f00').spin(180).toString(); // "#00ffff"
  342. new TinyColor('#f00').spin(-90).toString(); // "#7f00ff"
  343. new TinyColor('#f00').spin(90).toString(); // "#80ff00"
  344. // spin(0) and spin(360) do nothing
  345. new TinyColor('#f00').spin(0).toString(); // "#ff0000"
  346. new TinyColor('#f00').spin(360).toString(); // "#ff0000"
  347. ```
  348. ### mix
  349. `mix: function(amount = 50) => TinyColor`. Mix the current color a given amount with another color, from 0 to 100. 0 means no mixing (return current color).
  350. ```ts
  351. let color1 = new TinyColor('#f0f');
  352. let color2 = new TinyColor('#0f0');
  353. color1.mix(color2).toHexString(); // #808080
  354. ```
  355. ### Color Combinations
  356. Combination functions return an array of TinyColor objects unless otherwise noted.
  357. ### analogous
  358. `analogous: function(results = 6, slices = 30) -> array<TinyColor>`.
  359. ```ts
  360. const colors = new TinyColor('#f00').analogous();
  361. colors.map(t => t.toHexString()); // [ "#ff0000", "#ff0066", "#ff0033", "#ff0000", "#ff3300", "#ff6600" ]
  362. ```
  363. ### monochromatic
  364. `monochromatic: function(, results = 6) -> array<TinyColor>`.
  365. ```ts
  366. const colors = new TinyColor('#f00').monochromatic();
  367. colors.map(t => t.toHexString()); // [ "#ff0000", "#2a0000", "#550000", "#800000", "#aa0000", "#d40000" ]
  368. ```
  369. ### splitcomplement
  370. `splitcomplement: function() -> array<TinyColor>`.
  371. ```ts
  372. const colors = new TinyColor('#f00').splitcomplement();
  373. colors.map(t => t.toHexString()); // [ "#ff0000", "#ccff00", "#0066ff" ]
  374. ```
  375. ### triad
  376. `triad: function() -> array<TinyColor>`. Alias for `polyad(3)`.
  377. ```ts
  378. const colors = new TinyColor('#f00').triad();
  379. colors.map(t => t.toHexString()); // [ "#ff0000", "#00ff00", "#0000ff" ]
  380. ```
  381. ### tetrad
  382. `tetrad: function() -> array<TinyColor>`. Alias for `polyad(4)`.
  383. ```ts
  384. const colors = new TinyColor('#f00').tetrad();
  385. colors.map(t => t.toHexString()); // [ "#ff0000", "#80ff00", "#00ffff", "#7f00ff" ]
  386. ```
  387. ### polyad
  388. `polyad: function(number) -> array<TinyColor>`.
  389. ```ts
  390. const colors = new TinyColor('#f00').polyad(4);
  391. colors.map(t => t.toHexString()); // [ "#ff0000", "#80ff00", "#00ffff", "#7f00ff" ]
  392. ```
  393. ### complement
  394. `complement: function() -> TinyColor`.
  395. ```ts
  396. new TinyColor('#f00').complement().toHexString(); // "#00ffff"
  397. ```
  398. ## Color Utilities
  399. ### equals
  400. ```ts
  401. let color1 = new TinyColor('red');
  402. let color2 = new TinyColor('#f00');
  403. color1.equals(color2); // true
  404. ```
  405. ### random
  406. Returns a random TinyColor object. This is an implementation of [randomColor](https://github.com/davidmerfield/randomColor/) by David Merfield.
  407. The difference input parsing and output formatting are handled by TinyColor.
  408. You can pass an options object to influence the type of color it produces. The options object accepts the following properties:
  409. * `hue` – Controls the hue of the generated color. You can pass a string representing a color name: `red`, `orange`, `yellow`, `green`, `blue`, `purple`, `pink` and `monochrome` are currently supported. If you pass a hexidecimal color string such as #00FFFF, its hue value will be extracted and used to generate colors.
  410. * `luminosity` – Controls the luminosity of the generated color. You can specify a string containing bright, light or dark.
  411. * `count` – An integer which specifies the number of colors to generate.
  412. * `seed` – An integer which when passed will cause randomColor to return the same color each time.
  413. * `alpha` – A decimal between 0 and 1. Only relevant when using a format with an alpha channel (rgba and hsla). Defaults to a random value.
  414. ```ts
  415. import { random } from '@ctrl/tinycolor';
  416. // Returns a TinyColor for an attractive color
  417. random();
  418. // Returns an array of ten green colors
  419. random({
  420. count: 10,
  421. hue: 'green',
  422. });
  423. // Returns a TinyColor object in a light blue
  424. random({
  425. luminosity: 'light',
  426. hue: 'blue',
  427. });
  428. // Returns a TinyColor object in a 'truly random' color
  429. random({
  430. luminosity: 'random',
  431. hue: 'random',
  432. });
  433. // Returns a dark RGB color with specified alpha
  434. random({
  435. luminosity: 'dark',
  436. alpha: 0.5,
  437. });
  438. ```
  439. ### Readability
  440. TinyColor assesses readability based on the [Web Content Accessibility Guidelines (Version 2.0)](http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef).
  441. #### readability
  442. `readability: function(TinyColor, TinyColor) -> number`.
  443. Returns the contrast ratio between two colors.
  444. ```ts
  445. import { readability } from '@ctrl/tinycolor';
  446. readability('#000', '#000'); // 1
  447. readability('#000', '#111'); // 1.1121078324840545
  448. readability('#000', '#fff'); // 21
  449. ```
  450. Use the values in your own calculations, or use one of the convenience functions below.
  451. #### isReadable
  452. `isReadable: function(TinyColor, TinyColor, Object) -> Boolean`. Ensure that foreground and background color combinations meet WCAG guidelines. `Object` is optional, defaulting to `{level: "AA",size: "small"}`. `level` can be `"AA"` or "AAA" and `size` can be `"small"` or `"large"`.
  453. Here are links to read more about the [AA](http://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html) and [AAA](http://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast7.html) requirements.
  454. ```ts
  455. import { isReadable } from '@ctrl/tinycolor';
  456. isReadable("#000", "#111"); // false
  457. isReadable("#ff0088", "#5c1a72", { level: "AA", size: "small" }); // false
  458. isReadable("#ff0088", "#5c1a72", { level: "AA", size: "large" }), // true
  459. ```
  460. #### mostReadable
  461. `mostReadable: function(TinyColor, [TinyColor, TinyColor ...], Object) -> Boolean`.
  462. Given a base color and a list of possible foreground or background colors for that base, returns the most readable color.
  463. If none of the colors in the list is readable, `mostReadable` will return the better of black or white if `includeFallbackColors:true`.
  464. ```ts
  465. import { mostReadable } from '@ctrl/tinycolor';
  466. mostReadable('#000', ['#f00', '#0f0', '#00f']).toHexString(); // "#00ff00"
  467. mostReadable('#123', ['#124', '#125'], { includeFallbackColors: false }).toHexString(); // "#112255"
  468. mostReadable('#123', ['#124', '#125'], { includeFallbackColors: true }).toHexString(); // "#ffffff"
  469. mostReadable('#ff0088', ['#2e0c3a'], {
  470. includeFallbackColors: true,
  471. level: 'AAA',
  472. size: 'large',
  473. }).toHexString(); // "#2e0c3a",
  474. mostReadable('#ff0088', ['#2e0c3a'], {
  475. includeFallbackColors: true,
  476. level: 'AAA',
  477. size: 'small',
  478. }).toHexString(); // "#000000",
  479. ```
  480. See [index.html](https://github.com/bgrins/TinyColor/blob/master/index.html) in the project for a demo.
  481. ## Common operations
  482. ### clone
  483. `clone: function() -> TinyColor`.
  484. Instantiate a new TinyColor object with the same color. Any changes to the new one won't affect the old one.
  485. ```ts
  486. const color1 = new TinyColor('#F00');
  487. const color2 = color1.clone();
  488. color2.setAlpha(0.5);
  489. color1.toString(); // "#ff0000"
  490. color2.toString(); // "rgba(255, 0, 0, 0.5)"
  491. ```