@supermanzm/streamdown-code 1.1.1

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.
@@ -0,0 +1,60 @@
1
+ import { BundledTheme, ThemeRegistrationAny, TokensResult, BundledLanguage } from 'shiki';
2
+
3
+ type ThemeInput = BundledTheme | ThemeRegistrationAny;
4
+ /**
5
+ * Result from code highlighting
6
+ */
7
+ type HighlightResult = TokensResult;
8
+ /**
9
+ * Options for highlighting code
10
+ */
11
+ interface HighlightOptions {
12
+ code: string;
13
+ language: BundledLanguage;
14
+ themes: [ThemeInput, ThemeInput];
15
+ }
16
+ /**
17
+ * Plugin for code syntax highlighting (Shiki)
18
+ */
19
+ interface CodeHighlighterPlugin {
20
+ /**
21
+ * Get list of supported languages
22
+ */
23
+ getSupportedLanguages: () => BundledLanguage[];
24
+ /**
25
+ * Get the configured themes
26
+ */
27
+ getThemes: () => [ThemeInput, ThemeInput];
28
+ /**
29
+ * Highlight code and return tokens
30
+ * Returns null if highlighting not ready yet (async loading)
31
+ * Use callback for async result
32
+ */
33
+ highlight: (options: HighlightOptions, callback?: (result: HighlightResult) => void) => HighlightResult | null;
34
+ name: "shiki";
35
+ /**
36
+ * Check if language is supported
37
+ */
38
+ supportsLanguage: (language: BundledLanguage) => boolean;
39
+ type: "code-highlighter";
40
+ }
41
+ /**
42
+ * Options for creating a code plugin
43
+ */
44
+ interface CodePluginOptions {
45
+ /**
46
+ * Default themes for syntax highlighting [light, dark]
47
+ * @default ["github-light", "github-dark"]
48
+ */
49
+ themes?: [ThemeInput, ThemeInput];
50
+ }
51
+ /**
52
+ * Create a code plugin with optional configuration
53
+ */
54
+ declare function createCodePlugin(options?: CodePluginOptions): CodeHighlighterPlugin;
55
+ /**
56
+ * Pre-configured code plugin with default settings
57
+ */
58
+ declare const code: CodeHighlighterPlugin;
59
+
60
+ export { type CodeHighlighterPlugin, type CodePluginOptions, type HighlightOptions, type HighlightResult, type ThemeInput, code, createCodePlugin };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import {bundledLanguagesInfo,bundledLanguages,createHighlighter}from'shiki';import {createJavaScriptRegexEngine}from'shiki/engine/javascript';var S=createJavaScriptRegexEngine({forgiving:true}),C=Object.fromEntries(bundledLanguagesInfo.flatMap(e=>{var n;return ((n=e.aliases)!=null?n:[]).map(t=>[t,e.id])})),r=new Set(Object.keys(bundledLanguages)),B=e=>{let t=e.trim().toLowerCase(),g=C[t];return g||(r.has(t),t)},c=new Map,p=new Map,s=new Map,o=e=>{var n;return typeof e=="string"?e:(n=e.name)!=null?n:"custom"},v=(e,n)=>`${e}-${o(n[0])}-${o(n[1])}`,x=(e,n,t)=>{let g=e.slice(0,100),u=e.length>100?e.slice(-100):"";return `${n}:${t[0]}:${t[1]}:${e.length}:${g}:${u}`},P=(e,n)=>{let t=v(e,n);if(c.has(t))return c.get(t);let g=createHighlighter({themes:n,langs:[e],engine:S});return c.set(t,g),g};function $(e={}){var t;let n=(t=e.themes)!=null?t:["github-light","github-dark"];return {name:"shiki",type:"code-highlighter",supportsLanguage(g){let u=B(g);return r.has(u)},getSupportedLanguages(){return Array.from(r)},getThemes(){return n},highlight({code:g,language:u,themes:h},m){let i=B(u),d=[o(h[0]),o(h[1])],a=x(g,i,d);if(p.has(a))return p.get(a);m&&(s.has(a)||s.set(a,new Set),s.get(a).add(m));let f=r.has(i)?i:"text";return P(f,h).then(l=>{let y=l.getLoadedLanguages().includes(i)?i:"text",L=l.codeToTokens(g,{lang:y,themes:{light:d[0],dark:d[1]}});p.set(a,L);let T=s.get(a);if(T){for(let H of T)H(L);s.delete(a);}}).catch(l=>{console.error("[Streamdown Code] Failed to highlight code:",l),s.delete(a);}),null}}}var G=$();export{G as code,$ as createCodePlugin};
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@supermanzm/streamdown-code",
3
+ "version": "1.1.1",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsup",
19
+ "test": "vitest run",
20
+ "test:coverage": "vitest --coverage run"
21
+ },
22
+ "peerDependencies": {
23
+ "react": "^18.0.0 || ^19.0.0"
24
+ },
25
+ "dependencies": {
26
+ "shiki": "^3.19.0"
27
+ },
28
+ "devDependencies": {
29
+ "@vitest/coverage-v8": "^4.0.15",
30
+ "tsup": "^8.5.1",
31
+ "typescript": "^5.9.3",
32
+ "vitest": "^4.0.15"
33
+ },
34
+ "author": "Hayden Bleasel <hayden.bleasel@vercel.com>",
35
+ "license": "Apache-2.0",
36
+ "description": "Shiki syntax highlighting plugin for Streamdown",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/vercel/streamdown.git",
40
+ "directory": "packages/streamdown-code"
41
+ }
42
+ }