sass-planifolia

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

commit
0f92ed17286c42968bc3195915d9c06fd8acf03c
parent
8ec29ee84b8ab45076afc0d9e27b2b25c34737af
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2017-10-17 07:23
add support for HSLab and HSLuv

Diffstat

M sass/color.scss 32 ++++++++++++++++++++++++++++++++

1 files changed, 32 insertions, 0 deletions


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

@@ -206,6 +206,24 @@ $planifolia-colorspace: 'lab' !default;
  206   206   @return ($l, $a, $b);
  207   207 }
  208   208 
   -1   209 @function _pf-max-chroma($lightness, $hue, $colorspace) {
   -1   210   $c-min: 0;
   -1   211   $c-max: 200;
   -1   212   $c-tmp: ($c-min + $c-max) / 2;
   -1   213 
   -1   214   @while $c-max - $c-min > 1 {
   -1   215     $rgb: _lch-unclipped($lightness, $c-tmp, $hue, $colorspace);
   -1   216     @if _pf-clip-needed($rgb) {
   -1   217       $c-max: $c-tmp;
   -1   218     } @else {
   -1   219       $c-min: $c-tmp;
   -1   220     }
   -1   221     $c-tmp: ($c-min + $c-max) / 2;
   -1   222   }
   -1   223 
   -1   224   @return $c-tmp;
   -1   225 }
   -1   226 
  209   227 /// @require pow
  210   228 /// @require sqrt
  211   229 /// @require atan2
@@ -214,10 +232,18 @@ $planifolia-colorspace: 'lab' !default;
  214   232     $xyz: _pf-to-xyz($color);
  215   233     $lab: _pf-xyz-to-lab($xyz);
  216   234     @return _pf-lab-to-lch($lab);
   -1   235   } @else if $colorspace == 'hslab' {
   -1   236     $lch: _pf-to-lch($color, 'lab');
   -1   237     $max: _pf-max-chroma(nth($lch, 1), nth($lch, 3), 'lab');
   -1   238     @return (nth($lch, 1), nth($lch, 2) / $max * 100, nth($lch, 3));
  217   239   } @else if $colorspace == 'luv' {
  218   240     $xyz: _pf-to-xyz($color);
  219   241     $luv: _pf-xyz-to-luv($xyz);
  220   242     @return _pf-lab-to-lch($luv);
   -1   243   } @else if $colorspace == 'hsluv' {
   -1   244     $lch: _pf-to-lch($color, 'luv');
   -1   245     $max: _pf-max-chroma(nth($lch, 1), nth($lch, 3), 'luv');
   -1   246     @return (nth($lch, 1), nth($lch, 2) / $max * 100, nth($lch, 3));
  221   247   } @else if $colorspace == 'hsl' {
  222   248     $chroma: saturation($color) * lightness($color) / 100%;
  223   249     @return (lightness($color) / 1%, $chroma / 1%, hue($color));
@@ -234,10 +260,16 @@ $planifolia-colorspace: 'lab' !default;
  234   260     $lab: _pf-lch-to-lab(($lightness, $chroma, $hue));
  235   261     $xyz: _pf-lab-to-xyz($lab);
  236   262     @return _pf-from-xyz($xyz);
   -1   263   } @else if $colorspace == 'hslab' {
   -1   264     $max: _pf-max-chroma($lightness, $hue, 'lab');
   -1   265     @return _lch-unclipped($lightness, $chroma * $max / 100, $hue, 'lab');
  237   266   } @else if $colorspace == 'luv' {
  238   267     $luv: _pf-lch-to-lab(($lightness, $chroma, $hue));
  239   268     $xyz: _pf-luv-to-xyz($luv);
  240   269     @return _pf-from-xyz($xyz);
   -1   270   } @else if $colorspace == 'hsluv' {
   -1   271     $max: _pf-max-chroma($lightness, $hue, 'luv');
   -1   272     @return _lch-unclipped($lightness, $chroma * $max / 100, $hue, 'luv');
  241   273   } @else if $colorspace == 'hsl' {
  242   274     $saturation: if($lightness == 0, 0, $chroma / $lightness * 100);
  243   275     $color: hsl($hue, $saturation * 1%, $lightness * 1%);