desaturate method

Color desaturate(
  1. Node color,
  2. Dimension amount,
  3. [Keyword method]
)

Decrease the saturation of a color in the HSL color space by an absolute amount.

Parameters: color: A color object. amount: A percentage 0-100%. method: Optional, set to relative for the adjustment to be relative to the current value. Returns: color Example: desaturate(hsl(90, 80%, 50%), 20%) Output: #80cc33 // hsl(90, 60%, 50%)

Implementation

Color desaturate(Node color, Dimension amount, [Keyword method]) {
  final hsl = toHSL(color);

  hsl
    ..s -= (method?.value == 'relative')
        ? hsl.s * amount.value / 100
        : amount.value / 100
    ..s = clamp(hsl.s);

  return hslaColorSpace(color, hsl);

// 3.9.0 20190711
//  desaturate: function (color, amount, method) {
//    var hsl = toHSL(color);
//
//    if (typeof method !== 'undefined' && method.value === 'relative') {
//      hsl.s -=  hsl.s * amount.value / 100;
//    }
//    else {
//      hsl.s -= amount.value / 100;
//    }
//    hsl.s = clamp(hsl.s);
//    return hsla(color, hsl);
//  },
}