@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.
- package/LICENSE +20 -0
- package/README.md +6 -0
- package/package.json +18 -0
- package/types/compile.d.ts +342 -0
- package/types/deprecations.d.ts +290 -0
- package/types/exception.d.ts +41 -0
- package/types/importer.d.ts +471 -0
- package/types/index.d.ts +122 -0
- package/types/legacy/exception.d.ts +55 -0
- package/types/legacy/function.d.ts +757 -0
- package/types/legacy/importer.d.ts +169 -0
- package/types/legacy/options.d.ts +700 -0
- package/types/legacy/plugin_this.d.ts +74 -0
- package/types/legacy/render.d.ts +144 -0
- package/types/logger/index.d.ts +115 -0
- package/types/logger/source_location.d.ts +21 -0
- package/types/logger/source_span.d.ts +34 -0
- package/types/options.d.ts +468 -0
- package/types/util/promise_or.d.ts +17 -0
- package/types/value/argument_list.d.ts +47 -0
- package/types/value/boolean.d.ts +29 -0
- package/types/value/calculation.d.ts +137 -0
- package/types/value/color.d.ts +566 -0
- package/types/value/function.d.ts +22 -0
- package/types/value/index.d.ts +219 -0
- package/types/value/list.d.ts +54 -0
- package/types/value/map.d.ts +41 -0
- package/types/value/mixin.d.ts +14 -0
- package/types/value/number.d.ts +305 -0
- package/types/value/string.d.ts +84 -0
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
import {DeprecationOrId, Version} from './deprecations';
|
|
2
|
+
import {FileImporter, Importer, NodePackageImporter} from './importer';
|
|
3
|
+
import {Logger} from './logger';
|
|
4
|
+
import {Value} from './value';
|
|
5
|
+
import {PromiseOr} from './util/promise_or';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Syntaxes supported by Sass:
|
|
9
|
+
*
|
|
10
|
+
* - `'scss'` is the [SCSS
|
|
11
|
+
* syntax](https://sass-lang.com/documentation/syntax#scss).
|
|
12
|
+
* - `'indented'` is the [indented
|
|
13
|
+
* syntax](https://sass-lang.com/documentation/syntax#the-indented-syntax)
|
|
14
|
+
* - `'css'` is plain CSS, which is parsed like SCSS but forbids the use of any
|
|
15
|
+
* special Sass features.
|
|
16
|
+
*
|
|
17
|
+
* @category Options
|
|
18
|
+
*/
|
|
19
|
+
export type Syntax = 'scss' | 'indented' | 'css';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Possible output styles for the compiled CSS:
|
|
23
|
+
*
|
|
24
|
+
* - `"expanded"` (the default for Dart Sass) writes each selector and
|
|
25
|
+
* declaration on its own line.
|
|
26
|
+
*
|
|
27
|
+
* - `"compressed"` removes as many extra characters as possible, and writes
|
|
28
|
+
* the entire stylesheet on a single line.
|
|
29
|
+
*
|
|
30
|
+
* @category Options
|
|
31
|
+
*/
|
|
32
|
+
export type OutputStyle = 'expanded' | 'compressed';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A callback that implements a custom Sass function. This can be passed to
|
|
36
|
+
* {@link Options.functions}.
|
|
37
|
+
*
|
|
38
|
+
* ```js
|
|
39
|
+
* const result = sass.compile('style.scss', {
|
|
40
|
+
* functions: {
|
|
41
|
+
* "sum($arg1, $arg2)": (args) => {
|
|
42
|
+
* const arg1 = args[0].assertNumber('arg1');
|
|
43
|
+
* const value1 = arg1.value;
|
|
44
|
+
* const value2 = args[1].assertNumber('arg2')
|
|
45
|
+
* .convertValueToMatch(arg1, 'arg2', 'arg1');
|
|
46
|
+
* return new sass.SassNumber(value1 + value2).coerceToMatch(arg1);
|
|
47
|
+
* }
|
|
48
|
+
* }
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @typeParam sync - A `CustomFunction<'sync'>` must return synchronously, but
|
|
53
|
+
* in return it can be passed to {@link compile} and {@link compileString} in
|
|
54
|
+
* addition to {@link compileAsync} and {@link compileStringAsync}.
|
|
55
|
+
*
|
|
56
|
+
* A `CustomFunction<'async'>` may either return synchronously or
|
|
57
|
+
* asynchronously, but it can only be used with {@link compileAsync} and {@link
|
|
58
|
+
* compileStringAsync}.
|
|
59
|
+
*
|
|
60
|
+
* @param args - An array of arguments passed by the function's caller. If the
|
|
61
|
+
* function takes [arbitrary
|
|
62
|
+
* arguments](https://sass-lang.com/documentation/at-rules/function#taking-arbitrary-arguments),
|
|
63
|
+
* the last element will be a {@link SassArgumentList}.
|
|
64
|
+
*
|
|
65
|
+
* @returns The function's result. This may be in the form of a `Promise`, but
|
|
66
|
+
* if it is the function may only be passed to {@link compileAsync} and {@link
|
|
67
|
+
* compileStringAsync}, not {@link compile} or {@link compileString}.
|
|
68
|
+
*
|
|
69
|
+
* @throws any - This function may throw an error, which the Sass compiler will
|
|
70
|
+
* treat as the function call failing. If the exception object has a `message`
|
|
71
|
+
* property, it will be used as the wrapped exception's message; otherwise, the
|
|
72
|
+
* exception object's `toString()` will be used. This means it's safe for custom
|
|
73
|
+
* functions to throw plain strings.
|
|
74
|
+
*
|
|
75
|
+
* @category Custom Function
|
|
76
|
+
*/
|
|
77
|
+
export type CustomFunction<sync extends 'sync' | 'async'> = (
|
|
78
|
+
args: Value[]
|
|
79
|
+
) => PromiseOr<Value, sync>;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Options that can be passed to {@link compile}, {@link compileAsync}, {@link
|
|
83
|
+
* compileString}, or {@link compileStringAsync}.
|
|
84
|
+
*
|
|
85
|
+
* @typeParam sync - This lets the TypeScript checker verify that asynchronous
|
|
86
|
+
* {@link Importer}s, {@link FileImporter}s, and {@link CustomFunction}s aren't
|
|
87
|
+
* passed to {@link compile} or {@link compileString}.
|
|
88
|
+
*
|
|
89
|
+
* @category Options
|
|
90
|
+
*/
|
|
91
|
+
export interface Options<sync extends 'sync' | 'async'> {
|
|
92
|
+
/**
|
|
93
|
+
* If this is `true`, the compiler will exclusively use ASCII characters in
|
|
94
|
+
* its error and warning messages. Otherwise, it may use non-ASCII Unicode
|
|
95
|
+
* characters as well.
|
|
96
|
+
*
|
|
97
|
+
* @defaultValue `false`
|
|
98
|
+
* @category Messages
|
|
99
|
+
*/
|
|
100
|
+
alertAscii?: boolean;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* If this is `true`, the compiler will use ANSI color escape codes in its
|
|
104
|
+
* error and warning messages. If it's `false`, it won't use these. If it's
|
|
105
|
+
* undefined, the compiler will determine whether or not to use colors
|
|
106
|
+
* depending on whether the user is using an interactive terminal.
|
|
107
|
+
*
|
|
108
|
+
* @category Messages
|
|
109
|
+
*/
|
|
110
|
+
alertColor?: boolean;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* If `true`, the compiler may prepend `@charset "UTF-8";` or U+FEFF
|
|
114
|
+
* (byte-order marker) if it outputs non-ASCII CSS.
|
|
115
|
+
*
|
|
116
|
+
* If `false`, the compiler never emits these byte sequences. This is ideal
|
|
117
|
+
* when concatenating or embedding in HTML `<style>` tags. (The output will
|
|
118
|
+
* still be UTF-8.)
|
|
119
|
+
*
|
|
120
|
+
* @defaultValue `true`
|
|
121
|
+
* @category Output
|
|
122
|
+
* @compatibility dart: "1.54.0", node: false
|
|
123
|
+
*/
|
|
124
|
+
charset?: boolean;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* A set of deprecations to treat as fatal.
|
|
128
|
+
*
|
|
129
|
+
* If a deprecation warning of any provided type is encountered during
|
|
130
|
+
* compilation, the compiler will error instead.
|
|
131
|
+
*
|
|
132
|
+
* If a `Version` is provided, then all deprecations that were active in that
|
|
133
|
+
* compiler version will be treated as fatal.
|
|
134
|
+
*
|
|
135
|
+
* @category Messages
|
|
136
|
+
* @compatiblity dart: "1.74.0", node: false
|
|
137
|
+
*/
|
|
138
|
+
fatalDeprecations?: (DeprecationOrId | Version)[];
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Additional built-in Sass functions that are available in all stylesheets.
|
|
142
|
+
* This option takes an object whose keys are Sass function signatures like
|
|
143
|
+
* you'd write for the [`@function
|
|
144
|
+
* rule`](https://sass-lang.com/documentation/at-rules/function) and whose
|
|
145
|
+
* values are {@link CustomFunction}s.
|
|
146
|
+
*
|
|
147
|
+
* Functions are passed subclasses of {@link Value}, and must return the same.
|
|
148
|
+
* If the return value includes {@link SassCalculation}s they will be
|
|
149
|
+
* simplified before being returned.
|
|
150
|
+
*
|
|
151
|
+
* When writing custom functions, it's important to make them as user-friendly
|
|
152
|
+
* and as close to the standards set by Sass's core functions as possible. Some
|
|
153
|
+
* good guidelines to follow include:
|
|
154
|
+
*
|
|
155
|
+
* * Use `Value.assert*` methods, like {@link Value.assertString}, to cast
|
|
156
|
+
* untyped `Value` objects to more specific types. For values that were
|
|
157
|
+
* passed directly as arguments, pass in the argument name as well. This
|
|
158
|
+
* ensures that the user gets good error messages when they pass in the
|
|
159
|
+
* wrong type to your function.
|
|
160
|
+
*
|
|
161
|
+
* * Individual classes may have more specific `assert*` methods, like {@link
|
|
162
|
+
* SassNumber.assertInt}, which should be used when possible.
|
|
163
|
+
*
|
|
164
|
+
* * In Sass, every value counts as a list. Rather than trying to detect the
|
|
165
|
+
* {@link SassList} type, you should use {@link Value.asList} to treat all
|
|
166
|
+
* values as lists.
|
|
167
|
+
*
|
|
168
|
+
* * When manipulating values like lists, strings, and numbers that have
|
|
169
|
+
* metadata (comma versus space separated, bracketed versus unbracketed,
|
|
170
|
+
* quoted versus unquoted, units), the output metadata should match the
|
|
171
|
+
* input metadata.
|
|
172
|
+
*
|
|
173
|
+
* * When in doubt, lists should default to comma-separated, strings should
|
|
174
|
+
* default to quoted, and numbers should default to unitless.
|
|
175
|
+
*
|
|
176
|
+
* * In Sass, lists and strings use one-based indexing and use negative
|
|
177
|
+
* indices to index from the end of value. Functions should follow these
|
|
178
|
+
* conventions. {@link Value.sassIndexToListIndex} and {@link
|
|
179
|
+
* SassString.sassIndexToStringIndex} can be used to do this automatically.
|
|
180
|
+
*
|
|
181
|
+
* * String indexes in Sass refer to Unicode code points while JavaScript
|
|
182
|
+
* string indices refer to UTF-16 code units. For example, the character
|
|
183
|
+
* U+1F60A SMILING FACE WITH SMILING EYES is a single Unicode code point but
|
|
184
|
+
* is represented in UTF-16 as two code units (`0xD83D` and `0xDE0A`). So in
|
|
185
|
+
* JavaScript, `"a😊b".charCodeAt(1)` returns `0xD83D`, whereas in Sass
|
|
186
|
+
* `str-slice("a😊b", 1, 1)` returns `"😊"`. Functions should follow Sass's
|
|
187
|
+
* convention. {@link SassString.sassIndexToStringIndex} can be used to do
|
|
188
|
+
* this automatically, and the {@link SassString.sassLength} getter can be
|
|
189
|
+
* used to access a string's length in code points.
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
*
|
|
193
|
+
* ```js
|
|
194
|
+
* sass.compileString(`
|
|
195
|
+
* h1 {
|
|
196
|
+
* font-size: pow(2, 5) * 1px;
|
|
197
|
+
* }`, {
|
|
198
|
+
* functions: {
|
|
199
|
+
* // Note: in real code, you should use `math.pow()` from the built-in
|
|
200
|
+
* // `sass:math` module.
|
|
201
|
+
* 'pow($base, $exponent)': function(args) {
|
|
202
|
+
* const base = args[0].assertNumber('base').assertNoUnits('base');
|
|
203
|
+
* const exponent =
|
|
204
|
+
* args[1].assertNumber('exponent').assertNoUnits('exponent');
|
|
205
|
+
*
|
|
206
|
+
* return new sass.SassNumber(Math.pow(base.value, exponent.value));
|
|
207
|
+
* }
|
|
208
|
+
* }
|
|
209
|
+
* });
|
|
210
|
+
* ```
|
|
211
|
+
*
|
|
212
|
+
* @category Plugins
|
|
213
|
+
*/
|
|
214
|
+
functions?: Record<string, CustomFunction<sync>>;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* A set of future deprecations to opt into early.
|
|
218
|
+
*
|
|
219
|
+
* Future deprecations passed here will be treated as active by the compiler,
|
|
220
|
+
* emitting warnings as necessary.
|
|
221
|
+
*
|
|
222
|
+
* @category Messages
|
|
223
|
+
* @compatiblity dart: "1.74.0", node: false
|
|
224
|
+
*/
|
|
225
|
+
futureDeprecations?: DeprecationOrId[];
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Custom importers that control how Sass resolves loads from rules like
|
|
229
|
+
* [`@use`](https://sass-lang.com/documentation/at-rules/use) and
|
|
230
|
+
* [`@import`](https://sass-lang.com/documentation/at-rules/import).
|
|
231
|
+
*
|
|
232
|
+
* Loads are resolved by trying, in order:
|
|
233
|
+
*
|
|
234
|
+
* - **For relative URLs only:** the URL resolved relative to the current
|
|
235
|
+
* stylesheet's canonical URL, passed to the importer that loaded the current
|
|
236
|
+
* stylesheet.
|
|
237
|
+
*
|
|
238
|
+
* When calling {@link compileString} or {@link compileStringAsync}, the
|
|
239
|
+
* entrypoint file isn't "loaded" in the same sense as other files. In that
|
|
240
|
+
* case:
|
|
241
|
+
*
|
|
242
|
+
* - {@link StringOptions.url} is the canonical URL and {@link
|
|
243
|
+
* StringOptions.importer} is the importer that loaded it.
|
|
244
|
+
*
|
|
245
|
+
* - If {@link StringOptions.importer} isn't passed and {@link
|
|
246
|
+
* StringOptions.url} is a `file:` URL, the URL is loaded from the
|
|
247
|
+
* filesystem by default. (You can disable this by passing `{canonicalize:
|
|
248
|
+
* url => null}` as {@link StringOptions.importer}.)
|
|
249
|
+
*
|
|
250
|
+
* - If {@link StringOptions.url} isn't passed but {@link
|
|
251
|
+
* StringOptions.importer} is, the relative URL is passed to {@link
|
|
252
|
+
* StringOptions.importer} as-is.
|
|
253
|
+
*
|
|
254
|
+
* - Each {@link Importer}, {@link FileImporter}, or
|
|
255
|
+
* {@link NodePackageImporter} in {@link importers}, in order.
|
|
256
|
+
*
|
|
257
|
+
* - Each load path in {@link loadPaths}, in order.
|
|
258
|
+
*
|
|
259
|
+
* If none of these return a Sass file, the load fails and Sass throws an
|
|
260
|
+
* error.
|
|
261
|
+
*
|
|
262
|
+
* @category Plugins
|
|
263
|
+
*/
|
|
264
|
+
importers?: (Importer<sync> | FileImporter<sync> | NodePackageImporter)[];
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Paths in which to look for stylesheets loaded by rules like
|
|
268
|
+
* [`@use`](https://sass-lang.com/documentation/at-rules/use) and
|
|
269
|
+
* [`@import`](https://sass-lang.com/documentation/at-rules/import).
|
|
270
|
+
*
|
|
271
|
+
* A load path `loadPath` is equivalent to the following {@link FileImporter}:
|
|
272
|
+
*
|
|
273
|
+
* ```js
|
|
274
|
+
* {
|
|
275
|
+
* findFileUrl(url) {
|
|
276
|
+
* // Load paths only support relative URLs.
|
|
277
|
+
* if (/^[a-z]+:/i.test(url)) return null;
|
|
278
|
+
* return new URL(url, pathToFileURL(loadPath));
|
|
279
|
+
* }
|
|
280
|
+
* }
|
|
281
|
+
* ```
|
|
282
|
+
*
|
|
283
|
+
* @category Input
|
|
284
|
+
*/
|
|
285
|
+
loadPaths?: string[];
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* An object to use to handle warnings and/or debug messages from Sass.
|
|
289
|
+
*
|
|
290
|
+
* By default, Sass emits warnings and debug messages to standard error, but
|
|
291
|
+
* if {@link Logger.warn} or {@link Logger.debug} is set, this will invoke
|
|
292
|
+
* them instead.
|
|
293
|
+
*
|
|
294
|
+
* The special value {@link Logger.silent} can be used to easily silence all
|
|
295
|
+
* messages.
|
|
296
|
+
*
|
|
297
|
+
* @category Messages
|
|
298
|
+
*/
|
|
299
|
+
logger?: Logger;
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* If this option is set to `true`, Sass won’t print warnings that are caused
|
|
303
|
+
* by dependencies. A “dependency” is defined as any file that’s loaded
|
|
304
|
+
* through {@link loadPaths} or {@link importers}. Stylesheets that are
|
|
305
|
+
* imported relative to the entrypoint are not considered dependencies.
|
|
306
|
+
*
|
|
307
|
+
* This is useful for silencing deprecation warnings that you can’t fix on
|
|
308
|
+
* your own. However, please <em>also</em> notify your dependencies of the deprecations
|
|
309
|
+
* so that they can get fixed as soon as possible!
|
|
310
|
+
*
|
|
311
|
+
* **Heads up!** If {@link compileString} or {@link compileStringAsync} is
|
|
312
|
+
* called without {@link StringOptions.url}, <em>all</em> stylesheets it loads
|
|
313
|
+
* will be considered dependencies. Since it doesn’t have a path of its own,
|
|
314
|
+
* everything it loads is coming from a load path rather than a relative
|
|
315
|
+
* import.
|
|
316
|
+
*
|
|
317
|
+
* @defaultValue `false`
|
|
318
|
+
* @category Messages
|
|
319
|
+
*/
|
|
320
|
+
quietDeps?: boolean;
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* A set of active deprecations to ignore.
|
|
324
|
+
*
|
|
325
|
+
* If a deprecation warning of any provided type is encountered during
|
|
326
|
+
* compilation, the compiler will ignore it instead.
|
|
327
|
+
*
|
|
328
|
+
* **Heads up!** The deprecated functionality you're depending on will
|
|
329
|
+
* eventually break.
|
|
330
|
+
*
|
|
331
|
+
* @category Messages
|
|
332
|
+
* @compatiblity dart: "1.74.0", node: false
|
|
333
|
+
*/
|
|
334
|
+
silenceDeprecations?: DeprecationOrId[];
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Whether or not Sass should generate a source map. If it does, the source
|
|
338
|
+
* map will be available as {@link CompileResult.sourceMap}.
|
|
339
|
+
*
|
|
340
|
+
* **Heads up!** Sass doesn't automatically add a `sourceMappingURL` comment
|
|
341
|
+
* to the generated CSS. It's up to callers to do that, since callers have
|
|
342
|
+
* full knowledge of where the CSS and the source map will exist in relation
|
|
343
|
+
* to one another and how they'll be served to the browser.
|
|
344
|
+
*
|
|
345
|
+
* @defaultValue `false`
|
|
346
|
+
* @category Output
|
|
347
|
+
*/
|
|
348
|
+
sourceMap?: boolean;
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Whether Sass should include the sources in the generated source map.
|
|
352
|
+
*
|
|
353
|
+
* This option has no effect if {@link sourceMap} is `false`.
|
|
354
|
+
*
|
|
355
|
+
* @defaultValue `false`
|
|
356
|
+
* @category Output
|
|
357
|
+
*/
|
|
358
|
+
sourceMapIncludeSources?: boolean;
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* The {@link OutputStyle} of the compiled CSS.
|
|
362
|
+
*
|
|
363
|
+
* @example
|
|
364
|
+
*
|
|
365
|
+
* ```js
|
|
366
|
+
* const source = `
|
|
367
|
+
* h1 {
|
|
368
|
+
* font-size: 40px;
|
|
369
|
+
* code {
|
|
370
|
+
* font-face: Roboto Mono;
|
|
371
|
+
* }
|
|
372
|
+
* }`;
|
|
373
|
+
*
|
|
374
|
+
* let result = sass.compileString(source, {style: "expanded"});
|
|
375
|
+
* console.log(result.css.toString());
|
|
376
|
+
* // h1 {
|
|
377
|
+
* // font-size: 40px;
|
|
378
|
+
* // }
|
|
379
|
+
* // h1 code {
|
|
380
|
+
* // font-face: Roboto Mono;
|
|
381
|
+
* // }
|
|
382
|
+
*
|
|
383
|
+
* result = sass.compileString(source, {style: "compressed"})
|
|
384
|
+
* console.log(result.css.toString());
|
|
385
|
+
* // h1{font-size:40px}h1 code{font-face:Roboto Mono}
|
|
386
|
+
* ```
|
|
387
|
+
*
|
|
388
|
+
* @category Output
|
|
389
|
+
*/
|
|
390
|
+
style?: OutputStyle;
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* By default, Dart Sass will print only five instances of the same
|
|
394
|
+
* deprecation warning per compilation to avoid deluging users in console
|
|
395
|
+
* noise. If you set `verbose` to `true`, it will instead print every
|
|
396
|
+
* deprecation warning it encounters.
|
|
397
|
+
*
|
|
398
|
+
* @defaultValue `false`
|
|
399
|
+
* @category Messages
|
|
400
|
+
*/
|
|
401
|
+
verbose?: boolean;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Options that can be passed to {@link compileString} or {@link
|
|
406
|
+
* compileStringAsync}.
|
|
407
|
+
*
|
|
408
|
+
* If the {@link StringOptions.importer} field isn't passed, the entrypoint file
|
|
409
|
+
* can load files relative to itself if a `file://` URL is passed to the {@link
|
|
410
|
+
* url} field. If `importer` is passed, the entrypoint file uses that importer
|
|
411
|
+
* to load files relative to itself.
|
|
412
|
+
*
|
|
413
|
+
* @typeParam sync - This lets the TypeScript checker verify that asynchronous
|
|
414
|
+
* {@link Importer}s, {@link FileImporter}s, and {@link CustomFunction}s aren't
|
|
415
|
+
* passed to {@link compile} or {@link compileString}.
|
|
416
|
+
*
|
|
417
|
+
* @category Options
|
|
418
|
+
*/
|
|
419
|
+
export interface StringOptions<sync extends 'sync' | 'async'>
|
|
420
|
+
extends Options<sync> {
|
|
421
|
+
/**
|
|
422
|
+
* The {@link Syntax} to use to parse the entrypoint stylesheet.
|
|
423
|
+
*
|
|
424
|
+
* @default `'scss'`
|
|
425
|
+
*
|
|
426
|
+
* @category Input
|
|
427
|
+
*/
|
|
428
|
+
syntax?: Syntax;
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* The importer to use to handle relative URL loads in the entrypoint
|
|
432
|
+
* stylesheet and stylesheets loaded relative to the entrypoint stylesheet.
|
|
433
|
+
*
|
|
434
|
+
* See {@link Options.importers} for details on how loads are resolved for the
|
|
435
|
+
* entrypoint stylesheet.
|
|
436
|
+
*
|
|
437
|
+
* @category Input
|
|
438
|
+
*/
|
|
439
|
+
importer?: Importer<sync> | FileImporter<sync>;
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* The canonical URL of the entrypoint stylesheet.
|
|
443
|
+
*
|
|
444
|
+
* See {@link Options.importers} for details on how loads are resolved for the
|
|
445
|
+
* entrypoint stylesheet.
|
|
446
|
+
*
|
|
447
|
+
* @category Input
|
|
448
|
+
* @compatibility feature: "Undefined URL with importer", dart: "1.75.0", node: false
|
|
449
|
+
*
|
|
450
|
+
* Earlier versions of Dart Sass required {@link url} to be defined when
|
|
451
|
+
* passing {@link StringOptions.importer}.
|
|
452
|
+
*/
|
|
453
|
+
url?: URL;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* @category Options
|
|
458
|
+
* @deprecated Use {@link StringOptions} instead.
|
|
459
|
+
*/
|
|
460
|
+
type StringOptionsWithoutImporter<sync extends 'sync' | 'async'> =
|
|
461
|
+
StringOptions<sync>;
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* @category Options
|
|
465
|
+
* @deprecated Use {@link StringOptions} instead.
|
|
466
|
+
*/
|
|
467
|
+
type StringOptionsWithImporter<sync extends 'sync' | 'async'> =
|
|
468
|
+
StringOptions<sync>;
|
|
@@ -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 {@link CustomFunction},
|
|
6
|
+
* {@link Importer}, and {@link FileImporter} so that TypeScript enforces that
|
|
7
|
+
* asynchronous plugins are only passed to {@link compileAsync} and {@link
|
|
8
|
+
* compileStringAsync}, not {@link compile} or {@link 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
|
+
* {@link SassList} in that it may contain a keyword map as well as the
|
|
12
|
+
* positional 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 {@link 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 {@link OrderedMap}
|
|
28
|
+
* from 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 {@link 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,137 @@
|
|
|
1
|
+
import {List, ValueObject} from 'immutable';
|
|
2
|
+
import {Value, SassNumber, SassString} from './index';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The type of values that can be arguments to a {@link SassCalculation}.
|
|
6
|
+
* @category Custom Function
|
|
7
|
+
* */
|
|
8
|
+
export type CalculationValue =
|
|
9
|
+
| SassNumber
|
|
10
|
+
| SassCalculation
|
|
11
|
+
| SassString
|
|
12
|
+
| CalculationOperation
|
|
13
|
+
| CalculationInterpolation;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Sass's [calculation
|
|
17
|
+
* type](https://sass-lang.com/documentation/values/calculations).
|
|
18
|
+
*
|
|
19
|
+
* Note: in the JS API calculations are not simplified eagerly. This also means
|
|
20
|
+
* that unsimplified calculations are not equal to the numbers they would be
|
|
21
|
+
* simplified to.
|
|
22
|
+
*
|
|
23
|
+
* @category Custom Function
|
|
24
|
+
*/
|
|
25
|
+
export class SassCalculation extends Value {
|
|
26
|
+
/**
|
|
27
|
+
* Creates a value that represents `calc(argument)`.
|
|
28
|
+
*
|
|
29
|
+
* @throws `Error` if `argument` is a quoted {@link SassString}
|
|
30
|
+
* @returns A calculation with the name `calc` and `argument` as its single
|
|
31
|
+
* argument.
|
|
32
|
+
*/
|
|
33
|
+
static calc(argument: CalculationValue): SassCalculation;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Creates a value that represents `min(arguments...)`.
|
|
37
|
+
*
|
|
38
|
+
* @throws `Error` if `arguments` contains a quoted {@link SassString}
|
|
39
|
+
* @returns A calculation with the name `min` and `arguments` as its
|
|
40
|
+
* arguments.
|
|
41
|
+
*/
|
|
42
|
+
static min(
|
|
43
|
+
arguments: CalculationValue[] | List<CalculationValue>
|
|
44
|
+
): SassCalculation;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Creates a value that represents `max(arguments...)`.
|
|
48
|
+
*
|
|
49
|
+
* @throws `Error` if `arguments` contains a quoted {@link SassString}
|
|
50
|
+
* @returns A calculation with the name `max` and `arguments` as its
|
|
51
|
+
* arguments.
|
|
52
|
+
*/
|
|
53
|
+
static max(
|
|
54
|
+
arguments: CalculationValue[] | List<CalculationValue>
|
|
55
|
+
): SassCalculation;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Creates a value that represents `clamp(value, min, max)`.
|
|
59
|
+
*
|
|
60
|
+
* @throws `Error` if any of `value`, `min`, or `max` are a quoted
|
|
61
|
+
* {@link SassString}.
|
|
62
|
+
* @throws `Error` if `value` is undefined and `max` is not undefined.
|
|
63
|
+
* @throws `Error` if either `value` or `max` is undefined and neither `min`
|
|
64
|
+
nor `value` is a {@link SassString} or {@link CalculationInterpolation}.
|
|
65
|
+
@returns A calculation with the name `clamp` and `min`, `value`, and `max`
|
|
66
|
+
as it's arguments, excluding any arguments that are undefined.
|
|
67
|
+
*/
|
|
68
|
+
static clamp(
|
|
69
|
+
min: CalculationValue,
|
|
70
|
+
value?: CalculationValue,
|
|
71
|
+
max?: CalculationValue
|
|
72
|
+
): SassCalculation;
|
|
73
|
+
|
|
74
|
+
/** Returns the calculation's `name` field. */
|
|
75
|
+
get name(): string;
|
|
76
|
+
|
|
77
|
+
/** Returns a list of the calculation's `arguments` */
|
|
78
|
+
get arguments(): List<CalculationValue>;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The set of possible operators in a Sass calculation.
|
|
83
|
+
* @category Custom Function
|
|
84
|
+
*/
|
|
85
|
+
export type CalculationOperator = '+' | '-' | '*' | '/';
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* A binary operation that can appear in a {@link SassCalculation}.
|
|
89
|
+
* @category Custom Function
|
|
90
|
+
*/
|
|
91
|
+
export class CalculationOperation implements ValueObject {
|
|
92
|
+
/**
|
|
93
|
+
* Creates a Sass CalculationOperation with the given `operator`, `left`, and
|
|
94
|
+
* `right` values.
|
|
95
|
+
* @throws `Error` if `left` or `right` are quoted {@link SassString}s.
|
|
96
|
+
*/
|
|
97
|
+
constructor(
|
|
98
|
+
operator: CalculationOperator,
|
|
99
|
+
left: CalculationValue,
|
|
100
|
+
right: CalculationValue
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
/** Returns the operation's `operator` field. */
|
|
104
|
+
get operator(): CalculationOperator;
|
|
105
|
+
|
|
106
|
+
/** Returns the operation's `left` field. */
|
|
107
|
+
get left(): CalculationValue;
|
|
108
|
+
|
|
109
|
+
/** Returns the operation's `right` field. */
|
|
110
|
+
get right(): CalculationValue;
|
|
111
|
+
|
|
112
|
+
equals(other: unknown): boolean;
|
|
113
|
+
|
|
114
|
+
hashCode(): number;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* A string injected into a {@link SassCalculation} using interpolation. Unlike
|
|
119
|
+
* unquoted strings, interpolations are always surrounded in parentheses when
|
|
120
|
+
* they appear in {@link CalculationOperation}s.
|
|
121
|
+
* @category Custom Function
|
|
122
|
+
*/
|
|
123
|
+
export class CalculationInterpolation implements ValueObject {
|
|
124
|
+
/**
|
|
125
|
+
* Creates a Sass CalculationInterpolation with the given `value`.
|
|
126
|
+
*/
|
|
127
|
+
constructor(value: string);
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Returns the interpolation's `value` field.
|
|
131
|
+
*/
|
|
132
|
+
get value(): string;
|
|
133
|
+
|
|
134
|
+
equals(other: unknown): boolean;
|
|
135
|
+
|
|
136
|
+
hashCode(): number;
|
|
137
|
+
}
|