@@ -120,9 +120,9 @@ abstract class Color implements IColor {
120120
121121 getColorSpaceAxes ( xyChannels : { xChannel ?: ColorChannel , yChannel ?: ColorChannel } ) : ColorAxes {
122122 let { xChannel, yChannel} = xyChannels ;
123- let xCh = xChannel || this . getColorChannels ( ) . find ( c => c !== yChannel ) ;
124- let yCh = yChannel || this . getColorChannels ( ) . find ( c => c !== xCh ) ;
125- let zCh = this . getColorChannels ( ) . find ( c => c !== xCh && c !== yCh ) ;
123+ let xCh = xChannel || this . getColorChannels ( ) . find ( c => c !== yChannel ) ! ;
124+ let yCh = yChannel || this . getColorChannels ( ) . find ( c => c !== xCh ) ! ;
125+ let zCh = this . getColorChannels ( ) . find ( c => c !== xCh && c !== yCh ) ! ;
126126
127127 return { xChannel : xCh , yChannel : yCh , zChannel : zCh } ;
128128 }
@@ -245,7 +245,7 @@ class RGBColor extends Color {
245245 }
246246
247247 static parse ( value : string ) {
248- let colors = [ ] ;
248+ let colors : Array < number | undefined > = [ ] ;
249249 // matching #rgb, #rgba, #rrggbb, #rrggbbaa
250250 if ( / ^ # [ \d a - f ] + $ / i. test ( value ) && [ 4 , 5 , 7 , 9 ] . includes ( value . length ) ) {
251251 const values = ( value . length < 6 ? value . replace ( / [ ^ # ] / gi, '$&$&' ) : value ) . slice ( 1 ) . split ( '' ) ;
@@ -259,7 +259,12 @@ class RGBColor extends Color {
259259 const match = value . match ( / ^ r g b a ? \( ( .* ) \) $ / ) ;
260260 if ( match ?. [ 1 ] ) {
261261 colors = match [ 1 ] . split ( ',' ) . map ( value => Number ( value . trim ( ) ) ) ;
262- colors = colors . map ( ( num , i ) => clamp ( num , 0 , i < 3 ? 255 : 1 ) ) ;
262+ colors = colors . map ( ( num , i ) => {
263+ return clamp ( num ?? 0 , 0 , i < 3 ? 255 : 1 ) ;
264+ } ) ;
265+ }
266+ if ( colors [ 0 ] === undefined || colors [ 1 ] === undefined || colors [ 2 ] === undefined ) {
267+ return undefined ;
263268 }
264269
265270 return colors . length < 3 ? undefined : new RGBColor ( colors [ 0 ] , colors [ 1 ] , colors [ 2 ] , colors [ 3 ] ?? 1 ) ;
@@ -371,6 +376,7 @@ class RGBColor extends Color {
371376 hue = ( blue - red ) / chroma + 2 ;
372377 break ;
373378 case blue :
379+ default :
374380 hue = ( red - green ) / chroma + 4 ;
375381 break ;
376382 }
@@ -443,7 +449,7 @@ class HSBColor extends Color {
443449 }
444450
445451 static parse ( value : string ) : HSBColor | void {
446- let m : RegExpMatchArray | void ;
452+ let m : RegExpMatchArray | null ;
447453 if ( ( m = value . match ( HSB_REGEX ) ) ) {
448454 const [ h , s , b , a ] = ( m [ 1 ] ?? m [ 2 ] ) . split ( ',' ) . map ( n => Number ( n . trim ( ) . replace ( '%' , '' ) ) ) ;
449455 return new HSBColor ( normalizeHue ( h ) , clamp ( s , 0 , 100 ) , clamp ( b , 0 , 100 ) , clamp ( a ?? 1 , 0 , 1 ) ) ;
@@ -582,7 +588,7 @@ class HSLColor extends Color {
582588 }
583589
584590 static parse ( value : string ) : HSLColor | void {
585- let m : RegExpMatchArray | void ;
591+ let m : RegExpMatchArray | null ;
586592 if ( ( m = value . match ( HSL_REGEX ) ) ) {
587593 const [ h , s , l , a ] = ( m [ 1 ] ?? m [ 2 ] ) . split ( ',' ) . map ( n => Number ( n . trim ( ) . replace ( '%' , '' ) ) ) ;
588594 return new HSLColor ( normalizeHue ( h ) , clamp ( s , 0 , 100 ) , clamp ( l , 0 , 100 ) , clamp ( a ?? 1 , 0 , 1 ) ) ;
0 commit comments