    {-# LANGUAGE LambdaCase           #-}
    {-# LANGUAGE OverloadedStrings    #-}
    {- |
       Module      : Text.Pandoc.Lua.Marshal.ImageSize
       Copyright   : © 2024 Albert Krewinkel
       License     : GPL-2.0-or-later
       Maintainer  : Albert Krewinkel <albert+pandoc@tarleb.com>

    Marshaling image properties.
    -}
    module Text.Pandoc.Lua.Marshal.ImageSize
      ( pushImageType
      , pushImageSize
      ) where

    import Data.Char (toLower)
    import HsLua
    import Text.Pandoc.ImageSize

    -- | Pushes an 'ImageType' as a string value.
    pushImageType :: LuaError e => Pusher e ImageType
    pushImageType :: forall e. LuaError e => Pusher e ImageType
    pushImageType = String -> LuaE e ()
    forall e. String -> LuaE e ()
    pushString (String -> LuaE e ())
    -> (ImageType -> String) -> ImageType -> LuaE e ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Char -> Char) -> String -> String
    forall a b. (a -> b) -> [a] -> [b]
    map Char -> Char
    toLower (String -> String) -> (ImageType -> String) -> ImageType -> String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ImageType -> String
    forall a. Show a => a -> String
    show

    -- | Pushes a dimensional value.
    pushImageSize :: LuaError e => Pusher e ImageSize
    pushImageSize :: forall e. LuaError e => Pusher e ImageSize
    pushImageSize = [(Name, ImageSize -> LuaE e ())] -> ImageSize -> LuaE e ()
    forall e a.
    LuaError e =>
    [(Name, a -> LuaE e ())] -> a -> LuaE e ()
    pushAsTable
      [ (Name
    "width", Integer -> LuaE e ()
    forall a e. (Integral a, Show a) => a -> LuaE e ()
    pushIntegral (Integer -> LuaE e ())
    -> (ImageSize -> Integer) -> ImageSize -> LuaE e ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ImageSize -> Integer
    pxX)
      , (Name
    "height", Integer -> LuaE e ()
    forall a e. (Integral a, Show a) => a -> LuaE e ()
    pushIntegral (Integer -> LuaE e ())
    -> (ImageSize -> Integer) -> ImageSize -> LuaE e ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ImageSize -> Integer
    pxY)
      , (Name
    "dpi_horz", Integer -> LuaE e ()
    forall a e. (Integral a, Show a) => a -> LuaE e ()
    pushIntegral (Integer -> LuaE e ())
    -> (ImageSize -> Integer) -> ImageSize -> LuaE e ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ImageSize -> Integer
    dpiX)
      , (Name
    "dpi_vert", Integer -> LuaE e ()
    forall a e. (Integral a, Show a) => a -> LuaE e ()
    pushIntegral (Integer -> LuaE e ())
    -> (ImageSize -> Integer) -> ImageSize -> LuaE e ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ImageSize -> Integer
    dpiY)
      ]