@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Typewriter.js","names":["ColorSchemeProvider","React","useCallback","useEffect","useLayoutEffect","useMemo","useState","createPortal","renderToString","StyledTypewriter","StyledTypewriterPseudoText","StyledTypewriterText","getCharactersCount","getSubTextFromHTML","shuffleArray","TypewriterResetDelay","TypewriterSpeed","Typewriter","_ref","children","onFinish","pseudoChildren","resetDelay","Medium","shouldForceCursorAnimation","shouldHideCursor","shouldSortChildrenRandomly","shouldUseAnimationHeight","shouldUseResetAnimation","shouldWaitForContent","speed","textStyle","currentChildrenIndex","setCurrentChildrenIndex","shouldCount","setShouldCount","hasRenderedChildrenOnce","setHasRenderedChildrenOnce","sortedChildren","Array","isArray","areMultipleChildrenGiven","childrenCount","length","textContent","currentChildren","isValidElement","createElement","color","colorMode","style","display","charactersCount","isResetAnimationActive","setIsResetAnimationActive","shownCharCount","setShownCharCount","shouldStopAnimation","setShouldStopAnimation","prevChildren","setPrevChildren","isAnimatingText","handleClick","handleSetNextChildrenIndex","newIndex","interval","window","setInterval","prevState","nextState","clearInterval","setTimeout","shownText","pseudoTextHTML","pseudoText","onClick","dangerouslySetInnerHTML","__html","$isAnimatingText","$shouldHideCursor","position","visibility","document","body","displayName"],"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,SAASA,mBAAmB,QAAQ,yBAAyB;AAC7D,OAAOC,KAAK,IAGRC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,OAAO,EACPC,QAAQ,QACL,OAAO;AACd,SAASC,YAAY,QAAQ,WAAW;AACxC,SAASC,cAAc,QAAQ,kBAAkB;AACjD,SACIC,gB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oreList":[]}
@@ -0,0 +1,54 @@
1
+ import styled, { css, keyframes } from 'styled-components';
2
+ export const StyledTypewriter = styled.div`
3
+ align-items: inherit;
4
+ display: flex;
5
+ position: relative;
6
+ width: 100%;
7
+ `;
8
+ const blinkAnimation = keyframes`
9
+ 100% {
10
+ visibility: hidden;
11
+ }
12
+ `;
13
+ const typewriterCursorElement = _ref => {
14
+ let {
15
+ $isAnimatingText,
16
+ $shouldHideCursor
17
+ } = _ref;
18
+ return $isAnimatingText && !$shouldHideCursor && css`
19
+ &:after {
20
+ animation: ${blinkAnimation} 1s steps(5, start) infinite;
21
+ color: ${_ref2 => {
22
+ let {
23
+ theme
24
+ } = _ref2;
25
+ return theme.text;
26
+ }};
27
+ content: '▋';
28
+ margin-left: 0.25rem;
29
+ opacity: 0.85;
30
+ position: relative;
31
+ vertical-align: baseline;
32
+ }
33
+ `;
34
+ };
35
+ export const StyledTypewriterPseudoText = styled.span`
36
+ opacity: 0;
37
+ pointer-events: none;
38
+ user-select: none;
39
+
40
+ ${typewriterCursorElement}
41
+ `;
42
+ export const StyledTypewriterText = styled.span`
43
+ color: inherit;
44
+ position: ${_ref3 => {
45
+ let {
46
+ $isAnimatingText
47
+ } = _ref3;
48
+ return $isAnimatingText ? 'absolute' : 'relative';
49
+ }};
50
+ width: 100%;
51
+
52
+ ${typewriterCursorElement}
53
+ `;
54
+ //# sourceMappingURL=Typewriter.styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Typewriter.styles.js","names":["styled","css","keyframes","StyledTypewriter","div","blinkAnimation","typewriterCursorElement","_ref","$isAnimatingText","$shouldHideCursor","_ref2","theme","text","StyledTypewriterPseudoText","span","StyledTypewriterText","_ref3"],"sources":["../../../../src/components/typewriter/Typewriter.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport styled, { css, keyframes } from 'styled-components';\n\nexport const StyledTypewriter = styled.div`\n align-items: inherit;\n display: flex;\n position: relative;\n width: 100%;\n`;\n\nconst blinkAnimation = keyframes`\n 100% {\n visibility: hidden;\n }\n`;\n\nconst typewriterCursorElement = ({\n $isAnimatingText,\n $shouldHideCursor,\n}: {\n $isAnimatingText?: boolean;\n $shouldHideCursor?: boolean;\n}) =>\n $isAnimatingText &&\n !$shouldHideCursor &&\n css`\n &:after {\n animation: ${blinkAnimation} 1s steps(5, start) infinite;\n color: ${({ theme }: StyledTypewriterTextProps) => theme.text};\n content: '▋';\n margin-left: 0.25rem;\n opacity: 0.85;\n position: relative;\n vertical-align: baseline;\n }\n `;\n\nexport const StyledTypewriterPseudoText = styled.span<StyledTypewriterTextProps>`\n opacity: 0;\n pointer-events: none;\n user-select: none;\n\n ${typewriterCursorElement}\n`;\n\ntype StyledTypewriterTextProps = WithTheme<{\n $isAnimatingText?: boolean;\n $shouldHideCursor?: boolean;\n}>;\n\nexport const StyledTypewriterText = styled.span<StyledTypewriterTextProps>`\n color: inherit;\n position: ${({ $isAnimatingText }) => ($isAnimatingText ? 'absolute' : 'relative')};\n width: 100%;\n\n ${typewriterCursorElement}\n`;\n"],"mappings":"AACA,OAAOA,MAAM,IAAIC,GAAG,EAAEC,SAAS,QAAQ,mBAAmB;AAE1D,OAAO,MAAMC,gBAAgB,GAAGH,MAAM,CAACI,GAAG;AAC1C;AACA;AACA;AACA;AACA,CAAC;AAED,MAAMC,cAAc,GAAGH,SAAS;AAChC;AACA;AACA;AACA,CAAC;AAED,MAAMI,uBAAuB,GAAGC,IAAA;EAAA,IAAC;IAC7BC,gBAAgB;IAChBC;EAIJ,CAAC,GAAAF,IAAA;EAAA,OACGC,gBAAgB,IAChB,CAACC,iBAAiB,IAClBR,GAAG;AACP;AACA,yBAAyBI,cAAc;AACvC,qBAAqBK,KAAA;IAAA,IAAC;MAAEC;IAAiC,CAAC,GAAAD,KAAA;IAAA,OAAKC,KAAK,CAACC,IAAI;EAAA;AACzE;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AAAA;AAEL,OAAO,MAAMC,0BAA0B,GAAGb,MAAM,CAACc,IAA+B;AAChF;AACA;AACA;AACA;AACA,MAAMR,uBAAuB;AAC7B,CAAC;AAOD,OAAO,MAAMS,oBAAoB,GAAGf,MAAM,CAACc,IAA+B;AAC1E;AACA,gBAAgBE,KAAA;EAAA,IAAC;IAAER;EAAiB,CAAC,GAAAQ,KAAA;EAAA,OAAMR,gBAAgB,GAAG,UAAU,GAAG,UAAU;AAAA,CAAC;AACtF;AACA;AACA,MAAMF,uBAAuB;AAC7B,CAAC","ignoreList":[]}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * This function extracts a part of the text from an HTML text. The HTML elements themselves are
3
+ * returned in the result. In addition, the function ensures that the closing tag of the Bold HTML
4
+ * element is also returned for text that is cut off in the middle of a Bold element, for example.
5
+ *
6
+ * @param html - The text from which a part should be taken
7
+ * @param length - The length of the text to be extracted
8
+ *
9
+ * @return string - The text part with the specified length - additionally the HTML elements are added
10
+ */
11
+ export const getSubTextFromHTML = (html, length) => {
12
+ const div = document.createElement('div');
13
+ div.innerHTML = html;
14
+ let text = '';
15
+ let currLength = 0;
16
+ const traverse = element => {
17
+ if (element.nodeType === 3 && typeof element.textContent === 'string') {
18
+ const nodeText = element.textContent;
19
+ if (currLength + nodeText.length <= length) {
20
+ text += nodeText;
21
+ currLength += nodeText.length;
22
+ } else {
23
+ text += nodeText.substring(0, length - currLength);
24
+ return false;
25
+ }
26
+ } else if (element.nodeType === 1) {
27
+ const nodeName = element.nodeName.toLowerCase();
28
+ let attributes = '';
29
+
30
+ // @ts-expect-error: Type is correct here
31
+ // eslint-disable-next-line no-restricted-syntax
32
+ for (const attribute of element.attributes) {
33
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/restrict-template-expressions
34
+ attributes += ` ${attribute.name}="${attribute.value}"`;
35
+ }
36
+ text += `<${nodeName}${attributes}>`;
37
+ for (let i = 0; i < element.childNodes.length; i++) {
38
+ const childNode = element.childNodes[i];
39
+ if (childNode && !traverse(childNode)) {
40
+ return false;
41
+ }
42
+ }
43
+ text += `</${nodeName}>`;
44
+ }
45
+ return true;
46
+ };
47
+ for (let i = 0; i < div.childNodes.length; i++) {
48
+ const childNode = div.childNodes[i];
49
+ if (childNode && !traverse(childNode)) {
50
+ return text;
51
+ }
52
+ }
53
+ return text;
54
+ };
55
+ export const getCharactersCount = html => {
56
+ const div = document.createElement('div');
57
+ div.innerHTML = html;
58
+ let count = 0;
59
+ const traverse = node => {
60
+ if (node.nodeType === 3 && typeof node.textContent === 'string') {
61
+ count += node.textContent.trim().length;
62
+ } else if (node.nodeType === 1) {
63
+ if (node.nodeName === 'CODE' && node.textContent !== null) {
64
+ count += node.textContent.length;
65
+ return;
66
+ }
67
+ Array.from(node.childNodes).forEach(traverse);
68
+ }
69
+ };
70
+ Array.from(div.childNodes).forEach(traverse);
71
+ return count;
72
+ };
73
+ export const shuffleArray = array => {
74
+ const result = Array.from(array);
75
+ for (let i = result.length - 1; i > 0; i--) {
76
+ const j = Math.floor(Math.random() * (i + 1));
77
+ [result[i], result[j]] = [result[j], result[i]];
78
+ }
79
+ return result;
80
+ };
81
+ //# 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","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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AO,CAACrB,QAAQ,CAAC;EAE5C,OAAOgB,KAAK;AAChB,CAAC;AAED,OAAO,MAAMM,YAAY,GAAOC,KAAU,IAAU;EAChD,MAAMC,MAAM,GAAGL,KAAK,CAACC,IAAI,CAACG,KAAK,CAAC;EAEhC,KAAK,IAAIX,CAAC,GAAGY,MAAM,CAAC/B,MAAM,GAAG,CAAC,EAAEmB,CAAC,GAAG,CAAC,EAAEA,CAAC,EAAE,EAAE;IACxC,MAAMa,CAAC,GAAGC,IAAI,CAACC,KAAK,CAACD,IAAI,CAACE,MAAM,CAAC,CAAC,IAAIhB,CAAC,GAAG,CAAC,CAAC,CAAC;IAE7C,CAACY,MAAM,CAACZ,CAAC,CAAC,EAAEY,MAAM,CAACC,CAAC,CAAC,CAAC,GAAG,CAACD,MAAM,CAACC,CAAC,CAAC,EAAGD,MAAM,CAACZ,CAAC,CAAC,CAAE;EACrD;EAEA,OAAOY,MAAM;AACjB,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export { default as Typewriter, TypewriterSpeed } from './components/typewriter/Typewriter';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
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","ignoreList":[]}
@@ -0,0 +1,69 @@
1
+ import React, { FC, ReactElement } from 'react';
2
+ export declare enum TypewriterResetDelay {
3
+ Slow = 4000,
4
+ Medium = 2000,
5
+ Fast = 1000
6
+ }
7
+ export declare enum TypewriterSpeed {
8
+ Slow = 30,
9
+ Medium = 20,
10
+ Fast = 10
11
+ }
12
+ export type TypewriterProps = {
13
+ /**
14
+ * The text to type
15
+ */
16
+ children: ReactElement | ReactElement[] | string | string[];
17
+ /**
18
+ * Function that is executed when the typewriter animation has finished. This function will not
19
+ * be executed if multiple texts are used.
20
+ */
21
+ onFinish?: VoidFunction;
22
+ /**
23
+ * Pseudo-element to be rendered invisible during animation to define the size of the element
24
+ * for the typewriter effect. By default, the "children" is used for this purpose.
25
+ */
26
+ pseudoChildren?: ReactElement | string;
27
+ /**
28
+ * Waiting time before the typewriter resets the content if multiple texts are given
29
+ */
30
+ resetDelay?: TypewriterResetDelay;
31
+ /**
32
+ * Specifies whether the cursor should be forced to animate even if no text is currently animated.
33
+ */
34
+ shouldForceCursorAnimation?: boolean;
35
+ /**
36
+ * Specifies whether the cursor should be hidden
37
+ */
38
+ shouldHideCursor?: boolean;
39
+ /**
40
+ * Specifies whether the children should be sorted randomly if there are multiple texts.
41
+ * This makes the typewriter start with a different text each time and also changes them
42
+ * in a random order.
43
+ */
44
+ shouldSortChildrenRandomly?: boolean;
45
+ /**
46
+ * Specifies whether the animation should use its full height or the height of the current
47
+ * chunk.
48
+ */
49
+ shouldUseAnimationHeight?: boolean;
50
+ /**
51
+ * Specifies whether the reset of the text should be animated with a backspace animation for
52
+ * multiple texts.
53
+ */
54
+ shouldUseResetAnimation?: boolean;
55
+ /**
56
+ * Whether the typewriter should wait for new content
57
+ */
58
+ shouldWaitForContent?: boolean;
59
+ /**
60
+ * The speed of the animation. Use the TypewriterSpeed enum for this prop.
61
+ */
62
+ speed?: TypewriterSpeed | number;
63
+ /**
64
+ * The style of the typewriter text element
65
+ */
66
+ textStyle?: React.CSSProperties;
67
+ };
68
+ declare const Typewriter: FC<TypewriterProps>;
69
+ export default Typewriter;
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import type { WithTheme } from '@chayns-components/core';
3
+ export declare const StyledTypewriter: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
4
+ export declare const StyledTypewriterPseudoText: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, StyledTypewriterTextProps>> & string;
5
+ type StyledTypewriterTextProps = WithTheme<{
6
+ $isAnimatingText?: boolean;
7
+ $shouldHideCursor?: boolean;
8
+ }>;
9
+ export declare const StyledTypewriterText: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, StyledTypewriterTextProps>> & string;
10
+ export {};
@@ -10,3 +10,4 @@
10
10
  */
11
11
  export declare const getSubTextFromHTML: (html: string, length: number) => string;
12
12
  export declare const getCharactersCount: (html: string) => number;
13
+ export declare const shuffleArray: <T>(array: T[]) => T[];
package/package.json CHANGED
@@ -1,7 +1,14 @@
1
1
  {
2
2
  "name": "@chayns-components/typewriter",
3
- "version": "5.0.0-beta.66",
3
+ "version": "5.0.0-beta.661",
4
4
  "description": "A set of beautiful React components for developing your own applications with chayns.",
5
+ "sideEffects": false,
6
+ "browserslist": [
7
+ ">0.5%",
8
+ "not dead",
9
+ "not op_mini all",
10
+ "not IE 11"
11
+ ],
5
12
  "keywords": [
6
13
  "chayns",
7
14
  "react",
@@ -10,8 +17,16 @@
10
17
  "author": "Tobit.Software",
11
18
  "homepage": "https://github.com/TobitSoftware/chayns-components/tree/main/packages/typewriter#readme",
12
19
  "license": "MIT",
13
- "main": "lib/index.js",
14
- "types": "lib/index.d.ts",
20
+ "main": "lib/cjs/index.js",
21
+ "module": "lib/esm/index.js",
22
+ "types": "lib/types/index.d.ts",
23
+ "exports": {
24
+ ".": {
25
+ "require": "./lib/cjs/index.js",
26
+ "import": "./lib/esm/index.js",
27
+ "types": "./lib/types/index.d.ts"
28
+ }
29
+ },
15
30
  "directories": {
16
31
  "lib": "lib",
17
32
  "test": "__tests__"
@@ -24,44 +39,45 @@
24
39
  "url": "git+https://github.com/TobitSoftware/chayns-components.git"
25
40
  },
26
41
  "scripts": {
27
- "build": "npm run build:js && npm run build:types",
28
- "build:js": "babel src --out-dir lib --extensions=.ts,.tsx --source-maps --ignore=src/stories",
42
+ "build": "npm run build:cjs && npm run build:esm && npm run build:types",
29
43
  "build:types": "tsc",
44
+ "build:cjs": "cross-env NODE_ENV=cjs babel src --out-dir lib/cjs --extensions=.ts,.tsx --source-maps --ignore=src/stories",
45
+ "build:esm": "cross-env NODE_ENV=esm babel src --out-dir lib/esm --extensions=.ts,.tsx --source-maps --ignore=src/stories",
30
46
  "prepublishOnly": "npm run build"
31
47
  },
32
48
  "bugs": {
33
49
  "url": "https://github.com/TobitSoftware/chayns-components/issues"
34
50
  },
35
51
  "devDependencies": {
36
- "@babel/cli": "^7.21.0",
37
- "@babel/core": "^7.21.0",
38
- "@babel/preset-env": "^7.20.2",
39
- "@babel/preset-react": "^7.18.6",
40
- "@babel/preset-typescript": "^7.21.0",
41
- "@types/react": "^17.0.53",
42
- "@types/react-dom": "^17.0.19",
43
- "@types/styled-components": "^5.1.26",
44
- "@types/uuid": "^9.0.0",
45
- "babel-loader": "^8.3.0",
46
- "lerna": "^6.5.1",
47
- "react": "^17.0.2",
48
- "react-dom": "^17.0.2",
49
- "typescript": "^4.9.5"
52
+ "@babel/cli": "^7.24.6",
53
+ "@babel/core": "^7.24.6",
54
+ "@babel/preset-env": "^7.24.6",
55
+ "@babel/preset-react": "^7.24.6",
56
+ "@babel/preset-typescript": "^7.24.6",
57
+ "@types/react": "^18.3.3",
58
+ "@types/react-dom": "^18.3.0",
59
+ "@types/styled-components": "^5.1.34",
60
+ "@types/uuid": "^9.0.8",
61
+ "babel-loader": "^9.1.3",
62
+ "cross-env": "^7.0.3",
63
+ "lerna": "^8.1.3",
64
+ "react": "^18.3.1",
65
+ "react-dom": "^18.3.1",
66
+ "styled-components": "^6.1.11",
67
+ "typescript": "^5.4.5"
50
68
  },
51
69
  "dependencies": {
52
- "@chayns-components/core": "^5.0.0-beta.66",
53
- "@chayns/colors": "^2.0.0",
54
- "clsx": "^1.2.1",
55
- "framer-motion": "^6.5.1",
56
- "styled-components": "^5.3.6",
57
- "uuid": "^9.0.0"
70
+ "@chayns-components/core": "^5.0.0-beta.661"
58
71
  },
59
72
  "peerDependencies": {
73
+ "chayns-api": ">=1.0.50",
74
+ "framer-motion": ">=10.18.0",
60
75
  "react": ">=16.14.0",
61
- "react-dom": ">=16.14.0"
76
+ "react-dom": ">=16.14.0",
77
+ "styled-components": ">=5.3.11"
62
78
  },
63
79
  "publishConfig": {
64
80
  "access": "public"
65
81
  },
66
- "gitHead": "f876f20f2a14ef7d6db38205c18fe3554a503e16"
82
+ "gitHead": "abed9a83e68e93e9c80d3ee9c2363186fbabd502"
67
83
  }
@@ -1,15 +0,0 @@
1
- import { FC, ReactElement } from 'react';
2
- export declare enum TypewriterSpeed {
3
- Slow = 40,
4
- Medium = 30,
5
- Fast = 20
6
- }
7
- export type TypewriterProps = {
8
- /**
9
- * The text to type
10
- */
11
- children: ReactElement | string;
12
- speed?: TypewriterSpeed;
13
- };
14
- declare const Typewriter: FC<TypewriterProps>;
15
- export default Typewriter;
@@ -1,77 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.TypewriterSpeed = 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(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
- let TypewriterSpeed;
14
- exports.TypewriterSpeed = TypewriterSpeed;
15
- (function (TypewriterSpeed) {
16
- TypewriterSpeed[TypewriterSpeed["Slow"] = 40] = "Slow";
17
- TypewriterSpeed[TypewriterSpeed["Medium"] = 30] = "Medium";
18
- TypewriterSpeed[TypewriterSpeed["Fast"] = 20] = "Fast";
19
- })(TypewriterSpeed || (exports.TypewriterSpeed = TypewriterSpeed = {}));
20
- const Typewriter = _ref => {
21
- let {
22
- children,
23
- speed = TypewriterSpeed.Medium
24
- } = _ref;
25
- const textContent = /*#__PURE__*/_react.default.isValidElement(children) ? (0, _server.renderToString)(children) : children;
26
- const charactersCount = (0, _react.useMemo)(() => (0, _utils.getCharactersCount)(textContent), [textContent]);
27
- const [shownCharCount, setShownCharCount] = (0, _react.useState)(charactersCount > 0 ? 0 : textContent.length);
28
- const [shouldStopAnimation, setShouldStopAnimation] = (0, _react.useState)(false);
29
- const isAnimatingText = shownCharCount !== textContent.length;
30
- const handleClick = (0, _react.useCallback)(() => {
31
- setShouldStopAnimation(true);
32
- }, []);
33
- (0, _react.useEffect)(() => {
34
- let interval;
35
- if (shouldStopAnimation || charactersCount === 0) {
36
- setShownCharCount(textContent.length);
37
- } else {
38
- setShownCharCount(0);
39
- interval = window.setInterval(() => {
40
- setShownCharCount(prevState => {
41
- let nextState = prevState + 1;
42
- if (nextState === charactersCount) {
43
- window.clearInterval(interval);
44
-
45
- /**
46
- * At this point, the next value for "shownCharCount" is deliberately set to
47
- * the length of the textContent in order to correctly display HTML elements
48
- * after the last letter.
49
- */
50
- nextState = textContent.length;
51
- }
52
- return nextState;
53
- });
54
- }, speed);
55
- }
56
- return () => {
57
- window.clearInterval(interval);
58
- };
59
- }, [shouldStopAnimation, speed, textContent.length, charactersCount]);
60
- const shownText = (0, _react.useMemo)(() => (0, _utils.getSubTextFromHTML)(textContent, shownCharCount), [shownCharCount, textContent]);
61
- return /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriter, {
62
- onClick: handleClick
63
- }, isAnimatingText ? /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriterText, {
64
- dangerouslySetInnerHTML: {
65
- __html: shownText
66
- },
67
- isAnimatingText: true
68
- }) : /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriterText, null, children), isAnimatingText && /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriterPseudoText, {
69
- dangerouslySetInnerHTML: {
70
- __html: textContent
71
- }
72
- }));
73
- };
74
- Typewriter.displayName = 'Typewriter';
75
- var _default = Typewriter;
76
- exports.default = _default;
77
- //# sourceMappingURL=Typewriter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Typewriter.js","names":["_react","_interopRequireWildcard","require","_server","_Typewriter","_utils","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","TypewriterSpeed","exports","Typewriter","_ref","children","speed","Medium","textContent","React","isValidElement","renderToString","charactersCount","useMemo","getCharactersCount","shownCharCount","setShownCharCount","useState","length","shouldStopAnimation","setShouldStopAnimation","isAnimatingText","handleClick","useCallback","useEffect","interval","window","setInterval","prevState","nextState","clearInterval","shownText","getSubTextFromHTML","createElement","StyledTypewriter","onClick","StyledTypewriterText","dangerouslySetInnerHTML","__html","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 } from './utils';\n\nexport enum TypewriterSpeed {\n Slow = 40,\n Medium = 30,\n Fast = 20,\n}\n\nexport type TypewriterProps = {\n /**\n * The text to type\n */\n children: ReactElement | string;\n speed?: TypewriterSpeed;\n};\n\nconst Typewriter: FC<TypewriterProps> = ({ children, speed = TypewriterSpeed.Medium }) => {\n const textContent = React.isValidElement(children) ? renderToString(children) : children;\n\n const charactersCount = useMemo(() => getCharactersCount(textContent), [textContent]);\n\n const [shownCharCount, setShownCharCount] = useState(\n charactersCount > 0 ? 0 : textContent.length\n );\n const [shouldStopAnimation, setShouldStopAnimation] = useState(false);\n\n const isAnimatingText = shownCharCount !== textContent.length;\n\n const handleClick = useCallback(() => {\n setShouldStopAnimation(true);\n }, []);\n\n useEffect(() => {\n let interval: number | undefined;\n\n if (shouldStopAnimation || charactersCount === 0) {\n setShownCharCount(textContent.length);\n } else {\n setShownCharCount(0);\n\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\n return nextState;\n });\n }, speed);\n }\n\n return () => {\n window.clearInterval(interval);\n };\n }, [shouldStopAnimation, speed, textContent.length, charactersCount]);\n\n const shownText = useMemo(\n () => getSubTextFromHTML(textContent, shownCharCount),\n [shownCharCount, textContent]\n );\n\n return (\n <StyledTypewriter onClick={handleClick}>\n {isAnimatingText ? (\n <StyledTypewriterText\n dangerouslySetInnerHTML={{ __html: shownText }}\n isAnimatingText\n />\n ) : (\n <StyledTypewriterText>{children}</StyledTypewriterText>\n )}\n {isAnimatingText && (\n <StyledTypewriterPseudoText dangerouslySetInnerHTML={{ __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E,EAChF,CACc;AAE3B,CAAC;AAEDL,UAAU,CAACqC,WAAW,GAAG,YAAY;AAAC,IAAAC,QAAA,GAEvBtC,UAAU;AAAAD,OAAA,CAAAhB,OAAA,GAAAuD,QAAA"}
@@ -1,7 +0,0 @@
1
- export declare const StyledTypewriter: import("styled-components").StyledComponent<"div", any, {}, never>;
2
- export declare const StyledTypewriterPseudoText: import("styled-components").StyledComponent<"span", any, {}, never>;
3
- export declare const StyledTypewriterText: import("styled-components").StyledComponent<"span", any, {
4
- isAnimatingText?: boolean | undefined;
5
- } & {
6
- theme: import("@chayns-components/core/lib/components/color-scheme-provider/ColorSchemeProvider").Theme;
7
- }, never>;
@@ -1,62 +0,0 @@
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(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
9
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
10
- const StyledTypewriter = _styledComponents.default.div`
11
- position: relative;
12
- `;
13
- exports.StyledTypewriter = StyledTypewriter;
14
- const blinkAnimation = (0, _styledComponents.keyframes)`
15
- 100% {
16
- visibility: hidden;
17
- }
18
- `;
19
- const StyledTypewriterPseudoText = _styledComponents.default.span`
20
- opacity: 0;
21
- pointer-events: none;
22
- user-select: none;
23
- `;
24
- exports.StyledTypewriterPseudoText = StyledTypewriterPseudoText;
25
- const StyledTypewriterText = _styledComponents.default.span`
26
- color: ${_ref => {
27
- let {
28
- theme
29
- } = _ref;
30
- return theme.text;
31
- }};
32
- position: ${_ref2 => {
33
- let {
34
- isAnimatingText
35
- } = _ref2;
36
- return isAnimatingText ? 'absolute' : 'relative';
37
- }};
38
- width: 100%;
39
-
40
- ${_ref3 => {
41
- let {
42
- isAnimatingText
43
- } = _ref3;
44
- return isAnimatingText && (0, _styledComponents.css)`
45
- &:after {
46
- animation: ${blinkAnimation} 1s steps(5, start) infinite;
47
- color: ${_ref4 => {
48
- let {
49
- theme
50
- } = _ref4;
51
- return theme.text;
52
- }};
53
- content: '▋';
54
- margin-left: 0.25rem;
55
- opacity: 0.85;
56
- vertical-align: baseline;
57
- }
58
- `;
59
- }}
60
- `;
61
- exports.StyledTypewriterText = StyledTypewriterText;
62
- //# sourceMappingURL=Typewriter.styles.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Typewriter.styles.js","names":["_styledComponents","_interopRequireWildcard","require","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","StyledTypewriter","styled","div","exports","blinkAnimation","keyframes","StyledTypewriterPseudoText","span","StyledTypewriterText","_ref","theme","text","_ref2","isAnimatingText","_ref3","css","_ref4"],"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 position: relative;\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}>;\n\nexport const StyledTypewriterText = styled.span<StyledTypewriterTextProps>`\n color: ${({ theme }: StyledTypewriterTextProps) => theme.text};\n position: ${({ isAnimatingText }) => (isAnimatingText ? 'absolute' : 'relative')};\n width: 100%;\n\n ${({ isAnimatingText }) =>\n isAnimatingText &&\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 vertical-align: baseline;\n }\n `}\n`;\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,uBAAA,CAAAC,OAAA;AAA2D,SAAAC,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAH,wBAAAO,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,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GAAAM,KAAA;IAAA,OAAKN,KAAK,CAACC,IAAI;EAAA,CAAC;AAC9E;AACA;AACA;AACA;AACA;AACA,SAAS;AAAA,CAAC;AACV,CAAC;AAACR,OAAA,CAAAK,oBAAA,GAAAA,oBAAA"}
@@ -1 +0,0 @@
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"],"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 Array.from(node.childNodes).forEach(traverse);\n }\n };\n\n Array.from(div.childNodes).forEach(traverse);\n\n return count;\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,QAAQ,KAAK,CAAC,EAAE;MAC/B,MAAMI,QAAQ,GAAGL,OAAO,CAACK,QAAQ,CAACC,WAAW,EAAE;MAE/C,IAAIC,UAAU,G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