@assistant-ui/react 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- 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.js
CHANGED
@@ -1231,10 +1231,10 @@ var TextStreamAnimator = class {
|
|
1231
1231
|
}
|
1232
1232
|
animationFrameId = null;
|
1233
1233
|
lastUpdateTime = Date.now();
|
1234
|
-
decayFactor = 0.99;
|
1235
1234
|
targetText = "";
|
1236
1235
|
start() {
|
1237
1236
|
if (this.animationFrameId !== null) return;
|
1237
|
+
this.lastUpdateTime = Date.now();
|
1238
1238
|
this.animate();
|
1239
1239
|
}
|
1240
1240
|
stop() {
|
@@ -1246,7 +1246,7 @@ var TextStreamAnimator = class {
|
|
1246
1246
|
animate = () => {
|
1247
1247
|
const currentTime = Date.now();
|
1248
1248
|
const deltaTime = currentTime - this.lastUpdateTime;
|
1249
|
-
|
1249
|
+
let timeToConsume = deltaTime;
|
1250
1250
|
this.setText((currentText) => {
|
1251
1251
|
const targetText = this.targetText;
|
1252
1252
|
if (currentText === targetText) {
|
@@ -1254,14 +1254,18 @@ var TextStreamAnimator = class {
|
|
1254
1254
|
return currentText;
|
1255
1255
|
}
|
1256
1256
|
const remainingChars = targetText.length - currentText.length;
|
1257
|
-
const
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
const newText = targetText.slice(0, currentText.length + charsToAdd);
|
1257
|
+
const baseTimePerChar = Math.min(5, 250 / remainingChars);
|
1258
|
+
let charsToAdd = 0;
|
1259
|
+
while (timeToConsume >= baseTimePerChar && charsToAdd < remainingChars) {
|
1260
|
+
charsToAdd++;
|
1261
|
+
timeToConsume -= baseTimePerChar;
|
1262
|
+
}
|
1264
1263
|
this.animationFrameId = requestAnimationFrame(this.animate);
|
1264
|
+
if (charsToAdd === 0) {
|
1265
|
+
return currentText;
|
1266
|
+
}
|
1267
|
+
const newText = targetText.slice(0, currentText.length + charsToAdd);
|
1268
|
+
this.lastUpdateTime = currentTime - timeToConsume;
|
1265
1269
|
return newText;
|
1266
1270
|
});
|
1267
1271
|
};
|
@@ -1272,6 +1276,7 @@ var useSmooth = (text, smooth = false) => {
|
|
1272
1276
|
new TextStreamAnimator(setDisplayedText)
|
1273
1277
|
);
|
1274
1278
|
(0, import_react35.useEffect)(() => {
|
1279
|
+
console.log("smooth", smooth);
|
1275
1280
|
if (!smooth) {
|
1276
1281
|
animatorRef.stop();
|
1277
1282
|
return;
|
@@ -1284,6 +1289,7 @@ var useSmooth = (text, smooth = false) => {
|
|
1284
1289
|
}
|
1285
1290
|
animatorRef.targetText = text;
|
1286
1291
|
animatorRef.start();
|
1292
|
+
console.log("animating");
|
1287
1293
|
}, [animatorRef, smooth, text]);
|
1288
1294
|
(0, import_react35.useEffect)(() => {
|
1289
1295
|
return () => {
|
@@ -1295,7 +1301,7 @@ var useSmooth = (text, smooth = false) => {
|
|
1295
1301
|
|
1296
1302
|
// src/primitives/contentPart/ContentPartText.tsx
|
1297
1303
|
var import_jsx_runtime14 = require("react/jsx-runtime");
|
1298
|
-
var ContentPartPrimitiveText = (0, import_react36.forwardRef)(({ smooth, ...rest }, forwardedRef) => {
|
1304
|
+
var ContentPartPrimitiveText = (0, import_react36.forwardRef)(({ smooth = true, ...rest }, forwardedRef) => {
|
1299
1305
|
const {
|
1300
1306
|
status,
|
1301
1307
|
part: { text }
|