vue-stream-markdown 0.2.2 → 0.3.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 (69) hide show
  1. package/README.md +5 -1
  2. package/dist/{blockquote-CVFraiyL.js → blockquote-DTo6zg12.js} +6 -2
  3. package/dist/{break-CzrM3nW0.js → break-DoDPjOA0.js} +4 -0
  4. package/dist/button-1EHxh8s2.js +6 -0
  5. package/dist/{button-CWSGNZmd.js → button-B7H9jKmU.js} +2 -2
  6. package/dist/{code-DwwmPoup.js → code-DC7KVCvB.js} +14 -10
  7. package/dist/{code-block-XfHjZodV.js → code-block-DPC1FZT3.js} +26 -13
  8. package/dist/code-block-DYrPMONb.js +10 -0
  9. package/dist/{composables-BMXMKLLj.js → composables-BvaSMf02.js} +17 -2
  10. package/dist/{delete-BRwEUU72.js → delete-xkkM7TML.js} +6 -2
  11. package/dist/dropdown-Cv_yW4GS.js +6 -0
  12. package/dist/{emphasis-DblyP-Vp.js → emphasis-BmM30dZi.js} +6 -2
  13. package/dist/error-component-1U-JNS6o.js +5 -0
  14. package/dist/{error-component-CckClFee.js → error-component-DFBWdaYB.js} +2 -2
  15. package/dist/{footnote-definition-BvZNKSLa.js → footnote-definition-6cTbdg-J.js} +9 -5
  16. package/dist/{footnote-reference-DvAxMjRZ.js → footnote-reference-CxJUg8wT.js} +5 -1
  17. package/dist/{heading-g87txbB0.js → heading-DQ4lofbm.js} +6 -2
  18. package/dist/{html-BG83dEZJ.js → html-Be_6ezK6.js} +4 -0
  19. package/dist/{html-D7bGx0Cz.js → html-DfTs9nEm.js} +4 -0
  20. package/dist/{icon-CpKYt1dR.js → icon-BJa4ovUe.js} +1 -1
  21. package/dist/icon-CvIgAOPh.js +4 -0
  22. package/dist/{image-Dwe5A7RP.js → image-DXu2WF2r.js} +13 -10
  23. package/dist/image-Dm5xIWs7.js +9 -0
  24. package/dist/{image-CR28eDok.js → image-e0E51Nc3.js} +21 -12
  25. package/dist/index.css +130 -144
  26. package/dist/index.d.ts +211 -148
  27. package/dist/index.js +452 -247
  28. package/dist/{inline-code-E5uGvmnx.js → inline-code-B5lfHACE.js} +4 -0
  29. package/dist/{inline-math-BHDNxQ5R.js → inline-math-BuO_dWPX.js} +7 -3
  30. package/dist/{link-BiA46FMM.js → link-DyD59DzG.js} +8 -4
  31. package/dist/{list-D7QyoGUy.js → list-De0KPajx.js} +6 -2
  32. package/dist/{list-item-Cv8l3Ufd.js → list-item-CuUgvXRC.js} +6 -2
  33. package/dist/{math-BzuYH4PG.js → math-DnFOOLdz.js} +7 -3
  34. package/dist/{mermaid-BoiSJ4fF.js → mermaid-ZCQPlRUa.js} +22 -8
  35. package/dist/modal-B5jFKJL4.js +4 -0
  36. package/dist/{modal-DHGxvCt5.js → modal-Bhe0iSs6.js} +8 -5
  37. package/dist/{node-list-D6zJX92N.js → node-list-CWy--Gin.js} +7 -78
  38. package/dist/node-list-Doh9Z-4p.js +4 -0
  39. package/dist/{paragraph-YTqe84Bm.js → paragraph-D3H1qprZ.js} +6 -2
  40. package/dist/previewers-DB2HHDGb.js +10 -0
  41. package/dist/{segmented-DDQZGL7l.js → segmented-B-kjIOkd.js} +1 -1
  42. package/dist/segmented-fbmq_xK1.js +7 -0
  43. package/dist/{shiki-DDfRFzy0.js → shiki-DAu2_FTG.js} +7 -3
  44. package/dist/{strong-nPwCJEKq.js → strong-BlCQoXCR.js} +6 -2
  45. package/dist/{table-Dtpd-MnT.js → table-Co_MpK6m.js} +17 -8
  46. package/dist/{text-CfRWiRE0.js → text-DbHMEN3P.js} +4 -0
  47. package/dist/{thematic-break-DgOD2KmY.js → thematic-break-CdlhHAEZ.js} +4 -0
  48. package/dist/theme.css +2 -2
  49. package/dist/tooltip-70WIAMmC.js +4 -0
  50. package/dist/{tooltip-C4RiUZwy.js → tooltip-CWv9skVu.js} +3 -2
  51. package/dist/{vanilla-NR7MOE5P.js → vanilla-D30b-_ch.js} +1 -1
  52. package/dist/vanilla-DV7fYrnj.js +4 -0
  53. package/dist/{yaml-DP0yfJyS.js → yaml-DL5ozHZ_.js} +4 -0
  54. package/dist/{zoom-container-CqZQ4X6w.js → zoom-container-DbeN8U39.js} +33 -9
  55. package/dist/zoom-container-Dc8N-wuo.js +7 -0
  56. package/package.json +4 -5
  57. package/dist/button-BFS-gHGF.js +0 -6
  58. package/dist/code-block-CTM9VEwA.js +0 -10
  59. package/dist/dropdown-BQ3uynLf.js +0 -6
  60. package/dist/error-component-B_Vacrqa.js +0 -5
  61. package/dist/icon-BX3KKloR.js +0 -4
  62. package/dist/image-BtkXhzG1.js +0 -9
  63. package/dist/modal-CFOdkYNj.js +0 -4
  64. package/dist/node-list-BYDvt6bq.js +0 -4
  65. package/dist/previewers-Cpx1Wqu8.js +0 -10
  66. package/dist/segmented-CaVb5_Rp.js +0 -7
  67. package/dist/tooltip-BIvCaFUj.js +0 -4
  68. package/dist/vanilla-DfHiHWnr.js +0 -4
  69. package/dist/zoom-container-DtkZ07v1.js +0 -7
package/dist/index.js CHANGED
@@ -1,10 +1,8 @@
1
- import { t as CODE_PREVIEWERS } from "./previewers-Cpx1Wqu8.js";
2
- import { A as tableDataToMarkdown, B as flow, C as loadLocaleMessages, D as escapeMarkdownTableCell, E as useFloating, F as hasKatex, G as useControls, H as saveImage, I as hasMermaid, K as useContext, L as hasShiki, M as preloadAsyncComponents, N as findLastLeafNode, O as extractTableDataFromElement, P as findNodeParent, R as isClient, S as currentLocale, T as localesGlob, U as svgToPngBlob, V as save, W as transformUrl, a as SHADCN_SCHEMAS, b as useI18n, c as DEFAULT_HARDEN_OPTIONS, d as LANGUAGE_ALIAS, f as LANGUAGE_EXTENSIONS, g as useMathRenderer, h as useMediumZoom, i as useSanitizers, j as tableDataToTSV, k as tableDataToCSV, l as DEFAULT_DARK_THEME, m as useMermaid, n as useTailwindV3Theme, o as PRELOAD_NODE_RENDERER, p as LANGUAGE_ICONS, q as useCodeOptions, r as useShiki, s as ICONS, t as useZoom, u as DEFAULT_LIGHT_THEME, v as _defineProperty, w as localeMessages, x as SUPPORT_LANGUAGES, y as useKatex, z as isServer } from "./composables-BMXMKLLj.js";
3
- import { t as node_list_default } from "./node-list-D6zJX92N.js";
1
+ import { t as CODE_PREVIEWERS } from "./previewers-DB2HHDGb.js";
2
+ import { A as tableDataToMarkdown, B as flow, C as loadLocaleMessages, D as escapeMarkdownTableCell, E as useFloating, F as hasKatex, G as useControls, H as saveImage, I as hasMermaid, K as useContext, L as hasShiki, M as preloadAsyncComponents, N as findLastLeafNode, O as extractTableDataFromElement, P as findNodeParent, R as isClient, S as currentLocale, T as localesGlob, U as svgToPngBlob, V as save, W as transformUrl, a as SHADCN_SCHEMAS, b as useI18n, c as DEFAULT_HARDEN_OPTIONS, d as LANGUAGE_ALIAS, f as LANGUAGE_EXTENSIONS, g as useMathRenderer, h as useMediumZoom, i as useSanitizers, j as tableDataToTSV, k as tableDataToCSV, l as DEFAULT_DARK_THEME, m as useMermaid, n as useTailwindV3Theme, o as PRELOAD_NODE_RENDERER, p as LANGUAGE_ICONS, q as useCodeOptions, r as useShiki, s as ICONS, t as useZoom, u as DEFAULT_LIGHT_THEME, v as _defineProperty, w as localeMessages, x as SUPPORT_LANGUAGES, y as useKatex, z as isServer } from "./composables-BvaSMf02.js";
3
+ import { t as node_list_default } from "./node-list-CWy--Gin.js";
4
4
  import { n as treeFlatFilter, t as treeFilter } from "./dist-CYkm26BF.js";
5
5
  import { computed, createElementBlock, createVNode, defineAsyncComponent, defineComponent, mergeProps, normalizeClass, onBeforeUnmount, onMounted, openBlock, ref, toRefs, unref, watch } from "vue";
6
- import { MarkdownItAsync } from "markdown-it-async";
7
- import remend from "remend";
8
6
 
9
7
  //#region rolldown:runtime
10
8
  var __create = Object.create;
@@ -49,46 +47,46 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
49
47
  //#endregion
50
48
  //#region src/components/renderers/index.ts
51
49
  const NODE_RENDERERS = {
52
- blockquote: defineAsyncComponent(() => import("./blockquote-CVFraiyL.js")),
53
- break: defineAsyncComponent(() => import("./break-CzrM3nW0.js")),
54
- code: defineAsyncComponent(() => import("./code-DwwmPoup.js")),
55
- delete: defineAsyncComponent(() => import("./delete-BRwEUU72.js")),
56
- emphasis: defineAsyncComponent(() => import("./emphasis-DblyP-Vp.js")),
57
- footnoteDefinition: defineAsyncComponent(() => import("./footnote-definition-BvZNKSLa.js")),
58
- footnoteReference: defineAsyncComponent(() => import("./footnote-reference-DvAxMjRZ.js")),
59
- heading: defineAsyncComponent(() => import("./heading-g87txbB0.js")),
60
- html: defineAsyncComponent(() => import("./html-BG83dEZJ.js")),
61
- image: defineAsyncComponent(() => import("./image-CR28eDok.js")),
62
- inlineCode: defineAsyncComponent(() => import("./inline-code-E5uGvmnx.js")),
63
- inlineMath: defineAsyncComponent(() => import("./inline-math-BHDNxQ5R.js")),
64
- link: defineAsyncComponent(() => import("./link-BiA46FMM.js")),
65
- list: defineAsyncComponent(() => import("./list-D7QyoGUy.js")),
66
- listItem: defineAsyncComponent(() => import("./list-item-Cv8l3Ufd.js")),
67
- math: defineAsyncComponent(() => import("./math-BzuYH4PG.js")),
68
- paragraph: defineAsyncComponent(() => import("./paragraph-YTqe84Bm.js")),
69
- strong: defineAsyncComponent(() => import("./strong-nPwCJEKq.js")),
70
- table: defineAsyncComponent(() => import("./table-Dtpd-MnT.js")),
71
- text: defineAsyncComponent(() => import("./text-CfRWiRE0.js")),
72
- thematicBreak: defineAsyncComponent(() => import("./thematic-break-DgOD2KmY.js")),
73
- yaml: defineAsyncComponent(() => import("./yaml-DP0yfJyS.js"))
50
+ blockquote: defineAsyncComponent(() => import("./blockquote-DTo6zg12.js")),
51
+ break: defineAsyncComponent(() => import("./break-DoDPjOA0.js")),
52
+ code: defineAsyncComponent(() => import("./code-DC7KVCvB.js")),
53
+ delete: defineAsyncComponent(() => import("./delete-xkkM7TML.js")),
54
+ emphasis: defineAsyncComponent(() => import("./emphasis-BmM30dZi.js")),
55
+ footnoteDefinition: defineAsyncComponent(() => import("./footnote-definition-6cTbdg-J.js")),
56
+ footnoteReference: defineAsyncComponent(() => import("./footnote-reference-CxJUg8wT.js")),
57
+ heading: defineAsyncComponent(() => import("./heading-DQ4lofbm.js")),
58
+ html: defineAsyncComponent(() => import("./html-Be_6ezK6.js")),
59
+ image: defineAsyncComponent(() => import("./image-e0E51Nc3.js")),
60
+ inlineCode: defineAsyncComponent(() => import("./inline-code-B5lfHACE.js")),
61
+ inlineMath: defineAsyncComponent(() => import("./inline-math-BuO_dWPX.js")),
62
+ link: defineAsyncComponent(() => import("./link-DyD59DzG.js")),
63
+ list: defineAsyncComponent(() => import("./list-De0KPajx.js")),
64
+ listItem: defineAsyncComponent(() => import("./list-item-CuUgvXRC.js")),
65
+ math: defineAsyncComponent(() => import("./math-DnFOOLdz.js")),
66
+ paragraph: defineAsyncComponent(() => import("./paragraph-D3H1qprZ.js")),
67
+ strong: defineAsyncComponent(() => import("./strong-BlCQoXCR.js")),
68
+ table: defineAsyncComponent(() => import("./table-Co_MpK6m.js")),
69
+ text: defineAsyncComponent(() => import("./text-DbHMEN3P.js")),
70
+ thematicBreak: defineAsyncComponent(() => import("./thematic-break-CdlhHAEZ.js")),
71
+ yaml: defineAsyncComponent(() => import("./yaml-DL5ozHZ_.js"))
74
72
  };
75
73
 
76
74
  //#endregion
77
75
  //#region src/components/index.ts
78
76
  const UI = {
79
- Button: defineAsyncComponent(() => import("./button-BFS-gHGF.js")),
80
- CodeBlock: defineAsyncComponent(() => import("./code-block-CTM9VEwA.js")),
81
- Dropdown: defineAsyncComponent(() => import("./dropdown-BQ3uynLf.js")),
82
- ErrorComponent: defineAsyncComponent(() => import("./error-component-B_Vacrqa.js")),
83
- Icon: defineAsyncComponent(() => import("./icon-BX3KKloR.js")),
84
- Image: defineAsyncComponent(() => import("./image-BtkXhzG1.js")),
85
- Modal: defineAsyncComponent(() => import("./modal-CFOdkYNj.js")),
86
- NodeList: defineAsyncComponent(() => import("./node-list-BYDvt6bq.js")),
87
- Segmented: defineAsyncComponent(() => import("./segmented-CaVb5_Rp.js")),
77
+ Button: defineAsyncComponent(() => import("./button-1EHxh8s2.js")),
78
+ CodeBlock: defineAsyncComponent(() => import("./code-block-DYrPMONb.js")),
79
+ Dropdown: defineAsyncComponent(() => import("./dropdown-Cv_yW4GS.js")),
80
+ ErrorComponent: defineAsyncComponent(() => import("./error-component-1U-JNS6o.js")),
81
+ Icon: defineAsyncComponent(() => import("./icon-CvIgAOPh.js")),
82
+ Image: defineAsyncComponent(() => import("./image-Dm5xIWs7.js")),
83
+ Modal: defineAsyncComponent(() => import("./modal-B5jFKJL4.js")),
84
+ NodeList: defineAsyncComponent(() => import("./node-list-Doh9Z-4p.js")),
85
+ Segmented: defineAsyncComponent(() => import("./segmented-fbmq_xK1.js")),
88
86
  Spin: defineAsyncComponent(() => import("./spin-DElj7VPm.js")),
89
87
  Table: defineAsyncComponent(() => import("./table-D6j6Gl87.js")),
90
- Tooltip: defineAsyncComponent(() => import("./tooltip-BIvCaFUj.js")),
91
- ZoomContainer: defineAsyncComponent(() => import("./zoom-container-DtkZ07v1.js"))
88
+ Tooltip: defineAsyncComponent(() => import("./tooltip-70WIAMmC.js")),
89
+ ZoomContainer: defineAsyncComponent(() => import("./zoom-container-Dc8N-wuo.js"))
92
90
  };
93
91
 
94
92
  //#endregion
@@ -2894,7 +2892,7 @@ function initializeContent(effects) {
2894
2892
  * Construct and its state.
2895
2893
  */
2896
2894
  /** @type {InitialConstruct} */
2897
- const document = { tokenize: initializeDocument };
2895
+ const document$1 = { tokenize: initializeDocument };
2898
2896
  /** @type {Construct} */
2899
2897
  const containerConstruct = { tokenize: tokenizeContainer };
2900
2898
  /**
@@ -8989,7 +8987,7 @@ var constructs_exports = /* @__PURE__ */ __export({
8989
8987
  attentionMarkers: () => attentionMarkers,
8990
8988
  contentInitial: () => contentInitial,
8991
8989
  disable: () => disable,
8992
- document: () => document$1,
8990
+ document: () => document$2,
8993
8991
  flow: () => flow$2,
8994
8992
  flowInitial: () => flowInitial,
8995
8993
  insideSpan: () => insideSpan,
@@ -8997,7 +8995,7 @@ var constructs_exports = /* @__PURE__ */ __export({
8997
8995
  text: () => text$3
8998
8996
  });
8999
8997
  /** @satisfies {Extension['document']} */
9000
- const document$1 = {
8998
+ const document$2 = {
9001
8999
  [42]: list$2,
9002
9000
  [43]: list$2,
9003
9001
  [45]: list$2,
@@ -9552,7 +9550,7 @@ function parse(options) {
9552
9550
  constructs: combineExtensions([constructs_exports, ...(options || {}).extensions || []]),
9553
9551
  content: create$1(content),
9554
9552
  defined: [],
9555
- document: create$1(document),
9553
+ document: create$1(document$1),
9556
9554
  flow: create$1(flow$1),
9557
9555
  lazy: {},
9558
9556
  string: create$1(string),
@@ -19708,6 +19706,82 @@ const quoteTaskListPattern = /^>\s*- \[[x ]\]/i;
19708
19706
  const quoteIncompleteTaskListPattern = /^>\s*-\s*\[\s*$/;
19709
19707
  const trailingStandaloneDashWithNewlinesPattern = /(\n\n?)-[ \t]*$/;
19710
19708
 
19709
+ //#endregion
19710
+ //#region src/preprocess/utils.ts
19711
+ /**
19712
+ * Utility functions for preprocessing markdown content
19713
+ */
19714
+ /**
19715
+ * Find the start index of the last paragraph in content
19716
+ * A paragraph is defined as content after the last blank line
19717
+ *
19718
+ * @param lines - Array of lines from content.split('\n')
19719
+ * @param skipTrailingEmpty - If true, skip the last element if it's empty (from trailing \n)
19720
+ * @returns The start index of the last paragraph
19721
+ */
19722
+ function findLastParagraphStart(lines, skipTrailingEmpty = false) {
19723
+ for (let i = lines.length - 1; i >= 0; i--) {
19724
+ const line = lines[i];
19725
+ if (line === void 0) continue;
19726
+ if (skipTrailingEmpty && i === lines.length - 1 && line.trim() === "") continue;
19727
+ if (line.trim() === "") return i + 1;
19728
+ }
19729
+ return 0;
19730
+ }
19731
+ /**
19732
+ * Get the last paragraph and its start index
19733
+ *
19734
+ * @param content - Markdown content
19735
+ * @param skipTrailingEmpty - If true, skip trailing empty line when finding paragraph start
19736
+ * @returns Object with lastParagraph and startIndex
19737
+ */
19738
+ function getLastParagraphWithIndex(content$2, skipTrailingEmpty = false) {
19739
+ const lines = content$2.split("\n");
19740
+ const startIndex = findLastParagraphStart(lines, skipTrailingEmpty);
19741
+ return {
19742
+ lastParagraph: lines.slice(startIndex).join("\n"),
19743
+ startIndex
19744
+ };
19745
+ }
19746
+ /**
19747
+ * Find the index of the last non-empty line
19748
+ *
19749
+ * @param lines - Array of lines
19750
+ * @returns The index of the last non-empty line, or -1 if all lines are empty
19751
+ */
19752
+ function findLastNonEmptyLineIndex(lines) {
19753
+ for (let i = lines.length - 1; i >= 0; i--) {
19754
+ const line = lines[i];
19755
+ if (line && line.trim() !== "") return i;
19756
+ }
19757
+ return -1;
19758
+ }
19759
+ /**
19760
+ * Calculate the absolute position in content from a relative position in a paragraph
19761
+ *
19762
+ * @param paragraphStartIndex - The line index where the paragraph starts
19763
+ * @param relativePos - The position relative to the paragraph start
19764
+ * @param lines - All lines from content.split('\n')
19765
+ * @returns The absolute position in the full content
19766
+ */
19767
+ function calculateAbsolutePosition(paragraphStartIndex, relativePos, lines) {
19768
+ if (paragraphStartIndex === 0) return relativePos;
19769
+ const beforeParagraph = lines.slice(0, paragraphStartIndex).join("\n");
19770
+ return beforeParagraph.length > 0 ? beforeParagraph.length + 1 + relativePos : relativePos;
19771
+ }
19772
+ /**
19773
+ * Calculate the paragraph offset for absolute position calculations
19774
+ *
19775
+ * @param paragraphStartIndex - The line index where the paragraph starts
19776
+ * @param lines - All lines from content.split('\n')
19777
+ * @returns The offset to add to relative positions
19778
+ */
19779
+ function calculateParagraphOffset(paragraphStartIndex, lines) {
19780
+ if (paragraphStartIndex === 0) return 0;
19781
+ const beforeParagraph = lines.slice(0, paragraphStartIndex).join("\n");
19782
+ return beforeParagraph.length > 0 ? beforeParagraph.length + 1 : 0;
19783
+ }
19784
+
19711
19785
  //#endregion
19712
19786
  //#region src/preprocess/code.ts
19713
19787
  /**
@@ -19740,10 +19814,13 @@ const trailingStandaloneDashWithNewlinesPattern = /(\n\n?)-[ \t]*$/;
19740
19814
  * // Returns: '```' (no completion, code block has no content)
19741
19815
  */
19742
19816
  function fixCode(content$2) {
19817
+ const codeBlockMatches = content$2.match(tripleBacktickPattern);
19818
+ const isInsideCodeBlock = (codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1;
19743
19819
  const cleaned = removeTrailingIncompleteBackticks(content$2);
19744
19820
  const wasCleanedUp = cleaned !== content$2;
19745
19821
  content$2 = cleaned;
19746
- if (!wasCleanedUp) content$2 = fixCodeBlock(content$2);
19822
+ if (isInsideCodeBlock && wasCleanedUp) content$2 = fixCodeBlock(content$2);
19823
+ else if (!wasCleanedUp) content$2 = fixCodeBlock(content$2);
19747
19824
  if (!wasCleanedUp) content$2 = fixInlineCode(content$2);
19748
19825
  return content$2;
19749
19826
  }
@@ -19761,13 +19838,8 @@ function removeTrailingIncompleteBackticks(content$2) {
19761
19838
  const afterBackticks = content$2.substring(backtickPos + backtickSequence.length);
19762
19839
  if (afterBackticks.trim().length > 0) return content$2;
19763
19840
  if (backtickSequence.length === 1) {
19764
- const lines = beforeBackticks.split("\n");
19765
- let paragraphStartIndex = 0;
19766
- for (let i = lines.length - 1; i >= 0; i--) if (lines[i].trim() === "") {
19767
- paragraphStartIndex = i + 1;
19768
- break;
19769
- }
19770
- const backticks = lines.slice(paragraphStartIndex).join("\n").replace(codeBlockPattern, "").match(singleBacktickPattern);
19841
+ const { lastParagraph } = getLastParagraphWithIndex(beforeBackticks);
19842
+ const backticks = lastParagraph.replace(codeBlockPattern, "").match(singleBacktickPattern);
19771
19843
  const count = backticks ? backticks.length : 0;
19772
19844
  const codeBlockMatches = beforeBackticks.match(tripleBacktickPattern);
19773
19845
  const codeBlockCount = codeBlockMatches ? codeBlockMatches.length : 0;
@@ -19807,12 +19879,7 @@ function fixInlineCode(content$2) {
19807
19879
  const codeBlockMatches = content$2.match(tripleBacktickPattern);
19808
19880
  if ((codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1) return content$2;
19809
19881
  const lines = content$2.split("\n");
19810
- let paragraphStartIndex = 0;
19811
- for (let i = lines.length - 1; i >= 0; i--) if (lines[i].trim() === "") {
19812
- paragraphStartIndex = i + 1;
19813
- break;
19814
- }
19815
- const lastParagraph = lines.slice(paragraphStartIndex).join("\n");
19882
+ const { lastParagraph, startIndex: paragraphStartIndex } = getLastParagraphWithIndex(content$2);
19816
19883
  const backticks = lastParagraph.replace(codeBlockPattern, "").match(singleBacktickPattern);
19817
19884
  if ((backticks ? backticks.length : 0) % 2 === 1) {
19818
19885
  let lastBacktickPos = -1;
@@ -19834,8 +19901,7 @@ function fixInlineCode(content$2) {
19834
19901
  }
19835
19902
  }
19836
19903
  if (lastBacktickPos !== -1) {
19837
- const beforeLastParagraph = lines.slice(0, paragraphStartIndex).join("\n");
19838
- const actualPos = (beforeLastParagraph.length > 0 ? beforeLastParagraph.length + 1 : 0) + lastBacktickPos;
19904
+ const actualPos = calculateParagraphOffset(paragraphStartIndex, lines) + lastBacktickPos;
19839
19905
  if (content$2.substring(actualPos + 1).trim().length > 0) return `${content$2}\``;
19840
19906
  else return content$2.slice(0, actualPos) + content$2.slice(actualPos + 1);
19841
19907
  }
@@ -19867,31 +19933,28 @@ function fixInlineCode(content$2) {
19867
19933
  * // Returns: 'List item\n\n~~' (no completion, ~~ has no content)
19868
19934
  */
19869
19935
  function fixDelete(content$2) {
19870
- const lines = content$2.split("\n");
19871
- let paragraphStartIndex = 0;
19872
- for (let i = lines.length - 1; i >= 0; i--) if (lines[i].trim() === "") {
19873
- paragraphStartIndex = i + 1;
19874
- break;
19875
- }
19876
- const lastParagraph = lines.slice(paragraphStartIndex).join("\n");
19877
- const matches = lastParagraph.match(doubleTildePattern);
19936
+ const codeBlockMatches = content$2.match(tripleBacktickPattern);
19937
+ if ((codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1) return content$2;
19938
+ const { lastParagraph, startIndex: paragraphStartIndex } = getLastParagraphWithIndex(content$2);
19939
+ const lastParagraphWithoutCodeBlocks = lastParagraph.replace(codeBlockPattern, "");
19940
+ const matches = lastParagraphWithoutCodeBlocks.match(doubleTildePattern);
19878
19941
  const count = matches ? matches.length : 0;
19879
19942
  if (content$2.endsWith("~") && !content$2.endsWith("~~")) {
19880
19943
  const contentWithoutLastTilde = content$2.slice(0, -1);
19881
- const lastParagraphWithoutTilde = contentWithoutLastTilde.split("\n").slice(paragraphStartIndex).join("\n");
19882
- const matchesWithoutTilde = lastParagraphWithoutTilde.match(doubleTildePattern);
19944
+ const lastParagraphWithoutTildeAndCodeBlocks = contentWithoutLastTilde.split("\n").slice(paragraphStartIndex).join("\n").replace(codeBlockPattern, "");
19945
+ const matchesWithoutTilde = lastParagraphWithoutTildeAndCodeBlocks.match(doubleTildePattern);
19883
19946
  if ((matchesWithoutTilde ? matchesWithoutTilde.length : 0) % 2 === 1) {
19884
- const lastTildePos = lastParagraphWithoutTilde.lastIndexOf("~~");
19947
+ const lastTildePos = lastParagraphWithoutTildeAndCodeBlocks.lastIndexOf("~~");
19885
19948
  if (lastTildePos >= 0) {
19886
- if (lastParagraphWithoutTilde.substring(lastTildePos + 2).length > 0) return `${content$2}~`;
19949
+ if (lastParagraphWithoutTildeAndCodeBlocks.substring(lastTildePos + 2).length > 0) return `${content$2}~`;
19887
19950
  }
19888
19951
  } else return contentWithoutLastTilde;
19889
19952
  }
19890
19953
  if (count % 2 === 1) {
19891
- const lastTildePos = lastParagraph.lastIndexOf("~~");
19892
- const afterLast = lastParagraph.substring(lastTildePos + 2);
19954
+ const lastTildePos = lastParagraphWithoutCodeBlocks.lastIndexOf("~~");
19955
+ const afterLast = lastParagraphWithoutCodeBlocks.substring(lastTildePos + 2);
19893
19956
  if (afterLast.trim().length > 0) return `${content$2}~~`;
19894
- else return content$2.substring(0, content$2.length - afterLast.length - 2);
19957
+ else return content$2.substring(0, content$2.length - afterLast.length - 2).trimEnd();
19895
19958
  }
19896
19959
  return content$2;
19897
19960
  }
@@ -19905,35 +19968,46 @@ function fixDelete(content$2) {
19905
19968
  * This respects Markdown's rule that emphasis cannot span across paragraphs.
19906
19969
  */
19907
19970
  function fixEmphasis(content$2) {
19971
+ const codeBlockMatches = content$2.match(tripleBacktickPattern);
19972
+ if ((codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1) return content$2;
19908
19973
  const lines = content$2.split("\n");
19909
- let paragraphStartIndex = 0;
19910
- for (let i = lines.length - 1; i >= 0; i--) if (lines[i].trim() === "") {
19911
- paragraphStartIndex = i + 1;
19912
- break;
19913
- }
19914
- const lastParagraph = lines.slice(paragraphStartIndex).join("\n");
19915
- const withoutDoubleAsterisk = lastParagraph.replace(doubleAsteriskPattern, "");
19974
+ const { lastParagraph, startIndex: paragraphStartIndex } = getLastParagraphWithIndex(content$2);
19975
+ const lastParagraphWithoutCodeBlocks = lastParagraph.replace(codeBlockPattern, "");
19976
+ const withoutDoubleAsterisk = lastParagraphWithoutCodeBlocks.replace(doubleAsteriskPattern, "");
19916
19977
  const asteriskMatches = withoutDoubleAsterisk.match(singleAsteriskPattern);
19917
- if ((asteriskMatches ? asteriskMatches.length : 0) % 2 === 1) {
19978
+ const asteriskCount = asteriskMatches ? asteriskMatches.length : 0;
19979
+ const withoutDoubleUnderscore = lastParagraphWithoutCodeBlocks.replace(doubleUnderscorePattern, "");
19980
+ const underscoreMatches = withoutDoubleUnderscore.match(singleUnderscorePattern);
19981
+ const underscoreCount = underscoreMatches ? underscoreMatches.length : 0;
19982
+ let needsAsteriskCompletion = false;
19983
+ let needsUnderscoreCompletion = false;
19984
+ let needsAsteriskRemoval = false;
19985
+ let needsUnderscoreRemoval = false;
19986
+ if (asteriskCount % 2 === 1) {
19918
19987
  const lastStarPos = withoutDoubleAsterisk.lastIndexOf("*");
19919
- if (withoutDoubleAsterisk.substring(lastStarPos + 1).trim().length > 0) return `${content$2}*`;
19920
- else {
19921
- let result = content$2.slice(0, -1);
19922
- if (trailingStandaloneDashWithNewlinesPattern.test(result)) result = result.replace(trailingStandaloneDashWithNewlinesPattern, "$1");
19923
- return result;
19924
- }
19988
+ if (withoutDoubleAsterisk.substring(lastStarPos + 1).trim().length > 0) needsAsteriskCompletion = true;
19989
+ else needsAsteriskRemoval = true;
19925
19990
  }
19926
- const withoutDoubleUnderscore = lastParagraph.replace(doubleUnderscorePattern, "");
19927
- const underscoreMatches = withoutDoubleUnderscore.match(singleUnderscorePattern);
19928
- if ((underscoreMatches ? underscoreMatches.length : 0) % 2 === 1) {
19991
+ if (underscoreCount % 2 === 1) {
19929
19992
  const lastUnderscorePos = withoutDoubleUnderscore.lastIndexOf("_");
19930
- if (withoutDoubleUnderscore.substring(lastUnderscorePos + 1).trim().length > 0) return `${content$2}_`;
19931
- else {
19932
- let result = content$2.slice(0, -1);
19933
- if (trailingStandaloneDashWithNewlinesPattern.test(result)) result = result.replace(trailingStandaloneDashWithNewlinesPattern, "$1");
19934
- return result;
19935
- }
19993
+ if (withoutDoubleUnderscore.substring(lastUnderscorePos + 1).trim().length > 0) needsUnderscoreCompletion = true;
19994
+ else needsUnderscoreRemoval = true;
19936
19995
  }
19996
+ if (needsAsteriskRemoval) {
19997
+ let result = content$2.slice(0, -1).trimEnd();
19998
+ if (trailingStandaloneDashWithNewlinesPattern.test(result)) result = result.replace(trailingStandaloneDashWithNewlinesPattern, "$1");
19999
+ return result;
20000
+ }
20001
+ if (needsUnderscoreRemoval) {
20002
+ const absoluteLastUnderscorePos = calculateParagraphOffset(paragraphStartIndex, lines) + withoutDoubleUnderscore.lastIndexOf("_");
20003
+ let result = content$2.substring(0, absoluteLastUnderscorePos).trimEnd();
20004
+ if (trailingStandaloneDashWithNewlinesPattern.test(result)) result = result.replace(trailingStandaloneDashWithNewlinesPattern, "$1");
20005
+ return result;
20006
+ }
20007
+ if (needsAsteriskCompletion && needsUnderscoreCompletion) if (withoutDoubleAsterisk.indexOf("*") < withoutDoubleUnderscore.indexOf("_")) return `${content$2}_*`;
20008
+ else return `${content$2}*_`;
20009
+ if (needsAsteriskCompletion) return `${content$2}*`;
20010
+ if (needsUnderscoreCompletion) return `${content$2}_`;
19937
20011
  return content$2;
19938
20012
  }
19939
20013
 
@@ -20007,47 +20081,42 @@ function fixFootnote(content$2) {
20007
20081
  if (!(before === "`" && before2 === "`" || before === "`" && after === "`" || after === "`" && after2 === "`")) backtickPositions.push(i);
20008
20082
  }
20009
20083
  }
20010
- for (let i = 0; i < backtickPositions.length; i += 2) if (i + 1 < backtickPositions.length) {
20084
+ for (let i = 0; i < backtickPositions.length; i += 2) {
20011
20085
  const start = backtickPositions[i];
20012
- const end = backtickPositions[i + 1] + 1;
20013
- inlineCodeRanges.push({
20086
+ const end = backtickPositions[i + 1];
20087
+ if (start !== void 0 && end !== void 0) inlineCodeRanges.push({
20014
20088
  start,
20015
- end
20089
+ end: end + 1
20016
20090
  });
20017
20091
  }
20018
20092
  const footnoteDefRanges = [];
20019
20093
  let lineOffset = 0;
20020
20094
  for (let i = 0; i < lines.length; i++) {
20021
20095
  const line = lines[i];
20022
- if (isFootnoteDefLine(line)) {
20096
+ if (line && isFootnoteDefLine(line)) {
20023
20097
  const lineEnd = lineOffset + line.length;
20024
20098
  footnoteDefRanges.push({
20025
20099
  start: lineOffset,
20026
20100
  end: lineEnd
20027
20101
  });
20028
20102
  }
20029
- lineOffset += line.length + 1;
20030
- }
20031
- let lastParagraphStartIndex = 0;
20032
- for (let i = lines.length - 1; i >= 0; i--) if (lines[i].trim() === "") {
20033
- lastParagraphStartIndex = i + 1;
20034
- break;
20103
+ if (line) lineOffset += line.length + 1;
20035
20104
  }
20036
- const lastParagraph = lines.slice(lastParagraphStartIndex).join("\n");
20105
+ const { lastParagraph, startIndex: lastParagraphStartIndex } = getLastParagraphWithIndex(content$2);
20037
20106
  let result = content$2;
20038
20107
  if (incompleteFootnoteRefPattern.test(lastParagraph)) {
20039
20108
  const incompleteRefPos = lastParagraph.lastIndexOf("[^");
20040
20109
  if (incompleteRefPos !== -1) {
20041
- const absolutePos = lastParagraphStartIndex > 0 ? lines.slice(0, lastParagraphStartIndex).join("\n").length + 1 + incompleteRefPos : incompleteRefPos;
20110
+ const absolutePos = calculateAbsolutePosition(lastParagraphStartIndex, incompleteRefPos, lines);
20042
20111
  const isInCodeBlock = codeBlockRanges.some((range) => absolutePos >= range.start && absolutePos < range.end);
20043
20112
  const isInInlineCode = inlineCodeRanges.some((range) => absolutePos >= range.start && absolutePos < range.end);
20044
20113
  if (!isInCodeBlock && !isInInlineCode) {
20045
20114
  const lineEnd = lastParagraph.indexOf("\n", incompleteRefPos);
20046
20115
  const refEnd = lineEnd !== -1 ? lineEnd : lastParagraph.length;
20047
- const beforeLastParagraph = lines.slice(0, lastParagraphStartIndex).join("\n");
20048
- const paragraphOffset = beforeLastParagraph.length > 0 ? beforeLastParagraph.length + 1 : 0;
20049
- const absoluteStart = paragraphOffset + incompleteRefPos;
20050
- const absoluteEnd = paragraphOffset + refEnd;
20116
+ let refStart = incompleteRefPos;
20117
+ if (refStart > 0 && lastParagraph[refStart - 1] === " ") refStart--;
20118
+ const absoluteStart = calculateAbsolutePosition(lastParagraphStartIndex, refStart, lines);
20119
+ const absoluteEnd = calculateAbsolutePosition(lastParagraphStartIndex, refEnd, lines);
20051
20120
  result = result.substring(0, absoluteStart) + result.substring(absoluteEnd);
20052
20121
  content$2 = result;
20053
20122
  codeBlockRanges.length = 0;
@@ -20081,12 +20150,12 @@ function fixFootnote(content$2) {
20081
20150
  if (!(before === "`" && before2 === "`" || before === "`" && after === "`" || after === "`" && after2 === "`")) backtickPositions.push(i);
20082
20151
  }
20083
20152
  }
20084
- for (let i = 0; i < backtickPositions.length; i += 2) if (i + 1 < backtickPositions.length) {
20153
+ for (let i = 0; i < backtickPositions.length; i += 2) {
20085
20154
  const start = backtickPositions[i];
20086
- const end = backtickPositions[i + 1] + 1;
20087
- inlineCodeRanges.push({
20155
+ const end = backtickPositions[i + 1];
20156
+ if (start !== void 0 && end !== void 0) inlineCodeRanges.push({
20088
20157
  start,
20089
- end
20158
+ end: end + 1
20090
20159
  });
20091
20160
  }
20092
20161
  }
@@ -20095,8 +20164,8 @@ function fixFootnote(content$2) {
20095
20164
  const refPositions = [];
20096
20165
  let refMatch = footnoteRefPattern.exec(content$2);
20097
20166
  while (refMatch !== null) {
20098
- const absolutePos = refMatch.index;
20099
- const refText = refMatch[0];
20167
+ const absolutePos = refMatch.index ?? 0;
20168
+ const refText = refMatch[0] ?? "";
20100
20169
  const isInCodeBlock = codeBlockRanges.some((range) => absolutePos >= range.start && absolutePos < range.end);
20101
20170
  const isInInlineCode = inlineCodeRanges.some((range) => absolutePos >= range.start && absolutePos < range.end);
20102
20171
  const isInFootnoteDef = footnoteDefRanges.some((range) => absolutePos >= range.start && absolutePos < range.end);
@@ -20113,7 +20182,11 @@ function fixFootnote(content$2) {
20113
20182
  if (refPositions.length === 0) return content$2;
20114
20183
  for (let i = refPositions.length - 1; i >= 0; i--) {
20115
20184
  const ref$1 = refPositions[i];
20116
- if (!definedLabels.has(ref$1.label)) result = result.substring(0, ref$1.start) + result.substring(ref$1.end);
20185
+ if (ref$1 && !definedLabels.has(ref$1.label)) {
20186
+ let refStart = ref$1.start;
20187
+ if (refStart > 0 && result[refStart - 1] === " ") refStart--;
20188
+ result = result.substring(0, refStart) + result.substring(ref$1.end);
20189
+ }
20117
20190
  }
20118
20191
  return result;
20119
20192
  }
@@ -20149,15 +20222,11 @@ function fixFootnote(content$2) {
20149
20222
  * // Returns: '$$\n' (no completion, this is block math)
20150
20223
  */
20151
20224
  function fixInlineMath(content$2) {
20225
+ if (content$2 === "$") return "";
20152
20226
  const codeBlockMatches = content$2.match(tripleBacktickPattern);
20153
20227
  if ((codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1) return content$2;
20154
20228
  const lines = content$2.split("\n");
20155
- let paragraphStartIndex = 0;
20156
- for (let i = lines.length - 1; i >= 0; i--) if (lines[i].trim() === "") {
20157
- paragraphStartIndex = i + 1;
20158
- break;
20159
- }
20160
- const lastParagraph = lines.slice(paragraphStartIndex).join("\n");
20229
+ const { lastParagraph, startIndex: paragraphStartIndex } = getLastParagraphWithIndex(content$2);
20161
20230
  let withoutCodeBlocks = lastParagraph.replace(codeBlockPattern, "");
20162
20231
  withoutCodeBlocks = withoutCodeBlocks.replace(/`[^`\n]+`/g, "");
20163
20232
  const dollarMatches = withoutCodeBlocks.match(doubleDollarPattern);
@@ -20165,36 +20234,22 @@ function fixInlineMath(content$2) {
20165
20234
  const lastDollarPos = findLastDollarPairNotInCodeBlock(lastParagraph);
20166
20235
  if (lastDollarPos === -1) return content$2;
20167
20236
  let afterLast = lastParagraph.substring(lastDollarPos + 2);
20237
+ if (afterLast.startsWith("\n") || afterLast.includes("\n")) return content$2;
20168
20238
  if (afterLast.trim() === "$") return content$2;
20169
20239
  let shouldRemoveTrailingDollar = false;
20170
20240
  if (afterLast.endsWith("$") && !afterLast.endsWith("$$")) {
20171
20241
  shouldRemoveTrailingDollar = true;
20172
20242
  afterLast = afterLast.slice(0, -1);
20173
20243
  }
20174
- const hasContentAfter = (afterLast.split("\n")[0] ?? "").trim().length > 0;
20175
- const isBlockMathByAfter = !hasContentAfter && afterLast.startsWith("\n");
20176
- const linesInParagraph = lastParagraph.split("\n");
20177
- let lineWithDollar = "";
20178
- for (let i = linesInParagraph.length - 1; i >= 0; i--) {
20179
- const line = linesInParagraph[i];
20180
- if (line.includes("$$")) {
20181
- lineWithDollar = line;
20182
- break;
20183
- }
20184
- }
20185
- const isBlockMathByLine = lineWithDollar.replace(/\$\$/g, "").trim() === "" && afterLast.startsWith("\n");
20186
- if (isBlockMathByAfter || isBlockMathByLine) return content$2;
20187
- if (hasContentAfter) {
20244
+ if (afterLast.trim().length > 0) {
20188
20245
  if (shouldRemoveTrailingDollar) {
20189
- const beforeLastParagraph = lines.slice(0, paragraphStartIndex).join("\n");
20190
- const actualLastDollarPos = (beforeLastParagraph.length > 0 ? beforeLastParagraph.length + 1 : 0) + lastDollarPos;
20246
+ const actualLastDollarPos = calculateParagraphOffset(paragraphStartIndex, lines) + lastDollarPos;
20191
20247
  return `${content$2.substring(0, actualLastDollarPos + 2)}${lastParagraph.substring(lastDollarPos + 2, lastParagraph.length - 1)}$$`;
20192
20248
  }
20193
20249
  return `${content$2}$$`;
20194
20250
  } else {
20195
- const beforeLastParagraph = lines.slice(0, paragraphStartIndex).join("\n");
20196
- const actualLastDollarPos = (beforeLastParagraph.length > 0 ? beforeLastParagraph.length + 1 : 0) + lastDollarPos;
20197
- return content$2.slice(0, actualLastDollarPos) + content$2.slice(actualLastDollarPos + 2);
20251
+ const actualLastDollarPos = calculateParagraphOffset(paragraphStartIndex, lines) + lastDollarPos;
20252
+ return content$2.slice(0, actualLastDollarPos).trimEnd();
20198
20253
  }
20199
20254
  }
20200
20255
  return content$2;
@@ -20275,36 +20330,87 @@ function findLastDollarPairNotInCodeBlock(text$4) {
20275
20330
  * // Removes trailing standalone bracket and trailing newline
20276
20331
  */
20277
20332
  function fixLink(content$2) {
20278
- var _lines$lastNonEmptyLi;
20333
+ const codeBlockMatches = content$2.match(tripleBacktickPattern);
20334
+ if ((codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1) return content$2;
20279
20335
  const lines = content$2.split("\n");
20280
- let paragraphStartIndex = 0;
20281
- for (let i = lines.length - 1; i >= 0; i--) if (lines[i].trim() === "") {
20282
- paragraphStartIndex = i + 1;
20283
- break;
20284
- }
20285
- const lastParagraph = lines.slice(paragraphStartIndex).join("\n");
20286
- let lastNonEmptyLineIndex = lines.length - 1;
20287
- while (lastNonEmptyLineIndex >= 0 && ((_lines$lastNonEmptyLi = lines[lastNonEmptyLineIndex]) === null || _lines$lastNonEmptyLi === void 0 ? void 0 : _lines$lastNonEmptyLi.trim()) === "") lastNonEmptyLineIndex--;
20336
+ const { lastParagraph } = getLastParagraphWithIndex(content$2);
20337
+ const lastParagraphWithoutCodeBlocks = lastParagraph.replace(codeBlockPattern, "");
20338
+ const lastNonEmptyLineIndex = findLastNonEmptyLineIndex(lines);
20288
20339
  if (lastNonEmptyLineIndex >= 0) {
20289
20340
  const lastLine = lines[lastNonEmptyLineIndex];
20290
- if (trailingStandaloneBracketPattern.test(lastLine)) {
20291
- const bracketMatch = lastLine.match(trailingStandaloneBracketPattern);
20292
- if (bracketMatch) {
20293
- const bracket = bracketMatch[1];
20294
- const bracketPos = lastLine.lastIndexOf(bracket);
20295
- if (lastLine.substring(bracketPos + bracket.length).trim().length === 0) {
20296
- const newLine = lastLine.substring(0, bracketPos);
20297
- const newLines = [...lines];
20298
- newLines[lastNonEmptyLineIndex] = newLine;
20299
- if (lastNonEmptyLineIndex + 1 < newLines.length && newLines[lastNonEmptyLineIndex + 1].trim() === "") newLines.splice(lastNonEmptyLineIndex + 1, 1);
20300
- return newLines.join("\n");
20341
+ if (!lastLine) return content$2;
20342
+ const standaloneBracketMatch = lastLine.match(/(!?\[)\s*$/);
20343
+ if (standaloneBracketMatch && standaloneBracketMatch[1]) {
20344
+ const bracket = standaloneBracketMatch[1];
20345
+ const bracketPos = lastLine.lastIndexOf(bracket);
20346
+ if (lastLine.substring(bracketPos + bracket.length).trim().length === 0) {
20347
+ const newLine = lastLine.substring(0, bracketPos).trimEnd();
20348
+ const newLines = [...lines];
20349
+ newLines[lastNonEmptyLineIndex] = newLine;
20350
+ if (lastNonEmptyLineIndex + 1 < newLines.length) {
20351
+ const nextLine = newLines[lastNonEmptyLineIndex + 1];
20352
+ if (nextLine !== void 0 && nextLine.trim() === "") newLines.splice(lastNonEmptyLineIndex + 1, 1);
20301
20353
  }
20354
+ return newLines.join("\n");
20302
20355
  }
20303
20356
  }
20304
20357
  }
20305
- if (incompleteBracketPattern.test(lastParagraph)) return `${content$2}]()`;
20306
- if (incompleteLinkTextPattern.test(lastParagraph)) return `${content$2}()`;
20307
- if (incompleteUrlPattern.test(lastParagraph)) return `${content$2})`;
20358
+ if (incompleteBracketPattern.test(lastParagraphWithoutCodeBlocks)) return `${content$2}]()`;
20359
+ if (incompleteLinkTextPattern.test(lastParagraphWithoutCodeBlocks)) return `${content$2}()`;
20360
+ if (incompleteUrlPattern.test(lastParagraphWithoutCodeBlocks)) return `${content$2})`;
20361
+ return content$2;
20362
+ }
20363
+
20364
+ //#endregion
20365
+ //#region src/preprocess/math.ts
20366
+ /**
20367
+ * Fix unclosed block math ($$) syntax in streaming markdown
20368
+ *
20369
+ * Block math is defined as $$ delimiters on separate lines:
20370
+ * $$
20371
+ * E = mc^2
20372
+ * $$
20373
+ *
20374
+ * This function processes the entire content (not just last paragraph)
20375
+ * because block math can span multiple paragraphs.
20376
+ *
20377
+ * @param content - Markdown content (potentially incomplete in stream mode)
20378
+ * @returns Content with auto-completed block math if needed
20379
+ *
20380
+ * @example
20381
+ * fixMath('$$\nE = mc^2')
20382
+ * // Returns: '$$\nE = mc^2\n$$'
20383
+ *
20384
+ * @example
20385
+ * fixMath('$$\nE = mc^2\n$$')
20386
+ * // Returns: '$$\nE = mc^2\n$$' (no change)
20387
+ */
20388
+ function fixMath(content$2) {
20389
+ const codeBlockMatches = content$2.match(tripleBacktickPattern);
20390
+ if ((codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1) return content$2;
20391
+ const lines = content$2.split("\n");
20392
+ let inCodeBlock = false;
20393
+ const blockMathDelimiters = [];
20394
+ for (let i = 0; i < lines.length; i++) {
20395
+ const line = lines[i] ?? "";
20396
+ if (line.trim().startsWith("```")) {
20397
+ inCodeBlock = !inCodeBlock;
20398
+ continue;
20399
+ }
20400
+ if (inCodeBlock) continue;
20401
+ if (line.trim() === "$$") blockMathDelimiters.push(i);
20402
+ }
20403
+ if (blockMathDelimiters.length % 2 === 1) {
20404
+ const lastDelimiterIndex = blockMathDelimiters[blockMathDelimiters.length - 1] ?? -1;
20405
+ if (lastDelimiterIndex === -1) return content$2;
20406
+ if (lines.slice(lastDelimiterIndex + 1).some((line) => {
20407
+ const trimmed = line.trim();
20408
+ return trimmed.length > 0 && trimmed !== "$$";
20409
+ })) {
20410
+ if (!content$2.endsWith("\n")) return `${content$2}\n$$`;
20411
+ return `${content$2}$$`;
20412
+ } else return lines.slice(0, lastDelimiterIndex).join("\n");
20413
+ }
20308
20414
  return content$2;
20309
20415
  }
20310
20416
 
@@ -20336,32 +20442,96 @@ function fixLink(content$2) {
20336
20442
  * // Returns: 'List item\n\n**' (no completion, ** has no content)
20337
20443
  */
20338
20444
  function fixStrong(content$2) {
20339
- const lines = content$2.split("\n");
20340
- let paragraphStartIndex = 0;
20341
- for (let i = lines.length - 1; i >= 0; i--) if (lines[i].trim() === "") {
20342
- paragraphStartIndex = i + 1;
20343
- break;
20445
+ if (content$2 === "*" || content$2 === "_") return "";
20446
+ const codeBlockMatches = content$2.match(tripleBacktickPattern);
20447
+ if ((codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1) return content$2;
20448
+ const { lastParagraph } = getLastParagraphWithIndex(content$2);
20449
+ const lastParagraphWithoutCodeBlocks = lastParagraph.replace(codeBlockPattern, "");
20450
+ const endsWithSingleAsterisk = content$2.endsWith("*") && !content$2.endsWith("**");
20451
+ const endsWithSingleUnderscore = content$2.endsWith("_") && !content$2.endsWith("__");
20452
+ const asteriskMatches = lastParagraphWithoutCodeBlocks.match(doubleAsteriskPattern);
20453
+ const asteriskCount = asteriskMatches ? asteriskMatches.length : 0;
20454
+ const underscoreMatches = lastParagraphWithoutCodeBlocks.match(doubleUnderscorePattern);
20455
+ const underscoreCount = underscoreMatches ? underscoreMatches.length : 0;
20456
+ let needsAsteriskCompletion = false;
20457
+ let needsUnderscoreCompletion = false;
20458
+ let needsAsteriskRemoval = false;
20459
+ let needsUnderscoreRemoval = false;
20460
+ if (asteriskCount % 2 === 1) {
20461
+ const lastStarPos = lastParagraphWithoutCodeBlocks.lastIndexOf("**");
20462
+ if (lastParagraphWithoutCodeBlocks.substring(lastStarPos + 2).trim().length > 0) needsAsteriskCompletion = true;
20463
+ else needsAsteriskRemoval = true;
20464
+ }
20465
+ if (underscoreCount % 2 === 1) {
20466
+ const lastUnderscorePos = lastParagraphWithoutCodeBlocks.lastIndexOf("__");
20467
+ if (lastParagraphWithoutCodeBlocks.substring(lastUnderscorePos + 2).trim().length > 0) needsUnderscoreCompletion = true;
20468
+ else needsUnderscoreRemoval = true;
20469
+ }
20470
+ let removedTrailingSingle = false;
20471
+ if (endsWithSingleAsterisk && (needsAsteriskCompletion || needsAsteriskRemoval)) {
20472
+ content$2 = content$2.slice(0, -1);
20473
+ removedTrailingSingle = true;
20474
+ const { lastParagraph: newLastParagraph } = getLastParagraphWithIndex(content$2);
20475
+ const newLastParagraphWithoutCodeBlocks = newLastParagraph.replace(codeBlockPattern, "");
20476
+ const newAsteriskMatches = newLastParagraphWithoutCodeBlocks.match(doubleAsteriskPattern);
20477
+ if ((newAsteriskMatches ? newAsteriskMatches.length : 0) % 2 === 1) {
20478
+ const lastStarPos = newLastParagraphWithoutCodeBlocks.lastIndexOf("**");
20479
+ if (newLastParagraphWithoutCodeBlocks.substring(lastStarPos + 2).trim().length > 0) {
20480
+ needsAsteriskCompletion = true;
20481
+ needsAsteriskRemoval = false;
20482
+ } else {
20483
+ needsAsteriskRemoval = true;
20484
+ needsAsteriskCompletion = false;
20485
+ }
20486
+ }
20344
20487
  }
20345
- const lastParagraph = lines.slice(paragraphStartIndex).join("\n");
20346
- const asteriskMatches = lastParagraph.match(doubleAsteriskPattern);
20347
- if ((asteriskMatches ? asteriskMatches.length : 0) % 2 === 1) {
20348
- const lastStarPos = lastParagraph.lastIndexOf("**");
20349
- if (lastParagraph.substring(lastStarPos + 2).trim().length > 0) return `${content$2}**`;
20350
- else {
20351
- let result = content$2.slice(0, -2);
20352
- if (trailingStandaloneDashWithNewlinesPattern.test(result)) result = result.replace(trailingStandaloneDashWithNewlinesPattern, "$1");
20353
- return result;
20488
+ if (endsWithSingleUnderscore && (needsUnderscoreCompletion || needsUnderscoreRemoval)) {
20489
+ content$2 = content$2.slice(0, -1);
20490
+ removedTrailingSingle = true;
20491
+ const { lastParagraph: newLastParagraph } = getLastParagraphWithIndex(content$2);
20492
+ const newLastParagraphWithoutCodeBlocks = newLastParagraph.replace(codeBlockPattern, "");
20493
+ const newUnderscoreMatches = newLastParagraphWithoutCodeBlocks.match(doubleUnderscorePattern);
20494
+ if ((newUnderscoreMatches ? newUnderscoreMatches.length : 0) % 2 === 1) {
20495
+ const lastUnderscorePos = newLastParagraphWithoutCodeBlocks.lastIndexOf("__");
20496
+ if (newLastParagraphWithoutCodeBlocks.substring(lastUnderscorePos + 2).trim().length > 0) {
20497
+ needsUnderscoreCompletion = true;
20498
+ needsUnderscoreRemoval = false;
20499
+ } else {
20500
+ needsUnderscoreRemoval = true;
20501
+ needsUnderscoreCompletion = false;
20502
+ }
20354
20503
  }
20355
20504
  }
20356
- const underscoreMatches = lastParagraph.match(doubleUnderscorePattern);
20357
- if ((underscoreMatches ? underscoreMatches.length : 0) % 2 === 1) {
20358
- const lastUnderscorePos = lastParagraph.lastIndexOf("__");
20359
- if (lastParagraph.substring(lastUnderscorePos + 2).trim().length > 0) return `${content$2}__`;
20360
- else {
20361
- let result = content$2.slice(0, -2);
20362
- if (trailingStandaloneDashWithNewlinesPattern.test(result)) result = result.replace(trailingStandaloneDashWithNewlinesPattern, "$1");
20363
- return result;
20505
+ if (needsAsteriskRemoval) {
20506
+ let result = content$2.slice(0, -2).trimEnd();
20507
+ if (trailingStandaloneDashWithNewlinesPattern.test(result)) result = result.replace(trailingStandaloneDashWithNewlinesPattern, "$1");
20508
+ return result;
20509
+ }
20510
+ if (needsUnderscoreRemoval) {
20511
+ const { lastParagraph: newLastParagraph, startIndex: newParagraphStartIndex } = getLastParagraphWithIndex(content$2);
20512
+ const lastUnderscorePos = newLastParagraph.lastIndexOf("__");
20513
+ const absoluteLastUnderscorePos = calculateParagraphOffset(newParagraphStartIndex, content$2.split("\n")) + lastUnderscorePos;
20514
+ let result = content$2.substring(0, absoluteLastUnderscorePos).trimEnd();
20515
+ if (trailingStandaloneDashWithNewlinesPattern.test(result)) result = result.replace(trailingStandaloneDashWithNewlinesPattern, "$1");
20516
+ return result;
20517
+ }
20518
+ if (needsAsteriskCompletion && needsUnderscoreCompletion) if (lastParagraphWithoutCodeBlocks.indexOf("**") < lastParagraphWithoutCodeBlocks.indexOf("__")) return `${content$2}__**`;
20519
+ else return `${content$2}**__`;
20520
+ if (needsAsteriskCompletion) {
20521
+ if (!removedTrailingSingle) {
20522
+ const { lastParagraph: currentLastParagraph } = getLastParagraphWithIndex(content$2);
20523
+ const singleAsteriskMatches = currentLastParagraph.replace(codeBlockPattern, "").replace(doubleAsteriskPattern, "").match(singleAsteriskPattern);
20524
+ if ((singleAsteriskMatches ? singleAsteriskMatches.length : 0) % 2 === 1) return `${content$2}***`;
20525
+ }
20526
+ return `${content$2}**`;
20527
+ }
20528
+ if (needsUnderscoreCompletion) {
20529
+ if (!removedTrailingSingle) {
20530
+ const { lastParagraph: currentLastParagraph } = getLastParagraphWithIndex(content$2);
20531
+ const singleUnderscoreMatches = currentLastParagraph.replace(codeBlockPattern, "").replace(doubleUnderscorePattern, "").match(singleUnderscorePattern);
20532
+ if ((singleUnderscoreMatches ? singleUnderscoreMatches.length : 0) % 2 === 1) return `${content$2}___`;
20364
20533
  }
20534
+ return `${content$2}__`;
20365
20535
  }
20366
20536
  return content$2;
20367
20537
  }
@@ -20397,29 +20567,40 @@ function fixStrong(content$2) {
20397
20567
  function fixTable(content$2) {
20398
20568
  const codeBlockMatches = content$2.match(tripleBacktickPattern);
20399
20569
  if ((codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1) return content$2;
20400
- const lines = content$2.split("\n");
20401
- let paragraphStartIndex = 0;
20402
- for (let i = lines.length - 1; i >= 0; i--) {
20403
- const line = lines[i];
20404
- if (i === lines.length - 1 && line.trim() === "") continue;
20405
- if (line.trim() === "") {
20406
- paragraphStartIndex = i + 1;
20407
- break;
20408
- }
20570
+ const codeBlockRanges = [];
20571
+ let searchStart = 0;
20572
+ while (true) {
20573
+ const codeBlockStart = content$2.indexOf("```", searchStart);
20574
+ if (codeBlockStart === -1) break;
20575
+ const codeBlockEnd = content$2.indexOf("```", codeBlockStart + 3);
20576
+ if (codeBlockEnd === -1) break;
20577
+ codeBlockRanges.push({
20578
+ start: codeBlockStart,
20579
+ end: codeBlockEnd + 3
20580
+ });
20581
+ searchStart = codeBlockEnd + 3;
20409
20582
  }
20410
- const paragraphLines = lines.slice(paragraphStartIndex).join("\n").split("\n").filter((line) => line.trim() !== "");
20583
+ const { lastParagraph } = getLastParagraphWithIndex(content$2, true);
20584
+ const paragraphLines = lastParagraph.split("\n").filter((line) => line.trim() !== "");
20411
20585
  if (paragraphLines.length === 0) return content$2;
20412
20586
  let headerRowIndex = -1;
20413
20587
  let headerRow = "";
20414
20588
  for (let i = 0; i < paragraphLines.length; i++) {
20415
- const line = paragraphLines[i].trim();
20416
- if (tableRowPattern.test(line) || line.startsWith("|") && line.length > 1) {
20589
+ const line = paragraphLines[i];
20590
+ if (!line) continue;
20591
+ const trimmedLine = line.trim();
20592
+ if (tableRowPattern.test(trimmedLine) || trimmedLine.startsWith("|") && trimmedLine.length > 1) {
20417
20593
  headerRowIndex = i;
20418
- headerRow = line;
20594
+ headerRow = trimmedLine;
20419
20595
  break;
20420
20596
  }
20421
20597
  }
20422
20598
  if (headerRowIndex === -1) return content$2;
20599
+ const headerRowPos = content$2.lastIndexOf(headerRow);
20600
+ if (headerRowPos !== -1) {
20601
+ const headerRowEndPos = headerRowPos + headerRow.length;
20602
+ if (codeBlockRanges.some((range) => headerRowPos >= range.start && headerRowPos < range.end || headerRowEndPos > range.start && headerRowEndPos <= range.end || headerRowPos < range.start && headerRowEndPos > range.end)) return content$2;
20603
+ }
20423
20604
  const trimmedHeader = headerRow.trim();
20424
20605
  const isHeaderComplete = trimmedHeader.endsWith("|");
20425
20606
  let completedHeaderRow = headerRow;
@@ -20427,7 +20608,6 @@ function fixTable(content$2) {
20427
20608
  const headerColumns = (completedHeaderRow.match(/\|/g) || []).length - 1;
20428
20609
  if (headerColumns < 1) return content$2;
20429
20610
  const separator = generateSeparator(headerColumns);
20430
- const headerRowPos = content$2.lastIndexOf(headerRow);
20431
20611
  const beforeHeaderRow = content$2.substring(0, headerRowPos);
20432
20612
  const afterHeaderRow = content$2.substring(headerRowPos + headerRow.length);
20433
20613
  if (headerRowIndex === paragraphLines.length - 1) {
@@ -20435,7 +20615,9 @@ function fixTable(content$2) {
20435
20615
  if (newContent.endsWith("\n")) return `${newContent}${separator}`;
20436
20616
  else return `${newContent}\n${separator}`;
20437
20617
  }
20438
- const nextLine = paragraphLines[headerRowIndex + 1].trim();
20618
+ const nextLineRaw = paragraphLines[headerRowIndex + 1];
20619
+ if (!nextLineRaw) return content$2;
20620
+ const nextLine = nextLineRaw.trim();
20439
20621
  if (separatorPattern.test(nextLine)) {
20440
20622
  if ((nextLine.match(/\|/g) || []).length - 1 === headerColumns) {
20441
20623
  if (!isHeaderComplete) return `${beforeHeaderRow}${completedHeaderRow}${afterHeaderRow}`;
@@ -20445,6 +20627,7 @@ function fixTable(content$2) {
20445
20627
  const afterLines = afterHeaderRow.split("\n");
20446
20628
  if (afterLines.length > 1) {
20447
20629
  const nextLineInContent = afterLines[1];
20630
+ if (!nextLineInContent) return content$2;
20448
20631
  if (nextLineInContent.startsWith("|") && nextLineInContent.includes("-")) {
20449
20632
  const remainingLines = afterLines.slice(2).join("\n");
20450
20633
  const newHeader = isHeaderComplete ? headerRow : completedHeaderRow;
@@ -20497,29 +20680,37 @@ function generateSeparator(columns) {
20497
20680
  * // Returns: '> **Note**: Here\'s a quote with tasks:\n\n'
20498
20681
  */
20499
20682
  function fixTaskList(content$2) {
20683
+ const codeBlockMatches = content$2.match(tripleBacktickPattern);
20684
+ if ((codeBlockMatches ? codeBlockMatches.length : 0) % 2 === 1) return content$2;
20685
+ const codeBlockRanges = [];
20686
+ let searchStart = 0;
20687
+ while (true) {
20688
+ const codeBlockStart = content$2.indexOf("```", searchStart);
20689
+ if (codeBlockStart === -1) break;
20690
+ const codeBlockEnd = content$2.indexOf("```", codeBlockStart + 3);
20691
+ if (codeBlockEnd === -1) break;
20692
+ codeBlockRanges.push({
20693
+ start: codeBlockStart,
20694
+ end: codeBlockEnd + 3
20695
+ });
20696
+ searchStart = codeBlockEnd + 3;
20697
+ }
20500
20698
  const lines = content$2.split("\n");
20501
20699
  if (lines.length === 0) return content$2;
20502
20700
  const lastLine = lines[lines.length - 1];
20503
- if (quoteIncompleteTaskListPattern.test(lastLine)) {
20504
- const result = lines.slice(0, -1).join("\n");
20505
- if (lines.length > 1) return `${result}\n`;
20506
- return result;
20507
- }
20508
- if (quoteStandaloneDashPattern.test(lastLine) && !quoteTaskListPattern.test(lastLine)) {
20509
- const result = lines.slice(0, -1).join("\n");
20510
- if (lines.length > 1) return `${result}\n`;
20511
- return result;
20512
- }
20513
- if (incompleteTaskListPattern.test(lastLine)) {
20514
- const result = lines.slice(0, -1).join("\n");
20515
- if (lines.length > 1) return `${result}\n`;
20516
- return result;
20517
- }
20518
- if (standaloneDashPattern.test(lastLine) && !taskListPattern.test(lastLine)) {
20519
- const result = lines.slice(0, -1).join("\n");
20520
- if (lines.length > 1) return `${result}\n`;
20521
- return result;
20522
- }
20701
+ if (!lastLine) return content$2;
20702
+ let lastLineStartPos = 0;
20703
+ for (let i = 0; i < lines.length - 1; i++) {
20704
+ const line = lines[i];
20705
+ if (line !== void 0) lastLineStartPos += line.length + 1;
20706
+ }
20707
+ const lastLineEndPos = lastLineStartPos + lastLine.length;
20708
+ if (codeBlockRanges.some((range) => lastLineStartPos >= range.start && lastLineStartPos < range.end || lastLineEndPos > range.start && lastLineEndPos <= range.end || lastLineStartPos < range.start && lastLineEndPos > range.end)) return content$2;
20709
+ if (quoteIncompleteTaskListPattern.test(lastLine)) return lines.slice(0, -1).join("\n");
20710
+ if (quoteStandaloneDashPattern.test(lastLine) && !quoteTaskListPattern.test(lastLine)) return lines.slice(0, -1).join("\n");
20711
+ if (incompleteTaskListPattern.test(lastLine)) return lines.slice(0, -1).join("\n");
20712
+ if (standaloneDashPattern.test(lastLine) && !taskListPattern.test(lastLine)) return lines.slice(0, -1).join("\n");
20713
+ if (/^\s*-\s+$/.test(lastLine) && !taskListPattern.test(lastLine)) return lines.slice(0, -1).join("\n");
20523
20714
  return content$2;
20524
20715
  }
20525
20716
 
@@ -20554,16 +20745,16 @@ function normalize(content$2) {
20554
20745
  }
20555
20746
  function preprocess(content$2) {
20556
20747
  return flow([
20748
+ fixCode,
20557
20749
  fixFootnote,
20558
20750
  fixStrong,
20559
20751
  fixEmphasis,
20560
20752
  fixDelete,
20561
- fixCode,
20562
20753
  fixTaskList,
20563
20754
  fixLink,
20564
20755
  fixTable,
20565
20756
  fixInlineMath,
20566
- remend
20757
+ fixMath
20567
20758
  ])(content$2);
20568
20759
  }
20569
20760
 
@@ -20571,16 +20762,12 @@ function preprocess(content$2) {
20571
20762
  //#region src/markdown-parser.ts
20572
20763
  var MarkdownParser = class {
20573
20764
  constructor(options) {
20574
- var _this$options$extendM, _this$options;
20575
20765
  _defineProperty(this, "mode", "streaming");
20576
- _defineProperty(this, "md", void 0);
20577
20766
  _defineProperty(this, "content", "");
20578
20767
  _defineProperty(this, "syntaxTree", null);
20579
20768
  _defineProperty(this, "options", void 0);
20580
20769
  this.mode = options.mode;
20581
20770
  this.options = options;
20582
- this.md = new MarkdownItAsync();
20583
- (_this$options$extendM = (_this$options = this.options).extendMarkdownIt) === null || _this$options$extendM === void 0 || _this$options$extendM.call(_this$options, this.md);
20584
20771
  }
20585
20772
  update(data) {
20586
20773
  data = (this.options.normalize ?? normalize)(data);
@@ -20606,9 +20793,6 @@ var MarkdownParser = class {
20606
20793
  nodes: this.syntaxTree.children
20607
20794
  };
20608
20795
  }
20609
- markdownToHtml(content$2) {
20610
- return this.md.render(content$2);
20611
- }
20612
20796
  markdownToAst(content$2, loading = false) {
20613
20797
  var _this$options$mdastOp, _this$options$mdastOp2;
20614
20798
  const data = fromMarkdown(content$2, {
@@ -20701,6 +20885,10 @@ var index_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
20701
20885
  required: false,
20702
20886
  default: void 0
20703
20887
  },
20888
+ beforeDownload: {
20889
+ type: Function,
20890
+ required: false
20891
+ },
20704
20892
  controls: {
20705
20893
  type: [Boolean, Object],
20706
20894
  required: false,
@@ -20735,6 +20923,10 @@ var index_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
20735
20923
  type: Object,
20736
20924
  required: false
20737
20925
  },
20926
+ uiOptions: {
20927
+ type: Object,
20928
+ required: false
20929
+ },
20738
20930
  isDark: {
20739
20931
  type: Boolean,
20740
20932
  required: false,
@@ -20759,26 +20951,16 @@ var index_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
20759
20951
  postprocess: {
20760
20952
  type: Function,
20761
20953
  required: false
20762
- },
20763
- extendMarkdownIt: {
20764
- type: Function,
20765
- required: false
20766
20954
  }
20767
20955
  },
20768
20956
  emits: ["copied"],
20769
20957
  setup(__props, { expose: __expose, emit: __emit }) {
20770
20958
  const props = __props;
20771
20959
  const emits = __emit;
20772
- const { mode, shikiOptions, mermaidOptions, isDark, enableAnimate } = toRefs(props);
20960
+ const { mode, shikiOptions, mermaidOptions, uiOptions, isDark, enableAnimate } = toRefs(props);
20773
20961
  const containerRef = ref();
20774
20962
  const { provideContext } = useContext();
20775
- const markdownParser = new MarkdownParser({
20776
- mode: props.mode,
20777
- mdastOptions: props.mdastOptions,
20778
- postprocess: props.postprocess,
20779
- preprocess: props.preprocess,
20780
- normalize: props.normalize
20781
- });
20963
+ const markdownParser = new MarkdownParser(props);
20782
20964
  const processed = computed(() => markdownParser.parseMarkdown(props.content));
20783
20965
  const parsedNodes = computed(() => processed.value.nodes);
20784
20966
  const processedContent = computed(() => processed.value.content);
@@ -20797,10 +20979,29 @@ var index_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
20797
20979
  function getContainer() {
20798
20980
  return containerRef.value;
20799
20981
  }
20982
+ function getOverlayContainer() {
20983
+ return document.querySelector("#stream-markdown-overlay");
20984
+ }
20800
20985
  const { preload: preloadShiki, dispose: disposeShiki } = useShiki({ shikiOptions });
20801
20986
  const { preload: preloadMermaid, dispose: disposeMermaid } = useMermaid({ mermaidOptions });
20802
20987
  const { preload: preloadKatex, dispose: disposeKatex } = useKatex();
20988
+ function ensureOverlayContainer() {
20989
+ if (!getOverlayContainer()) {
20990
+ const div = document.createElement("div");
20991
+ div.id = "stream-markdown-overlay";
20992
+ div.classList.add("stream-markdown-overlay");
20993
+ div.classList.add(isDark.value ? "dark" : "light");
20994
+ document.body.appendChild(div);
20995
+ }
20996
+ }
20997
+ function updateOverlayContainerTheme() {
20998
+ const overlayContainer = getOverlayContainer();
20999
+ if (!overlayContainer) return;
21000
+ overlayContainer.classList.toggle("dark", isDark.value);
21001
+ overlayContainer.classList.toggle("light", !isDark.value);
21002
+ }
20803
21003
  async function bootstrap() {
21004
+ ensureOverlayContainer();
20804
21005
  const tasks = [
20805
21006
  preloadShiki(),
20806
21007
  preloadMermaid(),
@@ -20814,13 +21015,17 @@ var index_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
20814
21015
  onMounted(bootstrap);
20815
21016
  watch(() => props.mode, () => markdownParser.updateMode(props.mode));
20816
21017
  watch(() => props.locale, () => loadLocaleMessages(props.locale));
21018
+ watch(() => props.isDark, () => updateOverlayContainerTheme());
20817
21019
  provideContext({
20818
21020
  mode,
20819
21021
  icons,
21022
+ uiOptions,
20820
21023
  isDark,
20821
21024
  enableAnimate,
20822
21025
  parsedNodes,
20823
21026
  getContainer,
21027
+ getOverlayContainer,
21028
+ beforeDownload: props.beforeDownload,
20824
21029
  onCopied: (content$2) => {
20825
21030
  emits("copied", content$2);
20826
21031
  }
@@ -20859,4 +21064,4 @@ var index_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCo
20859
21064
  var src_default = index_vue_vue_type_script_setup_true_lang_default;
20860
21065
 
20861
21066
  //#endregion
20862
- export { CODE_PREVIEWERS, DEFAULT_DARK_THEME, DEFAULT_HARDEN_OPTIONS, DEFAULT_LIGHT_THEME, ICONS, LANGUAGE_ALIAS, LANGUAGE_EXTENSIONS, LANGUAGE_ICONS, src_default as Markdown, MarkdownParser, NODE_RENDERERS, PRELOAD_NODE_RENDERER, SHADCN_SCHEMAS, SUPPORT_LANGUAGES, UI, codeBlockPattern, crlfPattern, currentLocale, doubleAsteriskPattern, doubleDollarPattern, doubleTildePattern, doubleUnderscorePattern, escapeMarkdownTableCell, extractTableDataFromElement, findLastLeafNode, findNodeParent, fixCode, fixDelete, fixEmphasis, fixFootnote, fixLink, fixStrong, fixTable, fixTaskList, flow, footnoteDefLabelPattern, footnoteDefLinePattern, footnoteDefPattern, footnoteRefLabelPattern, footnoteRefPattern, hasKatex, hasMermaid, hasShiki, incompleteBracketPattern, incompleteFootnoteRefPattern, incompleteLinkTextPattern, incompleteTaskListPattern, incompleteUrlPattern, isClient, isServer, loadLocaleMessages, localeMessages, localesGlob, normalize, postFixFootnote, postFixText, postNormalize, postprocess, preloadAsyncComponents, preprocess, preprocessLaTeX, proprocessContent, quoteIncompleteTaskListPattern, quoteStandaloneDashPattern, quoteTaskListPattern, remend, save, saveImage, separatorPattern, singleAsteriskPattern, singleBacktickPattern, singleUnderscorePattern, standaloneDashPattern, svgToPngBlob, tableDataToCSV, tableDataToMarkdown, tableDataToTSV, tableRowPattern, taskListPattern, trailingBackticksPattern, trailingStandaloneBracketPattern, trailingStandaloneDashWithNewlinesPattern, trailingWhitespacePattern, transformUrl, tripleBacktickPattern, useCodeOptions, useContext, useControls, useFloating, useI18n, useKatex, useMathRenderer, useMediumZoom, useMermaid, useSanitizers, useShiki, useTailwindV3Theme, useZoom };
21067
+ export { CODE_PREVIEWERS, DEFAULT_DARK_THEME, DEFAULT_HARDEN_OPTIONS, DEFAULT_LIGHT_THEME, ICONS, LANGUAGE_ALIAS, LANGUAGE_EXTENSIONS, LANGUAGE_ICONS, src_default as Markdown, MarkdownParser, NODE_RENDERERS, PRELOAD_NODE_RENDERER, SHADCN_SCHEMAS, SUPPORT_LANGUAGES, UI, codeBlockPattern, crlfPattern, currentLocale, doubleAsteriskPattern, doubleDollarPattern, doubleTildePattern, doubleUnderscorePattern, escapeMarkdownTableCell, extractTableDataFromElement, findLastLeafNode, findNodeParent, fixCode, fixDelete, fixEmphasis, fixFootnote, fixLink, fixMath, fixStrong, fixTable, fixTaskList, flow, footnoteDefLabelPattern, footnoteDefLinePattern, footnoteDefPattern, footnoteRefLabelPattern, footnoteRefPattern, hasKatex, hasMermaid, hasShiki, incompleteBracketPattern, incompleteFootnoteRefPattern, incompleteLinkTextPattern, incompleteTaskListPattern, incompleteUrlPattern, isClient, isServer, loadLocaleMessages, localeMessages, localesGlob, normalize, postFixFootnote, postFixText, postNormalize, postprocess, preloadAsyncComponents, preprocess, preprocessLaTeX, proprocessContent, quoteIncompleteTaskListPattern, quoteStandaloneDashPattern, quoteTaskListPattern, save, saveImage, separatorPattern, singleAsteriskPattern, singleBacktickPattern, singleUnderscorePattern, standaloneDashPattern, svgToPngBlob, tableDataToCSV, tableDataToMarkdown, tableDataToTSV, tableRowPattern, taskListPattern, trailingBackticksPattern, trailingStandaloneBracketPattern, trailingStandaloneDashWithNewlinesPattern, trailingWhitespacePattern, transformUrl, tripleBacktickPattern, useCodeOptions, useContext, useControls, useFloating, useI18n, useKatex, useMathRenderer, useMediumZoom, useMermaid, useSanitizers, useShiki, useTailwindV3Theme, useZoom };