sass 1.43.5 → 1.45.0

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,652 @@
1
+ import {LegacyPluginThis} from './plugin_this';
2
+
3
+ /**
4
+ * A synchronous callback that implements a custom Sass function. This can be
5
+ * passed to [[LegacySharedOptions.functions]] for either [[render]] or
6
+ * [[renderSync]].
7
+ *
8
+ * If this throws an error, Sass will treat that as the function failing with
9
+ * that error message.
10
+ *
11
+ * ```js
12
+ * const result = sass.renderSync({
13
+ * file: 'style.scss',
14
+ * functions: {
15
+ * "sum($arg1, $arg2)": (arg1, arg2) => {
16
+ * if (!(arg1 instanceof sass.types.Number)) {
17
+ * throw new Error("$arg1: Expected a number");
18
+ * } else if (!(arg2 instanceof sass.types.Number)) {
19
+ * throw new Error("$arg2: Expected a number");
20
+ * }
21
+ * return new sass.types.Number(arg1.getValue() + arg2.getValue());
22
+ * }
23
+ * }
24
+ * });
25
+ * ```
26
+ *
27
+ * @param args - One argument for each argument that's declared in the signature
28
+ * that's passed to [[LegacySharedOptions.functions]]. If the signature [takes
29
+ * arbitrary arguments](https://sass-lang.com/documentation/at-rules/function#taking-arbitrary-arguments),
30
+ * they're passed as a single argument list in the last argument.
31
+ *
32
+ * @category Legacy
33
+ * @deprecated This only works with the legacy [[render]] and [[renderSync]]
34
+ * APIs. Use [[CustomFunction]] with [[compile]], [[compileString]],
35
+ * [[compileAsync]], and [[compileStringAsync]] instead.
36
+ */
37
+ export type LegacySyncFunction = (
38
+ this: LegacyPluginThis,
39
+ ...args: LegacyValue[]
40
+ ) => LegacyValue;
41
+
42
+ /**
43
+ * An asynchronous callback that implements a custom Sass function. This can be
44
+ * passed to [[LegacySharedOptions.functions]], but only for [[render]].
45
+ *
46
+ * An asynchronous function must return `undefined`. Its final argument will
47
+ * always be a callback, which it should call with the result of the function
48
+ * once it's done running.
49
+ *
50
+ * If this throws an error, Sass will treat that as the function failing with
51
+ * that error message.
52
+ *
53
+ * ```js
54
+ * sass.render({
55
+ * file: 'style.scss',
56
+ * functions: {
57
+ * "sum($arg1, $arg2)": (arg1, arg2, done) => {
58
+ * if (!(arg1 instanceof sass.types.Number)) {
59
+ * throw new Error("$arg1: Expected a number");
60
+ * } else if (!(arg2 instanceof sass.types.Number)) {
61
+ * throw new Error("$arg2: Expected a number");
62
+ * }
63
+ * done(new sass.types.Number(arg1.getValue() + arg2.getValue()));
64
+ * }
65
+ * }
66
+ * }, (result, error) => {
67
+ * // ...
68
+ * });
69
+ * ```
70
+ *
71
+ * @param args - One argument for each argument that's declared in the signature
72
+ * that's passed to [[LegacySharedOptions.functions]]. If the signature [takes
73
+ * arbitrary arguments](https://sass-lang.com/documentation/at-rules/function#taking-arbitrary-arguments),
74
+ * they're passed as a single argument list in the last argument before the
75
+ * callback.
76
+ *
77
+ * @category Legacy
78
+ * @deprecated This only works with the legacy [[render]] and [[renderSync]]
79
+ * APIs. Use [[CustomFunction]] with [[compile]], [[compileString]],
80
+ * [[compileAsync]], and [[compileStringAsync]] instead.
81
+ */
82
+ export type LegacyAsyncFunction = (
83
+ this: LegacyPluginThis,
84
+ ...args: [...LegacyValue[], (result: LegacyValue) => void]
85
+ ) => void;
86
+
87
+ /**
88
+ * A callback that implements a custom Sass function. For [[renderSync]], this
89
+ * must be a [[LegacySyncFunction]] which returns its result directly; for
90
+ * [[render]], it may be either a [[LegacySyncFunction]] or a
91
+ * [[LegacyAsyncFunction]] which calls a callback with its result.
92
+ *
93
+ * See [[LegacySharedOptions.functions]] for more details.
94
+ *
95
+ * @category Legacy
96
+ * @deprecated This only works with the legacy [[render]] and [[renderSync]]
97
+ * APIs. Use [[CustomFunction]] with [[compile]], [[compileString]],
98
+ * [[compileAsync]], and [[compileStringAsync]] instead.
99
+ */
100
+ export type LegacyFunction<sync extends 'sync' | 'async'> = sync extends 'async'
101
+ ? LegacySyncFunction | LegacyAsyncFunction
102
+ : LegacySyncFunction;
103
+
104
+ /**
105
+ * A type representing all the possible values that may be passed to or returned
106
+ * from a [[LegacyFunction]].
107
+ *
108
+ * @category Legacy
109
+ * @deprecated This only works with the legacy [[render]] and [[renderSync]]
110
+ * APIs. Use [[Value]] with [[compile]], [[compileString]], [[compileAsync]],
111
+ * and [[compileStringAsync]] instead.
112
+ */
113
+ export type LegacyValue =
114
+ | types.Null
115
+ | types.Number
116
+ | types.String
117
+ | types.Boolean
118
+ | types.Color
119
+ | types.List
120
+ | types.Map;
121
+
122
+ /**
123
+ * The namespace for value types used in the legacy function API.
124
+ *
125
+ * @category Legacy
126
+ * @deprecated This only works with the legacy [[render]] and [[renderSync]]
127
+ * APIs. Use [[Value]] with [[compile]], [[compileString]], [[compileAsync]],
128
+ * and [[compileStringAsync]] instead.
129
+ */
130
+ export namespace types {
131
+ /**
132
+ * The class for Sass's singleton [`null`
133
+ * value](https://sass-lang.com/documentation/values/null). The value itself
134
+ * can be accessed through the [[NULL]] field.
135
+ */
136
+ export class Null {
137
+ /** Sass's singleton `null` value. */
138
+ static readonly NULL: Null;
139
+ }
140
+
141
+ /**
142
+ * Sass's [number type](https://sass-lang.com/documentation/values/numbers).
143
+ */
144
+ export class Number {
145
+ /**
146
+ * @param value - The numeric value of the number.
147
+ *
148
+ * @param unit - If passed, the number's unit.
149
+ *
150
+ * Complex units can be represented as
151
+ * `<unit>*<unit>*.../<unit>*<unit>*...`, with numerator units on the
152
+ * left-hand side of the `/` and denominator units on the right. A number
153
+ * with only numerator units may omit the `/` and the units after it, and a
154
+ * number with only denominator units may be represented
155
+ * with no units before the `/`.
156
+ *
157
+ * @example
158
+ *
159
+ * ```scss
160
+ * new sass.types.Number(0.5); // == 0.5
161
+ * new sass.types.Number(10, "px"); // == 10px
162
+ * new sass.types.Number(10, "px*px"); // == 10px * 1px
163
+ * new sass.types.Number(10, "px/s"); // == math.div(10px, 1s)
164
+ * new sass.types.Number(10, "px*px/s*s"); // == 10px * math.div(math.div(1px, 1s), 1s)
165
+ * ```
166
+ */
167
+ constructor(value: number, unit?: string);
168
+
169
+ /**
170
+ * Returns the value of the number, ignoring units.
171
+ *
172
+ * **Heads up!** This means that `96px` and `1in` will return different
173
+ * values, even though they represent the same length.
174
+ *
175
+ * @example
176
+ *
177
+ * ```js
178
+ * const number = new sass.types.Number(10, "px");
179
+ * number.getValue(); // 10
180
+ * ```
181
+ */
182
+ getValue(): number;
183
+
184
+ /**
185
+ * Destructively modifies this number by setting its numeric value to
186
+ * `value`, independent of its units.
187
+ *
188
+ * @deprecated Use [[constructor]] instead.
189
+ */
190
+ setValue(value: number): void;
191
+
192
+ /**
193
+ * Returns a string representation of this number's units. Complex units are
194
+ * returned in the same format that [[constructor]] accepts them.
195
+ *
196
+ * @example
197
+ *
198
+ * ```js
199
+ * // number is `10px`.
200
+ * number.getUnit(); // "px"
201
+ *
202
+ * // number is `math.div(10px, 1s)`.
203
+ * number.getUnit(); // "px/s"
204
+ * ```
205
+ */
206
+ getUnit(): string;
207
+
208
+ /**
209
+ * Destructively modifies this number by setting its units to `unit`,
210
+ * independent of its numeric value. Complex units are specified in the same
211
+ * format as [[constructor]].
212
+ *
213
+ * @deprecated Use [[constructor]] instead.
214
+ */
215
+ setUnit(unit: string): void;
216
+ }
217
+
218
+ /**
219
+ * Sass's [string type](https://sass-lang.com/documentation/values/strings).
220
+ *
221
+ * **Heads up!** This API currently provides no way of distinguishing between
222
+ * a [quoted](https://sass-lang.com/documentation/values/strings#quoted) and
223
+ * [unquoted](https://sass-lang.com/documentation/values/strings#unquoted)
224
+ * string.
225
+ */
226
+ export class String {
227
+ /**
228
+ * Creates an unquoted string with the given contents.
229
+ *
230
+ * **Heads up!** This API currently provides no way of creating a
231
+ * [quoted](https://sass-lang.com/documentation/values/strings#quoted)
232
+ * string.
233
+ */
234
+ constructor(value: string);
235
+
236
+ /**
237
+ * Returns the contents of the string. If the string contains escapes,
238
+ * those escapes are included literally if it’s
239
+ * [unquoted](https://sass-lang.com/documentation/values/strings#unquoted),
240
+ * while the values of the escapes are included if it’s
241
+ * [quoted](https://sass-lang.com/documentation/values/strings#quoted).
242
+ *
243
+ * @example
244
+ *
245
+ * ```
246
+ * // string is `Arial`.
247
+ * string.getValue(); // "Arial"
248
+ *
249
+ * // string is `"Helvetica Neue"`.
250
+ * string.getValue(); // "Helvetica Neue"
251
+ *
252
+ * // string is `\1F46D`.
253
+ * string.getValue(); // "\\1F46D"
254
+ *
255
+ * // string is `"\1F46D"`.
256
+ * string.getValue(); // "👭"
257
+ * ```
258
+ */
259
+ getValue(): string;
260
+
261
+ /**
262
+ * Destructively modifies this string by setting its numeric value to
263
+ * `value`.
264
+ *
265
+ * **Heads up!** Even if the string was originally quoted, this will cause
266
+ * it to become unquoted.
267
+ *
268
+ * @deprecated Use [[constructor]] instead.
269
+ */
270
+ setValue(value: string): void;
271
+ }
272
+
273
+ /**
274
+ * Sass's [boolean type](https://sass-lang.com/documentation/values/booleans).
275
+ *
276
+ * Custom functions should respect Sass’s notion of
277
+ * [truthiness](https://sass-lang.com/documentation/at-rules/control/if#truthiness-and-falsiness)
278
+ * by treating `false` and `null` as falsey and everything else as truthy.
279
+ *
280
+ * **Heads up!** Boolean values can't be constructed, they can only be
281
+ * accessed through the [[TRUE]] and [[FALSE]] constants.
282
+ */
283
+ export class Boolean<T extends boolean = boolean> {
284
+ /**
285
+ * Returns `true` if this is Sass's `true` value and `false` if this is
286
+ * Sass's `false` value.
287
+ *
288
+ * @example
289
+ *
290
+ * ```js
291
+ * // boolean is `true`.
292
+ * boolean.getValue(); // true
293
+ * boolean === sass.types.Boolean.TRUE; // true
294
+ *
295
+ * // boolean is `false`.
296
+ * boolean.getValue(); // false
297
+ * boolean === sass.types.Boolean.FALSE; // true
298
+ * ```
299
+ */
300
+ getValue(): T;
301
+
302
+ /** Sass's `true` value. */
303
+ static readonly TRUE: Boolean<true>;
304
+
305
+ /** Sass's `false` value. */
306
+ static readonly FALSE: Boolean<false>;
307
+ }
308
+
309
+ /**
310
+ * Sass's [color type](https://sass-lang.com/documentation/values/colors).
311
+ */
312
+ export class Color {
313
+ /**
314
+ * Creates a new Sass color with the given red, green, blue, and alpha
315
+ * channels. The red, green, and blue channels must be integers between 0
316
+ * and 255 (inclusive), and alpha must be between 0 and 1 (inclusive).
317
+ *
318
+ * @example
319
+ *
320
+ * ```js
321
+ * new sass.types.Color(107, 113, 127); // #6b717f
322
+ * new sass.types.Color(0, 0, 0, 0); // rgba(0, 0, 0, 0)
323
+ * ```
324
+ */
325
+ constructor(r: number, g: number, b: number, a?: number);
326
+
327
+ /**
328
+ * Creates a new Sass color with alpha, red, green, and blue channels taken
329
+ * from respective two-byte chunks of a hexidecimal number.
330
+ *
331
+ * @example
332
+ *
333
+ * ```js
334
+ * new sass.types.Color(0xff6b717f); // #6b717f
335
+ * new sass.types.Color(0x00000000); // rgba(0, 0, 0, 0)
336
+ * ```
337
+ */
338
+ constructor(argb: number);
339
+
340
+ /**
341
+ * Returns the red channel of the color as an integer from 0 to 255.
342
+ *
343
+ * @example
344
+ *
345
+ * ```js
346
+ * // color is `#6b717f`.
347
+ * color.getR(); // 107
348
+ *
349
+ * // color is `#b37399`.
350
+ * color.getR(); // 179
351
+ * ```
352
+ */
353
+ getR(): number;
354
+
355
+ /**
356
+ * Sets the red channel of the color. The value must be an integer between 0
357
+ * and 255 (inclusive).
358
+ *
359
+ * @deprecated Use [[constructor]] instead.
360
+ */
361
+ setR(value: number): void;
362
+
363
+ /**
364
+ * Returns the green channel of the color as an integer from 0 to 255.
365
+ *
366
+ * @example
367
+ *
368
+ * ```js
369
+ * // color is `#6b717f`.
370
+ * color.getG(); // 113
371
+ *
372
+ * // color is `#b37399`.
373
+ * color.getG(); // 115
374
+ * ```
375
+ */
376
+ getG(): number;
377
+
378
+ /**
379
+ * Sets the green channel of the color. The value must be an integer between
380
+ * 0 and 255 (inclusive).
381
+ *
382
+ * @deprecated Use [[constructor]] instead.
383
+ */
384
+ setG(value: number): void;
385
+
386
+ /**
387
+ * Returns the blue channel of the color as an integer from 0 to 255.
388
+ *
389
+ * @example
390
+ *
391
+ * ```js
392
+ * // color is `#6b717f`.
393
+ * color.getB(); // 127
394
+ *
395
+ * // color is `#b37399`.
396
+ * color.getB(); // 153
397
+ * ```
398
+ */
399
+ getB(): number;
400
+
401
+ /**
402
+ * Sets the blue channel of the color. The value must be an integer between
403
+ * 0 and 255 (inclusive).
404
+ *
405
+ * @deprecated Use [[constructor]] instead.
406
+ */
407
+ setB(value: number): void;
408
+
409
+ /**
410
+ * Returns the alpha channel of the color as a number from 0 to 1.
411
+ *
412
+ * @example
413
+ *
414
+ * ```js
415
+ * // color is `#6b717f`.
416
+ * color.getA(); // 1
417
+ *
418
+ * // color is `transparent`.
419
+ * color.getA(); // 0
420
+ * ```
421
+ */
422
+ getA(): number;
423
+
424
+ /**
425
+ * Sets the alpha channel of the color. The value must be between 0 and 1
426
+ * (inclusive).
427
+ *
428
+ * @deprecated Use [[constructor]] instead.
429
+ */
430
+ setA(value: number): void;
431
+ }
432
+
433
+ /**
434
+ * Sass's [list type](https://sass-lang.com/documentation/values/lists).
435
+ *
436
+ * **Heads up!** This list type’s methods use 0-based indexing, even though
437
+ * within Sass lists use 1-based indexing. These methods also don’t support
438
+ * using negative numbers to index backwards from the end of the list.
439
+ */
440
+ export class List {
441
+ /**
442
+ * Creates a new Sass list.
443
+ *
444
+ * **Heads up!** The initial values of the list elements are undefined.
445
+ * These elements must be set using [[setValue]] before accessing them or
446
+ * passing the list back to Sass.
447
+ *
448
+ * @example
449
+ *
450
+ * ```js
451
+ * const list = new sass.types.List(3);
452
+ * list.setValue(0, new sass.types.Number(10, "px"));
453
+ * list.setValue(1, new sass.types.Number(15, "px"));
454
+ * list.setValue(2, new sass.types.Number(32, "px"));
455
+ * list; // 10px, 15px, 32px
456
+ * ```
457
+ *
458
+ * @param length - The number of (initially undefined) elements in the list.
459
+ * @param commaSeparator - If `true`, the list is comma-separated; otherwise,
460
+ * it's space-separated. Defaults to `true`.
461
+ */
462
+ constructor(length: number, commaSeparator?: boolean);
463
+
464
+ /**
465
+ * Returns the element at `index`, or `undefined` if that value hasn't yet
466
+ * been set.
467
+ *
468
+ * @example
469
+ *
470
+ * ```js
471
+ * // list is `10px, 15px, 32px`
472
+ * list.getValue(0); // 10px
473
+ * list.getValue(2); // 32px
474
+ * ```
475
+ *
476
+ * @param index - A (0-based) index into this list.
477
+ * @throws `Error` if `index` is less than 0 or greater than or equal to the
478
+ * number of elements in this list.
479
+ */
480
+ getValue(index: number): LegacyValue | undefined;
481
+
482
+ /**
483
+ * Sets the element at `index` to `value`.
484
+ *
485
+ * @example
486
+ *
487
+ * ```js
488
+ * // list is `10px, 15px, 32px`
489
+ * list.setValue(1, new sass.types.Number(18, "px"));
490
+ * list; // 10px, 18px, 32px
491
+ * ```
492
+ *
493
+ * @param index - A (0-based) index into this list.
494
+ * @throws `Error` if `index` is less than 0 or greater than or equal to the
495
+ * number of elements in this list.
496
+ */
497
+ setValue(index: number, value: LegacyValue): void;
498
+
499
+ /**
500
+ * Returns `true` if this list is comma-separated and `false` otherwise.
501
+ *
502
+ * @example
503
+ *
504
+ * ```js
505
+ * // list is `10px, 15px, 32px`
506
+ * list.getSeparator(); // true
507
+ *
508
+ * // list is `1px solid`
509
+ * list.getSeparator(); // false
510
+ * ```
511
+ */
512
+ getSeparator(): boolean;
513
+
514
+ /**
515
+ * Sets whether the list is comma-separated.
516
+ *
517
+ * @param isComma - `true` to make the list comma-separated, `false` otherwise.
518
+ */
519
+ setSeparator(isComma: boolean): void;
520
+
521
+ /**
522
+ * Returns the number of elements in the list.
523
+ *
524
+ * @example
525
+ *
526
+ * ```js
527
+ * // list is `10px, 15px, 32px`
528
+ * list.getLength(); // 3
529
+ *
530
+ * // list is `1px solid`
531
+ * list.getLength(); // 2
532
+ * ```
533
+ */
534
+ getLength(): number;
535
+ }
536
+
537
+ /**
538
+ * Sass's [map type](https://sass-lang.com/documentation/values/maps).
539
+ *
540
+ * **Heads up!** This map type is represented as a list of key-value pairs
541
+ * rather than a mapping from keys to values. The only way to find the value
542
+ * associated with a given key is to iterate through the map checking for that
543
+ * key. Maps created through this API are still forbidden from having duplicate
544
+ * keys.
545
+ */
546
+ export class Map {
547
+ /**
548
+ * Creates a new Sass map.
549
+ *
550
+ * **Heads up!** The initial keys and values of the map are undefined. They
551
+ * must be set using [[setKey]] and [[setValue]] before accessing them or
552
+ * passing the map back to Sass.
553
+ *
554
+ * @example
555
+ *
556
+ * ```js
557
+ * const map = new sass.types.Map(2);
558
+ * map.setKey(0, new sass.types.String("width"));
559
+ * map.setValue(0, new sass.types.Number(300, "px"));
560
+ * map.setKey(1, new sass.types.String("height"));
561
+ * map.setValue(1, new sass.types.Number(100, "px"));
562
+ * map; // (width: 300px, height: 100px)
563
+ * ```
564
+ *
565
+ * @param length - The number of (initially undefined) key/value pairs in the map.
566
+ */
567
+ constructor(length: number);
568
+
569
+ /**
570
+ * Returns the value in the key/value pair at `index`.
571
+ *
572
+ * @example
573
+ *
574
+ * ```js
575
+ * // map is `(width: 300px, height: 100px)`
576
+ * map.getValue(0); // 300px
577
+ * map.getValue(1); // 100px
578
+ * ```
579
+ *
580
+ * @param index - A (0-based) index of a key/value pair in this map.
581
+ * @throws `Error` if `index` is less than 0 or greater than or equal to the
582
+ * number of pairs in this map.
583
+ */
584
+ getValue(index: number): LegacyValue;
585
+
586
+ /**
587
+ * Sets the value in the key/value pair at `index` to `value`.
588
+ *
589
+ * @example
590
+ *
591
+ * ```js
592
+ * // map is `("light": 200, "medium": 400, "bold": 600)`
593
+ * map.setValue(1, new sass.types.Number(300));
594
+ * map; // ("light": 200, "medium": 300, "bold": 600)
595
+ * ```
596
+ *
597
+ * @param index - A (0-based) index of a key/value pair in this map.
598
+ * @throws `Error` if `index` is less than 0 or greater than or equal to the
599
+ * number of pairs in this map.
600
+ */
601
+ setValue(index: number, value: LegacyValue): void;
602
+
603
+ /**
604
+ * Returns the key in the key/value pair at `index`.
605
+ *
606
+ * @example
607
+ *
608
+ * ```js
609
+ * // map is `(width: 300px, height: 100px)`
610
+ * map.getKey(0); // width
611
+ * map.getKey(1); // height
612
+ * ```
613
+ *
614
+ * @param index - A (0-based) index of a key/value pair in this map.
615
+ * @throws `Error` if `index` is less than 0 or greater than or equal to the
616
+ * number of pairs in this map.
617
+ */
618
+ getKey(index: number): LegacyValue;
619
+
620
+ /**
621
+ * Sets the value in the key/value pair at `index` to `value`.
622
+ *
623
+ * @example
624
+ *
625
+ * ```js
626
+ * // map is `("light": 200, "medium": 400, "bold": 600)`
627
+ * map.setValue(1, new sass.types.String("lighter"));
628
+ * map; // ("lighter": 200, "medium": 300, "bold": 600)
629
+ * ```
630
+ *
631
+ * @param index - A (0-based) index of a key/value pair in this map.
632
+ * @throws `Error` if `index` is less than 0 or greater than or equal to the
633
+ * number of pairs in this map.
634
+ */
635
+ setKey(index: number, key: LegacyValue): void;
636
+
637
+ /**
638
+ * Returns the number of key/value pairs in this map.
639
+ *
640
+ * @example
641
+ *
642
+ * ```js
643
+ * // map is `("light": 200, "medium": 400, "bold": 600)`
644
+ * map.getLength(); // 3
645
+ *
646
+ * // map is `(width: 300px, height: 100px)`
647
+ * map.getLength(); // 2
648
+ * ```
649
+ */
650
+ getLength(): number;
651
+ }
652
+ }