@chayns-components/typewriter 5.0.0-beta.596 → 5.0.0-beta.597

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.
@@ -156,7 +156,10 @@ const Typewriter = ({
156
156
  if (pseudoChildren) {
157
157
  const pseudoText = /*#__PURE__*/_react.default.isValidElement(pseudoChildren) ? (0, _server.renderToString)( /*#__PURE__*/_react.default.createElement(_core.ColorSchemeProvider, {
158
158
  color: "#005EB8",
159
- colorMode: 0
159
+ colorMode: 0,
160
+ style: {
161
+ display: 'inline'
162
+ }
160
163
  }, pseudoChildren)) : pseudoChildren;
161
164
  if (shouldUseAnimationHeight) {
162
165
  return (0, _utils.getSubTextFromHTML)(pseudoText, shownCharCount);
@@ -185,7 +188,9 @@ const Typewriter = ({
185
188
  }, sortedChildren), isAnimatingText && /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriterPseudoText, {
186
189
  dangerouslySetInnerHTML: {
187
190
  __html: pseudoTextHTML
188
- }
191
+ },
192
+ $isAnimatingText: true,
193
+ $shouldHideCursor: shouldHideCursor
189
194
  })), [handleClick, isAnimatingText, pseudoTextHTML, shouldHideCursor, shownText, sortedChildren, textStyle]);
190
195
  };
191
196
  Typewriter.displayName = 'Typewriter';
@@ -1 +1 @@
1
- {"version":3,"file":"Typewriter.js","names":["_core","require","_react","_interopRequireWildcard","_server","_Typewriter","_utils","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","TypewriterResetDelay","exports","TypewriterSpeed","Typewriter","children","onFinish","pseudoChildren","resetDelay","Medium","shouldForceCursorAnimation","shouldHideCursor","shouldSortChildrenRandomly","shouldUseAnimationHeight","shouldUseResetAnimation","shouldWaitForContent","speed","textStyle","currentChildrenIndex","setCurrentChildrenIndex","useState","shouldCount","setShouldCount","sortedChildren","useMemo","Array","isArray","shuffleArray","areMultipleChildrenGiven","childrenCount","length","textContent","currentChildren","React","isValidElement","renderToString","createElement","ColorSchemeProvider","color","colorMode","style","display","charactersCount","getCharactersCount","isResetAnimationActive","setIsResetAnimationActive","shownCharCount","setShownCharCount","shouldStopAnimation","setShouldStopAnimation","prevChildren","setPrevChildren","useEffect","isAnimatingText","handleClick","useCallback","handleSetNextChildrenIndex","newIndex","interval","window","setInterval","prevState","nextState","clearInterval","setTimeout","shownText","getSubTextFromHTML","pseudoTextHTML","pseudoText","StyledTypewriter","onClick","StyledTypewriterText","dangerouslySetInnerHTML","__html","$isAnimatingText","$shouldHideCursor","visibility","position","StyledTypewriterPseudoText","displayName","_default"],"sources":["../../../../src/components/typewriter/Typewriter.tsx"],"sourcesContent":["import { ColorSchemeProvider } from '@chayns-components/core';\nimport React, { FC, ReactElement, useCallback, useEffect, useMemo, useState } from 'react';\nimport { renderToString } from 'react-dom/server';\nimport {\n StyledTypewriter,\n StyledTypewriterPseudoText,\n StyledTypewriterText,\n} from './Typewriter.styles';\nimport { getCharactersCount, getSubTextFromHTML, shuffleArray } from './utils';\n\n// noinspection JSUnusedGlobalSymbols\nexport enum TypewriterResetDelay {\n Slow = 4000,\n Medium = 2000,\n Fast = 1000,\n}\n\n// noinspection JSUnusedGlobalSymbols\nexport enum TypewriterSpeed {\n Slow = 30,\n Medium = 20,\n Fast = 10,\n}\n\nexport type TypewriterProps = {\n /**\n * The text to type\n */\n children: ReactElement | ReactElement[] | string | string[];\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 * 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 before the typewriter resets the content if multiple texts are given\n */\n resetDelay?: TypewriterResetDelay;\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 * 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 style of the typewriter text element\n */\n textStyle?: React.CSSProperties;\n};\n\nconst Typewriter: FC<TypewriterProps> = ({\n children,\n onFinish,\n pseudoChildren,\n resetDelay = TypewriterResetDelay.Medium,\n shouldForceCursorAnimation = false,\n shouldHideCursor = false,\n shouldSortChildrenRandomly = false,\n shouldUseAnimationHeight = false,\n shouldUseResetAnimation = false,\n shouldWaitForContent,\n speed = TypewriterSpeed.Medium,\n textStyle,\n}) => {\n const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);\n const [shouldCount, setShouldCount] = useState(true);\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 <ColorSchemeProvider\n color=\"#005EB8\"\n colorMode={0}\n style={{ display: 'inline' }}\n >\n {currentChildren}\n </ColorSchemeProvider>,\n )\n : (currentChildren as string);\n }\n\n return '';\n }\n\n return React.isValidElement(sortedChildren)\n ? renderToString(\n <ColorSchemeProvider color=\"#005EB8\" colorMode={0} style={{ display: 'inline' }}>\n {sortedChildren}\n </ColorSchemeProvider>,\n )\n : (sortedChildren as string);\n }, [areMultipleChildrenGiven, currentChildrenIndex, sortedChildren]);\n\n const charactersCount = useMemo(() => getCharactersCount(textContent), [textContent]);\n\n const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);\n const [shownCharCount, setShownCharCount] = useState(\n charactersCount > 0 ? 0 : textContent.length,\n );\n const [shouldStopAnimation, setShouldStopAnimation] = useState(false);\n const [prevChildren, setPrevChildren] = useState<TypewriterProps['children']>(children);\n\n useEffect(() => {\n if (children !== prevChildren) {\n setShouldCount(true);\n setPrevChildren(children);\n }\n }, [children, prevChildren]);\n\n const isAnimatingText =\n shownCharCount < textContent.length ||\n shouldForceCursorAnimation ||\n areMultipleChildrenGiven ||\n textContent.length === 0;\n\n const handleClick = useCallback(() => {\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 } else if (isResetAnimationActive) {\n interval = window.setInterval(() => {\n setShownCharCount((prevState) => {\n const nextState = prevState - 1;\n\n if (nextState === 0) {\n window.clearInterval(interval);\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n setIsResetAnimationActive(false);\n handleSetNextChildrenIndex();\n }, resetDelay);\n }\n }\n\n return nextState;\n });\n }, speed);\n } else {\n interval = window.setInterval(() => {\n setShownCharCount((prevState) => {\n let nextState = prevState;\n\n if (shouldCount) {\n nextState = prevState + 1;\n }\n\n if (nextState >= charactersCount) {\n if (shouldWaitForContent) {\n setShouldCount(false);\n } else {\n window.clearInterval(interval);\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, resetDelay / 2);\n }\n }, resetDelay);\n }\n }\n }\n\n return nextState;\n });\n }, speed);\n }\n\n return () => {\n window.clearInterval(interval);\n };\n }, [\n shouldStopAnimation,\n speed,\n textContent.length,\n charactersCount,\n isResetAnimationActive,\n areMultipleChildrenGiven,\n resetDelay,\n childrenCount,\n handleSetNextChildrenIndex,\n shouldUseResetAnimation,\n shouldCount,\n shouldWaitForContent,\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 <ColorSchemeProvider color=\"#005EB8\" colorMode={0}>\n {pseudoChildren}\n </ColorSchemeProvider>,\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 }, [pseudoChildren, shouldUseAnimationHeight, shownCharCount, textContent]);\n\n return useMemo(\n () => (\n <StyledTypewriter onClick={handleClick}>\n {isAnimatingText && (\n <StyledTypewriterText\n dangerouslySetInnerHTML={{ __html: shownText }}\n $isAnimatingText\n $shouldHideCursor={shouldHideCursor}\n style={textStyle}\n />\n )}\n <StyledTypewriterText\n style={\n isAnimatingText ? { visibility: 'hidden', position: 'absolute' } : textStyle\n }\n >\n {sortedChildren}\n </StyledTypewriterText>\n {isAnimatingText && (\n <StyledTypewriterPseudoText\n dangerouslySetInnerHTML={{ __html: pseudoTextHTML }}\n />\n )}\n </StyledTypewriter>\n ),\n [\n handleClick,\n isAnimatingText,\n pseudoTextHTML,\n shouldHideCursor,\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,MAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AAKA,IAAAK,MAAA,GAAAL,OAAA;AAA+E,SAAAM,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAL,wBAAAK,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAG,CAAA,KAAAA,CAAA,CAAAV,GAAA,IAAAU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ireWildcard","_server","_Typewriter","_utils","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","TypewriterResetDelay","exports","TypewriterSpeed","Typewriter","children","onFinish","pseudoChildren","resetDelay","Medium","shouldForceCursorAnimation","shouldHideCursor","shouldSortChildrenRandomly","shouldUseAnimationHeight","shouldUseResetAnimation","shouldWaitForContent","speed","textStyle","currentChildrenIndex","setCurrentChildrenIndex","useState","shouldCount","setShouldCount","sortedChildren","useMemo","Array","isArray","shuffleArray","areMultipleChildrenGiven","childrenCount","length","textContent","currentChildren","React","isValidElement","renderToString","createElement","ColorSchemeProvider","color","colorMode","style","display","charactersCount","getCharactersCount","isResetAnimationActive","setIsResetAnimationActive","shownCharCount","setShownCharCount","shouldStopAnimation","setShouldStopAnimation","prevChildren","setPrevChildren","useEffect","isAnimatingText","handleClick","useCallback","handleSetNextChildrenIndex","newIndex","interval","window","setInterval","prevState","nextState","clearInterval","setTimeout","shownText","getSubTextFromHTML","pseudoTextHTML","pseudoText","StyledTypewriter","onClick","StyledTypewriterText","dangerouslySetInnerHTML","__html","$isAnimatingText","$shouldHideCursor","visibility","position","StyledTypewriterPseudoText","displayName","_default"],"sources":["../../../../src/components/typewriter/Typewriter.tsx"],"sourcesContent":["import { ColorSchemeProvider } from '@chayns-components/core';\nimport React, { FC, ReactElement, useCallback, useEffect, useMemo, useState } from 'react';\nimport { renderToString } from 'react-dom/server';\nimport {\n StyledTypewriter,\n StyledTypewriterPseudoText,\n StyledTypewriterText,\n} from './Typewriter.styles';\nimport { getCharactersCount, getSubTextFromHTML, shuffleArray } from './utils';\n\n// noinspection JSUnusedGlobalSymbols\nexport enum TypewriterResetDelay {\n Slow = 4000,\n Medium = 2000,\n Fast = 1000,\n}\n\n// noinspection JSUnusedGlobalSymbols\nexport enum TypewriterSpeed {\n Slow = 30,\n Medium = 20,\n Fast = 10,\n}\n\nexport type TypewriterProps = {\n /**\n * The text to type\n */\n children: ReactElement | ReactElement[] | string | string[];\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 * 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 before the typewriter resets the content if multiple texts are given\n */\n resetDelay?: TypewriterResetDelay;\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 * 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 style of the typewriter text element\n */\n textStyle?: React.CSSProperties;\n};\n\nconst Typewriter: FC<TypewriterProps> = ({\n children,\n onFinish,\n pseudoChildren,\n resetDelay = TypewriterResetDelay.Medium,\n shouldForceCursorAnimation = false,\n shouldHideCursor = false,\n shouldSortChildrenRandomly = false,\n shouldUseAnimationHeight = false,\n shouldUseResetAnimation = false,\n shouldWaitForContent,\n speed = TypewriterSpeed.Medium,\n textStyle,\n}) => {\n const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);\n const [shouldCount, setShouldCount] = useState(true);\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 <ColorSchemeProvider\n color=\"#005EB8\"\n colorMode={0}\n style={{ display: 'inline' }}\n >\n {currentChildren}\n </ColorSchemeProvider>,\n )\n : (currentChildren as string);\n }\n\n return '';\n }\n\n return React.isValidElement(sortedChildren)\n ? renderToString(\n <ColorSchemeProvider color=\"#005EB8\" colorMode={0} style={{ display: 'inline' }}>\n {sortedChildren}\n </ColorSchemeProvider>,\n )\n : (sortedChildren as string);\n }, [areMultipleChildrenGiven, currentChildrenIndex, sortedChildren]);\n\n const charactersCount = useMemo(() => getCharactersCount(textContent), [textContent]);\n\n const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);\n const [shownCharCount, setShownCharCount] = useState(\n charactersCount > 0 ? 0 : textContent.length,\n );\n const [shouldStopAnimation, setShouldStopAnimation] = useState(false);\n const [prevChildren, setPrevChildren] = useState<TypewriterProps['children']>(children);\n\n useEffect(() => {\n if (children !== prevChildren) {\n setShouldCount(true);\n setPrevChildren(children);\n }\n }, [children, prevChildren]);\n\n const isAnimatingText =\n shownCharCount < textContent.length ||\n shouldForceCursorAnimation ||\n areMultipleChildrenGiven ||\n textContent.length === 0;\n\n const handleClick = useCallback(() => {\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 } else if (isResetAnimationActive) {\n interval = window.setInterval(() => {\n setShownCharCount((prevState) => {\n const nextState = prevState - 1;\n\n if (nextState === 0) {\n window.clearInterval(interval);\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n setIsResetAnimationActive(false);\n handleSetNextChildrenIndex();\n }, resetDelay);\n }\n }\n\n return nextState;\n });\n }, speed);\n } else {\n interval = window.setInterval(() => {\n setShownCharCount((prevState) => {\n let nextState = prevState;\n\n if (shouldCount) {\n nextState = prevState + 1;\n }\n\n if (nextState >= charactersCount) {\n if (shouldWaitForContent) {\n setShouldCount(false);\n } else {\n window.clearInterval(interval);\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, resetDelay / 2);\n }\n }, resetDelay);\n }\n }\n }\n\n return nextState;\n });\n }, speed);\n }\n\n return () => {\n window.clearInterval(interval);\n };\n }, [\n shouldStopAnimation,\n speed,\n textContent.length,\n charactersCount,\n isResetAnimationActive,\n areMultipleChildrenGiven,\n resetDelay,\n childrenCount,\n handleSetNextChildrenIndex,\n shouldUseResetAnimation,\n shouldCount,\n shouldWaitForContent,\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 <ColorSchemeProvider\n color=\"#005EB8\"\n colorMode={0}\n style={{ display: 'inline' }}\n >\n {pseudoChildren}\n </ColorSchemeProvider>,\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 }, [pseudoChildren, shouldUseAnimationHeight, shownCharCount, textContent]);\n\n return useMemo(\n () => (\n <StyledTypewriter onClick={handleClick}>\n {isAnimatingText && (\n <StyledTypewriterText\n dangerouslySetInnerHTML={{ __html: shownText }}\n $isAnimatingText\n $shouldHideCursor={shouldHideCursor}\n style={textStyle}\n />\n )}\n <StyledTypewriterText\n style={\n isAnimatingText ? { visibility: 'hidden', position: 'absolute' } : textStyle\n }\n >\n {sortedChildren}\n </StyledTypewriterText>\n {isAnimatingText && (\n <StyledTypewriterPseudoText\n dangerouslySetInnerHTML={{ __html: pseudoTextHTML }}\n $isAnimatingText\n $shouldHideCursor={shouldHideCursor}\n />\n )}\n </StyledTypewriter>\n ),\n [\n handleClick,\n isAnimatingText,\n pseudoTextHTML,\n shouldHideCursor,\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,MAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AAKA,IAAAK,MAAA,GAAAL,OAAA;AAA+E,SAAAM,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAL,wBAAAK,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,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Q,EAAE;IAAW,CAAC,GAAG5D;EACtE,GAEAM,cACiB,CAAC,EACtB8B,eAAe,iBACZ7E,MAAA,CAAAW,OAAA,CAAAiD,aAAA,CAACzD,WAAA,CAAAmG,0BAA0B;IACvBN,uBAAuB,EAAE;MAAEC,MAAM,EAAEN;IAAe,CAAE;IACpDO,gBAAgB;IAChBC,iBAAiB,EAAEhE;EAAiB,CACvC,CAES,CACrB,EACD,CACI2C,WAAW,EACXD,eAAe,EACfc,cAAc,EACdxD,gBAAgB,EAChBsD,SAAS,EACT1C,cAAc,EACdN,SAAS,CAEjB,CAAC;AACL,CAAC;AAEDb,UAAU,CAAC2E,WAAW,GAAG,YAAY;AAAC,IAAAC,QAAA,GAAA9E,OAAA,CAAAf,OAAA,GAEvBiB,UAAU","ignoreList":[]}
@@ -18,10 +18,28 @@ const blinkAnimation = (0, _styledComponents.keyframes)`
18
18
  visibility: hidden;
19
19
  }
20
20
  `;
21
+ const typewriterCursorElement = ({
22
+ $isAnimatingText,
23
+ $shouldHideCursor
24
+ }) => $isAnimatingText && !$shouldHideCursor && (0, _styledComponents.css)`
25
+ &:after {
26
+ animation: ${blinkAnimation} 1s steps(5, start) infinite;
27
+ color: ${({
28
+ theme
29
+ }) => theme.text};
30
+ content: '▋';
31
+ margin-left: 0.25rem;
32
+ opacity: 0.85;
33
+ position: relative;
34
+ vertical-align: baseline;
35
+ }
36
+ `;
21
37
  const StyledTypewriterPseudoText = exports.StyledTypewriterPseudoText = _styledComponents.default.span`
22
38
  opacity: 0;
23
39
  pointer-events: none;
24
40
  user-select: none;
41
+
42
+ ${typewriterCursorElement}
25
43
  `;
26
44
  const StyledTypewriterText = exports.StyledTypewriterText = _styledComponents.default.span`
27
45
  color: inherit;
@@ -30,21 +48,6 @@ const StyledTypewriterText = exports.StyledTypewriterText = _styledComponents.de
30
48
  }) => $isAnimatingText ? 'absolute' : 'relative'};
31
49
  width: 100%;
32
50
 
33
- ${({
34
- $isAnimatingText,
35
- $shouldHideCursor
36
- }) => $isAnimatingText && !$shouldHideCursor && (0, _styledComponents.css)`
37
- &:after {
38
- animation: ${blinkAnimation} 1s steps(5, start) infinite;
39
- color: ${({
40
- theme
41
- }) => theme.text};
42
- content: '▋';
43
- margin-left: 0.25rem;
44
- opacity: 0.85;
45
- position: absolute;
46
- vertical-align: baseline;
47
- }
48
- `}
51
+ ${typewriterCursorElement}
49
52
  `;
50
53
  //# sourceMappingURL=Typewriter.styles.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Typewriter.styles.js","names":["_styledComponents","_interopRequireWildcard","require","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","StyledTypewriter","exports","styled","div","blinkAnimation","keyframes","StyledTypewriterPseudoText","span","StyledTypewriterText","$isAnimatingText","$shouldHideCursor","css","theme","text"],"sources":["../../../../src/components/typewriter/Typewriter.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport styled, { css, keyframes } from 'styled-components';\n\nexport const StyledTypewriter = styled.div`\n align-items: inherit;\n display: flex;\n position: relative;\n width: 100%;\n`;\n\nconst blinkAnimation = keyframes`\n 100% {\n visibility: hidden;\n }\n`;\n\nexport const StyledTypewriterPseudoText = styled.span`\n opacity: 0;\n pointer-events: none;\n user-select: none;\n`;\n\ntype StyledTypewriterTextProps = WithTheme<{\n $isAnimatingText?: boolean;\n $shouldHideCursor?: boolean;\n}>;\n\nexport const StyledTypewriterText = styled.span<StyledTypewriterTextProps>`\n color: inherit;\n position: ${({ $isAnimatingText }) => ($isAnimatingText ? 'absolute' : 'relative')};\n width: 100%;\n\n ${({ $isAnimatingText, $shouldHideCursor }) =>\n $isAnimatingText &&\n !$shouldHideCursor &&\n css`\n &:after {\n animation: ${blinkAnimation} 1s steps(5, start) infinite;\n color: ${({ theme }: StyledTypewriterTextProps) => theme.text};\n content: '▋';\n margin-left: 0.25rem;\n opacity: 0.85;\n position: absolute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M,CAACC,GAAI;AAC3C;AACA;AACA;AACA;AACA,CAAC;AAED,MAAMC,cAAc,GAAG,IAAAC,2BAAS,CAAC;AACjC;AACA;AACA;AACA,CAAC;AAEM,MAAMC,0BAA0B,GAAAL,OAAA,CAAAK,0BAAA,GAAGJ,yBAAM,CAACK,IAAK;AACtD;AACA;AACA;AACA,CAAC;AAOM,MAAMC,oBAAoB,GAAAP,OAAA,CAAAO,oBAAA,GAAGN,yBAAM,CAACK,IAAgC;AAC3E;AACA,gBAAgB,CAAC;EAAEE;AAAiB,CAAC,KAAMA,gBAAgB,GAAG,UAAU,GAAG,UAAY;AACvF;AACA;AACA,MAAM,CAAC;EAAEA,gBAAgB;EAAEC;AAAkB,CAAC,KACtCD,gBAAgB,IAChB,CAACC,iBAAiB,IAClB,IAAAC,qBAAG,CAAC;AACZ;AACA,6BAA6BP,cAAe;AAC5C,yBAAyB,CAAC;EAAEQ;AAAiC,CAAC,KAAKA,KAAK,CAACC,IAAK;AAC9E;AACA;AACA;AACA;AACA;AACA;AACA,SAAU;AACV,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"Typewriter.styles.js","names":["_styledComponents","_interopRequireWildcard","require","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","StyledTypewriter","exports","styled","div","blinkAnimation","keyframes","typewriterCursorElement","$isAnimatingText","$shouldHideCursor","css","theme","text","StyledTypewriterPseudoText","span","StyledTypewriterText"],"sources":["../../../../src/components/typewriter/Typewriter.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport styled, { css, keyframes } from 'styled-components';\n\nexport const StyledTypewriter = styled.div`\n align-items: inherit;\n display: flex;\n position: relative;\n width: 100%;\n`;\n\nconst blinkAnimation = keyframes`\n 100% {\n visibility: hidden;\n }\n`;\n\nconst typewriterCursorElement = ({\n $isAnimatingText,\n $shouldHideCursor,\n}: {\n $isAnimatingText?: boolean;\n $shouldHideCursor?: boolean;\n}) =>\n $isAnimatingText &&\n !$shouldHideCursor &&\n css`\n &:after {\n animation: ${blinkAnimation} 1s steps(5, start) infinite;\n color: ${({ theme }: StyledTypewriterTextProps) => theme.text};\n content: '▋';\n margin-left: 0.25rem;\n opacity: 0.85;\n position: relative;\n vertical-align: baseline;\n }\n `;\n\nexport const StyledTypewriterPseudoText = styled.span<StyledTypewriterTextProps>`\n opacity: 0;\n pointer-events: none;\n user-select: none;\n\n ${typewriterCursorElement}\n`;\n\ntype StyledTypewriterTextProps = WithTheme<{\n $isAnimatingText?: boolean;\n $shouldHideCursor?: boolean;\n}>;\n\nexport const StyledTypewriterText = styled.span<StyledTypewriterTextProps>`\n color: inherit;\n position: ${({ $isAnimatingText }) => ($isAnimatingText ? 'absolute' : 'relative')};\n width: 100%;\n\n ${typewriterCursorElement}\n`;\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,uBAAA,CAAAC,OAAA;AAA2D,SAAAC,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAH,wBAAAG,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CA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C","ignoreList":[]}
@@ -152,7 +152,10 @@ const Typewriter = _ref => {
152
152
  if (pseudoChildren) {
153
153
  const pseudoText = /*#__PURE__*/React.isValidElement(pseudoChildren) ? renderToString( /*#__PURE__*/React.createElement(ColorSchemeProvider, {
154
154
  color: "#005EB8",
155
- colorMode: 0
155
+ colorMode: 0,
156
+ style: {
157
+ display: 'inline'
158
+ }
156
159
  }, pseudoChildren)) : pseudoChildren;
157
160
  if (shouldUseAnimationHeight) {
158
161
  return getSubTextFromHTML(pseudoText, shownCharCount);
@@ -181,7 +184,9 @@ const Typewriter = _ref => {
181
184
  }, sortedChildren), isAnimatingText && /*#__PURE__*/React.createElement(StyledTypewriterPseudoText, {
182
185
  dangerouslySetInnerHTML: {
183
186
  __html: pseudoTextHTML
184
- }
187
+ },
188
+ $isAnimatingText: true,
189
+ $shouldHideCursor: shouldHideCursor
185
190
  })), [handleClick, isAnimatingText, pseudoTextHTML, shouldHideCursor, shownText, sortedChildren, textStyle]);
186
191
  };
187
192
  Typewriter.displayName = 'Typewriter';
@@ -1 +1 @@
1
- {"version":3,"file":"Typewriter.js","names":["ColorSchemeProvider","React","useCallback","useEffect","useMemo","useState","renderToString","StyledTypewriter","StyledTypewriterPseudoText","StyledTypewriterText","getCharactersCount","getSubTextFromHTML","shuffleArray","TypewriterResetDelay","TypewriterSpeed","Typewriter","_ref","children","onFinish","pseudoChildren","resetDelay","Medium","shouldForceCursorAnimation","shouldHideCursor","shouldSortChildrenRandomly","shouldUseAnimationHeight","shouldUseResetAnimation","shouldWaitForContent","speed","textStyle","currentChildrenIndex","setCurrentChildrenIndex","shouldCount","setShouldCount","sortedChildren","Array","isArray","areMultipleChildrenGiven","childrenCount","length","textContent","currentChildren","isValidElement","createElement","color","colorMode","style","display","charactersCount","isResetAnimationActive","setIsResetAnimationActive","shownCharCount","setShownCharCount","shouldStopAnimation","setShouldStopAnimation","prevChildren","setPrevChildren","isAnimatingText","handleClick","handleSetNextChildrenIndex","newIndex","interval","window","setInterval","prevState","nextState","clearInterval","setTimeout","shownText","pseudoTextHTML","pseudoText","onClick","dangerouslySetInnerHTML","__html","$isAnimatingText","$shouldHideCursor","visibility","position","displayName"],"sources":["../../../../src/components/typewriter/Typewriter.tsx"],"sourcesContent":["import { ColorSchemeProvider } from '@chayns-components/core';\nimport React, { FC, ReactElement, useCallback, useEffect, useMemo, useState } from 'react';\nimport { renderToString } from 'react-dom/server';\nimport {\n StyledTypewriter,\n StyledTypewriterPseudoText,\n StyledTypewriterText,\n} from './Typewriter.styles';\nimport { getCharactersCount, getSubTextFromHTML, shuffleArray } from './utils';\n\n// noinspection JSUnusedGlobalSymbols\nexport enum TypewriterResetDelay {\n Slow = 4000,\n Medium = 2000,\n Fast = 1000,\n}\n\n// noinspection JSUnusedGlobalSymbols\nexport enum TypewriterSpeed {\n Slow = 30,\n Medium = 20,\n Fast = 10,\n}\n\nexport type TypewriterProps = {\n /**\n * The text to type\n */\n children: ReactElement | ReactElement[] | string | string[];\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 * 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 before the typewriter resets the content if multiple texts are given\n */\n resetDelay?: TypewriterResetDelay;\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 * 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 style of the typewriter text element\n */\n textStyle?: React.CSSProperties;\n};\n\nconst Typewriter: FC<TypewriterProps> = ({\n children,\n onFinish,\n pseudoChildren,\n resetDelay = TypewriterResetDelay.Medium,\n shouldForceCursorAnimation = false,\n shouldHideCursor = false,\n shouldSortChildrenRandomly = false,\n shouldUseAnimationHeight = false,\n shouldUseResetAnimation = false,\n shouldWaitForContent,\n speed = TypewriterSpeed.Medium,\n textStyle,\n}) => {\n const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);\n const [shouldCount, setShouldCount] = useState(true);\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 <ColorSchemeProvider\n color=\"#005EB8\"\n colorMode={0}\n style={{ display: 'inline' }}\n >\n {currentChildren}\n </ColorSchemeProvider>,\n )\n : (currentChildren as string);\n }\n\n return '';\n }\n\n return React.isValidElement(sortedChildren)\n ? renderToString(\n <ColorSchemeProvider color=\"#005EB8\" colorMode={0} style={{ display: 'inline' }}>\n {sortedChildren}\n </ColorSchemeProvider>,\n )\n : (sortedChildren as string);\n }, [areMultipleChildrenGiven, currentChildrenIndex, sortedChildren]);\n\n const charactersCount = useMemo(() => getCharactersCount(textContent), [textContent]);\n\n const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);\n const [shownCharCount, setShownCharCount] = useState(\n charactersCount > 0 ? 0 : textContent.length,\n );\n const [shouldStopAnimation, setShouldStopAnimation] = useState(false);\n const [prevChildren, setPrevChildren] = useState<TypewriterProps['children']>(children);\n\n useEffect(() => {\n if (children !== prevChildren) {\n setShouldCount(true);\n setPrevChildren(children);\n }\n }, [children, prevChildren]);\n\n const isAnimatingText =\n shownCharCount < textContent.length ||\n shouldForceCursorAnimation ||\n areMultipleChildrenGiven ||\n textContent.length === 0;\n\n const handleClick = useCallback(() => {\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 } else if (isResetAnimationActive) {\n interval = window.setInterval(() => {\n setShownCharCount((prevState) => {\n const nextState = prevState - 1;\n\n if (nextState === 0) {\n window.clearInterval(interval);\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n setIsResetAnimationActive(false);\n handleSetNextChildrenIndex();\n }, resetDelay);\n }\n }\n\n return nextState;\n });\n }, speed);\n } else {\n interval = window.setInterval(() => {\n setShownCharCount((prevState) => {\n let nextState = prevState;\n\n if (shouldCount) {\n nextState = prevState + 1;\n }\n\n if (nextState >= charactersCount) {\n if (shouldWaitForContent) {\n setShouldCount(false);\n } else {\n window.clearInterval(interval);\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, resetDelay / 2);\n }\n }, resetDelay);\n }\n }\n }\n\n return nextState;\n });\n }, speed);\n }\n\n return () => {\n window.clearInterval(interval);\n };\n }, [\n shouldStopAnimation,\n speed,\n textContent.length,\n charactersCount,\n isResetAnimationActive,\n areMultipleChildrenGiven,\n resetDelay,\n childrenCount,\n handleSetNextChildrenIndex,\n shouldUseResetAnimation,\n shouldCount,\n shouldWaitForContent,\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 <ColorSchemeProvider color=\"#005EB8\" colorMode={0}>\n {pseudoChildren}\n </ColorSchemeProvider>,\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 }, [pseudoChildren, shouldUseAnimationHeight, shownCharCount, textContent]);\n\n return useMemo(\n () => (\n <StyledTypewriter onClick={handleClick}>\n {isAnimatingText && (\n <StyledTypewriterText\n dangerouslySetInnerHTML={{ __html: shownText }}\n $isAnimatingText\n $shouldHideCursor={shouldHideCursor}\n style={textStyle}\n />\n )}\n <StyledTypewriterText\n style={\n isAnimatingText ? { visibility: 'hidden', position: 'absolute' } : textStyle\n }\n >\n {sortedChildren}\n </StyledTypewriterText>\n {isAnimatingText && (\n <StyledTypewriterPseudoText\n dangerouslySetInnerHTML={{ __html: pseudoTextHTML }}\n />\n )}\n </StyledTypewriter>\n ),\n [\n handleClick,\n isAnimatingText,\n pseudoTextHTML,\n shouldHideCursor,\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,OAAOC,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,aAAA,CAACpC,gBAAgB;IAACgE,OAAO,EAAEb;EAAY,GAClCD,eAAe,iBACZxD,KAAA,CAAA0C,aAAA,CAAClC,oBAAoB;IACjB+D,uBAAuB,EAAE;MAAEC,MAAM,EAAEL;IAAU,CAAE;IAC/CM,gBAAgB;IAChBC,iBAAiB,EAAEpD,gBAAiB;IACpCuB,KAAK,EAAEjB;EAAU,CACpB,CACJ,eACD5B,KAAA,CAAA0C,aAAA,CAAClC,oBAAoB;IACjBqC,KAAK,EACDW,eAAe,GAAG;MAAEmB,UAAU,EAAE,QAAQ;MAAEC,QAAQ,EAAE;IAAW,CAAC,GAAGhD;EACtE,GAEAK,cACiB,CAAC,EACtBuB,eAAe,iBACZxD,KAAA,CAAA0C,aAAA,CAACnC,0BAA0B;IACvBgE,uBAAuB,EAAE;MAAEC,MAAM,EAAEJ;IAAe;EAAE,CACvD,CAES,CACrB,EACD,CACIX,WAAW,EACXD,eAAe,EACfY,cAAc,EACd9C,gBAAgB,EAChB6C,SAAS,EACTlC,cAAc,EACdL,SAAS,CAEjB,CAAC;AACL,CAAC;AAEDd,UAAU,CAAC+D,WAAW,GAAG,YAAY;AAErC,eAAe/D,UAAU","ignoreList":[]}
1
+ {"version":3,"file":"Typewriter.js","names":["ColorSchemeProvider","React","useCallback","useEffect","useMemo","useState","renderToString","StyledTypewriter","StyledTypewriterPseudoText","StyledTypewriterText","getCharactersCount","getSubTextFromHTML","shuffleArray","TypewriterResetDelay","TypewriterSpeed","Typewriter","_ref","children","onFinish","pseudoChildren","resetDelay","Medium","shouldForceCursorAnimation","shouldHideCursor","shouldSortChildrenRandomly","shouldUseAnimationHeight","shouldUseResetAnimation","shouldWaitForContent","speed","textStyle","currentChildrenIndex","setCurrentChildrenIndex","shouldCount","setShouldCount","sortedChildren","Array","isArray","areMultipleChildrenGiven","childrenCount","length","textContent","currentChildren","isValidElement","createElement","color","colorMode","style","display","charactersCount","isResetAnimationActive","setIsResetAnimationActive","shownCharCount","setShownCharCount","shouldStopAnimation","setShouldStopAnimation","prevChildren","setPrevChildren","isAnimatingText","handleClick","handleSetNextChildrenIndex","newIndex","interval","window","setInterval","prevState","nextState","clearInterval","setTimeout","shownText","pseudoTextHTML","pseudoText","onClick","dangerouslySetInnerHTML","__html","$isAnimatingText","$shouldHideCursor","visibility","position","displayName"],"sources":["../../../../src/components/typewriter/Typewriter.tsx"],"sourcesContent":["import { ColorSchemeProvider } from '@chayns-components/core';\nimport React, { FC, ReactElement, useCallback, useEffect, useMemo, useState } from 'react';\nimport { renderToString } from 'react-dom/server';\nimport {\n StyledTypewriter,\n StyledTypewriterPseudoText,\n StyledTypewriterText,\n} from './Typewriter.styles';\nimport { getCharactersCount, getSubTextFromHTML, shuffleArray } from './utils';\n\n// noinspection JSUnusedGlobalSymbols\nexport enum TypewriterResetDelay {\n Slow = 4000,\n Medium = 2000,\n Fast = 1000,\n}\n\n// noinspection JSUnusedGlobalSymbols\nexport enum TypewriterSpeed {\n Slow = 30,\n Medium = 20,\n Fast = 10,\n}\n\nexport type TypewriterProps = {\n /**\n * The text to type\n */\n children: ReactElement | ReactElement[] | string | string[];\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 * 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 before the typewriter resets the content if multiple texts are given\n */\n resetDelay?: TypewriterResetDelay;\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 * 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 style of the typewriter text element\n */\n textStyle?: React.CSSProperties;\n};\n\nconst Typewriter: FC<TypewriterProps> = ({\n children,\n onFinish,\n pseudoChildren,\n resetDelay = TypewriterResetDelay.Medium,\n shouldForceCursorAnimation = false,\n shouldHideCursor = false,\n shouldSortChildrenRandomly = false,\n shouldUseAnimationHeight = false,\n shouldUseResetAnimation = false,\n shouldWaitForContent,\n speed = TypewriterSpeed.Medium,\n textStyle,\n}) => {\n const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);\n const [shouldCount, setShouldCount] = useState(true);\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 <ColorSchemeProvider\n color=\"#005EB8\"\n colorMode={0}\n style={{ display: 'inline' }}\n >\n {currentChildren}\n </ColorSchemeProvider>,\n )\n : (currentChildren as string);\n }\n\n return '';\n }\n\n return React.isValidElement(sortedChildren)\n ? renderToString(\n <ColorSchemeProvider color=\"#005EB8\" colorMode={0} style={{ display: 'inline' }}>\n {sortedChildren}\n </ColorSchemeProvider>,\n )\n : (sortedChildren as string);\n }, [areMultipleChildrenGiven, currentChildrenIndex, sortedChildren]);\n\n const charactersCount = useMemo(() => getCharactersCount(textContent), [textContent]);\n\n const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);\n const [shownCharCount, setShownCharCount] = useState(\n charactersCount > 0 ? 0 : textContent.length,\n );\n const [shouldStopAnimation, setShouldStopAnimation] = useState(false);\n const [prevChildren, setPrevChildren] = useState<TypewriterProps['children']>(children);\n\n useEffect(() => {\n if (children !== prevChildren) {\n setShouldCount(true);\n setPrevChildren(children);\n }\n }, [children, prevChildren]);\n\n const isAnimatingText =\n shownCharCount < textContent.length ||\n shouldForceCursorAnimation ||\n areMultipleChildrenGiven ||\n textContent.length === 0;\n\n const handleClick = useCallback(() => {\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 } else if (isResetAnimationActive) {\n interval = window.setInterval(() => {\n setShownCharCount((prevState) => {\n const nextState = prevState - 1;\n\n if (nextState === 0) {\n window.clearInterval(interval);\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n setIsResetAnimationActive(false);\n handleSetNextChildrenIndex();\n }, resetDelay);\n }\n }\n\n return nextState;\n });\n }, speed);\n } else {\n interval = window.setInterval(() => {\n setShownCharCount((prevState) => {\n let nextState = prevState;\n\n if (shouldCount) {\n nextState = prevState + 1;\n }\n\n if (nextState >= charactersCount) {\n if (shouldWaitForContent) {\n setShouldCount(false);\n } else {\n window.clearInterval(interval);\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, resetDelay / 2);\n }\n }, resetDelay);\n }\n }\n }\n\n return nextState;\n });\n }, speed);\n }\n\n return () => {\n window.clearInterval(interval);\n };\n }, [\n shouldStopAnimation,\n speed,\n textContent.length,\n charactersCount,\n isResetAnimationActive,\n areMultipleChildrenGiven,\n resetDelay,\n childrenCount,\n handleSetNextChildrenIndex,\n shouldUseResetAnimation,\n shouldCount,\n shouldWaitForContent,\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 <ColorSchemeProvider\n color=\"#005EB8\"\n colorMode={0}\n style={{ display: 'inline' }}\n >\n {pseudoChildren}\n </ColorSchemeProvider>,\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 }, [pseudoChildren, shouldUseAnimationHeight, shownCharCount, textContent]);\n\n return useMemo(\n () => (\n <StyledTypewriter onClick={handleClick}>\n {isAnimatingText && (\n <StyledTypewriterText\n dangerouslySetInnerHTML={{ __html: shownText }}\n $isAnimatingText\n $shouldHideCursor={shouldHideCursor}\n style={textStyle}\n />\n )}\n <StyledTypewriterText\n style={\n isAnimatingText ? { visibility: 'hidden', position: 'absolute' } : textStyle\n }\n >\n {sortedChildren}\n </StyledTypewriterText>\n {isAnimatingText && (\n <StyledTypewriterPseudoText\n dangerouslySetInnerHTML={{ __html: pseudoTextHTML }}\n $isAnimatingText\n $shouldHideCursor={shouldHideCursor}\n />\n )}\n </StyledTypewriter>\n ),\n [\n handleClick,\n isAnimatingText,\n pseudoTextHTML,\n should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B,WAAW,EAAEW,cAAc,CAAC;IAC1D;IAEA,OAAOX,WAAW,IAAI,SAAS;EACnC,CAAC,EAAE,CAACrB,cAAc,EAAEM,wBAAwB,EAAE0B,cAAc,EAAEX,WAAW,CAAC,CAAC;EAE3E,OAAOpC,OAAO,CACV,mBACIH,KAAA,CAAA0C,aAAA,CAACpC,gBAAgB;IAACgE,OAAO,EAAEb;EAAY,GAClCD,eAAe,iBACZxD,KAAA,CAAA0C,aAAA,CAAClC,oBAAoB;IACjB+D,uBAAuB,EAAE;MAAEC,MAAM,EAAEL;IAAU,CAAE;IAC/CM,gBAAgB;IAChBC,iBAAiB,EAAEpD,gBAAiB;IACpCuB,KAAK,EAAEjB;EAAU,CACpB,CACJ,eACD5B,KAAA,CAAA0C,aAAA,CAAClC,oBAAoB;IACjBqC,KAAK,EACDW,eAAe,GAAG;MAAEmB,UAAU,EAAE,QAAQ;MAAEC,QAAQ,EAAE;IAAW,CAAC,GAAGhD;EACtE,GAEAK,cACiB,CAAC,EACtBuB,eAAe,iBACZxD,KAAA,CAAA0C,aAAA,CAACnC,0BAA0B;IACvBgE,uBAAuB,EAAE;MAAEC,MAAM,EAAEJ;IAAe,CAAE;IACpDK,gBAAgB;IAChBC,iBAAiB,EAAEpD;EAAiB,CACvC,CAES,CACrB,EACD,CACImC,WAAW,EACXD,eAAe,EACfY,cAAc,EACd9C,gBAAgB,EAChB6C,SAAS,EACTlC,cAAc,EACdL,SAAS,CAEjB,CAAC;AACL,CAAC;AAEDd,UAAU,CAAC+D,WAAW,GAAG,YAAY;AAErC,eAAe/D,UAAU","ignoreList":[]}
@@ -10,42 +10,45 @@ const blinkAnimation = keyframes`
10
10
  visibility: hidden;
11
11
  }
12
12
  `;
13
+ const typewriterCursorElement = _ref => {
14
+ let {
15
+ $isAnimatingText,
16
+ $shouldHideCursor
17
+ } = _ref;
18
+ return $isAnimatingText && !$shouldHideCursor && css`
19
+ &:after {
20
+ animation: ${blinkAnimation} 1s steps(5, start) infinite;
21
+ color: ${_ref2 => {
22
+ let {
23
+ theme
24
+ } = _ref2;
25
+ return theme.text;
26
+ }};
27
+ content: '▋';
28
+ margin-left: 0.25rem;
29
+ opacity: 0.85;
30
+ position: relative;
31
+ vertical-align: baseline;
32
+ }
33
+ `;
34
+ };
13
35
  export const StyledTypewriterPseudoText = styled.span`
14
36
  opacity: 0;
15
37
  pointer-events: none;
16
38
  user-select: none;
39
+
40
+ ${typewriterCursorElement}
17
41
  `;
18
42
  export const StyledTypewriterText = styled.span`
19
43
  color: inherit;
20
- position: ${_ref => {
44
+ position: ${_ref3 => {
21
45
  let {
22
46
  $isAnimatingText
23
- } = _ref;
47
+ } = _ref3;
24
48
  return $isAnimatingText ? 'absolute' : 'relative';
25
49
  }};
26
50
  width: 100%;
27
51
 
28
- ${_ref2 => {
29
- let {
30
- $isAnimatingText,
31
- $shouldHideCursor
32
- } = _ref2;
33
- return $isAnimatingText && !$shouldHideCursor && css`
34
- &:after {
35
- animation: ${blinkAnimation} 1s steps(5, start) infinite;
36
- color: ${_ref3 => {
37
- let {
38
- theme
39
- } = _ref3;
40
- return theme.text;
41
- }};
42
- content: '▋';
43
- margin-left: 0.25rem;
44
- opacity: 0.85;
45
- position: absolute;
46
- vertical-align: baseline;
47
- }
48
- `;
49
- }}
52
+ ${typewriterCursorElement}
50
53
  `;
51
54
  //# sourceMappingURL=Typewriter.styles.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Typewriter.styles.js","names":["styled","css","keyframes","StyledTypewriter","div","blinkAnimation","StyledTypewriterPseudoText","span","StyledTypewriterText","_ref","$isAnimatingText","_ref2","$shouldHideCursor","_ref3","theme","text"],"sources":["../../../../src/components/typewriter/Typewriter.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport styled, { css, keyframes } from 'styled-components';\n\nexport const StyledTypewriter = styled.div`\n align-items: inherit;\n display: flex;\n position: relative;\n width: 100%;\n`;\n\nconst blinkAnimation = keyframes`\n 100% {\n visibility: hidden;\n }\n`;\n\nexport const StyledTypewriterPseudoText = styled.span`\n opacity: 0;\n pointer-events: none;\n user-select: none;\n`;\n\ntype StyledTypewriterTextProps = WithTheme<{\n $isAnimatingText?: boolean;\n $shouldHideCursor?: boolean;\n}>;\n\nexport const StyledTypewriterText = styled.span<StyledTypewriterTextProps>`\n color: inherit;\n position: ${({ $isAnimatingText }) => ($isAnimatingText ? 'absolute' : 'relative')};\n width: 100%;\n\n ${({ $isAnimatingText, $shouldHideCursor }) =>\n $isAnimatingText &&\n !$shouldHideCursor &&\n css`\n &:after {\n animation: ${blinkAnimation} 1s steps(5, start) infinite;\n color: ${({ theme }: StyledTypewriterTextProps) => theme.text};\n content: '▋';\n margin-left: 0.25rem;\n opacity: 0.85;\n position: absolute;\n vertical-align: baseline;\n }\n `}\n`;\n"],"mappings":"AACA,OAAOA,MAAM,IAAIC,GAAG,EAAEC,SAAS,QAAQ,mBAAmB;AAE1D,OAAO,MAAMC,gBAAgB,GAAGH,MAAM,CAACI,GAAI;AAC3C;AACA;AACA;AACA;AACA,CAAC;AAED,MAAMC,cAAc,GAAGH,SAAU;AACjC;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAMI,0BAA0B,GAAGN,MAAM,CAACO,IAAK;AACtD;AACA;AACA;AACA,CAAC;AAOD,OAAO,MAAMC,oBAAoB,GAAGR,MAAM,CAACO,IAAgC;AAC3E;AACA,gBAAgBE,IAAA;EAAA,IAAC;IAAEC;EAAiB,CAAC,GAAAD,IAAA;EAAA,OAAMC,gBAAgB,GAAG,UAAU,GAAG,UAAU;AAAA,CAAE;AACvF;AACA;AACA,MAAMC,KAAA;EAAA,IAAC;IAAED,gBAAgB;IAAEE;EAAkB,CAAC,GAAAD,KAAA;EAAA,OACtCD,gBAAgB,IAChB,CAACE,iBAAiB,IAClBX,GAAI;AACZ;AACA,6BAA6BI,cAAe;AAC5C,yBAAyBQ,KAAA;IAAA,IAAC;MAAEC;IAAiC,CAAC,GAAAD,KAAA;IAAA,OAAKC,KAAK,CAACC,IAAI;EAAA,CAAC;AAC9E;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AAAA,CAAC;AACV,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"Typewriter.styles.js","names":["styled","css","keyframes","StyledTypewriter","div","blinkAnimation","typewriterCursorElement","_ref","$isAnimatingText","$shouldHideCursor","_ref2","theme","text","StyledTypewriterPseudoText","span","StyledTypewriterText","_ref3"],"sources":["../../../../src/components/typewriter/Typewriter.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport styled, { css, keyframes } from 'styled-components';\n\nexport const StyledTypewriter = styled.div`\n align-items: inherit;\n display: flex;\n position: relative;\n width: 100%;\n`;\n\nconst blinkAnimation = keyframes`\n 100% {\n visibility: hidden;\n }\n`;\n\nconst typewriterCursorElement = ({\n $isAnimatingText,\n $shouldHideCursor,\n}: {\n $isAnimatingText?: boolean;\n $shouldHideCursor?: boolean;\n}) =>\n $isAnimatingText &&\n !$shouldHideCursor &&\n css`\n &:after {\n animation: ${blinkAnimation} 1s steps(5, start) infinite;\n color: ${({ theme }: StyledTypewriterTextProps) => theme.text};\n content: '▋';\n margin-left: 0.25rem;\n opacity: 0.85;\n position: relative;\n vertical-align: baseline;\n }\n `;\n\nexport const StyledTypewriterPseudoText = styled.span<StyledTypewriterTextProps>`\n opacity: 0;\n pointer-events: none;\n user-select: none;\n\n ${typewriterCursorElement}\n`;\n\ntype StyledTypewriterTextProps = WithTheme<{\n $isAnimatingText?: boolean;\n $shouldHideCursor?: boolean;\n}>;\n\nexport const StyledTypewriterText = styled.span<StyledTypewriterTextProps>`\n color: inherit;\n position: ${({ $isAnimatingText }) => ($isAnimatingText ? 'absolute' : 'relative')};\n width: 100%;\n\n ${typewriterCursorElement}\n`;\n"],"mappings":"AACA,OAAOA,MAAM,IAAIC,GAAG,EAAEC,SAAS,QAAQ,mBAAmB;AAE1D,OAAO,MAAMC,gBAAgB,GAAGH,MAAM,CAACI,GAAI;AAC3C;AACA;AACA;AACA;AACA,CAAC;AAED,MAAMC,cAAc,GAAGH,SAAU;AACjC;AACA;AACA;AACA,CAAC;AAED,MAAMI,uBAAuB,GAAGC,IAAA;EAAA,IAAC;IAC7BC,gBAAgB;IAChBC;EAIJ,CAAC,GAAAF,IAAA;EAAA,OACGC,gBAAgB,IAChB,CAACC,iBAAiB,IAClBR,GAAI;AACR;AACA,yBAAyBI,cAAe;AACxC,qBAAqBK,KAAA;IAAA,IAAC;MAAEC;IAAiC,CAAC,GAAAD,KAAA;IAAA,OAAKC,KAAK,CAACC,IAAI;EAAA,CAAC;AAC1E;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AAAA;AAEL,OAAO,MAAMC,0BAA0B,GAAGb,MAAM,CAACc,IAAgC;AACjF;AACA;AACA;AACA;AACA,MAAMR,uBAAwB;AAC9B,CAAC;AAOD,OAAO,MAAMS,oBAAoB,GAAGf,MAAM,CAACc,IAAgC;AAC3E;AACA,gBAAgBE,KAAA;EAAA,IAAC;IAAER;EAAiB,CAAC,GAAAQ,KAAA;EAAA,OAAMR,gBAAgB,GAAG,UAAU,GAAG,UAAU;AAAA,CAAE;AACvF;AACA;AACA,MAAMF,uBAAwB;AAC9B,CAAC","ignoreList":[]}
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import type { WithTheme } from '@chayns-components/core';
3
3
  export declare const StyledTypewriter: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
4
- export declare const StyledTypewriterPseudoText: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, never>> & string;
4
+ export declare const StyledTypewriterPseudoText: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, StyledTypewriterTextProps>> & string;
5
5
  type StyledTypewriterTextProps = WithTheme<{
6
6
  $isAnimatingText?: boolean;
7
7
  $shouldHideCursor?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chayns-components/typewriter",
3
- "version": "5.0.0-beta.596",
3
+ "version": "5.0.0-beta.597",
4
4
  "description": "A set of beautiful React components for developing your own applications with chayns.",
5
5
  "sideEffects": false,
6
6
  "browserslist": [
@@ -79,5 +79,5 @@
79
79
  "publishConfig": {
80
80
  "access": "public"
81
81
  },
82
- "gitHead": "3afaf2c3a3314311c14b8501ed2540451f248116"
82
+ "gitHead": "6fcdc4626b7c48acd7bafc98592e97addc6d6ae2"
83
83
  }