Skip to content

Let lf-diagram run on a plain HTML page, and make visual parts portable - #4611

Merged
max-sixty merged 1 commit into
mainfrom
portable-diagram
Oct 28, 2026
Merged

max-sixty merged 1 commit into
mainfrom
portable-diagram

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

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-motion and lf-timeline follow in the next two PRs, which make Leaf's Lit, first drawing and base class load anywhere.

This was written by Claude Code on behalf of max-sixty

`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_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants