i have no idea how this worked but now it actually works
This commit is contained in:
parent
5e098c1231
commit
3548075abb
1 changed files with 4 additions and 3 deletions
|
@ -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 } : {}
|
||||
|
|
Loading…
Add table
Reference in a new issue