@use 'sass:color';
@use 'sass:list';
@use 'variables' as v;

/// Calculates the luminance of a color.
/// Luminance is defined as a decimal value between 0 and 1,
/// with "0" corresponding to "no brightness"
/// and "1" corresponding to "full brightness".
///
/// See [WCAG 2.0 Contrast Ratio (G17)](https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests)
/// for more information.
///
///	@example scss
/// 	@include daff-luminance(#efefef);
///
@function daff-luminance($color) {
	$red-index: color.channel($color, 'red') + 1;
	$green-index: color.channel($color, 'green') + 1;
	$blue-index: color.channel($color, 'blue') + 1;

	$red: list.nth(v.$linear-channel-values, $red-index);
	$green: list.nth(v.$linear-channel-values, $green-index);
	$blue: list.nth(v.$linear-channel-values, $blue-index);
	@return 0.2126 * $red + 0.7152 * $green + 0.0722 * $blue;
}
