@assistant-ui/react 0.3.2 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
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
- this.lastUpdateTime = currentTime;
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 charsToAdd = Math.max(
1199
- 1,
1200
- Math.floor(
1201
- remainingChars * (1 - Math.pow(this.decayFactor, deltaTime))
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
  };
@@ -1236,7 +1240,7 @@ var useSmooth = (text, smooth = false) => {
1236
1240
 
1237
1241
  // src/primitives/contentPart/ContentPartText.tsx
1238
1242
  import { jsx as jsx14 } from "react/jsx-runtime";
1239
- var ContentPartPrimitiveText = forwardRef7(({ smooth, ...rest }, forwardedRef) => {
1243
+ var ContentPartPrimitiveText = forwardRef7(({ smooth = true, ...rest }, forwardedRef) => {
1240
1244
  const {
1241
1245
  status,
1242
1246
  part: { text }