---
title: "Events"
description: "An event binding is an action reference or partially applied action."
modificationDate: "2026-11-30"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Events

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/reference/contract-grammar/events: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

An event binding is an action reference or partially applied action. Captured
arguments precede the event payload. The table names every handler `contract vocab` lists.
Numeric multi-argument payload ordering should be copied from the feature's
working fixture, not inferred from JavaScript's Event interface.

These events bubble, as in the DOM: `key` and `keyup` from the focus,
`focusin` and `focusout` from the element gaining or losing focus,
`pointerdown`, `pointerup` and `pointercancel` from the node pressed, and `wheel` from the node
under the pointer, each to every ancestor that declares it, innermost first
(`keycapture` goes outermost first). An action that calls `stopPropagation()`
stops that event at its handler, as DOM's
[`Event.stopPropagation()`](https://dom.spec.whatwg.org/#dom-event-stoppropagation)
does: no handler after it hears that event. The stop is that event's alone. A
stopped `pointerdown` still sends its `pointerup` to every node it passed, and
the pointer's moves stay with the node that holds them. The event's default
action still happens: only `preventDefault()` stops a key's typing, a
wheel's scroll or a press's focus move, and a stopped `pointerdown` or
`pointerup` leaves the click's `press` alone. A `pointerdown` action that
calls `preventDefault()` keeps the focus where it is, places no caret and
starts no selection, as Chrome's does, by mouse and by touch; the `press`
still fires, and an action's own `focus()` still moves the focus. (On iOS a
field that already has the focus still places its caret where the touch
lifts; LLP 1005 §3.) A formatting toolbar keeps its editor focused so:

```text
action keep(e: PointerEvent)
  preventDefault()
button pointerdown=keep press=bold …
```

`press` is DOM's `click` stopped at its handler: a press goes to the nearest
node from the one pressed up that takes a press (a `press` handler or a
link), and to no node above it. Content in an open popover or a modal
`dialog` presses the popover's or dialog's authored ancestors, as a click
bubbles out of the top layer, never a node only under it: a modal dialog's
ancestors take that press though the dialog makes them inert, while an
authored `inert` still silences them. That ancestor's own box is seldom
under the pointer, so the press lands as the content it went down on judges
its own: a pointer that leaves that content before it lifts presses nothing.
A press that reaches an invoker (`commandfor`, `popovertarget`) behind a
modal dialog runs its `press` handler, and opens or closes its target only
where the target is inside the modal's subtree; a target the modal makes
inert stays as it is, as a `contextPopover` on an ancestor behind the modal
opens no menu.

On the web, a modal `dialog` stays in the top layer while its
`-exact-exit-animation` plays. Its `close` event and focus return follow the
animation. Reduced motion closes it immediately. An unpositioned modal
dialog uses the browser’s viewport positioning.

A text field, a checkbox or another form control takes a tap or a click
itself, so an ancestor's `press` does not fire, in the page or in a dialog.
That is the platform's rule on macOS and iOS (a hand-built screen's control
consumes its touch, LLP 1115);
on the web the click bubbles from the control to the ancestor. A `press`
written on the control itself gives the same result on every host. A
`button` with no `press` of its own presses the nearest ancestor's on every
host.

| Payload appended to captured arguments | Handler names |
| --- | --- |
| A string, then optionally an `InputEvent` | `change`, `input` on a text field, textarea, `select`, date or time input, and `type="radio"` (the radio's `value`); an action taking one more parameter also hears the [target](https://exact.expo.dev/reference/contract-grammar/events.md#form-controls-radio-inputevent-setselectionrange) |
| A tag string, then optionally a `NotificationEvent` | `notificationshow` on the root for a local post presented while visible, and `notificationclick` for a click ([notifications](https://exact.expo.dev/reference/developer/generate-typescript-data-source-types.md#notifications)) |
| One string | `message`, `error`, `pictureinpictureerror` (why picture in picture failed) |
| A string, then optionally a `KeyboardEvent` | `keycapture` (capture-phase `keydown`), `key` (bubble-phase `keydown`) and `keyup`: the key's name; an action taking one more parameter also hears the [modifiers, the physical key and whether it repeats](https://exact.expo.dev/reference/contract-grammar/events.md#keys) |
| Two numbers, then optionally a `ScrollEvent` | `scroll`: left and top; an action taking one more parameter also hears the scroller's extents (below) |
| Zero or one `IntersectionObserverEntry` | `intersect`: `isIntersecting` (bool) and `intersectionRatio` (number), mount then enter/leave at threshold 0; the web, AppKit, UIKit and Linux |
| Two numbers, then optionally a `DOMRectReadOnly` | `resize` given an action: the content box's width and height; an action taking one more parameter also hears its `contentRect` (below). A string `resize` is CSS's property |
| One boolean | `hover`; `fullscreenchange` (whether the video is now full screen) |
| One boolean, then optionally an `InputEvent` | `change`, `input` on a checkbox or `switch` |
| One number | `timeupdate`, `durationchange` |
| One number, then optionally an `InputEvent` | `change`, `input` on `type="range"` |
| One `Picked[]`, then optionally an `InputEvent` | `change`, `input` on `type="file"` |
| One `MarkdownSelection` | `select` on the Markdown editor (`textarea markup="markdown"`) |
| One `InputEvent` | `select` on a text field or any other `textarea` ([form controls](https://exact.expo.dev/reference/contract-grammar/events.md#form-controls-radio-inputevent-setselectionrange)) |
| Two numbers | `pan`, `panrelease`, `heightrelease` |
| Three numbers | `pinch`, `pinchrelease` (scale, viewport x, viewport y) |
| A string, an `option<string>`, then optionally a `ReorderEvent` | `reorderdrop`, on a vertical `list virtualized=true` only: the dragged row's key, then the key it lands before (`none` at the end); an action taking one more parameter also hears `ReorderEvent { from, to }`, the two lists' `id`s (equal within one list; LLP 1094 D2) |
| Four numbers | `transformgeometry` |
| Six numbers | `transformrelease` |
| Special: zero or one location string, no captured args | `navigate` |
| Zero or one `PointerEvent` (the action takes it or leaves it) | `pointerdown`, `pointerup`, `pointercancel`, `pointermove`, `contextmenu` (UI Events makes it one: where the secondary click or long press was; a keyboard's menu key targets the focus) |
| Zero or one `WheelEvent` (the action takes it or leaves it) | `wheel` |
| Zero or one `HistorySwipeEvent` (the action takes it or leaves it) | `historyswipe`, on the navigation root |
| Zero or one `ScrollDragEvent` (the action takes it or leaves it) | `scrolldragend`: the release velocity and where the scroll will stop (below) |
| Zero or one `DragEvent` (the action takes it or leaves it) | `drop`, `dragenter`, `dragover`, `dragleave`, `dragstart`, `dragend` |
| Zero or one `ClipboardEvent` (the action takes it or leaves it) | `copy`, `cut`, `paste` ([clipboard](https://exact.expo.dev/reference/contract-grammar/events.md#clipboard)) |
| Zero or one `FocusEvent` (the action takes it or leaves it) | `focusin`, `focusout`: `target` is the focused element's `id` (or `""`); `relatedTarget` is `some(id)` for the other element or `none` |
| Zero or one `Selection` (the action takes it or leaves it) | `selectionchange`, on a `text` ([text selection](https://exact.expo.dev/reference/contract-grammar/events.md#text-selection)) |
| Zero or one `InputEvent` | `selectionchange` and `beforeinput`, on a plain text field |
| Zero or one `MediaSessionActionDetails` (the action takes it or leaves it) | `seekbackward`, `seekforward`, `seekto`, `previoustrack`, `nexttrack`, `stop`, on an `audio` or `video` with `metadata=` ([media session](https://exact.expo.dev/reference/contract-grammar/events.md#media-session)) |
| Zero or one `ToggleEvent` (the action takes it or leaves it) | `toggle`, on a popover: `oldState` and `newState`. It fires at the popover, never at the button that opens it, so on an element with no `popover` it is refused (`lower-handler-tag`) |
| Zero or one `AtomEvent` (the action takes it or leaves it) | `atompress`, on a node with `atoms=` ([inline atoms](https://exact.expo.dev/reference/contract-grammar/built-in-tags.md#inline-atoms-atom-atoms-atomfaces-atompress)) |
| Zero or one frame record (the action takes it or leaves it) | on an `iframe`: `currententrychange`, `navigatesuccess` and `navigateerror` (`FrameNavigation`), `capture` (`FrameCapture`), `download` (`FrameDownload`), `newwindow` (`FrameNewWindow`) and `userpromptopened` (`FrameUserPrompt`) |
| Zero or one `MIDIMessageEvent` (the action takes it or leaves it) | `midimessage`, on an element with `midiinputs=` ([MIDI](https://exact.expo.dev/reference/contract-grammar/components-and-actions.md#midi-exactmidi-sendmidi-midimessage)) |
| Zero or one `MouseEvent` (the action takes it or leaves it) | `press`: the modifier keys held, `shiftKey`, `ctrlKey`, `altKey`, `metaKey` (a shift-click, a ⌘-click; all false from a keyboard or assistive activation), and where the pointer was, `clientX`, `clientY`, from the viewport (0, 0 from a keyboard or assistive activation, as Chrome's; a popover's `left`/`top` can open it there, LLP 1021 D2) |
| None | `enterpictureinpicture`, `leavepictureinpicture`, `beforeunload`, `cancel`, `close`, `scrollend`, `scrolldragstart`, `focus`, `blur`, `submit`, `load`, `dblclick`, `swipe`, `refresh`, `loadedmetadata`, `play`, `playing`, `pause`, `ended`, `waiting`, `seeking`, `seeked`, `ratechange`, `volumechange`, `canplay`, `reachstart`, `reachend` |

On text fields and textareas, `input` reports every edit. An `input` handler
should update raw draft state so live search, validation and button enablement
follow typing. `change` reports a committed value: Enter or blur for a text
field, the end of editing for a textarea. Its handler should normalize the
draft. Use `submit` for explicit submission. Checkboxes, switches and selects
use `change` when a value is chosen.

A dialog's `close=action` runs after dismissal and focus restoration on the web,
macOS and iOS, whether an action, an invoker button or Escape closed it. It takes
no payload. Closing an already-closed dialog fires nothing; removing a dialog or
resetting the session does not fire `close`.

An `audio` is HTML's: `video`'s props and events without `poster`, `playsinline`
or `playbackVisibilityThreshold`; no box unless `controls` (then Chrome's 300×54,
which `width`/`height` override), whatever `display` says
(LLP 1042 §8).
A `video`'s or `audio`'s `error` appends a stable code, never the engine's text: MediaError's
`aborted`, `network`, `decode` and `src-not-supported` (a source that never loaded),
`not-allowed` (the browser refused to start playing) or `invalid-value` (a number out
of range). A play interrupted by a pause or a new source is no error. A `video` the
tree removed reports nothing more, on every host
(LLP 1042 §3).

## Media session

`metadata=MediaMetadata(title=…, artist=…, album=…, artwork=…)` on an `audio`
or `video` claims the platform's media session (Now Playing, the media keys, the
lock screen; LLP 1098). `MediaMetadata`
is a compiler shape an app builds as it builds its own records (every field a
string, each named once; `artwork` is one image's source), so a `fn` may return
one; an app's own `shape MediaMetadata` or `fn MediaMetadata` is refused. The
element's six actions append a `MediaSessionActionDetails { action: string,
seekOffset: number, seekTime: number, fastSeek: bool }` to an action that takes
one: `seekOffset` is the platform's, else the element's `seekbackwardOffset` or
`seekforwardOffset` (seconds, greater than 0, default 10), 0 for the other four;
`seekTime` is `seekto`'s. An action or an offset on an element without
`metadata=` is `lower-media-session`. The platform's play and pause act on the
element, whose own `play` and `pause` events report them; the session's position
and playback state are the player's. Of several claimants, the one that most
recently started playing owns the session (else the latest mounted).
`scroll` appends left then top offsets, and to an action that takes one more
parameter a `ScrollEvent`: the scroller's own `scrollLeft`, `scrollTop`,
`scrollWidth`, `scrollHeight`, `clientWidth` and `clientHeight` as the event
fires, what a web handler reads off `event.target`, and `scrollZoom`, a
zoomable scroller's zoom (1 on any other; LLP 1057.001.000). "At the end" is the web's
arithmetic, on every host and on a virtualized list too (chat F4, a
jump-to-latest pill); a native host's `scrollHeight` is its port plus the range
it clamps to:

```text
action moved(x: number, y: number, e: ScrollEvent)
  away = e.scrollHeight - e.scrollTop - e.clientHeight > 1
list appearance="none" virtualized=true scroll-start="end" scrollFollowEnd=true scroll=moved …
```

On a virtualized list, the record also carries `firstVisibleKey: option<string>`
and `firstVisibleOffset: number`: the first row intersecting the port, and the
signed distance in CSS pixels from its wrapper's start to the port's start,
on the list's axis. Keys are text (numeric and boolean keys use their text
representation). The snapshot uses the event's offset and the list's latest
measured/estimated sizes; zero-size rows are skipped. An ordinary scroller,
an empty list, or a port showing only padding reports `none` and `0`.

The app can save these two fields by document or conversation and restore
after mounting the list with `scrollIntoView("feed", key, offset=within)`.
`offset=` is a finite number and belongs only to the list form. It places the
port that many pixels into the keyed row wrapper, overriding that list's
`block`/`inline` alignment and scroll-padding, clamped to the scroll range.

A virtualized list mounts the rows near its port and unmounts the rest.
`keep-mounted=` names rows that stay mounted wherever the window is: a list of
up to 64 keys as the `for`'s `key=` gives them, each possibly an `option`
(`none` names no row), computed or literal. A screen reader moves only through
mounted rows, so a transcript keeps its first and last message,
`keep-mounted=[first(ids), ids.at(-1)]`; a row playing audio keeps its player.
A key the list does not hold is passed over; another value keeps none and
says so in the journal (LLP 1010 §6.11).

`scroll-padding` (or its four physical sides) insets any scroll container’s
alignment port. It takes nonnegative lengths and percentages; negative literals
are refused. A calculation's negative result clamps to zero.
`scroll-margin` expands the target element’s border box for
`scrollIntoView`; its signed lengths change neither layout nor scroll range.
Scroll margins refuse percentages, including inside `calc()`, `min()`, `max()` and `clamp()`.
Padding percentages use the corresponding scrollport dimension on ordinary
scrollers; a virtual list still requires resolvable main-axis lengths.
Negative offsets preserve padding showing before the row. With `row=`, only
the inner list takes the offset; the outer row aligns normally. Unmounting a
top-level list saves nothing automatically, with either `scroll-restoration`
value.

As on the web, the event comes when the offset changes (a follow of the end
moves it); content that grows below a reader who is not following it changes
no offset and sends none.

`scrollend`, on a `scroll` or a `list`, comes once a scroll that moved the
offset is over, after its last `scroll`: the finger lifted with nothing thrown,
the momentum or a smooth scroll stopped, or (a jump, a mouse wheel's notches)
the offset still for 100 ms on Apple's hosts. It takes no payload. An app that
needs to know a fling has stopped hears it, instead of restarting a timer on
every `scroll`. Linux and the shared Android Presenter complete notches and
instant jumps at the next delivery point. Android's drag ends at the lift
when nothing is thrown and when its fling stops, however long a finger rests on
the list meanwhile; other reader samples use 100 ms quiet.
Delivery uses the existing host clock after its runner work, so a late wake may
run a later timer first. Android device qualification remains open (LLP 1005,
“Linux, first step”).

`scrolldragstart` and `scrolldragend`, on a scroller, bracket a drag of it by
the reader: UIKit's `scrollViewWillBeginDragging` and
`scrollViewWillEndDragging(_:withVelocity:targetContentOffset:)` (Charlie,
2026-11-10). The start comes once the drag moves the scroller and takes no
payload; the end comes as the finger lifts, before that drag's momentum
`scroll`s and its `scrollend`. An action taking one parameter hears the end's
`ScrollDragEvent`: `velocityX` and `velocityY`, UIKit's velocity in its own
units, CSS pixels (points) per millisecond, positive in the direction
`scrollLeft` and `scrollTop` grow (a flick up the page that will scroll further
down is positive `velocityY`), and `targetLeft` and `targetTop`, `some` offset
where the scroll will come to rest when the host knows it before the momentum
runs (UIKit), else `none`. A collapsing header tells a flick from a bounce by
it:

```text
action released(e: ScrollDragEvent)
  headerShown = e.velocityY < -0.5
scroll scrolldragend=released …
```

A mouse wheel, the keyboard and a programmatic scroll send neither event.
iOS hears UIKit's delegate calls, and its target is where the scroll will rest
after any snap. AppKit has no such calls: macOS takes a trackpad's two fingers
as the drag, from the first move the scroller takes to the lift, and estimates
the velocity from the moves of the last 100 ms, with no target. The web takes a
touch on the scroller, from its first `scroll` under the finger to the last
finger's lift, with no target and the finger's velocity over its last 100 ms
of moves (UIKit's is the pan's too), 0 if it rested that long before
lifting; a mouse or a pen sends neither. Android takes a finger's drag of each
scroller it moves (an outer one the hand-off reaches too), from the drag's first
move of it to the lift, with the platform's velocity (`VelocityTracker`) and, as the target, where
the fling will rest (`OverScroller`), or where the scroller is when nothing is
thrown. Linux and Windows scroll by no drag and send neither.

`intersect=action` offers an optional final `IntersectionObserverEntry` after
any authored arguments. The record contains `isIntersecting: bool` and
`intersectionRatio: number`. The nearest ancestor CSS scroll container is the
root, otherwise the viewport; threshold is fixed at 0. `intersect-margin` is a
literal rootMargin string (one to four px/% lengths, default `"0px"`). It fires
on mount and enter/leave, not every ratio change; removal stops observation
without a leave event. Both web targets implement it; native delivery remains
owed (LLP 1005, "Intersection visibility").

`resize` is two things, told apart by its value, as nowhere else: a string
(`resize="none"`) is CSS's `resize` property, and an action is the element
resize event, `ResizeObserver`'s. Its action hears the content box's width
and height after layout: once the element is first laid out, then whenever
its content box changes size (a commit that leaves it alone says nothing; one
under `display: none` reads 0 by 0). A box that straddles the columns of a
multi-column flow is one column wide and as tall as its pieces end to end, as
Chrome reports it, while `frame()` answers its union (LLP 1093 D11). One more
parameter hears the entry's `contentRect`, a `DOMRectReadOnly`: `x` and `y` the padding's left and top,
`width`, `height`, `top`, `right`, `bottom`, `left`. The web observes with
the browser's `ResizeObserver`; a native host delivers after its layout and
lays out again before the next round, each round only to elements deeper than
the shallowest the last one reached, as the browser's loop does, so a handler
that keeps growing its own box cannot spin: what is left is delivered after
the next layout and the log says `ResizeObserver loop completed with
undelivered notifications`. Geometry inside the action is `frame(id)`:

```text
action fit(w: number, h: number)
  columns = floor(w / 240)
column resize=fit …
```

`pan` supplies the move since its last event (dx, dy),
the first one since the press, so their sum is the drag's offset from the press. `panrelease` appends x/y release velocity;
`heightrelease` appends height and velocity. A `pan` hears a drag that starts
anywhere inside it, a nested `button` or `press` node included: past the slop
the pan takes the contact and the press does not fire, while a tap still
presses. A nested text input or control keeps its own drags, and the innermost
recognizer wins (LLP 1057.001 §1).
The compiler validates arity and
available payload types; tags and hosts constrain where events make sense.
`navigate` belongs on the first root element, outside any region, which must
also carry `navigationKey` (the navigation root; its `navigationBack`, naming the
Back control, is optional). `historyswipe` belongs there too: on macOS it
hears the two-finger swipe back or forward as AppKit tracks it, so an app can
draw its own sign of the swipe (an arrow at the window's edge) while the step
stays the platform's (LLP 1115.000
D5.5). Its `HistorySwipeEvent` has `phase` (`"began"`, `"changed"`, then
`"ended"` just before the step or `"cancelled"` when the lift goes nowhere),
`direction` (`"back"` or `"forward"`, the way the swipe set out), `amount`,
AppKit's `gestureAmount` along that way (0 at rest, 1 a whole page; a slow lift
steps from about 0.25 on macOS 27, a quick one from less), and `clientX` and
`clientY`, where the pointer was as the swipe began. The swipe follows
System Settings › Trackpad › Swipe between pages, so with it off nothing comes.
The web's browser draws its own arrow and tells the page nothing, so the web,
iOS, Linux and Windows send none. The root's `navigationHistory` says which
ways through history it offers now: `"back forward"`, the default, offers each
wherever the router has somewhere to go, and `"back"`, `"forward"` or `"none"`
withholds the rest. Bind it when the app's own Back and Forward go less far
than its router's visits (a palette open over the page, a history capped at so
many visits). On macOS a way withheld is no swipe AppKit tracks, so no
`historyswipe` either, and no Go ▸ Back or Forward or mouse side button; the
web's history is the browser's, and the other hosts ignore it. Transform geometry/release
bindings are required as a pair. See
[`handler_arity`](https://github.com/expo/exact/blob/41ded8c5ede0b2959ef0daa83b1ff78545dd4428/contract/analyze/src/lib.rs) and the corresponding corpus/tests.

Any node, including a `list` or `scroll`, can bind `pinch=action` and
`pinchrelease=action` independently. Each appends `(scale, x, y)` after any
bound arguments. Scale is positive and relative to the initial span (1). The focal point
uses `PointerEvent.clientX` and `clientY` coordinates. Movement reports
`pinch`. The first lift ends the pair with one `pinchrelease` carrying the scale and focal point
from the last moment both fingers were down. Cancellation releases at scale 1. Both
bindings observe alongside one-finger scrolling and pointer events. On iOS and iPadOS,
UIKit delivers both bindings; other hosts accept them and stay silent
([reporting a pinch](https://exact.expo.dev/reference/developer/interactive-stress-examples.md#reporting-a-pinch)).

## Pointer

`pointerdown`, `pointerup`, `pointercancel` and `pointermove` are DOM's, on every host. A
touch or a button going down (any: `buttons` says which, 2 for a right-click)
is the `pointerdown` of every enabled node from the one under it up that
declares it, innermost first, as `key` and `wheel` bubble, before any gesture
decides; a press inside a popover or a modal dialog reaches its authored
ancestors, never a node only under it. A lift sends `pointerup` before the click's `press`. A cancelled contact
sends `pointercancel` instead, before a begun pan's `panrelease(0, 0)`.
Each terminal event visits the nodes the down passed, innermost first,
wherever the pointer is. The innermost enabled node that hears any pointer event holds the pointer: its
`pointermove`s follow the pointer wherever it goes until it lifts, and a
`pointermove`, or a `pan` that takes the contact, takes no ancestor's down
or up. A node disabled when the pointer goes down hears none of them, and
its ancestors still do. A handler's `stopPropagation()` stops the down or up
it hears there ([Events](https://exact.expo.dev/reference/contract-grammar/events.md)). A free pointer (a mouse or a pen
hovering, no button down) moving over a node is that node's `pointermove`
too, the innermost hearing it; a touch has none. Moves go out at most once a frame,
the latest. None of them takes anything from `press`, `pan` or scrolling, so
a drawing surface sets `touch-action="none"`, as on the web, or a touch
that scrolls is cancelled.

A mouse's back and forward buttons go Back and Forward at their release, as
Chrome's do, after their `pointerdown` and `pointerup` (`button` 3 and 4); a
`pointerup` handler's `preventDefault()` keeps the page where it is
(LLP 1115.000 D5.5).

An action that takes one more parameter than the binding captures gets a
`PointerEvent` (DOM's names, LLP 1056 §8.6):

| Field | Meaning |
| --- | --- |
| `offsetX`, `offsetY` | The point from the node's content box, CSS px (DOM measures from the target's padding edge; a canvas draws in its content box) |
| `button` | The button that went down or came up, DOM's number: 0 primary, a touch or a pen's contact; 1 auxiliary; 2 secondary; 3 back; 4 forward; -1 on a move |
| `buttons` | DOM's bits: 1 primary, a touch or a pen in contact; 2 secondary; 4 auxiliary; 8 back; 16 forward; 0 on `pointerup` and a hover |
| `pressure` | 0 to 1: a pen's or a pressed touch's force where the platform measures one, else 0.5 while down and 0 while not |
| `pointerType` | `mouse`, `pen` or `touch` |
| `pointerId` | 1 for the mouse; a touch or pen has its own while down |
| `clientX`, `clientY` | The point from the viewport, CSS px: `frame()`'s space, so a hit test against `frame` needs no scroll bookkeeping (LLP 1094 D11) |
| `shiftKey`, `ctrlKey`, `altKey`, `metaKey` | The modifier keys held (a hardware keyboard's, on iPadOS) |

```text
action stroke(e: PointerEvent)
  points = `${points} ${e.offsetX},${e.offsetY}`
canvas surface=ink(points) pointerdown=begin pointermove=stroke touch-action="none"
```

A `contextmenu` (a right-click, a long press) offers the same record: on a Mac
and in a browser on one it comes on the button's down, after its `pointerdown`.
A Control-click there is a secondary click too: where a `contextmenu` or
`contextPopover` answers it, it holds the primary button and Control, and
nothing presses. A secondary click in a modal dialog reaches an ancestor's
`contextmenu` behind it, but that ancestor's `contextPopover` stays shut,
since the modal makes it inert; a press bubbling to an invoker behind the
modal follows the same rule ([Events](https://exact.expo.dev/reference/contract-grammar/events.md)).
On Apple hosts, the unmodified `ContextMenu` key and Shift+F10 open it at the
focused node's centre, after `key` handlers run, with `buttons=0` and
`pressure=0`. A `key` handler's `preventDefault()` cancels it. The nearest
`contextmenu` handler runs before its `contextPopover` opens; either declaration
is sufficient. A text field keeps its editing menu. Drive it with
`type "row" key "ContextMenu"` or `type "row" key "Shift+F10"`. UIKit presents
keyboard-invoked actions through its native menu without the long-press preview.
Disabled controls and inert nodes do not open menus. On macOS a request that
no node answers, from the key or from VoiceOver's show menu, gets the menu a
right-click at that point would show, as Chrome shows its own menu then: the
menu of the view drawn there or above it (selected text's), else whatever
answers past the session's view (an embedder's or an app's responder). No
`pointerdown` or `contextmenu` fires, and selected text keeps its selection.
With nothing focused and text selected, the key opens at the selection's first
line, as Chrome's does. The web shows the browser's own menu; the other hosts
have no page menu to show.

`wheel` is DOM's: a wheel's turn or a trackpad's scroll over the node, heard by
every node from it up that declares it, innermost first. Its `WheelEvent` is
`offsetX`, `offsetY`, `deltaX`, `deltaY` (CSS px; positive scrolls down and
right), `deltaMode` (0 pixels) and the four modifiers. A trackpad's pinch is a
wheel with `ctrlKey` and `deltaY` of -100 × its magnification, as browsers
deliver one. An action that calls `stopPropagation()` stops the wheel at its
handler and leaves the scroll alone; one that calls `preventDefault()` keeps
the scroll from happening (web, macOS, Linux; iOS has none). On macOS a
trackpad gesture that a scroller scrolls reaches the handler only in its first
events, since AppKit runs the rest on its scrolling thread, unless the handler
prevents them or the scroller snaps or has a `scrolldragstart` or
`scrolldragend` handler:

```text
action wheeled(e: WheelEvent)
  if e.ctrlKey or e.metaKey
    zoom = zoom * (1 - e.deltaY / 100)
    preventDefault()
scroll wheel=wheeled …
```

`drop` is DOM's `drop` of what another app drags in (Finder, Explorer, Photos,
a browser, another Exact app) onto the innermost node that declares it, when
the drag carries files, plain text or a link and its source allows a copy
(LLP 1094.001): its `DragEvent` is `offsetX`, `offsetY`, `files` (a
`string[]` of `doc:` handles minted as a picker's are, LLP 1069.010 D1,
readable under `fs.read doc:/`), `text`, `url`, `dropEffect` (`"copy"`, the
operation Exact takes), the modifiers, and `clientX` and `clientY` (the point from the viewport, `frame()`'s space). `text` is
the drag's plain text, its items' joined by line breaks; `url` is its first
link that is not a file (a `file:` URL is a file), of any scheme, so check
it before following it. Each is `""` when the drag has none, so a link
whose source gives no plain text has `text` `""`. Each file
arrives as a `doc:` handle, whatever its type, on the hosts that take files (the reference's table), and a dropped folder, on a host that takes one, is a folder's handle (`fs.stat` says
`isDirectory`, `fs.readdir` lists it); the app never learns an absolute
path. A dropped file is lent, not given: its handle reads the source's file,
which may change or be deleted, or the session's copy, and a handle not kept
ends with its window, so an app copies an attachment it keeps into
`app:/data` ([recipe](https://exact.expo.dev/recipes/drag-in.md)). A drag with files over an `input` or a `textarea` inside such a node
is the node's, as on the web, where its listener prevents the field's own
drop: the field inserts no path text. A drag of text over a field is the
field's, which inserts it, unless the field itself declares `drop`. On the
web a field takes only plain text, as HTML inserts it, so a link with no
plain text goes to the `drop` above; a macOS field takes links too. On
Windows a field takes no drag, so any drag goes to the `drop` above unless
the field itself declares `drop`. While a drop waits for its files, the
nodes it was over defer the next drag's `dragenter`, so the waiting drop's
action cannot clear what the next drag drew: it is heard when the waiting
drops land or when the next drag drops, and the next drag's leave cancels it. Web, macOS
and Windows deliver files in the order the source supplies them, and macOS
receives a promised file (Photos', an Exact app's) before the action runs.
A browser without `getAsFileSystemHandle` hands the app read-only copies.
iOS and iPadOS take a drag from another app or from the same one through
UIKit's drop interaction, a file as a copy and no folder; a field there
keeps text, links and text files, and the text of a drag that also carries
files, as UIKit's text views do. Android takes one from another app or
from the same one, a file as a copy of its `content:` item and no folder,
and no `file:` path, which another app cannot share; a field there keeps
text, links and text files, as Android's text views do, unless the field
declares `drop`, and gives a file to the `drop` above it. Android's apps
send a link as text, so Android alone makes `url` from text: while a drop
has no `url` yet, a text item whose whole last line is an `http://` or
`https://` link gives that link as `url`, and its lines before it, such as
the title Chrome sends, as `text`. Linux's Wayland window takes a drag from another app, or
from its own window, as a copy: its files and folders in place, its text, and its link from
the URI list or the titled link a browser sends; its fields take no drag, and Wayland tells it
no keys, so a drop's modifiers are those the window holds. In a Flatpak sandbox it takes a
drag's files from the document portal's file transfer key, else only those the sandbox shares
with the host. A drop
waits for a source still copying its files until the source ends or another drop is taken. tvOS and the terminal take no drop. The driver's
`tap <target> drop [<path…>] [--text "…"] [--url "…"]` drops files,
folders (not on iOS or Android), text and a link, at least one of them, as a test's
`tap "zone" drop …` step does.

`dragenter` and `dragleave` are DOM's, as a node hears them when it ignores
moves between its own descendants (the `currentTarget.contains(relatedTarget)`
test a drop overlay makes): a node that declares one hears `dragenter` when
a drag from another app comes over its box, and `dragleave` when it leaves
the box or is cancelled. A drop a node takes sends `drop` and no
`dragleave`, as the DOM's does: the drop's action clears what the enter drew,
an ancestor's overlay included, since it is the app's state. A drop no node
takes, one a field takes, and one that carried nothing that arrived send
`dragleave` instead. Their `DragEvent` has the point and the modifiers and
no data (`files` `[]`, `text` and `url` `""`, `dropEffect` `"none"`), which
the DOM keeps from a page until the drop. They are heard whether or not a `drop` will take the drag, so
an overlay can say where it would land:

```text
state over = false
state paths = []
action entered
  over = true
action left
  over = false
action took(e: DragEvent)
  over = false
  paths = e.files
column dragenter=entered dragleave=left drop=took position="relative"
  textarea placeholder="Message"
  if over
    column position="absolute" inset=8 pointer-events="none" border-width=2 border-style="dashed" align-items="center" justify-content="center"
      text "Drop files to attach" role="status"
```

The web, macOS, iOS, Android, Linux and Windows support these events; tvOS and the terminal take no drag. The driver's
`tap <target> dragenter [<path…>] [--text "…"] [--url "…"] [at <x> <y>]` brings that drag over the target, at that
point from its top left or its middle, and leaves it there (for a screenshot); another `dragenter` with the same
paths, text and link moves it; `tap <target> drop … [at <x> <y>]` drops it, and `tap <target> dragleave` takes it
away undropped.

`dragover` is DOM's `dragover` heard as a notification (LLP 1094.000 D18): a node that declares it hears where a drag
is while it is over its box, to draw where a drop would land, such as the line between two rows. It decides
nothing: what a drop there does is still what `drop` declares. Each node under the drag that declares it hears it,
innermost first, at its own offsets, at most once a display frame and only when its record changed: the offsets,
`clientX` and `clientY`, the modifiers, or its `dropEffect`, which is `"copy"` when a release there would deliver
the drop to this node and `"none"` otherwise (over a nested `drop`, over a field that keeps the drag, or where nothing
takes it). A still drag over content that scrolls or moves hears the new point; one held still over still content
hears nothing more. It comes after the node's `dragenter`, none comes after its `dragleave` or the drop, and the drop
carries its own point, which an action places by:

```text
state rows = ["Fuji", "Rainier", "Hood"]
state line = -1
action moved(e: DragEvent)
  line = e.dropEffect == "copy" ? min(rows.length, max(0, round(e.offsetY / 44))) : -1
action left
  line = -1
action took(e: DragEvent)
  line = -1
  rows = rows.slice(0, round(e.offsetY / 44)).concat([e.text]).concat(rows.slice(round(e.offsetY / 44)))
column dragover=moved dragleave=left drop=took position="relative"
  for row in rows key=row
    text row height=44
```

Rows of differing heights count the rows above the point with `frame(id)`: `rows.filter(r => frame(r).y +
frame(r).height / 2 <= e.clientY).length`. Every host that takes a drag supports it.

`draggable` is HTML's attribute: a node a person can lift and drop into
another app, a boolean that may be bound, on a box, a `link`, a `button` or
an `image` (LLP 1094.000). `dataTransfer=DataTransfer(text=, url=, files=[…], names=[…], html=, pictures=[…])`
declares what the drag carries, by `DataTransfer`'s names: `text` as
`text/plain`, `url` (absolute `http:` or `https:`) as `text/uri-list`, and
each file as itself, a shipped `assets/` file or an `app:/` path behind
`fs.read`. `html`, which needs `text` beside it, is the drag's formatted
text, which Notes, Mail and a document take where a plain field takes
`text` ([recipe](https://exact.expo.dev/recipes/drag-formatted-text.md)). It is HTML with CSS, the
elements and properties at least one platform's rich text keeps: blocks
`p`, `div`, `h1` to `h6`, `blockquote`, `pre`, `ul`, `ol`, `li`, `dl`,
`dt`, `dd`, `hr`, `table`, `caption`, `thead`, `tbody`, `tfoot`, `tr`, `th`
and `td`; runs `b`, `strong`, `i`, `em`, `u`, `s`, `del`, `ins`, `mark`,
`small`, `sup`, `sub`, `code`, `kbd`, `span`, `br`, `a` and `img`;
attributes `href` on `a` (`http:`, `https:`, `mailto:` or `tel:`), `src`,
`alt`, `width` and `height` on `img`, `colspan` and `rowspan` on cells,
`start` on `ol`, and `dir` and `style` on any; in `style`, `font-family`,
`font-size`, `font-weight`, `font-style`, `font-variant-caps`,
`font-stretch`, `font-variant-ligatures`, `color`, `background-color`,
`text-decoration` and its longhands, `vertical-align`, `letter-spacing`,
`text-shadow`, `-webkit-text-stroke`, `text-align`, `direction`,
`text-indent`, `margin`, `line-height`, `tab-size`, `hyphens`,
`white-space`, `list-style-type`, and on cells `border`, `padding` and
`width`. A colour is hex, named, `rgb()`, `hsl()`, `color(display-p3 …)`,
one of CSS's system colours or an `-exact-` role, the colour the app shows
as the drag begins. Any other element, attribute or property is refused by
name when compiled, and a value outside its grammar or bounds is left out,
journaled. Its markup is the author's: a literal or a template whose
interpolations are markup, `escapeHtml(…)` in text or a quoted attribute,
`cssValue(…)` in a `style` declaration's value, a number or a boolean; a
choice of markup; `xs.map(x => …).join("")`; a derived name or a `fn` whose
body is markup. Each piece closes what it opens, and a block stands at the
top or in `div`, `blockquote`, `li`, `dd`, `th` or `td`. What the author
leaves unsaid, a run's font or colour, is the destination's own. A
picture's `src` is one of `files`, each once and in their order, and each
file's item carries its file and then the text through the block that
holds its picture, so a collection of places is one item a place, which
Notes takes as its pictures alone; with no `files`, `pictures` lists the
pictures, and the drag is one item of the text with its pictures inside,
which Notes takes whole (LLP 1094.000 D19). **On
Android a destination that takes plain text gets the words of `html`, not
`text`**: Android reads a drag item's plain text from its formatted text,
so write `html` whose words read well alone. `names`, which needs `files`, gives the name a destination is
offered for the file at the same place; a missing or empty name keeps the
file's own. A name whose suffix is the file's, or another spelling of its
type (`.jpeg` for a `.jpg` file), is offered as written; any other gets the
file's suffix added (`Mount Fuji` for a `.jpg` file is offered as
`Mount Fuji.jpg`, `Fuji.png` as `Fuji.png.jpg`). Exact accepts a name of 1
to 255 bytes of UTF-8 with no control character, none of
`< > : " / \ | ? *`, no space at either end, no dot at the end, and not a
name Windows keeps for a device (`CON`, `NUL`, `COM1`, …); a bound name it
refuses is journaled, and the file keeps its own. `draggable` and
`dataTransfer` each need the other. On iOS, iPadOS and the Mac each file is
one item of the drag, and the `url` and `text` are further forms of the first
file's item, or the one item of a node with no file. A drag's count is its
items, so the app sets it by what each node carries: a card with a picture and
a caption is one item, and a collection with a file for each member one item
per member; the system shows the count, and Exact adds none. A receiver takes
the form it reads, so one that takes the picture leaves its caption, and an
Exact app's `drop` takes all three. On iOS a first file that is itself text
keeps the `url` and `text` on an item of their own (LLP 1094.000 D4, D5). A
file the app opens as a database is not one to drag: on Apple and Android the host opens and closes the file as a
destination asks for it, which drops SQLite's locks on it
([How To Corrupt An SQLite Database File, §2.2](https://sqlite.org/howtocorrupt.html#_posix_advisory_locks_canceled_by_a_separate_thread_doing_close_)),
so drag a copy made with `storage.fs` while the database is closed, or an
export of its rows. The data is declared on the node, not set in
a `dragstart` listener, because every platform takes a drag's items as it
begins. `dragstart` and `dragend` on the draggable node (LLP 1094.000 D16)
tell it, after the platform began the drag and once it ended, for the
node's own look, a card that dims while it is dragged: they change nothing
the drag carries, which a change to `dataTransfer` gives the next drag.
Their `DragEvent` has the point in the node where the drag began, the keys
held, and no data; at `dragend` its `dropEffect` is `"copy"` when a
destination took the drag, and `"none"` when it was cancelled or refused,
the app's own `drop` counting once it is delivered. A drag the app drops on
itself hears `dragstart`, the drop's `dragenter` and `drop`, then `dragend`,
in that order. Either on a node that never drags is refused
(`lower-drag-event-source`), and `drag`, HTML's source motion, everywhere
(`lower-handler-later`). The runner admits each file, name and `url` for the
host and journals a refusal (`drag: refused: …`); `expect drag` asserts what a node
carries ([recipe](https://exact.expo.dev/recipes/drag-out.md)). On iOS, iPadOS and Android a press
held on the node lifts it into another app, and on the Mac and the web a mouse
drags it. In Linux's Wayland window a mouse drags its `text` (UTF-8, as
`text/plain;charset=utf-8` and `UTF8_STRING`), its `url` (as
`text/uri-list` and `text/x-moz-url`) and its files, into another app or
back into this one. Each file goes as a copy made when a receiver first
asks, never as the app's own file, in `text/uri-list` and, while the
document portal answers, as its file transfer key, which a Flatpak receiver
reads. The copies are temporaries the receiver may keep: in the system's
folder for large temporary files (as `systemd-path temporary-large` names
it), aged as the system's configuration ages that folder, or in a Flatpak
app's own cache, which the app empties of copies unused for 30 days as it
starts and as each drag makes its folder. Linux gives formatted text as
`text/html`. In a Windows window a mouse drags the node through OLE, as a
Win32 app drags: its `text` as `CF_UNICODETEXT` and `CF_TEXT`, its `url` as
the shell's `UniformResourceLocator`, its formatted text as `CF_HTML` and
Rich Text Format, and its files as `FileGroupDescriptorW` and
`FileContents`, then as `CF_HDROP` once their copies are made; an `app:/`
file goes as a copy, never as the app's own file. The drag carries the
node's picture through `IDragSourceHelper`, and the window displays
incoming drag pictures through `IDropTargetHelper`; a touch or a pen does
not lift there yet (LLP 1094.000 D20).

`beforeunload` is DOM's: the window is about to close or the app to quit
(macOS: its close button, File ▸ Close Window, ⌘Q; the web: leaving the page).
Every element that declares it hears it; an action that calls `preventDefault()`
keeps the window open. The browser then asks "Leave site?" itself; a Mac app asks
its own question, and calls the host command `close()` once it is answered,
which closes the window without asking again (on the web, `window.close()`, which
a browser honours only for a window a script opened). Windows asks it as the Mac
does, before its close button, Alt+F4 or the taskbar's Close window closes the
window (a window that `keepRunning` hides asks nothing) and before a sign-out,
restart or shutdown ends the app (a handler that keeps the window keeps the
session, and Windows names the app as preventing it; a critical end asks
nothing), and its bare `close()`
closes the window and ends the one-window app without asking again. A Wayland
window asks before its title-bar close or the desktop's close command, and
`close()` ends the app without asking again. SIGTERM, SIGINT and SIGHUP
end the Wayland app without asking. A second termination signal ends the
process immediately. iOS has no window-close event.

`head edited=…` marks the document
as unsaved: on macOS the dot in the window's close button, beside the proxy icon
of the file the window opened;
other hosts show nothing (a declared deviation: the web has no unsaved mark).

HTML's global `title` attribute, on any element but `head` (whose `title` is the
document's), is advisory text: the browser's tooltip on the web, `toolTip` on
macOS, and the system tooltip control on Windows (including its hover delay and
dismissal), drawn in the current style by the common controls the executable's
manifest names. Linux, touch hosts, and a touch or a pen on Windows show none.
The painted hosts' accessibility (UI Automation on Windows, TalkBack on Android)
reads it as the element's description where it is not its name, and as its name
where nothing else names it (an icon-only button), as HTML-AAM has it.

## Clipboard

`copy`, `cut` and `paste` are DOM's, on every host: ⌘C, ⌘X and ⌘V (Control on
Windows and Linux keyboards, the Edit menu, an iPad's hardware keyboard) with
the focus at a node or inside it are heard by the nearest node with the
handler, itself or an ancestor — so a node with one takes the focus, as a
`key` node does. With nothing focused they go to the first root, as the
DOM's go to `<body>` (web, macOS and iOS; the Edit menu's item is enabled
while the root has the handler; a Mac sheet's own window holds none). On the web and macOS Paste and Match Style
(⌥⇧⌘V on the Mac) is a `paste` too, as Chrome's is: an app that treats it
apart tells by the key before it, as a page does. In a field whose node or
an ancestor hears `paste`, Paste is enabled on the Mac while the clipboard
holds only files or image data, which the field cannot take itself; the
paste carries them as `files` and inserts nothing. An action that takes one more parameter gets a
`ClipboardEvent` whose `text` is the clipboard's plain text: what is pasted,
and empty on `copy` and `cut`, as the DOM's is until a listener sets it — the
action writes the clipboard with `copyText`. Its `files` is the paste's
`clipboardData.files`, each a `doc:` handle as a dropped file's (a copied file
or folder, any type); image data with no file behind it (a screenshot, an
image copied from a page) arrives as one `image.png`. A paste of text alone
has none, and `copy` and `cut` none. Web, macOS and iOS; Linux, Windows,
Android and the terminal paste text only, and tvOS has no pasteboard
(`files` is empty). In an `input` or `textarea`
the event comes first and the field's own cut, copy or paste follows,
unless the action calls `preventDefault()`, which cancels it as the DOM's
does (a paste then inserts nothing): on the web and on macOS and iOS alike,
where the field's editor fires the three (a password field's on macOS
fires none). The driver's `type <id> paste <text>` delivers a paste
carrying that text, `type <id> paste --file <path…>` one carrying those files
(and folders), `type <id> paste --image <png>` one carrying that image's data
with no file, and `type <id> copy` and `type <id> cut` the others,
without touching the system clipboard; at a field, an unprevented paste
inserts the text.

```text
action pasteAt(cell: string, e: ClipboardEvent)
  send pasted = pasteCells(cell, e.text)
column key=move paste=pasteAt(selected) copy=copyCells cut=cutCells
```

A Paste button or menu command can send a mutation whose data code calls
`readText()` or `read()` from `@exact/clipboard` on macOS, iOS, Android and the web.
Android requires window focus and supplies `text/plain` and `image/png`.
Declare `clipboard.read` in the data source's grants. A mount, tool, wake or
headless session rejects with `NotAllowedError` and `person-required`.
iOS decides whether to show its system paste prompt before reading another app's copy. The agent reads its session pasteboard.

Data code can write `text/html` on macOS, iOS and the web. Pass the markup
as a string in a `ClipboardItem` with an optional `text/plain` fallback.
The host sanitizes the HTML before writing the item. An iOS write accepts
a second argument such as `{ apple: { localOnly: true, expirationDate: when } }`,
where `when` is epoch milliseconds. Other hosts ignore these options. [Clipboard formats](https://exact.expo.dev/reference/developer/generate-typescript-data-source-types.md#clipboard-images).

To write an image, data code imports `@exact/clipboard` (LLP 1133.006): the
Clipboard API's `write([new ClipboardItem({"image/png": path, "text/plain":
text})])`, with an `app:/` path to a PNG (or at most 2 MiB of PNG bytes)
and `writeText(text)`. The host writes a new PNG of the image's pixels, frame
0 of an animation; convert another format first with
`storage.fs.compressImage(…, {type: "image/png"})`. Web, macOS and iOS;
Windows accepts the `app:/` path form and `writeText`, but refuses in-memory
image bytes with `NotSupportedError`. A path's file is at most 64 MiB and
its image at most 64,000,000 pixels. Windows offers registered `PNG` first,
then `CF_DIBV5` with alpha for sRGB or untagged input, and `CF_UNICODETEXT`
when text is supplied. Other colour information (gamma, primaries or an ICC
profile) stays in the PNG; those images have no bitmap fallback, so the paste
recipient must accept PNG. Full-range sRGB cICP `(1, 13, 0, 1)` without
mDCV or cLLI is normalized to sRGB, replacing lower-priority colour tags,
and gets a bitmap. Other cICP values, mDCV and cLLI are refused. Without
cICP, iCCP takes precedence over sRGB and the sRGB tag is removed. See the
[Windows paste limitations](https://exact.expo.dev/reference/developer/generate-typescript-data-source-types.md#clipboard-images).
The app's Contract names the package with a `use` (`use ClipboardItem from
"@exact/clipboard"`), which links it. Under the agent neither this nor
`copyText` touches the person's clipboard: the write lands on the session's
own pasteboard (in memory on the web and Windows), and `state.extensions.clipboard.implementation`
shows the last one (`EXACT_DEVICE=real` writes the real one on Apple and Windows).

## Text selection

`selectionchange` on a `text` is the web's `selectionchange`, per element:
when the part of the reader's text selection inside that paragraph changes —
a drag, a double or triple click, select-all, a click that clears it — an
action that takes one more parameter gets a `Selection`: its `text` (the
selected source text), its `rects: Geometry[]`
(the selected fragments in viewport coordinates), and its `start` and `end`,
UTF-16 offsets into the node's own text as written (white space before CSS
collapses it, a `text`'s inline children joined in order, and Markdown line
breaks counted as newlines). Inline IDs use offsets within that inline text.
Nothing selected
there is `text: ""` with `start == end == 0` and `rects: []`; it fires while a drag moves,
once per change. The web and macOS select text; iOS selects text its author
made selectable (`user-select="text"`), by a long press, a double tap and the
selection's handles; a `user-select="text"` container around multiple selectable
paragraphs shares one selection across them when none has a context menu and no
scroll container or pressable lies between the touched paragraph and the
container (a paragraph inside a nested scroll container joins while a selection
started outside that scroller is active, and stays local when started inside
it; a `user-select="all"` container spans its paragraphs atomically when none has
a context menu). Copy joins separate `text` blocks with a blank line
(`\n\n`) on macOS and iOS; the iOS edit menu offers Select All alongside Copy
and the system actions, and tapping outside the selection clears it. On Android a long press selects a word in an opted-in
paragraph. Dragging its handles changes the selected range and Select all
takes the paragraph's selectable text. On Linux and Windows, dragging the mouse selects
text in opted-in paragraphs. Double-click selects a word and triple-click selects
a paragraph, including text that wraps onto another line. For Markdown, the offsets count UTF-16 units
in the rendered text. Ctrl+C copies the visible text, with a newline between
paragraphs, when the host supplies a clipboard. In a
`user-select="all"` element one click (a long press on Android or iOS,
or a double tap on iOS) selects the whole element, and a selection that reaches
into it takes all of it.

On web, macOS and iOS, `removeAllRanges()` clears the reader's selection. Each
paragraph that held a part reports its empty selection. The documented
extension `setSelectionRange(id, start, end[, direction])` also selects a
`text` on web and macOS: offsets are UTF-16 in its source text, clamped as for a field; an end
before the start collapses at the end. Requested source boundaries survive
CSS whitespace collapsing. `backward` puts the anchor at the end,
as `Selection.setBaseAndExtent` does. The command replaces the page's previous
selection and fires `selectionchange` for changed parts without focusing a
field. An unchanged part does not fire again. On iOS and Android selection events carry
an empty rectangle list.

Rectangles are snapshots at that event, not live layout facts. On the web they
are the paragraph's selected `Range.getClientRects()`; macOS uses the same
CoreText fragments as its selection highlight and inline-run geometry. Linux
reports the clipped fragments of its painted highlight. The `provisional` and
`unavailable` flags are false; an empty selection has no
rectangles. Native paragraphs rendered by the reader worker currently return
an empty rectangle list: their caret geometry is not available synchronously.
Scrolling alone does not emit another selection event.

```text
action mark(para: string, s: Selection)
  selection = Excerpt(para=para, from=s.start, to=s.end, text=s.text)
text para.body selectionchange=mark(para.id)
```

## Progress: `progress`

`progress value=… max=…` is HTML's determinate progress bar, each platform's
own: `UIProgressView` (`.default`) on iOS, tinted by `accent-color` (UIKit's
tint where none is said); a determinate `NSProgressIndicator` bar on macOS
(small, regular where the box holds its 20 points; AppKit gives it no tint);
the browser's `<progress>` on the web; and on Linux a painted bar, a 4-pixel
track filled with the accent. `max` is 1 unless said (a number above 0), and
`value` is held to 0 and `max`, as HTML holds it; both take numbers, bound or
literal. It is as wide as what holds it and `1em` tall: the compiler gives it
`width: 100%`, as it gives `input type="range"`, since neither platform control
has a width of its own (LLP 1115.000 D10.2). That is an ordinary CSS row, so a
`width` you write replaces it, and in a `row` the bar or slider takes what the
row's other children leave and shrinks below its own width to do so, while a
label of several words beside it shrinks too and wraps: give the control
`flex=1 min-width=0` and the label keeps its line. Where the percentage has
nothing to resolve against (a box sized by its content), or under
`width="auto"`, each is its intrinsic size: a progress `10em` by `1em` (160 × 16
at 16 px), a range 129 wide. The bar is centred in the box at its own thickness. Its role is
`progressbar`, its value the platform's (UIKit's "25%", AppKit's value of its
maximum, the DOM's attributes); name it with `aria-label`, and `aria-valuetext`
gives the words a reader speaks instead. A change of value eases on iOS, except
under the agent's clock.

`progress` with no `value` is HTML's indeterminate progress, shown as the
platform's activity indicator: `UIActivityIndicatorView` on iOS (`.medium`,
`.large` where the box's shorter side is 37 points or more), a spinning
`NSProgressIndicator` on macOS (small, regular from 32 points), and on the web
and Linux a spinner the host draws, since HTML's own indeterminate progress is
a bar (the one deliberate divergence, LLP 1069.001).
It is a 20 × 20 box until `width` or `height` sizes it, and the indicator is
centred in it. Its own `color` colours it on iOS, the web, Linux and Android's
reader, else an authored `accent-color` (on it or around it, or the design's
`AccentColor`), else the platform's ink (an inherited colour never does: LLP
1115 D4, LLP 1121 D9); macOS draws the system's colour, as AppKit gives a
spinner no tint. Its role is `progressbar`,
busy (`aria-busy`); name it with `aria-label`. It turns while it shows, and
stops where it is hidden or gone; under the agent's held clock it shows one
still frame (on the web, the frame at the agent's time, as every CSS animation;
Linux paints one still frame always). A `max` with no `value` is refused (it is
the bar's), and so are children, `type`, and `aria-valuenow`, `aria-valuemin`
and `aria-valuemax` (`value` and `max` are its range).

```text
progress value=glasses max=8 aria-label="Water today"
progress aria-label="Loading"
progress width=37 height=37 color="#1083fe" aria-label="Loading posts"
```

## Form controls: radio, `InputEvent`, `setSelectionRange`

`input type="radio"` is HTML's (x2apps survey #2). Its `name` is its group:
the radios of one non-empty `name` in the window are exclusive, and a radio
with no `name` is a group of its own. Choosing an unchecked radio checks it and
unchecks the rest at once, then fires `input` and `change` on it, carrying its
`value` (`on` when it has none); choosing the checked one fires nothing. With
a radio focused, ArrowDown and ArrowRight move the focus and the check to the
next enabled radio of its group, ArrowUp and ArrowLeft to the previous,
wrapping. Left and Right reverse when the radio's parent group is right to
left. Each move fires `input` and `change`; Space checks the focused one.
`checked` is controlled as a checkbox's: after the action, every radio shows
its bound `checked` again, so an action that writes nothing snaps the group
back. The driver's `type <radio> true` checks it as a click does; `false` is
refused, a radio being unchecked only by checking another.

```text
action pick(value: string)
  color = value
for c in colors key=c
  input type="radio" name="color" value=c checked=color == c change=pick aria-label=c
```

`input` and `change` hand an action that takes one more parameter an
`InputEvent`: the target's own fields as the event leaves it, by the DOM's
names — `value` (a checkbox's or a radio's own `value`, `on` when it has
none; a range's number as text), `checked`, and a text field's
`selectionStart`, `selectionEnd` (UTF-16 offsets into its value) and
`selectionDirection` (`forward`, `backward` or `none`); a control without a
text selection reports 0, 0 and `none`. `inputType` names the edit (for example
`insertText`, `insertFromPaste`, `deleteContentBackward` or `historyUndo`).
`data` is `option<string>`: inserted text, or `none` for deletion and history.
`cancelable` and `isComposing` report whether the event can be canceled and
whether it belongs to an IME composition. Events without edit metadata
(`change`, `select`, `selectionchange`) report `""`, `none`, `false`, `false`.
After typing, the caret sits after
the typed text; the direction then is the platform's (Chrome's varies with
the input), so test the offsets. A text field's `select` (an `input` that is
no control, a `textarea` that is not the Markdown editor) is HTML's: it fires
when the person selects text (a non-empty selection, each time it is
extended), and when `setSelectionRange` changes the selection, collapsed
included; typing and a plain caret move do not fire it. Its payload is the
`InputEvent`.

A text field (including search) or textarea shows its
bound `value` after its own `input` action assigns state that expression
read. Assigning the old value counts. For `value=form.name` the slot is
`form`, including when a child receives the name from its parent and calls
the parent's action. A guard that skips the assignment, a data layer that
issues no write, validation and a save awaiting a reply all leave the draft
visible. A later change to the binding updates the field normally. The
caret follows the accepted part of the edit. The terminal currently displays
the bound text between keystrokes even when the action only validates.

While an input method composes in a text field or a textarea (Japanese kana
before its kanji, pinyin, a Korean syllable), `input` fires at every change
with the composing text in the value, as the DOM's does, on every host that
composes (the web, macOS, iOS, Android): "に", "にほ", "にほん", then "日本".
Contract has no `compositionstart` or `compositionend` handlers. An input
action can inspect `InputEvent.isComposing` to distinguish composition edits
from other edits; the value includes the current composing text. On macOS and
iOS the commit of what is composed as it stands changes no text and is not
another `input`;
`change` is still the end of the editing. An action that writes the value it
was handed back (a controlled input) changes nothing in the field, and the
composition goes on. One that writes a different value (trimmed,
upper-cased, cut to a length) does not interrupt the person either: on every
host that composes, the value is held while the text composes and lands when
the composition ends, committed or cancelled, so the rewrite shows a moment
later. The latest accepted value takes precedence even if the input method
sends no further `input`.

`setSelectionRange(id, start, end)` and `setSelectionRange(id, start, end,
direction)` are the field's own method, by its `id`, after the commit's tree
is in place (so a `value` written beside it is there first). It does not
focus the field; the field keeps the selection, and the next key typed there
replaces it. The offsets are clamped as the DOM's are (`-1` is past the end).
On the web and macOS, a selection this or `selectText` sets in the `focus`
handler of a press that focuses the field stays once the press ends, as in
Chrome (an address bar selects its URL as a click focuses it); a press that
drags or double-clicks keeps what it selected.

On **web (JS and wasm), macOS, iOS, Linux, Windows and Android**,
`setRangeText(id, text)` on a plain text field replaces the
current selection; `setRangeText(id, text, start, end[, selectionMode])`
replaces the given UTF-16 range. `selectionMode` is `preserve` by default,
or `select`, `start`, `end`, following HTML. It does not focus the field or
apply `maxlength`. On macOS, wherever the field has an editor (a textarea, or
an input being edited), and on iOS while the field is focused, a changed value
is one undo step that restores the text and selection before it. On iOS, redo
also restores the replacement and its selection. Without an editor, without
focus on iOS, or while an input method composes, the value is written as the
app's own is, clearing only that field's undo history. On the web it is HTML's,
which Chrome makes no undo step, and Linux keeps no field undo history. Invalid
ranges, modes, unsupported input types and missing ids log a refusal without editing. On the Markdown
editor (web, macOS and iOS) the offsets are the source's and each call is one
undo step ([Markdown](https://exact.expo.dev/reference/contract-grammar/built-in-tags.md#markdown-markup-format-select)). Linux, Windows and
Android refuse range replacement in Markdown textareas. The terminal host
refuses the command for every field.

**Deliberate deviation (Charlie, 2026-10-12):** unlike the DOM method,
Exact fires one noncancelable `input` after a successful replacement, even
when the value is unchanged. Wire `input` to update your bound value. Its
`InputEvent.inputType` is `insertReplacementText`. This type also describes
hatch replacements and browser spelling corrections; it does not identify
a `setRangeText` call uniquely. The event's `data` carries the replacement
text. The browser still delivers its own `select`/`selectionchange` events. Chrome delivers
`select` after the added input, only when the selection changes; native
hosts queue replacement selects after the action's commands and report the
field's current value and selection at delivery. macOS Chrome resets direction
to `none` on replacement; Apple follows it. URL inputs strip leading and trailing
ASCII whitespace after removing CR/LF. Contract's
field `selectionchange` also reports collapsed caret moves through an optional
`InputEvent`, independently of a reader's `Selection`. It is queued and
coalesced per field, and reads the current value and selection at delivery.

`beforeinput=action` takes an optional `InputEvent` describing the old value
and selection and the proposed `inputType` and `data`. `preventDefault()`
keeps a cancelable edit from changing the field. A subsequent `input`
describes the applied edit and is noncancelable. IME composition edits are
noncancelable; `preventDefault()` cannot interrupt them. `setRangeText`
continues to emit only its recorded extra input, without beforeinput.
The web forwards the browser's metadata. AppKit and Linux intercept ordinary
field edits and paste before applying them; AppKit's undo/redo responder
commands are cancelable too. UIKit's delegate observes ordinary edits,
but undo operations that bypass its delegate remain a host limit. Linux
has no native field undo history. The Markdown editor's events are these,
over its source ([Markdown](https://exact.expo.dev/reference/contract-grammar/built-in-tags.md#markdown-markup-format-select)).

```text
action edited(text: string, e: InputEvent)
  send doc = edit(text, e.selectionStart, e.selectionEnd)
action jump(line: number)
  setSelectionRange("editor", line, line)
textarea id="editor" value=source input=edited select=selected
```

## Keys

`focusin` and `focusout` bubble from the element that gains or loses focus to
each ancestor handler. A wrapper with either handler gains no Tab stop. Both
offer an optional `FocusEvent`: `target` is the focused element's `id` (empty
when it has none), and `relatedTarget` is `some(id)` for the other element or
`none` when there is none. `focusout` fires even when focus moves to another
descendant of the same wrapper; compare `relatedTarget` to decide whether
focus left the subtree. `stopPropagation()` stops the current event from
reaching further ancestor handlers. Autofocus also delivers focus transitions;
IDs reflect their value when focus moves.
Web, AppKit, UIKit and Linux dispatch these transitions. An edited field sends
`change`, `blur`, `focusout`, then the next field's `focus`, `focusin`. If `blur`
removes a wrapper, its `focusout` still runs inside the detached subtree;
former connected ancestors do not hear that event, even while an exit animation
keeps the removed wrapper visible. A blur caused by a tree update runs before
the update's focus commands or autofocus. A nested focus transition
from commit processing does not cancel the outgoing event.

`key` is the DOM's `keydown` and `keyup` its `keyup`, on every host (web,
macOS, iOS and iPadOS with a hardware keyboard, Linux):

- **Where.** The key goes to the focused element: a field or textarea being
  edited, a `button`, or any element with a `press`, `focus`, `blur` or `key`
  handler (such an element takes the focus, as `tabindex="0"` gives it, and
  is in the Tab order), or with a `tabindex`. It then bubbles: the
  focused element's handler hears it first, then every ancestor's, innermost
  first. With nothing focused (at load, or after the focused element is
  removed) the path is the first root, the app's outermost node: its
  `keycapture`, `key` and `keyup` handlers hear the key after the
  `aria-keyshortcuts` buttons, as the DOM's `window` listeners hear a key
  whose target is `<body>`, and a `preventDefault()` there cancels the key's
  default (Tab's move to the first stop; the terminal's scroll). The root
  takes no focus by it: no `focus` event, no ring, no Tab stop. So on the
  web, macOS, iOS, Linux and Windows. The terminal's root hears `key` alone,
  and first, as its focused node's handler does: before the shortcuts and a
  dialog's Escape. Android hands keys only to a focused field.
  On the Mac a click on a `button`, or on a box that is only pressable, leaves
  the focus where it is, as a click on an AppKit button does: a field beside
  it keeps its caret, and its pending `change` is committed before the `press`
  runs. A click on empty ground moves no focus either. An element with a
  `tabindex`, a `button` included, or a box that is no button and has `focus`,
  `blur` or `key` handlers, still takes a click's focus there, and `focus(id)`
  moves it to any of them.
- **What.** The payload is `KeyboardEvent.key`: the character typed, Shift's
  included (`"a"`, `"A"`, `"7"`, `" "`, `"/"`), or the key's name (`"Enter"`,
  `"Escape"`, `"Tab"`, `"Backspace"`, `"Delete"`, `"ArrowUp"`…, `"Home"`,
  `"End"`, `"PageUp"`, `"PageDown"`, `"F1"`…, `"Shift"`). Every key is heard,
  printable ones in a field included. On macOS and iOS, keys an input
  method is composing are its own, but for two: a modifier's own press and
  release (so a Shift let go mid-syllable is still a keyup), and a ⌘ chord,
  whose keydown commits the composed text first: the chord's `key` handlers
  then run on committed text and read the value Chrome's would, which the
  field's `input` heard as it was composed (the commit is not heard again). A
  composer's ⌘Enter `key` action sends what was typed. On macOS such a chord
  presses no `aria-keyshortcuts` button, as the web's skip a key that came
  composing. On macOS a press outside the field (a mouse-down anywhere else
  in its window) commits the composition before the press runs, as
  Chrome's mousedown ends one, where AppKit would leave it marked: a Send
  button's action reads committed text, and no syllable stays with the
  input method once the action clears the field. On the web, Chrome hands
  the `key` handlers every key while composing, each `isComposing` (below),
  and commits nothing before a chord's handlers.
- **Modifiers.** An action that takes one more parameter, typed
  `KeyboardEvent`, hears the event too: the record `{ key: string, shiftKey:
  bool, ctrlKey: bool, altKey: bool, metaKey: bool, code: string, repeat:
  bool, isComposing: bool }`, the DOM's fields (`altKey` is Option and
  `metaKey` Command on a Mac). A key typed with Control or Meta held is a shortcut: it types
  nothing. `code` is the physical key, whatever the layout or input source
  types there (`"KeyB"`, `"Digit1"`, `"Space"`, `"MetaLeft"`), so a shortcut
  can match the key under a Korean or Russian layout; `""` where the host
  cannot tell (a software keyboard's key). `repeat` is true on the keydowns
  the platform repeats while a key is held, so an action can act once per
  press (iOS reports none: UIKit's presses carry no auto-repeat).
  `isComposing` is true on a key that comes while an input method composes
  text, between its `compositionstart` and `compositionend` (UI Events). On
  the web that is every such key, the Enter that picks a candidate
  included, so an Enter or Escape handler skips it with `not e.isComposing`,
  as web code does. A keydown an input method processed, `keyCode` 229 in
  the DOM, is composing there too, as web code's `e.keyCode === 229` test
  takes it: Safari sends the Enter that commits a composition after
  `compositionend`. On macOS and iOS the only composing keys a handler hears
  are a modifier's own press and release, which are `isComposing` as
  Chrome's are; a ⌘ chord is not, and neither are the keys after it, ⌘'s
  release included, since its keydown has committed the text (Chrome's
  stay composing).
  Linux, Windows, the terminal and Android hand handlers no composing key,
  and it is always false there.
- **Release.** `keyup` hears the key coming up, at the focus, bubbling as
  `key` does (`stopPropagation()` stops it the same way), with the same
  name and record (`repeat` is false). A modifier's release is one too
  (`key` `"Meta"`), and its own flag is no longer held (`metaKey` is true
  on Meta's keydown, false on its keyup), so an app shows a "⌘ held" hint
  between the two. A keyup reaches the focus whatever took the keydown (a
  shortcut, a `preventDefault()`). It has no default to prevent on a native
  host. An element with a `keyup` handler takes the focus, as one with
  `key` does.
- **Capture.** `keycapture` hears a keydown on the outermost ancestor first,
  down to the focused target, before the target and ancestors hear `key`.
  It takes the same name and optional `KeyboardEvent` as `key`. An ancestor's
  `stopPropagation()` during capture stops target and bubble handlers,
  including the target's `key` handler when called at the target. A capture
  stop still lets Enter submit; a capture handler's `preventDefault()`
  cancels the field edit, submission or other default.
  Putting `keycapture` on a container does not add a Tab stop.
- **Then the default.** After the handlers, the key does what it would have:
  a character is typed into the focused field, Backspace deletes, Enter
  commits an input (its `change`, when its value changed, as HTML's does)
  and then submits it (`submit`), breaks a textarea's line (a textarea has no
  `submit`, as in HTML) or presses a button, Space presses a button (Enter
  and Space press any element with a `press` handler as they do a button,
  Enter alone a `role="link"`; give it `role="button"` to be announced as one),
  Tab moves the focus, arrows move the caret; on the web arrows, Space and
  the page keys also scroll the page or the focus's scroller (a native
  scroller does not scroll by key, so there is nothing there to prevent).
  On a native host a screen reader's step of an `input type="range"`
  (VoiceOver's swipe up or down; the increment and decrement macOS and
  Windows offer; Android's scroll forward and backward) is its arrow keydown
  first, ArrowRight to raise and ArrowLeft to lower (swapped where its
  `direction` is `rtl`): a handler that calls `preventDefault()` makes the
  move itself, as it does for a keyboard's arrow on the web, and otherwise
  the host steps the range.
  Where Exact paints the group (on the web, Linux, Windows and Android's
  reader always; on the Mac and iOS where no segmented control, sidebar,
  toolbar or tab bar stands in for it), a
  `radiogroup` of `button role="radio"` has one Tab stop and arrows move and
  press the next eligible radio; a `tablist` has one stop and arrows move
  without pressing (Left/Right, mirrored in RTL, or Up/Down with
  `aria-orientation="vertical"`), with Home/End reaching its ends. A `role="menu"`
  painted in the page moves by Up/Down and Home/End among its buttons, links
  and `menuitem`s without pressing, and each item stays a Tab stop.
- **Claiming a key.** An action run by a `key` event that calls the host
  command `preventDefault()` is the handler's `event.preventDefault()`: that
  default does not happen. Ancestors' handlers still hear the key, as they do
  on the web, unless the action also calls `stopPropagation()`, the handler's
  stop for Exact's key handlers: no ancestor's `key` handler hears it, and its
  default still happens (an inline rename field's Enter submits without the
  list around it opening the selection). Call either only for the keys you
  handle, so typing still works:

```text
action move(k: string)
  if k == "ArrowDown"
    cursor = cursor + 1
    preventDefault()
```

Enter sends and Shift+Enter breaks the line, as a chat composer does (on a
phone the software keyboard's Return is Enter, so it sends there too):

```text
action compose(k: string, e: KeyboardEvent)
  if k == "Enter" and not e.shiftKey
    send(draft)
    preventDefault()
```

`textarea value=draft input=write key=compose`. A shortcut reads the modifier
the platform's users press: `(e.metaKey or e.ctrlKey) and k == "s"` saves on a
Mac and elsewhere. The driver presses chords in Playwright's spelling (`type
"composer" key "Shift+Enter"`, `key "Meta+s"`).

Hints while ⌘ is held, and a held ⌘W that closes one panel, not one per
repeat, by the physical key whatever the layout types. Held modifiers are
tracked as a page tracks them: every keydown and keyup says what is held,
and losing the window's focus forgets it, since a key let go while another
app or window has the focus sends no keyup, here as in Chrome. A page's
`window` `blur` listener is `exactPage().hasFocus` turning false, the gate of
a task that clears the flag:

```text
action down(k: string, e: KeyboardEvent)
  hints = e.metaKey
  if e.metaKey and e.code == "KeyW" and not e.repeat
    closed = closed + 1
    preventDefault()
action up(k: string, e: KeyboardEvent)
  hints = e.metaKey
action forget()
  hints = false
task release when hints and not page.hasFocus
  after(1, forget)
```

`resource page = exactPage() as shape Page` (`hasFocus: bool`), `column
key=down keyup=up`, and `if hints and page.hasFocus` around the hints. The
driver holds and releases a key with `type "list" key "Meta" down` and `key
"Meta" up`, takes the focus away with `prefer has-focus false` (then `clock
+1` for the task), and `key "a" for 1200` repeats a key while held, as a
keyboard does (the first repeat 500 ms after the down, then every 83 ms, on
the virtual clock).

- **A game's canvas.** A key at a canvas whose world takes input, or at a
  node inside one, goes the same way first: a shortcut takes it, then the
  `key` handlers from the focus out hear it, and one that calls
  `preventDefault()` keeps it from the world. The world hears the rest, so a
  canvas's `key=` handler hears what the world binds as well as what it does
  not (the platformer's diary, R8).
- **Shortcuts.** An `aria-keyshortcuts` button hears its chord before any
  `key` handler, and takes the key (no `key` handler hears it), on the web,
  macOS, iPadOS (a hardware keyboard's chord; the session's view holds
  the focus when nothing else does) and Linux. While a modal is shown — a modal
  `dialog`, or an `aria-modal` view, the last shown — only the buttons
  inside it hear their chords (on the Mac, an item of the app menu or Help
  still does, as below), and Enter or Space with the focus on a
  control they activate (a button, a pressable, a checkbox) is that
  control's, whatever button declares it. A chord's key is one character,
  a named key, or F1–F35; the paste chord (⌘V, Control+V off the Mac) is a
  chord like any other, so a button declaring it takes the driver's `type
  … paste` too and the paste never lands. A key that types no Latin letter
  (Russian's с, Greek's ψ, ㅠ under Korean 2-Set) also takes the chord of the
  key the US layout puts in its place, as browsers match it: under such a
  layout Control+C copies in a field and a button declaring Control+K takes
  the K key. A Latin letter is the key wherever it is (AZERTY's A, German's
  ö). On iPadOS a hardware keyboard's
  F13–F24 reach `key` handlers but no shortcut (UIKit's key commands name
  F1–F12 only); the driver's reach both, as everywhere.
  `Mod` is the primary modifier in any modifier position. It means `Meta`
  on Apple platforms and `Control` elsewhere. In a single chord, combining
  `Mod` with either spelling is ambiguous. Chords in a list are alternatives for the
  same action, including when two resolve to the same chord. The web reads
  `navigator.userAgentData.platform` when present and otherwise
  `navigator.platform`; an iPad reporting Mac receives Command. A server
  render omits an attribute containing `Mod` until the browser sets the
  resolved `aria-keyshortcuts` on the element. The host checks chord spelling
  in literal attributes, list items, conditional arms, concatenations and state
  initializers, while the compiler checks the literal `-exact-menu-keys` override.
  `formatShortcut(chord)` gives one chord's key cap in the reader's notation,
  or the empty string for an invalid chord or during server rendering.
- **The Mac's menu bar.** Every button whose chord holds ⌘ is also a menu
  item, titled by its `aria-label` (or its text), placed by its chord as
  Apple's HIG places one: ⌘, is Settings…; ⌘[ ⌘] and a `tablist`'s tabs are
  Go; ⌘Z ⇧⌘Z ⌘X ⌘C ⌘V ⇧⌘V ⌥⇧⌘V ⌘A ⌘D ⌘F ⌘G ⇧⌘G are Edit; ⌘= ⌘+ ⌘- ⌘0 and
  any ⌃⌘ chord are View; the rest are File. One whose chord is the host's own
  Edit item's (Undo, Redo, Cut, Copy, Paste, Select All) takes that item's
  place, so Edit ▸ Undo is the app's "Undo Move"; a paste variant (⇧⌘V,
  ⌥⇧⌘V) follows Paste, as Paste and Match Style does in TextEdit, Safari and
  Chrome ("Paste as Text"); the rest follow Select All. Any other host item
  whose chord a button declares keeps its place without the chord (File ▸
  Close Window beside the app's ⌘W). Drop the chord while a field is being
  edited and the host's text Undo, Cut, Copy and Paste come back (studio
  diary R16). Edit also holds Speech ▸ Start Speaking and Stop Speaking, which
  read the selected text aloud, in a field or out of one.

  Explicit placement: `button "Check for Updates…" -exact-menu="about"
  press=checkUpdates` also becomes a menu item without a shortcut. The literal
  ids are `about` (the app menu, directly under About, as apps that update
  themselves place Check for Updates…), `app` (after About's separator, with
  Settings…), `file`, `edit`, `view`, `go`, `window`, `help`, and `none`, which
  shows no item and keeps the chord a shortcut (a host item with that chord
  keeps its place without it); they are independent of localized menu titles
  and override chord filing. A placed item shows and takes the button's first
  chord holding ⌘, or else its first holding ⌃ (`Control+Space`,
  `Control+Meta+1`); a chord of ⌥ or ⇧ alone stays out of the menu, since those
  type, and one press runs the command once whichever of the window and the
  menu takes it. ⌃Space is macOS's default shortcut for Select the Previous
  Input Source; where it is on, the system takes it before the app. The label
  remains the button's `aria-label` or text. `disabled`/inert disable the item; hidden or removed buttons leave the
  menu. An item in the app menu or Help (`about`, `app`, `help`, and Settings…)
  is the app's, not its window's: it stays enabled, and its chord works, while
  no window is key, under a sheet and under a Contract modal dialog, as in a
  hand-built Mac app; an authored `inert`, or a route behind a modal route,
  still disables it, and an app-modal panel (`NSApp.runModal`) disables it
  as AppKit disables every item then. The agent uses `tap` on that
  same button. Help retains the system search field; the standard menus, and
  Develop in a development build, remain unless removed. Other hosts keep the ordinary button
  and ignore this Mac presentation hint. On a top-level root,
  `-exact-menu-remove="show-tab-bar close-all"` suppresses the named
  standard items and their menu equivalents. The literal whitespace-separated
  ids are `close-all`, `show-tab-bar`, `show-all-tabs`,
  `enter-full-screen`, `minimize`, `zoom`, `bring-all-to-front`,
  `show-previous-tab`, `show-next-tab`, `move-tab-to-new-window`,
  `merge-all-windows`, `back` (Go ▸ Back), `forward` (Go ▸ Forward), `develop` (the Develop menu),
  `paste-and-match-style`, `find`, `spelling-and-grammar`, `substitutions`,
  `transformations`, `app-help` (Help ▸ *App* Help), `actual-size`, `zoom-in`
  and `zoom-out`, and `status-quit` (the host's Quit ending a status item's
  menu, LLP 1133.025 D7). A removed submenu (`find`) takes its items' chords with it,
  and an app command that would stand in there follows Select All instead.
  Empty removes nothing; duplicates are harmless. Unknown ids, expressions and
  non-root use fail with `lower-menu-remove`, which names the accepted set.
  Removing the root declaration restores the items; the policy follows the
  active window. It never removes an app button; `develop` takes the Develop
  menu off the bar and leaves its chords (Save Trace's ⌥⌘T among them);
  other hosts ignore it (LLP 1021 §5.3).

  On a top-level root, `-exact-menu-keys="close-window=none"` keeps File ▸
  Close Window (built with ⌘W) in its place with no chord, so ⌘W reaches the
  page, and `close-window=Meta+Shift+W` gives it ⇧⌘W. `close-window` is the
  one id; the chord is one `aria-keyshortcuts` chord with `Meta` or `Mod` that is not
  one of the host's or the system's own (⌘Q, ⌘W, ⌘H, ⌘M, ⌘-comma and the like).
  Another id, an id named twice, a chord without `Meta` or `Mod`, a standard chord,
  expressions and non-root use fail with `lower-menu-keys`. With nothing
  holding ⌘W, AppKit's Close All ⌥⌘W shows as a row of its own: an app that
  removes ⌘W declares `-exact-menu-remove="close-all"` too. An app command
  with the same chord still takes it from the item; removing the declaration
  gives it ⌘W back. Other hosts ignore it
  (LLP 1021 §5.3.3).

  The Dock menu and the status item (LLP 1133.025
  D4, D5): `dock` beside one menu id, or alone, files the button in the Dock
  menu too, above AppKit's own items, in declaration order, from the key
  window's session. `-exact-menu="status"` stands alone (with another id it
  fails `lower-menu-status`) and presents the button as the app's
  `NSStatusItem` on macOS, taking its place in the page; its `popovertarget`
  menu is the item's menu. A click opens the menu when there is one and runs
  `press` when there is none. On Windows the button is a notification-area
  icon and likewise leaves the page: a left click or a keyboard
  selection runs `press`, or opens the menu when there is none, and a right
  click opens the menu, which ends with Exit unless `status-quit` is removed.
  Every other host keeps the button an ordinary button in the window. With
  `host.macos.activationPolicy: "accessory"` the app has no Dock tile and
  opens no window at launch. Bare `focus()` is the window's, as the web's
  `window.focus()`: on macOS and Windows it shows the session's window if
  hidden, brings it forward and activates the app; Linux brings no window
  forward and logs it as unsupported. `focus(id)` stays an element's.
  `hideWindow()` puts the session's window away as the person's close does
  under `keepRunning`, or on macOS while a status item is placed, and the
  app keeps running; the next `focus()` shows it.
  On Windows `host.windows.window.keepRunning: true` makes closing the window
  hide it, as on the Mac, and a login item registered `hidden` opens no
  window at that launch. A Windows app is one process: launching it again
  shows the window it has, and a location on that command line (a
  jump-list task) opens in it. A placed status item does not make the close
  hide the window there, as Windows' guidelines advise; it is a way back to a
  window `keepRunning` hid, and its menu's Exit a way out.

  `@exact/global-shortcuts` on Windows accepts `PrintScreen` and modified
  chords such as `Control+PrintScreen`. Bare `PrintScreen` answers
  `registered: false, reason: "reserved"` when the Snipping Tool keyboard
  setting (`HKCU\Control Panel\Keyboard\PrintScreenKeyForSnippingEnabled`)
  is a nonzero DWORD, unreadable or of the wrong type. A missing value is
  reserved on Windows 11 (build 22000 or later), or if the build cannot be
  read. An explicit DWORD 0, or a missing value before build 22000, lets
  `RegisterHotKey` decide. Registration and checks of an already-held chord
  apply the same rule; modified chords are unaffected by this refusal.
  Turn off "Use the Print screen key to open screen capture" in
  Settings › Accessibility › Keyboard, or choose another chord. The host
  does not monitor setting changes or intercept the key with a keyboard hook.

  View holds Actual Size ⌘0, Zoom In ⌘+ (⌘= too) and Zoom Out ⌘-, as Safari's
  and Preview's View does, stepping through Safari's zoom levels (50% to 300%)
  for the main window (the key one, or the one under a key panel). It is a
  page zoom, as a browser's: a CSS px is the factor's points, so the viewport
  the page lays out in shrinks (media queries and `resize` see it) and `px`,
  `rem` and the controls in the page all scale, drawn at the display's scale
  times the factor. It is per window and not kept across a launch. An app's
  own ⌘0, ⌘= or ⌘- command takes the host item's place and sets its own steps
  with `setPageZoom(factor)` (LLP 1021 §5.3.1).

  A held ⌘Q, as Chrome's Warn Before Quitting asks for: a root `key` handler
  that calls `preventDefault()` on ⌘Q (match `code == "KeyQ"`: under a
  non-Latin input source `key` is that source's letter) hears its press, each
  auto-repeat (`repeat`) and its `keyup`, and the menu's Quit never runs; the
  app calls `close()` to end a one-window app when the hold completes. Quit
  chosen with the pointer still quits at once, after `beforeunload`. The
  host's own items (Copy, Quit, Minimize, …) match a ⌘ chord under a
  non-Latin input source as AppKit matches them in any Mac app: the event's
  characters with ⌘ are the key's Latin letter (measured under Korean 2-Set).

## Focus order: `tabindex`

HTML's `tabindex` (no `tabIndex` alias; LLP 1088
D7.3), on any element and a module tag's box, a number or bound to state. Present, it
makes the element focusable — a click, `focus(id)` and `autofocus` reach it, and the
`key` handlers above it hear its keys; absent is never `0`, so a plain box is no stop.
`tabindex >= 0` is a Tab stop: positive values first in ascending order, then `0` and
the elements that are stops by kind (inputs, buttons, handlers) in tree order. A
negative value is focusable but skipped by Tab, a handler's element included
(`button tabindex=(revealed ? 0 : -1)` keeps a hidden swipe action out of the order).
An inert or `display: none` element is never focusable, nor is a disabled `button`,
`input`, `textarea` or control. `disabled` means nothing on a box, as on a `<div>` in
Chrome: `box tabindex=0 disabled=true` is still a Tab stop, and so is a `link` with
an `href` (the web's `<a>`, which `disabled` does not touch). Tab and Shift-Tab walk
and wrap on the web, macOS, iPadOS's hardware keyboard and Linux; tvOS's remote skips a
negative value and keeps UIKit's geometric order.

On the Mac which elements are stops by kind follows the person's Keyboard navigation
setting (System Settings ▸ Keyboard), as in every Mac app. Off, the default, Tab moves
between text fields and what takes keys of its own (a box that is no button with
`focus`, `blur` or `key` handlers, a canvas that takes input): a `button`, a pressable
box and a radio group are passed over. On, Tab reaches every control, including
each inline link or pressable text run inside a paragraph, including in a dialog.
Return activates a focused inline link before a dialog's default button. Space
activates a pressable run only when it has no `href`; it never follows a link.
Return presses no other focused button on the Mac: it belongs to a dialog's default
button, as in AppKit (LLP 1115.000 D7.3). An app that copies a web app's keys writes
`-exact-return-presses="descendants"` on a container: under it Return presses the focused
button as Space does, before a dialog's default button, as Chromium presses a focused
`<button>` on Enter. The web does that already, and other hosts ignore the property.
A `tabindex` you write wins either way: `0` or more is always a stop, a negative one never. A button that
`focus(id)` or `autofocus` reached while it is no stop still goes on to the next stop
with Tab, and back to the one before with Shift-Tab. Under the agent the setting is the
drive's, off unless it says `prefer keyboard-navigation true` (`state.focus.keyboardNavigation`
reads it); a `type <id> key Tab` after that walks every control.

A new Mac window puts the caret in its first stop, as AppKit does: with Keyboard
navigation off the first text field, and with no stop nothing. An `autofocus` you wrote
elsewhere wins, and a window whose first stop is in a `canvas` that takes input opens
with nothing focused. The web and iOS focus nothing on load unless `autofocus` says so.
An `autofocus` mounted later takes the focus only when nothing holds it, as in Chrome: a
`tabindex` button a tap focused keeps it when a timer remounts an `autofocus` element.
The tap's own work is the exception on the web and iOS: a field it shows, or the
`autofocus` field of a sheet, dialog or popover it opens, takes the focus from the control
tapped (LLP 1035.000 D9). On macOS and
iOS a click or touch whose press mounts an `autofocus` text field or textarea begins editing
it as the platform's click-to-edit does: on the Mac the field takes the focus from any field
that held it, and on both the caret goes under the press (the end below the text). The web
puts the caret where its focus does, at the end.

`aria-disabled=true` (or `aria-disabled="true"`) reports an unavailable control
to accessibility while keeping its focus and Tab behavior. It accepts a bound
boolean on a control or an element with a role, including a group. Its `press` still runs,
as on the web; guard the action in the app when it must do nothing. Descendant
controls and inline links inherit this state, including toolbar items, grouped-list
rows and content lifted into a popover; an explicit
`aria-disabled=false` on a descendant overrides it. Use HTML
`disabled=true` when the control should leave the Tab order and refuse input.
