sass-planifolia

Vanilla Sass helper functions
git clone https://git.ce9e.org/sass-planifolia.git

commit
84a0fa2c237d41b149ce4a4dc2c838bc972afca8
parent
abb40dc53561235ffe3868f5eb1c7865c75db19a
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2017-01-31 18:39
use simple pow approximation in contrast

this way it no longer depends on math

This is the same approximation I also used in bourbon:
https://github.com/thoughtbot/bourbon/pull/935

Diffstat

M sass/contrast.scss 7 +++----
M test/contrast.js 8 ++++++--

2 files changed, 9 insertions, 6 deletions


diff --git a/sass/contrast.scss b/sass/contrast.scss

@@ -2,9 +2,6 @@
    2     2 /// Functions to help with contrast as defined by
    3     3 /// [WCAG20](https://www.w3.org/TR/WCAG20/#contrast-ratiodef)
    4     4 ///
    5    -1 /// This module requires a function called `pow()`. You should make sure that
    6    -1 /// one is available, e.g. by including the math module from this project.
    7    -1 ///
    8     5 /// @group contrast
    9     6 ////
   10     7 
@@ -18,7 +15,9 @@ $planifolia-contrast-light-default: white !default;
   18    15   @if $x <= .03928 {
   19    16     @return $x / 12.92;
   20    17   } @else {
   21    -1     @return pow(($x + .055) / 1.055, 2.4);
   -1    18     $c: ($x + .055) / 1.055;
   -1    19     // approximation for pow($x, 2.4)
   -1    20     @return (133 * $c * $c * $c + 155 * $c * $c) / 288;
   22    21   }
   23    22 }
   24    23 

diff --git a/test/contrast.js b/test/contrast.js

@@ -1,5 +1,6 @@
    1     1 var path = require('path');
    2     2 var Sassaby = require('sassaby');
   -1     3 var shared = require('./shared');
    3     4 
    4     5 describe('contrast', function() {
    5     6   var file = path.resolve(__dirname, '../sass/contrast.scss');
@@ -63,6 +64,9 @@ describe('contrast', function() {
   63    64     it('cyan', function() {
   64    65       sassaby.func('luma').calledWithArgs('cyan').equals('.7874');
   65    66     });
   -1    67     it('random', function() {
   -1    68       shared.similar(sassaby.func('luma').calledWithArgs('rgb(12, 180, 92)'), 0.3349, 0.02);
   -1    69     });
   66    70     it('white with alpha', function() {
   67    71       sassaby.func('luma').calledWithArgs('rgba(255,255,255,0.5)').equals('1');
   68    72     });
@@ -84,8 +88,8 @@ describe('contrast', function() {
   84    88     it('red-red', function() {
   85    89       sassaby.func('contrast').calledWithArgs('red', 'red').equals('1');
   86    90     });
   87    -1     it('red-red', function() {
   88    -1       sassaby.func('contrast').calledWithArgs('red', '#676eff').equals('1.00017');
   -1    91     it('red-lightblue', function() {
   -1    92       shared.similar(sassaby.func('contrast').calledWithArgs('red', '#676eff'), 1, 0.02);
   89    93     });
   90    94   });
   91    95