|
@@ -22,8 +22,8 @@
|
|
|
|
|
|
|
|
this.cssMinifier = this.cssMinifier || (() => {
|
|
this.cssMinifier = this.cssMinifier || (() => {
|
|
|
|
|
|
|
|
- const REMOVED_PSEUDO_CLASSES = ["focus", "focus-within", "hover", "link", "visited", "active"];
|
|
|
|
|
- const REMOVED_PSEUDO_ELEMENTS = ["after", "before", "first-line", "first-letter", "placeholder", "-webkit-input-placeholder", "selection", "marker", "cue", "-webkit-progress-bar", "-webkit-progress-value", "-webkit-inner-spin-button", "-webkit-outer-spin-button", "-webkit-search-cancel-button", "-webkit-search-cancel-button"];
|
|
|
|
|
|
|
+ const REMOVED_PSEUDO_CLASSES = [":focus", ":focus-within", ":hover", ":link", ":visited", ":active"];
|
|
|
|
|
+ const REMOVED_PSEUDO_ELEMENTS = ["::after", "::before", "::first-line", "::first-letter", "::placeholder", "::-webkit-input-placeholder", "::selection", "::marker", "::cue", "::-webkit-progress-bar", "::-webkit-progress-value", "::-webkit-inner-spin-button", "::-webkit-outer-spin-button", "::-webkit-search-cancel-button", "::-webkit-search-cancel-button"];
|
|
|
const IGNORED_SELECTORS = ["::-webkit-scrollbar", "::-webkit-scrollbar-button", "::-webkit-scrollbar-thumb", "::-webkit-scrollbar-track", "::-webkit-scrollbar-track-piece", "::-webkit-scrollbar-corner", "::-webkit-resizer"];
|
|
const IGNORED_SELECTORS = ["::-webkit-scrollbar", "::-webkit-scrollbar-button", "::-webkit-scrollbar-thumb", "::-webkit-scrollbar-track", "::-webkit-scrollbar-track-piece", "::-webkit-scrollbar-corner", "::-webkit-resizer"];
|
|
|
|
|
|
|
|
return {
|
|
return {
|
|
@@ -84,10 +84,6 @@ this.cssMinifier = this.cssMinifier || (() => {
|
|
|
stats.discarded -= cssRules.length;
|
|
stats.discarded -= cssRules.length;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function testIgnoredSelector(selectorText) {
|
|
|
|
|
- return IGNORED_SELECTORS.find(selector => selectorText.toLowerCase().includes(selector)) || testFilterSelector(selectorText);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
function processStyle(doc, cssStyle, mediaInfo) {
|
|
function processStyle(doc, cssStyle, mediaInfo) {
|
|
|
const styleInfo = mediaInfo.styles.get(cssStyle);
|
|
const styleInfo = mediaInfo.styles.get(cssStyle);
|
|
|
if (styleInfo) {
|
|
if (styleInfo) {
|
|
@@ -113,8 +109,45 @@ this.cssMinifier = this.cssMinifier || (() => {
|
|
|
return sheetContent;
|
|
return sheetContent;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function testIgnoredSelector(selectorText) {
|
|
|
|
|
+ let indexSelector = 0, found;
|
|
|
|
|
+ selectorText = selectorText.toLowerCase();
|
|
|
|
|
+ while (indexSelector < IGNORED_SELECTORS.length && !found) {
|
|
|
|
|
+ found = selectorText.includes(IGNORED_SELECTORS[indexSelector]);
|
|
|
|
|
+ if (!found) {
|
|
|
|
|
+ indexSelector++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!found) {
|
|
|
|
|
+ indexSelector = 0;
|
|
|
|
|
+ while (indexSelector < IGNORED_SELECTORS.length && !found) {
|
|
|
|
|
+ found = testFilterSelector(selectorText);
|
|
|
|
|
+ if (!found) {
|
|
|
|
|
+ indexSelector++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return found;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function testFilterSelector(selector) {
|
|
function testFilterSelector(selector) {
|
|
|
- return REMOVED_PSEUDO_CLASSES.find(pseudoClass => selector.includes(":" + pseudoClass)) || REMOVED_PSEUDO_ELEMENTS.find(pseudoElement => selector.includes("::" + pseudoElement));
|
|
|
|
|
|
|
+ let indexPseudoClass = 0, found;
|
|
|
|
|
+ while (indexPseudoClass < REMOVED_PSEUDO_CLASSES.length && !found) {
|
|
|
|
|
+ found = selector.includes(REMOVED_PSEUDO_CLASSES[indexPseudoClass]);
|
|
|
|
|
+ if (!found) {
|
|
|
|
|
+ indexPseudoClass++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!found) {
|
|
|
|
|
+ let indexPseudoElement = 0;
|
|
|
|
|
+ while (indexPseudoElement < REMOVED_PSEUDO_ELEMENTS.length && !found) {
|
|
|
|
|
+ found = selector.includes(REMOVED_PSEUDO_ELEMENTS[indexPseudoElement]);
|
|
|
|
|
+ if (!found) {
|
|
|
|
|
+ indexPseudoElement++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return found;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
})();
|
|
})();
|