From 3548075abb41baffb05ebd8f45886bb487ed3961 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Mon, 30 Dec 2024 20:56:50 +0200 Subject: [PATCH] i have no idea how this worked but now it actually works --- src/services/color_convert/color_convert.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/services/color_convert/color_convert.js b/src/services/color_convert/color_convert.js index a8b0f7741..aa7dc8b94 100644 --- a/src/services/color_convert/color_convert.js +++ b/src/services/color_convert/color_convert.js @@ -197,7 +197,7 @@ export const getTextColor = function (bg, text, preserve) { const originalColor = convert(text).hex const invertedColor = invertLightness(originalColor).hex - const invertedContrast = getContrastRatio(bg, invertedColor) + const invertedContrast = getContrastRatio(bg, convert(invertedColor).rgb) let workColor if (invertedContrast > originalContrast) { @@ -210,9 +210,10 @@ export const getTextColor = function (bg, text, preserve) { const result = convert(rgb2hex(workColor)).hsl const delta = result.l > 50 ? 1 : -1 const multiplier = 10 - while (contrast < 4.5) { + while (contrast < 4.5 && result.l > 0 && result.l < 100) { result.l += delta * multiplier - contrast = getContrastRatio(bg, result) + contrast = getContrastRatio(bg, convert(result).rgb) + console.log(convert(result).hex, result.l, contrast) } const base = typeof text.a !== 'undefined' ? { a: text.a } : {}