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