motion-v
Version:
<h1 align="center"> <img width="35" height="35" alt="Motion logo" src="https://github.com/user-attachments/assets/00d6d1c3-72c4-4c2f-a664-69da13182ffc" /><br />Motion for Vue</h1>
29 lines (28 loc) • 872 B
JavaScript
import { isMotionValue, motionValue } from "framer-motion/dom";
import { attachFollow } from "motion-dom";
import { toValue, watch } from "vue";
function useFollowValue(source, options = {}) {
const value = motionValue(isMotionValue(source) ? source.get() : source);
let cleanup;
watch(() => toValue(options), (_1, _2, onCleanup) => {
cleanup = attachFollow(value, source, toValue(options));
onCleanup(() => {
cleanup?.();
});
}, { immediate: true });
return value;
}
function useSpring(source, config = {}) {
const value = motionValue(isMotionValue(source) ? source.get() : source);
watch(() => toValue(config), (_1, _2, onCleanup) => {
const cleanup = attachFollow(value, source, {
type: "spring",
...toValue(config)
});
onCleanup(() => {
cleanup?.();
});
}, { immediate: true });
return value;
}
export { useFollowValue, useSpring };