/* fromObject attempts to convert an object o to and RGB
instance. This accepts an object with red, green and blue
members or a string. If the string is a known CSS color name
or a hexdecimal string it will accept it.
162177
function(o) {
            if (o instanceof Array) {
                return this._fromRGBArray(o);
            }
            if ("string" == typeof o) {
                return this._fromCSS(trim(o));
            }
            if (o.hasOwnProperty('red') &&
                o.hasOwnProperty('green') &&
                o.hasOwnProperty('blue')) {
                return this._fromRGB(o);
            }
            // nothing matchs, not an RGB object
        }
760572
function getColorObj(value, mode) {
		if (value[0] === "#") { return parseHex(value, mode); }
		else { return parseRgbOrHsl(value, mode); }
	}
405199
def color_to_rgb(color):
        
        if isinstance(color, tuple):
            return color
        if color.startswith('#'):
            try:
                return webcolors.hex_to_rgb(color)
            except ValueError:
                raise InvalidColor(color)

        try:
            return webcolors.name_to_rgb(color)
        except ValueError:
            raise InvalidColor(color)
158413
function fromObject (obj) {
	//else retrieve format properties from object
	var format = {}

	formatProperties.forEach(function (key) {
		if (obj[key] != null) format[key] = obj[key]
	})

	//some AudioNode/etc-specific options
	if (!format.channels && (obj.channelCount || obj.numberOfChannels)) {
		format.channels = obj.channelCount || obj.numberOfChannels
	}
	if (!format.sampleRate && obj.rate) {
		format.sampleRate = obj.rate
	}

	return format
}
1017371
function ( color ) {
            var type = this.type( color, 'color.toHex() : "' + color + '" ' + MSG_NOT_COLOR );
    
            switch ( type ) {
                case 'hex':
                    return color;
                    break;
                case 'rgb':
                case 'rgba':
                    return this.rgbToHex( color );
                    break;
                case 'hsl':
                case 'hsla':
                    color = this.hslToRgb( color );
                    return this.rgbToHex( color );
                    break;
                case 'keyword':
                    return this.keyword( color, 'color.toHex() : "' + color + '" ' + MSG_NOT_COLOR );
                    break;
            }
        }
716432
function parseColor (str) {
    if (str.substr(0,1) === '#') {
      // Handle color shorthands (like #abc)
      var shorthand = str.length === 4,
          m = str.match(shorthand ? /\w/g : /\w{2}/g);

      if (!m) return;
      m = m.map(function(s) { return parseInt(shorthand ? s+s : s, 16) });
      return new nodes.RGBA(m[0],m[1],m[2],1);
    }
    else if (str.substr(0,3) === 'rgb'){
      var m = str.match(/([0-9]*\.?[0-9]+)/g);
      if (!m) return;
      m = m.map(function(s){return parseFloat(s, 10)});
      return new nodes.RGBA(m[0], m[1], m[2], m[3] || 1);
    }
    else {
      var rgb = colors[str];
      if (!rgb) return;
      return new nodes.RGBA(rgb[0], rgb[1], rgb[2], 1);
    }
  }
219730
function(
    val, predefinedColors, fallbackColor, fallbackFormat, hexNumberSignPrefix) {
    this.fallbackValue = fallbackColor ?
      (
        (typeof fallbackColor === 'string') ?
        this.parse(fallbackColor) :
        fallbackColor
      ) :
      null;

    this.fallbackFormat = fallbackFormat ? fallbackFormat : 'rgba';

    this.hexNumberSignPrefix = hexNumberSignPrefix === true;

    this.value = this.fallbackValue;

    this.origFormat = null; // original string format

    this.predefinedColors = predefinedColors ? predefinedColors : {};

    // We don't want to share aliases across instances so we extend new object
    this.colors = $.extend({}, Color.webColors, this.predefinedColors);

    if (val) {
      if (typeof val.h !== 'undefined') {
        this.value = val;
      } else {
        this.setColor(String(val));
      }
    }

    if (!this.value) {
      // Initial value is always black if no arguments are passed or val is empty
      this.value = {
        h: 0,
        s: 0,
        b: 0,
        a: 1
      };
    }
  }
107393
public static boolean isObjectAnObject(java.lang.Object o) {
    return o instanceof JavaScriptObject && isValueObject(wrap0(o));
  }
1220843
function selectColor(namespace) {
    var hash = 0,
      i;

    for (i in namespace) {
      hash = (hash << 5) - hash + namespace.charCodeAt(i);
      hash |= 0; // Convert to 32bit integer
    }

    return exports.colors[Math.abs(hash) % exports.colors.length];
  }
601622
function validateFormatColor(obj) {
	return COLORS.indexOf(obj) !== -1 || obj.match(colorsReHex3) || obj.match(colorsReHex6)
		|| obj.match(colorsReRgbNum) || obj.match(colorsReRgbPerc);
}
711504
function fromNamed(color) {
  const el = document.createElement('div');
  el.style.color = color;
  if (el.style.color !== '') {
    document.body.appendChild(el);
    const rgb = getComputedStyle(el).color;
    document.body.removeChild(el);
    return rgb;
  } else {
    return '';
  }
}
1116031
function convertColorToRGBA(color) {
  const cstr = `${color}`.toLowerCase().trim() || '';

  if (!/^rgba?\(.+?\)$/.test(cstr)) {
    // Convert both color names and hex colors to rgba
    const hexColor = convertColorNameToHex(color);
    return convertHexColorToRgba(hexColor);
  }

  // Convert rgb to rgba
  const channels = cstr.match(/([\-0-9.]+)/g) || [];

  switch (channels.length) {
    case 3:
      // Convert rgb to rgba
      return `rgba(${channels.join(', ')}, 1)`;

    case 4:
      // Format rgba
      return `rgba(${channels.join(', ')})`;

    default:
      // Unexpected color format. Leave it untouched (let the user handle it)
      return color;
  }
}
653586
public static GenericColor valueOf(String color) {

    Objects.requireNonNull(color, "color");
    Color namedColor = Color.fromName(color);
    if (namedColor != null) {
      return valueOf(namedColor);
    }
    int length = color.length();
    Throwable cause = null;
    try {
      // "#RRGGBB" / #AARRGGBB
      Color hexColor = Color.parseHexString(color);
      if (hexColor != null) {
        return valueOf(hexColor);
      }
      // "rgb(1,1,1)" = 10
      if (length >= 7) {
        String model = BasicHelper.toUpperCase(color.substring(0, 3));
        ColorModel colorModel = ColorModel.valueOf(model);
        int index = 3;
        boolean hasAlpha = false;
        char c = Character.toLowerCase(color.charAt(index));
        if (c == 'a') {
          hasAlpha = true;
          index++;
          c = color.charAt(index);
        }
        if (c == '(') {
          index++;
          int endIndex = color.indexOf(',', index);
          if (endIndex > 0) {
            String firstSegment = color.substring(index, endIndex).trim();
            index = endIndex + 1;
            endIndex = color.indexOf(',', index);
            if (endIndex > 0) {
              String secondSegment = color.substring(index, endIndex).trim();
              index = endIndex + 1;
              if (hasAlpha) {
                endIndex = color.indexOf(',', index);
              } else {
                endIndex = length - 1;
              }
              if (endIndex > 0) {
                String thirdSegment = color.substring(index, endIndex).trim();
                Alpha alpha;
                if (hasAlpha) {
                  alpha = new Alpha(color.substring(endIndex + 1, length - 1));
                } else {
                  alpha = Alpha.OPAQUE;
                }
                switch (colorModel) {
                  case RGB:
                    return valueOf(new Red(firstSegment), new Green(secondSegment), new Blue(thirdSegment), alpha);
                  case HSL:
                    return valueOf(new Hue(firstSegment), new Saturation(secondSegment), new Lightness(thirdSegment), alpha);
                  case HSV:
                  case HSB:
                    return valueOf(new Hue(firstSegment), new Saturation(secondSegment), new Brightness(thirdSegment), alpha);
                  default :
                    throw new IllegalStateException("" + colorModel);
                }
              }
            }
          }
        }
      }
    } catch (RuntimeException e) {
      cause = e;
    }
    throw new IllegalArgumentException(color, cause);
  }
910309
function parseColor(color) {

	// Let the browser round the RGBA values for consistency
	parseColorStyle.cssText = 'color:' + color;
	color = parseColorStyle.color;

	if (!color || !color.split || !color.split('(')[1]) {
		return [0, 0, 0, 0];
	}

	color = color.split('(')[1].split(',').map(parseFloat);

	if (color[3] === undefined) {
		color[3] = 1;
	}
	else if (!color[3]) {
		color[0] = color[1] = color[2] = 0;
	}

	color[3] = Math.round(color[3] * 255);

	return rgbaToHsla(color);

}
263885
def _jsTypeof(o):
    ''''''
    if o == None:
        return 'object'
    elif o == Undefined:
        return 'undefined'
    elif isinstance(o, bool):
        return 'boolean'
    if isinstance(o, int) or isinstance(o, float):
        return 'number'
    elif isinstance(o, list) or isinstance(o, dict):
        return 'object'
    elif isinstance(o, stringtype):
        return 'string'
    raise ValueError('Unknown type for object %s (%s)' % (o, type(o)))
191076
function parseColor(color, contrast) {
      contrast = contrast || false;
      var rgbValues = $mdTheming.PALETTES[color.palette][color.hue];

      rgbValues = contrast ? rgbValues.contrast : rgbValues.value;

      return $mdUtil.supplant('rgba({0}, {1}, {2}, {3})',
        [rgbValues[0], rgbValues[1], rgbValues[2], rgbValues[3] || color.opacity]
      );
    }
882462
function (colour) {
  if (!colour || !!((colour = String(colour)).indexOf("-") + 1)) {
    return {r: -1, g: -1, b: -1, opacity: -1, error: 1};
  }
  if (colour == "none") {
    return {r: -1, g: -1, b: -1, opacity: -1};
  }
  !(hsrg[has](colour.toLowerCase().substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour));
  if (!colour) {
    return {r: -1, g: -1, b: -1, opacity: -1, error: 1};
  }
  var res,
      red,
      green,
      blue,
      opacity,
      t,
      values,
      rgb = colour.match(colourRegExp);
  if (rgb) {
    if (rgb[2]) {
      blue = parseInt(rgb[2].substring(5), 16);
      green = parseInt(rgb[2].substring(3, 5), 16);
      red = parseInt(rgb[2].substring(1, 3), 16);
    }
    if (rgb[3]) {
      blue = parseInt((t = rgb[3].charAt(3)) + t, 16);
      green = parseInt((t = rgb[3].charAt(2)) + t, 16);
      red = parseInt((t = rgb[3].charAt(1)) + t, 16);
    }
    if (rgb[4]) {
      values = rgb[4].split(commaSpaces);
      red = parseFloat(values[0]);
      values[0].slice(-1) == "%" && (red *= 2.55);
      green = parseFloat(values[1]);
      values[1].slice(-1) == "%" && (green *= 2.55);
      blue = parseFloat(values[2]);
      values[2].slice(-1) == "%" && (blue *= 2.55);
      rgb[1].toLowerCase().slice(0, 4) == "rgba" && (opacity = parseFloat(values[3]));
      values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
    }
    if (rgb[5]) {
      values = rgb[5].split(commaSpaces);
      red = parseFloat(values[0]);
      values[0].slice(-1) == "%" && (red /= 100);
      green = parseFloat(values[1]);
      values[1].slice(-1) == "%" && (green /= 100);
      blue = parseFloat(values[2]);
      values[2].slice(-1) == "%" && (blue /= 100);
      (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
      rgb[1].toLowerCase().slice(0, 4) == "hsba" && (opacity = parseFloat(values[3]));
      values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
      return hsb2rgb(red, green, blue, opacity);
    }
    if (rgb[6]) {
      values = rgb[6].split(commaSpaces);
      red = parseFloat(values[0]);
      values[0].slice(-1) == "%" && (red /= 100);
      green = parseFloat(values[1]);
      values[1].slice(-1) == "%" && (green /= 100);
      blue = parseFloat(values[2]);
      values[2].slice(-1) == "%" && (blue /= 100);
      (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360);
      rgb[1].toLowerCase().slice(0, 4) == "hsla" && (opacity = parseFloat(values[3]));
      values[3] && values[3].slice(-1) == "%" && (opacity /= 100);
      return hsl2rgb(red, green, blue, opacity);
    }
    red = Math.min(Math.round(red), 255);
    green = Math.min(Math.round(green), 255);
    blue = Math.min(Math.round(blue), 255);
    opacity = Math.min(Math.max(opacity, 0), 1);
    rgb = {r: red, g: green, b: blue};
    rgb.opacity = isFinite(opacity) ? opacity : 1;
    return rgb;
  }
  return {r: -1, g: -1, b: -1, opacity: -1, error: 1};
}