UNPKG

21.3 kBTypeScriptView Raw
1// Type definitions for tinycolor 1.4
2// Project: https://github.com/bgrins/TinyColor
3// Definitions by: Mordechai Zuber <https://github.com/M-Zuber>,
4// Geert Jansen <https://github.com/geertjansen>,
5// Niels van Hoorn <https://github.com/nvh>
6// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
7// TypeScript Version: 2.1
8
9declare namespace tinycolor {
10 type ColorInputWithoutInstance =
11 | string
12 | ColorFormats.PRGB
13 | ColorFormats.PRGBA
14 | ColorFormats.RGB
15 | ColorFormats.RGBA
16 | ColorFormats.HSL
17 | ColorFormats.HSLA
18 | ColorFormats.HSV
19 | ColorFormats.HSVA
20 ;
21 type ColorInput = ColorInputWithoutInstance | Instance;
22
23 namespace ColorFormats {
24 interface Alpha {
25 a: number;
26 }
27
28 interface PRGB {
29 r: string;
30 g: string;
31 b: string;
32 }
33
34 interface PRGBA extends PRGB, Alpha {}
35
36 interface RGB {
37 r: number;
38 g: number;
39 b: number;
40 }
41
42 interface RGBA extends RGB, Alpha {}
43
44 interface HSL {
45 h: number;
46 s: number;
47 l: number;
48 }
49
50 interface HSLA extends HSL, Alpha {}
51
52 interface HSV {
53 h: number;
54 s: number;
55 v: number;
56 }
57
58 interface HSVA extends HSV {
59 a: number;
60 }
61 }
62
63 interface ConstructorOptions {
64 format?: string | undefined;
65 gradientType?: boolean | undefined;
66 }
67
68 interface WCAG2Options {
69 level?: "AA" | "AAA" | undefined;
70 size?: "large" | "small" | undefined;
71 }
72
73 interface MostReadableArgs extends WCAG2Options {
74 includeFallbackColors?: boolean | undefined;
75 }
76
77 interface Constructor {
78 /**
79 * Create a tinycolor instance of the color named.
80 *
81 * @param color - the color as one of the valid color input format.
82 */
83 new (color?: ColorInput, opts?: ConstructorOptions): Instance;
84 (color?: ColorInput, opts?: ConstructorOptions): Instance;
85
86 /**
87 * Create a tinycolor instance based off the relative values.
88 * Works with any color formats
89 *
90 * @param ratio - the relative color/hue values to apply to the new instance.
91 */
92 fromRatio(ratio?: ColorInputWithoutInstance): Instance;
93
94 /**
95 * Compares two colors. Each colors can be any color inputs.
96 */
97 equals(color1?: ColorInput, color2?: ColorInput): boolean;
98
99 /**
100 * Returns a random color
101 */
102 random(): Instance;
103
104 mix(color1: ColorInput, color2: ColorInput, amount?: number): Instance;
105
106 /**
107 * Compares the two colors and returns the constrast between two colors as a number.
108 *
109 * @param color1 - the first color to be used in the comparison.
110 * @param color2 - the second color to be used in the comparison.
111 */
112 readability(color1: ColorInput, color2: ColorInput): number;
113
114 /**
115 * Ensure that foreground and background color combinations meet WCAG2 guidelines.
116 *
117 * @param color1 - the fore color wanted.
118 * @param color2 - the back color wanted.
119 * @param wcag2 - WCAG option. If the entire object is absent, function use the default of {level:"AA",size:"small"}.
120 * @param wcag2.level - The 'level' property states 'AA' or 'AAA'
121 * if missing or invalid, it defaults to 'AA'
122 * @param wcag2.size - The 'size' property states 'large' or 'small'
123 * if missing or invalid, it defaults to 'small'.
124 */
125 isReadable(color1: ColorInput, color2: ColorInput, wcag2?: WCAG2Options): boolean;
126
127 /**
128 * Given a base color and a list of possible foreground or background colors for that base,
129 * returns the most readable color. Optionally returns Black or White if the most readable color is unreadable.
130 *
131 * @param color - the base color.
132 * @param colorsToCompare - array of colors to pick the most readable one from.
133 * @param args - and object with extra arguments
134 */
135 mostReadable(baseColor: ColorInput, colorList: ColorInput[], args?: MostReadableArgs): Instance;
136
137 /**
138 * key: 'real' color name
139 * value: hex value ex. names["red"] --> "f00"
140 */
141 names: {
142 aliceblue: "f0f8ff";
143 antiquewhite: "faebd7";
144 aqua: "0ff";
145 aquamarine: "7fffd4";
146 azure: "f0ffff";
147 beige: "f5f5dc";
148 bisque: "ffe4c4";
149 black: "000";
150 blanchedalmond: "ffebcd";
151 blue: "00f";
152 blueviolet: "8a2be2";
153 brown: "a52a2a";
154 burlywood: "deb887";
155 burntsienna: "ea7e5d";
156 cadetblue: "5f9ea0";
157 chartreuse: "7fff00";
158 chocolate: "d2691e";
159 coral: "ff7f50";
160 cornflowerblue: "6495ed";
161 cornsilk: "fff8dc";
162 crimson: "dc143c";
163 cyan: "0ff";
164 darkblue: "00008b";
165 darkcyan: "008b8b";
166 darkgoldenrod: "b8860b";
167 darkgray: "a9a9a9";
168 darkgreen: "006400";
169 darkgrey: "a9a9a9";
170 darkkhaki: "bdb76b";
171 darkmagenta: "8b008b";
172 darkolivegreen: "556b2f";
173 darkorange: "ff8c00";
174 darkorchid: "9932cc";
175 darkred: "8b0000";
176 darksalmon: "e9967a";
177 darkseagreen: "8fbc8f";
178 darkslateblue: "483d8b";
179 darkslategray: "2f4f4f";
180 darkslategrey: "2f4f4f";
181 darkturquoise: "00ced1";
182 darkviolet: "9400d3";
183 deeppink: "ff1493";
184 deepskyblue: "00bfff";
185 dimgray: "696969";
186 dimgrey: "696969";
187 dodgerblue: "1e90ff";
188 firebrick: "b22222";
189 floralwhite: "fffaf0";
190 forestgreen: "228b22";
191 fuchsia: "f0f";
192 gainsboro: "dcdcdc";
193 ghostwhite: "f8f8ff";
194 gold: "ffd700";
195 goldenrod: "daa520";
196 gray: "808080";
197 green: "008000";
198 greenyellow: "adff2f";
199 grey: "808080";
200 honeydew: "f0fff0";
201 hotpink: "ff69b4";
202 indianred: "cd5c5c";
203 indigo: "4b0082";
204 ivory: "fffff0";
205 khaki: "f0e68c";
206 lavender: "e6e6fa";
207 lavenderblush: "fff0f5";
208 lawngreen: "7cfc00";
209 lemonchiffon: "fffacd";
210 lightblue: "add8e6";
211 lightcoral: "f08080";
212 lightcyan: "e0ffff";
213 lightgoldenrodyellow: "fafad2";
214 lightgray: "d3d3d3";
215 lightgreen: "90ee90";
216 lightgrey: "d3d3d3";
217 lightpink: "ffb6c1";
218 lightsalmon: "ffa07a";
219 lightseagreen: "20b2aa";
220 lightskyblue: "87cefa";
221 lightslategray: "789";
222 lightslategrey: "789";
223 lightsteelblue: "b0c4de";
224 lightyellow: "ffffe0";
225 lime: "0f0";
226 limegreen: "32cd32";
227 linen: "faf0e6";
228 magenta: "f0f";
229 maroon: "800000";
230 mediumaquamarine: "66cdaa";
231 mediumblue: "0000cd";
232 mediumorchid: "ba55d3";
233 mediumpurple: "9370db";
234 mediumseagreen: "3cb371";
235 mediumslateblue: "7b68ee";
236 mediumspringgreen: "00fa9a";
237 mediumturquoise: "48d1cc";
238 mediumvioletred: "c71585";
239 midnightblue: "191970";
240 mintcream: "f5fffa";
241 mistyrose: "ffe4e1";
242 moccasin: "ffe4b5";
243 navajowhite: "ffdead";
244 navy: "000080";
245 oldlace: "fdf5e6";
246 olive: "808000";
247 olivedrab: "6b8e23";
248 orange: "ffa500";
249 orangered: "ff4500";
250 orchid: "da70d6";
251 palegoldenrod: "eee8aa";
252 palegreen: "98fb98";
253 paleturquoise: "afeeee";
254 palevioletred: "db7093";
255 papayawhip: "ffefd5";
256 peachpuff: "ffdab9";
257 peru: "cd853f";
258 pink: "ffc0cb";
259 plum: "dda0dd";
260 powderblue: "b0e0e6";
261 purple: "800080";
262 rebeccapurple: "663399";
263 red: "f00";
264 rosybrown: "bc8f8f";
265 royalblue: "4169e1";
266 saddlebrown: "8b4513";
267 salmon: "fa8072";
268 sandybrown: "f4a460";
269 seagreen: "2e8b57";
270 seashell: "fff5ee";
271 sienna: "a0522d";
272 silver: "c0c0c0";
273 skyblue: "87ceeb";
274 slateblue: "6a5acd";
275 slategray: "708090";
276 slategrey: "708090";
277 snow: "fffafa";
278 springgreen: "00ff7f";
279 steelblue: "4682b4";
280 tan: "d2b48c";
281 teal: "008080";
282 thistle: "d8bfd8";
283 tomato: "ff6347";
284 turquoise: "40e0d0";
285 violet: "ee82ee";
286 wheat: "f5deb3";
287 white: "fff";
288 whitesmoke: "f5f5f5";
289 yellow: "ff0";
290 yellowgreen: "9acd32";
291 };
292
293 /**
294 * key: hex value
295 * value: string name ex. hexnames["f00"] --> "red"
296 */
297 hexNames: {
298 "f0f8ff": "aliceblue";
299 "faebd7": "antiquewhite";
300 "0ff": "aqua" | "cyan";
301 "7fffd4": "aquamarine";
302 "f0ffff": "azure";
303 "f5f5dc": "beige";
304 "ffe4c4": "bisque";
305 "000": "black";
306 "ffebcd": "blanchedalmond";
307 "00f": "blue";
308 "8a2be2": "blueviolet";
309 "a52a2a": "brown";
310 "deb887": "burlywood";
311 "ea7e5d": "burntsienna";
312 "5f9ea0": "cadetblue";
313 "7fff00": "chartreuse";
314 "d2691e": "chocolate";
315 "ff7f50": "coral";
316 "6495ed": "cornflowerblue";
317 "fff8dc": "cornsilk";
318 "dc143c": "crimson";
319 "00008b": "darkblue";
320 "008b8b": "darkcyan";
321 "b8860b": "darkgoldenrod";
322 "a9a9a9": "darkgray" | "darkgrey";
323 "006400": "darkgreen";
324 "bdb76b": "darkkhaki";
325 "8b008b": "darkmagenta";
326 "556b2f": "darkolivegreen";
327 "ff8c00": "darkorange";
328 "9932cc": "darkorchid";
329 "8b0000": "darkred";
330 "e9967a": "darksalmon";
331 "8fbc8f": "darkseagreen";
332 "483d8b": "darkslateblue";
333 "2f4f4f": "darkslategray" | "darkslategrey";
334 "00ced1": "darkturquoise";
335 "9400d3": "darkviolet";
336 "ff1493": "deeppink";
337 "00bfff": "deepskyblue";
338 "696969": "dimgray" | "dimgrey";
339 "1e90ff": "dodgerblue";
340 "b22222": "firebrick";
341 "fffaf0": "floralwhite";
342 "228b22": "forestgreen";
343 "f0f": "fuchsia" | "magenta";
344 "dcdcdc": "gainsboro";
345 "f8f8ff": "ghostwhite";
346 "ffd700": "gold";
347 "daa520": "goldenrod";
348 "808080": "gray" | "grey";
349 "008000": "green";
350 "adff2f": "greenyellow";
351 "f0fff0": "honeydew";
352 "ff69b4": "hotpink";
353 "cd5c5c": "indianred";
354 "4b0082": "indigo";
355 "fffff0": "ivory";
356 "f0e68c": "khaki";
357 "e6e6fa": "lavender";
358 "fff0f5": "lavenderblush";
359 "7cfc00": "lawngreen";
360 "fffacd": "lemonchiffon";
361 "add8e6": "lightblue";
362 "f08080": "lightcoral";
363 "e0ffff": "lightcyan";
364 "fafad2": "lightgoldenrodyellow";
365 "d3d3d3": "lightgray" | "lightgrey";
366 "90ee90": "lightgreen";
367 "ffb6c1": "lightpink";
368 "ffa07a": "lightsalmon";
369 "20b2aa": "lightseagreen";
370 "87cefa": "lightskyblue";
371 "789": "lightslategray" | "lightslategrey";
372 "b0c4de": "lightsteelblue";
373 "ffffe0": "lightyellow";
374 "0f0": "lime";
375 "32cd32": "limegreen";
376 "faf0e6": "linen";
377 "800000": "maroon";
378 "66cdaa": "mediumaquamarine";
379 "0000cd": "mediumblue";
380 "ba55d3": "mediumorchid";
381 "9370db": "mediumpurple";
382 "3cb371": "mediumseagreen";
383 "7b68ee": "mediumslateblue";
384 "00fa9a": "mediumspringgreen";
385 "48d1cc": "mediumturquoise";
386 "c71585": "mediumvioletred";
387 "191970": "midnightblue";
388 "f5fffa": "mintcream";
389 "ffe4e1": "mistyrose";
390 "ffe4b5": "moccasin";
391 "ffdead": "navajowhite";
392 "000080": "navy";
393 "fdf5e6": "oldlace";
394 "808000": "olive";
395 "6b8e23": "olivedrab";
396 "ffa500": "orange";
397 "ff4500": "orangered";
398 "da70d6": "orchid";
399 "eee8aa": "palegoldenrod";
400 "98fb98": "palegreen";
401 "afeeee": "paleturquoise";
402 "db7093": "palevioletred";
403 "ffefd5": "papayawhip";
404 "ffdab9": "peachpuff";
405 "cd853f": "peru";
406 "ffc0cb": "pink";
407 "dda0dd": "plum";
408 "b0e0e6": "powderblue";
409 "800080": "purple";
410 "663399": "rebeccapurple";
411 "f00": "red";
412 "bc8f8f": "rosybrown";
413 "4169e1": "royalblue";
414 "8b4513": "saddlebrown";
415 "fa8072": "salmon";
416 "f4a460": "sandybrown";
417 "2e8b57": "seagreen";
418 "fff5ee": "seashell";
419 "a0522d": "sienna";
420 "c0c0c0": "silver";
421 "87ceeb": "skyblue";
422 "6a5acd": "slateblue";
423 "708090": "slategray" | "slategrey";
424 "fffafa": "snow";
425 "00ff7f": "springgreen";
426 "4682b4": "steelblue";
427 "d2b48c": "tan";
428 "008080": "teal";
429 "d8bfd8": "thistle";
430 "ff6347": "tomato";
431 "40e0d0": "turquoise";
432 "ee82ee": "violet";
433 "f5deb3": "wheat";
434 "fff": "white";
435 "f5f5f5": "whitesmoke";
436 "ff0": "yellow";
437 "9acd32": "yellowgreen";
438 };
439 }
440
441 interface Instance {
442 /**
443 * Return an indication whether the color's perceived brightness is dark.
444 */
445 isDark(): boolean;
446
447 /**
448 * Return an indication whether the color's perceived brightness is light.
449 */
450 isLight(): boolean;
451
452 /**
453 * Return an indication whether the color was successfully parsed.
454 */
455 isValid(): boolean;
456
457 /**
458 * Returns the input passed into the constructer used to create the tinycolor instance.
459 */
460 getOriginalInput(): ColorInput;
461
462 /**
463 * Returns the format used to create the tinycolor instance.
464 */
465 getFormat(): string;
466
467 /**
468 * Returns the alpha value of the color
469 */
470 getAlpha(): number;
471
472 /**
473 * Returns the perceived brightness of the color, from 0-255.
474 */
475 getBrightness(): number;
476
477 /**
478 * Returns the perceived luminance of a color, from 0-1.
479 */
480 getLuminance(): number;
481
482 /**
483 * Sets the alpha value on the current color.
484 *
485 * @param alpha - The new alpha value. The accepted range is 0-1.
486 */
487 setAlpha(alpha: number): Instance;
488
489 /**
490 * Returns the object as a HSVA object.
491 */
492 toHsv(): ColorFormats.HSVA;
493
494 /**
495 * Returns the hsva values interpolated into a string with the following format:
496 * "hsva(xxx, xxx, xxx, xx)".
497 */
498 toHsvString(): string;
499
500 /**
501 * Returns the object as a HSLA object.
502 */
503 toHsl(): ColorFormats.HSLA;
504
505 /**
506 * Returns the hsla values interpolated into a string with the following format:
507 * "hsla(xxx, xxx, xxx, xx)".
508 */
509 toHslString(): string;
510
511 /**
512 * Returns the hex value of the color.
513 */
514 toHex(): string;
515
516 /**
517 * Returns the hex value of the color -with a # appened.
518 */
519 toHexString(): string;
520
521 /**
522 * Returns the hex 8 value of the color.
523 */
524 toHex8(): string;
525
526 /**
527 * Returns the hex 8 value of the color -with a # appened.
528 */
529 toHex8String(): string;
530
531 /**
532 * Returns the object as a RGBA object.
533 */
534 toRgb(): ColorFormats.RGBA;
535
536 /**
537 * Returns the RGBA values interpolated into a string with the following format:
538 * "RGBA(xxx, xxx, xxx, xx)".
539 */
540 toRgbString(): string;
541
542 /**
543 * Returns the object as a RGBA object.
544 */
545 toPercentageRgb(): ColorFormats.PRGBA;
546
547 /**
548 * Returns the RGBA relative values interpolated into a string with the following format:
549 * "RGBA(xxx, xxx, xxx, xx)".
550 */
551 toPercentageRgbString(): string;
552
553 /**
554 * The 'real' name of the color -if there is one.
555 */
556 toName(): string | false;
557
558 /**
559 * Returns the color represented as a Microsoft filter for use in old versions of IE.
560 */
561 toFilter(): string;
562
563 /**
564 * String representation of the color.
565 *
566 * @param format - The format to be used when displaying the string representation.
567 * The accepted values are: "rgb", "prgb", "hex6", "hex3", "hex8", "name", "hsl", "hsv".
568 */
569 toString(format?: "rgb" | "prgb" | "hex" | "hex6" | "hex3" | "hex4" | "hex8" | "name" | "hsl" | "hsv"): string;
570
571 /**
572 * Gets a new instance with the current color
573 */
574 clone(): Instance;
575
576 /**
577 * Lighten the color a given amount. Providing 100 will always return white.
578 *
579 * @param amount - The amount to lighten by. The valid range is 0 to 100.
580 * Default value: 10.
581 */
582 lighten(amount?: number): Instance;
583
584 /**
585 * Brighten the color a given amount.
586 *
587 * @param amount - The amount to brighten by. The valid range is 0 to 100.
588 * Default value: 10.
589 */
590 brighten(amount?: number): Instance;
591
592 /**
593 * Darken the color a given amount.
594 * Providing 100 will always return black.
595 *
596 * @param amount - The amount to darken by. The valid range is 0 to 100.
597 * Default value: 10.
598 */
599 darken(amount?: number): Instance;
600 /**
601 * Desaturate the color a given amount.
602 * Providing 100 will is the same as calling greyscale.
603 *
604 * @param amount - The amount to desaturate by. The valid range is 0 to 100.
605 * Default value: 10.
606 */
607 desaturate(amount?: number): Instance;
608
609 /**
610 * Saturate the color a given amount.
611 *
612 * @param amount - The amount to saturate by. The valid range is 0 to 100.
613 * Default value: 10.
614 */
615 saturate(amount?: number): Instance;
616
617 /**
618 * Completely desaturates a color into greyscale.
619 * Same as calling desaturate(100).
620 */
621 greyscale(): Instance;
622
623 /**
624 * Spin the hue a given amount. Calling with 0, 360, or -360 will do nothing.
625 *
626 * @param amount - The amount to spin by. The valid range is -360 to 360.
627 */
628 spin(amount: number): Instance;
629
630 /**
631 * Gets an analogous color scheme based off of the current color.
632 *
633 * @param results - The amount of results to return.
634 * Default value: 6.
635 * @param slices - The amount to slice the input color by.
636 * Default value: 30.
637 */
638 analogous(results?: number, slices?: number): Instance[];
639
640 /**
641 * Gets the complement of the current color
642 */
643 complement(): Instance;
644
645 /**
646 * Gets a monochromatic color scheme based off of the current color.
647 *
648 * @param results - The amount of results to return.
649 * Default value: 6.
650 */
651 monochromatic(results?: number): Instance[];
652
653 /**
654 * Gets a split complement color scheme based off of the current color.
655 */
656 splitcomplement(): [Instance, Instance, Instance];
657
658 /**
659 * Gets a triad based off of the current color.
660 */
661 triad(): [Instance, Instance, Instance];
662
663 /**
664 * Gets a tetrad based off of the current color.
665 */
666 tetrad(): [Instance, Instance, Instance, Instance];
667 }
668}
669
670declare const tinycolor: tinycolor.Constructor;
671export = tinycolor;
672export as namespace tinycolor;