From 3446423ed9cefd79ecadaa7b22d47bc69da30707 Mon Sep 17 00:00:00 2001 From: Shea Duma Date: Thu, 23 Apr 2026 02:17:19 +0300 Subject: [PATCH] edgecase of setting the color to #000 --- src/app/utils/shadeColor.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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)}`;