import "../../../color-string@1.9.1/node_modules/color-string/index.js";
import d from "../../../color-convert@1.9.3/node_modules/color-convert/index.js";
import { c as F } from "../../../../../_virtual/index19.js";
var v = F.exports, s = d, m = [].slice, x = [
  "keyword",
  "gray",
  "hex"
], p = {};
Object.keys(s).forEach(function(r) {
  p[m.call(s[r].labels).sort().join("")] = r;
});
var g = {};
function h(r, t) {
  if (!(this instanceof h))
    return new h(r, t);
  if (t && t in x && (t = null), t && !(t in s))
    throw new Error("Unknown model: " + t);
  var n, a;
  if (r == null)
    this.model = "rgb", this.color = [0, 0, 0], this.valpha = 1;
  else if (r instanceof h)
    this.model = r.model, this.color = r.color.slice(), this.valpha = r.valpha;
  else if (typeof r == "string") {
    var i = v.get(r);
    if (i === null)
      throw new Error("Unable to parse color from string: " + r);
    this.model = i.model, a = s[this.model].channels, this.color = i.value.slice(0, a), this.valpha = typeof i.value[a] == "number" ? i.value[a] : 1;
  } else if (r.length) {
    this.model = t || "rgb", a = s[this.model].channels;
    var u = m.call(r, 0, a);
    this.color = b(u, a), this.valpha = typeof r[a] == "number" ? r[a] : 1;
  } else if (typeof r == "number")
    r &= 16777215, this.model = "rgb", this.color = [
      r >> 16 & 255,
      r >> 8 & 255,
      r & 255
    ], this.valpha = 1;
  else {
    this.valpha = 1;
    var l = Object.keys(r);
    "alpha" in r && (l.splice(l.indexOf("alpha"), 1), this.valpha = typeof r.alpha == "number" ? r.alpha : 0);
    var c = l.sort().join("");
    if (!(c in p))
      throw new Error("Unable to parse color from object: " + JSON.stringify(r));
    this.model = p[c];
    var f = s[this.model].labels, y = [];
    for (n = 0; n < f.length; n++)
      y.push(r[f[n]]);
    this.color = b(y);
  }
  if (g[this.model])
    for (a = s[this.model].channels, n = 0; n < a; n++) {
      var w = g[this.model][n];
      w && (this.color[n] = w(this.color[n]));
    }
  this.valpha = Math.max(0, Math.min(1, this.valpha)), Object.freeze && Object.freeze(this);
}
h.prototype = {
  toString: function() {
    return this.string();
  },
  toJSON: function() {
    return this[this.model]();
  },
  string: function(r) {
    var t = this.model in v.to ? this : this.rgb();
    t = t.round(typeof r == "number" ? r : 1);
    var n = t.valpha === 1 ? t.color : t.color.concat(this.valpha);
    return v.to[t.model](n);
  },
  percentString: function(r) {
    var t = this.rgb().round(typeof r == "number" ? r : 1), n = t.valpha === 1 ? t.color : t.color.concat(this.valpha);
    return v.to.rgb.percent(n);
  },
  array: function() {
    return this.valpha === 1 ? this.color.slice() : this.color.concat(this.valpha);
  },
  object: function() {
    for (var r = {}, t = s[this.model].channels, n = s[this.model].labels, a = 0; a < t; a++)
      r[n[a]] = this.color[a];
    return this.valpha !== 1 && (r.alpha = this.valpha), r;
  },
  unitArray: function() {
    var r = this.rgb().color;
    return r[0] /= 255, r[1] /= 255, r[2] /= 255, this.valpha !== 1 && r.push(this.valpha), r;
  },
  unitObject: function() {
    var r = this.rgb().object();
    return r.r /= 255, r.g /= 255, r.b /= 255, this.valpha !== 1 && (r.alpha = this.valpha), r;
  },
  round: function(r) {
    return r = Math.max(r || 0, 0), new h(this.color.map(A(r)).concat(this.valpha), this.model);
  },
  alpha: function(r) {
    return arguments.length ? new h(this.color.concat(Math.max(0, Math.min(1, r))), this.model) : this.valpha;
  },
  red: e("rgb", 0, o(255)),
  green: e("rgb", 1, o(255)),
  blue: e("rgb", 2, o(255)),
  hue: e(["hsl", "hsv", "hsl", "hwb", "hcg"], 0, function(r) {
    return (r % 360 + 360) % 360;
  }),
  saturationl: e("hsl", 1, o(100)),
  lightness: e("hsl", 2, o(100)),
  saturationv: e("hsv", 1, o(100)),
  value: e("hsv", 2, o(100)),
  chroma: e("hcg", 1, o(100)),
  gray: e("hcg", 2, o(100)),
  white: e("hwb", 1, o(100)),
  wblack: e("hwb", 2, o(100)),
  cyan: e("cmyk", 0, o(100)),
  magenta: e("cmyk", 1, o(100)),
  yellow: e("cmyk", 2, o(100)),
  black: e("cmyk", 3, o(100)),
  x: e("xyz", 0, o(100)),
  y: e("xyz", 1, o(100)),
  z: e("xyz", 2, o(100)),
  l: e("lab", 0, o(100)),
  a: e("lab", 1),
  b: e("lab", 2),
  keyword: function(r) {
    return arguments.length ? new h(r) : s[this.model].keyword(this.color);
  },
  hex: function(r) {
    return arguments.length ? new h(r) : v.to.hex(this.rgb().round().color);
  },
  rgbNumber: function() {
    var r = this.rgb().color;
    return (r[0] & 255) << 16 | (r[1] & 255) << 8 | r[2] & 255;
  },
  luminosity: function() {
    for (var r = this.rgb().color, t = [], n = 0; n < r.length; n++) {
      var a = r[n] / 255;
      t[n] = a <= 0.03928 ? a / 12.92 : Math.pow((a + 0.055) / 1.055, 2.4);
    }
    return 0.2126 * t[0] + 0.7152 * t[1] + 0.0722 * t[2];
  },
  contrast: function(r) {
    var t = this.luminosity(), n = r.luminosity();
    return t > n ? (t + 0.05) / (n + 0.05) : (n + 0.05) / (t + 0.05);
  },
  level: function(r) {
    var t = this.contrast(r);
    return t >= 7.1 ? "AAA" : t >= 4.5 ? "AA" : "";
  },
  isDark: function() {
    var r = this.rgb().color, t = (r[0] * 299 + r[1] * 587 + r[2] * 114) / 1e3;
    return t < 128;
  },
  isLight: function() {
    return !this.isDark();
  },
  negate: function() {
    for (var r = this.rgb(), t = 0; t < 3; t++)
      r.color[t] = 255 - r.color[t];
    return r;
  },
  lighten: function(r) {
    var t = this.hsl();
    return t.color[2] += t.color[2] * r, t;
  },
  darken: function(r) {
    var t = this.hsl();
    return t.color[2] -= t.color[2] * r, t;
  },
  saturate: function(r) {
    var t = this.hsl();
    return t.color[1] += t.color[1] * r, t;
  },
  desaturate: function(r) {
    var t = this.hsl();
    return t.color[1] -= t.color[1] * r, t;
  },
  whiten: function(r) {
    var t = this.hwb();
    return t.color[1] += t.color[1] * r, t;
  },
  blacken: function(r) {
    var t = this.hwb();
    return t.color[2] += t.color[2] * r, t;
  },
  grayscale: function() {
    var r = this.rgb().color, t = r[0] * 0.3 + r[1] * 0.59 + r[2] * 0.11;
    return h.rgb(t, t, t);
  },
  fade: function(r) {
    return this.alpha(this.valpha - this.valpha * r);
  },
  opaquer: function(r) {
    return this.alpha(this.valpha + this.valpha * r);
  },
  rotate: function(r) {
    var t = this.hsl(), n = t.color[0];
    return n = (n + r) % 360, n = n < 0 ? 360 + n : n, t.color[0] = n, t;
  },
  mix: function(r, t) {
    if (!r || !r.rgb)
      throw new Error('Argument to "mix" was not a Color instance, but rather an instance of ' + typeof r);
    var n = r.rgb(), a = this.rgb(), i = t === void 0 ? 0.5 : t, u = 2 * i - 1, l = n.alpha() - a.alpha(), c = ((u * l === -1 ? u : (u + l) / (1 + u * l)) + 1) / 2, f = 1 - c;
    return h.rgb(
      c * n.red() + f * a.red(),
      c * n.green() + f * a.green(),
      c * n.blue() + f * a.blue(),
      n.alpha() * i + a.alpha() * (1 - i)
    );
  }
};
Object.keys(s).forEach(function(r) {
  if (x.indexOf(r) === -1) {
    var t = s[r].channels;
    h.prototype[r] = function() {
      if (this.model === r)
        return new h(this);
      if (arguments.length)
        return new h(arguments, r);
      var n = typeof arguments[t] == "number" ? t : this.valpha;
      return new h(M(s[this.model][r].raw(this.color)).concat(n), r);
    }, h[r] = function(n) {
      return typeof n == "number" && (n = b(m.call(arguments), t)), new h(n, r);
    };
  }
});
function k(r, t) {
  return Number(r.toFixed(t));
}
function A(r) {
  return function(t) {
    return k(t, r);
  };
}
function e(r, t, n) {
  return r = Array.isArray(r) ? r : [r], r.forEach(function(a) {
    (g[a] || (g[a] = []))[t] = n;
  }), r = r[0], function(a) {
    var i;
    return arguments.length ? (n && (a = n(a)), i = this[r](), i.color[t] = a, i) : (i = this[r]().color[t], n && (i = n(i)), i);
  };
}
function o(r) {
  return function(t) {
    return Math.max(0, Math.min(r, t));
  };
}
function M(r) {
  return Array.isArray(r) ? r : [r];
}
function b(r, t) {
  for (var n = 0; n < t; n++)
    typeof r[n] != "number" && (r[n] = 0);
  return r;
}
var S = h;
export {
  S as default
};
//# sourceMappingURL=index.js.map
