You can consider the fact that a color with negative luminosity is always black and a white color is a color with luminosity bigger than 100%
.
Here is an idea where I use calc(30% - luminosity)
which will return a positive value if the luminosity is less than 30% (white color) and will return a negative value if the luminosity bigger than 30% (black color). I multiply everything by 100
to always have white in case of small positive value.
:root {
--main-color-hue: 205;
--main-color-saturation: 73%;
--main-color-luminosity: 29%;
--main-color: hsla(var(--main-color-hue), var(--main-color-saturation), var(--main-color-luminosity), 1);
--main-dark-color: hsla(var(--main-color-hue), var(--main-color-saturation), calc(var(--main-color-luminosity) * 0.5), 1);
--main-light-color: hsla(var(--main-color-hue), var(--main-color-saturation), calc(var(--main-color-luminosity) * 1.5), 1);
--main-text-color: hsl(0,100%, calc((30% - var(--main-color-luminosity)) *100));
--main-dark-text-color: hsl(0,100%, calc((30% - var(--main-color-luminosity)*0.5) *100));
--main-light-text-color: hsl(0,100%, calc((30% - var(--main-color-luminosity)*1.5) *100));
}
button {
background-color: var(--main-color);
color: var(--main-text-color);
border: 0;
padding: 16px;
}
button.dark {
background-color: var(--main-dark-color);
color: var(--main-dark-text-color);
border: 0;
padding: 16px;
}
button.light {
background-color: var(--main-light-color);
color: var(--main-light-text-color);
border: 0;
padding: 16px;
}
Main
<button>test</button>
Dark
<button class="dark">test</button>
Light
<button class="light">test</button>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…