Skip to content

Keep page CSS off Leaf's controls unless it names them, and each package's CSS inside its own widgets - #1278

Merged
max-sixty merged 2 commits into
mainfrom
layout-survey
Sep 27, 2026
Merged

max-sixty merged 2 commits into
mainfrom
layout-survey

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 27, 2026 •

Copy link
Copy Markdown
Owner

A page's CSS now reaches Leaf's controls only when it names them, and each package's CSS reaches only its own widgets.

Page CSS. A page's stylesheet is unlayered, above the lf-base layer where Leaf states the face of its controls. That let a page rule such as button { … } restyle every button in the banner and thread panel, and every control a widget builds in the page. At boot, and again after each revision activates, runtime/page-sheets.js narrows each page selector that names no widget and nothing of Leaf's (no custom element, no lf- class or id, no data-lf- attribute). A narrowed selector skips the chrome and every .lf-ui control. Each member of a selector list is judged separately. The rewrite goes through the CSSOM: the browser has already parsed the sheet, and an assignment it cannot parse leaves the rule unchanged.

Naming the widget is the deliberate route. lf-board button restyles the board's controls, as does a page's own element for controls its module builds with offer. Tokens on :root still reach every surface. Inheritance is the one route selectors can't close, so the chrome's root and .lf-ui now state their whole face. The .lf-ui part is a zero-specificity rule, so any declared rule still wins.

Package CSS. Composition (layer.py, widget_confinement) narrows every rule in a package's theme.css and shadow.css to elements that are one of the package's widgets or stand inside one. In the shadow sheet that every declared tree receives, the same rules apply only in trees one of the package's widgets hosts (:host(:is(<tags>))). A rule with no declarations of its own is left as written, because its nested rules extend it; declarations inside a nested condition such as @media count as the rule's own. A widget package's rule whose subject is :root, html or body is refused. A package without widgets is a theme and reaches the page as before.

Confinement exposed rules the default package held for other owners. Those moved to the kernel theme:

  • the pane role, which the playground and visual-review panes use;
  • .lf-chips and .lf-ref, which command-hub's widgets write;
  • .lf-toc-target, which stands before a heading;
  • the contents map's rules on main;
  • the root tab strip's scroll clearance.

Command-hub states its own apparatus voice. The swipe deck used to make its Ask a container; it now measures itself, on six fixed tracks whose piles pick their spans. The interaction gallery's runtime classes are now lf-interaction-*. code-comparison and data-explorer name their own element where their CSS styles controls their module builds.

Exported pages (#12). .lf-quiet moved from runtime/chrome.css, which an export never adopts, into shadow.css. Exported files no longer show "done" or "highlighted" on screen.

Evidence. I measured every element's computed face across all 23 examples on main and on this branch.

  • As authored: faces match, apart from the swipe deck's few pixels and the ideas page's 18px, which comes from the Ask's heading margin now collapsing.
  • Hostile page stylesheet (button, a, div, span … { font-family: cursive; color: red } and a bold italic spaced body): controls and chrome wearing the page's face fell from 2,805 to 171 elements on the corpus, and to zero on most examples. What remains is inheritance by design: lf-diff's shadow tree keeps its host's face, and a few controls deliberately match their prose.
  • Guidance eval: the new page-css-names-leaf-controls case scores 0/3 on main and 3/3 here. The other five cases hold.

Behaviour the tests pin moved:

  • test_a_pages_own_element_rules_leave_the_layers_controls_alone is no longer xfail. It also checks the deliberate route and inherited type.
  • test_a_swipe_deck_reflows_with_its_parent_allocation no longer counts grid tracks. Its layout assertions stand unchanged.
  • The two layer tests that read package CSS verbatim now read the confined rule.

Still open, in TODO.md: chrome.css is unlayered and adopted after the page's sheets, so a page restyling the chrome itself still has to out-weigh its selectors.

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

🤖 Generated with Claude Code

…age's CSS inside its own widgets

A page's stylesheet is unlayered above lf-base, so a page's `button` rule restyled
the banner, the thread panel and every control a widget builds. runtime/page-sheets.js
narrows each page selector that names no widget and nothing of Leaf's to skip the
chrome and every .lf-ui control, member by member, at boot and after each revision
activates. Naming the widget is the deliberate route. The chrome's root and .lf-ui now
state their whole face, so inherited type from the page stops at them.

Composition confines each widget package's theme.css and shadow.css to its own
widgets (layer.py, widget_confinement; styles.confined), and refuses a widget
package's rule on :root, html or body. Rules the default package held for other
owners move to the kernel theme: the pane role, .lf-chips, .lf-ref, .lf-toc-target,
the contents map's posture on main and the root tab strip's scroll clearance.
Command-hub states its own apparatus voice; the swipe deck measures itself instead
of making its Ask a container; the interaction gallery's classes take the lf- prefix.

.lf-quiet moves from chrome.css to shadow.css, so exported pages clip their quiet
words (#12).

Tests: the decision-E xfail passes and pins the deliberate route and inherited type;
new tests cover package confinement, the root refusal and export clipping. The swipe
reflow test no longer counts grid tracks, and the layer tests read the confined rule.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package isolation stops at the document boundary. composed_sheets appends each package's original shadow.css to the shared shadow output, and shadowStage installs that whole output in every x-shadow root. Thus a package rule such as button { … } in shadow.css still styles another package's shadow widget, despite the new package contract saying it reaches only its own widgets; the diff package already contributes unqualified selectors such as [data-line]. The shadow output needs package ownership preserved so each root receives only its owner's rules, alongside the shared kernel and theme rules.

Every declared shadow tree receives the layer's shadow sheet, so a package's
shadow.css reached other packages' trees. Its rules now meet :host(<its tags>) there,
as they meet its tags in the document.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@max-sixty
max-sixty merged commit 8e11f35 into main Sep 27, 2026
5 checks passed
@max-sixty
max-sixty deleted the layout-survey branch September 27, 2026 06:00
max-sixty added a commit that referenced this pull request Sep 27, 2026
…tired column variables (#1273)

A first sidebar that holds only an `lf-toc` stays in the flow between an 848px shell,
where the default package fixes the map into the left margin, and 1296px, where the
core theme floats the sidebar. In that band the empty sidebar kept its
`margin: var(--sp-4) 0 30px`, and as a `flow-root` box it also kept the blocks on either
side of it from collapsing their margins. On `feature-gallery` at 1200px, the render
gate's width, that put 54px between the lede and the paragraph after it where the
floated posture gives 13px. The docs site patched it for itself (#1246) by zeroing the
margins, which still left 23px because the box stayed `flow-root`.

The core theme now handles this beside the posture declaration that #1278 moved there:
under the margin posture, a first sidebar whose only child is the `lf-toc` is
`display: block` with no block margins, so the blocks on either side meet as they do
when the sidebar floats. The rule has to be in the core theme, because package CSS is
now confined to the package's own widgets and could not reach the `aside`. The docs
copy is deleted. From 1296px the core theme's float margins still outrank the new rule,
so the floated sidebar is unchanged.

The surveyor's reading of no gap at 1000px came from the page, not from Leaf: the
feature gallery hides `#bg-sidebar` below a 1152px shell (its own
`@container lf-shell (max-width: 1151px)`, from #237), so there the gap only shows
from 1152 to 1295px. Any other page with this shape has the gap from 848px.

`layouts.css` no longer pins `--lf-shift: 0px` and `--lf-gutter-l`. These were left
over from the column model #1246 retired, and they only fed `--lf-sidebar-free-left`,
which nothing read, and a `+ 0px` term in the default package's outline width. The core
theme's `main` rule that set those two properties and `--lf-sidebar-claim` is gone.
`--lf-sidebar-claim` was an alias for `--sidebar-max` with one reader, the map's width,
which now reads `--sidebar-max` directly.

Behaviour that moved: between 848 and 1296px of shell, on a fine pointer, a page
whose first sidebar holds only the contents map loses the gap under the block before
it (41px on the feature gallery at 1200px). `test_a_left_sidebar_uses_the_margin_until_the_page_needs_it_back`
now checks that band: the block after the sidebar stands where it would with the
sidebar gone. `test_the_reading_map_returns_when_a_hidden_sidebar_comes_back` asserted
the wrapper's display was `flow-root`, which only stood in for "the wrapper came
back". It now asserts that the display is not `none`.

`layouts.css` still selects `lf-pane` by tag. The survey read this as a pane-depth
inconsistency that the role alone would fix. Keying on the role alone breaks two things
the tag carries. An authored pane is held only as the workspace body or a cell of it,
and `test_a_pane_inside_a_plain_section_of_a_workspace_flows` goes red if the depth
limit is dropped. The tag is also the only mark present at first paint: on
`alert-review` the runtime paints `data-lf-reading-role` 450-650ms after first paint.
That needs a first-paint, authored-versus-generated mark, so it is a `TODO.md` entry
under Shared definitions.


> _This was written by Claude Code on behalf of max-sixty_

🤖 Generated with [Claude Code](https://claude.com/claude-code)
max-sixty pushed a commit that referenced this pull request Sep 27, 2026
The nightly chrome class check still expected `.lf-quiet` in the
runtime's document-level stylesheet, although #1278 moved its rule to
the shared shadow sheet so exported pages hide quiet text too. Remove
that stale expectation; the check still verifies that private chrome
selectors do not style authored content.

The failing check reproduces on current `main` and passes with this
change: `uv run pytest -q -n0
tests/test_render_threads.py::test_a_coined_class_cannot_reach_the_chromes_rules`.
The [failed main
run](https://github.com/max-sixty/leaf/actions/runs/36294616353) also
had other nightly failures, which remain tracked in #1283.

Refs #1283

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.

2 participants