Repository navigation
Let lf-motion run on a plain HTML page, with Leaf's Lit loading anywhere - #4616
Merged
Merged
Conversation
`lf-motion` now loads, draws and plays by its own controls on a plain HTML page that maps `/runtime/` and `/vendor/` with its own import map, as `lf-chart`, `lf-code` and `lf-diagram` do. On a Leaf page it looks and behaves as before, except that a playback failure now also says so in the transport. Its import graph is 17 runtime modules and 101 KB of source plus `/vendor/lit.js` (33 KB), down from 183 modules and 2,252 KB. `lf-diagram`'s grows from 14 modules and 76 KB to 17 and 101 KB, since the portable surface now carries Lit's names, the motion preference and the first-drawing reader. **Leaf's Lit loads in any document.** `/vendor/lit.js` imported `/runtime/dom-move.js`, whose `focus.js` reads prepaint's `lfInputs` at import, and Lit's insertion seam and namespace assignment both dereferenced `document.documentElement.lfInitial`. Now the seam asks the root for its mover at each insertion and inserts natively where there is none, the namespace is assigned only where a coordinator exists, and the runtime installs the focus-preserving mover from outside: `framework.js` imports `dom-move.js`, and neither `lit.js` nor `lit-shared.js` does. The kernel no longer serves `dom-move.js` as an entry of its own, which existed only because Lit imported it by URL. **Words for a listener are an event.** `announce(message)` keeps its form and moves to the portable surface: it dispatches `lf-announce` on the window with the words as `detail`, which `notifications.js` says in the live region and a page without Leaf leaves unsaid. Every caller is unchanged. `runtime-globals.d.ts` declares the event. **A first drawing off Leaf.** `initialRender(host, draw)` adopts prepaint's drawing where a coordinator ran, and otherwise calls `draw` with plain tools and renders it. The plain tools set only the widget's own classes, button type and name, not Leaf's marks (`lf-ui`, a role's face, `data-lf-gen`, `data-lf-offer`), which nothing reads there. Motion's producer moves beside its widget (`widgets/motion-view.js`) and imports the portable helpers by served path; the initial bundle imports it, and `build/initial.mjs` resolves `/runtime/` to sources with `sideEffects: false`, so the bundle holds only what the producer uses. Where `drawsFirst()` says a coordinator drew, the module defines the element at once and fetches nothing more; elsewhere it imports the producer and defines the element once it arrives (a module-level `.then`), so every study upgrades with its producer in hand and draws in the task that upgrades it. - Rejected: a static import, which had every Leaf page fetch the 3.4 KB producer it never runs, one more request on upgrade. Also rejected: a top-level `await import()` before `customElements.define`, which the lint rule `architecture/top-level-await` refuses because it turns off the bundler's chunk merging; and defining at once and waiting for the producer in each instance's connection, a second route through setup. - Off Leaf a widget that draws at upgrade still grows when it is defined, so a host that doesn't reserve its room sees what follows it move: deferring the definition keeps the widget from showing undrawn but can't move its drawing before the first paint. (The Layout Instability API scores the old and new shapes alike here: the authored nodes the drawing moves are reinserted, which it doesn't count, and what follows moves the same either way.) - Rejected: off Leaf the widget renders its own template with no adoption. The template is the producer's and calls the producer's tools, so that path needs the same module and tools, with the branch in each widget instead of in `initialRender`, which seven other `x-initial` widgets can share. - On the motion playground the page reaches its first presented state with 3 fewer requests (2 of them script) and 5 KB more, and on lost-update with 3 fewer and 1.5 KB more, against main. **The widget.** It extends `HTMLElement` and draws its transport with Lit's `render` in the task that changes it, as it already did for every frame, so it claims no presentation. `onUserInput` becomes window capture listeners for the inputs prepaint counts, `signal` a private field, and `reducedMotion` and `onMotionPreferenceChange` portable exports. - Rejected: `LitElement` with a `PendingTaskEvent` on its first update, which adds Lit's asynchronous scheduler beside the per-frame `render` and a public `LitElement` export. Also rejected: splitting `LeafElement` so Leaf attaches presentation from outside, a change to all 30 `LeafElement` widgets for state this one doesn't read. - What `LeafElement` gave it that no longer applies: a region claim per update and no drawing while detached; motion's setters drew directly before too. - **Play** is the widget's own button. Its row names the press its control makes, with no `run`, so the register runs nothing for it; one click listener plays when there is something to play; and the transport draws the button `aria-disabled` from a `playable` input, the availability the register reads. The producer reads the study's videos before the coordinator moves the authored nodes into the body box, so a video study is available from first paint. - **A playback failure** reaches the agent through `reportFailure`, and the clock's place says "Failed" until the next press or seek, on any page. It replaces `raiseError`, whose notice exists only in Leaf's panel. The word fits the clock's 9ch box, where "Playback failed" moved the transport. - **A drawing failure** shows the fail-soft box beside the transport, placed by the widget (`placesFailure`): the default replaced the Lit part, whose template holds the author's study, so a throwing frame deleted the study and a frame that kept throwing swapped box and transport every frame. One failure keeps one box and stops the clock, and a frame that draws takes it away. Play draws the first frame before saying Pause, so a throwing frame doesn't write Pause and back in one task. No protocol bump: the public package API doesn't move it (#4551). **Tests.** - The smoke test adds lf-motion (transport, icon, scrubber), sets `renderFrame`, clicks Play, and sees the clock and the last frame reach the end. The host hides each widget until defined, serves the producer late so the page paints first, lays its widgets two to a row with the one that draws at upgrade last, so its growth moves nothing under the shift watch, and holds the clock to one width as the package's stylesheet does. - New `test_a_motion_failure_shows_beside_the_study_and_reaches_the_agent` and `test_play_is_available_from_first_paint_only_where_there_is_something_to_play`. `test_timeline_steps_by_every_route_and_keeps_the_step` asserts a key's step is said in the live region. - Each failed when undone: Lit's seam without its native fallback (`reading 'move'` in `lit.js`); `notifications.js` not hearing `lf-announce` (live region empty); the "Failed" word removed; the widget's failure placer removed (the study is deleted); the videos read after the body box takes them (Play drawn `aria-disabled` at first paint on a video study). - Also run: `pnpm run test:runtime` (695), `pnpm run check:browser`, pre-commit, `test_motion.py`, `test_timeline.py`, `test_key_surfaces.py` (its announce test included), a board's keyboard move, a diff's hunk step, retained moves, the initial-delivery tests, initial settlement, the pending-task hold, the public API before boot, and a reply's widget module. > _This was written by Claude Code on behalf of max-sixty_
leaf-agent
reviewed
Oct 28, 2026
leaf-agent
left a comment
Collaborator
There was a problem hiding this comment.
The plain-page initial-view tools omit one of the action constructors the new authoring guidance exposes; a producer using actionOffers(tools).offerAction(...) fails outside Leaf. The inline suggestion supplies the missing constructor.
`actionOffers(tools)` wraps both `offerAction` and `offerActionElement`, but `initialRender`'s plain tools supplied only the element writer, so a producer calling `actionOffers(tools).offerAction(...)` threw `base.offerAction is not a function` off Leaf while working on a Leaf page. The plain tools now carry `offerAction` in prepaint.js's shape: a button whose worded role shows its label as words and whose symbol or mark says it as its name. Reported by Leaf's reviewer on #4616. The new runtime test, `off Leaf, a producer gets both role constructors in prepaint's shapes`, fails with `offerAction` left out of the plain tools. `pnpm run test:runtime` (696) and `pnpm run check:browser` pass. > _This was written by Claude Code on behalf of max-sixty_
# Conflicts: # dist/kernel/runtime/bundle-copy-control.js # dist/kernel/runtime/bundle-data.js # dist/kernel/runtime/bundle-layer-client.js
leaf-agent
approved these changes
Oct 28, 2026
max-sixty
added a commit
that referenced
this pull request
Oct 28, 2026
…here a key lands (#4626) `lf-timeline` now loads, draws and steps by its own buttons and marks on a plain HTML page that maps `/runtime/` and `/vendor/` with its own import map. On a Leaf page it behaves as before. Its import graph is 18 runtime modules and 104 KB of source plus `/vendor/lit.js`, down from 183 modules and 2,256 KB. On lost-update the page reaches its first presented state with 2 fewer requests and 4 KB more, against main: the drawing module is fetched only off Leaf, as lf-motion's producer is. **`lands(from)`, a command row field.** A key that steps from a row of the step list carried focus to the new step's row through `focused()` and `focusDestination()`, which live in `focus.js` and load only on a Leaf page; the lint rules for current-location reads and placements refuse the platform equivalents. The register now does it: right after it runs a row for a key, a command-reference pick or a click on the row's `control`, it calls the row's `lands(from)` with the element the press came from and puts the user on what it returns as a move. The call is synchronous, so it reads the state the run left. `runLanding` in `keyboard/scopes.js` is the one place, which the button adapter and both of the dispatcher's invocation builders use; `checked` refuses a `lands` that isn't a function; the row header in `bindings.js` and module-input.md's "Command rows" say what it means, and "Walks" points there. The timeline's rows declare `lands: (from) => rows.includes(from) ? rows[current] : null`, today's rule. Rows that move focus in their own `run`, as `lf-dial` and `lf-tabs` do, keep doing so. - Rejected: landing after a margin entry's activation too. The activation already decides focus itself (it returns the user to the entry's surface only while its origin still holds focus), so a `lands` there would either repeat that check or override it; the entry keeps its own handling. - Rejected: importing Leaf's focus helpers on the keyed path only. A dynamic import resolves a task later even for a loaded module (measured in Chromium and Firefox), after the key's frame. **A run-less row that names a control owns its keys.** Previous and Next are the widget's own buttons, as Play is lf-motion's: their rows name the press their control makes and have no `run`, and the drawing's `aria-disabled` at each end is the availability the register reads. The dispatcher didn't count such a row as making its press (`ownsLeafInvocation`), so while it was unavailable its scope stopped claiming its key, and ArrowRight on a deck's timeline at its last step turned the deck's card, against keyboard/AGENTS.md's rule that an unavailable command's press reaches no other command. A row now owns its keys when it or one of its routes names a `control`, since Leaf makes that press with `click()`; the dispatcher's comment and module-input.md's "How scopes compose" say so. No other row in the tree is run-less with keys and a control (a scan of `browser/`, `packages/` and `examples/`), so nothing else changes. **The rest, as lf-motion does it.** The drawing moves beside the widget (`widgets/timeline-view.js`) and imports the portable helpers, including the time axis's; the initial bundle imports it and holds the same code as before. The widget extends `HTMLElement`, draws the drawing's template with Lit in the task that changes it, and shows `failSoft`'s box on a throw. Off Leaf the element is defined once its drawing module arrives, so it upgrades with the producer in hand. Off Leaf a step row is neither a button nor a tab stop, since only Leaf's step row makes Enter and Space work; the pointer still picks it. The `quoted(this)` check before keeping the step goes: ids are unique across a page and its replies, and a sample's frame keeps its tab store under its own page root. - Rejected: native `<button>` step rows. widget-elements.js keeps a page word that is also a control a span with a role so it stays selectable, its drag guard tells a press from the release that ends a selection, and Leaf's theme dresses selectable offers and native buttons differently; moving the rows to buttons reopens that decision for every selectable offer, not just these. **Tests.** - The smoke test adds lf-timeline (transport with its symbols, a row per step), clicks Next to reach the second step, and with the keyboard alone reaches Previous and Next by Tab and steps with Enter and Space. It failed with Previous's click listener removed. - New `test_a_timeline_s_unavailable_arrow_reaches_no_command_around_it`: a timeline in a deck, at its last step, keeps the deck's card and the user's place on ArrowRight. - Each failed when undone: the dispatcher not counting a run-less control row (the deck turned and focus left the row); the rows without `lands`, and the dispatcher running rows without landing (focus stays on the first row after ArrowRight in `test_timeline_steps_by_every_route_and_keeps_the_step`); the widget importing `widget-api.js` (the smoke test's load error). - Also run: `pnpm run test:runtime` (696 after rebasing on #4616), `pnpm run check:browser`, pre-commit, `test_timeline.py`, `test_motion.py`, `test_key_surfaces.py`, a board's keyboard move, a diff's hunk step, retained moves, the initial-delivery tests, initial settlement, the pending-task hold, the public API before boot, and a reply's widget module. No row whose routes name controls has keys yet, so that half of the ownership rule has no test. > _This was written by Claude Code on behalf of max-sixty_
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
lf-motionnow loads, draws and plays by its own controls on a plain HTMLpage that maps
/runtime/and/vendor/with its own import map, aslf-chart,lf-codeandlf-diagramdo. On a Leaf page it looks and behavesas before, except that a playback failure now also says so in the transport.
Its import graph is 17 runtime modules and 101 KB of source plus
/vendor/lit.js(33 KB), down from 183 modules and 2,252 KB.lf-diagram'sgrows from 14 modules and 76 KB to 17 and 101 KB, since the portable surface
now carries Lit's names, the motion preference and the first-drawing reader.
Leaf's Lit loads in any document.
/vendor/lit.jsimported/runtime/dom-move.js, whosefocus.jsreads prepaint'slfInputsatimport, and Lit's insertion seam and namespace assignment both dereferenced
document.documentElement.lfInitial. Now the seam asks the root for its moverat each insertion and inserts natively where there is none, the namespace is
assigned only where a coordinator exists, and the runtime installs the
focus-preserving mover from outside:
framework.jsimportsdom-move.js, andneither
lit.jsnorlit-shared.jsdoes. The kernel no longer servesdom-move.jsas an entry of its own, which existed only because Lit importedit by URL.
Words for a listener are an event.
announce(message)keeps its form andmoves to the portable surface: it dispatches
lf-announceon the window withthe words as
detail, whichnotifications.jssays in the live region and apage without Leaf leaves unsaid. Every caller is unchanged.
runtime-globals.d.tsdeclares the event.A first drawing off Leaf.
initialRender(host, draw)adopts prepaint'sdrawing where a coordinator ran, and otherwise calls
drawwith plain toolsand renders it. The plain tools give both of prepaint's role constructors
(
offerAction,offerActionElement) in its shapes, and set only the widget's own classes, button typeand name, not Leaf's marks (
lf-ui, a role's face,data-lf-gen,data-lf-offer), which nothing reads there. Motion's producer moves besideits widget (
widgets/motion-view.js) and imports the portable helpers byserved path; the initial bundle imports it, and
build/initial.mjsresolves/runtime/to sources withsideEffects: false, so the bundle holds only whatthe producer uses. Where
drawsFirst()says a coordinator drew, the moduledefines the element at once and fetches nothing more; elsewhere it imports the
producer and defines the element once it arrives (a module-level
.then), soevery study upgrades with its producer in hand and draws in the task that
upgrades it.
producer it never runs, one more request on upgrade. Also rejected: a
top-level
await import()beforecustomElements.define, which the lintrule
architecture/top-level-awaitrefuses because it turns off thebundler's chunk merging; and defining at once and waiting for the producer in
each instance's connection, a second route through setup.
host that doesn't reserve its room sees what follows it move: deferring the
definition keeps the widget from showing undrawn but can't move its drawing
before the first paint. (The Layout Instability API scores the old and new
shapes alike here: the authored nodes the drawing moves are reinserted, which
it doesn't count, and what follows moves the same either way.)
template is the producer's and calls the producer's tools, so that path needs
the same module and tools, with the branch in each widget instead of in
initialRender, which seven otherx-initialwidgets can share.fewer requests (2 of them script) and 5 KB more, and on lost-update with 3
fewer and 1.5 KB more, against main.
The widget. It extends
HTMLElementand draws its transport with Lit'srenderin the task that changes it, as it already did for every frame, so itclaims no presentation.
onUserInputbecomes window capture listeners for theinputs prepaint counts,
signala private field, andreducedMotionandonMotionPreferenceChangeportable exports.LitElementwith aPendingTaskEventon its first update, whichadds Lit's asynchronous scheduler beside the per-frame
renderand a publicLitElementexport. Also rejected: splittingLeafElementso Leaf attachespresentation from outside, a change to all 30
LeafElementwidgets forstate this one doesn't read.
LeafElementgave it that no longer applies: a region claim per updateand no drawing while detached; motion's setters drew directly before too.
makes, with no
run, so the register runs nothing for it; one click listenerplays when there is something to play; and the transport draws the button
aria-disabledfrom aplayableinput, the availability the register reads.The producer reads the study's videos before the coordinator moves the
authored nodes into the body box, so a video study is available from first
paint.
reportFailure, and theclock's place says "Failed" until the next press or seek, on any page. It
replaces
raiseError, whose notice exists only in Leaf's panel. The wordfits the clock's 9ch box, where "Playback failed" moved the transport.
by the widget (
placesFailure): the default replaced the Lit part, whosetemplate holds the author's study, so a throwing frame deleted the study and a
frame that kept throwing swapped box and transport every frame. One failure
keeps one box and stops the clock, and a frame that draws takes it away. Play
draws the first frame before saying Pause, so a throwing frame doesn't write
Pause and back in one task.
No protocol bump: the public package API doesn't move it (#4551).
Tests.
renderFrame, clicks Play, and sees the clock and the last frame reach theend. The host hides each widget until defined, serves the producer late so
the page paints first, lays its widgets two to a row with the one that draws
at upgrade last, so its growth moves nothing under the shift watch, and holds
the clock to one width as the package's stylesheet does.
test_a_motion_failure_shows_beside_the_study_and_reaches_the_agentandtest_play_is_available_from_first_paint_only_where_there_is_something_to_play.test_timeline_steps_by_every_route_and_keeps_the_stepasserts a key's stepis said in the live region.
reading 'move'inlit.js);notifications.jsnot hearinglf-announce(live regionempty); the "Failed" word removed; the widget's failure placer removed (the
study is deleted); the videos read after the body box takes them (Play drawn
aria-disabledat first paint on a video study).pnpm run test:runtime(695),pnpm run check:browser,pre-commit,
test_motion.py,test_timeline.py,test_key_surfaces.py(its announce test included), a board's keyboard move, a diff's hunk step,
retained moves, the initial-delivery tests, initial settlement, the
pending-task hold, the public API before boot, and a reply's widget module.