@use 'sass:math';

/*
 * Provides a colour equivalent (when over a white background) to a given opaque
 * colour, but with a maximum value of alpha.
 * Obtained from: https://stackoverflow.com/questions/6672374
 */
@function transparentize-on-white($color) {
  $red: red($color);
  $green: green($color);
  $blue: blue($color);
  $lowestColorComponent: min($red, $green, $blue);
  $alpha: math.div(255 - $lowestColorComponent, 255);

  @return rgba(
    math.div($red - $lowestColorComponent, $alpha),
    math.div($green - $lowestColorComponent, $alpha),
    math.div($blue - $lowestColorComponent, $alpha),
    $alpha
  );
}
