PhoenixKitOG.Render.Svg (PhoenixKitOG v0.1.1)

Copy Markdown View Source

Converts a canvas spec + binding values into a clean SVG string suitable for rasterization by rsvg-convert / librsvg.

Why we generate fresh SVG instead of reusing the editor's HEEx output:

  • The editor uses <foreignObject> to embed HTML for ergonomic text layout. librsvg ignores foreignObject, so we generate native <text> + <tspan> here with manual word wrapping.
  • The editor renders a 60%-scaled preview; the rasterizer needs the full-size SVG (the canvas's intrinsic width/height).

The output is deterministic — same canvas + values produce byte-identical SVG. That's load-bearing for cache-key hashing in PhoenixKitOG.Render.Cache.

Summary

Functions

Renders the canvas to an SVG string.

Render to a binary (the rasterizer pipes bytes via stdin). Convenience over render/2 |> IO.iodata_to_binary/1.

Types

context()

@type context() :: %{optional(:values) => %{required(String.t()) => String.t()}}

Functions

render(canvas, context \\ %{})

@spec render(map(), context()) :: iodata()

Renders the canvas to an SVG string.

context carries the variable values used to substitute bindings ({post.title} etc.) and the consumer module key used to look up fallback example values.

to_binary(canvas, context \\ %{})

@spec to_binary(map(), context()) :: binary()

Render to a binary (the rasterizer pipes bytes via stdin). Convenience over render/2 |> IO.iodata_to_binary/1.