forked from graypegg/chromatism
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
352 lines (311 loc) · 11.8 KB
/
index.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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/**
* Types for all available colour modes.
*/
export namespace ColourModes {
/**
* Hexadecimal Color String
* @example
* "#FFC837"
*/
export type HEX = string;
/**
* RGB Color Object
* @example
* { r:255, g: 200, b: 55 }
*/
export type RGB = { r: number; g: number; b: number; };
/**
* CSS RGB Color String
* @example
* "rgb(255,200,55)"
*/
export type CSSRGB = string;
/**
* HSL Color Object
* @example
* { h: 44, s: 100, l: 61 }
*/
export type HSL = { h: number; s: number; l: number; };
/**
* CSS HSL Color String
* @example
* "hsl(44,100,61)"
*/
export type CSSHSL = { h: number; s: number; l: number; };
/**
* HSV Color Object
* @example
* { h: 44, s: 78, v: 100 }
*/
export type HSV = { h: number; s: number; v: number; };
/**
* CMYK Color Object
* @example
* { c: 0.5, m: 1, y: 0.2, k: 0.45 }
*/
export type CMYK = { c: number; m: number; y: number; k: number; };
/**
* YIQ Color Object
* @example
* { y: 0.132, i: 0.0222, q: 0.195 }
*/
export type YIQ = { y: number; i: number; q: number; };
/**
* XYZ Color Object
* @example
* { X: 41.24, Y: 21.26, Z: 1.93 }
*/
export type XYZ = { X: number; Y: number; Z: number; };
/**
* xyY Color Object
* @example
* { x: 0.64, y: 0.33, Y: 21.26 }
*/
export type XYY = { x: number; y: number; Y: number; };
/**
* LMS Color Object
* @example
* { rho: 42.266, gamma: 5.561, beta: 2.135 }
*/
export type LMS = { rho: number; gamma: number; beta: number; };
/**
* CIELAB (L*a*b*) Color Object
* @example
* { L: 53.23, a: 80.11, b: 67.22 }
*/
export type CIELAB = { L: number; a: number; b: number; };
/**
* CIELUV (L*u*v*) Color Object
* @example
* { L: 53.23, u: 175.05, v: 37.75 }
*/
export type CIELUV = { L: number; u: number; v: number; };
/**
* CIELCH (L*C*h*) Color Object
* @example
* { L: 53.23, C: 179.08, h: 12.17 }
*/
export type CIELCH = { L: number; C: number; h: number; };
/**
* HSLuv Color Object
* @example
* { L: 53.23, C: 179.08, h: 12.17 }
*/
export type HSLUV = { hu: number; s: number; l: number; };
/**
* Represents all available color modes.
*/
export type Any = (
HEX | RGB | CSSRGB | HSL | CSSHSL |
HSV | CMYK | YIQ | XYZ | XYY | LMS |
CIELAB | CIELUV | CIELCH | HSLUV
);
}
/**
* All functions return an object containing all modes of the result.
*/
export type ColourObject = {
hex: ColourModes.HEX;
rgb: ColourModes.RGB;
cssrgb: ColourModes.CSSRGB;
hsl: ColourModes.HSL;
csshsl: ColourModes.CSSHSL;
hsv: ColourModes.HSV;
cmyk: ColourModes.CMYK;
yiq: ColourModes.YIQ;
XYZ: ColourModes.XYZ;
xyY: ColourModes.XYY;
lms: ColourModes.LMS;
cielab: ColourModes.CIELAB;
cieluv: ColourModes.CIELUV;
cielch: ColourModes.CIELCH;
hsluv: ColourModes.HSLUV;
};
/**
* Helper type for functions that return multiple colour values.
*/
export type ColourObjectArray = {[P in keyof ColourObject]: ColourObject[P][]};
/**
* Performs colour transformations.
* @param colour - Any supported colour mode.
* @returns A colour object containing all available transforms.
* @see {@link https://github.com/toish/chromatism/blob/master/README.md#currency_exchange-colour-transformations}
*/
export function convert(colour: ColourModes.Any): ColourObject;
/**
* Generate a complementary colour
* @param colour - Any supported colour mode.
* @returns The complementary colour.
* @see {@link https://github.com/toish/chromatism/blob/master/README.md#generate-a-complementary-colour}
*/
export function complementary(colour: ColourModes.Any): ColourObject;
/**
* Generate an array of triad colours
* @param colour - Any supported colour mode.
* @returns Array of 3 colour objects.
* @see {@link https://github.com/toish/chromatism/blob/master/README.md#generate-an-array-of-triad-colours}
*/
export function triad(colour: ColourModes.Any): ColourObjectArray;
/**
* Generate an array of tetrad colours
* @param colour - Any supported colour mode.
* @returns Array of 4 colour objects.
* @see {@link https://github.com/toish/chromatism/blob/master/README.md#generate-an-array-of-tetrad-colours}
*/
export function tetrad(colour: ColourModes.Any): ColourObjectArray;
/**
* Generate a complementary colour with uniform lightness.
* @param colour - Any supported colour mode.
* @returns The complementary colour.
* @see {@link https://github.com/toish/chromatism/blob/master/README.md#generate-a-complementary-colour}
*/
export function uniformComplementary(colour: ColourModes.Any): ColourObject;
/**
* Generate an array of triad colours with uniform lightness.
* @param colour - Any supported colour mode.
* @returns Array of 3 colour objects.
* @see {@link https://github.com/toish/chromatism/blob/master/README.md#generate-an-array-of-triad-colours}
*/
export function uniformTriad(colour: ColourModes.Any): ColourObjectArray;
/**
* Generate an array of tetrad colours with uniform lightness.
* @param colour - Any supported colour mode.
* @returns Array of 4 colour objects.
* @see {@link https://github.com/toish/chromatism/blob/master/README.md#generate-an-array-of-tetrad-colours}
*/
export function uniformTetrad(colour: ColourModes.Any): ColourObjectArray;
/**
* Find the mid point between two colours
* [See more]{@link https://github.com/toish/chromatism/blob/master/README.md#find-the-mid-point-between-two-colours}
* @param colourOne - Any supported colour mode.
* @param colourTwo - Any supported colour mode.
* @returns The mid point colour.
*/
export function mid(colourOne: ColourModes.Any, colourTwo: ColourModes.Any): ColourObject;
/**
* Invert a colour
* @param colour - Any supported colour mode.
* @see {@link https://github.com/toish/chromatism/blob/master/README.md#invert-a-colour}
* @returns The inverted colour.
*/
export function invert(colour: ColourModes.Any): ColourObject;
/**
* Invert a grey colour
* @param colour - Any supported colour mode.
* @returns The inverted colour.
* @see {@link https://github.com/toish/chromatism/blob/master/README.md#invert-a-grey-colour}
*/
export function invertLightness(colour: ColourModes.Any): ColourObject;
/**
* Blend two colours (Multiply)
* @param colourOne - Any supported colour mode.
* @param colourTwo - Any supported colour mode.
* @returns The blended colour.
* @see {@link https://github.com/toish/chromatism/blob/master/README.md#blend-two-colours-multiply}
*/
export function multiply(colourOne: ColourModes.Any, colourTwo: ColourModes.Any): ColourObject;
/**
* Generate an array of adjacent hue-shifted colours (rainbow effect)
* @param degrees - The range of hue to include (in degrees, positive or negative)
* @param sections - How many adjacent colours to return.
* @param colour - Any supported colour mode.
* @returns An array of adjacent huge-shifted colours.
* @see {@link https://github.com/toish/chromatism/blob/master/README.md#generate-an-array-of-adjacent-hue-shifted-colours-rainbow-effect}
*/
export function adjacent(degrees: number, sections: number, colour: ColourModes.Any): ColourObjectArray;
/**
* Generate an array of the fade between two colours
* @param amount - The number of fade colours to return.
* @param colourFrom - Any supported colour mode.
* @param colourTo - Any supported colour mode.
* @returns An array containing the colour fade.
* @see {@link https://github.com/toish/chromatism/blob/master/README.md#generate-an-array-of-the-fade-between-two-colours}
*/
export function fade(amount: number, colourFrom: ColourModes.Any, colourTo: ColourModes.Any): ColourObjectArray;
/**
* Generate a new shade of a colour
* @param percent - A number between -100 and 100
* @param colour - Any supported colour mode.
* @returns The colour shade
* @see {@link https://github.com/toish/chromatism/blob/master/README.md#generate-a-new-shade-of-a-colour}
*/
export function shade(percent: number, colour: ColourModes.Any): ColourObject;
/**
* Generate a new saturation of a colour
* @param percent - A number between -100 and 100
* @param colour - Any supported colour mode.
* @returns The new saturation of colour.
* @see {@link https://github.com/toish/chromatism/blob/master/README.md#generate-a-new-saturation-of-a-colour}
*/
export function saturation(percent: number, colour: ColourModes.Any): ColourObject;
/**
* Change colour's brightness
* @param percent - A number between -100 and 100
* @param colour - Any supported colour mode.
* @returns The new colour.
* @see {@link https://github.com/toish/chromatism/blob/master/README.md#change-colours-brightness}
*/
export function brightness(percent: number, colour: ColourModes.Any): ColourObject;
/**
* Shift the hue of a colour
* @param degrees - The degree of hue to shift by (in degrees, positive or negative)
* @param colour - Any supported colour mode.
* @returns The new colour.
* @see {@link https://github.com/toish/chromatism/blob/master/README.md#shift-the-hue-of-a-colour}
*/
export function hue(degrees: number, colour: ColourModes.Any): ColourObject;
/**
* Shift the contrast of a colour
* @param contrastCoeff - A decimal value, normally between 0 and 4
* @param colour - Any supported colour mode.
* @returns The shifted contrast colour.
* @see {@link https://github.com/toish/chromatism/blob/master/README.md#shift-the-contrast-of-a-colour}
*/
export function contrast(contrastCoeff: number, colour: ColourModes.Any): ColourObject;
/**
* Greyscale version of the colour
* @param colour - Any supported colour mode.
* @returns The greyscale colour
* @see {@link https://github.com/toish/chromatism/blob/master/README.md#greyscale-version-of-the-colour}
*/
export function greyscale(colour: ColourModes.Any): ColourObject;
/**
* Sepia version of the colour
* @param colour - Any supported colour mode.
* @returns The sepia version of the colour
* @see {@link https://github.com/toish/chromatism/blob/master/README.md#sepia-version-of-the-colour}
*/
export function sepia(colour: ColourModes.Any): ColourObject;
/**
* Determine accessible colour for foreground text
* @param colour - Any supported colour mode.
* @returns The accessible foreground colour
* @see {@link https://github.com/toish/chromatism/blob/master/README.md#determine-accessible-colour-for-foreground-text}
*/
export function contrastRatio(colour: ColourModes.Any): ColourObject;
/**
* Chromatic Adaptation (White point)
* @param colour - Any supported colour mode.
* @param illuminantColour - A value from the {@ILLUMINANTS} constant
* @param sourceIlluminant [{ColourModes.XYZ}] - optional, assumed D65
* @returns The illuminant shifted colour
* @see {@link https://github.com/toish/chromatism/blob/master/README.md#chromatic-adaptation-white-point}
*/
export function adapt(colour: ColourModes.Any, illuminantColour: ColourModes.Any, sourceIlluminant?: ColourModes.Any): ColourObject;
/**
* Colour Difference
* @param colourOne - Any supported colour mode.
* @param colourTwo - Any supported colour mode.
* @param luminanceWeight [1] - optional
* @param chromaWeight [1] - optional
* @returns A measure of how different the two supplied colours are.
* @see {@link https://github.com/toish/chromatism/blob/master/README.md#colour-difference}
*/
export function difference(colourOne: ColourModes.Any, colourTwo: ColourModes.Any, luminanceWeight?: number, chromaWeight?: number): number;
/**
* Colour Temperature
* @param colour - Any supported colour mode.
* @returns The correlated colour temperature of the supplied colour.
* @see {@link https://github.com/toish/chromatism/blob/master/README.md#colour-temperature}
*/
export function temperature(colour: ColourModes.Any): number;