fix(css): scope the subject compound so theme-dark rules keep matching
This commit is contained in:
+20
-3
@@ -59,9 +59,26 @@ function scopeSelector(selector) {
|
||||
if (mentions(selector, ROOT)) {
|
||||
return selector;
|
||||
}
|
||||
// `*` has to open a compound, and :is() takes that place now.
|
||||
const rest = selector[0]?.type === "universal" ? selector.slice(1) : selector;
|
||||
return [SCOPE, ...rest];
|
||||
// The scope goes on the subject — the last compound — not the first:
|
||||
// `.theme-dark .hue-chip` must keep matching with `.theme-dark` on body,
|
||||
// outside the root.
|
||||
let at = 0;
|
||||
for (let i = 0; i < selector.length; i += 1) {
|
||||
if (selector[i].type === "combinator") {
|
||||
at = i + 1;
|
||||
}
|
||||
}
|
||||
const head = selector.slice(0, at);
|
||||
const subject = selector.slice(at);
|
||||
// `*` and type selectors must open a compound; :is() goes in their place
|
||||
// or right after them.
|
||||
if (subject[0]?.type === "universal") {
|
||||
return [...head, SCOPE, ...subject.slice(1)];
|
||||
}
|
||||
if (subject[0]?.type === "type") {
|
||||
return [...head, subject[0], SCOPE, ...subject.slice(1)];
|
||||
}
|
||||
return [...head, SCOPE, ...subject];
|
||||
}
|
||||
|
||||
/** Rewrites a built stylesheet so its rules only reach the plugin's own DOM. */
|
||||
|
||||
Reference in New Issue
Block a user