From f7a34706c7302093f17ebb7bd324923d00a9f5b4 Mon Sep 17 00:00:00 2001 From: Zeno Kapitein Date: Fri, 2 May 2025 19:41:05 +0200 Subject: [PATCH] Allow high-contrast input colors to be used as-is (#3209) --- .changeset/rich-lamps-compare.md | 5 +++++ packages/colors/src/transformations.ts | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changeset/rich-lamps-compare.md diff --git a/.changeset/rich-lamps-compare.md b/.changeset/rich-lamps-compare.md new file mode 100644 index 000000000..57b026b7b --- /dev/null +++ b/.changeset/rich-lamps-compare.md @@ -0,0 +1,5 @@ +--- +"@gitbook/colors": patch +--- + +Change lightness check for color step 9 to allow input colors with a higher-than-needed contrast diff --git a/packages/colors/src/transformations.ts b/packages/colors/src/transformations.ts index 90cb4482e..8234a460a 100644 --- a/packages/colors/src/transformations.ts +++ b/packages/colors/src/transformations.ts @@ -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;