@@ -106,6 +106,12 @@ final global = UnmodifiableListView([
106
106
var color = arguments[0 ].assertColor ("color" );
107
107
var degrees = _angleValue (arguments[1 ], "degrees" );
108
108
109
+ if (! color.isLegacy) {
110
+ throw SassScriptException (
111
+ "adjust-hue() is only supported for legacy colors. Please use "
112
+ "color.adjust() instead with an explicit \$ space argument." );
113
+ }
114
+
109
115
var suggestedValue = SassNumber (degrees, 'deg' );
110
116
warnForDeprecation (
111
117
"adjust-hue() is deprecated. Suggestion:\n "
@@ -121,6 +127,12 @@ final global = UnmodifiableListView([
121
127
_function ("lighten" , r"$color, $amount" , (arguments) {
122
128
var color = arguments[0 ].assertColor ("color" );
123
129
var amount = arguments[1 ].assertNumber ("amount" );
130
+ if (! color.isLegacy) {
131
+ throw SassScriptException (
132
+ "lighten() is only supported for legacy colors. Please use "
133
+ "color.adjust() instead with an explicit \$ space argument." );
134
+ }
135
+
124
136
var result = color.changeHsl (
125
137
lightness: (color.lightness + amount.valueInRange (0 , 100 , "amount" ))
126
138
.clamp (0 , 100 ));
@@ -137,6 +149,12 @@ final global = UnmodifiableListView([
137
149
_function ("darken" , r"$color, $amount" , (arguments) {
138
150
var color = arguments[0 ].assertColor ("color" );
139
151
var amount = arguments[1 ].assertNumber ("amount" );
152
+ if (! color.isLegacy) {
153
+ throw SassScriptException (
154
+ "darken() is only supported for legacy colors. Please use "
155
+ "color.adjust() instead with an explicit \$ space argument." );
156
+ }
157
+
140
158
var result = color.changeHsl (
141
159
lightness: (color.lightness - amount.valueInRange (0 , 100 , "amount" ))
142
160
.clamp (0 , 100 ));
@@ -162,6 +180,12 @@ final global = UnmodifiableListView([
162
180
r"$color, $amount" : (arguments) {
163
181
var color = arguments[0 ].assertColor ("color" );
164
182
var amount = arguments[1 ].assertNumber ("amount" );
183
+ if (! color.isLegacy) {
184
+ throw SassScriptException (
185
+ "saturate() is only supported for legacy colors. Please use "
186
+ "color.adjust() instead with an explicit \$ space argument." );
187
+ }
188
+
165
189
var result = color.changeHsl (
166
190
saturation: (color.saturation + amount.valueInRange (0 , 100 , "amount" ))
167
191
.clamp (0 , 100 ));
@@ -179,6 +203,12 @@ final global = UnmodifiableListView([
179
203
_function ("desaturate" , r"$color, $amount" , (arguments) {
180
204
var color = arguments[0 ].assertColor ("color" );
181
205
var amount = arguments[1 ].assertNumber ("amount" );
206
+ if (! color.isLegacy) {
207
+ throw SassScriptException (
208
+ "desaturate() is only supported for legacy colors. Please use "
209
+ "color.adjust() instead with an explicit \$ space argument." );
210
+ }
211
+
182
212
var result = color.changeHsl (
183
213
saturation: (color.saturation - amount.valueInRange (0 , 100 , "amount" ))
184
214
.clamp (0 , 100 ));
@@ -203,18 +233,16 @@ final global = UnmodifiableListView([
203
233
(arguments) => _transparentize ("fade-out" , arguments)),
204
234
205
235
BuiltInCallable .overloadedFunction ("alpha" , {
206
- r"$color" : (arguments) {
207
- var argument = arguments[0 ];
208
- if (argument is SassString &&
209
- ! argument.hasQuotes &&
210
- argument.text.contains (_microsoftFilterStart)) {
211
- // Support the proprietary Microsoft alpha() function.
212
- return _functionString ("alpha" , arguments);
213
- }
214
-
215
- var color = argument.assertColor ("color" );
216
- return SassNumber (color.alpha);
217
- },
236
+ r"$color" : (arguments) => switch (arguments[0 ]) {
237
+ // Support the proprietary Microsoft alpha() function.
238
+ SassString (hasQuotes: false , : var text)
239
+ when text.contains (_microsoftFilterStart) =>
240
+ _functionString ("alpha" , arguments),
241
+ SassColor (isLegacy: false ) => throw SassScriptException (
242
+ "alpha() is only supported for legacy colors. Please use "
243
+ "color.channel() instead." ),
244
+ var argument => SassNumber (argument.assertColor ("color" ).alpha)
245
+ },
218
246
r"$args..." : (arguments) {
219
247
var argList = arguments[0 ].asList;
220
248
if (argList.isNotEmpty &&
@@ -364,21 +392,26 @@ final module = BuiltInModule("color", functions: <Callable>[
364
392
365
393
BuiltInCallable .overloadedFunction ("alpha" , {
366
394
r"$color" : (arguments) {
367
- var argument = arguments[0 ];
368
- if (argument is SassString &&
369
- ! argument.hasQuotes &&
370
- argument.text.contains (_microsoftFilterStart)) {
371
- var result = _functionString ("alpha" , arguments);
372
- warnForDeprecation (
373
- "Using color.alpha() for a Microsoft filter is deprecated.\n "
374
- "\n "
375
- "Recommendation: $result " ,
376
- Deprecation .colorModuleCompat);
377
- return result;
378
- }
395
+ switch (arguments[0 ]) {
396
+ // Support the proprietary Microsoft alpha() function.
397
+ case SassString (hasQuotes: false , : var text)
398
+ when text.contains (_microsoftFilterStart):
399
+ var result = _functionString ("alpha" , arguments);
400
+ warnForDeprecation (
401
+ "Using color.alpha() for a Microsoft filter is deprecated.\n "
402
+ "\n "
403
+ "Recommendation: $result " ,
404
+ Deprecation .colorModuleCompat);
405
+ return result;
406
+
407
+ case SassColor (isLegacy: false ):
408
+ throw SassScriptException (
409
+ "color.alpha() is only supported for legacy colors. Please use "
410
+ "color.channel() instead." );
379
411
380
- var color = argument.assertColor ("color" );
381
- return SassNumber (color.alpha);
412
+ case var argument:
413
+ return SassNumber (argument.assertColor ("color" ).alpha);
414
+ }
382
415
},
383
416
r"$args..." : (arguments) {
384
417
if (arguments[0 ].asList.every ((argument) =>
@@ -1155,6 +1188,12 @@ SassColor _mixLegacy(SassColor color1, SassColor color2, SassNumber weight) {
1155
1188
SassColor _opacify (String name, List <Value > arguments) {
1156
1189
var color = arguments[0 ].assertColor ("color" );
1157
1190
var amount = arguments[1 ].assertNumber ("amount" );
1191
+ if (! color.isLegacy) {
1192
+ throw SassScriptException (
1193
+ "$name () is only supported for legacy colors. Please use "
1194
+ "color.adjust() instead with an explicit \$ space argument." );
1195
+ }
1196
+
1158
1197
var result = color.changeAlpha (
1159
1198
(color.alpha + amount.valueInRangeWithUnit (0 , 1 , "amount" , "" ))
1160
1199
.clamp (0 , 1 ));
@@ -1172,6 +1211,12 @@ SassColor _opacify(String name, List<Value> arguments) {
1172
1211
SassColor _transparentize (String name, List <Value > arguments) {
1173
1212
var color = arguments[0 ].assertColor ("color" );
1174
1213
var amount = arguments[1 ].assertNumber ("amount" );
1214
+ if (! color.isLegacy) {
1215
+ throw SassScriptException (
1216
+ "$name () is only supported for legacy colors. Please use "
1217
+ "color.adjust() instead with an explicit \$ space argument." );
1218
+ }
1219
+
1175
1220
var result = color.changeAlpha (
1176
1221
(color.alpha - amount.valueInRangeWithUnit (0 , 1 , "amount" , "" ))
1177
1222
.clamp (0 , 1 ));
0 commit comments