import { fromHtmlIsomorphic as w } from "../../../../hast-util-from-html-isomorphic@2.0.0/node_modules/hast-util-from-html-isomorphic/lib/browser.es.js";
import u from "../../../../katex@0.16.28/node_modules/katex/dist/katex.es.js";
import { visitParents as C, SKIP as I } from "../../../../unist-util-visit-parents@6.0.2/node_modules/unist-util-visit-parents/lib/index.es.js";
import { toText as O } from "../../../../hast-util-to-text@4.0.2/node_modules/hast-util-to-text/lib/index.es.js";
const S = {}, T = [];
function E(d) {
  const s = d || S;
  return function(f, g) {
    C(f, "element", function(r, o) {
      const n = Array.isArray(r.properties.className) ? r.properties.className : T, p = n.includes("language-math"), m = n.includes("math-display"), y = n.includes("math-inline");
      let a = m;
      if (!p && !m && !y)
        return;
      let t = o[o.length - 1], i = r;
      if (r.tagName === "code" && p && t && t.type === "element" && t.tagName === "pre" && (i = t, t = o[o.length - 2], a = !0), !t) return;
      const c = O(i, { whitespace: "pre" });
      let e;
      try {
        e = u.renderToString(c, {
          ...s,
          displayMode: a,
          throwOnError: !0
        });
      } catch (l) {
        const h = (
          /** @type {Error} */
          l
        ), N = h.name.toLowerCase();
        g.message("Could not render math with KaTeX", {
          ancestors: [...o, r],
          cause: h,
          place: r.position,
          ruleId: N,
          source: "rehype-katex"
        });
        try {
          e = u.renderToString(c, {
            ...s,
            displayMode: a,
            strict: "ignore",
            throwOnError: !1
          });
        } catch {
          e = [
            {
              type: "element",
              tagName: "span",
              properties: {
                className: ["katex-error"],
                style: "color:" + (s.errorColor || "#cc0000"),
                title: String(l)
              },
              children: [{ type: "text", value: c }]
            }
          ];
        }
      }
      typeof e == "string" && (e = /** @type {Array<ElementContent>} */
      w(e).children);
      const x = t.children.indexOf(i);
      return t.children.splice(x, 1, ...e), I;
    });
  };
}
export {
  E as default
};
//# sourceMappingURL=index.es.js.map
