md-editor-v3 3.0.1 → 4.0.0-beta.0

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 (103) hide show
  1. package/README.md +131 -95
  2. package/lib/cjs/DropdownToolbar.cjs +1 -0
  3. package/lib/cjs/MdCatalog.cjs +1 -0
  4. package/lib/cjs/MdEditor.cjs +60 -0
  5. package/lib/cjs/MdPreview.cjs +1 -0
  6. package/lib/cjs/ModalToolbar.cjs +1 -0
  7. package/lib/cjs/NormalToolbar.cjs +1 -0
  8. package/lib/cjs/chunks/config.cjs +1 -0
  9. package/lib/cjs/chunks/dom.cjs +1 -0
  10. package/lib/cjs/chunks/event-bus.cjs +1 -0
  11. package/lib/cjs/chunks/index.cjs +8 -0
  12. package/lib/cjs/chunks/index2.cjs +1 -0
  13. package/lib/cjs/chunks/index3.cjs +1 -0
  14. package/lib/cjs/chunks/index4.cjs +2 -0
  15. package/lib/cjs/chunks/vue-tsx.cjs +1 -0
  16. package/lib/cjs/config.cjs +1 -0
  17. package/lib/cjs/index.cjs +1 -0
  18. package/lib/es/DropdownToolbar.mjs +7 -0
  19. package/lib/es/MdCatalog.mjs +215 -0
  20. package/lib/es/MdEditor.mjs +2286 -0
  21. package/lib/es/MdPreview.mjs +15 -0
  22. package/lib/es/ModalToolbar.mjs +9 -0
  23. package/lib/es/NormalToolbar.mjs +39 -0
  24. package/lib/es/chunks/config.mjs +271 -0
  25. package/lib/es/chunks/dom.mjs +32 -0
  26. package/lib/es/chunks/event-bus.mjs +38 -0
  27. package/lib/es/chunks/index.mjs +1061 -0
  28. package/lib/es/chunks/index2.mjs +135 -0
  29. package/lib/es/chunks/index3.mjs +229 -0
  30. package/lib/es/chunks/index4.mjs +57 -0
  31. package/lib/es/chunks/vue-tsx.mjs +11 -0
  32. package/lib/es/config.mjs +4 -0
  33. package/lib/es/index.mjs +35 -0
  34. package/lib/preview.css +1 -0
  35. package/lib/style.css +1 -1
  36. package/lib/types/DropdownToolbar/index.d.ts +129 -0
  37. package/lib/{MdEditor/extensions → types}/MdCatalog/CatalogLink.d.ts +4 -4
  38. package/lib/{MdEditor/extensions/MdCatalog/index.d.ts → types/MdCatalog/MdCatalog.d.ts} +3 -3
  39. package/lib/types/MdCatalog/index.d.ts +193 -0
  40. package/lib/{MdEditor → types/MdEditor}/Editor.d.ts +153 -162
  41. package/lib/types/MdEditor/components/Checkbox/index.d.ts +24 -0
  42. package/lib/types/MdEditor/components/Divider/index.d.ts +2 -0
  43. package/lib/types/MdEditor/components/Dropdown/index.d.ts +53 -0
  44. package/lib/types/MdEditor/components/Modal/index.d.ts +84 -0
  45. package/lib/types/MdEditor/composition.d.ts +66 -0
  46. package/lib/{MdEditor → types/MdEditor}/index.d.ts +343 -388
  47. package/lib/types/MdEditor/layouts/Content/ContentPreview.d.ts +154 -0
  48. package/lib/types/MdEditor/layouts/Content/codemirror/commands.d.ts +4 -0
  49. package/lib/types/MdEditor/layouts/Content/codemirror/index.d.ts +56 -0
  50. package/lib/types/MdEditor/layouts/Content/codemirror/themeLight.d.ts +23 -0
  51. package/lib/types/MdEditor/layouts/Content/codemirror/themeOneDark.d.ts +26 -0
  52. package/lib/types/MdEditor/layouts/Content/composition/index.d.ts +6 -0
  53. package/lib/types/MdEditor/layouts/Content/composition/useAttach.d.ts +7 -0
  54. package/lib/types/MdEditor/layouts/Content/composition/useAutoScroll.d.ts +5 -0
  55. package/lib/types/MdEditor/layouts/Content/composition/useCodeMirror.d.ts +13 -0
  56. package/lib/types/MdEditor/layouts/Content/composition/useCopyCode.d.ts +4 -0
  57. package/lib/types/MdEditor/layouts/Content/composition/useHighlight.d.ts +8 -0
  58. package/lib/types/MdEditor/layouts/Content/composition/useKatex.d.ts +8 -0
  59. package/lib/types/MdEditor/layouts/Content/composition/useMarkdownIt.d.ts +5 -0
  60. package/lib/types/MdEditor/layouts/Content/composition/useMermaid.d.ts +11 -0
  61. package/lib/types/MdEditor/layouts/Content/composition/usePasteUpload.d.ts +6 -0
  62. package/lib/types/MdEditor/layouts/Content/composition/userZoom.d.ts +10 -0
  63. package/lib/types/MdEditor/layouts/Content/index.d.ts +173 -0
  64. package/lib/types/MdEditor/layouts/Content/markdownIt/admonition/index.d.ts +5 -0
  65. package/lib/types/MdEditor/layouts/Content/markdownIt/codetabs/index.d.ts +14 -0
  66. package/lib/types/MdEditor/layouts/Content/markdownIt/heading/index.d.ts +9 -0
  67. package/lib/types/MdEditor/layouts/Content/markdownIt/katex/index.d.ts +10 -0
  68. package/lib/types/MdEditor/layouts/Content/markdownIt/mermaid/index.d.ts +6 -0
  69. package/lib/types/MdEditor/layouts/Content/props.d.ts +89 -0
  70. package/lib/types/MdEditor/layouts/Footer/MarkdownTotal.d.ts +15 -0
  71. package/lib/types/MdEditor/layouts/Footer/ScrollAuto.d.ts +21 -0
  72. package/lib/types/MdEditor/layouts/Footer/index.d.ts +50 -0
  73. package/lib/types/MdEditor/layouts/Modals/Clip.d.ts +33 -0
  74. package/lib/types/MdEditor/layouts/Modals/Link.d.ts +42 -0
  75. package/lib/types/MdEditor/layouts/Modals/index.d.ts +51 -0
  76. package/lib/types/MdEditor/layouts/Toolbar/TableShape.d.ts +28 -0
  77. package/lib/types/MdEditor/layouts/Toolbar/composition.d.ts +4 -0
  78. package/lib/types/MdEditor/layouts/Toolbar/index.d.ts +91 -0
  79. package/lib/types/MdEditor/layouts/Toolbar/props.d.ts +45 -0
  80. package/lib/types/MdEditor/props.d.ts +546 -0
  81. package/lib/types/MdEditor/static/event-name.d.ts +9 -0
  82. package/lib/{MdEditor → types/MdEditor}/type.d.ts +2 -1
  83. package/lib/types/MdEditor/utils/content-help.d.ts +19 -0
  84. package/lib/types/MdEditor/utils/dom.d.ts +22 -0
  85. package/lib/types/MdEditor/utils/event-bus.d.ts +17 -0
  86. package/lib/types/MdEditor/utils/index.d.ts +66 -0
  87. package/lib/types/MdEditor/utils/scroll-auto.d.ts +18 -0
  88. package/lib/types/MdEditor/utils/smooth-scroll.d.ts +8 -0
  89. package/lib/types/MdEditor/utils/vue-tsx.d.ts +23 -0
  90. package/lib/types/MdPreview/MdPreview.d.ts +186 -0
  91. package/lib/types/MdPreview/index.d.ts +453 -0
  92. package/lib/types/ModalToolbar/index.d.ts +244 -0
  93. package/lib/types/NormalToolbar/index.d.ts +105 -0
  94. package/lib/types/config.d.ts +1 -0
  95. package/lib/types/index.d.ts +8 -0
  96. package/lib/{md-editor-v3.umd.js → umd/index.js} +38 -38
  97. package/package.json +16 -20
  98. package/lib/md-editor-v3.cjs +0 -63
  99. package/lib/md-editor-v3.mjs +0 -4143
  100. /package/lib/{MdEditor/extensions → types/DropdownToolbar}/DropdownToolbar.d.ts +0 -0
  101. /package/lib/{MdEditor → types/MdEditor}/config.d.ts +0 -0
  102. /package/lib/{MdEditor/extensions → types/ModalToolbar}/ModalToolbar.d.ts +0 -0
  103. /package/lib/{MdEditor/extensions → types/NormalToolbar}/NormalToolbar.d.ts +0 -0
@@ -1,4143 +0,0 @@
1
- var wt = Object.defineProperty;
2
- var Tt = (e, l, o) => l in e ? wt(e, l, { enumerable: !0, configurable: !0, writable: !0, value: o }) : e[l] = o;
3
- var K = (e, l, o) => (Tt(e, typeof l != "symbol" ? l + "" : l, o), o);
4
- import { defineComponent as M, createVNode as i, reactive as q, ref as B, watch as S, onMounted as H, onBeforeUnmount as Se, cloneVNode as St, inject as x, computed as U, nextTick as Y, Fragment as xe, toRef as ne, shallowRef as de, provide as Z, isVNode as xt } from "vue";
5
- import { minimalSetup as Et, EditorView as fe } from "codemirror";
6
- import { EditorSelection as be, EditorState as ge, Compartment as Lt, StateEffect as At } from "@codemirror/state";
7
- import { EditorView as Ee, placeholder as It, keymap as Ht } from "@codemirror/view";
8
- import { languages as Ft } from "@codemirror/language-data";
9
- import { markdown as Mt } from "@codemirror/lang-markdown";
10
- import { deleteLine as Bt, indentWithTab as Rt, undo as jt, redo as Pt } from "@codemirror/commands";
11
- import { HighlightStyle as vt, syntaxHighlighting as pt, indentUnit as Dt } from "@codemirror/language";
12
- import { tags as g } from "@lezer/highlight";
13
- import Ot from "medium-zoom";
14
- import _t from "copy-to-clipboard";
15
- import Nt from "markdown-it";
16
- import Vt from "markdown-it-image-figures";
17
- import Ut from "markdown-it-task-lists";
18
- import qt from "markdown-it-codetabs";
19
- import Gt from "lru-cache";
20
- const s = "md-editor", Wt = "md-editor-v3", Kt = "https://at.alicdn.com/t/c/font_2605852_u82y61ve02.js", L = "https://cdnjs.cloudflare.com/ajax/libs", zt = `${L}/highlight.js/11.7.0/highlight.min.js`, We = {
21
- main: `${L}/prettier/2.8.0/standalone.js`,
22
- markdown: `${L}/prettier/2.8.0/parser-markdown.js`
23
- }, Ke = {
24
- css: `${L}/cropperjs/1.5.13/cropper.min.css`,
25
- js: `${L}/cropperjs/1.5.13/cropper.min.js`
26
- }, Xt = `${L}/screenfull.js/5.2.0/screenfull.min.js`, bt = [
27
- "bold",
28
- "underline",
29
- "italic",
30
- "strikeThrough",
31
- "-",
32
- "title",
33
- "sub",
34
- "sup",
35
- "quote",
36
- "unorderedList",
37
- "orderedList",
38
- "task",
39
- "-",
40
- "codeRow",
41
- "code",
42
- "link",
43
- "image",
44
- "table",
45
- "mermaid",
46
- "katex",
47
- "-",
48
- "revoke",
49
- "next",
50
- "save",
51
- "=",
52
- "prettier",
53
- "pageFullscreen",
54
- "fullscreen",
55
- "preview",
56
- "htmlPreview",
57
- "catalog",
58
- "github"
59
- ], kt = ["markdownTotal", "=", "scrollSwitch"], ze = {
60
- "zh-CN": {
61
- toolbarTips: {
62
- bold: "加粗",
63
- underline: "下划线",
64
- italic: "斜体",
65
- strikeThrough: "删除线",
66
- title: "标题",
67
- sub: "下标",
68
- sup: "上标",
69
- quote: "引用",
70
- unorderedList: "无序列表",
71
- orderedList: "有序列表",
72
- task: "任务列表",
73
- codeRow: "行内代码",
74
- code: "块级代码",
75
- link: "链接",
76
- image: "图片",
77
- table: "表格",
78
- mermaid: "mermaid图",
79
- katex: "katex公式",
80
- revoke: "后退",
81
- next: "前进",
82
- save: "保存",
83
- prettier: "美化",
84
- pageFullscreen: "浏览器全屏",
85
- fullscreen: "屏幕全屏",
86
- preview: "预览",
87
- htmlPreview: "html代码预览",
88
- catalog: "目录",
89
- github: "源码地址"
90
- },
91
- titleItem: {
92
- h1: "一级标题",
93
- h2: "二级标题",
94
- h3: "三级标题",
95
- h4: "四级标题",
96
- h5: "五级标题",
97
- h6: "六级标题"
98
- },
99
- imgTitleItem: {
100
- link: "添加链接",
101
- upload: "上传图片",
102
- clip2upload: "裁剪上传"
103
- },
104
- linkModalTips: {
105
- linkTitle: "添加链接",
106
- imageTitle: "添加图片",
107
- descLabel: "链接描述:",
108
- descLabelPlaceHolder: "请输入描述...",
109
- urlLabel: "链接地址:",
110
- urlLabelPlaceHolder: "请输入链接...",
111
- buttonOK: "确定"
112
- },
113
- clipModalTips: {
114
- title: "裁剪图片上传",
115
- buttonUpload: "上传"
116
- },
117
- copyCode: {
118
- text: "复制代码",
119
- successTips: "已复制!",
120
- failTips: "复制失败!"
121
- },
122
- mermaid: {
123
- flow: "流程图",
124
- sequence: "时序图",
125
- gantt: "甘特图",
126
- class: "类图",
127
- state: "状态图",
128
- pie: "饼图",
129
- relationship: "关系图",
130
- journey: "旅程图"
131
- },
132
- katex: {
133
- inline: "行内公式",
134
- block: "块级公式"
135
- },
136
- footer: {
137
- markdownTotal: "字数",
138
- scrollAuto: "同步滚动"
139
- }
140
- },
141
- "en-US": {
142
- toolbarTips: {
143
- bold: "bold",
144
- underline: "underline",
145
- italic: "italic",
146
- strikeThrough: "strikeThrough",
147
- title: "title",
148
- sub: "subscript",
149
- sup: "superscript",
150
- quote: "quote",
151
- unorderedList: "unordered list",
152
- orderedList: "ordered list",
153
- task: "task list",
154
- codeRow: "inline code",
155
- code: "block-level code",
156
- link: "link",
157
- image: "image",
158
- table: "table",
159
- mermaid: "mermaid",
160
- katex: "formula",
161
- revoke: "revoke",
162
- next: "undo revoke",
163
- save: "save",
164
- prettier: "prettier",
165
- pageFullscreen: "fullscreen in page",
166
- fullscreen: "fullscreen",
167
- preview: "preview",
168
- htmlPreview: "html preview",
169
- catalog: "catalog",
170
- github: "source code"
171
- },
172
- titleItem: {
173
- h1: "Lv1 Heading",
174
- h2: "Lv2 Heading",
175
- h3: "Lv3 Heading",
176
- h4: "Lv4 Heading",
177
- h5: "Lv5 Heading",
178
- h6: "Lv6 Heading"
179
- },
180
- imgTitleItem: {
181
- link: "Add Img Link",
182
- upload: "Upload Img",
183
- clip2upload: "Clip Upload"
184
- },
185
- linkModalTips: {
186
- linkTitle: "Add Link",
187
- imageTitle: "Add Image",
188
- descLabel: "Desc:",
189
- descLabelPlaceHolder: "Enter a description...",
190
- urlLabel: "Link:",
191
- urlLabelPlaceHolder: "Enter a link...",
192
- buttonOK: "OK"
193
- },
194
- clipModalTips: {
195
- title: "Crop Image",
196
- buttonUpload: "Upload"
197
- },
198
- copyCode: {
199
- text: "Copy",
200
- successTips: "Copied!",
201
- failTips: "Copy failed!"
202
- },
203
- mermaid: {
204
- flow: "flow",
205
- sequence: "sequence",
206
- gantt: "gantt",
207
- class: "class",
208
- state: "state",
209
- pie: "pie",
210
- relationship: "relationship",
211
- journey: "journey"
212
- },
213
- katex: {
214
- inline: "inline",
215
- block: "block"
216
- },
217
- footer: {
218
- markdownTotal: "Word Count",
219
- scrollAuto: "Scroll Auto"
220
- }
221
- }
222
- }, Zt = `${L}/mermaid/9.4.0/mermaid.min.js`, Xe = {
223
- js: `${L}/KaTeX/0.16.3/katex.min.js`,
224
- css: `${L}/KaTeX/0.16.3/katex.min.css`
225
- }, Ze = {
226
- a11y: {
227
- light: `${L}/highlight.js/11.7.0/styles/a11y-light.min.css`,
228
- dark: `${L}/highlight.js/11.7.0/styles/a11y-dark.min.css`
229
- },
230
- atom: {
231
- light: `${L}/highlight.js/11.7.0/styles/atom-one-light.min.css`,
232
- dark: `${L}/highlight.js/11.7.0/styles/atom-one-dark.min.css`
233
- },
234
- github: {
235
- light: `${L}/highlight.js/11.7.0/styles/github.min.css`,
236
- dark: `${L}/highlight.js/11.7.0/styles/github-dark.min.css`
237
- },
238
- gradient: {
239
- light: `${L}/highlight.js/11.7.0/styles/gradient-light.min.css`,
240
- dark: `${L}/highlight.js/11.7.0/styles/gradient-dark.min.css`
241
- },
242
- kimbie: {
243
- light: `${L}/highlight.js/11.7.0/styles/kimbie-light.min.css`,
244
- dark: `${L}/highlight.js/11.7.0/styles/kimbie-dark.min.css`
245
- },
246
- paraiso: {
247
- light: `${L}/highlight.js/11.7.0/styles/paraiso-light.min.css`,
248
- dark: `${L}/highlight.js/11.7.0/styles/paraiso-dark.min.css`
249
- },
250
- qtcreator: {
251
- light: `${L}/highlight.js/11.7.0/styles/qtcreator-light.min.css`,
252
- dark: `${L}/highlight.js/11.7.0/styles/qtcreator-dark.min.css`
253
- },
254
- stackoverflow: {
255
- light: `${L}/highlight.js/11.7.0/styles/stackoverflow-light.min.css`,
256
- dark: `${L}/highlight.js/11.7.0/styles/stackoverflow-dark.min.css`
257
- }
258
- }, A = {
259
- // markedRenderer: (r) => r,
260
- // markedExtensions: [],
261
- // markedOptions: {},
262
- editorExtensions: {},
263
- editorConfig: {},
264
- codeMirrorExtensions: (e, l) => l,
265
- markdownItConfig: () => {
266
- }
267
- }, Jt = (e) => {
268
- if (e)
269
- for (const l in e) {
270
- const o = e[l];
271
- o && (A[l] = o);
272
- }
273
- };
274
- const Yt = /* @__PURE__ */ M({
275
- setup() {
276
- return () => i("div", {
277
- class: `${s}-divider`
278
- }, null);
279
- }
280
- }), G = ({
281
- instance: e,
282
- ctx: l,
283
- props: o = {}
284
- }, t = "default") => {
285
- const r = (e == null ? void 0 : e.$slots[t]) || (l == null ? void 0 : l.slots[t]);
286
- return (r ? r(e) : "") || o[t];
287
- };
288
- const Qt = {
289
- trigger: {
290
- type: String,
291
- default: "hover"
292
- },
293
- overlay: {
294
- type: [String, Object],
295
- default: ""
296
- },
297
- visible: {
298
- type: Boolean,
299
- default: !1
300
- },
301
- onChange: {
302
- type: Function,
303
- default: () => {
304
- }
305
- },
306
- // 相对滚动的元素选择器
307
- relative: {
308
- type: String,
309
- default: "html"
310
- }
311
- }, oe = /* @__PURE__ */ M({
312
- props: Qt,
313
- setup(e, l) {
314
- const o = `${s}-dropdown-hidden`, t = q({
315
- overlayClass: [o],
316
- overlayStyle: {},
317
- triggerHover: !1,
318
- overlayHover: !1
319
- }), r = B(), n = B(), a = () => {
320
- var T;
321
- e.trigger === "hover" && (t.triggerHover = !0);
322
- const f = r.value, h = n.value, p = f.getBoundingClientRect(), v = f.offsetTop, b = f.offsetLeft, y = p.height, C = p.width, $ = ((T = document.querySelector(e.relative)) == null ? void 0 : T.scrollLeft) || 0;
323
- t.overlayStyle = {
324
- ...t.overlayStyle,
325
- top: v + y + "px",
326
- left: b - h.offsetWidth / 2 + C / 2 - $ + "px"
327
- }, e.onChange(!0);
328
- }, d = () => {
329
- t.overlayHover = !0;
330
- };
331
- S(() => e.visible, (f) => {
332
- f ? t.overlayClass = t.overlayClass.filter((h) => h !== o) : t.overlayClass.push(o);
333
- });
334
- const m = (f) => {
335
- const h = r.value, p = n.value;
336
- !h.contains(f.target) && !p.contains(f.target) && e.onChange(!1);
337
- };
338
- let u = -1;
339
- const c = (f) => {
340
- r.value === f.target ? t.triggerHover = !1 : t.overlayHover = !1, clearTimeout(u), u = window.setTimeout(() => {
341
- !t.overlayHover && !t.triggerHover && e.onChange(!1);
342
- }, 10);
343
- };
344
- return H(() => {
345
- e.trigger === "click" ? (r.value.addEventListener("click", a), document.addEventListener("click", m)) : (r.value.addEventListener("mouseenter", a), r.value.addEventListener("mouseleave", c), n.value.addEventListener("mouseenter", d), n.value.addEventListener("mouseleave", c));
346
- }), Se(() => {
347
- e.trigger === "click" ? (r.value.removeEventListener("click", a), document.removeEventListener("click", m)) : (r.value.removeEventListener("mouseenter", a), r.value.removeEventListener("mouseleave", c), n.value.removeEventListener("mouseenter", d), n.value.removeEventListener("mouseleave", c));
348
- }), () => {
349
- const f = G({
350
- ctx: l
351
- }), h = G({
352
- props: e,
353
- ctx: l
354
- }, "overlay"), p = St(f instanceof Array ? f[0] : f, {
355
- ref: r
356
- }), v = i("div", {
357
- class: [`${s}-dropdown`, t.overlayClass],
358
- style: t.overlayStyle,
359
- ref: n
360
- }, [i("div", {
361
- class: `${s}-dropdown-overlay`
362
- }, [h instanceof Array ? h[0] : h])]);
363
- return [p, v];
364
- };
365
- }
366
- });
367
- class el {
368
- constructor() {
369
- // 事件池
370
- K(this, "pools", {});
371
- }
372
- // 移除事件监听
373
- remove(l, o, t) {
374
- const n = this.pools[l] && this.pools[l][o];
375
- n && (this.pools[l][o] = n.filter((a) => a !== t));
376
- }
377
- // 清空全部事件,由于单一实例,多次注册会被共享内容
378
- clear(l) {
379
- this.pools[l] = {};
380
- }
381
- // 注册事件监听
382
- on(l, o) {
383
- return this.pools[l] || (this.pools[l] = {}), this.pools[l][o.name] || (this.pools[l][o.name] = []), this.pools[l][o.name].push(o.callback), this.pools[l][o.name].includes(o.callback);
384
- }
385
- // 触发事件
386
- emit(l, o, ...t) {
387
- this.pools[l] || (this.pools[l] = {});
388
- const n = this.pools[l][o];
389
- n && n.forEach((a) => {
390
- try {
391
- a(...t);
392
- } catch (d) {
393
- console.error(`${o} monitor event exception!`, d);
394
- }
395
- });
396
- }
397
- }
398
- const k = new el(), tl = (e, l = {
399
- newWindow: !0,
400
- nofollow: !0
401
- }) => {
402
- e || console.error("error link!");
403
- const o = document.createElement("a");
404
- o.href = e, o.style.display = "none", l.newWindow && (o.target = "_blank"), l.nofollow && (o.rel = "noopener noreferrer"), document.body.appendChild(o), o.click(), document.body.removeChild(o);
405
- }, ll = (e, l = "image.png") => {
406
- const o = e.split(","), t = o[0].match(/:(.*?);/);
407
- if (t) {
408
- const r = t[1], n = atob(o[1]);
409
- let a = n.length;
410
- const d = new Uint8Array(a);
411
- for (; a--; )
412
- d[a] = n.charCodeAt(a);
413
- return new File([d], l, { type: r });
414
- }
415
- return null;
416
- }, ol = (e) => {
417
- if (!e)
418
- return e;
419
- const l = e.split(`
420
- `), o = ['<span rn-wrapper aria-hidden="true">'];
421
- return l.forEach(() => {
422
- o.push("<span></span>");
423
- }), o.push("</span>"), `<span class="code-block">${e}</span>${o.join("")}`;
424
- }, ve = (e, l = 200) => {
425
- let o = 0;
426
- return (...t) => new Promise((r) => {
427
- o && (clearTimeout(o), r("cancel")), o = window.setTimeout(() => {
428
- e.apply(void 0, t), o = 0, r("done");
429
- }, l);
430
- });
431
- }, nl = (e, l = 200) => {
432
- let o = 0, t = null;
433
- return (...r) => {
434
- const n = (a) => {
435
- o === 0 && (o = a), a - o >= l ? (e.apply(void 0, t), t = null, o = 0) : window.requestAnimationFrame(n);
436
- };
437
- t === null && window.requestAnimationFrame(n), t = r;
438
- };
439
- }, rl = (e, l) => {
440
- const o = e == null ? void 0 : e.getBoundingClientRect();
441
- if (l === document.documentElement)
442
- return o.top - l.clientTop;
443
- const t = l == null ? void 0 : l.getBoundingClientRect();
444
- return o.top - t.top;
445
- }, il = () => `${Date.now().toString(36)}${Math.random().toString(36).substring(2)}`, al = {
446
- noPrettier: {
447
- type: Boolean
448
- },
449
- // 工具栏选择显示
450
- toolbars: {
451
- type: Array,
452
- default: () => []
453
- },
454
- // 工具栏选择不显示
455
- toolbarsExclude: {
456
- type: Array,
457
- default: () => []
458
- },
459
- setting: {
460
- type: Object,
461
- default: () => ({})
462
- },
463
- screenfull: {
464
- type: Object,
465
- default: null
466
- },
467
- screenfullJs: {
468
- type: String,
469
- default: ""
470
- },
471
- updateSetting: {
472
- type: Function,
473
- default: () => {
474
- }
475
- },
476
- tableShape: {
477
- type: Array,
478
- default: () => [6, 4]
479
- },
480
- defToolbars: {
481
- type: Object
482
- },
483
- noUploadImg: {
484
- type: Boolean
485
- }
486
- }, pe = "onSave", Le = "changeCatalogVisible", yt = "changeFullscreen", Je = "pageFullscreenChanged", Ye = "fullscreenChanged", Ce = "previewChanged", Qe = "htmlPreviewChanged", et = "catalogVisibleChanged", Ct = "textareaFocus", tt = (e, l) => {
487
- const o = (t) => {
488
- const r = e.parentElement || document.body, n = r.offsetWidth, a = r.offsetHeight, { clientWidth: d } = document.documentElement, { clientHeight: m } = document.documentElement, u = t.offsetX, c = t.offsetY, f = (p) => {
489
- let v = p.x + document.body.scrollLeft - document.body.clientLeft - u, b = p.y + document.body.scrollTop - document.body.clientTop - c;
490
- v = v < 1 ? 1 : v < d - n - 1 ? v : d - n - 1, b = b < 1 ? 1 : b < m - a - 1 ? b : m - a - 1, l ? l(v, b) : (r.style.left = `${v}px`, r.style.top = `${b}px`);
491
- };
492
- document.addEventListener("mousemove", f);
493
- const h = () => {
494
- document.removeEventListener("mousemove", f), document.removeEventListener("mouseup", h);
495
- };
496
- document.addEventListener("mouseup", h);
497
- };
498
- return e.addEventListener("mousedown", o), () => {
499
- e.removeEventListener("mousedown", o);
500
- };
501
- }, V = (e, l = "") => {
502
- const o = document.getElementById(e.id), t = e.onload;
503
- e.onload = null;
504
- const r = function(n) {
505
- typeof t == "function" && t.bind(this)(n), e.removeEventListener("load", r);
506
- };
507
- o ? l !== "" && (o.addEventListener("load", r), Reflect.get(window, l) && o.dispatchEvent(new Event("load"))) : (e.addEventListener("load", r), document.head.appendChild(e));
508
- }, sl = ve((e, l, o) => {
509
- const t = document.getElementById(e);
510
- t && t.setAttribute(l, o);
511
- }, 10), cl = (e) => {
512
- var m, u, c, f;
513
- const l = x("editorId");
514
- let o = (u = (m = A.editorExtensions) == null ? void 0 : m.screenfull) == null ? void 0 : u.instance;
515
- const t = (f = (c = A.editorExtensions) == null ? void 0 : c.screenfull) == null ? void 0 : f.js, r = B(!1), n = (h) => {
516
- if (!o) {
517
- k.emit(l, "errorCatcher", {
518
- name: "fullscreen",
519
- message: "fullscreen is undefined"
520
- });
521
- return;
522
- }
523
- o.isEnabled ? (r.value = !0, (h === void 0 ? !o.isFullscreen : h) ? o.request() : o.exit()) : console.error("browser does not support screenfull!");
524
- }, a = () => {
525
- o && o.isEnabled && o.on("change", () => {
526
- (r.value || e.setting.fullscreen) && (r.value = !1, e.updateSetting("fullscreen"));
527
- });
528
- }, d = () => {
529
- o = window.screenfull, a();
530
- };
531
- return H(() => {
532
- if (a(), !o) {
533
- const h = document.createElement("script");
534
- h.src = t || Xt, h.onload = d, h.id = `${s}-screenfull`, V(h, "screenfull");
535
- }
536
- }), H(() => {
537
- k.on(l, {
538
- name: yt,
539
- callback: n
540
- });
541
- }), { fullscreenHandler: n };
542
- }, dl = {
543
- tableShape: {
544
- type: Array,
545
- default: () => [6, 4]
546
- },
547
- onSelected: {
548
- type: Function,
549
- default: () => {
550
- }
551
- }
552
- }, ul = /* @__PURE__ */ M({
553
- name: "TableShape",
554
- props: dl,
555
- setup(e) {
556
- const l = q({
557
- x: -1,
558
- y: -1
559
- });
560
- return () => i("div", {
561
- class: `${s}-table-shape`,
562
- onMouseleave: () => {
563
- l.x = -1, l.y = -1;
564
- }
565
- }, [new Array(e.tableShape[1]).fill("").map((o, t) => i("div", {
566
- class: `${s}-table-shape-row`,
567
- key: `table-shape-row-${t}`
568
- }, [new Array(e.tableShape[0]).fill("").map((r, n) => i("div", {
569
- class: `${s}-table-shape-col`,
570
- key: `table-shape-col-${n}`,
571
- onMouseenter: () => {
572
- l.x = t, l.y = n;
573
- },
574
- onClick: () => {
575
- e.onSelected(l);
576
- }
577
- }, [i("div", {
578
- class: [`${s}-table-shape-col-default`, t <= l.x && n <= l.y && `${s}-table-shape-col-include`]
579
- }, null)]))]))]);
580
- }
581
- });
582
- const ml = {
583
- title: {
584
- type: String,
585
- default: ""
586
- },
587
- visible: {
588
- type: Boolean,
589
- default: !1
590
- },
591
- width: {
592
- type: String,
593
- default: "auto"
594
- },
595
- height: {
596
- type: String,
597
- default: "auto"
598
- },
599
- onClose: {
600
- type: Function,
601
- default: () => {
602
- }
603
- },
604
- showAdjust: {
605
- type: Boolean,
606
- default: !1
607
- },
608
- isFullscreen: {
609
- type: Boolean,
610
- default: !1
611
- },
612
- onAdjust: {
613
- type: Function,
614
- default: () => {
615
- }
616
- },
617
- class: {
618
- type: String
619
- }
620
- }, Ae = /* @__PURE__ */ M({
621
- props: ml,
622
- setup(e, l) {
623
- const o = B(e.visible), t = B([`${s}-modal`]), r = B(), n = B();
624
- let a = () => {
625
- };
626
- const d = q({
627
- initPos: {
628
- left: "0px",
629
- top: "0px"
630
- },
631
- historyPos: {
632
- left: "0px",
633
- top: "0px"
634
- }
635
- }), m = U(() => e.isFullscreen ? {
636
- width: "100%",
637
- height: "100%"
638
- } : {
639
- width: e.width,
640
- height: e.height
641
- });
642
- return H(() => {
643
- a = tt(n.value, (u, c) => {
644
- d.initPos.left = u + "px", d.initPos.top = c + "px";
645
- });
646
- }), Se(() => {
647
- a();
648
- }), S(() => e.isFullscreen, (u) => {
649
- u ? a() : a = tt(n.value, (c, f) => {
650
- d.initPos.left = c + "px", d.initPos.top = f + "px";
651
- });
652
- }), S(() => e.visible, (u) => {
653
- u ? (t.value.push("zoom-in"), o.value = u, Y(() => {
654
- const c = r.value.offsetWidth / 2, f = r.value.offsetHeight / 2, h = document.documentElement.clientWidth / 2, p = document.documentElement.clientHeight / 2;
655
- d.initPos.left = h - c + "px", d.initPos.top = p - f + "px";
656
- }), setTimeout(() => {
657
- t.value = t.value.filter((c) => c !== "zoom-in");
658
- }, 140)) : (t.value.push("zoom-out"), setTimeout(() => {
659
- t.value = t.value.filter((c) => c !== "zoom-out"), o.value = u;
660
- }, 130));
661
- }), () => {
662
- const u = G({
663
- ctx: l
664
- }), c = G({
665
- props: e,
666
- ctx: l
667
- }, "title");
668
- return i("div", {
669
- class: [e.class],
670
- style: {
671
- display: o.value ? "block" : "none"
672
- }
673
- }, [i("div", {
674
- class: `${s}-modal-mask`,
675
- onClick: e.onClose
676
- }, null), i("div", {
677
- class: t.value,
678
- style: {
679
- ...d.initPos,
680
- ...m.value
681
- },
682
- ref: r
683
- }, [i("div", {
684
- class: `${s}-modal-header`,
685
- ref: n
686
- }, [c || ""]), i("div", {
687
- class: `${s}-modal-body`
688
- }, [u]), i("div", {
689
- class: `${s}-modal-func`
690
- }, [e.showAdjust && i("div", {
691
- class: `${s}-modal-adjust`,
692
- onClick: (f) => {
693
- f.stopPropagation(), e.isFullscreen ? d.initPos = d.historyPos : (d.historyPos = d.initPos, d.initPos = {
694
- left: "0",
695
- top: "0"
696
- }), e.onAdjust(!e.isFullscreen);
697
- }
698
- }, [i("svg", {
699
- class: `${s}-icon`,
700
- "aria-hidden": "true"
701
- }, [i("use", {
702
- "xlink:href": `#md-editor-icon-${e.isFullscreen ? "suoxiao" : "fangda"}`
703
- }, null)])]), i("div", {
704
- class: `${s}-modal-close`,
705
- onClick: (f) => {
706
- f.stopPropagation(), e.onClose && e.onClose();
707
- }
708
- }, [i("svg", {
709
- class: `${s}-icon`,
710
- "aria-hidden": "true"
711
- }, [i("use", {
712
- "xlink:href": "#md-editor-icon-close"
713
- }, null)])])])])]);
714
- };
715
- }
716
- }), fl = {
717
- type: {
718
- type: String,
719
- default: "link"
720
- },
721
- visible: {
722
- type: Boolean,
723
- default: !1
724
- },
725
- onCancel: {
726
- type: Function,
727
- default: () => {
728
- }
729
- },
730
- onOk: {
731
- type: Function,
732
- default: () => {
733
- }
734
- }
735
- }, gl = /* @__PURE__ */ M({
736
- props: fl,
737
- setup(e) {
738
- const l = x("usedLanguageText"), o = x("editorId"), t = U(() => {
739
- var n, a;
740
- switch (e.type) {
741
- case "link":
742
- return (n = l.value.linkModalTips) == null ? void 0 : n.linkTitle;
743
- case "image":
744
- return (a = l.value.linkModalTips) == null ? void 0 : a.imageTitle;
745
- default:
746
- return "";
747
- }
748
- }), r = q({
749
- desc: "",
750
- url: ""
751
- });
752
- return S(() => e.visible, (n) => {
753
- n || setTimeout(() => {
754
- r.desc = "", r.url = "";
755
- }, 200);
756
- }), () => i(Ae, {
757
- title: t.value,
758
- visible: e.visible,
759
- onClose: e.onCancel
760
- }, {
761
- default: () => {
762
- var n, a, d, m, u;
763
- return [i("div", {
764
- class: `${s}-form-item`
765
- }, [i("label", {
766
- class: `${s}-label`,
767
- for: `link-desc-${o}`
768
- }, [(n = l.value.linkModalTips) == null ? void 0 : n.descLabel]), i("input", {
769
- placeholder: (a = l.value.linkModalTips) == null ? void 0 : a.descLabelPlaceHolder,
770
- class: `${s}-input`,
771
- id: `link-desc-${o}`,
772
- type: "text",
773
- value: r.desc,
774
- onChange: (c) => {
775
- r.desc = c.target.value;
776
- },
777
- autocomplete: "off"
778
- }, null)]), i("div", {
779
- class: `${s}-form-item`
780
- }, [i("label", {
781
- class: `${s}-label`,
782
- for: `link-url-${o}`
783
- }, [(d = l.value.linkModalTips) == null ? void 0 : d.urlLabel]), i("input", {
784
- placeholder: (m = l.value.linkModalTips) == null ? void 0 : m.urlLabelPlaceHolder,
785
- class: `${s}-input`,
786
- id: `link-url-${o}`,
787
- type: "text",
788
- value: r.url,
789
- onChange: (c) => {
790
- r.url = c.target.value;
791
- },
792
- autocomplete: "off"
793
- }, null)]), i("div", {
794
- class: `${s}-form-item`
795
- }, [i("button", {
796
- class: [`${s}-btn`, `${s}-btn-row`],
797
- type: "button",
798
- onClick: () => {
799
- e.onOk(r), r.desc = "", r.url = "";
800
- }
801
- }, [(u = l.value.linkModalTips) == null ? void 0 : u.buttonOK])])];
802
- }
803
- });
804
- }
805
- });
806
- const hl = {
807
- visible: {
808
- type: Boolean,
809
- default: !1
810
- },
811
- onCancel: {
812
- type: Function,
813
- default: () => {
814
- }
815
- },
816
- onOk: {
817
- type: Function,
818
- default: () => {
819
- }
820
- }
821
- }, vl = /* @__PURE__ */ M({
822
- props: hl,
823
- setup(e) {
824
- var c, f;
825
- const l = x("usedLanguageText"), o = x("editorId");
826
- let t = (f = (c = A == null ? void 0 : A.editorExtensions) == null ? void 0 : c.cropper) == null ? void 0 : f.instance;
827
- const r = B(), n = B(), a = B(), d = q({
828
- cropperInited: !1,
829
- imgSelected: !1,
830
- imgSrc: "",
831
- // 是否全屏
832
- isFullscreen: !1
833
- });
834
- let m = null;
835
- S(() => e.visible, () => {
836
- e.visible && !d.cropperInited && (t = t || window.Cropper, r.value.onchange = () => {
837
- if (!t) {
838
- k.emit(o, "errorCatcher", {
839
- name: "Cropper",
840
- message: "Cropper is undefined"
841
- });
842
- return;
843
- }
844
- const h = r.value.files || [];
845
- if (d.imgSelected = !0, (h == null ? void 0 : h.length) > 0) {
846
- const p = new FileReader();
847
- p.onload = (v) => {
848
- d.imgSrc = v.target.result, Y(() => {
849
- m = new t(n.value, {
850
- viewMode: 2,
851
- preview: `.${s}-clip-preview-target`
852
- // aspectRatio: 16 / 9,
853
- });
854
- });
855
- }, p.readAsDataURL(h[0]);
856
- }
857
- });
858
- }), S(() => [d.imgSelected], () => {
859
- a.value.style = "";
860
- }), S(() => d.isFullscreen, () => {
861
- Y(() => {
862
- m == null || m.destroy(), a.value.style = "", n.value && (m = new t(n.value, {
863
- viewMode: 2,
864
- preview: `.${s}-clip-preview-target`
865
- // aspectRatio: 16 / 9,
866
- }));
867
- });
868
- });
869
- const u = () => {
870
- m.clear(), m.destroy(), m = null, r.value.value = "", d.imgSelected = !1;
871
- };
872
- return () => {
873
- var h;
874
- return i(Ae, {
875
- class: `${s}-modal-clip`,
876
- title: (h = l.value.clipModalTips) == null ? void 0 : h.title,
877
- visible: e.visible,
878
- onClose: e.onCancel,
879
- showAdjust: !0,
880
- isFullscreen: d.isFullscreen,
881
- onAdjust: (p) => {
882
- d.isFullscreen = p;
883
- },
884
- width: "668px",
885
- height: "421px"
886
- }, {
887
- default: () => {
888
- var p, v;
889
- return [i("div", {
890
- class: `${s}-form-item ${s}-clip`
891
- }, [i("div", {
892
- class: `${s}-clip-main`
893
- }, [d.imgSelected ? i("div", {
894
- class: `${s}-clip-cropper`
895
- }, [i("img", {
896
- src: d.imgSrc,
897
- ref: n,
898
- style: {
899
- display: "none"
900
- },
901
- alt: ""
902
- }, null), i("div", {
903
- class: `${s}-clip-delete`,
904
- onClick: u
905
- }, [i("svg", {
906
- class: `${s}-icon`,
907
- "aria-hidden": "true"
908
- }, [i("use", {
909
- "xlink:href": "#md-editor-icon-delete"
910
- }, null)])])]) : i("div", {
911
- class: `${s}-clip-upload`,
912
- onClick: () => {
913
- r.value.click();
914
- }
915
- }, [i("svg", {
916
- class: `${s}-icon`,
917
- "aria-hidden": "true"
918
- }, [i("use", {
919
- "xlink:href": "#md-editor-icon-upload"
920
- }, null)])])]), i("div", {
921
- class: `${s}-clip-preview`
922
- }, [i("div", {
923
- class: `${s}-clip-preview-target`,
924
- ref: a
925
- }, null)])]), i("div", {
926
- class: `${s}-form-item`
927
- }, [i("button", {
928
- class: `${s}-btn`,
929
- type: "button",
930
- onClick: () => {
931
- if (m) {
932
- const b = m.getCroppedCanvas();
933
- k.emit(o, "uploadImage", [ll(b.toDataURL("image/png"))], e.onOk), u();
934
- }
935
- }
936
- }, [((p = l.value.clipModalTips) == null ? void 0 : p.buttonUpload) || ((v = l.value.linkModalTips) == null ? void 0 : v.buttonOK)])]), i("input", {
937
- ref: r,
938
- accept: "image/*",
939
- type: "file",
940
- multiple: !1,
941
- style: {
942
- display: "none"
943
- }
944
- }, null)];
945
- }
946
- });
947
- };
948
- }
949
- }), pl = {
950
- type: {
951
- type: String,
952
- default: "link"
953
- },
954
- linkVisible: {
955
- type: Boolean,
956
- default: !1
957
- },
958
- clipVisible: {
959
- type: Boolean,
960
- default: !1
961
- },
962
- onCancel: {
963
- type: Function,
964
- default: () => {
965
- }
966
- },
967
- onOk: {
968
- type: Function,
969
- default: () => {
970
- }
971
- }
972
- }, bl = /* @__PURE__ */ M({
973
- props: pl,
974
- setup(e) {
975
- return () => i(xe, null, [i(gl, {
976
- type: e.type,
977
- visible: e.linkVisible,
978
- onOk: e.onOk,
979
- onCancel: e.onCancel
980
- }, null), i(vl, {
981
- visible: e.clipVisible,
982
- onOk: e.onOk,
983
- onCancel: e.onCancel
984
- }, null)]);
985
- }
986
- }), kl = /* @__PURE__ */ M({
987
- name: "MDEditorToolbar",
988
- props: al,
989
- setup(e) {
990
- const l = x("editorId"), o = x("usedLanguageText"), {
991
- fullscreenHandler: t
992
- } = cl(e), r = `${l}-toolbar-wrapper`, n = q({
993
- title: !1,
994
- catalog: !1,
995
- // 图片上传下拉
996
- image: !1,
997
- // 表格预选
998
- table: !1,
999
- // mermaid
1000
- mermaid: !1,
1001
- katex: !1
1002
- }), a = (p, v) => {
1003
- k.emit(l, "replace", p, v);
1004
- }, d = q({
1005
- type: "link",
1006
- linkVisible: !1,
1007
- clipVisible: !1
1008
- }), m = B();
1009
- H(() => {
1010
- k.on(l, {
1011
- name: "openModals",
1012
- callback(p) {
1013
- d.type = p, d.linkVisible = !0;
1014
- }
1015
- });
1016
- });
1017
- const u = U(() => {
1018
- const p = e.toolbars.filter((C) => !e.toolbarsExclude.includes(C)), v = p.indexOf("="), b = v === -1 ? p : p.slice(0, v + 1), y = v === -1 ? [] : p.slice(v, Number.MAX_SAFE_INTEGER);
1019
- return [b, y];
1020
- }), c = B(), f = () => {
1021
- k.emit(l, "uploadImage", Array.from(c.value.files || [])), c.value.value = "";
1022
- };
1023
- H(() => {
1024
- c.value.addEventListener("change", f);
1025
- });
1026
- const h = (p) => {
1027
- var v, b, y, C, $, T, I, w, F, j, R, P, _, N, D, Q, z, ue, re, ee, X, ie, te, O, W, ae, me, Ie, He, Fe, Me, Be, Re, je, Pe, De, Oe, _e, Ne, Ve, Ue, qe, Ge;
1028
- if (bt.includes(p))
1029
- switch (p) {
1030
- case "-":
1031
- return i(Yt, null, null);
1032
- case "bold":
1033
- return i("div", {
1034
- class: `${s}-toolbar-item`,
1035
- title: (v = o.value.toolbarTips) == null ? void 0 : v.bold,
1036
- onClick: () => {
1037
- a("bold");
1038
- }
1039
- }, [i("svg", {
1040
- class: `${s}-icon`,
1041
- "aria-hidden": "true"
1042
- }, [i("use", {
1043
- "xlink:href": "#md-editor-icon-bold"
1044
- }, null)])]);
1045
- case "underline":
1046
- return i("div", {
1047
- class: `${s}-toolbar-item`,
1048
- title: (b = o.value.toolbarTips) == null ? void 0 : b.underline,
1049
- onClick: () => {
1050
- a("underline");
1051
- }
1052
- }, [i("svg", {
1053
- class: `${s}-icon`,
1054
- "aria-hidden": "true"
1055
- }, [i("use", {
1056
- "xlink:href": "#md-editor-icon-underline"
1057
- }, null)])]);
1058
- case "italic":
1059
- return i("div", {
1060
- class: `${s}-toolbar-item`,
1061
- title: (y = o.value.toolbarTips) == null ? void 0 : y.italic,
1062
- onClick: () => {
1063
- a("italic");
1064
- }
1065
- }, [i("svg", {
1066
- class: `${s}-icon`,
1067
- "aria-hidden": "true"
1068
- }, [i("use", {
1069
- "xlink:href": "#md-editor-icon-italic"
1070
- }, null)])]);
1071
- case "strikeThrough":
1072
- return i("div", {
1073
- class: `${s}-toolbar-item`,
1074
- title: (C = o.value.toolbarTips) == null ? void 0 : C.strikeThrough,
1075
- onClick: () => {
1076
- a("strikeThrough");
1077
- }
1078
- }, [i("svg", {
1079
- class: `${s}-icon`,
1080
- "aria-hidden": "true"
1081
- }, [i("use", {
1082
- "xlink:href": "#md-editor-icon-strike-through"
1083
- }, null)])]);
1084
- case "title":
1085
- return i(oe, {
1086
- relative: `#${r}`,
1087
- visible: n.title,
1088
- onChange: (E) => {
1089
- n.title = E;
1090
- },
1091
- overlay: i("ul", {
1092
- class: `${s}-menu`,
1093
- onClick: () => {
1094
- n.title = !1;
1095
- }
1096
- }, [i("li", {
1097
- class: `${s}-menu-item`,
1098
- onClick: () => {
1099
- a("h1");
1100
- }
1101
- }, [($ = o.value.titleItem) == null ? void 0 : $.h1]), i("li", {
1102
- class: `${s}-menu-item`,
1103
- onClick: () => {
1104
- a("h2");
1105
- }
1106
- }, [(T = o.value.titleItem) == null ? void 0 : T.h2]), i("li", {
1107
- class: `${s}-menu-item`,
1108
- onClick: () => {
1109
- a("h3");
1110
- }
1111
- }, [(I = o.value.titleItem) == null ? void 0 : I.h3]), i("li", {
1112
- class: `${s}-menu-item`,
1113
- onClick: () => {
1114
- a("h4");
1115
- }
1116
- }, [(w = o.value.titleItem) == null ? void 0 : w.h4]), i("li", {
1117
- class: `${s}-menu-item`,
1118
- onClick: () => {
1119
- a("h5");
1120
- }
1121
- }, [(F = o.value.titleItem) == null ? void 0 : F.h5]), i("li", {
1122
- class: `${s}-menu-item`,
1123
- onClick: () => {
1124
- a("h6");
1125
- }
1126
- }, [(j = o.value.titleItem) == null ? void 0 : j.h6])])
1127
- }, {
1128
- default: () => {
1129
- var E;
1130
- return [i("div", {
1131
- class: `${s}-toolbar-item`,
1132
- title: (E = o.value.toolbarTips) == null ? void 0 : E.title
1133
- }, [i("svg", {
1134
- class: `${s}-icon`,
1135
- "aria-hidden": "true"
1136
- }, [i("use", {
1137
- "xlink:href": "#md-editor-icon-title"
1138
- }, null)])])];
1139
- }
1140
- });
1141
- case "sub":
1142
- return i("div", {
1143
- class: `${s}-toolbar-item`,
1144
- title: (R = o.value.toolbarTips) == null ? void 0 : R.sub,
1145
- onClick: () => {
1146
- a("sub");
1147
- }
1148
- }, [i("svg", {
1149
- class: `${s}-icon`,
1150
- "aria-hidden": "true"
1151
- }, [i("use", {
1152
- "xlink:href": "#md-editor-icon-sub"
1153
- }, null)])]);
1154
- case "sup":
1155
- return i("div", {
1156
- class: `${s}-toolbar-item`,
1157
- title: (P = o.value.toolbarTips) == null ? void 0 : P.sup,
1158
- onClick: () => {
1159
- a("sup");
1160
- }
1161
- }, [i("svg", {
1162
- class: `${s}-icon`,
1163
- "aria-hidden": "true"
1164
- }, [i("use", {
1165
- "xlink:href": "#md-editor-icon-sup"
1166
- }, null)])]);
1167
- case "quote":
1168
- return i("div", {
1169
- class: `${s}-toolbar-item`,
1170
- title: (_ = o.value.toolbarTips) == null ? void 0 : _.quote,
1171
- onClick: () => {
1172
- a("quote");
1173
- }
1174
- }, [i("svg", {
1175
- class: `${s}-icon`,
1176
- "aria-hidden": "true"
1177
- }, [i("use", {
1178
- "xlink:href": "#md-editor-icon-quote"
1179
- }, null)])]);
1180
- case "unorderedList":
1181
- return i("div", {
1182
- class: `${s}-toolbar-item`,
1183
- title: (N = o.value.toolbarTips) == null ? void 0 : N.unorderedList,
1184
- onClick: () => {
1185
- a("unorderedList");
1186
- }
1187
- }, [i("svg", {
1188
- class: `${s}-icon`,
1189
- "aria-hidden": "true"
1190
- }, [i("use", {
1191
- "xlink:href": "#md-editor-icon-unordered-list"
1192
- }, null)])]);
1193
- case "orderedList":
1194
- return i("div", {
1195
- class: `${s}-toolbar-item`,
1196
- title: (D = o.value.toolbarTips) == null ? void 0 : D.orderedList,
1197
- onClick: () => {
1198
- a("orderedList");
1199
- }
1200
- }, [i("svg", {
1201
- class: `${s}-icon`,
1202
- "aria-hidden": "true"
1203
- }, [i("use", {
1204
- "xlink:href": "#md-editor-icon-ordered-list"
1205
- }, null)])]);
1206
- case "task":
1207
- return i("div", {
1208
- class: `${s}-toolbar-item`,
1209
- title: (Q = o.value.toolbarTips) == null ? void 0 : Q.task,
1210
- onClick: () => {
1211
- a("task");
1212
- }
1213
- }, [i("svg", {
1214
- class: `${s}-icon`,
1215
- "aria-hidden": "true"
1216
- }, [i("use", {
1217
- "xlink:href": "#md-editor-icon-task"
1218
- }, null)])]);
1219
- case "codeRow":
1220
- return i("div", {
1221
- class: `${s}-toolbar-item`,
1222
- title: (z = o.value.toolbarTips) == null ? void 0 : z.codeRow,
1223
- onClick: () => {
1224
- a("codeRow");
1225
- }
1226
- }, [i("svg", {
1227
- class: `${s}-icon`,
1228
- "aria-hidden": "true"
1229
- }, [i("use", {
1230
- "xlink:href": "#md-editor-icon-code-row"
1231
- }, null)])]);
1232
- case "code":
1233
- return i("div", {
1234
- class: `${s}-toolbar-item`,
1235
- title: (ue = o.value.toolbarTips) == null ? void 0 : ue.code,
1236
- onClick: () => {
1237
- a("code");
1238
- }
1239
- }, [i("svg", {
1240
- class: `${s}-icon`,
1241
- "aria-hidden": "true"
1242
- }, [i("use", {
1243
- "xlink:href": "#md-editor-icon-code"
1244
- }, null)])]);
1245
- case "link":
1246
- return i("div", {
1247
- class: `${s}-toolbar-item`,
1248
- title: (re = o.value.toolbarTips) == null ? void 0 : re.link,
1249
- onClick: () => {
1250
- d.type = "link", d.linkVisible = !0;
1251
- }
1252
- }, [i("svg", {
1253
- class: `${s}-icon`,
1254
- "aria-hidden": "true"
1255
- }, [i("use", {
1256
- "xlink:href": "#md-editor-icon-link"
1257
- }, null)])]);
1258
- case "image":
1259
- return e.noUploadImg ? i("div", {
1260
- class: `${s}-toolbar-item`,
1261
- title: (ee = o.value.toolbarTips) == null ? void 0 : ee.image,
1262
- onClick: () => {
1263
- d.type = "image", d.linkVisible = !0;
1264
- }
1265
- }, [i("svg", {
1266
- class: `${s}-icon`,
1267
- "aria-hidden": "true"
1268
- }, [i("use", {
1269
- "xlink:href": "#md-editor-icon-image"
1270
- }, null)])]) : i(oe, {
1271
- relative: `#${r}`,
1272
- visible: n.image,
1273
- onChange: (E) => {
1274
- n.image = E;
1275
- },
1276
- overlay: i("ul", {
1277
- class: `${s}-menu`,
1278
- onClick: () => {
1279
- n.title = !1;
1280
- }
1281
- }, [i("li", {
1282
- class: `${s}-menu-item`,
1283
- onClick: () => {
1284
- d.type = "image", d.linkVisible = !0;
1285
- }
1286
- }, [(X = o.value.imgTitleItem) == null ? void 0 : X.link]), i("li", {
1287
- class: `${s}-menu-item`,
1288
- onClick: () => {
1289
- c.value.click();
1290
- }
1291
- }, [(ie = o.value.imgTitleItem) == null ? void 0 : ie.upload]), i("li", {
1292
- class: `${s}-menu-item`,
1293
- onClick: () => {
1294
- d.clipVisible = !0;
1295
- }
1296
- }, [(te = o.value.imgTitleItem) == null ? void 0 : te.clip2upload])])
1297
- }, {
1298
- default: () => {
1299
- var E;
1300
- return [i("div", {
1301
- class: `${s}-toolbar-item`,
1302
- title: (E = o.value.toolbarTips) == null ? void 0 : E.image
1303
- }, [i("svg", {
1304
- class: `${s}-icon`,
1305
- "aria-hidden": "true"
1306
- }, [i("use", {
1307
- "xlink:href": "#md-editor-icon-image"
1308
- }, null)])])];
1309
- }
1310
- });
1311
- case "table":
1312
- return i(oe, {
1313
- relative: `#${r}`,
1314
- visible: n.table,
1315
- onChange: (E) => {
1316
- n.table = E;
1317
- },
1318
- key: "bar-table",
1319
- overlay: i(ul, {
1320
- tableShape: e.tableShape,
1321
- onSelected: (E) => {
1322
- a("table", {
1323
- selectedShape: E
1324
- });
1325
- }
1326
- }, null)
1327
- }, {
1328
- default: () => {
1329
- var E;
1330
- return [i("div", {
1331
- class: `${s}-toolbar-item`,
1332
- title: (E = o.value.toolbarTips) == null ? void 0 : E.table
1333
- }, [i("svg", {
1334
- class: `${s}-icon`,
1335
- "aria-hidden": "true"
1336
- }, [i("use", {
1337
- "xlink:href": "#md-editor-icon-table"
1338
- }, null)])])];
1339
- }
1340
- });
1341
- case "revoke":
1342
- return i("div", {
1343
- class: `${s}-toolbar-item`,
1344
- title: (O = o.value.toolbarTips) == null ? void 0 : O.revoke,
1345
- onClick: () => {
1346
- k.emit(l, "ctrlZ");
1347
- }
1348
- }, [i("svg", {
1349
- class: `${s}-icon`,
1350
- "aria-hidden": "true"
1351
- }, [i("use", {
1352
- "xlink:href": "#md-editor-icon-revoke"
1353
- }, null)])]);
1354
- case "next":
1355
- return i("div", {
1356
- class: `${s}-toolbar-item`,
1357
- title: (W = o.value.toolbarTips) == null ? void 0 : W.next,
1358
- onClick: () => {
1359
- k.emit(l, "ctrlShiftZ");
1360
- }
1361
- }, [i("svg", {
1362
- class: `${s}-icon`,
1363
- "aria-hidden": "true"
1364
- }, [i("use", {
1365
- "xlink:href": "#md-editor-icon-next"
1366
- }, null)])]);
1367
- case "save":
1368
- return i("div", {
1369
- class: `${s}-toolbar-item`,
1370
- title: (ae = o.value.toolbarTips) == null ? void 0 : ae.save,
1371
- onClick: () => {
1372
- k.emit(l, pe);
1373
- }
1374
- }, [i("svg", {
1375
- class: `${s}-icon`,
1376
- "aria-hidden": "true"
1377
- }, [i("use", {
1378
- "xlink:href": "#md-editor-icon-baocun"
1379
- }, null)])]);
1380
- case "prettier":
1381
- return e.noPrettier ? "" : i("div", {
1382
- class: `${s}-toolbar-item`,
1383
- title: (me = o.value.toolbarTips) == null ? void 0 : me.prettier,
1384
- onClick: () => {
1385
- a("prettier");
1386
- }
1387
- }, [i("svg", {
1388
- class: `${s}-icon`,
1389
- "aria-hidden": "true"
1390
- }, [i("use", {
1391
- "xlink:href": "#md-editor-icon-prettier"
1392
- }, null)])]);
1393
- case "pageFullscreen":
1394
- return !e.setting.fullscreen && i("div", {
1395
- class: `${s}-toolbar-item`,
1396
- title: (Ie = o.value.toolbarTips) == null ? void 0 : Ie.pageFullscreen,
1397
- onClick: () => {
1398
- e.updateSetting("pageFullscreen");
1399
- }
1400
- }, [i("svg", {
1401
- class: `${s}-icon`,
1402
- "aria-hidden": "true"
1403
- }, [i("use", {
1404
- "xlink:href": `#md-editor-icon-${e.setting.pageFullscreen ? "suoxiao" : "fangda"}`
1405
- }, null)])]);
1406
- case "fullscreen":
1407
- return i("div", {
1408
- class: `${s}-toolbar-item`,
1409
- title: (He = o.value.toolbarTips) == null ? void 0 : He.fullscreen,
1410
- onClick: () => {
1411
- t();
1412
- }
1413
- }, [i("svg", {
1414
- class: `${s}-icon`,
1415
- "aria-hidden": "true"
1416
- }, [i("use", {
1417
- "xlink:href": `#md-editor-icon-${e.setting.fullscreen ? "fullscreen-exit" : "fullscreen"}`
1418
- }, null)])]);
1419
- case "preview":
1420
- return i("div", {
1421
- class: `${s}-toolbar-item`,
1422
- title: (Fe = o.value.toolbarTips) == null ? void 0 : Fe.preview,
1423
- onClick: () => {
1424
- e.updateSetting("preview");
1425
- }
1426
- }, [i("svg", {
1427
- class: `${s}-icon`,
1428
- "aria-hidden": "true"
1429
- }, [i("use", {
1430
- "xlink:href": "#md-editor-icon-preview"
1431
- }, null)])]);
1432
- case "htmlPreview":
1433
- return i("div", {
1434
- class: `${s}-toolbar-item`,
1435
- title: (Me = o.value.toolbarTips) == null ? void 0 : Me.htmlPreview,
1436
- onClick: () => {
1437
- e.updateSetting("htmlPreview");
1438
- }
1439
- }, [i("svg", {
1440
- class: `${s}-icon`,
1441
- "aria-hidden": "true"
1442
- }, [i("use", {
1443
- "xlink:href": "#md-editor-icon-coding"
1444
- }, null)])]);
1445
- case "catalog":
1446
- return i("div", {
1447
- class: `${s}-toolbar-item`,
1448
- title: (Be = o.value.toolbarTips) == null ? void 0 : Be.catalog,
1449
- onClick: () => {
1450
- k.emit(l, Le);
1451
- },
1452
- key: "bar-catalog"
1453
- }, [i("svg", {
1454
- class: `${s}-icon`,
1455
- "aria-hidden": "true"
1456
- }, [i("use", {
1457
- "xlink:href": "#md-editor-icon-catalog"
1458
- }, null)])]);
1459
- case "github":
1460
- return i("div", {
1461
- class: `${s}-toolbar-item`,
1462
- title: (Re = o.value.toolbarTips) == null ? void 0 : Re.github,
1463
- onClick: () => tl("https://github.com/imzbf/md-editor-v3")
1464
- }, [i("svg", {
1465
- class: `${s}-icon`,
1466
- "aria-hidden": "true"
1467
- }, [i("use", {
1468
- "xlink:href": "#md-editor-icon-github"
1469
- }, null)])]);
1470
- case "mermaid":
1471
- return i(oe, {
1472
- relative: `#${r}`,
1473
- visible: n.mermaid,
1474
- onChange: (E) => {
1475
- n.mermaid = E;
1476
- },
1477
- overlay: i("ul", {
1478
- class: `${s}-menu`,
1479
- onClick: () => {
1480
- n.mermaid = !1;
1481
- }
1482
- }, [i("li", {
1483
- class: `${s}-menu-item`,
1484
- onClick: () => {
1485
- a("flow");
1486
- }
1487
- }, [(je = o.value.mermaid) == null ? void 0 : je.flow]), i("li", {
1488
- class: `${s}-menu-item`,
1489
- onClick: () => {
1490
- a("sequence");
1491
- }
1492
- }, [(Pe = o.value.mermaid) == null ? void 0 : Pe.sequence]), i("li", {
1493
- class: `${s}-menu-item`,
1494
- onClick: () => {
1495
- a("gantt");
1496
- }
1497
- }, [(De = o.value.mermaid) == null ? void 0 : De.gantt]), i("li", {
1498
- class: `${s}-menu-item`,
1499
- onClick: () => {
1500
- a("class");
1501
- }
1502
- }, [(Oe = o.value.mermaid) == null ? void 0 : Oe.class]), i("li", {
1503
- class: `${s}-menu-item`,
1504
- onClick: () => {
1505
- a("state");
1506
- }
1507
- }, [(_e = o.value.mermaid) == null ? void 0 : _e.state]), i("li", {
1508
- class: `${s}-menu-item`,
1509
- onClick: () => {
1510
- a("pie");
1511
- }
1512
- }, [(Ne = o.value.mermaid) == null ? void 0 : Ne.pie]), i("li", {
1513
- class: `${s}-menu-item`,
1514
- onClick: () => {
1515
- a("relationship");
1516
- }
1517
- }, [(Ve = o.value.mermaid) == null ? void 0 : Ve.relationship]), i("li", {
1518
- class: `${s}-menu-item`,
1519
- onClick: () => {
1520
- a("journey");
1521
- }
1522
- }, [(Ue = o.value.mermaid) == null ? void 0 : Ue.journey])]),
1523
- key: "bar-mermaid"
1524
- }, {
1525
- default: () => {
1526
- var E;
1527
- return [i("div", {
1528
- class: `${s}-toolbar-item`,
1529
- title: (E = o.value.toolbarTips) == null ? void 0 : E.mermaid
1530
- }, [i("svg", {
1531
- class: `${s}-icon`,
1532
- "aria-hidden": "true"
1533
- }, [i("use", {
1534
- "xlink:href": "#md-editor-icon-mermaid"
1535
- }, null)])])];
1536
- }
1537
- });
1538
- case "katex":
1539
- return i(oe, {
1540
- relative: `#${r}`,
1541
- visible: n.katex,
1542
- onChange: (E) => {
1543
- n.katex = E;
1544
- },
1545
- overlay: i("ul", {
1546
- class: `${s}-menu`,
1547
- onClick: () => {
1548
- n.katex = !1;
1549
- }
1550
- }, [i("li", {
1551
- class: `${s}-menu-item`,
1552
- onClick: () => {
1553
- a("katexInline");
1554
- }
1555
- }, [(qe = o.value.katex) == null ? void 0 : qe.inline]), i("li", {
1556
- class: `${s}-menu-item`,
1557
- onClick: () => {
1558
- a("katexBlock");
1559
- }
1560
- }, [(Ge = o.value.katex) == null ? void 0 : Ge.block])]),
1561
- key: "bar-katex"
1562
- }, {
1563
- default: () => {
1564
- var E;
1565
- return [i("div", {
1566
- class: `${s}-toolbar-item`,
1567
- title: (E = o.value.toolbarTips) == null ? void 0 : E.katex
1568
- }, [i("svg", {
1569
- class: `${s}-icon`,
1570
- "aria-hidden": "true"
1571
- }, [i("use", {
1572
- "xlink:href": "#md-editor-icon-formula"
1573
- }, null)])])];
1574
- }
1575
- });
1576
- }
1577
- else
1578
- return e.defToolbars instanceof Array ? e.defToolbars[p] || "" : e.defToolbars && e.defToolbars.children instanceof Array && e.defToolbars.children[p] || "";
1579
- };
1580
- return () => {
1581
- const p = u.value[0].map((b) => h(b)), v = u.value[1].map((b) => h(b));
1582
- return i(xe, null, [e.toolbars.length > 0 && i("div", {
1583
- class: `${s}-toolbar-wrapper`,
1584
- id: r
1585
- }, [i("div", {
1586
- class: `${s}-toolbar`
1587
- }, [i("div", {
1588
- class: `${s}-toolbar-left`,
1589
- ref: m
1590
- }, [p]), i("div", {
1591
- class: `${s}-toolbar-right`
1592
- }, [v])])]), i("input", {
1593
- ref: c,
1594
- accept: "image/*",
1595
- type: "file",
1596
- multiple: !0,
1597
- style: {
1598
- display: "none"
1599
- }
1600
- }, null), i(bl, {
1601
- linkVisible: d.linkVisible,
1602
- clipVisible: d.clipVisible,
1603
- type: d.type,
1604
- onCancel: () => {
1605
- d.linkVisible = !1, d.clipVisible = !1;
1606
- },
1607
- onOk: (b) => {
1608
- b && a(d.type, {
1609
- desc: b.desc,
1610
- url: b.url
1611
- }), d.linkVisible = !1, d.clipVisible = !1;
1612
- }
1613
- }, null)]);
1614
- };
1615
- }
1616
- }), lt = (e, l, o) => {
1617
- let t = e.scrollTop;
1618
- const r = () => {
1619
- const n = l - t;
1620
- t = t + n / 5, Math.abs(n) < 1 ? (e.scrollTo(0, l), o && setTimeout(o, 100)) : (e.scrollTo(0, t), requestAnimationFrame(r));
1621
- };
1622
- r();
1623
- }, yl = (e, l) => {
1624
- const o = ve(() => {
1625
- e.removeEventListener("scroll", t), e.addEventListener("scroll", t), l.removeEventListener("scroll", t), l.addEventListener("scroll", t);
1626
- }, 50), t = (r) => {
1627
- const n = e.clientHeight, a = l.clientHeight, d = e.scrollHeight, m = l.scrollHeight, u = (d - n) / (m - a);
1628
- r.target === e ? (l.removeEventListener("scroll", t), l.scrollTo({
1629
- top: e.scrollTop / u
1630
- // behavior: 'smooth'
1631
- }), o()) : (e.removeEventListener("scroll", t), e.scrollTo({
1632
- top: l.scrollTop * u
1633
- // behavior: 'smooth'
1634
- }), o());
1635
- };
1636
- return [
1637
- () => {
1638
- o().finally(() => {
1639
- e.dispatchEvent(new Event("scroll"));
1640
- });
1641
- },
1642
- () => {
1643
- e.removeEventListener("scroll", t), l.removeEventListener("scroll", t);
1644
- }
1645
- ];
1646
- }, Cl = (e, l, o) => {
1647
- const { view: t } = o, r = (f) => t.lineBlockAt(t.state.doc.line(f).from).top, n = (f) => t.lineBlockAt(t.state.doc.line(f).from).height;
1648
- let a = [];
1649
- const d = () => {
1650
- a = [];
1651
- const f = Array.from(l.querySelectorAll("[data-line]")).map(
1652
- (b) => Number(b.dataset.line) + 1
1653
- ), { lines: h } = t.state.doc;
1654
- let p = 1, v = f.shift() ?? h;
1655
- for (let b = 1; b <= h; b++)
1656
- b === v && (p = b, v = f.shift() || h + 1), a.push({
1657
- start: p,
1658
- end: v - 1
1659
- });
1660
- };
1661
- let m = 0, u = 0;
1662
- const c = (f) => {
1663
- var v, b, y, C, $, T, I;
1664
- if (!((v = l.firstElementChild) != null && v.firstElementChild))
1665
- return;
1666
- const h = t.lineBlockAtHeight(t.scrollDOM.scrollTop), { number: p } = t.state.doc.lineAt(h.from);
1667
- if (!(p > a.length) && !(t.state.doc.lines < a[a.length - 1].end))
1668
- if (f.target === e) {
1669
- if (u !== 0)
1670
- return;
1671
- m++;
1672
- const w = a[p - 1], F = r(w.end) + n(w.end);
1673
- let j = 0;
1674
- const R = r(w.start), P = l.querySelector(`[data-line="${w.start - 1}"]`) || ((b = l.firstElementChild) == null ? void 0 : b.firstElementChild), _ = l.querySelector(`[data-line="${w.end}"]`) || ((y = l.lastElementChild) == null ? void 0 : y.lastElementChild);
1675
- let N = 0, D = 0;
1676
- R === 0 ? (j = (t.scrollDOM.scrollTop - R) / (F - R), N = _.offsetTop) : F > t.scrollDOM.scrollHeight - t.scrollDOM.clientHeight ? (j = (t.scrollDOM.scrollTop - R) / (t.scrollDOM.scrollHeight - t.scrollDOM.clientHeight - R), D = P.offsetTop, N = l.scrollHeight - l.clientHeight - D + 10) : (j = (t.scrollDOM.scrollTop - R) / (F - R), D = P.offsetTop, N = _.offsetTop - D);
1677
- const Q = D - 10 + N * j;
1678
- lt(l, Q, () => {
1679
- m--;
1680
- });
1681
- } else {
1682
- if (m !== 0)
1683
- return;
1684
- u++;
1685
- const w = Array.from(
1686
- l.querySelectorAll("[data-line]")
1687
- ), F = l.scrollTop, j = l.scrollHeight;
1688
- let R = w.length === 0 ? 1 : Math.ceil(
1689
- Number(w[w.length - 1].dataset.line) * (F / j)
1690
- ), P = (C = l.firstElementChild) == null ? void 0 : C.firstElementChild;
1691
- for (let O = R; O >= 0; O--) {
1692
- const W = l.querySelector(`[data-line="${O}"]`);
1693
- if (W) {
1694
- P = W, R = O;
1695
- break;
1696
- }
1697
- }
1698
- let _ = ($ = l.firstElementChild) == null ? void 0 : $.firstElementChild, N = (T = l.firstElementChild) == null ? void 0 : T.lastElementChild;
1699
- for (; w.length > 0; ) {
1700
- const O = w.indexOf(P);
1701
- if (O + 1 >= w.length)
1702
- break;
1703
- const W = w[O + 1], ae = P.offsetTop;
1704
- if (ae > F) {
1705
- if (O === 0) {
1706
- _ = P, N = W;
1707
- break;
1708
- }
1709
- P = w[O - 1];
1710
- continue;
1711
- }
1712
- const me = W.offsetTop;
1713
- if (ae <= F && me > F) {
1714
- _ = P, N = W;
1715
- break;
1716
- }
1717
- P = W;
1718
- }
1719
- const D = _.offsetTop, Q = N.offsetTop;
1720
- let z = 0;
1721
- const { start: ue, end: re } = a[Number(_.dataset.line || 0)], ee = r(ue);
1722
- let X = r(re);
1723
- const ie = n(re);
1724
- let te = 0;
1725
- _ === ((I = l.firstElementChild) == null ? void 0 : I.firstElementChild) ? (z = Math.max(F / Q, 0), te = X + ie - ee) : X > t.scrollDOM.scrollHeight - t.scrollDOM.clientHeight ? (z = Math.max(
1726
- (F - D) / (l.scrollHeight - D - l.clientHeight),
1727
- 0
1728
- ), X = r(t.state.doc.lines) + n(t.state.doc.lines), te = 8 + X - ee - e.clientHeight) : (z = Math.max(
1729
- (F - D) / (Q - D),
1730
- 0
1731
- ), te = X + ie - ee), lt(e, ee + te * z, () => {
1732
- u--;
1733
- });
1734
- }
1735
- };
1736
- return [
1737
- () => {
1738
- d(), e.addEventListener("scroll", c), l.addEventListener("scroll", c), e.dispatchEvent(new Event("scroll"));
1739
- },
1740
- () => {
1741
- a = [], e.removeEventListener("scroll", c), l.removeEventListener("scroll", c);
1742
- }
1743
- ];
1744
- }, $l = (e, l, o, t, r) => {
1745
- const n = x("previewOnly");
1746
- let a = () => {
1747
- }, d = () => {
1748
- };
1749
- const m = () => {
1750
- a();
1751
- const u = document.querySelector(".cm-scroller");
1752
- !n && (o.value || t.value) && ([d, a] = (o.value ? Cl : yl)(
1753
- u,
1754
- o.value || t.value,
1755
- r.value
1756
- )), e.scrollAuto && d();
1757
- };
1758
- S(
1759
- [
1760
- l,
1761
- ne(e.setting, "preview"),
1762
- ne(e.setting, "htmlPreview"),
1763
- ne(e.setting, "fullscreen"),
1764
- ne(e.setting, "pageFullscreen")
1765
- ],
1766
- () => {
1767
- Y(m);
1768
- }
1769
- ), S(
1770
- () => e.scrollAuto,
1771
- (u) => {
1772
- u ? d() : a();
1773
- }
1774
- ), H(m);
1775
- }, wl = (e, l, o) => {
1776
- var c, f, h, p, v, b;
1777
- let t = "", r = 0, n = 0, a = !0, d = !1;
1778
- const m = l.getSelectedText(), u = (c = A.editorConfig) == null ? void 0 : c.mermaidTemplate;
1779
- if (/^h[1-6]{1}$/.test(e)) {
1780
- const y = e.replace(/^h(\d)/, (C, $) => new Array(Number($)).fill("#", 0, $).join(""));
1781
- t = `${y} ${m}`, r = y.length + 1;
1782
- } else if (e === "prettier") {
1783
- const y = window.prettier || ((h = (f = A.editorExtensions) == null ? void 0 : f.prettier) == null ? void 0 : h.prettierInstance), C = [
1784
- ((p = window.prettierPlugins) == null ? void 0 : p.markdown) || ((b = (v = A.editorExtensions) == null ? void 0 : v.prettier) == null ? void 0 : b.parserMarkdownInstance)
1785
- ];
1786
- !y || C[0] === void 0 ? (k.emit(o.editorId, "errorCatcher", {
1787
- name: "prettier",
1788
- message: "prettier is undefined"
1789
- }), t = l.getValue()) : t = y.format(l.getValue(), {
1790
- parser: "markdown",
1791
- plugins: C
1792
- }), a = !1, d = !0;
1793
- } else
1794
- switch (e) {
1795
- case "bold": {
1796
- t = `**${m}**`, r = 2, n = -2;
1797
- break;
1798
- }
1799
- case "underline": {
1800
- t = `<u>${m}</u>`, r = 3, n = -4;
1801
- break;
1802
- }
1803
- case "italic": {
1804
- t = `*${m}*`, r = 1, n = -1;
1805
- break;
1806
- }
1807
- case "strikeThrough": {
1808
- t = `~~${m}~~`, r = 2, n = -2;
1809
- break;
1810
- }
1811
- case "sub": {
1812
- t = `<sub>${m}</sub>`, r = 5, n = -6;
1813
- break;
1814
- }
1815
- case "sup": {
1816
- t = `<sup>${m}</sup>`, r = 5, n = -6;
1817
- break;
1818
- }
1819
- case "codeRow": {
1820
- t = "`" + m + "`", r = 1, n = -1;
1821
- break;
1822
- }
1823
- case "quote": {
1824
- t = `> ${m}`, r = 2;
1825
- break;
1826
- }
1827
- case "orderedList": {
1828
- t = `1. ${m}`, r = 3;
1829
- break;
1830
- }
1831
- case "unorderedList": {
1832
- t = `- ${m}`, r = 2;
1833
- break;
1834
- }
1835
- case "task": {
1836
- t = `- [ ] ${m}`, r = 6;
1837
- break;
1838
- }
1839
- case "code": {
1840
- const y = o.text || m || "", C = o.mode || "language";
1841
- t = `\`\`\`${C}
1842
- ${y}
1843
- \`\`\`
1844
- `, r = 3, n = 3 + C.length - t.length;
1845
- break;
1846
- }
1847
- case "table": {
1848
- t = "|";
1849
- const { selectedShape: y = { x: 1, y: 1 } } = o, { x: C, y: $ } = y;
1850
- for (let T = 0; T <= $; T++)
1851
- t += " col |";
1852
- t += `
1853
- |`;
1854
- for (let T = 0; T <= $; T++)
1855
- t += " - |";
1856
- for (let T = 0; T <= C; T++) {
1857
- t += `
1858
- |`;
1859
- for (let I = 0; I <= $; I++)
1860
- t += " content |";
1861
- }
1862
- r = 2, n = 5 - t.length;
1863
- break;
1864
- }
1865
- case "link": {
1866
- const { desc: y, url: C } = o;
1867
- t = `[${y}](${C})`, a = !1;
1868
- break;
1869
- }
1870
- case "image": {
1871
- const { desc: y, url: C, urls: $ } = o;
1872
- $ instanceof Array ? t = $.reduce((T, I) => T + `![${y}](${I})
1873
- `, "") : t = `![${y}](${C})
1874
- `, a = !1;
1875
- break;
1876
- }
1877
- case "flow": {
1878
- t = `\`\`\`mermaid
1879
- ${(u == null ? void 0 : u.flow) || `flowchart TD
1880
- Start --> Stop`}
1881
- \`\`\`
1882
- `, r = 3, n = 10 - t.length;
1883
- break;
1884
- }
1885
- case "sequence": {
1886
- t = `\`\`\`mermaid
1887
- ${(u == null ? void 0 : u.sequence) || `sequenceDiagram
1888
- A->>B: hello!
1889
- B-->>A: hi!
1890
- A-)B: bye!`}
1891
- \`\`\`
1892
- `, r = 3, n = 10 - t.length;
1893
- break;
1894
- }
1895
- case "gantt": {
1896
- t = `\`\`\`mermaid
1897
- ${(u == null ? void 0 : u.gantt) || `gantt
1898
- title A Gantt Diagram
1899
- dateFormat YYYY-MM-DD
1900
- section Section
1901
- A task :a1, 2014-01-01, 30d
1902
- Another task :after a1, 20d`}
1903
- \`\`\`
1904
- `, r = 3, n = 10 - t.length;
1905
- break;
1906
- }
1907
- case "class": {
1908
- t = `\`\`\`mermaid
1909
- ${(u == null ? void 0 : u.class) || `classDiagram
1910
- class Animal
1911
- Vehicle <|-- Car`}
1912
- \`\`\`
1913
- `, r = 3, n = 10 - t.length;
1914
- break;
1915
- }
1916
- case "state": {
1917
- t = `\`\`\`mermaid
1918
- ${(u == null ? void 0 : u.state) || `stateDiagram-v2
1919
- s1 --> s2`}
1920
- \`\`\`
1921
- `, r = 3, n = 10 - t.length;
1922
- break;
1923
- }
1924
- case "pie": {
1925
- t = `\`\`\`mermaid
1926
- ${(u == null ? void 0 : u.pie) || `pie title Pets adopted by volunteers
1927
- "Dogs" : 386
1928
- "Cats" : 85
1929
- "Rats" : 15`}
1930
- \`\`\`
1931
- `, r = 3, n = 10 - t.length;
1932
- break;
1933
- }
1934
- case "relationship": {
1935
- t = `\`\`\`mermaid
1936
- ${(u == null ? void 0 : u.relationship) || `erDiagram
1937
- CAR ||--o{ NAMED-DRIVER : allows
1938
- PERSON ||--o{ NAMED-DRIVER : is`}
1939
- \`\`\`
1940
- `, r = 3, n = 10 - t.length;
1941
- break;
1942
- }
1943
- case "journey": {
1944
- t = `\`\`\`mermaid
1945
- ${(u == null ? void 0 : u.journey) || `journey
1946
- title My working day
1947
- section Go to work
1948
- Make tea: 5: Me
1949
- Go upstairs: 3: Me
1950
- Do work: 1: Me, Cat
1951
- section Go home
1952
- Go downstairs: 5: Me
1953
- Sit down: 5: Me`}
1954
- \`\`\`
1955
- `, r = 3, n = 10 - t.length;
1956
- break;
1957
- }
1958
- case "katexInline": {
1959
- t = "$$", r = 1, n = -1;
1960
- break;
1961
- }
1962
- case "katexBlock": {
1963
- t = `$$
1964
-
1965
- $$
1966
- `, r = 3, n = -4;
1967
- break;
1968
- }
1969
- case "universal": {
1970
- const { generate: y } = o, C = y(m);
1971
- t = C.targetValue, a = C.select, r = C.deviationStart, n = C.deviationEnd;
1972
- }
1973
- }
1974
- return {
1975
- text: t,
1976
- options: {
1977
- // 是否选中
1978
- select: a,
1979
- // 选中时,开始位置的偏移量
1980
- deviationStart: r,
1981
- // 结束的偏移量
1982
- deviationEnd: n,
1983
- // 是否整个替换
1984
- replaceAll: d
1985
- }
1986
- };
1987
- }, Tl = "#e5c07b", ot = "var(--md-color)", Sl = "#56b6c2", xl = "#ffffff", se = "var(--md-color)", nt = "#e5c07b", El = "#e5c07b", Ll = "var(--md-color)", rt = "#d19a66", Al = "#c678dd", Il = "#21252b", it = "#2c313a", at = "#000", ke = "#353a42", Hl = "#ceedfa33", st = "#528bff", Fl = Ee.theme(
1988
- {
1989
- "&": {
1990
- color: se,
1991
- backgroundColor: at
1992
- },
1993
- ".cm-content": {
1994
- caretColor: st
1995
- },
1996
- ".cm-cursor, .cm-dropCursor": { borderLeftColor: st },
1997
- "&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": { backgroundColor: Hl },
1998
- ".cm-panels": { backgroundColor: Il, color: se },
1999
- ".cm-panels.cm-panels-top": { borderBottom: "2px solid black" },
2000
- ".cm-panels.cm-panels-bottom": { borderTop: "2px solid black" },
2001
- ".cm-searchMatch": {
2002
- backgroundColor: "#72a1ff59",
2003
- outline: "1px solid #457dff"
2004
- },
2005
- ".cm-searchMatch.cm-searchMatch-selected": {
2006
- backgroundColor: "#6199ff2f"
2007
- },
2008
- ".cm-activeLine": { backgroundColor: "#ceedfa33" },
2009
- ".cm-selectionMatch": { backgroundColor: "#aafe661a" },
2010
- "&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket": {
2011
- backgroundColor: "#bad0f847"
2012
- },
2013
- ".cm-gutters": {
2014
- backgroundColor: at,
2015
- color: se,
2016
- borderRight: "1px solid",
2017
- borderColor: "var(--md-border-color)"
2018
- },
2019
- ".cm-activeLineGutter": {
2020
- backgroundColor: it
2021
- },
2022
- ".cm-foldPlaceholder": {
2023
- backgroundColor: "transparent",
2024
- border: "none",
2025
- color: "#ddd"
2026
- },
2027
- ".cm-tooltip": {
2028
- border: "none",
2029
- backgroundColor: ke
2030
- },
2031
- ".cm-tooltip .cm-tooltip-arrow:before": {
2032
- borderTopColor: "transparent",
2033
- borderBottomColor: "transparent"
2034
- },
2035
- ".cm-tooltip .cm-tooltip-arrow:after": {
2036
- borderTopColor: ke,
2037
- borderBottomColor: ke
2038
- },
2039
- ".cm-tooltip-autocomplete": {
2040
- "& > ul > li[aria-selected]": {
2041
- backgroundColor: it,
2042
- color: se
2043
- }
2044
- }
2045
- },
2046
- { dark: !0 }
2047
- ), Ml = vt.define([
2048
- { tag: g.keyword, color: Al },
2049
- { tag: [g.name, g.deleted, g.character, g.propertyName, g.macroName], color: ot },
2050
- { tag: [g.function(g.variableName), g.labelName], color: El },
2051
- { tag: [g.color, g.constant(g.name), g.standard(g.name)], color: rt },
2052
- { tag: [g.definition(g.name), g.separator], color: se },
2053
- {
2054
- tag: [
2055
- g.typeName,
2056
- g.className,
2057
- g.number,
2058
- g.changed,
2059
- g.annotation,
2060
- g.modifier,
2061
- g.self,
2062
- g.namespace
2063
- ],
2064
- color: Tl
2065
- },
2066
- {
2067
- tag: [
2068
- g.operator,
2069
- g.operatorKeyword,
2070
- g.url,
2071
- g.escape,
2072
- g.regexp,
2073
- g.link,
2074
- g.special(g.string)
2075
- ],
2076
- color: Sl
2077
- },
2078
- { tag: [g.meta, g.comment], color: nt },
2079
- { tag: g.strong, fontWeight: "bold" },
2080
- { tag: g.emphasis, fontStyle: "italic" },
2081
- { tag: g.strikethrough, textDecoration: "line-through" },
2082
- { tag: g.link, color: nt, textDecoration: "underline" },
2083
- { tag: g.heading, fontWeight: "bold", color: ot },
2084
- { tag: [g.atom, g.bool, g.special(g.variableName)], color: rt },
2085
- { tag: [g.processingInstruction, g.string, g.inserted], color: Ll },
2086
- { tag: g.invalid, color: xl }
2087
- ]), Bl = [
2088
- Fl,
2089
- pt(Ml)
2090
- ], Rl = "#e5c07b", ct = "#3f4a54", jl = "#56b6c2", Pl = "#fff", ce = "#3f4a54", dt = "#2d8cf0", Dl = "#2d8cf0", Ol = "#3f4a54", ut = "#d19a66", _l = "#c678dd", Nl = "#21252b", mt = "#ceedfa33", ft = "#fff", ye = "#353a42", Vl = "#bad5fa", gt = "#3f4a54", Ul = Ee.theme(
2091
- {
2092
- "&": {
2093
- color: ce,
2094
- backgroundColor: ft
2095
- },
2096
- ".cm-content": {
2097
- caretColor: gt
2098
- },
2099
- ".cm-cursor, .cm-dropCursor": { borderLeftColor: gt },
2100
- "&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection": { backgroundColor: Vl },
2101
- ".cm-panels": { backgroundColor: Nl, color: ce },
2102
- ".cm-panels.cm-panels-top": { borderBottom: "2px solid black" },
2103
- ".cm-panels.cm-panels-bottom": { borderTop: "2px solid black" },
2104
- ".cm-searchMatch": {
2105
- backgroundColor: "#72a1ff59",
2106
- outline: "1px solid #457dff"
2107
- },
2108
- ".cm-searchMatch.cm-searchMatch-selected": {
2109
- backgroundColor: "#6199ff2f"
2110
- },
2111
- ".cm-activeLine": { backgroundColor: "#ceedfa33" },
2112
- ".cm-selectionMatch": { backgroundColor: "#aafe661a" },
2113
- "&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket": {
2114
- backgroundColor: "#bad0f847"
2115
- },
2116
- ".cm-gutters": {
2117
- backgroundColor: ft,
2118
- color: ce,
2119
- borderRight: "1px solid",
2120
- borderColor: "var(--md-border-color)"
2121
- },
2122
- ".cm-activeLineGutter": {
2123
- backgroundColor: mt
2124
- },
2125
- ".cm-foldPlaceholder": {
2126
- backgroundColor: "transparent",
2127
- border: "none",
2128
- color: "#ddd"
2129
- },
2130
- ".cm-tooltip": {
2131
- border: "none",
2132
- backgroundColor: ye
2133
- },
2134
- ".cm-tooltip .cm-tooltip-arrow:before": {
2135
- borderTopColor: "transparent",
2136
- borderBottomColor: "transparent"
2137
- },
2138
- ".cm-tooltip .cm-tooltip-arrow:after": {
2139
- borderTopColor: ye,
2140
- borderBottomColor: ye
2141
- },
2142
- ".cm-tooltip-autocomplete": {
2143
- "& > ul > li[aria-selected]": {
2144
- backgroundColor: mt,
2145
- color: ce
2146
- }
2147
- }
2148
- },
2149
- { dark: !0 }
2150
- ), ql = vt.define([
2151
- { tag: g.keyword, color: _l },
2152
- { tag: [g.name, g.deleted, g.character, g.propertyName, g.macroName], color: ct },
2153
- { tag: [g.function(g.variableName), g.labelName], color: Dl },
2154
- { tag: [g.color, g.constant(g.name), g.standard(g.name)], color: ut },
2155
- { tag: [g.definition(g.name), g.separator], color: ce },
2156
- {
2157
- tag: [
2158
- g.typeName,
2159
- g.className,
2160
- g.number,
2161
- g.changed,
2162
- g.annotation,
2163
- g.modifier,
2164
- g.self,
2165
- g.namespace
2166
- ],
2167
- color: Rl
2168
- },
2169
- {
2170
- tag: [
2171
- g.operator,
2172
- g.operatorKeyword,
2173
- g.url,
2174
- g.escape,
2175
- g.regexp,
2176
- g.link,
2177
- g.special(g.string)
2178
- ],
2179
- color: jl
2180
- },
2181
- { tag: [g.meta, g.comment], color: dt },
2182
- { tag: g.strong, fontWeight: "bold" },
2183
- { tag: g.emphasis, fontStyle: "italic" },
2184
- { tag: g.strikethrough, textDecoration: "line-through" },
2185
- { tag: g.link, color: dt, textDecoration: "underline" },
2186
- { tag: g.heading, fontWeight: "bold", color: ct },
2187
- { tag: [g.atom, g.bool, g.special(g.variableName)], color: ut },
2188
- { tag: [g.processingInstruction, g.string, g.inserted], color: Ol },
2189
- { tag: g.invalid, color: Pl }
2190
- ]), Gl = [
2191
- Ul,
2192
- pt(ql)
2193
- ], le = (e) => {
2194
- const l = new Lt();
2195
- return (t) => (l.get(e.state) ? e.dispatch({ effects: l.reconfigure(t) }) : e.dispatch({
2196
- effects: At.appendConfig.of(l.of(t))
2197
- }), !0);
2198
- };
2199
- class Wl {
2200
- constructor(l) {
2201
- K(this, "view");
2202
- // 切换tabSize的执行方法。切换时,Compartment实例需要相同
2203
- K(this, "toggleTabSize");
2204
- K(this, "togglePlaceholder");
2205
- /**
2206
- * 设置全部的扩展
2207
- */
2208
- K(this, "setExtensions");
2209
- K(this, "toggleDisabled");
2210
- K(this, "toggleReadOnly");
2211
- K(this, "toggleMaxlength");
2212
- this.view = l, this.toggleTabSize = le(this.view), this.togglePlaceholder = le(this.view), this.setExtensions = le(this.view), this.toggleDisabled = le(this.view), this.toggleReadOnly = le(this.view), this.toggleMaxlength = le(this.view);
2213
- }
2214
- getValue() {
2215
- return this.view.state.doc.toString();
2216
- }
2217
- /**
2218
- * 设置内容
2219
- *
2220
- * @param insert 待插入内容
2221
- * @param from 插入开始位置
2222
- * @param to 插入结束位置
2223
- */
2224
- setValue(l, o = 0, t = this.view.state.doc.length) {
2225
- this.view.dispatch({
2226
- changes: {
2227
- from: o,
2228
- to: t,
2229
- insert: l
2230
- }
2231
- });
2232
- }
2233
- /**
2234
- * 获取选中的文本
2235
- */
2236
- getSelectedText() {
2237
- const { from: l, to: o } = this.view.state.selection.main;
2238
- return this.view.state.sliceDoc(l, o);
2239
- }
2240
- /**
2241
- * 使用新的内容替换选中的内容
2242
- *
2243
- * @param text 待替换内容
2244
- * @param options 替换后是否选中
2245
- */
2246
- replaceSelectedText(l, o = {
2247
- // 是否选中
2248
- select: !0,
2249
- // 选中时,开始位置的偏移量
2250
- deviationStart: 0,
2251
- // 结束的偏移量
2252
- deviationEnd: 0,
2253
- // 直接替换所有文本
2254
- replaceAll: !1
2255
- }) {
2256
- if (o.replaceAll) {
2257
- this.setValue(l);
2258
- return;
2259
- }
2260
- const { from: t } = this.view.state.selection.main;
2261
- if (this.view.dispatch(this.view.state.replaceSelection(l)), o.select) {
2262
- const r = t + l.length + o.deviationEnd;
2263
- this.view.dispatch({
2264
- selection: be.create(
2265
- [
2266
- be.range(t + o.deviationStart, r),
2267
- be.cursor(r)
2268
- ],
2269
- 1
2270
- )
2271
- }), this.view.focus();
2272
- }
2273
- }
2274
- /**
2275
- * 设置tabSize
2276
- *
2277
- * @param tabSize 需要切换的大小
2278
- */
2279
- setTabSize(l) {
2280
- this.toggleTabSize([
2281
- ge.tabSize.of(l),
2282
- Dt.of(" ".repeat(l))
2283
- ]);
2284
- }
2285
- /**
2286
- * 设置placeholder
2287
- *
2288
- * @param t 目标内容
2289
- */
2290
- setPlaceholder(l) {
2291
- this.togglePlaceholder(It(l));
2292
- }
2293
- focus() {
2294
- this.view.focus();
2295
- }
2296
- setDisabled(l) {
2297
- this.toggleDisabled([Ee.editable.of(!l)]);
2298
- }
2299
- setReadOnly(l) {
2300
- this.toggleReadOnly([ge.readOnly.of(l)]);
2301
- }
2302
- setMaxLength(l) {
2303
- this.toggleMaxlength([
2304
- ge.changeFilter.of((o) => o.newDoc.length <= l)
2305
- ]);
2306
- }
2307
- }
2308
- const Kl = (e) => {
2309
- const l = x("editorId");
2310
- return (t) => {
2311
- if (t.clipboardData) {
2312
- if (t.clipboardData.files.length > 0) {
2313
- const { files: r } = t.clipboardData;
2314
- k.emit(
2315
- l,
2316
- "uploadImage",
2317
- Array.from(r).filter((n) => /image\/.*/.test(n.type))
2318
- ), t.preventDefault();
2319
- }
2320
- if (e.autoDetectCode && t.clipboardData.types.includes("vscode-editor-data")) {
2321
- const r = JSON.parse(t.clipboardData.getData("vscode-editor-data"));
2322
- k.emit(l, "replace", "code", {
2323
- mode: r.mode,
2324
- text: t.clipboardData.getData("text/plain")
2325
- }), t.preventDefault();
2326
- }
2327
- }
2328
- };
2329
- }, zl = (e) => {
2330
- const l = x("editorId");
2331
- H(() => {
2332
- k.on(l, {
2333
- name: Ct,
2334
- callback() {
2335
- var o;
2336
- (o = e.value) == null || o.focus();
2337
- }
2338
- });
2339
- });
2340
- }, Xl = (e, l) => [
2341
- {
2342
- key: "Ctrl-b",
2343
- mac: "Cmd-b",
2344
- run: () => (k.emit(e, "replace", "bold"), !0)
2345
- },
2346
- {
2347
- key: "Ctrl-d",
2348
- mac: "Cmd-d",
2349
- run: Bt,
2350
- preventDefault: !0
2351
- },
2352
- {
2353
- key: "Ctrl-s",
2354
- mac: "Cmd-s",
2355
- run: (I) => (k.emit(e, pe, I.state.doc.toString()), !0),
2356
- shift: () => (k.emit(e, "replace", "strikeThrough"), !0)
2357
- },
2358
- {
2359
- key: "Ctrl-u",
2360
- mac: "Cmd-u",
2361
- run: () => (k.emit(e, "replace", "underline"), !0),
2362
- shift: () => (k.emit(e, "replace", "unorderedList"), !0)
2363
- },
2364
- {
2365
- key: "Ctrl-i",
2366
- mac: "Cmd-i",
2367
- run: () => (k.emit(e, "replace", "italic"), !0),
2368
- shift: () => (k.emit(e, "openModals", "image"), !0)
2369
- },
2370
- {
2371
- key: "Ctrl-1",
2372
- mac: "Cmd-1",
2373
- run: () => (k.emit(e, "replace", "h1"), !0)
2374
- },
2375
- {
2376
- key: "Ctrl-2",
2377
- mac: "Cmd-2",
2378
- run: () => (k.emit(e, "replace", "h2"), !0)
2379
- },
2380
- {
2381
- key: "Ctrl-3",
2382
- mac: "Cmd-3",
2383
- run: () => (k.emit(e, "replace", "h3"), !0)
2384
- },
2385
- {
2386
- key: "Ctrl-4",
2387
- mac: "Cmd-4",
2388
- run: () => (k.emit(e, "replace", "h4"), !0)
2389
- },
2390
- {
2391
- key: "Ctrl-5",
2392
- mac: "Cmd-5",
2393
- run: () => (k.emit(e, "replace", "h5"), !0)
2394
- },
2395
- {
2396
- key: "Ctrl-6",
2397
- mac: "Cmd-6",
2398
- run: () => (k.emit(e, "replace", "h6"), !0)
2399
- },
2400
- {
2401
- key: "Ctrl-ArrowUp",
2402
- mac: "Cmd-ArrowUp",
2403
- run: () => (k.emit(e, "replace", "sup"), !0)
2404
- },
2405
- {
2406
- key: "Ctrl-ArrowDown",
2407
- mac: "Cmd-ArrowDown",
2408
- run: () => (k.emit(e, "replace", "sub"), !0)
2409
- },
2410
- {
2411
- key: "Ctrl-o",
2412
- mac: "Cmd-o",
2413
- run: () => (k.emit(e, "replace", "orderedList"), !0)
2414
- },
2415
- {
2416
- key: "Ctrl-c",
2417
- mac: "Cmd-c",
2418
- shift: () => (k.emit(e, "replace", "code"), !0),
2419
- any(I, w) {
2420
- return (w.ctrlKey || w.metaKey) && w.altKey && w.code === "KeyC" ? (k.emit(e, "replace", "codeRow"), !0) : !1;
2421
- }
2422
- },
2423
- {
2424
- key: "Ctrl-l",
2425
- mac: "Cmd-l",
2426
- run: () => (k.emit(e, "openModals", "link"), !0)
2427
- },
2428
- {
2429
- key: "Ctrl-f",
2430
- mac: "Cmd-f",
2431
- shift: () => l.noPrettier ? !1 : (k.emit(e, "replace", "prettier"), !0)
2432
- },
2433
- {
2434
- any: (I, w) => (w.ctrlKey || w.metaKey) && w.altKey && w.shiftKey && w.code === "KeyT" ? (k.emit(e, "replace", "table"), !0) : !1
2435
- }
2436
- ], Zl = (e) => {
2437
- const l = x("tabWidth"), o = x("editorId"), t = x("theme"), r = B(), n = de(), a = Xl(o, e), d = Kl(e), m = [
2438
- Ht.of([...a, Rt]),
2439
- Et,
2440
- Mt({ codeLanguages: Ft }),
2441
- // 横向换行
2442
- fe.lineWrapping,
2443
- fe.updateListener.of((c) => {
2444
- c.docChanged && e.onChange(c.state.doc.toString());
2445
- }),
2446
- fe.domEventHandlers({
2447
- paste: d,
2448
- blur: e.onBlur,
2449
- focus: e.onFocus
2450
- })
2451
- ], u = () => t.value === "light" ? A.codeMirrorExtensions(
2452
- t.value,
2453
- [...m, Gl],
2454
- [...a]
2455
- ) : A.codeMirrorExtensions(
2456
- t.value,
2457
- [...m, Bl],
2458
- [...a]
2459
- );
2460
- return H(() => {
2461
- const c = ge.create({
2462
- doc: e.value
2463
- }), f = new fe({
2464
- state: c,
2465
- parent: r.value
2466
- });
2467
- n.value = new Wl(f), n.value.setTabSize(l), n.value.setExtensions(u()), n.value.setPlaceholder(e.placeholder), n.value.setDisabled(e.disabled), n.value.setReadOnly(e.readonly), e.autofocus && f.focus(), e.maxlength && n.value.setMaxLength(e.maxlength), k.on(o, {
2468
- name: "ctrlZ",
2469
- callback() {
2470
- jt(f);
2471
- }
2472
- }), k.on(o, {
2473
- name: "ctrlShiftZ",
2474
- callback() {
2475
- Pt(f);
2476
- }
2477
- }), k.on(o, {
2478
- name: "replace",
2479
- callback(h, p = {}) {
2480
- var y;
2481
- const { text: v, options: b } = wl(h, n.value, p);
2482
- (y = n.value) == null || y.replaceSelectedText(v, b);
2483
- }
2484
- });
2485
- }), S(
2486
- () => t.value,
2487
- () => {
2488
- var c, f;
2489
- t.value === "dark" ? (c = n.value) == null || c.setExtensions(u()) : (f = n.value) == null || f.setExtensions(u());
2490
- }
2491
- ), S(
2492
- () => e.value,
2493
- () => {
2494
- var c, f;
2495
- ((c = n.value) == null ? void 0 : c.getValue()) !== e.value && ((f = n.value) == null || f.setValue(e.value));
2496
- }
2497
- ), S(
2498
- () => e.value,
2499
- () => {
2500
- var c;
2501
- (c = n.value) == null || c.setPlaceholder(e.placeholder);
2502
- }
2503
- ), S(
2504
- () => e.disabled,
2505
- () => {
2506
- var c;
2507
- (c = n.value) == null || c.setDisabled(e.disabled);
2508
- }
2509
- ), S(
2510
- () => e.readonly,
2511
- () => {
2512
- var c;
2513
- (c = n.value) == null || c.setDisabled(e.readonly);
2514
- }
2515
- ), S(
2516
- () => e.maxlength,
2517
- () => {
2518
- var c;
2519
- e.maxlength && ((c = n.value) == null || c.setMaxLength(e.maxlength));
2520
- }
2521
- ), zl(n), {
2522
- inputWrapperRef: r,
2523
- codeMirrorUt: n
2524
- };
2525
- }, Jl = (e, l) => {
2526
- const o = x("editorId"), t = ve(() => {
2527
- const r = document.querySelectorAll(`#${o}-preview img`);
2528
- r.length !== 0 && Ot(r, {
2529
- background: "#00000073"
2530
- });
2531
- });
2532
- H(t), S([l, ne(e.setting, "preview")], t);
2533
- }, Yl = (e, l) => {
2534
- const o = x("editorId"), t = x("usedLanguageText"), r = () => {
2535
- document.querySelectorAll(`#${o}-preview pre`).forEach((d) => {
2536
- var f, h;
2537
- let m = -1;
2538
- (f = d.querySelector(".copy-button")) == null || f.remove();
2539
- const u = ((h = t.value.copyCode) == null ? void 0 : h.text) || "复制代码", c = document.createElement("span");
2540
- c.setAttribute("class", "copy-button"), c.dataset.tips = u, c.innerHTML = `<svg class="${s}-icon" aria-hidden="true"><use xlink:href="#${s}-icon-copy"></use></svg>`, c.addEventListener("click", () => {
2541
- var C, $;
2542
- clearTimeout(m);
2543
- const p = d.querySelector("code").innerText, v = _t(e.formatCopiedText(p)), b = ((C = t.value.copyCode) == null ? void 0 : C.successTips) || "已复制!", y = (($ = t.value.copyCode) == null ? void 0 : $.failTips) || "已复制!";
2544
- c.dataset.tips = v ? b : y, m = window.setTimeout(() => {
2545
- c.dataset.tips = u;
2546
- }, 1500);
2547
- }), d.appendChild(c);
2548
- });
2549
- }, n = () => {
2550
- Y(r);
2551
- }, a = (d) => {
2552
- d && Y(r);
2553
- };
2554
- S(() => l.value, n), S(() => e.setting.preview, a), S(() => e.setting.htmlPreview, a), S(() => t.value, r), H(r);
2555
- }, Ql = (e) => {
2556
- var n;
2557
- const l = (n = A.editorExtensions) == null ? void 0 : n.highlight, o = l == null ? void 0 : l.instance, t = x("highlight"), r = de(o);
2558
- return H(() => {
2559
- if (!e.noHighlight && !r.value) {
2560
- const a = document.createElement("script");
2561
- a.src = t.value.js, a.onload = () => {
2562
- r.value = window.hljs;
2563
- }, a.id = `${s}-hljs`, V(a, "hljs");
2564
- const d = document.createElement("link");
2565
- d.rel = "stylesheet", d.href = t.value.css, d.id = `${s}-hlCss`, V(d);
2566
- }
2567
- }), S(
2568
- () => t.value.css,
2569
- (a) => {
2570
- sl(`${s}-hlCss`, "href", a);
2571
- }
2572
- ), r;
2573
- }, eo = (e) => {
2574
- const l = x("theme"), { editorExtensions: o } = A, t = o == null ? void 0 : o.mermaid, r = de(t == null ? void 0 : t.instance), n = de(!1), a = new Gt({
2575
- max: 1e3,
2576
- // 缓存10分钟
2577
- ttl: 6e5
2578
- }), d = () => {
2579
- const u = (t == null ? void 0 : t.instance) || window.mermaid;
2580
- !e.noMermaid && u && (u.initialize({
2581
- startOnLoad: !1,
2582
- theme: l.value === "dark" ? "dark" : "default"
2583
- }), n.value = !n.value);
2584
- };
2585
- return S(
2586
- () => l.value,
2587
- () => {
2588
- a.clear(), d();
2589
- }
2590
- ), H(() => {
2591
- if (!e.noMermaid && !(t != null && t.instance)) {
2592
- const u = document.createElement("script");
2593
- u.id = `${s}-mermaid`;
2594
- const c = (t == null ? void 0 : t.js) || Zt;
2595
- /\.mjs/.test(c) ? (u.setAttribute("type", "module"), u.innerHTML = `import mermaid from "${c}";window.mermaid=mermaid;document.getElementById('${s}-mermaid').dispatchEvent(new Event('load'));`) : u.src = c, u.onload = () => {
2596
- r.value = window.mermaid, d();
2597
- }, V(u, "mermaid");
2598
- }
2599
- }), { mermaidRef: r, reRenderRef: n, replaceMermaid: () => {
2600
- Y(() => {
2601
- !e.noMermaid && r.value && document.querySelectorAll(
2602
- `div.${s}-mermaid`
2603
- ).forEach(async (c) => {
2604
- let f = a.get(c.innerText);
2605
- if (!f) {
2606
- const p = il(), b = await (r.value.renderAsync || r.value.render)(p, c.innerText);
2607
- f = typeof b == "string" ? b : b.svg, a.set(c.innerText, f);
2608
- }
2609
- const h = document.createElement("p");
2610
- h.className = `${s}-mermaid`, h.setAttribute("data-processed", ""), h.innerHTML = f, c.dataset.line !== void 0 && (h.dataset.line = c.dataset.line), c.replaceWith(h);
2611
- });
2612
- });
2613
- } };
2614
- }, to = (e) => {
2615
- var r;
2616
- const l = (r = A.editorExtensions) == null ? void 0 : r.katex, o = l == null ? void 0 : l.instance, t = de(o);
2617
- return H(() => {
2618
- if (!e.noKatex && !t.value) {
2619
- const n = document.createElement("script");
2620
- n.src = (l == null ? void 0 : l.js) || Xe.js, n.onload = () => {
2621
- t.value = window.katex;
2622
- }, n.id = `${s}-katex`;
2623
- const a = document.createElement("link");
2624
- a.rel = "stylesheet", a.href = (l == null ? void 0 : l.css) || Xe.css, a.id = `${s}-katexCss`, V(n, "katex"), V(a);
2625
- }
2626
- }), t;
2627
- }, lo = (e, l) => {
2628
- const o = e.renderer.rules.fence.bind(e.renderer.rules);
2629
- e.renderer.rules.fence = (t, r, n, a, d) => {
2630
- const m = t[r], u = m.content.trim();
2631
- if (m.info === "mermaid") {
2632
- let c;
2633
- return t[r].map && t[r].level === 0 && (c = t[r].map[0], t[r].attrSet("data-line", String(c))), `<div class="${s}-mermaid" ${c !== void 0 ? "data-line=" + c : ""} data-mermaid-theme=${l.themeRef.value}>${u}</div>`;
2634
- }
2635
- return o(t, r, n, a, d);
2636
- };
2637
- }, ht = (e, l) => {
2638
- let o = !0, t = !0;
2639
- const r = e.posMax, n = l > 0 ? e.src.charCodeAt(l - 1) : -1, a = l + 1 <= r ? e.src.charCodeAt(l + 1) : -1;
2640
- return (n === 32 || n === 9 || a >= 48 && a <= 57) && (t = !1), (a === 32 || a === 9) && (o = !1), {
2641
- can_open: o,
2642
- can_close: t
2643
- };
2644
- }, oo = (e, l) => {
2645
- let o, t, r, n;
2646
- if (e.src[e.pos] !== "$")
2647
- return !1;
2648
- if (r = ht(e, e.pos), !r.can_open)
2649
- return l || (e.pending += "$"), e.pos += 1, !0;
2650
- const a = e.pos + 1;
2651
- for (o = a; (o = e.src.indexOf("$", o)) !== -1; ) {
2652
- for (n = o - 1; e.src[n] === "\\"; )
2653
- n -= 1;
2654
- if ((o - n) % 2 == 1)
2655
- break;
2656
- o += 1;
2657
- }
2658
- return o === -1 ? (l || (e.pending += "$"), e.pos = a, !0) : o - a === 0 ? (l || (e.pending += "$$"), e.pos = a + 1, !0) : (r = ht(e, o), r.can_close ? (l || (t = e.push("math_inline", "math", 0), t.markup = "$", t.content = e.src.slice(a, o)), e.pos = o + 1, !0) : (l || (e.pending += "$"), e.pos = a, !0));
2659
- }, no = (e, l, o, t) => {
2660
- let r, n, a, d, m = !1, u = e.bMarks[l] + e.tShift[l], c = e.eMarks[l];
2661
- if (u + 2 > c || e.src.slice(u, u + 2) !== "$$")
2662
- return !1;
2663
- if (u += 2, r = e.src.slice(u, c), t)
2664
- return !0;
2665
- for (r.trim().slice(-2) === "$$" && (r = r.trim().slice(0, -2), m = !0), a = l; !m && (a++, !(a >= o || (u = e.bMarks[a] + e.tShift[a], c = e.eMarks[a], u < c && e.tShift[a] < e.blkIndent))); )
2666
- e.src.slice(u, c).trim().slice(-2) === "$$" && (d = e.src.slice(0, c).lastIndexOf("$$"), n = e.src.slice(u, d), m = !0);
2667
- e.line = a + 1;
2668
- const f = e.push("math_block", "math", 0);
2669
- return f.block = !0, f.content = (r && r.trim() ? r + `
2670
- ` : "") + e.getLines(l + 1, a, e.tShift[l], !0) + (n && n.trim() ? n : ""), f.map = [l, e.line], f.markup = "$$", !0;
2671
- }, ro = (e, l) => {
2672
- const o = (r) => {
2673
- if (l.katexRef.value) {
2674
- const n = l.katexRef.value.renderToString(r, {
2675
- throwOnError: !1
2676
- });
2677
- return `<span class="${s}-katex-inline" data-processed>${n}</span>`;
2678
- } else
2679
- return `<span class="${s}-katex-inline">${r}</span>`;
2680
- }, t = (r, n) => {
2681
- if (l.katexRef.value) {
2682
- const a = l.katexRef.value.renderToString(r, {
2683
- throwOnError: !1,
2684
- displayMode: !0
2685
- });
2686
- return `<p class="${s}-katex-block" data-line=${n} data-processed>${a}</p>`;
2687
- } else
2688
- return `<p class="${s}-katex-block" data-line=${n}>${r}</p>`;
2689
- };
2690
- e.inline.ruler.after("escape", "math_inline", oo), e.block.ruler.after("blockquote", "math_block", no, {
2691
- alt: ["paragraph", "reference", "blockquote", "list"]
2692
- }), e.renderer.rules.math_inline = (r, n) => o(r[n].content), e.renderer.rules.math_block = (r, n) => t(r[n].content, r[n].map[0]) + `
2693
- `;
2694
- }, io = (e, l) => {
2695
- l = l || {};
2696
- const o = 3, t = l.marker || "!", r = t.charCodeAt(0), n = t.length;
2697
- let a = "", d = "";
2698
- const m = (c, f, h, p, v) => {
2699
- const b = c[f];
2700
- return b.type === "admonition_open" ? (c[f].attrPush([
2701
- "class",
2702
- `${s}-admonition ${s}-admonition-${b.info}`
2703
- ]), c[f].attrSet("data-line", String(c[f].map[0]))) : b.type === "admonition_title_open" && c[f].attrPush(["class", `${s}-admonition-title`]), v.renderToken(c, f, h);
2704
- }, u = (c) => {
2705
- const f = c.trim().split(" ", 2);
2706
- d = "", a = f[0], f.length > 1 && (d = c.substring(a.length + 2)), (d === "" || !d) && (d = a);
2707
- };
2708
- e.block.ruler.before(
2709
- "code",
2710
- "admonition",
2711
- (c, f, h, p) => {
2712
- let v, b, y, C = !1, $ = c.bMarks[f] + c.tShift[f], T = c.eMarks[f];
2713
- if (r !== c.src.charCodeAt($))
2714
- return !1;
2715
- for (v = $ + 1; v <= T && t[(v - $) % n] === c.src[v]; v++)
2716
- ;
2717
- const I = Math.floor((v - $) / n);
2718
- if (I !== o)
2719
- return !1;
2720
- v -= (v - $) % n;
2721
- const w = c.src.slice($, v), F = c.src.slice(v, T);
2722
- if (u(F), p)
2723
- return !0;
2724
- for (b = f; b++, !(b >= h || ($ = c.bMarks[b] + c.tShift[b], T = c.eMarks[b], $ < T && c.sCount[b] < c.blkIndent)); )
2725
- if (r === c.src.charCodeAt($) && !(c.sCount[b] - c.blkIndent >= 4)) {
2726
- for (v = $ + 1; v <= T && t[(v - $) % n] === c.src[v]; v++)
2727
- ;
2728
- if (!(Math.floor((v - $) / n) < I) && (v -= (v - $) % n, v = c.skipSpaces(v), !(v < T))) {
2729
- C = !0;
2730
- break;
2731
- }
2732
- }
2733
- const j = c.parentType, R = c.lineMax;
2734
- return c.parentType = "root", c.lineMax = b, y = c.push("admonition_open", "div", 1), y.markup = w, y.block = !0, y.info = a, y.map = [f, b], y = c.push("admonition_title_open", "p", 1), y.markup = w + " " + a, y.map = [f, b], y = c.push("inline", "", 0), y.content = d, y.map = [f, c.line - 1], y.children = [], y = c.push("admonition_title_close", "p", -1), y.markup = w + " " + a, c.md.block.tokenize(c, f + 1, b), y = c.push("admonition_close", "div", -1), y.markup = c.src.slice($, v), y.block = !0, c.parentType = j, c.lineMax = R, c.line = b + (C ? 1 : 0), !0;
2735
- },
2736
- {
2737
- alt: ["paragraph", "reference", "blockquote", "list"]
2738
- }
2739
- ), e.renderer.rules.admonition_open = m, e.renderer.rules.admonition_title_open = m, e.renderer.rules.admonition_title_close = m, e.renderer.rules.admonition_close = m;
2740
- }, ao = (e, l) => {
2741
- let o;
2742
- e.core.ruler.push("headingLinks", (t) => {
2743
- o || (o = t.Token);
2744
- }), e.renderer.rules.heading_open = (t, r) => {
2745
- const n = t[r], a = t[r + 1].content, d = n.markup.length;
2746
- return l.headsRef.value.push({
2747
- text: a,
2748
- level: d
2749
- }), n.map && n.level === 0 && (n.attrSet("data-line", String(n.map[0])), n.attrSet(
2750
- "id",
2751
- l.mdHeadingId(a, d, l.headsRef.value.length)
2752
- )), e.renderer.renderToken(t, r, l);
2753
- }, e.renderer.rules.heading_close = (t, r, n, a, d) => d.renderToken(t, r, n);
2754
- }, so = (e) => {
2755
- [
2756
- "paragraph_open",
2757
- "table_open",
2758
- "ordered_list_open",
2759
- "bullet_list_open",
2760
- "blockquote_open",
2761
- "hr"
2762
- ].forEach((l) => {
2763
- e.renderer.rules[l] = (o, t, r, n, a) => {
2764
- let d;
2765
- return o[t].map && o[t].level === 0 && (d = o[t].map[0], o[t].attrSet("data-line", String(d))), a.renderToken(o, t, r);
2766
- };
2767
- }), ["html_block", "fence"].forEach((l) => {
2768
- const o = e.renderer.rules[l];
2769
- e.renderer.rules[l] = (t, r, n, a, d) => {
2770
- let m;
2771
- const u = o(t, r, n, a, d);
2772
- return t[r].map && t[r].level === 0 ? (m = t[r].map[0], u.replace(/^(<[^>]*)/, `$1 data-line="${m}"`)) : u;
2773
- };
2774
- });
2775
- }, co = (e) => {
2776
- const { editorConfig: l, markdownItConfig: o } = A, t = x("editorId"), r = x("showCodeRowNumber"), n = x("previewOnly"), a = x("theme"), d = B([]), m = Ql(e), u = to(e), { reRenderRef: c, replaceMermaid: f } = eo(e), h = Nt({
2777
- html: !0,
2778
- breaks: !0
2779
- });
2780
- h.use(ro, { katexRef: u }), h.use(Vt, { figcaption: !0 }), h.use(io), h.use(Ut), h.use(ao, { mdHeadingId: e.mdHeadingId, headsRef: d }), h.use(qt), e.noMermaid || h.use(lo, { themeRef: a }), h.set({
2781
- highlight: (y, C) => {
2782
- let $;
2783
- !e.noHighlight && m.value ? m.value.getLanguage(C) ? $ = m.value.highlight(y, {
2784
- language: C,
2785
- ignoreIllegals: !0
2786
- }).value : $ = m.value.highlightAuto(y).value : $ = h.utils.escapeHtml(y);
2787
- const T = r ? ol($.trim()) : `<span class="code-block">${$.trim()}</span>`;
2788
- return `<pre><code class="language-${C}" language=${C}>${T}</code></pre>`;
2789
- }
2790
- }), so(h), o(h);
2791
- const p = B(e.sanitize(h.render(e.value)));
2792
- k.emit(t, "buildFinished", p.value), e.onHtmlChanged(p.value), e.onGetCatalog(d.value), k.emit(t, "catalogChanged", d.value), f();
2793
- const v = ve(
2794
- async () => {
2795
- d.value = [], p.value = e.sanitize(h.render(e.value)), k.emit(t, "buildFinished", p.value), e.onHtmlChanged(p.value), e.onGetCatalog(d.value), k.emit(t, "catalogChanged", d.value), f();
2796
- },
2797
- (l == null ? void 0 : l.renderDelay) !== void 0 ? l == null ? void 0 : l.renderDelay : n ? 0 : 500
2798
- ), b = U(() => (e.noKatex || u.value) && (e.noHighlight || m.value));
2799
- return S([ne(e, "value"), b, c], v), H(() => {
2800
- k.on(t, {
2801
- name: "pushCatalog",
2802
- callback() {
2803
- k.emit(t, "catalogChanged", d.value);
2804
- }
2805
- });
2806
- }), { html: p };
2807
- }, uo = {
2808
- value: {
2809
- type: String,
2810
- default: ""
2811
- },
2812
- onChange: {
2813
- type: Function,
2814
- default: () => {
2815
- }
2816
- },
2817
- setting: {
2818
- type: Object,
2819
- default: () => ({})
2820
- },
2821
- onHtmlChanged: {
2822
- type: Function,
2823
- default: () => {
2824
- }
2825
- },
2826
- onGetCatalog: {
2827
- type: Function,
2828
- default: () => {
2829
- }
2830
- },
2831
- mdHeadingId: {
2832
- type: Function,
2833
- default: () => ""
2834
- },
2835
- noMermaid: {
2836
- type: Boolean,
2837
- default: !1
2838
- },
2839
- sanitize: {
2840
- type: Function,
2841
- default: (e) => e
2842
- },
2843
- placeholder: {
2844
- type: String,
2845
- default: ""
2846
- },
2847
- // 不使用该函数功能
2848
- noKatex: {
2849
- type: Boolean,
2850
- default: !1
2851
- },
2852
- scrollAuto: {
2853
- type: Boolean
2854
- },
2855
- formatCopiedText: {
2856
- type: Function,
2857
- default: (e) => e
2858
- },
2859
- autofocus: {
2860
- type: Boolean
2861
- },
2862
- disabled: {
2863
- type: Boolean
2864
- },
2865
- readonly: {
2866
- type: Boolean
2867
- },
2868
- maxlength: {
2869
- type: Number
2870
- },
2871
- autoDetectCode: {
2872
- type: Boolean
2873
- },
2874
- /**
2875
- * 输入框失去焦点时触发事件
2876
- */
2877
- onBlur: {
2878
- type: Function,
2879
- default: () => {
2880
- }
2881
- },
2882
- /**
2883
- * 输入框获得焦点时触发事件
2884
- */
2885
- onFocus: {
2886
- type: Function,
2887
- default: () => {
2888
- }
2889
- },
2890
- noPrettier: {
2891
- type: Boolean
2892
- },
2893
- noHighlight: {
2894
- type: Boolean,
2895
- default: !1
2896
- }
2897
- }, mo = /* @__PURE__ */ M({
2898
- name: "MDEditorContent",
2899
- props: uo,
2900
- setup(e) {
2901
- const l = x("previewOnly"), o = x("showCodeRowNumber"), t = x("previewTheme"), r = x("editorId"), n = B(), a = B(), {
2902
- inputWrapperRef: d,
2903
- codeMirrorUt: m
2904
- } = Zl(e), {
2905
- html: u
2906
- } = co(e);
2907
- return $l(e, u, n, a, m), Yl(e, u), Jl(e, u), () => i("div", {
2908
- class: `${s}-content`
2909
- }, [!l && i("div", {
2910
- class: `${s}-input-wrapper`,
2911
- ref: d
2912
- }, null), e.setting.preview && i("div", {
2913
- id: `${r}-preview-wrapper`,
2914
- class: `${s}-preview-wrapper`,
2915
- ref: n,
2916
- key: "content-preview-wrapper"
2917
- }, [i("article", {
2918
- id: `${r}-preview`,
2919
- class: [`${s}-preview`, `${t == null ? void 0 : t.value}-theme`, o && `${s}-scrn`],
2920
- innerHTML: u.value
2921
- }, null)]), e.setting.htmlPreview && i("div", {
2922
- class: `${s}-preview-wrapper`,
2923
- ref: a,
2924
- key: "html-preview-wrapper"
2925
- }, [i("div", {
2926
- class: `${s}-html`
2927
- }, [u.value])])]);
2928
- }
2929
- }), fo = /* @__PURE__ */ M({
2930
- props: {
2931
- modelValue: {
2932
- type: String,
2933
- default: ""
2934
- }
2935
- },
2936
- setup(e) {
2937
- const l = x("usedLanguageText");
2938
- return () => {
2939
- var o, t;
2940
- return i("div", {
2941
- class: `${s}-footer-item`
2942
- }, [i("label", {
2943
- class: `${s}-footer-label`
2944
- }, [`${(o = l.value.footer) == null ? void 0 : o.markdownTotal}:`]), i("span", null, [((t = e.modelValue) == null ? void 0 : t.length) || 0])]);
2945
- };
2946
- }
2947
- });
2948
- const go = {
2949
- checked: {
2950
- type: Boolean,
2951
- default: !1
2952
- },
2953
- onChange: {
2954
- type: Function,
2955
- default: () => {
2956
- }
2957
- }
2958
- }, ho = /* @__PURE__ */ M({
2959
- props: go,
2960
- setup(e) {
2961
- return () => i("div", {
2962
- class: [`${s}-checkbox`, e.checked && `${s}-checkbox-checked`],
2963
- onClick: () => {
2964
- e.onChange(!e.checked);
2965
- }
2966
- }, null);
2967
- }
2968
- }), vo = {
2969
- scrollAuto: {
2970
- type: Boolean
2971
- },
2972
- onScrollAutoChange: {
2973
- type: Function,
2974
- default: () => {
2975
- }
2976
- }
2977
- }, po = /* @__PURE__ */ M({
2978
- props: vo,
2979
- setup(e) {
2980
- const l = x("usedLanguageText");
2981
- return () => {
2982
- var o;
2983
- return i("div", {
2984
- class: `${s}-footer-item`
2985
- }, [i("label", {
2986
- class: `${s}-footer-label`,
2987
- onClick: () => {
2988
- e.onScrollAutoChange(!e.scrollAuto);
2989
- }
2990
- }, [(o = l.value.footer) == null ? void 0 : o.scrollAuto]), i(ho, {
2991
- checked: e.scrollAuto,
2992
- onChange: e.onScrollAutoChange
2993
- }, null)]);
2994
- };
2995
- }
2996
- }), bo = {
2997
- modelValue: {
2998
- type: String,
2999
- default: ""
3000
- },
3001
- footers: {
3002
- type: Array,
3003
- default: []
3004
- },
3005
- scrollAuto: {
3006
- type: Boolean
3007
- },
3008
- onScrollAutoChange: {
3009
- type: Function,
3010
- default: () => {
3011
- }
3012
- },
3013
- defFooters: {
3014
- type: Object
3015
- }
3016
- }, ko = /* @__PURE__ */ M({
3017
- name: "MDEditorFooter",
3018
- props: bo,
3019
- setup(e) {
3020
- const l = U(() => {
3021
- const t = e.footers.indexOf("="), r = t === -1 ? e.footers : e.footers.slice(0, t), n = t === -1 ? [] : e.footers.slice(t, Number.MAX_SAFE_INTEGER);
3022
- return [r, n];
3023
- }), o = (t) => {
3024
- if (kt.includes(t))
3025
- switch (t) {
3026
- case "markdownTotal":
3027
- return i(fo, {
3028
- modelValue: e.modelValue
3029
- }, null);
3030
- case "scrollSwitch":
3031
- return i(po, {
3032
- scrollAuto: e.scrollAuto,
3033
- onScrollAutoChange: e.onScrollAutoChange
3034
- }, null);
3035
- }
3036
- else
3037
- return e.defFooters instanceof Array ? e.defFooters[t] || "" : e.defFooters && e.defFooters.children instanceof Array && e.defFooters.children[t] || "";
3038
- };
3039
- return () => {
3040
- const t = l.value[0].map((n) => o(n)), r = l.value[1].map((n) => o(n));
3041
- return i("div", {
3042
- class: `${s}-footer`
3043
- }, [i("div", {
3044
- class: `${s}-footer-left`
3045
- }, [t]), i("div", {
3046
- class: `${s}-footer-right`
3047
- }, [r])]);
3048
- };
3049
- }
3050
- }), yo = {
3051
- tocItem: {
3052
- type: Object,
3053
- default: () => ({})
3054
- },
3055
- mdHeadingId: {
3056
- type: Function,
3057
- default: () => {
3058
- }
3059
- },
3060
- scrollElement: {
3061
- type: [String, Object],
3062
- default: ""
3063
- },
3064
- onClick: {
3065
- type: Function,
3066
- default: () => {
3067
- }
3068
- },
3069
- scrollElementOffsetTop: {
3070
- type: Number,
3071
- default: 0
3072
- }
3073
- }, $t = /* @__PURE__ */ M({
3074
- props: yo,
3075
- setup(e) {
3076
- return () => {
3077
- const {
3078
- tocItem: l,
3079
- mdHeadingId: o,
3080
- scrollElement: t,
3081
- onClick: r,
3082
- scrollElementOffsetTop: n
3083
- } = e;
3084
- return i("div", {
3085
- class: [`${s}-catalog-link`, l.active && `${s}-catalog-active`],
3086
- onClick: (a) => {
3087
- r(a, l), a.stopPropagation();
3088
- const d = o(l.text, l.level, l.index), m = document.getElementById(d), u = t instanceof Element ? t : document.querySelector(t);
3089
- if (m && u) {
3090
- let c = m.offsetParent, f = m.offsetTop;
3091
- if (u.contains(c))
3092
- for (; c && u != c; )
3093
- f += c == null ? void 0 : c.offsetTop, c = c == null ? void 0 : c.offsetParent;
3094
- u == null || u.scrollTo({
3095
- top: f - n,
3096
- behavior: "smooth"
3097
- });
3098
- }
3099
- }
3100
- }, [i("span", {
3101
- title: l.text
3102
- }, [l.text]), i("div", {
3103
- class: `${s}-catalog-wrapper`
3104
- }, [l.children && l.children.map((a) => i($t, {
3105
- mdHeadingId: o,
3106
- key: `${l.text}-link-${a.level}-${a.text}`,
3107
- tocItem: a,
3108
- scrollElement: t,
3109
- onClick: r,
3110
- scrollElementOffsetTop: n
3111
- }, null))])]);
3112
- };
3113
- }
3114
- });
3115
- const Co = {
3116
- /**
3117
- * 编辑器的Id,务必与需要绑定的编辑器Id相同
3118
- */
3119
- editorId: {
3120
- type: String
3121
- },
3122
- class: {
3123
- type: String,
3124
- default: ""
3125
- },
3126
- mdHeadingId: {
3127
- type: Function,
3128
- default: (e) => e
3129
- },
3130
- /**
3131
- * 指定滚动的容器,选择器需带上对应的符号,默认预览框
3132
- * 元素必须定位!!!!!!
3133
- *
3134
- * 默认:#md-editor-preview-wrapper
3135
- */
3136
- scrollElement: {
3137
- type: [String, Object]
3138
- },
3139
- theme: {
3140
- type: String,
3141
- default: "light"
3142
- },
3143
- /**
3144
- * 高亮标题相对滚动容器顶部偏移量,即距离该值时,高亮当前目录菜单项
3145
- *
3146
- * 默认:20px
3147
- */
3148
- offsetTop: {
3149
- type: Number,
3150
- default: 20
3151
- },
3152
- /**
3153
- * 滚动区域的固定顶部高度
3154
- *
3155
- * 默认:0
3156
- */
3157
- scrollElementOffsetTop: {
3158
- type: Number,
3159
- default: 0
3160
- },
3161
- onClick: {
3162
- type: Function
3163
- }
3164
- }, he = /* @__PURE__ */ M({
3165
- name: "MdCatalog",
3166
- props: Co,
3167
- emits: ["onClick"],
3168
- setup(e, l) {
3169
- const o = e.editorId, t = q({
3170
- list: [],
3171
- show: !1,
3172
- scrollElement: e.scrollElement || `#${o}-preview-wrapper`
3173
- }), r = U(() => {
3174
- const a = [];
3175
- return t.list.forEach(({
3176
- text: d,
3177
- level: m,
3178
- active: u
3179
- }, c) => {
3180
- const f = {
3181
- level: m,
3182
- text: d,
3183
- index: c + 1,
3184
- active: !!u
3185
- };
3186
- if (a.length === 0)
3187
- a.push(f);
3188
- else {
3189
- let h = a[a.length - 1];
3190
- if (f.level > h.level)
3191
- for (let p = h.level + 1; p <= 6; p++) {
3192
- const {
3193
- children: v
3194
- } = h;
3195
- if (!v) {
3196
- h.children = [f];
3197
- break;
3198
- }
3199
- if (h = v[v.length - 1], f.level <= h.level) {
3200
- v.push(f);
3201
- break;
3202
- }
3203
- }
3204
- else
3205
- a.push(f);
3206
- }
3207
- }), a;
3208
- });
3209
- H(() => {
3210
- k.on(o, {
3211
- name: "catalogChanged",
3212
- callback: (a) => {
3213
- t.list = a.map((d, m) => m === 0 ? {
3214
- ...d,
3215
- active: !0
3216
- } : {
3217
- ...d
3218
- });
3219
- }
3220
- }), k.emit(o, "pushCatalog");
3221
- });
3222
- const n = () => {
3223
- var d;
3224
- const a = t.scrollElement instanceof HTMLElement ? t.scrollElement : document.querySelector(t.scrollElement);
3225
- (d = a === document.documentElement ? window : a) == null || d.addEventListener("scroll", nl(() => {
3226
- if (t.list.length === 0)
3227
- return !1;
3228
- const {
3229
- activeHead: m
3230
- } = t.list.reduce((u, c, f) => {
3231
- const h = document.getElementById(e.mdHeadingId(c.text, c.level, f + 1));
3232
- if (h instanceof HTMLElement) {
3233
- const p = rl(h, a);
3234
- if (p < e.offsetTop && p > u.minTop)
3235
- return {
3236
- activeHead: c,
3237
- minTop: p
3238
- };
3239
- }
3240
- return u;
3241
- }, {
3242
- activeHead: t.list[0],
3243
- minTop: Number.MIN_SAFE_INTEGER
3244
- });
3245
- t.list = t.list.map((u) => u === m ? {
3246
- ...u,
3247
- active: !0
3248
- } : {
3249
- ...u,
3250
- active: !1
3251
- });
3252
- }));
3253
- };
3254
- return H(() => {
3255
- n(), k.on(o, {
3256
- name: Ce,
3257
- callback(a) {
3258
- a && Y(n);
3259
- }
3260
- });
3261
- }), () => i("div", {
3262
- class: `${s}-catalog${e.theme === "dark" ? "-dark" : ""} ${e.class}`
3263
- }, [r.value.map((a) => i($t, {
3264
- mdHeadingId: e.mdHeadingId,
3265
- tocItem: a,
3266
- key: `link-${a.level}-${a.text}`,
3267
- scrollElement: t.scrollElement,
3268
- onClick: (d, m) => {
3269
- e.onClick ? e.onClick(d, m) : l.emit("onClick", d, m);
3270
- },
3271
- scrollElementOffsetTop: e.scrollElementOffsetTop
3272
- }, null))]);
3273
- }
3274
- }), $o = (e, l) => {
3275
- const { editorId: o, previewOnly: t } = e, r = q({
3276
- // 是否已编译成html
3277
- buildFinished: !1,
3278
- // 存储当前最新的html
3279
- html: ""
3280
- });
3281
- S(
3282
- () => e.modelValue,
3283
- () => {
3284
- r.buildFinished = !1;
3285
- }
3286
- ), H(() => {
3287
- t || (k.on(o, {
3288
- name: "buildFinished",
3289
- callback(n) {
3290
- r.buildFinished = !0, r.html = n;
3291
- }
3292
- }), k.on(o, {
3293
- name: pe,
3294
- callback() {
3295
- const n = new Promise((a) => {
3296
- if (r.buildFinished)
3297
- a(r.html);
3298
- else {
3299
- const d = (m) => {
3300
- a(m), k.remove(o, "buildFinished", d);
3301
- };
3302
- k.on(o, {
3303
- name: "buildFinished",
3304
- callback: d
3305
- });
3306
- }
3307
- });
3308
- e.onSave ? e.onSave(e.modelValue, n) : l.emit("onSave", e.modelValue, n);
3309
- }
3310
- }));
3311
- });
3312
- }, wo = (e) => {
3313
- var n;
3314
- const { editorId: l, previewOnly: o } = e, t = (n = A == null ? void 0 : A.editorExtensions) == null ? void 0 : n.highlight;
3315
- Z("editorId", l), Z("tabWidth", e.tabWidth), Z(
3316
- "theme",
3317
- U(() => e.theme)
3318
- ), Z(
3319
- "highlight",
3320
- U(() => {
3321
- const a = {
3322
- ...Ze,
3323
- ...t == null ? void 0 : t.css
3324
- }, d = e.codeStyleReverse && e.codeStyleReverseList.includes(e.previewTheme) ? "dark" : e.theme;
3325
- return {
3326
- js: (t == null ? void 0 : t.js) || zt,
3327
- css: a[e.codeTheme] ? a[e.codeTheme][d] : Ze.atom[d]
3328
- };
3329
- })
3330
- ), Z("previewOnly", o), Z("showCodeRowNumber", e.showCodeRowNumber);
3331
- const r = U(() => {
3332
- var d;
3333
- const a = {
3334
- ...ze,
3335
- ...(d = A == null ? void 0 : A.editorConfig) == null ? void 0 : d.languageUserDefined
3336
- };
3337
- return a[e.language] ? a[e.language] : ze["zh-CN"];
3338
- });
3339
- Z("usedLanguageText", r), Z(
3340
- "previewTheme",
3341
- U(() => e.previewTheme)
3342
- );
3343
- }, To = (e) => {
3344
- var u, c, f, h, p, v;
3345
- const { noPrettier: l, previewOnly: o, noIconfont: t, noUploadImg: r } = e, { editorExtensions: n } = A, a = l || !!((c = (u = A.editorExtensions) == null ? void 0 : u.prettier) != null && c.prettierInstance), d = l || !!((h = (f = A.editorExtensions) == null ? void 0 : f.prettier) != null && h.parserMarkdownInstance), m = r || !!((v = (p = A.editorExtensions) == null ? void 0 : p.cropper) != null && v.instance);
3346
- H(() => {
3347
- var I, w, F, j;
3348
- const b = document.createElement("script");
3349
- b.src = (n == null ? void 0 : n.iconfont) || Kt, b.id = `${s}-icon`;
3350
- const y = document.createElement("script"), C = document.createElement("script");
3351
- y.src = ((I = n == null ? void 0 : n.prettier) == null ? void 0 : I.standaloneJs) || We.main, y.id = `${s}-prettier`, C.src = ((w = n == null ? void 0 : n.prettier) == null ? void 0 : w.parserMarkdownJs) || We.markdown, C.id = `${s}-prettierMD`;
3352
- const $ = document.createElement("link");
3353
- $.rel = "stylesheet", $.href = ((F = n == null ? void 0 : n.cropper) == null ? void 0 : F.css) || Ke.css, $.id = `${s}-cropperCss`;
3354
- const T = document.createElement("script");
3355
- T.src = ((j = n == null ? void 0 : n.cropper) == null ? void 0 : j.js) || Ke.js, T.id = `${s}-cropper`, t || V(b), o || (m || (V($), V(T)), a || V(y), d || V(C));
3356
- });
3357
- }, So = (e, l) => {
3358
- const { editorId: o, previewOnly: t } = e, r = q({
3359
- pageFullscreen: e.pageFullscreen,
3360
- fullscreen: !1,
3361
- preview: e.preview,
3362
- htmlPreview: e.preview ? !1 : e.htmlPreview
3363
- }), n = (m, u) => {
3364
- r[m] = u === void 0 ? !r[m] : u, m === "preview" && r.preview ? r.htmlPreview = !1 : m === "htmlPreview" && r.htmlPreview && (r.preview = !1);
3365
- };
3366
- let a = "";
3367
- const d = () => {
3368
- r.pageFullscreen || r.fullscreen ? document.body.style.overflow = "hidden" : document.body.style.overflow = a;
3369
- };
3370
- return S(() => [r.pageFullscreen, r.fullscreen], d), H(() => {
3371
- t || k.on(o, {
3372
- name: "uploadImage",
3373
- callback(m, u) {
3374
- const c = (f) => {
3375
- k.emit(o, "replace", "image", {
3376
- desc: "",
3377
- urls: f
3378
- }), u && u();
3379
- };
3380
- e.onUploadImg ? e.onUploadImg(m, c) : l.emit("onUploadImg", m, c);
3381
- }
3382
- }), a = document.body.style.overflow, d();
3383
- }), [r, n];
3384
- }, xo = (e) => {
3385
- const { editorId: l } = e, o = B(!1);
3386
- H(() => {
3387
- k.on(l, {
3388
- name: Le,
3389
- callback: (r) => {
3390
- r === void 0 ? o.value = !o.value : o.value = r;
3391
- }
3392
- });
3393
- });
3394
- const t = U(() => !e.toolbarsExclude.includes("catalog") && e.toolbars.includes("catalog"));
3395
- return [o, t];
3396
- }, Eo = (e, l, o, t, r) => {
3397
- const { editorId: n } = e;
3398
- S(
3399
- () => t.pageFullscreen,
3400
- (d) => {
3401
- k.emit(n, Je, d);
3402
- }
3403
- ), S(
3404
- () => t.fullscreen,
3405
- (d) => {
3406
- k.emit(n, Ye, d);
3407
- }
3408
- ), S(
3409
- () => t.preview,
3410
- (d) => {
3411
- k.emit(n, Ce, d);
3412
- }
3413
- ), S(
3414
- () => t.htmlPreview,
3415
- (d) => {
3416
- k.emit(n, Qe, d);
3417
- }
3418
- ), S(o, (d) => {
3419
- k.emit(n, et, d);
3420
- });
3421
- const a = {
3422
- on(d, m) {
3423
- switch (d) {
3424
- case "pageFullscreen": {
3425
- k.on(n, {
3426
- name: Je,
3427
- callback(u) {
3428
- m(u);
3429
- }
3430
- });
3431
- break;
3432
- }
3433
- case "fullscreen": {
3434
- k.on(n, {
3435
- name: Ye,
3436
- callback(u) {
3437
- m(u);
3438
- }
3439
- });
3440
- break;
3441
- }
3442
- case "preview": {
3443
- k.on(n, {
3444
- name: Ce,
3445
- callback(u) {
3446
- m(u);
3447
- }
3448
- });
3449
- break;
3450
- }
3451
- case "htmlPreview": {
3452
- k.on(n, {
3453
- name: Qe,
3454
- callback(u) {
3455
- m(u);
3456
- }
3457
- });
3458
- break;
3459
- }
3460
- case "catalog": {
3461
- k.on(n, {
3462
- name: et,
3463
- callback(u) {
3464
- m(u);
3465
- }
3466
- });
3467
- break;
3468
- }
3469
- }
3470
- },
3471
- togglePageFullscreen(d) {
3472
- r("pageFullscreen", d);
3473
- },
3474
- toggleFullscreen(d) {
3475
- k.emit(n, yt, d);
3476
- },
3477
- togglePreview(d) {
3478
- r("preview", d);
3479
- },
3480
- toggleHtmlPreview(d) {
3481
- r("htmlPreview", d);
3482
- },
3483
- toggleCatalog(d) {
3484
- k.emit(n, Le, d);
3485
- },
3486
- triggerSave() {
3487
- k.emit(n, pe);
3488
- },
3489
- insert(d) {
3490
- k.emit(n, "replace", "universal", { generate: d });
3491
- },
3492
- focus() {
3493
- k.emit(n, Ct);
3494
- }
3495
- };
3496
- l.expose(a);
3497
- }, Lo = (e) => e, Ao = {
3498
- /**
3499
- * 主题
3500
- *
3501
- * @default 'light'
3502
- */
3503
- modelValue: {
3504
- type: String,
3505
- default: ""
3506
- },
3507
- /**
3508
- * 主题,支持light和dark
3509
- *
3510
- * @default 'light'
3511
- */
3512
- theme: {
3513
- type: String,
3514
- default: "light"
3515
- },
3516
- /**
3517
- * 外层类名
3518
- *
3519
- * @default ''
3520
- */
3521
- class: {
3522
- type: String,
3523
- default: ""
3524
- },
3525
- /**
3526
- * input回调事件
3527
- */
3528
- onChange: {
3529
- type: Function
3530
- },
3531
- /**
3532
- * input回调事件
3533
- */
3534
- onSave: {
3535
- type: Function
3536
- },
3537
- /**
3538
- * 上传图片事件
3539
- */
3540
- onUploadImg: {
3541
- type: Function
3542
- },
3543
- /**
3544
- * 是否页面内全屏
3545
- *
3546
- * @default false
3547
- */
3548
- pageFullscreen: {
3549
- type: Boolean,
3550
- default: !1
3551
- },
3552
- /**
3553
- * 是否展开预览
3554
- *
3555
- * @default true
3556
- */
3557
- preview: {
3558
- type: Boolean,
3559
- default: !0
3560
- },
3561
- /**
3562
- * 是否展开html预览
3563
- *
3564
- * @default false
3565
- */
3566
- htmlPreview: {
3567
- type: Boolean,
3568
- default: !1
3569
- },
3570
- /**
3571
- * 仅预览模式,不显示toolbar和编辑框
3572
- *
3573
- * @default false
3574
- */
3575
- previewOnly: {
3576
- type: Boolean,
3577
- default: !1
3578
- },
3579
- /**
3580
- * 预设语言名称
3581
- *
3582
- * @default 'zh-CN'
3583
- */
3584
- language: {
3585
- type: String,
3586
- default: "zh-CN"
3587
- },
3588
- /**
3589
- * 工具栏选择显示
3590
- *
3591
- * @default allToolbar
3592
- */
3593
- toolbars: {
3594
- type: Array,
3595
- default: bt
3596
- },
3597
- /**
3598
- * 工具栏选择不显示
3599
- *
3600
- * @default []
3601
- */
3602
- toolbarsExclude: {
3603
- type: Array,
3604
- default: []
3605
- },
3606
- /**
3607
- * 格式化md
3608
- *
3609
- * @default true
3610
- */
3611
- noPrettier: {
3612
- type: Boolean,
3613
- default: !1
3614
- },
3615
- /**
3616
- * html变化事件
3617
- */
3618
- onHtmlChanged: {
3619
- type: Function
3620
- },
3621
- /**
3622
- * 获取目录结构
3623
- */
3624
- onGetCatalog: {
3625
- type: Function
3626
- },
3627
- /**
3628
- * 编辑器唯一标识
3629
- *
3630
- * @default 'md-editor-v3'
3631
- */
3632
- editorId: {
3633
- type: String,
3634
- default: Wt
3635
- },
3636
- /**
3637
- * 一个tab等于空格数
3638
- *
3639
- * @default 2
3640
- */
3641
- tabWidth: {
3642
- type: Number,
3643
- default: 2
3644
- },
3645
- /**
3646
- * 预览中代码是否显示行号
3647
- *
3648
- * @default false
3649
- */
3650
- showCodeRowNumber: {
3651
- type: Boolean,
3652
- default: !1
3653
- },
3654
- /**
3655
- * 预览内容样式
3656
- *
3657
- * @default 'default'
3658
- */
3659
- previewTheme: {
3660
- type: String,
3661
- default: "default"
3662
- },
3663
- /**
3664
- * 编辑器样式
3665
- */
3666
- style: {
3667
- type: Object,
3668
- default: () => ({})
3669
- },
3670
- /**
3671
- * 标题的id生成方式
3672
- *
3673
- * @default (text: string) => text
3674
- */
3675
- mdHeadingId: {
3676
- type: Function,
3677
- default: Lo
3678
- },
3679
- /**
3680
- * 表格预设格子数
3681
- *
3682
- * @default [6, 4]
3683
- */
3684
- tableShape: {
3685
- type: Array,
3686
- default: () => [6, 4]
3687
- },
3688
- /**
3689
- * 不使用该mermaid
3690
- *
3691
- * @default false
3692
- */
3693
- noMermaid: {
3694
- type: Boolean,
3695
- default: !1
3696
- },
3697
- /**
3698
- *
3699
- * 不能保证文本正确的情况,在marked编译md文本后通过该方法处理
3700
- * 推荐DOMPurify、sanitize-html
3701
- *
3702
- * @default (text: string) => text
3703
- */
3704
- sanitize: {
3705
- type: Function,
3706
- default: (e) => e
3707
- },
3708
- /**
3709
- * 空提示
3710
- *
3711
- * @default ''
3712
- */
3713
- placeholder: {
3714
- type: String,
3715
- default: ""
3716
- },
3717
- /**
3718
- * 不使用katex
3719
- *
3720
- * @default false
3721
- */
3722
- noKatex: {
3723
- type: Boolean,
3724
- default: !1
3725
- },
3726
- /**
3727
- * 自定义的工具栏列表
3728
- */
3729
- defToolbars: {
3730
- type: [String, Object]
3731
- },
3732
- /**
3733
- * 内部错误捕获
3734
- */
3735
- onError: {
3736
- type: Function
3737
- },
3738
- /**
3739
- * 代码主题
3740
- *
3741
- * @default 'atom'
3742
- */
3743
- codeTheme: {
3744
- type: String,
3745
- default: "atom"
3746
- },
3747
- /**
3748
- * 页脚列表显示顺序
3749
- */
3750
- footers: {
3751
- type: Array,
3752
- default: kt
3753
- },
3754
- /**
3755
- * 是否默认激活输入框和预览框同步滚动
3756
- *
3757
- * @default true
3758
- */
3759
- scrollAuto: {
3760
- type: Boolean,
3761
- default: !0
3762
- },
3763
- /**
3764
- * 自定义的也叫工具组件列表
3765
- */
3766
- defFooters: {
3767
- type: [String, Object]
3768
- },
3769
- /**
3770
- * 不插入iconfont链接
3771
- *
3772
- * @default false
3773
- */
3774
- noIconfont: {
3775
- type: Boolean
3776
- },
3777
- /**
3778
- * 复制代码格式化方法
3779
- *
3780
- * @default (text) => text
3781
- */
3782
- formatCopiedText: {
3783
- type: Function,
3784
- default: (e) => e
3785
- },
3786
- /**
3787
- * 是否禁用上传图片
3788
- *
3789
- * @default false
3790
- */
3791
- noUploadImg: {
3792
- type: Boolean
3793
- },
3794
- /**
3795
- * 某些预览主题的代码模块背景是暗色系
3796
- * 将这个属性设置为true,会自动在该主题下的light模式下使用暗色系的代码风格
3797
- *
3798
- * @default true
3799
- */
3800
- codeStyleReverse: {
3801
- type: Boolean,
3802
- default: !0
3803
- },
3804
- /**
3805
- * 需要自动调整的预览主题
3806
- *
3807
- * @default ['default', 'mk-cute']
3808
- */
3809
- codeStyleReverseList: {
3810
- type: Array,
3811
- default: ["default", "mk-cute"]
3812
- },
3813
- /**
3814
- * 文本区域自动获得焦点
3815
- *
3816
- * @default false
3817
- */
3818
- autoFocus: {
3819
- type: Boolean
3820
- },
3821
- /**
3822
- * 禁用文本区域
3823
- *
3824
- * @default false
3825
- */
3826
- disabled: {
3827
- type: Boolean
3828
- },
3829
- /**
3830
- * 文本区域为只读
3831
- *
3832
- * @default false
3833
- */
3834
- readOnly: {
3835
- type: Boolean
3836
- },
3837
- /**
3838
- * 文本区域允许的最大字符数
3839
- */
3840
- maxLength: {
3841
- type: Number
3842
- },
3843
- /**
3844
- * 是否启用自动识别粘贴代码类别
3845
- * 目前支持 vscode 复制的代码识别
3846
- *
3847
- * @default false
3848
- */
3849
- autoDetectCode: {
3850
- type: Boolean
3851
- },
3852
- /**
3853
- * 输入框失去焦点时触发事件
3854
- */
3855
- onBlur: {
3856
- type: Function
3857
- },
3858
- /**
3859
- * 输入框获得焦点时触发事件
3860
- */
3861
- onFocus: {
3862
- type: Function
3863
- },
3864
- noHighlight: {
3865
- type: Boolean,
3866
- default: !1
3867
- }
3868
- }, Io = [
3869
- "onChange",
3870
- "onSave",
3871
- "onUploadImg",
3872
- "onHtmlChanged",
3873
- "onGetCatalog",
3874
- "onError",
3875
- "update:modelValue",
3876
- "onBlur",
3877
- "onFocus"
3878
- ];
3879
- const J = /* @__PURE__ */ M({
3880
- name: "MdEditorV3",
3881
- props: Ao,
3882
- emits: Io,
3883
- setup(e, l) {
3884
- const {
3885
- editorId: o,
3886
- previewOnly: t,
3887
- noKatex: r,
3888
- noMermaid: n,
3889
- noPrettier: a,
3890
- noUploadImg: d,
3891
- noHighlight: m
3892
- } = e, u = q({
3893
- scrollAuto: e.scrollAuto
3894
- });
3895
- $o(e, l), wo(e), To(e);
3896
- const [c, f] = So(e, l), [h, p] = xo(e);
3897
- return Se(() => {
3898
- k.clear(o);
3899
- }), Eo(e, l, h, c, f), () => {
3900
- var y;
3901
- const v = G({
3902
- props: e,
3903
- ctx: l
3904
- }, "defToolbars"), b = G({
3905
- props: e,
3906
- ctx: l
3907
- }, "defFooters");
3908
- return i("div", {
3909
- id: o,
3910
- class: [s, e.class, e.theme === "dark" && `${s}-dark`, c.fullscreen || c.pageFullscreen ? `${s}-fullscreen` : "", t && `${s}-previewOnly`],
3911
- style: e.style
3912
- }, [!t && i(kl, {
3913
- noPrettier: a,
3914
- toolbars: e.toolbars,
3915
- toolbarsExclude: e.toolbarsExclude,
3916
- setting: c,
3917
- updateSetting: f,
3918
- tableShape: e.tableShape,
3919
- defToolbars: v,
3920
- noUploadImg: d
3921
- }, null), i(mo, {
3922
- value: e.modelValue,
3923
- setting: c,
3924
- mdHeadingId: e.mdHeadingId,
3925
- noMermaid: n,
3926
- noPrettier: a,
3927
- sanitize: e.sanitize,
3928
- placeholder: e.placeholder,
3929
- noKatex: r,
3930
- scrollAuto: u.scrollAuto,
3931
- formatCopiedText: e.formatCopiedText,
3932
- autofocus: e.autoFocus,
3933
- disabled: e.disabled,
3934
- readonly: e.readOnly,
3935
- maxlength: e.maxLength,
3936
- autoDetectCode: e.autoDetectCode,
3937
- noHighlight: m,
3938
- onChange: (C) => {
3939
- e.onChange ? e.onChange(C) : (l.emit("update:modelValue", C), l.emit("onChange", C));
3940
- },
3941
- onHtmlChanged: (C) => {
3942
- e.onHtmlChanged ? e.onHtmlChanged(C) : l.emit("onHtmlChanged", C);
3943
- },
3944
- onGetCatalog: (C) => {
3945
- e.onGetCatalog ? e.onGetCatalog(C) : l.emit("onGetCatalog", C);
3946
- },
3947
- onBlur: (C) => {
3948
- e.onBlur ? e.onBlur(C) : l.emit("onBlur", C);
3949
- },
3950
- onFocus: (C) => {
3951
- e.onFocus ? e.onFocus(C) : l.emit("onFocus", C);
3952
- }
3953
- }, null), !t && ((y = e.footers) == null ? void 0 : y.length) > 0 && i(ko, {
3954
- modelValue: e.modelValue,
3955
- footers: e.footers,
3956
- defFooters: b,
3957
- scrollAuto: u.scrollAuto,
3958
- onScrollAutoChange: (C) => u.scrollAuto = C
3959
- }, null), p.value && !t && i(he, {
3960
- theme: e.theme,
3961
- style: {
3962
- display: h.value ? "block" : "none"
3963
- },
3964
- class: `${s}-catalog-editor`,
3965
- editorId: o,
3966
- mdHeadingId: e.mdHeadingId
3967
- }, null)]);
3968
- };
3969
- }
3970
- }), Ho = {
3971
- title: {
3972
- type: String,
3973
- default: ""
3974
- },
3975
- // 展示在工具栏的内容,通常是个图标
3976
- trigger: {
3977
- type: [String, Object]
3978
- },
3979
- onClick: {
3980
- type: Function
3981
- }
3982
- }, $e = /* @__PURE__ */ M({
3983
- name: "NormalToolbar",
3984
- props: Ho,
3985
- emits: ["onClick"],
3986
- setup(e, l) {
3987
- return () => {
3988
- const o = G({
3989
- props: e,
3990
- ctx: l
3991
- }, "trigger");
3992
- return i("div", {
3993
- class: `${s}-toolbar-item`,
3994
- title: e.title,
3995
- onClick: (t) => {
3996
- e.onClick instanceof Function ? e.onClick(t) : l.emit("onClick", t);
3997
- }
3998
- }, [o]);
3999
- };
4000
- }
4001
- }), Fo = {
4002
- title: {
4003
- type: String,
4004
- default: ""
4005
- },
4006
- visible: {
4007
- type: Boolean
4008
- },
4009
- // 展示在工具栏的内容,通常是个图标
4010
- trigger: {
4011
- type: [String, Object]
4012
- },
4013
- onChange: {
4014
- type: Function
4015
- },
4016
- // 下拉框中的内容
4017
- overlay: {
4018
- type: [String, Object]
4019
- }
4020
- }, we = /* @__PURE__ */ M({
4021
- name: "DropdownToolbar",
4022
- props: Fo,
4023
- emits: ["onChange"],
4024
- setup(e, l) {
4025
- const o = x("editorId");
4026
- return () => {
4027
- const t = G({
4028
- props: e,
4029
- ctx: l
4030
- }, "trigger"), r = G({
4031
- props: e,
4032
- ctx: l
4033
- }, "overlay");
4034
- return i(oe, {
4035
- relative: `#${o}-toolbar-wrapper`,
4036
- visible: e.visible,
4037
- onChange: (n) => {
4038
- e.onChange instanceof Function ? e.onChange(n) : l.emit("onChange", n);
4039
- },
4040
- overlay: r
4041
- }, {
4042
- default: () => [i("div", {
4043
- class: `${s}-toolbar-item`,
4044
- title: e.title || ""
4045
- }, [t])]
4046
- });
4047
- };
4048
- }
4049
- });
4050
- function Mo(e) {
4051
- return typeof e == "function" || Object.prototype.toString.call(e) === "[object Object]" && !xt(e);
4052
- }
4053
- const Bo = {
4054
- title: {
4055
- type: String,
4056
- default: ""
4057
- },
4058
- modalTitle: {
4059
- type: String,
4060
- default: ""
4061
- },
4062
- visible: {
4063
- type: Boolean
4064
- },
4065
- width: {
4066
- type: String,
4067
- default: "auto"
4068
- },
4069
- height: {
4070
- type: String,
4071
- default: "auto"
4072
- },
4073
- // 展示在工具栏的内容,通常是个图标
4074
- trigger: {
4075
- type: [String, Object]
4076
- },
4077
- onClick: {
4078
- type: Function
4079
- },
4080
- onClose: {
4081
- type: Function
4082
- },
4083
- /**
4084
- * 显示全屏按钮
4085
- */
4086
- showAdjust: {
4087
- type: Boolean,
4088
- default: !1
4089
- },
4090
- isFullscreen: {
4091
- type: Boolean,
4092
- default: !1
4093
- },
4094
- onAdjust: {
4095
- type: Function
4096
- }
4097
- }, Te = /* @__PURE__ */ M({
4098
- name: "ModalToolbar",
4099
- props: Bo,
4100
- emits: ["onClick", "onClose", "onAdjust"],
4101
- setup(e, l) {
4102
- return () => {
4103
- const o = G({
4104
- props: e,
4105
- ctx: l
4106
- }, "trigger"), t = G({
4107
- props: e,
4108
- ctx: l
4109
- }, "default");
4110
- return i(xe, null, [i("div", {
4111
- class: `${s}-toolbar-item`,
4112
- title: e.title,
4113
- onClick: () => {
4114
- e.onClick instanceof Function ? e.onClick() : l.emit("onClick");
4115
- }
4116
- }, [o]), i(Ae, {
4117
- width: e.width,
4118
- height: e.height,
4119
- title: e.modalTitle,
4120
- visible: e.visible,
4121
- onClose: () => {
4122
- e.onClose instanceof Function ? e.onClose() : l.emit("onClose");
4123
- },
4124
- showAdjust: e.showAdjust,
4125
- isFullscreen: e.isFullscreen,
4126
- onAdjust: (r) => {
4127
- e.onAdjust instanceof Function ? e.onAdjust(r) : l.emit("onAdjust", r);
4128
- }
4129
- }, Mo(t) ? t : {
4130
- default: () => [t]
4131
- })]);
4132
- };
4133
- }
4134
- });
4135
- J.install = (e) => (e.component(J.name, J), e.component($e.name, $e), e.component(we.name, we), e.component(he.name, he), e.component(Te.name, Te), e);
4136
- J.NormalToolbar = $e;
4137
- J.DropdownToolbar = we;
4138
- J.MdCatalog = he;
4139
- J.ModalToolbar = Te;
4140
- J.config = Jt;
4141
- export {
4142
- J as default
4143
- };