We already use an appropriate colour automatically depending on the background. If you have a very dark background, the text will be a light colour. If you have a very light background, the text will be a dark colour.
I know but it doesn’t work as well as my function works as you can see in my screenshot. Maybe it is ok for you but my function is based on science and works very well since many years for all of my clients.