@enact-ui/animate 0.1.0 → 0.2.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.
- package/api-schema.json +206 -0
- package/dist/components/CountUp.d.ts +84 -0
- package/dist/components/CountUp.d.ts.map +1 -0
- package/dist/components/CountUp.js +68 -0
- package/dist/components/CountUp.js.map +1 -0
- package/dist/components/MotionDiv.d.ts +159 -0
- package/dist/components/MotionDiv.d.ts.map +1 -0
- package/dist/components/MotionDiv.js +162 -0
- package/dist/components/MotionDiv.js.map +1 -0
- package/dist/components/StaggerContainer.d.ts +136 -0
- package/dist/components/StaggerContainer.d.ts.map +1 -0
- package/dist/components/StaggerContainer.js +166 -0
- package/dist/components/StaggerContainer.js.map +1 -0
- package/dist/hooks/use-component-animation.d.ts +156 -0
- package/dist/hooks/use-component-animation.d.ts.map +1 -0
- package/dist/hooks/use-component-animation.js +231 -0
- package/dist/hooks/use-component-animation.js.map +1 -0
- package/dist/hooks/use-count-up.d.ts +111 -0
- package/dist/hooks/use-count-up.d.ts.map +1 -0
- package/dist/hooks/use-count-up.js +246 -0
- package/dist/hooks/use-count-up.js.map +1 -0
- package/dist/hooks/use-draw-path.d.ts +96 -0
- package/dist/hooks/use-draw-path.d.ts.map +1 -0
- package/dist/hooks/use-draw-path.js +227 -0
- package/dist/hooks/use-draw-path.js.map +1 -0
- package/dist/hooks/use-motion-preset.d.ts.map +1 -1
- package/dist/hooks/use-motion-preset.js +17 -16
- package/dist/hooks/use-motion-preset.js.map +1 -1
- package/dist/hooks/use-stagger.d.ts +174 -0
- package/dist/hooks/use-stagger.d.ts.map +1 -0
- package/dist/hooks/use-stagger.js +256 -0
- package/dist/hooks/use-stagger.js.map +1 -0
- package/dist/index.d.ts +17 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2442 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2335 -25
- package/dist/index.mjs.map +1 -1
- package/dist/presets/component-presets.d.ts +246 -0
- package/dist/presets/component-presets.d.ts.map +1 -0
- package/dist/presets/component-presets.js +472 -0
- package/dist/presets/component-presets.js.map +1 -0
- package/dist/presets/micro-interactions.d.ts +451 -0
- package/dist/presets/micro-interactions.d.ts.map +1 -0
- package/dist/presets/micro-interactions.js +856 -0
- package/dist/presets/micro-interactions.js.map +1 -0
- package/dist/presets/motion-presets.d.ts.map +1 -1
- package/dist/presets/motion-presets.js +0 -1
- package/dist/presets/motion-presets.js.map +1 -1
- package/dist/presets/motion-styles.d.ts +186 -0
- package/dist/presets/motion-styles.d.ts.map +1 -0
- package/dist/presets/motion-styles.js +204 -0
- package/dist/presets/motion-styles.js.map +1 -0
- package/dist/presets/stagger-presets.d.ts +378 -0
- package/dist/presets/stagger-presets.d.ts.map +1 -0
- package/dist/presets/stagger-presets.js +582 -0
- package/dist/presets/stagger-presets.js.map +1 -0
- package/dist/showcase/motion-presets.demo.d.ts +25 -0
- package/dist/showcase/motion-presets.demo.d.ts.map +1 -0
- package/dist/showcase/motion-presets.demo.js +96 -0
- package/dist/showcase/motion-presets.demo.js.map +1 -0
- package/dist/showcase/motion-presets.story.d.ts +37 -0
- package/dist/showcase/motion-presets.story.d.ts.map +1 -0
- package/dist/showcase/motion-presets.story.js +151 -0
- package/dist/showcase/motion-presets.story.js.map +1 -0
- package/dist/utils/easing.d.ts +294 -0
- package/dist/utils/easing.d.ts.map +1 -0
- package/dist/utils/easing.js +265 -0
- package/dist/utils/easing.js.map +1 -0
- package/dist/utils/reduced-motion.d.ts +322 -0
- package/dist/utils/reduced-motion.d.ts.map +1 -0
- package/dist/utils/reduced-motion.js +362 -0
- package/dist/utils/reduced-motion.js.map +1 -0
- package/dist/utils/select-preset.d.ts +186 -0
- package/dist/utils/select-preset.d.ts.map +1 -0
- package/dist/utils/select-preset.js +320 -0
- package/dist/utils/select-preset.js.map +1 -0
- package/dist/utils/spring-configs.d.ts +187 -0
- package/dist/utils/spring-configs.d.ts.map +1 -0
- package/dist/utils/spring-configs.js +169 -0
- package/dist/utils/spring-configs.js.map +1 -0
- package/package.json +4 -3
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
// Copyright (c) 2026 Amsterdam Data Labs
|
|
2
|
+
// =============================================================================
|
|
3
|
+
// STANDARD EASING CURVES
|
|
4
|
+
// =============================================================================
|
|
5
|
+
/**
|
|
6
|
+
* Linear easing - constant speed with no acceleration.
|
|
7
|
+
*
|
|
8
|
+
* @ai-hint Use for progress indicators, loading bars, or when you need
|
|
9
|
+
* mechanical, uniform motion. Rarely suitable for UI transitions.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* <motion.div animate={{ width: "100%" }} transition={{ duration: 2, ease: linear }} />
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export const linear = [0, 0, 1, 1];
|
|
17
|
+
/**
|
|
18
|
+
* Ease-in - starts slow, accelerates toward end.
|
|
19
|
+
*
|
|
20
|
+
* @ai-hint Use for elements exiting the screen or fading out.
|
|
21
|
+
* Creates anticipation but can feel sluggish if overused.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* <motion.div exit={{ opacity: 0, x: -100 }} transition={{ duration: 0.3, ease: easeIn }} />
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export const easeIn = [0.4, 0, 1, 1];
|
|
29
|
+
/**
|
|
30
|
+
* Ease-out - starts fast, decelerates toward end.
|
|
31
|
+
*
|
|
32
|
+
* @ai-hint The most natural-feeling easing for UI. Use for elements
|
|
33
|
+
* entering the screen or appearing. Mimics real-world deceleration.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```tsx
|
|
37
|
+
* <motion.div initial={{ opacity: 0 }} animate={{ opacity: 1 }} transition={{ duration: 0.3, ease: easeOut }} />
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export const easeOut = [0, 0, 0.2, 1];
|
|
41
|
+
/**
|
|
42
|
+
* Ease-in-out - slow start and end, fast middle.
|
|
43
|
+
*
|
|
44
|
+
* @ai-hint Good for elements that transform in place (scale, rotate)
|
|
45
|
+
* or move between two visible positions. Symmetric and balanced.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```tsx
|
|
49
|
+
* <motion.div animate={{ rotate: 180 }} transition={{ duration: 0.5, ease: easeInOut }} />
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export const easeInOut = [0.4, 0, 0.2, 1];
|
|
53
|
+
// =============================================================================
|
|
54
|
+
// EXPRESSIVE EASING CURVES
|
|
55
|
+
// =============================================================================
|
|
56
|
+
/**
|
|
57
|
+
* Quart ease-out - more dramatic deceleration than standard ease-out.
|
|
58
|
+
*
|
|
59
|
+
* @ai-hint Use for hero animations, page transitions, or anywhere you want
|
|
60
|
+
* motion to feel more dynamic and expressive. Popular in modern UI design.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```tsx
|
|
64
|
+
* <motion.section
|
|
65
|
+
* initial={{ y: 50, opacity: 0 }}
|
|
66
|
+
* animate={{ y: 0, opacity: 1 }}
|
|
67
|
+
* transition={{ duration: 0.6, ease: easeOutQuart }}
|
|
68
|
+
* />
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export const easeOutQuart = [0.25, 1, 0.5, 1];
|
|
72
|
+
/**
|
|
73
|
+
* Cubic ease-in-out - smooth acceleration and deceleration.
|
|
74
|
+
*
|
|
75
|
+
* @ai-hint A balanced, professional curve suitable for most transitions.
|
|
76
|
+
* Less aggressive than quart, more refined than standard ease-in-out.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```tsx
|
|
80
|
+
* <motion.div
|
|
81
|
+
* animate={{ height: isOpen ? "auto" : 0 }}
|
|
82
|
+
* transition={{ duration: 0.4, ease: easeInOutCubic }}
|
|
83
|
+
* />
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export const easeInOutCubic = [0.65, 0, 0.35, 1];
|
|
87
|
+
/**
|
|
88
|
+
* Back ease-out - slight overshoot before settling.
|
|
89
|
+
*
|
|
90
|
+
* @ai-hint Use for playful, attention-grabbing animations. The overshoot
|
|
91
|
+
* creates a "bounce back" effect. Use sparingly in professional UIs.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```tsx
|
|
95
|
+
* <motion.div
|
|
96
|
+
* initial={{ scale: 0 }}
|
|
97
|
+
* animate={{ scale: 1 }}
|
|
98
|
+
* transition={{ duration: 0.5, ease: easeOutBack }}
|
|
99
|
+
* />
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export const easeOutBack = [0.34, 1.56, 0.64, 1];
|
|
103
|
+
/**
|
|
104
|
+
* Expo ease-out - very fast start with long, smooth deceleration.
|
|
105
|
+
*
|
|
106
|
+
* @ai-hint Creates a snappy feel while maintaining smoothness.
|
|
107
|
+
* Great for modals, popovers, and navigation transitions.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```tsx
|
|
111
|
+
* <motion.dialog
|
|
112
|
+
* initial={{ scale: 0.95, opacity: 0 }}
|
|
113
|
+
* animate={{ scale: 1, opacity: 1 }}
|
|
114
|
+
* transition={{ duration: 0.3, ease: easeOutExpo }}
|
|
115
|
+
* />
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export const easeOutExpo = [0.16, 1, 0.3, 1];
|
|
119
|
+
/**
|
|
120
|
+
* Quint ease-in-out - dramatic but smooth transition.
|
|
121
|
+
*
|
|
122
|
+
* @ai-hint Use for large-scale transitions like page changes or
|
|
123
|
+
* full-screen reveals. The aggressive curve makes motion feel purposeful.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```tsx
|
|
127
|
+
* <motion.main
|
|
128
|
+
* initial={{ opacity: 0 }}
|
|
129
|
+
* animate={{ opacity: 1 }}
|
|
130
|
+
* transition={{ duration: 0.8, ease: easeInOutQuint }}
|
|
131
|
+
* />
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export const easeInOutQuint = [0.83, 0, 0.17, 1];
|
|
135
|
+
// =============================================================================
|
|
136
|
+
// TWEEN FACTORIES
|
|
137
|
+
// =============================================================================
|
|
138
|
+
/**
|
|
139
|
+
* Creates a tween transition with specified duration and optional easing.
|
|
140
|
+
*
|
|
141
|
+
* @ai-hint Primary factory for duration-based animations. Provides
|
|
142
|
+
* consistent, predictable timing. Default easing is easeOut.
|
|
143
|
+
*
|
|
144
|
+
* @param duration - Animation duration in seconds
|
|
145
|
+
* @param ease - Optional cubic bezier curve or easing name
|
|
146
|
+
* @returns A TweenTransition configuration object
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```tsx
|
|
150
|
+
* // Quick fade
|
|
151
|
+
* <motion.div animate={{ opacity: 1 }} transition={createTween(0.2)} />
|
|
152
|
+
*
|
|
153
|
+
* // Expressive entrance
|
|
154
|
+
* <motion.div animate={{ y: 0 }} transition={createTween(0.5, easeOutQuart)} />
|
|
155
|
+
*
|
|
156
|
+
* // Using named easing
|
|
157
|
+
* <motion.div animate={{ x: 100 }} transition={createTween(0.3, "easeInOut")} />
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export function createTween(duration, ease) {
|
|
161
|
+
return {
|
|
162
|
+
type: "tween",
|
|
163
|
+
duration,
|
|
164
|
+
ease: ease ?? easeOut,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Creates a tween transition from a params object.
|
|
169
|
+
*
|
|
170
|
+
* @ai-hint Alternative factory accepting an object, useful when
|
|
171
|
+
* animation parameters come from configuration or are computed.
|
|
172
|
+
*
|
|
173
|
+
* @param params - Tween parameters object
|
|
174
|
+
* @returns A TweenTransition configuration object
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```tsx
|
|
178
|
+
* const config = { duration: 0.4, ease: easeOutQuart };
|
|
179
|
+
* const tween = createTweenFromParams(config);
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
export function createTweenFromParams(params) {
|
|
183
|
+
const result = {
|
|
184
|
+
type: "tween",
|
|
185
|
+
duration: params.duration,
|
|
186
|
+
};
|
|
187
|
+
if (params.ease !== undefined) {
|
|
188
|
+
return { ...result, ease: params.ease };
|
|
189
|
+
}
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
192
|
+
// =============================================================================
|
|
193
|
+
// DURATION PRESETS
|
|
194
|
+
// =============================================================================
|
|
195
|
+
/**
|
|
196
|
+
* Standard duration values for consistent timing across the application.
|
|
197
|
+
*
|
|
198
|
+
* @ai-hint Use these durations to maintain rhythm and consistency.
|
|
199
|
+
* Faster durations for small, frequent interactions; longer for emphasis.
|
|
200
|
+
*/
|
|
201
|
+
export const durations = {
|
|
202
|
+
/** Micro-interactions: hover states, small toggles (100ms) */
|
|
203
|
+
instant: 0.1,
|
|
204
|
+
/** Quick feedback: button clicks, checkboxes (200ms) */
|
|
205
|
+
fast: 0.2,
|
|
206
|
+
/** Standard transitions: most UI elements (300ms) */
|
|
207
|
+
normal: 0.3,
|
|
208
|
+
/** Emphasized transitions: modals, drawers (400ms) */
|
|
209
|
+
slow: 0.4,
|
|
210
|
+
/** Dramatic transitions: page changes, reveals (600ms) */
|
|
211
|
+
slower: 0.6,
|
|
212
|
+
};
|
|
213
|
+
// =============================================================================
|
|
214
|
+
// PRESET COLLECTIONS
|
|
215
|
+
// =============================================================================
|
|
216
|
+
/**
|
|
217
|
+
* Collection of all easing curves for iteration or dynamic selection.
|
|
218
|
+
*
|
|
219
|
+
* @ai-hint Use this map when you need to select easings dynamically
|
|
220
|
+
* based on theme or user preferences.
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```tsx
|
|
224
|
+
* const easingName = theme.animationEasing; // 'easeOutQuart' | 'easeInOut' | etc.
|
|
225
|
+
* const easing = easingPresets[easingName];
|
|
226
|
+
* ```
|
|
227
|
+
*/
|
|
228
|
+
export const easingPresets = {
|
|
229
|
+
linear,
|
|
230
|
+
easeIn,
|
|
231
|
+
easeOut,
|
|
232
|
+
easeInOut,
|
|
233
|
+
easeOutQuart,
|
|
234
|
+
easeInOutCubic,
|
|
235
|
+
easeOutBack,
|
|
236
|
+
easeOutExpo,
|
|
237
|
+
easeInOutQuint,
|
|
238
|
+
};
|
|
239
|
+
// =============================================================================
|
|
240
|
+
// CONVENIENCE TRANSITIONS
|
|
241
|
+
// =============================================================================
|
|
242
|
+
/**
|
|
243
|
+
* Pre-configured tween transitions for common use cases.
|
|
244
|
+
*
|
|
245
|
+
* @ai-hint Ready-to-use transitions that combine duration and easing
|
|
246
|
+
* for typical scenarios. Use these for consistent animation behavior.
|
|
247
|
+
*
|
|
248
|
+
* @example
|
|
249
|
+
* ```tsx
|
|
250
|
+
* <motion.div initial={{ opacity: 0 }} animate={{ opacity: 1 }} transition={tweenPresets.fadeIn} />
|
|
251
|
+
* ```
|
|
252
|
+
*/
|
|
253
|
+
export const tweenPresets = {
|
|
254
|
+
/** Quick fade for hover states and micro-interactions */
|
|
255
|
+
instant: createTween(durations.instant, easeOut),
|
|
256
|
+
/** Snappy transition for interactive elements */
|
|
257
|
+
fast: createTween(durations.fast, easeOut),
|
|
258
|
+
/** Balanced transition for most UI elements */
|
|
259
|
+
normal: createTween(durations.normal, easeOutQuart),
|
|
260
|
+
/** Smooth transition for modals and overlays */
|
|
261
|
+
slow: createTween(durations.slow, easeOutQuart),
|
|
262
|
+
/** Dramatic transition for page-level changes */
|
|
263
|
+
slower: createTween(durations.slower, easeInOutCubic),
|
|
264
|
+
};
|
|
265
|
+
//# sourceMappingURL=easing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"easing.js","sourceRoot":"","sources":["../../src/utils/easing.ts"],"names":[],"mappings":"AAAA,yCAAyC;AAyDzC,gFAAgF;AAChF,yBAAyB;AACzB,gFAAgF;AAEhF;;;;;;;;;;GAUG;AACH,MA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AE,OAAO,CAAC;IAC1C,+CAA+C;IAC/C,MAAM,EAAE,WAAW,CAAC,SAAS,CAAC,MAAM,EAAE,YAAY,CAAC;IACnD,gDAAgD;IAChD,IAAI,EAAE,WAAW,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC;IAC/C,iDAAiD;IACjD,MAAM,EAAE,WAAW,CAAC,SAAS,CAAC,MAAM,EAAE,cAAc,CAAC;CAC/C,CAAC"}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Motion variant configuration for animations.
|
|
3
|
+
*
|
|
4
|
+
* @ai-hint This type represents animation variant objects used by Motion library.
|
|
5
|
+
* Variants define the animation states (initial, animate, exit, etc.).
|
|
6
|
+
*/
|
|
7
|
+
export type MotionVariant = Record<string, unknown>;
|
|
8
|
+
/**
|
|
9
|
+
* Props that can be passed to Motion components.
|
|
10
|
+
*
|
|
11
|
+
* @ai-hint This type represents the common props used in Motion components
|
|
12
|
+
* including animation configuration, transition settings, and variants.
|
|
13
|
+
*/
|
|
14
|
+
export interface MotionProps {
|
|
15
|
+
/** Initial animation state or variant name */
|
|
16
|
+
initial?: MotionVariant | string | boolean | undefined;
|
|
17
|
+
/** Target animation state or variant name */
|
|
18
|
+
animate?: MotionVariant | string | undefined;
|
|
19
|
+
/** Exit animation state or variant name */
|
|
20
|
+
exit?: MotionVariant | string | undefined;
|
|
21
|
+
/** Animation variants object */
|
|
22
|
+
variants?: Record<string, MotionVariant> | undefined;
|
|
23
|
+
/** Transition configuration */
|
|
24
|
+
transition?: MotionTransition | undefined;
|
|
25
|
+
/** Whether animations should be active */
|
|
26
|
+
whileHover?: MotionVariant | string | undefined;
|
|
27
|
+
/** Animation when element is in view */
|
|
28
|
+
whileInView?: MotionVariant | string | undefined;
|
|
29
|
+
/** Animation while element is pressed */
|
|
30
|
+
whileTap?: MotionVariant | string | undefined;
|
|
31
|
+
/** Animation while element is focused */
|
|
32
|
+
whileFocus?: MotionVariant | string | undefined;
|
|
33
|
+
/** Animation while dragging */
|
|
34
|
+
whileDrag?: MotionVariant | string | undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Transition configuration for Motion animations.
|
|
38
|
+
*
|
|
39
|
+
* @ai-hint This type represents the transition object in Motion library.
|
|
40
|
+
* It controls duration, easing, delay, and other timing aspects.
|
|
41
|
+
*/
|
|
42
|
+
export interface MotionTransition {
|
|
43
|
+
/** Duration in seconds */
|
|
44
|
+
duration?: number;
|
|
45
|
+
/** Delay before animation starts in seconds */
|
|
46
|
+
delay?: number;
|
|
47
|
+
/** Easing function or curve */
|
|
48
|
+
ease?: string | number[];
|
|
49
|
+
/** Type of animation (tween, spring, inertia) */
|
|
50
|
+
type?: "tween" | "spring" | "inertia";
|
|
51
|
+
/** Spring stiffness (for spring type) */
|
|
52
|
+
stiffness?: number;
|
|
53
|
+
/** Spring damping (for spring type) */
|
|
54
|
+
damping?: number;
|
|
55
|
+
/** Spring mass (for spring type) */
|
|
56
|
+
mass?: number;
|
|
57
|
+
/** Number of times to repeat (-1 for infinite) */
|
|
58
|
+
repeat?: number;
|
|
59
|
+
/** Type of repeat behavior */
|
|
60
|
+
repeatType?: "loop" | "reverse" | "mirror";
|
|
61
|
+
/** Delay between repeats */
|
|
62
|
+
repeatDelay?: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Options for creating reduced motion props.
|
|
66
|
+
*
|
|
67
|
+
* @ai-hint Use these options to customize how motion props are transformed
|
|
68
|
+
* when reduced motion is preferred.
|
|
69
|
+
*/
|
|
70
|
+
export interface ReducedMotionOptions {
|
|
71
|
+
/**
|
|
72
|
+
* Whether to preserve opacity transitions even in reduced motion mode.
|
|
73
|
+
* Opacity changes are generally considered acceptable for accessibility.
|
|
74
|
+
* @default true
|
|
75
|
+
*/
|
|
76
|
+
preserveOpacity?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Whether to preserve color transitions in reduced motion mode.
|
|
79
|
+
* Color changes without movement are typically accessibility-safe.
|
|
80
|
+
* @default true
|
|
81
|
+
*/
|
|
82
|
+
preserveColors?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Custom transition to use when reduced motion is preferred.
|
|
85
|
+
* If not provided, uses instant transition (duration: 0).
|
|
86
|
+
*/
|
|
87
|
+
reducedTransition?: MotionTransition;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Media query string for detecting reduced motion preference.
|
|
91
|
+
*
|
|
92
|
+
* @ai-hint Use this constant when you need to directly query the media feature
|
|
93
|
+
* outside of the provided hooks.
|
|
94
|
+
*/
|
|
95
|
+
export declare const REDUCED_MOTION_QUERY = "(prefers-reduced-motion: reduce)";
|
|
96
|
+
/**
|
|
97
|
+
* Default transition for reduced motion mode.
|
|
98
|
+
* Provides instant transitions without animation.
|
|
99
|
+
*
|
|
100
|
+
* @ai-hint This transition effectively disables animation while still
|
|
101
|
+
* allowing the final state to be applied immediately.
|
|
102
|
+
*/
|
|
103
|
+
export declare const INSTANT_TRANSITION: MotionTransition;
|
|
104
|
+
/**
|
|
105
|
+
* Hook that returns whether the user prefers reduced motion.
|
|
106
|
+
*
|
|
107
|
+
* @ai-hint This hook reactively tracks the `prefers-reduced-motion` media query.
|
|
108
|
+
* It updates automatically when the user changes their system preference.
|
|
109
|
+
* Use this hook to conditionally apply or skip animations.
|
|
110
|
+
*
|
|
111
|
+
* @returns `true` if the user prefers reduced motion, `false` otherwise
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```tsx
|
|
115
|
+
* function AnimatedComponent() {
|
|
116
|
+
* const prefersReducedMotion = useReducedMotion();
|
|
117
|
+
*
|
|
118
|
+
* return (
|
|
119
|
+
* <motion.div
|
|
120
|
+
* animate={{ x: 100 }}
|
|
121
|
+
* transition={prefersReducedMotion ? { duration: 0 } : { duration: 0.5 }}
|
|
122
|
+
* >
|
|
123
|
+
* Content
|
|
124
|
+
* </motion.div>
|
|
125
|
+
* );
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```tsx
|
|
131
|
+
* // Skip animation entirely when reduced motion is preferred
|
|
132
|
+
* function FadeInComponent({ children }: { children: React.ReactNode }) {
|
|
133
|
+
* const prefersReducedMotion = useReducedMotion();
|
|
134
|
+
*
|
|
135
|
+
* if (prefersReducedMotion) {
|
|
136
|
+
* return <div>{children}</div>;
|
|
137
|
+
* }
|
|
138
|
+
*
|
|
139
|
+
* return (
|
|
140
|
+
* <motion.div
|
|
141
|
+
* initial={{ opacity: 0 }}
|
|
142
|
+
* animate={{ opacity: 1 }}
|
|
143
|
+
* transition={{ duration: 0.3 }}
|
|
144
|
+
* >
|
|
145
|
+
* {children}
|
|
146
|
+
* </motion.div>
|
|
147
|
+
* );
|
|
148
|
+
* }
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export declare function useReducedMotion(): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Returns the appropriate variant based on reduced motion preference.
|
|
154
|
+
*
|
|
155
|
+
* @ai-hint Use this function to provide alternative animation variants for users
|
|
156
|
+
* who prefer reduced motion. The reduced variant should avoid or minimize
|
|
157
|
+
* movement-based animations while potentially preserving opacity/color changes.
|
|
158
|
+
*
|
|
159
|
+
* @param normalVariant - The variant to use when motion is allowed
|
|
160
|
+
* @param reducedVariant - The variant to use when reduced motion is preferred
|
|
161
|
+
* @returns The appropriate variant based on the current reduced motion preference
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```tsx
|
|
165
|
+
* function SlideInCard() {
|
|
166
|
+
* const prefersReducedMotion = useReducedMotion();
|
|
167
|
+
*
|
|
168
|
+
* const normalVariant = {
|
|
169
|
+
* hidden: { x: -100, opacity: 0 },
|
|
170
|
+
* visible: { x: 0, opacity: 1 },
|
|
171
|
+
* };
|
|
172
|
+
*
|
|
173
|
+
* const reducedVariant = {
|
|
174
|
+
* hidden: { opacity: 0 },
|
|
175
|
+
* visible: { opacity: 1 },
|
|
176
|
+
* };
|
|
177
|
+
*
|
|
178
|
+
* const variants = getReducedMotionVariant(
|
|
179
|
+
* normalVariant,
|
|
180
|
+
* reducedVariant,
|
|
181
|
+
* prefersReducedMotion
|
|
182
|
+
* );
|
|
183
|
+
*
|
|
184
|
+
* return (
|
|
185
|
+
* <motion.div
|
|
186
|
+
* variants={variants}
|
|
187
|
+
* initial="hidden"
|
|
188
|
+
* animate="visible"
|
|
189
|
+
* >
|
|
190
|
+
* Card Content
|
|
191
|
+
* </motion.div>
|
|
192
|
+
* );
|
|
193
|
+
* }
|
|
194
|
+
* ```
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* ```tsx
|
|
198
|
+
* // Using with a hook for reactive updates
|
|
199
|
+
* function AnimatedList({ items }: { items: string[] }) {
|
|
200
|
+
* const prefersReducedMotion = useReducedMotion();
|
|
201
|
+
*
|
|
202
|
+
* const itemVariant = getReducedMotionVariant(
|
|
203
|
+
* { hidden: { y: 20, opacity: 0 }, visible: { y: 0, opacity: 1 } },
|
|
204
|
+
* { hidden: { opacity: 0 }, visible: { opacity: 1 } },
|
|
205
|
+
* prefersReducedMotion
|
|
206
|
+
* );
|
|
207
|
+
*
|
|
208
|
+
* return (
|
|
209
|
+
* <motion.ul>
|
|
210
|
+
* {items.map((item, i) => (
|
|
211
|
+
* <motion.li
|
|
212
|
+
* key={item}
|
|
213
|
+
* variants={itemVariant}
|
|
214
|
+
* initial="hidden"
|
|
215
|
+
* animate="visible"
|
|
216
|
+
* transition={{ delay: i * 0.1 }}
|
|
217
|
+
* >
|
|
218
|
+
* {item}
|
|
219
|
+
* </motion.li>
|
|
220
|
+
* ))}
|
|
221
|
+
* </motion.ul>
|
|
222
|
+
* );
|
|
223
|
+
* }
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
export declare function getReducedMotionVariant<T extends MotionVariant | Record<string, MotionVariant>>(normalVariant: T, reducedVariant: T, prefersReducedMotion: boolean): T;
|
|
227
|
+
/**
|
|
228
|
+
* Wraps Motion props to respect the user's reduced motion preference.
|
|
229
|
+
*
|
|
230
|
+
* @ai-hint This function transforms Motion component props to be accessibility-friendly.
|
|
231
|
+
* When reduced motion is preferred, it either disables animations or preserves
|
|
232
|
+
* only safe properties (like opacity) based on the options provided.
|
|
233
|
+
*
|
|
234
|
+
* @param props - The original Motion props
|
|
235
|
+
* @param prefersReducedMotion - Whether reduced motion is preferred
|
|
236
|
+
* @param options - Options for customizing reduced motion behavior
|
|
237
|
+
* @returns Transformed props that respect reduced motion preference
|
|
238
|
+
*
|
|
239
|
+
* @example
|
|
240
|
+
* ```tsx
|
|
241
|
+
* function AccessibleMotionDiv({ children }: { children: React.ReactNode }) {
|
|
242
|
+
* const prefersReducedMotion = useReducedMotion();
|
|
243
|
+
*
|
|
244
|
+
* const baseProps: MotionProps = {
|
|
245
|
+
* initial: { x: -50, opacity: 0 },
|
|
246
|
+
* animate: { x: 0, opacity: 1 },
|
|
247
|
+
* transition: { duration: 0.5 },
|
|
248
|
+
* };
|
|
249
|
+
*
|
|
250
|
+
* const accessibleProps = createReducedMotionProps(
|
|
251
|
+
* baseProps,
|
|
252
|
+
* prefersReducedMotion
|
|
253
|
+
* );
|
|
254
|
+
*
|
|
255
|
+
* return <motion.div {...accessibleProps}>{children}</motion.div>;
|
|
256
|
+
* }
|
|
257
|
+
* ```
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```tsx
|
|
261
|
+
* // Preserve opacity transitions in reduced motion mode
|
|
262
|
+
* function FadeSlideComponent() {
|
|
263
|
+
* const prefersReducedMotion = useReducedMotion();
|
|
264
|
+
*
|
|
265
|
+
* const props = createReducedMotionProps(
|
|
266
|
+
* {
|
|
267
|
+
* initial: { y: 20, opacity: 0 },
|
|
268
|
+
* animate: { y: 0, opacity: 1 },
|
|
269
|
+
* transition: { duration: 0.3 },
|
|
270
|
+
* },
|
|
271
|
+
* prefersReducedMotion,
|
|
272
|
+
* { preserveOpacity: true }
|
|
273
|
+
* );
|
|
274
|
+
*
|
|
275
|
+
* // In reduced motion: only opacity animates, y is instant
|
|
276
|
+
* return <motion.div {...props}>Content</motion.div>;
|
|
277
|
+
* }
|
|
278
|
+
* ```
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```tsx
|
|
282
|
+
* // Custom reduced transition
|
|
283
|
+
* function CustomReducedMotion() {
|
|
284
|
+
* const prefersReducedMotion = useReducedMotion();
|
|
285
|
+
*
|
|
286
|
+
* const props = createReducedMotionProps(
|
|
287
|
+
* {
|
|
288
|
+
* animate: { scale: 1.1 },
|
|
289
|
+
* transition: { duration: 0.5 },
|
|
290
|
+
* },
|
|
291
|
+
* prefersReducedMotion,
|
|
292
|
+
* {
|
|
293
|
+
* reducedTransition: { duration: 0.1, ease: "linear" },
|
|
294
|
+
* }
|
|
295
|
+
* );
|
|
296
|
+
*
|
|
297
|
+
* return <motion.button {...props}>Hover me</motion.button>;
|
|
298
|
+
* }
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
export declare function createReducedMotionProps(props: MotionProps, prefersReducedMotion: boolean, options?: ReducedMotionOptions): MotionProps;
|
|
302
|
+
/**
|
|
303
|
+
* Checks if reduced motion is preferred (non-reactive, for one-time checks).
|
|
304
|
+
*
|
|
305
|
+
* @ai-hint Use this function for one-time checks outside of React components.
|
|
306
|
+
* For reactive behavior within components, prefer the `useReducedMotion` hook.
|
|
307
|
+
*
|
|
308
|
+
* @returns `true` if reduced motion is preferred, `false` otherwise (including SSR)
|
|
309
|
+
*
|
|
310
|
+
* @example
|
|
311
|
+
* ```ts
|
|
312
|
+
* // In a utility function
|
|
313
|
+
* function getAnimationDuration(baseDuration: number): number {
|
|
314
|
+
* if (checkReducedMotion()) {
|
|
315
|
+
* return 0;
|
|
316
|
+
* }
|
|
317
|
+
* return baseDuration;
|
|
318
|
+
* }
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
export declare function checkReducedMotion(): boolean;
|
|
322
|
+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