@chayns-components/typewriter 5.0.19 → 5.0.23
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/lib/cjs/components/typewriter/Typewriter.js +29 -21
- package/lib/cjs/components/typewriter/Typewriter.js.map +1 -1
- package/lib/cjs/components/typewriter/utils.js +48 -17
- package/lib/cjs/components/typewriter/utils.js.map +1 -1
- package/lib/esm/components/typewriter/Typewriter.js +30 -22
- package/lib/esm/components/typewriter/Typewriter.js.map +1 -1
- package/lib/esm/components/typewriter/utils.js +46 -16
- package/lib/esm/components/typewriter/utils.js.map +1 -1
- package/lib/types/components/typewriter/Typewriter.d.ts +5 -4
- package/lib/types/components/typewriter/utils.d.ts +17 -6
- package/package.json +3 -3
|
@@ -49,8 +49,8 @@ const Typewriter = ({
|
|
|
49
49
|
const [shouldPreventBlinkingCursor, setShouldPreventBlinkingCursor] = (0, _react.useState)(false);
|
|
50
50
|
const [isResetAnimationActive, setIsResetAnimationActive] = (0, _react.useState)(false);
|
|
51
51
|
const [shouldStopAnimation, setShouldStopAnimation] = (0, _react.useState)(false);
|
|
52
|
-
const
|
|
53
|
-
const
|
|
52
|
+
const autoSpeed = (0, _react.useRef)();
|
|
53
|
+
const autoSteps = (0, _react.useRef)(animationSteps);
|
|
54
54
|
const functions = (0, _chaynsApi.useFunctions)();
|
|
55
55
|
const values = (0, _chaynsApi.useValues)();
|
|
56
56
|
const colorScheme = (0, _core.useColorScheme)();
|
|
@@ -64,11 +64,6 @@ const Typewriter = ({
|
|
|
64
64
|
setHasRenderedChildrenOnce(true);
|
|
65
65
|
}
|
|
66
66
|
}, [hasRenderedChildrenOnce]);
|
|
67
|
-
(0, _react.useEffect)(() => {
|
|
68
|
-
if (animationSteps > 0 && !shouldCalcAutoSpeed) {
|
|
69
|
-
setAutoSteps(animationSteps);
|
|
70
|
-
}
|
|
71
|
-
}, [animationSteps, shouldCalcAutoSpeed]);
|
|
72
67
|
const sortedChildren = (0, _react.useMemo)(() => Array.isArray(children) && shouldSortChildrenRandomly ? (0, _utils.shuffleArray)(children) : children, [children, shouldSortChildrenRandomly]);
|
|
73
68
|
const areMultipleChildrenGiven = Array.isArray(sortedChildren);
|
|
74
69
|
const childrenCount = areMultipleChildrenGiven ? sortedChildren.length : 1;
|
|
@@ -109,25 +104,38 @@ const Typewriter = ({
|
|
|
109
104
|
}, sortedChildren)))) : sortedChildren;
|
|
110
105
|
}, [areMultipleChildrenGiven, colorScheme === null || colorScheme === void 0 || (_colorScheme$designSe5 = colorScheme.designSettings) === null || _colorScheme$designSe5 === void 0 ? void 0 : _colorScheme$designSe5.color, colorScheme === null || colorScheme === void 0 || (_colorScheme$designSe6 = colorScheme.designSettings) === null || _colorScheme$designSe6 === void 0 ? void 0 : _colorScheme$designSe6.colorMode, currentChildrenIndex, functions, sortedChildren, values]);
|
|
111
106
|
const charactersCount = (0, _react.useMemo)(() => (0, _utils.getCharactersCount)(textContent), [textContent]);
|
|
107
|
+
const chunkIntervalExponentialMovingAverage = (0, _react.useRef)({
|
|
108
|
+
lastTimestamp: undefined,
|
|
109
|
+
lastLength: charactersCount,
|
|
110
|
+
ema: charactersCount / (autoSpeedBaseFactor / 1000)
|
|
111
|
+
});
|
|
112
112
|
const [shownCharCount, setShownCharCount] = (0, _react.useState)(charactersCount > 0 ? 0 : textContent.length);
|
|
113
113
|
const currentPosition = (0, _react.useRef)(0);
|
|
114
|
+
(0, _react.useEffect)(() => {
|
|
115
|
+
if (shouldUseResetAnimation) {
|
|
116
|
+
chunkIntervalExponentialMovingAverage.current = {
|
|
117
|
+
ema: charactersCount / (autoSpeedBaseFactor / 1000),
|
|
118
|
+
lastLength: charactersCount
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
chunkIntervalExponentialMovingAverage.current = (0, _utils.updateChunkStreamingSpeedEMA)({
|
|
122
|
+
currentLength: charactersCount,
|
|
123
|
+
state: chunkIntervalExponentialMovingAverage.current
|
|
124
|
+
});
|
|
125
|
+
}, [autoSpeedBaseFactor, charactersCount, shouldUseResetAnimation]);
|
|
114
126
|
(0, _react.useEffect)(() => {
|
|
115
127
|
if (!shouldCalcAutoSpeed) {
|
|
116
|
-
|
|
117
|
-
|
|
128
|
+
autoSpeed.current = undefined;
|
|
129
|
+
autoSteps.current = animationSteps;
|
|
118
130
|
return;
|
|
119
131
|
}
|
|
120
132
|
const {
|
|
121
133
|
speed: calculatedAutoSpeed,
|
|
122
134
|
steps
|
|
123
|
-
} = (0, _utils.calculateAutoSpeed)(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
});
|
|
128
|
-
setAutoSpeed(calculatedAutoSpeed);
|
|
129
|
-
setAutoSteps(steps);
|
|
130
|
-
}, [animationSteps, autoSpeedBaseFactor, charactersCount, shouldCalcAutoSpeed]);
|
|
135
|
+
} = (0, _utils.calculateAutoSpeed)(chunkIntervalExponentialMovingAverage.current.ema);
|
|
136
|
+
autoSpeed.current = calculatedAutoSpeed;
|
|
137
|
+
autoSteps.current = steps;
|
|
138
|
+
}, [animationSteps, charactersCount, shouldCalcAutoSpeed]);
|
|
131
139
|
const isAnimatingText = shownCharCount < textContent.length || shouldForceCursorAnimation || areMultipleChildrenGiven || textContent.length === 0;
|
|
132
140
|
const handleClick = (0, _react.useCallback)(event => {
|
|
133
141
|
event.stopPropagation();
|
|
@@ -152,7 +160,7 @@ const Typewriter = ({
|
|
|
152
160
|
}
|
|
153
161
|
interval = window.setInterval(() => {
|
|
154
162
|
setShownCharCount(prevState => {
|
|
155
|
-
const nextState = prevState - autoSteps;
|
|
163
|
+
const nextState = prevState - autoSteps.current;
|
|
156
164
|
currentPosition.current = nextState;
|
|
157
165
|
if (nextState === 0) {
|
|
158
166
|
window.clearInterval(interval);
|
|
@@ -179,7 +187,7 @@ const Typewriter = ({
|
|
|
179
187
|
}
|
|
180
188
|
const runTypingInterval = () => {
|
|
181
189
|
setShownCharCount(prevState => {
|
|
182
|
-
let nextState = Math.min(prevState + autoSteps, charactersCount);
|
|
190
|
+
let nextState = Math.min(prevState + autoSteps.current, charactersCount);
|
|
183
191
|
if (nextState >= charactersCount && !shouldWaitForContent) {
|
|
184
192
|
window.clearInterval(interval);
|
|
185
193
|
if (cursorType === _cursor.CursorType.Thin) {
|
|
@@ -210,7 +218,7 @@ const Typewriter = ({
|
|
|
210
218
|
return nextState;
|
|
211
219
|
});
|
|
212
220
|
};
|
|
213
|
-
interval = window.setInterval(runTypingInterval, autoSpeed ?? speed);
|
|
221
|
+
interval = window.setInterval(runTypingInterval, autoSpeed.current ?? speed);
|
|
214
222
|
};
|
|
215
223
|
if (startDelay) {
|
|
216
224
|
setTimeout(startTypingAnimation, startDelay);
|
|
@@ -221,7 +229,7 @@ const Typewriter = ({
|
|
|
221
229
|
return () => {
|
|
222
230
|
window.clearInterval(interval);
|
|
223
231
|
};
|
|
224
|
-
}, [
|
|
232
|
+
}, [areMultipleChildrenGiven, autoSteps, charactersCount, cursorType, handleSetNextChildrenIndex, isResetAnimationActive, nextTextDelay, onResetAnimationEnd, onResetAnimationStart, onTypingAnimationEnd, onTypingAnimationStart, resetDelay, resetSpeed, shouldStopAnimation, shouldUseResetAnimation, shouldWaitForContent, speed, startDelay, textContent.length]);
|
|
225
233
|
(0, _react.useEffect)(() => {
|
|
226
234
|
if (!isAnimatingText && typeof onFinish === 'function') {
|
|
227
235
|
onFinish();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Typewriter.js","names":["_core","require","_chaynsApi","_react","_interopRequireWildcard","_reactDom","_server","_cursor","_speed","_AnimatedTypewriterText","_interopRequireDefault","_Typewriter","_utils","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","useIsomorphicLayoutEffect","window","useLayoutEffect","useEffect","Typewriter","children","cursorType","CursorType","Default","nextTextDelay","TypewriterDelay","Medium","onFinish","onResetAnimationEnd","animationSteps","onResetAnimationStart","onTypingAnimationEnd","onTypingAnimationStart","pseudoChildren","resetDelay","shouldForceCursorAnimation","shouldHideCursor","shouldRemainSingleLine","shouldSortChildrenRandomly","shouldUseAnimationHeight","shouldUseResetAnimation","shouldWaitForContent","speed","TypewriterSpeed","resetSpeed","startDelay","None","textStyle","shouldCalcAutoSpeed","autoSpeedBaseFactor","_colorScheme$designSe5","_colorScheme$designSe6","_colorScheme$designSe9","_colorScheme$designSe0","currentChildrenIndex","setCurrentChildrenIndex","useState","hasRenderedChildrenOnce","setHasRenderedChildrenOnce","shouldPreventBlinkingCursor","setShouldPreventBlinkingCursor","isResetAnimationActive","setIsResetAnimationActive","shouldStopAnimation","setShouldStopAnimation","autoSpeed","setAutoSpeed","autoSteps","setAutoSteps","functions","useFunctions","values","useValues","colorScheme","useColorScheme","sortedChildren","useMemo","Array","isArray","shuffleArray","areMultipleChildrenGiven","childrenCount","length","textContent","_colorScheme$designSe3","_colorScheme$designSe4","currentChildren","_colorScheme$designSe","_colorScheme$designSe2","React","isValidElement","renderToString","createElement","ChaynsProvider","data","isModule","ColorSchemeProvider","color","designSettings","colorMode","style","display","className","charactersCount","getCharactersCount","shownCharCount","setShownCharCount","currentPosition","useRef","undefined","calculatedAutoSpeed","steps","calculateAutoSpeed","fullTextLength","current","baseSpeedFactor","isAnimatingText","handleClick","useCallback","event","stopPropagation","preventDefault","handleSetNextChildrenIndex","newIndex","interval","setInterval","prevState","nextState","clearInterval","setTimeout","startTypingAnimation","Thin","runTypingInterval","Math","min","shownText","getSubTextFromHTML","pseudoTextHTML","_colorScheme$designSe7","_colorScheme$designSe8","pseudoText","StyledTypewriter","$cursorType","onClick","$isAnimatingText","$shouldHideCursor","$shouldPreventBlinkAnimation","StyledTypewriterText","$shouldRemainSingleLine","dangerouslySetInnerHTML","__html","StyledTypewriterPseudoText","createPortal","position","visibility","document","body","displayName","_default","exports"],"sources":["../../../../src/components/typewriter/Typewriter.tsx"],"sourcesContent":["import { ColorSchemeProvider, useColorScheme } from '@chayns-components/core';\nimport { ChaynsProvider, useFunctions, useValues } from 'chayns-api';\nimport React, {\n FC,\n ReactElement,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { renderToString } from 'react-dom/server';\nimport { CSSPropertiesWithVars } from 'styled-components/dist/types';\nimport { CursorType } from '../../types/cursor';\nimport { TypewriterDelay, TypewriterSpeed } from '../../types/speed';\nimport AnimatedTypewriterText from './AnimatedTypewriterText';\nimport {\n StyledTypewriter,\n StyledTypewriterPseudoText,\n StyledTypewriterText,\n} from './Typewriter.styles';\nimport { calculateAutoSpeed, getCharactersCount, getSubTextFromHTML, shuffleArray } from './utils';\n\nconst useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport type TypewriterProps = {\n /**\n * The number of characters that will be animated per animation cycle.\n */\n animationSteps?: number;\n /**\n * The base speed factor to calculate the animation speed.\n */\n autoSpeedBaseFactor?: number;\n /**\n * The text to type\n */\n children: ReactElement | ReactElement[] | string | string[];\n /**\n * The type of the cursor. Use the CursorType enum for this prop.\n */\n cursorType?: CursorType;\n /**\n * The delay in milliseconds before the next text is shown.\n * This prop is only used if multiple texts are given.\n */\n nextTextDelay?: TypewriterDelay;\n /**\n * Function that is executed when the typewriter animation has finished. This function will not\n * be executed if multiple texts are used.\n */\n onFinish?: VoidFunction;\n /**\n * Function that is executed when the reset animation has finished. This function will not be\n * executed if `shouldUseResetAnimation` is not set to `true`.\n */\n onResetAnimationEnd?: VoidFunction;\n /**\n * Function that is executed when the reset animation has started. This function will not be\n * executed if `shouldUseResetAnimation` is not set to `true`.\n */\n onResetAnimationStart?: VoidFunction;\n /**\n * Function that is executed when the typing animation has finished. If multiple texts are given,\n * this function will be executed for each text.\n */\n onTypingAnimationEnd?: VoidFunction;\n /**\n * Function that is executed when the typing animation has started. If multiple texts are given,\n * this function will be executed for each text.\n */\n onTypingAnimationStart?: VoidFunction;\n /**\n * Pseudo-element to be rendered invisible during animation to define the size of the element\n * for the typewriter effect. By default, the \"children\" is used for this purpose.\n */\n pseudoChildren?: ReactElement | string;\n /**\n * Waiting time in milliseconds before the typewriter resets the text.\n * This prop is only used if multiple texts are given.\n */\n resetDelay?: TypewriterDelay;\n /**\n * The reset speed of the animation. Use the TypewriterSpeed enum for this prop.\n */\n resetSpeed?: TypewriterSpeed | number;\n /**\n * Specifies whether the cursor should be forced to animate even if no text is currently animated.\n */\n shouldForceCursorAnimation?: boolean;\n /**\n * Specifies whether the cursor should be hidden\n */\n shouldHideCursor?: boolean;\n /**\n * Whether the content should remain a single line.\n */\n shouldRemainSingleLine?: boolean;\n /**\n * Specifies whether the children should be sorted randomly if there are multiple texts.\n * This makes the typewriter start with a different text each time and also changes them\n * in a random order.\n */\n shouldSortChildrenRandomly?: boolean;\n /**\n * Specifies whether the animation should use its full height or the height of the current\n * chunk.\n */\n shouldUseAnimationHeight?: boolean;\n /**\n * Whether the animation speed should be calculated with the chunk interval.\n */\n shouldCalcAutoSpeed?: boolean;\n /**\n * Specifies whether the reset of the text should be animated with a backspace animation for\n * multiple texts.\n */\n shouldUseResetAnimation?: boolean;\n /**\n * Whether the typewriter should wait for new content\n */\n shouldWaitForContent?: boolean;\n /**\n * The speed of the animation. Use the TypewriterSpeed enum for this prop.\n */\n speed?: TypewriterSpeed | number;\n /**\n * The delay in milliseconds before the typewriter starts typing.\n */\n startDelay?: TypewriterDelay;\n /**\n * The style of the typewriter text element\n */\n textStyle?: CSSPropertiesWithVars;\n};\n\nconst Typewriter: FC<TypewriterProps> = ({\n children,\n cursorType = CursorType.Default,\n nextTextDelay = TypewriterDelay.Medium,\n onFinish,\n onResetAnimationEnd,\n animationSteps = 1,\n onResetAnimationStart,\n onTypingAnimationEnd,\n onTypingAnimationStart,\n pseudoChildren,\n resetDelay = TypewriterDelay.Medium,\n shouldForceCursorAnimation = false,\n shouldHideCursor = false,\n shouldRemainSingleLine = false,\n shouldSortChildrenRandomly = false,\n shouldUseAnimationHeight = false,\n shouldUseResetAnimation = false,\n shouldWaitForContent,\n speed = TypewriterSpeed.Medium,\n resetSpeed = speed,\n startDelay = TypewriterDelay.None,\n textStyle,\n shouldCalcAutoSpeed = false,\n autoSpeedBaseFactor = 2000,\n}) => {\n const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);\n const [hasRenderedChildrenOnce, setHasRenderedChildrenOnce] = useState(false);\n const [shouldPreventBlinkingCursor, setShouldPreventBlinkingCursor] = useState(false);\n const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);\n const [shouldStopAnimation, setShouldStopAnimation] = useState(false);\n const [autoSpeed, setAutoSpeed] = useState<number>();\n const [autoSteps, setAutoSteps] = useState(animationSteps);\n\n const functions = useFunctions();\n const values = useValues();\n\n const colorScheme = useColorScheme();\n\n useIsomorphicLayoutEffect(() => {\n if (children) {\n setHasRenderedChildrenOnce(false);\n }\n }, [children]);\n\n useEffect(() => {\n if (!hasRenderedChildrenOnce) {\n setHasRenderedChildrenOnce(true);\n }\n }, [hasRenderedChildrenOnce]);\n\n useEffect(() => {\n if (animationSteps > 0 && !shouldCalcAutoSpeed) {\n setAutoSteps(animationSteps);\n }\n }, [animationSteps, shouldCalcAutoSpeed]);\n\n const sortedChildren = useMemo(\n () =>\n Array.isArray(children) && shouldSortChildrenRandomly\n ? shuffleArray<ReactElement | string>(children)\n : children,\n [children, shouldSortChildrenRandomly],\n );\n\n const areMultipleChildrenGiven = Array.isArray(sortedChildren);\n const childrenCount = areMultipleChildrenGiven ? sortedChildren.length : 1;\n\n const textContent = useMemo(() => {\n if (areMultipleChildrenGiven) {\n const currentChildren = sortedChildren[currentChildrenIndex];\n\n if (currentChildren) {\n return React.isValidElement(currentChildren)\n ? renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider\n color={colorScheme?.designSettings?.color}\n colorMode={colorScheme?.designSettings?.colorMode}\n style={{ display: 'inline' }}\n >\n <span className=\"notranslate\">{currentChildren}</span>\n </ColorSchemeProvider>\n </ChaynsProvider>,\n )\n : (currentChildren as string);\n }\n\n return '';\n }\n\n return React.isValidElement(sortedChildren)\n ? renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider\n color={colorScheme?.designSettings?.color}\n colorMode={colorScheme?.designSettings?.colorMode}\n style={{ display: 'inline' }}\n >\n <span className=\"notranslate\">{sortedChildren}</span>\n </ColorSchemeProvider>\n </ChaynsProvider>,\n )\n : (sortedChildren as string);\n }, [\n areMultipleChildrenGiven,\n colorScheme?.designSettings?.color,\n colorScheme?.designSettings?.colorMode,\n currentChildrenIndex,\n functions,\n sortedChildren,\n values,\n ]);\n\n const charactersCount = useMemo(() => getCharactersCount(textContent), [textContent]);\n\n const [shownCharCount, setShownCharCount] = useState(\n charactersCount > 0 ? 0 : textContent.length,\n );\n\n const currentPosition = useRef(0);\n\n useEffect(() => {\n if (!shouldCalcAutoSpeed) {\n setAutoSpeed(undefined);\n setAutoSteps(animationSteps);\n\n return;\n }\n\n const { speed: calculatedAutoSpeed, steps } = calculateAutoSpeed({\n fullTextLength: charactersCount,\n currentPosition: currentPosition.current,\n baseSpeedFactor: autoSpeedBaseFactor,\n });\n\n setAutoSpeed(calculatedAutoSpeed);\n setAutoSteps(steps);\n }, [animationSteps, autoSpeedBaseFactor, charactersCount, shouldCalcAutoSpeed]);\n\n const isAnimatingText =\n shownCharCount < textContent.length ||\n shouldForceCursorAnimation ||\n areMultipleChildrenGiven ||\n textContent.length === 0;\n\n const handleClick = useCallback((event: React.MouseEvent) => {\n event.stopPropagation();\n event.preventDefault();\n\n setShouldStopAnimation(true);\n }, []);\n\n const handleSetNextChildrenIndex = useCallback(\n () =>\n setCurrentChildrenIndex(() => {\n let newIndex = currentChildrenIndex + 1;\n\n if (newIndex > childrenCount - 1) {\n newIndex = 0;\n }\n\n return newIndex;\n }),\n [childrenCount, currentChildrenIndex],\n );\n\n useEffect(() => {\n let interval: number | undefined;\n\n if (shouldStopAnimation || charactersCount === 0) {\n setShownCharCount(textContent.length);\n currentPosition.current = textContent.length;\n } else if (isResetAnimationActive) {\n if (typeof onResetAnimationStart === 'function') {\n onResetAnimationStart();\n }\n\n interval = window.setInterval(() => {\n setShownCharCount((prevState) => {\n const nextState = prevState - autoSteps;\n currentPosition.current = nextState;\n\n if (nextState === 0) {\n window.clearInterval(interval);\n\n if (typeof onResetAnimationEnd === 'function') {\n onResetAnimationEnd();\n }\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n setIsResetAnimationActive(false);\n handleSetNextChildrenIndex();\n }, nextTextDelay);\n }\n }\n\n return nextState;\n });\n }, resetSpeed);\n } else {\n const startTypingAnimation = () => {\n if (cursorType === CursorType.Thin) {\n setShouldPreventBlinkingCursor(true);\n }\n\n if (typeof onTypingAnimationStart === 'function') {\n onTypingAnimationStart();\n }\n\n const runTypingInterval = () => {\n setShownCharCount((prevState) => {\n let nextState = Math.min(prevState + autoSteps, charactersCount);\n\n if (nextState >= charactersCount && !shouldWaitForContent) {\n window.clearInterval(interval);\n\n if (cursorType === CursorType.Thin) {\n setShouldPreventBlinkingCursor(false);\n }\n\n if (typeof onTypingAnimationEnd === 'function') {\n onTypingAnimationEnd();\n }\n\n /**\n * At this point, the next value for \"shownCharCount\" is deliberately set to\n * the length of the textContent to correctly display HTML elements\n * after the last letter.\n */\n nextState = textContent.length;\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n if (shouldUseResetAnimation) {\n setIsResetAnimationActive(true);\n } else {\n setShownCharCount(0);\n setTimeout(handleSetNextChildrenIndex, nextTextDelay);\n }\n }, resetDelay);\n }\n }\n\n currentPosition.current = nextState;\n\n return nextState;\n });\n };\n\n interval = window.setInterval(runTypingInterval, autoSpeed ?? speed);\n };\n\n if (startDelay) {\n setTimeout(startTypingAnimation, startDelay);\n } else {\n startTypingAnimation();\n }\n }\n\n return () => {\n window.clearInterval(interval);\n };\n }, [\n resetSpeed,\n speed,\n resetDelay,\n childrenCount,\n charactersCount,\n textContent.length,\n shouldStopAnimation,\n shouldWaitForContent,\n isResetAnimationActive,\n shouldUseResetAnimation,\n areMultipleChildrenGiven,\n handleSetNextChildrenIndex,\n nextTextDelay,\n startDelay,\n onResetAnimationStart,\n onResetAnimationEnd,\n onTypingAnimationStart,\n onTypingAnimationEnd,\n cursorType,\n autoSpeed,\n autoSteps,\n ]);\n\n useEffect(() => {\n if (!isAnimatingText && typeof onFinish === 'function') {\n onFinish();\n }\n }, [isAnimatingText, onFinish]);\n\n const shownText = useMemo(\n () => getSubTextFromHTML(textContent, shownCharCount),\n [shownCharCount, textContent],\n );\n\n const pseudoTextHTML = useMemo(() => {\n if (pseudoChildren) {\n const pseudoText = React.isValidElement(pseudoChildren)\n ? renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider\n color={colorScheme?.designSettings?.color}\n colorMode={colorScheme?.designSettings?.colorMode}\n style={{ display: 'inline' }}\n >\n {pseudoChildren}\n </ColorSchemeProvider>\n </ChaynsProvider>,\n )\n : (pseudoChildren as string);\n\n if (shouldUseAnimationHeight) {\n return getSubTextFromHTML(pseudoText, shownCharCount);\n }\n\n return pseudoText;\n }\n\n if (shouldUseAnimationHeight && textContent) {\n return getSubTextFromHTML(textContent, shownCharCount);\n }\n\n return textContent || '​';\n }, [\n colorScheme?.designSettings?.color,\n colorScheme?.designSettings?.colorMode,\n functions,\n pseudoChildren,\n shouldUseAnimationHeight,\n shownCharCount,\n textContent,\n values,\n ]);\n\n return useMemo(\n () => (\n <StyledTypewriter\n $cursorType={cursorType}\n onClick={isAnimatingText ? handleClick : undefined}\n $isAnimatingText={isAnimatingText}\n $shouldHideCursor={shouldHideCursor}\n $shouldPreventBlinkAnimation={shouldPreventBlinkingCursor}\n >\n {isAnimatingText ? (\n <AnimatedTypewriterText\n shouldHideCursor={shouldHideCursor}\n shouldRemainSingleLine={shouldRemainSingleLine}\n shownText={shownText}\n textStyle={textStyle}\n />\n ) : (\n <StyledTypewriterText\n className=\"notranslate\"\n $shouldRemainSingleLine={shouldRemainSingleLine}\n dangerouslySetInnerHTML={\n typeof sortedChildren === 'string' ? { __html: shownText } : undefined\n }\n style={textStyle}\n >\n {typeof sortedChildren !== 'string' ? sortedChildren : undefined}\n </StyledTypewriterText>\n )}\n {isAnimatingText && (\n <StyledTypewriterPseudoText\n $isAnimatingText={isAnimatingText}\n $shouldHideCursor={shouldHideCursor}\n dangerouslySetInnerHTML={{ __html: pseudoTextHTML }}\n />\n )}\n {/*\n The following is needed because some components like the CodeHighlighter will not render correct\n if the element is not rendered on a client before...\n */}\n {!hasRenderedChildrenOnce &&\n createPortal(\n <div style={{ position: 'absolute', visibility: 'hidden' }}>\n {children}\n </div>,\n document.body,\n )}\n </StyledTypewriter>\n ),\n [\n children,\n cursorType,\n handleClick,\n hasRenderedChildrenOnce,\n isAnimatingText,\n pseudoTextHTML,\n shouldHideCursor,\n shouldPreventBlinkingCursor,\n shouldRemainSingleLine,\n shownText,\n sortedChildren,\n textStyle,\n ],\n );\n};\n\nTypewriter.displayName = 'Typewriter';\n\nexport default Typewriter;\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,uBAAA,CAAAH,OAAA;AAUA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AAEA,IAAAM,OAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,uBAAA,GAAAC,sBAAA,CAAAT,OAAA;AACA,IAAAU,WAAA,GAAAV,OAAA;AAKA,IAAAW,MAAA,GAAAX,OAAA;AAAmG,SAAAS,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAT,wBAAAS,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAA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uBAAuB,iBACrB,IAAA+F,sBAAY,eACRtK,MAAA,CAAAY,OAAA,CAAA8F,aAAA;IAAKQ,KAAK,EAAE;MAAEqD,QAAQ,EAAE,UAAU;MAAEC,UAAU,EAAE;IAAS;EAAE,GACtDtI,QACA,CAAC,EACNuI,QAAQ,CAACC,IACb,CACU,CACrB,EACD,CACIxI,QAAQ,EACRC,UAAU,EACVgG,WAAW,EACX5D,uBAAuB,EACvB2D,eAAe,EACfqB,cAAc,EACdrG,gBAAgB,EAChBuB,2BAA2B,EAC3BtB,sBAAsB,EACtBkG,SAAS,EACT5D,cAAc,EACd5B,SAAS,CAEjB,CAAC;AACL,CAAC;AAED5B,UAAU,CAAC0I,WAAW,GAAG,YAAY;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAjK,OAAA,GAEvBqB,UAAU","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"Typewriter.js","names":["_core","require","_chaynsApi","_react","_interopRequireWildcard","_reactDom","_server","_cursor","_speed","_AnimatedTypewriterText","_interopRequireDefault","_Typewriter","_utils","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","useIsomorphicLayoutEffect","window","useLayoutEffect","useEffect","Typewriter","children","cursorType","CursorType","Default","nextTextDelay","TypewriterDelay","Medium","onFinish","onResetAnimationEnd","animationSteps","onResetAnimationStart","onTypingAnimationEnd","onTypingAnimationStart","pseudoChildren","resetDelay","shouldForceCursorAnimation","shouldHideCursor","shouldRemainSingleLine","shouldSortChildrenRandomly","shouldUseAnimationHeight","shouldUseResetAnimation","shouldWaitForContent","speed","TypewriterSpeed","resetSpeed","startDelay","None","textStyle","shouldCalcAutoSpeed","autoSpeedBaseFactor","_colorScheme$designSe5","_colorScheme$designSe6","_colorScheme$designSe9","_colorScheme$designSe0","currentChildrenIndex","setCurrentChildrenIndex","useState","hasRenderedChildrenOnce","setHasRenderedChildrenOnce","shouldPreventBlinkingCursor","setShouldPreventBlinkingCursor","isResetAnimationActive","setIsResetAnimationActive","shouldStopAnimation","setShouldStopAnimation","autoSpeed","useRef","autoSteps","functions","useFunctions","values","useValues","colorScheme","useColorScheme","sortedChildren","useMemo","Array","isArray","shuffleArray","areMultipleChildrenGiven","childrenCount","length","textContent","_colorScheme$designSe3","_colorScheme$designSe4","currentChildren","_colorScheme$designSe","_colorScheme$designSe2","React","isValidElement","renderToString","createElement","ChaynsProvider","data","isModule","ColorSchemeProvider","color","designSettings","colorMode","style","display","className","charactersCount","getCharactersCount","chunkIntervalExponentialMovingAverage","lastTimestamp","undefined","lastLength","ema","shownCharCount","setShownCharCount","currentPosition","current","updateChunkStreamingSpeedEMA","currentLength","state","calculatedAutoSpeed","steps","calculateAutoSpeed","isAnimatingText","handleClick","useCallback","event","stopPropagation","preventDefault","handleSetNextChildrenIndex","newIndex","interval","setInterval","prevState","nextState","clearInterval","setTimeout","startTypingAnimation","Thin","runTypingInterval","Math","min","shownText","getSubTextFromHTML","pseudoTextHTML","_colorScheme$designSe7","_colorScheme$designSe8","pseudoText","StyledTypewriter","$cursorType","onClick","$isAnimatingText","$shouldHideCursor","$shouldPreventBlinkAnimation","StyledTypewriterText","$shouldRemainSingleLine","dangerouslySetInnerHTML","__html","StyledTypewriterPseudoText","createPortal","position","visibility","document","body","displayName","_default","exports"],"sources":["../../../../src/components/typewriter/Typewriter.tsx"],"sourcesContent":["import { ColorSchemeProvider, useColorScheme } from '@chayns-components/core';\nimport { ChaynsProvider, useFunctions, useValues } from 'chayns-api';\nimport React, {\n FC,\n ReactElement,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { renderToString } from 'react-dom/server';\nimport { CSSPropertiesWithVars } from 'styled-components/dist/types';\nimport { CursorType } from '../../types/cursor';\nimport { TypewriterDelay, TypewriterSpeed } from '../../types/speed';\nimport AnimatedTypewriterText from './AnimatedTypewriterText';\nimport {\n StyledTypewriter,\n StyledTypewriterPseudoText,\n StyledTypewriterText,\n} from './Typewriter.styles';\nimport {\n calculateAutoSpeed,\n ChunkStreamingSpeedState,\n getCharactersCount,\n getSubTextFromHTML,\n shuffleArray,\n updateChunkStreamingSpeedEMA,\n} from './utils';\n\nconst useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport type TypewriterProps = {\n /**\n * The number of characters that will be animated per animation cycle.\n */\n animationSteps?: number;\n /**\n * The text to type\n */\n children: ReactElement | ReactElement[] | string | string[];\n /**\n * The type of the cursor. Use the CursorType enum for this prop.\n */\n cursorType?: CursorType;\n /**\n * The delay in milliseconds before the next text is shown.\n * This prop is only used if multiple texts are given.\n */\n nextTextDelay?: TypewriterDelay;\n /**\n * Function that is executed when the typewriter animation has finished. This function will not\n * be executed if multiple texts are used.\n */\n onFinish?: VoidFunction;\n /**\n * Function that is executed when the reset animation has finished. This function will not be\n * executed if `shouldUseResetAnimation` is not set to `true`.\n */\n onResetAnimationEnd?: VoidFunction;\n /**\n * Function that is executed when the reset animation has started. This function will not be\n * executed if `shouldUseResetAnimation` is not set to `true`.\n */\n onResetAnimationStart?: VoidFunction;\n /**\n * Function that is executed when the typing animation has finished. If multiple texts are given,\n * this function will be executed for each text.\n */\n onTypingAnimationEnd?: VoidFunction;\n /**\n * Function that is executed when the typing animation has started. If multiple texts are given,\n * this function will be executed for each text.\n */\n onTypingAnimationStart?: VoidFunction;\n /**\n * Pseudo-element to be rendered invisible during animation to define the size of the element\n * for the typewriter effect. By default, the \"children\" is used for this purpose.\n */\n pseudoChildren?: ReactElement | string;\n /**\n * Waiting time in milliseconds before the typewriter resets the text.\n * This prop is only used if multiple texts are given.\n */\n resetDelay?: TypewriterDelay;\n /**\n * The reset speed of the animation. Use the TypewriterSpeed enum for this prop.\n */\n resetSpeed?: TypewriterSpeed | number;\n /**\n * Specifies whether the cursor should be forced to animate even if no text is currently animated.\n */\n shouldForceCursorAnimation?: boolean;\n /**\n * Specifies whether the cursor should be hidden\n */\n shouldHideCursor?: boolean;\n /**\n * Whether the content should remain a single line.\n */\n shouldRemainSingleLine?: boolean;\n /**\n * Specifies whether the children should be sorted randomly if there are multiple texts.\n * This makes the typewriter start with a different text each time and also changes them\n * in a random order.\n */\n shouldSortChildrenRandomly?: boolean;\n /**\n * Specifies whether the animation should use its full height or the height of the current\n * chunk.\n */\n shouldUseAnimationHeight?: boolean;\n /**\n * Whether the animation speed should be calculated with the chunk interval.\n */\n shouldCalcAutoSpeed?: boolean;\n /**\n * Sets how long the animation should last when `shouldCalcAutoSpeed` is enabled in milliseconds.\n * When chunks are streamed, this value will only be used for the initial speed and then change to the speed characters are added at\n */\n autoSpeedBaseFactor?: number;\n /**\n * Specifies whether the reset of the text should be animated with a backspace animation for\n * multiple texts.\n */\n shouldUseResetAnimation?: boolean;\n /**\n * Whether the typewriter should wait for new content\n */\n shouldWaitForContent?: boolean;\n /**\n * The speed of the animation. Use the TypewriterSpeed enum for this prop.\n */\n speed?: TypewriterSpeed | number;\n /**\n * The delay in milliseconds before the typewriter starts typing.\n */\n startDelay?: TypewriterDelay;\n /**\n * The style of the typewriter text element\n */\n textStyle?: CSSPropertiesWithVars;\n};\n\nconst Typewriter: FC<TypewriterProps> = ({\n children,\n cursorType = CursorType.Default,\n nextTextDelay = TypewriterDelay.Medium,\n onFinish,\n onResetAnimationEnd,\n animationSteps = 1,\n onResetAnimationStart,\n onTypingAnimationEnd,\n onTypingAnimationStart,\n pseudoChildren,\n resetDelay = TypewriterDelay.Medium,\n shouldForceCursorAnimation = false,\n shouldHideCursor = false,\n shouldRemainSingleLine = false,\n shouldSortChildrenRandomly = false,\n shouldUseAnimationHeight = false,\n shouldUseResetAnimation = false,\n shouldWaitForContent,\n speed = TypewriterSpeed.Medium,\n resetSpeed = speed,\n startDelay = TypewriterDelay.None,\n textStyle,\n shouldCalcAutoSpeed = false,\n autoSpeedBaseFactor = 2000,\n}) => {\n const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);\n const [hasRenderedChildrenOnce, setHasRenderedChildrenOnce] = useState(false);\n const [shouldPreventBlinkingCursor, setShouldPreventBlinkingCursor] = useState(false);\n const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);\n const [shouldStopAnimation, setShouldStopAnimation] = useState(false);\n const autoSpeed = useRef<number>();\n const autoSteps = useRef<number>(animationSteps);\n\n const functions = useFunctions();\n const values = useValues();\n\n const colorScheme = useColorScheme();\n\n useIsomorphicLayoutEffect(() => {\n if (children) {\n setHasRenderedChildrenOnce(false);\n }\n }, [children]);\n\n useEffect(() => {\n if (!hasRenderedChildrenOnce) {\n setHasRenderedChildrenOnce(true);\n }\n }, [hasRenderedChildrenOnce]);\n\n const sortedChildren = useMemo(\n () =>\n Array.isArray(children) && shouldSortChildrenRandomly\n ? shuffleArray<ReactElement | string>(children)\n : children,\n [children, shouldSortChildrenRandomly],\n );\n\n const areMultipleChildrenGiven = Array.isArray(sortedChildren);\n const childrenCount = areMultipleChildrenGiven ? sortedChildren.length : 1;\n\n const textContent = useMemo(() => {\n if (areMultipleChildrenGiven) {\n const currentChildren = sortedChildren[currentChildrenIndex];\n\n if (currentChildren) {\n return React.isValidElement(currentChildren)\n ? renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider\n color={colorScheme?.designSettings?.color}\n colorMode={colorScheme?.designSettings?.colorMode}\n style={{ display: 'inline' }}\n >\n <span className=\"notranslate\">{currentChildren}</span>\n </ColorSchemeProvider>\n </ChaynsProvider>,\n )\n : (currentChildren as string);\n }\n\n return '';\n }\n\n return React.isValidElement(sortedChildren)\n ? renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider\n color={colorScheme?.designSettings?.color}\n colorMode={colorScheme?.designSettings?.colorMode}\n style={{ display: 'inline' }}\n >\n <span className=\"notranslate\">{sortedChildren}</span>\n </ColorSchemeProvider>\n </ChaynsProvider>,\n )\n : (sortedChildren as string);\n }, [\n areMultipleChildrenGiven,\n colorScheme?.designSettings?.color,\n colorScheme?.designSettings?.colorMode,\n currentChildrenIndex,\n functions,\n sortedChildren,\n values,\n ]);\n\n const charactersCount = useMemo(() => getCharactersCount(textContent), [textContent]);\n\n const chunkIntervalExponentialMovingAverage = useRef<ChunkStreamingSpeedState>({\n lastTimestamp: undefined,\n lastLength: charactersCount,\n ema: charactersCount / (autoSpeedBaseFactor / 1000),\n });\n\n const [shownCharCount, setShownCharCount] = useState(\n charactersCount > 0 ? 0 : textContent.length,\n );\n\n const currentPosition = useRef(0);\n\n useEffect(() => {\n if (shouldUseResetAnimation) {\n chunkIntervalExponentialMovingAverage.current = {\n ema: charactersCount / (autoSpeedBaseFactor / 1000),\n lastLength: charactersCount,\n };\n }\n chunkIntervalExponentialMovingAverage.current = updateChunkStreamingSpeedEMA({\n currentLength: charactersCount,\n state: chunkIntervalExponentialMovingAverage.current,\n });\n }, [autoSpeedBaseFactor, charactersCount, shouldUseResetAnimation]);\n\n useEffect(() => {\n if (!shouldCalcAutoSpeed) {\n autoSpeed.current = undefined;\n autoSteps.current = animationSteps;\n return;\n }\n\n const { speed: calculatedAutoSpeed, steps } = calculateAutoSpeed(\n chunkIntervalExponentialMovingAverage.current.ema,\n );\n autoSpeed.current = calculatedAutoSpeed;\n autoSteps.current = steps;\n }, [animationSteps, charactersCount, shouldCalcAutoSpeed]);\n\n const isAnimatingText =\n shownCharCount < textContent.length ||\n shouldForceCursorAnimation ||\n areMultipleChildrenGiven ||\n textContent.length === 0;\n\n const handleClick = useCallback((event: React.MouseEvent) => {\n event.stopPropagation();\n event.preventDefault();\n\n setShouldStopAnimation(true);\n }, []);\n\n const handleSetNextChildrenIndex = useCallback(\n () =>\n setCurrentChildrenIndex(() => {\n let newIndex = currentChildrenIndex + 1;\n\n if (newIndex > childrenCount - 1) {\n newIndex = 0;\n }\n\n return newIndex;\n }),\n [childrenCount, currentChildrenIndex],\n );\n\n useEffect(() => {\n let interval: number | undefined;\n\n if (shouldStopAnimation || charactersCount === 0) {\n setShownCharCount(textContent.length);\n currentPosition.current = textContent.length;\n } else if (isResetAnimationActive) {\n if (typeof onResetAnimationStart === 'function') {\n onResetAnimationStart();\n }\n\n interval = window.setInterval(() => {\n setShownCharCount((prevState) => {\n const nextState = prevState - autoSteps.current;\n currentPosition.current = nextState;\n\n if (nextState === 0) {\n window.clearInterval(interval);\n\n if (typeof onResetAnimationEnd === 'function') {\n onResetAnimationEnd();\n }\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n setIsResetAnimationActive(false);\n handleSetNextChildrenIndex();\n }, nextTextDelay);\n }\n }\n\n return nextState;\n });\n }, resetSpeed);\n } else {\n const startTypingAnimation = () => {\n if (cursorType === CursorType.Thin) {\n setShouldPreventBlinkingCursor(true);\n }\n\n if (typeof onTypingAnimationStart === 'function') {\n onTypingAnimationStart();\n }\n\n const runTypingInterval = () => {\n setShownCharCount((prevState) => {\n let nextState = Math.min(prevState + autoSteps.current, charactersCount);\n\n if (nextState >= charactersCount && !shouldWaitForContent) {\n window.clearInterval(interval);\n\n if (cursorType === CursorType.Thin) {\n setShouldPreventBlinkingCursor(false);\n }\n\n if (typeof onTypingAnimationEnd === 'function') {\n onTypingAnimationEnd();\n }\n\n /**\n * At this point, the next value for \"shownCharCount\" is deliberately set to\n * the length of the textContent to correctly display HTML elements\n * after the last letter.\n */\n nextState = textContent.length;\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n if (shouldUseResetAnimation) {\n setIsResetAnimationActive(true);\n } else {\n setShownCharCount(0);\n setTimeout(handleSetNextChildrenIndex, nextTextDelay);\n }\n }, resetDelay);\n }\n }\n\n currentPosition.current = nextState;\n\n return nextState;\n });\n };\n interval = window.setInterval(runTypingInterval, autoSpeed.current ?? speed);\n };\n\n if (startDelay) {\n setTimeout(startTypingAnimation, startDelay);\n } else {\n startTypingAnimation();\n }\n }\n\n return () => {\n window.clearInterval(interval);\n };\n }, [\n areMultipleChildrenGiven,\n autoSteps,\n charactersCount,\n cursorType,\n handleSetNextChildrenIndex,\n isResetAnimationActive,\n nextTextDelay,\n onResetAnimationEnd,\n onResetAnimationStart,\n onTypingAnimationEnd,\n onTypingAnimationStart,\n resetDelay,\n resetSpeed,\n shouldStopAnimation,\n shouldUseResetAnimation,\n shouldWaitForContent,\n speed,\n startDelay,\n textContent.length,\n ]);\n\n useEffect(() => {\n if (!isAnimatingText && typeof onFinish === 'function') {\n onFinish();\n }\n }, [isAnimatingText, onFinish]);\n\n const shownText = useMemo(\n () => getSubTextFromHTML(textContent, shownCharCount),\n [shownCharCount, textContent],\n );\n\n const pseudoTextHTML = useMemo(() => {\n if (pseudoChildren) {\n const pseudoText = React.isValidElement(pseudoChildren)\n ? renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider\n color={colorScheme?.designSettings?.color}\n colorMode={colorScheme?.designSettings?.colorMode}\n style={{ display: 'inline' }}\n >\n {pseudoChildren}\n </ColorSchemeProvider>\n </ChaynsProvider>,\n )\n : (pseudoChildren as string);\n\n if (shouldUseAnimationHeight) {\n return getSubTextFromHTML(pseudoText, shownCharCount);\n }\n\n return pseudoText;\n }\n\n if (shouldUseAnimationHeight && textContent) {\n return getSubTextFromHTML(textContent, shownCharCount);\n }\n\n return textContent || '​';\n }, [\n colorScheme?.designSettings?.color,\n colorScheme?.designSettings?.colorMode,\n functions,\n pseudoChildren,\n shouldUseAnimationHeight,\n shownCharCount,\n textContent,\n values,\n ]);\n\n return useMemo(\n () => (\n <StyledTypewriter\n $cursorType={cursorType}\n onClick={isAnimatingText ? handleClick : undefined}\n $isAnimatingText={isAnimatingText}\n $shouldHideCursor={shouldHideCursor}\n $shouldPreventBlinkAnimation={shouldPreventBlinkingCursor}\n >\n {isAnimatingText ? (\n <AnimatedTypewriterText\n shouldHideCursor={shouldHideCursor}\n shouldRemainSingleLine={shouldRemainSingleLine}\n shownText={shownText}\n textStyle={textStyle}\n />\n ) : (\n <StyledTypewriterText\n className=\"notranslate\"\n $shouldRemainSingleLine={shouldRemainSingleLine}\n dangerouslySetInnerHTML={\n typeof sortedChildren === 'string' ? { __html: shownText } : undefined\n }\n style={textStyle}\n >\n {typeof sortedChildren !== 'string' ? sortedChildren : undefined}\n </StyledTypewriterText>\n )}\n {isAnimatingText && (\n <StyledTypewriterPseudoText\n $isAnimatingText={isAnimatingText}\n $shouldHideCursor={shouldHideCursor}\n dangerouslySetInnerHTML={{ __html: pseudoTextHTML }}\n />\n )}\n {/*\n The following is needed because some components like the CodeHighlighter will not render correct\n if the element is not rendered on a client before...\n */}\n {!hasRenderedChildrenOnce &&\n createPortal(\n <div style={{ position: 'absolute', visibility: 'hidden' }}>\n {children}\n </div>,\n document.body,\n )}\n </StyledTypewriter>\n ),\n [\n children,\n cursorType,\n handleClick,\n hasRenderedChildrenOnce,\n isAnimatingText,\n pseudoTextHTML,\n shouldHideCursor,\n shouldPreventBlinkingCursor,\n shouldRemainSingleLine,\n shownText,\n sortedChildren,\n textStyle,\n ],\n );\n};\n\nTypewriter.displayName = 'Typewriter';\n\nexport default Typewriter;\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,uBAAA,CAAAH,OAAA;AAUA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AAEA,IAAAM,OAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,uBAAA,GAAAC,sBAAA,CAAAT,OAAA;AACA,IAAAU,WAAA,GAAAV,OAAA;AAKA,IAAAW,MAAA,GAAAX,OAAA;AAOiB,SAAAS,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAT,wBAAAS,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAb,uBAAA,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AU,GAEhB,OAAO2B,cAAc,KAAK,QAAQ,GAAGA,cAAc,GAAGgC,SACrC,CACzB,EACAa,eAAe,iBACZrI,MAAA,CAAAY,OAAA,CAAA6F,aAAA,CAACjG,WAAA,CAAAgK,0BAA0B;IACvBP,gBAAgB,EAAE5B,eAAgB;IAClC6B,iBAAiB,EAAEhH,gBAAiB;IACpCoH,uBAAuB,EAAE;MAAEC,MAAM,EAAEb;IAAe;EAAE,CACvD,CACJ,EAKA,CAACnF,uBAAuB,iBACrB,IAAAkG,sBAAY,eACRzK,MAAA,CAAAY,OAAA,CAAA6F,aAAA;IAAKQ,KAAK,EAAE;MAAEyD,QAAQ,EAAE,UAAU;MAAEC,UAAU,EAAE;IAAS;EAAE,GACtDzI,QACA,CAAC,EACN0I,QAAQ,CAACC,IACb,CACU,CACrB,EACD,CACI3I,QAAQ,EACRC,UAAU,EACVmG,WAAW,EACX/D,uBAAuB,EACvB8D,eAAe,EACfqB,cAAc,EACdxG,gBAAgB,EAChBuB,2BAA2B,EAC3BtB,sBAAsB,EACtBqG,SAAS,EACThE,cAAc,EACd3B,SAAS,CAEjB,CAAC;AACL,CAAC;AAED5B,UAAU,CAAC6I,WAAW,GAAG,YAAY;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAApK,OAAA,GAEvBqB,UAAU","ignoreList":[]}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.shuffleArray = exports.getSubTextFromHTML = exports.getCharactersCount = exports.calculateAutoSpeed = void 0;
|
|
6
|
+
exports.updateChunkStreamingSpeedEMA = exports.shuffleArray = exports.getSubTextFromHTML = exports.getCharactersCount = exports.calculateEMA = exports.calculateAutoSpeed = void 0;
|
|
7
|
+
var _speed = require("../../types/speed");
|
|
7
8
|
/**
|
|
8
9
|
* Returns a substring of an HTML string while preserving HTML structure.
|
|
9
10
|
*
|
|
@@ -155,27 +156,57 @@ const shuffleArray = array => {
|
|
|
155
156
|
return result;
|
|
156
157
|
};
|
|
157
158
|
exports.shuffleArray = shuffleArray;
|
|
158
|
-
const calculateAutoSpeed =
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
if (
|
|
159
|
+
const calculateAutoSpeed = ema => {
|
|
160
|
+
// nested timer calls are clamped to a 4ms minimum
|
|
161
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout#reasons_for_longer_delays_than_specified
|
|
162
|
+
const MINIMUM_TIMEOUT = 4;
|
|
163
|
+
if (ema <= 0) {
|
|
164
|
+
return {
|
|
165
|
+
speed: _speed.TypewriterSpeed.ExtraSlow,
|
|
166
|
+
steps: 1
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
const msPerChar = 1000 / ema;
|
|
170
|
+
if (msPerChar >= MINIMUM_TIMEOUT) {
|
|
170
171
|
return {
|
|
171
|
-
speed:
|
|
172
|
-
steps:
|
|
172
|
+
speed: msPerChar,
|
|
173
|
+
steps: 1
|
|
173
174
|
};
|
|
174
175
|
}
|
|
176
|
+
const steps = Math.max(1, MINIMUM_TIMEOUT / msPerChar);
|
|
175
177
|
return {
|
|
176
|
-
speed,
|
|
177
|
-
steps
|
|
178
|
+
speed: MINIMUM_TIMEOUT,
|
|
179
|
+
steps
|
|
178
180
|
};
|
|
179
181
|
};
|
|
180
182
|
exports.calculateAutoSpeed = calculateAutoSpeed;
|
|
183
|
+
const calculateEMA = ({
|
|
184
|
+
currentEMA,
|
|
185
|
+
newValue,
|
|
186
|
+
alpha = 0.25
|
|
187
|
+
}) => alpha * newValue + (1 - alpha) * currentEMA;
|
|
188
|
+
exports.calculateEMA = calculateEMA;
|
|
189
|
+
const updateChunkStreamingSpeedEMA = ({
|
|
190
|
+
currentLength,
|
|
191
|
+
state
|
|
192
|
+
}) => {
|
|
193
|
+
const now = Date.now();
|
|
194
|
+
const deltaTime = now - ((state === null || state === void 0 ? void 0 : state.lastTimestamp) ?? now);
|
|
195
|
+
if (deltaTime <= 0) return {
|
|
196
|
+
...state,
|
|
197
|
+
lastTimestamp: now
|
|
198
|
+
};
|
|
199
|
+
const deltaLength = currentLength - state.lastLength;
|
|
200
|
+
const charsPerSecond = Math.max(0, deltaLength / deltaTime * 1000);
|
|
201
|
+
const newEMA = calculateEMA({
|
|
202
|
+
currentEMA: state.ema,
|
|
203
|
+
newValue: charsPerSecond
|
|
204
|
+
});
|
|
205
|
+
return {
|
|
206
|
+
lastTimestamp: now,
|
|
207
|
+
lastLength: currentLength,
|
|
208
|
+
ema: newEMA
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
exports.updateChunkStreamingSpeedEMA = updateChunkStreamingSpeedEMA;
|
|
181
212
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["getSubTextFromHTML","html","length","div","document","createElement","innerHTML","text","currLength","escapeText","value","replace","escapeAttr","String","VOID_ELEMENTS","Set","traverse","node","nodeType","textContent","nodeText","remaining","substring","element","nodeName","toLowerCase","attributes","attribute","name","isVoid","has","i","childNodes","childNode","exports","getCharactersCount","count","trim","Array","from","forEach","shuffleArray","array","result","j","Math","floor","random","calculateAutoSpeed","fullTextLength","currentPosition","baseSpeedFactor","MIN_SPEED","MAX_SPEED","remainingLength","speed","min","steps"],"sources":["../../../../src/components/typewriter/utils.ts"],"sourcesContent":["/**\n * Returns a substring of an HTML string while preserving HTML structure.\n *\n * Core rules:\n * - Element nodes are re-serialized as tags (start/end) to keep structure.\n * - Text nodes are always HTML-escaped on output. This prevents that previously\n * escaped text (like \"<div>\") turns into real tags during the DOM round trip.\n * - Attribute values are HTML-escaped on output.\n * - Void elements are serialized without closing tags.\n * - For TWIGNORE/TW-IGNORE elements, the innerHTML is passed through so that\n * their content (including real HTML) remains untouched.\n * - On early cutoff (once the length limit is reached), already opened tags are\n * properly closed to keep the result valid HTML.\n *\n * Note on length counting:\n * - The length is based on the decoded textContent length (as the DOM provides),\n * not on byte length nor escaped entity length. This mirrors how the text is perceived.\n *\n * @param html The input HTML string; may contain a mix of real HTML and already escaped HTML.\n * @param length The maximum number of text characters (based on textContent) to include.\n * @returns A valid HTML string containing up to the specified number of text characters,\n * preserving HTML tags and keeping escaped text escaped.\n */\nexport const getSubTextFromHTML = (html: string, length: number): string => {\n const div = document.createElement('div');\n\n div.innerHTML = html;\n\n let text = '';\n let currLength = 0;\n\n // Escape text node content to ensure that decoded \"<\" and \">\" do not become real tags.\n const escapeText = (value: string): string =>\n value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');\n\n // Escape attribute values safely.\n const escapeAttr = (value: string): string =>\n String(value)\n .replace(/&/g, '&')\n .replace(/\"/g, '"')\n .replace(/</g, '<')\n .replace(/>/g, '>');\n\n // HTML void elements (must not have closing tags)\n const VOID_ELEMENTS = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n ]);\n\n // Traverses nodes and appends to \"text\".\n // Returns false to signal \"stop traversal\" once the length limit is reached.\n const traverse = (node: Node): boolean => {\n // Text node\n if (node.nodeType === 3 && typeof node.textContent === 'string') {\n const nodeText = node.textContent;\n const remaining = length - currLength;\n\n if (remaining <= 0) {\n return false;\n }\n\n if (nodeText.length <= remaining) {\n // Always escape text before writing to output\n text += escapeText(nodeText);\n currLength += nodeText.length;\n } else {\n // Cut the text and stop traversal\n text += escapeText(nodeText.substring(0, remaining));\n currLength += remaining;\n return false;\n }\n\n return true;\n }\n\n // Element node\n if (node.nodeType === 1) {\n const element = node as Element;\n\n // Pass-through for TWIGNORE/TW-IGNORE: keep their HTML as-is.\n if (element.nodeName === 'TWIGNORE' || element.nodeName === 'TW-IGNORE') {\n // element.innerHTML serializes children; escaped text stays escaped,\n // real HTML stays HTML — exactly what we want here.\n text += element.innerHTML;\n return true;\n }\n\n const nodeName = element.nodeName.toLowerCase();\n\n // Serialize attributes safely\n let attributes = '';\n // @ts-expect-error: attributes is a NodeListOf<Attr>\n // eslint-disable-next-line no-restricted-syntax\n for (const attribute of element.attributes) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/restrict-template-expressions,@typescript-eslint/no-unsafe-argument\n attributes += ` ${attribute.name}=\"${escapeAttr(attribute.value)}\"`;\n }\n\n // Open tag\n text += `<${nodeName}${attributes}>`;\n\n // Void elements: do not recurse children and do not emit a closing tag\n const isVoid = VOID_ELEMENTS.has(nodeName);\n if (!isVoid) {\n // Recurse through children until limit is reached\n for (let i = 0; i < element.childNodes.length; i++) {\n const childNode = element.childNodes[i];\n if (childNode && !traverse(childNode)) {\n // On early stop: close this tag to keep valid HTML, then bubble stop.\n text += `</${nodeName}>`;\n return false;\n }\n }\n\n // Close tag after all children\n text += `</${nodeName}>`;\n }\n\n return true;\n }\n\n // Other node types (comments, etc.) are ignored for text length\n return true;\n };\n\n // Traverse top-level children\n for (let i = 0; i < div.childNodes.length; i++) {\n const childNode = div.childNodes[i];\n if (childNode && !traverse(childNode)) {\n return text;\n }\n }\n\n return text;\n};\n\nexport const getCharactersCount = (html: string): number => {\n const div = document.createElement('div');\n\n div.innerHTML = html;\n\n let count = 0;\n\n const traverse = (node: Node): void => {\n if (node.nodeName === 'TWIGNORE') {\n count += 1;\n } else if (node.nodeType === 3 && typeof node.textContent === 'string') {\n count += node.textContent.trim().length;\n } else if (node.nodeType === 1) {\n if (node.nodeName === 'CODE' && node.textContent !== null) {\n count += node.textContent.length;\n\n return;\n }\n\n Array.from(node.childNodes).forEach(traverse);\n }\n };\n\n Array.from(div.childNodes).forEach(traverse);\n\n return count;\n};\n\nexport const shuffleArray = <T>(array: T[]): T[] => {\n const result = Array.from(array);\n\n for (let i = result.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n [result[i], result[j]] = [result[j]!, result[i]!];\n }\n\n return result;\n};\n\ninterface CalculateAutoSpeedProps {\n fullTextLength: number;\n currentPosition: number;\n baseSpeedFactor: number;\n}\n\nexport const calculateAutoSpeed = ({\n fullTextLength,\n currentPosition,\n baseSpeedFactor,\n}: CalculateAutoSpeedProps): { speed: number; steps: number } => {\n const MIN_SPEED = 1;\n const MAX_SPEED = 10;\n\n const remainingLength = fullTextLength - currentPosition;\n\n // Calculate the speed with the remaining text length and the baseSpeedFactor\n const speed = Math.min(baseSpeedFactor / remainingLength, MAX_SPEED);\n\n if (speed < MIN_SPEED) {\n return { speed: 1, steps: 2 };\n }\n\n return { speed, steps: 1 };\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,kBAAkB,GAAGA,CAACC,IAAY,EAAEC,MAAc,KAAa;EACxE,MAAMC,GAAG,GAAGC,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAEzCF,GAAG,CAACG,SAAS,GAAGL,IAAI;EAEpB,IAAIM,IAAI,GAAG,EAAE;EACb,IAAIC,UAAU,GAAG,CAAC;;EAElB;EACA,MAAMC,UAAU,GAAIC,KAAa,IAC7BA,KAAK,CAACC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAACA,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAACA,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;;EAE5E;EACA,MAAMC,UAAU,GAAIF,KAAa,IAC7BG,MAAM,CAACH,KAAK,CAAC,CACRC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CACtBA,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CACvBA,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CACrBA,OAAO,CAAC,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C;;IAE7C;IACA,CAACY,MAAM,CAACZ,CAAC,CAAC,EAAEY,MAAM,CAACC,CAAC,CAAC,CAAC,GAAG,CAACD,MAAM,CAACC,CAAC,CAAC,EAAGD,MAAM,CAACZ,CAAC,CAAC,CAAE;EACrD;EAEA,OAAOY,MAAM;AACjB,CAAC;AAACT,OAAA,CAAAO,YAAA,GAAAA,YAAA;AAQK,MAAMO,kBAAkB,GAAGA,CAAC;EAC/BC,cAAc;EACdC,eAAe;EACfC;AACqB,CAAC,KAAuC;EAC7D,MAAMC,SAAS,GAAG,CAAC;EACnB,MAAMC,SAAS,GAAG,EAAE;EAEpB,MAAMC,eAAe,GAAGL,cAAc,GAAGC,eAAe;;EAExD;EACA,MAAMK,KAAK,GAAGV,IAAI,CAACW,GAAG,CAACL,eAAe,GAAGG,eAAe,EAAED,SAAS,CAAC;EAEpE,IAAIE,KAAK,GAAGH,SAAS,EAAE;IACnB,OAAO;MAAEG,KAAK,EAAE,CAAC;MAAEE,KAAK,EAAE;IAAE,CAAC;EACjC;EAEA,OAAO;IAAEF,KAAK;IAAEE,KAAK,EAAE;EAAE,CAAC;AAC9B,CAAC;AAACvB,OAAA,CAAAc,kBAAA,GAAAA,kBAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"utils.js","names":["_speed","require","getSubTextFromHTML","html","length","div","document","createElement","innerHTML","text","currLength","escapeText","value","replace","escapeAttr","String","VOID_ELEMENTS","Set","traverse","node","nodeType","textContent","nodeText","remaining","substring","element","nodeName","toLowerCase","attributes","attribute","name","isVoid","has","i","childNodes","childNode","exports","getCharactersCount","count","trim","Array","from","forEach","shuffleArray","array","result","j","Math","floor","random","calculateAutoSpeed","ema","MINIMUM_TIMEOUT","speed","TypewriterSpeed","ExtraSlow","steps","msPerChar","max","calculateEMA","currentEMA","newValue","alpha","updateChunkStreamingSpeedEMA","currentLength","state","now","Date","deltaTime","lastTimestamp","deltaLength","lastLength","charsPerSecond","newEMA"],"sources":["../../../../src/components/typewriter/utils.ts"],"sourcesContent":["import { TypewriterSpeed } from '../../types/speed';\n\n/**\n * Returns a substring of an HTML string while preserving HTML structure.\n *\n * Core rules:\n * - Element nodes are re-serialized as tags (start/end) to keep structure.\n * - Text nodes are always HTML-escaped on output. This prevents that previously\n * escaped text (like \"<div>\") turns into real tags during the DOM round trip.\n * - Attribute values are HTML-escaped on output.\n * - Void elements are serialized without closing tags.\n * - For TWIGNORE/TW-IGNORE elements, the innerHTML is passed through so that\n * their content (including real HTML) remains untouched.\n * - On early cutoff (once the length limit is reached), already opened tags are\n * properly closed to keep the result valid HTML.\n *\n * Note on length counting:\n * - The length is based on the decoded textContent length (as the DOM provides),\n * not on byte length nor escaped entity length. This mirrors how the text is perceived.\n *\n * @param html The input HTML string; may contain a mix of real HTML and already escaped HTML.\n * @param length The maximum number of text characters (based on textContent) to include.\n * @returns A valid HTML string containing up to the specified number of text characters,\n * preserving HTML tags and keeping escaped text escaped.\n */\nexport const getSubTextFromHTML = (html: string, length: number): string => {\n const div = document.createElement('div');\n\n div.innerHTML = html;\n\n let text = '';\n let currLength = 0;\n\n // Escape text node content to ensure that decoded \"<\" and \">\" do not become real tags.\n const escapeText = (value: string): string =>\n value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');\n\n // Escape attribute values safely.\n const escapeAttr = (value: string): string =>\n String(value)\n .replace(/&/g, '&')\n .replace(/\"/g, '"')\n .replace(/</g, '<')\n .replace(/>/g, '>');\n\n // HTML void elements (must not have closing tags)\n const VOID_ELEMENTS = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n ]);\n\n // Traverses nodes and appends to \"text\".\n // Returns false to signal \"stop traversal\" once the length limit is reached.\n const traverse = (node: Node): boolean => {\n // Text node\n if (node.nodeType === 3 && typeof node.textContent === 'string') {\n const nodeText = node.textContent;\n const remaining = length - currLength;\n\n if (remaining <= 0) {\n return false;\n }\n\n if (nodeText.length <= remaining) {\n // Always escape text before writing to output\n text += escapeText(nodeText);\n currLength += nodeText.length;\n } else {\n // Cut the text and stop traversal\n text += escapeText(nodeText.substring(0, remaining));\n currLength += remaining;\n return false;\n }\n\n return true;\n }\n\n // Element node\n if (node.nodeType === 1) {\n const element = node as Element;\n\n // Pass-through for TWIGNORE/TW-IGNORE: keep their HTML as-is.\n if (element.nodeName === 'TWIGNORE' || element.nodeName === 'TW-IGNORE') {\n // element.innerHTML serializes children; escaped text stays escaped,\n // real HTML stays HTML — exactly what we want here.\n text += element.innerHTML;\n return true;\n }\n\n const nodeName = element.nodeName.toLowerCase();\n\n // Serialize attributes safely\n let attributes = '';\n // @ts-expect-error: attributes is a NodeListOf<Attr>\n // eslint-disable-next-line no-restricted-syntax\n for (const attribute of element.attributes) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/restrict-template-expressions,@typescript-eslint/no-unsafe-argument\n attributes += ` ${attribute.name}=\"${escapeAttr(attribute.value)}\"`;\n }\n\n // Open tag\n text += `<${nodeName}${attributes}>`;\n\n // Void elements: do not recurse children and do not emit a closing tag\n const isVoid = VOID_ELEMENTS.has(nodeName);\n if (!isVoid) {\n // Recurse through children until limit is reached\n for (let i = 0; i < element.childNodes.length; i++) {\n const childNode = element.childNodes[i];\n if (childNode && !traverse(childNode)) {\n // On early stop: close this tag to keep valid HTML, then bubble stop.\n text += `</${nodeName}>`;\n return false;\n }\n }\n\n // Close tag after all children\n text += `</${nodeName}>`;\n }\n\n return true;\n }\n\n // Other node types (comments, etc.) are ignored for text length\n return true;\n };\n\n // Traverse top-level children\n for (let i = 0; i < div.childNodes.length; i++) {\n const childNode = div.childNodes[i];\n if (childNode && !traverse(childNode)) {\n return text;\n }\n }\n\n return text;\n};\n\nexport const getCharactersCount = (html: string): number => {\n const div = document.createElement('div');\n\n div.innerHTML = html;\n\n let count = 0;\n\n const traverse = (node: Node): void => {\n if (node.nodeName === 'TWIGNORE') {\n count += 1;\n } else if (node.nodeType === 3 && typeof node.textContent === 'string') {\n count += node.textContent.trim().length;\n } else if (node.nodeType === 1) {\n if (node.nodeName === 'CODE' && node.textContent !== null) {\n count += node.textContent.length;\n\n return;\n }\n\n Array.from(node.childNodes).forEach(traverse);\n }\n };\n\n Array.from(div.childNodes).forEach(traverse);\n\n return count;\n};\n\nexport const shuffleArray = <T>(array: T[]): T[] => {\n const result = Array.from(array);\n\n for (let i = result.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n [result[i], result[j]] = [result[j]!, result[i]!];\n }\n\n return result;\n};\n\nexport const calculateAutoSpeed = (ema: number): { speed: number; steps: number } => {\n // nested timer calls are clamped to a 4ms minimum\n // https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout#reasons_for_longer_delays_than_specified\n const MINIMUM_TIMEOUT = 4;\n\n if (ema <= 0) {\n return { speed: TypewriterSpeed.ExtraSlow, steps: 1 };\n }\n\n const msPerChar = 1000 / ema;\n\n if (msPerChar >= MINIMUM_TIMEOUT) {\n return { speed: msPerChar, steps: 1 };\n }\n\n const steps = Math.max(1, MINIMUM_TIMEOUT / msPerChar);\n return { speed: MINIMUM_TIMEOUT, steps };\n};\n\ninterface CalculateEMAProps {\n currentEMA: number;\n newValue: number;\n alpha?: number;\n}\n\nexport const calculateEMA = ({ currentEMA, newValue, alpha = 0.25 }: CalculateEMAProps): number =>\n alpha * newValue + (1 - alpha) * currentEMA;\n\nexport interface ChunkStreamingSpeedState {\n lastTimestamp?: number;\n lastLength: number;\n ema: number;\n}\n\ninterface ChunkStreamingSpeedProps {\n currentLength: number;\n state: ChunkStreamingSpeedState;\n}\n\nexport const updateChunkStreamingSpeedEMA = ({\n currentLength,\n state,\n}: ChunkStreamingSpeedProps): ChunkStreamingSpeedState => {\n const now = Date.now();\n const deltaTime = now - (state?.lastTimestamp ?? now);\n\n if (deltaTime <= 0) return { ...state, lastTimestamp: now };\n\n const deltaLength = currentLength - state.lastLength;\n\n const charsPerSecond = Math.max(0, (deltaLength / deltaTime) * 1000);\n\n const newEMA = calculateEMA({\n currentEMA: state.ema,\n newValue: charsPerSecond,\n });\n\n return {\n lastTimestamp: now,\n lastLength: currentLength,\n ema: newEMA,\n };\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,kBAAkB,GAAGA,CAACC,IAAY,EAAEC,MAAc,KAAa;EACxE,MAAMC,GAAG,GAAGC,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAEzCF,GAAG,CAACG,SAAS,GAAGL,IAAI;EAEpB,IAAIM,IAAI,GAAG,EAAE;EACb,IAAIC,UAAU,GAAG,CAAC;;EAElB;EACA,MAAMC,UAAU,GAAIC,KAAa,IAC7BA,KAAK,CAACC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAACA,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAACA,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;;EAE5E;EACA,MAAMC,UAAU,GAAIF,KAAa,IAC7BG,MAAM,CAACH,KAAK,CAAC,CACRC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CACtBA,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CACvBA,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CACrBA,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;;EAE9B;EACA,MAAMG,aAAa,GAAG,IAAIC,GAAG,CAAC,CAC1B,MAAM,EACN,MAAM,EACN,IAAI,EACJ,KAAK,EACL,OAAO,EACP,IAAI,EACJ,KAAK,EACL,OAAO,EACP,MAAM,EACN,MAAM,EACN,OAAO,EACP,QAAQ,EACR,OAAO,EACP,KAAK,CACR,CAAC;;EAEF;EACA;EAC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AI,IAAI,CAAC;EAEpE,MAAMK,MAAM,GAAGd,YAAY,CAAC;IACxBC,UAAU,EAAEK,KAAK,CAACd,GAAG;IACrBU,QAAQ,EAAEW;EACd,CAAC,CAAC;EAEF,OAAO;IACHH,aAAa,EAAEH,GAAG;IAClBK,UAAU,EAAEP,aAAa;IACzBb,GAAG,EAAEsB;EACT,CAAC;AACL,CAAC;AAACrC,OAAA,CAAA2B,4BAAA,GAAAA,4BAAA","ignoreList":[]}
|
|
@@ -7,7 +7,7 @@ import { CursorType } from '../../types/cursor';
|
|
|
7
7
|
import { TypewriterDelay, TypewriterSpeed } from '../../types/speed';
|
|
8
8
|
import AnimatedTypewriterText from './AnimatedTypewriterText';
|
|
9
9
|
import { StyledTypewriter, StyledTypewriterPseudoText, StyledTypewriterText } from './Typewriter.styles';
|
|
10
|
-
import { calculateAutoSpeed, getCharactersCount, getSubTextFromHTML, shuffleArray } from './utils';
|
|
10
|
+
import { calculateAutoSpeed, getCharactersCount, getSubTextFromHTML, shuffleArray, updateChunkStreamingSpeedEMA } from './utils';
|
|
11
11
|
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
12
12
|
const Typewriter = ({
|
|
13
13
|
children,
|
|
@@ -40,8 +40,8 @@ const Typewriter = ({
|
|
|
40
40
|
const [shouldPreventBlinkingCursor, setShouldPreventBlinkingCursor] = useState(false);
|
|
41
41
|
const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);
|
|
42
42
|
const [shouldStopAnimation, setShouldStopAnimation] = useState(false);
|
|
43
|
-
const
|
|
44
|
-
const
|
|
43
|
+
const autoSpeed = useRef();
|
|
44
|
+
const autoSteps = useRef(animationSteps);
|
|
45
45
|
const functions = useFunctions();
|
|
46
46
|
const values = useValues();
|
|
47
47
|
const colorScheme = useColorScheme();
|
|
@@ -55,11 +55,6 @@ const Typewriter = ({
|
|
|
55
55
|
setHasRenderedChildrenOnce(true);
|
|
56
56
|
}
|
|
57
57
|
}, [hasRenderedChildrenOnce]);
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
if (animationSteps > 0 && !shouldCalcAutoSpeed) {
|
|
60
|
-
setAutoSteps(animationSteps);
|
|
61
|
-
}
|
|
62
|
-
}, [animationSteps, shouldCalcAutoSpeed]);
|
|
63
58
|
const sortedChildren = useMemo(() => Array.isArray(children) && shouldSortChildrenRandomly ? shuffleArray(children) : children, [children, shouldSortChildrenRandomly]);
|
|
64
59
|
const areMultipleChildrenGiven = Array.isArray(sortedChildren);
|
|
65
60
|
const childrenCount = areMultipleChildrenGiven ? sortedChildren.length : 1;
|
|
@@ -98,25 +93,38 @@ const Typewriter = ({
|
|
|
98
93
|
}, sortedChildren)))) : sortedChildren;
|
|
99
94
|
}, [areMultipleChildrenGiven, colorScheme?.designSettings?.color, colorScheme?.designSettings?.colorMode, currentChildrenIndex, functions, sortedChildren, values]);
|
|
100
95
|
const charactersCount = useMemo(() => getCharactersCount(textContent), [textContent]);
|
|
96
|
+
const chunkIntervalExponentialMovingAverage = useRef({
|
|
97
|
+
lastTimestamp: undefined,
|
|
98
|
+
lastLength: charactersCount,
|
|
99
|
+
ema: charactersCount / (autoSpeedBaseFactor / 1000)
|
|
100
|
+
});
|
|
101
101
|
const [shownCharCount, setShownCharCount] = useState(charactersCount > 0 ? 0 : textContent.length);
|
|
102
102
|
const currentPosition = useRef(0);
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
if (shouldUseResetAnimation) {
|
|
105
|
+
chunkIntervalExponentialMovingAverage.current = {
|
|
106
|
+
ema: charactersCount / (autoSpeedBaseFactor / 1000),
|
|
107
|
+
lastLength: charactersCount
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
chunkIntervalExponentialMovingAverage.current = updateChunkStreamingSpeedEMA({
|
|
111
|
+
currentLength: charactersCount,
|
|
112
|
+
state: chunkIntervalExponentialMovingAverage.current
|
|
113
|
+
});
|
|
114
|
+
}, [autoSpeedBaseFactor, charactersCount, shouldUseResetAnimation]);
|
|
103
115
|
useEffect(() => {
|
|
104
116
|
if (!shouldCalcAutoSpeed) {
|
|
105
|
-
|
|
106
|
-
|
|
117
|
+
autoSpeed.current = undefined;
|
|
118
|
+
autoSteps.current = animationSteps;
|
|
107
119
|
return;
|
|
108
120
|
}
|
|
109
121
|
const {
|
|
110
122
|
speed: calculatedAutoSpeed,
|
|
111
123
|
steps
|
|
112
|
-
} = calculateAutoSpeed(
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
});
|
|
117
|
-
setAutoSpeed(calculatedAutoSpeed);
|
|
118
|
-
setAutoSteps(steps);
|
|
119
|
-
}, [animationSteps, autoSpeedBaseFactor, charactersCount, shouldCalcAutoSpeed]);
|
|
124
|
+
} = calculateAutoSpeed(chunkIntervalExponentialMovingAverage.current.ema);
|
|
125
|
+
autoSpeed.current = calculatedAutoSpeed;
|
|
126
|
+
autoSteps.current = steps;
|
|
127
|
+
}, [animationSteps, charactersCount, shouldCalcAutoSpeed]);
|
|
120
128
|
const isAnimatingText = shownCharCount < textContent.length || shouldForceCursorAnimation || areMultipleChildrenGiven || textContent.length === 0;
|
|
121
129
|
const handleClick = useCallback(event => {
|
|
122
130
|
event.stopPropagation();
|
|
@@ -141,7 +149,7 @@ const Typewriter = ({
|
|
|
141
149
|
}
|
|
142
150
|
interval = window.setInterval(() => {
|
|
143
151
|
setShownCharCount(prevState => {
|
|
144
|
-
const nextState = prevState - autoSteps;
|
|
152
|
+
const nextState = prevState - autoSteps.current;
|
|
145
153
|
currentPosition.current = nextState;
|
|
146
154
|
if (nextState === 0) {
|
|
147
155
|
window.clearInterval(interval);
|
|
@@ -168,7 +176,7 @@ const Typewriter = ({
|
|
|
168
176
|
}
|
|
169
177
|
const runTypingInterval = () => {
|
|
170
178
|
setShownCharCount(prevState => {
|
|
171
|
-
let nextState = Math.min(prevState + autoSteps, charactersCount);
|
|
179
|
+
let nextState = Math.min(prevState + autoSteps.current, charactersCount);
|
|
172
180
|
if (nextState >= charactersCount && !shouldWaitForContent) {
|
|
173
181
|
window.clearInterval(interval);
|
|
174
182
|
if (cursorType === CursorType.Thin) {
|
|
@@ -199,7 +207,7 @@ const Typewriter = ({
|
|
|
199
207
|
return nextState;
|
|
200
208
|
});
|
|
201
209
|
};
|
|
202
|
-
interval = window.setInterval(runTypingInterval, autoSpeed ?? speed);
|
|
210
|
+
interval = window.setInterval(runTypingInterval, autoSpeed.current ?? speed);
|
|
203
211
|
};
|
|
204
212
|
if (startDelay) {
|
|
205
213
|
setTimeout(startTypingAnimation, startDelay);
|
|
@@ -210,7 +218,7 @@ const Typewriter = ({
|
|
|
210
218
|
return () => {
|
|
211
219
|
window.clearInterval(interval);
|
|
212
220
|
};
|
|
213
|
-
}, [
|
|
221
|
+
}, [areMultipleChildrenGiven, autoSteps, charactersCount, cursorType, handleSetNextChildrenIndex, isResetAnimationActive, nextTextDelay, onResetAnimationEnd, onResetAnimationStart, onTypingAnimationEnd, onTypingAnimationStart, resetDelay, resetSpeed, shouldStopAnimation, shouldUseResetAnimation, shouldWaitForContent, speed, startDelay, textContent.length]);
|
|
214
222
|
useEffect(() => {
|
|
215
223
|
if (!isAnimatingText && typeof onFinish === 'function') {
|
|
216
224
|
onFinish();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Typewriter.js","names":["ColorSchemeProvider","useColorScheme","ChaynsProvider","useFunctions","useValues","React","useCallback","useEffect","useLayoutEffect","useMemo","useRef","useState","createPortal","renderToString","CursorType","TypewriterDelay","TypewriterSpeed","AnimatedTypewriterText","StyledTypewriter","StyledTypewriterPseudoText","StyledTypewriterText","calculateAutoSpeed","getCharactersCount","getSubTextFromHTML","shuffleArray","useIsomorphicLayoutEffect","window","Typewriter","children","cursorType","Default","nextTextDelay","Medium","onFinish","onResetAnimationEnd","animationSteps","onResetAnimationStart","onTypingAnimationEnd","onTypingAnimationStart","pseudoChildren","resetDelay","shouldForceCursorAnimation","shouldHideCursor","shouldRemainSingleLine","shouldSortChildrenRandomly","shouldUseAnimationHeight","shouldUseResetAnimation","shouldWaitForContent","speed","resetSpeed","startDelay","None","textStyle","shouldCalcAutoSpeed","autoSpeedBaseFactor","currentChildrenIndex","setCurrentChildrenIndex","hasRenderedChildrenOnce","setHasRenderedChildrenOnce","shouldPreventBlinkingCursor","setShouldPreventBlinkingCursor","isResetAnimationActive","setIsResetAnimationActive","shouldStopAnimation","setShouldStopAnimation","autoSpeed","setAutoSpeed","autoSteps","setAutoSteps","functions","values","colorScheme","sortedChildren","Array","isArray","areMultipleChildrenGiven","childrenCount","length","textContent","currentChildren","isValidElement","createElement","data","isModule","color","designSettings","colorMode","style","display","className","charactersCount","shownCharCount","setShownCharCount","currentPosition","undefined","calculatedAutoSpeed","steps","fullTextLength","current","baseSpeedFactor","isAnimatingText","handleClick","event","stopPropagation","preventDefault","handleSetNextChildrenIndex","newIndex","interval","setInterval","prevState","nextState","clearInterval","setTimeout","startTypingAnimation","Thin","runTypingInterval","Math","min","shownText","pseudoTextHTML","pseudoText","$cursorType","onClick","$isAnimatingText","$shouldHideCursor","$shouldPreventBlinkAnimation","$shouldRemainSingleLine","dangerouslySetInnerHTML","__html","position","visibility","document","body","displayName"],"sources":["../../../../src/components/typewriter/Typewriter.tsx"],"sourcesContent":["import { ColorSchemeProvider, useColorScheme } from '@chayns-components/core';\nimport { ChaynsProvider, useFunctions, useValues } from 'chayns-api';\nimport React, {\n FC,\n ReactElement,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { renderToString } from 'react-dom/server';\nimport { CSSPropertiesWithVars } from 'styled-components/dist/types';\nimport { CursorType } from '../../types/cursor';\nimport { TypewriterDelay, TypewriterSpeed } from '../../types/speed';\nimport AnimatedTypewriterText from './AnimatedTypewriterText';\nimport {\n StyledTypewriter,\n StyledTypewriterPseudoText,\n StyledTypewriterText,\n} from './Typewriter.styles';\nimport { calculateAutoSpeed, getCharactersCount, getSubTextFromHTML, shuffleArray } from './utils';\n\nconst useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport type TypewriterProps = {\n /**\n * The number of characters that will be animated per animation cycle.\n */\n animationSteps?: number;\n /**\n * The base speed factor to calculate the animation speed.\n */\n autoSpeedBaseFactor?: number;\n /**\n * The text to type\n */\n children: ReactElement | ReactElement[] | string | string[];\n /**\n * The type of the cursor. Use the CursorType enum for this prop.\n */\n cursorType?: CursorType;\n /**\n * The delay in milliseconds before the next text is shown.\n * This prop is only used if multiple texts are given.\n */\n nextTextDelay?: TypewriterDelay;\n /**\n * Function that is executed when the typewriter animation has finished. This function will not\n * be executed if multiple texts are used.\n */\n onFinish?: VoidFunction;\n /**\n * Function that is executed when the reset animation has finished. This function will not be\n * executed if `shouldUseResetAnimation` is not set to `true`.\n */\n onResetAnimationEnd?: VoidFunction;\n /**\n * Function that is executed when the reset animation has started. This function will not be\n * executed if `shouldUseResetAnimation` is not set to `true`.\n */\n onResetAnimationStart?: VoidFunction;\n /**\n * Function that is executed when the typing animation has finished. If multiple texts are given,\n * this function will be executed for each text.\n */\n onTypingAnimationEnd?: VoidFunction;\n /**\n * Function that is executed when the typing animation has started. If multiple texts are given,\n * this function will be executed for each text.\n */\n onTypingAnimationStart?: VoidFunction;\n /**\n * Pseudo-element to be rendered invisible during animation to define the size of the element\n * for the typewriter effect. By default, the \"children\" is used for this purpose.\n */\n pseudoChildren?: ReactElement | string;\n /**\n * Waiting time in milliseconds before the typewriter resets the text.\n * This prop is only used if multiple texts are given.\n */\n resetDelay?: TypewriterDelay;\n /**\n * The reset speed of the animation. Use the TypewriterSpeed enum for this prop.\n */\n resetSpeed?: TypewriterSpeed | number;\n /**\n * Specifies whether the cursor should be forced to animate even if no text is currently animated.\n */\n shouldForceCursorAnimation?: boolean;\n /**\n * Specifies whether the cursor should be hidden\n */\n shouldHideCursor?: boolean;\n /**\n * Whether the content should remain a single line.\n */\n shouldRemainSingleLine?: boolean;\n /**\n * Specifies whether the children should be sorted randomly if there are multiple texts.\n * This makes the typewriter start with a different text each time and also changes them\n * in a random order.\n */\n shouldSortChildrenRandomly?: boolean;\n /**\n * Specifies whether the animation should use its full height or the height of the current\n * chunk.\n */\n shouldUseAnimationHeight?: boolean;\n /**\n * Whether the animation speed should be calculated with the chunk interval.\n */\n shouldCalcAutoSpeed?: boolean;\n /**\n * Specifies whether the reset of the text should be animated with a backspace animation for\n * multiple texts.\n */\n shouldUseResetAnimation?: boolean;\n /**\n * Whether the typewriter should wait for new content\n */\n shouldWaitForContent?: boolean;\n /**\n * The speed of the animation. Use the TypewriterSpeed enum for this prop.\n */\n speed?: TypewriterSpeed | number;\n /**\n * The delay in milliseconds before the typewriter starts typing.\n */\n startDelay?: TypewriterDelay;\n /**\n * The style of the typewriter text element\n */\n textStyle?: CSSPropertiesWithVars;\n};\n\nconst Typewriter: FC<TypewriterProps> = ({\n children,\n cursorType = CursorType.Default,\n nextTextDelay = TypewriterDelay.Medium,\n onFinish,\n onResetAnimationEnd,\n animationSteps = 1,\n onResetAnimationStart,\n onTypingAnimationEnd,\n onTypingAnimationStart,\n pseudoChildren,\n resetDelay = TypewriterDelay.Medium,\n shouldForceCursorAnimation = false,\n shouldHideCursor = false,\n shouldRemainSingleLine = false,\n shouldSortChildrenRandomly = false,\n shouldUseAnimationHeight = false,\n shouldUseResetAnimation = false,\n shouldWaitForContent,\n speed = TypewriterSpeed.Medium,\n resetSpeed = speed,\n startDelay = TypewriterDelay.None,\n textStyle,\n shouldCalcAutoSpeed = false,\n autoSpeedBaseFactor = 2000,\n}) => {\n const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);\n const [hasRenderedChildrenOnce, setHasRenderedChildrenOnce] = useState(false);\n const [shouldPreventBlinkingCursor, setShouldPreventBlinkingCursor] = useState(false);\n const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);\n const [shouldStopAnimation, setShouldStopAnimation] = useState(false);\n const [autoSpeed, setAutoSpeed] = useState<number>();\n const [autoSteps, setAutoSteps] = useState(animationSteps);\n\n const functions = useFunctions();\n const values = useValues();\n\n const colorScheme = useColorScheme();\n\n useIsomorphicLayoutEffect(() => {\n if (children) {\n setHasRenderedChildrenOnce(false);\n }\n }, [children]);\n\n useEffect(() => {\n if (!hasRenderedChildrenOnce) {\n setHasRenderedChildrenOnce(true);\n }\n }, [hasRenderedChildrenOnce]);\n\n useEffect(() => {\n if (animationSteps > 0 && !shouldCalcAutoSpeed) {\n setAutoSteps(animationSteps);\n }\n }, [animationSteps, shouldCalcAutoSpeed]);\n\n const sortedChildren = useMemo(\n () =>\n Array.isArray(children) && shouldSortChildrenRandomly\n ? shuffleArray<ReactElement | string>(children)\n : children,\n [children, shouldSortChildrenRandomly],\n );\n\n const areMultipleChildrenGiven = Array.isArray(sortedChildren);\n const childrenCount = areMultipleChildrenGiven ? sortedChildren.length : 1;\n\n const textContent = useMemo(() => {\n if (areMultipleChildrenGiven) {\n const currentChildren = sortedChildren[currentChildrenIndex];\n\n if (currentChildren) {\n return React.isValidElement(currentChildren)\n ? renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider\n color={colorScheme?.designSettings?.color}\n colorMode={colorScheme?.designSettings?.colorMode}\n style={{ display: 'inline' }}\n >\n <span className=\"notranslate\">{currentChildren}</span>\n </ColorSchemeProvider>\n </ChaynsProvider>,\n )\n : (currentChildren as string);\n }\n\n return '';\n }\n\n return React.isValidElement(sortedChildren)\n ? renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider\n color={colorScheme?.designSettings?.color}\n colorMode={colorScheme?.designSettings?.colorMode}\n style={{ display: 'inline' }}\n >\n <span className=\"notranslate\">{sortedChildren}</span>\n </ColorSchemeProvider>\n </ChaynsProvider>,\n )\n : (sortedChildren as string);\n }, [\n areMultipleChildrenGiven,\n colorScheme?.designSettings?.color,\n colorScheme?.designSettings?.colorMode,\n currentChildrenIndex,\n functions,\n sortedChildren,\n values,\n ]);\n\n const charactersCount = useMemo(() => getCharactersCount(textContent), [textContent]);\n\n const [shownCharCount, setShownCharCount] = useState(\n charactersCount > 0 ? 0 : textContent.length,\n );\n\n const currentPosition = useRef(0);\n\n useEffect(() => {\n if (!shouldCalcAutoSpeed) {\n setAutoSpeed(undefined);\n setAutoSteps(animationSteps);\n\n return;\n }\n\n const { speed: calculatedAutoSpeed, steps } = calculateAutoSpeed({\n fullTextLength: charactersCount,\n currentPosition: currentPosition.current,\n baseSpeedFactor: autoSpeedBaseFactor,\n });\n\n setAutoSpeed(calculatedAutoSpeed);\n setAutoSteps(steps);\n }, [animationSteps, autoSpeedBaseFactor, charactersCount, shouldCalcAutoSpeed]);\n\n const isAnimatingText =\n shownCharCount < textContent.length ||\n shouldForceCursorAnimation ||\n areMultipleChildrenGiven ||\n textContent.length === 0;\n\n const handleClick = useCallback((event: React.MouseEvent) => {\n event.stopPropagation();\n event.preventDefault();\n\n setShouldStopAnimation(true);\n }, []);\n\n const handleSetNextChildrenIndex = useCallback(\n () =>\n setCurrentChildrenIndex(() => {\n let newIndex = currentChildrenIndex + 1;\n\n if (newIndex > childrenCount - 1) {\n newIndex = 0;\n }\n\n return newIndex;\n }),\n [childrenCount, currentChildrenIndex],\n );\n\n useEffect(() => {\n let interval: number | undefined;\n\n if (shouldStopAnimation || charactersCount === 0) {\n setShownCharCount(textContent.length);\n currentPosition.current = textContent.length;\n } else if (isResetAnimationActive) {\n if (typeof onResetAnimationStart === 'function') {\n onResetAnimationStart();\n }\n\n interval = window.setInterval(() => {\n setShownCharCount((prevState) => {\n const nextState = prevState - autoSteps;\n currentPosition.current = nextState;\n\n if (nextState === 0) {\n window.clearInterval(interval);\n\n if (typeof onResetAnimationEnd === 'function') {\n onResetAnimationEnd();\n }\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n setIsResetAnimationActive(false);\n handleSetNextChildrenIndex();\n }, nextTextDelay);\n }\n }\n\n return nextState;\n });\n }, resetSpeed);\n } else {\n const startTypingAnimation = () => {\n if (cursorType === CursorType.Thin) {\n setShouldPreventBlinkingCursor(true);\n }\n\n if (typeof onTypingAnimationStart === 'function') {\n onTypingAnimationStart();\n }\n\n const runTypingInterval = () => {\n setShownCharCount((prevState) => {\n let nextState = Math.min(prevState + autoSteps, charactersCount);\n\n if (nextState >= charactersCount && !shouldWaitForContent) {\n window.clearInterval(interval);\n\n if (cursorType === CursorType.Thin) {\n setShouldPreventBlinkingCursor(false);\n }\n\n if (typeof onTypingAnimationEnd === 'function') {\n onTypingAnimationEnd();\n }\n\n /**\n * At this point, the next value for \"shownCharCount\" is deliberately set to\n * the length of the textContent to correctly display HTML elements\n * after the last letter.\n */\n nextState = textContent.length;\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n if (shouldUseResetAnimation) {\n setIsResetAnimationActive(true);\n } else {\n setShownCharCount(0);\n setTimeout(handleSetNextChildrenIndex, nextTextDelay);\n }\n }, resetDelay);\n }\n }\n\n currentPosition.current = nextState;\n\n return nextState;\n });\n };\n\n interval = window.setInterval(runTypingInterval, autoSpeed ?? speed);\n };\n\n if (startDelay) {\n setTimeout(startTypingAnimation, startDelay);\n } else {\n startTypingAnimation();\n }\n }\n\n return () => {\n window.clearInterval(interval);\n };\n }, [\n resetSpeed,\n speed,\n resetDelay,\n childrenCount,\n charactersCount,\n textContent.length,\n shouldStopAnimation,\n shouldWaitForContent,\n isResetAnimationActive,\n shouldUseResetAnimation,\n areMultipleChildrenGiven,\n handleSetNextChildrenIndex,\n nextTextDelay,\n startDelay,\n onResetAnimationStart,\n onResetAnimationEnd,\n onTypingAnimationStart,\n onTypingAnimationEnd,\n cursorType,\n autoSpeed,\n autoSteps,\n ]);\n\n useEffect(() => {\n if (!isAnimatingText && typeof onFinish === 'function') {\n onFinish();\n }\n }, [isAnimatingText, onFinish]);\n\n const shownText = useMemo(\n () => getSubTextFromHTML(textContent, shownCharCount),\n [shownCharCount, textContent],\n );\n\n const pseudoTextHTML = useMemo(() => {\n if (pseudoChildren) {\n const pseudoText = React.isValidElement(pseudoChildren)\n ? renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider\n color={colorScheme?.designSettings?.color}\n colorMode={colorScheme?.designSettings?.colorMode}\n style={{ display: 'inline' }}\n >\n {pseudoChildren}\n </ColorSchemeProvider>\n </ChaynsProvider>,\n )\n : (pseudoChildren as string);\n\n if (shouldUseAnimationHeight) {\n return getSubTextFromHTML(pseudoText, shownCharCount);\n }\n\n return pseudoText;\n }\n\n if (shouldUseAnimationHeight && textContent) {\n return getSubTextFromHTML(textContent, shownCharCount);\n }\n\n return textContent || '​';\n }, [\n colorScheme?.designSettings?.color,\n colorScheme?.designSettings?.colorMode,\n functions,\n pseudoChildren,\n shouldUseAnimationHeight,\n shownCharCount,\n textContent,\n values,\n ]);\n\n return useMemo(\n () => (\n <StyledTypewriter\n $cursorType={cursorType}\n onClick={isAnimatingText ? handleClick : undefined}\n $isAnimatingText={isAnimatingText}\n $shouldHideCursor={shouldHideCursor}\n $shouldPreventBlinkAnimation={shouldPreventBlinkingCursor}\n >\n {isAnimatingText ? (\n <AnimatedTypewriterText\n shouldHideCursor={shouldHideCursor}\n shouldRemainSingleLine={shouldRemainSingleLine}\n shownText={shownText}\n textStyle={textStyle}\n />\n ) : (\n <StyledTypewriterText\n className=\"notranslate\"\n $shouldRemainSingleLine={shouldRemainSingleLine}\n dangerouslySetInnerHTML={\n typeof sortedChildren === 'string' ? { __html: shownText } : undefined\n }\n style={textStyle}\n >\n {typeof sortedChildren !== 'string' ? sortedChildren : undefined}\n </StyledTypewriterText>\n )}\n {isAnimatingText && (\n <StyledTypewriterPseudoText\n $isAnimatingText={isAnimatingText}\n $shouldHideCursor={shouldHideCursor}\n dangerouslySetInnerHTML={{ __html: pseudoTextHTML }}\n />\n )}\n {/*\n The following is needed because some components like the CodeHighlighter will not render correct\n if the element is not rendered on a client before...\n */}\n {!hasRenderedChildrenOnce &&\n createPortal(\n <div style={{ position: 'absolute', visibility: 'hidden' }}>\n {children}\n </div>,\n document.body,\n )}\n </StyledTypewriter>\n ),\n [\n children,\n cursorType,\n handleClick,\n hasRenderedChildrenOnce,\n isAnimatingText,\n pseudoTextHTML,\n shouldHideCursor,\n shouldPreventBlinkingCursor,\n shouldRemainSingleLine,\n shownText,\n sortedChildren,\n textStyle,\n ],\n );\n};\n\nTypewriter.displayName = 'Typewriter';\n\nexport default Typewriter;\n"],"mappings":"AAAA,SAASA,mBAAmB,EAAEC,cAAc,QAAQ,yBAAyB;AAC7E,SAASC,cAAc,EAAEC,YAAY,EAAEC,SAAS,QAAQ,YAAY;AACpE,OAAOC,KAAK,IAGRC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACL,OAAO;AACd,SAASC,YAAY,QAAQ,WAAW;AACxC,SAASC,cAAc,QAAQ,kBAAkB;AAEjD,SAASC,UAAU,QAAQ,oBAAoB;AAC/C,SAASC,eAAe,EAAEC,eAAe,QAAQ,mBAAmB;AACpE,OAAOC,sBAAsB,MAAM,0BAA0B;AAC7D,SACIC,gBAAgB,EAChBC,0BAA0B,EAC1BC,oBAAoB,QACjB,qBAAqB;AAC5B,SAASC,kBAAkB,EAAEC,kBAAkB,EAAEC,kBAAkB,EAAEC,YAAY,QAAQ,SAAS;AAElG,MAAMC,yBAAyB,GAAG,OAAOC,MAAM,KAAK,WAAW,GAAGlB,eAAe,GAAGD,SAAS;AAiH7F,MAAMoB,UAA+B,GAAGA,CAAC;EACrCC,QAAQ;EACRC,UAAU,GAAGf,UAAU,CAACgB,OAAO;EAC/BC,aAAa,GAAGhB,eAAe,CAACiB,MAAM;EACtCC,QAAQ;EACRC,mBAAmB;EACnBC,cAAc,GAAG,CAAC;EAClBC,qBAAqB;EACrBC,oBAAoB;EACpBC,sBAAsB;EACtBC,cAAc;EACdC,UAAU,GAAGzB,eAAe,CAACiB,MAAM;EACnCS,0BAA0B,GAAG,KAAK;EAClCC,gBAAgB,GAAG,KAAK;EACxBC,sBAAsB,GAAG,KAAK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B,EAC3BhB,sBAAsB,EACtB2E,SAAS,EACT9C,cAAc,EACdpB,SAAS,CAEjB,CAAC;AACL,CAAC;AAEDzB,UAAU,CAAC0G,WAAW,GAAG,YAAY;AAErC,eAAe1G,UAAU","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"Typewriter.js","names":["ColorSchemeProvider","useColorScheme","ChaynsProvider","useFunctions","useValues","React","useCallback","useEffect","useLayoutEffect","useMemo","useRef","useState","createPortal","renderToString","CursorType","TypewriterDelay","TypewriterSpeed","AnimatedTypewriterText","StyledTypewriter","StyledTypewriterPseudoText","StyledTypewriterText","calculateAutoSpeed","getCharactersCount","getSubTextFromHTML","shuffleArray","updateChunkStreamingSpeedEMA","useIsomorphicLayoutEffect","window","Typewriter","children","cursorType","Default","nextTextDelay","Medium","onFinish","onResetAnimationEnd","animationSteps","onResetAnimationStart","onTypingAnimationEnd","onTypingAnimationStart","pseudoChildren","resetDelay","shouldForceCursorAnimation","shouldHideCursor","shouldRemainSingleLine","shouldSortChildrenRandomly","shouldUseAnimationHeight","shouldUseResetAnimation","shouldWaitForContent","speed","resetSpeed","startDelay","None","textStyle","shouldCalcAutoSpeed","autoSpeedBaseFactor","currentChildrenIndex","setCurrentChildrenIndex","hasRenderedChildrenOnce","setHasRenderedChildrenOnce","shouldPreventBlinkingCursor","setShouldPreventBlinkingCursor","isResetAnimationActive","setIsResetAnimationActive","shouldStopAnimation","setShouldStopAnimation","autoSpeed","autoSteps","functions","values","colorScheme","sortedChildren","Array","isArray","areMultipleChildrenGiven","childrenCount","length","textContent","currentChildren","isValidElement","createElement","data","isModule","color","designSettings","colorMode","style","display","className","charactersCount","chunkIntervalExponentialMovingAverage","lastTimestamp","undefined","lastLength","ema","shownCharCount","setShownCharCount","currentPosition","current","currentLength","state","calculatedAutoSpeed","steps","isAnimatingText","handleClick","event","stopPropagation","preventDefault","handleSetNextChildrenIndex","newIndex","interval","setInterval","prevState","nextState","clearInterval","setTimeout","startTypingAnimation","Thin","runTypingInterval","Math","min","shownText","pseudoTextHTML","pseudoText","$cursorType","onClick","$isAnimatingText","$shouldHideCursor","$shouldPreventBlinkAnimation","$shouldRemainSingleLine","dangerouslySetInnerHTML","__html","position","visibility","document","body","displayName"],"sources":["../../../../src/components/typewriter/Typewriter.tsx"],"sourcesContent":["import { ColorSchemeProvider, useColorScheme } from '@chayns-components/core';\nimport { ChaynsProvider, useFunctions, useValues } from 'chayns-api';\nimport React, {\n FC,\n ReactElement,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { renderToString } from 'react-dom/server';\nimport { CSSPropertiesWithVars } from 'styled-components/dist/types';\nimport { CursorType } from '../../types/cursor';\nimport { TypewriterDelay, TypewriterSpeed } from '../../types/speed';\nimport AnimatedTypewriterText from './AnimatedTypewriterText';\nimport {\n StyledTypewriter,\n StyledTypewriterPseudoText,\n StyledTypewriterText,\n} from './Typewriter.styles';\nimport {\n calculateAutoSpeed,\n ChunkStreamingSpeedState,\n getCharactersCount,\n getSubTextFromHTML,\n shuffleArray,\n updateChunkStreamingSpeedEMA,\n} from './utils';\n\nconst useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport type TypewriterProps = {\n /**\n * The number of characters that will be animated per animation cycle.\n */\n animationSteps?: number;\n /**\n * The text to type\n */\n children: ReactElement | ReactElement[] | string | string[];\n /**\n * The type of the cursor. Use the CursorType enum for this prop.\n */\n cursorType?: CursorType;\n /**\n * The delay in milliseconds before the next text is shown.\n * This prop is only used if multiple texts are given.\n */\n nextTextDelay?: TypewriterDelay;\n /**\n * Function that is executed when the typewriter animation has finished. This function will not\n * be executed if multiple texts are used.\n */\n onFinish?: VoidFunction;\n /**\n * Function that is executed when the reset animation has finished. This function will not be\n * executed if `shouldUseResetAnimation` is not set to `true`.\n */\n onResetAnimationEnd?: VoidFunction;\n /**\n * Function that is executed when the reset animation has started. This function will not be\n * executed if `shouldUseResetAnimation` is not set to `true`.\n */\n onResetAnimationStart?: VoidFunction;\n /**\n * Function that is executed when the typing animation has finished. If multiple texts are given,\n * this function will be executed for each text.\n */\n onTypingAnimationEnd?: VoidFunction;\n /**\n * Function that is executed when the typing animation has started. If multiple texts are given,\n * this function will be executed for each text.\n */\n onTypingAnimationStart?: VoidFunction;\n /**\n * Pseudo-element to be rendered invisible during animation to define the size of the element\n * for the typewriter effect. By default, the \"children\" is used for this purpose.\n */\n pseudoChildren?: ReactElement | string;\n /**\n * Waiting time in milliseconds before the typewriter resets the text.\n * This prop is only used if multiple texts are given.\n */\n resetDelay?: TypewriterDelay;\n /**\n * The reset speed of the animation. Use the TypewriterSpeed enum for this prop.\n */\n resetSpeed?: TypewriterSpeed | number;\n /**\n * Specifies whether the cursor should be forced to animate even if no text is currently animated.\n */\n shouldForceCursorAnimation?: boolean;\n /**\n * Specifies whether the cursor should be hidden\n */\n shouldHideCursor?: boolean;\n /**\n * Whether the content should remain a single line.\n */\n shouldRemainSingleLine?: boolean;\n /**\n * Specifies whether the children should be sorted randomly if there are multiple texts.\n * This makes the typewriter start with a different text each time and also changes them\n * in a random order.\n */\n shouldSortChildrenRandomly?: boolean;\n /**\n * Specifies whether the animation should use its full height or the height of the current\n * chunk.\n */\n shouldUseAnimationHeight?: boolean;\n /**\n * Whether the animation speed should be calculated with the chunk interval.\n */\n shouldCalcAutoSpeed?: boolean;\n /**\n * Sets how long the animation should last when `shouldCalcAutoSpeed` is enabled in milliseconds.\n * When chunks are streamed, this value will only be used for the initial speed and then change to the speed characters are added at\n */\n autoSpeedBaseFactor?: number;\n /**\n * Specifies whether the reset of the text should be animated with a backspace animation for\n * multiple texts.\n */\n shouldUseResetAnimation?: boolean;\n /**\n * Whether the typewriter should wait for new content\n */\n shouldWaitForContent?: boolean;\n /**\n * The speed of the animation. Use the TypewriterSpeed enum for this prop.\n */\n speed?: TypewriterSpeed | number;\n /**\n * The delay in milliseconds before the typewriter starts typing.\n */\n startDelay?: TypewriterDelay;\n /**\n * The style of the typewriter text element\n */\n textStyle?: CSSPropertiesWithVars;\n};\n\nconst Typewriter: FC<TypewriterProps> = ({\n children,\n cursorType = CursorType.Default,\n nextTextDelay = TypewriterDelay.Medium,\n onFinish,\n onResetAnimationEnd,\n animationSteps = 1,\n onResetAnimationStart,\n onTypingAnimationEnd,\n onTypingAnimationStart,\n pseudoChildren,\n resetDelay = TypewriterDelay.Medium,\n shouldForceCursorAnimation = false,\n shouldHideCursor = false,\n shouldRemainSingleLine = false,\n shouldSortChildrenRandomly = false,\n shouldUseAnimationHeight = false,\n shouldUseResetAnimation = false,\n shouldWaitForContent,\n speed = TypewriterSpeed.Medium,\n resetSpeed = speed,\n startDelay = TypewriterDelay.None,\n textStyle,\n shouldCalcAutoSpeed = false,\n autoSpeedBaseFactor = 2000,\n}) => {\n const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);\n const [hasRenderedChildrenOnce, setHasRenderedChildrenOnce] = useState(false);\n const [shouldPreventBlinkingCursor, setShouldPreventBlinkingCursor] = useState(false);\n const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);\n const [shouldStopAnimation, setShouldStopAnimation] = useState(false);\n const autoSpeed = useRef<number>();\n const autoSteps = useRef<number>(animationSteps);\n\n const functions = useFunctions();\n const values = useValues();\n\n const colorScheme = useColorScheme();\n\n useIsomorphicLayoutEffect(() => {\n if (children) {\n setHasRenderedChildrenOnce(false);\n }\n }, [children]);\n\n useEffect(() => {\n if (!hasRenderedChildrenOnce) {\n setHasRenderedChildrenOnce(true);\n }\n }, [hasRenderedChildrenOnce]);\n\n const sortedChildren = useMemo(\n () =>\n Array.isArray(children) && shouldSortChildrenRandomly\n ? shuffleArray<ReactElement | string>(children)\n : children,\n [children, shouldSortChildrenRandomly],\n );\n\n const areMultipleChildrenGiven = Array.isArray(sortedChildren);\n const childrenCount = areMultipleChildrenGiven ? sortedChildren.length : 1;\n\n const textContent = useMemo(() => {\n if (areMultipleChildrenGiven) {\n const currentChildren = sortedChildren[currentChildrenIndex];\n\n if (currentChildren) {\n return React.isValidElement(currentChildren)\n ? renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider\n color={colorScheme?.designSettings?.color}\n colorMode={colorScheme?.designSettings?.colorMode}\n style={{ display: 'inline' }}\n >\n <span className=\"notranslate\">{currentChildren}</span>\n </ColorSchemeProvider>\n </ChaynsProvider>,\n )\n : (currentChildren as string);\n }\n\n return '';\n }\n\n return React.isValidElement(sortedChildren)\n ? renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider\n color={colorScheme?.designSettings?.color}\n colorMode={colorScheme?.designSettings?.colorMode}\n style={{ display: 'inline' }}\n >\n <span className=\"notranslate\">{sortedChildren}</span>\n </ColorSchemeProvider>\n </ChaynsProvider>,\n )\n : (sortedChildren as string);\n }, [\n areMultipleChildrenGiven,\n colorScheme?.designSettings?.color,\n colorScheme?.designSettings?.colorMode,\n currentChildrenIndex,\n functions,\n sortedChildren,\n values,\n ]);\n\n const charactersCount = useMemo(() => getCharactersCount(textContent), [textContent]);\n\n const chunkIntervalExponentialMovingAverage = useRef<ChunkStreamingSpeedState>({\n lastTimestamp: undefined,\n lastLength: charactersCount,\n ema: charactersCount / (autoSpeedBaseFactor / 1000),\n });\n\n const [shownCharCount, setShownCharCount] = useState(\n charactersCount > 0 ? 0 : textContent.length,\n );\n\n const currentPosition = useRef(0);\n\n useEffect(() => {\n if (shouldUseResetAnimation) {\n chunkIntervalExponentialMovingAverage.current = {\n ema: charactersCount / (autoSpeedBaseFactor / 1000),\n lastLength: charactersCount,\n };\n }\n chunkIntervalExponentialMovingAverage.current = updateChunkStreamingSpeedEMA({\n currentLength: charactersCount,\n state: chunkIntervalExponentialMovingAverage.current,\n });\n }, [autoSpeedBaseFactor, charactersCount, shouldUseResetAnimation]);\n\n useEffect(() => {\n if (!shouldCalcAutoSpeed) {\n autoSpeed.current = undefined;\n autoSteps.current = animationSteps;\n return;\n }\n\n const { speed: calculatedAutoSpeed, steps } = calculateAutoSpeed(\n chunkIntervalExponentialMovingAverage.current.ema,\n );\n autoSpeed.current = calculatedAutoSpeed;\n autoSteps.current = steps;\n }, [animationSteps, charactersCount, shouldCalcAutoSpeed]);\n\n const isAnimatingText =\n shownCharCount < textContent.length ||\n shouldForceCursorAnimation ||\n areMultipleChildrenGiven ||\n textContent.length === 0;\n\n const handleClick = useCallback((event: React.MouseEvent) => {\n event.stopPropagation();\n event.preventDefault();\n\n setShouldStopAnimation(true);\n }, []);\n\n const handleSetNextChildrenIndex = useCallback(\n () =>\n setCurrentChildrenIndex(() => {\n let newIndex = currentChildrenIndex + 1;\n\n if (newIndex > childrenCount - 1) {\n newIndex = 0;\n }\n\n return newIndex;\n }),\n [childrenCount, currentChildrenIndex],\n );\n\n useEffect(() => {\n let interval: number | undefined;\n\n if (shouldStopAnimation || charactersCount === 0) {\n setShownCharCount(textContent.length);\n currentPosition.current = textContent.length;\n } else if (isResetAnimationActive) {\n if (typeof onResetAnimationStart === 'function') {\n onResetAnimationStart();\n }\n\n interval = window.setInterval(() => {\n setShownCharCount((prevState) => {\n const nextState = prevState - autoSteps.current;\n currentPosition.current = nextState;\n\n if (nextState === 0) {\n window.clearInterval(interval);\n\n if (typeof onResetAnimationEnd === 'function') {\n onResetAnimationEnd();\n }\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n setIsResetAnimationActive(false);\n handleSetNextChildrenIndex();\n }, nextTextDelay);\n }\n }\n\n return nextState;\n });\n }, resetSpeed);\n } else {\n const startTypingAnimation = () => {\n if (cursorType === CursorType.Thin) {\n setShouldPreventBlinkingCursor(true);\n }\n\n if (typeof onTypingAnimationStart === 'function') {\n onTypingAnimationStart();\n }\n\n const runTypingInterval = () => {\n setShownCharCount((prevState) => {\n let nextState = Math.min(prevState + autoSteps.current, charactersCount);\n\n if (nextState >= charactersCount && !shouldWaitForContent) {\n window.clearInterval(interval);\n\n if (cursorType === CursorType.Thin) {\n setShouldPreventBlinkingCursor(false);\n }\n\n if (typeof onTypingAnimationEnd === 'function') {\n onTypingAnimationEnd();\n }\n\n /**\n * At this point, the next value for \"shownCharCount\" is deliberately set to\n * the length of the textContent to correctly display HTML elements\n * after the last letter.\n */\n nextState = textContent.length;\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n if (shouldUseResetAnimation) {\n setIsResetAnimationActive(true);\n } else {\n setShownCharCount(0);\n setTimeout(handleSetNextChildrenIndex, nextTextDelay);\n }\n }, resetDelay);\n }\n }\n\n currentPosition.current = nextState;\n\n return nextState;\n });\n };\n interval = window.setInterval(runTypingInterval, autoSpeed.current ?? speed);\n };\n\n if (startDelay) {\n setTimeout(startTypingAnimation, startDelay);\n } else {\n startTypingAnimation();\n }\n }\n\n return () => {\n window.clearInterval(interval);\n };\n }, [\n areMultipleChildrenGiven,\n autoSteps,\n charactersCount,\n cursorType,\n handleSetNextChildrenIndex,\n isResetAnimationActive,\n nextTextDelay,\n onResetAnimationEnd,\n onResetAnimationStart,\n onTypingAnimationEnd,\n onTypingAnimationStart,\n resetDelay,\n resetSpeed,\n shouldStopAnimation,\n shouldUseResetAnimation,\n shouldWaitForContent,\n speed,\n startDelay,\n textContent.length,\n ]);\n\n useEffect(() => {\n if (!isAnimatingText && typeof onFinish === 'function') {\n onFinish();\n }\n }, [isAnimatingText, onFinish]);\n\n const shownText = useMemo(\n () => getSubTextFromHTML(textContent, shownCharCount),\n [shownCharCount, textContent],\n );\n\n const pseudoTextHTML = useMemo(() => {\n if (pseudoChildren) {\n const pseudoText = React.isValidElement(pseudoChildren)\n ? renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider\n color={colorScheme?.designSettings?.color}\n colorMode={colorScheme?.designSettings?.colorMode}\n style={{ display: 'inline' }}\n >\n {pseudoChildren}\n </ColorSchemeProvider>\n </ChaynsProvider>,\n )\n : (pseudoChildren as string);\n\n if (shouldUseAnimationHeight) {\n return getSubTextFromHTML(pseudoText, shownCharCount);\n }\n\n return pseudoText;\n }\n\n if (shouldUseAnimationHeight && textContent) {\n return getSubTextFromHTML(textContent, shownCharCount);\n }\n\n return textContent || '​';\n }, [\n colorScheme?.designSettings?.color,\n colorScheme?.designSettings?.colorMode,\n functions,\n pseudoChildren,\n shouldUseAnimationHeight,\n shownCharCount,\n textContent,\n values,\n ]);\n\n return useMemo(\n () => (\n <StyledTypewriter\n $cursorType={cursorType}\n onClick={isAnimatingText ? handleClick : undefined}\n $isAnimatingText={isAnimatingText}\n $shouldHideCursor={shouldHideCursor}\n $shouldPreventBlinkAnimation={shouldPreventBlinkingCursor}\n >\n {isAnimatingText ? (\n <AnimatedTypewriterText\n shouldHideCursor={shouldHideCursor}\n shouldRemainSingleLine={shouldRemainSingleLine}\n shownText={shownText}\n textStyle={textStyle}\n />\n ) : (\n <StyledTypewriterText\n className=\"notranslate\"\n $shouldRemainSingleLine={shouldRemainSingleLine}\n dangerouslySetInnerHTML={\n typeof sortedChildren === 'string' ? { __html: shownText } : undefined\n }\n style={textStyle}\n >\n {typeof sortedChildren !== 'string' ? sortedChildren : undefined}\n </StyledTypewriterText>\n )}\n {isAnimatingText && (\n <StyledTypewriterPseudoText\n $isAnimatingText={isAnimatingText}\n $shouldHideCursor={shouldHideCursor}\n dangerouslySetInnerHTML={{ __html: pseudoTextHTML }}\n />\n )}\n {/*\n The following is needed because some components like the CodeHighlighter will not render correct\n if the element is not rendered on a client before...\n */}\n {!hasRenderedChildrenOnce &&\n createPortal(\n <div style={{ position: 'absolute', visibility: 'hidden' }}>\n {children}\n </div>,\n document.body,\n )}\n </StyledTypewriter>\n ),\n [\n children,\n cursorType,\n handleClick,\n hasRenderedChildrenOnce,\n isAnimatingText,\n pseudoTextHTML,\n shouldHideCursor,\n shouldPreventBlinkingCursor,\n shouldRemainSingleLine,\n shownText,\n sortedChildren,\n textStyle,\n ],\n );\n};\n\nTypewriter.displayName = 'Typewriter';\n\nexport default Typewriter;\n"],"mappings":"AAAA,SAASA,mBAAmB,EAAEC,cAAc,QAAQ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Ae,EACfmB,cAAc,EACd/E,gBAAgB,EAChBiB,2BAA2B,EAC3BhB,sBAAsB,EACtB6E,SAAS,EACTlD,cAAc,EACdlB,SAAS,CAEjB,CAAC;AACL,CAAC;AAEDzB,UAAU,CAAC4G,WAAW,GAAG,YAAY;AAErC,eAAe5G,UAAU","ignoreList":[]}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { TypewriterSpeed } from '../../types/speed';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Returns a substring of an HTML string while preserving HTML structure.
|
|
3
5
|
*
|
|
@@ -146,26 +148,54 @@ export const shuffleArray = array => {
|
|
|
146
148
|
}
|
|
147
149
|
return result;
|
|
148
150
|
};
|
|
149
|
-
export const calculateAutoSpeed =
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
if (
|
|
151
|
+
export const calculateAutoSpeed = ema => {
|
|
152
|
+
// nested timer calls are clamped to a 4ms minimum
|
|
153
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout#reasons_for_longer_delays_than_specified
|
|
154
|
+
const MINIMUM_TIMEOUT = 4;
|
|
155
|
+
if (ema <= 0) {
|
|
156
|
+
return {
|
|
157
|
+
speed: TypewriterSpeed.ExtraSlow,
|
|
158
|
+
steps: 1
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
const msPerChar = 1000 / ema;
|
|
162
|
+
if (msPerChar >= MINIMUM_TIMEOUT) {
|
|
161
163
|
return {
|
|
162
|
-
speed:
|
|
163
|
-
steps:
|
|
164
|
+
speed: msPerChar,
|
|
165
|
+
steps: 1
|
|
164
166
|
};
|
|
165
167
|
}
|
|
168
|
+
const steps = Math.max(1, MINIMUM_TIMEOUT / msPerChar);
|
|
169
|
+
return {
|
|
170
|
+
speed: MINIMUM_TIMEOUT,
|
|
171
|
+
steps
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
export const calculateEMA = ({
|
|
175
|
+
currentEMA,
|
|
176
|
+
newValue,
|
|
177
|
+
alpha = 0.25
|
|
178
|
+
}) => alpha * newValue + (1 - alpha) * currentEMA;
|
|
179
|
+
export const updateChunkStreamingSpeedEMA = ({
|
|
180
|
+
currentLength,
|
|
181
|
+
state
|
|
182
|
+
}) => {
|
|
183
|
+
const now = Date.now();
|
|
184
|
+
const deltaTime = now - (state?.lastTimestamp ?? now);
|
|
185
|
+
if (deltaTime <= 0) return {
|
|
186
|
+
...state,
|
|
187
|
+
lastTimestamp: now
|
|
188
|
+
};
|
|
189
|
+
const deltaLength = currentLength - state.lastLength;
|
|
190
|
+
const charsPerSecond = Math.max(0, deltaLength / deltaTime * 1000);
|
|
191
|
+
const newEMA = calculateEMA({
|
|
192
|
+
currentEMA: state.ema,
|
|
193
|
+
newValue: charsPerSecond
|
|
194
|
+
});
|
|
166
195
|
return {
|
|
167
|
-
|
|
168
|
-
|
|
196
|
+
lastTimestamp: now,
|
|
197
|
+
lastLength: currentLength,
|
|
198
|
+
ema: newEMA
|
|
169
199
|
};
|
|
170
200
|
};
|
|
171
201
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["getSubTextFromHTML","html","length","div","document","createElement","innerHTML","text","currLength","escapeText","value","replace","escapeAttr","String","VOID_ELEMENTS","Set","traverse","node","nodeType","textContent","nodeText","remaining","substring","element","nodeName","toLowerCase","attributes","attribute","name","isVoid","has","i","childNodes","childNode","getCharactersCount","count","trim","Array","from","forEach","shuffleArray","array","result","j","Math","floor","random","calculateAutoSpeed","fullTextLength","currentPosition","baseSpeedFactor","MIN_SPEED","MAX_SPEED","remainingLength","speed","min","steps"],"sources":["../../../../src/components/typewriter/utils.ts"],"sourcesContent":["/**\n * Returns a substring of an HTML string while preserving HTML structure.\n *\n * Core rules:\n * - Element nodes are re-serialized as tags (start/end) to keep structure.\n * - Text nodes are always HTML-escaped on output. This prevents that previously\n * escaped text (like \"<div>\") turns into real tags during the DOM round trip.\n * - Attribute values are HTML-escaped on output.\n * - Void elements are serialized without closing tags.\n * - For TWIGNORE/TW-IGNORE elements, the innerHTML is passed through so that\n * their content (including real HTML) remains untouched.\n * - On early cutoff (once the length limit is reached), already opened tags are\n * properly closed to keep the result valid HTML.\n *\n * Note on length counting:\n * - The length is based on the decoded textContent length (as the DOM provides),\n * not on byte length nor escaped entity length. This mirrors how the text is perceived.\n *\n * @param html The input HTML string; may contain a mix of real HTML and already escaped HTML.\n * @param length The maximum number of text characters (based on textContent) to include.\n * @returns A valid HTML string containing up to the specified number of text characters,\n * preserving HTML tags and keeping escaped text escaped.\n */\nexport const getSubTextFromHTML = (html: string, length: number): string => {\n const div = document.createElement('div');\n\n div.innerHTML = html;\n\n let text = '';\n let currLength = 0;\n\n // Escape text node content to ensure that decoded \"<\" and \">\" do not become real tags.\n const escapeText = (value: string): string =>\n value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');\n\n // Escape attribute values safely.\n const escapeAttr = (value: string): string =>\n String(value)\n .replace(/&/g, '&')\n .replace(/\"/g, '"')\n .replace(/</g, '<')\n .replace(/>/g, '>');\n\n // HTML void elements (must not have closing tags)\n const VOID_ELEMENTS = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n ]);\n\n // Traverses nodes and appends to \"text\".\n // Returns false to signal \"stop traversal\" once the length limit is reached.\n const traverse = (node: Node): boolean => {\n // Text node\n if (node.nodeType === 3 && typeof node.textContent === 'string') {\n const nodeText = node.textContent;\n const remaining = length - currLength;\n\n if (remaining <= 0) {\n return false;\n }\n\n if (nodeText.length <= remaining) {\n // Always escape text before writing to output\n text += escapeText(nodeText);\n currLength += nodeText.length;\n } else {\n // Cut the text and stop traversal\n text += escapeText(nodeText.substring(0, remaining));\n currLength += remaining;\n return false;\n }\n\n return true;\n }\n\n // Element node\n if (node.nodeType === 1) {\n const element = node as Element;\n\n // Pass-through for TWIGNORE/TW-IGNORE: keep their HTML as-is.\n if (element.nodeName === 'TWIGNORE' || element.nodeName === 'TW-IGNORE') {\n // element.innerHTML serializes children; escaped text stays escaped,\n // real HTML stays HTML — exactly what we want here.\n text += element.innerHTML;\n return true;\n }\n\n const nodeName = element.nodeName.toLowerCase();\n\n // Serialize attributes safely\n let attributes = '';\n // @ts-expect-error: attributes is a NodeListOf<Attr>\n // eslint-disable-next-line no-restricted-syntax\n for (const attribute of element.attributes) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/restrict-template-expressions,@typescript-eslint/no-unsafe-argument\n attributes += ` ${attribute.name}=\"${escapeAttr(attribute.value)}\"`;\n }\n\n // Open tag\n text += `<${nodeName}${attributes}>`;\n\n // Void elements: do not recurse children and do not emit a closing tag\n const isVoid = VOID_ELEMENTS.has(nodeName);\n if (!isVoid) {\n // Recurse through children until limit is reached\n for (let i = 0; i < element.childNodes.length; i++) {\n const childNode = element.childNodes[i];\n if (childNode && !traverse(childNode)) {\n // On early stop: close this tag to keep valid HTML, then bubble stop.\n text += `</${nodeName}>`;\n return false;\n }\n }\n\n // Close tag after all children\n text += `</${nodeName}>`;\n }\n\n return true;\n }\n\n // Other node types (comments, etc.) are ignored for text length\n return true;\n };\n\n // Traverse top-level children\n for (let i = 0; i < div.childNodes.length; i++) {\n const childNode = div.childNodes[i];\n if (childNode && !traverse(childNode)) {\n return text;\n }\n }\n\n return text;\n};\n\nexport const getCharactersCount = (html: string): number => {\n const div = document.createElement('div');\n\n div.innerHTML = html;\n\n let count = 0;\n\n const traverse = (node: Node): void => {\n if (node.nodeName === 'TWIGNORE') {\n count += 1;\n } else if (node.nodeType === 3 && typeof node.textContent === 'string') {\n count += node.textContent.trim().length;\n } else if (node.nodeType === 1) {\n if (node.nodeName === 'CODE' && node.textContent !== null) {\n count += node.textContent.length;\n\n return;\n }\n\n Array.from(node.childNodes).forEach(traverse);\n }\n };\n\n Array.from(div.childNodes).forEach(traverse);\n\n return count;\n};\n\nexport const shuffleArray = <T>(array: T[]): T[] => {\n const result = Array.from(array);\n\n for (let i = result.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n [result[i], result[j]] = [result[j]!, result[i]!];\n }\n\n return result;\n};\n\ninterface CalculateAutoSpeedProps {\n fullTextLength: number;\n currentPosition: number;\n baseSpeedFactor: number;\n}\n\nexport const calculateAutoSpeed = ({\n fullTextLength,\n currentPosition,\n baseSpeedFactor,\n}: CalculateAutoSpeedProps): { speed: number; steps: number } => {\n const MIN_SPEED = 1;\n const MAX_SPEED = 10;\n\n const remainingLength = fullTextLength - currentPosition;\n\n // Calculate the speed with the remaining text length and the baseSpeedFactor\n const speed = Math.min(baseSpeedFactor / remainingLength, MAX_SPEED);\n\n if (speed < MIN_SPEED) {\n return { speed: 1, steps: 2 };\n }\n\n return { speed, steps: 1 };\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,kBAAkB,GAAGA,CAACC,IAAY,EAAEC,MAAc,KAAa;EACxE,MAAMC,GAAG,GAAGC,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAEzCF,GAAG,CAACG,SAAS,GAAGL,IAAI;EAEpB,IAAIM,IAAI,GAAG,EAAE;EACb,IAAIC,UAAU,GAAG,CAAC;;EAElB;EACA,MAAMC,UAAU,GAAIC,KAAa,IAC7BA,KAAK,CAACC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAACA,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAACA,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;;EAE5E;EACA,MAAMC,UAAU,GAAI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IACxC,MAAMY,CAAC,GAAGC,IAAI,CAACC,KAAK,CAACD,IAAI,CAACE,MAAM,CAAC,CAAC,IAAIf,CAAC,GAAG,CAAC,CAAC,CAAC;;IAE7C;IACA,CAACW,MAAM,CAACX,CAAC,CAAC,EAAEW,MAAM,CAACC,CAAC,CAAC,CAAC,GAAG,CAACD,MAAM,CAACC,CAAC,CAAC,EAAGD,MAAM,CAACX,CAAC,CAAC,CAAE;EACrD;EAEA,OAAOW,MAAM;AACjB,CAAC;AAQD,OAAO,MAAMK,kBAAkB,GAAGA,CAAC;EAC/BC,cAAc;EACdC,eAAe;EACfC;AACqB,CAAC,KAAuC;EAC7D,MAAMC,SAAS,GAAG,CAAC;EACnB,MAAMC,SAAS,GAAG,EAAE;EAEpB,MAAMC,eAAe,GAAGL,cAAc,GAAGC,eAAe;;EAExD;EACA,MAAMK,KAAK,GAAGV,IAAI,CAACW,GAAG,CAACL,eAAe,GAAGG,eAAe,EAAED,SAAS,CAAC;EAEpE,IAAIE,KAAK,GAAGH,SAAS,EAAE;IACnB,OAAO;MAAEG,KAAK,EAAE,CAAC;MAAEE,KAAK,EAAE;IAAE,CAAC;EACjC;EAEA,OAAO;IAAEF,KAAK;IAAEE,KAAK,EAAE;EAAE,CAAC;AAC9B,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"utils.js","names":["TypewriterSpeed","getSubTextFromHTML","html","length","div","document","createElement","innerHTML","text","currLength","escapeText","value","replace","escapeAttr","String","VOID_ELEMENTS","Set","traverse","node","nodeType","textContent","nodeText","remaining","substring","element","nodeName","toLowerCase","attributes","attribute","name","isVoid","has","i","childNodes","childNode","getCharactersCount","count","trim","Array","from","forEach","shuffleArray","array","result","j","Math","floor","random","calculateAutoSpeed","ema","MINIMUM_TIMEOUT","speed","ExtraSlow","steps","msPerChar","max","calculateEMA","currentEMA","newValue","alpha","updateChunkStreamingSpeedEMA","currentLength","state","now","Date","deltaTime","lastTimestamp","deltaLength","lastLength","charsPerSecond","newEMA"],"sources":["../../../../src/components/typewriter/utils.ts"],"sourcesContent":["import { TypewriterSpeed } from '../../types/speed';\n\n/**\n * Returns a substring of an HTML string while preserving HTML structure.\n *\n * Core rules:\n * - Element nodes are re-serialized as tags (start/end) to keep structure.\n * - Text nodes are always HTML-escaped on output. This prevents that previously\n * escaped text (like \"<div>\") turns into real tags during the DOM round trip.\n * - Attribute values are HTML-escaped on output.\n * - Void elements are serialized without closing tags.\n * - For TWIGNORE/TW-IGNORE elements, the innerHTML is passed through so that\n * their content (including real HTML) remains untouched.\n * - On early cutoff (once the length limit is reached), already opened tags are\n * properly closed to keep the result valid HTML.\n *\n * Note on length counting:\n * - The length is based on the decoded textContent length (as the DOM provides),\n * not on byte length nor escaped entity length. This mirrors how the text is perceived.\n *\n * @param html The input HTML string; may contain a mix of real HTML and already escaped HTML.\n * @param length The maximum number of text characters (based on textContent) to include.\n * @returns A valid HTML string containing up to the specified number of text characters,\n * preserving HTML tags and keeping escaped text escaped.\n */\nexport const getSubTextFromHTML = (html: string, length: number): string => {\n const div = document.createElement('div');\n\n div.innerHTML = html;\n\n let text = '';\n let currLength = 0;\n\n // Escape text node content to ensure that decoded \"<\" and \">\" do not become real tags.\n const escapeText = (value: string): string =>\n value.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');\n\n // Escape attribute values safely.\n const escapeAttr = (value: string): string =>\n String(value)\n .replace(/&/g, '&')\n .replace(/\"/g, '"')\n .replace(/</g, '<')\n .replace(/>/g, '>');\n\n // HTML void elements (must not have closing tags)\n const VOID_ELEMENTS = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n ]);\n\n // Traverses nodes and appends to \"text\".\n // Returns false to signal \"stop traversal\" once the length limit is reached.\n const traverse = (node: Node): boolean => {\n // Text node\n if (node.nodeType === 3 && typeof node.textContent === 'string') {\n const nodeText = node.textContent;\n const remaining = length - currLength;\n\n if (remaining <= 0) {\n return false;\n }\n\n if (nodeText.length <= remaining) {\n // Always escape text before writing to output\n text += escapeText(nodeText);\n currLength += nodeText.length;\n } else {\n // Cut the text and stop traversal\n text += escapeText(nodeText.substring(0, remaining));\n currLength += remaining;\n return false;\n }\n\n return true;\n }\n\n // Element node\n if (node.nodeType === 1) {\n const element = node as Element;\n\n // Pass-through for TWIGNORE/TW-IGNORE: keep their HTML as-is.\n if (element.nodeName === 'TWIGNORE' || element.nodeName === 'TW-IGNORE') {\n // element.innerHTML serializes children; escaped text stays escaped,\n // real HTML stays HTML — exactly what we want here.\n text += element.innerHTML;\n return true;\n }\n\n const nodeName = element.nodeName.toLowerCase();\n\n // Serialize attributes safely\n let attributes = '';\n // @ts-expect-error: attributes is a NodeListOf<Attr>\n // eslint-disable-next-line no-restricted-syntax\n for (const attribute of element.attributes) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/restrict-template-expressions,@typescript-eslint/no-unsafe-argument\n attributes += ` ${attribute.name}=\"${escapeAttr(attribute.value)}\"`;\n }\n\n // Open tag\n text += `<${nodeName}${attributes}>`;\n\n // Void elements: do not recurse children and do not emit a closing tag\n const isVoid = VOID_ELEMENTS.has(nodeName);\n if (!isVoid) {\n // Recurse through children until limit is reached\n for (let i = 0; i < element.childNodes.length; i++) {\n const childNode = element.childNodes[i];\n if (childNode && !traverse(childNode)) {\n // On early stop: close this tag to keep valid HTML, then bubble stop.\n text += `</${nodeName}>`;\n return false;\n }\n }\n\n // Close tag after all children\n text += `</${nodeName}>`;\n }\n\n return true;\n }\n\n // Other node types (comments, etc.) are ignored for text length\n return true;\n };\n\n // Traverse top-level children\n for (let i = 0; i < div.childNodes.length; i++) {\n const childNode = div.childNodes[i];\n if (childNode && !traverse(childNode)) {\n return text;\n }\n }\n\n return text;\n};\n\nexport const getCharactersCount = (html: string): number => {\n const div = document.createElement('div');\n\n div.innerHTML = html;\n\n let count = 0;\n\n const traverse = (node: Node): void => {\n if (node.nodeName === 'TWIGNORE') {\n count += 1;\n } else if (node.nodeType === 3 && typeof node.textContent === 'string') {\n count += node.textContent.trim().length;\n } else if (node.nodeType === 1) {\n if (node.nodeName === 'CODE' && node.textContent !== null) {\n count += node.textContent.length;\n\n return;\n }\n\n Array.from(node.childNodes).forEach(traverse);\n }\n };\n\n Array.from(div.childNodes).forEach(traverse);\n\n return count;\n};\n\nexport const shuffleArray = <T>(array: T[]): T[] => {\n const result = Array.from(array);\n\n for (let i = result.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n [result[i], result[j]] = [result[j]!, result[i]!];\n }\n\n return result;\n};\n\nexport const calculateAutoSpeed = (ema: number): { speed: number; steps: number } => {\n // nested timer calls are clamped to a 4ms minimum\n // https://developer.mozilla.org/en-US/docs/Web/API/Window/setTimeout#reasons_for_longer_delays_than_specified\n const MINIMUM_TIMEOUT = 4;\n\n if (ema <= 0) {\n return { speed: TypewriterSpeed.ExtraSlow, steps: 1 };\n }\n\n const msPerChar = 1000 / ema;\n\n if (msPerChar >= MINIMUM_TIMEOUT) {\n return { speed: msPerChar, steps: 1 };\n }\n\n const steps = Math.max(1, MINIMUM_TIMEOUT / msPerChar);\n return { speed: MINIMUM_TIMEOUT, steps };\n};\n\ninterface CalculateEMAProps {\n currentEMA: number;\n newValue: number;\n alpha?: number;\n}\n\nexport const calculateEMA = ({ currentEMA, newValue, alpha = 0.25 }: CalculateEMAProps): number =>\n alpha * newValue + (1 - alpha) * currentEMA;\n\nexport interface ChunkStreamingSpeedState {\n lastTimestamp?: number;\n lastLength: number;\n ema: number;\n}\n\ninterface ChunkStreamingSpeedProps {\n currentLength: number;\n state: ChunkStreamingSpeedState;\n}\n\nexport const updateChunkStreamingSpeedEMA = ({\n currentLength,\n state,\n}: ChunkStreamingSpeedProps): ChunkStreamingSpeedState => {\n const now = Date.now();\n const deltaTime = now - (state?.lastTimestamp ?? now);\n\n if (deltaTime <= 0) return { ...state, lastTimestamp: now };\n\n const deltaLength = currentLength - state.lastLength;\n\n const charsPerSecond = Math.max(0, (deltaLength / deltaTime) * 1000);\n\n const newEMA = calculateEMA({\n currentEMA: state.ema,\n newValue: charsPerSecond,\n });\n\n return {\n lastTimestamp: now,\n lastLength: currentLength,\n ema: newEMA,\n };\n};\n"],"mappings":"AAAA,SAASA,eAAe,QAAQ,mBAAmB;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,GAAGA,CAACC,IAAY,EAAEC,MAAc,KAAa;EACxE,MAAMC,GAAG,GAAGC,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAEzCF,GAAG,CAACG,SAAS,GAAGL,IAAI;EAEpB,IAAIM,IAAI,GAAG,EAAE;EACb,IAAIC,UAAU,GAAG,CAAC;;EAElB;EACA,MAAMC,UAAU,GAAIC,KAAa,IAC7BA,KAAK,CAACC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAACA,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAACA,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;;EAE5E;EACA,MAAMC,UAAU,GAAIF,KAAa,IAC7BG,MAAM,CAACH,KAAK,CAAC,CACRC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CACtBA,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CACvBA,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CACrBA,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;;EAE9B;EACA,MAAMG,aAAa,GAAG,IAAIC,GAAG,CAAC,CAC1B,MAAM,EACN,MAAM,EACN,IAAI,EACJ,KAAK,EACL,OAAO,EACP,IAAI,EACJ,KAAK,EACL,OAAO,EACP,MAAM,EACN,MAAM,EACN,OAAO,EACP,QAAQ,EACR,OAAO,EACP,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U,EAAEP,aAAa;IACzBZ,GAAG,EAAEqB;EACT,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -7,10 +7,6 @@ export type TypewriterProps = {
|
|
|
7
7
|
* The number of characters that will be animated per animation cycle.
|
|
8
8
|
*/
|
|
9
9
|
animationSteps?: number;
|
|
10
|
-
/**
|
|
11
|
-
* The base speed factor to calculate the animation speed.
|
|
12
|
-
*/
|
|
13
|
-
autoSpeedBaseFactor?: number;
|
|
14
10
|
/**
|
|
15
11
|
* The text to type
|
|
16
12
|
*/
|
|
@@ -90,6 +86,11 @@ export type TypewriterProps = {
|
|
|
90
86
|
* Whether the animation speed should be calculated with the chunk interval.
|
|
91
87
|
*/
|
|
92
88
|
shouldCalcAutoSpeed?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Sets how long the animation should last when `shouldCalcAutoSpeed` is enabled in milliseconds.
|
|
91
|
+
* When chunks are streamed, this value will only be used for the initial speed and then change to the speed characters are added at
|
|
92
|
+
*/
|
|
93
|
+
autoSpeedBaseFactor?: number;
|
|
93
94
|
/**
|
|
94
95
|
* Specifies whether the reset of the text should be animated with a backspace animation for
|
|
95
96
|
* multiple texts.
|
|
@@ -24,13 +24,24 @@
|
|
|
24
24
|
export declare const getSubTextFromHTML: (html: string, length: number) => string;
|
|
25
25
|
export declare const getCharactersCount: (html: string) => number;
|
|
26
26
|
export declare const shuffleArray: <T>(array: T[]) => T[];
|
|
27
|
-
|
|
28
|
-
fullTextLength: number;
|
|
29
|
-
currentPosition: number;
|
|
30
|
-
baseSpeedFactor: number;
|
|
31
|
-
}
|
|
32
|
-
export declare const calculateAutoSpeed: ({ fullTextLength, currentPosition, baseSpeedFactor, }: CalculateAutoSpeedProps) => {
|
|
27
|
+
export declare const calculateAutoSpeed: (ema: number) => {
|
|
33
28
|
speed: number;
|
|
34
29
|
steps: number;
|
|
35
30
|
};
|
|
31
|
+
interface CalculateEMAProps {
|
|
32
|
+
currentEMA: number;
|
|
33
|
+
newValue: number;
|
|
34
|
+
alpha?: number;
|
|
35
|
+
}
|
|
36
|
+
export declare const calculateEMA: ({ currentEMA, newValue, alpha }: CalculateEMAProps) => number;
|
|
37
|
+
export interface ChunkStreamingSpeedState {
|
|
38
|
+
lastTimestamp?: number;
|
|
39
|
+
lastLength: number;
|
|
40
|
+
ema: number;
|
|
41
|
+
}
|
|
42
|
+
interface ChunkStreamingSpeedProps {
|
|
43
|
+
currentLength: number;
|
|
44
|
+
state: ChunkStreamingSpeedState;
|
|
45
|
+
}
|
|
46
|
+
export declare const updateChunkStreamingSpeedEMA: ({ currentLength, state, }: ChunkStreamingSpeedProps) => ChunkStreamingSpeedState;
|
|
36
47
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chayns-components/typewriter",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.23",
|
|
4
4
|
"description": "A set of beautiful React components for developing your own applications with chayns.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"browserslist": [
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"typescript": "^5.9.3"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@chayns-components/core": "^5.0.
|
|
73
|
+
"@chayns-components/core": "^5.0.21"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
76
|
"chayns-api": ">=2.2.0",
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
"publishConfig": {
|
|
83
83
|
"access": "public"
|
|
84
84
|
},
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "de5a26c1e674e8b289cea5917110d07d204e7541"
|
|
86
86
|
}
|