@chayns-components/typewriter 5.0.0-beta.101
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/LICENSE +21 -0
- package/README.md +45 -0
- package/lib/components/typewriter/Typewriter.d.ts +37 -0
- package/lib/components/typewriter/Typewriter.js +139 -0
- package/lib/components/typewriter/Typewriter.js.map +1 -0
- package/lib/components/typewriter/Typewriter.styles.d.ts +7 -0
- package/lib/components/typewriter/Typewriter.styles.js +62 -0
- package/lib/components/typewriter/Typewriter.styles.js.map +1 -0
- package/lib/components/typewriter/utils.d.ts +13 -0
- package/lib/components/typewriter/utils.js +86 -0
- package/lib/components/typewriter/utils.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +21 -0
- package/lib/index.js.map +1 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Tobit Laboratories AG
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1>
|
|
3
|
+
<img src="https://raw.githubusercontent.com/TobitSoftware/chayns-components/master/assets/logo.png" width="600px" alt="chayns-components" />
|
|
4
|
+
</h1>
|
|
5
|
+
<p>A set of beautiful React components for developing your own applications with chayns.</p>
|
|
6
|
+
<div>
|
|
7
|
+
<img src="https://img.shields.io/npm/dm/@chayns-components/typewriter.svg?style=for-the-badge" alt="" />
|
|
8
|
+
<img src="https://img.shields.io/npm/v/@chayns-components/typewriter?style=for-the-badge" alt="" />
|
|
9
|
+
<img src="https://img.shields.io/github/license/TobitSoftware/chayns-components?style=for-the-badge" alt="" />
|
|
10
|
+
<img src="https://img.shields.io/github/contributors/TobitSoftware/chayns-components?style=for-the-badge" alt="" />
|
|
11
|
+
</div>
|
|
12
|
+
</div>
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
First you need to install the typewriter part of the chayns-components.
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# NPM
|
|
22
|
+
npm install @chayns-components/typewriter
|
|
23
|
+
|
|
24
|
+
# Yarn
|
|
25
|
+
yarn add @chayns-components/typewriter
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
> **Information:** Since the components have now been implemented with the styled-components
|
|
29
|
+
> library, the styles are delivered directly with the components. There is no need to load an extra
|
|
30
|
+
> stylesheet anymore.
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
You can use the components in your project as in the following example.
|
|
35
|
+
|
|
36
|
+
```typescript jsx
|
|
37
|
+
import { Typewriter } from '@chayns-components/typewriter';
|
|
38
|
+
|
|
39
|
+
<Typewriter>
|
|
40
|
+
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt
|
|
41
|
+
ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo
|
|
42
|
+
dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est. Lorem ipsum dolor
|
|
43
|
+
sit amet.
|
|
44
|
+
</Typewriter>;
|
|
45
|
+
```
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { 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 = 40,
|
|
9
|
+
Medium = 30,
|
|
10
|
+
Fast = 20
|
|
11
|
+
}
|
|
12
|
+
export type TypewriterProps = {
|
|
13
|
+
/**
|
|
14
|
+
* The text to type
|
|
15
|
+
*/
|
|
16
|
+
children: ReactElement | ReactElement[] | string | string[];
|
|
17
|
+
/**
|
|
18
|
+
* Waiting time before the typewriter resets the content if multiple texts are given
|
|
19
|
+
*/
|
|
20
|
+
resetDelay?: TypewriterResetDelay;
|
|
21
|
+
/**
|
|
22
|
+
* Specifies whether the children should be sorted randomly if there are multiple texts.
|
|
23
|
+
* This makes the typewriter start with a different text each time and also changes them
|
|
24
|
+
* in a random order.
|
|
25
|
+
*/
|
|
26
|
+
shouldSortChildrenRandomly?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Specifies whether the reset of the text should be animated with a backspace animation for multiple texts.
|
|
29
|
+
*/
|
|
30
|
+
shouldUseResetAnimation?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* The speed of the animation. Use the TypewriterSpeed enum for this prop.
|
|
33
|
+
*/
|
|
34
|
+
speed?: TypewriterSpeed;
|
|
35
|
+
};
|
|
36
|
+
declare const Typewriter: FC<TypewriterProps>;
|
|
37
|
+
export default Typewriter;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.TypewriterSpeed = exports.TypewriterResetDelay = void 0;
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _server = require("react-dom/server");
|
|
9
|
+
var _Typewriter = require("./Typewriter.styles");
|
|
10
|
+
var _utils = require("./utils");
|
|
11
|
+
function _getRequireWildcardCache(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 TypewriterResetDelay;
|
|
14
|
+
exports.TypewriterResetDelay = TypewriterResetDelay;
|
|
15
|
+
(function (TypewriterResetDelay) {
|
|
16
|
+
TypewriterResetDelay[TypewriterResetDelay["Slow"] = 4000] = "Slow";
|
|
17
|
+
TypewriterResetDelay[TypewriterResetDelay["Medium"] = 2000] = "Medium";
|
|
18
|
+
TypewriterResetDelay[TypewriterResetDelay["Fast"] = 1000] = "Fast";
|
|
19
|
+
})(TypewriterResetDelay || (exports.TypewriterResetDelay = TypewriterResetDelay = {}));
|
|
20
|
+
let TypewriterSpeed;
|
|
21
|
+
exports.TypewriterSpeed = TypewriterSpeed;
|
|
22
|
+
(function (TypewriterSpeed) {
|
|
23
|
+
TypewriterSpeed[TypewriterSpeed["Slow"] = 40] = "Slow";
|
|
24
|
+
TypewriterSpeed[TypewriterSpeed["Medium"] = 30] = "Medium";
|
|
25
|
+
TypewriterSpeed[TypewriterSpeed["Fast"] = 20] = "Fast";
|
|
26
|
+
})(TypewriterSpeed || (exports.TypewriterSpeed = TypewriterSpeed = {}));
|
|
27
|
+
const Typewriter = _ref => {
|
|
28
|
+
let {
|
|
29
|
+
children,
|
|
30
|
+
resetDelay = TypewriterResetDelay.Medium,
|
|
31
|
+
shouldSortChildrenRandomly = false,
|
|
32
|
+
shouldUseResetAnimation = false,
|
|
33
|
+
speed = TypewriterSpeed.Medium
|
|
34
|
+
} = _ref;
|
|
35
|
+
const [currentChildrenIndex, setCurrentChildrenIndex] = (0, _react.useState)(0);
|
|
36
|
+
const sortedChildren = Array.isArray(children) && shouldSortChildrenRandomly ? (0, _utils.shuffleArray)(children) : children;
|
|
37
|
+
const areMultipleChildrenGiven = Array.isArray(sortedChildren);
|
|
38
|
+
const childrenCount = areMultipleChildrenGiven ? sortedChildren.length : 1;
|
|
39
|
+
const textContent = (0, _react.useMemo)(() => {
|
|
40
|
+
if (areMultipleChildrenGiven) {
|
|
41
|
+
const currentChildren = sortedChildren[currentChildrenIndex];
|
|
42
|
+
if (currentChildren) {
|
|
43
|
+
return /*#__PURE__*/_react.default.isValidElement(currentChildren) ? (0, _server.renderToString)(currentChildren) : currentChildren;
|
|
44
|
+
}
|
|
45
|
+
return '';
|
|
46
|
+
}
|
|
47
|
+
return /*#__PURE__*/_react.default.isValidElement(sortedChildren) ? (0, _server.renderToString)(sortedChildren) : sortedChildren;
|
|
48
|
+
}, [areMultipleChildrenGiven, currentChildrenIndex, sortedChildren]);
|
|
49
|
+
const charactersCount = (0, _react.useMemo)(() => (0, _utils.getCharactersCount)(textContent), [textContent]);
|
|
50
|
+
const [isResetAnimationActive, setIsResetAnimationActive] = (0, _react.useState)(false);
|
|
51
|
+
const [shownCharCount, setShownCharCount] = (0, _react.useState)(charactersCount > 0 ? 0 : textContent.length);
|
|
52
|
+
const [shouldStopAnimation, setShouldStopAnimation] = (0, _react.useState)(false);
|
|
53
|
+
const isAnimatingText = shownCharCount !== textContent.length || areMultipleChildrenGiven;
|
|
54
|
+
const handleClick = (0, _react.useCallback)(() => {
|
|
55
|
+
setShouldStopAnimation(true);
|
|
56
|
+
}, []);
|
|
57
|
+
const handleSetNextChildrenIndex = (0, _react.useCallback)(() => setCurrentChildrenIndex(() => {
|
|
58
|
+
let newIndex = currentChildrenIndex + 1;
|
|
59
|
+
if (newIndex > childrenCount - 1) {
|
|
60
|
+
newIndex = 0;
|
|
61
|
+
}
|
|
62
|
+
return newIndex;
|
|
63
|
+
}), [childrenCount, currentChildrenIndex]);
|
|
64
|
+
(0, _react.useEffect)(() => {
|
|
65
|
+
let interval;
|
|
66
|
+
if (shouldStopAnimation || charactersCount === 0) {
|
|
67
|
+
setShownCharCount(textContent.length);
|
|
68
|
+
} else if (isResetAnimationActive) {
|
|
69
|
+
interval = window.setInterval(() => {
|
|
70
|
+
setShownCharCount(prevState => {
|
|
71
|
+
const nextState = prevState - 1;
|
|
72
|
+
if (nextState === 0) {
|
|
73
|
+
window.clearInterval(interval);
|
|
74
|
+
if (areMultipleChildrenGiven) {
|
|
75
|
+
setTimeout(() => {
|
|
76
|
+
setIsResetAnimationActive(false);
|
|
77
|
+
handleSetNextChildrenIndex();
|
|
78
|
+
}, resetDelay);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return nextState;
|
|
82
|
+
});
|
|
83
|
+
}, speed);
|
|
84
|
+
} else {
|
|
85
|
+
interval = window.setInterval(() => {
|
|
86
|
+
setShownCharCount(prevState => {
|
|
87
|
+
let nextState = prevState + 1;
|
|
88
|
+
if (nextState === charactersCount) {
|
|
89
|
+
window.clearInterval(interval);
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* At this point, the next value for "shownCharCount" is deliberately set to
|
|
93
|
+
* the length of the textContent in order to correctly display HTML elements
|
|
94
|
+
* after the last letter.
|
|
95
|
+
*/
|
|
96
|
+
nextState = textContent.length;
|
|
97
|
+
if (areMultipleChildrenGiven) {
|
|
98
|
+
setTimeout(() => {
|
|
99
|
+
if (shouldUseResetAnimation) {
|
|
100
|
+
setIsResetAnimationActive(true);
|
|
101
|
+
} else {
|
|
102
|
+
setShownCharCount(0);
|
|
103
|
+
setTimeout(handleSetNextChildrenIndex, resetDelay / 2);
|
|
104
|
+
}
|
|
105
|
+
}, resetDelay);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return nextState;
|
|
109
|
+
});
|
|
110
|
+
}, speed);
|
|
111
|
+
}
|
|
112
|
+
return () => {
|
|
113
|
+
window.clearInterval(interval);
|
|
114
|
+
};
|
|
115
|
+
}, [shouldStopAnimation, speed, textContent.length, charactersCount, isResetAnimationActive, areMultipleChildrenGiven, resetDelay, childrenCount, handleSetNextChildrenIndex, shouldUseResetAnimation]);
|
|
116
|
+
(0, _react.useEffect)(() => {
|
|
117
|
+
if (charactersCount) {
|
|
118
|
+
setIsResetAnimationActive(false);
|
|
119
|
+
setShownCharCount(0);
|
|
120
|
+
}
|
|
121
|
+
}, [charactersCount]);
|
|
122
|
+
const shownText = (0, _react.useMemo)(() => (0, _utils.getSubTextFromHTML)(textContent, shownCharCount), [shownCharCount, textContent]);
|
|
123
|
+
return /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriter, {
|
|
124
|
+
onClick: handleClick
|
|
125
|
+
}, isAnimatingText ? /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriterText, {
|
|
126
|
+
dangerouslySetInnerHTML: {
|
|
127
|
+
__html: shownText
|
|
128
|
+
},
|
|
129
|
+
isAnimatingText: true
|
|
130
|
+
}) : /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriterText, null, sortedChildren), isAnimatingText && /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriterPseudoText, {
|
|
131
|
+
dangerouslySetInnerHTML: {
|
|
132
|
+
__html: textContent
|
|
133
|
+
}
|
|
134
|
+
}));
|
|
135
|
+
};
|
|
136
|
+
Typewriter.displayName = 'Typewriter';
|
|
137
|
+
var _default = Typewriter;
|
|
138
|
+
exports.default = _default;
|
|
139
|
+
//# sourceMappingURL=Typewriter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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","TypewriterResetDelay","exports","TypewriterSpeed","Typewriter","_ref","children","resetDelay","Medium","shouldSortChildrenRandomly","shouldUseResetAnimation","speed","currentChildrenIndex","setCurrentChildrenIndex","useState","sortedChildren","Array","isArray","shuffleArray","areMultipleChildrenGiven","childrenCount","length","textContent","useMemo","currentChildren","React","isValidElement","renderToString","charactersCount","getCharactersCount","isResetAnimationActive","setIsResetAnimationActive","shownCharCount","setShownCharCount","shouldStopAnimation","setShouldStopAnimation","isAnimatingText","handleClick","useCallback","handleSetNextChildrenIndex","newIndex","useEffect","interval","window","setInterval","prevState","nextState","clearInterval","setTimeout","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, shuffleArray } from './utils';\n\nexport enum TypewriterResetDelay {\n Slow = 4000,\n Medium = 2000,\n Fast = 1000,\n}\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 | ReactElement[] | string | 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 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 reset of the text should be animated with a backspace animation for multiple texts.\n */\n shouldUseResetAnimation?: boolean;\n /**\n * The speed of the animation. Use the TypewriterSpeed enum for this prop.\n */\n speed?: TypewriterSpeed;\n};\n\nconst Typewriter: FC<TypewriterProps> = ({\n children,\n resetDelay = TypewriterResetDelay.Medium,\n shouldSortChildrenRandomly = false,\n shouldUseResetAnimation = false,\n speed = TypewriterSpeed.Medium,\n}) => {\n const [currentChildrenIndex, setCurrentChildrenIndex] = useState(0);\n\n const sortedChildren =\n Array.isArray(children) && shouldSortChildrenRandomly\n ? shuffleArray<ReactElement | string>(children)\n : children;\n\n const areMultipleChildrenGiven = Array.isArray(sortedChildren);\n const childrenCount = areMultipleChildrenGiven ? sortedChildren.length : 1;\n\n const textContent = useMemo(() => {\n if (areMultipleChildrenGiven) {\n const currentChildren = sortedChildren[currentChildrenIndex];\n\n if (currentChildren) {\n return React.isValidElement(currentChildren)\n ? renderToString(currentChildren)\n : currentChildren;\n }\n\n return '';\n }\n\n return React.isValidElement(sortedChildren)\n ? renderToString(sortedChildren)\n : sortedChildren;\n }, [areMultipleChildrenGiven, currentChildrenIndex, sortedChildren]);\n\n const charactersCount = useMemo(() => getCharactersCount(textContent), [textContent]);\n\n const [isResetAnimationActive, setIsResetAnimationActive] = useState(false);\n const [shownCharCount, setShownCharCount] = useState(\n charactersCount > 0 ? 0 : textContent.length\n );\n const [shouldStopAnimation, setShouldStopAnimation] = useState(false);\n\n const isAnimatingText = shownCharCount !== textContent.length || areMultipleChildrenGiven;\n\n const handleClick = useCallback(() => {\n setShouldStopAnimation(true);\n }, []);\n\n const handleSetNextChildrenIndex = useCallback(\n () =>\n setCurrentChildrenIndex(() => {\n let newIndex = currentChildrenIndex + 1;\n\n if (newIndex > childrenCount - 1) {\n newIndex = 0;\n }\n\n return newIndex;\n }),\n [childrenCount, currentChildrenIndex]\n );\n\n useEffect(() => {\n let interval: number | undefined;\n\n if (shouldStopAnimation || charactersCount === 0) {\n setShownCharCount(textContent.length);\n } else if (isResetAnimationActive) {\n interval = window.setInterval(() => {\n setShownCharCount((prevState) => {\n const nextState = prevState - 1;\n\n if (nextState === 0) {\n window.clearInterval(interval);\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n setIsResetAnimationActive(false);\n handleSetNextChildrenIndex();\n }, resetDelay);\n }\n }\n\n return nextState;\n });\n }, speed);\n } else {\n interval = window.setInterval(() => {\n setShownCharCount((prevState) => {\n let nextState = prevState + 1;\n\n if (nextState === charactersCount) {\n window.clearInterval(interval);\n\n /**\n * At this point, the next value for \"shownCharCount\" is deliberately set to\n * the length of the textContent in order to correctly display HTML elements\n * after the last letter.\n */\n nextState = textContent.length;\n\n if (areMultipleChildrenGiven) {\n setTimeout(() => {\n if (shouldUseResetAnimation) {\n setIsResetAnimationActive(true);\n } else {\n setShownCharCount(0);\n setTimeout(handleSetNextChildrenIndex, resetDelay / 2);\n }\n }, resetDelay);\n }\n }\n\n return nextState;\n });\n }, speed);\n }\n\n return () => {\n window.clearInterval(interval);\n };\n }, [\n shouldStopAnimation,\n speed,\n textContent.length,\n charactersCount,\n isResetAnimationActive,\n areMultipleChildrenGiven,\n resetDelay,\n childrenCount,\n handleSetNextChildrenIndex,\n shouldUseResetAnimation,\n ]);\n\n useEffect(() => {\n if (charactersCount) {\n setIsResetAnimationActive(false);\n setShownCharCount(0);\n }\n }, [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>{sortedChildren}</StyledTypewriterText>\n )}\n {isAnimatingText && (\n <StyledTypewriterPseudoText dangerouslySetInnerHTML={{ __html: textContent }} />\n )}\n </StyledTypewriter>\n );\n};\n\nTypewriter.displayName = 'Typewriter';\n\nexport default Typewriter;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAKA,IAAAG,MAAA,GAAAH,OAAA;AAA+E,SAAAI,yBAAAC,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,SAAAN,wBAAAU,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,IAAA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AO,EAAEhB;EAAY,GAClCD,eAAe,gBACZ/D,MAAA,CAAAa,OAAA,CAAAiE,aAAA,CAAC1E,WAAA,CAAA6E,oBAAoB;IACjBC,uBAAuB,EAAE;MAAEC,MAAM,EAAEP;IAAU,CAAE;IAC/Cb,eAAe;EAAA,EACjB,gBAEF/D,MAAA,CAAAa,OAAA,CAAAiE,aAAA,CAAC1E,WAAA,CAAA6E,oBAAoB,QAAEvC,cAAc,CACxC,EACAqB,eAAe,iBACZ/D,MAAA,CAAAa,OAAA,CAAAiE,aAAA,CAAC1E,WAAA,CAAAgF,0BAA0B;IAACF,uBAAuB,EAAE;MAAEC,MAAM,EAAElC;IAAY;EAAE,EAChF,CACc;AAE3B,CAAC;AAEDlB,UAAU,CAACsD,WAAW,GAAG,YAAY;AAAC,IAAAC,QAAA,GAEvBvD,UAAU;AAAAF,OAAA,CAAAhB,OAAA,GAAAyE,QAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
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>;
|
|
@@ -0,0 +1,62 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CA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
|
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 declare const getSubTextFromHTML: (html: string, length: number) => string;
|
|
12
|
+
export declare const getCharactersCount: (html: string) => number;
|
|
13
|
+
export declare const shuffleArray: <T>(array: T[]) => T[];
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.shuffleArray = exports.getSubTextFromHTML = exports.getCharactersCount = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* This function extracts a part of the text from an HTML text. The HTML elements themselves are
|
|
9
|
+
* returned in the result. In addition, the function ensures that the closing tag of the Bold HTML
|
|
10
|
+
* element is also returned for text that is cut off in the middle of a Bold element, for example.
|
|
11
|
+
*
|
|
12
|
+
* @param html - The text from which a part should be taken
|
|
13
|
+
* @param length - The length of the text to be extracted
|
|
14
|
+
*
|
|
15
|
+
* @return string - The text part with the specified length - additionally the HTML elements are added
|
|
16
|
+
*/
|
|
17
|
+
const getSubTextFromHTML = (html, length) => {
|
|
18
|
+
const div = document.createElement('div');
|
|
19
|
+
div.innerHTML = html;
|
|
20
|
+
let text = '';
|
|
21
|
+
let currLength = 0;
|
|
22
|
+
const traverse = element => {
|
|
23
|
+
if (element.nodeType === 3 && typeof element.textContent === 'string') {
|
|
24
|
+
const nodeText = element.textContent;
|
|
25
|
+
if (currLength + nodeText.length <= length) {
|
|
26
|
+
text += nodeText;
|
|
27
|
+
currLength += nodeText.length;
|
|
28
|
+
} else {
|
|
29
|
+
text += nodeText.substring(0, length - currLength);
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
} else if (element.nodeType === 1) {
|
|
33
|
+
const nodeName = element.nodeName.toLowerCase();
|
|
34
|
+
let attributes = '';
|
|
35
|
+
|
|
36
|
+
// @ts-expect-error: Type is correct here
|
|
37
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
38
|
+
for (const attribute of element.attributes) {
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/restrict-template-expressions
|
|
40
|
+
attributes += ` ${attribute.name}="${attribute.value}"`;
|
|
41
|
+
}
|
|
42
|
+
text += `<${nodeName}${attributes}>`;
|
|
43
|
+
for (let i = 0; i < element.childNodes.length; i++) {
|
|
44
|
+
const childNode = element.childNodes[i];
|
|
45
|
+
if (childNode && !traverse(childNode)) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
text += `</${nodeName}>`;
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
};
|
|
53
|
+
for (let i = 0; i < div.childNodes.length; i++) {
|
|
54
|
+
const childNode = div.childNodes[i];
|
|
55
|
+
if (childNode && !traverse(childNode)) {
|
|
56
|
+
return text;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return text;
|
|
60
|
+
};
|
|
61
|
+
exports.getSubTextFromHTML = getSubTextFromHTML;
|
|
62
|
+
const getCharactersCount = html => {
|
|
63
|
+
const div = document.createElement('div');
|
|
64
|
+
div.innerHTML = html;
|
|
65
|
+
let count = 0;
|
|
66
|
+
const traverse = node => {
|
|
67
|
+
if (node.nodeType === 3 && typeof node.textContent === 'string') {
|
|
68
|
+
count += node.textContent.trim().length;
|
|
69
|
+
} else if (node.nodeType === 1) {
|
|
70
|
+
Array.from(node.childNodes).forEach(traverse);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
Array.from(div.childNodes).forEach(traverse);
|
|
74
|
+
return count;
|
|
75
|
+
};
|
|
76
|
+
exports.getCharactersCount = getCharactersCount;
|
|
77
|
+
const shuffleArray = array => {
|
|
78
|
+
const result = Array.from(array);
|
|
79
|
+
for (let i = result.length - 1; i > 0; i--) {
|
|
80
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
81
|
+
[result[i], result[j]] = [result[j], result[i]];
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
};
|
|
85
|
+
exports.shuffleArray = shuffleArray;
|
|
86
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","names":["getSubTextFromHTML","html","length","div","document","createElement","innerHTML","text","currLength","traverse","element","nodeType","textContent","nodeText","substring","nodeName","toLowerCase","attributes","attribute","name","value","i","childNodes","childNode","exports","getCharactersCount","count","node","trim","Array","from","forEach","shuffleArray","array","result","j","Math","floor","random"],"sources":["../../../src/components/typewriter/utils.ts"],"sourcesContent":["/**\n * This function extracts a part of the text from an HTML text. The HTML elements themselves are\n * returned in the result. In addition, the function ensures that the closing tag of the Bold HTML\n * element is also returned for text that is cut off in the middle of a Bold element, for example.\n *\n * @param html - The text from which a part should be taken\n * @param length - The length of the text to be extracted\n *\n * @return string - The text part with the specified length - additionally the HTML elements are added\n */\nexport const getSubTextFromHTML = (html: string, length: number): string => {\n const div = document.createElement('div');\n\n div.innerHTML = html;\n\n let text = '';\n let currLength = 0;\n\n const traverse = (element: Element): boolean => {\n if (element.nodeType === 3 && typeof element.textContent === 'string') {\n const nodeText = element.textContent;\n\n if (currLength + nodeText.length <= length) {\n text += nodeText;\n currLength += nodeText.length;\n } else {\n text += nodeText.substring(0, length - currLength);\n\n return false;\n }\n } else if (element.nodeType === 1) {\n const nodeName = element.nodeName.toLowerCase();\n\n let attributes = '';\n\n // @ts-expect-error: Type is correct here\n // eslint-disable-next-line no-restricted-syntax\n for (const attribute of element.attributes) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/restrict-template-expressions\n attributes += ` ${attribute.name}=\"${attribute.value}\"`;\n }\n\n text += `<${nodeName}${attributes}>`;\n\n for (let i = 0; i < element.childNodes.length; i++) {\n const childNode = element.childNodes[i];\n\n if (childNode && !traverse(childNode as Element)) {\n return false;\n }\n }\n\n text += `</${nodeName}>`;\n }\n\n return true;\n };\n\n for (let i = 0; i < div.childNodes.length; i++) {\n const childNode = div.childNodes[i];\n\n if (childNode && !traverse(childNode as Element)) {\n return text;\n }\n }\n\n return text;\n};\n\nexport const getCharactersCount = (html: string): number => {\n const div = document.createElement('div');\n\n div.innerHTML = html;\n\n let count = 0;\n\n const traverse = (node: Node): void => {\n if (node.nodeType === 3 && typeof node.textContent === 'string') {\n count += node.textContent.trim().length;\n } else if (node.nodeType === 1) {\n Array.from(node.childNodes).forEach(traverse);\n }\n };\n\n Array.from(div.childNodes).forEach(traverse);\n\n return count;\n};\n\nexport const shuffleArray = <T>(array: T[]): T[] => {\n const result = Array.from(array);\n\n for (let i = result.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n\n [result[i], result[j]] = [result[j]!, result[i]!];\n }\n\n return result;\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,kBAAkB,GAAGA,CAACC,IAAY,EAAEC,MAAc,KAAa;EACxE,MAAMC,GAAG,GAAGC,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAEzCF,GAAG,CAACG,SAAS,GAAGL,IAAI;EAEpB,IAAIM,IAAI,GAAG,EAAE;EACb,IAAIC,UAAU,GAAG,CAAC;EAElB,MAAMC,QAAQ,GAAIC,OAAgB,IAAc;IAC5C,IAAIA,OAAO,CAACC,QAAQ,KAAK,CAAC,IAAI,OAAOD,OAAO,CAACE,WAAW,KAAK,QAAQ,EAAE;MACnE,MAAMC,QAAQ,GAAGH,OAAO,CAACE,WAAW;MAEpC,IAAIJ,UAAU,GAAGK,QAAQ,CAAC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AAC,EAAGD,MAAM,CAACb,CAAC,CAAC,CAAE;EACrD;EAEA,OAAOa,MAAM;AACjB,CAAC;AAACV,OAAA,CAAAQ,YAAA,GAAAA,YAAA"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Typewriter, TypewriterSpeed } from './components/typewriter/Typewriter';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "Typewriter", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _Typewriter.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "TypewriterSpeed", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _Typewriter.TypewriterSpeed;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
var _Typewriter = _interopRequireWildcard(require("./components/typewriter/Typewriter"));
|
|
19
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
20
|
+
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; }
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["_Typewriter","_interopRequireWildcard","require","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set"],"sources":["../src/index.ts"],"sourcesContent":["export { default as Typewriter, TypewriterSpeed } from './components/typewriter/Typewriter';\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,WAAA,GAAAC,uBAAA,CAAAC,OAAA;AAA4F,SAAAC,yBAAAC,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,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GAAA,KAAAR,MAAA,CAAAC,cAAA,CAAAH,MAAA,EAAAK,GAAA,EAAAI,IAAA,YAAAT,MAAA,CAAAK,GAAA,IAAAX,GAAA,CAAAW,GAAA,SAAAL,MAAA,CAAAJ,OAAA,GAAAF,GAAA,MAAAG,KAAA,IAAAA,KAAA,CAAAa,GAAA,CAAAhB,GAAA,EAAAM,MAAA,YAAAA,MAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@chayns-components/typewriter",
|
|
3
|
+
"version": "5.0.0-beta.101",
|
|
4
|
+
"description": "A set of beautiful React components for developing your own applications with chayns.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"chayns",
|
|
7
|
+
"react",
|
|
8
|
+
"components"
|
|
9
|
+
],
|
|
10
|
+
"author": "Tobit.Software",
|
|
11
|
+
"homepage": "https://github.com/TobitSoftware/chayns-components/tree/main/packages/typewriter#readme",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"main": "lib/index.js",
|
|
14
|
+
"types": "lib/index.d.ts",
|
|
15
|
+
"directories": {
|
|
16
|
+
"lib": "lib",
|
|
17
|
+
"test": "__tests__"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"lib"
|
|
21
|
+
],
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/TobitSoftware/chayns-components.git"
|
|
25
|
+
},
|
|
26
|
+
"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",
|
|
29
|
+
"build:types": "tsc",
|
|
30
|
+
"prepublishOnly": "npm run build"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/TobitSoftware/chayns-components/issues"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@babel/cli": "^7.21.0",
|
|
37
|
+
"@babel/core": "^7.21.3",
|
|
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.1",
|
|
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"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@chayns-components/core": "^5.0.0-beta.98",
|
|
53
|
+
"@chayns/colors": "^2.0.0",
|
|
54
|
+
"clsx": "^1.2.1",
|
|
55
|
+
"framer-motion": "^6.5.1",
|
|
56
|
+
"styled-components": "^5.3.9",
|
|
57
|
+
"uuid": "^9.0.0"
|
|
58
|
+
},
|
|
59
|
+
"peerDependencies": {
|
|
60
|
+
"react": ">=16.14.0",
|
|
61
|
+
"react-dom": ">=16.14.0"
|
|
62
|
+
},
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"access": "public"
|
|
65
|
+
},
|
|
66
|
+
"gitHead": "63c6839096fc69842742008896954f0b22276fcf"
|
|
67
|
+
}
|