UNPKG

@matechat/core

Version:

前端智能化场景解决方案UI库,轻松构建你的AI应用。

711 lines (710 loc) 35.1 kB
import "./index.css"; import { defineComponent as le, ref as x, computed as W, watch as k, nextTick as Z, onMounted as ce, createElementBlock as v, openBlock as C, normalizeClass as b, renderSlot as R, createVNode as ye, createElementVNode as M, toDisplayString as K, createCommentVNode as O, unref as L, Transition as fe, withCtx as Me, withDirectives as Ce, vShow as we, isVNode as ae, h as f, useSlots as ve, Fragment as A, createBlock as Le, resolveDynamicComponent as Ne } from "vue"; import D from "highlight.js"; import Ie from "markdown-it"; import { debounce as De } from "lodash-es"; import { getDefaultWhiteList as xe, getDefaultCSSWhiteList as Te, filterXSS as Ae } from "xss"; import { useMcI18n as be } from "@matechat/core/Locale"; const ke = "data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='UTF-8'?%3e%3csvg%20width='16px'%20height='16px'%20viewBox='0%200%2016%2016'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3ctitle%3eenlarge%3c/title%3e%3cg%20id='enlarge'%20stroke='none'%20stroke-width='1'%20fill='none'%20fill-rule='evenodd'%3e%3cpath%20d='M7.16666667,1%20C10.572409,1%2013.3333333,3.76092429%2013.3333333,7.16666667%20C13.3333333,8.68984984%2012.781084,10.0840543%2011.8658888,11.1599767%20L14.4225201,13.7154466%20C14.6177822,13.9107088%2014.6177822,14.2272912%2014.4225201,14.4225534%20C14.2489537,14.5961197%2013.9795293,14.6154049%2013.7846612,14.4804088%20L13.7154133,14.4225534%20L11.158968,11.8667467%20C10.083183,12.7814291%208.68937384,13.3333333%207.16666667,13.3333333%20C3.76092429,13.3333333%201,10.572409%201,7.16666667%20C1,3.76092429%203.76092429,1%207.16666667,1%20Z%20M7.16666667,2%20C4.31320904,2%202,4.31320904%202,7.16666667%20C2,10.0201243%204.31320904,12.3333333%207.16666667,12.3333333%20C10.0201243,12.3333333%2012.3333333,10.0201243%2012.3333333,7.16666667%20C12.3333333,4.31320904%2010.0201243,2%207.16666667,2%20Z%20M7.16666667,4.66666667%20C7.41212656,4.66666667%207.61627504,4.84354183%207.658611,5.07679103%20L7.66666667,5.16666667%20L7.666,6.668%20L9.16601582,6.66666666%20C9.44215796,6.66630764%209.66630679,6.88987368%209.66666668,7.16601582%20C9.66698576,7.4114755%209.49037648,7.61585405%209.25718258,7.65849359%20L9.16731751,7.66666666%20L7.666,7.668%20L7.66666667,9.16666667%20C7.66666667,9.44280904%207.44280904,9.66666667%207.16666667,9.66666667%20C6.92120678,9.66666667%206.7170583,9.48979151%206.67472234,9.2565423%20L6.66666667,9.16666667%20L6.666,7.669%20L5.17251751,7.67186668%20C4.89637537,7.6722257%204.67222654,7.44865965%204.67186666,7.17251751%20C4.67154758,6.92705783%204.84815685,6.72267929%205.08135075,6.68003974%20L5.17121582,6.67186709%20L6.666,6.669%20L6.66666667,5.16666667%20C6.66666667,4.89052429%206.89052429,4.66666667%207.16666667,4.66666667%20Z'%20id='形状结合'%20fill='%2371757F'%20fill-rule='nonzero'%3e%3c/path%3e%3c/g%3e%3c/svg%3e", je = "data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='UTF-8'?%3e%3csvg%20width='16px'%20height='16px'%20viewBox='0%200%2016%2016'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3ctitle%3ezoom-out%3c/title%3e%3cg%20id='zoom-out'%20stroke='none'%20stroke-width='1'%20fill='none'%20fill-rule='evenodd'%3e%3cpath%20d='M7.16666667,1%20C10.572409,1%2013.3333333,3.76092429%2013.3333333,7.16666667%20C13.3333333,8.68984984%2012.781084,10.0840543%2011.8658888,11.1599767%20L14.4225201,13.7154466%20C14.6177822,13.9107088%2014.6177822,14.2272912%2014.4225201,14.4225534%20C14.2489537,14.5961197%2013.9795293,14.6154049%2013.7846612,14.4804088%20L13.7154133,14.4225534%20L11.158968,11.8667467%20C10.083183,12.7814291%208.68937384,13.3333333%207.16666667,13.3333333%20C3.76092429,13.3333333%201,10.572409%201,7.16666667%20C1,3.76092429%203.76092429,1%207.16666667,1%20Z%20M7.16666667,2%20C4.31320904,2%202,4.31320904%202,7.16666667%20C2,10.0201243%204.31320904,12.3333333%207.16666667,12.3333333%20C10.0201243,12.3333333%2012.3333333,10.0201243%2012.3333333,7.16666667%20C12.3333333,4.31320904%2010.0201243,2%207.16666667,2%20Z%20M9.16601582,6.66666666%20C9.44215796,6.66630764%209.66630679,6.88987368%209.66666668,7.16601582%20C9.66698576,7.4114755%209.49037648,7.61585405%209.25718258,7.65849359%20L9.16731751,7.66666666%20L5.17251751,7.67186668%20C4.89637537,7.6722257%204.67222654,7.44865965%204.67186666,7.17251751%20C4.67154758,6.92705783%204.84815685,6.72267929%205.08135075,6.68003974%20L5.17121582,6.67186709%20L9.16601582,6.66666666%20Z'%20id='形状结合'%20fill='%2371757F'%20fill-rule='nonzero'%3e%3c/path%3e%3c/g%3e%3c/svg%3e", Se = "data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='UTF-8'?%3e%3csvg%20width='16px'%20height='16px'%20viewBox='0%200%2016%2016'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3ctitle%3ei下载%3c/title%3e%3cg%20id='页面-1'%20stroke='none'%20stroke-width='1'%20fill='none'%20fill-rule='evenodd'%3e%3cg%20id='i下载'%3e%3cpath%20d='M14.5,14%20C14.7761424,14%2015,14.2238576%2015,14.5%20C15,14.7761424%2014.7761424,15%2014.5,15%20L1.5,15%20C1.22385763,15%201,14.7761424%201,14.5%20C1,14.2238576%201.22385763,14%201.5,14%20L14.5,14%20Z%20M8,1%20C8.24545989,1%208.44960837,1.17687516%208.49194433,1.41012437%20L8.5,1.5%20L8.5,10.793%20L11.6464466,7.64644661%20C11.820013,7.47288026%2012.0894374,7.45359511%2012.2843055,7.58859116%20L12.3535534,7.64644661%20C12.5271197,7.82001296%2012.5464049,8.08943736%2012.4114088,8.2843055%20L12.3535534,8.35355339%20L8.35355339,12.3535534%20L8.34128643,12.3654113%20C8.32881868,12.3770608%208.31575424,12.3880797%208.30214392,12.3984173%20L8.35355339,12.3535534%20C8.32671912,12.3803877%208.29759357,12.4035342%208.26680652,12.422993%20C8.25568247,12.4299807%208.24404667,12.4367067%208.23212724,12.4429657%20C8.21827569,12.4502504%208.20453886,12.4566485%208.1905951,12.4623894%20C8.17802507,12.4675915%208.16473685,12.4724419%208.15119917,12.4767316%20C8.13583471,12.481552%208.12047425,12.4856039%208.10498705,12.4889143%20C8.09430622,12.4912471%208.08325248,12.4932298%208.07207924,12.494843%20C8.05487076,12.4972949%208.03773477,12.498877%208.02056948,12.4995793%20C8.01375728,12.4998604%208.00689494,12.5%208,12.5%20L7.98043349,12.4996194%20C7.96293275,12.4989382%207.94546098,12.4973429%207.92809589,12.4948333%20L8,12.5%20C7.96390296,12.5%207.92869933,12.4961748%207.89477235,12.4889078%20C7.87952575,12.4856039%207.86416529,12.481552%207.84898836,12.4767587%20C7.83526315,12.4724419%207.82197493,12.4675915%207.80896344,12.4622078%20C7.79546114,12.4566485%207.78172431,12.4502504%207.76824181,12.443195%20C7.75595333,12.4367067%207.74431753,12.4299807%207.73298968,12.422812%20C7.72729809,12.4192668%207.72146362,12.4154054%207.7156945,12.4114088%20L7.69785608,12.3984173%20C7.68424576,12.3880797%207.67118132,12.3770608%207.65871357,12.3654113%20L7.64644661,12.3535534%20L3.64644661,8.35355339%20C3.45118446,8.15829124%203.45118446,7.84170876%203.64644661,7.64644661%20C3.82001296,7.47288026%204.08943736,7.45359511%204.2843055,7.58859116%20L4.35355339,7.64644661%20L7.5,10.793%20L7.5,1.5%20C7.5,1.22385763%207.72385763,1%208,1%20Z'%20id='形状结合'%20fill='%2371757F'%3e%3c/path%3e%3c/g%3e%3c/g%3e%3c/svg%3e", Oe = "data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='UTF-8'?%3e%3csvg%20width='16px'%20height='16px'%20viewBox='0%200%2016%2016'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3ctitle%3e全部收起%3c/title%3e%3cg%20id='全部收起'%20stroke='none'%20stroke-width='1'%20fill='none'%20fill-rule='evenodd'%3e%3cpath%20d='M4.715694,14.4114091%20C4.910563,14.5464051%205.179987,14.5271201%205.353553,14.3535531%20L5.353553,14.3535531%20L7.99999988,11.7070001%20L10.646447,14.3535531%20L10.715694,14.4114091%20C10.910563,14.5464051%2011.179987,14.5271201%2011.353553,14.3535531%20C11.548816,14.1582911%2011.548816,13.8417091%2011.353553,13.6464471%20L11.353553,13.6464471%20L8.353553,10.6464471%20L8.284306,10.5885911%20C8.089437,10.4535951%207.820013,10.4728801%207.646447,10.6464471%20L7.646447,10.6464471%20L4.646447,13.6464471%20L4.588591,13.7156941%20C4.453595,13.9105631%204.47288,14.1799871%204.646447,14.3535531%20L4.646447,14.3535531%20L4.715694,14.4114091%20Z%20M14.5,7.50000012%20C14.776142,7.50000012%2015,7.72385812%2015,8.00000012%20C15,8.27614212%2014.776142,8.50000012%2014.5,8.50000012%20L1.5,8.50000012%20C1.223858,8.50000012%201,8.27614212%201,8.00000012%20C1,7.72385812%201.223858,7.50000012%201.5,7.50000012%20L14.5,7.50000012%20Z%20M8.284306,5.41140912%20L8.353553,5.35355312%20L11.353553,2.35355312%20C11.548816,2.15829112%2011.548816,1.84170912%2011.353553,1.64644712%20C11.179987,1.47288012%2010.910563,1.45359512%2010.715694,1.58859112%20L10.646447,1.64644712%20L7.99999988,4.29300012%20L5.353553,1.64644712%20C5.179987,1.47288012%204.910563,1.45359512%204.715694,1.58859112%20L4.646447,1.64644712%20C4.47288,1.82001312%204.453595,2.08943712%204.588591,2.28430612%20L4.646447,2.35355312%20L7.646447,5.35355312%20C7.820013,5.52712012%208.089437,5.54640512%208.284306,5.41140912%20Z'%20id='形状结合'%20fill='%2371757F'%20fill-rule='nonzero'%3e%3c/path%3e%3c/g%3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wMTI0IEw1OTcsMjA3LjUgTDU5NywyMDggTDYwMi41LDIwOCBDNjAzLjI3OTY5NiwyMDggNjAzLjkyMDQ0OSwyMDguNTk0ODg4IDYwMy45OTMxMzMsMjA5LjM1NTU0IEw2MDQsMjA5LjUgTDYwNCwyMTUgTDYwNC41LDIxNSBDNjA0Ljc0NTQ2LDIxNSA2MDQuOTQ5NjA4LDIxNC44MjMxMjUgNjA0Ljk5MTk0NCwyMTQuNTg5ODc2IEw2MDUsMjE0LjUgTDYwNSwyMDcuNSBDNjA1LDIwNy4yNTQ1NCA2MDQuODIzMTI1LDIwNy4wNTAzOTIgNjA0LjU4OTg3NiwyMDcuMDA4MDU2IEw2MDQuNSwyMDcgWiIgaWQ9IuW9oueKtue7k+WQiCIgZmlsbD0iIzcxNzU3RiIgZmlsbC1ydWxlPSJub256ZXJvIj48L3BhdGg+CiAgICAgICAgPC9nPgogICAgPC9nPgo8L3N2Zz4=", Be = "data:image/svg+xml,%3c?xml%20version='1.0'%20encoding='UTF-8'?%3e%3csvg%20width='16px'%20height='16px'%20viewBox='0%200%2016%2016'%20version='1.1'%20xmlns='http://www.w3.org/2000/svg'%20xmlns:xlink='http://www.w3.org/1999/xlink'%3e%3ctitle%3estatus/whiteBG/correct%3c/title%3e%3cdesc%3eCreated%20with%20Sketch.%3c/desc%3e%3cdefs%3e%3cpolygon%20id='path-1'%20points='6.53553391%209.77817459%2012.1923882%204.12132034%2013.6066017%205.53553391%206.53553391%2012.6066017%203%209.07106781%204.41421356%207.65685425%206.53553391%209.77817459'%3e%3c/polygon%3e%3c/defs%3e%3cg%20id='status/whiteBG/correct'%20stroke='none'%20stroke-width='1'%20fill='none'%20fill-rule='evenodd'%3e%3cmask%20id='mask-2'%20fill='white'%3e%3cuse%20xlink:href='%23path-1'%3e%3c/use%3e%3c/mask%3e%3cuse%20id='Mask'%20fill='%233DCCA6'%20xlink:href='%23path-1'%3e%3c/use%3e%3c/g%3e%3c/svg%3e"; class de { constructor() { this.xssWhiteList = xe(), this.cssWhiteList = Te(), this.setDefaultXss(); } setDefaultXss() { this.xssWhiteList.input = ["type", "checked", "disabled", "class"], this.xssWhiteList.label = ["for"], this.xssWhiteList.ul = ["class"], this.xssWhiteList.div = ["class"], this.xssWhiteList.a = ["href", "class", "target", "name"], this.xssWhiteList.ol = ["start"], this.xssWhiteList.p = ["class"], this.xssWhiteList.span = ["style", "class", "title", "id"], this.xssWhiteList.svg = ["style", "class", "width", "height", "viewbox", "preserveaspectratio", "id", "fill", "stroke"], this.xssWhiteList.path = ["style", "class", "d", "id", "fill", "stroke"], this.xssWhiteList.th = ["style"], this.xssWhiteList.td = ["style"]; } onIgnoreTagAttr(s, r, a, n) { if (!n && (r === "id" || s === "span" && r === "style")) return r + "=" + a; } getXssWhiteList() { return this.xssWhiteList; } setXssWhiteList(s) { this.xssWhiteList = s; } setCustomXssRules(s) { s && s.forEach((r) => { r.value === null ? delete this.xssWhiteList[r.key] : this.xssWhiteList[r.key] = r.value; }); } setMdPlugins(s, r) { s && s.length && s.forEach((a) => { const { plugin: n, opts: g } = a; r.use(n, g); }); } filterHtml(s) { return Ae(s, { whiteList: this.xssWhiteList, onIgnoreTagAttr: this.onIgnoreTagAttr, css: { whiteList: Object.assign({}, this.cssWhiteList, { top: !0, left: !0, bottom: !0, right: !0 }) } }); } } const Ue = { key: 0, class: "mc-code-block-header" }, _e = { class: "mc-code-lang" }, ze = { class: "mc-code-block-actions" }, We = { key: 0, style: { "margin-right": "8px" } }, Ze = ["title"], Ye = ["title"], Pe = ["title"], Qe = ["title"], Ge = ["title"], He = { key: 0, src: Ee }, Fe = { key: 1, src: Be }, $e = { key: 0, class: "mc-mermaid-content" }, Xe = { key: 1 }, Re = ["innerHTML"], Ke = /* @__PURE__ */ le({ __name: "CodeBlock", props: { code: { type: String, required: !0 }, language: { type: String, default: "" }, blockIndex: { type: Number, required: !0 }, theme: { type: String, default: "light" }, enableMermaid: { type: Boolean, default: !1 }, mermaidConfig: { type: Object, default: () => ({}) } }, setup(i) { const s = i, { t: r } = be(), a = new de(); let n = null; const g = x(!0), d = x(!1); x(""); const l = x(!0), c = W(() => { var t; return s.enableMermaid && ((t = s.language) == null ? void 0 : t.toLowerCase()) === "mermaid"; }), h = W(() => { try { const t = s.code.indexOf('<span class="mc-typewriter'); let e; return s.language && D.getLanguage(s.language) ? t !== -1 ? e = D.highlight(s.code.slice(0, t), { language: s.language }).value + s.code.slice(t) : e = D.highlight(s.code, { language: s.language }).value : typeof D.highlightAuto !== void 0 ? t !== -1 ? e = D.highlightAuto(s.code.slice(0, t)).value + s.code.slice(t) : e = D.highlightAuto(s.code).value : e = a.filterHtml(s.code), e; } catch { } }), w = x(null), E = () => { var e; const t = (e = w.value) == null ? void 0 : e.querySelector(".mc-mermaid-content"); t && n && n.zoomIn(t); }, N = () => { var e; const t = (e = w.value) == null ? void 0 : e.querySelector(".mc-mermaid-content"); t && n && n.zoomOut(t); }, P = () => { var e; const t = (e = w.value) == null ? void 0 : e.querySelector(".mc-mermaid-content"); t && n && n.download(t); }, I = async () => { if (!(!c.value || !s.code)) { if (!n) try { const { MermaidService: t } = await import("./MermaidService-B6BcjbW_.js"), e = { theme: s.theme === "dark" ? "dark" : "default", ...s.mermaidConfig }; n = new t(e); } catch (t) { console.error("Failed to load MermaidService:", t); return; } Z(async () => { var e; const t = (e = w.value) == null ? void 0 : e.querySelector(".mc-mermaid-content"); t && await n.renderToContainer(t, s.code.replace(/<span[^>]*\bclass\s*=\s*['"]mc-typewriter[^>]*>([\s\S]*?)<\/span>/g, "$1"), s.theme); }); } }, Q = () => { g.value = !g.value; }, B = De((t) => { const e = t.target; if (navigator.clipboard) navigator.clipboard.writeText(s.code); else { const o = document.createElement("textarea"); o.style.position = "fixed", o.style.top = "-9999px", o.style.left = "-9999px", o.style.zIndex = "-1", o.value = s.code, document.body.appendChild(o), o.select(), document.execCommand("copy"), document.body.removeChild(o); } e.classList.remove("icon-copy-new"), d.value = !0, setTimeout(() => { d.value = !1; }, 1500); }, 300), G = (t) => { t.dataset || (t.dataset = {}), t.style.height && (t.dataset.height = t.style.height), t.style.maxHeight = 0; }, H = (t) => { requestAnimationFrame(() => { t.dataset.oldOverflow = t.style.overflow, t.dataset.height ? t.style.maxHeight = t.dataset.height : t.scrollHeight !== 0 ? t.style.maxHeight = `${t.scrollHeight}px` : t.style.maxHeight = 0, t.style.overflow = "hidden"; }); }, U = (t) => { t.style.maxHeight = "", t.style.overflow = t.dataset.oldOverflow; }, j = (t) => { t.dataset || (t.dataset = {}), t.dataset.oldOverflow = t.style.overflow, t.style.maxHeight = `${t.scrollHeight}px`, t.style.overflow = "hidden"; }, F = (t) => { t.scrollHeight !== 0 && (t.style.maxHeight = 0); }, $ = (t) => { t.style.maxHeight = "", t.style.overflow = t.dataset.oldOverflow; }, X = W(() => s.theme === "dark" ? "mc-code-block-dark" : "mc-code-block-light"); return k(() => [s.code, s.theme, s.enableMermaid], () => { c.value && Z(() => { I(); }); }, { immediate: !0 }), k( () => l.value, (t) => { t && c.value && Z(() => { I(); }); } ), ce(() => { c.value && I(); }), (t, e) => (C(), v( "div", { class: b(["mc-code-block", X.value]), ref_key: "rootRef", ref: w }, [ t.$slots.header ? R(t.$slots, "header", { key: 1 }, void 0, !0) : (C(), v("div", Ue, [ M( "span", _e, K(i.language), 1 /* TEXT */ ), R(t.$slots, "actions", {}, () => [ M("div", ze, [ c.value ? (C(), v("div", We, [ M( "ul", { class: b(["mc-diagram-switch", { "mc-show-code": !l.value }]) }, [ M( "li", { onClick: e[0] || (e[0] = (o) => l.value = !0), class: b({ "mc-diagram-switch-active": l.value }) }, K(L(r)("Md.diagram")), 3 /* TEXT, CLASS */ ), M( "li", { onClick: e[1] || (e[1] = (o) => l.value = !1), class: b({ "mc-diagram-switch-active": !l.value }) }, K(L(r)("Md.code")), 3 /* TEXT, CLASS */ ) ], 2 /* CLASS */ ) ])) : O("v-if", !0), c.value && l.value ? (C(), v("div", { key: 1, class: "mc-action-btn mc-toggle-btn", title: L(r)("Md.zoomIn"), onClick: E }, e[3] || (e[3] = [ M( "img", { src: ke }, null, -1 /* HOISTED */ ) ]), 8, Ze)) : O("v-if", !0), c.value && l.value ? (C(), v("div", { key: 2, class: "mc-action-btn mc-toggle-btn", title: L(r)("Md.zoomOut"), onClick: N }, e[4] || (e[4] = [ M( "img", { src: je }, null, -1 /* HOISTED */ ) ]), 8, Ye)) : O("v-if", !0), c.value && l.value ? (C(), v("div", { key: 3, class: "mc-action-btn mc-toggle-btn", title: L(r)("Md.downLoad"), onClick: P }, e[5] || (e[5] = [ M( "img", { src: Se }, null, -1 /* HOISTED */ ) ]), 8, Pe)) : O("v-if", !0), M("div", { class: "mc-action-btn mc-toggle-btn", title: L(r)("Md.toggle"), onClick: Q }, e[6] || (e[6] = [ M( "img", { src: Oe }, null, -1 /* HOISTED */ ) ]), 8, Qe), M("div", { class: "mc-action-btn mc-copy-btn", title: L(r)("Md.copy"), onClick: e[2] || (e[2] = //@ts-ignore (...o) => L(B) && L(B)(...o)) }, [ d.value ? (C(), v("img", Fe)) : (C(), v("img", He)) ], 8, Ge) ]) ], !0) ])), ye(fe, { name: "collapse-transition", onBeforeEnter: G, onEnter: H, onAfterEnter: U, onBeforeLeave: j, onLeave: F, onAfterLeave: $, persisted: "" }, { default: Me(() => [ Ce(M( "div", null, [ c.value && l.value && !t.$slots.content ? (C(), v("div", $e)) : t.$slots.content ? R(t.$slots, "content", { key: 2 }, void 0, !0) : (C(), v("pre", Xe, [ M("code", { class: b(`hljs language-${i.language}`), innerHTML: h.value }, null, 10, Re) ])) ], 512 /* NEED_PATCH */ ), [ [we, g.value] ]) ]), _: 3 /* FORWARDED */ }) ], 2 /* CLASS */ )); } }), ge = (i, s) => { const r = i.__vccOpts || i; for (const [a, n] of s) r[a] = n; return r; }, Ve = /* @__PURE__ */ ge(Ke, [["__scopeId", "data-v-6332bb90"]]), oe = { step: 2, interval: 50, style: "normal" }, Je = { content: { type: String, default: "" }, typing: { type: Boolean, default: !1 }, enableThink: { type: Boolean, default: !1 }, typingOptions: { step: { type: Number, default: 2 }, interval: { type: [Number, Array], default: 60 }, style: { type: String, default: "normal" } }, thinkOptions: { customClass: { type: String, default: "" } }, mdOptions: { type: Object, default: () => ({}) }, mdPlugins: { type: Array, default: () => [] }, customXssRules: { type: Array, default: () => [] }, theme: { type: String, default: "light" }, enableMermaid: { type: Boolean, default: !1 }, mermaidConfig: { type: Object, default: () => ({}) } }, qe = (i, s) => { const r = (i == null ? void 0 : i.content) || "", a = (s == null ? void 0 : s.content) || "", n = r.match(/<(\w+)/), g = a.match(/<\/(\w+)/); return n && g ? n[1] === g[1] : !1; }, et = (i) => { const s = i.content || ""; if (s.match(/<(\w+)[^>]*\/>/)) return !0; const r = [], a = /<(\w+)[^>]*>/g, n = /<\/(\w+)>/g; let g, d; a.lastIndex = 0, n.lastIndex = 0; const l = []; for (; (g = a.exec(s)) !== null; ) l.push({ type: "open", tagName: g[1], index: g.index }); for (; (d = n.exec(s)) !== null; ) l.push({ type: "close", tagName: d[1], index: d.index }); l.sort((c, h) => c.index - h.index); for (const c of l) if (c.type === "open") r.push(c.tagName); else { if (r.length === 0 || r[r.length - 1] !== c.tagName) return !1; r.pop(); } return r.length === 0; }, V = (i) => ({ nodeType: i ? i.type.replace("_open", "") : "root", openNode: i, closeNode: null, children: [], vNodeKey: (i == null ? void 0 : i.vNodeKey) || "" }), tt = (i, s) => { const r = i.content.startsWith("</"); if (!s.length) { i.nesting = r ? 0 : 1, s.push(i); return; } const a = s[s.length - 1]; qe(a, i) ? (i.nesting = -1, s.pop()) : r ? i.nesting = 0 : (i.nesting = 1, s.push(i)); }, ue = (i) => { const s = (l) => { const c = V(l); return l.children && l.children.length > 0 && (c.children = ue(l.children)), c; }, r = V(null); let a = r; const n = [], g = [], d = []; return i.forEach((l, c) => { if (l.vNodeKey = `mc-markdown-content-key-${c}`, l.tokenIndex = c, l.type.includes("html_")) { if (et(l)) { l.nesting = 0; return; } const h = l.type === "html_block" ? d : g; tt(l, h); } }), i.forEach((l, c) => { let h; if (l.nesting === 1) h = V(l), a.children.push(h), n.push(a), a = h; else if (l.nesting === -1) { if (a.closeNode = l, !n.length) throw new Error("AST stack underflow."); h = n.pop(), a = h; } else if (l.nesting === 0) if (l.type === "inline" && l.children && l.children.length > 0) { const w = s(l); a.children.push(w); } else a.children.push(l); else throw new Error(`Invalid nesting level found in token index ${c}.`); }), r.children; }, z = (i) => { if (!i || !i.trim()) return []; if (typeof window > "u" || typeof DOMParser > "u") return [i]; const r = new DOMParser().parseFromString(`<body>${i}</body>`, "text/html"), a = []; return r.body.childNodes.forEach((n, g) => { const d = he(n); (ae(d) || typeof d == "string") && (typeof d == "object" && (d.key = g), a.push(d)); }), a; }, he = (i) => { if (i.nodeType === Node.TEXT_NODE) return i.textContent; if (i.nodeType !== Node.ELEMENT_NODE) return i.textContent || ""; const s = i, r = {}; if (s.hasAttributes() && s.attributes) for (const n of Array.from(s.attributes)) r[n.name] = n.value; const a = []; return s.childNodes.length > 0 && s.childNodes.forEach((n) => { const g = he(n); (ae(g) || typeof g == "string") && a.push(g); }), Y(s.tagName) ? f(s.tagName.toLowerCase(), r, a) : (i == null ? void 0 : i.textContent) || ""; }, Y = (i) => { if (!i) return !1; try { return document.createElement(i), !0; } catch { return !1; } }, st = /* @__PURE__ */ le({ __name: "mdCard", props: Je, emits: ["afterMdtInit", "typingStart", "typing", "typingEnd"], setup(i, { expose: s, emit: r }) { const a = new de(), n = i, g = r, d = ve(); let l = null; const c = Ie({ breaks: !0, linkify: !0, html: !0, highlight: (e, o) => { if (o && D.getLanguage(o)) try { return D.highlight(e, { language: o }).value; } catch { } return ""; }, ...n.mdOptions }), h = x(0), w = x(!1), E = x(), N = () => { var m; let e = n.content || ""; if (n.typing && w.value) { e = n.content.slice(0, h.value) || ""; const p = { ...oe, ...n == null ? void 0 : n.typingOptions }; p.style === "cursor" ? e += '<span class="mc-typewriter mc-typewriter-cursor">|</span>' : (p.style === "color" || p.style === "gradient") && (e = e.slice(0, -5) + `<span class="mc-typewriter mc-typewriter-${p.style}">${e.slice(-5)}</span>`); } if (n.enableThink) { const p = ((m = n.thinkOptions) == null ? void 0 : m.customClass) || "mc-think-block"; e = (e == null ? void 0 : e.replace("<think>", `<div class="${p}">`).replace("</think>", "</div>")) || ""; } const o = c.parse(e, {}), u = ue(o), y = P(u); E.value = f(A, y); }, P = (e) => e.map((o) => I(o)), I = (e) => { var o, u; if (e.nodeType === "html_inline" || e.nodeType === "html_block") { const y = z(((o = e.openNode) == null ? void 0 : o.content) || ""); if (!y || y.length === 0) return f("span", ((u = e.openNode) == null ? void 0 : u.content) || ""); const m = y.map((p) => { if (typeof p == "string") return f("span", p); const S = e.children.map((T) => I(T)); return Array.isArray(p.children) ? p.children = [...p.children, ...S] : p.children = [p.children, ...S].filter((T) => T), p; }); return f(A, m); } if (e.nodeType === "inline") { const y = c.renderer.render([e.openNode], c.options, {}), m = z(y); return f(A, m); } return Q(e) ? B(e) : H(e); }, Q = (e) => "type" in e && "content" in e, B = (e) => { if (e.type === "text") return e.content; if (e.type === "inline") return G(e); if (e.type === "fence") return U(e); if (e.type === "softbreak") return c.options.breaks ? f("br") : ` `; if (e.type === "html_block" || e.type === "html_inline") return e.type === "html_block" ? f("div", { innerHTML: e.content }) : f("span", { innerHTML: e.content }); if (e.type === "math_block" && e.markup === "$$") { const o = c.renderer.render([e], c.options, {}), u = z(o); return f(A, u); } if (e.tag) { const o = Y(e.tag) ? e.tag : "div", u = j(e.attrs || []); return f(o, { ...u, key: e.vNodeKey }, e.content); } return e.content; }, G = (e) => { const o = c.renderer.render([e], c.options, {}), u = z(o); return f(A, u); }, H = (e) => { var m, p, S, T, J, q, ee, te, se; let o = "div"; (m = e.openNode) != null && m.tag && Y((p = e.openNode) == null ? void 0 : p.tag) && (o = (S = e.openNode) == null ? void 0 : S.tag); const u = j(((T = e.openNode) == null ? void 0 : T.attrs) || []); if (((J = e.openNode) == null ? void 0 : J.type) === "fence") return U(e.openNode); if ((q = e.openNode) != null && q.tag) { let _ = Y((ee = e.openNode) == null ? void 0 : ee.tag) ? (te = e.openNode) == null ? void 0 : te.tag : "div"; const me = e.children.map((ie) => I(ie)), pe = j(((se = e.openNode) == null ? void 0 : se.attrs) || []), ne = f(_, { ...pe, key: e.vNodeKey }, me); return _ === "table" ? f("div", { className: "mc-table-container", key: `${e.vNodeKey}-table-container` }, [ne]) : ne; } const y = e.children.map((_) => I(_)); return f(o, { ...u, key: e.vNodeKey }, y); }, U = (e) => { var y; const o = ((y = e.info) == null ? void 0 : y.replace(/<span\b[^>]*>/i, "").replace("</span>", "")) || "", u = e.content; return F(o, u, e.tokenIndex); }, j = (e) => e.reduce((o, [u, y]) => (o[u] = y, o), {}); k( () => { var e; return [n.enableThink, (e = n.thinkOptions) == null ? void 0 : e.customClass, n.theme]; }, () => { N(); } ); const F = (e, o, u) => { const y = { actions: d.actions ? () => { var m; return ((m = d.actions) == null ? void 0 : m.call(d, { codeBlockData: { code: o, language: e } })) || null; } : void 0, header: d.header ? () => { var m; return ((m = d.header) == null ? void 0 : m.call(d, { codeBlockData: { code: o, language: e } })) || null; } : void 0, content: d.content ? () => { var m; return ((m = d.content) == null ? void 0 : m.call(d, { codeBlockData: { code: o, language: e } })) || null; } : void 0 }; return f( Ve, { language: e, code: o, blockIndex: u, theme: n.theme, enableMermaid: n.enableMermaid, mermaidConfig: n.mermaidConfig, key: `code-block-${u}` }, y ); }, $ = () => { clearTimeout(l), w.value = !0, g("typingStart"); const e = { ...oe, ...n == null ? void 0 : n.typingOptions }, o = () => { let u = e.step; if (Array.isArray(e.step) && (u = e.step[0] + Math.floor(Math.random() * (e.step[1] - e.step[0]))), h.value += u, N(), g("typing"), h.value >= n.content.length) { X(), N(); return; } l = setTimeout(o, e.interval); }; l = setTimeout(o); }; k( () => n.content, (e, o) => { if (!n.typing) { h.value = (e == null ? void 0 : e.length) || 0, N(); return; } e.indexOf(o) === -1 && (h.value = 0), Z(() => $()); }, { immediate: !0 } ); const X = () => { w.value = !1, g("typingEnd"); }; k( () => n.customXssRules, (e) => { a.setCustomXssRules(e), N(); }, { deep: !1 } ), k( () => n.mdPlugins, (e) => { a.setMdPlugins(e, c), N(); }, { immediate: !0, deep: !1 } ); const t = W(() => n.theme === "dark" ? "mc-markdown-render-dark" : "mc-markdown-render-light"); return ce(() => { g("afterMdtInit", c); }), s({ mdt: c }), (e, o) => (C(), v( A, null, [ M( "div", { class: b(["mc-markdown-render", t.value]) }, [ (C(), Le(Ne(E.value))) ], 2 /* CLASS */ ), O("v-if", !0) ], 64 /* STABLE_FRAGMENT */ )); } }), re = /* @__PURE__ */ ge(st, [["__scopeId", "data-v-f0759799"]]); re.install = (i) => { i.component("McMarkdownCard", re); }; export { re as McMarkdownCard };