@chayns-components/typewriter 5.0.52 → 5.0.53-alpha.1

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.
@@ -24,13 +24,13 @@ const AnimatedTypewriterText = ({
24
24
  };
25
25
  const lastParentWithContent = traverseNodes(ref);
26
26
 
27
- // Removes lastWithContent class from all elements
27
+ // Removes the cursor marker from the previous render.
28
28
  ref.classList.remove('typewriter-lastWithContent');
29
- ref.querySelectorAll('.lastWithContent').forEach(element => {
29
+ ref.querySelectorAll('.typewriter-lastWithContent').forEach(element => {
30
30
  element.classList.remove('typewriter-lastWithContent');
31
31
  });
32
32
 
33
- // Adds lastWithContent class to the last element with content
33
+ // Adds the cursor marker to the last element that still contains text.
34
34
  if (lastParentWithContent) {
35
35
  lastParentWithContent.classList.add('typewriter-lastWithContent');
36
36
  } else {
@@ -1 +1 @@
1
- {"version":3,"file":"AnimatedTypewriterText.js","names":["React","useCallback","useMemo","StyledTypewriterText","AnimatedTypewriterText","shouldHideCursor","shownText","shouldRemainSingleLine","textStyle","updateTypewriterCursor","ref","traverseNodes","node","nodeType","Node","TEXT_NODE","textContent","trim","parentElement","childNodes","Array","from","i","length","result","lastParentWithContent","classList","remove","querySelectorAll","forEach","element","add","createElement","dangerouslySetInnerHTML","__html","$shouldRemainSingleLine","style","$isAnimatingText"],"sources":["../../../../src/components/typewriter/AnimatedTypewriterText.tsx"],"sourcesContent":["import React, { FC, useCallback, useMemo } from 'react';\nimport { CSSPropertiesWithVars } from 'styled-components/dist/types';\nimport { StyledTypewriterText } from './Typewriter.styles';\n\ntype AnimatedTypewriterTextProps = {\n shouldHideCursor: boolean;\n shownText: string;\n textStyle?: CSSPropertiesWithVars;\n shouldRemainSingleLine: boolean;\n};\n\nconst AnimatedTypewriterText: FC<AnimatedTypewriterTextProps> = ({\n shouldHideCursor,\n shownText,\n shouldRemainSingleLine,\n textStyle,\n}) => {\n const updateTypewriterCursor = useCallback(\n (ref: HTMLSpanElement | null) => {\n if (ref && !shouldHideCursor) {\n // Finds the last text node with content.\n const traverseNodes = (node: Node): HTMLElement | null => {\n if (node.nodeType === Node.TEXT_NODE && node.textContent?.trim()) {\n return node.parentElement;\n }\n\n const childNodes = Array.from(node.childNodes);\n for (let i = childNodes.length - 1; i >= 0; i--) {\n const result = traverseNodes(childNodes[i] as Node);\n if (result) {\n return result;\n }\n }\n\n return null;\n };\n\n const lastParentWithContent = traverseNodes(ref);\n\n // Removes lastWithContent class from all elements\n ref.classList.remove('typewriter-lastWithContent');\n ref.querySelectorAll('.lastWithContent').forEach((element) => {\n element.classList.remove('typewriter-lastWithContent');\n });\n\n // Adds lastWithContent class to the last element with content\n if (lastParentWithContent) {\n lastParentWithContent.classList.add('typewriter-lastWithContent');\n } else {\n ref.classList.add('typewriter-lastWithContent');\n }\n }\n },\n [shouldHideCursor],\n );\n\n return useMemo(\n () => (\n <StyledTypewriterText\n ref={(ref) => updateTypewriterCursor(ref)}\n dangerouslySetInnerHTML={{ __html: shownText }}\n $shouldRemainSingleLine={shouldRemainSingleLine}\n style={textStyle}\n $isAnimatingText\n />\n ),\n [shownText, shouldRemainSingleLine, textStyle, updateTypewriterCursor],\n );\n};\n\nexport default AnimatedTypewriterText;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAQC,WAAW,EAAEC,OAAO,QAAQ,OAAO;AAEvD,SAASC,oBAAoB,QAAQ,qBAAqB;AAS1D,MAAMC,sBAAuD,GAAGA,CAAC;EAC7DC,gBAAgB;EAChBC,SAAS;EACTC,sBAAsB;EACtBC;AACJ,CAAC,KAAK;EACF,MAAMC,sBAAsB,GAAGR,WAAW,CACrCS,GAA2B,IAAK;IAC7B,IAAIA,GAAG,IAAI,CAACL,gBAAgB,EAAE;MAC1B;MACA,MAAMM,aAAa,GAAIC,IAAU,IAAyB;QACtD,IAAIA,IAAI,CAACC,QAAQ,KAAKC,IAAI,CAACC,SAAS,IAAIH,IAAI,CAACI,WAAW,EAAEC,IAAI,CAAC,C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EAAEC,sBAAsB,CACzE,CAAC;AACL,CAAC;AAED,eAAeL,sBAAsB","ignoreList":[]}
1
+ {"version":3,"file":"AnimatedTypewriterText.js","names":["React","useCallback","useMemo","StyledTypewriterText","AnimatedTypewriterText","shouldHideCursor","shownText","shouldRemainSingleLine","textStyle","updateTypewriterCursor","ref","traverseNodes","node","nodeType","Node","TEXT_NODE","textContent","trim","parentElement","childNodes","Array","from","i","length","result","lastParentWithContent","classList","remove","querySelectorAll","forEach","element","add","createElement","dangerouslySetInnerHTML","__html","$shouldRemainSingleLine","style","$isAnimatingText"],"sources":["../../../../src/components/typewriter/AnimatedTypewriterText.tsx"],"sourcesContent":["import React, { FC, useCallback, useMemo } from 'react';\nimport { CSSPropertiesWithVars } from 'styled-components/dist/types';\nimport { StyledTypewriterText } from './Typewriter.styles';\n\ntype AnimatedTypewriterTextProps = {\n shouldHideCursor: boolean;\n shownText: string;\n textStyle?: CSSPropertiesWithVars;\n shouldRemainSingleLine: boolean;\n};\n\nconst AnimatedTypewriterText: FC<AnimatedTypewriterTextProps> = ({\n shouldHideCursor,\n shownText,\n shouldRemainSingleLine,\n textStyle,\n}) => {\n const updateTypewriterCursor = useCallback(\n (ref: HTMLSpanElement | null) => {\n if (ref && !shouldHideCursor) {\n // Finds the last text node with content.\n const traverseNodes = (node: Node): HTMLElement | null => {\n if (node.nodeType === Node.TEXT_NODE && node.textContent?.trim()) {\n return node.parentElement;\n }\n\n const childNodes = Array.from(node.childNodes);\n for (let i = childNodes.length - 1; i >= 0; i--) {\n const result = traverseNodes(childNodes[i] as Node);\n if (result) {\n return result;\n }\n }\n\n return null;\n };\n\n const lastParentWithContent = traverseNodes(ref);\n\n // Removes the cursor marker from the previous render.\n ref.classList.remove('typewriter-lastWithContent');\n ref.querySelectorAll('.typewriter-lastWithContent').forEach((element) => {\n element.classList.remove('typewriter-lastWithContent');\n });\n\n // Adds the cursor marker to the last element that still contains text.\n if (lastParentWithContent) {\n lastParentWithContent.classList.add('typewriter-lastWithContent');\n } else {\n ref.classList.add('typewriter-lastWithContent');\n }\n }\n },\n [shouldHideCursor],\n );\n\n return useMemo(\n () => (\n <StyledTypewriterText\n ref={(ref) => updateTypewriterCursor(ref)}\n dangerouslySetInnerHTML={{ __html: shownText }}\n $shouldRemainSingleLine={shouldRemainSingleLine}\n style={textStyle}\n $isAnimatingText\n />\n ),\n [shownText, shouldRemainSingleLine, textStyle, updateTypewriterCursor],\n );\n};\n\nexport default AnimatedTypewriterText;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAQC,WAAW,EAAEC,OAAO,QAAQ,OAAO;AAEvD,SAASC,oBAAoB,QAAQ,qBAAqB;AAS1D,MAAMC,sBAAuD,GAAGA,CAAC;EAC7DC,gBAAgB;EAChBC,SAAS;EACTC,sBAAsB;EACtBC;AACJ,CAAC,KAAK;EACF,MAAMC,sBAAsB,GAAGR,WAAW,CACrCS,GAA2B,IAAK;IAC7B,IAAIA,GAAG,IAAI,CAACL,gBAAgB,EAAE;MAC1B;MACA,MAAMM,aAAa,GAAIC,IAAU,IAAyB;QACtD,IAAIA,IAAI,CAACC,QAAQ,KAAKC,IAAI,CAACC,SAAS,IAAIH,IAAI,CAACI,WAAW,EAAEC,IAAI,CAAC,CAAC,EAAE;UAC9D,OAAOL,IAAI,CAACM,aAAa;QAC7B;QAEA,MAAMC,UAAU,GAAGC,KAAK,CAACC,IAAI,CAACT,IAAI,CAACO,UAAU,CAAC;QAC9C,KAAK,IAAIG,CAAC,GAAGH,UAAU,CAACI,MAAM,GAAG,CAAC,EAAED,CAAC,IAAI,CAAC,EAAEA,CAAC,EAAE,EAAE;UAC7C,MAAME,MAAM,GAAGb,aAAa,CAACQ,UAAU,CAACG,CAAC,CAAS,CAAC;UACnD,IAAIE,MAAM,EAAE;YACR,OAAOA,MAAM;UACjB;QACJ;QAEA,OAAO,IAAI;MACf,CAAC;MAED,MAAMC,qBAAqB,GAAGd,aAAa,CAACD,GAAG,CAAC;;MAEhD;MACAA,GAAG,CAACgB,SAAS,CAACC,MAAM,CAAC,4BAA4B,CAAC;MAClDjB,GAAG,CAACkB,gBAAgB,CAAC,6BAA6B,CAAC,CAACC,OAAO,CAAEC,OAAO,IAAK;QACrEA,OAAO,CAACJ,SAAS,CAACC,MAAM,CAAC,4BAA4B,CAAC;MAC1D,CAAC,CAAC;;MAEF;MACA,IAAIF,qBAAqB,EAAE;QACvBA,qBAAqB,CAACC,SAAS,CAACK,GAAG,CAAC,4BAA4B,CAAC;MACrE,CAAC,MAAM;QACHrB,GAAG,CAACgB,SAAS,CAACK,GAAG,CAAC,4BAA4B,CAAC;MACnD;IACJ;EACJ,CAAC,EACD,CAAC1B,gBAAgB,CACrB,CAAC;EAED,OAAOH,OAAO,CACV,mBACIF,KAAA,CAAAgC,aAAA,CAAC7B,oBAAoB;IACjBO,GAAG,EAAGA,GAAG,IAAKD,sBAAsB,CAACC,GAAG,CAAE;IAC1CuB,uBAAuB,EAAE;MAAEC,MAAM,EAAE5B;IAAU,CAAE;IAC/C6B,uBAAuB,EAAE5B,sBAAuB;IAChD6B,KAAK,EAAE5B,SAAU;IACjB6B,gBAAgB;EAAA,CACnB,CACJ,EACD,CAAC/B,SAAS,EAAEC,sBAAsB,EAAEC,SAAS,EAAEC,sBAAsB,CACzE,CAAC;AACL,CAAC;AAED,eAAeL,sBAAsB","ignoreList":[]}
@@ -8,6 +8,7 @@ import { TypewriterDelay, TypewriterSpeed } from '../../types/speed';
8
8
  import AnimatedTypewriterText from './AnimatedTypewriterText';
9
9
  import { StyledTypewriter, StyledTypewriterPseudoText, StyledTypewriterText } from './Typewriter.styles';
10
10
  import { calculateAutoSpeed, getCharactersCount, getSubTextFromHTML, shuffleArray, updateChunkStreamingSpeedEMA } from './utils';
11
+ import useTypewriterAnimation from './useTypewriterAnimation';
11
12
  const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
12
13
  const Typewriter = ({
13
14
  children,
@@ -37,9 +38,6 @@ const Typewriter = ({
37
38
  }) => {
38
39
  const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);
39
40
  const [hasRenderedChildrenOnce, setHasRenderedChildrenOnce] = useState(false);
40
- const [shouldPreventBlinkingCursor, setShouldPreventBlinkingCursor] = useState(false);
41
- const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);
42
- const [shouldStopAnimation, setShouldStopAnimation] = useState(false);
43
41
  const autoSpeed = useRef();
44
42
  const autoSteps = useRef(animationSteps);
45
43
  const functions = useFunctions();
@@ -97,8 +95,6 @@ const Typewriter = ({
97
95
  lastLength: charactersCount,
98
96
  ema: charactersCount / (autoSpeedBaseFactor / 1000)
99
97
  });
100
- const [shownCharCount, setShownCharCount] = useState(charactersCount > 0 ? 0 : textContent.length);
101
- const currentPosition = useRef(0);
102
98
  useEffect(() => {
103
99
  if (shouldUseResetAnimation) {
104
100
  chunkIntervalExponentialMovingAverage.current = {
@@ -124,100 +120,38 @@ const Typewriter = ({
124
120
  autoSpeed.current = calculatedAutoSpeed;
125
121
  autoSteps.current = steps;
126
122
  }, [animationSteps, charactersCount, shouldCalcAutoSpeed]);
123
+ const handleSetNextChildrenIndex = useCallback(() => {
124
+ setCurrentChildrenIndex(prevIndex => {
125
+ const nextIndex = prevIndex + 1;
126
+ return nextIndex > childrenCount - 1 ? 0 : nextIndex;
127
+ });
128
+ }, [childrenCount]);
129
+ const {
130
+ handleClick,
131
+ isResetAnimationActive,
132
+ shownCharCount,
133
+ shouldPreventBlinkingCursor
134
+ } = useTypewriterAnimation({
135
+ areMultipleChildrenGiven,
136
+ autoSpeedRef: autoSpeed,
137
+ autoStepsRef: autoSteps,
138
+ charactersCount,
139
+ cursorType,
140
+ nextTextDelay,
141
+ onAdvanceText: handleSetNextChildrenIndex,
142
+ onResetAnimationEnd,
143
+ onResetAnimationStart,
144
+ onTypingAnimationEnd,
145
+ onTypingAnimationStart,
146
+ resetDelay,
147
+ resetSpeed,
148
+ shouldUseResetAnimation,
149
+ shouldWaitForContent,
150
+ speed,
151
+ startDelay,
152
+ textContentLength: textContent.length
153
+ });
127
154
  const isAnimatingText = shownCharCount < textContent.length || shouldForceCursorAnimation || areMultipleChildrenGiven || textContent.length === 0;
128
- const handleClick = useCallback(event => {
129
- event.stopPropagation();
130
- event.preventDefault();
131
- setShouldStopAnimation(true);
132
- }, []);
133
- const handleSetNextChildrenIndex = useCallback(() => setCurrentChildrenIndex(() => {
134
- let newIndex = currentChildrenIndex + 1;
135
- if (newIndex > childrenCount - 1) {
136
- newIndex = 0;
137
- }
138
- return newIndex;
139
- }), [childrenCount, currentChildrenIndex]);
140
- useEffect(() => {
141
- let interval;
142
- if (shouldStopAnimation || charactersCount === 0) {
143
- setShownCharCount(textContent.length);
144
- currentPosition.current = textContent.length;
145
- } else if (isResetAnimationActive) {
146
- if (typeof onResetAnimationStart === 'function') {
147
- onResetAnimationStart();
148
- }
149
- interval = window.setInterval(() => {
150
- setShownCharCount(prevState => {
151
- const nextState = prevState - autoSteps.current;
152
- currentPosition.current = nextState;
153
- if (nextState === 0) {
154
- window.clearInterval(interval);
155
- if (typeof onResetAnimationEnd === 'function') {
156
- onResetAnimationEnd();
157
- }
158
- if (areMultipleChildrenGiven) {
159
- setTimeout(() => {
160
- setIsResetAnimationActive(false);
161
- handleSetNextChildrenIndex();
162
- }, nextTextDelay);
163
- }
164
- }
165
- return nextState;
166
- });
167
- }, resetSpeed);
168
- } else {
169
- const startTypingAnimation = () => {
170
- if (cursorType === CursorType.Thin) {
171
- setShouldPreventBlinkingCursor(true);
172
- }
173
- if (typeof onTypingAnimationStart === 'function') {
174
- onTypingAnimationStart();
175
- }
176
- const runTypingInterval = () => {
177
- setShownCharCount(prevState => {
178
- let nextState = Math.min(prevState + autoSteps.current, charactersCount);
179
- if (nextState >= charactersCount && !shouldWaitForContent) {
180
- window.clearInterval(interval);
181
- if (cursorType === CursorType.Thin) {
182
- setShouldPreventBlinkingCursor(false);
183
- }
184
- if (typeof onTypingAnimationEnd === 'function') {
185
- onTypingAnimationEnd();
186
- }
187
-
188
- /**
189
- * At this point, the next value for "shownCharCount" is deliberately set to
190
- * the length of the textContent to correctly display HTML elements
191
- * after the last letter.
192
- */
193
- nextState = textContent.length;
194
- if (areMultipleChildrenGiven) {
195
- setTimeout(() => {
196
- if (shouldUseResetAnimation) {
197
- setIsResetAnimationActive(true);
198
- } else {
199
- setShownCharCount(0);
200
- setTimeout(handleSetNextChildrenIndex, nextTextDelay);
201
- }
202
- }, resetDelay);
203
- }
204
- }
205
- currentPosition.current = nextState;
206
- return nextState;
207
- });
208
- };
209
- interval = window.setInterval(runTypingInterval, autoSpeed.current ?? speed);
210
- };
211
- if (startDelay) {
212
- setTimeout(startTypingAnimation, startDelay);
213
- } else {
214
- startTypingAnimation();
215
- }
216
- }
217
- return () => {
218
- window.clearInterval(interval);
219
- };
220
- }, [areMultipleChildrenGiven, autoSteps, charactersCount, cursorType, handleSetNextChildrenIndex, isResetAnimationActive, nextTextDelay, onResetAnimationEnd, onResetAnimationStart, onTypingAnimationEnd, onTypingAnimationStart, resetDelay, resetSpeed, shouldStopAnimation, shouldUseResetAnimation, shouldWaitForContent, speed, startDelay, textContent.length]);
221
155
  useEffect(() => {
222
156
  if (!isAnimatingText && typeof onFinish === 'function') {
223
157
  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","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","lastLength","ema","shownCharCount","setShownCharCount","currentPosition","current","currentLength","state","undefined","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 const chunkIntervalExponentialMovingAverage = useRef<ChunkStreamingSpeedState>({\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 const { speed: calculatedAutoSpeed, steps } = calculateAutoSpeed(\n chunkIntervalExponentialMovingAverage.current.ema,\n );\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 || '&#8203;';\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,SACIC,kBAAkB,EAElBC,kBAAkB,EAClBC,kBAAkB,EAClBC,YAAY,EACZC,4BAA4B,QACzB,SAAS;AAEhB,MAAMC,yBAAyB,GAAG,OAAOC,MAAM,KAAK,WAAW,GAAGnB,eAAe,GAAGD,SAAS;AAkH7F,MAAMqB,UAA+B,GAAGA,CAAC;EACr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AGrB,SAChE;IACDb,KAAK,EAAEjC;EAAU,GAEhB,OAAOkB,cAAc,KAAK,QAAQ,GAAGA,cAAc,GAAG4B,SACrC,CACzB,EACAG,eAAe,iBACZjG,KAAA,CAAA2E,aAAA,CAAC7D,0BAA0B;IACvB0G,gBAAgB,EAAEvB,eAAgB;IAClCwB,iBAAiB,EAAEnF,gBAAiB;IACpCsF,uBAAuB,EAAE;MAAEC,MAAM,EAAET;IAAe;EAAE,CACvD,CACJ,EAKA,CAAC/D,uBAAuB,iBACrB9C,YAAY,cACRP,KAAA,CAAA2E,aAAA;IAAKM,KAAK,EAAE;MAAE6C,QAAQ,EAAE,UAAU;MAAEC,UAAU,EAAE;IAAS;EAAE,GACtDvG,QACA,CAAC,EACNwG,QAAQ,CAACC,IACb,CACU,CACrB,EACD,CACIzG,QAAQ,EACRC,UAAU,EACVyE,WAAW,EACX7C,uBAAuB,EACvB4C,eAAe,EACfmB,cAAc,EACd9E,gBAAgB,EAChBiB,2BAA2B,EAC3BhB,sBAAsB,EACtB4E,SAAS,EACTjD,cAAc,EACdlB,SAAS,CAEjB,CAAC;AACL,CAAC;AAEDzB,UAAU,CAAC2G,WAAW,GAAG,YAAY;AAErC,eAAe3G,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","useTypewriterAnimation","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","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","lastLength","ema","current","currentLength","state","undefined","calculatedAutoSpeed","steps","handleSetNextChildrenIndex","prevIndex","nextIndex","handleClick","isResetAnimationActive","shownCharCount","shouldPreventBlinkingCursor","autoSpeedRef","autoStepsRef","onAdvanceText","textContentLength","isAnimatingText","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';\nimport useTypewriterAnimation from './useTypewriterAnimation';\n\nconst useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport type TypewriterProps = {\n /**\n * The number of characters that will be animated per animation step.\n *\n * The step is advanced by the requestAnimationFrame-driven scheduler. When\n * `shouldCalcAutoSpeed` is enabled, the component may override this value dynamically.\n */\n animationSteps?: number;\n /**\n * The content to type.\n *\n * Strings are animated directly. React elements and arrays are rendered to HTML first so the\n * typewriter can preserve nested markup and inline components.\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 *\n * This prop is only used when `children` is an array.\n */\n nextTextDelay?: TypewriterDelay;\n /**\n * Function that is executed when the entire typewriter animation has finished.\n *\n * This callback is not used while more texts are still queued.\n */\n onFinish?: VoidFunction;\n /**\n * Function that is executed when the reset animation has finished.\n *\n * This callback only runs when `shouldUseResetAnimation` is enabled.\n */\n onResetAnimationEnd?: VoidFunction;\n /**\n * Function that is executed when the reset animation has started.\n *\n * This callback only runs when `shouldUseResetAnimation` is enabled.\n */\n onResetAnimationStart?: VoidFunction;\n /**\n * Function that is executed when the typing animation has finished.\n *\n * If multiple texts are given, this function will be executed for each text.\n */\n onTypingAnimationEnd?: VoidFunction;\n /**\n * Function that is executed when the typing animation has started.\n *\n * If multiple texts are given, this function will be executed for each text.\n */\n onTypingAnimationStart?: VoidFunction;\n /**\n * Invisible content that defines the reserved layout size while the animation is running.\n *\n * When omitted, the visible `children` are used as the layout template.\n */\n pseudoChildren?: ReactElement | string;\n /**\n * Waiting time in milliseconds before the typewriter resets the text.\n *\n * This prop is only used when `children` is an array.\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 * Keeps the cursor animated even if the current text is not actively changing.\n */\n shouldForceCursorAnimation?: boolean;\n /**\n * Hides the cursor entirely.\n */\n shouldHideCursor?: boolean;\n /**\n * Keeps the content on a single line and applies ellipsis overflow handling.\n */\n shouldRemainSingleLine?: boolean;\n /**\n * Randomizes the order of `children` when multiple texts are provided.\n */\n shouldSortChildrenRandomly?: boolean;\n /**\n * Makes the hidden sizing text follow the currently revealed chunk instead of the full content.\n */\n shouldUseAnimationHeight?: boolean;\n /**\n * Derives the typing cadence from the observed streaming rate.\n */\n shouldCalcAutoSpeed?: boolean;\n /**\n * Base factor used to initialize the auto-speed EMA.\n */\n autoSpeedBaseFactor?: number;\n /**\n * Animates the reset between multiple texts with a backspace-like effect.\n */\n shouldUseResetAnimation?: boolean;\n /**\n * Keeps the typewriter active while waiting for new content to arrive.\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 * Inline styles for the visible 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 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 const chunkIntervalExponentialMovingAverage = useRef<ChunkStreamingSpeedState>({\n lastLength: charactersCount,\n ema: charactersCount / (autoSpeedBaseFactor / 1000),\n });\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 const { speed: calculatedAutoSpeed, steps } = calculateAutoSpeed(\n chunkIntervalExponentialMovingAverage.current.ema,\n );\n\n autoSpeed.current = calculatedAutoSpeed;\n autoSteps.current = steps;\n }, [animationSteps, charactersCount, shouldCalcAutoSpeed]);\n\n const handleSetNextChildrenIndex = useCallback(() => {\n setCurrentChildrenIndex((prevIndex) => {\n const nextIndex = prevIndex + 1;\n\n return nextIndex > childrenCount - 1 ? 0 : nextIndex;\n });\n }, [childrenCount]);\n\n const { handleClick, isResetAnimationActive, shownCharCount, shouldPreventBlinkingCursor } =\n useTypewriterAnimation({\n areMultipleChildrenGiven,\n autoSpeedRef: autoSpeed,\n autoStepsRef: autoSteps,\n charactersCount,\n cursorType,\n nextTextDelay,\n onAdvanceText: handleSetNextChildrenIndex,\n onResetAnimationEnd,\n onResetAnimationStart,\n onTypingAnimationEnd,\n onTypingAnimationStart,\n resetDelay,\n resetSpeed,\n shouldUseResetAnimation,\n shouldWaitForContent,\n speed,\n startDelay,\n textContentLength: textContent.length,\n });\n\n const isAnimatingText =\n shownCharCount < textContent.length ||\n shouldForceCursorAnimation ||\n areMultipleChildrenGiven ||\n textContent.length === 0;\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 || '&#8203;';\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,SACIC,kBAAkB,EAElBC,kBAAkB,EAClBC,kBAAkB,EAClBC,YAAY,EACZC,4BAA4B,QACzB,SAAS;AAChB,OAAOC,sBAAsB,MAAM,0BAA0B;AAE7D,MAAMC,yBAAyB,GAAG,OAAOC,MAAM,KAAK,WAAW,GAAGpB,eAAe,GAAGD,SAAS;AA2H7F,MAAMsB,UAA+B,GAAGA,CAAC;EACrCC,QAAQ;EACRC,UAAU,GAAGjB,UAAU,CAACkB,OAAO;EAC/BC,aAAa,GAAGlB,eAAe,CAACmB,MAAM;EACtCC,QAAQ;EACRC,mBAAmB;EACnBC,cAAc,GAAG,CAAC;EAClBC,qBAAqB;EACrBC,oBAAoB;EACpBC,sBAAsB;EACtBC,cAAc;EACdC,UAAU,GAAG3B,eAA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F,UAAU","ignoreList":[]}
@@ -0,0 +1,231 @@
1
+ import { useCallback, useEffect, useState } from 'react';
2
+ import { CursorType } from '../../types/cursor';
3
+ const useTypewriterAnimation = ({
4
+ areMultipleChildrenGiven,
5
+ charactersCount,
6
+ cursorType,
7
+ onAdvanceText,
8
+ nextTextDelay,
9
+ onResetAnimationEnd,
10
+ onResetAnimationStart,
11
+ onTypingAnimationEnd,
12
+ onTypingAnimationStart,
13
+ resetDelay,
14
+ resetSpeed,
15
+ shouldUseResetAnimation,
16
+ shouldWaitForContent,
17
+ speed,
18
+ startDelay,
19
+ textContentLength,
20
+ autoSpeedRef,
21
+ autoStepsRef
22
+ }) => {
23
+ const [shouldPreventBlinkingCursor, setShouldPreventBlinkingCursor] = useState(false);
24
+ const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);
25
+ const [shouldStopAnimation, setShouldStopAnimation] = useState(false);
26
+ const [shownCharCount, setShownCharCount] = useState(charactersCount > 0 ? 0 : textContentLength);
27
+ const handleClick = useCallback(event => {
28
+ event.stopPropagation();
29
+ event.preventDefault();
30
+ setShouldStopAnimation(true);
31
+ }, []);
32
+ useEffect(() => {
33
+ let animationFrameId;
34
+ let phaseStartTime = performance.now();
35
+ let lastFrameTime = phaseStartTime;
36
+ let currentShownCharCount = shownCharCount;
37
+ let typingAccumulator = 0;
38
+ let resetAccumulator = 0;
39
+ let hasStartedTyping = false;
40
+ let hasStartedReset = false;
41
+ let hasEndedTyping = false;
42
+ let hasEndedReset = false;
43
+ let phase = isResetAnimationActive ? 'resetting' : 'typing';
44
+ if (startDelay) {
45
+ phase = 'typingDelay';
46
+ }
47
+ const cancelFrame = () => {
48
+ if (typeof animationFrameId === 'number') {
49
+ window.cancelAnimationFrame(animationFrameId);
50
+ animationFrameId = undefined;
51
+ }
52
+ };
53
+ const updateShownCharCount = nextValue => {
54
+ currentShownCharCount = nextValue;
55
+ setShownCharCount(nextValue);
56
+ };
57
+ const startTyping = () => {
58
+ if (hasStartedTyping) {
59
+ return;
60
+ }
61
+ hasStartedTyping = true;
62
+ if (cursorType === CursorType.Thin) {
63
+ setShouldPreventBlinkingCursor(true);
64
+ }
65
+ if (typeof onTypingAnimationStart === 'function') {
66
+ onTypingAnimationStart();
67
+ }
68
+ };
69
+ const finishTyping = () => {
70
+ if (hasEndedTyping) {
71
+ return;
72
+ }
73
+ hasEndedTyping = true;
74
+ if (cursorType === CursorType.Thin) {
75
+ setShouldPreventBlinkingCursor(false);
76
+ }
77
+ if (typeof onTypingAnimationEnd === 'function') {
78
+ onTypingAnimationEnd();
79
+ }
80
+ };
81
+ const startReset = () => {
82
+ if (hasStartedReset) {
83
+ return;
84
+ }
85
+ hasStartedReset = true;
86
+ if (typeof onResetAnimationStart === 'function') {
87
+ onResetAnimationStart();
88
+ }
89
+ };
90
+ const finishReset = () => {
91
+ if (hasEndedReset) {
92
+ return;
93
+ }
94
+ hasEndedReset = true;
95
+ if (typeof onResetAnimationEnd === 'function') {
96
+ onResetAnimationEnd();
97
+ }
98
+ };
99
+ if (shouldStopAnimation || charactersCount === 0) {
100
+ updateShownCharCount(textContentLength);
101
+ return undefined;
102
+ }
103
+ if (phase === 'typing') {
104
+ startTyping();
105
+ } else if (phase === 'resetting') {
106
+ startReset();
107
+ }
108
+ const tick = now => {
109
+ if (shouldStopAnimation || charactersCount === 0) {
110
+ updateShownCharCount(textContentLength);
111
+ cancelFrame();
112
+ return;
113
+ }
114
+ const delta = now - lastFrameTime;
115
+ lastFrameTime = now;
116
+ switch (phase) {
117
+ case 'typingDelay':
118
+ {
119
+ if (now - phaseStartTime < startDelay) {
120
+ break;
121
+ }
122
+ phase = 'typing';
123
+ phaseStartTime = now;
124
+ typingAccumulator = 0;
125
+ startTyping();
126
+ break;
127
+ }
128
+ case 'typing':
129
+ {
130
+ startTyping();
131
+ typingAccumulator += delta;
132
+ const typingInterval = autoSpeedRef.current ?? speed;
133
+ while (typingAccumulator >= typingInterval) {
134
+ typingAccumulator -= typingInterval;
135
+ const nextValue = Math.min(currentShownCharCount + autoStepsRef.current, charactersCount);
136
+ if (nextValue >= charactersCount) {
137
+ updateShownCharCount(textContentLength);
138
+ if (shouldWaitForContent) {
139
+ typingAccumulator = 0;
140
+ break;
141
+ }
142
+ finishTyping();
143
+ if (areMultipleChildrenGiven) {
144
+ phase = 'resetDelay';
145
+ phaseStartTime = now;
146
+ typingAccumulator = 0;
147
+ } else {
148
+ cancelFrame();
149
+ return;
150
+ }
151
+ break;
152
+ }
153
+ updateShownCharCount(nextValue);
154
+ }
155
+ break;
156
+ }
157
+ case 'resetDelay':
158
+ {
159
+ if (now - phaseStartTime < resetDelay) {
160
+ break;
161
+ }
162
+ if (areMultipleChildrenGiven) {
163
+ if (shouldUseResetAnimation) {
164
+ setIsResetAnimationActive(true);
165
+ cancelFrame();
166
+ return;
167
+ }
168
+ updateShownCharCount(0);
169
+ phase = 'nextTextDelay';
170
+ phaseStartTime = now;
171
+ } else {
172
+ cancelFrame();
173
+ return;
174
+ }
175
+ break;
176
+ }
177
+ case 'resetting':
178
+ {
179
+ startReset();
180
+ resetAccumulator += delta;
181
+ const resetInterval = resetSpeed;
182
+ while (resetAccumulator >= resetInterval) {
183
+ resetAccumulator -= resetInterval;
184
+ const nextValue = Math.max(currentShownCharCount - autoStepsRef.current, 0);
185
+ updateShownCharCount(nextValue);
186
+ if (nextValue === 0) {
187
+ finishReset();
188
+ if (areMultipleChildrenGiven) {
189
+ phase = 'nextTextDelay';
190
+ phaseStartTime = now;
191
+ resetAccumulator = 0;
192
+ } else {
193
+ cancelFrame();
194
+ return;
195
+ }
196
+ break;
197
+ }
198
+ }
199
+ break;
200
+ }
201
+ case 'nextTextDelay':
202
+ {
203
+ if (now - phaseStartTime < nextTextDelay) {
204
+ break;
205
+ }
206
+ if (shouldUseResetAnimation) {
207
+ setIsResetAnimationActive(false);
208
+ }
209
+ onAdvanceText?.();
210
+ cancelFrame();
211
+ return;
212
+ }
213
+ default:
214
+ break;
215
+ }
216
+ animationFrameId = window.requestAnimationFrame(tick);
217
+ };
218
+ animationFrameId = window.requestAnimationFrame(tick);
219
+ return () => {
220
+ cancelFrame();
221
+ };
222
+ }, [areMultipleChildrenGiven, charactersCount, cursorType, isResetAnimationActive, nextTextDelay, onResetAnimationEnd, onResetAnimationStart, onTypingAnimationEnd, onTypingAnimationStart, resetDelay, resetSpeed, shouldStopAnimation, shouldUseResetAnimation, shouldWaitForContent, speed, startDelay, textContentLength, autoSpeedRef, autoStepsRef, onAdvanceText]);
223
+ return {
224
+ handleClick,
225
+ isResetAnimationActive,
226
+ shownCharCount,
227
+ shouldPreventBlinkingCursor
228
+ };
229
+ };
230
+ export default useTypewriterAnimation;
231
+ //# sourceMappingURL=useTypewriterAnimation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useTypewriterAnimation.js","names":["useCallback","useEffect","useState","CursorType","useTypewriterAnimation","areMultipleChildrenGiven","charactersCount","cursorType","onAdvanceText","nextTextDelay","onResetAnimationEnd","onResetAnimationStart","onTypingAnimationEnd","onTypingAnimationStart","resetDelay","resetSpeed","shouldUseResetAnimation","shouldWaitForContent","speed","startDelay","textContentLength","autoSpeedRef","autoStepsRef","shouldPreventBlinkingCursor","setShouldPreventBlinkingCursor","isResetAnimationActive","setIsResetAnimationActive","shouldStopAnimation","setShouldStopAnimation","shownCharCount","setShownCharCount","handleClick","event","stopPropagation","preventDefault","animationFrameId","phaseStartTime","performance","now","lastFrameTime","currentShownCharCount","typingAccumulator","resetAccumulator","hasStartedTyping","hasStartedReset","hasEndedTyping","hasEndedReset","phase","cancelFrame","window","cancelAnimationFrame","undefined","updateShownCharCount","nextValue","startTyping","Thin","finishTyping","startReset","finishReset","tick","delta","typingInterval","current","Math","min","resetInterval","max","requestAnimationFrame"],"sources":["../../../../src/components/typewriter/useTypewriterAnimation.ts"],"sourcesContent":["import type { MouseEvent, MutableRefObject } from 'react';\nimport { useCallback, useEffect, useState } from 'react';\nimport { CursorType } from '../../types/cursor';\n\nexport type UseTypewriterAnimationOptions = {\n areMultipleChildrenGiven: boolean;\n charactersCount: number;\n cursorType: CursorType;\n onAdvanceText?: VoidFunction;\n nextTextDelay: number;\n onResetAnimationEnd?: VoidFunction;\n onResetAnimationStart?: VoidFunction;\n onTypingAnimationEnd?: VoidFunction;\n onTypingAnimationStart?: VoidFunction;\n resetDelay: number;\n resetSpeed: number;\n shouldUseResetAnimation: boolean;\n shouldWaitForContent?: boolean;\n speed: number;\n startDelay: number;\n textContentLength: number;\n autoSpeedRef: MutableRefObject<number | undefined>;\n autoStepsRef: MutableRefObject<number>;\n};\n\nexport type UseTypewriterAnimationResult = {\n handleClick: (event: MouseEvent) => void;\n isResetAnimationActive: boolean;\n shownCharCount: number;\n shouldPreventBlinkingCursor: boolean;\n};\n\nconst useTypewriterAnimation = ({\n areMultipleChildrenGiven,\n charactersCount,\n cursorType,\n onAdvanceText,\n nextTextDelay,\n onResetAnimationEnd,\n onResetAnimationStart,\n onTypingAnimationEnd,\n onTypingAnimationStart,\n resetDelay,\n resetSpeed,\n shouldUseResetAnimation,\n shouldWaitForContent,\n speed,\n startDelay,\n textContentLength,\n autoSpeedRef,\n autoStepsRef,\n}: UseTypewriterAnimationOptions): UseTypewriterAnimationResult => {\n const [shouldPreventBlinkingCursor, setShouldPreventBlinkingCursor] = useState(false);\n const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);\n const [shouldStopAnimation, setShouldStopAnimation] = useState(false);\n const [shownCharCount, setShownCharCount] = useState(\n charactersCount > 0 ? 0 : textContentLength,\n );\n\n const handleClick = useCallback((event: MouseEvent) => {\n event.stopPropagation();\n event.preventDefault();\n\n setShouldStopAnimation(true);\n }, []);\n\n useEffect(() => {\n let animationFrameId: number | undefined;\n let phaseStartTime = performance.now();\n let lastFrameTime = phaseStartTime;\n let currentShownCharCount = shownCharCount;\n let typingAccumulator = 0;\n let resetAccumulator = 0;\n let hasStartedTyping = false;\n let hasStartedReset = false;\n let hasEndedTyping = false;\n let hasEndedReset = false;\n\n type AnimationPhase =\n | 'typingDelay'\n | 'typing'\n | 'resetDelay'\n | 'resetting'\n | 'nextTextDelay';\n let phase: AnimationPhase = isResetAnimationActive ? 'resetting' : 'typing';\n\n if (startDelay) {\n phase = 'typingDelay';\n }\n\n const cancelFrame = () => {\n if (typeof animationFrameId === 'number') {\n window.cancelAnimationFrame(animationFrameId);\n animationFrameId = undefined;\n }\n };\n\n const updateShownCharCount = (nextValue: number): void => {\n currentShownCharCount = nextValue;\n setShownCharCount(nextValue);\n };\n\n const startTyping = (): void => {\n if (hasStartedTyping) {\n return;\n }\n\n hasStartedTyping = true;\n\n if (cursorType === CursorType.Thin) {\n setShouldPreventBlinkingCursor(true);\n }\n\n if (typeof onTypingAnimationStart === 'function') {\n onTypingAnimationStart();\n }\n };\n\n const finishTyping = (): void => {\n if (hasEndedTyping) {\n return;\n }\n\n hasEndedTyping = true;\n\n if (cursorType === CursorType.Thin) {\n setShouldPreventBlinkingCursor(false);\n }\n\n if (typeof onTypingAnimationEnd === 'function') {\n onTypingAnimationEnd();\n }\n };\n\n const startReset = (): void => {\n if (hasStartedReset) {\n return;\n }\n\n hasStartedReset = true;\n\n if (typeof onResetAnimationStart === 'function') {\n onResetAnimationStart();\n }\n };\n\n const finishReset = (): void => {\n if (hasEndedReset) {\n return;\n }\n\n hasEndedReset = true;\n\n if (typeof onResetAnimationEnd === 'function') {\n onResetAnimationEnd();\n }\n };\n\n if (shouldStopAnimation || charactersCount === 0) {\n updateShownCharCount(textContentLength);\n return undefined;\n }\n\n if (phase === 'typing') {\n startTyping();\n } else if (phase === 'resetting') {\n startReset();\n }\n\n const tick = (now: number): void => {\n if (shouldStopAnimation || charactersCount === 0) {\n updateShownCharCount(textContentLength);\n cancelFrame();\n return;\n }\n\n const delta = now - lastFrameTime;\n lastFrameTime = now;\n\n switch (phase) {\n case 'typingDelay': {\n if (now - phaseStartTime < startDelay) {\n break;\n }\n\n phase = 'typing';\n phaseStartTime = now;\n typingAccumulator = 0;\n startTyping();\n break;\n }\n case 'typing': {\n startTyping();\n typingAccumulator += delta;\n\n const typingInterval = autoSpeedRef.current ?? speed;\n\n while (typingAccumulator >= typingInterval) {\n typingAccumulator -= typingInterval;\n\n const nextValue = Math.min(\n currentShownCharCount + autoStepsRef.current,\n charactersCount,\n );\n\n if (nextValue >= charactersCount) {\n updateShownCharCount(textContentLength);\n\n if (shouldWaitForContent) {\n typingAccumulator = 0;\n break;\n }\n\n finishTyping();\n\n if (areMultipleChildrenGiven) {\n phase = 'resetDelay';\n phaseStartTime = now;\n typingAccumulator = 0;\n } else {\n cancelFrame();\n return;\n }\n\n break;\n }\n\n updateShownCharCount(nextValue);\n }\n\n break;\n }\n case 'resetDelay': {\n if (now - phaseStartTime < resetDelay) {\n break;\n }\n\n if (areMultipleChildrenGiven) {\n if (shouldUseResetAnimation) {\n setIsResetAnimationActive(true);\n cancelFrame();\n return;\n }\n\n updateShownCharCount(0);\n phase = 'nextTextDelay';\n phaseStartTime = now;\n } else {\n cancelFrame();\n return;\n }\n\n break;\n }\n case 'resetting': {\n startReset();\n resetAccumulator += delta;\n\n const resetInterval = resetSpeed;\n\n while (resetAccumulator >= resetInterval) {\n resetAccumulator -= resetInterval;\n\n const nextValue = Math.max(currentShownCharCount - autoStepsRef.current, 0);\n\n updateShownCharCount(nextValue);\n\n if (nextValue === 0) {\n finishReset();\n\n if (areMultipleChildrenGiven) {\n phase = 'nextTextDelay';\n phaseStartTime = now;\n resetAccumulator = 0;\n } else {\n cancelFrame();\n return;\n }\n\n break;\n }\n }\n\n break;\n }\n case 'nextTextDelay': {\n if (now - phaseStartTime < nextTextDelay) {\n break;\n }\n\n if (shouldUseResetAnimation) {\n setIsResetAnimationActive(false);\n }\n\n onAdvanceText?.();\n cancelFrame();\n return;\n }\n default:\n break;\n }\n\n animationFrameId = window.requestAnimationFrame(tick);\n };\n\n animationFrameId = window.requestAnimationFrame(tick);\n\n return () => {\n cancelFrame();\n };\n }, [\n areMultipleChildrenGiven,\n charactersCount,\n cursorType,\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 textContentLength,\n autoSpeedRef,\n autoStepsRef,\n onAdvanceText,\n ]);\n\n return {\n handleClick,\n isResetAnimationActive,\n shownCharCount,\n shouldPreventBlinkingCursor,\n };\n};\n\nexport default useTypewriterAnimation;\n"],"mappings":"AACA,SAASA,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AACxD,SAASC,UAAU,QAAQ,oBAAoB;AA8B/C,MAAMC,sBAAsB,GAAGA,CAAC;EAC5BC,wBAAwB;EACxBC,eAAe;EACfC,UAAU;EACVC,aAAa;EACbC,aAAa;EACbC,mBAAmB;EACnBC,qBAAqB;EACrBC,oBAAoB;EACpBC,sBAAsB;EACtBC,UAAU;EACVC,UAAU;EACVC,uBAAuB;EACvBC,oBAAoB;EACpBC,KAAK;EACLC,UAAU;EACVC,iBAAiB;EACjBC,YAAY;EACZC;AAC2B,CAAC,KAAmC;EAC/D,MAAM,CAACC,2BAA2B,EAAEC,8BAA8B,CAAC,GAAGtB,QAAQ,CAAC,KAAK,CAAC;EACrF,MAAM,CAACuB,sBAAsB,EAAEC,yBAAyB,CAAC,GAAGxB,QAAQ,CAAC,KAAK,CAAC;EAC3E,MAAM,CAACyB,mBAAmB,EAAEC,sBAAsB,CAAC,GAAG1B,QAAQ,CAAC,KAAK,CAAC;EACrE,MAAM,CAAC2B,cAAc,EAAEC,iBAAiB,CAAC,GAAG5B,QAAQ,CAChDI,eAAe,GAAG,CAAC,GAAG,CAAC,GAAGc,iBAC9B,CAAC;EAED,MAAMW,WAAW,GAAG/B,WAAW,CAAEgC,KAAiB,IAAK;IACnDA,KAAK,CAACC,eAAe,CAAC,CAAC;IACvBD,KAAK,CAACE,cAAc,CAAC,CAAC;IAEtBN,sBAAsB,CAAC,IAAI,CA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