@@ -90,6 +90,12 @@ type HueInterpolationMethod =
90
90
| 'longer'
91
91
| 'shorter' ;
92
92
93
+ /**
94
+ * Methods by which colors in bounded spaces can be mapped to within their
95
+ * gamut.
96
+ */
97
+ type GamutMapMethod = 'clip' | 'local-minde' ;
98
+
93
99
/** Options for specifying any channel value. */
94
100
type ChannelOptions = {
95
101
[ key in ChannelName ] ?: number | null ;
@@ -153,6 +159,14 @@ function encodeSpaceForColorJs(space?: KnownColorSpace): string | undefined {
153
159
return space ;
154
160
}
155
161
162
+ /**
163
+ * Normalize discrepancies between Sass's [GamutMapMethod] and Color.js's
164
+ * `method` option.
165
+ */
166
+ function encodeGamutMapMethodForColorJs ( method : GamutMapMethod ) : string {
167
+ return method === 'local-minde' ? 'css' : method ;
168
+ }
169
+
156
170
/**
157
171
* Normalize discrepancies between Sass color spaces and ColorJS color space
158
172
* ids, converting ColorJS values to Sass values.
@@ -714,18 +728,21 @@ export class SassColor extends Value {
714
728
715
729
/**
716
730
* Returns a copy of this color, modified so it is in-gamut for the specified
717
- * `space`—or the current color space if `space` is not specified—using the
718
- * recommended [CSS Gamut Mapping Algorithm][css-mapping] to map out-of-gamut
719
- * colors into the desired gamut with as little perceptual change as possible.
720
- *
721
- * [css-mapping]:
722
- * https://www.w3.org/TR/css-color-4/#css-gamut-mapping-algorithm
731
+ * `space`—or the current color space if `space` is not specified—using
732
+ * `method` to map out-of-gamut colors into the desired gamut.
723
733
*/
724
- toGamut ( space ?: KnownColorSpace ) : SassColor {
734
+ toGamut ( {
735
+ space,
736
+ method,
737
+ } : {
738
+ space ?: KnownColorSpace ;
739
+ method : GamutMapMethod ;
740
+ } ) : SassColor {
725
741
if ( this . isInGamut ( space ) ) return this ;
726
- const color = this . color
727
- . clone ( )
728
- . toGamut ( { space : encodeSpaceForColorJs ( space ) } ) ;
742
+ const color = this . color . clone ( ) . toGamut ( {
743
+ space : encodeSpaceForColorJs ( space ) ,
744
+ method : encodeGamutMapMethodForColorJs ( method ) ,
745
+ } ) ;
729
746
return new SassColor ( { color, space : space ?? this . space } ) ;
730
747
}
731
748
0 commit comments