@assistant-ui/react 0.3.2 → 0.3.3
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/dist/index.js +16 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -12
- package/dist/experimental.d.mts +0 -2
- package/dist/experimental.d.ts +0 -2
- package/dist/experimental.js +0 -2
- package/dist/experimental.js.map +0 -1
- package/dist/experimental.mjs +0 -1
- package/dist/experimental.mjs.map +0 -1
package/dist/index.mjs
CHANGED
@@ -1172,10 +1172,10 @@ var TextStreamAnimator = class {
|
|
1172
1172
|
}
|
1173
1173
|
animationFrameId = null;
|
1174
1174
|
lastUpdateTime = Date.now();
|
1175
|
-
decayFactor = 0.99;
|
1176
1175
|
targetText = "";
|
1177
1176
|
start() {
|
1178
1177
|
if (this.animationFrameId !== null) return;
|
1178
|
+
this.lastUpdateTime = Date.now();
|
1179
1179
|
this.animate();
|
1180
1180
|
}
|
1181
1181
|
stop() {
|
@@ -1187,7 +1187,7 @@ var TextStreamAnimator = class {
|
|
1187
1187
|
animate = () => {
|
1188
1188
|
const currentTime = Date.now();
|
1189
1189
|
const deltaTime = currentTime - this.lastUpdateTime;
|
1190
|
-
|
1190
|
+
let timeToConsume = deltaTime;
|
1191
1191
|
this.setText((currentText) => {
|
1192
1192
|
const targetText = this.targetText;
|
1193
1193
|
if (currentText === targetText) {
|
@@ -1195,14 +1195,18 @@ var TextStreamAnimator = class {
|
|
1195
1195
|
return currentText;
|
1196
1196
|
}
|
1197
1197
|
const remainingChars = targetText.length - currentText.length;
|
1198
|
-
const
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
const newText = targetText.slice(0, currentText.length + charsToAdd);
|
1198
|
+
const baseTimePerChar = Math.min(5, 250 / remainingChars);
|
1199
|
+
let charsToAdd = 0;
|
1200
|
+
while (timeToConsume >= baseTimePerChar && charsToAdd < remainingChars) {
|
1201
|
+
charsToAdd++;
|
1202
|
+
timeToConsume -= baseTimePerChar;
|
1203
|
+
}
|
1205
1204
|
this.animationFrameId = requestAnimationFrame(this.animate);
|
1205
|
+
if (charsToAdd === 0) {
|
1206
|
+
return currentText;
|
1207
|
+
}
|
1208
|
+
const newText = targetText.slice(0, currentText.length + charsToAdd);
|
1209
|
+
this.lastUpdateTime = currentTime - timeToConsume;
|
1206
1210
|
return newText;
|
1207
1211
|
});
|
1208
1212
|
};
|
@@ -1213,6 +1217,7 @@ var useSmooth = (text, smooth = false) => {
|
|
1213
1217
|
new TextStreamAnimator(setDisplayedText)
|
1214
1218
|
);
|
1215
1219
|
useEffect8(() => {
|
1220
|
+
console.log("smooth", smooth);
|
1216
1221
|
if (!smooth) {
|
1217
1222
|
animatorRef.stop();
|
1218
1223
|
return;
|
@@ -1225,6 +1230,7 @@ var useSmooth = (text, smooth = false) => {
|
|
1225
1230
|
}
|
1226
1231
|
animatorRef.targetText = text;
|
1227
1232
|
animatorRef.start();
|
1233
|
+
console.log("animating");
|
1228
1234
|
}, [animatorRef, smooth, text]);
|
1229
1235
|
useEffect8(() => {
|
1230
1236
|
return () => {
|
@@ -1236,7 +1242,7 @@ var useSmooth = (text, smooth = false) => {
|
|
1236
1242
|
|
1237
1243
|
// src/primitives/contentPart/ContentPartText.tsx
|
1238
1244
|
import { jsx as jsx14 } from "react/jsx-runtime";
|
1239
|
-
var ContentPartPrimitiveText = forwardRef7(({ smooth, ...rest }, forwardedRef) => {
|
1245
|
+
var ContentPartPrimitiveText = forwardRef7(({ smooth = true, ...rest }, forwardedRef) => {
|
1240
1246
|
const {
|
1241
1247
|
status,
|
1242
1248
|
part: { text }
|