forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chroma-js.d.ts
269 lines (202 loc) · 7.55 KB
/
chroma-js.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
// Type definitions for Chroma.js v1.1.1
// Project: https://github.com/gka/chroma.js
// Definitions by: Sebastian Brückner <https://github.com/invliD>, Marcin Pacholec <https://github.com/mpacholec>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/**
* Chroma.js is a tiny library for all kinds of color conversions and color scales.
*/
declare namespace Chroma {
export interface ChromaStatic {
/**
* Creates a color from a string representation (as supported in CSS).
*
* @param color The string to convert to a color.
* @return the color object.
*/
(color: string): Color;
/**
* Creates a color from a number representation [0; 16777215]
*
* @param color The number to convert to a color.
* @return the color object.
*/
(number: number): Color;
/**
* Create a color in the specified color space using a, b and c as values.
*
* @param a
* @param b
* @param c
* @param colorSpace The color space to use (one of "rgb", "hsl", "hsv", "lab", "lch", "gl"). Defaults to "rgb".
* @return the color object.
*/
(a: number, b: number, c: number, colorSpace?: string): Color;
(a: number, b: number, c: number, d: number, colorSpace?: string): Color;
/**
* Create a color in the specified color space using values.
*
* @param values An array of values (e.g. [r, g, b, a?]).
* @param colorSpace The color space to use (one of "rgb", "hsl", "hsv", "lab", "lch", "gl"). Defaults to "rgb".
* @return the color object.
*/
(values: number[], colorSpace?: string): Color;
/**
* Create a color from a hex or string representation (as supported in CSS).
*
* This is an alias of chroma.css().
*
* @param color The string to convert to a color.
* @return the color object.
*/
hex(color: string): Color;
hsl(h: number, s: number, l: number): Color;
hsv(h: number, s: number, v: number): Color;
lab(lightness: number, a: number, b: number, alpha?: number): Color;
lch(l: number, c: number, h: number): Color;
rgb(r: number, g: number, b: number): Color;
/**
* GL is a variant of RGB(A), with the only difference that the components are normalized to the range of 0..1.
*/
gl(red: number, green: number, blue: number, alpha?: number): Color;
/**
* light 2000K, bright sunlight 6000K. Based on Neil Bartlett's implementation.
* https://github.com/neilbartlett/color-temperature
*/
temperature(t: number): Color;
mix(col1: string | Color, col2: string | Color, f?: number, colorSpace?: string): Color;
interpolate(col1: string | Color, col2: string | Color, f?: number, colorSpace?: string): Color;
/**
* Blends two colors using RGB channel-wise blend functions. Valid blend modes are multiply, darken, lighten, screen, overlay, burn, and dogde.
*/
blend(col1: string, col2: string, blendMode: string): Color;
/**
* Returns a random color.
*/
random(): Color;
/**
* Computes the WCAG contrast ratio between two colors.
* A minimum contrast of 4.5:1 is recommended to ensure that text is still readable against a background color.
*
* @param color1 The first color.
* @param color2 The second color.
* @return the contrast ratio.
*/
contrast(col1: string | Color, col2: string | Color): number;
bezier(colors: string[]): Scale;
/**
* chroma.brewer is an map of ColorBrewer scales that are included in chroma.js for convenience.
* chroma.scale uses the colors to construct.
*/
brewer: {
OrRd: string[];
PuBu: string[];
BuPu: string[];
Oranges: string[];
BuGn: string[];
YlOrBr: string[];
YlGn: string[];
Reds: string[];
RdPu: string[];
Greens: string[];
YlGnBu: string[];
Purples: string[];
GnBu: string[];
Greys: string[];
YlOrRd: string[];
PuRd: string[];
Blues: string[];
PuBuGn: string[];
Spectral: string[];
RdYlGn: string[];
RdBu: string[];
PiYG: string[];
PRGn: string[];
RdYlBu: string[];
BrBG: string[];
RdGy: string[];
PuOr: string[];
Set2: string[];
Accent: string[];
Set1: string[];
Set3: string[];
Dark2: string[];
Paired: string[];
Pastel2: string[];
Pastel1: string[];
};
/**
* Helper function that computes class breaks for you, based on actual data.
* Supports three different modes: equidistant breaks, quantiles breaks and breaks based on k-means clusting.
*/
limits(data: number[], mode: string, c: number): number[];
scale(name: string): Scale;
scale(colors?: string[]): Scale;
cubehelix(): Cubehelix;
cmyk(c: number, m: number, y: number, k: number): Color;
/**
* Create a color from a hex or string representation (as supported in CSS).
*
* This is an alias of chroma.hex().
*
* @param color The string to convert to a color.
* @return the color object.
*/
css(col: string, mode?: string): string;
}
export interface Color {
alpha(a?: number): Color;
darken(f?: number): Color;
brighten(f?: number): Color;
saturate(s?: number): Color;
desaturate(s?: number): Color;
set(modechan: string, v: number | string): Color;
get(modechan: string): number;
luminance(): number;
luminance(l: number, mode?: string): Color;
hex(): string;
name(): string;
/**
* Create a color from a hex or string representation (as supported in CSS).
*
* This is an alias of chroma.hex().
*
* @param color The string to convert to a color.
* @return the color object.
*/
css(mode?: string): string;
rgb(): number[];
rgba(): number[];
hsl(): number[];
hsv(): number[];
hsi(): number[];
lab(): number[];
lch(): number[];
hcl(): number[];
temperature(): number;
gl(): number[];
}
export interface Scale {
(c: string[]): Scale;
(value: number): any;
domain(d?: number[], n?: number, mode?: string): Scale;
mode(mode: string): Scale;
correctLightness(enable?: boolean): Scale;
bezier(colors: string[]): Scale;
padding(p: number | number[]): Scale;
colors(c?: number): string[];
classes(c: number | number[]): (t: number) => Color;
range(arg: string[]): Scale;
scale(): Scale;
out(mode: string): Scale;
}
export interface Cubehelix extends Scale {
start(s: number): Cubehelix;
rotations(r: number): Cubehelix;
gamma(g: number): Cubehelix;
lightness(l: number[]): Cubehelix;
}
}
declare var chroma: Chroma.ChromaStatic;
declare module "chroma-js" {
export = chroma;
}