Skip to content

Commit 248437e

Browse files
authored
Support missing channels across the embedded protocol (#336)
Closes #335
1 parent 1a63ffa commit 248437e

File tree

2 files changed

+38
-33
lines changed

2 files changed

+38
-33
lines changed

lib/src/protofier.ts

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ export class Protofier {
6868
} else if (value instanceof SassNumber) {
6969
result.value = {case: 'number', value: this.protofyNumber(value)};
7070
} else if (value instanceof SassColor) {
71-
const channels = value.channels;
71+
const channels = value.channelsOrNull;
7272
const color = create(proto.Value_ColorSchema, {
7373
channel1: channels.get(0) as number,
7474
channel2: channels.get(1) as number,
7575
channel3: channels.get(2) as number,
76-
alpha: value.alpha,
76+
alpha: value.isChannelMissing('alpha') ? undefined : value.alpha,
7777
space: value.space,
7878
});
7979
result.value = {case: 'color', value: color};
@@ -236,6 +236,11 @@ export class Protofier {
236236

237237
case 'color': {
238238
const color = value.value.value;
239+
const channel1 = color.channel1 ?? null;
240+
const channel2 = color.channel2 ?? null;
241+
const channel3 = color.channel3 ?? null;
242+
const alpha = color.alpha ?? null;
243+
const space = color.space as KnownColorSpace;
239244
switch (color.space.toLowerCase()) {
240245
case 'rgb':
241246
case 'srgb':
@@ -245,60 +250,60 @@ export class Protofier {
245250
case 'prophoto-rgb':
246251
case 'rec2020':
247252
return new SassColor({
248-
red: color.channel1,
249-
green: color.channel2,
250-
blue: color.channel3,
251-
alpha: color.alpha,
252-
space: color.space as KnownColorSpace,
253+
red: channel1,
254+
green: channel2,
255+
blue: channel3,
256+
alpha,
257+
space,
253258
});
254259

255260
case 'hsl':
256261
return new SassColor({
257-
hue: color.channel1,
258-
saturation: color.channel2,
259-
lightness: color.channel3,
260-
alpha: color.alpha,
261-
space: 'hsl',
262+
hue: channel1,
263+
saturation: channel2,
264+
lightness: channel3,
265+
alpha,
266+
space,
262267
});
263268

264269
case 'hwb':
265270
return new SassColor({
266-
hue: color.channel1,
267-
whiteness: color.channel2,
268-
blackness: color.channel3,
269-
alpha: color.alpha,
270-
space: 'hwb',
271+
hue: channel1,
272+
whiteness: channel2,
273+
blackness: channel3,
274+
alpha,
275+
space,
271276
});
272277

273278
case 'lab':
274279
case 'oklab':
275280
return new SassColor({
276-
lightness: color.channel1,
277-
a: color.channel2,
278-
b: color.channel3,
279-
alpha: color.alpha,
280-
space: color.space as KnownColorSpace,
281+
lightness: channel1,
282+
a: channel2,
283+
b: channel3,
284+
alpha,
285+
space,
281286
});
282287

283288
case 'lch':
284289
case 'oklch':
285290
return new SassColor({
286-
lightness: color.channel1,
287-
chroma: color.channel2,
288-
hue: color.channel3,
289-
alpha: color.alpha,
290-
space: color.space as KnownColorSpace,
291+
lightness: channel1,
292+
chroma: channel2,
293+
hue: channel3,
294+
alpha,
295+
space,
291296
});
292297

293298
case 'xyz':
294299
case 'xyz-d65':
295300
case 'xyz-d50':
296301
return new SassColor({
297-
x: color.channel1,
298-
y: color.channel2,
299-
z: color.channel3,
300-
alpha: color.alpha,
301-
space: color.space as KnownColorSpace,
302+
x: channel1,
303+
y: channel2,
304+
z: channel3,
305+
alpha,
306+
space,
302307
});
303308

304309
default:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "sass-embedded",
33
"version": "1.79.4",
4-
"protocol-version": "3.0.0",
4+
"protocol-version": "3.1.0",
55
"compiler-version": "1.79.4",
66
"description": "Node.js library that communicates with Embedded Dart Sass using the Embedded Sass protocol",
77
"repository": "sass/embedded-host-node",

0 commit comments

Comments
 (0)