@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,320 @@
|
|
|
1
|
+
// Copyright (c) 2026 Amsterdam Data Labs
|
|
2
|
+
/**
|
|
3
|
+
* AI-Driven Preset Selection
|
|
4
|
+
*
|
|
5
|
+
* Utilities for intelligently selecting animation presets based on
|
|
6
|
+
* context, use case, and preferences. Designed to be used by AI tools
|
|
7
|
+
* for automatic animation selection.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
import { componentPresets, getPresetsByContext, } from "../presets/component-presets";
|
|
12
|
+
// =============================================================================
|
|
13
|
+
// Selection Logic
|
|
14
|
+
// =============================================================================
|
|
15
|
+
/**
|
|
16
|
+
* Calculates a match score between criteria and a preset.
|
|
17
|
+
*/
|
|
18
|
+
function calculateMatchScore(preset, criteria) {
|
|
19
|
+
let score = 0;
|
|
20
|
+
let factors = 0;
|
|
21
|
+
// Use case match
|
|
22
|
+
if (criteria.useCase) {
|
|
23
|
+
factors++;
|
|
24
|
+
if (preset.metadata.useCase.includes(criteria.useCase)) {
|
|
25
|
+
score += 1;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
// Context match
|
|
29
|
+
if (criteria.context) {
|
|
30
|
+
factors++;
|
|
31
|
+
if (preset.metadata.context.includes(criteria.context)) {
|
|
32
|
+
score += 1;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Intensity range
|
|
36
|
+
if (criteria.maxIntensity !== undefined) {
|
|
37
|
+
factors++;
|
|
38
|
+
if (preset.metadata.intensity <= criteria.maxIntensity) {
|
|
39
|
+
score += 1;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (criteria.minIntensity !== undefined) {
|
|
43
|
+
factors++;
|
|
44
|
+
if (preset.metadata.intensity >= criteria.minIntensity) {
|
|
45
|
+
score += 1;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Movement preference
|
|
49
|
+
if (criteria.preferMovement !== undefined) {
|
|
50
|
+
factors++;
|
|
51
|
+
if (preset.metadata.hasMovement === criteria.preferMovement) {
|
|
52
|
+
score += 1;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// Direction match
|
|
56
|
+
if (criteria.direction && preset.metadata.direction) {
|
|
57
|
+
factors++;
|
|
58
|
+
if (preset.metadata.direction === criteria.direction) {
|
|
59
|
+
score += 1;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Accessibility preference (lower intensity = more accessible)
|
|
63
|
+
if (criteria.prioritizeAccessibility) {
|
|
64
|
+
factors++;
|
|
65
|
+
// Favor lower intensity presets
|
|
66
|
+
score += (5 - preset.metadata.intensity) / 5;
|
|
67
|
+
}
|
|
68
|
+
return factors > 0 ? score / factors : 0;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Determines the best motion style based on criteria.
|
|
72
|
+
*/
|
|
73
|
+
function determineStyle(criteria) {
|
|
74
|
+
if (criteria.style) {
|
|
75
|
+
return criteria.style;
|
|
76
|
+
}
|
|
77
|
+
if (criteria.prioritizeAccessibility) {
|
|
78
|
+
return "subtle";
|
|
79
|
+
}
|
|
80
|
+
if (criteria.context === "hero" || criteria.context === "page") {
|
|
81
|
+
return "bold";
|
|
82
|
+
}
|
|
83
|
+
if (criteria.context === "tooltip" || criteria.context === "dropdown") {
|
|
84
|
+
return "subtle";
|
|
85
|
+
}
|
|
86
|
+
return "standard";
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Generates reasoning for a selection.
|
|
90
|
+
*/
|
|
91
|
+
function generateReasoning(preset, criteria, score) {
|
|
92
|
+
const reasons = [];
|
|
93
|
+
if (criteria.useCase && preset.metadata.useCase.includes(criteria.useCase)) {
|
|
94
|
+
reasons.push(`matches use case "${criteria.useCase}"`);
|
|
95
|
+
}
|
|
96
|
+
if (criteria.context && preset.metadata.context.includes(criteria.context)) {
|
|
97
|
+
reasons.push(`suitable for "${criteria.context}" context`);
|
|
98
|
+
}
|
|
99
|
+
if (criteria.direction && preset.metadata.direction === criteria.direction) {
|
|
100
|
+
reasons.push(`provides "${criteria.direction}" movement`);
|
|
101
|
+
}
|
|
102
|
+
if (criteria.prioritizeAccessibility && preset.metadata.intensity <= 2) {
|
|
103
|
+
reasons.push("has low intensity for accessibility");
|
|
104
|
+
}
|
|
105
|
+
if (reasons.length === 0) {
|
|
106
|
+
reasons.push("general-purpose animation");
|
|
107
|
+
}
|
|
108
|
+
return `Selected "${preset.metadata.name}" (${Math.round(score * 100)}% match): ${reasons.join(", ")}.`;
|
|
109
|
+
}
|
|
110
|
+
// =============================================================================
|
|
111
|
+
// Main Selection Functions
|
|
112
|
+
// =============================================================================
|
|
113
|
+
/**
|
|
114
|
+
* Selects the best preset based on criteria.
|
|
115
|
+
*
|
|
116
|
+
* This function analyzes the given criteria and returns the most
|
|
117
|
+
* appropriate animation preset along with reasoning.
|
|
118
|
+
*
|
|
119
|
+
* @ai-hint Use this function to automatically select animations based on
|
|
120
|
+
* the component's context and requirements. Pass as much information as
|
|
121
|
+
* possible for better selection.
|
|
122
|
+
*
|
|
123
|
+
* @param criteria - Selection criteria
|
|
124
|
+
* @returns Selection result with preset and reasoning
|
|
125
|
+
*
|
|
126
|
+
* @example
|
|
127
|
+
* ```ts
|
|
128
|
+
* const result = selectPreset({
|
|
129
|
+
* useCase: "entrance",
|
|
130
|
+
* context: "modal",
|
|
131
|
+
* prioritizeAccessibility: true,
|
|
132
|
+
* });
|
|
133
|
+
*
|
|
134
|
+
* console.log(result.presetName); // "fadeIn"
|
|
135
|
+
* console.log(result.reasoning); // "Selected 'Fade In' (95% match): ..."
|
|
136
|
+
* ```
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```ts
|
|
140
|
+
* // For a hero section with bold animation
|
|
141
|
+
* const result = selectPreset({
|
|
142
|
+
* useCase: "entrance",
|
|
143
|
+
* context: "hero",
|
|
144
|
+
* preferMovement: true,
|
|
145
|
+
* direction: "up",
|
|
146
|
+
* });
|
|
147
|
+
*
|
|
148
|
+
* console.log(result.presetName); // "slideUpScale"
|
|
149
|
+
* console.log(result.style); // "bold"
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
export function selectPreset(criteria) {
|
|
153
|
+
const allPresets = Object.entries(componentPresets);
|
|
154
|
+
// Calculate scores for all presets
|
|
155
|
+
const scoredPresets = allPresets.map(([name, preset]) => ({
|
|
156
|
+
name,
|
|
157
|
+
preset,
|
|
158
|
+
score: calculateMatchScore(preset, criteria),
|
|
159
|
+
}));
|
|
160
|
+
// Sort by score descending
|
|
161
|
+
scoredPresets.sort((a, b) => b.score - a.score);
|
|
162
|
+
const best = scoredPresets[0];
|
|
163
|
+
const style = determineStyle(criteria);
|
|
164
|
+
if (!best) {
|
|
165
|
+
throw new Error("selectPreset: no presets available; cannot select a preset.");
|
|
166
|
+
}
|
|
167
|
+
const alternatives = scoredPresets
|
|
168
|
+
.slice(1, 4)
|
|
169
|
+
.filter((p) => p.score > 0.3)
|
|
170
|
+
.map((p) => p.name);
|
|
171
|
+
return {
|
|
172
|
+
preset: best.preset,
|
|
173
|
+
presetName: best.name,
|
|
174
|
+
style,
|
|
175
|
+
confidence: best.score,
|
|
176
|
+
reasoning: generateReasoning(best.preset, criteria, best.score),
|
|
177
|
+
alternatives,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Gets recommendations for a specific context.
|
|
182
|
+
*
|
|
183
|
+
* Returns multiple preset options ranked by suitability.
|
|
184
|
+
*
|
|
185
|
+
* @param context - The UI context
|
|
186
|
+
* @param options - Additional filtering options
|
|
187
|
+
* @returns Array of recommendations
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```ts
|
|
191
|
+
* const recommendations = getRecommendations("modal");
|
|
192
|
+
* // Returns: [
|
|
193
|
+
* // { preset: scale, name: "scale", reason: "...", score: 0.9 },
|
|
194
|
+
* // { preset: fadeIn, name: "fadeIn", reason: "...", score: 0.8 },
|
|
195
|
+
* // ...
|
|
196
|
+
* // ]
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
export function getRecommendations(context, options = {}) {
|
|
200
|
+
const { maxResults = 5, minScore = 0.3 } = options;
|
|
201
|
+
const contextPresets = getPresetsByContext(context);
|
|
202
|
+
const recommendations = contextPresets.map((preset) => {
|
|
203
|
+
const name = Object.entries(componentPresets).find(([_, p]) => p === preset)?.[0];
|
|
204
|
+
// Score based on how well the preset fits the context
|
|
205
|
+
const contextFit = preset.metadata.context.indexOf(context) === 0 ? 1 : 0.7;
|
|
206
|
+
const intensityFit = 1 - Math.abs(preset.metadata.intensity - 3) / 4;
|
|
207
|
+
const score = (contextFit + intensityFit) / 2;
|
|
208
|
+
return {
|
|
209
|
+
preset,
|
|
210
|
+
name,
|
|
211
|
+
reason: `${preset.metadata.description}. Ideal for ${preset.metadata.context.slice(0, 2).join(", ")}.`,
|
|
212
|
+
score,
|
|
213
|
+
};
|
|
214
|
+
});
|
|
215
|
+
return recommendations
|
|
216
|
+
.filter((r) => r.score >= minScore)
|
|
217
|
+
.sort((a, b) => b.score - a.score)
|
|
218
|
+
.slice(0, maxResults);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Gets the default preset for a context.
|
|
222
|
+
*
|
|
223
|
+
* Quick helper for getting a sensible default animation.
|
|
224
|
+
*
|
|
225
|
+
* @param context - The UI context
|
|
226
|
+
* @returns The default preset for that context
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```ts
|
|
230
|
+
* const modalPreset = getDefaultPreset("modal");
|
|
231
|
+
* // Returns: scale preset
|
|
232
|
+
*
|
|
233
|
+
* const tooltipPreset = getDefaultPreset("tooltip");
|
|
234
|
+
* // Returns: fadeIn preset
|
|
235
|
+
* ```
|
|
236
|
+
*/
|
|
237
|
+
export function getDefaultPreset(context) {
|
|
238
|
+
// Define sensible defaults for each context
|
|
239
|
+
const defaults = {
|
|
240
|
+
modal: "scale",
|
|
241
|
+
dropdown: "slideDown",
|
|
242
|
+
tooltip: "fadeIn",
|
|
243
|
+
drawer: "slideRight",
|
|
244
|
+
card: "fadeIn",
|
|
245
|
+
"list-item": "slideUp",
|
|
246
|
+
notification: "slideRight",
|
|
247
|
+
page: "fadeIn",
|
|
248
|
+
section: "slideUp",
|
|
249
|
+
hero: "slideUpScale",
|
|
250
|
+
};
|
|
251
|
+
return componentPresets[defaults[context]];
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Suggests animation combinations for a component.
|
|
255
|
+
*
|
|
256
|
+
* Returns entrance, exit, and interaction animations that work together.
|
|
257
|
+
*
|
|
258
|
+
* @param context - The UI context
|
|
259
|
+
* @param style - Preferred motion style
|
|
260
|
+
* @returns Object with suggested animations
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```ts
|
|
264
|
+
* const suggestions = suggestAnimations("card", "standard");
|
|
265
|
+
* // Returns: {
|
|
266
|
+
* // entrance: slideUp,
|
|
267
|
+
* // exit: fadeOut,
|
|
268
|
+
* // interaction: cardHover (from micro-interactions)
|
|
269
|
+
* // }
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
export function suggestAnimations(context, style = "standard") {
|
|
273
|
+
// Get the best entrance animation
|
|
274
|
+
const entranceResult = selectPreset({
|
|
275
|
+
useCase: "entrance",
|
|
276
|
+
context,
|
|
277
|
+
style,
|
|
278
|
+
});
|
|
279
|
+
// Get a matching exit animation
|
|
280
|
+
const exitResult = selectPreset({
|
|
281
|
+
useCase: "exit",
|
|
282
|
+
context,
|
|
283
|
+
style,
|
|
284
|
+
});
|
|
285
|
+
return {
|
|
286
|
+
entrance: entranceResult.preset,
|
|
287
|
+
entranceName: entranceResult.presetName,
|
|
288
|
+
exit: exitResult.preset,
|
|
289
|
+
exitName: exitResult.presetName,
|
|
290
|
+
style,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
// =============================================================================
|
|
294
|
+
// Preset Metadata Utilities
|
|
295
|
+
// =============================================================================
|
|
296
|
+
/**
|
|
297
|
+
* Gets all available preset names.
|
|
298
|
+
*/
|
|
299
|
+
export function getAllPresetNames() {
|
|
300
|
+
return Object.keys(componentPresets);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Gets all available contexts.
|
|
304
|
+
*/
|
|
305
|
+
export function getAllContexts() {
|
|
306
|
+
return ["modal", "dropdown", "tooltip", "drawer", "card", "list-item", "notification", "page", "section", "hero"];
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Gets all available use cases.
|
|
310
|
+
*/
|
|
311
|
+
export function getAllUseCases() {
|
|
312
|
+
return ["entrance", "exit", "transition", "emphasis", "reveal"];
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Gets preset metadata by name.
|
|
316
|
+
*/
|
|
317
|
+
export function getPresetMetadata(name) {
|
|
318
|
+
return componentPresets[name].metadata;
|
|
319
|
+
}
|
|
320
|
+
//# sourceMappingURL=select-preset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select-preset.js","sourceRoot":"","sources":["../../src/utils/select-preset.ts"],"names":[],"mappings":"AAAA,yCAAyC;AAEzC;;;;;;;;GAQG;AAEH,OAAO,EAGH,gBAAgB,EAChB,mBAAmB,GAGtB,MAAM,8BAA8B,CAAC;AA6DtC,gFAAgF;AAChF,kBAAkB;AAClB,gFAAgF;AAEhF;;GAEG;AACH,SAAS,mBAAmB,CAAC,MAAuB,EAAE,QAA2B;IAC7E,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,OAAO,GAAG,CAAC,CAAC;IAEhB,iBAAiB;IACjB,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,EAAE,CAAC;QACV,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YACrD,KAAK,IAAI,CAA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AC"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Spring configuration presets for Motion library animations.
|
|
3
|
+
*
|
|
4
|
+
* @ai-hint This module provides pre-configured spring physics parameters for
|
|
5
|
+
* smooth, natural-feeling animations. Springs are preferred over duration-based
|
|
6
|
+
* animations for interactive UI elements as they respond naturally to interruption.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import { springGentle, springSnappy, createSpring } from './spring-configs';
|
|
11
|
+
*
|
|
12
|
+
* // Use a preset
|
|
13
|
+
* <motion.div animate={{ x: 100 }} transition={springGentle} />
|
|
14
|
+
*
|
|
15
|
+
* // Create custom spring
|
|
16
|
+
* const customSpring = createSpring(300, 25, 0.8);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* Configuration object for spring-based animations.
|
|
21
|
+
*
|
|
22
|
+
* @ai-hint SpringTransition defines physics-based animation parameters.
|
|
23
|
+
* Higher stiffness = faster movement, higher damping = less oscillation,
|
|
24
|
+
* higher mass = more inertia and slower response.
|
|
25
|
+
*/
|
|
26
|
+
export interface SpringTransition {
|
|
27
|
+
/** Animation type identifier */
|
|
28
|
+
readonly type: "spring";
|
|
29
|
+
/**
|
|
30
|
+
* Spring stiffness coefficient.
|
|
31
|
+
* Higher values create faster, more aggressive animations.
|
|
32
|
+
* @default 100
|
|
33
|
+
*/
|
|
34
|
+
readonly stiffness: number;
|
|
35
|
+
/**
|
|
36
|
+
* Damping coefficient to reduce oscillation.
|
|
37
|
+
* Higher values reduce bounciness.
|
|
38
|
+
* @default 10
|
|
39
|
+
*/
|
|
40
|
+
readonly damping: number;
|
|
41
|
+
/**
|
|
42
|
+
* Mass of the animated object.
|
|
43
|
+
* Higher values create more inertia.
|
|
44
|
+
* @default 1
|
|
45
|
+
*/
|
|
46
|
+
readonly mass: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Parameters for creating a custom spring configuration.
|
|
50
|
+
*/
|
|
51
|
+
export interface SpringParams {
|
|
52
|
+
/** Spring stiffness (tension) */
|
|
53
|
+
stiffness: number;
|
|
54
|
+
/** Damping (friction) */
|
|
55
|
+
damping: number;
|
|
56
|
+
/** Mass of the object */
|
|
57
|
+
mass: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Gentle spring with smooth, relaxed motion.
|
|
61
|
+
*
|
|
62
|
+
* @ai-hint Use for subtle transitions, fades, and non-interactive elements.
|
|
63
|
+
* Creates a calm, professional feel without drawing attention.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```tsx
|
|
67
|
+
* <motion.div
|
|
68
|
+
* initial={{ opacity: 0 }}
|
|
69
|
+
* animate={{ opacity: 1 }}
|
|
70
|
+
* transition={springGentle}
|
|
71
|
+
* />
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare const springGentle: SpringTransition;
|
|
75
|
+
/**
|
|
76
|
+
* Snappy spring with quick, responsive motion.
|
|
77
|
+
*
|
|
78
|
+
* @ai-hint Use for buttons, toggles, and interactive elements that need
|
|
79
|
+
* immediate feedback. Feels responsive without being jarring.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```tsx
|
|
83
|
+
* <motion.button
|
|
84
|
+
* whileHover={{ scale: 1.05 }}
|
|
85
|
+
* whileTap={{ scale: 0.95 }}
|
|
86
|
+
* transition={springSnappy}
|
|
87
|
+
* />
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare const springSnappy: SpringTransition;
|
|
91
|
+
/**
|
|
92
|
+
* Bouncy spring with playful oscillation.
|
|
93
|
+
*
|
|
94
|
+
* @ai-hint Use sparingly for celebratory moments, notifications, or
|
|
95
|
+
* elements that should draw attention. Too much bounce can feel unpolished.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```tsx
|
|
99
|
+
* <motion.div
|
|
100
|
+
* initial={{ scale: 0 }}
|
|
101
|
+
* animate={{ scale: 1 }}
|
|
102
|
+
* transition={springBouncy}
|
|
103
|
+
* />
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare const springBouncy: SpringTransition;
|
|
107
|
+
/**
|
|
108
|
+
* Stiff spring with minimal oscillation and fast settling.
|
|
109
|
+
*
|
|
110
|
+
* @ai-hint Use for UI elements that need to feel solid and immediate,
|
|
111
|
+
* like modals, dropdowns, or navigation. Minimal overshoot.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```tsx
|
|
115
|
+
* <motion.nav
|
|
116
|
+
* initial={{ x: -300 }}
|
|
117
|
+
* animate={{ x: 0 }}
|
|
118
|
+
* transition={springStiff}
|
|
119
|
+
* />
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export declare const springStiff: SpringTransition;
|
|
123
|
+
/**
|
|
124
|
+
* Creates a custom spring configuration with specified physics parameters.
|
|
125
|
+
*
|
|
126
|
+
* @ai-hint Use this factory when presets don't match your needs. Start with
|
|
127
|
+
* a preset and adjust from there. Common adjustments:
|
|
128
|
+
* - Increase stiffness for faster animations
|
|
129
|
+
* - Increase damping to reduce bounce
|
|
130
|
+
* - Decrease mass for quicker response
|
|
131
|
+
*
|
|
132
|
+
* @param stiffness - Spring stiffness (tension). Range: 100-1000. Higher = faster.
|
|
133
|
+
* @param damping - Damping coefficient (friction). Range: 10-50. Higher = less bounce.
|
|
134
|
+
* @param mass - Mass of the object. Range: 0.5-2. Higher = more inertia.
|
|
135
|
+
* @returns A SpringTransition configuration object.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```tsx
|
|
139
|
+
* // Create a very snappy spring for micro-interactions
|
|
140
|
+
* const microSpring = createSpring(600, 40, 0.5);
|
|
141
|
+
*
|
|
142
|
+
* // Create a heavy, slow spring for large elements
|
|
143
|
+
* const heavySpring = createSpring(150, 25, 1.5);
|
|
144
|
+
*
|
|
145
|
+
* <motion.div transition={createSpring(350, 28, 0.9)} />
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export declare function createSpring(stiffness: number, damping: number, mass: number): SpringTransition;
|
|
149
|
+
/**
|
|
150
|
+
* Creates a spring configuration from a params object.
|
|
151
|
+
*
|
|
152
|
+
* @ai-hint Alternative factory that accepts an object, useful when
|
|
153
|
+
* spring parameters come from configuration or theme.
|
|
154
|
+
*
|
|
155
|
+
* @param params - Spring parameters object
|
|
156
|
+
* @returns A SpringTransition configuration object.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```tsx
|
|
160
|
+
* const themeSpring = { stiffness: 250, damping: 22, mass: 1 };
|
|
161
|
+
* const spring = createSpringFromParams(themeSpring);
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
export declare function createSpringFromParams(params: SpringParams): SpringTransition;
|
|
165
|
+
/**
|
|
166
|
+
* Collection of all spring presets for iteration or dynamic selection.
|
|
167
|
+
*
|
|
168
|
+
* @ai-hint Use this map when you need to select springs dynamically
|
|
169
|
+
* based on user preference or theme configuration.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```tsx
|
|
173
|
+
* const springName = userPreference.animationStyle; // 'gentle' | 'snappy' | etc.
|
|
174
|
+
* const spring = springPresets[springName];
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
export declare const springPresets: {
|
|
178
|
+
readonly gentle: SpringTransition;
|
|
179
|
+
readonly snappy: SpringTransition;
|
|
180
|
+
readonly bouncy: SpringTransition;
|
|
181
|
+
readonly stiff: SpringTransition;
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Type representing valid spring preset names.
|
|
185
|
+
*/
|
|
186
|
+
export type SpringPresetName = keyof typeof springPresets;
|
|
187
|
+
//# sourceMappingURL=spring-configs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spring-configs.d.ts","sourceRoot":"","sources":["../../src/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(c) 2026 Amsterdam Data Labs
|
|
2
|
+
// =============================================================================
|
|
3
|
+
// SPRING PRESETS
|
|
4
|
+
// =============================================================================
|
|
5
|
+
/**
|
|
6
|
+
* Gentle spring with smooth, relaxed motion.
|
|
7
|
+
*
|
|
8
|
+
* @ai-hint Use for subtle transitions, fades, and non-interactive elements.
|
|
9
|
+
* Creates a calm, professional feel without drawing attention.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* <motion.div
|
|
14
|
+
* initial={{ opacity: 0 }}
|
|
15
|
+
* animate={{ opacity: 1 }}
|
|
16
|
+
* transition={springGentle}
|
|
17
|
+
* />
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export const springGentle = {
|
|
21
|
+
type: "spring",
|
|
22
|
+
stiffness: 200,
|
|
23
|
+
damping: 30,
|
|
24
|
+
mass: 1,
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Snappy spring with quick, responsive motion.
|
|
28
|
+
*
|
|
29
|
+
* @ai-hint Use for buttons, toggles, and interactive elements that need
|
|
30
|
+
* immediate feedback. Feels responsive without being jarring.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* <motion.button
|
|
35
|
+
* whileHover={{ scale: 1.05 }}
|
|
36
|
+
* whileTap={{ scale: 0.95 }}
|
|
37
|
+
* transition={springSnappy}
|
|
38
|
+
* />
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export const springSnappy = {
|
|
42
|
+
type: "spring",
|
|
43
|
+
stiffness: 400,
|
|
44
|
+
damping: 30,
|
|
45
|
+
mass: 0.8,
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Bouncy spring with playful oscillation.
|
|
49
|
+
*
|
|
50
|
+
* @ai-hint Use sparingly for celebratory moments, notifications, or
|
|
51
|
+
* elements that should draw attention. Too much bounce can feel unpolished.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```tsx
|
|
55
|
+
* <motion.div
|
|
56
|
+
* initial={{ scale: 0 }}
|
|
57
|
+
* animate={{ scale: 1 }}
|
|
58
|
+
* transition={springBouncy}
|
|
59
|
+
* />
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export const springBouncy = {
|
|
63
|
+
type: "spring",
|
|
64
|
+
stiffness: 300,
|
|
65
|
+
damping: 15,
|
|
66
|
+
mass: 1,
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Stiff spring with minimal oscillation and fast settling.
|
|
70
|
+
*
|
|
71
|
+
* @ai-hint Use for UI elements that need to feel solid and immediate,
|
|
72
|
+
* like modals, dropdowns, or navigation. Minimal overshoot.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```tsx
|
|
76
|
+
* <motion.nav
|
|
77
|
+
* initial={{ x: -300 }}
|
|
78
|
+
* animate={{ x: 0 }}
|
|
79
|
+
* transition={springStiff}
|
|
80
|
+
* />
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export const springStiff = {
|
|
84
|
+
type: "spring",
|
|
85
|
+
stiffness: 500,
|
|
86
|
+
damping: 35,
|
|
87
|
+
mass: 0.6,
|
|
88
|
+
};
|
|
89
|
+
// =============================================================================
|
|
90
|
+
// SPRING FACTORY
|
|
91
|
+
// =============================================================================
|
|
92
|
+
/**
|
|
93
|
+
* Creates a custom spring configuration with specified physics parameters.
|
|
94
|
+
*
|
|
95
|
+
* @ai-hint Use this factory when presets don't match your needs. Start with
|
|
96
|
+
* a preset and adjust from there. Common adjustments:
|
|
97
|
+
* - Increase stiffness for faster animations
|
|
98
|
+
* - Increase damping to reduce bounce
|
|
99
|
+
* - Decrease mass for quicker response
|
|
100
|
+
*
|
|
101
|
+
* @param stiffness - Spring stiffness (tension). Range: 100-1000. Higher = faster.
|
|
102
|
+
* @param damping - Damping coefficient (friction). Range: 10-50. Higher = less bounce.
|
|
103
|
+
* @param mass - Mass of the object. Range: 0.5-2. Higher = more inertia.
|
|
104
|
+
* @returns A SpringTransition configuration object.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```tsx
|
|
108
|
+
* // Create a very snappy spring for micro-interactions
|
|
109
|
+
* const microSpring = createSpring(600, 40, 0.5);
|
|
110
|
+
*
|
|
111
|
+
* // Create a heavy, slow spring for large elements
|
|
112
|
+
* const heavySpring = createSpring(150, 25, 1.5);
|
|
113
|
+
*
|
|
114
|
+
* <motion.div transition={createSpring(350, 28, 0.9)} />
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export function createSpring(stiffness, damping, mass) {
|
|
118
|
+
return {
|
|
119
|
+
type: "spring",
|
|
120
|
+
stiffness,
|
|
121
|
+
damping,
|
|
122
|
+
mass,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Creates a spring configuration from a params object.
|
|
127
|
+
*
|
|
128
|
+
* @ai-hint Alternative factory that accepts an object, useful when
|
|
129
|
+
* spring parameters come from configuration or theme.
|
|
130
|
+
*
|
|
131
|
+
* @param params - Spring parameters object
|
|
132
|
+
* @returns A SpringTransition configuration object.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```tsx
|
|
136
|
+
* const themeSpring = { stiffness: 250, damping: 22, mass: 1 };
|
|
137
|
+
* const spring = createSpringFromParams(themeSpring);
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
export function createSpringFromParams(params) {
|
|
141
|
+
return {
|
|
142
|
+
type: "spring",
|
|
143
|
+
stiffness: params.stiffness,
|
|
144
|
+
damping: params.damping,
|
|
145
|
+
mass: params.mass,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
// =============================================================================
|
|
149
|
+
// PRESET COLLECTIONS
|
|
150
|
+
// =============================================================================
|
|
151
|
+
/**
|
|
152
|
+
* Collection of all spring presets for iteration or dynamic selection.
|
|
153
|
+
*
|
|
154
|
+
* @ai-hint Use this map when you need to select springs dynamically
|
|
155
|
+
* based on user preference or theme configuration.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```tsx
|
|
159
|
+
* const springName = userPreference.animationStyle; // 'gentle' | 'snappy' | etc.
|
|
160
|
+
* const spring = springPresets[springName];
|
|
161
|
+
* ```
|
|
162
|
+
*/
|
|
163
|
+
export const springPresets = {
|
|
164
|
+
gentle: springGentle,
|
|
165
|
+
snappy: springSnappy,
|
|
166
|
+
bouncy: springBouncy,
|
|
167
|
+
stiff: springStiff,
|
|
168
|
+
};
|
|
169
|
+
//# sourceMappingURL=spring-configs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spring-configs.js","sourceRoot":"","sources":["../../src/utils/spring-configs.ts"],"names":[],"mappings":"AAAA,yCAAyC;AA+DzC,gFAAgF;AAChF,iBAAiB;AACjB,gFAAgF;AAEhF;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,YAAY,GAAqB;IAC1C,IAAI,EAAE,QAAQ;IACd,SAAS,EAAE,GAAG;IACd,OAAO,EAAE,EAAE;IACX,IAAI,EAAE,CAAC;CACD,CAAC;AAEX;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,YAAY,GAAqB;IAC1C,IAAI,EAAE,QAAQ;IACd,SAAS,EAAE,GAAG;IACd,OAAO,EAAE,EAAE;IACX,IAAI,EAAE,GAAG;CACH,CAAC;AAEX;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,YAAY,GAAqB;IAC1C,IAAI,EAAE,QAAQ;IACd,SAAS,EAAE,GAAG;IACd,OAAO,EAAE,EAAE;IACX,IAAI,EAAE,CAAC;CACD,CAAC;AAEX;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,WAAW,GAAqB;IACzC,IAAI,EAAE,QAAQ;IACd,SAAS,EAAE,GAAG;IACd,OAAO,EAAE,EAAE;IACX,IAAI,EAAE,GAAG;CAC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