@function color($value) @if type-of($value) == color @return true @else @return null @function color_list($values) @if list($values) @each $value in $values @if color($value) @return true @else @return null @else @return null @function optional_color_list($values) @if color($values) @return true @else if color_list($values) @return true @else @return null @function luma($color) // Adapted from: https://gist.github.com/voxpelli/6304812 $rgba: red($color), green($color), blue($color) $rgba2: () @for $i from 1 through 3 $rgb: nth($rgba, $i) $rgb: $rgb / 255 $rgb: if($rgb < .03928, $rgb / 12.92, pow(($rgb + .055) / 1.055, 2.4)) $rgba2: append($rgba2, $rgb) @return (.2126 * nth($rgba2, 1) + .7152 * nth($rgba2, 2) + .0722 * nth($rgba2, 3))*100 $ruma-threshold: 100 / pi() !default @function luma_contrast($color-1, $color-2: null) @if $color-2 @if abs(luma($color-1) - luma($color-2)) > $ruma-threshold @return true @else @return null @else @return if(luma($color-1) < 51, dark, bright) @function luma_value($color-1, $color-2: null) @if $color-2 @return abs(luma($color-1) - luma($color-2)) @else @return luma($color-1) @function luma_which($color) @return if(luma($color) < 51, dark, bright) @function luma_bright($color) @if luma($color) < 51 @return null @else @return true @function luma_dark($color) @if luma($color) < 51 @return true @else @return null @function luma_contrast_color($color) $luma-contrast-bright-color: #000000 !default $luma-contrast-dark-color: #ffffff !default @if luma_which($color) == bright @return $luma-contrast-bright-color @else @return $luma-contrast-dark-color @function luma_add_contrast($background-color, $candidate-color) @if luma_contrast($background-color, $candidate-color) @return $candidate-color @else @if luma_dark($background-color) @return tint($candidate-color, reverse(percentage(luma_value($background-color, $candidate-color)*0.01))/1.618) @else @return shade($candidate-color, reverse(percentage(luma_value($background-color, $candidate-color)*0.01))/1.618)