import { uniqueId as e } from "@milaboratories/helpers";
function t() {
	let 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 ?? t();
var n = window.SvgRegistryRawSvgMap, r = window.SvgRegistryDefsElement;
function i(t, i) {
	if (!n.has(t)) {
		let a = `svg-${i ? `${i}-` : ""}${e(16)}`, o = t.match(/^<svg[^>]*>/i)?.[0], s = o?.match(/fill\s*=\s*"(.*?)"/)?.[1], c = o?.match(/stroke\s*=\s*"(.*?)"/)?.[1], l = o?.match(/width\s*=\s*"(\d+)(px)?"/)?.[1], u = o?.match(/height\s*=\s*"(\d+)(px)?"/)?.[1], d = o?.match(/viewBox\s*=\s*"[-+]?\d*\.?\d+(?:e[-+]?\d+)?"/), f = d?.[2], p = d?.[3], m = Number(f ?? l ?? 16);
		m = isNaN(m) ? 16 : m;
		let h = Number(p ?? u ?? 16);
		h = isNaN(h) ? 16 : h;
		let g = `0 0 ${m} ${h}`, _ = 0, v = 0, y = s ? `fill="${s}"` : "", b = c ? `stroke="${c}"` : "", x = t.replace(/^<svg[^>]*>/i, `<svg id="${a}" viewBox="${g}" ${y} ${b}>`).replace(/<\/svg>\s*$/, "</svg>").replace(/\bfill\s*=\s*(['"])(.*?)\1/gi, (e, t, n) => /^(none|transparent)$/i.test(n) ? `fill=${t}${n}${t}` : `fill=${t}var(--svg-fill-${_++}, ${n})${t}`).replace(/\bstroke\s*=\s*(['"])(.*?)\1/gi, (e, t, n) => /^(none|transparent)$/i.test(n) ? `stroke=${t}${n}${t}` : `stroke=${t}var(--svg-stroke-${v++}, ${n})${t}`), S = document.createElement("template");
		S.innerHTML = x;
		let C = S.content.firstElementChild;
		C && r && r.appendChild(C), n.set(t, {
			spriteId: a,
			defaultWidth: m,
			defaultHeight: h
		});
	}
	return n.get(t);
}
export { i as registerSvg };

//# sourceMappingURL=registry.js.map