@sass/types 1.93.2

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.
@@ -0,0 +1,219 @@
1
+ import {List, ValueObject} from 'immutable';
2
+
3
+ import {SassBoolean} from './boolean';
4
+ import {SassCalculation} from './calculation';
5
+ import {SassColor} from './color';
6
+ import {SassFunction} from './function';
7
+ import {ListSeparator} from './list';
8
+ import {SassMap} from './map';
9
+ import {SassMixin} from './mixin';
10
+ import {SassNumber} from './number';
11
+ import {SassString} from './string';
12
+
13
+ export {SassArgumentList} from './argument_list';
14
+ export {SassBoolean, sassTrue, sassFalse} from './boolean';
15
+ export {
16
+ SassCalculation,
17
+ CalculationValue,
18
+ CalculationOperator,
19
+ CalculationOperation,
20
+ CalculationInterpolation,
21
+ } from './calculation';
22
+ export {
23
+ SassColor,
24
+ ColorSpaceHsl,
25
+ ChannelNameHsl,
26
+ ColorSpaceHwb,
27
+ ChannelNameHwb,
28
+ ColorSpaceLab,
29
+ ChannelNameLab,
30
+ ColorSpaceLch,
31
+ ChannelNameLch,
32
+ ColorSpaceRgb,
33
+ ChannelNameRgb,
34
+ ColorSpaceXyz,
35
+ ChannelNameXyz,
36
+ ChannelName,
37
+ GamutMapMethod,
38
+ KnownColorSpace,
39
+ PolarColorSpace,
40
+ RectangularColorSpace,
41
+ HueInterpolationMethod,
42
+ } from './color';
43
+ export {SassFunction} from './function';
44
+ export {SassList, ListSeparator} from './list';
45
+ export {SassMap} from './map';
46
+ export {SassMixin} from './mixin';
47
+ export {SassNumber} from './number';
48
+ export {SassString} from './string';
49
+
50
+ /**
51
+ * Sass's [`null` value](https://sass-lang.com/documentation/values/null).
52
+ *
53
+ * @category Custom Function
54
+ */
55
+ export const sassNull: Value;
56
+
57
+ /**
58
+ * The abstract base class of Sass's value types.
59
+ *
60
+ * This is passed to and returned by {@link CustomFunction}s, which are passed
61
+ * into the Sass implementation using {@link Options.functions}.
62
+ *
63
+ * @category Custom Function
64
+ */
65
+ export abstract class Value implements ValueObject {
66
+ protected constructor();
67
+
68
+ /**
69
+ * This value as a list.
70
+ *
71
+ * All SassScript values can be used as lists. Maps count as lists of pairs,
72
+ * and all other values count as single-value lists.
73
+ *
74
+ * @returns An immutable {@link List} from the [`immutable`
75
+ * package](https://immutable-js.com/).
76
+ */
77
+ get asList(): List<Value>;
78
+
79
+ /**
80
+ * Whether this value as a list has brackets.
81
+ *
82
+ * All SassScript values can be used as lists. Maps count as lists of pairs,
83
+ * and all other values count as single-value lists.
84
+ */
85
+ get hasBrackets(): boolean;
86
+
87
+ /**
88
+ * Whether the value counts as `true` in an `@if` statement and other
89
+ * contexts.
90
+ */
91
+ get isTruthy(): boolean;
92
+
93
+ /**
94
+ * Returns JavaScript's `null` value if this is {@link sassNull}, and returns
95
+ * `this` otherwise.
96
+ */
97
+ get realNull(): null | Value;
98
+
99
+ /**
100
+ * The separator for this value as a list.
101
+ *
102
+ * All SassScript values can be used as lists. Maps count as lists of pairs,
103
+ * and all other values count as single-value lists.
104
+ */
105
+ get separator(): ListSeparator;
106
+
107
+ /**
108
+ * Converts `sassIndex` into a JavaScript-style index into the list returned
109
+ * by {@link asList}.
110
+ *
111
+ * Sass indexes are one-based, while JavaScript indexes are zero-based. Sass
112
+ * indexes may also be negative in order to index from the end of the list.
113
+ *
114
+ * @param sassIndex - The Sass-style index into this as a list.
115
+ * @param name - The name of the function argument `sassIndex` came from
116
+ * (without the `$`) if it came from an argument. Used for error reporting.
117
+ * @throws `Error` If `sassIndex` isn't a number, if that number isn't an
118
+ * integer, or if that integer isn't a valid index for {@link asList}.
119
+ */
120
+ sassIndexToListIndex(sassIndex: Value, name?: string): number;
121
+
122
+ /**
123
+ * Returns the value at index `index` in this value as a list, or `undefined`
124
+ * if `index` isn't valid for this list.
125
+ *
126
+ * All SassScript values can be used as lists. Maps count as lists of pairs,
127
+ * and all other values count as single-value lists.
128
+ *
129
+ * This is a shorthand for `this.asList.get(index)`, although it may be more
130
+ * efficient in some cases.
131
+ *
132
+ * **Heads up!** This method uses the same indexing conventions as the
133
+ * `immutable` package: unlike Sass the index of the first element is 0, but
134
+ * like Sass negative numbers index from the end of the list.
135
+ */
136
+ get(index: number): Value | undefined;
137
+
138
+ /**
139
+ * Throws if `this` isn't a {@link SassBoolean}.
140
+ *
141
+ * **Heads up!** Functions should generally use {@link isTruthy} rather than
142
+ * requiring a literal boolean.
143
+ *
144
+ * @param name - The name of the function argument `this` came from (without
145
+ * the `$`) if it came from an argument. Used for error reporting.
146
+ */
147
+ assertBoolean(name?: string): SassBoolean;
148
+
149
+ /**
150
+ * Throws if `this` isn't a {@link SassCalculation}.
151
+ *
152
+ * @param name - The name of the function argument `this` came from (without
153
+ * the `$`) if it came from an argument. Used for error reporting.
154
+ */
155
+ assertCalculation(name?: string): SassCalculation;
156
+
157
+ /**
158
+ * Throws if `this` isn't a {@link SassColor}.
159
+ *
160
+ * @param name - The name of the function argument `this` came from (without
161
+ * the `$`) if it came from an argument. Used for error reporting.
162
+ */
163
+ assertColor(name?: string): SassColor;
164
+
165
+ /**
166
+ * Throws if `this` isn't a {@link SassFunction}.
167
+ *
168
+ * @param name - The name of the function argument `this` came from (without
169
+ * the `$`) if it came from an argument. Used for error reporting.
170
+ */
171
+ assertFunction(name?: string): SassFunction;
172
+
173
+ /**
174
+ * Throws if `this` isn't a {@link SassMap}.
175
+ *
176
+ * @param name - The name of the function argument `this` came from (without
177
+ * the `$`) if it came from an argument. Used for error reporting.
178
+ */
179
+ assertMap(name?: string): SassMap;
180
+
181
+ /**
182
+ * Throws if `this` isn't a {@link SassMixin}.
183
+ *
184
+ * @param name - The name of the function argument `this` came from (without
185
+ * the `$`) if it came from an argument. Used for error reporting.
186
+ */
187
+ assertMixin(name?: string): SassMixin;
188
+
189
+ /**
190
+ * Throws if `this` isn't a {@link SassNumber}.
191
+ *
192
+ * @param name - The name of the function argument `this` came from (without
193
+ * the `$`) if it came from an argument. Used for error reporting.
194
+ */
195
+ assertNumber(name?: string): SassNumber;
196
+
197
+ /**
198
+ * Throws if `this` isn't a {@link SassString}.
199
+ *
200
+ * @param name - The name of the function argument `this` came from (without
201
+ * the `$`) if it came from an argument. Used for error reporting.
202
+ */
203
+ assertString(name?: string): SassString;
204
+
205
+ /**
206
+ * Returns `this` as a map if it counts as one (empty lists count as empty
207
+ * maps) or `null` if it doesn't.
208
+ */
209
+ tryMap(): SassMap | null;
210
+
211
+ /** Returns whether `this` represents the same value as `other`. */
212
+ equals(other: Value): boolean;
213
+
214
+ /** Returns a hash code that can be used to store `this` in a hash map. */
215
+ hashCode(): number;
216
+
217
+ /** @hidden */
218
+ toString(): string;
219
+ }
@@ -0,0 +1,54 @@
1
+ import {List} from 'immutable';
2
+
3
+ import {Value} from './index';
4
+
5
+ /**
6
+ * Possible separators used by Sass lists. The special separator `null` is only
7
+ * used for lists with fewer than two elements, and indicates that the separator
8
+ * has not yet been decided for this list.
9
+ *
10
+ * @category Custom Function
11
+ */
12
+ export type ListSeparator = ',' | '/' | ' ' | null;
13
+
14
+ /**
15
+ * Sass's [list type](https://sass-lang.com/documentation/values/lists).
16
+ *
17
+ * @category Custom Function
18
+ */
19
+ export class SassList extends Value {
20
+ /**
21
+ * Creates a new list.
22
+ *
23
+ * @param contents - The contents of the list. This may be either a plain
24
+ * JavaScript array or an immutable {@link List} from the [`immutable`
25
+ * package](https://immutable-js.com/).
26
+ *
27
+ * @param options.separator - The separator to use between elements of this
28
+ * list. Defaults to `','`.
29
+ *
30
+ * @param options.brackets - Whether the list has square brackets. Defaults to
31
+ * `false`.
32
+ */
33
+ constructor(
34
+ contents: Value[] | List<Value>,
35
+ options?: {
36
+ separator?: ListSeparator;
37
+ brackets?: boolean;
38
+ }
39
+ );
40
+
41
+ /**
42
+ * Creates an empty list.
43
+ *
44
+ * @param options.separator - The separator to use between elements of this
45
+ * list. Defaults to `','`.
46
+ *
47
+ * @param options.brackets - Whether the list has square brackets. Defaults to
48
+ * `false`.
49
+ */
50
+ constructor(options?: {separator?: ListSeparator; brackets?: boolean});
51
+
52
+ /** @hidden */
53
+ get separator(): ListSeparator;
54
+ }
@@ -0,0 +1,41 @@
1
+ import {OrderedMap} from 'immutable';
2
+
3
+ import {SassList} from './list';
4
+ import {Value} from './index';
5
+
6
+ /**
7
+ * Sass's [map type](https://sass-lang.com/documentation/values/maps).
8
+ *
9
+ * @category Custom Function
10
+ */
11
+ export class SassMap extends Value {
12
+ /**
13
+ * Creates a new map.
14
+ *
15
+ * @param contents - The contents of the map. This is an immutable
16
+ * `OrderedMap` from the [`immutable` package](https://immutable-js.com/).
17
+ * Defaults to an empty map.
18
+ */
19
+ constructor(contents?: OrderedMap<Value, Value>);
20
+
21
+ /**
22
+ * Returns the contents of this map as an immutable {@link OrderedMap} from the
23
+ * [`immutable` package](https://immutable-js.com/).
24
+ */
25
+ get contents(): OrderedMap<Value, Value>;
26
+
27
+ /**
28
+ * Returns the value associated with `key` in this map, or `undefined` if
29
+ * `key` isn't in the map.
30
+ *
31
+ * This is a shorthand for `this.contents.get(key)`, although it may be more
32
+ * efficient in some cases.
33
+ */
34
+ get(key: Value): Value | undefined;
35
+
36
+ /** Inherited from {@link Value.get}. */
37
+ get(index: number): SassList | undefined;
38
+
39
+ /** @hidden */
40
+ tryMap(): SassMap;
41
+ }
@@ -0,0 +1,14 @@
1
+ import {Value} from './index';
2
+
3
+ /**
4
+ * Sass's [mixin type](https://sass-lang.com/documentation/values/mixins).
5
+ *
6
+ * @category Custom Function
7
+ */
8
+ export class SassMixin extends Value {
9
+ /**
10
+ * It is not possible to construct a Sass mixin outside of Sass. Attempting to
11
+ * construct one will throw an exception.
12
+ */
13
+ constructor();
14
+ }
@@ -0,0 +1,305 @@
1
+ import {List} from 'immutable';
2
+
3
+ import {Value} from './index';
4
+
5
+ /**
6
+ * Sass's [number type](https://sass-lang.com/documentation/values/numbers).
7
+ *
8
+ * @category Custom Function
9
+ */
10
+ export class SassNumber extends Value {
11
+ /**
12
+ * Creates a new number with more complex units than just a single numerator.
13
+ *
14
+ * Upon construction, any compatible numerator and denominator units are
15
+ * simplified away according to the conversion factor between them.
16
+ *
17
+ * @param value - The number's numeric value.
18
+ *
19
+ * @param unit - If this is a string, it's used as the single numerator unit
20
+ * for the number.
21
+ *
22
+ * @param unit.numeratorUnits - If passed, these are the numerator units to
23
+ * use for the number. This may be either a plain JavaScript array or an
24
+ * immutable {@link List} from the [`immutable`
25
+ * package](https://immutable-js.com/).
26
+ *
27
+ * @param unit.denominatorUnits - If passed, these are the denominator units
28
+ * to use for the number. This may be either a plain JavaScript array or an
29
+ * immutable {@link List} from the [`immutable`
30
+ * package](https://immutable-js.com/).
31
+ */
32
+ constructor(
33
+ value: number,
34
+ unit?:
35
+ | string
36
+ | {
37
+ numeratorUnits?: string[] | List<string>;
38
+ denominatorUnits?: string[] | List<string>;
39
+ }
40
+ );
41
+
42
+ /** This number's numeric value. */
43
+ get value(): number;
44
+
45
+ /** Whether {@link value} is an integer according to Sass's equality logic. */
46
+ get isInt(): boolean;
47
+
48
+ /**
49
+ * If {@link value} is an integer according to {@link isInt}, returns {@link
50
+ * value} rounded to that integer. If it's not an integer, returns `null`.
51
+ */
52
+ get asInt(): number | null;
53
+
54
+ /**
55
+ * This number's numerator units as an immutable {@link List} from the
56
+ * [`immutable` package](https://immutable-js.com/).
57
+ */
58
+ get numeratorUnits(): List<string>;
59
+
60
+ /**
61
+ * This number's denominator units as an immutable {@link List} from the
62
+ * [`immutable` package](https://immutable-js.com/).
63
+ */
64
+ get denominatorUnits(): List<string>;
65
+
66
+ /** Whether this number has any numerator or denominator units. */
67
+ get hasUnits(): boolean;
68
+
69
+ /**
70
+ * If {@link value} is an integer according to {@link isInt}, returns it
71
+ * rounded to that integer. Otherwise, throws an error.
72
+ *
73
+ * @param name - The name of the function argument `this` came from (without
74
+ * the `$`) if it came from an argument. Used for error reporting.
75
+ */
76
+ assertInt(name?: string): number;
77
+
78
+ /**
79
+ * Returns {@link value} if it's within `min` and `max`. If {@link value} is
80
+ * equal to `min` or `max` according to Sass's equality, returns `min` or
81
+ * `max` respectively. Otherwise, throws an error.
82
+ *
83
+ * @param name - The name of the function argument `this` came from (without
84
+ * the `$`) if it came from an argument. Used for error reporting.
85
+ */
86
+ assertInRange(min: number, max: number, name?: string): number;
87
+
88
+ /**
89
+ * If this number has no units, returns it. Otherwise, throws an error.
90
+ *
91
+ * @param name - The name of the function argument `this` came from (without
92
+ * the `$`) if it came from an argument. Used for error reporting.
93
+ */
94
+ assertNoUnits(name?: string): SassNumber;
95
+
96
+ /**
97
+ * If this number has `unit` as its only unit (and as a numerator), returns
98
+ * this number. Otherwise, throws an error.
99
+ *
100
+ * @param name - The name of the function argument `this` came from (without
101
+ * the `$`) if it came from an argument. Used for error reporting.
102
+ */
103
+ assertUnit(unit: string, name?: string): SassNumber;
104
+
105
+ /** Whether this number has `unit` as its only unit (and as a numerator). */
106
+ hasUnit(unit: string): boolean;
107
+
108
+ /**
109
+ * Whether this has exactly one numerator unit, and that unit is compatible
110
+ * with `unit`.
111
+ */
112
+ compatibleWithUnit(unit: string): boolean;
113
+
114
+ /**
115
+ * Returns a copy of this number, converted to the units represented by
116
+ * `newNumerators` and `newDenominators`.
117
+ *
118
+ * @throws `Error` if this number's units are incompatible with
119
+ * `newNumerators` and `newDenominators`; or if this number is unitless and
120
+ * either `newNumerators` or `newDenominators` are not empty, or vice-versa.
121
+ *
122
+ * @param newNumerators - The numerator units to convert this number to. This
123
+ * may be either a plain JavaScript array or an immutable {@link List} from
124
+ * the [`immutable` package](https://immutable-js.com/).
125
+ *
126
+ * @param newDenominators - The denominator units to convert this number to.
127
+ * This may be either a plain JavaScript array or an immutable {@link List}
128
+ * from the [`immutable` package](https://immutable-js.com/).
129
+ *
130
+ * @param name - The name of the function argument `this` came from (without
131
+ * the `$`) if it came from an argument. Used for error reporting.
132
+ */
133
+ convert(
134
+ newNumerators: string[] | List<string>,
135
+ newDenominators: string[] | List<string>,
136
+ name?: string
137
+ ): SassNumber;
138
+
139
+ /**
140
+ * Returns a copy of this number, converted to the same units as `other`.
141
+ *
142
+ * @throws `Error` if this number's units are incompatible with `other`'s
143
+ * units, or if either number is unitless but the other is not.
144
+ *
145
+ * @param name - The name of the function argument `this` came from (without
146
+ * the `$`) if it came from an argument. Used for error reporting.
147
+ *
148
+ * @param otherName - The name of the function argument `other` came from
149
+ * (without the `$`) if it came from an argument. Used for error reporting.
150
+ */
151
+ convertToMatch(
152
+ other: SassNumber,
153
+ name?: string,
154
+ otherName?: string
155
+ ): SassNumber;
156
+
157
+ /**
158
+ * Returns {@link value}, converted to the units represented by
159
+ * `newNumerators` and `newDenominators`.
160
+ *
161
+ * @throws `Error` if this number's units are incompatible with
162
+ * `newNumerators` and `newDenominators`; or if this number is unitless and
163
+ * either `newNumerators` or `newDenominators` are not empty, or vice-versa.
164
+ *
165
+ * @param newNumerators - The numerator units to convert {@link value} to.
166
+ * This may be either a plain JavaScript array or an immutable {@link List}
167
+ * from the [`immutable` package](https://immutable-js.com/).
168
+ *
169
+ * @param newDenominators - The denominator units to convert {@link value} to.
170
+ * This may be either a plain JavaScript array or an immutable {@link List}
171
+ * from the [`immutable` package](https://immutable-js.com/).
172
+ *
173
+ * @param name - The name of the function argument `this` came from (without
174
+ * the `$`) if it came from an argument. Used for error reporting.
175
+ */
176
+ convertValue(
177
+ newNumerators: string[] | List<string>,
178
+ newDenominators: string[] | List<string>,
179
+ name?: string
180
+ ): number;
181
+
182
+ /**
183
+ * Returns {@link value}, converted to the same units as `other`.
184
+ *
185
+ * @throws `Error` if this number's units are incompatible with `other`'s
186
+ * units, or if either number is unitless but the other is not.
187
+ *
188
+ * @param name - The name of the function argument `this` came from (without
189
+ * the `$`) if it came from an argument. Used for error reporting.
190
+ *
191
+ * @param otherName - The name of the function argument `other` came from
192
+ * (without the `$`) if it came from an argument. Used for error reporting.
193
+ */
194
+ convertValueToMatch(
195
+ other: SassNumber,
196
+ name?: string,
197
+ otherName?: string
198
+ ): number;
199
+
200
+ /**
201
+ * Returns a copy of this number, converted to the units represented by
202
+ * `newNumerators` and `newDenominators`.
203
+ *
204
+ * Unlike {@link convert} this does *not* throw an error if this number is
205
+ * unitless and either `newNumerators` or `newDenominators` are not empty, or
206
+ * vice-versa. Instead, it treats all unitless numbers as convertible to and
207
+ * from all units without changing the value.
208
+ *
209
+ * @throws `Error` if this number's units are incompatible with
210
+ * `newNumerators` and `newDenominators`.
211
+ *
212
+ * @param newNumerators - The numerator units to convert this number to. This
213
+ * may be either a plain JavaScript array or an immutable {@link List} from
214
+ * the [`immutable` package](https://immutable-js.com/).
215
+ *
216
+ * @param newDenominators - The denominator units to convert this number to.
217
+ * This may be either a plain JavaScript array or an immutable {@link List}
218
+ * from the [`immutable` package](https://immutable-js.com/).
219
+ *
220
+ * @param name - The name of the function argument `this` came from (without
221
+ * the `$`) if it came from an argument. Used for error reporting.
222
+ */
223
+ coerce(
224
+ newNumerators: string[] | List<string>,
225
+ newDenominators: string[] | List<string>,
226
+ name?: string
227
+ ): SassNumber;
228
+
229
+ /**
230
+ * Returns a copy of this number, converted to the units represented by
231
+ * `newNumerators` and `newDenominators`.
232
+ *
233
+ * Unlike {@link convertToMatch} this does *not* throw an error if this number
234
+ * is unitless and either `newNumerators` or `newDenominators` are not empty,
235
+ * or vice-versa. Instead, it treats all unitless numbers as convertible to
236
+ * and from all units without changing the value.
237
+ *
238
+ * @throws `Error` if this number's units are incompatible with `other`'s
239
+ * units.
240
+ *
241
+ * @param name - The name of the function argument `this` came from (without
242
+ * the `$`) if it came from an argument. Used for error reporting.
243
+ *
244
+ * @param otherName - The name of the function argument `other` came from
245
+ * (without the `$`) if it came from an argument. Used for error reporting.
246
+ */
247
+ coerceToMatch(
248
+ other: SassNumber,
249
+ name?: string,
250
+ otherName?: string
251
+ ): SassNumber;
252
+
253
+ /**
254
+ * Returns {@link value}, converted to the units represented by
255
+ * `newNumerators` and `newDenominators`.
256
+ *
257
+ * Unlike {@link convertValue} this does *not* throw an error if this number
258
+ * is unitless and either `newNumerators` or `newDenominators` are not empty,
259
+ * or vice-versa. Instead, it treats all unitless numbers as convertible to
260
+ * and from all units without changing the value.
261
+ *
262
+ * @throws `Error` if this number's units are incompatible with
263
+ * `newNumerators` and `newDenominators`.
264
+ *
265
+ * @param newNumerators - The numerator units to convert {@link value} to.
266
+ * This may be either a plain JavaScript array or an immutable {@link List}
267
+ * from the [`immutable` package](https://immutable-js.com/).
268
+ *
269
+ * @param newDenominators - The denominator units to convert {@link value} to.
270
+ * This may be either a plain JavaScript array or an immutable {@link List}
271
+ * from the [`immutable` package](https://immutable-js.com/).
272
+ *
273
+ * @param name - The name of the function argument `this` came from (without
274
+ * the `$`) if it came from an argument. Used for error reporting.
275
+ */
276
+ coerceValue(
277
+ newNumerators: string[] | List<string>,
278
+ newDenominators: string[] | List<string>,
279
+ name?: string
280
+ ): number;
281
+
282
+ /**
283
+ * Returns {@link value}, converted to the units represented by
284
+ * `newNumerators` and `newDenominators`.
285
+ *
286
+ * Unlike {@link convertValueToMatch} this does *not* throw an error if this
287
+ * number is unitless and either `newNumerators` or `newDenominators` are not
288
+ * empty, or vice-versa. Instead, it treats all unitless numbers as
289
+ * convertible to and from all units without changing the value.
290
+ *
291
+ * @throws `Error` if this number's units are incompatible with `other`'s
292
+ * units.
293
+ *
294
+ * @param name - The name of the function argument `this` came from (without
295
+ * the `$`) if it came from an argument. Used for error reporting.
296
+ *
297
+ * @param otherName - The name of the function argument `other` came from
298
+ * (without the `$`) if it came from an argument. Used for error reporting.
299
+ */
300
+ coerceValueToMatch(
301
+ other: SassNumber,
302
+ name?: string,
303
+ otherName?: string
304
+ ): number;
305
+ }