Here is an approximation using filter. Not sure if it will cover all the cases.
.color {
padding: 5px;
background: currentColor;
}
.color>span {
filter: invert(1) saturate(0);
font-weight: bold;
font-size: 23px;
}
<div class="color" style="color: #fff">
<span>good</span>
</div>
<div class="color" style="color: #000">
<span>good</span>
</div>
<div class="color" style="color: #0f0">
<span>should be black or dark grey</span>
</div>
<div class="color" style="color: #00f">
<span>should be white or light grey</span>
</div>
<div class="color" style="color: #f00">
<span>should be white or light grey</span>
</div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…