UNPKG

rgba-to-rgb

Version:
18 lines 1.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var invariant = require("invariant"); exports.default = (function (background, color) { if (background === void 0) { background = ''; } if (color === void 0) { color = ''; } var b = background.match(/rgb\((-?\d{1,3}),\s*(-?\d{1,3}),\s*(-?\d{1,3})\)/); var c = color.match(/rgba\((-?\d{1,3}),\s*(-?\d{1,3}),\s*(-?\d{1,3}),\s*([0-1]?(?:\.\d+)?)\)/); invariant(b !== null && b.length === 4, "rgba-to-rgb: background should be in 'rgb(r, g, b)' format, got '" + background + "'."); invariant(c !== null && c.length === 5, "rgba-to-rgb: color should be in 'rgba(r, g, b, a)' format, got '" + color + "'."); var _a = b, bRed = _a[1], bGreen = _a[2], bBlue = _a[3]; var _b = c, cRed = _b[1], cGreen = _b[2], cBlue = _b[3], cAlpha = _b[4]; var red = (1 - +cAlpha) * +bRed + +cAlpha * +cRed; var green = (1 - +cAlpha) * +bGreen + +cAlpha * +cGreen; var blue = (1 - +cAlpha) * +bBlue + +cAlpha * +cBlue; return "rgb(" + Math.round(red) + ", " + Math.round(green) + ", " + Math.round(blue) + ")"; }); //# sourceMappingURL=index.js.map