# `Macaw.Frame.Output`
[🔗](https://github.com/dcoai/macaw_frame/blob/v0.1.0/lib/macaw/frame/output.ex#L1)

The Frame's output targets (spec/10 §10.2), copied from visualize's
`Visualize.Render.to_document/2`, `Visualize.Stylesheet` (`rules/1`, `classes/1`,
`embed/1`), `Visualize.Render.to_png/2` and `Visualize.Chart.render/2` (`root: true`):
a Frame's value as a standalone document, which no page CSP governs.

- **The output target decides; there is no setting** (visualize #1103, D-296). Page
  markup writes classes and never their rules; a self-contained document carries its
  own `<style data-mw-sheet="">` holding the static stylesheet's rules its classes
  select, the first child of its first `<svg>` (`embed/1`).
- **`svg/3`** renders the Frame as one `<svg>` root in `:literal` resolution (the
  theme's colors as literals), `xmlns` set, every layer SVG as in every mode outside
  live (§2.7), embedded, tile hrefs left at the proxy route (§8), the summary as its
  `<desc>`; no motion class (a file draws the end state). It renders at the context's
  `now`, size and theme, reading no clock.
- **`png/3`** is `svg/3`'s document rasterized by `Macaw.Draw.Render.Raster` (§9), with
  `:scale`, `:background`, `:fonts`, `:resvg` and `:timeout` passed through, the Frame
  realized at `resolution: scale` (visualize D-269); its warnings are the SVG's and the
  raster's together.

# `classes`

```elixir
@spec classes(String.t()) :: [String.t()]
```

The class names the markup's `class` attributes hold, each once, in order of first
appearance.

    iex> Macaw.Frame.Output.classes(~s(<svg class="a b"><g class="b c"/></svg>))
    ["a", "b", "c"]

# `embed`

```elixir
@spec embed(String.t()) :: String.t() | {:error, [Macaw.Base.Fault.t()]}
```

Markup made self-contained: a `<style data-mw-sheet="">` holding the static
stylesheet's rules (`Macaw.Frame.Render.stylesheet/0`) that select any class the
markup's `class` attributes hold, in the sheet's order, inserted as the first child of
its first `<svg>`. Markup with no rule to embed, with no `<svg>`, or already embedded is
returned as it is, so embedding twice is embedding once.

    iex> Macaw.Frame.Output.embed(~s(<svg class="none-of-ours"></svg>))
    ~s(<svg class="none-of-ours"></svg>)

# `png`

```elixir
@spec png(Macaw.Frame.Value.t(), Macaw.Component.Context.t(), keyword()) ::
  {:ok, binary(), [term()]} | {:error, term()}
```

`svg/3`'s document rasterized (§9): `{:ok, png, warnings}`, or the raster's
`{:error, reason}`; the Frame realized at `resolution: scale`.

# `rules`

```elixir
@spec rules([String.t()]) :: String.t()
```

The rules of the static stylesheet that select any of `classes`, in the sheet's order,
each followed by a new line.

# `svg`

```elixir
@spec svg(Macaw.Frame.Value.t(), Macaw.Component.Context.t(), keyword()) ::
  {:ok, String.t(), [term()]} | {:error, [Macaw.Base.Fault.t()]}
```

The Frame of `value` as a standalone SVG document in `context` (its `now`, size and
theme): `{:ok, svg, warnings}`, or `{:error, faults}` for a value that draws nothing.
Options: `title:` and `description:` (spec/11 §3).

---

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