{"version":3,"names":["valueSetter","mutable","value","forceUpdate","arguments","length","undefined","previousAnimation","_animation","cancelled","onFrame","animation","_value","current","isHigherOrder","callback","initializeAnimation","timestamp","onStart","currentTimestamp","global","__frameTimestamp","_getAnimationTimestamp","step","newTimestamp","finished","requestAnimationFrame"],"sources":["valueSetter.ts"],"sourcesContent":["'use strict';\nimport type { AnimationObject, Mutable } from './commonTypes';\n\nexport function valueSetter(\n mutable: Mutable,\n value: Value,\n forceUpdate = false\n): void {\n 'worklet';\n const previousAnimation = mutable._animation;\n if (previousAnimation) {\n previousAnimation.cancelled = true;\n mutable._animation = null;\n }\n if (\n typeof value === 'function' ||\n (value !== null &&\n typeof value === 'object' &&\n // TODO TYPESCRIPT fix this after fixing AnimationObject type\n (value as unknown as AnimationObject).onFrame !== undefined)\n ) {\n const animation: AnimationObject =\n typeof value === 'function'\n ? // TODO TYPESCRIPT fix this after fixing AnimationObject type\n (value as () => AnimationObject)()\n : // TODO TYPESCRIPT fix this after fixing AnimationObject type\n (value as unknown as AnimationObject);\n // prevent setting again to the same value\n // and triggering the mappers that treat this value as an input\n // this happens when the animation's target value(stored in animation.current until animation.onStart is called) is set to the same value as a current one(this._value)\n // built in animations that are not higher order(withTiming, withSpring) hold target value in .current\n if (\n mutable._value === animation.current &&\n !animation.isHigherOrder &&\n !forceUpdate\n ) {\n animation.callback && animation.callback(true);\n return;\n }\n // animated set\n const initializeAnimation = (timestamp: number) => {\n animation.onStart(animation, mutable.value, timestamp, previousAnimation);\n };\n const currentTimestamp =\n global.__frameTimestamp || _getAnimationTimestamp();\n initializeAnimation(currentTimestamp);\n\n const step = (newTimestamp: number) => {\n // Function `requestAnimationFrame` adds callback to an array, all the callbacks are flushed with function `__flushAnimationFrame`\n // Usually we flush them inside function `nativeRequestAnimationFrame` and then the given timestamp is the timestamp of end of the current frame.\n // However function `__flushAnimationFrame` may also be called inside `registerEventHandler` - then we get actual timestamp which is earlier than the end of the frame.\n\n const timestamp =\n newTimestamp < (animation.timestamp || 0)\n ? animation.timestamp\n : newTimestamp;\n\n if (animation.cancelled) {\n animation.callback && animation.callback(false /* finished */);\n return;\n }\n const finished = animation.onFrame(animation, timestamp);\n animation.finished = true;\n animation.timestamp = timestamp;\n // TODO TYPESCRIPT\n // For now I'll assume that `animation.current` is always defined\n // but actually need to dive into animations to understand it\n mutable._value = animation.current!;\n if (finished) {\n animation.callback && animation.callback(true /* finished */);\n } else {\n requestAnimationFrame(step);\n }\n };\n\n mutable._animation = animation;\n\n step(currentTimestamp);\n } else {\n // prevent setting again to the same value\n // and triggering the mappers that treat this value as an input\n if (mutable._value === value && !forceUpdate) {\n return;\n }\n mutable._value = value;\n }\n}\n"],"mappings":"AAAA,YAAY;;AAGZ,OAAO,SAASA,WAAWA,CACzBC,OAAuB,EACvBC,KAAY,EAEN;EACN,SAAS;;EAAC,IAFVC,WAAW,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,KAAK;EAGnB,MAAMG,iBAAiB,GAAGN,OAAO,CAACO,UAAU;EAC5C,IAAID,iBAAiB,EAAE;IACrBA,iBAAiB,CAACE,SAAS,GAAG,IAAI;IAClCR,OAAO,CAACO,UAAU,GAAG,IAAI;EAC3B;EACA,IACE,OAAON,KAAK,KAAK,UAAU,IAC1BA,KAAK,KAAK,IAAI,IACb,OAAOA,KAAK,KAAK,QAAQ;EACzB;EACCA,KAAK,CAAgCQ,OAAO,KAAKJ,SAAU,EAC9D;IACA,MAAMK,SAAiC,GACrC,OAAOT,KAAK,KAAK,UAAU;IACvB;IACCA,KAAK,EAAmC;IACzC;IACCA,KAA2C;IAClD;IACA;IACA;IACA;IACA,IACED,OAAO,CAACW,MAAM,KAAKD,SAAS,CAACE,OAAO,IACpC,CAACF,SAAS,CAACG,aAAa,IACxB,CAACX,WAAW,EACZ;MACAQ,SAAS,CAACI,QAAQ,IAAIJ,SAAS,CAACI,QAAQ,CAAC,IAAI,CAAC;MAC9C;IACF;IACA;IAC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