类型定义
IntervalConfig
动态打字速度配置。
interface IntervalConfig {
max: number; // 最大间隔(ms),剩余字符多时使用
min: number; // 最小间隔(ms),剩余字符少时使用
curveFn?: (x: number) => number; // 自定义曲线函数,x 是剩余比例 [0,1]
curve?: 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'linear' | 'step-start' | 'step-end'; // 预设曲线
}示例
const intervalConfig: IntervalConfig = {
min: 10,
max: 50,
curve: 'ease-out'
};IMarkdownMath
数学公式配置。
interface IMarkdownMath {
splitSymbol: 'dollar' | 'bracket'; // 数学公式分隔符类型
replaceMathBracket?: (value: string) => string; // 数学公式替换函数
}示例
const mathConfig: IMarkdownMath = {
splitSymbol: 'dollar' // 使用 $...$ 语法
};IMarkdownCode
代码块配置。
interface IMarkdownCode {
headerActions?: boolean | React.ReactNode; // 是否显示头部操作按钮
}示例
const codeConfig: IMarkdownCode = {
headerActions: true // 显示默认操作按钮
};
// 或自定义
const customCodeConfig: IMarkdownCode = {
headerActions: <CustomActions />
};IMarkdownPlugin
插件配置。
interface IMarkdownPlugin {
remarkPlugin?: unknown; // remark 插件实例
rehypePlugin?: unknown; // rehype 插件实例
type: 'buildIn' | 'custom'; // 插件类型
id?: any; // 插件唯一标识符
components?: Record<string, React.ComponentType<unknown>>; // 自定义组件
}ITypedChar
打字字符数据。
interface ITypedChar {
currentIndex: number; // 当前字符在字符串中的索引
currentChar: string; // 刚刚打出的字符
answerType: AnswerType; // 内容类型(thinking/answer)
prevStr: string; // 当前类型的前缀字符串
currentStr: string; // 当前类型的完整字符串
percent: number; // 打字进度百分比 (0-100)
}IBeforeTypedChar
打字前字符数据。
interface IBeforeTypedChar {
currentIndex: number; // 当前字符在字符串中的索引
currentChar: string; // 即将打出的字符
answerType: AnswerType; // 内容类型(thinking/answer)
prevStr: string; // 当前类型的前缀字符串
percent: number; // 打字进度百分比 (0-100)
}IEndData
打字结束数据。
interface IEndData {
manual: boolean; // 是否手动触发
answerStr: string; // 回答字符串
thinkingStr: string; // 思考字符串
str: string; // 打字字符串,与 answerStr 相同
}IStartData
打字开始数据。
interface IStartData {
currentIndex: number; // 当前字符在字符串中的索引
currentChar: string; // 当前字符
prevStr: string; // 前缀字符串
}AnswerType
内容类型。
type AnswerType = 'thinking' | 'answer';Theme
主题类型。
type Theme = 'light' | 'dark';