Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fix-shiki-type-declarations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"streamdown": patch
---

Fix type declarations requiring a `shiki` install.

`BundledLanguage`, `BundledTheme`, and `ThemeRegistrationAny` are now defined locally and re-exported from `streamdown`, so consumers can type-check without installing `shiki`. Runtime highlighting remains in `@streamdown/code`, which still depends on `shiki`.
8 changes: 3 additions & 5 deletions packages/streamdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ import {
} from "./lib/translations-context";
import { createCn } from "./lib/utils";

export type {
BundledLanguage,
BundledTheme,
ThemeRegistrationAny,
} from "shiki";
export type { AnimateOptions } from "./lib/animate";
// biome-ignore lint/performance/noBarrelFile: "required"
export { createAnimatePlugin } from "./lib/animate";
Expand All @@ -73,6 +68,8 @@ export type {
export { defaultUrlTransform } from "./lib/markdown";
export { parseMarkdownIntoBlocks } from "./lib/parse-blocks";
export type {
BundledLanguage,
BundledTheme,
CjkPlugin,
CodeHighlighterPlugin,
CustomRenderer,
Expand All @@ -82,6 +79,7 @@ export type {
MathPlugin,
PluginConfig,
ThemeInput,
ThemeRegistrationAny,
} from "./lib/plugin-types";
export {
TableCopyDropdown,
Expand Down
3 changes: 1 addition & 2 deletions packages/streamdown/lib/code-block/highlighted-body.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { type HTMLAttributes, useContext, useEffect, useState } from "react";
import type { BundledLanguage } from "shiki";
import { StreamdownContext } from "../../index";
import { useCodePlugin } from "../plugin-context";
import type { HighlightResult } from "../plugin-types";
import type { BundledLanguage, HighlightResult } from "../plugin-types";
import { CodeBlockBody } from "./body";

type HighlightedCodeBlockBodyProps = HTMLAttributes<HTMLDivElement> & {
Expand Down
24 changes: 17 additions & 7 deletions packages/streamdown/lib/plugin-types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import type { MermaidConfig } from "mermaid";
import type React from "react";
import type { Pluggable } from "unified";
import type {
BundledLanguage,
BundledTheme,
ThemeRegistrationAny,
} from "shiki";
import type { Pluggable } from "unified";
} from "./shiki-types";

export type {
BundledLanguage,
BundledTheme,
ThemeRegistrationAny,
} from "./shiki-types";

export type ThemeInput = BundledTheme | ThemeRegistrationAny;

Expand Down Expand Up @@ -42,30 +48,34 @@ export interface HighlightOptions {

/**
* Plugin for code syntax highlighting (Shiki)
*
* Method syntax is intentional: parameter types stay bivariant so plugins
* from `@streamdown/code` (which use Shiki's narrower language/theme unions)
* remain assignable without requiring a `shiki` type dependency here.
*/
export interface CodeHighlighterPlugin {
/**
* Get list of supported languages
*/
getSupportedLanguages: () => BundledLanguage[];
getSupportedLanguages(): BundledLanguage[];
/**
* Get the configured themes
*/
getThemes: () => [ThemeInput, ThemeInput];
getThemes(): [ThemeInput, ThemeInput];
/**
* Highlight code and return tokens
* Returns null if highlighting not ready yet (async loading)
* Use callback for async result
*/
highlight: (
highlight(
options: HighlightOptions,
callback?: (result: HighlightResult) => void
) => HighlightResult | null;
): HighlightResult | null;
name: "shiki";
/**
* Check if language is supported
*/
supportsLanguage: (language: BundledLanguage) => boolean;
supportsLanguage(language: BundledLanguage): boolean;
type: "code-highlighter";
}

Expand Down
43 changes: 43 additions & 0 deletions packages/streamdown/lib/shiki-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* Types compatible with Shiki, defined locally so consumers of `streamdown`
* can type-check without installing the `shiki` package.
*
* Runtime highlighting lives in `@streamdown/code`, which depends on `shiki`.
* Streamdown only needs these types for its plugin API surface (`shikiTheme`,
* `CodeHighlighterPlugin`, and related re-exports).
*
* @see https://shiki.style/languages
* @see https://shiki.style/themes
*/

/**
* Language identifier for syntax highlighting.
* Compatible with Shiki's `BundledLanguage`.
*/
export type BundledLanguage = string;

/**
* Built-in theme name for syntax highlighting.
* Compatible with Shiki's `BundledTheme`.
*/
export type BundledTheme = string;

/**
* Custom theme registration object compatible with Shiki's
* `ThemeRegistrationAny` (raw, resolved, or intermediate forms).
*
* Kept structural and permissive so custom theme objects from
* `@streamdown/code` / Shiki remain assignable without a type dependency.
*/
export interface ThemeRegistrationAny {
bg?: string;
colors?: Record<string, string>;
displayName?: string;
fg?: string;
name?: string;
semanticHighlighting?: boolean;
semanticTokenColors?: Record<string, unknown>;
settings?: unknown[];
tokenColors?: unknown[];
type?: "light" | "dark";
}
1 change: 0 additions & 1 deletion packages/streamdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"react-markdown": "^10.1.0",
"rehype-parse": "^9.0.1",
"rehype-stringify": "^10.0.1",
"shiki": "^3.19.0",
"tsup": "^8.5.1",
"vitest": "^4.0.15"
},
Expand Down
11 changes: 4 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.