Skip to content

Give a page without Leaf the portable widgets' look through one linked stylesheet - #5121

Merged
max-sixty merged 8 commits into
mainfrom
agent-a0ea13f49c8ca160e
Nov 3, 2026
Merged

max-sixty merged 8 commits into
mainfrom
agent-a0ea13f49c8ca160e

Conversation

@max-sixty

@max-sixty max-sixty commented Nov 3, 2026 •

Copy link
Copy Markdown
Owner

Closes #4797

A plain HTML page running lf-chart, lf-code, lf-diagram, lf-motion or lf-timeline through portable-api.js now gets their look by linking the layer's portable.css beside its import map:

<link rel="stylesheet" href="/leaf/portable.css">
<script type="importmap">…</script>

portable.css is served beside /widgets/ and theme.css, at the root the host already maps its module directories to. It isn't under /runtime/, as the decision's sketch showed, because it is composed from the layer's packages, while /runtime/ holds only the serving Leaf's runtime.

What the sheet holds

layer.portable_sheet composes three parts, all in lf-base, the tier a widget module's adopted rules take off Leaf too:

  • the kernel's tokens, now in browser/styles/tokens.css, which base.css imports instead of declaring them;
  • the kernel's whole shared sheet, shadow.css, nested under :where(<the layer's element tags>);
  • the widget-shadow.css and defaults.css of each package that ships widgets.

The host's unlayered CSS outranks all of it. The host restyles the widgets by restating a token such as --accent, sets --lf-ground when it paints its own background, and picks their colours with its color-scheme.

Calls made in review

  • The shared sheet goes in whole, nested under the widget tags. Nesting keeps its page-wide rules (.button, .field, .choice, data-room, a native control's font, the disclosure arrow) to the widgets' insides, so a host's own markup keeps its look. Nothing is hand-sorted into a portable file, so the earlier faces.css split is reverted: controls.css, surfaces.css and shadow.css are main's.
  • :where() nesting rather than @scope. Nesting adds no specificity and keeps each rule's order, so a package's rule still outranks a kernel face of equal weight, as on a Leaf page. Under @scope, scope proximity would rank the kernel face first.
  • Two :root token rules move into tokens.css. A nested rule reaches no :root on a host. The parity test needed exactly two: the symbol's face size with the composer's action inset, from response.css (without it a host drew icon buttons at 18px instead of 28px), and a text scroller's track room, from reading.css (lf-code's block stood 8px short). The shared sheet's other :root rules style parts only Leaf adds and stay where they are. Its seven @property rules and one @keyframes, which can't nest, don't reach a host; they serve threads, messages and scroll marks.
  • A package that ships no widgets stays out. That keeps out the reading theme in every new page's layer, which restyled a host's background, body text, ink and pre.
  • Renaming Leaf's author classes is a separate decision and isn't touched here.

Leaf pages

A Leaf page's composed theme.css and shadow.css hold the same rules as main's. Compared rule by rule, the only changes are the token rules moving to the head of base.css, with no rule between their old and new places declaring the same property on the root, and shadow.css dropping the two :root rules, which never match in a declared shadow tree. leaf-dev stills over the review's 45 states against main finds 42 unchanged. share-link and retained-quote-full differed in the review's run on 89e15f8 too. command-reference-search differed only in its inspection dialog's rows and main's margins, with 0 px changed, and is unchanged on a rerun.

Tests and measurements

  • test_a_host_draws_each_widget_as_a_leaf_page_does puts the five widgets' markup on a Leaf page that takes no theme and on a plain host linking the sheet, with the same inherited text and ground at each root, and compares every face and size of every element below each root, skipping only the parts Leaf adds, such as Copy and quiet words. It passes, and fails on 89e15f8's sheet in 28 element groups of lf-code, lf-motion and lf-timeline.
  • test_a_display_widget_draws_on_a_page_without_leaf reads a host row holding .button, a.button, .choice, .field and data-room beside a plain p, button, summary, pre, select and svg, with the sheet and without it in one task: nothing changes. It fails on 89e15f8's sheet.
  • test_portable_css_carries_the_widgets_look_and_no_theme holds a theme's rules out of the sheet.
  • For the plain-page fixture's layer (default, diagram, motion and timeline), portable.css is 187 KB raw and 34 KB gzipped: 9 KB of tokens, 77 KB of shared sheet, and 99 KB of package sheets, 90 KB of them the default package's. For the examples' layer, with every bundled package, it is 265 KB raw and 45 KB gzipped.
  • pnpm run check (including test:runtime), pre-commit, and the touched model and smoke tests pass.

Tests that read tokens from base.css now read tokens.css.

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

…d stylesheet

A plain HTML page running lf-chart, lf-code, lf-diagram, lf-motion or
lf-timeline through portable-api.js drew them with the browser's defaults:
Times text, black bars, unhighlighted code, an unstyled failure box, and
transport buttons whose 16px icons drew at 0x0. Their rules reach only a
Leaf page, composed into /theme.css with base.css's page shell.

The layer now composes a fourth sheet, portable.css, served beside
theme.css. It holds the kernel's browser/portable.css, then each package's
widget-shadow.css and defaults.css, all in lf-base, so the host's own CSS
outranks every rule and restyles the widgets by restating a token. A host
links it next to its import map.

Each rule keeps one home. The theme's tokens move from base.css into
styles/tokens.css, which base.css imports. The faces of what a widget
builds with the helper surface (icons, the failure box, and the control
faces from controls.css's role faces on) move into
styles/components/faces.css, which shadow.css imports right after
controls.css; the symbol's face size and hit box move there from
response.css. browser/portable.css imports those two files. A Leaf page's
composed theme.css and shadow.css hold the same rules as before: comparing
them rule by rule, only those blocks moved, with no rule between their old
and new places setting the same property on the same element.

Of the host's own markup, portable.css styles only the control classes Leaf
gives authors (.button, .field, .choice, data-room), since they share the
role faces' rules, and the element rules of a theme the host's layer
selects. The plain-page test now links the sheet, drops its motion-clock
width it replaces, and reads each kind of part with the sheet and without
it: every part it draws changes, and the host's p, button, summary, pre,
select and svg do not.

Prose pointing at controls.css for a moved rule now points at faces.css;
the three runtime modules whose comments changed take a kernel rebuild,
which changes only kernel.json's recorded hashes.
A host whose own cascade layers are declared before it links portable.css
places lf-base after them, so only its unlayered rules are sure to win.
leaf-agent
leaf-agent previously approved these changes Nov 3, 2026
@max-sixty
max-sixty marked this pull request as draft November 3, 2026 06:25
… test it against a Leaf page

Review of #5121 found the hand-drawn faces.css boundary both too wide and too
narrow. It restyled a host's own `.button`, `a.button`, `.choice`, `.field`
inputs and `data-room`, names Bulma and Foundation use too. And it missed
faces the widgets wear: a native control's face and the disabled press in
surfaces.css, so the timeline's Previous at step 1 looked pressable and the
motion clock and Speed drew at 11.5px, and reading.css, so lf-code had no
frame, no monospace and black text.

portable.css is now composed by `layer.portable_sheet` from the kernel's tokens,
the kernel's whole shared sheet (shadow.css) nested under `:where(<the layer's
element tags>)`, and the defaults.css and widget-shadow.css of each package that
ships widgets. The nesting keeps page-wide faces to the widgets' insides, adds no
specificity and keeps each rule's order, so a package's rule still outranks a
kernel face of equal weight, as on a Leaf page; `@scope` would rank the scoped
face first. A package with no widgets, such as the reading theme in every new
page's layer, stays out, so the host's background, text and `pre` keep their
look.

This reverts the faces.css split and the prose pointers it moved: controls.css,
surfaces.css, response.css and shadow.css are main's again, and
browser/portable.css is gone. Two pure `:root` token rules move into tokens.css,
since a nested rule reaches no `:root` on a host: the symbol's face size with the
composer's action inset (response.css), and a text scroller's track room
(reading.css). Without them a host drew icon buttons at 18px instead of 28px and
lf-code's block 8px short. A `:root` rule never matches in a declared shadow tree,
so the shadow sheet loses nothing, and no rule between their old and new places
declares those properties on the root.

The plain-page test's main check is now a parity test: the five widgets' markup
on a Leaf page that takes no theme and on a plain host linking the sheet, with the
same inherited text and ground at each root, compare every face and size below
each root, skipping only the parts Leaf adds. It fails on 89e15f8's sheet in 28
element groups of lf-code, lf-motion and lf-timeline. The host check now reads a
host row holding `.button`, `a.button`, `.choice`, `.field` and `data-room` beside
plain elements, and fails on that sheet too. A model test holds the theme out of
portable.css.
@max-sixty
max-sixty marked this pull request as ready for review November 3, 2026 07:21
leaf-agent
leaf-agent previously approved these changes Nov 3, 2026
browser/base.css conflicted: main edited the token block this branch moves into
styles/tokens.css, dropping --lf-z-escaped-control and the --raise-2 note about a
focused chip at the window's head, and renamed .lf-margin-entry's face rules to
.lf-margin-face. tokens.css takes main's token block with both edits; base.css is
main's with the block removed as before, keeping the face rename. dist/kernel is
main's and rebuilds to the same bytes.

Note in portable_sheet that the shared sheet's @Property and @Keyframes rules
can't nest and never reach a host.
@max-sixty
max-sixty merged commit 8027266 into main Nov 3, 2026
4 checks passed
@max-sixty
max-sixty deleted the agent-a0ea13f49c8ca160e branch November 3, 2026 07:54
max-sixty added a commit that referenced this pull request Nov 3, 2026
…enderer rules inside the diff (#5243)

Two changes to how a package's rules meet the page: every rule that
styles a widget by its tag now names one of the theme's fonts, and the
diff's rules for its renderer's rows stop reaching the page's own
elements.

### Widget faces name the theme's fonts

The font check (`tests/model/test_interface_fonts.py`) read a rule as
Leaf's interface only when it named an `lf-` class, so the 26 rules that
style a widget by its tag set their own faces unchecked, and those had
drifted as the classes' had before #4774: a board card, a note on a line
of code, a worktree and a review each set the small sans on a 1.5
leading, a playground's controls on 1.35 and its instruction on 1.55, a
diff's notes at the prose rung, and the file editor its source at
0.88rem beside the theme's 0.84375rem code size. The check now reads a
rule that names an `lf-` element too (an attribute such as
`data-lf-state` qualifies an element rather than naming one), and every
such rule names a font.

Two fonts join the set in `styles/tokens.css`:

- `--font-widget` (the small sans on the prose's 1.5 leading) for the
words a widget holds: a card's, a code or diff note's, a review's, a
worktree's, a row of options, a playground's instruction.
- `--font-choice` (the interface font at 500) for a segmented control's
choices, which hold the chosen weight so choosing never widens them: a
dial's depths, a shot's views and tools, and the dial's placeholder,
which measures those labels before the buttons arrive and now can't
drift from them.

What changes on screen, by `leaf-dev stills main` over 25 states:

- A diff's author notes go from 17px to 14px, the size a code note
already took.
- The file editor's source takes the theme's code size, 13.5px where it
was 14.08px, and 13.12px on a phone. `--lf-file-editor-size` goes, and a
page sizes the editor's code with `--code-size`, as it does every other
source.
- A playground's controls stand on the interface leading (1.45, from
1.35) and its instruction on 1.5 (from 1.55), about a pixel a line
either way.
- A board card's title takes a pane title's font, its line 20.3px where
it was 19.6px, and a worktree's disclosure takes the small font, its
lines 16.7px apart where they were 17.3px.

Options' card and rail faces compute as they did, and the unused card
value of `--lf-option-font` goes with the variable. A draft keeps its
holder's size above the entry floor, which the check now allows for a
box the user types in, as `surfaces.css` floors every field. The
references point at `styles/tokens.css`, where the fonts have lived
since #5121.

### The diff's renderer rules stay inside the diff

`layer.py` places each package's widget-shadow.css in the document's
lf-base as well as in every declared shadow tree, with no scope around
it, so each rule names the widgets it styles: by tag or `lf-` class in
the document, by `:host(tag)` in a tree. Six of the diff's rules named
only its renderer's attributes (`[data-separator]`, `[data-no-newline]`,
`[data-line-type] [data-diff-span]`, `[data-line]` in print), so they
reached the page's own elements too. A `leaf-dev probe` of the worktree
example with a `<p data-separator>` added read the paragraph's
background as rgb(246, 248, 250), the code ground, with `pre-wrap`. With
each rule under `:where(:host(lf-diff))` it reads transparent and
`normal`. The `:where()` keeps each rule's specificity, and `leaf-dev
stills` over seven diff and worktree states shows no difference inside
the diff.

`test_a_sheet_both_trees_take_names_the_widgets_it_styles` reads every
bundled package's widget-shadow.css, imports included, and fails a rule
that names no `lf-` element or class and no `:host`. It fails on the six
rules above without this change.

### Checks

- `test_interface_fonts.py`, the new scoping check, `pnpm run check`
(type check and runtime tests).
- Browser tests for the file editor's theme, worktree summaries and
disclosures, options' rails, a diff's author notes, and a playground's
instruction and rail.

> _This was written by Claude Code on behalf of max-sixty_
leaf-agent added a commit that referenced this pull request Nov 4, 2026
…ns and words now live (#5299)

Comments in the theme, runtime, bundled packages and two test docstrings
still sent readers to `base.css` for tokens that #5121 moved into
`browser/styles/tokens.css`. Two comments in
`browser/runtime/version.js` still described the inline comparison that
#5249 replaced with a change card. This PR updates those pointers. It
changes comments only, so nothing behaves differently.

- **Tokens:** every edited pointer names a token that `tokens.css`
declares and `base.css` no longer does: `--font-ui`, `--font-compact`,
`--font-status`, `--font-message`, `--font-heading`, `--font-*`,
`--muted`, `--chip-r`, `--r`, `--mark-size`, `--wide`, `--raise-*`,
`--focus-shadow`, `--lf-rail-room`, `--lf-top-covered` and
`--aim-floor`'s pointer query. I checked each by grepping both files for
its declaration. Pointers to rules still in `base.css` are unchanged,
such as `--lf-top`, `--lf-block-frame` and `--lf-wears-ring`.
- **`version.js`:** the comment above `diffWords` now names the change
card's `diffWordsOf`. The guard in the revision's `activates` now gives
its real reason: `activateRevision` turns a selected comparison off and
restores it, and that comparison's marks can own the rendered subject.

`prek run` passes on the changed files.

The same stale `base.css` pointers also appear in `browser/AGENTS.md`,
the developing-leaf glossary and
`skills/leaf/references/package-themes.md`. Those paths need the
control-plane owner's approval, so they go in a separate PR.

Co-authored-by: leaf-agent <[email protected]>
max-sixty pushed a commit that referenced this pull request Nov 18, 2026
…t cycles (#5301)

Some agent instructions still point to where things used to live. #5121
moved every `:root` theme token from `browser/base.css` into
`browser/styles/tokens.css`, and #5222 moved the import-cycle check from
dependency-cruiser to knip. This PR updates those pointers and changes
no rule.

- **`browser/AGENTS.md`**
- `--lf-line` and `--raise-1` to `--raise-3` now point to
`styles/tokens.css`.
- The Layout/style/widget rule now says the style's tokens are in
`styles/tokens.css`.
- The module-boundaries paragraph now credits knip (`knip.config.js`)
with rejecting import cycles. `.dependency-cruiser.mjs` has had no cycle
rule since #5222.
- **The developing-leaf glossary:** **Focus ring** now places
`--focus-ring` in `styles/tokens.css`.
- **The shipped `skills/leaf/references/package-themes.md`:** the
default palette and the "Where it stands" tokens (`--focus-region-gap`,
etc.) now point to `browser/styles/tokens.css`. An agent writing a theme
would otherwise search `base.css` and find none of them.

I grepped both files to confirm each named token is declared in
`tokens.css` and not in `base.css`. `prek run` passes on the changed
files.

#5299 fixes the same stale pointers in code comments. This PR is
separate because these paths need the control-plane owner's approval.

Co-authored-by: leaf-agent <[email protected]>
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.

Give a plain HTML host the portable widgets' look

2 participants