{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances, FlexibleContexts #-}
module Graphics.Layout.CSS(CSSBox(..), BoxSizing(..), Display(..),
finalizeCSS, finalizeCSS') where
import qualified Data.Text as Txt
import Stylist (PropertyParser(..))
import Stylist.Tree (StyleTree(..))
import Data.Text.ParagraphLayout.Rich (constructParagraph, defaultBoxOptions,
LineHeight(..), InnerNode(..), Box(..), RootNode(..), strut)
import Graphics.Layout.Box as B
import Graphics.Layout
import Graphics.Layout.CSS.Length
import Graphics.Layout.CSS.Font
import Graphics.Layout.Grid.CSS
import Graphics.Layout.Grid
import Graphics.Layout.Grid.Table
import Graphics.Layout.Inline.CSS
import Graphics.Layout.Flex.CSS
import Data.Char (isSpace)
import Graphics.Layout.CSS.Parse
import Data.Maybe (fromMaybe)
instance (PropertyParser x, Zero m, Zero n) => Default (UserData m n x) where
def :: UserData m n x
def = ((Font'
placeholderFont, Int
0), PaddedBox m n -> Either (PaddedBox m n) (LayoutItem m n x)
forall a b. a -> Either a b
Left PaddedBox m n
forall a. Zero a => a
zero, x
forall a. PropertyParser a => a
temp)
inner' :: PropertyParser x => Font' -> CSSBox x -> x
inner' :: forall x. PropertyParser x => Font' -> CSSBox x -> x
inner' Font'
f CSSBox x
self = ((Text, [Token]) -> x -> x) -> x -> [(Text, [Token])] -> x
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Text, [Token]) -> x -> x
apply (CSSBox x -> x
forall a. CSSBox a -> a
inner CSSBox x
self) ([(Text, [Token])] -> x) -> [(Text, [Token])] -> x
forall a b. (a -> b) -> a -> b
$ CSSBox x -> [(Text, [Token])]
forall a. CSSBox a -> [(Text, [Token])]
innerProperties CSSBox x
self
where apply :: (Text, [Token]) -> x -> x
apply (Text
k, [Token]
v) x
ret = x -> Maybe x -> x
forall a. a -> Maybe a -> a
fromMaybe x
ret (Maybe x -> x) -> Maybe x -> x
forall a b. (a -> b) -> a -> b
$
x -> x -> Text -> [Token] -> Maybe x
forall a. PropertyParser a => a -> a -> Text -> [Token] -> Maybe a
longhand (CSSBox x -> x
forall a. CSSBox a -> a
innerParent CSSBox x
self) x
ret Text
k ([Token] -> Maybe x) -> [Token] -> Maybe x
forall a b. (a -> b) -> a -> b
$ Font' -> [Token] -> [Token]
finalizeLengths Font'
f [Token]
v
finalizeCSS :: PropertyParser x => Font' -> Font' -> StyleTree (CSSBox x) ->
LayoutItem Length Length x
finalizeCSS :: forall x.
PropertyParser x =>
Font'
-> Font' -> StyleTree (CSSBox x) -> LayoutItem Length Length x
finalizeCSS Font'
root Font'
parent StyleTree { style :: forall p. StyleTree p -> p
style = self' :: CSSBox x
self'@CSSBox { display :: forall a. CSSBox a -> Display
display = Display
None } } =
x
-> PaddedBox Length Length
-> [LayoutItem Length Length x]
-> LayoutItem Length Length x
forall m n x.
x -> PaddedBox m n -> [LayoutItem m n x] -> LayoutItem m n x
LayoutFlow (Font' -> CSSBox x -> x
forall x. PropertyParser x => Font' -> CSSBox x -> x
inner' Font'
parent CSSBox x
self') PaddedBox Length Length
lengthBox []
finalizeCSS Font'
root Font'
parent self :: StyleTree (CSSBox x)
self@StyleTree {
style :: forall p. StyleTree p -> p
style = self' :: CSSBox x
self'@CSSBox { display :: forall a. CSSBox a -> Display
display = Display
Grid }, children :: forall p. StyleTree p -> [StyleTree p]
children = [StyleTree (CSSBox x)]
childs
} = x
-> PaddedBox Length Length
-> [LayoutItem Length Length x]
-> LayoutItem Length Length x
forall m n x.
x -> PaddedBox m n -> [LayoutItem m n x] -> LayoutItem m n x
LayoutFlow (Font' -> CSSBox x -> x
forall x. PropertyParser x => Font' -> CSSBox x -> x
inner' Font'
font_ CSSBox x
self') (CSSBox x -> Font' -> PaddedBox Length Length
forall {a}. CSSBox a -> Font' -> PaddedBox Length Length
finalizeBox CSSBox x
self' Font'
font_) [
CSSGrid
-> Font'
-> [CSSCell]
-> [LayoutItem Length Length x]
-> LayoutItem Length Length x
forall x.
PropertyParser x =>
CSSGrid
-> Font'
-> [CSSCell]
-> [LayoutItem Length Length x]
-> LayoutItem Length Length x
finalizeGrid (CSSBox x -> CSSGrid
forall a. CSSBox a -> CSSGrid
gridStyles CSSBox x
self') Font'
font_ ((CSSBox x -> CSSCell) -> [CSSBox x] -> [CSSCell]
forall a b. (a -> b) -> [a] -> [b]
map CSSBox x -> CSSCell
forall a. CSSBox a -> CSSCell
cellStyles ([CSSBox x] -> [CSSCell]) -> [CSSBox x] -> [CSSCell]
forall a b. (a -> b) -> a -> b
$ (StyleTree (CSSBox x) -> CSSBox x)
-> [StyleTree (CSSBox x)] -> [CSSBox x]
forall a b. (a -> b) -> [a] -> [b]
map StyleTree (CSSBox x) -> CSSBox x
forall p. StyleTree p -> p
style [StyleTree (CSSBox x)]
childs)
(Font'
-> Font'
-> CSSBox x
-> [StyleTree (CSSBox x)]
-> [LayoutItem Length Length x]
forall x.
PropertyParser x =>
Font'
-> Font'
-> CSSBox x
-> [StyleTree (CSSBox x)]
-> [LayoutItem Length Length x]
finalizeChilds Font'
root Font'
font_ CSSBox x
self' [StyleTree (CSSBox x)]
childs)]
where
font_ :: Font'
font_ = Pattern -> CSSFont -> Font' -> Font' -> Font'
pattern2font (CSSBox x -> Pattern
forall a. CSSBox a -> Pattern
font CSSBox x
self') (CSSBox x -> CSSFont
forall a. CSSBox a -> CSSFont
font' CSSBox x
self') Font'
parent Font'
root
finalizeCSS Font'
root Font'
parent self :: StyleTree (CSSBox x)
self@StyleTree {
style :: forall p. StyleTree p -> p
style = self' :: CSSBox x
self'@CSSBox {
display :: forall a. CSSBox a -> Display
display = Display
Table, tableOptions :: forall a. CSSBox a -> TableOptions
tableOptions = opts :: TableOptions
opts@TableOptions {captionBelow :: TableOptions -> Bool
captionBelow=Bool
False}
},
children :: forall p. StyleTree p -> [StyleTree p]
children = [StyleTree (CSSBox x)]
childs
} = x
-> PaddedBox Length Length
-> [LayoutItem Length Length x]
-> LayoutItem Length Length x
forall m n x.
x -> PaddedBox m n -> [LayoutItem m n x] -> LayoutItem m n x
LayoutFlow (Font' -> CSSBox x -> x
forall x. PropertyParser x => Font' -> CSSBox x -> x
inner' Font'
font_ CSSBox x
self')
(CSSBox x -> Font' -> PaddedBox Length Length
forall {a}. CSSBox a -> Font' -> PaddedBox Length Length
finalizeBox (CSSBox x -> CSSBox x
forall x. CSSBox x -> CSSBox x
collapseTBorders' CSSBox x
self') Font'
font_)
([Font'
-> Font' -> StyleTree (CSSBox x) -> LayoutItem Length Length x
forall x.
PropertyParser x =>
Font'
-> Font' -> StyleTree (CSSBox x) -> LayoutItem Length Length x
finalizeCSS Font'
root Font'
font_ StyleTree (CSSBox x)
child { style :: CSSBox x
style = CSSBox x
child' { display :: Display
display = Display
Block } }
| child :: StyleTree (CSSBox x)
child@StyleTree { style :: forall p. StyleTree p -> p
style = child' :: CSSBox x
child'@CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableCaption } } <- [StyleTree (CSSBox x)]
childs] [LayoutItem Length Length x]
-> [LayoutItem Length Length x] -> [LayoutItem Length Length x]
forall a. [a] -> [a] -> [a]
++
[Font'
-> Font'
-> x
-> TableOptions
-> [StyleTree (CSSBox x)]
-> LayoutItem Length Length x
forall {x}.
PropertyParser x =>
Font'
-> Font'
-> x
-> TableOptions
-> [StyleTree (CSSBox x)]
-> LayoutItem Length Length x
finalizeTable Font'
root Font'
font_ x
forall a. PropertyParser a => a
temp TableOptions
opts [StyleTree (CSSBox x)]
childs])
where
font_ :: Font'
font_ = Pattern -> CSSFont -> Font' -> Font' -> Font'
pattern2font (CSSBox x -> Pattern
forall a. CSSBox a -> Pattern
font CSSBox x
self') (CSSBox x -> CSSFont
forall a. CSSBox a -> CSSFont
font' CSSBox x
self') Font'
parent Font'
root
finalizeCSS Font'
root Font'
parent self :: StyleTree (CSSBox x)
self@StyleTree {
style :: forall p. StyleTree p -> p
style = self' :: CSSBox x
self'@CSSBox {
display :: forall a. CSSBox a -> Display
display = Display
Table, tableOptions :: forall a. CSSBox a -> TableOptions
tableOptions = opts :: TableOptions
opts@TableOptions {captionBelow :: TableOptions -> Bool
captionBelow=Bool
True}
}, children :: forall p. StyleTree p -> [StyleTree p]
children = [StyleTree (CSSBox x)]
childs
} = x
-> PaddedBox Length Length
-> [LayoutItem Length Length x]
-> LayoutItem Length Length x
forall m n x.
x -> PaddedBox m n -> [LayoutItem m n x] -> LayoutItem m n x
LayoutFlow (Font' -> CSSBox x -> x
forall x. PropertyParser x => Font' -> CSSBox x -> x
inner' Font'
font_ CSSBox x
self')
(CSSBox x -> Font' -> PaddedBox Length Length
forall {a}. CSSBox a -> Font' -> PaddedBox Length Length
finalizeBox (CSSBox x -> CSSBox x
forall x. CSSBox x -> CSSBox x
collapseTBorders' CSSBox x
self') Font'
font_)
(Font'
-> Font'
-> x
-> TableOptions
-> [StyleTree (CSSBox x)]
-> LayoutItem Length Length x
forall {x}.
PropertyParser x =>
Font'
-> Font'
-> x
-> TableOptions
-> [StyleTree (CSSBox x)]
-> LayoutItem Length Length x
finalizeTable Font'
root Font'
font_ x
forall a. PropertyParser a => a
temp TableOptions
opts [StyleTree (CSSBox x)]
childsLayoutItem Length Length x
-> [LayoutItem Length Length x] -> [LayoutItem Length Length x]
forall a. a -> [a] -> [a]
:
[Font'
-> Font' -> StyleTree (CSSBox x) -> LayoutItem Length Length x
forall x.
PropertyParser x =>
Font'
-> Font' -> StyleTree (CSSBox x) -> LayoutItem Length Length x
finalizeCSS Font'
root Font'
font_ StyleTree (CSSBox x)
child { style :: CSSBox x
style = CSSBox x
child' { display :: Display
display = Display
Block } }
| child :: StyleTree (CSSBox x)
child@StyleTree { style :: forall p. StyleTree p -> p
style = child' :: CSSBox x
child'@CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableCaption } } <- [StyleTree (CSSBox x)]
childs])
where
font_ :: Font'
font_ = Pattern -> CSSFont -> Font' -> Font' -> Font'
pattern2font (CSSBox x -> Pattern
forall a. CSSBox a -> Pattern
font CSSBox x
self') (CSSBox x -> CSSFont
forall a. CSSBox a -> CSSFont
font' CSSBox x
self') Font'
parent Font'
root
finalizeCSS Font'
root Font'
parent self :: StyleTree (CSSBox x)
self@StyleTree {
style :: forall p. StyleTree p -> p
style = self' :: CSSBox x
self'@CSSBox { display :: forall a. CSSBox a -> Display
display = Display
Flex, flexOptions :: forall a. CSSBox a -> CSSFlex
flexOptions = CSSFlex
flex },
children :: forall p. StyleTree p -> [StyleTree p]
children = [StyleTree (CSSBox x)]
childs
} = x
-> PaddedBox Length Length
-> [LayoutItem Length Length x]
-> LayoutItem Length Length x
forall m n x.
x -> PaddedBox m n -> [LayoutItem m n x] -> LayoutItem m n x
LayoutFlow (Font' -> CSSBox x -> x
forall x. PropertyParser x => Font' -> CSSBox x -> x
inner' Font'
font_ CSSBox x
self' ) (CSSBox x -> Font' -> PaddedBox Length Length
forall {a}. CSSBox a -> Font' -> PaddedBox Length Length
finalizeBox CSSBox x
self' Font'
font_) [
x
-> Flex (LayoutItem Length Length x) Length
-> LayoutItem Length Length x
forall m n x. x -> Flex (LayoutItem m n x) m -> LayoutItem m n x
LayoutFlex x
forall a. PropertyParser a => a
temp (Flex (LayoutItem Length Length x) Length
-> LayoutItem Length Length x)
-> Flex (LayoutItem Length Length x) Length
-> LayoutItem Length Length x
forall a b. (a -> b) -> a -> b
$ CSSFlex
-> Font'
-> [CSSFlex]
-> [LayoutItem Length Length x]
-> [Font']
-> Flex (LayoutItem Length Length x) Length
forall a.
CSSFlex -> Font' -> [CSSFlex] -> [a] -> [Font'] -> Flex a Length
lowerFlex CSSFlex
flex Font'
font_ ((CSSBox x -> CSSFlex) -> [CSSBox x] -> [CSSFlex]
forall a b. (a -> b) -> [a] -> [b]
map CSSBox x -> CSSFlex
forall a. CSSBox a -> CSSFlex
flexOptions [CSSBox x]
childs')
(((StyleTree (CSSBox x) -> LayoutItem Length Length x)
-> [StyleTree (CSSBox x)] -> [LayoutItem Length Length x])
-> [StyleTree (CSSBox x)]
-> (StyleTree (CSSBox x) -> LayoutItem Length Length x)
-> [LayoutItem Length Length x]
forall a b c. (a -> b -> c) -> b -> a -> c
flip (StyleTree (CSSBox x) -> LayoutItem Length Length x)
-> [StyleTree (CSSBox x)] -> [LayoutItem Length Length x]
forall a b. (a -> b) -> [a] -> [b]
map [StyleTree (CSSBox x)]
childs ((StyleTree (CSSBox x) -> LayoutItem Length Length x)
-> [LayoutItem Length Length x])
-> (StyleTree (CSSBox x) -> LayoutItem Length Length x)
-> [LayoutItem Length Length x]
forall a b. (a -> b) -> a -> b
$ Font'
-> Font' -> StyleTree (CSSBox x) -> LayoutItem Length Length x
forall x.
PropertyParser x =>
Font'
-> Font' -> StyleTree (CSSBox x) -> LayoutItem Length Length x
finalizeCSS Font'
root Font'
font_) ((CSSBox x -> Font') -> [CSSBox x] -> [Font']
forall a b. (a -> b) -> [a] -> [b]
map CSSBox x -> Font'
forall {a}. CSSBox a -> Font'
style2font [CSSBox x]
childs')]
where
font_ :: Font'
font_ = CSSBox x -> Font'
forall {a}. CSSBox a -> Font'
style2font CSSBox x
self'
style2font :: CSSBox a -> Font'
style2font CSSBox a
style = Pattern -> CSSFont -> Font' -> Font' -> Font'
pattern2font (CSSBox a -> Pattern
forall a. CSSBox a -> Pattern
font CSSBox a
style) (CSSBox a -> CSSFont
forall a. CSSBox a -> CSSFont
font' CSSBox a
style) Font'
parent Font'
root
childs' :: [CSSBox x]
childs' = (StyleTree (CSSBox x) -> CSSBox x)
-> [StyleTree (CSSBox x)] -> [CSSBox x]
forall a b. (a -> b) -> [a] -> [b]
map StyleTree (CSSBox x) -> CSSBox x
forall p. StyleTree p -> p
style [StyleTree (CSSBox x)]
childs
finalizeCSS Font'
root Font'
parent self :: StyleTree (CSSBox x)
self@StyleTree {
style :: forall p. StyleTree p -> p
style = CSSBox x
self', children :: forall p. StyleTree p -> [StyleTree p]
children = [StyleTree (CSSBox x)]
childs
} = x
-> PaddedBox Length Length
-> [LayoutItem Length Length x]
-> LayoutItem Length Length x
forall m n x.
x -> PaddedBox m n -> [LayoutItem m n x] -> LayoutItem m n x
LayoutFlow (Font' -> CSSBox x -> x
forall x. PropertyParser x => Font' -> CSSBox x -> x
inner' Font'
font_ CSSBox x
self') (CSSBox x -> Font' -> PaddedBox Length Length
forall {a}. CSSBox a -> Font' -> PaddedBox Length Length
finalizeBox CSSBox x
self' Font'
font_)
(Font'
-> Font'
-> CSSBox x
-> [StyleTree (CSSBox x)]
-> [LayoutItem Length Length x]
forall x.
PropertyParser x =>
Font'
-> Font'
-> CSSBox x
-> [StyleTree (CSSBox x)]
-> [LayoutItem Length Length x]
finalizeChilds Font'
root Font'
font_ CSSBox x
self' [StyleTree (CSSBox x)]
childs)
where
font_ :: Font'
font_ = Pattern -> CSSFont -> Font' -> Font' -> Font'
pattern2font (CSSBox x -> Pattern
forall a. CSSBox a -> Pattern
font CSSBox x
self') (CSSBox x -> CSSFont
forall a. CSSBox a -> CSSFont
font' CSSBox x
self') Font'
parent Font'
root
finalizeCSS' :: Font' -> StyleTree (CSSBox x) -> LayoutItem Length Length x
finalizeCSS' Font'
sysfont self :: StyleTree (CSSBox x)
self@StyleTree { style :: forall p. StyleTree p -> p
style = CSSBox x
self' } =
Font'
-> Font' -> StyleTree (CSSBox x) -> LayoutItem Length Length x
forall x.
PropertyParser x =>
Font'
-> Font' -> StyleTree (CSSBox x) -> LayoutItem Length Length x
finalizeCSS (Pattern -> CSSFont -> Font' -> Font' -> Font'
pattern2font (CSSBox x -> Pattern
forall a. CSSBox a -> Pattern
font CSSBox x
self') (CSSBox x -> CSSFont
forall a. CSSBox a -> CSSFont
font' CSSBox x
self') Font'
sysfont Font'
sysfont) Font'
sysfont StyleTree (CSSBox x)
self
finalizeChilds :: PropertyParser x => Font' -> Font' -> CSSBox x ->
[StyleTree (CSSBox x)] -> [LayoutItem Length Length x]
finalizeChilds :: forall x.
PropertyParser x =>
Font'
-> Font'
-> CSSBox x
-> [StyleTree (CSSBox x)]
-> [LayoutItem Length Length x]
finalizeChilds Font'
root Font'
parent CSSBox x
style' (StyleTree { style :: forall p. StyleTree p -> p
style = CSSBox { display :: forall a. CSSBox a -> Display
display = Display
None } }:[StyleTree (CSSBox x)]
childs) =
Font'
-> Font'
-> CSSBox x
-> [StyleTree (CSSBox x)]
-> [LayoutItem Length Length x]
forall x.
PropertyParser x =>
Font'
-> Font'
-> CSSBox x
-> [StyleTree (CSSBox x)]
-> [LayoutItem Length Length x]
finalizeChilds Font'
root Font'
parent CSSBox x
style' [StyleTree (CSSBox x)]
childs
finalizeChilds Font'
root Font'
parent CSSBox x
style' childs :: [StyleTree (CSSBox x)]
childs@(StyleTree (CSSBox x)
child:[StyleTree (CSSBox x)]
_)
| [StyleTree (CSSBox x)] -> Bool
forall {a}. [StyleTree (CSSBox a)] -> Bool
isInlineTree [StyleTree (CSSBox x)]
childs, Just Paragraph
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length x), x)
self <- RootNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length x), x)
-> Maybe
(Paragraph
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length x), x))
forall {d}. RootNode Text d -> Maybe (Paragraph d)
finalizeParagraph ([StyleTree (CSSBox x)]
-> RootNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length x), x)
flattenTree0 [StyleTree (CSSBox x)]
childs) =
[x
-> Paragraph
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length x), x)
-> PageOptions
-> LayoutItem Length Length x
forall m n x.
x -> Paragraph (UserData m n x) -> PageOptions -> LayoutItem m n x
LayoutInline (x -> x
forall a. PropertyParser a => a -> a
inherit (x -> x) -> x -> x
forall a b. (a -> b) -> a -> b
$ Font' -> CSSBox x -> x
forall x. PropertyParser x => Font' -> CSSBox x -> x
inner' Font'
parent CSSBox x
style') Paragraph
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length x), x)
self PageOptions
paging]
| (inlines :: [StyleTree (CSSBox x)]
inlines@(StyleTree (CSSBox x)
_:[StyleTree (CSSBox x)]
_), [StyleTree (CSSBox x)]
blocks) <- [StyleTree (CSSBox x)]
-> ([StyleTree (CSSBox x)], [StyleTree (CSSBox x)])
forall {a}.
[StyleTree (CSSBox a)]
-> ([StyleTree (CSSBox a)], [StyleTree (CSSBox a)])
spanInlines [StyleTree (CSSBox x)]
childs,
Just Paragraph
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length x), x)
self <- RootNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length x), x)
-> Maybe
(Paragraph
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length x), x))
forall {d}. RootNode Text d -> Maybe (Paragraph d)
finalizeParagraph ([StyleTree (CSSBox x)]
-> RootNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length x), x)
flattenTree0 [StyleTree (CSSBox x)]
inlines) =
x
-> Paragraph
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length x), x)
-> PageOptions
-> LayoutItem Length Length x
forall m n x.
x -> Paragraph (UserData m n x) -> PageOptions -> LayoutItem m n x
LayoutInline (x -> x
forall a. PropertyParser a => a -> a
inherit (x -> x) -> x -> x
forall a b. (a -> b) -> a -> b
$ Font' -> CSSBox x -> x
forall x. PropertyParser x => Font' -> CSSBox x -> x
inner' Font'
parent CSSBox x
style') Paragraph
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length x), x)
self PageOptions
paging LayoutItem Length Length x
-> [LayoutItem Length Length x] -> [LayoutItem Length Length x]
forall a. a -> [a] -> [a]
:
Font'
-> Font'
-> CSSBox x
-> [StyleTree (CSSBox x)]
-> [LayoutItem Length Length x]
forall x.
PropertyParser x =>
Font'
-> Font'
-> CSSBox x
-> [StyleTree (CSSBox x)]
-> [LayoutItem Length Length x]
finalizeChilds Font'
root Font'
parent CSSBox x
style' [StyleTree (CSSBox x)]
blocks
| (StyleTree { style :: forall p. StyleTree p -> p
style = CSSBox { display :: forall a. CSSBox a -> Display
display = Display
Inline } }:[StyleTree (CSSBox x)]
childs') <- [StyleTree (CSSBox x)]
childs =
Font'
-> Font'
-> CSSBox x
-> [StyleTree (CSSBox x)]
-> [LayoutItem Length Length x]
forall x.
PropertyParser x =>
Font'
-> Font'
-> CSSBox x
-> [StyleTree (CSSBox x)]
-> [LayoutItem Length Length x]
finalizeChilds Font'
root Font'
parent CSSBox x
style' [StyleTree (CSSBox x)]
childs'
where
paging :: PageOptions
paging = CSSBox x -> PageOptions
forall a. CSSBox a -> PageOptions
pageOptions (CSSBox x -> PageOptions) -> CSSBox x -> PageOptions
forall a b. (a -> b) -> a -> b
$ StyleTree (CSSBox x) -> CSSBox x
forall p. StyleTree p -> p
style StyleTree (CSSBox x)
child
isInlineTree :: [StyleTree (CSSBox a)] -> Bool
isInlineTree = (StyleTree (CSSBox a) -> Bool) -> [StyleTree (CSSBox a)] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all StyleTree (CSSBox a) -> Bool
isInlineTree0
isInlineTree0 :: StyleTree (CSSBox a) -> Bool
isInlineTree0 StyleTree { style :: forall p. StyleTree p -> p
style = CSSBox { display :: forall a. CSSBox a -> Display
display = Display
Inline }, children :: forall p. StyleTree p -> [StyleTree p]
children = [StyleTree (CSSBox a)]
childs } =
[StyleTree (CSSBox a)] -> Bool
isInlineTree [StyleTree (CSSBox a)]
childs
isInlineTree0 StyleTree { style :: forall p. StyleTree p -> p
style = CSSBox { display :: forall a. CSSBox a -> Display
display = Inline' Display
_ } } = Bool
True
isInlineTree0 StyleTree (CSSBox a)
_ = Bool
False
spanInlines :: [StyleTree (CSSBox a)]
-> ([StyleTree (CSSBox a)], [StyleTree (CSSBox a)])
spanInlines [StyleTree (CSSBox a)]
childs = case (StyleTree (CSSBox a) -> Bool)
-> [StyleTree (CSSBox a)]
-> ([StyleTree (CSSBox a)], [StyleTree (CSSBox a)])
forall a. (a -> Bool) -> [a] -> ([a], [a])
span StyleTree (CSSBox a) -> Bool
forall {a}. StyleTree (CSSBox a) -> Bool
isInlineTree0 [StyleTree (CSSBox a)]
childs of
([StyleTree (CSSBox a)]
inlines, (StyleTree {
style :: forall p. StyleTree p -> p
style = CSSBox { display :: forall a. CSSBox a -> Display
display = Display
Inline }, children :: forall p. StyleTree p -> [StyleTree p]
children = [StyleTree (CSSBox a)]
tail
}:[StyleTree (CSSBox a)]
blocks)) -> let ([StyleTree (CSSBox a)]
inlines', [StyleTree (CSSBox a)]
blocks') = [StyleTree (CSSBox a)]
-> ([StyleTree (CSSBox a)], [StyleTree (CSSBox a)])
spanInlines [StyleTree (CSSBox a)]
tail
in ([StyleTree (CSSBox a)]
inlines [StyleTree (CSSBox a)]
-> [StyleTree (CSSBox a)] -> [StyleTree (CSSBox a)]
forall a. [a] -> [a] -> [a]
++ [StyleTree (CSSBox a)]
inlines', [StyleTree (CSSBox a)]
blocks' [StyleTree (CSSBox a)]
-> [StyleTree (CSSBox a)] -> [StyleTree (CSSBox a)]
forall a. [a] -> [a] -> [a]
++ [StyleTree (CSSBox a)]
blocks)
([StyleTree (CSSBox a)], [StyleTree (CSSBox a)])
ret -> ([StyleTree (CSSBox a)], [StyleTree (CSSBox a)])
ret
flattenTree0 :: [StyleTree (CSSBox x)]
-> RootNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length x), x)
flattenTree0 = ((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length x), x)
-> RootNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length x), x)
-> RootNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length x), x)
forall t d. EmptyText t => d -> RootNode t d -> RootNode t d
strut ((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length x), x)
forall a. Default a => a
def (RootNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length x), x)
-> RootNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length x), x))
-> ([StyleTree (CSSBox x)]
-> RootNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length x), x))
-> [StyleTree (CSSBox x)]
-> RootNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length x), x)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [StyleTree (CSSBox x)]
-> RootNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length x), x)
forall {a}.
(Default
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a),
PropertyParser a) =>
[StyleTree (CSSBox a)]
-> RootNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
flattenTree0'
flattenTree0' :: [StyleTree (CSSBox a)]
-> RootNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
flattenTree0' [StyleTree (CSSBox a)]
childs
| iStyle :: CSSInline
iStyle@(CSSInline Text
_ TextOptions
_ UnicodeBidi
bidi) <- CSSBox x -> CSSInline
forall a. CSSBox a -> CSSInline
inlineStyles CSSBox x
style',
UnicodeBidi
bidi UnicodeBidi -> [UnicodeBidi] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [UnicodeBidi
BdOverride, UnicodeBidi
BdIsolateOverride] = Box
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
-> RootNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
forall t d. Box t d -> RootNode t d
RootBox (Box
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
-> RootNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a))
-> Box
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
-> RootNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
forall a b. (a -> b) -> a -> b
$ [InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)]
-> TextOptions
-> Box
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
forall t d. [InnerNode t d] -> TextOptions -> Box t d
Box
(CSSInline
-> [InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)]
-> [InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)]
forall d.
Default d =>
CSSInline -> [InnerNode Text d] -> [InnerNode Text d]
applyBidi CSSInline
iStyle ([InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)]
-> [InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)])
-> [InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)]
-> [InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)]
forall a b. (a -> b) -> a -> b
$ ((Int, StyleTree (CSSBox a))
-> InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a))
-> [(Int, StyleTree (CSSBox a))]
-> [InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)]
forall a b. (a -> b) -> [a] -> [b]
map (Font'
-> (Int, StyleTree (CSSBox a))
-> InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
forall {a}.
(PropertyParser a,
Default
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a),
a)) =>
Font'
-> (Int, StyleTree (CSSBox a))
-> InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
flattenTree Font'
parent) ([(Int, StyleTree (CSSBox a))]
-> [InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)])
-> [(Int, StyleTree (CSSBox a))]
-> [InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)]
forall a b. (a -> b) -> a -> b
$ [StyleTree (CSSBox a)] -> [(Int, StyleTree (CSSBox a))]
forall {b}. [b] -> [(Int, b)]
enumerate [StyleTree (CSSBox a)]
childs)
(TextOptions
-> Box
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a))
-> TextOptions
-> Box
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
forall a b. (a -> b) -> a -> b
$ (TextOptions -> Font' -> TextOptions)
-> Font' -> TextOptions -> TextOptions
forall a b c. (a -> b -> c) -> b -> a -> c
flip TextOptions -> Font' -> TextOptions
applyFontInline Font'
parent (TextOptions -> TextOptions) -> TextOptions -> TextOptions
forall a b. (a -> b) -> a -> b
$ CSSBox x -> TextOptions
forall {a}. CSSBox a -> TextOptions
txtOpts CSSBox x
style'
| Bool
otherwise = Box
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
-> RootNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
forall t d. Box t d -> RootNode t d
RootBox (Box
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
-> RootNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a))
-> Box
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
-> RootNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
forall a b. (a -> b) -> a -> b
$ [InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)]
-> TextOptions
-> Box
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
forall t d. [InnerNode t d] -> TextOptions -> Box t d
Box (((Int, StyleTree (CSSBox a))
-> InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a))
-> [(Int, StyleTree (CSSBox a))]
-> [InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)]
forall a b. (a -> b) -> [a] -> [b]
map (Font'
-> (Int, StyleTree (CSSBox a))
-> InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
forall {a}.
(PropertyParser a,
Default
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a),
a)) =>
Font'
-> (Int, StyleTree (CSSBox a))
-> InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
flattenTree Font'
parent) ([(Int, StyleTree (CSSBox a))]
-> [InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)])
-> [(Int, StyleTree (CSSBox a))]
-> [InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)]
forall a b. (a -> b) -> a -> b
$ [StyleTree (CSSBox a)] -> [(Int, StyleTree (CSSBox a))]
forall {b}. [b] -> [(Int, b)]
enumerate [StyleTree (CSSBox a)]
childs)
(TextOptions
-> Box
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a))
-> TextOptions
-> Box
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
forall a b. (a -> b) -> a -> b
$ (TextOptions -> Font' -> TextOptions)
-> Font' -> TextOptions -> TextOptions
forall a b c. (a -> b -> c) -> b -> a -> c
flip TextOptions -> Font' -> TextOptions
applyFontInline Font'
parent (TextOptions -> TextOptions) -> TextOptions -> TextOptions
forall a b. (a -> b) -> a -> b
$ CSSBox x -> TextOptions
forall {a}. CSSBox a -> TextOptions
txtOpts CSSBox x
style'
flattenTree :: Font'
-> (Int, StyleTree (CSSBox a))
-> InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
flattenTree Font'
p (Int
i, StyleTree self :: CSSBox a
self@CSSBox { display :: forall a. CSSBox a -> Display
display = Inline' Display
disp' } [StyleTree (CSSBox a)]
kids) =
Font'
-> Int
-> Either (PaddedBox Length Length) (LayoutItem Length Length a)
-> CSSBox a
-> [InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)]
-> InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
forall {a} {b} {b}.
(PropertyParser a, Default ((Font', b), b, a)) =>
Font'
-> b
-> b
-> CSSBox a
-> [InnerNode Text ((Font', b), b, a)]
-> InnerNode Text ((Font', b), b, a)
buildInline' (Pattern -> CSSFont -> Font' -> Font' -> Font'
pattern2font (CSSBox a -> Pattern
forall a. CSSBox a -> Pattern
font CSSBox a
self) (CSSBox a -> CSSFont
forall a. CSSBox a -> CSSFont
font' CSSBox a
self) Font'
p Font'
root) Int
i
(LayoutItem Length Length a
-> Either (PaddedBox Length Length) (LayoutItem Length Length a)
forall a b. b -> Either a b
Right (LayoutItem Length Length a
-> Either (PaddedBox Length Length) (LayoutItem Length Length a))
-> LayoutItem Length Length a
-> Either (PaddedBox Length Length) (LayoutItem Length Length a)
forall a b. (a -> b) -> a -> b
$ Font'
-> Font' -> StyleTree (CSSBox a) -> LayoutItem Length Length a
forall x.
PropertyParser x =>
Font'
-> Font' -> StyleTree (CSSBox x) -> LayoutItem Length Length x
finalizeCSS Font'
root Font'
p (StyleTree (CSSBox a) -> LayoutItem Length Length a)
-> StyleTree (CSSBox a) -> LayoutItem Length Length a
forall a b. (a -> b) -> a -> b
$ CSSBox a -> [StyleTree (CSSBox a)] -> StyleTree (CSSBox a)
forall p. p -> [StyleTree p] -> StyleTree p
StyleTree CSSBox a
self { display :: Display
display = Display
disp' } [StyleTree (CSSBox a)]
kids)
CSSBox a
self []
flattenTree Font'
p (Int
i, StyleTree CSSBox a
self child :: [StyleTree (CSSBox a)]
child@(StyleTree (CSSBox a)
_:[StyleTree (CSSBox a)]
_)) =
Font'
-> Int
-> CSSBox a
-> [InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)]
-> InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
forall {a} {b} {b}.
(PropertyParser a,
Default ((Font', b), Either (PaddedBox Length Length) b, a)) =>
Font'
-> b
-> CSSBox a
-> [InnerNode
Text ((Font', b), Either (PaddedBox Length Length) b, a)]
-> InnerNode
Text ((Font', b), Either (PaddedBox Length Length) b, a)
buildInline Font'
f Int
i CSSBox a
self ([InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)]
-> InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a))
-> [InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)]
-> InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
forall a b. (a -> b) -> a -> b
$ ((Int, StyleTree (CSSBox a))
-> InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a))
-> [(Int, StyleTree (CSSBox a))]
-> [InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)]
forall a b. (a -> b) -> [a] -> [b]
map (Font'
-> (Int, StyleTree (CSSBox a))
-> InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
flattenTree Font'
f) ([(Int, StyleTree (CSSBox a))]
-> [InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)])
-> [(Int, StyleTree (CSSBox a))]
-> [InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)]
forall a b. (a -> b) -> a -> b
$ [StyleTree (CSSBox a)] -> [(Int, StyleTree (CSSBox a))]
forall {b}. [b] -> [(Int, b)]
enumerate [StyleTree (CSSBox a)]
child
where f :: Font'
f = Pattern -> CSSFont -> Font' -> Font' -> Font'
pattern2font (CSSBox a -> Pattern
forall a. CSSBox a -> Pattern
font CSSBox a
self) (CSSBox a -> CSSFont
forall a. CSSBox a -> CSSFont
font' CSSBox a
self) Font'
p Font'
root
flattenTree Font'
f (Int
i,StyleTree {style :: forall p. StyleTree p -> p
style=self :: CSSBox a
self@CSSBox {inlineStyles :: forall a. CSSBox a -> CSSInline
inlineStyles=CSSInline Text
txt TextOptions
_ UnicodeBidi
_}})
= Font'
-> Int
-> CSSBox a
-> [InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)]
-> InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
forall {a} {b} {b}.
(PropertyParser a,
Default ((Font', b), Either (PaddedBox Length Length) b, a)) =>
Font'
-> b
-> CSSBox a
-> [InnerNode
Text ((Font', b), Either (PaddedBox Length Length) b, a)]
-> InnerNode
Text ((Font', b), Either (PaddedBox Length Length) b, a)
buildInline Font'
f Int
i CSSBox a
self [
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
-> Text
-> InnerNode
Text
((Font', Int),
Either (PaddedBox Length Length) (LayoutItem Length Length a), a)
forall t d. d -> t -> InnerNode t d
TextSequence ((Font'
f, Int
0), PaddedBox Length Length
-> Either (PaddedBox Length Length) (LayoutItem Length Length a)
forall a b. a -> Either a b
Left PaddedBox Length Length
forall a. Zero a => a
zero, a -> a
forall a. PropertyParser a => a -> a
inherit (a -> a) -> a -> a
forall a b. (a -> b) -> a -> b
$ Font' -> CSSBox a -> a
forall x. PropertyParser x => Font' -> CSSBox x -> x
inner' Font'
parent CSSBox a
self) Text
txt]
buildInline :: Font'
-> b
-> CSSBox a
-> [InnerNode
Text ((Font', b), Either (PaddedBox Length Length) b, a)]
-> InnerNode
Text ((Font', b), Either (PaddedBox Length Length) b, a)
buildInline Font'
f b
i CSSBox a
self [InnerNode
Text ((Font', b), Either (PaddedBox Length Length) b, a)]
childs =
Font'
-> b
-> Either (PaddedBox Length Length) b
-> CSSBox a
-> [InnerNode
Text ((Font', b), Either (PaddedBox Length Length) b, a)]
-> InnerNode
Text ((Font', b), Either (PaddedBox Length Length) b, a)
forall {a} {b} {b}.
(PropertyParser a, Default ((Font', b), b, a)) =>
Font'
-> b
-> b
-> CSSBox a
-> [InnerNode Text ((Font', b), b, a)]
-> InnerNode Text ((Font', b), b, a)
buildInline' Font'
f b
i (PaddedBox Length Length -> Either (PaddedBox Length Length) b
forall a b. a -> Either a b
Left (PaddedBox Length Length -> Either (PaddedBox Length Length) b)
-> PaddedBox Length Length -> Either (PaddedBox Length Length) b
forall a b. (a -> b) -> a -> b
$ CSSBox a -> Font' -> PaddedBox Length Length
forall {a}. CSSBox a -> Font' -> PaddedBox Length Length
finalizeBox CSSBox a
self Font'
f) CSSBox a
self [InnerNode
Text ((Font', b), Either (PaddedBox Length Length) b, a)]
childs
buildInline' :: Font'
-> b
-> b
-> CSSBox a
-> [InnerNode Text ((Font', b), b, a)]
-> InnerNode Text ((Font', b), b, a)
buildInline' Font'
f b
i b
val CSSBox a
self [InnerNode Text ((Font', b), b, a)]
childs =
((Font', b), b, a)
-> Box Text ((Font', b), b, a)
-> BoxOptions
-> InnerNode Text ((Font', b), b, a)
forall t d. d -> Box t d -> BoxOptions -> InnerNode t d
InlineBox ((Font'
f, b
i), b
val, Font' -> CSSBox a -> a
forall x. PropertyParser x => Font' -> CSSBox x -> x
inner' Font'
parent CSSBox a
self)
([InnerNode Text ((Font', b), b, a)]
-> TextOptions -> Box Text ((Font', b), b, a)
forall t d. [InnerNode t d] -> TextOptions -> Box t d
Box [InnerNode Text ((Font', b), b, a)]
childs' (TextOptions -> Box Text ((Font', b), b, a))
-> TextOptions -> Box Text ((Font', b), b, a)
forall a b. (a -> b) -> a -> b
$ (TextOptions -> Font' -> TextOptions)
-> Font' -> TextOptions -> TextOptions
forall a b c. (a -> b -> c) -> b -> a -> c
flip TextOptions -> Font' -> TextOptions
applyFontInline Font'
f (TextOptions -> TextOptions) -> TextOptions -> TextOptions
forall a b. (a -> b) -> a -> b
$ CSSBox a -> TextOptions
forall {a}. CSSBox a -> TextOptions
txtOpts CSSBox a
self)
(BoxOptions -> InnerNode Text ((Font', b), b, a))
-> BoxOptions -> InnerNode Text ((Font', b), b, a)
forall a b. (a -> b) -> a -> b
$ Font' -> TableOptions -> BoxOptions
resolveBoxOpts Font'
f (CSSBox a -> TableOptions
forall a. CSSBox a -> TableOptions
tableOptions CSSBox a
self)
where childs' :: [InnerNode Text ((Font', b), b, a)]
childs' = CSSInline
-> [InnerNode Text ((Font', b), b, a)]
-> [InnerNode Text ((Font', b), b, a)]
forall d.
Default d =>
CSSInline -> [InnerNode Text d] -> [InnerNode Text d]
applyBidi (CSSBox a -> CSSInline
forall a. CSSBox a -> CSSInline
inlineStyles CSSBox a
self) [InnerNode Text ((Font', b), b, a)]
childs
finalizeParagraph :: RootNode Text d -> Maybe (Paragraph d)
finalizeParagraph (RootBox (Box [TextSequence d
_ Text
txt] TextOptions
_))
| (Char -> Bool) -> Text -> Bool
Txt.all Char -> Bool
isSpace Text
txt = Maybe (Paragraph d)
forall a. Maybe a
Nothing
finalizeParagraph RootNode Text d
tree =
Paragraph d -> Maybe (Paragraph d)
forall a. a -> Maybe a
Just (Paragraph d -> Maybe (Paragraph d))
-> Paragraph d -> Maybe (Paragraph d)
forall a b. (a -> b) -> a -> b
$ Text -> RootNode Text d -> Text -> ParagraphOptions -> Paragraph d
forall d.
Text -> RootNode Text d -> Text -> ParagraphOptions -> Paragraph d
constructParagraph Text
"" RootNode Text d
tree Text
"" (ParagraphOptions -> Paragraph d)
-> ParagraphOptions -> Paragraph d
forall a b. (a -> b) -> a -> b
$ CSSBox x -> ParagraphOptions
forall a. CSSBox a -> ParagraphOptions
paragraphOptions CSSBox x
style'
enumerate :: [b] -> [(Int, b)]
enumerate = [Int] -> [b] -> [(Int, b)]
forall a b. [a] -> [b] -> [(a, b)]
zip ([Int] -> [b] -> [(Int, b)]) -> [Int] -> [b] -> [(Int, b)]
forall a b. (a -> b) -> a -> b
$ Int -> [Int]
forall a. Enum a => a -> [a]
enumFrom Int
0
finalizeChilds Font'
root Font'
parent style' :: CSSBox x
style'@CSSBox { tableOptions :: forall a. CSSBox a -> TableOptions
tableOptions = TableOptions
tOpts } [StyleTree (CSSBox x)]
childs
| (StyleTree (CSSBox x)
_:[StyleTree (CSSBox x)]
_) <- [StyleTree (CSSBox x)]
table = Font'
-> Font'
-> x
-> TableOptions
-> [StyleTree (CSSBox x)]
-> LayoutItem Length Length x
forall {x}.
PropertyParser x =>
Font'
-> Font'
-> x
-> TableOptions
-> [StyleTree (CSSBox x)]
-> LayoutItem Length Length x
finalizeTable Font'
root Font'
parent x
forall a. PropertyParser a => a
temp TableOptions
tOpts [StyleTree (CSSBox x)]
tableLayoutItem Length Length x
-> [LayoutItem Length Length x] -> [LayoutItem Length Length x]
forall a. a -> [a] -> [a]
:
Font'
-> Font'
-> CSSBox x
-> [StyleTree (CSSBox x)]
-> [LayoutItem Length Length x]
forall x.
PropertyParser x =>
Font'
-> Font'
-> CSSBox x
-> [StyleTree (CSSBox x)]
-> [LayoutItem Length Length x]
finalizeChilds Font'
root Font'
parent CSSBox x
style' [StyleTree (CSSBox x)]
rest
| (StyleTree (CSSBox x)
child:[StyleTree (CSSBox x)]
childs') <- [StyleTree (CSSBox x)]
childs = Font'
-> Font' -> StyleTree (CSSBox x) -> LayoutItem Length Length x
forall x.
PropertyParser x =>
Font'
-> Font' -> StyleTree (CSSBox x) -> LayoutItem Length Length x
finalizeCSS Font'
root Font'
parent StyleTree (CSSBox x)
childLayoutItem Length Length x
-> [LayoutItem Length Length x] -> [LayoutItem Length Length x]
forall a. a -> [a] -> [a]
:
Font'
-> Font'
-> CSSBox x
-> [StyleTree (CSSBox x)]
-> [LayoutItem Length Length x]
forall x.
PropertyParser x =>
Font'
-> Font'
-> CSSBox x
-> [StyleTree (CSSBox x)]
-> [LayoutItem Length Length x]
finalizeChilds Font'
root Font'
parent CSSBox x
style' [StyleTree (CSSBox x)]
childs'
| Bool
otherwise = []
where
([StyleTree (CSSBox x)]
table, [StyleTree (CSSBox x)]
rest) = (StyleTree (CSSBox x) -> Bool)
-> [StyleTree (CSSBox x)]
-> ([StyleTree (CSSBox x)], [StyleTree (CSSBox x)])
forall a. (a -> Bool) -> [a] -> ([a], [a])
span StyleTree (CSSBox x) -> Bool
forall {a}. StyleTree (CSSBox a) -> Bool
isTable [StyleTree (CSSBox x)]
childs
isTable :: StyleTree (CSSBox a) -> Bool
isTable (StyleTree CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableRow } [StyleTree (CSSBox a)]
_) = Bool
True
isTable (StyleTree CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableHeaderGroup } [StyleTree (CSSBox a)]
_) = Bool
True
isTable (StyleTree CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableRowGroup } [StyleTree (CSSBox a)]
_) = Bool
True
isTable (StyleTree CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableFooterGroup } [StyleTree (CSSBox a)]
_) = Bool
True
isTable (StyleTree CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableCell } [StyleTree (CSSBox a)]
_) = Bool
True
isTable (StyleTree CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableColumn } [StyleTree (CSSBox a)]
_) = Bool
True
isTable (StyleTree CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableColumnGroup } [StyleTree (CSSBox a)]
_) = Bool
True
isTable StyleTree (CSSBox a)
_ = Bool
False
finalizeBox :: CSSBox a -> Font' -> PaddedBox Length Length
finalizeBox self :: CSSBox a
self@CSSBox { cssBox :: forall a. CSSBox a -> PaddedBox Unitted Unitted
cssBox = PaddedBox Unitted Unitted
box } Font'
font_ =
(Unitted -> Length)
-> PaddedBox Unitted Length -> PaddedBox Length Length
forall m mm n. (m -> mm) -> PaddedBox m n -> PaddedBox mm n
mapY' ((Unitted -> Font' -> Length) -> Font' -> Unitted -> Length
forall a b c. (a -> b -> c) -> b -> a -> c
flip Unitted -> Font' -> Length
finalizeLength Font'
font_) (PaddedBox Unitted Length -> PaddedBox Length Length)
-> PaddedBox Unitted Length -> PaddedBox Length Length
forall a b. (a -> b) -> a -> b
$ (Unitted -> Length)
-> PaddedBox Unitted Unitted -> PaddedBox Unitted Length
forall n nn m. (n -> nn) -> PaddedBox m n -> PaddedBox m nn
mapX' ((Unitted -> Font' -> Length) -> Font' -> Unitted -> Length
forall a b c. (a -> b -> c) -> b -> a -> c
flip Unitted -> Font' -> Length
finalizeLength Font'
font_) PaddedBox Unitted Unitted
box
finalizeTable :: Font'
-> Font'
-> x
-> TableOptions
-> [StyleTree (CSSBox x)]
-> LayoutItem Length Length x
finalizeTable Font'
root Font'
parent x
val TableOptions
opts [StyleTree (CSSBox x)]
childs = x
-> Grid Length Length
-> [GridItem]
-> [LayoutItem Length Length x]
-> LayoutItem Length Length x
forall m n x.
x
-> Grid m n -> [GridItem] -> [LayoutItem m n x] -> LayoutItem m n x
LayoutGrid x
val Grid Length Length
grid [GridItem]
cells' [LayoutItem Length Length x]
childs'
where
grid :: Grid Length Length
grid = Track {
cells :: [Either Length Double]
cells = Int -> Either Length Double -> [Either Length Double]
forall a. Int -> a -> [a]
replicate Int
width (Either Length Double -> [Either Length Double])
-> Either Length Double -> [Either Length Double]
forall a b. (a -> b) -> a -> b
$ Length -> Either Length Double
forall a b. a -> Either a b
Left Length
Auto,
gap :: Length
gap = Length
hGap,
trackMins :: [Double]
trackMins = [], trackNats :: [Double]
trackNats = []
} Track Length -> Track Length -> Grid Length Length
forall m n. n -> m -> Size m n
`Size` Track {
cells :: [Either Length Double]
cells = Int -> Either Length Double -> [Either Length Double]
forall a. Int -> a -> [a]
replicate Int
height (Either Length Double -> [Either Length Double])
-> Either Length Double -> [Either Length Double]
forall a b. (a -> b) -> a -> b
$ Length -> Either Length Double
forall a b. a -> Either a b
Left Length
Auto,
gap :: Length
gap = Length
yGap,
trackMins :: [Double]
trackMins = [], trackNats :: [Double]
trackNats = []
}
([GridItem]
cells', [LayoutItem Length Length x]
childs') = [(GridItem, LayoutItem Length Length x)]
-> ([GridItem], [LayoutItem Length Length x])
forall a b. [(a, b)] -> ([a], [b])
unzip ([(GridItem, LayoutItem Length Length x)]
decor [(GridItem, LayoutItem Length Length x)]
-> [(GridItem, LayoutItem Length Length x)]
-> [(GridItem, LayoutItem Length Length x)]
forall a. [a] -> [a] -> [a]
++ [(GridItem, LayoutItem Length Length x)]
cells)
(Length
hGap, Length
yGap) = TableOptions -> Font' -> (Length, Length)
finalizeGap TableOptions
opts Font'
parent
([(GridItem, LayoutItem Length Length x)]
cells, Int
width, Int
height) = [StyleTree (CSSBox x)]
-> Int
-> [Int]
-> ([(GridItem, LayoutItem Length Length x)], Int, Int)
forall {a}.
PropertyParser a =>
[StyleTree (CSSBox a)]
-> Int
-> [Int]
-> ([(GridItem, LayoutItem Length Length a)], Int, Int)
lowerCells [StyleTree (CSSBox x)]
childs Int
0 [Int]
emptyRow
decor :: [(GridItem, LayoutItem Length Length x)]
decor = [StyleTree (CSSBox x)]
-> Int -> Int -> [(GridItem, LayoutItem Length Length x)]
forall {a}.
PropertyParser a =>
[StyleTree (CSSBox a)]
-> Int -> Int -> [(GridItem, LayoutItem Length Length a)]
decorateRow [StyleTree (CSSBox x)]
childs Int
width Int
0 [(GridItem, LayoutItem Length Length x)]
-> [(GridItem, LayoutItem Length Length x)]
-> [(GridItem, LayoutItem Length Length x)]
forall a. [a] -> [a] -> [a]
++ [StyleTree (CSSBox x)]
-> Int -> Int -> [(GridItem, LayoutItem Length Length x)]
forall {a}.
PropertyParser a =>
[StyleTree (CSSBox a)]
-> Int -> Int -> [(GridItem, LayoutItem Length Length a)]
decorateCol [StyleTree (CSSBox x)]
childs Int
height Int
0
lowerCells :: [StyleTree (CSSBox a)]
-> Int
-> [Int]
-> ([(GridItem, LayoutItem Length Length a)], Int, Int)
lowerCells (StyleTree self :: CSSBox a
self@CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableRow } [StyleTree (CSSBox a)]
cells:[StyleTree (CSSBox a)]
rest) Int
h [Int]
x =
([(GridItem, LayoutItem Length Length a)]
row [(GridItem, LayoutItem Length Length a)]
-> [(GridItem, LayoutItem Length Length a)]
-> [(GridItem, LayoutItem Length Length a)]
forall a. [a] -> [a] -> [a]
++ [(GridItem, LayoutItem Length Length a)]
rows, Int -> Int -> Int
forall a. Ord a => a -> a -> a
Prelude.max Int
rowwidth Int
width', Int
height')
where
([(GridItem, LayoutItem Length Length a)]
row, Int
rowwidth, [Int]
x') = [StyleTree (CSSBox a)]
-> Int
-> Int
-> [Int]
-> ([(GridItem, LayoutItem Length Length a)], Int, [Int])
forall {a}.
PropertyParser a =>
[StyleTree (CSSBox a)]
-> Int
-> Int
-> [Int]
-> ([(GridItem, LayoutItem Length Length a)], Int, [Int])
lowerRow [StyleTree (CSSBox a)]
cells Int
0 Int
h [Int]
x
([(GridItem, LayoutItem Length Length a)]
rows, Int
width', Int
height') = [StyleTree (CSSBox a)]
-> Int
-> [Int]
-> ([(GridItem, LayoutItem Length Length a)], Int, Int)
lowerCells [StyleTree (CSSBox a)]
rest (Int -> Int
forall a. Enum a => a -> a
succ Int
h) ([Int] -> ([(GridItem, LayoutItem Length Length a)], Int, Int))
-> [Int] -> ([(GridItem, LayoutItem Length Length a)], Int, Int)
forall a b. (a -> b) -> a -> b
$ [Int] -> [Int]
commitRow [Int]
x'
lowerCells (StyleTree CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableHeaderGroup } [StyleTree (CSSBox a)]
childs:[StyleTree (CSSBox a)]
rest) Int
h [Int]
x =
[StyleTree (CSSBox a)]
-> Int
-> [Int]
-> ([(GridItem, LayoutItem Length Length a)], Int, Int)
lowerCells ([StyleTree (CSSBox a)]
childs [StyleTree (CSSBox a)]
-> [StyleTree (CSSBox a)] -> [StyleTree (CSSBox a)]
forall a. [a] -> [a] -> [a]
++ [StyleTree (CSSBox a)]
rest) Int
h [Int]
x
lowerCells (StyleTree CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableFooterGroup } [StyleTree (CSSBox a)]
childs:[StyleTree (CSSBox a)]
rest) Int
h [Int]
x =
[StyleTree (CSSBox a)]
-> Int
-> [Int]
-> ([(GridItem, LayoutItem Length Length a)], Int, Int)
lowerCells ([StyleTree (CSSBox a)]
childs [StyleTree (CSSBox a)]
-> [StyleTree (CSSBox a)] -> [StyleTree (CSSBox a)]
forall a. [a] -> [a] -> [a]
++ [StyleTree (CSSBox a)]
rest) Int
h [Int]
x
lowerCells (StyleTree CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableRowGroup } [StyleTree (CSSBox a)]
childs:[StyleTree (CSSBox a)]
rest) Int
h [Int]
x =
[StyleTree (CSSBox a)]
-> Int
-> [Int]
-> ([(GridItem, LayoutItem Length Length a)], Int, Int)
lowerCells ([StyleTree (CSSBox a)]
childs [StyleTree (CSSBox a)]
-> [StyleTree (CSSBox a)] -> [StyleTree (CSSBox a)]
forall a. [a] -> [a] -> [a]
++ [StyleTree (CSSBox a)]
rest) Int
h [Int]
x
lowerCells (StyleTree CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableColumnGroup } [StyleTree (CSSBox a)]
_:[StyleTree (CSSBox a)]
rest) Int
h [Int]
x =
[StyleTree (CSSBox a)]
-> Int
-> [Int]
-> ([(GridItem, LayoutItem Length Length a)], Int, Int)
lowerCells [StyleTree (CSSBox a)]
rest Int
h [Int]
x
lowerCells (StyleTree CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableColumn } [StyleTree (CSSBox a)]
_:[StyleTree (CSSBox a)]
rest) Int
h [Int]
x =
[StyleTree (CSSBox a)]
-> Int
-> [Int]
-> ([(GridItem, LayoutItem Length Length a)], Int, Int)
lowerCells [StyleTree (CSSBox a)]
rest Int
h [Int]
x
lowerCells (StyleTree CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableCaption } [StyleTree (CSSBox a)]
_:[StyleTree (CSSBox a)]
rest) Int
h [Int]
x =
[StyleTree (CSSBox a)]
-> Int
-> [Int]
-> ([(GridItem, LayoutItem Length Length a)], Int, Int)
lowerCells [StyleTree (CSSBox a)]
rest Int
h [Int]
x
lowerCells [] Int
h [Int]
_ = ([], Int
0, Int
h)
lowerCells [StyleTree (CSSBox a)]
items Int
h [Int]
x = ([(GridItem, LayoutItem Length Length a)]
row [(GridItem, LayoutItem Length Length a)]
-> [(GridItem, LayoutItem Length Length a)]
-> [(GridItem, LayoutItem Length Length a)]
forall a. [a] -> [a] -> [a]
++ [(GridItem, LayoutItem Length Length a)]
rows, Int -> Int -> Int
forall a. Ord a => a -> a -> a
Prelude.max Int
rowwidth Int
width', Int
height')
where
([StyleTree (CSSBox a)]
cells, [StyleTree (CSSBox a)]
rest) = (StyleTree (CSSBox a) -> Bool)
-> [StyleTree (CSSBox a)]
-> ([StyleTree (CSSBox a)], [StyleTree (CSSBox a)])
forall a. (a -> Bool) -> [a] -> ([a], [a])
break StyleTree (CSSBox a) -> Bool
forall {a}. StyleTree (CSSBox a) -> Bool
isRowGroup [StyleTree (CSSBox a)]
items
([(GridItem, LayoutItem Length Length a)]
row, Int
rowwidth, [Int]
x') = [StyleTree (CSSBox a)]
-> Int
-> Int
-> [Int]
-> ([(GridItem, LayoutItem Length Length a)], Int, [Int])
forall {a}.
PropertyParser a =>
[StyleTree (CSSBox a)]
-> Int
-> Int
-> [Int]
-> ([(GridItem, LayoutItem Length Length a)], Int, [Int])
lowerRow [StyleTree (CSSBox a)]
cells Int
0 Int
h [Int]
x
([(GridItem, LayoutItem Length Length a)]
rows, Int
width', Int
height') = [StyleTree (CSSBox a)]
-> Int
-> [Int]
-> ([(GridItem, LayoutItem Length Length a)], Int, Int)
lowerCells [StyleTree (CSSBox a)]
rest (Int -> Int
forall a. Enum a => a -> a
succ Int
h) ([Int] -> ([(GridItem, LayoutItem Length Length a)], Int, Int))
-> [Int] -> ([(GridItem, LayoutItem Length Length a)], Int, Int)
forall a b. (a -> b) -> a -> b
$ [Int] -> [Int]
commitRow [Int]
x'
lowerRow :: [StyleTree (CSSBox a)]
-> Int
-> Int
-> [Int]
-> ([(GridItem, LayoutItem Length Length a)], Int, [Int])
lowerRow (StyleTree self :: CSSBox a
self@CSSBox {
display :: forall a. CSSBox a -> Display
display = Display
TableCell, tableOptions :: forall a. CSSBox a -> TableOptions
tableOptions = TableOptions
self' } [StyleTree (CSSBox a)]
childs:[StyleTree (CSSBox a)]
rest) Int
ix Int
row [Int]
x =
((GridItem, LayoutItem Length Length a)
cell(GridItem, LayoutItem Length Length a)
-> [(GridItem, LayoutItem Length Length a)]
-> [(GridItem, LayoutItem Length Length a)]
forall a. a -> [a] -> [a]
:[(GridItem, LayoutItem Length Length a)]
cells, Int
width, [Int]
x')
where
([(GridItem, LayoutItem Length Length a)]
cells, Int
width, [Int]
x') = [StyleTree (CSSBox a)]
-> Int
-> Int
-> [Int]
-> ([(GridItem, LayoutItem Length Length a)], Int, [Int])
lowerRow [StyleTree (CSSBox a)]
rest Int
end Int
row ([Int] -> ([(GridItem, LayoutItem Length Length a)], Int, [Int]))
-> [Int] -> ([(GridItem, LayoutItem Length Length a)], Int, [Int])
forall a b. (a -> b) -> a -> b
$
Int -> Int -> Int -> [Int] -> [Int]
insertCell Int
start (TableOptions -> Int
colspan TableOptions
self') (TableOptions -> Int
rowspan TableOptions
self') [Int]
x
start :: Int
start = Int -> [Int] -> Int
allocCol Int
ix [Int]
x
end :: Int
end = Int
start Int -> Int -> Int
forall a. Num a => a -> a -> a
+ TableOptions -> Int
colspan TableOptions
self'
cell :: (GridItem, LayoutItem Length Length a)
cell = (Int -> Int -> Alignment -> Double -> Double -> GridItem'
GridItem Int
start Int
end Alignment
Start Double
0 Double
0
GridItem' -> GridItem' -> GridItem
forall m n. n -> m -> Size m n
`Size` Int -> Int -> Alignment -> Double -> Double -> GridItem'
GridItem Int
row (Int
row Int -> Int -> Int
forall a. Num a => a -> a -> a
+ TableOptions -> Int
rowspan TableOptions
self') Alignment
valign Double
0 Double
0,
Font'
-> Font' -> StyleTree (CSSBox a) -> LayoutItem Length Length a
forall x.
PropertyParser x =>
Font'
-> Font' -> StyleTree (CSSBox x) -> LayoutItem Length Length x
finalizeCSS Font'
root Font'
parent (StyleTree (CSSBox a) -> LayoutItem Length Length a)
-> StyleTree (CSSBox a) -> LayoutItem Length Length a
forall a b. (a -> b) -> a -> b
$ CSSBox a -> [StyleTree (CSSBox a)] -> StyleTree (CSSBox a)
forall p. p -> [StyleTree p] -> StyleTree p
StyleTree CSSBox a
self { display :: Display
display = Display
Block } [StyleTree (CSSBox a)]
childs)
valign :: Alignment
valign = TableOptions -> Alignment
finalizeVAlign TableOptions
self'
halign :: Alignment
halign = ParagraphOptions -> Direction -> Alignment
finalizeHAlign (CSSBox a -> ParagraphOptions
forall a. CSSBox a -> ParagraphOptions
paragraphOptions CSSBox a
self) (CSSBox a -> Direction
forall {a}. CSSBox a -> Direction
direction CSSBox a
self)
lowerRow (StyleTree (CSSBox a)
self:[StyleTree (CSSBox a)]
rest) Int
ix Int
row [Int]
x = ((GridItem, LayoutItem Length Length a)
cell(GridItem, LayoutItem Length Length a)
-> [(GridItem, LayoutItem Length Length a)]
-> [(GridItem, LayoutItem Length Length a)]
forall a. a -> [a] -> [a]
:[(GridItem, LayoutItem Length Length a)]
cells, Int
width, [Int]
x')
where
ix' :: Int
ix' = Int -> [Int] -> Int
allocCol Int
ix [Int]
x
([(GridItem, LayoutItem Length Length a)]
cells, Int
width, [Int]
x') = [StyleTree (CSSBox a)]
-> Int
-> Int
-> [Int]
-> ([(GridItem, LayoutItem Length Length a)], Int, [Int])
lowerRow [StyleTree (CSSBox a)]
rest (Int -> Int
forall a. Enum a => a -> a
succ Int
ix') Int
row ([Int] -> ([(GridItem, LayoutItem Length Length a)], Int, [Int]))
-> [Int] -> ([(GridItem, LayoutItem Length Length a)], Int, [Int])
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int -> [Int] -> [Int]
insertCell Int
ix' Int
1 Int
1 [Int]
x
cell :: (GridItem, LayoutItem Length Length a)
cell = (Int -> Int -> Alignment -> Double -> Double -> GridItem'
GridItem Int
ix' (Int -> Int
forall a. Enum a => a -> a
succ Int
ix') Alignment
Start Double
0 Double
0
GridItem' -> GridItem' -> GridItem
forall m n. n -> m -> Size m n
`Size` Int -> Int -> Alignment -> Double -> Double -> GridItem'
GridItem Int
row (Int -> Int
forall a. Enum a => a -> a
succ Int
row) Alignment
Start Double
0 Double
0,
Font'
-> Font' -> StyleTree (CSSBox a) -> LayoutItem Length Length a
forall x.
PropertyParser x =>
Font'
-> Font' -> StyleTree (CSSBox x) -> LayoutItem Length Length x
finalizeCSS Font'
root Font'
parent StyleTree (CSSBox a)
self {
style :: CSSBox a
style = (StyleTree (CSSBox a) -> CSSBox a
forall p. StyleTree p -> p
style StyleTree (CSSBox a)
self) {
cssBox :: PaddedBox Unitted Unitted
cssBox = TableOptions
-> PaddedBox Unitted Unitted -> PaddedBox Unitted Unitted
collapseBorders TableOptions
opts (PaddedBox Unitted Unitted -> PaddedBox Unitted Unitted)
-> PaddedBox Unitted Unitted -> PaddedBox Unitted Unitted
forall a b. (a -> b) -> a -> b
$ CSSBox a -> PaddedBox Unitted Unitted
forall a. CSSBox a -> PaddedBox Unitted Unitted
cssBox (CSSBox a -> PaddedBox Unitted Unitted)
-> CSSBox a -> PaddedBox Unitted Unitted
forall a b. (a -> b) -> a -> b
$ StyleTree (CSSBox a) -> CSSBox a
forall p. StyleTree p -> p
style StyleTree (CSSBox a)
self
}
})
lowerRow [] Int
ix Int
_ [Int]
x = ([], Int
ix, [Int]
x)
decorateRow :: [StyleTree (CSSBox a)]
-> Int -> Int -> [(GridItem, LayoutItem Length Length a)]
decorateRow (StyleTree self :: CSSBox a
self@CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableRow } [StyleTree (CSSBox a)]
_:[StyleTree (CSSBox a)]
rest) Int
w Int
row =
CSSBox a
-> Int
-> Int
-> Int
-> Int
-> (GridItem, LayoutItem Length Length a)
forall {x}.
PropertyParser x =>
CSSBox x
-> Int
-> Int
-> Int
-> Int
-> (GridItem, LayoutItem Length Length x)
buildDecor CSSBox a
self Int
0 Int
w Int
row Int
1(GridItem, LayoutItem Length Length a)
-> [(GridItem, LayoutItem Length Length a)]
-> [(GridItem, LayoutItem Length Length a)]
forall a. a -> [a] -> [a]
:[StyleTree (CSSBox a)]
-> Int -> Int -> [(GridItem, LayoutItem Length Length a)]
decorateRow [StyleTree (CSSBox a)]
rest Int
w (Int -> Int
forall a. Enum a => a -> a
succ Int
row)
decorateRow (StyleTree self :: CSSBox a
self@CSSBox { display :: forall a. CSSBox a -> Display
display = Display
d } [StyleTree (CSSBox a)]
childs:[StyleTree (CSSBox a)]
rest) Int
w Int
row
| Display
d Display -> [Display] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Display
TableHeaderGroup, Display
TableFooterGroup, Display
TableRowGroup] =
CSSBox a
-> Int
-> Int
-> Int
-> Int
-> (GridItem, LayoutItem Length Length a)
forall {x}.
PropertyParser x =>
CSSBox x
-> Int
-> Int
-> Int
-> Int
-> (GridItem, LayoutItem Length Length x)
buildDecor CSSBox a
self Int
0 Int
w Int
row ([StyleTree (CSSBox a)] -> Int
forall {a} {a}. (Enum a, Num a) => [StyleTree (CSSBox a)] -> a
countRows [StyleTree (CSSBox a)]
childs)(GridItem, LayoutItem Length Length a)
-> [(GridItem, LayoutItem Length Length a)]
-> [(GridItem, LayoutItem Length Length a)]
forall a. a -> [a] -> [a]
:
[StyleTree (CSSBox a)]
-> Int -> Int -> [(GridItem, LayoutItem Length Length a)]
decorateRow ([StyleTree (CSSBox a)]
childs [StyleTree (CSSBox a)]
-> [StyleTree (CSSBox a)] -> [StyleTree (CSSBox a)]
forall a. [a] -> [a] -> [a]
++ [StyleTree (CSSBox a)]
rest) Int
w (Int
row Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [StyleTree (CSSBox a)] -> Int
forall {a} {a}. (Enum a, Num a) => [StyleTree (CSSBox a)] -> a
countRows [StyleTree (CSSBox a)]
childs)
| Display
d Display -> [Display] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Display
TableCaption, Display
TableColumn, Display
TableColumnGroup] =
[StyleTree (CSSBox a)]
-> Int -> Int -> [(GridItem, LayoutItem Length Length a)]
decorateRow [StyleTree (CSSBox a)]
rest Int
w Int
row
| Bool
otherwise = [StyleTree (CSSBox a)]
-> Int -> Int -> [(GridItem, LayoutItem Length Length a)]
decorateRow ((StyleTree (CSSBox a) -> Bool)
-> [StyleTree (CSSBox a)] -> [StyleTree (CSSBox a)]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile (Bool -> Bool
not (Bool -> Bool)
-> (StyleTree (CSSBox a) -> Bool) -> StyleTree (CSSBox a) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StyleTree (CSSBox a) -> Bool
forall {a}. StyleTree (CSSBox a) -> Bool
isRowGroup) [StyleTree (CSSBox a)]
rest) Int
w(Int -> [(GridItem, LayoutItem Length Length a)])
-> Int -> [(GridItem, LayoutItem Length Length a)]
forall a b. (a -> b) -> a -> b
$Int -> Int
forall a. Enum a => a -> a
succ Int
row
decorateRow [] Int
_ Int
_ = []
decorateCol :: [StyleTree (CSSBox a)]
-> Int -> Int -> [(GridItem, LayoutItem Length Length a)]
decorateCol (StyleTree self :: CSSBox a
self@CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableColumn } [StyleTree (CSSBox a)]
_:[StyleTree (CSSBox a)]
rest) Int
h Int
col =
CSSBox a
-> Int
-> Int
-> Int
-> Int
-> (GridItem, LayoutItem Length Length a)
forall {x}.
PropertyParser x =>
CSSBox x
-> Int
-> Int
-> Int
-> Int
-> (GridItem, LayoutItem Length Length x)
buildDecor CSSBox a
self Int
col Int
1 Int
0 Int
h(GridItem, LayoutItem Length Length a)
-> [(GridItem, LayoutItem Length Length a)]
-> [(GridItem, LayoutItem Length Length a)]
forall a. a -> [a] -> [a]
:[StyleTree (CSSBox a)]
-> Int -> Int -> [(GridItem, LayoutItem Length Length a)]
decorateCol [StyleTree (CSSBox a)]
rest Int
h (Int -> Int
forall a. Enum a => a -> a
succ Int
col)
decorateCol (StyleTree self :: CSSBox a
self@CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableColumnGroup } [StyleTree (CSSBox a)]
childs:[StyleTree (CSSBox a)]
rest)
Int
h Int
col = CSSBox a
-> Int
-> Int
-> Int
-> Int
-> (GridItem, LayoutItem Length Length a)
forall {x}.
PropertyParser x =>
CSSBox x
-> Int
-> Int
-> Int
-> Int
-> (GridItem, LayoutItem Length Length x)
buildDecor CSSBox a
self Int
col ([StyleTree (CSSBox a)] -> CSSBox a -> Int
forall {a} {a}. [StyleTree (CSSBox a)] -> CSSBox a -> Int
countCols' [StyleTree (CSSBox a)]
childs CSSBox a
self) Int
0 Int
h(GridItem, LayoutItem Length Length a)
-> [(GridItem, LayoutItem Length Length a)]
-> [(GridItem, LayoutItem Length Length a)]
forall a. a -> [a] -> [a]
:
[StyleTree (CSSBox a)]
-> Int -> Int -> [(GridItem, LayoutItem Length Length a)]
decorateCol ([StyleTree (CSSBox a)]
childs [StyleTree (CSSBox a)]
-> [StyleTree (CSSBox a)] -> [StyleTree (CSSBox a)]
forall a. [a] -> [a] -> [a]
++ [StyleTree (CSSBox a)]
rest) Int
h (Int
col Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [StyleTree (CSSBox a)] -> CSSBox a -> Int
forall {a} {a}. [StyleTree (CSSBox a)] -> CSSBox a -> Int
countCols' [StyleTree (CSSBox a)]
childs CSSBox a
self)
decorateCol (StyleTree (CSSBox a)
_:[StyleTree (CSSBox a)]
rest) Int
h Int
col = [StyleTree (CSSBox a)]
-> Int -> Int -> [(GridItem, LayoutItem Length Length a)]
decorateCol [StyleTree (CSSBox a)]
rest Int
h Int
col
decorateCol [] Int
_ Int
_ = []
countRows :: [StyleTree (CSSBox a)] -> a
countRows (StyleTree CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableRow } [StyleTree (CSSBox a)]
_:[StyleTree (CSSBox a)]
rest) =
a -> a
forall a. Enum a => a -> a
succ (a -> a) -> a -> a
forall a b. (a -> b) -> a -> b
$ [StyleTree (CSSBox a)] -> a
countRows [StyleTree (CSSBox a)]
rest
countRows (StyleTree CSSBox { display :: forall a. CSSBox a -> Display
display = Display
d } [StyleTree (CSSBox a)]
childs:[StyleTree (CSSBox a)]
rest)
| Display
d Display -> [Display] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Display
TableHeaderGroup, Display
TableFooterGroup, Display
TableRowGroup] =
[StyleTree (CSSBox a)] -> a
countRows [StyleTree (CSSBox a)]
childs a -> a -> a
forall a. Num a => a -> a -> a
+ [StyleTree (CSSBox a)] -> a
countRows [StyleTree (CSSBox a)]
rest
| Display
d Display -> [Display] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Display
TableCaption, Display
TableColumn, Display
TableColumnGroup] = [StyleTree (CSSBox a)] -> a
countRows [StyleTree (CSSBox a)]
rest
| Bool
otherwise = a -> a
forall a. Enum a => a -> a
succ (a -> a) -> a -> a
forall a b. (a -> b) -> a -> b
$ [StyleTree (CSSBox a)] -> a
countRows ([StyleTree (CSSBox a)] -> a) -> [StyleTree (CSSBox a)] -> a
forall a b. (a -> b) -> a -> b
$ (StyleTree (CSSBox a) -> Bool)
-> [StyleTree (CSSBox a)] -> [StyleTree (CSSBox a)]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile (Bool -> Bool
not (Bool -> Bool)
-> (StyleTree (CSSBox a) -> Bool) -> StyleTree (CSSBox a) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StyleTree (CSSBox a) -> Bool
forall {a}. StyleTree (CSSBox a) -> Bool
isRowGroup) [StyleTree (CSSBox a)]
rest
countRows [] = a
0
countCols' :: [StyleTree (CSSBox a)] -> CSSBox a -> Int
countCols' cols :: [StyleTree (CSSBox a)]
cols@(StyleTree (CSSBox a)
_:[StyleTree (CSSBox a)]
_) CSSBox a
_ = [StyleTree (CSSBox a)] -> Int
forall {a}. [StyleTree (CSSBox a)] -> Int
countCols [StyleTree (CSSBox a)]
cols
countCols' [StyleTree (CSSBox a)]
_ CSSBox { tableOptions :: forall a. CSSBox a -> TableOptions
tableOptions = TableOptions { colspan :: TableOptions -> Int
colspan = Int
x } } = Int
x
countCols :: [StyleTree (CSSBox a)] -> Int
countCols (StyleTree CSSBox {
display :: forall a. CSSBox a -> Display
display = Display
TableColumn,
tableOptions :: forall a. CSSBox a -> TableOptions
tableOptions = TableOptions { colspan :: TableOptions -> Int
colspan = Int
x }
} [StyleTree (CSSBox a)]
_:[StyleTree (CSSBox a)]
rest) = Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [StyleTree (CSSBox a)] -> Int
countCols [StyleTree (CSSBox a)]
rest
countCols (StyleTree CSSBox {
display :: forall a. CSSBox a -> Display
display = Display
TableColumnGroup,
tableOptions :: forall a. CSSBox a -> TableOptions
tableOptions = TableOptions { colspan :: TableOptions -> Int
colspan = Int
x }
} []:[StyleTree (CSSBox a)]
rest) = Int
x Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [StyleTree (CSSBox a)] -> Int
countCols [StyleTree (CSSBox a)]
rest
countCols (StyleTree CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableColumnGroup } [StyleTree (CSSBox a)]
childs:[StyleTree (CSSBox a)]
rest) =
[StyleTree (CSSBox a)] -> Int
countCols [StyleTree (CSSBox a)]
childs Int -> Int -> Int
forall a. Num a => a -> a -> a
+ [StyleTree (CSSBox a)] -> Int
countCols [StyleTree (CSSBox a)]
rest
countCols (StyleTree (CSSBox a)
_:[StyleTree (CSSBox a)]
rest) = [StyleTree (CSSBox a)] -> Int
countCols [StyleTree (CSSBox a)]
rest
countCols [] = Int
0
buildDecor :: CSSBox x
-> Int
-> Int
-> Int
-> Int
-> (GridItem, LayoutItem Length Length x)
buildDecor CSSBox x
self Int
col Int
colspan Int
row Int
rowspan =
(Int -> Int -> Alignment -> Double -> Double -> GridItem'
GridItem Int
col (Int
col Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
colspan) Alignment
Start Double
0 Double
0 GridItem' -> GridItem' -> GridItem
forall m n. n -> m -> Size m n
`Size`
Int -> Int -> Alignment -> Double -> Double -> GridItem'
GridItem Int
row (Int
row Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
rowspan) Alignment
Start Double
0 Double
0,
Font'
-> Font' -> StyleTree (CSSBox x) -> LayoutItem Length Length x
forall x.
PropertyParser x =>
Font'
-> Font' -> StyleTree (CSSBox x) -> LayoutItem Length Length x
finalizeCSS Font'
root Font'
parent (StyleTree (CSSBox x) -> LayoutItem Length Length x)
-> StyleTree (CSSBox x) -> LayoutItem Length Length x
forall a b. (a -> b) -> a -> b
$ CSSBox x -> [StyleTree (CSSBox x)] -> StyleTree (CSSBox x)
forall p. p -> [StyleTree p] -> StyleTree p
StyleTree CSSBox x
self {
display :: Display
display = Display
Block, cssBox :: PaddedBox Unitted Unitted
cssBox = TableOptions
-> PaddedBox Unitted Unitted -> PaddedBox Unitted Unitted
collapseBorders TableOptions
opts (PaddedBox Unitted Unitted -> PaddedBox Unitted Unitted)
-> PaddedBox Unitted Unitted -> PaddedBox Unitted Unitted
forall a b. (a -> b) -> a -> b
$ CSSBox x -> PaddedBox Unitted Unitted
forall a. CSSBox a -> PaddedBox Unitted Unitted
cssBox CSSBox x
self
} [])
isRowGroup :: StyleTree (CSSBox a) -> Bool
isRowGroup (StyleTree CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableRow } [StyleTree (CSSBox a)]
_) = Bool
True
isRowGroup (StyleTree CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableHeaderGroup } [StyleTree (CSSBox a)]
_) = Bool
True
isRowGroup (StyleTree CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableFooterGroup } [StyleTree (CSSBox a)]
_) = Bool
True
isRowGroup (StyleTree CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableRowGroup } [StyleTree (CSSBox a)]
_) = Bool
True
isRowGroup (StyleTree CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableCaption } [StyleTree (CSSBox a)]
_) = Bool
True
isRowGroup (StyleTree CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableColumn } [StyleTree (CSSBox a)]
_) = Bool
True
isRowGroup (StyleTree CSSBox { display :: forall a. CSSBox a -> Display
display = Display
TableColumnGroup } [StyleTree (CSSBox a)]
_) = Bool
True
isRowGroup StyleTree (CSSBox a)
_ = Bool
False
collapseTBorders' :: CSSBox x -> CSSBox x
collapseTBorders' :: forall x. CSSBox x -> CSSBox x
collapseTBorders' CSSBox x
self = CSSBox x
self {
cssBox :: PaddedBox Unitted Unitted
cssBox = TableOptions
-> PaddedBox Unitted Unitted -> PaddedBox Unitted Unitted
collapseTBorders (CSSBox x -> TableOptions
forall a. CSSBox a -> TableOptions
tableOptions CSSBox x
self) (CSSBox x -> PaddedBox Unitted Unitted
forall a. CSSBox a -> PaddedBox Unitted Unitted
cssBox CSSBox x
self)
}