|
1 | | -/** |
2 | | - * Schedule a callback to run on the next animation frame. |
3 | | - * Multiple calls within the same frame are batched together. |
4 | | - * |
5 | | - * @param {VoidFunction} fn - The callback to execute. |
6 | | - */ |
7 | | -export function schedule(fn: VoidFunction): void; |
8 | | -/** |
9 | | - * Represents an asynchronous animation operation. |
10 | | - * Provides both callback-based and promise-based completion APIs. |
11 | | - */ |
12 | 1 | export class AnimateRunner { |
13 | 2 | /** |
14 | | - * Run an array of animation runners in sequence. |
15 | | - * Each runner waits for the previous one to complete. |
| 3 | + * Executes a list of runners sequentially. |
| 4 | + * Each must complete before the next starts. |
16 | 5 | * |
17 | | - * @param {AnimateRunner[]} runners - Runners to execute in order. |
18 | | - * @param {(ok: boolean) => void} callback - Invoked when all complete or one fails. |
| 6 | + * @param {AnimateRunner[]} runners |
| 7 | + * @param {(ok: boolean) => void} callback |
19 | 8 | */ |
20 | 9 | static _chain( |
21 | 10 | runners: AnimateRunner[], |
22 | 11 | callback: (ok: boolean) => void, |
23 | 12 | ): void; |
24 | 13 | /** |
25 | | - * Waits for all animation runners to complete before invoking the callback. |
| 14 | + * Waits until all runners complete. |
26 | 15 | * |
27 | | - * @param {AnimateRunner[]} runners - Active runners to wait for. |
28 | | - * @param {(ok: boolean) => void} callback - Called when all runners complete. |
| 16 | + * @param {AnimateRunner[]} runners |
| 17 | + * @param {(ok: boolean) => void} callback |
29 | 18 | */ |
30 | 19 | static _all(runners: AnimateRunner[], callback: (ok: boolean) => void): void; |
31 | 20 | /** |
32 | | - * @param {import("../interface.ts").AnimationHost} [host] - Optional animation host. |
| 21 | + * @param {AnimationHost} [host] - Optional animation host callbacks. |
| 22 | + * @param {boolean} [jsAnimation=false] |
| 23 | + * If true: use RAF/timer ticks. |
| 24 | + * If false: use batched CSS animation ticks. |
33 | 25 | */ |
34 | | - constructor(host?: import("../interface.ts").AnimationHost); |
35 | | - /** @type {import("../interface.ts").AnimationHost} */ |
36 | | - _host: import("../interface.ts").AnimationHost; |
| 26 | + constructor(host?: AnimationHost, jsAnimation?: boolean); |
| 27 | + /** @type {AnimationHost} */ |
| 28 | + _host: AnimationHost; |
37 | 29 | /** @type {Array<(ok: boolean) => void>} */ |
38 | 30 | _doneCallbacks: Array<(ok: boolean) => void>; |
39 | 31 | /** @type {RunnerState} */ |
40 | 32 | _state: RunnerState; |
41 | | - /** @type {Promise<void>|null} */ |
42 | | - _promise: Promise<void> | null; |
43 | | - /** @type {(fn: VoidFunction) => void} */ |
44 | | - _schedule: (fn: VoidFunction) => void; |
45 | 33 | /** |
46 | | - * Sets or updates the animation host. |
47 | | - * @param {import("../interface.ts").AnimationHost} host - The host object. |
| 34 | + * Deferred promise used by .then/.catch/.finally. |
| 35 | + * @type {Promise<void>|null} |
| 36 | + * @private |
| 37 | + */ |
| 38 | + private _promise; |
| 39 | + _tick: (fn: any) => void; |
| 40 | + /** |
| 41 | + * Sets or replaces the current host. |
| 42 | + * @param {AnimationHost} host |
48 | 43 | */ |
49 | | - setHost(host: import("../interface.ts").AnimationHost): void; |
| 44 | + setHost(host: AnimationHost): void; |
50 | 45 | /** |
51 | | - * Registers a callback to be called once the animation completes. |
52 | | - * If the animation is already complete, it's called immediately. |
| 46 | + * Register a completion callback. |
| 47 | + * Fires immediately if animation is already done. |
53 | 48 | * |
54 | | - * @param {(ok: boolean) => void} fn - Completion callback. |
| 49 | + * @param {(ok: boolean) => void} fn |
55 | 50 | */ |
56 | 51 | done(fn: (ok: boolean) => void): void; |
57 | 52 | /** |
58 | | - * Notifies the host of animation progress. |
59 | | - * @param {...any} args - Progress arguments. |
| 53 | + * Reports progress to host. |
| 54 | + * @param {...any} args |
60 | 55 | */ |
61 | 56 | progress(...args: any[]): void; |
62 | | - /** Pauses the animation, if supported by the host. */ |
| 57 | + /** Pause underlying animation (if supported). */ |
63 | 58 | pause(): void; |
64 | | - /** Resumes the animation, if supported by the host. */ |
| 59 | + /** Resume underlying animation (if supported). */ |
65 | 60 | resume(): void; |
66 | | - /** Ends the animation successfully. */ |
| 61 | + /** |
| 62 | + * Ends the animation successfully. |
| 63 | + * Equivalent to user choosing to finish it immediately. |
| 64 | + */ |
67 | 65 | end(): void; |
68 | | - /** Cancels the animation. */ |
69 | | - cancel(): void; |
70 | 66 | /** |
71 | | - * Marks the animation as complete on the next animation frame. |
72 | | - * @param {boolean} [status=true] - True if successful, false if canceled. |
| 67 | + * Cancels the animation. |
73 | 68 | */ |
74 | | - complete(status?: boolean): void; |
| 69 | + cancel(): void; |
75 | 70 | /** |
76 | | - * Returns a promise that resolves or rejects when the animation completes. |
77 | | - * @returns {Promise<void>} Promise resolved on success or rejected on cancel. |
| 71 | + * Schedule animation completion. |
| 72 | + * |
| 73 | + * @param {boolean} [status=true] |
78 | 74 | */ |
79 | | - getPromise(): Promise<void>; |
80 | | - /** @inheritdoc */ |
81 | | - then(onFulfilled: any, onRejected: any): Promise<void>; |
82 | | - /** @inheritdoc */ |
83 | | - catch(onRejected: any): Promise<void>; |
84 | | - /** @inheritdoc */ |
85 | | - finally(onFinally: any): Promise<void>; |
| 75 | + complete(status?: boolean): void; |
86 | 76 | /** |
87 | 77 | * Completes the animation and invokes all done callbacks. |
| 78 | + * @param {boolean} status |
88 | 79 | * @private |
89 | | - * @param {boolean} status - True if completed successfully, false if canceled. |
90 | 80 | */ |
91 | 81 | private _finish; |
| 82 | + /** |
| 83 | + * Returns an internal promise that resolves on success, |
| 84 | + * and rejects on cancel. |
| 85 | + * |
| 86 | + * @returns {Promise<void>} |
| 87 | + */ |
| 88 | + getPromise(): Promise<void>; |
| 89 | + /** |
| 90 | + * Standard "thenable" interface |
| 91 | + * @template T |
| 92 | + * @param {(value: void) => T|Promise<T>} onFulfilled |
| 93 | + * @param {(reason: any) => any} [onRejected] |
| 94 | + * @returns {Promise<T>} |
| 95 | + */ |
| 96 | + then<T>( |
| 97 | + onFulfilled: (value: void) => T | Promise<T>, |
| 98 | + onRejected?: (reason: any) => any, |
| 99 | + ): Promise<T>; |
| 100 | + /** |
| 101 | + * Standard promise catcher. |
| 102 | + * @param {(reason: any) => any} onRejected |
| 103 | + * @returns {Promise<void>} |
| 104 | + */ |
| 105 | + catch(onRejected: (reason: any) => any): Promise<void>; |
| 106 | + /** |
| 107 | + * Standard promise finally. |
| 108 | + * @param {() => any} onFinally |
| 109 | + * @returns {Promise<void>} |
| 110 | + */ |
| 111 | + finally(onFinally: () => any): Promise<void>; |
92 | 112 | } |
| 113 | +export type AnimationHost = import("../interface.ts").AnimationHost; |
93 | 114 | /** |
94 | 115 | * Internal runner states. |
95 | 116 | */ |
|
0 commit comments