API 文档Props 属性

MarkdownTyper Props

属性类型默认值说明
childrenstring-Markdown 内容(必需)
intervalnumber | IntervalType30打字间隔(毫秒)
timerType'setTimeout' | 'requestAnimationFrame''setTimeout'定时器类型
showCursorbooleanfalse是否显示光标
cursorReact.ReactNode"|"光标内容
showCursorOnPausebooleantrue暂停时是否显示光标
disableTypingbooleanfalse禁用打字动画
autoStartTypingbooleantrue是否自动开始
onStart(data) => void-打字开始回调
onEnd(data) => void-打字结束回调
onTypedChar(data) => void-每个字符打字后回调
onBeforeTypedChar(data) => Promise<void>-每个字符打字前回调
reactMarkdownPropsOptions-react-markdown 配置
customConvertMarkdownString(str: string) => string-自定义 Markdown 转换函数

MarkdownTyperCMD Props

MarkdownTyper 相同,但不需要 children

IntervalType

支持动态打字速度:

type IntervalType = number | {
  max: number;      // 最大间隔
  min: number;      // 最小间隔
  curve?: 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'linear' | 'step-start' | 'step-end';
  curveFn?: (x: number) => number;  // 自定义曲线函数
}

示例

<MarkdownTyper 
  interval={{
    min: 10,
    max: 100,
    curve: 'ease-out'  // 开始快,结束慢
  }}
>
  内容...
</MarkdownTyper>

回调函数

onStart

打字开始时触发:

onStart={(data) => {
  console.log('开始打字', data);
  // data: { currentIndex: number, currentChar: string, prevStr: string }
}}

onEnd

打字结束时触发:

onEnd={(data) => {
  console.log('打字结束', data);
  // data: { manual: boolean, str: string }
}}

onTypedChar

每个字符打字后触发:

onTypedChar={(data) => {
  console.log('进度:', data.percent + '%');
  // data: { currentIndex, currentChar, prevStr, currentStr, percent }
}}

onBeforeTypedChar

每个字符打字前触发(支持异步):

onBeforeTypedChar={async (data) => {
  await someAsyncOperation();
  // data: { currentIndex, currentChar, prevStr, percent }
}}