@chayns-components/typewriter 5.0.0-beta.66 → 5.0.0-beta.661

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 (31) hide show
  1. package/README.md +4 -15
  2. package/lib/cjs/components/typewriter/Typewriter.js +212 -0
  3. package/lib/cjs/components/typewriter/Typewriter.js.map +1 -0
  4. package/lib/cjs/components/typewriter/Typewriter.styles.js +53 -0
  5. package/lib/cjs/components/typewriter/Typewriter.styles.js.map +1 -0
  6. package/lib/{components → cjs/components}/typewriter/utils.js +14 -1
  7. package/lib/cjs/components/typewriter/utils.js.map +1 -0
  8. package/lib/cjs/index.js +21 -0
  9. package/lib/cjs/index.js.map +1 -0
  10. package/lib/esm/components/typewriter/Typewriter.js +208 -0
  11. package/lib/esm/components/typewriter/Typewriter.js.map +1 -0
  12. package/lib/esm/components/typewriter/Typewriter.styles.js +54 -0
  13. package/lib/esm/components/typewriter/Typewriter.styles.js.map +1 -0
  14. package/lib/esm/components/typewriter/utils.js +81 -0
  15. package/lib/esm/components/typewriter/utils.js.map +1 -0
  16. package/lib/esm/index.js +2 -0
  17. package/lib/esm/index.js.map +1 -0
  18. package/lib/types/components/typewriter/Typewriter.d.ts +69 -0
  19. package/lib/types/components/typewriter/Typewriter.styles.d.ts +10 -0
  20. package/lib/{components → types/components}/typewriter/utils.d.ts +1 -0
  21. package/package.json +43 -27
  22. package/lib/components/typewriter/Typewriter.d.ts +0 -15
  23. package/lib/components/typewriter/Typewriter.js +0 -77
  24. package/lib/components/typewriter/Typewriter.js.map +0 -1
  25. package/lib/components/typewriter/Typewriter.styles.d.ts +0 -7
  26. package/lib/components/typewriter/Typewriter.styles.js +0 -62
  27. package/lib/components/typewriter/Typewriter.styles.js.map +0 -1
  28. package/lib/components/typewriter/utils.js.map +0 -1
  29. package/lib/index.js +0 -21
  30. package/lib/index.js.map +0 -1
  31. /package/lib/{index.d.ts → types/index.d.ts} +0 -0
package/README.md CHANGED
@@ -4,8 +4,8 @@
4
4
  </h1>
5
5
  <p>A set of beautiful React components for developing your own applications with chayns.</p>
6
6
  <div>
7
- <img src="https://img.shields.io/npm/dm/@chayns-components/typewriter.svg?style=for-the-badge" alt="" />
8
- <img src="https://img.shields.io/npm/v/@chayns-components/typewriter?style=for-the-badge" alt="" />
7
+ <img src="https://img.shields.io/npm/dm/@chayns-components/core.svg?style=for-the-badge" alt="" />
8
+ <img src="https://img.shields.io/npm/v/@chayns-components/core?style=for-the-badge" alt="" />
9
9
  <img src="https://img.shields.io/github/license/TobitSoftware/chayns-components?style=for-the-badge" alt="" />
10
10
  <img src="https://img.shields.io/github/contributors/TobitSoftware/chayns-components?style=for-the-badge" alt="" />
11
11
  </div>
@@ -15,7 +15,7 @@
15
15
 
16
16
  ## Installation
17
17
 
18
- First you need to install the typewriter part of the chayns-components.
18
+ First you need to install the core part of the chayns-components.
19
19
 
20
20
  ```bash
21
21
  # NPM
@@ -31,15 +31,4 @@ yarn add @chayns-components/typewriter
31
31
 
32
32
  ## Usage
33
33
 
34
- You can use the components in your project as in the following example.
35
-
36
- ```typescript jsx
37
- import { Typewriter } from '@chayns-components/typewriter';
38
-
39
- <Typewriter>
40
- Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt
41
- ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo
42
- dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est. Lorem ipsum dolor
43
- sit amet.
44
- </Typewriter>;
45
- ```
34
+ For detailed usage visit the [storybook](https://components.chayns.site/storybook).
@@ -0,0 +1,212 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.TypewriterSpeed = exports.TypewriterResetDelay = void 0;
7
+ var _core = require("@chayns-components/core");
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _reactDom = require("react-dom");
10
+ var _server = require("react-dom/server");
11
+ var _Typewriter = require("./Typewriter.styles");
12
+ var _utils = require("./utils");
13
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
14
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
15
+ // noinspection JSUnusedGlobalSymbols
16
+ let TypewriterResetDelay = exports.TypewriterResetDelay = /*#__PURE__*/function (TypewriterResetDelay) {
17
+ TypewriterResetDelay[TypewriterResetDelay["Slow"] = 4000] = "Slow";
18
+ TypewriterResetDelay[TypewriterResetDelay["Medium"] = 2000] = "Medium";
19
+ TypewriterResetDelay[TypewriterResetDelay["Fast"] = 1000] = "Fast";
20
+ return TypewriterResetDelay;
21
+ }({}); // noinspection JSUnusedGlobalSymbols
22
+ let TypewriterSpeed = exports.TypewriterSpeed = /*#__PURE__*/function (TypewriterSpeed) {
23
+ TypewriterSpeed[TypewriterSpeed["Slow"] = 30] = "Slow";
24
+ TypewriterSpeed[TypewriterSpeed["Medium"] = 20] = "Medium";
25
+ TypewriterSpeed[TypewriterSpeed["Fast"] = 10] = "Fast";
26
+ return TypewriterSpeed;
27
+ }({});
28
+ const Typewriter = ({
29
+ children,
30
+ onFinish,
31
+ pseudoChildren,
32
+ resetDelay = TypewriterResetDelay.Medium,
33
+ shouldForceCursorAnimation = false,
34
+ shouldHideCursor = false,
35
+ shouldSortChildrenRandomly = false,
36
+ shouldUseAnimationHeight = false,
37
+ shouldUseResetAnimation = false,
38
+ shouldWaitForContent,
39
+ speed = TypewriterSpeed.Medium,
40
+ textStyle
41
+ }) => {
42
+ const [currentChildrenIndex, setCurrentChildrenIndex] = (0, _react.useState)(0);
43
+ const [shouldCount, setShouldCount] = (0, _react.useState)(true);
44
+ const [hasRenderedChildrenOnce, setHasRenderedChildrenOnce] = (0, _react.useState)(false);
45
+ (0, _react.useLayoutEffect)(() => {
46
+ if (children) {
47
+ setHasRenderedChildrenOnce(false);
48
+ }
49
+ }, [children]);
50
+ (0, _react.useEffect)(() => {
51
+ if (!hasRenderedChildrenOnce) {
52
+ setHasRenderedChildrenOnce(true);
53
+ }
54
+ }, [hasRenderedChildrenOnce]);
55
+ const sortedChildren = (0, _react.useMemo)(() => Array.isArray(children) && shouldSortChildrenRandomly ? (0, _utils.shuffleArray)(children) : children, [children, shouldSortChildrenRandomly]);
56
+ const areMultipleChildrenGiven = Array.isArray(sortedChildren);
57
+ const childrenCount = areMultipleChildrenGiven ? sortedChildren.length : 1;
58
+ const textContent = (0, _react.useMemo)(() => {
59
+ if (areMultipleChildrenGiven) {
60
+ const currentChildren = sortedChildren[currentChildrenIndex];
61
+ if (currentChildren) {
62
+ return /*#__PURE__*/_react.default.isValidElement(currentChildren) ? (0, _server.renderToString)( /*#__PURE__*/_react.default.createElement(_core.ColorSchemeProvider, {
63
+ color: "#005EB8",
64
+ colorMode: 0,
65
+ style: {
66
+ display: 'inline'
67
+ }
68
+ }, currentChildren)) : currentChildren;
69
+ }
70
+ return '';
71
+ }
72
+ return /*#__PURE__*/_react.default.isValidElement(sortedChildren) ? (0, _server.renderToString)( /*#__PURE__*/_react.default.createElement(_core.ColorSchemeProvider, {
73
+ color: "#005EB8",
74
+ colorMode: 0,
75
+ style: {
76
+ display: 'inline'
77
+ }
78
+ }, sortedChildren)) : sortedChildren;
79
+ }, [areMultipleChildrenGiven, currentChildrenIndex, sortedChildren]);
80
+ const charactersCount = (0, _react.useMemo)(() => (0, _utils.getCharactersCount)(textContent), [textContent]);
81
+ const [isResetAnimationActive, setIsResetAnimationActive] = (0, _react.useState)(false);
82
+ const [shownCharCount, setShownCharCount] = (0, _react.useState)(charactersCount > 0 ? 0 : textContent.length);
83
+ const [shouldStopAnimation, setShouldStopAnimation] = (0, _react.useState)(false);
84
+ const [prevChildren, setPrevChildren] = (0, _react.useState)(children);
85
+ (0, _react.useEffect)(() => {
86
+ if (children !== prevChildren) {
87
+ setShouldCount(true);
88
+ setPrevChildren(children);
89
+ }
90
+ }, [children, prevChildren]);
91
+ const isAnimatingText = shownCharCount < textContent.length || shouldForceCursorAnimation || areMultipleChildrenGiven || textContent.length === 0;
92
+ const handleClick = (0, _react.useCallback)(() => {
93
+ setShouldStopAnimation(true);
94
+ }, []);
95
+ const handleSetNextChildrenIndex = (0, _react.useCallback)(() => setCurrentChildrenIndex(() => {
96
+ let newIndex = currentChildrenIndex + 1;
97
+ if (newIndex > childrenCount - 1) {
98
+ newIndex = 0;
99
+ }
100
+ return newIndex;
101
+ }), [childrenCount, currentChildrenIndex]);
102
+ (0, _react.useEffect)(() => {
103
+ let interval;
104
+ if (shouldStopAnimation || charactersCount === 0) {
105
+ setShownCharCount(textContent.length);
106
+ } else if (isResetAnimationActive) {
107
+ interval = window.setInterval(() => {
108
+ setShownCharCount(prevState => {
109
+ const nextState = prevState - 1;
110
+ if (nextState === 0) {
111
+ window.clearInterval(interval);
112
+ if (areMultipleChildrenGiven) {
113
+ setTimeout(() => {
114
+ setIsResetAnimationActive(false);
115
+ handleSetNextChildrenIndex();
116
+ }, resetDelay);
117
+ }
118
+ }
119
+ return nextState;
120
+ });
121
+ }, speed);
122
+ } else {
123
+ interval = window.setInterval(() => {
124
+ setShownCharCount(prevState => {
125
+ let nextState = prevState;
126
+ if (shouldCount) {
127
+ nextState = prevState + 1;
128
+ }
129
+ if (nextState >= charactersCount) {
130
+ if (shouldWaitForContent) {
131
+ setShouldCount(false);
132
+ } else {
133
+ window.clearInterval(interval);
134
+
135
+ /**
136
+ * At this point, the next value for "shownCharCount" is deliberately set to
137
+ * the length of the textContent in order to correctly display HTML elements
138
+ * after the last letter.
139
+ */
140
+ nextState = textContent.length;
141
+ if (areMultipleChildrenGiven) {
142
+ setTimeout(() => {
143
+ if (shouldUseResetAnimation) {
144
+ setIsResetAnimationActive(true);
145
+ } else {
146
+ setShownCharCount(0);
147
+ setTimeout(handleSetNextChildrenIndex, resetDelay / 2);
148
+ }
149
+ }, resetDelay);
150
+ }
151
+ }
152
+ }
153
+ return nextState;
154
+ });
155
+ }, speed);
156
+ }
157
+ return () => {
158
+ window.clearInterval(interval);
159
+ };
160
+ }, [shouldStopAnimation, speed, textContent.length, charactersCount, isResetAnimationActive, areMultipleChildrenGiven, resetDelay, childrenCount, handleSetNextChildrenIndex, shouldUseResetAnimation, shouldCount, shouldWaitForContent]);
161
+ (0, _react.useEffect)(() => {
162
+ if (!isAnimatingText && typeof onFinish === 'function') {
163
+ onFinish();
164
+ }
165
+ }, [isAnimatingText, onFinish]);
166
+ const shownText = (0, _react.useMemo)(() => (0, _utils.getSubTextFromHTML)(textContent, shownCharCount), [shownCharCount, textContent]);
167
+ const pseudoTextHTML = (0, _react.useMemo)(() => {
168
+ if (pseudoChildren) {
169
+ const pseudoText = /*#__PURE__*/_react.default.isValidElement(pseudoChildren) ? (0, _server.renderToString)( /*#__PURE__*/_react.default.createElement(_core.ColorSchemeProvider, {
170
+ color: "#005EB8",
171
+ colorMode: 0,
172
+ style: {
173
+ display: 'inline'
174
+ }
175
+ }, pseudoChildren)) : pseudoChildren;
176
+ if (shouldUseAnimationHeight) {
177
+ return (0, _utils.getSubTextFromHTML)(pseudoText, shownCharCount);
178
+ }
179
+ return pseudoText;
180
+ }
181
+ if (shouldUseAnimationHeight && textContent) {
182
+ return (0, _utils.getSubTextFromHTML)(textContent, shownCharCount);
183
+ }
184
+ return textContent || '&#8203;';
185
+ }, [pseudoChildren, shouldUseAnimationHeight, shownCharCount, textContent]);
186
+ return (0, _react.useMemo)(() => /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriter, {
187
+ onClick: handleClick
188
+ }, isAnimatingText ? /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriterText, {
189
+ dangerouslySetInnerHTML: {
190
+ __html: shownText
191
+ },
192
+ $isAnimatingText: true,
193
+ $shouldHideCursor: shouldHideCursor,
194
+ style: textStyle
195
+ }) : /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriterText, {
196
+ style: textStyle
197
+ }, sortedChildren), isAnimatingText && /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriterPseudoText, {
198
+ dangerouslySetInnerHTML: {
199
+ __html: pseudoTextHTML
200
+ },
201
+ $isAnimatingText: true,
202
+ $shouldHideCursor: shouldHideCursor
203
+ }), !hasRenderedChildrenOnce && /*#__PURE__*/(0, _reactDom.createPortal)( /*#__PURE__*/_react.default.createElement("div", {
204
+ style: {
205
+ position: 'absolute',
206
+ visibility: 'hidden'
207
+ }
208
+ }, children), document.body)), [children, handleClick, hasRenderedChildrenOnce, isAnimatingText, pseudoTextHTML, shouldHideCursor, shownText, sortedChildren, textStyle]);
209
+ };
210
+ Typewriter.displayName = 'Typewriter';
211
+ var _default = exports.default = Typewriter;
212
+ //# sourceMappingURL=Typewriter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Typewriter.js","names":["_core","require","_react","_interopRequireWildcard","_reactDom","_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","hasRenderedChildrenOnce","setHasRenderedChildrenOnce","useLayoutEffect","useEffect","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","isAnimatingText","handleClick","useCallback","handleSetNextChildrenIndex","newIndex","interval","window","setInterval","prevState","nextState","clearInterval","setTimeout","shownText","getSubTextFromHTML","pseudoTextHTML","pseudoText","StyledTypewriter","onClick","StyledTypewriterText","dangerouslySetInnerHTML","__html","$isAnimatingText","$shouldHideCursor","StyledTypewriterPseudoText","createPortal","position","visibility","document","body","displayName","_default"],"sources":["../../../../src/components/typewriter/Typewriter.tsx"],"sourcesContent":["import { ColorSchemeProvider } from '@chayns-components/core';\nimport React, {\n FC,\n ReactElement,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\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';\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 const [hasRenderedChildrenOnce, setHasRenderedChildrenOnce] = useState(false);\n\n useLayoutEffect(() => {\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 <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 style={textStyle}>{sortedChildren}</StyledTypewriterText>\n )}\n {isAnimatingText && (\n <StyledTypewriterPseudoText\n dangerouslySetInnerHTML={{ __html: pseudoTextHTML }}\n $isAnimatingText\n $shouldHideCursor={shouldHideCursor}\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,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,uBAAA,CAAAF,OAAA;AASA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,WAAA,GAAAL,OAAA;AAKA,IAAAM,MAAA,GAAAN,OAAA;AAA+E,SAAAO,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,SAAAN,wBAAAM,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA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aAAA,CAAC7D,WAAA,CAAA6F,gBAAgB;IAACC,OAAO,EAAEhB;EAAY,GAClCD,eAAe,gBACZjF,MAAA,CAAAY,OAAA,CAAAqD,aAAA,CAAC7D,WAAA,CAAA+F,oBAAoB;IACjBC,uBAAuB,EAAE;MAAEC,MAAM,EAAER;IAAU,CAAE;IAC/CS,gBAAgB;IAChBC,iBAAiB,EAAEnE,gBAAiB;IACpCiC,KAAK,EAAE3B;EAAU,CACpB,CAAC,gBAEF1C,MAAA,CAAAY,OAAA,CAAAqD,aAAA,CAAC7D,WAAA,CAAA+F,oBAAoB;IAAC9B,KAAK,EAAE3B;EAAU,GAAEU,cAAqC,CACjF,EACA6B,eAAe,iBACZjF,MAAA,CAAAY,OAAA,CAAAqD,aAAA,CAAC7D,WAAA,CAAAoG,0BAA0B;IACvBJ,uBAAuB,EAAE;MAAEC,MAAM,EAAEN;IAAe,CAAE;IACpDO,gBAAgB;IAChBC,iBAAiB,EAAEnE;EAAiB,CACvC,CACJ,EAKA,CAACY,uBAAuB,iBACrB,IAAAyD,sBAAY,gBACRzG,MAAA,CAAAY,OAAA,CAAAqD,aAAA;IAAKI,KAAK,EAAE;MAAEqC,QAAQ,EAAE,UAAU;MAAEC,UAAU,EAAE;IAAS;EAAE,GACtD7E,QACA,CAAC,EACN8E,QAAQ,CAACC,IACb,CACU,CACrB,EACD,CACI/E,QAAQ,EACRoD,WAAW,EACXlC,uBAAuB,EACvBiC,eAAe,EACfc,cAAc,EACd3D,gBAAgB,EAChByD,SAAS,EACTzC,cAAc,EACdV,SAAS,CAEjB,CAAC;AACL,CAAC;AAEDb,UAAU,CAACiF,WAAW,GAAG,YAAY;AAAC,IAAAC,QAAA,GAAApF,OAAA,CAAAf,OAAA,GAEvBiB,UAAU","ignoreList":[]}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.StyledTypewriterText = exports.StyledTypewriterPseudoText = exports.StyledTypewriter = void 0;
7
+ var _styledComponents = _interopRequireWildcard(require("styled-components"));
8
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
9
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
10
+ const StyledTypewriter = exports.StyledTypewriter = _styledComponents.default.div`
11
+ align-items: inherit;
12
+ display: flex;
13
+ position: relative;
14
+ width: 100%;
15
+ `;
16
+ const blinkAnimation = (0, _styledComponents.keyframes)`
17
+ 100% {
18
+ visibility: hidden;
19
+ }
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
+ `;
37
+ const StyledTypewriterPseudoText = exports.StyledTypewriterPseudoText = _styledComponents.default.span`
38
+ opacity: 0;
39
+ pointer-events: none;
40
+ user-select: none;
41
+
42
+ ${typewriterCursorElement}
43
+ `;
44
+ const StyledTypewriterText = exports.StyledTypewriterText = _styledComponents.default.span`
45
+ color: inherit;
46
+ position: ${({
47
+ $isAnimatingText
48
+ }) => $isAnimatingText ? 'absolute' : 'relative'};
49
+ width: 100%;
50
+
51
+ ${typewriterCursorElement}
52
+ `;
53
+ //# sourceMappingURL=Typewriter.styles.js.map
@@ -0,0 +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","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,uB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C,2BAAS;AAChC;AACA;AACA;AACA,CAAC;AAED,MAAMC,uBAAuB,GAAGA,CAAC;EAC7BC,gBAAgB;EAChBC;AAIJ,CAAC,KACGD,gBAAgB,IAChB,CAACC,iBAAiB,IAClB,IAAAC,qBAAG;AACP;AACA,yBAAyBL,cAAc;AACvC,qBAAqB,CAAC;EAAEM;AAAiC,CAAC,KAAKA,KAAK,CAACC,IAAI;AACzE;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AAEE,MAAMC,0BAA0B,GAAAX,OAAA,CAAAW,0BAAA,GAAGV,yBAAM,CAACW,IAA+B;AAChF;AACA;AACA;AACA;AACA,MAAMP,uBAAuB;AAC7B,CAAC;AAOM,MAAMQ,oBAAoB,GAAAb,OAAA,CAAAa,oBAAA,GAAGZ,yBAAM,CAACW,IAA+B;AAC1E;AACA,gBAAgB,CAAC;EAAEN;AAAiB,CAAC,KAAMA,gBAAgB,GAAG,UAAU,GAAG,UAAW;AACtF;AACA;AACA,MAAMD,uBAAuB;AAC7B,CAAC","ignoreList":[]}
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getSubTextFromHTML = exports.getCharactersCount = void 0;
6
+ exports.shuffleArray = exports.getSubTextFromHTML = exports.getCharactersCount = void 0;
7
7
  /**
8
8
  * This function extracts a part of the text from an HTML text. The HTML elements themselves are
9
9
  * returned in the result. In addition, the function ensures that the closing tag of the Bold HTML
@@ -67,6 +67,10 @@ const getCharactersCount = html => {
67
67
  if (node.nodeType === 3 && typeof node.textContent === 'string') {
68
68
  count += node.textContent.trim().length;
69
69
  } else if (node.nodeType === 1) {
70
+ if (node.nodeName === 'CODE' && node.textContent !== null) {
71
+ count += node.textContent.length;
72
+ return;
73
+ }
70
74
  Array.from(node.childNodes).forEach(traverse);
71
75
  }
72
76
  };
@@ -74,4 +78,13 @@ const getCharactersCount = html => {
74
78
  return count;
75
79
  };
76
80
  exports.getCharactersCount = getCharactersCount;
81
+ const shuffleArray = array => {
82
+ const result = Array.from(array);
83
+ for (let i = result.length - 1; i > 0; i--) {
84
+ const j = Math.floor(Math.random() * (i + 1));
85
+ [result[i], result[j]] = [result[j], result[i]];
86
+ }
87
+ return result;
88
+ };
89
+ exports.shuffleArray = shuffleArray;
77
90
  //# 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","nodeType","textContent","nodeText","substring","nodeName","toLowerCase","attributes","attribute","name","value","i","childNodes","childNode","exports","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.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.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;AACO,MAAMA,kBAAkB,GAAGA,CAACC,IAAY,EAAEC,MAAc,KAAa;EACxE,MAAMC,GAAG,GAAGC,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAEzCF,GAAG,CAACG,SAAS,GAAGL,IAAI;EAEpB,IAAIM,IAAI,GAAG,EAAE;EACb,IAAIC,UAAU,GAAG,CAAC;EAElB,MAAMC,QAAQ,GAAIC,OAAgB,IAAc;IAC5C,IAAIA,OAAO,CAACC,QAAQ,KAAK,CAAC,IAAI,OAAOD,OAAO,CAACE,WAAW,KAAK,QAAQ,EAAE;MACnE,MAAMC,QAAQ,GAAGH,OAAO,CAACE,WAAW;MAEpC,IAAIJ,UAAU,GAAGK,QAAQ,CAACX,MAAM,IAAIA,MAAM,EAAE;QACxCK,IAAI,IAAIM,QAAQ;QAChBL,UAAU,IAAIK,QAA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CAACa,MAAM,CAACb,CAAC,CAAC,EAAEa,MAAM,CAACC,CAAC,CAAC,CAAC,GAAG,CAACD,MAAM,CAACC,CAAC,CAAC,EAAGD,MAAM,CAACb,CAAC,CAAC,CAAE;EACrD;EAEA,OAAOa,MAAM;AACjB,CAAC;AAACV,OAAA,CAAAQ,YAAA,GAAAA,YAAA","ignoreList":[]}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "Typewriter", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _Typewriter.default;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "TypewriterSpeed", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _Typewriter.TypewriterSpeed;
16
+ }
17
+ });
18
+ var _Typewriter = _interopRequireWildcard(require("./components/typewriter/Typewriter"));
19
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
20
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["_Typewriter","_interopRequireWildcard","require","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set"],"sources":["../../src/index.ts"],"sourcesContent":["export { default as Typewriter, TypewriterS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chayns-components/core';
2
+ import React, { useCallback, useEffect, useLayoutEffect, useMemo, useState } from 'react';
3
+ import { createPortal } from 'react-dom';
4
+ import { renderToString } from 'react-dom/server';
5
+ import { StyledTypewriter, StyledTypewriterPseudoText, StyledTypewriterText } from './Typewriter.styles';
6
+ import { getCharactersCount, getSubTextFromHTML, shuffleArray } from './utils';
7
+
8
+ // noinspection JSUnusedGlobalSymbols
9
+ export let TypewriterResetDelay = /*#__PURE__*/function (TypewriterResetDelay) {
10
+ TypewriterResetDelay[TypewriterResetDelay["Slow"] = 4000] = "Slow";
11
+ TypewriterResetDelay[TypewriterResetDelay["Medium"] = 2000] = "Medium";
12
+ TypewriterResetDelay[TypewriterResetDelay["Fast"] = 1000] = "Fast";
13
+ return TypewriterResetDelay;
14
+ }({});
15
+
16
+ // noinspection JSUnusedGlobalSymbols
17
+ export let TypewriterSpeed = /*#__PURE__*/function (TypewriterSpeed) {
18
+ TypewriterSpeed[TypewriterSpeed["Slow"] = 30] = "Slow";
19
+ TypewriterSpeed[TypewriterSpeed["Medium"] = 20] = "Medium";
20
+ TypewriterSpeed[TypewriterSpeed["Fast"] = 10] = "Fast";
21
+ return TypewriterSpeed;
22
+ }({});
23
+ const Typewriter = _ref => {
24
+ let {
25
+ children,
26
+ onFinish,
27
+ pseudoChildren,
28
+ resetDelay = TypewriterResetDelay.Medium,
29
+ shouldForceCursorAnimation = false,
30
+ shouldHideCursor = false,
31
+ shouldSortChildrenRandomly = false,
32
+ shouldUseAnimationHeight = false,
33
+ shouldUseResetAnimation = false,
34
+ shouldWaitForContent,
35
+ speed = TypewriterSpeed.Medium,
36
+ textStyle
37
+ } = _ref;
38
+ const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);
39
+ const [shouldCount, setShouldCount] = useState(true);
40
+ const [hasRenderedChildrenOnce, setHasRenderedChildrenOnce] = useState(false);
41
+ useLayoutEffect(() => {
42
+ if (children) {
43
+ setHasRenderedChildrenOnce(false);
44
+ }
45
+ }, [children]);
46
+ useEffect(() => {
47
+ if (!hasRenderedChildrenOnce) {
48
+ setHasRenderedChildrenOnce(true);
49
+ }
50
+ }, [hasRenderedChildrenOnce]);
51
+ const sortedChildren = useMemo(() => Array.isArray(children) && shouldSortChildrenRandomly ? shuffleArray(children) : children, [children, shouldSortChildrenRandomly]);
52
+ const areMultipleChildrenGiven = Array.isArray(sortedChildren);
53
+ const childrenCount = areMultipleChildrenGiven ? sortedChildren.length : 1;
54
+ const textContent = useMemo(() => {
55
+ if (areMultipleChildrenGiven) {
56
+ const currentChildren = sortedChildren[currentChildrenIndex];
57
+ if (currentChildren) {
58
+ return /*#__PURE__*/React.isValidElement(currentChildren) ? renderToString( /*#__PURE__*/React.createElement(ColorSchemeProvider, {
59
+ color: "#005EB8",
60
+ colorMode: 0,
61
+ style: {
62
+ display: 'inline'
63
+ }
64
+ }, currentChildren)) : currentChildren;
65
+ }
66
+ return '';
67
+ }
68
+ return /*#__PURE__*/React.isValidElement(sortedChildren) ? renderToString( /*#__PURE__*/React.createElement(ColorSchemeProvider, {
69
+ color: "#005EB8",
70
+ colorMode: 0,
71
+ style: {
72
+ display: 'inline'
73
+ }
74
+ }, sortedChildren)) : sortedChildren;
75
+ }, [areMultipleChildrenGiven, currentChildrenIndex, sortedChildren]);
76
+ const charactersCount = useMemo(() => getCharactersCount(textContent), [textContent]);
77
+ const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);
78
+ const [shownCharCount, setShownCharCount] = useState(charactersCount > 0 ? 0 : textContent.length);
79
+ const [shouldStopAnimation, setShouldStopAnimation] = useState(false);
80
+ const [prevChildren, setPrevChildren] = useState(children);
81
+ useEffect(() => {
82
+ if (children !== prevChildren) {
83
+ setShouldCount(true);
84
+ setPrevChildren(children);
85
+ }
86
+ }, [children, prevChildren]);
87
+ const isAnimatingText = shownCharCount < textContent.length || shouldForceCursorAnimation || areMultipleChildrenGiven || textContent.length === 0;
88
+ const handleClick = useCallback(() => {
89
+ setShouldStopAnimation(true);
90
+ }, []);
91
+ const handleSetNextChildrenIndex = useCallback(() => setCurrentChildrenIndex(() => {
92
+ let newIndex = currentChildrenIndex + 1;
93
+ if (newIndex > childrenCount - 1) {
94
+ newIndex = 0;
95
+ }
96
+ return newIndex;
97
+ }), [childrenCount, currentChildrenIndex]);
98
+ useEffect(() => {
99
+ let interval;
100
+ if (shouldStopAnimation || charactersCount === 0) {
101
+ setShownCharCount(textContent.length);
102
+ } else if (isResetAnimationActive) {
103
+ interval = window.setInterval(() => {
104
+ setShownCharCount(prevState => {
105
+ const nextState = prevState - 1;
106
+ if (nextState === 0) {
107
+ window.clearInterval(interval);
108
+ if (areMultipleChildrenGiven) {
109
+ setTimeout(() => {
110
+ setIsResetAnimationActive(false);
111
+ handleSetNextChildrenIndex();
112
+ }, resetDelay);
113
+ }
114
+ }
115
+ return nextState;
116
+ });
117
+ }, speed);
118
+ } else {
119
+ interval = window.setInterval(() => {
120
+ setShownCharCount(prevState => {
121
+ let nextState = prevState;
122
+ if (shouldCount) {
123
+ nextState = prevState + 1;
124
+ }
125
+ if (nextState >= charactersCount) {
126
+ if (shouldWaitForContent) {
127
+ setShouldCount(false);
128
+ } else {
129
+ window.clearInterval(interval);
130
+
131
+ /**
132
+ * At this point, the next value for "shownCharCount" is deliberately set to
133
+ * the length of the textContent in order to correctly display HTML elements
134
+ * after the last letter.
135
+ */
136
+ nextState = textContent.length;
137
+ if (areMultipleChildrenGiven) {
138
+ setTimeout(() => {
139
+ if (shouldUseResetAnimation) {
140
+ setIsResetAnimationActive(true);
141
+ } else {
142
+ setShownCharCount(0);
143
+ setTimeout(handleSetNextChildrenIndex, resetDelay / 2);
144
+ }
145
+ }, resetDelay);
146
+ }
147
+ }
148
+ }
149
+ return nextState;
150
+ });
151
+ }, speed);
152
+ }
153
+ return () => {
154
+ window.clearInterval(interval);
155
+ };
156
+ }, [shouldStopAnimation, speed, textContent.length, charactersCount, isResetAnimationActive, areMultipleChildrenGiven, resetDelay, childrenCount, handleSetNextChildrenIndex, shouldUseResetAnimation, shouldCount, shouldWaitForContent]);
157
+ useEffect(() => {
158
+ if (!isAnimatingText && typeof onFinish === 'function') {
159
+ onFinish();
160
+ }
161
+ }, [isAnimatingText, onFinish]);
162
+ const shownText = useMemo(() => getSubTextFromHTML(textContent, shownCharCount), [shownCharCount, textContent]);
163
+ const pseudoTextHTML = useMemo(() => {
164
+ if (pseudoChildren) {
165
+ const pseudoText = /*#__PURE__*/React.isValidElement(pseudoChildren) ? renderToString( /*#__PURE__*/React.createElement(ColorSchemeProvider, {
166
+ color: "#005EB8",
167
+ colorMode: 0,
168
+ style: {
169
+ display: 'inline'
170
+ }
171
+ }, pseudoChildren)) : pseudoChildren;
172
+ if (shouldUseAnimationHeight) {
173
+ return getSubTextFromHTML(pseudoText, shownCharCount);
174
+ }
175
+ return pseudoText;
176
+ }
177
+ if (shouldUseAnimationHeight && textContent) {
178
+ return getSubTextFromHTML(textContent, shownCharCount);
179
+ }
180
+ return textContent || '&#8203;';
181
+ }, [pseudoChildren, shouldUseAnimationHeight, shownCharCount, textContent]);
182
+ return useMemo(() => /*#__PURE__*/React.createElement(StyledTypewriter, {
183
+ onClick: handleClick
184
+ }, isAnimatingText ? /*#__PURE__*/React.createElement(StyledTypewriterText, {
185
+ dangerouslySetInnerHTML: {
186
+ __html: shownText
187
+ },
188
+ $isAnimatingText: true,
189
+ $shouldHideCursor: shouldHideCursor,
190
+ style: textStyle
191
+ }) : /*#__PURE__*/React.createElement(StyledTypewriterText, {
192
+ style: textStyle
193
+ }, sortedChildren), isAnimatingText && /*#__PURE__*/React.createElement(StyledTypewriterPseudoText, {
194
+ dangerouslySetInnerHTML: {
195
+ __html: pseudoTextHTML
196
+ },
197
+ $isAnimatingText: true,
198
+ $shouldHideCursor: shouldHideCursor
199
+ }), !hasRenderedChildrenOnce && /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement("div", {
200
+ style: {
201
+ position: 'absolute',
202
+ visibility: 'hidden'
203
+ }
204
+ }, children), document.body)), [children, handleClick, hasRenderedChildrenOnce, isAnimatingText, pseudoTextHTML, shouldHideCursor, shownText, sortedChildren, textStyle]);
205
+ };
206
+ Typewriter.displayName = 'Typewriter';
207
+ export default Typewriter;
208
+ //# sourceMappingURL=Typewriter.js.map