sass-planifolia

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

commit
709eee2ce44b6a78285340d7850839754b7e1e9f
parent
d69f147ea22c575d401fbc9cb1d35f8ac844e862
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2019-04-11 06:11
add leading zeros

Diffstat

M sass/color.scss 36 ++++++++++++++++++------------------
M sass/contrast.scss 12 ++++++------
M sass/math.scss 2 +-

3 files changed, 25 insertions, 25 deletions


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

@@ -38,20 +38,20 @@ $planifolia-colorspace: 'lab' !default;
   38    38 
   39    39 @function _pf-srgb-to-rgb($c) {
   40    40   $c: $c / 255;
   41    -1   @if $c <= .04045 {
   -1    41   @if $c <= 0.04045 {
   42    42     $c: $c / 12.92;
   43    43   } @else {
   44    -1     $c: pow(($c + .055) / 1.055, 2.4);
   -1    44     $c: pow(($c + 0.055) / 1.055, 2.4);
   45    45   }
   46    46   @return $c * 100;
   47    47 }
   48    48 
   49    49 @function _pf-rgb-to-srgb($c) {
   50    50   $c: $c / 100;
   51    -1   @if $c <= .0031308 {
   -1    51   @if $c <= 0.0031308 {
   52    52     $c: $c * 12.92;
   53    53   } @else {
   54    -1     $c: 1.055 * pow($c, 1 / 2.4) - .055;
   -1    54     $c: 1.055 * pow($c, 1 / 2.4) - 0.055;
   55    55   }
   56    56   @return $c * 255;
   57    57 }
@@ -61,17 +61,17 @@ $planifolia-colorspace: 'lab' !default;
   61    61   $g: _pf-srgb-to-rgb(green($color));
   62    62   $b: _pf-srgb-to-rgb(blue($color));
   63    63 
   64    -1   $x: .4124 * $r + .3576 * $g + .1805 * $b;
   65    -1   $y: .2126 * $r + .7152 * $g + .0722 * $b;
   66    -1   $z: .0193 * $r + .1192 * $g + .9505 * $b;
   -1    64   $x: 0.4124 * $r + 0.3576 * $g + 0.1805 * $b;
   -1    65   $y: 0.2126 * $r + 0.7152 * $g + 0.0722 * $b;
   -1    66   $z: 0.0193 * $r + 0.1192 * $g + 0.9505 * $b;
   67    67 
   68    68   @return ($x, $y, $z);
   69    69 }
   70    70 
   71    71 @function _pf-from-xyz($xyz) {
   72    -1   $r: 3.2406 * nth($xyz, 1) - 1.5372 * nth($xyz, 2) - .4986 * nth($xyz, 3);
   73    -1   $g: -.9689 * nth($xyz, 1) + 1.8758 * nth($xyz, 2) + .0415 * nth($xyz, 3);
   74    -1   $b: .0557 * nth($xyz, 1) - .204 * nth($xyz, 2) + 1.057 * nth($xyz, 3);
   -1    72   $r: 3.2406 * nth($xyz, 1) - 1.5372 * nth($xyz, 2) - 0.4986 * nth($xyz, 3);
   -1    73   $g: -0.9689 * nth($xyz, 1) + 1.8758 * nth($xyz, 2) + 0.0415 * nth($xyz, 3);
   -1    74   $b: 0.0557 * nth($xyz, 1) - 0.204 * nth($xyz, 2) + 1.057 * nth($xyz, 3);
   75    75 
   76    76   $r: _pf-rgb-to-srgb($r);
   77    77   $g: _pf-rgb-to-srgb($g);
@@ -85,9 +85,9 @@ $planifolia-colorspace: 'lab' !default;
   85    85   $g: _pf-srgb-to-rgb(green($color));
   86    86   $b: _pf-srgb-to-rgb(blue($color));
   87    87 
   88    -1   $y: .2126 * $r + .7152 * $g + .0722 * $b;
   89    -1   $u: -.09991 * $r + -.33609 * $g + .436 * $b;
   90    -1   $v: .615 * $r + -.55861 * $g + -.05639 * $b;
   -1    88   $y: 0.2126 * $r + 0.7152 * $g + 0.0722 * $b;
   -1    89   $u: -0.09991 * $r + -0.33609 * $g + 0.436 * $b;
   -1    90   $v: 0.615 * $r + -0.55861 * $g + -0.05639 * $b;
   91    91 
   92    92   @return ($y, $v, -$u);
   93    93 }
@@ -98,7 +98,7 @@ $planifolia-colorspace: 'lab' !default;
   98    98   $u: -1 * nth($yuv, 3);
   99    99 
  100   100   $r: _pf-rgb-to-srgb($y + 1.28033 * $v);
  101    -1   $g: _pf-rgb-to-srgb($y + -.21482 * $u + -.38059 * $v);
   -1   101   $g: _pf-rgb-to-srgb($y + -0.21482 * $u + -0.38059 * $v);
  102   102   $b: _pf-rgb-to-srgb($y + 2.12798 * $u);
  103   103 
  104   104   @return ($r, $g, $b);
@@ -197,7 +197,7 @@ $planifolia-colorspace: 'lab' !default;
  197   197   $l: nth($lab, 1);
  198   198   $c: sqrt(nth($lab, 2) * nth($lab, 2) + nth($lab, 3) * nth($lab, 3));
  199   199   $h: 0;
  200    -1   @if abs(nth($lab, 2)) > .0001 or abs(nth($lab, 3)) > .0001 {
   -1   200   @if abs(nth($lab, 2)) > 0.0001 or abs(nth($lab, 3)) > 0.0001 {
  201   201     $h: atan2(nth($lab, 3), nth($lab, 2)) * 1rad;
  202   202   }
  203   203 
@@ -309,7 +309,7 @@ $planifolia-colorspace: 'lab' !default;
  309   309     $c-max: $chroma;
  310   310     $c-tmp: ($c-min + $c-max) / 2;
  311   311 
  312    -1     @while $c-max - $c-min > .01 {
   -1   312     @while $c-max - $c-min > 0.01 {
  313   313       $rgb: _lch-unclipped($lightness, $c-tmp, $hue, $colorspace);
  314   314       @if _pf-clip-needed($rgb) {
  315   315         $c-max: $c-tmp;
@@ -490,8 +490,8 @@ $planifolia-colorspace: 'lab' !default;
  490   490   $w2: (1 - $w) * nth($lch2, 2);
  491   491 
  492   492   @if ($w1 == 0 and $w2 == 0) {
  493    -1     $w1: .5;
  494    -1     $w2: .5;
   -1   493     $w1: 0.5;
   -1   494     $w2: 0.5;
  495   495   }
  496   496 
  497   497   $h1: nth($lch1, 3);

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

@@ -24,10 +24,10 @@ $planifolia-contrast-light-default: white !default;
   24    24 
   25    25 @function _pf-srgb($channel) {
   26    26   $x: $channel / 255;
   27    -1   @if $x <= .03928 {
   -1    27   @if $x <= 0.03928 {
   28    28     @return $x / 12.92;
   29    29   } @else {
   30    -1     $c: ($x + .055) / 1.055;
   -1    30     $c: ($x + 0.055) / 1.055;
   31    31     @if function-exists('pow') {
   32    32       @return pow($c, 2.4);
   33    33     } @else {
@@ -36,7 +36,7 @@ $planifolia-contrast-light-default: white !default;
   36    36       // NOTE that `contrast()` amplifies the errors generated here.
   37    37       // The factors a chosen to minify that effect.
   38    38       $cc: $c * $c;
   39    -1       @return .4 * $cc + .8 * ($cc * $c) - .2 * ($cc * $cc);
   -1    39       @return 0.4 * $cc + 0.8 * ($cc * $c) - 0.2 * ($cc * $cc);
   40    40     }
   41    41   }
   42    42 }
@@ -65,13 +65,13 @@ $planifolia-contrast-light-default: white !default;
   65    65   $r: _pf-srgb(red($color));
   66    66   $g: _pf-srgb(green($color));
   67    67   $b: _pf-srgb(blue($color));
   68    -1   @return .2126 * $r + .7152 * $g + .0722 * $b;
   -1    68   @return 0.2126 * $r + 0.7152 * $g + 0.0722 * $b;
   69    69 }
   70    70 
   71    71 @function _pf-contrast($fg, $bg) {
   72    72   $lbg: luma($bg);
   73    73   $lfg: luma(alpha-blend($fg, $bg));
   74    -1   @return (max($lbg, $lfg) + .05) / (min($lbg, $lfg) + .05);
   -1    74   @return (max($lbg, $lfg) + 0.05) / (min($lbg, $lfg) + 0.05);
   75    75 }
   76    76 
   77    77 /// Calculate the minimum possible contrast between two colors.
@@ -151,7 +151,7 @@ $planifolia-contrast-light-default: white !default;
  151   151 @function contrast-stretch($base, $color, $threshold: 4.5) {
  152   152   $threshold: _pf-threshold($threshold);
  153   153   $lower: $color;
  154    -1   $upper: if(luma($base) < .18, white, black);
   -1   154   $upper: if(luma($base) < 0.18, white, black);
  155   155 
  156   156   @if contrast($base, $lower) >= $threshold {
  157   157     @return $lower;

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

@@ -205,7 +205,7 @@ $planifolia-math-steps-default: 32 !default;
  205   205 @function asin($x, $steps: $planifolia-math-steps-default) {
  206   206   @if $x < 0 {
  207   207     @return -1 * asin(-$x, $steps);
  208    -1   } @else if $x * $x > .5 {
   -1   208   } @else if $x * $x > 0.5 {
  209   209     @return acos(sqrt(1 - $x * $x, $steps), $steps);
  210   210   } @else {
  211   211     @return _pf-asin-taylor-0($x, $steps);