diff --git a/CHANGELOG.md b/CHANGELOG.md index 802deb5f4..3e6d4f2ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,15 @@ ## 1.65.0 +* **Breaking change**: Passing a number with unit `%` to the `$alpha` parameter + of `color.change()`, `color.adjust()`, `change-color()`, and `adjust-color()` + is now interpreted as a percentage, instead of ignoring the unit. For example, + `color.change(red, $alpha: 50%)` now returns `rgb(255 0 0 / 0.5)`. + * Add support for CSS Color Level 4 [color spaces]. Each color value now tracks its color space along with the values of each channel in that color space. There are two general principles to keep in mind when dealing with new color spaces: - + 1. With the exception of legacy color spaces (`rgb`, `hsl`, and `hwb`), colors will always be emitted in the color space they were defined in unless they're explicitly converted. diff --git a/lib/src/functions/color.dart b/lib/src/functions/color.dart index 56322f0b7..9d2400af6 100644 --- a/lib/src/functions/color.dart +++ b/lib/src/functions/color.dart @@ -728,8 +728,24 @@ SassColor _changeColor( channelArgs[0] ?? SassNumber(color.channel0), channelArgs[1] ?? SassNumber(color.channel1, latterUnits), channelArgs[2] ?? SassNumber(color.channel2, latterUnits), - alphaArg.andThen( - (alphaArg) => _percentageOrUnitless(alphaArg, 1, 'alpha')) ?? + alphaArg.andThen((alphaArg) { + if (!alphaArg.hasUnits) { + return alphaArg.value; + } else if (alphaArg.hasUnit('%')) { + return alphaArg.value / 100; + } else { + warnForDeprecation( + "\$alpha: Passing a unit other than % ($alphaArg) is " + "deprecated.\n" + "\n" + "To preserve current behavior: " + "${alphaArg.unitSuggestion('alpha')}\n" + "\n" + "See https://sass-lang.com/d/function-units", + Deprecation.functionUnits); + return alphaArg.value; + } + }) ?? color.alpha); } diff --git a/test/deprecations_test.dart b/test/deprecations_test.dart index 28cd1e2fd..157963477 100644 --- a/test/deprecations_test.dart +++ b/test/deprecations_test.dart @@ -98,12 +98,6 @@ void main() { _expectDeprecation("a {b: hsl(10deg, 0%, 0)}", Deprecation.functionUnits); }); - test("an alpha value with a percent unit", () { - _expectDeprecation( - r"@use 'sass:color'; a {b: color.change(red, $alpha: 1%)}", - Deprecation.functionUnits); - }); - test("an alpha value with a non-percent unit", () { _expectDeprecation( r"@use 'sass:color'; a {b: color.change(red, $alpha: 1px)}",