Skip to content

Commit 4ab54f6

Browse files
committed
Detect colorspace
1 parent 6460130 commit 4ab54f6

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/color.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ export default class Color {
44
constructor(color) {
55
this.color = Object(Object(color).color || color);
66

7+
this.color.colorspace = this.color.colorspace
8+
? this.color.colorspace
9+
: 'red' in color && 'green' in color && 'blue' in color
10+
? 'rgb'
11+
: 'hue' in color && 'saturation' in color && 'lightness' in color
12+
? 'hsl'
13+
: 'hue' in color && 'whiteness' in color && 'blackness' in color
14+
? 'hwb'
15+
: 'unknown';
16+
717
if (color.colorspace === 'rgb') {
818
this.color.hue = rgb2hue(color.red, color.green, color.blue, color.hue || 0);
919
}

0 commit comments

Comments
 (0)