{"version":3,"names":["Animations","AnimationsData","TransitionType","convertAnimationObjectToKeyframes","LinearTransition","SequencedTransition","FadingTransition","insertWebAnimation","addPxToTranslate","existingTransform","newTransform","map","transformProp","newTransformProp","key","value","Object","entries","includes","addExistingTransform","newAnimationData","keyframeStepProperties","values","style","transform","Array","prototype","unshift","apply","createAnimationWithExistingTransform","animationName","layoutTransition","structuredClone","keyframeName","generateNextCustomKeyframeName","name","keyframe","customKeyframeCounter","TransitionGenerator","transitionType","transitionData","transitionKeyframeName","transitionObject","LINEAR","SEQUENCED","FADING","transitionKeyframe"],"sources":["createAnimation.ts"],"sourcesContent":["'use strict';\n\nimport { Animations, AnimationsData, TransitionType } from './config';\nimport { convertAnimationObjectToKeyframes } from './animationParser';\nimport type {\n AnimationData,\n ReanimatedWebTransformProperties,\n TransitionData,\n} from './animationParser';\nimport type { TransformsStyle } from 'react-native';\nimport { LinearTransition } from './transition/Linear.web';\nimport { SequencedTransition } from './transition/Sequenced.web';\nimport { FadingTransition } from './transition/Fading.web';\nimport { insertWebAnimation } from './domUtils';\n\n// Translate values are passed as numbers. However, if `translate` property receives number, it will not automatically\n// convert it to `px`. Therefore if we want to keep exisitng transform we have to add 'px' suffix to each of translate values\n// that are present inside transform.\nfunction addPxToTranslate(\n existingTransform: NonNullable\n) {\n type RNTransformProp = (typeof existingTransform)[number];\n\n // @ts-ignore `existingTransform` cannot be string because in that case\n // we throw error in `extractTransformFromStyle`\n const newTransform = existingTransform.map(\n (transformProp: RNTransformProp) => {\n const newTransformProp: ReanimatedWebTransformProperties = {};\n for (const [key, value] of Object.entries(transformProp)) {\n if (key.includes('translate')) {\n // @ts-ignore After many trials we decided to ignore this error - it says that we cannot use 'key' to index this object.\n // Sadly it doesn't go away after using cast `key as keyof TransformProperties`.\n newTransformProp[key] = `${value}px`;\n } else {\n // @ts-ignore same as above.\n newTransformProp[key] = value;\n }\n }\n return newTransformProp;\n }\n );\n\n return newTransform;\n}\n\n// In order to keep exisitng transform throughout animation, we have to add it to each of keyframe step.\nfunction addExistingTransform(\n newAnimationData: AnimationData,\n newTransform: ReanimatedWebTransformProperties[]\n) {\n for (const keyframeStepProperties of Object.values(newAnimationData.style)) {\n if (!keyframeStepProperties.transform) {\n // If transform doesn't exist, we add only transform that already exists\n keyframeStepProperties.transform = newTransform;\n } else {\n // We insert existing transformations before ours.\n Array.prototype.unshift.apply(\n keyframeStepProperties.transform,\n newTransform\n );\n }\n }\n}\n\n/**\n * Modifies default animation by preserving transformations that given element already contains.\n *\n * @param animationName - Name of the animation to be modified (e.g. `FadeIn`).\n * @param existingTransform - Transform values that element already contains.\n * @returns Animation parsed to keyframe string.\n */\nexport function createAnimationWithExistingTransform(\n animationName: string,\n existingTransform: NonNullable,\n layoutTransition?: AnimationData\n) {\n let newAnimationData;\n\n if (layoutTransition) {\n newAnimationData = layoutTransition;\n } else {\n if (!(animationName in Animations)) {\n return '';\n }\n newAnimationData = structuredClone(AnimationsData[animationName]);\n }\n\n const keyframeName = generateNextCustomKeyframeName();\n\n newAnimationData.name = keyframeName;\n\n const newTransform = addPxToTranslate(existingTransform);\n\n addExistingTransform(newAnimationData, newTransform);\n\n const keyframe = convertAnimationObjectToKeyframes(newAnimationData);\n\n insertWebAnimation(keyframeName, keyframe);\n\n return keyframeName;\n}\n\nlet customKeyframeCounter = 0;\n\nfunction generateNextCustomKeyframeName() {\n return `REA${customKeyframeCounter++}`;\n}\n\n/**\n * Creates transition of given type, appends it to stylesheet and returns keyframe name.\n *\n * @param transitionType - Type of transition (e.g. LINEAR).\n * @param transitionData - Object containing data for transforms (translateX, scaleX,...).\n * @returns Keyframe name that represents transition.\n */\nexport function TransitionGenerator(\n transitionType: TransitionType,\n transitionData: TransitionData,\n existingTransform: TransformsStyle['transform'] | undefined\n) {\n const transitionKeyframeName = generateNextCustomKeyframeName();\n let transitionObject;\n\n switch (transitionType) {\n case TransitionType.LINEAR:\n transitionObject = LinearTransition(\n transitionKeyframeName,\n transitionData\n );\n break;\n case TransitionType.SEQUENCED:\n transitionObject = SequencedTransition(\n transitionKeyframeName,\n transitionData\n );\n break;\n case TransitionType.FADING:\n transitionObject = FadingTransition(\n transitionKeyframeName,\n transitionData\n );\n break;\n }\n\n if (existingTransform) {\n return createAnimationWithExistingTransform(\n '',\n existingTransform,\n transitionObject\n );\n }\n\n const transitionKeyframe =\n convertAnimationObjectToKeyframes(transitionObject);\n\n insertWebAnimation(transitionKeyframeName, transitionKeyframe);\n\n return transitionKeyframeName;\n}\n"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,UAAU,EAAEC,cAAc,EAAEC,cAAc,QAAQ,UAAU;AACrE,SAASC,iCAAiC,QAAQ,mBAAmB;AAOrE,SAASC,gBAAgB,QAAQ,yBAAyB;AAC1D,SAASC,mBAAmB,QAAQ,4BAA4B;AAChE,SAASC,gBAAgB,QAAQ,yBAAyB;AAC1D,SAASC,kBAAkB,QAAQ,YAAY;;AAE/C;AACA;AACA;AACA,SAASC,gBAAgBA,CACvBC,iBAA4D,EAC5D;EAGA;EACA;EACA,MAAMC,YAAY,GAAGD,iBAAiB,CAACE,GAAG,CACvCC,aAA8B,IAAK;IAClC,MAAMC,gBAAkD,GAAG,CAAC,CAAC;IAC7D,KAAK,MAAM,CAACC,GAAG,EAAEC,KAAK,CAAC,IAAIC,MAAM,CAACC,OAAO,CAACL,aAAa,CAAC,EAAE;MACxD,IAAIE,GAAG,CAACI,QAAQ,CAAC,WAAW,CAAC,EAAE;QAC7B;QACA;QACAL,gBAAgB,CAACC,GAAG,CAAC,GAAI,GAAEC,KAAM,IAAG;MACtC,CAAC,MAAM;QACL;QACAF,gBAAgB,CAACC,GAAG,CAAC,GAAGC,KAAK;MAC/B;IACF;IACA,OAAOF,gBAAgB;EACzB,CAAC,CACF;EAED,OAAOH,YAAY;AACrB;;AAEA;AACA,SAASS,oBAAoBA,CAC3BC,gBAA+B,EAC/BV,YAAgD,EAChD;EACA,KAAK,MAAMW,sBAAsB,IAAIL,MAAM,CAACM,MAAM,CAACF,gBA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