md-editor-v3 4.12.0 → 4.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/lib/cjs/DropdownToolbar.cjs +3 -1
  2. package/lib/cjs/MdCatalog.cjs +270 -1
  3. package/lib/cjs/MdEditor.cjs +3101 -58
  4. package/lib/cjs/MdModal.cjs +3 -1
  5. package/lib/cjs/MdPreview.cjs +3 -1
  6. package/lib/cjs/ModalToolbar.cjs +124 -1
  7. package/lib/cjs/NormalToolbar.cjs +61 -1
  8. package/lib/cjs/chunks/config.cjs +290 -1
  9. package/lib/cjs/chunks/dom.cjs +64 -1
  10. package/lib/cjs/chunks/index.cjs +1863 -8
  11. package/lib/cjs/chunks/index2.cjs +198 -1
  12. package/lib/cjs/chunks/index3.cjs +270 -1
  13. package/lib/cjs/chunks/index4.cjs +141 -2
  14. package/lib/cjs/chunks/vue-tsx.cjs +10 -1
  15. package/lib/cjs/config.cjs +12 -1
  16. package/lib/cjs/index.cjs +25 -1
  17. package/lib/es/DropdownToolbar.mjs +2 -2
  18. package/lib/es/MdCatalog.mjs +164 -114
  19. package/lib/es/MdEditor.mjs +2292 -1677
  20. package/lib/es/MdModal.mjs +2 -2
  21. package/lib/es/MdPreview.mjs +2 -2
  22. package/lib/es/ModalToolbar.mjs +55 -38
  23. package/lib/es/NormalToolbar.mjs +26 -18
  24. package/lib/es/chunks/config.mjs +73 -54
  25. package/lib/es/chunks/dom.mjs +57 -24
  26. package/lib/es/chunks/index.mjs +1093 -611
  27. package/lib/es/chunks/index2.mjs +126 -78
  28. package/lib/es/chunks/index3.mjs +185 -111
  29. package/lib/es/chunks/index4.mjs +124 -73
  30. package/lib/es/chunks/vue-tsx.mjs +8 -8
  31. package/lib/es/config.mjs +11 -10
  32. package/lib/es/index.mjs +23 -23
  33. package/lib/preview.css +200 -1
  34. package/lib/style.css +592 -1
  35. package/lib/types/DropdownToolbar/DropdownToolbar.d.ts +1 -1
  36. package/lib/types/DropdownToolbar/index.d.ts +39 -61
  37. package/lib/types/MdCatalog/CatalogLink.d.ts +1 -1
  38. package/lib/types/MdCatalog/MdCatalog.d.ts +1 -1
  39. package/lib/types/MdCatalog/index.d.ts +47 -60
  40. package/lib/types/MdEditor/Editor.d.ts +1 -1
  41. package/lib/types/MdEditor/components/Checkbox/index.d.ts +1 -1
  42. package/lib/types/MdEditor/components/Divider/index.d.ts +1 -1
  43. package/lib/types/MdEditor/components/Dropdown/index.d.ts +1 -1
  44. package/lib/types/MdEditor/components/Icon/Icon.d.ts +1 -1
  45. package/lib/types/MdEditor/components/Icon/index.d.ts +1 -1
  46. package/lib/types/MdEditor/components/Modal/Modal.d.ts +2 -2
  47. package/lib/types/MdEditor/components/Modal/index.d.ts +59 -63
  48. package/lib/types/MdEditor/components/Popper/index.d.ts +1 -1
  49. package/lib/types/MdEditor/index.d.ts +238 -104
  50. package/lib/types/MdEditor/layouts/Content/ContentPreview.d.ts +1 -1
  51. package/lib/types/MdEditor/layouts/Content/index.d.ts +1 -1
  52. package/lib/types/MdEditor/layouts/Footer/MarkdownTotal.d.ts +1 -1
  53. package/lib/types/MdEditor/layouts/Footer/ScrollAuto.d.ts +1 -1
  54. package/lib/types/MdEditor/layouts/Footer/index.d.ts +1 -1
  55. package/lib/types/MdEditor/layouts/Modals/Clip.d.ts +1 -1
  56. package/lib/types/MdEditor/layouts/Modals/Link.d.ts +1 -1
  57. package/lib/types/MdEditor/layouts/Modals/index.d.ts +1 -1
  58. package/lib/types/MdEditor/layouts/Toolbar/TableShape.d.ts +1 -1
  59. package/lib/types/MdEditor/layouts/Toolbar/index.d.ts +1 -1
  60. package/lib/types/MdEditor/utils/vue-tsx.d.ts +1 -1
  61. package/lib/types/MdPreview/MdPreview.d.ts +1 -1
  62. package/lib/types/MdPreview/index.d.ts +119 -73
  63. package/lib/types/ModalToolbar/ModalToolbar.d.ts +1 -1
  64. package/lib/types/ModalToolbar/index.d.ts +64 -66
  65. package/lib/types/NormalToolbar/NormalToolbar.d.ts +1 -1
  66. package/lib/types/NormalToolbar/index.d.ts +30 -58
  67. package/lib/umd/index.js +42 -42
  68. package/package.json +4 -4
@@ -1,314 +1,614 @@
1
- import { inject as P, watch as I, toRef as te, onMounted as _, nextTick as j, shallowRef as B, ref as R, computed as F, defineComponent as ne, createVNode as M, Fragment as pe, reactive as oe, provide as x, onBeforeUnmount as he } from "vue";
2
- import { e as S, p as h, m as ge, k as D, f as V, h as ye, s as z, a as ve, i as be, g as W, j as q, b as we, d as ke } from "./config.mjs";
3
- import { a as $e, b as g, P as Ce, C as K, R as G, B as A, O as re, E as Ie, U as Se, c as ae, d as Z, F as J, e as X, H as Q, f as Y, h as le, i as Ee, j as Pe, k as _e } from "./index4.mjs";
4
- import { a as T, u as Te } from "./dom.mjs";
5
- import xe from "medium-zoom";
6
- import { debounce as ie, uuid as U } from "@vavt/util";
7
- import Fe from "copy-to-clipboard";
8
- import He from "markdown-it";
9
- import Me from "markdown-it-image-figures";
10
- import Re from "markdown-it-task-lists";
11
- import Ae from "markdown-it-xss";
12
- import { LRUCache as Be } from "lru-cache";
13
- const Le = (e, a) => {
14
- const l = P("editorId"), { noImgZoomIn: t } = e, n = ie(() => {
15
- const i = document.querySelectorAll(`#${l}-preview img`);
16
- i.length !== 0 && xe(i, {
17
- background: "#00000073"
18
- });
19
- });
20
- I(
21
- [a, te(e.setting, "preview")],
1
+ import { inject, watch, toRef, onMounted, nextTick, shallowRef, ref, computed, defineComponent, createVNode, Fragment, reactive, provide, onBeforeUnmount } from "vue";
2
+ import { e as configOption, p as prefix, m as mermaidUrl, k as katexUrl, f as codeCss, h as highlightUrl, s as staticTextDefault, a as iconfontSvgUrl, i as iconfontClassUrl, g as prettierUrl, j as cropperUrl, b as allToolbar, d as allFooter } from "./config.mjs";
3
+ import { a as generateCodeRowNumber, b as bus, P as PUSH_CATALOG, C as CATALOG_CHANGED, R as RERENDER, B as BUILD_FINISHED, O as ON_SAVE, E as ERROR_CATCHER, U as UPLOAD_IMAGE, c as CHANGE_CATALOG_VISIBLE, d as PAGE_FULL_SCREEN_CHANGED, F as FULL_SCREEN_CHANGED, e as PREVIEW_CHANGED, H as HTML_PREVIEW_CHANGED, f as CATALOG_VISIBLE_CHANGED, h as REPLACE, i as CHANGE_FULL_SCREEN, j as EVENT_LISTENER, k as getNextId } from "./index4.mjs";
4
+ import { a as appendHandler, u as updateHandler } from "./dom.mjs";
5
+ import mediumZoom from "medium-zoom";
6
+ import { debounce, uuid } from "@vavt/util";
7
+ import copy from "copy-to-clipboard";
8
+ import mdit from "markdown-it";
9
+ import ImageFiguresPlugin from "markdown-it-image-figures";
10
+ import TaskListPlugin from "markdown-it-task-lists";
11
+ import XSSPlugin from "markdown-it-xss";
12
+ import { LRUCache } from "lru-cache";
13
+ const userZoom = (props, html) => {
14
+ const editorId = inject("editorId");
15
+ const { noImgZoomIn } = props;
16
+ let zoomHander = () => {
17
+ };
18
+ watch(
19
+ [html, toRef(props.setting, "preview")],
22
20
  () => {
23
- !t && e.setting.preview && n();
21
+ if (!noImgZoomIn && props.setting.preview) {
22
+ zoomHander();
23
+ }
24
24
  },
25
25
  {
26
- immediate: !0
26
+ immediate: true
27
27
  }
28
28
  );
29
- }, Ne = (e, a) => {
30
- if (typeof a[e] == "string")
31
- return a[e];
32
- const l = `<i class="${h}-iconfont ${h}-icon-${e}"></i>`;
33
- switch (S.iconfontType) {
34
- case "svg":
35
- return `<svg class="${h}-icon" aria-hidden="true"><use xlink:href="#${h}-icon-${e}"></use></svg>`;
36
- default:
37
- return l;
29
+ onMounted(() => {
30
+ zoomHander = debounce(() => {
31
+ const imgs = document.querySelectorAll(`#${editorId}-preview img`);
32
+ if (imgs.length === 0) {
33
+ return;
34
+ }
35
+ mediumZoom(imgs, {
36
+ background: "#00000073"
37
+ });
38
+ });
39
+ });
40
+ };
41
+ const StrIcon = (name, customIcon) => {
42
+ if (typeof customIcon[name] === "string") {
43
+ return customIcon[name];
44
+ }
45
+ const defaultStr = `<i class="${prefix}-iconfont ${prefix}-icon-${name}"></i>`;
46
+ switch (configOption.iconfontType) {
47
+ case "svg": {
48
+ return `<svg class="${prefix}-icon" aria-hidden="true"><use xlink:href="#${prefix}-icon-${name}"></use></svg>`;
49
+ }
50
+ default: {
51
+ return defaultStr;
52
+ }
38
53
  }
39
- }, Oe = (e, a, l) => {
40
- const t = P("editorId"), n = P("usedLanguageText"), i = P("customIcon"), o = () => {
41
- document.querySelectorAll(`#${t}-preview pre`).forEach((s) => {
42
- var v, m;
43
- let r = -1;
44
- (v = s.querySelector(".copy-button")) == null || v.remove();
45
- const d = ((m = n.value.copyCode) == null ? void 0 : m.text) || "复制代码", b = document.createElement("span");
46
- b.setAttribute("class", "copy-button"), b.dataset.tips = d, b.innerHTML = Ne("copy", i.value), b.addEventListener("click", () => {
47
- var w, E;
48
- clearTimeout(r);
49
- const p = s.querySelector("code").innerText, f = Fe(e.formatCopiedText(p)), k = ((w = n.value.copyCode) == null ? void 0 : w.successTips) || "已复制!", y = ((E = n.value.copyCode) == null ? void 0 : E.failTips) || "已复制!";
50
- b.dataset.tips = f ? k : y, r = window.setTimeout(() => {
51
- b.dataset.tips = d;
54
+ };
55
+ const useCopyCode = (props, html, key) => {
56
+ const editorId = inject("editorId");
57
+ const ult = inject("usedLanguageText");
58
+ const customIcon = inject("customIcon");
59
+ const initCopyEntry = () => {
60
+ document.querySelectorAll(`#${editorId}-preview pre`).forEach((pre) => {
61
+ var _a, _b;
62
+ let clearTimer = -1;
63
+ (_a = pre.querySelector(".copy-button")) == null ? void 0 : _a.remove();
64
+ const copyBtnText = ((_b = ult.value.copyCode) == null ? void 0 : _b.text) || "复制代码";
65
+ const copyButton = document.createElement("span");
66
+ copyButton.setAttribute("class", "copy-button");
67
+ copyButton.dataset.tips = copyBtnText;
68
+ copyButton.innerHTML = StrIcon("copy", customIcon.value);
69
+ copyButton.addEventListener("click", () => {
70
+ var _a2, _b2;
71
+ clearTimeout(clearTimer);
72
+ const codeText = pre.querySelector("code").innerText;
73
+ const success = copy(props.formatCopiedText(codeText));
74
+ const succssTip = ((_a2 = ult.value.copyCode) == null ? void 0 : _a2.successTips) || "已复制!";
75
+ const failTip = ((_b2 = ult.value.copyCode) == null ? void 0 : _b2.failTips) || "已复制!";
76
+ copyButton.dataset.tips = success ? succssTip : failTip;
77
+ clearTimer = window.setTimeout(() => {
78
+ copyButton.dataset.tips = copyBtnText;
52
79
  }, 1500);
53
- }), s.appendChild(b);
80
+ });
81
+ pre.appendChild(copyButton);
54
82
  });
55
- }, u = () => {
56
- j(o);
57
- }, c = (s) => {
58
- s && j(o);
59
83
  };
60
- I([a, l], u), I(() => e.setting.preview, c), I(() => e.setting.htmlPreview, c), I(() => n.value, o), _(o);
61
- }, je = (e) => {
62
- var i;
63
- const a = (i = S.editorExtensions) == null ? void 0 : i.highlight, l = a == null ? void 0 : a.instance, t = P("highlight"), n = B(l);
64
- return _(() => {
65
- if (!e.noHighlight && !n.value) {
66
- const o = document.createElement("script");
67
- o.src = t.value.js, o.onload = () => {
68
- n.value = window.hljs;
69
- }, o.id = `${h}-hljs`, T(o, "hljs");
70
- const u = document.createElement("link");
71
- u.rel = "stylesheet", u.href = t.value.css, u.id = `${h}-hlCss`, T(u);
84
+ const htmlChanged = () => {
85
+ nextTick(initCopyEntry);
86
+ };
87
+ const settingPreviewChanged = (nVal) => {
88
+ if (nVal) {
89
+ nextTick(initCopyEntry);
72
90
  }
73
- }), I(
74
- () => t.value.css,
75
- (o) => {
76
- Te(`${h}-hlCss`, "href", o);
91
+ };
92
+ watch([html, key], htmlChanged);
93
+ watch(() => props.setting.preview, settingPreviewChanged);
94
+ watch(() => props.setting.htmlPreview, settingPreviewChanged);
95
+ watch(() => ult.value, initCopyEntry);
96
+ onMounted(initCopyEntry);
97
+ };
98
+ const useHighlight = (props) => {
99
+ var _a;
100
+ const hljsConf = (_a = configOption.editorExtensions) == null ? void 0 : _a.highlight;
101
+ const hljs = hljsConf == null ? void 0 : hljsConf.instance;
102
+ const highlightUrl2 = inject("highlight");
103
+ const hljsRef = shallowRef(hljs);
104
+ onMounted(() => {
105
+ if (props.noHighlight) {
106
+ return;
77
107
  }
78
- ), n;
79
- }, Ue = (e) => {
80
- const a = P("theme"), { editorExtensions: l, mermaidConfig: t } = S, n = l == null ? void 0 : l.mermaid, i = B(n == null ? void 0 : n.instance), o = B(-1), u = new Be({
108
+ if (!hljsRef.value) {
109
+ const highlightScript = document.createElement("script");
110
+ highlightScript.src = highlightUrl2.value.js;
111
+ highlightScript.onload = () => {
112
+ hljsRef.value = window.hljs;
113
+ };
114
+ highlightScript.id = `${prefix}-hljs`;
115
+ appendHandler(highlightScript, "hljs");
116
+ const highlightLink = document.createElement("link");
117
+ highlightLink.rel = "stylesheet";
118
+ highlightLink.href = highlightUrl2.value.css;
119
+ highlightLink.id = `${prefix}-hlCss`;
120
+ appendHandler(highlightLink);
121
+ }
122
+ });
123
+ watch(
124
+ () => highlightUrl2.value.css,
125
+ (url) => {
126
+ updateHandler(`${prefix}-hlCss`, "href", url);
127
+ }
128
+ );
129
+ return hljsRef;
130
+ };
131
+ const useMermaid = (props) => {
132
+ const theme = inject("theme");
133
+ const { editorExtensions, mermaidConfig } = configOption;
134
+ const mermaidConf = editorExtensions == null ? void 0 : editorExtensions.mermaid;
135
+ const mermaidRef = shallowRef(mermaidConf == null ? void 0 : mermaidConf.instance);
136
+ const reRenderRef = shallowRef(-1);
137
+ const mermaidCache = new LRUCache({
81
138
  max: 1e3,
82
139
  // 缓存10分钟
83
140
  ttl: 6e5
84
- }), c = () => {
85
- const r = i.value;
86
- !e.noMermaid && r && (r.initialize(
87
- t({
88
- startOnLoad: !1,
89
- theme: a.value === "dark" ? "dark" : "default"
90
- })
91
- ), o.value = o.value + 1);
141
+ });
142
+ const configMermaid = () => {
143
+ const mermaid = mermaidRef.value;
144
+ if (!props.noMermaid && mermaid) {
145
+ mermaid.initialize(
146
+ mermaidConfig({
147
+ startOnLoad: false,
148
+ theme: theme.value === "dark" ? "dark" : "default"
149
+ })
150
+ );
151
+ reRenderRef.value = reRenderRef.value + 1;
152
+ }
92
153
  };
93
- return I(
94
- () => a.value,
154
+ watch(
155
+ () => theme.value,
95
156
  () => {
96
- u.clear(), c();
157
+ mermaidCache.clear();
158
+ configMermaid();
159
+ }
160
+ );
161
+ onMounted(() => {
162
+ if (props.noMermaid) {
163
+ return;
97
164
  }
98
- ), _(() => {
99
- if (!e.noMermaid && !(n != null && n.instance)) {
100
- const r = (n == null ? void 0 : n.js) || ge;
101
- if (/\.mjs/.test(r))
165
+ if (!(mermaidConf == null ? void 0 : mermaidConf.instance)) {
166
+ const jsSrc = (mermaidConf == null ? void 0 : mermaidConf.js) || mermaidUrl;
167
+ if (/\.mjs/.test(jsSrc)) {
102
168
  import(
103
169
  /* @vite-ignore */
104
170
  /* webpackIgnore: true */
105
- r
106
- ).then((d) => {
107
- i.value = d.default, c();
171
+ jsSrc
172
+ ).then((module) => {
173
+ mermaidRef.value = module.default;
174
+ configMermaid();
108
175
  });
109
- else {
110
- const d = document.createElement("script");
111
- d.id = `${h}-mermaid`, d.src = r, d.onload = () => {
112
- i.value = window.mermaid, c();
113
- }, T(d, "mermaid");
176
+ } else {
177
+ const mermaidScript = document.createElement("script");
178
+ mermaidScript.id = `${prefix}-mermaid`;
179
+ mermaidScript.src = jsSrc;
180
+ mermaidScript.onload = () => {
181
+ mermaidRef.value = window.mermaid;
182
+ configMermaid();
183
+ };
184
+ appendHandler(mermaidScript, "mermaid");
114
185
  }
115
186
  }
116
- }), { mermaidRef: i, reRenderRef: o, replaceMermaid: () => {
117
- j(() => {
118
- if (!e.noMermaid && i.value) {
119
- const r = document.querySelectorAll(
120
- `div.${h}-mermaid`
121
- ), d = document.createElement("div");
122
- d.style.width = document.body.offsetWidth + "px", d.style.height = document.body.offsetHeight + "px", d.style.position = "fixed", d.style.zIndex = "-10000", d.style.top = "-10000";
123
- let b = r.length;
124
- b > 0 && document.body.appendChild(d), r.forEach(async (v) => {
125
- let m = u.get(v.innerText);
126
- if (!m) {
127
- const f = U(), k = i.value.renderAsync || i.value.render;
128
- let y = "";
187
+ });
188
+ const replaceMermaid = () => {
189
+ nextTick(() => {
190
+ if (!props.noMermaid && mermaidRef.value) {
191
+ const mermaidSourceEles = document.querySelectorAll(
192
+ `div.${prefix}-mermaid`
193
+ );
194
+ const svgContainingElement = document.createElement("div");
195
+ svgContainingElement.style.width = document.body.offsetWidth + "px";
196
+ svgContainingElement.style.height = document.body.offsetHeight + "px";
197
+ svgContainingElement.style.position = "fixed";
198
+ svgContainingElement.style.zIndex = "-10000";
199
+ svgContainingElement.style.top = "-10000";
200
+ let count = mermaidSourceEles.length;
201
+ if (count > 0) {
202
+ document.body.appendChild(svgContainingElement);
203
+ }
204
+ mermaidSourceEles.forEach(async (item) => {
205
+ let mermaidHtml = mermaidCache.get(item.innerText);
206
+ if (!mermaidHtml) {
207
+ const idRand = uuid();
208
+ const render = mermaidRef.value.renderAsync || mermaidRef.value.render;
209
+ let svg = "";
129
210
  try {
130
- y = await k(f, v.innerText, d);
131
- } catch {
211
+ svg = await render(idRand, item.innerText, svgContainingElement);
212
+ } catch (error) {
132
213
  }
133
- m = await e.sanitizeMermaid(
134
- typeof y == "string" ? y : y.svg
135
- ), u.set(v.innerText, m);
214
+ mermaidHtml = await props.sanitizeMermaid(
215
+ typeof svg === "string" ? svg : svg.svg
216
+ );
217
+ mermaidCache.set(item.innerText, mermaidHtml);
136
218
  }
137
219
  const p = document.createElement("p");
138
- p.className = `${h}-mermaid`, p.setAttribute("data-processed", ""), p.innerHTML = m, v.dataset.line !== void 0 && (p.dataset.line = v.dataset.line), v.replaceWith(p), --b === 0 && d.remove();
220
+ p.className = `${prefix}-mermaid`;
221
+ p.setAttribute("data-processed", "");
222
+ p.innerHTML = mermaidHtml;
223
+ if (item.dataset.line !== void 0) {
224
+ p.dataset.line = item.dataset.line;
225
+ }
226
+ item.replaceWith(p);
227
+ if (--count === 0) {
228
+ svgContainingElement.remove();
229
+ }
139
230
  });
140
231
  }
141
232
  });
142
- } };
143
- }, Ge = (e) => {
144
- var n;
145
- const a = (n = S.editorExtensions) == null ? void 0 : n.katex, l = a == null ? void 0 : a.instance, t = B(l);
146
- return _(() => {
147
- if (!e.noKatex && !t.value) {
148
- const i = document.createElement("script");
149
- i.src = (a == null ? void 0 : a.js) || D.js, i.onload = () => {
150
- t.value = window.katex;
151
- }, i.id = `${h}-katex`;
152
- const o = document.createElement("link");
153
- o.rel = "stylesheet", o.href = (a == null ? void 0 : a.css) || D.css, o.id = `${h}-katexCss`, T(i, "katex"), T(o);
233
+ };
234
+ return { mermaidRef, reRenderRef, replaceMermaid };
235
+ };
236
+ const useKatex = (props) => {
237
+ var _a;
238
+ const katexConf = (_a = configOption.editorExtensions) == null ? void 0 : _a.katex;
239
+ const katexIns = katexConf == null ? void 0 : katexConf.instance;
240
+ const katex = shallowRef(katexIns);
241
+ onMounted(() => {
242
+ if (!props.noKatex && !katex.value) {
243
+ const katexScript = document.createElement("script");
244
+ katexScript.src = (katexConf == null ? void 0 : katexConf.js) || katexUrl.js;
245
+ katexScript.onload = () => {
246
+ katex.value = window.katex;
247
+ };
248
+ katexScript.id = `${prefix}-katex`;
249
+ const katexLink = document.createElement("link");
250
+ katexLink.rel = "stylesheet";
251
+ katexLink.href = (katexConf == null ? void 0 : katexConf.css) || katexUrl.css;
252
+ katexLink.id = `${prefix}-katexCss`;
253
+ appendHandler(katexScript, "katex");
254
+ appendHandler(katexLink);
154
255
  }
155
- }), t;
156
- }, De = (e, a) => {
157
- const l = e.renderer.rules.fence.bind(e.renderer.rules);
158
- e.renderer.rules.fence = (t, n, i, o, u) => {
159
- const c = t[n], s = c.content.trim();
160
- if (c.info === "mermaid") {
161
- let r;
162
- return t[n].map && t[n].level === 0 && (r = t[n].map[0], t[n].attrSet("data-line", String(r))), `<div class="${h}-mermaid" ${r !== void 0 ? "data-line=" + r : ""} data-mermaid-theme=${a.themeRef.value}>${s}</div>`;
256
+ });
257
+ return katex;
258
+ };
259
+ const MermaidPlugin = (md, options) => {
260
+ const temp = md.renderer.rules.fence.bind(md.renderer.rules);
261
+ md.renderer.rules.fence = (tokens, idx, ops, env, slf) => {
262
+ const token = tokens[idx];
263
+ const code = token.content.trim();
264
+ if (token.info === "mermaid") {
265
+ let line;
266
+ if (tokens[idx].map && tokens[idx].level === 0) {
267
+ line = tokens[idx].map[0];
268
+ tokens[idx].attrSet("data-line", String(line));
269
+ }
270
+ return `<div class="${prefix}-mermaid" ${line !== void 0 ? "data-line=" + line : ""} data-mermaid-theme=${options.themeRef.value}>${code}</div>`;
163
271
  }
164
- return l(t, n, i, o, u);
272
+ return temp(tokens, idx, ops, env, slf);
165
273
  };
166
- }, Ve = De, ee = (e, a) => {
167
- let l = !0, t = !0;
168
- const n = e.posMax, i = a > 0 ? e.src.charCodeAt(a - 1) : -1, o = a + 1 <= n ? e.src.charCodeAt(a + 1) : -1;
169
- return (i === 32 || i === 9 || o >= 48 && o <= 57) && (t = !1), (o === 32 || o === 9) && (l = !1), {
170
- can_open: l,
171
- can_close: t
274
+ };
275
+ const MermaidPlugin$1 = MermaidPlugin;
276
+ const isValidDelim = (state, pos) => {
277
+ let can_open = true, can_close = true;
278
+ const max = state.posMax;
279
+ const prevChar = pos > 0 ? state.src.charCodeAt(pos - 1) : -1;
280
+ const nextChar = pos + 1 <= max ? state.src.charCodeAt(pos + 1) : -1;
281
+ if (prevChar === 32 || prevChar === 9 || nextChar >= 48 && nextChar <= 57) {
282
+ can_close = false;
283
+ }
284
+ if (nextChar === 32 || nextChar === 9) {
285
+ can_open = false;
286
+ }
287
+ return {
288
+ can_open,
289
+ can_close
172
290
  };
173
- }, ze = (e, a) => {
174
- let l, t, n, i;
175
- if (e.src[e.pos] !== "$")
176
- return !1;
177
- if (n = ee(e, e.pos), !n.can_open)
178
- return a || (e.pending += "$"), e.pos += 1, !0;
179
- const o = e.pos + 1;
180
- for (l = o; (l = e.src.indexOf("$", l)) !== -1; ) {
181
- for (i = l - 1; e.src[i] === "\\"; )
182
- i -= 1;
183
- if ((l - i) % 2 == 1)
291
+ };
292
+ const math_inline = (state, silent) => {
293
+ let match, token, res, pos;
294
+ if (state.src[state.pos] !== "$") {
295
+ return false;
296
+ }
297
+ res = isValidDelim(state, state.pos);
298
+ if (!res.can_open) {
299
+ if (!silent) {
300
+ state.pending += "$";
301
+ }
302
+ state.pos += 1;
303
+ return true;
304
+ }
305
+ const start = state.pos + 1;
306
+ match = start;
307
+ while ((match = state.src.indexOf("$", match)) !== -1) {
308
+ pos = match - 1;
309
+ while (state.src[pos] === "\\") {
310
+ pos -= 1;
311
+ }
312
+ if ((match - pos) % 2 == 1) {
313
+ break;
314
+ }
315
+ match += 1;
316
+ }
317
+ if (match === -1) {
318
+ if (!silent) {
319
+ state.pending += "$";
320
+ }
321
+ state.pos = start;
322
+ return true;
323
+ }
324
+ if (match - start === 0) {
325
+ if (!silent) {
326
+ state.pending += "$$";
327
+ }
328
+ state.pos = start + 1;
329
+ return true;
330
+ }
331
+ res = isValidDelim(state, match);
332
+ if (!res.can_close) {
333
+ if (!silent) {
334
+ state.pending += "$";
335
+ }
336
+ state.pos = start;
337
+ return true;
338
+ }
339
+ if (!silent) {
340
+ token = state.push("math_inline", "math", 0);
341
+ token.markup = "$";
342
+ token.content = state.src.slice(start, match);
343
+ }
344
+ state.pos = match + 1;
345
+ return true;
346
+ };
347
+ const math_block = (state, start, end, silent) => {
348
+ let firstLine, lastLine, next, lastPos, found = false, pos = state.bMarks[start] + state.tShift[start], max = state.eMarks[start];
349
+ if (pos + 2 > max) {
350
+ return false;
351
+ }
352
+ if (state.src.slice(pos, pos + 2) !== "$$") {
353
+ return false;
354
+ }
355
+ pos += 2;
356
+ firstLine = state.src.slice(pos, max);
357
+ if (silent) {
358
+ return true;
359
+ }
360
+ if (firstLine.trim().slice(-2) === "$$") {
361
+ firstLine = firstLine.trim().slice(0, -2);
362
+ found = true;
363
+ }
364
+ for (next = start; !found; ) {
365
+ next++;
366
+ if (next >= end) {
184
367
  break;
185
- l += 1;
368
+ }
369
+ pos = state.bMarks[next] + state.tShift[next];
370
+ max = state.eMarks[next];
371
+ if (pos < max && state.tShift[next] < state.blkIndent) {
372
+ break;
373
+ }
374
+ if (state.src.slice(pos, max).trim().slice(-2) === "$$") {
375
+ lastPos = state.src.slice(0, max).lastIndexOf("$$");
376
+ lastLine = state.src.slice(pos, lastPos);
377
+ found = true;
378
+ }
186
379
  }
187
- return l === -1 ? (a || (e.pending += "$"), e.pos = o, !0) : l - o === 0 ? (a || (e.pending += "$$"), e.pos = o + 1, !0) : (n = ee(e, l), n.can_close ? (a || (t = e.push("math_inline", "math", 0), t.markup = "$", t.content = e.src.slice(o, l)), e.pos = l + 1, !0) : (a || (e.pending += "$"), e.pos = o, !0));
188
- }, We = (e, a, l, t) => {
189
- let n, i, o, u, c = !1, s = e.bMarks[a] + e.tShift[a], r = e.eMarks[a];
190
- if (s + 2 > r || e.src.slice(s, s + 2) !== "$$")
191
- return !1;
192
- if (s += 2, n = e.src.slice(s, r), t)
193
- return !0;
194
- for (n.trim().slice(-2) === "$$" && (n = n.trim().slice(0, -2), c = !0), o = a; !c && (o++, !(o >= l || (s = e.bMarks[o] + e.tShift[o], r = e.eMarks[o], s < r && e.tShift[o] < e.blkIndent))); )
195
- e.src.slice(s, r).trim().slice(-2) === "$$" && (u = e.src.slice(0, r).lastIndexOf("$$"), i = e.src.slice(s, u), c = !0);
196
- e.line = o + 1;
197
- const d = e.push("math_block", "math", 0);
198
- return d.block = !0, d.content = (n && n.trim() ? n + `
199
- ` : "") + e.getLines(a + 1, o, e.tShift[a], !0) + (i && i.trim() ? i : ""), d.map = [a, e.line], d.markup = "$$", !0;
200
- }, qe = (e, a) => {
201
- const l = (n) => {
202
- if (a.katexRef.value) {
203
- const i = a.katexRef.value.renderToString(n, {
204
- throwOnError: !1
380
+ state.line = next + 1;
381
+ const token = state.push("math_block", "math", 0);
382
+ token.block = true;
383
+ token.content = (firstLine && firstLine.trim() ? firstLine + "\n" : "") + state.getLines(start + 1, next, state.tShift[start], true) + (lastLine && lastLine.trim() ? lastLine : "");
384
+ token.map = [start, state.line];
385
+ token.markup = "$$";
386
+ return true;
387
+ };
388
+ const KatexPlugin = (md, options) => {
389
+ const katexInline = (str) => {
390
+ if (options.katexRef.value) {
391
+ const html = options.katexRef.value.renderToString(str, {
392
+ throwOnError: false
205
393
  });
206
- return `<span class="${h}-katex-inline" data-processed>${i}</span>`;
207
- } else
208
- return `<span class="${h}-katex-inline">${n}</span>`;
209
- }, t = (n, i) => {
210
- if (a.katexRef.value) {
211
- const o = a.katexRef.value.renderToString(n, {
212
- throwOnError: !1,
213
- displayMode: !0
394
+ return `<span class="${prefix}-katex-inline" data-processed>${html}</span>`;
395
+ } else {
396
+ return `<span class="${prefix}-katex-inline">${str}</span>`;
397
+ }
398
+ };
399
+ const katexBlock = (str, lineNum) => {
400
+ if (options.katexRef.value) {
401
+ const html = options.katexRef.value.renderToString(str, {
402
+ throwOnError: false,
403
+ displayMode: true
214
404
  });
215
- return `<p class="${h}-katex-block" data-line=${i} data-processed>${o}</p>`;
216
- } else
217
- return `<p class="${h}-katex-block" data-line=${i}>${n}</p>`;
405
+ return `<p class="${prefix}-katex-block" data-line=${lineNum} data-processed>${html}</p>`;
406
+ } else {
407
+ return `<p class="${prefix}-katex-block" data-line=${lineNum}>${str}</p>`;
408
+ }
218
409
  };
219
- e.inline.ruler.after("escape", "math_inline", ze), e.block.ruler.after("blockquote", "math_block", We, {
410
+ md.inline.ruler.after("escape", "math_inline", math_inline);
411
+ md.block.ruler.after("blockquote", "math_block", math_block, {
220
412
  alt: ["paragraph", "reference", "blockquote", "list"]
221
- }), e.renderer.rules.math_inline = (n, i) => l(n[i].content), e.renderer.rules.math_block = (n, i) => t(n[i].content, n[i].map[0]) + `
222
- `;
223
- }, Ke = qe, Ze = (e, a) => {
224
- a = a || {};
225
- const l = 3, t = a.marker || "!", n = t.charCodeAt(0), i = t.length;
226
- let o = "", u = "";
227
- const c = (r, d, b, v, m) => {
228
- const p = r[d];
229
- return p.type === "admonition_open" ? (r[d].attrPush([
230
- "class",
231
- `${h}-admonition ${h}-admonition-${p.info}`
232
- ]), r[d].attrSet("data-line", String(r[d].map[0]))) : p.type === "admonition_title_open" && r[d].attrPush(["class", `${h}-admonition-title`]), m.renderToken(r, d, b);
233
- }, s = (r) => {
234
- const d = r.trim().split(" ", 2);
235
- u = "", o = d[0], d.length > 1 && (u = r.substring(o.length + 2)), (u === "" || !u) && (u = o);
413
+ });
414
+ md.renderer.rules.math_inline = (tokens, idx) => {
415
+ return katexInline(tokens[idx].content);
416
+ };
417
+ md.renderer.rules.math_block = (tokens, idx) => {
418
+ return katexBlock(tokens[idx].content, tokens[idx].map[0]) + "\n";
419
+ };
420
+ };
421
+ const KatexPlugin$1 = KatexPlugin;
422
+ const AdmonitionPlugin = (md, options) => {
423
+ options = options || {};
424
+ const markers = 3, markerStr = options.marker || "!", markerChar = markerStr.charCodeAt(0), markerLen = markerStr.length;
425
+ let type = "", title = "";
426
+ const render = (tokens, idx, _options, _env, self) => {
427
+ const token = tokens[idx];
428
+ if (token.type === "admonition_open") {
429
+ tokens[idx].attrPush([
430
+ "class",
431
+ `${prefix}-admonition ${prefix}-admonition-${token.info}`
432
+ ]);
433
+ tokens[idx].attrSet("data-line", String(tokens[idx].map[0]));
434
+ } else if (token.type === "admonition_title_open") {
435
+ tokens[idx].attrPush(["class", `${prefix}-admonition-title`]);
436
+ }
437
+ return self.renderToken(tokens, idx, _options);
438
+ };
439
+ const validate = (params) => {
440
+ const array = params.trim().split(" ", 2);
441
+ title = "";
442
+ type = array[0];
443
+ if (array.length > 1) {
444
+ title = params.substring(type.length + 2);
445
+ }
446
+ if (title === "" || !title) {
447
+ title = type;
448
+ }
236
449
  };
237
- e.block.ruler.before(
450
+ md.block.ruler.before(
238
451
  "code",
239
452
  "admonition",
240
- (r, d, b, v) => {
241
- let m, p, f, k = !1, y = r.bMarks[d] + r.tShift[d], w = r.eMarks[d];
242
- if (n !== r.src.charCodeAt(y))
243
- return !1;
244
- for (m = y + 1; m <= w && t[(m - y) % i] === r.src[m]; m++)
245
- ;
246
- const E = Math.floor((m - y) / i);
247
- if (E !== l)
248
- return !1;
249
- m -= (m - y) % i;
250
- const $ = r.src.slice(y, m), C = r.src.slice(m, w);
251
- if (s(C), v)
252
- return !0;
253
- for (p = d; p++, !(p >= b || (y = r.bMarks[p] + r.tShift[p], w = r.eMarks[p], y < w && r.sCount[p] < r.blkIndent)); )
254
- if (n === r.src.charCodeAt(y) && !(r.sCount[p] - r.blkIndent >= 4)) {
255
- for (m = y + 1; m <= w && t[(m - y) % i] === r.src[m]; m++)
256
- ;
257
- if (!(Math.floor((m - y) / i) < E) && (m -= (m - y) % i, m = r.skipSpaces(m), !(m < w))) {
258
- k = !0;
453
+ (state, startLine, endLine, silent) => {
454
+ let pos, nextLine, token, autoClosed = false, start = state.bMarks[startLine] + state.tShift[startLine], max = state.eMarks[startLine];
455
+ if (markerChar !== state.src.charCodeAt(start)) {
456
+ return false;
457
+ }
458
+ for (pos = start + 1; pos <= max; pos++) {
459
+ if (markerStr[(pos - start) % markerLen] !== state.src[pos]) {
460
+ break;
461
+ }
462
+ }
463
+ const markerCount = Math.floor((pos - start) / markerLen);
464
+ if (markerCount !== markers) {
465
+ return false;
466
+ }
467
+ pos -= (pos - start) % markerLen;
468
+ const markup = state.src.slice(start, pos);
469
+ const params = state.src.slice(pos, max);
470
+ validate(params);
471
+ if (silent) {
472
+ return true;
473
+ }
474
+ nextLine = startLine;
475
+ for (; ; ) {
476
+ nextLine++;
477
+ if (nextLine >= endLine) {
478
+ break;
479
+ }
480
+ start = state.bMarks[nextLine] + state.tShift[nextLine];
481
+ max = state.eMarks[nextLine];
482
+ if (start < max && state.sCount[nextLine] < state.blkIndent) {
483
+ break;
484
+ }
485
+ if (markerChar !== state.src.charCodeAt(start)) {
486
+ continue;
487
+ }
488
+ if (state.sCount[nextLine] - state.blkIndent >= 4) {
489
+ continue;
490
+ }
491
+ for (pos = start + 1; pos <= max; pos++) {
492
+ if (markerStr[(pos - start) % markerLen] !== state.src[pos]) {
259
493
  break;
260
494
  }
261
495
  }
262
- const L = r.parentType, H = r.lineMax;
263
- return r.parentType = "root", r.lineMax = p, f = r.push("admonition_open", "div", 1), f.markup = $, f.block = !0, f.info = o, f.map = [d, p], f = r.push("admonition_title_open", "p", 1), f.markup = $ + " " + o, f.map = [d, p], f = r.push("inline", "", 0), f.content = u, f.map = [d, r.line - 1], f.children = [], f = r.push("admonition_title_close", "p", -1), f.markup = $ + " " + o, r.md.block.tokenize(r, d + 1, p), f = r.push("admonition_close", "div", -1), f.markup = r.src.slice(y, m), f.block = !0, r.parentType = L, r.lineMax = H, r.line = p + (k ? 1 : 0), !0;
496
+ if (Math.floor((pos - start) / markerLen) < markerCount) {
497
+ continue;
498
+ }
499
+ pos -= (pos - start) % markerLen;
500
+ pos = state.skipSpaces(pos);
501
+ if (pos < max) {
502
+ continue;
503
+ }
504
+ autoClosed = true;
505
+ break;
506
+ }
507
+ const oldParent = state.parentType;
508
+ const oldLineMax = state.lineMax;
509
+ state.parentType = "root";
510
+ state.lineMax = nextLine;
511
+ token = state.push("admonition_open", "div", 1);
512
+ token.markup = markup;
513
+ token.block = true;
514
+ token.info = type;
515
+ token.map = [startLine, nextLine];
516
+ token = state.push("admonition_title_open", "p", 1);
517
+ token.markup = markup + " " + type;
518
+ token.map = [startLine, nextLine];
519
+ token = state.push("inline", "", 0);
520
+ token.content = title;
521
+ token.map = [startLine, state.line - 1];
522
+ token.children = [];
523
+ token = state.push("admonition_title_close", "p", -1);
524
+ token.markup = markup + " " + type;
525
+ state.md.block.tokenize(state, startLine + 1, nextLine);
526
+ token = state.push("admonition_close", "div", -1);
527
+ token.markup = state.src.slice(start, pos);
528
+ token.block = true;
529
+ state.parentType = oldParent;
530
+ state.lineMax = oldLineMax;
531
+ state.line = nextLine + (autoClosed ? 1 : 0);
532
+ return true;
264
533
  },
265
534
  {
266
535
  alt: ["paragraph", "reference", "blockquote", "list"]
267
536
  }
268
- ), e.renderer.rules.admonition_open = c, e.renderer.rules.admonition_title_open = c, e.renderer.rules.admonition_title_close = c, e.renderer.rules.admonition_close = c;
269
- }, Je = Ze, Xe = (e, a) => {
270
- e.renderer.rules.heading_open = (l, t) => {
271
- var u;
272
- const n = l[t], i = ((u = l[t + 1].children) == null ? void 0 : u.reduce((c, s) => c + (s.content || ""), "")) || "", o = n.markup.length;
273
- return a.headsRef.value.push({
274
- text: i,
275
- level: o
276
- }), n.map && n.level === 0 && (n.attrSet("data-line", String(n.map[0])), n.attrSet(
277
- "id",
278
- a.mdHeadingId(i, o, a.headsRef.value.length)
279
- )), e.renderer.renderToken(l, t, a);
280
- }, e.renderer.rules.heading_close = (l, t, n, i, o) => o.renderToken(l, t, n);
281
- }, Qe = Xe, Ye = (e, a) => {
282
- const l = e.renderer.rules.fence, t = e.utils.unescapeAll, n = /\[(\w*)(?::([\w ]*))?\]/;
283
- function i(s) {
284
- return s.info ? t(s.info).trim() : "";
537
+ );
538
+ md.renderer.rules["admonition_open"] = render;
539
+ md.renderer.rules["admonition_title_open"] = render;
540
+ md.renderer.rules["admonition_title_close"] = render;
541
+ md.renderer.rules["admonition_close"] = render;
542
+ };
543
+ const AdmonitionPlugin$1 = AdmonitionPlugin;
544
+ const HeadingPlugin = (md, options) => {
545
+ md.renderer.rules.heading_open = (tokens, idx) => {
546
+ var _a;
547
+ const token = tokens[idx];
548
+ const text = ((_a = tokens[idx + 1].children) == null ? void 0 : _a.reduce((p, c) => {
549
+ return p + (c.content || "");
550
+ }, "")) || "";
551
+ const level = token.markup.length;
552
+ options.headsRef.value.push({
553
+ text,
554
+ level
555
+ });
556
+ if (token.map && token.level === 0) {
557
+ token.attrSet("data-line", String(token.map[0]));
558
+ token.attrSet(
559
+ "id",
560
+ options.mdHeadingId(text, level, options.headsRef.value.length)
561
+ );
562
+ }
563
+ return md.renderer.renderToken(tokens, idx, options);
564
+ };
565
+ md.renderer.rules.heading_close = (tokens, idx, opts, _env, self) => {
566
+ return self.renderToken(tokens, idx, opts);
567
+ };
568
+ };
569
+ const HeadingPlugin$1 = HeadingPlugin;
570
+ const codetabs = (md, _opts) => {
571
+ const defaultRender = md.renderer.rules.fence, unescapeAll = md.utils.unescapeAll, re = /\[(\w*)(?::([\w ]*))?\]/;
572
+ function getInfo(token) {
573
+ return token.info ? unescapeAll(token.info).trim() : "";
285
574
  }
286
- function o(s) {
287
- const r = i(s), [d = null, b = ""] = (n.exec(r) || []).slice(1);
288
- return [d, b];
575
+ function getGroupAndTab(token) {
576
+ const info = getInfo(token), [group = null, tab = ""] = (re.exec(info) || []).slice(1);
577
+ return [group, tab];
289
578
  }
290
- function u(s) {
291
- const r = i(s);
292
- return r ? r.split(/(\s+)/g)[0] : "";
579
+ function getLangName(token) {
580
+ const info = getInfo(token);
581
+ return info ? info.split(/(\s+)/g)[0] : "";
293
582
  }
294
- const c = (s, r, d, b, v) => {
295
- if (s[r].hidden)
583
+ const fenceGroup = (tokens, idx, options, env, slf) => {
584
+ if (tokens[idx].hidden) {
296
585
  return "";
297
- const [m, p] = o(s[r]);
298
- if (m === null)
299
- return l(s, r, d, b, v);
300
- let f, k, y, w, E = "", $ = "";
301
- for (let C = r; C < s.length && (f = s[C], [k, y] = o(f), k === m); C++)
302
- f.info = f.info.replace(n, ""), f.hidden = !0, w = C - r > 0 ? "" : " checked", E += `<li><input type="radio" name="label-group-${a.editorId}-${r}"${w}><label for="group-${a.editorId}-${r}-tab-${C - r}" onclick="this.previousElementSibling.click()">${y || u(f)}</label></li>
303
- `, $ += `<input type="radio" id="group-${a.editorId}-${r}-tab-${C - r}" name="group-${a.editorId}-${r}"${w}>
304
- ` + l(s, C, d, b, v);
305
- return `<div class="code-tabs">
306
- <ul>
307
- ` + E + `</ul>
308
- ` + $ + "</div>";
586
+ }
587
+ const [GROUP, _] = getGroupAndTab(tokens[idx]);
588
+ if (GROUP === null) {
589
+ return defaultRender(tokens, idx, options, env, slf);
590
+ }
591
+ let token, group, tab, checked, labels = "", pres = "";
592
+ for (let i = idx; i < tokens.length; i++) {
593
+ token = tokens[i];
594
+ [group, tab] = getGroupAndTab(token);
595
+ if (group !== GROUP) {
596
+ break;
597
+ }
598
+ token.info = token.info.replace(re, "");
599
+ token.hidden = true;
600
+ checked = i - idx > 0 ? "" : " checked";
601
+ labels += `<li><input type="radio" name="label-group-${_opts.editorId}-${idx}"${checked}><label for="group-${_opts.editorId}-${idx}-tab-${i - idx}" onclick="this.previousElementSibling.click()">${tab || getLangName(token)}</label></li>
602
+ `;
603
+ pres += `<input type="radio" id="group-${_opts.editorId}-${idx}-tab-${i - idx}" name="group-${_opts.editorId}-${idx}"${checked}>
604
+ ` + defaultRender(tokens, i, options, env, slf);
605
+ }
606
+ return '<div class="code-tabs">\n<ul>\n' + labels + "</ul>\n" + pres + "</div>";
309
607
  };
310
- e.renderer.rules.fence = c;
311
- }, et = Ye, tt = (e) => {
608
+ md.renderer.rules.fence = fenceGroup;
609
+ };
610
+ const CodeTabsPlugin = codetabs;
611
+ const initLineNumber = (md) => {
312
612
  [
313
613
  "paragraph_open",
314
614
  "table_open",
@@ -318,64 +618,85 @@ const Le = (e, a) => {
318
618
  "hr",
319
619
  "html_block",
320
620
  "fence"
321
- ].forEach((a) => {
322
- const l = e.renderer.rules[a];
323
- l ? e.renderer.rules[a] = (t, n, i, o, u) => {
324
- let c;
325
- const s = l(t, n, i, o, u);
326
- return t[n].map && t[n].level === 0 && !/^<!--/.test(s) ? (c = t[n].map[0], s.replace(/^(<[^>]*)/, `$1 data-line="${c}"`)) : s;
327
- } : e.renderer.rules[a] = (t, n, i, o, u) => {
328
- let c;
329
- return t[n].map && t[n].level === 0 && (c = t[n].map[0], t[n].attrSet("data-line", String(c))), u.renderToken(t, n, i);
330
- };
621
+ ].forEach((rule) => {
622
+ const backup = md.renderer.rules[rule];
623
+ if (!backup) {
624
+ md.renderer.rules[rule] = (tokens, idx, options, _env, self) => {
625
+ let line;
626
+ if (tokens[idx].map && tokens[idx].level === 0) {
627
+ line = tokens[idx].map[0];
628
+ tokens[idx].attrSet("data-line", String(line));
629
+ }
630
+ return self.renderToken(tokens, idx, options);
631
+ };
632
+ } else {
633
+ md.renderer.rules[rule] = (tokens, idx, options, env, self) => {
634
+ let line;
635
+ const _htmlCode = backup(tokens, idx, options, env, self);
636
+ if (tokens[idx].map && tokens[idx].level === 0 && !/^<!--/.test(_htmlCode)) {
637
+ line = tokens[idx].map[0];
638
+ return _htmlCode.replace(/^(<[^>]*)/, `$1 data-line="${line}"`);
639
+ }
640
+ return _htmlCode;
641
+ };
642
+ }
331
643
  });
332
- }, nt = (e, a) => {
333
- const { editorConfig: l, markdownItConfig: t, markdownItPlugins: n } = S, i = P("editorId"), o = P("showCodeRowNumber"), u = P("theme"), c = R([]), s = je(e), r = Ge(e), { reRenderRef: d, replaceMermaid: b } = Ue(e), v = He({
334
- html: !0,
335
- breaks: !0
644
+ };
645
+ const useMarkdownIt = (props, previewOnly) => {
646
+ const { editorConfig, markdownItConfig, markdownItPlugins } = configOption;
647
+ const editorId = inject("editorId");
648
+ const showCodeRowNumber = inject("showCodeRowNumber");
649
+ const themeRef = inject("theme");
650
+ const headsRef = ref([]);
651
+ const hljsRef = useHighlight(props);
652
+ const katexRef = useKatex(props);
653
+ const { reRenderRef, replaceMermaid } = useMermaid(props);
654
+ const md = mdit({
655
+ html: true,
656
+ breaks: true
336
657
  });
337
- t(v, {
338
- editorId: i
658
+ markdownItConfig(md, {
659
+ editorId
339
660
  });
340
- const m = [
661
+ const plugins = [
341
662
  {
342
663
  type: "katex",
343
- plugin: Ke,
344
- options: { katexRef: r }
664
+ plugin: KatexPlugin$1,
665
+ options: { katexRef }
345
666
  },
346
667
  {
347
668
  type: "image",
348
- plugin: Me,
349
- options: { figcaption: !0, classes: "md-zoom" }
669
+ plugin: ImageFiguresPlugin,
670
+ options: { figcaption: true, classes: "md-zoom" }
350
671
  },
351
672
  {
352
673
  type: "admonition",
353
- plugin: Je,
674
+ plugin: AdmonitionPlugin$1,
354
675
  options: {}
355
676
  },
356
677
  {
357
678
  type: "taskList",
358
- plugin: Re,
679
+ plugin: TaskListPlugin,
359
680
  options: {}
360
681
  },
361
682
  {
362
683
  type: "heading",
363
- plugin: Qe,
364
- options: { mdHeadingId: e.mdHeadingId, headsRef: c }
684
+ plugin: HeadingPlugin$1,
685
+ options: { mdHeadingId: props.mdHeadingId, headsRef }
365
686
  },
366
687
  {
367
688
  type: "codeTabs",
368
- plugin: et,
369
- options: { editorId: i }
689
+ plugin: CodeTabsPlugin,
690
+ options: { editorId }
370
691
  },
371
692
  {
372
693
  type: "xss",
373
- plugin: Ae,
694
+ plugin: XSSPlugin,
374
695
  options: {
375
696
  // https://github.com/leizongmin/js-xss/blob/master/README.zh.md
376
- xss($) {
697
+ xss(xss) {
377
698
  return {
378
- whiteList: Object.assign({}, $.getDefaultWhiteList(), {
699
+ whiteList: Object.assign({}, xss.getDefaultWhiteList(), {
379
700
  // 支持任务列表
380
701
  input: ["class", "disabled", "type", "checked"],
381
702
  // 主要支持youtobe、腾讯视频、哔哩哔哩等内嵌视频代码
@@ -397,66 +718,97 @@ const Le = (e, a) => {
397
718
  }
398
719
  }
399
720
  ];
400
- e.noMermaid || m.push({
401
- type: "mermaid",
402
- plugin: Ve,
403
- options: { themeRef: u }
404
- }), n(m, {
405
- editorId: i
406
- }).forEach(($) => {
407
- v.use($.plugin, $.options);
721
+ if (!props.noMermaid) {
722
+ plugins.push({
723
+ type: "mermaid",
724
+ plugin: MermaidPlugin$1,
725
+ options: { themeRef }
726
+ });
727
+ }
728
+ markdownItPlugins(plugins, {
729
+ editorId
730
+ }).forEach((item) => {
731
+ md.use(item.plugin, item.options);
408
732
  });
409
- const p = v.options.highlight;
410
- v.set({
411
- highlight: ($, C, L) => {
412
- if (p) {
413
- const N = p($, C, L);
414
- if (N)
415
- return N;
733
+ const userDefHighlight = md.options.highlight;
734
+ md.set({
735
+ highlight: (str, language, attrs) => {
736
+ if (userDefHighlight) {
737
+ const result = userDefHighlight(str, language, attrs);
738
+ if (result) {
739
+ return result;
740
+ }
416
741
  }
417
- let H;
418
- !e.noHighlight && s.value ? s.value.getLanguage(C) ? H = s.value.highlight($, {
419
- language: C,
420
- ignoreIllegals: !0
421
- }).value : H = s.value.highlightAuto($).value : H = v.utils.escapeHtml($);
422
- const fe = o ? $e(H.replace(/^\n+|\n+$/g, "")) : `<span class="code-block">${H.replace(/^\n+|\n+$/g, "")}</span>`;
423
- return `<pre><code class="language-${C}" language=${C}>${fe}</code></pre>`;
742
+ let codeHtml;
743
+ if (!props.noHighlight && hljsRef.value) {
744
+ const hljsLang = hljsRef.value.getLanguage(language);
745
+ if (hljsLang) {
746
+ codeHtml = hljsRef.value.highlight(str, {
747
+ language,
748
+ ignoreIllegals: true
749
+ }).value;
750
+ } else {
751
+ codeHtml = hljsRef.value.highlightAuto(str).value;
752
+ }
753
+ } else {
754
+ codeHtml = md.utils.escapeHtml(str);
755
+ }
756
+ const codeSpan = showCodeRowNumber ? generateCodeRowNumber(codeHtml.replace(/^\n+|\n+$/g, "")) : `<span class="code-block">${codeHtml.replace(/^\n+|\n+$/g, "")}</span>`;
757
+ return `<pre><code class="language-${language}" language=${language}>${codeSpan}</code></pre>`;
424
758
  }
425
- }), tt(v);
426
- const f = R(`_article-key_${U()}`), k = R(e.sanitize(v.render(e.modelValue))), y = () => {
427
- g.emit(i, A, k.value), e.onHtmlChanged(k.value), e.onGetCatalog(c.value), g.emit(i, K, c.value), b();
759
+ });
760
+ initLineNumber(md);
761
+ const key = ref(`_article-key_${uuid()}`);
762
+ const html = ref(props.sanitize(md.render(props.modelValue)));
763
+ const updatedTodo = () => {
764
+ bus.emit(editorId, BUILD_FINISHED, html.value);
765
+ props.onHtmlChanged(html.value);
766
+ props.onGetCatalog(headsRef.value);
767
+ bus.emit(editorId, CATALOG_CHANGED, headsRef.value);
768
+ replaceMermaid();
428
769
  };
429
- _(y);
430
- const w = () => {
431
- c.value = [], k.value = e.sanitize(v.render(e.modelValue)), y();
432
- }, E = F(() => (e.noKatex || r.value) && (e.noHighlight || s.value));
433
- return I(
434
- [te(e, "modelValue"), E, d],
435
- ie(
436
- w,
437
- (l == null ? void 0 : l.renderDelay) !== void 0 ? l == null ? void 0 : l.renderDelay : a ? 0 : 500
770
+ onMounted(updatedTodo);
771
+ const markHtml = () => {
772
+ headsRef.value = [];
773
+ html.value = props.sanitize(md.render(props.modelValue));
774
+ updatedTodo();
775
+ };
776
+ const needReRender = computed(() => {
777
+ return (props.noKatex || katexRef.value) && (props.noHighlight || hljsRef.value);
778
+ });
779
+ watch(
780
+ [toRef(props, "modelValue"), needReRender, reRenderRef],
781
+ debounce(
782
+ markHtml,
783
+ (editorConfig == null ? void 0 : editorConfig.renderDelay) !== void 0 ? editorConfig == null ? void 0 : editorConfig.renderDelay : previewOnly ? 0 : 500
438
784
  )
439
- ), _(() => {
440
- g.on(i, {
441
- name: Ce,
785
+ );
786
+ onMounted(() => {
787
+ bus.on(editorId, {
788
+ name: PUSH_CATALOG,
442
789
  callback() {
443
- g.emit(i, K, c.value);
790
+ bus.emit(editorId, CATALOG_CHANGED, headsRef.value);
444
791
  }
445
- }), g.on(i, {
446
- name: G,
792
+ });
793
+ bus.on(editorId, {
794
+ name: RERENDER,
447
795
  callback: () => {
448
- w(), f.value = `_article-key_${U()}`;
796
+ markHtml();
797
+ key.value = `_article-key_${uuid()}`;
449
798
  }
450
799
  });
451
- }), { html: k, key: f };
452
- }, ot = nt, ce = {
800
+ });
801
+ return { html, key };
802
+ };
803
+ const useMarkdownIt$1 = useMarkdownIt;
804
+ const contentPreviewProps = {
453
805
  modelValue: {
454
806
  type: String,
455
807
  default: ""
456
808
  },
457
809
  setting: {
458
810
  type: Object,
459
- default: () => ({ preview: !0 })
811
+ default: () => ({ preview: true })
460
812
  },
461
813
  onHtmlChanged: {
462
814
  type: Function,
@@ -474,28 +826,28 @@ const Le = (e, a) => {
474
826
  },
475
827
  noMermaid: {
476
828
  type: Boolean,
477
- default: !1
829
+ default: false
478
830
  },
479
831
  sanitize: {
480
832
  type: Function,
481
- default: (e) => e
833
+ default: (html) => html
482
834
  },
483
835
  // 不使用该函数功能
484
836
  noKatex: {
485
837
  type: Boolean,
486
- default: !1
838
+ default: false
487
839
  },
488
840
  formatCopiedText: {
489
841
  type: Function,
490
- default: (e) => e
842
+ default: (text) => text
491
843
  },
492
844
  noHighlight: {
493
845
  type: Boolean,
494
- default: !1
846
+ default: false
495
847
  },
496
848
  previewOnly: {
497
849
  type: Boolean,
498
- default: !1
850
+ default: false
499
851
  },
500
852
  noImgZoomIn: {
501
853
  type: Boolean
@@ -503,8 +855,9 @@ const Le = (e, a) => {
503
855
  sanitizeMermaid: {
504
856
  type: Function
505
857
  }
506
- }, bt = {
507
- ...ce,
858
+ };
859
+ const contentProps = {
860
+ ...contentPreviewProps,
508
861
  updateModelValue: {
509
862
  type: Function,
510
863
  default: () => {
@@ -580,296 +933,402 @@ const Le = (e, a) => {
580
933
  onInputBoxWitdhChange: {
581
934
  type: Function
582
935
  }
583
- }, rt = /* @__PURE__ */ ne({
936
+ };
937
+ const ContentPreview = /* @__PURE__ */ defineComponent({
584
938
  name: "ContentPreview",
585
- props: ce,
586
- setup(e) {
587
- const a = P("editorId"), l = P("previewTheme"), t = P("showCodeRowNumber"), {
588
- html: n,
589
- key: i
590
- } = ot(e, e.previewOnly);
591
- return Oe(e, n, i), Le(e, n), () => M(pe, null, [e.setting.preview && M("div", {
592
- id: `${a}-preview-wrapper`,
593
- class: `${h}-preview-wrapper`,
594
- key: "content-preview-wrapper"
595
- }, [M("div", {
596
- key: i.value,
597
- id: `${a}-preview`,
598
- class: [`${h}-preview`, `${l == null ? void 0 : l.value}-theme`, t && `${h}-scrn`],
599
- innerHTML: n.value
600
- }, null)]), !e.previewOnly && e.setting.htmlPreview && M("div", {
601
- id: `${a}-html-wrapper`,
602
- class: `${h}-preview-wrapper`,
603
- key: "html-preview-wrapper"
604
- }, [M("div", {
605
- class: `${h}-html`
606
- }, [n.value])])]);
939
+ props: contentPreviewProps,
940
+ setup(props) {
941
+ const editorId = inject("editorId");
942
+ const previewTheme = inject("previewTheme");
943
+ const showCodeRowNumber = inject("showCodeRowNumber");
944
+ const {
945
+ html,
946
+ key
947
+ } = useMarkdownIt$1(props, props.previewOnly);
948
+ useCopyCode(props, html, key);
949
+ userZoom(props, html);
950
+ return () => {
951
+ return createVNode(Fragment, null, [props.setting.preview && createVNode("div", {
952
+ "id": `${editorId}-preview-wrapper`,
953
+ "class": `${prefix}-preview-wrapper`,
954
+ "key": "content-preview-wrapper"
955
+ }, [createVNode("div", {
956
+ "key": key.value,
957
+ "id": `${editorId}-preview`,
958
+ "class": [`${prefix}-preview`, `${previewTheme == null ? void 0 : previewTheme.value}-theme`, showCodeRowNumber && `${prefix}-scrn`],
959
+ "innerHTML": html.value
960
+ }, null)]), !props.previewOnly && props.setting.htmlPreview && createVNode("div", {
961
+ "id": `${editorId}-html-wrapper`,
962
+ "class": `${prefix}-preview-wrapper`,
963
+ "key": "html-preview-wrapper"
964
+ }, [createVNode("div", {
965
+ "class": `${prefix}-html`
966
+ }, [html.value])])]);
967
+ };
607
968
  }
608
- }), wt = (e, a) => {
609
- const { editorId: l } = e, t = oe({
969
+ });
970
+ const useOnSave = (props, context) => {
971
+ const { editorId } = props;
972
+ const state = reactive({
610
973
  // 是否已编译成html
611
- buildFinished: !1,
974
+ buildFinished: false,
612
975
  // 存储当前最新的html
613
976
  html: ""
614
977
  });
615
- I(
616
- () => e.modelValue,
978
+ watch(
979
+ () => props.modelValue,
617
980
  () => {
618
- t.buildFinished = !1;
981
+ state.buildFinished = false;
619
982
  }
620
- ), _(() => {
621
- g.on(l, {
622
- name: A,
623
- callback(n) {
624
- t.buildFinished = !0, t.html = n;
983
+ );
984
+ onMounted(() => {
985
+ bus.on(editorId, {
986
+ name: BUILD_FINISHED,
987
+ callback(html) {
988
+ state.buildFinished = true;
989
+ state.html = html;
625
990
  }
626
- }), g.on(l, {
627
- name: re,
991
+ });
992
+ bus.on(editorId, {
993
+ name: ON_SAVE,
628
994
  callback() {
629
- const n = new Promise((i) => {
630
- if (t.buildFinished)
631
- i(t.html);
632
- else {
633
- const o = (u) => {
634
- i(u), g.remove(l, A, o);
995
+ const htmlPromise = new Promise((rev) => {
996
+ if (state.buildFinished) {
997
+ rev(state.html);
998
+ } else {
999
+ const buildFinishedCallback = (html) => {
1000
+ rev(html);
1001
+ bus.remove(editorId, BUILD_FINISHED, buildFinishedCallback);
635
1002
  };
636
- g.on(l, {
637
- name: A,
638
- callback: o
1003
+ bus.on(editorId, {
1004
+ name: BUILD_FINISHED,
1005
+ callback: buildFinishedCallback
639
1006
  });
640
1007
  }
641
1008
  });
642
- e.onSave ? e.onSave(e.modelValue, n) : a.emit("onSave", e.modelValue, n);
1009
+ if (props.onSave) {
1010
+ props.onSave(props.modelValue, htmlPromise);
1011
+ } else {
1012
+ context.emit("onSave", props.modelValue, htmlPromise);
1013
+ }
643
1014
  }
644
1015
  });
645
1016
  });
646
- }, se = (e) => {
647
- var n, i;
648
- const { editorId: a } = e, l = (i = (n = S) == null ? void 0 : n.editorExtensions) == null ? void 0 : i.highlight;
649
- x("editorId", a), x(
1017
+ };
1018
+ const useProvidePreview = (props) => {
1019
+ var _a, _b;
1020
+ const { editorId } = props;
1021
+ const highlightConfig = (_b = (_a = configOption) == null ? void 0 : _a.editorExtensions) == null ? void 0 : _b.highlight;
1022
+ provide("editorId", editorId);
1023
+ provide(
650
1024
  "theme",
651
- F(() => e.theme)
652
- ), x(
1025
+ computed(() => props.theme)
1026
+ );
1027
+ provide(
653
1028
  "language",
654
- F(() => e.language)
655
- ), x(
1029
+ computed(() => props.language)
1030
+ );
1031
+ provide(
656
1032
  "highlight",
657
- F(() => {
658
- const o = {
659
- ...V,
660
- ...l == null ? void 0 : l.css
661
- }, u = e.codeStyleReverse && e.codeStyleReverseList.includes(e.previewTheme) ? "dark" : e.theme;
1033
+ computed(() => {
1034
+ const cssList = {
1035
+ ...codeCss,
1036
+ ...highlightConfig == null ? void 0 : highlightConfig.css
1037
+ };
1038
+ const theme = props.codeStyleReverse && props.codeStyleReverseList.includes(props.previewTheme) ? "dark" : props.theme;
662
1039
  return {
663
- js: (l == null ? void 0 : l.js) || ye,
664
- css: o[e.codeTheme] ? o[e.codeTheme][u] : V.atom[u]
1040
+ js: (highlightConfig == null ? void 0 : highlightConfig.js) || highlightUrl,
1041
+ css: cssList[props.codeTheme] ? cssList[props.codeTheme][theme] : codeCss.atom[theme]
665
1042
  };
666
1043
  })
667
- ), x("showCodeRowNumber", e.showCodeRowNumber);
668
- const t = F(() => {
669
- var u, c;
670
- const o = {
671
- ...z,
672
- ...(c = (u = S) == null ? void 0 : u.editorConfig) == null ? void 0 : c.languageUserDefined
1044
+ );
1045
+ provide("showCodeRowNumber", props.showCodeRowNumber);
1046
+ const usedLanguageText = computed(() => {
1047
+ var _a2, _b2;
1048
+ const allText = {
1049
+ ...staticTextDefault,
1050
+ ...(_b2 = (_a2 = configOption) == null ? void 0 : _a2.editorConfig) == null ? void 0 : _b2.languageUserDefined
673
1051
  };
674
- return o[e.language] ? o[e.language] : z["zh-CN"];
1052
+ if (allText[props.language]) {
1053
+ return allText[props.language];
1054
+ } else {
1055
+ return staticTextDefault["zh-CN"];
1056
+ }
675
1057
  });
676
- x("usedLanguageText", t), x(
1058
+ provide("usedLanguageText", usedLanguageText);
1059
+ provide(
677
1060
  "previewTheme",
678
- F(() => e.previewTheme)
679
- ), x(
1061
+ computed(() => props.previewTheme)
1062
+ );
1063
+ provide(
680
1064
  "customIcon",
681
- F(() => e.customIcon)
1065
+ computed(() => props.customIcon)
682
1066
  );
683
- }, kt = (e) => {
684
- se(e), x("tabWidth", e.tabWidth);
685
- }, ue = (e) => {
686
- _(() => {
687
- var a, l;
688
- if (!e.noIconfont)
689
- if (S.iconfontType === "svg") {
690
- const t = document.createElement("script");
691
- t.src = ((a = S.editorExtensions) == null ? void 0 : a.iconfont) || ve, t.id = `${h}-icon`, T(t);
1067
+ };
1068
+ const useProvide = (props) => {
1069
+ useProvidePreview(props);
1070
+ provide("tabWidth", props.tabWidth);
1071
+ };
1072
+ const useExpansionPreview = (props) => {
1073
+ onMounted(() => {
1074
+ var _a, _b;
1075
+ if (!props.noIconfont) {
1076
+ if (configOption.iconfontType === "svg") {
1077
+ const iconfontScript = document.createElement("script");
1078
+ iconfontScript.src = ((_a = configOption.editorExtensions) == null ? void 0 : _a.iconfont) || iconfontSvgUrl;
1079
+ iconfontScript.id = `${prefix}-icon`;
1080
+ appendHandler(iconfontScript);
692
1081
  } else {
693
- const t = document.createElement("link");
694
- t.rel = "stylesheet", t.href = ((l = S.editorExtensions) == null ? void 0 : l.iconfontClass) || be, t.id = `${h}-icon-class`, T(t);
1082
+ const iconfontLink = document.createElement("link");
1083
+ iconfontLink.rel = "stylesheet";
1084
+ iconfontLink.href = ((_b = configOption.editorExtensions) == null ? void 0 : _b.iconfontClass) || iconfontClassUrl;
1085
+ iconfontLink.id = `${prefix}-icon-class`;
1086
+ appendHandler(iconfontLink);
695
1087
  }
1088
+ }
696
1089
  });
697
- }, $t = (e) => {
698
- var u, c, s, r, d, b;
699
- const { noPrettier: a, noUploadImg: l } = e, { editorExtensions: t } = S, n = a || !!((c = (u = S.editorExtensions) == null ? void 0 : u.prettier) != null && c.prettierInstance), i = a || !!((r = (s = S.editorExtensions) == null ? void 0 : s.prettier) != null && r.parserMarkdownInstance), o = l || !!((b = (d = S.editorExtensions) == null ? void 0 : d.cropper) != null && b.instance);
700
- _(() => {
701
- var k, y, w, E;
702
- const v = document.createElement("script"), m = document.createElement("script");
703
- v.src = ((k = t == null ? void 0 : t.prettier) == null ? void 0 : k.standaloneJs) || W.main, v.id = `${h}-prettier`, m.src = ((y = t == null ? void 0 : t.prettier) == null ? void 0 : y.parserMarkdownJs) || W.markdown, m.id = `${h}-prettierMD`;
704
- const p = document.createElement("link");
705
- p.rel = "stylesheet", p.href = ((w = t == null ? void 0 : t.cropper) == null ? void 0 : w.css) || q.css, p.id = `${h}-cropperCss`;
706
- const f = document.createElement("script");
707
- f.src = ((E = t == null ? void 0 : t.cropper) == null ? void 0 : E.js) || q.js, f.id = `${h}-cropper`, o || (T(p), T(f)), n || T(v), i || T(m);
708
- }), ue(e);
709
- }, Ct = (e, a) => {
710
- const { editorId: l } = e;
711
- _(() => {
712
- g.on(l, {
713
- name: Ie,
714
- callback: (t) => {
715
- e.onError instanceof Function ? e.onError(t) : a.emit("onError", t);
1090
+ };
1091
+ const useExpansion = (props) => {
1092
+ var _a, _b, _c, _d, _e, _f;
1093
+ const { noPrettier, noUploadImg } = props;
1094
+ const { editorExtensions } = configOption;
1095
+ const noPrettierScript = noPrettier || !!((_b = (_a = configOption.editorExtensions) == null ? void 0 : _a.prettier) == null ? void 0 : _b.prettierInstance);
1096
+ const noParserMarkdownScript = noPrettier || !!((_d = (_c = configOption.editorExtensions) == null ? void 0 : _c.prettier) == null ? void 0 : _d.parserMarkdownInstance);
1097
+ const noCropperScript = noUploadImg || !!((_f = (_e = configOption.editorExtensions) == null ? void 0 : _e.cropper) == null ? void 0 : _f.instance);
1098
+ onMounted(() => {
1099
+ var _a2, _b2, _c2, _d2;
1100
+ const prettierScript = document.createElement("script");
1101
+ const prettierMDScript = document.createElement("script");
1102
+ prettierScript.src = ((_a2 = editorExtensions == null ? void 0 : editorExtensions.prettier) == null ? void 0 : _a2.standaloneJs) || prettierUrl.main;
1103
+ prettierScript.id = `${prefix}-prettier`;
1104
+ prettierMDScript.src = ((_b2 = editorExtensions == null ? void 0 : editorExtensions.prettier) == null ? void 0 : _b2.parserMarkdownJs) || prettierUrl.markdown;
1105
+ prettierMDScript.id = `${prefix}-prettierMD`;
1106
+ const cropperLink = document.createElement("link");
1107
+ cropperLink.rel = "stylesheet";
1108
+ cropperLink.href = ((_c2 = editorExtensions == null ? void 0 : editorExtensions.cropper) == null ? void 0 : _c2.css) || cropperUrl.css;
1109
+ cropperLink.id = `${prefix}-cropperCss`;
1110
+ const cropperScript = document.createElement("script");
1111
+ cropperScript.src = ((_d2 = editorExtensions == null ? void 0 : editorExtensions.cropper) == null ? void 0 : _d2.js) || cropperUrl.js;
1112
+ cropperScript.id = `${prefix}-cropper`;
1113
+ if (!noCropperScript) {
1114
+ appendHandler(cropperLink);
1115
+ appendHandler(cropperScript);
1116
+ }
1117
+ if (!noPrettierScript) {
1118
+ appendHandler(prettierScript);
1119
+ }
1120
+ if (!noParserMarkdownScript) {
1121
+ appendHandler(prettierMDScript);
1122
+ }
1123
+ });
1124
+ useExpansionPreview(props);
1125
+ };
1126
+ const useErrorCatcher = (props, context) => {
1127
+ const { editorId } = props;
1128
+ onMounted(() => {
1129
+ bus.on(editorId, {
1130
+ name: ERROR_CATCHER,
1131
+ callback: (err) => {
1132
+ if (props.onError instanceof Function) {
1133
+ props.onError(err);
1134
+ } else {
1135
+ context.emit("onError", err);
1136
+ }
716
1137
  }
717
1138
  });
718
1139
  });
719
- }, It = (e, a) => {
720
- const { editorId: l } = e, t = oe({
721
- pageFullscreen: e.pageFullscreen,
722
- fullscreen: !1,
723
- preview: e.preview,
724
- htmlPreview: e.preview ? !1 : e.htmlPreview
725
- }), n = (u, c) => {
726
- t[u] = c === void 0 ? !t[u] : c, u === "preview" && t.preview ? t.htmlPreview = !1 : u === "htmlPreview" && t.htmlPreview && (t.preview = !1);
1140
+ };
1141
+ const useConfig = (props, context) => {
1142
+ const { editorId } = props;
1143
+ const setting = reactive({
1144
+ pageFullscreen: props.pageFullscreen,
1145
+ fullscreen: false,
1146
+ preview: props.preview,
1147
+ htmlPreview: props.preview ? false : props.htmlPreview
1148
+ });
1149
+ const updateSetting = (k, v) => {
1150
+ setting[k] = v === void 0 ? !setting[k] : v;
1151
+ if (k === "preview" && setting.preview) {
1152
+ setting.htmlPreview = false;
1153
+ } else if (k === "htmlPreview" && setting.htmlPreview) {
1154
+ setting.preview = false;
1155
+ }
727
1156
  };
728
- let i = "";
729
- const o = () => {
730
- t.pageFullscreen || t.fullscreen ? document.body.style.overflow = "hidden" : document.body.style.overflow = i;
1157
+ let bodyOverflowHistory = "";
1158
+ const adjustBody = () => {
1159
+ if (setting.pageFullscreen || setting.fullscreen) {
1160
+ document.body.style.overflow = "hidden";
1161
+ } else {
1162
+ document.body.style.overflow = bodyOverflowHistory;
1163
+ }
731
1164
  };
732
- return I(() => [t.pageFullscreen, t.fullscreen], o), _(() => {
733
- g.on(l, {
734
- name: Se,
735
- callback(u, c) {
736
- const s = (r) => {
737
- g.emit(l, le, "image", {
1165
+ watch(() => [setting.pageFullscreen, setting.fullscreen], adjustBody);
1166
+ onMounted(() => {
1167
+ bus.on(editorId, {
1168
+ name: UPLOAD_IMAGE,
1169
+ callback(files, cb) {
1170
+ const insertHanlder = (urls) => {
1171
+ bus.emit(editorId, REPLACE, "image", {
738
1172
  desc: "",
739
- urls: r
740
- }), c && c();
1173
+ urls
1174
+ });
1175
+ cb && cb();
741
1176
  };
742
- e.onUploadImg ? e.onUploadImg(u, s) : a.emit("onUploadImg", u, s);
1177
+ if (props.onUploadImg) {
1178
+ props.onUploadImg(files, insertHanlder);
1179
+ } else {
1180
+ context.emit("onUploadImg", files, insertHanlder);
1181
+ }
743
1182
  }
744
- }), i = document.body.style.overflow, o();
745
- }), [t, n];
746
- }, St = (e) => {
747
- const { editorId: a } = e, l = R(!1);
748
- return _(() => {
749
- g.on(a, {
750
- name: ae,
751
- callback: (n) => {
752
- n === void 0 ? l.value = !l.value : l.value = n;
1183
+ });
1184
+ bodyOverflowHistory = document.body.style.overflow;
1185
+ adjustBody();
1186
+ });
1187
+ return [setting, updateSetting];
1188
+ };
1189
+ const useCatalog = (props) => {
1190
+ const { editorId } = props;
1191
+ const catalogShow = ref(false);
1192
+ onMounted(() => {
1193
+ bus.on(editorId, {
1194
+ name: CHANGE_CATALOG_VISIBLE,
1195
+ callback: (v) => {
1196
+ if (v === void 0) {
1197
+ catalogShow.value = !catalogShow.value;
1198
+ } else {
1199
+ catalogShow.value = v;
1200
+ }
753
1201
  }
754
1202
  });
755
- }), F(() => !e.toolbarsExclude.includes("catalog") && e.toolbars.includes("catalog") && l.value);
756
- }, Et = (e, a, l, t, n, i) => {
757
- const { editorId: o } = e;
758
- I(
759
- () => t.pageFullscreen,
760
- (c) => {
761
- g.emit(o, Z, c);
1203
+ });
1204
+ const catalogVisible = computed(() => {
1205
+ return !props.toolbarsExclude.includes("catalog") && props.toolbars.includes("catalog") && catalogShow.value;
1206
+ });
1207
+ return catalogVisible;
1208
+ };
1209
+ const useExpose$1 = (props, ctx, catalogVisible, setting, updateSetting, codeRef) => {
1210
+ const { editorId } = props;
1211
+ watch(
1212
+ () => setting.pageFullscreen,
1213
+ (newVal) => {
1214
+ bus.emit(editorId, PAGE_FULL_SCREEN_CHANGED, newVal);
762
1215
  }
763
- ), I(
764
- () => t.fullscreen,
765
- (c) => {
766
- g.emit(o, J, c);
1216
+ );
1217
+ watch(
1218
+ () => setting.fullscreen,
1219
+ (newVal) => {
1220
+ bus.emit(editorId, FULL_SCREEN_CHANGED, newVal);
767
1221
  }
768
- ), I(
769
- () => t.preview,
770
- (c) => {
771
- g.emit(o, X, c);
1222
+ );
1223
+ watch(
1224
+ () => setting.preview,
1225
+ (newVal) => {
1226
+ bus.emit(editorId, PREVIEW_CHANGED, newVal);
772
1227
  }
773
- ), I(
774
- () => t.htmlPreview,
775
- (c) => {
776
- g.emit(o, Q, c);
1228
+ );
1229
+ watch(
1230
+ () => setting.htmlPreview,
1231
+ (newVal) => {
1232
+ bus.emit(editorId, HTML_PREVIEW_CHANGED, newVal);
777
1233
  }
778
- ), I(l, (c) => {
779
- g.emit(o, Y, c);
1234
+ );
1235
+ watch(catalogVisible, (newVal) => {
1236
+ bus.emit(editorId, CATALOG_VISIBLE_CHANGED, newVal);
780
1237
  });
781
- const u = {
782
- on(c, s) {
783
- switch (c) {
1238
+ const exposeParam = {
1239
+ on(eventName, callBack) {
1240
+ switch (eventName) {
784
1241
  case "pageFullscreen": {
785
- g.on(o, {
786
- name: Z,
787
- callback(r) {
788
- s(r);
1242
+ bus.on(editorId, {
1243
+ name: PAGE_FULL_SCREEN_CHANGED,
1244
+ callback(status) {
1245
+ callBack(status);
789
1246
  }
790
1247
  });
791
1248
  break;
792
1249
  }
793
1250
  case "fullscreen": {
794
- g.on(o, {
795
- name: J,
796
- callback(r) {
797
- s(r);
1251
+ bus.on(editorId, {
1252
+ name: FULL_SCREEN_CHANGED,
1253
+ callback(status) {
1254
+ callBack(status);
798
1255
  }
799
1256
  });
800
1257
  break;
801
1258
  }
802
1259
  case "preview": {
803
- g.on(o, {
804
- name: X,
805
- callback(r) {
806
- s(r);
1260
+ bus.on(editorId, {
1261
+ name: PREVIEW_CHANGED,
1262
+ callback(status) {
1263
+ callBack(status);
807
1264
  }
808
1265
  });
809
1266
  break;
810
1267
  }
811
1268
  case "htmlPreview": {
812
- g.on(o, {
813
- name: Q,
814
- callback(r) {
815
- s(r);
1269
+ bus.on(editorId, {
1270
+ name: HTML_PREVIEW_CHANGED,
1271
+ callback(status) {
1272
+ callBack(status);
816
1273
  }
817
1274
  });
818
1275
  break;
819
1276
  }
820
1277
  case "catalog": {
821
- g.on(o, {
822
- name: Y,
823
- callback(r) {
824
- s(r);
1278
+ bus.on(editorId, {
1279
+ name: CATALOG_VISIBLE_CHANGED,
1280
+ callback(status) {
1281
+ callBack(status);
825
1282
  }
826
1283
  });
827
1284
  break;
828
1285
  }
829
1286
  }
830
1287
  },
831
- togglePageFullscreen(c) {
832
- n("pageFullscreen", c);
1288
+ togglePageFullscreen(status) {
1289
+ updateSetting("pageFullscreen", status);
833
1290
  },
834
- toggleFullscreen(c) {
835
- g.emit(o, Ee, c);
1291
+ toggleFullscreen(status) {
1292
+ bus.emit(editorId, CHANGE_FULL_SCREEN, status);
836
1293
  },
837
- togglePreview(c) {
838
- n("preview", c);
1294
+ togglePreview(status) {
1295
+ updateSetting("preview", status);
839
1296
  },
840
- toggleHtmlPreview(c) {
841
- n("htmlPreview", c);
1297
+ toggleHtmlPreview(status) {
1298
+ updateSetting("htmlPreview", status);
842
1299
  },
843
- toggleCatalog(c) {
844
- g.emit(o, ae, c);
1300
+ toggleCatalog(status) {
1301
+ bus.emit(editorId, CHANGE_CATALOG_VISIBLE, status);
845
1302
  },
846
1303
  triggerSave() {
847
- g.emit(o, re);
1304
+ bus.emit(editorId, ON_SAVE);
848
1305
  },
849
- insert(c) {
850
- g.emit(o, le, "universal", { generate: c });
1306
+ insert(generate) {
1307
+ bus.emit(editorId, REPLACE, "universal", { generate });
851
1308
  },
852
- focus(c) {
853
- var s;
854
- (s = i.value) == null || s.focus(c);
1309
+ focus(options) {
1310
+ var _a;
1311
+ (_a = codeRef.value) == null ? void 0 : _a.focus(options);
855
1312
  },
856
1313
  rerender() {
857
- g.emit(o, G);
1314
+ bus.emit(editorId, RERENDER);
858
1315
  },
859
1316
  getSelectedText() {
860
- var c;
861
- return (c = i.value) == null ? void 0 : c.getSelectedText();
1317
+ var _a;
1318
+ return (_a = codeRef.value) == null ? void 0 : _a.getSelectedText();
862
1319
  },
863
1320
  resetHistory() {
864
- var c;
865
- (c = i.value) == null || c.resetHistory();
1321
+ var _a;
1322
+ (_a = codeRef.value) == null ? void 0 : _a.resetHistory();
866
1323
  },
867
- domEventHandlers(c) {
868
- g.emit(o, Pe, c);
1324
+ domEventHandlers(handlers) {
1325
+ bus.emit(editorId, EVENT_LISTENER, handlers);
869
1326
  }
870
1327
  };
871
- a.expose(u);
872
- }, at = (e) => e, de = {
1328
+ ctx.expose(exposeParam);
1329
+ };
1330
+ const mdHeadingId = (text) => text;
1331
+ const mdPreviewProps = {
873
1332
  /**
874
1333
  * markdown content.
875
1334
  *
@@ -925,7 +1384,7 @@ const Le = (e, a) => {
925
1384
  */
926
1385
  editorId: {
927
1386
  type: String,
928
- default: () => _e("md-editor-v3_")
1387
+ default: () => getNextId("md-editor-v3_")
929
1388
  },
930
1389
  /**
931
1390
  * 预览中代码是否显示行号
@@ -934,7 +1393,7 @@ const Le = (e, a) => {
934
1393
  */
935
1394
  showCodeRowNumber: {
936
1395
  type: Boolean,
937
- default: !1
1396
+ default: false
938
1397
  },
939
1398
  /**
940
1399
  * 预览内容样式
@@ -959,7 +1418,7 @@ const Le = (e, a) => {
959
1418
  */
960
1419
  mdHeadingId: {
961
1420
  type: Function,
962
- default: at
1421
+ default: mdHeadingId
963
1422
  },
964
1423
  /**
965
1424
  *
@@ -970,7 +1429,7 @@ const Le = (e, a) => {
970
1429
  */
971
1430
  sanitize: {
972
1431
  type: Function,
973
- default: (e) => e
1432
+ default: (html) => html
974
1433
  },
975
1434
  /**
976
1435
  * 不使用该mermaid
@@ -979,7 +1438,7 @@ const Le = (e, a) => {
979
1438
  */
980
1439
  noMermaid: {
981
1440
  type: Boolean,
982
- default: !1
1441
+ default: false
983
1442
  },
984
1443
  /**
985
1444
  * 不使用katex
@@ -988,7 +1447,7 @@ const Le = (e, a) => {
988
1447
  */
989
1448
  noKatex: {
990
1449
  type: Boolean,
991
- default: !1
1450
+ default: false
992
1451
  },
993
1452
  /**
994
1453
  * 代码主题
@@ -1014,7 +1473,7 @@ const Le = (e, a) => {
1014
1473
  */
1015
1474
  formatCopiedText: {
1016
1475
  type: Function,
1017
- default: (e) => e
1476
+ default: (text) => text
1018
1477
  },
1019
1478
  /**
1020
1479
  * 某些预览主题的代码模块背景是暗色系
@@ -1024,7 +1483,7 @@ const Le = (e, a) => {
1024
1483
  */
1025
1484
  codeStyleReverse: {
1026
1485
  type: Boolean,
1027
- default: !0
1486
+ default: true
1028
1487
  },
1029
1488
  /**
1030
1489
  * 需要自动调整的预览主题
@@ -1037,14 +1496,14 @@ const Le = (e, a) => {
1037
1496
  },
1038
1497
  noHighlight: {
1039
1498
  type: Boolean,
1040
- default: !1
1499
+ default: false
1041
1500
  },
1042
1501
  /**
1043
1502
  * 是否关闭编辑器默认的放大缩小功能
1044
1503
  */
1045
1504
  noImgZoomIn: {
1046
1505
  type: Boolean,
1047
- default: !1
1506
+ default: false
1048
1507
  },
1049
1508
  /**
1050
1509
  * 自定义的图标
@@ -1055,10 +1514,11 @@ const Le = (e, a) => {
1055
1514
  },
1056
1515
  sanitizeMermaid: {
1057
1516
  type: Function,
1058
- default: (e) => Promise.resolve(e)
1517
+ default: (h) => Promise.resolve(h)
1059
1518
  }
1060
- }, Pt = {
1061
- ...de,
1519
+ };
1520
+ const editorProps = {
1521
+ ...mdPreviewProps,
1062
1522
  /**
1063
1523
  * input回调事件
1064
1524
  */
@@ -1084,7 +1544,7 @@ const Le = (e, a) => {
1084
1544
  */
1085
1545
  pageFullscreen: {
1086
1546
  type: Boolean,
1087
- default: !1
1547
+ default: false
1088
1548
  },
1089
1549
  /**
1090
1550
  * 是否展开预览
@@ -1093,7 +1553,7 @@ const Le = (e, a) => {
1093
1553
  */
1094
1554
  preview: {
1095
1555
  type: Boolean,
1096
- default: !0
1556
+ default: true
1097
1557
  },
1098
1558
  /**
1099
1559
  * 是否展开html预览
@@ -1102,7 +1562,7 @@ const Le = (e, a) => {
1102
1562
  */
1103
1563
  htmlPreview: {
1104
1564
  type: Boolean,
1105
- default: !1
1565
+ default: false
1106
1566
  },
1107
1567
  /**
1108
1568
  * 仅预览模式,不显示toolbar和编辑框
@@ -1122,7 +1582,7 @@ const Le = (e, a) => {
1122
1582
  */
1123
1583
  toolbars: {
1124
1584
  type: Array,
1125
- default: we
1585
+ default: allToolbar
1126
1586
  },
1127
1587
  /**
1128
1588
  * 工具栏选择不显示
@@ -1140,7 +1600,7 @@ const Le = (e, a) => {
1140
1600
  */
1141
1601
  noPrettier: {
1142
1602
  type: Boolean,
1143
- default: !1
1603
+ default: false
1144
1604
  },
1145
1605
  /**
1146
1606
  * 一个tab等于空格数
@@ -1186,7 +1646,7 @@ const Le = (e, a) => {
1186
1646
  */
1187
1647
  footers: {
1188
1648
  type: Array,
1189
- default: ke
1649
+ default: allFooter
1190
1650
  },
1191
1651
  /**
1192
1652
  * 是否默认激活输入框和预览框同步滚动
@@ -1195,7 +1655,7 @@ const Le = (e, a) => {
1195
1655
  */
1196
1656
  scrollAuto: {
1197
1657
  type: Boolean,
1198
- default: !0
1658
+ default: true
1199
1659
  },
1200
1660
  /**
1201
1661
  * 自定义的也叫工具组件列表
@@ -1282,7 +1742,7 @@ const Le = (e, a) => {
1282
1742
  */
1283
1743
  showToolbarName: {
1284
1744
  type: Boolean,
1285
- default: !1
1745
+ default: false
1286
1746
  },
1287
1747
  /**
1288
1748
  * 字符输入事件
@@ -1309,8 +1769,10 @@ const Le = (e, a) => {
1309
1769
  onInputBoxWitdhChange: {
1310
1770
  type: Function
1311
1771
  }
1312
- }, me = ["onHtmlChanged", "onGetCatalog"], _t = [
1313
- ...me,
1772
+ };
1773
+ const mdPreviewEmits = ["onHtmlChanged", "onGetCatalog"];
1774
+ const editorEmits = [
1775
+ ...mdPreviewEmits,
1314
1776
  "onChange",
1315
1777
  "onSave",
1316
1778
  "onUploadImg",
@@ -1321,62 +1783,82 @@ const Le = (e, a) => {
1321
1783
  "onInput",
1322
1784
  "onDrop",
1323
1785
  "onInputBoxWitdhChange"
1324
- ], lt = (e, a) => {
1325
- const { editorId: l } = e, t = {
1786
+ ];
1787
+ const useExpose = (props, ctx) => {
1788
+ const { editorId } = props;
1789
+ const exposeParam = {
1326
1790
  rerender() {
1327
- g.emit(l, G);
1791
+ bus.emit(editorId, RERENDER);
1328
1792
  }
1329
1793
  };
1330
- a.expose(t);
1331
- }, O = /* @__PURE__ */ ne({
1794
+ ctx.expose(exposeParam);
1795
+ };
1796
+ const MdPreview = /* @__PURE__ */ defineComponent({
1332
1797
  name: "MdPreview",
1333
- props: de,
1334
- emits: me,
1335
- setup(e, a) {
1798
+ props: mdPreviewProps,
1799
+ emits: mdPreviewEmits,
1800
+ setup(props, ctx) {
1336
1801
  const {
1337
- editorId: l,
1338
- noKatex: t,
1339
- noMermaid: n,
1340
- noHighlight: i
1341
- } = e;
1342
- return se(e), ue(e), lt(e, a), he(() => {
1343
- g.clear(l);
1344
- }), () => M("div", {
1345
- id: l,
1346
- class: [h, e.class, e.theme === "dark" && `${h}-dark`, `${h}-previewOnly`],
1347
- style: e.style
1348
- }, [M(rt, {
1349
- modelValue: e.modelValue,
1350
- onHtmlChanged: (o) => {
1351
- e.onHtmlChanged ? e.onHtmlChanged(o) : a.emit("onHtmlChanged", o);
1352
- },
1353
- onGetCatalog: (o) => {
1354
- e.onGetCatalog ? e.onGetCatalog(o) : a.emit("onGetCatalog", o);
1355
- },
1356
- mdHeadingId: e.mdHeadingId,
1357
- noMermaid: n,
1358
- sanitize: e.sanitize,
1359
- noKatex: t,
1360
- formatCopiedText: e.formatCopiedText,
1361
- noHighlight: i,
1362
- noImgZoomIn: e.noImgZoomIn,
1363
- previewOnly: !0,
1364
- sanitizeMermaid: e.sanitizeMermaid
1365
- }, null)]);
1802
+ editorId,
1803
+ noKatex,
1804
+ noMermaid,
1805
+ noHighlight
1806
+ } = props;
1807
+ useProvidePreview(props);
1808
+ useExpansionPreview(props);
1809
+ useExpose(props, ctx);
1810
+ onBeforeUnmount(() => {
1811
+ bus.clear(editorId);
1812
+ });
1813
+ return () => {
1814
+ return createVNode("div", {
1815
+ "id": editorId,
1816
+ "class": [prefix, props.class, props.theme === "dark" && `${prefix}-dark`, `${prefix}-previewOnly`],
1817
+ "style": props.style
1818
+ }, [createVNode(ContentPreview, {
1819
+ "modelValue": props.modelValue,
1820
+ "onHtmlChanged": (html) => {
1821
+ if (props.onHtmlChanged) {
1822
+ props.onHtmlChanged(html);
1823
+ } else {
1824
+ ctx.emit("onHtmlChanged", html);
1825
+ }
1826
+ },
1827
+ "onGetCatalog": (list) => {
1828
+ if (props.onGetCatalog) {
1829
+ props.onGetCatalog(list);
1830
+ } else {
1831
+ ctx.emit("onGetCatalog", list);
1832
+ }
1833
+ },
1834
+ "mdHeadingId": props.mdHeadingId,
1835
+ "noMermaid": noMermaid,
1836
+ "sanitize": props.sanitize,
1837
+ "noKatex": noKatex,
1838
+ "formatCopiedText": props.formatCopiedText,
1839
+ "noHighlight": noHighlight,
1840
+ "noImgZoomIn": props.noImgZoomIn,
1841
+ "previewOnly": true,
1842
+ "sanitizeMermaid": props.sanitizeMermaid
1843
+ }, null)]);
1844
+ };
1366
1845
  }
1367
1846
  });
1368
- O.install = (e) => (e.component(O.name, O), e);
1847
+ MdPreview.install = (app) => {
1848
+ app.component(MdPreview.name, MdPreview);
1849
+ return app;
1850
+ };
1369
1851
  export {
1370
- rt as C,
1371
- O as M,
1372
- _t as a,
1373
- kt as b,
1374
- bt as c,
1375
- $t as d,
1376
- Pt as e,
1377
- Ct as f,
1378
- It as g,
1379
- St as h,
1380
- Et as i,
1381
- wt as u
1852
+ ContentPreview as C,
1853
+ MdPreview as M,
1854
+ editorEmits as a,
1855
+ useProvide as b,
1856
+ contentProps as c,
1857
+ useExpansion as d,
1858
+ editorProps as e,
1859
+ useErrorCatcher as f,
1860
+ useConfig as g,
1861
+ useCatalog as h,
1862
+ useExpose$1 as i,
1863
+ useOnSave as u
1382
1864
  };