forked from kurkle/color
-
Notifications
You must be signed in to change notification settings - Fork 0
/
color.d.ts
235 lines (234 loc) · 5.13 KB
/
color.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
/**
* @packageDocumentation
* @module @kurkle/color
*/
export type RGBA = {
/**
* - red [0..255]
*/
r: number;
/**
* - green [0..255]
*/
g: number;
/**
* - blue [0..255]
*/
b: number;
/**
* - alpha [0..1]
*/
a: number;
};
/**
* Parse HEX to color
* @param {string} str - the string
*/
export function hexParse(str: string): {
r: number;
g: number;
b: number;
a: number;
};
/**
* Return HEX string from color
* @param {RGBA} v - the color
*/
export function hexString(v: RGBA): string | RGBA;
/**
* Rounds decimal to nearest integer
* @param {number} v - the number to round
*/
export function round(v: number): number;
/**
* convert percent to byte 0..255
* @param {number} v - 0..100
*/
export function p2b(v: number): number;
/**
* convert byte to percet 0..100
* @param {number} v - 0..255
*/
export function b2p(v: number): number;
/**
* convert normalized to byte 0..255
* @param {number} v - 0..1
*/
export function n2b(v: number): number;
/**
* convert byte to normalized 0..1
* @param {number} v - 0..255
*/
export function b2n(v: number): number;
/**
* convert normalized to percent 0..100
* @param {number} v - 0..1
*/
export function n2p(v: number): number;
/**
* Convert rgb to hsl
* @param {RGBA} v - the color
* @returns {number[]} - [h, s, l]
*/
export function rgb2hsl(v: RGBA): number[];
/**
* Convert hsl to rgb
* @param {number|number[]} h - hue | [h, s, l]
* @param {number} [s] - saturation
* @param {number} [l] - lightness
* @returns {number[]}
*/
export function hsl2rgb(h: number | number[], s?: number, l?: number): number[];
/**
* Convert hwb to rgb
* @param {number|number[]} h - hue | [h, s, l]
* @param {number} [w] - whiteness
* @param {number} [b] - blackness
* @returns {number[]}
*/
export function hwb2rgb(h: number | number[], w?: number, b?: number): number[];
/**
* Convert hsv to rgb
* @param {number|number[]} h - hue | [h, s, l]
* @param {number} [s] - saturation
* @param {number} [v] - value
* @returns {number[]}
*/
export function hsv2rgb(h: number | number[], s?: number, v?: number): number[];
/**
* Parse hsl/hsv/hwb color string
* @param {string} str - hsl/hsv/hwb color string
* @returns {RGBA} - the parsed color components
*/
export function hueParse(str: string): RGBA;
/**
* Rotate the `v` color by `deg` degrees
* @param {RGBA} v - the color
* @param {number} deg - degrees to rotate
*/
export function rotate(v: RGBA, deg: number): void;
/**
* Return hsl(a) string from color components
* @param {RGBA} v - the color
* @return {string|undefined}
*/
export function hslString(v: RGBA): string;
/**
* Parse color name
* @param {string} str - the color name
* @return {RGBA} - the color
*/
export function nameParse(str: string): RGBA;
/**
* Parse rgb(a) string to RGBA
* @param {string} str - the rgb string
* @returns {RGBA} - the parsed color
*/
export function rgbParse(str: string): RGBA;
/**
* Return rgb(a) string from color
* @param {RGBA} v - the color
*/
export function rgbString(v: RGBA): string;
export class Color {
/**
* constructor
* @param {Color|RGBA|string|number[]} input
*/
constructor(input: string | number[] | Color | RGBA);
/**
* @type {RGBA}
* @hidden
**/
_rgb: RGBA;
/**
* @type {boolean}
* @hidden
**/
_valid: boolean;
/**
* `true` if this is a valid color
* @returns {boolean}
*/
get valid(): boolean;
/**
* @param {RGBA} obj - the color
*/
set rgb(arg: RGBA);
/**
* @returns {RGBA} - the color
*/
get rgb(): RGBA;
/**
* rgb(a) string
*/
rgbString(): string;
/**
* hex string
*/
hexString(): string | RGBA;
/**
* hsl(a) string
*/
hslString(): string;
/**
* Mix another color to this color.
* @param {Color} color - Color to mix in
* @param {number} weight - 0..1
*/
mix(color: Color, weight: number): Color;
/**
* Clone
*/
clone(): Color;
/**
* Set aplha
* @param {number} a - the alpha [0..1]
*/
alpha(a: number): Color;
/**
* Make clearer
* @param {number} ratio - ratio [0..1]
*/
clearer(ratio: number): Color;
/**
* Convert to grayscale
*/
greyscale(): Color;
/**
* Opaquer
* @param {number} ratio - ratio [0..1]
*/
opaquer(ratio: number): Color;
negate(): Color;
/**
* Lighten
* @param {number} ratio - ratio [0..1]
*/
lighten(ratio: number): Color;
/**
* Darken
* @param {number} ratio - ratio [0..1]
*/
darken(ratio: number): Color;
/**
* Saturate
* @param {number} ratio - ratio [0..1]
*/
saturate(ratio: number): Color;
/**
* Desaturate
* @param {number} ratio - ratio [0..1]
*/
desaturate(ratio: number): Color;
/**
* Rotate
* @param {number} deg - degrees to rotate
*/
rotate(deg: number): Color;
}
/**
* Construct new Color instance
* @param {Color|RGBA|string|number[]} input
*/
export default function _default(input: string | number[] | Color | RGBA): Color;