import { __exports as i } from "../../../../../../_virtual/index26.js";
import { __require as S } from "../../../../domelementtype@2.3.0/node_modules/domelementtype/lib/index.js";
import { __require as A } from "../../../../entities@4.5.0/node_modules/entities/lib/index.js";
import { __require as C } from "./foreignNames.js";
var g;
function R() {
  if (g) return i;
  g = 1;
  var u = i && i.__assign || function() {
    return u = Object.assign || function(e) {
      for (var r, n = 1, t = arguments.length; n < t; n++) {
        r = arguments[n];
        for (var a in r) Object.prototype.hasOwnProperty.call(r, a) && (e[a] = r[a]);
      }
      return e;
    }, u.apply(this, arguments);
  }, _ = i && i.__createBinding || (Object.create ? function(e, r, n, t) {
    t === void 0 && (t = n);
    var a = Object.getOwnPropertyDescriptor(r, n);
    (!a || ("get" in a ? !r.__esModule : a.writable || a.configurable)) && (a = { enumerable: !0, get: function() {
      return r[n];
    } }), Object.defineProperty(e, t, a);
  } : function(e, r, n, t) {
    t === void 0 && (t = n), e[t] = r[n];
  }), b = i && i.__setModuleDefault || (Object.create ? function(e, r) {
    Object.defineProperty(e, "default", { enumerable: !0, value: r });
  } : function(e, r) {
    e.default = r;
  }), h = i && i.__importStar || function(e) {
    if (e && e.__esModule) return e;
    var r = {};
    if (e != null) for (var n in e) n !== "default" && Object.prototype.hasOwnProperty.call(e, n) && _(r, e, n);
    return b(r, e), r;
  };
  Object.defineProperty(i, "__esModule", { value: !0 }), i.render = void 0;
  var c = h(/* @__PURE__ */ S()), f = /* @__PURE__ */ A(), s = /* @__PURE__ */ C(), x = /* @__PURE__ */ new Set([
    "style",
    "script",
    "xmp",
    "iframe",
    "noembed",
    "noframes",
    "plaintext",
    "noscript"
  ]);
  function M(e) {
    return e.replace(/"/g, "&quot;");
  }
  function p(e, r) {
    var n;
    if (e) {
      var t = ((n = r.encodeEntities) !== null && n !== void 0 ? n : r.decodeEntities) === !1 ? M : r.xmlMode || r.encodeEntities !== "utf8" ? f.encodeXML : f.escapeAttribute;
      return Object.keys(e).map(function(a) {
        var l, d, v = (l = e[a]) !== null && l !== void 0 ? l : "";
        return r.xmlMode === "foreign" && (a = (d = s.attributeNames.get(a)) !== null && d !== void 0 ? d : a), !r.emptyAttrs && !r.xmlMode && v === "" ? a : "".concat(a, '="').concat(t(v), '"');
      }).join(" ");
    }
  }
  var m = /* @__PURE__ */ new Set([
    "area",
    "base",
    "basefont",
    "br",
    "col",
    "command",
    "embed",
    "frame",
    "hr",
    "img",
    "input",
    "isindex",
    "keygen",
    "link",
    "meta",
    "param",
    "source",
    "track",
    "wbr"
  ]);
  function o(e, r) {
    r === void 0 && (r = {});
    for (var n = ("length" in e) ? e : [e], t = "", a = 0; a < n.length; a++)
      t += O(n[a], r);
    return t;
  }
  i.render = o, i.default = o;
  function O(e, r) {
    switch (e.type) {
      case c.Root:
        return o(e.children, r);
      // @ts-expect-error We don't use `Doctype` yet
      case c.Doctype:
      case c.Directive:
        return q(e);
      case c.Comment:
        return D(e);
      case c.CDATA:
        return E(e);
      case c.Script:
      case c.Style:
      case c.Tag:
        return T(e, r);
      case c.Text:
        return w(e, r);
    }
  }
  var j = /* @__PURE__ */ new Set([
    "mi",
    "mo",
    "mn",
    "ms",
    "mtext",
    "annotation-xml",
    "foreignObject",
    "desc",
    "title"
  ]), y = /* @__PURE__ */ new Set(["svg", "math"]);
  function T(e, r) {
    var n;
    r.xmlMode === "foreign" && (e.name = (n = s.elementNames.get(e.name)) !== null && n !== void 0 ? n : e.name, e.parent && j.has(e.parent.name) && (r = u(u({}, r), { xmlMode: !1 }))), !r.xmlMode && y.has(e.name) && (r = u(u({}, r), { xmlMode: "foreign" }));
    var t = "<".concat(e.name), a = p(e.attribs, r);
    return a && (t += " ".concat(a)), e.children.length === 0 && (r.xmlMode ? (
      // In XML mode or foreign mode, and user hasn't explicitly turned off self-closing tags
      r.selfClosingTags !== !1
    ) : (
      // User explicitly asked for self-closing tags, even in HTML mode
      r.selfClosingTags && m.has(e.name)
    )) ? (r.xmlMode || (t += " "), t += "/>") : (t += ">", e.children.length > 0 && (t += o(e.children, r)), (r.xmlMode || !m.has(e.name)) && (t += "</".concat(e.name, ">"))), t;
  }
  function q(e) {
    return "<".concat(e.data, ">");
  }
  function w(e, r) {
    var n, t = e.data || "";
    return ((n = r.encodeEntities) !== null && n !== void 0 ? n : r.decodeEntities) !== !1 && !(!r.xmlMode && e.parent && x.has(e.parent.name)) && (t = r.xmlMode || r.encodeEntities !== "utf8" ? (0, f.encodeXML)(t) : (0, f.escapeText)(t)), t;
  }
  function E(e) {
    return "<![CDATA[".concat(e.children[0].data, "]]>");
  }
  function D(e) {
    return "<!--".concat(e.data, "-->");
  }
  return i;
}
export {
  R as __require
};
//# sourceMappingURL=index.js.map
