Skip to content

Commit

Permalink
Add a $space parameter to the channel function deprecation
Browse files Browse the repository at this point in the history
Closes #2353
  • Loading branch information
nex3 committed Sep 19, 2024
1 parent 5fa04d3 commit 4e79f2c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.79.2

* Add a `$space` parameter to the suggested replacement for `color.red()`,
`color.green()`, `color.blue()`, `color.hue()`, `color.saturation()`,
`color.lightness()`, `color.whiteness()`, and `color.blackness()`.

## 1.79.1

* No user-visible changes.
Expand Down
38 changes: 22 additions & 16 deletions lib/src/functions/color.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ const _specialCommaSpaces = {ColorSpace.rgb, ColorSpace.hsl};
/// The global definitions of Sass color functions.
final global = UnmodifiableListView([
// ### RGB
_channelFunction("red", (color) => color.red, global: true)
_channelFunction("red", ColorSpace.rgb, (color) => color.red, global: true)
.withDeprecationWarning("color"),
_channelFunction("green", (color) => color.green, global: true)
_channelFunction("green", ColorSpace.rgb, (color) => color.green,
global: true)
.withDeprecationWarning("color"),
_channelFunction("blue", (color) => color.blue, global: true)
_channelFunction("blue", ColorSpace.rgb, (color) => color.blue, global: true)
.withDeprecationWarning("color"),
_mix.withDeprecationWarning("color"),

Expand All @@ -59,12 +60,13 @@ final global = UnmodifiableListView([
.withDeprecationWarning("color"),

// ### HSL
_channelFunction("hue", (color) => color.hue, unit: 'deg', global: true)
_channelFunction("hue", ColorSpace.hsl, (color) => color.hue,
unit: 'deg', global: true)
.withDeprecationWarning("color"),
_channelFunction("saturation", (color) => color.saturation,
_channelFunction("saturation", ColorSpace.hsl, (color) => color.saturation,
unit: '%', global: true)
.withDeprecationWarning("color"),
_channelFunction("lightness", (color) => color.lightness,
_channelFunction("lightness", ColorSpace.hsl, (color) => color.lightness,
unit: '%', global: true)
.withDeprecationWarning("color"),

Expand Down Expand Up @@ -346,9 +348,9 @@ final global = UnmodifiableListView([
/// The Sass color module.
final module = BuiltInModule("color", functions: <Callable>[
// ### RGB
_channelFunction("red", (color) => color.red),
_channelFunction("green", (color) => color.green),
_channelFunction("blue", (color) => color.blue),
_channelFunction("red", ColorSpace.rgb, (color) => color.red),
_channelFunction("green", ColorSpace.rgb, (color) => color.green),
_channelFunction("blue", ColorSpace.rgb, (color) => color.blue),
_mix,

_function("invert", r"$color, $weight: 100%, $space: null", (arguments) {
Expand All @@ -365,9 +367,11 @@ final module = BuiltInModule("color", functions: <Callable>[
}),

// ### HSL
_channelFunction("hue", (color) => color.hue, unit: 'deg'),
_channelFunction("saturation", (color) => color.saturation, unit: '%'),
_channelFunction("lightness", (color) => color.lightness, unit: '%'),
_channelFunction("hue", ColorSpace.hsl, (color) => color.hue, unit: 'deg'),
_channelFunction("saturation", ColorSpace.hsl, (color) => color.saturation,
unit: '%'),
_channelFunction("lightness", ColorSpace.hsl, (color) => color.lightness,
unit: '%'),
_removedColorFunction("adjust-hue", "hue"),
_removedColorFunction("lighten", "lightness"),
_removedColorFunction("darken", "lightness", negative: true),
Expand Down Expand Up @@ -403,8 +407,10 @@ final module = BuiltInModule("color", functions: <Callable>[
space: ColorSpace.hwb, name: 'channels')
}),

_channelFunction("whiteness", (color) => color.whiteness, unit: '%'),
_channelFunction("blackness", (color) => color.blackness, unit: '%'),
_channelFunction("whiteness", ColorSpace.hwb, (color) => color.whiteness,
unit: '%'),
_channelFunction("blackness", ColorSpace.hwb, (color) => color.blackness,
unit: '%'),

// ### Opacity
_removedColorFunction("opacify", "alpha"),
Expand Down Expand Up @@ -1593,15 +1599,15 @@ bool _isNone(Value value) =>
/// If [unit] is passed, the channel is returned with that unit. The [global]
/// parameter indicates whether this was called using the legacy global syntax.
BuiltInCallable _channelFunction(
String name, num Function(SassColor color) getter,
String name, ColorSpace space, num Function(SassColor color) getter,
{String? unit, bool global = false}) {
return _function(name, r"$color", (arguments) {
var result = SassNumber(getter(arguments.first.assertColor("color")), unit);

warnForDeprecation(
"${global ? '' : 'color.'}$name() is deprecated. Suggestion:\n"
"\n"
'color.channel(\$color, $name)\n'
'color.channel(\$color, $name, \$space: $space)\n'
"\n"
"More info: https://sass-lang.com/d/color-functions",
Deprecation.colorFunctions);
Expand Down
4 changes: 4 additions & 0 deletions pkg/sass-parser/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.1

* No user-visible changes.

## 0.2.0

* Initial unstable release.
2 changes: 1 addition & 1 deletion pkg/sass-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sass-parser",
"version": "0.2.0",
"version": "0.2.1-dev",
"description": "A PostCSS-compatible wrapper of the official Sass parser",
"repository": "sass/sass",
"author": "Google Inc.",
Expand Down
4 changes: 4 additions & 0 deletions pkg/sass_api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 12.0.2

* No user-visible changes.

## 12.0.1

* No user-visible changes.
Expand Down
4 changes: 2 additions & 2 deletions pkg/sass_api/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ name: sass_api
# Note: Every time we add a new Sass AST node, we need to bump the *major*
# version because it's a breaking change for anyone who's implementing the
# visitor interface(s).
version: 12.0.1
version: 12.0.2
description: Additional APIs for Dart Sass.
homepage: https://github.com/sass/dart-sass

environment:
sdk: ">=3.0.0 <4.0.0"

dependencies:
sass: 1.79.1
sass: 1.79.2

dev_dependencies:
dartdoc: ^8.0.14
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: sass
version: 1.79.1
version: 1.79.2-dev
description: A Sass implementation in Dart.
homepage: https://github.com/sass/dart-sass

Expand Down

0 comments on commit 4e79f2c

Please sign in to comment.