Macaw.Frame.Output (macaw_frame v0.1.0)

Copy Markdown View Source

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.

Summary

Functions

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

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.

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

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

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).

Functions

classes(markup)

@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(markup)

@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(value, context, opts)

@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(classes)

@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(value, context, opts)

@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).