@matechat/core
Version:
前端智能化场景解决方案UI库,轻松构建你的AI应用。
890 lines (887 loc) • 39.8 kB
JavaScript
import "./index.css";
var ve = Object.defineProperty;
var Ne = (o, t, s) => t in o ? ve(o, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : o[t] = s;
var I = (o, t, s) => Ne(o, typeof t != "symbol" ? t + "" : t, s);
import { defineComponent as de, ref as x, computed as G, watch as O, nextTick as U, onMounted as ge, openBlock as C, createElementBlock as M, normalizeClass as E, createElementVNode as w, toDisplayString as V, renderSlot as q, unref as T, createCommentVNode as P, createVNode as Me, Transition as Le, withCtx as Ie, withDirectives as Te, vShow as xe, isVNode as ue, h as y, reactive as De, onBeforeUnmount as ke, useSlots as Ae, Fragment as j, createBlock as Se, resolveDynamicComponent as be } from "vue";
import k from "highlight.js";
import je from "markdown-it";
import { debounce as Ee } from "lodash-es";
import { getDefaultWhiteList as Oe, getDefaultCSSWhiteList as _e, filterXSS as ze } from "xss";
import { useMcI18n as pe } from "@matechat/core/Locale";
const 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%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", Pe = "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", Ue = "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", Ye = "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%3e%3c/svg%3e", We = "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4NCjxzdmcgd2lkdGg9IjE2cHgiIGhlaWdodD0iMTZweCIgdmlld0JveD0iMCAwIDE2IDE2IiB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiPg0KICAgIDx0aXRsZT5mdW5jdGlvbiBpY29uL2NvcHk8L3RpdGxlPg0KICAgIDxnIGlkPSLpobXpnaItMSIgc3Ryb2tlPSJub25lIiBzdHJva2Utd2lkdGg9IjEiIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCI+DQogICAgICAgIDxnIGlkPSJBUEktc3RhcnRlci3lm77moIflhaXlupMiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC01OTIuMDAwMDAwLCAtMjA0LjAwMDAwMCkiPg0KICAgICAgICAgICAgPGcgaWQ9IuaWueagvOWkh+S7vS0xNiIgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoNTYwLjAwMDAwMCwgMTgwLjAwMDAwMCkiPg0KICAgICAgICAgICAgICAgIDx0ZXh0IGlkPSLlm77moIciIGZvbnQtZmFtaWx5PSJQaW5nRmFuZ1NDLVJlZ3VsYXIsIFBpbmdGYW5nIFNDIiBmb250LXNpemU9IjEyIiBmb250LXdlaWdodD0ibm9ybWFsIiBsaW5lLXNwYWNpbmc9IjE2IiBmaWxsPSIjNzE3NTdGIj4NCiAgICAgICAgICAgICAgICAgICAgPHRzcGFuIHg9IjI3LjEzNiIgeT0iNjEiPuWkjeWItjwvdHNwYW4+DQogICAgICAgICAgICAgICAgPC90ZXh0Pg0KICAgICAgICAgICAgPC9nPg0KICAgICAgICAgICAgPHBhdGggZD0iTTYwNC41LDIwNiBDNjA1LjI3OTY5NiwyMDYgNjA1LjkyMDQ0OSwyMDYuNTk0ODg4IDYwNS45OTMxMzMsMjA3LjM1NTU0IEw2MDYsMjA3LjUgTDYwNiwyMTQuNSBDNjA2LDIxNS4yNzk2OTYgNjA1LjQwNTExMiwyMTUuOTIwNDQ5IDYwNC42NDQ0NiwyMTUuOTkzMTMzIEw2MDQuNSwyMTYgTDYwNCwyMTYgTDYwNCwyMTYuNSBDNjA0LDIxNy4yNzk2OTYgNjAzLjQwNTExMiwyMTcuOTIwNDQ5IDYwMi42NDQ0NiwyMTcuOTkzMTMzIEw2MDIuNSwyMTggTDU5NS41LDIxOCBDNTk0LjY3MTU3MywyMTggNTk0LDIxNy4zMjg0MjcgNTk0LDIxNi41IEw1OTQsMjE2LjUgTDU5NCwyMDkuNSBDNTk0LDIwOC42NzE1NzMgNTk0LjY3MTU3MywyMDggNTk1LjUsMjA4IEw1OTUuNSwyMDggTDU5NiwyMDggTDU5NiwyMDcuNSBDNTk2LDIwNi43MjAzMDQgNTk2LjU5NDg4OCwyMDYuMDc5NTUxIDU5Ny4zNTU1NCwyMDYuMDA2ODY3IEw1OTcuNSwyMDYgTDYwNC41LDIwNiBaIE02MDIuNSwyMDkgTDU5NS41LDIwOSBDNTk1LjIyMzg1OCwyMDkgNTk1LDIwOS4yMjM4NTggNTk1LDIwOS41IEw1OTUsMjA5LjUgTDU5NSwyMTYuNSBDNTk1LDIxNi43NzYxNDIgNTk1LjIyMzg1OCwyMTcgNTk1LjUsMjE3IEw1OTUuNSwyMTcgTDYwMi41LDIxNyBDNjAyLjc3NjE0MiwyMTcgNjAzLDIxNi43NzYxNDIgNjAzLDIxNi41IEw2MDMsMjE2LjUgTDYwMywyMDkuNSBDNjAzLDIwOS4yMjM4NTggNjAyLjc3NjE0MiwyMDkgNjAyLjUsMjA5IEw2MDIuNSwyMDkgWiBNNjA0LjUsMjA3IEw1OTcuNSwyMDcgQzU5Ny4yNTQ1NCwyMDcgNTk3LjA1MDM5MiwyMDcuMTc2ODc1IDU5Ny4wMDgwNTYsMjA3LjQxMDEyNCBMNTk3LDIwNy41IEw1OTcsMjA4IEw2MDIuNSwyMDggQzYwMy4yNzk2OTYsMjA4IDYwMy45MjA0NDksMjA4LjU5NDg4OCA2MDMuOTkzMTMzLDIwOS4zNTU1NCBMNjA0LDIwOS41IEw2MDQsMjE1IEw2MDQuNSwyMTUgQzYwNC43NDU0NiwyMTUgNjA0Ljk0OTYwOCwyMTQuODIzMTI1IDYwNC45OTE5NDQsMjE0LjU4OTg3NiBMNjA1LDIxNC41IEw2MDUsMjA3LjUgQzYwNSwyMDcuMjU0NTQgNjA0LjgyMzEyNSwyMDcuMDUwMzkyIDYwNC41ODk4NzYsMjA3LjAwODA1NiBMNjA0LjUsMjA3IFoiIGlkPSLlvaLnirbnu5PlkIgiIGZpbGw9IiM3MTc1N0YiIGZpbGwtcnVsZT0ibm9uemVybyI+PC9wYXRoPg0KICAgICAgICA8L2c+DQogICAgPC9nPg0KPC9zdmc+", He = "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 he {
constructor() {
I(this, "xssWhiteList", Oe());
I(this, "cssWhiteList", _e());
this.setDefaultXss();
}
setDefaultXss() {
this.xssWhiteList.input = ["type", "checked", "disabled", "class"], this.xssWhiteList.label = ["for"], this.xssWhiteList.ul = ["class"], this.xssWhiteList.div = ["class", "key"], 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"];
}
getXssWhiteList() {
return this.xssWhiteList;
}
setXssWhiteList(t) {
this.xssWhiteList = t;
}
setCustomXssRules(t) {
t && t.forEach((s) => {
s.value === null ? delete this.xssWhiteList[s.key] : this.xssWhiteList[s.key] = s.value;
});
}
setMdPlugins(t, s) {
t && t.length && t.forEach((a) => {
const { plugin: n, opts: c } = a;
s.use(n, c);
});
}
filterHtml(t) {
return ze(t, {
whiteList: this.xssWhiteList,
css: {
whiteList: Object.assign({}, this.cssWhiteList, {
top: !0,
left: !0,
bottom: !0,
right: !0
})
}
});
}
}
const Ze = {
key: 0,
class: "mc-code-block-header"
}, Ge = { class: "mc-code-lang" }, Qe = { class: "mc-code-block-actions" }, Fe = {
key: 0,
style: { "margin-right": "8px" }
}, $e = ["title"], Xe = ["title"], Re = ["title"], Ke = ["title"], Je = ["title"], Ve = {
key: 0,
src: We
}, qe = {
key: 1,
src: He
}, et = {
key: 0,
class: "mc-mermaid-content"
}, tt = { key: 2 }, st = ["innerHTML"], nt = /* @__PURE__ */ de({
__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(o) {
const t = o, { t: s } = pe(), a = new he();
let n = null;
const c = x(!0), d = x(!1);
x("");
const r = x(!0), g = G(() => {
var i;
return t.enableMermaid && ((i = t.language) == null ? void 0 : i.toLowerCase()) === "mermaid";
}), m = G(() => {
try {
const i = t.code.indexOf('<span class="mc-typewriter');
let e;
return t.language && k.getLanguage(t.language) ? i !== -1 ? e = k.highlight(t.code.slice(0, i), { language: t.language }).value + t.code.slice(i) : e = k.highlight(t.code, { language: t.language }).value : typeof k.highlightAuto !== void 0 ? i !== -1 ? e = k.highlightAuto(t.code.slice(0, i)).value + t.code.slice(i) : e = k.highlightAuto(t.code).value : e = a.filterHtml(t.code), e;
} catch {
}
}), f = x(null), D = () => {
var e;
const i = (e = f.value) == null ? void 0 : e.querySelector(".mc-mermaid-content");
i && n && n.zoomIn(i);
}, A = () => {
var e;
const i = (e = f.value) == null ? void 0 : e.querySelector(".mc-mermaid-content");
i && n && n.zoomOut(i);
}, L = () => {
var e;
const i = (e = f.value) == null ? void 0 : e.querySelector(".mc-mermaid-content");
i && n && n.download(i);
}, _ = async () => {
if (!(!g.value || !t.code)) {
if (!n)
try {
const { MermaidService: i } = await import("./MermaidService-yeLQUW_e.js"), e = {
theme: t.theme === "dark" ? "dark" : "default",
...t.mermaidConfig
};
n = new i(e);
} catch (i) {
console.error("Failed to load MermaidService:", i);
return;
}
U(async () => {
var e;
const i = (e = f.value) == null ? void 0 : e.querySelector(".mc-mermaid-content");
i && await n.renderToContainer(i, t.code.replace(/<span[^>]*\bclass\s*=\s*['"]mc-typewriter[^>]*>([\s\S]*?)<\/span>/g, "$1"), t.theme);
});
}
}, S = () => {
c.value = !c.value;
}, Y = Ee((i) => {
const e = i.target;
if (navigator.clipboard)
navigator.clipboard.writeText(t.code);
else {
const l = document.createElement("textarea");
l.style.position = "fixed", l.style.top = "-9999px", l.style.left = "-9999px", l.style.zIndex = "-1", l.value = t.code, document.body.appendChild(l), l.select(), document.execCommand("copy"), document.body.removeChild(l);
}
e.classList.remove("icon-copy-new"), d.value = !0, setTimeout(() => {
d.value = !1;
}, 1500);
}, 300), $ = (i) => {
i.dataset || (i.dataset = {}), i.style.height && (i.dataset.height = i.style.height), i.style.maxHeight = 0;
}, X = (i) => {
requestAnimationFrame(() => {
i.dataset.oldOverflow = i.style.overflow, i.dataset.height ? i.style.maxHeight = i.dataset.height : i.scrollHeight !== 0 ? i.style.maxHeight = `${i.scrollHeight}px` : i.style.maxHeight = 0, i.style.overflow = "hidden";
});
}, W = (i) => {
i.style.maxHeight = "", i.style.overflow = i.dataset.oldOverflow;
}, z = (i) => {
i.dataset || (i.dataset = {}), i.dataset.oldOverflow = i.style.overflow, i.style.maxHeight = `${i.scrollHeight}px`, i.style.overflow = "hidden";
}, R = (i) => {
i.scrollHeight !== 0 && (i.style.maxHeight = 0);
}, K = (i) => {
i.style.maxHeight = "", i.style.overflow = i.dataset.oldOverflow;
}, J = G(() => t.theme === "dark" ? "mc-code-block-dark" : "mc-code-block-light");
return O(() => [t.code, t.theme, t.enableMermaid], () => {
g.value && U(() => {
_();
});
}, { immediate: !0 }), O(
() => r.value,
(i) => {
i && g.value && U(() => {
_();
});
}
), ge(() => {
g.value && _();
}), (i, e) => (C(), M(
"div",
{
class: E(["mc-code-block", J.value]),
ref_key: "rootRef",
ref: f
},
[
i.$slots.header ? q(i.$slots, "header", { key: 1 }, void 0, !0) : (C(), M("div", Ze, [
w(
"span",
Ge,
V(o.language),
1
/* TEXT */
),
q(i.$slots, "actions", {}, () => [
w("div", Qe, [
g.value ? (C(), M("div", Fe, [
w(
"ul",
{
class: E(["mc-diagram-switch", { "mc-show-code": !r.value }])
},
[
w(
"li",
{
onClick: e[0] || (e[0] = (l) => r.value = !0),
class: E({ "mc-diagram-switch-active": r.value })
},
V(T(s)("Md.diagram")),
3
/* TEXT, CLASS */
),
w(
"li",
{
onClick: e[1] || (e[1] = (l) => r.value = !1),
class: E({ "mc-diagram-switch-active": !r.value })
},
V(T(s)("Md.code")),
3
/* TEXT, CLASS */
)
],
2
/* CLASS */
)
])) : P("v-if", !0),
g.value && r.value ? (C(), M("div", {
key: 1,
class: "mc-action-btn mc-toggle-btn",
title: T(s)("Md.zoomIn"),
onClick: D
}, e[3] || (e[3] = [
w(
"img",
{ src: Be },
null,
-1
/* HOISTED */
)
]), 8, $e)) : P("v-if", !0),
g.value && r.value ? (C(), M("div", {
key: 2,
class: "mc-action-btn mc-toggle-btn",
title: T(s)("Md.zoomOut"),
onClick: A
}, e[4] || (e[4] = [
w(
"img",
{ src: Pe },
null,
-1
/* HOISTED */
)
]), 8, Xe)) : P("v-if", !0),
g.value && r.value ? (C(), M("div", {
key: 3,
class: "mc-action-btn mc-toggle-btn",
title: T(s)("Md.downLoad"),
onClick: L
}, e[5] || (e[5] = [
w(
"img",
{ src: Ue },
null,
-1
/* HOISTED */
)
]), 8, Re)) : P("v-if", !0),
w("div", {
class: "mc-action-btn mc-toggle-btn",
title: T(s)("Md.toggle"),
onClick: S
}, e[6] || (e[6] = [
w(
"img",
{ src: Ye },
null,
-1
/* HOISTED */
)
]), 8, Ke),
w("div", {
class: "mc-action-btn mc-copy-btn",
title: T(s)("Md.copy"),
onClick: e[2] || (e[2] = //@ts-ignore
(...l) => T(Y) && T(Y)(...l))
}, [
d.value ? (C(), M("img", qe)) : (C(), M("img", Ve))
], 8, Je)
])
], !0)
])),
Me(Le, {
name: "collapse-transition",
onBeforeEnter: $,
onEnter: X,
onAfterEnter: W,
onBeforeLeave: z,
onLeave: R,
onAfterLeave: K,
persisted: ""
}, {
default: Ie(() => [
Te(w(
"div",
null,
[
g.value && r.value ? (C(), M("div", et)) : i.$slots.content ? q(i.$slots, "content", { key: 1 }, void 0, !0) : (C(), M("pre", tt, [
w("code", {
class: E(`hljs language-${o.language}`),
innerHTML: m.value
}, null, 10, st)
]))
],
512
/* NEED_PATCH */
), [
[xe, c.value]
])
]),
_: 3
/* FORWARDED */
})
],
2
/* CLASS */
));
}
}), me = (o, t) => {
const s = o.__vccOpts || o;
for (const [a, n] of t)
s[a] = n;
return s;
}, it = /* @__PURE__ */ me(nt, [["__scopeId", "data-v-285b1a39"]]), ot = {
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: () => ({})
}
}, F = {
step: 2,
interval: 50,
style: "normal"
}, rt = (o) => {
const t = o.content || "";
if (t.match(/<(\w+)[^>]*\/>/))
return !0;
const s = [], a = /<(\w+)[^>]*>/g, n = /<\/(\w+)>/g;
let c, d;
a.lastIndex = 0, n.lastIndex = 0;
const r = [];
for (; (c = a.exec(t)) !== null; )
r.push({
type: "open",
tagName: c[1],
index: c.index
});
for (; (d = n.exec(t)) !== null; )
r.push({
type: "close",
tagName: d[1],
index: d.index
});
r.sort((g, m) => g.index - m.index);
for (const g of r)
if (g.type === "open")
s.push(g.tagName);
else {
if (s.length === 0 || s[s.length - 1] !== g.tagName)
return !1;
s.pop();
}
return s.length === 0;
}, at = (o, t) => {
const s = (o == null ? void 0 : o.content) || "", a = (t == null ? void 0 : t.content) || "", n = s.match(/<(\w+)/), c = a.match(/<\/(\w+)/);
return n && c ? n[1] === c[1] : !1;
}, ee = (o) => ({
nodeType: o ? o.type.replace("_open", "") : "root",
openNode: o,
closeNode: null,
children: [],
vNodeKey: (o == null ? void 0 : o.vNodeKey) || ""
}), lt = (o, t) => {
const s = o.content.startsWith("</");
if (!t.length) {
o.nesting = s ? 0 : 1, t.push(o);
return;
}
const a = t[t.length - 1];
at(a, o) ? (o.nesting = -1, t.pop()) : s ? o.nesting = 0 : (o.nesting = 1, t.push(o));
}, Q = (o) => {
if (!o) return !1;
try {
return document.createElement(o), !0;
} catch {
return !1;
}
}, ye = (o) => {
const t = (r) => {
const g = ee(r);
return r.children && r.children.length > 0 && (g.children = ye(r.children)), g;
}, s = ee(null);
let a = s;
const n = [], c = [], d = [];
return o.forEach((r, g) => {
if (r.vNodeKey = `mc-markdown-content-key-${g}`, r.tokenIndex = g, r.type.includes("html_")) {
if (rt(r)) {
r.nesting = 0;
return;
}
const m = r.type === "html_block" ? d : c;
lt(r, m);
}
}), o.forEach((r, g) => {
let m;
if (r.nesting === 1)
m = ee(r), a.children.push(m), n.push(a), a = m;
else if (r.nesting === -1) {
if (a.closeNode = r, !n.length)
throw new Error("AST stack underflow.");
m = n.pop(), a = m;
} else if (r.nesting === 0)
if (r.type === "inline" && r.children && r.children.length > 0) {
const f = t(r);
a.children.push(f);
} else
a.children.push(r);
else
throw new Error(`Invalid nesting level found in token index ${g}.`);
}), s.children;
}, Z = (o) => {
if (!o || !o.trim()) return [];
if (typeof window > "u" || typeof DOMParser > "u")
return [o];
const s = new DOMParser().parseFromString(`<body>${o}</body>`, "text/html"), a = [];
return s.body.childNodes.forEach((n, c) => {
const d = fe(n);
(ue(d) || typeof d == "string") && (typeof d == "object" && (d.key = c), a.push(d));
}), a;
}, fe = (o) => {
if (o.nodeType === Node.TEXT_NODE) return o.textContent;
if (o.nodeType !== Node.ELEMENT_NODE) return o.textContent || "";
const t = o, s = {};
if (t.hasAttributes() && t.attributes)
for (const n of Array.from(t.attributes))
s[n.name] = n.value;
const a = [];
return t.childNodes.length > 0 && t.childNodes.forEach((n) => {
const c = fe(n);
(ue(c) || typeof c == "string") && a.push(c);
}), Q(t.tagName) ? y(t.tagName.toLowerCase(), s, a) : (o == null ? void 0 : o.textContent) || "";
};
function ct() {
const o = De({});
return {
getCache: (t) => o[t],
getCaches: () => ({ ...o }),
setCache: (t, s) => {
o[t] = s;
},
nextTick: U
};
}
function dt({
adapter: o,
foundationClass: t
}) {
const s = x(null), a = () => (s.value || (s.value = new t(o), typeof s.value.init == "function" && s.value.init()), s.value), n = () => {
s.value && (typeof s.value.destroy == "function" && s.value.destroy(), s.value = null);
};
return ke(() => {
n();
}), {
foundation: a(),
destroyFoundation: n
};
}
const N = () => {
};
class te {
constructor(t) {
I(this, "_adapter");
this._adapter = { ...te.defaultAdapter, ...t };
}
static get cssClasses() {
return {};
}
static get strings() {
return {};
}
static get numbers() {
return {};
}
static get defaultAdapter() {
return {
getProp: N,
getProps: N,
getState: N,
getStates: N,
setState: N,
getContext: N,
getContexts: N,
getCache: N,
setCache: N,
getCaches: N,
stopPropagation: N
};
}
getProp(t) {
return this._adapter.getProp(t);
}
getProps() {
return this._adapter.getProps();
}
getState(t) {
return this._adapter.getState(t);
}
getStates() {
return this._adapter.getStates();
}
setState(t, s) {
return this._adapter.setState({ ...t }, s);
}
/* istanbul ignore next */
getCaches() {
return this._adapter.getCaches();
}
getCache(t) {
return this._adapter.getCache(t);
}
setCache(t, s) {
return t && this._adapter.setCache(t, s);
}
nextTick(t) {
return this._adapter.nextTick(t);
}
_isInProps(t) {
const s = this.getProps();
return t in s;
}
init(t) {
}
destroy() {
}
}
class gt extends te {
constructor(s) {
super({ ...s });
I(this, "isToken", (s) => "type" in s && "content" in s);
I(this, "typewriterEnd", () => {
var s, a;
this.setState({ isTyping: !1 }), (a = (s = this._adapter).typingEnd) == null || a.call(s);
});
I(this, "getThinkContent", (s, a) => {
var c;
const n = (a == null ? void 0 : a.customClass) || "mc-think-block";
return ((c = s == null ? void 0 : s.replace("<think>", `<div class="${n}">`)) == null ? void 0 : c.replace("</think>", `
</div>
`)) || "";
});
I(this, "parseTypingContent", (s) => {
const { typingOptions: a } = this.getProps(), { typingIndex: n } = this.getStates();
s = s.slice(0, n) || "";
const c = { ...F, ...a };
return c.style === "cursor" ? s += '<span class="mc-typewriter mc-typewriter-cursor">|</span>' : (c.style === "color" || c.style === "gradient") && (s = s.slice(0, -5) + `<span class="mc-typewriter mc-typewriter-${c.style}">${s.slice(-5)}</span>`), s || "";
});
I(this, "parseContent", () => {
const { content: s, thinkOptions: a, enableThink: n } = this.getProps(), { typing: c, isTyping: d } = this.getStates();
let r = s || "";
c && d && (r = this.parseTypingContent(s)), n && (r = this.getThinkContent(s, a)), r = this._adapter.parseContent(r);
});
I(this, "typewriterStart", () => {
var r, g;
const { typingOptions: s } = this.getProps(), { timer: a } = this.getStates();
a && clearTimeout(a), this.setState({ isTyping: !0 }), (g = (r = this._adapter).typingStart) == null || g.call(r);
const n = { ...F, ...s }, c = () => {
const { typingIndex: m, content: f } = this.getStates();
let D = n.step || 2;
Array.isArray(n.step) && (D = n.step[0] + Math.floor(Math.random() * (n.step[1] - n.step[0])));
let A = m + D;
if (this.setState({ typingIndex: A }), this.parseContent(), this._adapter.typingEvent(), A >= f.length) {
this.typewriterEnd(), this.parseContent();
return;
}
let L = setTimeout(
c,
typeof n.interval == "number" ? n.interval : 50
);
this.setState({
timer: L
});
};
let d = setTimeout(c);
this.setState({
timer: d
});
});
}
}
function ut({
props: o,
emit: t
}) {
const { t: s } = pe(), n = {
...ct(),
getProps: () => o,
getProp: (d) => o[d],
getStates: () => ({}),
getState: (d) => {
},
setState: (d, r) => {
},
locale: (d, r) => s(d, r),
typingStart: () => t("typingStart"),
typingEnd: () => t("typingEnd"),
typingEvent: () => t("typingEvent"),
parseContent: (d) => {
}
// todo
}, { foundation: c } = dt({
adapter: n,
foundationClass: gt
});
return {
foundation: c
};
}
const pt = /* @__PURE__ */ de({
__name: "mdCard",
props: ot,
emits: ["afterMdtInit", "typingStart", "typing", "typingEnd"],
setup(o, { expose: t, emit: s }) {
const a = new he(), n = o, c = s, d = Ae();
let r = null;
const g = je({
breaks: !0,
linkify: !0,
html: !0,
highlight: (e, l) => {
if (l && k.getLanguage(l))
try {
return k.highlight(e, { language: l }).value;
} catch {
}
return "";
},
...n.mdOptions
}), { foundation: m } = ut({
props: n,
emit: c
}), f = x(0), D = x(!1), A = x(), L = () => {
let e = n.content || "";
if (n.typing && D.value) {
e = n.content.slice(0, f.value) || "";
const h = { ...F, ...n == null ? void 0 : n.typingOptions };
h.style === "cursor" ? e += '<span class="mc-typewriter mc-typewriter-cursor">|</span>' : (h.style === "color" || h.style === "gradient") && (e = e.slice(0, -5) + `<span class="mc-typewriter mc-typewriter-${h.style}">${e.slice(-5)}</span>`);
}
n.enableThink && (e = m.getThinkContent(e, n.thinkOptions));
const l = g.parse(e, {}), u = ye(l), p = _(u);
A.value = y(j, p);
}, _ = (e) => e.map((l) => S(l)), S = (e) => {
var l;
if (e.nodeType === "html_inline" || e.nodeType === "html_block") {
const u = a.filterHtml(((l = e.openNode) == null ? void 0 : l.content) || ""), p = Z(u);
if (!p || p.length === 0)
return y("span", u);
const h = p.map((v) => {
if (typeof v == "string")
return y("span", v);
const B = e.children.map((b) => S(b));
return Array.isArray(v.children) ? v.children = [...v.children, ...B] : v.children = [v.children, ...B].filter((b) => b), v;
});
return y(j, h);
}
if (e.nodeType === "inline") {
const u = g.renderer.render([e.openNode], g.options, {}), p = a.filterHtml(u), h = Z(p);
return y(j, h);
}
return m.isToken(e) ? Y(e) : X(e);
}, Y = (e) => {
if (e.type === "text")
return e.content;
if (e.type === "inline")
return $(e);
if (e.type === "fence")
return W(e);
if (e.type === "softbreak")
return g.options.breaks ? y("br") : `
`;
if (e.type === "html_block" || e.type === "html_inline") {
const l = a.filterHtml(e.content);
return e.type === "html_block" ? y("div", { innerHTML: l }) : y("span", { innerHTML: l });
}
if (e.type === "math_block" && e.markup === "$$") {
const l = g.renderer.render([e], g.options, {}), u = a.filterHtml(l), p = Z(u);
return y(j, p);
}
if (e.tag) {
const l = Q(e.tag) ? e.tag : "div", u = z(e.attrs || []);
return y(l, { ...u, key: e.vNodeKey }, e.content);
}
return e.content;
}, $ = (e) => {
const l = g.renderer.render([e], g.options, {}), u = a.filterHtml(l), p = Z(u);
return y(j, p);
}, X = (e) => {
var h, v, B, b, se, ne, ie, oe, re;
let l = "div";
(h = e.openNode) != null && h.tag && Q((v = e.openNode) == null ? void 0 : v.tag) && (l = (B = e.openNode) == null ? void 0 : B.tag);
const u = z(((b = e.openNode) == null ? void 0 : b.attrs) || []);
if (((se = e.openNode) == null ? void 0 : se.type) === "fence")
return W(e.openNode);
if ((ne = e.openNode) != null && ne.tag) {
let H = Q((ie = e.openNode) == null ? void 0 : ie.tag) ? (oe = e.openNode) == null ? void 0 : oe.tag : "div";
const we = e.children.map((le) => S(le)), Ce = z(((re = e.openNode) == null ? void 0 : re.attrs) || []), ae = y(H, { ...Ce, key: e.vNodeKey }, we);
return H === "table" ? y("div", { className: "mc-table-container", key: `${e.vNodeKey}-table-container` }, [ae]) : ae;
}
const p = e.children.map((H) => S(H));
return y(l, { ...u, key: e.vNodeKey }, p);
}, W = (e) => {
var p;
const l = ((p = e.info) == null ? void 0 : p.replace(/<span\b[^>]*>/i, "").replace("</span>", "")) || "", u = e.content;
return R(l, u, e.tokenIndex);
}, z = (e) => e.reduce((l, [u, p]) => (l[u] = p, l), {});
O(
() => {
var e;
return [n.enableThink, (e = n.thinkOptions) == null ? void 0 : e.customClass, n.theme];
},
() => {
L();
}
);
const R = (e, l, u) => {
const p = {
actions: d.actions ? () => {
var h;
return ((h = d.actions) == null ? void 0 : h.call(d, { codeBlockData: { code: l, language: e } })) || null;
} : void 0,
header: d.header ? () => {
var h;
return ((h = d.header) == null ? void 0 : h.call(d, { codeBlockData: { code: l, language: e } })) || null;
} : void 0,
content: d.content ? () => {
var h;
return ((h = d.content) == null ? void 0 : h.call(d, { codeBlockData: { code: l, language: e } })) || null;
} : void 0
};
return y(
it,
{
language: e,
code: l,
blockIndex: u,
theme: n.theme,
enableMermaid: n.enableMermaid,
mermaidConfig: n.mermaidConfig,
key: `code-block-${u}`
},
p
);
}, K = () => {
clearTimeout(r), D.value = !0, c("typingStart");
const e = { ...F, ...n == null ? void 0 : n.typingOptions }, l = () => {
let u = e.step;
if (Array.isArray(e.step) && (u = e.step[0] + Math.floor(Math.random() * (e.step[1] - e.step[0]))), f.value += u, L(), c("typing"), f.value >= n.content.length) {
J(), L();
return;
}
r = setTimeout(l, e.interval);
};
r = setTimeout(l);
};
O(
() => n.content,
(e, l) => {
if (!n.typing) {
f.value = (e == null ? void 0 : e.length) || 0, L();
return;
}
e.indexOf(l) === -1 && (f.value = 0), U(() => K());
},
{ immediate: !0 }
);
const J = () => {
D.value = !1, c("typingEnd");
};
O(
() => n.customXssRules,
(e) => {
a.setCustomXssRules(e), L();
},
{ deep: !1, immediate: !0 }
), O(
() => n.mdPlugins,
(e) => {
a.setMdPlugins(e, g), L();
},
{ immediate: !0, deep: !1 }
);
const i = G(() => n.theme === "dark" ? "mc-markdown-render-dark" : "mc-markdown-render-light");
return ge(() => {
c("afterMdtInit", g);
}), t({ mdt: g }), (e, l) => (C(), M(
j,
null,
[
w(
"div",
{
class: E(["mc-markdown-render", i.value])
},
[
(C(), Se(be(A.value)))
],
2
/* CLASS */
),
P("v-if", !0)
],
64
/* STABLE_FRAGMENT */
));
}
}), ce = /* @__PURE__ */ me(pt, [["__scopeId", "data-v-b2f30ac7"]]);
ce.install = (o) => {
o.component("McMarkdownCard", ce);
};
export {
ce as McMarkdownCard
};