{"version":3,"names":["defineAnimation","getReduceMotionForAnimation","withSequence","_reduceMotionOrFirstAnimation","_len","arguments","length","_animations","Array","_key","reduceMotion","unshift","console","warn","onStart","animation","value","current","onFrame","animationIndex","animations","map","a","result","finished","findNextNonReducedMotionAnimationIndex","index","callback","forEach","sequence","now","currentAnim","nextAnim","previousAnimation","anim","undefined","currentAnimation","isHigherOrder"],"sources":["sequence.ts"],"sourcesContent":["'use strict';\nimport { defineAnimation, getReduceMotionForAnimation } from './util';\nimport type { NextAnimation, SequenceAnimation } from './commonTypes';\nimport type {\n Animation,\n AnimatableValue,\n AnimationObject,\n ReduceMotion,\n Timestamp,\n} from '../commonTypes';\n\n/**\n * Lets you run animations in a sequence.\n *\n * @param reduceMotion - Determines how the animation responds to the device's reduced motion accessibility setting. Default to `ReduceMotion.System` - {@link ReduceMotion}.\n * @param animations - Any number of animation objects to be run in a sequence.\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/withSequence\n */\nexport function withSequence(\n _reduceMotion: ReduceMotion,\n ...animations: T[]\n): T;\n\nexport function withSequence(...animations: T[]): T;\n\nexport function withSequence(\n _reduceMotionOrFirstAnimation?: ReduceMotion | NextAnimation,\n ..._animations: NextAnimation[]\n): Animation {\n 'worklet';\n let reduceMotion: ReduceMotion | undefined;\n\n // the first argument is either a config or an animation\n // this is done to allow the reduce motion config prop to be optional\n if (_reduceMotionOrFirstAnimation) {\n if (typeof _reduceMotionOrFirstAnimation === 'string') {\n reduceMotion = _reduceMotionOrFirstAnimation as ReduceMotion;\n } else {\n _animations.unshift(\n _reduceMotionOrFirstAnimation as NextAnimation\n );\n }\n }\n\n if (_animations.length === 0) {\n console.warn('[Reanimated] No animation was provided for the sequence');\n\n return defineAnimation(0, () => {\n 'worklet';\n return {\n onStart: (animation, value) => (animation.current = value),\n onFrame: () => true,\n current: 0,\n animationIndex: 0,\n reduceMotion: getReduceMotionForAnimation(reduceMotion),\n } as SequenceAnimation;\n });\n }\n\n return defineAnimation(\n _animations[0] as SequenceAnimation,\n () => {\n 'worklet';\n\n const animations = _animations.map((a) => {\n const result = typeof a === 'function' ? a() : a;\n result.finished = false;\n return result;\n });\n\n function findNextNonReducedMotionAnimationIndex(index: number) {\n // the last animation is returned even if reduced motion is enabled,\n // because we want the sequence to finish at the right spot\n while (\n index < animations.length - 1 &&\n animations[index].reduceMotion\n ) {\n index++;\n }\n\n return index;\n }\n\n const callback = (finished: boolean): void => {\n if (finished) {\n // we want to call the callback after every single animation\n // not after all of them\n return;\n }\n // this is going to be called only if sequence has been cancelled\n animations.forEach((animation) => {\n if (typeof animation.callback === 'function' && !animation.finished) {\n animation.callback(finished);\n }\n });\n };\n\n function sequence(animation: SequenceAnimation, now: Timestamp): boolean {\n const currentAnim = animations[animation.animationIndex];\n const finished = currentAnim.onFrame(currentAnim, now);\n animation.current = currentAnim.current;\n if (finished) {\n // we want to call the callback after every single animation\n if (currentAnim.callback) {\n currentAnim.callback(true /* finished */);\n }\n currentAnim.finished = true;\n animation.animationIndex = findNextNonReducedMotionAnimationIndex(\n animation.animationIndex + 1\n );\n if (animation.animationIndex < animations.length) {\n const nextAnim = animations[animation.animationIndex];\n nextAnim.onStart(nextAnim, currentAnim.current, now, currentAnim);\n return false;\n }\n return true;\n }\n return false;\n }\n\n function onStart(\n animation: SequenceAnimation,\n value: AnimatableValue,\n now: Timestamp,\n previousAnimation: SequenceAnimation\n ): void {\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 animations.forEach((anim) => {\n if (anim.reduceMotion === undefined) {\n anim.reduceMotion = animation.reduceMotion;\n }\n });\n animation.animationIndex = findNextNonReducedMotionAnimationIndex(0);\n\n if (previousAnimation === undefined) {\n previousAnimation = animations[\n animations.length - 1\n ] as SequenceAnimation;\n }\n\n const currentAnimation = animations[animation.animationIndex];\n currentAnimation.onStart(\n currentAnimation,\n value,\n now,\n previousAnimation\n );\n }\n\n return {\n isHigherOrder: true,\n onFrame: sequence,\n onStart,\n animationIndex: 0,\n current: animations[0].current,\n callback,\n reduceMotion: getReduceMotionForAnimation(reduceMotion),\n } as SequenceAnimation;\n }\n );\n}\n"],"mappings":"AAAA,YAAY;;AACZ,SAASA,eAAe,EAAEC,2BAA2B,QAAQ,QAAQ;;AAUrE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAQA,OAAO,SAASC,YAAYA,CAC1BC,6BAA6E,EAE/C;EAC9B,SAAS;;EAAC,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAFPC,WAAW,OAAAC,KAAA,CAAAJ,IAAA,OAAAA,IAAA,WAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;IAAXF,WAAW,CAAAE,IAAA,QAAAJ,SAAA,CAAAI,IAAA;EAAA;EAGd,IAAIC,YAAsC;;EAE1C;EACA;EACA,IAAIP,6BAA6B,EAAE;IACjC,IAAI,OAAOA,6BAA6B,KAAK,QAAQ,EAAE;MACrDO,YAAY,GAAGP,6BAA6C;IAC9D,CAAC,MAAM;MACLI,WAAW,CAACI,OAAO,CACjBR,6BAA6B,CAC9B;IACH;EACF;EAEA,IAAII,WAAW,CAACD,MAAM,KAAK,CAAC,EAAE;IAC5BM,OAAO,CAACC,IAAI,CAAC,yDAAyD,CAAC;IAEvE,OAAOb,eAAe,CAAoB,CAAC,EAAE,MAAM;MACjD,SAAS;;MACT,OAAO;QACLc,OAAO,EAAEA,CAACC,SAAS,EAAEC,KAAK,KAAMD,SAAS,CAACE,OAAO,GAAGD,KAAM;QAC1DE,OAAO,EAAEA,CAAA,KAAM,IAAI;QACnBD,OAAO,EAAE,CAAC;QACVE,cAAc,EAAE,CAAC;QACjBT,YAAY,EAAET,2BAA2B,CAACS,YAAY;MACxD,CAAC;IACH,CAAC,CAAC;EACJ;EAEA,OAAOV,eAAe,CACpBO,WAAW,CAAC,CAAC,CAAC,EACd,MAA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