blob: 722c8d60dd4ce5bcca04e33eceb33cac3b8901c3 [file] [log] [blame]
////
/// @group components/functions
////
/* light, strong, medium */
/// Calculates a contrasting color relative to the passed parameters.
/// @param {number} $strength
/// @param {hex} $color
/// @param {bool} $desaturate
@function get_contrast ($strength, $color, $desaturate: true) {
$new-color: $color;
$new-color: darken($color, $strength);
$strength-offset: 50; //in case of unexpected bright spots in dark themes
@if lightness($new-color) <= 5 {
@if $strength > $strength-offset {
$new-color: darken($color, $strength - $strength-offset);
//@warn "doppeldunkel #{$new-color}-";
}
@else {
$new-color: lighten($color, $strength);
}
}
@else if lightness($new-color) >= 95 {
$new-color: darken($color, $strength);
}
@if $desaturate == true {
$new-color: desaturate($new-color, 100%);
}
@return $new-color;
}
/// Mixes two colors.
/// @todo seem's useless. Could just call built-in "mix" function.
@function get_color_mix ($color, $mix, $strength) {
$new-color: mix($color, $mix, $strength);
@return $new-color;
}
/// Remove the unit of a length
/// @param {Number} $number - Number to remove unit from
/// @return {Number} - Unitless number
@function strip_unit($number) {
@if type-of($number) == 'number' and not unitless($number) {
@return $number / ($number * 0 + 1);
}
@return $number;
}
/// Tries to return an even number.
/// Unfortunately, sass modulo never returns fractions, so this is a bit cumbersome.
@function make_even($number) {
/* TODO: */
/* v-layout-spacing muss ne gerade zahl sein, rest aber eigentlich "nur" auf ne glatte zahl gerundet. */
/* genau unterscheiden, wo was gebraucht wird, sonst basst nix! */
/* make sure units are correct */
$even-number: $number + 0px;
/* $number: strip_unit($number); */
$num-ceil: ceil($number);
$num-floor: floor($number);
@if $num-ceil % 2 == 0px {
$t1: $num-ceil % 2;
$even-number: $num-ceil;
}
@else if $num-floor % 2 == 0px {
$t2: $num-ceil % 2;
$even-number: $num-floor;
}
@else { /*assume that number is an odd integer - this might not go well*/
$even-number: $number + 1px;
}
/* Line below shows up as exception; use to check values... */
/* @return ($even-number,$num-ceil, $num-floor, $t1, $t2) ; */
@return $even-number;
}
@function sqrt($r) {
$x0: 1;
$x1: $x0;
@for $i from 1 through 10 {
$x1: $x0 - ($x0 * $x0 - abs($r)) / (2 * $x0);
$x0: $x1;
}
@return $x1;
}
/*
* Luminance Formula
* Y = 0.2126 R + 0.7152 G + 0.0722 B
83 96 122
@function is-dark-color($color) {
$luminance: color-luminance($color);
@if $luminance < $v-luminance-threshold or (saturation($color) > 80% and ($luminance < $v-luminance-threshold + 20)) {
@return true;
} @else {
@return false;
}
} */