# `Plushie.Encode`
[🔗](https://github.com/plushie-ui/plushie-elixir/blob/v0.6.0/lib/plushie/encode.ex#L1)

Protocol for encoding Elixir values to wire-safe representations.

This protocol is called during `Tree.normalize/1`, the single value
encoding pass that converts raw Elixir values into wire-compatible
forms. Widget builders (`Build.put_if/3`) do NOT call this protocol --
values stay as raw Elixir terms (atoms, tuples, structs) until
normalization.

Key stringification (atom keys to string keys) is NOT handled here.
That happens at the wire boundary in `Protocol.Encode.stringify_keys/1`,
which runs just before serialization.

Widget authors should implement this protocol for custom value
types that need special wire encoding (e.g. a struct that should
become a specific map shape on the wire).

## Primitive implementations

- **Atom**: `true`/`false`/`nil` pass through; other atoms become strings
- **BitString**: pass through
- **Integer**: pass through
- **Float**: pass through
- **Tuple**: converted to list with recursive encoding
- **Map**: values recursively encoded
- **List**: elements recursively encoded
- **Any**: raises `Protocol.UndefinedError` (no silent passthrough)

## Struct implementations

Struct implementations live alongside their struct definitions:

- `Plushie.Type.A11y` -- strips nil fields, converts atom keys to strings
- `Plushie.Type.Border` -- encodes per-corner radius to string-keyed map
- `Plushie.Type.Shadow` -- encodes offset as `[x, y]` list
- `Plushie.Type.Font` -- encodes struct to wire font map (strips nils)
- `Plushie.Type.Padding` -- encodes struct to per-side map (strips nils)
- `Plushie.Type.StyleMap` -- encodes status overrides and nested structs

# `t`

```elixir
@type t() :: term()
```

All the types that implement this protocol.

# `encode`

```elixir
@spec encode(value :: term()) :: term()
```

Encodes a value for JSON wire format.

---

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