function parseRgba(color) {
  // Fast lane for rgb(a) colors
  if (color.toLowerCase().startsWith('rgb')) {
    const rgb =
      color.match(rgbLegacyAbsoluteRegEx) ||
      color.match(rgbModernRegEx) ||
      color.match(rgbLegacyPercentageRegEx);
    if (rgb) {
      const alpha = rgb[4];
      const rgbDivider = 100 / 255;
      return [
        clamp((toColorComponent(rgb[1], rgbDivider) + 0.5) | 0, 0, 255),
        clamp((toColorComponent(rgb[2], rgbDivider) + 0.5) | 0, 0, 255),
        clamp((toColorComponent(rgb[3], rgbDivider) + 0.5) | 0, 0, 255),
        alpha !== undefined ? clamp(toColorComponent(alpha, 100), 0, 1) : 1,
      ];
    }
    throwInvalidColor(color);
  }
  // Fast lane for hex colors (also with alpha)
  if (color.startsWith('#')) {
    if (hexRegEx.test(color)) {
      const hex = color.substring(1);
      const step = hex.length <= 4 ? 1 : 2;
      const colorFromHex = [0, 0, 0, 255];
      for (let i = 0, ii = hex.length; i < ii; i += step) {
        let colorComponent = parseInt(hex.substring(i, i + step), 16);
        if (step === 1) {
          colorComponent += colorComponent << 4;
        }
        colorFromHex[i / step] = colorComponent;
      }
      colorFromHex[3] = colorFromHex[3] / 255;
      return colorFromHex;
    }
    throwInvalidColor(color);
  }
  // Use canvas color serialization to parse the color into hex or rgba
  // See https://www.w3.org/TR/2021/SPSD-2dcontext-20210128/#serialization-of-a-color
  const context = getColorParseContext();
  context.fillStyle = '#abcdef';
  let invalidCheckFillStyle = context.fillStyle;
  context.fillStyle = color;
  if (context.fillStyle === invalidCheckFillStyle) {
    context.fillStyle = '#fedcba';
    invalidCheckFillStyle = context.fillStyle;
    context.fillStyle = color;
    if (context.fillStyle === invalidCheckFillStyle) {
      throwInvalidColor(color);
    }
  }
  const colorString = context.fillStyle;
  if (colorString.startsWith('#') || colorString.startsWith('rgba')) {
    return parseRgba(colorString);
  }
  context.clearRect(0, 0, 1, 1);
  context.fillRect(0, 0, 1, 1);
  const colorFromImage = Array.from(context.getImageData(0, 0, 1, 1).data);
  colorFromImage[3] = toFixed(colorFromImage[3] / 255, 3);
  return colorFromImage;
}
@param {string} color Color string.
@return {Color} RGBa color array.