@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.
- package/README.md +20 -4
- package/THIRD_PARTY_NOTICES.md +67 -6
- package/dist/ai.css +1 -5
- package/dist/ai.theme.css +1 -0
- 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/Response.svelte +2 -2
- package/dist/components/Response.svelte.d.ts +1 -1
- package/dist/components/code/index.d.ts +9 -18
- package/dist/components/code/index.js +8 -11
- package/dist/components/code-block/highlight.js +1 -1
- package/dist/utilities.css +3172 -0
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +1 -1
- package/package.json +36 -11
- 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
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { useStreamdown } from '../context.svelte.js';
|
|
3
|
+
import { extractCodeFenceLanguage, getThemeName, type HighlightToken } from '../plugins.js';
|
|
4
|
+
import { STREAMDOWN_BLOCK_CONTEXT } from '../incomplete-code.js';
|
|
5
|
+
import { save } from '../utils/save.js';
|
|
6
|
+
import { useCopy } from '../utils/copy.svelte.js';
|
|
7
|
+
import { HighlighterManager, languageExtensionMap } from '../utils/hightlighter.svelte.js';
|
|
8
|
+
import { parseCodeFenceInfo } from '../utils/code-block.js';
|
|
9
|
+
import { bundledLanguagesInfo } from '../utils/bundledLanguages.js';
|
|
10
|
+
import type { Tokens } from 'marked';
|
|
11
|
+
import { getContext, untrack } from 'svelte';
|
|
12
|
+
import { checkIcon, copyIcon, downloadIcon, resolveIcon } from './icons.js';
|
|
13
|
+
|
|
14
|
+
type RenderToken = HighlightToken;
|
|
15
|
+
|
|
16
|
+
const {
|
|
17
|
+
token,
|
|
18
|
+
id,
|
|
19
|
+
isIncomplete = false
|
|
20
|
+
}: {
|
|
21
|
+
token: Tokens.Code;
|
|
22
|
+
id: string;
|
|
23
|
+
isIncomplete?: boolean;
|
|
24
|
+
} = $props();
|
|
25
|
+
|
|
26
|
+
const streamdown = useStreamdown();
|
|
27
|
+
const block = getContext<{ isIncompleteCodeFence: boolean }>(STREAMDOWN_BLOCK_CONTEXT);
|
|
28
|
+
const highlighter = HighlighterManager.create(
|
|
29
|
+
bundledLanguagesInfo,
|
|
30
|
+
streamdown.shikiThemes,
|
|
31
|
+
streamdown.shikiLanguages
|
|
32
|
+
);
|
|
33
|
+
const codePlugin = $derived(streamdown.plugins?.code ?? null);
|
|
34
|
+
const fence = $derived(parseCodeFenceInfo(token.lang));
|
|
35
|
+
const displayLanguage = $derived(
|
|
36
|
+
extractCodeFenceLanguage(token) || fence.language || token.lang || ''
|
|
37
|
+
);
|
|
38
|
+
const language = $derived(
|
|
39
|
+
extractCodeFenceLanguage(token) || fence.language || token.lang || 'text'
|
|
40
|
+
);
|
|
41
|
+
const pluginThemes = $derived(codePlugin?.getThemes() ?? null);
|
|
42
|
+
const activeThemeName = $derived(streamdown.shikiTheme);
|
|
43
|
+
const pluginActiveTheme = $derived.by(() => {
|
|
44
|
+
if (!pluginThemes) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return pluginThemes.find((theme) => getThemeName(theme) === activeThemeName) ?? activeThemeName;
|
|
49
|
+
});
|
|
50
|
+
const showLineNumbers = $derived(streamdown.lineNumbers && fence.showLineNumbers);
|
|
51
|
+
const incomplete = $derived(Boolean(block ? block.isIncompleteCodeFence : isIncomplete));
|
|
52
|
+
const buttonDisabled = $derived(streamdown.isAnimating || incomplete);
|
|
53
|
+
const showCodeActions = $derived(
|
|
54
|
+
streamdown.controls.code && (streamdown.codeControls.copy || streamdown.codeControls.download)
|
|
55
|
+
);
|
|
56
|
+
const codeStyle = $derived(
|
|
57
|
+
showLineNumbers && fence.startLine && fence.startLine > 1
|
|
58
|
+
? `counter-reset: sd-line ${fence.startLine - 1};`
|
|
59
|
+
: undefined
|
|
60
|
+
);
|
|
61
|
+
let pluginTokens = $state<RenderToken[][] | null>(null);
|
|
62
|
+
|
|
63
|
+
const copy = useCopy({
|
|
64
|
+
get content() {
|
|
65
|
+
return token.text;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const downloadCode = () => {
|
|
70
|
+
if (buttonDisabled) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
const extension =
|
|
76
|
+
language && language in languageExtensionMap
|
|
77
|
+
? languageExtensionMap[language as keyof typeof languageExtensionMap]
|
|
78
|
+
: 'txt';
|
|
79
|
+
const filename = `file.${extension}`;
|
|
80
|
+
const mimeType = 'text/plain';
|
|
81
|
+
save(filename, token.text, mimeType);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
console.error('Failed to download file:', error);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
$effect(() => {
|
|
88
|
+
const theme = activeThemeName;
|
|
89
|
+
const lang = language;
|
|
90
|
+
if (codePlugin) {
|
|
91
|
+
const result = codePlugin.highlight(
|
|
92
|
+
{
|
|
93
|
+
code: token.text,
|
|
94
|
+
language: lang,
|
|
95
|
+
themes: codePlugin.getThemes(),
|
|
96
|
+
activeTheme: pluginActiveTheme ?? undefined
|
|
97
|
+
},
|
|
98
|
+
(asyncResult) => {
|
|
99
|
+
pluginTokens = asyncResult.tokens;
|
|
100
|
+
}
|
|
101
|
+
);
|
|
102
|
+
pluginTokens = result?.tokens ?? null;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
untrack(() => {
|
|
107
|
+
void highlighter.load(theme, lang);
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const renderedLines = $derived.by(() => {
|
|
112
|
+
if (token.text.length === 0) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
if (codePlugin) {
|
|
117
|
+
return pluginTokens;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (!highlighter.isReady(activeThemeName, language)) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return highlighter.highlightCode(token.text, language, activeThemeName);
|
|
125
|
+
});
|
|
126
|
+
</script>
|
|
127
|
+
|
|
128
|
+
<div
|
|
129
|
+
data-streamdown="code-block"
|
|
130
|
+
data-language={language}
|
|
131
|
+
data-streamdown-code={id}
|
|
132
|
+
data-incomplete={incomplete ? 'true' : undefined}
|
|
133
|
+
style={streamdown.isMounted ? streamdown.animationBlockStyle : ''}
|
|
134
|
+
class={streamdown.theme.code.base}
|
|
135
|
+
>
|
|
136
|
+
<div data-streamdown="code-block-header" class={streamdown.theme.code.header}>
|
|
137
|
+
<span class={streamdown.theme.code.language}>{displayLanguage}</span>
|
|
138
|
+
</div>
|
|
139
|
+
{#if showCodeActions}
|
|
140
|
+
<div data-streamdown="code-block-actions-shell" class={streamdown.theme.code.actions}>
|
|
141
|
+
<div data-streamdown="code-block-actions" class={streamdown.theme.code.buttons}>
|
|
142
|
+
{#if streamdown.codeControls.download}
|
|
143
|
+
<button
|
|
144
|
+
class={streamdown.theme.components.button}
|
|
145
|
+
onclick={downloadCode}
|
|
146
|
+
title={streamdown.translations.downloadFile}
|
|
147
|
+
disabled={buttonDisabled}
|
|
148
|
+
type="button"
|
|
149
|
+
>
|
|
150
|
+
{@render resolveIcon(streamdown.icons, 'download', downloadIcon)()}
|
|
151
|
+
</button>
|
|
152
|
+
{/if}
|
|
153
|
+
|
|
154
|
+
{#if streamdown.codeControls.copy}
|
|
155
|
+
<button
|
|
156
|
+
class={streamdown.theme.components.button}
|
|
157
|
+
onclick={() => {
|
|
158
|
+
if (!buttonDisabled) {
|
|
159
|
+
void copy.copy();
|
|
160
|
+
}
|
|
161
|
+
}}
|
|
162
|
+
title={streamdown.translations.copyCode}
|
|
163
|
+
disabled={buttonDisabled}
|
|
164
|
+
type="button"
|
|
165
|
+
>
|
|
166
|
+
{#if copy.isCopied}
|
|
167
|
+
{@render resolveIcon(streamdown.icons, 'check', checkIcon)()}
|
|
168
|
+
{:else}
|
|
169
|
+
{@render resolveIcon(streamdown.icons, 'copy', copyIcon)()}
|
|
170
|
+
{/if}
|
|
171
|
+
</button>
|
|
172
|
+
{/if}
|
|
173
|
+
</div>
|
|
174
|
+
</div>
|
|
175
|
+
{/if}
|
|
176
|
+
<div
|
|
177
|
+
data-streamdown="code-block-body"
|
|
178
|
+
data-language={language}
|
|
179
|
+
style="height: fit-content; width: 100%;"
|
|
180
|
+
class={streamdown.theme.code.container}
|
|
181
|
+
>
|
|
182
|
+
{#if renderedLines}
|
|
183
|
+
<pre class={streamdown.theme.code.pre}><code
|
|
184
|
+
class="block"
|
|
185
|
+
class:sd-line-numbers={showLineNumbers}
|
|
186
|
+
data-streamdown-line-numbers={showLineNumbers}
|
|
187
|
+
style={codeStyle}>{@render Tokens(renderedLines)}</code
|
|
188
|
+
></pre>
|
|
189
|
+
{:else}
|
|
190
|
+
<pre class={streamdown.theme.code.pre}><code
|
|
191
|
+
class="block"
|
|
192
|
+
class:sd-line-numbers={showLineNumbers}
|
|
193
|
+
data-streamdown-line-numbers={showLineNumbers}
|
|
194
|
+
style={codeStyle}>{@render Skeleton(token.text.split('\n'))}</code
|
|
195
|
+
></pre>
|
|
196
|
+
{/if}
|
|
197
|
+
</div>
|
|
198
|
+
</div>
|
|
199
|
+
|
|
200
|
+
{#snippet Tokens(lines: RenderToken[][])}
|
|
201
|
+
{#each lines as tokens}
|
|
202
|
+
<span class={`sd-code-line ${streamdown.theme.code.line}`}>
|
|
203
|
+
{#each tokens as token}
|
|
204
|
+
<span
|
|
205
|
+
style={streamdown.isMounted ? streamdown.animationTextStyle : ''}
|
|
206
|
+
style:color={token.color}
|
|
207
|
+
style:background-color={token.bgColor}
|
|
208
|
+
>
|
|
209
|
+
{token.content}
|
|
210
|
+
</span>
|
|
211
|
+
{/each}
|
|
212
|
+
</span>
|
|
213
|
+
{/each}
|
|
214
|
+
{/snippet}
|
|
215
|
+
|
|
216
|
+
{#snippet Skeleton(lines: string[])}
|
|
217
|
+
{#if lines.length === 1 && lines[0]?.length === 0}
|
|
218
|
+
{'\n'}
|
|
219
|
+
{:else}
|
|
220
|
+
{#each lines as line}
|
|
221
|
+
<span class={`sd-code-line ${streamdown.theme.code.skeleton}`}>
|
|
222
|
+
{line.length > 0 ? line : '\n'}
|
|
223
|
+
</span>
|
|
224
|
+
{/each}
|
|
225
|
+
{/if}
|
|
226
|
+
{/snippet}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Tokens } from 'marked';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
token: Tokens.Code;
|
|
4
|
+
id: string;
|
|
5
|
+
isIncomplete?: boolean;
|
|
6
|
+
};
|
|
7
|
+
declare const Code: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
8
|
+
type Code = ReturnType<typeof Code>;
|
|
9
|
+
export default Code;
|