@assistant-ui/react 0.3.2 → 0.3.4

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 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
- this.lastUpdateTime = currentTime;
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 charsToAdd = Math.max(
1258
- 1,
1259
- Math.floor(
1260
- remainingChars * (1 - Math.pow(this.decayFactor, deltaTime))
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
  };
@@ -1295,7 +1299,7 @@ var useSmooth = (text, smooth = false) => {
1295
1299
 
1296
1300
  // src/primitives/contentPart/ContentPartText.tsx
1297
1301
  var import_jsx_runtime14 = require("react/jsx-runtime");
1298
- var ContentPartPrimitiveText = (0, import_react36.forwardRef)(({ smooth, ...rest }, forwardedRef) => {
1302
+ var ContentPartPrimitiveText = (0, import_react36.forwardRef)(({ smooth = true, ...rest }, forwardedRef) => {
1299
1303
  const {
1300
1304
  status,
1301
1305
  part: { text }