forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chroma-js.d.ts
317 lines (273 loc) · 10.2 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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
// Type definitions for Chroma.js v0.5.6
// Project: https://github.com/gka/chroma.js
// Definitions by: Sebastian Brückner <https://github.com/invliD>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/**
* Chroma.js is a tiny library for all kinds of color conversions and color scales.
*/
declare module 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;
/**
* 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;
/**
* 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 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.
*/
color(a: number, b: number, c: number, colorSpace?: string): Color;
/**
* Calculate the contrast ratio of two colors.
*
* @param color1 The first color.
* @param color2 The second color.
* @return the contrast ratio.
*/
contrast(color1: Color, color2: Color): number;
/**
* Calculate the contrast ratio of two colors.
*
* @param color1 The first color.
* @param color2 The second color.
* @return the contrast ratio.
*/
contrast(color1: Color, color2: string): number;
/**
* Calculate the contrast ratio of two colors.
*
* @param color1 The first color.
* @param color2 The second color.
* @return the contrast ratio.
*/
contrast(color1: string, color2: Color): number;
/**
* Calculate the contrast ratio of two colors.
*
* @param color1 The first color.
* @param color2 The second color.
* @return the contrast ratio.
*/
contrast(color1: string, color2: string): number;
/**
* 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(color: 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;
rgb(red: number, green: number, blue: number, alpha?: number): Color;
hsl(hue: number, saturation: number, lightness: number, alpha?: number): Color;
hsv(hue: number, saturation: number, value: number, alpha?: number): Color;
lab(lightness: number, a: number, b: number, alpha?: number): Color;
lch(lightness: number, chroma: number, hue: number, alpha?: number): Color;
gl(red: number, green: number, blue: number, alpha?: number): Color;
interpolate: InterpolateFunction;
mix: InterpolateFunction;
luminance(color: Color): number;
luminance(color: string): number;
/**
* Creates a color scale using a pre-defined color scale.
*
* @param name The name of the color scale.
* @return the resulting color scale.
*/
scale(name: string): Scale;
/**
* Creates a color scale function from the given set of colors.
*
* @param colors An Array of at least two color names or hex values.
* @return the resulting color scale.
*/
scale(colors?: string[]): Scale;
scales: PredefinedScales;
}
interface InterpolateFunction {
(color1: Color, color2: Color, f: number, mode?: string): Color;
(color1: Color, color2: string, f: number, mode?: string): Color;
(color1: string, color2: Color, f: number, mode?: string): Color;
(color1: string, color2: string, f: number, mode?: string): Color;
bezier(colors: any[]): (t: number) => Color;
}
interface PredefinedScales {
[key: string]: Scale;
cool: Scale;
hot: Scale;
}
export interface Color {
/**
* Creates a color from a string representation (as supported in CSS).
*
* @param color The string to convert to a color.
*/
new(color: string): 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".
*/
new(a: number, b: number, c: number, colorSpace?: string): Color;
/**
* Create a color in the specified color space using a, b and c as color values and alpha as the alpha value.
*
* @param a
* @param b
* @param c
* @param alpha The alpha value of the color.
* @param colorSpace The color space to use (one of "rgb", "hsl", "hsv", "lab", "lch", "gl"). Defaults to "rgb".
*/
new(a: number, b: number, c: number, alpha: 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".
*/
new(values: number[], colorSpace: string): Color;
/**
* Convert this color to CSS hex representation.
*
* @return this color's hex representation.
*/
hex(): string;
/**
* @return the relative luminance of the color, which is a value between 0 (black) and 1 (white).
*/
luminance(): number;
/**
* @return the X11 name of this color or its hex value if it does not have a name.
*/
name(): string;
/**
* @return the alpha value of the color.
*/
alpha(): number;
/**
* Set the alpha value.
*
* @param alpha The alpha value.
* @return this
*/
alpha(alpha: number): Color;
css(mode?: string): string;
interpolate(color: Color, f: number, mode?: string): Color;
interpolate(color: string, f: number, mode?: string): Color;
premultiply(): Color;
rgb(): number[];
rgba(): number[];
hsl(): number[];
hsv(): number[];
lab(): number[];
lch(): number[];
hsi(): number[];
gl(): number[];
darken(amount?: number): Color;
darker(amount: number): Color;
brighten(amount?: number): Color;
brighter(amount: number): Color;
saturate(amount?: number): Color;
desaturate(amount?: number): Color;
toString(): string;
}
export interface Scale {
/**
* Interpolate a color using the currently set range and domain.
*
* @param value The value to use for interpolation.
* @return the interpolated hex color OR a Color object (depending on the mode set on this Scale).
*/
(value: number): any;
/**
* Retreive all possible colors generated by this scale if it has distinct classes.
*
* @param mode The output mode to use. Must be one of Color's getters. Defaults to "hex".
* @return an array of colors in the type specified by mode.
*/
colors(mode?: string): any[];
correctLightness(): boolean;
/**
* Enable or disable automatic lightness correction of this scale.
*
* @param Whether to enable or disable automatic lightness correction.
* @return this
*/
correctLightness(enable: boolean): Scale;
/**
* Get the current domain.
*
* @return The current domain.
*/
domain(): number[];
/**
* Set the domain.
*
* @param domain An Array of at least two numbers (min and max).
* @param classes The number of fixed classes to create between min and max.
* @param mode The scale to use. Examples: log, quantiles, k-means.
* @return this
*/
domain(domain: number[], classes?: number, mode?: string): Scale;
/**
* Specify in which color space the colors should be interpolated. Defaults to "rgb".
* You can use any of the following spaces: rgb, hsv, hsl, lab, lch
*
* @param colorSpace The color space to use for interpolation.
* @return this
*/
mode(colorSpace: string): Scale;
/**
* Set the output mode of this Scale.
*
* @param mode The output mode to use. Must be one of Color's getters.
* @return this
*/
out(mode: string): Scale;
/**
* Set the color range after initialization.
*
* @param colors An Array of at least two color names or hex values.
* @return this
*/
range(colors: string[]): Scale;
}
}
declare var chroma: Chroma.ChromaStatic;