saturate method

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

Increase 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: saturate(hsl(90, 80%, 50%), 20%) Output: #80ff00 // hsl(90, 100%, 50%)

Implementation

Color saturate(Node color, [Dimension amount, Keyword method]) {
  // filter: saturate(3.2);
  // should be kept as is, so check for color
  if (color is! Color) return null; // ??

  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
//  saturate: function (color, amount, method) {
//    // filter: saturate(3.2);
//    // should be kept as is, so check for color
//    if (!color.rgb) {
//      return null;
//    }
//    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);
//  },
}