@svadmin/ai-elements 0.7.4 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/README.md +20 -4
  2. package/THIRD_PARTY_NOTICES.md +67 -6
  3. package/dist/ai.css +1 -5
  4. package/dist/ai.theme.css +1 -0
  5. package/dist/class-properties.generated.d.ts +1 -0
  6. package/dist/class-properties.generated.js +2 -0
  7. package/dist/classnames.d.ts +8 -0
  8. package/dist/classnames.js +26 -0
  9. package/dist/components/Response.svelte +2 -2
  10. package/dist/components/Response.svelte.d.ts +1 -1
  11. package/dist/components/code/index.d.ts +9 -18
  12. package/dist/components/code/index.js +8 -11
  13. package/dist/components/code-block/highlight.js +1 -1
  14. package/dist/utilities.css +3172 -0
  15. package/dist/utils.d.ts +1 -1
  16. package/dist/utils.js +1 -1
  17. package/package.json +36 -11
  18. package/vendor/streamdown/AnimatedText.svelte +93 -0
  19. package/vendor/streamdown/AnimatedText.svelte.d.ts +6 -0
  20. package/vendor/streamdown/Block.svelte +96 -0
  21. package/vendor/streamdown/Block.svelte.d.ts +11 -0
  22. package/vendor/streamdown/Elements/Alert.svelte +69 -0
  23. package/vendor/streamdown/Elements/Alert.svelte.d.ts +10 -0
  24. package/vendor/streamdown/Elements/Citation.svelte +260 -0
  25. package/vendor/streamdown/Elements/Citation.svelte.d.ts +7 -0
  26. package/vendor/streamdown/Elements/Code.svelte +226 -0
  27. package/vendor/streamdown/Elements/Code.svelte.d.ts +9 -0
  28. package/vendor/streamdown/Elements/Element.svelte +574 -0
  29. package/vendor/streamdown/Elements/Element.svelte.d.ts +10 -0
  30. package/vendor/streamdown/Elements/FootnoteRef.svelte +30 -0
  31. package/vendor/streamdown/Elements/FootnoteRef.svelte.d.ts +7 -0
  32. package/vendor/streamdown/Elements/Footnotes.svelte +54 -0
  33. package/vendor/streamdown/Elements/Footnotes.svelte.d.ts +7 -0
  34. package/vendor/streamdown/Elements/Image.svelte +200 -0
  35. package/vendor/streamdown/Elements/Image.svelte.d.ts +10 -0
  36. package/vendor/streamdown/Elements/Link.svelte +220 -0
  37. package/vendor/streamdown/Elements/Link.svelte.d.ts +10 -0
  38. package/vendor/streamdown/Elements/LinkSafetyModal.svelte +121 -0
  39. package/vendor/streamdown/Elements/LinkSafetyModal.svelte.d.ts +4 -0
  40. package/vendor/streamdown/Elements/Math.svelte +100 -0
  41. package/vendor/streamdown/Elements/Math.svelte.d.ts +9 -0
  42. package/vendor/streamdown/Elements/Mermaid.svelte +455 -0
  43. package/vendor/streamdown/Elements/Mermaid.svelte.d.ts +9 -0
  44. package/vendor/streamdown/Elements/MermaidDownload.svelte +145 -0
  45. package/vendor/streamdown/Elements/MermaidDownload.svelte.d.ts +8 -0
  46. package/vendor/streamdown/Elements/Slot.svelte +23 -0
  47. package/vendor/streamdown/Elements/Slot.svelte.d.ts +10 -0
  48. package/vendor/streamdown/Elements/Table.svelte +195 -0
  49. package/vendor/streamdown/Elements/Table.svelte.d.ts +9 -0
  50. package/vendor/streamdown/Elements/TableDownload.svelte +221 -0
  51. package/vendor/streamdown/Elements/TableDownload.svelte.d.ts +8 -0
  52. package/vendor/streamdown/Elements/fallbacks/CodeFallback.svelte +41 -0
  53. package/vendor/streamdown/Elements/fallbacks/CodeFallback.svelte.d.ts +9 -0
  54. package/vendor/streamdown/Elements/fallbacks/MathFallback.svelte +35 -0
  55. package/vendor/streamdown/Elements/fallbacks/MathFallback.svelte.d.ts +8 -0
  56. package/vendor/streamdown/Elements/fallbacks/MermaidFallback.svelte +36 -0
  57. package/vendor/streamdown/Elements/fallbacks/MermaidFallback.svelte.d.ts +9 -0
  58. package/vendor/streamdown/Elements/fallbacks/index.d.ts +3 -0
  59. package/vendor/streamdown/Elements/fallbacks/index.js +3 -0
  60. package/vendor/streamdown/Elements/icons.d.ts +31 -0
  61. package/vendor/streamdown/Elements/icons.js +200 -0
  62. package/vendor/streamdown/Elements/index.d.ts +8 -0
  63. package/vendor/streamdown/Elements/index.js +8 -0
  64. package/vendor/streamdown/Elements/popover.svelte.d.ts +8 -0
  65. package/vendor/streamdown/Elements/popover.svelte.js +45 -0
  66. package/vendor/streamdown/Elements/stepperState.svelte.d.ts +36 -0
  67. package/vendor/streamdown/Elements/stepperState.svelte.js +92 -0
  68. package/vendor/streamdown/IconProvider.svelte +11 -0
  69. package/vendor/streamdown/IconProvider.svelte.d.ts +30 -0
  70. package/vendor/streamdown/LICENSE +202 -0
  71. package/vendor/streamdown/PluginProvider.svelte +11 -0
  72. package/vendor/streamdown/PluginProvider.svelte.d.ts +30 -0
  73. package/vendor/streamdown/README.svadmin.md +5 -0
  74. package/vendor/streamdown/Streamdown.svelte +447 -0
  75. package/vendor/streamdown/Streamdown.svelte.d.ts +25 -0
  76. package/vendor/streamdown/block/BlockTokens.svelte +45 -0
  77. package/vendor/streamdown/block/BlockTokens.svelte.d.ts +9 -0
  78. package/vendor/streamdown/block/html.d.ts +14 -0
  79. package/vendor/streamdown/block/html.js +27 -0
  80. package/vendor/streamdown/block/text.d.ts +10 -0
  81. package/vendor/streamdown/block/text.js +31 -0
  82. package/vendor/streamdown/context-key.d.ts +1 -0
  83. package/vendor/streamdown/context-key.js +1 -0
  84. package/vendor/streamdown/context.svelte.d.ts +24 -0
  85. package/vendor/streamdown/context.svelte.js +75 -0
  86. package/vendor/streamdown/contracts/plugins.d.ts +26 -0
  87. package/vendor/streamdown/contracts/plugins.js +1 -0
  88. package/vendor/streamdown/contracts/streamdown.d.ts +374 -0
  89. package/vendor/streamdown/contracts/streamdown.js +29 -0
  90. package/vendor/streamdown/detect-direction.d.ts +1 -0
  91. package/vendor/streamdown/detect-direction.js +1 -0
  92. package/vendor/streamdown/icon-context.d.ts +36 -0
  93. package/vendor/streamdown/icon-context.js +52 -0
  94. package/vendor/streamdown/incomplete-code.d.ts +6 -0
  95. package/vendor/streamdown/incomplete-code.js +23 -0
  96. package/vendor/streamdown/index.d.ts +22 -0
  97. package/vendor/streamdown/index.js +20 -0
  98. package/vendor/streamdown/markdown-parse-cache.d.ts +37 -0
  99. package/vendor/streamdown/markdown-parse-cache.js +109 -0
  100. package/vendor/streamdown/markdown.d.ts +21 -0
  101. package/vendor/streamdown/markdown.js +214 -0
  102. package/vendor/streamdown/marked/index.d.ts +44 -0
  103. package/vendor/streamdown/marked/index.js +228 -0
  104. package/vendor/streamdown/marked/marked-alert.d.ts +13 -0
  105. package/vendor/streamdown/marked/marked-alert.js +47 -0
  106. package/vendor/streamdown/marked/marked-align.d.ts +10 -0
  107. package/vendor/streamdown/marked/marked-align.js +45 -0
  108. package/vendor/streamdown/marked/marked-br.d.ts +6 -0
  109. package/vendor/streamdown/marked/marked-br.js +15 -0
  110. package/vendor/streamdown/marked/marked-citations.d.ts +8 -0
  111. package/vendor/streamdown/marked/marked-citations.js +53 -0
  112. package/vendor/streamdown/marked/marked-cjk.d.ts +2 -0
  113. package/vendor/streamdown/marked/marked-cjk.js +165 -0
  114. package/vendor/streamdown/marked/marked-dl.d.ts +23 -0
  115. package/vendor/streamdown/marked/marked-dl.js +44 -0
  116. package/vendor/streamdown/marked/marked-footnotes.d.ts +26 -0
  117. package/vendor/streamdown/marked/marked-footnotes.js +101 -0
  118. package/vendor/streamdown/marked/marked-hr.d.ts +6 -0
  119. package/vendor/streamdown/marked/marked-hr.js +18 -0
  120. package/vendor/streamdown/marked/marked-list.d.ts +31 -0
  121. package/vendor/streamdown/marked/marked-list.js +330 -0
  122. package/vendor/streamdown/marked/marked-math.d.ts +13 -0
  123. package/vendor/streamdown/marked/marked-math.js +129 -0
  124. package/vendor/streamdown/marked/marked-mdx.d.ts +12 -0
  125. package/vendor/streamdown/marked/marked-mdx.js +124 -0
  126. package/vendor/streamdown/marked/marked-subsup.d.ts +22 -0
  127. package/vendor/streamdown/marked/marked-subsup.js +40 -0
  128. package/vendor/streamdown/marked/marked-table.d.ts +80 -0
  129. package/vendor/streamdown/marked/marked-table.js +527 -0
  130. package/vendor/streamdown/plugin-context.d.ts +19 -0
  131. package/vendor/streamdown/plugin-context.js +40 -0
  132. package/vendor/streamdown/plugins/cjk-shared.d.ts +1 -0
  133. package/vendor/streamdown/plugins/cjk-shared.js +1 -0
  134. package/vendor/streamdown/plugins.d.ts +19 -0
  135. package/vendor/streamdown/plugins.js +107 -0
  136. package/vendor/streamdown/provenance.json +229 -0
  137. package/vendor/streamdown/remend.d.ts +2 -0
  138. package/vendor/streamdown/remend.js +1 -0
  139. package/vendor/streamdown/security/html.d.ts +19 -0
  140. package/vendor/streamdown/security/html.js +329 -0
  141. package/vendor/streamdown/security/preprocess-custom-tags.d.ts +1 -0
  142. package/vendor/streamdown/security/preprocess-custom-tags.js +20 -0
  143. package/vendor/streamdown/security/preprocess-literal-tag-content.d.ts +1 -0
  144. package/vendor/streamdown/security/preprocess-literal-tag-content.js +16 -0
  145. package/vendor/streamdown/security/types.d.ts +1 -0
  146. package/vendor/streamdown/security/types.js +1 -0
  147. package/vendor/streamdown/site/SiteHeader.svelte +94 -0
  148. package/vendor/streamdown/site/SiteHeader.svelte.d.ts +6 -0
  149. package/vendor/streamdown/site/home/HomeDemo.svelte +122 -0
  150. package/vendor/streamdown/site/home/HomeDemo.svelte.d.ts +3 -0
  151. package/vendor/streamdown/site/home/HomePage.svelte +293 -0
  152. package/vendor/streamdown/site/home/HomePage.svelte.d.ts +3 -0
  153. package/vendor/streamdown/site/home/content.d.ts +69 -0
  154. package/vendor/streamdown/site/home/content.js +144 -0
  155. package/vendor/streamdown/site/metadata.d.ts +4 -0
  156. package/vendor/streamdown/site/metadata.js +4 -0
  157. package/vendor/streamdown/site/navigation.d.ts +6 -0
  158. package/vendor/streamdown/site/navigation.js +22 -0
  159. package/vendor/streamdown/streamdown/config.d.ts +41 -0
  160. package/vendor/streamdown/streamdown/config.js +125 -0
  161. package/vendor/streamdown/streamdown/context.d.ts +12 -0
  162. package/vendor/streamdown/streamdown/context.js +2 -0
  163. package/vendor/streamdown/streamdown/incomplete-markdown.d.ts +5 -0
  164. package/vendor/streamdown/streamdown/incomplete-markdown.js +79 -0
  165. package/vendor/streamdown/streamdown/pipeline.d.ts +95 -0
  166. package/vendor/streamdown/streamdown/pipeline.js +138 -0
  167. package/vendor/streamdown/streamdown/runtime.d.ts +59 -0
  168. package/vendor/streamdown/streamdown/runtime.js +112 -0
  169. package/vendor/streamdown/streaming.d.ts +5 -0
  170. package/vendor/streamdown/streaming.js +5 -0
  171. package/vendor/streamdown/theme.d.ts +486 -0
  172. package/vendor/streamdown/theme.js +370 -0
  173. package/vendor/streamdown/translations.d.ts +43 -0
  174. package/vendor/streamdown/translations.js +54 -0
  175. package/vendor/streamdown/url-policy.d.ts +1 -0
  176. package/vendor/streamdown/url-policy.js +1 -0
  177. package/vendor/streamdown/utils/bind.d.ts +8 -0
  178. package/vendor/streamdown/utils/bind.js +26 -0
  179. package/vendor/streamdown/utils/bundledLanguages.d.ts +1 -0
  180. package/vendor/streamdown/utils/bundledLanguages.js +1 -0
  181. package/vendor/streamdown/utils/code-block.d.ts +8 -0
  182. package/vendor/streamdown/utils/code-block.js +38 -0
  183. package/vendor/streamdown/utils/copy.svelte.d.ts +7 -0
  184. package/vendor/streamdown/utils/copy.svelte.js +38 -0
  185. package/vendor/streamdown/utils/darkMode.svelte.d.ts +3 -0
  186. package/vendor/streamdown/utils/darkMode.svelte.js +49 -0
  187. package/vendor/streamdown/utils/detectDirection.d.ts +1 -0
  188. package/vendor/streamdown/utils/detectDirection.js +19 -0
  189. package/vendor/streamdown/utils/get.d.ts +1 -0
  190. package/vendor/streamdown/utils/get.js +25 -0
  191. package/vendor/streamdown/utils/hightlighter.svelte.d.ts +30 -0
  192. package/vendor/streamdown/utils/hightlighter.svelte.js +524 -0
  193. package/vendor/streamdown/utils/index.d.ts +3 -0
  194. package/vendor/streamdown/utils/index.js +3 -0
  195. package/vendor/streamdown/utils/mermaid.d.ts +13 -0
  196. package/vendor/streamdown/utils/mermaid.js +49 -0
  197. package/vendor/streamdown/utils/panzoom.svelte.d.ts +35 -0
  198. package/vendor/streamdown/utils/panzoom.svelte.js +556 -0
  199. package/vendor/streamdown/utils/parse-incomplete-markdown.d.ts +2 -0
  200. package/vendor/streamdown/utils/parse-incomplete-markdown.js +2 -0
  201. package/vendor/streamdown/utils/runtime-env.d.ts +1 -0
  202. package/vendor/streamdown/utils/runtime-env.js +13 -0
  203. package/vendor/streamdown/utils/save.d.ts +1 -0
  204. package/vendor/streamdown/utils/save.js +14 -0
  205. package/vendor/streamdown/utils/scroll-lock.d.ts +2 -0
  206. package/vendor/streamdown/utils/scroll-lock.js +35 -0
  207. package/vendor/streamdown/utils/table.d.ts +8 -0
  208. package/vendor/streamdown/utils/table.js +176 -0
  209. package/vendor/streamdown/utils/url.d.ts +22 -0
  210. package/vendor/streamdown/utils/url.js +98 -0
  211. package/vendor/streamdown/utils/useClickOutside.svelte.d.ts +8 -0
  212. package/vendor/streamdown/utils/useClickOutside.svelte.js +41 -0
  213. package/vendor/streamdown/utils/useKeyDown.svelte.d.ts +5 -0
  214. package/vendor/streamdown/utils/useKeyDown.svelte.js +23 -0
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { cn } from 'cn';
1
+ export { cn } from './classnames.js';
2
2
  export type SnippetLike = import('svelte').Snippet;
3
3
  export declare function stopPropagation(event: Event): void;
4
4
  export declare function isPromiseLike(value: unknown): value is PromiseLike<unknown>;
package/dist/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- export { cn } from 'cn';
1
+ export { cn } from './classnames.js';
2
2
  const RESOURCE_PROTOCOLS = new Set(['http:', 'https:', 'blob:']);
3
3
  export function stopPropagation(event) {
4
4
  event.stopPropagation();
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@svadmin/ai-elements",
3
- "version": "0.7.4",
3
+ "version": "0.8.0",
4
4
  "description": "Composable Svelte 5 AI interaction components for SVAdmin",
5
5
  "type": "module",
6
6
  "sideEffects": [
7
- "./dist/ai.css"
7
+ "./dist/*.css",
8
+ "./vendor/**/*.css"
8
9
  ],
9
10
  "files": [
10
11
  "dist",
@@ -13,7 +14,8 @@
13
14
  "!dist/**/*.test.*",
14
15
  "!dist/**/*.test-*",
15
16
  "!dist/**/*.spec.*",
16
- "!dist/**/*.spec-*"
17
+ "!dist/**/*.spec-*",
18
+ "vendor"
17
19
  ],
18
20
  "main": "dist/index.js",
19
21
  "types": "dist/index.d.ts",
@@ -47,10 +49,14 @@
47
49
  "./parity": {
48
50
  "types": "./dist/parity-manifest.d.ts",
49
51
  "default": "./dist/parity-manifest.js"
52
+ },
53
+ "./ai.theme.css": {
54
+ "style": "./dist/ai.theme.css",
55
+ "default": "./dist/ai.theme.css"
50
56
  }
51
57
  },
52
58
  "peerDependencies": {
53
- "@svadmin/core": "^0.52.0",
59
+ "@svadmin/core": "^0.53.0",
54
60
  "@tanstack/svelte-query": "^6.1.48",
55
61
  "svelte": "^5.56.10"
56
62
  },
@@ -64,11 +70,29 @@
64
70
  "@rive-app/webgl2": "^2.41.0",
65
71
  "@sinclair/typebox": "^0.34.52",
66
72
  "@xyflow/svelte": "^1.6.5",
67
- "cn": "^0.2.4",
68
- "streamdown-svelte": "^3.0.6",
69
- "tailwind-merge": "^3.6.0",
70
- "tailwind-variants": "^3.3.1",
71
- "type-fest": "^4.41.0"
73
+ "type-fest": "^4.41.0",
74
+ "clsx": "^2.1.1",
75
+ "@floating-ui/dom": "^1.7.4",
76
+ "@shikijs/langs": "^3.17.1",
77
+ "@shikijs/themes": "^3.17.1",
78
+ "esm-env": "^1.2.2",
79
+ "katex": "^0.16.22",
80
+ "marked": "^16.2.1",
81
+ "mermaid": "^11.11.0",
82
+ "rehype-harden": "^1.1.8",
83
+ "rehype-raw": "^7.0.0",
84
+ "rehype-sanitize": "^6.0.0",
85
+ "rehype-stringify": "^10.0.1",
86
+ "remark-cjk-friendly": "^2.0.1",
87
+ "remark-cjk-friendly-gfm-strikethrough": "^2.0.1",
88
+ "remark-gfm": "^4.0.1",
89
+ "remark-parse": "^11.0.0",
90
+ "remark-rehype": "^11.1.2",
91
+ "shiki": "^3.13.0",
92
+ "unified": "^11.0.5",
93
+ "unist-util-visit": "^5.1.0",
94
+ "@streamdown-svelte/plugin-core": "1.0.0",
95
+ "@streamdown-svelte/remend": "1.3.0"
72
96
  },
73
97
  "devDependencies": {
74
98
  "@happy-dom/global-registrator": "^20.11.12",
@@ -81,10 +105,11 @@
81
105
  "vitest": "^4.1.11"
82
106
  },
83
107
  "scripts": {
84
- "build": "node ../../node_modules/@sveltejs/package/svelte-package.js -i src -o dist && bun scripts/clean-dist.ts",
108
+ "build": "node ../../scripts/build-migrated-ui.mjs ai-elements && node ../../scripts/build-native-classnames.mjs ai-elements && node ../../node_modules/@sveltejs/package/svelte-package.js -i src -o dist && bun scripts/clean-dist.ts",
85
109
  "check": "svelte-check --tsgo-experimental-api --tsconfig ./tsconfig.json --threshold error",
86
110
  "test": "vitest run --config ./vitest.config.ts && bun test scripts/clean-dist.test.ts scripts/audit-upstream-parity.test.ts",
87
- "audit:upstream": "bun scripts/audit-upstream-parity.ts"
111
+ "audit:upstream": "bun scripts/audit-upstream-parity.ts",
112
+ "styles:migrated:check": "node ../../scripts/build-migrated-ui.mjs ai-elements --check"
88
113
  },
89
114
  "license": "MIT",
90
115
  "publishConfig": {
@@ -0,0 +1,93 @@
1
+ <script lang="ts">
2
+ import { useStreamdown } from './context.svelte.js';
3
+ let { text }: { text: string } = $props();
4
+
5
+ const streamdown = useStreamdown();
6
+ const whitespaceOnlyPattern = /^\s+$/;
7
+ let previousRenderedLength = $state(0);
8
+ let committedText = $state('');
9
+
10
+ const tokenizeNewContent = (text: string) => {
11
+ if (!text) return [];
12
+
13
+ let splitRegex;
14
+ if (streamdown.animation.tokenize === 'word') {
15
+ splitRegex = /(\s+)/;
16
+ } else {
17
+ splitRegex = /(.)/;
18
+ }
19
+
20
+ return text.split(splitRegex).filter((token) => token.length > 0);
21
+ };
22
+
23
+ const tokens = $derived.by(() => {
24
+ let cursor = 0;
25
+ let newAnimatedTokenIndex = 0;
26
+ const stagger = streamdown.animation.stagger ?? 0;
27
+
28
+ return tokenizeNewContent(text).map((token) => {
29
+ const start = cursor;
30
+ cursor += token.length;
31
+
32
+ if (whitespaceOnlyPattern.test(token)) {
33
+ return {
34
+ content: token,
35
+ animated: false,
36
+ style: undefined
37
+ };
38
+ }
39
+
40
+ const isAlreadyRendered = previousRenderedLength > 0 && start < previousRenderedLength;
41
+ const duration = isAlreadyRendered ? 0 : streamdown.animation.duration;
42
+ const delay = !isAlreadyRendered && stagger > 0 ? newAnimatedTokenIndex * stagger : 0;
43
+
44
+ if (!isAlreadyRendered) {
45
+ newAnimatedTokenIndex += 1;
46
+ }
47
+
48
+ return {
49
+ content: token,
50
+ animated: true,
51
+ style: `--sd-animation:sd-${streamdown.animation.type};
52
+ --sd-duration:${duration}ms;
53
+ --sd-easing:${streamdown.animation.timingFunction};
54
+ ${delay > 0 ? `--sd-delay:${delay}ms;\n` : ''}animation-name: var(--sd-animation);
55
+ animation-duration: var(--sd-duration);
56
+ animation-timing-function: var(--sd-easing);
57
+ animation-delay: var(--sd-delay, 0ms);
58
+ animation-iteration-count: 1;
59
+ animation-fill-mode: forwards;
60
+ white-space: pre-wrap;
61
+ display: inline-block;
62
+ text-decoration: inherit;`
63
+ };
64
+ });
65
+ });
66
+
67
+ $effect(() => {
68
+ if (!(streamdown.animation.enabled && streamdown.isAnimating)) {
69
+ previousRenderedLength = 0;
70
+ committedText = '';
71
+ return;
72
+ }
73
+
74
+ if (text !== committedText) {
75
+ previousRenderedLength = committedText.length;
76
+ committedText = text;
77
+ }
78
+ });
79
+ </script>
80
+
81
+ {#if streamdown.animation.enabled}
82
+ {#each tokens as token}
83
+ {#if token.animated}
84
+ <span data-streamdown-animate="" style={token.style}>
85
+ {token.content}
86
+ </span>
87
+ {:else}
88
+ {token.content}
89
+ {/if}
90
+ {/each}
91
+ {:else}
92
+ {text}
93
+ {/if}
@@ -0,0 +1,6 @@
1
+ type $$ComponentProps = {
2
+ text: string;
3
+ };
4
+ declare const AnimatedText: import("svelte").Component<$$ComponentProps, {}, "">;
5
+ type AnimatedText = ReturnType<typeof AnimatedText>;
6
+ export default AnimatedText;
@@ -0,0 +1,96 @@
1
+ <script lang="ts">
2
+ import { setContext } from 'svelte';
3
+ import BlockTokens from './block/BlockTokens.svelte';
4
+ import { renderBlockHtml } from './block/html.js';
5
+ import { useStreamdown } from './context.svelte.js';
6
+ import { filterMarkdownTokens } from './markdown.js';
7
+ import { lex, type StreamdownToken } from './marked/index.js';
8
+ import { applyPluginMarkdownTransforms } from './plugins.js';
9
+ import { repairIncompleteMarkdown } from './streamdown/incomplete-markdown.js';
10
+ import { detectTextDirection } from './utils/detectDirection.js';
11
+ import { hasIncompleteCodeFence, STREAMDOWN_BLOCK_CONTEXT } from './incomplete-code.js';
12
+
13
+ let {
14
+ block,
15
+ static: isStatic = false,
16
+ tokens: providedTokens,
17
+ parseIncompleteMarkdown: shouldParseIncompleteMarkdown = true,
18
+ isIncomplete = false
19
+ }: {
20
+ block: string;
21
+ static?: boolean;
22
+ tokens?: StreamdownToken[];
23
+ parseIncompleteMarkdown?: boolean;
24
+ isIncomplete?: boolean;
25
+ } = $props();
26
+
27
+ const streamdown = useStreamdown();
28
+ const repairedBlock = $derived.by(() => {
29
+ if (providedTokens) {
30
+ return block;
31
+ }
32
+
33
+ if (isStatic || !shouldParseIncompleteMarkdown || streamdown.parseIncompleteMarkdown === false) {
34
+ return block;
35
+ }
36
+
37
+ return repairIncompleteMarkdown(block, streamdown.remend);
38
+ });
39
+ const markdown = $derived(applyPluginMarkdownTransforms(repairedBlock, streamdown.plugins));
40
+ const isIncompleteCodeFence = $derived(
41
+ streamdown.isAnimating && !isStatic && hasIncompleteCodeFence(block)
42
+ );
43
+ const tokens = $derived(
44
+ filterMarkdownTokens(providedTokens ?? lex(markdown, streamdown.extensions), {
45
+ allowedElements: streamdown.allowedElements,
46
+ allowElement: streamdown.allowElement,
47
+ disallowedElements: streamdown.disallowedElements,
48
+ skipHtml: streamdown.skipHtml,
49
+ unwrapDisallowed: streamdown.unwrapDisallowed
50
+ })
51
+ );
52
+ const securityHtmlBlock = $derived.by(() => {
53
+ return renderBlockHtml(markdown, {
54
+ allowedImagePrefixes: streamdown.allowedImagePrefixes,
55
+ allowedLinkPrefixes: streamdown.allowedLinkPrefixes,
56
+ allowedTags: streamdown.allowedTags,
57
+ defaultOrigin: streamdown.defaultOrigin,
58
+ renderHtml: streamdown.renderHtml,
59
+ skipHtml: streamdown.skipHtml,
60
+ urlTransform: streamdown.urlTransform
61
+ });
62
+ });
63
+
64
+ const dir = $derived.by(() => {
65
+ if (!streamdown.dir) {
66
+ return undefined;
67
+ }
68
+
69
+ if (streamdown.dir === 'auto') {
70
+ return detectTextDirection(markdown);
71
+ }
72
+
73
+ return streamdown.dir;
74
+ });
75
+
76
+ setContext(STREAMDOWN_BLOCK_CONTEXT, {
77
+ get isIncompleteCodeFence() {
78
+ return isIncompleteCodeFence;
79
+ },
80
+ get rawBlock() {
81
+ return block;
82
+ }
83
+ });
84
+ </script>
85
+
86
+ {#if securityHtmlBlock !== null}
87
+ {@html securityHtmlBlock}
88
+ {:else}
89
+ {#if dir}
90
+ <div data-streamdown-dir={dir} {dir} style="display: contents;">
91
+ <BlockTokens {tokens} {isIncomplete} {isStatic} />
92
+ </div>
93
+ {:else}
94
+ <BlockTokens {tokens} {isIncomplete} {isStatic} />
95
+ {/if}
96
+ {/if}
@@ -0,0 +1,11 @@
1
+ import { type StreamdownToken } from './marked/index.js';
2
+ type $$ComponentProps = {
3
+ block: string;
4
+ static?: boolean;
5
+ tokens?: StreamdownToken[];
6
+ parseIncompleteMarkdown?: boolean;
7
+ isIncomplete?: boolean;
8
+ };
9
+ declare const Block: import("svelte").Component<$$ComponentProps, {}, "">;
10
+ type Block = ReturnType<typeof Block>;
11
+ export default Block;
@@ -0,0 +1,69 @@
1
+ <script lang="ts">
2
+ const icons = {
3
+ note: `<circle cx="12" cy="12" r="10" /><path d="M12 16v-4" /><path d="M12 8h.01" />`,
4
+ caution: `<circle cx="12" cy="12" r="10"/><line x1="12" x2="12" y1="8" y2="12"/><line x1="12" x2="12.01" y1="16" y2="16"/>`,
5
+ important: `<path
6
+ d="M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z"
7
+ /><path d="M7 11h10" /><path d="M7 15h6" /><path d="M7 7h8" />`,
8
+ tip: `<path
9
+ d="M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5"
10
+ /><path d="M9 18h6" /><path d="M10 22h4" />`,
11
+ warning: `<path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3" /><path
12
+ d="M12 9v4"
13
+ /><path d="M12 17h.01" />`
14
+ };
15
+
16
+ import { useStreamdown } from '../context.svelte.js';
17
+ import { resolveIcon } from './icons.js';
18
+ import Slot from './Slot.svelte';
19
+ import type { AlertToken } from '../marked/index.js';
20
+ import type { Snippet } from 'svelte';
21
+
22
+ const streamdown = useStreamdown();
23
+
24
+ const {
25
+ children,
26
+ token,
27
+ id
28
+ }: {
29
+ id: string;
30
+ children: Snippet;
31
+ token: AlertToken;
32
+ } = $props();
33
+ </script>
34
+
35
+ <Slot
36
+ props={{
37
+ children,
38
+ token
39
+ }}
40
+ render={streamdown.snippets.alert}
41
+ >
42
+ <div
43
+ data-streamdown-alert={id}
44
+ style={streamdown.isMounted ? streamdown.animationBlockStyle : ''}
45
+ class={`${streamdown.theme.alert.base} ${streamdown.theme.alert[token.variant]}`}
46
+ >
47
+ <div data-alert-title class={streamdown.theme.alert.title}>
48
+ {@render resolveIcon(streamdown.icons, token.variant, icon)()}
49
+ {streamdown.translations?.alert?.[token.variant] || token.variant}
50
+ </div>
51
+ {@render children()}
52
+ </div>
53
+ </Slot>
54
+
55
+ {#snippet icon()}
56
+ <svg
57
+ xmlns="http://www.w3.org/2000/svg"
58
+ width="24"
59
+ height="24"
60
+ viewBox="0 0 24 24"
61
+ fill="none"
62
+ stroke-width="2"
63
+ stroke-linecap="round"
64
+ stroke-linejoin="round"
65
+ class={streamdown.theme.alert.icon}
66
+ >
67
+ {@html icons[token.variant]}
68
+ </svg>
69
+ {/snippet}
@@ -0,0 +1,10 @@
1
+ import type { AlertToken } from '../marked/index.js';
2
+ import type { Snippet } from 'svelte';
3
+ type $$ComponentProps = {
4
+ id: string;
5
+ children: Snippet;
6
+ token: AlertToken;
7
+ };
8
+ declare const Alert: import("svelte").Component<$$ComponentProps, {}, "">;
9
+ type Alert = ReturnType<typeof Alert>;
10
+ export default Alert;
@@ -0,0 +1,260 @@
1
+ <script lang="ts">
2
+ import { useStreamdown } from '../context.svelte.js';
3
+ import Slot from './Slot.svelte';
4
+ import { useClickOutside } from '../utils/useClickOutside.svelte.js';
5
+ import { scale } from 'svelte/transition';
6
+ import Block from '../Block.svelte';
7
+ import { useKeyDown } from '../utils/useKeyDown.svelte.js';
8
+ import type { CitationToken } from '../marked/marked-citations.js';
9
+ import { StepperState } from './stepperState.svelte.js';
10
+ import { Popover } from './popover.svelte.js';
11
+ import { get } from '../utils/get.js';
12
+ import { chevronLeft, chevronRight, resolveIcon } from './icons.js';
13
+
14
+ const {
15
+ token
16
+ }: {
17
+ token: CitationToken;
18
+ } = $props();
19
+ const streamdown = useStreamdown();
20
+ const id = $props.id();
21
+ const popover = new Popover();
22
+
23
+ const citationWithSources = $derived.by(() => {
24
+ return token.keys.reduce((acc, key) => {
25
+ const source = get<Record<string, any>>(streamdown.sources, key);
26
+ const safeUrl = (url: string | null) => {
27
+ if (url == null) return null;
28
+ try {
29
+ return new URL(url);
30
+ } catch (error) {
31
+ return null;
32
+ }
33
+ };
34
+ if (source) {
35
+ const url = safeUrl(source.url ?? source.href ?? source.link ?? source.source);
36
+ acc.push({
37
+ key,
38
+ title: source.title ?? source.name ?? source.author ?? null,
39
+ url,
40
+ host: url ? url.host.replace('www.', '') : null,
41
+ favicon: url ? `https://www.google.com/s2/favicons?domain=${url.hostname}&sz=128` : null,
42
+ content: source.content ?? source.text ?? source.summary ?? source.excerpt ?? null,
43
+ source
44
+ });
45
+ }
46
+ return acc;
47
+ }, [] as CitationWithSource[]);
48
+ });
49
+ useKeyDown({
50
+ keys: ['Escape'],
51
+ get isActive() {
52
+ return popover.isOpen;
53
+ },
54
+ callback: () => {
55
+ popover.isOpen = false;
56
+ }
57
+ });
58
+ const clickOutside = useClickOutside({
59
+ get isActive() {
60
+ return popover.isOpen;
61
+ },
62
+ callback: () => {
63
+ popover.isOpen = false;
64
+ }
65
+ });
66
+
67
+ const stepper = new StepperState({
68
+ get items() {
69
+ return citationWithSources;
70
+ },
71
+ keyFramesOptions: { duration: 200, easing: 'ease-in-out', fill: 'forwards' }
72
+ });
73
+
74
+ type CitationWithSource = Record<string, any> & {
75
+ key: string;
76
+ title: string | null;
77
+ url: URL | null;
78
+ favicon: string | null;
79
+ content: string | null;
80
+ source: Record<string, any>;
81
+ };
82
+ </script>
83
+
84
+ {#if popover.isOpen}
85
+ <dialog
86
+ data-streamdown-citation-popover={id}
87
+ id={'citation-popover-' + id}
88
+ aria-modal="false"
89
+ transition:scale|global={{ start: 0.95, duration: 200 }}
90
+ {@attach clickOutside.attachment}
91
+ {@attach popover.popoverAttachment}
92
+ open
93
+ class={`${streamdown.theme.components.popover}`}
94
+ style:max-width="400px"
95
+ >
96
+ <Slot
97
+ props={{
98
+ token,
99
+ isOpen: popover.isOpen
100
+ }}
101
+ render={streamdown.snippets.inlineCitationPopover}
102
+ >
103
+ {#if streamdown.inlineCitationsMode === 'carousel'}
104
+ {@render carouselView()}
105
+ {:else}
106
+ {@render listView()}
107
+ {/if}
108
+ </Slot>
109
+ </dialog>
110
+ {/if}
111
+
112
+ {#snippet listView()}
113
+ <div class={streamdown.theme.inlineCitation.list.base}>
114
+ {#each citationWithSources as { favicon, key, source, title, url }}
115
+ <Slot render={streamdown.snippets.inlineCitationContent} props={{ source, key, token }}>
116
+ <a
117
+ class={streamdown.theme.inlineCitation.list.item}
118
+ href={url?.toString()}
119
+ target="_blank"
120
+ rel="noopener noreferrer"
121
+ >
122
+ {#if title}
123
+ <span class={streamdown.theme.inlineCitation.list.title}>{title}</span>
124
+ {/if}
125
+ {#if url}
126
+ <span class={streamdown.theme.inlineCitation.list.url}>
127
+ {#if favicon}
128
+ <img
129
+ src={favicon}
130
+ alt={title || url.host}
131
+ class={streamdown.theme.inlineCitation.list.favicon}
132
+ />
133
+ {/if}
134
+ {url.host}{url.pathname === '/' ? '' : url.pathname}
135
+ </span>
136
+ {/if}
137
+ </a>
138
+ </Slot>
139
+ {/each}
140
+ </div>
141
+ {/snippet}
142
+
143
+ {#snippet carouselView()}
144
+ {#if citationWithSources.length > 1}
145
+ <div class={streamdown.theme.inlineCitation.carousel.header}>
146
+ <div class={streamdown.theme.inlineCitation.carousel.stepCounter}>
147
+ {stepper.activeStep + 1}
148
+ / {citationWithSources.length}
149
+ </div>
150
+ <div class={streamdown.theme.inlineCitation.carousel.buttons}>
151
+ <button
152
+ disabled={!stepper.canGoPrevious}
153
+ class={streamdown.theme.components.button}
154
+ onclick={() => stepper.previous()}
155
+ >
156
+ {@render resolveIcon(streamdown.icons, 'chevronLeft', chevronLeft)()}
157
+ </button>
158
+ <button
159
+ disabled={!stepper.canGoNext}
160
+ class={streamdown.theme.components.button}
161
+ onclick={() => stepper.next()}
162
+ >
163
+ {@render resolveIcon(streamdown.icons, 'chevronRight', chevronRight)()}
164
+ </button>
165
+ </div>
166
+ </div>
167
+ {/if}
168
+ <div
169
+ use:stepper.scroller
170
+ style:height={Number.isFinite(stepper.stepHeights[stepper.activeStep])
171
+ ? `${stepper.stepHeights[stepper.activeStep]}px`
172
+ : 'auto'}
173
+ style:overflow="hidden"
174
+ style:position="relative"
175
+ style:transition-duration="200ms"
176
+ style:transition-timing-function="ease-in-out"
177
+ aria-label="Citations-${id}"
178
+ >
179
+ <div
180
+ bind:this={stepper.stepContainer}
181
+ style:display="grid"
182
+ style:transition-duration={`${200}ms`}
183
+ style:width="100%"
184
+ style:grid-template-columns="repeat({citationWithSources.length}, 100%)"
185
+ >
186
+ {#each citationWithSources as { favicon, key, source, title, url, content }, index}
187
+ <div
188
+ bind:offsetHeight={stepper.stepHeights[index]}
189
+ data-step={index}
190
+ tabindex={stepper.activeStep === index ? 0 : -1}
191
+ inert={stepper.activeStep !== index}
192
+ role="tabpanel"
193
+ style:height="fit-content"
194
+ style:width="100%"
195
+ style:flex-grow="1"
196
+ aria-label="Citation-${id}"
197
+ >
198
+ <Slot render={streamdown.snippets.inlineCitationContent} props={{ source, key, token }}>
199
+ {#if url || title}
200
+ <div class="mb-4">
201
+ {#if title}
202
+ <div class={streamdown.theme.inlineCitation.carousel.title}>
203
+ {title}
204
+ </div>
205
+ {/if}
206
+ {#if url}
207
+ <a
208
+ href={url.toString()}
209
+ target="_blank"
210
+ rel="noopener noreferrer"
211
+ class={streamdown.theme.inlineCitation.carousel.url}
212
+ >
213
+ {#if favicon}
214
+ <img
215
+ src={favicon}
216
+ alt={title || url.host}
217
+ class={streamdown.theme.inlineCitation.carousel.favicon}
218
+ />
219
+ {/if}
220
+ <!-- Skip search params -->
221
+ {url.host}{url.pathname === '/' ? '' : url.pathname}
222
+ </a>
223
+ {/if}
224
+ </div>
225
+ {/if}
226
+ {#if content}
227
+ <Block block={content} />
228
+ {/if}
229
+ </Slot>
230
+ </div>
231
+ {/each}
232
+ </div>
233
+ </div>
234
+ {/snippet}
235
+
236
+ {#if citationWithSources.length > 0}
237
+ <button
238
+ data-streamdown-citation-preview={id}
239
+ style={streamdown.animationBlockStyle}
240
+ bind:this={popover.reference}
241
+ class={streamdown.theme.inlineCitation.preview}
242
+ onclick={() => (popover.isOpen = !popover.isOpen)}
243
+ aria-expanded={popover.isOpen}
244
+ aria-haspopup="dialog"
245
+ aria-controls={'citation-popover-' + id}
246
+ {@attach clickOutside.attachment}
247
+ >
248
+ <Slot
249
+ render={streamdown.snippets.inlineCitationPreview}
250
+ props={{
251
+ token
252
+ }}
253
+ >
254
+ {citationWithSources[0]?.url?.host ??
255
+ citationWithSources[0]?.title ??
256
+ citationWithSources[0]?.key}
257
+ {citationWithSources.length > 1 ? ` +${citationWithSources.length - 1}` : ''}
258
+ </Slot>
259
+ </button>
260
+ {/if}
@@ -0,0 +1,7 @@
1
+ import type { CitationToken } from '../marked/marked-citations.js';
2
+ type $$ComponentProps = {
3
+ token: CitationToken;
4
+ };
5
+ declare const Citation: import("svelte").Component<$$ComponentProps, {}, "">;
6
+ type Citation = ReturnType<typeof Citation>;
7
+ export default Citation;