@svadmin/ai-elements 0.5.1 → 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.
- package/README.md +18 -53
- package/THIRD_PARTY_NOTICES.md +67 -6
- package/dist/ai.css +149 -2740
- package/dist/ai.theme.css +1 -2771
- package/dist/class-properties.generated.d.ts +1 -0
- package/dist/class-properties.generated.js +2 -0
- package/dist/classnames.d.ts +8 -0
- package/dist/classnames.js +26 -0
- package/dist/components/AICommandBar.svelte +6 -4
- package/dist/components/ChatDialog.svelte +102 -125
- package/dist/components/ChatDialog.svelte.d.ts +3 -9
- package/dist/components/Conversation.svelte +34 -10
- package/dist/components/ConversationContent.svelte +1 -1
- package/dist/components/ConversationScrollButton.svelte +0 -1
- package/dist/components/CopilotPanel.svelte +8 -6
- package/dist/components/Message.svelte +1 -1
- package/dist/components/MessageActions.svelte +1 -1
- package/dist/components/MessageContent.svelte +1 -1
- package/dist/components/MessageToolbar.svelte +1 -1
- package/dist/components/Response.svelte +32 -12
- package/dist/components/Response.svelte.d.ts +3 -3
- package/dist/components/Tool.svelte +13 -13
- package/dist/components/Tool.svelte.d.ts +1 -1
- package/dist/components/action/Action.svelte +3 -1
- package/dist/components/artifact/ArtifactAction.svelte +3 -1
- package/dist/components/attachments/Attachment.svelte +4 -2
- package/dist/components/attachments/Attachments.svelte +3 -1
- package/dist/components/attachments/types.js +3 -2
- package/dist/components/audio-player/AudioPlayer.svelte.d.ts +1 -1
- package/dist/components/canvas/Canvas.svelte +1 -1
- package/dist/components/checkpoint/index.d.ts +2 -2
- package/dist/components/code/index.d.ts +9 -1
- package/dist/components/code/index.js +8 -1
- package/dist/components/code-block/CodeBlockLanguageSelector.svelte.d.ts +1 -1
- package/dist/components/code-block/highlight.js +11 -10
- package/dist/components/commit/Commit.svelte +23 -2
- package/dist/components/commit/CommitActions.svelte +2 -11
- package/dist/components/commit/CommitCopyButton.svelte +1 -1
- package/dist/components/commit/CommitHeader.svelte +12 -2
- package/dist/components/commit/context.svelte.d.ts +6 -0
- package/dist/components/commit/context.svelte.js +14 -0
- package/dist/components/context/Context.svelte +6 -4
- package/dist/components/context/TokensWithCost.svelte +2 -1
- package/dist/components/edge/Animated.svelte +6 -6
- package/dist/components/edge/Temporary.svelte +6 -5
- package/dist/components/file-tree/FileTree.svelte +7 -5
- package/dist/components/jsx-preview/parser.js +10 -10
- package/dist/components/message/MessageAction.svelte +3 -1
- package/dist/components/mic-selector/MicSelector.svelte.d.ts +1 -1
- package/dist/components/model-selector/ModelSelectorDialog.svelte +3 -1
- package/dist/components/open-in-chat/OpenInChatGPT.svelte +3 -1
- package/dist/components/open-in-chat/OpenInClaude.svelte +3 -1
- package/dist/components/open-in-chat/OpenInCursor.svelte +3 -1
- package/dist/components/open-in-chat/OpenInGitHub.svelte +3 -1
- package/dist/components/open-in-chat/OpenInScira.svelte +3 -1
- package/dist/components/open-in-chat/OpenInT3.svelte +3 -1
- package/dist/components/open-in-chat/OpenInv0.svelte +3 -1
- package/dist/components/package-info/PackageInfo.svelte +3 -1
- package/dist/components/prompt-input/PromptInput.svelte +8 -18
- package/dist/components/prompt-input/PromptInputCommand.svelte +2 -1
- package/dist/components/prompt-input/PromptInputSelect.svelte.d.ts +1 -1
- package/dist/components/prompt-input/PromptInputSubmit.svelte +5 -18
- package/dist/components/prompt-input/PromptInputTextarea.svelte +6 -11
- package/dist/components/prompt-input/context.svelte.d.ts +1 -8
- package/dist/components/prompt-input/files.js +3 -2
- package/dist/components/question/Question.svelte +3 -1
- package/dist/components/schema-display/SchemaDisplay.svelte +4 -2
- package/dist/components/schema-display/SchemaDisplayParameter.svelte +14 -1
- package/dist/components/schema-display/SchemaDisplayProperty.svelte +16 -1
- package/dist/components/snippet/index.d.ts +3 -3
- package/dist/components/stack-trace/StackTrace.svelte +7 -5
- package/dist/components/suggestion/index.d.ts +1 -1
- package/dist/components/terminal/Terminal.svelte +4 -2
- package/dist/components/terminal/ansi.js +9 -6
- package/dist/components/test-results/Test.svelte +1 -1
- package/dist/components/test-results/TestResults.svelte +1 -1
- package/dist/components/test-results/context.svelte.d.ts +1 -1
- package/dist/components/tool/ToolContent.svelte +1 -1
- package/dist/components/tool/ToolHeader.svelte +5 -5
- package/dist/components/tool/ToolInput.svelte +2 -4
- package/dist/components/tool/ToolOutput.svelte +2 -4
- package/dist/components/tool/ToolStatusBadge.svelte +2 -3
- package/dist/components/voice-selector/VoiceSelector.svelte +2 -1
- package/dist/components/voice-selector/VoiceSelector.svelte.d.ts +2 -2
- package/dist/components/voice-selector/context.svelte.d.ts +2 -1
- package/dist/components/web-preview/WebPreview.svelte +4 -3
- package/dist/contracts.d.ts +2 -2
- package/dist/generated-components.d.ts +15 -1
- package/dist/generated-components.js +20 -1
- package/dist/internal/Tooltip.svelte +2 -1
- package/dist/parity-manifest.d.ts +0 -1
- package/dist/parity-manifest.js +0 -97
- package/dist/utilities.css +3172 -0
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/package.json +37 -22
- package/vendor/streamdown/AnimatedText.svelte +93 -0
- package/vendor/streamdown/AnimatedText.svelte.d.ts +6 -0
- package/vendor/streamdown/Block.svelte +96 -0
- package/vendor/streamdown/Block.svelte.d.ts +11 -0
- package/vendor/streamdown/Elements/Alert.svelte +69 -0
- package/vendor/streamdown/Elements/Alert.svelte.d.ts +10 -0
- package/vendor/streamdown/Elements/Citation.svelte +260 -0
- package/vendor/streamdown/Elements/Citation.svelte.d.ts +7 -0
- package/vendor/streamdown/Elements/Code.svelte +226 -0
- package/vendor/streamdown/Elements/Code.svelte.d.ts +9 -0
- package/vendor/streamdown/Elements/Element.svelte +574 -0
- package/vendor/streamdown/Elements/Element.svelte.d.ts +10 -0
- package/vendor/streamdown/Elements/FootnoteRef.svelte +30 -0
- package/vendor/streamdown/Elements/FootnoteRef.svelte.d.ts +7 -0
- package/vendor/streamdown/Elements/Footnotes.svelte +54 -0
- package/vendor/streamdown/Elements/Footnotes.svelte.d.ts +7 -0
- package/vendor/streamdown/Elements/Image.svelte +200 -0
- package/vendor/streamdown/Elements/Image.svelte.d.ts +10 -0
- package/vendor/streamdown/Elements/Link.svelte +220 -0
- package/vendor/streamdown/Elements/Link.svelte.d.ts +10 -0
- package/vendor/streamdown/Elements/LinkSafetyModal.svelte +121 -0
- package/vendor/streamdown/Elements/LinkSafetyModal.svelte.d.ts +4 -0
- package/vendor/streamdown/Elements/Math.svelte +100 -0
- package/vendor/streamdown/Elements/Math.svelte.d.ts +9 -0
- package/vendor/streamdown/Elements/Mermaid.svelte +455 -0
- package/vendor/streamdown/Elements/Mermaid.svelte.d.ts +9 -0
- package/vendor/streamdown/Elements/MermaidDownload.svelte +145 -0
- package/vendor/streamdown/Elements/MermaidDownload.svelte.d.ts +8 -0
- package/vendor/streamdown/Elements/Slot.svelte +23 -0
- package/vendor/streamdown/Elements/Slot.svelte.d.ts +10 -0
- package/vendor/streamdown/Elements/Table.svelte +195 -0
- package/vendor/streamdown/Elements/Table.svelte.d.ts +9 -0
- package/vendor/streamdown/Elements/TableDownload.svelte +221 -0
- package/vendor/streamdown/Elements/TableDownload.svelte.d.ts +8 -0
- package/vendor/streamdown/Elements/fallbacks/CodeFallback.svelte +41 -0
- package/vendor/streamdown/Elements/fallbacks/CodeFallback.svelte.d.ts +9 -0
- package/vendor/streamdown/Elements/fallbacks/MathFallback.svelte +35 -0
- package/vendor/streamdown/Elements/fallbacks/MathFallback.svelte.d.ts +8 -0
- package/vendor/streamdown/Elements/fallbacks/MermaidFallback.svelte +36 -0
- package/vendor/streamdown/Elements/fallbacks/MermaidFallback.svelte.d.ts +9 -0
- package/vendor/streamdown/Elements/fallbacks/index.d.ts +3 -0
- package/vendor/streamdown/Elements/fallbacks/index.js +3 -0
- package/vendor/streamdown/Elements/icons.d.ts +31 -0
- package/vendor/streamdown/Elements/icons.js +200 -0
- package/vendor/streamdown/Elements/index.d.ts +8 -0
- package/vendor/streamdown/Elements/index.js +8 -0
- package/vendor/streamdown/Elements/popover.svelte.d.ts +8 -0
- package/vendor/streamdown/Elements/popover.svelte.js +45 -0
- package/vendor/streamdown/Elements/stepperState.svelte.d.ts +36 -0
- package/vendor/streamdown/Elements/stepperState.svelte.js +92 -0
- package/vendor/streamdown/IconProvider.svelte +11 -0
- package/vendor/streamdown/IconProvider.svelte.d.ts +30 -0
- package/vendor/streamdown/LICENSE +202 -0
- package/vendor/streamdown/PluginProvider.svelte +11 -0
- package/vendor/streamdown/PluginProvider.svelte.d.ts +30 -0
- package/vendor/streamdown/README.svadmin.md +5 -0
- package/vendor/streamdown/Streamdown.svelte +447 -0
- package/vendor/streamdown/Streamdown.svelte.d.ts +25 -0
- package/vendor/streamdown/block/BlockTokens.svelte +45 -0
- package/vendor/streamdown/block/BlockTokens.svelte.d.ts +9 -0
- package/vendor/streamdown/block/html.d.ts +14 -0
- package/vendor/streamdown/block/html.js +27 -0
- package/vendor/streamdown/block/text.d.ts +10 -0
- package/vendor/streamdown/block/text.js +31 -0
- package/vendor/streamdown/context-key.d.ts +1 -0
- package/vendor/streamdown/context-key.js +1 -0
- package/vendor/streamdown/context.svelte.d.ts +24 -0
- package/vendor/streamdown/context.svelte.js +75 -0
- package/vendor/streamdown/contracts/plugins.d.ts +26 -0
- package/vendor/streamdown/contracts/plugins.js +1 -0
- package/vendor/streamdown/contracts/streamdown.d.ts +374 -0
- package/vendor/streamdown/contracts/streamdown.js +29 -0
- package/vendor/streamdown/detect-direction.d.ts +1 -0
- package/vendor/streamdown/detect-direction.js +1 -0
- package/vendor/streamdown/icon-context.d.ts +36 -0
- package/vendor/streamdown/icon-context.js +52 -0
- package/vendor/streamdown/incomplete-code.d.ts +6 -0
- package/vendor/streamdown/incomplete-code.js +23 -0
- package/vendor/streamdown/index.d.ts +22 -0
- package/vendor/streamdown/index.js +20 -0
- package/vendor/streamdown/markdown-parse-cache.d.ts +37 -0
- package/vendor/streamdown/markdown-parse-cache.js +109 -0
- package/vendor/streamdown/markdown.d.ts +21 -0
- package/vendor/streamdown/markdown.js +214 -0
- package/vendor/streamdown/marked/index.d.ts +44 -0
- package/vendor/streamdown/marked/index.js +228 -0
- package/vendor/streamdown/marked/marked-alert.d.ts +13 -0
- package/vendor/streamdown/marked/marked-alert.js +47 -0
- package/vendor/streamdown/marked/marked-align.d.ts +10 -0
- package/vendor/streamdown/marked/marked-align.js +45 -0
- package/vendor/streamdown/marked/marked-br.d.ts +6 -0
- package/vendor/streamdown/marked/marked-br.js +15 -0
- package/vendor/streamdown/marked/marked-citations.d.ts +8 -0
- package/vendor/streamdown/marked/marked-citations.js +53 -0
- package/vendor/streamdown/marked/marked-cjk.d.ts +2 -0
- package/vendor/streamdown/marked/marked-cjk.js +165 -0
- package/vendor/streamdown/marked/marked-dl.d.ts +23 -0
- package/vendor/streamdown/marked/marked-dl.js +44 -0
- package/vendor/streamdown/marked/marked-footnotes.d.ts +26 -0
- package/vendor/streamdown/marked/marked-footnotes.js +101 -0
- package/vendor/streamdown/marked/marked-hr.d.ts +6 -0
- package/vendor/streamdown/marked/marked-hr.js +18 -0
- package/vendor/streamdown/marked/marked-list.d.ts +31 -0
- package/vendor/streamdown/marked/marked-list.js +330 -0
- package/vendor/streamdown/marked/marked-math.d.ts +13 -0
- package/vendor/streamdown/marked/marked-math.js +129 -0
- package/vendor/streamdown/marked/marked-mdx.d.ts +12 -0
- package/vendor/streamdown/marked/marked-mdx.js +124 -0
- package/vendor/streamdown/marked/marked-subsup.d.ts +22 -0
- package/vendor/streamdown/marked/marked-subsup.js +40 -0
- package/vendor/streamdown/marked/marked-table.d.ts +80 -0
- package/vendor/streamdown/marked/marked-table.js +527 -0
- package/vendor/streamdown/plugin-context.d.ts +19 -0
- package/vendor/streamdown/plugin-context.js +40 -0
- package/vendor/streamdown/plugins/cjk-shared.d.ts +1 -0
- package/vendor/streamdown/plugins/cjk-shared.js +1 -0
- package/vendor/streamdown/plugins.d.ts +19 -0
- package/vendor/streamdown/plugins.js +107 -0
- package/vendor/streamdown/provenance.json +229 -0
- package/vendor/streamdown/remend.d.ts +2 -0
- package/vendor/streamdown/remend.js +1 -0
- package/vendor/streamdown/security/html.d.ts +19 -0
- package/vendor/streamdown/security/html.js +329 -0
- package/vendor/streamdown/security/preprocess-custom-tags.d.ts +1 -0
- package/vendor/streamdown/security/preprocess-custom-tags.js +20 -0
- package/vendor/streamdown/security/preprocess-literal-tag-content.d.ts +1 -0
- package/vendor/streamdown/security/preprocess-literal-tag-content.js +16 -0
- package/vendor/streamdown/security/types.d.ts +1 -0
- package/vendor/streamdown/security/types.js +1 -0
- package/vendor/streamdown/site/SiteHeader.svelte +94 -0
- package/vendor/streamdown/site/SiteHeader.svelte.d.ts +6 -0
- package/vendor/streamdown/site/home/HomeDemo.svelte +122 -0
- package/vendor/streamdown/site/home/HomeDemo.svelte.d.ts +3 -0
- package/vendor/streamdown/site/home/HomePage.svelte +293 -0
- package/vendor/streamdown/site/home/HomePage.svelte.d.ts +3 -0
- package/vendor/streamdown/site/home/content.d.ts +69 -0
- package/vendor/streamdown/site/home/content.js +144 -0
- package/vendor/streamdown/site/metadata.d.ts +4 -0
- package/vendor/streamdown/site/metadata.js +4 -0
- package/vendor/streamdown/site/navigation.d.ts +6 -0
- package/vendor/streamdown/site/navigation.js +22 -0
- package/vendor/streamdown/streamdown/config.d.ts +41 -0
- package/vendor/streamdown/streamdown/config.js +125 -0
- package/vendor/streamdown/streamdown/context.d.ts +12 -0
- package/vendor/streamdown/streamdown/context.js +2 -0
- package/vendor/streamdown/streamdown/incomplete-markdown.d.ts +5 -0
- package/vendor/streamdown/streamdown/incomplete-markdown.js +79 -0
- package/vendor/streamdown/streamdown/pipeline.d.ts +95 -0
- package/vendor/streamdown/streamdown/pipeline.js +138 -0
- package/vendor/streamdown/streamdown/runtime.d.ts +59 -0
- package/vendor/streamdown/streamdown/runtime.js +112 -0
- package/vendor/streamdown/streaming.d.ts +5 -0
- package/vendor/streamdown/streaming.js +5 -0
- package/vendor/streamdown/theme.d.ts +486 -0
- package/vendor/streamdown/theme.js +370 -0
- package/vendor/streamdown/translations.d.ts +43 -0
- package/vendor/streamdown/translations.js +54 -0
- package/vendor/streamdown/url-policy.d.ts +1 -0
- package/vendor/streamdown/url-policy.js +1 -0
- package/vendor/streamdown/utils/bind.d.ts +8 -0
- package/vendor/streamdown/utils/bind.js +26 -0
- package/vendor/streamdown/utils/bundledLanguages.d.ts +1 -0
- package/vendor/streamdown/utils/bundledLanguages.js +1 -0
- package/vendor/streamdown/utils/code-block.d.ts +8 -0
- package/vendor/streamdown/utils/code-block.js +38 -0
- package/vendor/streamdown/utils/copy.svelte.d.ts +7 -0
- package/vendor/streamdown/utils/copy.svelte.js +38 -0
- package/vendor/streamdown/utils/darkMode.svelte.d.ts +3 -0
- package/vendor/streamdown/utils/darkMode.svelte.js +49 -0
- package/vendor/streamdown/utils/detectDirection.d.ts +1 -0
- package/vendor/streamdown/utils/detectDirection.js +19 -0
- package/vendor/streamdown/utils/get.d.ts +1 -0
- package/vendor/streamdown/utils/get.js +25 -0
- package/vendor/streamdown/utils/hightlighter.svelte.d.ts +30 -0
- package/vendor/streamdown/utils/hightlighter.svelte.js +524 -0
- package/vendor/streamdown/utils/index.d.ts +3 -0
- package/vendor/streamdown/utils/index.js +3 -0
- package/vendor/streamdown/utils/mermaid.d.ts +13 -0
- package/vendor/streamdown/utils/mermaid.js +49 -0
- package/vendor/streamdown/utils/panzoom.svelte.d.ts +35 -0
- package/vendor/streamdown/utils/panzoom.svelte.js +556 -0
- package/vendor/streamdown/utils/parse-incomplete-markdown.d.ts +2 -0
- package/vendor/streamdown/utils/parse-incomplete-markdown.js +2 -0
- package/vendor/streamdown/utils/runtime-env.d.ts +1 -0
- package/vendor/streamdown/utils/runtime-env.js +13 -0
- package/vendor/streamdown/utils/save.d.ts +1 -0
- package/vendor/streamdown/utils/save.js +14 -0
- package/vendor/streamdown/utils/scroll-lock.d.ts +2 -0
- package/vendor/streamdown/utils/scroll-lock.js +35 -0
- package/vendor/streamdown/utils/table.d.ts +8 -0
- package/vendor/streamdown/utils/table.js +176 -0
- package/vendor/streamdown/utils/url.d.ts +22 -0
- package/vendor/streamdown/utils/url.js +98 -0
- package/vendor/streamdown/utils/useClickOutside.svelte.d.ts +8 -0
- package/vendor/streamdown/utils/useClickOutside.svelte.js +41 -0
- package/vendor/streamdown/utils/useKeyDown.svelte.d.ts +5 -0
- package/vendor/streamdown/utils/useKeyDown.svelte.js +23 -0
- package/UPSTREAM_PARITY.md +0 -69
- package/dist/ai-theme.css +0 -28
- package/dist/components/code/code-variants.d.ts +0 -25
- package/dist/components/code/code-variants.js +0 -20
- package/dist/components/conversation/scroll.d.ts +0 -4
- package/dist/components/conversation/scroll.js +0 -85
- package/dist/components/message/content-polish-html.d.ts +0 -5
- package/dist/components/message/content-polish-html.js +0 -75
- package/dist/components/tool/content-polish-scroll-region.d.ts +0 -3
- package/dist/components/tool/content-polish-scroll-region.js +0 -22
|
@@ -0,0 +1,574 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext } from 'svelte';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
4
|
+
import Link from './Link.svelte';
|
|
5
|
+
import Image from './Image.svelte';
|
|
6
|
+
import Alert from './Alert.svelte';
|
|
7
|
+
import type { StreamdownToken } from '../marked/index.js';
|
|
8
|
+
import Slot from './Slot.svelte';
|
|
9
|
+
import { useStreamdown } from '../context.svelte.js';
|
|
10
|
+
import { renderHtmlToken } from '../security/html.js';
|
|
11
|
+
import FootnoteRef from './FootnoteRef.svelte';
|
|
12
|
+
import Citation from './Citation.svelte';
|
|
13
|
+
import Table from './Table.svelte';
|
|
14
|
+
// Import fallback components
|
|
15
|
+
import Code from './Code.svelte';
|
|
16
|
+
import Mermaid from './Mermaid.svelte';
|
|
17
|
+
import Math from './Math.svelte';
|
|
18
|
+
import { MermaidFallback, MathFallback } from './fallbacks/index.js';
|
|
19
|
+
import {
|
|
20
|
+
extractCodeFenceLanguage,
|
|
21
|
+
extractCodeFenceMeta,
|
|
22
|
+
findCustomRenderer
|
|
23
|
+
} from '../plugins.js';
|
|
24
|
+
import { STREAMDOWN_BLOCK_CONTEXT } from '../incomplete-code.js';
|
|
25
|
+
let {
|
|
26
|
+
token,
|
|
27
|
+
children,
|
|
28
|
+
isIncomplete = false
|
|
29
|
+
}: {
|
|
30
|
+
token: StreamdownToken;
|
|
31
|
+
children: Snippet;
|
|
32
|
+
isIncomplete?: boolean;
|
|
33
|
+
} = $props();
|
|
34
|
+
const streamdown = useStreamdown();
|
|
35
|
+
const headingTags = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] as const;
|
|
36
|
+
|
|
37
|
+
// Use provided components or fallback to lightweight versions
|
|
38
|
+
const CodeComponent = $derived(streamdown.components?.code ?? Code);
|
|
39
|
+
const MermaidComponent = $derived(
|
|
40
|
+
streamdown.components?.mermaid ?? (streamdown.plugins?.mermaid ? Mermaid : MermaidFallback)
|
|
41
|
+
);
|
|
42
|
+
const MathComponent = $derived(
|
|
43
|
+
streamdown.components?.math ?? (streamdown.plugins?.math ? Math : MathFallback)
|
|
44
|
+
);
|
|
45
|
+
const customRenderer = $derived(
|
|
46
|
+
token.type === 'code'
|
|
47
|
+
? findCustomRenderer(streamdown.plugins?.renderers, extractCodeFenceLanguage(token))
|
|
48
|
+
: null
|
|
49
|
+
);
|
|
50
|
+
const headingThemeKey = $derived(
|
|
51
|
+
token.type === 'heading' ? (headingTags[token.depth - 1] ?? 'h1') : 'h1'
|
|
52
|
+
);
|
|
53
|
+
const HeadingComponent = $derived(
|
|
54
|
+
token.type === 'heading' ? streamdown.components?.[headingThemeKey] : undefined
|
|
55
|
+
);
|
|
56
|
+
const ParagraphComponent = $derived(
|
|
57
|
+
token.type === 'paragraph' && !(token.tokens?.length === 1 && token.tokens[0]?.type === 'image')
|
|
58
|
+
? streamdown.components?.p
|
|
59
|
+
: undefined
|
|
60
|
+
);
|
|
61
|
+
const BlockquoteComponent = $derived(
|
|
62
|
+
token.type === 'blockquote' ? streamdown.components?.blockquote : undefined
|
|
63
|
+
);
|
|
64
|
+
const InlineCodeComponent = $derived(
|
|
65
|
+
token.type === 'codespan' ? streamdown.components?.inlineCode : undefined
|
|
66
|
+
);
|
|
67
|
+
const OrderedListComponent = $derived(
|
|
68
|
+
token.type === 'list' && token.ordered ? streamdown.components?.ol : undefined
|
|
69
|
+
);
|
|
70
|
+
const UnorderedListComponent = $derived(
|
|
71
|
+
token.type === 'list' && !token.ordered ? streamdown.components?.ul : undefined
|
|
72
|
+
);
|
|
73
|
+
const ListItemComponent = $derived(
|
|
74
|
+
token.type === 'list_item' ? streamdown.components?.li : undefined
|
|
75
|
+
);
|
|
76
|
+
const TableHeadComponent = $derived(
|
|
77
|
+
token.type === 'thead' ? streamdown.components?.thead : undefined
|
|
78
|
+
);
|
|
79
|
+
const TableBodyComponent = $derived(
|
|
80
|
+
token.type === 'tbody' ? streamdown.components?.tbody : undefined
|
|
81
|
+
);
|
|
82
|
+
const TableFootComponent = $derived(
|
|
83
|
+
token.type === 'tfoot' ? streamdown.components?.tfoot : undefined
|
|
84
|
+
);
|
|
85
|
+
const TableRowComponent = $derived(token.type === 'tr' ? streamdown.components?.tr : undefined);
|
|
86
|
+
const TableCellComponent = $derived(token.type === 'td' ? streamdown.components?.td : undefined);
|
|
87
|
+
const TableHeaderCellComponent = $derived(
|
|
88
|
+
token.type === 'th' ? streamdown.components?.th : undefined
|
|
89
|
+
);
|
|
90
|
+
const SubComponent = $derived(token.type === 'sub' ? streamdown.components?.sub : undefined);
|
|
91
|
+
const SupComponent = $derived(token.type === 'sup' ? streamdown.components?.sup : undefined);
|
|
92
|
+
const StrongComponent = $derived(
|
|
93
|
+
token.type === 'strong' ? streamdown.components?.strong : undefined
|
|
94
|
+
);
|
|
95
|
+
const EmComponent = $derived(token.type === 'em' ? streamdown.components?.em : undefined);
|
|
96
|
+
const DelComponent = $derived(token.type === 'del' ? streamdown.components?.del : undefined);
|
|
97
|
+
const HrComponent = $derived(token.type === 'hr' ? streamdown.components?.hr : undefined);
|
|
98
|
+
const BrComponent = $derived(token.type === 'br' ? streamdown.components?.br : undefined);
|
|
99
|
+
const shouldRenderCitationPreview = $derived.by(() => {
|
|
100
|
+
if (token.type !== 'inline-citations') {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return token.keys.some((key) => key in (streamdown.sources ?? {}));
|
|
105
|
+
});
|
|
106
|
+
const shouldUnwrapStandaloneImageParagraph = $derived(
|
|
107
|
+
token.type === 'paragraph' && token.tokens?.length === 1 && token.tokens[0]?.type === 'image'
|
|
108
|
+
);
|
|
109
|
+
const listHasTaskItems = $derived(
|
|
110
|
+
token.type === 'list' && token.tokens.some((item) => item.task)
|
|
111
|
+
);
|
|
112
|
+
const rawBlock = $derived(
|
|
113
|
+
getContext<{ rawBlock?: string } | undefined>(STREAMDOWN_BLOCK_CONTEXT)?.rawBlock
|
|
114
|
+
);
|
|
115
|
+
const isRecoveredInlineFormatting = $derived.by(() => {
|
|
116
|
+
if (!isIncomplete) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (token.type !== 'strong' && token.type !== 'em' && token.type !== 'del') {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (typeof token.raw !== 'string' || token.raw.length === 0) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return !rawBlock?.includes(token.raw);
|
|
129
|
+
});
|
|
130
|
+
const isRecoveredDelimitedFormatting = $derived.by(() => {
|
|
131
|
+
if (!isIncomplete || typeof rawBlock !== 'string') {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const text = 'text' in token && typeof token.text === 'string' ? token.text : null;
|
|
136
|
+
if (!text || text.length === 0) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (token.type === 'strong') {
|
|
141
|
+
return rawBlock.includes(`**${text}`) && !rawBlock.includes(`**${text}**`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (token.type === 'em') {
|
|
145
|
+
return (
|
|
146
|
+
(rawBlock.includes(`*${text}`) && !rawBlock.includes(`*${text}*`)) ||
|
|
147
|
+
(rawBlock.includes(`_${text}`) && !rawBlock.includes(`_${text}_`))
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (token.type === 'del') {
|
|
152
|
+
return rawBlock.includes(`~~${text}`) && !rawBlock.includes(`~~${text}~~`);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return false;
|
|
156
|
+
});
|
|
157
|
+
const isIncompleteTableBlock = $derived.by(() => {
|
|
158
|
+
if (streamdown.mode !== 'streaming' || typeof rawBlock !== 'string') {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return /(^|\n)\|/.test(rawBlock);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// Only apply animation on block level elements. Leaves text elements to be animated by their text children.
|
|
166
|
+
const style = $derived(streamdown.isMounted ? streamdown.animationBlockStyle : '');
|
|
167
|
+
const id = $props.id();
|
|
168
|
+
</script>
|
|
169
|
+
|
|
170
|
+
{#if token.type === 'heading'}
|
|
171
|
+
<Slot
|
|
172
|
+
props={{
|
|
173
|
+
children,
|
|
174
|
+
token,
|
|
175
|
+
class: streamdown.theme[headingThemeKey].base,
|
|
176
|
+
style
|
|
177
|
+
}}
|
|
178
|
+
render={streamdown.snippets.heading}
|
|
179
|
+
component={HeadingComponent}
|
|
180
|
+
>
|
|
181
|
+
{#if token.depth === 1}
|
|
182
|
+
<h1 data-streamdown-heading-1={id} {style} class={streamdown.theme[`h${token.depth}`].base}>
|
|
183
|
+
{@render children()}
|
|
184
|
+
</h1>
|
|
185
|
+
{:else if token.depth === 2}
|
|
186
|
+
<h2 data-streamdown-heading-2={id} {style} class={streamdown.theme[`h${token.depth}`].base}>
|
|
187
|
+
{@render children()}
|
|
188
|
+
</h2>
|
|
189
|
+
{:else if token.depth === 3}
|
|
190
|
+
<h3 data-streamdown-heading-3={id} {style} class={streamdown.theme[`h${token.depth}`].base}>
|
|
191
|
+
{@render children()}
|
|
192
|
+
</h3>
|
|
193
|
+
{:else if token.depth === 4}
|
|
194
|
+
<h4 data-streamdown-heading-4={id} {style} class={streamdown.theme[`h${token.depth}`].base}>
|
|
195
|
+
{@render children()}
|
|
196
|
+
</h4>
|
|
197
|
+
{:else if token.depth === 5}
|
|
198
|
+
<h5 data-streamdown-heading-5={id} {style} class={streamdown.theme[`h${token.depth}`].base}>
|
|
199
|
+
{@render children()}
|
|
200
|
+
</h5>
|
|
201
|
+
{:else if token.depth === 6}
|
|
202
|
+
<h6 data-streamdown-heading-6={id} {style} class={streamdown.theme[`h${token.depth}`].base}>
|
|
203
|
+
{@render children()}
|
|
204
|
+
</h6>
|
|
205
|
+
{/if}
|
|
206
|
+
</Slot>
|
|
207
|
+
{:else if token.type === 'paragraph'}
|
|
208
|
+
{#if shouldUnwrapStandaloneImageParagraph}
|
|
209
|
+
<!-- Keep standalone images out of paragraph wrappers to avoid invalid hydration markup. -->
|
|
210
|
+
{@render children()}
|
|
211
|
+
{:else}
|
|
212
|
+
<Slot
|
|
213
|
+
props={{ children, token, class: streamdown.theme.paragraph.base, style }}
|
|
214
|
+
render={streamdown.snippets.paragraph}
|
|
215
|
+
component={ParagraphComponent}
|
|
216
|
+
>
|
|
217
|
+
<p data-streamdown-paragraph={id} {style} class={streamdown.theme.paragraph.base}>
|
|
218
|
+
{@render children()}
|
|
219
|
+
</p>
|
|
220
|
+
</Slot>
|
|
221
|
+
{/if}
|
|
222
|
+
{:else if token.type === 'blockquote'}
|
|
223
|
+
<Slot
|
|
224
|
+
props={{ children, token, class: streamdown.theme.blockquote.base, style }}
|
|
225
|
+
render={streamdown.snippets.blockquote}
|
|
226
|
+
component={BlockquoteComponent}
|
|
227
|
+
>
|
|
228
|
+
<blockquote data-streamdown-blockquote={id} {style} class={streamdown.theme.blockquote.base}>
|
|
229
|
+
{@render children()}
|
|
230
|
+
</blockquote>
|
|
231
|
+
</Slot>
|
|
232
|
+
{:else if token.type === 'code' && customRenderer}
|
|
233
|
+
{@const Renderer = customRenderer.component}
|
|
234
|
+
<Renderer
|
|
235
|
+
code={token.text}
|
|
236
|
+
{isIncomplete}
|
|
237
|
+
language={extractCodeFenceLanguage(token)}
|
|
238
|
+
meta={extractCodeFenceMeta(token)}
|
|
239
|
+
/>
|
|
240
|
+
{:else if token.type === 'code' && extractCodeFenceLanguage(token) === 'mermaid'}
|
|
241
|
+
<Slot props={{ children, token }} render={streamdown.snippets.code}>
|
|
242
|
+
<MermaidComponent {id} {token} {isIncomplete} />
|
|
243
|
+
</Slot>
|
|
244
|
+
{:else if token.type === 'code'}
|
|
245
|
+
<Slot props={{ children, token }} render={streamdown.snippets.code}>
|
|
246
|
+
<CodeComponent {id} {token} {isIncomplete} />
|
|
247
|
+
</Slot>
|
|
248
|
+
{:else if token.type === 'codespan'}
|
|
249
|
+
<Slot
|
|
250
|
+
props={{ children, token, class: streamdown.theme.codespan.base }}
|
|
251
|
+
render={streamdown.snippets.codespan}
|
|
252
|
+
component={InlineCodeComponent}
|
|
253
|
+
>
|
|
254
|
+
<code data-streamdown-codespan={id} class={streamdown.theme.codespan.base}>
|
|
255
|
+
{@render children()}
|
|
256
|
+
</code>
|
|
257
|
+
</Slot>
|
|
258
|
+
{:else if token.type === 'list'}
|
|
259
|
+
{#if token.ordered}
|
|
260
|
+
<Slot
|
|
261
|
+
props={{ children, token, class: streamdown.theme.ol.base }}
|
|
262
|
+
render={streamdown.snippets.ol}
|
|
263
|
+
component={OrderedListComponent}
|
|
264
|
+
>
|
|
265
|
+
<ol
|
|
266
|
+
data-streamdown-ol={id}
|
|
267
|
+
style:list-style-type={token.listType}
|
|
268
|
+
{...token.start && token.start !== 1 ? { start: token.start } : {}}
|
|
269
|
+
class:contains-task-list={listHasTaskItems}
|
|
270
|
+
class={streamdown.theme.ol.base}
|
|
271
|
+
>
|
|
272
|
+
{@render children()}
|
|
273
|
+
</ol>
|
|
274
|
+
</Slot>
|
|
275
|
+
{:else}
|
|
276
|
+
<Slot
|
|
277
|
+
props={{ children, token, class: streamdown.theme.ul.base }}
|
|
278
|
+
render={streamdown.snippets.ul}
|
|
279
|
+
component={UnorderedListComponent}
|
|
280
|
+
>
|
|
281
|
+
<ul
|
|
282
|
+
data-streamdown-ul={id}
|
|
283
|
+
class:contains-task-list={listHasTaskItems}
|
|
284
|
+
class={streamdown.theme.ul.base}
|
|
285
|
+
>
|
|
286
|
+
{@render children()}
|
|
287
|
+
</ul>
|
|
288
|
+
</Slot>
|
|
289
|
+
{/if}
|
|
290
|
+
{:else if token.type === 'list_item'}
|
|
291
|
+
<Slot
|
|
292
|
+
props={{ children, token, class: streamdown.theme.li.base, style }}
|
|
293
|
+
render={streamdown.snippets.li}
|
|
294
|
+
component={ListItemComponent}
|
|
295
|
+
>
|
|
296
|
+
<li
|
|
297
|
+
data-streamdown-li={id}
|
|
298
|
+
{style}
|
|
299
|
+
style:list-style-type={token.task ? 'none' : undefined}
|
|
300
|
+
{...token.value && token.skipped && !token.task ? { value: token.value } : {}}
|
|
301
|
+
class:task-list-item={token.task}
|
|
302
|
+
class={streamdown.theme.li.base}
|
|
303
|
+
>
|
|
304
|
+
{#if token.task}
|
|
305
|
+
<input
|
|
306
|
+
disabled
|
|
307
|
+
type="checkbox"
|
|
308
|
+
checked={token.checked}
|
|
309
|
+
class={streamdown.theme.li.checkbox}
|
|
310
|
+
/>
|
|
311
|
+
{' '}
|
|
312
|
+
{/if}{@render children()}
|
|
313
|
+
</li>
|
|
314
|
+
</Slot>
|
|
315
|
+
{:else if token.type === 'table'}
|
|
316
|
+
<Slot props={{ token, children }} render={streamdown.snippets.table}>
|
|
317
|
+
<div {style}>
|
|
318
|
+
<Table {id} {token}>
|
|
319
|
+
{@render children()}
|
|
320
|
+
</Table>
|
|
321
|
+
</div>
|
|
322
|
+
</Slot>
|
|
323
|
+
{:else if token.type === 'thead'}
|
|
324
|
+
<Slot
|
|
325
|
+
props={{ token, children, class: streamdown.theme.thead.base, style }}
|
|
326
|
+
render={streamdown.snippets.thead}
|
|
327
|
+
component={TableHeadComponent}
|
|
328
|
+
>
|
|
329
|
+
<thead data-streamdown-thead={id} {style} class={streamdown.theme.thead.base}>
|
|
330
|
+
{@render children?.()}
|
|
331
|
+
</thead>
|
|
332
|
+
</Slot>
|
|
333
|
+
{:else if token.type === 'tbody'}
|
|
334
|
+
<Slot
|
|
335
|
+
props={{ token, children, class: streamdown.theme.tbody.base, style }}
|
|
336
|
+
render={streamdown.snippets.tbody}
|
|
337
|
+
component={TableBodyComponent}
|
|
338
|
+
>
|
|
339
|
+
<tbody data-streamdown-tbody={id} {style} class={streamdown.theme.tbody.base}>
|
|
340
|
+
{@render children?.()}
|
|
341
|
+
</tbody>
|
|
342
|
+
</Slot>
|
|
343
|
+
{:else if token.type === 'tfoot'}
|
|
344
|
+
<Slot
|
|
345
|
+
props={{ token, children, class: streamdown.theme.tfoot.base, style }}
|
|
346
|
+
render={streamdown.snippets.tfoot}
|
|
347
|
+
component={TableFootComponent}
|
|
348
|
+
>
|
|
349
|
+
<tfoot data-streamdown-tfoot={id} {style} class={streamdown.theme.tfoot.base}>
|
|
350
|
+
{@render children?.()}
|
|
351
|
+
</tfoot>
|
|
352
|
+
</Slot>
|
|
353
|
+
{:else if token.type === 'tr'}
|
|
354
|
+
<Slot
|
|
355
|
+
props={{ token, children, class: streamdown.theme.tr.base, style }}
|
|
356
|
+
render={streamdown.snippets.tr}
|
|
357
|
+
component={TableRowComponent}
|
|
358
|
+
>
|
|
359
|
+
<tr data-streamdown-tr={id} {style} class={streamdown.theme.tr.base}>
|
|
360
|
+
{@render children?.()}
|
|
361
|
+
{#if streamdown.mode === 'streaming' && (token.placeholderColumns ?? 0) > 0}
|
|
362
|
+
{#each Array.from({ length: token.placeholderColumns ?? 0 }) as _, placeholderIndex}
|
|
363
|
+
{#if token.tokens[0]?.type === 'th'}
|
|
364
|
+
<th
|
|
365
|
+
data-streamdown-th={`${id}-placeholder-${placeholderIndex}`}
|
|
366
|
+
class={streamdown.theme.th.base}
|
|
367
|
+
></th>
|
|
368
|
+
{:else}
|
|
369
|
+
<td
|
|
370
|
+
data-streamdown-td={`${id}-placeholder-${placeholderIndex}`}
|
|
371
|
+
class={streamdown.theme.td.base}
|
|
372
|
+
></td>
|
|
373
|
+
{/if}
|
|
374
|
+
{/each}
|
|
375
|
+
{/if}
|
|
376
|
+
</tr>
|
|
377
|
+
</Slot>
|
|
378
|
+
{:else if token.type === 'td'}
|
|
379
|
+
{#if token.rowspan > 0}
|
|
380
|
+
<Slot
|
|
381
|
+
props={{ children, token, class: streamdown.theme.td.base, style }}
|
|
382
|
+
render={streamdown.snippets.td}
|
|
383
|
+
component={TableCellComponent}
|
|
384
|
+
>
|
|
385
|
+
<td
|
|
386
|
+
{style}
|
|
387
|
+
data-streamdown-td={id}
|
|
388
|
+
class={streamdown.theme.td.base}
|
|
389
|
+
{...token.colspan > 1 ? { colspan: token.colspan } : {}}
|
|
390
|
+
{...token.rowspan > 1 ? { rowspan: token.rowspan } : {}}
|
|
391
|
+
{...token.align && ['left', 'center', 'right', 'justify', 'char'].includes(token.align)
|
|
392
|
+
? { align: token.align as 'left' | 'center' | 'right' | 'justify' | 'char' }
|
|
393
|
+
: { align: 'left' }}
|
|
394
|
+
>
|
|
395
|
+
{@render children?.()}
|
|
396
|
+
</td>
|
|
397
|
+
</Slot>
|
|
398
|
+
{/if}
|
|
399
|
+
{:else if token.type === 'th'}
|
|
400
|
+
{#if token.rowspan > 0}
|
|
401
|
+
<Slot
|
|
402
|
+
props={{ children, token, class: streamdown.theme.th.base, style }}
|
|
403
|
+
render={streamdown.snippets.th}
|
|
404
|
+
component={TableHeaderCellComponent}
|
|
405
|
+
>
|
|
406
|
+
<th
|
|
407
|
+
{style}
|
|
408
|
+
data-streamdown-th={id}
|
|
409
|
+
class={streamdown.theme.th.base}
|
|
410
|
+
{...token.colspan > 1 ? { colspan: token.colspan } : {}}
|
|
411
|
+
{...token.rowspan > 1 ? { rowspan: token.rowspan } : {}}
|
|
412
|
+
{...token.align && ['left', 'center', 'right', 'justify', 'char'].includes(token.align)
|
|
413
|
+
? { align: token.align as 'left' | 'center' | 'right' | 'justify' | 'char' }
|
|
414
|
+
: { align: 'left' }}
|
|
415
|
+
>
|
|
416
|
+
{@render children?.()}
|
|
417
|
+
</th>
|
|
418
|
+
</Slot>
|
|
419
|
+
{/if}
|
|
420
|
+
{:else if token.type === 'image'}
|
|
421
|
+
<Image {id} {token} {children} />
|
|
422
|
+
{:else if token.type === 'link'}
|
|
423
|
+
<Link {id} {token} {children} />
|
|
424
|
+
{:else if token.type === 'sub'}
|
|
425
|
+
<Slot
|
|
426
|
+
props={{ children, token, class: streamdown.theme.sub.base }}
|
|
427
|
+
render={streamdown.snippets.sub}
|
|
428
|
+
component={SubComponent}
|
|
429
|
+
>
|
|
430
|
+
<sub data-streamdown-sub={id} class={streamdown.theme.sub.base}>{@render children()}</sub>
|
|
431
|
+
</Slot>
|
|
432
|
+
{:else if token.type === 'sup'}
|
|
433
|
+
<Slot
|
|
434
|
+
props={{ children, token, class: streamdown.theme.sup.base }}
|
|
435
|
+
render={streamdown.snippets.sup}
|
|
436
|
+
component={SupComponent}
|
|
437
|
+
>
|
|
438
|
+
<sup data-streamdown-sup={id} class={streamdown.theme.sup.base}>{@render children()}</sup>
|
|
439
|
+
</Slot>
|
|
440
|
+
{:else if token.type === 'strong'}
|
|
441
|
+
<Slot
|
|
442
|
+
props={{ children, token, class: streamdown.theme.strong.base }}
|
|
443
|
+
render={streamdown.snippets.strong}
|
|
444
|
+
component={StrongComponent}
|
|
445
|
+
>
|
|
446
|
+
<!-- Upstream streamdown styles strong tokens with span rather than semantic strong. -->
|
|
447
|
+
<span data-streamdown-strong={id} class={streamdown.theme.strong.base}
|
|
448
|
+
>{@render children()}</span
|
|
449
|
+
>
|
|
450
|
+
</Slot>
|
|
451
|
+
{:else if token.type === 'em'}
|
|
452
|
+
{#if isRecoveredInlineFormatting || isRecoveredDelimitedFormatting || isIncompleteTableBlock}
|
|
453
|
+
<span data-streamdown-em={id}>{@render children()}</span>
|
|
454
|
+
{:else}
|
|
455
|
+
<Slot
|
|
456
|
+
props={{ children, token, class: streamdown.theme.em.base }}
|
|
457
|
+
render={streamdown.snippets.em}
|
|
458
|
+
component={EmComponent}
|
|
459
|
+
>
|
|
460
|
+
<em data-streamdown-em={id} class={streamdown.theme.em.base}>{@render children()}</em>
|
|
461
|
+
</Slot>
|
|
462
|
+
{/if}
|
|
463
|
+
{:else if token.type === 'del'}
|
|
464
|
+
{#if isRecoveredInlineFormatting || isRecoveredDelimitedFormatting || isIncompleteTableBlock}
|
|
465
|
+
<span data-streamdown-del={id}>{@render children()}</span>
|
|
466
|
+
{:else}
|
|
467
|
+
<Slot
|
|
468
|
+
props={{ children, token, class: streamdown.theme.del.base }}
|
|
469
|
+
render={streamdown.snippets.del}
|
|
470
|
+
component={DelComponent}
|
|
471
|
+
>
|
|
472
|
+
<del data-streamdown-del={id} class={streamdown.theme.del.base}>{@render children()}</del>
|
|
473
|
+
</Slot>
|
|
474
|
+
{/if}
|
|
475
|
+
{:else if token.type === 'hr'}
|
|
476
|
+
<Slot
|
|
477
|
+
props={{ children, token, class: streamdown.theme.hr.base, style }}
|
|
478
|
+
render={streamdown.snippets.hr}
|
|
479
|
+
component={HrComponent}
|
|
480
|
+
>
|
|
481
|
+
<hr data-streamdown-hr={id} {style} class={streamdown.theme.hr.base} />
|
|
482
|
+
</Slot>
|
|
483
|
+
{:else if token.type === 'br'}
|
|
484
|
+
<Slot props={{ children, token }} render={streamdown.snippets.br} component={BrComponent}>
|
|
485
|
+
<br data-streamdown-br={id} />
|
|
486
|
+
</Slot>
|
|
487
|
+
{:else if token.type === 'math'}
|
|
488
|
+
<Slot
|
|
489
|
+
props={{
|
|
490
|
+
children,
|
|
491
|
+
token
|
|
492
|
+
}}
|
|
493
|
+
render={streamdown.snippets.math}
|
|
494
|
+
>
|
|
495
|
+
<MathComponent {id} {token} />
|
|
496
|
+
</Slot>
|
|
497
|
+
{:else if token.type === 'alert'}
|
|
498
|
+
<Alert {id} {token} {children} />
|
|
499
|
+
{:else if token.type === 'footnoteRef'}
|
|
500
|
+
<Slot props={{ token }} render={streamdown.snippets.footnoteRef}>
|
|
501
|
+
<FootnoteRef {token} />
|
|
502
|
+
</Slot>
|
|
503
|
+
{:else if token.type === 'inline-citations'}
|
|
504
|
+
{#if shouldRenderCitationPreview}
|
|
505
|
+
<Slot props={{ token }} render={streamdown.snippets.inlineCitation}>
|
|
506
|
+
<Citation {token} />
|
|
507
|
+
</Slot>
|
|
508
|
+
{:else}
|
|
509
|
+
{token.text}
|
|
510
|
+
{/if}
|
|
511
|
+
{:else if token.type === 'footnote'}
|
|
512
|
+
<!-- Footnotes render as a trailing section in Streamdown.svelte. -->
|
|
513
|
+
{:else if token.type === 'descriptionList'}
|
|
514
|
+
<Slot props={{ children, token }} render={streamdown.snippets.descriptionList}>
|
|
515
|
+
<dl
|
|
516
|
+
data-streamdown-description-list={id}
|
|
517
|
+
style={streamdown.animationBlockStyle}
|
|
518
|
+
class={streamdown.theme.descriptionList.base}
|
|
519
|
+
>
|
|
520
|
+
{@render children()}
|
|
521
|
+
</dl>
|
|
522
|
+
</Slot>
|
|
523
|
+
{:else if token.type === 'description'}
|
|
524
|
+
<Slot props={{ children, token }} render={streamdown.snippets.description}>
|
|
525
|
+
{@render children()}
|
|
526
|
+
</Slot>
|
|
527
|
+
{:else if token.type === 'descriptionTerm'}
|
|
528
|
+
<Slot props={{ children, token }} render={streamdown.snippets.descriptionTerm}>
|
|
529
|
+
<dt data-streamdown-description-term={id} {style} class={streamdown.theme.descriptionTerm.base}>
|
|
530
|
+
{@render children()}
|
|
531
|
+
</dt>
|
|
532
|
+
</Slot>
|
|
533
|
+
{:else if token.type === 'descriptionDetail'}
|
|
534
|
+
<Slot props={{ children, token }} render={streamdown.snippets.descriptionDetail}>
|
|
535
|
+
<dd
|
|
536
|
+
data-streamdown-description-detail={id}
|
|
537
|
+
{style}
|
|
538
|
+
class={streamdown.theme.descriptionDetail.base}
|
|
539
|
+
>
|
|
540
|
+
{@render children()}
|
|
541
|
+
</dd>
|
|
542
|
+
</Slot>
|
|
543
|
+
{:else if token.type === 'def'}
|
|
544
|
+
<!-- TODO This does not seems to be tokenized for now -->
|
|
545
|
+
{:else if token.type === 'escape'}
|
|
546
|
+
<!-- TODO This does not seems to be tokenized for now -->
|
|
547
|
+
{:else if token.type === 'space'}
|
|
548
|
+
<!-- TODO This does not seems to be tokenized for now -->
|
|
549
|
+
{:else if token.type === 'text'}
|
|
550
|
+
{@render children()}
|
|
551
|
+
{:else if token.type === 'html'}
|
|
552
|
+
{@const content = renderHtmlToken(token, {
|
|
553
|
+
allowedImagePrefixes: streamdown.allowedImagePrefixes,
|
|
554
|
+
allowedLinkPrefixes: streamdown.allowedLinkPrefixes,
|
|
555
|
+
allowedTags: streamdown.allowedTags,
|
|
556
|
+
defaultOrigin: streamdown.defaultOrigin,
|
|
557
|
+
renderHtml: streamdown.renderHtml,
|
|
558
|
+
skipHtml: streamdown.skipHtml,
|
|
559
|
+
urlTransform: streamdown.urlTransform
|
|
560
|
+
})}
|
|
561
|
+
{@html content}
|
|
562
|
+
{:else if token.type === 'mdx'}
|
|
563
|
+
{@const Component = streamdown.mdxComponents?.[token.tagName]}
|
|
564
|
+
{#if Component}
|
|
565
|
+
<Component {token} {children} props={token.attributes} />
|
|
566
|
+
{:else}
|
|
567
|
+
<Slot props={{ token, children, props: token.attributes }} render={streamdown.snippets.mdx}>
|
|
568
|
+
{@render children()}
|
|
569
|
+
</Slot>
|
|
570
|
+
{/if}
|
|
571
|
+
{:else}
|
|
572
|
+
<!-- For tokens we don't handle specifically, it may certainely be a custom extension to to the children props to handle -->
|
|
573
|
+
{@render streamdown.children?.({ token, children, streamdown })}
|
|
574
|
+
{/if}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
import type { StreamdownToken } from '../marked/index.js';
|
|
3
|
+
type $$ComponentProps = {
|
|
4
|
+
token: StreamdownToken;
|
|
5
|
+
children: Snippet;
|
|
6
|
+
isIncomplete?: boolean;
|
|
7
|
+
};
|
|
8
|
+
declare const Element: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
9
|
+
type Element = ReturnType<typeof Element>;
|
|
10
|
+
export default Element;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { useStreamdown } from '../context.svelte.js';
|
|
3
|
+
import type { FootnoteRef } from '../marked/marked-footnotes.js';
|
|
4
|
+
|
|
5
|
+
const streamdown = useStreamdown();
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
token
|
|
9
|
+
}: {
|
|
10
|
+
token: FootnoteRef;
|
|
11
|
+
} = $props();
|
|
12
|
+
|
|
13
|
+
const id = $props.id();
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
{#if token.label !== 'streamdown:footnote'}
|
|
17
|
+
<sup data-streamdown-sup={id} class={streamdown.theme.sup.base}>
|
|
18
|
+
<a
|
|
19
|
+
id={'footnote-ref-' + token.label}
|
|
20
|
+
href={'#footnote-' + token.label}
|
|
21
|
+
data-footnote-ref
|
|
22
|
+
data-streamdown-footnote-ref={id}
|
|
23
|
+
class={streamdown.theme.footnoteRef.base}
|
|
24
|
+
aria-describedby="user-content-footnote-label"
|
|
25
|
+
style={streamdown.animationBlockStyle}
|
|
26
|
+
>
|
|
27
|
+
{token.label.replace('^', '')}
|
|
28
|
+
</a>
|
|
29
|
+
</sup>
|
|
30
|
+
{/if}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { FootnoteRef } from '../marked/marked-footnotes.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
token: FootnoteRef;
|
|
4
|
+
};
|
|
5
|
+
declare const FootnoteRef: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
6
|
+
type FootnoteRef = ReturnType<typeof FootnoteRef>;
|
|
7
|
+
export default FootnoteRef;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Footnote } from '../marked/marked-footnotes.js';
|
|
3
|
+
import { useStreamdown } from '../context.svelte.js';
|
|
4
|
+
import Block from '../Block.svelte';
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
entries
|
|
8
|
+
}: {
|
|
9
|
+
entries: Footnote[];
|
|
10
|
+
} = $props();
|
|
11
|
+
|
|
12
|
+
const streamdown = useStreamdown();
|
|
13
|
+
|
|
14
|
+
const visibleEntries = $derived.by(() =>
|
|
15
|
+
entries
|
|
16
|
+
.map((entry) => ({
|
|
17
|
+
...entry,
|
|
18
|
+
content: entry.lines.join('\n').trim()
|
|
19
|
+
}))
|
|
20
|
+
.filter(
|
|
21
|
+
(entry) =>
|
|
22
|
+
entry.label !== 'streamdown:footnote' &&
|
|
23
|
+
((streamdown.mode === 'streaming' && streamdown.isAnimating) ||
|
|
24
|
+
entry.content.length > 0)
|
|
25
|
+
)
|
|
26
|
+
);
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
{#if visibleEntries.length > 0}
|
|
30
|
+
<section data-footnotes class="footnotes">
|
|
31
|
+
<h2 id="user-content-footnote-label" class="sr-only">Footnotes</h2>
|
|
32
|
+
<ol class={streamdown.theme.ol.base}>
|
|
33
|
+
{#each visibleEntries as entry}
|
|
34
|
+
{#if entry.content.length > 0 && streamdown.mode !== 'streaming'}
|
|
35
|
+
<li
|
|
36
|
+
id={'footnote-' + entry.label}
|
|
37
|
+
data-streamdown="list-item"
|
|
38
|
+
class={streamdown.theme.li.base}
|
|
39
|
+
>
|
|
40
|
+
<Block static={true} block={entry.content} tokens={entry.tokens} />
|
|
41
|
+
<a
|
|
42
|
+
href={'#footnote-ref-' + entry.label}
|
|
43
|
+
data-footnote-backref
|
|
44
|
+
class={streamdown.theme.footnoteRef.base}
|
|
45
|
+
aria-label={'Back to reference ' + entry.label}
|
|
46
|
+
>
|
|
47
|
+
↩
|
|
48
|
+
</a>
|
|
49
|
+
</li>
|
|
50
|
+
{/if}
|
|
51
|
+
{/each}
|
|
52
|
+
</ol>
|
|
53
|
+
</section>
|
|
54
|
+
{/if}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Footnote } from '../marked/marked-footnotes.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
entries: Footnote[];
|
|
4
|
+
};
|
|
5
|
+
declare const Footnotes: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
6
|
+
type Footnotes = ReturnType<typeof Footnotes>;
|
|
7
|
+
export default Footnotes;
|