Interesting. Made me think to write a simple mixin for sass.
@mixin fg-contrast($bg) {
background: $bg;
$textcolor: #ffffff;
@if lightness($bg) > 50% {
$textcolor: #000000;
}
color: $textcolor;
}
Could also be done by using the red(), green(), and blue() functions, but lightness was simpler.