import { uniqueId as D } from "@milaboratories/helpers";
function H() {
  const e = document.createElementNS("http://www.w3.org/2000/svg", "svg");
  return e.setAttribute("xmlns", "http://www.w3.org/2000/svg"), e.style.display = "none", document.body.prepend(e), e;
}
window.SvgRegistryRawSvgMap = window.SvgRegistryRawSvgMap ?? /* @__PURE__ */ new Map();
window.SvgRegistryDefsElement = window.SvgRegistryDefsElement ?? H();
const l = window.SvgRegistryRawSvgMap, u = window.SvgRegistryDefsElement;
function M(e, d) {
  var c, $, w, m, f;
  if (!l.has(e)) {
    const g = `svg-${d ? `${d}-` : ""}${D(16)}`, t = (c = e.match(/^<svg[^>]*>/i)) == null ? void 0 : c[0], h = ($ = t == null ? void 0 : t.match(/fill\s*=\s*"(.*?)"/)) == null ? void 0 : $[1], p = (w = t == null ? void 0 : t.match(/stroke\s*=\s*"(.*?)"/)) == null ? void 0 : w[1], y = (m = t == null ? void 0 : t.match(/width\s*=\s*"(\d+)(px)?"/)) == null ? void 0 : m[1], R = (f = t == null ? void 0 : t.match(/height\s*=\s*"(\d+)(px)?"/)) == null ? void 0 : f[1], n = t == null ? void 0 : t.match(/viewBox\s*=\s*"[-+]?\d*\.?\d+(?:e[-+]?\d+)?"/), k = n == null ? void 0 : n[2], x = n == null ? void 0 : n[3];
    let r = Number(k ?? y ?? 16);
    r = isNaN(r) ? 16 : r;
    let o = Number(x ?? R ?? 16);
    o = isNaN(o) ? 16 : o;
    const E = `0 0 ${r} ${o}`;
    let b = 0, N = 0;
    const I = h ? `fill="${h}"` : "", S = p ? `stroke="${p}"` : "", A = e.replace(/^<svg[^>]*>/i, `<svg id="${g}" viewBox="${E}" ${I} ${S}>`).replace(/<\/svg>\s*$/, "</svg>").replace(
      /\bfill\s*=\s*(['"])(.*?)\1/gi,
      (C, s, i) => /^(none|transparent)$/i.test(i) ? `fill=${s}${i}${s}` : `fill=${s}var(--svg-fill-${b++}, ${i})${s}`
    ).replace(
      /\bstroke\s*=\s*(['"])(.*?)\1/gi,
      (C, s, i) => /^(none|transparent)$/i.test(i) ? `stroke=${s}${i}${s}` : `stroke=${s}var(--svg-stroke-${N++}, ${i})${s}`
    ), a = document.createElement("template");
    a.innerHTML = A;
    const v = a.content.firstElementChild;
    v && u && u.appendChild(v), l.set(e, {
      spriteId: g,
      defaultWidth: r,
      defaultHeight: o
    });
  }
  return l.get(e);
}
export {
  M as registerSvg
};
//# sourceMappingURL=registry.js.map
