/**
 * tdesign v0.46.4
 * (c) 2022 tdesign
 * @license MIT
 */

var rgb2cmyk = function rgb2cmyk(red, green, blue) {
  var computedC = 0;
  var computedM = 0;
  var computedY = 0;
  var computedK = 0;
  var r = parseInt("".concat(red).replace(/\s/g, ""), 10);
  var g = parseInt("".concat(green).replace(/\s/g, ""), 10);
  var b = parseInt("".concat(blue).replace(/\s/g, ""), 10);

  if (r === 0 && g === 0 && b === 0) {
    computedK = 1;
    return [0, 0, 0, 1];
  }

  computedC = 1 - r / 255;
  computedM = 1 - g / 255;
  computedY = 1 - b / 255;
  var minCMY = Math.min(computedC, Math.min(computedM, computedY));
  computedC = (computedC - minCMY) / (1 - minCMY);
  computedM = (computedM - minCMY) / (1 - minCMY);
  computedY = (computedY - minCMY) / (1 - minCMY);
  computedK = minCMY;
  return [computedC, computedM, computedY, computedK];
};
var cmyk2rgb = function cmyk2rgb(cyan, magenta, yellow, black) {
  var c = cyan / 100;
  var m = magenta / 100;
  var y = yellow / 100;
  var k = black / 100;
  c = c * (1 - k) + k;
  m = m * (1 - k) + k;
  y = y * (1 - k) + k;
  var r = 1 - c;
  var g = 1 - m;
  var b = 1 - y;
  r = Math.round(255 * r);
  g = Math.round(255 * g);
  b = Math.round(255 * b);
  return {
    r: r,
    g: g,
    b: b
  };
};
var REG_CMYK_STRING = /cmyk\((\d+%?),(\d+%?),(\d+%?),(\d+%?)\)/;

var toNumber = function toNumber(str) {
  return Math.max(0, Math.min(255, parseInt(str, 10)));
};

var cmykInputToColor = function cmykInputToColor(input) {
  if (/cmyk/i.test(input)) {
    var str = input.replace(/\s/g, "");
    var match = str.match(REG_CMYK_STRING);
    var c = toNumber(match[1]);
    var m = toNumber(match[2]);
    var y = toNumber(match[3]);
    var k = toNumber(match[4]);

    var _cmyk2rgb = cmyk2rgb(c, m, y, k),
        r = _cmyk2rgb.r,
        g = _cmyk2rgb.g,
        b = _cmyk2rgb.b;

    return "rgb(".concat(r, ", ").concat(g, ", ").concat(b, ")");
  }

  return input;
};

export { cmyk2rgb, cmykInputToColor, rgb2cmyk };
//# sourceMappingURL=cmyk.js.map
