1 |
|
2 |
|
3 |
|
4 |
|
5 | @import 'math';
|
6 |
|
7 | $contrast-warnings: true !default;
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | @function color-luminance($color) {
|
19 |
|
20 |
|
21 | $rgba: red($color), green($color), blue($color);
|
22 | $rgba2: ();
|
23 |
|
24 | @for $i from 1 through 3 {
|
25 | $rgb: nth($rgba, $i);
|
26 | $rgb: $rgb / 255;
|
27 |
|
28 | $rgb: if($rgb < 0.03928, $rgb / 12.92, pow(($rgb + 0.055) / 1.055, 2.4));
|
29 |
|
30 | $rgba2: append($rgba2, $rgb);
|
31 | }
|
32 |
|
33 | @return 0.2126 * nth($rgba2, 1) + 0.7152 * nth($rgba2, 2) + 0.0722 * nth($rgba2, 3);
|
34 | }
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | @function color-contrast($color1, $color2) {
|
43 |
|
44 |
|
45 | $luminance1: color-luminance($color1) + 0.05;
|
46 | $luminance2: color-luminance($color2) + 0.05;
|
47 | $ratio: $luminance1 / $luminance2;
|
48 |
|
49 | @if $luminance2 > $luminance1 {
|
50 | $ratio: 1 / $ratio;
|
51 | }
|
52 |
|
53 | $ratio: round($ratio * 10) / 10;
|
54 |
|
55 | @return $ratio;
|
56 | }
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | @function color-pick-contrast($base, $colors: ($white, $black), $tolerance: $global-color-pick-contrast-tolerance) {
|
66 | $contrast: color-contrast($base, nth($colors, 1));
|
67 | $best: nth($colors, 1);
|
68 |
|
69 | @for $i from 2 through length($colors) {
|
70 | $current-contrast: color-contrast($base, nth($colors, $i));
|
71 | @if ($current-contrast - $contrast > $tolerance) {
|
72 | $contrast: color-contrast($base, nth($colors, $i));
|
73 | $best: nth($colors, $i);
|
74 | }
|
75 | }
|
76 |
|
77 | @if ($contrast-warnings and $contrast < 3) {
|
78 | @warn "Contrast ratio of #{$best} on #{$base} is pretty bad, just #{$contrast}";
|
79 | }
|
80 |
|
81 | @return $best;
|
82 | }
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 | @function smart-scale($color, $scale: 5%, $threshold: 40%) {
|
92 | @if lightness($color) > $threshold {
|
93 | $scale: -$scale;
|
94 | }
|
95 | @return scale-color($color, $lightness: $scale);
|
96 | }
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 | @function get-color($key) {
|
104 | @if map-has-key($foundation-palette, $key) {
|
105 | @return map-get($foundation-palette, $key);
|
106 | }
|
107 | @else {
|
108 | @error 'given $key is not available in $foundation-palette';
|
109 | }
|
110 | }
|
111 |
|
112 |
|
113 | @mixin add-foundation-colors() {
|
114 | @if map-has-key($foundation-palette, primary) {
|
115 | $primary-color: map-get($foundation-palette, primary) !global;
|
116 | }
|
117 | @if map-has-key($foundation-palette, secondary) {
|
118 | $secondary-color: map-get($foundation-palette, secondary) !global;
|
119 | }
|
120 | @if map-has-key($foundation-palette, success) {
|
121 | $success-color: map-get($foundation-palette, success) !global;
|
122 | }
|
123 | @if map-has-key($foundation-palette, warning) {
|
124 | $warning-color: map-get($foundation-palette, warning) !global;
|
125 | }
|
126 | @if map-has-key($foundation-palette, alert) {
|
127 | $alert-color: map-get($foundation-palette, alert) !global;
|
128 | }
|
129 | }
|