{-# LANGUAGE OverloadedStrings #-}
module Graphics.Layout.Flex.CSS(CSSFlex(..), lowerFlex) where
import Data.CSS.Syntax.Tokens (Token(..), NumericValue(..))
import Stylist (PropertyParser(..), TrivialPropertyParser, parseOperands,
parseUnorderedShorthand', parseUnorderedShorthand)
import Graphics.Layout.Flex as F
import Graphics.Layout.CSS.Length (parseLength, finalizeLength, n2f, Unitted, Font')
import Graphics.Layout.Box (Length)
import Data.Maybe (isJust)
data CSSFlex = CSSFlex {
CSSFlex -> Direction
directionCSS :: Direction,
CSSFlex -> Bool
reverseRowsCSS :: Bool,
CSSFlex -> FlexWrapping
wrapCSS :: FlexWrapping,
CSSFlex -> Maybe Justification
justifyCSS :: Maybe Justification,
CSSFlex -> Alignment
alignItemsCSS :: Alignment,
CSSFlex -> Maybe Justification
alignLinesCSS :: Maybe Justification,
CSSFlex -> Unitted
rowGapCSS :: Unitted,
CSSFlex -> Unitted
columnGapCSS :: Unitted,
CSSFlex -> Integer
orderCSS :: Integer,
CSSFlex -> Double
growCSS :: Double,
CSSFlex -> Double
shrinkCSS :: Double,
CSSFlex -> Unitted
basisCSS :: Unitted,
CSSFlex -> Alignment
alignSelfCSS :: Alignment,
CSSFlex -> Bool
textRTL :: Bool
}
setDir :: CSSFlex -> Direction -> Bool -> Maybe CSSFlex
setDir CSSFlex
self Direction
dir Bool
rev = CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { directionCSS :: Direction
directionCSS = Direction
dir, reverseRowsCSS :: Bool
reverseRowsCSS = Bool
rev }
parseJustify :: CSSFlex -> a -> Maybe Justification
parseJustify CSSFlex
self a
"flex-start" | CSSFlex -> Bool
reverseRowsCSS CSSFlex
self = Justification -> Maybe Justification
forall a. a -> Maybe a
Just Justification
JEnd
| Bool
otherwise = Justification -> Maybe Justification
forall a. a -> Maybe a
Just Justification
JStart
parseJustify CSSFlex
self a
"flex-end" | CSSFlex -> Bool
reverseRowsCSS CSSFlex
self = Justification -> Maybe Justification
forall a. a -> Maybe a
Just Justification
JStart
| Bool
otherwise = Justification -> Maybe Justification
forall a. a -> Maybe a
Just Justification
JEnd
parseJustify CSSFlex
self a
"start" | CSSFlex -> Bool
textRTL CSSFlex
self = Justification -> Maybe Justification
forall a. a -> Maybe a
Just Justification
JEnd
| Bool
otherwise = Justification -> Maybe Justification
forall a. a -> Maybe a
Just Justification
JStart
parseJustify CSSFlex
self a
"end" | CSSFlex -> Bool
textRTL CSSFlex
self = Justification -> Maybe Justification
forall a. a -> Maybe a
Just Justification
JStart
| Bool
otherwise = Justification -> Maybe Justification
forall a. a -> Maybe a
Just Justification
JEnd
parseJustify CSSFlex
_ a
"left" = Justification -> Maybe Justification
forall a. a -> Maybe a
Just Justification
JStart
parseJustify CSSFlex
_ a
"right" = Justification -> Maybe Justification
forall a. a -> Maybe a
Just Justification
JEnd
parseJustify CSSFlex
_ a
"center" = Justification -> Maybe Justification
forall a. a -> Maybe a
Just Justification
JCenter
parseJustify CSSFlex
_ a
"space-between" = Justification -> Maybe Justification
forall a. a -> Maybe a
Just Justification
JSpaceBetween
parseJustify CSSFlex
_ a
"space-around" = Justification -> Maybe Justification
forall a. a -> Maybe a
Just Justification
JSpaceAround
parseJustify CSSFlex
_ a
"space-evenly" = Justification -> Maybe Justification
forall a. a -> Maybe a
Just Justification
JSpaceEvenly
parseJustify CSSFlex
_ a
_ = Maybe Justification
forall a. Maybe a
Nothing
parseAlign :: CSSFlex -> a -> Maybe Alignment
parseAlign CSSFlex
_ a
"stretch" = Alignment -> Maybe Alignment
forall a. a -> Maybe a
Just Alignment
AlStretch
parseAlign CSSFlex
self a
"flex-start" | CSSFlex -> Bool
reverseRowsCSS CSSFlex
self = Alignment -> Maybe Alignment
forall a. a -> Maybe a
Just Alignment
AlEnd
| Bool
otherwise = Alignment -> Maybe Alignment
forall a. a -> Maybe a
Just Alignment
AlStart
parseAlign CSSFlex
_ a
"start" = Alignment -> Maybe Alignment
forall a. a -> Maybe a
Just Alignment
AlStart
parseAlign CSSFlex
self a
"self-start" | CSSFlex -> Bool
textRTL CSSFlex
self = Alignment -> Maybe Alignment
forall a. a -> Maybe a
Just Alignment
AlEnd
| Bool
otherwise = Alignment -> Maybe Alignment
forall a. a -> Maybe a
Just Alignment
AlStart
parseAlign CSSFlex
self a
"flex-end" | CSSFlex -> Bool
reverseRowsCSS CSSFlex
self = Alignment -> Maybe Alignment
forall a. a -> Maybe a
Just Alignment
AlStart
| Bool
otherwise = Alignment -> Maybe Alignment
forall a. a -> Maybe a
Just Alignment
AlEnd
parseAlign CSSFlex
_ a
"end" = Alignment -> Maybe Alignment
forall a. a -> Maybe a
Just Alignment
AlEnd
parseAlign CSSFlex
self a
"self-end" | CSSFlex -> Bool
textRTL CSSFlex
self = Alignment -> Maybe Alignment
forall a. a -> Maybe a
Just Alignment
AlStart
| Bool
otherwise = Alignment -> Maybe Alignment
forall a. a -> Maybe a
Just Alignment
AlEnd
parseAlign CSSFlex
_ a
"center" = Alignment -> Maybe Alignment
forall a. a -> Maybe a
Just Alignment
AlCenter
parseAlign CSSFlex
_ a
"baseline" = Alignment -> Maybe Alignment
forall a. a -> Maybe a
Just Alignment
AlBaseline
parseAlign CSSFlex
_ a
_ = Maybe Alignment
forall a. Maybe a
Nothing
instance PropertyParser CSSFlex where
temp :: CSSFlex
temp = CSSFlex {
directionCSS :: Direction
directionCSS = Direction
Row,
reverseRowsCSS :: Bool
reverseRowsCSS = Bool
False,
wrapCSS :: FlexWrapping
wrapCSS = FlexWrapping
NoWrap,
justifyCSS :: Maybe Justification
justifyCSS = Maybe Justification
forall a. Maybe a
Nothing,
alignItemsCSS :: Alignment
alignItemsCSS = Alignment
AlStretch,
alignLinesCSS :: Maybe Justification
alignLinesCSS = Justification -> Maybe Justification
forall a. a -> Maybe a
Just Justification
JStart,
rowGapCSS :: Unitted
rowGapCSS = (Double
0,Text
"px"),
columnGapCSS :: Unitted
columnGapCSS = (Double
0,Text
"px"),
orderCSS :: Integer
orderCSS = Integer
0,
growCSS :: Double
growCSS = Double
0,
shrinkCSS :: Double
shrinkCSS = Double
1,
basisCSS :: Unitted
basisCSS = (Double
0,Text
"auto"),
alignSelfCSS :: Alignment
alignSelfCSS = Alignment
AlStretch,
textRTL :: Bool
textRTL = Bool
False
}
inherit :: CSSFlex -> CSSFlex
inherit CSSFlex
parent = CSSFlex
forall a. PropertyParser a => a
temp { alignSelfCSS :: Alignment
alignSelfCSS = CSSFlex -> Alignment
alignItemsCSS CSSFlex
parent }
priority :: CSSFlex -> [Text]
priority CSSFlex
_ = [Text
"flex-direction"]
longhand :: CSSFlex -> CSSFlex -> Text -> [Token] -> Maybe CSSFlex
longhand CSSFlex
_ CSSFlex
self Text
"flex-direction" [Ident Text
"row"] = CSSFlex -> Direction -> Bool -> Maybe CSSFlex
setDir CSSFlex
self Direction
Row Bool
False
longhand CSSFlex
_ CSSFlex
self Text
"flex-direction" [Ident Text
"row-reverse"] = CSSFlex -> Direction -> Bool -> Maybe CSSFlex
setDir CSSFlex
self Direction
Row Bool
True
longhand CSSFlex
_ CSSFlex
self Text
"flex-direction" [Ident Text
"column"] = CSSFlex -> Direction -> Bool -> Maybe CSSFlex
setDir CSSFlex
self Direction
F.Column Bool
False
longhand CSSFlex
_ CSSFlex
self Text
"flex-direction" [Ident Text
"column-reverse"] =
CSSFlex -> Direction -> Bool -> Maybe CSSFlex
setDir CSSFlex
self Direction
F.Column Bool
True
longhand CSSFlex
_ CSSFlex
self Text
"flex-direction" [Ident Text
"initial"] = CSSFlex -> Direction -> Bool -> Maybe CSSFlex
setDir CSSFlex
self Direction
Row Bool
False
longhand CSSFlex
_ CSSFlex
self Text
"flex-wrap" [Ident Text
"no-wrap"] = CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { wrapCSS :: FlexWrapping
wrapCSS = FlexWrapping
NoWrap }
longhand CSSFlex
_ CSSFlex
self Text
"flex-wrap" [Ident Text
"wrap"] = CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { wrapCSS :: FlexWrapping
wrapCSS = FlexWrapping
Wrap }
longhand CSSFlex
_ CSSFlex
self Text
"flex-wrap" [Ident Text
"wrap-reverse"] =
CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { wrapCSS :: FlexWrapping
wrapCSS = FlexWrapping
WrapReverse }
longhand CSSFlex
_ CSSFlex
self Text
"flex-wrap" [Ident Text
"initial"] = CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { wrapCSS :: FlexWrapping
wrapCSS = FlexWrapping
NoWrap }
longhand CSSFlex
_ CSSFlex
self Text
"justify-content" [Ident Text
x]
| Text
x Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"initial" = CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { justifyCSS :: Maybe Justification
justifyCSS = CSSFlex -> String -> Maybe Justification
forall {a}.
(Eq a, IsString a) =>
CSSFlex -> a -> Maybe Justification
parseJustify CSSFlex
self String
"flex-start" }
| y :: Maybe Justification
y@(Just Justification
_) <- CSSFlex -> Text -> Maybe Justification
forall {a}.
(Eq a, IsString a) =>
CSSFlex -> a -> Maybe Justification
parseJustify CSSFlex
self Text
x = CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { justifyCSS :: Maybe Justification
justifyCSS = Maybe Justification
y }
longhand CSSFlex
_ CSSFlex
self Text
"align-items" [Ident Text
x]
| Text
x Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"initial" = CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { alignItemsCSS :: Alignment
alignItemsCSS = Alignment
AlStretch }
| Just Alignment
y <- CSSFlex -> Text -> Maybe Alignment
forall {a}. (Eq a, IsString a) => CSSFlex -> a -> Maybe Alignment
parseAlign CSSFlex
self Text
x = CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { alignItemsCSS :: Alignment
alignItemsCSS = Alignment
y }
longhand CSSFlex
_ CSSFlex
self Text
"align-content" [Ident Text
x] | Text
x Text -> [Text] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text
"initial", Text
"normal"] =
CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { alignLinesCSS :: Maybe Justification
alignLinesCSS = CSSFlex -> String -> Maybe Justification
forall {a}.
(Eq a, IsString a) =>
CSSFlex -> a -> Maybe Justification
parseJustify CSSFlex
self String
"start" }
| Text
x Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"stretch" = CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { alignLinesCSS :: Maybe Justification
alignLinesCSS = Maybe Justification
forall a. Maybe a
Nothing }
| y :: Maybe Justification
y@(Just Justification
_) <- CSSFlex -> Text -> Maybe Justification
forall {a}.
(Eq a, IsString a) =>
CSSFlex -> a -> Maybe Justification
parseJustify CSSFlex
self Text
x = CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { alignLinesCSS :: Maybe Justification
alignLinesCSS = Maybe Justification
y }
longhand CSSFlex
_ CSSFlex
self Text
"row-gap" [Ident Text
x]
| Text
x Text -> [Text] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text
"initial", Text
"normal"] = CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { rowGapCSS :: Unitted
rowGapCSS = (Double
0,Text
"px") }
| Bool
otherwise = Maybe CSSFlex
forall a. Maybe a
Nothing
longhand CSSFlex
_ CSSFlex
self Text
"row-gap" [Token]
toks
| Just Unitted
x <- [Token] -> Maybe Unitted
parseLength [Token]
toks = CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { rowGapCSS :: Unitted
rowGapCSS = Unitted
x}
longhand CSSFlex
_ CSSFlex
self Text
"column-gap" [Ident Text
x]
| Text
x Text -> [Text] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text
"initial", Text
"normal"] = CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { columnGapCSS :: Unitted
columnGapCSS = (Double
0,Text
"px") }
| Bool
otherwise = Maybe CSSFlex
forall a. Maybe a
Nothing
longhand CSSFlex
_ CSSFlex
self Text
"column-gap" [Token]
toks
| Just Unitted
x <- [Token] -> Maybe Unitted
parseLength [Token]
toks = CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { columnGapCSS :: Unitted
columnGapCSS = Unitted
x }
longhand CSSFlex
_ CSSFlex
self Text
"order" [Number Text
_ (NVInteger Integer
x)] = CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { orderCSS :: Integer
orderCSS = Integer
x }
longhand CSSFlex
_ CSSFlex
self Text
"order" [Ident Text
"initial"] = CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { orderCSS :: Integer
orderCSS = Integer
0 }
longhand CSSFlex
_ CSSFlex
self Text
"flex-grow" [Number Text
_ NumericValue
x] | NumericValue -> Double
forall x. (Fractional x, RealFloat x) => NumericValue -> x
n2f NumericValue
xDouble -> Double -> Bool
forall a. Ord a => a -> a -> Bool
>Double
0 = CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self {growCSS :: Double
growCSS=NumericValue -> Double
forall x. (Fractional x, RealFloat x) => NumericValue -> x
n2f NumericValue
x}
longhand CSSFlex
_ CSSFlex
self Text
"flex-grow" [Ident Text
"initial"] = CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { growCSS :: Double
growCSS = Double
0 }
longhand CSSFlex
_ CSSFlex
self Text
"flex-shrink" [Number Text
_ NumericValue
x] | NumericValue -> Double
forall x. (Fractional x, RealFloat x) => NumericValue -> x
n2f NumericValue
x Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
> Double
0 =
CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { shrinkCSS :: Double
shrinkCSS = NumericValue -> Double
forall x. (Fractional x, RealFloat x) => NumericValue -> x
n2f NumericValue
x }
longhand CSSFlex
_ CSSFlex
self Text
"flex-shrink" [Ident Text
"initial"] = CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { shrinkCSS :: Double
shrinkCSS = Double
1 }
longhand CSSFlex
_ CSSFlex
self Text
"flex-basis" [Token]
toks | Just Unitted
x <- [Token] -> Maybe Unitted
parseLength [Token]
toks =
CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { basisCSS :: Unitted
basisCSS = Unitted
x }
longhand CSSFlex
parent CSSFlex
self Text
"align-self" [Ident Text
x] | Text
x Text -> [Text] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Text
"initial", Text
"auto"] =
CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { alignSelfCSS :: Alignment
alignSelfCSS = CSSFlex -> Alignment
alignItemsCSS CSSFlex
parent }
| Just Alignment
y <- CSSFlex -> Text -> Maybe Alignment
forall {a}. (Eq a, IsString a) => CSSFlex -> a -> Maybe Alignment
parseAlign CSSFlex
self Text
x = CSSFlex -> Maybe CSSFlex
forall a. a -> Maybe a
Just CSSFlex
self { alignSelfCSS :: Alignment
alignSelfCSS = Alignment
y }
longhand CSSFlex
_ CSSFlex
_ Text
_ [Token]
_ = Maybe CSSFlex
forall a. Maybe a
Nothing
shorthand :: CSSFlex -> Text -> [Token] -> Props
shorthand CSSFlex
self Text
"flex-flow" [Token]
toks =
CSSFlex -> [Text] -> [Token] -> Props
forall a. PropertyParser a => a -> [Text] -> [Token] -> Props
parseUnorderedShorthand CSSFlex
self [Text
"flex-direction", Text
"flex-wrap"] [Token]
toks
shorthand CSSFlex
self Text
"gap" [Token]
toks | [[Token]
x] <- [Token] -> [[Token]]
parseOperands [Token]
toks =
CSSFlex -> [Text] -> [[Token]] -> Props
forall a. PropertyParser a => a -> [Text] -> [[Token]] -> Props
parseUnorderedShorthand' CSSFlex
self [Text
"row-gap", Text
"column-gap"] [[Token]
x, [Token]
x]
| Bool
otherwise = CSSFlex -> [Text] -> [Token] -> Props
forall a. PropertyParser a => a -> [Text] -> [Token] -> Props
parseUnorderedShorthand CSSFlex
self [Text
"row-gap", Text
"column-gap"] [Token]
toks
shorthand CSSFlex
self Text
"flex" [Token]
toks
| [Ident Text
"initial"] <- [Token]
toks =
[(Text
"flex-grow", [Token]
init), (Text
"flex-shrink", [Token]
init), (Text
"flex-basis", [Token]
px0)]
| [Ident Text
"auto"] <- [Token]
toks =
[(Text
"flex-grow", [Token]
n1), (Text
"flex-shrink", [Token]
n1), (Text
"flex-basis", [Token]
init)]
| [Ident Text
"none"] <- [Token]
toks =
[(Text
"flex-grow", [Token]
n0), (Text
"flex-shrink", [Token]
n0), (Text
"flex-basis", [Token]
init)]
| [[Token]
a] <- [[Token]]
operands, Text -> [Token] -> Bool
test Text
"flex-grow" [Token]
a =
[(Text
"flex-grow", [Token]
a), (Text
"flex-shrink", [Token]
init), (Text
"flex-basis", [Token]
px0)]
| [[Token]
a] <- [[Token]]
operands, Text -> [Token] -> Bool
test Text
"flex-basis" [Token]
a =
[(Text
"flex-grow", [Token]
n1), (Text
"flex-shrink", [Token]
init), (Text
"flex-basis", [Token]
a)]
| [[Token]
a, [Token]
b] <- [[Token]]
operands, Text -> [Token] -> Bool
test Text
"flex-grow" [Token]
a, Text -> [Token] -> Bool
test Text
"flex-shrink" [Token]
b =
[(Text
"flex-grow", [Token]
a), (Text
"flex-shrink", [Token]
b), (Text
"flex-basis", [Token]
px0)]
| [[Token]
a, [Token]
b] <- [[Token]]
operands, Text -> [Token] -> Bool
test Text
"flex-grow" [Token]
a, Text -> [Token] -> Bool
test Text
"flex-basis" [Token]
b =
[(Text
"flex-grow", [Token]
a), (Text
"flex-shrink", [Token]
init), (Text
"flex-basis", [Token]
b)]
| [[Token]
a, [Token]
b, [Token]
c] <- [[Token]]
operands, Text -> [Token] -> Bool
test Text
"flex-grow" [Token]
a, Text -> [Token] -> Bool
test Text
"flex-shrink" [Token]
b, Text -> [Token] -> Bool
test Text
"flex-basis" [Token]
c =
[(Text
"flex-grow", [Token]
a), (Text
"flex-shrink", [Token]
b), (Text
"flex-basis", [Token]
c)]
where
operands :: [[Token]]
operands = [Token] -> [[Token]]
parseOperands [Token]
toks
test :: Text -> [Token] -> Bool
test Text
a = Maybe CSSFlex -> Bool
forall a. Maybe a -> Bool
isJust (Maybe CSSFlex -> Bool)
-> ([Token] -> Maybe CSSFlex) -> [Token] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CSSFlex -> CSSFlex -> Text -> [Token] -> Maybe CSSFlex
forall a. PropertyParser a => a -> a -> Text -> [Token] -> Maybe a
longhand CSSFlex
self CSSFlex
self Text
a
init :: [Token]
init = [Text -> Token
Ident Text
"initial"]
px0 :: [Token]
px0 = [Text -> NumericValue -> Text -> Token
Dimension Text
"0" (Integer -> NumericValue
NVInteger Integer
0) Text
"px"]
n1 :: [Token]
n1 = [Text -> NumericValue -> Token
Number Text
"1" (Integer -> NumericValue
NVInteger Integer
1)]
n0 :: [Token]
n0 = [Text -> NumericValue -> Token
Number Text
"0" (Integer -> NumericValue
NVInteger Integer
0)]
shorthand CSSFlex
self Text
k [Token]
v | Just CSSFlex
_ <- CSSFlex -> CSSFlex -> Text -> [Token] -> Maybe CSSFlex
forall a. PropertyParser a => a -> a -> Text -> [Token] -> Maybe a
longhand CSSFlex
self CSSFlex
self Text
k [Token]
v = [(Text
k, [Token]
v)]
| Bool
otherwise = []
lowerFlex :: CSSFlex -> Font' -> [CSSFlex] -> [a] -> [Font'] -> Flex a Length
lowerFlex :: forall a.
CSSFlex -> Font' -> [CSSFlex] -> [a] -> [Font'] -> Flex a Length
lowerFlex CSSFlex
self Font'
font [CSSFlex]
kids [a]
kids' [Font']
fonts' = Flex {
direction :: Direction
direction = CSSFlex -> Direction
directionCSS CSSFlex
self,
reverseRows :: Bool
reverseRows = CSSFlex -> Bool
reverseRowsCSS CSSFlex
self,
wrap :: FlexWrapping
wrap = CSSFlex -> FlexWrapping
wrapCSS CSSFlex
self,
justify :: Justification
justify = case CSSFlex -> Maybe Justification
justifyCSS CSSFlex
self of
Just Justification
x -> Justification
x
Maybe Justification
Nothing | CSSFlex -> Bool
reverseRowsCSS CSSFlex
self -> Justification
JEnd
Maybe Justification
Nothing -> Justification
JStart,
alignLines :: Maybe Justification
alignLines = CSSFlex -> Maybe Justification
alignLinesCSS CSSFlex
self,
baseGap :: Length
baseGap = case CSSFlex -> Direction
directionCSS CSSFlex
self of
Direction
Row -> (Unitted -> Font' -> Length) -> Font' -> Unitted -> Length
forall a b c. (a -> b -> c) -> b -> a -> c
flip Unitted -> Font' -> Length
finalizeLength Font'
font (Unitted -> Length) -> Unitted -> Length
forall a b. (a -> b) -> a -> b
$ CSSFlex -> Unitted
rowGapCSS CSSFlex
self
Direction
F.Column -> (Unitted -> Font' -> Length) -> Font' -> Unitted -> Length
forall a b c. (a -> b -> c) -> b -> a -> c
flip Unitted -> Font' -> Length
finalizeLength Font'
font (Unitted -> Length) -> Unitted -> Length
forall a b. (a -> b) -> a -> b
$ CSSFlex -> Unitted
columnGapCSS CSSFlex
self,
crossGap :: Length
crossGap = case CSSFlex -> Direction
directionCSS CSSFlex
self of
Direction
Row -> (Unitted -> Font' -> Length) -> Font' -> Unitted -> Length
forall a b c. (a -> b -> c) -> b -> a -> c
flip Unitted -> Font' -> Length
finalizeLength Font'
font (Unitted -> Length) -> Unitted -> Length
forall a b. (a -> b) -> a -> b
$ CSSFlex -> Unitted
columnGapCSS CSSFlex
self
Direction
F.Column -> (Unitted -> Font' -> Length) -> Font' -> Unitted -> Length
forall a b c. (a -> b -> c) -> b -> a -> c
flip Unitted -> Font' -> Length
finalizeLength Font'
font (Unitted -> Length) -> Unitted -> Length
forall a b. (a -> b) -> a -> b
$ CSSFlex -> Unitted
rowGapCSS CSSFlex
self,
pageWidth :: Double
pageWidth = Double
0,
children :: [[FlexChild a Length]]
children = [[FlexChild {
grow :: Double
grow = CSSFlex -> Double
growCSS CSSFlex
kid,
shrink :: Double
shrink = CSSFlex -> Double
shrinkCSS CSSFlex
kid,
basis :: Length
basis = (Unitted -> Font' -> Length) -> Font' -> Unitted -> Length
forall a b c. (a -> b -> c) -> b -> a -> c
flip Unitted -> Font' -> Length
finalizeLength Font'
font' (Unitted -> Length) -> Unitted -> Length
forall a b. (a -> b) -> a -> b
$ CSSFlex -> Unitted
rowGapCSS CSSFlex
kid,
alignment :: Alignment
alignment = CSSFlex -> Alignment
alignSelfCSS CSSFlex
kid,
flexInner :: a
flexInner = a
kid'
} | (CSSFlex
kid, a
kid', Font'
font') <- [CSSFlex] -> [a] -> [Font'] -> [(CSSFlex, a, Font')]
forall a b c. [a] -> [b] -> [c] -> [(a, b, c)]
zip3 [CSSFlex]
kids [a]
kids' [Font']
fonts']]
}