/
hwb-extended.ts
68 lines (64 loc) · 1.85 KB
/
hwb-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
import { ModelType } from '../types/base';
import KeyedSpace from '../types/keyed-spaced';
import Converter from '../utils/converter/converter';
import HWBSpace from '../hwb/hwb-space';
import HWBColorSpace from '../hwb/types/hwb-color-space';
import hwbConverter from '../utils/converter/hwb-converter';
import { ExtendedHSLSpace } from './hsl-extended';
import { ExtendedHSVSpace } from './hsv-extended';
import { ExtendedRGBASpace } from './rgba-extended';
import { toColorSpace } from '../space-extender';
export class ExtendedHWBSpace extends HWBSpace {
/**
* @inheritDoc
*/
public clone(): ExtendedHWBSpace {
return new ExtendedHWBSpace(this.model);
}
/**
* @inheritDoc
*/
public applyModel(model: HWBColorSpace): ExtendedHWBSpace {
super.applyModel(model);
return this;
}
/**
* @inheritDoc
*/
public setColor(
color: keyof HWBColorSpace,
value: number
): ExtendedHWBSpace {
super.setColor(color, value);
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,
ExtendedHSVSpace,
null,
ExtendedHSLSpace,
ExtendedRGBASpace
> {
return toColorSpace<
HWBColorSpace,
T,
Converter<HWBColorSpace>,
ExtendedHSVSpace,
null,
ExtendedHSLSpace,
ExtendedRGBASpace
>(this.model, hwbConverter, space, {
HSL: ExtendedHSLSpace,
HSV: ExtendedHSVSpace,
RGBA: ExtendedRGBASpace,
});
}
}