UNPKG

35.2 kBTypeScriptView Raw
1/**
2 * Chroma.js is a tiny library for all kinds of color conversions and color scales.
3 */
4declare namespace chroma {
5 type W3CX11ColorName =
6 | "aliceblue"
7 | "antiquewhite"
8 | "aqua"
9 | "aquamarine"
10 | "azure"
11 | "beige"
12 | "bisque"
13 | "black"
14 | "blanchedalmond"
15 | "blue"
16 | "blueviolet"
17 | "brown"
18 | "burlywood"
19 | "cadetblue"
20 | "chartreuse"
21 | "chocolate"
22 | "coral"
23 | "cornflowerblue"
24 | "cornsilk"
25 | "crimson"
26 | "cyan"
27 | "darkblue"
28 | "darkcyan"
29 | "darkgoldenrod"
30 | "darkgray"
31 | "darkgreen"
32 | "darkgrey"
33 | "darkkhaki"
34 | "darkmagenta"
35 | "darkolivegreen"
36 | "darkorange"
37 | "darkorchid"
38 | "darkred"
39 | "darksalmon"
40 | "darkseagreen"
41 | "darkslateblue"
42 | "darkslategray"
43 | "darkslategrey"
44 | "darkturquoise"
45 | "darkviolet"
46 | "deeppink"
47 | "deepskyblue"
48 | "dimgray"
49 | "dimgrey"
50 | "dodgerblue"
51 | "firebrick"
52 | "floralwhite"
53 | "forestgreen"
54 | "fuchsia"
55 | "gainsboro"
56 | "ghostwhite"
57 | "gold"
58 | "goldenrod"
59 | "gray"
60 | "green"
61 | "greenyellow"
62 | "grey"
63 | "honeydew"
64 | "hotpink"
65 | "indianred"
66 | "indigo"
67 | "ivory"
68 | "khaki"
69 | "laserlemon"
70 | "lavender"
71 | "lavenderblush"
72 | "lawngreen"
73 | "lemonchiffon"
74 | "lightblue"
75 | "lightcoral"
76 | "lightcyan"
77 | "lightgoldenrod"
78 | "lightgoldenrodyellow"
79 | "lightgray"
80 | "lightgreen"
81 | "lightgrey"
82 | "lightpink"
83 | "lightsalmon"
84 | "lightseagreen"
85 | "lightskyblue"
86 | "lightslategray"
87 | "lightslategrey"
88 | "lightsteelblue"
89 | "lightyellow"
90 | "lime"
91 | "limegreen"
92 | "linen"
93 | "magenta"
94 | "maroon"
95 | "maroon2"
96 | "maroon3"
97 | "mediumaquamarine"
98 | "mediumblue"
99 | "mediumorchid"
100 | "mediumpurple"
101 | "mediumseagreen"
102 | "mediumslateblue"
103 | "mediumspringgreen"
104 | "mediumturquoise"
105 | "mediumvioletred"
106 | "midnightblue"
107 | "mintcream"
108 | "mistyrose"
109 | "moccasin"
110 | "navajowhite"
111 | "navy"
112 | "oldlace"
113 | "olive"
114 | "olivedrab"
115 | "orange"
116 | "orangered"
117 | "orchid"
118 | "palegoldenrod"
119 | "palegreen"
120 | "paleturquoise"
121 | "palevioletred"
122 | "papayawhip"
123 | "peachpuff"
124 | "peru"
125 | "pink"
126 | "plum"
127 | "powderblue"
128 | "purple"
129 | "purple2"
130 | "purple3"
131 | "rebeccapurple"
132 | "red"
133 | "rosybrown"
134 | "royalblue"
135 | "saddlebrown"
136 | "salmon"
137 | "sandybrown"
138 | "seagreen"
139 | "seashell"
140 | "sienna"
141 | "silver"
142 | "skyblue"
143 | "slateblue"
144 | "slategray"
145 | "slategrey"
146 | "snow"
147 | "springgreen"
148 | "steelblue"
149 | "tan"
150 | "teal"
151 | "thistle"
152 | "tomato"
153 | "turquoise"
154 | "violet"
155 | "wheat"
156 | "white"
157 | "whitesmoke"
158 | "yellow"
159 | "yellowgreen";
160
161 type BrewerPaletteName =
162 | "OrRd"
163 | "PuBu"
164 | "BuPu"
165 | "Oranges"
166 | "BuGn"
167 | "YlOrBr"
168 | "YlGn"
169 | "Reds"
170 | "RdPu"
171 | "Greens"
172 | "YlGnBu"
173 | "Purples"
174 | "GnBu"
175 | "Greys"
176 | "YlOrRd"
177 | "PuRd"
178 | "Blues"
179 | "PuBuGn"
180 | "Viridis"
181 | "Spectral"
182 | "RdYlGn"
183 | "RdBu"
184 | "PiYG"
185 | "PRGn"
186 | "RdYlBu"
187 | "BrBG"
188 | "RdGy"
189 | "PuOr"
190 | "Set2"
191 | "Accent"
192 | "Set1"
193 | "Set3"
194 | "Dark2"
195 | "Paired"
196 | "Pastel2"
197 | "Pastel1";
198
199 // eslint-disable-next-line @typescript-eslint/no-empty-interface
200 interface Nothing {} // used to auto-complete W3CX11ColorNames
201 type AnyOther<T> = T & Nothing;
202
203 type ChromaInput = W3CX11ColorName | AnyOther<string> | number | { [key: string]: number } | Color;
204
205 interface ColorFormats {
206 cmyk: [number, number, number, number];
207 gl: [number, number, number, number];
208 hcg: [number, number, number];
209 hcl: [number, number, number];
210 hsi: [number, number, number];
211 hsl: [number, number, number];
212 hsv: [number, number, number];
213 lab: [number, number, number];
214 lch: [number, number, number];
215 oklab: [number, number, number];
216 oklch: [number, number, number];
217 rgb: [number, number, number];
218 }
219
220 type ColorFormat = keyof ColorFormats;
221
222 type InterpolationMode = "hcl" | "hsi" | "hsl" | "hsv" | "lab" | "lch" | "lrgb" | "oklab" | "oklch" | "rgb";
223
224 type WhitePoint = "D50" | "D55" | "D65" | "A" | "B" | "C" | "F2" | "F7" | "F11" | "E";
225
226 interface ChromaStatic {
227 /**
228 * Attempts to guess the format of the input color for you.
229 * For instance, it will recognize any named color from the W3CX11 specification.
230 * If there's no matching named color, chroma.js checks for a hexadecimal string.
231 * It ignores case, the # sign is optional, and it can recognize the shorter three
232 * letter format as well. So, any of these are valid hexadecimal representations:
233 *
234 * #ff3399, FF3399, #f39, etc.
235 *
236 * In addition to hex strings, hexadecimal numbers (in fact, just any number between 0 and 16777215)
237 * will be recognized, too.
238 */
239 (color: ChromaInput): Color;
240
241 /**
242 * Create a color in the specified color format using a, b and c as values.
243 * The color format defaults to "rgb".
244 */
245 (a: number, b: number, c: number, format?: ColorFormat): Color;
246
247 /**
248 * Create a color in the specified color format using a, b, c, and d as values.
249 * The color format defaults to "rgb".
250 */
251 (a: number, b: number, c: number, d: number, format?: ColorFormat): Color;
252
253 /**
254 * Create a color from an array of RGB values. Each parameter must be within 0..255.
255 */
256 (rgbArray: [number, number, number]): Color;
257
258 /**
259 * Create a color from an object with attributes corresponding to a color format.
260 */
261 (colorObject: { [key: string]: number }): Color;
262
263 /**
264 * Test if a color argument can be correctly parsed as color by chroma.js
265 *
266 * @example
267 * ```typescript
268 * chroma.valid('red') // true
269 * chroma.valid('bread') // false
270 * chroma.valid('#F0000D') // true
271 * chroma.valid('#FOOOOD') // false
272 * ```
273 */
274 valid(color: any): boolean;
275
276 hsl(hue: number, saturation: number, lightness: number, alpha?: number): Color;
277
278 hsv(hue: number, saturation: number, value: number, alpha?: number): Color;
279
280 /**
281 * CIE Lab color space. To calculate the lightness value of a color, the CIE Lab color space uses
282 * a reference white point. This reference white point defines what is considered to be "white" in
283 * the color space. By default chroma.js is using the D65 reference point.
284 */
285 lab(lightness: number, a: number, b: number, alpha?: number): Color;
286
287 /**
288 * Sets the current CIE Lab white reference point.
289 * Possible values:
290 * - D50: Represents the color temperature of daylight at 5000K.
291 * - D55: Represents mid-morning or mid-afternoon daylight at 5500K.
292 * - D65: Represents average daylight at 6500K.
293 * - A: Represents the color temperature of a typical incandescent light bulb at approximately 2856K.
294 * - B: Represents noon daylight with a color temperature of approximately 4874K.
295 * - C: Represents average or north sky daylight; it's a theoretical construct, not often used in practical applications.
296 * - F2: Represents cool white fluorescent light.
297 * - F7: This is a broad-band fluorescent light source with a color temperature of approximately 6500K.
298 * - F11: This is a narrow tri-band fluorescent light source with a color temperature of approximately 4000K.
299 * - E: Represents an equal energy white point, where all wavelengths in the visible spectrum are equally represented.
300 *
301 * @example
302 * ```typescript
303 * chroma('hotpink').lab() // [65.49,64.24,-10.65]
304 * chroma.setLabWhitePoint('F2')
305 * chroma('hotpink').lab() // [66.28,61.45,-8.62]
306 * ```
307 */
308 setLabWhitePoint: (whitePoint: WhitePoint) => void;
309
310 /**
311 * Returns the name of the currently set CIE Lab white reference point.
312 *
313 * @example
314 * ```typescript
315 * chroma.getLabWhitePoint() // "D65"
316 * ```
317 */
318 getLabWhitePoint: () => WhitePoint;
319
320 /**
321 * The range for lightness and chroma depend on the hue, but go roughly from 0..100-150.
322 * The range for hue is 0..360.
323 */
324 lch(lightness: number, chroma: number, hue: number, alpha?: number): Color;
325
326 /**
327 * You can use hcl instead of lch. Lightness and hue channels are switched to be more consistent with HSL.
328 */
329 hcl(hue: number, chroma: number, lightness: number, alpha?: number): Color;
330
331 /**
332 * {@link https://bottosson.github.io/posts/oklab|Oklab color space}
333 */
334 oklab(lightness: number, a: number, b: number, alpha?: number): Color;
335
336 oklch(lightness: number, chromaticity: number, hue: number, alpha?: number): Color;
337
338 /**
339 * Each between 0 and 1.
340 */
341 cmyk(cyan: number, magenta: number, yellow: number, black: number): Color;
342
343 rgb(red: number, green: number, blue: number, alpha?: number): Color;
344
345 /**
346 * GL is a variant of RGB(A), with the only difference that the components are normalized to the range of 0..1.
347 */
348 gl(red: number, green: number, blue: number, alpha?: number): Color;
349
350 /**
351 * Returns a color from the {@link https://en.wikipedia.org/wiki/Color_temperature#Categorizing_different_lighting|color temperature} scale.
352 * light 2000K, bright sunlight 6000K. Based on
353 * {@link https://github.com/neilbartlett/color-temperature|Neil Bartlett's implementation}.
354 * The effective temperature range goes from 0 to about 30000 Kelvin
355 *
356 * @example
357 * ```typescript
358 * chroma.temperature(2000) // #ff8b14 candle light
359 * chroma.temperature(3500) // #ffc38a sunset
360 * chroma.temperature(6500) // #fffafe daylight
361 * ```
362 */
363 temperature(K: number): Color;
364
365 /**
366 * Mixes two colors. The mix ratio is a value between 0 and 1.
367 * The color mixing produces different results based the mode used for interpolation. Defaults to lrgb.
368 * @example
369 * ```typescript
370 * chroma.mix([0,0,0], 'blue') // #0000b4
371 * chroma.mix('red', 'blue', 0.25) // #dd0080
372 * chroma.mix('red', 'blue', 0.75) // #8000dd
373 * chroma.mix('red', 'blue', 0.5, 'rgb') // #800080
374 * chroma.mix('red', 'blue', 0.5, 'hsl') // #ff00ff
375 * chroma.mix('red', 'blue', 0.5, 'lab') // #ca0088
376 * chroma.mix('red', 'blue', 0.5, 'lch') // #fa0080
377 * chroma.mix('red', 'blue', 0.5, 'lrgb') // #b400b4
378 * ```
379 */
380 mix(color1: ChromaInput, color2: ChromaInput, ratio?: number, mode?: InterpolationMode): Color;
381
382 /**
383 * Similar to {@link mix}, but accepts more than two colors. Simple averaging of R,G,B components and the alpha
384 * channel. mode defaults to 'lrgb'. You can also provide an array of weights to compute a weighted average of colors.
385 *
386 * @example
387 * ```typescript
388 * colors = ['#ddd', 'yellow', 'red', 'teal']
389 * chroma.average(colors) // #d3b480
390 * chroma.average(colors, 'rgb') // #b79757
391 * chroma.average(colors, 'lab') // #d3a96a
392 * chroma.average(colors, 'lch') // #ef9e4e
393 * chroma.average(colors, 'lch', [1,1,2,1]) // #f98841
394 * chroma.average(colors, 'lch', [1.5,0.5,1,2.3]) // #ae9e52
395 * ```
396 */
397 average(colors: ChromaInput[], mode?: InterpolationMode, weights?: number[]): Color;
398
399 /**
400 * Blends two colors using RGB channel-wise blend functions.
401 *
402 * @example
403 * ```typescript
404 * chroma.blend('4CBBFC', 'EEEE22', 'multiply') // #47af22
405 * chroma.blend('4CBBFC', 'EEEE22', 'darken') // #4cbb22
406 * chroma.blend('4CBBFC', 'EEEE22', 'lighten') // #eeeefc
407 * ```
408 */
409 blend(
410 color1: ChromaInput,
411 color2: ChromaInput,
412 blendMode: "multiply" | "darken" | "lighten" | "screen" | "overlay" | "burn" | "dodge",
413 ): Color;
414
415 /**
416 * Creates a random color by generating a random hexadecimal string.
417 */
418 random(): Color;
419
420 /**
421 * Computes the WCAG contrast ratio between two colors.
422 * A minimum contrast of 4.5:1 is recommended {@link https://www.w3.org/TR/WCAG20-TECHS/G18.html}
423 * to ensure that text is still readable against a background color.
424 *
425 * @example
426 * ```typescript
427 * chroma.contrast('pink', 'hotpink') // 1.721
428 * chroma.contrast('pink', 'purple') // 6.124
429 * ````
430 */
431 contrast(color1: ChromaInput, color2: ChromaInput): number;
432
433 /**
434 * Computes the {@link https://www.myndex.com/APCA|APCA contrast ratio} of a text color against its background color.
435 * The basic idea is that you check the contrast between the text and background color
436 * and then use {@link https://raw.githubusercontent.com/Myndex/apca-w3/master/images/APCAlookupByContrast.jpeg|this lookup table} to find the minimum font size you're allowed to use
437 * (given the font weight and purpose of the text).
438 *
439 * Read more about how to interpret and use this metric at {@link https://readtech.org/ARC|APCA Readability Criterion}.
440 * Please note that the APCA algorithm is still in beta and may change be subject to changes in the future.
441 *
442 * @example
443 * ```typescript
444 * chroma.contrastAPCA('hotpink', 'pink') // 23.746
445 * chroma.contrastAPCA('purple', 'pink') // 62.534
446 * ```
447 */
448 contrastAPCA(text: ChromaInput, background: ChromaInput): number;
449
450 /**
451 * Computes the eucledian distance between two colors in a given color format (default is 'lab').
452 * {@link https://en.wikipedia.org/wiki/Euclidean_distance#Three_dimensions}
453 *
454 * @example
455 * ```typescript
456 * chroma.distance('#fff', '#ff0', 'rgb') // 255
457 * chroma.distance('#fff', '#f0f', 'rgb') // 255
458 * chroma.distance('#fff', '#ff0') // 96.948
459 * chroma.distance('#fff', '#f0f') // 122.163
460 * ```
461 */
462 distance(color1: ChromaInput, color2: ChromaInput, format?: ColorFormat): number;
463
464 /**
465 * Computes {@link https://en.wikipedia.org/wiki/Color_difference#CIEDE2000|color difference} as developed by the
466 * International Commission on Illumination (CIE) in 2000. The implementation is based on the formula from
467 * {@link http://www.brucelindbloom.com/index.html?Eqn_DeltaE_CIE2000.html|Bruce Lindbloom}.
468 * Resulting values range from 0 (no difference) to 100 (maximum difference), and are a metric for how the
469 * human eye percieves color difference. The optional parameters Kl, Kc, and Kh may be used to adjust weightings of
470 * lightness, chroma, and hue.
471 *
472 * @example
473 * ```typescript
474 * chroma.deltaE('#ededee', '#ededee') // 0
475 * chroma.deltaE('#ededee', '#edeeed') // 1.321
476 * chroma.deltaE('#ececee', '#eceeec') // 2.602
477 * chroma.deltaE('#e9e9ee', '#e9eee9') // 6.221
478 * chroma.deltaE('#e4e4ee', '#e4eee4') // 11.598
479 * chroma.deltaE('#e0e0ee', '#e0eee0') // 15.391
480 * chroma.deltaE('#000000', '#ffffff') // 100
481 * ```
482 */
483 deltaE(color1: ChromaInput, color2: ChromaInput, Kl?: number, Kc?: number, Kh?: number): number;
484
485 /**
486 * chroma.brewer is an map of {@link http://colorbrewer2.org/|ColorBrewer palettes} that are included
487 * in chroma.js for convenience. Chroma.scale uses the colors to construct. Note that chroma.js only
488 * includes the 9-step versions of the palettes (11 steps for the diverging palettes). So, for instance,
489 * if you use chroma.js to construct a 5-color palette, they will be different from the "official"
490 * 5-color palettes in ColorBrewer (which have lower contrast).
491 */
492 brewer: Record<BrewerPaletteName, string[]>;
493
494 /**
495 * A helper function that computes class breaks for you, based on data.
496 * It supports the modes:
497 * - e: equidistant
498 * - breaks are computed by dividing the total range of the data into _n_ groups of equal size.
499 * - q: quantile
500 * - the input domain is divided by quantile ranges.
501 * - l: logarithmic
502 * - breaks are equidistant breaks but on a logarithmic scale.
503 * - k: k-means
504 * - break is using the 1-dimensional {@link https://en.wikipedia.org/wiki/K-means_clustering|k-means clustering algorithm} to find (roughly) _n_ groups of "similar" values.
505 * Note that this k-means implementation does not guarantee to find exactly _n_ groups.
506 *
507 * @example
508 * ```typescript
509 * const data = [2.0,3.5,3.6,3.8,3.8,4.1,4.3,4.4,4.6,4.9,5.2,5.3,5.4,5.7,5.8,5.9, 6.2,6.5,6.8,7.2,8]
510 * chroma.limits(data, 'e', 4) // [2,3.5,5,6.5,8]
511 * chroma.limits(data, 'q', 4) // [2,4.1,5.2,5.9,8]
512 * chroma.limits(data, 'l', 4) // [2,2.83,4,5.66,8]
513 * chroma.limits(data, 'k', 4) // [2,8]
514 * ```
515 */
516 limits(data: number[], mode: "e" | "q" | "l" | "k", n: number): number[];
517
518 /**
519 * A color scale, created with chroma.scale, is a function that maps numeric values to a color palette.
520 * The default scale has the domain 0..1 and goes from white to black.
521 * You can pass an array of colors to chroma.scale. Any color that can be read by chroma()
522 * will work here, too. If you pass more than two colors, they will be evenly distributed along the gradient.
523 */
524 scale(colors?: BrewerPaletteName | ChromaInput[]): Scale;
525
526 /**
527 * Returns a function that [bezier-interpolates]{@link https://www.vis4.net/blog/posts/mastering-multi-hued-color-scales/}
528 * between colors in Lab space. The input range of the function is [0..1].
529 * You can convert a bezier interpolator into a chroma.scale instance.
530 */
531 bezier(colors: string[]): { (t: number): Color; scale(): Scale };
532
533 cubehelix(): Cubehelix;
534 }
535
536 interface Color {
537 /**
538 * Get and set the color opacity.
539 *
540 * @example
541 * ```typescript
542 * chroma('red').alpha(0.5) // #ff000080
543 * chroma('rgba(255,0,0,0.35)').alpha() // 0.35
544 * ```
545 */
546 alpha(): number;
547 alpha(a: number): Color;
548
549 /**
550 * Decreases the lightness of the color. value defaults to 1.
551 *
552 * @example
553 * ```typescript
554 * chroma('hotpink').darken() // #c93384
555 * chroma('hotpink').darken(2) // #930058
556 * chroma('hotpink').darken(2.6) // #74003f
557 * ```
558 */
559 darken(value?: number): Color;
560
561 /**
562 * Increases the lightness of the color. value defaults to 1.
563 *
564 * @example
565 * ```typescript
566 * chroma('hotpink').brighten() // #ff9ce6
567 * chroma('hotpink').brighten(2) // #ffd1ff
568 * chroma('hotpink').brighten(3) // #ffffff
569 * ```
570 */
571 brighten(value?: number): Color;
572
573 /**
574 * Changes the saturation of a color by manipulating the Lch chromacity.
575 *
576 * @example
577 * ```typescript
578 * chroma('slategray').saturate() // #4b83ae
579 * chroma('slategray').saturate(2) // #0087cd
580 * chroma('slategray').saturate(3) // #008bec
581 * ```
582 */
583 saturate(value?: number): Color;
584
585 /**
586 * Similar to saturate, but the opposite direction.
587 *
588 * @example
589 * ```typescript
590 * chroma('hotpink').desaturate() // #e77dae
591 * chroma('hotpink').desaturate(2) // #cd8ca8
592 * chroma('hotpink').desaturate(3) // #b199a3
593 * ```
594 */
595 desaturate(value?: number): Color;
596
597 /**
598 * Mix this color with a target color. The mix ratio is a value between 0 and 1.
599 * This is the same as chroma.mix but with the first parameter already set.
600 * As such, the color format used can be adjusted.
601 *
602 * @example
603 * ```typescript
604 * chroma('hotpink').mix('blue') // #b44add
605 * chroma('hotpink').mix('blue', 0.25) // #dd5bc9
606 * chroma('hotpink').mix('blue', 0.75, 'lab') // #811ced
607 * ```
608 */
609 mix(targetColor: ChromaInput, ratio?: number, format?: ColorFormat): Color;
610
611 /**
612 * Produce a shade of the color. This is syntactic sugar for color.mix with a target color of black.
613 *
614 * @example
615 * ```typescript
616 * chroma('hotpink').shade(0.25) // #dd5b9c
617 * chroma('hotpink').shade(0.5) // #b44a7f
618 * chroma('hotpink').shade(0.75) // #80355a
619 * ```
620 */
621 shade: (ratio?: number, mode?: InterpolationMode) => Color;
622
623 /**
624 * Produce a tint of the color. This is syntactic sugar for color.mix with a target color of white.
625 *
626 * @example
627 * ```typescript
628 * chroma('hotpink').tint(0.25) // #ff9dc9
629 * chroma('hotpink').tint(0.5) // #ffc3dd
630 * chroma('hotpink').tint(0.75) // #ffe3ee
631 * ```
632 */
633 tint: (ratio?: number, mode?: InterpolationMode) => Color;
634
635 /**
636 * Changes a single channel and returns the result a new chroma object.
637 * Also works with relative changes
638 *
639 * @example
640 * ```typescript
641 * chroma('skyblue').set('hsl.h', 0) // #eb8787
642 * chroma('hotpink').set('lch.c', 30) // #ce8ca9
643 * chroma('orangered').set('lab.l', '*0.5') // #a10000
644 * chroma('darkseagreen').set('lch.c', '*2') // #63c56c
645 */
646 set(channel: string, value: number | string): Color;
647
648 /**
649 * Returns a single channel value.
650 *
651 * @example
652 * ```typescript
653 * chroma('orangered').get('lab.l') // 57.582
654 * chroma('orangered').get('hsl.l') // 0.5
655 * chroma('orangered').get('rgb.g') // 69
656 * ```
657 */
658 get(channel: string): number;
659
660 /**
661 * Relative brightness, according to the
662 * [WCAG]{@link http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef} definition.
663 * Normalized to 0 for darkest black and 1 for lightest white.
664 */
665 luminance(): number;
666
667 /**
668 * Set luminance of color. The source color will be interpolated with black or white until
669 * the correct luminance is found. The color space used defaults to RGB.
670 */
671 luminance(value: number, mode?: InterpolationMode): Color;
672
673 /**
674 * Get color as hexadecimal string. the default mode is "auto" which means that the hex string
675 * will include the alpha channel if it's less than 1. If you don't want the alpha channel to be
676 * included you must explicitly set the mode to "rgb"
677 *
678 * @example
679 * ```typescript
680 * chroma('orange').hex() // #ffa500
681 * chroma('orange').alpha(0.5).hex() // #ffa50080
682 * chroma('orange').alpha(0.5).hex('rgb') // #ffa500
683 * chroma('orange').alpha(0.5).hex('argb') // #80ffa500
684 * ```
685 */
686 hex(mode?: "auto" | "rgb" | "rgba" | "argb"): string;
687
688 /**
689 * Returns the named color. Falls back to hexadecimal RGB string, if the color isn't present.
690 *
691 * @example
692 * ```typescript
693 * chroma('#ffa500').name() // orange
694 * chroma('#ffa505').name() // #ffa505
695 * ```
696 */
697 name(): string;
698
699 /**
700 * Returns a CSS string representation that can be used as CSS-color definition.
701 * mode defaults to rgb
702 *
703 * @example
704 * ```typescript
705 * chroma('teal').css() // rgb(0 128 128)
706 * chroma('teal').alpha(0.5).css() // rgb(0 128 128 / 0.5)
707 * chroma('teal').css('hsl') // hsl(180deg 100% 25.1%)
708 * chroma('teal').css('lab') // lab(47.99% -30.39 -8.98)
709 * chroma('teal').css('oklch') // oklch(54.31% 0.09 194.76deg)
710 * ```
711 */
712 css(mode?: "rgb" | "hsl" | "lab" | "lch" | "oklab" | "oklch"): string;
713
714 /**
715 * Returns an array with the red, green, and blue component, each as
716 * number within the range 0..255. Chroma internally stores RGB
717 * channels as floats but rounds the numbers before returning them.
718 * You can pass false to prevent the rounding.
719 *
720 * @example
721 * ```typescript
722 * chroma('orange').rgb() // [255,165,0]
723 * chroma('orange').darken().rgb() // [198,118,0]
724 * chroma('orange').darken().rgb(false) // [198.05,118.11,0]
725 * ```
726 */
727 rgb: (round?: boolean) => ColorFormats["rgb"];
728
729 /**
730 * Just like color.rgb but adds the alpha channel to the returned array.
731 *
732 * @example
733 * ```typescript
734 * chroma('orange').rgba() // [255,165,0,1]
735 * chroma('hsla(20, 100%, 40%, 0.5)').rgba() // [204,68,0,0.5]
736 * ```
737 */
738 rgba: (round?: boolean) => [number, number, number, number];
739
740 /**
741 * Returns an array with the `hue`, `saturation`, and `lightness`
742 * component. Hue is the color angle in degree (`0..360`), saturation
743 * and lightness are within `0..1`. Note that for hue-less colors
744 * (black, white, and grays), the hue component will be NaN.
745 *
746 * @example
747 * ```typescript
748 * chroma('orange').hsl() // [38.82,1,0.5,1]
749 * chroma('white').hsl() // [NaN,0,1,1]
750 * ```
751 */
752 hsl: () => ColorFormats["hsl"];
753
754 /**
755 * Returns an array with the `hue`, `saturation`, and `value`
756 * components. Hue is the color angle in degree (`0..360`),
757 * saturation and value are within `0..1`. Note that for hue-less
758 * colors (black, white, and grays), the hue component will be NaN.
759 *
760 * @example
761 * ```typescript
762 * chroma('orange').hsv() // [38.82,1,1]
763 * chroma('white').hsv() // [NaN,0,1]
764 * ```
765 */
766 hsv: () => ColorFormats["hsv"];
767
768 /**
769 * Returns an array with the `hue`, `saturation`, and `intensity`
770 * components, each as number between 0 and 255. Note that for hue-less
771 * colors (black, white, and grays), the hue component will be NaN.
772 *
773 * @example
774 * ```typescript
775 * chroma('orange').hsi() // [39.64,1,0.55]
776 * chroma('white').hsi() // [NaN,0,1]
777 * ```
778 */
779 hsi: () => ColorFormats["hsi"];
780
781 /**
782 * Returns an array with the **L**, **a**, and **b** components.
783 *
784 * @example
785 * ```typescript
786 * chroma('orange').lab() // [74.94,23.93,78.95]
787 * ```
788 */
789 lab: () => ColorFormats["lab"];
790
791 /**
792 * Returns an array with the **Lightness**, **chroma**, and **hue**
793 * components.
794 *
795 * @example
796 * ```typescript
797 * chroma('skyblue').lch() // [79.21,25.94,235.11]
798 * ```
799 */
800 lch: () => ColorFormats["lch"];
801
802 /**
803 * Alias of lch, but with the components in reverse order.
804 *
805 * @example
806 * ```typescript
807 * chroma('skyblue').hcl() // [235.11,25.94,79.21]
808 * ```
809 */
810 hcl: () => ColorFormats["hcl"];
811
812 /**
813 * Returns an array with the **L**, **a**, and **b** components.
814 * in the {@link https://bottosson.github.io/posts/oklab|OKLab} color space.
815 *
816 * @example
817 * ```typescript
818 * chroma('orange').oklab() // [0.79,0.06,0.16]
819 * ```
820 */
821 oklab: () => ColorFormats["oklab"];
822
823 /**
824 * Returns an array with the **Lightness**, **chroma**, and **hue** components
825 * in the {@link https://bottosson.github.io/posts/oklab|OKLch}
826 *
827 * @example
828 * ```typescript
829 * chroma('skyblue').oklch() // [0.81,0.08,225.74]
830 * ```
831 */
832 oklch: () => ColorFormats["oklch"];
833
834 /**
835 * Returns an array with the cyan, magenta, yellow, and key (black)
836 * components, each as a normalized value between 0 and 1.
837 *
838 * @example
839 * ```typescript
840 * chroma('orange').rgba() // [255,165,0,1]
841 * chroma('hsla(20, 100%, 40%, 0.5)').rgba() // [204,68,0,0.5]
842 * ```typescript
843 */
844 cmyk: () => ColorFormats["cmyk"];
845
846 /**
847 * Returns the numeric representation of the hexadecimal RGB color.
848 *
849 * @example
850 * ```typescript
851 * chroma('#000000').num() // 0
852 * chroma('#0000ff').num() // 255
853 * chroma('#00ff00').num() // 65280
854 * chroma('#ff0000').num() // 16711680
855 * ```
856 */
857 num(): number;
858
859 /**
860 * Estimate the temperature in Kelvin of any given color, though this makes
861 * only sense for colors from the {@link https://en.wikipedia.org/wiki/Color_temperature#Categorizing_different_lighting|temperature gradient}.
862 *
863 * @example
864 * ```typescript
865 * chroma('#ff3300').temperature() // 1000
866 * chroma('#ff8a13').temperature() // 2000
867 * chroma('#ffe3cd').temperature() // 4999
868 * chroma('#cbdbff').temperature() // 10115
869 * chroma('#b3ccff').temperature() // 15169
870 * ```
871 */
872 temperature(): number;
873
874 /**
875 * Like RGB, but in the channel range of `[0..1]` instead of `[0..255]`
876 *
877 * @example
878 * ```typescript
879 * chroma('#33cc00').gl() // [0.2,0.8,0,1]
880 * ```
881 */
882 gl: () => ColorFormats["gl"];
883
884 /**
885 * Test if a color has been clipped or not.
886 * Colors generated from CIELab color space may have their RGB
887 * channels clipped to the range of [0..255].
888 * Colors outside that range may exist in nature but are not
889 * displayable on RGB monitors (such as ultraviolet).
890 *
891 * @example
892 * ```typescript
893 * chroma.hcl(50, 40, 20).clipped() // true
894 * ```
895 */
896 clipped: () => boolean;
897
898 /**
899 * The unclipped RGB components.
900 *
901 * @example
902 * ```typescript
903 * chroma.hcl(50, 40, 100).rgb() // [255,235,197]
904 * chroma.hcl(50, 40, 100).clipped() // true
905 * chroma.hcl(50, 40, 100)._rgb._unclipped // [322.65,235.24,196.7,1]
906 * ```
907 */
908 _rgb: { _unclipped: [number, number, number, number] };
909 }
910
911 interface Scale<OutType = Color> {
912 (c: string[]): Scale;
913
914 (value: number | null | undefined): OutType;
915 domain(): number[];
916 domain(d?: number[], n?: number, mode?: string): this;
917
918 mode(mode: InterpolationMode): this;
919
920 gamma(g: number): this;
921
922 cache(use: boolean): boolean;
923
924 correctLightness(enable?: boolean): this;
925
926 padding(p: number | number[]): this;
927
928 /**
929 * You can call scale.colors(n) to quickly grab `c` equi-distant colors from a color scale. If called with no
930 * arguments, scale.colors returns the original array of colors used to create the scale.
931 */
932 colors(
933 c: number | undefined,
934 format: undefined | null | "alpha" | "darken" | "brighten" | "saturate" | "desaturate",
935 ): Color[];
936 colors(c: number | undefined, format: "luminance" | "temperature"): number[];
937 colors<K extends ColorFormat>(c: number | undefined, format: K): Array<ColorFormats[K]>;
938 colors(c: number | undefined, format?: "hex" | "name"): string[];
939
940 /**
941 * If you want the scale function to return a distinct set of colors instead of a continuous gradient, you can
942 * use scale.classes. If you pass a number the scale will broken into equi-distant classes.
943 * You can also define custom class breaks by passing them as array
944 */
945 classes(c: number | number[]): this;
946
947 /**
948 * Set out format for scale() call. Passing null will result in a scale which outputs colors.
949 */
950 out(format: null): Scale;
951 out<K extends ColorFormat>(format: K): Scale<ColorFormats[K]>;
952 out(format: "hex"): Scale<string>;
953 }
954
955 interface Cubehelix {
956 /**
957 * Set start color for hue rotation, default=300
958 */
959 start(s: number): Cubehelix;
960
961 /**
962 * number (and direction) of hue rotations (e.g. 1=360°, 1.5=`540°``), default=-1.5
963 */
964 rotations(r: number): Cubehelix;
965
966 /**
967 * gamma factor can be used to emphasise low or high intensity values, default=1
968 */
969 gamma(g: number): Cubehelix;
970
971 /**
972 * lightness range: default: [0,1] (black -> white)
973 */
974 lightness(l: number[]): Cubehelix;
975
976 /**
977 * You can call cubehelix.scale() to use the cube-helix through the chroma.scale interface.
978 */
979 scale(): Scale;
980 }
981}
982
983declare var chroma: chroma.ChromaStatic;
984
985export type Color = chroma.Color;
986export type Scale = chroma.Scale;
987export type Cubehelix = chroma.Cubehelix;
988export default chroma;
989export as namespace chroma;