sass 1.44.0 → 1.45.1

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,17 @@
1
+ /**
2
+ * A utility type for choosing between synchronous and asynchronous return
3
+ * values.
4
+ *
5
+ * This is used as the return value for plugins like [[CustomFunction]],
6
+ * [[Importer]], and [[FileImporter]] so that TypeScript enforces that
7
+ * asynchronous plugins are only passed to [[compileAsync]] and
8
+ * [[compileStringAsync]], not [[compile]] or [[compileString]].
9
+ *
10
+ * @typeParam sync - If this is `'sync'`, this can only be a `T`. If it's
11
+ * `'async'`, this can be either a `T` or a `Promise<T>`.
12
+ *
13
+ * @category Other
14
+ */
15
+ export type PromiseOr<T, sync extends 'sync' | 'async'> = sync extends 'async'
16
+ ? T | Promise<T>
17
+ : T;
@@ -0,0 +1,47 @@
1
+ import {List, OrderedMap} from 'immutable';
2
+
3
+ import {Value} from './index';
4
+ import {SassList, ListSeparator} from './list';
5
+
6
+ /**
7
+ * Sass's [argument list
8
+ * type](https://sass-lang.com/documentation/values/lists#argument-lists).
9
+ *
10
+ * An argument list comes from a rest argument. It's distinct from a normal
11
+ * [[SassList]] in that it may contain a keyword map as well as the positional
12
+ * arguments.
13
+ *
14
+ * @category Custom Function
15
+ */
16
+ export class SassArgumentList extends SassList {
17
+ /**
18
+ * Creates a new argument list.
19
+ *
20
+ * @param contents - The positional arguments that make up the primary
21
+ * contents of the list. This may be either a plain JavaScript array or an
22
+ * immutable [[List]] from the [`immutable`
23
+ * package](https://immutable-js.com/).
24
+ *
25
+ * @param keywords - The keyword arguments attached to this argument list,
26
+ * whose names should exclude `$`. This can be either a plain JavaScript
27
+ * object with argument names as fields, or an immutable [[OrderedMap]] from
28
+ * the [`immutable` package](https://immutable-js.com/)
29
+ *
30
+ * @param separator - The separator for this list. Defaults to `','`.
31
+ */
32
+ constructor(
33
+ contents: Value[] | List<Value>,
34
+ keywords: Record<string, Value> | OrderedMap<string, Value>,
35
+ separator?: ListSeparator
36
+ );
37
+
38
+ /**
39
+ * The keyword arguments attached to this argument list.
40
+ *
41
+ * The argument names don't include `$`.
42
+ *
43
+ * @returns An immutable [[OrderedMap]] from the [`immutable`
44
+ * package](https://immutable-js.com/).
45
+ */
46
+ get keywords(): OrderedMap<string, Value>;
47
+ }
@@ -0,0 +1,29 @@
1
+ import {Value} from './index';
2
+
3
+ /**
4
+ * Sass's [`true` value](https://sass-lang.com/documentation/values/booleans).
5
+ *
6
+ * @category Custom Function
7
+ */
8
+ export const sassTrue: SassBoolean;
9
+
10
+ /**
11
+ * Sass's [`false` value](https://sass-lang.com/documentation/values/booleans).
12
+ *
13
+ * @category Custom Function
14
+ */
15
+ export const sassFalse: SassBoolean;
16
+
17
+ /**
18
+ * Sass's [boolean type](https://sass-lang.com/documentation/values/booleans).
19
+ *
20
+ * @category Custom Function
21
+ */
22
+ export class SassBoolean extends Value {
23
+ private constructor();
24
+
25
+ /**
26
+ * Whether this value is `true` or `false`.
27
+ */
28
+ get value(): boolean;
29
+ }
@@ -0,0 +1,107 @@
1
+ import {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
+ */
11
+ export class SassColor extends Value {
12
+ /**
13
+ * Creates an RGB color.
14
+ *
15
+ * @throws `Error` if `red`, `green`, and `blue` aren't between `0` and
16
+ * `255`, or if `alpha` isn't between `0` and `1`.
17
+ */
18
+ constructor(options: {
19
+ red: number;
20
+ green: number;
21
+ blue: number;
22
+ alpha?: number;
23
+ });
24
+
25
+ /**
26
+ * Creates an HSL color.
27
+ *
28
+ * @throws `Error` if `saturation` or `lightness` aren't between `0` and
29
+ * `100`, or if `alpha` isn't between `0` and `1`.
30
+ */
31
+ constructor(options: {
32
+ hue: number;
33
+ saturation: number;
34
+ lightness: number;
35
+ alpha?: number;
36
+ });
37
+
38
+ /**
39
+ * Creates an HWB color.
40
+ *
41
+ * @throws `Error` if `whiteness` or `blackness` aren't between `0` and `100`,
42
+ * or if `alpha` isn't between `0` and `1`.
43
+ */
44
+ constructor(options: {
45
+ hue: number;
46
+ whiteness: number;
47
+ blackness: number;
48
+ alpha?: number;
49
+ });
50
+
51
+ /** This color's red channel, between `0` and `255`. */
52
+ get red(): number;
53
+
54
+ /** This color's green channel, between `0` and `255`. */
55
+ get green(): number;
56
+
57
+ /** This color's blue channel, between `0` and `255`. */
58
+ get blue(): number;
59
+
60
+ /** This color's hue, between `0` and `360`. */
61
+ get hue(): number;
62
+
63
+ /** This color's saturation, between `0` and `100`. */
64
+ get saturation(): number;
65
+
66
+ /** This color's lightness, between `0` and `100`. */
67
+ get lightness(): number;
68
+
69
+ /** This color's whiteness, between `0` and `100`. */
70
+ get whiteness(): number;
71
+
72
+ /** This color's blackness, between `0` and `100`. */
73
+ get blackness(): number;
74
+
75
+ /** This color's alpha channel, between `0` and `1`. */
76
+ get alpha(): number;
77
+
78
+ /**
79
+ * Changes one or more of this color's RGB channels and returns the result.
80
+ */
81
+ change(options: {
82
+ red?: number;
83
+ green?: number;
84
+ blue?: number;
85
+ alpha?: number;
86
+ }): SassColor;
87
+
88
+ /**
89
+ * Changes one or more of this color's HSL channels and returns the result.
90
+ */
91
+ change(options: {
92
+ hue?: number;
93
+ saturation?: number;
94
+ lightness?: number;
95
+ alpha?: number;
96
+ }): SassColor;
97
+
98
+ /**
99
+ * Changes one or more of this color's HWB channels and returns the result.
100
+ */
101
+ change(options: {
102
+ hue?: number;
103
+ whiteness?: number;
104
+ blackness?: number;
105
+ alpha?: number;
106
+ }): SassColor;
107
+ }
@@ -0,0 +1,22 @@
1
+ import {Value} from './index';
2
+
3
+ /**
4
+ * Sass's [function type](https://sass-lang.com/documentation/values/functions).
5
+ *
6
+ * **Heads up!** Although first-class Sass functions can be processed by custom
7
+ * functions, there's no way to invoke them outside of a Sass stylesheet.
8
+ *
9
+ * @category Custom Function
10
+ */
11
+ export class SassFunction extends Value {
12
+ /**
13
+ * Creates a new first-class function that can be invoked using
14
+ * [`meta.call()`](https://sass-lang.com/documentation/modules/meta#call).
15
+ *
16
+ * @param signature - The function signature, like you'd write for the
17
+ * [`@function rule`](https://sass-lang.com/documentation/at-rules/function).
18
+ * @param callback - The callback that's invoked when this function is called,
19
+ * just like for a [[CustomFunction]].
20
+ */
21
+ constructor(signature: string, callback: (args: Value[]) => Value);
22
+ }
@@ -0,0 +1,173 @@
1
+ import {List, ValueObject} from 'immutable';
2
+
3
+ import {SassBoolean} from './boolean';
4
+ import {SassColor} from './color';
5
+ import {SassFunction} from './function';
6
+ import {ListSeparator} from './list';
7
+ import {SassMap} from './map';
8
+ import {SassNumber} from './number';
9
+ import {SassString} from './string';
10
+
11
+ export {SassArgumentList} from './argument_list';
12
+ export {SassBoolean, sassTrue, sassFalse} from './boolean';
13
+ export {SassColor} from './color';
14
+ export {SassFunction} from './function';
15
+ export {SassList, ListSeparator} from './list';
16
+ export {SassMap} from './map';
17
+ export {SassNumber} from './number';
18
+ export {SassString} from './string';
19
+
20
+ /**
21
+ * Sass's [`null` value](https://sass-lang.com/documentation/values/null).
22
+ *
23
+ * @category Custom Function
24
+ */
25
+ export const sassNull: Value;
26
+
27
+ /**
28
+ * The abstract base class of Sass's value types.
29
+ *
30
+ * This is passed to and returned by [[CustomFunction]]s, which are passed into
31
+ * the Sass implementation using [[Options.functions]].
32
+ *
33
+ * @category Custom Function
34
+ */
35
+ export abstract class Value implements ValueObject {
36
+ protected constructor();
37
+
38
+ /**
39
+ * This value as a list.
40
+ *
41
+ * All SassScript values can be used as lists. Maps count as lists of pairs,
42
+ * and all other values count as single-value lists.
43
+ *
44
+ * @returns An immutable [[List]] from the [`immutable`
45
+ * package](https://immutable-js.com/).
46
+ */
47
+ get asList(): List<Value>;
48
+
49
+ /**
50
+ * Whether this value as a list has brackets.
51
+ *
52
+ * All SassScript values can be used as lists. Maps count as lists of pairs,
53
+ * and all other values count as single-value lists.
54
+ */
55
+ get hasBrackets(): boolean;
56
+
57
+ /**
58
+ * Whether the value counts as `true` in an `@if` statement and other
59
+ * contexts.
60
+ */
61
+ get isTruthy(): boolean;
62
+
63
+ /**
64
+ * Returns JavaScript's `null` value if this is [[sassNull]], and returns
65
+ * `this` otherwise.
66
+ */
67
+ get realNull(): null | Value;
68
+
69
+ /**
70
+ * The separator for this value as a list.
71
+ *
72
+ * All SassScript values can be used as lists. Maps count as lists of pairs,
73
+ * and all other values count as single-value lists.
74
+ */
75
+ get separator(): ListSeparator;
76
+
77
+ /**
78
+ * Converts `sassIndex` into a JavaScript-style index into the list returned
79
+ * by [[asList]].
80
+ *
81
+ * Sass indexes are one-based, while JavaScript indexes are zero-based. Sass
82
+ * indexes may also be negative in order to index from the end of the list.
83
+ *
84
+ * @param sassIndex - The Sass-style index into this as a list.
85
+ * @param name - The name of the function argument `sassIndex` came from
86
+ * (without the `$`) if it came from an argument. Used for error reporting.
87
+ * @throws `Error` If `sassIndex` isn't a number, if that number isn't an
88
+ * integer, or if that integer isn't a valid index for [[asList]].
89
+ */
90
+ sassIndexToListIndex(sassIndex: Value, name?: string): number;
91
+
92
+ /**
93
+ * Returns the value at index `index` in this value as a list, or `undefined`
94
+ * if `index` isn't valid for this list.
95
+ *
96
+ * All SassScript values can be used as lists. Maps count as lists of pairs,
97
+ * and all other values count as single-value lists.
98
+ *
99
+ * This is a shorthand for `this.asList.get(index)`, although it may be more
100
+ * efficient in some cases.
101
+ *
102
+ * **Heads up!** This method uses the same indexing conventions as the
103
+ * `immutable` package: unlike Sass the index of the first element is 0, but
104
+ * like Sass negative numbers index from the end of the list.
105
+ */
106
+ get(index: number): Value | undefined;
107
+
108
+ /**
109
+ * Throws if `this` isn't a [[SassBoolean]].
110
+ *
111
+ * **Heads up!** Functions should generally use [[isTruthy]] rather than
112
+ * requiring a literal boolean.
113
+ *
114
+ * @param name - The name of the function argument `this` came from (without
115
+ * the `$`) if it came from an argument. Used for error reporting.
116
+ */
117
+ assertBoolean(name?: string): SassBoolean;
118
+
119
+ /**
120
+ * Throws if `this` isn't a [[SassColor]].
121
+ *
122
+ * @param name - The name of the function argument `this` came from (without
123
+ * the `$`) if it came from an argument. Used for error reporting.
124
+ */
125
+ assertColor(name?: string): SassColor;
126
+
127
+ /**
128
+ * Throws if `this` isn't a [[SassFunction]].
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
+ assertFunction(name?: string): SassFunction;
134
+
135
+ /**
136
+ * Throws if `this` isn't a [[SassMap]].
137
+ *
138
+ * @param name - The name of the function argument `this` came from (without
139
+ * the `$`) if it came from an argument. Used for error reporting.
140
+ */
141
+ assertMap(name?: string): SassMap;
142
+
143
+ /**
144
+ * Throws if `this` isn't a [[SassNumber]].
145
+ *
146
+ * @param name - The name of the function argument `this` came from (without
147
+ * the `$`) if it came from an argument. Used for error reporting.
148
+ */
149
+ assertNumber(name?: string): SassNumber;
150
+
151
+ /**
152
+ * Throws if `this` isn't a [[SassString]].
153
+ *
154
+ * @param name - The name of the function argument `this` came from (without
155
+ * the `$`) if it came from an argument. Used for error reporting.
156
+ */
157
+ assertString(name?: string): SassString;
158
+
159
+ /**
160
+ * Returns `this` as a map if it counts as one (empty lists count as empty
161
+ * maps) or `null` if it doesn't.
162
+ */
163
+ tryMap(): SassMap | null;
164
+
165
+ /** Returns whether `this` represents the same value as `other`. */
166
+ equals(other: Value): boolean;
167
+
168
+ /** Returns a hash code that can be used to store `this` in a hash map. */
169
+ hashCode(): number;
170
+
171
+ /** @hidden */
172
+ toString(): string;
173
+ }
@@ -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 [[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 [[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 [[Value.get]]. */
37
+ get(index: number): SassList | undefined;
38
+
39
+ /** @hidden */
40
+ tryMap(): SassMap;
41
+ }