| 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 |
} |