I am trying to create an application that lets you create geometric images within the browser. I am mostly creating this application as a development environment for creating my art. I need to be able to download the image that was created as an SVG file type. I have been able to learn through most of the technical issues up to this point, all except downloading the created image.
I have been using the ianmackenzie/elm-geometry-svg library to create and display the content within the browser. The geometry utilities within the elm-geometry and elm-geometry-svg libraries are paramount to the style of art that I create. This package is one of the reasons I was so excited to create my stack within the elm environment.
Everything was going well until I tried to implement the download functionality. I was looking at the
elm/file library to download the image. They have an example
import File.Download as Download download : String -> Cmd msg download svgContent = Download.string "floorplan.svg" "image/svg+xml" svgContent
I was able to download some string output but where I’m getting stuck is that I need to convert the SVG content into the
String representation to send to this example download function. The
elm/svg library doesn’t provide any
Svg.toString function to do this conversion. With more research, I was able to find the PaackEng/elm-svg-string and
zwilias/elm-html-string packages which try to help and solve this problem.
Unfortunately, there isn’t a simple single-function insertion from either of these packages. This would be a wholesale replacement of all the
Svg function calls with the
Svg.string variants from these packages. It appears like the
Svg.String uses strings as an internal representation instead of the
VirtualDom. I would be alright just swapping to those libraries and taking what I assume would be a performance hit because of the different representation. However, this switch would have other propagating consequences. Since I am using the
ianmackenzie/elm-geometry-svg, this library also has dependencies on the core libraries.
The only solution I see at the moment it to now fork
ianmackenzie/elm-geometry-svg library and rework it to use the
Svg.String library as the backend. Not only would this likely be a lot of work, but it also seems like more of a hacky solution and has consequences for any packages that use these core libraries as dependencies. I would also have to then manually update that fork with all the new updates from that library.
What is the best way forward to solve this problem? What other pathways forward do I have to be able to download these SVG files that are created on the fly? Thanks