@alifd/chat 0.3.28-beta.4 → 0.3.28-beta.5

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/es/index.js CHANGED
@@ -31,4 +31,4 @@ export { default as RadioGroup } from './radio-group';
31
31
  export { default as CheckboxGroup } from './checkbox-group';
32
32
  export { default as Select } from './select';
33
33
  export { default as Flip } from './flip';
34
- export const version = '0.3.28-beta.4';
34
+ export const version = '0.3.28-beta.5';
@@ -46,68 +46,27 @@ const Markdown = forwardRef((_a, ref) => {
46
46
  }
47
47
  // 记录新的内容
48
48
  previousContentRef.current = content;
49
- // 计算当前已输出的内容+队列中待输出的内容
50
- const currentTotalContent = displayedContent + contentQueue.join('');
51
- // 如果新内容完全不同,则重置
52
- if (content.indexOf(currentTotalContent) !== 0 && currentTotalContent.indexOf(content) !== 0) {
49
+ // 清除任何现有的定时器
50
+ if (typeTimeoutRef.current) {
51
+ clearTimeout(typeTimeoutRef.current);
52
+ typeTimeoutRef.current = null;
53
+ }
54
+ // 将内容分成两部分:直接显示部分和打字效果部分
55
+ if (content.length <= 20) {
56
+ // 如果内容不超过20个字符,全部使用打字效果
53
57
  setDisplayedContent('');
54
58
  setContentQueue(content.split(''));
55
- setTyping(true);
56
- return;
57
- }
58
- // 如果新内容是当前内容的子集(内容被截断)
59
- if (content.length < currentTotalContent.length && currentTotalContent.indexOf(content) === 0) {
60
- // 计算应保留的已显示内容
61
- if (content.length <= displayedContent.length) {
62
- // 只需截断已显示内容
63
- setDisplayedContent(content);
64
- setContentQueue([]);
65
- }
66
- else {
67
- // 需要保留部分已显示内容和部分队列内容
68
- setDisplayedContent(displayedContent);
69
- setContentQueue(content.substring(displayedContent.length).split(''));
70
- }
71
- return;
72
- }
73
- // 如果新内容包含当前内容,但有新增(最常见情况)
74
- if (content.indexOf(currentTotalContent) === 0) {
75
- // 将新增的部分添加到队列中
76
- const newContent = content.substring(currentTotalContent.length);
77
- if (newContent) {
78
- setContentQueue(prevQueue => [...prevQueue, ...newContent.split('')]);
79
- if (!typing) {
80
- setTyping(true);
81
- }
82
- }
83
- return;
84
- }
85
- // 如果新内容与已显示内容有部分重叠,但不完全包含
86
- // 查找重叠的最大前缀
87
- let overlapLength = 0;
88
- for (let i = 1; i <= Math.min(displayedContent.length, content.length); i++) {
89
- if (content.substring(0, i) === displayedContent.substring(displayedContent.length - i)) {
90
- overlapLength = i;
91
- }
92
- }
93
- if (overlapLength > 0) {
94
- // 保留重叠部分,更新队列
95
- const newDisplayed = displayedContent.substring(0, displayedContent.length - overlapLength) +
96
- content.substring(0, overlapLength);
97
- const newQueue = content.substring(overlapLength).split('');
98
- setDisplayedContent(newDisplayed);
99
- setContentQueue(newQueue);
100
- if (newQueue.length > 0 && !typing) {
101
- setTyping(true);
102
- }
103
59
  }
104
60
  else {
105
- // 无法找到合适的重叠,完全重置
106
- setDisplayedContent('');
107
- setContentQueue(content.split(''));
108
- setTyping(true);
61
+ // 如果内容超过20个字符,前面部分直接显示,后20个字符用于打字效果
62
+ const displayPart = content.slice(0, content.length - 20);
63
+ const typingPart = content.slice(content.length - 20);
64
+ setDisplayedContent(displayPart);
65
+ setContentQueue(typingPart.split(''));
109
66
  }
110
- }, [content, others === null || others === void 0 ? void 0 : others.typewriterEffect, displayedContent, contentQueue, typing]);
67
+ // 启动打字机效果
68
+ setTyping(true);
69
+ }, [content, others === null || others === void 0 ? void 0 : others.typewriterEffect]);
111
70
  // 执行打字机效果
112
71
  useEffect(() => {
113
72
  if (!(others === null || others === void 0 ? void 0 : others.typewriterEffect) || contentQueue.length === 0 || !typing) {
@@ -118,9 +77,8 @@ const Markdown = forwardRef((_a, ref) => {
118
77
  clearTimeout(typeTimeoutRef.current);
119
78
  typeTimeoutRef.current = null;
120
79
  }
121
- // 动态计算输出速度,确保在2秒内完成
122
- const remainingChars = contentQueue.length;
123
- const timePerChar = Math.max(Math.min(2000 / remainingChars, 50), 10); // 最快10ms,最慢50ms每字符
80
+ // 固定打字速度为50ms一个字
81
+ const timePerChar = 50;
124
82
  const processNextChar = () => {
125
83
  if (contentQueue.length === 0) {
126
84
  if (typeTimeoutRef.current) {
package/lib/index.js CHANGED
@@ -68,4 +68,4 @@ var select_1 = require("./select");
68
68
  Object.defineProperty(exports, "Select", { enumerable: true, get: function () { return tslib_1.__importDefault(select_1).default; } });
69
69
  var flip_1 = require("./flip");
70
70
  Object.defineProperty(exports, "Flip", { enumerable: true, get: function () { return tslib_1.__importDefault(flip_1).default; } });
71
- exports.version = '0.3.28-beta.4';
71
+ exports.version = '0.3.28-beta.5';
@@ -48,68 +48,27 @@ const Markdown = (0, react_1.forwardRef)((_a, ref) => {
48
48
  }
49
49
  // 记录新的内容
50
50
  previousContentRef.current = content;
51
- // 计算当前已输出的内容+队列中待输出的内容
52
- const currentTotalContent = displayedContent + contentQueue.join('');
53
- // 如果新内容完全不同,则重置
54
- if (content.indexOf(currentTotalContent) !== 0 && currentTotalContent.indexOf(content) !== 0) {
51
+ // 清除任何现有的定时器
52
+ if (typeTimeoutRef.current) {
53
+ clearTimeout(typeTimeoutRef.current);
54
+ typeTimeoutRef.current = null;
55
+ }
56
+ // 将内容分成两部分:直接显示部分和打字效果部分
57
+ if (content.length <= 20) {
58
+ // 如果内容不超过20个字符,全部使用打字效果
55
59
  setDisplayedContent('');
56
60
  setContentQueue(content.split(''));
57
- setTyping(true);
58
- return;
59
- }
60
- // 如果新内容是当前内容的子集(内容被截断)
61
- if (content.length < currentTotalContent.length && currentTotalContent.indexOf(content) === 0) {
62
- // 计算应保留的已显示内容
63
- if (content.length <= displayedContent.length) {
64
- // 只需截断已显示内容
65
- setDisplayedContent(content);
66
- setContentQueue([]);
67
- }
68
- else {
69
- // 需要保留部分已显示内容和部分队列内容
70
- setDisplayedContent(displayedContent);
71
- setContentQueue(content.substring(displayedContent.length).split(''));
72
- }
73
- return;
74
- }
75
- // 如果新内容包含当前内容,但有新增(最常见情况)
76
- if (content.indexOf(currentTotalContent) === 0) {
77
- // 将新增的部分添加到队列中
78
- const newContent = content.substring(currentTotalContent.length);
79
- if (newContent) {
80
- setContentQueue(prevQueue => [...prevQueue, ...newContent.split('')]);
81
- if (!typing) {
82
- setTyping(true);
83
- }
84
- }
85
- return;
86
- }
87
- // 如果新内容与已显示内容有部分重叠,但不完全包含
88
- // 查找重叠的最大前缀
89
- let overlapLength = 0;
90
- for (let i = 1; i <= Math.min(displayedContent.length, content.length); i++) {
91
- if (content.substring(0, i) === displayedContent.substring(displayedContent.length - i)) {
92
- overlapLength = i;
93
- }
94
- }
95
- if (overlapLength > 0) {
96
- // 保留重叠部分,更新队列
97
- const newDisplayed = displayedContent.substring(0, displayedContent.length - overlapLength) +
98
- content.substring(0, overlapLength);
99
- const newQueue = content.substring(overlapLength).split('');
100
- setDisplayedContent(newDisplayed);
101
- setContentQueue(newQueue);
102
- if (newQueue.length > 0 && !typing) {
103
- setTyping(true);
104
- }
105
61
  }
106
62
  else {
107
- // 无法找到合适的重叠,完全重置
108
- setDisplayedContent('');
109
- setContentQueue(content.split(''));
110
- setTyping(true);
63
+ // 如果内容超过20个字符,前面部分直接显示,后20个字符用于打字效果
64
+ const displayPart = content.slice(0, content.length - 20);
65
+ const typingPart = content.slice(content.length - 20);
66
+ setDisplayedContent(displayPart);
67
+ setContentQueue(typingPart.split(''));
111
68
  }
112
- }, [content, others === null || others === void 0 ? void 0 : others.typewriterEffect, displayedContent, contentQueue, typing]);
69
+ // 启动打字机效果
70
+ setTyping(true);
71
+ }, [content, others === null || others === void 0 ? void 0 : others.typewriterEffect]);
113
72
  // 执行打字机效果
114
73
  (0, react_1.useEffect)(() => {
115
74
  if (!(others === null || others === void 0 ? void 0 : others.typewriterEffect) || contentQueue.length === 0 || !typing) {
@@ -120,9 +79,8 @@ const Markdown = (0, react_1.forwardRef)((_a, ref) => {
120
79
  clearTimeout(typeTimeoutRef.current);
121
80
  typeTimeoutRef.current = null;
122
81
  }
123
- // 动态计算输出速度,确保在2秒内完成
124
- const remainingChars = contentQueue.length;
125
- const timePerChar = Math.max(Math.min(2000 / remainingChars, 50), 10); // 最快10ms,最慢50ms每字符
82
+ // 固定打字速度为50ms一个字
83
+ const timePerChar = 50;
126
84
  const processNextChar = () => {
127
85
  if (contentQueue.length === 0) {
128
86
  if (typeTimeoutRef.current) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alifd/chat",
3
- "version": "0.3.28-beta.4",
3
+ "version": "0.3.28-beta.5",
4
4
  "description": "A configurable component library for chat built on React.",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",