import d from "../channels/reusable.js";
import { DEC2HEX as n } from "../constants.js";
const l = {
  /* VARIABLES */
  re: /^#((?:[a-f0-9]{2}){2,4}|[a-f0-9]{3})$/i,
  /* API */
  parse: (r) => {
    if (r.charCodeAt(0) !== 35)
      return;
    const s = r.match(l.re);
    if (!s)
      return;
    const e = s[1], t = parseInt(e, 16), a = e.length, f = a % 4 === 0, c = a > 4, o = c ? 1 : 17, u = c ? 8 : 4, i = f ? 0 : -1, h = c ? 255 : 15;
    return d.set({
      r: (t >> u * (i + 3) & h) * o,
      g: (t >> u * (i + 2) & h) * o,
      b: (t >> u * (i + 1) & h) * o,
      a: f ? (t & h) * o / 255 : 1
    }, r);
  },
  stringify: (r) => {
    const { r: s, g: e, b: t, a } = r;
    return a < 1 ? `#${n[Math.round(s)]}${n[Math.round(e)]}${n[Math.round(t)]}${n[Math.round(a * 255)]}` : `#${n[Math.round(s)]}${n[Math.round(e)]}${n[Math.round(t)]}`;
  }
};
export {
  l as default
};
