# The SDK contract

Every name a work may call on window.playspace, rendered from the SDK's types; on what a name means, this page wins. "The transcoder" is Playspace's publishing agent; record ids can be skipped.
For a work you write, wire input as [the controller](https://www.joinplayspace.com/sdk/docs/controller.md) says; the verbs and the declaration here are how that agent wires a work it did not write.

## The contract

Sharing is one controller on every work: the left thumb moves, the right finger looks, a tap acts, and one button is
the action with no place. Publishing is the
transcoder writing every work onto it. The SDK is the contract between them, and a control nothing listens to is
never drawn (0.16.0). A work on the contract gets the controller as a guarantee; a work on the fallback gets it as a guess.

**The four verbs and the declaration** (what the transcoder writes; what a creator is told; nothing else):
1. **The stick moves it.** Each frame read `playspace.input.axis("moveX")` and `("moveY")` (-1..1, up negative) and
   move the work in its camera's frame: with `f` the camera's forward flattened onto the floor and `r = f × up` its
   right, the step is `r * moveX - f * moveY` times the speed and `dt` (games_fps's `getSideVector` and
   `getForwardVector`); with a yaw `a` alone (three.js's `rotation.y`), `dx = moveX cos a + moveY sin a`,
   `dz = moveY cos a - moveX sin a`. A read makes the stick live. `dash` (an intent) is a push past the rim.
2. **The drag turns it.** `playspace.camera.onLook((yaw, pitch) => ...)`: radians after the player's comfort, yaw right
   and pitch up positive, applied to the work's own camera. A drag that starts on empty space is the look.
3. **A tap acts in it.** `playspace.input.onIntent((i) => ...)`, returning true for what it handled: `tap` is the tap
   (a click on a computer) under every reading, never a walk (the stick is the only locomotion), with `target`
   when `select: { hit }` wraps the work's raycaster; `hold`, `drag` (with `holdDrag`), `press`, `swipe`, `zoom`,
   `doubleTap` for the finger's other gestures. (`act` renamed `tap`; `goto` and `primary` folded into it.)
   A work with more verbs than these carries them on `tap`, then `doubleTap`, then `dash`, in that order; never two
   held together (the cookbook's rule 8).
4. **The button is the action**: `{ type: "action", on, t0 }` through `onIntent`, on at the down and off at
   the lift (a jump, a flip, a confirm: an action with no place on the screen; the held span is the work's). The
   declaration's `action: "Jump"` names and lights it. Not `tap`: a tap acts on what it lands on, the button does not.
   **The second button** (0.11.0): `{ type: "secondary", on, t0 }`, the same shape, lit only by the
   declaration's `secondary: "Run"` (or `keys.secondary`): the smaller disc above the button on a phone, Shift or the
   right mouse button (0.12.0; and a declared `keys.secondary`) on a computer; the verb a work holds (run,
   boost, aim), or its second action.
5. **The declaration.** `playspace.layout({ v: 3, action?, secondary?, select?, avoid?, forward?, scroll?, inspect?, own? })`:
   only what the defaults cannot guess, and the work's HUD to keep the controls off.
Plus the envelope's signals, already the contract: `ready()`, `start()`, `moment()`, `end()`, `progress()`,
`score()`, `idle()`, `error()`, `on("pause" | "resume")`, `camera.fovFor()`, `touch.geometry()` (0.10.0's neutral
names first; `gameplayStart()` and `complete()` are the same calls under their first names).

**One contract, every device**: the work writes the three verbs once and the SDK feeds them from what the
person holds. Phone: the left stick, a drag on empty space, a tap, the round button at the lower right. Computer: W A S
D or the arrows, a mouse drag on empty space (no pointer lock), a click, Space; Shift or the right mouse button is the
second button where it is declared (0.12.0); the wheel zooms and a held button is `hold`. On a phone a two-finger
pinch on empty space zooms too (0.12.0). A first-person work may say `look: { computer: "capture" }`: a click takes
the mouse, Esc gives it back (0.9.2; since runtime 1.27.0, the player does nothing then: the work hears
`pointerlockchange` and its own Escape). On a trackpad (runtime 1.13.0): a two-finger click, or
Ctrl+click on a Mac, is the right mouse button; a pinch is zoom (`via: "pinch"`); press and drag looks, or click to
take the mouse where the work asks (`capture`). Mixed devices (1.13.0): a finger on a computer's touch screen is the
mouse's drag, click and hold (never the captured mouse), and a keyboard beside a touch screen moves and presses as on
a computer (the stick wins while a finger is on it). `swipe`, `dash` and the double tap's drag `zoom` are touch
gestures with no computer form. Gamepad, later: the left stick, the
right stick, the A button. Nothing on a computer is synthetic: the real keys, mouse and click still reach
the work, and the SDK adds no second click. On a computer the work needs no `playspace.layout` for this: a subscriber to
`onIntent` or `onLook`, or a read of `moveX`/`moveY`, is the declaration.

**The player surface** (the Home button): the same around every
work. While a work runs, the one thing of the player's on the screen is the player's Home button, our mark in a disc
at the top left; a press on it (a click on a computer, a tap on a phone; never a key) freezes the work underneath, silent and dimmed, like a
console's Home button: a play disc to go back in, Leave, and the column beside the work (Save, Share, More, Next and
Previous). More holds Sound and volume, Quality, Look speed and Invert look where the work looks, About with "How it plays", Not for me
and Report. The Home button is the same on every work and **shows nothing of yours**: your menus, pause, restart,
stats, objective, settings and modes are yours, inside your frame. Sound and volume is the player's (runtime 1.24.0): on a computer a mute and a volume slider, on a phone the mute (the phone's buttons are the volume); muted
until the first touch inside the frame. Quality is the player's too (runtime 1.25.0): Auto, Low and High, the
same on every work (`playspace.quality`, `on("quality")`). The end card shows only when a work really ends
(`end()`) or reports an error; it says why, offers Share and Up next and counts down to the next work. Idle is a
datum, never a card. A work **tells**: `ready()`, `start()`, `moment(name, data)`, `end({ score, outcome })`,
`progress(step, of, label)`, `score(n)`, `idle()`, `error(message)`, `share()`, `save()`, and declares `kind` and
`controls: false` in `playspace.json` (`idle` there is read and changes nothing on screen); it **hears** `pause`,
`resume`, `mute`, `orientation`, `insets`, `arm`, `facts`. `menu()` and `stat()` (SDK 0.13.0, runtime 1.14.0)
are accepted and recorded, drawn nowhere (D4): `menu.score` and `menu.restart` are still read by the end
card's Play again and the board, and `score`, `end` and the outcome feed the end card. It still **never asks** the
chrome for anything: not to hide or move the button, not a colour, a like, a button or a menu item of its own, a
count drawn by the chrome, or a hint of its own over the frame; its own menus live inside its frame, and the player
still freezes it around them. The render defaults are the player's (runtime 1.5.1, 1.5.2, 1.17.0): in the
app and on a touch screen `devicePixelRatio` reads at most 1.5, and every frame is delivered on Auto (from 1.5.2 to
1.26.0 a slow frame clock was halved to a steady 30 there; since 1.28.0, no tier thins frames), both on `stats`
and `frame_stats` (`pixelRatio`, `cadence`). `playspace.json`
`"pixelRatio"` (what a work can take) is documented and not yet read.

**Not the work's: the feel.** `camera.comfort()` (speed, smoothing, slop, invertY, the curve) is the player's, one
setting for every work, read-only for a work; the player sets it by the runtime's bounded `comfort`
message. A work names only the fallback's mouse units, `look.radPerPx`.

**The stick is live only when something listens**: the declaration's direction `keys`, the host's facts
naming keys in a set, a read of `moveX`/`moveY` (each frame, from the first), the SDK's `locomotion`, or a bound
`moveX`; for an undeclared original only, a key listener the runtime saw it register on the page. Otherwise it is not drawn and its corner's touches are the playfield's (0.16.0;
under `own` the work's). An undeclared original with a manifest of its own and no stick in it gets no stick.

**Typing in the work's own field** (0.24.0, runtime 1.39.0): a work that asks for text (a name, a
line, a search) puts its own `<input>`, `<textarea>` or `contenteditable` on its page; there is no SDK call and no
manifest field for it. While a text field of the work has the focus every key goes to the field as typed (nothing is
translated); on a phone the stick, A, B and the pill are hidden and every key they held is let go (from a focus that
follows a touch), and a touch outside the field lets the field go and still reaches the work; the first Esc is the
work's, and lets the field go if the work did not; the player's pause lets it go too; Buddy never starts and presses
nothing while a field has the focus. The cap is the field's own `maxlength`. Playspace's runtime never reads,
records or sends what is typed in a work's field: the frame tells the player only that a field has the focus
(`typing`, on or off). The limits: a field inside a closed shadow root or inside a frame of the work's own is not
seen as a field (text mode does not begin for it, and a key typed in a closed root may be counted as a key).

## Beside the contract: the fallback, the player's own

The SDK is `src/sdk/sdk.js` (`playspace.sdk.version`, 0.9.2 on `co18-ios`), appended to the runtime (1.9.0) that the
edge inserts into every served page, so a work loads nothing. It runs the same in the web player (`/play`), in embeds
and in the app: a work is one build everywhere.

**The fallback** (an original with no code, before its transcode). The host sends the facts its check learned with
`arm` (`playspace.facts()`: the keys the build answers, whether it took a pointer lock, scrolls, answered a touch), and
a work that declares nothing is laid out from them on a touch screen: the stick presses the keys found, matched to
their set (WASD, the arrows, ZQSD; lit only on a set's forward key or two of its keys), a drag moves the work's mouse
(no button under a pointer lock, else a held drag), a tap clicks where it lands, a hold is a held click, and the
button holds Space where the check found it. A work the check saw answer a touch is laid out as `own`. On a computer
an undeclared original is untouched. It covers keyboard-and-mouse originals only; the rest is the transcoder's.

**The control manifest** (0.14.0, runtime 1.19.0; since runtime 1.34.0, the
**Playspace set**): with the facts the host sends the controls the build plays with (`"controls"` in the build's
playspace.json: a bundle's at its root, a source's `public/playspace.json`, which its build ships; else the fallback the check's record makes). Every
work is played with the same few controls. On a phone: **the stick** (bottom left, `move`, a fixed disc at its rest
whose touch circle is half again as wide: where the thumb lands inside it is that touch's centre), **A** (bottom
right, 72 across, `a`), **B** (60 across, up from A toward the edge, `b`) and **the pill** at the top left (`esc`, the
work's menu key; its word at most six letters, Menu when none); a tap on the work is the click where it lands and a
drag the mouse, held, or the view turning (`pointer`). Each place is in px from the corner its hand holds with the
safe insets added (`touch.geometry().map`, its touch areas `touch.geometry().touch`), the same on every work: only
what the manifest names is drawn and nothing moves. In each the work's word alone; full for four seconds, then at 40
percent, a touched control full and Signal blue at once; hidden while a keyboard or a gamepad was the last input. A
thumb holding A or B that slides onto the other presses both (the roll) and lets the second go when it slides back.
The runtime presses the work's own key (or the mouse's button where the finger aims, `click` and `click2`; or
alternates it, `press: "switch"`), never changing the work. Under `pointer: "own"` the work keeps the frame, every
finger outside our controls. A frame under 300 px tall gets nothing of ours. Under a version 3 manifest our controls
appear when the work says play begins (`playspace.start()`); a stored version 1 or 2 manifest shows them at arm. A
declaration's stick, A and B win (A and B then say the declaration's own word); the pill comes only from a manifest.

**Version 3 of the manifest** (runtime 1.34.0; the one to write): `{ "v": 3, "move": { "keys":
[up, down, left, right], "alt"?, "word"? }, "a": { "key", "word"?, "press"? }, "b": { ... }, "esc": { "key", "word"?
}, "pointer": "mouse" | "look" | "own" | "none", "click"?, "capture"?: true, "fixed"?, "extra"?: [{ "key", "why": "repeat" | "unneeded"
}] }`. Only `v` is required; each of `move`, `a`, `b`, `esc` is drawn only where named. `a.key` may be `"click"`,
`b.key` `"click2"`. Words are at most eight letters (the pill's six). A key goes in one control only, and not also in
`extra`, which the player never gets. The file's `v: 3` is not the code's `playspace.layout({ v: 3 })`. Versions 1
and 2 still read, onto the set by rule (A the primary action, B the secondary, else the next the manifest names; the
menu key the pill; every other action not drawn); the fallback is version 1. On a computer a small picture with no
words shows which of the set's keys the work uses (runtime 1.44.0): a mini keyboard with only them lit, the arrows,
the mouse and a text field where the work takes typing, centred at the stage's bottom for 6 s from the work's first
picture and 3 s after each resume, never while paused.

**A place yields to your own control**: while a place's touch area covers your page's own
button, link or field (`button`, `a[href]`, `input`, `select`, `textarea`, `summary`, `[role=button]`,
`[role=link]`, `[onclick]`, `[contenteditable]`, `label[for]` or a `label` with a control in it, `video[controls]`,
`audio[controls]`, or the outermost of the elements showing a pointer cursor; never a canvas, the page's html or body,
anything at 40 percent of the frame or more, nor anything at under 0.1 of opacity or `visibility: hidden`), it is
not drawn and takes no touch, so the finger reaches yours; it comes back when your control goes, fades or moves. A
control inside a shadow root or an iframe is not seen. It cannot see a button painted on a canvas: mark where play
begins (`start()`) so our controls are not over your own title screen. `touch.geometry()` says it per place
(`yielded: true` with `under`, your control's tag, an input's type and its `aria-label`, `placeholder` or text, never
a field's value, at most 40 letters) and `touch.controls()` leaves such a place out. And a held A or B keeps passing
its finger's drag on as look once it is off both buttons, as a drag on the playfield does (on a work that reads the
playfield's mouse drag, the same held mouse drag), the button held until the lift.

**The player's own.** The feel (`camera.comfort()`: speed, smoothing, slop, invertY, the curve) is one setting for
every work, set by the player through the runtime's bounded `comfort` message and read-only for a work. The layout,
every number from the live viewport: a playfield (the frame less the insets and a top band as tall as the reserved
corners, 60 px below the top inset); the move stick's zone in the lower left (`TOUCH_STYLE.stickZone`, 30 percent of
the width from 45 percent of the height, widened to hold the left rest), its base under the thumb, a ghost at the
map's left rest when untouched; the action disc at the map's A. A control nothing listens to is not drawn (0.16.0; before it, a
ghost at 25 percent): its corner's touches are the playfield's, and `touch.geometry()` keeps its rect with
`live: false`, `drawn: false`. A finger
belongs to the place it lands in until it lifts, a second finger in a held place is kept from the work, so at most
three touches are read; a pinch is never the page's: once a layout is shown the page never zooms, and since 0.12.0 a
two-finger pinch on empty space is the `zoom` intent (the one-finger rule stands for everything else, never under
`own`, where every finger is the work's since 0.17.0). A touch that
starts on the work's own button, link, field, scrolling box or `avoid` rect passes through to the work untouched.
Under every reading but `scroll` (`own` included) the page never scrolls or hands a drag to the browser; a scrolling
box of your own scrolls while it has room (runtime 1.23.0, the SDK cancels a touchmove's default, never its
propagation, so your own touch and pointer listeners still hear every finger).

**One shape**: `{ v: 3, ... }` is the only declaration. The v1 schemes, the v2 one-finger schemes and their
grammar words, the action map (`input.use`, `.bind`, `.down`, `.on`, `.emitKeys` and the rest) and the old touch calls
(`touch.insets`, `.click`, `.fit`, `.state`, and since 0.20.0 `touch.show`) are gone, not aliased: a declaration that is not `v: 3` lays
nothing out (the work is read as undeclared). `camera.attach`, `.preset`, `.update`, `.yaw`, `.pitch`, `.distance`,
`.focus` and `locomotion.*` are optional three.js conveniences, not the contract.

**The readings**, one word each in the declaration, the first set of `own`, `scroll`, `inspect`, `forward`, else the
layout:
- `playspace.layout({ v: 3, keys: { forward: "KeyW", back: "KeyS", left: "KeyA", right: "KeyD" }, look: { radPerPx: 0.002 } })`: a walk
  and a look, the keys and the fallback's mouse units named.
- `playspace.layout({ v: 3, forward: "always" })`: a racer or a runner; forward held, the stick steers and brakes.
- `playspace.layout({ v: 3, scroll: true, orbit: ["#hero"] })`: a story; the page is the space (a module).
- `playspace.layout({ v: 3, inspect: { distance: [4, 2.5], limits: { pitch: [0, 0.6] } } })`: a viewer or a
  configurator; the thing in the hand (a module). A work with its own camera (OrbitControls, ArcRotateCamera) keeps
  it: the reading draws no stick and gives a view; the work turns its camera by `camera.onLook` and zooms on
  `doubleTap`; the orbit and distance defaults act only through the optional camera module.
- `playspace.layout({ v: 3, own: true })`: a toy that reads its own touch; no stick and no disc are drawn.

**What the player reserves**, so a work never claims it:
1. The pause control: the top-left corner, 44 by 44 inside the safe-area insets; the SDK keeps
   `TOUCH_STYLE.reserved.left` (72 by 60) clear. A touch there is the player's, a drag or a pull included.
2. The system edges in the app: a work plays in landscape, full screen, inside the safe area (750 by 382 on an
   iPhone 17); a swipe from the top or the bottom needs a second swipe; the left edge is the work's. Read the live
   viewport, never a phone's screen size.
3. The top-right corner (`TOUCH_STYLE.reserved.right`, 120 by 60): nothing of the player's is drawn there, so its
   touches are the work's; the SDK keeps its own controls out of both corners.
4. The top band, as tall as the corners, is the SDK's playfield's edge, not the player's; in the app the iOS keyboard
   shortens the frame to its top (an ordinary resize).
5. No key: since runtime 1.27.0 Escape reaches the work like any key, on a computer and in
   an embed, and the player takes no key at all; a manifest may name `Escape` (a work's own menu key on a phone).
   The browser still lets a captured mouse go on Esc; the player does nothing then.

**Lifecycle** (the runtime's half; each optional, a work that sends none still plays): `ready()` ends the loading
screen (the first drawn frame does too: since runtime 1.11.1, the first frame after a canvas was drawn to, never a
loading screen in HTML over it) and the work starts muted until the first touch; `start()` a person's
interaction began (a game's run, a piece's first use; `gameplayStart()` the same); `moment(name, data?)` a moment in
the work's own terms (0.10.0: a preset changed, something made, a scene entered; recorded for the creator, shown to no
one); `end({ score })` an experience that really ends (the end card and a ten-second countdown; `complete()` the
same), and a work that never ends never calls it; `score(n)` for a work that keeps one; `idle()` nothing is
happening (recorded with the visit, never a card); `progress(step, of, label?)` recorded, drawn nowhere;
`error(message)` the error card. Calls before `init` wait (up to 64, and 32 moments) and go out at init. `on("pause" |
"resume" | "mute" | "orientation" | "insets" | "facts" | "arm")`; `save`, `load`, `share`.

**What a work should know**: a stroke keeps the frame once started, even across the pause corner; a held finger that
moves keeps holding, and `t0` is the down's time on every intent; a scene change keeps the camera and the layout as
they are; a field tapped is the work's (focus a field only from a touch, never a timer); forms never submit (the
frame's sandbox has no `allow-forms`: act on the button's click and Enter's keydown); pause holds `requestAnimationFrame`
and timers, so clamp your `dt`. Patterns with no word of their own (the survey's call 10): a charge reads
`performance.now() - t0` while `hold` is on; tiers and counts are the work's from each `t0` (say "hold a moment", never
a number); scrubbing is `holdDrag: "drag"`; auto-pan at the left and right edges from `drag`'s point and
`geometry().playfield`; a shake from `DeviceMotionEvent` after `gyro: "pitch"`; a story's chapter on `scrollend`.

**Sharp screens** (runtime 1.5.1; 1.17.0). In the app and, since 1.17.0, on a touch screen (a coarse pointer with
touch points: a phone or a tablet, in the web player and in embeds) `window.devicePixelRatio` reads at most 1.5 (the
getter is defined before the work's scripts run, and a value the work assigns is read under the same cap); on a
computer, a touch monitor with a mouse included, it is the screen's own. Only what a work sizes from it follows the cap; the page's text, CSS and images are
drawn at the screen's own ratio. Size the drawing buffer from it at the start and on each resize (a canvas's CSS
size times `devicePixelRatio`; three.js `renderer.setPixelRatio(window.devicePixelRatio)`), never from an assumed
number; a lower cap of the work's own is fine. `stats.pixelRatio` reports the value a work reads.

**Pause and the background.** The host pauses the work while its tab or the app is in the background and, on the
web, while the frame is out of view; also when the player froze you underneath (the Home button)
and while a sheet or the end card covers it, and a work backgrounded while running comes back frozen under the Home
screen until the person goes back in. `on("pause")`: the player froze you underneath; pause your clock if you have one. The runtime holds
`requestAnimationFrame` callbacks (delivered at the first frame after resume) and `setTimeout` callbacks that fall
due (run just after), and drops `setInterval` ticks; it also holds them while `document.hidden`, which the work hears
as `pause` and `resume` too (once each, whoever paused it).
`performance.now()` and the frame's timestamp keep counting, so clamp `dt`. Not held: CSS and Web Animations,
`<video>`, workers, `MessageChannel` loops, promises. Pause holds the sound as mute does: every `AudioContext` is
suspended and every media element paused, and both come back on `resume` unless muted (a work's own `resume()` or
`play()` meanwhile waits). The player's volume (runtime 1.24.0) sits above every sound you make, like a TV's
volume over a game's own audio menu: each `AudioContext`'s `destination` is the player's gain into the speakers, and a
media element plays at your `volume` times the player's (`volume` reads back your own). Your own music and effects
sliders keep working under it; you hear no event for it. On iOS a media element's volume is the device's (Safari
ignores the write); Web Audio follows the player there too. On `pause` the SDK lets go of every finger (the
stick reads 0, the button raises its off, a held forward is let go) and hides its layer until `resume`; on the
window's `blur` it clears the keys it reads (the axes read 0) and raises a held Space's `action` off. A work's own key
table should clear on `blur` too.

**Accessibility.** The frame carries the work's title (the iframe's `title`); the Home button is labelled ("Playspace").
The SDK's layer is `aria-hidden` and draws no words, and under `prefers-reduced-motion: reduce` its transitions and
animations are off. On a computer the keys are read by `code` (W A S D and the arrows by position, any layout) and
Space; there is no remapping. The stick, the look and the button need sight and touch; the player offers no other
way to move or look. Everything inside the frame is the work's: words as page text where it can (a canvas's words
are invisible to a screen reader), labelled buttons, `prefers-reduced-motion` for shakes and flashes, meaning never by
colour alone, sound's cues shown.

**Browsers.** The runtime and the SDK are plain ES2017 with no polyfill; the layer reads Pointer Events. In the app a
work runs in the iPhone's WebKit (`WKWebView`); on a computer and in embeds, in the person's browser. The check runs
every build in Chromium 153 (Playwright 1.63.0), as a phone and as a computer, with WebGL 2 in software (SwiftShader)
and no WebGPU; the hosted suite also runs the frame in WebKit 26.6. Firefox is not tested.

**Orientation and portability.** The player plays in both orientations on a phone; nothing names one:
every number is computed from the live viewport at each layout and touch, so the same layout lays out sideways and
upright, and `touch.geometry().orientation` says which the frame is now (0.15.0). A work adapts upright by its own
code (a `resize` handler, `camera.aspect`, a HUD by CSS); one that cannot says `fixed` in its manifest and is fitted to
the width. Never a rotate prompt, never `screen.orientation.lock`. The app's own conveniences (haptics on its controls, player mode, the edge
swipes deferred, the next work preloaded, the age sheet) are not part of the SDK.

**The modules.** The core is what every page gets, under the branch's 27.5 KB gzipped line. Six files are fetched from
the work's own origin (`/.playspace/`) only by a declaration or a call that needs them, never put on `window`:
`sdk-scroll`, `sdk-inspect`, `sdk-select` (`select`, `drag`, `holdDrag`), `sdk-gyro`, `sdk-menu` (the menu's bounds, at the first `menu` call; the declaration waits for it) and `sdk-camera` (the optional
presets and locomotion, at their first call; the calls made before it arrives are kept and run in order);
`playspace.layout` stays synchronous and `playspace.sdk.ready()` resolves once they arrive. Since 0.24.0 `sdk-text`
(text mode) is fetched at the first focus on a field of the work.

### The types

```ts
/** Viewport px, and normalized device coordinates (-1..1, y up: what a three.js raycaster takes). */
export interface IntentPoint {
  x: number;
  y: number;
  nx: number;
  ny: number;
}

/**
 * The intents (`input.onIntent`). The contract's are `tap` and `action`; the rest are the finger's other gestures, read
 * where a work wants them. Every one with a point carries the viewport px and `nx, ny` of the largest canvas (-1..1, y
 * up: what a raycaster takes; the viewport where there is no canvas), and `t0`, `performance.now()` at the down.
 * - `tap`: a tap (down and up within 260 ms under the 6 px slop; known at the lift) under every reading, and a click on
 *   a computer: an act at the point (use, pick, fire, open), never a destination. With `select`, an unhandled select's
 *   `target` and `via` ride on it. Under `forward: "toggle"` a tap flips the forward instead.
 * - `action`: the button (the disc at the lower right, Space on a computer): `on` at the down, off at the lift (`held`
 *   true when it was held, 0.9.2). `actionHold` (0.9.2, AQ42): the button held 250 ms, `on` then, off at its lift; a
 *   quick press is the first verb. Since 0.11.0 a work's second place-less verb is the second button (below), and a
 *   hold on this one carries a third (the cookbook's rule 8).
 * - `secondary` (0.11.0, AV29): the second button (the smaller disc above the action disc on a phone, Shift, the right
 *   mouse button (0.12.0) or the declared `keys.secondary` on a computer), only where the declaration names `secondary` or `keys.secondary`: `on` at
 *   the down, off at the lift (`held` true when it was held). `secondaryHold`: it held 250 ms, as `actionHold`. A held
 *   verb (run, sprint, boost, aim) takes it over a discrete one (interact, flashlight, alt-fire). No default.
 * - `look`: the same stream as `camera.onLook` (radians after the player's comfort, yaw right and pitch up positive):
 *   a drag on empty space, `inspect`'s drag, a story's orbit rect, the gyroscope; on a computer under
 *   `look: { computer: "capture" }` the captured mouse's movement (0.9.2).
 * - `doubleTap`: a double tap (a second tap within 300 ms and 24 px, raised in its place, and on a computer a double
 *   click on empty space, 0.9.2; `doubleTap: false` keeps it a
 *   tap). `zoom`: a double tap whose second down drags: `start`, `move`, `end`, `dx, dy` from that down (not under `own`
 *   or `forward`; drag down to bring a thing closer). On a computer the wheel too (0.9.2): `via: "wheel"`, `dx` 0, `dy`
 *   the accumulated delta in px (toward the person: closer), `end` after 150 ms of quiet; never under `scroll`. A zoom
 *   via the wheel includes a trackpad's inertia tail (the ticks after the fingers lift), so its `end` comes late. A
 *   trackpad's pinch on a computer (a wheel with `ctrlKey`, runtime 1.13.0) is `via: "pinch"`, `dy` positive as the
 *   fingers spread, the same start, move and end; the page never zooms. On a
 *   touch screen a two-finger pinch on empty space too (0.12.0, AV58): `via: "pinch"`, both fingers on the playfield
 *   (not a stick's zone, a disc or the band above; not the work's own interface or an `avoid` rect; never under `own`)
 *   with the first still pending (under the slop, no hold) when the second lands; once their distance has changed by
 *   the slop, `start` (of the landing: `t0` its time, `dy` 0), then `move` per move, `end` at
 *   either lift; `x0, y0` the fingers' midpoint at the landing, `x, y` now, `dx` 0, `dy` the change in their distance
 *   in px, positive as they spread (closer, the wheel's and the drag's sense; negative as they close). The page
 *   never zooms.
 * - `hold`: 250 ms still: `on` with the down's point, `off` at the lift (`x1, y1` its point); a held finger that moves
 *   keeps holding. On a computer a mouse button held still (0.9.2), with no tap at its lift. `press`: `on` at a finger's down on the playfield, off at its lift (informational: a finger landed;
 *   no default, the return ignored).
 * - `drag` (with the scheme's `drag`, or from a hold with `holdDrag: "drag"`, then `from: "hold"`): `start`, `move`,
 *   `end`, the origin `x0, y0`, `dx, dy` in px; `points` with `drag: "points"` (coalesced points, a secure page's);
 *   with `select`, `target` is what is under the finger now. `swipe`: at the lift, 40 px along the larger axis within
 *   300 ms, with `edge` (`"left"`, `"right"` within 24 px of the playfield's sides, `"bottom"`, else null).
 *   `vx, vy` on `swipe` and `drag`'s `end`: px/s over the last 80 ms.
 * - `select` (with the scheme's `select`): a tap that hit something, before the `tap`; handled, it is the tap.
 * - `dash`: the stick pushed past its travel fast (`via: "push"`), or flicked off with `flick: true`; `hx, hy` the
 *   stick's heading. A burst, never a held modifier: a sprint is the work's own reading of `moveX`/`moveY` at full
 *   deflection. Say "push harder to dash", never a number.
 * - `steer` and `forward`: the stick's x and the held forward under `forward`.
 */
export type Intent =
  | ({ type: "tap"; t0: number; target?: unknown; via?: "hit" | "element" } & IntentPoint)
  | { type: "action"; on: boolean; t0: number; held?: boolean }
  | { type: "actionHold"; on: boolean; t0: number }
  | { type: "secondary"; on: boolean; t0: number; held?: boolean }
  | { type: "secondaryHold"; on: boolean; t0: number }
  | { type: "look"; yaw: number; pitch: number }
  | ({ type: "hold"; on: boolean; t0: number; target?: unknown; x1?: number; y1?: number } & IntentPoint)
  | ({ type: "doubleTap"; t0: number } & IntentPoint)
  | { type: "steer"; x: number }
  | { type: "forward"; on: boolean }
  | ({ type: "drag"; phase: "start" | "move" | "end"; x0: number; y0: number; dx: number; dy: number; t0: number; points?: { x: number; y: number; t: number }[]; vx?: number; vy?: number; from?: "hold"; target?: unknown } & IntentPoint)
  | ({ type: "swipe"; dir: "left" | "right" | "up" | "down"; dx: number; dy: number; ms: number; t0: number; edge: "left" | "right" | "bottom" | null; vx: number; vy: number } & IntentPoint)
  | ({ type: "press"; on: boolean; t0: number } & IntentPoint)
  | ({ type: "zoom"; phase: "start" | "move" | "end"; x0: number; y0: number; dx: number; dy: number; t0: number; via?: "wheel" | "pinch" } & IntentPoint)
  | ({ type: "dash"; via: "push" | "flick"; hx: number; hy: number; r: number; vx: number; vy: number; t0: number } & IntentPoint)
  | ({ type: "select"; target: unknown; via: "hit" | "element"; t0: number } & IntentPoint);

/**
 * A subscriber returns `true` to say it handled the intent; otherwise the default binding applies: on a touch screen
 * `tap` is a click at the point on the work below the layer (on a computer the real click already reached it);
 * `forward` holds the forward key, `steer` the side keys past `keyThreshold` (0.35); `hold` is a held click under the
 * fallback and `v: 3`; `doubleTap` and `dash` pulse a key only where the scheme names one (`keys.doubleTap`,
 * `keys.dash`) or under the fallback. A handled release still lets go of a key the default held. `look`, `action`,
 * `actionHold`, `secondary`, `secondaryHold`, `drag`, `swipe`, `select`, `press` and `zoom` have no default (the two
 * buttons hold their declared keys, `keys.action` and `keys.secondary`, while pressed on a phone, handled or not).
 */
export type IntentHandler = (intent: Intent) => boolean | void;

/** A small button (pause, reset, menu): accepted and inert since 0.9.1 (AQ40, D5; CO 16 call 6): nothing is drawn or pressed; every work has the same UI. */
export interface SmallButton {
  type: "button";
  id: string;
  key?: string | string[];
  label?: string;
  icon?: string;
  side?: "top-left" | "top-right";
}

/**
 * A rect as fractions of the viewport, or a CSS selector: the work's own interface. The layer never takes a touch that
 * starts there, scroll included (v0.6, the pass-through): the touch is the work's, untouched, and raises no intent.
 * `pass: false` on a rect keeps the layer's reading there (a HUD the work draws but does not want tapped).
 */
export type Avoid = string | { x: number; y: number; w: number; h: number; /** default true: the touch passes to the work */ pass?: boolean };

/**
 * `select` (v0.6): a tap carries what it hit. The SDK never raycasts (it has no three.js): the work's own raycaster is
 * `hit`, asked first at the tap's point; then the `targets` selectors, matched by the element under the finger
 * (`closest`, below the layer: HTML hotspots such as a pin's ring; a button, link or field there is the work's anyway, by
 * the pass-through). A hit raises `select` before the tap; a handled `select` is the tap (no `tap`, no
 * default click); null (or false, or nothing) on both is the plain tap. A `hit` that throws is
 * a miss. `waitForDoubleTap: true` waits `doubleMs` (300 ms) before raising a tap on a target, so a double tap there is
 * only the `doubleTap` (a zoom never swaps the shade under it); without it (the default) the first tap acts at once, as boards and
 * rhythms need; `doubleTap: false` makes `hold` moot.
 */
export interface SelectOptions {
  /** The work's own hit test at the tap's viewport point (its raycaster): what was hit, or null. */
  hit?: (p: IntentPoint) => unknown;
  /** CSS selectors for HTML hotspots, matched by the element under the finger. */
  targets?: string[];
  /** Wait for a possible double tap before raising a tap on a target (default false). */
  waitForDoubleTap?: boolean;
}

/**
 * The declaration (version 3): every field optional, `{ v: 3 }` alone the layout. Only what the defaults cannot guess:
 * the button's word, `select`, the HUD to `avoid`, and one reading word (the tail's "The readings").
 */
export interface LayoutScheme {
  v: 3;
  /**
   * The keys the stick and the button press (KeyboardEvent.code), ahead of the host's facts and the preset's. `action`
   * is the button's key, held while the thumb is down (AQ28; it was `primary`, pulsed by a tap: a tap is now always the
   * click); `dash` (ShiftLeft by default) is the dash's (the plan's Task 5), `doubleTap` the double tap's.
   * `secondary` (0.11.0) is the second button's: held while the second disc is down on a phone, and on a computer read
   * as the second button beside Shift and the right mouse button (never in their place). On a computer `action` is read beside Space and the four
   * directions beside W A S D and the arrows (0.11.0: declared keys add, never replace). A scheme that names
   * `secondary` should not also name ShiftLeft as its `dash`.
   */
  keys?: { forward?: string; back?: string; left?: string; right?: string; action?: string; secondary?: string; doubleTap?: string; dash?: string };
  /**
   * AQ28: the one button, the action with no place (a jump, a flip). Declaring it draws the round button at the lower
   * right while the work listens (an `onIntent` subscriber; since 0.16.0 a declared action nothing hears and no
   * `keys.action` is not drawn). Since runtime 1.30.0 (AV245) a word of at most 8 letters is drawn on the disc; a longer
   * one draws the key's own cap instead (with no key, the letter A). The work reads `action` on and off.
   */
  action?: string | true;
  /**
   * 0.11.0 (AV29): the second button, the work's held verb (run, boost, aim) or its second action. Declaring it (a word
   * or true; `keys.secondary` does too) draws the smaller disc above the round button on a phone, live while an
   * `onIntent` subscriber listens or a key is named, and lets Shift and the right mouse button raise it on a computer
   * (0.12.0: where it is live, the browser's context menu does not open on the frame). Since runtime 1.30.0 (AV245) a
   * word of at most 8 letters is drawn on the disc, a longer one the key's own cap (with no key, the letter B); the
   * player's controls card says it too. The work reads `secondary` on and off.
   */
  secondary?: string | true;
  /**
   * The fallback's mouse only (never `onLook`'s scale): the game's radians per mouse px, the look sent as `mousemove`
   * in its units (without it the SDK's guess: 0.002 under a lock, a drag 2 pi per viewport height, 0.001 with Babylon),
   * and which mouse: "movement" (no button, on the locked element) or "drag" (a held drag from the canvas's centre).
   * `computer` (0.9.2, AQ40): the look's mouse on a computer, `"drag"` (the default: a mouse drag on empty space) or
   * `"capture"` (a click on empty space takes the pointer lock and raises no tap; the mouse's movement is then the look,
   * a click `tap` at the centre, a held button `hold`; Esc lets go (the player does nothing since runtime 1.27.0, AV234:
   * the work hears its own Escape and `pointerlockchange`); the next click takes it again).
   * Read on a computer only, for a work that reads the look (`camera.onLook`); a phone's drag is unchanged.
   */
  look?: { radPerPx?: number; mouse?: "movement" | "drag"; computer?: "drag" | "capture" };
  /** A racer or a runner: forward held by the SDK (`"toggle"`: by a tap); the move stick steers and brakes. */
  forward?: "always" | "toggle";
  /**
   * A story: the page is the space (the scroll module; no stick and no disc drawn). The SDK sets
   * `html,body{touch-action:pan-y;overscroll-behavior-y:none}` (the page scrolls; it never bounces past its ends), the
   * viewport meta, the pinch guard and the one-finger rule, and leaves every touch to the page except on the `orbit`
   * rects. On a touch screen only. Example: `playspace.layout({ v: 3, scroll: true, orbit: ["#hero"] })`.
   */
  scroll?: boolean;
  /**
   * Where the playfield's reading applies instead of the scroll (a hero you can turn): a drag there raises `look` from
   * its horizontal travel only (`pitch` 0), a tap `tap` (or `select`), a hold `hold`. Each selector gets
   * `touch-action: pan-y` (unless the work's own CSS says otherwise), so a vertical drag that starts on the hero still
   * scrolls the page. Rects are read where they are at each touch (they move with the page); keep one narrower than 80
   * percent of the width.
   */
  orbit?: Avoid[];
  /**
   * Default true (AQ11): `complete()` once the document's bottom has been in view for `endDwellMs` (default 1500, 0 to
   * 60000) after the reader's first scroll, or at once on a push past the end (a drag upward of 24 px that starts at the
   * bottom, or a wheel down there); never while a finger is on an orbit rect; once per page. `false` for a story that
   * loops or ends itself.
   */
  endAtBottom?: boolean;
  endDwellMs?: number;
  /**
   * A viewer or a configurator with no touch input of its own: the thing in the hand (the inspect module; no stick
   * drawn). A work whose own code reads its own drag or pinch (an orbit or trackball control, a pinch from its touches
   * or pointers, a gesture library) keeps its own touch (`"pointer": "own"` in the file) and declares no `inspect`: the SDK would take its pinch as
   * the `zoom` intent and its drag as the look (AV189, map, never remove). A drag looks, a tap is
   * `tap` (or `select`), a hold `hold`, a double tap `doubleTap`; the module adds the orbit (`camera.preset("orbit")`'s
   * yaw, pitch and distance; attach the work's camera and step it with `loop.start` or `camera.update(dt)`), fed by that
   * look: a drag right turns the object's front with the finger, a drag up lowers the camera. The orbit takes no
   * pinch (AQ11); since 0.12.0 a pinch raises `zoom` (`via: "pinch"`) for the work to read.
   * `speed`: the gain, a multiple of `comfort.lookSpeed` (default 1.5). `limits`: the orbit's stops in radians of its own
   * yaw (0: the camera on the centre's +z side) and pitch (default ±1.3); what reaches `onLook` is what turned.
   * `distance: [far, near]`: the orbit starts at `far` and stays between the two. `zoom`: `"doubleTap"` (default) eases
   * 300 ms to the other distance on a double tap; `"hold"` moves toward the farther at (far − near) per second while held;
   * `"none"`. They are the default bindings of `doubleTap` and `hold`: a work that handles them takes them over.
   * `camera.focus(point, { ms, center })` eases the orbit (450 ms) until a world point faces the camera.
   */
  inspect?: { speed?: number; limits?: { yaw?: [number, number]; pitch?: [number, number] }; distance?: [far: number, near: number]; zoom?: "doubleTap" | "hold" | "none" };
  /**
   * The work reads its own touch (a sling, a pen, a toy, an orbit control): nothing raised, no stick and no disc drawn,
   * every finger the work's. The SDK keeps the hygiene (the viewport meta, `touch-action: none`, `overscroll-behavior:
   * none`, the page's pinch guard: the page never zooms) and nothing else: since 0.17.0 (AV189, map, never remove) a
   * second and a third finger reach the work by their touch and pointer events too (its own pinch, its two-finger pan),
   * and no `zoom` intent is raised; before it a second finger was kept from the work while one was down.
   */
  own?: boolean;
  /** The move stick's dash (default true) and the release flick (default false): the `dash` intent. */
  dash?: boolean;
  flick?: boolean;
  /** `"drag"`: a drag from a hold raises `drag` with `from: "hold"` and never looks (pick, carry, drop); the select module. */
  holdDrag?: "look" | "drag";
  /** A tap carries what it hit (`SelectOptions`; the select module). */
  select?: SelectOptions;
  avoid?: Avoid[];
  /** Accepted and inert since 0.9.1 (AQ40, D5; CO 16 call 6): nothing is drawn or pressed; every work has the same UI. */
  controls?: SmallButton[];
  /** Look gain multiplier on `comfort.lookSpeed` (default 1; 0: no look, for a work that reads `drag`). */
  speed?: number;
  /** Raise `drag` intents (px from the origin) beside the look; `"points"` adds each move's coalesced points. */
  drag?: boolean | "points";
  /** The look's smoothing (ms) for this work, in place of `comfort.smoothing` (0: no tail after the lift). */
  smoothing?: number;
  /** False keeps a second tap within 300 ms and 24 px a tap (two `tap`s, no `doubleTap`). Default true. */
  doubleTap?: boolean;
  /** The gyroscope as an optional second look (never the only one; `ComfortSettings.gyro`). */
  gyro?: "off" | "pitch" | "full";
}

export interface ComfortSettings {
  /** Degrees of turn per short side of drag (v0.8; it was per width, the short side in portrait): the look drag, `inspect`'s drag. */
  lookSpeed: number;
  /** null (the default) is linear; a curve reads the drag's speed filtered over `filterMs`. */
  curve: { threshold: number; max: number; k: number } | null;
  filterMs: number;
  slop: number;
  smoothing: number;
  invertY: boolean;
  deadZone: number;
  keyThreshold: number;
  fov: { keepHorizontal: boolean; baseAspect: number; portrait: number; min: number; max: number };
  /**
   * The gyroscope as an optional second look (never the only one: the drag aims everywhere it does). The motion question
   * (`DeviceMotionEvent.requestPermission`, iOS) is asked at the first lift of a touch inside the frame once a scheme with
   * the gyroscope on is shown, never from `comfort()` (which only arms the next touch), so the order of the glue's calls
   * does not matter (v0.6). It is latched only on an answer: "granted" listens, "denied" never asks again, and a refusal
   * with no answer (the promise rejected) asks again at the next lift. Motion needs a secure context: on plain http the
   * frame has no `DeviceMotionEvent` and nothing moves. Absolute tilt (`deviceorientation`) is not offered: read the
   * sensors yourself (the frame's allow list permits them).
   */
  gyro: false | true | "pitch" | "full";
  gyroGain: number;
}

/**
 * 0.19.0 (runtime 1.31.0, DECISIONS AV246): on a laid place, why it is not drawn now (`drawn: false`): `yielded:
 * true` when its touch area covers the work's own control, `under` that control's tag and words, never a field's
 * value (at most 40 letters, `button "Launch"`). Absent when the place is drawn as laid. (0.20.0: `shown` went with
 * `touch.show`.)
 */
export interface PlaceShown { yielded?: true; under?: string }
export interface TouchGeometry {
  vw: number;
  vh: number;
  /** 0.15.0 (runtime 1.20.0; DECISIONS AV183): the frame's own orientation now (`innerWidth > innerHeight`: landscape). */
  orientation?: "landscape" | "portrait";
  insets: { top: number; right: number; bottom: number; left: number; edge: number };
  safe: { x: number; y: number; w: number; h: number };
  reserved: { x: number; y: number; w: number; h: number; corner: "left" | "right" }[];
  sizes: Record<string, number>;
  /** 0.9.2 (AQ40): how the look reads now: "capture" under the look module's pointer lock, "drag" for a work with a view, else null. */
  look?: "drag" | "capture" | null;
  /** A shown layout's playfield bounds (every reading; `own` and a story lay no zone over it). */
  playfield?: { x: number; y: number; w: number; h: number };
  /**
   * The move stick's zone and whether something listens to it (`live: false`: not drawn, its touches the playfield's).
   * 0.16.0 (runtime 1.21.0; DECISIONS AV186): `drawn` (a place is drawn exactly where it is live), the resting base's
   * centre `rest` and its size `base`, present whether or not the stick is drawn.
   */
  sticks?: { move: { x: number; y: number; w: number; h: number; live: boolean; drawn?: boolean; rest?: { x: number; y: number }; base?: number } & PlaceShown };
  /** The action disc's rect and whether something listens to it (AQ28: the declaration's `action`, `keys.action`, or the fallback's Space). */
  action?: { x: number; y: number; w: number; h: number; live: boolean; /** 0.16.0: drawn only where live (no dimmed disc). */ drawn?: boolean; /** Runtime 1.30.0: the key the disc presses, null with none. */ key?: string | null } & PlaceShown;
  /** 0.11.0: the second disc's rect (the map's B since runtime 1.30.0, up and toward the edge from A) and whether it is live; only where the declaration has the second button. */
  secondary?: { x: number; y: number; w: number; h: number; live: boolean; /** 0.16.0: drawn only where live. */ drawn?: boolean; /** Runtime 1.30.0: the key the disc presses. */ key?: string | null; /** 0.20.0: its word and its touch area. */ word?: string; hit?: { x: number; y: number; w: number; h: number } } & PlaceShown;
  /** 0.20.0 (runtime 1.34.0, AV254): the pill at the top left, the work's menu key, its rect drawn, its word and its touch area. */
  esc?: { x: number; y: number; w: number; h: number; live: boolean; drawn: boolean; place: "ESC"; key: string | null; word: string; hit: { x: number; y: number; w: number; h: number } } & PlaceShown;
  /** Whether the work has a view the drag turns (it reads the look, took a pointer lock, or is a viewer); false: the drag is the work's own. Any device. */
  view?: boolean;
  /** Whether something listens to movement (the stick's evidence; on a computer, W A S D and the arrows). Any device. */
  move?: boolean;
  /** Runtime 1.34.0 (AV254): the set's four places (`LS`, `A`, `B`, `ESC`), each its drawn rect, whatever a work uses. */
  map?: Record<string, { x: number; y: number; w: number; h: number }>;
  /** Runtime 1.34.0 (AV254): each place's touch area (the stick's, A's and B's the square their circle fills). */
  touch?: Record<string, { x: number; y: number; w: number; h: number }>;
  /**
   * Which of the four fit this frame (inside the safe area, clear of the reserved right corner and of the places before
   * it). `none`: the frame is under 300 px tall or has no room for the stick and A, so nothing of ours is drawn and
   * every touch is the work's own.
   */
  fit?: Record<string, boolean>;
  none?: boolean;
  /** 0.20.0 (AV254): a version 3 work has not said play began (`start()`): nothing of ours is drawn yet, every place `drawn: false`. */
  waiting?: boolean;
}

/** 0.13.0 (runtime 1.14.0, AV65): how an experience ended, for the end card ("You won", "Not this time", "Finished"). */
export type MenuOutcome = "won" | "lost" | "done";

/**
 * 0.13.0: one typed setting of the universal menu. `id`: a letter, then letters and digits, 24 at most; `label` 32 at
 * most; a `range` carries `min` and `max` (finite, `min < max`, `value` inside, `step` optional and positive); a
 * `choice` carries 1 to 12 `options` (each id once, labels 32 at most; an option's id a letter or a digit, then letters,
 * digits, `_`, `.` and `-`, 24 at most, so `"0.25"` is one since 0.17.0; one id outside it drops the whole choice) and
 * `value` is one of their ids; `applies:
 * "restart"` for a setting that takes effect only at a restart or a load. **Reserved ids** render in the panel's own
 * rows and the person's choice carries across works: `volume`, `music`, `effects` (ranges 0 to 1), `quality` (a choice
 * over `low`, `medium`, `high`, `ultra`), `difficulty` (`easy`, `normal`, `hard`), `language` (BCP 47 codes), `hud` (a
 * toggle); a reserved id outside its kind or vocabulary is dropped. Any other id is the work's own row. Never the
 * host's own rows (Sound, Look speed, Invert look, Fullscreen), and no reduced-motion row (the system's).
 */
export type MenuSetting = { id: string; label: string; applies?: "restart" } & (
  | { kind: "toggle"; value: boolean }
  | { kind: "range"; value: number; min: number; max: number; step?: number }
  | { kind: "choice"; value: string; options: { id: string; label: string }[] }
);

/**
 * 0.13.0: `playspace.menu`'s declaration, every field optional: `objective`, the one line the work is about (160
 * characters at most; under the title in place of the description's line); `score`, its unit (32 at most: "points",
 * "ms", a word) and which way is better ("lower" for a time); `restart`, the work restarts itself without a reload
 * when the panel's Restart raises `on("restart")` ("run" or "level"; undeclared, Restart is a fresh document);
 * `settings` (8 at most) and `modes` (6 at most: `{ id, label }`, raised as `on("mode", id)`).
 */
export interface MenuDeclaration {
  objective?: string;
  score?: { unit?: string; better: "higher" | "lower" };
  restart?: "run" | "level";
  settings?: MenuSetting[];
  modes?: { id: string; label: string }[];
}

/**
 * The lifecycle calls on `window.playspace` (the runtime's API, 1.4.0; see the file header's Lifecycle for what the
 * Player does on each). Inert outside Playspace's player: the messages go to the one parent the runtime was given.
 */
export interface PlayspaceLifecycle {
  /** The work can be played: ends the loading screen (as the first draw does). */
  ready(): void;
  /** 0.10.0: a person's interaction began (a game's run, a piece's first use); again on each restart. */
  start(): void;
  /** 0.10.0: `end()` with no result (the old `gameplayStop`): the player ends the experience under its end card. Prefer `end()`. */
  stop(): void;
  /**
   * 0.10.0: an experience that really ends (a game's end, a story's last scene), with its score (finite) when it keeps
   * one: the end card and the countdown to the next work. A work that never ends never calls it.
   */
  end(result?: { score?: number; outcome?: MenuOutcome }): void;
  /**
   * 0.13.0 (runtime 1.14.0, AV65): the work's universal menu, accepted and recorded, drawn nowhere since AV191 (D4: the
   * player's Home button shows nothing of the work's); `score` and `restart` are still read by the end card's best and
   * Play again, and the outcome by its reason line. A second call
   * replaces the first; `menu(null)` clears it. An item outside its bounds is dropped (one console line in
   * development, never a throw); true when the declaration was taken. Before the player is ready it waits.
   */
  menu(decl: MenuDeclaration | null): boolean;
  /**
   * 0.13.0 (runtime 1.14.0): one of the HUD's values ("Health 60 · Coins 12"), recorded and drawn nowhere (AV191), as it changes: `id` a
   * word (`MENU_ID`'s form), `value` a finite number or text of 24 characters at most, `label` and `unit` 32 at most
   * (kept per id once given). The last value per id goes out at most every 200 ms; at most eight ids a page (a ninth
   * is dropped). True when taken. A death that restarts the run inside the work is a stat, never an `end`.
   */
  stat(id: string, value: number | string, opts?: { label?: string; unit?: string }): boolean;
  /**
   * 0.10.0 (runtime 1.10.0): a moment in the work's own terms, recorded for the creator, shown to no one. `name`:
   * snake_case, a letter first, 40 at most (`preset_changed`, `object_placed`, `scene_entered`, `first_touch`;
   * `level_reached` in a game). `data`: at most 8 fields, each a snake_case key with a finite number, a boolean or a
   * string (40 characters). At most one per name every 250 ms and 100 a visit; before the player is ready they wait (up
   * to 32, one per name). True when it was sent or queued, not that it was kept.
   */
  moment(name: string, data?: Record<string, number | boolean | string>): boolean;
  /** `start()` under its first name (kept for good). */
  gameplayStart(): void;
  /** `end()` under its first name (kept for good). */
  complete(result?: { score?: number; outcome?: MenuOutcome }): void;
  /** The score now (finite numbers only). */
  score(n: number): void;
  /** Nothing is happening: recorded with the visit, never a card (AV191: the "Still there?" card retired). */
  idle(): void;
  /** A declared failure: the error card at once; the message (sliced to 300) is counted for review, never shown. */
  error(message: string): void;
  /** 1.4.0: where the person is (the header's Lifecycle): whole numbers, `of` 1 to 999, `step` 0 to `of`; label at most 40. */
  progress(step: number, of: number, label?: string): void;
  /**
   * The frame's safe-area insets and the system edge's reach as the Player last sent them (the `insets` event's
   * value, `playspace.on("insets", fn)`), or null before the first: a work that loads after the event reads it here.
   */
  insets(): { top: number; right: number; bottom: number; left: number; edge: number } | null;
  /**
   * 1.5.0 (docs/PLAN_CONTROL_LAYOUT.md 4.3): the host's facts about the build as the Player last sent them with `arm`
   * (the `facts` event's value, `playspace.on("facts", fn)`), a copy, or null before the first (and always outside the
   * app's Player): at most 32 key codes, four booleans (1.5.1's `app`: the page is the app's player). Host to frame only;
   * nothing about the person.
   */
  facts(): { keys: string[]; pointerLock: boolean; scrolls: boolean; touch: boolean; app: boolean } | null;
  /** Keeps up to 32,768 characters of text for a signed-in player, on every device they sign in on; resolves true when kept. */
  save(text: string): Promise<boolean>;
  /** The saved text, or null (no save, or a player who is not signed in). */
  load(): Promise<string | null>;
  /** Opens the share sheet with the work's words (the title cut to 100 characters, the text to 280). */
  share(o?: { title?: string; text?: string }): void;
  /** The player's events: paused, resumed, muted (the value is on), the screen turned, the insets, the facts, armed. */
  on(name: "pause" | "resume" | "arm", fn: () => void): void;
  on(name: "mute", fn: (on: boolean) => void): void;
  on(name: "orientation", fn: (value: "landscape" | "portrait") => void): void;
  on(name: "insets", fn: (insets: { top: number; right: number; bottom: number; left: number; edge: number }) => void): void;
  on(name: "facts", fn: (facts: { keys: string[]; pointerLock: boolean; scrolls: boolean; touch: boolean; app: boolean }) => void): void;
  /**
   * 0.13.0 (runtime 1.14.0): the person's answers to the work's `menu`: a declared setting's new value (a range's
   * clamped to its bounds; the stored ones arrive as soon as the declaration does, and an `applies: "restart"` one is
   * applied at the next restart), the panel's Restart where the work declared `restart` (restart without a reload), a
   * declared mode chosen (a restart in that mode). Nothing the declaration does not name ever arrives.
   */
  on(name: "setting", fn: (s: { id: string; value: boolean | number | string }) => void): void;
  on(name: "restart", fn: (scope: "run" | "level") => void): void;
  on(name: "mode", fn: (id: string) => void): void;
  /**
   * 0.18.0 (runtime 1.25.0, AV193): the player's Quality changed (`"auto"`, `"low"`, `"high"`). The player already
   * applied what it can on every work: under `"low"` `devicePixelRatio` reads 1.0; under `"high"` the screen's own
   * ratio; under `"auto"` at most 1.5 on a touch screen. Every tier calls your requestAnimationFrame back on every
   * frame of the screen (runtime 1.28.0, AV235: Low no longer halves it). One
   * `resize` reaches you just before your next requestAnimationFrame frame (a loop on timers alone never gets it, and
   * this event can reach you while the player's Home screen has you frozen: change detail here, draw at your next
   * frame). A `matchMedia` resolution query still answers the screen's ratio. Set your own detail levels here
   * (shadows, particles, post-effects, a renderer's pixel ratio): `"low"` your lowest, `"high"` your highest, `"auto"`
   * your own default. Your own graphics menu stays yours and may go finer.
   */
  on(name: "quality", fn: (tier: "auto" | "low" | "high") => void): void;
  /** Whether the player has the work muted (the `mute` event's last value). */
  readonly muted: boolean;
  /**
   * 0.18.0 (runtime 1.25.0, AV193): the player's Quality, the last the player sent (`"auto"` before any). The player
   * sends the person's choice as your frame opens (with the gates), so read it at load and follow `on("quality")`.
   */
  readonly quality: "auto" | "low" | "high";
  /** The runtime's version ("1.11.1"). */
  readonly runtime: string;
}

/**
 * 0.21.0 (runtime 1.36.0, AV310; docs/plans/PLAN_AI_PLAYS_FIRST_BUILD_2026-11-12.md section 2): one step of an autoplay
 * policy. x and y of a tap or a drag are 0..1 of the frame; the stick's are -1..1 (up negative); `ms` how long it holds.
 */
export type AutoplayStep =
  | ["stick", number, number, number]
  | ["a", number]
  | ["b", number]
  | ["tap", number, number]
  | ["tapText", string]
  | ["drag", number, number, number, number, number]
  | ["wait", number];
/**
 * 0.21.0: the controller a policy's `rule` gets: the Playspace set and nothing else (no key by name, no Esc, no menu).
 * The stick, A and B press the work's own keys for the set: the build's manifest's where it names one, else the key
 * its `layout()` names (`keys.forward`, `back`, `left`, `right`, `action`, `secondary`), else the policy's `map`; a
 * control with no key from any of them does nothing.
 * a tap or a drag goes to the work's element under the point; `tapText` clicks the work's own control by its words.
 */
export interface AutoplayController {
  stick(x: number, y: number): void;
  a(on: boolean): void;
  b(on: boolean): void;
  press(which: "a" | "b", ms?: number): Promise<void>;
  tap(x: number, y: number): void;
  tapText(words: string): boolean;
  drag(x0: number, y0: number, x1: number, y1: number, ms?: number): Promise<void>;
  /** The policy's own `reset()`. */
  reset(): void;
  /** Milliseconds since the policy began to play. */
  now(): number;
}
/**
 * 0.21.0: a work's autoplay policy, written once into the build: a visitor who does nothing sees the work come alive
 * after 3 s with no input, and the first input takes over (30 s at most, then it stops by itself). `start` runs once
 * (past a title), then `rule` every `every` ms (50 to 5,000; 250 by default) or `loop` for ever. `handover`: "fresh" (a
 * work with a score or a clock: `reset()` runs at the take-over, which spends that first touch) or "continue" (a toy, a
 * walk: the touch passes through as the person's first input). `reset()` puts the work back at its start and clears
 * what the run stored in the work's own storage.
 */
export interface AutoplayPolicy {
  handover: "fresh" | "continue";
  /**
   * Key codes for the stick (up, down, left, right), A and B where neither the build's manifest nor its `layout()`
   * names one; it never replaces a key either names.
   */
  map?: { move?: [string, string, string, string]; a?: string; b?: string };
  start?: AutoplayStep[];
  loop?: AutoplayStep[];
  every?: number;
  // eslint-disable-next-line @typescript-eslint/no-explicit-any -- the rule's scratch object is the rule's own
  rule?(c: AutoplayController, s: Record<string, any>): void | Promise<void>;
  reset?(): void;
}

/**
 * `window.playspace` on a served page: the runtime's lifecycle (`PlayspaceLifecycle`, the header's Lifecycle) and the
 * SDK's inside (input, touch, camera, locomotion, loop, audio). A work keeps its own controls out of what the player
 * reserves (the header's list).
 */
export interface PlayspaceSdk extends PlayspaceLifecycle {
  /** `version`: the SDK's ("0.11.0"; the names are frozen, the tail's "The 0.9 promise"); `ready()`: resolves once a scheme's module has arrived. */
  sdk: { version: string; ready(): Promise<void> };
  input: {
    /** `"moveX"` and `"moveY"` (-1..1, up negative): the move stick on a touch screen, the keys on a computer; else 0. */
    axis(name: "moveX" | "moveY" | (string & {})): number;
    onIntent(fn: IntentHandler): () => void;
  };
  /**
   * The declaration (`LayoutScheme`; laid out at once, a story's and a viewer's once their module arrives); null
   * removes it, and anything that is not `v: 3` is no declaration (AQ30). It governs a computer too (AQ27).
   */
  layout(scheme: LayoutScheme | null): void;
  /** A read-only copy of the declared scheme, as declared, null when none (the runtime reports its reading on `stats`). */
  layout(): LayoutScheme | null;
  touch: {
    /**
     * Tooling (the shared check, `pnpm sdk:try`): the controls as laid out, one per drawn control; [] with no layout
     * shown. Since runtime 1.30.0 (AV245's review) `x, y, w, h` are the shape drawn, `hit` the touch area where it is
     * larger, `place` the set's place (`LS`, `A`, `B`, `ESC`).
     */
    controls(): Record<string, unknown>[];
    /**
     * The frame's reservations, never null (v0.6): with a shown layout, its geometry (the playfield, the stick and the
     * disc too); without one (no scheme, a desktop, after `layout(null)`), the viewport, the insets with the edge, the
     * safe area, the reserved corners and the sizes.
     */
    geometry(): TouchGeometry;
    readonly shown: boolean;
    readonly visible: boolean;
    readonly device: boolean;
  };
  camera: {
    /**
     * Optional, three.js only, not the contract (AQ30): `attach`, `preset`, `update`, `resize`, `yaw`, `pitch`,
     * `distance`, `focus` and `locomotion.*` drive a three.js-shaped camera for a work that wants them; the camera module
     * arrives at the first call (`sdk.ready()` waits for it). The contract's camera is the work's own, turned by `onLook`.
     */
    attach(camera: unknown, opts?: { renderer?: unknown; target?: unknown; canvas?: unknown; resize?: boolean; maxPixelRatio?: number }): unknown;
    preset(name: "orbit" | "follow" | "first-person" | "fixed" | "side", opts?: Record<string, unknown>): unknown;
    update(dt?: number): void;
    resize(): void;
    /** The player's comfort settings, read-only for a work (AQ25 (h), AQ29): a write is ignored. */
    comfort(): ComfortSettings;
    onLook(fn: (yaw: number, pitch: number) => void): () => void;
    /** The vertical fov (degrees) for an aspect, keeping the horizontal field of `baseDeg` at 16:9; clamped. */
    fovFor(baseDeg: number, aspect?: number): number;
    /** Apply the pending touch look now, from the work's own frame (all of it, without the smoothing's remainder). */
    drain(): void;
    /** The orbit preset's yaw, pitch and distance, settable (v0.6; under an `inspect` scheme held inside its limits). */
    yaw: number;
    pitch: number;
    distance: number;
    /** v0.6, with an `inspect` scheme: ease the orbit until a world point faces the camera (`LayoutScheme.inspect`). */
    focus(point: Vec3, o?: { ms?: number; center?: boolean }): unknown;
  };
  /** Optional, three.js only, not the contract (AQ30): the camera module's walk by `moveX`/`moveY` and its scripted walk. */
  locomotion: {
    use(name: "walk" | "fly", opts?: { speed?: number; height?: number; collide?: (from: Vec3, to: Vec3) => Vec3 | void }): void;
    update(dt: number): void;
    /** Walk the SDK-driven camera (or its target) toward a world point on the ground plane; stops within `arrive` (0.5). */
    goto(point: { x: number; z: number } | null, o?: { speed?: number; arrive?: number; collide?: (from: Vec3, to: Vec3) => Vec3 | void }): void;
    readonly target: { x: number; z: number } | null;
  };
  loop: { start(fn: (dt: number, t: number) => void): void; stop(): void; fixed(hz: number, fn: (step: number, t: number) => void): void; readonly time: number };
  audio: Record<string, unknown>;
  /**
   * 0.21.0 (runtime 1.36.0, AV310): the build's autoplay policy, kept once (a second call is ignored); true when taken.
   * Played only where the player allows it, the work is armed, no one has touched it and no reduced motion (under the
   * work's own `layout()` as without one); stopped for good by a person's input, the Home menu, a hidden tab, 30 s or an error in the rule.
   */
  autoplay(policy: AutoplayPolicy): boolean;
}

export interface Vec3 {
  x: number;
  y: number;
  z: number;
}
```

## The 0.9 promise

From 0.9.0 the contract's names stop changing. A work written against 0.9 keeps working on every later 0.x and on
1.0: nothing frozen is renamed, removed or given a new meaning, and nothing below comes back once gone.

**Frozen at 0.9** (the names and what they mean):
- **The four verbs:** `playspace.input.axis` with `"moveX"` and `"moveY"` (-1..1, up negative; a read makes the stick
  live); `playspace.camera.onLook` (radians after the player's comfort, yaw right and pitch up positive; it returns
  the unsubscribe); `playspace.input.onIntent` (a subscriber returns true for what it handled; it returns the
  unsubscribe) with its `tap` (an act at the point, never a walk); and the button, the `action` intent (`on` at the
  down, off at the lift, `t0`); and, from 0.11.0, the second button, the `secondary` intent (the same shape).
- **The declaration's words:** `playspace.layout` with `{ v: 3 }` and its keys `v`, `keys` (`forward`, `back`,
  `left`, `right`, `action`, `doubleTap`, `dash`; `secondary` added in 0.11.0), `action`, `secondary` (0.11.0), `look` (`radPerPx`, `mouse`; `computer` added in 0.9.2), `forward`, `scroll`,
  `orbit`, `endAtBottom`, `endDwellMs`, `inspect` (`speed`, `limits`, `distance`, `zoom`), `own`, `dash`, `flick`,
  `holdDrag`, `select` (`hit`, `targets`, `waitForDoubleTap`), `avoid`, `controls`, `speed`, `drag`, `smoothing`,
  `doubleTap`, `gyro`; `playspace.layout(null)` removes it; anything that is not `v: 3` is no declaration.
- **The intents** (their names and the fields `Intent` gives them): `tap`, `action`, `look`, `hold`, `doubleTap`,
  `steer`, `forward`, `drag`, `swipe`, `press`, `zoom`, `dash`, `select` (and `actionHold`, added in 0.9.2;
  `secondary` and `secondaryHold`, added in 0.11.0); and the default each one has or has not
  (`IntentHandler`).
- **The lifecycle signals:** `playspace.ready`, `playspace.start`, `playspace.moment`, `playspace.end`,
  `playspace.stop` (0.10.0's neutral names; documented first), `playspace.gameplayStart`, `playspace.complete`,
  `playspace.score`,
  `playspace.progress`, `playspace.idle`, `playspace.error`, `playspace.on` (`pause`, `resume`, `mute`,
  `orientation`, `insets`, `facts`, `arm`), `playspace.save`, `playspace.load`, `playspace.share`,
  `playspace.insets`, `playspace.facts`, `playspace.muted`, `playspace.runtime`, `playspace.camera.fovFor`,
  `playspace.sdk.version` and `playspace.sdk.ready`.
- **The reservations**: `touch.geometry()`'s `safe`, `insets` and `reserved` (the corners the
  player keeps), so a work can keep its own buttons clear of them.

**Additive only** (a later version may add, never take away): a new intent, a new optional field on an intent, a new
declaration key or reading word, a new event for `on`, a new lifecycle call, a new module, a new field on
`touch.geometry()` or the runtime's `stats`. A work that ignores an addition plays as before. The numbers in the
reference (the tap's 260 ms, the slop, the sizes, the comfort's values, the idle waits) are the player's and may be
tuned; what each word means does not change with them.

**Tooling** (for the check, `pnpm sdk:try` and a developer's own eyes; kept, and its fields not renamed, but a work
should not steer by it): `touch.geometry()`'s other fields (the live flags, the zones, the sizes), `touch.controls()`,
`touch.shown`, `.visible`, `.device`, the getter `playspace.layout()`, the runtime's reading on `stats` (`grammar`,
`live`), and `pnpm sdk:try`. Since runtime 1.7.0 `stats` also carries the SDK's own report, `sdk` (the check records
it on the build as `HostedInput.sdk`, beside the controller's verdict, `HostedInput.controller`): `declared`, the
`reading`, the contract's `verbs` the work used (`move`: it read the stick; `look`: it subscribed to `onLook`; `tap`
and `action`: an `onIntent` subscriber was there when one was raised), the intents it `handled` (returned true for),
the removed names it reached for (`legacy`, by the gone list below, and a declaration that is not `v: 3`), the
declaration's `unknownKeys` (each also a console warning) and its `comfortWrites`. A work on the contract reads
`declared`, with `legacy` and `unknownKeys` empty and no comfort write.

**Optional, not the contract** (they stay and may still change before 1.0; a work that leans on them may need a change
at a later 0.x; the cookbook's section 4 says what the SDK does with each):
`camera.attach`, `.preset`, `.update`, `.resize`, `.yaw`, `.pitch`, `.distance`, `.focus` and `locomotion.*` (three.js
only, the camera module's); `camera.drain()`; `loop.*`; `audio`; `camera.comfort()` (the player's feel, read-only).

**Gone, and never coming back** (removed by 0.9.0): the version 1 schemes (the sticks and pads, the d-pad, the
gesture recogniser); `v: 2` with its grammar words; the action map (`input.use`, `.bind`, `.down`, `.pressed`,
`.released`, `.on`, `.emitKeys`, `.update`, `.lock`, `.unlock`); `touch.insets`, `.click`, `.fit`, `.state` (the
old show came back in 0.19.0 as a place's show and hide, and went again in 0.20.0, our controls appear when play begins); `geometry().zone` and `.grammar`; `sdk.pinned` and `sdk.load`; and the old names, each now its new one:
the old `secondary` (the double tap) is `doubleTap`, `select.hold` is `select.waitForDoubleTap`, `thrust` and
`keys.sprint` are `dash` and `keys.dash`, `touch.layout`, `touch.layouts` and `touch.scheme()` are
`playspace.layout`. The one word that came back, by Playspace's decision: `secondary`, at
0.11.0 the second button and nothing else (never the double tap it was before 0.9). Kept for the old
`playspace.js` script only, never the contract: `gameplayStop` (say end, or its 0.10.0 name stop) and
`playspace.version` ("0").

**1.0** is declared only after both: the proof (the transcoder on its set of works)
passes with no change to the SDK, and a pilot of real creators' works has been transcoded and played on phones.
Until then a frozen name changes only by Playspace's decision, with a new SDK version and a line below. Per-build
pinning comes before transcoding at scale: every build keeps the SDK version it was published with; today
every page gets the one SDK.

**The SDK's versions:**
- 0.28.0 with runtime 1.45.0 (no call changes): `playspace.json`'s `"capture": true` beside
  `"pointer": "look"`: on a computer a click takes the mouse and its movement turns the view (Esc gives it back),
  with no `layout()` declared; left out, a drag turns the view as before. A phone is unchanged.
- 0.27.0 with runtime 1.42.0 (no call changes): the viewer's loop's changes taken back out.
  A person's first touch, click or key no longer runs the policy's `start` steps (0.25.0 and 0.26.0):
  `start` runs only when Buddy plays, as in 0.21.3; the key-cap row on a computer shows from play's beginning again
  (0.23.0's wait for a first input is gone), and the runtime's `paint` no longer comes from a canvas that has not
  drawn. Text mode (0.24.0) is unchanged.
- 0.24.0 with runtime 1.39.0 (additive, no call changes): text mode. While the work's own text
  field has the focus our controls on a phone are hidden and their keys let go, the key hints on a computer are
  hidden, a touch outside the field and the pause let it go, the first Esc lets it go after the work heard it, and
  Buddy neither starts nor presses a key; a key typed in a field is never counted in the runtime's `keyed`; the
  frame's `typing` message says when a field takes or leaves the focus (cookbook 0.7).
- 0.21.3 with runtime 1.36.2 (no call changes): a policy's `drag` lasts its `ms` by the clock,
  whatever the tick rate (it counted 32 ms ticks, so on a slow renderer a 2 s drag outlasted the 30 s and the steps
  after it never ran); its last move is at the end point.
- 0.21.2 with runtime 1.36.1 (no call changes): while a policy plays, the layer's own
  forward hold (a `forward: "always"` layout on a phone) is let go and comes back at a person's first input, so a
  policy that stops never leaves the work's forward key down.
- 0.21.1 with runtime 1.36.1 (additive, no call changes): the SDK's own report says whether a
  policy is registered, so the check plays it on each device and records whether it passed; the host plays a policy
  only where that check passed and the manifest does not say `autoplay: { mode: "off" }`.
- 0.21.0 with runtime 1.36.0 (additive): `autoplay(policy)`, the build's own autoplay policy, played
  by the `sdk-auto` module only where the host allows it (off everywhere for now); while it plays the
  work's `score`, `save`, `stat`, `moment`, `end` and `complete` are dropped (a save answers false).
- 0.20.0 with runtime 1.34.0: the Playspace set on a phone (the stick, A, B and the pill; seven
  places, the list, the pad and the pair gone); `touch.show` is gone (0.19.0 was never released); `touch.geometry()`
  reports the four places (`map`, `touch`, `fit`, `esc`; `slots`, `list` and `over` gone); the facts carry `set`.
- 0.19.0 with runtime 1.31.0 (additive): `touch.show(place, on)` and `touch.show(on)`; a place
  yields to the work's own control under it; a held right-hand button's drag turns the view. `touch.geometry()` adds
  `shown`, `yielded` and `under` on a place; the module `sdk-yield` comes with a laid controller on a touch screen.
- 0.18.0 with runtime 1.30.0 (no API change, additive geometry): the Playspace controller on a
  touch screen, the version 1 manifest read onto its fixed map of eleven places by rule, the list START opens for
  what has no place left (nothing dropped, the cap of twelve gone), words only (no icon), the approved look.
  `touch.geometry()` adds `map`, `list` and each place's `place`; `over` is 0.
- 0.18.0 with runtime 1.28.0 (no API change): Low no longer thins frames (only its pixel ratio of
  1.0 stays; `cadence` is 60 on every tier); a page the check found scrolls scrolls on a vertical drag anywhere, under
  any `touch`, unless the manifest declares a stick or drag-to-look or the check saw a drag answered.
- 0.18.0 with runtime 1.27.0 (no API change): Escape is the work's (the runtime no longer takes
  it and the player no longer pauses on it or on a pointer lock let go; a manifest may name `Escape`); Auto never
  thins frames (only Low holds 30); a page the check found scrolls keeps its scroll under the layer.
- 0.18.0 (runtime 1.25.0): additive: `playspace.quality` and `on("quality")`; the player's
  Quality is Auto, Low, High; Low is pixel ratio 1.0 on every work (and, until runtime 1.28.0, about 30 frames a second); your own detail
  levels follow it where you wire them. A work that declared the reserved `quality` setting (0.13.0) also hears
  `on("setting")` with its lowest option on Low, its highest on High and its declared value on Auto. Size your
  drawing buffer from `devicePixelRatio` in your resize handler: a buffer sized once at boot follows at the next load.
- 0.17.0 (runtime 1.22.0; map, never remove): under `own` every finger is the work's (the
  second and third too: a work's own pinch or two-finger pan reaches it; no `zoom` intent is raised under it); the
  one-finger rule holds under every other reading. A choice's option id takes a dot after its first character
  (`"0.25"`). `inspect` is for a viewer with no touch input of its own. Additive: every name stays.
- 0.16.0 (runtime 1.21.0): only the controls a work uses are drawn. A
  stick, A or B nothing listens to is not drawn (no dimmed ghost); its corner is the playfield's. `touch.geometry()`
  gains `drawn` on `sticks.move`, `action` and `secondary`, and `sticks.move.rest` and `.base`; `slots`' A and B say
  `drawn` truthfully. A work with its own control manifest (a `controls` block in its playspace.json) draws exactly
  what the manifest names, whatever it declares: the stick where it has a `move` (never under `own`), A where it
  names a `primary`, B a `secondary`; a declared `action` or `secondary`, a subscriber or a read adds no place, and A
  or B presses the manifest's key where `keys` names none. Additive: every name stays.
- 0.13.0 (runtime 1.14.0):
  the universal menu's contract, additive: `menu(decl)`, `stat(id, value, opts?)`, `end({ outcome })` and the events
  `setting`, `restart` and `mode`; the SDK's report gains `menu`. The contract's words say both halves: a work
  tells its universal information and still never asks the chrome for anything.
- Runtime 1.13.0 (the SDK stays 0.12.0, no name changes): mixed devices (a finger on a computer's
  touch screen, a keyboard beside a touch screen), a trackpad's pinch is `zoom` `via: "pinch"`, Ctrl+click on a Mac is
  the right mouse button, and the report's `look` says "capture" from the declaration (its `locked` says whether the
  lock is held now).
- 0.12.0: the right mouse button presses the second button on a computer, beside
  Shift and under its conditions (the browser's context menu does not open on the frame where B is live), under the
  pointer lock too; a two-finger pinch on empty space on a phone raises `zoom` with `via: "pinch"` (runtime 1.12.0).
- 0.11.0:
  the second button: the intents `secondary` and `secondaryHold` (the `action` pair's shape and hold time), the
  declaration's `secondary` and `keys.secondary`, a second disc above the action disc on a phone (only where
  declared), Shift (and a declared `keys.secondary`) on a computer; the desktop reading also honours a declared
  `keys.action` beside Space and `keys.forward`/`back`/`left`/`right` beside W A S D and the arrows (runtime 1.11.0).
- 0.10.0: the neutral names `start()`, `stop()`, `end(result?)`
  (the same calls as `gameplayStart`, `gameplayStop` and `complete`; `gameplayStart` and `complete` stay for good,
  `gameplayStop` with the old script) and `moment(name, data?)`
  (runtime 1.10.0), because Playspace is interactive as entertainment, not games.
- 0.9.2: added `look.computer` (`"drag"` | `"capture"`), the wheel's `zoom` (`via: "wheel"`) and the
  mouse `hold` on a computer, `touch.geometry().look`, the module `sdk-look` (computers only); `actionHold` and
  `action` off's `held` (the button held, the second verb), and the double click as `doubleTap` on a computer.
- 0.9.1: `controls` draws nothing, on any device (the word stays known, inert; D5).
- 0.9.0: the names frozen (this promise); one shape (`v: 3` only) and the subtraction and renames above;
  the camera presets and locomotion moved to the lazy `sdk-camera` module; on a computer a viewer's mouse drag turns
  its orbit.
- 0.8.0: the one layout (`v: 3`: the move stick, the action disc, the playfield), the fallback from the host's facts.
- Before 0.8: CHANGELOG.md.
