react-markdown-typer 0.0.2 → 1.0.0-beta.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.
- package/README.md +8 -9
- package/README.zh.md +6 -9
- package/es/Markdown/index.d.ts +5 -0
- package/es/Markdown/index.d.ts.map +1 -0
- package/es/Markdown/index.js +62 -0
- package/es/Markdown/index.js.map +1 -0
- package/es/MarkdownCMD/index.d.ts +4 -0
- package/es/MarkdownCMD/index.d.ts.map +1 -0
- package/es/MarkdownCMD/index.js +160 -0
- package/es/MarkdownCMD/index.js.map +1 -0
- package/es/components/HighReactMarkdown/index.d.ts +9 -0
- package/es/components/HighReactMarkdown/index.d.ts.map +1 -0
- package/es/components/HighReactMarkdown/index.js +7 -0
- package/es/components/HighReactMarkdown/index.js.map +1 -0
- package/es/constant.d.ts +4 -0
- package/es/constant.d.ts.map +1 -0
- package/es/constant.js +4 -0
- package/es/constant.js.map +1 -0
- package/{dist/cjs/index.d.ts → es/defined.d.ts} +47 -21
- package/es/defined.d.ts.map +1 -0
- package/es/defined.js +2 -0
- package/es/defined.js.map +1 -0
- package/es/hooks/useTypingTask.d.ts +32 -0
- package/es/hooks/useTypingTask.d.ts.map +1 -0
- package/{dist/esm/index.js → es/hooks/useTypingTask.js} +7 -260
- package/es/hooks/useTypingTask.js.map +1 -0
- package/es/index.d.ts +7 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +5 -0
- package/es/index.js.map +1 -0
- package/package.json +11 -15
- package/dist/cjs/index.js +0 -570
- package/dist/cjs/index.js.map +0 -1
- package/dist/esm/index.d.ts +0 -77
- package/dist/esm/index.js.map +0 -1
package/dist/cjs/index.js
DELETED
|
@@ -1,570 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
-
var react = require('react');
|
|
7
|
-
var ReactMarkdown = require('react-markdown');
|
|
8
|
-
|
|
9
|
-
const __DEV__ = process.env.NODE_ENV === 'development';
|
|
10
|
-
|
|
11
|
-
const useTypingTask = (options) => {
|
|
12
|
-
const { timerType = 'setTimeout', interval, charsRef, onEnd, onStart, onBeforeTypedChar, onTypedChar, processCharDisplay, wholeContentRef, disableTyping, triggerUpdate, resetWholeContent, } = options;
|
|
13
|
-
/** 是否卸载 */
|
|
14
|
-
const isUnmountRef = react.useRef(false);
|
|
15
|
-
/** 是否正在打字 */
|
|
16
|
-
const isTypingRef = react.useRef(false);
|
|
17
|
-
/** 动画帧ID */
|
|
18
|
-
const animationFrameRef = react.useRef(null);
|
|
19
|
-
/** 传统定时器(兼容模式) */
|
|
20
|
-
const timerRef = react.useRef(null);
|
|
21
|
-
// 已经打过的字记录
|
|
22
|
-
const typedCharsRef = react.useRef(undefined);
|
|
23
|
-
// 是否主动调用 stop 方法
|
|
24
|
-
const typedIsManualStopRef = react.useRef(false);
|
|
25
|
-
const disableTypingRef = react.useRef(disableTyping);
|
|
26
|
-
disableTypingRef.current = disableTyping;
|
|
27
|
-
const intervalRef = react.useRef(interval);
|
|
28
|
-
intervalRef.current = interval;
|
|
29
|
-
const getChars = () => {
|
|
30
|
-
return charsRef.current;
|
|
31
|
-
};
|
|
32
|
-
react.useEffect(() => {
|
|
33
|
-
isUnmountRef.current = false;
|
|
34
|
-
return () => {
|
|
35
|
-
isUnmountRef.current = true;
|
|
36
|
-
clearTimer();
|
|
37
|
-
};
|
|
38
|
-
}, []);
|
|
39
|
-
/**
|
|
40
|
-
* 触发打字开始回调
|
|
41
|
-
* @param char 当前字符
|
|
42
|
-
*/
|
|
43
|
-
const triggerOnStart = (char) => {
|
|
44
|
-
if (!onStart) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
const prevStr = wholeContentRef.current.content;
|
|
48
|
-
onStart({
|
|
49
|
-
currentIndex: prevStr.length,
|
|
50
|
-
currentChar: char.content,
|
|
51
|
-
prevStr,
|
|
52
|
-
});
|
|
53
|
-
};
|
|
54
|
-
/**
|
|
55
|
-
* 触发打字结束回调
|
|
56
|
-
*/
|
|
57
|
-
const triggerOnEnd = (data) => {
|
|
58
|
-
if (!onEnd) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
onEnd({
|
|
62
|
-
str: wholeContentRef.current.content,
|
|
63
|
-
manual: data?.manual ?? false,
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
/**
|
|
67
|
-
* 触发打字过程中回调
|
|
68
|
-
* @param char 当前字符
|
|
69
|
-
*/
|
|
70
|
-
const triggerOnBeforeTypedChar = async (char) => {
|
|
71
|
-
if (!onBeforeTypedChar) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const { content, index } = char;
|
|
75
|
-
const allLength = wholeContentRef.current.length;
|
|
76
|
-
// 计算之前字符的百分比
|
|
77
|
-
const percent = (char.index / allLength) * 100;
|
|
78
|
-
await onBeforeTypedChar({
|
|
79
|
-
currentIndex: index,
|
|
80
|
-
currentChar: content,
|
|
81
|
-
prevStr: wholeContentRef.current.content,
|
|
82
|
-
percent,
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
/** 打字完成回调 */
|
|
86
|
-
const triggerOnTypedChar = async (char) => {
|
|
87
|
-
if (!onTypedChar) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
const { content, index } = char;
|
|
91
|
-
const allLength = wholeContentRef.current.length;
|
|
92
|
-
const percent = ((char.index + 1) / allLength) * 100;
|
|
93
|
-
onTypedChar({
|
|
94
|
-
currentIndex: index,
|
|
95
|
-
currentChar: content,
|
|
96
|
-
prevStr: wholeContentRef.current.content.slice(0, index),
|
|
97
|
-
currentStr: wholeContentRef.current.content,
|
|
98
|
-
percent,
|
|
99
|
-
});
|
|
100
|
-
};
|
|
101
|
-
/** 清除定时器 */
|
|
102
|
-
const clearTimer = () => {
|
|
103
|
-
// 清理 requestAnimationFrame
|
|
104
|
-
if (animationFrameRef.current) {
|
|
105
|
-
cancelAnimationFrame(animationFrameRef.current);
|
|
106
|
-
animationFrameRef.current = null;
|
|
107
|
-
}
|
|
108
|
-
// 清理 setTimeout (可能被 timestamp 模式使用)
|
|
109
|
-
if (timerRef.current) {
|
|
110
|
-
clearTimeout(timerRef.current);
|
|
111
|
-
timerRef.current = null;
|
|
112
|
-
}
|
|
113
|
-
isTypingRef.current = false;
|
|
114
|
-
typedCharsRef.current = undefined;
|
|
115
|
-
};
|
|
116
|
-
/** 开始打字任务 */
|
|
117
|
-
const startTypedTask = () => {
|
|
118
|
-
/** 如果手动调用 stop 方法,则不重新开始打字 */
|
|
119
|
-
if (typedIsManualStopRef.current) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
if (isTypingRef.current) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
if (timerType === 'requestAnimationFrame') {
|
|
126
|
-
startAnimationFrameMode();
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
startTimeoutMode();
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
/** 打字机打完所有字符 */
|
|
133
|
-
async function typingRemainAll() {
|
|
134
|
-
const chars = getChars();
|
|
135
|
-
const answerCharsStr = chars.map((char) => char.content).join('');
|
|
136
|
-
if (answerCharsStr) {
|
|
137
|
-
await onBeforeTypedChar?.({
|
|
138
|
-
currentIndex: wholeContentRef.current.length,
|
|
139
|
-
currentChar: answerCharsStr,
|
|
140
|
-
prevStr: wholeContentRef.current.content,
|
|
141
|
-
percent: 100,
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
wholeContentRef.current.content += answerCharsStr;
|
|
145
|
-
wholeContentRef.current.prevLength = wholeContentRef.current.length;
|
|
146
|
-
wholeContentRef.current.length += answerCharsStr.length;
|
|
147
|
-
charsRef.current = [];
|
|
148
|
-
isTypingRef.current = false;
|
|
149
|
-
triggerOnEnd();
|
|
150
|
-
triggerUpdate();
|
|
151
|
-
}
|
|
152
|
-
/** requestAnimationFrame 模式 */
|
|
153
|
-
const startAnimationFrameMode = () => {
|
|
154
|
-
let lastFrameTime = performance.now();
|
|
155
|
-
const frameLoop = async (currentTime) => {
|
|
156
|
-
// 如果关闭打字机效果,则打完所有字符
|
|
157
|
-
if (disableTypingRef.current) {
|
|
158
|
-
await typingRemainAll();
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
const chars = getChars();
|
|
162
|
-
if (isUnmountRef.current)
|
|
163
|
-
return;
|
|
164
|
-
if (chars.length === 0) {
|
|
165
|
-
stopAnimationFrame();
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
const deltaTime = currentTime - lastFrameTime;
|
|
169
|
-
let needToTypingCharsLength = Math.max(0, Math.floor(deltaTime / intervalRef.current));
|
|
170
|
-
needToTypingCharsLength = Math.min(needToTypingCharsLength, chars.length);
|
|
171
|
-
if (needToTypingCharsLength > 0) {
|
|
172
|
-
// 处理字符
|
|
173
|
-
for (let i = 0; i < needToTypingCharsLength; i++) {
|
|
174
|
-
const char = chars.shift();
|
|
175
|
-
if (char === undefined)
|
|
176
|
-
break;
|
|
177
|
-
if (!isTypingRef.current) {
|
|
178
|
-
isTypingRef.current = true;
|
|
179
|
-
triggerOnStart(char);
|
|
180
|
-
}
|
|
181
|
-
/** 打字前回调 */
|
|
182
|
-
await triggerOnBeforeTypedChar(char);
|
|
183
|
-
processCharDisplay(char);
|
|
184
|
-
/** 打字完成回调 */
|
|
185
|
-
triggerOnTypedChar(char);
|
|
186
|
-
}
|
|
187
|
-
lastFrameTime = performance.now();
|
|
188
|
-
// 继续下一帧
|
|
189
|
-
if (chars.length > 0) {
|
|
190
|
-
animationFrameRef.current = requestAnimationFrame(frameLoop);
|
|
191
|
-
}
|
|
192
|
-
else {
|
|
193
|
-
isTypingRef.current = false;
|
|
194
|
-
triggerOnEnd();
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
// 本次你不需要打字,继续下一帧
|
|
199
|
-
animationFrameRef.current = requestAnimationFrame(frameLoop);
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
animationFrameRef.current = requestAnimationFrame(frameLoop);
|
|
203
|
-
};
|
|
204
|
-
/** 停止动画帧模式 */
|
|
205
|
-
const stopAnimationFrame = (manual = false) => {
|
|
206
|
-
isTypingRef.current = false;
|
|
207
|
-
if (animationFrameRef.current) {
|
|
208
|
-
cancelAnimationFrame(animationFrameRef.current);
|
|
209
|
-
animationFrameRef.current = null;
|
|
210
|
-
}
|
|
211
|
-
if (!manual) {
|
|
212
|
-
triggerOnEnd({ manual });
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
/** setTimeout 模式 */
|
|
216
|
-
const startTimeoutMode = () => {
|
|
217
|
-
const nextTyped = () => {
|
|
218
|
-
const chars = getChars();
|
|
219
|
-
if (chars.length === 0) {
|
|
220
|
-
stopTimeout();
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
timerRef.current = setTimeout(startTyped, intervalRef.current);
|
|
224
|
-
};
|
|
225
|
-
const startTyped = async (isStartPoint = false) => {
|
|
226
|
-
// 如果关闭打字机效果,则打完所有字符
|
|
227
|
-
if (disableTypingRef.current) {
|
|
228
|
-
typingRemainAll();
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
const chars = getChars();
|
|
232
|
-
if (isUnmountRef.current)
|
|
233
|
-
return;
|
|
234
|
-
isTypingRef.current = true;
|
|
235
|
-
const char = chars.shift();
|
|
236
|
-
if (char === undefined) {
|
|
237
|
-
stopTimeout();
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
if (isStartPoint) {
|
|
241
|
-
triggerOnStart(char);
|
|
242
|
-
}
|
|
243
|
-
/** 打字前回调 */
|
|
244
|
-
await triggerOnBeforeTypedChar(char);
|
|
245
|
-
processCharDisplay(char);
|
|
246
|
-
/** 打字完成回调 */
|
|
247
|
-
triggerOnTypedChar(char);
|
|
248
|
-
nextTyped();
|
|
249
|
-
};
|
|
250
|
-
startTyped(true);
|
|
251
|
-
};
|
|
252
|
-
/** 停止超时模式 */
|
|
253
|
-
const stopTimeout = () => {
|
|
254
|
-
isTypingRef.current = false;
|
|
255
|
-
if (timerRef.current) {
|
|
256
|
-
clearTimeout(timerRef.current);
|
|
257
|
-
timerRef.current = null;
|
|
258
|
-
}
|
|
259
|
-
triggerOnEnd();
|
|
260
|
-
};
|
|
261
|
-
const cancelTask = () => {
|
|
262
|
-
if (timerType === 'requestAnimationFrame') {
|
|
263
|
-
stopAnimationFrame();
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
266
|
-
stopTimeout();
|
|
267
|
-
}
|
|
268
|
-
};
|
|
269
|
-
/** 暂时停止 */
|
|
270
|
-
const stopTask = () => {
|
|
271
|
-
typedIsManualStopRef.current = true;
|
|
272
|
-
cancelTask();
|
|
273
|
-
};
|
|
274
|
-
/** 停止打字任务 */
|
|
275
|
-
const endTask = () => {
|
|
276
|
-
cancelTask();
|
|
277
|
-
};
|
|
278
|
-
function restartTypedTask() {
|
|
279
|
-
endTask();
|
|
280
|
-
typedIsManualStopRef.current = false;
|
|
281
|
-
// 将wholeContentRef的内容放到charsRef中
|
|
282
|
-
charsRef.current.unshift(...wholeContentRef.current.content.split('').map((charUnit) => {
|
|
283
|
-
const char = {
|
|
284
|
-
content: charUnit,
|
|
285
|
-
tokenId: 0,
|
|
286
|
-
index: 0,
|
|
287
|
-
};
|
|
288
|
-
return char;
|
|
289
|
-
}));
|
|
290
|
-
charsRef.current.unshift(...wholeContentRef.current.content.split('').map((charUnit) => {
|
|
291
|
-
const char = {
|
|
292
|
-
content: charUnit,
|
|
293
|
-
tokenId: 0,
|
|
294
|
-
index: 0,
|
|
295
|
-
};
|
|
296
|
-
return char;
|
|
297
|
-
}));
|
|
298
|
-
resetWholeContent();
|
|
299
|
-
triggerUpdate();
|
|
300
|
-
startTypedTask();
|
|
301
|
-
}
|
|
302
|
-
function clear() {
|
|
303
|
-
clearTimer();
|
|
304
|
-
}
|
|
305
|
-
function resume() {
|
|
306
|
-
typedIsManualStopRef.current = false;
|
|
307
|
-
startTypedTask();
|
|
308
|
-
}
|
|
309
|
-
return {
|
|
310
|
-
start: startTypedTask,
|
|
311
|
-
restart: restartTypedTask,
|
|
312
|
-
stop: stopTask,
|
|
313
|
-
resume: resume,
|
|
314
|
-
clear: clear,
|
|
315
|
-
isTyping: () => isTypingRef.current,
|
|
316
|
-
typedIsManualStopRef,
|
|
317
|
-
};
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
const replaceMathBracket = (value) => {
|
|
321
|
-
// Extract all block-level formula content, temporarily replace with placeholder, [...]
|
|
322
|
-
const blockMatches = [];
|
|
323
|
-
let replaced = value.replace(/\\*\[([\s\S]+?)\\*\]/g, (_m, p1) => {
|
|
324
|
-
blockMatches.push(p1);
|
|
325
|
-
return `__BLOCK_MATH_${blockMatches.length - 1}__`;
|
|
326
|
-
});
|
|
327
|
-
// Extract all inline formula content, temporarily replace with placeholder, [...]
|
|
328
|
-
replaced = replaced.replace(/\$\$([\s\S]+?)\$\$/g, (_m, p1) => {
|
|
329
|
-
blockMatches.push(p1);
|
|
330
|
-
return `__BLOCK_MATH_${blockMatches.length - 1}__`;
|
|
331
|
-
});
|
|
332
|
-
// Replace ( ... ) outside the block-level formula with $...$
|
|
333
|
-
replaced = replaced.replace(/\\*\(([^)]+?)\\*\)/g, (_m, p1) => {
|
|
334
|
-
return '$' + p1 + '$';
|
|
335
|
-
});
|
|
336
|
-
// Restore block-level formula content, keep the original parentheses inside
|
|
337
|
-
replaced = replaced.replace(/__BLOCK_MATH_(\d+)__/g, (_m, idx) => {
|
|
338
|
-
return '$$' + blockMatches[Number(idx)] + '$$';
|
|
339
|
-
});
|
|
340
|
-
return replaced;
|
|
341
|
-
};
|
|
342
|
-
|
|
343
|
-
const HighReactMarkdown = ({ reactMarkdownProps, children: _children, math }) => {
|
|
344
|
-
const mathSplitSymbol = math?.splitSymbol ?? 'dollar';
|
|
345
|
-
const children = react.useMemo(() => {
|
|
346
|
-
/** 如果存在数学公式插件,并且数学公式分隔符为括号,则替换成 $ 符号 */
|
|
347
|
-
if (mathSplitSymbol === 'bracket') {
|
|
348
|
-
return replaceMathBracket(_children);
|
|
349
|
-
}
|
|
350
|
-
return _children;
|
|
351
|
-
}, [mathSplitSymbol, _children]);
|
|
352
|
-
return jsxRuntime.jsx(ReactMarkdown, { ...reactMarkdownProps, children: children });
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
const MarkdownCMD = react.forwardRef(({ interval = 30, onEnd, onStart, onTypedChar, onBeforeTypedChar, timerType = 'setTimeout', math, reactMarkdownProps, disableTyping = false, autoStartTyping = true }, ref) => {
|
|
356
|
-
/** 是否自动开启打字动画, 后面发生变化将不会生效 */
|
|
357
|
-
const autoStartTypingRef = react.useRef(autoStartTyping);
|
|
358
|
-
/** 是否打过字 */
|
|
359
|
-
const isStartedTypingRef = react.useRef(false);
|
|
360
|
-
/** 当前需要打字的内容 */
|
|
361
|
-
const charsRef = react.useRef([]);
|
|
362
|
-
/**
|
|
363
|
-
* 打字是否已经完全结束
|
|
364
|
-
* 如果打字已经完全结束,则不会再触发打字效果
|
|
365
|
-
*/
|
|
366
|
-
const isWholeTypedEndRef = react.useRef(false);
|
|
367
|
-
const charIndexRef = react.useRef(0);
|
|
368
|
-
/** 整个内容引用 */
|
|
369
|
-
const wholeContentRef = react.useRef({
|
|
370
|
-
content: '',
|
|
371
|
-
length: 0,
|
|
372
|
-
prevLength: 0,
|
|
373
|
-
});
|
|
374
|
-
const [, setUpdate] = react.useState(0);
|
|
375
|
-
const triggerUpdate = () => {
|
|
376
|
-
setUpdate((prev) => prev + 1);
|
|
377
|
-
};
|
|
378
|
-
/**
|
|
379
|
-
* 处理字符显示逻辑
|
|
380
|
-
*/
|
|
381
|
-
const processCharDisplay = (char) => {
|
|
382
|
-
if (!isStartedTypingRef.current) {
|
|
383
|
-
isStartedTypingRef.current = true;
|
|
384
|
-
}
|
|
385
|
-
wholeContentRef.current.prevLength = wholeContentRef.current.length;
|
|
386
|
-
wholeContentRef.current.content += char.content;
|
|
387
|
-
wholeContentRef.current.length += char.content.length;
|
|
388
|
-
triggerUpdate();
|
|
389
|
-
};
|
|
390
|
-
const resetWholeContent = () => {
|
|
391
|
-
wholeContentRef.current.content = '';
|
|
392
|
-
wholeContentRef.current.length = 0;
|
|
393
|
-
wholeContentRef.current.prevLength = 0;
|
|
394
|
-
};
|
|
395
|
-
// 使用新的打字任务 hook
|
|
396
|
-
const typingTask = useTypingTask({
|
|
397
|
-
timerType,
|
|
398
|
-
interval,
|
|
399
|
-
charsRef,
|
|
400
|
-
onEnd,
|
|
401
|
-
onStart,
|
|
402
|
-
onTypedChar,
|
|
403
|
-
onBeforeTypedChar,
|
|
404
|
-
processCharDisplay,
|
|
405
|
-
wholeContentRef,
|
|
406
|
-
disableTyping,
|
|
407
|
-
triggerUpdate,
|
|
408
|
-
resetWholeContent,
|
|
409
|
-
});
|
|
410
|
-
/**
|
|
411
|
-
* 内部推送处理逻辑
|
|
412
|
-
*/
|
|
413
|
-
const processHasTypingPush = (content) => {
|
|
414
|
-
if (content.length === 0) {
|
|
415
|
-
return;
|
|
416
|
-
}
|
|
417
|
-
charsRef.current.push(...content.split('').map((chatStr) => {
|
|
418
|
-
const index = charIndexRef.current++;
|
|
419
|
-
const charObj = {
|
|
420
|
-
content: chatStr,
|
|
421
|
-
tokenId: 0,
|
|
422
|
-
index,
|
|
423
|
-
};
|
|
424
|
-
return charObj;
|
|
425
|
-
}));
|
|
426
|
-
// 如果关闭了自动打字, 并且没有打过字, 则不开启打字动画
|
|
427
|
-
if (!autoStartTypingRef.current && !isStartedTypingRef.current) {
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
430
|
-
if (!typingTask.isTyping()) {
|
|
431
|
-
typingTask.start();
|
|
432
|
-
}
|
|
433
|
-
};
|
|
434
|
-
const processNoTypingPush = (content) => {
|
|
435
|
-
wholeContentRef.current.content += content;
|
|
436
|
-
// 记录打字前的长度
|
|
437
|
-
wholeContentRef.current.prevLength = wholeContentRef.current.length;
|
|
438
|
-
wholeContentRef.current.length += content.length;
|
|
439
|
-
triggerUpdate();
|
|
440
|
-
onEnd?.({
|
|
441
|
-
str: content,
|
|
442
|
-
manual: false,
|
|
443
|
-
});
|
|
444
|
-
};
|
|
445
|
-
react.useImperativeHandle(ref, () => ({
|
|
446
|
-
/**
|
|
447
|
-
* 添加内容
|
|
448
|
-
* @param content 内容 {string}
|
|
449
|
-
* @param answerType 回答类型 {AnswerType}
|
|
450
|
-
*/
|
|
451
|
-
push: (content) => {
|
|
452
|
-
if (disableTyping) {
|
|
453
|
-
processNoTypingPush(content);
|
|
454
|
-
return;
|
|
455
|
-
}
|
|
456
|
-
processHasTypingPush(content);
|
|
457
|
-
},
|
|
458
|
-
/**
|
|
459
|
-
* 清除打字任务
|
|
460
|
-
*/
|
|
461
|
-
clear: () => {
|
|
462
|
-
typingTask.stop();
|
|
463
|
-
typingTask.typedIsManualStopRef.current = false;
|
|
464
|
-
charsRef.current = [];
|
|
465
|
-
resetWholeContent();
|
|
466
|
-
isWholeTypedEndRef.current = false;
|
|
467
|
-
charIndexRef.current = 0;
|
|
468
|
-
isStartedTypingRef.current = false;
|
|
469
|
-
triggerUpdate();
|
|
470
|
-
},
|
|
471
|
-
/** 开启打字,只有在关闭了自动打字才生效 */
|
|
472
|
-
start: () => {
|
|
473
|
-
if (!autoStartTypingRef.current) {
|
|
474
|
-
typingTask.start();
|
|
475
|
-
}
|
|
476
|
-
},
|
|
477
|
-
/** 停止打字任务 */
|
|
478
|
-
stop: () => {
|
|
479
|
-
typingTask.stop();
|
|
480
|
-
},
|
|
481
|
-
/** 重新开始打字任务 */
|
|
482
|
-
resume: () => {
|
|
483
|
-
typingTask.resume();
|
|
484
|
-
},
|
|
485
|
-
/**
|
|
486
|
-
* 主动触发打字结束
|
|
487
|
-
*/
|
|
488
|
-
triggerWholeEnd: () => {
|
|
489
|
-
isWholeTypedEndRef.current = true;
|
|
490
|
-
if (!typingTask.isTyping()) {
|
|
491
|
-
// 这里需要手动触发结束回调,因为 hook 中的 triggerOnEnd 不能直接调用
|
|
492
|
-
onEnd?.({
|
|
493
|
-
str: wholeContentRef.current.content,
|
|
494
|
-
manual: true,
|
|
495
|
-
});
|
|
496
|
-
}
|
|
497
|
-
},
|
|
498
|
-
/** 重新开始打字任务 */
|
|
499
|
-
restart: () => {
|
|
500
|
-
typingTask.restart();
|
|
501
|
-
},
|
|
502
|
-
}));
|
|
503
|
-
return (jsxRuntime.jsx(HighReactMarkdown, { reactMarkdownProps: reactMarkdownProps, math: math, children: wholeContentRef.current.content }));
|
|
504
|
-
});
|
|
505
|
-
if (__DEV__) {
|
|
506
|
-
MarkdownCMD.displayName = 'MarkdownCMD';
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
const MarkdownInner = ({ children: _children = '', markdownRef, ...rest }) => {
|
|
510
|
-
const cmdRef = react.useRef(null);
|
|
511
|
-
const prefixRef = react.useRef('');
|
|
512
|
-
const content = react.useMemo(() => {
|
|
513
|
-
if (typeof _children === 'string') {
|
|
514
|
-
return _children;
|
|
515
|
-
}
|
|
516
|
-
if (__DEV__) {
|
|
517
|
-
console.error('Markdown component must have a string child');
|
|
518
|
-
}
|
|
519
|
-
return '';
|
|
520
|
-
}, [_children]);
|
|
521
|
-
react.useEffect(() => {
|
|
522
|
-
if (prefixRef.current !== content) {
|
|
523
|
-
let newContent = '';
|
|
524
|
-
if (prefixRef.current === '') {
|
|
525
|
-
newContent = content;
|
|
526
|
-
}
|
|
527
|
-
else {
|
|
528
|
-
if (content.startsWith(prefixRef.current)) {
|
|
529
|
-
newContent = content.slice(prefixRef.current.length);
|
|
530
|
-
}
|
|
531
|
-
else {
|
|
532
|
-
newContent = content;
|
|
533
|
-
cmdRef.current.clear();
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
cmdRef.current.push(newContent);
|
|
537
|
-
prefixRef.current = content;
|
|
538
|
-
}
|
|
539
|
-
}, [content]);
|
|
540
|
-
react.useImperativeHandle(markdownRef, () => ({
|
|
541
|
-
stop: () => {
|
|
542
|
-
cmdRef.current.stop();
|
|
543
|
-
},
|
|
544
|
-
resume: () => {
|
|
545
|
-
cmdRef.current.resume();
|
|
546
|
-
},
|
|
547
|
-
start: () => {
|
|
548
|
-
cmdRef.current.start();
|
|
549
|
-
},
|
|
550
|
-
restart: () => {
|
|
551
|
-
cmdRef.current.restart();
|
|
552
|
-
},
|
|
553
|
-
}));
|
|
554
|
-
return jsxRuntime.jsx(MarkdownCMD, { ref: cmdRef, ...rest });
|
|
555
|
-
};
|
|
556
|
-
const Markdown = react.forwardRef((props, ref) => {
|
|
557
|
-
const { children = '' } = props;
|
|
558
|
-
if (__DEV__) {
|
|
559
|
-
if (typeof children !== 'string') {
|
|
560
|
-
throw new Error('Markdown component must have a string child');
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
return jsxRuntime.jsx(MarkdownInner, { ...props, markdownRef: ref });
|
|
564
|
-
});
|
|
565
|
-
var Markdown$1 = react.memo(Markdown);
|
|
566
|
-
|
|
567
|
-
exports.Markdown = Markdown$1;
|
|
568
|
-
exports.MarkdownCMD = MarkdownCMD;
|
|
569
|
-
exports.default = Markdown$1;
|
|
570
|
-
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/constant.ts","../../src/hooks/useTypingTask.ts","../../src/utils/remarkMathBracket.ts","../../src/components/HighReactMarkdown/index.tsx","../../src/MarkdownCMD/index.tsx","../../src/Markdown/index.tsx"],"sourcesContent":[null,null,null,null,null,null],"names":["useRef","useEffect","useMemo","_jsx","forwardRef","useState","useImperativeHandle","memo"],"mappings":";;;;;;;;AAAO,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa;;AC6BtD,MAAM,aAAa,GAAG,CAAC,OAA6B,KAA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EAAA,EAAA,GAAK,KAAK,EAAE,WAAW,EAAE,GAAG,EAAA,CAAI;AACvD,CAAC,CAAC;AAEF,iBAAeI,UAAI,CAAC,QAAQ,CAAC;;;;;;"}
|
package/dist/esm/index.d.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import * as react from 'react';
|
|
2
|
-
import react__default from 'react';
|
|
3
|
-
import { Options } from 'react-markdown';
|
|
4
|
-
|
|
5
|
-
interface IOnTypedCharData {
|
|
6
|
-
currentIndex: number;
|
|
7
|
-
currentChar: string;
|
|
8
|
-
prevStr: string;
|
|
9
|
-
}
|
|
10
|
-
interface ITypedChar extends IOnTypedCharData {
|
|
11
|
-
percent: number;
|
|
12
|
-
currentStr: string;
|
|
13
|
-
}
|
|
14
|
-
interface IBeforeTypedChar extends IOnTypedCharData {
|
|
15
|
-
percent: number;
|
|
16
|
-
}
|
|
17
|
-
interface MarkdownBaseProps {
|
|
18
|
-
reactMarkdownProps?: Options;
|
|
19
|
-
/** 计时类型: 支持setTimeout和requestAnimationFrame */
|
|
20
|
-
timerType?: 'setTimeout' | 'requestAnimationFrame';
|
|
21
|
-
/** 打字机效果间隔时间 */
|
|
22
|
-
interval: number;
|
|
23
|
-
/** 是否关闭打字机效果 */
|
|
24
|
-
disableTyping?: boolean;
|
|
25
|
-
/** 打字完成后回调, */
|
|
26
|
-
onEnd?: (data?: IEndData) => void;
|
|
27
|
-
/** 开始打字回调 */
|
|
28
|
-
onStart?: (data?: IOnTypedCharData) => void;
|
|
29
|
-
/** 打字前回调 */
|
|
30
|
-
onBeforeTypedChar?: (data?: IBeforeTypedChar) => Promise<void>;
|
|
31
|
-
/**
|
|
32
|
-
* 打字机打完一个字符回调
|
|
33
|
-
* @param char 字符
|
|
34
|
-
* @param index 字符索引
|
|
35
|
-
*/
|
|
36
|
-
onTypedChar?: (data?: ITypedChar) => void;
|
|
37
|
-
/** 是否自动开启打字动画 */
|
|
38
|
-
autoStartTyping?: boolean;
|
|
39
|
-
math?: IMarkdownMath;
|
|
40
|
-
}
|
|
41
|
-
interface MarkdownProps extends MarkdownBaseProps {
|
|
42
|
-
children: string | undefined;
|
|
43
|
-
}
|
|
44
|
-
/** MarkdownCMD 组件不需要 children */
|
|
45
|
-
interface MarkdownCMDProps extends MarkdownBaseProps {
|
|
46
|
-
children?: undefined;
|
|
47
|
-
}
|
|
48
|
-
interface IMarkdownMath {
|
|
49
|
-
/** 是括号还是$作为分隔符, 默认是$ */
|
|
50
|
-
splitSymbol: 'bracket' | 'dollar';
|
|
51
|
-
}
|
|
52
|
-
interface MarkdownBaseRef {
|
|
53
|
-
stop: () => void;
|
|
54
|
-
resume: () => void;
|
|
55
|
-
start: () => void;
|
|
56
|
-
restart: () => void;
|
|
57
|
-
}
|
|
58
|
-
/** Markdown 组件的ref 类型 */
|
|
59
|
-
type MarkdownRef = MarkdownBaseRef;
|
|
60
|
-
/** MarkdownCMD 组件的 ref 类型 */
|
|
61
|
-
interface MarkdownCMDRef extends MarkdownBaseRef {
|
|
62
|
-
push: (content: string) => void;
|
|
63
|
-
clear: () => void;
|
|
64
|
-
triggerWholeEnd: () => void;
|
|
65
|
-
}
|
|
66
|
-
interface IEndData {
|
|
67
|
-
manual: boolean;
|
|
68
|
-
/** 打字机打过的字符串, 和answerStr 相同 */
|
|
69
|
-
str: string;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
declare const MarkdownCMD: react.ForwardRefExoticComponent<MarkdownCMDProps & react.RefAttributes<MarkdownCMDRef>>;
|
|
73
|
-
|
|
74
|
-
declare const _default: react__default.NamedExoticComponent<MarkdownProps & react__default.RefAttributes<MarkdownBaseRef>>;
|
|
75
|
-
|
|
76
|
-
export { _default as Markdown, MarkdownCMD, _default as default };
|
|
77
|
-
export type { IMarkdownMath, ITypedChar, MarkdownCMDProps, MarkdownCMDRef, MarkdownProps, MarkdownRef };
|