import extractorInterface from '@typings/extractorInterface' ; import { gridPropertyInterface } from '@typings/propertyObject' ; import { GridAlignment , GridPattern , PropertyType , UnitTypePixel } from '@typings/valueTypes' ; import { tokenTypes } from '@config/tokenTypes' ; import { tokenCategoryType } from '@typings/tokenCategory' ; import { tokenExportKeyType } from '@typings/tokenExportKey' ; import config from '@config/config' ; const gridValues = ( grid ) => ( { pattern : { value : grid . pattern . toLowerCase ( ) as GridPattern , type : 'string' as PropertyType } , sectionSize : { value : grid . sectionSize , unit : 'pixel' as UnitTypePixel , type : 'number' as PropertyType } } ) ; const getCount = count => { if ( count === Infinity ) { return { value : 'auto' , type : 'string' as PropertyType } ; } return { value : count , type : 'number' as PropertyType } ; } ; const rowColumnValues = ( grid ) => ( { pattern : { value : grid . pattern . toLowerCase ( ) as GridPattern , type : 'string' as PropertyType } , ... ( grid . sectionSize !== undefined && { sectionSize : { value : grid . sectionSize , unit : 'pixel' as UnitTypePixel , type : 'number' as PropertyType } } ) , gutterSize : { value : grid . gutterSize , unit : 'pixel' as UnitTypePixel , type : 'number' as PropertyType } , alignment : { value : grid . alignment . toLowerCase ( ) as GridAlignment , type : 'string' as PropertyType } , count : getCount ( grid . count ) , ... ( grid . offset !== undefined && { offset : { value : grid . offset , unit : 'pixel' as UnitTypePixel , type : 'number' as PropertyType } } ) } ) ; const extractGrids = ( tokenNodes , prefixArray ) : gridPropertyInterface [ ] => { return tokenNodes . filter ( node => node . layoutGrids . length > 0 ) . map ( node => ( { name : `${ prefixArray [ 0 ] }/${ node . name }` , category : 'grid' as tokenCategoryType , exportKey : tokenTypes . grid . key as tokenExportKeyType , description : node . description || null , values : node . layoutGrids . map ( ( grid ) => grid . pattern === 'GRID' ? gridValues ( grid ) : rowColumnValues ( grid ) ) , extensions : { [ config . key . extensionPluginData ] : { [ config . key . extensionFigmaStyleId ] : node . id , exportKey : tokenTypes . grid . key as tokenExportKeyType } } } ) ) ; } ; export default extractGrids ;