import { getColorForKey , getFontFamily , getFontWeigth , getBoxShadow , getSizeForKey , getTextAlign , } from './getters' ; import { atomGenerator , capitalize } from './utils' ; import constants from './constants' ; import { Dimensions , TextStyle } from 'react-native' ; const compose = ( transformer = ( v ) => v ) => ( property ) => ( value , key ? ) => atomGenerator ( property , transformer ( value , key ) ) ; const getColorFor = compose ( getColorForKey ) ; const getSizeFor = compose ( getSizeForKey ) ; const getFontWeightFor = compose ( getFontWeigth ) ; const getAlignmentFor = compose ( getTextAlign ) ; const keyAsValue = compose ( ( _ , k ) => k ) ; interface keysWithSides { '' ? : any ; border ? : any ; radius ? : any ; p ? : any ; m ? : any ; } const sides = [ '' , 'top' , 'bottom' , 'left' , 'right' , 'start' , 'end' ] as const ; const getSidesFor = ( property , f , shortPosition = false ) : keysWithSides => sides . reduce ( ( acc , current ) => ( { ... acc , [ property + ( shortPosition ? current [ 0 ] || '' : current ) ] : f ( capitalize ( current ) ) , } ) , { } ) ; const dictionary = { bg : getColorFor ( 'backgroundColor' ) , text : getColorFor ( 'color' ) , font : getSizeFor ( 'fontSize' ) , family : compose ( getFontFamily ) ( 'fontFamily' ) , align : getAlignmentFor ( 'textAlign' ) , alignvertical : getAlignmentFor ( 'textAlignVertical' ) , line : getSizeFor ( 'lineHeight' ) , italic : keyAsValue ( 'fontStyle' ) , uppercase : keyAsValue ( 'textTransform' ) , lowercase : keyAsValue ( 'textTransform' ) , capitalize : keyAsValue ( 'textTransform' ) , bold : keyAsValue ( 'fontWeight' ) , weight : getFontWeightFor ( 'fontWeight' ) , tint : getColorFor ( 'tintColor' ) , ... getSidesFor ( 'border' , position => ( value ) => { return ( isNaN ( Number ( value ) ) && ! constants . sizing [ value ] ? getColorFor ( `border${ position }Color` as 'borderColor' ) : getSizeFor ( `border${ position }Width` as 'borderWidth' ) ) ( value ) ; } ) , radius : getSizeFor ( 'borderRadius' ) , radiustl : getSizeFor ( 'borderTopLeftRadius' ) , radiustr : getSizeFor ( 'borderTopRightRadius' ) , radiusbl : getSizeFor ( 'borderBottomLeftRadius' ) , radiusbr : getSizeFor ( 'borderBottomRightRadius' ) , radiustop : ( value ) => Object . assign ( getSizeFor ( 'borderTopLeftRadius' ) ( value ) , getSizeFor ( 'borderTopRightRadius' ) ( value ) ) , radiusbottom : ( value ) => Object . assign ( getSizeFor ( `borderBottomLeftRadius` as 'borderRadius' ) ( value ) , getSizeFor ( `borderBottomRightRadius` as 'borderRadius' ) ( value ) ) , radiusleft : ( value ) => Object . assign ( getSizeFor ( `borderTopLeftRadius` as 'borderRadius' ) ( value ) , getSizeFor ( `borderBottomLeftRadius` as 'borderRadius' ) ( value ) ) , radiusright : ( value ) => Object . assign ( getSizeFor ( `borderTopRightRadius` as 'borderRadius' ) ( value ) , getSizeFor ( `borderBottomRightRadius` as 'borderRadius' ) ( value ) ) , radiusstart : ( value ) => Object . assign ( getSizeFor ( `borderTopStartRadius` as 'borderRadius' ) ( value ) , getSizeFor ( `borderBottomStartRadius` as 'borderRadius' ) ( value ) ) , radiusend : ( value ) => Object . assign ( getSizeFor ( `borderTopEndRadius` as 'borderRadius' ) ( value ) , getSizeFor ( `borderBottomEndRadius` as 'borderRadius' ) ( value ) ) , h : getSizeFor ( 'height' ) , hscreen : compose ( ( ) => Dimensions . get ( 'window' ) . height ) ( 'height' ) , maxh : getSizeFor ( 'maxHeight' ) , minh : getSizeFor ( 'minHeight' ) , w : getSizeFor ( 'width' ) , wscreen : compose ( ( ) => Dimensions . get ( 'window' ) . width ) ( 'width' ) , maxw : getSizeFor ( 'maxWidth' ) , minw : getSizeFor ( 'minWidth' ) , ... getSidesFor ( 'p' , position => getSizeFor ( `padding${ position }` as 'padding' ) , true ) , py : getSizeFor ( 'paddingVertical' ) , px : getSizeFor ( 'paddingHorizontal' ) , ... getSidesFor ( 'm' , position => getSizeFor ( `margin${ position }` as 'margin' ) , true ) , my : getSizeFor ( 'marginVertical' ) , mx : getSizeFor ( 'marginHorizontal' ) , absolute : keyAsValue ( 'position' ) , ltr : keyAsValue ( 'direction' ) , rtl : keyAsValue ( 'direction' ) , ... getSidesFor ( '' , position => getSizeFor ( position . toLowerCase ( ) as typeof sides [ 1 ] ) ) , overflow : compose ( ) ( 'overflow' ) , flex : compose ( ( value ) => Number ( value || 1 ) ) ( 'flex' ) , row : keyAsValue ( 'flexDirection' ) , wrap : keyAsValue ( 'flexWrap' ) , justify : getAlignmentFor ( 'justifyContent' ) , items : getAlignmentFor ( 'alignItems' ) , self : getAlignmentFor ( 'alignSelf' ) , content : getAlignmentFor ( 'alignContent' ) , elevation : compose ( ( value ) => Number ( value ) ) ( 'elevation' ) , opacity : compose ( ( value ) => Number ( value ) / 100 ) ( 'opacity' ) , shadow : getBoxShadow , } ; export type DictionaryKeys = keyof typeof dictionary ; export default dictionary ;