@alquimia-ai/ui 1.2.3 → 1.2.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/components/hooks/index.js +41 -32
- package/dist/components/hooks/index.js.map +1 -1
- package/dist/components/hooks/index.mjs +42 -33
- package/dist/components/hooks/index.mjs.map +1 -1
- package/dist/components/molecules/index.js +41 -32
- package/dist/components/molecules/index.js.map +1 -1
- package/dist/components/molecules/index.mjs +42 -33
- package/dist/components/molecules/index.mjs.map +1 -1
- package/dist/components/organisms/index.js +41 -32
- package/dist/components/organisms/index.js.map +1 -1
- package/dist/components/organisms/index.mjs +42 -33
- package/dist/components/organisms/index.mjs.map +1 -1
- package/dist/index.js +41 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -33
- package/dist/index.mjs.map +1 -1
- package/dist/package.json +136 -0
- package/package.json +20 -3
|
@@ -2455,48 +2455,57 @@ var React32 = __toESM(require("react"));
|
|
|
2455
2455
|
// src/components/hooks/use-text-streaming.ts
|
|
2456
2456
|
var import_react8 = require("react");
|
|
2457
2457
|
var CHAR_DELAY = 25;
|
|
2458
|
-
var PUNCTUATION_DELAY =
|
|
2459
|
-
var PUNCTUATION_MARKS = [".", "!", "?", ";", ":"];
|
|
2458
|
+
var PUNCTUATION_DELAY = 400;
|
|
2460
2459
|
function useTextStreaming(content, shouldStream, handleIsTextStreaming) {
|
|
2461
|
-
const [
|
|
2462
|
-
const
|
|
2460
|
+
const [displayedText, setDisplayedText] = (0, import_react8.useState)("");
|
|
2461
|
+
const contentRef = (0, import_react8.useRef)(content);
|
|
2462
|
+
const indexRef = (0, import_react8.useRef)(0);
|
|
2463
|
+
const timerRef = (0, import_react8.useRef)(null);
|
|
2463
2464
|
const hasStartedStreaming = (0, import_react8.useRef)(false);
|
|
2464
|
-
const getDelayForChar = (text, position) => {
|
|
2465
|
-
if (position === 0) return CHAR_DELAY;
|
|
2466
|
-
const previousChar = text[position - 1] || "";
|
|
2467
|
-
const isEllipsis = text.slice(position - 1, position + 2) === "...";
|
|
2468
|
-
if (isEllipsis) {
|
|
2469
|
-
return CHAR_DELAY;
|
|
2470
|
-
}
|
|
2471
|
-
return PUNCTUATION_MARKS.includes(previousChar) ? PUNCTUATION_DELAY : CHAR_DELAY;
|
|
2472
|
-
};
|
|
2473
2465
|
(0, import_react8.useEffect)(() => {
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
return;
|
|
2466
|
+
contentRef.current = content;
|
|
2467
|
+
if (hasStartedStreaming.current && !timerRef.current && indexRef.current < contentRef.current.length) {
|
|
2468
|
+
typeNext();
|
|
2478
2469
|
}
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
if (
|
|
2482
|
-
const
|
|
2483
|
-
|
|
2484
|
-
|
|
2470
|
+
}, [content]);
|
|
2471
|
+
const typeNext = (0, import_react8.useCallback)(() => {
|
|
2472
|
+
if (indexRef.current < contentRef.current.length) {
|
|
2473
|
+
const nextChar = contentRef.current.charAt(indexRef.current);
|
|
2474
|
+
setDisplayedText((prev) => prev + nextChar);
|
|
2475
|
+
indexRef.current++;
|
|
2476
|
+
const delay = /[.!?;:]/.test(nextChar) ? PUNCTUATION_DELAY : CHAR_DELAY;
|
|
2477
|
+
timerRef.current = setTimeout(() => {
|
|
2478
|
+
timerRef.current = null;
|
|
2479
|
+
typeNext();
|
|
2485
2480
|
}, delay);
|
|
2486
2481
|
} else {
|
|
2487
2482
|
handleIsTextStreaming?.(false);
|
|
2488
2483
|
}
|
|
2484
|
+
}, []);
|
|
2485
|
+
(0, import_react8.useEffect)(() => {
|
|
2486
|
+
if (!shouldStream && !hasStartedStreaming.current) {
|
|
2487
|
+
setDisplayedText(contentRef.current);
|
|
2488
|
+
indexRef.current = contentRef.current.length;
|
|
2489
|
+
if (timerRef.current) {
|
|
2490
|
+
clearTimeout(timerRef.current);
|
|
2491
|
+
timerRef.current = null;
|
|
2492
|
+
}
|
|
2493
|
+
handleIsTextStreaming?.(false);
|
|
2494
|
+
} else {
|
|
2495
|
+
if (indexRef.current < contentRef.current.length && !timerRef.current) {
|
|
2496
|
+
handleIsTextStreaming?.(true);
|
|
2497
|
+
hasStartedStreaming.current = true;
|
|
2498
|
+
typeNext();
|
|
2499
|
+
}
|
|
2500
|
+
}
|
|
2489
2501
|
return () => {
|
|
2490
|
-
if (
|
|
2502
|
+
if (timerRef.current) {
|
|
2503
|
+
clearTimeout(timerRef.current);
|
|
2504
|
+
timerRef.current = null;
|
|
2505
|
+
}
|
|
2491
2506
|
};
|
|
2492
|
-
}, [
|
|
2493
|
-
|
|
2494
|
-
displayedContent,
|
|
2495
|
-
shouldStream,
|
|
2496
|
-
getDelayForChar,
|
|
2497
|
-
handleIsTextStreaming
|
|
2498
|
-
]);
|
|
2499
|
-
return displayedContent;
|
|
2507
|
+
}, [shouldStream, typeNext]);
|
|
2508
|
+
return displayedText;
|
|
2500
2509
|
}
|
|
2501
2510
|
|
|
2502
2511
|
// src/components/molecules/call-out.tsx
|