ant-design-x-vue-next
Version:
Ant Design X for Vue — community continuation aligned with @ant-design/x
102 lines (101 loc) • 3.12 kB
JavaScript
import { h as c } from "vue";
import L from "./AnimationText.mjs";
import { sanitizeMarkdownHtml as k } from "./sanitize.mjs";
const g = /* @__PURE__ */ new Set([
"area",
"base",
"br",
"col",
"embed",
"hr",
"img",
"input",
"link",
"meta",
"param",
"source",
"track",
"wbr"
]), _ = /* @__PURE__ */ new Set(["p", "li", "h1", "h2", "h3", "h4", "td", "th", "blockquote"]);
function x(i) {
const e = {};
for (const t of Array.from(i.attributes)) {
const o = t.name;
if (o === "class")
e.class = t.value;
else if (o === "style")
e.style = t.value;
else {
if (o.startsWith("on"))
continue;
e[o] = t.value;
}
}
return e;
}
function p(i, e) {
var h, N, C, y, A, E;
const {
components: t,
streamStatus: o,
enableAnimation: u,
animationConfig: f,
parentTag: n,
parentIsCustom: T
} = e;
if (i.nodeType === Node.TEXT_NODE) {
const r = i.textContent || "";
return u && r.trim() && !T && n && _.has(n) ? c(L, { text: r, animationConfig: f }) : r;
}
if (i.nodeType !== Node.ELEMENT_NODE)
return null;
const a = i, s = (a.localName || a.tagName || a.nodeName || "").toLowerCase() || ((N = (h = (a.outerHTML || "").match(/^<\s*([a-zA-Z][\w:-]*)/)) == null ? void 0 : h[1]) == null ? void 0 : N.toLowerCase()) || "";
if (!s)
return a.textContent;
const b = !!(t != null && t[s]), v = Array.from(a.childNodes).map(
(r) => p(r, {
...e,
parentTag: s,
parentIsCustom: b || T
})
), l = x(a), d = v.filter((r) => r != null), m = t == null ? void 0 : t[s];
if (m) {
if (s === "code") {
const r = ((C = (a.getAttribute("class") || "").split(/\s+/).find((S) => S.startsWith("language-"))) == null ? void 0 : C.replace("language-", "")) || ((y = a.parentElement) == null ? void 0 : y.getAttribute("data-language")) || void 0;
l.lang = r;
const w = (((A = a.parentElement) == null ? void 0 : A.localName) || ((E = a.parentElement) == null ? void 0 : E.tagName) || "").toLowerCase();
l.block = w === "pre", l.content = a.textContent || "";
}
return l.streamStatus = o, typeof m == "string" ? c(m, l, g.has(s) ? void 0 : () => d) : c(m, l, g.has(s) ? void 0 : () => d);
}
if (s === "pre" && (t != null && t.code)) {
const r = a.querySelector(":scope > code");
if (r)
return p(r, e);
}
return c(s, l, g.has(s) ? void 0 : d);
}
function H(i, e = {}) {
if (!i)
return [];
const t = Object.keys(e.components || {}).filter((n) => n !== "code"), o = k(i, {
dompurifyConfig: e.dompurifyConfig,
componentTags: t
});
if (typeof document > "u")
return o ? [c("div", null, o)] : [];
const u = document.createElement("div");
u.innerHTML = o;
const f = e.streamStatus ?? "done";
return Array.from(u.childNodes).map(
(n) => p(n, {
components: e.components,
streamStatus: f,
enableAnimation: e.enableAnimation,
animationConfig: e.animationConfig
})
).filter((n) => n != null).map((n) => typeof n == "string" ? c("span", null, n) : n);
}
export {
H as htmlToVNodes
};