@omicrxn/mercury
Version:
Mercury is a Svelte animation library powered by Motion. It simplifies complex animations with Svelte actions, provides layout and exit animations, and integrates seamlessly with Svelte features.
22 lines (21 loc) • 842 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) {
return press(element, (element, startEvent) => {
params.onTapStart?.(startEvent);
let animation;
if (params.whileTap) {
const { transition, ...keyframes } = params.whileTap;
animation = motionAnimate(element, keyframes, mapTransitionToMotion(transition));
}
return (endEvent) => {
params.onTapEnd?.(endEvent);
if (params.whileTap && animation) {
animation.speed = -1;
animation.play();
}
};
});
}
};