@chayns-components/typewriter 5.0.0-beta.97 → 5.0.0-beta.971
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.
- package/README.md +4 -15
- package/lib/cjs/components/typewriter/AnimatedTypewriterText.js +59 -0
- package/lib/cjs/components/typewriter/AnimatedTypewriterText.js.map +1 -0
- package/lib/cjs/components/typewriter/Typewriter.js +273 -0
- package/lib/cjs/components/typewriter/Typewriter.js.map +1 -0
- package/lib/cjs/components/typewriter/Typewriter.styles.js +96 -0
- package/lib/cjs/components/typewriter/Typewriter.styles.js.map +1 -0
- package/lib/{components → cjs/components}/typewriter/utils.js +43 -3
- package/lib/cjs/components/typewriter/utils.js.map +1 -0
- package/lib/cjs/index.js +34 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/types/cursor.js +12 -0
- package/lib/cjs/types/cursor.js.map +1 -0
- package/lib/cjs/types/speed.js +25 -0
- package/lib/cjs/types/speed.js.map +1 -0
- package/lib/esm/components/typewriter/AnimatedTypewriterText.js +51 -0
- package/lib/esm/components/typewriter/AnimatedTypewriterText.js.map +1 -0
- package/lib/esm/components/typewriter/Typewriter.js +265 -0
- package/lib/esm/components/typewriter/Typewriter.js.map +1 -0
- package/lib/esm/components/typewriter/Typewriter.styles.js +101 -0
- package/lib/esm/components/typewriter/Typewriter.styles.js.map +1 -0
- package/lib/esm/components/typewriter/utils.js +108 -0
- package/lib/esm/components/typewriter/utils.js.map +1 -0
- package/lib/esm/index.js +4 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/types/cursor.js +6 -0
- package/lib/esm/types/cursor.js.map +1 -0
- package/lib/esm/types/speed.js +21 -0
- package/lib/esm/types/speed.js.map +1 -0
- package/lib/types/components/typewriter/AnimatedTypewriterText.d.ts +8 -0
- package/lib/types/components/typewriter/Typewriter.d.ts +111 -0
- package/lib/types/components/typewriter/Typewriter.styles.d.ts +19 -0
- package/lib/{components → types/components}/typewriter/utils.d.ts +11 -0
- package/lib/types/index.d.ts +3 -0
- package/lib/types/types/cursor.d.ts +4 -0
- package/lib/types/types/speed.d.ts +15 -0
- package/package.json +46 -28
- package/lib/components/typewriter/Typewriter.d.ts +0 -27
- package/lib/components/typewriter/Typewriter.js +0 -128
- package/lib/components/typewriter/Typewriter.js.map +0 -1
- package/lib/components/typewriter/Typewriter.styles.d.ts +0 -7
- package/lib/components/typewriter/Typewriter.styles.js +0 -62
- package/lib/components/typewriter/Typewriter.styles.js.map +0 -1
- package/lib/components/typewriter/utils.js.map +0 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -21
- package/lib/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
</h1>
|
|
5
5
|
<p>A set of beautiful React components for developing your own applications with chayns.</p>
|
|
6
6
|
<div>
|
|
7
|
-
<img src="https://img.shields.io/npm/dm/@chayns-components/
|
|
8
|
-
<img src="https://img.shields.io/npm/v/@chayns-components/
|
|
7
|
+
<img src="https://img.shields.io/npm/dm/@chayns-components/core.svg?style=for-the-badge" alt="" />
|
|
8
|
+
<img src="https://img.shields.io/npm/v/@chayns-components/core?style=for-the-badge" alt="" />
|
|
9
9
|
<img src="https://img.shields.io/github/license/TobitSoftware/chayns-components?style=for-the-badge" alt="" />
|
|
10
10
|
<img src="https://img.shields.io/github/contributors/TobitSoftware/chayns-components?style=for-the-badge" alt="" />
|
|
11
11
|
</div>
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
## Installation
|
|
17
17
|
|
|
18
|
-
First you need to install the
|
|
18
|
+
First you need to install the core part of the chayns-components.
|
|
19
19
|
|
|
20
20
|
```bash
|
|
21
21
|
# NPM
|
|
@@ -31,15 +31,4 @@ yarn add @chayns-components/typewriter
|
|
|
31
31
|
|
|
32
32
|
## Usage
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
```typescript jsx
|
|
37
|
-
import { Typewriter } from '@chayns-components/typewriter';
|
|
38
|
-
|
|
39
|
-
<Typewriter>
|
|
40
|
-
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt
|
|
41
|
-
ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo
|
|
42
|
-
dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est. Lorem ipsum dolor
|
|
43
|
-
sit amet.
|
|
44
|
-
</Typewriter>;
|
|
45
|
-
```
|
|
34
|
+
For detailed usage visit the [storybook](https://components.chayns.site/storybook).
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _Typewriter = require("./Typewriter.styles");
|
|
9
|
+
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); }
|
|
10
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
|
+
const AnimatedTypewriterText = ({
|
|
12
|
+
shouldHideCursor,
|
|
13
|
+
shownText,
|
|
14
|
+
textStyle
|
|
15
|
+
}) => {
|
|
16
|
+
const updateTypewriterCursor = (0, _react.useCallback)(ref => {
|
|
17
|
+
if (ref && !shouldHideCursor) {
|
|
18
|
+
// Finds the last text node with content.
|
|
19
|
+
const traverseNodes = node => {
|
|
20
|
+
var _node$textContent;
|
|
21
|
+
if (node.nodeType === Node.TEXT_NODE && (_node$textContent = node.textContent) !== null && _node$textContent !== void 0 && _node$textContent.trim()) {
|
|
22
|
+
return node.parentElement;
|
|
23
|
+
}
|
|
24
|
+
const childNodes = Array.from(node.childNodes);
|
|
25
|
+
for (let i = childNodes.length - 1; i >= 0; i--) {
|
|
26
|
+
const result = traverseNodes(childNodes[i]);
|
|
27
|
+
if (result) {
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
};
|
|
33
|
+
const lastParentWithContent = traverseNodes(ref);
|
|
34
|
+
|
|
35
|
+
// Removes lastWithContent class from all elements
|
|
36
|
+
ref.classList.remove('typewriter-lastWithContent');
|
|
37
|
+
ref.querySelectorAll('.lastWithContent').forEach(element => {
|
|
38
|
+
element.classList.remove('typewriter-lastWithContent');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Adds lastWithContent class to the last element with content
|
|
42
|
+
if (lastParentWithContent) {
|
|
43
|
+
lastParentWithContent.classList.add('typewriter-lastWithContent');
|
|
44
|
+
} else {
|
|
45
|
+
ref.classList.add('typewriter-lastWithContent');
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}, [shouldHideCursor]);
|
|
49
|
+
return (0, _react.useMemo)(() => /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriterText, {
|
|
50
|
+
ref: ref => updateTypewriterCursor(ref),
|
|
51
|
+
dangerouslySetInnerHTML: {
|
|
52
|
+
__html: shownText
|
|
53
|
+
},
|
|
54
|
+
style: textStyle,
|
|
55
|
+
$isAnimatingText: true
|
|
56
|
+
}), [updateTypewriterCursor, shownText, textStyle]);
|
|
57
|
+
};
|
|
58
|
+
var _default = exports.default = AnimatedTypewriterText;
|
|
59
|
+
//# sourceMappingURL=AnimatedTypewriterText.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AnimatedTypewriterText.js","names":["_react","_interopRequireWildcard","require","_Typewriter","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","AnimatedTypewriterText","shouldHideCursor","shownText","textStyle","updateTypewriterCursor","useCallback","ref","traverseNodes","node","_node$textContent","nodeType","Node","TEXT_NODE","textContent","trim","parentElement","childNodes","Array","from","length","result","lastParentWithContent","classList","remove","querySelectorAll","forEach","element","add","useMemo","createElement","StyledTypewriterText","dangerouslySetInnerHTML","__html","style","$isAnimatingText","_default","exports"],"sources":["../../../../src/components/typewriter/AnimatedTypewriterText.tsx"],"sourcesContent":["import React, {FC, useCallback, useEffect, useMemo, useRef} from 'react';\nimport {StyledTypewriterText} from \"./Typewriter.styles\";\n\ntype AnimatedTypewriterTextProps = {\n shouldHideCursor: boolean;\n shownText: string;\n textStyle?: React.CSSProperties;\n};\n\nconst AnimatedTypewriterText: FC<AnimatedTypewriterTextProps> = ({\n shouldHideCursor,\n shownText,\n textStyle\n}) => {\n const updateTypewriterCursor = useCallback((ref: HTMLSpanElement | null) => {\n if (ref && !shouldHideCursor) {\n // Finds the last text node with content.\n const traverseNodes = (node: Node): HTMLElement | null => {\n if (node.nodeType === Node.TEXT_NODE && node.textContent?.trim()) {\n return node.parentElement;\n }\n\n const childNodes = Array.from(node.childNodes);\n for (let i = childNodes.length - 1; i >= 0; i--) {\n const result = traverseNodes(childNodes[i] as Node);\n if (result) {\n return result;\n }\n }\n\n return null;\n }\n\n const lastParentWithContent = traverseNodes(ref);\n\n // Removes lastWithContent class from all elements\n ref.classList.remove('typewriter-lastWithContent');\n ref.querySelectorAll('.lastWithContent').forEach(element => {\n element.classList.remove('typewriter-lastWithContent');\n });\n\n // Adds lastWithContent class to the last element with content\n if (lastParentWithContent) {\n lastParentWithContent.classList.add('typewriter-lastWithContent');\n } else {\n ref.classList.add('typewriter-lastWithContent');\n }\n }\n }, [shouldHideCursor]);\n\n return useMemo(() => (\n <StyledTypewriterText\n ref={(ref) => updateTypewriterCursor(ref)}\n dangerouslySetInnerHTML={{ __html: shownText }}\n style={textStyle}\n $isAnimatingText\n />\n ), [updateTypewriterCursor, shownText, textStyle]);\n};\n\nexport default AnimatedTypewriterText;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAAyD,SAAAE,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,SAAAJ,wBAAAI,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAG,CAAA,KAAAA,CAAA,CAAAV,GAAA,IAAAU,CAAA,CAAAC,GAAA,IAAAP,MAAA,CAAAC,cAAA,CAAAJ,CAAA,EAAAM,CAAA,EAAAG,CAAA,IAAAT,CAAA,CAAAM,CAAA,IAAAd,CAAA,CAA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AAIF,qBAAqB,EAAE;QACvBA,qBAAqB,CAACC,SAAS,CAACK,GAAG,CAAC,4BAA4B,CAAC;MACrE,CAAC,MAAM;QACHrB,GAAG,CAACgB,SAAS,CAACK,GAAG,CAAC,4BAA4B,CAAC;MACnD;IACJ;EACJ,CAAC,EAAE,CAAC1B,gBAAgB,CAAC,CAAC;EAEtB,OAAO,IAAA2B,cAAO,EAAC,mBACXpD,MAAA,CAAAU,OAAA,CAAA2C,aAAA,CAAClD,WAAA,CAAAmD,oBAAoB;IACjBxB,GAAG,EAAGA,GAAG,IAAKF,sBAAsB,CAACE,GAAG,CAAE;IAC1CyB,uBAAuB,EAAE;MAAEC,MAAM,EAAE9B;IAAU,CAAE;IAC/C+B,KAAK,EAAE9B,SAAU;IACjB+B,gBAAgB;EAAA,CACnB,CACJ,EAAE,CAAC9B,sBAAsB,EAAEF,SAAS,EAAEC,SAAS,CAAC,CAAC;AACtD,CAAC;AAAC,IAAAgC,QAAA,GAAAC,OAAA,CAAAlD,OAAA,GAEac,sBAAsB","ignoreList":[]}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _core = require("@chayns-components/core");
|
|
8
|
+
var _chaynsApi = require("chayns-api");
|
|
9
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _reactDom = require("react-dom");
|
|
11
|
+
var _server = require("react-dom/server");
|
|
12
|
+
var _cursor = require("../../types/cursor");
|
|
13
|
+
var _speed = require("../../types/speed");
|
|
14
|
+
var _AnimatedTypewriterText = _interopRequireDefault(require("./AnimatedTypewriterText"));
|
|
15
|
+
var _Typewriter = require("./Typewriter.styles");
|
|
16
|
+
var _utils = require("./utils");
|
|
17
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
+
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); }
|
|
19
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
20
|
+
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? _react.useLayoutEffect : _react.useEffect;
|
|
21
|
+
const Typewriter = ({
|
|
22
|
+
children,
|
|
23
|
+
cursorType = _cursor.CursorType.Default,
|
|
24
|
+
nextTextDelay = _speed.TypewriterDelay.Medium,
|
|
25
|
+
onFinish,
|
|
26
|
+
onResetAnimationEnd,
|
|
27
|
+
animationSteps = 1,
|
|
28
|
+
onResetAnimationStart,
|
|
29
|
+
onTypingAnimationEnd,
|
|
30
|
+
onTypingAnimationStart,
|
|
31
|
+
pseudoChildren,
|
|
32
|
+
resetDelay = _speed.TypewriterDelay.Medium,
|
|
33
|
+
shouldForceCursorAnimation = false,
|
|
34
|
+
shouldHideCursor = false,
|
|
35
|
+
shouldSortChildrenRandomly = false,
|
|
36
|
+
shouldUseAnimationHeight = false,
|
|
37
|
+
shouldUseResetAnimation = false,
|
|
38
|
+
shouldWaitForContent,
|
|
39
|
+
speed = _speed.TypewriterSpeed.Medium,
|
|
40
|
+
resetSpeed = speed,
|
|
41
|
+
startDelay = _speed.TypewriterDelay.None,
|
|
42
|
+
textStyle,
|
|
43
|
+
shouldCalcAutoSpeed = false,
|
|
44
|
+
autoSpeedBaseFactor = 2000
|
|
45
|
+
}) => {
|
|
46
|
+
const [currentChildrenIndex, setCurrentChildrenIndex] = (0, _react.useState)(0);
|
|
47
|
+
const [hasRenderedChildrenOnce, setHasRenderedChildrenOnce] = (0, _react.useState)(false);
|
|
48
|
+
const [shouldPreventBlinkingCursor, setShouldPreventBlinkingCursor] = (0, _react.useState)(false);
|
|
49
|
+
const [isResetAnimationActive, setIsResetAnimationActive] = (0, _react.useState)(false);
|
|
50
|
+
const [shouldStopAnimation, setShouldStopAnimation] = (0, _react.useState)(false);
|
|
51
|
+
const [autoSpeed, setAutoSpeed] = (0, _react.useState)();
|
|
52
|
+
const [autoSteps, setAutoSteps] = (0, _react.useState)(animationSteps);
|
|
53
|
+
const functions = (0, _chaynsApi.useFunctions)();
|
|
54
|
+
const values = (0, _chaynsApi.useValues)();
|
|
55
|
+
useIsomorphicLayoutEffect(() => {
|
|
56
|
+
if (children) {
|
|
57
|
+
setHasRenderedChildrenOnce(false);
|
|
58
|
+
}
|
|
59
|
+
}, [children]);
|
|
60
|
+
(0, _react.useEffect)(() => {
|
|
61
|
+
if (!hasRenderedChildrenOnce) {
|
|
62
|
+
setHasRenderedChildrenOnce(true);
|
|
63
|
+
}
|
|
64
|
+
}, [hasRenderedChildrenOnce]);
|
|
65
|
+
(0, _react.useEffect)(() => {
|
|
66
|
+
if (animationSteps > 0 && !shouldCalcAutoSpeed) {
|
|
67
|
+
setAutoSteps(animationSteps);
|
|
68
|
+
}
|
|
69
|
+
}, [animationSteps, shouldCalcAutoSpeed]);
|
|
70
|
+
const sortedChildren = (0, _react.useMemo)(() => Array.isArray(children) && shouldSortChildrenRandomly ? (0, _utils.shuffleArray)(children) : children, [children, shouldSortChildrenRandomly]);
|
|
71
|
+
const areMultipleChildrenGiven = Array.isArray(sortedChildren);
|
|
72
|
+
const childrenCount = areMultipleChildrenGiven ? sortedChildren.length : 1;
|
|
73
|
+
const textContent = (0, _react.useMemo)(() => {
|
|
74
|
+
if (areMultipleChildrenGiven) {
|
|
75
|
+
const currentChildren = sortedChildren[currentChildrenIndex];
|
|
76
|
+
if (currentChildren) {
|
|
77
|
+
return /*#__PURE__*/_react.default.isValidElement(currentChildren) ? (0, _server.renderToString)(/*#__PURE__*/_react.default.createElement(_chaynsApi.ChaynsProvider, {
|
|
78
|
+
data: values,
|
|
79
|
+
functions: functions,
|
|
80
|
+
isModule: true
|
|
81
|
+
}, /*#__PURE__*/_react.default.createElement(_core.ColorSchemeProvider, {
|
|
82
|
+
color: "#005EB8",
|
|
83
|
+
colorMode: 0,
|
|
84
|
+
style: {
|
|
85
|
+
display: 'inline'
|
|
86
|
+
}
|
|
87
|
+
}, currentChildren))) : currentChildren;
|
|
88
|
+
}
|
|
89
|
+
return '';
|
|
90
|
+
}
|
|
91
|
+
return /*#__PURE__*/_react.default.isValidElement(sortedChildren) ? (0, _server.renderToString)(/*#__PURE__*/_react.default.createElement(_chaynsApi.ChaynsProvider, {
|
|
92
|
+
data: values,
|
|
93
|
+
functions: functions,
|
|
94
|
+
isModule: true
|
|
95
|
+
}, /*#__PURE__*/_react.default.createElement(_core.ColorSchemeProvider, {
|
|
96
|
+
color: "#005EB8",
|
|
97
|
+
colorMode: 0,
|
|
98
|
+
style: {
|
|
99
|
+
display: 'inline'
|
|
100
|
+
}
|
|
101
|
+
}, sortedChildren))) : sortedChildren;
|
|
102
|
+
}, [areMultipleChildrenGiven, currentChildrenIndex, functions, sortedChildren, values]);
|
|
103
|
+
const charactersCount = (0, _react.useMemo)(() => (0, _utils.getCharactersCount)(textContent), [textContent]);
|
|
104
|
+
const [shownCharCount, setShownCharCount] = (0, _react.useState)(charactersCount > 0 ? 0 : textContent.length);
|
|
105
|
+
const currentPosition = (0, _react.useRef)(0);
|
|
106
|
+
(0, _react.useEffect)(() => {
|
|
107
|
+
if (!shouldCalcAutoSpeed) {
|
|
108
|
+
setAutoSpeed(undefined);
|
|
109
|
+
setAutoSteps(animationSteps);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const {
|
|
113
|
+
speed: calculatedAutoSpeed,
|
|
114
|
+
steps
|
|
115
|
+
} = (0, _utils.calculateAutoSpeed)({
|
|
116
|
+
fullTextLength: charactersCount,
|
|
117
|
+
currentPosition: currentPosition.current,
|
|
118
|
+
baseSpeedFactor: autoSpeedBaseFactor
|
|
119
|
+
});
|
|
120
|
+
setAutoSpeed(calculatedAutoSpeed);
|
|
121
|
+
setAutoSteps(steps);
|
|
122
|
+
}, [animationSteps, autoSpeedBaseFactor, charactersCount, shouldCalcAutoSpeed]);
|
|
123
|
+
const isAnimatingText = shownCharCount < textContent.length || shouldForceCursorAnimation || areMultipleChildrenGiven || textContent.length === 0;
|
|
124
|
+
const handleClick = (0, _react.useCallback)(event => {
|
|
125
|
+
event.stopPropagation();
|
|
126
|
+
event.preventDefault();
|
|
127
|
+
setShouldStopAnimation(true);
|
|
128
|
+
}, []);
|
|
129
|
+
const handleSetNextChildrenIndex = (0, _react.useCallback)(() => setCurrentChildrenIndex(() => {
|
|
130
|
+
let newIndex = currentChildrenIndex + 1;
|
|
131
|
+
if (newIndex > childrenCount - 1) {
|
|
132
|
+
newIndex = 0;
|
|
133
|
+
}
|
|
134
|
+
return newIndex;
|
|
135
|
+
}), [childrenCount, currentChildrenIndex]);
|
|
136
|
+
(0, _react.useEffect)(() => {
|
|
137
|
+
let interval;
|
|
138
|
+
if (shouldStopAnimation || charactersCount === 0) {
|
|
139
|
+
setShownCharCount(textContent.length);
|
|
140
|
+
currentPosition.current = textContent.length;
|
|
141
|
+
} else if (isResetAnimationActive) {
|
|
142
|
+
if (typeof onResetAnimationStart === 'function') {
|
|
143
|
+
onResetAnimationStart();
|
|
144
|
+
}
|
|
145
|
+
interval = window.setInterval(() => {
|
|
146
|
+
setShownCharCount(prevState => {
|
|
147
|
+
const nextState = prevState - autoSteps;
|
|
148
|
+
currentPosition.current = nextState;
|
|
149
|
+
if (nextState === 0) {
|
|
150
|
+
window.clearInterval(interval);
|
|
151
|
+
if (typeof onResetAnimationEnd === 'function') {
|
|
152
|
+
onResetAnimationEnd();
|
|
153
|
+
}
|
|
154
|
+
if (areMultipleChildrenGiven) {
|
|
155
|
+
setTimeout(() => {
|
|
156
|
+
setIsResetAnimationActive(false);
|
|
157
|
+
handleSetNextChildrenIndex();
|
|
158
|
+
}, nextTextDelay);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return nextState;
|
|
162
|
+
});
|
|
163
|
+
}, resetSpeed);
|
|
164
|
+
} else {
|
|
165
|
+
const startTypingAnimation = () => {
|
|
166
|
+
if (cursorType === _cursor.CursorType.Thin) {
|
|
167
|
+
setShouldPreventBlinkingCursor(true);
|
|
168
|
+
}
|
|
169
|
+
if (typeof onTypingAnimationStart === 'function') {
|
|
170
|
+
onTypingAnimationStart();
|
|
171
|
+
}
|
|
172
|
+
const runTypingInterval = () => {
|
|
173
|
+
setShownCharCount(prevState => {
|
|
174
|
+
let nextState = Math.min(prevState + autoSteps, charactersCount);
|
|
175
|
+
if (nextState >= charactersCount && !shouldWaitForContent) {
|
|
176
|
+
window.clearInterval(interval);
|
|
177
|
+
if (cursorType === _cursor.CursorType.Thin) {
|
|
178
|
+
setShouldPreventBlinkingCursor(false);
|
|
179
|
+
}
|
|
180
|
+
if (typeof onTypingAnimationEnd === 'function') {
|
|
181
|
+
onTypingAnimationEnd();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* At this point, the next value for "shownCharCount" is deliberately set to
|
|
186
|
+
* the length of the textContent in order to correctly display HTML elements
|
|
187
|
+
* after the last letter.
|
|
188
|
+
*/
|
|
189
|
+
nextState = textContent.length;
|
|
190
|
+
if (areMultipleChildrenGiven) {
|
|
191
|
+
setTimeout(() => {
|
|
192
|
+
if (shouldUseResetAnimation) {
|
|
193
|
+
setIsResetAnimationActive(true);
|
|
194
|
+
} else {
|
|
195
|
+
setShownCharCount(0);
|
|
196
|
+
setTimeout(handleSetNextChildrenIndex, nextTextDelay);
|
|
197
|
+
}
|
|
198
|
+
}, resetDelay);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
currentPosition.current = nextState;
|
|
202
|
+
return nextState;
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
interval = window.setInterval(runTypingInterval, autoSpeed ?? speed);
|
|
206
|
+
};
|
|
207
|
+
if (startDelay) {
|
|
208
|
+
setTimeout(startTypingAnimation, startDelay);
|
|
209
|
+
} else {
|
|
210
|
+
startTypingAnimation();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return () => {
|
|
214
|
+
window.clearInterval(interval);
|
|
215
|
+
};
|
|
216
|
+
}, [resetSpeed, speed, resetDelay, childrenCount, charactersCount, textContent.length, shouldStopAnimation, shouldWaitForContent, isResetAnimationActive, shouldUseResetAnimation, areMultipleChildrenGiven, handleSetNextChildrenIndex, nextTextDelay, startDelay, onResetAnimationStart, onResetAnimationEnd, onTypingAnimationStart, onTypingAnimationEnd, cursorType, autoSpeed, autoSteps]);
|
|
217
|
+
(0, _react.useEffect)(() => {
|
|
218
|
+
if (!isAnimatingText && typeof onFinish === 'function') {
|
|
219
|
+
onFinish();
|
|
220
|
+
}
|
|
221
|
+
}, [isAnimatingText, onFinish]);
|
|
222
|
+
const shownText = (0, _react.useMemo)(() => (0, _utils.getSubTextFromHTML)(textContent, shownCharCount), [shownCharCount, textContent]);
|
|
223
|
+
const pseudoTextHTML = (0, _react.useMemo)(() => {
|
|
224
|
+
if (pseudoChildren) {
|
|
225
|
+
const pseudoText = /*#__PURE__*/_react.default.isValidElement(pseudoChildren) ? (0, _server.renderToString)(/*#__PURE__*/_react.default.createElement(_chaynsApi.ChaynsProvider, {
|
|
226
|
+
data: values,
|
|
227
|
+
functions: functions,
|
|
228
|
+
isModule: true
|
|
229
|
+
}, /*#__PURE__*/_react.default.createElement(_core.ColorSchemeProvider, {
|
|
230
|
+
color: "#005EB8",
|
|
231
|
+
colorMode: 0,
|
|
232
|
+
style: {
|
|
233
|
+
display: 'inline'
|
|
234
|
+
}
|
|
235
|
+
}, pseudoChildren))) : pseudoChildren;
|
|
236
|
+
if (shouldUseAnimationHeight) {
|
|
237
|
+
return (0, _utils.getSubTextFromHTML)(pseudoText, shownCharCount);
|
|
238
|
+
}
|
|
239
|
+
return pseudoText;
|
|
240
|
+
}
|
|
241
|
+
if (shouldUseAnimationHeight && textContent) {
|
|
242
|
+
return (0, _utils.getSubTextFromHTML)(textContent, shownCharCount);
|
|
243
|
+
}
|
|
244
|
+
return textContent || '​';
|
|
245
|
+
}, [functions, pseudoChildren, shouldUseAnimationHeight, shownCharCount, textContent, values]);
|
|
246
|
+
return (0, _react.useMemo)(() => /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriter, {
|
|
247
|
+
$cursorType: cursorType,
|
|
248
|
+
onClick: isAnimatingText ? handleClick : undefined,
|
|
249
|
+
$isAnimatingText: isAnimatingText,
|
|
250
|
+
$shouldHideCursor: shouldHideCursor,
|
|
251
|
+
$shouldPreventBlinkAnimation: shouldPreventBlinkingCursor
|
|
252
|
+
}, isAnimatingText ? /*#__PURE__*/_react.default.createElement(_AnimatedTypewriterText.default, {
|
|
253
|
+
shouldHideCursor: shouldHideCursor,
|
|
254
|
+
shownText: shownText,
|
|
255
|
+
textStyle: textStyle
|
|
256
|
+
}) : /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriterText, {
|
|
257
|
+
style: textStyle
|
|
258
|
+
}, sortedChildren), isAnimatingText && /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriterPseudoText, {
|
|
259
|
+
$isAnimatingText: isAnimatingText,
|
|
260
|
+
$shouldHideCursor: shouldHideCursor,
|
|
261
|
+
dangerouslySetInnerHTML: {
|
|
262
|
+
__html: pseudoTextHTML
|
|
263
|
+
}
|
|
264
|
+
}), !hasRenderedChildrenOnce && /*#__PURE__*/(0, _reactDom.createPortal)(/*#__PURE__*/_react.default.createElement("div", {
|
|
265
|
+
style: {
|
|
266
|
+
position: 'absolute',
|
|
267
|
+
visibility: 'hidden'
|
|
268
|
+
}
|
|
269
|
+
}, children), document.body)), [children, cursorType, handleClick, hasRenderedChildrenOnce, isAnimatingText, pseudoTextHTML, shouldHideCursor, shouldPreventBlinkingCursor, shownText, sortedChildren, textStyle]);
|
|
270
|
+
};
|
|
271
|
+
Typewriter.displayName = 'Typewriter';
|
|
272
|
+
var _default = exports.default = Typewriter;
|
|
273
|
+
//# sourceMappingURL=Typewriter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Typewriter.js","names":["_core","require","_chaynsApi","_react","_interopRequireWildcard","_reactDom","_server","_cursor","_speed","_AnimatedTypewriterText","_interopRequireDefault","_Typewriter","_utils","e","__esModule","default","_getRequireWildcardCache","WeakMap","r","t","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","useIsomorphicLayoutEffect","window","useLayoutEffect","useEffect","Typewriter","children","cursorType","CursorType","Default","nextTextDelay","TypewriterDelay","Medium","onFinish","onResetAnimationEnd","animationSteps","onResetAnimationStart","onTypingAnimationEnd","onTypingAnimationStart","pseudoChildren","resetDelay","shouldForceCursorAnimation","shouldHideCursor","shouldSortChildrenRandomly","shouldUseAnimationHeight","shouldUseResetAnimation","shouldWaitForContent","speed","TypewriterSpeed","resetSpeed","startDelay","None","textStyle","shouldCalcAutoSpeed","autoSpeedBaseFactor","currentChildrenIndex","setCurrentChildrenIndex","useState","hasRenderedChildrenOnce","setHasRenderedChildrenOnce","shouldPreventBlinkingCursor","setShouldPreventBlinkingCursor","isResetAnimationActive","setIsResetAnimationActive","shouldStopAnimation","setShouldStopAnimation","autoSpeed","setAutoSpeed","autoSteps","setAutoSteps","functions","useFunctions","values","useValues","sortedChildren","useMemo","Array","isArray","shuffleArray","areMultipleChildrenGiven","childrenCount","length","textContent","currentChildren","React","isValidElement","renderToString","createElement","ChaynsProvider","data","isModule","ColorSchemeProvider","color","colorMode","style","display","charactersCount","getCharactersCount","shownCharCount","setShownCharCount","currentPosition","useRef","undefined","calculatedAutoSpeed","steps","calculateAutoSpeed","fullTextLength","current","baseSpeedFactor","isAnimatingText","handleClick","useCallback","event","stopPropagation","preventDefault","handleSetNextChildrenIndex","newIndex","interval","setInterval","prevState","nextState","clearInterval","setTimeout","startTypingAnimation","Thin","runTypingInterval","Math","min","shownText","getSubTextFromHTML","pseudoTextHTML","pseudoText","StyledTypewriter","$cursorType","onClick","$isAnimatingText","$shouldHideCursor","$shouldPreventBlinkAnimation","StyledTypewriterText","StyledTypewriterPseudoText","dangerouslySetInnerHTML","__html","createPortal","position","visibility","document","body","displayName","_default","exports"],"sources":["../../../../src/components/typewriter/Typewriter.tsx"],"sourcesContent":["import { ColorSchemeProvider } from '@chayns-components/core';\nimport { ChaynsProvider, useFunctions, useValues } from 'chayns-api';\nimport React, {\n FC,\n ReactElement,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { createPortal } from 'react-dom';\nimport { renderToString } from 'react-dom/server';\nimport { CursorType } from '../../types/cursor';\nimport { TypewriterDelay, TypewriterSpeed } from '../../types/speed';\nimport AnimatedTypewriterText from './AnimatedTypewriterText';\nimport {\n StyledTypewriter,\n StyledTypewriterPseudoText,\n StyledTypewriterText,\n} from './Typewriter.styles';\nimport { calculateAutoSpeed, getCharactersCount, getSubTextFromHTML, shuffleArray } from './utils';\n\nconst useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport type TypewriterProps = {\n /**\n * The amount of characters that will be animated per animation cycle.\n */\n animationSteps?: number;\n /**\n * The base speed factor to calculate the animation speed.\n */\n autoSpeedBaseFactor?: number;\n /**\n * The text to type\n */\n children: ReactElement | ReactElement[] | string | string[];\n /**\n * The type of the cursor. Use the CursorType enum for this prop.\n */\n cursorType?: CursorType;\n /**\n * The delay in milliseconds before the next text is shown.\n * This prop is only used if multiple texts are given.\n */\n nextTextDelay?: TypewriterDelay;\n /**\n * Function that is executed when the typewriter animation has finished. This function will not\n * be executed if multiple texts are used.\n */\n onFinish?: VoidFunction;\n /**\n * Function that is executed when the reset animation has finished. This function will not be\n * executed if `shouldUseResetAnimation` is not set to `true`.\n */\n onResetAnimationEnd?: VoidFunction;\n /**\n * Function that is executed when the reset animation has started. This function will not be\n * executed if `shouldUseResetAnimation` is not set to `true`.\n */\n onResetAnimationStart?: VoidFunction;\n /**\n * Function that is executed when the typing animation has finished. If multiple texts are given,\n * this function will be executed for each text.\n */\n onTypingAnimationEnd?: VoidFunction;\n /**\n * Function that is executed when the typing animation has started. If multiple texts are given,\n * this function will be executed for each text.\n */\n onTypingAnimationStart?: VoidFunction;\n /**\n * Pseudo-element to be rendered invisible during animation to define the size of the element\n * for the typewriter effect. By default, the \"children\" is used for this purpose.\n */\n pseudoChildren?: ReactElement | string;\n /**\n * Waiting time in milliseconds before the typewriter resets the text.\n * This prop is only used if multiple texts are given.\n */\n resetDelay?: TypewriterDelay;\n /**\n * The reset speed of the animation. Use the TypewriterSpeed enum for this prop.\n */\n resetSpeed?: TypewriterSpeed | number;\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 * Whether the animation speed should be calculated with the chunk interval.\n */\n shouldCalcAutoSpeed?: boolean;\n /**\n * Specifies whether the reset of the text should be animated with a backspace animation for\n * multiple texts.\n */\n shouldUseResetAnimation?: boolean;\n /**\n * Whether the typewriter should wait for new content\n */\n shouldWaitForContent?: boolean;\n /**\n * The speed of the animation. Use the TypewriterSpeed enum for this prop.\n */\n speed?: TypewriterSpeed | number;\n /**\n * The delay in milliseconds before the typewriter starts typing.\n */\n startDelay?: TypewriterDelay;\n /**\n * The style of the typewriter text element\n */\n textStyle?: React.CSSProperties;\n};\n\nconst Typewriter: FC<TypewriterProps> = ({\n children,\n cursorType = CursorType.Default,\n nextTextDelay = TypewriterDelay.Medium,\n onFinish,\n onResetAnimationEnd,\n animationSteps = 1,\n onResetAnimationStart,\n onTypingAnimationEnd,\n onTypingAnimationStart,\n pseudoChildren,\n resetDelay = TypewriterDelay.Medium,\n shouldForceCursorAnimation = false,\n shouldHideCursor = false,\n shouldSortChildrenRandomly = false,\n shouldUseAnimationHeight = false,\n shouldUseResetAnimation = false,\n shouldWaitForContent,\n speed = TypewriterSpeed.Medium,\n resetSpeed = speed,\n startDelay = TypewriterDelay.None,\n textStyle,\n shouldCalcAutoSpeed = false,\n autoSpeedBaseFactor = 2000,\n}) => {\n const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);\n const [hasRenderedChildrenOnce, setHasRenderedChildrenOnce] = useState(false);\n const [shouldPreventBlinkingCursor, setShouldPreventBlinkingCursor] = useState(false);\n const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);\n const [shouldStopAnimation, setShouldStopAnimation] = useState(false);\n const [autoSpeed, setAutoSpeed] = useState<number>();\n const [autoSteps, setAutoSteps] = useState(animationSteps);\n\n const functions = useFunctions();\n const values = useValues();\n\n useIsomorphicLayoutEffect(() => {\n if (children) {\n setHasRenderedChildrenOnce(false);\n }\n }, [children]);\n\n useEffect(() => {\n if (!hasRenderedChildrenOnce) {\n setHasRenderedChildrenOnce(true);\n }\n }, [hasRenderedChildrenOnce]);\n\n useEffect(() => {\n if (animationSteps > 0 && !shouldCalcAutoSpeed) {\n setAutoSteps(animationSteps);\n }\n }, [animationSteps, shouldCalcAutoSpeed]);\n\n const sortedChildren = useMemo(\n () =>\n Array.isArray(children) && shouldSortChildrenRandomly\n ? shuffleArray<ReactElement | string>(children)\n : children,\n [children, shouldSortChildrenRandomly],\n );\n\n const areMultipleChildrenGiven = Array.isArray(sortedChildren);\n const childrenCount = areMultipleChildrenGiven ? sortedChildren.length : 1;\n\n const textContent = useMemo(() => {\n if (areMultipleChildrenGiven) {\n const currentChildren = sortedChildren[currentChildrenIndex];\n\n if (currentChildren) {\n return React.isValidElement(currentChildren)\n ? renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider\n color=\"#005EB8\"\n colorMode={0}\n style={{ display: 'inline' }}\n >\n {currentChildren}\n </ColorSchemeProvider>\n </ChaynsProvider>,\n )\n : (currentChildren as string);\n }\n\n return '';\n }\n\n return React.isValidElement(sortedChildren)\n ? renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider\n color=\"#005EB8\"\n colorMode={0}\n style={{ display: 'inline' }}\n >\n {sortedChildren}\n </ColorSchemeProvider>\n </ChaynsProvider>,\n )\n : (sortedChildren as string);\n }, [areMultipleChildrenGiven, currentChildrenIndex, functions, sortedChildren, values]);\n\n const charactersCount = useMemo(() => getCharactersCount(textContent), [textContent]);\n\n const [shownCharCount, setShownCharCount] = useState(\n charactersCount > 0 ? 0 : textContent.length,\n );\n\n const currentPosition = useRef(0);\n\n useEffect(() => {\n if (!shouldCalcAutoSpeed) {\n setAutoSpeed(undefined);\n setAutoSteps(animationSteps);\n\n return;\n }\n\n const { speed: calculatedAutoSpeed, steps } = calculateAutoSpeed({\n fullTextLength: charactersCount,\n currentPosition: currentPosition.current,\n baseSpeedFactor: autoSpeedBaseFactor,\n });\n\n setAutoSpeed(calculatedAutoSpeed);\n setAutoSteps(steps);\n }, [animationSteps, autoSpeedBaseFactor, charactersCount, shouldCalcAutoSpeed]);\n\n const isAnimatingText =\n shownCharCount < textContent.length ||\n shouldForceCursorAnimation ||\n areMultipleChildrenGiven ||\n textContent.length === 0;\n\n const handleClick = useCallback((event: React.MouseEvent) => {\n event.stopPropagation();\n event.preventDefault();\n\n setShouldStopAnimation(true);\n }, []);\n\n const handleSetNextChildrenIndex = useCallback(\n () =>\n setCurrentChildrenIndex(() => {\n let newIndex = currentChildrenIndex + 1;\n\n if (newIndex > childrenCount - 1) {\n newIndex = 0;\n }\n\n return newIndex;\n }),\n [childrenCount, currentChildrenIndex],\n );\n\n useEffect(() => {\n let interval: number | undefined;\n\n if (shouldStopAnimation || charactersCount === 0) {\n setShownCharCount(textContent.length);\n currentPosition.current = textContent.length;\n } else if (isResetAnimationActive) {\n if (typeof onResetAnimationStart === 'function') {\n onResetAnimationStart();\n }\n\n interval = window.setInterval(() => {\n setShownCharCount((prevState) => {\n const nextState = prevState - autoSteps;\n currentPosition.current = nextState;\n\n if (nextState === 0) {\n window.clearInterval(interval);\n\n if (typeof onResetAnimationEnd === 'function') {\n onResetAnimationEnd();\n }\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n setIsResetAnimationActive(false);\n handleSetNextChildrenIndex();\n }, nextTextDelay);\n }\n }\n\n return nextState;\n });\n }, resetSpeed);\n } else {\n const startTypingAnimation = () => {\n if (cursorType === CursorType.Thin) {\n setShouldPreventBlinkingCursor(true);\n }\n\n if (typeof onTypingAnimationStart === 'function') {\n onTypingAnimationStart();\n }\n\n const runTypingInterval = () => {\n setShownCharCount((prevState) => {\n let nextState = Math.min(prevState + autoSteps, charactersCount);\n\n if (nextState >= charactersCount && !shouldWaitForContent) {\n window.clearInterval(interval);\n\n if (cursorType === CursorType.Thin) {\n setShouldPreventBlinkingCursor(false);\n }\n\n if (typeof onTypingAnimationEnd === 'function') {\n onTypingAnimationEnd();\n }\n\n /**\n * At this point, the next value for \"shownCharCount\" is deliberately set to\n * the length of the textContent in order to correctly display HTML elements\n * after the last letter.\n */\n nextState = textContent.length;\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n if (shouldUseResetAnimation) {\n setIsResetAnimationActive(true);\n } else {\n setShownCharCount(0);\n setTimeout(handleSetNextChildrenIndex, nextTextDelay);\n }\n }, resetDelay);\n }\n }\n\n currentPosition.current = nextState;\n\n return nextState;\n });\n };\n\n interval = window.setInterval(runTypingInterval, autoSpeed ?? speed);\n };\n\n if (startDelay) {\n setTimeout(startTypingAnimation, startDelay);\n } else {\n startTypingAnimation();\n }\n }\n\n return () => {\n window.clearInterval(interval);\n };\n }, [\n resetSpeed,\n speed,\n resetDelay,\n childrenCount,\n charactersCount,\n textContent.length,\n shouldStopAnimation,\n shouldWaitForContent,\n isResetAnimationActive,\n shouldUseResetAnimation,\n areMultipleChildrenGiven,\n handleSetNextChildrenIndex,\n nextTextDelay,\n startDelay,\n onResetAnimationStart,\n onResetAnimationEnd,\n onTypingAnimationStart,\n onTypingAnimationEnd,\n cursorType,\n autoSpeed,\n autoSteps,\n ]);\n\n useEffect(() => {\n if (!isAnimatingText && typeof onFinish === 'function') {\n onFinish();\n }\n }, [isAnimatingText, onFinish]);\n\n const shownText = useMemo(\n () => getSubTextFromHTML(textContent, shownCharCount),\n [shownCharCount, textContent],\n );\n\n const pseudoTextHTML = useMemo(() => {\n if (pseudoChildren) {\n const pseudoText = React.isValidElement(pseudoChildren)\n ? renderToString(\n <ChaynsProvider data={values} functions={functions} isModule>\n <ColorSchemeProvider\n color=\"#005EB8\"\n colorMode={0}\n style={{ display: 'inline' }}\n >\n {pseudoChildren}\n </ColorSchemeProvider>\n </ChaynsProvider>,\n )\n : (pseudoChildren as string);\n\n if (shouldUseAnimationHeight) {\n return getSubTextFromHTML(pseudoText, shownCharCount);\n }\n\n return pseudoText;\n }\n\n if (shouldUseAnimationHeight && textContent) {\n return getSubTextFromHTML(textContent, shownCharCount);\n }\n\n return textContent || '​';\n }, [functions, pseudoChildren, shouldUseAnimationHeight, shownCharCount, textContent, values]);\n\n return useMemo(\n () => (\n <StyledTypewriter\n $cursorType={cursorType}\n onClick={isAnimatingText ? handleClick : undefined}\n $isAnimatingText={isAnimatingText}\n $shouldHideCursor={shouldHideCursor}\n $shouldPreventBlinkAnimation={shouldPreventBlinkingCursor}\n >\n {isAnimatingText ? (\n <AnimatedTypewriterText\n shouldHideCursor={shouldHideCursor}\n shownText={shownText}\n textStyle={textStyle}\n />\n ) : (\n <StyledTypewriterText style={textStyle}>{sortedChildren}</StyledTypewriterText>\n )}\n {isAnimatingText && (\n <StyledTypewriterPseudoText\n $isAnimatingText={isAnimatingText}\n $shouldHideCursor={shouldHideCursor}\n dangerouslySetInnerHTML={{ __html: pseudoTextHTML }}\n />\n )}\n {/*\n The following is needed because some components like the CodeHighlighter will not render correct\n if the element is not rendered on client before...\n */}\n {!hasRenderedChildrenOnce &&\n createPortal(\n <div style={{ position: 'absolute', visibility: 'hidden' }}>\n {children}\n </div>,\n document.body,\n )}\n </StyledTypewriter>\n ),\n [\n children,\n cursorType,\n handleClick,\n hasRenderedChildrenOnce,\n isAnimatingText,\n pseudoTextHTML,\n shouldHideCursor,\n shouldPreventBlinkingCursor,\n shownText,\n sortedChildren,\n textStyle,\n ],\n );\n};\n\nTypewriter.displayName = 'Typewriter';\n\nexport default Typewriter;\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,uBAAA,CAAAH,OAAA;AAUA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,OAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AACA,IAAAQ,uBAAA,GAAAC,sBAAA,CAAAT,OAAA;AACA,IAAAU,WAAA,GAAAV,OAAA;AAKA,IAAAW,MAAA,GAAAX,OAAA;AAAmG,SAAAS,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAG,yBAAAH,CAAA,6BAAAI,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAD,wBAAA,YAAAA,CAAAH,CAAA,WAAAA,CAAA,GAAAM,CAAA,GAAAD,CAAA,KAAAL,CAAA;AAAA,SAAAT,wBAAAS,CAAA,EAAAK,CAAA,SAAAA,CAAA,IAAAL,CAAA,IAAAA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ports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.StyledTypewriterText = exports.StyledTypewriterPseudoText = exports.StyledTypewriter = void 0;
|
|
7
|
+
var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
8
|
+
var _cursor = require("../../types/cursor");
|
|
9
|
+
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); }
|
|
10
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
|
+
const typewriterCursorElement = ({
|
|
12
|
+
$cursorType,
|
|
13
|
+
$isAnimatingText,
|
|
14
|
+
$shouldHideCursor,
|
|
15
|
+
$shouldPreventBlinkAnimation
|
|
16
|
+
}) => {
|
|
17
|
+
if (!$isAnimatingText || $shouldHideCursor) {
|
|
18
|
+
return '';
|
|
19
|
+
}
|
|
20
|
+
if ($cursorType === _cursor.CursorType.Thin) {
|
|
21
|
+
return (0, _styledComponents.css)`
|
|
22
|
+
.typewriter-lastWithContent {
|
|
23
|
+
&:after {
|
|
24
|
+
animation: ${$shouldPreventBlinkAnimation ? 'none' : blinkAnimation} 1s steps(2, start) infinite;
|
|
25
|
+
color: inherit;
|
|
26
|
+
content: '|';
|
|
27
|
+
font-size: 25px;
|
|
28
|
+
position: relative;
|
|
29
|
+
line-height: 0;
|
|
30
|
+
vertical-align: baseline;
|
|
31
|
+
}
|
|
32
|
+
`;
|
|
33
|
+
}
|
|
34
|
+
return (0, _styledComponents.css)`
|
|
35
|
+
.typewriter-lastWithContent {
|
|
36
|
+
&:after {
|
|
37
|
+
animation: ${blinkAnimation} 1s steps(2, start) infinite;
|
|
38
|
+
color: ${({
|
|
39
|
+
theme
|
|
40
|
+
}) => theme.text};
|
|
41
|
+
content: '▋';
|
|
42
|
+
margin-left: 0.25rem;
|
|
43
|
+
opacity: 0.85;
|
|
44
|
+
position: relative;
|
|
45
|
+
vertical-align: baseline;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
};
|
|
50
|
+
const StyledTypewriter = exports.StyledTypewriter = _styledComponents.default.div`
|
|
51
|
+
align-items: inherit;
|
|
52
|
+
display: flex;
|
|
53
|
+
position: relative;
|
|
54
|
+
width: 100%;
|
|
55
|
+
${typewriterCursorElement}
|
|
56
|
+
`;
|
|
57
|
+
const blinkAnimation = (0, _styledComponents.keyframes)`
|
|
58
|
+
100% {
|
|
59
|
+
visibility: hidden;
|
|
60
|
+
}
|
|
61
|
+
`;
|
|
62
|
+
const StyledTypewriterPseudoText = exports.StyledTypewriterPseudoText = _styledComponents.default.span`
|
|
63
|
+
opacity: 0;
|
|
64
|
+
pointer-events: none;
|
|
65
|
+
user-select: none;
|
|
66
|
+
width: fit-content;
|
|
67
|
+
|
|
68
|
+
${({
|
|
69
|
+
$isAnimatingText,
|
|
70
|
+
$shouldHideCursor
|
|
71
|
+
}) => $isAnimatingText && !$shouldHideCursor && (0, _styledComponents.css)`
|
|
72
|
+
&:after {
|
|
73
|
+
animation: ${blinkAnimation} 1s steps(2, start) infinite;
|
|
74
|
+
color: inherit;
|
|
75
|
+
content: '|';
|
|
76
|
+
font-size: 25px;
|
|
77
|
+
position: relative;
|
|
78
|
+
line-height: 0;
|
|
79
|
+
vertical-align: baseline;
|
|
80
|
+
}
|
|
81
|
+
`}
|
|
82
|
+
`;
|
|
83
|
+
const StyledTypewriterText = exports.StyledTypewriterText = _styledComponents.default.span`
|
|
84
|
+
color: inherit;
|
|
85
|
+
position: ${({
|
|
86
|
+
$isAnimatingText
|
|
87
|
+
}) => $isAnimatingText ? 'absolute' : 'relative'};
|
|
88
|
+
width: fit-content;
|
|
89
|
+
|
|
90
|
+
${({
|
|
91
|
+
$isAnimatingText
|
|
92
|
+
}) => $isAnimatingText && (0, _styledComponents.css)`
|
|
93
|
+
pointer-events: none;
|
|
94
|
+
`}
|
|
95
|
+
`;
|
|
96
|
+
//# sourceMappingURL=Typewriter.styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Typewriter.styles.js","names":["_styledComponents","_interopRequireWildcard","require","_cursor","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","typewriterCursorElement","$cursorType","$isAnimatingText","$shouldHideCursor","$shouldPreventBlinkAnimation","CursorType","Thin","css","blinkAnimation","theme","text","StyledTypewriter","exports","styled","div","keyframes","StyledTypewriterPseudoText","span","StyledTypewriterText"],"sources":["../../../../src/components/typewriter/Typewriter.styles.ts"],"sourcesContent":["import type { WithTheme } from '@chayns-components/core';\nimport styled, { css, keyframes } from 'styled-components';\nimport { CursorType } from '../../types/cursor';\nimport type { TypewriterProps } from './Typewriter';\n\ntype StyledTypewriterProps = WithTheme<{\n $cursorType: TypewriterProps['cursorType'];\n $isAnimatingText: boolean;\n $shouldHideCursor: TypewriterProps['shouldHideCursor'];\n $shouldPreventBlinkAnimation: boolean;\n}>;\n\nconst typewriterCursorElement = ({\n $cursorType,\n $isAnimatingText,\n $shouldHideCursor,\n $shouldPreventBlinkAnimation,\n}: StyledTypewriterProps) => {\n if (!$isAnimatingText || $shouldHideCursor) {\n return '';\n }\n\n if ($cursorType === CursorType.Thin) {\n return css`\n .typewriter-lastWithContent {\n &:after {\n animation: ${$shouldPreventBlinkAnimation ? 'none' : blinkAnimation} 1s steps(2, start) infinite;\n color: inherit;\n content: '|';\n font-size: 25px;\n position: relative;\n line-height: 0;\n vertical-align: baseline;\n }\n `;\n }\n\n return css`\n .typewriter-lastWithContent {\n &:after {\n animation: ${blinkAnimation} 1s steps(2, start) infinite;\n color: ${({ theme }: StyledTypewriterTextProps) => theme.text};\n content: '▋';\n margin-left: 0.25rem;\n opacity: 0.85;\n position: relative;\n vertical-align: baseline;\n }\n }\n `;\n};\n\nexport const StyledTypewriter = styled.div<StyledTypewriterProps>`\n align-items: inherit;\n display: flex;\n position: relative;\n width: 100%;\n ${typewriterCursorElement}\n`;\n\nconst blinkAnimation = keyframes`\n 100% {\n visibility: hidden;\n }\n`;\n\ntype StyledTypewriterPseudoTextProps = WithTheme<{\n $isAnimatingText?: boolean;\n $shouldHideCursor: TypewriterProps['shouldHideCursor'];\n}>;\n\nexport const StyledTypewriterPseudoText = styled.span<StyledTypewriterPseudoTextProps>`\n opacity: 0;\n pointer-events: none;\n user-select: none;\n width: fit-content;\n\n ${({ $isAnimatingText, $shouldHideCursor }) =>\n $isAnimatingText &&\n !$shouldHideCursor &&\n css`\n &:after {\n animation: ${blinkAnimation} 1s steps(2, start) infinite;\n color: inherit;\n content: '|';\n font-size: 25px;\n position: relative;\n line-height: 0;\n vertical-align: baseline;\n }\n `}\n`;\n\ntype StyledTypewriterTextProps = WithTheme<{\n $isAnimatingText?: boolean;\n}>;\n\nexport const StyledTypewriterText = styled.span<StyledTypewriterTextProps>`\n color: inherit;\n position: ${({ $isAnimatingText }) => ($isAnimatingText ? 'absolute' : 'relative')};\n width: fit-content;\n\n ${({ $isAnimatingText }) =>\n $isAnimatingText &&\n css`\n pointer-events: none;\n `}\n`;\n"],"mappings":";;;;;;AACA,IAAAA,iBAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAAgD,SAAAE,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAA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AG,MAAM,GAAGI,cAAc;AACvF;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;EACL;EAEA,OAAO,IAAAD,qBAAG;AACd;AACA;AACA,6BAA6BC,cAAc;AAC3C,yBAAyB,CAAC;IAAEC;EAAiC,CAAC,KAAKA,KAAK,CAACC,IAAI;AAC7E;AACA;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL,CAAC;AAEM,MAAMC,gBAAgB,GAAAC,OAAA,CAAAD,gBAAA,GAAGE,yBAAM,CAACC,GAA0B;AACjE;AACA;AACA;AACA;AACA,MAAMd,uBAAuB;AAC7B,CAAC;AAED,MAAMQ,cAAc,GAAG,IAAAO,2BAAS;AAChC;AACA;AACA;AACA,CAAC;AAOM,MAAMC,0BAA0B,GAAAJ,OAAA,CAAAI,0BAAA,GAAGH,yBAAM,CAACI,IAAqC;AACtF;AACA;AACA;AACA;AACA;AACA,MAAM,CAAC;EAAEf,gBAAgB;EAAEC;AAAkB,CAAC,KACtCD,gBAAgB,IAChB,CAACC,iBAAiB,IAClB,IAAAI,qBAAG;AACX;AACA,6BAA6BC,cAAc;AAC3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT,CAAC;AAMM,MAAMU,oBAAoB,GAAAN,OAAA,CAAAM,oBAAA,GAAGL,yBAAM,CAACI,IAA+B;AAC1E;AACA,gBAAgB,CAAC;EAAEf;AAAiB,CAAC,KAAMA,gBAAgB,GAAG,UAAU,GAAG,UAAW;AACtF;AACA;AACA,MAAM,CAAC;EAAEA;AAAiB,CAAC,KACnBA,gBAAgB,IAChB,IAAAK,qBAAG;AACX;AACA,SAAS;AACT,CAAC","ignoreList":[]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getSubTextFromHTML = exports.getCharactersCount = void 0;
|
|
6
|
+
exports.shuffleArray = exports.getSubTextFromHTML = exports.getCharactersCount = exports.calculateAutoSpeed = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* This function extracts a part of the text from an HTML text. The HTML elements themselves are
|
|
9
9
|
* returned in the result. In addition, the function ensures that the closing tag of the Bold HTML
|
|
@@ -20,7 +20,9 @@ const getSubTextFromHTML = (html, length) => {
|
|
|
20
20
|
let text = '';
|
|
21
21
|
let currLength = 0;
|
|
22
22
|
const traverse = element => {
|
|
23
|
-
if (element.
|
|
23
|
+
if (element.nodeName === 'TWIGNORE') {
|
|
24
|
+
text += element.innerHTML;
|
|
25
|
+
} else if (element.nodeType === 3 && typeof element.textContent === 'string') {
|
|
24
26
|
const nodeText = element.textContent;
|
|
25
27
|
if (currLength + nodeText.length <= length) {
|
|
26
28
|
text += nodeText;
|
|
@@ -64,9 +66,15 @@ const getCharactersCount = html => {
|
|
|
64
66
|
div.innerHTML = html;
|
|
65
67
|
let count = 0;
|
|
66
68
|
const traverse = node => {
|
|
67
|
-
if (node.
|
|
69
|
+
if (node.nodeName === 'TWIGNORE') {
|
|
70
|
+
count += 1;
|
|
71
|
+
} else if (node.nodeType === 3 && typeof node.textContent === 'string') {
|
|
68
72
|
count += node.textContent.trim().length;
|
|
69
73
|
} else if (node.nodeType === 1) {
|
|
74
|
+
if (node.nodeName === 'CODE' && node.textContent !== null) {
|
|
75
|
+
count += node.textContent.length;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
70
78
|
Array.from(node.childNodes).forEach(traverse);
|
|
71
79
|
}
|
|
72
80
|
};
|
|
@@ -74,4 +82,36 @@ const getCharactersCount = html => {
|
|
|
74
82
|
return count;
|
|
75
83
|
};
|
|
76
84
|
exports.getCharactersCount = getCharactersCount;
|
|
85
|
+
const shuffleArray = array => {
|
|
86
|
+
const result = Array.from(array);
|
|
87
|
+
for (let i = result.length - 1; i > 0; i--) {
|
|
88
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
89
|
+
[result[i], result[j]] = [result[j], result[i]];
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
};
|
|
93
|
+
exports.shuffleArray = shuffleArray;
|
|
94
|
+
const calculateAutoSpeed = ({
|
|
95
|
+
fullTextLength,
|
|
96
|
+
currentPosition,
|
|
97
|
+
baseSpeedFactor
|
|
98
|
+
}) => {
|
|
99
|
+
const MIN_SPEED = 1;
|
|
100
|
+
const MAX_SPEED = 10;
|
|
101
|
+
const remainingLength = fullTextLength - currentPosition;
|
|
102
|
+
|
|
103
|
+
// Calculate the speed with the remaining text length and the baseSpeedFactor
|
|
104
|
+
const speed = Math.min(baseSpeedFactor / remainingLength, MAX_SPEED);
|
|
105
|
+
if (speed < MIN_SPEED) {
|
|
106
|
+
return {
|
|
107
|
+
speed: 1,
|
|
108
|
+
steps: 2
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
speed,
|
|
113
|
+
steps: 1
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
exports.calculateAutoSpeed = calculateAutoSpeed;
|
|
77
117
|
//# sourceMappingURL=utils.js.map
|