Skip to content
This repository was archived by the owner on May 15, 2023. It is now read-only.

Commit 4396693

Browse files
authored
Support consuming Value.HwbColor and emitting Value.HslColor (#54)
1 parent 0ed8d89 commit 4396693

File tree

10 files changed

+54
-38
lines changed

10 files changed

+54
-38
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 1.0.0-beta.11
2+
3+
* Support version 1.0.0-beta.13 of the Sass embedded protocol:
4+
* Support `Value.HwbColor`.
5+
* Emit colors as `Value.HslColor` if that internal representation is
6+
available.
7+
18
## 1.0.0-beta.10
29

310
* Support version 1.0.0-beta.12 of the Sass embedded protocol:

lib/src/function_registry.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
44

5-
import 'package:sass/sass.dart' as sass;
5+
import 'package:sass_api/sass_api.dart' as sass;
66

77
import 'embedded_sass.pb.dart';
88

lib/src/host_callable.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import 'dart:cli';
66
import 'dart:io';
77

8-
import 'package:sass/sass.dart' as sass;
8+
import 'package:sass_api/sass_api.dart' as sass;
99

1010
import 'dispatcher.dart';
1111
import 'embedded_sass.pb.dart';

lib/src/importer.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import 'dart:cli';
66

7-
import 'package:sass/sass.dart' as sass;
7+
import 'package:sass_api/sass_api.dart' as sass;
88

99
import 'dispatcher.dart';
1010
import 'embedded_sass.pb.dart' hide SourceSpan;

lib/src/logger.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// https://opensource.org/licenses/MIT.
44

55
import 'package:path/path.dart' as p;
6-
import 'package:sass/sass.dart' as sass;
6+
import 'package:sass_api/sass_api.dart' as sass;
77
import 'package:source_span/source_span.dart';
88
import 'package:stack_trace/stack_trace.dart';
99

lib/src/protofier.dart

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
44

5-
import 'package:sass/sass.dart' as sass;
5+
import 'package:sass_api/sass_api.dart' as sass;
66

77
import 'dispatcher.dart';
88
import 'embedded_sass.pb.dart';
@@ -51,14 +51,19 @@ class Protofier {
5151
number.denominators.addAll(value.denominatorUnits);
5252
result.number = number;
5353
} else if (value is sass.SassColor) {
54-
// TODO(nweiz): If the color is represented as HSL internally, this coerces
55-
// it to RGB. Is it worth providing some visibility into its internal
56-
// representation so we can serialize without converting?
57-
result.rgbColor = Value_RgbColor()
58-
..red = value.red
59-
..green = value.green
60-
..blue = value.blue
61-
..alpha = value.alpha * 1.0;
54+
if (value.hasCalculatedHsl) {
55+
result.hslColor = Value_HslColor()
56+
..hue = value.hue * 1.0
57+
..saturation = value.saturation * 1.0
58+
..lightness = value.lightness * 1.0
59+
..alpha = value.alpha * 1.0;
60+
} else {
61+
result.rgbColor = Value_RgbColor()
62+
..red = value.red
63+
..green = value.green
64+
..blue = value.blue
65+
..alpha = value.alpha * 1.0;
66+
}
6267
} else if (value is sass.SassArgumentList) {
6368
_argumentLists.add(value);
6469
var argList = Value_ArgumentList()
@@ -148,6 +153,13 @@ class Protofier {
148153
value.hslColor.lightness,
149154
value.hslColor.alpha);
150155

156+
case Value_Value.hwbColor:
157+
return sass.SassColor.hwb(
158+
value.hwbColor.hue,
159+
value.hwbColor.whiteness,
160+
value.hwbColor.blackness,
161+
value.hwbColor.alpha);
162+
151163
case Value_Value.argumentList:
152164
if (value.argumentList.id != 0) {
153165
return _argumentListForId(value.argumentList.id);

lib/src/utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
44

5-
import 'package:sass/sass.dart' as sass;
5+
import 'package:sass_api/sass_api.dart' as sass;
66
import 'package:source_span/source_span.dart';
77
import 'package:term_glyph/term_glyph.dart' as term_glyph;
88

lib/src/value.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// MIT-style license that can be found in the LICENSE file or at
33
// https://opensource.org/licenses/MIT.
44

5-
import 'package:sass/sass.dart' as sass;
5+
import 'package:sass_api/sass_api.dart' as sass;
66

77
import 'dispatcher.dart';
88
import 'embedded_sass.pb.dart';

pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: sass_embedded
2-
version: 1.0.0-beta.10
2+
version: 1.0.0-dev
33
description: An implementation of the Sass embedded protocol using Dart Sass.
44
author: Sass Team
55
homepage: https://github.com/sass/dart-sass-embedded
@@ -14,7 +14,7 @@ dependencies:
1414
async: ">=1.13.0 <3.0.0"
1515
meta: ^1.1.0
1616
protobuf: ^2.0.0
17-
sass: ^1.38.0
17+
sass_api: ^1.0.0-beta.5
1818
source_span: ^1.1.0
1919
stack_trace: ^1.6.0
2020
stream_channel: ">=1.6.0 <3.0.0"

test/function_test.dart

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -447,78 +447,75 @@ void main() {
447447
group("without alpha:", () {
448448
group("hue", () {
449449
test("0", () async {
450-
expect(
451-
await _protofy('hsl(0, 50%, 50%)'), _rgb(191, 64, 64, 1.0));
450+
expect(await _protofy('hsl(0, 50%, 50%)'), _hsl(0, 50, 50, 1.0));
452451
});
453452

454453
test("360", () async {
455454
expect(
456-
await _protofy('hsl(360, 50%, 50%)'), _rgb(191, 64, 64, 1.0));
455+
await _protofy('hsl(360, 50%, 50%)'), _hsl(0, 50, 50, 1.0));
457456
});
458457

459458
test("below 0", () async {
460459
expect(await _protofy('hsl(-100, 50%, 50%)'),
461-
_rgb(106, 64, 191, 1.0));
460+
_hsl(260, 50, 50, 1.0));
462461
});
463462

464463
test("between 0 and 360", () async {
465-
expect(await _protofy('hsl(100, 50%, 50%)'),
466-
_rgb(106, 191, 64, 1.0));
464+
expect(
465+
await _protofy('hsl(100, 50%, 50%)'), _hsl(100, 50, 50, 1.0));
467466
});
468467

469468
test("above 360", () async {
470-
expect(await _protofy('hsl(560, 50%, 50%)'),
471-
_rgb(64, 149, 191, 1.0));
469+
expect(
470+
await _protofy('hsl(560, 50%, 50%)'), _hsl(200, 50, 50, 1.0));
472471
});
473472
});
474473

475474
group("saturation", () {
476475
test("0", () async {
477-
expect(
478-
await _protofy('hsl(0, 0%, 50%)'), _rgb(128, 128, 128, 1.0));
476+
expect(await _protofy('hsl(0, 0%, 50%)'), _hsl(0, 0, 50, 1.0));
479477
});
480478

481479
test("100", () async {
482-
expect(await _protofy('hsl(0, 100%, 50%)'), _rgb(255, 0, 0, 1.0));
480+
expect(
481+
await _protofy('hsl(0, 100%, 50%)'), _hsl(0, 100, 50, 1.0));
483482
});
484483

485484
test("in the middle", () async {
486-
expect(
487-
await _protofy('hsl(0, 42%, 50%)'), _rgb(181, 74, 74, 1.0));
485+
expect(await _protofy('hsl(0, 42%, 50%)'), _hsl(0, 42, 50, 1.0));
488486
});
489487
});
490488

491489
group("lightness", () {
492490
test("0", () async {
493-
expect(await _protofy('hsl(0, 50%, 0%)'), _rgb(0, 0, 0, 1.0));
491+
expect(await _protofy('hsl(0, 50%, 0%)'), _hsl(0, 50, 0, 1.0));
494492
});
495493

496494
test("100", () async {
497-
expect(await _protofy('hsl(0, 50%, 100%)'),
498-
_rgb(255, 255, 255, 1.0));
495+
expect(
496+
await _protofy('hsl(0, 50%, 100%)'), _hsl(0, 50, 100, 1.0));
499497
});
500498

501499
test("in the middle", () async {
502-
expect(
503-
await _protofy('hsl(0, 50%, 42%)'), _rgb(161, 54, 54, 1.0));
500+
expect(await _protofy('hsl(0, 50%, 42%)'), _hsl(0, 50, 42, 1.0));
504501
});
505502
});
506503
});
507504

508505
group("with alpha", () {
509506
test("0", () async {
510507
expect(await _protofy('hsl(10, 20%, 30%, 0)'),
511-
equals(_rgb(92, 66, 61, 0.0)));
508+
equals(_hsl(10, 20, 30, 0.0)));
512509
});
513510

514511
test("1", () async {
515512
expect(await _protofy('hsl(10, 20%, 30%, 1)'),
516-
equals(_rgb(92, 66, 61, 1.0)));
513+
equals(_hsl(10, 20, 30, 1.0)));
517514
});
518515

519516
test("between 0 and 1", () async {
520517
expect(await _protofy('hsl(10, 20%, 30%, 0.123)'),
521-
equals(_rgb(92, 66, 61, 0.123)));
518+
equals(_hsl(10, 20, 30, 0.123)));
522519
});
523520
});
524521
});

0 commit comments

Comments
 (0)