UNPKG

ant-design-x-vue-next

Version:

Ant Design X for Vue — community continuation aligned with @ant-design/x

110 lines (109 loc) 3.69 kB
import { U as f } from "../chunks/module-chunk.mjs"; let s = null; function p() { var a, r; if (s) return s; if (typeof window < "u" && typeof Node < "u") try { const n = document.createElement("template"); n.innerHTML = "<test-detect></test-detect>"; const t = n.content.firstChild; if (t) { const e = (a = Object.getOwnPropertyDescriptor(Node.prototype, "nodeName")) == null ? void 0 : a.get, i = (r = Object.getOwnPropertyDescriptor(Node.prototype, "nodeValue")) == null ? void 0 : r.get, u = !!(e && t.nodeName && !e.call(t)); if (u && e) { const c = e; Object.defineProperty(Node.prototype, "nodeName", { get: function() { const o = c.call(this); if (o) return o; if (this.nodeType === 1 && "tagName" in this) return this.tagName; switch (this.nodeType) { case 3: return "#text"; case 4: return "#cdata-section"; case 7: return "#processing-instruction"; case 8: return "#comment"; case 9: return "#document"; case 11: return "#document-fragment"; } return o; }, configurable: !0, enumerable: !0 }); } const d = !!i && (() => { var l; n.innerHTML = "<div>test</div>"; const c = (l = n.content.firstChild) == null ? void 0 : l.firstChild; if (!c || !i) return !1; const o = i.call(c); return c.nodeValue != null && o == null; })(); if (d && i) { const c = i; Object.defineProperty(Node.prototype, "nodeValue", { get: function() { const o = c.call(this); return o ?? ((this.nodeType === 3 || this.nodeType === 4 || this.nodeType === 8) && "data" in this ? this.data : o); }, configurable: !0, enumerable: !0 }); } if (u || d) return s = f(window), s; } } catch { } return s = f, s; } const m = [ "target", "rel", "data-language", "class", "style", "data-raw", "data-state", "data-lang", "data-block" ], y = ["script", "iframe", "object", "embed", "base", "form"]; function g(a) { if (typeof document > "u") return a.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "").replace(/<iframe\b[^<]*(?:(?!<\/iframe>)<[^<]*)*<\/iframe>/gi, ""); const r = document.createElement("template"); r.innerHTML = a, y.forEach((t) => { r.content.querySelectorAll(t).forEach((e) => e.remove()); }), r.content.querySelectorAll("*").forEach((t) => { for (const e of Array.from(t.attributes)) (e.name.startsWith("on") || e.name === "srcdoc") && t.removeAttribute(e.name); }); const n = document.createElement("div"); return n.appendChild(r.content.cloneNode(!0)), n.innerHTML; } function h(a, r = {}) { if (!a) return ""; const n = g(a), t = p(); if (typeof t.sanitize != "function") return n.replace(/<[^>]*>/g, ""); const e = r.dompurifyConfig || {}, i = Array.isArray(e.ADD_TAGS) ? e.ADD_TAGS : [], u = Array.isArray(e.ADD_ATTR) ? e.ADD_ATTR : [], d = r.componentTags || []; return String( t.sanitize(n, { ...e, ADD_TAGS: Array.from(/* @__PURE__ */ new Set(["xmd-tail", ...d, ...i])), ADD_ATTR: Array.from(/* @__PURE__ */ new Set([...m, ...u])) }) ); } export { p as createPatchedDOMPurify, h as sanitizeMarkdownHtml };