{-# LANGUAGE OverloadedStrings #-}
module HGeometry.Miso.Svg
( renderSvgToFile
, renderAsSvgText, renderAsSvgByteString
, withAts
, Drawable(..)
, dPoint
, dLineSegment
, dRectangle
, dCircle
, dDisk
, dPolyLine
, dSimplePolygon
) where
import Data.ByteString.Lazy qualified as ByteString
import Data.Text.Encoding.Error qualified as Text
import Data.Text.Lazy qualified as Text
import Data.Text.Lazy.Encoding qualified as Text
import HGeometry.Miso.Svg.Writer
import Miso qualified
import Miso.Html.Render qualified as Miso
import System.File.OsPath qualified as File
import System.OsPath
renderSvgToFile :: OsPath -> Miso.View model action -> IO ()
renderSvgToFile :: forall model action. OsPath -> View model action -> IO ()
renderSvgToFile OsPath
fp = OsPath -> ByteString -> IO ()
File.writeFile OsPath
fp (ByteString -> IO ())
-> (View model action -> ByteString) -> View model action -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. View model action -> ByteString
forall model action. View model action -> ByteString
renderAsSvgByteString
withDocType :: ByteString.ByteString -> ByteString.ByteString
withDocType :: ByteString -> ByteString
withDocType ByteString
content = [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
mconcat
[ ByteString
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">"
, ByteString
"<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">"
, ByteString
content
, ByteString
"</svg>"
]
renderAsSvgText :: Miso.View model action -> Text.Text
renderAsSvgText :: forall model action. View model action -> Text
renderAsSvgText = OnDecodeError -> ByteString -> Text
Text.decodeUtf8With OnDecodeError
Text.strictDecode (ByteString -> Text)
-> (View model action -> ByteString) -> View model action -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. View model action -> ByteString
forall model action. View model action -> ByteString
renderAsSvgByteString
renderAsSvgByteString :: Miso.View model action -> ByteString.ByteString
renderAsSvgByteString :: forall model action. View model action -> ByteString
renderAsSvgByteString = ByteString -> ByteString
withDocType (ByteString -> ByteString)
-> (View model action -> ByteString)
-> View model action
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. View model action -> ByteString
forall a. ToHtml a => a -> ByteString
Miso.toHtml