If we have some transparency, the only way to represent it is via `rgba`. Otherwise, we use the hex representation, which has better compatibility with older browsers. Values are capped between `0` and `255`, rounded and zero-padded.
483332
function () {
        if (this.alpha < 1.0) {
            return "rgba(" + this.rgb.map(function (c) {
                return Math.round(c);
            }).concat(this.alpha).join(', ') + ")";
        } else {
            return '#' + this.rgb.map(function (i) {
                i = Math.round(i);
                i = (i > 255 ? 255 : (i < 0 ? 0 : i)).toString(16);
                return i.length === 1 ? '0' + i : i;
            }).join('');
        }
    }
1137176
function whiteOrBlack( color ) {
		color = color.replace( /^#/, '' );
		for ( var i = 0, rgb = []; i <= 2; i++ )
			rgb[ i ] = parseInt( color.substr( i * 2, 2 ), 16 );
		var luma = ( 0.2126 * rgb[ 0 ] ) + ( 0.7152 * rgb[ 1 ] ) + ( 0.0722 * rgb[ 2 ] );
		return '#' + ( luma >= 165 ? '000' : 'fff' );
	}
1054988
function getAlphaHex(alpha) {
    var num = Math.round(alpha * 255);
    var hex = num.toString(16);

    return hex.length === 1 ? '0' + hex : hex;
}
584866
function(color, prc) {
		var num = parseInt(color, 16),
		    amt = Math.round(2.55 * prc),
		    R = (num >> 16) + amt,
		    G = (num >> 8 & 0x00FF) + amt,
		    B = (num & 0x0000FF) + amt;
		return (0x1000000 + (R < 255 ? R < 1 ? 0 : R : 255) * 0x10000 +
			(G < 255 ? G < 1 ? 0 : G : 255) * 0x100 +
			(B < 255 ? B < 1 ? 0 : B : 255))
			.toString(16)
			.slice(1);
	}
267276
function (str) {
            var values, r, g, b, a = 1;
            if ((str.length === 4 || str.length === 7) && str.substr(0, 1) === '#') {
                values = str.match(hexRe);
                if (values) {
                    r = parseHex(values[1]);
                    g = parseHex(values[2]);
                    b = parseHex(values[3]);
                    if (str.length === 4) {
                        r = paddingHex(r);
                        g = paddingHex(g);
                        b = paddingHex(b);
                    }
                }
            } else {
                values = str.match(rgbaRe);
                if (values) {
                    r = parseInt(values[1], 10);
                    g = parseInt(values[2], 10);
                    b = parseInt(values[3], 10);
                    a = parseFloat(values[4]) || 1;
                }
            }
            return typeof r === 'undefined' ? undefined : new Color({
                r: r,
                g: g,
                b: b,
                a: a
            });
        }
1026094
function intToRGBA(i) {
  const rgba = {};

  rgba.r = Math.floor(i / Math.pow(256, 3));
  rgba.g = Math.floor((i - rgba.r * Math.pow(256, 3)) / Math.pow(256, 2));
  rgba.b = Math.floor(
    (i - rgba.r * Math.pow(256, 3) - rgba.g * Math.pow(256, 2)) /
      Math.pow(256, 1)
  );
  rgba.a = Math.floor(
    (i -
      rgba.r * Math.pow(256, 3) -
      rgba.g * Math.pow(256, 2) -
      rgba.b * Math.pow(256, 1)) /
      Math.pow(256, 0)
  );

  return rgba;
}
1083546
function(rgba, offset) {
        rgba = rgba || [];
        offset = offset || 0;
		rgba[offset++] = this.rgb[0];
		rgba[offset++] = this.rgb[1];
		rgba[offset++] = this.rgb[2];
		rgba[offset] = this._alpha;
		return rgba;
	}
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);

}
548949
function rgbToHsl(r, g, b) {

    r = bound01(r, 255);
    g = bound01(g, 255);
    b = bound01(b, 255);

    var max = mathMax(r, g, b), min = mathMin(r, g, b);
    var h, s, l = (max + min) / 2;

    if(max == min) {
        h = s = 0; // achromatic
    }
    else {
        var d = max - min;
        s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
        switch(max) {
            case r: h = (g - b) / d + (g < b ? 6 : 0); break;
            case g: h = (b - r) / d + 2; break;
            case b: h = (r - g) / d + 4; break;
        }

        h /= 6;
    }

    return { h: h, s: s, l: l };
}
352840
def to_s(opts = {})
      return smallest if options[:style] == :compressed
      return representation if representation

      # IE10 doesn't properly support the color name "transparent", so we emit
      # generated transparent colors as rgba(0, 0, 0, 0) in favor of that. See
      # #1782.
      return rgba_str if Number.basically_equal?(alpha, 0)
      return name if name
      alpha? ? rgba_str : hex_str
    end
1001480
def convertColor(value):
    
    s = value

    if s in colors:
        s = colors[s]

    rgbpMatch = rgbp.match(s)
    if rgbpMatch is not None:
        r = int(float(rgbpMatch.group(1)) * 255.0 / 100.0)
        g = int(float(rgbpMatch.group(2)) * 255.0 / 100.0)
        b = int(float(rgbpMatch.group(3)) * 255.0 / 100.0)
        s = '#%02x%02x%02x' % (r, g, b)
    else:
        rgbMatch = rgb.match(s)
        if rgbMatch is not None:
            r = int(rgbMatch.group(1))
            g = int(rgbMatch.group(2))
            b = int(rgbMatch.group(3))
            s = '#%02x%02x%02x' % (r, g, b)

    if s[0] == '#':
        s = s.lower()
        if len(s) == 7 and s[1] == s[2] and s[3] == s[4] and s[5] == s[6]:
            s = '#' + s[1] + s[3] + s[5]

    return s
1064129
function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
    // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
    // not the usual [0, 1]. If a command like setFillColor is used the src
    // values will already be within the correct range. However, if we are
    // converting an image we have to map the values to the correct range given
    // above.
    // Ls,as,bs <---> L*,a*,b* in the spec
    var Ls = src[srcOffset];
    var as = src[srcOffset + 1];
    var bs = src[srcOffset + 2];
    if (maxVal !== false) {
      Ls = decode(Ls, maxVal, 0, 100);
      as = decode(as, maxVal, cs.amin, cs.amax);
      bs = decode(bs, maxVal, cs.bmin, cs.bmax);
    }

    // Adjust limits of 'as' and 'bs'
    as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
    bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;

    // Computes intermediate variables X,Y,Z as per spec
    var M = (Ls + 16) / 116;
    var L = M + (as / 500);
    var N = M - (bs / 200);

    var X = cs.XW * fn_g(L);
    var Y = cs.YW * fn_g(M);
    var Z = cs.ZW * fn_g(N);

    var r, g, b;
    // Using different conversions for D50 and D65 white points,
    // per http://www.color.org/srgb.pdf
    if (cs.ZW < 1) {
      // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
      r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
      g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
      b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
    } else {
      // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
      r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
      g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
      b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
    }
    // clamp color values to [0,1] range then convert to [0,255] range.
    dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
    dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
    dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  }
512891
def hex_color(value):
    '''
    '''
    r = ((value >> (8 * 2)) & 255) / 255.0
    g = ((value >> (8 * 1)) & 255) / 255.0
    b = ((value >> (8 * 0)) & 255) / 255.0
    return (r, g, b)
673855
function() {
           
            var hex = this.get(this.OPT.HEX),
                l   = hex.length,
                c,i,rgb;

            // support #369 -> #336699 shorthand
            if (l === 3) {
                c = hex.split("");
                for (i=0; i<l; i=i+1) {
                    c[i] = c[i] + c[i];
                }

                hex = c.join("");
            }

            if (hex.length !== 6) {
                return false;
            }

            rgb = Color.hex2rgb(hex);


            this.setValue(rgb);
        }
957469
function HSVA_TO_RGBA() {
        var h = this.h();
        var s = this.s();
        var v = this.v();
        var a = this.a();
        var hi = Math.floor(h / 60);
        var f = h / 60 - hi;
        var p = v * (1 - s);
        var q = v * (1 - f * s);
        var t = v * (1 - (1 - f) * s);
        var rgba;

        switch (hi) {
            case 0:
                rgba = [v, t, p, a]; break;
            case 1:
                rgba = [q, v, p, a]; break;
            case 2:
                rgba = [p, v, t, a]; break;
            case 3:
                rgba = [p, q, v, a]; break;
            case 4:
                rgba = [t, p, v, a]; break;
            case 5:
                rgba = [v, p, q, a]; break;
            default:
                rgba = [0, 0, 0, a];
        }

        for (var i = rgba.length - 1; i--;) {
            rgba[i] *= 255;
        }

        return kolor.rgba(rgba);
    }
486792
def rgba_to_int(cls, red, green, blue, alpha):
        
        red = unwrap(red)
        green = unwrap(green)
        blue = unwrap(blue)
        alpha = unwrap(alpha)
        if red is None or green is None or blue is None:
            return None
        if alpha is None:
            alpha = 255
        r = red << 24
        g = green << 16
        b = blue << 8
        a = alpha << 0
        rgba_int = r+g+b+a
        if (rgba_int > (2**31-1)):       # convert to signed 32-bit int
            rgba_int = rgba_int - 2**32
        return rgba_int
470513
def unparse_color(r, g, b, a, type):
    
    if type == '#rgb':
        # Don't lose precision on rgb shortcut
        if r % 17 == 0 and g % 17 == 0 and b % 17 == 0:
            return '#%x%x%x' % (int(r / 17), int(g / 17), int(b / 17))
        type = '#rrggbb'

    if type == '#rgba':
        if r % 17 == 0 and g % 17 == 0 and b % 17 == 0:
            return '#%x%x%x%x' % (
                int(r / 17), int(g / 17), int(b / 17), int(a * 15)
            )
        type = '#rrggbbaa'

    if type == '#rrggbb':
        return '#%02x%02x%02x' % (r, g, b)

    if type == '#rrggbbaa':
        return '#%02x%02x%02x%02x' % (r, g, b, int(a * 255))

    if type == 'rgb':
        return 'rgb(%d, %d, %d)' % (r, g, b)

    if type == 'rgba':
        return 'rgba(%d, %d, %d, %g)' % (r, g, b, a)