@ue-too/animate 0.9.5 → 0.11.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.
@@ -1,5 +1,27 @@
1
1
  import { AnimatableAttributeHelper, Keyframe } from "./animatable-attribute";
2
+ /**
3
+ * Linear easing function (no easing).
4
+ *
5
+ * @param percentage - Animation progress (0.0 to 1.0)
6
+ * @returns Same as input (linear progression)
7
+ *
8
+ * @category Easing
9
+ */
2
10
  export declare const linear: (percentage: number) => number;
11
+ /**
12
+ * Core interface for all animators in the animation system.
13
+ *
14
+ * @remarks
15
+ * The Animator interface defines the contract for both individual animations ({@link Animation})
16
+ * and composite animations ({@link CompositeAnimation}). All animators support:
17
+ * - Lifecycle control (start, stop, pause, resume)
18
+ * - Duration management with delays and drag time
19
+ * - Looping with optional max loop count
20
+ * - Parent-child relationships for composition
21
+ * - Event callbacks for start and end
22
+ *
23
+ * @category Core
24
+ */
3
25
  export interface Animator {
4
26
  loops: boolean;
5
27
  duration: number;
@@ -24,12 +46,63 @@ export interface Animator {
24
46
  maxLoopCount: number | undefined;
25
47
  playing: boolean;
26
48
  }
49
+ /**
50
+ * Function type for unsubscribing from animation events.
51
+ *
52
+ * @category Core
53
+ */
27
54
  export type UnSubscribe = () => void;
55
+ /**
56
+ * Interface for containers that hold and manage child animators.
57
+ *
58
+ * @remarks
59
+ * Implemented by {@link CompositeAnimation} to manage hierarchical animation structures.
60
+ * Handles duration updates and prevents cyclic dependencies.
61
+ *
62
+ * @category Core
63
+ */
28
64
  export interface AnimatorContainer {
29
65
  updateDuration(): void;
30
66
  checkCyclicChildren(): boolean;
31
67
  containsAnimation(animationInInterest: Animator): boolean;
32
68
  }
69
+ /**
70
+ * Container for sequencing and composing multiple animations.
71
+ *
72
+ * @remarks
73
+ * CompositeAnimation allows you to orchestrate complex animation sequences by:
74
+ * - **Sequencing**: Add animations to play one after another
75
+ * - **Overlapping**: Start animations before previous ones complete
76
+ * - **Synchronizing**: Play multiple animations simultaneously
77
+ * - **Nesting**: Compose animations contain other composite animations
78
+ *
79
+ * ## Key Features
80
+ *
81
+ * - Add animations at specific time offsets
82
+ * - Position animations relative to other animations (`addAnimationAfter`, `addAnimationBefore`)
83
+ * - Automatic duration calculation based on child animations
84
+ * - Hierarchical composition for complex sequences
85
+ * - Prevent cyclic animation dependencies
86
+ *
87
+ * @example
88
+ * Basic sequence
89
+ * ```typescript
90
+ * const sequence = new CompositeAnimation();
91
+ *
92
+ * // Add first animation at start (time 0)
93
+ * sequence.addAnimation('fadeIn', fadeAnimation, 0);
94
+ *
95
+ * // Add second animation after first completes
96
+ * sequence.addAnimationAfter('slideIn', slideAnimation, 'fadeIn');
97
+ *
98
+ * // Add third animation to overlap with second (100ms after second starts)
99
+ * sequence.addAnimationAdmist('scaleUp', scaleAnimation, 'slideIn', 100);
100
+ *
101
+ * sequence.start();
102
+ * ```
103
+ *
104
+ * @category Core
105
+ */
33
106
  export declare class CompositeAnimation implements Animator, AnimatorContainer {
34
107
  private animations;
35
108
  private localTime;
@@ -102,6 +175,54 @@ export declare class CompositeAnimation implements Animator, AnimatorContainer {
102
175
  get maxLoopCount(): number | undefined;
103
176
  set maxLoopCount(maxLoopCount: number | undefined);
104
177
  }
178
+ /**
179
+ * Keyframe-based animation for a single value.
180
+ *
181
+ * @remarks
182
+ * The Animation class interpolates a value through a series of keyframes over time.
183
+ * It handles:
184
+ * - Keyframe interpolation with binary search for efficiency
185
+ * - Easing functions for smooth motion curves
186
+ * - Reverse playback
187
+ * - Looping with optional max loop count
188
+ * - Delays before start and drag time after completion
189
+ * - Lifecycle callbacks
190
+ *
191
+ * ## How It Works
192
+ *
193
+ * 1. Define keyframes at percentages (0.0 to 1.0) along the timeline
194
+ * 2. Provide a callback to apply the animated value
195
+ * 3. Provide an interpolation helper for the value type
196
+ * 4. Call `animate(deltaTime)` each frame to progress the animation
197
+ *
198
+ * @typeParam T - The type of value being animated
199
+ *
200
+ * @example
201
+ * Animating a number with easing
202
+ * ```typescript
203
+ * let opacity = 0;
204
+ *
205
+ * const fadeIn = new Animation(
206
+ * [
207
+ * { percentage: 0, value: 0 },
208
+ * { percentage: 1, value: 1, easingFn: (t) => t * t } // Ease-in
209
+ * ],
210
+ * (value) => { opacity = value; },
211
+ * numberHelperFunctions,
212
+ * 1000 // 1 second duration
213
+ * );
214
+ *
215
+ * fadeIn.start();
216
+ *
217
+ * // In animation loop
218
+ * function loop(deltaTime: number) {
219
+ * fadeIn.animate(deltaTime);
220
+ * element.style.opacity = opacity;
221
+ * }
222
+ * ```
223
+ *
224
+ * @category Core
225
+ */
105
226
  export declare class Animation<T> implements Animator {
106
227
  private localTime;
107
228
  private _duration;
package/index.d.ts CHANGED
@@ -1,2 +1,102 @@
1
+ /**
2
+ * @packageDocumentation
3
+ * Keyframe-based animation library for TypeScript.
4
+ *
5
+ * @remarks
6
+ * The `@ue-too/animate` package provides a flexible, composable animation system based on keyframes.
7
+ * It supports animating various types (numbers, points, colors, strings) with easing functions,
8
+ * delays, and complex animation sequencing through composition.
9
+ *
10
+ * ## Core Concepts
11
+ *
12
+ * - **Keyframes**: Define animation values at specific points in time (0.0 to 1.0)
13
+ * - **Animation**: Interpolates between keyframes to animate a single value
14
+ * - **Composite Animation**: Sequences and overlaps multiple animations
15
+ * - **Animation Helpers**: Type-specific interpolation logic (lerp functions)
16
+ * - **Easing Functions**: Transform animation timing curves
17
+ *
18
+ * ## Key Features
19
+ *
20
+ * - **Type-Safe Interpolation**: Built-in helpers for numbers, points, colors, strings
21
+ * - **Composite Animations**: Sequence, overlap, and synchronize multiple animations
22
+ * - **Lifecycle Hooks**: `onStart`, `onEnd`, `setUp`, `tearDown` callbacks
23
+ * - **Looping**: Support for finite and infinite loops
24
+ * - **Delays and Drag**: Add delays before animation start and drag time after completion
25
+ * - **Reverse Playback**: Animations can play in reverse
26
+ * - **Hierarchical Composition**: Nest composite animations to create complex sequences
27
+ *
28
+ * ## Main Exports
29
+ *
30
+ * - {@link Animation}: Single keyframe animation for a value
31
+ * - {@link CompositeAnimation}: Container for sequencing multiple animations
32
+ * - {@link Keyframe}: Type defining a value at a percentage point in time
33
+ * - {@link AnimatableAttributeHelper}: Interface for type-specific interpolation
34
+ * - Helper functions: {@link pointHelperFunctions}, {@link numberHelperFunctions}, {@link rgbHelperFunctions}
35
+ *
36
+ * @example
37
+ * Basic number animation
38
+ * ```typescript
39
+ * import { Animation, numberHelperFunctions } from '@ue-too/animate';
40
+ *
41
+ * let currentValue = 0;
42
+ *
43
+ * const animation = new Animation(
44
+ * [
45
+ * { percentage: 0, value: 0 },
46
+ * { percentage: 0.5, value: 50 },
47
+ * { percentage: 1, value: 100 }
48
+ * ],
49
+ * (value) => { currentValue = value; }, // Apply function
50
+ * numberHelperFunctions,
51
+ * 1000 // Duration in ms
52
+ * );
53
+ *
54
+ * animation.start();
55
+ *
56
+ * // In your animation loop
57
+ * function animate(deltaTime: number) {
58
+ * animation.animate(deltaTime);
59
+ * console.log('Current value:', currentValue);
60
+ * requestAnimationFrame(animate);
61
+ * }
62
+ * ```
63
+ *
64
+ * @example
65
+ * Composite animation sequence
66
+ * ```typescript
67
+ * import { Animation, CompositeAnimation, numberHelperFunctions } from '@ue-too/animate';
68
+ *
69
+ * let x = 0, y = 0;
70
+ *
71
+ * const moveRight = new Animation(
72
+ * [{ percentage: 0, value: 0 }, { percentage: 1, value: 100 }],
73
+ * (value) => { x = value; },
74
+ * numberHelperFunctions,
75
+ * 500
76
+ * );
77
+ *
78
+ * const moveDown = new Animation(
79
+ * [{ percentage: 0, value: 0 }, { percentage: 1, value: 100 }],
80
+ * (value) => { y = value; },
81
+ * numberHelperFunctions,
82
+ * 500
83
+ * );
84
+ *
85
+ * const sequence = new CompositeAnimation();
86
+ * sequence.addAnimation('moveRight', moveRight, 0);
87
+ * sequence.addAnimationAfter('moveDown', moveDown, 'moveRight');
88
+ *
89
+ * sequence.start();
90
+ *
91
+ * // Animate in your loop
92
+ * function loop(deltaTime: number) {
93
+ * sequence.animate(deltaTime);
94
+ * requestAnimationFrame(loop);
95
+ * }
96
+ * ```
97
+ *
98
+ * @see {@link Animation} for single value animations
99
+ * @see {@link CompositeAnimation} for animation sequencing
100
+ */
1
101
  export * from "./animatable-attribute";
2
102
  export * from "./composite-animation";