95284ae0fa9836896a3959cdfe7020645819b8376047c0252773424f49494801d72fc2c5616ba50326fe96e91c834be6036c7fce437e818052c8890adda1da 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. import {List, ValueObject} from 'immutable';
  2. import {SassBoolean} from './boolean';
  3. import {SassCalculation} from './calculation';
  4. import {SassColor} from './color';
  5. import {SassFunction} from './function';
  6. import {ListSeparator} from './list';
  7. import {SassMap} from './map';
  8. import {SassMixin} from './mixin';
  9. import {SassNumber} from './number';
  10. import {SassString} from './string';
  11. export {SassArgumentList} from './argument_list';
  12. export {SassBoolean, sassTrue, sassFalse} from './boolean';
  13. export {
  14. SassCalculation,
  15. CalculationValue,
  16. CalculationOperator,
  17. CalculationOperation,
  18. CalculationInterpolation,
  19. } from './calculation';
  20. export {
  21. SassColor,
  22. ColorSpaceHsl,
  23. ChannelNameHsl,
  24. ColorSpaceHwb,
  25. ChannelNameHwb,
  26. ColorSpaceLab,
  27. ChannelNameLab,
  28. ColorSpaceLch,
  29. ChannelNameLch,
  30. ColorSpaceRgb,
  31. ChannelNameRgb,
  32. ColorSpaceXyz,
  33. ChannelNameXyz,
  34. ChannelName,
  35. GamutMapMethod,
  36. KnownColorSpace,
  37. PolarColorSpace,
  38. RectangularColorSpace,
  39. HueInterpolationMethod,
  40. } from './color';
  41. export {SassFunction} from './function';
  42. export {SassList, ListSeparator} from './list';
  43. export {SassMap} from './map';
  44. export {SassMixin} from './mixin';
  45. export {SassNumber} from './number';
  46. export {SassString} from './string';
  47. /**
  48. * Sass's [`null` value](https://sass-lang.com/documentation/values/null).
  49. *
  50. * @category Custom Function
  51. */
  52. export const sassNull: Value;
  53. /**
  54. * The abstract base class of Sass's value types.
  55. *
  56. * This is passed to and returned by {@link CustomFunction}s, which are passed
  57. * into the Sass implementation using {@link Options.functions}.
  58. *
  59. * @category Custom Function
  60. */
  61. export abstract class Value implements ValueObject {
  62. protected constructor();
  63. /**
  64. * This value as a list.
  65. *
  66. * All SassScript values can be used as lists. Maps count as lists of pairs,
  67. * and all other values count as single-value lists.
  68. *
  69. * @returns An immutable {@link List} from the [`immutable`
  70. * package](https://immutable-js.com/).
  71. */
  72. get asList(): List<Value>;
  73. /**
  74. * Whether this value as a list has brackets.
  75. *
  76. * All SassScript values can be used as lists. Maps count as lists of pairs,
  77. * and all other values count as single-value lists.
  78. */
  79. get hasBrackets(): boolean;
  80. /**
  81. * Whether the value counts as `true` in an `@if` statement and other
  82. * contexts.
  83. */
  84. get isTruthy(): boolean;
  85. /**
  86. * Returns JavaScript's `null` value if this is {@link sassNull}, and returns
  87. * `this` otherwise.
  88. */
  89. get realNull(): null | Value;
  90. /**
  91. * The separator for this value as a list.
  92. *
  93. * All SassScript values can be used as lists. Maps count as lists of pairs,
  94. * and all other values count as single-value lists.
  95. */
  96. get separator(): ListSeparator;
  97. /**
  98. * Converts `sassIndex` into a JavaScript-style index into the list returned
  99. * by {@link asList}.
  100. *
  101. * Sass indexes are one-based, while JavaScript indexes are zero-based. Sass
  102. * indexes may also be negative in order to index from the end of the list.
  103. *
  104. * @param sassIndex - The Sass-style index into this as a list.
  105. * @param name - The name of the function argument `sassIndex` came from
  106. * (without the `$`) if it came from an argument. Used for error reporting.
  107. * @throws `Error` If `sassIndex` isn't a number, if that number isn't an
  108. * integer, or if that integer isn't a valid index for {@link asList}.
  109. */
  110. sassIndexToListIndex(sassIndex: Value, name?: string): number;
  111. /**
  112. * Returns the value at index `index` in this value as a list, or `undefined`
  113. * if `index` isn't valid for this list.
  114. *
  115. * All SassScript values can be used as lists. Maps count as lists of pairs,
  116. * and all other values count as single-value lists.
  117. *
  118. * This is a shorthand for `this.asList.get(index)`, although it may be more
  119. * efficient in some cases.
  120. *
  121. * **Heads up!** This method uses the same indexing conventions as the
  122. * `immutable` package: unlike Sass the index of the first element is 0, but
  123. * like Sass negative numbers index from the end of the list.
  124. */
  125. get(index: number): Value | undefined;
  126. /**
  127. * Throws if `this` isn't a {@link SassBoolean}.
  128. *
  129. * **Heads up!** Functions should generally use {@link isTruthy} rather than
  130. * requiring a literal boolean.
  131. *
  132. * @param name - The name of the function argument `this` came from (without
  133. * the `$`) if it came from an argument. Used for error reporting.
  134. */
  135. assertBoolean(name?: string): SassBoolean;
  136. /**
  137. * Throws if `this` isn't a {@link SassCalculation}.
  138. *
  139. * @param name - The name of the function argument `this` came from (without
  140. * the `$`) if it came from an argument. Used for error reporting.
  141. */
  142. assertCalculation(name?: string): SassCalculation;
  143. /**
  144. * Throws if `this` isn't a {@link SassColor}.
  145. *
  146. * @param name - The name of the function argument `this` came from (without
  147. * the `$`) if it came from an argument. Used for error reporting.
  148. */
  149. assertColor(name?: string): SassColor;
  150. /**
  151. * Throws if `this` isn't a {@link SassFunction}.
  152. *
  153. * @param name - The name of the function argument `this` came from (without
  154. * the `$`) if it came from an argument. Used for error reporting.
  155. */
  156. assertFunction(name?: string): SassFunction;
  157. /**
  158. * Throws if `this` isn't a {@link SassMap}.
  159. *
  160. * @param name - The name of the function argument `this` came from (without
  161. * the `$`) if it came from an argument. Used for error reporting.
  162. */
  163. assertMap(name?: string): SassMap;
  164. /**
  165. * Throws if `this` isn't a {@link SassMixin}.
  166. *
  167. * @param name - The name of the function argument `this` came from (without
  168. * the `$`) if it came from an argument. Used for error reporting.
  169. */
  170. assertMixin(name?: string): SassMixin;
  171. /**
  172. * Throws if `this` isn't a {@link SassNumber}.
  173. *
  174. * @param name - The name of the function argument `this` came from (without
  175. * the `$`) if it came from an argument. Used for error reporting.
  176. */
  177. assertNumber(name?: string): SassNumber;
  178. /**
  179. * Throws if `this` isn't a {@link SassString}.
  180. *
  181. * @param name - The name of the function argument `this` came from (without
  182. * the `$`) if it came from an argument. Used for error reporting.
  183. */
  184. assertString(name?: string): SassString;
  185. /**
  186. * Returns `this` as a map if it counts as one (empty lists count as empty
  187. * maps) or `null` if it doesn't.
  188. */
  189. tryMap(): SassMap | null;
  190. /** Returns whether `this` represents the same value as `other`. */
  191. equals(other: Value): boolean;
  192. /** Returns a hash code that can be used to store `this` in a hash map. */
  193. hashCode(): number;
  194. /** @hidden */
  195. toString(): string;
  196. }