Skip to main content

expand

Function expand 

Source
pub fn expand<'a>(
    shorthand: &str,
    value: &[ComponentValue<'a>],
) -> Result<Vec<(&'static str, Specified<'a>)>, InvalidValue>
Expand description

Parses a shorthand’s value and splits it into a value for each of its longhands, in the order the spec lists them; a longhand the value leaves out gets its initial value. A longhand that is itself a shorthand (border-width in border) is followed by its own. A longhand gives itself.

use parsec_css::values::expand;

let v = parsec_css::parse_component_values("1px 2px");
let longhands: Vec<String> = expand("margin", &v)
    .unwrap()
    .iter()
    .map(|(name, value)| format!("{name}: {value}"))
    .collect();
assert_eq!(
    longhands,
    ["margin-top: 1px", "margin-right: 2px", "margin-bottom: 1px", "margin-left: 2px"]
);