chunk.CTCDC263.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import {
  2. __spreadProps,
  3. __spreadValues
  4. } from "./chunk.IHGPZX35.js";
  5. // src/internal/animate.ts
  6. function animateTo(el, keyframes, options) {
  7. return new Promise(async (resolve) => {
  8. if ((options == null ? void 0 : options.duration) === Infinity) {
  9. throw new Error("Promise-based animations must be finite.");
  10. }
  11. const animation = el.animate(keyframes, __spreadProps(__spreadValues({}, options), {
  12. duration: prefersReducedMotion() ? 0 : options.duration
  13. }));
  14. animation.addEventListener("cancel", resolve, { once: true });
  15. animation.addEventListener("finish", resolve, { once: true });
  16. });
  17. }
  18. function parseDuration(delay) {
  19. delay = (delay + "").toLowerCase();
  20. if (delay.indexOf("ms") > -1) {
  21. return parseFloat(delay);
  22. }
  23. if (delay.indexOf("s") > -1) {
  24. return parseFloat(delay) * 1e3;
  25. }
  26. return parseFloat(delay);
  27. }
  28. function prefersReducedMotion() {
  29. const query = window.matchMedia("(prefers-reduced-motion: reduce)");
  30. return query == null ? void 0 : query.matches;
  31. }
  32. function stopAnimations(el) {
  33. return Promise.all(el.getAnimations().map((animation) => {
  34. return new Promise((resolve) => {
  35. const handleAnimationEvent = requestAnimationFrame(resolve);
  36. animation.addEventListener("cancel", () => handleAnimationEvent, { once: true });
  37. animation.addEventListener("finish", () => handleAnimationEvent, { once: true });
  38. animation.cancel();
  39. });
  40. }));
  41. }
  42. function shimKeyframesHeightAuto(keyframes, calculatedHeight) {
  43. return keyframes.map((keyframe) => Object.assign({}, keyframe, {
  44. height: keyframe.height === "auto" ? `${calculatedHeight}px` : keyframe.height
  45. }));
  46. }
  47. // src/internal/event.ts
  48. function waitForEvent(el, eventName) {
  49. return new Promise((resolve) => {
  50. function done(event) {
  51. if (event.target === el) {
  52. el.removeEventListener(eventName, done);
  53. resolve();
  54. }
  55. }
  56. el.addEventListener(eventName, done);
  57. });
  58. }
  59. export {
  60. animateTo,
  61. parseDuration,
  62. stopAnimations,
  63. shimKeyframesHeightAuto,
  64. waitForEvent
  65. };