import { attachFollow, isMotionValue, motionValue } from "motion-dom"; import { toValue, watch } from "vue"; //#region src/value/use-spring.ts 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; } //#endregion export { useFollowValue, useSpring };