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

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.
@@ -32,13 +32,13 @@ const AnimatedTypewriterText = ({
32
32
  };
33
33
  const lastParentWithContent = traverseNodes(ref);
34
34
 
35
- // Removes the cursor marker from the previous render.
35
+ // Removes lastWithContent class from all elements
36
36
  ref.classList.remove('typewriter-lastWithContent');
37
- ref.querySelectorAll('.typewriter-lastWithContent').forEach(element => {
37
+ ref.querySelectorAll('.lastWithContent').forEach(element => {
38
38
  element.classList.remove('typewriter-lastWithContent');
39
39
  });
40
40
 
41
- // Adds the cursor marker to the last element that still contains text.
41
+ // Adds lastWithContent class to the last element with content
42
42
  if (lastParentWithContent) {
43
43
  lastParentWithContent.classList.add('typewriter-lastWithContent');
44
44
  } else {
@@ -1 +1 @@
1
- {"version":3,"file":"AnimatedTypewriterText.js","names":["_react","_interopRequireWildcard","require","_Typewriter","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","AnimatedTypewriterText","shouldHideCursor","shownText","shouldRemainSingleLine","textStyle","updateTypewriterCursor","useCallback","ref","traverseNodes","node","_node$textContent","nodeType","Node","TEXT_NODE","textContent","trim","parentElement","childNodes","Array","from","length","result","lastParentWithContent","classList","remove","querySelectorAll","forEach","element","add","useMemo","createElement","StyledTypewriterText","dangerouslySetInnerHTML","__html","$shouldRemainSingleLine","style","$isAnimatingText","_default","exports"],"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,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,WAAA,GAAAD,OAAA;AAA2D,SAAAD,wBAAAG,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAL,uBAAA,YAAAA,CAAAG,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,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AAC,IAAAgC,QAAA,GAAAC,OAAA,CAAA/C,OAAA,GAEaS,sBAAsB","ignoreList":[]}
1
+ {"version":3,"file":"AnimatedTypewriterText.js","names":["_react","_interopRequireWildcard","require","_Typewriter","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","AnimatedTypewriterText","shouldHideCursor","shownText","shouldRemainSingleLine","textStyle","updateTypewriterCursor","useCallback","ref","traverseNodes","node","_node$textContent","nodeType","Node","TEXT_NODE","textContent","trim","parentElement","childNodes","Array","from","length","result","lastParentWithContent","classList","remove","querySelectorAll","forEach","element","add","useMemo","createElement","StyledTypewriterText","dangerouslySetInnerHTML","__html","$shouldRemainSingleLine","style","$isAnimatingText","_default","exports"],"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,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,WAAA,GAAAD,OAAA;AAA2D,SAAAD,wBAAAG,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAL,uBAAA,YAAAA,CAAAG,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBA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ACC,OAAO,CAAEC,OAAO,IAAK;QAC1DA,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,CAAC3B,gBAAgB,CACrB,CAAC;EAED,OAAO,IAAA4B,cAAO,EACV,mBACIpD,MAAA,CAAAc,OAAA,CAAAuC,aAAA,CAAClD,WAAA,CAAAmD,oBAAoB;IACjBxB,GAAG,EAAGA,GAAG,IAAKF,sBAAsB,CAACE,GAAG,CAAE;IAC1CyB,uBAAuB,EAAE;MAAEC,MAAM,EAAE/B;IAAU,CAAE;IAC/CgC,uBAAuB,EAAE/B,sBAAuB;IAChDgC,KAAK,EAAE/B,SAAU;IACjBgC,gBAAgB;EAAA,CACnB,CACJ,EACD,CAAClC,SAAS,EAAEC,sBAAsB,EAAEC,SAAS,EAAEC,sBAAsB,CACzE,CAAC;AACL,CAAC;AAAC,IAAAgC,QAAA,GAAAC,OAAA,CAAA/C,OAAA,GAEaS,sBAAsB","ignoreList":[]}
@@ -14,7 +14,6 @@ var _speed = require("../../types/speed");
14
14
  var _AnimatedTypewriterText = _interopRequireDefault(require("./AnimatedTypewriterText"));
15
15
  var _Typewriter = require("./Typewriter.styles");
16
16
  var _utils = require("./utils");
17
- var _useTypewriterAnimation = _interopRequireDefault(require("./useTypewriterAnimation"));
18
17
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
19
18
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
20
19
  const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? _react.useLayoutEffect : _react.useEffect;
@@ -47,6 +46,9 @@ const Typewriter = ({
47
46
  var _colorScheme$designSe5, _colorScheme$designSe6, _colorScheme$designSe9, _colorScheme$designSe0;
48
47
  const [currentChildrenIndex, setCurrentChildrenIndex] = (0, _react.useState)(0);
49
48
  const [hasRenderedChildrenOnce, setHasRenderedChildrenOnce] = (0, _react.useState)(false);
49
+ const [shouldPreventBlinkingCursor, setShouldPreventBlinkingCursor] = (0, _react.useState)(false);
50
+ const [isResetAnimationActive, setIsResetAnimationActive] = (0, _react.useState)(false);
51
+ const [shouldStopAnimation, setShouldStopAnimation] = (0, _react.useState)(false);
50
52
  const autoSpeed = (0, _react.useRef)();
51
53
  const autoSteps = (0, _react.useRef)(animationSteps);
52
54
  const functions = (0, _chaynsApi.useFunctions)();
@@ -106,6 +108,8 @@ const Typewriter = ({
106
108
  lastLength: charactersCount,
107
109
  ema: charactersCount / (autoSpeedBaseFactor / 1000)
108
110
  });
111
+ const [shownCharCount, setShownCharCount] = (0, _react.useState)(charactersCount > 0 ? 0 : textContent.length);
112
+ const currentPosition = (0, _react.useRef)(0);
109
113
  (0, _react.useEffect)(() => {
110
114
  if (shouldUseResetAnimation) {
111
115
  chunkIntervalExponentialMovingAverage.current = {
@@ -131,38 +135,100 @@ const Typewriter = ({
131
135
  autoSpeed.current = calculatedAutoSpeed;
132
136
  autoSteps.current = steps;
133
137
  }, [animationSteps, charactersCount, shouldCalcAutoSpeed]);
134
- const handleSetNextChildrenIndex = (0, _react.useCallback)(() => {
135
- setCurrentChildrenIndex(prevIndex => {
136
- const nextIndex = prevIndex + 1;
137
- return nextIndex > childrenCount - 1 ? 0 : nextIndex;
138
- });
139
- }, [childrenCount]);
140
- const {
141
- handleClick,
142
- isResetAnimationActive,
143
- shownCharCount,
144
- shouldPreventBlinkingCursor
145
- } = (0, _useTypewriterAnimation.default)({
146
- areMultipleChildrenGiven,
147
- autoSpeedRef: autoSpeed,
148
- autoStepsRef: autoSteps,
149
- charactersCount,
150
- cursorType,
151
- nextTextDelay,
152
- onAdvanceText: handleSetNextChildrenIndex,
153
- onResetAnimationEnd,
154
- onResetAnimationStart,
155
- onTypingAnimationEnd,
156
- onTypingAnimationStart,
157
- resetDelay,
158
- resetSpeed,
159
- shouldUseResetAnimation,
160
- shouldWaitForContent,
161
- speed,
162
- startDelay,
163
- textContentLength: textContent.length
164
- });
165
138
  const isAnimatingText = shownCharCount < textContent.length || shouldForceCursorAnimation || areMultipleChildrenGiven || textContent.length === 0;
139
+ const handleClick = (0, _react.useCallback)(event => {
140
+ event.stopPropagation();
141
+ event.preventDefault();
142
+ setShouldStopAnimation(true);
143
+ }, []);
144
+ const handleSetNextChildrenIndex = (0, _react.useCallback)(() => setCurrentChildrenIndex(() => {
145
+ let newIndex = currentChildrenIndex + 1;
146
+ if (newIndex > childrenCount - 1) {
147
+ newIndex = 0;
148
+ }
149
+ return newIndex;
150
+ }), [childrenCount, currentChildrenIndex]);
151
+ (0, _react.useEffect)(() => {
152
+ let interval;
153
+ if (shouldStopAnimation || charactersCount === 0) {
154
+ setShownCharCount(textContent.length);
155
+ currentPosition.current = textContent.length;
156
+ } else if (isResetAnimationActive) {
157
+ if (typeof onResetAnimationStart === 'function') {
158
+ onResetAnimationStart();
159
+ }
160
+ interval = window.setInterval(() => {
161
+ setShownCharCount(prevState => {
162
+ const nextState = prevState - autoSteps.current;
163
+ currentPosition.current = nextState;
164
+ if (nextState === 0) {
165
+ window.clearInterval(interval);
166
+ if (typeof onResetAnimationEnd === 'function') {
167
+ onResetAnimationEnd();
168
+ }
169
+ if (areMultipleChildrenGiven) {
170
+ setTimeout(() => {
171
+ setIsResetAnimationActive(false);
172
+ handleSetNextChildrenIndex();
173
+ }, nextTextDelay);
174
+ }
175
+ }
176
+ return nextState;
177
+ });
178
+ }, resetSpeed);
179
+ } else {
180
+ const startTypingAnimation = () => {
181
+ if (cursorType === _cursor.CursorType.Thin) {
182
+ setShouldPreventBlinkingCursor(true);
183
+ }
184
+ if (typeof onTypingAnimationStart === 'function') {
185
+ onTypingAnimationStart();
186
+ }
187
+ const runTypingInterval = () => {
188
+ setShownCharCount(prevState => {
189
+ let nextState = Math.min(prevState + autoSteps.current, charactersCount);
190
+ if (nextState >= charactersCount && !shouldWaitForContent) {
191
+ window.clearInterval(interval);
192
+ if (cursorType === _cursor.CursorType.Thin) {
193
+ setShouldPreventBlinkingCursor(false);
194
+ }
195
+ if (typeof onTypingAnimationEnd === 'function') {
196
+ onTypingAnimationEnd();
197
+ }
198
+
199
+ /**
200
+ * At this point, the next value for "shownCharCount" is deliberately set to
201
+ * the length of the textContent to correctly display HTML elements
202
+ * after the last letter.
203
+ */
204
+ nextState = textContent.length;
205
+ if (areMultipleChildrenGiven) {
206
+ setTimeout(() => {
207
+ if (shouldUseResetAnimation) {
208
+ setIsResetAnimationActive(true);
209
+ } else {
210
+ setShownCharCount(0);
211
+ setTimeout(handleSetNextChildrenIndex, nextTextDelay);
212
+ }
213
+ }, resetDelay);
214
+ }
215
+ }
216
+ currentPosition.current = nextState;
217
+ return nextState;
218
+ });
219
+ };
220
+ interval = window.setInterval(runTypingInterval, autoSpeed.current ?? speed);
221
+ };
222
+ if (startDelay) {
223
+ setTimeout(startTypingAnimation, startDelay);
224
+ } else {
225
+ startTypingAnimation();
226
+ }
227
+ }
228
+ return () => {
229
+ window.clearInterval(interval);
230
+ };
231
+ }, [areMultipleChildrenGiven, autoSteps, charactersCount, cursorType, handleSetNextChildrenIndex, isResetAnimationActive, nextTextDelay, onResetAnimationEnd, onResetAnimationStart, onTypingAnimationEnd, onTypingAnimationStart, resetDelay, resetSpeed, shouldStopAnimation, shouldUseResetAnimation, shouldWaitForContent, speed, startDelay, textContent.length]);
166
232
  (0, _react.useEffect)(() => {
167
233
  if (!isAnimatingText && typeof onFinish === 'function') {
168
234
  onFinish();
@@ -1 +1 @@
1
- {"version":3,"file":"Typewriter.js","names":["_core","require","_chaynsApi","_react","_interopRequireWildcard","_reactDom","_server","_cursor","_speed","_AnimatedTypewriterText","_interopRequireDefault","_Typewriter","_utils","_useTypewriterAnimation","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","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","lastLength","ema","current","updateChunkStreamingSpeedEMA","currentLength","state","undefined","calculatedAutoSpeed","steps","calculateAutoSpeed","handleSetNextChildrenIndex","useCallback","prevIndex","nextIndex","handleClick","isResetAnimationActive","shownCharCount","shouldPreventBlinkingCursor","useTypewriterAnimation","autoSpeedRef","autoStepsRef","onAdvanceText","textContentLength","isAnimatingText","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';\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,IAAAA,KA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lB,SAChE;IACDZ,KAAK,EAAE9C;EAAU,GAEhB,OAAOqB,cAAc,KAAK,QAAQ,GAAGA,cAAc,GAAGqC,SACrC,CACzB,EACAiB,eAAe,iBACZzI,MAAA,CAAAa,OAAA,CAAAuF,aAAA,CAAC5F,WAAA,CAAAkJ,0BAA0B;IACvBP,gBAAgB,EAAEV,eAAgB;IAClCW,iBAAiB,EAAEjG,gBAAiB;IACpCqG,uBAAuB,EAAE;MAAEC,MAAM,EAAEb;IAAe;EAAE,CACvD,CACJ,EAKA,CAACpE,uBAAuB,iBACrB,IAAAmF,sBAAY,eACR3J,MAAA,CAAAa,OAAA,CAAAuF,aAAA;IAAKQ,KAAK,EAAE;MAAEgD,QAAQ,EAAE,UAAU;MAAEC,UAAU,EAAE;IAAS;EAAE,GACtD1H,QACA,CAAC,EACN2H,QAAQ,CAACC,IACb,CACU,CACrB,EACD,CACI5H,QAAQ,EACRC,UAAU,EACV4F,WAAW,EACXxD,uBAAuB,EACvBiE,eAAe,EACfG,cAAc,EACdzF,gBAAgB,EAChBgF,2BAA2B,EAC3B/E,sBAAsB,EACtBsF,SAAS,EACTvD,cAAc,EACdrB,SAAS,CAEjB,CAAC;AACL,CAAC;AAED5B,UAAU,CAAC8H,WAAW,GAAG,YAAY;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAArJ,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","lastLength","ema","shownCharCount","setShownCharCount","currentPosition","current","updateChunkStreamingSpeedEMA","currentLength","state","undefined","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 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,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,CAA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AAU,CACxB,CAAC,gBAEF7D,MAAA,CAAAY,OAAA,CAAA6F,aAAA,CAACjG,WAAA,CAAA2J,oBAAoB;IACjBhD,SAAS,EAAC,aAAa;IACvBiD,uBAAuB,EAAEjH,sBAAuB;IAChDkH,uBAAuB,EACnB,OAAO7E,cAAc,KAAK,QAAQ,GAAG;MAAE8E,MAAM,EAAEf;IAAU,CAAC,GAAGvB,SAChE;IACDf,KAAK,EAAEpD;EAAU,GAEhB,OAAO2B,cAAc,KAAK,QAAQ,GAAGA,cAAc,GAAGwC,SACrC,CACzB,EACAI,eAAe,iBACZpI,MAAA,CAAAY,OAAA,CAAA6F,aAAA,CAACjG,WAAA,CAAA+J,0BAA0B;IACvBP,gBAAgB,EAAE5B,eAAgB;IAClC6B,iBAAiB,EAAE/G,gBAAiB;IACpCmH,uBAAuB,EAAE;MAAEC,MAAM,EAAEb;IAAe;EAAE,CACvD,CACJ,EAKA,CAAClF,uBAAuB,iBACrB,IAAAiG,sBAAY,eACRxK,MAAA,CAAAY,OAAA,CAAA6F,aAAA;IAAKQ,KAAK,EAAE;MAAEwD,QAAQ,EAAE,UAAU;MAAEC,UAAU,EAAE;IAAS;EAAE,GACtDxI,QACA,CAAC,EACNyI,QAAQ,CAACC,IACb,CACU,CACrB,EACD,CACI1I,QAAQ,EACRC,UAAU,EACVkG,WAAW,EACX9D,uBAAuB,EACvB6D,eAAe,EACfqB,cAAc,EACdvG,gBAAgB,EAChBuB,2BAA2B,EAC3BtB,sBAAsB,EACtBoG,SAAS,EACT/D,cAAc,EACd3B,SAAS,CAEjB,CAAC;AACL,CAAC;AAED5B,UAAU,CAAC4I,WAAW,GAAG,YAAY;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAnK,OAAA,GAEvBqB,UAAU","ignoreList":[]}
@@ -24,13 +24,13 @@ const AnimatedTypewriterText = ({
24
24
  };
25
25
  const lastParentWithContent = traverseNodes(ref);
26
26
 
27
- // Removes the cursor marker from the previous render.
27
+ // Removes lastWithContent class from all elements
28
28
  ref.classList.remove('typewriter-lastWithContent');
29
- ref.querySelectorAll('.typewriter-lastWithContent').forEach(element => {
29
+ ref.querySelectorAll('.lastWithContent').forEach(element => {
30
30
  element.classList.remove('typewriter-lastWithContent');
31
31
  });
32
32
 
33
- // Adds the cursor marker to the last element that still contains text.
33
+ // Adds lastWithContent class to the last element with content
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 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":[]}
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, textSty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AACC,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,7 +8,6 @@ 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';
12
11
  const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
13
12
  const Typewriter = ({
14
13
  children,
@@ -38,6 +37,9 @@ const Typewriter = ({
38
37
  }) => {
39
38
  const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);
40
39
  const [hasRenderedChildrenOnce, setHasRenderedChildrenOnce] = useState(false);
40
+ const [shouldPreventBlinkingCursor, setShouldPreventBlinkingCursor] = useState(false);
41
+ const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);
42
+ const [shouldStopAnimation, setShouldStopAnimation] = useState(false);
41
43
  const autoSpeed = useRef();
42
44
  const autoSteps = useRef(animationSteps);
43
45
  const functions = useFunctions();
@@ -95,6 +97,8 @@ const Typewriter = ({
95
97
  lastLength: charactersCount,
96
98
  ema: charactersCount / (autoSpeedBaseFactor / 1000)
97
99
  });
100
+ const [shownCharCount, setShownCharCount] = useState(charactersCount > 0 ? 0 : textContent.length);
101
+ const currentPosition = useRef(0);
98
102
  useEffect(() => {
99
103
  if (shouldUseResetAnimation) {
100
104
  chunkIntervalExponentialMovingAverage.current = {
@@ -120,38 +124,100 @@ const Typewriter = ({
120
124
  autoSpeed.current = calculatedAutoSpeed;
121
125
  autoSteps.current = steps;
122
126
  }, [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
- });
154
127
  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]);
155
221
  useEffect(() => {
156
222
  if (!isAnimatingText && typeof onFinish === 'function') {
157
223
  onFinish();