Bugfix: scoped styles (#178)
This commit is contained in:
parent
7b55d3d43e
commit
87ab4c6927
3 changed files with 13 additions and 5 deletions
5
.changeset/wicked-sloths-hide.md
Normal file
5
.changeset/wicked-sloths-hide.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Bugfix: Scoped CSS with pseudoclasses and direct children selectors
|
|
@ -75,18 +75,18 @@ export function scopeRule(selector: string, className: string) {
|
|||
continue;
|
||||
}
|
||||
|
||||
// don‘t scope body, title, etc.
|
||||
if (NEVER_SCOPED_TAGS.has(value)) {
|
||||
// don’t scope body, title, etc.
|
||||
if (CSS_SEPARATORS.has(value) || NEVER_SCOPED_TAGS.has(value)) {
|
||||
ss = head + value + tail;
|
||||
continue;
|
||||
}
|
||||
|
||||
// scope everything else
|
||||
let newSelector = ss.substring(start, end);
|
||||
let newSelector = value;
|
||||
const pseudoIndex = newSelector.indexOf(':');
|
||||
if (pseudoIndex > 0) {
|
||||
// if there‘s a pseudoclass (:focus)
|
||||
ss = head + newSelector.substring(start, pseudoIndex) + c + newSelector.substr(pseudoIndex) + tail;
|
||||
// if there’s a pseudoclass (:focus or ::before)
|
||||
ss = head + newSelector.substring(0, pseudoIndex) + c + newSelector.substr(pseudoIndex) + tail;
|
||||
} else {
|
||||
ss = head + newSelector + c + tail;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,9 @@ ScopedStyles('Scopes rules correctly', () => {
|
|||
'.class~:global(a)': `.class.${className}~a`,
|
||||
'.class *': `.class.${className} .${className}`,
|
||||
'.class>*': `.class.${className}>.${className}`,
|
||||
'.class button:focus': `.class.${className} button.${className}:focus`,
|
||||
'.class h3::before': `.class.${className} h3.${className}::before`,
|
||||
'button:focus::before': `button.${className}:focus::before`,
|
||||
'.class :global(*)': `.class.${className} *`,
|
||||
'.class :global(.nav:not(.is-active))': `.class.${className} .nav:not(.is-active)`, // preserve nested parens
|
||||
'.class :global(ul li)': `.class.${className} ul li`, // allow doubly-scoped selectors
|
||||
|
|
Loading…
Reference in a new issue