UNPKG

9.76 kBSource Map (JSON)View Raw
1{"version":3,"names":["_tools","require","_react","_react2","_interopRequireWildcard","_createMotionComponent","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","_extends","assign","target","i","arguments","length","source","apply","LinearGradient","setLinearGradientComponent","linearGradient","GradientHelper","Component","render","numColors","startX","startY","endX","endY","rest","props","start","undefined","x","y","end","colors","push","createElement","AnimatedGradientHelper","createMotionAnimatedComponent","pointToXY","point","name","isArray","MotionLinearGradient","MemoFnComponent","animateProps","initialProps","propsOut","colorsAnimate","startAnimate","endAnimate","animatePropsOut","forEach","color","initialPropsOut","colorsInitial","startInitial","endInitial","exports"],"sources":["LinearGradient.tsx"],"sourcesContent":["import { isArray } from '@legendapp/tools';\nimport { MemoFnComponent } from '@legendapp/tools/react';\nimport React, { Component, ComponentClass } from 'react';\nimport type { ViewProps, ViewStyle } from 'react-native';\nimport { createMotionAnimatedComponent } from './createMotionComponent';\nimport type { MotionComponentProps } from './Interfaces';\n\nexport type LinearGradientPoint = {\n x: number;\n y: number;\n};\n\nexport type LinearGradientProps = ViewProps & {\n colors?: string[];\n locations?: number[] | null;\n start?: LinearGradientPoint | null;\n end?: LinearGradientPoint | null;\n};\n\nlet LinearGradient;\n\nfunction setLinearGradientComponent(linearGradient) {\n LinearGradient = linearGradient;\n}\n\ntype PropsGradient = Omit<LinearGradientProps, 'colors'> & {\n numColors?: number;\n startX?: number;\n startY?: number;\n endX?: number;\n endY?: number;\n};\n\nclass GradientHelper extends Component<PropsGradient> {\n render() {\n const { numColors, startX, startY, endX, endY, ...rest } = this.props;\n\n // Combine startX, startY, endX, endY back into start,end\n let start;\n if (startX !== undefined || startY !== undefined) {\n start = {\n x: startX,\n y: startY,\n };\n }\n let end;\n if (endX !== undefined || endY !== undefined) {\n end = {\n x: endX,\n y: endY,\n };\n }\n\n // Combine individual color props back into a colors array\n const colors: string[] = [];\n for (let i = 0; i < numColors; i++) {\n colors.push(rest['color' + i]);\n delete rest['color' + i];\n }\n\n return <LinearGradient colors={colors} start={start} end={end} {...rest} />;\n }\n}\n\nconst AnimatedGradientHelper = createMotionAnimatedComponent(GradientHelper);\n\nfunction pointToXY(props: PropsGradient, point: LinearGradientPoint, name: string) {\n if (point) {\n props[name + 'X'] = isArray(point) ? point[0] : point.x;\n props[name + 'Y'] = isArray(point) ? point[1] : point.y;\n }\n}\n\n// Create MotionLinearGradient with the same API as other Motion components, but it's more complicated because it needs to\n// transform to a different set of props into the AnimatedGradientHelper.\nconst MotionLinearGradient = MemoFnComponent(function <\n TAnimate,\n TAnimateProps extends Partial<Omit<LinearGradientProps, 'locations' | 'style'>>\n>(\n props: MotionComponentProps<\n ComponentClass<Omit<LinearGradientProps, 'locations'>>,\n ViewStyle,\n TAnimate,\n TAnimateProps,\n Omit<LinearGradientProps, 'locations' | 'style'>\n > &\n LinearGradientProps\n) {\n const { colors, animateProps, start, end, initialProps, ...propsOut } = props;\n const { colors: colorsAnimate, start: startAnimate, end: endAnimate, ...animatePropsOut } = animateProps as LinearGradientProps;\n\n // Split colors array out into individual props so they can be animated\n colors?.forEach((color, i) => (propsOut['color' + i] = color));\n colorsAnimate?.forEach((color, i) => (animatePropsOut['color' + i] = color));\n\n // Split start/end objects out into individual props so they can be animated\n pointToXY(propsOut, start, 'start');\n pointToXY(propsOut, end, 'end');\n\n pointToXY(animatePropsOut, startAnimate, 'start');\n pointToXY(animatePropsOut, endAnimate, 'end');\n\n let numColors = colors?.length || colorsAnimate?.length || 0;\n\n // Split initialProps too if it exists\n const initialPropsOut: Partial<LinearGradientProps> = {};\n if (initialProps) {\n const { colors: colorsInitial, start: startInitial, end: endInitial } = animateProps as LinearGradientProps;\n colorsInitial?.forEach((color, i) => (initialPropsOut['color' + i] = color));\n pointToXY(initialPropsOut, startInitial, 'start');\n pointToXY(initialPropsOut, endInitial, 'end');\n\n if (colorsInitial) {\n numColors = colorsInitial.length;\n }\n }\n\n // @ts-ignore Ignore this because it won't conform to the customized props\n return <AnimatedGradientHelper numColors={numColors} {...propsOut} initialProps={initialPropsOut} animateProps={animatePropsOut} />;\n});\n\nexport { setLinearGradientComponent, MotionLinearGradient };\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAC,uBAAA,CAAAH,OAAA;AAEA,IAAAI,sBAAA,GAAAJ,OAAA;AAAwE,SAAAK,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAH,wBAAAO,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GAAA,KAAAR,MAAA,CAAAC,cAA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