Skip to content

Commit 1b0f2a4

Browse files
committed
fix: more fixes to psuedo element logic
1 parent 5f6e2b6 commit 1b0f2a4

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

src/stringify.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ function printPseudoElements(data: VisualData) {
7474

7575
return `<style>@scope{:scope{\n${Object.keys(pseudoStyles)
7676
.sort()
77-
.map((name) =>
78-
indent(`&${name} {${printProperties(pseudoStyles[name])}}`)
79-
)
77+
.map((name) => indent(`&${name} {${printProperties(pseudoStyles[name])}}`))
8078
.join("\n")}\n}}</style>`;
8179
}
8280

src/stylesheets.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import splitSelectors from "./split-selector";
33
import { SelectorWithStyles } from "./types";
44
import { getDefaultStyles } from "./default-styles";
55
const pseudoElementRegex =
6-
/([(>~|+\s])?\s*::?(before|after|first-letter|first-line|selection|backdrop|placeholder|marker|spelling-error|grammar-error|target(?:-text)?)/gi;
6+
/([(>~|+\s])?\s*::?(before|after|checkmark|details-content|file-selector-button|first-letter|first-line|selection|backdrop|placeholder(?:-shown)|picker-icon|marker|spelling-error|grammar-error|target-text)(?![a-z-])/gi;
77

88
/**
99
* Given a document, reads all style sheets returns extracts all CSSRules
@@ -64,9 +64,13 @@ export function getPseudoElementStyles(
6464
seenPseudos = [name];
6565
}
6666

67-
baseSelector =
68-
baseSelector.slice(0, match.index) + (childCombinator || "");
69-
baseSelector.slice(match.index + match[0].length);
67+
baseSelector = childCombinator
68+
? baseSelector.slice(0, match.index) +
69+
childCombinator +
70+
"*" +
71+
baseSelector.slice(match.index + match[0].length)
72+
: baseSelector.slice(0, match.index) +
73+
baseSelector.slice(match.index + match[0].length);
7074
}
7175

7276
if (seenPseudos && el.matches(baseSelector || "*")) {

0 commit comments

Comments
 (0)