@antdv-next/x-markdown 0.0.1 → 0.1.0-beta.1

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 (70) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -1
  3. package/dist/XMarkdown/components/AnimationText.js +5 -0
  4. package/dist/XMarkdown/components/AnimationText.vue.d.ts +0 -1
  5. package/dist/XMarkdown/components/AnimationText.vue_vue_type_script_setup_true_lang.js +42 -0
  6. package/dist/XMarkdown/components/DebugPanel.js +7 -0
  7. package/dist/XMarkdown/components/DebugPanel.vue.d.ts +0 -1
  8. package/dist/XMarkdown/components/DebugPanel.vue_vue_type_script_setup_true_lang.js +128 -0
  9. package/dist/XMarkdown/components/DebugPanel.vue_vue_type_style_index_0_scoped_d6923a13_lang.css +39 -0
  10. package/dist/XMarkdown/components/TailIndicator.js +7 -0
  11. package/dist/XMarkdown/components/TailIndicator.vue.d.ts +0 -1
  12. package/dist/XMarkdown/components/TailIndicator.vue_vue_type_script_setup_true_lang.js +14 -0
  13. package/dist/XMarkdown/components/TailIndicator.vue_vue_type_style_index_0_scoped_802ace82_lang.css +6 -0
  14. package/dist/XMarkdown/components/index.d.ts +0 -1
  15. package/dist/XMarkdown/components/index.js +4 -0
  16. package/dist/XMarkdown/composables/index.d.ts +4 -0
  17. package/dist/XMarkdown/composables/index.js +5 -0
  18. package/dist/XMarkdown/composables/useParser.d.ts +0 -1
  19. package/dist/XMarkdown/composables/useParser.js +24 -0
  20. package/dist/XMarkdown/composables/useRenderer.d.ts +0 -1
  21. package/dist/XMarkdown/composables/useRenderer.js +24 -0
  22. package/dist/XMarkdown/composables/useStreaming.d.ts +0 -1
  23. package/dist/XMarkdown/composables/useStreaming.js +215 -0
  24. package/dist/XMarkdown/composables/useTail.d.ts +0 -1
  25. package/dist/XMarkdown/composables/useTail.js +25 -0
  26. package/dist/XMarkdown/core/Parser.d.ts +5 -2
  27. package/dist/XMarkdown/core/Parser.js +162 -0
  28. package/dist/XMarkdown/core/VueRenderer.d.ts +0 -1
  29. package/dist/XMarkdown/core/VueRenderer.js +223 -0
  30. package/dist/XMarkdown/core/detectUnclosedComponentTags.d.ts +2 -2
  31. package/dist/XMarkdown/core/detectUnclosedComponentTags.js +141 -0
  32. package/dist/XMarkdown/core/index.d.ts +3 -0
  33. package/dist/XMarkdown/core/index.js +4 -0
  34. package/dist/XMarkdown/index.d.ts +14 -0
  35. package/dist/XMarkdown/index.js +13 -0
  36. package/dist/XMarkdown/index.vue.d.ts +0 -1
  37. package/dist/XMarkdown/index.vue_vue_type_script_setup_true_lang.js +135 -0
  38. package/dist/XMarkdown/index2.js +5 -0
  39. package/dist/XMarkdown/interface.d.ts +0 -1
  40. package/dist/XMarkdown/interface.js +14 -0
  41. package/dist/XMarkdown/utils/tail.d.ts +0 -1
  42. package/dist/XMarkdown/utils/tail.js +9 -0
  43. package/dist/_virtual/_plugin-vue_export-helper.js +8 -0
  44. package/dist/env.d.js +0 -0
  45. package/dist/index.d.ts +0 -1
  46. package/dist/index.js +13 -740
  47. package/package.json +9 -7
  48. package/{dist/plugins → plugins}/Latex/index.d.ts +0 -1
  49. package/plugins/Latex/index.js +74 -0
  50. package/themes/index.css +206 -0
  51. package/dist/XMarkdown/components/AnimationText.vue.d.ts.map +0 -1
  52. package/dist/XMarkdown/components/DebugPanel.vue.d.ts.map +0 -1
  53. package/dist/XMarkdown/components/TailIndicator.vue.d.ts.map +0 -1
  54. package/dist/XMarkdown/components/index.d.ts.map +0 -1
  55. package/dist/XMarkdown/composables/useParser.d.ts.map +0 -1
  56. package/dist/XMarkdown/composables/useRenderer.d.ts.map +0 -1
  57. package/dist/XMarkdown/composables/useStreaming.d.ts.map +0 -1
  58. package/dist/XMarkdown/composables/useTail.d.ts.map +0 -1
  59. package/dist/XMarkdown/core/Parser.d.ts.map +0 -1
  60. package/dist/XMarkdown/core/VueRenderer.d.ts.map +0 -1
  61. package/dist/XMarkdown/core/detectUnclosedComponentTags.d.ts.map +0 -1
  62. package/dist/XMarkdown/index.vue.d.ts.map +0 -1
  63. package/dist/XMarkdown/interface.d.ts.map +0 -1
  64. package/dist/XMarkdown/utils/tail.d.ts.map +0 -1
  65. package/dist/index.css +0 -1
  66. package/dist/index.d.ts.map +0 -1
  67. package/dist/plugins/Latex/index.d.ts.map +0 -1
  68. package/dist/plugins/Latex/index.js +0 -68
  69. /package/{dist/themes → themes}/dark.css +0 -0
  70. /package/{dist/themes → themes}/light.css +0 -0
package/dist/index.js CHANGED
@@ -1,740 +1,13 @@
1
- import { Fragment as e, computed as t, createBlock as n, createCommentVNode as r, createElementBlock as i, createElementVNode as a, createTextVNode as o, createVNode as s, defineComponent as c, h as l, normalizeClass as u, normalizeStyle as d, onMounted as f, onUnmounted as p, openBlock as m, ref as h, renderList as g, shallowRef as _, toDisplayString as v, unref as y, watch as b } from "vue";
2
- import x from "dompurify";
3
- import { Marked as S } from "marked";
4
- //#region src/XMarkdown/components/DebugPanel.vue?vue&type=script&setup=true&lang.ts
5
- var C = { class: "xmd-debug-content" }, w = { class: "xmd-debug-stat" }, T = { class: "xmd-debug-stat" }, E = {
6
- class: "xmd-debug-chart",
7
- viewBox: "0 0 200 60"
8
- }, D = ["d"], O = 60, k = /* @__PURE__ */ c({
9
- __name: "DebugPanel",
10
- props: { className: {} },
11
- setup(e) {
12
- let t = h(!1), n = h({
13
- x: 20,
14
- y: 20
15
- }), r = h({
16
- x: 0,
17
- y: 0
18
- }), o = h(0), s = h(0), c = h([]), l = null, g = 0, _ = 0;
19
- function y() {
20
- g = performance.now(), _ = 0;
21
- function e() {
22
- _++;
23
- let t = performance.now(), n = t - g;
24
- if (n >= 1e3) {
25
- if (o.value = Math.round(_ * 1e3 / n), _ = 0, g = t, "memory" in performance) {
26
- let e = performance.memory;
27
- s.value = e ? Math.round(e.usedJSHeapSize / 1024 / 1024) : 0;
28
- }
29
- c.value.push({
30
- fps: o.value,
31
- memory: s.value,
32
- timestamp: Date.now()
33
- }), c.value.length > O && c.value.shift();
34
- }
35
- l = requestAnimationFrame(e);
36
- }
37
- l = requestAnimationFrame(e);
38
- }
39
- function b() {
40
- l !== null && (cancelAnimationFrame(l), l = null);
41
- }
42
- function x(e) {
43
- t.value = !0, r.value = {
44
- x: e.clientX - n.value.x,
45
- y: e.clientY - n.value.y
46
- };
47
- }
48
- function S(e) {
49
- t.value && (n.value = {
50
- x: e.clientX - r.value.x,
51
- y: e.clientY - r.value.y
52
- });
53
- }
54
- function k() {
55
- t.value = !1;
56
- }
57
- function A(e) {
58
- return e >= 55 ? "#52c41a" : e >= 40 ? "#faad14" : "#ff4d4f";
59
- }
60
- function j() {
61
- return c.value.length < 2 ? "" : `M ${c.value.map((e, t) => `${t / (O - 1) * 200},${60 - e.fps / 60 * 60}`).join(" L ")}`;
62
- }
63
- return f(() => {
64
- y(), document.addEventListener("mousemove", S), document.addEventListener("mouseup", k);
65
- }), p(() => {
66
- b(), document.removeEventListener("mousemove", S), document.removeEventListener("mouseup", k);
67
- }), (t, r) => (m(), i("div", {
68
- class: u(["xmd-debug-panel", e.className]),
69
- style: d({
70
- left: `${n.value.x}px`,
71
- top: `${n.value.y}px`
72
- })
73
- }, [a("div", {
74
- class: "xmd-debug-header",
75
- onMousedown: x
76
- }, [...r[0] ||= [a("span", null, "Debug Panel", -1)]], 32), a("div", C, [
77
- a("div", w, [r[1] ||= a("span", { class: "xmd-debug-label" }, "FPS:", -1), a("span", { style: d({ color: A(o.value) }) }, v(o.value), 5)]),
78
- a("div", T, [r[2] ||= a("span", { class: "xmd-debug-label" }, "Memory:", -1), a("span", null, v(s.value) + " MB", 1)]),
79
- (m(), i("svg", E, [a("path", {
80
- d: j(),
81
- fill: "none",
82
- stroke: "#1890ff",
83
- "stroke-width": "2"
84
- }, null, 8, D)]))
85
- ])], 6));
86
- }
87
- }), A = (e, t) => {
88
- let n = e.__vccOpts || e;
89
- for (let [e, r] of t) n[e] = r;
90
- return n;
91
- }, j = /* @__PURE__ */ A(k, [["__scopeId", "data-v-d6923a13"]]), ee = { class: "xmd-tail" }, M = /* @__PURE__ */ A(/* @__PURE__ */ c({
92
- __name: "TailIndicator",
93
- props: { content: { default: "▋" } },
94
- setup(e) {
95
- return (t, n) => (m(), i("span", ee, v(e.content), 1));
96
- }
97
- }), [["__scopeId", "data-v-802ace82"]]), N = /* @__PURE__ */ function(e) {
98
- return e.Text = "text", e.Link = "link", e.Image = "image", e.Html = "html", e.Emphasis = "emphasis", e.List = "list", e.Table = "table", e.InlineCode = "inline-code", e;
99
- }({}), P = {
100
- image: [/^!\[[^\]\r\n]{0,1000}$/, /^!\[[^\r\n]{0,1000}\]\(*[^)\r\n]{0,1000}$/],
101
- link: [/^\[[^\]\r\n]{0,1000}$/, /^\[[^\r\n]{0,1000}\]\(*[^)\r\n]{0,1000}$/],
102
- html: [/^<\/$/, /^<\/?[a-zA-Z][a-zA-Z0-9-]{0,100}[^>\r\n]{0,1000}$/],
103
- commonEmphasis: [/^(\*{1,3}|_{1,3})(?!\s)(?!.*\1$)[^\r\n]{0,1000}$/],
104
- list: [/^[-+*]\s{0,3}$/, /^[-+*]\s{1,3}(\*{1,3}|_{1,3})(?!\s)(?!.*\1$)[^\r\n]{0,1000}$/],
105
- "inline-code": [/^`[^`\r\n]{0,300}$/]
106
- }, F = (e) => {
107
- if (e.includes("\n\n")) return !1;
108
- let t = e.split("\n");
109
- if (t.length <= 1) return !0;
110
- let [n, r] = t, i = n.trim();
111
- if (!/^\|.*\|$/.test(i)) return !1;
112
- let a = r.trim().split("|").map((e) => e.trim()).filter(Boolean), o = /^:?-+:?$/;
113
- return a.every((e, t) => t === a.length - 1 && e === ":" || o.test(e));
114
- }, I = {
115
- [N.Link]: {
116
- tokenType: N.Link,
117
- isStartOfToken: (e) => e.startsWith("["),
118
- isStreamingValid: (e) => P.link.some((t) => t.test(e))
119
- },
120
- [N.Image]: {
121
- tokenType: N.Image,
122
- isStartOfToken: (e) => e.startsWith("!"),
123
- isStreamingValid: (e) => P.image.some((t) => t.test(e))
124
- },
125
- [N.Html]: {
126
- tokenType: N.Html,
127
- isStartOfToken: (e) => e.startsWith("<"),
128
- isStreamingValid: (e) => P.html.some((t) => t.test(e))
129
- },
130
- [N.Emphasis]: {
131
- tokenType: N.Emphasis,
132
- isStartOfToken: (e) => e.startsWith("*") || e.startsWith("_"),
133
- isStreamingValid: (e) => P.commonEmphasis.some((t) => t.test(e))
134
- },
135
- [N.List]: {
136
- tokenType: N.List,
137
- isStartOfToken: (e) => /^[-+*]/.test(e),
138
- isStreamingValid: (e) => P.list.some((t) => t.test(e)),
139
- getCommitPrefix: (e) => {
140
- let t = e.match(/^([-+*]\s{0,3})/)?.[1], n = t ? e.slice(t.length) : "";
141
- return t && n.startsWith("`") ? t : null;
142
- }
143
- },
144
- [N.Table]: {
145
- tokenType: N.Table,
146
- isStartOfToken: (e) => e.startsWith("|"),
147
- isStreamingValid: F
148
- },
149
- [N.InlineCode]: {
150
- tokenType: N.InlineCode,
151
- isStartOfToken: (e) => e.startsWith("`"),
152
- isStreamingValid: (e) => P["inline-code"].some((t) => t.test(e))
153
- }
154
- }, L = (e, t) => {
155
- let n = I[t];
156
- if (!n) return;
157
- let { token: r, pending: i } = e;
158
- if (r === N.Text && n.isStartOfToken(i)) {
159
- e.token = t;
160
- return;
161
- }
162
- if (r === t && !n.isStreamingValid(i)) {
163
- let t = n.getCommitPrefix?.(i);
164
- if (t) {
165
- e.completeMarkdown += t, e.pending = i.slice(t.length), e.token = N.Text;
166
- return;
167
- }
168
- B(e);
169
- }
170
- }, R = Object.values(I).filter((e) => !!e), z = () => ({
171
- pending: "",
172
- token: N.Text,
173
- processedLength: 0,
174
- completeMarkdown: ""
175
- }), B = (e) => {
176
- e.pending &&= (e.completeMarkdown += e.pending, ""), e.token = N.Text;
177
- }, te = (e, t = !1) => {
178
- let n = e.split("\n"), r = !1, i = "", a = 0;
179
- for (let e = 0; e < n.length; e++) {
180
- let o = n[e], s = (o.endsWith("\r") ? o.slice(0, -1) : o).match(/^(`{3,}|~{3,})(.*)$/);
181
- if (!s) continue;
182
- let c = s[1], l = s[2], u = c[0], d = c.length;
183
- if (!r) {
184
- r = !0, i = u, a = d;
185
- continue;
186
- }
187
- u === i && d >= a && /^\s*$/.test(l) && (t || e < n.length - 1) && (r = !1, i = "", a = 0);
188
- }
189
- return r;
190
- }, ne = (e) => {
191
- let t = "";
192
- for (let n = 0; n < e.length; n++) {
193
- let r = e.charCodeAt(n);
194
- r >= 55296 && r <= 56319 ? n + 1 < e.length && e.charCodeAt(n + 1) >= 56320 && e.charCodeAt(n + 1) <= 57343 && (t += e[n] + e[n + 1], n++) : (r < 56320 || r > 57343) && (t += e[n]);
195
- }
196
- return t;
197
- }, V = (e) => {
198
- try {
199
- return encodeURIComponent(e);
200
- } catch (t) {
201
- return t instanceof URIError ? encodeURIComponent(ne(e)) : "";
202
- }
203
- };
204
- function H(e, t, n) {
205
- let r = h(z()), i = h("");
206
- function a(e, t) {
207
- let { token: r, pending: i } = e;
208
- if (r === N.Text || r === N.Image && i === "!") return;
209
- if (r === N.Table && i.split("\n").length > 2) return i;
210
- let a = t?.incompleteMarkdownComponentMap?.[r] ?? `incomplete-${r}`;
211
- if (n?.value?.[a]) return `<${a} data-raw="${V(i)}" />`;
212
- }
213
- function o(e, t) {
214
- if (!e) {
215
- i.value = "", r.value = z();
216
- return;
217
- }
218
- let n = r.value.completeMarkdown + r.value.pending;
219
- e.startsWith(n) || (r.value = z());
220
- let o = r.value, s = e.slice(o.processedLength);
221
- if (!s) {
222
- let e = a(o, t);
223
- i.value = o.completeMarkdown + (e || "");
224
- return;
225
- }
226
- o.processedLength += s.length;
227
- for (let e of s) {
228
- if (o.pending += e, te(o.completeMarkdown + o.pending)) {
229
- B(o);
230
- continue;
231
- }
232
- if (o.token === N.Text) for (let e of R) L(o, e.tokenType);
233
- else {
234
- let e = R.find((e) => e.tokenType === o.token);
235
- if (e && L(o, e.tokenType), o.token === N.Text) for (let e of R) L(o, e.tokenType);
236
- }
237
- o.token === N.Text && B(o);
238
- }
239
- let c = a(o, t);
240
- i.value = o.completeMarkdown + (c || "");
241
- }
242
- function s() {
243
- r.value = z(), i.value = "";
244
- }
245
- return b([e, () => t.value?.hasNextChunk], ([e, n]) => {
246
- let a = t.value;
247
- if (!n) {
248
- i.value = e, r.value = {
249
- pending: "",
250
- token: N.Text,
251
- processedLength: e.length,
252
- completeMarkdown: e
253
- };
254
- return;
255
- }
256
- o(e, a);
257
- }, { immediate: !0 }), {
258
- processedContent: i,
259
- reset: s
260
- };
261
- }
262
- //#endregion
263
- //#region src/XMarkdown/composables/useTail.ts
264
- var U = "▋";
265
- function W(e) {
266
- let n = t(() => {
267
- let t = e.value?.tail;
268
- return t ? typeof t == "boolean" ? U : t.content || U : null;
269
- });
270
- return {
271
- tailContent: n,
272
- tailComponent: t(() => {
273
- let t = e.value?.tail;
274
- return !t || typeof t == "boolean" ? null : t.component || null;
275
- }),
276
- showTail: t(() => e.value?.hasNextChunk && n.value !== null)
277
- };
278
- }
279
- //#endregion
280
- //#region src/XMarkdown/core/Parser.ts
281
- var re = {
282
- "&": "&amp;",
283
- "<": "&lt;",
284
- ">": "&gt;",
285
- "\"": "&quot;",
286
- "'": "&#39;"
287
- };
288
- function G(e) {
289
- return /[&<>"']/.test(e) ? e.replace(/[&<>"']/g, (e) => re[e] || e) : e;
290
- }
291
- var K = class {
292
- options;
293
- markdownInstance;
294
- injectTail = !1;
295
- constructor(e = {}) {
296
- this.options = {
297
- openLinksInNewTab: e.openLinksInNewTab ?? !0,
298
- paragraphTag: e.paragraphTag ?? "p",
299
- injectTail: e.injectTail ?? !1,
300
- protectCustomTags: e.protectCustomTags ?? !0,
301
- escapeRawHtml: e.escapeRawHtml ?? !1,
302
- config: {
303
- gfm: !0,
304
- ...e.config
305
- },
306
- components: e.components ?? {},
307
- streamStatus: e.streamStatus ?? "done",
308
- codeBlockStatus: e.codeBlockStatus ?? {}
309
- }, this.markdownInstance = new S(this.options.config), this.configureRenderers();
310
- }
311
- updateMarkedConfig(e) {
312
- this.options.config = {
313
- ...this.options.config,
314
- ...e
315
- }, this.markdownInstance = new S(this.options.config), this.configureRenderers();
316
- }
317
- configureRenderers() {
318
- this.markdownInstance.use({ renderer: {
319
- html: (e) => this.options.escapeRawHtml ? G(e) : e,
320
- link: (e, t, n) => `<a href="${e}"${t ? ` title="${t}"` : ""}${this.options.openLinksInNewTab ? " target=\"_blank\" rel=\"noopener noreferrer\"" : ""}>${n}</a>`,
321
- paragraph: (e) => this.options.paragraphTag === "p" ? `<p>${e}</p>` : `<${this.options.paragraphTag}>${e}</${this.options.paragraphTag}>`,
322
- code: (e, t, n) => {
323
- let r = t || "";
324
- return `<pre><code class="language-${r}"${r ? ` data-lang="${r}"` : ""} data-block="true"${` data-state="${this.getCodeBlockState(r)}"`}>${n ? e : G(e)}</code></pre>`;
325
- }
326
- } });
327
- }
328
- getCodeBlockState(e) {
329
- return this.options.codeBlockStatus[e] ?? this.options.streamStatus;
330
- }
331
- parse(e, t) {
332
- this.injectTail = t?.injectTail ?? !1;
333
- let n = e;
334
- this.options.protectCustomTags && (n = this.protectCustomTags(n)), this.options.escapeRawHtml && (n = this.escapeRawHtml(n));
335
- let r = this.markedParse(n), i = this.sanitize(r);
336
- return this.injectTail ? this.injectTailMarker(i) : i;
337
- }
338
- markedParse(e) {
339
- return this.markdownInstance.parse(e);
340
- }
341
- sanitize(e) {
342
- let t = Object.keys(this.options.components);
343
- return x.sanitize(e, {
344
- ADD_ATTR: [
345
- "target",
346
- "data-lang",
347
- "data-block",
348
- "data-state",
349
- "data-raw",
350
- "data-icon",
351
- "data-description",
352
- "icon",
353
- "description",
354
- "rel"
355
- ],
356
- ADD_TAGS: ["xmd-tail", ...t]
357
- });
358
- }
359
- protectCustomTags(e) {
360
- let t = /<[A-Z][a-zA-Z0-9]*[^>]*>[\s\S]*?<\/[A-Z][a-zA-Z0-9]*>/g, n = e, r = 0;
361
- return n = n.replace(t, () => {
362
- let e = `__CUSTOM_TAG_${r}__`;
363
- return r++, e;
364
- }), n;
365
- }
366
- escapeRawHtml(e) {
367
- return e.replace(/<[^>]+>/g, (e) => G(e));
368
- }
369
- injectTailMarker(e) {
370
- if (e.includes("<xmd-tail></xmd-tail>")) return e;
371
- let t = document.createElement("div");
372
- t.innerHTML = e;
373
- let n = (e) => {
374
- let t = Array.from(e.childNodes);
375
- for (let e = t.length - 1; e >= 0; e--) {
376
- let r = t[e];
377
- if (r.nodeType === Node.TEXT_NODE) {
378
- if ((r.textContent || "").trim()) return r;
379
- continue;
380
- }
381
- if (r.nodeType === Node.ELEMENT_NODE) return n(r) || r;
382
- }
383
- return null;
384
- }, r = n(t);
385
- if (!r || r.nodeType !== Node.TEXT_NODE) return e;
386
- let i = document.createElement("xmd-tail");
387
- return r.parentNode?.insertBefore(i, r.nextSibling), t.innerHTML;
388
- }
389
- setOptions(e) {
390
- let { config: t, ...n } = e;
391
- Object.assign(this.options, n), t && this.updateMarkedConfig(t);
392
- }
393
- }, q = /* @__PURE__ */ c({
394
- __name: "AnimationText",
395
- props: {
396
- text: {},
397
- fadeDuration: { default: 200 },
398
- easing: { default: "ease-in-out" }
399
- },
400
- setup(n) {
401
- let r = n, a = h([]), o = h("");
402
- function s(e) {
403
- if (e === o.value) return;
404
- if (!(o.value && e.startsWith(o.value))) {
405
- a.value = [e], o.value = e;
406
- return;
407
- }
408
- let t = e.slice(o.value.length);
409
- t && (a.value = [...a.value, t], o.value = e);
410
- }
411
- b(() => r.text, s, { immediate: !0 });
412
- let c = t(() => ({
413
- animation: `x-markdown-fade-in ${r.fadeDuration}ms ${r.easing} forwards`,
414
- color: "inherit"
415
- }));
416
- return (t, n) => (m(!0), i(e, null, g(a.value, (e, t) => (m(), i("span", {
417
- key: `animation-text-${t}`,
418
- style: d(c.value)
419
- }, v(e), 5))), 128));
420
- }
421
- }), J = new Set([
422
- "area",
423
- "base",
424
- "br",
425
- "col",
426
- "embed",
427
- "hr",
428
- "img",
429
- "input",
430
- "link",
431
- "meta",
432
- "param",
433
- "source",
434
- "track",
435
- "wbr"
436
- ]), Y = /\/\s*>$/;
437
- function X(e, t) {
438
- let n = /* @__PURE__ */ new Set(), r = [], i = {};
439
- t.forEach((e) => {
440
- i[e] = 0;
441
- });
442
- let a = /<\/?([a-zA-Z][a-zA-Z0-9-]*)[^>]*>/g, o;
443
- for (; (o = a.exec(e)) !== null;) {
444
- let e = o[0], n = o[1].toLowerCase();
445
- if (!t.includes(n) || e.includes("<!--") || e.includes("<![CDATA[")) continue;
446
- let a = Y.test(e), s = !e.startsWith("</");
447
- if (!(a || !s) && !J.has(n)) if (s) {
448
- i[n] = (i[n] || 0) + 1;
449
- let e = `${n}-${i[n]}`;
450
- r.push({
451
- name: n,
452
- instanceId: e
453
- });
454
- } else {
455
- let e = r.findLast((e) => e.name === n);
456
- if (e) {
457
- let t = r.lastIndexOf(e);
458
- r.splice(t, 1);
459
- }
460
- }
461
- }
462
- return r.forEach((e) => {
463
- n.add(e.instanceId);
464
- }), n;
465
- }
466
- //#endregion
467
- //#region src/XMarkdown/core/VueRenderer.ts
468
- var ie = 200, ae = /[^\r\n\s]+/, oe = /* @__PURE__ */ "math.maction.maligngroup.malignmark.menclose.merror.mfenced.mfrac.mglyph.mi.mlabeledtr.mlongdiv.mmultiscripts.mn.mo.mover.mpadded.mphantom.mprescripts.mroot.mrow.ms.mscarries.mscarry.msgroup.msline.mspace.msqrt.msrow.mstack.mstyle.msub.msup.msubsup.mtable.mtd.mtext.mtr.munder.munderover.semantics.annotation.annotation-xml".split("."), Z = class {
469
- options;
470
- constructor(e = {}) {
471
- this.options = {
472
- components: e.components ?? {},
473
- enableAnimation: e.enableAnimation ?? !0,
474
- animationConfig: {
475
- fadeDuration: e.animationConfig?.fadeDuration ?? ie,
476
- easing: e.animationConfig?.easing ?? "ease-in-out"
477
- }
478
- };
479
- }
480
- render(t) {
481
- let n = this.sanitize(t), r = X(n, Object.keys(this.options.components)), i = this.parseToVNodes(n, r);
482
- return i.length === 0 ? l("span", "") : i.length === 1 ? i[0] : l(e, i);
483
- }
484
- sanitize(e) {
485
- let t = [...new Set([
486
- ...Object.keys(this.options.components),
487
- "p",
488
- "br",
489
- "span",
490
- "div",
491
- "a",
492
- "img",
493
- "ul",
494
- "ol",
495
- "li",
496
- "h1",
497
- "h2",
498
- "h3",
499
- "h4",
500
- "h5",
501
- "h6",
502
- "blockquote",
503
- "pre",
504
- "code",
505
- "em",
506
- "strong",
507
- "del",
508
- "ins",
509
- "table",
510
- "thead",
511
- "tbody",
512
- "tr",
513
- "th",
514
- "td",
515
- "hr",
516
- "xmd-tail",
517
- ...oe
518
- ])];
519
- return x.sanitize(e, {
520
- ALLOWED_TAGS: t,
521
- ALLOWED_ATTR: [
522
- "class",
523
- "style",
524
- "aria-hidden",
525
- "aria-label",
526
- "role",
527
- "xmlns",
528
- "encoding",
529
- "href",
530
- "src",
531
- "title",
532
- "alt",
533
- "target",
534
- "rel",
535
- "data-lang",
536
- "data-block",
537
- "data-state",
538
- "data-raw",
539
- "data-icon",
540
- "data-description",
541
- "icon",
542
- "description"
543
- ]
544
- });
545
- }
546
- parseToVNodes(e, t) {
547
- let n = `<div>${e}</div>`, r = document.createElement("div");
548
- r.innerHTML = n;
549
- let i = [];
550
- return Array.from(r.childNodes).forEach((e) => {
551
- let n = this.convertNode(e, t);
552
- n && i.push(n);
553
- }), i;
554
- }
555
- convertNode(e, t) {
556
- if (e.nodeType === Node.TEXT_NODE) {
557
- let t = e.textContent || "", n = e.parentNode instanceof Element ? e.parentNode.tagName.toLowerCase() : "", r = !!(n && this.options.components[n]);
558
- return this.options.enableAnimation && ae.test(t) && !r ? this.wrapWithAnimation(t) : o(t);
559
- }
560
- if (e.nodeType !== Node.ELEMENT_NODE) return null;
561
- let n = e, r = n.tagName.toLowerCase(), i = this.options.components[r];
562
- if (i) {
563
- let e = this.extractComponentProps(n, r, t), a = [];
564
- return Array.from(n.childNodes).forEach((e) => {
565
- let n = this.convertNode(e, t);
566
- n && a.push(n);
567
- }), a.length === 0 ? l(i, e) : l(i, e, { default: () => a });
568
- }
569
- return r === "xmd-tail" ? l("span", { class: "xmd-tail" }, "▋") : this.convertNativeElement(n, r, t);
570
- }
571
- convertNativeElement(e, t, n) {
572
- let r = [], i = {};
573
- return Array.from(e.attributes).forEach((e) => {
574
- i[e.name] = e.value;
575
- }), Array.from(e.childNodes).forEach((e) => {
576
- let t = this.convertNode(e, n);
577
- t && r.push(t);
578
- }), l(t, i, r);
579
- }
580
- extractComponentProps(e, t, n) {
581
- let r = {};
582
- return r.streamStatus = Array.from(n).find((e) => e.startsWith(t)) ? "loading" : "done", Array.from(e.attributes).forEach((e) => {
583
- r[e.name] = e.value;
584
- }), r;
585
- }
586
- wrapWithAnimation(e) {
587
- return l(q, {
588
- text: e,
589
- fadeDuration: this.options.animationConfig.fadeDuration,
590
- easing: this.options.animationConfig.easing
591
- });
592
- }
593
- setOptions(e) {
594
- e.components && (this.options.components = {
595
- ...this.options.components,
596
- ...e.components
597
- }), e.enableAnimation !== void 0 && (this.options.enableAnimation = e.enableAnimation), e.animationConfig && (this.options.animationConfig = {
598
- ...this.options.animationConfig,
599
- ...e.animationConfig
600
- });
601
- }
602
- }, se = /* @__PURE__ */ c({
603
- __name: "index",
604
- props: {
605
- content: { default: "" },
606
- components: { default: () => ({}) },
607
- streaming: { default: void 0 },
608
- config: { default: () => ({ gfm: !0 }) },
609
- debug: {
610
- type: Boolean,
611
- default: !1
612
- },
613
- protectCustomTagNewlines: {
614
- type: Boolean,
615
- default: !0
616
- },
617
- escapeRawHtml: {
618
- type: Boolean,
619
- default: !1
620
- },
621
- className: {},
622
- style: {},
623
- openLinksInNewTab: {
624
- type: Boolean,
625
- default: !0
626
- },
627
- paragraphTag: { default: "p" }
628
- },
629
- setup(e) {
630
- let a = e, o = t(() => a.content || ""), f = t(() => a.streaming), { processedContent: p } = H(o, f, t(() => a.components)), { tailContent: g, tailComponent: v, showTail: x } = W(f), S = t(() => {
631
- let e = { ...a.components };
632
- if (!x.value || !g.value) return e;
633
- let t = v.value || M, n = g.value, r = c({
634
- name: "XmdTailBridge",
635
- setup() {
636
- return () => l(t, { content: n });
637
- }
638
- });
639
- return {
640
- ...e,
641
- "xmd-tail": r
642
- };
643
- }), C = c({
644
- name: "XmdVNodeRenderer",
645
- props: { node: {
646
- type: Object,
647
- required: !0
648
- } },
649
- setup(e) {
650
- return () => e.node;
651
- }
652
- }), w = _(new K({
653
- openLinksInNewTab: a.openLinksInNewTab,
654
- paragraphTag: a.paragraphTag,
655
- protectCustomTags: a.protectCustomTagNewlines,
656
- escapeRawHtml: a.escapeRawHtml,
657
- config: a.config,
658
- components: a.components
659
- })), T = _(new Z({
660
- components: S.value,
661
- enableAnimation: a.streaming?.enableAnimation ?? !0,
662
- animationConfig: a.streaming?.animationConfig
663
- })), E = h(0), D = () => {
664
- E.value += 1;
665
- }, O = t(() => (E.value, w.value.parse(p.value, { injectTail: x.value }))), k = t(() => (E.value, T.value.render(O.value)));
666
- return b(() => [
667
- a.openLinksInNewTab,
668
- a.paragraphTag,
669
- a.protectCustomTagNewlines,
670
- a.escapeRawHtml
671
- ], () => {
672
- w.value.setOptions({
673
- openLinksInNewTab: a.openLinksInNewTab,
674
- paragraphTag: a.paragraphTag,
675
- protectCustomTags: a.protectCustomTagNewlines,
676
- escapeRawHtml: a.escapeRawHtml
677
- }), D();
678
- }), b(() => a.config, (e) => {
679
- w.value.setOptions({ config: e }), D();
680
- }, { deep: !0 }), b(() => a.components, (e) => {
681
- w.value.setOptions({ components: e }), D();
682
- }, { deep: !0 }), b(S, (e) => {
683
- T.value.setOptions({ components: e }), D();
684
- }, { deep: !0 }), b(() => a.streaming, (e) => {
685
- T.value.setOptions({
686
- enableAnimation: e?.enableAnimation ?? !0,
687
- animationConfig: e?.animationConfig
688
- }), D();
689
- }, { deep: !0 }), (t, a) => (m(), i("div", {
690
- class: u(["x-markdown", e.className]),
691
- style: d(e.style)
692
- }, [s(y(C), { node: k.value }, null, 8, ["node"]), e.debug ? (m(), n(j, { key: 0 })) : r("", !0)], 6));
693
- }
694
- });
695
- //#endregion
696
- //#region src/XMarkdown/composables/useParser.ts
697
- function Q(e) {
698
- let t = _(null);
699
- function n(e) {
700
- return new K(e);
701
- }
702
- function r(r, i) {
703
- return t.value ||= n(i || e), i && t.value.setOptions(i), t.value.parse(r);
704
- }
705
- function i(e) {
706
- t.value = n(e);
707
- }
708
- return {
709
- parser: t,
710
- parse: r,
711
- resetParser: i
712
- };
713
- }
714
- //#endregion
715
- //#region src/XMarkdown/composables/useRenderer.ts
716
- function ce(e) {
717
- let t = _(null);
718
- function n(e) {
719
- return new Z(e);
720
- }
721
- function r(r, i) {
722
- return t.value ||= n(i || e), i && t.value.setOptions(i), t.value.render(r);
723
- }
724
- function i(e) {
725
- t.value = n(e);
726
- }
727
- return {
728
- renderer: t,
729
- render: r,
730
- resetRenderer: i
731
- };
732
- }
733
- //#endregion
734
- //#region src/XMarkdown/utils/tail.ts
735
- var $ = "▋";
736
- function le(e) {
737
- return e ? e === !0 ? $ : e.content || $ : null;
738
- }
739
- //#endregion
740
- export { q as AnimationText, j as DebugPanel, K as Parser, M as TailIndicator, Z as VueRenderer, se as XMarkdown, X as detectUnclosedComponentTags, le as resolveTailContent, Q as useParser, ce as useRenderer, H as useStreaming, W as useTail };
1
+ import AnimationText_default from "./XMarkdown/components/AnimationText.js";
2
+ import DebugPanel_default from "./XMarkdown/components/DebugPanel.js";
3
+ import TailIndicator_default from "./XMarkdown/components/TailIndicator.js";
4
+ import { useStreaming } from "./XMarkdown/composables/useStreaming.js";
5
+ import { Parser } from "./XMarkdown/core/Parser.js";
6
+ import { useParser } from "./XMarkdown/composables/useParser.js";
7
+ import { detectUnclosedComponentTags } from "./XMarkdown/core/detectUnclosedComponentTags.js";
8
+ import { VueRenderer } from "./XMarkdown/core/VueRenderer.js";
9
+ import { useRenderer } from "./XMarkdown/composables/useRenderer.js";
10
+ import { useTail } from "./XMarkdown/composables/useTail.js";
11
+ import XMarkdown_default from "./XMarkdown/index2.js";
12
+ import { resolveTailContent } from "./XMarkdown/utils/tail.js";
13
+ export { AnimationText_default as AnimationText, DebugPanel_default as DebugPanel, Parser, TailIndicator_default as TailIndicator, VueRenderer, XMarkdown_default as XMarkdown, detectUnclosedComponentTags, resolveTailContent, useParser, useRenderer, useStreaming, useTail };