UNPKG

3.77 kBTypeScriptView Raw
1import {Value} from './index';
2
3/**
4 * Sass's [color type](https://sass-lang.com/documentation/values/colors).
5 *
6 * No matter what representation was originally used to create this color, all
7 * of its channels are accessible.
8 *
9 * @category Custom Function
10 */
11export class SassColor extends Value {
12 /**
13 * Creates an RGB color.
14 *
15 * **Only** `undefined` should be passed to indicate a missing `alpha`. If
16 * `null` is passed instead, it will be treated as a [missing component] in
17 * future versions of Dart Sass. See [breaking changes] for details.
18 *
19 * [missing component]: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#missing_color_components
20 * [breaking changes]: /documentation/breaking-changes/null-alpha
21 *
22 * @throws `Error` if `red`, `green`, and `blue` aren't between `0` and
23 * `255`, or if `alpha` isn't between `0` and `1`.
24 */
25 constructor(options: {
26 red: number;
27 green: number;
28 blue: number;
29 alpha?: number;
30 });
31
32 /**
33 * Creates an HSL color.
34 *
35 * **Only** `undefined` should be passed to indicate a missing `alpha`. If
36 * `null` is passed instead, it will be treated as a [missing component] in
37 * future versions of Dart Sass. See [breaking changes] for details.
38 *
39 * [missing component]: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#missing_color_components
40 * [breaking changes]: /documentation/breaking-changes/null-alpha
41 *
42 * @throws `Error` if `saturation` or `lightness` aren't between `0` and
43 * `100`, or if `alpha` isn't between `0` and `1`.
44 */
45 constructor(options: {
46 hue: number;
47 saturation: number;
48 lightness: number;
49 alpha?: number;
50 });
51
52 /**
53 * Creates an HWB color.
54 *
55 * **Only** `undefined` should be passed to indicate a missing `alpha`. If
56 * `null` is passed instead, it will be treated as a [missing component] in
57 * future versions of Dart Sass. See [breaking changes] for details.
58 *
59 * [missing component]: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#missing_color_components
60 * [breaking changes]: /documentation/breaking-changes/null-alpha
61 *
62 * @throws `Error` if `whiteness` or `blackness` aren't between `0` and `100`,
63 * or if `alpha` isn't between `0` and `1`.
64 */
65 constructor(options: {
66 hue: number;
67 whiteness: number;
68 blackness: number;
69 alpha?: number;
70 });
71
72 /** This color's red channel, between `0` and `255`. */
73 get red(): number;
74
75 /** This color's green channel, between `0` and `255`. */
76 get green(): number;
77
78 /** This color's blue channel, between `0` and `255`. */
79 get blue(): number;
80
81 /** This color's hue, between `0` and `360`. */
82 get hue(): number;
83
84 /** This color's saturation, between `0` and `100`. */
85 get saturation(): number;
86
87 /** This color's lightness, between `0` and `100`. */
88 get lightness(): number;
89
90 /** This color's whiteness, between `0` and `100`. */
91 get whiteness(): number;
92
93 /** This color's blackness, between `0` and `100`. */
94 get blackness(): number;
95
96 /** This color's alpha channel, between `0` and `1`. */
97 get alpha(): number;
98
99 /**
100 * Changes one or more of this color's RGB channels and returns the result.
101 */
102 change(options: {
103 red?: number;
104 green?: number;
105 blue?: number;
106 alpha?: number;
107 }): SassColor;
108
109 /**
110 * Changes one or more of this color's HSL channels and returns the result.
111 */
112 change(options: {
113 hue?: number;
114 saturation?: number;
115 lightness?: number;
116 alpha?: number;
117 }): SassColor;
118
119 /**
120 * Changes one or more of this color's HWB channels and returns the result.
121 */
122 change(options: {
123 hue?: number;
124 whiteness?: number;
125 blackness?: number;
126 alpha?: number;
127 }): SassColor;
128}