single-file-core 1.5.77 → 1.5.78

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,8 +28,6 @@ import { sanitizeSelector } from "./css-selector-sanitizer.js";
28
28
 
29
29
  const DEBUG = false;
30
30
 
31
- const CANONICAL_PSEUDO_ELEMENT_NAMES = new Set(["after", "before", "first-letter", "first-line", "placeholder", "selection", "part", "marker"]);
32
- const DYNAMIC_STATE_PSEUDO_CLASSES = new Set(["hover", "focus", "active", "focus-within", "focus-visible", "target", "visited", "link", "target-current"]);
33
31
  const CONDITIONAL_AT_RULE_NAMES = new Set(["media", "supports", "container"]);
34
32
  const RULE_TYPE = "Rule";
35
33
  const AT_RULE_TYPE = "Atrule";
@@ -289,17 +287,15 @@ function processSelectors(ruleData, processingContext, docContext) {
289
287
  for (let selector = ruleData.prelude.children.head, selectorIndex = 0; selector; selector = selector.next, selectorIndex++) {
290
288
  const {
291
289
  startsWithCombinator,
292
- hasPseudoElement,
293
- hasDynamicStatePseudoClass,
290
+ hasPseudo,
294
291
  scopeRelative
295
292
  } = analyzeSelector(selector.data);
296
293
  registerSelector(selector, ruleData, scopeRelative, processingContext, docContext);
297
- if (!hasPseudoElement && !hasDynamicStatePseudoClass &&
298
- (!startsWithCombinator || !ancestorsSelectors || !ancestorsSelectors.length)) {
294
+ if (!startsWithCombinator || !ancestorsSelectors || !ancestorsSelectors.length) {
299
295
  const matchedElements = matchElements(selector, ancestorsSelectors, docContext);
300
- if (matchedElements.length) {
296
+ if (matchedElements.length && !hasPseudo) {
301
297
  updateMatchingSelectors(matchedElements, selector, docContext);
302
- } else {
298
+ } else if (!matchedElements.length) {
303
299
  removedSelectors.push(selector);
304
300
  }
305
301
  }
@@ -308,20 +304,16 @@ function processSelectors(ruleData, processingContext, docContext) {
308
304
  }
309
305
 
310
306
  function analyzeSelector(selector) {
311
- let hasPseudoElement = false;
312
- let hasDynamicStatePseudoClass = false;
307
+ let hasPseudo = false;
313
308
  let hasNestingOrScope = false;
314
309
  let startsWithCombinator = false;
315
310
  cssTree.walk(selector, {
316
311
  enter(node) {
317
312
  if (node.type === PSEUDO_ELEMENT_SELECTOR_TYPE) {
318
- hasPseudoElement = true;
313
+ hasPseudo = true;
319
314
  } else if (node.type === PSEUDO_CLASS_SELECTOR_TYPE) {
320
- if (CANONICAL_PSEUDO_ELEMENT_NAMES.has(node.name)) {
321
- hasPseudoElement = true;
322
- } else if (DYNAMIC_STATE_PSEUDO_CLASSES.has(node.name)) {
323
- hasDynamicStatePseudoClass = true;
324
- } else if (node.name === SCOPE_NAME) {
315
+ hasPseudo = true;
316
+ if (node.name === SCOPE_NAME) {
325
317
  hasNestingOrScope = true;
326
318
  }
327
319
  } else if (node.type === NESTING_SELECTOR_TYPE) {
@@ -332,7 +324,7 @@ function analyzeSelector(selector) {
332
324
  const firstChild = selector.children.head.data;
333
325
  startsWithCombinator = firstChild && firstChild.type === COMBINATOR_NAME;
334
326
  const scopeRelative = !startsWithCombinator && !hasNestingOrScope;
335
- return { hasPseudoElement, hasDynamicStatePseudoClass, startsWithCombinator, scopeRelative };
327
+ return { hasPseudo, startsWithCombinator, scopeRelative };
336
328
  }
337
329
 
338
330
  function updateMatchingSelectors(matchedElements, selector, docContext) {
@@ -44,7 +44,39 @@ const UNMATCHABLE_PSEUDO_CLASSES = [
44
44
  "right",
45
45
  "seeking",
46
46
  "stalled",
47
- "volume-locked"
47
+ "volume-locked",
48
+ "after",
49
+ "before",
50
+ "visited",
51
+ "link",
52
+ "any-link",
53
+ "local-link",
54
+ "target",
55
+ "scope",
56
+ "hover",
57
+ "active",
58
+ "focus",
59
+ "focus-within",
60
+ "focus-visible",
61
+ "target-current",
62
+ "enabled",
63
+ "disabled",
64
+ "read-only",
65
+ "read-write",
66
+ "placeholder-shown",
67
+ "autofill",
68
+ "default",
69
+ "checked",
70
+ "indeterminate",
71
+ "blank",
72
+ "valid",
73
+ "invalid",
74
+ "in-range",
75
+ "out-of-range",
76
+ "required",
77
+ "optional",
78
+ "user-valid",
79
+ "user-invalid"
48
80
  ];
49
81
 
50
82
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.5.77",
3
+ "version": "1.5.78",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",