@7sage/vidstack
Version:
UI component library for building high-quality, accessible video and audio experiences on the web.
27 lines (24 loc) • 525 B
JavaScript
import { isUndefined, isNumber } from './vidstack-BGSTndAW.js';
class RAFLoop {
#id;
#callback;
constructor(callback) {
this.#callback = callback;
}
start() {
if (!isUndefined(this.#id)) return;
this.#loop();
}
stop() {
if (isNumber(this.#id)) window.cancelAnimationFrame(this.#id);
this.#id = void 0;
}
#loop() {
this.#id = window.requestAnimationFrame(() => {
if (isUndefined(this.#id)) return;
this.#callback();
this.#loop();
});
}
}
export { RAFLoop };