Repository navigation
Let a theme restyle Leaf's chrome by named parts - #4869
Merged
Merged
Conversation
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
leaf-agent
approved these changes
Oct 31, 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.
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 cardpart="card", and the comment box a selection raisespart="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--sansor 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_restylewraps each style rule as@scope (.lf-chrome) { :scope:not(#\#):not(#\#) { … } }. The scope confines it to the chrome, so a selector such asbody: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,@layerand@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 barehtml.dark [part~="panel"]matches nothing, in all three engines. A sheet holding@scopeanywhere 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":chrome.cssrule inside@layerloses to the chrome's unlayered rules.!importantrules such as forced-colour borders, still win.backgroundorborderon a part paints behind or over that drawing. The panel's ground stands beside the panel rather than inside it, so it carries thepanelpart as well, and a box property set on the part reaches the ground too.--accent, and the raise shadows its--shade. A theme sets--focus-ringand--focus-shadowon the part itself.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_partsruns in Chromium, Firefox and WebKit. It covers:@mediatoo;prule and bybody:has(&);&-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.pypins the composed text, the@scoperefusal, and the invalid pieces a condition drops. The composed text covers@keyframes,@layerblocks and statements, and@font-faceinside@media.