@@ -117,14 +117,6 @@ function getColorSpace(options: ChannelOptions): KnownColorSpace {
117117 throw valueError ( 'No color space found' ) ;
118118}
119119
120- /**
121- * Convert from the ColorJS representation of a missing component (`null`) to
122- * `NaN`.
123- */
124- function nullToNaN ( val : number | null ) : number {
125- return val ?? NaN ;
126- }
127-
128120/**
129121 * Convert from the ColorJS representation of a missing component (`null`) to
130122 * `0`.
@@ -650,8 +642,7 @@ export class SassColor extends Value {
650642 */
651643 get red ( ) : number {
652644 emitColor4ApiGetterDeprecation ( 'red' ) ;
653- const val = nullToZero ( coordToRgb ( this . color . srgb . red ) ) ;
654- return fuzzyRound ( val ) ;
645+ return fuzzyRound ( coordToRgb ( this . color . srgb . red ) ) ?? 0 ;
655646 }
656647
657648 /**
@@ -661,8 +652,7 @@ export class SassColor extends Value {
661652 */
662653 get green ( ) : number {
663654 emitColor4ApiGetterDeprecation ( 'green' ) ;
664- const val = nullToZero ( coordToRgb ( this . color . srgb . green ) ) ;
665- return fuzzyRound ( val ) ;
655+ return fuzzyRound ( coordToRgb ( this . color . srgb . green ) ) ?? 0 ;
666656 }
667657
668658 /**
@@ -672,8 +662,7 @@ export class SassColor extends Value {
672662 */
673663 get blue ( ) : number {
674664 emitColor4ApiGetterDeprecation ( 'blue' ) ;
675- const val = nullToZero ( coordToRgb ( this . color . srgb . blue ) ) ;
676- return fuzzyRound ( val ) ;
665+ return fuzzyRound ( coordToRgb ( this . color . srgb . blue ) ) ?? 0 ;
677666 }
678667
679668 /**
@@ -1157,49 +1146,47 @@ export class SassColor extends Value {
11571146 coords = this . color
11581147 . to ( 'srgb' )
11591148 . coords . map ( coordToRgb )
1160- . map ( nullToNaN )
1161- . map ( fuzzyRound ) as [ number , number , number ] ;
1149+ . map ( fuzzyRound ) as [ number | null , number | null , number | null ] ;
11621150 otherCoords = other . color
11631151 . to ( 'srgb' )
11641152 . coords . map ( coordToRgb )
1165- . map ( nullToNaN )
1166- . map ( fuzzyRound ) as [ number , number , number ] ;
1153+ . map ( fuzzyRound ) as [ number | null , number | null , number | null ] ;
11671154 }
11681155 return (
1169- fuzzyEquals ( nullToNaN ( coords [ 0 ] ) , nullToNaN ( otherCoords [ 0 ] ) ) &&
1170- fuzzyEquals ( nullToNaN ( coords [ 1 ] ) , nullToNaN ( otherCoords [ 1 ] ) ) &&
1171- fuzzyEquals ( nullToNaN ( coords [ 2 ] ) , nullToNaN ( otherCoords [ 2 ] ) )
1156+ fuzzyEquals ( coords [ 0 ] , otherCoords [ 0 ] ) &&
1157+ fuzzyEquals ( coords [ 1 ] , otherCoords [ 1 ] ) &&
1158+ fuzzyEquals ( coords [ 2 ] , otherCoords [ 2 ] )
11721159 ) ;
11731160 }
11741161 return (
11751162 this . space === other . space &&
1176- fuzzyEquals ( nullToNaN ( coords [ 0 ] ) , nullToNaN ( otherCoords [ 0 ] ) ) &&
1177- fuzzyEquals ( nullToNaN ( coords [ 1 ] ) , nullToNaN ( otherCoords [ 1 ] ) ) &&
1178- fuzzyEquals ( nullToNaN ( coords [ 2 ] ) , nullToNaN ( otherCoords [ 2 ] ) ) &&
1163+ fuzzyEquals ( coords [ 0 ] , otherCoords [ 0 ] ) &&
1164+ fuzzyEquals ( coords [ 1 ] , otherCoords [ 1 ] ) &&
1165+ fuzzyEquals ( coords [ 2 ] , otherCoords [ 2 ] ) &&
11791166 fuzzyEquals ( this . alpha , other . alpha )
11801167 ) ;
11811168 }
11821169
11831170 hashCode ( ) : number {
11841171 let coords = this . color . coords ;
11851172 if ( this . isLegacy ) {
1186- coords = this . color
1187- . to ( 'srgb' )
1188- . coords . map ( coordToRgb )
1189- . map ( nullToNaN )
1190- . map ( fuzzyRound ) as [ number , number , number ] ;
1173+ coords = this . color . to ( 'srgb' ) . coords . map ( coordToRgb ) . map ( fuzzyRound ) as [
1174+ number ,
1175+ number ,
1176+ number ,
1177+ ] ;
11911178 return (
1192- fuzzyHashCode ( nullToNaN ( coords [ 0 ] ) ) ^
1193- fuzzyHashCode ( nullToNaN ( coords [ 1 ] ) ) ^
1194- fuzzyHashCode ( nullToNaN ( coords [ 2 ] ) ) ^
1179+ fuzzyHashCode ( coords [ 0 ] ) ^
1180+ fuzzyHashCode ( coords [ 1 ] ) ^
1181+ fuzzyHashCode ( coords [ 2 ] ) ^
11951182 fuzzyHashCode ( this . alpha )
11961183 ) ;
11971184 }
11981185 return (
11991186 hash ( this . space ) ^
1200- fuzzyHashCode ( nullToNaN ( coords [ 0 ] ) ) ^
1201- fuzzyHashCode ( nullToNaN ( coords [ 1 ] ) ) ^
1202- fuzzyHashCode ( nullToNaN ( coords [ 2 ] ) ) ^
1187+ fuzzyHashCode ( coords [ 0 ] ) ^
1188+ fuzzyHashCode ( coords [ 1 ] ) ^
1189+ fuzzyHashCode ( coords [ 2 ] ) ^
12031190 fuzzyHashCode ( this . alpha )
12041191 ) ;
12051192 }
0 commit comments