oxios-web 0.2.0

Web dashboard channel for Oxios
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
# [Khrôma]https://en.wiktionary.org/wiki/%CF%87%CF%81%E1%BF%B6%CE%BC%CE%B1#Noun

A collection of functions for manipulating CSS colors, inspired by SASS.

## Features

- **Small**: the entire library weighs ~5kb (min + gzip) and has no dependencies.
- **Fast**: in our benchmark suite functions are executed at ~0.0025ms per call on a mid-2014 MBP.
- **Flexible**: All valid CSS colors are supported.
- **SASS-like**: if you're familiar with SASS you should feel right at home.

## Install

```sh
npm install --save khroma
```

## Usage

```ts
import {red, isDark, darken, change} from 'khroma';

red ( '#ffffff' ); // => 255
isDark ( 'white' ); // => false
darken ( 'hsl(0, 5%, 100%)', 50 ); // => 'hsl(0, 5%, 50%)'
change ( 'rgb(255, 255, 255)', { a: 0.5 } ); // => 'rgba(255, 255, 255, 0.5)'
```

## Functions

These are all the provided functions, for each of them below you can find a short description, its interface and examples.

| Create        | Convert                 | Get <sub>channel</sub>    | Get <sub>more</sub>     | Edit <sub>channel</sub>           | Edit <sub>more</sub> |
| ------------- | ----------------------- | ------------------------- | ----------------------- | --------------------------------- | -------------------- |
| [hex]#hex   | [toKeyword]#tokeyword | [channel]#channel       | [contrast]#contrast   | [saturate]#saturate             | [adjust]#adjust    |
| [rgb]#rgb   | [toHex]#tohex         | [red]#red               | [luminance]#luminance | [desaturate]#desaturate         | [change]#change    |
| [rgba]#rgba | [toRgba]#torgba       | [green]#green           | [isDark]#isdark       | [lighten]#lighten               | [invert]#invert    |
| [hsl]#hsl   | [toHsla]#tohsla       | [blue]#blue             | [isLight]#islight     | [darken]#darken                 | [mix]#mix          |
| [hsla]#hsla |                         | [hue]#hue               | [isValid]#isvalid     | [opacify]#opacify               | [scale]#scale      |
|               |                         | [saturation]#saturation |                         | [fadeIn]#fadein                 |                      |
|               |                         | [lightness]#lightness   |                         | [transparentize]#transparentize |                      |
|               |                         | [alpha]#alpha           |                         | [fadeOut]#fadeout               |                      |
|               |                         | [opacity]#opacity       |                         | [rgba]#rgba-alt (alt)           |                      |
|               |                         |                           |                         | [complement]#complement         |                      |
|               |                         |                           |                         | [grayscale]#grayscale           |                      |

### Create

These functions create a new color given the provided channels.

#### `hex`

Alias for [`rgba`](#rgba).

#### `rgb`

Alias for [`rgba`](#rgba).

#### `rgba`

Creates a new color given its rgba channels, the alpha channel is optional.

```ts
function rgba ( r: string, g: number, b: number, a: number = 1 ): string;
```

```ts
rgba ( 255, 204, 0 ); // => '#ffcc00'
rgba ( 255, 204, 0, 0.5 ); // => 'rgba(255, 204, 0, 0.5)'
```

#### `hsl`

Alias for [`hsla`](#hsla).

#### `hsla`

Creates a new color given its hsla channels, the alpha channel is optional.

```ts
function hsla ( h: number, s: number, l: number, a: number = 1 ): string;
```

```ts
hsla ( 0, 50, 100 ); // => 'hsl(0, 50%, 100%)'
hsla ( 10, 50, 100, 0.5 ); // => 'hsla(10, 50%, 100%, 0.5)'
```

### Convert

These functions convert supported colors to a specific format.

#### `toKeyword`

Convert a color to the keyword format, when possible.

```ts
function toKeyword ( color: string ): string | undefined;
```

```ts
channel ( '#ff0000' ); // => 'red'
channel ( '#ffcc00' ); // => undefined
```

#### `toHex`

Convert a color to the HEX format.

```ts
function toHex ( color: string ): string;
```

```ts
channel ( 'red' ); // => '#ff0000'
channel ( '#ff0000' ); // => '#ff0000'
```

#### `toRgba`

Convert a color to the RGBA format.

```ts
function toRgba ( color: string ): string;
```

```ts
channel ( 'red' ); // => 'rgb(255, 0, 0)'
channel ( '#ff0000' ); // => 'rgb(255, 0, 0)'
channel ( '#00000088' ); // => 'rgba(0, 0, 0, 0.5333333333)'
```

#### `toHsla`

Convert a color to the HSLA format.

```ts
function toHsla ( color: string ): string;
```

```ts
channel ( 'red' ); // => 'hsl(0, 100%, 50%)'
channel ( '#ff0000' ); // => 'hsl(0, 100%, 50%)'
channel ( 'rgb(255, 0, 0)' ); // => 'hsl(0, 100%, 50%)'
```

### Get <sub>channel</sub>

These functions get a single channel from the provided color.

#### `channel`

Gets any single channel of the color.

```ts
function channel ( color: string, channel: 'r' | 'g' | 'b' | 'h' | 's' | 'l' | 'a' ): number;
```

```ts
channel ( '#ffcc00', 'r' ); // => 255
channel ( '#ffcc00', 'h' ); // => 48
channel ( '#ffcc00', 'a' ); // => 1
```

#### `red`

Gets the red channel of the color.

```ts
function red ( color: string ): number;
```

```ts
red ( '#ffcc00' ); // => 255
```

#### `green`

Gets the green channel of the color.

```ts
function green ( color: string ): number;
```

```ts
green ( '#ffcc00' ); // => 204
```

#### `blue`

Gets the blue channel of the color.

```ts
function blue ( color: string ): number;
```

```ts
blue ( '#ffcc00' ); // => 0
```

#### `hue`

Gets the hue channel of the color.

```ts
function hue ( color: string ): number;
```

```ts
hue ( 'hsl(0, 50%, 100%)' ); // => 0
```

#### `saturation`

Gets the saturation channel of the color.

```ts
function saturation ( color: string ): number;
```

```ts
saturation ( 'hsl(0, 50%, 100%)' ); // => 50
```

#### `lightness`

Gets the lightness channel of the color.

```ts
function lightness ( color: string ): number;
```

```ts
lightness ( 'hsl(0, 50%, 100%)' ); // => 100
```

#### `alpha`

Gets the alpha channel of the color.

```ts
function alpha ( color: string ): number;
```

```ts
alpha ( '#ffcc00' ); // => 1
alpha ( 'rgba(255, 205, 0, 0.5)' ); // => 0.5
```

#### `opacity`

Alias for [`alpha`](#alpha).

### Get <sub>more</sub>

These functions get some other information from the provided color.

#### `contrast`

Gets the contrast in luminance between two colors.

Contrast values go between 1 and 10. 1 means same color, >= 4 means decent contrast, >= 7 means great contrast, 10 means great contrast.

```ts
function contrast ( color1: string, color2: string ): number;
```

```ts
contrast ( '#000000', '#000000' ); // => 1
contrast ( '#000000', '#ffffff' ); // => 10
contrast ( '#888888', '#ffffff' ); // => 4.0617165366
```

#### `luminance`

Gets the [relative luminance](https://en.wikipedia.org/wiki/Relative_luminance) of the color.

```ts
function luminance ( color: string ): number;
```

```ts
luminance ( 'black' ); // => 0
luminance ( 'white' ); // => 1
luminance ( '#ffcc00' ); // => 0.6444573127
```

#### `isDark`

Checks if the provided color is a dark color.

```ts
function isDark ( color: string ): number;
```

```ts
isDark ( 'black' ); // => true
isDark ( 'white' ); // => false
isDark ( '#ffcc00' ); // => false
```

#### `isLight`

Checks if the provided color is a light color.

```ts
function isLight ( color: string ): number;
```

```ts
isLight ( 'black' ); // => false
isLight ( 'white' ); // => true
isLight ( '#ffcc00' ); // => true
```

#### `isValid`

Checks if the provided color is a valid color.

```ts
function isLight ( color: string ): boolean;
```

```ts
isValid ( 'black' ); // => true
isLight ( '#ffcc00' ); // => true
isValid ( '#wtf' ); // => false
```

### Edit <sub>channel</sub>

These functions change a single channel of the provided color.

#### `saturate`

Increases the saturation channel of the color.

```ts
function saturate ( color: string, amount: number ): string;
```

```ts
saturate ( 'hsl(0, 50%, 50%)', 25 ); // => 'hsl(0, 75%, 50%)'
```

#### `desaturate`

Decreases the saturation channel of the color.

```ts
function desaturate ( color: string, amount: number ): string;
```

```ts
desaturate ( 'hsl(0, 50%, 50%)', 25 ); // => 'hsl(0, 25%, 50%)'
```

#### `lighten`

Increases the lightness channel of the color.

```ts
function lighten ( color: string, amount: number ): string;
```

```ts
lighten ( 'hsl(0, 50%, 50%)', 25 ); // => 'hsl(0, 50%, 75%)'
```

#### `darken`

Decreases the lightness channel of the color.

```ts
function darken ( color: string, amount: number ): string;
```

```ts
darken ( 'hsl(0, 50%, 50%)', 25 ); // => 'hsl(0, 50%, 25%)'
```

#### `opacify`

Increases the opacity channel of the color.

```ts
function opacify ( color: string, amount: number ): string;
```

```ts
opacify ( 'rgba(255, 204, 0, 0.5)', 0.25 ); // => 'rgba(255, 204, 0, 0.75)'
```

#### `fadeIn`

Alias for [`opacify`](#opacify).

#### `transparentize`

Decreases the opacity channel of the color.

```ts
function transparentize ( color: string, amount: number ): string;
```

```ts
transparentize ( 'rgba(255, 204, 0, 0.5)', 0.25 ); // => 'rgba(255, 204, 0, 0.25)'
```

#### `fadeOut`

Alias for [`transparentize`](#transparentize).

#### `rgba` (alt)

Sets a new value for the opacity channel.

```ts
function rgba ( color: string, amount: number ): string;
```

```ts
rgba ( 'rgba(255, 204, 0, 0.5)', 0.1 ); // => 'rgba(255, 204, 0, 0.1)'
```

#### `complement`

Gets the complement of the color, rotating its hue channel by 180 degrees.

```ts
function complement ( color: string ): string;
```

```ts
complement ( '#ffcc00' ); // => 'hsl(228, 100%, 50%)'
```

#### `grayscale`

Gets the grayscale version of the color, setting its saturation to 0.

```ts
function grayscale ( color: string ): string;
```

```ts
grayscale ( '#ffcc00' ); // => 'hsl(48, 0%, 50%)'
```

### Edit <sub>more</sub>

These functions can/will change more than a single channel at once of the provided color.

#### `adjust`

Increases or decreases the value of any channel of the color.

```ts
function adjust ( color: string, channels: Record<'r' | 'g' | 'b' | 'h' | 's' | 'l' | 'a', number> ): string;
```

```ts
adjust ( '#ffcc00', { r: -10, g: 200 } ); // => '#f5ff00'
adjust ( '#ffcc00', { a: -0.5 } ); // => 'rgba(255, 204, 0, 0.5)'
adjust ( '#ffcc00', { h: 50, l: -30 } ); // => 'hsl(98, 100%, 20%)'
```

#### `change`

Sets a new value for any channel of the color.

```ts
function change ( color: string, channels: Record<'r' | 'g' | 'b' | 'h' | 's' | 'l' | 'a', number> ): string;
```

```ts
change ( '#ffcc00', { r: 10, g: 200 } ); // => '#0ac800'
change ( '#ffcc00', { a: 0.5 } ); // => 'rgba(255, 204, 0, 0.5)'
change ( '#ffcc00', { h: 50, l: 30 } ); // => 'hsl(50, 100%, 30%)'
```

#### `invert`

Gets the inverse of the color.

```ts
function invert ( color: string, weight: number = 100 ): string;
```

```ts
invert ( '#ffcc00' ); // => '#0033ff'
invert ( '#ffcc00', 50 ); // => '#808080'
```

#### `mix`

Mixes two colors together.

```ts
function mix ( color1: string, color2: string, weight: number = 50 ): string;
```

```ts
mix ( 'red', 'blue' ); // => '#800080'
mix ( 'red', 'blue', 15 ); // => '#2600d9'
```

#### `scale`

Scales any channel of the color.

```ts
function scale ( color: string, channels: Record<'r' | 'g' | 'b' | 'h' | 's' | 'l' | 'a', number> ): string;
```

```ts
scale ( '#ffcc00', { r: -50, b: 10 } ); // => '#80cc1a'
```

## License

MIT © Fabio Spampinato, Andrew Maney