{"version":3,"file":"follow-value.mjs","sources":["../../../src/value/follow-value.ts"],"sourcesContent":["import { MotionValue, motionValue } from \".\"\nimport { keyframes } from \"../animation/generators/keyframes\"\nimport {\n AnyResolvedKeyframe,\n ValueAnimationTransition,\n} from \"../animation/types\"\nimport { replaceTransitionType } from \"../animation/utils/replace-transition-type\"\nimport { follow, FollowOptions } from \"./utils/follow\"\nimport { isMotionValue } from \"./utils/is-motion-value\"\n\n/**\n * Options for useFollowValue hook, extending ValueAnimationTransition\n * but excluding lifecycle callbacks that don't make sense for the hook pattern,\n * and repeat options, as a follower always heads for its latest value.\n */\nexport type FollowValueOptions = Omit<\n ValueAnimationTransition,\n | \"onUpdate\"\n | \"onComplete\"\n | \"onPlay\"\n | \"onRepeat\"\n | \"onStop\"\n | \"repeat\"\n | \"repeatType\"\n | \"repeatDelay\"\n> & {\n /**\n * When true, the first change from a tracked `MotionValue` source\n * will jump to the new value instead of animating. Subsequent\n * changes animate normally. This prevents unwanted animations\n * on page refresh or back navigation (e.g. `useScroll` + `useSpring`).\n *\n * @default false\n */\n skipInitialAnimation?: boolean\n}\n\n/**\n * Create a `MotionValue` that animates to its latest value using any transition type.\n * Can either be a value or track another `MotionValue`.\n *\n * ```jsx\n * const x = motionValue(0)\n * const y = followValue(x, { type: \"spring\", stiffness: 300 })\n * // or with tween\n * const z = followValue(x, { type: \"tween\", duration: 0.5, ease: \"easeOut\" })\n * ```\n *\n * @param source - Initial value or MotionValue to track\n * @param options - Animation transition options\n * @returns `MotionValue`\n *\n * @public\n */\nexport function followValue(\n source: T | MotionValue,\n options?: FollowValueOptions\n) {\n const initialValue = isMotionValue(source) ? source.get() : source\n const value = motionValue(initialValue)\n\n attachFollow(value, source, options)\n\n return value\n}\n\n/**\n * Attach an animation to a MotionValue that will animate whenever the value changes.\n * Similar to attachSpring but supports any transition type (spring, tween, inertia, etc.)\n *\n * @param value - The MotionValue to animate\n * @param source - Initial value or MotionValue to track\n * @param options - Animation transition options\n * @returns Cleanup function\n *\n * @public\n */\nexport function attachFollow(\n value: MotionValue,\n source: T | MotionValue,\n options: FollowValueOptions = {}\n): VoidFunction {\n // Default to spring if no type specified (matches useSpring behavior)\n const transition: FollowValueOptions = { type: \"spring\", ...options }\n replaceTransitionType(transition)\n transition.type = transition.type || keyframes\n\n return follow(value, source, transition as FollowOptions)\n}\n"],"names":[],"mappings":";;;;;;AAqCA;;;;;;;;;;;;;;;;AAgBG;AACG,SAAU,WAAW,CACvB,MAA0B,EAC1B,OAA4B,EAAA;AAE5B,IAAA,MAAM,YAAY,GAAG,aAAa,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,MAAM;AAClE,IAAA,MAAM,KAAK,GAAG,WAAW,CAAC,YAAY,CAAC;AAEvC,IAAA,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC;AAEpC,IAAA,OAAO,KAAK;AAChB;AAEA;;;;;;;;;;AAUG;AACG,SAAU,YAAY,CACxB,KAAqB,EACrB,MAA0B,EAC1B,UAA8B,EAAE,EAAA;;IAGhC,MAAM,UAAU,GAAuB,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAE;IACrE,qBAAqB,CAAC,UAAU,CAAC;IACjC,UAAU,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,IAAI,SAAS;IAE9C,OAAO,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,UAA2B,CAAC;AAC7D;;;;"}