/
hsv-extended.ts
140 lines (127 loc) · 3.15 KB
/
hsv-extended.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
import { ModelType } from '../types/base';
import Converter from '../utils/converter/converter';
import KeyedSpace from '../types/keyed-spaced';
import HSVSpace from '../hsv/hsv-space';
import HSVColorSpace from '../hsv/types/hsv-color-space';
import hsvConverter from '../utils/converter/hsv-converter';
import { ExtendedRGBASpace } from './rgba-extended';
import { ExtendedHSLSpace } from './hsl-extended';
import { ExtendedHWBSpace } from './hwb-extended';
import { toColorSpace } from '../space-extender';
export class ExtendedHSVSpace extends HSVSpace {
/**
* @inheritDoc
*/
public blacken(ratio: number): ExtendedHSVSpace {
super.blacken(ratio);
return this;
}
/**
* @inheritDoc
*/
public clone(): ExtendedHSVSpace {
return new ExtendedHSVSpace(this.model);
}
/**
* @inheritDoc
*/
public darken(ratio: number): ExtendedHSVSpace {
super.darken(ratio);
return this;
}
/**
* @inheritDoc
*/
public desaturate(ratio: number): ExtendedHSVSpace {
super.desaturate(ratio);
return this;
}
/**
* @inheritDoc
*/
public applyModel(model: HSVColorSpace): ExtendedHSVSpace {
super.applyModel(model);
return this;
}
/**
* @inheritDoc
*/
public setColor(
color: keyof HSVColorSpace,
value: number
): ExtendedHSVSpace {
super.setColor(color, value);
return this;
}
/**
* @inheritDoc
*/
public grayscale(): ExtendedHSVSpace {
super.grayscale();
return this;
}
/**
* @inheritDoc
*/
public lighten(ratio: number): ExtendedHSVSpace {
super.lighten(ratio);
return this;
}
/**
* @inheritDoc
*/
public mix(color: HSVColorSpace, weight = 0.5): ExtendedHSVSpace {
super.mix(color, weight);
return this;
}
/**
* @inheritDoc
*/
public rotate(degrees: number): ExtendedHSVSpace {
super.rotate(degrees);
return this;
}
/**
* @inheritDoc
*/
public saturate(ratio: number): ExtendedHSVSpace {
super.saturate(ratio);
return this;
}
/**
* @inheritDoc
*/
public whiten(ratio: number): ExtendedHSVSpace {
super.whiten(ratio);
return this;
}
/**
* Converts the HSL color space to the model matching the provided key.
* @param space The color model to convert the space to
*
* @returns A new instance of the color space which matches the provided key otherwise `null`
*/
public toSpace<T extends ModelType>(
space: T
): KeyedSpace<
T,
null,
ExtendedHWBSpace,
ExtendedHSLSpace,
ExtendedRGBASpace
> {
return toColorSpace<
HSVColorSpace,
T,
Converter<HSVColorSpace>,
null,
ExtendedHWBSpace,
ExtendedHSLSpace,
ExtendedRGBASpace
>(this.model, hsvConverter, space, {
HSL: ExtendedHSLSpace,
HWB: ExtendedHWBSpace,
RGBA: ExtendedRGBASpace,
});
}
}