@ai-matrx/rich-content 0.0.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (247) hide show
  1. package/CHANGELOG.md +72 -0
  2. package/LICENSE +1 -1
  3. package/README.md +58 -3
  4. package/dist/display/blocks/csv/CsvBlock.d.ts +10 -0
  5. package/dist/display/blocks/csv/CsvBlock.js +245 -0
  6. package/dist/display/blocks/table/parseMarkdownTable.d.ts +20 -0
  7. package/dist/display/blocks/table/parseMarkdownTable.js +35 -0
  8. package/dist/display/chat-markdown/citations/remarkMatrxCite.d.ts +33 -0
  9. package/dist/display/chat-markdown/citations/remarkMatrxCite.js +71 -0
  10. package/dist/display/chat-markdown/matrx-variables/remarkMatrxVariable.d.ts +29 -0
  11. package/dist/display/chat-markdown/matrx-variables/remarkMatrxVariable.js +71 -0
  12. package/dist/display/chat-markdown/page-break/remarkMatrxPageBreak.d.ts +55 -0
  13. package/dist/display/chat-markdown/page-break/remarkMatrxPageBreak.js +108 -0
  14. package/dist/display/chat-markdown/rehypeSafeRawHtml.d.ts +59 -0
  15. package/dist/display/chat-markdown/rehypeSafeRawHtml.js +140 -0
  16. package/dist/display/markdown-classification/processors/bock-processors/parse-markdown-table.d.ts +14 -0
  17. package/dist/display/markdown-classification/processors/bock-processors/parse-markdown-table.js +171 -0
  18. package/dist/display/markdown-classification/processors/types.d.ts +120 -0
  19. package/dist/display/markdown-classification/processors/types.js +10 -0
  20. package/dist/display/markdown-classification/processors/utils/client-blocks.d.ts +169 -0
  21. package/dist/display/markdown-classification/processors/utils/client-blocks.js +0 -0
  22. package/dist/display/markdown-classification/processors/utils/content-splitter-core.d.ts +223 -0
  23. package/dist/display/markdown-classification/processors/utils/content-splitter-core.js +1791 -0
  24. package/dist/display/markdown-classification/processors/utils/content-splitter-v2.d.ts +15 -0
  25. package/dist/display/markdown-classification/processors/utils/content-splitter-v2.js +19 -0
  26. package/dist/display/markdown-classification/processors/utils/expand-text-blocks.d.ts +9 -0
  27. package/dist/display/markdown-classification/processors/utils/expand-text-blocks.js +36 -0
  28. package/dist/display/markdown-classification/processors/utils/gfm-table-lines.d.ts +5 -0
  29. package/dist/display/markdown-classification/processors/utils/gfm-table-lines.js +40 -0
  30. package/dist/display/markdown-classification/processors/utils/gfm-table-vector-inputs.d.ts +16 -0
  31. package/dist/display/markdown-classification/processors/utils/gfm-table-vector-inputs.js +385 -0
  32. package/dist/display/markdown-classification/processors/utils/gfm-table-vectors.d.ts +43 -0
  33. package/dist/display/markdown-classification/processors/utils/gfm-table-vectors.js +33 -0
  34. package/dist/display/markdown-classification/processors/utils/table-data-parser.d.ts +9 -0
  35. package/dist/display/markdown-classification/processors/utils/table-data-parser.js +30 -0
  36. package/dist/display/markdown-classification/processors/utils/thinking-parser.d.ts +7 -0
  37. package/dist/display/markdown-classification/processors/utils/thinking-parser.js +70 -0
  38. package/dist/display/render-block.d.ts +23 -0
  39. package/dist/display/render-block.js +0 -0
  40. package/dist/display/themes.d.ts +1023 -0
  41. package/dist/display/themes.js +1105 -0
  42. package/dist/display/types.d.ts +32 -0
  43. package/dist/display/types.js +0 -0
  44. package/dist/host/ContentIrHostBoundary.d.ts +8 -0
  45. package/dist/host/ContentIrHostBoundary.js +15 -0
  46. package/dist/host/ErrorActions.d.ts +4 -0
  47. package/dist/host/ErrorActions.js +11 -0
  48. package/dist/host/NestedContent.d.ts +3 -0
  49. package/dist/host/NestedContent.js +12 -0
  50. package/dist/host/ResourcePeek.d.ts +6 -0
  51. package/dist/host/ResourcePeek.js +14 -0
  52. package/dist/host/component-registry.d.ts +2 -0
  53. package/dist/host/component-registry.js +25 -0
  54. package/dist/host/diagnostics.d.ts +2 -0
  55. package/dist/host/diagnostics.js +15 -0
  56. package/dist/host/index.d.ts +3 -0
  57. package/dist/host/index.js +18 -0
  58. package/dist/host/kind-incident.d.ts +3 -0
  59. package/dist/host/kind-incident.js +12 -0
  60. package/dist/host/kind-registry.d.ts +2 -0
  61. package/dist/host/kind-registry.js +35 -0
  62. package/dist/host/people.d.ts +3 -0
  63. package/dist/host/people.js +12 -0
  64. package/dist/host/registry.d.ts +27 -0
  65. package/dist/host/registry.js +55 -0
  66. package/dist/host/splitter-envelopes.d.ts +2 -0
  67. package/dist/host/splitter-envelopes.js +7 -0
  68. package/dist/host/tables.d.ts +6 -0
  69. package/dist/host/tables.js +8 -0
  70. package/dist/host/toast.d.ts +2 -0
  71. package/dist/host/toast.js +57 -0
  72. package/dist/host/types.d.ts +157 -0
  73. package/dist/host/types.js +0 -0
  74. package/dist/host/wikilinks.d.ts +15 -0
  75. package/dist/host/wikilinks.js +23 -0
  76. package/dist/kinds/host/route-env.d.ts +33 -0
  77. package/dist/kinds/host/route-env.js +16 -0
  78. package/dist/kinds/react/KindEscapedNotice.d.ts +14 -0
  79. package/dist/kinds/react/KindEscapedNotice.js +72 -0
  80. package/dist/kinds/react/ProvisionalKindBoundary.d.ts +19 -0
  81. package/dist/kinds/react/ProvisionalKindBoundary.js +17 -0
  82. package/dist/kinds/react/ensure-kind-renderable.d.ts +14 -0
  83. package/dist/kinds/react/ensure-kind-renderable.js +45 -0
  84. package/dist/kinds/react/kind-problems.d.ts +62 -0
  85. package/dist/kinds/react/kind-problems.js +134 -0
  86. package/dist/kinds/react/kind-route.d.ts +23 -0
  87. package/dist/kinds/react/kind-route.js +24 -0
  88. package/dist/kinds/react/loading/infer-loading-slug.d.ts +58 -0
  89. package/dist/kinds/react/loading/infer-loading-slug.js +100 -0
  90. package/dist/kinds/react/loading/kind-loading-components.d.ts +48 -0
  91. package/dist/kinds/react/loading/kind-loading-components.js +447 -0
  92. package/dist/kinds/react/loading/kind-loading-registry.d.ts +21 -0
  93. package/dist/kinds/react/loading/kind-loading-registry.js +62 -0
  94. package/dist/kinds/react/loading/kind-loading-slugs.d.ts +18 -0
  95. package/dist/kinds/react/loading/kind-loading-slugs.js +34 -0
  96. package/dist/kinds/react/loading/kind-loading.types.d.ts +79 -0
  97. package/dist/kinds/react/loading/kind-loading.types.js +31 -0
  98. package/dist/kinds/react/loading/resolve-loading-slug.d.ts +29 -0
  99. package/dist/kinds/react/loading/resolve-loading-slug.js +51 -0
  100. package/dist/kinds/react/partial-kind-route.d.ts +32 -0
  101. package/dist/kinds/react/partial-kind-route.js +27 -0
  102. package/dist/kinds/react/registry-versioned.d.ts +54 -0
  103. package/dist/kinds/react/registry-versioned.js +18 -0
  104. package/dist/kinds/react/route-at-version.d.ts +38 -0
  105. package/dist/kinds/react/route-at-version.js +78 -0
  106. package/dist/kinds/react/slot/KindSlot.d.ts +87 -0
  107. package/dist/kinds/react/slot/KindSlot.js +65 -0
  108. package/dist/kinds/react/use-registry-repaint.d.ts +6 -0
  109. package/dist/kinds/react/use-registry-repaint.js +36 -0
  110. package/dist/kinds/react/useIrNode.d.ts +9 -0
  111. package/dist/kinds/react/useIrNode.js +46 -0
  112. package/dist/kinds/react/useLiveJsonRegion.d.ts +15 -0
  113. package/dist/kinds/react/useLiveJsonRegion.js +84 -0
  114. package/dist/kinds/redux/render-block-envelope.d.ts +14 -0
  115. package/dist/kinds/redux/render-block-envelope.js +26 -0
  116. package/dist/kinds/registry/kind-correctors.d.ts +63 -0
  117. package/dist/kinds/registry/kind-correctors.js +94 -0
  118. package/dist/kinds/registry/legacy-quiz-envelope.d.ts +1 -0
  119. package/dist/kinds/registry/legacy-quiz-envelope.js +1 -0
  120. package/dist/kinds/registry/region-envelope-memo.d.ts +45 -0
  121. package/dist/kinds/registry/region-envelope-memo.js +94 -0
  122. package/dist/kinds/registry/registry-debug.d.ts +38 -0
  123. package/dist/kinds/registry/registry-debug.js +39 -0
  124. package/dist/markdown-core/MarkdownCore.d.ts +6 -0
  125. package/dist/markdown-core/MarkdownCore.js +32 -0
  126. package/dist/markdown-core/MarkdownCoreImpl.d.ts +3 -0
  127. package/dist/markdown-core/MarkdownCoreImpl.js +27 -0
  128. package/dist/markdown-core/MarkdownCoreServer.d.ts +4 -0
  129. package/dist/markdown-core/MarkdownCoreServer.js +26 -0
  130. package/dist/markdown-core/heading-anchors-context.d.ts +2 -0
  131. package/dist/markdown-core/heading-anchors-context.js +11 -0
  132. package/dist/markdown-core/heading-anchors-props.d.ts +2 -0
  133. package/dist/markdown-core/heading-anchors-props.js +6 -0
  134. package/dist/markdown-core/markdown-core-html.d.ts +3 -0
  135. package/dist/markdown-core/markdown-core-html.js +33 -0
  136. package/dist/markdown-core/markdown-core-presets.d.ts +22 -0
  137. package/dist/markdown-core/markdown-core-presets.js +118 -0
  138. package/dist/markdown-core/markdown-core-types.d.ts +43 -0
  139. package/dist/markdown-core/markdown-core-types.js +0 -0
  140. package/dist/markdown-core/math/vendor/micromark-math-math-flow.d.ts +15 -0
  141. package/dist/markdown-core/math/vendor/micromark-math-math-flow.js +143 -0
  142. package/dist/markdown-core/math/vendor/micromark-math-math-text.d.ts +24 -0
  143. package/dist/markdown-core/math/vendor/micromark-math-math-text.js +127 -0
  144. package/dist/markdown-core/math/vendor/micromark-math-syntax.d.ts +30 -0
  145. package/dist/markdown-core/math/vendor/micromark-math-syntax.js +15 -0
  146. package/dist/markdown-core/math/vendor/rehype-katex.d.ts +15 -0
  147. package/dist/markdown-core/math/vendor/rehype-katex.js +83 -0
  148. package/dist/markdown-core/math/vendor/remark-math.d.ts +9 -0
  149. package/dist/markdown-core/math/vendor/remark-math.js +20 -0
  150. package/dist/markdown-core/math-normalizer.d.ts +57 -0
  151. package/dist/markdown-core/math-normalizer.js +315 -0
  152. package/dist/markdown-core/plain-title.d.ts +2 -0
  153. package/dist/markdown-core/plain-title.js +1 -0
  154. package/dist/markdown-core/stream-heal.d.ts +2 -0
  155. package/dist/markdown-core/stream-heal.js +184 -0
  156. package/dist/markdown-core/streaming-context.d.ts +2 -0
  157. package/dist/markdown-core/streaming-context.js +11 -0
  158. package/dist/markdown-core/syntax/callout-types.d.ts +9 -0
  159. package/dist/markdown-core/syntax/callout-types.js +101 -0
  160. package/dist/markdown-core/syntax/containers.d.ts +17 -0
  161. package/dist/markdown-core/syntax/containers.js +353 -0
  162. package/dist/markdown-core/syntax/document-numbering.d.ts +52 -0
  163. package/dist/markdown-core/syntax/document-numbering.js +184 -0
  164. package/dist/markdown-core/syntax/elements/CalloutIcon.d.ts +3 -0
  165. package/dist/markdown-core/syntax/elements/CalloutIcon.js +41 -0
  166. package/dist/markdown-core/syntax/elements/CrossRef.d.ts +12 -0
  167. package/dist/markdown-core/syntax/elements/CrossRef.js +57 -0
  168. package/dist/markdown-core/syntax/elements/CsvFence.d.ts +4 -0
  169. package/dist/markdown-core/syntax/elements/CsvFence.js +18 -0
  170. package/dist/markdown-core/syntax/elements/DetailsElements.d.ts +12 -0
  171. package/dist/markdown-core/syntax/elements/DetailsElements.js +38 -0
  172. package/dist/markdown-core/syntax/elements/DocumentNumbering.d.ts +20 -0
  173. package/dist/markdown-core/syntax/elements/DocumentNumbering.js +37 -0
  174. package/dist/markdown-core/syntax/elements/DocumentPropertiesPanel.d.ts +4 -0
  175. package/dist/markdown-core/syntax/elements/DocumentPropertiesPanel.js +46 -0
  176. package/dist/markdown-core/syntax/elements/InDocAnchor.d.ts +11 -0
  177. package/dist/markdown-core/syntax/elements/InDocAnchor.js +87 -0
  178. package/dist/markdown-core/syntax/elements/MarkdownSourceEdit.d.ts +24 -0
  179. package/dist/markdown-core/syntax/elements/MarkdownSourceEdit.js +28 -0
  180. package/dist/markdown-core/syntax/elements/MatrxTabs.d.ts +10 -0
  181. package/dist/markdown-core/syntax/elements/MatrxTabs.js +59 -0
  182. package/dist/markdown-core/syntax/elements/MentionChip.d.ts +7 -0
  183. package/dist/markdown-core/syntax/elements/MentionChip.js +69 -0
  184. package/dist/markdown-core/syntax/elements/NestedBody.d.ts +3 -0
  185. package/dist/markdown-core/syntax/elements/NestedBody.js +13 -0
  186. package/dist/markdown-core/syntax/elements/TableOfContents.d.ts +5 -0
  187. package/dist/markdown-core/syntax/elements/TableOfContents.js +44 -0
  188. package/dist/markdown-core/syntax/elements/TaskCheckbox.d.ts +7 -0
  189. package/dist/markdown-core/syntax/elements/TaskCheckbox.js +63 -0
  190. package/dist/markdown-core/syntax/elements/WikiEmbed.d.ts +7 -0
  191. package/dist/markdown-core/syntax/elements/WikiEmbed.js +68 -0
  192. package/dist/markdown-core/syntax/elements/WikiLink.d.ts +10 -0
  193. package/dist/markdown-core/syntax/elements/WikiLink.js +114 -0
  194. package/dist/markdown-core/syntax/elements/core-syntax-elements.d.ts +22 -0
  195. package/dist/markdown-core/syntax/elements/core-syntax-elements.js +70 -0
  196. package/dist/markdown-core/syntax/elements/find-in-document.d.ts +3 -0
  197. package/dist/markdown-core/syntax/elements/find-in-document.js +20 -0
  198. package/dist/markdown-core/syntax/elements/wiki-target.d.ts +5 -0
  199. package/dist/markdown-core/syntax/elements/wiki-target.js +8 -0
  200. package/dist/markdown-core/syntax/frontmatter.d.ts +26 -0
  201. package/dist/markdown-core/syntax/frontmatter.js +72 -0
  202. package/dist/markdown-core/syntax/gfm-cell-pipes.d.ts +11 -0
  203. package/dist/markdown-core/syntax/gfm-cell-pipes.js +4 -0
  204. package/dist/markdown-core/syntax/inline-syntax.d.ts +26 -0
  205. package/dist/markdown-core/syntax/inline-syntax.js +163 -0
  206. package/dist/markdown-core/syntax/linear-scan.d.ts +46 -0
  207. package/dist/markdown-core/syntax/linear-scan.js +129 -0
  208. package/dist/markdown-core/syntax/mdast-helpers.d.ts +48 -0
  209. package/dist/markdown-core/syntax/mdast-helpers.js +48 -0
  210. package/dist/markdown-core/syntax/mentions.d.ts +2 -0
  211. package/dist/markdown-core/syntax/mentions.js +42 -0
  212. package/dist/markdown-core/syntax/names.d.ts +6 -0
  213. package/dist/markdown-core/syntax/names.js +18 -0
  214. package/dist/markdown-core/syntax/prepare-syntax-source.d.ts +1 -0
  215. package/dist/markdown-core/syntax/prepare-syntax-source.js +78 -0
  216. package/dist/markdown-core/syntax/rehype-matrx-syntax.d.ts +9 -0
  217. package/dist/markdown-core/syntax/rehype-matrx-syntax.js +180 -0
  218. package/dist/markdown-core/syntax/remark-inline-only.d.ts +23 -0
  219. package/dist/markdown-core/syntax/remark-inline-only.js +25 -0
  220. package/dist/markdown-core/syntax/remark-matrx-syntax.d.ts +7 -0
  221. package/dist/markdown-core/syntax/remark-matrx-syntax.js +351 -0
  222. package/dist/markdown-core/syntax/remark-table-code-pipes.d.ts +7 -0
  223. package/dist/markdown-core/syntax/remark-table-code-pipes.js +23 -0
  224. package/dist/markdown-core/syntax/stream-heal-syntax.d.ts +2 -0
  225. package/dist/markdown-core/syntax/stream-heal-syntax.js +108 -0
  226. package/dist/markdown-core/syntax/task-source.d.ts +10 -0
  227. package/dist/markdown-core/syntax/task-source.js +34 -0
  228. package/dist/markdown-core/syntax/useDocumentProperties.d.ts +3 -0
  229. package/dist/markdown-core/syntax/useDocumentProperties.js +8 -0
  230. package/dist/styles.css +0 -0
  231. package/dist/utils/addressWithoutNavigating.d.ts +68 -0
  232. package/dist/utils/addressWithoutNavigating.js +60 -0
  233. package/dist/utils/client-lazy.d.ts +13 -0
  234. package/dist/utils/client-lazy.js +24 -0
  235. package/dist/utils/decision-options.d.ts +21 -0
  236. package/dist/utils/decision-options.js +32 -0
  237. package/dist/utils/gfm-lexer.d.ts +5 -0
  238. package/dist/utils/gfm-lexer.js +10 -0
  239. package/dist/utils/json.d.ts +63 -0
  240. package/dist/utils/json.js +22 -0
  241. package/dist/utils/plain-title.d.ts +25 -0
  242. package/dist/utils/plain-title.js +51 -0
  243. package/dist/utils/table-source.d.ts +62 -0
  244. package/dist/utils/table-source.js +191 -0
  245. package/dist/utils/youtube.d.ts +52 -0
  246. package/dist/utils/youtube.js +137 -0
  247. package/package.json +132 -5
@@ -0,0 +1,9 @@
1
+ export declare const CALLOUT_TYPES: readonly ["note", "tip", "important", "warning", "caution", "info", "success", "question", "quote"];
2
+ export type CalloutType = (typeof CALLOUT_TYPES)[number];
3
+ export declare function resolveCalloutType(name: string | undefined | null): CalloutType | null;
4
+ export declare const CALLOUT_LABEL: Readonly<Record<CalloutType, string>>;
5
+ /** Frame (border + wash) and title colour per type — light and dark. */
6
+ export declare const CALLOUT_CLASSES: Readonly<Record<CalloutType, {
7
+ frame: string;
8
+ title: string;
9
+ }>>;
@@ -0,0 +1,101 @@
1
+ const CALLOUT_TYPES = [
2
+ "note",
3
+ "tip",
4
+ "important",
5
+ "warning",
6
+ "caution",
7
+ "info",
8
+ "success",
9
+ "question",
10
+ "quote"
11
+ ];
12
+ const ALIASES = {
13
+ note: "note",
14
+ seealso: "note",
15
+ example: "note",
16
+ tip: "tip",
17
+ hint: "tip",
18
+ important: "important",
19
+ warning: "warning",
20
+ warn: "warning",
21
+ attention: "warning",
22
+ caution: "caution",
23
+ danger: "caution",
24
+ error: "caution",
25
+ failure: "caution",
26
+ fail: "caution",
27
+ missing: "caution",
28
+ bug: "caution",
29
+ info: "info",
30
+ abstract: "info",
31
+ summary: "info",
32
+ tldr: "info",
33
+ todo: "info",
34
+ success: "success",
35
+ check: "success",
36
+ done: "success",
37
+ question: "question",
38
+ help: "question",
39
+ faq: "question",
40
+ quote: "quote",
41
+ cite: "quote"
42
+ };
43
+ function resolveCalloutType(name) {
44
+ if (!name) return null;
45
+ return ALIASES[name.trim().toLowerCase()] ?? null;
46
+ }
47
+ const CALLOUT_LABEL = {
48
+ note: "Note",
49
+ tip: "Tip",
50
+ important: "Important",
51
+ warning: "Warning",
52
+ caution: "Caution",
53
+ info: "Info",
54
+ success: "Success",
55
+ question: "Question",
56
+ quote: "Quote"
57
+ };
58
+ const CALLOUT_CLASSES = {
59
+ note: {
60
+ frame: "border-blue-500/70 bg-blue-500/5 dark:border-blue-400/70 dark:bg-blue-400/10",
61
+ title: "text-blue-700 dark:text-blue-300"
62
+ },
63
+ tip: {
64
+ frame: "border-emerald-500/70 bg-emerald-500/5 dark:border-emerald-400/70 dark:bg-emerald-400/10",
65
+ title: "text-emerald-700 dark:text-emerald-300"
66
+ },
67
+ important: {
68
+ frame: "border-violet-500/70 bg-violet-500/5 dark:border-violet-400/70 dark:bg-violet-400/10",
69
+ title: "text-violet-700 dark:text-violet-300"
70
+ },
71
+ warning: {
72
+ frame: "border-amber-500/80 bg-amber-500/5 dark:border-amber-400/70 dark:bg-amber-400/10",
73
+ title: "text-amber-700 dark:text-amber-300"
74
+ },
75
+ caution: {
76
+ frame: "border-red-500/70 bg-red-500/5 dark:border-red-400/70 dark:bg-red-400/10",
77
+ title: "text-red-700 dark:text-red-300"
78
+ },
79
+ info: {
80
+ frame: "border-sky-500/70 bg-sky-500/5 dark:border-sky-400/70 dark:bg-sky-400/10",
81
+ title: "text-sky-700 dark:text-sky-300"
82
+ },
83
+ success: {
84
+ frame: "border-green-600/70 bg-green-600/5 dark:border-green-400/70 dark:bg-green-400/10",
85
+ title: "text-green-700 dark:text-green-300"
86
+ },
87
+ question: {
88
+ frame: "border-indigo-500/70 bg-indigo-500/5 dark:border-indigo-400/70 dark:bg-indigo-400/10",
89
+ title: "text-indigo-700 dark:text-indigo-300"
90
+ },
91
+ quote: {
92
+ frame: "border-zinc-400/80 bg-zinc-500/5 dark:border-zinc-500/80 dark:bg-zinc-400/10",
93
+ title: "text-zinc-600 dark:text-zinc-300"
94
+ }
95
+ };
96
+ export {
97
+ CALLOUT_CLASSES,
98
+ CALLOUT_LABEL,
99
+ CALLOUT_TYPES,
100
+ resolveCalloutType
101
+ };
@@ -0,0 +1,17 @@
1
+ import { type CalloutType } from "./callout-types.js";
2
+ import { type MNode, type SyntaxFile } from "./mdast-helpers.js";
3
+ type Fold = "none" | "closed" | "open";
4
+ /** Build the one callout node. `title` null → the type's own label. */
5
+ export declare function calloutNode(type: CalloutType, title: MNode[] | null, body: MNode[], fold: Fold): MNode;
6
+ /** The default `==highlight==` / `:mark[…]` wash. */
7
+ export declare const MARK_CLASS: string[];
8
+ export declare const KBD_CLASS: string[];
9
+ /** The table-of-contents placeholder; the rehype pass fills it from the headings. */
10
+ export declare function tocNode(): MNode;
11
+ /**
12
+ * Resolve every directive and GitHub/Obsidian callout in the tree, children
13
+ * first (so a callout inside a tab or a tab inside a column is already
14
+ * resolved when its parent is built).
15
+ */
16
+ export declare function transformContainers(node: MNode, file: SyntaxFile | undefined): void;
17
+ export {};
@@ -0,0 +1,353 @@
1
+ import {
2
+ CALLOUT_CLASSES,
3
+ CALLOUT_LABEL,
4
+ resolveCalloutType
5
+ } from "./callout-types.js";
6
+ import { CONTAINER_DIRECTIVES, LEAF_DIRECTIVES, TEXT_DIRECTIVES } from "./names.js";
7
+ import { el, mergeText, rawOf, text, toText } from "./mdast-helpers.js";
8
+ function calloutNode(type, title, body, fold) {
9
+ const colors = CALLOUT_CLASSES[type];
10
+ const foldable = fold !== "none";
11
+ const titleChildren = [
12
+ el("matrx-callout-icon", { dataType: type }),
13
+ // A default title ("Note") is renderer text, not the source's: marked as content chrome.
14
+ title && title.length > 0 ? el("span", { className: ["min-w-0"] }, title) : el("span", { className: ["min-w-0"], dataContentChrome: true }, [text(CALLOUT_LABEL[type])])
15
+ ];
16
+ if (foldable) titleChildren.push(el("matrx-callout-icon", { dataType: "chevron" }));
17
+ const titleNode = el(
18
+ foldable ? "summary" : "div",
19
+ {
20
+ className: [
21
+ "matrx-callout-title",
22
+ "flex",
23
+ "items-center",
24
+ "gap-2",
25
+ "text-sm",
26
+ "font-semibold",
27
+ colors.title,
28
+ ...foldable ? ["cursor-pointer", "list-none", "select-none", "[&::-webkit-details-marker]:hidden"] : []
29
+ ]
30
+ },
31
+ titleChildren
32
+ );
33
+ const bodyNode = el(
34
+ "div",
35
+ {
36
+ className: [
37
+ "matrx-callout-body",
38
+ "mt-1.5",
39
+ "text-sm",
40
+ "text-foreground",
41
+ "[&>*:last-child]:mb-0",
42
+ "[&>*:first-child]:mt-0"
43
+ ]
44
+ },
45
+ body
46
+ );
47
+ return el(
48
+ foldable ? "details" : "div",
49
+ {
50
+ className: [
51
+ "matrx-callout",
52
+ "group/callout",
53
+ "my-3",
54
+ "rounded-md",
55
+ "border-l-4",
56
+ "px-3",
57
+ "py-2",
58
+ colors.frame
59
+ ],
60
+ dataCallout: type,
61
+ ...foldable ? {} : { role: "note" },
62
+ ...fold === "open" ? { open: true } : {}
63
+ },
64
+ body.length > 0 ? [titleNode, bodyNode] : [titleNode],
65
+ "matrxCallout"
66
+ );
67
+ }
68
+ const ALERT_MARKER = /^\[!([A-Za-z][\w-]*)\]([+-])?[ \t]*/;
69
+ function blockquoteToCallout(node) {
70
+ const first = node.children?.[0];
71
+ if (!first || first.type !== "paragraph" || !first.children?.length) return null;
72
+ const lead = first.children[0];
73
+ if (!lead || lead.type !== "text") return null;
74
+ const match = ALERT_MARKER.exec(lead.value ?? "");
75
+ if (!match) return null;
76
+ const type = resolveCalloutType(match[1]);
77
+ if (!type) return null;
78
+ const fold = match[2] === "-" ? "closed" : match[2] === "+" ? "open" : "none";
79
+ const rest = [{ ...lead, value: (lead.value ?? "").slice(match[0].length) }, ...first.children.slice(1)];
80
+ const title = [];
81
+ const bodyInline = [];
82
+ let inBody = false;
83
+ for (const child of rest) {
84
+ if (inBody) {
85
+ bodyInline.push(child);
86
+ continue;
87
+ }
88
+ if (child.type === "break") {
89
+ inBody = true;
90
+ continue;
91
+ }
92
+ if (child.type === "text" && (child.value ?? "").includes("\n")) {
93
+ const value = child.value ?? "";
94
+ const cut = value.indexOf("\n");
95
+ if (cut > 0) title.push(text(value.slice(0, cut)));
96
+ const after = value.slice(cut + 1);
97
+ if (after) bodyInline.push(text(after));
98
+ inBody = true;
99
+ continue;
100
+ }
101
+ title.push(child);
102
+ }
103
+ const titleNodes = title.filter((n) => !(n.type === "text" && !(n.value ?? "").trim()));
104
+ const body = [];
105
+ if (bodyInline.some((n) => !(n.type === "text" && !(n.value ?? "").trim()))) {
106
+ body.push({ type: "paragraph", children: bodyInline });
107
+ }
108
+ body.push(...node.children?.slice(1) ?? []);
109
+ return calloutNode(type, titleNodes.length > 0 ? titleNodes : null, body, fold);
110
+ }
111
+ function splitLabel(node) {
112
+ const children = node.children ?? [];
113
+ const first = children[0];
114
+ if (first && first.data?.directiveLabel) {
115
+ return { label: first.children ?? [], body: children.slice(1) };
116
+ }
117
+ return { label: null, body: children };
118
+ }
119
+ function attr(node, key) {
120
+ const attrs = node.attributes;
121
+ if (!attrs || !(key in attrs)) return void 0;
122
+ return attrs[key] ?? null;
123
+ }
124
+ function foldOf(node) {
125
+ const value = attr(node, "fold") ?? attr(node, "collapse") ?? attr(node, "collapsed");
126
+ if (value === void 0) return "none";
127
+ if (value === "open" || value === "false") return "open";
128
+ return "closed";
129
+ }
130
+ const TEXT_COLORS = {
131
+ red: "text-red-600 dark:text-red-400",
132
+ orange: "text-orange-600 dark:text-orange-400",
133
+ amber: "text-amber-600 dark:text-amber-400",
134
+ yellow: "text-yellow-600 dark:text-yellow-300",
135
+ green: "text-green-600 dark:text-green-400",
136
+ teal: "text-teal-600 dark:text-teal-400",
137
+ blue: "text-blue-600 dark:text-blue-400",
138
+ indigo: "text-indigo-600 dark:text-indigo-400",
139
+ purple: "text-purple-600 dark:text-purple-400",
140
+ pink: "text-pink-600 dark:text-pink-400",
141
+ gray: "text-zinc-500 dark:text-zinc-400",
142
+ muted: "text-muted-foreground",
143
+ primary: "text-primary",
144
+ success: "text-green-600 dark:text-green-400",
145
+ warning: "text-amber-600 dark:text-amber-400",
146
+ danger: "text-red-600 dark:text-red-400",
147
+ info: "text-sky-600 dark:text-sky-400"
148
+ };
149
+ const HIGHLIGHT_COLORS = {
150
+ yellow: "bg-yellow-200/70 dark:bg-yellow-400/25",
151
+ green: "bg-green-200/70 dark:bg-green-400/25",
152
+ blue: "bg-blue-200/70 dark:bg-blue-400/25",
153
+ pink: "bg-pink-200/70 dark:bg-pink-400/25",
154
+ purple: "bg-purple-200/70 dark:bg-purple-400/25",
155
+ orange: "bg-orange-200/70 dark:bg-orange-400/25",
156
+ red: "bg-red-200/70 dark:bg-red-400/25",
157
+ gray: "bg-zinc-200/80 dark:bg-zinc-500/30",
158
+ success: "bg-green-200/70 dark:bg-green-400/25",
159
+ warning: "bg-amber-200/70 dark:bg-amber-400/25",
160
+ danger: "bg-red-200/70 dark:bg-red-400/25",
161
+ info: "bg-sky-200/70 dark:bg-sky-400/25"
162
+ };
163
+ const MARK_CLASS = ["rounded-sm", "px-0.5", "text-inherit", "bg-yellow-200/70", "dark:bg-yellow-400/25"];
164
+ const KBD_CLASS = [
165
+ "rounded",
166
+ "border",
167
+ "border-border",
168
+ "border-b-2",
169
+ "bg-muted",
170
+ "px-1.5",
171
+ "py-px",
172
+ "font-mono",
173
+ "text-[0.8em]",
174
+ "text-foreground"
175
+ ];
176
+ function colorClass(value, table) {
177
+ if (!value) return [];
178
+ const cls = table[value.trim().toLowerCase()];
179
+ return cls ? cls.split(" ") : [];
180
+ }
181
+ function textDirective(node, file) {
182
+ const name = (node.name ?? "").toLowerCase();
183
+ const children = node.children ?? [];
184
+ if (!TEXT_DIRECTIVES.has(name) || children.length === 0) {
185
+ return text(rawOf(node, file) ?? `:${node.name ?? ""}`);
186
+ }
187
+ const color = attr(node, "color") ?? attr(node, "fg");
188
+ const bg = attr(node, "bg") ?? attr(node, "background");
189
+ switch (name) {
190
+ case "span": {
191
+ const classes = [...colorClass(color, TEXT_COLORS), ...colorClass(bg, HIGHLIGHT_COLORS)];
192
+ if (bg && classes.length > 0) classes.push("rounded-sm", "px-0.5");
193
+ return el("span", classes.length > 0 ? { className: classes, dataColor: color ?? bg ?? void 0 } : {}, children);
194
+ }
195
+ case "mark": {
196
+ const wash = colorClass(bg ?? color, HIGHLIGHT_COLORS);
197
+ return el(
198
+ "mark",
199
+ { className: wash.length > 0 ? ["rounded-sm", "px-0.5", "text-inherit", ...wash] : MARK_CLASS },
200
+ children
201
+ );
202
+ }
203
+ case "kbd":
204
+ return el("kbd", { className: KBD_CLASS }, children);
205
+ case "abbr":
206
+ return el("abbr", { title: attr(node, "title") ?? void 0, className: ["cursor-help", "underline", "decoration-dotted"] }, children);
207
+ case "sup":
208
+ case "sub":
209
+ return el(name, {}, children);
210
+ default:
211
+ return text(rawOf(node, file) ?? `:${node.name ?? ""}`);
212
+ }
213
+ }
214
+ function tocNode() {
215
+ return el("matrx-toc", {}, [], "matrxToc");
216
+ }
217
+ function hasFence(nodes) {
218
+ return nodes.some((n) => n.type === "code" || n.type !== "matrxNested" && !!n.children && hasFence(n.children));
219
+ }
220
+ function nestBlockyBody(body, file) {
221
+ if (body.length === 0 || !hasFence(body)) return body;
222
+ const source = typeof file?.value === "string" ? file.value : null;
223
+ const start = body[0]?.position?.start.offset;
224
+ const end = body[body.length - 1]?.position?.end.offset;
225
+ if (source === null || start === void 0 || end === void 0) return body;
226
+ return [el("matrx-nested", { dataSource: source.slice(start, end) }, [], "matrxNested")];
227
+ }
228
+ function containerDirective(node, file) {
229
+ const name = (node.name ?? "").toLowerCase();
230
+ const split = splitLabel(node);
231
+ const label = split.label;
232
+ const body = nestBlockyBody(split.body, file);
233
+ const callout = resolveCalloutType(name);
234
+ if (callout && !CONTAINER_DIRECTIVES.has(name)) {
235
+ return calloutNode(callout, label, body, foldOf(node));
236
+ }
237
+ const id = attr(node, "id") ?? void 0;
238
+ switch (name) {
239
+ case "details": {
240
+ const open = attr(node, "open") !== void 0;
241
+ return el("details", { ...open ? { open: true } : {}, id }, [
242
+ el("summary", {}, label && label.length > 0 ? label : [text("Details")]),
243
+ el("div", { className: ["matrx-details-body"] }, body)
244
+ ]);
245
+ }
246
+ case "columns": {
247
+ const count = body.filter((c) => c.type === "matrxColumn").length;
248
+ const cols = count >= 3 ? "md:grid-cols-3" : "md:grid-cols-2";
249
+ return el("div", { className: ["matrx-columns", "my-3", "grid", "grid-cols-1", "gap-4", cols], id }, body);
250
+ }
251
+ case "column": {
252
+ const lead = label && label.length > 0 ? [{ type: "paragraph", children: label }] : [];
253
+ return el("div", { className: ["matrx-column", "min-w-0", "[&>*:first-child]:mt-0"] }, [...lead, ...body], "matrxColumn");
254
+ }
255
+ case "tabs": {
256
+ const tabs = body.filter((c) => c.type === "matrxTab");
257
+ const labels = tabs.map((t, i) => String(t.data?.hProperties?.dataLabel ?? `Tab ${i + 1}`));
258
+ return el("matrx-tabs", { dataLabels: JSON.stringify(labels), id }, tabs);
259
+ }
260
+ case "tab": {
261
+ const tabLabel = (label ?? []).map(toText).join("").trim() || attr(node, "title") || attr(node, "label") || "";
262
+ return el("matrx-tab", { dataLabel: tabLabel }, body, "matrxTab");
263
+ }
264
+ case "figure":
265
+ case "table": {
266
+ const figure = el(
267
+ "figure",
268
+ {
269
+ className: [name === "table" ? "matrx-table-figure" : "matrx-figure", "my-4"],
270
+ id
271
+ },
272
+ body,
273
+ "matrxFigure"
274
+ );
275
+ figure.matrxFigure = { kind: name === "table" ? "tbl" : "fig", caption: label ?? [], id: id ?? null };
276
+ return figure;
277
+ }
278
+ case "aside":
279
+ return el(
280
+ "aside",
281
+ {
282
+ className: ["matrx-aside", "my-3", "rounded-md", "border", "border-border", "bg-muted/40", "px-3", "py-2", "text-sm", "[&>*:last-child]:mb-0"],
283
+ id
284
+ },
285
+ label && label.length > 0 ? [el("p", { className: ["font-semibold"] }, label), ...body] : body
286
+ );
287
+ case "toc":
288
+ return tocNode();
289
+ default:
290
+ return el(
291
+ "div",
292
+ { className: ["matrx-directive"], dataDirective: name, id },
293
+ label && label.length > 0 ? [{ type: "paragraph", children: label }, ...body] : body
294
+ );
295
+ }
296
+ }
297
+ function leafDirective(node, file) {
298
+ const name = (node.name ?? "").toLowerCase();
299
+ if (LEAF_DIRECTIVES.has(name) && name === "toc") return tocNode();
300
+ return { type: "paragraph", children: [text(rawOf(node, file) ?? `::${node.name ?? ""}`)] };
301
+ }
302
+ const STRAY_CLOSER = /^:{3,}$/;
303
+ function transformContainers(node, file) {
304
+ const children = node.children;
305
+ if (!children) return;
306
+ for (const child of children) transformContainers(child, file);
307
+ const next = [];
308
+ let changed = false;
309
+ for (const child of children) {
310
+ switch (child.type) {
311
+ case "textDirective":
312
+ next.push(textDirective(child, file));
313
+ changed = true;
314
+ continue;
315
+ case "leafDirective":
316
+ next.push(leafDirective(child, file));
317
+ changed = true;
318
+ continue;
319
+ case "containerDirective":
320
+ next.push({ ...containerDirective(child, file), position: child.position });
321
+ changed = true;
322
+ continue;
323
+ case "blockquote": {
324
+ const callout = blockquoteToCallout(child);
325
+ if (callout) {
326
+ next.push(callout);
327
+ changed = true;
328
+ continue;
329
+ }
330
+ break;
331
+ }
332
+ case "paragraph": {
333
+ const only = child.children?.length === 1 ? child.children[0] : null;
334
+ if (only?.type === "text" && STRAY_CLOSER.test((only.value ?? "").trim())) {
335
+ changed = true;
336
+ continue;
337
+ }
338
+ break;
339
+ }
340
+ default:
341
+ break;
342
+ }
343
+ next.push(child);
344
+ }
345
+ if (changed) node.children = mergeText(next);
346
+ }
347
+ export {
348
+ KBD_CLASS,
349
+ MARK_CLASS,
350
+ calloutNode,
351
+ tocNode,
352
+ transformContainers
353
+ };
@@ -0,0 +1,52 @@
1
+ export interface NumberedTarget {
2
+ kind: "fig" | "tbl" | "eq" | "sec";
3
+ /** "Figure 2", "Table 1", "(3)", or a section's heading text. */
4
+ display: string;
5
+ }
6
+ export interface DocumentNumbering {
7
+ /** Labelled targets by label. */
8
+ byLabel: Map<string, NumberedTarget>;
9
+ /** Unlabelled figures/tables by `kind|caption`, in document order (one entry per occurrence). */
10
+ byCaption: Map<string, string[]>;
11
+ /**
12
+ * Footnote identifier (lower-case) → its number, exactly as GFM numbers the
13
+ * whole document: defined labels only, body references in order of first
14
+ * reference, then references inside the notes. A label absent here is either
15
+ * undefined (the reference stays text) or never cited (the note is dropped).
16
+ */
17
+ footnotes: Map<string, number>;
18
+ /**
19
+ * The cited notes' definitions exactly as written (`[^x]: …` plus their
20
+ * continuation lines), in number order, "" when none. The document root
21
+ * renders them ONCE, after its last block (DocumentFootnotes), as GFM places
22
+ * notes after the whole document; a block never renders a definition itself.
23
+ */
24
+ footnoteMarkdown: string;
25
+ /**
26
+ * The document's link reference definitions as canonical definition lines
27
+ * (`[label]: <url> "title"`), "" when none — every block resolves its
28
+ * `[text][label]` references against them (prepareCoreSource), so a block
29
+ * split from them still shows the link GFM shows.
30
+ */
31
+ linkDefinitions: string;
32
+ }
33
+ export declare function captionKey(kind: "fig" | "tbl", caption: string): string;
34
+ export declare function computeDocumentNumbering(source: string): DocumentNumbering;
35
+ /**
36
+ * The first line of the document's footnote block: the root renders
37
+ * `documentFootnoteSource(numbering)` through its ordinary prose path after its
38
+ * last block, and the syntax pass (remarkMatrxSyntax) renders the notes' section
39
+ * ONLY in the tree that carries this line.
40
+ */
41
+ export declare const DOCUMENT_FOOTNOTES_MARKER = "<!-- matrx:document-footnotes -->";
42
+ /** The markdown of the document's one footnote section, or "" when nothing is cited. */
43
+ export declare function documentFootnoteSource(numbering: DocumentNumbering | null | undefined): string;
44
+ /**
45
+ * Same numbers? Two numberings that assign every label, caption and footnote
46
+ * the same display are interchangeable. The document root re-computes the
47
+ * numbering on every edit and every stream chunk; handing every MarkdownCore
48
+ * leaf a NEW object each time made every leaf of the document re-parse on
49
+ * every keystroke (the markdown-tester browser crash, 2026-09-26). The
50
+ * provider keeps the previous object whenever this says nothing changed.
51
+ */
52
+ export declare function sameDocumentNumbering(a: DocumentNumbering, b: DocumentNumbering): boolean;