# `Visualize.Backend`
[🔗](https://github.com/dcoai/Visualize/blob/v0.8.3/lib/visualize/backend/backend.ex#L1)

Behaviour defining the interface for rendering backends.

Backends convert the intermediate representation (IR) to their
target output format (SVG strings, Canvas commands, etc.).

## Built-in Backends

- `Visualize.Backend.SVG` - SVG string output (default)
- `Visualize.Backend.Canvas` - Canvas 2D API commands

## Configuration

Set the default backend in your config:

    config :visualize, default_backend: :svg

Or specify at render time:

    Visualize.Render.to_string(element, backend: :canvas)

## Implementing a Custom Backend

To implement a custom backend, define a module that implements this behaviour:

    defmodule MyApp.PDFBackend do
      @behaviour Visualize.Backend

      @impl true
      def path_data(path), do: ...

      @impl true
      def render_path(path, opts), do: ...

      @impl true
      def render_element(element, opts), do: ...

      @impl true
      def render_scene(elements, opts), do: ...
    end

# `options`

```elixir
@type options() :: keyword()
```

# `output`

```elixir
@type output() :: iolist() | String.t() | map() | [tuple()]
```

# `path_data`

```elixir
@callback path_data(Visualize.IR.Path.t()) :: String.t() | [tuple()]
```

Converts a Path IR to backend-specific path data.

For SVG, this returns the `d` attribute string (e.g., "M10,20L100,200Z").
For Canvas, this returns a list of drawing commands.

# `render_element`

```elixir
@callback render_element(Visualize.IR.Element.t(), options()) :: output()
```

Renders an Element IR tree to the backend's output format.

# `render_path`

```elixir
@callback render_path(Visualize.IR.Path.t(), options()) :: output()
```

Renders a Path IR to the backend's output format.

Options may include style information and other backend-specific settings.

# `render_scene`

```elixir
@callback render_scene([Visualize.IR.Element.t()], options()) :: output()
```

Renders a complete scene (list of elements) to output.

# `wrap_root`
*optional* 

```elixir
@callback wrap_root(output(), options()) :: output()
```

Wraps content in a root container.

For SVG, this wraps in `<svg>` tags. For Canvas, this may generate
the canvas element and setup code.

This callback is optional.

# `default`

```elixir
@spec default() :: module()
```

Gets the configured default backend module.

# `resolve`

```elixir
@spec resolve(atom() | nil) :: module()
```

Resolves a backend from various inputs.

Accepts:
- `nil` - returns the default backend
- `:svg` - returns `Visualize.Backend.SVG`
- `:canvas` - returns `Visualize.Backend.Canvas`
- A module atom - returns the module directly

---

*Consult [api-reference.md](api-reference.md) for complete listing*
