@import "function-contrast.scss"; @function tint($color, $percentage) { @return mix(white, $color, $percentage); } @function shade($color, $percentage) { @return mix(black, $color, $percentage); } @function tone($color, $percentage) { @return mix(grey, $color, $percentage); } @function invert($color, $amount: 100%) { $inverse: change-color($color, $hue: hue($color) + 180); @return mix($inverse, $color, $amount); } @function str-replace($string, $search, $replace: '') { $index: str-index($string, $search); @if $index { @return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace); } @return $string; } @mixin iefix($property1, $value1, $property2:null, $value2:null, $property3:null, $value3:null) { @media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) { #{$property1}: $value1; #{$property2}: $value2; #{$property3}: $value3; } } //lookup string2int $_str2int: ( '1': 1, '2': 2, '3': 3, '4': 4, '5': 5 ); ///////////////////////////////////////////// $default-text-color-contrast: 4.5; $dark-text-color-contrasts: ( 1 : 4.9, 2 : 5.5, 3 : 6.3, 4 : 7 ); $medium-text-color-contrasts: ( 1 : 4.1, 2 : 3.65, 3 : 3.2 ); $exclude-from-text-contrast: ( 'orange': 1, 'warning': 1, 'yellow': 1, 'light': 1, 'white': 1, ); ////////////////// $cached-colors: (); //text color functions @function text-color($name, $lightness: null) { @if $lightness == null { @return map-get($text-colors, $name); } $color: map-get($cached-colors, 'text:' + $name + ':' + $lightness); @if $color != null { @return $color } $type: str-slice($lightness, 1, 1); $index: map-get($_str2int, str-slice($lightness, 2, 2)); @if $type == 'l' { $color: light-text-color($name, $index); } @else if $type == 'm' { $color: medium-text-color($name, $index); } @else if $type == 'd' { $color: dark-text-color($name, $index); } $key: 'text:' + $name + ':' + $lightness; $cached-colors: map-merge(($key: $color), $cached-colors) !global; @return $color; } @function light-text-color($name, $index) { $color: map-get($text-colors, $name); @return lighten( $color , 14.5 + 4.25 * $index ); } @function medium-text-color($name, $index) { $color: map-get($text-colors, $name); $val: lighten( $color , 3.875 * $index ); $bg: #fff; $target-contrast: map-get($medium-text-color-contrasts, $index); @if $add-contrast == true and map-get($exclude-from-text-contrast, $name) == null { @while color-contrast($val, $bg) < $target-contrast { $val: darken($val, 0.5%); } } @return $val; } @function dark-text-color($name, $index) { $color: map-get($text-colors, $name); $val: darken( $color , 2.675 * ($index) ); $bg: #fff; $target-contrast: map-get($dark-text-color-contrasts, $index); @if $add-contrast == true and map-get($exclude-from-text-contrast, $name) == null { @while color-contrast($val, $bg) < $target-contrast { $val: darken($val, 0.5%); } } @return $val; } /////////////////////////////////////////////// //degree of lightness of bgc-name-l(x) colors $_lights: ( 1: 73, 2: 81.5, 3: 88, 4: 91.75, 5: 95.25 ); //degree of lightness of bgc-name-m(x) colors $_mediums: ( 1: 15, 2: 28, 3: 41, 4: 55 ); $_lightnesses: ( 1: 85, 2: 89.5, 3: 93.25, 4: 95.75, 5: 97.5 ); @function bgc-color($name, $lightness: null) { @if $lightness == null { @return map-get($background-colors, $name); } $color: map-get($cached-colors, 'bgc:' + $name + ':' + $lightness); @if $color != null { @return $color } $type: str-slice($lightness, 1, 1); $index: map-get($_str2int, str-slice($lightness, 2, 2)); @if $type == 'l' { $color: light-bgc-color($name, $index); } @else if $type == 'm' { $color: medium-bgc-color($name, $index); } @else if $type == 'd' { $color: dark-bgc-color($name, $index); } $key: 'bgc:' + $name + ':' + $lightness; $cached-colors: map-merge(($key: $color), $cached-colors) !global; @return $color; } @function light-bgc-color($name, $index) { $color: map-get($background-colors, $name); $_lightness: map-get($_lights, $index); $color2: tint($color, $_lightness); // make them similar in lightness @if $name != 'light' and $name != 'white' and $name != 'black' and $name != 'dark' { $_l: map-get($_lightnesses, $index); $i: 0; @if lightness($color2) > $_l { @while lightness($color2) - $_l > 0.1 { $color2: tint($color, $_lightness - $i); $i: $i + 0.1; } } @else if lightness($color2) < $_l { @while $_l - lightness($color2) > 0.1 { $color2: tint($color, $_lightness + $i); $i: $i + 0.1; } } } @return $color2; } @function medium-bgc-color($name, $index) { $color: map-get($background-colors, $name); $_mediumness: map-get($_mediums, $index); $c: tint($color, $_mediumness); @return $c; } @function dark-bgc-color($name, $index) { $color: map-get($background-colors, $name); @return shade($color, 5 * $index); } ///////////