UNPKG

@omicrxn/mercury

Version:

Mercury is a Svelte animation library using AnimeJS under the hood. It simplifies complex animations with Svelte actions, provides layout and exit animations, and integrates seamlessly with Svelte features.

27 lines (26 loc) 1.08 kB
import { animate as motionAnimate } from 'motion'; import { mapTransitionToMotion } from '../utils.js'; export const MotionEngine = { animate(element, params) { const { animate: mercuryAnimation, transition: mercuryTransition, callbacks } = params; //Mapping animation to motion const animationOptions = mercuryAnimation; //Mapping transition to motion const transitionOptions = mapTransitionToMotion(mercuryTransition, callbacks); const animation = motionAnimate(element, animationOptions, transitionOptions); const instance = { completed: false, play: () => animation.play(), pause: () => animation.pause(), cancel: () => animation.cancel(), onComplete: (onResolve, onReject) => { return animation.then(() => { onResolve(); // Update the completed flag on THIS instance instance.completed = true; }, onReject); } }; return instance; } };