@chayns-components/typewriter 5.0.52 → 5.0.53-alpha.1

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.
@@ -4,104 +4,113 @@ import { CursorType } from '../../types/cursor';
4
4
  import { TypewriterDelay, TypewriterSpeed } from '../../types/speed';
5
5
  export type TypewriterProps = {
6
6
  /**
7
- * The number of characters that will be animated per animation cycle.
7
+ * The number of characters that will be animated per animation step.
8
+ *
9
+ * The step is advanced by the requestAnimationFrame-driven scheduler. When
10
+ * `shouldCalcAutoSpeed` is enabled, the component may override this value dynamically.
8
11
  */
9
12
  animationSteps?: number;
10
13
  /**
11
- * The text to type
14
+ * The content to type.
15
+ *
16
+ * Strings are animated directly. React elements and arrays are rendered to HTML first so the
17
+ * typewriter can preserve nested markup and inline components.
12
18
  */
13
19
  children: ReactElement | ReactElement[] | string | string[];
14
20
  /**
15
- * The type of the cursor. Use the CursorType enum for this prop.
21
+ * The type of the cursor. Use the `CursorType` enum for this prop.
16
22
  */
17
23
  cursorType?: CursorType;
18
24
  /**
19
25
  * The delay in milliseconds before the next text is shown.
20
- * This prop is only used if multiple texts are given.
26
+ *
27
+ * This prop is only used when `children` is an array.
21
28
  */
22
29
  nextTextDelay?: TypewriterDelay;
23
30
  /**
24
- * Function that is executed when the typewriter animation has finished. This function will not
25
- * be executed if multiple texts are used.
31
+ * Function that is executed when the entire typewriter animation has finished.
32
+ *
33
+ * This callback is not used while more texts are still queued.
26
34
  */
27
35
  onFinish?: VoidFunction;
28
36
  /**
29
- * Function that is executed when the reset animation has finished. This function will not be
30
- * executed if `shouldUseResetAnimation` is not set to `true`.
37
+ * Function that is executed when the reset animation has finished.
38
+ *
39
+ * This callback only runs when `shouldUseResetAnimation` is enabled.
31
40
  */
32
41
  onResetAnimationEnd?: VoidFunction;
33
42
  /**
34
- * Function that is executed when the reset animation has started. This function will not be
35
- * executed if `shouldUseResetAnimation` is not set to `true`.
43
+ * Function that is executed when the reset animation has started.
44
+ *
45
+ * This callback only runs when `shouldUseResetAnimation` is enabled.
36
46
  */
37
47
  onResetAnimationStart?: VoidFunction;
38
48
  /**
39
- * Function that is executed when the typing animation has finished. If multiple texts are given,
40
- * this function will be executed for each text.
49
+ * Function that is executed when the typing animation has finished.
50
+ *
51
+ * If multiple texts are given, this function will be executed for each text.
41
52
  */
42
53
  onTypingAnimationEnd?: VoidFunction;
43
54
  /**
44
- * Function that is executed when the typing animation has started. If multiple texts are given,
45
- * this function will be executed for each text.
55
+ * Function that is executed when the typing animation has started.
56
+ *
57
+ * If multiple texts are given, this function will be executed for each text.
46
58
  */
47
59
  onTypingAnimationStart?: VoidFunction;
48
60
  /**
49
- * Pseudo-element to be rendered invisible during animation to define the size of the element
50
- * for the typewriter effect. By default, the "children" is used for this purpose.
61
+ * Invisible content that defines the reserved layout size while the animation is running.
62
+ *
63
+ * When omitted, the visible `children` are used as the layout template.
51
64
  */
52
65
  pseudoChildren?: ReactElement | string;
53
66
  /**
54
67
  * Waiting time in milliseconds before the typewriter resets the text.
55
- * This prop is only used if multiple texts are given.
68
+ *
69
+ * This prop is only used when `children` is an array.
56
70
  */
57
71
  resetDelay?: TypewriterDelay;
58
72
  /**
59
- * The reset speed of the animation. Use the TypewriterSpeed enum for this prop.
73
+ * The reset speed of the animation. Use the `TypewriterSpeed` enum for this prop.
60
74
  */
61
75
  resetSpeed?: TypewriterSpeed | number;
62
76
  /**
63
- * Specifies whether the cursor should be forced to animate even if no text is currently animated.
77
+ * Keeps the cursor animated even if the current text is not actively changing.
64
78
  */
65
79
  shouldForceCursorAnimation?: boolean;
66
80
  /**
67
- * Specifies whether the cursor should be hidden
81
+ * Hides the cursor entirely.
68
82
  */
69
83
  shouldHideCursor?: boolean;
70
84
  /**
71
- * Whether the content should remain a single line.
85
+ * Keeps the content on a single line and applies ellipsis overflow handling.
72
86
  */
73
87
  shouldRemainSingleLine?: boolean;
74
88
  /**
75
- * Specifies whether the children should be sorted randomly if there are multiple texts.
76
- * This makes the typewriter start with a different text each time and also changes them
77
- * in a random order.
89
+ * Randomizes the order of `children` when multiple texts are provided.
78
90
  */
79
91
  shouldSortChildrenRandomly?: boolean;
80
92
  /**
81
- * Specifies whether the animation should use its full height or the height of the current
82
- * chunk.
93
+ * Makes the hidden sizing text follow the currently revealed chunk instead of the full content.
83
94
  */
84
95
  shouldUseAnimationHeight?: boolean;
85
96
  /**
86
- * Whether the animation speed should be calculated with the chunk interval.
97
+ * Derives the typing cadence from the observed streaming rate.
87
98
  */
88
99
  shouldCalcAutoSpeed?: boolean;
89
100
  /**
90
- * Sets how long the animation should last when `shouldCalcAutoSpeed` is enabled in milliseconds.
91
- * When chunks are streamed, this value will only be used for the initial speed and then change to the speed characters are added at
101
+ * Base factor used to initialize the auto-speed EMA.
92
102
  */
93
103
  autoSpeedBaseFactor?: number;
94
104
  /**
95
- * Specifies whether the reset of the text should be animated with a backspace animation for
96
- * multiple texts.
105
+ * Animates the reset between multiple texts with a backspace-like effect.
97
106
  */
98
107
  shouldUseResetAnimation?: boolean;
99
108
  /**
100
- * Whether the typewriter should wait for new content
109
+ * Keeps the typewriter active while waiting for new content to arrive.
101
110
  */
102
111
  shouldWaitForContent?: boolean;
103
112
  /**
104
- * The speed of the animation. Use the TypewriterSpeed enum for this prop.
113
+ * The speed of the animation. Use the `TypewriterSpeed` enum for this prop.
105
114
  */
106
115
  speed?: TypewriterSpeed | number;
107
116
  /**
@@ -109,7 +118,7 @@ export type TypewriterProps = {
109
118
  */
110
119
  startDelay?: TypewriterDelay;
111
120
  /**
112
- * The style of the typewriter text element
121
+ * Inline styles for the visible text element.
113
122
  */
114
123
  textStyle?: CSSPropertiesWithVars;
115
124
  };
@@ -0,0 +1,30 @@
1
+ import type { MouseEvent, MutableRefObject } from 'react';
2
+ import { CursorType } from '../../types/cursor';
3
+ export type UseTypewriterAnimationOptions = {
4
+ areMultipleChildrenGiven: boolean;
5
+ charactersCount: number;
6
+ cursorType: CursorType;
7
+ onAdvanceText?: VoidFunction;
8
+ nextTextDelay: number;
9
+ onResetAnimationEnd?: VoidFunction;
10
+ onResetAnimationStart?: VoidFunction;
11
+ onTypingAnimationEnd?: VoidFunction;
12
+ onTypingAnimationStart?: VoidFunction;
13
+ resetDelay: number;
14
+ resetSpeed: number;
15
+ shouldUseResetAnimation: boolean;
16
+ shouldWaitForContent?: boolean;
17
+ speed: number;
18
+ startDelay: number;
19
+ textContentLength: number;
20
+ autoSpeedRef: MutableRefObject<number | undefined>;
21
+ autoStepsRef: MutableRefObject<number>;
22
+ };
23
+ export type UseTypewriterAnimationResult = {
24
+ handleClick: (event: MouseEvent) => void;
25
+ isResetAnimationActive: boolean;
26
+ shownCharCount: number;
27
+ shouldPreventBlinkingCursor: boolean;
28
+ };
29
+ declare const useTypewriterAnimation: ({ areMultipleChildrenGiven, charactersCount, cursorType, onAdvanceText, nextTextDelay, onResetAnimationEnd, onResetAnimationStart, onTypingAnimationEnd, onTypingAnimationStart, resetDelay, resetSpeed, shouldUseResetAnimation, shouldWaitForContent, speed, startDelay, textContentLength, autoSpeedRef, autoStepsRef, }: UseTypewriterAnimationOptions) => UseTypewriterAnimationResult;
30
+ export default useTypewriterAnimation;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chayns-components/typewriter",
3
- "version": "5.0.52",
3
+ "version": "5.0.53-alpha.1",
4
4
  "description": "A set of beautiful React components for developing your own applications with chayns.",
5
5
  "sideEffects": false,
6
6
  "browserslist": [
@@ -83,5 +83,5 @@
83
83
  "publishConfig": {
84
84
  "access": "public"
85
85
  },
86
- "gitHead": "3a3e55778a44dd7ecac7aa4d8acb6ab4eebea1c0"
86
+ "gitHead": "69820ddb1ce53b30c0c6dba7b03c89f04e7b89cf"
87
87
  }