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

Presets as registered fragments (spec/02 §14), replacing visualize's
`Visualize.Chart.Presets` and its function components: a preset is a stored composite
or design fragment with its variables declared as parameters, found by name and placed
as any fragment is. Nothing is a function component.

A preset is a module implementing this behavior. **The registry is explicit and default
closed** (`registry/1`), built from the packages a host lists, each package's
`__members__/0` read for the modules implementing it; a name two presets claim is a
fault of the registry, and every preset's fragment is checked with its kind's per-kind
validity (`Macaw.Frame.Document.validate/2`), each fault under the preset's name.

**A preset is used by its fragment** (`fetch/2`): a host stacks it under a design's own
layers, binds its variables at a site (`Macaw.Layers.Use` with `vars:`), or copies it
into its store. It is never referenced by name from inside a document. visualize's ten
presets become registered presets with the catalog's designs (spec/13); none is
registered in macaw_frame's package until then.

    iex> Macaw.Frame.Preset.registry([])
    {:ok, %{}}
    iex> Macaw.Frame.Preset.fetch(%{}, "bar_chart")
    :error

# `registry`

```elixir
@type registry() :: %{required(String.t()) =&gt; module()}
```

A registry of presets by name.

# `doc`

```elixir
@callback doc() :: String.t()
```

What it draws, for a person and a catalog.

# `fragment`

```elixir
@callback fragment() :: map()
```

The fragment: a composite, or a design, with its variables and slots declared.

# `name`

```elixir
@callback name() :: String.t()
```

The preset's name, unique in a registry (`"line_chart"`).

# `fetch`

```elixir
@spec fetch(term(), term()) :: {:ok, map()} | :error
```

A preset's fragment by name, read by spelling: `{:ok, fragment}` or `:error`.

# `names`

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

The registry's preset names, sorted.

# `preset?`

```elixir
@spec preset?(term()) :: boolean()
```

Whether a module implements every callback of the behavior.

# `registry`

```elixir
@spec registry(term()) :: {:ok, registry()} | {:error, [Macaw.Base.Fault.t(), ...]}
```

The registry of the presets the packages hold: `{:ok, %{name => module}}`, or every
fault at once: a module that is no package `{[:packages, i], :not_a_package}`; a name
two presets claim `{[:presets, name], {:named_twice, module, other}}`; a preset's
fragment that no kind fits `{[:presets, name], {:type, :fragment}}`, and its per-kind
validity's faults under `[:presets, name | path]`.

---

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