Layer-4 token transformer: injects data-lavash-* annotations on
HTML tag attributes so the JS hook can apply optimistic updates
client-side.
Handles seven patterns, each gated on the relevant metadata. All
patterns are no-ops in :base mode (the whole transformer
short-circuits if metadata[:layer] == :base).
Patterns
1. Form input shorthand
<input field={@form[:email]} />becomes:
<input
name={@form[:email].name}
value={@form[:email].value || ""}
data-lavash-bind="form_params.email"
data-lavash-form="form"
data-lavash-field="email"
data-lavash-valid="form_email_valid"
/>The field={...} attribute is consumed (removed from the
output). Variants exist for explicit-name inputs without the
shorthand.
2. State binding on inputs
<input value={@count} />gets data-lavash-bind="count" injected when :count is an
optimistic state field.
3. Conditional visibility
<div :if={@open}>...</div>gets data-lavash-visible="open" injected when :open is an
optimistic boolean field.
4. Enabled/disabled
<button disabled={not @valid}>...</button>gets data-lavash-enabled="valid" injected when :valid is an
optimistic boolean field.
5. Class toggle
<div class={if @active, do: "on", else: "off"}>...</div>gets data-lavash-toggle="active|on|off" injected when
:active is an optimistic boolean field.
6. Class membership
<span class={if "x" in @selected, do: "on", else: "off"}>gets data-lavash-member="selected|on|off" +
data-lavash-member-value="x" injected when :selected is an
optimistic array field.
7. Reactive attribute derives
For any attr listed in metadata[:attr_derives] (computed by
Lavash.Optimistic.Transformers.AnalyzeOptimisticTemplate), a
matching data-lavash-attr-<attr>="<derive_name>" is injected
so the JS hook can re-evaluate the attribute client-side.