hover method
Generates a hovered variant of the given color
by darkening light colors and lighting dark colors based on their
HSL lightness.
Colors at the extremes (very light or very dark) will be adjusted more aggressively than colors in the middle.
The lightening and darkening are controlled by hoverLighten and hoverDarken.
Implementation
Color hover(Color color) {
final hsl = HSLColor.fromColor(color);
final l = hsl.lightness;
// More aggressive color change when close to extremes & less when in the middle.
final (space, factor, sign) = l > 0.5 ? (1.0 - l, hoverDarken, -1) : (l, hoverLighten, 1);
final aggressiveness = 1 + ((0.5 - space) / 0.5);
final adjustment = factor * aggressiveness * sign;
final lightness = clampDouble(l + adjustment, 0, 1);
return hsl.withLightness(lightness).toColor();
}