single-file-core 1.6.8 → 1.6.9
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.
|
@@ -48,6 +48,7 @@ const IMPORT_NAME = "import";
|
|
|
48
48
|
const FONT_FACE_NAME = "font-face";
|
|
49
49
|
const KEYFRAMES_NAME = "keyframes";
|
|
50
50
|
const COMBINATOR_NAME = "Combinator";
|
|
51
|
+
const TYPE_SELECTOR_TYPE = "TypeSelector";
|
|
51
52
|
const STYLE_ATTRIBUTE_NAME = "style";
|
|
52
53
|
const SELECTOR_LIST_CONTEXT = "selectorList";
|
|
53
54
|
const STYLESHEET_CONTEXT = "stylesheet";
|
|
@@ -59,6 +60,9 @@ const QSA_ERROR_MESSAGE = "Failed to match selector";
|
|
|
59
60
|
const PRELUDE_SEPARATOR = ",";
|
|
60
61
|
const NESTING_SELECTOR = "&";
|
|
61
62
|
const SCOPE_PSEUDO_CLASS = ":scope";
|
|
63
|
+
const NAMESPACE_SEPARATOR = "|";
|
|
64
|
+
const SELECTOR_SUPPORTS_PREFIX = "selector(";
|
|
65
|
+
const SELECTOR_SUPPORTS_SUFFIX = ")";
|
|
62
66
|
const VENDOR_PREFIX = "-";
|
|
63
67
|
const CUSTOM_PROPERTY_PREFIX = "--";
|
|
64
68
|
const LAYER_NAME_SEPARATOR = ".";
|
|
@@ -119,6 +123,7 @@ function process(doc, stylesheets) {
|
|
|
119
123
|
layerOrder: new Map(),
|
|
120
124
|
selectorData: new Map(),
|
|
121
125
|
selectorTexts: new Map(),
|
|
126
|
+
supportedSelectors: new Map(),
|
|
122
127
|
preludeTexts: new Map(),
|
|
123
128
|
rulesCounter: 0,
|
|
124
129
|
scopeIdCounter: 0
|
|
@@ -380,6 +385,9 @@ function minifyAtRule(ruleData, cssRule, stylesheets, processingContext, removed
|
|
|
380
385
|
|
|
381
386
|
function minifyStylesheetRule(ruleData, cssRule, stylesheets, processingContext, removedRules, docContext) {
|
|
382
387
|
ruleData.order = docContext.rulesCounter++;
|
|
388
|
+
if (!isPreludeSupported(ruleData.prelude, docContext)) {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
383
391
|
const removedSelectors = processSelectors(ruleData, processingContext, docContext);
|
|
384
392
|
const wasDiscarded = removeUnmatchedSelectors(ruleData, removedSelectors, removedRules, cssRule, docContext);
|
|
385
393
|
if (!wasDiscarded && hasChildNodes(ruleData.block)) {
|
|
@@ -455,6 +463,45 @@ function analyzeSelector(selector) {
|
|
|
455
463
|
return { hasUnqueryableSelector, hasNestedUnqueryablePseudoClass, startsWithCombinator };
|
|
456
464
|
}
|
|
457
465
|
|
|
466
|
+
function isPreludeSupported(prelude, docContext) {
|
|
467
|
+
if (!globalThis.CSS || !globalThis.CSS.supports) {
|
|
468
|
+
return true;
|
|
469
|
+
}
|
|
470
|
+
for (let selector = prelude.children.head; selector; selector = selector.next) {
|
|
471
|
+
if (!isSelectorSupported(selector.data, docContext)) {
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return true;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
function isSelectorSupported(selector, docContext) {
|
|
479
|
+
const selectorNode = cssTree.clone(selector);
|
|
480
|
+
cssTree.walk(selectorNode, {
|
|
481
|
+
visit: TYPE_SELECTOR_TYPE,
|
|
482
|
+
enter(node) {
|
|
483
|
+
if (typeof node.name === "string" && node.name.includes(NAMESPACE_SEPARATOR)) {
|
|
484
|
+
node.name = node.name.substring(node.name.lastIndexOf(NAMESPACE_SEPARATOR) + 1);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
let selectorText = cssTree.generate(selectorNode);
|
|
489
|
+
const firstChild = selectorNode.children && selectorNode.children.head && selectorNode.children.head.data;
|
|
490
|
+
if (firstChild && firstChild.type === COMBINATOR_NAME) {
|
|
491
|
+
selectorText = SCOPE_PSEUDO_CLASS + selectorText;
|
|
492
|
+
}
|
|
493
|
+
if (!docContext.supportedSelectors.has(selectorText)) {
|
|
494
|
+
let supported;
|
|
495
|
+
try {
|
|
496
|
+
supported = globalThis.CSS.supports(SELECTOR_SUPPORTS_PREFIX + selectorText + SELECTOR_SUPPORTS_SUFFIX);
|
|
497
|
+
} catch {
|
|
498
|
+
supported = true;
|
|
499
|
+
}
|
|
500
|
+
docContext.supportedSelectors.set(selectorText, supported);
|
|
501
|
+
}
|
|
502
|
+
return docContext.supportedSelectors.get(selectorText);
|
|
503
|
+
}
|
|
504
|
+
|
|
458
505
|
function updateMatchingSelectors(matchedElements, selector, docContext) {
|
|
459
506
|
matchedElements.forEach(element => {
|
|
460
507
|
docContext.matchedElements.add(element);
|