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

A style's compound parts (spec/02 §3.1, §3.5): their shorthands normalized on read and
the merge rule one style is laid over another by.

**Shorthands.** `normalize/1` holds a style in the full shape so a tool reads one: a
`fill` or a `stroke` written as a color is `%{type: :solid, color: c}`, `:none` is
`%{type: :none}`, `{:paint, name}` is `%{type: :paint, name: name}`; a part map with a
single `color` and no `type` is `:solid`; a gradient's `color: [a, b, …]` is its stops,
evenly spaced, `stops` winning where both are given; `curve: :step` is
`%{type: :step}` and `effect: :shadow` is `%{type: :shadow}`. A value that is neither a
part nor a shorthand stays where it stands, for the validator to name there.

**The merge rule** (`merge/2`): every top-level key of the later wins, except a part,
which merges key by key; when the two name different `type`s of one part, the later
replaces the earlier and keeps of it only what no type decides (a paint's `opacity`, a
stroke's `width`, `dash`, `join`, `cap` and `placement`). `under/3` is the same rule for
the fragment cascade, which merges the rest key by key itself.

    iex> Macaw.Frame.Style.Parts.normalize(%{fill: {:color, "bad"}, curve: :step})
    %{fill: %{type: :solid, color: {:color, "bad"}}, curve: %{type: :step}}

    iex> Macaw.Frame.Style.Parts.merge(%{stroke: %{type: :solid, color: {:color, "red"}}},
    ...>   %{stroke: %{width: 2}})
    %{stroke: %{type: :solid, color: {:color, "red"}, width: 2}}

Projection, resolution and binding are `Macaw.Frame.Style`'s (spec/02 §3.4, #34).

# `drawn`

```elixir
@spec drawn(term(), term()) :: map()
```

A projected style without the parts a layer kind does not draw (§3.8; 04-layer-kinds
§1.7.3): `parts` the kind's `parts/0`, any of `:fill`, `:stroke`, `:marker`, `:font`,
`:text`. A part a style sets that the kind does not draw is ignored, never a fault.

    iex> Macaw.Frame.Style.Parts.drawn(%{fill: {:color, "a"}, fill_opacity: 1, stroke: {:color, "b"}}, [:stroke])
    %{stroke: {:color, "b"}}

# `merge`

```elixir
@spec merge(term(), term()) :: term()
```

`over` laid on `under` by the merge rule (§3.5), both normalized first. A term that is
no style map is replaced by the later one whole.

    iex> Macaw.Frame.Style.Parts.merge(%{fill: %{type: :linear, stops: [], opacity: 0.5}},
    ...>   %{fill: %{type: :solid, color: {:color, "a"}}})
    %{fill: %{type: :solid, color: {:color, "a"}, opacity: 0.5}}

# `merge_part`

```elixir
@spec merge_part(atom(), term(), term()) :: term()
```

Two values of one part laid by the merge rule: key by key, or the later part whole but
for what no type decides when the two name different types.

# `normalize`

```elixir
@spec normalize(term()) :: term()
```

A style node with its shorthands as parts (§3.1); any other term as it is.

    iex> Macaw.Frame.Style.Parts.normalize(%{fill: %{color: [{:color, "a"}, {:color, "b"}]}})
    %{fill: %{stops: [%{at: 0, color: {:color, "a"}}, %{at: 1, color: {:color, "b"}}]}}

# `paint`

```elixir
@spec paint(term()) :: term()
```

A paint in the full shape: a color shorthand expanded, a map's type inferred where its
one color says it, a `color` list written as evenly spaced stops. A variable, a field
binding and a generator call stand where they are, since their value is a paint only
once resolved.

# `part`

```elixir
@spec part(term(), term()) :: term()
```

One part's value in the full shape, `key` the part's name; any other key's value as it
is.

# `parts`

```elixir
@spec parts() :: [atom(), ...]
```

The keys of a style that are parts, merged key by key (§3.1).

# `project`

```elixir
@spec project(term()) :: map()
```

A style node's parts projected onto the flat element keys the drawing layer reads
(§3.4): `fill`, `fill_opacity`, `stroke`, `stroke_width`, `stroke_dasharray`,
`stroke_linejoin`, `stroke_linecap`, `stroke_opacity`, `font_family`, `font_size`,
`font_weight`, `font_style`, `line_height`, `text_anchor`, `opacity`, `blend`, `effect`
with `effect_radius`, `effect_offset` and `effect_color`, `vector_effect` and `class`.
`curve`, `marker`, a stroke's `placement`, the text layout and the motion parts reach
the generator and the placement, never an element, and stay under their own keys. A
gradient or a hatch written in place is the fill or stroke `{:paint, node}`.

    iex> Macaw.Frame.Style.Parts.project(%{fill: %{type: :solid, color: {:color, "bad"}, opacity: 0.5},
    ...>   font: %{weight: :bold}, curve: %{type: :step}})
    %{fill: {:color, "bad"}, fill_opacity: 0.5, font_weight: 700, curve: %{type: :step}}

# `under`

```elixir
@spec under(term(), term(), term()) :: term()
```

What of a lower part of node kind `kind` a higher one keeps under it (§3.5): all of it,
unless the two name different types, when only what no type decides. The fragment
cascade's `under/3` hook (spec/02 §8.4).

---

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