text: "use strict";
  Object.defineProperty(exports, "__esModule", { value: true });
  var util_1 = require("./util");
  function rgbToRgb(r, g, b) {
      return {
          r: util_1.bound01(r, 255) * 255,
          g: util_1.bound01(g, 255) * 255,
          b: util_1.bound01(b, 255) * 255,
      };
  }
  exports.rgbToRgb = rgbToRgb;
  function rgbToHsl(r, g, b) {
      r = util_1.bound01(r, 255);
      g = util_1.bound01(g, 255);
      b = util_1.bound01(b, 255);
      var max = Math.max(r, g, b);
      var min = Math.min(r, g, b);
      var h = 0;
      var s = 0;
      var l = (max + min) / 2;
      if (max === min) {
          s = 0;
          h = 0;
      }
      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;
              default:
                  break;
          }
          h /= 6;
      }
      return { h: h, s: s, l: l };
  }
  exports.rgbToHsl = rgbToHsl;
  function hue2rgb(p, q, t) {
      if (t < 0) {
          t += 1;
      }
      if (t > 1) {
          t -= 1;
      }
      if (t < 1 / 6) {
          return p + ((q - p) * (6 * t));
      }
      if (t < 1 / 2) {
          return q;
      }
      if (t < 2 / 3) {
          return p + ((q - p) * ((2 / 3) - t) * 6);
      }
      return p;
  }
  function hslToRgb(h, s, l) {
      var r;
      var g;
      var b;
      h = util_1.bound01(h, 360);
      s = util_1.bound01(s, 100);
      l = util_1.bound01(l, 100);
      if (s === 0) {
          g = l;
          b = l;
          r = l;
      }
      else {
          var q = l < 0.5 ? (l * (1 + s)) : (l + s - (l * s));
          var p = (2 * l) - q;
          r = hue2rgb(p, q, h + (1 / 3));
          g = hue2rgb(p, q, h);
          b = hue2rgb(p, q, h - (1 / 3));
      }
      return { r: r * 255, g: g * 255, b: b * 255 };
  }
  exports.hslToRgb = hslToRgb;
  function rgbToHsv(r, g, b) {
      r = util_1.bound01(r, 255);
      g = util_1.bound01(g, 255);
      b = util_1.bound01(b, 255);
      var max = Math.max(r, g, b);
      var min = Math.min(r, g, b);
      var h = 0;
      var v = max;
      var d = max - min;
      var s = max === 0 ? 0 : d / max;
      if (max === min) {
          h = 0;
      }
      else {
          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;
              default:
                  break;
          }
          h /= 6;
      }
      return { h: h, s: s, v: v };
  }
  exports.rgbToHsv = rgbToHsv;
  function hsvToRgb(h, s, v) {
      h = util_1.bound01(h, 360) * 6;
      s = util_1.bound01(s, 100);
      v = util_1.bound01(v, 100);
      var i = Math.floor(h);
      var f = h - i;
      var p = v * (1 - s);
      var q = v * (1 - (f * s));
      var t = v * (1 - ((1 - f) * s));
      var mod = i % 6;
      var r = [v, q, p, p, t, v][mod];
      var g = [t, v, v, q, p, p][mod];
      var b = [p, p, t, v, v, q][mod];
      return { r: r * 255, g: g * 255, b: b * 255 };
  }
  exports.hsvToRgb = hsvToRgb;
  function rgbToHex(r, g, b, allow3Char) {
      var hex = [
          util_1.pad2(Math.round(r).toString(16)),
          util_1.pad2(Math.round(g).toString(16)),
          util_1.pad2(Math.round(b).toString(16)),
      ];
      if (allow3Char &&
          hex[0].startsWith(hex[0].charAt(1)) &&
          hex[1].startsWith(hex[1].charAt(1)) &&
          hex[2].startsWith(hex[2].charAt(1))) {
          return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
      }
      return hex.join('');
  }
  exports.rgbToHex = rgbToHex;
  function rgbaToHex(r, g, b, a, allow4Char) {
      var hex = [
          util_1.pad2(Math.round(r).toString(16)),
          util_1.pad2(Math.round(g).toString(16)),
          util_1.pad2(Math.round(b).toString(16)),
          util_1.pad2(convertDecimalToHex(a)),
      ];
      if (allow4Char &&
          hex[0].startsWith(hex[0].charAt(1)) &&
          hex[1].startsWith(hex[1].charAt(1)) &&
          hex[2].startsWith(hex[2].charAt(1)) &&
          hex[3].startsWith(hex[3].charAt(1))) {
          return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
      }
      return hex.join('');
  }
  exports.rgbaToHex = rgbaToHex;
  function rgbaToArgbHex(r, g, b, a) {
      var hex = [
          util_1.pad2(convertDecimalToHex(a)),
          util_1.pad2(Math.round(r).toString(16)),
          util_1.pad2(Math.round(g).toString(16)),
          util_1.pad2(Math.round(b).toString(16)),
      ];
      return hex.join('');
  }
  exports.rgbaToArgbHex = rgbaToArgbHex;
  function convertDecimalToHex(d) {
      return Math.round(parseFloat(d) * 255).toString(16);
  }
  exports.convertDecimalToHex = convertDecimalToHex;
  function convertHexToDecimal(h) {
      return parseIntFromHex(h) / 255;
  }
  exports.convertHexToDecimal = convertHexToDecimal;
  function parseIntFromHex(val) {
      return parseInt(val, 16);
  }
  exports.parseIntFromHex = parseIntFromHex;
  