'use strict';

/*!
 * @techmely/utils
 * Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com>
 * MIT Licensed
 */


// src/matchMedia.ts
function windowMatchMedia() {
  return typeof window !== "undefined" ? window.matchMedia || window.msMatchMedia : void 0;
}

// src/isPrefersReducedMotion.ts
function isPrefersReducedMotion() {
  const mediaQuery = windowMatchMedia()?.("(prefers-reduced-motion: reduce)");
  return typeof window !== "undefined" ? mediaQuery?.matches : false;
}

// 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 });
  });
}

exports.animateTo = animateTo;
