-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
calculation.d.ts
137 lines (119 loc) · 3.91 KB
/
calculation.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import {List, ValueObject} from 'immutable';
import {Value, SassNumber, SassString} from './index';
/**
* The type of values that can be arguments to a {@link SassCalculation}.
* @category Custom Function
* */
export type CalculationValue =
| SassNumber
| SassCalculation
| SassString
| CalculationOperation
| CalculationInterpolation;
/**
* Sass's [calculation
* type](https://sass-lang.com/documentation/values/calculations).
*
* Note: in the JS API calculations are not simplified eagerly. This also means
* that unsimplified calculations are not equal to the numbers they would be
* simplified to.
*
* @category Custom Function
*/
export class SassCalculation extends Value {
/**
* Creates a value that represents `calc(argument)`.
*
* @throws `Error` if `argument` is a quoted {@link SassString}
* @returns A calculation with the name `calc` and `argument` as its single
* argument.
*/
static calc(argument: CalculationValue): SassCalculation;
/**
* Creates a value that represents `min(arguments...)`.
*
* @throws `Error` if `arguments` contains a quoted {@link SassString}
* @returns A calculation with the name `min` and `arguments` as its
* arguments.
*/
static min(
arguments: CalculationValue[] | List<CalculationValue>
): SassCalculation;
/**
* Creates a value that represents `max(arguments...)`.
*
* @throws `Error` if `arguments` contains a quoted {@link SassString}
* @returns A calculation with the name `max` and `arguments` as its
* arguments.
*/
static max(
arguments: CalculationValue[] | List<CalculationValue>
): SassCalculation;
/**
* Creates a value that represents `clamp(value, min, max)`.
*
* @throws `Error` if any of `value`, `min`, or `max` are a quoted
* {@link SassString}.
* @throws `Error` if `value` is undefined and `max` is not undefined.
* @throws `Error` if either `value` or `max` is undefined and neither `min`
nor `value` is a {@link SassString} or {@link CalculationInterpolation}.
@returns A calculation with the name `clamp` and `min`, `value`, and `max`
as it's arguments, excluding any arguments that are undefined.
*/
static clamp(
min: CalculationValue,
value?: CalculationValue,
max?: CalculationValue
): SassCalculation;
/** Returns the calculation's `name` field. */
get name(): string;
/** Returns a list of the calculation's `arguments` */
get arguments(): List<CalculationValue>;
}
/**
* The set of possible operators in a Sass calculation.
* @category Custom Function
*/
export type CalculationOperator = '+' | '-' | '*' | '/';
/**
* A binary operation that can appear in a {@link SassCalculation}.
* @category Custom Function
*/
export class CalculationOperation implements ValueObject {
/**
* Creates a Sass CalculationOperation with the given `operator`, `left`, and
* `right` values.
* @throws `Error` if `left` or `right` are quoted {@link SassString}s.
*/
constructor(
operator: CalculationOperator,
left: CalculationValue,
right: CalculationValue
);
/** Returns the operation's `operator` field. */
get operator(): CalculationOperator;
/** Returns the operation's `left` field. */
get left(): CalculationValue;
/** Returns the operation's `right` field. */
get right(): CalculationValue;
equals(other: unknown): boolean;
hashCode(): number;
}
/**
* A string injected into a {@link SassCalculation} using interpolation. Unlike
* unquoted strings, interpolations are always surrounded in parentheses when
* they appear in {@link CalculationOperation}s.
* @category Custom Function
*/
export class CalculationInterpolation implements ValueObject {
/**
* Creates a Sass CalculationInterpolation with the given `value`.
*/
constructor(value: string);
/**
* Returns the interpolation's `value` field.
*/
get value(): string;
equals(other: unknown): boolean;
hashCode(): number;
}