JavaScript animation engine
Keep Callback and promise types, just remove nullify then on this #1043 #1082
Julian Garnier5c6509dc98b4
diff --git a/dist/modules/animation/animation.cjs b/dist/modules/animation/animation.cjsindex 344dace4..7ae1a407 100644--- a/dist/modules/animation/animation.cjs+++ b/dist/modules/animation/animation.cjs@@ -647,8 +647,12 @@ class JSAnimation extends timer.Timer {}/**- * @param {Callback<this>} [callback]- * @return {Promise}+ * @typedef {this & {then: null}} ResolvedJSAnimation+ */++ /**+ * @param {Callback<ResolvedJSAnimation>} [callback]+ * @return Promise<this>*/then(callback) {return super.then(callback);diff --git a/dist/modules/animation/animation.d.ts b/dist/modules/animation/animation.d.tsindex b184cf76..9d560e41 100644--- a/dist/modules/animation/animation.d.ts+++ b/dist/modules/animation/animation.d.ts@@ -30,10 +30,15 @@ export class JSAnimation extends Timer {*/revert(): this;/**- * @param {Callback<this>} [callback]- * @return {Promise}+ * @typedef {this & {then: null}} ResolvedJSAnimation*/- then(callback?: Callback<this>): Promise<any>;+ /**+ * @param {Callback<ResolvedJSAnimation>} [callback]+ * @return Promise<this>+ */+ then(callback?: Callback<this & {+ then: null;+ }>): Promise<any>;}export function animate(targets: TargetsParam, parameters: AnimationParams): JSAnimation;import { Timer } from '../timer/timer.js';diff --git a/dist/modules/animation/animation.js b/dist/modules/animation/animation.jsindex 93f73792..fb765045 100644--- a/dist/modules/animation/animation.js+++ b/dist/modules/animation/animation.js@@ -645,8 +645,12 @@ class JSAnimation extends Timer {}/**- * @param {Callback<this>} [callback]- * @return {Promise}+ * @typedef {this & {then: null}} ResolvedJSAnimation+ */++ /**+ * @param {Callback<ResolvedJSAnimation>} [callback]+ * @return Promise<this>*/then(callback) {return super.then(callback);diff --git a/dist/modules/timeline/timeline.cjs b/dist/modules/timeline/timeline.cjsindex 4454caae..00804f53 100644--- a/dist/modules/timeline/timeline.cjs+++ b/dist/modules/timeline/timeline.cjs@@ -294,8 +294,12 @@ class Timeline extends timer.Timer {}/**- * @param {Callback<this>} [callback]- * @return {Promise}+ * @typedef {this & {then: null}} ResolvedTimeline+ */++ /**+ * @param {Callback<ResolvedTimeline>} [callback]+ * @return Promise<this>*/then(callback) {return super.then(callback);diff --git a/dist/modules/timeline/timeline.d.ts b/dist/modules/timeline/timeline.d.tsindex e633a01e..7a3f0468 100644--- a/dist/modules/timeline/timeline.d.ts+++ b/dist/modules/timeline/timeline.d.ts@@ -144,10 +144,15 @@ export class Timeline extends Timer {*/revert(): this;/**- * @param {Callback<this>} [callback]- * @return {Promise}+ * @typedef {this & {then: null}} ResolvedTimeline*/- then(callback?: Callback<this>): Promise<any>;+ /**+ * @param {Callback<ResolvedTimeline>} [callback]+ * @return Promise<this>+ */+ then(callback?: Callback<this & {+ then: null;+ }>): Promise<any>;}export function createTimeline(parameters?: TimelineParams): Timeline;import { Timer } from '../timer/timer.js';diff --git a/dist/modules/timeline/timeline.js b/dist/modules/timeline/timeline.jsindex 76f13266..c940b1d9 100644--- a/dist/modules/timeline/timeline.js+++ b/dist/modules/timeline/timeline.js@@ -292,8 +292,12 @@ class Timeline extends Timer {}/**- * @param {Callback<this>} [callback]- * @return {Promise}+ * @typedef {this & {then: null}} ResolvedTimeline+ */++ /**+ * @param {Callback<ResolvedTimeline>} [callback]+ * @return Promise<this>*/then(callback) {return super.then(callback);diff --git a/dist/modules/timer/timer.cjs b/dist/modules/timer/timer.cjsindex 8d3af8eb..1a22c9f4 100644--- a/dist/modules/timer/timer.cjs+++ b/dist/modules/timer/timer.cjs@@ -57,7 +57,7 @@ const reviveTimer = timer => {if (timer._hasChildren) {helpers.forEachChildren(timer, reviveTimer);} else {- helpers.forEachChildren(timer, (/** @type {Tween} tween*/tween) => {+ helpers.forEachChildren(timer, (/** @type {Tween} tween */tween) => {if (tween._composition !== consts.compositionTypes.none) {composition.composeTween(tween, composition.getTweenSiblings(tween.target, tween.property));}@@ -457,8 +457,12 @@ class Timer extends clock.Clock {}/**- * @param {Callback<this>} [callback]- * @return {Promise}+ * @typedef {this & {then: null}} ResolvedTimer+ */++ /**+ * @param {Callback<ResolvedTimer>} [callback]+ * @return Promise<this>*/then(callback = consts.noop) {const then = this.then;@@ -466,7 +470,7 @@ class Timer extends clock.Clock {// this.then = null prevents infinite recursion if returned by an async function// https://github.com/juliangarnierorg/anime-beta/issues/26this.then = null;- callback(this);+ callback(/** @type {ResolvedTimer} */(this));this.then = then;this._resolve = consts.noop;};diff --git a/dist/modules/timer/timer.d.ts b/dist/modules/timer/timer.d.tsindex 979b88be..f2a1bfc4 100644--- a/dist/modules/timer/timer.d.ts+++ b/dist/modules/timer/timer.d.ts@@ -127,10 +127,15 @@ export class Timer extends Clock {*/complete(): this;/**- * @param {Callback<this>} [callback]- * @return {Promise}+ * @typedef {this & {then: null}} ResolvedTimer*/- then(callback?: Callback<this>): Promise<any>;+ /**+ * @param {Callback<ResolvedTimer>} [callback]+ * @return Promise<this>+ */+ then(callback?: Callback<this & {+ then: null;+ }>): Promise<any>;}export function createTimer(parameters?: TimerParams): Timer;import { Clock } from '../core/clock.js';diff --git a/dist/modules/timer/timer.js b/dist/modules/timer/timer.jsindex 78795dca..88e95cd6 100644--- a/dist/modules/timer/timer.js+++ b/dist/modules/timer/timer.js@@ -55,7 +55,7 @@ const reviveTimer = timer => {if (timer._hasChildren) {forEachChildren(timer, reviveTimer);} else {- forEachChildren(timer, (/** @type {Tween} tween*/tween) => {+ forEachChildren(timer, (/** @type {Tween} tween */tween) => {if (tween._composition !== compositionTypes.none) {composeTween(tween, getTweenSiblings(tween.target, tween.property));}@@ -455,8 +455,12 @@ class Timer extends Clock {}/**- * @param {Callback<this>} [callback]- * @return {Promise}+ * @typedef {this & {then: null}} ResolvedTimer+ */++ /**+ * @param {Callback<ResolvedTimer>} [callback]+ * @return Promise<this>*/then(callback = noop) {const then = this.then;@@ -464,7 +468,7 @@ class Timer extends Clock {// this.then = null prevents infinite recursion if returned by an async function// https://github.com/juliangarnierorg/anime-beta/issues/26this.then = null;- callback(this);+ callback(/** @type {ResolvedTimer} */(this));this.then = then;this._resolve = noop;};diff --git a/dist/modules/types/index.d.ts b/dist/modules/types/index.d.tsindex 15d28141..5ab38aa4 100644--- a/dist/modules/types/index.d.ts+++ b/dist/modules/types/index.d.ts@@ -254,7 +254,6 @@ export type TimelineParams = TimerOptions & TimelineOptions & TickableCallbacks<export type WAAPITweenValue = string | number | Array<string> | Array<number>;export type WAAPIFunctionValue = (target: DOMTarget, index: number, length: number) => WAAPITweenValue;export type WAAPIKeyframeValue = WAAPITweenValue | WAAPIFunctionValue | Array<string | number | WAAPIFunctionValue>;-export type WAAPICallback = Callback<WAAPIAnimation>;export type WAAPITweenOptions = {to?: WAAPIKeyframeValue;from?: WAAPIKeyframeValue;@@ -274,9 +273,9 @@ export type WAAPIAnimationOptions = {ease?: WAAPIEasingParam;composition?: CompositeOperation;persist?: boolean;- onComplete?: WAAPICallback;+ onComplete?: Callback<WAAPIAnimation>;};-export type WAAPIAnimationParams = Record<string, WAAPIKeyframeValue | WAAPIAnimationOptions | boolean | ScrollObserver | WAAPICallback | WAAPIEasingParam | WAAPITweenOptions> & WAAPIAnimationOptions;+export type WAAPIAnimationParams = Record<string, WAAPIKeyframeValue | WAAPIAnimationOptions | boolean | ScrollObserver | Callback<WAAPIAnimation> | WAAPIEasingParam | WAAPITweenOptions> & WAAPIAnimationOptions;export type AnimatablePropertySetter = (to: number | Array<number>, duration?: number, ease?: EasingParam) => AnimatableObject;export type AnimatablePropertyGetter = () => number | Array<number>;export type AnimatableProperty = AnimatablePropertySetter & AnimatablePropertyGetter;diff --git a/dist/modules/waapi/waapi.cjs b/dist/modules/waapi/waapi.cjsindex 1b4b848b..dfcd689f 100644--- a/dist/modules/waapi/waapi.cjs+++ b/dist/modules/waapi/waapi.cjs@@ -27,7 +27,6 @@ var composition = require('./composition.cjs');* WAAPIAnimationParams,* WAAPITweenOptions,* WAAPIKeyframeValue,- * WAAPICallback,* WAAPITweenValue* } from '../types/index.js'*/@@ -459,14 +458,18 @@ class WAAPIAnimation {}/**- * @param {WAAPICallback} [callback]- * @return {Promise}+ * @typedef {this & {then: null}} ResolvedWAAPIAnimation+ */++ /**+ * @param {Callback<ResolvedWAAPIAnimation>} [callback]+ * @return Promise<this>*/then(callback = consts.noop) {const then = this.then;const onResolve = () => {this.then = null;- callback(this);+ callback(/** @type {ResolvedWAAPIAnimation} */(this));this.then = then;this._resolve = consts.noop;};diff --git a/dist/modules/waapi/waapi.d.ts b/dist/modules/waapi/waapi.d.tsindex 6ced2b0b..25834cf6 100644--- a/dist/modules/waapi/waapi.d.ts+++ b/dist/modules/waapi/waapi.d.ts@@ -65,10 +65,15 @@ export class WAAPIAnimation {cancel(): this;revert(): this;/**- * @param {WAAPICallback} [callback]- * @return {Promise}+ * @typedef {this & {then: null}} ResolvedWAAPIAnimation*/- then(callback?: WAAPICallback): Promise<any>;+ /**+ * @param {Callback<ResolvedWAAPIAnimation>} [callback]+ * @return Promise<this>+ */+ then(callback?: Callback<this & {+ then: null;+ }>): Promise<any>;}export namespace waapi {export function animate(targets: DOMTargetsParam, params: WAAPIAnimationParams): WAAPIAnimation;@@ -77,7 +82,6 @@ export namespace waapi {import type { DOMTargetsArray } from '../types/index.js';import type { Callback } from '../types/index.js';import type { ScrollObserver } from '../events/scroll.js';-import type { WAAPICallback } from '../types/index.js';import type { DOMTargetsParam } from '../types/index.js';import type { WAAPIAnimationParams } from '../types/index.js';/**@@ -91,7 +95,6 @@ import type { WAAPIAnimationParams } from '../types/index.js';* WAAPIAnimationParams,* WAAPITweenOptions,* WAAPIKeyframeValue,- * WAAPICallback,* WAAPITweenValue* } from '../types/index.js'*/diff --git a/dist/modules/waapi/waapi.js b/dist/modules/waapi/waapi.jsindex a98b8777..dd989da3 100644--- a/dist/modules/waapi/waapi.js+++ b/dist/modules/waapi/waapi.js@@ -25,7 +25,6 @@ import { addWAAPIAnimation } from './composition.js';* WAAPIAnimationParams,* WAAPITweenOptions,* WAAPIKeyframeValue,- * WAAPICallback,* WAAPITweenValue* } from '../types/index.js'*/@@ -457,14 +456,18 @@ class WAAPIAnimation {}/**- * @param {WAAPICallback} [callback]- * @return {Promise}+ * @typedef {this & {then: null}} ResolvedWAAPIAnimation+ */++ /**+ * @param {Callback<ResolvedWAAPIAnimation>} [callback]+ * @return Promise<this>*/then(callback = noop) {const then = this.then;const onResolve = () => {this.then = null;- callback(this);+ callback(/** @type {ResolvedWAAPIAnimation} */(this));this.then = then;this._resolve = noop;};diff --git a/src/animation/animation.js b/src/animation/animation.jsindex fad08f56..83e0983c 100644--- a/src/animation/animation.js+++ b/src/animation/animation.js@@ -697,8 +697,12 @@ export class JSAnimation extends Timer {}/**- * @param {Callback<this>} [callback]- * @return {Promise}+ * @typedef {this & {then: null}} ResolvedJSAnimation+ */++ /**+ * @param {Callback<ResolvedJSAnimation>} [callback]+ * @return Promise<this>*/then(callback) {return super.then(callback);diff --git a/src/timeline/timeline.js b/src/timeline/timeline.jsindex f4c3a6f4..ef62d7d2 100644--- a/src/timeline/timeline.js+++ b/src/timeline/timeline.js@@ -331,8 +331,12 @@ export class Timeline extends Timer {}/**- * @param {Callback<this>} [callback]- * @return {Promise}+ * @typedef {this & {then: null}} ResolvedTimeline+ */++ /**+ * @param {Callback<ResolvedTimeline>} [callback]+ * @return Promise<this>*/then(callback) {return super.then(callback);diff --git a/src/timer/timer.js b/src/timer/timer.jsindex af51fa7a..87fda73f 100644--- a/src/timer/timer.js+++ b/src/timer/timer.js@@ -87,7 +87,7 @@ const reviveTimer = timer => {if (timer._hasChildren) {forEachChildren(timer, reviveTimer);} else {- forEachChildren(timer, (/** @type {Tween} tween*/tween) => {+ forEachChildren(timer, (/** @type {Tween} tween */tween) => {if (tween._composition !== compositionTypes.none) {composeTween(tween, getTweenSiblings(tween.target, tween.property));}@@ -487,8 +487,12 @@ export class Timer extends Clock {}/**- * @param {Callback<this>} [callback]- * @return {Promise}+ * @typedef {this & {then: null}} ResolvedTimer+ */++ /**+ * @param {Callback<ResolvedTimer>} [callback]+ * @return Promise<this>*/then(callback = noop) {const then = this.then;@@ -496,7 +500,7 @@ export class Timer extends Clock {// this.then = null prevents infinite recursion if returned by an async function// https://github.com/juliangarnierorg/anime-beta/issues/26this.then = null;- callback(this);+ callback(/** @type {ResolvedTimer} */(this));this.then = then;this._resolve = noop;}diff --git a/src/types/index.js b/src/types/index.jsindex aa43bc71..d7c44928 100644--- a/src/types/index.js+++ b/src/types/index.js@@ -400,10 +400,6 @@ export {}* @typedef {WAAPITweenValue|WAAPIFunctionValue|Array<String|Number|WAAPIFunctionValue>} WAAPIKeyframeValue*/-/**- * @typedef {Callback<WAAPIAnimation>} WAAPICallback- */-/*** @typedef {Object} WAAPITweenOptions* @property {WAAPIKeyframeValue} [to]@@ -426,11 +422,11 @@ export {}* @property {WAAPIEasingParam} [ease]* @property {CompositeOperation} [composition]* @property {Boolean} [persist]- * @property {WAAPICallback} [onComplete]+ * @property {Callback<WAAPIAnimation>} [onComplete]*//**- * @typedef {Record<String, WAAPIKeyframeValue | WAAPIAnimationOptions | Boolean | ScrollObserver | WAAPICallback | WAAPIEasingParam | WAAPITweenOptions> & WAAPIAnimationOptions} WAAPIAnimationParams+ * @typedef {Record<String, WAAPIKeyframeValue | WAAPIAnimationOptions | Boolean | ScrollObserver | Callback<WAAPIAnimation> | WAAPIEasingParam | WAAPITweenOptions> & WAAPIAnimationOptions} WAAPIAnimationParams*/// Animatable typesdiff --git a/src/waapi/waapi.js b/src/waapi/waapi.jsindex a1c7a5a5..bb5e9f32 100644--- a/src/waapi/waapi.js+++ b/src/waapi/waapi.js@@ -61,7 +61,6 @@ import {* WAAPIAnimationParams,* WAAPITweenOptions,* WAAPIKeyframeValue,- * WAAPICallback,* WAAPITweenValue* } from '../types/index.js'*/@@ -494,14 +493,18 @@ export class WAAPIAnimation {}/**- * @param {WAAPICallback} [callback]- * @return {Promise}+ * @typedef {this & {then: null}} ResolvedWAAPIAnimation+ */++ /**+ * @param {Callback<ResolvedWAAPIAnimation>} [callback]+ * @return Promise<this>*/then(callback = noop) {const then = this.then;const onResolve = () => {this.then = null;- callback(this);+ callback(/** @type {ResolvedWAAPIAnimation} */(this));this.then = then;this._resolve = noop;}diff --git a/tests/playground/sandbox/index.js b/tests/playground/sandbox/index.jsindex f102423b..2f9aa736 100644--- a/tests/playground/sandbox/index.js+++ b/tests/playground/sandbox/index.js@@ -1,14 +1,5 @@import { waapi, animate, onScroll, $, set, stagger, spring, random, utils } from '../../../dist/modules/index.js';-const container = document.querySelector("main");-animate(".rectangle", {- x: "70px",- ease: "inOutCirc",- delay: 1000,- loopDelay: 1000,- loop: true,- autoplay: onScroll({- container,- debug: true- })-});+async function animation() {+ await animate('test', { x: 100 });+}\ No newline at end of file