@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.
21 lines (20 loc) • 788 B
JavaScript
import { animate as motionAnimate, press, } from 'motion';
import { mapTransitionToMotion } from '../utils.js';
export const handleTap = (element, params) => {
if (params?.whileTap || params?.onTapStart || params?.onTapEnd) {
press(element, (element, startEvent) => {
params.onTapStart?.(startEvent);
let animation;
if (params.whileTap) {
animation = motionAnimate(element, params.whileTap, mapTransitionToMotion(params.whileTap?.transition));
}
return (endEvent) => {
params.onTapEnd?.(endEvent);
if (params.whileTap && animation) {
animation.speed = -1;
animation.play();
}
};
});
}
};