-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathanimation.zod.ts
More file actions
113 lines (98 loc) · 4.39 KB
/
Copy pathanimation.zod.ts
File metadata and controls
113 lines (98 loc) · 4.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { z } from 'zod';
import { I18nLabelSchema, AriaPropsSchema } from './i18n.zod';
/**
* Transition Preset Schema
* Common animation transition presets.
*/
export const TransitionPresetSchema = z.enum([
'fade',
'slide_up',
'slide_down',
'slide_left',
'slide_right',
'scale',
'rotate',
'flip',
'none',
]).describe('Transition preset type');
export type TransitionPreset = z.infer<typeof TransitionPresetSchema>;
/**
* Easing Function Schema
* Supported animation easing/timing functions.
*/
export const EasingFunctionSchema = z.enum([
'linear',
'ease',
'ease_in',
'ease_out',
'ease_in_out',
'spring',
]).describe('Animation easing function');
export type EasingFunction = z.infer<typeof EasingFunctionSchema>;
/**
* Transition Configuration Schema
* Defines a single animation transition with timing and easing options.
*/
export const TransitionConfigSchema = z.object({
preset: TransitionPresetSchema.optional().describe('Transition preset to apply'),
duration: z.number().optional().describe('Transition duration in milliseconds'),
easing: EasingFunctionSchema.optional().describe('Easing function for the transition'),
delay: z.number().optional().describe('Delay before transition starts in milliseconds'),
customKeyframes: z.string().optional().describe('CSS @keyframes name for custom animations'),
themeToken: z.string().optional().describe('Reference to a theme animation token (e.g. "animation.duration.fast")'),
}).describe('Animation transition configuration');
export type TransitionConfig = z.infer<typeof TransitionConfigSchema>;
/**
* Animation Trigger Schema
* Events that can trigger an animation.
*/
export const AnimationTriggerSchema = z.enum([
'on_mount',
'on_unmount',
'on_hover',
'on_focus',
'on_click',
'on_scroll',
'on_visible',
]).describe('Event that triggers the animation');
export type AnimationTrigger = z.infer<typeof AnimationTriggerSchema>;
/**
* Component Animation Schema
* Animation configuration for an individual UI component.
*/
export const ComponentAnimationSchema = z.object({
label: I18nLabelSchema.optional().describe('Descriptive label for this animation configuration'),
enter: TransitionConfigSchema.optional().describe('Enter/mount animation'),
exit: TransitionConfigSchema.optional().describe('Exit/unmount animation'),
hover: TransitionConfigSchema.optional().describe('Hover state animation'),
trigger: AnimationTriggerSchema.optional().describe('When to trigger the animation'),
reducedMotion: z.enum(['respect', 'disable', 'alternative']).default('respect')
.describe('Accessibility: how to handle prefers-reduced-motion'),
}).merge(AriaPropsSchema.partial()).describe('Component-level animation configuration');
export type ComponentAnimation = z.infer<typeof ComponentAnimationSchema>;
/**
* Page Transition Schema
* Defines the animation used when navigating between pages.
*/
export const PageTransitionSchema = z.object({
type: TransitionPresetSchema.default('fade').describe('Page transition type'),
duration: z.number().default(300).describe('Transition duration in milliseconds'),
easing: EasingFunctionSchema.default('ease_in_out').describe('Easing function for the transition'),
crossFade: z.boolean().default(false).describe('Whether to cross-fade between pages'),
}).describe('Page-level transition configuration');
export type PageTransition = z.infer<typeof PageTransitionSchema>;
/**
* Motion Configuration Schema
* Top-level animation and motion design configuration.
*/
export const MotionConfigSchema = z.object({
label: I18nLabelSchema.optional().describe('Descriptive label for the motion configuration'),
defaultTransition: TransitionConfigSchema.optional().describe('Default transition applied to all animations'),
pageTransitions: PageTransitionSchema.optional().describe('Page navigation transition settings'),
componentAnimations: z.record(z.string(), ComponentAnimationSchema).optional()
.describe('Component name to animation configuration mapping'),
reducedMotion: z.boolean().default(false).describe('When true, respect prefers-reduced-motion and suppress animations globally'),
enabled: z.boolean().default(true).describe('Enable or disable all animations globally'),
}).describe('Top-level motion and animation design configuration');
export type MotionConfig = z.infer<typeof MotionConfigSchema>;