sass-embedded 1.77.8 → 1.79.1

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.
Files changed (53) hide show
  1. package/dist/bin/sass.js +23 -0
  2. package/dist/bin/sass.js.map +1 -0
  3. package/dist/jest.config.js +1 -0
  4. package/dist/jest.config.js.map +1 -1
  5. package/dist/lib/src/compiler/async.js +32 -24
  6. package/dist/lib/src/compiler/async.js.map +1 -1
  7. package/dist/lib/src/compiler/sync.js +40 -32
  8. package/dist/lib/src/compiler/sync.js.map +1 -1
  9. package/dist/lib/src/compiler/utils.js +4 -3
  10. package/dist/lib/src/compiler/utils.js.map +1 -1
  11. package/dist/lib/src/compiler-path.js +14 -6
  12. package/dist/lib/src/compiler-path.js.map +1 -1
  13. package/dist/lib/src/deprecations.js +99 -3
  14. package/dist/lib/src/deprecations.js.map +1 -1
  15. package/dist/lib/src/dispatcher.js +3 -2
  16. package/dist/lib/src/dispatcher.js.map +1 -1
  17. package/dist/lib/src/elf.js +81 -0
  18. package/dist/lib/src/elf.js.map +1 -0
  19. package/dist/lib/src/function-registry.js +3 -2
  20. package/dist/lib/src/function-registry.js.map +1 -1
  21. package/dist/lib/src/importer-registry.js +16 -14
  22. package/dist/lib/src/importer-registry.js.map +1 -1
  23. package/dist/lib/src/legacy/index.js +6 -0
  24. package/dist/lib/src/legacy/index.js.map +1 -1
  25. package/dist/lib/src/legacy/value/wrap.js +2 -2
  26. package/dist/lib/src/legacy/value/wrap.js.map +1 -1
  27. package/dist/lib/src/message-transformer.js +3 -2
  28. package/dist/lib/src/message-transformer.js.map +1 -1
  29. package/dist/lib/src/protofier.js +104 -66
  30. package/dist/lib/src/protofier.js.map +1 -1
  31. package/dist/lib/src/sync-process/sync-message-port.js +8 -4
  32. package/dist/lib/src/sync-process/sync-message-port.js.map +1 -1
  33. package/dist/lib/src/value/calculations.js +4 -2
  34. package/dist/lib/src/value/calculations.js.map +1 -1
  35. package/dist/lib/src/value/color.js +814 -199
  36. package/dist/lib/src/value/color.js.map +1 -1
  37. package/dist/lib/src/vendor/deprecations.js +35 -0
  38. package/dist/lib/src/vendor/deprecations.js.map +1 -1
  39. package/dist/lib/src/vendor/embedded_sass_pb.js +223 -2293
  40. package/dist/lib/src/vendor/embedded_sass_pb.js.map +1 -1
  41. package/dist/package.json +32 -24
  42. package/dist/tool/prepare-optional-release.js +2 -26
  43. package/dist/tool/prepare-optional-release.js.map +1 -1
  44. package/dist/tool/utils.js +2 -5
  45. package/dist/tool/utils.js.map +1 -1
  46. package/dist/types/deprecations.d.ts +36 -1
  47. package/dist/types/index.d.ts +19 -1
  48. package/dist/types/index.m.d.ts +19 -1
  49. package/dist/types/legacy/options.d.ts +40 -0
  50. package/dist/types/logger/index.d.ts +32 -16
  51. package/dist/types/value/color.d.ts +505 -67
  52. package/dist/types/value/index.d.ts +21 -1
  53. package/package.json +32 -24
@@ -5,254 +5,869 @@
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.SassColor = void 0;
7
7
  const index_1 = require("./index");
8
- const utils_1 = require("./utils");
8
+ const deprecations_1 = require("../deprecations");
9
+ const utils_1 = require("../utils");
10
+ const utils_2 = require("./utils");
9
11
  const immutable_1 = require("immutable");
12
+ const colorjs_io_1 = require("colorjs.io");
13
+ /** Legacy determination of color space by channel name. */
14
+ function getColorSpace(options) {
15
+ if (typeof options.red === 'number')
16
+ return 'rgb';
17
+ if (typeof options.saturation === 'number')
18
+ return 'hsl';
19
+ if (typeof options.whiteness === 'number')
20
+ return 'hwb';
21
+ throw (0, utils_1.valueError)('No color space found');
22
+ }
23
+ /**
24
+ * Convert from the ColorJS representation of a missing component (`NaN`) to
25
+ * `null`.
26
+ */
27
+ function NaNtoNull(val) {
28
+ return Number.isNaN(val) ? null : val;
29
+ }
30
+ /**
31
+ * Convert from the ColorJS representation of a missing component (`NaN`) to
32
+ * `0`.
33
+ */
34
+ function NaNtoZero(val) {
35
+ return Number.isNaN(val) ? 0 : val;
36
+ }
37
+ /** Convert from sRGB (0-1) to RGB (0-255) units. */
38
+ function coordToRgb(val) {
39
+ return val * 255;
40
+ }
41
+ /** Normalize `hue` values to be within the range `[0, 360)`. */
42
+ function normalizeHue(val) {
43
+ return (0, utils_2.positiveMod)(val, 360);
44
+ }
45
+ /**
46
+ * Normalize discrepancies between Sass color spaces and ColorJS color space
47
+ * ids, converting Sass values to ColorJS values.
48
+ */
49
+ function encodeSpaceForColorJs(space) {
50
+ switch (space) {
51
+ case 'rgb':
52
+ return 'srgb';
53
+ case 'a98-rgb':
54
+ return 'a98rgb';
55
+ case 'display-p3':
56
+ return 'p3';
57
+ case 'prophoto-rgb':
58
+ return 'prophoto';
59
+ }
60
+ return space;
61
+ }
62
+ /**
63
+ * Normalize discrepancies between Sass's [GamutMapMethod] and Color.js's
64
+ * `method` option.
65
+ */
66
+ function encodeGamutMapMethodForColorJs(method) {
67
+ return method === 'local-minde' ? 'css' : method;
68
+ }
69
+ /**
70
+ * Normalize discrepancies between Sass color spaces and ColorJS color space
71
+ * ids, converting ColorJS values to Sass values.
72
+ */
73
+ function decodeSpaceFromColorJs(space, isRgb = false) {
74
+ switch (space) {
75
+ case 'srgb':
76
+ return isRgb ? 'rgb' : space;
77
+ case 'xyz-d65':
78
+ return 'xyz';
79
+ case 'a98rgb':
80
+ return 'a98-rgb';
81
+ case 'p3':
82
+ return 'display-p3';
83
+ case 'prophoto':
84
+ return 'prophoto-rgb';
85
+ }
86
+ return space;
87
+ }
88
+ /**
89
+ * Normalize discrepancies between Sass channel names and ColorJS channel ids,
90
+ * converting Sass values to ColorJS values.
91
+ *
92
+ * @TODO Waiting on a new release of ColorJS that allows Lab spaces to accept
93
+ * `lightness` instead of only `l` and not as a channel name.
94
+ * Fixed in: https://github.com/LeaVerou/color.js/pull/348
95
+ */
96
+ function encodeChannelForColorJs(channel) {
97
+ if (channel === 'lightness')
98
+ return 'l';
99
+ return channel;
100
+ }
101
+ /**
102
+ * Implement our own check of channel name validity for a given space, because
103
+ * ColorJS allows e.g. `b` for any of `blue`, `blackness`, or `b` channels.
104
+ */
105
+ function validateChannelInSpace(channel, space) {
106
+ if (channel === 'alpha')
107
+ return;
108
+ let valid = false;
109
+ switch (space) {
110
+ case 'rgb':
111
+ case 'srgb':
112
+ case 'srgb-linear':
113
+ case 'display-p3':
114
+ case 'a98-rgb':
115
+ case 'prophoto-rgb':
116
+ case 'rec2020':
117
+ valid = ['red', 'green', 'blue'].includes(channel);
118
+ break;
119
+ case 'hsl':
120
+ valid = ['hue', 'saturation', 'lightness'].includes(channel);
121
+ break;
122
+ case 'hwb':
123
+ valid = ['hue', 'whiteness', 'blackness'].includes(channel);
124
+ break;
125
+ case 'lab':
126
+ case 'oklab':
127
+ valid = ['lightness', 'a', 'b'].includes(channel);
128
+ break;
129
+ case 'lch':
130
+ case 'oklch':
131
+ valid = ['lightness', 'chroma', 'hue'].includes(channel);
132
+ break;
133
+ case 'xyz':
134
+ case 'xyz-d65':
135
+ case 'xyz-d50':
136
+ valid = ['x', 'y', 'z'].includes(channel);
137
+ break;
138
+ }
139
+ if (!valid) {
140
+ throw (0, utils_1.valueError)(`Unknown channel name "${channel}" for color space "${space}".`);
141
+ }
142
+ }
143
+ /** Determine whether the given space is a polar color space. */
144
+ function isPolarColorSpace(space) {
145
+ switch (space) {
146
+ case 'hsl':
147
+ case 'hwb':
148
+ case 'lch':
149
+ case 'oklch':
150
+ return true;
151
+ default:
152
+ return false;
153
+ }
154
+ }
155
+ /**
156
+ * Convert from ColorJS coordinates (which use `NaN` for missing components, and
157
+ * a range of `0-1` for `rgb` channel values) to Sass Color coordinates (which
158
+ * use `null` for missing components, and a range of `0-255` for `rgb` channel
159
+ * values).
160
+ */
161
+ function decodeCoordsFromColorJs(coords, // ColorJS coordinates
162
+ isRgb = false // Whether this color is in the `rgb` color space
163
+ ) {
164
+ let newCoords = coords;
165
+ // If this color is in the `rgb` space, convert channel values to `0-255`
166
+ if (isRgb)
167
+ newCoords = newCoords.map(coordToRgb);
168
+ // Convert `NaN` values to `null`
169
+ return newCoords.map(NaNtoNull);
170
+ }
171
+ /** Returns `true` if `val` is a `number` or `null`. */
172
+ function isNumberOrNull(val) {
173
+ return val === null || typeof val === 'number';
174
+ }
175
+ /**
176
+ * Emit deprecation warnings when legacy color spaces set `alpha` or channel
177
+ * values to `null` without explicitly setting the `space`.
178
+ */
179
+ function checkChangeDeprecations(options, channels) {
180
+ if (options.alpha === null)
181
+ emitNullAlphaDeprecation();
182
+ for (const channel of channels) {
183
+ if (options[channel] === null)
184
+ emitColor4ApiChangeNullDeprecation(channel);
185
+ }
186
+ }
187
+ /** Warn users about legacy color channel getters. */
188
+ function emitColor4ApiGetterDeprecation(name) {
189
+ (0, deprecations_1.warnForHostSideDeprecation)(`\`${name}\` is deprecated, use \`channel\` instead.` +
190
+ '\n' +
191
+ 'More info: https://sass-lang.com/d/color-4-api', deprecations_1.deprecations['color-4-api']);
192
+ }
193
+ /**
194
+ * Warn users about changing channels not in the current color space without
195
+ * explicitly setting `space`.
196
+ */
197
+ function emitColor4ApiChangeSpaceDeprecation() {
198
+ (0, deprecations_1.warnForHostSideDeprecation)("Changing a channel not in this color's space without explicitly " +
199
+ 'specifying the `space` option is deprecated.' +
200
+ '\n' +
201
+ 'More info: https://sass-lang.com/d/color-4-api', deprecations_1.deprecations['color-4-api']);
202
+ }
203
+ /** Warn users about `null` channel values without setting `space`. */
204
+ function emitColor4ApiChangeNullDeprecation(channel) {
205
+ (0, deprecations_1.warnForHostSideDeprecation)(`Passing \`${channel}: null\` without setting \`space\` is deprecated.` +
206
+ '\n' +
207
+ 'More info: https://sass-lang.com/d/color-4-api', deprecations_1.deprecations['color-4-api']);
208
+ }
209
+ /** Warn users about null-alpha deprecation. */
210
+ function emitNullAlphaDeprecation() {
211
+ (0, deprecations_1.warnForHostSideDeprecation)('Passing `alpha: null` without setting `space` is deprecated.' +
212
+ '\n' +
213
+ 'More info: https://sass-lang.com/d/null-alpha', deprecations_1.deprecations['null-alpha']);
214
+ }
215
+ /**
216
+ * Determines whether the options passed to the Constructor include an existing
217
+ * ColorJS color object.
218
+ */
219
+ function optionsHaveColor(opts) {
220
+ return opts.color instanceof colorjs_io_1.default;
221
+ }
10
222
  /** A SassScript color. */
11
223
  class SassColor extends index_1.Value {
12
- constructor(color) {
224
+ // Sets channel names based on this color's color space
225
+ setChannelIds(space) {
226
+ switch (space) {
227
+ case 'rgb':
228
+ case 'srgb':
229
+ case 'srgb-linear':
230
+ case 'display-p3':
231
+ case 'a98-rgb':
232
+ case 'prophoto-rgb':
233
+ case 'rec2020':
234
+ this.channel0Id = 'red';
235
+ this.channel1Id = 'green';
236
+ this.channel2Id = 'blue';
237
+ break;
238
+ case 'hsl':
239
+ this.channel0Id = 'hue';
240
+ this.channel1Id = 'saturation';
241
+ this.channel2Id = 'lightness';
242
+ break;
243
+ case 'hwb':
244
+ this.channel0Id = 'hue';
245
+ this.channel1Id = 'whiteness';
246
+ this.channel2Id = 'blackness';
247
+ break;
248
+ case 'lab':
249
+ case 'oklab':
250
+ this.channel0Id = 'lightness';
251
+ this.channel1Id = 'a';
252
+ this.channel2Id = 'b';
253
+ break;
254
+ case 'lch':
255
+ case 'oklch':
256
+ this.channel0Id = 'lightness';
257
+ this.channel1Id = 'chroma';
258
+ this.channel2Id = 'hue';
259
+ break;
260
+ case 'xyz':
261
+ case 'xyz-d65':
262
+ case 'xyz-d50':
263
+ this.channel0Id = 'x';
264
+ this.channel1Id = 'y';
265
+ this.channel2Id = 'z';
266
+ break;
267
+ }
268
+ }
269
+ constructor(optionsMaybeWithColor) {
270
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
13
271
  super();
14
- if ('red' in color) {
15
- this.redInternal = (0, utils_1.fuzzyAssertInRange)(Math.round(color.red), 0, 255, 'red');
16
- this.greenInternal = (0, utils_1.fuzzyAssertInRange)(Math.round(color.green), 0, 255, 'green');
17
- this.blueInternal = (0, utils_1.fuzzyAssertInRange)(Math.round(color.blue), 0, 255, 'blue');
272
+ // Boolean indicating whether this color is in RGB format
273
+ //
274
+ // ColorJS treats `rgb` as an output format of the `srgb` color space, while
275
+ // Sass treats it as its own color space. By internally tracking whether this
276
+ // color is `rgb` or not, we can use `srgb` consistently for ColorJS while
277
+ // still returning expected `rgb` values for Sass users.
278
+ this.isRgb = false;
279
+ let options;
280
+ // Use existing ColorJS color object from options for the new SassColor
281
+ if (optionsHaveColor(optionsMaybeWithColor)) {
282
+ const { color, space } = optionsMaybeWithColor;
283
+ if (space === 'rgb')
284
+ this.isRgb = true;
285
+ this.setChannelIds(space);
286
+ this.color = color;
287
+ return;
288
+ }
289
+ else {
290
+ options = optionsMaybeWithColor;
18
291
  }
19
- else if ('saturation' in color) {
20
- this.hueInternal = (0, utils_1.positiveMod)(color.hue, 360);
21
- this.saturationInternal = (0, utils_1.fuzzyAssertInRange)(color.saturation, 0, 100, 'saturation');
22
- this.lightnessInternal = (0, utils_1.fuzzyAssertInRange)(color.lightness, 0, 100, 'lightness');
292
+ const space = (_a = options.space) !== null && _a !== void 0 ? _a : getColorSpace(options);
293
+ this.setChannelIds(space);
294
+ if (space === 'rgb')
295
+ this.isRgb = true;
296
+ let alpha;
297
+ if (options.alpha === null) {
298
+ if (!options.space)
299
+ emitNullAlphaDeprecation();
300
+ alpha = NaN;
301
+ }
302
+ else if (options.alpha === undefined) {
303
+ alpha = 1;
23
304
  }
24
305
  else {
25
- // From https://www.w3.org/TR/css-color-4/#hwb-to-rgb
26
- const scaledHue = (0, utils_1.positiveMod)(color.hue, 360) / 360;
27
- let scaledWhiteness = (0, utils_1.fuzzyAssertInRange)(color.whiteness, 0, 100, 'whiteness') / 100;
28
- let scaledBlackness = (0, utils_1.fuzzyAssertInRange)(color.blackness, 0, 100, 'blackness') / 100;
29
- const sum = scaledWhiteness + scaledBlackness;
30
- if (sum > 1) {
31
- scaledWhiteness /= sum;
32
- scaledBlackness /= sum;
306
+ alpha = (0, utils_2.fuzzyAssertInRange)(options.alpha, 0, 1, 'alpha');
307
+ }
308
+ switch (space) {
309
+ case 'rgb':
310
+ case 'srgb': {
311
+ const red = (_b = options.red) !== null && _b !== void 0 ? _b : NaN;
312
+ const green = (_c = options.green) !== null && _c !== void 0 ? _c : NaN;
313
+ const blue = (_d = options.blue) !== null && _d !== void 0 ? _d : NaN;
314
+ if (this.isRgb) {
315
+ this.color = new colorjs_io_1.default({
316
+ spaceId: encodeSpaceForColorJs(space),
317
+ // convert from 0-255 to 0-1
318
+ coords: [red / 255, green / 255, blue / 255],
319
+ alpha,
320
+ });
321
+ }
322
+ else {
323
+ this.color = new colorjs_io_1.default({
324
+ spaceId: encodeSpaceForColorJs(space),
325
+ coords: [red, green, blue],
326
+ alpha,
327
+ });
328
+ }
329
+ break;
330
+ }
331
+ case 'srgb-linear':
332
+ case 'display-p3':
333
+ case 'a98-rgb':
334
+ case 'prophoto-rgb':
335
+ case 'rec2020':
336
+ this.color = new colorjs_io_1.default({
337
+ spaceId: encodeSpaceForColorJs(space),
338
+ coords: [
339
+ (_e = options.red) !== null && _e !== void 0 ? _e : NaN,
340
+ (_f = options.green) !== null && _f !== void 0 ? _f : NaN,
341
+ (_g = options.blue) !== null && _g !== void 0 ? _g : NaN,
342
+ ],
343
+ alpha,
344
+ });
345
+ break;
346
+ case 'hsl': {
347
+ let hue = normalizeHue((_h = options.hue) !== null && _h !== void 0 ? _h : NaN);
348
+ let saturation = (_j = options.saturation) !== null && _j !== void 0 ? _j : NaN;
349
+ const lightness = (_k = options.lightness) !== null && _k !== void 0 ? _k : NaN;
350
+ if (!Number.isNaN(saturation) && (0, utils_2.fuzzyLessThan)(saturation, 0)) {
351
+ saturation = Math.abs(saturation);
352
+ hue = (hue + 180) % 360;
353
+ }
354
+ this.color = new colorjs_io_1.default({
355
+ spaceId: encodeSpaceForColorJs(space),
356
+ coords: [hue, saturation, lightness],
357
+ alpha,
358
+ });
359
+ break;
360
+ }
361
+ case 'hwb': {
362
+ const hue = normalizeHue((_l = options.hue) !== null && _l !== void 0 ? _l : NaN);
363
+ const whiteness = (_m = options.whiteness) !== null && _m !== void 0 ? _m : NaN;
364
+ const blackness = (_o = options.blackness) !== null && _o !== void 0 ? _o : NaN;
365
+ this.color = new colorjs_io_1.default({
366
+ spaceId: encodeSpaceForColorJs(space),
367
+ coords: [hue, whiteness, blackness],
368
+ alpha,
369
+ });
370
+ break;
33
371
  }
34
- // Because HWB is (currently) used much less frequently than HSL or RGB, we
35
- // don't cache its values because we expect the memory overhead of doing so
36
- // to outweigh the cost of recalculating it on access. Instead, we eagerly
37
- // convert it to RGB and then convert back if necessary.
38
- this.redInternal = hwbToRgb(scaledHue + 1 / 3, scaledWhiteness, scaledBlackness);
39
- this.greenInternal = hwbToRgb(scaledHue, scaledWhiteness, scaledBlackness);
40
- this.blueInternal = hwbToRgb(scaledHue - 1 / 3, scaledWhiteness, scaledBlackness);
372
+ case 'lab':
373
+ case 'oklab': {
374
+ const lightness = (_p = options.lightness) !== null && _p !== void 0 ? _p : NaN;
375
+ const a = (_q = options.a) !== null && _q !== void 0 ? _q : NaN;
376
+ const b = (_r = options.b) !== null && _r !== void 0 ? _r : NaN;
377
+ this.color = new colorjs_io_1.default({
378
+ spaceId: encodeSpaceForColorJs(space),
379
+ coords: [lightness, a, b],
380
+ alpha,
381
+ });
382
+ break;
383
+ }
384
+ case 'lch':
385
+ case 'oklch': {
386
+ const lightness = (_s = options.lightness) !== null && _s !== void 0 ? _s : NaN;
387
+ let chroma = (_t = options.chroma) !== null && _t !== void 0 ? _t : NaN;
388
+ let hue = normalizeHue((_u = options.hue) !== null && _u !== void 0 ? _u : NaN);
389
+ if (!Number.isNaN(chroma) && (0, utils_2.fuzzyLessThan)(chroma, 0)) {
390
+ chroma = Math.abs(chroma);
391
+ hue = (hue + 180) % 360;
392
+ }
393
+ this.color = new colorjs_io_1.default({
394
+ spaceId: encodeSpaceForColorJs(space),
395
+ coords: [lightness, chroma, hue],
396
+ alpha,
397
+ });
398
+ break;
399
+ }
400
+ case 'xyz':
401
+ case 'xyz-d65':
402
+ case 'xyz-d50':
403
+ this.color = new colorjs_io_1.default({
404
+ spaceId: encodeSpaceForColorJs(space),
405
+ coords: [(_v = options.x) !== null && _v !== void 0 ? _v : NaN, (_w = options.y) !== null && _w !== void 0 ? _w : NaN, (_x = options.z) !== null && _x !== void 0 ? _x : NaN],
406
+ alpha,
407
+ });
408
+ break;
409
+ }
410
+ // @TODO Waiting on new release of ColorJS that includes allowing `alpha`
411
+ // to be `NaN` on initial construction.
412
+ // Fixed in: https://github.com/LeaVerou/color.js/commit/08b39c180565ae61408ad737d91bd71a1f79d3df
413
+ if (Number.isNaN(alpha)) {
414
+ this.color.alpha = NaN;
41
415
  }
42
- this.alphaInternal =
43
- color.alpha === undefined
44
- ? 1
45
- : (0, utils_1.fuzzyAssertInRange)(color.alpha, 0, 1, 'alpha');
46
416
  }
47
- /** `this`'s red channel. */
48
- get red() {
49
- if (this.redInternal === undefined) {
50
- this.hslToRgb();
417
+ /** This color's alpha channel, between `0` and `1`. */
418
+ get alpha() {
419
+ return NaNtoZero(this.color.alpha);
420
+ }
421
+ /** The name of this color's color space. */
422
+ get space() {
423
+ return decodeSpaceFromColorJs(this.color.spaceId, this.isRgb);
424
+ }
425
+ /**
426
+ * A boolean indicating whether this color is in a legacy color space (`rgb`,
427
+ * `hsl`, or `hwb`).
428
+ */
429
+ get isLegacy() {
430
+ return ['rgb', 'hsl', 'hwb'].includes(this.space);
431
+ }
432
+ /**
433
+ * A list of this color's channel values (excluding alpha), with [missing
434
+ * channels] converted to `null`.
435
+ *
436
+ * [missing channels]: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#missing_color_components
437
+ */
438
+ get channelsOrNull() {
439
+ let coords = this.color.coords;
440
+ if (this.space === 'rgb') {
441
+ coords = coords.map(coordToRgb);
51
442
  }
52
- return this.redInternal;
443
+ return (0, immutable_1.List)(coords.map(NaNtoNull));
53
444
  }
54
- /** `this`'s blue channel. */
55
- get blue() {
56
- if (this.blueInternal === undefined) {
57
- this.hslToRgb();
445
+ /**
446
+ * A list of this color's channel values (excluding alpha), with [missing
447
+ * channels] converted to `0`.
448
+ *
449
+ * [missing channels]: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#missing_color_components
450
+ */
451
+ get channels() {
452
+ let coords = this.color.coords;
453
+ if (this.space === 'rgb') {
454
+ coords = coords.map(coordToRgb);
58
455
  }
59
- return this.blueInternal;
456
+ return (0, immutable_1.List)(coords.map(NaNtoZero));
457
+ }
458
+ /**
459
+ * This color's red channel in the RGB color space, between `0` and `255`.
460
+ *
461
+ * @deprecated Use {@link channel} instead.
462
+ */
463
+ get red() {
464
+ emitColor4ApiGetterDeprecation('red');
465
+ const val = NaNtoZero(coordToRgb(this.color.srgb.red));
466
+ return (0, utils_2.fuzzyRound)(val);
60
467
  }
61
- /** `this`'s green channel. */
468
+ /**
469
+ * This color's green channel in the RGB color space, between `0` and `255`.
470
+ *
471
+ * @deprecated Use {@link channel} instead.
472
+ */
62
473
  get green() {
63
- if (this.greenInternal === undefined) {
64
- this.hslToRgb();
65
- }
66
- return this.greenInternal;
474
+ emitColor4ApiGetterDeprecation('green');
475
+ const val = NaNtoZero(coordToRgb(this.color.srgb.green));
476
+ return (0, utils_2.fuzzyRound)(val);
477
+ }
478
+ /**
479
+ * This color's blue channel in the RGB color space, between `0` and `255`.
480
+ *
481
+ * @deprecated Use {@link channel} instead.
482
+ */
483
+ get blue() {
484
+ emitColor4ApiGetterDeprecation('blue');
485
+ const val = NaNtoZero(coordToRgb(this.color.srgb.blue));
486
+ return (0, utils_2.fuzzyRound)(val);
67
487
  }
68
- /** `this`'s hue value. */
488
+ /**
489
+ * This color's hue in the HSL color space, between `0` and `360`.
490
+ *
491
+ * @deprecated Use {@link channel} instead.
492
+ */
69
493
  get hue() {
70
- if (this.hueInternal === undefined) {
71
- this.rgbToHsl();
72
- }
73
- return this.hueInternal;
494
+ emitColor4ApiGetterDeprecation('hue');
495
+ return NaNtoZero(this.color.hsl.hue);
74
496
  }
75
- /** `this`'s saturation value. */
497
+ /**
498
+ * This color's saturation in the HSL color space, between `0` and `100`.
499
+ *
500
+ * @deprecated Use {@link channel} instead.
501
+ */
76
502
  get saturation() {
77
- if (this.saturationInternal === undefined) {
78
- this.rgbToHsl();
79
- }
80
- return this.saturationInternal;
503
+ emitColor4ApiGetterDeprecation('saturation');
504
+ return NaNtoZero(this.color.hsl.saturation);
81
505
  }
82
- /** `this`'s hue value. */
506
+ /**
507
+ * This color's lightness in the HSL color space, between `0` and `100`.
508
+ *
509
+ * @deprecated Use {@link channel} instead.
510
+ */
83
511
  get lightness() {
84
- if (this.lightnessInternal === undefined) {
85
- this.rgbToHsl();
86
- }
87
- return this.lightnessInternal;
512
+ emitColor4ApiGetterDeprecation('lightness');
513
+ return NaNtoZero(this.color.hsl.lightness);
88
514
  }
89
- /** `this`'s whiteness value. */
515
+ /**
516
+ * This color's whiteness in the HWB color space, between `0` and `100`.
517
+ *
518
+ * @deprecated Use {@link channel} instead.
519
+ */
90
520
  get whiteness() {
91
- // Because HWB is (currently) used much less frequently than HSL or RGB, we
92
- // don't cache its values because we expect the memory overhead of doing so
93
- // to outweigh the cost of recalculating it on access.
94
- return (Math.min(this.red, this.green, this.blue) / 255) * 100;
95
- }
96
- /** `this`'s blackness value. */
97
- get blackness() {
98
- // Because HWB is (currently) used much less frequently than HSL or RGB, we
99
- // don't cache its values because we expect the memory overhead of doing so
100
- // to outweigh the cost of recalculating it on access.
101
- return 100 - (Math.max(this.red, this.green, this.blue) / 255) * 100;
102
- }
103
- /** `this`'s alpha channel. */
104
- get alpha() {
105
- return this.alphaInternal;
521
+ emitColor4ApiGetterDeprecation('whiteness');
522
+ return NaNtoZero(this.color.hwb.whiteness);
106
523
  }
107
524
  /**
108
- * Whether `this` has already calculated the HSL components for the color.
525
+ * This color's blackness in the HWB color space, between `0` and `100`.
109
526
  *
110
- * This is an internal property that's not an official part of Sass's JS API,
111
- * and may be broken at any time.
527
+ * @deprecated Use {@link channel} instead.
112
528
  */
113
- get hasCalculatedHsl() {
114
- return !!this.hueInternal;
529
+ get blackness() {
530
+ emitColor4ApiGetterDeprecation('blackness');
531
+ return NaNtoZero(this.color.hwb.blackness);
115
532
  }
116
533
  assertColor() {
117
534
  return this;
118
535
  }
119
- change(color) {
120
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
121
- if ('whiteness' in color || 'blackness' in color) {
122
- return new SassColor({
123
- hue: (_a = color.hue) !== null && _a !== void 0 ? _a : this.hue,
124
- whiteness: (_b = color.whiteness) !== null && _b !== void 0 ? _b : this.whiteness,
125
- blackness: (_c = color.blackness) !== null && _c !== void 0 ? _c : this.blackness,
126
- alpha: (_d = color.alpha) !== null && _d !== void 0 ? _d : this.alpha,
127
- });
128
- }
129
- else if ('hue' in color ||
130
- 'saturation' in color ||
131
- 'lightness' in color) {
132
- // Tell TypeScript this isn't a Partial<HwbColor>.
133
- const hsl = color;
134
- return new SassColor({
135
- hue: (_e = hsl.hue) !== null && _e !== void 0 ? _e : this.hue,
136
- saturation: (_f = hsl.saturation) !== null && _f !== void 0 ? _f : this.saturation,
137
- lightness: (_g = hsl.lightness) !== null && _g !== void 0 ? _g : this.lightness,
138
- alpha: (_h = hsl.alpha) !== null && _h !== void 0 ? _h : this.alpha,
139
- });
140
- }
141
- else if ('red' in color ||
142
- 'green' in color ||
143
- 'blue' in color ||
144
- this.redInternal) {
145
- const rgb = color;
146
- return new SassColor({
147
- red: (_j = rgb.red) !== null && _j !== void 0 ? _j : this.red,
148
- green: (_k = rgb.green) !== null && _k !== void 0 ? _k : this.green,
149
- blue: (_l = rgb.blue) !== null && _l !== void 0 ? _l : this.blue,
150
- alpha: (_m = rgb.alpha) !== null && _m !== void 0 ? _m : this.alpha,
536
+ /**
537
+ * Returns a new color that's the result of converting this color to the
538
+ * specified `space`.
539
+ */
540
+ toSpace(space) {
541
+ if (space === this.space)
542
+ return this;
543
+ const color = this.color.to(encodeSpaceForColorJs(space));
544
+ return new SassColor({ color, space });
545
+ }
546
+ /**
547
+ * Returns a boolean indicating whether this color is in-gamut (as opposed to
548
+ * having one or more of its channels out of bounds) for the specified
549
+ * `space`, or its current color space if `space` is not specified.
550
+ */
551
+ isInGamut(space) {
552
+ return this.color.inGamut(encodeSpaceForColorJs(space));
553
+ }
554
+ /**
555
+ * Returns a copy of this color, modified so it is in-gamut for the specified
556
+ * `space`—or the current color space if `space` is not specified—using
557
+ * `method` to map out-of-gamut colors into the desired gamut.
558
+ */
559
+ toGamut({ space, method, }) {
560
+ if (this.isInGamut(space))
561
+ return this;
562
+ const color = this.color.clone().toGamut({
563
+ space: encodeSpaceForColorJs(space),
564
+ method: encodeGamutMapMethodForColorJs(method),
565
+ });
566
+ return new SassColor({ color, space: space !== null && space !== void 0 ? space : this.space });
567
+ }
568
+ channel(channel, options) {
569
+ var _a;
570
+ if (channel === 'alpha')
571
+ return this.alpha;
572
+ let val;
573
+ const space = (_a = options === null || options === void 0 ? void 0 : options.space) !== null && _a !== void 0 ? _a : this.space;
574
+ validateChannelInSpace(channel, space);
575
+ if (options === null || options === void 0 ? void 0 : options.space) {
576
+ val = this.color.get({
577
+ space: encodeSpaceForColorJs(options.space),
578
+ coordId: encodeChannelForColorJs(channel),
151
579
  });
152
580
  }
153
581
  else {
154
- return new SassColor({
155
- hue: this.hue,
156
- saturation: this.saturation,
157
- lightness: this.lightness,
158
- alpha: (_o = color.alpha) !== null && _o !== void 0 ? _o : this.alpha,
582
+ val = this.color.get({
583
+ space: this.color.spaceId,
584
+ coordId: encodeChannelForColorJs(channel),
159
585
  });
160
586
  }
587
+ if (space === 'rgb')
588
+ val = coordToRgb(val);
589
+ return NaNtoZero(val);
161
590
  }
162
- equals(other) {
163
- return (other instanceof SassColor &&
164
- (0, utils_1.fuzzyEquals)(this.red, other.red) &&
165
- (0, utils_1.fuzzyEquals)(this.green, other.green) &&
166
- (0, utils_1.fuzzyEquals)(this.blue, other.blue) &&
167
- (0, utils_1.fuzzyEquals)(this.alpha, other.alpha));
168
- }
169
- hashCode() {
170
- return (0, immutable_1.hash)(this.red ^ this.green ^ this.blue ^ this.alpha);
591
+ /**
592
+ * Returns a boolean indicating whether a given channel value is a [missing
593
+ * channel].
594
+ *
595
+ * [missing channel]: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value#missing_color_components
596
+ */
597
+ isChannelMissing(channel) {
598
+ if (channel === 'alpha')
599
+ return Number.isNaN(this.color.alpha);
600
+ validateChannelInSpace(channel, this.space);
601
+ return Number.isNaN(this.color.get({
602
+ space: this.color.spaceId,
603
+ coordId: encodeChannelForColorJs(channel),
604
+ }));
171
605
  }
172
- toString() {
173
- const isOpaque = (0, utils_1.fuzzyEquals)(this.alpha, 1);
174
- let string = isOpaque ? 'rgb(' : 'rgba(';
175
- string += `${this.red}, ${this.green}, ${this.blue}`;
176
- string += isOpaque ? ')' : `, ${this.alpha})`;
177
- return string;
178
- }
179
- // Computes `this`'s `hue`, `saturation`, and `lightness` values based on
180
- // `red`, `green`, and `blue`.
181
- //
182
- // Algorithm from https://en.wikipedia.org/wiki/HSL_and_HSV#RGB_to_HSL_and_HSV
183
- rgbToHsl() {
184
- const scaledRed = this.red / 255;
185
- const scaledGreen = this.green / 255;
186
- const scaledBlue = this.blue / 255;
187
- const max = Math.max(scaledRed, scaledGreen, scaledBlue);
188
- const min = Math.min(scaledRed, scaledGreen, scaledBlue);
189
- const delta = max - min;
190
- if (max === min) {
191
- this.hueInternal = 0;
606
+ isChannelPowerless(channel, options) {
607
+ if (channel === 'alpha')
608
+ return false;
609
+ const color = (options === null || options === void 0 ? void 0 : options.space) ? this.toSpace(options.space) : this;
610
+ validateChannelInSpace(channel, color.space);
611
+ const channels = color.channels.toArray();
612
+ switch (channel) {
613
+ case color.channel0Id:
614
+ if (color.space === 'hsl')
615
+ return (0, utils_2.fuzzyEquals)(channels[1], 0);
616
+ if (color.space === 'hwb') {
617
+ return (0, utils_2.fuzzyGreaterThanOrEquals)(channels[1] + channels[2], 100);
618
+ }
619
+ return false;
620
+ case color.channel2Id:
621
+ switch (color.space) {
622
+ case 'lch':
623
+ case 'oklch':
624
+ return (0, utils_2.fuzzyEquals)(channels[1], 0);
625
+ }
626
+ return false;
192
627
  }
193
- else if (max === scaledRed) {
194
- this.hueInternal = (0, utils_1.positiveMod)((60 * (scaledGreen - scaledBlue)) / delta, 360);
628
+ return false;
629
+ }
630
+ /**
631
+ * Returns a color partway between this color and `color2` according to
632
+ * `method`, as defined by the CSS Color 4 [color interpolation] procedure.
633
+ *
634
+ * [color interpolation]: https://www.w3.org/TR/css-color-4/#interpolation
635
+ *
636
+ * If `method` is missing and this color is in a polar color space (HSL, HWB,
637
+ * LCH, and Oklch spaces), `method` defaults to "shorter".
638
+ *
639
+ * The `weight` is a number between 0 and 1 that indicates how much of this
640
+ * color should be in the resulting color. If omitted, it defaults to 0.5.
641
+ */
642
+ interpolate(color2, options) {
643
+ var _a, _b;
644
+ const hueInterpolationMethod = (_a = options === null || options === void 0 ? void 0 : options.method) !== null && _a !== void 0 ? _a : (isPolarColorSpace(this.space) ? 'shorter' : undefined);
645
+ const weight = (_b = options === null || options === void 0 ? void 0 : options.weight) !== null && _b !== void 0 ? _b : 0.5;
646
+ if ((0, utils_2.fuzzyEquals)(weight, 0))
647
+ return color2;
648
+ if ((0, utils_2.fuzzyEquals)(weight, 1))
649
+ return this;
650
+ if (weight < 0 || weight > 1) {
651
+ throw (0, utils_1.valueError)(`Expected \`weight\` between \`0\` and \`1\`, received \`${weight}\`.`);
195
652
  }
196
- else if (max === scaledGreen) {
197
- this.hueInternal = (0, utils_1.positiveMod)(120 + (60 * (scaledBlue - scaledRed)) / delta, 360);
653
+ // ColorJS inverses the `weight` argument, where `0` is `this` and `1` is
654
+ // `color2`.
655
+ const color = this.color.mix(color2.color, 1 - weight, {
656
+ space: encodeSpaceForColorJs(this.space),
657
+ hue: hueInterpolationMethod,
658
+ });
659
+ const coords = decodeCoordsFromColorJs(color.coords, this.space === 'rgb');
660
+ return new SassColor({
661
+ space: this.space,
662
+ [this.channel0Id]: coords[0],
663
+ [this.channel1Id]: coords[1],
664
+ [this.channel2Id]: coords[2],
665
+ alpha: NaNtoNull(this.color.alpha),
666
+ });
667
+ }
668
+ /** Legacy determination of color space by option channels. */
669
+ getLegacyChangeSpace(options) {
670
+ let space;
671
+ if (isNumberOrNull(options.whiteness) ||
672
+ isNumberOrNull(options.blackness) ||
673
+ (this.space === 'hwb' && isNumberOrNull(options.hue))) {
674
+ space = 'hwb';
198
675
  }
199
- else if (max === scaledBlue) {
200
- this.hueInternal = (0, utils_1.positiveMod)(240 + (60 * (scaledRed - scaledGreen)) / delta, 360);
676
+ else if (isNumberOrNull(options.hue) ||
677
+ isNumberOrNull(options.saturation) ||
678
+ isNumberOrNull(options.lightness)) {
679
+ space = 'hsl';
201
680
  }
202
- this.lightnessInternal = 50 * (max + min);
203
- if (max === min) {
204
- this.saturationInternal = 0;
681
+ else if (isNumberOrNull(options.red) ||
682
+ isNumberOrNull(options.green) ||
683
+ isNumberOrNull(options.blue)) {
684
+ space = 'rgb';
205
685
  }
206
- else if (this.lightnessInternal < 50) {
207
- this.saturationInternal = (100 * delta) / (max + min);
686
+ if (space !== this.space)
687
+ emitColor4ApiChangeSpaceDeprecation();
688
+ return space !== null && space !== void 0 ? space : this.space;
689
+ }
690
+ /**
691
+ * Returns a new SassColor in the given `space` that's the result of changing
692
+ * one or more of this color's channels.
693
+ */
694
+ getChangedColor(options, space, spaceSetExplicitly) {
695
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
696
+ const color = this.toSpace(space);
697
+ function getChangedValue(channel) {
698
+ if (isNumberOrNull(options[channel]))
699
+ return options[channel];
700
+ return color.channel(channel);
208
701
  }
209
- else {
210
- this.saturationInternal = (100 * delta) / (2 - max - min);
702
+ switch (space) {
703
+ case 'hsl':
704
+ if (spaceSetExplicitly) {
705
+ return new SassColor({
706
+ hue: getChangedValue('hue'),
707
+ saturation: getChangedValue('saturation'),
708
+ lightness: getChangedValue('lightness'),
709
+ alpha: getChangedValue('alpha'),
710
+ space,
711
+ });
712
+ }
713
+ else {
714
+ checkChangeDeprecations(options, ['hue', 'saturation', 'lightness']);
715
+ return new SassColor({
716
+ hue: (_a = options.hue) !== null && _a !== void 0 ? _a : color.channel('hue'),
717
+ saturation: (_b = options.saturation) !== null && _b !== void 0 ? _b : color.channel('saturation'),
718
+ lightness: (_c = options.lightness) !== null && _c !== void 0 ? _c : color.channel('lightness'),
719
+ alpha: (_d = options.alpha) !== null && _d !== void 0 ? _d : color.channel('alpha'),
720
+ space,
721
+ });
722
+ }
723
+ case 'hwb':
724
+ if (spaceSetExplicitly) {
725
+ return new SassColor({
726
+ hue: getChangedValue('hue'),
727
+ whiteness: getChangedValue('whiteness'),
728
+ blackness: getChangedValue('blackness'),
729
+ alpha: getChangedValue('alpha'),
730
+ space,
731
+ });
732
+ }
733
+ else {
734
+ checkChangeDeprecations(options, ['hue', 'whiteness', 'blackness']);
735
+ return new SassColor({
736
+ hue: (_e = options.hue) !== null && _e !== void 0 ? _e : color.channel('hue'),
737
+ whiteness: (_f = options.whiteness) !== null && _f !== void 0 ? _f : color.channel('whiteness'),
738
+ blackness: (_g = options.blackness) !== null && _g !== void 0 ? _g : color.channel('blackness'),
739
+ alpha: (_h = options.alpha) !== null && _h !== void 0 ? _h : color.channel('alpha'),
740
+ space,
741
+ });
742
+ }
743
+ case 'rgb':
744
+ if (spaceSetExplicitly) {
745
+ return new SassColor({
746
+ red: getChangedValue('red'),
747
+ green: getChangedValue('green'),
748
+ blue: getChangedValue('blue'),
749
+ alpha: getChangedValue('alpha'),
750
+ space,
751
+ });
752
+ }
753
+ else {
754
+ checkChangeDeprecations(options, ['red', 'green', 'blue']);
755
+ return new SassColor({
756
+ red: (_j = options.red) !== null && _j !== void 0 ? _j : color.channel('red'),
757
+ green: (_k = options.green) !== null && _k !== void 0 ? _k : color.channel('green'),
758
+ blue: (_l = options.blue) !== null && _l !== void 0 ? _l : color.channel('blue'),
759
+ alpha: (_m = options.alpha) !== null && _m !== void 0 ? _m : color.channel('alpha'),
760
+ space,
761
+ });
762
+ }
763
+ case 'lab':
764
+ case 'oklab':
765
+ return new SassColor({
766
+ lightness: getChangedValue('lightness'),
767
+ a: getChangedValue('a'),
768
+ b: getChangedValue('b'),
769
+ alpha: getChangedValue('alpha'),
770
+ space,
771
+ });
772
+ case 'lch':
773
+ case 'oklch':
774
+ return new SassColor({
775
+ lightness: getChangedValue('lightness'),
776
+ chroma: getChangedValue('chroma'),
777
+ hue: getChangedValue('hue'),
778
+ alpha: getChangedValue('alpha'),
779
+ space,
780
+ });
781
+ case 'a98-rgb':
782
+ case 'display-p3':
783
+ case 'prophoto-rgb':
784
+ case 'rec2020':
785
+ case 'srgb':
786
+ case 'srgb-linear':
787
+ return new SassColor({
788
+ red: getChangedValue('red'),
789
+ green: getChangedValue('green'),
790
+ blue: getChangedValue('blue'),
791
+ alpha: getChangedValue('alpha'),
792
+ space,
793
+ });
794
+ case 'xyz':
795
+ case 'xyz-d50':
796
+ case 'xyz-d65':
797
+ return new SassColor({
798
+ y: getChangedValue('y'),
799
+ x: getChangedValue('x'),
800
+ z: getChangedValue('z'),
801
+ alpha: getChangedValue('alpha'),
802
+ space,
803
+ });
211
804
  }
212
805
  }
213
- // Computes `this`'s red`, `green`, and `blue` channels based on `hue`,
214
- // `saturation`, and `value`.
215
- //
216
- // Algorithm from the CSS3 spec: https://www.w3.org/TR/css3-color/#hsl-color.
217
- hslToRgb() {
218
- const scaledHue = this.hue / 360;
219
- const scaledSaturation = this.saturation / 100;
220
- const scaledLightness = this.lightness / 100;
221
- const m2 = scaledLightness <= 0.5
222
- ? scaledLightness * (scaledSaturation + 1)
223
- : scaledLightness +
224
- scaledSaturation -
225
- scaledLightness * scaledSaturation;
226
- const m1 = scaledLightness * 2 - m2;
227
- this.redInternal = (0, utils_1.fuzzyRound)(hueToRgb(m1, m2, scaledHue + 1 / 3) * 255);
228
- this.greenInternal = (0, utils_1.fuzzyRound)(hueToRgb(m1, m2, scaledHue) * 255);
229
- this.blueInternal = (0, utils_1.fuzzyRound)(hueToRgb(m1, m2, scaledHue - 1 / 3) * 255);
230
- }
231
- }
232
- exports.SassColor = SassColor;
233
- // A helper for converting HWB colors to RGB.
234
- function hwbToRgb(hue, scaledWhiteness, scaledBlackness) {
235
- const factor = 1 - scaledWhiteness - scaledBlackness;
236
- const channel = hueToRgb(0, 1, hue) * factor + scaledWhiteness;
237
- return (0, utils_1.fuzzyRound)(channel * 255);
238
- }
239
- // An algorithm from the CSS3 spec: http://www.w3.org/TR/css3-color/#hsl-color.
240
- function hueToRgb(m1, m2, hue) {
241
- if (hue < 0)
242
- hue += 1;
243
- if (hue > 1)
244
- hue -= 1;
245
- if (hue < 1 / 6) {
246
- return m1 + (m2 - m1) * hue * 6;
806
+ change(options) {
807
+ var _a;
808
+ const spaceSetExplicitly = !!options.space;
809
+ let space = (_a = options.space) !== null && _a !== void 0 ? _a : this.space;
810
+ if (this.isLegacy && !spaceSetExplicitly) {
811
+ space = this.getLegacyChangeSpace(options);
812
+ }
813
+ // Validate channel values
814
+ const keys = Object.keys(options).filter(key => key !== 'space');
815
+ for (const channel of keys) {
816
+ validateChannelInSpace(channel, space);
817
+ }
818
+ if (isNumberOrNull(options.alpha) && options.alpha !== null) {
819
+ (0, utils_2.fuzzyAssertInRange)(options.alpha, 0, 1, 'alpha');
820
+ }
821
+ return this.getChangedColor(options, space, spaceSetExplicitly).toSpace(this.space);
247
822
  }
248
- else if (hue < 1 / 2) {
249
- return m2;
823
+ equals(other) {
824
+ if (!(other instanceof SassColor))
825
+ return false;
826
+ let coords = this.color.coords;
827
+ let otherCoords = other.color.coords;
828
+ if (this.isLegacy) {
829
+ if (!other.isLegacy)
830
+ return false;
831
+ if (!(0, utils_2.fuzzyEquals)(this.alpha, other.alpha))
832
+ return false;
833
+ if (!(this.space === 'rgb' && other.space === 'rgb')) {
834
+ coords = this.color
835
+ .to('srgb')
836
+ .coords.map(coordToRgb)
837
+ .map(utils_2.fuzzyRound);
838
+ otherCoords = other.color
839
+ .to('srgb')
840
+ .coords.map(coordToRgb)
841
+ .map(utils_2.fuzzyRound);
842
+ }
843
+ return ((0, utils_2.fuzzyEquals)(coords[0], otherCoords[0]) &&
844
+ (0, utils_2.fuzzyEquals)(coords[1], otherCoords[1]) &&
845
+ (0, utils_2.fuzzyEquals)(coords[2], otherCoords[2]));
846
+ }
847
+ return (this.space === other.space &&
848
+ (0, utils_2.fuzzyEquals)(coords[0], otherCoords[0]) &&
849
+ (0, utils_2.fuzzyEquals)(coords[1], otherCoords[1]) &&
850
+ (0, utils_2.fuzzyEquals)(coords[2], otherCoords[2]) &&
851
+ (0, utils_2.fuzzyEquals)(this.alpha, other.alpha));
250
852
  }
251
- else if (hue < 2 / 3) {
252
- return m1 + (m2 - m1) * (2 / 3 - hue) * 6;
853
+ hashCode() {
854
+ let coords = this.color.coords;
855
+ if (this.isLegacy) {
856
+ coords = this.color.to('srgb').coords.map(coordToRgb).map(utils_2.fuzzyRound);
857
+ return ((0, utils_2.fuzzyHashCode)(coords[0]) ^
858
+ (0, utils_2.fuzzyHashCode)(coords[1]) ^
859
+ (0, utils_2.fuzzyHashCode)(coords[2]) ^
860
+ (0, utils_2.fuzzyHashCode)(this.alpha));
861
+ }
862
+ return ((0, immutable_1.hash)(this.space) ^
863
+ (0, utils_2.fuzzyHashCode)(coords[0]) ^
864
+ (0, utils_2.fuzzyHashCode)(coords[1]) ^
865
+ (0, utils_2.fuzzyHashCode)(coords[2]) ^
866
+ (0, utils_2.fuzzyHashCode)(this.alpha));
253
867
  }
254
- else {
255
- return m1;
868
+ toString() {
869
+ return this.color.toString({ inGamut: false });
256
870
  }
257
871
  }
872
+ exports.SassColor = SassColor;
258
873
  //# sourceMappingURL=color.js.map