@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.
Files changed (82) hide show
  1. package/api-schema.json +206 -0
  2. package/dist/components/CountUp.d.ts +84 -0
  3. package/dist/components/CountUp.d.ts.map +1 -0
  4. package/dist/components/CountUp.js +68 -0
  5. package/dist/components/CountUp.js.map +1 -0
  6. package/dist/components/MotionDiv.d.ts +159 -0
  7. package/dist/components/MotionDiv.d.ts.map +1 -0
  8. package/dist/components/MotionDiv.js +162 -0
  9. package/dist/components/MotionDiv.js.map +1 -0
  10. package/dist/components/StaggerContainer.d.ts +136 -0
  11. package/dist/components/StaggerContainer.d.ts.map +1 -0
  12. package/dist/components/StaggerContainer.js +166 -0
  13. package/dist/components/StaggerContainer.js.map +1 -0
  14. package/dist/hooks/use-component-animation.d.ts +156 -0
  15. package/dist/hooks/use-component-animation.d.ts.map +1 -0
  16. package/dist/hooks/use-component-animation.js +231 -0
  17. package/dist/hooks/use-component-animation.js.map +1 -0
  18. package/dist/hooks/use-count-up.d.ts +111 -0
  19. package/dist/hooks/use-count-up.d.ts.map +1 -0
  20. package/dist/hooks/use-count-up.js +246 -0
  21. package/dist/hooks/use-count-up.js.map +1 -0
  22. package/dist/hooks/use-draw-path.d.ts +96 -0
  23. package/dist/hooks/use-draw-path.d.ts.map +1 -0
  24. package/dist/hooks/use-draw-path.js +227 -0
  25. package/dist/hooks/use-draw-path.js.map +1 -0
  26. package/dist/hooks/use-motion-preset.d.ts.map +1 -1
  27. package/dist/hooks/use-motion-preset.js +17 -16
  28. package/dist/hooks/use-motion-preset.js.map +1 -1
  29. package/dist/hooks/use-stagger.d.ts +174 -0
  30. package/dist/hooks/use-stagger.d.ts.map +1 -0
  31. package/dist/hooks/use-stagger.js +256 -0
  32. package/dist/hooks/use-stagger.js.map +1 -0
  33. package/dist/index.d.ts +17 -1
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +2442 -26
  36. package/dist/index.js.map +1 -1
  37. package/dist/index.mjs +2335 -25
  38. package/dist/index.mjs.map +1 -1
  39. package/dist/presets/component-presets.d.ts +246 -0
  40. package/dist/presets/component-presets.d.ts.map +1 -0
  41. package/dist/presets/component-presets.js +472 -0
  42. package/dist/presets/component-presets.js.map +1 -0
  43. package/dist/presets/micro-interactions.d.ts +451 -0
  44. package/dist/presets/micro-interactions.d.ts.map +1 -0
  45. package/dist/presets/micro-interactions.js +856 -0
  46. package/dist/presets/micro-interactions.js.map +1 -0
  47. package/dist/presets/motion-presets.d.ts.map +1 -1
  48. package/dist/presets/motion-presets.js +0 -1
  49. package/dist/presets/motion-presets.js.map +1 -1
  50. package/dist/presets/motion-styles.d.ts +186 -0
  51. package/dist/presets/motion-styles.d.ts.map +1 -0
  52. package/dist/presets/motion-styles.js +204 -0
  53. package/dist/presets/motion-styles.js.map +1 -0
  54. package/dist/presets/stagger-presets.d.ts +378 -0
  55. package/dist/presets/stagger-presets.d.ts.map +1 -0
  56. package/dist/presets/stagger-presets.js +582 -0
  57. package/dist/presets/stagger-presets.js.map +1 -0
  58. package/dist/showcase/motion-presets.demo.d.ts +25 -0
  59. package/dist/showcase/motion-presets.demo.d.ts.map +1 -0
  60. package/dist/showcase/motion-presets.demo.js +96 -0
  61. package/dist/showcase/motion-presets.demo.js.map +1 -0
  62. package/dist/showcase/motion-presets.story.d.ts +37 -0
  63. package/dist/showcase/motion-presets.story.d.ts.map +1 -0
  64. package/dist/showcase/motion-presets.story.js +151 -0
  65. package/dist/showcase/motion-presets.story.js.map +1 -0
  66. package/dist/utils/easing.d.ts +294 -0
  67. package/dist/utils/easing.d.ts.map +1 -0
  68. package/dist/utils/easing.js +265 -0
  69. package/dist/utils/easing.js.map +1 -0
  70. package/dist/utils/reduced-motion.d.ts +322 -0
  71. package/dist/utils/reduced-motion.d.ts.map +1 -0
  72. package/dist/utils/reduced-motion.js +362 -0
  73. package/dist/utils/reduced-motion.js.map +1 -0
  74. package/dist/utils/select-preset.d.ts +186 -0
  75. package/dist/utils/select-preset.d.ts.map +1 -0
  76. package/dist/utils/select-preset.js +320 -0
  77. package/dist/utils/select-preset.js.map +1 -0
  78. package/dist/utils/spring-configs.d.ts +187 -0
  79. package/dist/utils/spring-configs.d.ts.map +1 -0
  80. package/dist/utils/spring-configs.js +169 -0
  81. package/dist/utils/spring-configs.js.map +1 -0
  82. package/package.json +4 -3
@@ -0,0 +1,378 @@
1
+ /**
2
+ * Stagger Animation Presets
3
+ *
4
+ * Defines stagger animation presets for animating lists and grids of items.
5
+ * These presets control the timing and order in which child elements animate,
6
+ * creating visually appealing sequential or patterned animations.
7
+ *
8
+ * Each preset includes:
9
+ * - A delay calculation function based on item index
10
+ * - Container variants for orchestrating child animations
11
+ * - Item variants for individual element animations
12
+ * - Metadata for documentation and AI tool selection
13
+ *
14
+ * @packageDocumentation
15
+ *
16
+ * @example Basic list animation with sequential stagger
17
+ * ```tsx
18
+ * import { motion } from "motion/react";
19
+ * import { staggerSequential } from "@enact-ui/animate";
20
+ *
21
+ * function AnimatedList({ items }) {
22
+ * const { getContainerVariants, getItemVariants } = staggerSequential;
23
+ *
24
+ * return (
25
+ * <motion.ul
26
+ * variants={getContainerVariants("standard")}
27
+ * initial="hidden"
28
+ * animate="visible"
29
+ * >
30
+ * {items.map((item, index) => (
31
+ * <motion.li key={item.id} variants={getItemVariants("standard")}>
32
+ * {item.content}
33
+ * </motion.li>
34
+ * ))}
35
+ * </motion.ul>
36
+ * );
37
+ * }
38
+ * ```
39
+ *
40
+ * @example Grid animation with diagonal wave
41
+ * ```tsx
42
+ * import { staggerGrid } from "@enact-ui/animate";
43
+ *
44
+ * function AnimatedGrid({ items, columns = 4 }) {
45
+ * return (
46
+ * <motion.div
47
+ * className="grid grid-cols-4"
48
+ * variants={staggerGrid.getContainerVariants("bold")}
49
+ * initial="hidden"
50
+ * animate="visible"
51
+ * >
52
+ * {items.map((item, index) => (
53
+ * <motion.div
54
+ * key={item.id}
55
+ * variants={staggerGrid.getItemVariants("bold")}
56
+ * custom={{ index, columns }}
57
+ * >
58
+ * {item.content}
59
+ * </motion.div>
60
+ * ))}
61
+ * </motion.div>
62
+ * );
63
+ * }
64
+ * ```
65
+ */
66
+ import type { MotionStyle } from "./motion-styles";
67
+ /**
68
+ * Container animation variants for stagger orchestration.
69
+ * The container coordinates when children should animate.
70
+ */
71
+ export interface ContainerVariants {
72
+ /** Hidden state before animation starts */
73
+ hidden: Record<string, unknown>;
74
+ /** Visible state with stagger children configuration */
75
+ visible: Record<string, unknown>;
76
+ }
77
+ /**
78
+ * Item animation variants for individual elements.
79
+ * Applied to each child element in the staggered animation.
80
+ */
81
+ export interface ItemVariants {
82
+ /** Hidden state (typically opacity: 0, transform offset) */
83
+ hidden: Record<string, unknown>;
84
+ /** Visible state (typically opacity: 1, transform reset) */
85
+ visible: Record<string, unknown>;
86
+ }
87
+ /**
88
+ * Complete stagger preset configuration.
89
+ *
90
+ * @ai-hint Stagger presets control how lists and grids of items animate.
91
+ * Choose based on the visual effect needed: sequential for simple lists,
92
+ * center for focus effects, grid for 2D layouts, wave for organic feels.
93
+ */
94
+ export interface StaggerPreset {
95
+ /** Display name of the stagger preset */
96
+ name: string;
97
+ /** Description of the animation effect */
98
+ description: string;
99
+ /** Recommended use cases for this preset */
100
+ useCase: string[];
101
+ /**
102
+ * Calculates the delay for a specific item.
103
+ *
104
+ * @param index - The item's index in the list (0-based)
105
+ * @param total - Total number of items in the list
106
+ * @param style - The motion style to use for timing
107
+ * @returns Delay in seconds before this item animates
108
+ */
109
+ getDelay: (index: number, total: number, style: MotionStyle) => number;
110
+ /**
111
+ * Gets container variants for Motion library.
112
+ *
113
+ * @param style - The motion style for timing configuration
114
+ * @returns Container variants with stagger configuration
115
+ */
116
+ getContainerVariants: (style: MotionStyle) => ContainerVariants;
117
+ /**
118
+ * Gets item variants for Motion library.
119
+ *
120
+ * @param style - The motion style for animation configuration
121
+ * @returns Item variants for individual elements
122
+ */
123
+ getItemVariants: (style: MotionStyle) => ItemVariants;
124
+ }
125
+ /**
126
+ * Sequential Stagger - Items animate one after another from top to bottom.
127
+ *
128
+ * The most common stagger pattern where items appear in their natural order.
129
+ * Creates a clean, predictable animation flow that guides the eye downward.
130
+ *
131
+ * @ai-hint Use staggerSequential for standard lists, menus, and vertical
132
+ * content where you want items to appear in reading order (top to bottom).
133
+ *
134
+ * @example
135
+ * ```tsx
136
+ * import { staggerSequential } from "@enact-ui/animate";
137
+ *
138
+ * // Navigation menu items
139
+ * <motion.nav variants={staggerSequential.getContainerVariants("standard")}>
140
+ * {menuItems.map((item) => (
141
+ * <motion.a variants={staggerSequential.getItemVariants("standard")}>
142
+ * {item.label}
143
+ * </motion.a>
144
+ * ))}
145
+ * </motion.nav>
146
+ * ```
147
+ */
148
+ export declare const staggerSequential: StaggerPreset;
149
+ /**
150
+ * Reverse Stagger - Items animate from bottom to top.
151
+ *
152
+ * Creates an upward flow effect, useful for content that should draw
153
+ * attention upward or create a "rising" visual metaphor.
154
+ *
155
+ * @ai-hint Use staggerReverse for toast notifications, chat messages
156
+ * (newest first), or any content where bottom-to-top flow makes sense.
157
+ *
158
+ * @example
159
+ * ```tsx
160
+ * import { staggerReverse } from "@enact-ui/animate";
161
+ *
162
+ * // Toast notification stack
163
+ * <motion.div variants={staggerReverse.getContainerVariants("standard")}>
164
+ * {toasts.map((toast) => (
165
+ * <motion.div variants={staggerReverse.getItemVariants("standard")}>
166
+ * {toast.message}
167
+ * </motion.div>
168
+ * ))}
169
+ * </motion.div>
170
+ * ```
171
+ */
172
+ export declare const staggerReverse: StaggerPreset;
173
+ /**
174
+ * Center Stagger - Items animate from center outward.
175
+ *
176
+ * Creates a radial expansion effect where the middle item(s) appear first,
177
+ * then items progressively reveal outward. Great for focus-based UIs.
178
+ *
179
+ * @ai-hint Use staggerCenter for hero sections, featured content, or any
180
+ * UI where you want to draw attention to the center element first.
181
+ *
182
+ * @example
183
+ * ```tsx
184
+ * import { staggerCenter } from "@enact-ui/animate";
185
+ *
186
+ * // Feature cards with center focus
187
+ * <motion.div
188
+ * className="flex gap-4"
189
+ * variants={staggerCenter.getContainerVariants("bold")}
190
+ * >
191
+ * {features.map((feature, i) => (
192
+ * <motion.div
193
+ * variants={staggerCenter.getItemVariants("bold")}
194
+ * custom={{ index: i, total: features.length }}
195
+ * >
196
+ * {feature.title}
197
+ * </motion.div>
198
+ * ))}
199
+ * </motion.div>
200
+ * ```
201
+ */
202
+ export declare const staggerCenter: StaggerPreset;
203
+ /**
204
+ * Random Stagger - Items animate in random order.
205
+ *
206
+ * Creates an organic, unpredictable animation pattern. Each render
207
+ * produces the same "random" order using a seeded approach based on index.
208
+ *
209
+ * @ai-hint Use staggerRandom for photo galleries, tag clouds, or creative
210
+ * UIs where a playful, organic feel is desired. Avoid for data-heavy UIs.
211
+ *
212
+ * @example
213
+ * ```tsx
214
+ * import { staggerRandom } from "@enact-ui/animate";
215
+ *
216
+ * // Photo gallery with organic reveal
217
+ * <motion.div
218
+ * className="grid grid-cols-3"
219
+ * variants={staggerRandom.getContainerVariants("playful")}
220
+ * >
221
+ * {photos.map((photo) => (
222
+ * <motion.img
223
+ * src={photo.url}
224
+ * variants={staggerRandom.getItemVariants("playful")}
225
+ * />
226
+ * ))}
227
+ * </motion.div>
228
+ * ```
229
+ */
230
+ export declare const staggerRandom: StaggerPreset;
231
+ /**
232
+ * Grid Stagger - 2D diagonal wave pattern for grid layouts.
233
+ *
234
+ * Creates a diagonal wave effect where items animate based on their
235
+ * row + column position. Perfect for image grids and card layouts.
236
+ *
237
+ * @ai-hint Use staggerGrid for 2D layouts like image galleries, card grids,
238
+ * or dashboards. Pass columns count for accurate diagonal calculation.
239
+ *
240
+ * @example
241
+ * ```tsx
242
+ * import { staggerGrid } from "@enact-ui/animate";
243
+ *
244
+ * const COLUMNS = 4;
245
+ *
246
+ * // Image grid with diagonal wave
247
+ * <motion.div
248
+ * className="grid grid-cols-4"
249
+ * variants={staggerGrid.getContainerVariants("standard")}
250
+ * >
251
+ * {images.map((image, index) => (
252
+ * <motion.div
253
+ * key={image.id}
254
+ * variants={staggerGrid.getItemVariants("standard")}
255
+ * style={{
256
+ * // Custom delay based on grid position
257
+ * transitionDelay: `${staggerGrid.getDelay(
258
+ * index,
259
+ * images.length,
260
+ * "standard"
261
+ * )}s`,
262
+ * }}
263
+ * >
264
+ * <img src={image.url} alt={image.alt} />
265
+ * </motion.div>
266
+ * ))}
267
+ * </motion.div>
268
+ * ```
269
+ */
270
+ export declare const staggerGrid: StaggerPreset;
271
+ /**
272
+ * Wave Stagger - Sine-wave based stagger pattern.
273
+ *
274
+ * Creates an organic wave effect using sinusoidal timing. Items
275
+ * animate in a flowing pattern that feels natural and rhythmic.
276
+ *
277
+ * @ai-hint Use staggerWave for music/audio UIs, timeline visualizations,
278
+ * or any interface that benefits from organic, flowing motion.
279
+ *
280
+ * @example
281
+ * ```tsx
282
+ * import { staggerWave } from "@enact-ui/animate";
283
+ *
284
+ * // Audio equalizer bars
285
+ * <motion.div
286
+ * className="flex items-end gap-1"
287
+ * variants={staggerWave.getContainerVariants("playful")}
288
+ * >
289
+ * {bars.map((bar, index) => (
290
+ * <motion.div
291
+ * key={index}
292
+ * className="bg-primary"
293
+ * style={{ height: bar.height }}
294
+ * variants={staggerWave.getItemVariants("playful")}
295
+ * />
296
+ * ))}
297
+ * </motion.div>
298
+ * ```
299
+ */
300
+ export declare const staggerWave: StaggerPreset;
301
+ /**
302
+ * Cascade Stagger - Fast initial items, progressively slower.
303
+ *
304
+ * Creates an accelerating cascade effect where early items appear quickly
305
+ * and later items take longer. Great for emphasizing quantity.
306
+ *
307
+ * @ai-hint Use staggerCascade for long lists, data tables, or anywhere
308
+ * you want to convey "there's more" by slowing down the reveal.
309
+ *
310
+ * @example
311
+ * ```tsx
312
+ * import { staggerCascade } from "@enact-ui/animate";
313
+ *
314
+ * // Long data table rows
315
+ * <motion.tbody variants={staggerCascade.getContainerVariants("subtle")}>
316
+ * {rows.map((row) => (
317
+ * <motion.tr
318
+ * key={row.id}
319
+ * variants={staggerCascade.getItemVariants("subtle")}
320
+ * >
321
+ * {row.cells.map((cell) => (
322
+ * <td key={cell.id}>{cell.value}</td>
323
+ * ))}
324
+ * </motion.tr>
325
+ * ))}
326
+ * </motion.tbody>
327
+ * ```
328
+ */
329
+ export declare const staggerCascade: StaggerPreset;
330
+ /**
331
+ * All stagger presets indexed by name.
332
+ *
333
+ * @ai-hint Use this map to dynamically select stagger presets based on
334
+ * user preferences or component configuration.
335
+ */
336
+ export declare const staggerPresets: Record<string, StaggerPreset>;
337
+ /**
338
+ * Stagger preset type identifier.
339
+ */
340
+ export type StaggerPresetType = keyof typeof staggerPresets;
341
+ /**
342
+ * Gets a stagger preset by name.
343
+ *
344
+ * @param name - The preset name to retrieve
345
+ * @returns The stagger preset configuration
346
+ * @throws Error if preset name is not found
347
+ *
348
+ * @example
349
+ * ```ts
350
+ * const preset = getStaggerPreset("center");
351
+ * const containerVariants = preset.getContainerVariants("standard");
352
+ * ```
353
+ */
354
+ export declare function getStaggerPreset(name: StaggerPresetType): StaggerPreset;
355
+ /**
356
+ * Creates custom delay values for a list of items using a specific preset.
357
+ *
358
+ * Useful when you need to calculate delays outside of Motion's variants
359
+ * system, such as for CSS animations or manual timing control.
360
+ *
361
+ * @param preset - The stagger preset to use
362
+ * @param total - Total number of items
363
+ * @param style - The motion style for timing
364
+ * @returns Array of delay values in seconds for each item
365
+ *
366
+ * @example
367
+ * ```ts
368
+ * const delays = calculateStaggerDelays("cascade", 10, "standard");
369
+ * // Returns: [0, 0.05, 0.071, 0.087, 0.1, ...]
370
+ *
371
+ * // Use with CSS custom properties
372
+ * items.forEach((item, index) => {
373
+ * item.style.setProperty("--delay", `${delays[index]}s`);
374
+ * });
375
+ * ```
376
+ */
377
+ export declare function calculateStaggerDelays(preset: StaggerPresetType, total: number, style: MotionStyle): number[];
378
+ //# sourceMappingURL=stagger-presets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stagger-presets.d.ts","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