single-file-core 1.5.48 → 1.5.49
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.
- package/core/index.js +1 -4
- package/core/lib/processor-helper-inline.js +24 -0
- package/core/lib/processor-helper.js +15 -2
- package/core/util.js +2 -5
- package/modules/css-media-query-utils.js +63 -0
- package/modules/css-medias-alt-minifier.js +26 -23
- package/modules/css-rules-minifier.js +904 -79
- package/modules/css-scope-prelude-parser.js +119 -0
- package/modules/css-selector-sanitizer.js +106 -0
- package/modules/css-specificity.js +211 -0
- package/modules/html-serializer.js +14 -9
- package/modules/index.js +0 -2
- package/package.json +2 -2
- package/processors/compression/compression.js +182 -20
- package/processors/hooks/content/content-hooks-frames-web.js +2 -4
- package/processors/hooks/content/content-hooks-frames.js +6 -8
- package/vendor/css-font-property-parser.js +87 -67
- package/vendor/css-tree.js +9 -9
- package/modules/css-matched-rules.js +0 -384
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2010-2022 Gildas Lormeau
|
|
3
|
-
* contact : gildas.lormeau <at> gmail.com
|
|
4
|
-
*
|
|
5
|
-
* This file is part of SingleFile.
|
|
6
|
-
*
|
|
7
|
-
* The code in this file is free software: you can redistribute it and/or
|
|
8
|
-
* modify it under the terms of the GNU Affero General Public License
|
|
9
|
-
* (GNU AGPL) as published by the Free Software Foundation, either version 3
|
|
10
|
-
* of the License, or (at your option) any later version.
|
|
11
|
-
*
|
|
12
|
-
* The code in this file is distributed in the hope that it will be useful,
|
|
13
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
|
|
15
|
-
* General Public License for more details.
|
|
16
|
-
*
|
|
17
|
-
* As additional permission under GNU AGPL version 3 section 7, you may
|
|
18
|
-
* distribute UNMODIFIED VERSIONS OF THIS file without the copy of the GNU
|
|
19
|
-
* AGPL normally required by section 4, provided you include this license
|
|
20
|
-
* notice and a URL through which recipients can access the Corresponding
|
|
21
|
-
* Source.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
import * as cssTree from "./../vendor/css-tree.js";
|
|
25
|
-
|
|
26
|
-
const MEDIA_ALL = "all";
|
|
27
|
-
const IGNORED_PSEUDO_ELEMENTS = ["after", "before", "first-letter", "first-line", "placeholder", "selection", "part", "marker"];
|
|
28
|
-
const SINGLE_FILE_HIDDEN_CLASS_NAME = "sf-hidden";
|
|
29
|
-
const DISPLAY_STYLE = "display";
|
|
30
|
-
const REGEXP_VENDOR_IDENTIFIER = /-(ms|webkit|moz|o)-/;
|
|
31
|
-
const DEBUG = false;
|
|
32
|
-
|
|
33
|
-
class MatchedRules {
|
|
34
|
-
constructor(doc, stylesheets, styles) {
|
|
35
|
-
this.doc = doc;
|
|
36
|
-
this.mediaAllInfo = createMediaInfo(MEDIA_ALL);
|
|
37
|
-
const matchedElementsCache = new Map();
|
|
38
|
-
let sheetIndex = 0;
|
|
39
|
-
const workStyleSheet = doc.createElement("style");
|
|
40
|
-
doc.body.appendChild(workStyleSheet);
|
|
41
|
-
const workStyleElement = doc.createElement("span");
|
|
42
|
-
doc.body.appendChild(workStyleElement);
|
|
43
|
-
stylesheets.forEach((stylesheetInfo, key) => {
|
|
44
|
-
if (!stylesheetInfo.scoped && stylesheetInfo.stylesheet && !key.urlNode) {
|
|
45
|
-
const cssRules = stylesheetInfo.stylesheet.children;
|
|
46
|
-
if (cssRules) {
|
|
47
|
-
if (stylesheetInfo.mediaText && stylesheetInfo.mediaText != MEDIA_ALL) {
|
|
48
|
-
const mediaInfo = createMediaInfo(stylesheetInfo.mediaText);
|
|
49
|
-
this.mediaAllInfo.medias.set("style-" + sheetIndex + "-" + stylesheetInfo.mediaText, mediaInfo);
|
|
50
|
-
getMatchedElementsRules(doc, cssRules, stylesheets, mediaInfo, sheetIndex, styles, matchedElementsCache, workStyleSheet);
|
|
51
|
-
} else {
|
|
52
|
-
getMatchedElementsRules(doc, cssRules, stylesheets, this.mediaAllInfo, sheetIndex, styles, matchedElementsCache, workStyleSheet);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
sheetIndex++;
|
|
57
|
-
});
|
|
58
|
-
let startTime;
|
|
59
|
-
if (DEBUG) {
|
|
60
|
-
startTime = Date.now();
|
|
61
|
-
log(" -- STARTED sortRules");
|
|
62
|
-
}
|
|
63
|
-
sortRules(this.mediaAllInfo);
|
|
64
|
-
if (DEBUG) {
|
|
65
|
-
log(" -- ENDED sortRules", Date.now() - startTime);
|
|
66
|
-
startTime = Date.now();
|
|
67
|
-
log(" -- STARTED computeCascade");
|
|
68
|
-
}
|
|
69
|
-
computeCascade(this.mediaAllInfo, [], this.mediaAllInfo, workStyleSheet, workStyleElement);
|
|
70
|
-
workStyleSheet.remove();
|
|
71
|
-
workStyleElement.remove();
|
|
72
|
-
if (DEBUG) {
|
|
73
|
-
log(" -- ENDED computeCascade", Date.now() - startTime);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
getMediaAllInfo() {
|
|
78
|
-
return this.mediaAllInfo;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export {
|
|
83
|
-
getMediaAllInfo
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
function getMediaAllInfo(doc, stylesheets, styles) {
|
|
87
|
-
return new MatchedRules(doc, stylesheets, styles).getMediaAllInfo();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function createMediaInfo(media) {
|
|
91
|
-
const mediaInfo = {
|
|
92
|
-
media: media,
|
|
93
|
-
elements: new Map(),
|
|
94
|
-
medias: new Map(),
|
|
95
|
-
rules: new Map(),
|
|
96
|
-
pseudoRules: new Map()
|
|
97
|
-
};
|
|
98
|
-
if (media == MEDIA_ALL) {
|
|
99
|
-
mediaInfo.matchedStyles = new Map();
|
|
100
|
-
}
|
|
101
|
-
return mediaInfo;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function getMatchedElementsRules(doc, cssRules, stylesheets, mediaInfo, sheetIndex, styles, matchedElementsCache, workStylesheet, indexes = {
|
|
105
|
-
mediaIndex: 0, ruleIndex: 0
|
|
106
|
-
}) {
|
|
107
|
-
let startTime;
|
|
108
|
-
if (DEBUG && cssRules.length > 1) {
|
|
109
|
-
startTime = Date.now();
|
|
110
|
-
log(" -- STARTED getMatchedElementsRules", " index =", sheetIndex, "rules.length =", cssRules.length);
|
|
111
|
-
}
|
|
112
|
-
cssRules.forEach(ruleData => {
|
|
113
|
-
if (ruleData.type == "Atrule" && ruleData.name == "import" && ruleData.prelude && ruleData.prelude.children && ruleData.prelude.children.head.data.importedChildren) {
|
|
114
|
-
getMatchedElementsRules(doc, ruleData.prelude.children.head.data.importedChildren, stylesheets, mediaInfo, sheetIndex, styles, matchedElementsCache, workStylesheet, indexes);
|
|
115
|
-
} else if (ruleData.block && ruleData.block.children && ruleData.prelude && ruleData.prelude.children) {
|
|
116
|
-
if (ruleData.type == "Atrule" && ruleData.name == "media") {
|
|
117
|
-
const mediaText = cssTree.generate(ruleData.prelude);
|
|
118
|
-
const ruleMediaInfo = createMediaInfo(mediaText);
|
|
119
|
-
mediaInfo.medias.set("rule-" + sheetIndex + "-" + indexes.mediaIndex + "-" + mediaText, ruleMediaInfo);
|
|
120
|
-
getMatchedElementsRules(doc, ruleData.block.children, stylesheets, ruleMediaInfo, sheetIndex, styles, matchedElementsCache, workStylesheet);
|
|
121
|
-
indexes.mediaIndex++;
|
|
122
|
-
} else if (ruleData.type == "Rule") {
|
|
123
|
-
const selectors = ruleData.prelude.children.toArray();
|
|
124
|
-
const selectorsText = ruleData.prelude.children.toArray().map(selector => cssTree.generate(selector));
|
|
125
|
-
const ruleInfo = { ruleData, mediaInfo, ruleIndex: indexes.ruleIndex, sheetIndex, matchedSelectors: new Set(), declarations: new Set(), selectors, selectorsText };
|
|
126
|
-
if (!invalidSelector(selectorsText.join(","), workStylesheet) || selectorsText.find(selectorText => selectorText.includes("|"))) {
|
|
127
|
-
for (let selector = ruleData.prelude.children.head, selectorIndex = 0; selector; selector = selector.next, selectorIndex++) {
|
|
128
|
-
const selectorText = selectorsText[selectorIndex];
|
|
129
|
-
const selectorInfo = { selector, selectorText, ruleInfo };
|
|
130
|
-
getMatchedElementsSelector(doc, selectorInfo, styles, matchedElementsCache);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
indexes.ruleIndex++;
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
if (DEBUG && cssRules.length > 1) {
|
|
138
|
-
log(" -- ENDED getMatchedElementsRules", "delay =", Date.now() - startTime);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function invalidSelector(selectorText, workStylesheet) {
|
|
143
|
-
workStylesheet.textContent = selectorText + "{}";
|
|
144
|
-
return workStylesheet.sheet ? !workStylesheet.sheet.cssRules.length : workStylesheet.sheet;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function getMatchedElementsSelector(doc, selectorInfo, styles, matchedElementsCache) {
|
|
148
|
-
const filteredSelectorText = getFilteredSelector(selectorInfo.selector, selectorInfo.selectorText);
|
|
149
|
-
const selectorText = filteredSelectorText != selectorInfo.selectorText ? filteredSelectorText : selectorInfo.selectorText;
|
|
150
|
-
const cachedMatchedElements = matchedElementsCache.get(selectorText);
|
|
151
|
-
let matchedElements = cachedMatchedElements;
|
|
152
|
-
if (!matchedElements) {
|
|
153
|
-
try {
|
|
154
|
-
matchedElements = doc.querySelectorAll(selectorText);
|
|
155
|
-
if (selectorText != "." + SINGLE_FILE_HIDDEN_CLASS_NAME) {
|
|
156
|
-
matchedElements = Array.from(doc.querySelectorAll(selectorText)).filter(matchedElement =>
|
|
157
|
-
!matchedElement.classList.contains(SINGLE_FILE_HIDDEN_CLASS_NAME) &&
|
|
158
|
-
(matchedElement.style.getPropertyValue(DISPLAY_STYLE) != "none" || matchedElement.style.getPropertyPriority("display") != "important")
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
// eslint-disable-next-line no-unused-vars
|
|
162
|
-
} catch (error) {
|
|
163
|
-
// ignored
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
if (matchedElements) {
|
|
167
|
-
if (!cachedMatchedElements) {
|
|
168
|
-
matchedElementsCache.set(selectorText, matchedElements);
|
|
169
|
-
}
|
|
170
|
-
if (matchedElements.length) {
|
|
171
|
-
if (filteredSelectorText == selectorInfo.selectorText) {
|
|
172
|
-
matchedElements.forEach(element => addRule(element, selectorInfo, styles));
|
|
173
|
-
} else {
|
|
174
|
-
let pseudoSelectors = selectorInfo.ruleInfo.mediaInfo.pseudoRules.get(selectorInfo.ruleInfo.ruleData);
|
|
175
|
-
if (!pseudoSelectors) {
|
|
176
|
-
pseudoSelectors = new Set();
|
|
177
|
-
selectorInfo.ruleInfo.mediaInfo.pseudoRules.set(selectorInfo.ruleInfo.ruleData, pseudoSelectors);
|
|
178
|
-
}
|
|
179
|
-
pseudoSelectors.add(selectorInfo.selectorText);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function getFilteredSelector(selector, selectorText) {
|
|
186
|
-
const removedSelectors = [];
|
|
187
|
-
let namespaceFound;
|
|
188
|
-
selector = { data: cssTree.parse(cssTree.generate(selector.data), { context: "selector" }) };
|
|
189
|
-
filterNamespace(selector);
|
|
190
|
-
if (namespaceFound) {
|
|
191
|
-
selectorText = cssTree.generate(selector.data).trim();
|
|
192
|
-
}
|
|
193
|
-
filterPseudoClasses(selector);
|
|
194
|
-
if (removedSelectors.length) {
|
|
195
|
-
removedSelectors.forEach(({ parentSelector, selector }) => {
|
|
196
|
-
if (parentSelector.data.children.size == 0 || !selector.prev || selector.prev.data.type == "Combinator" || selector.prev.data.type == "WhiteSpace") {
|
|
197
|
-
parentSelector.data.children.replace(selector, cssTree.parse("*", { context: "selector" }).children.head);
|
|
198
|
-
} else {
|
|
199
|
-
parentSelector.data.children.remove(selector);
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
selectorText = cssTree.generate(selector.data).trim();
|
|
203
|
-
}
|
|
204
|
-
return selectorText;
|
|
205
|
-
|
|
206
|
-
function filterPseudoClasses(selector, parentSelector) {
|
|
207
|
-
if (selector.data.children) {
|
|
208
|
-
for (let childSelector = selector.data.children.head; childSelector; childSelector = childSelector.next) {
|
|
209
|
-
filterPseudoClasses(childSelector, selector);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
if ((selector.data.type == "PseudoClassSelector") ||
|
|
213
|
-
(selector.data.type == "PseudoElementSelector" && (testVendorPseudo(selector) || IGNORED_PSEUDO_ELEMENTS.includes(selector.data.name)))) {
|
|
214
|
-
removedSelectors.push({ parentSelector, selector });
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
function filterNamespace(selector) {
|
|
219
|
-
if (selector.data.children) {
|
|
220
|
-
for (let childSelector = selector.data.children.head; childSelector; childSelector = childSelector.next) {
|
|
221
|
-
filterNamespace(childSelector);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
if (selector.data.type == "TypeSelector" && selector.data.name.includes("|")) {
|
|
225
|
-
namespaceFound = true;
|
|
226
|
-
selector.data.name = selector.data.name.substring(selector.data.name.lastIndexOf("|") + 1);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
function testVendorPseudo(selector) {
|
|
231
|
-
const name = selector.data.name;
|
|
232
|
-
return name.startsWith("-") || name.startsWith("\\-");
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
function addRule(element, selectorInfo, styles) {
|
|
237
|
-
const mediaInfo = selectorInfo.ruleInfo.mediaInfo;
|
|
238
|
-
const elementStyle = styles.get(element);
|
|
239
|
-
let elementInfo = mediaInfo.elements.get(element);
|
|
240
|
-
if (!elementInfo) {
|
|
241
|
-
elementInfo = [];
|
|
242
|
-
if (elementStyle) {
|
|
243
|
-
elementInfo.push({ styleInfo: { styleData: elementStyle, declarations: new Set() } });
|
|
244
|
-
}
|
|
245
|
-
mediaInfo.elements.set(element, elementInfo);
|
|
246
|
-
}
|
|
247
|
-
const specificity = computeSpecificity(selectorInfo.selector.data);
|
|
248
|
-
specificity.ruleIndex = selectorInfo.ruleInfo.ruleIndex;
|
|
249
|
-
specificity.sheetIndex = selectorInfo.ruleInfo.sheetIndex;
|
|
250
|
-
selectorInfo.specificity = specificity;
|
|
251
|
-
elementInfo.push(selectorInfo);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
function computeCascade(mediaInfo, parentMediaInfo, mediaAllInfo, workStylesheet, workStyleElement) {
|
|
255
|
-
mediaInfo.elements.forEach((elementInfo/*, element*/) =>
|
|
256
|
-
getDeclarationsInfo(elementInfo, workStylesheet, workStyleElement/*, element*/).forEach((declarationsInfo, property) => {
|
|
257
|
-
if (declarationsInfo.selectorInfo.ruleInfo || mediaInfo == mediaAllInfo) {
|
|
258
|
-
let info;
|
|
259
|
-
if (declarationsInfo.selectorInfo.ruleInfo) {
|
|
260
|
-
info = declarationsInfo.selectorInfo.ruleInfo;
|
|
261
|
-
const ruleData = info.ruleData;
|
|
262
|
-
const ascendantMedia = [mediaInfo, ...parentMediaInfo].find(media => media.rules.get(ruleData)) || mediaInfo;
|
|
263
|
-
ascendantMedia.rules.set(ruleData, info);
|
|
264
|
-
if (ruleData) {
|
|
265
|
-
info.matchedSelectors.add(declarationsInfo.selectorInfo.selectorText);
|
|
266
|
-
}
|
|
267
|
-
} else {
|
|
268
|
-
info = declarationsInfo.selectorInfo.styleInfo;
|
|
269
|
-
const styleData = info.styleData;
|
|
270
|
-
const matchedStyleInfo = mediaAllInfo.matchedStyles.get(styleData);
|
|
271
|
-
if (!matchedStyleInfo) {
|
|
272
|
-
mediaAllInfo.matchedStyles.set(styleData, info);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
if (!info.declarations.has(property)) {
|
|
276
|
-
info.declarations.add(property);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}));
|
|
280
|
-
delete mediaInfo.elements;
|
|
281
|
-
mediaInfo.medias.forEach(childMediaInfo => computeCascade(childMediaInfo, [mediaInfo, ...parentMediaInfo], mediaAllInfo, workStylesheet, workStyleElement));
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
function getDeclarationsInfo(elementInfo, workStylesheet, workStyleElement/*, element*/) {
|
|
285
|
-
const declarationsInfo = new Map();
|
|
286
|
-
const processedProperties = new Set();
|
|
287
|
-
elementInfo.forEach(selectorInfo => {
|
|
288
|
-
let declarations;
|
|
289
|
-
if (selectorInfo.styleInfo) {
|
|
290
|
-
declarations = selectorInfo.styleInfo.styleData.children;
|
|
291
|
-
} else {
|
|
292
|
-
declarations = selectorInfo.ruleInfo.ruleData.block.children;
|
|
293
|
-
}
|
|
294
|
-
processDeclarations(declarationsInfo, declarations, selectorInfo, processedProperties, workStylesheet, workStyleElement);
|
|
295
|
-
});
|
|
296
|
-
return declarationsInfo;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
function processDeclarations(declarationsInfo, declarations, selectorInfo, processedProperties, workStylesheet, workStyleElement) {
|
|
300
|
-
for (let declaration = declarations.tail; declaration; declaration = declaration.prev) {
|
|
301
|
-
const declarationData = declaration.data;
|
|
302
|
-
const declarationText = cssTree.generate(declarationData);
|
|
303
|
-
if (declarationData.type == "Declaration" &&
|
|
304
|
-
(declarationText.match(REGEXP_VENDOR_IDENTIFIER) || !processedProperties.has(declarationData.property) || declarationData.important) && !invalidDeclaration(declarationText, workStyleElement)) {
|
|
305
|
-
const declarationInfo = declarationsInfo.get(declarationData);
|
|
306
|
-
if (!declarationInfo || (declarationData.important && !declarationInfo.important)) {
|
|
307
|
-
declarationsInfo.set(declarationData, { selectorInfo, important: declarationData.important });
|
|
308
|
-
if (!declarationText.match(REGEXP_VENDOR_IDENTIFIER)) {
|
|
309
|
-
processedProperties.add(declarationData.property);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
} else if (declarationData.type == "Rule") {
|
|
313
|
-
const declarationInfo = declarationsInfo.get(declarationData);
|
|
314
|
-
if (!declarationInfo) {
|
|
315
|
-
declarationsInfo.set(declarationData, { selectorInfo });
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
function invalidDeclaration(declarationText, workStyleElement) {
|
|
322
|
-
let invalidDeclaration;
|
|
323
|
-
workStyleElement.style = declarationText;
|
|
324
|
-
if (!workStyleElement.style.length) {
|
|
325
|
-
if (!declarationText.match(REGEXP_VENDOR_IDENTIFIER)) {
|
|
326
|
-
invalidDeclaration = true;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
return invalidDeclaration;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
function sortRules(media) {
|
|
333
|
-
media.elements.forEach(elementRules => elementRules.sort((ruleInfo1, ruleInfo2) =>
|
|
334
|
-
ruleInfo1.styleInfo && !ruleInfo2.styleInfo ? -1 :
|
|
335
|
-
!ruleInfo1.styleInfo && ruleInfo2.styleInfo ? 1 :
|
|
336
|
-
compareSpecificity(ruleInfo1.specificity, ruleInfo2.specificity)));
|
|
337
|
-
media.medias.forEach(sortRules);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
function computeSpecificity(selector, specificity = { a: 0, b: 0, c: 0 }) {
|
|
341
|
-
if (selector.type == "IdSelector") {
|
|
342
|
-
specificity.a++;
|
|
343
|
-
}
|
|
344
|
-
if (selector.type == "ClassSelector" || selector.type == "AttributeSelector" || (selector.type == "PseudoClassSelector" && selector.name != "not")) {
|
|
345
|
-
specificity.b++;
|
|
346
|
-
}
|
|
347
|
-
if ((selector.type == "TypeSelector" && selector.name != "*") || selector.type == "PseudoElementSelector") {
|
|
348
|
-
specificity.c++;
|
|
349
|
-
}
|
|
350
|
-
if (selector.children) {
|
|
351
|
-
selector.children.forEach(selector => computeSpecificity(selector, specificity));
|
|
352
|
-
}
|
|
353
|
-
return specificity;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
function compareSpecificity(specificity1, specificity2) {
|
|
357
|
-
if (specificity1.a > specificity2.a) {
|
|
358
|
-
return -1;
|
|
359
|
-
} else if (specificity1.a < specificity2.a) {
|
|
360
|
-
return 1;
|
|
361
|
-
} else if (specificity1.b > specificity2.b) {
|
|
362
|
-
return -1;
|
|
363
|
-
} else if (specificity1.b < specificity2.b) {
|
|
364
|
-
return 1;
|
|
365
|
-
} else if (specificity1.c > specificity2.c) {
|
|
366
|
-
return -1;
|
|
367
|
-
} else if (specificity1.c < specificity2.c) {
|
|
368
|
-
return 1;
|
|
369
|
-
} else if (specificity1.sheetIndex > specificity2.sheetIndex) {
|
|
370
|
-
return -1;
|
|
371
|
-
} else if (specificity1.sheetIndex < specificity2.sheetIndex) {
|
|
372
|
-
return 1;
|
|
373
|
-
} else if (specificity1.ruleIndex > specificity2.ruleIndex) {
|
|
374
|
-
return -1;
|
|
375
|
-
} else if (specificity1.ruleIndex < specificity2.ruleIndex) {
|
|
376
|
-
return 1;
|
|
377
|
-
} else {
|
|
378
|
-
return -1;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
function log(...args) {
|
|
383
|
-
console.log("S-File <css-mat>", ...args); // eslint-disable-line no-console
|
|
384
|
-
}
|