diff --git a/src/app/utils/shadeColor.ts b/src/app/utils/shadeColor.ts index 00dabe397..b0b9ce59b 100644 --- a/src/app/utils/shadeColor.ts +++ b/src/app/utils/shadeColor.ts @@ -3,15 +3,13 @@ export function shadeColor(initialColor: string, percent: number) { const ratio = 1 + percent / 100; // Get hex value, convert it to number, multiply it by the desired amount, then clamp it - const R = Math.floor( - Math.max(Math.min(parseInt(initialColor.substring(1, 3), 16) * ratio, 255), 0) - ); - const G = Math.floor( - Math.max(Math.min(parseInt(initialColor.substring(3, 5), 16) * ratio, 255), 0) - ); - const B = Math.floor( - Math.max(Math.min(parseInt(initialColor.substring(5, 7), 16) * ratio, 255), 0) - ); + let R = Math.floor(Math.min(parseInt(initialColor.substring(1, 3), 16) * ratio, 255)); + let G = Math.floor(Math.min(parseInt(initialColor.substring(3, 5), 16) * ratio, 255)); + let B = Math.floor(Math.min(parseInt(initialColor.substring(5, 7), 16) * ratio, 255)); + + if (R <= 0 && percent > 0) R = Math.max(178 - R, 0); + if (G <= 0 && percent > 0) G = Math.max(178 - G, 0); + if (B <= 0 && percent > 0) B = Math.max(178 - B, 0); const RR = `${R < 16 ? '0' : ''}${R.toString(16)}`; const GG = `${G < 16 ? '0' : ''}${G.toString(16)}`;