@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.
Files changed (218) hide show
  1. package/README.md +31 -4
  2. package/THIRD_PARTY_NOTICES.md +67 -6
  3. package/dist/ai-workspace-contract.d.ts +14 -0
  4. package/dist/ai-workspace-contract.js +14 -0
  5. package/dist/ai.css +2 -5
  6. package/dist/ai.theme.css +1 -0
  7. package/dist/class-properties.generated.d.ts +1 -0
  8. package/dist/class-properties.generated.js +2 -0
  9. package/dist/classnames.d.ts +8 -0
  10. package/dist/classnames.js +26 -0
  11. package/dist/components/Response.svelte +2 -2
  12. package/dist/components/Response.svelte.d.ts +1 -1
  13. package/dist/components/code/index.d.ts +9 -18
  14. package/dist/components/code/index.js +8 -11
  15. package/dist/components/code-block/highlight.js +1 -1
  16. package/dist/index.d.ts +2 -0
  17. package/dist/index.js +1 -0
  18. package/dist/utilities.css +3172 -0
  19. package/dist/utils.d.ts +1 -1
  20. package/dist/utils.js +1 -1
  21. package/package.json +36 -11
  22. package/vendor/streamdown/AnimatedText.svelte +93 -0
  23. package/vendor/streamdown/AnimatedText.svelte.d.ts +6 -0
  24. package/vendor/streamdown/Block.svelte +96 -0
  25. package/vendor/streamdown/Block.svelte.d.ts +11 -0
  26. package/vendor/streamdown/Elements/Alert.svelte +69 -0
  27. package/vendor/streamdown/Elements/Alert.svelte.d.ts +10 -0
  28. package/vendor/streamdown/Elements/Citation.svelte +260 -0
  29. package/vendor/streamdown/Elements/Citation.svelte.d.ts +7 -0
  30. package/vendor/streamdown/Elements/Code.svelte +226 -0
  31. package/vendor/streamdown/Elements/Code.svelte.d.ts +9 -0
  32. package/vendor/streamdown/Elements/Element.svelte +574 -0
  33. package/vendor/streamdown/Elements/Element.svelte.d.ts +10 -0
  34. package/vendor/streamdown/Elements/FootnoteRef.svelte +30 -0
  35. package/vendor/streamdown/Elements/FootnoteRef.svelte.d.ts +7 -0
  36. package/vendor/streamdown/Elements/Footnotes.svelte +54 -0
  37. package/vendor/streamdown/Elements/Footnotes.svelte.d.ts +7 -0
  38. package/vendor/streamdown/Elements/Image.svelte +200 -0
  39. package/vendor/streamdown/Elements/Image.svelte.d.ts +10 -0
  40. package/vendor/streamdown/Elements/Link.svelte +220 -0
  41. package/vendor/streamdown/Elements/Link.svelte.d.ts +10 -0
  42. package/vendor/streamdown/Elements/LinkSafetyModal.svelte +121 -0
  43. package/vendor/streamdown/Elements/LinkSafetyModal.svelte.d.ts +4 -0
  44. package/vendor/streamdown/Elements/Math.svelte +100 -0
  45. package/vendor/streamdown/Elements/Math.svelte.d.ts +9 -0
  46. package/vendor/streamdown/Elements/Mermaid.svelte +455 -0
  47. package/vendor/streamdown/Elements/Mermaid.svelte.d.ts +9 -0
  48. package/vendor/streamdown/Elements/MermaidDownload.svelte +145 -0
  49. package/vendor/streamdown/Elements/MermaidDownload.svelte.d.ts +8 -0
  50. package/vendor/streamdown/Elements/Slot.svelte +23 -0
  51. package/vendor/streamdown/Elements/Slot.svelte.d.ts +10 -0
  52. package/vendor/streamdown/Elements/Table.svelte +195 -0
  53. package/vendor/streamdown/Elements/Table.svelte.d.ts +9 -0
  54. package/vendor/streamdown/Elements/TableDownload.svelte +221 -0
  55. package/vendor/streamdown/Elements/TableDownload.svelte.d.ts +8 -0
  56. package/vendor/streamdown/Elements/fallbacks/CodeFallback.svelte +41 -0
  57. package/vendor/streamdown/Elements/fallbacks/CodeFallback.svelte.d.ts +9 -0
  58. package/vendor/streamdown/Elements/fallbacks/MathFallback.svelte +35 -0
  59. package/vendor/streamdown/Elements/fallbacks/MathFallback.svelte.d.ts +8 -0
  60. package/vendor/streamdown/Elements/fallbacks/MermaidFallback.svelte +36 -0
  61. package/vendor/streamdown/Elements/fallbacks/MermaidFallback.svelte.d.ts +9 -0
  62. package/vendor/streamdown/Elements/fallbacks/index.d.ts +3 -0
  63. package/vendor/streamdown/Elements/fallbacks/index.js +3 -0
  64. package/vendor/streamdown/Elements/icons.d.ts +31 -0
  65. package/vendor/streamdown/Elements/icons.js +200 -0
  66. package/vendor/streamdown/Elements/index.d.ts +8 -0
  67. package/vendor/streamdown/Elements/index.js +8 -0
  68. package/vendor/streamdown/Elements/popover.svelte.d.ts +8 -0
  69. package/vendor/streamdown/Elements/popover.svelte.js +45 -0
  70. package/vendor/streamdown/Elements/stepperState.svelte.d.ts +36 -0
  71. package/vendor/streamdown/Elements/stepperState.svelte.js +92 -0
  72. package/vendor/streamdown/IconProvider.svelte +11 -0
  73. package/vendor/streamdown/IconProvider.svelte.d.ts +30 -0
  74. package/vendor/streamdown/LICENSE +202 -0
  75. package/vendor/streamdown/PluginProvider.svelte +11 -0
  76. package/vendor/streamdown/PluginProvider.svelte.d.ts +30 -0
  77. package/vendor/streamdown/README.svadmin.md +5 -0
  78. package/vendor/streamdown/Streamdown.svelte +447 -0
  79. package/vendor/streamdown/Streamdown.svelte.d.ts +25 -0
  80. package/vendor/streamdown/block/BlockTokens.svelte +45 -0
  81. package/vendor/streamdown/block/BlockTokens.svelte.d.ts +9 -0
  82. package/vendor/streamdown/block/html.d.ts +14 -0
  83. package/vendor/streamdown/block/html.js +27 -0
  84. package/vendor/streamdown/block/text.d.ts +10 -0
  85. package/vendor/streamdown/block/text.js +31 -0
  86. package/vendor/streamdown/context-key.d.ts +1 -0
  87. package/vendor/streamdown/context-key.js +1 -0
  88. package/vendor/streamdown/context.svelte.d.ts +24 -0
  89. package/vendor/streamdown/context.svelte.js +75 -0
  90. package/vendor/streamdown/contracts/plugins.d.ts +26 -0
  91. package/vendor/streamdown/contracts/plugins.js +1 -0
  92. package/vendor/streamdown/contracts/streamdown.d.ts +374 -0
  93. package/vendor/streamdown/contracts/streamdown.js +29 -0
  94. package/vendor/streamdown/detect-direction.d.ts +1 -0
  95. package/vendor/streamdown/detect-direction.js +1 -0
  96. package/vendor/streamdown/icon-context.d.ts +36 -0
  97. package/vendor/streamdown/icon-context.js +52 -0
  98. package/vendor/streamdown/incomplete-code.d.ts +6 -0
  99. package/vendor/streamdown/incomplete-code.js +23 -0
  100. package/vendor/streamdown/index.d.ts +22 -0
  101. package/vendor/streamdown/index.js +20 -0
  102. package/vendor/streamdown/markdown-parse-cache.d.ts +37 -0
  103. package/vendor/streamdown/markdown-parse-cache.js +109 -0
  104. package/vendor/streamdown/markdown.d.ts +21 -0
  105. package/vendor/streamdown/markdown.js +214 -0
  106. package/vendor/streamdown/marked/index.d.ts +44 -0
  107. package/vendor/streamdown/marked/index.js +228 -0
  108. package/vendor/streamdown/marked/marked-alert.d.ts +13 -0
  109. package/vendor/streamdown/marked/marked-alert.js +47 -0
  110. package/vendor/streamdown/marked/marked-align.d.ts +10 -0
  111. package/vendor/streamdown/marked/marked-align.js +45 -0
  112. package/vendor/streamdown/marked/marked-br.d.ts +6 -0
  113. package/vendor/streamdown/marked/marked-br.js +15 -0
  114. package/vendor/streamdown/marked/marked-citations.d.ts +8 -0
  115. package/vendor/streamdown/marked/marked-citations.js +53 -0
  116. package/vendor/streamdown/marked/marked-cjk.d.ts +2 -0
  117. package/vendor/streamdown/marked/marked-cjk.js +165 -0
  118. package/vendor/streamdown/marked/marked-dl.d.ts +23 -0
  119. package/vendor/streamdown/marked/marked-dl.js +44 -0
  120. package/vendor/streamdown/marked/marked-footnotes.d.ts +26 -0
  121. package/vendor/streamdown/marked/marked-footnotes.js +101 -0
  122. package/vendor/streamdown/marked/marked-hr.d.ts +6 -0
  123. package/vendor/streamdown/marked/marked-hr.js +18 -0
  124. package/vendor/streamdown/marked/marked-list.d.ts +31 -0
  125. package/vendor/streamdown/marked/marked-list.js +330 -0
  126. package/vendor/streamdown/marked/marked-math.d.ts +13 -0
  127. package/vendor/streamdown/marked/marked-math.js +129 -0
  128. package/vendor/streamdown/marked/marked-mdx.d.ts +12 -0
  129. package/vendor/streamdown/marked/marked-mdx.js +124 -0
  130. package/vendor/streamdown/marked/marked-subsup.d.ts +22 -0
  131. package/vendor/streamdown/marked/marked-subsup.js +40 -0
  132. package/vendor/streamdown/marked/marked-table.d.ts +80 -0
  133. package/vendor/streamdown/marked/marked-table.js +527 -0
  134. package/vendor/streamdown/plugin-context.d.ts +19 -0
  135. package/vendor/streamdown/plugin-context.js +40 -0
  136. package/vendor/streamdown/plugins/cjk-shared.d.ts +1 -0
  137. package/vendor/streamdown/plugins/cjk-shared.js +1 -0
  138. package/vendor/streamdown/plugins.d.ts +19 -0
  139. package/vendor/streamdown/plugins.js +107 -0
  140. package/vendor/streamdown/provenance.json +229 -0
  141. package/vendor/streamdown/remend.d.ts +2 -0
  142. package/vendor/streamdown/remend.js +1 -0
  143. package/vendor/streamdown/security/html.d.ts +19 -0
  144. package/vendor/streamdown/security/html.js +329 -0
  145. package/vendor/streamdown/security/preprocess-custom-tags.d.ts +1 -0
  146. package/vendor/streamdown/security/preprocess-custom-tags.js +20 -0
  147. package/vendor/streamdown/security/preprocess-literal-tag-content.d.ts +1 -0
  148. package/vendor/streamdown/security/preprocess-literal-tag-content.js +16 -0
  149. package/vendor/streamdown/security/types.d.ts +1 -0
  150. package/vendor/streamdown/security/types.js +1 -0
  151. package/vendor/streamdown/site/SiteHeader.svelte +94 -0
  152. package/vendor/streamdown/site/SiteHeader.svelte.d.ts +6 -0
  153. package/vendor/streamdown/site/home/HomeDemo.svelte +122 -0
  154. package/vendor/streamdown/site/home/HomeDemo.svelte.d.ts +3 -0
  155. package/vendor/streamdown/site/home/HomePage.svelte +293 -0
  156. package/vendor/streamdown/site/home/HomePage.svelte.d.ts +3 -0
  157. package/vendor/streamdown/site/home/content.d.ts +69 -0
  158. package/vendor/streamdown/site/home/content.js +144 -0
  159. package/vendor/streamdown/site/metadata.d.ts +4 -0
  160. package/vendor/streamdown/site/metadata.js +4 -0
  161. package/vendor/streamdown/site/navigation.d.ts +6 -0
  162. package/vendor/streamdown/site/navigation.js +22 -0
  163. package/vendor/streamdown/streamdown/config.d.ts +41 -0
  164. package/vendor/streamdown/streamdown/config.js +125 -0
  165. package/vendor/streamdown/streamdown/context.d.ts +12 -0
  166. package/vendor/streamdown/streamdown/context.js +2 -0
  167. package/vendor/streamdown/streamdown/incomplete-markdown.d.ts +5 -0
  168. package/vendor/streamdown/streamdown/incomplete-markdown.js +79 -0
  169. package/vendor/streamdown/streamdown/pipeline.d.ts +95 -0
  170. package/vendor/streamdown/streamdown/pipeline.js +138 -0
  171. package/vendor/streamdown/streamdown/runtime.d.ts +59 -0
  172. package/vendor/streamdown/streamdown/runtime.js +112 -0
  173. package/vendor/streamdown/streaming.d.ts +5 -0
  174. package/vendor/streamdown/streaming.js +5 -0
  175. package/vendor/streamdown/theme.d.ts +486 -0
  176. package/vendor/streamdown/theme.js +370 -0
  177. package/vendor/streamdown/translations.d.ts +43 -0
  178. package/vendor/streamdown/translations.js +54 -0
  179. package/vendor/streamdown/url-policy.d.ts +1 -0
  180. package/vendor/streamdown/url-policy.js +1 -0
  181. package/vendor/streamdown/utils/bind.d.ts +8 -0
  182. package/vendor/streamdown/utils/bind.js +26 -0
  183. package/vendor/streamdown/utils/bundledLanguages.d.ts +1 -0
  184. package/vendor/streamdown/utils/bundledLanguages.js +1 -0
  185. package/vendor/streamdown/utils/code-block.d.ts +8 -0
  186. package/vendor/streamdown/utils/code-block.js +38 -0
  187. package/vendor/streamdown/utils/copy.svelte.d.ts +7 -0
  188. package/vendor/streamdown/utils/copy.svelte.js +38 -0
  189. package/vendor/streamdown/utils/darkMode.svelte.d.ts +3 -0
  190. package/vendor/streamdown/utils/darkMode.svelte.js +49 -0
  191. package/vendor/streamdown/utils/detectDirection.d.ts +1 -0
  192. package/vendor/streamdown/utils/detectDirection.js +19 -0
  193. package/vendor/streamdown/utils/get.d.ts +1 -0
  194. package/vendor/streamdown/utils/get.js +25 -0
  195. package/vendor/streamdown/utils/hightlighter.svelte.d.ts +30 -0
  196. package/vendor/streamdown/utils/hightlighter.svelte.js +524 -0
  197. package/vendor/streamdown/utils/index.d.ts +3 -0
  198. package/vendor/streamdown/utils/index.js +3 -0
  199. package/vendor/streamdown/utils/mermaid.d.ts +13 -0
  200. package/vendor/streamdown/utils/mermaid.js +49 -0
  201. package/vendor/streamdown/utils/panzoom.svelte.d.ts +35 -0
  202. package/vendor/streamdown/utils/panzoom.svelte.js +556 -0
  203. package/vendor/streamdown/utils/parse-incomplete-markdown.d.ts +2 -0
  204. package/vendor/streamdown/utils/parse-incomplete-markdown.js +2 -0
  205. package/vendor/streamdown/utils/runtime-env.d.ts +1 -0
  206. package/vendor/streamdown/utils/runtime-env.js +13 -0
  207. package/vendor/streamdown/utils/save.d.ts +1 -0
  208. package/vendor/streamdown/utils/save.js +14 -0
  209. package/vendor/streamdown/utils/scroll-lock.d.ts +2 -0
  210. package/vendor/streamdown/utils/scroll-lock.js +35 -0
  211. package/vendor/streamdown/utils/table.d.ts +8 -0
  212. package/vendor/streamdown/utils/table.js +176 -0
  213. package/vendor/streamdown/utils/url.d.ts +22 -0
  214. package/vendor/streamdown/utils/url.js +98 -0
  215. package/vendor/streamdown/utils/useClickOutside.svelte.d.ts +8 -0
  216. package/vendor/streamdown/utils/useClickOutside.svelte.js +41 -0
  217. package/vendor/streamdown/utils/useKeyDown.svelte.d.ts +5 -0
  218. package/vendor/streamdown/utils/useKeyDown.svelte.js +23 -0
@@ -0,0 +1,19 @@
1
+ const RTL_PATTERN = /[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFF]/;
2
+ const LETTER_PATTERN = /\p{L}/u;
3
+ export function detectTextDirection(text) {
4
+ const stripped = text
5
+ .replace(/^#{1,6}\s+/gm, '')
6
+ .replace(/(\*{1,3}|_{1,3})/g, '')
7
+ .replace(/`[^`]*`/g, '')
8
+ .replace(/\[([^\]]*)\]\([^)]*\)/g, '$1')
9
+ .replace(/^[\s>*\-+\d.]+/gm, '');
10
+ for (const char of stripped) {
11
+ if (RTL_PATTERN.test(char)) {
12
+ return 'rtl';
13
+ }
14
+ if (LETTER_PATTERN.test(char)) {
15
+ return 'ltr';
16
+ }
17
+ }
18
+ return 'ltr';
19
+ }
@@ -0,0 +1 @@
1
+ export declare const get: <T>(obj: Record<string, any> | undefined, path: string) => T | null;
@@ -0,0 +1,25 @@
1
+ // A method that gets a value from an object using a path
2
+ // It should work with nested objects and arrays
3
+ export const get = (obj, path) => {
4
+ if (!obj)
5
+ return null;
6
+ const keys = path.split('.');
7
+ if (keys.length === 1) {
8
+ return obj[path];
9
+ }
10
+ let value = obj;
11
+ for (const key of keys) {
12
+ if (value == null)
13
+ return null;
14
+ if (Array.isArray(value)) {
15
+ const index = Number(key);
16
+ if (isNaN(index) || index < 0 || index >= value.length)
17
+ return null;
18
+ value = value[index];
19
+ }
20
+ else {
21
+ value = value[key];
22
+ }
23
+ }
24
+ return value;
25
+ };
@@ -0,0 +1,30 @@
1
+ import type { ThemedToken, ThemeRegistration } from 'shiki';
2
+ import type { HighlighterCore } from 'shiki/core';
3
+ import { SvelteMap } from 'svelte/reactivity';
4
+ import { type LanguageInfo } from './bundledLanguages.js';
5
+ export type Highlighter = HighlighterCore;
6
+ declare class HighlighterManager {
7
+ loadedLanguages: SvelteMap<string, boolean | Promise<void>>;
8
+ highlighter: any;
9
+ customLanguages: Set<string>;
10
+ languageLoaders: Map<string, () => Promise<any>>;
11
+ additionalThemes: Record<string, ThemeRegistration>;
12
+ constructor(languages: LanguageInfo[], additionalThemes?: Record<string, ThemeRegistration>, additionalLanguages?: LanguageInfo[]);
13
+ private loadHighlighter;
14
+ private isThemeAvailable;
15
+ private loadLanguage;
16
+ private isLanguageSupported;
17
+ isReady(theme: string, language: string | undefined): boolean;
18
+ /**
19
+ * Ensures the highlighter is ready for the given theme and language.
20
+ */
21
+ load(theme: string, language: string | undefined): Promise<void>;
22
+ /**
23
+ * Highlights code synchronously. Must call isReady() first.
24
+ * Returns plaintext tokens for unsupported languages.
25
+ */
26
+ highlightCode(code: string, language: string | undefined, theme: string): ThemedToken[][];
27
+ static create(languages?: LanguageInfo[], additionalThemes?: Record<string, ThemeRegistration>, additionalLanguages?: LanguageInfo[]): HighlighterManager;
28
+ }
29
+ export { HighlighterManager };
30
+ export declare const languageExtensionMap: Record<string, string>;
@@ -0,0 +1,524 @@
1
+ import { SvelteMap } from 'svelte/reactivity';
2
+ import { supportedLanguages, createLanguageSet, bundledLanguagesInfo } from './bundledLanguages.js';
3
+ import { createHighlighterCore } from 'shiki/core';
4
+ import { createJavaScriptRegexEngine } from 'shiki/engine/javascript';
5
+ // Import default themes directly
6
+ import githubDark from '@shikijs/themes/github-dark';
7
+ import githubLight from '@shikijs/themes/github-light';
8
+ // Default themes that are always loaded
9
+ const DEFAULT_THEMES = {
10
+ 'github-dark': githubDark,
11
+ 'github-light': githubLight
12
+ };
13
+ class HighlighterManager {
14
+ loadedLanguages = new SvelteMap();
15
+ highlighter = $state(null);
16
+ customLanguages;
17
+ languageLoaders;
18
+ additionalThemes;
19
+ constructor(languages, additionalThemes, additionalLanguages) {
20
+ // Store additional themes (will be loaded with highlighter)
21
+ this.additionalThemes = additionalThemes || {};
22
+ // Merge languages: default + additional
23
+ const allLanguages = additionalLanguages ? [...languages, ...additionalLanguages] : languages;
24
+ this.languageLoaders = new Map();
25
+ allLanguages.forEach((l) => {
26
+ this.languageLoaders.set(l.id, l.import);
27
+ if (l.aliases) {
28
+ l.aliases.forEach((alias) => this.languageLoaders.set(alias, l.import));
29
+ }
30
+ });
31
+ // Build custom languages set for validation
32
+ if (additionalLanguages) {
33
+ const additionalSet = createLanguageSet(additionalLanguages);
34
+ this.customLanguages = new Set([...supportedLanguages, ...additionalSet]);
35
+ }
36
+ else {
37
+ this.customLanguages = supportedLanguages;
38
+ }
39
+ if (typeof window !== 'undefined') {
40
+ Object.assign(window, {
41
+ STREAMDOWN_HIGHLIGHTER: this
42
+ });
43
+ }
44
+ }
45
+ async loadHighlighter() {
46
+ if (this.highlighter instanceof Promise) {
47
+ return this.highlighter;
48
+ }
49
+ else if (!this.highlighter) {
50
+ this.highlighter = new Promise(async (resolve, reject) => {
51
+ try {
52
+ const engine = createJavaScriptRegexEngine({ forgiving: true });
53
+ // Load default themes + any additional themes immediately
54
+ const allThemes = [
55
+ ...Object.values(DEFAULT_THEMES),
56
+ ...Object.values(this.additionalThemes)
57
+ ];
58
+ const highlighter = await createHighlighterCore({
59
+ themes: allThemes,
60
+ langs: [],
61
+ engine
62
+ });
63
+ this.highlighter = highlighter;
64
+ resolve(highlighter);
65
+ }
66
+ catch (error) {
67
+ reject(error);
68
+ }
69
+ });
70
+ return this.highlighter;
71
+ }
72
+ else {
73
+ return this.highlighter;
74
+ }
75
+ }
76
+ isThemeAvailable(theme) {
77
+ return theme in DEFAULT_THEMES || theme in this.additionalThemes;
78
+ }
79
+ async loadLanguage(language, highlighter) {
80
+ // Skip loading if language is not supported
81
+ if (!this.isLanguageSupported(language)) {
82
+ return;
83
+ }
84
+ const languageLoader = this.loadedLanguages.get(language);
85
+ if (languageLoader instanceof Promise) {
86
+ await languageLoader;
87
+ }
88
+ else if (!languageLoader) {
89
+ const loader = this.languageLoaders.get(language);
90
+ if (!loader) {
91
+ // Language not available, mark as failed
92
+ this.loadedLanguages.set(language, false);
93
+ return;
94
+ }
95
+ const languageLoaderPromise = loader()
96
+ .then((langModule) => {
97
+ const langObj = langModule.default || langModule;
98
+ return highlighter.loadLanguage(langObj);
99
+ })
100
+ .then(() => {
101
+ this.loadedLanguages.set(language, true);
102
+ })
103
+ .catch((err) => {
104
+ this.loadedLanguages.set(language, false);
105
+ throw err;
106
+ });
107
+ this.loadedLanguages.set(language, languageLoaderPromise);
108
+ await languageLoaderPromise;
109
+ }
110
+ }
111
+ isLanguageSupported = (language) => {
112
+ return this.customLanguages.has(language);
113
+ };
114
+ isReady(theme, language) {
115
+ // Check if theme is available
116
+ if (!this.isThemeAvailable(theme)) {
117
+ return false;
118
+ }
119
+ // For unsupported languages, we don't need to load anything (will use plaintext)
120
+ if (!language || !this.isLanguageSupported(language)) {
121
+ return !!this.highlighter && !(this.highlighter instanceof Promise);
122
+ }
123
+ return (!!this.highlighter &&
124
+ !(this.highlighter instanceof Promise) &&
125
+ this.loadedLanguages.get(language) === true);
126
+ }
127
+ /**
128
+ * Ensures the highlighter is ready for the given theme and language.
129
+ */
130
+ async load(theme, language) {
131
+ // For unsupported languages, only need to load highlighter (themes are pre-loaded)
132
+ if (!language || !this.isLanguageSupported(language)) {
133
+ if (this.highlighter !== null && !(this.highlighter instanceof Promise)) {
134
+ return;
135
+ }
136
+ await this.loadHighlighter();
137
+ return;
138
+ }
139
+ const languageLoader = this.loadedLanguages.get(language);
140
+ if (this.highlighter !== null &&
141
+ !(this.highlighter instanceof Promise) &&
142
+ languageLoader === true) {
143
+ return;
144
+ }
145
+ const highlighter = await this.loadHighlighter();
146
+ await this.loadLanguage(language, highlighter);
147
+ }
148
+ /**
149
+ * Highlights code synchronously. Must call isReady() first.
150
+ * Returns plaintext tokens for unsupported languages.
151
+ */
152
+ highlightCode(code, language, theme) {
153
+ try {
154
+ const highlighter = this.highlighter;
155
+ if (!highlighter || highlighter instanceof Promise) {
156
+ // Return plaintext tokens when highlighter is not ready
157
+ return code.split('\n').map((line) => [
158
+ {
159
+ content: line,
160
+ color: undefined,
161
+ bgColor: undefined
162
+ }
163
+ ]);
164
+ }
165
+ // For unsupported languages, return plaintext tokens
166
+ if (!language || !this.isLanguageSupported(language)) {
167
+ return code.split('\n').map((line) => [
168
+ {
169
+ content: line,
170
+ color: undefined,
171
+ bgColor: undefined
172
+ }
173
+ ]);
174
+ }
175
+ const tokens = highlighter.codeToTokensBase(code, {
176
+ lang: language,
177
+ theme
178
+ });
179
+ return tokens;
180
+ }
181
+ catch (error) {
182
+ // Return plaintext tokens on error
183
+ return code.split('\n').map((line) => [
184
+ {
185
+ content: line,
186
+ color: undefined,
187
+ bgColor: undefined
188
+ }
189
+ ]);
190
+ }
191
+ }
192
+ static create(languages = bundledLanguagesInfo, additionalThemes, additionalLanguages) {
193
+ if (typeof window !== 'undefined' && 'STREAMDOWN_HIGHLIGHTER' in window) {
194
+ const previousHighlighter = window.STREAMDOWN_HIGHLIGHTER;
195
+ // Merge additional themes
196
+ if (additionalThemes) {
197
+ Object.assign(previousHighlighter.additionalThemes, additionalThemes);
198
+ }
199
+ // Merge additional languages with existing set
200
+ if (additionalLanguages) {
201
+ additionalLanguages.forEach((lang) => {
202
+ previousHighlighter.languageLoaders.set(lang.id, lang.import);
203
+ if (lang.aliases) {
204
+ lang.aliases.forEach((alias) => previousHighlighter.languageLoaders.set(alias, lang.import));
205
+ }
206
+ });
207
+ const additionalSet = createLanguageSet(additionalLanguages);
208
+ additionalSet.forEach((lang) => previousHighlighter.customLanguages.add(lang));
209
+ }
210
+ return previousHighlighter;
211
+ }
212
+ return new HighlighterManager(languages, additionalThemes, additionalLanguages);
213
+ }
214
+ }
215
+ // Export the class for those who want to create their own instances
216
+ export { HighlighterManager };
217
+ export const languageExtensionMap = {
218
+ '1c': '1c',
219
+ '1c-query': '1cq',
220
+ abap: 'abap',
221
+ 'actionscript-3': 'as',
222
+ ada: 'ada',
223
+ adoc: 'adoc',
224
+ 'angular-html': 'html',
225
+ 'angular-ts': 'ts',
226
+ apache: 'conf',
227
+ apex: 'cls',
228
+ apl: 'apl',
229
+ applescript: 'applescript',
230
+ ara: 'ara',
231
+ asciidoc: 'adoc',
232
+ asm: 'asm',
233
+ astro: 'astro',
234
+ awk: 'awk',
235
+ ballerina: 'bal',
236
+ bash: 'sh',
237
+ bat: 'bat',
238
+ batch: 'bat',
239
+ be: 'be',
240
+ beancount: 'beancount',
241
+ berry: 'berry',
242
+ bibtex: 'bib',
243
+ bicep: 'bicep',
244
+ blade: 'blade.php',
245
+ bsl: 'bsl',
246
+ c: 'c',
247
+ 'c#': 'cs',
248
+ 'c++': 'cpp',
249
+ cadence: 'cdc',
250
+ cairo: 'cairo',
251
+ cdc: 'cdc',
252
+ clarity: 'clar',
253
+ clj: 'clj',
254
+ clojure: 'clj',
255
+ 'closure-templates': 'soy',
256
+ cmake: 'cmake',
257
+ cmd: 'cmd',
258
+ cobol: 'cob',
259
+ codeowners: 'CODEOWNERS',
260
+ codeql: 'ql',
261
+ coffee: 'coffee',
262
+ coffeescript: 'coffee',
263
+ 'common-lisp': 'lisp',
264
+ console: 'sh',
265
+ coq: 'v',
266
+ cpp: 'cpp',
267
+ cql: 'cql',
268
+ crystal: 'cr',
269
+ cs: 'cs',
270
+ csharp: 'cs',
271
+ css: 'css',
272
+ csv: 'csv',
273
+ cue: 'cue',
274
+ cypher: 'cql',
275
+ d: 'd',
276
+ dart: 'dart',
277
+ dax: 'dax',
278
+ desktop: 'desktop',
279
+ diff: 'diff',
280
+ docker: 'dockerfile',
281
+ dockerfile: 'dockerfile',
282
+ dotenv: 'env',
283
+ 'dream-maker': 'dm',
284
+ edge: 'edge',
285
+ elisp: 'el',
286
+ elixir: 'ex',
287
+ elm: 'elm',
288
+ 'emacs-lisp': 'el',
289
+ erb: 'erb',
290
+ erl: 'erl',
291
+ erlang: 'erl',
292
+ f: 'f',
293
+ 'f#': 'fs',
294
+ f03: 'f03',
295
+ f08: 'f08',
296
+ f18: 'f18',
297
+ f77: 'f77',
298
+ f90: 'f90',
299
+ f95: 'f95',
300
+ fennel: 'fnl',
301
+ fish: 'fish',
302
+ fluent: 'ftl',
303
+ for: 'for',
304
+ 'fortran-fixed-form': 'f',
305
+ 'fortran-free-form': 'f90',
306
+ fs: 'fs',
307
+ fsharp: 'fs',
308
+ fsl: 'fsl',
309
+ ftl: 'ftl',
310
+ gdresource: 'tres',
311
+ gdscript: 'gd',
312
+ gdshader: 'gdshader',
313
+ genie: 'gs',
314
+ gherkin: 'feature',
315
+ 'git-commit': 'gitcommit',
316
+ 'git-rebase': 'gitrebase',
317
+ gjs: 'js',
318
+ gleam: 'gleam',
319
+ 'glimmer-js': 'js',
320
+ 'glimmer-ts': 'ts',
321
+ glsl: 'glsl',
322
+ gnuplot: 'plt',
323
+ go: 'go',
324
+ gql: 'gql',
325
+ graphql: 'graphql',
326
+ groovy: 'groovy',
327
+ gts: 'gts',
328
+ hack: 'hack',
329
+ haml: 'haml',
330
+ handlebars: 'hbs',
331
+ haskell: 'hs',
332
+ haxe: 'hx',
333
+ hbs: 'hbs',
334
+ hcl: 'hcl',
335
+ hjson: 'hjson',
336
+ hlsl: 'hlsl',
337
+ hs: 'hs',
338
+ html: 'html',
339
+ 'html-derivative': 'html',
340
+ http: 'http',
341
+ hxml: 'hxml',
342
+ hy: 'hy',
343
+ imba: 'imba',
344
+ ini: 'ini',
345
+ jade: 'jade',
346
+ java: 'java',
347
+ javascript: 'js',
348
+ jinja: 'jinja',
349
+ jison: 'jison',
350
+ jl: 'jl',
351
+ js: 'js',
352
+ json: 'json',
353
+ json5: 'json5',
354
+ jsonc: 'jsonc',
355
+ jsonl: 'jsonl',
356
+ jsonnet: 'jsonnet',
357
+ jssm: 'jssm',
358
+ jsx: 'jsx',
359
+ julia: 'jl',
360
+ kotlin: 'kt',
361
+ kql: 'kql',
362
+ kt: 'kt',
363
+ kts: 'kts',
364
+ kusto: 'kql',
365
+ latex: 'tex',
366
+ lean: 'lean',
367
+ lean4: 'lean',
368
+ less: 'less',
369
+ liquid: 'liquid',
370
+ lisp: 'lisp',
371
+ lit: 'lit',
372
+ llvm: 'll',
373
+ log: 'log',
374
+ logo: 'logo',
375
+ lua: 'lua',
376
+ luau: 'luau',
377
+ make: 'mak',
378
+ makefile: 'mak',
379
+ markdown: 'md',
380
+ marko: 'marko',
381
+ matlab: 'm',
382
+ md: 'md',
383
+ mdc: 'mdc',
384
+ mdx: 'mdx',
385
+ mediawiki: 'wiki',
386
+ mermaid: 'mmd',
387
+ mips: 's',
388
+ mipsasm: 's',
389
+ mmd: 'mmd',
390
+ mojo: 'mojo',
391
+ move: 'move',
392
+ nar: 'nar',
393
+ narrat: 'narrat',
394
+ nextflow: 'nf',
395
+ nf: 'nf',
396
+ nginx: 'conf',
397
+ nim: 'nim',
398
+ nix: 'nix',
399
+ nu: 'nu',
400
+ nushell: 'nu',
401
+ objc: 'm',
402
+ 'objective-c': 'm',
403
+ 'objective-cpp': 'mm',
404
+ ocaml: 'ml',
405
+ pascal: 'pas',
406
+ perl: 'pl',
407
+ perl6: 'p6',
408
+ php: 'php',
409
+ plsql: 'pls',
410
+ po: 'po',
411
+ polar: 'polar',
412
+ postcss: 'pcss',
413
+ pot: 'pot',
414
+ potx: 'potx',
415
+ powerquery: 'pq',
416
+ powershell: 'ps1',
417
+ prisma: 'prisma',
418
+ prolog: 'pl',
419
+ properties: 'properties',
420
+ proto: 'proto',
421
+ protobuf: 'proto',
422
+ ps: 'ps',
423
+ ps1: 'ps1',
424
+ pug: 'pug',
425
+ puppet: 'pp',
426
+ purescript: 'purs',
427
+ py: 'py',
428
+ python: 'py',
429
+ ql: 'ql',
430
+ qml: 'qml',
431
+ qmldir: 'qmldir',
432
+ qss: 'qss',
433
+ r: 'r',
434
+ racket: 'rkt',
435
+ raku: 'raku',
436
+ razor: 'cshtml',
437
+ rb: 'rb',
438
+ reg: 'reg',
439
+ regex: 'regex',
440
+ regexp: 'regexp',
441
+ rel: 'rel',
442
+ riscv: 's',
443
+ rs: 'rs',
444
+ rst: 'rst',
445
+ ruby: 'rb',
446
+ rust: 'rs',
447
+ sas: 'sas',
448
+ sass: 'sass',
449
+ scala: 'scala',
450
+ scheme: 'scm',
451
+ scss: 'scss',
452
+ sdbl: 'sdbl',
453
+ sh: 'sh',
454
+ shader: 'shader',
455
+ shaderlab: 'shader',
456
+ shell: 'sh',
457
+ shellscript: 'sh',
458
+ shellsession: 'sh',
459
+ smalltalk: 'st',
460
+ solidity: 'sol',
461
+ soy: 'soy',
462
+ sparql: 'rq',
463
+ spl: 'spl',
464
+ splunk: 'spl',
465
+ sql: 'sql',
466
+ 'ssh-config': 'config',
467
+ stata: 'do',
468
+ styl: 'styl',
469
+ stylus: 'styl',
470
+ svelte: 'svelte',
471
+ swift: 'swift',
472
+ 'system-verilog': 'sv',
473
+ systemd: 'service',
474
+ talon: 'talon',
475
+ talonscript: 'talon',
476
+ tasl: 'tasl',
477
+ tcl: 'tcl',
478
+ templ: 'templ',
479
+ terraform: 'tf',
480
+ tex: 'tex',
481
+ tf: 'tf',
482
+ tfvars: 'tfvars',
483
+ toml: 'toml',
484
+ ts: 'ts',
485
+ 'ts-tags': 'ts',
486
+ tsp: 'tsp',
487
+ tsv: 'tsv',
488
+ tsx: 'tsx',
489
+ turtle: 'ttl',
490
+ twig: 'twig',
491
+ typ: 'typ',
492
+ typescript: 'ts',
493
+ typespec: 'tsp',
494
+ typst: 'typ',
495
+ v: 'v',
496
+ vala: 'vala',
497
+ vb: 'vb',
498
+ verilog: 'v',
499
+ vhdl: 'vhdl',
500
+ vim: 'vim',
501
+ viml: 'vim',
502
+ vimscript: 'vim',
503
+ vue: 'vue',
504
+ 'vue-html': 'html',
505
+ 'vue-vine': 'vine',
506
+ vy: 'vy',
507
+ vyper: 'vy',
508
+ wasm: 'wasm',
509
+ wenyan: 'wy',
510
+ wgsl: 'wgsl',
511
+ wiki: 'wiki',
512
+ wikitext: 'wiki',
513
+ wit: 'wit',
514
+ wl: 'wl',
515
+ wolfram: 'wl',
516
+ xml: 'xml',
517
+ xsl: 'xsl',
518
+ yaml: 'yaml',
519
+ yml: 'yml',
520
+ zenscript: 'zs',
521
+ zig: 'zig',
522
+ zsh: 'zsh',
523
+ 文言: 'wy'
524
+ };
@@ -0,0 +1,3 @@
1
+ export { cn } from '../theme.js';
2
+ export { save } from './save.js';
3
+ export { parseUrl, transformUrl, isPathRelativeUrl } from './url.js';
@@ -0,0 +1,3 @@
1
+ export { cn } from '../theme.js';
2
+ export { save } from './save.js';
3
+ export { parseUrl, transformUrl, isPathRelativeUrl } from './url.js';
@@ -0,0 +1,13 @@
1
+ export type MermaidSvgMarkupOptions = {
2
+ id: string;
3
+ renderSvg?: () => Promise<string>;
4
+ root?: ParentNode;
5
+ };
6
+ export type SvgToPngBlobOptions = {
7
+ scale?: number;
8
+ };
9
+ export declare const DEFAULT_MERMAID_PNG_SCALE = 5;
10
+ export declare const getMermaidSvgElement: (id: string, root?: ParentNode) => SVGSVGElement | null;
11
+ export declare const serializeSvg: (svg: SVGSVGElement) => string;
12
+ export declare const getMermaidSvgMarkup: ({ id, renderSvg, root }: MermaidSvgMarkupOptions) => Promise<string | null>;
13
+ export declare const svgToPngBlob: (svgString: string, options?: SvgToPngBlobOptions) => Promise<Blob>;
@@ -0,0 +1,49 @@
1
+ export const DEFAULT_MERMAID_PNG_SCALE = 5;
2
+ export const getMermaidSvgElement = (id, root = document) => {
3
+ const container = root.querySelector?.(`[data-streamdown-mermaid="${id}"]`);
4
+ if (!container) {
5
+ return null;
6
+ }
7
+ return container.querySelector('[data-mermaid-svg] svg');
8
+ };
9
+ export const serializeSvg = (svg) => {
10
+ const clonedSvg = svg.cloneNode(true);
11
+ clonedSvg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
12
+ clonedSvg.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
13
+ return new XMLSerializer().serializeToString(clonedSvg);
14
+ };
15
+ export const getMermaidSvgMarkup = async ({ id, renderSvg, root = document }) => {
16
+ if (renderSvg) {
17
+ return renderSvg();
18
+ }
19
+ const svg = getMermaidSvgElement(id, root);
20
+ return svg ? serializeSvg(svg) : null;
21
+ };
22
+ export const svgToPngBlob = async (svgString, options = {}) => {
23
+ const encoded = 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svgString)));
24
+ const image = await new Promise((resolve, reject) => {
25
+ const img = new Image();
26
+ img.crossOrigin = 'anonymous';
27
+ img.onload = () => resolve(img);
28
+ img.onerror = () => reject(new Error('Failed to load SVG image'));
29
+ img.src = encoded;
30
+ });
31
+ const canvas = document.createElement('canvas');
32
+ const scale = options.scale ?? DEFAULT_MERMAID_PNG_SCALE;
33
+ canvas.width = image.width * scale;
34
+ canvas.height = image.height * scale;
35
+ const ctx = canvas.getContext('2d');
36
+ if (!ctx) {
37
+ throw new Error('Failed to create 2D canvas context for PNG export');
38
+ }
39
+ ctx.drawImage(image, 0, 0, canvas.width, canvas.height);
40
+ return new Promise((resolve, reject) => {
41
+ canvas.toBlob((blob) => {
42
+ if (!blob) {
43
+ reject(new Error('Failed to create PNG blob'));
44
+ return;
45
+ }
46
+ resolve(blob);
47
+ }, 'image/png');
48
+ });
49
+ };