UNPKG

6.08 kBTypeScriptView Raw
1export interface Animation {
2 parentAnimation: Animation | undefined;
3 elements: HTMLElement[];
4 childAnimations: Animation[];
5 id: string | undefined;
6 /**
7 * Play the animation
8 *
9 * If the `sync` options is `true`, the animation will play synchronously. This
10 * is the equivalent of running the animation
11 * with a duration of 0ms.
12 */
13 play(opts?: AnimationPlayOptions): Promise<void>;
14 /**
15 * Pauses the animation
16 */
17 pause(): void;
18 /**
19 * Stop the animation and reset
20 * all elements to their initial state
21 */
22 stop(): void;
23 /**
24 * Destroy the animation and all child animations.
25 */
26 destroy(clearStyleSheets?: boolean): void;
27 progressStart(forceLinearEasing: boolean, step?: number): void;
28 progressStep(step: number): void;
29 progressEnd(playTo: 0 | 1 | undefined, step: number, dur?: number): void;
30 from(property: string, value: any): Animation;
31 to(property: string, value: any): Animation;
32 fromTo(property: string, fromValue: any, toValue: any): Animation;
33 /**
34 * Set the keyframes for the animation.
35 */
36 keyframes(keyframes: AnimationKeyFrames): Animation;
37 /**
38 * Group one or more animations together to be controlled by a parent animation.
39 */
40 addAnimation(animationToAdd: Animation | Animation[]): Animation;
41 /**
42 * Add one or more elements to the animation
43 */
44 addElement(el: Element | Element[] | Node | Node[] | NodeList): Animation;
45 /**
46 * Sets the number of times the animation cycle
47 * should be played before stopping.
48 */
49 iterations(iterations: number): Animation;
50 /**
51 * Sets how the animation applies styles to its
52 * elements before and after the animation's execution.
53 */
54 fill(fill: AnimationFill | undefined): Animation;
55 /**
56 * Sets whether the animation should play forwards,
57 * backwards, or alternating back and forth.
58 */
59 direction(direction: AnimationDirection | undefined): Animation;
60 /**
61 * Sets the length of time the animation takes
62 * to complete one cycle.
63 */
64 duration(duration: number | undefined): Animation;
65 /**
66 * Sets how the animation progresses through the
67 * duration of each cycle.
68 */
69 easing(easing: string | undefined): Animation;
70 /**
71 * Sets when an animation starts (in milliseconds).
72 */
73 delay(delay: number | undefined): Animation;
74 /**
75 * Get an array of keyframes for the animation.
76 */
77 getKeyframes(): AnimationKeyFrames;
78 /**
79 * Returns the animation's direction.
80 */
81 getDirection(): AnimationDirection;
82 /**
83 * Returns the animation's fill mode.
84 */
85 getFill(): AnimationFill;
86 /**
87 * Gets the animation's delay in milliseconds.
88 */
89 getDelay(): number;
90 /**
91 * Gets the number of iterations the animation will run.
92 */
93 getIterations(): number;
94 /**
95 * Returns the animation's easing.
96 */
97 getEasing(): string;
98 /**
99 * Gets the animation's duration in milliseconds.
100 */
101 getDuration(): number;
102 /**
103 * Returns the raw Web Animations object
104 * for all elements in an Animation.
105 * This will return an empty array on
106 * browsers that do not support
107 * the Web Animations API.
108 */
109 getWebAnimations(): any[];
110 /**
111 * Add a function that performs a
112 * DOM read to be run after the
113 * animation end
114 */
115 afterAddRead(readFn: () => void): Animation;
116 /**
117 * Add a function that performs a
118 * DOM write to be run after the
119 * animation end
120 */
121 afterAddWrite(writeFn: () => void): Animation;
122 /**
123 * Clear CSS inline styles from the animation's
124 * elements after the animation ends.
125 */
126 afterClearStyles(propertyNames: string[]): Animation;
127 /**
128 * Set CSS inline styles to the animation's
129 * elements after the animation ends.
130 */
131 afterStyles(styles: {
132 [property: string]: any;
133 }): Animation;
134 /**
135 * Add CSS class to the animation's
136 * elements after the animation ends.
137 */
138 afterAddClass(className: string | string[]): Animation;
139 /**
140 * Remove CSS class from the animation's
141 * elements after the animation ends.
142 */
143 afterRemoveClass(className: string | string[]): Animation;
144 /**
145 * Add a function that performs a
146 * DOM read to be run before the
147 * animation starts
148 */
149 beforeAddRead(readFn: () => void): Animation;
150 /**
151 * Add a function that performs a
152 * DOM write to be run before the
153 * animation starts
154 */
155 beforeAddWrite(writeFn: () => void): Animation;
156 /**
157 * Clear CSS inline styles from the animation's
158 * elements before the animation begins.
159 */
160 beforeClearStyles(propertyNames: string[]): Animation;
161 /**
162 * Set CSS inline styles to the animation's
163 * elements before the animation begins.
164 */
165 beforeStyles(styles: {
166 [property: string]: any;
167 }): Animation;
168 /**
169 * Add a class to the animation's
170 * elements before the animation starts
171 */
172 beforeAddClass(className: string | string[]): Animation;
173 /**
174 * Remove a class from the animation's
175 * elements before the animation starts
176 */
177 beforeRemoveClass(className: string | string[]): Animation;
178 /**
179 * Add a callback to be run
180 * upon the animation ending
181 */
182 onFinish(callback: AnimationLifecycle, opts?: AnimationCallbackOptions): Animation;
183}
184export declare type AnimationLifecycle = (currentStep: 0 | 1, animation: Animation) => void;
185export declare type AnimationKeyFrames = [AnimationKeyFrameEdge, AnimationKeyFrameEdge] | AnimationKeyFrame[];
186export declare type AnimationStyles = Record<string, any>;
187export interface AnimationCallbackOptions {
188 oneTimeCallback: boolean;
189}
190export interface AnimationKeyFrame extends AnimationStyles {
191 offset: number;
192}
193export interface AnimationKeyFrameEdge extends AnimationStyles {
194 offset?: number;
195}
196export interface AnimationPlayOptions {
197 sync: boolean;
198}
199export declare type AnimationPlayTo = 'start' | 'end';
200export declare type AnimationDirection = 'normal' | 'reverse' | 'alternate' | 'alternate-reverse';
201export declare type AnimationFill = 'auto' | 'none' | 'forwards' | 'backwards' | 'both';
202export declare type AnimationBuilder = (baseEl: any, opts?: any) => Animation;