import { Token, TokenGroup } from "../../../types/Token"; import { isMeasurement, getMeasurementType, getMeasurementValue, getMeasurements } from '../properties'; import { StyleMarginRule } from "../../../types/style/StyleMarginRule"; import { StylePropertyType } from "../../../types/style/StylePropertyType"; export function parseMargin( tokens: Token[] ): StyleMarginRule | null { const subProperties = tokens.filter( x => x.group === TokenGroup.CSS && x.section === 'subProperty' ).map( x => x.key ); const measurements = getMeasurements( tokens ); if( measurements.length === 0 ) return null; return { type: StylePropertyType.Margin, leftAmount: subProperties.includes( 'left' ) ? measurements[0] : undefined, rightAmount: subProperties.includes( 'right' ) ? measurements[0] : undefined, topAmount: subProperties.includes( 'top' ) ? measurements[0] : undefined, bottomAmount: subProperties.includes( 'bottom' ) ? measurements[0] : undefined, amount: subProperties.length === 0 ? measurements[0] : undefined } }