@chayns-components/typewriter 5.0.0-beta.959 → 5.0.0-beta.960

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.
@@ -39,7 +39,8 @@ const Typewriter = ({
39
39
  resetSpeed = speed,
40
40
  startDelay = _speed.TypewriterDelay.None,
41
41
  textStyle,
42
- shouldCalcAutoSpeed = false
42
+ shouldCalcAutoSpeed = false,
43
+ autoSpeedBaseFactor = 2000
43
44
  }) => {
44
45
  const [currentChildrenIndex, setCurrentChildrenIndex] = (0, _react.useState)(0);
45
46
  const [hasRenderedChildrenOnce, setHasRenderedChildrenOnce] = (0, _react.useState)(false);
@@ -107,11 +108,12 @@ const Typewriter = ({
107
108
  steps
108
109
  } = (0, _utils.calculateAutoSpeed)({
109
110
  fullTextLength: charactersCount,
110
- currentPosition: currentPosition.current
111
+ currentPosition: currentPosition.current,
112
+ baseSpeedFactor: autoSpeedBaseFactor
111
113
  });
112
114
  setAutoSpeed(calculatedAutoSpeed);
113
115
  setAutoSteps(steps);
114
- }, [charactersCount, shouldCalcAutoSpeed, speed, textContent]);
116
+ }, [autoSpeedBaseFactor, charactersCount, shouldCalcAutoSpeed]);
115
117
  const isAnimatingText = shownCharCount < textContent.length || shouldForceCursorAnimation || areMultipleChildrenGiven || textContent.length === 0;
116
118
  const handleClick = (0, _react.useCallback)(event => {
117
119
  event.stopPropagation();
@@ -202,6 +204,10 @@ const Typewriter = ({
202
204
  startTypingAnimation();
203
205
  }
204
206
  }
207
+ console.debug('TEST - Typewriter', {
208
+ autoSpeed,
209
+ autoSteps
210
+ });
205
211
  return () => {
206
212
  window.clearInterval(interval);
207
213
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Typewriter.js","names":["_core","require","_chaynsApi","_react","_interopRequireWildcard","_reactDom","_server","_cursor","_speed","_AnimatedTypewriterText","_interopRequireDefault","_Typewriter","_utils","e","__esModule","default","_getRequireWildcardCache","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","useIsomorphicLayoutEffect","window","useLayoutEffect","useEffect","Typewriter","children","cursorType","CursorType","Default","nextTextDelay","TypewriterDelay","Medium","onFinish","onResetAnimationEnd","onResetAnimationStart","onTypingAnimationEnd","onTypingAnimationStart","pseudoChildren","resetDelay","shouldForceCursorAnimation","shouldHideCursor","shouldSortChildrenRandomly","shouldUseAnimationHeight","shouldUseResetAnimation","shouldWaitForContent","speed","TypewriterSpeed","resetSpeed","startDelay","None","textStyle","shouldCalcAutoSpeed","currentChildrenIndex","setCurrentChildrenIndex","useState","hasRenderedChildrenOnce","setHasRenderedChildrenOnce","shouldPreventBlinkingCursor","setShouldPreventBlinkingCursor","isResetAnimationActive","setIsResetAnimationActive","shouldStopAnimation","setShouldStopAnimation","autoSpeed","setAutoSpeed","autoSteps","setAutoSteps","functions","useFunctions","values","useValues","sortedChildren","useMemo","Array","isArray","shuffleArray","areMultipleChildrenGiven","childrenCount","length","textContent","currentChildren","React","isValidElement","renderToString","createElement","ChaynsProvider","data","isModule","ColorSchemeProvider","color","colorMode","style","display","charactersCount","getCharactersCount","shownCharCount","setShownCharCount","currentPosition","useRef","undefined","calculatedAutoSpeed","steps","calculateAutoSpeed","fullTextLength","current","isAnimatingText","handleClick","useCallback","event","stopPropagation","preventDefault","handleSetNextChildrenIndex","newIndex","interval","setInterval","prevState","nextState","clearInterval","setTimeout","startTypingAnimation","Thin","runTypingInterval","Math","min","shownText","getSubTextFromHTML","pseudoTextHTML","pseudoText","StyledTypewriter","$cursorType","onClick","$isAnimatingText","$shouldHideCursor","$shouldPreventBlinkAnimation","StyledTypewriterText","StyledTypewriterPseudoText","dangerouslySetInnerHTML","__html","createPortal","position","visibility","document","body","displayName","_default","exports"],"sources":["../../../../src/components/typewriter/Typewriter.tsx"],"sourcesContent":["import { ColorSchemeProvider } 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 { CursorType } from '../../types/cursor';\nimport { TypewriterDelay, TypewriterSpeed } from '../../types/speed';\nimport AnimatedTypewriterText from './AnimatedTypewriterText';\nimport {\n StyledTypewriter,\n StyledTypewriterPseudoText,\n StyledTypewriterText,\n} from './Typewriter.styles';\nimport { calculateAutoSpeed, getCharactersCount, getSubTextFromHTML, shuffleArray } from './utils';\n\nconst useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport type TypewriterProps = {\n /**\n * The 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 * Specifies whether the children should be sorted randomly if there are multiple texts.\n * This makes the typewriter start with a different text each time and also changes them\n * in a random order.\n */\n shouldSortChildrenRandomly?: boolean;\n /**\n * Specifies whether the animation should use its full height or the height of the current\n * chunk.\n */\n shouldUseAnimationHeight?: boolean;\n /**\n * Whether the animation speed should be calculated with the chunk interval.\n */\n shouldCalcAutoSpeed?: boolean;\n /**\n * Specifies whether the reset of the text should be animated with a backspace animation for\n * multiple texts.\n */\n shouldUseResetAnimation?: boolean;\n /**\n * Whether the typewriter should wait for new content\n */\n shouldWaitForContent?: boolean;\n /**\n * The speed of the animation. Use the TypewriterSpeed enum for this prop.\n */\n speed?: TypewriterSpeed | number;\n /**\n * The delay in milliseconds before the typewriter starts typing.\n */\n startDelay?: TypewriterDelay;\n /**\n * The style of the typewriter text element\n */\n textStyle?: React.CSSProperties;\n};\n\nconst Typewriter: FC<TypewriterProps> = ({\n children,\n cursorType = CursorType.Default,\n nextTextDelay = TypewriterDelay.Medium,\n onFinish,\n onResetAnimationEnd,\n onResetAnimationStart,\n onTypingAnimationEnd,\n onTypingAnimationStart,\n pseudoChildren,\n resetDelay = TypewriterDelay.Medium,\n shouldForceCursorAnimation = false,\n shouldHideCursor = 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}) => {\n const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);\n const [hasRenderedChildrenOnce, setHasRenderedChildrenOnce] = useState(false);\n const [shouldPreventBlinkingCursor, setShouldPreventBlinkingCursor] = useState(false);\n const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);\n const [shouldStopAnimation, setShouldStopAnimation] = useState(false);\n const [autoSpeed, setAutoSpeed] = useState<number>();\n const [autoSteps, setAutoSteps] = useState(1);\n\n const functions = useFunctions();\n const values = useValues();\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=\"#005EB8\"\n colorMode={0}\n style={{ display: 'inline' }}\n >\n {currentChildren}\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=\"#005EB8\"\n colorMode={0}\n style={{ display: 'inline' }}\n >\n {sortedChildren}\n </ColorSchemeProvider>\n </ChaynsProvider>,\n )\n : (sortedChildren as string);\n }, [areMultipleChildrenGiven, currentChildrenIndex, functions, sortedChildren, values]);\n\n const charactersCount = useMemo(() => getCharactersCount(textContent), [textContent]);\n\n const [shownCharCount, setShownCharCount] = useState(\n charactersCount > 0 ? 0 : textContent.length,\n );\n\n const currentPosition = useRef(0);\n\n useEffect(() => {\n if (!shouldCalcAutoSpeed) {\n setAutoSpeed(undefined);\n setAutoSteps(1);\n\n return;\n }\n\n const { speed: calculatedAutoSpeed, steps } = calculateAutoSpeed({\n fullTextLength: charactersCount,\n currentPosition: currentPosition.current,\n });\n\n setAutoSpeed(calculatedAutoSpeed);\n setAutoSteps(steps);\n }, [charactersCount, shouldCalcAutoSpeed, speed, textContent]);\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 - 1;\n currentPosition.current = nextState;\n\n if (nextState === 0) {\n window.clearInterval(interval);\n\n if (typeof onResetAnimationEnd === 'function') {\n onResetAnimationEnd();\n }\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n setIsResetAnimationActive(false);\n handleSetNextChildrenIndex();\n }, nextTextDelay);\n }\n }\n\n return nextState;\n });\n }, resetSpeed);\n } else {\n const startTypingAnimation = () => {\n if (cursorType === CursorType.Thin) {\n setShouldPreventBlinkingCursor(true);\n }\n\n if (typeof onTypingAnimationStart === 'function') {\n onTypingAnimationStart();\n }\n\n const runTypingInterval = () => {\n setShownCharCount((prevState) => {\n let nextState = Math.min(prevState + autoSteps, charactersCount);\n\n if (nextState >= charactersCount && !shouldWaitForContent) {\n window.clearInterval(interval);\n\n if (cursorType === CursorType.Thin) {\n setShouldPreventBlinkingCursor(false);\n }\n\n if (typeof onTypingAnimationEnd === 'function') {\n onTypingAnimationEnd();\n }\n\n /**\n * At this point, the next value for \"shownCharCount\" is deliberately set to\n * the length of the textContent in order to correctly display HTML elements\n * after the last letter.\n */\n nextState = textContent.length;\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n if (shouldUseResetAnimation) {\n setIsResetAnimationActive(true);\n } else {\n setShownCharCount(0);\n setTimeout(handleSetNextChildrenIndex, nextTextDelay);\n }\n }, resetDelay);\n }\n }\n\n currentPosition.current = nextState;\n\n return nextState;\n });\n };\n\n interval = window.setInterval(runTypingInterval, autoSpeed ?? speed);\n };\n\n if (startDelay) {\n setTimeout(startTypingAnimation, startDelay);\n } else {\n startTypingAnimation();\n }\n }\n\n return () => {\n window.clearInterval(interval);\n };\n }, [\n resetSpeed,\n speed,\n resetDelay,\n childrenCount,\n charactersCount,\n textContent.length,\n shouldStopAnimation,\n shouldWaitForContent,\n isResetAnimationActive,\n shouldUseResetAnimation,\n areMultipleChildrenGiven,\n handleSetNextChildrenIndex,\n nextTextDelay,\n startDelay,\n onResetAnimationStart,\n onResetAnimationEnd,\n onTypingAnimationStart,\n onTypingAnimationEnd,\n cursorType,\n autoSpeed,\n autoSteps,\n ]);\n\n useEffect(() => {\n if (!isAnimatingText && typeof onFinish === 'function') {\n onFinish();\n }\n }, [isAnimatingText, onFinish]);\n\n const shownText = useMemo(\n () => getSubTextFromHTML(textContent, shownCharCount),\n [shownCharCount, textContent],\n );\n\n const pseudoTextHTML = useMemo(() => {\n if (pseudoChildren) {\n const pseudoText = React.isValidElement(pseudoChildren)\n ? renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider\n color=\"#005EB8\"\n colorMode={0}\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 }, [functions, pseudoChildren, shouldUseAnimationHeight, shownCharCount, textContent, values]);\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 shownText={shownText}\n textStyle={textStyle}\n />\n ) : (\n <StyledTypewriterText style={textStyle}>{sortedChildren}</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 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 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;AACA,IAAAM,OAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAA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U,CAACuH,WAAW,GAAG,YAAY;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAA/I,OAAA,GAEvBsB,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","_getRequireWildcardCache","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","useIsomorphicLayoutEffect","window","useLayoutEffect","useEffect","Typewriter","children","cursorType","CursorType","Default","nextTextDelay","TypewriterDelay","Medium","onFinish","onResetAnimationEnd","onResetAnimationStart","onTypingAnimationEnd","onTypingAnimationStart","pseudoChildren","resetDelay","shouldForceCursorAnimation","shouldHideCursor","shouldSortChildrenRandomly","shouldUseAnimationHeight","shouldUseResetAnimation","shouldWaitForContent","speed","TypewriterSpeed","resetSpeed","startDelay","None","textStyle","shouldCalcAutoSpeed","autoSpeedBaseFactor","currentChildrenIndex","setCurrentChildrenIndex","useState","hasRenderedChildrenOnce","setHasRenderedChildrenOnce","shouldPreventBlinkingCursor","setShouldPreventBlinkingCursor","isResetAnimationActive","setIsResetAnimationActive","shouldStopAnimation","setShouldStopAnimation","autoSpeed","setAutoSpeed","autoSteps","setAutoSteps","functions","useFunctions","values","useValues","sortedChildren","useMemo","Array","isArray","shuffleArray","areMultipleChildrenGiven","childrenCount","length","textContent","currentChildren","React","isValidElement","renderToString","createElement","ChaynsProvider","data","isModule","ColorSchemeProvider","color","colorMode","style","display","charactersCount","getCharactersCount","shownCharCount","setShownCharCount","currentPosition","useRef","undefined","calculatedAutoSpeed","steps","calculateAutoSpeed","fullTextLength","current","baseSpeedFactor","isAnimatingText","handleClick","useCallback","event","stopPropagation","preventDefault","handleSetNextChildrenIndex","newIndex","interval","setInterval","prevState","nextState","clearInterval","setTimeout","startTypingAnimation","Thin","runTypingInterval","Math","min","console","debug","shownText","getSubTextFromHTML","pseudoTextHTML","pseudoText","StyledTypewriter","$cursorType","onClick","$isAnimatingText","$shouldHideCursor","$shouldPreventBlinkAnimation","StyledTypewriterText","StyledTypewriterPseudoText","dangerouslySetInnerHTML","__html","createPortal","position","visibility","document","body","displayName","_default","exports"],"sources":["../../../../src/components/typewriter/Typewriter.tsx"],"sourcesContent":["import { ColorSchemeProvider } 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 { CursorType } from '../../types/cursor';\nimport { TypewriterDelay, TypewriterSpeed } from '../../types/speed';\nimport AnimatedTypewriterText from './AnimatedTypewriterText';\nimport {\n StyledTypewriter,\n StyledTypewriterPseudoText,\n StyledTypewriterText,\n} from './Typewriter.styles';\nimport { calculateAutoSpeed, getCharactersCount, getSubTextFromHTML, shuffleArray } from './utils';\n\nconst useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport type TypewriterProps = {\n /**\n * The base speed factor to calculate the animation speed.\n */\n autoSpeedBaseFactor?: number;\n /**\n * The text to type\n */\n children: ReactElement | ReactElement[] | string | string[];\n /**\n * The type of the cursor. Use the CursorType enum for this prop.\n */\n cursorType?: CursorType;\n /**\n * The delay in milliseconds before the next text is shown.\n * This prop is only used if multiple texts are given.\n */\n nextTextDelay?: TypewriterDelay;\n /**\n * Function that is executed when the typewriter animation has finished. This function will not\n * be executed if multiple texts are used.\n */\n onFinish?: VoidFunction;\n /**\n * Function that is executed when the reset animation has finished. This function will not be\n * executed if `shouldUseResetAnimation` is not set to `true`.\n */\n onResetAnimationEnd?: VoidFunction;\n /**\n * Function that is executed when the reset animation has started. This function will not be\n * executed if `shouldUseResetAnimation` is not set to `true`.\n */\n onResetAnimationStart?: VoidFunction;\n /**\n * Function that is executed when the typing animation has finished. If multiple texts are given,\n * this function will be executed for each text.\n */\n onTypingAnimationEnd?: VoidFunction;\n /**\n * Function that is executed when the typing animation has started. If multiple texts are given,\n * this function will be executed for each text.\n */\n onTypingAnimationStart?: VoidFunction;\n /**\n * Pseudo-element to be rendered invisible during animation to define the size of the element\n * for the typewriter effect. By default, the \"children\" is used for this purpose.\n */\n pseudoChildren?: ReactElement | string;\n /**\n * Waiting time in milliseconds before the typewriter resets the text.\n * This prop is only used if multiple texts are given.\n */\n resetDelay?: TypewriterDelay;\n /**\n * The reset speed of the animation. Use the TypewriterSpeed enum for this prop.\n */\n resetSpeed?: TypewriterSpeed | number;\n /**\n * Specifies whether the cursor should be forced to animate even if no text is currently animated.\n */\n shouldForceCursorAnimation?: boolean;\n /**\n * Specifies whether the cursor should be hidden\n */\n shouldHideCursor?: boolean;\n /**\n * Specifies whether the children should be sorted randomly if there are multiple texts.\n * This makes the typewriter start with a different text each time and also changes them\n * in a random order.\n */\n shouldSortChildrenRandomly?: boolean;\n /**\n * Specifies whether the animation should use its full height or the height of the current\n * chunk.\n */\n shouldUseAnimationHeight?: boolean;\n /**\n * Whether the animation speed should be calculated with the chunk interval.\n */\n shouldCalcAutoSpeed?: boolean;\n /**\n * Specifies whether the reset of the text should be animated with a backspace animation for\n * multiple texts.\n */\n shouldUseResetAnimation?: boolean;\n /**\n * Whether the typewriter should wait for new content\n */\n shouldWaitForContent?: boolean;\n /**\n * The speed of the animation. Use the TypewriterSpeed enum for this prop.\n */\n speed?: TypewriterSpeed | number;\n /**\n * The delay in milliseconds before the typewriter starts typing.\n */\n startDelay?: TypewriterDelay;\n /**\n * The style of the typewriter text element\n */\n textStyle?: React.CSSProperties;\n};\n\nconst Typewriter: FC<TypewriterProps> = ({\n children,\n cursorType = CursorType.Default,\n nextTextDelay = TypewriterDelay.Medium,\n onFinish,\n onResetAnimationEnd,\n onResetAnimationStart,\n onTypingAnimationEnd,\n onTypingAnimationStart,\n pseudoChildren,\n resetDelay = TypewriterDelay.Medium,\n shouldForceCursorAnimation = false,\n shouldHideCursor = false,\n shouldSortChildrenRandomly = false,\n shouldUseAnimationHeight = false,\n shouldUseResetAnimation = false,\n shouldWaitForContent,\n speed = TypewriterSpeed.Medium,\n resetSpeed = speed,\n startDelay = TypewriterDelay.None,\n textStyle,\n shouldCalcAutoSpeed = false,\n autoSpeedBaseFactor = 2000,\n}) => {\n const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);\n const [hasRenderedChildrenOnce, setHasRenderedChildrenOnce] = useState(false);\n const [shouldPreventBlinkingCursor, setShouldPreventBlinkingCursor] = useState(false);\n const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);\n const [shouldStopAnimation, setShouldStopAnimation] = useState(false);\n const [autoSpeed, setAutoSpeed] = useState<number>();\n const [autoSteps, setAutoSteps] = useState(1);\n\n const functions = useFunctions();\n const values = useValues();\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=\"#005EB8\"\n colorMode={0}\n style={{ display: 'inline' }}\n >\n {currentChildren}\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=\"#005EB8\"\n colorMode={0}\n style={{ display: 'inline' }}\n >\n {sortedChildren}\n </ColorSchemeProvider>\n </ChaynsProvider>,\n )\n : (sortedChildren as string);\n }, [areMultipleChildrenGiven, currentChildrenIndex, functions, sortedChildren, values]);\n\n const charactersCount = useMemo(() => getCharactersCount(textContent), [textContent]);\n\n const [shownCharCount, setShownCharCount] = useState(\n charactersCount > 0 ? 0 : textContent.length,\n );\n\n const currentPosition = useRef(0);\n\n useEffect(() => {\n if (!shouldCalcAutoSpeed) {\n setAutoSpeed(undefined);\n setAutoSteps(1);\n\n return;\n }\n\n const { speed: calculatedAutoSpeed, steps } = calculateAutoSpeed({\n fullTextLength: charactersCount,\n currentPosition: currentPosition.current,\n baseSpeedFactor: autoSpeedBaseFactor,\n });\n\n setAutoSpeed(calculatedAutoSpeed);\n setAutoSteps(steps);\n }, [autoSpeedBaseFactor, charactersCount, shouldCalcAutoSpeed]);\n\n const isAnimatingText =\n shownCharCount < textContent.length ||\n shouldForceCursorAnimation ||\n areMultipleChildrenGiven ||\n textContent.length === 0;\n\n const handleClick = useCallback((event: React.MouseEvent) => {\n event.stopPropagation();\n event.preventDefault();\n\n setShouldStopAnimation(true);\n }, []);\n\n const handleSetNextChildrenIndex = useCallback(\n () =>\n setCurrentChildrenIndex(() => {\n let newIndex = currentChildrenIndex + 1;\n\n if (newIndex > childrenCount - 1) {\n newIndex = 0;\n }\n\n return newIndex;\n }),\n [childrenCount, currentChildrenIndex],\n );\n\n useEffect(() => {\n let interval: number | undefined;\n\n if (shouldStopAnimation || charactersCount === 0) {\n setShownCharCount(textContent.length);\n currentPosition.current = textContent.length;\n } else if (isResetAnimationActive) {\n if (typeof onResetAnimationStart === 'function') {\n onResetAnimationStart();\n }\n\n interval = window.setInterval(() => {\n setShownCharCount((prevState) => {\n const nextState = prevState - 1;\n currentPosition.current = nextState;\n\n if (nextState === 0) {\n window.clearInterval(interval);\n\n if (typeof onResetAnimationEnd === 'function') {\n onResetAnimationEnd();\n }\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n setIsResetAnimationActive(false);\n handleSetNextChildrenIndex();\n }, nextTextDelay);\n }\n }\n\n return nextState;\n });\n }, resetSpeed);\n } else {\n const startTypingAnimation = () => {\n if (cursorType === CursorType.Thin) {\n setShouldPreventBlinkingCursor(true);\n }\n\n if (typeof onTypingAnimationStart === 'function') {\n onTypingAnimationStart();\n }\n\n const runTypingInterval = () => {\n setShownCharCount((prevState) => {\n let nextState = Math.min(prevState + autoSteps, charactersCount);\n\n if (nextState >= charactersCount && !shouldWaitForContent) {\n window.clearInterval(interval);\n\n if (cursorType === CursorType.Thin) {\n setShouldPreventBlinkingCursor(false);\n }\n\n if (typeof onTypingAnimationEnd === 'function') {\n onTypingAnimationEnd();\n }\n\n /**\n * At this point, the next value for \"shownCharCount\" is deliberately set to\n * the length of the textContent in order to correctly display HTML elements\n * after the last letter.\n */\n nextState = textContent.length;\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n if (shouldUseResetAnimation) {\n setIsResetAnimationActive(true);\n } else {\n setShownCharCount(0);\n setTimeout(handleSetNextChildrenIndex, nextTextDelay);\n }\n }, resetDelay);\n }\n }\n\n currentPosition.current = nextState;\n\n return nextState;\n });\n };\n\n interval = window.setInterval(runTypingInterval, autoSpeed ?? speed);\n };\n\n if (startDelay) {\n setTimeout(startTypingAnimation, startDelay);\n } else {\n startTypingAnimation();\n }\n }\n\n console.debug('TEST - Typewriter', { autoSpeed, autoSteps });\n\n return () => {\n window.clearInterval(interval);\n };\n }, [\n resetSpeed,\n speed,\n resetDelay,\n childrenCount,\n charactersCount,\n textContent.length,\n shouldStopAnimation,\n shouldWaitForContent,\n isResetAnimationActive,\n shouldUseResetAnimation,\n areMultipleChildrenGiven,\n handleSetNextChildrenIndex,\n nextTextDelay,\n startDelay,\n onResetAnimationStart,\n onResetAnimationEnd,\n onTypingAnimationStart,\n onTypingAnimationEnd,\n cursorType,\n autoSpeed,\n autoSteps,\n ]);\n\n useEffect(() => {\n if (!isAnimatingText && typeof onFinish === 'function') {\n onFinish();\n }\n }, [isAnimatingText, onFinish]);\n\n const shownText = useMemo(\n () => getSubTextFromHTML(textContent, shownCharCount),\n [shownCharCount, textContent],\n );\n\n const pseudoTextHTML = useMemo(() => {\n if (pseudoChildren) {\n const pseudoText = React.isValidElement(pseudoChildren)\n ? renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider\n color=\"#005EB8\"\n colorMode={0}\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 }, [functions, pseudoChildren, shouldUseAnimationHeight, shownCharCount, textContent, values]);\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 shownText={shownText}\n textStyle={textStyle}\n />\n ) : (\n <StyledTypewriterText style={textStyle}>{sortedChildren}</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 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 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;AACA,IAAAM,OAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,uBAAA,GAAAC,sBAAA,CAAAT,OAAA;AACA,IAAAU,WAAA,GAAAV,OAAA;AAKA,IAAAW,MAAA,GAAAX,OAAA;AAAmG,SAAAS,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAG,yBAAAH,CAAA,6BAAAI,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAD,wBAAA,YAAAA,CAAAH,CAAA,WAAAA,CAAA,GAAAM,CAAA,GAAAD,CAAA,KAAAL,CAAA;AAAA,SAAAT,wBAAAS,CAAA,EAAAK,CAAA,SAAAA,CAAA,IAAAL,CAAA,IAAAA,CAAA,CAAAC,UAAA,SAAAD,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAE,OAAA,EAAAF,CAAA,QAAAM,CAAA,GAAAH,wBAAA,CAAAE,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAC,GAAA,CAAAP,CAAA,UAAAM,CAAA,CAAAE,GAAA,CAAAR,CAAA,OAAAS,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAA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AY,OAAA,CAAAmF,aAAA,CAACvF,WAAA,CAAA6I,0BAA0B;IACvBJ,gBAAgB,EAAE5B,eAAgB;IAClC6B,iBAAiB,EAAEhG,gBAAiB;IACpCoG,uBAAuB,EAAE;MAAEC,MAAM,EAAEX;IAAe;EAAE,CACvD,CACJ,EAKA,CAAC1E,uBAAuB,iBACrB,IAAAsF,sBAAY,eACRxJ,MAAA,CAAAY,OAAA,CAAAmF,aAAA;IAAKO,KAAK,EAAE;MAAEmD,QAAQ,EAAE,UAAU;MAAEC,UAAU,EAAE;IAAS;EAAE,GACtDvH,QACA,CAAC,EACNwH,QAAQ,CAACC,IACb,CACU,CACrB,EACD,CACIzH,QAAQ,EACRC,UAAU,EACVkF,WAAW,EACXpD,uBAAuB,EACvBmD,eAAe,EACfuB,cAAc,EACd1F,gBAAgB,EAChBkB,2BAA2B,EAC3BsE,SAAS,EACTxD,cAAc,EACdtB,SAAS,CAEjB,CAAC;AACL,CAAC;AAED1B,UAAU,CAAC2H,WAAW,GAAG,YAAY;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAnJ,OAAA,GAEvBsB,UAAU","ignoreList":[]}
@@ -93,14 +93,15 @@ const shuffleArray = array => {
93
93
  exports.shuffleArray = shuffleArray;
94
94
  const calculateAutoSpeed = ({
95
95
  fullTextLength,
96
- currentPosition
96
+ currentPosition,
97
+ baseSpeedFactor
97
98
  }) => {
98
99
  const MIN_SPEED = 1;
99
100
  const MAX_SPEED = 10;
100
101
  const remainingLength = fullTextLength - currentPosition;
101
102
 
102
- // Calculate the speed with the remaining text length
103
- const speed = Math.min(2000 / remainingLength, MAX_SPEED);
103
+ // Calculate the speed with the remaining text length and the baseSpeedFactor
104
+ const speed = Math.min(baseSpeedFactor / remainingLength, MAX_SPEED);
104
105
  if (speed < MIN_SPEED) {
105
106
  return {
106
107
  speed: 1,
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":["getSubTextFromHTML","html","length","div","document","createElement","innerHTML","text","currLength","traverse","element","nodeName","nodeType","textContent","nodeText","substring","toLowerCase","attributes","attribute","name","value","i","childNodes","childNode","exports","getCharactersCount","count","node","trim","Array","from","forEach","shuffleArray","array","result","j","Math","floor","random","calculateAutoSpeed","fullTextLength","currentPosition","MIN_SPEED","MAX_SPEED","remainingLength","speed","min","steps"],"sources":["../../../../src/components/typewriter/utils.ts"],"sourcesContent":["/**\n * This function extracts a part of the text from an HTML text. The HTML elements themselves are\n * returned in the result. In addition, the function ensures that the closing tag of the Bold HTML\n * element is also returned for text that is cut off in the middle of a Bold element, for example.\n *\n * @param html - The text from which a part should be taken\n * @param length - The length of the text to be extracted\n *\n * @return string - The text part with the specified length - additionally the HTML elements are added\n */\nexport const getSubTextFromHTML = (html: string, length: number): string => {\n const div = document.createElement('div');\n\n div.innerHTML = html;\n\n let text = '';\n let currLength = 0;\n\n const traverse = (element: Element): boolean => {\n if (element.nodeName === 'TWIGNORE') {\n text += element.innerHTML;\n } else if (element.nodeType === 3 && typeof element.textContent === 'string') {\n const nodeText = element.textContent;\n\n if (currLength + nodeText.length <= length) {\n text += nodeText;\n currLength += nodeText.length;\n } else {\n text += nodeText.substring(0, length - currLength);\n\n return false;\n }\n } else if (element.nodeType === 1) {\n const nodeName = element.nodeName.toLowerCase();\n\n let attributes = '';\n\n // @ts-expect-error: Type is correct here\n // eslint-disable-next-line no-restricted-syntax\n for (const attribute of element.attributes) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/restrict-template-expressions\n attributes += ` ${attribute.name}=\"${attribute.value}\"`;\n }\n\n text += `<${nodeName}${attributes}>`;\n\n for (let i = 0; i < element.childNodes.length; i++) {\n const childNode = element.childNodes[i];\n\n if (childNode && !traverse(childNode as Element)) {\n return false;\n }\n }\n\n text += `</${nodeName}>`;\n }\n\n return true;\n };\n\n for (let i = 0; i < div.childNodes.length; i++) {\n const childNode = div.childNodes[i];\n\n if (childNode && !traverse(childNode as Element)) {\n return text;\n }\n }\n\n return text;\n};\n\nexport const getCharactersCount = (html: string): number => {\n const div = document.createElement('div');\n\n div.innerHTML = html;\n\n let count = 0;\n\n const traverse = (node: Node): void => {\n if (node.nodeName === 'TWIGNORE') {\n count += 1;\n } else if (node.nodeType === 3 && typeof node.textContent === 'string') {\n count += node.textContent.trim().length;\n } else if (node.nodeType === 1) {\n if (node.nodeName === 'CODE' && node.textContent !== null) {\n count += node.textContent.length;\n\n return;\n }\n\n Array.from(node.childNodes).forEach(traverse);\n }\n };\n\n Array.from(div.childNodes).forEach(traverse);\n\n return count;\n};\n\nexport const shuffleArray = <T>(array: T[]): T[] => {\n const result = Array.from(array);\n\n for (let i = result.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n\n [result[i], result[j]] = [result[j]!, result[i]!];\n }\n\n return result;\n};\n\ninterface CalculateAutoSpeedProps {\n fullTextLength: number;\n currentPosition: number;\n}\n\nexport const calculateAutoSpeed = ({\n fullTextLength,\n currentPosition,\n}: CalculateAutoSpeedProps): { speed: number; steps: number } => {\n const MIN_SPEED = 1;\n const MAX_SPEED = 10;\n\n const remainingLength = fullTextLength - currentPosition;\n\n // Calculate the speed with the remaining text length\n const speed = Math.min(2000 / remainingLength, MAX_SPEED);\n\n if (speed < MIN_SPEED) {\n return { speed: 1, steps: 2 };\n }\n\n return { speed, steps: 1 };\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,kBAAkB,GAAGA,CAACC,IAAY,EAAEC,MAAc,KAAa;EACxE,MAAMC,GAAG,GAAGC,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAEzCF,GAAG,CAACG,SAAS,GAAGL,IAAI;EAEpB,IAAIM,IAAI,GAAG,EAAE;EACb,IAAIC,UAAU,GAAG,CAAC;EAElB,MAAMC,QAAQ,GAAIC,OAAgB,IAAc;IAC5C,IAAIA,OAAO,CAACC,QAAQ,KAAK,UAAU,EAAE;MACjCJ,IAAI,IAAIG,OAAO,CA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AA,GAAAA,kBAAA;AAEK,MAAMO,YAAY,GAAOC,KAAU,IAAU;EAChD,MAAMC,MAAM,GAAGL,KAAK,CAACC,IAAI,CAACG,KAAK,CAAC;EAEhC,KAAK,IAAIZ,CAAC,GAAGa,MAAM,CAAChC,MAAM,GAAG,CAAC,EAAEmB,CAAC,GAAG,CAAC,EAAEA,CAAC,EAAE,EAAE;IACxC,MAAMc,CAAC,GAAGC,IAAI,CAACC,KAAK,CAACD,IAAI,CAACE,MAAM,CAAC,CAAC,IAAIjB,CAAC,GAAG,CAAC,CAAC,CAAC;IAE7C,CAACa,MAAM,CAACb,CAAC,CAAC,EAAEa,MAAM,CAACC,CAAC,CAAC,CAAC,GAAG,CAACD,MAAM,CAACC,CAAC,CAAC,EAAGD,MAAM,CAACb,CAAC,CAAC,CAAE;EACrD;EAEA,OAAOa,MAAM;AACjB,CAAC;AAACV,OAAA,CAAAQ,YAAA,GAAAA,YAAA;AAOK,MAAMO,kBAAkB,GAAGA,CAAC;EAC/BC,cAAc;EACdC;AACqB,CAAC,KAAuC;EAC7D,MAAMC,SAAS,GAAG,CAAC;EACnB,MAAMC,SAAS,GAAG,EAAE;EAEpB,MAAMC,eAAe,GAAGJ,cAAc,GAAGC,eAAe;;EAExD;EACA,MAAMI,KAAK,GAAGT,IAAI,CAACU,GAAG,CAAC,IAAI,GAAGF,eAAe,EAAED,SAAS,CAAC;EAEzD,IAAIE,KAAK,GAAGH,SAAS,EAAE;IACnB,OAAO;MAAEG,KAAK,EAAE,CAAC;MAAEE,KAAK,EAAE;IAAE,CAAC;EACjC;EAEA,OAAO;IAAEF,KAAK;IAAEE,KAAK,EAAE;EAAE,CAAC;AAC9B,CAAC;AAACvB,OAAA,CAAAe,kBAAA,GAAAA,kBAAA","ignoreList":[]}
1
+ {"version":3,"file":"utils.js","names":["getSubTextFromHTML","html","length","div","document","createElement","innerHTML","text","currLength","traverse","element","nodeName","nodeType","textContent","nodeText","substring","toLowerCase","attributes","attribute","name","value","i","childNodes","childNode","exports","getCharactersCount","count","node","trim","Array","from","forEach","shuffleArray","array","result","j","Math","floor","random","calculateAutoSpeed","fullTextLength","currentPosition","baseSpeedFactor","MIN_SPEED","MAX_SPEED","remainingLength","speed","min","steps"],"sources":["../../../../src/components/typewriter/utils.ts"],"sourcesContent":["/**\n * This function extracts a part of the text from an HTML text. The HTML elements themselves are\n * returned in the result. In addition, the function ensures that the closing tag of the Bold HTML\n * element is also returned for text that is cut off in the middle of a Bold element, for example.\n *\n * @param html - The text from which a part should be taken\n * @param length - The length of the text to be extracted\n *\n * @return string - The text part with the specified length - additionally the HTML elements are added\n */\nexport const getSubTextFromHTML = (html: string, length: number): string => {\n const div = document.createElement('div');\n\n div.innerHTML = html;\n\n let text = '';\n let currLength = 0;\n\n const traverse = (element: Element): boolean => {\n if (element.nodeName === 'TWIGNORE') {\n text += element.innerHTML;\n } else if (element.nodeType === 3 && typeof element.textContent === 'string') {\n const nodeText = element.textContent;\n\n if (currLength + nodeText.length <= length) {\n text += nodeText;\n currLength += nodeText.length;\n } else {\n text += nodeText.substring(0, length - currLength);\n\n return false;\n }\n } else if (element.nodeType === 1) {\n const nodeName = element.nodeName.toLowerCase();\n\n let attributes = '';\n\n // @ts-expect-error: Type is correct here\n // eslint-disable-next-line no-restricted-syntax\n for (const attribute of element.attributes) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/restrict-template-expressions\n attributes += ` ${attribute.name}=\"${attribute.value}\"`;\n }\n\n text += `<${nodeName}${attributes}>`;\n\n for (let i = 0; i < element.childNodes.length; i++) {\n const childNode = element.childNodes[i];\n\n if (childNode && !traverse(childNode as Element)) {\n return false;\n }\n }\n\n text += `</${nodeName}>`;\n }\n\n return true;\n };\n\n for (let i = 0; i < div.childNodes.length; i++) {\n const childNode = div.childNodes[i];\n\n if (childNode && !traverse(childNode as Element)) {\n return text;\n }\n }\n\n return text;\n};\n\nexport const getCharactersCount = (html: string): number => {\n const div = document.createElement('div');\n\n div.innerHTML = html;\n\n let count = 0;\n\n const traverse = (node: Node): void => {\n if (node.nodeName === 'TWIGNORE') {\n count += 1;\n } else if (node.nodeType === 3 && typeof node.textContent === 'string') {\n count += node.textContent.trim().length;\n } else if (node.nodeType === 1) {\n if (node.nodeName === 'CODE' && node.textContent !== null) {\n count += node.textContent.length;\n\n return;\n }\n\n Array.from(node.childNodes).forEach(traverse);\n }\n };\n\n Array.from(div.childNodes).forEach(traverse);\n\n return count;\n};\n\nexport const shuffleArray = <T>(array: T[]): T[] => {\n const result = Array.from(array);\n\n for (let i = result.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n\n [result[i], result[j]] = [result[j]!, result[i]!];\n }\n\n return result;\n};\n\ninterface CalculateAutoSpeedProps {\n fullTextLength: number;\n currentPosition: number;\n baseSpeedFactor: number;\n}\n\nexport const calculateAutoSpeed = ({\n fullTextLength,\n currentPosition,\n baseSpeedFactor,\n}: CalculateAutoSpeedProps): { speed: number; steps: number } => {\n const MIN_SPEED = 1;\n const MAX_SPEED = 10;\n\n const remainingLength = fullTextLength - currentPosition;\n\n // Calculate the speed with the remaining text length and the baseSpeedFactor\n const speed = Math.min(baseSpeedFactor / remainingLength, MAX_SPEED);\n\n if (speed < MIN_SPEED) {\n return { speed: 1, steps: 2 };\n }\n\n return { speed, steps: 1 };\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,kBAAkB,GAAGA,CAACC,IAAY,EAAEC,MAAc,KAAa;EACxE,MAAMC,GAAG,GAAGC,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAEzCF,GAAG,CAACG,SAAS,GAAGL,IAAI;EAEpB,IAAIM,IAAI,GAAG,EAAE;EACb,IAAIC,UAAU,GAAG,CAAC;EAElB,MAAMC,QAAQ,GAAIC,OAAgB,IAAc;IAC5C,IAAIA,OAAO,CAACC,QAAQ,KAAK,UAAU,EAAE;MACjCJ,IAAI,IAAIG,OA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C,kBAAA,GAAAA,kBAAA;AAEK,MAAMO,YAAY,GAAOC,KAAU,IAAU;EAChD,MAAMC,MAAM,GAAGL,KAAK,CAACC,IAAI,CAACG,KAAK,CAAC;EAEhC,KAAK,IAAIZ,CAAC,GAAGa,MAAM,CAAChC,MAAM,GAAG,CAAC,EAAEmB,CAAC,GAAG,CAAC,EAAEA,CAAC,EAAE,EAAE;IACxC,MAAMc,CAAC,GAAGC,IAAI,CAACC,KAAK,CAACD,IAAI,CAACE,MAAM,CAAC,CAAC,IAAIjB,CAAC,GAAG,CAAC,CAAC,CAAC;IAE7C,CAACa,MAAM,CAACb,CAAC,CAAC,EAAEa,MAAM,CAACC,CAAC,CAAC,CAAC,GAAG,CAACD,MAAM,CAACC,CAAC,CAAC,EAAGD,MAAM,CAACb,CAAC,CAAC,CAAE;EACrD;EAEA,OAAOa,MAAM;AACjB,CAAC;AAACV,OAAA,CAAAQ,YAAA,GAAAA,YAAA;AAQK,MAAMO,kBAAkB,GAAGA,CAAC;EAC/BC,cAAc;EACdC,eAAe;EACfC;AACqB,CAAC,KAAuC;EAC7D,MAAMC,SAAS,GAAG,CAAC;EACnB,MAAMC,SAAS,GAAG,EAAE;EAEpB,MAAMC,eAAe,GAAGL,cAAc,GAAGC,eAAe;;EAExD;EACA,MAAMK,KAAK,GAAGV,IAAI,CAACW,GAAG,CAACL,eAAe,GAAGG,eAAe,EAAED,SAAS,CAAC;EAEpE,IAAIE,KAAK,GAAGH,SAAS,EAAE;IACnB,OAAO;MAAEG,KAAK,EAAE,CAAC;MAAEE,KAAK,EAAE;IAAE,CAAC;EACjC;EAEA,OAAO;IAAEF,KAAK;IAAEE,KAAK,EAAE;EAAE,CAAC;AAC9B,CAAC;AAACxB,OAAA,CAAAe,kBAAA,GAAAA,kBAAA","ignoreList":[]}
@@ -31,7 +31,8 @@ const Typewriter = _ref => {
31
31
  resetSpeed = speed,
32
32
  startDelay = TypewriterDelay.None,
33
33
  textStyle,
34
- shouldCalcAutoSpeed = false
34
+ shouldCalcAutoSpeed = false,
35
+ autoSpeedBaseFactor = 2000
35
36
  } = _ref;
36
37
  const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);
37
38
  const [hasRenderedChildrenOnce, setHasRenderedChildrenOnce] = useState(false);
@@ -99,11 +100,12 @@ const Typewriter = _ref => {
99
100
  steps
100
101
  } = calculateAutoSpeed({
101
102
  fullTextLength: charactersCount,
102
- currentPosition: currentPosition.current
103
+ currentPosition: currentPosition.current,
104
+ baseSpeedFactor: autoSpeedBaseFactor
103
105
  });
104
106
  setAutoSpeed(calculatedAutoSpeed);
105
107
  setAutoSteps(steps);
106
- }, [charactersCount, shouldCalcAutoSpeed, speed, textContent]);
108
+ }, [autoSpeedBaseFactor, charactersCount, shouldCalcAutoSpeed]);
107
109
  const isAnimatingText = shownCharCount < textContent.length || shouldForceCursorAnimation || areMultipleChildrenGiven || textContent.length === 0;
108
110
  const handleClick = useCallback(event => {
109
111
  event.stopPropagation();
@@ -194,6 +196,10 @@ const Typewriter = _ref => {
194
196
  startTypingAnimation();
195
197
  }
196
198
  }
199
+ console.debug('TEST - Typewriter', {
200
+ autoSpeed,
201
+ autoSteps
202
+ });
197
203
  return () => {
198
204
  window.clearInterval(interval);
199
205
  };
@@ -1 +1 @@
1
- {"version":3,"file":"Typewriter.js","names":["ColorSchemeProvider","ChaynsProvider","useFunctions","useValues","React","useCallback","useEffect","useLayoutEffect","useMemo","useRef","useState","createPortal","renderToString","CursorType","TypewriterDelay","TypewriterSpeed","AnimatedTypewriterText","StyledTypewriter","StyledTypewriterPseudoText","StyledTypewriterText","calculateAutoSpeed","getCharactersCount","getSubTextFromHTML","shuffleArray","useIsomorphicLayoutEffect","window","Typewriter","_ref","children","cursorType","Default","nextTextDelay","Medium","onFinish","onResetAnimationEnd","onResetAnimationStart","onTypingAnimationEnd","onTypingAnimationStart","pseudoChildren","resetDelay","shouldForceCursorAnimation","shouldHideCursor","shouldSortChildrenRandomly","shouldUseAnimationHeight","shouldUseResetAnimation","shouldWaitForContent","speed","resetSpeed","startDelay","None","textStyle","shouldCalcAutoSpeed","currentChildrenIndex","setCurrentChildrenIndex","hasRenderedChildrenOnce","setHasRenderedChildrenOnce","shouldPreventBlinkingCursor","setShouldPreventBlinkingCursor","isResetAnimationActive","setIsResetAnimationActive","shouldStopAnimation","setShouldStopAnimation","autoSpeed","setAutoSpeed","autoSteps","setAutoSteps","functions","values","sortedChildren","Array","isArray","areMultipleChildrenGiven","childrenCount","length","textContent","currentChildren","isValidElement","createElement","data","isModule","color","colorMode","style","display","charactersCount","shownCharCount","setShownCharCount","currentPosition","undefined","calculatedAutoSpeed","steps","fullTextLength","current","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","dangerouslySetInnerHTML","__html","position","visibility","document","body","displayName"],"sources":["../../../../src/components/typewriter/Typewriter.tsx"],"sourcesContent":["import { ColorSchemeProvider } 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 { CursorType } from '../../types/cursor';\nimport { TypewriterDelay, TypewriterSpeed } from '../../types/speed';\nimport AnimatedTypewriterText from './AnimatedTypewriterText';\nimport {\n StyledTypewriter,\n StyledTypewriterPseudoText,\n StyledTypewriterText,\n} from './Typewriter.styles';\nimport { calculateAutoSpeed, getCharactersCount, getSubTextFromHTML, shuffleArray } from './utils';\n\nconst useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport type TypewriterProps = {\n /**\n * The 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 * Specifies whether the children should be sorted randomly if there are multiple texts.\n * This makes the typewriter start with a different text each time and also changes them\n * in a random order.\n */\n shouldSortChildrenRandomly?: boolean;\n /**\n * Specifies whether the animation should use its full height or the height of the current\n * chunk.\n */\n shouldUseAnimationHeight?: boolean;\n /**\n * Whether the animation speed should be calculated with the chunk interval.\n */\n shouldCalcAutoSpeed?: boolean;\n /**\n * Specifies whether the reset of the text should be animated with a backspace animation for\n * multiple texts.\n */\n shouldUseResetAnimation?: boolean;\n /**\n * Whether the typewriter should wait for new content\n */\n shouldWaitForContent?: boolean;\n /**\n * The speed of the animation. Use the TypewriterSpeed enum for this prop.\n */\n speed?: TypewriterSpeed | number;\n /**\n * The delay in milliseconds before the typewriter starts typing.\n */\n startDelay?: TypewriterDelay;\n /**\n * The style of the typewriter text element\n */\n textStyle?: React.CSSProperties;\n};\n\nconst Typewriter: FC<TypewriterProps> = ({\n children,\n cursorType = CursorType.Default,\n nextTextDelay = TypewriterDelay.Medium,\n onFinish,\n onResetAnimationEnd,\n onResetAnimationStart,\n onTypingAnimationEnd,\n onTypingAnimationStart,\n pseudoChildren,\n resetDelay = TypewriterDelay.Medium,\n shouldForceCursorAnimation = false,\n shouldHideCursor = 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}) => {\n const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);\n const [hasRenderedChildrenOnce, setHasRenderedChildrenOnce] = useState(false);\n const [shouldPreventBlinkingCursor, setShouldPreventBlinkingCursor] = useState(false);\n const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);\n const [shouldStopAnimation, setShouldStopAnimation] = useState(false);\n const [autoSpeed, setAutoSpeed] = useState<number>();\n const [autoSteps, setAutoSteps] = useState(1);\n\n const functions = useFunctions();\n const values = useValues();\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=\"#005EB8\"\n colorMode={0}\n style={{ display: 'inline' }}\n >\n {currentChildren}\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=\"#005EB8\"\n colorMode={0}\n style={{ display: 'inline' }}\n >\n {sortedChildren}\n </ColorSchemeProvider>\n </ChaynsProvider>,\n )\n : (sortedChildren as string);\n }, [areMultipleChildrenGiven, currentChildrenIndex, functions, sortedChildren, values]);\n\n const charactersCount = useMemo(() => getCharactersCount(textContent), [textContent]);\n\n const [shownCharCount, setShownCharCount] = useState(\n charactersCount > 0 ? 0 : textContent.length,\n );\n\n const currentPosition = useRef(0);\n\n useEffect(() => {\n if (!shouldCalcAutoSpeed) {\n setAutoSpeed(undefined);\n setAutoSteps(1);\n\n return;\n }\n\n const { speed: calculatedAutoSpeed, steps } = calculateAutoSpeed({\n fullTextLength: charactersCount,\n currentPosition: currentPosition.current,\n });\n\n setAutoSpeed(calculatedAutoSpeed);\n setAutoSteps(steps);\n }, [charactersCount, shouldCalcAutoSpeed, speed, textContent]);\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 - 1;\n currentPosition.current = nextState;\n\n if (nextState === 0) {\n window.clearInterval(interval);\n\n if (typeof onResetAnimationEnd === 'function') {\n onResetAnimationEnd();\n }\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n setIsResetAnimationActive(false);\n handleSetNextChildrenIndex();\n }, nextTextDelay);\n }\n }\n\n return nextState;\n });\n }, resetSpeed);\n } else {\n const startTypingAnimation = () => {\n if (cursorType === CursorType.Thin) {\n setShouldPreventBlinkingCursor(true);\n }\n\n if (typeof onTypingAnimationStart === 'function') {\n onTypingAnimationStart();\n }\n\n const runTypingInterval = () => {\n setShownCharCount((prevState) => {\n let nextState = Math.min(prevState + autoSteps, charactersCount);\n\n if (nextState >= charactersCount && !shouldWaitForContent) {\n window.clearInterval(interval);\n\n if (cursorType === CursorType.Thin) {\n setShouldPreventBlinkingCursor(false);\n }\n\n if (typeof onTypingAnimationEnd === 'function') {\n onTypingAnimationEnd();\n }\n\n /**\n * At this point, the next value for \"shownCharCount\" is deliberately set to\n * the length of the textContent in order to correctly display HTML elements\n * after the last letter.\n */\n nextState = textContent.length;\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n if (shouldUseResetAnimation) {\n setIsResetAnimationActive(true);\n } else {\n setShownCharCount(0);\n setTimeout(handleSetNextChildrenIndex, nextTextDelay);\n }\n }, resetDelay);\n }\n }\n\n currentPosition.current = nextState;\n\n return nextState;\n });\n };\n\n interval = window.setInterval(runTypingInterval, autoSpeed ?? speed);\n };\n\n if (startDelay) {\n setTimeout(startTypingAnimation, startDelay);\n } else {\n startTypingAnimation();\n }\n }\n\n return () => {\n window.clearInterval(interval);\n };\n }, [\n resetSpeed,\n speed,\n resetDelay,\n childrenCount,\n charactersCount,\n textContent.length,\n shouldStopAnimation,\n shouldWaitForContent,\n isResetAnimationActive,\n shouldUseResetAnimation,\n areMultipleChildrenGiven,\n handleSetNextChildrenIndex,\n nextTextDelay,\n startDelay,\n onResetAnimationStart,\n onResetAnimationEnd,\n onTypingAnimationStart,\n onTypingAnimationEnd,\n cursorType,\n autoSpeed,\n autoSteps,\n ]);\n\n useEffect(() => {\n if (!isAnimatingText && typeof onFinish === 'function') {\n onFinish();\n }\n }, [isAnimatingText, onFinish]);\n\n const shownText = useMemo(\n () => getSubTextFromHTML(textContent, shownCharCount),\n [shownCharCount, textContent],\n );\n\n const pseudoTextHTML = useMemo(() => {\n if (pseudoChildren) {\n const pseudoText = React.isValidElement(pseudoChildren)\n ? renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider\n color=\"#005EB8\"\n colorMode={0}\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 }, [functions, pseudoChildren, shouldUseAnimationHeight, shownCharCount, textContent, values]);\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 shownText={shownText}\n textStyle={textStyle}\n />\n ) : (\n <StyledTypewriterText style={textStyle}>{sortedChildren}</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 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 shownText,\n sortedChildren,\n textStyle,\n ],\n );\n};\n\nTypewriter.displayName = 'Typewriter';\n\nexport default Typewriter;\n"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,yBAAyB;AAC7D,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;AACjD,SAASC,UAAU,QAAQ,oBAAoB;AAC/C,SAASC,eAAe,EAAEC,eAAe,QAAQ,mBAAmB;AACpE,OAAOC,sBAAsB,MAAM,0BAA0B;AAC7D,SACIC,gBAAgB,EAChBC,0BAA0B,EAC1BC,oBAAoB,QACjB,qBAAqB;AAC5B,SAASC,kBAAkB,EAAEC,kBAAkB,EAAEC,kBAAkB,EAAEC,YAAY,QAAQ,SAAS;AAElG,MAAMC,yBAAyB,GAAG,OAAOC,MAAM,KAAK,WAAW,GAAGlB,eAAe,GAAGD,SAAS;AAqG7F,MAAMoB,UAA+B,GAAGC,IAAA,IAsBlC;EAAA,IAtBmC;IACrCC,QAAQ;IACRC,UAAU,GAAGhB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ACZzF,KAAA,CAAAyE,aAAA,CAAC3D,0BAA0B;IACvBkG,gBAAgB,EAAEvB,eAAgB;IAClCwB,iBAAiB,EAAE5E,gBAAiB;IACpC8E,uBAAuB,EAAE;MAAEC,MAAM,EAAER;IAAe;EAAE,CACvD,CACJ,EAKA,CAAC1D,uBAAuB,iBACrB3C,YAAY,cACRP,KAAA,CAAAyE,aAAA;IAAKK,KAAK,EAAE;MAAEuC,QAAQ,EAAE,UAAU;MAAEC,UAAU,EAAE;IAAS;EAAE,GACtD9F,QACA,CAAC,EACN+F,QAAQ,CAACC,IACb,CACU,CACrB,EACD,CACIhG,QAAQ,EACRC,UAAU,EACViE,WAAW,EACXxC,uBAAuB,EACvBuC,eAAe,EACfmB,cAAc,EACdvE,gBAAgB,EAChBe,2BAA2B,EAC3BuD,SAAS,EACT3C,cAAc,EACdlB,SAAS,CAEjB,CAAC;AACL,CAAC;AAEDxB,UAAU,CAACmG,WAAW,GAAG,YAAY;AAErC,eAAenG,UAAU","ignoreList":[]}
1
+ {"version":3,"file":"Typewriter.js","names":["ColorSchemeProvider","ChaynsProvider","useFunctions","useValues","React","useCallback","useEffect","useLayoutEffect","useMemo","useRef","useState","createPortal","renderToString","CursorType","TypewriterDelay","TypewriterSpeed","AnimatedTypewriterText","StyledTypewriter","StyledTypewriterPseudoText","StyledTypewriterText","calculateAutoSpeed","getCharactersCount","getSubTextFromHTML","shuffleArray","useIsomorphicLayoutEffect","window","Typewriter","_ref","children","cursorType","Default","nextTextDelay","Medium","onFinish","onResetAnimationEnd","onResetAnimationStart","onTypingAnimationEnd","onTypingAnimationStart","pseudoChildren","resetDelay","shouldForceCursorAnimation","shouldHideCursor","shouldSortChildrenRandomly","shouldUseAnimationHeight","shouldUseResetAnimation","shouldWaitForContent","speed","resetSpeed","startDelay","None","textStyle","shouldCalcAutoSpeed","autoSpeedBaseFactor","currentChildrenIndex","setCurrentChildrenIndex","hasRenderedChildrenOnce","setHasRenderedChildrenOnce","shouldPreventBlinkingCursor","setShouldPreventBlinkingCursor","isResetAnimationActive","setIsResetAnimationActive","shouldStopAnimation","setShouldStopAnimation","autoSpeed","setAutoSpeed","autoSteps","setAutoSteps","functions","values","sortedChildren","Array","isArray","areMultipleChildrenGiven","childrenCount","length","textContent","currentChildren","isValidElement","createElement","data","isModule","color","colorMode","style","display","charactersCount","shownCharCount","setShownCharCount","currentPosition","undefined","calculatedAutoSpeed","steps","fullTextLength","current","baseSpeedFactor","isAnimatingText","handleClick","event","stopPropagation","preventDefault","handleSetNextChildrenIndex","newIndex","interval","setInterval","prevState","nextState","clearInterval","setTimeout","startTypingAnimation","Thin","runTypingInterval","Math","min","console","debug","shownText","pseudoTextHTML","pseudoText","$cursorType","onClick","$isAnimatingText","$shouldHideCursor","$shouldPreventBlinkAnimation","dangerouslySetInnerHTML","__html","position","visibility","document","body","displayName"],"sources":["../../../../src/components/typewriter/Typewriter.tsx"],"sourcesContent":["import { ColorSchemeProvider } 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 { CursorType } from '../../types/cursor';\nimport { TypewriterDelay, TypewriterSpeed } from '../../types/speed';\nimport AnimatedTypewriterText from './AnimatedTypewriterText';\nimport {\n StyledTypewriter,\n StyledTypewriterPseudoText,\n StyledTypewriterText,\n} from './Typewriter.styles';\nimport { calculateAutoSpeed, getCharactersCount, getSubTextFromHTML, shuffleArray } from './utils';\n\nconst useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport type TypewriterProps = {\n /**\n * The base speed factor to calculate the animation speed.\n */\n autoSpeedBaseFactor?: number;\n /**\n * The text to type\n */\n children: ReactElement | ReactElement[] | string | string[];\n /**\n * The type of the cursor. Use the CursorType enum for this prop.\n */\n cursorType?: CursorType;\n /**\n * The delay in milliseconds before the next text is shown.\n * This prop is only used if multiple texts are given.\n */\n nextTextDelay?: TypewriterDelay;\n /**\n * Function that is executed when the typewriter animation has finished. This function will not\n * be executed if multiple texts are used.\n */\n onFinish?: VoidFunction;\n /**\n * Function that is executed when the reset animation has finished. This function will not be\n * executed if `shouldUseResetAnimation` is not set to `true`.\n */\n onResetAnimationEnd?: VoidFunction;\n /**\n * Function that is executed when the reset animation has started. This function will not be\n * executed if `shouldUseResetAnimation` is not set to `true`.\n */\n onResetAnimationStart?: VoidFunction;\n /**\n * Function that is executed when the typing animation has finished. If multiple texts are given,\n * this function will be executed for each text.\n */\n onTypingAnimationEnd?: VoidFunction;\n /**\n * Function that is executed when the typing animation has started. If multiple texts are given,\n * this function will be executed for each text.\n */\n onTypingAnimationStart?: VoidFunction;\n /**\n * Pseudo-element to be rendered invisible during animation to define the size of the element\n * for the typewriter effect. By default, the \"children\" is used for this purpose.\n */\n pseudoChildren?: ReactElement | string;\n /**\n * Waiting time in milliseconds before the typewriter resets the text.\n * This prop is only used if multiple texts are given.\n */\n resetDelay?: TypewriterDelay;\n /**\n * The reset speed of the animation. Use the TypewriterSpeed enum for this prop.\n */\n resetSpeed?: TypewriterSpeed | number;\n /**\n * Specifies whether the cursor should be forced to animate even if no text is currently animated.\n */\n shouldForceCursorAnimation?: boolean;\n /**\n * Specifies whether the cursor should be hidden\n */\n shouldHideCursor?: boolean;\n /**\n * Specifies whether the children should be sorted randomly if there are multiple texts.\n * This makes the typewriter start with a different text each time and also changes them\n * in a random order.\n */\n shouldSortChildrenRandomly?: boolean;\n /**\n * Specifies whether the animation should use its full height or the height of the current\n * chunk.\n */\n shouldUseAnimationHeight?: boolean;\n /**\n * Whether the animation speed should be calculated with the chunk interval.\n */\n shouldCalcAutoSpeed?: boolean;\n /**\n * Specifies whether the reset of the text should be animated with a backspace animation for\n * multiple texts.\n */\n shouldUseResetAnimation?: boolean;\n /**\n * Whether the typewriter should wait for new content\n */\n shouldWaitForContent?: boolean;\n /**\n * The speed of the animation. Use the TypewriterSpeed enum for this prop.\n */\n speed?: TypewriterSpeed | number;\n /**\n * The delay in milliseconds before the typewriter starts typing.\n */\n startDelay?: TypewriterDelay;\n /**\n * The style of the typewriter text element\n */\n textStyle?: React.CSSProperties;\n};\n\nconst Typewriter: FC<TypewriterProps> = ({\n children,\n cursorType = CursorType.Default,\n nextTextDelay = TypewriterDelay.Medium,\n onFinish,\n onResetAnimationEnd,\n onResetAnimationStart,\n onTypingAnimationEnd,\n onTypingAnimationStart,\n pseudoChildren,\n resetDelay = TypewriterDelay.Medium,\n shouldForceCursorAnimation = false,\n shouldHideCursor = false,\n shouldSortChildrenRandomly = false,\n shouldUseAnimationHeight = false,\n shouldUseResetAnimation = false,\n shouldWaitForContent,\n speed = TypewriterSpeed.Medium,\n resetSpeed = speed,\n startDelay = TypewriterDelay.None,\n textStyle,\n shouldCalcAutoSpeed = false,\n autoSpeedBaseFactor = 2000,\n}) => {\n const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);\n const [hasRenderedChildrenOnce, setHasRenderedChildrenOnce] = useState(false);\n const [shouldPreventBlinkingCursor, setShouldPreventBlinkingCursor] = useState(false);\n const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);\n const [shouldStopAnimation, setShouldStopAnimation] = useState(false);\n const [autoSpeed, setAutoSpeed] = useState<number>();\n const [autoSteps, setAutoSteps] = useState(1);\n\n const functions = useFunctions();\n const values = useValues();\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=\"#005EB8\"\n colorMode={0}\n style={{ display: 'inline' }}\n >\n {currentChildren}\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=\"#005EB8\"\n colorMode={0}\n style={{ display: 'inline' }}\n >\n {sortedChildren}\n </ColorSchemeProvider>\n </ChaynsProvider>,\n )\n : (sortedChildren as string);\n }, [areMultipleChildrenGiven, currentChildrenIndex, functions, sortedChildren, values]);\n\n const charactersCount = useMemo(() => getCharactersCount(textContent), [textContent]);\n\n const [shownCharCount, setShownCharCount] = useState(\n charactersCount > 0 ? 0 : textContent.length,\n );\n\n const currentPosition = useRef(0);\n\n useEffect(() => {\n if (!shouldCalcAutoSpeed) {\n setAutoSpeed(undefined);\n setAutoSteps(1);\n\n return;\n }\n\n const { speed: calculatedAutoSpeed, steps } = calculateAutoSpeed({\n fullTextLength: charactersCount,\n currentPosition: currentPosition.current,\n baseSpeedFactor: autoSpeedBaseFactor,\n });\n\n setAutoSpeed(calculatedAutoSpeed);\n setAutoSteps(steps);\n }, [autoSpeedBaseFactor, charactersCount, shouldCalcAutoSpeed]);\n\n const isAnimatingText =\n shownCharCount < textContent.length ||\n shouldForceCursorAnimation ||\n areMultipleChildrenGiven ||\n textContent.length === 0;\n\n const handleClick = useCallback((event: React.MouseEvent) => {\n event.stopPropagation();\n event.preventDefault();\n\n setShouldStopAnimation(true);\n }, []);\n\n const handleSetNextChildrenIndex = useCallback(\n () =>\n setCurrentChildrenIndex(() => {\n let newIndex = currentChildrenIndex + 1;\n\n if (newIndex > childrenCount - 1) {\n newIndex = 0;\n }\n\n return newIndex;\n }),\n [childrenCount, currentChildrenIndex],\n );\n\n useEffect(() => {\n let interval: number | undefined;\n\n if (shouldStopAnimation || charactersCount === 0) {\n setShownCharCount(textContent.length);\n currentPosition.current = textContent.length;\n } else if (isResetAnimationActive) {\n if (typeof onResetAnimationStart === 'function') {\n onResetAnimationStart();\n }\n\n interval = window.setInterval(() => {\n setShownCharCount((prevState) => {\n const nextState = prevState - 1;\n currentPosition.current = nextState;\n\n if (nextState === 0) {\n window.clearInterval(interval);\n\n if (typeof onResetAnimationEnd === 'function') {\n onResetAnimationEnd();\n }\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n setIsResetAnimationActive(false);\n handleSetNextChildrenIndex();\n }, nextTextDelay);\n }\n }\n\n return nextState;\n });\n }, resetSpeed);\n } else {\n const startTypingAnimation = () => {\n if (cursorType === CursorType.Thin) {\n setShouldPreventBlinkingCursor(true);\n }\n\n if (typeof onTypingAnimationStart === 'function') {\n onTypingAnimationStart();\n }\n\n const runTypingInterval = () => {\n setShownCharCount((prevState) => {\n let nextState = Math.min(prevState + autoSteps, charactersCount);\n\n if (nextState >= charactersCount && !shouldWaitForContent) {\n window.clearInterval(interval);\n\n if (cursorType === CursorType.Thin) {\n setShouldPreventBlinkingCursor(false);\n }\n\n if (typeof onTypingAnimationEnd === 'function') {\n onTypingAnimationEnd();\n }\n\n /**\n * At this point, the next value for \"shownCharCount\" is deliberately set to\n * the length of the textContent in order to correctly display HTML elements\n * after the last letter.\n */\n nextState = textContent.length;\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n if (shouldUseResetAnimation) {\n setIsResetAnimationActive(true);\n } else {\n setShownCharCount(0);\n setTimeout(handleSetNextChildrenIndex, nextTextDelay);\n }\n }, resetDelay);\n }\n }\n\n currentPosition.current = nextState;\n\n return nextState;\n });\n };\n\n interval = window.setInterval(runTypingInterval, autoSpeed ?? speed);\n };\n\n if (startDelay) {\n setTimeout(startTypingAnimation, startDelay);\n } else {\n startTypingAnimation();\n }\n }\n\n console.debug('TEST - Typewriter', { autoSpeed, autoSteps });\n\n return () => {\n window.clearInterval(interval);\n };\n }, [\n resetSpeed,\n speed,\n resetDelay,\n childrenCount,\n charactersCount,\n textContent.length,\n shouldStopAnimation,\n shouldWaitForContent,\n isResetAnimationActive,\n shouldUseResetAnimation,\n areMultipleChildrenGiven,\n handleSetNextChildrenIndex,\n nextTextDelay,\n startDelay,\n onResetAnimationStart,\n onResetAnimationEnd,\n onTypingAnimationStart,\n onTypingAnimationEnd,\n cursorType,\n autoSpeed,\n autoSteps,\n ]);\n\n useEffect(() => {\n if (!isAnimatingText && typeof onFinish === 'function') {\n onFinish();\n }\n }, [isAnimatingText, onFinish]);\n\n const shownText = useMemo(\n () => getSubTextFromHTML(textContent, shownCharCount),\n [shownCharCount, textContent],\n );\n\n const pseudoTextHTML = useMemo(() => {\n if (pseudoChildren) {\n const pseudoText = React.isValidElement(pseudoChildren)\n ? renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider\n color=\"#005EB8\"\n colorMode={0}\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 }, [functions, pseudoChildren, shouldUseAnimationHeight, shownCharCount, textContent, values]);\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 shownText={shownText}\n textStyle={textStyle}\n />\n ) : (\n <StyledTypewriterText style={textStyle}>{sortedChildren}</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 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 shownText,\n sortedChildren,\n textStyle,\n ],\n );\n};\n\nTypewriter.displayName = 'Typewriter';\n\nexport default Typewriter;\n"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,yBAAyB;AAC7D,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;AACjD,SAASC,UAAU,QAAQ,oBAAoB;AAC/C,SAASC,eAAe,EAAEC,eAAe,QAAQ,mBAAmB;AACpE,OAAOC,sBAAsB,MAAM,0BAA0B;AAC7D,SACIC,gBAAgB,EAChBC,0BAA0B,EAC1BC,oBAAoB,QACjB,qBAAqB;AAC5B,SAASC,kBAAkB,EAAEC,kBAAkB,EAAEC,kBAAkB,EAAEC,YAAY,QAAQ,SAAS;AAElG,MAAMC,yBAAyB,GAAG,OAAOC,MAAM,KAAK,WAAW,GAAGlB,eAAe,GAAGD,SAAS;AAyG7F,MAAMoB,UAA+B,GAAGC,IAAA,IAuBlC;EAAA,IAvBmC;I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S,EAAEA,SAAU;IACrBjE,SAAS,EAAEA;EAAU,CACxB,CAAC,gBAEF9C,KAAA,CAAA0E,aAAA,CAAC3D,oBAAoB;IAACgE,KAAK,EAAEjC;EAAU,GAAEmB,cAAqC,CACjF,EACA0B,eAAe,iBACZ3F,KAAA,CAAA0E,aAAA,CAAC5D,0BAA0B;IACvBsG,gBAAgB,EAAEzB,eAAgB;IAClC0B,iBAAiB,EAAEhF,gBAAiB;IACpCkF,uBAAuB,EAAE;MAAEC,MAAM,EAAER;IAAe;EAAE,CACvD,CACJ,EAKA,CAAC7D,uBAAuB,iBACrB5C,YAAY,cACRP,KAAA,CAAA0E,aAAA;IAAKK,KAAK,EAAE;MAAE0C,QAAQ,EAAE,UAAU;MAAEC,UAAU,EAAE;IAAS;EAAE,GACtDlG,QACA,CAAC,EACNmG,QAAQ,CAACC,IACb,CACU,CACrB,EACD,CACIpG,QAAQ,EACRC,UAAU,EACVmE,WAAW,EACXzC,uBAAuB,EACvBwC,eAAe,EACfqB,cAAc,EACd3E,gBAAgB,EAChBgB,2BAA2B,EAC3B0D,SAAS,EACT9C,cAAc,EACdnB,SAAS,CAEjB,CAAC;AACL,CAAC;AAEDxB,UAAU,CAACuG,WAAW,GAAG,YAAY;AAErC,eAAevG,UAAU","ignoreList":[]}
@@ -85,14 +85,15 @@ export const shuffleArray = array => {
85
85
  export const calculateAutoSpeed = _ref => {
86
86
  let {
87
87
  fullTextLength,
88
- currentPosition
88
+ currentPosition,
89
+ baseSpeedFactor
89
90
  } = _ref;
90
91
  const MIN_SPEED = 1;
91
92
  const MAX_SPEED = 10;
92
93
  const remainingLength = fullTextLength - currentPosition;
93
94
 
94
- // Calculate the speed with the remaining text length
95
- const speed = Math.min(2000 / remainingLength, MAX_SPEED);
95
+ // Calculate the speed with the remaining text length and the baseSpeedFactor
96
+ const speed = Math.min(baseSpeedFactor / remainingLength, MAX_SPEED);
96
97
  if (speed < MIN_SPEED) {
97
98
  return {
98
99
  speed: 1,
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","names":["getSubTextFromHTML","html","length","div","document","createElement","innerHTML","text","currLength","traverse","element","nodeName","nodeType","textContent","nodeText","substring","toLowerCase","attributes","attribute","name","value","i","childNodes","childNode","getCharactersCount","count","node","trim","Array","from","forEach","shuffleArray","array","result","j","Math","floor","random","calculateAutoSpeed","_ref","fullTextLength","currentPosition","MIN_SPEED","MAX_SPEED","remainingLength","speed","min","steps"],"sources":["../../../../src/components/typewriter/utils.ts"],"sourcesContent":["/**\n * This function extracts a part of the text from an HTML text. The HTML elements themselves are\n * returned in the result. In addition, the function ensures that the closing tag of the Bold HTML\n * element is also returned for text that is cut off in the middle of a Bold element, for example.\n *\n * @param html - The text from which a part should be taken\n * @param length - The length of the text to be extracted\n *\n * @return string - The text part with the specified length - additionally the HTML elements are added\n */\nexport const getSubTextFromHTML = (html: string, length: number): string => {\n const div = document.createElement('div');\n\n div.innerHTML = html;\n\n let text = '';\n let currLength = 0;\n\n const traverse = (element: Element): boolean => {\n if (element.nodeName === 'TWIGNORE') {\n text += element.innerHTML;\n } else if (element.nodeType === 3 && typeof element.textContent === 'string') {\n const nodeText = element.textContent;\n\n if (currLength + nodeText.length <= length) {\n text += nodeText;\n currLength += nodeText.length;\n } else {\n text += nodeText.substring(0, length - currLength);\n\n return false;\n }\n } else if (element.nodeType === 1) {\n const nodeName = element.nodeName.toLowerCase();\n\n let attributes = '';\n\n // @ts-expect-error: Type is correct here\n // eslint-disable-next-line no-restricted-syntax\n for (const attribute of element.attributes) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/restrict-template-expressions\n attributes += ` ${attribute.name}=\"${attribute.value}\"`;\n }\n\n text += `<${nodeName}${attributes}>`;\n\n for (let i = 0; i < element.childNodes.length; i++) {\n const childNode = element.childNodes[i];\n\n if (childNode && !traverse(childNode as Element)) {\n return false;\n }\n }\n\n text += `</${nodeName}>`;\n }\n\n return true;\n };\n\n for (let i = 0; i < div.childNodes.length; i++) {\n const childNode = div.childNodes[i];\n\n if (childNode && !traverse(childNode as Element)) {\n return text;\n }\n }\n\n return text;\n};\n\nexport const getCharactersCount = (html: string): number => {\n const div = document.createElement('div');\n\n div.innerHTML = html;\n\n let count = 0;\n\n const traverse = (node: Node): void => {\n if (node.nodeName === 'TWIGNORE') {\n count += 1;\n } else if (node.nodeType === 3 && typeof node.textContent === 'string') {\n count += node.textContent.trim().length;\n } else if (node.nodeType === 1) {\n if (node.nodeName === 'CODE' && node.textContent !== null) {\n count += node.textContent.length;\n\n return;\n }\n\n Array.from(node.childNodes).forEach(traverse);\n }\n };\n\n Array.from(div.childNodes).forEach(traverse);\n\n return count;\n};\n\nexport const shuffleArray = <T>(array: T[]): T[] => {\n const result = Array.from(array);\n\n for (let i = result.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n\n [result[i], result[j]] = [result[j]!, result[i]!];\n }\n\n return result;\n};\n\ninterface CalculateAutoSpeedProps {\n fullTextLength: number;\n currentPosition: number;\n}\n\nexport const calculateAutoSpeed = ({\n fullTextLength,\n currentPosition,\n}: CalculateAutoSpeedProps): { speed: number; steps: number } => {\n const MIN_SPEED = 1;\n const MAX_SPEED = 10;\n\n const remainingLength = fullTextLength - currentPosition;\n\n // Calculate the speed with the remaining text length\n const speed = Math.min(2000 / remainingLength, MAX_SPEED);\n\n if (speed < MIN_SPEED) {\n return { speed: 1, steps: 2 };\n }\n\n return { speed, steps: 1 };\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,kBAAkB,GAAGA,CAACC,IAAY,EAAEC,MAAc,KAAa;EACxE,MAAMC,GAAG,GAAGC,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAEzCF,GAAG,CAACG,SAAS,GAAGL,IAAI;EAEpB,IAAIM,IAAI,GAAG,EAAE;EACb,IAAIC,UAAU,GAAG,CAAC;EAElB,MAAMC,QAAQ,GAAIC,OAAgB,IAAc;I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,KAAK;AAChB,CAAC;AAED,OAAO,MAAMM,YAAY,GAAOC,KAAU,IAAU;EAChD,MAAMC,MAAM,GAAGL,KAAK,CAACC,IAAI,CAACG,KAAK,CAAC;EAEhC,KAAK,IAAIX,CAAC,GAAGY,MAAM,CAAC/B,MAAM,GAAG,CAAC,EAAEmB,CAAC,GAAG,CAAC,EAAEA,CAAC,EAAE,EAAE;IACxC,MAAMa,CAAC,GAAGC,IAAI,CAACC,KAAK,CAACD,IAAI,CAACE,MAAM,CAAC,CAAC,IAAIhB,CAAC,GAAG,CAAC,CAAC,CAAC;IAE7C,CAACY,MAAM,CAACZ,CAAC,CAAC,EAAEY,MAAM,CAACC,CAAC,CAAC,CAAC,GAAG,CAACD,MAAM,CAACC,CAAC,CAAC,EAAGD,MAAM,CAACZ,CAAC,CAAC,CAAE;EACrD;EAEA,OAAOY,MAAM;AACjB,CAAC;AAOD,OAAO,MAAMK,kBAAkB,GAAGC,IAAA,IAG+B;EAAA,IAH9B;IAC/BC,cAAc;IACdC;EACqB,CAAC,GAAAF,IAAA;EACtB,MAAMG,SAAS,GAAG,CAAC;EACnB,MAAMC,SAAS,GAAG,EAAE;EAEpB,MAAMC,eAAe,GAAGJ,cAAc,GAAGC,eAAe;;EAExD;EACA,MAAMI,KAAK,GAAGV,IAAI,CAACW,GAAG,CAAC,IAAI,GAAGF,eAAe,EAAED,SAAS,CAAC;EAEzD,IAAIE,KAAK,GAAGH,SAAS,EAAE;IACnB,OAAO;MAAEG,KAAK,EAAE,CAAC;MAAEE,KAAK,EAAE;IAAE,CAAC;EACjC;EAEA,OAAO;IAAEF,KAAK;IAAEE,KAAK,EAAE;EAAE,CAAC;AAC9B,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"utils.js","names":["getSubTextFromHTML","html","length","div","document","createElement","innerHTML","text","currLength","traverse","element","nodeName","nodeType","textContent","nodeText","substring","toLowerCase","attributes","attribute","name","value","i","childNodes","childNode","getCharactersCount","count","node","trim","Array","from","forEach","shuffleArray","array","result","j","Math","floor","random","calculateAutoSpeed","_ref","fullTextLength","currentPosition","baseSpeedFactor","MIN_SPEED","MAX_SPEED","remainingLength","speed","min","steps"],"sources":["../../../../src/components/typewriter/utils.ts"],"sourcesContent":["/**\n * This function extracts a part of the text from an HTML text. The HTML elements themselves are\n * returned in the result. In addition, the function ensures that the closing tag of the Bold HTML\n * element is also returned for text that is cut off in the middle of a Bold element, for example.\n *\n * @param html - The text from which a part should be taken\n * @param length - The length of the text to be extracted\n *\n * @return string - The text part with the specified length - additionally the HTML elements are added\n */\nexport const getSubTextFromHTML = (html: string, length: number): string => {\n const div = document.createElement('div');\n\n div.innerHTML = html;\n\n let text = '';\n let currLength = 0;\n\n const traverse = (element: Element): boolean => {\n if (element.nodeName === 'TWIGNORE') {\n text += element.innerHTML;\n } else if (element.nodeType === 3 && typeof element.textContent === 'string') {\n const nodeText = element.textContent;\n\n if (currLength + nodeText.length <= length) {\n text += nodeText;\n currLength += nodeText.length;\n } else {\n text += nodeText.substring(0, length - currLength);\n\n return false;\n }\n } else if (element.nodeType === 1) {\n const nodeName = element.nodeName.toLowerCase();\n\n let attributes = '';\n\n // @ts-expect-error: Type is correct here\n // eslint-disable-next-line no-restricted-syntax\n for (const attribute of element.attributes) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/restrict-template-expressions\n attributes += ` ${attribute.name}=\"${attribute.value}\"`;\n }\n\n text += `<${nodeName}${attributes}>`;\n\n for (let i = 0; i < element.childNodes.length; i++) {\n const childNode = element.childNodes[i];\n\n if (childNode && !traverse(childNode as Element)) {\n return false;\n }\n }\n\n text += `</${nodeName}>`;\n }\n\n return true;\n };\n\n for (let i = 0; i < div.childNodes.length; i++) {\n const childNode = div.childNodes[i];\n\n if (childNode && !traverse(childNode as Element)) {\n return text;\n }\n }\n\n return text;\n};\n\nexport const getCharactersCount = (html: string): number => {\n const div = document.createElement('div');\n\n div.innerHTML = html;\n\n let count = 0;\n\n const traverse = (node: Node): void => {\n if (node.nodeName === 'TWIGNORE') {\n count += 1;\n } else if (node.nodeType === 3 && typeof node.textContent === 'string') {\n count += node.textContent.trim().length;\n } else if (node.nodeType === 1) {\n if (node.nodeName === 'CODE' && node.textContent !== null) {\n count += node.textContent.length;\n\n return;\n }\n\n Array.from(node.childNodes).forEach(traverse);\n }\n };\n\n Array.from(div.childNodes).forEach(traverse);\n\n return count;\n};\n\nexport const shuffleArray = <T>(array: T[]): T[] => {\n const result = Array.from(array);\n\n for (let i = result.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n\n [result[i], result[j]] = [result[j]!, result[i]!];\n }\n\n return result;\n};\n\ninterface CalculateAutoSpeedProps {\n fullTextLength: number;\n currentPosition: number;\n baseSpeedFactor: number;\n}\n\nexport const calculateAutoSpeed = ({\n fullTextLength,\n currentPosition,\n baseSpeedFactor,\n}: CalculateAutoSpeedProps): { speed: number; steps: number } => {\n const MIN_SPEED = 1;\n const MAX_SPEED = 10;\n\n const remainingLength = fullTextLength - currentPosition;\n\n // Calculate the speed with the remaining text length and the baseSpeedFactor\n const speed = Math.min(baseSpeedFactor / remainingLength, MAX_SPEED);\n\n if (speed < MIN_SPEED) {\n return { speed: 1, steps: 2 };\n }\n\n return { speed, steps: 1 };\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,kBAAkB,GAAGA,CAACC,IAAY,EAAEC,MAAc,KAAa;EACxE,MAAMC,GAAG,GAAGC,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAEzCF,GAAG,CAACG,SAAS,GAAGL,IAAI;EAEpB,IAAIM,IAAI,GAAG,EAAE;EACb,IAAIC,UAAU,GAAG,CAAC;EAElB,MAAMC,QAAQ,GAAIC,OAAgB,IAAc;IAC5C,IAAIA,OAAO,CAACC,QAAQ,KAAK,UAAU,EAAE;MACjCJ,IAAI,IAAIG,OAAO,CAACJ,SAAS;IAC7B,CAAC,MAAM,IAAII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AK,CAAC;EAEhC,KAAK,IAAIX,CAAC,GAAGY,MAAM,CAAC/B,MAAM,GAAG,CAAC,EAAEmB,CAAC,GAAG,CAAC,EAAEA,CAAC,EAAE,EAAE;IACxC,MAAMa,CAAC,GAAGC,IAAI,CAACC,KAAK,CAACD,IAAI,CAACE,MAAM,CAAC,CAAC,IAAIhB,CAAC,GAAG,CAAC,CAAC,CAAC;IAE7C,CAACY,MAAM,CAACZ,CAAC,CAAC,EAAEY,MAAM,CAACC,CAAC,CAAC,CAAC,GAAG,CAACD,MAAM,CAACC,CAAC,CAAC,EAAGD,MAAM,CAACZ,CAAC,CAAC,CAAE;EACrD;EAEA,OAAOY,MAAM;AACjB,CAAC;AAQD,OAAO,MAAMK,kBAAkB,GAAGC,IAAA,IAI+B;EAAA,IAJ9B;IAC/BC,cAAc;IACdC,eAAe;IACfC;EACqB,CAAC,GAAAH,IAAA;EACtB,MAAMI,SAAS,GAAG,CAAC;EACnB,MAAMC,SAAS,GAAG,EAAE;EAEpB,MAAMC,eAAe,GAAGL,cAAc,GAAGC,eAAe;;EAExD;EACA,MAAMK,KAAK,GAAGX,IAAI,CAACY,GAAG,CAACL,eAAe,GAAGG,eAAe,EAAED,SAAS,CAAC;EAEpE,IAAIE,KAAK,GAAGH,SAAS,EAAE;IACnB,OAAO;MAAEG,KAAK,EAAE,CAAC;MAAEE,KAAK,EAAE;IAAE,CAAC;EACjC;EAEA,OAAO;IAAEF,KAAK;IAAEE,KAAK,EAAE;EAAE,CAAC;AAC9B,CAAC","ignoreList":[]}
@@ -2,6 +2,10 @@ import React, { FC, ReactElement } from 'react';
2
2
  import { CursorType } from '../../types/cursor';
3
3
  import { TypewriterDelay, TypewriterSpeed } from '../../types/speed';
4
4
  export type TypewriterProps = {
5
+ /**
6
+ * The base speed factor to calculate the animation speed.
7
+ */
8
+ autoSpeedBaseFactor?: number;
5
9
  /**
6
10
  * The text to type
7
11
  */
@@ -14,8 +14,9 @@ export declare const shuffleArray: <T>(array: T[]) => T[];
14
14
  interface CalculateAutoSpeedProps {
15
15
  fullTextLength: number;
16
16
  currentPosition: number;
17
+ baseSpeedFactor: number;
17
18
  }
18
- export declare const calculateAutoSpeed: ({ fullTextLength, currentPosition, }: CalculateAutoSpeedProps) => {
19
+ export declare const calculateAutoSpeed: ({ fullTextLength, currentPosition, baseSpeedFactor, }: CalculateAutoSpeedProps) => {
19
20
  speed: number;
20
21
  steps: number;
21
22
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chayns-components/typewriter",
3
- "version": "5.0.0-beta.959",
3
+ "version": "5.0.0-beta.960",
4
4
  "description": "A set of beautiful React components for developing your own applications with chayns.",
5
5
  "sideEffects": false,
6
6
  "browserslist": [
@@ -81,5 +81,5 @@
81
81
  "publishConfig": {
82
82
  "access": "public"
83
83
  },
84
- "gitHead": "9e4d6bd596d5144a831e709f27b7c1dc463d7874"
84
+ "gitHead": "07ad1c2f3597a911746a883d5b3291a894bbc4df"
85
85
  }