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

A frame document compiled (spec/02 §12.2): what `Macaw.Frame.Document.compile/3` answers
and the Frame's `init/2` holds, copied from visualize's `Visualize.Chart.Compiled` (its
struct and compile steps; its regions' closures, static strings and `rescue` sites are
not carried over).

**A value with no closure in it:** equal inputs give equal values, so any host can hold
and compare it. The fields of §12.2:

  * `design` - the concrete design: flattened, variables and facts resolved, canonical,
    validated;
  * `bound` - each variable bound to state, with the paths it stood at;
  * `theme` - the `%Macaw.Layers.Theme{}` it draws in;
  * `model` - per frame by name, the coordinate model's `module`, its `name` and the
    frame `node` it realizes (spec/03);
  * `layers` - per layer in design order: `index`, `frame`, `kind` (its name) and
    `module` (the registry's kind, `nil` when the registry lists no kinds), `channels`
    and the `scales` each channel reads, `slot` and its checked `steps`, `style` (the
    path of its style site), `label` and `tooltip` (their nodes and style sites),
    `render` and `budget`;
  * `scales` - per frame, each scale's `node`, whether it is `fixed`, the channels it
    `reads`, and for a fixed scale the `realized` scale at the current size;
  * `styles` - `sites` (each site's stack, kind, inherited defaults, laid node, its
    `per_datum` entries and its `resolved` style), `paints` (the definitions and the
    paints written in place) and `motion` (the generated stylesheet and its classes);
  * `regions` - the static and dynamic regions per frame in drawing order, each with its
    reason, and each layer's target rule (spec/10);
  * `declarations` - what the Frame declares (§12.3);
  * `contract` - each slot's contract (§7.3); `versions` the schema version each slot
    was compiled against;
  * `faults` - what applied nothing at render, by path, replaced at each realization;
  * `options` - `ceiling`, `motion`, the registries' `digests`, and the generator
    `registry` sites call through.

Beside them it keeps what its transitions re-derive from: `template` (the flattened
design before its variables), `values` (each variable's value), `missing` (the
references a flatten masked), `context` (the size, sync group, units and zone it was
compiled under) and, from `size/2`, `size`, `models` (each frame's realized model,
without data) and `ticks` (each axis's derived tick count).

**Transitions** (§12.4): `size/2` recomputes the size-dependent part, never compiling;
`bound/3` re-resolves a bound variable at its paths only; `schema/3` re-runs a slot's
facts and what they reach; `site/3` lays a site's per-datum entries over rows, its
generator faults replacing the site's in `faults`.

# `error`

```elixir
@type error() :: {:error, [Macaw.Base.Fault.t(), ...]}
```

A refusal: faults with their paths.

# `t`

```elixir
@type t() :: %Macaw.Frame.Compiled{
  bound: %{required(String.t()) =&gt; [list()]},
  context: map(),
  contract: map(),
  declarations: keyword(),
  design: map(),
  faults: [Macaw.Base.Fault.t()],
  layers: [map()],
  missing: list(),
  model: %{required(String.t()) =&gt; map()},
  models: %{required(String.t()) =&gt; Macaw.Frame.Coordinates.Model.t()},
  options: map(),
  regions: [map()],
  scales: %{required(String.t()) =&gt; %{required(String.t()) =&gt; map()}},
  size: {number(), number()} | nil,
  styles: map(),
  template: map(),
  theme: Macaw.Layers.Theme.t() | nil,
  ticks: map(),
  values: map(),
  versions: map()
}
```

# `bound`

```elixir
@spec bound(term(), term(), term()) :: {:ok, t()} | error()
```

A bound variable's new state value (§12.4): validated by its declaration where it
stands, written at the paths the variable stood at, and what reads those paths (the
styles, the scales, the regions) derived again at the current size; nothing is
flattened, read or validated elsewhere. A name no variable bound to state has is
`{:unknown, :var, name}` at `[:vars, name]`; a value its declaration refuses is the
declaration's faults under `[:vars, name]`.

# `schema`

```elixir
@spec schema(term(), term(), term()) :: {:ok, t()} | error()
```

A delivery naming another schema for a slot (§12.4): when its version differs from the
one the slot was compiled against, its facts are read again from it and steps 3 onward
run for the design, `versions` recording the new one; the same version answers the
value unchanged. Faults as `compile/3`'s.

# `site`

```elixir
@spec site(term(), term(), term(), keyword()) :: {:ok, [map()], t()} | error()
```

The styles of a site over rows (§3.13, §12.2): `{:ok, styles, compiled}`, one resolved
element style per row, the site's per-datum entries (field and generator) laid over its
node for each row, each generator called once per distinct `(name, arguments)`; a
generator result that is no style, or a name the registry lacks, applies nothing and is
a fault at the site's path in the answered value's `faults`, which replace the site's
earlier ones. `at` is a site's path (`[:layers, 0, :style]`); one compilation does not
hold is `{:unknown, :site, at}`. `opts`: `context:` the generator context.

# `size`

```elixir
@spec size(term(), term()) :: {:ok, t()} | error()
```

The compiled value at a size `{width, height}` (§12.2): every frame's model realized
without data (its plot, margins and ranges, its legend's fit), each fixed scale's
realized scale, and each axis's derived tick count, the axis's own `ticks` when it gives
them. Nothing is compiled: the design, layers, styles and declarations are untouched.

---

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