@chayns-components/typewriter 5.0.0-beta.441 → 5.0.0-beta.443

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.
@@ -1,23 +1,18 @@
1
- "use strict";
1
+ import React, { useCallback, useEffect, useMemo, useState } from 'react';
2
+ import { renderToString } from 'react-dom/server';
3
+ import { StyledTypewriter, StyledTypewriterPseudoText, StyledTypewriterText } from './Typewriter.styles';
4
+ import { getCharactersCount, getSubTextFromHTML, shuffleArray } from './utils';
2
5
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.TypewriterSpeed = exports.TypewriterResetDelay = void 0;
7
- var _react = _interopRequireWildcard(require("react"));
8
- var _server = require("react-dom/server");
9
- var _Typewriter = require("./Typewriter.styles");
10
- var _utils = require("./utils");
11
- 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); }
12
- 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 && Object.prototype.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; }
13
6
  // noinspection JSUnusedGlobalSymbols
14
- let TypewriterResetDelay = exports.TypewriterResetDelay = /*#__PURE__*/function (TypewriterResetDelay) {
7
+ export let TypewriterResetDelay = /*#__PURE__*/function (TypewriterResetDelay) {
15
8
  TypewriterResetDelay[TypewriterResetDelay["Slow"] = 4000] = "Slow";
16
9
  TypewriterResetDelay[TypewriterResetDelay["Medium"] = 2000] = "Medium";
17
10
  TypewriterResetDelay[TypewriterResetDelay["Fast"] = 1000] = "Fast";
18
11
  return TypewriterResetDelay;
19
- }({}); // noinspection JSUnusedGlobalSymbols
20
- let TypewriterSpeed = exports.TypewriterSpeed = /*#__PURE__*/function (TypewriterSpeed) {
12
+ }({});
13
+
14
+ // noinspection JSUnusedGlobalSymbols
15
+ export let TypewriterSpeed = /*#__PURE__*/function (TypewriterSpeed) {
21
16
  TypewriterSpeed[TypewriterSpeed["Slow"] = 35] = "Slow";
22
17
  TypewriterSpeed[TypewriterSpeed["Medium"] = 25] = "Medium";
23
18
  TypewriterSpeed[TypewriterSpeed["Fast"] = 15] = "Fast";
@@ -37,41 +32,41 @@ const Typewriter = _ref => {
37
32
  speed = TypewriterSpeed.Medium,
38
33
  textStyle
39
34
  } = _ref;
40
- const [currentChildrenIndex, setCurrentChildrenIndex] = (0, _react.useState)(0);
41
- const sortedChildren = (0, _react.useMemo)(() => Array.isArray(children) && shouldSortChildrenRandomly ? (0, _utils.shuffleArray)(children) : children, [children, shouldSortChildrenRandomly]);
35
+ const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);
36
+ const sortedChildren = useMemo(() => Array.isArray(children) && shouldSortChildrenRandomly ? shuffleArray(children) : children, [children, shouldSortChildrenRandomly]);
42
37
  const areMultipleChildrenGiven = Array.isArray(sortedChildren);
43
38
  const childrenCount = areMultipleChildrenGiven ? sortedChildren.length : 1;
44
- const textContent = (0, _react.useMemo)(() => {
39
+ const textContent = useMemo(() => {
45
40
  if (areMultipleChildrenGiven) {
46
41
  const currentChildren = sortedChildren[currentChildrenIndex];
47
42
  if (currentChildren) {
48
- return /*#__PURE__*/_react.default.isValidElement(currentChildren) ? (0, _server.renderToString)(currentChildren) : currentChildren;
43
+ return /*#__PURE__*/React.isValidElement(currentChildren) ? renderToString(currentChildren) : currentChildren;
49
44
  }
50
45
  return '';
51
46
  }
52
- return /*#__PURE__*/_react.default.isValidElement(sortedChildren) ? (0, _server.renderToString)(sortedChildren) : sortedChildren;
47
+ return /*#__PURE__*/React.isValidElement(sortedChildren) ? renderToString(sortedChildren) : sortedChildren;
53
48
  }, [areMultipleChildrenGiven, currentChildrenIndex, sortedChildren]);
54
- const charactersCount = (0, _react.useMemo)(() => (0, _utils.getCharactersCount)(textContent), [textContent]);
55
- const [isResetAnimationActive, setIsResetAnimationActive] = (0, _react.useState)(false);
56
- const [shownCharCount, setShownCharCount] = (0, _react.useState)(charactersCount > 0 ? 0 : textContent.length);
57
- const [shouldStopAnimation, setShouldStopAnimation] = (0, _react.useState)(false);
49
+ const charactersCount = useMemo(() => getCharactersCount(textContent), [textContent]);
50
+ const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);
51
+ const [shownCharCount, setShownCharCount] = useState(charactersCount > 0 ? 0 : textContent.length);
52
+ const [shouldStopAnimation, setShouldStopAnimation] = useState(false);
58
53
  console.debug({
59
54
  charactersCount,
60
55
  textContent,
61
56
  shownCharCount
62
57
  });
63
- const isAnimatingText = shownCharCount !== textContent.length || shouldForceCursorAnimation || areMultipleChildrenGiven || textContent.length === 0;
64
- const handleClick = (0, _react.useCallback)(() => {
58
+ const isAnimatingText = shownCharCount < textContent.length || shouldForceCursorAnimation || areMultipleChildrenGiven || textContent.length === 0;
59
+ const handleClick = useCallback(() => {
65
60
  setShouldStopAnimation(true);
66
61
  }, []);
67
- const handleSetNextChildrenIndex = (0, _react.useCallback)(() => setCurrentChildrenIndex(() => {
62
+ const handleSetNextChildrenIndex = useCallback(() => setCurrentChildrenIndex(() => {
68
63
  let newIndex = currentChildrenIndex + 1;
69
64
  if (newIndex > childrenCount - 1) {
70
65
  newIndex = 0;
71
66
  }
72
67
  return newIndex;
73
68
  }), [childrenCount, currentChildrenIndex]);
74
- (0, _react.useEffect)(() => {
69
+ useEffect(() => {
75
70
  let interval;
76
71
  if (shouldStopAnimation || charactersCount === 0) {
77
72
  setShownCharCount(textContent.length);
@@ -123,45 +118,45 @@ const Typewriter = _ref => {
123
118
  window.clearInterval(interval);
124
119
  };
125
120
  }, [shouldStopAnimation, speed, textContent.length, charactersCount, isResetAnimationActive, areMultipleChildrenGiven, resetDelay, childrenCount, handleSetNextChildrenIndex, shouldUseResetAnimation]);
126
- (0, _react.useEffect)(() => {
121
+ useEffect(() => {
127
122
  if (!isAnimatingText && typeof onFinish === 'function') {
128
123
  onFinish();
129
124
  }
130
125
  }, [isAnimatingText, onFinish]);
131
- const shownText = (0, _react.useMemo)(() => (0, _utils.getSubTextFromHTML)(textContent, shownCharCount), [shownCharCount, textContent]);
132
- const pseudoTextHTML = (0, _react.useMemo)(() => {
126
+ const shownText = useMemo(() => getSubTextFromHTML(textContent, shownCharCount), [shownCharCount, textContent]);
127
+ const pseudoTextHTML = useMemo(() => {
133
128
  if (pseudoChildren) {
134
- const pseudoText = /*#__PURE__*/_react.default.isValidElement(pseudoChildren) ? (0, _server.renderToString)(pseudoChildren) : pseudoChildren;
129
+ const pseudoText = /*#__PURE__*/React.isValidElement(pseudoChildren) ? renderToString(pseudoChildren) : pseudoChildren;
135
130
  if (shouldUseAnimationHeight) {
136
- return (0, _utils.getSubTextFromHTML)(pseudoText, shownCharCount);
131
+ return getSubTextFromHTML(pseudoText, shownCharCount);
137
132
  }
138
133
  return pseudoText;
139
134
  }
140
135
  if (shouldUseAnimationHeight && textContent) {
141
- return (0, _utils.getSubTextFromHTML)(textContent, shownCharCount);
136
+ return getSubTextFromHTML(textContent, shownCharCount);
142
137
  }
143
138
  return textContent || '&#8203;';
144
139
  }, [pseudoChildren, shouldUseAnimationHeight, shownCharCount, textContent]);
145
- return (0, _react.useMemo)(() => /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriter, {
140
+ return useMemo(() => /*#__PURE__*/React.createElement(StyledTypewriter, {
146
141
  onClick: handleClick
147
- }, isAnimatingText && /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriterText, {
142
+ }, isAnimatingText && /*#__PURE__*/React.createElement(StyledTypewriterText, {
148
143
  dangerouslySetInnerHTML: {
149
144
  __html: shownText
150
145
  },
151
146
  isAnimatingText: true,
152
147
  shouldHideCursor: shouldHideCursor,
153
148
  style: textStyle
154
- }), /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriterText, {
149
+ }), /*#__PURE__*/React.createElement(StyledTypewriterText, {
155
150
  style: isAnimatingText ? {
156
151
  visibility: 'hidden',
157
152
  position: 'absolute'
158
153
  } : textStyle
159
- }, sortedChildren), isAnimatingText && /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriterPseudoText, {
154
+ }, sortedChildren), isAnimatingText && /*#__PURE__*/React.createElement(StyledTypewriterPseudoText, {
160
155
  dangerouslySetInnerHTML: {
161
156
  __html: pseudoTextHTML
162
157
  }
163
158
  })), [handleClick, isAnimatingText, pseudoTextHTML, shouldHideCursor, shownText, sortedChildren, textStyle]);
164
159
  };
165
160
  Typewriter.displayName = 'Typewriter';
166
- var _default = exports.default = Typewriter;
161
+ export default Typewriter;
167
162
  //# sourceMappingURL=Typewriter.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Typewriter.js","names":["_react","_interopRequireWildcard","require","_server","_Typewriter","_utils","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","TypewriterResetDelay","exports","TypewriterSpeed","Typewriter","_ref","children","onFinish","pseudoChildren","resetDelay","Medium","shouldForceCursorAnimation","shouldHideCursor","shouldSortChildrenRandomly","shouldUseAnimationHeight","shouldUseResetAnimation","speed","textStyle","currentChildrenIndex","setCurrentChildrenIndex","useState","sortedChildren","useMemo","Array","isArray","shuffleArray","areMultipleChildrenGiven","childrenCount","length","textContent","currentChildren","React","isValidElement","renderToString","charactersCount","getCharactersCount","isResetAnimationActive","setIsResetAnimationActive","shownCharCount","setShownCharCount","shouldStopAnimation","setShouldStopAnimation","console","debug","isAnimatingText","handleClick","useCallback","handleSetNextChildrenIndex","newIndex","useEffect","interval","window","setInterval","prevState","nextState","clearInterval","setTimeout","shownText","getSubTextFromHTML","pseudoTextHTML","pseudoText","createElement","StyledTypewriter","onClick","StyledTypewriterText","dangerouslySetInnerHTML","__html","style","visibility","position","StyledTypewriterPseudoText","displayName","_default"],"sources":["../../../src/components/typewriter/Typewriter.tsx"],"sourcesContent":["import 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 = 35,\n Medium = 25,\n Fast = 15,\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 * 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 speed = TypewriterSpeed.Medium,\n textStyle,\n}) => {\n const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);\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(currentChildren)\n : (currentChildren as string);\n }\n\n return '';\n }\n\n return React.isValidElement(sortedChildren)\n ? renderToString(sortedChildren)\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\n console.debug({ charactersCount, textContent, shownCharCount });\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 + 1;\n\n if (nextState === charactersCount) {\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 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 ]);\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(pseudoChildren)\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,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAKA,IAAAG,MAAA,GAAAH,OAAA;AAA+E,SAAAI,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,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAA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D;EAAU,CACpB,CACJ,eACD3C,MAAA,CAAAY,OAAA,CAAA2E,aAAA,CAACnF,WAAA,CAAAsF,oBAAoB;IACjBG,KAAK,EACDvB,eAAe,GAAG;MAAEwB,UAAU,EAAE,QAAQ;MAAEC,QAAQ,EAAE;IAAW,CAAC,GAAGpD;EACtE,GAEAI,cACiB,CAAC,EACtBuB,eAAe,iBACZtE,MAAA,CAAAY,OAAA,CAAA2E,aAAA,CAACnF,WAAA,CAAA4F,0BAA0B;IACvBL,uBAAuB,EAAE;MAAEC,MAAM,EAAEP;IAAe;EAAE,CACvD,CAES,CACrB,EACD,CACId,WAAW,EACXD,eAAe,EACfe,cAAc,EACd/C,gBAAgB,EAChB6C,SAAS,EACTpC,cAAc,EACdJ,SAAS,CAEjB,CAAC;AACL,CAAC;AAEDb,UAAU,CAACmE,WAAW,GAAG,YAAY;AAAC,IAAAC,QAAA,GAAAtE,OAAA,CAAAhB,OAAA,GAEvBkB,UAAU"}
1
+ {"version":3,"file":"Typewriter.js","names":["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","speed","textStyle","currentChildrenIndex","setCurrentChildrenIndex","sortedChildren","Array","isArray","areMultipleChildrenGiven","childrenCount","length","textContent","currentChildren","isValidElement","charactersCount","isResetAnimationActive","setIsResetAnimationActive","shownCharCount","setShownCharCount","shouldStopAnimation","setShouldStopAnimation","console","debug","isAnimatingText","handleClick","handleSetNextChildrenIndex","newIndex","interval","window","setInterval","prevState","nextState","clearInterval","setTimeout","shownText","pseudoTextHTML","pseudoText","createElement","onClick","dangerouslySetInnerHTML","__html","style","visibility","position","displayName"],"sources":["../../../src/components/typewriter/Typewriter.tsx"],"sourcesContent":["import 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 = 35,\n Medium = 25,\n Fast = 15,\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 * 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 speed = TypewriterSpeed.Medium,\n textStyle,\n}) => {\n const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);\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(currentChildren)\n : (currentChildren as string);\n }\n\n return '';\n }\n\n return React.isValidElement(sortedChildren)\n ? renderToString(sortedChildren)\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\n console.debug({ charactersCount, textContent, shownCharCount });\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 + 1;\n\n if (nextState === charactersCount) {\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 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 ]);\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(pseudoChildren)\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,OAAOA,KAAK,IAAsBC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AAC1F,SAASC,cAAc,QAAQ,kBAAkB;AACjD,SACIC,gBAAgB,EAChBC,0BAA0B,EAC1BC,oBAAoB,QACjB,qBAAqB;AAC5B,SAASC,kBAAkB,EAAEC,kBAAkB,EAAEC,YAAY,QAAQ,SAAS;;AAE9E;AACA,WAAYC,oBAAoB,0BAApBA,oBAAoB;EAApBA,oBAAoB,CAApBA,oBAAoB;EAApBA,oBAAoB,CAApBA,oBAAoB;EAApBA,oBAAoB,CAApBA,oBAAoB;EAAA,OAApBA,oBAAoB;AAAA;;AAMhC;AACA,WAAYC,eAAe,0BAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAA,OAAfA,eAAe;AAAA;AA2D3B,MAAMC,UAA+B,GAAGC,IAAA,IAYlC;EAAA,IAZmC;IACrCC,QAAQ;IACRC,QAAQ;IACRC,cAAc;IACdC,UAAU,GAAGP,oBAAoB,CAACQ,MAAM;IACxCC,0BAA0B,GAAG,KAAK;IAClCC,gBA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E;IAAW,CAAC,GAAGzC;EACtE,GAEAG,cACiB,CAAC,EACtBkB,eAAe,iBACZhD,KAAA,CAAA8D,aAAA,CAACvD,0BAA0B;IACvByD,uBAAuB,EAAE;MAAEC,MAAM,EAAEL;IAAe;EAAE,CACvD,CAES,CACrB,EACD,CACIX,WAAW,EACXD,eAAe,EACfY,cAAc,EACdtC,gBAAgB,EAChBqC,SAAS,EACT7B,cAAc,EACdH,SAAS,CAEjB,CAAC;AACL,CAAC;AAEDb,UAAU,CAACuD,WAAW,GAAG,YAAY;AAErC,eAAevD,UAAU"}
@@ -1,29 +1,21 @@
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 && Object.prototype.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`
1
+ import styled, { css, keyframes } from 'styled-components';
2
+ export const StyledTypewriter = styled.div`
11
3
  align-items: inherit;
12
4
  display: flex;
13
5
  position: relative;
14
6
  width: 100%;
15
7
  `;
16
- const blinkAnimation = (0, _styledComponents.keyframes)`
8
+ const blinkAnimation = keyframes`
17
9
  100% {
18
10
  visibility: hidden;
19
11
  }
20
12
  `;
21
- const StyledTypewriterPseudoText = exports.StyledTypewriterPseudoText = _styledComponents.default.span`
13
+ export const StyledTypewriterPseudoText = styled.span`
22
14
  opacity: 0;
23
15
  pointer-events: none;
24
16
  user-select: none;
25
17
  `;
26
- const StyledTypewriterText = exports.StyledTypewriterText = _styledComponents.default.span`
18
+ export const StyledTypewriterText = styled.span`
27
19
  color: inherit;
28
20
  position: ${_ref => {
29
21
  let {
@@ -38,7 +30,7 @@ const StyledTypewriterText = exports.StyledTypewriterText = _styledComponents.de
38
30
  isAnimatingText,
39
31
  shouldHideCursor
40
32
  } = _ref2;
41
- return isAnimatingText && !shouldHideCursor && (0, _styledComponents.css)`
33
+ return isAnimatingText && !shouldHideCursor && css`
42
34
  &:after {
43
35
  animation: ${blinkAnimation} 1s steps(5, start) infinite;
44
36
  color: ${_ref3 => {
@@ -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","prototype","hasOwnProperty","call","i","set","StyledTypewriter","exports","styled","div","blinkAnimation","keyframes","StyledTypewriterPseudoText","span","StyledTypewriterText","_ref","isAnimatingText","_ref2","shouldHideCursor","css","_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,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,CAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAjB,CAAA,EAAAc,CAAA,SAAAI,CAAA,GAAAR,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAI,CAAA,KAAAA,CAAA,CAAAX,GAAA,IAAAW,CAAA,CAAAC,GAAA,IAAAR,MAAA,CAAAC,cAAA,CAAAJ,CAAA,EAAAM,CAAA,EAAAI,CAAA,IAAAV,CAAA,CAAAM,CAAA,IAAAd,CAAA,CAAAc,CAAA,YAAAN,CAAA,CAAAH,OAAA,GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAgB,GAAA,CAAAnB,CAAA,EAAAQ,CAAA,GAAAA,CAAA;AAEpD,MAAMY,gBAAgB,GAAAC,OAAA,CAAAD,gBAAA,GAAGE,yBAAM,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,gBAAgBE,IAAA;EAAA,IAAC;IAAEC;EAAgB,CAAC,GAAAD,IAAA;EAAA,OAAMC,eAAe,GAAG,UAAU,GAAG,UAAU;AAAA,CAAE;AACrF;AACA;AACA,MAAMC,KAAA;EAAA,IAAC;IAAED,eAAe;IAAEE;EAAiB,CAAC,GAAAD,KAAA;EAAA,OACpCD,eAAe,IACf,CAACE,gBAAgB,IACjB,IAAAC,qBAAG,CAAC;AACZ;AACA,6BAA6BT,cAAe;AAC5C,yBAAyBU,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"}
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;EAAgB,CAAC,GAAAD,IAAA;EAAA,OAAMC,eAAe,GAAG,UAAU,GAAG,UAAU;AAAA,CAAE;AACrF;AACA;AACA,MAAMC,KAAA;EAAA,IAAC;IAAED,eAAe;IAAEE;EAAiB,CAAC,GAAAD,KAAA;EAAA,OACpCD,eAAe,IACf,CAACE,gBAAgB,IACjBX,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"}
@@ -1,9 +1,3 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.shuffleArray = exports.getSubTextFromHTML = exports.getCharactersCount = void 0;
7
1
  /**
8
2
  * This function extracts a part of the text from an HTML text. The HTML elements themselves are
9
3
  * returned in the result. In addition, the function ensures that the closing tag of the Bold HTML
@@ -14,7 +8,7 @@ exports.shuffleArray = exports.getSubTextFromHTML = exports.getCharactersCount =
14
8
  *
15
9
  * @return string - The text part with the specified length - additionally the HTML elements are added
16
10
  */
17
- const getSubTextFromHTML = (html, length) => {
11
+ export const getSubTextFromHTML = (html, length) => {
18
12
  const div = document.createElement('div');
19
13
  div.innerHTML = html;
20
14
  let text = '';
@@ -58,8 +52,7 @@ const getSubTextFromHTML = (html, length) => {
58
52
  }
59
53
  return text;
60
54
  };
61
- exports.getSubTextFromHTML = getSubTextFromHTML;
62
- const getCharactersCount = html => {
55
+ export const getCharactersCount = html => {
63
56
  const div = document.createElement('div');
64
57
  div.innerHTML = html;
65
58
  let count = 0;
@@ -77,8 +70,7 @@ const getCharactersCount = html => {
77
70
  Array.from(div.childNodes).forEach(traverse);
78
71
  return count;
79
72
  };
80
- exports.getCharactersCount = getCharactersCount;
81
- const shuffleArray = array => {
73
+ export const shuffleArray = array => {
82
74
  const result = Array.from(array);
83
75
  for (let i = result.length - 1; i > 0; i--) {
84
76
  const j = Math.floor(Math.random() * (i + 1));
@@ -86,5 +78,4 @@ const shuffleArray = array => {
86
78
  }
87
79
  return result;
88
80
  };
89
- exports.shuffleArray = shuffleArray;
90
81
  //# sourceMappingURL=utils.js.map
@@ -1 +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,QAAQ,CAACX,MAAM;MACjC,CAAC,MAAM;QACHK,IAAI,IAAIM,QAAQ,CAACC,SAAS,CAAC,CAAC,EAAEZ,MAAM,GAAGM,UAAU,CAAC;QAElD,OAAO,KAAK;MAChB;IACJ,CAAC,MAAM,IAAIE,OAAO,CAACC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V,OAAA,CAAAQ,YAAA,GAAAA,YAAA"}
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","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;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,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,QAAQ,CAACX,MAAM;MACjC,CAAC,MAAM;QACHK,IAAI,IAAIM,QAAQ,CAACC,SAAS,CAAC,CAAC,EAAEZ,MAAM,GAAGM,UAAU,CAAC;QAElD,OAAO,KAAK;MAChB;IACJ,CAAC,MAAM,IAAIE,OAAO,CAACC,QAAQ,KAA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});
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 && Object.prototype.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; }
1
+ export { default as Typewriter, TypewriterSpeed } from './components/typewriter/Typewriter';
21
2
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +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","prototype","hasOwnProperty","call","i","set"],"sources":["../src/index.ts"],"sourcesContent":["export { default as Typewriter, TypewriterSpeed } from './components/typewriter/Typewriter';\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,WAAA,GAAAC,uBAAA,CAAAC,OAAA;AAA4F,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,CAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAjB,CAAA,EAAAc,CAAA,SAAAI,CAAA,GAAAR,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAI,CAAA,KAAAA,CAAA,CAAAX,GAAA,IAAAW,CAAA,CAAAC,GAAA,IAAAR,MAAA,CAAAC,cAAA,CAAAJ,CAAA,EAAAM,CAAA,EAAAI,CAAA,IAAAV,CAAA,CAAAM,CAAA,IAAAd,CAAA,CAAAc,CAAA,YAAAN,CAAA,CAAAH,OAAA,GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAgB,GAAA,CAAAnB,CAAA,EAAAQ,CAAA,GAAAA,CAAA"}
1
+ {"version":3,"file":"index.js","names":["default","Typewriter","TypewriterSpeed"],"sources":["../src/index.ts"],"sourcesContent":["export { default as Typewriter, TypewriterSpeed } from './components/typewriter/Typewriter';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,UAAU,EAAEC,eAAe,QAAQ,oCAAoC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chayns-components/typewriter",
3
- "version": "5.0.0-beta.441",
3
+ "version": "5.0.0-beta.443",
4
4
  "description": "A set of beautiful React components for developing your own applications with chayns.",
5
5
  "keywords": [
6
6
  "chayns",
@@ -33,24 +33,24 @@
33
33
  "url": "https://github.com/TobitSoftware/chayns-components/issues"
34
34
  },
35
35
  "devDependencies": {
36
- "@babel/cli": "^7.23.4",
37
- "@babel/core": "^7.23.7",
38
- "@babel/preset-env": "^7.23.8",
36
+ "@babel/cli": "^7.23.9",
37
+ "@babel/core": "^7.23.9",
38
+ "@babel/preset-env": "^7.23.9",
39
39
  "@babel/preset-react": "^7.23.3",
40
40
  "@babel/preset-typescript": "^7.23.3",
41
- "@types/react": "^18.2.48",
42
- "@types/react-dom": "^18.2.18",
41
+ "@types/react": "^18.2.55",
42
+ "@types/react-dom": "^18.2.19",
43
43
  "@types/styled-components": "^5.1.34",
44
- "@types/uuid": "^9.0.7",
44
+ "@types/uuid": "^9.0.8",
45
45
  "babel-loader": "^9.1.3",
46
- "lerna": "^8.0.2",
46
+ "lerna": "^8.1.2",
47
47
  "react": "^18.2.0",
48
48
  "react-dom": "^18.2.0",
49
49
  "styled-components": "^6.1.8",
50
50
  "typescript": "^5.3.3"
51
51
  },
52
52
  "dependencies": {
53
- "@chayns-components/core": "^5.0.0-beta.441"
53
+ "@chayns-components/core": "^5.0.0-beta.443"
54
54
  },
55
55
  "peerDependencies": {
56
56
  "chayns-api": ">=1.0.50",
@@ -62,5 +62,5 @@
62
62
  "publishConfig": {
63
63
  "access": "public"
64
64
  },
65
- "gitHead": "d9b7d5cebd42707113634c1d54151306f6236d8f"
65
+ "gitHead": "3f3e8b424de86b8597fd4670766a496a767ee1ba"
66
66
  }