@use "../variables/colours"; @use "sass:color"; @use "sass:math"; @mixin text-contrast($n, $dark: colours.$black, $light: colours.$white, $cutoff: 1.667) { $brightness: math.round((color.channel($n, "red") * 299) + (color.channel($n, "green") * 587) + math.div((color.channel($n, "blue") * 114), 1000)); $light-color: math.round((color.channel(colours.$white, "red") * 299) + (color.channel(colours.$white, "green") * 587) + math.div((color.channel(colours.$white, "blue") * 114), 1000)); @if math.abs($brightness) < (math.div($light-color, $cutoff)) { color: $light; } @else { color: $dark; } }