-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Lays out boxes according to the CSS Box Model. -- -- Computes where to place e.g. images, paragraphs, containers, tables, -- etc onscreen given desired amounts of whitespace. @package cattrap @version 0.5.0.0 -- | (Unused) Parses & evaluates calc() expressions. Implemented using -- The Shunting Yard Algorithm. module Graphics.Layout.Arithmetic -- | Parsed calc() expression. As a postfix arithmatic expression. data Opcode n Seq :: Opcode n Add :: Opcode n Subtract :: Opcode n Multiply :: Opcode n Divide :: Opcode n Func :: Text -> Opcode n Num :: n -> Opcode n -- | Parse a calc() expression. parseCalc :: [Token] -> [Opcode (Float, String)] -> [Opcode (Float, String)] -- | Verify that a parsed math expression can be properly evaluated. verifyCalc :: [Opcode (Float, String)] -> [Bool] -> Bool -- | Evaluate a parsed calc() expression. evalCalc :: [Opcode Float] -> [Float] -> Float -- | Convert all numbers in an expression via the given callback. mapCalc :: (a -> b) -> [Opcode a] -> [Opcode b] instance GHC.Show.Show n => GHC.Show.Show (Graphics.Layout.Arithmetic.Opcode n) -- | Datastructures representing the CSS box model, & utilities for -- operating on them. module Graphics.Layout.Box -- | Amount of space surrounding the box. data Border m n Border :: m -> m -> n -> n -> Border m n [top] :: Border m n -> m [bottom] :: Border m n -> m [left] :: Border m n -> n [right] :: Border m n -> n -- | Convert horizontal spacing via given callback. mapX :: (n -> nn) -> Border m n -> Border m nn -- | Convert vertical spacing via given callback. mapY :: (m -> mm) -> Border m n -> Border mm n -- | 2D size of a box. Typically inline is width & block is height. -- This may change as support for vertical layout is added. data Size m n Size :: n -> m -> Size m n [inline] :: Size m n -> n [block] :: Size m n -> m -- | Convert block size via given callback mapSizeX :: (n -> nn) -> Size m n -> Size m nn -- | Convert inline size via given callback mapSizeY :: (m -> mm) -> Size m n -> Size mm n -- | A box with min & max bounds & surrounding borders. The CSS Box -- Model. data PaddedBox m n PaddedBox :: Size m n -> Size m n -> Size Double Double -> Size m n -> Border m n -> Border m n -> Border m n -> PaddedBox m n -- | The minimum amount of pixels this box should take. [min] :: PaddedBox m n -> Size m n -- | The maximum amount of pixels this box should take. [max] :: PaddedBox m n -> Size m n -- | The ideal number of pixels this box should take. [nat] :: PaddedBox m n -> Size Double Double -- | The amount of pixels this box should take. [size] :: PaddedBox m n -> Size m n -- | The amount of space between the box & the border. [padding] :: PaddedBox m n -> Border m n -- | The amount of space for the border. [border] :: PaddedBox m n -> Border m n -- | The amount of space between the border & anything else. [margin] :: PaddedBox m n -> Border m n -- | An empty box, takes up nospace onscreen. zeroBox :: PaddedBox Double Double -- | A box which takes up all available space with no borders. lengthBox :: PaddedBox Length Length -- | Convert all sizes along the inline axis via given callback. mapX' :: (n -> nn) -> PaddedBox m n -> PaddedBox m nn -- | Convert all sizes along the block axis via given callback. mapY' :: (m -> mm) -> PaddedBox m n -> PaddedBox mm n -- | The total size along the inline axis including borders, etc. width :: Num a => PaddedBox m a -> a -- | The total size along the block axis, including borders, etc. height :: Num a => PaddedBox a n -> a -- | The total minimum size along the inline axis. minWidth :: Num a => PaddedBox m a -> a -- | The total minimum size along the block axis. minHeight :: Num a => PaddedBox a n -> a -- | The total maximum size along the inline axis. maxWidth :: Num a => PaddedBox m a -> a -- | The total maximum size along the block axis. maxHeight :: Num a => PaddedBox a n -> a -- | Amount of whitespace to the left, summing margins, borders, & -- padding. leftSpace :: Num a => PaddedBox m a -> a -- | Amount of whitespace to the right, summing margins, borders, & -- padding. rightSpace :: Num a => PaddedBox m a -> a -- | Amount of whitespace to the top, summing margins, borders, & -- padding. topSpace :: Num a => PaddedBox a n -> a -- | Amount of whitespace to the bottom, summing margins, borders, & -- padding. bottomSpace :: Num a => PaddedBox a n -> a -- | Amount of whitespace along the x axis, summing margins, borders, & -- padding. hSpace :: Num a => PaddedBox m a -> a -- | Amount of whitespace along the y axis, summing margins, borders, & -- padding. vSpace :: Num a => PaddedBox a n -> a -- | A partially-computed length value. data Length -- | Absolute number of device pixels. Pixels :: Double -> Length -- | Multiplier by container width. Percent :: Double -> Length -- | Use normal layout computations. Auto :: Length -- | Use computed preferred width. Preferred :: Length -- | Use minimum legible width. Min :: Length -- | Replace keywords with a given number of pixels. Useful for avoiding -- messing up percentage calculations in later processing. mapAuto :: Double -> Length -> Length -- | Convert a length given the container's width. Filling in 0 for -- keywords. If you wish for keywords to be handled differently, callers -- need to compute that themselves. lowerLength :: Double -> Length -> Double -- | Typeclass for zeroing out fields, so layout primitives can be more -- reusable. class Zero a -- | Return the empty (or zero) value for a CatTrap geometric type. zero :: Zero a => a -- | Typeclass for converting between doubles & layout types, -- approximately if needs be. So layout primitives can be more reusable. class CastDouble a -- | Convert a double to a double or length. fromDouble :: CastDouble a => Double -> a -- | Convert a double or length to a double. toDouble :: CastDouble a => a -> Double toDoubleWithin :: CastDouble a => Double -> a -> Double toDoubleWithinAuto :: CastDouble a => Double -> Double -> a -> Double instance GHC.Generics.Generic (Graphics.Layout.Box.Border m n) instance (GHC.Show.Show m, GHC.Show.Show n) => GHC.Show.Show (Graphics.Layout.Box.Border m n) instance (GHC.Read.Read m, GHC.Read.Read n) => GHC.Read.Read (Graphics.Layout.Box.Border m n) instance (GHC.Classes.Eq m, GHC.Classes.Eq n) => GHC.Classes.Eq (Graphics.Layout.Box.Border m n) instance GHC.Generics.Generic (Graphics.Layout.Box.Size m n) instance (GHC.Read.Read n, GHC.Read.Read m) => GHC.Read.Read (Graphics.Layout.Box.Size m n) instance (GHC.Show.Show n, GHC.Show.Show m) => GHC.Show.Show (Graphics.Layout.Box.Size m n) instance (GHC.Classes.Eq n, GHC.Classes.Eq m) => GHC.Classes.Eq (Graphics.Layout.Box.Size m n) instance GHC.Generics.Generic (Graphics.Layout.Box.PaddedBox m n) instance (GHC.Show.Show n, GHC.Show.Show m) => GHC.Show.Show (Graphics.Layout.Box.PaddedBox m n) instance (GHC.Read.Read n, GHC.Read.Read m) => GHC.Read.Read (Graphics.Layout.Box.PaddedBox m n) instance (GHC.Classes.Eq n, GHC.Classes.Eq m) => GHC.Classes.Eq (Graphics.Layout.Box.PaddedBox m n) instance GHC.Generics.Generic Graphics.Layout.Box.Length instance GHC.Show.Show Graphics.Layout.Box.Length instance GHC.Read.Read Graphics.Layout.Box.Length instance GHC.Classes.Eq Graphics.Layout.Box.Length instance Graphics.Layout.Box.CastDouble GHC.Types.Double instance Graphics.Layout.Box.CastDouble Graphics.Layout.Box.Length instance Graphics.Layout.Box.Zero GHC.Types.Double instance Graphics.Layout.Box.Zero Graphics.Layout.Box.Length instance (Graphics.Layout.Box.Zero m, Graphics.Layout.Box.Zero n) => Graphics.Layout.Box.Zero (Graphics.Layout.Box.PaddedBox m n) instance (Graphics.Layout.Box.Zero m, Graphics.Layout.Box.Zero n) => Graphics.Layout.Box.Zero (Graphics.Layout.Box.Border m n) instance Control.DeepSeq.NFData Graphics.Layout.Box.Length instance (Control.DeepSeq.NFData m, Control.DeepSeq.NFData n) => Control.DeepSeq.NFData (Graphics.Layout.Box.PaddedBox m n) instance (Control.DeepSeq.NFData m, Control.DeepSeq.NFData n) => Control.DeepSeq.NFData (Graphics.Layout.Box.Size m n) instance (Control.DeepSeq.NFData m, Control.DeepSeq.NFData n) => Control.DeepSeq.NFData (Graphics.Layout.Box.Border m n) -- | Infrastructure for parsing & desugaring length units & -- keywords, in reference to the selected font. module Graphics.Layout.CSS.Length -- | A number+unit, prior to resolving side units. The unit may alternately -- represent a keyword, in which case the number is ignored & -- typically set to 0. type Unitted = (Double, Text) -- | The CSS auto keyword. auto :: Unitted -- | Parse a pre-tokenized CSS length value. parseLength :: [Token] -> Maybe Unitted -- | Variant of parseLength which supports min-content & -- max-content keywords. parseLength' :: [Token] -> Maybe (Double, Text) -- | Supported length units. units :: [Text] -- | Convert a lexed number to a Double. n2f :: (Fractional x, RealFloat x) => NumericValue -> x -- | Resolve a parsed length according to the sizing parameters in a given -- Font`. finalizeLength :: Unitted -> Font' -> Length -- | Convert any length-units in the given CSS tokens to device pixels finalizeLengths :: Font' -> [Token] -> [Token] -- | Convert from a computed length to the "pt" unit. px2pt :: Font' -> Double -> Double -- | A Harfbuzz font with sizing parameters. data Font' Font' :: Font -> Pattern -> (Char -> Double) -> (Char -> Double) -> Double -> Double -> Double -> Double -> Double -> Double -> Double -> Double -> Double -> Font' -- | The Harfbuzz font used to shape text & query character-size -- information. [hbFont] :: Font' -> Font -- | The FontConfig query result. Useful to incorporate into output -- rendering. [pattern] :: Font' -> Pattern -- | Query the height of a character. Used for cap, ex, or ic units. [fontHeight] :: Font' -> Char -> Double -- | Query the width of a character, used for ch unit. [fontAdvance] :: Font' -> Char -> Double -- | The desired font-size, used for em unit. [fontSize] :: Font' -> Double -- | The root font's size, used for rem unit. [rootEm] :: Font' -> Double -- | The desired line-height, used for lh unit. [lineheight] :: Font' -> Double -- | The root font's line-height, used for rlh unit. [rlh] :: Font' -> Double -- | Scale-factor for vh unit. [vh] :: Font' -> Double -- | Scale-factor for vw unit. [vw] :: Font' -> Double -- | Scale-factor for vmax unit. [vmax] :: Font' -> Double -- | Scale-factor for vmin unit. [vmin] :: Font' -> Double -- | How many device pixels in a CSS px? [scale] :: Font' -> Double instance GHC.Classes.Eq Graphics.Layout.CSS.Length.Font' instance GHC.Show.Show Graphics.Layout.CSS.Length.Font' instance Graphics.Layout.Box.Zero Graphics.Layout.CSS.Length.Unitted -- | Infrastructure for parsing & desugaring CSS properties related to -- fonts. module Graphics.Layout.CSS.Font -- | A Harfbuzz font with sizing parameters. data Font' Font' :: Font -> Pattern -> (Char -> Double) -> (Char -> Double) -> Double -> Double -> Double -> Double -> Double -> Double -> Double -> Double -> Double -> Font' -- | The Harfbuzz font used to shape text & query character-size -- information. [hbFont] :: Font' -> Font -- | The FontConfig query result. Useful to incorporate into output -- rendering. [pattern] :: Font' -> Pattern -- | Query the height of a character. Used for cap, ex, or ic units. [fontHeight] :: Font' -> Char -> Double -- | Query the width of a character, used for ch unit. [fontAdvance] :: Font' -> Char -> Double -- | The desired font-size, used for em unit. [fontSize] :: Font' -> Double -- | The root font's size, used for rem unit. [rootEm] :: Font' -> Double -- | The desired line-height, used for lh unit. [lineheight] :: Font' -> Double -- | The root font's line-height, used for rlh unit. [rlh] :: Font' -> Double -- | Scale-factor for vh unit. [vh] :: Font' -> Double -- | Scale-factor for vw unit. [vw] :: Font' -> Double -- | Scale-factor for vmax unit. [vmax] :: Font' -> Double -- | Scale-factor for vmin unit. [vmin] :: Font' -> Double -- | How many device pixels in a CSS px? [scale] :: Font' -> Double -- | zero'd Font` to serve as the root's parent in a font heirarchy. placeholderFont :: Font' -- | Scale-factor for text-shaping APIs. hbUnit :: Double -- | Convert from FontConfig query result to a Harfbuzz font. pattern2hbfont :: Pattern -> Int -> [Variation] -> Font -- | Convert Parsed CSS to a Font`. Includes sizing parameters -- derived from a root & parent Font`. pattern2font :: Pattern -> CSSFont -> Font' -> Font' -> Font' -- | Parsed CSS font properties, excluding the FontConfig query. data CSSFont CSSFont :: Unitted -> Unitted -> [Variation] -> Variation -> Variation -> Variation -> Bool -> CSSFont -- | Parsed CSS font-size. [cssFontSize] :: CSSFont -> Unitted -- | Parsed CSS line-height. [cssLineheight] :: CSSFont -> Unitted -- | Parsed CSS font-variation-settings. [variations] :: CSSFont -> [Variation] -- | Parsed CSS font-weight. [weightVariation] :: CSSFont -> Variation -- | Parsed CSS font-stretch. [widthVariation] :: CSSFont -> Variation -- | Parsed CSS font-style. [slantVariation] :: CSSFont -> Variation -- | Parsed CSS font-optical-sizing. [opticalSize] :: CSSFont -> Bool -- | All font-variations from the parsed CSS properties. | Requires the -- resolved font-size in case font-optical-sizing is set. variations' :: Double -> CSSFont -> [Variation] instance Stylist.PropertyParser Graphics.Layout.CSS.Font.CSSFont -- | Layout formula positioning children horizontally or vertically, with -- or without wrapping. module Graphics.Layout.Flex -- | Parameters to flexbox layout data Flex a b Flex :: Direction -> Bool -> FlexWrapping -> Justification -> Maybe Justification -> b -> b -> [[FlexChild a b]] -> Double -> Flex a b -- | On which axis to position children [direction] :: Flex a b -> Direction -- | Whether to reverse each row [reverseRows] :: Flex a b -> Bool -- | Whether to wrap children to multiple lines [wrap] :: Flex a b -> FlexWrapping -- | How to justify children within lines [justify] :: Flex a b -> Justification -- | How to justify lines within the flexbox. Nothing is CSS "stretch". [alignLines] :: Flex a b -> Maybe Justification -- | Gap between children [baseGap] :: Flex a b -> b -- | Gap between lines [crossGap] :: Flex a b -> b -- | The children to layout, 2D list so as to store lines once split. [children] :: Flex a b -> [[FlexChild a b]] -- | How wide to consider the page when paginating. [pageWidth] :: Flex a b -> Double -- | Properties for positioning a child of a flexbox data FlexChild a b FlexChild :: Double -> Double -> b -> Alignment -> a -> FlexChild a b [grow] :: FlexChild a b -> Double [shrink] :: FlexChild a b -> Double [basis] :: FlexChild a b -> b [alignment] :: FlexChild a b -> Alignment [flexInner] :: FlexChild a b -> a -- | Which axis to position children along data Direction Row :: Direction Column :: Direction -- | Whether to wrap or reverse the wrapped lines data FlexWrapping NoWrap :: FlexWrapping Wrap :: FlexWrapping WrapReverse :: FlexWrapping -- | How to position lines within a flexbox, or children within a line data Justification JStart :: Justification JEnd :: Justification JCenter :: Justification JSpaceBetween :: Justification JSpaceAround :: Justification JSpaceEvenly :: Justification -- | How to align children along the cross-axis (opposite axis from which -- they're laid out) data Alignment AlStretch :: Alignment AlStart :: Alignment AlEnd :: Alignment AlCenter :: Alignment AlBaseline :: Alignment -- | Apply an operation to every child flexMap :: (a -> b) -> Flex a c -> Flex b c -- | Resolve lengths in the flexbox to doubles. flexResolve :: CastDouble b => (a -> Direction -> Double) -> Double -> Flex a b -> Flex a Double -- | The minimum size of the flexbox along direction, i.e. maximum -- size of a child. flexMaxBasis :: Flex a Double -> Double -- | The maximum width of each row of the flexbox. flexSumBasis :: Flex a Double -> Double -- | Wrap all lines to a given size reassigning overflow or underflow -- space. NOTE: shrink propery may yield negative sizes. Caller will want -- to enforce min-sizes. flexWrap :: CastDouble b => Flex a b -> Double -> Flex a b -- | The cross (opposite from direction axis) size of a row. flexRowSize :: (a -> Double) -> [FlexChild a b] -> Double -- | The cross (opposite from direction axis) size of all rows. flexRowsSize :: (a -> Double) -> Flex a Double -> Double -- | How far right to shift some elements to achieve desired justification. justifyOffset :: Double -> [Double] -> Double -> Justification -> Double -- | How much space to add between elements. justifySpacing :: Double -> [Double] -> Double -> Justification -> Double -- | Position new positions for the given items according to the given -- justification. flexJustify :: (a -> Double) -> Double -> [a] -> Double -> Justification -> [(Double, a)] -- | How far right to shift some elements to achieve desired alignment. alignOffset :: Double -> Double -> Alignment -> Double outerMinMain :: Num m => PaddedBox m m -> Direction -> m outerMain :: Num m => PaddedBox m m -> Direction -> m outerMaxMain :: Num m => PaddedBox m m -> Direction -> m outerMinCross :: Num m => PaddedBox m m -> Direction -> m outerCross :: Num m => PaddedBox m m -> Direction -> m outerMaxCross :: Num m => PaddedBox m m -> Direction -> m innerMinMain :: Num m => PaddedBox m m -> Direction -> m innerMain :: Num m => PaddedBox m m -> Direction -> m innerMaxMain :: Num m => PaddedBox m m -> Direction -> m innerMinCross :: Num m => PaddedBox m m -> Direction -> m innerCross :: Num m => PaddedBox m m -> Direction -> m innerMaxCross :: Num m => PaddedBox m m -> Direction -> m -- | Compute the size bounds of a flexbox. flexGetBox :: (Zero m, CastDouble m, Zero n, CastDouble n) => (a -> PaddedBox Double Double) -> Flex a m -> PaddedBox m n -- | Split a flexbox over multiple pages. flexSplit :: (a -> Size Double Double) -> Double -> Double -> Flex a Double -> (Flex a Double, Flex a Double) -- | Compute final position of a flexbox's children. flexPosition :: ((Double, Double) -> a -> b) -> (a -> Size Double Double) -> (Double, Double) -> Size Double Double -> Flex a Double -> Flex b Double instance GHC.Read.Read Graphics.Layout.Flex.Direction instance GHC.Show.Show Graphics.Layout.Flex.Direction instance GHC.Classes.Eq Graphics.Layout.Flex.Direction instance GHC.Read.Read Graphics.Layout.Flex.FlexWrapping instance GHC.Show.Show Graphics.Layout.Flex.FlexWrapping instance GHC.Classes.Eq Graphics.Layout.Flex.FlexWrapping instance GHC.Read.Read Graphics.Layout.Flex.Justification instance GHC.Show.Show Graphics.Layout.Flex.Justification instance GHC.Classes.Eq Graphics.Layout.Flex.Justification instance GHC.Read.Read Graphics.Layout.Flex.Alignment instance GHC.Show.Show Graphics.Layout.Flex.Alignment instance GHC.Classes.Eq Graphics.Layout.Flex.Alignment instance (GHC.Read.Read b, GHC.Read.Read a) => GHC.Read.Read (Graphics.Layout.Flex.FlexChild a b) instance (GHC.Show.Show b, GHC.Show.Show a) => GHC.Show.Show (Graphics.Layout.Flex.FlexChild a b) instance (GHC.Classes.Eq b, GHC.Classes.Eq a) => GHC.Classes.Eq (Graphics.Layout.Flex.FlexChild a b) instance (GHC.Read.Read b, GHC.Read.Read a) => GHC.Read.Read (Graphics.Layout.Flex.Flex a b) instance (GHC.Show.Show b, GHC.Show.Show a) => GHC.Show.Show (Graphics.Layout.Flex.Flex a b) instance (GHC.Classes.Eq b, GHC.Classes.Eq a) => GHC.Classes.Eq (Graphics.Layout.Flex.Flex a b) -- | Parse FlexBox-related CSS properties module Graphics.Layout.Flex.CSS -- | Parsed FlexBox-related CSS properties. data CSSFlex CSSFlex :: Direction -> Bool -> FlexWrapping -> Maybe Justification -> Alignment -> Maybe Justification -> Unitted -> Unitted -> Integer -> Double -> Double -> Unitted -> Alignment -> Bool -> CSSFlex -- | Parsed CSS flex-direction, axis component. [directionCSS] :: CSSFlex -> Direction -- | Parsed CSS flex-direction, reversed flag [reverseRowsCSS] :: CSSFlex -> Bool -- | Parsed CSS flex-wrap [wrapCSS] :: CSSFlex -> FlexWrapping -- | Parsed CSS justify-content [justifyCSS] :: CSSFlex -> Maybe Justification -- | Parsed CSS align-items [alignItemsCSS] :: CSSFlex -> Alignment -- | Parsed CSS align-content, Nothing is "stretch" [alignLinesCSS] :: CSSFlex -> Maybe Justification -- | Parsed CSS row-gap [rowGapCSS] :: CSSFlex -> Unitted -- | Parsed CSS column-gap [columnGapCSS] :: CSSFlex -> Unitted -- | Parsed CSS order [orderCSS] :: CSSFlex -> Integer -- | Parsed CSS flex-grow [growCSS] :: CSSFlex -> Double -- | Parsed CSS flex-shrink [shrinkCSS] :: CSSFlex -> Double -- | Parsed CSS flex-basis [basisCSS] :: CSSFlex -> Unitted -- | Parsed CSS align-self [alignSelfCSS] :: CSSFlex -> Alignment -- | Whether justification or alignment properties should be parsed as -- right-to-left or left-to-right. [textRTL] :: CSSFlex -> Bool -- | Lower the Flexbox styling tree to the Layout tree. lowerFlex :: CSSFlex -> Font' -> [CSSFlex] -> [a] -> [Font'] -> Flex a Length instance Stylist.PropertyParser Graphics.Layout.Flex.CSS.CSSFlex -- | Sizes a block element & positions their children. Taking into -- account size bounds. module Graphics.Layout.Flow -- | Compute the minimum width of a block element with children of the -- given sizes. flowMinWidth :: Double -> PaddedBox a Length -> [PaddedBox b Double] -> Double -- | Compute the natural width of a block element with children of the -- given sizes. flowNatWidth :: Double -> PaddedBox a Length -> [PaddedBox b Double] -> Double -- | Compute the maximum width of a block element inside the given parent -- size. flowMaxWidth :: PaddedBox a Double -> PaddedBox b Length -> Double -- | Compute final block element width based on cached width computations -- & parent size. flowWidth :: PaddedBox a Double -> PaddedBox b Length -> Double -- | Compute natural block element height at cached width. flowNatHeight :: Double -> PaddedBox Length Double -> [PaddedBox Double Double] -> Double -- | Compute minimum block height at cached width. flowMinHeight :: Double -> PaddedBox Length Double -> Double -- | Compute maximum block height at cached width. flowMaxHeight :: Double -> PaddedBox Length Double -> Double -- | Compute final block height at cached width. flowHeight :: PaddedBox Double Double -> PaddedBox Length Double -> Double -- | Compute position of all children relative to this block element. positionFlow :: [PaddedBox Double Double] -> [Size Double Double] -- | Compute size given block element in given parent, & position of -- given children. layoutFlow :: PaddedBox Double Double -> PaddedBox Length Length -> [PaddedBox Length Double] -> (PaddedBox Double Double, [(Size Double Double, PaddedBox Double Double)]) -- | Sizes grid cells & positions elements to them. module Graphics.Layout.Grid -- | An element which positions it's children within a grid. type Grid m n = Size (Track m) (Track n) -- | The sizes to which children are alonged on a single axis. data Track x Track :: [Either x Double] -> [Double] -> [Double] -> x -> Track x -- | The desired size of each cell. If Left specifies ratio of excess space -- to use. [cells] :: Track x -> [Either x Double] -- | The minimum amount of space each cell should take. [trackMins] :: Track x -> [Double] -- | The ideal amount of space each cell should take. [trackNats] :: Track x -> [Double] -- | How much space to add between cells. [gap] :: Track x -> x -- | Which cells a child should be aligned to. type GridItem = Size GridItem' GridItem' -- | How a grid child should be aligned per-axis. data GridItem' GridItem :: Int -> Int -> Alignment -> Double -> Double -> GridItem' -- | On which cell should this child start. [cellStart] :: GridItem' -> Int -- | Before which cell should this child end. [cellEnd] :: GridItem' -> Int -- | How to redistribute excess space. [alignment] :: GridItem' -> Alignment -- | The minimum amount of space to allocate to this child. [minSize] :: GridItem' -> Double -- | The maximum aount of space to allocate to this child. [natSize] :: GridItem' -> Double -- | How to redistribute excess space. data Alignment Start :: Alignment Mid :: Alignment End :: Alignment -- | Constructs a track with default (to-be-computed) values & given -- cell sizes. buildTrack :: CastDouble x => [Either x Double] -> Track x -- | Constructs a grid with default (to-be-computed) values & given -- cell sizes. buildGrid :: (CastDouble m, CastDouble n) => [Either m Double] -> [Either n Double] -> Grid m n -- | Sets minimum & natural sizes from the given padded box. setCellBox :: (CastDouble m, CastDouble n) => GridItem -> PaddedBox m n -> GridItem -- | Utility for associate an index with each item in a list. enumerate :: [b] -> [(Int, b)] -- | Compute the maximum size as a PaddedBox of a child, for it to be sized -- to. gridItemBox :: (CastDouble x, CastDouble y) => Grid y x -> GridItem -> PaddedBox Double Double -- | Compute the maximum size along an axis of a child, for it to be sized -- to. cellSize :: CastDouble x => Track x -> GridItem' -> Double -- | Compute the minimum size for the track given cell sizes. Refers to -- computed min sizes if cached. trackMin :: (n -> Double) -> Track n -> Double -- | Compute the natural size for the track given cell sizes. Refers to -- compute natural sizes if cached. trackNat :: (n -> Double) -> Track n -> Double -- | Estimate grid width to inform proper width calculation. gridEstWidth :: Grid y Length -> [GridItem] -> Double -- | Calculate minimum sizes for all cells in the track. Sized to fit given -- children. sizeTrackMins :: Double -> Track Length -> [GridItem'] -> [Double] -- | Compute natural sizes for all cells in the track. Sized to fit given -- children. sizeTrackNats :: Double -> Track Length -> [GridItem'] -> [Double] -- | Compute maximum sizes for all cells in the track, sized to the parent -- element. sizeTrackMaxs :: Double -> Track Length -> [Double] -- | Compute the position of all children within the grid. trackPosition :: Track Double -> [GridItem'] -> [Double] -- | Compute the position of all children in a grid. gridPosition :: Grid Double Double -> [GridItem] -> [(Double, Double)] -- | Compute the track sizes & child positions along a single axis. trackLayout :: Double -> Double -> Track Length -> [GridItem'] -> (Track Double, [(Double, GridItem')]) -- | Compute the track sizes & child positions along both axes. gridLayout :: Size Double Double -> Grid Length Length -> [GridItem] -> (Grid Double Double, [((Double, Double), GridItem)]) instance GHC.Classes.Ord x => GHC.Classes.Ord (Graphics.Layout.Grid.Track x) instance GHC.Classes.Eq x => GHC.Classes.Eq (Graphics.Layout.Grid.Track x) instance GHC.Read.Read x => GHC.Read.Read (Graphics.Layout.Grid.Track x) instance GHC.Show.Show x => GHC.Show.Show (Graphics.Layout.Grid.Track x) instance GHC.Generics.Generic Graphics.Layout.Grid.Alignment instance GHC.Classes.Eq Graphics.Layout.Grid.Alignment instance GHC.Classes.Ord Graphics.Layout.Grid.Alignment instance GHC.Enum.Enum Graphics.Layout.Grid.Alignment instance GHC.Show.Show Graphics.Layout.Grid.Alignment instance GHC.Read.Read Graphics.Layout.Grid.Alignment instance GHC.Generics.Generic Graphics.Layout.Grid.GridItem' instance GHC.Classes.Eq Graphics.Layout.Grid.GridItem' instance GHC.Classes.Ord Graphics.Layout.Grid.GridItem' instance GHC.Show.Show Graphics.Layout.Grid.GridItem' instance GHC.Read.Read Graphics.Layout.Grid.GridItem' instance Control.DeepSeq.NFData Graphics.Layout.Grid.GridItem' instance Control.DeepSeq.NFData Graphics.Layout.Grid.Alignment -- | Datastructures for parsing table styling properties, & for -- positioning cells into Grid layout regions. module Graphics.Layout.Grid.Table -- | Tracks rowspan attributes so later rows can dodge it. type Overflowed = [Int] -- | A row with no cells overflowing into it. emptyRow :: Overflowed -- | Decrement all rowspans being overflowed, removing 0'd ones. commitRow :: Overflowed -> Overflowed -- | Find the next column which a previous multi-row cell hasn't called -- "dibs" on. allocCol :: Int -> Overflowed -> Int -- | Splice a newly-allocated cell covernig colspan (2nd arg) & -- rowspan (3rd arg) from "ix" (from 1st arg) into the final arg. insertCell :: Int -> Int -> Int -> Overflowed -> Overflowed -- | Parsed CSS properties & HTML attributes for laying out "table" -- elements. To parse HTML attributes, expects the following useragent -- stylesheet rules: -- -- data TableOptions TableOptions :: Int -> Int -> Bool -> Bool -> Unitted -> Unitted -> Unitted -> TableOptions -- | HTML rowspan attribute [rowspan] :: TableOptions -> Int -- | HTML colspan attribute [colspan] :: TableOptions -> Int -- | Parsed CSS caption-side. [captionBelow] :: TableOptions -> Bool -- | Parsed CSS border-collapse [borderCollapse] :: TableOptions -> Bool -- | Semi-parsed border-spacing, horizontal axis [borderHSpacing] :: TableOptions -> Unitted -- | Semi-parsed border-spacing, vertical axis [borderVSpacing] :: TableOptions -> Unitted -- | Parsed CSS vertical-align [verticalAlign] :: TableOptions -> Unitted -- | Resolve any units in the "border-spacing" property according to the -- given font. If "border-collapse" is set, removes this spacing. finalizeGap :: TableOptions -> Font' -> (Length, Length) -- | Shorthand for a padded box without its CSS units resolved, simplifies -- type signatures. type UPaddedBox = PaddedBox Unitted Unitted -- | Removes margins & halves borders if "border-collapse" is set, as -- per the CSS specification. Apply this on the table cells, rows, & -- columns. collapseBorders :: TableOptions -> UPaddedBox -> UPaddedBox -- | Removes padding & halves borders if "border-collapse" is set, as -- per the CSS specification. Apply this on the table itself. collapseTBorders :: TableOptions -> UPaddedBox -> UPaddedBox -- | Helper for halving a unit. half :: Fractional a => (a, b) -> (a, b) -- | Lower vertical alignment to grid alignment options. finalizeVAlign :: TableOptions -> Alignment -- | Lower text alignment to grid alignment. finalizeHAlign :: ParagraphOptions -> Direction -> Alignment instance Stylist.PropertyParser Graphics.Layout.Grid.Table.TableOptions -- | Sizes inline text & extracts positioned children, wraps Balkón for -- the actual logic. module Graphics.Layout.Inline -- | Apply an operation to the 2nd field of the paragraph's userdata, for -- it's entire subtree. paragraphMap :: (b -> b') -> Paragraph (a, b, c) -> Paragraph (a, b', c) -- | Apply an operation to the 2nd field of a laid-out paragraph's -- userdata, for it's entire subtree. layoutMap :: (b -> b') -> ParagraphLayout (a, b, c) -> ParagraphLayout (a, b', c) -- | Apply an operation to the 2nd field of the tree extracted from a -- laid-out paragraph, for all nodes. treeMap :: (b -> b') -> FragmentTree (a, b, c) -> FragmentTree (a, b', c) -- | Compute minimum width & height for some richtext. inlineMin :: (CastDouble x, CastDouble y) => Paragraph (a, PaddedBox x y, c) -> Size x y -- | Compute width & height of some richtext at configured width. inlineSize :: (CastDouble x, CastDouble y) => Paragraph (a, PaddedBox x y, c) -> Size x y -- | Retrieve children out of some richtext, associating given userdata -- with them. inlineChildren :: (CastDouble x, CastDouble y, Eq x, Eq y, Eq a, Eq c) => Paragraph (a, PaddedBox x y, c) -> [FragmentTree (a, PaddedBox x y, c)] -- | Retrieve a laid-out paragraph's rect & convert to CatTrap types. layoutSize :: (CastDouble x, CastDouble y) => ParagraphLayout a -> Size x y -- | Retrieve a laid-out paragraph's children & associate with given -- userdata. layoutChildren :: Eq a => ParagraphLayout a -> [FragmentTree a] -- | Compute the paddedbox for a subtree. treeBox :: (CastDouble m, CastDouble n) => FragmentTree (a, PaddedBox m n, c) -> PaddedBox m n -- | Add an X,Y offset to all positions, annotating the userdata. positionTree :: (CastDouble m, CastDouble n) => (Double, Double) -> FragmentTree (a, PaddedBox m n, c) -> FragmentTree (a, PaddedBox m n, ((Double, Double), c)) -- | Retrieve 3rd userdata field. treeInner :: FragmentTree (a, b, c) -> c -- | Retrieve userdata field. treeInner' :: FragmentTree a -> a -- | Retrieve Harfbuzz data out of the tree extracted from Balkón. glyphs :: FragmentTree x -> [(GlyphInfo, GlyphPos)] -- | Retrieve the Unicode codepoints out of the tree extracted from Balkón. codepoints :: FragmentTree x -> [Word32] -- | A tree extracted from Balkón's inline layout. data FragmentTree x Branch :: AncestorBox x -> [FragmentTree x] -> FragmentTree x Leaf :: Fragment x -> FragmentTree x instance GHC.Classes.Eq x => GHC.Classes.Eq (Graphics.Layout.Inline.FragmentTree x) instance GHC.Show.Show x => GHC.Show.Show (Graphics.Layout.Inline.FragmentTree x) -- | Generic layout logic, handling a hierarchy of varying formulas. Unless -- callers have more specific needs they probably wish to use this -- abstraction. Attempts to follow the CSS specs. See boxLayout -- for a main entrypoint, & CSS to receive CSS input. module Graphics.Layout -- | A tree of different layout algorithms. More to come... data LayoutItem m n x -- | A block element. With margins, borders, & padding. LayoutFlow :: x -> PaddedBox m n -> [LayoutItem m n x] -> LayoutItem m n x -- | A grid or table element. LayoutGrid :: x -> Grid m n -> [GridItem] -> [LayoutItem m n x] -> LayoutItem m n x -- | Some richtext. (Balkón holds children) LayoutInline :: x -> Paragraph (UserData m n x) -> PageOptions -> LayoutItem m n x -- | Results laying out richtext, has fixed width. Generated from -- LayoutInline for the sake of pagination. LayoutInline' :: x -> ParagraphLayout (UserData m n x) -> PageOptions -> LayoutItem m n x -- | A branch with constant bounding box. Generated from -- LayoutInline when attaching position info. LayoutConst :: x -> PaddedBox m n -> [LayoutItem m n x] -> LayoutItem m n x -- | Children of a LayoutInline or LayoutInline`. LayoutSpan :: FragmentTree (UserData m n x) -> LayoutItem m n x LayoutFlex :: x -> Flex (LayoutItem m n x) m -> LayoutItem m n x -- | Additional data routed through Balkon. type UserData m n x = ((Font', Int), PaddedBox m n, x) -- | Retrieve the surrounding box for a layout item. layoutGetBox :: (Zero m, Zero n, CastDouble m, CastDouble n) => LayoutItem m n x -> PaddedBox m n -- | Retrieve the subtree under a node. layoutGetChilds :: (CastDouble b, CastDouble n, Eq b, Eq n, Eq x) => LayoutItem b n x -> [LayoutItem b n x] -- | Retrieve the caller-specified data attached to a layout node. layoutGetInner :: LayoutItem m n x -> x -- | Update a (sub)tree to compute & cache minimum legible sizes. boxMinWidth :: (Zero y, CastDouble y, NFData y) => Maybe Double -> LayoutItem y Length x -> LayoutItem y Length x -- | Update a (sub)tree to compute & cache maximum legible width. boxMaxWidth :: (CastDouble y, Zero y, NFData y) => PaddedBox a Double -> LayoutItem y Length x -> LayoutItem y Length x -- | Update a (sub)tree to compute & cache ideal width. boxNatWidth :: (Zero y, CastDouble y, NFData y) => Maybe Double -> LayoutItem y Length x -> LayoutItem y Length x -- | Update a (sub)tree to compute & cache final width. boxWidth :: (Zero y, CastDouble y, NFData y) => PaddedBox b Double -> LayoutItem y Length x -> LayoutItem y Double x -- | Update a (sub)tree to compute & cache ideal legible height. boxNatHeight :: Double -> LayoutItem Length Double x -> LayoutItem Length Double x -- | Update a (sub)tree to compute & cache minimum legible height. boxMinHeight :: Double -> LayoutItem Length Double x -> LayoutItem Length Double x -- | Update a subtree to compute & cache maximum legible height. boxMaxHeight :: PaddedBox Double Double -> LayoutItem Length Double x -> LayoutItem Length Double x -- | Update a (sub)tree to compute & cache final height. boxHeight :: PaddedBox Double Double -> LayoutItem Length Double x -> LayoutItem Double Double x -- | Split a (sub)tree to fit within max-height. May take full page height -- into account. boxSplit :: PropertyParser x => Double -> Double -> LayoutItem Double Double x -> (LayoutItem Double Double x, Maybe (LayoutItem Double Double x)) -- | Generate a list of pages from a node, splitting subtrees where -- necessary. boxPaginate :: PropertyParser x => Double -> LayoutItem Double Double x -> [LayoutItem Double Double x] -- | Compute position of all nodes in the (sub)tree relative to a base -- coordinate. boxPosition :: (PropertyParser x, Eq x) => (Double, Double) -> LayoutItem Double Double x -> LayoutItem Double Double ((Double, Double), x) -- | Compute sizes & position information for all nodes in the -- (sub)tree. boxLayout :: (PropertyParser x, Eq x) => PaddedBox Double Double -> LayoutItem Length Length x -> Bool -> [LayoutItem Double Double ((Double, Double), x)] -- | Retrieve Harfbuzz data out of the tree extracted from Balkón. glyphs :: FragmentTree x -> [(GlyphInfo, GlyphPos)] -- | Retrieve the Unicode codepoints out of the tree extracted from Balkón. codepoints :: FragmentTree x -> [Word32] -- | Retrieve the font associated with inline layout. fragmentFont :: FragmentTree (a, b, c) -> a -- | Compute a mapping from a layout tree indicating which glyphs for which -- fonts are required. Useful for assembling glyph atlases. glyphsPerFont :: (CastDouble x, CastDouble y, Eq x, Eq y, Eq z) => LayoutItem x y z -> Map (Pattern, Double) IntSet instance (GHC.Classes.Eq x, GHC.Classes.Eq n, GHC.Classes.Eq m) => GHC.Classes.Eq (Graphics.Layout.LayoutItem m n x) instance (GHC.Show.Show x, GHC.Show.Show n, GHC.Show.Show m) => GHC.Show.Show (Graphics.Layout.LayoutItem m n x) instance GHC.Show.Show Data.Text.ParagraphLayout.Internal.Paginable.PageOptions instance GHC.Classes.Eq Data.Text.ParagraphLayout.Internal.Paginable.PageOptions instance (Graphics.Layout.Box.Zero m, Graphics.Layout.Box.CastDouble m, Control.DeepSeq.NFData m, Graphics.Layout.Box.Zero n, Graphics.Layout.Box.CastDouble n, Control.DeepSeq.NFData n) => Control.DeepSeq.NFData (Graphics.Layout.LayoutItem m n x) instance GHC.Show.Show (Data.Text.ParagraphLayout.Internal.Rich.Paragraph.Paragraph x) instance GHC.Classes.Eq (Data.Text.ParagraphLayout.Internal.Rich.Paragraph.Paragraph x) -- | Infrastructure for parsing & desugaring grid-layout related CSS -- properties. module Graphics.Layout.Grid.CSS -- | Parsed CSS Grid properties data CSSGrid CSSGrid :: Unitted -> Axis -> Bool -> Unitted -> Areas -> [([Text], Unitted)] -> [([Text], Unitted)] -> Size Unitted Unitted -> Size Alignment Alignment -> CSSGrid -- | Parsed CSS grid-auto-columns [autoColumns] :: CSSGrid -> Unitted -- | Parsed grid-auto-flow [autoFlow] :: CSSGrid -> Axis -- | Whether grid-auto-flow: dense was specified. [autoFlowDense] :: CSSGrid -> Bool -- | Parsed CSS grid-auto-rows [autoRows] :: CSSGrid -> Unitted -- | Parsed CSS grid-template-areas [templateAreas] :: CSSGrid -> Areas -- | Parsed CSS grid-template-columns [templateColumns] :: CSSGrid -> [([Text], Unitted)] -- | Parsed CSS grid-template-rows [templateRows] :: CSSGrid -> [([Text], Unitted)] -- | Parsed CSS row-gap & column-gap [cssGap] :: CSSGrid -> Size Unitted Unitted -- | Parsed CSS justify-items & align-items [alignItems] :: CSSGrid -> Size Alignment Alignment -- | A grid axis. data Axis Row :: Axis Col :: Axis -- | Parsed CSS grid item properties. data CSSCell CSSCell :: Placement -> Placement -> Placement -> Placement -> Size (Maybe Alignment) (Maybe Alignment) -> CSSCell -- | Parsed CSS grid-column-start [columnStart] :: CSSCell -> Placement -- | Parsed CSS grid-column-end [columnEnd] :: CSSCell -> Placement -- | Parsed CSS grid-row-start [rowStart] :: CSSCell -> Placement -- | Parsed CSS grid-row-end [rowEnd] :: CSSCell -> Placement -- | Parsed CSS align-self & justify-self [alignSelf] :: CSSCell -> Size (Maybe Alignment) (Maybe Alignment) -- | Identifies a cell in the CSS grid. data Placement Autoplace :: Placement Named :: Text -> Placement Numbered :: Int -> Maybe Text -> Placement Span :: Int -> Maybe Text -> Placement -- | Desugar grid properties to a grid layout. finalizeGrid :: PropertyParser x => CSSGrid -> Font' -> [CSSCell] -> [LayoutItem Length Length x] -> LayoutItem Length Length x -- | Mapping from area identifiers to bounding boxes. type Areas = HashMap Text ((Int, Int), (Int, Maybe Int)) -- | Converts a grid to lookup table start & indices for row & -- columns. Exported for the sake of testing parseASCIIGrid :: [[Text]] -> Int -> Areas -> Maybe Areas instance GHC.Classes.Eq Graphics.Layout.Grid.CSS.Axis instance Stylist.PropertyParser Graphics.Layout.Grid.CSS.CSSCell instance Stylist.PropertyParser Graphics.Layout.Grid.CSS.CSSGrid -- | Infrastructure for parsing & desugaring text related CSS -- properties. module Graphics.Layout.Inline.CSS -- | Document text with Balkón styling options, CSS stylable. data CSSInline CSSInline :: Text -> TextOptions -> UnicodeBidi -> CSSInline -- | Types with default values. Used to fill in values into generated -- fragments from caller. class Default a def :: Default a => a -- | To what degree is the text direction isolated? data UnicodeBidi BdNormal :: UnicodeBidi BdEmbed :: UnicodeBidi BdOverride :: UnicodeBidi BdIsolate :: UnicodeBidi BdIsolateOverride :: UnicodeBidi BdPlainText :: UnicodeBidi -- | Fills in properties from looked-up fonts. applyFontInline :: TextOptions -> Font' -> TextOptions -- | Apply Bidi chars around the inline text. FIXME: Handle the tree! applyBidi :: Default d => CSSInline -> [InnerNode Text d] -> [InnerNode Text d] -- | Converts parsed valign keywords or length units to Balkón alignment. resolveVAlign :: Font' -> Unitted -> VerticalAlignment -- | Converts grid options to box options. resolveBoxOpts :: Font' -> TableOptions -> BoxOptions -- | Construct plain text plaintext :: Text -> CSSInline instance GHC.Show.Show Graphics.Layout.Inline.CSS.UnicodeBidi instance GHC.Read.Read Graphics.Layout.Inline.CSS.UnicodeBidi instance GHC.Enum.Enum Graphics.Layout.Inline.CSS.UnicodeBidi instance GHC.Classes.Ord Graphics.Layout.Inline.CSS.UnicodeBidi instance GHC.Classes.Eq Graphics.Layout.Inline.CSS.UnicodeBidi instance Stylist.PropertyParser Graphics.Layout.Inline.CSS.CSSInline -- | Parses & desugars CSS properties to general CatTrap -- datastructures. module Graphics.Layout.CSS -- | Parsed CSS properties relevant to layout. data CSSBox a CSSBox :: Display -> BoxSizing -> PaddedBox Unitted Unitted -> Pattern -> CSSFont -> a -> [(Text, [Token])] -> a -> CSSGrid -> CSSCell -> CSSInline -> PageOptions -> ParagraphOptions -> TableOptions -> CSSFlex -> CSSBox a -- | Which layout formula to use, a.k.a. parsed CSS display property. [display] :: CSSBox a -> Display -- | (Unused) Parsed CSS box-sizing [boxSizing] :: CSSBox a -> BoxSizing -- | sizing, margins, border-width, & padding CSS properties. Stores -- units in case they're needed for font-related units. [cssBox] :: CSSBox a -> PaddedBox Unitted Unitted -- | Query parameters describing desired font. [font] :: CSSBox a -> Pattern -- | Additional font-related CSS properties. [font'] :: CSSBox a -> CSSFont -- | Caller-specified data, to parse additional CSS properties. [inner] :: CSSBox a -> a -- | Properties to lower size units before passing onto to inner [innerProperties] :: CSSBox a -> [(Text, [Token])] -- | Parent to use when parsing length-expanded inner properties. [innerParent] :: CSSBox a -> a -- | Grid-related CSS properties. [gridStyles] :: CSSBox a -> CSSGrid -- | Grid item related CSS properties. [cellStyles] :: CSSBox a -> CSSCell -- | inline-related CSS properties. [inlineStyles] :: CSSBox a -> CSSInline -- | Parsed widows & orphans controlling pagination. [pageOptions] :: CSSBox a -> PageOptions -- | Parsed text-alignment & other options which applies per-paragraph. [paragraphOptions] :: CSSBox a -> ParagraphOptions -- | (Semi-)parsed CSS properties & HTML attributes relating to laying -- out HTML table elements. [tableOptions] :: CSSBox a -> TableOptions -- | Semi-parsed CSS properties relating to FlexBox layouts. [flexOptions] :: CSSBox a -> CSSFlex -- | Possible values for CSS box-sizing. data BoxSizing BorderBox :: BoxSizing ContentBox :: BoxSizing -- | Possibly values for CSS display property. data Display Block :: Display Grid :: Display Inline :: Display Table :: Display None :: Display TableRow :: Display TableHeaderGroup :: Display TableRowGroup :: Display TableFooterGroup :: Display TableCell :: Display TableColumn :: Display TableColumnGroup :: Display TableCaption :: Display Flex :: Display -- | Desugar parsed CSS into more generic layout parameters. finalizeCSS :: PropertyParser x => Font' -> Font' -> StyleTree (CSSBox x) -> LayoutItem Length Length x -- | Desugars parsed CSS with a provided system font into more generic -- layout parameters. finalizeCSS' :: PropertyParser x => Font' -> StyleTree (CSSBox x) -> LayoutItem Length Length x instance (Stylist.PropertyParser x, Graphics.Layout.Box.Zero m, Graphics.Layout.Box.Zero n) => Graphics.Layout.Inline.CSS.Default (Graphics.Layout.UserData m n x)