sass 1.63.6 → 1.64.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.
package/sass.default.js CHANGED
@@ -13,6 +13,9 @@ export const compileStringAsync = _cliPkgExports.compileStringAsync;
13
13
  export const Logger = _cliPkgExports.Logger;
14
14
  export const SassArgumentList = _cliPkgExports.SassArgumentList;
15
15
  export const SassBoolean = _cliPkgExports.SassBoolean;
16
+ export const SassCalculation = _cliPkgExports.SassCalculation;
17
+ export const CalculationOperation = _cliPkgExports.CalculationOperation;
18
+ export const CalculationInterpolation = _cliPkgExports.CalculationInterpolation;
16
19
  export const SassColor = _cliPkgExports.SassColor;
17
20
  export const SassFunction = _cliPkgExports.SassFunction;
18
21
  export const SassList = _cliPkgExports.SassList;
package/sass.node.mjs CHANGED
@@ -7,6 +7,9 @@ export const compileStringAsync = cjs.compileStringAsync;
7
7
  export const Logger = cjs.Logger;
8
8
  export const SassArgumentList = cjs.SassArgumentList;
9
9
  export const SassBoolean = cjs.SassBoolean;
10
+ export const SassCalculation = cjs.SassCalculation;
11
+ export const CalculationOperation = cjs.CalculationOperation;
12
+ export const CalculationInterpolation = cjs.CalculationInterpolation;
10
13
  export const SassColor = cjs.SassColor;
11
14
  export const SassFunction = cjs.SassFunction;
12
15
  export const SassList = cjs.SassList;
@@ -67,6 +70,18 @@ export default {
67
70
  defaultExportDeprecation();
68
71
  return cjs.SassBoolean;
69
72
  },
73
+ get SassCalculation() {
74
+ defaultExportDeprecation();
75
+ return cjs.SassCalculation;
76
+ },
77
+ get CalculationOperation() {
78
+ defaultExportDeprecation();
79
+ return cjs.CalculationOperation;
80
+ },
81
+ get CalculationInterpolation() {
82
+ defaultExportDeprecation();
83
+ return cjs.CalculationInterpolation;
84
+ },
70
85
  get SassColor() {
71
86
  defaultExportDeprecation();
72
87
  return cjs.SassColor;
package/types/index.d.ts CHANGED
@@ -23,9 +23,14 @@ export {
23
23
  } from './options';
24
24
  export {PromiseOr} from './util/promise_or';
25
25
  export {
26
+ CalculationInterpolation,
27
+ CalculationOperation,
28
+ CalculationOperator,
29
+ CalculationValue,
26
30
  ListSeparator,
27
31
  SassArgumentList,
28
32
  SassBoolean,
33
+ SassCalculation,
29
34
  SassColor,
30
35
  SassFunction,
31
36
  SassList,
@@ -390,9 +390,8 @@ export interface LegacySharedOptions<sync extends 'sync' | 'async'> {
390
390
  * whose values are {@link LegacyFunction}s. Each function should take the
391
391
  * same arguments as its signature.
392
392
  *
393
- * Functions are passed JavaScript representations of [Sass value
394
- * types](https://sass-lang.com/documentation/js-api#value-types), and must
395
- * return the same.
393
+ * Functions are passed subclasses of {@link LegacyValue}, and must return the
394
+ * same.
396
395
  *
397
396
  * **Heads up!** When writing custom functions, it’s important to ensure that
398
397
  * all the arguments are the types you expect. Otherwise, users’ stylesheets
@@ -129,9 +129,9 @@ export interface Options<sync extends 'sync' | 'async'> {
129
129
  * rule`](https://sass-lang.com/documentation/at-rules/function) and whose
130
130
  * values are {@link CustomFunction}s.
131
131
  *
132
- * Functions are passed JavaScript representations of [Sass value
133
- * types](https://sass-lang.com/documentation/js-api#value-types), and must
134
- * return the same.
132
+ * Functions are passed subclasses of {@link Value}, and must return the same.
133
+ * If the return value includes {@link SassCalculation}s they will be
134
+ * simplified before being returned.
135
135
  *
136
136
  * When writing custom functions, it's important to make them as user-friendly
137
137
  * and as close to the standards set by Sass's core functions as possible. Some
@@ -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
+ }
@@ -1,6 +1,7 @@
1
1
  import {List, ValueObject} from 'immutable';
2
2
 
3
3
  import {SassBoolean} from './boolean';
4
+ import {SassCalculation} from './calculation';
4
5
  import {SassColor} from './color';
5
6
  import {SassFunction} from './function';
6
7
  import {ListSeparator} from './list';
@@ -10,6 +11,13 @@ import {SassString} from './string';
10
11
 
11
12
  export {SassArgumentList} from './argument_list';
12
13
  export {SassBoolean, sassTrue, sassFalse} from './boolean';
14
+ export {
15
+ SassCalculation,
16
+ CalculationValue,
17
+ CalculationOperator,
18
+ CalculationOperation,
19
+ CalculationInterpolation,
20
+ } from './calculation';
13
21
  export {SassColor} from './color';
14
22
  export {SassFunction} from './function';
15
23
  export {SassList, ListSeparator} from './list';
@@ -116,6 +124,14 @@ export abstract class Value implements ValueObject {
116
124
  */
117
125
  assertBoolean(name?: string): SassBoolean;
118
126
 
127
+ /**
128
+ * Throws if `this` isn't a {@link SassCalculation}.
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
+ assertCalculation(name?: string): SassCalculation;
134
+
119
135
  /**
120
136
  * Throws if `this` isn't a {@link SassColor}.
121
137
  *