Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Color 4] Properly serialize missing channels in legacy colors #2115

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion lib/src/visitor/serialize.dart
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,38 @@ final class _SerializeVisitor

void visitColor(SassColor value) {
switch (value.space) {
case ColorSpace.rgb || ColorSpace.hsl || ColorSpace.hwb:
case ColorSpace.rgb || ColorSpace.hsl || ColorSpace.hwb
when !value.isChannel0Missing &&
!value.isChannel1Missing &&
!value.isChannel2Missing &&
!value.isAlphaMissing:
_writeLegacyColor(value);

case ColorSpace.rgb:
_buffer.write('rgb(');
_writeChannel(value.channel0OrNull);
_buffer.writeCharCode($space);
_writeChannel(value.channel1OrNull);
_buffer.writeCharCode($space);
_writeChannel(value.channel2OrNull);
_maybeWriteSlashAlpha(value);
_buffer.writeCharCode($rparen);

case ColorSpace.hsl || ColorSpace.hwb:
_buffer
..write(value.space)
..writeCharCode($lparen);
_writeChannel(value.channel0OrNull);
if (!_isCompressed && !value.isChannel0Missing) _buffer.write('deg');
_buffer.writeCharCode($space);
_writeChannel(value.channel1OrNull);
if (!value.isChannel1Missing) _buffer.writeCharCode($percent);
_buffer.writeCharCode($space);
_writeChannel(value.channel2OrNull);
if (!value.isChannel2Missing) _buffer.writeCharCode($percent);
_maybeWriteSlashAlpha(value);
_buffer.writeCharCode($rparen);

case ColorSpace.lab ||
ColorSpace.oklab ||
ColorSpace.lch ||
Expand Down