import v from "./index-esm4.js";
function w(i) {
  const {
    baseURL: c,
    content: a,
    description: s,
    handleError: f,
    hash: d,
    preProcessor: h,
    title: u,
    uniquifyIDs: n = !1
  } = i;
  try {
    const o = b(a, h), l = v(o, {
      nodeOnly: !0
    });
    if (!l || !(l instanceof SVGSVGElement))
      throw new Error("Could not convert the src to a DOM Node");
    const r = p(l, {
      baseURL: c,
      hash: d,
      uniquifyIDs: n
    });
    if (s) {
      const e = r.querySelector("desc");
      e != null && e.parentNode && e.parentNode.removeChild(e);
      const t = document.createElementNS("http://www.w3.org/2000/svg", "desc");
      t.innerHTML = s, r.prepend(t);
    }
    if (typeof u < "u") {
      const e = r.querySelector("title");
      if (e != null && e.parentNode && e.parentNode.removeChild(e), u) {
        const t = document.createElementNS("http://www.w3.org/2000/svg", "title");
        t.innerHTML = u, r.prepend(t);
      }
    }
    return r;
  } catch (o) {
    return f(o);
  }
}
function b(i, c) {
  return c ? c(i) : i;
}
function p(i, c) {
  const {
    baseURL: a = "",
    hash: s,
    uniquifyIDs: f
  } = c, d = ["id", "href", "xlink:href", "xlink:role", "xlink:arcrole"], h = ["href", "xlink:href"], u = (n, o) => h.includes(n) && (o ? !o.includes("#") : !1);
  return f && [...i.children].forEach((n) => {
    var o;
    if ((o = n.attributes) != null && o.length) {
      const l = Object.values(n.attributes).map((r) => {
        const e = r, t = /url\((.*?)\)/.exec(r.value);
        return t != null && t[1] && (e.value = r.value.replace(t[0], `url(${a}${t[1]}__${s})`)), e;
      });
      d.forEach((r) => {
        const e = l.find((t) => t.name === r);
        e && !u(r, e.value) && (e.value = `${e.value}__${s}`);
      });
    }
    return n.children.length ? p(n, c) : n;
  }), i;
}
export {
  w as getNode,
  b as processSVG,
  p as updateSVGAttributes
};
