Skip to content

Commit 9380ac0

Browse files
committed
Fix js animation and demo
1 parent 991cffa commit 9380ac0

File tree

8 files changed

+398
-680
lines changed

8 files changed

+398
-680
lines changed

@types/animations/animate-js.d.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,9 @@
1-
/**
2-
* @param {ng.AnimateProvider} $animateProvider
3-
*/
4-
export function AnimateJsProvider($animateProvider: ng.AnimateProvider): void;
1+
export function AnimateJsProvider($animateProvider: any): void;
52
export class AnimateJsProvider {
6-
/**
7-
* @param {ng.AnimateProvider} $animateProvider
8-
*/
9-
constructor($animateProvider: ng.AnimateProvider);
3+
constructor($animateProvider: any);
104
$get: (
115
| string
12-
| (($injector: ng.InjectorService) => (
13-
element: any,
14-
event: any,
15-
classes: any,
16-
options: any,
17-
) => {
18-
$$willAnimate: boolean;
19-
end(): any;
20-
start(): any;
21-
})
6+
| (($injector: ng.InjectorService) => import("./interface.ts").AnimateJsFn)
227
)[];
238
}
249
export namespace AnimateJsProvider {

@types/animations/interface.d.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,19 @@ export interface AnimationOptions {
9898
removeClass?: string;
9999
to?: Record<string, string | number>;
100100
tempClasses: string | string[];
101+
/** Optional DOM operation callback executed before animation */
102+
domOperation?: () => void;
103+
}
104+
export interface AnimateJsRunner {
105+
$$willAnimate: true;
106+
start: () => AnimateRunner;
107+
end: () => AnimateRunner;
108+
}
109+
export interface AnimateJsFn {
110+
(
111+
element: HTMLElement,
112+
event: string,
113+
classes?: string | null,
114+
options?: AnimationOptions,
115+
): AnimateJsRunner;
101116
}

@types/animations/runner/animate-runner.d.ts

Lines changed: 73 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,116 @@
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-
*/
121
export class AnimateRunner {
132
/**
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.
165
*
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
198
*/
209
static _chain(
2110
runners: AnimateRunner[],
2211
callback: (ok: boolean) => void,
2312
): void;
2413
/**
25-
* Waits for all animation runners to complete before invoking the callback.
14+
* Waits until all runners complete.
2615
*
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
2918
*/
3019
static _all(runners: AnimateRunner[], callback: (ok: boolean) => void): void;
3120
/**
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.
3325
*/
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;
3729
/** @type {Array<(ok: boolean) => void>} */
3830
_doneCallbacks: Array<(ok: boolean) => void>;
3931
/** @type {RunnerState} */
4032
_state: RunnerState;
41-
/** @type {Promise<void>|null} */
42-
_promise: Promise<void> | null;
43-
/** @type {(fn: VoidFunction) => void} */
44-
_schedule: (fn: VoidFunction) => void;
4533
/**
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
4843
*/
49-
setHost(host: import("../interface.ts").AnimationHost): void;
44+
setHost(host: AnimationHost): void;
5045
/**
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.
5348
*
54-
* @param {(ok: boolean) => void} fn - Completion callback.
49+
* @param {(ok: boolean) => void} fn
5550
*/
5651
done(fn: (ok: boolean) => void): void;
5752
/**
58-
* Notifies the host of animation progress.
59-
* @param {...any} args - Progress arguments.
53+
* Reports progress to host.
54+
* @param {...any} args
6055
*/
6156
progress(...args: any[]): void;
62-
/** Pauses the animation, if supported by the host. */
57+
/** Pause underlying animation (if supported). */
6358
pause(): void;
64-
/** Resumes the animation, if supported by the host. */
59+
/** Resume underlying animation (if supported). */
6560
resume(): void;
66-
/** Ends the animation successfully. */
61+
/**
62+
* Ends the animation successfully.
63+
* Equivalent to user choosing to finish it immediately.
64+
*/
6765
end(): void;
68-
/** Cancels the animation. */
69-
cancel(): void;
7066
/**
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.
7368
*/
74-
complete(status?: boolean): void;
69+
cancel(): void;
7570
/**
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]
7874
*/
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;
8676
/**
8777
* Completes the animation and invokes all done callbacks.
78+
* @param {boolean} status
8879
* @private
89-
* @param {boolean} status - True if completed successfully, false if canceled.
9080
*/
9181
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>;
92112
}
113+
export type AnimationHost = import("../interface.ts").AnimationHost;
93114
/**
94115
* Internal runner states.
95116
*/

src/animations/animate-js.html

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,25 @@
66

77
<link rel="shortcut icon" type="image/png" href="/images/favicon.ico" />
88
<script type="module" src="/src/index.js"></script>
9-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/anime.min.js"></script>
10-
<script>
11-
document.addEventListener("DOMContentLoaded", () => {
12-
window.angular.module("test", []).animation(".movable", [
13-
function () {
14-
return {
15-
addClass: function (element, className, doneFn) {
16-
anime({
17-
targets: element,
18-
translateX: parseInt(className),
19-
});
20-
},
21-
removeClass: function (element, className, doneFn) {},
22-
setClass: function (element, className, removedClass, doneFn) {
23-
anime({
24-
targets: element,
25-
translateX: parseInt(className),
26-
});
27-
},
28-
};
9+
<script src="https://cdn.jsdelivr.net/npm/animejs/dist/bundles/anime.umd.min.js"></script>
10+
11+
<script type="module">
12+
window.angular.module("test", []).animation(".movable", function () {
13+
const { animate } = anime;
14+
return {
15+
addClass(element, className, doneFn) {
16+
animate(element, {
17+
translateX: parseInt(className),
18+
onComplete: doneFn,
19+
});
20+
},
21+
setClass(element, className, removedClass, doneFn) {
22+
animate(element, {
23+
translateX: parseInt(className),
24+
onComplete: doneFn,
25+
});
2926
},
30-
]);
27+
};
3128
});
3229
</script>
3330

0 commit comments

Comments
 (0)