@chayns-components/typewriter 5.0.0-beta.98 → 5.0.0-beta.981

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/README.md +4 -15
  2. package/lib/cjs/components/typewriter/AnimatedTypewriterText.js +59 -0
  3. package/lib/cjs/components/typewriter/AnimatedTypewriterText.js.map +1 -0
  4. package/lib/cjs/components/typewriter/Typewriter.js +273 -0
  5. package/lib/cjs/components/typewriter/Typewriter.js.map +1 -0
  6. package/lib/cjs/components/typewriter/Typewriter.styles.js +96 -0
  7. package/lib/cjs/components/typewriter/Typewriter.styles.js.map +1 -0
  8. package/lib/{components → cjs/components}/typewriter/utils.js +43 -3
  9. package/lib/cjs/components/typewriter/utils.js.map +1 -0
  10. package/lib/cjs/index.js +34 -0
  11. package/lib/cjs/index.js.map +1 -0
  12. package/lib/cjs/types/cursor.js +12 -0
  13. package/lib/cjs/types/cursor.js.map +1 -0
  14. package/lib/cjs/types/speed.js +25 -0
  15. package/lib/cjs/types/speed.js.map +1 -0
  16. package/lib/esm/components/typewriter/AnimatedTypewriterText.js +51 -0
  17. package/lib/esm/components/typewriter/AnimatedTypewriterText.js.map +1 -0
  18. package/lib/esm/components/typewriter/Typewriter.js +265 -0
  19. package/lib/esm/components/typewriter/Typewriter.js.map +1 -0
  20. package/lib/esm/components/typewriter/Typewriter.styles.js +101 -0
  21. package/lib/esm/components/typewriter/Typewriter.styles.js.map +1 -0
  22. package/lib/esm/components/typewriter/utils.js +108 -0
  23. package/lib/esm/components/typewriter/utils.js.map +1 -0
  24. package/lib/esm/index.js +4 -0
  25. package/lib/esm/index.js.map +1 -0
  26. package/lib/esm/types/cursor.js +6 -0
  27. package/lib/esm/types/cursor.js.map +1 -0
  28. package/lib/esm/types/speed.js +21 -0
  29. package/lib/esm/types/speed.js.map +1 -0
  30. package/lib/types/components/typewriter/AnimatedTypewriterText.d.ts +8 -0
  31. package/lib/types/components/typewriter/Typewriter.d.ts +111 -0
  32. package/lib/types/components/typewriter/Typewriter.styles.d.ts +19 -0
  33. package/lib/{components → types/components}/typewriter/utils.d.ts +11 -0
  34. package/lib/types/index.d.ts +3 -0
  35. package/lib/types/types/cursor.d.ts +4 -0
  36. package/lib/types/types/speed.d.ts +15 -0
  37. package/package.json +46 -28
  38. package/lib/components/typewriter/Typewriter.d.ts +0 -27
  39. package/lib/components/typewriter/Typewriter.js +0 -128
  40. package/lib/components/typewriter/Typewriter.js.map +0 -1
  41. package/lib/components/typewriter/Typewriter.styles.d.ts +0 -7
  42. package/lib/components/typewriter/Typewriter.styles.js +0 -62
  43. package/lib/components/typewriter/Typewriter.styles.js.map +0 -1
  44. package/lib/components/typewriter/utils.js.map +0 -1
  45. package/lib/index.d.ts +0 -1
  46. package/lib/index.js +0 -21
  47. package/lib/index.js.map +0 -1
@@ -0,0 +1,108 @@
1
+ /**
2
+ * This function extracts a part of the text from an HTML text. The HTML elements themselves are
3
+ * returned in the result. In addition, the function ensures that the closing tag of the Bold HTML
4
+ * element is also returned for text that is cut off in the middle of a Bold element, for example.
5
+ *
6
+ * @param html - The text from which a part should be taken
7
+ * @param length - The length of the text to be extracted
8
+ *
9
+ * @return string - The text part with the specified length - additionally the HTML elements are added
10
+ */
11
+ export const getSubTextFromHTML = (html, length) => {
12
+ const div = document.createElement('div');
13
+ div.innerHTML = html;
14
+ let text = '';
15
+ let currLength = 0;
16
+ const traverse = element => {
17
+ if (element.nodeName === 'TWIGNORE') {
18
+ text += element.innerHTML;
19
+ } else if (element.nodeType === 3 && typeof element.textContent === 'string') {
20
+ const nodeText = element.textContent;
21
+ if (currLength + nodeText.length <= length) {
22
+ text += nodeText;
23
+ currLength += nodeText.length;
24
+ } else {
25
+ text += nodeText.substring(0, length - currLength);
26
+ return false;
27
+ }
28
+ } else if (element.nodeType === 1) {
29
+ const nodeName = element.nodeName.toLowerCase();
30
+ let attributes = '';
31
+
32
+ // @ts-expect-error: Type is correct here
33
+ // eslint-disable-next-line no-restricted-syntax
34
+ for (const attribute of element.attributes) {
35
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/restrict-template-expressions
36
+ attributes += ` ${attribute.name}="${attribute.value}"`;
37
+ }
38
+ text += `<${nodeName}${attributes}>`;
39
+ for (let i = 0; i < element.childNodes.length; i++) {
40
+ const childNode = element.childNodes[i];
41
+ if (childNode && !traverse(childNode)) {
42
+ return false;
43
+ }
44
+ }
45
+ text += `</${nodeName}>`;
46
+ }
47
+ return true;
48
+ };
49
+ for (let i = 0; i < div.childNodes.length; i++) {
50
+ const childNode = div.childNodes[i];
51
+ if (childNode && !traverse(childNode)) {
52
+ return text;
53
+ }
54
+ }
55
+ return text;
56
+ };
57
+ export const getCharactersCount = html => {
58
+ const div = document.createElement('div');
59
+ div.innerHTML = html;
60
+ let count = 0;
61
+ const traverse = node => {
62
+ if (node.nodeName === 'TWIGNORE') {
63
+ count += 1;
64
+ } else if (node.nodeType === 3 && typeof node.textContent === 'string') {
65
+ count += node.textContent.trim().length;
66
+ } else if (node.nodeType === 1) {
67
+ if (node.nodeName === 'CODE' && node.textContent !== null) {
68
+ count += node.textContent.length;
69
+ return;
70
+ }
71
+ Array.from(node.childNodes).forEach(traverse);
72
+ }
73
+ };
74
+ Array.from(div.childNodes).forEach(traverse);
75
+ return count;
76
+ };
77
+ export 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
+ export const calculateAutoSpeed = _ref => {
86
+ let {
87
+ fullTextLength,
88
+ currentPosition,
89
+ baseSpeedFactor
90
+ } = _ref;
91
+ const MIN_SPEED = 1;
92
+ const MAX_SPEED = 10;
93
+ const remainingLength = fullTextLength - currentPosition;
94
+
95
+ // Calculate the speed with the remaining text length and the baseSpeedFactor
96
+ const speed = Math.min(baseSpeedFactor / remainingLength, MAX_SPEED);
97
+ if (speed < MIN_SPEED) {
98
+ return {
99
+ speed: 1,
100
+ steps: 2
101
+ };
102
+ }
103
+ return {
104
+ speed,
105
+ steps: 1
106
+ };
107
+ };
108
+ //# 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","nodeName","nodeType","textContent","nodeText","substring","toLowerCase","attributes","attribute","name","value","i","childNodes","childNode","getCharactersCount","count","node","trim","Array","from","forEach","shuffleArray","array","result","j","Math","floor","random","calculateAutoSpeed","_ref","fullTextLength","currentPosition","baseSpeedFactor","MIN_SPEED","MAX_SPEED","remainingLength","speed","min","steps"],"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.nodeName === 'TWIGNORE') {\n text += element.innerHTML;\n } else 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.nodeName === 'TWIGNORE') {\n count += 1;\n } else if (node.nodeType === 3 && typeof node.textContent === 'string') {\n count += node.textContent.trim().length;\n } else if (node.nodeType === 1) {\n if (node.nodeName === 'CODE' && node.textContent !== null) {\n count += node.textContent.length;\n\n return;\n }\n\n Array.from(node.childNodes).forEach(traverse);\n }\n };\n\n Array.from(div.childNodes).forEach(traverse);\n\n return count;\n};\n\nexport const shuffleArray = <T>(array: T[]): T[] => {\n const result = Array.from(array);\n\n for (let i = result.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n\n [result[i], result[j]] = [result[j]!, result[i]!];\n }\n\n return result;\n};\n\ninterface CalculateAutoSpeedProps {\n fullTextLength: number;\n currentPosition: number;\n baseSpeedFactor: number;\n}\n\nexport const calculateAutoSpeed = ({\n fullTextLength,\n currentPosition,\n baseSpeedFactor,\n}: CalculateAutoSpeedProps): { speed: number; steps: number } => {\n const MIN_SPEED = 1;\n const MAX_SPEED = 10;\n\n const remainingLength = fullTextLength - currentPosition;\n\n // Calculate the speed with the remaining text length and the baseSpeedFactor\n const speed = Math.min(baseSpeedFactor / remainingLength, MAX_SPEED);\n\n if (speed < MIN_SPEED) {\n return { speed: 1, steps: 2 };\n }\n\n return { speed, steps: 1 };\n};\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,kBAAkB,GAAGA,CAACC,IAAY,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F,KAAK;IAAEE,KAAK,EAAE;EAAE,CAAC;AAC9B,CAAC","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ export { default as Typewriter } from './components/typewriter/Typewriter';
2
+ export { CursorType } from './types/cursor';
3
+ export { TypewriterDelay, TypewriterSpeed } from './types/speed';
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["default","Typewriter","CursorType","TypewriterDelay","TypewriterSpeed"],"sources":["../../src/index.ts"],"sourcesContent":["export { default as Typewriter } from './components/typewriter/Typewriter';\nexport { CursorType } from './types/cursor';\nexport { TypewriterDelay, TypewriterSpeed } from './types/speed';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,UAAU,QAAQ,oCAAoC;AAC1E,SAASC,UAAU,QAAQ,gBAAgB;AAC3C,SAASC,eAAe,EAAEC,eAAe,QAAQ,eAAe","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ export let CursorType = /*#__PURE__*/function (CursorType) {
2
+ CursorType["Default"] = "default";
3
+ CursorType["Thin"] = "thin";
4
+ return CursorType;
5
+ }({});
6
+ //# sourceMappingURL=cursor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cursor.js","names":["CursorType"],"sources":["../../../src/types/cursor.ts"],"sourcesContent":["export enum CursorType {\n Default = 'default',\n Thin = 'thin',\n}\n"],"mappings":"AAAA,WAAYA,UAAU,0BAAVA,UAAU;EAAVA,UAAU;EAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA","ignoreList":[]}
@@ -0,0 +1,21 @@
1
+ // noinspection JSUnusedGlobalSymbols
2
+ export let TypewriterDelay = /*#__PURE__*/function (TypewriterDelay) {
3
+ TypewriterDelay[TypewriterDelay["ExtraSlow"] = 4000] = "ExtraSlow";
4
+ TypewriterDelay[TypewriterDelay["Slow"] = 2000] = "Slow";
5
+ TypewriterDelay[TypewriterDelay["Medium"] = 1000] = "Medium";
6
+ TypewriterDelay[TypewriterDelay["Fast"] = 500] = "Fast";
7
+ TypewriterDelay[TypewriterDelay["ExtraFast"] = 250] = "ExtraFast";
8
+ TypewriterDelay[TypewriterDelay["None"] = 0] = "None";
9
+ return TypewriterDelay;
10
+ }({});
11
+
12
+ // noinspection JSUnusedGlobalSymbols
13
+ export let TypewriterSpeed = /*#__PURE__*/function (TypewriterSpeed) {
14
+ TypewriterSpeed[TypewriterSpeed["ExtraSlow"] = 40] = "ExtraSlow";
15
+ TypewriterSpeed[TypewriterSpeed["Slow"] = 20] = "Slow";
16
+ TypewriterSpeed[TypewriterSpeed["Medium"] = 10] = "Medium";
17
+ TypewriterSpeed[TypewriterSpeed["Fast"] = 5] = "Fast";
18
+ TypewriterSpeed[TypewriterSpeed["ExtraFast"] = 2.5] = "ExtraFast";
19
+ return TypewriterSpeed;
20
+ }({});
21
+ //# sourceMappingURL=speed.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"speed.js","names":["TypewriterDelay","TypewriterSpeed"],"sources":["../../../src/types/speed.ts"],"sourcesContent":["// noinspection JSUnusedGlobalSymbols\nexport enum TypewriterDelay {\n ExtraSlow = 4000,\n Slow = 2000,\n Medium = 1000,\n Fast = 500,\n ExtraFast = 250,\n None = 0,\n}\n\n// noinspection JSUnusedGlobalSymbols\nexport enum TypewriterSpeed {\n ExtraSlow = 40,\n Slow = 20,\n Medium = 10,\n Fast = 5,\n ExtraFast = 2.5,\n}\n"],"mappings":"AAAA;AACA,WAAYA,eAAe,0BAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAA,OAAfA,eAAe;AAAA;;AAS3B;AACA,WAAYC,eAAe,0BAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAfA,eAAe,CAAfA,eAAe;EAAA,OAAfA,eAAe;AAAA","ignoreList":[]}
@@ -0,0 +1,8 @@
1
+ import React, { FC } from 'react';
2
+ type AnimatedTypewriterTextProps = {
3
+ shouldHideCursor: boolean;
4
+ shownText: string;
5
+ textStyle?: React.CSSProperties;
6
+ };
7
+ declare const AnimatedTypewriterText: FC<AnimatedTypewriterTextProps>;
8
+ export default AnimatedTypewriterText;
@@ -0,0 +1,111 @@
1
+ import React, { FC, ReactElement } from 'react';
2
+ import { CursorType } from '../../types/cursor';
3
+ import { TypewriterDelay, TypewriterSpeed } from '../../types/speed';
4
+ export type TypewriterProps = {
5
+ /**
6
+ * The amount of characters that will be animated per animation cycle.
7
+ */
8
+ animationSteps?: number;
9
+ /**
10
+ * The base speed factor to calculate the animation speed.
11
+ */
12
+ autoSpeedBaseFactor?: number;
13
+ /**
14
+ * The text to type
15
+ */
16
+ children: ReactElement | ReactElement[] | string | string[];
17
+ /**
18
+ * The type of the cursor. Use the CursorType enum for this prop.
19
+ */
20
+ cursorType?: CursorType;
21
+ /**
22
+ * The delay in milliseconds before the next text is shown.
23
+ * This prop is only used if multiple texts are given.
24
+ */
25
+ nextTextDelay?: TypewriterDelay;
26
+ /**
27
+ * Function that is executed when the typewriter animation has finished. This function will not
28
+ * be executed if multiple texts are used.
29
+ */
30
+ onFinish?: VoidFunction;
31
+ /**
32
+ * Function that is executed when the reset animation has finished. This function will not be
33
+ * executed if `shouldUseResetAnimation` is not set to `true`.
34
+ */
35
+ onResetAnimationEnd?: VoidFunction;
36
+ /**
37
+ * Function that is executed when the reset animation has started. This function will not be
38
+ * executed if `shouldUseResetAnimation` is not set to `true`.
39
+ */
40
+ onResetAnimationStart?: VoidFunction;
41
+ /**
42
+ * Function that is executed when the typing animation has finished. If multiple texts are given,
43
+ * this function will be executed for each text.
44
+ */
45
+ onTypingAnimationEnd?: VoidFunction;
46
+ /**
47
+ * Function that is executed when the typing animation has started. If multiple texts are given,
48
+ * this function will be executed for each text.
49
+ */
50
+ onTypingAnimationStart?: VoidFunction;
51
+ /**
52
+ * Pseudo-element to be rendered invisible during animation to define the size of the element
53
+ * for the typewriter effect. By default, the "children" is used for this purpose.
54
+ */
55
+ pseudoChildren?: ReactElement | string;
56
+ /**
57
+ * Waiting time in milliseconds before the typewriter resets the text.
58
+ * This prop is only used if multiple texts are given.
59
+ */
60
+ resetDelay?: TypewriterDelay;
61
+ /**
62
+ * The reset speed of the animation. Use the TypewriterSpeed enum for this prop.
63
+ */
64
+ resetSpeed?: TypewriterSpeed | number;
65
+ /**
66
+ * Specifies whether the cursor should be forced to animate even if no text is currently animated.
67
+ */
68
+ shouldForceCursorAnimation?: boolean;
69
+ /**
70
+ * Specifies whether the cursor should be hidden
71
+ */
72
+ shouldHideCursor?: boolean;
73
+ /**
74
+ * Specifies whether the children should be sorted randomly if there are multiple texts.
75
+ * This makes the typewriter start with a different text each time and also changes them
76
+ * in a random order.
77
+ */
78
+ shouldSortChildrenRandomly?: boolean;
79
+ /**
80
+ * Specifies whether the animation should use its full height or the height of the current
81
+ * chunk.
82
+ */
83
+ shouldUseAnimationHeight?: boolean;
84
+ /**
85
+ * Whether the animation speed should be calculated with the chunk interval.
86
+ */
87
+ shouldCalcAutoSpeed?: boolean;
88
+ /**
89
+ * Specifies whether the reset of the text should be animated with a backspace animation for
90
+ * multiple texts.
91
+ */
92
+ shouldUseResetAnimation?: boolean;
93
+ /**
94
+ * Whether the typewriter should wait for new content
95
+ */
96
+ shouldWaitForContent?: boolean;
97
+ /**
98
+ * The speed of the animation. Use the TypewriterSpeed enum for this prop.
99
+ */
100
+ speed?: TypewriterSpeed | number;
101
+ /**
102
+ * The delay in milliseconds before the typewriter starts typing.
103
+ */
104
+ startDelay?: TypewriterDelay;
105
+ /**
106
+ * The style of the typewriter text element
107
+ */
108
+ textStyle?: React.CSSProperties;
109
+ };
110
+ declare const Typewriter: FC<TypewriterProps>;
111
+ export default Typewriter;
@@ -0,0 +1,19 @@
1
+ import type { WithTheme } from '@chayns-components/core';
2
+ import type { TypewriterProps } from './Typewriter';
3
+ type StyledTypewriterProps = WithTheme<{
4
+ $cursorType: TypewriterProps['cursorType'];
5
+ $isAnimatingText: boolean;
6
+ $shouldHideCursor: TypewriterProps['shouldHideCursor'];
7
+ $shouldPreventBlinkAnimation: boolean;
8
+ }>;
9
+ export declare const StyledTypewriter: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, StyledTypewriterProps>> & string;
10
+ type StyledTypewriterPseudoTextProps = WithTheme<{
11
+ $isAnimatingText?: boolean;
12
+ $shouldHideCursor: TypewriterProps['shouldHideCursor'];
13
+ }>;
14
+ export declare const StyledTypewriterPseudoText: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, StyledTypewriterPseudoTextProps>> & string;
15
+ type StyledTypewriterTextProps = WithTheme<{
16
+ $isAnimatingText?: boolean;
17
+ }>;
18
+ export declare const StyledTypewriterText: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, StyledTypewriterTextProps>> & string;
19
+ export {};
@@ -10,3 +10,14 @@
10
10
  */
11
11
  export declare const getSubTextFromHTML: (html: string, length: number) => string;
12
12
  export declare const getCharactersCount: (html: string) => number;
13
+ export declare const shuffleArray: <T>(array: T[]) => T[];
14
+ interface CalculateAutoSpeedProps {
15
+ fullTextLength: number;
16
+ currentPosition: number;
17
+ baseSpeedFactor: number;
18
+ }
19
+ export declare const calculateAutoSpeed: ({ fullTextLength, currentPosition, baseSpeedFactor, }: CalculateAutoSpeedProps) => {
20
+ speed: number;
21
+ steps: number;
22
+ };
23
+ export {};
@@ -0,0 +1,3 @@
1
+ export { default as Typewriter } from './components/typewriter/Typewriter';
2
+ export { CursorType } from './types/cursor';
3
+ export { TypewriterDelay, TypewriterSpeed } from './types/speed';
@@ -0,0 +1,4 @@
1
+ export declare enum CursorType {
2
+ Default = "default",
3
+ Thin = "thin"
4
+ }
@@ -0,0 +1,15 @@
1
+ export declare enum TypewriterDelay {
2
+ ExtraSlow = 4000,
3
+ Slow = 2000,
4
+ Medium = 1000,
5
+ Fast = 500,
6
+ ExtraFast = 250,
7
+ None = 0
8
+ }
9
+ export declare enum TypewriterSpeed {
10
+ ExtraSlow = 40,
11
+ Slow = 20,
12
+ Medium = 10,
13
+ Fast = 5,
14
+ ExtraFast = 2.5
15
+ }
package/package.json CHANGED
@@ -1,7 +1,14 @@
1
1
  {
2
2
  "name": "@chayns-components/typewriter",
3
- "version": "5.0.0-beta.98",
3
+ "version": "5.0.0-beta.981",
4
4
  "description": "A set of beautiful React components for developing your own applications with chayns.",
5
+ "sideEffects": false,
6
+ "browserslist": [
7
+ ">0.5%",
8
+ "not dead",
9
+ "not op_mini all",
10
+ "not IE 11"
11
+ ],
5
12
  "keywords": [
6
13
  "chayns",
7
14
  "react",
@@ -10,8 +17,16 @@
10
17
  "author": "Tobit.Software",
11
18
  "homepage": "https://github.com/TobitSoftware/chayns-components/tree/main/packages/typewriter#readme",
12
19
  "license": "MIT",
13
- "main": "lib/index.js",
14
- "types": "lib/index.d.ts",
20
+ "types": "lib/types/index.d.ts",
21
+ "main": "lib/cjs/index.js",
22
+ "module": "lib/esm/index.js",
23
+ "exports": {
24
+ ".": {
25
+ "types": "./lib/types/index.d.ts",
26
+ "require": "./lib/cjs/index.js",
27
+ "import": "./lib/esm/index.js"
28
+ }
29
+ },
15
30
  "directories": {
16
31
  "lib": "lib",
17
32
  "test": "__tests__"
@@ -24,44 +39,47 @@
24
39
  "url": "git+https://github.com/TobitSoftware/chayns-components.git"
25
40
  },
26
41
  "scripts": {
27
- "build": "npm run build:js && npm run build:types",
28
- "build:js": "babel src --out-dir lib --extensions=.ts,.tsx --source-maps --ignore=src/stories",
42
+ "build": "npm run build:cjs && npm run build:esm && npm run build:types",
29
43
  "build:types": "tsc",
30
- "prepublishOnly": "npm run build"
44
+ "build:cjs": "cross-env NODE_ENV=cjs babel src --out-dir lib/cjs --extensions=.ts,.tsx --source-maps --ignore=src/stories",
45
+ "build:esm": "cross-env NODE_ENV=esm babel src --out-dir lib/esm --extensions=.ts,.tsx --source-maps --ignore=src/stories",
46
+ "prepublishOnly": "npm run build",
47
+ "watch:js": "npm run build:esm -- --watch",
48
+ "link": "npm link && npm run watch:js"
31
49
  },
32
50
  "bugs": {
33
51
  "url": "https://github.com/TobitSoftware/chayns-components/issues"
34
52
  },
35
53
  "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"
54
+ "@babel/cli": "^7.26.4",
55
+ "@babel/core": "^7.26.0",
56
+ "@babel/preset-env": "^7.26.0",
57
+ "@babel/preset-react": "^7.26.3",
58
+ "@babel/preset-typescript": "^7.26.0",
59
+ "@types/react": "^18.3.18",
60
+ "@types/react-dom": "^18.3.5",
61
+ "@types/styled-components": "^5.1.34",
62
+ "@types/uuid": "^10.0.0",
63
+ "babel-loader": "^9.2.1",
64
+ "cross-env": "^7.0.3",
65
+ "lerna": "^8.1.9",
66
+ "react": "^18.3.1",
67
+ "react-dom": "^18.3.1",
68
+ "styled-components": "^6.1.14",
69
+ "typescript": "^5.7.3"
50
70
  },
51
71
  "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"
72
+ "@chayns-components/core": "^5.0.0-beta.981"
58
73
  },
59
74
  "peerDependencies": {
75
+ "chayns-api": ">=1.0.73",
76
+ "framer-motion": ">=10.18.0",
60
77
  "react": ">=16.14.0",
61
- "react-dom": ">=16.14.0"
78
+ "react-dom": ">=16.14.0",
79
+ "styled-components": ">=5.3.11"
62
80
  },
63
81
  "publishConfig": {
64
82
  "access": "public"
65
83
  },
66
- "gitHead": "ee7237bbc5e9a51e98268f74989f98da251255c1"
84
+ "gitHead": "a5d2942d7a6adea7b282fcbcb9f490af90517978"
67
85
  }
@@ -1,27 +0,0 @@
1
- import { FC, ReactElement } from 'react';
2
- export declare enum TypewriterResetDelay {
3
- Slow = 3000,
4
- Medium = 1500,
5
- Fast = 750
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
- * The speed of the animation. Use the TypewriterSpeed enum for this prop.
23
- */
24
- speed?: TypewriterSpeed;
25
- };
26
- declare const Typewriter: FC<TypewriterProps>;
27
- export default Typewriter;
@@ -1,128 +0,0 @@
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"] = 3000] = "Slow";
17
- TypewriterResetDelay[TypewriterResetDelay["Medium"] = 1500] = "Medium";
18
- TypewriterResetDelay[TypewriterResetDelay["Fast"] = 750] = "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
- speed = TypewriterSpeed.Medium
32
- } = _ref;
33
- const [currentChildrenIndex, setCurrentChildrenIndex] = (0, _react.useState)(0);
34
- const areMultipleChildrenGiven = Array.isArray(children);
35
- const childrenCount = areMultipleChildrenGiven ? children.length : 1;
36
- const textContent = (0, _react.useMemo)(() => {
37
- if (areMultipleChildrenGiven) {
38
- const currentChildren = children[currentChildrenIndex];
39
- if (currentChildren) {
40
- return /*#__PURE__*/_react.default.isValidElement(currentChildren) ? (0, _server.renderToString)(currentChildren) : currentChildren;
41
- }
42
- return '';
43
- }
44
- return /*#__PURE__*/_react.default.isValidElement(children) ? (0, _server.renderToString)(children) : children;
45
- }, [areMultipleChildrenGiven, children, currentChildrenIndex]);
46
- const charactersCount = (0, _react.useMemo)(() => (0, _utils.getCharactersCount)(textContent), [textContent]);
47
- const [isResetAnimationActive, setIsResetAnimationActive] = (0, _react.useState)(false);
48
- const [shownCharCount, setShownCharCount] = (0, _react.useState)(charactersCount > 0 ? 0 : textContent.length);
49
- const [shouldStopAnimation, setShouldStopAnimation] = (0, _react.useState)(false);
50
- const isAnimatingText = shownCharCount !== textContent.length || areMultipleChildrenGiven;
51
- const handleClick = (0, _react.useCallback)(() => {
52
- setShouldStopAnimation(true);
53
- }, []);
54
- (0, _react.useEffect)(() => {
55
- let interval;
56
- if (shouldStopAnimation || charactersCount === 0) {
57
- setShownCharCount(textContent.length);
58
- } else if (isResetAnimationActive) {
59
- interval = window.setInterval(() => {
60
- setShownCharCount(prevState => {
61
- const nextState = prevState - 1;
62
- if (nextState === 0) {
63
- window.clearInterval(interval);
64
- if (areMultipleChildrenGiven) {
65
- setTimeout(() => {
66
- setIsResetAnimationActive(false);
67
- setCurrentChildrenIndex(currentIndex => {
68
- let newIndex = currentIndex + 1;
69
- if (newIndex > childrenCount - 1) {
70
- newIndex = 0;
71
- }
72
- return newIndex;
73
- });
74
- }, resetDelay);
75
- }
76
- }
77
- return nextState;
78
- });
79
- }, speed);
80
- } else {
81
- interval = window.setInterval(() => {
82
- setShownCharCount(prevState => {
83
- let nextState = prevState + 1;
84
- if (nextState === charactersCount) {
85
- window.clearInterval(interval);
86
-
87
- /**
88
- * At this point, the next value for "shownCharCount" is deliberately set to
89
- * the length of the textContent in order to correctly display HTML elements
90
- * after the last letter.
91
- */
92
- nextState = textContent.length;
93
- if (areMultipleChildrenGiven) {
94
- setTimeout(setIsResetAnimationActive, resetDelay, true);
95
- }
96
- }
97
- return nextState;
98
- });
99
- }, speed);
100
- }
101
- return () => {
102
- window.clearInterval(interval);
103
- };
104
- }, [shouldStopAnimation, speed, textContent.length, charactersCount, isResetAnimationActive, areMultipleChildrenGiven, resetDelay, childrenCount]);
105
- (0, _react.useEffect)(() => {
106
- if (charactersCount) {
107
- setIsResetAnimationActive(false);
108
- setShownCharCount(0);
109
- }
110
- }, [charactersCount]);
111
- const shownText = (0, _react.useMemo)(() => (0, _utils.getSubTextFromHTML)(textContent, shownCharCount), [shownCharCount, textContent]);
112
- return /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriter, {
113
- onClick: handleClick
114
- }, isAnimatingText ? /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriterText, {
115
- dangerouslySetInnerHTML: {
116
- __html: shownText
117
- },
118
- isAnimatingText: true
119
- }) : /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriterText, null, children), isAnimatingText && /*#__PURE__*/_react.default.createElement(_Typewriter.StyledTypewriterPseudoText, {
120
- dangerouslySetInnerHTML: {
121
- __html: textContent
122
- }
123
- }));
124
- };
125
- Typewriter.displayName = 'Typewriter';
126
- var _default = Typewriter;
127
- exports.default = _default;
128
- //# sourceMappingURL=Typewriter.js.map