ink-motion 0.1.0

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.
@@ -0,0 +1,262 @@
1
+ import React from 'react';
2
+
3
+ /**
4
+ * Colour value as hex (#ff0000), rgb (rgb(255,0,0)), or named (red, blue, etc.)
5
+ * Note: Props use 'color' (US spelling) for React convention, but type uses UK spelling
6
+ */
7
+ type Colour = string;
8
+ /**
9
+ * @deprecated Use Colour instead
10
+ */
11
+ type Color = Colour;
12
+ /**
13
+ * Easing function that takes normalised time (0-1) and returns eased value (0-1)
14
+ */
15
+ type EasingFunction = (time: number) => number;
16
+ /**
17
+ * Named easing functions
18
+ */
19
+ type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out';
20
+ /**
21
+ * Base props shared by all effect components
22
+ */
23
+ interface BaseEffectProps {
24
+ /**
25
+ * Text to animate (required)
26
+ */
27
+ children: string;
28
+ /**
29
+ * Animation speed multiplier
30
+ * @default 1
31
+ * @example 0.5 // half speed
32
+ * @example 2 // double speed
33
+ */
34
+ speed?: number;
35
+ /**
36
+ * Enable/disable animation
37
+ * @default true
38
+ */
39
+ enabled?: boolean;
40
+ /**
41
+ * Callback when animation completes
42
+ */
43
+ onComplete?: () => void;
44
+ }
45
+
46
+ type ShimmerDirection = 'left' | 'right';
47
+ interface ShimmerProps extends BaseEffectProps {
48
+ /**
49
+ * Gradient colours for the shimmer effect [start, peak, end]
50
+ * @default ['#666666', '#ffffff', '#666666']
51
+ * @example ['#60a5fa', '#3b82f6', '#60a5fa']
52
+ */
53
+ colors?: [Colour, Colour, Colour];
54
+ /**
55
+ * Width of the shimmer band in characters
56
+ * @default 4
57
+ */
58
+ width?: number;
59
+ /**
60
+ * Brightness multiplier (0-1)
61
+ * @default 1
62
+ */
63
+ intensity?: number;
64
+ /**
65
+ * Direction of shimmer movement
66
+ * @default 'right'
67
+ */
68
+ direction?: ShimmerDirection;
69
+ }
70
+ /**
71
+ * Shimmer effect component that creates a moving highlight across text
72
+ *
73
+ * Creates a shimmering animation by interpolating through a gradient of colours
74
+ * that sweeps across the text from left to right or right to left.
75
+ *
76
+ * @example
77
+ * ```tsx
78
+ * <Shimmer colors={['#60a5fa', '#3b82f6', '#60a5fa']} intensity={0.8}>
79
+ * Loading...
80
+ * </Shimmer>
81
+ * ```
82
+ */
83
+ declare function Shimmer({ children, colors, width, intensity, direction, speed, enabled, onComplete, }: ShimmerProps): React.JSX.Element;
84
+
85
+ interface TypewriterProps extends BaseEffectProps {
86
+ /**
87
+ * Text colour
88
+ * @default undefined (inherits)
89
+ * @example 'green'
90
+ */
91
+ color?: Colour;
92
+ /**
93
+ * Cursor character or false to disable
94
+ * @default '▋'
95
+ * @example '█'
96
+ */
97
+ cursor?: string | boolean;
98
+ /**
99
+ * Cursor colour (defaults to text colour)
100
+ * @default undefined
101
+ * @example 'cyan'
102
+ */
103
+ cursorColor?: Colour;
104
+ /**
105
+ * Typing speed randomness (0-1) for more human-like typing
106
+ * @default 0.3
107
+ */
108
+ variance?: number;
109
+ /**
110
+ * Initial delay before typing starts (ms)
111
+ * @default 0
112
+ */
113
+ delay?: number;
114
+ }
115
+ /**
116
+ * Typewriter effect component that reveals text character by character
117
+ *
118
+ * Simulates typing text with configurable speed, variance for realistic timing,
119
+ * and an optional cursor. The cursor blinks while typing is in progress.
120
+ *
121
+ * @example
122
+ * ```tsx
123
+ * <Typewriter color="green" cursor="█" variance={0.5} speed={2}>
124
+ * npm install ink-motion
125
+ * </Typewriter>
126
+ * ```
127
+ */
128
+ declare function Typewriter({ children, color, cursor, cursorColor, variance, delay, speed, enabled, onComplete, }: TypewriterProps): React.JSX.Element;
129
+
130
+ interface FadeProps extends BaseEffectProps {
131
+ /**
132
+ * Text colour
133
+ * @default '#ffffff'
134
+ * @example 'yellow'
135
+ */
136
+ color?: Colour;
137
+ /**
138
+ * Starting opacity (0-1)
139
+ * @default 0
140
+ */
141
+ from?: number;
142
+ /**
143
+ * Ending opacity (0-1)
144
+ * @default 1
145
+ */
146
+ to?: number;
147
+ /**
148
+ * Duration in milliseconds
149
+ * @default 1000
150
+ */
151
+ duration?: number;
152
+ /**
153
+ * Easing function
154
+ * @default 'ease-out'
155
+ */
156
+ easing?: EasingName;
157
+ /**
158
+ * Loop animation continuously
159
+ * @default false
160
+ */
161
+ loop?: boolean;
162
+ }
163
+ /**
164
+ * Fade effect component that smoothly transitions text opacity
165
+ *
166
+ * Animates text from one opacity to another using configurable easing functions.
167
+ * Can loop continuously or run once.
168
+ *
169
+ * @example
170
+ * ```tsx
171
+ * <Fade color="yellow" from={0} to={1} duration={500} easing="ease-in">
172
+ * Success!
173
+ * </Fade>
174
+ * ```
175
+ */
176
+ declare function Fade({ children, color, from, to, duration, easing, loop, speed, enabled, onComplete, }: FadeProps): React.JSX.Element;
177
+
178
+ type WaveType = 'brightness' | 'vertical';
179
+ interface WaveProps extends BaseEffectProps {
180
+ /**
181
+ * Gradient colours for the wave [dark, bright]
182
+ * @default ['#888888', '#ffffff']
183
+ * @example ['#ec4899', '#8b5cf6']
184
+ */
185
+ colors?: [Colour, Colour];
186
+ /**
187
+ * Wave height (0-1)
188
+ * @default 0.5
189
+ */
190
+ amplitude?: number;
191
+ /**
192
+ * Number of wave cycles across text
193
+ * @default 2
194
+ */
195
+ frequency?: number;
196
+ /**
197
+ * Wave effect type
198
+ * @default 'brightness'
199
+ */
200
+ type?: WaveType;
201
+ }
202
+ /**
203
+ * Wave effect component that creates a wave motion through text
204
+ *
205
+ * Animates text with a sine wave pattern that can affect brightness or vertical position.
206
+ * The wave continuously flows through the text.
207
+ *
208
+ * @example
209
+ * ```tsx
210
+ * <Wave colors={['#ec4899', '#8b5cf6']} amplitude={0.7} frequency={3}>
211
+ * ~~ wavy text ~~
212
+ * </Wave>
213
+ * ```
214
+ */
215
+ declare function Wave({ children, colors, amplitude, frequency, type, speed, enabled, }: WaveProps): React.JSX.Element;
216
+
217
+ /**
218
+ * Runs a callback on every animation frame using setInterval
219
+ *
220
+ * @param callback - Function called each frame with delta time in ms
221
+ * @param enabled - Whether animation is active
222
+ */
223
+ declare function useAnimationFrame(callback: (deltaTime: number) => void, enabled?: boolean): void;
224
+
225
+ /**
226
+ * Hook that tracks elapsed time since mount or last reset
227
+ *
228
+ * @param enabled - Whether to track time
229
+ * @param speed - Speed multiplier (default: 1)
230
+ * @returns Elapsed time in milliseconds
231
+ */
232
+ declare function useElapsedTime(enabled?: boolean, speed?: number): number;
233
+
234
+ interface UseCursorBlinkOptions {
235
+ enabled: boolean;
236
+ isComplete: boolean;
237
+ }
238
+ /**
239
+ * Hook that manages cursor blinking state
240
+ *
241
+ * @param options - Configuration for cursor blink
242
+ * @returns Whether cursor should be visible
243
+ */
244
+ declare function useCursorBlink({ enabled, isComplete, }: UseCursorBlinkOptions): boolean;
245
+
246
+ interface UseTypewriterProgressOptions {
247
+ totalCharacters: number;
248
+ speed: number;
249
+ variance: number;
250
+ initialDelay: number;
251
+ enabled: boolean;
252
+ onComplete?: () => void;
253
+ }
254
+ /**
255
+ * Hook that manages typewriter character reveal timing
256
+ *
257
+ * @param options - Configuration for typewriter progress
258
+ * @returns Number of characters to display
259
+ */
260
+ declare function useTypewriterProgress({ totalCharacters, speed, variance, initialDelay, enabled, onComplete, }: UseTypewriterProgressOptions): number;
261
+
262
+ export { type BaseEffectProps, type Color, type Colour, type EasingFunction, type EasingName, Fade, Shimmer, Typewriter, Wave, useAnimationFrame, useCursorBlink, useElapsedTime, useTypewriterProgress };
@@ -0,0 +1,262 @@
1
+ import React from 'react';
2
+
3
+ /**
4
+ * Colour value as hex (#ff0000), rgb (rgb(255,0,0)), or named (red, blue, etc.)
5
+ * Note: Props use 'color' (US spelling) for React convention, but type uses UK spelling
6
+ */
7
+ type Colour = string;
8
+ /**
9
+ * @deprecated Use Colour instead
10
+ */
11
+ type Color = Colour;
12
+ /**
13
+ * Easing function that takes normalised time (0-1) and returns eased value (0-1)
14
+ */
15
+ type EasingFunction = (time: number) => number;
16
+ /**
17
+ * Named easing functions
18
+ */
19
+ type EasingName = 'linear' | 'ease-in' | 'ease-out' | 'ease-in-out';
20
+ /**
21
+ * Base props shared by all effect components
22
+ */
23
+ interface BaseEffectProps {
24
+ /**
25
+ * Text to animate (required)
26
+ */
27
+ children: string;
28
+ /**
29
+ * Animation speed multiplier
30
+ * @default 1
31
+ * @example 0.5 // half speed
32
+ * @example 2 // double speed
33
+ */
34
+ speed?: number;
35
+ /**
36
+ * Enable/disable animation
37
+ * @default true
38
+ */
39
+ enabled?: boolean;
40
+ /**
41
+ * Callback when animation completes
42
+ */
43
+ onComplete?: () => void;
44
+ }
45
+
46
+ type ShimmerDirection = 'left' | 'right';
47
+ interface ShimmerProps extends BaseEffectProps {
48
+ /**
49
+ * Gradient colours for the shimmer effect [start, peak, end]
50
+ * @default ['#666666', '#ffffff', '#666666']
51
+ * @example ['#60a5fa', '#3b82f6', '#60a5fa']
52
+ */
53
+ colors?: [Colour, Colour, Colour];
54
+ /**
55
+ * Width of the shimmer band in characters
56
+ * @default 4
57
+ */
58
+ width?: number;
59
+ /**
60
+ * Brightness multiplier (0-1)
61
+ * @default 1
62
+ */
63
+ intensity?: number;
64
+ /**
65
+ * Direction of shimmer movement
66
+ * @default 'right'
67
+ */
68
+ direction?: ShimmerDirection;
69
+ }
70
+ /**
71
+ * Shimmer effect component that creates a moving highlight across text
72
+ *
73
+ * Creates a shimmering animation by interpolating through a gradient of colours
74
+ * that sweeps across the text from left to right or right to left.
75
+ *
76
+ * @example
77
+ * ```tsx
78
+ * <Shimmer colors={['#60a5fa', '#3b82f6', '#60a5fa']} intensity={0.8}>
79
+ * Loading...
80
+ * </Shimmer>
81
+ * ```
82
+ */
83
+ declare function Shimmer({ children, colors, width, intensity, direction, speed, enabled, onComplete, }: ShimmerProps): React.JSX.Element;
84
+
85
+ interface TypewriterProps extends BaseEffectProps {
86
+ /**
87
+ * Text colour
88
+ * @default undefined (inherits)
89
+ * @example 'green'
90
+ */
91
+ color?: Colour;
92
+ /**
93
+ * Cursor character or false to disable
94
+ * @default '▋'
95
+ * @example '█'
96
+ */
97
+ cursor?: string | boolean;
98
+ /**
99
+ * Cursor colour (defaults to text colour)
100
+ * @default undefined
101
+ * @example 'cyan'
102
+ */
103
+ cursorColor?: Colour;
104
+ /**
105
+ * Typing speed randomness (0-1) for more human-like typing
106
+ * @default 0.3
107
+ */
108
+ variance?: number;
109
+ /**
110
+ * Initial delay before typing starts (ms)
111
+ * @default 0
112
+ */
113
+ delay?: number;
114
+ }
115
+ /**
116
+ * Typewriter effect component that reveals text character by character
117
+ *
118
+ * Simulates typing text with configurable speed, variance for realistic timing,
119
+ * and an optional cursor. The cursor blinks while typing is in progress.
120
+ *
121
+ * @example
122
+ * ```tsx
123
+ * <Typewriter color="green" cursor="█" variance={0.5} speed={2}>
124
+ * npm install ink-motion
125
+ * </Typewriter>
126
+ * ```
127
+ */
128
+ declare function Typewriter({ children, color, cursor, cursorColor, variance, delay, speed, enabled, onComplete, }: TypewriterProps): React.JSX.Element;
129
+
130
+ interface FadeProps extends BaseEffectProps {
131
+ /**
132
+ * Text colour
133
+ * @default '#ffffff'
134
+ * @example 'yellow'
135
+ */
136
+ color?: Colour;
137
+ /**
138
+ * Starting opacity (0-1)
139
+ * @default 0
140
+ */
141
+ from?: number;
142
+ /**
143
+ * Ending opacity (0-1)
144
+ * @default 1
145
+ */
146
+ to?: number;
147
+ /**
148
+ * Duration in milliseconds
149
+ * @default 1000
150
+ */
151
+ duration?: number;
152
+ /**
153
+ * Easing function
154
+ * @default 'ease-out'
155
+ */
156
+ easing?: EasingName;
157
+ /**
158
+ * Loop animation continuously
159
+ * @default false
160
+ */
161
+ loop?: boolean;
162
+ }
163
+ /**
164
+ * Fade effect component that smoothly transitions text opacity
165
+ *
166
+ * Animates text from one opacity to another using configurable easing functions.
167
+ * Can loop continuously or run once.
168
+ *
169
+ * @example
170
+ * ```tsx
171
+ * <Fade color="yellow" from={0} to={1} duration={500} easing="ease-in">
172
+ * Success!
173
+ * </Fade>
174
+ * ```
175
+ */
176
+ declare function Fade({ children, color, from, to, duration, easing, loop, speed, enabled, onComplete, }: FadeProps): React.JSX.Element;
177
+
178
+ type WaveType = 'brightness' | 'vertical';
179
+ interface WaveProps extends BaseEffectProps {
180
+ /**
181
+ * Gradient colours for the wave [dark, bright]
182
+ * @default ['#888888', '#ffffff']
183
+ * @example ['#ec4899', '#8b5cf6']
184
+ */
185
+ colors?: [Colour, Colour];
186
+ /**
187
+ * Wave height (0-1)
188
+ * @default 0.5
189
+ */
190
+ amplitude?: number;
191
+ /**
192
+ * Number of wave cycles across text
193
+ * @default 2
194
+ */
195
+ frequency?: number;
196
+ /**
197
+ * Wave effect type
198
+ * @default 'brightness'
199
+ */
200
+ type?: WaveType;
201
+ }
202
+ /**
203
+ * Wave effect component that creates a wave motion through text
204
+ *
205
+ * Animates text with a sine wave pattern that can affect brightness or vertical position.
206
+ * The wave continuously flows through the text.
207
+ *
208
+ * @example
209
+ * ```tsx
210
+ * <Wave colors={['#ec4899', '#8b5cf6']} amplitude={0.7} frequency={3}>
211
+ * ~~ wavy text ~~
212
+ * </Wave>
213
+ * ```
214
+ */
215
+ declare function Wave({ children, colors, amplitude, frequency, type, speed, enabled, }: WaveProps): React.JSX.Element;
216
+
217
+ /**
218
+ * Runs a callback on every animation frame using setInterval
219
+ *
220
+ * @param callback - Function called each frame with delta time in ms
221
+ * @param enabled - Whether animation is active
222
+ */
223
+ declare function useAnimationFrame(callback: (deltaTime: number) => void, enabled?: boolean): void;
224
+
225
+ /**
226
+ * Hook that tracks elapsed time since mount or last reset
227
+ *
228
+ * @param enabled - Whether to track time
229
+ * @param speed - Speed multiplier (default: 1)
230
+ * @returns Elapsed time in milliseconds
231
+ */
232
+ declare function useElapsedTime(enabled?: boolean, speed?: number): number;
233
+
234
+ interface UseCursorBlinkOptions {
235
+ enabled: boolean;
236
+ isComplete: boolean;
237
+ }
238
+ /**
239
+ * Hook that manages cursor blinking state
240
+ *
241
+ * @param options - Configuration for cursor blink
242
+ * @returns Whether cursor should be visible
243
+ */
244
+ declare function useCursorBlink({ enabled, isComplete, }: UseCursorBlinkOptions): boolean;
245
+
246
+ interface UseTypewriterProgressOptions {
247
+ totalCharacters: number;
248
+ speed: number;
249
+ variance: number;
250
+ initialDelay: number;
251
+ enabled: boolean;
252
+ onComplete?: () => void;
253
+ }
254
+ /**
255
+ * Hook that manages typewriter character reveal timing
256
+ *
257
+ * @param options - Configuration for typewriter progress
258
+ * @returns Number of characters to display
259
+ */
260
+ declare function useTypewriterProgress({ totalCharacters, speed, variance, initialDelay, enabled, onComplete, }: UseTypewriterProgressOptions): number;
261
+
262
+ export { type BaseEffectProps, type Color, type Colour, type EasingFunction, type EasingName, Fade, Shimmer, Typewriter, Wave, useAnimationFrame, useCursorBlink, useElapsedTime, useTypewriterProgress };