single-file-core 1.5.51 → 1.5.53

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.
@@ -37,6 +37,7 @@ const NESTING_SELECTOR_TYPE = "NestingSelector";
37
37
  const PSEUDO_CLASS_SELECTOR_TYPE = "PseudoClassSelector";
38
38
  const DECLARATION_TYPE = "Declaration";
39
39
  const RAW_TYPE = "Raw";
40
+ const VALUE_TYPE = "Value";
40
41
  const PSEUDO_ELEMENT_SELECTOR_TYPE = "PseudoElementSelector";
41
42
  const LAYER_NAME = "layer";
42
43
  const SCOPE_NAME = "scope";
@@ -64,6 +65,7 @@ const BLOCK_CLOSE = "}";
64
65
  const EMPTY_STRING = "";
65
66
  const CSS_IMPORTANCE_NOT_IMPORTANT = 0;
66
67
  const CSS_IMPORTANCE_IMPORTANT = 1;
68
+ const INVALID_CSS_ESCAPE_TEST = /\\(?![0-9a-fA-F]{1,6}\s|[^0-9a-zA-Z])/;
67
69
 
68
70
  export {
69
71
  process
@@ -355,7 +357,6 @@ function updateMatchingSelectors(matchedElements, selector, docContext) {
355
357
 
356
358
  function processNestedRules(ruleData, stylesheets, processingContext, docContext) {
357
359
  expandRawCssRules(ruleData);
358
- removeDuplicateDeclarations(ruleData.block);
359
360
  const newProcessingContext = { ...processingContext, ancestorsSelectors: [...processingContext.ancestorsSelectors, ruleData.prelude] };
360
361
  minifyStylesheetRules(ruleData.block.children, stylesheets, newProcessingContext, docContext);
361
362
  }
@@ -421,14 +422,19 @@ function collectDeclarationItemsForElement(element, docContext) {
421
422
  const declarations = cssRule.block.children;
422
423
  for (let declaration = declarations.head; declaration; declaration = declaration.next) {
423
424
  const { type, value } = declaration.data;
424
- if (type === DECLARATION_TYPE && value && value.type !== RAW_TYPE) {
425
- allDeclarations.push({
426
- declaration,
427
- selector,
428
- effectiveSpecificity: computeEffectiveSpecificity(
429
- docContext.selectorData.get(selector), element, docContext),
430
- isInline: false
431
- });
425
+ if (type === DECLARATION_TYPE && value) {
426
+ const isRawValue = value.type === RAW_TYPE;
427
+ const isVendorValue = value.type === VALUE_TYPE && hasChildNodes(value) && value.children.head.data.name && value.children.head.data.name.startsWith(VENDOR_PREFIX);
428
+ const isInvalidValue = value.type === VALUE_TYPE && hasChildNodes(value) && value.children.head.data.name && INVALID_CSS_ESCAPE_TEST.test(value.children.head.data.name);
429
+ if (!isRawValue && !isVendorValue && !isInvalidValue) {
430
+ allDeclarations.push({
431
+ declaration,
432
+ selector,
433
+ effectiveSpecificity: computeEffectiveSpecificity(
434
+ docContext.selectorData.get(selector), element, docContext),
435
+ isInline: false
436
+ });
437
+ }
432
438
  }
433
439
  }
434
440
  }
@@ -703,32 +709,6 @@ function removeUnmatchedSelectors(ruleData, removedSelectors, removedRules, cssR
703
709
  return false;
704
710
  }
705
711
 
706
- function removeDuplicateDeclarations(block) {
707
- const propertyMap = new Map();
708
- const removedDeclarations = [];
709
- for (let ruleChildNode = block.children.head; ruleChildNode; ruleChildNode = ruleChildNode.next) {
710
- if (ruleChildNode.data.type === DECLARATION_TYPE) {
711
- const property = ruleChildNode.data.property;
712
- const isImportant = ruleChildNode.data.important;
713
- if (propertyMap.has(property)) {
714
- const existing = propertyMap.get(property);
715
- if (existing.isImportant === isImportant) {
716
- removedDeclarations.push(existing.node);
717
- propertyMap.set(property, { node: ruleChildNode, isImportant });
718
- } else if (isImportant && !existing.isImportant) {
719
- removedDeclarations.push(existing.node);
720
- propertyMap.set(property, { node: ruleChildNode, isImportant });
721
- } else {
722
- removedDeclarations.push(ruleChildNode);
723
- }
724
- } else {
725
- propertyMap.set(property, { node: ruleChildNode, isImportant });
726
- }
727
- }
728
- }
729
- removedDeclarations.forEach(declaration => block.children.remove(declaration));
730
- }
731
-
732
712
  function removeLosingDeclarations(winningDeclarations, docContext) {
733
713
  const allDeclarations = new Map();
734
714
  const protectedDeclarations = new Set();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.5.51",
3
+ "version": "1.5.53",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",