UNPKG

@yuntijs/ui

Version:

☁️ Yunti UI - an open-source UI component library for building Cloud Native web apps

47 lines (46 loc) 1.89 kB
import { transformerNotationDiff } from '@shikijs/transformers'; import { CSSProperties } from 'react'; import type { ThemedToken, codeToHtml } from 'shiki'; import { themeMap } from './themeMap'; export declare const FALLBACK_LANG = "txt"; export type ThemeProps = (typeof themeMap)[number]; declare const MD5_LENGTH_THRESHOLD = 10000; type ColorReplacements = { [themeName: string]: { [color: string]: string; }; }; declare const loadShiki: () => Promise<typeof codeToHtml>; declare const shikiPromise: Promise<typeof codeToHtml>; declare const escapeHtml: (str: string) => string; export type StreamingHighlightResult = { colorReplacements?: Record<string, string>; lines: ThemedToken[][]; preStyle?: CSSProperties; }; export type UseStaticHighlightResponse = string; export type UseStreamHighlightResponse = StreamingHighlightResult | undefined; export type HighlightConfig = { colorReplacements: ColorReplacements; matchedLanguage: string; shikiTheme: string; transformers?: ReturnType<typeof transformerNotationDiff>[]; }; /** * 共享的高亮配置 hook * 处理主题、语言匹配、颜色替换等通用逻辑 */ export declare const useHighlightConfig: (lang: string, enableTransformer?: boolean, theme?: ThemeProps) => HighlightConfig; /** * 静态高亮 hook * 将代码转换为高亮 HTML 字符串 */ export declare const useStaticHighlight: (text: string, lang: string, enableTransformer?: boolean, theme?: ThemeProps) => UseStaticHighlightResponse; /** * 流式高亮 hook * 用于实时流式渲染代码高亮 */ export declare const useStreamHighlight: (text: string, lang: string, enableTransformer?: boolean, theme?: ThemeProps) => UseStreamHighlightResponse; export { languageMap } from './languageMap'; export { themeMap } from './themeMap'; export { escapeHtml, loadShiki, MD5_LENGTH_THRESHOLD, shikiPromise };