@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.
Files changed (303) hide show
  1. package/README.md +18 -53
  2. package/THIRD_PARTY_NOTICES.md +67 -6
  3. package/dist/ai.css +149 -2740
  4. package/dist/ai.theme.css +1 -2771
  5. package/dist/class-properties.generated.d.ts +1 -0
  6. package/dist/class-properties.generated.js +2 -0
  7. package/dist/classnames.d.ts +8 -0
  8. package/dist/classnames.js +26 -0
  9. package/dist/components/AICommandBar.svelte +6 -4
  10. package/dist/components/ChatDialog.svelte +102 -125
  11. package/dist/components/ChatDialog.svelte.d.ts +3 -9
  12. package/dist/components/Conversation.svelte +34 -10
  13. package/dist/components/ConversationContent.svelte +1 -1
  14. package/dist/components/ConversationScrollButton.svelte +0 -1
  15. package/dist/components/CopilotPanel.svelte +8 -6
  16. package/dist/components/Message.svelte +1 -1
  17. package/dist/components/MessageActions.svelte +1 -1
  18. package/dist/components/MessageContent.svelte +1 -1
  19. package/dist/components/MessageToolbar.svelte +1 -1
  20. package/dist/components/Response.svelte +32 -12
  21. package/dist/components/Response.svelte.d.ts +3 -3
  22. package/dist/components/Tool.svelte +13 -13
  23. package/dist/components/Tool.svelte.d.ts +1 -1
  24. package/dist/components/action/Action.svelte +3 -1
  25. package/dist/components/artifact/ArtifactAction.svelte +3 -1
  26. package/dist/components/attachments/Attachment.svelte +4 -2
  27. package/dist/components/attachments/Attachments.svelte +3 -1
  28. package/dist/components/attachments/types.js +3 -2
  29. package/dist/components/audio-player/AudioPlayer.svelte.d.ts +1 -1
  30. package/dist/components/canvas/Canvas.svelte +1 -1
  31. package/dist/components/checkpoint/index.d.ts +2 -2
  32. package/dist/components/code/index.d.ts +9 -1
  33. package/dist/components/code/index.js +8 -1
  34. package/dist/components/code-block/CodeBlockLanguageSelector.svelte.d.ts +1 -1
  35. package/dist/components/code-block/highlight.js +11 -10
  36. package/dist/components/commit/Commit.svelte +23 -2
  37. package/dist/components/commit/CommitActions.svelte +2 -11
  38. package/dist/components/commit/CommitCopyButton.svelte +1 -1
  39. package/dist/components/commit/CommitHeader.svelte +12 -2
  40. package/dist/components/commit/context.svelte.d.ts +6 -0
  41. package/dist/components/commit/context.svelte.js +14 -0
  42. package/dist/components/context/Context.svelte +6 -4
  43. package/dist/components/context/TokensWithCost.svelte +2 -1
  44. package/dist/components/edge/Animated.svelte +6 -6
  45. package/dist/components/edge/Temporary.svelte +6 -5
  46. package/dist/components/file-tree/FileTree.svelte +7 -5
  47. package/dist/components/jsx-preview/parser.js +10 -10
  48. package/dist/components/message/MessageAction.svelte +3 -1
  49. package/dist/components/mic-selector/MicSelector.svelte.d.ts +1 -1
  50. package/dist/components/model-selector/ModelSelectorDialog.svelte +3 -1
  51. package/dist/components/open-in-chat/OpenInChatGPT.svelte +3 -1
  52. package/dist/components/open-in-chat/OpenInClaude.svelte +3 -1
  53. package/dist/components/open-in-chat/OpenInCursor.svelte +3 -1
  54. package/dist/components/open-in-chat/OpenInGitHub.svelte +3 -1
  55. package/dist/components/open-in-chat/OpenInScira.svelte +3 -1
  56. package/dist/components/open-in-chat/OpenInT3.svelte +3 -1
  57. package/dist/components/open-in-chat/OpenInv0.svelte +3 -1
  58. package/dist/components/package-info/PackageInfo.svelte +3 -1
  59. package/dist/components/prompt-input/PromptInput.svelte +8 -18
  60. package/dist/components/prompt-input/PromptInputCommand.svelte +2 -1
  61. package/dist/components/prompt-input/PromptInputSelect.svelte.d.ts +1 -1
  62. package/dist/components/prompt-input/PromptInputSubmit.svelte +5 -18
  63. package/dist/components/prompt-input/PromptInputTextarea.svelte +6 -11
  64. package/dist/components/prompt-input/context.svelte.d.ts +1 -8
  65. package/dist/components/prompt-input/files.js +3 -2
  66. package/dist/components/question/Question.svelte +3 -1
  67. package/dist/components/schema-display/SchemaDisplay.svelte +4 -2
  68. package/dist/components/schema-display/SchemaDisplayParameter.svelte +14 -1
  69. package/dist/components/schema-display/SchemaDisplayProperty.svelte +16 -1
  70. package/dist/components/snippet/index.d.ts +3 -3
  71. package/dist/components/stack-trace/StackTrace.svelte +7 -5
  72. package/dist/components/suggestion/index.d.ts +1 -1
  73. package/dist/components/terminal/Terminal.svelte +4 -2
  74. package/dist/components/terminal/ansi.js +9 -6
  75. package/dist/components/test-results/Test.svelte +1 -1
  76. package/dist/components/test-results/TestResults.svelte +1 -1
  77. package/dist/components/test-results/context.svelte.d.ts +1 -1
  78. package/dist/components/tool/ToolContent.svelte +1 -1
  79. package/dist/components/tool/ToolHeader.svelte +5 -5
  80. package/dist/components/tool/ToolInput.svelte +2 -4
  81. package/dist/components/tool/ToolOutput.svelte +2 -4
  82. package/dist/components/tool/ToolStatusBadge.svelte +2 -3
  83. package/dist/components/voice-selector/VoiceSelector.svelte +2 -1
  84. package/dist/components/voice-selector/VoiceSelector.svelte.d.ts +2 -2
  85. package/dist/components/voice-selector/context.svelte.d.ts +2 -1
  86. package/dist/components/web-preview/WebPreview.svelte +4 -3
  87. package/dist/contracts.d.ts +2 -2
  88. package/dist/generated-components.d.ts +15 -1
  89. package/dist/generated-components.js +20 -1
  90. package/dist/internal/Tooltip.svelte +2 -1
  91. package/dist/parity-manifest.d.ts +0 -1
  92. package/dist/parity-manifest.js +0 -97
  93. package/dist/utilities.css +3172 -0
  94. package/dist/utils.d.ts +1 -1
  95. package/dist/utils.js +1 -1
  96. package/package.json +37 -22
  97. package/vendor/streamdown/AnimatedText.svelte +93 -0
  98. package/vendor/streamdown/AnimatedText.svelte.d.ts +6 -0
  99. package/vendor/streamdown/Block.svelte +96 -0
  100. package/vendor/streamdown/Block.svelte.d.ts +11 -0
  101. package/vendor/streamdown/Elements/Alert.svelte +69 -0
  102. package/vendor/streamdown/Elements/Alert.svelte.d.ts +10 -0
  103. package/vendor/streamdown/Elements/Citation.svelte +260 -0
  104. package/vendor/streamdown/Elements/Citation.svelte.d.ts +7 -0
  105. package/vendor/streamdown/Elements/Code.svelte +226 -0
  106. package/vendor/streamdown/Elements/Code.svelte.d.ts +9 -0
  107. package/vendor/streamdown/Elements/Element.svelte +574 -0
  108. package/vendor/streamdown/Elements/Element.svelte.d.ts +10 -0
  109. package/vendor/streamdown/Elements/FootnoteRef.svelte +30 -0
  110. package/vendor/streamdown/Elements/FootnoteRef.svelte.d.ts +7 -0
  111. package/vendor/streamdown/Elements/Footnotes.svelte +54 -0
  112. package/vendor/streamdown/Elements/Footnotes.svelte.d.ts +7 -0
  113. package/vendor/streamdown/Elements/Image.svelte +200 -0
  114. package/vendor/streamdown/Elements/Image.svelte.d.ts +10 -0
  115. package/vendor/streamdown/Elements/Link.svelte +220 -0
  116. package/vendor/streamdown/Elements/Link.svelte.d.ts +10 -0
  117. package/vendor/streamdown/Elements/LinkSafetyModal.svelte +121 -0
  118. package/vendor/streamdown/Elements/LinkSafetyModal.svelte.d.ts +4 -0
  119. package/vendor/streamdown/Elements/Math.svelte +100 -0
  120. package/vendor/streamdown/Elements/Math.svelte.d.ts +9 -0
  121. package/vendor/streamdown/Elements/Mermaid.svelte +455 -0
  122. package/vendor/streamdown/Elements/Mermaid.svelte.d.ts +9 -0
  123. package/vendor/streamdown/Elements/MermaidDownload.svelte +145 -0
  124. package/vendor/streamdown/Elements/MermaidDownload.svelte.d.ts +8 -0
  125. package/vendor/streamdown/Elements/Slot.svelte +23 -0
  126. package/vendor/streamdown/Elements/Slot.svelte.d.ts +10 -0
  127. package/vendor/streamdown/Elements/Table.svelte +195 -0
  128. package/vendor/streamdown/Elements/Table.svelte.d.ts +9 -0
  129. package/vendor/streamdown/Elements/TableDownload.svelte +221 -0
  130. package/vendor/streamdown/Elements/TableDownload.svelte.d.ts +8 -0
  131. package/vendor/streamdown/Elements/fallbacks/CodeFallback.svelte +41 -0
  132. package/vendor/streamdown/Elements/fallbacks/CodeFallback.svelte.d.ts +9 -0
  133. package/vendor/streamdown/Elements/fallbacks/MathFallback.svelte +35 -0
  134. package/vendor/streamdown/Elements/fallbacks/MathFallback.svelte.d.ts +8 -0
  135. package/vendor/streamdown/Elements/fallbacks/MermaidFallback.svelte +36 -0
  136. package/vendor/streamdown/Elements/fallbacks/MermaidFallback.svelte.d.ts +9 -0
  137. package/vendor/streamdown/Elements/fallbacks/index.d.ts +3 -0
  138. package/vendor/streamdown/Elements/fallbacks/index.js +3 -0
  139. package/vendor/streamdown/Elements/icons.d.ts +31 -0
  140. package/vendor/streamdown/Elements/icons.js +200 -0
  141. package/vendor/streamdown/Elements/index.d.ts +8 -0
  142. package/vendor/streamdown/Elements/index.js +8 -0
  143. package/vendor/streamdown/Elements/popover.svelte.d.ts +8 -0
  144. package/vendor/streamdown/Elements/popover.svelte.js +45 -0
  145. package/vendor/streamdown/Elements/stepperState.svelte.d.ts +36 -0
  146. package/vendor/streamdown/Elements/stepperState.svelte.js +92 -0
  147. package/vendor/streamdown/IconProvider.svelte +11 -0
  148. package/vendor/streamdown/IconProvider.svelte.d.ts +30 -0
  149. package/vendor/streamdown/LICENSE +202 -0
  150. package/vendor/streamdown/PluginProvider.svelte +11 -0
  151. package/vendor/streamdown/PluginProvider.svelte.d.ts +30 -0
  152. package/vendor/streamdown/README.svadmin.md +5 -0
  153. package/vendor/streamdown/Streamdown.svelte +447 -0
  154. package/vendor/streamdown/Streamdown.svelte.d.ts +25 -0
  155. package/vendor/streamdown/block/BlockTokens.svelte +45 -0
  156. package/vendor/streamdown/block/BlockTokens.svelte.d.ts +9 -0
  157. package/vendor/streamdown/block/html.d.ts +14 -0
  158. package/vendor/streamdown/block/html.js +27 -0
  159. package/vendor/streamdown/block/text.d.ts +10 -0
  160. package/vendor/streamdown/block/text.js +31 -0
  161. package/vendor/streamdown/context-key.d.ts +1 -0
  162. package/vendor/streamdown/context-key.js +1 -0
  163. package/vendor/streamdown/context.svelte.d.ts +24 -0
  164. package/vendor/streamdown/context.svelte.js +75 -0
  165. package/vendor/streamdown/contracts/plugins.d.ts +26 -0
  166. package/vendor/streamdown/contracts/plugins.js +1 -0
  167. package/vendor/streamdown/contracts/streamdown.d.ts +374 -0
  168. package/vendor/streamdown/contracts/streamdown.js +29 -0
  169. package/vendor/streamdown/detect-direction.d.ts +1 -0
  170. package/vendor/streamdown/detect-direction.js +1 -0
  171. package/vendor/streamdown/icon-context.d.ts +36 -0
  172. package/vendor/streamdown/icon-context.js +52 -0
  173. package/vendor/streamdown/incomplete-code.d.ts +6 -0
  174. package/vendor/streamdown/incomplete-code.js +23 -0
  175. package/vendor/streamdown/index.d.ts +22 -0
  176. package/vendor/streamdown/index.js +20 -0
  177. package/vendor/streamdown/markdown-parse-cache.d.ts +37 -0
  178. package/vendor/streamdown/markdown-parse-cache.js +109 -0
  179. package/vendor/streamdown/markdown.d.ts +21 -0
  180. package/vendor/streamdown/markdown.js +214 -0
  181. package/vendor/streamdown/marked/index.d.ts +44 -0
  182. package/vendor/streamdown/marked/index.js +228 -0
  183. package/vendor/streamdown/marked/marked-alert.d.ts +13 -0
  184. package/vendor/streamdown/marked/marked-alert.js +47 -0
  185. package/vendor/streamdown/marked/marked-align.d.ts +10 -0
  186. package/vendor/streamdown/marked/marked-align.js +45 -0
  187. package/vendor/streamdown/marked/marked-br.d.ts +6 -0
  188. package/vendor/streamdown/marked/marked-br.js +15 -0
  189. package/vendor/streamdown/marked/marked-citations.d.ts +8 -0
  190. package/vendor/streamdown/marked/marked-citations.js +53 -0
  191. package/vendor/streamdown/marked/marked-cjk.d.ts +2 -0
  192. package/vendor/streamdown/marked/marked-cjk.js +165 -0
  193. package/vendor/streamdown/marked/marked-dl.d.ts +23 -0
  194. package/vendor/streamdown/marked/marked-dl.js +44 -0
  195. package/vendor/streamdown/marked/marked-footnotes.d.ts +26 -0
  196. package/vendor/streamdown/marked/marked-footnotes.js +101 -0
  197. package/vendor/streamdown/marked/marked-hr.d.ts +6 -0
  198. package/vendor/streamdown/marked/marked-hr.js +18 -0
  199. package/vendor/streamdown/marked/marked-list.d.ts +31 -0
  200. package/vendor/streamdown/marked/marked-list.js +330 -0
  201. package/vendor/streamdown/marked/marked-math.d.ts +13 -0
  202. package/vendor/streamdown/marked/marked-math.js +129 -0
  203. package/vendor/streamdown/marked/marked-mdx.d.ts +12 -0
  204. package/vendor/streamdown/marked/marked-mdx.js +124 -0
  205. package/vendor/streamdown/marked/marked-subsup.d.ts +22 -0
  206. package/vendor/streamdown/marked/marked-subsup.js +40 -0
  207. package/vendor/streamdown/marked/marked-table.d.ts +80 -0
  208. package/vendor/streamdown/marked/marked-table.js +527 -0
  209. package/vendor/streamdown/plugin-context.d.ts +19 -0
  210. package/vendor/streamdown/plugin-context.js +40 -0
  211. package/vendor/streamdown/plugins/cjk-shared.d.ts +1 -0
  212. package/vendor/streamdown/plugins/cjk-shared.js +1 -0
  213. package/vendor/streamdown/plugins.d.ts +19 -0
  214. package/vendor/streamdown/plugins.js +107 -0
  215. package/vendor/streamdown/provenance.json +229 -0
  216. package/vendor/streamdown/remend.d.ts +2 -0
  217. package/vendor/streamdown/remend.js +1 -0
  218. package/vendor/streamdown/security/html.d.ts +19 -0
  219. package/vendor/streamdown/security/html.js +329 -0
  220. package/vendor/streamdown/security/preprocess-custom-tags.d.ts +1 -0
  221. package/vendor/streamdown/security/preprocess-custom-tags.js +20 -0
  222. package/vendor/streamdown/security/preprocess-literal-tag-content.d.ts +1 -0
  223. package/vendor/streamdown/security/preprocess-literal-tag-content.js +16 -0
  224. package/vendor/streamdown/security/types.d.ts +1 -0
  225. package/vendor/streamdown/security/types.js +1 -0
  226. package/vendor/streamdown/site/SiteHeader.svelte +94 -0
  227. package/vendor/streamdown/site/SiteHeader.svelte.d.ts +6 -0
  228. package/vendor/streamdown/site/home/HomeDemo.svelte +122 -0
  229. package/vendor/streamdown/site/home/HomeDemo.svelte.d.ts +3 -0
  230. package/vendor/streamdown/site/home/HomePage.svelte +293 -0
  231. package/vendor/streamdown/site/home/HomePage.svelte.d.ts +3 -0
  232. package/vendor/streamdown/site/home/content.d.ts +69 -0
  233. package/vendor/streamdown/site/home/content.js +144 -0
  234. package/vendor/streamdown/site/metadata.d.ts +4 -0
  235. package/vendor/streamdown/site/metadata.js +4 -0
  236. package/vendor/streamdown/site/navigation.d.ts +6 -0
  237. package/vendor/streamdown/site/navigation.js +22 -0
  238. package/vendor/streamdown/streamdown/config.d.ts +41 -0
  239. package/vendor/streamdown/streamdown/config.js +125 -0
  240. package/vendor/streamdown/streamdown/context.d.ts +12 -0
  241. package/vendor/streamdown/streamdown/context.js +2 -0
  242. package/vendor/streamdown/streamdown/incomplete-markdown.d.ts +5 -0
  243. package/vendor/streamdown/streamdown/incomplete-markdown.js +79 -0
  244. package/vendor/streamdown/streamdown/pipeline.d.ts +95 -0
  245. package/vendor/streamdown/streamdown/pipeline.js +138 -0
  246. package/vendor/streamdown/streamdown/runtime.d.ts +59 -0
  247. package/vendor/streamdown/streamdown/runtime.js +112 -0
  248. package/vendor/streamdown/streaming.d.ts +5 -0
  249. package/vendor/streamdown/streaming.js +5 -0
  250. package/vendor/streamdown/theme.d.ts +486 -0
  251. package/vendor/streamdown/theme.js +370 -0
  252. package/vendor/streamdown/translations.d.ts +43 -0
  253. package/vendor/streamdown/translations.js +54 -0
  254. package/vendor/streamdown/url-policy.d.ts +1 -0
  255. package/vendor/streamdown/url-policy.js +1 -0
  256. package/vendor/streamdown/utils/bind.d.ts +8 -0
  257. package/vendor/streamdown/utils/bind.js +26 -0
  258. package/vendor/streamdown/utils/bundledLanguages.d.ts +1 -0
  259. package/vendor/streamdown/utils/bundledLanguages.js +1 -0
  260. package/vendor/streamdown/utils/code-block.d.ts +8 -0
  261. package/vendor/streamdown/utils/code-block.js +38 -0
  262. package/vendor/streamdown/utils/copy.svelte.d.ts +7 -0
  263. package/vendor/streamdown/utils/copy.svelte.js +38 -0
  264. package/vendor/streamdown/utils/darkMode.svelte.d.ts +3 -0
  265. package/vendor/streamdown/utils/darkMode.svelte.js +49 -0
  266. package/vendor/streamdown/utils/detectDirection.d.ts +1 -0
  267. package/vendor/streamdown/utils/detectDirection.js +19 -0
  268. package/vendor/streamdown/utils/get.d.ts +1 -0
  269. package/vendor/streamdown/utils/get.js +25 -0
  270. package/vendor/streamdown/utils/hightlighter.svelte.d.ts +30 -0
  271. package/vendor/streamdown/utils/hightlighter.svelte.js +524 -0
  272. package/vendor/streamdown/utils/index.d.ts +3 -0
  273. package/vendor/streamdown/utils/index.js +3 -0
  274. package/vendor/streamdown/utils/mermaid.d.ts +13 -0
  275. package/vendor/streamdown/utils/mermaid.js +49 -0
  276. package/vendor/streamdown/utils/panzoom.svelte.d.ts +35 -0
  277. package/vendor/streamdown/utils/panzoom.svelte.js +556 -0
  278. package/vendor/streamdown/utils/parse-incomplete-markdown.d.ts +2 -0
  279. package/vendor/streamdown/utils/parse-incomplete-markdown.js +2 -0
  280. package/vendor/streamdown/utils/runtime-env.d.ts +1 -0
  281. package/vendor/streamdown/utils/runtime-env.js +13 -0
  282. package/vendor/streamdown/utils/save.d.ts +1 -0
  283. package/vendor/streamdown/utils/save.js +14 -0
  284. package/vendor/streamdown/utils/scroll-lock.d.ts +2 -0
  285. package/vendor/streamdown/utils/scroll-lock.js +35 -0
  286. package/vendor/streamdown/utils/table.d.ts +8 -0
  287. package/vendor/streamdown/utils/table.js +176 -0
  288. package/vendor/streamdown/utils/url.d.ts +22 -0
  289. package/vendor/streamdown/utils/url.js +98 -0
  290. package/vendor/streamdown/utils/useClickOutside.svelte.d.ts +8 -0
  291. package/vendor/streamdown/utils/useClickOutside.svelte.js +41 -0
  292. package/vendor/streamdown/utils/useKeyDown.svelte.d.ts +5 -0
  293. package/vendor/streamdown/utils/useKeyDown.svelte.js +23 -0
  294. package/UPSTREAM_PARITY.md +0 -69
  295. package/dist/ai-theme.css +0 -28
  296. package/dist/components/code/code-variants.d.ts +0 -25
  297. package/dist/components/code/code-variants.js +0 -20
  298. package/dist/components/conversation/scroll.d.ts +0 -4
  299. package/dist/components/conversation/scroll.js +0 -85
  300. package/dist/components/message/content-polish-html.d.ts +0 -5
  301. package/dist/components/message/content-polish-html.js +0 -75
  302. package/dist/components/tool/content-polish-scroll-region.d.ts +0 -3
  303. package/dist/components/tool/content-polish-scroll-region.js +0 -22
@@ -0,0 +1,200 @@
1
+ <script lang="ts">
2
+ import { useStreamdown } from '../context.svelte.js';
3
+ import { applyMarkdownUrlTransform, createMarkdownElement } from '../markdown.js';
4
+ import { save } from '../utils/save.js';
5
+ import { isPathRelativeUrl, transformUrl } from '../utils/url.js';
6
+ import Slot from './Slot.svelte';
7
+ import { downloadIcon, resolveIcon } from './icons.js';
8
+ import type { Tokens } from 'marked';
9
+ import type { Snippet } from 'svelte';
10
+
11
+ const streamdown = useStreamdown();
12
+
13
+ const {
14
+ children,
15
+ token,
16
+ id
17
+ }: {
18
+ children: Snippet;
19
+ token: Tokens.Image;
20
+ id: string;
21
+ } = $props();
22
+
23
+ const imageSource = $derived.by(() => {
24
+ if (token.href === 'streamdown:incomplete-image') {
25
+ return null;
26
+ }
27
+
28
+ const transformedHref = applyMarkdownUrlTransform(
29
+ token.href,
30
+ 'src',
31
+ createMarkdownElement('img', {
32
+ alt: token.text,
33
+ src: token.href,
34
+ title: token.title ?? undefined
35
+ }),
36
+ streamdown.urlTransform
37
+ );
38
+
39
+ if (typeof transformedHref !== 'string' || transformedHref.length === 0) {
40
+ return null;
41
+ }
42
+
43
+ if (isPathRelativeUrl(transformedHref)) {
44
+ return transformedHref;
45
+ }
46
+
47
+ return (
48
+ transformUrl(
49
+ transformedHref,
50
+ streamdown.allowedImagePrefixes ?? [],
51
+ streamdown.defaultOrigin,
52
+ {
53
+ kind: 'image'
54
+ }
55
+ ) ?? null
56
+ );
57
+ });
58
+
59
+ let isLoaded = $state(false);
60
+ let hasError = $state(false);
61
+ let imageElement = $state<HTMLImageElement | null>(null);
62
+
63
+ function getImageSource(): string | null {
64
+ return imageSource;
65
+ }
66
+
67
+ function getExtensionFromBlob(blob: Blob): string {
68
+ const type = blob.type.toLowerCase();
69
+ if (type === 'image/svg+xml') return 'svg';
70
+ if (type === 'image/jpeg') return 'jpg';
71
+ if (type === 'image/gif') return 'gif';
72
+ if (type === 'image/webp') return 'webp';
73
+ return 'png';
74
+ }
75
+
76
+ function getFilename(source: string, blob: Blob): string {
77
+ const cleanUrl = source.split('#')[0].split('?')[0];
78
+ const lastSegment = cleanUrl.split('/').filter(Boolean).at(-1);
79
+ if (lastSegment && /\.[a-z0-9]+$/i.test(lastSegment)) {
80
+ return lastSegment;
81
+ }
82
+
83
+ const baseName = token.text?.trim() || 'image';
84
+ return `${baseName}.${getExtensionFromBlob(blob)}`;
85
+ }
86
+
87
+ async function downloadImage(): Promise<void> {
88
+ const source = getImageSource();
89
+ if (!source) {
90
+ return;
91
+ }
92
+
93
+ const response = await fetch(source);
94
+ const blob = await response.blob();
95
+ save(getFilename(source, blob), blob, blob.type || 'application/octet-stream');
96
+ }
97
+
98
+ function handleLoad(): void {
99
+ isLoaded = true;
100
+ hasError = false;
101
+ }
102
+
103
+ function handleError(): void {
104
+ hasError = true;
105
+ isLoaded = false;
106
+ }
107
+
108
+ $effect(() => {
109
+ const source = getImageSource();
110
+ if (!imageElement || !source) {
111
+ return;
112
+ }
113
+
114
+ if (!imageElement.complete) {
115
+ return;
116
+ }
117
+
118
+ if (imageElement.naturalWidth > 0) {
119
+ handleLoad();
120
+ return;
121
+ }
122
+
123
+ handleError();
124
+ });
125
+ </script>
126
+
127
+ {#if token.href !== 'streamdown:incomplete-image'}
128
+ {#if imageSource}
129
+ <Slot
130
+ props={{
131
+ src: imageSource,
132
+ alt: token.text,
133
+ class: streamdown.theme.image.image,
134
+ onload: handleLoad,
135
+ onerror: handleError,
136
+ children,
137
+ token
138
+ }}
139
+ render={streamdown.snippets.image}
140
+ >
141
+ <span
142
+ data-streamdown-image={id}
143
+ style={streamdown.isMounted ? streamdown.animationBlockStyle : ''}
144
+ class={streamdown.theme.image.base}
145
+ >
146
+ {#if hasError}
147
+ <span data-streamdown-image-fallback={id}>
148
+ {streamdown.translations.imageNotAvailable}
149
+ </span>
150
+ {:else}
151
+ <Slot
152
+ props={{
153
+ src: imageSource,
154
+ alt: token.text,
155
+ class: streamdown.theme.image.image,
156
+ onload: handleLoad,
157
+ onerror: handleError,
158
+ children,
159
+ token
160
+ }}
161
+ component={streamdown.components?.img}
162
+ >
163
+ <img
164
+ bind:this={imageElement}
165
+ class={streamdown.theme.image.image}
166
+ src={imageSource}
167
+ alt={token.text}
168
+ onload={handleLoad}
169
+ onerror={handleError}
170
+ />
171
+ </Slot>
172
+ {/if}
173
+ <div
174
+ aria-hidden="true"
175
+ class="pointer-events-none absolute inset-0 hidden rounded-lg bg-black/10 group-hover:block"
176
+ ></div>
177
+ {#if isLoaded && !hasError}
178
+ <button
179
+ class="absolute right-2 bottom-2 flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border border-border bg-background/90 text-muted-foreground opacity-0 shadow-sm backdrop-blur-sm transition-all duration-200 hover:bg-background hover:text-foreground group-hover:opacity-100"
180
+ type="button"
181
+ title={streamdown.translations.downloadImage}
182
+ aria-label={streamdown.translations.downloadImage}
183
+ onclick={downloadImage}
184
+ >
185
+ {@render resolveIcon(streamdown.icons, 'download', downloadIcon)()}
186
+ </button>
187
+ {/if}
188
+ </span>
189
+ </Slot>
190
+ {:else}
191
+ <p>
192
+ <span
193
+ data-streamdown-image-blocked={id}
194
+ class="inline-block rounded bg-gray-200 px-3 py-1 text-sm text-gray-600 dark:bg-gray-700 dark:text-gray-400"
195
+ >
196
+ [Image blocked: {token.text || 'No description'}]
197
+ </span>
198
+ </p>
199
+ {/if}
200
+ {/if}
@@ -0,0 +1,10 @@
1
+ import type { Tokens } from 'marked';
2
+ import type { Snippet } from 'svelte';
3
+ type $$ComponentProps = {
4
+ children: Snippet;
5
+ token: Tokens.Image;
6
+ id: string;
7
+ };
8
+ declare const Image: import("svelte").Component<$$ComponentProps, {}, "">;
9
+ type Image = ReturnType<typeof Image>;
10
+ export default Image;
@@ -0,0 +1,220 @@
1
+ <script lang="ts">
2
+ import { useStreamdown, type LinkSafetyModalProps } from '../context.svelte.js';
3
+ import { applyMarkdownUrlTransform, createMarkdownElement } from '../markdown.js';
4
+ import { isPathRelativeUrl, transformUrl } from '../utils/url.js';
5
+ import Slot from './Slot.svelte';
6
+ import LinkSafetyModal from './LinkSafetyModal.svelte';
7
+ import type { Tokens } from 'marked';
8
+ import type { Snippet } from 'svelte';
9
+
10
+ const streamdown = useStreamdown();
11
+
12
+ const {
13
+ children,
14
+ token,
15
+ id
16
+ }: {
17
+ children: Snippet;
18
+ token: Tokens.Link;
19
+ id: string;
20
+ } = $props();
21
+
22
+ const resolvedLink = $derived.by(() => {
23
+ if (token.href === 'streamdown:incomplete-link') {
24
+ return {
25
+ href: undefined,
26
+ rel: undefined,
27
+ state: 'blocked' as const,
28
+ target: undefined,
29
+ isIncomplete: true,
30
+ isRelative: false
31
+ };
32
+ }
33
+
34
+ const transformedHref = applyMarkdownUrlTransform(
35
+ token.href,
36
+ 'href',
37
+ createMarkdownElement('a', {
38
+ href: token.href,
39
+ title: token.title ?? undefined
40
+ }),
41
+ streamdown.urlTransform
42
+ );
43
+
44
+ if (transformedHref == null) {
45
+ return {
46
+ href: undefined,
47
+ rel: undefined,
48
+ state: 'literal' as const,
49
+ target: undefined,
50
+ isIncomplete: false,
51
+ isRelative: false
52
+ };
53
+ }
54
+
55
+ if (transformedHref === '') {
56
+ return {
57
+ href: '',
58
+ rel: undefined,
59
+ state: 'anchor' as const,
60
+ target: undefined,
61
+ isIncomplete: false,
62
+ isRelative: false
63
+ };
64
+ }
65
+
66
+ if (isPathRelativeUrl(transformedHref)) {
67
+ return {
68
+ href: transformedHref,
69
+ rel: undefined,
70
+ state: 'anchor' as const,
71
+ target: undefined,
72
+ isIncomplete: false,
73
+ isRelative: true
74
+ };
75
+ }
76
+
77
+ const safeHref = transformUrl(
78
+ transformedHref,
79
+ streamdown.allowedLinkPrefixes ?? [],
80
+ streamdown.defaultOrigin,
81
+ {
82
+ kind: 'link'
83
+ }
84
+ );
85
+
86
+ if (safeHref) {
87
+ return {
88
+ href: safeHref,
89
+ rel: 'noopener noreferrer',
90
+ state: 'anchor' as const,
91
+ target: '_blank',
92
+ isIncomplete: false,
93
+ isRelative: false
94
+ };
95
+ }
96
+
97
+ return {
98
+ href: undefined,
99
+ rel: undefined,
100
+ state: 'blocked' as const,
101
+ target: undefined,
102
+ isIncomplete: false,
103
+ isRelative: false
104
+ };
105
+ });
106
+
107
+ const shouldIntercept = $derived(
108
+ Boolean(
109
+ streamdown.linkSafety?.enabled &&
110
+ resolvedLink.state === 'anchor' &&
111
+ resolvedLink.href &&
112
+ !resolvedLink.isRelative &&
113
+ !resolvedLink.isIncomplete
114
+ )
115
+ );
116
+ const splitMailtoLabel = $derived.by(() => {
117
+ if (!token.href.startsWith('mailto:')) {
118
+ return null;
119
+ }
120
+
121
+ const text = typeof token.text === 'string' ? token.text : '';
122
+ if (!text.startsWith('mailto:')) {
123
+ return null;
124
+ }
125
+
126
+ return {
127
+ prefix: 'mailto:',
128
+ label: text.slice('mailto:'.length)
129
+ };
130
+ });
131
+ const customModal = $derived(
132
+ streamdown.linkSafety?.renderModal as Snippet<[LinkSafetyModalProps]> | undefined
133
+ );
134
+ let isModalOpen = $state(false);
135
+
136
+ const openHref = () => {
137
+ if (typeof window === 'undefined' || !resolvedLink.href || resolvedLink.isIncomplete) {
138
+ return;
139
+ }
140
+
141
+ window.open(resolvedLink.href, '_blank', 'noreferrer');
142
+ };
143
+
144
+ const handleInterceptedClick = async (event: MouseEvent) => {
145
+ if (!shouldIntercept || resolvedLink.isIncomplete || !resolvedLink.href) {
146
+ return;
147
+ }
148
+
149
+ event.preventDefault();
150
+
151
+ try {
152
+ if (streamdown.linkSafety?.onLinkCheck) {
153
+ const isAllowed = await streamdown.linkSafety.onLinkCheck(resolvedLink.href);
154
+ if (isAllowed) {
155
+ openHref();
156
+ return;
157
+ }
158
+ }
159
+ } catch {
160
+ // Fall through to the confirmation modal when the checker fails closed.
161
+ }
162
+
163
+ isModalOpen = true;
164
+ };
165
+
166
+ const modalProps = $derived({
167
+ url: resolvedLink.href ?? '',
168
+ isOpen: isModalOpen,
169
+ onClose: () => {
170
+ isModalOpen = false;
171
+ },
172
+ onConfirm: openHref
173
+ } satisfies LinkSafetyModalProps);
174
+ </script>
175
+
176
+ {#if resolvedLink.state === 'anchor'}
177
+ {#if shouldIntercept}
178
+ {#if splitMailtoLabel}{splitMailtoLabel.prefix}{/if}
179
+ <button
180
+ type="button"
181
+ data-streamdown="link"
182
+ data-streamdown-link={id}
183
+ data-incomplete={resolvedLink.isIncomplete ? 'true' : undefined}
184
+ class={`${streamdown.theme.link.base} appearance-none border-none bg-transparent p-0 text-left`}
185
+ onclick={(event) => void handleInterceptedClick(event)}
186
+ >{#if splitMailtoLabel}{splitMailtoLabel.label}{:else}{@render children()}{/if}</button>{#if customModal}{@render customModal(modalProps)}{:else}<LinkSafetyModal {...modalProps} />{/if}
187
+ {:else}
188
+ <Slot
189
+ props={{
190
+ href: resolvedLink.href,
191
+ target: resolvedLink.target,
192
+ rel: resolvedLink.rel,
193
+ title: token.title,
194
+ class: streamdown.theme.link.base,
195
+ children,
196
+ token
197
+ }}
198
+ render={streamdown.snippets.link}
199
+ component={streamdown.components?.a}
200
+ >
201
+ <a
202
+ data-streamdown="link"
203
+ data-streamdown-link={id}
204
+ data-incomplete={resolvedLink.isIncomplete ? 'true' : undefined}
205
+ class={streamdown.theme.link.base}
206
+ href={resolvedLink.href}
207
+ target={resolvedLink.target}
208
+ rel={resolvedLink.rel}
209
+ >{#if splitMailtoLabel}{splitMailtoLabel.prefix}{splitMailtoLabel.label}{:else}{@render children()}{/if}</a>
210
+ </Slot>
211
+ {/if}
212
+ {:else if resolvedLink.state === 'literal'}
213
+ {'['}{@render children()}{']'}
214
+ {:else}
215
+ <span
216
+ data-streamdown-link-blocked={id}
217
+ class={streamdown.theme.link.blocked}
218
+ title={`Blocked URL: ${resolvedLink.href}`}
219
+ >{@render children()} [blocked]</span>
220
+ {/if}
@@ -0,0 +1,10 @@
1
+ import type { Tokens } from 'marked';
2
+ import type { Snippet } from 'svelte';
3
+ type $$ComponentProps = {
4
+ children: Snippet;
5
+ token: Tokens.Link;
6
+ id: string;
7
+ };
8
+ declare const Link: import("svelte").Component<$$ComponentProps, {}, "">;
9
+ type Link = ReturnType<typeof Link>;
10
+ export default Link;
@@ -0,0 +1,121 @@
1
+ <script lang="ts">
2
+ import { useStreamdown, type LinkSafetyModalProps } from '../context.svelte.js';
3
+ import { useCopy } from '../utils/copy.svelte.js';
4
+ import { lockBodyScroll } from '../utils/scroll-lock.js';
5
+ import { checkIcon, copyIcon, resolveIcon } from './icons.js';
6
+
7
+ let { url, isOpen, onClose, onConfirm }: LinkSafetyModalProps = $props();
8
+
9
+ const streamdown = useStreamdown();
10
+ const copy = useCopy({
11
+ get content() {
12
+ return url;
13
+ }
14
+ });
15
+
16
+ const handleCopy = async () => {
17
+ await copy.copy();
18
+ };
19
+
20
+ const handleConfirm = () => {
21
+ onConfirm();
22
+ onClose();
23
+ };
24
+
25
+ $effect(() => {
26
+ if (!isOpen || typeof document === 'undefined') {
27
+ return;
28
+ }
29
+
30
+ const releaseBodyScroll = lockBodyScroll(document);
31
+
32
+ const handleEscape = (event: KeyboardEvent) => {
33
+ if (event.key === 'Escape') {
34
+ onClose();
35
+ }
36
+ };
37
+
38
+ document.addEventListener('keydown', handleEscape);
39
+
40
+ return () => {
41
+ document.removeEventListener('keydown', handleEscape);
42
+ releaseBodyScroll();
43
+ };
44
+ });
45
+ </script>
46
+
47
+ {#if isOpen}
48
+ <div
49
+ data-streamdown="link-safety-modal"
50
+ class="fixed inset-0 z-50 flex items-center justify-center bg-black/45 px-4 backdrop-blur-sm"
51
+ role="button"
52
+ tabindex="0"
53
+ aria-label={streamdown.translations.close}
54
+ onclick={onClose}
55
+ onkeydown={(event) => {
56
+ if (event.key === 'Escape') {
57
+ onClose();
58
+ }
59
+ }}
60
+ >
61
+ <div
62
+ role="presentation"
63
+ class="relative flex w-full max-w-md flex-col gap-4 rounded-xl border border-gray-200 bg-white p-6 shadow-xl"
64
+ onclick={(event) => event.stopPropagation()}
65
+ onkeydown={(event) => event.stopPropagation()}
66
+ >
67
+ <button
68
+ type="button"
69
+ class="absolute top-4 right-4 rounded-md px-2 py-1 text-sm text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900"
70
+ title={streamdown.translations.close}
71
+ aria-label={streamdown.translations.close}
72
+ onclick={onClose}
73
+ >
74
+ {streamdown.translations.close}
75
+ </button>
76
+
77
+ <div class="flex flex-col gap-2 pr-12">
78
+ <h2 class="text-lg font-semibold text-gray-900">
79
+ {streamdown.translations.openExternalLink}
80
+ </h2>
81
+ <p class="text-sm text-gray-600">{streamdown.translations.externalLinkWarning}</p>
82
+ </div>
83
+
84
+ <div
85
+ class={`rounded-md border border-gray-200 bg-gray-50 p-3 font-mono text-sm break-all text-gray-700 ${
86
+ url.length > 100 ? 'max-h-32 overflow-y-auto' : ''
87
+ }`}
88
+ >
89
+ {url}
90
+ </div>
91
+
92
+ <div class="flex gap-2">
93
+ <button
94
+ type="button"
95
+ class="flex flex-1 items-center justify-center gap-2 rounded-md border border-gray-200 bg-white px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50"
96
+ onclick={() => void handleCopy()}
97
+ >
98
+ <span class="h-4 w-4">
99
+ {#if copy.isCopied}
100
+ {@render resolveIcon(streamdown.icons, 'check', checkIcon)()}
101
+ {:else}
102
+ {@render resolveIcon(streamdown.icons, 'copy', copyIcon)()}
103
+ {/if}
104
+ </span>
105
+ <span
106
+ >{copy.isCopied
107
+ ? streamdown.translations.copied
108
+ : streamdown.translations.copyLink}</span
109
+ >
110
+ </button>
111
+ <button
112
+ type="button"
113
+ class="flex flex-1 items-center justify-center rounded-md bg-gray-900 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-black"
114
+ onclick={handleConfirm}
115
+ >
116
+ {streamdown.translations.openLink}
117
+ </button>
118
+ </div>
119
+ </div>
120
+ </div>
121
+ {/if}
@@ -0,0 +1,4 @@
1
+ import { type LinkSafetyModalProps } from '../context.svelte.js';
2
+ declare const LinkSafetyModal: import("svelte").Component<LinkSafetyModalProps, {}, "">;
3
+ type LinkSafetyModal = ReturnType<typeof LinkSafetyModal>;
4
+ export default LinkSafetyModal;
@@ -0,0 +1,100 @@
1
+ <script lang="ts">
2
+ import { BROWSER } from 'esm-env';
3
+ import { onMount, untrack } from 'svelte';
4
+ import { useStreamdown } from '../context.svelte.js';
5
+ import type { MathToken } from '../marked/index.js';
6
+ import { getMathPluginOptions } from '../plugins.js';
7
+ import { isTestMode } from '../utils/runtime-env.js';
8
+ import type { KatexOptions } from 'katex';
9
+ import 'katex/dist/katex.min.css';
10
+
11
+ type KatexRenderer = Pick<typeof import('katex'), 'renderToString'>;
12
+
13
+ const {
14
+ token,
15
+ id
16
+ }: {
17
+ token: MathToken;
18
+ id: string;
19
+ } = $props();
20
+
21
+ const streamdown = useStreamdown();
22
+ const mathPluginOptions = $derived(getMathPluginOptions(streamdown.plugins?.math));
23
+ let katexInstance = $state<KatexRenderer | null>(null);
24
+ const loadKatex = async (): Promise<KatexRenderer | null> => {
25
+ if (!BROWSER) {
26
+ return null;
27
+ }
28
+
29
+ return await import('katex');
30
+ };
31
+ const escapeHtml = (value: string): string =>
32
+ value
33
+ .replaceAll('&', '&amp;')
34
+ .replaceAll('<', '&lt;')
35
+ .replaceAll('>', '&gt;')
36
+ .replaceAll('"', '&quot;')
37
+ .replaceAll("'", '&#39;');
38
+
39
+ onMount(() => {
40
+ void loadKatex().then((instance) => {
41
+ if (instance) {
42
+ katexInstance = instance;
43
+ }
44
+ });
45
+ });
46
+
47
+ let inner = $state<HTMLElement | null>(null);
48
+ const html = $derived.by(() => {
49
+ const code = token.text;
50
+ if (!katexInstance) {
51
+ return '';
52
+ }
53
+ const config: KatexOptions = {
54
+ output: 'htmlAndMathml',
55
+ displayMode: !token.isInline,
56
+ throwOnError: false,
57
+ errorColor: mathPluginOptions.errorColor,
58
+ ...(typeof streamdown.katexConfig === 'function'
59
+ ? streamdown.katexConfig(token.isInline)
60
+ : streamdown.katexConfig || {})
61
+ };
62
+
63
+ if (config.strict === undefined && isTestMode()) {
64
+ config.strict = 'ignore';
65
+ }
66
+
67
+ try {
68
+ return katexInstance.renderToString(code, config);
69
+ } catch (error) {
70
+ const message = error instanceof Error ? error.message : 'KaTeX render failed';
71
+ return untrack(() => {
72
+ return `<span title="${escapeHtml(`ParseError: ${message}`)}">${inner?.innerHTML || escapeHtml(code)}</span>`;
73
+ });
74
+ }
75
+ });
76
+ </script>
77
+
78
+ {#if token.isInline}
79
+ <span
80
+ data-streamdown-inline-math={id}
81
+ style={streamdown.isMounted ? streamdown.animationBlockStyle : ''}
82
+ bind:this={inner}
83
+ class={streamdown.theme.math.inline}
84
+ >
85
+ {@html html}
86
+ </span>
87
+ {:else}
88
+ <div
89
+ data-streamdown-block-math={id}
90
+ style={streamdown.isMounted ? streamdown.animationBlockStyle : ''}
91
+ style:height="fit-content"
92
+ style:width="100%"
93
+ >
94
+ <div class="overflow-x-auto">
95
+ <div bind:this={inner} class={streamdown.theme.math.block}>
96
+ {@html html}
97
+ </div>
98
+ </div>
99
+ </div>
100
+ {/if}
@@ -0,0 +1,9 @@
1
+ import type { MathToken } from '../marked/index.js';
2
+ import 'katex/dist/katex.min.css';
3
+ type $$ComponentProps = {
4
+ token: MathToken;
5
+ id: string;
6
+ };
7
+ declare const Math: import("svelte").Component<$$ComponentProps, {}, "">;
8
+ type Math = ReturnType<typeof Math>;
9
+ export default Math;