@@ -294,12 +294,13 @@ export function getPodColor(podName: string): string {
294294 return podColorCache . get ( podName ) ! ;
295295 }
296296
297- // Generate multiple hash values for better distribution
297+ // Generate multiple hash values for better distribution with overflow protection
298298 let hash1 = 0 ;
299299 let hash2 = 0 ;
300300 for ( let i = 0 ; i < podName . length ; i ++ ) {
301- hash1 = podName . charCodeAt ( i ) + ( ( hash1 << 5 ) - hash1 ) ;
302- hash2 = podName . charCodeAt ( i ) + ( ( hash2 << 3 ) - hash2 ) + i ;
301+ const char = podName . charCodeAt ( i ) ;
302+ hash1 = ( char + ( ( hash1 << 5 ) - hash1 ) ) >>> 0 ; // Use unsigned right shift to keep 32-bit
303+ hash2 = ( char + ( ( hash2 << 3 ) - hash2 ) + i ) >>> 0 ;
303304 }
304305
305306 // Create distinct color palette with wider ranges and better separation
@@ -314,19 +315,23 @@ export function getPodColor(podName: string): string {
314315 { r : [ 180 , 220 ] , g : [ 140 , 200 ] , b : [ 50 , 100 ] } , // Orange variations
315316 { r : [ 140 , 200 ] , g : [ 50 , 100 ] , b : [ 180 , 220 ] } , // Purple variations
316317 { r : [ 50 , 100 ] , g : [ 180 , 220 ] , b : [ 140 , 200 ] } , // Teal variations
317- { r : [ 255 , 255 ] , g : [ 160 , 200 ] , b : [ 160 , 200 ] } , // Light corals
318- { r : [ 160 , 200 ] , g : [ 255 , 255 ] , b : [ 160 , 200 ] } , // Light greens
319- { r : [ 160 , 200 ] , g : [ 160 , 200 ] , b : [ 255 , 255 ] } // Light blues
318+ { r : [ 240 , 255 ] , g : [ 160 , 200 ] , b : [ 160 , 200 ] } , // Light corals
319+ { r : [ 160 , 200 ] , g : [ 240 , 255 ] , b : [ 160 , 200 ] } , // Light greens
320+ { r : [ 160 , 200 ] , g : [ 160 , 200 ] , b : [ 240 , 255 ] } // Light blues
320321 ] ;
321322
322323 // Select color scheme based on first hash
323- const schemeIndex = Math . abs ( hash1 ) % colorSchemes . length ;
324+ const schemeIndex = hash1 % colorSchemes . length ;
324325 const scheme = colorSchemes [ schemeIndex ] ;
325326
326- // Generate RGB values within the selected scheme's ranges
327- const r = scheme . r [ 0 ] + ( Math . abs ( hash1 ) % ( scheme . r [ 1 ] - scheme . r [ 0 ] ) ) ;
328- const g = scheme . g [ 0 ] + ( Math . abs ( hash2 ) % ( scheme . g [ 1 ] - scheme . g [ 0 ] ) ) ;
329- const b = scheme . b [ 0 ] + ( Math . abs ( hash1 ^ hash2 ) % ( scheme . b [ 1 ] - scheme . b [ 0 ] ) ) ;
327+ // Generate RGB values within the selected scheme's ranges with safety checks
328+ const rRange = Math . max ( 1 , scheme . r [ 1 ] - scheme . r [ 0 ] ) ;
329+ const gRange = Math . max ( 1 , scheme . g [ 1 ] - scheme . g [ 0 ] ) ;
330+ const bRange = Math . max ( 1 , scheme . b [ 1 ] - scheme . b [ 0 ] ) ;
331+
332+ const r = scheme . r [ 0 ] + ( hash1 % rRange ) ;
333+ const g = scheme . g [ 0 ] + ( hash2 % gRange ) ;
334+ const b = scheme . b [ 0 ] + ( Math . abs ( hash1 ^ hash2 ) % bRange ) ;
330335
331336 // Ensure minimum contrast for readability
332337 let finalR = clamp ( r ) ;
0 commit comments