@techmely/utils
Version:
Collection of helpful JavaScript / TypeScript utils
21 lines (18 loc) • 660 B
JavaScript
import { isPrefersReducedMotion } from './chunk-IELBQYQJ.mjs';
import './chunk-BPJKMILL.mjs';
import './chunk-NYLAFCGV.mjs';
// src/animateTo.ts
function animateTo(el, keyframes, options) {
return new Promise((resolve) => {
if (options?.duration === Number.POSITIVE_INFINITY) {
throw new Error("Promise-based animations must be finite.");
}
const animation = el.animate(keyframes, {
...options,
duration: isPrefersReducedMotion() ? 0 : options?.duration
});
animation.addEventListener("cancel", resolve, { once: true });
animation.addEventListener("finish", resolve, { once: true });
});
}
export { animateTo };