color-fns
Version:
Modern JavaScript color utility library.
32 lines • 1.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var parseRgb_1 = require("./parseRgb");
function rgbToCmyk(rgb) {
var value = typeof rgb === 'string' ? parseRgb_1.parseRgb(rgb) : rgb;
if (!value) {
return null;
}
// Convert the RGB values to the range 0-1
var _a = [value.red / 255, value.green / 255, value.blue / 255, value.alpha], red = _a[0], green = _a[1], blue = _a[2], alpha = _a[3];
// Find the maximum value of R, G and B.
var max = Math.max(red, green, blue);
// Calculate the cmyk values
var key = 1 - max;
var cyan = (1 - red - key) / (1 - key);
var magenta = (1 - green - key) / (1 - key);
var yellow = (1 - blue - key) / (1 - key);
// normalize values
cyan = Math.floor(cyan * 100);
magenta = Math.floor(magenta * 100);
yellow = Math.floor(yellow * 100);
key = Math.floor(key * 100);
return {
alpha: typeof alpha !== 'undefined' ? alpha : 1,
cyan: cyan,
key: key,
magenta: magenta,
yellow: yellow
};
}
exports.rgbToCmyk = rgbToCmyk;
//# sourceMappingURL=rgbToCmyk.js.map