@chayns-components/typewriter 5.0.0-beta.56 → 5.0.0-beta.59
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/lib/components/typewriter/Typewriter.d.ts +6 -0
- package/lib/components/typewriter/Typewriter.js +16 -7
- package/lib/components/typewriter/Typewriter.js.map +1 -1
- package/lib/components/typewriter/Typewriter.styles.js +2 -0
- package/lib/components/typewriter/Typewriter.styles.js.map +1 -1
- package/lib/components/typewriter/utils.d.ts +1 -0
- package/lib/components/typewriter/utils.js +16 -1
- package/lib/components/typewriter/utils.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +9 -2
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { FC, ReactElement } from 'react';
|
|
2
|
+
export declare enum TypewriterSpeed {
|
|
3
|
+
Slow = 40,
|
|
4
|
+
Medium = 30,
|
|
5
|
+
Fast = 20
|
|
6
|
+
}
|
|
2
7
|
export type TypewriterProps = {
|
|
3
8
|
/**
|
|
4
9
|
* The text to type
|
|
5
10
|
*/
|
|
6
11
|
children: ReactElement | string;
|
|
12
|
+
speed?: TypewriterSpeed;
|
|
7
13
|
};
|
|
8
14
|
declare const Typewriter: FC<TypewriterProps>;
|
|
9
15
|
export default Typewriter;
|
|
@@ -3,44 +3,53 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
6
|
+
exports.default = exports.TypewriterSpeed = void 0;
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _server = require("react-dom/server");
|
|
9
9
|
var _Typewriter = require("./Typewriter.styles");
|
|
10
10
|
var _utils = require("./utils");
|
|
11
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
12
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
13
|
+
let TypewriterSpeed;
|
|
14
|
+
exports.TypewriterSpeed = TypewriterSpeed;
|
|
15
|
+
(function (TypewriterSpeed) {
|
|
16
|
+
TypewriterSpeed[TypewriterSpeed["Slow"] = 40] = "Slow";
|
|
17
|
+
TypewriterSpeed[TypewriterSpeed["Medium"] = 30] = "Medium";
|
|
18
|
+
TypewriterSpeed[TypewriterSpeed["Fast"] = 20] = "Fast";
|
|
19
|
+
})(TypewriterSpeed || (exports.TypewriterSpeed = TypewriterSpeed = {}));
|
|
13
20
|
const Typewriter = _ref => {
|
|
14
21
|
let {
|
|
15
|
-
children
|
|
22
|
+
children,
|
|
23
|
+
speed = TypewriterSpeed.Medium
|
|
16
24
|
} = _ref;
|
|
17
25
|
const [shownCharCount, setShownCharCount] = (0, _react.useState)(0);
|
|
18
26
|
const [shouldStopAnimation, setShouldStopAnimation] = (0, _react.useState)(false);
|
|
19
27
|
const textContent = /*#__PURE__*/_react.default.isValidElement(children) ? (0, _server.renderToString)(children) : children;
|
|
20
|
-
const
|
|
28
|
+
const textLength = (0, _react.useMemo)(() => (0, _utils.getCharactersCount)(textContent), [textContent]);
|
|
29
|
+
const isAnimatingText = shownCharCount !== textLength;
|
|
21
30
|
const handleClick = (0, _react.useCallback)(() => {
|
|
22
31
|
setShouldStopAnimation(true);
|
|
23
32
|
}, []);
|
|
24
33
|
(0, _react.useEffect)(() => {
|
|
25
34
|
let interval;
|
|
26
35
|
if (shouldStopAnimation) {
|
|
27
|
-
setShownCharCount(
|
|
36
|
+
setShownCharCount(textLength);
|
|
28
37
|
} else {
|
|
29
38
|
setShownCharCount(0);
|
|
30
39
|
interval = window.setInterval(() => {
|
|
31
40
|
setShownCharCount(prevState => {
|
|
32
41
|
const nextState = prevState + 1;
|
|
33
|
-
if (nextState ===
|
|
42
|
+
if (nextState === textLength) {
|
|
34
43
|
window.clearInterval(interval);
|
|
35
44
|
}
|
|
36
45
|
return nextState;
|
|
37
46
|
});
|
|
38
|
-
},
|
|
47
|
+
}, speed);
|
|
39
48
|
}
|
|
40
49
|
return () => {
|
|
41
50
|
window.clearInterval(interval);
|
|
42
51
|
};
|
|
43
|
-
}, [shouldStopAnimation,
|
|
52
|
+
}, [shouldStopAnimation, speed, textLength]);
|
|
44
53
|
const shownText = (0, _react.useMemo)(() => (0, _utils.getSubTextFromHTML)(textContent, shownCharCount), [shownCharCount, textContent]);
|
|
45
54
|
return /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriter, {
|
|
46
55
|
onClick: handleClick
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Typewriter.js","names":["Typewriter","children","shownCharCount","setShownCharCount","useState","shouldStopAnimation","setShouldStopAnimation","textContent","React","isValidElement","renderToString","
|
|
1
|
+
{"version":3,"file":"Typewriter.js","names":["TypewriterSpeed","Typewriter","children","speed","Medium","shownCharCount","setShownCharCount","useState","shouldStopAnimation","setShouldStopAnimation","textContent","React","isValidElement","renderToString","textLength","useMemo","getCharactersCount","isAnimatingText","handleClick","useCallback","useEffect","interval","window","setInterval","prevState","nextState","clearInterval","shownText","getSubTextFromHTML","__html","displayName"],"sources":["../../../src/components/typewriter/Typewriter.tsx"],"sourcesContent":["import React, { FC, ReactElement, useCallback, useEffect, useMemo, useState } from 'react';\nimport { renderToString } from 'react-dom/server';\nimport {\n StyledTypewriter,\n StyledTypewriterPseudoText,\n StyledTypewriterText,\n} from './Typewriter.styles';\nimport { getCharactersCount, getSubTextFromHTML } from './utils';\n\nexport enum TypewriterSpeed {\n Slow = 40,\n Medium = 30,\n Fast = 20,\n}\n\nexport type TypewriterProps = {\n /**\n * The text to type\n */\n children: ReactElement | string;\n speed?: TypewriterSpeed;\n};\n\nconst Typewriter: FC<TypewriterProps> = ({ children, speed = TypewriterSpeed.Medium }) => {\n const [shownCharCount, setShownCharCount] = useState(0);\n const [shouldStopAnimation, setShouldStopAnimation] = useState(false);\n\n const textContent = React.isValidElement(children) ? renderToString(children) : children;\n\n const textLength = useMemo(() => getCharactersCount(textContent), [textContent]);\n\n const isAnimatingText = shownCharCount !== textLength;\n\n const handleClick = useCallback(() => {\n setShouldStopAnimation(true);\n }, []);\n\n useEffect(() => {\n let interval: number | undefined;\n\n if (shouldStopAnimation) {\n setShownCharCount(textLength);\n } else {\n setShownCharCount(0);\n\n interval = window.setInterval(() => {\n setShownCharCount((prevState) => {\n const nextState = prevState + 1;\n\n if (nextState === textLength) {\n window.clearInterval(interval);\n }\n\n return nextState;\n });\n }, speed);\n }\n\n return () => {\n window.clearInterval(interval);\n };\n }, [shouldStopAnimation, speed, textLength]);\n\n const shownText = useMemo(\n () => getSubTextFromHTML(textContent, shownCharCount),\n [shownCharCount, textContent]\n );\n\n return (\n <StyledTypewriter onClick={handleClick}>\n <StyledTypewriterText\n dangerouslySetInnerHTML={{ __html: shownText }}\n isAnimatingText={isAnimatingText}\n />\n {isAnimatingText && <StyledTypewriterPseudoText>{children}</StyledTypewriterPseudoText>}\n </StyledTypewriter>\n );\n};\n\nTypewriter.displayName = 'Typewriter';\n\nexport default Typewriter;\n"],"mappings":";;;;;;AAAA;AACA;AACA;AAKA;AAAiE;AAAA;AAAA,IAErDA,e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SAAS;QACpB,CAAC,CAAC;MACN,CAAC,EAAEtB,KAAK,CAAC;IACb;IAEA,OAAO,MAAM;MACTmB,MAAM,CAACI,aAAa,CAACL,QAAQ,CAAC;IAClC,CAAC;EACL,CAAC,EAAE,CAACb,mBAAmB,EAAEL,KAAK,EAAEW,UAAU,CAAC,CAAC;EAE5C,MAAMa,SAAS,GAAG,IAAAZ,cAAO,EACrB,MAAM,IAAAa,yBAAkB,EAAClB,WAAW,EAAEL,cAAc,CAAC,EACrD,CAACA,cAAc,EAAEK,WAAW,CAAC,CAChC;EAED,oBACI,6BAAC,4BAAgB;IAAC,OAAO,EAAEQ;EAAY,gBACnC,6BAAC,gCAAoB;IACjB,uBAAuB,EAAE;MAAEW,MAAM,EAAEF;IAAU,CAAE;IAC/C,eAAe,EAAEV;EAAgB,EACnC,EACDA,eAAe,iBAAI,6BAAC,sCAA0B,QAAEf,QAAQ,CAA8B,CACxE;AAE3B,CAAC;AAEDD,UAAU,CAAC6B,WAAW,GAAG,YAAY;AAAC,eAEvB7B,UAAU;AAAA"}
|
|
@@ -8,6 +8,7 @@ var _styledComponents = _interopRequireWildcard(require("styled-components"));
|
|
|
8
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
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
10
|
const StyledTypewriter = _styledComponents.default.span`
|
|
11
|
+
display: flex;
|
|
11
12
|
position: relative;
|
|
12
13
|
`;
|
|
13
14
|
exports.StyledTypewriter = StyledTypewriter;
|
|
@@ -35,6 +36,7 @@ const StyledTypewriterText = _styledComponents.default.span`
|
|
|
35
36
|
} = _ref2;
|
|
36
37
|
return isAnimatingText ? 'absolute' : 'relative';
|
|
37
38
|
}};
|
|
39
|
+
width: 100%;
|
|
38
40
|
|
|
39
41
|
${_ref3 => {
|
|
40
42
|
let {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Typewriter.styles.js","names":["StyledTypewriter","styled","span","blinkAnimation","keyframes","StyledTypewriterPseudoText","StyledTypewriterText","theme","text","isAnimatingText","css"],"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.span`\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\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;AAA2D;AAAA;AAEpD,MAAMA,gBAAgB,GAAGC,yBAAM,CAACC,IAAK;AAC5C;AACA,CAAC;AAAC;AAEF,MAAMC,cAAc,GAAG,IAAAC,2BAAS,CAAC;AACjC;AACA;AACA;AACA,CAAC;AAEM,MAAMC,0BAA0B,GAAGJ,yBAAM,CAACC,IAAK;AACtD;AACA;AACA;AACA,CAAC;AAAC;AAMK,MAAMI,oBAAoB,GAAGL,yBAAM,CAACC,IAAgC;AAC3E,aAAa;EAAA,IAAC;IAAEK;EAAiC,CAAC;EAAA,OAAKA,KAAK,CAACC,IAAI;AAAA,CAAC;AAClE,gBAAgB;EAAA,IAAC;IAAEC;EAAgB,CAAC;EAAA,OAAMA,eAAe,GAAG,UAAU,GAAG,UAAU;AAAA,CAAE;AACrF;AACA,MAAM;EAAA,IAAC;IAAEA;EAAgB,CAAC;EAAA,OAClBA,eAAe,IACf,IAAAC,qBAAG,CAAC;AACZ;AACA,6BAA6BP,cAAe;AAC5C,yBAAyB;IAAA,IAAC;MAAEI;IAAiC,CAAC;IAAA,OAAKA,KAAK,CAACC,IAAI;EAAA,CAAC;AAC9E;AACA;AACA;AACA;AACA;AACA,SAAS;AAAA,CAAC;AACV,CAAC;AAAC"}
|
|
1
|
+
{"version":3,"file":"Typewriter.styles.js","names":["StyledTypewriter","styled","span","blinkAnimation","keyframes","StyledTypewriterPseudoText","StyledTypewriterText","theme","text","isAnimatingText","css"],"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.span`\n display: flex;\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;AAA2D;AAAA;AAEpD,MAAMA,gBAAgB,GAAGC,yBAAM,CAACC,IAAK;AAC5C;AACA;AACA,CAAC;AAAC;AAEF,MAAMC,cAAc,GAAG,IAAAC,2BAAS,CAAC;AACjC;AACA;AACA;AACA,CAAC;AAEM,MAAMC,0BAA0B,GAAGJ,yBAAM,CAACC,IAAK;AACtD;AACA;AACA;AACA,CAAC;AAAC;AAMK,MAAMI,oBAAoB,GAAGL,yBAAM,CAACC,IAAgC;AAC3E,aAAa;EAAA,IAAC;IAAEK;EAAiC,CAAC;EAAA,OAAKA,KAAK,CAACC,IAAI;AAAA,CAAC;AAClE,gBAAgB;EAAA,IAAC;IAAEC;EAAgB,CAAC;EAAA,OAAMA,eAAe,GAAG,UAAU,GAAG,UAAU;AAAA,CAAE;AACrF;AACA;AACA,MAAM;EAAA,IAAC;IAAEA;EAAgB,CAAC;EAAA,OAClBA,eAAe,IACf,IAAAC,qBAAG,CAAC;AACZ;AACA,6BAA6BP,cAAe;AAC5C,yBAAyB;IAAA,IAAC;MAAEI;IAAiC,CAAC;IAAA,OAAKA,KAAK,CAACC,IAAI;EAAA,CAAC;AAC9E;AACA;AACA;AACA;AACA;AACA,SAAS;AAAA,CAAC;AACV,CAAC;AAAC"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getSubTextFromHTML = void 0;
|
|
6
|
+
exports.getSubTextFromHTML = exports.getCharactersCount = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* This function extracts a part of the text from an HTML text. The HTML elements themselves are
|
|
9
9
|
* returned in the result. In addition, the function ensures that the closing tag of the Bold HTML
|
|
@@ -59,4 +59,19 @@ const getSubTextFromHTML = (html, length) => {
|
|
|
59
59
|
return text;
|
|
60
60
|
};
|
|
61
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;
|
|
62
77
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["getSubTextFromHTML","html","length","div","document","createElement","innerHTML","text","currLength","traverse","element","nodeType","textContent","nodeText","substring","nodeName","toLowerCase","attributes","attribute","name","value","i","childNodes","childNode"],"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"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,kBAAkB,GAAG,CAACC,IAAY,EAAEC,MAAc,KAAa;EACxE,MAAMC,GAAG,GAAGC,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAEzCF,GAAG,CAACG,SAAS,GAAGL,IAAI;EAEpB,IAAIM,IAAI,GAAG,EAAE;EACb,IAAIC,UAAU,GAAG,CAAC;EAElB,MAAMC,QAAQ,GAAIC,OAAgB,IAAc;IAC5C,IAAIA,OAAO,CAACC,QAAQ,KAAK,CAAC,IAAI,OAAOD,OAAO,CAACE,WAAW,KAAK,QAAQ,EAAE;MACnE,MAAMC,QAAQ,GAAGH,OAAO,CAACE,WAAW;MAEpC,IAAIJ,UAAU,GAAGK,QAAQ,CAACX,MAAM,IAAIA,MAAM,EAAE;QACxCK,IAAI,IAAIM,QAAQ;QAChBL,UAAU,IAAIK,QAAQ,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ement","innerHTML","text","currLength","traverse","element","nodeType","textContent","nodeText","substring","nodeName","toLowerCase","attributes","attribute","name","value","i","childNodes","childNode","getCharactersCount","count","node","trim","Array","from","forEach"],"sources":["../../../src/components/typewriter/utils.ts"],"sourcesContent":["/**\n * This function extracts a part of the text from an HTML text. The HTML elements themselves are\n * returned in the result. In addition, the function ensures that the closing tag of the Bold HTML\n * element is also returned for text that is cut off in the middle of a Bold element, for example.\n *\n * @param html - The text from which a part should be taken\n * @param length - The length of the text to be extracted\n *\n * @return string - The text part with the specified length - additionally the HTML elements are added\n */\nexport const getSubTextFromHTML = (html: string, length: number): string => {\n const div = document.createElement('div');\n\n div.innerHTML = html;\n\n let text = '';\n let currLength = 0;\n\n const traverse = (element: Element): boolean => {\n if (element.nodeType === 3 && typeof element.textContent === 'string') {\n const nodeText = element.textContent;\n\n if (currLength + nodeText.length <= length) {\n text += nodeText;\n currLength += nodeText.length;\n } else {\n text += nodeText.substring(0, length - currLength);\n\n return false;\n }\n } else if (element.nodeType === 1) {\n const nodeName = element.nodeName.toLowerCase();\n\n let attributes = '';\n\n // @ts-expect-error: Type is correct here\n // eslint-disable-next-line no-restricted-syntax\n for (const attribute of element.attributes) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/restrict-template-expressions\n attributes += ` ${attribute.name}=\"${attribute.value}\"`;\n }\n\n text += `<${nodeName}${attributes}>`;\n\n for (let i = 0; i < element.childNodes.length; i++) {\n const childNode = element.childNodes[i];\n\n if (childNode && !traverse(childNode as Element)) {\n return false;\n }\n }\n\n text += `</${nodeName}>`;\n }\n\n return true;\n };\n\n for (let i = 0; i < div.childNodes.length; i++) {\n const childNode = div.childNodes[i];\n\n if (childNode && !traverse(childNode as Element)) {\n return text;\n }\n }\n\n return text;\n};\n\nexport const getCharactersCount = (html: string): number => {\n const div = document.createElement('div');\n\n div.innerHTML = html;\n\n let count = 0;\n\n const traverse = (node: Node): void => {\n if (node.nodeType === 3 && typeof node.textContent === 'string') {\n count += node.textContent.trim().length;\n } else if (node.nodeType === 1) {\n Array.from(node.childNodes).forEach(traverse);\n }\n };\n\n Array.from(div.childNodes).forEach(traverse);\n\n return count;\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,kBAAkB,GAAG,CAACC,IAAY,EAAEC,MAAc,KAAa;EACxE,MAAMC,GAAG,GAAGC,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAEzCF,GAAG,CAACG,SAAS,GAAGL,IAAI;EAEpB,IAAIM,IAAI,GAAG,EAAE;EACb,IAAIC,UAAU,GAAG,CAAC;EAElB,MAAMC,QAAQ,GAAIC,OAAgB,IAAc;IAC5C,IAAIA,OAAO,CAACC,QAAQ,KAAK,CAAC,IAAI,OAAOD,OAAO,CAACE,WAAW,KAAK,QAAQ,EAAE;MACnE,MAAMC,QAAQ,GAAGH,OAAO,CAACE,WAAW;MAEpC,IAAIJ,UAAU,GAAGK,QAAQ,CAACX,MAAM,IAAIA,MAAM,EAAE;QACxCK,IAAI,IAAIM,QAAQ;QAChBL,UAAU,IAAIK,QAAQ,CAACX,MAAM;MACjC,CAAC,MAAM;QACHK,IAAI,IAAIM,QAAQ,CAACC,SAAS,CAAC,CAAC,EAAEZ,MAAM,GAAGM,UAAU,CAAC;QAElD,OAAO,KAAK;MAChB;IACJ,CAAC,MAAM,IAAIE,OAAO,CAACC,QAAQ,KAAK,CAAC,EAAE;MAC/B,MAAMI,QAAQ,GAAGL,OAAO,CAACK,QAAQ,CAACC,WAAW,EAAE;MAE/C,IAAIC,UAAU,GAAG,EAAE;;MAEnB;MACA;MACA,KAAK,MAAMC,SAAS,IAAIR,OAAO,CAACO,UAAU,EAAE;QACxC;QACAA,UAAU,IAAK,IAAGC,SAAS,CAACC,IAAK,KAAID,SAAS,CAACE,KAAM,GAAE;MAC3D;MAEAb,IAAI,IAAK,IAAGQ,QAAS,GAAEE,UAAW,GAAE;MAEpC,KAAK,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,IAAI,CAAC1B,GAAG,CAACmB,UAAU,CAAC,CAACQ,OAAO,CAACrB,QAAQ,CAAC;EAE5C,OAAOgB,KAAK;AAChB,CAAC;AAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { default as Typewriter } from './components/typewriter/Typewriter';
|
|
1
|
+
export { default as Typewriter, TypewriterSpeed } from './components/typewriter/Typewriter';
|
package/lib/index.js
CHANGED
|
@@ -9,6 +9,13 @@ Object.defineProperty(exports, "Typewriter", {
|
|
|
9
9
|
return _Typewriter.default;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
|
-
|
|
13
|
-
|
|
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; }
|
|
14
21
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export { default as Typewriter } from './components/typewriter/Typewriter';\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export { default as Typewriter, TypewriterSpeed } from './components/typewriter/Typewriter';\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AAA4F;AAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chayns-components/typewriter",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.59",
|
|
4
4
|
"description": "A set of beautiful React components for developing your own applications with chayns.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chayns",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"publishConfig": {
|
|
64
64
|
"access": "public"
|
|
65
65
|
},
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "7156cfb6cf8c80809fd4655db8e7b87dbef8ef4e"
|
|
67
67
|
}
|