Repository navigation
Let lf-diagram run on a plain HTML page, and make visual parts portable - #4611
Merged
Merged
Conversation
`lf-diagram` now loads and draws on a plain HTML page that maps `/runtime/` and `/vendor/` with its own import map, as `lf-chart` and `lf-code` do. On a Leaf page it behaves as before. Its import graph is 14 runtime modules and 76 KB of source, down from 183 and 2,252 KB (static imports through `/runtime/` and relative paths; Pele stays a lazy `/vendor/` import). **Visual parts are a declaration Leaf reads.** `registerVisualParts` records an inventory in a WeakMap keyed by the element, and Leaf reads it only when a Comment, an aim or the render gate asks, so the call already is a declaration; it was off the portable surface only because `visual-parts.js` imported `under` and `upFrom` through `shadow.js`, whose `registry.js` import doesn't load off Leaf. It now imports them from `shadow-tree.js`, which has no dependencies, and `portable-api.js` re-exports `registerVisualParts`; `widget-api.js` drops its own export line and keeps the name through `export *`. Off Leaf the inventory is recorded and nobody reads it, so a diagram there offers no Comment target. The Leaf readers stay in the module and now ship in the kernel's portable chunk. - Rejected: an `lfVisualParts` property on the element, as keys are `lfCommands`. Keys need a signal because Leaf binds them on arrival; parts are read on demand, so the WeakMap needs none, and the property would have moved six widgets, three test fixtures and the docs to a second spelling of the same declaration for no change in behaviour. **Drawing.** `lf-diagram` announces its drawing with `PendingTaskEvent` instead of `widgetController(this).present`; the document listener in `widget-controller.js` holds the same presentation on it. **Fonts off Leaf.** The drawing reads `--sans` and `--mono`, which a plain page doesn't set, so Pele measures with no family and draws in `var(--pele-font, sans-serif)`: the browser's sans-serif unless the host sets those properties. Left as is: reading the inherited `font-family` instead would add an off-Leaf branch for a page that can already name its fonts. No protocol bump: the public package API doesn't move the protocol (#4551), and every name `widget-api.js` exported is still exported. **Tests.** - `tests/smoke/test_plain_page.py` adds lf-diagram, drawing an svg holding its two named boxes inside the room the host reserves. `Portable.fills_height` becomes `sized` (`box`, `width` or `natural`), since a diagram keeps its natural size rather than filling the host's width as a chart and a code block do. The host reserves the diagram's height, as Leaf's stylesheet does from `data-height`; without it the drawing's arrival shifted the refused chart below by 98px and the shift watch failed the test. - Each failed when undone, at load, on prepaint's `lfInputs` read in `bundle-dom-move.js`: lf-diagram importing `widget-api.js` again, and `visual-parts.js` importing `shadow.js` again. - Also run: `pnpm run test:runtime` (694), `pnpm run check:browser`, and 24 focused browser tests: every diagram test (renderer loading, render gate identities, late labels, scrollbar clearance, scheme, fonts, injection, room, failed-soft room, rounded part aims, pane aims, revision restoration), the visual-part fixtures (picture target, shadow visual clipping, shadow scroller aim) and the pending-task test. `lf-timeline` and `lf-motion` stay on `widget-api.js`. Both draw with Lit, and Leaf's `/vendor/lit.js` doesn't load off Leaf: it imports `dom-move.js`, which imports `focus.js` and so `control-selectors.js`, reading prepaint's `lfInputs`, and its insertion seam and namespace assignment both dereference `document.documentElement.lfInitial`. They also adopt a drawing prepaint made (`x-initial`, `initialRender`) and extend `LeafElement`, whose lifecycle calls into Leaf's presentation. Making them portable needs those three core changes first. > _This was written by Claude Code on behalf of max-sixty_
leaf-agent
approved these changes
Oct 28, 2026
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-diagramnow loads and draws on a plain HTML page that maps/runtime/and
/vendor/with its own import map, aslf-chartandlf-codedo. On aLeaf page it behaves as before. Its import graph is 14 runtime modules and
76 KB of source, down from 183 and 2,252 KB (static imports through
/runtime/and relative paths; Pele stays a lazy/vendor/import).Visual parts are a declaration Leaf reads.
registerVisualPartsrecordsan inventory in a WeakMap keyed by the element, and Leaf reads it only when a
Comment, an aim or the render gate asks, so the call already is a
declaration; it was off the portable surface only because
visual-parts.jsimported
underandupFromthroughshadow.js, whoseregistry.jsimportdoesn't load off Leaf. It now imports them from
shadow-tree.js, which has nodependencies, and
portable-api.jsre-exportsregisterVisualParts;widget-api.jsdrops its own export line and keeps the name throughexport *. Off Leaf the inventory is recorded and nobody reads it, so adiagram there offers no Comment target. The Leaf readers stay in the module
and now ship in the kernel's portable chunk.
lfVisualPartsproperty on the element, as keys arelfCommands. Keys need a signal because Leaf binds them on arrival; partsare read on demand, so the WeakMap needs none, and the property would have
moved six widgets, three test fixtures and the docs to a second spelling of
the same declaration for no change in behaviour.
Drawing.
lf-diagramannounces its drawing withPendingTaskEventinstead of
widgetController(this).present; the document listener inwidget-controller.jsholds the same presentation on it.Fonts off Leaf. The drawing reads
--sansand--mono, which a plainpage doesn't set, so Pele measures with no family and draws in
var(--pele-font, sans-serif): the browser's sans-serif unless the host setsthose properties. Left as is: reading the inherited
font-familyinsteadwould add an off-Leaf branch for a page that can already name its fonts.
No protocol bump: the public package API doesn't move the protocol (#4551),
and every name
widget-api.jsexported is still exported.Tests.
tests/smoke/test_plain_page.pyadds lf-diagram, drawing an svg holding itstwo named boxes inside the room the host reserves.
Portable.fills_heightbecomes
sized(box,widthornatural), since a diagram keeps itsnatural size rather than filling the host's width as a chart and a code
block do. The host reserves the diagram's height, as Leaf's stylesheet does
from
data-height; without it the drawing's arrival shifted the refusedchart below by 98px and the shift watch failed the test.
lfInputsread inbundle-dom-move.js: lf-diagram importingwidget-api.jsagain, andvisual-parts.jsimportingshadow.jsagain.pnpm run test:runtime(694),pnpm run check:browser, and 24focused browser tests: every diagram test (renderer loading, render gate
identities, late labels, scrollbar clearance, scheme, fonts, injection,
room, failed-soft room, rounded part aims, pane aims, revision restoration),
the visual-part fixtures (picture target, shadow visual clipping, shadow
scroller aim) and the pending-task test.
lf-motionandlf-timelinefollow in the next two PRs, which make Leaf's Lit, first drawing and base class load anywhere.