colorizr 2.1.1 → 3.0.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +487 -153
- package/dist/index.d.mts +450 -0
- package/dist/index.d.ts +450 -0
- package/dist/index.js +1627 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1551 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +56 -38
- package/src/brightness-difference.ts +18 -11
- package/src/chroma.ts +8 -5
- package/src/color-difference.ts +9 -7
- package/src/colorizr.ts +214 -0
- package/src/compare.ts +10 -7
- package/src/contrast.ts +10 -7
- package/src/convert.ts +12 -0
- package/src/converters/hex2hsl.ts +14 -0
- package/src/converters/hex2oklab.ts +14 -0
- package/src/converters/hex2oklch.ts +14 -0
- package/src/converters/hex2rgb.ts +19 -0
- package/src/converters/hsl2hex.ts +12 -0
- package/src/converters/hsl2oklab.ts +12 -0
- package/src/converters/hsl2oklch.ts +12 -0
- package/src/{hsl2rgb.ts → converters/hsl2rgb.ts} +9 -12
- package/src/converters/index.ts +24 -0
- package/src/converters/oklab2hex.ts +12 -0
- package/src/converters/oklab2hsl.ts +12 -0
- package/src/converters/oklab2oklch.ts +20 -0
- package/src/converters/oklab2rgb.ts +36 -0
- package/src/converters/oklch2hex.ts +12 -0
- package/src/converters/oklch2hsl.ts +12 -0
- package/src/converters/oklch2oklab.ts +26 -0
- package/src/converters/oklch2rgb.ts +12 -0
- package/src/converters/rgb2hex.ts +12 -0
- package/src/{rgb2hsl.ts → converters/rgb2hsl.ts} +9 -15
- package/src/converters/rgb2oklab.ts +34 -0
- package/src/converters/rgb2oklch.ts +12 -0
- package/src/darken.ts +5 -3
- package/src/desaturate.ts +5 -3
- package/src/extract-color-parts.ts +57 -0
- package/src/format-css.ts +83 -21
- package/src/format-hex.ts +15 -11
- package/src/index.ts +35 -191
- package/src/invert.ts +20 -0
- package/src/is-valid-color.ts +2 -2
- package/src/lighten.ts +5 -3
- package/src/luminance.ts +8 -5
- package/src/modules/constants.ts +46 -0
- package/src/modules/css-colors.ts +8 -5
- package/src/modules/hex-utils.ts +69 -0
- package/src/modules/hue2rgb.ts +3 -1
- package/src/modules/invariant.ts +22 -0
- package/src/modules/parse-color.ts +58 -38
- package/src/modules/updater.ts +24 -12
- package/src/modules/utils.ts +137 -187
- package/src/modules/validators.ts +169 -0
- package/src/name.ts +13 -6
- package/src/opacify.ts +21 -0
- package/src/opacity.ts +25 -0
- package/src/palette.ts +32 -14
- package/src/parse-css.ts +118 -62
- package/src/random.ts +4 -3
- package/src/rotate.ts +21 -11
- package/src/saturate.ts +5 -3
- package/src/scheme.ts +42 -15
- package/src/swatch.ts +106 -0
- package/src/text-color.ts +32 -7
- package/src/transparentize.ts +25 -0
- package/src/types/index.ts +59 -41
- package/esm/brightness-difference.d.ts +0 -4
- package/esm/brightness-difference.js +0 -16
- package/esm/brightness-difference.js.map +0 -1
- package/esm/chroma.d.ts +0 -4
- package/esm/chroma.js +0 -14
- package/esm/chroma.js.map +0 -1
- package/esm/color-difference.d.ts +0 -4
- package/esm/color-difference.js +0 -17
- package/esm/color-difference.js.map +0 -1
- package/esm/compare.d.ts +0 -5
- package/esm/compare.js +0 -36
- package/esm/compare.js.map +0 -1
- package/esm/contrast.d.ts +0 -4
- package/esm/contrast.js +0 -16
- package/esm/contrast.js.map +0 -1
- package/esm/darken.d.ts +0 -4
- package/esm/darken.js +0 -8
- package/esm/darken.js.map +0 -1
- package/esm/desaturate.d.ts +0 -4
- package/esm/desaturate.js +0 -8
- package/esm/desaturate.js.map +0 -1
- package/esm/fade.d.ts +0 -5
- package/esm/fade.js +0 -23
- package/esm/fade.js.map +0 -1
- package/esm/format-css.d.ts +0 -2
- package/esm/format-css.js +0 -27
- package/esm/format-css.js.map +0 -1
- package/esm/format-hex.d.ts +0 -1
- package/esm/format-hex.js +0 -17
- package/esm/format-hex.js.map +0 -1
- package/esm/hex2hsl.d.ts +0 -2
- package/esm/hex2hsl.js +0 -8
- package/esm/hex2hsl.js.map +0 -1
- package/esm/hex2rgb.d.ts +0 -2
- package/esm/hex2rgb.js +0 -12
- package/esm/hex2rgb.js.map +0 -1
- package/esm/hsl2hex.d.ts +0 -5
- package/esm/hsl2hex.js +0 -11
- package/esm/hsl2hex.js.map +0 -1
- package/esm/hsl2rgb.d.ts +0 -5
- package/esm/hsl2rgb.js +0 -35
- package/esm/hsl2rgb.js.map +0 -1
- package/esm/index.d.ts +0 -110
- package/esm/index.js +0 -167
- package/esm/index.js.map +0 -1
- package/esm/is-valid-color.d.ts +0 -1
- package/esm/is-valid-color.js +0 -11
- package/esm/is-valid-color.js.map +0 -1
- package/esm/is-valid-hex.d.ts +0 -1
- package/esm/is-valid-hex.js +0 -11
- package/esm/is-valid-hex.js.map +0 -1
- package/esm/lighten.d.ts +0 -4
- package/esm/lighten.js +0 -8
- package/esm/lighten.js.map +0 -1
- package/esm/luminance.d.ts +0 -4
- package/esm/luminance.js +0 -21
- package/esm/luminance.js.map +0 -1
- package/esm/modules/css-colors.d.ts +0 -152
- package/esm/modules/css-colors.js +0 -153
- package/esm/modules/css-colors.js.map +0 -1
- package/esm/modules/hue2rgb.d.ts +0 -4
- package/esm/modules/hue2rgb.js +0 -25
- package/esm/modules/hue2rgb.js.map +0 -1
- package/esm/modules/parse-color.d.ts +0 -2
- package/esm/modules/parse-color.js +0 -56
- package/esm/modules/parse-color.js.map +0 -1
- package/esm/modules/updater.d.ts +0 -4
- package/esm/modules/updater.js +0 -19
- package/esm/modules/updater.js.map +0 -1
- package/esm/modules/utils.d.ts +0 -61
- package/esm/modules/utils.js +0 -199
- package/esm/modules/utils.js.map +0 -1
- package/esm/name.d.ts +0 -1
- package/esm/name.js +0 -10
- package/esm/name.js.map +0 -1
- package/esm/palette.d.ts +0 -2
- package/esm/palette.js +0 -32
- package/esm/palette.js.map +0 -1
- package/esm/parse-css.d.ts +0 -5
- package/esm/parse-css.js +0 -78
- package/esm/parse-css.js.map +0 -1
- package/esm/random.d.ts +0 -4
- package/esm/random.js +0 -13
- package/esm/random.js.map +0 -1
- package/esm/rgb2hex.d.ts +0 -5
- package/esm/rgb2hex.js +0 -20
- package/esm/rgb2hex.js.map +0 -1
- package/esm/rgb2hsl.d.ts +0 -2
- package/esm/rgb2hsl.js +0 -51
- package/esm/rgb2hsl.js.map +0 -1
- package/esm/rotate.d.ts +0 -4
- package/esm/rotate.js +0 -17
- package/esm/rotate.js.map +0 -1
- package/esm/saturate.d.ts +0 -4
- package/esm/saturate.js +0 -8
- package/esm/saturate.js.map +0 -1
- package/esm/scheme.d.ts +0 -5
- package/esm/scheme.js +0 -44
- package/esm/scheme.js.map +0 -1
- package/esm/shift.d.ts +0 -5
- package/esm/shift.js +0 -13
- package/esm/shift.js.map +0 -1
- package/esm/text-color.d.ts +0 -4
- package/esm/text-color.js +0 -13
- package/esm/text-color.js.map +0 -1
- package/esm/types/index.d.ts +0 -46
- package/esm/types/index.js +0 -2
- package/esm/types/index.js.map +0 -1
- package/lib/brightness-difference.d.ts +0 -4
- package/lib/brightness-difference.js +0 -19
- package/lib/brightness-difference.js.map +0 -1
- package/lib/chroma.d.ts +0 -4
- package/lib/chroma.js +0 -17
- package/lib/chroma.js.map +0 -1
- package/lib/color-difference.d.ts +0 -4
- package/lib/color-difference.js +0 -20
- package/lib/color-difference.js.map +0 -1
- package/lib/compare.d.ts +0 -5
- package/lib/compare.js +0 -39
- package/lib/compare.js.map +0 -1
- package/lib/contrast.d.ts +0 -4
- package/lib/contrast.js +0 -19
- package/lib/contrast.js.map +0 -1
- package/lib/darken.d.ts +0 -4
- package/lib/darken.js +0 -11
- package/lib/darken.js.map +0 -1
- package/lib/desaturate.d.ts +0 -4
- package/lib/desaturate.js +0 -11
- package/lib/desaturate.js.map +0 -1
- package/lib/fade.d.ts +0 -5
- package/lib/fade.js +0 -26
- package/lib/fade.js.map +0 -1
- package/lib/format-css.d.ts +0 -2
- package/lib/format-css.js +0 -30
- package/lib/format-css.js.map +0 -1
- package/lib/format-hex.d.ts +0 -1
- package/lib/format-hex.js +0 -20
- package/lib/format-hex.js.map +0 -1
- package/lib/hex2hsl.d.ts +0 -2
- package/lib/hex2hsl.js +0 -11
- package/lib/hex2hsl.js.map +0 -1
- package/lib/hex2rgb.d.ts +0 -2
- package/lib/hex2rgb.js +0 -15
- package/lib/hex2rgb.js.map +0 -1
- package/lib/hsl2hex.d.ts +0 -5
- package/lib/hsl2hex.js +0 -14
- package/lib/hsl2hex.js.map +0 -1
- package/lib/hsl2rgb.d.ts +0 -5
- package/lib/hsl2rgb.js +0 -38
- package/lib/hsl2rgb.js.map +0 -1
- package/lib/index.d.ts +0 -110
- package/lib/index.js +0 -212
- package/lib/index.js.map +0 -1
- package/lib/is-valid-color.d.ts +0 -1
- package/lib/is-valid-color.js +0 -14
- package/lib/is-valid-color.js.map +0 -1
- package/lib/is-valid-hex.d.ts +0 -1
- package/lib/is-valid-hex.js +0 -14
- package/lib/is-valid-hex.js.map +0 -1
- package/lib/lighten.d.ts +0 -4
- package/lib/lighten.js +0 -11
- package/lib/lighten.js.map +0 -1
- package/lib/luminance.d.ts +0 -4
- package/lib/luminance.js +0 -24
- package/lib/luminance.js.map +0 -1
- package/lib/modules/css-colors.d.ts +0 -152
- package/lib/modules/css-colors.js +0 -156
- package/lib/modules/css-colors.js.map +0 -1
- package/lib/modules/hue2rgb.d.ts +0 -4
- package/lib/modules/hue2rgb.js +0 -28
- package/lib/modules/hue2rgb.js.map +0 -1
- package/lib/modules/parse-color.d.ts +0 -2
- package/lib/modules/parse-color.js +0 -59
- package/lib/modules/parse-color.js.map +0 -1
- package/lib/modules/updater.d.ts +0 -4
- package/lib/modules/updater.js +0 -22
- package/lib/modules/updater.js.map +0 -1
- package/lib/modules/utils.d.ts +0 -61
- package/lib/modules/utils.js +0 -215
- package/lib/modules/utils.js.map +0 -1
- package/lib/name.d.ts +0 -1
- package/lib/name.js +0 -13
- package/lib/name.js.map +0 -1
- package/lib/palette.d.ts +0 -2
- package/lib/palette.js +0 -35
- package/lib/palette.js.map +0 -1
- package/lib/parse-css.d.ts +0 -5
- package/lib/parse-css.js +0 -81
- package/lib/parse-css.js.map +0 -1
- package/lib/random.d.ts +0 -4
- package/lib/random.js +0 -16
- package/lib/random.js.map +0 -1
- package/lib/rgb2hex.d.ts +0 -5
- package/lib/rgb2hex.js +0 -23
- package/lib/rgb2hex.js.map +0 -1
- package/lib/rgb2hsl.d.ts +0 -2
- package/lib/rgb2hsl.js +0 -54
- package/lib/rgb2hsl.js.map +0 -1
- package/lib/rotate.d.ts +0 -4
- package/lib/rotate.js +0 -20
- package/lib/rotate.js.map +0 -1
- package/lib/saturate.d.ts +0 -4
- package/lib/saturate.js +0 -11
- package/lib/saturate.js.map +0 -1
- package/lib/scheme.d.ts +0 -5
- package/lib/scheme.js +0 -47
- package/lib/scheme.js.map +0 -1
- package/lib/shift.d.ts +0 -5
- package/lib/shift.js +0 -17
- package/lib/shift.js.map +0 -1
- package/lib/text-color.d.ts +0 -4
- package/lib/text-color.js +0 -16
- package/lib/text-color.js.map +0 -1
- package/lib/types/index.d.ts +0 -46
- package/lib/types/index.js +0 -3
- package/lib/types/index.js.map +0 -1
- package/src/fade.ts +0 -30
- package/src/hex2hsl.ts +0 -10
- package/src/hex2rgb.ts +0 -15
- package/src/hsl2hex.ts +0 -13
- package/src/is-valid-hex.ts +0 -13
- package/src/rgb2hex.ts +0 -24
- package/src/shift.ts +0 -15
package/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# Colorizr
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/colorizr) [](https://bundlephobia.com/result?p=colorizr) [](https://github.com/gilbarbara/colorizr/actions/workflows/main.yml) [](https://www.npmjs.com/package/colorizr) [](https://bundlephobia.com/result?p=colorizr) [](https://github.com/gilbarbara/colorizr/actions/workflows/main.yml) [](https://sonarcloud.io/summary/new_code?id=gilbarbara_colorizr) [](https://sonarcloud.io/summary/new_code?id=gilbarbara_colorizr)
|
|
4
4
|
|
|
5
|
-
Color conversion, manipulation, comparison, and analysis.
|
|
5
|
+
Color conversion, generation, manipulation, comparison, and analysis.
|
|
6
6
|
|
|
7
7
|
## Highlights
|
|
8
8
|
|
|
9
|
-
- 🏖 **Easy to use**: Works with HSL
|
|
9
|
+
- 🏖 **Easy to use**: Works with Hex, HSL, OkLab, OkLCH, and RGB.
|
|
10
10
|
- ♿️ **Accessibility:** WCAG analysis and comparison.
|
|
11
|
-
- 🛠 **Small:** Less than
|
|
11
|
+
- 🛠 **Small:** Less than 7k (gzipped) and tree-shakable.
|
|
12
12
|
- 🟦 **Modern:** Written in Typescript.
|
|
13
13
|
|
|
14
14
|
## Setup
|
|
@@ -16,40 +16,47 @@ Color conversion, manipulation, comparison, and analysis.
|
|
|
16
16
|
**Install**
|
|
17
17
|
|
|
18
18
|
```bash
|
|
19
|
-
npm
|
|
19
|
+
npm i colorizr
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
## Usage
|
|
23
23
|
|
|
24
|
+
You can use all the functions standalone:
|
|
25
|
+
|
|
24
26
|
```typescript
|
|
25
27
|
import { luminance } from 'colorizr';
|
|
26
28
|
|
|
27
29
|
const lux = luminance('#ff0044'); // 0.2168
|
|
28
30
|
```
|
|
29
31
|
|
|
30
|
-
Or you can create an instance to
|
|
32
|
+
Or you can create an instance to use all the methods for the same color:
|
|
31
33
|
|
|
32
34
|
```typescript
|
|
33
35
|
import Colorizr from 'Colorizr';
|
|
34
36
|
|
|
35
|
-
const
|
|
37
|
+
const colorInstance = new Colorizr('#ff0044');
|
|
38
|
+
colorInstance.luminance; // 0.2168
|
|
39
|
+
colorInstance.chroma; // 1
|
|
40
|
+
colorInstance.opacity; // 1
|
|
36
41
|
```
|
|
37
42
|
|
|
38
|
-
##
|
|
43
|
+
## API
|
|
39
44
|
|
|
40
|
-
> String inputs accept css values: hex, rgb
|
|
45
|
+
> String inputs accept css values: hex, hsl, oklab, oklch, rgb, and named colors.
|
|
41
46
|
|
|
42
|
-
|
|
43
|
-
|
|
47
|
+
- [Info](#Info)
|
|
48
|
+
- [Manipulators](#Manipulators)
|
|
49
|
+
- [Converters](#Converters)
|
|
50
|
+
- [Generators](#Generators)
|
|
51
|
+
- [Comparison](#Comparison)
|
|
52
|
+
- [Utilities](#Utilities)
|
|
53
|
+
- [Validators](#Validators)
|
|
54
|
+
- [Class](#Class)
|
|
44
55
|
|
|
45
|
-
|
|
46
|
-
import { brightnessDifference } from 'colorizr';
|
|
47
|
-
|
|
48
|
-
brightnessDifference('#fff', 'rgb(255, 0, 68)'); // 171.003
|
|
49
|
-
```
|
|
56
|
+
### Info
|
|
50
57
|
|
|
51
58
|
**chroma(input: string): number**
|
|
52
|
-
|
|
59
|
+
Get the chroma of a color.
|
|
53
60
|
|
|
54
61
|
```typescript
|
|
55
62
|
import { chroma } from 'colorizr';
|
|
@@ -58,24 +65,148 @@ chroma('#ff0044'); // 1
|
|
|
58
65
|
chroma('#ffc0cb'); // 0.2471
|
|
59
66
|
```
|
|
60
67
|
|
|
68
|
+
**luminance(input: string): number**
|
|
69
|
+
Get the relative brightness according to the [WCAG definition](https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef).
|
|
70
|
+
Normalized to `0` for black and `1` for white.
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import { luminance } from 'colorizr';
|
|
74
|
+
|
|
75
|
+
luminance('#ff0044'); // 0.2168
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**name(input: string): string**
|
|
79
|
+
Get the name of a color. Return the hex code if it can't be named.
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { name } from 'colorizr';
|
|
83
|
+
|
|
84
|
+
name('#ffc0cb'); // pink
|
|
85
|
+
name('rgb(176 224 230)'); // 'powderblue'
|
|
86
|
+
name('hsl(344 100 50)'); // #ff0044
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**opacity(input: string): string**
|
|
90
|
+
Get the opacity of a color.
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { opacity } from 'colorizr';
|
|
94
|
+
|
|
95
|
+
opacity('#ff0044'); // 1
|
|
96
|
+
opacity('rgb(255 0 68 / 90%)'); // 0.9
|
|
97
|
+
opacity('hsl(344 100 50 / 60%)'); // 0.6
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Manipulators
|
|
101
|
+
|
|
102
|
+
**lighten(input: string, amount: number): string**
|
|
103
|
+
Get a color with increased lightness.
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { lighten } from 'colorizr';
|
|
107
|
+
|
|
108
|
+
lighten('#ff0044', 10); // #ff3369
|
|
109
|
+
lighten('hsl(136 100% 50%)', 10); // hsl(136 100% 60%)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
**darken(input: string, amount: number): string**
|
|
113
|
+
Get a color with decreased lightness.
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { darken } from 'colorizr';
|
|
117
|
+
|
|
118
|
+
darken('#ff0044', 10); // #cc0036
|
|
119
|
+
darken('oklch(47.642% 0.29956 274.93693)', 10); // oklch(40.377% 0.25281 275.46794)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**saturate(input: string, amount: number): string**
|
|
123
|
+
Get a color with increased saturation.
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
import { saturate } from 'colorizr';
|
|
127
|
+
|
|
128
|
+
saturate('#ff0044', 10); // #ff0044 (already at the maximum)
|
|
129
|
+
saturate('pink', 10); // #ffc0cb
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**desaturate(input: string, alpha: number): string**
|
|
133
|
+
Get a color with decreased saturation.
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
import { desaturate } from 'colorizr';
|
|
137
|
+
|
|
138
|
+
desaturate('#ff0044', 10); // #f20d4a
|
|
139
|
+
desaturate('oklab(70.622% 0.1374 0.14283)', 10); // oklab(69.021% 0.12176 0.13721)
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**invert(input: string): string**
|
|
143
|
+
Invert the color.
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import { invert } from 'colorizr';
|
|
147
|
+
|
|
148
|
+
invert('#07e'); // '#0077ee'
|
|
149
|
+
invert('#f058'); // '#ff005588'
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**rotate(input: string, degrees: number): string**
|
|
153
|
+
Get a color with a hue rotated by the specified degrees.
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import { rotate } from 'colorizr';
|
|
157
|
+
|
|
158
|
+
rotate('#ff0044', 30); // #ff3b00
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**opacify(input: string, alpha: number, format?: ColorType): string**
|
|
162
|
+
Add opacity to a color
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
import { opacify } from 'colorizr';
|
|
166
|
+
|
|
167
|
+
opacify('hsl(344, 100, 50)', 0.9); // hsl(344 100 50 / 90%)
|
|
168
|
+
opacify('#ff0044', 0.8); // #ff0044cc
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
**transparentize(input: string, alpha: number, format?: ColorType): string**
|
|
172
|
+
Increase/decrease the color opacity.
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
import { transparentize } from 'colorizr';
|
|
176
|
+
|
|
177
|
+
transparentize('hsl(344, 100, 50)', 10); // hsl(344 100 50 / 90%)
|
|
178
|
+
transparentize('#ff0044', 50, 'hsl'); // #ff004480
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Comparison
|
|
182
|
+
|
|
183
|
+
**brightnessDifference(left: string, right: string): number**
|
|
184
|
+
Get the brightness difference between the two colors.
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
import { brightnessDifference } from 'colorizr';
|
|
188
|
+
|
|
189
|
+
brightnessDifference('#fff', 'rgb(255, 0, 68)'); // 171.003
|
|
190
|
+
```
|
|
191
|
+
|
|
61
192
|
**colorDifference(left: string, right: string): number**
|
|
62
|
-
|
|
193
|
+
Get the color difference between the two colors.
|
|
63
194
|
|
|
64
195
|
```typescript
|
|
65
196
|
import { colorDifference } from 'colorizr';
|
|
66
197
|
|
|
67
|
-
colorDifference('hsl(0
|
|
198
|
+
colorDifference('hsl(0 0% 100%)', '#f04'); // 442
|
|
68
199
|
```
|
|
69
200
|
|
|
70
201
|
**compare(left: string, right: string): Analysis**
|
|
71
|
-
|
|
202
|
+
Get the WCAG analysis between two colors.
|
|
72
203
|
|
|
73
204
|
```typescript
|
|
74
205
|
import { compare } from 'colorizr';
|
|
75
206
|
|
|
76
207
|
compare('#ff0044', '#fff');
|
|
77
208
|
|
|
78
|
-
{
|
|
209
|
+
({
|
|
79
210
|
"brightnessDifference": 171.003,
|
|
80
211
|
"colorDifference": 442,
|
|
81
212
|
"compliant": 1,
|
|
@@ -84,77 +215,105 @@ compare('#ff0044', '#fff');
|
|
|
84
215
|
"largeAAA": false,
|
|
85
216
|
"normalAA": false,
|
|
86
217
|
"normalAAA": false,
|
|
87
|
-
}
|
|
218
|
+
})
|
|
88
219
|
```
|
|
89
220
|
|
|
90
221
|
**contrast(left: string, right: string): number**
|
|
91
|
-
|
|
222
|
+
Get the WCAG contrast ratio between two colors.
|
|
92
223
|
|
|
93
224
|
```typescript
|
|
94
225
|
import { contrast } from 'colorizr';
|
|
95
226
|
|
|
96
|
-
contrast('hsl(0
|
|
227
|
+
contrast('hsl(0 0% 100%)', 'rgb(255 0 68)'); // 3.94
|
|
97
228
|
```
|
|
229
|
+
### Generators
|
|
98
230
|
|
|
99
|
-
**
|
|
100
|
-
|
|
231
|
+
**palette(input: string, options?: PaletteOptions): string[]**
|
|
232
|
+
Generate a palette of colors.
|
|
101
233
|
|
|
102
234
|
```typescript
|
|
103
|
-
import {
|
|
235
|
+
import { palette } from 'colorizr';
|
|
104
236
|
|
|
105
|
-
|
|
237
|
+
palette('#ff0044');
|
|
238
|
+
// ['#ff0044', '#ff7700', '#88ff00', '#00ff77', '#0088ff', '#7700ff'];
|
|
239
|
+
|
|
240
|
+
palette('#ff0044', { type: 'monochromatic' });
|
|
241
|
+
// ['#ff99b4', '#ff5582', '#ff1150', '#cc0036', '#880024', '#440012']
|
|
106
242
|
```
|
|
107
243
|
|
|
108
|
-
**
|
|
109
|
-
|
|
244
|
+
**scheme(input: string, type: Scheme): string[]**
|
|
245
|
+
Get a color scheme.
|
|
110
246
|
|
|
111
247
|
```typescript
|
|
112
|
-
import {
|
|
248
|
+
import { scheme } from 'colorizr';
|
|
113
249
|
|
|
114
|
-
|
|
250
|
+
const complementary = scheme('rgb(255 0 68)'); // ['#ff0044', '#00ffbb']
|
|
251
|
+
const triadic = scheme('#ff0044', 'triadic'); // ['#ff0044', '#44ff00', '#0044ff']
|
|
115
252
|
```
|
|
116
253
|
|
|
117
|
-
**
|
|
118
|
-
|
|
254
|
+
**swatch(input: string, variant?: 'up' | 'down'): string[]**
|
|
255
|
+
Generate a color swatch with ten shades.
|
|
256
|
+
The `variant` can be used to generate a lighter or darker swatch.
|
|
119
257
|
|
|
120
258
|
```typescript
|
|
121
|
-
import {
|
|
259
|
+
import { swatch } from 'colorizr';
|
|
122
260
|
|
|
123
|
-
|
|
124
|
-
|
|
261
|
+
const colors = swatch('#ff0044');
|
|
262
|
+
/* [
|
|
263
|
+
"#ffccda",
|
|
264
|
+
"#ff99b4",
|
|
265
|
+
"#ff668f",
|
|
266
|
+
"#ff3369",
|
|
267
|
+
"#ff0044",
|
|
268
|
+
"#cc0036",
|
|
269
|
+
"#990029",
|
|
270
|
+
"#66001b",
|
|
271
|
+
"#33000e",
|
|
272
|
+
"#1a0007",
|
|
273
|
+
] */
|
|
125
274
|
```
|
|
126
275
|
|
|
127
|
-
|
|
128
|
-
|
|
276
|
+
### Converters
|
|
277
|
+
|
|
278
|
+
**convert(input: string, format: ColorType): string**
|
|
279
|
+
Convert a color string to another format.
|
|
129
280
|
|
|
130
281
|
```typescript
|
|
131
|
-
import {
|
|
282
|
+
import { convert } from 'colorizr';
|
|
132
283
|
|
|
133
|
-
|
|
134
|
-
|
|
284
|
+
convert('#ff0044', 'hsl') // hsl(344 100% 50%)
|
|
285
|
+
convert('rgb(255 0 68)', 'oklch') // oklch(63.269% 0.25404 19.90218)
|
|
135
286
|
```
|
|
136
287
|
|
|
137
|
-
**
|
|
138
|
-
|
|
288
|
+
**hex2hsl(input: string): HSL**
|
|
289
|
+
Convert HEX to HSL.
|
|
139
290
|
|
|
140
291
|
```typescript
|
|
141
|
-
import {
|
|
292
|
+
import { hex2hsl } from 'colorizr';
|
|
142
293
|
|
|
143
|
-
|
|
144
|
-
formatHex('#f058'); // '#ff005588'
|
|
294
|
+
hex2hsl('#ff0044'); // { h: 344, s: 100, l: 50 }
|
|
145
295
|
```
|
|
146
296
|
|
|
147
|
-
**
|
|
148
|
-
|
|
297
|
+
**hex2oklab(input: string, precision?: number): LAB**
|
|
298
|
+
Convert HEX to OKLAB.
|
|
149
299
|
|
|
150
300
|
```typescript
|
|
151
|
-
import {
|
|
301
|
+
import { hex2oklab } from 'colorizr';
|
|
152
302
|
|
|
153
|
-
|
|
303
|
+
hex2oklab('#ff0044'); // { l: 0.63269, a: 0.23887, b: 0.08648 }
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
**hex2oklch(input: string, precision?: number): LCH**
|
|
307
|
+
Convert HEX to OKLCH.
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
import { hex2oklch } from 'colorizr';
|
|
311
|
+
|
|
312
|
+
hex2oklch('#ff0044'); // { l: 0.63269, c: 0.25404, h: 19.90218 }
|
|
154
313
|
```
|
|
155
314
|
|
|
156
315
|
**hex2rgb(input: string): RGB**
|
|
157
|
-
|
|
316
|
+
Convert HEX to RGB.
|
|
158
317
|
|
|
159
318
|
```typescript
|
|
160
319
|
import { hex2rgb } from 'colorizr';
|
|
@@ -162,161 +321,261 @@ import { hex2rgb } from 'colorizr';
|
|
|
162
321
|
hex2rgb('#ff0044'); // { r: 255, g: 0, b: 68 }
|
|
163
322
|
```
|
|
164
323
|
|
|
165
|
-
**hsl2hex(input: HSL): string**
|
|
166
|
-
|
|
324
|
+
**hsl2hex(input: HSL | ColorTuple): string**
|
|
325
|
+
Convert HSL to HEX.
|
|
167
326
|
|
|
168
327
|
```typescript
|
|
169
328
|
import { hsl2hex } from 'colorizr';
|
|
170
329
|
|
|
171
330
|
hsl2hex({ h: 344, s: 100, l: 50 }); // '#ff0044'
|
|
331
|
+
hsl2hex([344, 100, 50]); // '#ff0044'
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
**hsl2oklab(input: HSL | ColorTuple, precision?: number): LAB**
|
|
335
|
+
Convert HSL to OKLAB.
|
|
336
|
+
|
|
337
|
+
```typescript
|
|
338
|
+
import { hsl2oklab } from 'colorizr';
|
|
339
|
+
|
|
340
|
+
hsl2oklab({ h: 344, s: 100, l: 50 }); // { l: 0.63269, a: 0.23887, b: 0.08648 }
|
|
341
|
+
hsl2oklab([344, 100, 50]); // { l: 0.63269, a: 0.23887, b: 0.08648 }
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
**hsl2oklch(input: HSL | ColorTuple, precision?: number): LCH**
|
|
345
|
+
Convert HSL to OKLCH.
|
|
346
|
+
|
|
347
|
+
```typescript
|
|
348
|
+
import { hsl2oklch } from 'colorizr';
|
|
349
|
+
|
|
350
|
+
hsl2oklch({ h: 344, s: 100, l: 50 }); // { l: 0.63269, c: 0.25404, h: 19.90218 }
|
|
351
|
+
hsl2oklch([344, 100, 50]); // { l: 0.63269, c: 0.25404, h: 19.90218 }
|
|
172
352
|
```
|
|
173
353
|
|
|
174
|
-
**hsl2rgb(input: HSL): RGB**
|
|
175
|
-
|
|
354
|
+
**hsl2rgb(input: HSL | ColorTuple): RGB**
|
|
355
|
+
Convert HSL to RGB.
|
|
176
356
|
|
|
177
357
|
```typescript
|
|
178
358
|
import { hsl2rgb } from 'colorizr';
|
|
179
359
|
|
|
180
360
|
hsl2rgb({ h: 344, s: 100, l: 50 }); // { r: 255, g: 0, b: 68 }
|
|
361
|
+
hsl2rgb([344, 100, 50]); // { r: 255, g: 0, b: 68 }
|
|
181
362
|
```
|
|
182
363
|
|
|
183
|
-
**
|
|
184
|
-
|
|
364
|
+
**oklab2hex(input: LAB | ColorTuple): string**
|
|
365
|
+
Convert OKLAB to HEX.
|
|
185
366
|
|
|
186
367
|
```typescript
|
|
187
|
-
import {
|
|
368
|
+
import { oklab2hex } from 'colorizr';
|
|
188
369
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
isValidColor('#ff004400'); // true
|
|
192
|
-
isValidColor('rgb(100, 255, 0)'); // true
|
|
193
|
-
isValidColor('hsla(344, 100%, 50%)'); // true
|
|
194
|
-
isValidColor('blue'); // true
|
|
195
|
-
isValidColor('aliceblue'); // true
|
|
196
|
-
isValidColor('#mmff00'); // false
|
|
197
|
-
isValidColor('blue-ish'); // false
|
|
370
|
+
oklab2hex({ l: 0.63269, a: 0.23887, b: 0.08648 }); // '#ff0044'
|
|
371
|
+
oklab2hex([0.63269, 0.23887, 0.08648]); // '#ff0044'
|
|
198
372
|
```
|
|
199
373
|
|
|
200
|
-
**
|
|
201
|
-
|
|
374
|
+
**oklab2hsl(input: LAB | ColorTuple): HSL**
|
|
375
|
+
Convert OKLAB to HSL.
|
|
202
376
|
|
|
203
377
|
```typescript
|
|
204
|
-
import {
|
|
378
|
+
import { oklab2hsl } from 'colorizr';
|
|
205
379
|
|
|
206
|
-
|
|
380
|
+
oklab2hsl({ l: 0.63269, a: 0.23887, b: 0.08648 }); // { h: 344, s: 100, l: 50 }
|
|
381
|
+
oklab2hsl([0.63269, 0.23887, 0.08648]); // { h: 344, s: 100, l: 50 }
|
|
207
382
|
```
|
|
208
383
|
|
|
209
|
-
**
|
|
210
|
-
|
|
384
|
+
**oklab2oklch(input: LAB | ColorTuple, precision?: number): LCH**
|
|
385
|
+
Convert OKLAB to OKLCH.
|
|
211
386
|
|
|
212
387
|
```typescript
|
|
213
|
-
import {
|
|
388
|
+
import { oklab2oklch } from 'colorizr';
|
|
214
389
|
|
|
215
|
-
|
|
390
|
+
oklab2oklch({ l: 0.63269, a: 0.23887, b: 0.08648 }); // { l: 0.63269, c: 0.25404, h: 19.90218 }
|
|
391
|
+
oklab2oklch([0.63269, 0.23887, 0.08648]); // { l: 0.63269, c: 0.25404, h: 19.90218 }
|
|
216
392
|
```
|
|
217
393
|
|
|
218
|
-
**
|
|
219
|
-
|
|
394
|
+
**oklab2rgb(input: LAB | ColorTuple, precision: number = 0): RGB**
|
|
395
|
+
Convert OKLAB to RGB.
|
|
220
396
|
|
|
221
397
|
```typescript
|
|
222
|
-
import {
|
|
398
|
+
import { oklab2rgb } from 'colorizr';
|
|
223
399
|
|
|
224
|
-
|
|
400
|
+
oklab2rgb({ l: 0.63269, a: 0.23887, b: 0.08648 }); // { r: 255, g: 0, b: 68 }
|
|
401
|
+
oklab2rgb([0.63269, 0.23887, 0.08648]); // { r: 255, g: 0, b: 68 }
|
|
225
402
|
```
|
|
226
403
|
|
|
227
|
-
**
|
|
228
|
-
|
|
404
|
+
**oklch2hex(input: LCH | ColorTuple): string**
|
|
405
|
+
Convert OKLCH to HEX.
|
|
229
406
|
|
|
230
407
|
```typescript
|
|
231
|
-
import {
|
|
408
|
+
import { oklch2hex } from 'colorizr';
|
|
232
409
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
name('hsl(344, 100, 50)'); // #ff0044
|
|
410
|
+
oklch2hex({ l: 0.63269, c: 0.25404, h: 19.90218 }); // '#ff0044'
|
|
411
|
+
oklch2hex([0.63269, 0.25404, 19.90218]); // '#ff0044'
|
|
236
412
|
```
|
|
237
413
|
|
|
238
|
-
**
|
|
239
|
-
|
|
414
|
+
**oklch2hsl(input: LCH | ColorTuple): HSL**
|
|
415
|
+
Convert OKLCH to HSL.
|
|
240
416
|
|
|
241
417
|
```typescript
|
|
242
|
-
import {
|
|
418
|
+
import { oklch2hsl } from 'colorizr';
|
|
243
419
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
palette('#ff0044', { type: 'monochromatic' });
|
|
248
|
-
// ['#ff99b4', '#ff5582', '#ff1150', '#cc0036', '#880024', '#440012']
|
|
420
|
+
oklch2hsl({ l: 0.63269, c: 0.25404, h: 19.90218 }); // { h: 344, s: 100, l: 50 }
|
|
421
|
+
oklch2hsl([0.63269, 0.25404, 19.90218]); // { h: 344, s: 100, l: 50 }
|
|
249
422
|
```
|
|
250
423
|
|
|
251
|
-
**
|
|
252
|
-
|
|
424
|
+
**oklch2oklab(input: LCH | ColorTuple, precision?: number): LAB**
|
|
425
|
+
Convert OKLCH to OKLAB.
|
|
253
426
|
|
|
254
427
|
```typescript
|
|
255
|
-
import {
|
|
428
|
+
import { oklch2oklab } from 'colorizr';
|
|
256
429
|
|
|
257
|
-
|
|
258
|
-
|
|
430
|
+
oklch2oklab({ l: 0.63269, c: 0.25404, h: 19.90218 }); // { l: 0.63269, a: 0.23887, b: 0.08648 }
|
|
431
|
+
oklch2oklab([0.63269, 0.25404, 19.90218]); // { l: 0.63269, a: 0.23887, b: 0.08648 }
|
|
259
432
|
```
|
|
260
433
|
|
|
261
|
-
**
|
|
262
|
-
|
|
434
|
+
**oklch2rgb(input: LCH | ColorTuple, precision: number = 0): RGB**
|
|
435
|
+
Convert OKLCH to RGB.
|
|
263
436
|
|
|
264
437
|
```typescript
|
|
265
|
-
import {
|
|
438
|
+
import { oklch2rgb } from 'colorizr';
|
|
266
439
|
|
|
267
|
-
|
|
440
|
+
oklch2rgb({ l: 0.63269, c: 0.25404, h: 19.90218 }); // { r: 255, g: 0, b: 68 }
|
|
441
|
+
oklch2rgb([0.63269, 0.25404, 19.90218]); // { r: 255, g: 0, b: 68 }
|
|
268
442
|
```
|
|
269
443
|
|
|
270
|
-
**rgb2hex(input: RGB |
|
|
271
|
-
|
|
444
|
+
**rgb2hex(input: RGB | ColorTuple): string**
|
|
445
|
+
Convert RGB to HEX.
|
|
272
446
|
|
|
273
447
|
```typescript
|
|
274
448
|
import { rgb2hex } from 'colorizr';
|
|
275
449
|
|
|
276
|
-
rgb2hex({ r: 255, g:
|
|
450
|
+
rgb2hex({ r: 255, g: 0, b: 68 }); // '#ff0044'
|
|
277
451
|
rgb2hex([255, 0, 68]); // '#ff0044'
|
|
278
452
|
```
|
|
279
453
|
|
|
280
|
-
**rgb2hsl(input: RGB |
|
|
281
|
-
|
|
454
|
+
**rgb2hsl(input: RGB | ColorTuple): HSL**
|
|
455
|
+
Convert RGB to HSL.
|
|
282
456
|
|
|
283
457
|
```typescript
|
|
284
458
|
import { rgb2hsl } from 'colorizr';
|
|
285
459
|
|
|
286
|
-
rgb2hsl({ r: 255, g:
|
|
460
|
+
rgb2hsl({ r: 255, g: 0, b: 68 }); // { h: 344, s: 100, l: 50 }
|
|
287
461
|
rgb2hsl([255, 0, 68]); // { h: 344, s: 100, l: 50 }
|
|
288
462
|
```
|
|
289
463
|
|
|
290
|
-
**
|
|
464
|
+
**rgb2oklab(input: RGB | ColorTuple, precision: number): LAB**
|
|
465
|
+
Convert RGB to OKLAB.
|
|
291
466
|
|
|
292
467
|
```typescript
|
|
293
|
-
import {
|
|
468
|
+
import { rgb2oklab } from 'colorizr';
|
|
294
469
|
|
|
295
|
-
|
|
470
|
+
rgb2oklab({ r: 255, g: 0, b: 68 }); // { l: 0.63269, a: 0.23887, b: 0.08648 }
|
|
471
|
+
rgb2oklab([255, 0, 68]); // { l: 0.63269, a: 0.23887, b: 0.08648 }
|
|
296
472
|
```
|
|
297
473
|
|
|
298
|
-
**
|
|
299
|
-
|
|
474
|
+
**rgb2oklch(input: RGB | ColorTuple, precision: number): LCH**
|
|
475
|
+
Convert RGB to OKLCH.
|
|
300
476
|
|
|
301
477
|
```typescript
|
|
302
|
-
import {
|
|
478
|
+
import { rgb2oklch } from 'colorizr';
|
|
303
479
|
|
|
304
|
-
|
|
305
|
-
|
|
480
|
+
rgb2oklch({ r: 255, g: 0, b: 68 }); // { l: 0.63269, c: 0.25404, h: 19.90218 }
|
|
481
|
+
rgb2oklch([255, 0, 68]); // { l: 0.63269, c: 0.25404, h: 19.90218 }
|
|
306
482
|
```
|
|
307
483
|
|
|
308
|
-
|
|
309
|
-
|
|
484
|
+
### Utilities
|
|
485
|
+
|
|
486
|
+
**addAlphaToHex(input: string, alpha: number): string**
|
|
487
|
+
Add an alpha value to a hex string
|
|
310
488
|
|
|
311
489
|
```typescript
|
|
312
|
-
import {
|
|
490
|
+
import { addAlphaToHex } from 'colorizr';
|
|
313
491
|
|
|
314
|
-
|
|
315
|
-
|
|
492
|
+
addAlphaToHex('#ff0044', 0.9); // '#ff0044e6'
|
|
493
|
+
addAlphaToHex('#ff0044cc', 0.9); // '#ff0044e6'
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
**convertAlphaToHex(input: number): string**
|
|
497
|
+
Convert an alpha value to a hex value.
|
|
498
|
+
|
|
499
|
+
```typescript
|
|
500
|
+
import { convertAlphaToHex } from 'colorizr';
|
|
501
|
+
|
|
502
|
+
convertAlphaToHex(0.5); // '80'
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
**extractAlphaFromHex(input: string): number**
|
|
506
|
+
Extract the alpha value from a hex string
|
|
507
|
+
|
|
508
|
+
```typescript
|
|
509
|
+
import { extractAlphaFromHex } from 'colorizr';
|
|
510
|
+
|
|
511
|
+
convertAlphaToHex('#ff004480'); // 0.5
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
**extractColorParts(input: string): ExtractColorPartsReturn**
|
|
515
|
+
Extract the color parts from a CSS color string.
|
|
516
|
+
Hex colors are not supported.
|
|
517
|
+
|
|
518
|
+
```typescript
|
|
519
|
+
type ExtractColorPartsReturn = {
|
|
520
|
+
alpha?: number;
|
|
521
|
+
model: 'hsl' | 'oklab' | 'oklch' | 'rgb';
|
|
522
|
+
} & Record<string, number>;
|
|
523
|
+
|
|
524
|
+
extractColorParts('rgb(255 0 68)') // { model: 'rgb', r: 255, g: 0, b: 68 }
|
|
525
|
+
extractColorParts('hsl(344 100% 50% / 90%)') // { alpha: 0.9, model: 'hsl', h: 344, g: 100, l: 50 }
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
**formatCSS(input: HSL | RGB, options?: FormatOptions): string**
|
|
529
|
+
Get a css string from a color object.
|
|
530
|
+
|
|
531
|
+
```typescript
|
|
532
|
+
import { formatCSS } from 'colorizr';
|
|
533
|
+
|
|
534
|
+
formatCSS({ h: 344, s: 100, l: 50 }, { format: 'rgb' }); // 'rgb(255, 0, 68)'
|
|
535
|
+
formatCSS({ r: 255, g: 0, b: 68 }, { alpha: 0.5, format: 'hsl' }); // 'hsla(344, 100%, 50%, 0.5)'
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
**formatHex(input: string): string**
|
|
539
|
+
Format a short hex string of 3 (or 4) digits into 6 (or 8) digits.
|
|
540
|
+
|
|
541
|
+
```typescript
|
|
542
|
+
import { formatHex } from 'colorizr';
|
|
543
|
+
|
|
544
|
+
formatHex('#07e'); // '#0077ee'
|
|
545
|
+
formatHex('#f058'); // '#ff005588'
|
|
546
|
+
```
|
|
547
|
+
**parseCSS(input: string, format?: ColorType): string | HSL | RGB**
|
|
548
|
+
Parse a css string to hex, HSL, OKLAB, OKLCH, or RGB.
|
|
549
|
+
If the format isn't set, it will return the same format as the input.
|
|
550
|
+
|
|
551
|
+
```typescript
|
|
552
|
+
import { parseCSS } from 'colorizr';
|
|
553
|
+
|
|
554
|
+
parseCSS('hsl(344 100% 50%)'); // { h: 344, l: 50, s: 100 }
|
|
555
|
+
parseCSS('#ff0044', 'hsl'); // { h: 344, l: 50, s: 100 }
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
**random(type: ColorType = 'hex'): string**
|
|
559
|
+
Get a random color.
|
|
560
|
+
|
|
561
|
+
```typescript
|
|
562
|
+
import { random } from 'colorizr';
|
|
563
|
+
|
|
564
|
+
random(); // '#b385e0'
|
|
565
|
+
random('oklch') // oklab(86.876% -0.22518 0.1597)
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
**removeAlphaFromHex(input: string): string**
|
|
569
|
+
Remove the alpha value from a hex string
|
|
570
|
+
|
|
571
|
+
```typescript
|
|
572
|
+
import { removeAlphaFromHex } from 'colorizr';
|
|
573
|
+
|
|
574
|
+
removeAlphaFromHex('#ff0044cc'); // '#ff0044'
|
|
316
575
|
```
|
|
317
576
|
|
|
318
577
|
**textColor(input: string): string**
|
|
319
|
-
|
|
578
|
+
Get a contrasting color (black or white) for the input color.
|
|
320
579
|
|
|
321
580
|
```typescript
|
|
322
581
|
import { textColor } from 'colorizr';
|
|
@@ -325,7 +584,75 @@ textColor('#ff0044'); // #ffffff
|
|
|
325
584
|
textColor('#fff800'); // #000000
|
|
326
585
|
```
|
|
327
586
|
|
|
328
|
-
|
|
587
|
+
### Validators
|
|
588
|
+
|
|
589
|
+
**isValidColor(input: any): boolean**
|
|
590
|
+
Check if the input is a valid color.
|
|
591
|
+
|
|
592
|
+
```typescript
|
|
593
|
+
import { isValidColor } from 'colorizr';
|
|
594
|
+
|
|
595
|
+
isValidColor('#ff0044'); // true
|
|
596
|
+
isValidColor('#ff004400'); // true
|
|
597
|
+
isValidColor('hsl(136 100% 50%)'); // true
|
|
598
|
+
isValidColor('hsla(344, 100%, 50%, 0.4)'); // true
|
|
599
|
+
isValidColor('oklab(70.622% 0.1374 0.14283)'); // true
|
|
600
|
+
isValidColor('oklch(47.642% 0.29956 274.93693)'); // true
|
|
601
|
+
isValidColor('rgb(255 230 109)'); // true
|
|
602
|
+
isValidColor('blue'); // true
|
|
603
|
+
isValidColor('aliceblue'); // true
|
|
604
|
+
isValidColor('#mmff00'); // false
|
|
605
|
+
isValidColor('blue-ish'); // false
|
|
606
|
+
```
|
|
607
|
+
|
|
608
|
+
**isHex(input: unknown): boolean**
|
|
609
|
+
Check if the input is a valid hex color.
|
|
610
|
+
|
|
611
|
+
```typescript
|
|
612
|
+
import { isHex } from 'colorizr';
|
|
613
|
+
|
|
614
|
+
isHex('#f04'); // true
|
|
615
|
+
isHex('#ff0044'); // true
|
|
616
|
+
isHex('#ff0044cc'); // true
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
**isHSL(input: unknown): boolean**
|
|
620
|
+
Check if the input is a valid HSL object.
|
|
621
|
+
|
|
622
|
+
```typescript
|
|
623
|
+
import { isHSL } from 'colorizr';
|
|
624
|
+
|
|
625
|
+
isHSL({ h: 344, s: 100, l: 50 }); // true
|
|
626
|
+
```
|
|
627
|
+
|
|
628
|
+
**isLAB(input: unknown): boolean**
|
|
629
|
+
Check if the input is a valid LAB color.
|
|
630
|
+
|
|
631
|
+
```typescript
|
|
632
|
+
import { isLAB } from 'colorizr';
|
|
633
|
+
|
|
634
|
+
isLAB({ l: 0.63269, a: 0.23887, b: 0.08648 }); // true
|
|
635
|
+
```
|
|
636
|
+
|
|
637
|
+
**isLHC(input: unknown): boolean**
|
|
638
|
+
Check if the input is a valid LCH color.
|
|
639
|
+
|
|
640
|
+
```typescript
|
|
641
|
+
import { isLHC } from 'colorizr';
|
|
642
|
+
|
|
643
|
+
isLHC({ l: 0.63269, c: 0.25404, h: 19.90218 }); // true
|
|
644
|
+
```
|
|
645
|
+
|
|
646
|
+
**isRGB(input: unknown): boolean**
|
|
647
|
+
Check if the input is a valid RGB color.
|
|
648
|
+
|
|
649
|
+
```typescript
|
|
650
|
+
import { isRGB } from 'colorizr';
|
|
651
|
+
|
|
652
|
+
isRGB({ r: 255, g: 0, b: 68 }); // true
|
|
653
|
+
```
|
|
654
|
+
|
|
655
|
+
### Class
|
|
329
656
|
|
|
330
657
|
```typescript
|
|
331
658
|
import Colorizr from 'Colorizr';
|
|
@@ -337,65 +664,72 @@ colorizr.hsl; // { h: 344, s: 100, l: 50 };
|
|
|
337
664
|
colorizr.rgb; // { r: 255, g: 0, b: 68 };
|
|
338
665
|
```
|
|
339
666
|
|
|
340
|
-
|
|
667
|
+
#### Getters
|
|
341
668
|
|
|
342
669
|
**colorizr.hex**
|
|
343
|
-
|
|
670
|
+
Get the hex code.
|
|
344
671
|
|
|
345
672
|
**colorizr.hsl**
|
|
346
|
-
|
|
673
|
+
Get the HSL object.
|
|
674
|
+
|
|
675
|
+
**colorizr.oklab**
|
|
676
|
+
Get the OKLAB object.
|
|
677
|
+
|
|
678
|
+
**colorizr.oklch**
|
|
679
|
+
Get the OKLCH object.
|
|
347
680
|
|
|
348
681
|
**colorizr.rgb**
|
|
349
|
-
|
|
682
|
+
Get the RGB object.
|
|
350
683
|
|
|
351
684
|
**colorizr.hue**
|
|
352
|
-
|
|
685
|
+
Get the hue (0-360).
|
|
353
686
|
|
|
354
687
|
**colorizr.saturation**
|
|
355
|
-
|
|
688
|
+
Get the saturation (0-100).
|
|
356
689
|
|
|
357
690
|
**colorizr.lightness**
|
|
358
|
-
|
|
691
|
+
Get the lightness (0-100).
|
|
359
692
|
|
|
360
693
|
**colorizr.red**
|
|
361
|
-
|
|
694
|
+
Get the red level (0-255).
|
|
362
695
|
|
|
363
696
|
**colorizr.green**
|
|
364
|
-
|
|
697
|
+
Get the green level (0-255).
|
|
365
698
|
|
|
366
699
|
**colorizr.blue**
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
**colorizr.luminance**
|
|
700
|
+
Get the blue level (0-255).
|
|
370
701
|
|
|
371
702
|
**colorizr.chroma**
|
|
703
|
+
Get the chroma (0-1).
|
|
372
704
|
|
|
373
|
-
**colorizr.
|
|
374
|
-
|
|
375
|
-
### Manipulation
|
|
376
|
-
|
|
377
|
-
**colorizr.lighten(percentage = 10)**
|
|
705
|
+
**colorizr.luminance**
|
|
706
|
+
Get the luminance (0-1).
|
|
378
707
|
|
|
379
|
-
**colorizr.
|
|
708
|
+
**colorizr.opacity**
|
|
709
|
+
Get the opacity (0-1).
|
|
380
710
|
|
|
381
|
-
**colorizr.
|
|
711
|
+
**colorizr.css**
|
|
712
|
+
Get the css string of the same type as the input.
|
|
382
713
|
|
|
383
|
-
**colorizr.
|
|
384
|
-
|
|
385
|
-
**colorizr.rotate(degrees = 15)**
|
|
714
|
+
**colorizr.textColor**
|
|
715
|
+
Get a contrasting color (black or white).
|
|
386
716
|
|
|
387
|
-
|
|
717
|
+
#### Methods
|
|
388
718
|
|
|
389
|
-
**colorizr.
|
|
719
|
+
**colorizr.format(type: ColorType, precision?: number)**
|
|
720
|
+
Returns the formatted color with the type
|
|
390
721
|
|
|
391
|
-
|
|
722
|
+
...
|
|
392
723
|
|
|
393
|
-
|
|
394
|
-
_returns an object with the analysis (check the compare output above)_
|
|
724
|
+
Also, all the [manipulators](#Manipulators) and [comparison](#Comparison) utilities.
|
|
395
725
|
|
|
396
|
-
## References
|
|
726
|
+
## Credits / References
|
|
397
727
|
|
|
728
|
+
[color.js](https://github.com/color-js/color.js)
|
|
729
|
+
[chroma-js](https://gka.github.io/chroma.js/)
|
|
398
730
|
[calculating-color-contrast](https://24ways.org/2010/calculating-color-contrast/)
|
|
399
731
|
[Colour Contrast Check](https://snook.ca/technical/colour_contrast/colour.html)
|
|
400
732
|
[Contrast Checker](https://webaim.org/resources/contrastchecker/)
|
|
401
|
-
[Converting Color Spaces in typescript](https://css-tricks.com/converting-color-spaces-in-typescript/)
|
|
733
|
+
[Converting Color Spaces in typescript](https://css-tricks.com/converting-color-spaces-in-typescript/)
|
|
734
|
+
[A perceptual color space for image processing](https://bottosson.github.io/posts/oklab/)
|
|
735
|
+
|