import * as propParser from "css-property-parser" ; import { isResolution } from "../BlockSyntax" ; const BORDER_SHORTHANDS = new Set ( [ "border-top" , "border-bottom" , "border-left" , "border-right" ] ) ; param property param value export function expandProp ( prop , value ) { let expanded = { } ; if ( prop === "font-family" ) { expanded [ prop ] = value ; return expanded ; } if ( isResolution ( value ) ) { value = "inherit" ; } value = value . replace ( /var\([^\)]+\)/gi , "inherit" ) ; let borderProp = null ; if ( BORDER_SHORTHANDS . has ( prop ) ) { borderProp = prop ; prop = "border" ; } if ( propParser . isValidDeclaration ( prop , value ) ) { expanded = propParser . expandShorthandProperty ( prop , value , true , false ) ; } expanded [ prop ] = value ; if ( borderProp ) { expanded [ borderProp ] = value ; delete expanded [ "border" ] ; delete expanded [ "border-color" ] ; delete expanded [ "border-style" ] ; delete expanded [ "border-width" ] ; for ( let bprop of BORDER_SHORTHANDS ) { if ( bprop === borderProp ) { continue ; } delete expanded [ `${ bprop }-color` ] ; delete expanded [ `${ bprop }-style` ] ; delete expanded [ `${ bprop }-width` ] ; } } else if ( prop === "border" ) { expanded [ "border-top" ] = value ; expanded [ "border-left" ] = value ; expanded [ "border-bottom" ] = value ; expanded [ "border-right" ] = value ; } return expanded ; }