@svadmin/ai-elements 0.7.4 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -4
- package/THIRD_PARTY_NOTICES.md +67 -6
- package/dist/ai-workspace-contract.d.ts +14 -0
- package/dist/ai-workspace-contract.js +14 -0
- package/dist/ai.css +2 -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/index.d.ts +2 -0
- package/dist/index.js +1 -0
- 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,30 @@
|
|
|
1
|
+
import type { PluginConfig } from './plugins.js';
|
|
2
|
+
interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
|
|
3
|
+
new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
|
|
4
|
+
$$bindings?: Bindings;
|
|
5
|
+
} & Exports;
|
|
6
|
+
(internal: unknown, props: Props & {
|
|
7
|
+
$$events?: Events;
|
|
8
|
+
$$slots?: Slots;
|
|
9
|
+
}): Exports & {
|
|
10
|
+
$set?: any;
|
|
11
|
+
$on?: any;
|
|
12
|
+
};
|
|
13
|
+
z_$$bindings?: Bindings;
|
|
14
|
+
}
|
|
15
|
+
type $$__sveltets_2_PropsWithChildren<Props, Slots> = Props & (Slots extends {
|
|
16
|
+
default: any;
|
|
17
|
+
} ? Props extends Record<string, never> ? any : {
|
|
18
|
+
children?: any;
|
|
19
|
+
} : {});
|
|
20
|
+
declare const PluginProvider: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWithChildren<{
|
|
21
|
+
plugins?: PluginConfig | null;
|
|
22
|
+
}, {
|
|
23
|
+
default: {};
|
|
24
|
+
}>, {
|
|
25
|
+
[evt: string]: CustomEvent<any>;
|
|
26
|
+
}, {
|
|
27
|
+
default: {};
|
|
28
|
+
}, {}, string>;
|
|
29
|
+
type PluginProvider = InstanceType<typeof PluginProvider>;
|
|
30
|
+
export default PluginProvider;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Locked native-style Streamdown fork
|
|
2
|
+
|
|
3
|
+
This is the Apache-2.0 distribution of streamdown-svelte 3.0.6. LICENSE and any NOTICE are retained. Only theme.js is modified: two class-composition calls use svadmin finite CSS metadata instead of a utility-language engine. Parser, streaming repair, URL policy, sanitizers, controls and public props are unchanged. The provenance manifest records each original file digest.
|
|
4
|
+
|
|
5
|
+
This copy is deliberately owned: upstream fixes must be reviewed and updated explicitly; package-manager updates will not update it. Unknown host classes are preserved, not interpreted as arbitrary utilities. Rebuild svadmin CSS after editing its finite styles.
|
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
<script lang="ts" generics="Source extends Record<string, any> = Record<string, any>">
|
|
2
|
+
import { useDarkMode } from './utils/darkMode.svelte.js';
|
|
3
|
+
import Block from './Block.svelte';
|
|
4
|
+
import { type MermaidOptions, type StreamdownProps } from './context.svelte.js';
|
|
5
|
+
import { IconContext } from './icon-context.js';
|
|
6
|
+
import { PluginContext } from './plugin-context.js';
|
|
7
|
+
import { getThemeName } from './plugins.js';
|
|
8
|
+
import {
|
|
9
|
+
createMarkdownParseCache,
|
|
10
|
+
type MarkdownBlockCacheScope,
|
|
11
|
+
type MarkdownBlockParseResult
|
|
12
|
+
} from './markdown-parse-cache.js';
|
|
13
|
+
import Footnotes from './Elements/Footnotes.svelte';
|
|
14
|
+
import { parseBlocks } from './marked/index.js';
|
|
15
|
+
import { hasIncompleteCodeFence } from './streaming.js';
|
|
16
|
+
import { mergeTranslations } from './translations.js';
|
|
17
|
+
import { resolveParserExtensions } from './plugins.js';
|
|
18
|
+
import {
|
|
19
|
+
buildFootnoteEntries,
|
|
20
|
+
buildParsedBlocks,
|
|
21
|
+
mergeFootnoteState,
|
|
22
|
+
preprocessStreamdownContent,
|
|
23
|
+
resolveBlockDirection,
|
|
24
|
+
resolveCaretPresentation,
|
|
25
|
+
shouldResolveFootnotes
|
|
26
|
+
} from './streamdown/pipeline.js';
|
|
27
|
+
import {
|
|
28
|
+
collectThemeRegistrations,
|
|
29
|
+
defaultLinkSafetyConfig,
|
|
30
|
+
resolveAnimationConfig,
|
|
31
|
+
resolveControls,
|
|
32
|
+
resolveShikiThemePair,
|
|
33
|
+
resolveThemeClassMap
|
|
34
|
+
} from './streamdown/config.js';
|
|
35
|
+
import { createStreamdownRuntimeContext } from './streamdown/context.js';
|
|
36
|
+
import { repairStreamdownRenderedMarkdown } from './streamdown/incomplete-markdown.js';
|
|
37
|
+
|
|
38
|
+
let {
|
|
39
|
+
content = '',
|
|
40
|
+
class: className,
|
|
41
|
+
className: futureClassName,
|
|
42
|
+
shikiTheme,
|
|
43
|
+
shikiLanguages,
|
|
44
|
+
shikiThemes,
|
|
45
|
+
mermaid,
|
|
46
|
+
plugins,
|
|
47
|
+
remend: remendOptions,
|
|
48
|
+
parseIncompleteMarkdown = true,
|
|
49
|
+
parseMarkdownIntoBlocksFn,
|
|
50
|
+
mode = 'streaming',
|
|
51
|
+
dir,
|
|
52
|
+
defaultOrigin,
|
|
53
|
+
allowedLinkPrefixes = ['*'],
|
|
54
|
+
allowedImagePrefixes = ['*'],
|
|
55
|
+
linkSafety = defaultLinkSafetyConfig,
|
|
56
|
+
allowedTags,
|
|
57
|
+
allowedElements,
|
|
58
|
+
allowElement,
|
|
59
|
+
disallowedElements,
|
|
60
|
+
literalTagContent,
|
|
61
|
+
normalizeHtmlIndentation: shouldNormalizeHtmlIndentation = false,
|
|
62
|
+
skipHtml,
|
|
63
|
+
unwrapDisallowed,
|
|
64
|
+
urlTransform,
|
|
65
|
+
prefix,
|
|
66
|
+
lineNumbers = true,
|
|
67
|
+
theme,
|
|
68
|
+
mermaidConfig = {},
|
|
69
|
+
katexConfig,
|
|
70
|
+
translations,
|
|
71
|
+
baseTheme,
|
|
72
|
+
mergeTheme: shouldMergeTheme = true,
|
|
73
|
+
streamdown = $bindable(),
|
|
74
|
+
renderHtml,
|
|
75
|
+
controls = true,
|
|
76
|
+
isAnimating = false,
|
|
77
|
+
animated,
|
|
78
|
+
caret,
|
|
79
|
+
onAnimationStart,
|
|
80
|
+
onAnimationEnd,
|
|
81
|
+
BlockComponent,
|
|
82
|
+
animation,
|
|
83
|
+
element = $bindable(),
|
|
84
|
+
icons,
|
|
85
|
+
children,
|
|
86
|
+
extensions,
|
|
87
|
+
sources,
|
|
88
|
+
inlineCitationsMode = 'carousel',
|
|
89
|
+
mdxComponents,
|
|
90
|
+
components,
|
|
91
|
+
static: isStatic,
|
|
92
|
+
...snippets
|
|
93
|
+
}: StreamdownProps<Source> = $props();
|
|
94
|
+
|
|
95
|
+
const darkMode = useDarkMode();
|
|
96
|
+
const resolvedMode = $derived(isStatic === undefined ? mode : isStatic ? 'static' : 'streaming');
|
|
97
|
+
const resolvedStatic = $derived(resolvedMode === 'static');
|
|
98
|
+
const shouldShowCaret = $derived(resolvedMode !== 'static' && Boolean(caret) && isAnimating);
|
|
99
|
+
const resolvedControls = $derived(resolveControls(controls));
|
|
100
|
+
const resolvedShikiThemePair = $derived.by(() => {
|
|
101
|
+
if (plugins?.code) {
|
|
102
|
+
return plugins.code.getThemes();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return resolveShikiThemePair(shikiTheme);
|
|
106
|
+
});
|
|
107
|
+
const resolvedAnimation = $derived.by(() => {
|
|
108
|
+
return resolveAnimationConfig({
|
|
109
|
+
animation,
|
|
110
|
+
animated,
|
|
111
|
+
isAnimating,
|
|
112
|
+
mode: resolvedMode
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
const resolvedTheme = $derived.by(() =>
|
|
116
|
+
resolveThemeClassMap({
|
|
117
|
+
theme,
|
|
118
|
+
baseTheme,
|
|
119
|
+
shouldMergeTheme,
|
|
120
|
+
prefix
|
|
121
|
+
})
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
const shikiThemedTheme = $derived(getThemeName(resolvedShikiThemePair[darkMode.current ? 1 : 0]));
|
|
125
|
+
|
|
126
|
+
const mermaidThemedTheme = $derived(
|
|
127
|
+
mermaidConfig?.theme ? mermaidConfig.theme : darkMode.current ? 'dark' : 'default'
|
|
128
|
+
);
|
|
129
|
+
const resolvedMermaid = $derived<MermaidOptions | undefined>(mermaid);
|
|
130
|
+
|
|
131
|
+
const allowedTagNames = $derived(allowedTags ? Object.keys(allowedTags) : []);
|
|
132
|
+
const resolvedExtensions = $derived.by(() => resolveParserExtensions(extensions, plugins) ?? []);
|
|
133
|
+
|
|
134
|
+
const preprocessedContent = $derived.by(() =>
|
|
135
|
+
preprocessStreamdownContent({
|
|
136
|
+
content,
|
|
137
|
+
shouldNormalizeHtmlIndentation,
|
|
138
|
+
literalTagContent,
|
|
139
|
+
allowedTagNames
|
|
140
|
+
})
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
streamdown = createStreamdownRuntimeContext<Source>({
|
|
144
|
+
parse: {
|
|
145
|
+
content: () => content,
|
|
146
|
+
remend: () => remendOptions,
|
|
147
|
+
parseIncompleteMarkdown: () => parseIncompleteMarkdown,
|
|
148
|
+
parseMarkdownIntoBlocksFn: () => parseMarkdownIntoBlocksFn ?? parseBlocks,
|
|
149
|
+
mode: () => resolvedMode,
|
|
150
|
+
dir: () => dir,
|
|
151
|
+
sources: () => sources,
|
|
152
|
+
inlineCitationsMode: () => inlineCitationsMode,
|
|
153
|
+
extensions: () => resolvedExtensions
|
|
154
|
+
},
|
|
155
|
+
security: {
|
|
156
|
+
defaultOrigin: () => defaultOrigin,
|
|
157
|
+
allowedLinkPrefixes: () => allowedLinkPrefixes,
|
|
158
|
+
allowedImagePrefixes: () => allowedImagePrefixes,
|
|
159
|
+
linkSafety: () => linkSafety,
|
|
160
|
+
allowedTags: () => allowedTags,
|
|
161
|
+
allowedElements: () => allowedElements,
|
|
162
|
+
allowElement: () => allowElement,
|
|
163
|
+
disallowedElements: () => disallowedElements,
|
|
164
|
+
literalTagContent: () => literalTagContent,
|
|
165
|
+
normalizeHtmlIndentation: () => shouldNormalizeHtmlIndentation,
|
|
166
|
+
skipHtml: () => skipHtml,
|
|
167
|
+
unwrapDisallowed: () => unwrapDisallowed,
|
|
168
|
+
urlTransform: () => urlTransform,
|
|
169
|
+
renderHtml: () => renderHtml ?? true
|
|
170
|
+
},
|
|
171
|
+
render: {
|
|
172
|
+
BlockComponent: () => BlockComponent,
|
|
173
|
+
prefix: () => prefix,
|
|
174
|
+
lineNumbers: () => lineNumbers,
|
|
175
|
+
shikiTheme: () => shikiThemedTheme,
|
|
176
|
+
snippets: () => snippets,
|
|
177
|
+
theme: () => resolvedTheme,
|
|
178
|
+
baseTheme: () => baseTheme,
|
|
179
|
+
mermaidConfig: () => ({
|
|
180
|
+
theme: mermaidThemedTheme,
|
|
181
|
+
...(resolvedMermaid?.config ?? {}),
|
|
182
|
+
...mermaidConfig
|
|
183
|
+
}),
|
|
184
|
+
mermaid: () => resolvedMermaid,
|
|
185
|
+
katexConfig: () => katexConfig,
|
|
186
|
+
plugins: () => plugins,
|
|
187
|
+
translations: () => mergeTranslations(translations),
|
|
188
|
+
shikiLanguages: () => shikiLanguages,
|
|
189
|
+
shikiThemes: () => ({
|
|
190
|
+
...(shikiThemes ?? {}),
|
|
191
|
+
...collectThemeRegistrations(resolvedShikiThemePair)
|
|
192
|
+
}),
|
|
193
|
+
children: () => children,
|
|
194
|
+
mdxComponents: () => mdxComponents,
|
|
195
|
+
components: () => components
|
|
196
|
+
},
|
|
197
|
+
uiConfig: {
|
|
198
|
+
element: () => element,
|
|
199
|
+
animation: () => resolvedAnimation,
|
|
200
|
+
isAnimating: () => isAnimating,
|
|
201
|
+
animated: () => animated,
|
|
202
|
+
caret: () => caret,
|
|
203
|
+
onAnimationStart: () => onAnimationStart,
|
|
204
|
+
onAnimationEnd: () => onAnimationEnd,
|
|
205
|
+
controls: () => resolvedControls.controls,
|
|
206
|
+
codeControls: () => resolvedControls.codeControls,
|
|
207
|
+
icons: () => icons
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
PluginContext.provide(() => plugins ?? null);
|
|
211
|
+
IconContext.provide(() => icons);
|
|
212
|
+
|
|
213
|
+
const id = $props.id();
|
|
214
|
+
let previousIsAnimating = $state<boolean | undefined>(undefined);
|
|
215
|
+
const markdownParseCache = createMarkdownParseCache();
|
|
216
|
+
|
|
217
|
+
$effect(() => {
|
|
218
|
+
if (resolvedMode === 'static') {
|
|
219
|
+
previousIsAnimating = isAnimating;
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (previousIsAnimating === undefined) {
|
|
224
|
+
if (isAnimating) {
|
|
225
|
+
onAnimationStart?.();
|
|
226
|
+
}
|
|
227
|
+
} else if (!previousIsAnimating && isAnimating) {
|
|
228
|
+
onAnimationStart?.();
|
|
229
|
+
} else if (previousIsAnimating && !isAnimating) {
|
|
230
|
+
onAnimationEnd?.();
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
previousIsAnimating = isAnimating;
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
const parseMarkdownWithOptionalFootnotes = (
|
|
237
|
+
markdown: string,
|
|
238
|
+
cacheScope: MarkdownBlockCacheScope = 'stable'
|
|
239
|
+
): MarkdownBlockParseResult =>
|
|
240
|
+
markdownParseCache.parseBlock({
|
|
241
|
+
markdown,
|
|
242
|
+
extensions: streamdown.extensions,
|
|
243
|
+
resolveFootnotes: shouldResolveFootnotes({
|
|
244
|
+
markdown,
|
|
245
|
+
mode: resolvedMode,
|
|
246
|
+
parseIncompleteMarkdown
|
|
247
|
+
}),
|
|
248
|
+
cacheScope
|
|
249
|
+
});
|
|
250
|
+
const normalizedContent = $derived.by(() => {
|
|
251
|
+
return preprocessedContent;
|
|
252
|
+
});
|
|
253
|
+
const renderContent = $derived.by(() =>
|
|
254
|
+
resolvedMode === 'streaming' && parseIncompleteMarkdown
|
|
255
|
+
? repairStreamdownRenderedMarkdown(normalizedContent, remendOptions)
|
|
256
|
+
: normalizedContent
|
|
257
|
+
);
|
|
258
|
+
const parsedMarkdownDocument = $derived.by(() => {
|
|
259
|
+
if (resolvedStatic) {
|
|
260
|
+
const staticBlock = parseMarkdownWithOptionalFootnotes(renderContent);
|
|
261
|
+
return {
|
|
262
|
+
blocks: [renderContent],
|
|
263
|
+
footnotes: staticBlock.footnotes,
|
|
264
|
+
staticBlock
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return {
|
|
269
|
+
...markdownParseCache.parseDocument({
|
|
270
|
+
markdown: renderContent,
|
|
271
|
+
extensions: streamdown.extensions,
|
|
272
|
+
resolveFootnotes: shouldResolveFootnotes({
|
|
273
|
+
markdown: normalizedContent,
|
|
274
|
+
mode: resolvedMode,
|
|
275
|
+
parseIncompleteMarkdown
|
|
276
|
+
}),
|
|
277
|
+
splitBlocksFn: parseMarkdownIntoBlocksFn ?? parseBlocks,
|
|
278
|
+
blockCacheScope: 'transient'
|
|
279
|
+
}),
|
|
280
|
+
staticBlock: null
|
|
281
|
+
};
|
|
282
|
+
});
|
|
283
|
+
const rawBlocks = $derived(parsedMarkdownDocument.blocks);
|
|
284
|
+
const blockIsIncomplete = $derived(
|
|
285
|
+
rawBlocks.map(
|
|
286
|
+
(block, index) =>
|
|
287
|
+
resolvedMode === 'streaming' &&
|
|
288
|
+
isAnimating &&
|
|
289
|
+
index === rawBlocks.length - 1
|
|
290
|
+
)
|
|
291
|
+
);
|
|
292
|
+
const parsedDocument = $derived.by(() => {
|
|
293
|
+
return {
|
|
294
|
+
footnotes: parsedMarkdownDocument.footnotes
|
|
295
|
+
};
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
const parsedBlocks = $derived.by(() =>
|
|
299
|
+
buildParsedBlocks({
|
|
300
|
+
resolvedStatic,
|
|
301
|
+
normalizedContent: renderContent,
|
|
302
|
+
parsedMarkdownDocument,
|
|
303
|
+
rawBlocks,
|
|
304
|
+
blockIsIncomplete,
|
|
305
|
+
mode: resolvedMode,
|
|
306
|
+
isAnimating,
|
|
307
|
+
parseMarkdownWithFootnotes: parseMarkdownWithOptionalFootnotes
|
|
308
|
+
})
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
const footnoteState = $derived.by(() =>
|
|
312
|
+
mergeFootnoteState({
|
|
313
|
+
documentFootnotes: parsedDocument.footnotes,
|
|
314
|
+
parsedBlocks
|
|
315
|
+
})
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
const footnoteEntries = $derived.by(() =>
|
|
319
|
+
buildFootnoteEntries({
|
|
320
|
+
footnoteState,
|
|
321
|
+
parseMarkdownWithFootnotes: (markdown) => parseMarkdownWithOptionalFootnotes(markdown),
|
|
322
|
+
filtering: {
|
|
323
|
+
allowedElements: streamdown.allowedElements,
|
|
324
|
+
allowElement: streamdown.allowElement,
|
|
325
|
+
disallowedElements: streamdown.disallowedElements,
|
|
326
|
+
skipHtml: streamdown.skipHtml,
|
|
327
|
+
unwrapDisallowed: streamdown.unwrapDisallowed
|
|
328
|
+
}
|
|
329
|
+
})
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
$effect(() => {
|
|
333
|
+
streamdown.footnotes.refs = new Map(footnoteState.refs);
|
|
334
|
+
streamdown.footnotes.footnotes = new Map(footnoteState.footnotes);
|
|
335
|
+
});
|
|
336
|
+
const caretPresentation = $derived.by(() =>
|
|
337
|
+
resolveCaretPresentation({
|
|
338
|
+
caret,
|
|
339
|
+
className,
|
|
340
|
+
futureClassName,
|
|
341
|
+
prefix,
|
|
342
|
+
rawBlocks,
|
|
343
|
+
shouldShowCaret
|
|
344
|
+
})
|
|
345
|
+
);
|
|
346
|
+
const shouldHideCaret = $derived(caretPresentation.shouldHideCaret);
|
|
347
|
+
const rootStyle = $derived(caretPresentation.rootStyle);
|
|
348
|
+
const rootClassName = $derived(caretPresentation.rootClassName);
|
|
349
|
+
</script>
|
|
350
|
+
|
|
351
|
+
<div bind:this={element} class={rootClassName} style={rootStyle}>
|
|
352
|
+
{#if shouldShowCaret && !shouldHideCaret && parsedBlocks.length === 0}<span
|
|
353
|
+
></span>{/if}{#each parsedBlocks as parsedBlock, index (`${id}-block-${index}`)}{#if BlockComponent}{#snippet blockChildren()}<Block
|
|
354
|
+
static={resolvedStatic}
|
|
355
|
+
block={parsedBlock.raw}
|
|
356
|
+
tokens={parsedBlock.tokens}
|
|
357
|
+
parseIncompleteMarkdown={false}
|
|
358
|
+
isIncomplete={parsedBlock.isIncomplete}
|
|
359
|
+
/>{/snippet}<BlockComponent
|
|
360
|
+
content={parsedBlock.raw}
|
|
361
|
+
shouldParseIncompleteMarkdown={parseIncompleteMarkdown}
|
|
362
|
+
{shouldNormalizeHtmlIndentation}
|
|
363
|
+
{index}
|
|
364
|
+
isIncomplete={parsedBlock.isIncomplete}
|
|
365
|
+
dir={resolveBlockDirection({ block: parsedBlock.raw, dir })}
|
|
366
|
+
children={blockChildren}
|
|
367
|
+
/>{:else}<Block
|
|
368
|
+
static={resolvedStatic}
|
|
369
|
+
block={parsedBlock.raw}
|
|
370
|
+
tokens={parsedBlock.tokens}
|
|
371
|
+
parseIncompleteMarkdown={false}
|
|
372
|
+
isIncomplete={parsedBlock.isIncomplete}
|
|
373
|
+
/>{/if}{/each}<Footnotes entries={footnoteEntries} />
|
|
374
|
+
</div>
|
|
375
|
+
|
|
376
|
+
<style global>
|
|
377
|
+
:global {
|
|
378
|
+
@keyframes sd-fade {
|
|
379
|
+
from {
|
|
380
|
+
opacity: 0;
|
|
381
|
+
}
|
|
382
|
+
to {
|
|
383
|
+
opacity: 1;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
@keyframes sd-blur {
|
|
388
|
+
from {
|
|
389
|
+
opacity: 0;
|
|
390
|
+
filter: blur(5px);
|
|
391
|
+
}
|
|
392
|
+
to {
|
|
393
|
+
opacity: 1;
|
|
394
|
+
filter: blur(0px);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
@keyframes sd-slideUp {
|
|
399
|
+
from {
|
|
400
|
+
transform: translateY(10%);
|
|
401
|
+
opacity: 0;
|
|
402
|
+
}
|
|
403
|
+
to {
|
|
404
|
+
transform: translateY(0);
|
|
405
|
+
opacity: 1;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
@keyframes sd-slideDown {
|
|
410
|
+
from {
|
|
411
|
+
transform: translateY(-10%);
|
|
412
|
+
opacity: 0;
|
|
413
|
+
}
|
|
414
|
+
to {
|
|
415
|
+
transform: translateY(0);
|
|
416
|
+
opacity: 1;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
.sd-line-numbers {
|
|
421
|
+
counter-reset: sd-line;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
.sd-line-numbers > .sd-code-line {
|
|
425
|
+
position: relative;
|
|
426
|
+
display: block;
|
|
427
|
+
min-height: 1lh;
|
|
428
|
+
line-height: 1lh;
|
|
429
|
+
padding-left: 3rem;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
.sd-line-numbers > .sd-code-line::before {
|
|
433
|
+
content: counter(sd-line);
|
|
434
|
+
counter-increment: sd-line;
|
|
435
|
+
position: absolute;
|
|
436
|
+
left: 0;
|
|
437
|
+
top: 0;
|
|
438
|
+
width: 2rem;
|
|
439
|
+
display: block;
|
|
440
|
+
text-align: right;
|
|
441
|
+
font-size: 13px;
|
|
442
|
+
line-height: 1lh;
|
|
443
|
+
color: rgb(107 114 128);
|
|
444
|
+
user-select: none;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
</style>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type StreamdownProps } from './context.svelte.js';
|
|
2
|
+
declare function $$render<Source extends Record<string, any> = Record<string, any>>(): {
|
|
3
|
+
props: StreamdownProps<Source>;
|
|
4
|
+
exports: {};
|
|
5
|
+
bindings: "streamdown" | "element";
|
|
6
|
+
slots: {};
|
|
7
|
+
events: {};
|
|
8
|
+
};
|
|
9
|
+
declare class __sveltets_Render<Source extends Record<string, any> = Record<string, any>> {
|
|
10
|
+
props(): ReturnType<typeof $$render<Source>>['props'];
|
|
11
|
+
events(): ReturnType<typeof $$render<Source>>['events'];
|
|
12
|
+
slots(): ReturnType<typeof $$render<Source>>['slots'];
|
|
13
|
+
bindings(): "streamdown" | "element";
|
|
14
|
+
exports(): {};
|
|
15
|
+
}
|
|
16
|
+
interface $$IsomorphicComponent {
|
|
17
|
+
new <Source extends Record<string, any> = Record<string, any>>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<Source>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<Source>['props']>, ReturnType<__sveltets_Render<Source>['events']>, ReturnType<__sveltets_Render<Source>['slots']>> & {
|
|
18
|
+
$$bindings?: ReturnType<__sveltets_Render<Source>['bindings']>;
|
|
19
|
+
} & ReturnType<__sveltets_Render<Source>['exports']>;
|
|
20
|
+
<Source extends Record<string, any> = Record<string, any>>(internal: unknown, props: ReturnType<__sveltets_Render<Source>['props']> & {}): ReturnType<__sveltets_Render<Source>['exports']>;
|
|
21
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
22
|
+
}
|
|
23
|
+
declare const Streamdown: $$IsomorphicComponent;
|
|
24
|
+
type Streamdown<Source extends Record<string, any> = Record<string, any>> = InstanceType<typeof Streamdown<Source>>;
|
|
25
|
+
export default Streamdown;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getContext } from 'svelte';
|
|
3
|
+
import AnimatedText from '../AnimatedText.svelte';
|
|
4
|
+
import { useStreamdown } from '../context.svelte.js';
|
|
5
|
+
import Element from '../Elements/Element.svelte';
|
|
6
|
+
import type { StreamdownToken } from '../marked/index.js';
|
|
7
|
+
import { getTokenChildren, renderLeafText, shouldAnimateLeafText } from './text.js';
|
|
8
|
+
|
|
9
|
+
let {
|
|
10
|
+
tokens,
|
|
11
|
+
isIncomplete = false,
|
|
12
|
+
isStatic = false
|
|
13
|
+
}: {
|
|
14
|
+
tokens: StreamdownToken[];
|
|
15
|
+
isIncomplete?: boolean;
|
|
16
|
+
isStatic?: boolean;
|
|
17
|
+
} = $props();
|
|
18
|
+
|
|
19
|
+
const streamdown = useStreamdown();
|
|
20
|
+
const insidePopover = Boolean(getContext('POPOVER'));
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
{#snippet renderChildren(items: StreamdownToken[])}
|
|
24
|
+
{#each items as token}
|
|
25
|
+
{@const children = getTokenChildren(token)}
|
|
26
|
+
<Element {token} {isIncomplete}>
|
|
27
|
+
{#if children.length === 0}
|
|
28
|
+
{#if shouldAnimateLeafText({
|
|
29
|
+
token,
|
|
30
|
+
animationEnabled: streamdown.animation.enabled,
|
|
31
|
+
insidePopover,
|
|
32
|
+
isStatic
|
|
33
|
+
})}
|
|
34
|
+
<AnimatedText text={renderLeafText(token)} />
|
|
35
|
+
{:else}
|
|
36
|
+
{renderLeafText(token)}
|
|
37
|
+
{/if}
|
|
38
|
+
{:else}
|
|
39
|
+
{@render renderChildren(children)}
|
|
40
|
+
{/if}
|
|
41
|
+
</Element>
|
|
42
|
+
{/each}
|
|
43
|
+
{/snippet}
|
|
44
|
+
|
|
45
|
+
{@render renderChildren(tokens)}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { StreamdownToken } from '../marked/index.js';
|
|
2
|
+
type $$ComponentProps = {
|
|
3
|
+
tokens: StreamdownToken[];
|
|
4
|
+
isIncomplete?: boolean;
|
|
5
|
+
isStatic?: boolean;
|
|
6
|
+
};
|
|
7
|
+
declare const BlockTokens: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
8
|
+
type BlockTokens = ReturnType<typeof BlockTokens>;
|
|
9
|
+
export default BlockTokens;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Tokens } from 'marked';
|
|
2
|
+
import type { UrlTransform } from '../markdown.js';
|
|
3
|
+
import type { AllowedTags } from '../security/types.js';
|
|
4
|
+
export type BlockHtmlRenderOptions = {
|
|
5
|
+
allowedImagePrefixes?: string[];
|
|
6
|
+
allowedLinkPrefixes?: string[];
|
|
7
|
+
allowedTags?: AllowedTags;
|
|
8
|
+
defaultOrigin?: string;
|
|
9
|
+
renderHtml?: boolean | ((token: Tokens.HTML | Tokens.Tag) => string);
|
|
10
|
+
skipHtml?: boolean;
|
|
11
|
+
urlTransform?: UrlTransform;
|
|
12
|
+
};
|
|
13
|
+
export declare const isSecurityHtmlBlock: (markdown: string, { allowedTags, skipHtml }: Pick<BlockHtmlRenderOptions, "allowedTags" | "skipHtml">) => boolean;
|
|
14
|
+
export declare const renderBlockHtml: (markdown: string, options: BlockHtmlRenderOptions) => string | null;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { escapeHtml, renderMarkdownFragment } from '../security/html.js';
|
|
2
|
+
const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
3
|
+
export const isSecurityHtmlBlock = (markdown, { allowedTags, skipHtml }) => {
|
|
4
|
+
if (skipHtml) {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
const trimmed = markdown.trimStart();
|
|
8
|
+
if (trimmed.startsWith('<')) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
return Object.keys(allowedTags ?? {}).some((tagName) => new RegExp(`<\\/?${escapeRegExp(tagName)}(?=[\\s>/])`, 'i').test(markdown));
|
|
12
|
+
};
|
|
13
|
+
export const renderBlockHtml = (markdown, options) => {
|
|
14
|
+
if (!isSecurityHtmlBlock(markdown, options)) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
if (options.renderHtml === false) {
|
|
18
|
+
return escapeHtml(markdown);
|
|
19
|
+
}
|
|
20
|
+
return renderMarkdownFragment(markdown, {
|
|
21
|
+
allowedImagePrefixes: options.allowedImagePrefixes,
|
|
22
|
+
allowedLinkPrefixes: options.allowedLinkPrefixes,
|
|
23
|
+
allowedTags: options.allowedTags,
|
|
24
|
+
defaultOrigin: options.defaultOrigin,
|
|
25
|
+
urlTransform: options.urlTransform
|
|
26
|
+
});
|
|
27
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { StreamdownToken } from '../marked/index.js';
|
|
2
|
+
export declare const decodeHtmlEntities: (value: string) => string;
|
|
3
|
+
export declare const renderLeafText: (token: StreamdownToken) => string;
|
|
4
|
+
export declare const getTokenChildren: (token: StreamdownToken) => StreamdownToken[];
|
|
5
|
+
export declare const shouldAnimateLeafText: ({ animationEnabled, insidePopover, isStatic, token }: {
|
|
6
|
+
animationEnabled: boolean;
|
|
7
|
+
insidePopover: boolean;
|
|
8
|
+
isStatic: boolean;
|
|
9
|
+
token: StreamdownToken;
|
|
10
|
+
}) => boolean;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const namedHtmlEntities = {
|
|
2
|
+
amp: '&',
|
|
3
|
+
apos: "'",
|
|
4
|
+
bull: '•',
|
|
5
|
+
copy: '©',
|
|
6
|
+
gt: '>',
|
|
7
|
+
hearts: '♥',
|
|
8
|
+
lt: '<',
|
|
9
|
+
mdash: '—',
|
|
10
|
+
nbsp: '\u00A0',
|
|
11
|
+
quot: '"'
|
|
12
|
+
};
|
|
13
|
+
export const decodeHtmlEntities = (value) => value.replace(/&(#x?[0-9a-fA-F]+|[a-zA-Z][a-zA-Z0-9]+);/g, (match, entity) => {
|
|
14
|
+
if (entity.startsWith('#x') || entity.startsWith('#X')) {
|
|
15
|
+
const codePoint = Number.parseInt(entity.slice(2), 16);
|
|
16
|
+
return Number.isFinite(codePoint) ? String.fromCodePoint(codePoint) : match;
|
|
17
|
+
}
|
|
18
|
+
if (entity.startsWith('#')) {
|
|
19
|
+
const codePoint = Number.parseInt(entity.slice(1), 10);
|
|
20
|
+
return Number.isFinite(codePoint) ? String.fromCodePoint(codePoint) : match;
|
|
21
|
+
}
|
|
22
|
+
return namedHtmlEntities[entity] ?? match;
|
|
23
|
+
});
|
|
24
|
+
export const renderLeafText = (token) => {
|
|
25
|
+
if (!('text' in token) || typeof token.text !== 'string') {
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
return token.type === 'text' ? decodeHtmlEntities(token.text) : token.text;
|
|
29
|
+
};
|
|
30
|
+
export const getTokenChildren = (token) => 'tokens' in token && Array.isArray(token.tokens) ? token.tokens : [];
|
|
31
|
+
export const shouldAnimateLeafText = ({ animationEnabled, insidePopover, isStatic, token }) => animationEnabled && !insidePopover && !isStatic && token.type !== 'codespan';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const STREAMDOWN_CONTEXT_KEY = "streamdown";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const STREAMDOWN_CONTEXT_KEY = 'streamdown';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Footnote, FootnoteRef } from './marked/marked-footnotes.js';
|
|
2
|
+
import type { StreamdownContext as StreamdownContextContract } from './contracts/streamdown.js';
|
|
3
|
+
export { normalizeMermaidControls } from './contracts/streamdown.js';
|
|
4
|
+
import { StreamdownParseRuntime, StreamdownRenderRuntime, StreamdownSecurityRuntime, StreamdownUiConfigRuntime, type StreamdownRuntimeSections } from './streamdown/runtime.js';
|
|
5
|
+
export type { AllowedTags, AnimateOptions, BlockProps, CodeControlsConfig, Components, ControlsConfig, IconMap, LinkSafetyConfig, LinkSafetyModalProps, MermaidControls, MermaidErrorComponentProps, MermaidOptions, NormalizedMermaidControls, ResolvedAnimationConfig, Snippets, StreamdownComponents, StreamdownControlsConfig, StreamdownProps, TableControlsConfig } from './contracts/streamdown.js';
|
|
6
|
+
export type { StreamdownParseRuntimeInit, StreamdownSecurityRuntimeInit, StreamdownRenderRuntimeInit, StreamdownUiConfigRuntimeInit, StreamdownRuntimeSections } from './streamdown/runtime.js';
|
|
7
|
+
export interface StreamdownContext<Source extends Record<string, any> = Record<string, any>> extends StreamdownContextContract<Source> {
|
|
8
|
+
}
|
|
9
|
+
export declare class StreamdownContext<Source extends Record<string, any> = Record<string, any>> {
|
|
10
|
+
footnotes: {
|
|
11
|
+
refs: Map<string, FootnoteRef>;
|
|
12
|
+
footnotes: Map<string, Footnote>;
|
|
13
|
+
};
|
|
14
|
+
isMounted: boolean;
|
|
15
|
+
readonly parse: StreamdownParseRuntime<Source>;
|
|
16
|
+
readonly security: StreamdownSecurityRuntime<Source>;
|
|
17
|
+
readonly render: StreamdownRenderRuntime<Source>;
|
|
18
|
+
readonly uiConfig: StreamdownUiConfigRuntime<Source>;
|
|
19
|
+
get animationTextStyle(): string | undefined;
|
|
20
|
+
get animationBlockStyle(): string | undefined;
|
|
21
|
+
constructor(props: StreamdownRuntimeSections<Source>);
|
|
22
|
+
}
|
|
23
|
+
export declare const useStreamdown: <Source extends Record<string, any> = Record<string, any>>() => StreamdownContext<Source>;
|
|
24
|
+
export type StreamdownContextType = StreamdownContext;
|