Skip to content

Let a theme restyle Leaf's chrome by named parts - #4869

Merged
max-sixty merged 12 commits into
mainfrom
chrome-parts
Oct 31, 2026
Merged

max-sixty merged 12 commits into
mainfrom
chrome-parts

Conversation

@max-sixty

@max-sixty max-sixty commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Closes #4030.

A theme could reach Leaf's panel, thread cards and comment box only through the page-wide tokens, so it couldn't change one of them alone, or set anything a token doesn't carry. The chrome guard (styles/chrome-guard.css) rolls back page rules that reach the chrome, which keeps accidental leakage out but also stops a theme that means it. This names the three surfaces and lets a package restyle them on purpose.

Named parts. The floating panel and the ground it stands on carry part="panel", a thread card part="card", and the comment box a selection raises part="composer". A token set on a part, from a theme or from the page's own CSS, changes that surface alone. Each part resolves the interface's fonts (--font-*, base.css) again, so --sans or a type rung set on a part reaches every word there rather than stopping at the root's resolved font.

A package's chrome.css. layer.chrome_restyle wraps each style rule as @scope (.lf-chrome) { :scope:not(#\#):not(#\#) { … } }. The scope confines it to the chrome, so a selector such as body:has(&) can't reach the page, and the two :not(#…) give it two ids' weight, more than any of the chrome's own selectors. The theme wins by weight rather than by order, because a rule placed after Leaf's would still lose to a heavier chrome selector. Wrapping recurses into @media, @supports, @container, @layer and @starting-style, so a conditional rule keeps its condition and every other at-rule stays where it stood, global as anywhere in CSS. What a browser would drop as invalid is dropped. Nested, a selector is relative to the chrome's root, so one keyed on the page around the chrome places & for that root (html.dark & [part~="panel"]); a bare html.dark [part~="panel"] matches nothing, in all three engines. A sheet holding @scope anywhere is refused, since a theme's own scope would escape Leaf's. The composed sheet is appended to the chrome's adopted sheet (revision_delivery.delivery_sheets).

Limits, written into package-themes.md, "Leaf's chrome":

  • A chrome.css rule inside @layer loses to the chrome's unlayered rules.
  • Styles Leaf's script sets on an element, and its few !important rules such as forced-colour borders, still win.
  • Leaf draws each surface's ground, ring, corners and shadow from its tokens, so a background or border on a part paints behind or over that drawing. The panel's ground stands beside the panel rather than inside it, so it carries the panel part as well, and a box property set on the part reaches the ground too.
  • Values other than the fonts that Leaf derives on the root keep the root's reading on a part: the focus ring and link underline follow the root's --accent, and the raise shadows its --shade. A theme sets --focus-ring and --focus-shadow on the part itself.
  • The comment box and threads a widget seats in an outlet of its own (x-thread-surface: lf-diff, lf-visual-review) stand outside the chrome and keep the widget's look.

Tests. test_a_package_restyles_the_chrome_by_its_parts runs in Chromium, Firefox and WebKit. It covers:

  • a theme rule beating the chrome's selectors, inside @media too;
  • escape attempts by a bare p rule and by body:has(&);
  • the page's own tokens on a part;
  • a font set on a part;
  • the card, through an &-keyed rule.

It also holds the parts the chrome carries to the table in package-themes.md. Controls without the weight, without the scope, without the per-part fonts and without the card's part each fail it. test_interact_layer.py pins the composed text, the @scope refusal, and the invalid pieces a condition drops. The composed text covers @keyframes, @layer blocks and statements, and @font-face inside @media.

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

The chrome's rules stand outside every layer to beat the page, so no theme
rule could reshape the panel or a thread card (#4030). Three surfaces now carry
public part names, `panel` (the panel and its ground), `card` and `composer`,
and a package's chrome.css is added to the chrome's sheet after Leaf's rules,
nested under `.lf-chrome` at two ids' weight: its rules win over the chrome's
whatever selectors either writes, and reach nothing outside the chrome. At-rules
a style rule can't hold, such as @Keyframes, stay at the sheet's top.

A page's own rule naming a part sets the tokens there, which the guard leaves
alone, and nothing else; a page restyles further through a package of its own.

Closes #4030
…owing them

The thread card's rules live in the annotation sheet, adopted after the chrome's,
so a package's chrome.css wins there by weight alone.
Review found that nesting the whole chrome.css under one weighted rule let a
selector such as body:has(&) reach the page, hoisted @layer statements out of
order and put a @font-face under @media inside a style rule, which Chromium drops.
Each style rule is now wrapped on its own in @scope (.lf-chrome) at two ids'
weight, inside whatever @media, @supports, @container or @layer held it, and
every other at-rule stays as written. The browser test adds body:has(&), which
the old wrapper let through.

The reference now says that layered chrome.css rules lose to the chrome, that
thread words take --msg-font, which resolves on :root, and that a comment box a
widget seats in its own shadow tree keeps the widget's look.
A second review found that an @scope of the theme's own, at the sheet's top, kept
its own scope root and reached the page, and that one nested in a style rule
matched nothing in Chromium under the wrapper. Composition now refuses a chrome.css
holding @scope at any depth, naming the file. The reference now says a theme's
rule still loses to styles Leaf's script sets and to its few !important
declarations.
# Conflicts:
#	dist/kernel/kernel.json
Main's #4774 set every word of the interface in voices resolved on :root and
under .density-working, which left the reference's advice to set --sans or
--msg-font on a part true of neither: a face set on a part reached no word
there, and --msg-font no longer exists. Each chrome part is now another scope that
resolves the voices, as base.css's rule for derived tokens already asks of any
scope that may restate the ladder, so --sans or a rung set on a part reaches every
word that surface shows. The browser test reads the composer's message voice
after a page sets --sans on it; without the change it stays sans-serif.
Main renamed the interface's voices to fonts (#4804) and added --font-goal.
The per-part rule in base.css now resolves --font-message, --font-name and
--font-goal on the root and each chrome part, and the package-themes
reference and the restyle test name the fonts. The kernel manifest is
rebuilt from main's.
- chrome_restyle drops what a browser drops as invalid inside a condition
  (a stray `;`, a loose declaration), where serializing it raised TypeError.
- The per-part font rules are selector lists rather than :is(), so :root and
  .density-working keep one class's weight and a later lf-base rule on them
  still wins by order.
- The references describe the nesting model: a chrome.css selector is
  relative to the chrome's root, so one keyed on the page places `&`; other
  at-rules are global; root-derived values such as the focus ring keep the
  root's reading; Leaf draws each surface's box from its tokens; widget
  outlets (lf-diff, lf-visual-review) stand outside the chrome. Removed the
  claims that Leaf changes no package rule and that no layered rule reaches
  the chrome, and the `page init --package` example now keeps the page's
  other packages.
- The browser test covers the card part through an `&`-keyed rule and holds
  the parts the chrome carries to the table in package-themes.md.
# Conflicts:
#	dist/kernel/kernel.json
…two reference claims

A browser drops a rule whose selector holds `;`, but nested in the chrome's
root the `;` ends a declaration and the rest comes back as a rule, so
composition drops it as the browser would. packages.md no longer says a
layered rule reaches only the controls' layered faces, and package-themes.md
names the root-derived values a part keeps and that the panel part covers
its ground too.
…s twice

box-motion sets the ground's filter inline, so a theme's filter reaches only
the panel.
# Conflicts:
#	dist/kernel/kernel.json
@max-sixty
max-sixty merged commit 64a1eb1 into main Oct 31, 2026
4 checks passed
@max-sixty
max-sixty deleted the chrome-parts branch October 31, 2026 23:39
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.

Let a page restyle Leaf's chrome on purpose

2 participants