mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-25 09:03:12 +03:00
Fixed infinite loop when lightening/darkening colors
refs https://github.com/TryGhost/Team/issues/928
refs eed299d1f6
- usage of `color` was incorrect resulting in an infinite loop because the color was not being changed on each iteration
- `Color().lightness()` adjusts via percentage not exact number
- `Color().l()` does not return lightness
This commit is contained in:
parent
2cf55cb307
commit
3c3b3e6710
@ -4,14 +4,16 @@ export function lightenToContrastThreshold(foreground, background, contrastThres
|
||||
const foregroundColor = Color(foreground);
|
||||
const backgroundColor = Color(background);
|
||||
|
||||
const {h,s} = foregroundColor.hsl().object();
|
||||
|
||||
let newColor = foregroundColor;
|
||||
|
||||
while (newColor.contrast(backgroundColor) < contrastThreshold) {
|
||||
if (newColor.l() >= 100) {
|
||||
if (newColor.lightness() >= 100) {
|
||||
break;
|
||||
}
|
||||
|
||||
newColor = newColor.lightness(newColor.l() + 5);
|
||||
newColor = Color({h, s, l: newColor.lightness() + 5});
|
||||
}
|
||||
|
||||
return newColor;
|
||||
@ -21,14 +23,16 @@ export function darkenToContrastThreshold(foreground, background, contrastThresh
|
||||
const foregroundColor = Color(foreground);
|
||||
const backgroundColor = Color(background);
|
||||
|
||||
const {h,s} = foregroundColor.hsl().object();
|
||||
|
||||
let newColor = foregroundColor;
|
||||
|
||||
while (newColor.contrast(backgroundColor) < contrastThreshold) {
|
||||
if (newColor.l() <= 0) {
|
||||
if (newColor.lightness() <= 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
newColor = newColor.lightness(newColor.l() - 5);
|
||||
newColor = Color({h, s, l: newColor.lightness() - 5});
|
||||
}
|
||||
|
||||
return newColor;
|
||||
|
Loading…
Reference in New Issue
Block a user