Orasund/elm-svg-writer/1.0.0

NOTE: the latest version is 2.0.1

Svg.Writer

Svg

type SvgNode
= SvgNode
{ name : String
, attributes : List ( String, String )
, content : List SvgNode
}

A Svg Node.

It can be turned into a string using toString or into html using toHtml.

{ radius : Float
, pos : ( Float, Float )
}

define a cirlce svg node

{ topLeft : ( Float, Float )
, width : Float
, height : Float
}

create a rectangle svg node

turn a path into a svg node.

define : List ( String, SvgNode ) -> SvgNode

define a template.

You can use a template with use.

defineMask : String -> List SvgNode -> SvgNode

define a mask.

You can use the mask with withMask.

use : String -> SvgNode

Use a defined template

group nodes to apply styling to all nodes at once.

Attributes

fill the shape with a color

use no color for the filling

use a color for the border of the shape

define the with of the border of the shape

don't draw the border of the shape

withMask : String -> SvgNode -> SvgNode

Use a defined mask

withAttribute : ( String, String ) -> SvgNode -> SvgNode

add a attribute

Conversion

{ width : Int
, height : Int
}
-> List SvgNode
-> String

Convert the list of svg nodes into a svg-string.

List (Attribute msg)
-> { width : Int
, height : Int
}
-> List SvgNode
-> Html msg

convert the svg nodes into html.

Note: the svg will be displayed as the background of a div.

I tried converting it into a Svg node, but my browser didn't seem to like it.

Alternatively i looked into elm/Svg, but there i can't define custom attributes.

{ width : Int
, height : Int
}
-> List SvgNode
-> String

turn the list of svg nodes into a data URI.

backgroundImage : Html.Attribute msg
backgroundImage =
    Html.Attributes.style "background-image"
        ( "url(\\""
            ++ toDataURI { width = 100, height = 100 }
                svgNodes
            ++ "\\")"
        )

Interactive Viewer

type alias Program =
Program () Model Msg

A Program for viewing your Svg creations

{ name : String
, width : Int
, height : Int
}
-> List SvgNode
-> Program

Convert into a program for viewing your Svg creations.

You might want to use this in combination with hot-loading, while you write your svg.