-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_functions.scss
More file actions
60 lines (49 loc) · 1.52 KB
/
_functions.scss
File metadata and controls
60 lines (49 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
@function minus1px($value) {
$unit: unit($value);
@if ($unit == px) {
@return $value - 1;
} @elseif ($unit == em or $unit == rem) {
@return $value - (1 / 16);
}
@else {
@error 'Unit `#{$unit}` not supported.';
}
}
/*
Colour contrast from https://gist.github.com/FStop/8959422
Usage:
@if color_contrast($colour, #fff) < 2 {
color: #333;
}
@else{
color: #fff;
}
*/
/* Awesome contrast ratio function
* via https://gist.github.com/voxpelli/6304812
**/
@function color_luminance($color) {
// Adapted from: https://github.com/LeaVerou/contrast-ratio/blob/gh-pages/color.js
// Formula: http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
$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) + 0.0722 * nth($rgba2, 3);
}
@function color_contrast($color1, $color2) {
// Adapted from: https://github.com/LeaVerou/contrast-ratio/blob/gh-pages/color.js
// Formula: http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef
$luminance1: color_luminance($color1) + .05;
$luminance2: color_luminance($color2) + .05;
$ratio: $luminance1 / $luminance2;
@if $luminance2 > $luminance1 {
$ratio: 1 / $ratio;
}
$ratio: round($ratio * 10) / 10;
@return $ratio;
}