- commit
- 3173a3274cdadec97d16490acc1d3ce2de020e1c
- parent
- fb68b376ec093a3920205ef847435eeef73e92fc
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2018-03-29 07:44
contrast: refactor
Diffstat
| M | sass/contrast.scss | 24 | ++++++++++++------------ |
1 files changed, 12 insertions, 12 deletions
diff --git a/sass/contrast.scss b/sass/contrast.scss
@@ -113,7 +113,7 @@ $planifolia-contrast-light-default: white !default; 113 113 /// @return {number} between 1 and 21 114 114 /// @see contrast-min 115 115 @function contrast($color1, $color2) {116 -1 // optimize for the common case-1 116 // NOTE: optimized for the common case 117 117 @if alpha($color1) + alpha($color2) == 2 { 118 118 @return _pf-contrast($color1, $color2); 119 119 } @else { @@ -145,18 +145,18 @@ $planifolia-contrast-light-default: white !default; 145 145 /// 146 146 /// @param {color} $base 147 147 /// @param {color} $color148 -1 /// @param {number} $contrast [4.5]-1 148 /// @param {number} $threshold [4.5] 149 149 /// (can also be 'AA', 'AALG', 'AAA', or 'AAALG') 150 150 /// @return {color}151 -1 @function contrast-stretch($base, $color, $contrast: 4.5) {152 -1 $contrast: _pf-threshold($contrast);-1 151 @function contrast-stretch($base, $color, $threshold: 4.5) { -1 152 $threshold: _pf-threshold($threshold); 153 153 $lower: $color; 154 154 $upper: if(luma($base) < .18, white, black); 155 155156 -1 @if contrast($base, $lower) >= $contrast {-1 156 @if contrast($base, $lower) >= $threshold { 157 157 @return $lower; 158 158 }159 -1 @if contrast($base, $upper) <= $contrast {-1 159 @if contrast($base, $upper) <= $threshold { 160 160 @return $upper; 161 161 } 162 162 @@ -166,7 +166,7 @@ $planifolia-contrast-light-default: white !default; 166 166 @for $i from 0 to 10 { 167 167 $tmp: mix($lower, $upper); 168 168169 -1 @if contrast($base, $tmp) < $contrast {-1 169 @if contrast($base, $tmp) < $threshold { 170 170 $lower: $tmp; 171 171 } @else { 172 172 $upper: $tmp; @@ -178,15 +178,15 @@ $planifolia-contrast-light-default: white !default; 178 178 179 179 /// Warn if the contrast is below a threshold. 180 180 ///181 -1 /// @param {color} $color1 background color182 -1 /// @param {color} $color2 foreground color-1 181 /// @param {color} $base -1 182 /// @param {color} $color 183 183 /// @param {number} $threshold [4.5] 184 184 /// (can also be 'AA', 'AALG', 'AAA', or 'AAALG')185 -1 @function contrast-check($color1, $color2, $threshold: 4.5) {-1 185 @function contrast-check($base, $color, $threshold: 4.5) { 186 186 $threshold: _pf-threshold($threshold);187 -1 $contrast: contrast($color1, $color2);-1 187 $contrast: contrast($base, $color); 188 188 @if $contrast < $threshold {189 -1 @warn 'contrast #{$contrast} between #{$color1} and #{$color2} too low!';-1 189 @warn 'contrast #{$contrast} between #{$base} and #{$color} too low!'; 190 190 } 191 191 @return null; 192 192 }