@chayns-components/typewriter 5.0.0-beta.90 → 5.0.0-beta.901

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.
Files changed (37) hide show
  1. package/README.md +4 -15
  2. package/lib/cjs/components/typewriter/AnimatedTypewriterText.js +59 -0
  3. package/lib/cjs/components/typewriter/AnimatedTypewriterText.js.map +1 -0
  4. package/lib/cjs/components/typewriter/Typewriter.js +229 -0
  5. package/lib/cjs/components/typewriter/Typewriter.js.map +1 -0
  6. package/lib/cjs/components/typewriter/Typewriter.styles.js +59 -0
  7. package/lib/cjs/components/typewriter/Typewriter.styles.js.map +1 -0
  8. package/lib/{components → cjs/components}/typewriter/utils.js +20 -3
  9. package/lib/cjs/components/typewriter/utils.js.map +1 -0
  10. package/lib/cjs/index.js +27 -0
  11. package/lib/cjs/index.js.map +1 -0
  12. package/lib/esm/components/typewriter/AnimatedTypewriterText.js +51 -0
  13. package/lib/esm/components/typewriter/AnimatedTypewriterText.js.map +1 -0
  14. package/lib/esm/components/typewriter/Typewriter.js +223 -0
  15. package/lib/esm/components/typewriter/Typewriter.js.map +1 -0
  16. package/lib/esm/components/typewriter/Typewriter.styles.js +63 -0
  17. package/lib/esm/components/typewriter/Typewriter.styles.js.map +1 -0
  18. package/lib/esm/components/typewriter/utils.js +85 -0
  19. package/lib/esm/components/typewriter/utils.js.map +1 -0
  20. package/lib/esm/index.js +2 -0
  21. package/lib/esm/index.js.map +1 -0
  22. package/lib/types/components/typewriter/AnimatedTypewriterText.d.ts +8 -0
  23. package/lib/types/components/typewriter/Typewriter.d.ts +84 -0
  24. package/lib/types/components/typewriter/Typewriter.styles.d.ts +12 -0
  25. package/lib/{components → types/components}/typewriter/utils.d.ts +1 -0
  26. package/lib/types/index.d.ts +1 -0
  27. package/package.json +46 -28
  28. package/lib/components/typewriter/Typewriter.d.ts +0 -15
  29. package/lib/components/typewriter/Typewriter.js +0 -77
  30. package/lib/components/typewriter/Typewriter.js.map +0 -1
  31. package/lib/components/typewriter/Typewriter.styles.d.ts +0 -7
  32. package/lib/components/typewriter/Typewriter.styles.js +0 -62
  33. package/lib/components/typewriter/Typewriter.styles.js.map +0 -1
  34. package/lib/components/typewriter/utils.js.map +0 -1
  35. package/lib/index.d.ts +0 -1
  36. package/lib/index.js +0 -21
  37. package/lib/index.js.map +0 -1
@@ -0,0 +1,223 @@
1
+ import { ColorSchemeProvider } from '@chayns-components/core';
2
+ import { ChaynsProvider, useFunctions, useValues } from 'chayns-api';
3
+ import React, { useCallback, useEffect, useLayoutEffect, useMemo, useState } from 'react';
4
+ import { createPortal } from 'react-dom';
5
+ import { renderToString } from 'react-dom/server';
6
+ import { StyledTypewriter, StyledTypewriterPseudoText, StyledTypewriterText } from './Typewriter.styles';
7
+ import { getCharactersCount, getSubTextFromHTML, shuffleArray } from './utils';
8
+ import AnimatedTypewriterText from "./AnimatedTypewriterText";
9
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
10
+
11
+ // noinspection JSUnusedGlobalSymbols
12
+ export let TypewriterDelay = /*#__PURE__*/function (TypewriterDelay) {
13
+ TypewriterDelay[TypewriterDelay["ExtraSlow"] = 4000] = "ExtraSlow";
14
+ TypewriterDelay[TypewriterDelay["Slow"] = 2000] = "Slow";
15
+ TypewriterDelay[TypewriterDelay["Medium"] = 1000] = "Medium";
16
+ TypewriterDelay[TypewriterDelay["Fast"] = 500] = "Fast";
17
+ TypewriterDelay[TypewriterDelay["ExtraFast"] = 250] = "ExtraFast";
18
+ TypewriterDelay[TypewriterDelay["None"] = 0] = "None";
19
+ return TypewriterDelay;
20
+ }({});
21
+
22
+ // noinspection JSUnusedGlobalSymbols
23
+ export let TypewriterSpeed = /*#__PURE__*/function (TypewriterSpeed) {
24
+ TypewriterSpeed[TypewriterSpeed["ExtraSlow"] = 40] = "ExtraSlow";
25
+ TypewriterSpeed[TypewriterSpeed["Slow"] = 20] = "Slow";
26
+ TypewriterSpeed[TypewriterSpeed["Medium"] = 10] = "Medium";
27
+ TypewriterSpeed[TypewriterSpeed["Fast"] = 5] = "Fast";
28
+ TypewriterSpeed[TypewriterSpeed["ExtraFast"] = 2.5] = "ExtraFast";
29
+ return TypewriterSpeed;
30
+ }({});
31
+ const Typewriter = _ref => {
32
+ let {
33
+ children,
34
+ nextTextDelay = TypewriterDelay.Medium,
35
+ onFinish,
36
+ pseudoChildren,
37
+ resetDelay = TypewriterDelay.Medium,
38
+ shouldForceCursorAnimation = false,
39
+ shouldHideCursor = false,
40
+ shouldSortChildrenRandomly = false,
41
+ shouldUseAnimationHeight = false,
42
+ shouldUseResetAnimation = false,
43
+ shouldWaitForContent,
44
+ speed = TypewriterSpeed.Medium,
45
+ startDelay = TypewriterDelay.None,
46
+ textStyle
47
+ } = _ref;
48
+ const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);
49
+ const [hasRenderedChildrenOnce, setHasRenderedChildrenOnce] = useState(false);
50
+ const functions = useFunctions();
51
+ const values = useValues();
52
+ useIsomorphicLayoutEffect(() => {
53
+ if (children) {
54
+ setHasRenderedChildrenOnce(false);
55
+ }
56
+ }, [children]);
57
+ useEffect(() => {
58
+ if (!hasRenderedChildrenOnce) {
59
+ setHasRenderedChildrenOnce(true);
60
+ }
61
+ }, [hasRenderedChildrenOnce]);
62
+ const sortedChildren = useMemo(() => Array.isArray(children) && shouldSortChildrenRandomly ? shuffleArray(children) : children, [children, shouldSortChildrenRandomly]);
63
+ const areMultipleChildrenGiven = Array.isArray(sortedChildren);
64
+ const childrenCount = areMultipleChildrenGiven ? sortedChildren.length : 1;
65
+ const textContent = useMemo(() => {
66
+ if (areMultipleChildrenGiven) {
67
+ const currentChildren = sortedChildren[currentChildrenIndex];
68
+ if (currentChildren) {
69
+ return /*#__PURE__*/React.isValidElement(currentChildren) ? renderToString(/*#__PURE__*/React.createElement(ChaynsProvider, {
70
+ data: values,
71
+ functions: functions,
72
+ isModule: true
73
+ }, /*#__PURE__*/React.createElement(ColorSchemeProvider, {
74
+ color: "#005EB8",
75
+ colorMode: 0,
76
+ style: {
77
+ display: 'inline'
78
+ }
79
+ }, currentChildren))) : currentChildren;
80
+ }
81
+ return '';
82
+ }
83
+ return /*#__PURE__*/React.isValidElement(sortedChildren) ? renderToString(/*#__PURE__*/React.createElement(ChaynsProvider, {
84
+ data: values,
85
+ functions: functions,
86
+ isModule: true
87
+ }, /*#__PURE__*/React.createElement(ColorSchemeProvider, {
88
+ color: "#005EB8",
89
+ colorMode: 0,
90
+ style: {
91
+ display: 'inline'
92
+ }
93
+ }, sortedChildren))) : sortedChildren;
94
+ }, [areMultipleChildrenGiven, currentChildrenIndex, functions, sortedChildren, values]);
95
+ const charactersCount = useMemo(() => getCharactersCount(textContent), [textContent]);
96
+ const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);
97
+ const [shownCharCount, setShownCharCount] = useState(charactersCount > 0 ? 0 : textContent.length);
98
+ const [shouldStopAnimation, setShouldStopAnimation] = useState(false);
99
+ const isAnimatingText = shownCharCount < textContent.length || shouldForceCursorAnimation || areMultipleChildrenGiven || textContent.length === 0;
100
+ const handleClick = useCallback(event => {
101
+ event.stopPropagation();
102
+ event.preventDefault();
103
+ setShouldStopAnimation(true);
104
+ }, []);
105
+ const handleSetNextChildrenIndex = useCallback(() => setCurrentChildrenIndex(() => {
106
+ let newIndex = currentChildrenIndex + 1;
107
+ if (newIndex > childrenCount - 1) {
108
+ newIndex = 0;
109
+ }
110
+ return newIndex;
111
+ }), [childrenCount, currentChildrenIndex]);
112
+ useEffect(() => {
113
+ let interval;
114
+ if (shouldStopAnimation || charactersCount === 0) {
115
+ setShownCharCount(textContent.length);
116
+ } else if (isResetAnimationActive) {
117
+ interval = window.setInterval(() => {
118
+ setShownCharCount(prevState => {
119
+ const nextState = prevState - 1;
120
+ if (nextState === 0) {
121
+ window.clearInterval(interval);
122
+ if (areMultipleChildrenGiven) {
123
+ setTimeout(() => {
124
+ setIsResetAnimationActive(false);
125
+ handleSetNextChildrenIndex();
126
+ }, nextTextDelay);
127
+ }
128
+ }
129
+ return nextState;
130
+ });
131
+ }, speed);
132
+ } else {
133
+ const setInterval = () => {
134
+ interval = window.setInterval(() => {
135
+ setShownCharCount(prevState => {
136
+ let nextState = Math.min(prevState + 1, charactersCount);
137
+ if (nextState >= charactersCount && !shouldWaitForContent) {
138
+ window.clearInterval(interval);
139
+
140
+ /**
141
+ * At this point, the next value for "shownCharCount" is deliberately set to
142
+ * the length of the textContent in order to correctly display HTML elements
143
+ * after the last letter.
144
+ */
145
+ nextState = textContent.length;
146
+ if (areMultipleChildrenGiven) {
147
+ setTimeout(() => {
148
+ if (shouldUseResetAnimation) {
149
+ setIsResetAnimationActive(true);
150
+ } else {
151
+ setShownCharCount(0);
152
+ setTimeout(handleSetNextChildrenIndex, nextTextDelay);
153
+ }
154
+ }, resetDelay);
155
+ }
156
+ }
157
+ return nextState;
158
+ });
159
+ }, speed);
160
+ };
161
+ if (startDelay) {
162
+ setTimeout(setInterval, startDelay);
163
+ } else {
164
+ setInterval();
165
+ }
166
+ }
167
+ return () => {
168
+ window.clearInterval(interval);
169
+ };
170
+ }, [speed, resetDelay, childrenCount, charactersCount, textContent.length, shouldStopAnimation, shouldWaitForContent, isResetAnimationActive, shouldUseResetAnimation, areMultipleChildrenGiven, handleSetNextChildrenIndex, nextTextDelay, startDelay]);
171
+ useEffect(() => {
172
+ if (!isAnimatingText && typeof onFinish === 'function') {
173
+ onFinish();
174
+ }
175
+ }, [isAnimatingText, onFinish]);
176
+ const shownText = useMemo(() => getSubTextFromHTML(textContent, shownCharCount), [shownCharCount, textContent]);
177
+ const pseudoTextHTML = useMemo(() => {
178
+ if (pseudoChildren) {
179
+ const pseudoText = /*#__PURE__*/React.isValidElement(pseudoChildren) ? renderToString(/*#__PURE__*/React.createElement(ChaynsProvider, {
180
+ data: values,
181
+ functions: functions,
182
+ isModule: true
183
+ }, /*#__PURE__*/React.createElement(ColorSchemeProvider, {
184
+ color: "#005EB8",
185
+ colorMode: 0,
186
+ style: {
187
+ display: 'inline'
188
+ }
189
+ }, pseudoChildren))) : pseudoChildren;
190
+ if (shouldUseAnimationHeight) {
191
+ return getSubTextFromHTML(pseudoText, shownCharCount);
192
+ }
193
+ return pseudoText;
194
+ }
195
+ if (shouldUseAnimationHeight && textContent) {
196
+ return getSubTextFromHTML(textContent, shownCharCount);
197
+ }
198
+ return textContent || '&#8203;';
199
+ }, [functions, pseudoChildren, shouldUseAnimationHeight, shownCharCount, textContent, values]);
200
+ return useMemo(() => /*#__PURE__*/React.createElement(StyledTypewriter, {
201
+ onClick: isAnimatingText ? handleClick : undefined,
202
+ $isAnimatingText: isAnimatingText,
203
+ $shouldHideCursor: shouldHideCursor
204
+ }, isAnimatingText ? /*#__PURE__*/React.createElement(AnimatedTypewriterText, {
205
+ shouldHideCursor: shouldHideCursor,
206
+ shownText: shownText,
207
+ textStyle: textStyle
208
+ }) : /*#__PURE__*/React.createElement(StyledTypewriterText, {
209
+ style: textStyle
210
+ }, sortedChildren), isAnimatingText && /*#__PURE__*/React.createElement(StyledTypewriterPseudoText, {
211
+ dangerouslySetInnerHTML: {
212
+ __html: pseudoTextHTML
213
+ }
214
+ }), !hasRenderedChildrenOnce && /*#__PURE__*/createPortal(/*#__PURE__*/React.createElement("div", {
215
+ style: {
216
+ position: 'absolute',
217
+ visibility: 'hidden'
218
+ }
219
+ }, children), document.body)), [children, handleClick, hasRenderedChildrenOnce, isAnimatingText, pseudoTextHTML, shouldHideCursor, shownText, sortedChildren, textStyle]);
220
+ };
221
+ Typewriter.displayName = 'Typewriter';
222
+ export default Typewriter;
223
+ //# sourceMappingURL=Typewriter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Typewriter.js","names":["ColorSchemeProvider","ChaynsProvider","useFunctions","useValues","React","useCallback","useEffect","useLayoutEffect","useMemo","useState","createPortal","renderToString","StyledTypewriter","StyledTypewriterPseudoText","StyledTypewriterText","getCharactersCount","getSubTextFromHTML","shuffleArray","AnimatedTypewriterText","useIsomorphicLayoutEffect","window","TypewriterDelay","TypewriterSpeed","Typewriter","_ref","children","nextTextDelay","Medium","onFinish","pseudoChildren","resetDelay","shouldForceCursorAnimation","shouldHideCursor","shouldSortChildrenRandomly","shouldUseAnimationHeight","shouldUseResetAnimation","shouldWaitForContent","speed","startDelay","None","textStyle","currentChildrenIndex","setCurrentChildrenIndex","hasRenderedChildrenOnce","setHasRenderedChildrenOnce","functions","values","sortedChildren","Array","isArray","areMultipleChildrenGiven","childrenCount","length","textContent","currentChildren","isValidElement","createElement","data","isModule","color","colorMode","style","display","charactersCount","isResetAnimationActive","setIsResetAnimationActive","shownCharCount","setShownCharCount","shouldStopAnimation","setShouldStopAnimation","isAnimatingText","handleClick","event","stopPropagation","preventDefault","handleSetNextChildrenIndex","newIndex","interval","setInterval","prevState","nextState","clearInterval","setTimeout","Math","min","shownText","pseudoTextHTML","pseudoText","onClick","undefined","$isAnimatingText","$shouldHideCursor","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 {\n StyledTypewriter,\n StyledTypewriterPseudoText,\n StyledTypewriterText,\n} from './Typewriter.styles';\nimport { getCharactersCount, getSubTextFromHTML, shuffleArray } from './utils';\nimport AnimatedTypewriterText from \"./AnimatedTypewriterText\";\n\nconst useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\n// noinspection JSUnusedGlobalSymbols\nexport enum TypewriterDelay {\n ExtraSlow = 4000,\n Slow = 2000,\n Medium = 1000,\n Fast = 500,\n ExtraFast = 250,\n None = 0,\n}\n\n// noinspection JSUnusedGlobalSymbols\nexport enum TypewriterSpeed {\n ExtraSlow = 40,\n Slow = 20,\n Medium = 10,\n Fast = 5,\n ExtraFast = 2.5,\n}\n\nexport type TypewriterProps = {\n /**\n * The text to type\n */\n children: ReactElement | ReactElement[] | string | string[];\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 * 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 * 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 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 nextTextDelay = TypewriterDelay.Medium,\n onFinish,\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 startDelay = TypewriterDelay.None,\n textStyle,\n}) => {\n const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);\n const [hasRenderedChildrenOnce, setHasRenderedChildrenOnce] = useState(false);\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 [isResetAnimationActive, setIsResetAnimationActive] = useState(false);\n const [shownCharCount, setShownCharCount] = useState(\n charactersCount > 0 ? 0 : textContent.length,\n );\n const [shouldStopAnimation, setShouldStopAnimation] = useState(false);\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 } 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 }, nextTextDelay);\n }\n }\n\n return nextState;\n });\n }, speed);\n } else {\n const setInterval = () => {\n interval = window.setInterval(() => {\n setShownCharCount((prevState) => {\n let nextState = Math.min(prevState + 1, charactersCount);\n\n if (nextState >= charactersCount && !shouldWaitForContent) {\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, nextTextDelay);\n }\n }, resetDelay);\n }\n }\n\n return nextState;\n });\n }, speed);\n };\n\n if (startDelay) {\n setTimeout(setInterval, startDelay);\n } else {\n setInterval();\n }\n }\n\n return () => {\n window.clearInterval(interval);\n };\n }, [\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 ]);\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 onClick={isAnimatingText ? handleClick : undefined}\n $isAnimatingText={isAnimatingText}\n $shouldHideCursor={shouldHideCursor}\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 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 handleClick,\n hasRenderedChildrenOnce,\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,SAASC,cAAc,EAAEC,YAAY,EAAEC,SAAS,QAAQ,YAAY;AACpE,OAAOC,KAAK,IAGRC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,OAAO,EAEPC,QAAQ,QACL,OAAO;AACd,SAASC,YAAY,QAAQ,WAAW;AACxC,SAASC,cAAc,QAAQ,kBAAkB;AACjD,SACIC,gBAAgB,EAChBC,0BAA0B,EAC1BC,oBAAoB,QACjB,qBAAqB;AAC5B,SAASC,kBAAkB,EAAEC,kBAAkB,EAAEC,YAAY,QAAQ,SAAS;AAC9E,OAAOC,sBAAsB,MAAM,0BAA0B;AAE7D,MAAMC,yBAAyB,GAAG,OAAOC,MAAM,KAAK,WAAW,GAAGb,eAAe,GAAGD,SAAS;;AAE7F;AACA,WAAYe,eAAe,0BAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAA,OAAfA,eAAe;AAAA;;AAS3B;AACA,WAAYC,eAAe,0BAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAA,OAAfA,eAAe;AAAA;AA2E3B,MAAMC,UAA+B,GAAGC,IAAA,IAelC;EAAA,IAfmC;IACrCC,QAAQ;IACRC,aAAa,GAAGL,eAAe,C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1D;IAEA,OAAOb,WAAW,IAAI,SAAS;EACnC,CAAC,EAAE,CAACR,SAAS,EAAEhB,cAAc,EAAEK,wBAAwB,EAAEgC,cAAc,EAAEb,WAAW,EAAEP,MAAM,CAAC,CAAC;EAE9F,OAAOtC,OAAO,CACV,mBACIJ,KAAA,CAAAoD,aAAA,CAAC5C,gBAAgB;IACb4E,OAAO,EAAElB,eAAe,GAAGC,WAAW,GAAGkB,SAAU;IACnDC,gBAAgB,EAAEpB,eAAgB;IAClCqB,iBAAiB,EAAE3D;EAAiB,GAEnCsC,eAAe,gBACZlE,KAAA,CAAAoD,aAAA,CAACtC,sBAAsB;IACnBc,gBAAgB,EAAEA,gBAAiB;IACnCqD,SAAS,EAAEA,SAAU;IACrB7C,SAAS,EAAEA;EAAU,CACxB,CAAC,gBAEFpC,KAAA,CAAAoD,aAAA,CAAC1C,oBAAoB;IAAC+C,KAAK,EAAErB;EAAU,GAAEO,cAAqC,CACjF,EACAuB,eAAe,iBACZlE,KAAA,CAAAoD,aAAA,CAAC3C,0BAA0B;IACvB+E,uBAAuB,EAAE;MAAEC,MAAM,EAAEP;IAAe;EAAE,CACvD,CACJ,EAKA,CAAC3C,uBAAuB,iBACrBjC,YAAY,cACRN,KAAA,CAAAoD,aAAA;IAAKK,KAAK,EAAE;MAAEiC,QAAQ,EAAE,UAAU;MAAEC,UAAU,EAAE;IAAS;EAAE,GACtDtE,QACA,CAAC,EACNuE,QAAQ,CAACC,IACb,CACU,CACrB,EACD,CACIxE,QAAQ,EACR8C,WAAW,EACX5B,uBAAuB,EACvB2B,eAAe,EACfgB,cAAc,EACdtD,gBAAgB,EAChBqD,SAAS,EACTtC,cAAc,EACdP,SAAS,CAEjB,CAAC;AACL,CAAC;AAEDjB,UAAU,CAAC2E,WAAW,GAAG,YAAY;AAErC,eAAe3E,UAAU","ignoreList":[]}
@@ -0,0 +1,63 @@
1
+ import styled, { css, keyframes } from 'styled-components';
2
+ const typewriterCursorElement = _ref => {
3
+ let {
4
+ $isAnimatingText,
5
+ $shouldHideCursor
6
+ } = _ref;
7
+ return $isAnimatingText && !$shouldHideCursor && css`
8
+ .typewriter-lastWithContent {
9
+ &:after {
10
+ animation: ${blinkAnimation} 1s steps(2, start) infinite;
11
+ color: ${_ref2 => {
12
+ let {
13
+ theme
14
+ } = _ref2;
15
+ return theme.text;
16
+ }};
17
+ content: '▋';
18
+ margin-left: 0.25rem;
19
+ opacity: 0.85;
20
+ position: relative;
21
+ vertical-align: baseline;
22
+ }
23
+ }
24
+ `;
25
+ };
26
+ export const StyledTypewriter = styled.div`
27
+ align-items: inherit;
28
+ display: flex;
29
+ position: relative;
30
+ width: 100%;
31
+ ${typewriterCursorElement}
32
+ `;
33
+ const blinkAnimation = keyframes`
34
+ 100% {
35
+ visibility: hidden;
36
+ }
37
+ `;
38
+ export const StyledTypewriterPseudoText = styled.span`
39
+ opacity: 0;
40
+ pointer-events: none;
41
+ user-select: none;
42
+ width: 100%;
43
+ `;
44
+ export const StyledTypewriterText = styled.span`
45
+ color: inherit;
46
+ position: ${_ref3 => {
47
+ let {
48
+ $isAnimatingText
49
+ } = _ref3;
50
+ return $isAnimatingText ? 'absolute' : 'relative';
51
+ }};
52
+ width: 100%;
53
+
54
+ ${_ref4 => {
55
+ let {
56
+ $isAnimatingText
57
+ } = _ref4;
58
+ return $isAnimatingText && css`
59
+ pointer-events: none;
60
+ `;
61
+ }}
62
+ `;
63
+ //# sourceMappingURL=Typewriter.styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Typewriter.styles.js","names":["styled","css","keyframes","typewriterCursorElement","_ref","$isAnimatingText","$shouldHideCursor","blinkAnimation","_ref2","theme","text","StyledTypewriter","div","StyledTypewriterPseudoText","span","StyledTypewriterText","_ref3","_ref4"],"sources":["../../../../src/components/typewriter/Typewriter.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport styled, { css, keyframes } from 'styled-components';\n\nconst typewriterCursorElement = ({\n $isAnimatingText,\n $shouldHideCursor,\n}: {\n $isAnimatingText?: boolean;\n $shouldHideCursor?: boolean;\n}) =>\n $isAnimatingText &&\n !$shouldHideCursor &&\n css`\n .typewriter-lastWithContent {\n &:after {\n animation: ${blinkAnimation} 1s steps(2, 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 `;\n\ntype StyledTypewriterProps = WithTheme<{\n $isAnimatingText?: boolean;\n $shouldHideCursor?: boolean;\n}>;\n\nexport const StyledTypewriter = styled.div<StyledTypewriterProps>`\n align-items: inherit;\n display: flex;\n position: relative;\n width: 100%;\n ${typewriterCursorElement}\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 width: 100%;\n`;\n\ntype StyledTypewriterTextProps = WithTheme<{\n $isAnimatingText?: boolean;\n}>;\n\nexport const StyledTypewriterText = styled.span<StyledTypewriterTextProps>`\n color: inherit;\n position: ${({ $isAnimatingText }) => ($isAnimatingText ? 'absolute' : 'relative')};\n width: 100%;\n\n ${({ $isAnimatingText }) =>\n $isAnimatingText &&\n css`\n pointer-events: none;\n `}\n`;\n"],"mappings":"AACA,OAAOA,MAAM,IAAIC,GAAG,EAAEC,SAAS,QAAQ,mBAAmB;AAE1D,MAAMC,uBAAuB,GAAGC,IAAA;EAAA,IAAC;IAC7BC,gBAAgB;IAChBC;EAIJ,CAAC,GAAAF,IAAA;EAAA,OACGC,gBAAgB,IAChB,CAACC,iBAAiB,IAClBL,GAAG;AACP;AACA;AACA,uBAAuBM,cAAc;AACrC,mBAAmBC,KAAA;IAAA,IAAC;MAAEC;IAAiC,CAAC,GAAAD,KAAA;IAAA,OAAKC,KAAK,CAACC,IAAI;EAAA;AACvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AAAA;AAOL,OAAO,MAAMC,gBAAgB,GAAGX,MAAM,CAACY,GAA0B;AACjE;AACA;AACA;AACA;AACA,MAAMT,uBAAuB;AAC7B,CAAC;AAED,MAAMI,cAAc,GAAGL,SAAS;AAChC;AACA;AACA;AACA,CAAC;AAED,OAAO,MAAMW,0BAA0B,GAAGb,MAAM,CAACc,IAAI;AACrD;AACA;AACA;AACA;AACA,CAAC;AAMD,OAAO,MAAMC,oBAAoB,GAAGf,MAAM,CAACc,IAA+B;AAC1E;AACA,gBAAgBE,KAAA;EAAA,IAAC;IAAEX;EAAiB,CAAC,GAAAW,KAAA;EAAA,OAAMX,gBAAgB,GAAG,UAAU,GAAG,UAAU;AAAA,CAAC;AACtF;AACA;AACA,MAAMY,KAAA;EAAA,IAAC;IAAEZ;EAAiB,CAAC,GAAAY,KAAA;EAAA,OACnBZ,gBAAgB,IAChBJ,GAAG;AACX;AACA,SAAS;AAAA;AACT,CAAC","ignoreList":[]}
@@ -0,0 +1,85 @@
1
+ /**
2
+ * This function extracts a part of the text from an HTML text. The HTML elements themselves are
3
+ * returned in the result. In addition, the function ensures that the closing tag of the Bold HTML
4
+ * element is also returned for text that is cut off in the middle of a Bold element, for example.
5
+ *
6
+ * @param html - The text from which a part should be taken
7
+ * @param length - The length of the text to be extracted
8
+ *
9
+ * @return string - The text part with the specified length - additionally the HTML elements are added
10
+ */
11
+ export const getSubTextFromHTML = (html, length) => {
12
+ const div = document.createElement('div');
13
+ div.innerHTML = html;
14
+ let text = '';
15
+ let currLength = 0;
16
+ const traverse = element => {
17
+ if (element.nodeName === 'TWIGNORE') {
18
+ text += element.innerHTML;
19
+ } else if (element.nodeType === 3 && typeof element.textContent === 'string') {
20
+ const nodeText = element.textContent;
21
+ if (currLength + nodeText.length <= length) {
22
+ text += nodeText;
23
+ currLength += nodeText.length;
24
+ } else {
25
+ text += nodeText.substring(0, length - currLength);
26
+ return false;
27
+ }
28
+ } else if (element.nodeType === 1) {
29
+ const nodeName = element.nodeName.toLowerCase();
30
+ let attributes = '';
31
+
32
+ // @ts-expect-error: Type is correct here
33
+ // eslint-disable-next-line no-restricted-syntax
34
+ for (const attribute of element.attributes) {
35
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/restrict-template-expressions
36
+ attributes += ` ${attribute.name}="${attribute.value}"`;
37
+ }
38
+ text += `<${nodeName}${attributes}>`;
39
+ for (let i = 0; i < element.childNodes.length; i++) {
40
+ const childNode = element.childNodes[i];
41
+ if (childNode && !traverse(childNode)) {
42
+ return false;
43
+ }
44
+ }
45
+ text += `</${nodeName}>`;
46
+ }
47
+ return true;
48
+ };
49
+ for (let i = 0; i < div.childNodes.length; i++) {
50
+ const childNode = div.childNodes[i];
51
+ if (childNode && !traverse(childNode)) {
52
+ return text;
53
+ }
54
+ }
55
+ return text;
56
+ };
57
+ export const getCharactersCount = html => {
58
+ const div = document.createElement('div');
59
+ div.innerHTML = html;
60
+ let count = 0;
61
+ const traverse = node => {
62
+ if (node.nodeName === 'TWIGNORE') {
63
+ count += 1;
64
+ } else if (node.nodeType === 3 && typeof node.textContent === 'string') {
65
+ count += node.textContent.trim().length;
66
+ } else if (node.nodeType === 1) {
67
+ if (node.nodeName === 'CODE' && node.textContent !== null) {
68
+ count += node.textContent.length;
69
+ return;
70
+ }
71
+ Array.from(node.childNodes).forEach(traverse);
72
+ }
73
+ };
74
+ Array.from(div.childNodes).forEach(traverse);
75
+ return count;
76
+ };
77
+ export const shuffleArray = array => {
78
+ const result = Array.from(array);
79
+ for (let i = result.length - 1; i > 0; i--) {
80
+ const j = Math.floor(Math.random() * (i + 1));
81
+ [result[i], result[j]] = [result[j], result[i]];
82
+ }
83
+ return result;
84
+ };
85
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +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"],"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"],"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,OAAO,CAACE,QAAQ,KAAK,CAAC,IAAI,OAAOF,OAAO,CAACG,WAAW,KAAK,QAAQ,EAAE;MAC1E,MAAMC,QAAQ,GAAGJ,OAAO,CAACG,WAAW;MAEpC,IAAIL,UAAU,GAAGM,QAAQ,CAACZ,MAAM,IAAIA,MAAM,EAAE;QACxCK,IAAI,IAAIO,QAAQ;QAChBN,UAAU,IAAIM,QAAQ,CAACZ,MAAM;MACjC,CAAC,MAAM;QACHK,IAAI,IAAIO,QAAQ,CAACC,SAAS,CAAC,CAAC,EAAEb,MAAM,GAAGM,UAAU,CAAC;QAElD,OAAO,KAAK;MAChB;IACJ,CAAC,MAAM,IAAIE,OAAO,CAACE,QAAQ,KAAK,CAA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@@ -0,0 +1,2 @@
1
+ export { default as Typewriter, TypewriterDelay, TypewriterSpeed } from './components/typewriter/Typewriter';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["default","Typewriter","TypewriterDelay","TypewriterSpeed"],"sources":["../../src/index.ts"],"sourcesContent":["export {\n default as Typewriter,\n TypewriterDelay,\n TypewriterSpeed,\n} from './components/typewriter/Typewriter';\n"],"mappings":"AAAA,SACIA,OAAO,IAAIC,UAAU,EACrBC,eAAe,EACfC,eAAe,QACZ,oCAAoC","ignoreList":[]}
@@ -0,0 +1,8 @@
1
+ import React, { FC } from 'react';
2
+ type AnimatedTypewriterTextProps = {
3
+ shouldHideCursor: boolean;
4
+ shownText: string;
5
+ textStyle?: React.CSSProperties;
6
+ };
7
+ declare const AnimatedTypewriterText: FC<AnimatedTypewriterTextProps>;
8
+ export default AnimatedTypewriterText;
@@ -0,0 +1,84 @@
1
+ import React, { FC, ReactElement } from 'react';
2
+ export declare enum TypewriterDelay {
3
+ ExtraSlow = 4000,
4
+ Slow = 2000,
5
+ Medium = 1000,
6
+ Fast = 500,
7
+ ExtraFast = 250,
8
+ None = 0
9
+ }
10
+ export declare enum TypewriterSpeed {
11
+ ExtraSlow = 40,
12
+ Slow = 20,
13
+ Medium = 10,
14
+ Fast = 5,
15
+ ExtraFast = 2.5
16
+ }
17
+ export type TypewriterProps = {
18
+ /**
19
+ * The text to type
20
+ */
21
+ children: ReactElement | ReactElement[] | string | string[];
22
+ /**
23
+ * The delay in milliseconds before the next text is shown.
24
+ * This prop is only used if multiple texts are given.
25
+ */
26
+ nextTextDelay?: TypewriterDelay;
27
+ /**
28
+ * Function that is executed when the typewriter animation has finished. This function will not
29
+ * be executed if multiple texts are used.
30
+ */
31
+ onFinish?: VoidFunction;
32
+ /**
33
+ * Pseudo-element to be rendered invisible during animation to define the size of the element
34
+ * for the typewriter effect. By default, the "children" is used for this purpose.
35
+ */
36
+ pseudoChildren?: ReactElement | string;
37
+ /**
38
+ * Waiting time in milliseconds before the typewriter resets the text.
39
+ * This prop is only used if multiple texts are given.
40
+ */
41
+ resetDelay?: TypewriterDelay;
42
+ /**
43
+ * Specifies whether the cursor should be forced to animate even if no text is currently animated.
44
+ */
45
+ shouldForceCursorAnimation?: boolean;
46
+ /**
47
+ * Specifies whether the cursor should be hidden
48
+ */
49
+ shouldHideCursor?: boolean;
50
+ /**
51
+ * Specifies whether the children should be sorted randomly if there are multiple texts.
52
+ * This makes the typewriter start with a different text each time and also changes them
53
+ * in a random order.
54
+ */
55
+ shouldSortChildrenRandomly?: boolean;
56
+ /**
57
+ * Specifies whether the animation should use its full height or the height of the current
58
+ * chunk.
59
+ */
60
+ shouldUseAnimationHeight?: boolean;
61
+ /**
62
+ * Specifies whether the reset of the text should be animated with a backspace animation for
63
+ * multiple texts.
64
+ */
65
+ shouldUseResetAnimation?: boolean;
66
+ /**
67
+ * Whether the typewriter should wait for new content
68
+ */
69
+ shouldWaitForContent?: boolean;
70
+ /**
71
+ * The speed of the animation. Use the TypewriterSpeed enum for this prop.
72
+ */
73
+ speed?: TypewriterSpeed | number;
74
+ /**
75
+ * The delay in milliseconds before the typewriter starts typing.
76
+ */
77
+ startDelay?: TypewriterDelay;
78
+ /**
79
+ * The style of the typewriter text element
80
+ */
81
+ textStyle?: React.CSSProperties;
82
+ };
83
+ declare const Typewriter: FC<TypewriterProps>;
84
+ export default Typewriter;
@@ -0,0 +1,12 @@
1
+ import type { WithTheme } from '@chayns-components/core';
2
+ type StyledTypewriterProps = WithTheme<{
3
+ $isAnimatingText?: boolean;
4
+ $shouldHideCursor?: boolean;
5
+ }>;
6
+ export declare const StyledTypewriter: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, StyledTypewriterProps>> & string;
7
+ 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;
8
+ type StyledTypewriterTextProps = WithTheme<{
9
+ $isAnimatingText?: boolean;
10
+ }>;
11
+ export declare const StyledTypewriterText: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, StyledTypewriterTextProps>> & string;
12
+ export {};
@@ -10,3 +10,4 @@
10
10
  */
11
11
  export declare const getSubTextFromHTML: (html: string, length: number) => string;
12
12
  export declare const getCharactersCount: (html: string) => number;
13
+ export declare const shuffleArray: <T>(array: T[]) => T[];
@@ -0,0 +1 @@
1
+ export { default as Typewriter, TypewriterDelay, TypewriterSpeed, } from './components/typewriter/Typewriter';