'Invert part of the image color with CSS

I have an image with 3 colors: black, white, and purple. When inverted the purple turns green, how can I keep the purple and let black invert to white and white into black?enter image description here

.dark-mode .invert {
    -webkit-filter: invert(1);
   filter: invert(1);
}

enter image description here

css


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source