Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugins/css-has-pseudo/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes to CSS Has Pseudo

### Unreleased (patch)

- Fix order of removal of CSSOM rules when a browser supports `:has()` natively

### 7.0.2

_December 13, 2024_
Expand Down
2 changes: 1 addition & 1 deletion plugins/css-has-pseudo/dist/browser-global.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/css-has-pseudo/dist/browser-global.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/css-has-pseudo/dist/browser.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/css-has-pseudo/dist/browser.cjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/css-has-pseudo/dist/browser.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion plugins/css-has-pseudo/dist/browser.mjs.map

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions plugins/css-has-pseudo/src/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,24 +241,26 @@ export default function cssHasPseudo(document, options) {
function walkStyleSheet(styleSheet) {
try {
// walk a css rule to collect observed css rules
[].forEach.call(styleSheet.cssRules || [], function(rule, index) {
for (let i = (styleSheet.cssRules.length - 1); i >= 0; i--) {
let rule = styleSheet.cssRules[i];

if (rule.selectorText) {
rule.selectorText = rule.selectorText.replace(/\.js-has-pseudo\s/g, '');

try {
// decode the selector text in all browsers to:
const hasSelectors = extractEncodedSelectors(rule.selectorText.toString());
if (hasSelectors.length === 0) {
return;
continue;
}

if (!options.mustPolyfill) {
styleSheet.deleteRule(index);
return;
styleSheet.deleteRule(i);
continue;
}

for (let i = 0; i < hasSelectors.length; i++) {
const hasSelector = hasSelectors[i];
for (let j = 0; j < hasSelectors.length; j++) {
const hasSelector = hasSelectors[j];
if (hasSelector) {
observedItems.push({
rule: rule,
Expand All @@ -277,7 +279,7 @@ export default function cssHasPseudo(document, options) {
} else {
walkStyleSheet(rule);
}
});
}
} catch (e) {
if (options.debug) {
// eslint-disable-next-line no-console
Expand Down
Loading