@svadmin/ai-elements 0.7.4 → 0.9.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 (218) hide show
  1. package/README.md +31 -4
  2. package/THIRD_PARTY_NOTICES.md +67 -6
  3. package/dist/ai-workspace-contract.d.ts +14 -0
  4. package/dist/ai-workspace-contract.js +14 -0
  5. package/dist/ai.css +2 -5
  6. package/dist/ai.theme.css +1 -0
  7. package/dist/class-properties.generated.d.ts +1 -0
  8. package/dist/class-properties.generated.js +2 -0
  9. package/dist/classnames.d.ts +8 -0
  10. package/dist/classnames.js +26 -0
  11. package/dist/components/Response.svelte +2 -2
  12. package/dist/components/Response.svelte.d.ts +1 -1
  13. package/dist/components/code/index.d.ts +9 -18
  14. package/dist/components/code/index.js +8 -11
  15. package/dist/components/code-block/highlight.js +1 -1
  16. package/dist/index.d.ts +2 -0
  17. package/dist/index.js +1 -0
  18. package/dist/utilities.css +3172 -0
  19. package/dist/utils.d.ts +1 -1
  20. package/dist/utils.js +1 -1
  21. package/package.json +36 -11
  22. package/vendor/streamdown/AnimatedText.svelte +93 -0
  23. package/vendor/streamdown/AnimatedText.svelte.d.ts +6 -0
  24. package/vendor/streamdown/Block.svelte +96 -0
  25. package/vendor/streamdown/Block.svelte.d.ts +11 -0
  26. package/vendor/streamdown/Elements/Alert.svelte +69 -0
  27. package/vendor/streamdown/Elements/Alert.svelte.d.ts +10 -0
  28. package/vendor/streamdown/Elements/Citation.svelte +260 -0
  29. package/vendor/streamdown/Elements/Citation.svelte.d.ts +7 -0
  30. package/vendor/streamdown/Elements/Code.svelte +226 -0
  31. package/vendor/streamdown/Elements/Code.svelte.d.ts +9 -0
  32. package/vendor/streamdown/Elements/Element.svelte +574 -0
  33. package/vendor/streamdown/Elements/Element.svelte.d.ts +10 -0
  34. package/vendor/streamdown/Elements/FootnoteRef.svelte +30 -0
  35. package/vendor/streamdown/Elements/FootnoteRef.svelte.d.ts +7 -0
  36. package/vendor/streamdown/Elements/Footnotes.svelte +54 -0
  37. package/vendor/streamdown/Elements/Footnotes.svelte.d.ts +7 -0
  38. package/vendor/streamdown/Elements/Image.svelte +200 -0
  39. package/vendor/streamdown/Elements/Image.svelte.d.ts +10 -0
  40. package/vendor/streamdown/Elements/Link.svelte +220 -0
  41. package/vendor/streamdown/Elements/Link.svelte.d.ts +10 -0
  42. package/vendor/streamdown/Elements/LinkSafetyModal.svelte +121 -0
  43. package/vendor/streamdown/Elements/LinkSafetyModal.svelte.d.ts +4 -0
  44. package/vendor/streamdown/Elements/Math.svelte +100 -0
  45. package/vendor/streamdown/Elements/Math.svelte.d.ts +9 -0
  46. package/vendor/streamdown/Elements/Mermaid.svelte +455 -0
  47. package/vendor/streamdown/Elements/Mermaid.svelte.d.ts +9 -0
  48. package/vendor/streamdown/Elements/MermaidDownload.svelte +145 -0
  49. package/vendor/streamdown/Elements/MermaidDownload.svelte.d.ts +8 -0
  50. package/vendor/streamdown/Elements/Slot.svelte +23 -0
  51. package/vendor/streamdown/Elements/Slot.svelte.d.ts +10 -0
  52. package/vendor/streamdown/Elements/Table.svelte +195 -0
  53. package/vendor/streamdown/Elements/Table.svelte.d.ts +9 -0
  54. package/vendor/streamdown/Elements/TableDownload.svelte +221 -0
  55. package/vendor/streamdown/Elements/TableDownload.svelte.d.ts +8 -0
  56. package/vendor/streamdown/Elements/fallbacks/CodeFallback.svelte +41 -0
  57. package/vendor/streamdown/Elements/fallbacks/CodeFallback.svelte.d.ts +9 -0
  58. package/vendor/streamdown/Elements/fallbacks/MathFallback.svelte +35 -0
  59. package/vendor/streamdown/Elements/fallbacks/MathFallback.svelte.d.ts +8 -0
  60. package/vendor/streamdown/Elements/fallbacks/MermaidFallback.svelte +36 -0
  61. package/vendor/streamdown/Elements/fallbacks/MermaidFallback.svelte.d.ts +9 -0
  62. package/vendor/streamdown/Elements/fallbacks/index.d.ts +3 -0
  63. package/vendor/streamdown/Elements/fallbacks/index.js +3 -0
  64. package/vendor/streamdown/Elements/icons.d.ts +31 -0
  65. package/vendor/streamdown/Elements/icons.js +200 -0
  66. package/vendor/streamdown/Elements/index.d.ts +8 -0
  67. package/vendor/streamdown/Elements/index.js +8 -0
  68. package/vendor/streamdown/Elements/popover.svelte.d.ts +8 -0
  69. package/vendor/streamdown/Elements/popover.svelte.js +45 -0
  70. package/vendor/streamdown/Elements/stepperState.svelte.d.ts +36 -0
  71. package/vendor/streamdown/Elements/stepperState.svelte.js +92 -0
  72. package/vendor/streamdown/IconProvider.svelte +11 -0
  73. package/vendor/streamdown/IconProvider.svelte.d.ts +30 -0
  74. package/vendor/streamdown/LICENSE +202 -0
  75. package/vendor/streamdown/PluginProvider.svelte +11 -0
  76. package/vendor/streamdown/PluginProvider.svelte.d.ts +30 -0
  77. package/vendor/streamdown/README.svadmin.md +5 -0
  78. package/vendor/streamdown/Streamdown.svelte +447 -0
  79. package/vendor/streamdown/Streamdown.svelte.d.ts +25 -0
  80. package/vendor/streamdown/block/BlockTokens.svelte +45 -0
  81. package/vendor/streamdown/block/BlockTokens.svelte.d.ts +9 -0
  82. package/vendor/streamdown/block/html.d.ts +14 -0
  83. package/vendor/streamdown/block/html.js +27 -0
  84. package/vendor/streamdown/block/text.d.ts +10 -0
  85. package/vendor/streamdown/block/text.js +31 -0
  86. package/vendor/streamdown/context-key.d.ts +1 -0
  87. package/vendor/streamdown/context-key.js +1 -0
  88. package/vendor/streamdown/context.svelte.d.ts +24 -0
  89. package/vendor/streamdown/context.svelte.js +75 -0
  90. package/vendor/streamdown/contracts/plugins.d.ts +26 -0
  91. package/vendor/streamdown/contracts/plugins.js +1 -0
  92. package/vendor/streamdown/contracts/streamdown.d.ts +374 -0
  93. package/vendor/streamdown/contracts/streamdown.js +29 -0
  94. package/vendor/streamdown/detect-direction.d.ts +1 -0
  95. package/vendor/streamdown/detect-direction.js +1 -0
  96. package/vendor/streamdown/icon-context.d.ts +36 -0
  97. package/vendor/streamdown/icon-context.js +52 -0
  98. package/vendor/streamdown/incomplete-code.d.ts +6 -0
  99. package/vendor/streamdown/incomplete-code.js +23 -0
  100. package/vendor/streamdown/index.d.ts +22 -0
  101. package/vendor/streamdown/index.js +20 -0
  102. package/vendor/streamdown/markdown-parse-cache.d.ts +37 -0
  103. package/vendor/streamdown/markdown-parse-cache.js +109 -0
  104. package/vendor/streamdown/markdown.d.ts +21 -0
  105. package/vendor/streamdown/markdown.js +214 -0
  106. package/vendor/streamdown/marked/index.d.ts +44 -0
  107. package/vendor/streamdown/marked/index.js +228 -0
  108. package/vendor/streamdown/marked/marked-alert.d.ts +13 -0
  109. package/vendor/streamdown/marked/marked-alert.js +47 -0
  110. package/vendor/streamdown/marked/marked-align.d.ts +10 -0
  111. package/vendor/streamdown/marked/marked-align.js +45 -0
  112. package/vendor/streamdown/marked/marked-br.d.ts +6 -0
  113. package/vendor/streamdown/marked/marked-br.js +15 -0
  114. package/vendor/streamdown/marked/marked-citations.d.ts +8 -0
  115. package/vendor/streamdown/marked/marked-citations.js +53 -0
  116. package/vendor/streamdown/marked/marked-cjk.d.ts +2 -0
  117. package/vendor/streamdown/marked/marked-cjk.js +165 -0
  118. package/vendor/streamdown/marked/marked-dl.d.ts +23 -0
  119. package/vendor/streamdown/marked/marked-dl.js +44 -0
  120. package/vendor/streamdown/marked/marked-footnotes.d.ts +26 -0
  121. package/vendor/streamdown/marked/marked-footnotes.js +101 -0
  122. package/vendor/streamdown/marked/marked-hr.d.ts +6 -0
  123. package/vendor/streamdown/marked/marked-hr.js +18 -0
  124. package/vendor/streamdown/marked/marked-list.d.ts +31 -0
  125. package/vendor/streamdown/marked/marked-list.js +330 -0
  126. package/vendor/streamdown/marked/marked-math.d.ts +13 -0
  127. package/vendor/streamdown/marked/marked-math.js +129 -0
  128. package/vendor/streamdown/marked/marked-mdx.d.ts +12 -0
  129. package/vendor/streamdown/marked/marked-mdx.js +124 -0
  130. package/vendor/streamdown/marked/marked-subsup.d.ts +22 -0
  131. package/vendor/streamdown/marked/marked-subsup.js +40 -0
  132. package/vendor/streamdown/marked/marked-table.d.ts +80 -0
  133. package/vendor/streamdown/marked/marked-table.js +527 -0
  134. package/vendor/streamdown/plugin-context.d.ts +19 -0
  135. package/vendor/streamdown/plugin-context.js +40 -0
  136. package/vendor/streamdown/plugins/cjk-shared.d.ts +1 -0
  137. package/vendor/streamdown/plugins/cjk-shared.js +1 -0
  138. package/vendor/streamdown/plugins.d.ts +19 -0
  139. package/vendor/streamdown/plugins.js +107 -0
  140. package/vendor/streamdown/provenance.json +229 -0
  141. package/vendor/streamdown/remend.d.ts +2 -0
  142. package/vendor/streamdown/remend.js +1 -0
  143. package/vendor/streamdown/security/html.d.ts +19 -0
  144. package/vendor/streamdown/security/html.js +329 -0
  145. package/vendor/streamdown/security/preprocess-custom-tags.d.ts +1 -0
  146. package/vendor/streamdown/security/preprocess-custom-tags.js +20 -0
  147. package/vendor/streamdown/security/preprocess-literal-tag-content.d.ts +1 -0
  148. package/vendor/streamdown/security/preprocess-literal-tag-content.js +16 -0
  149. package/vendor/streamdown/security/types.d.ts +1 -0
  150. package/vendor/streamdown/security/types.js +1 -0
  151. package/vendor/streamdown/site/SiteHeader.svelte +94 -0
  152. package/vendor/streamdown/site/SiteHeader.svelte.d.ts +6 -0
  153. package/vendor/streamdown/site/home/HomeDemo.svelte +122 -0
  154. package/vendor/streamdown/site/home/HomeDemo.svelte.d.ts +3 -0
  155. package/vendor/streamdown/site/home/HomePage.svelte +293 -0
  156. package/vendor/streamdown/site/home/HomePage.svelte.d.ts +3 -0
  157. package/vendor/streamdown/site/home/content.d.ts +69 -0
  158. package/vendor/streamdown/site/home/content.js +144 -0
  159. package/vendor/streamdown/site/metadata.d.ts +4 -0
  160. package/vendor/streamdown/site/metadata.js +4 -0
  161. package/vendor/streamdown/site/navigation.d.ts +6 -0
  162. package/vendor/streamdown/site/navigation.js +22 -0
  163. package/vendor/streamdown/streamdown/config.d.ts +41 -0
  164. package/vendor/streamdown/streamdown/config.js +125 -0
  165. package/vendor/streamdown/streamdown/context.d.ts +12 -0
  166. package/vendor/streamdown/streamdown/context.js +2 -0
  167. package/vendor/streamdown/streamdown/incomplete-markdown.d.ts +5 -0
  168. package/vendor/streamdown/streamdown/incomplete-markdown.js +79 -0
  169. package/vendor/streamdown/streamdown/pipeline.d.ts +95 -0
  170. package/vendor/streamdown/streamdown/pipeline.js +138 -0
  171. package/vendor/streamdown/streamdown/runtime.d.ts +59 -0
  172. package/vendor/streamdown/streamdown/runtime.js +112 -0
  173. package/vendor/streamdown/streaming.d.ts +5 -0
  174. package/vendor/streamdown/streaming.js +5 -0
  175. package/vendor/streamdown/theme.d.ts +486 -0
  176. package/vendor/streamdown/theme.js +370 -0
  177. package/vendor/streamdown/translations.d.ts +43 -0
  178. package/vendor/streamdown/translations.js +54 -0
  179. package/vendor/streamdown/url-policy.d.ts +1 -0
  180. package/vendor/streamdown/url-policy.js +1 -0
  181. package/vendor/streamdown/utils/bind.d.ts +8 -0
  182. package/vendor/streamdown/utils/bind.js +26 -0
  183. package/vendor/streamdown/utils/bundledLanguages.d.ts +1 -0
  184. package/vendor/streamdown/utils/bundledLanguages.js +1 -0
  185. package/vendor/streamdown/utils/code-block.d.ts +8 -0
  186. package/vendor/streamdown/utils/code-block.js +38 -0
  187. package/vendor/streamdown/utils/copy.svelte.d.ts +7 -0
  188. package/vendor/streamdown/utils/copy.svelte.js +38 -0
  189. package/vendor/streamdown/utils/darkMode.svelte.d.ts +3 -0
  190. package/vendor/streamdown/utils/darkMode.svelte.js +49 -0
  191. package/vendor/streamdown/utils/detectDirection.d.ts +1 -0
  192. package/vendor/streamdown/utils/detectDirection.js +19 -0
  193. package/vendor/streamdown/utils/get.d.ts +1 -0
  194. package/vendor/streamdown/utils/get.js +25 -0
  195. package/vendor/streamdown/utils/hightlighter.svelte.d.ts +30 -0
  196. package/vendor/streamdown/utils/hightlighter.svelte.js +524 -0
  197. package/vendor/streamdown/utils/index.d.ts +3 -0
  198. package/vendor/streamdown/utils/index.js +3 -0
  199. package/vendor/streamdown/utils/mermaid.d.ts +13 -0
  200. package/vendor/streamdown/utils/mermaid.js +49 -0
  201. package/vendor/streamdown/utils/panzoom.svelte.d.ts +35 -0
  202. package/vendor/streamdown/utils/panzoom.svelte.js +556 -0
  203. package/vendor/streamdown/utils/parse-incomplete-markdown.d.ts +2 -0
  204. package/vendor/streamdown/utils/parse-incomplete-markdown.js +2 -0
  205. package/vendor/streamdown/utils/runtime-env.d.ts +1 -0
  206. package/vendor/streamdown/utils/runtime-env.js +13 -0
  207. package/vendor/streamdown/utils/save.d.ts +1 -0
  208. package/vendor/streamdown/utils/save.js +14 -0
  209. package/vendor/streamdown/utils/scroll-lock.d.ts +2 -0
  210. package/vendor/streamdown/utils/scroll-lock.js +35 -0
  211. package/vendor/streamdown/utils/table.d.ts +8 -0
  212. package/vendor/streamdown/utils/table.js +176 -0
  213. package/vendor/streamdown/utils/url.d.ts +22 -0
  214. package/vendor/streamdown/utils/url.js +98 -0
  215. package/vendor/streamdown/utils/useClickOutside.svelte.d.ts +8 -0
  216. package/vendor/streamdown/utils/useClickOutside.svelte.js +41 -0
  217. package/vendor/streamdown/utils/useKeyDown.svelte.d.ts +5 -0
  218. package/vendor/streamdown/utils/useKeyDown.svelte.js +23 -0
@@ -0,0 +1,80 @@
1
+ import type { Extension } from './index.js';
2
+ export interface SpanTableOptions {
3
+ useTheadTbody?: boolean;
4
+ useTfoot?: boolean;
5
+ detectFooter?: boolean;
6
+ maxColspan?: number | null;
7
+ handleComplexSpans?: boolean;
8
+ }
9
+ interface BaseCell {
10
+ rowspan: number;
11
+ colspan: number;
12
+ text: string;
13
+ position?: number;
14
+ tokens?: unknown[];
15
+ rowSpanTarget?: BaseCell;
16
+ complexRowSpan?: boolean;
17
+ relatedCell?: BaseCell;
18
+ align?: string | null;
19
+ }
20
+ export interface TH extends BaseCell {
21
+ type: 'th';
22
+ }
23
+ export interface TD extends BaseCell {
24
+ type: 'td';
25
+ }
26
+ export type RowColumnNormalizationMode = 'exact' | 'underflow-preserved' | 'overflow-preserved' | 'partial-fit-preserved' | 'complex-span-preserved';
27
+ export interface RowColumnNormalization {
28
+ mode: RowColumnNormalizationMode;
29
+ expectedColumns: number | null;
30
+ actualColumns: number;
31
+ }
32
+ export interface TableColumnNormalization {
33
+ mode: 'balanced' | 'preserve-content';
34
+ issues: Exclude<RowColumnNormalizationMode, 'exact'>[];
35
+ }
36
+ export interface THeadRow {
37
+ type: 'tr';
38
+ tokens: TH[];
39
+ columnNormalization?: RowColumnNormalization;
40
+ placeholderColumns?: number;
41
+ }
42
+ export interface TRow {
43
+ type: 'tr';
44
+ tokens: TD[];
45
+ columnNormalization?: RowColumnNormalization;
46
+ placeholderColumns?: number;
47
+ }
48
+ export interface THead {
49
+ type: 'thead';
50
+ tokens: THeadRow[];
51
+ }
52
+ export interface TBody {
53
+ type: 'tbody';
54
+ tokens: TRow[];
55
+ }
56
+ export interface TFoot {
57
+ type: 'tfoot';
58
+ tokens: TRow[];
59
+ }
60
+ export type TableSection = THead | TBody | TFoot;
61
+ export interface TableToken {
62
+ type: 'table';
63
+ tokens: TableSection[];
64
+ raw: string;
65
+ align: (string | null)[];
66
+ columnNormalization?: TableColumnNormalization;
67
+ }
68
+ interface WorkingCell extends BaseCell {
69
+ }
70
+ type WorkingRow = WorkingCell[];
71
+ interface WorkingRowData {
72
+ cells: WorkingRow;
73
+ columnNormalization: RowColumnNormalization;
74
+ placeholderColumns?: number;
75
+ }
76
+ export declare const DEFAULT_OPTIONS: Required<SpanTableOptions>;
77
+ export declare const getTableCell: (text: string, cell: BaseCell, type: "th" | "td", align: string | null) => string;
78
+ export declare const splitCells: (tableRow: string, count: number | null, prevRow?: WorkingRowData | null, maxColspan?: number | null, preserveIncompleteTail?: boolean) => WorkingRowData;
79
+ export declare const markedTable: Extension;
80
+ export {};
@@ -0,0 +1,527 @@
1
+ // Default configuration options for the extended tables extension
2
+ export const DEFAULT_OPTIONS = {
3
+ useTheadTbody: true,
4
+ useTfoot: false,
5
+ detectFooter: true,
6
+ maxColspan: null,
7
+ handleComplexSpans: true
8
+ };
9
+ // Creates an HTML table cell with appropriate attributes
10
+ export const getTableCell = (text, cell, type, align) => {
11
+ if (!cell.rowspan)
12
+ return '';
13
+ const tag = `<${type}` +
14
+ `${cell.colspan > 1 ? ` colspan=${cell.colspan}` : ''}` +
15
+ `${cell.rowspan > 1 ? ` rowspan=${cell.rowspan}` : ''}` +
16
+ `${align ? ` align=${align}` : ''}>`;
17
+ return `${tag + text}</${type}>\n`;
18
+ };
19
+ function splitRow(src) {
20
+ const out = [];
21
+ let buf = '';
22
+ let esc = false;
23
+ let inCode = false;
24
+ let fence = 0;
25
+ for (let i = 0; i < src.length; i++) {
26
+ const ch = src[i];
27
+ if (esc) {
28
+ buf += ch;
29
+ esc = false;
30
+ continue;
31
+ }
32
+ if (ch === '\\') {
33
+ esc = true;
34
+ buf += ch;
35
+ continue;
36
+ }
37
+ if (ch === '`') {
38
+ let run = 1;
39
+ while (i + run < src.length && src[i + run] === '`')
40
+ run++;
41
+ if (!inCode) {
42
+ inCode = true;
43
+ fence = run;
44
+ }
45
+ else if (run >= fence) {
46
+ inCode = false;
47
+ fence = 0;
48
+ }
49
+ buf += src.slice(i, i + run);
50
+ i += run - 1;
51
+ continue;
52
+ }
53
+ if (ch === '|' && !inCode) {
54
+ // Count consecutive pipes for colspan
55
+ let consecutivePipes = 1;
56
+ while (i + consecutivePipes < src.length && src[i + consecutivePipes] === '|') {
57
+ consecutivePipes++;
58
+ }
59
+ if (consecutivePipes > 1) {
60
+ // Multiple pipes = colspan marker
61
+ out.push(buf.trim() + '\x00COLSPAN:' + consecutivePipes);
62
+ i += consecutivePipes - 1;
63
+ }
64
+ else {
65
+ out.push(buf.trim());
66
+ }
67
+ buf = '';
68
+ continue;
69
+ }
70
+ buf += ch;
71
+ }
72
+ out.push(buf.trim());
73
+ return out;
74
+ }
75
+ // Splits a table row into cells and processes row/column spans
76
+ export const splitCells = (tableRow, count, prevRow = null, maxColspan = null, preserveIncompleteTail = false) => {
77
+ // Split by pipe, but handle escaped pipes and empty cells
78
+ const cells = splitRow(tableRow);
79
+ // Remove first/last cell if it's empty (from leading/trailing pipes)
80
+ if (cells.length > 0 && !cells[0])
81
+ cells.shift();
82
+ if (cells.length > 0 && !cells[cells.length - 1])
83
+ cells.pop();
84
+ return processSpans(cells, count, prevRow?.cells || [], maxColspan, preserveIncompleteTail);
85
+ };
86
+ // Process row and column spans in table cells
87
+ const processSpans = (cells, count, prevRow = [], maxColspan = null, preserveIncompleteTail = false) => {
88
+ let numCols = 0;
89
+ let i, j, trimmedCell, prevCell;
90
+ const processedCells = [];
91
+ // Track colspan cells that need rowspan
92
+ const colspanCells = new Map();
93
+ // First pass: Process each cell's colspan and merge consecutive empty cells
94
+ let cellIndex = 0;
95
+ const mergedIndices = new Set();
96
+ for (i = 0; i < cells.length; i++) {
97
+ if (mergedIndices.has(i))
98
+ continue;
99
+ trimmedCell = cells[i];
100
+ let colspan = 1;
101
+ // Check for colspan marker from consecutive pipes
102
+ if (trimmedCell.includes('\x00COLSPAN:')) {
103
+ const parts = trimmedCell.split('\x00COLSPAN:');
104
+ trimmedCell = parts[0];
105
+ colspan = parseInt(parts[1], 10);
106
+ }
107
+ else if (!trimmedCell.trim()) {
108
+ // Preserve explicit empty cells. Colspan should come from the dedicated
109
+ // repeated-pipe marker rather than silently merging blank markdown cells.
110
+ colspan = 1;
111
+ }
112
+ if (maxColspan !== null && colspan > maxColspan)
113
+ colspan = maxColspan;
114
+ processedCells[cellIndex] = {
115
+ rowspan: 1,
116
+ colspan: colspan,
117
+ text: trimmedCell.trim().replace(/\\\|/g, '|'),
118
+ position: numCols
119
+ };
120
+ numCols += processedCells[cellIndex].colspan;
121
+ cellIndex++;
122
+ }
123
+ // Second pass: Process rowspan by matching cells by position
124
+ for (i = 0; i < processedCells.length; i++) {
125
+ const cell = processedCells[i];
126
+ let cellText = cell.text;
127
+ // Handle Rowspan - cells ending with ^ (but not superscript ^text^)
128
+ // Check if it's a rowspan indicator (single ^ at end) vs superscript (^text^)
129
+ const isRowspanIndicator = cellText.slice(-1) === '^' && !cellText.match(/\^[^^\n\r]+\^$/); // Not a superscript pattern ^text^
130
+ if (isRowspanIndicator && prevRow.length > 0) {
131
+ // Clean the ^ indicator from the cell text
132
+ cell.text = cellText.slice(0, -1).trim();
133
+ cellText = cell.text;
134
+ let targetFound = false;
135
+ const startPosition = cell.position || 0;
136
+ const endPosition = startPosition + cell.colspan - 1;
137
+ // Try to find a matching cell or combination of cells in previous row
138
+ for (j = 0; j < prevRow.length; j++) {
139
+ prevCell = prevRow[j];
140
+ const prevStartPosition = prevCell.position || 0;
141
+ const prevEndPosition = prevStartPosition + prevCell.colspan - 1;
142
+ // Check for position overlap between cells
143
+ if ((startPosition >= prevStartPosition && startPosition <= prevEndPosition) ||
144
+ (endPosition >= prevStartPosition && endPosition <= prevEndPosition) ||
145
+ (prevStartPosition >= startPosition && prevEndPosition <= endPosition)) {
146
+ // Complex case: Handle rowspan for colspan cells
147
+ if (cell.colspan > 1 && prevCell.colspan > 1) {
148
+ // If the cell spans exactly match, simple case
149
+ if (cell.colspan === prevCell.colspan && cell.position === prevCell.position) {
150
+ cell.rowSpanTarget = prevCell.rowSpanTarget ?? prevCell;
151
+ // Only append text if it's different from the target cell
152
+ const textToAppend = cell.text.trim();
153
+ const targetText = cell.rowSpanTarget.text.trim();
154
+ // Don't append if the text is the same or already contained (common case for rowspan indicators)
155
+ if (textToAppend &&
156
+ textToAppend !== targetText &&
157
+ !targetText.includes(textToAppend)) {
158
+ cell.rowSpanTarget.text = targetText + (targetText ? ' ' : '') + textToAppend;
159
+ }
160
+ cell.rowSpanTarget.rowspan += 1;
161
+ cell.rowspan = 0;
162
+ targetFound = true;
163
+ break;
164
+ }
165
+ else {
166
+ // More complex case: Track colspan cells that need rowspan for next row
167
+ const key = `${cell.position}-${cell.colspan}`;
168
+ colspanCells.set(key, {
169
+ original: prevCell,
170
+ newCell: cell
171
+ });
172
+ // Keep the cell visible for now, will be merged in rendering
173
+ }
174
+ }
175
+ else {
176
+ // Standard case of single column cell with rowspan
177
+ cell.rowSpanTarget = prevCell.rowSpanTarget ?? prevCell;
178
+ // Only append text if it's different from the target cell
179
+ const textToAppend = cell.text.trim();
180
+ const targetText = cell.rowSpanTarget.text.trim();
181
+ // Don't append if the text is the same or already contained (common case for rowspan indicators)
182
+ if (textToAppend && textToAppend !== targetText && !targetText.includes(textToAppend)) {
183
+ cell.rowSpanTarget.text = targetText + (targetText ? ' ' : '') + textToAppend;
184
+ }
185
+ cell.rowSpanTarget.rowspan += 1;
186
+ cell.rowspan = 0;
187
+ targetFound = true;
188
+ break;
189
+ }
190
+ }
191
+ }
192
+ // If no target was found but it's a rowspan cell, clean the ^ indicator
193
+ if (!targetFound && cell.rowspan > 0) {
194
+ cell.text = cellText;
195
+ }
196
+ }
197
+ }
198
+ // Process any complex colspan+rowspan combinations we tracked
199
+ colspanCells.forEach((spanData) => {
200
+ const { original, newCell } = spanData;
201
+ if (original && newCell) {
202
+ // Here we could apply more sophisticated merging logic
203
+ // For now, just mark that these cells have a relationship
204
+ newCell.complexRowSpan = true;
205
+ newCell.relatedCell = original;
206
+ }
207
+ });
208
+ // Normalize column count
209
+ return normalizeColumnCount(processedCells, count, numCols, preserveIncompleteTail);
210
+ };
211
+ // Ensures the row has the correct number of columns
212
+ const normalizeColumnCount = (cells, count, numCols, preserveIncompleteTail) => {
213
+ if (count === null || numCols === count) {
214
+ return {
215
+ cells,
216
+ columnNormalization: {
217
+ mode: 'exact',
218
+ expectedColumns: count,
219
+ actualColumns: numCols
220
+ }
221
+ };
222
+ }
223
+ if (numCols < count) {
224
+ return {
225
+ cells,
226
+ columnNormalization: {
227
+ mode: 'underflow-preserved',
228
+ expectedColumns: count,
229
+ actualColumns: numCols
230
+ },
231
+ placeholderColumns: preserveIncompleteTail ? count - numCols : undefined
232
+ };
233
+ }
234
+ const hasPartialFit = cells.some((cell) => {
235
+ const startPosition = cell.position ?? 0;
236
+ return startPosition < count && startPosition + cell.colspan > count;
237
+ });
238
+ const hasComplexSpan = cells.some((cell) => cell.colspan > 1 || cell.rowspan > 1 || cell.complexRowSpan === true);
239
+ return {
240
+ cells,
241
+ columnNormalization: {
242
+ mode: hasPartialFit
243
+ ? 'partial-fit-preserved'
244
+ : hasComplexSpan
245
+ ? 'complex-span-preserved'
246
+ : 'overflow-preserved',
247
+ expectedColumns: count,
248
+ actualColumns: numCols
249
+ }
250
+ };
251
+ };
252
+ const summarizeTableNormalization = (rows) => {
253
+ const issues = Array.from(new Set(rows
254
+ .map((row) => row.columnNormalization.mode)
255
+ .filter((mode) => mode !== 'exact')));
256
+ if (issues.length === 0) {
257
+ return undefined;
258
+ }
259
+ return {
260
+ mode: 'preserve-content',
261
+ issues
262
+ };
263
+ };
264
+ // Process alignment indicators in table headers
265
+ function processAlignment(alignRow) {
266
+ const alignment = [];
267
+ for (let i = 0; i < alignRow.length; i++) {
268
+ if (/^ *-+: *$/.test(alignRow[i])) {
269
+ alignment[i] = 'right';
270
+ }
271
+ else if (/^ *:-+: *$/.test(alignRow[i])) {
272
+ alignment[i] = 'center';
273
+ }
274
+ else if (/^ *:-+ *$/.test(alignRow[i])) {
275
+ alignment[i] = 'left';
276
+ }
277
+ else {
278
+ alignment[i] = null;
279
+ }
280
+ }
281
+ return alignment;
282
+ }
283
+ // Convert working cell to TH
284
+ function workingCellToTH(cell, align) {
285
+ return {
286
+ type: 'th',
287
+ rowspan: cell.rowspan,
288
+ colspan: cell.colspan,
289
+ text: cell.text,
290
+ position: cell.position,
291
+ tokens: cell.tokens,
292
+ rowSpanTarget: cell.rowSpanTarget,
293
+ complexRowSpan: cell.complexRowSpan,
294
+ relatedCell: cell.relatedCell,
295
+ align
296
+ };
297
+ }
298
+ // Convert working cell to TD
299
+ function workingCellToTD(cell, align) {
300
+ return {
301
+ type: 'td',
302
+ rowspan: cell.rowspan,
303
+ colspan: cell.colspan,
304
+ text: cell.text,
305
+ position: cell.position,
306
+ tokens: cell.tokens,
307
+ rowSpanTarget: cell.rowSpanTarget,
308
+ complexRowSpan: cell.complexRowSpan,
309
+ relatedCell: cell.relatedCell,
310
+ align
311
+ };
312
+ }
313
+ // Process table rows and add inline tokens to cells
314
+ function processRows(headerRows, bodyRows, alignment, colCount, lexer, maxColspan, detectFooter) {
315
+ const tokens = [];
316
+ const normalizationRows = [];
317
+ // Process header rows
318
+ const processedHeaderRows = [];
319
+ for (let i = 0; i < headerRows.length; i++) {
320
+ const prevRow = i > 0 ? processedHeaderRows[i - 1] : null;
321
+ const padIncompleteTail = i === headerRows.length - 1;
322
+ processedHeaderRows[i] = splitCells(headerRows[i], colCount, prevRow, maxColspan, padIncompleteTail);
323
+ }
324
+ normalizationRows.push(...processedHeaderRows);
325
+ // Convert header rows to THead (only if we have header rows)
326
+ if (processedHeaderRows.length > 0) {
327
+ const theadRows = processedHeaderRows.map((row) => ({
328
+ type: 'tr',
329
+ columnNormalization: row.columnNormalization,
330
+ placeholderColumns: row.placeholderColumns,
331
+ tokens: row.cells.map((cell) => {
332
+ // Use the cell's position to get the correct alignment
333
+ const cellAlignment = cell.position !== undefined ? alignment[cell.position] : null;
334
+ const th = workingCellToTH(cell, cellAlignment);
335
+ // Add inline tokens
336
+ th.tokens = lexer.inline(th.text, th.tokens);
337
+ return th;
338
+ })
339
+ }));
340
+ tokens.push({
341
+ type: 'thead',
342
+ tokens: theadRows
343
+ });
344
+ }
345
+ // Process body rows
346
+ if (bodyRows.length > 0) {
347
+ const processedBodyRows = [];
348
+ for (let i = 0; i < bodyRows.length; i++) {
349
+ const prevRow = i > 0 ? processedBodyRows[i - 1] : processedHeaderRows[processedHeaderRows.length - 1];
350
+ const padIncompleteTail = i === bodyRows.length - 1;
351
+ processedBodyRows[i] = splitCells(bodyRows[i], colCount, prevRow, maxColspan, padIncompleteTail);
352
+ }
353
+ normalizationRows.push(...processedBodyRows);
354
+ // Handle footer detection
355
+ let tbodyRows = processedBodyRows;
356
+ let tfootRows = [];
357
+ if (detectFooter && processedBodyRows.length > 0) {
358
+ const lastRowIndex = processedBodyRows.length - 1;
359
+ tfootRows = [processedBodyRows[lastRowIndex]];
360
+ tbodyRows = processedBodyRows.slice(0, lastRowIndex);
361
+ }
362
+ // Convert body rows to TBody if there are any
363
+ if (tbodyRows.length > 0) {
364
+ const tbodyRowTokens = tbodyRows.map((row) => ({
365
+ type: 'tr',
366
+ columnNormalization: row.columnNormalization,
367
+ placeholderColumns: row.placeholderColumns,
368
+ tokens: row.cells.map((cell) => {
369
+ // Use the cell's position to get the correct alignment
370
+ const cellAlignment = cell.position !== undefined ? alignment[cell.position] : null;
371
+ const td = workingCellToTD(cell, cellAlignment);
372
+ // Add inline tokens
373
+ td.tokens = lexer.inline(td.text, td.tokens);
374
+ return td;
375
+ })
376
+ }));
377
+ tokens.push({
378
+ type: 'tbody',
379
+ tokens: tbodyRowTokens
380
+ });
381
+ }
382
+ // Convert footer rows to TFoot if there are any
383
+ if (tfootRows.length > 0) {
384
+ const tfootRowTokens = tfootRows.map((row) => ({
385
+ type: 'tr',
386
+ columnNormalization: row.columnNormalization,
387
+ placeholderColumns: row.placeholderColumns,
388
+ tokens: row.cells.map((cell) => {
389
+ // Use the cell's position to get the correct alignment
390
+ const cellAlignment = cell.position !== undefined ? alignment[cell.position] : null;
391
+ const td = workingCellToTD(cell, cellAlignment);
392
+ // Add inline tokens
393
+ td.tokens = lexer.inline(td.text, td.tokens);
394
+ return td;
395
+ })
396
+ }));
397
+ tokens.push({
398
+ type: 'tfoot',
399
+ tokens: tfootRowTokens
400
+ });
401
+ }
402
+ }
403
+ return {
404
+ tokens,
405
+ columnNormalization: summarizeTableNormalization(normalizationRows)
406
+ };
407
+ }
408
+ const { detectFooter, maxColspan } = DEFAULT_OPTIONS;
409
+ // Adds support for extended tables in marked with row spanning, column spanning,
410
+ // multi-row headers, and column alignment
411
+ export const markedTable = {
412
+ name: 'table',
413
+ level: 'block',
414
+ start(src) {
415
+ // Check for table with potential header alignment
416
+ let match = src.match(/^\n *([^\n ].*\|.*)\n/);
417
+ if (match)
418
+ return match.index;
419
+ // Check for simple table without header alignment
420
+ match = src.match(/^\n *(\|.*\|)\n/);
421
+ if (match)
422
+ return match.index;
423
+ return undefined;
424
+ },
425
+ tokenizer(src) {
426
+ // Try to match table with header and alignment first
427
+ let regex = new RegExp('^' +
428
+ '([^\\n ].*\\|.*\\n(?: *[^\\s].*\\n)*?)' + // Header
429
+ ' {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?' + // Header Align
430
+ '(?:\\n((?:(?! *\\n| {0,3}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})' + // Body Cells
431
+ '(?:\\n+|$)| {0,3}#{1,6} | {0,3}>| {4}[^\\n]| {0,3}(?:`{3,}' +
432
+ '(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n| {0,3}(?:[*+-]|1[.)]) |' +
433
+ '<\\/?(?:address|article|aside|base|basefont|blockquote|body|' +
434
+ 'caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?: +|\\n|\\/?>)|<(?:script|pre|style|textarea|!--)).*(?:\\n|$))*)\\n*|$)');
435
+ let cap = regex.exec(src);
436
+ let hasHeaderAlignment = true;
437
+ // If no match with header alignment, try table without header alignment
438
+ if (!cap) {
439
+ // Simple tables still require at least two pipe-delimited rows.
440
+ regex = /^(\|.*\|\n\|.*\|(?:\n\|.*\|)*)/;
441
+ cap = regex.exec(src);
442
+ hasHeaderAlignment = false;
443
+ }
444
+ if (!cap)
445
+ return undefined;
446
+ // Combine all captured groups to get complete table rows
447
+ let allTableContent = cap[1]; // Headers
448
+ if (cap[2])
449
+ allTableContent += '\n' + cap[2]; // Alignment row
450
+ if (cap[3])
451
+ allTableContent += '\n' + cap[3]; // Body rows
452
+ const allRows = allTableContent.replace(/\n$/, '').split('\n');
453
+ let headerRows = [];
454
+ let bodyRows = [];
455
+ let alignRow = [];
456
+ let alignment = [];
457
+ let colCount = 0;
458
+ if (hasHeaderAlignment) {
459
+ // Traditional table with header and alignment
460
+ // Parse all rows and identify which are headers vs body
461
+ let headerEndIndex = -1;
462
+ // Find the FIRST alignment row (contains dashes/underscores/asterisks)
463
+ for (let i = 0; i < allRows.length; i++) {
464
+ const row = allRows[i].trim();
465
+ const isAlignment = /^ *(\| *)?:?-+:? *(\| *:?-+:? *)*(\| *)?$/.test(row);
466
+ // Check if this row matches alignment pattern (contains only |, spaces, and alignment chars)
467
+ if (isAlignment) {
468
+ headerEndIndex = i;
469
+ alignRow = row.replace(/^ *\| *| *\| *$/g, '').split(/ *\| */);
470
+ break; // Stop at the first alignment row
471
+ }
472
+ }
473
+ if (headerEndIndex === -1) {
474
+ // No alignment row found, treat as simple table
475
+ bodyRows = allRows;
476
+ colCount = bodyRows[0].split('|').filter((cell) => cell.trim() !== '').length;
477
+ alignment = new Array(colCount).fill(null);
478
+ }
479
+ else {
480
+ // Found alignment row, split headers and body
481
+ // Filter out empty rows and the alignment row itself from headers
482
+ headerRows = allRows.slice(0, headerEndIndex).filter((row) => row.trim() !== '');
483
+ const headerCellCount = splitRow(headerRows[0] ?? '').filter((cell) => cell.length > 0).length;
484
+ bodyRows = headerEndIndex + 1 < allRows.length ? allRows.slice(headerEndIndex + 1) : [];
485
+ // Use alignment row length as the authoritative column count
486
+ colCount = alignRow.length;
487
+ // Validate that we have a reasonable table structure
488
+ if (colCount === 0 || (headerCellCount > 0 && colCount < headerCellCount))
489
+ return undefined;
490
+ // Process alignment
491
+ alignment = processAlignment(alignRow);
492
+ }
493
+ }
494
+ else {
495
+ // Table without header alignment - treat all rows as body rows
496
+ bodyRows = allRows;
497
+ const firstRowCells = bodyRows[0].split('|').filter((cell) => cell.trim() !== '');
498
+ colCount = firstRowCells.length;
499
+ alignment = new Array(colCount).fill(null); // No alignment for tables without headers
500
+ }
501
+ // Detect footer alignment row pattern in body rows (only for tables with header alignment)
502
+ let shouldDetectFooter = false;
503
+ let processedBodyRows = bodyRows;
504
+ if (detectFooter && hasHeaderAlignment && bodyRows.length > 0) {
505
+ // Check if any row matches the alignment pattern (contains only dashes, pipes, colons, and spaces)
506
+ for (let i = bodyRows.length - 1; i >= 0; i--) {
507
+ const row = bodyRows[i];
508
+ if (/^ *\| *:?-+:? *(\| *:?-+:? *)*\| *$/.test(row)) {
509
+ // Found footer alignment row - remove it and enable footer detection
510
+ shouldDetectFooter = true;
511
+ processedBodyRows = bodyRows.slice(0, i).concat(bodyRows.slice(i + 1));
512
+ break;
513
+ }
514
+ }
515
+ }
516
+ // Process all rows and create table sections
517
+ const processedTable = processRows(headerRows, processedBodyRows, alignment, colCount, this.lexer, maxColspan, shouldDetectFooter);
518
+ const item = {
519
+ type: 'table',
520
+ tokens: processedTable.tokens,
521
+ raw: cap[0],
522
+ align: alignment,
523
+ columnNormalization: processedTable.columnNormalization
524
+ };
525
+ return item;
526
+ }
527
+ };
@@ -0,0 +1,19 @@
1
+ import { type PluginConfig } from './plugins.js';
2
+ export type { AllowedTags, AnimateOptions, BlockProps, CodeControlsConfig, Components, ControlsConfig, IconMap, LinkSafetyConfig, LinkSafetyModalProps, MermaidControls, MermaidErrorComponentProps, MermaidOptions, NormalizedMermaidControls, ResolvedAnimationConfig, Snippets, StreamdownComponents, StreamdownContext as StreamdownContextType, StreamdownControlsConfig, StreamdownProps, TableControlsConfig } from './contracts/streamdown.js';
3
+ export { STREAMDOWN_CONTEXT_KEY } from './context-key.js';
4
+ export { StreamdownContext, useStreamdown } from './context.svelte.js';
5
+ type PluginContextGetter = {
6
+ getValue: () => PluginConfig | null;
7
+ };
8
+ export declare const PluginContext: {
9
+ key: symbol;
10
+ provide(getValue: () => PluginConfig | null): PluginContextGetter;
11
+ set(plugins: PluginConfig | null | undefined): PluginContextGetter;
12
+ get(): PluginConfig | null;
13
+ };
14
+ export declare function usePlugins(): PluginConfig | null;
15
+ export declare function useCodePlugin(): import("@streamdown-svelte/plugin-core").CodeHighlighterPlugin | null;
16
+ export declare function useMermaidPlugin(): import("@streamdown-svelte/plugin-core").DiagramPlugin | null;
17
+ export declare function useMathPlugin(): import("@streamdown-svelte/plugin-core").MathPlugin | null;
18
+ export declare function useCjkPlugin(): import("@streamdown-svelte/plugin-core").CjkPlugin | null;
19
+ export declare function useCustomRenderer(language: string): import("./plugins.js").CustomRenderer | null;
@@ -0,0 +1,40 @@
1
+ import { getContext, setContext } from 'svelte';
2
+ import { findCustomRenderer } from './plugins.js';
3
+ export { STREAMDOWN_CONTEXT_KEY } from './context-key.js';
4
+ export { StreamdownContext, useStreamdown } from './context.svelte.js';
5
+ const PLUGIN_CONTEXT_KEY = Symbol('streamdown.plugins');
6
+ const defaultPluginGetter = {
7
+ getValue: () => null
8
+ };
9
+ export const PluginContext = {
10
+ key: PLUGIN_CONTEXT_KEY,
11
+ provide(getValue) {
12
+ const value = { getValue };
13
+ setContext(PLUGIN_CONTEXT_KEY, value);
14
+ return value;
15
+ },
16
+ set(plugins) {
17
+ return this.provide(() => plugins ?? null);
18
+ },
19
+ get() {
20
+ return (getContext(PLUGIN_CONTEXT_KEY) ?? defaultPluginGetter).getValue();
21
+ }
22
+ };
23
+ export function usePlugins() {
24
+ return PluginContext.get();
25
+ }
26
+ export function useCodePlugin() {
27
+ return usePlugins()?.code ?? null;
28
+ }
29
+ export function useMermaidPlugin() {
30
+ return usePlugins()?.mermaid ?? null;
31
+ }
32
+ export function useMathPlugin() {
33
+ return usePlugins()?.math ?? null;
34
+ }
35
+ export function useCjkPlugin() {
36
+ return usePlugins()?.cjk ?? null;
37
+ }
38
+ export function useCustomRenderer(language) {
39
+ return findCustomRenderer(usePlugins()?.renderers, language) ?? null;
40
+ }
@@ -0,0 +1 @@
1
+ export { cjk, createCjkPlugin, type CjkPlugin } from '@streamdown-svelte/plugin-core';
@@ -0,0 +1 @@
1
+ export { cjk, createCjkPlugin } from '@streamdown-svelte/plugin-core';