import extractorInterface from '@typings/extractorInterface' ; import { effectPropertyInterface } from '@typings/propertyObject' ; import { EffectType , UnitTypePixel , PropertyType } from '@typings/valueTypes' ; import { tokenTypes } from '@config/tokenTypes' ; import { roundRgba } from '../utilities/convertColor' ; import { tokenCategoryType } from '@typings/tokenCategory' ; import { tokenExportKeyType } from '@typings/tokenExportKey' ; import config from '@config/config' ; const effectType = { LAYER_BLUR : 'layerBlur' , BACKGROUND_BLUR : 'backgroundBlur' , DROP_SHADOW : 'dropShadow' , INNER_SHADOW : 'innerShadow' } ; const blurValues = ( effect ) => ( { effectType : { value : effectType [ effect . type ] as EffectType , type : 'string' as PropertyType } , radius : { value : effect . radius , unit : 'pixel' as UnitTypePixel , type : 'number' as PropertyType } } ) ; const shadowValues = effect => ( { effectType : { value : effectType [ effect . type ] as EffectType , type : 'string' as PropertyType } , radius : { value : effect . radius , unit : 'pixel' as UnitTypePixel , type : 'number' as PropertyType } , color : { value : roundRgba ( effect . color ) , type : 'color' as PropertyType } , offset : { x : { value : effect . offset . x , unit : 'pixel' as UnitTypePixel , type : 'number' as PropertyType } , y : { value : effect . offset . y , unit : 'pixel' as UnitTypePixel , type : 'number' as PropertyType } } , spread : { value : effect . spread , unit : 'pixel' as UnitTypePixel , type : 'number' as PropertyType } } ) ; const extractEffects = ( tokenNodes , prefixArray ) : effectPropertyInterface [ ] => { return tokenNodes . filter ( node => node . effects . length > 0 ) . map ( node => ( { name : `${ prefixArray [ 0 ] }/${ node . name }` , category : 'effect' as tokenCategoryType , exportKey : tokenTypes . effect . key as tokenExportKeyType , description : node . description || null , values : node . effects . map ( ( effect ) => effect . type === 'LAYER_BLUR' || effect . type === 'BACKGROUND_BLUR' ? blurValues ( effect ) : shadowValues ( effect ) ) , extensions : { [ config . key . extensionPluginData ] : { [ config . key . extensionFigmaStyleId ] : node . id , exportKey : tokenTypes . effect . key as tokenExportKeyType } } } ) ) ; } ; export default extractEffects ;