Skip to content

Commit f7a3470

Browse files
authored
Allow high-contrast input colors to be used as-is (#3209)
1 parent f328a41 commit f7a3470

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

.changeset/rich-lamps-compare.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@gitbook/colors": patch
3+
---
4+
5+
Change lightness check for color step 9 to allow input colors with a higher-than-needed contrast

packages/colors/src/transformations.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,11 @@ export function colorScale(
214214
const targetL =
215215
foregroundColor.L * mapping[index] + backgroundColor.L * (1 - mapping[index]);
216216

217-
if (index === 8 && !mix && Math.abs(baseColor.L - targetL) < 0.2) {
217+
if (
218+
index === 8 &&
219+
!mix &&
220+
(darkMode ? targetL - baseColor.L < 0.2 : baseColor.L - targetL < 0.2)
221+
) {
218222
// Original colour is close enough to target, so let's use the original colour as step 9.
219223
result.push(hex);
220224
continue;

0 commit comments

Comments
 (0)