diff --git a/src/web/vaev-style/styles.h b/src/web/vaev-style/styles.h index 9a977a9..34bb570 100644 --- a/src/web/vaev-style/styles.h +++ b/src/web/vaev-style/styles.h @@ -7,6 +7,8 @@ #include "base.h" #include "computed.h" +#include "karm-base/tuple.h" +#include "karm-base/union.h" #include "values.h" // https://www.w3.org/TR/CSS22/propidx.html @@ -824,6 +826,52 @@ struct FlexWrapProp { } }; +// https://www.w3.org/TR/css-flexbox-1/#propdef-flex-flow +// <'flex-direction'> || <'flex-wrap'> +struct FlexFlowProp { + Tuple value = initial(); + + static Tuple initial() { + return { + FlexDirection::ROW, + FlexWrap::NOWRAP, + }; + } + + static constexpr Str name() { return "flex-flow"; } + + void apply(Computed &c) const { + c.flex.cow().direction = value.v0; + c.flex.cow().wrap = value.v1; + } + + Res<> parse(Cursor &c) { + if (c.ended()) + return Error::invalidData("unexpected end of input"); + + + auto direction = parseValue(c); + if (direction) { + value.v0 = direction.unwrap(); + + auto wrap = parseValue(c); + if (wrap) + value.v1 = wrap.unwrap(); + } else { + auto wrap = parseValue(c); + if(not wrap) + return Error::invalidData("expected flex direction or wrap"); + value.v1 = wrap.unwrap(); + + direction = parseValue(c); + if(direction) + value.v0 = direction.unwrap(); + } + + return Ok(); + } +}; + // MARK: Fonts ----------------------------------------------------------------- // https://www.w3.org/TR/css-fonts-4/#font-family-prop @@ -1545,6 +1593,7 @@ using _StyleProp = Union< FlexGrowProp, FlexShrinkProp, FlexWrapProp, + FlexFlowProp, // Font FontFamilyProp,