{"version":3,"names":["defineAnimation","getReduceMotionForAnimation","withRepeat","_nextAnimation","numberOfReps","arguments","length","undefined","reverse","callback","reduceMotion","nextAnimation","repeat","animation","now","finished","onFrame","current","reps","startValue","toValue","onStart","previousAnimation","repCallback","value","isHigherOrder"],"sources":["repeat.ts"],"sourcesContent":["'use strict';\nimport { defineAnimation, getReduceMotionForAnimation } from './util';\nimport type {\n Animation,\n AnimationCallback,\n AnimatableValue,\n Timestamp,\n AnimationObject,\n ReduceMotion,\n} from '../commonTypes';\nimport type { RepeatAnimation } from './commonTypes';\n\n// TODO TYPESCRIPT This is a temporary type to get rid of .d.ts file.\ntype withRepeatType = (\n animation: T,\n numberOfReps?: number,\n reverse?: boolean,\n callback?: AnimationCallback,\n reduceMotion?: ReduceMotion\n) => T;\n\n/**\n * Lets you repeat an animation given number of times or run it indefinitely.\n *\n * @param animation - An animation object you want to repeat.\n * @param numberOfReps - The number of times the animation is going to be repeated. Defaults to 2.\n * @param reverse - Whether the animation should run in reverse every other repetition. Defaults to false.\n * @param callback - A function called on animation complete.\n * @param reduceMotion - Determines how the animation responds to the device's reduced motion accessibility setting. Default to `ReduceMotion.System` - {@link ReduceMotion}.\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/withRepeat\n */\nexport const withRepeat = function (\n _nextAnimation: T | (() => T),\n numberOfReps = 2,\n reverse = false,\n callback?: AnimationCallback,\n reduceMotion?: ReduceMotion\n): Animation {\n 'worklet';\n\n return defineAnimation(\n _nextAnimation,\n (): RepeatAnimation => {\n 'worklet';\n\n const nextAnimation =\n typeof _nextAnimation === 'function'\n ? _nextAnimation()\n : _nextAnimation;\n\n function repeat(animation: RepeatAnimation, now: Timestamp): boolean {\n const finished = nextAnimation.onFrame(nextAnimation, now);\n animation.current = nextAnimation.current;\n if (finished) {\n animation.reps += 1;\n // call inner animation's callback on every repetition\n // as the second argument the animation's current value is passed\n if (nextAnimation.callback) {\n nextAnimation.callback(true /* finished */, animation.current);\n }\n if (\n animation.reduceMotion ||\n (numberOfReps > 0 && animation.reps >= numberOfReps)\n ) {\n return true;\n }\n\n const startValue = reverse\n ? (nextAnimation.current as number)\n : animation.startValue;\n if (reverse) {\n nextAnimation.toValue = animation.startValue;\n animation.startValue = startValue;\n }\n nextAnimation.onStart(\n nextAnimation,\n startValue,\n now,\n nextAnimation.previousAnimation as RepeatAnimation\n );\n return false;\n }\n return false;\n }\n\n const repCallback = (finished?: boolean): void => {\n if (callback) {\n callback(finished);\n }\n // when cancelled call inner animation's callback\n if (!finished && nextAnimation.callback) {\n nextAnimation.callback(false /* finished */);\n }\n };\n\n function onStart(\n animation: RepeatAnimation,\n value: AnimatableValue,\n now: Timestamp,\n previousAnimation: Animation | null\n ): void {\n animation.startValue = value;\n animation.reps = 0;\n\n // child animations inherit the setting, unless they already have it defined\n // they will have it defined only if the user used the `reduceMotion` prop\n if (nextAnimation.reduceMotion === undefined) {\n nextAnimation.reduceMotion = animation.reduceMotion;\n }\n\n // don't start the animation if reduced motion is enabled and\n // the animation would end at its starting point\n if (\n animation.reduceMotion &&\n reverse &&\n (numberOfReps <= 0 || numberOfReps % 2 === 0)\n ) {\n animation.current = animation.startValue;\n animation.onFrame = () => true;\n } else {\n nextAnimation.onStart(nextAnimation, value, now, previousAnimation);\n }\n }\n\n return {\n isHigherOrder: true,\n onFrame: repeat,\n onStart,\n reps: 0,\n current: nextAnimation.current,\n callback: repCallback,\n startValue: 0,\n reduceMotion: getReduceMotionForAnimation(reduceMotion),\n };\n }\n );\n} as withRepeatType;\n"],"mappings":"AAAA,YAAY;;AACZ,SAASA,eAAe,EAAEC,2BAA2B,QAAQ,QAAQ;;AAWrE;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,UAAU,GAAG,SAAAA,CACxBC,cAA6B,EAKD;EAC5B,SAAS;;EAAC,IALVC,YA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