Skip to content

Commit

Permalink
Support missing channels across the embedded protocol
Browse files Browse the repository at this point in the history
Closes #335
  • Loading branch information
nex3 committed Sep 24, 2024
1 parent 8818ed1 commit 01996dd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 33 deletions.
69 changes: 37 additions & 32 deletions lib/src/protofier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ export class Protofier {
} else if (value instanceof SassNumber) {
result.value = {case: 'number', value: this.protofyNumber(value)};
} else if (value instanceof SassColor) {
const channels = value.channels;
const channels = value.channelsOrNull;
const color = create(proto.Value_ColorSchema, {
channel1: channels.get(0) as number,
channel2: channels.get(1) as number,
channel3: channels.get(2) as number,
alpha: value.alpha,
alpha: value.isChannelMissing('alpha') ? undefined : value.alpha,
space: value.space,
});
result.value = {case: 'color', value: color};
Expand Down Expand Up @@ -236,6 +236,11 @@ export class Protofier {

case 'color': {
const color = value.value.value;
const channel1 = color.channel1 ?? null;
const channel2 = color.channel2 ?? null;
const channel3 = color.channel3 ?? null;
const alpha = color.alpha ?? null;
const space = color.space as KnownColorSpace;
switch (color.space.toLowerCase()) {
case 'rgb':
case 'srgb':
Expand All @@ -245,60 +250,60 @@ export class Protofier {
case 'prophoto-rgb':
case 'rec2020':
return new SassColor({
red: color.channel1,
green: color.channel2,
blue: color.channel3,
alpha: color.alpha,
space: color.space as KnownColorSpace,
red: channel1,
green: channel2,
blue: channel3,
alpha,
space,
});

case 'hsl':
return new SassColor({
hue: color.channel1,
saturation: color.channel2,
lightness: color.channel3,
alpha: color.alpha,
space: 'hsl',
hue: channel1,
saturation: channel2,
lightness: channel3,
alpha,
space,
});

case 'hwb':
return new SassColor({
hue: color.channel1,
whiteness: color.channel2,
blackness: color.channel3,
alpha: color.alpha,
space: 'hwb',
hue: channel1,
whiteness: channel2,
blackness: channel3,
alpha,
space,
});

case 'lab':
case 'oklab':
return new SassColor({
lightness: color.channel1,
a: color.channel2,
b: color.channel3,
alpha: color.alpha,
space: color.space as KnownColorSpace,
lightness: channel1,
a: channel2,
b: channel3,
alpha,
space,
});

case 'lch':
case 'oklch':
return new SassColor({
lightness: color.channel1,
chroma: color.channel2,
hue: color.channel3,
alpha: color.alpha,
space: color.space as KnownColorSpace,
lightness: channel1,
chroma: channel2,
hue: channel3,
alpha,
space,
});

case 'xyz':
case 'xyz-d65':
case 'xyz-d50':
return new SassColor({
x: color.channel1,
y: color.channel2,
z: color.channel3,
alpha: color.alpha,
space: color.space as KnownColorSpace,
x: channel1,
y: channel2,
z: channel3,
alpha,
space,
});

default:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sass-embedded",
"version": "1.79.3",
"protocol-version": "3.0.0",
"protocol-version": "3.1.0",
"compiler-version": "1.79.3",
"description": "Node.js library that communicates with Embedded Dart Sass using the Embedded Sass protocol",
"repository": "sass/embedded-host-node",
Expand Down

0 comments on commit 01996dd

Please sign in to comment.