contrast method

Color contrast(
  1. Node colorNode,
  2. [Color dark,
  3. Color light,
  4. Dimension threshold]
)

Choose which of two colors provides the greatest contrast with another.

Parameters: color: A color object to compare against. dark: optional - A designated dark color (defaults to black). light: optional - A designated light color (defaults to white). threshold: optional - A percentage 0-100% specifying where the transition from "dark" to "light" is (defaults to 43%, matching SASS). Returns: color

Implementation

Color contrast(Node colorNode,
    [Color dark, Color light, Dimension threshold]) {
  // filter: contrast(3.2);
  // should be kept as is, so check for color
  if (colorNode is! Color) return null;
  final Color color = colorNode;

  var _light = light ?? rgba(255, 255, 255, 1.0);
  var _dark = dark ?? rgba(0, 0, 0, 1.0);

  //Figure out which is actually light and dark!
  if (_dark.luma() > _light.luma()) {
    final t = _light;
    _light = _dark;
    _dark = t;
  }

  final double _threshold = (threshold == null) ? 0.43 : number(threshold);
  return (color.luma() < _threshold) ? _light : _dark;

//    contrast: function (color, dark, light, threshold) {
//        // filter: contrast(3.2);
//        // should be kept as is, so check for color
//        if (!color.rgb) {
//            return null;
//        }
//        if (typeof light === 'undefined') {
//            light = colorFunctions.rgba(255, 255, 255, 1.0);
//        }
//        if (typeof dark === 'undefined') {
//            dark = colorFunctions.rgba(0, 0, 0, 1.0);
//        }
//        //Figure out which is actually light and dark!
//        if (dark.luma() > light.luma()) {
//            var t = light;
//            light = dark;
//            dark = t;
//        }
//        if (typeof threshold === 'undefined') {
//            threshold = 0.43;
//        } else {
//            threshold = number(threshold);
//        }
//        if (color.luma() < threshold) {
//            return light;
//        } else {
//            return dark;
//        }
//    }
}