{"version":3,"names":["Easing","defineAnimation","getReduceMotionForAnimation","withTiming","toValue","userConfig","callback","config","duration","easing","inOut","quad","Object","keys","forEach","key","timing","animation","now","startTime","startValue","runtime","current","progress","onStart","value","previousAnimation","type","factory","onFrame","reduceMotion"],"sources":["timing.ts"],"sourcesContent":["'use strict';\nimport type { EasingFunction, EasingFunctionFactory } from '../Easing';\nimport { Easing } from '../Easing';\nimport { defineAnimation, getReduceMotionForAnimation } from './util';\nimport type {\n Animation,\n AnimationCallback,\n Timestamp,\n AnimatableValue,\n ReduceMotion,\n} from '../commonTypes';\n\n/**\n * The timing animation configuration.\n *\n * @param duration - Length of the animation (in milliseconds). Defaults to 300.\n * @param easing - An easing function which defines the animation curve. Defaults to `Easing.inOut(Easing.quad)`.\n * @param reduceMotion - Determines how the animation responds to the device's reduced motion accessibility setting. Default to `ReduceMotion.System` - {@link ReduceMotion}.\n * @see https://docs.swmansion.com/react-native-reanimated/docs/animations/withTiming#config-\n */\ninterface TimingConfig {\n duration?: number;\n reduceMotion?: ReduceMotion;\n easing?: EasingFunction | EasingFunctionFactory;\n}\n\nexport type WithTimingConfig = TimingConfig;\n\nexport interface TimingAnimation extends Animation {\n type: string;\n easing: EasingFunction;\n startValue: AnimatableValue;\n startTime: Timestamp;\n progress: number;\n toValue: AnimatableValue;\n current: AnimatableValue;\n}\n\ninterface InnerTimingAnimation\n extends Omit {\n toValue: number;\n current: number;\n}\n\n// TODO TYPESCRIPT This is temporary type put in here to get rid of our .d.ts file\ntype withTimingType = (\n toValue: T,\n userConfig?: TimingConfig,\n callback?: AnimationCallback\n) => T;\n\n/**\n * Lets you create an animation based on duration and easing.\n *\n * @param toValue - The value on which the animation will come at rest - {@link AnimatableValue}.\n * @param config - The timing animation configuration - {@link TimingConfig}.\n * @param callback - A function called on animation complete - {@link AnimationCallback}.\n * @returns An [animation object](https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/glossary#animation-object) which holds the current state of the animation.\n * @see https://docs.swmansion.com/react-native-reanimated/docs/animations/withTiming\n */\nexport const withTiming = function (\n toValue: AnimatableValue,\n userConfig?: TimingConfig,\n callback?: AnimationCallback\n): Animation {\n 'worklet';\n\n return defineAnimation(toValue, () => {\n 'worklet';\n const config: Required> = {\n duration: 300,\n easing: Easing.inOut(Easing.quad),\n };\n if (userConfig) {\n Object.keys(userConfig).forEach(\n (key) =>\n ((config as any)[key] = userConfig[key as keyof typeof userConfig])\n );\n }\n\n function timing(animation: InnerTimingAnimation, now: Timestamp): boolean {\n // eslint-disable-next-line @typescript-eslint/no-shadow\n const { toValue, startTime, startValue } = animation;\n const runtime = now - startTime;\n\n if (runtime >= config.duration) {\n // reset startTime to avoid reusing finished animation config in `start` method\n animation.startTime = 0;\n animation.current = toValue;\n return true;\n }\n const progress = animation.easing(runtime / config.duration);\n animation.current =\n (startValue as number) + (toValue - (startValue as number)) * progress;\n return false;\n }\n\n function onStart(\n animation: TimingAnimation,\n value: number,\n now: Timestamp,\n previousAnimation: Animation\n ): void {\n if (\n previousAnimation &&\n (previousAnimation as TimingAnimation).type === 'timing' &&\n (previousAnimation as TimingAnimation).toValue === toValue &&\n (previousAnimation as TimingAnimation).startTime\n ) {\n // to maintain continuity of timing animations we check if we are starting\n // new timing over the old one with the same parameters. If so, we want\n // to copy animation timeline properties\n animation.startTime = (previousAnimation as TimingAnimation).startTime;\n animation.startValue = (\n previousAnimation as TimingAnimation\n ).startValue;\n } else {\n animation.startTime = now;\n animation.startValue = value;\n }\n animation.current = value;\n if (typeof config.easing === 'object') {\n animation.easing = config.easing.factory();\n } else {\n animation.easing = config.easing;\n }\n }\n\n return {\n type: 'timing',\n onFrame: timing,\n onStart: onStart as (animation: TimingAnimation, now: number) => boolean,\n progress: 0,\n toValue,\n startValue: 0,\n startTime: 0,\n easing: () => 0,\n current: toValue,\n callback,\n reduceMotion: getReduceMotionForAnimation(userConfig?.reduceMotion),\n } as TimingAnimation;\n });\n} as withTimingType;\n"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,MA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