import a from "../utils/index.js";
import u from "../channels/reusable.js";
const i = {
  /* VARIABLES */
  re: /^rgba?\(\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e\d+)?(%?))\s*?(?:,|\s)\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e\d+)?(%?))\s*?(?:,|\s)\s*?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e\d+)?(%?))(?:\s*?(?:,|\/)\s*?\+?(-?(?:\d+(?:\.\d+)?|(?:\.\d+))(?:e\d+)?(%?)))?\s*?\)$/i,
  /* API */
  parse: (e) => {
    const r = e.charCodeAt(0);
    if (r !== 114 && r !== 82)
      return;
    const n = e.match(i.re);
    if (!n)
      return;
    const [, s, t, l, c, o, g, d, p] = n;
    return u.set({
      r: a.channel.clamp.r(t ? parseFloat(s) * 2.55 : parseFloat(s)),
      g: a.channel.clamp.g(c ? parseFloat(l) * 2.55 : parseFloat(l)),
      b: a.channel.clamp.b(g ? parseFloat(o) * 2.55 : parseFloat(o)),
      a: d ? a.channel.clamp.a(p ? parseFloat(d) / 100 : parseFloat(d)) : 1
    }, e);
  },
  stringify: (e) => {
    const { r, g: n, b: s, a: t } = e;
    return t < 1 ? `rgba(${a.lang.round(r)}, ${a.lang.round(n)}, ${a.lang.round(s)}, ${a.lang.round(t)})` : `rgb(${a.lang.round(r)}, ${a.lang.round(n)}, ${a.lang.round(s)})`;
  }
};
export {
  i as default
};
