@svadmin/ai-elements 0.7.4 → 0.8.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 (214) hide show
  1. package/README.md +20 -4
  2. package/THIRD_PARTY_NOTICES.md +67 -6
  3. package/dist/ai.css +1 -5
  4. package/dist/ai.theme.css +1 -0
  5. package/dist/class-properties.generated.d.ts +1 -0
  6. package/dist/class-properties.generated.js +2 -0
  7. package/dist/classnames.d.ts +8 -0
  8. package/dist/classnames.js +26 -0
  9. package/dist/components/Response.svelte +2 -2
  10. package/dist/components/Response.svelte.d.ts +1 -1
  11. package/dist/components/code/index.d.ts +9 -18
  12. package/dist/components/code/index.js +8 -11
  13. package/dist/components/code-block/highlight.js +1 -1
  14. package/dist/utilities.css +3172 -0
  15. package/dist/utils.d.ts +1 -1
  16. package/dist/utils.js +1 -1
  17. package/package.json +36 -11
  18. package/vendor/streamdown/AnimatedText.svelte +93 -0
  19. package/vendor/streamdown/AnimatedText.svelte.d.ts +6 -0
  20. package/vendor/streamdown/Block.svelte +96 -0
  21. package/vendor/streamdown/Block.svelte.d.ts +11 -0
  22. package/vendor/streamdown/Elements/Alert.svelte +69 -0
  23. package/vendor/streamdown/Elements/Alert.svelte.d.ts +10 -0
  24. package/vendor/streamdown/Elements/Citation.svelte +260 -0
  25. package/vendor/streamdown/Elements/Citation.svelte.d.ts +7 -0
  26. package/vendor/streamdown/Elements/Code.svelte +226 -0
  27. package/vendor/streamdown/Elements/Code.svelte.d.ts +9 -0
  28. package/vendor/streamdown/Elements/Element.svelte +574 -0
  29. package/vendor/streamdown/Elements/Element.svelte.d.ts +10 -0
  30. package/vendor/streamdown/Elements/FootnoteRef.svelte +30 -0
  31. package/vendor/streamdown/Elements/FootnoteRef.svelte.d.ts +7 -0
  32. package/vendor/streamdown/Elements/Footnotes.svelte +54 -0
  33. package/vendor/streamdown/Elements/Footnotes.svelte.d.ts +7 -0
  34. package/vendor/streamdown/Elements/Image.svelte +200 -0
  35. package/vendor/streamdown/Elements/Image.svelte.d.ts +10 -0
  36. package/vendor/streamdown/Elements/Link.svelte +220 -0
  37. package/vendor/streamdown/Elements/Link.svelte.d.ts +10 -0
  38. package/vendor/streamdown/Elements/LinkSafetyModal.svelte +121 -0
  39. package/vendor/streamdown/Elements/LinkSafetyModal.svelte.d.ts +4 -0
  40. package/vendor/streamdown/Elements/Math.svelte +100 -0
  41. package/vendor/streamdown/Elements/Math.svelte.d.ts +9 -0
  42. package/vendor/streamdown/Elements/Mermaid.svelte +455 -0
  43. package/vendor/streamdown/Elements/Mermaid.svelte.d.ts +9 -0
  44. package/vendor/streamdown/Elements/MermaidDownload.svelte +145 -0
  45. package/vendor/streamdown/Elements/MermaidDownload.svelte.d.ts +8 -0
  46. package/vendor/streamdown/Elements/Slot.svelte +23 -0
  47. package/vendor/streamdown/Elements/Slot.svelte.d.ts +10 -0
  48. package/vendor/streamdown/Elements/Table.svelte +195 -0
  49. package/vendor/streamdown/Elements/Table.svelte.d.ts +9 -0
  50. package/vendor/streamdown/Elements/TableDownload.svelte +221 -0
  51. package/vendor/streamdown/Elements/TableDownload.svelte.d.ts +8 -0
  52. package/vendor/streamdown/Elements/fallbacks/CodeFallback.svelte +41 -0
  53. package/vendor/streamdown/Elements/fallbacks/CodeFallback.svelte.d.ts +9 -0
  54. package/vendor/streamdown/Elements/fallbacks/MathFallback.svelte +35 -0
  55. package/vendor/streamdown/Elements/fallbacks/MathFallback.svelte.d.ts +8 -0
  56. package/vendor/streamdown/Elements/fallbacks/MermaidFallback.svelte +36 -0
  57. package/vendor/streamdown/Elements/fallbacks/MermaidFallback.svelte.d.ts +9 -0
  58. package/vendor/streamdown/Elements/fallbacks/index.d.ts +3 -0
  59. package/vendor/streamdown/Elements/fallbacks/index.js +3 -0
  60. package/vendor/streamdown/Elements/icons.d.ts +31 -0
  61. package/vendor/streamdown/Elements/icons.js +200 -0
  62. package/vendor/streamdown/Elements/index.d.ts +8 -0
  63. package/vendor/streamdown/Elements/index.js +8 -0
  64. package/vendor/streamdown/Elements/popover.svelte.d.ts +8 -0
  65. package/vendor/streamdown/Elements/popover.svelte.js +45 -0
  66. package/vendor/streamdown/Elements/stepperState.svelte.d.ts +36 -0
  67. package/vendor/streamdown/Elements/stepperState.svelte.js +92 -0
  68. package/vendor/streamdown/IconProvider.svelte +11 -0
  69. package/vendor/streamdown/IconProvider.svelte.d.ts +30 -0
  70. package/vendor/streamdown/LICENSE +202 -0
  71. package/vendor/streamdown/PluginProvider.svelte +11 -0
  72. package/vendor/streamdown/PluginProvider.svelte.d.ts +30 -0
  73. package/vendor/streamdown/README.svadmin.md +5 -0
  74. package/vendor/streamdown/Streamdown.svelte +447 -0
  75. package/vendor/streamdown/Streamdown.svelte.d.ts +25 -0
  76. package/vendor/streamdown/block/BlockTokens.svelte +45 -0
  77. package/vendor/streamdown/block/BlockTokens.svelte.d.ts +9 -0
  78. package/vendor/streamdown/block/html.d.ts +14 -0
  79. package/vendor/streamdown/block/html.js +27 -0
  80. package/vendor/streamdown/block/text.d.ts +10 -0
  81. package/vendor/streamdown/block/text.js +31 -0
  82. package/vendor/streamdown/context-key.d.ts +1 -0
  83. package/vendor/streamdown/context-key.js +1 -0
  84. package/vendor/streamdown/context.svelte.d.ts +24 -0
  85. package/vendor/streamdown/context.svelte.js +75 -0
  86. package/vendor/streamdown/contracts/plugins.d.ts +26 -0
  87. package/vendor/streamdown/contracts/plugins.js +1 -0
  88. package/vendor/streamdown/contracts/streamdown.d.ts +374 -0
  89. package/vendor/streamdown/contracts/streamdown.js +29 -0
  90. package/vendor/streamdown/detect-direction.d.ts +1 -0
  91. package/vendor/streamdown/detect-direction.js +1 -0
  92. package/vendor/streamdown/icon-context.d.ts +36 -0
  93. package/vendor/streamdown/icon-context.js +52 -0
  94. package/vendor/streamdown/incomplete-code.d.ts +6 -0
  95. package/vendor/streamdown/incomplete-code.js +23 -0
  96. package/vendor/streamdown/index.d.ts +22 -0
  97. package/vendor/streamdown/index.js +20 -0
  98. package/vendor/streamdown/markdown-parse-cache.d.ts +37 -0
  99. package/vendor/streamdown/markdown-parse-cache.js +109 -0
  100. package/vendor/streamdown/markdown.d.ts +21 -0
  101. package/vendor/streamdown/markdown.js +214 -0
  102. package/vendor/streamdown/marked/index.d.ts +44 -0
  103. package/vendor/streamdown/marked/index.js +228 -0
  104. package/vendor/streamdown/marked/marked-alert.d.ts +13 -0
  105. package/vendor/streamdown/marked/marked-alert.js +47 -0
  106. package/vendor/streamdown/marked/marked-align.d.ts +10 -0
  107. package/vendor/streamdown/marked/marked-align.js +45 -0
  108. package/vendor/streamdown/marked/marked-br.d.ts +6 -0
  109. package/vendor/streamdown/marked/marked-br.js +15 -0
  110. package/vendor/streamdown/marked/marked-citations.d.ts +8 -0
  111. package/vendor/streamdown/marked/marked-citations.js +53 -0
  112. package/vendor/streamdown/marked/marked-cjk.d.ts +2 -0
  113. package/vendor/streamdown/marked/marked-cjk.js +165 -0
  114. package/vendor/streamdown/marked/marked-dl.d.ts +23 -0
  115. package/vendor/streamdown/marked/marked-dl.js +44 -0
  116. package/vendor/streamdown/marked/marked-footnotes.d.ts +26 -0
  117. package/vendor/streamdown/marked/marked-footnotes.js +101 -0
  118. package/vendor/streamdown/marked/marked-hr.d.ts +6 -0
  119. package/vendor/streamdown/marked/marked-hr.js +18 -0
  120. package/vendor/streamdown/marked/marked-list.d.ts +31 -0
  121. package/vendor/streamdown/marked/marked-list.js +330 -0
  122. package/vendor/streamdown/marked/marked-math.d.ts +13 -0
  123. package/vendor/streamdown/marked/marked-math.js +129 -0
  124. package/vendor/streamdown/marked/marked-mdx.d.ts +12 -0
  125. package/vendor/streamdown/marked/marked-mdx.js +124 -0
  126. package/vendor/streamdown/marked/marked-subsup.d.ts +22 -0
  127. package/vendor/streamdown/marked/marked-subsup.js +40 -0
  128. package/vendor/streamdown/marked/marked-table.d.ts +80 -0
  129. package/vendor/streamdown/marked/marked-table.js +527 -0
  130. package/vendor/streamdown/plugin-context.d.ts +19 -0
  131. package/vendor/streamdown/plugin-context.js +40 -0
  132. package/vendor/streamdown/plugins/cjk-shared.d.ts +1 -0
  133. package/vendor/streamdown/plugins/cjk-shared.js +1 -0
  134. package/vendor/streamdown/plugins.d.ts +19 -0
  135. package/vendor/streamdown/plugins.js +107 -0
  136. package/vendor/streamdown/provenance.json +229 -0
  137. package/vendor/streamdown/remend.d.ts +2 -0
  138. package/vendor/streamdown/remend.js +1 -0
  139. package/vendor/streamdown/security/html.d.ts +19 -0
  140. package/vendor/streamdown/security/html.js +329 -0
  141. package/vendor/streamdown/security/preprocess-custom-tags.d.ts +1 -0
  142. package/vendor/streamdown/security/preprocess-custom-tags.js +20 -0
  143. package/vendor/streamdown/security/preprocess-literal-tag-content.d.ts +1 -0
  144. package/vendor/streamdown/security/preprocess-literal-tag-content.js +16 -0
  145. package/vendor/streamdown/security/types.d.ts +1 -0
  146. package/vendor/streamdown/security/types.js +1 -0
  147. package/vendor/streamdown/site/SiteHeader.svelte +94 -0
  148. package/vendor/streamdown/site/SiteHeader.svelte.d.ts +6 -0
  149. package/vendor/streamdown/site/home/HomeDemo.svelte +122 -0
  150. package/vendor/streamdown/site/home/HomeDemo.svelte.d.ts +3 -0
  151. package/vendor/streamdown/site/home/HomePage.svelte +293 -0
  152. package/vendor/streamdown/site/home/HomePage.svelte.d.ts +3 -0
  153. package/vendor/streamdown/site/home/content.d.ts +69 -0
  154. package/vendor/streamdown/site/home/content.js +144 -0
  155. package/vendor/streamdown/site/metadata.d.ts +4 -0
  156. package/vendor/streamdown/site/metadata.js +4 -0
  157. package/vendor/streamdown/site/navigation.d.ts +6 -0
  158. package/vendor/streamdown/site/navigation.js +22 -0
  159. package/vendor/streamdown/streamdown/config.d.ts +41 -0
  160. package/vendor/streamdown/streamdown/config.js +125 -0
  161. package/vendor/streamdown/streamdown/context.d.ts +12 -0
  162. package/vendor/streamdown/streamdown/context.js +2 -0
  163. package/vendor/streamdown/streamdown/incomplete-markdown.d.ts +5 -0
  164. package/vendor/streamdown/streamdown/incomplete-markdown.js +79 -0
  165. package/vendor/streamdown/streamdown/pipeline.d.ts +95 -0
  166. package/vendor/streamdown/streamdown/pipeline.js +138 -0
  167. package/vendor/streamdown/streamdown/runtime.d.ts +59 -0
  168. package/vendor/streamdown/streamdown/runtime.js +112 -0
  169. package/vendor/streamdown/streaming.d.ts +5 -0
  170. package/vendor/streamdown/streaming.js +5 -0
  171. package/vendor/streamdown/theme.d.ts +486 -0
  172. package/vendor/streamdown/theme.js +370 -0
  173. package/vendor/streamdown/translations.d.ts +43 -0
  174. package/vendor/streamdown/translations.js +54 -0
  175. package/vendor/streamdown/url-policy.d.ts +1 -0
  176. package/vendor/streamdown/url-policy.js +1 -0
  177. package/vendor/streamdown/utils/bind.d.ts +8 -0
  178. package/vendor/streamdown/utils/bind.js +26 -0
  179. package/vendor/streamdown/utils/bundledLanguages.d.ts +1 -0
  180. package/vendor/streamdown/utils/bundledLanguages.js +1 -0
  181. package/vendor/streamdown/utils/code-block.d.ts +8 -0
  182. package/vendor/streamdown/utils/code-block.js +38 -0
  183. package/vendor/streamdown/utils/copy.svelte.d.ts +7 -0
  184. package/vendor/streamdown/utils/copy.svelte.js +38 -0
  185. package/vendor/streamdown/utils/darkMode.svelte.d.ts +3 -0
  186. package/vendor/streamdown/utils/darkMode.svelte.js +49 -0
  187. package/vendor/streamdown/utils/detectDirection.d.ts +1 -0
  188. package/vendor/streamdown/utils/detectDirection.js +19 -0
  189. package/vendor/streamdown/utils/get.d.ts +1 -0
  190. package/vendor/streamdown/utils/get.js +25 -0
  191. package/vendor/streamdown/utils/hightlighter.svelte.d.ts +30 -0
  192. package/vendor/streamdown/utils/hightlighter.svelte.js +524 -0
  193. package/vendor/streamdown/utils/index.d.ts +3 -0
  194. package/vendor/streamdown/utils/index.js +3 -0
  195. package/vendor/streamdown/utils/mermaid.d.ts +13 -0
  196. package/vendor/streamdown/utils/mermaid.js +49 -0
  197. package/vendor/streamdown/utils/panzoom.svelte.d.ts +35 -0
  198. package/vendor/streamdown/utils/panzoom.svelte.js +556 -0
  199. package/vendor/streamdown/utils/parse-incomplete-markdown.d.ts +2 -0
  200. package/vendor/streamdown/utils/parse-incomplete-markdown.js +2 -0
  201. package/vendor/streamdown/utils/runtime-env.d.ts +1 -0
  202. package/vendor/streamdown/utils/runtime-env.js +13 -0
  203. package/vendor/streamdown/utils/save.d.ts +1 -0
  204. package/vendor/streamdown/utils/save.js +14 -0
  205. package/vendor/streamdown/utils/scroll-lock.d.ts +2 -0
  206. package/vendor/streamdown/utils/scroll-lock.js +35 -0
  207. package/vendor/streamdown/utils/table.d.ts +8 -0
  208. package/vendor/streamdown/utils/table.js +176 -0
  209. package/vendor/streamdown/utils/url.d.ts +22 -0
  210. package/vendor/streamdown/utils/url.js +98 -0
  211. package/vendor/streamdown/utils/useClickOutside.svelte.d.ts +8 -0
  212. package/vendor/streamdown/utils/useClickOutside.svelte.js +41 -0
  213. package/vendor/streamdown/utils/useKeyDown.svelte.d.ts +5 -0
  214. package/vendor/streamdown/utils/useKeyDown.svelte.js +23 -0
@@ -0,0 +1,13 @@
1
+ import type { Extension } from './index.js';
2
+ import type { Tokenizer, Tokens } from 'marked';
3
+ type variantType = 'note' | 'tip' | 'important' | 'warning' | 'caution';
4
+ export declare function createSyntaxPattern(type: variantType): string;
5
+ export declare const markedAlert: Extension;
6
+ export declare function processAlertToken(token: Tokens.Blockquote, tokenizer: Tokenizer): void;
7
+ export type AlertToken = {
8
+ type: 'alert';
9
+ variant: variantType;
10
+ raw: string;
11
+ text: string;
12
+ };
13
+ export {};
@@ -0,0 +1,47 @@
1
+ import { Lexer } from 'marked';
2
+ const variants = ['note', 'tip', 'important', 'warning', 'caution'];
3
+ export function createSyntaxPattern(type) {
4
+ return `^\\s*[\\*_]*\\[!${type.toUpperCase()}\\][\\*_]*\\s*`;
5
+ }
6
+ const defaultLexer = new Lexer({ gfm: true });
7
+ const defaultTokenizer = defaultLexer.options.tokenizer;
8
+ export const markedAlert = {
9
+ name: 'alert',
10
+ level: 'block',
11
+ tokenizer(src) {
12
+ const cap = defaultTokenizer.rules.block.blockquote.exec(src);
13
+ if (cap) {
14
+ const blockquoteToken = defaultTokenizer.blockquote(src);
15
+ blockquoteToken && processAlertToken(blockquoteToken, this.lexer.options.tokenizer);
16
+ return blockquoteToken;
17
+ }
18
+ }
19
+ };
20
+ export function processAlertToken(token, tokenizer) {
21
+ const matchedVariant = variants.find((type) => new RegExp(createSyntaxPattern(type), 'i').test(('text' in token && token.text) || ''));
22
+ if (!matchedVariant) {
23
+ Object.assign(token, {
24
+ tokens: token.tokens
25
+ .map((token) => {
26
+ return tokenizer.lexer.blockTokens(token.raw, [])[0];
27
+ })
28
+ .filter(Boolean)
29
+ });
30
+ return;
31
+ }
32
+ const alertPattern = new RegExp(`[\\*_]*\\[!${matchedVariant.toUpperCase()}\\][\\*_]*`, 'g');
33
+ const tokens = token.tokens
34
+ .map((token) => {
35
+ let cleanedRaw = token.raw;
36
+ // Remove alert markers with any markdown formatting (asterisks/underscores)
37
+ cleanedRaw = cleanedRaw.replaceAll(alertPattern, '').trim();
38
+ return tokenizer.lexer.blockTokens(cleanedRaw, [])[0];
39
+ })
40
+ .filter(Boolean);
41
+ Object.assign(token, {
42
+ type: 'alert',
43
+ variant: matchedVariant,
44
+ tokens,
45
+ text: token.text.replace(alertPattern, '').trim()
46
+ });
47
+ }
@@ -0,0 +1,10 @@
1
+ import type { Extension } from './index.js';
2
+ import type { Token } from 'marked';
3
+ export declare const markedAlign: Extension;
4
+ export type AlignToken = {
5
+ type: 'align';
6
+ align: 'center' | 'right';
7
+ raw: string;
8
+ text: string;
9
+ tokens: Token[];
10
+ };
@@ -0,0 +1,45 @@
1
+ const tokenizeAlignBlock = (src, align, blockTokens) => {
2
+ const openingTag = `[${align}]`;
3
+ const closingTag = `[/${align}]`;
4
+ if (!src.startsWith(openingTag)) {
5
+ return undefined;
6
+ }
7
+ const lines = src.split('\n');
8
+ if (lines[0].trim() !== openingTag) {
9
+ return undefined;
10
+ }
11
+ let contentEndLine = -1;
12
+ let hasClosingTag = false;
13
+ for (let i = 1; i < lines.length; i++) {
14
+ const trimmed = lines[i].trim();
15
+ if (trimmed === closingTag) {
16
+ contentEndLine = i - 1;
17
+ hasClosingTag = true;
18
+ break;
19
+ }
20
+ if (trimmed === '[center]' || trimmed === '[right]') {
21
+ contentEndLine = i - 1;
22
+ break;
23
+ }
24
+ }
25
+ if (contentEndLine === -1 && !hasClosingTag) {
26
+ return undefined;
27
+ }
28
+ const text = lines.slice(1, contentEndLine + 1).join('\n');
29
+ const raw = lines.slice(0, hasClosingTag ? contentEndLine + 2 : contentEndLine + 1).join('\n');
30
+ return {
31
+ type: 'align',
32
+ align,
33
+ raw,
34
+ text,
35
+ tokens: blockTokens(text, [])
36
+ };
37
+ };
38
+ export const markedAlign = {
39
+ name: 'align',
40
+ level: 'block',
41
+ tokenizer(src) {
42
+ return (tokenizeAlignBlock(src, 'center', this.lexer.blockTokens.bind(this.lexer)) ??
43
+ tokenizeAlignBlock(src, 'right', this.lexer.blockTokens.bind(this.lexer)));
44
+ }
45
+ };
@@ -0,0 +1,6 @@
1
+ import type { Extension } from './index.js';
2
+ export interface BrToken {
3
+ type: 'br';
4
+ raw: string;
5
+ }
6
+ export declare const markedBr: Extension;
@@ -0,0 +1,15 @@
1
+ export const markedBr = {
2
+ name: 'br',
3
+ level: 'inline',
4
+ tokenizer(src) {
5
+ // Match HTML <br> tags (with or without closing slash, case insensitive)
6
+ const match = src.match(/^<br\s*\/?>/i);
7
+ if (match) {
8
+ return {
9
+ type: 'br',
10
+ raw: match[0]
11
+ };
12
+ }
13
+ return undefined;
14
+ }
15
+ };
@@ -0,0 +1,8 @@
1
+ import type { Extension } from './index.js';
2
+ export declare const markedCitations: Extension;
3
+ export type CitationToken = {
4
+ type: 'inline-citations';
5
+ keys: string[];
6
+ text: string;
7
+ raw: string;
8
+ };
@@ -0,0 +1,53 @@
1
+ export const markedCitations = {
2
+ name: 'citations',
3
+ level: 'inline',
4
+ start(src) {
5
+ return src.indexOf('[') === -1 ? -1 : 0;
6
+ },
7
+ tokenizer(src) {
8
+ // Match inline citations like [1], [ref], [1] [2], [ref] [ref2], etc.
9
+ // Requires non-empty bracket contents and spaces between adjacent citation brackets
10
+ const match = src.match(/^\[[^\[\]]+\](?:\s+\[[^\[\]]+\])*/);
11
+ if (match) {
12
+ // Nested brackets are more likely link/image text than citation syntax.
13
+ const firstClosingBracketIndex = src.indexOf(']');
14
+ if (match[0].slice(1, firstClosingBracketIndex).includes('[')) {
15
+ return undefined;
16
+ }
17
+ // Early exit: if first closing bracket is immediately followed by '[', it's likely link-style syntax
18
+ if (firstClosingBracketIndex !== -1 && src[firstClosingBracketIndex + 1] === '[') {
19
+ return undefined;
20
+ }
21
+ // If followed by parentheses, it's likely a markdown link or image, so don't treat as citation
22
+ const remainingSrc = src.slice(match[0].length);
23
+ if (remainingSrc.match(/^\s*\(/)) {
24
+ return undefined;
25
+ }
26
+ // Extract all citation keys (anything inside brackets)
27
+ const citations = match[0].match(/\[([^\]]+)\]/g);
28
+ if (citations) {
29
+ // Filter out task list syntax ([ ], [x], [X]) after trimming
30
+ const validCitations = citations.filter((citation) => {
31
+ const content = citation.slice(1, -1).trim();
32
+ return content !== '' && content !== 'x' && content !== 'X';
33
+ });
34
+ if (validCitations.length > 0) {
35
+ // Process each bracket content and split on spaces, commas, or semicolons
36
+ const keys = validCitations.flatMap((citation) => {
37
+ const content = citation.slice(1, -1).trim(); // Remove brackets and trim
38
+ // Split on spaces, commas, or semicolons and filter out empty strings
39
+ return content.split(/[\s,;]+/).filter((key) => key.length > 0);
40
+ });
41
+ // Deduplicate keys after trimming
42
+ const uniqueKeys = Array.from(new Set(keys.map((key) => key.trim()).filter((key) => key.length > 0)));
43
+ return {
44
+ type: 'inline-citations',
45
+ keys: uniqueKeys,
46
+ text: match[0],
47
+ raw: match[0]
48
+ };
49
+ }
50
+ }
51
+ }
52
+ }
53
+ };
@@ -0,0 +1,2 @@
1
+ import type { Extension } from './index.js';
2
+ export declare const markedCjk: Extension[];
@@ -0,0 +1,165 @@
1
+ const CJK_AUTOLINK_BOUNDARY_CHARS = new Set([
2
+ '。',
3
+ '.',
4
+ ',',
5
+ '、',
6
+ '?',
7
+ '!',
8
+ ':',
9
+ ';',
10
+ '(',
11
+ ')',
12
+ '【',
13
+ '】',
14
+ '「',
15
+ '」',
16
+ '『',
17
+ '』',
18
+ '〈',
19
+ '〉',
20
+ '《',
21
+ '》'
22
+ ]);
23
+ const AUTOLINK_PREFIXES = ['https://', 'http://', 'mailto:', 'www.'];
24
+ const DELIMITER_CONFIGS = [
25
+ {
26
+ delimiter: '***',
27
+ type: 'em',
28
+ buildText: (content) => `**${content}**`
29
+ },
30
+ {
31
+ delimiter: '**',
32
+ type: 'strong',
33
+ buildText: (content) => content
34
+ },
35
+ {
36
+ delimiter: '~~',
37
+ type: 'del',
38
+ buildText: (content) => content
39
+ },
40
+ {
41
+ delimiter: '*',
42
+ type: 'em',
43
+ buildText: (content) => content
44
+ }
45
+ ];
46
+ function containsCjkBoundaryChar(value) {
47
+ for (const char of value) {
48
+ if (CJK_AUTOLINK_BOUNDARY_CHARS.has(char)) {
49
+ return true;
50
+ }
51
+ }
52
+ return false;
53
+ }
54
+ function hasNonWhitespaceBoundaryContent(value) {
55
+ return value.length > 0 && value.trim() === value;
56
+ }
57
+ function findDelimitedMatch(src, delimiter) {
58
+ if (!src.startsWith(delimiter)) {
59
+ return;
60
+ }
61
+ const closingIndex = src.indexOf(delimiter, delimiter.length);
62
+ if (closingIndex === -1) {
63
+ return;
64
+ }
65
+ const content = src.slice(delimiter.length, closingIndex);
66
+ if (!hasNonWhitespaceBoundaryContent(content) || !containsCjkBoundaryChar(content)) {
67
+ return;
68
+ }
69
+ return {
70
+ raw: src.slice(0, closingIndex + delimiter.length),
71
+ content
72
+ };
73
+ }
74
+ function createInlineTextToken(text) {
75
+ return {
76
+ type: 'text',
77
+ raw: text,
78
+ text,
79
+ escaped: false
80
+ };
81
+ }
82
+ function createAutolinkHref(text) {
83
+ return text.startsWith('www.') ? `http://${text}` : text;
84
+ }
85
+ function findAutolinkPrefixIndex(src) {
86
+ const indexes = AUTOLINK_PREFIXES.map((prefix) => {
87
+ const index = src.toLowerCase().indexOf(prefix);
88
+ return index === -1 ? Number.POSITIVE_INFINITY : index;
89
+ });
90
+ const firstIndex = Math.min(...indexes);
91
+ return Number.isFinite(firstIndex) ? firstIndex : undefined;
92
+ }
93
+ function createAutolinkToken(raw) {
94
+ return {
95
+ type: 'link',
96
+ raw,
97
+ href: createAutolinkHref(raw),
98
+ title: null,
99
+ text: raw,
100
+ tokens: [createInlineTextToken(raw)]
101
+ };
102
+ }
103
+ function findAutolinkBoundaryMatch(src) {
104
+ const prefix = AUTOLINK_PREFIXES.find((candidate) => src.toLowerCase().startsWith(candidate));
105
+ if (!prefix) {
106
+ return;
107
+ }
108
+ let index = prefix.length;
109
+ let sawBoundary = false;
110
+ while (index < src.length) {
111
+ const char = src[index];
112
+ if (/\s/.test(char)) {
113
+ break;
114
+ }
115
+ if (CJK_AUTOLINK_BOUNDARY_CHARS.has(char)) {
116
+ sawBoundary = true;
117
+ break;
118
+ }
119
+ index += 1;
120
+ }
121
+ if (!sawBoundary || index === prefix.length) {
122
+ return;
123
+ }
124
+ return src.slice(0, index);
125
+ }
126
+ function createCjkDelimitedExtension(config) {
127
+ return {
128
+ name: `cjk-${config.type}-${config.delimiter.length}`,
129
+ level: 'inline',
130
+ start(src) {
131
+ const firstIndex = src.indexOf(config.delimiter[0]);
132
+ return firstIndex === -1 ? undefined : firstIndex;
133
+ },
134
+ tokenizer(src) {
135
+ const match = findDelimitedMatch(src, config.delimiter);
136
+ if (!match) {
137
+ return;
138
+ }
139
+ const text = config.buildText(match.content);
140
+ return {
141
+ type: config.type,
142
+ raw: match.raw,
143
+ text,
144
+ tokens: this.lexer.inlineTokens(text)
145
+ };
146
+ }
147
+ };
148
+ }
149
+ export const markedCjk = [
150
+ {
151
+ name: 'cjk-autolink-boundary',
152
+ level: 'inline',
153
+ start(src) {
154
+ return findAutolinkPrefixIndex(src);
155
+ },
156
+ tokenizer(src) {
157
+ const match = findAutolinkBoundaryMatch(src);
158
+ if (!match) {
159
+ return;
160
+ }
161
+ return createAutolinkToken(match);
162
+ }
163
+ },
164
+ ...DELIMITER_CONFIGS.map(createCjkDelimitedExtension)
165
+ ];
@@ -0,0 +1,23 @@
1
+ import type { Extension, GenericToken } from './index.js';
2
+ export declare const markedDl: Extension;
3
+ export type DescriptionListToken = {
4
+ type: 'descriptionList';
5
+ raw: string;
6
+ text: string;
7
+ tokens: DescriptionToken[];
8
+ };
9
+ export type DescriptionToken = {
10
+ type: 'description';
11
+ raw: string;
12
+ tokens: [DescriptionTermToken, DescriptionDetailToken];
13
+ };
14
+ export type DescriptionTermToken = {
15
+ type: 'descriptionTerm';
16
+ raw: string;
17
+ tokens: GenericToken[];
18
+ };
19
+ export type DescriptionDetailToken = {
20
+ type: 'descriptionDetail';
21
+ raw: string;
22
+ tokens: GenericToken[];
23
+ };
@@ -0,0 +1,44 @@
1
+ export const markedDl = {
2
+ name: 'descriptionList',
3
+ level: 'block', // Is this a block-level or inline-level tokenizer?
4
+ tokenizer(src) {
5
+ const rule = /^(?:[ \t]*:[^:\n]+:[ \t]?[^\n]*(?:\n|$))+/;
6
+ const match = rule.exec(src);
7
+ if (match) {
8
+ const text = match[0].trim();
9
+ const tokens = [];
10
+ // Parse each line as a description
11
+ const lines = text.split('\n');
12
+ for (const line of lines) {
13
+ const lineMatch = /^\s*:([^:\n]+):([^:\n]*)(?:\n|$)/.exec(line);
14
+ if (lineMatch) {
15
+ const term = lineMatch[1].trim();
16
+ const detail = lineMatch[2].trim();
17
+ tokens.push({
18
+ type: 'description',
19
+ raw: lineMatch[0],
20
+ tokens: [
21
+ {
22
+ type: 'descriptionTerm',
23
+ raw: term,
24
+ tokens: this.lexer.inlineTokens(term)
25
+ },
26
+ {
27
+ type: 'descriptionDetail',
28
+ raw: detail,
29
+ tokens: this.lexer.inlineTokens(detail)
30
+ }
31
+ ]
32
+ });
33
+ }
34
+ }
35
+ const token = {
36
+ type: 'descriptionList',
37
+ raw: match[0],
38
+ text: text,
39
+ tokens: tokens
40
+ };
41
+ return token;
42
+ }
43
+ }
44
+ };
@@ -0,0 +1,26 @@
1
+ import { type StreamdownToken, type Extension } from './index.js';
2
+ type MarkedFootnoteOptions = {
3
+ preferContext?: boolean;
4
+ };
5
+ export declare function markedFootnote({ preferContext }?: MarkedFootnoteOptions): Extension[];
6
+ /**
7
+ * Represents a single footnote.
8
+ */
9
+ export type Footnote = {
10
+ type: 'footnote';
11
+ raw: string;
12
+ label: string;
13
+ tokens: StreamdownToken[];
14
+ lines: string[];
15
+ };
16
+ /**
17
+ * Represents a reference to a footnote.
18
+ */
19
+ export type FootnoteRef = {
20
+ type: 'footnoteRef';
21
+ raw: string;
22
+ label: string;
23
+ content: Footnote;
24
+ };
25
+ export type FootnoteToken = Footnote | FootnoteRef;
26
+ export {};
@@ -0,0 +1,101 @@
1
+ import {} from './index.js';
2
+ import { StreamdownContext } from '../context.svelte.js';
3
+ import { getContext } from 'svelte';
4
+ import { STREAMDOWN_CONTEXT_KEY } from '../context-key.js';
5
+ const footnoteRegex = /^\[\^([^\]\n]+)\]:(?:[ \t]+|\n|$)([^\n]*(?:\n(?:[ \t]+[^\n]*)?)*)/;
6
+ const footnoteRefRegex = /^\[\^([^\]\n]+)\](?!\()/;
7
+ const footNoteLastLineRegex = /^[ \t]*?[>\-*][ ]|[`]{3,}$|^[ \t]*?[|].+[|]$/;
8
+ const safeGetContext = () => {
9
+ try {
10
+ return getContext(STREAMDOWN_CONTEXT_KEY);
11
+ }
12
+ catch (e) {
13
+ return null;
14
+ }
15
+ };
16
+ export function markedFootnote({ preferContext = true } = {}) {
17
+ const ensureMaps = (tokenizer) => {
18
+ const streamdown = preferContext ? safeGetContext() : null;
19
+ if (!streamdown) {
20
+ if (!tokenizer.lexer.hasFootnotes) {
21
+ tokenizer.lexer.footnotes = {
22
+ refs: new Map(),
23
+ footnotes: new Map()
24
+ };
25
+ tokenizer.lexer.hasFootnotes = true;
26
+ }
27
+ return tokenizer.lexer.footnotes;
28
+ }
29
+ else {
30
+ return streamdown.footnotes;
31
+ }
32
+ };
33
+ return [
34
+ {
35
+ name: 'footnote',
36
+ level: 'block',
37
+ tokenizer(src) {
38
+ const maps = ensureMaps(this);
39
+ const match = footnoteRegex.exec(src);
40
+ if (match) {
41
+ const [raw, label, text = ''] = match;
42
+ let content = text.split('\n').reduce((acc, curr) => {
43
+ return acc + '\n' + curr.replace(/^[ \t]+/, '');
44
+ }, '');
45
+ const contentLastLine = content.trimEnd().split('\n').pop();
46
+ content +=
47
+ // add lines after list, blockquote, codefence, and table
48
+ contentLastLine && footNoteLastLineRegex.test(contentLastLine) ? '\n\n' : '';
49
+ const lines = content.split('\n');
50
+ const token = {
51
+ type: 'footnote',
52
+ raw,
53
+ label,
54
+ lines,
55
+ tokens: []
56
+ };
57
+ maps.footnotes.set(label, token);
58
+ const ref = maps.refs.get(label);
59
+ if (ref) {
60
+ ref.content = token;
61
+ }
62
+ return token;
63
+ }
64
+ }
65
+ },
66
+ {
67
+ name: 'footnoteRef',
68
+ level: 'inline',
69
+ tokenizer(src) {
70
+ const streamdown = preferContext ? safeGetContext() : null;
71
+ const maps = ensureMaps(this);
72
+ const match = footnoteRefRegex.exec(src);
73
+ if (match) {
74
+ const [raw, label] = match;
75
+ const footnote = maps.footnotes.get(label);
76
+ const hasResolvedStreamingContent = Boolean(footnote?.lines.join('\n').trim().length);
77
+ if (label === 'streamdown:footnote' ||
78
+ (streamdown?.mode === 'streaming' &&
79
+ streamdown.isAnimating &&
80
+ (!footnote || !hasResolvedStreamingContent))) {
81
+ return;
82
+ }
83
+ const token = {
84
+ type: 'footnoteRef',
85
+ raw,
86
+ label,
87
+ content: footnote || {
88
+ type: 'footnote',
89
+ raw,
90
+ label,
91
+ lines: [],
92
+ tokens: []
93
+ }
94
+ };
95
+ maps.refs.set(label, token);
96
+ return token;
97
+ }
98
+ }
99
+ }
100
+ ];
101
+ }
@@ -0,0 +1,6 @@
1
+ import type { Extension } from './index.js';
2
+ export interface HrToken {
3
+ type: 'hr';
4
+ raw: string;
5
+ }
6
+ export declare const markedHr: Extension;
@@ -0,0 +1,18 @@
1
+ export const markedHr = {
2
+ name: 'hr',
3
+ level: 'block',
4
+ tokenizer(src) {
5
+ // Match horizontal rules according to CommonMark spec:
6
+ // 3 or more matching -, _, or * characters, with optional spaces between
7
+ // Must be at start of string and match entire line
8
+ const match = src.match(/^[ \t]*(-[ \t]*-[ \t]*-+|_[ \t]*_[ \t]*_+|\*[ \t]*\*[ \t]*\*+)[ \t]*(?:\n|$)/);
9
+ if (match) {
10
+ const raw = match[0].replace(/\n$/, ''); // Remove trailing newline from raw
11
+ return {
12
+ type: 'hr',
13
+ raw: raw
14
+ };
15
+ }
16
+ return undefined;
17
+ }
18
+ };
@@ -0,0 +1,31 @@
1
+ import type { Extension, GenericToken } from './index.js';
2
+ export declare function letterToInt(letter: string): number;
3
+ export declare function romanToInt(roman: string): number;
4
+ export declare const romanUpper = "(?:C|XC|L?X{0,3}(?:IX|IV|V?I{0,3}))";
5
+ export declare const romanLower = "(?:c|xc|l?x{0,3}(?:ix|iv|v?i{0,3}))";
6
+ export declare const bulletPattern = "(?:[*+-]|(?:\\d{1,9}|[a-zA-Z]|(?:C|XC|L?X{0,3}(?:IX|IV|V?I{0,3}))|(?:c|xc|l?x{0,3}(?:ix|iv|v?i{0,3})))[.)])";
7
+ export declare const rule = "^( {0,3}(?:[*+-]|(?:\\d{1,9}|[a-zA-Z]|(?:C|XC|L?X{0,3}(?:IX|IV|V?I{0,3}))|(?:c|xc|l?x{0,3}(?:ix|iv|v?i{0,3})))[.)]))([ \\t][^\\n]*|[ \\t])?(?:\\n|$)";
8
+ export declare const markedList: Extension;
9
+ export interface ListToken {
10
+ type: 'list';
11
+ raw: string;
12
+ ordered: boolean;
13
+ listType: 'decimal' | 'lower-alpha' | 'upper-alpha' | 'lower-roman' | 'upper-roman' | null;
14
+ loose: boolean;
15
+ start?: number;
16
+ tokens: ListItemToken[];
17
+ }
18
+ /**
19
+ * Token representing an item in an extended list.
20
+ */
21
+ export interface ListItemToken {
22
+ type: 'list_item';
23
+ raw: string;
24
+ task: boolean;
25
+ checked: boolean;
26
+ loose: boolean;
27
+ text: string;
28
+ value: number | null;
29
+ skipped: boolean;
30
+ tokens: GenericToken[];
31
+ }