@figliolia/ripples
Version:
WebGL ripples based on the clever work of Pim Schreurs
41 lines (40 loc) • 1.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Animations = void 0;
const event_emitter_1 = require("@figliolia/event-emitter");
class Animations {
static register(callback) {
const ID = this.callstack.register(callback);
void Promise.resolve().then(() => {
this.nextFrame();
});
return ID;
}
static delete(ID) {
return this.callstack.remove(ID);
}
static nextFrame() {
if (this.frame) {
return;
}
this.animate();
}
static animate() {
this.frame = requestAnimationFrame(() => {
if (!this.callstack.length) {
return this.closeLoop();
}
this.callstack.execute();
this.animate();
});
}
static closeLoop() {
if (this.frame) {
cancelAnimationFrame(this.frame);
this.frame = null;
}
}
}
exports.Animations = Animations;
Animations.frame = null;
Animations.callstack = new event_emitter_1.Subscriptable();