Allow high-contrast input colors to be used as-is (#3209)

This commit is contained in:
Zeno Kapitein
2025-05-02 19:41:05 +02:00
committed by GitHub
parent f328a41982
commit f7a34706c7
2 changed files with 10 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@gitbook/colors": patch
---
Change lightness check for color step 9 to allow input colors with a higher-than-needed contrast
+5 -1
View File
@@ -214,7 +214,11 @@ export function colorScale(
const targetL =
foregroundColor.L * mapping[index] + backgroundColor.L * (1 - mapping[index]);
if (index === 8 && !mix && Math.abs(baseColor.L - targetL) < 0.2) {
if (
index === 8 &&
!mix &&
(darkMode ? targetL - baseColor.L < 0.2 : baseColor.L - targetL < 0.2)
) {
// Original colour is close enough to target, so let's use the original colour as step 9.
result.push(hex);
continue;