single-file-core 1.0.23 → 1.0.24
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/modules/css-matched-rules.js +17 -14
- package/package.json +1 -1
- package/single-file-core.js +0 -4
|
@@ -36,7 +36,9 @@ class MatchedRules {
|
|
|
36
36
|
this.mediaAllInfo = createMediaInfo(MEDIA_ALL);
|
|
37
37
|
const matchedElementsCache = new Map();
|
|
38
38
|
let sheetIndex = 0;
|
|
39
|
-
const
|
|
39
|
+
const workStyleSheet = doc.createElement("style");
|
|
40
|
+
doc.body.appendChild(workStyleSheet);
|
|
41
|
+
const workStyleElement = doc.createElement("span");
|
|
40
42
|
doc.body.appendChild(workStyleElement);
|
|
41
43
|
stylesheets.forEach(stylesheetInfo => {
|
|
42
44
|
if (!stylesheetInfo.scoped) {
|
|
@@ -45,9 +47,9 @@ class MatchedRules {
|
|
|
45
47
|
if (stylesheetInfo.mediaText && stylesheetInfo.mediaText != MEDIA_ALL) {
|
|
46
48
|
const mediaInfo = createMediaInfo(stylesheetInfo.mediaText);
|
|
47
49
|
this.mediaAllInfo.medias.set("style-" + sheetIndex + "-" + stylesheetInfo.mediaText, mediaInfo);
|
|
48
|
-
getMatchedElementsRules(doc, cssRules, mediaInfo, sheetIndex, styles, matchedElementsCache,
|
|
50
|
+
getMatchedElementsRules(doc, cssRules, mediaInfo, sheetIndex, styles, matchedElementsCache, workStyleSheet);
|
|
49
51
|
} else {
|
|
50
|
-
getMatchedElementsRules(doc, cssRules, this.mediaAllInfo, sheetIndex, styles, matchedElementsCache,
|
|
52
|
+
getMatchedElementsRules(doc, cssRules, this.mediaAllInfo, sheetIndex, styles, matchedElementsCache, workStyleSheet);
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
}
|
|
@@ -64,7 +66,8 @@ class MatchedRules {
|
|
|
64
66
|
startTime = Date.now();
|
|
65
67
|
log(" -- STARTED computeCascade");
|
|
66
68
|
}
|
|
67
|
-
computeCascade(this.mediaAllInfo, [], this.mediaAllInfo, workStyleElement);
|
|
69
|
+
computeCascade(this.mediaAllInfo, [], this.mediaAllInfo, workStyleSheet, workStyleElement);
|
|
70
|
+
workStyleSheet.remove();
|
|
68
71
|
workStyleElement.remove();
|
|
69
72
|
if (DEBUG) {
|
|
70
73
|
log(" -- ENDED computeCascade", Date.now() - startTime);
|
|
@@ -222,9 +225,9 @@ function addRule(element, selectorInfo, styles) {
|
|
|
222
225
|
elementInfo.push(selectorInfo);
|
|
223
226
|
}
|
|
224
227
|
|
|
225
|
-
function computeCascade(mediaInfo, parentMediaInfo, mediaAllInfo, workStylesheet) {
|
|
228
|
+
function computeCascade(mediaInfo, parentMediaInfo, mediaAllInfo, workStylesheet, workStyleElement) {
|
|
226
229
|
mediaInfo.elements.forEach((elementInfo/*, element*/) =>
|
|
227
|
-
getDeclarationsInfo(elementInfo, workStylesheet/*, element*/).forEach((declarationsInfo, property) => {
|
|
230
|
+
getDeclarationsInfo(elementInfo, workStylesheet, workStyleElement/*, element*/).forEach((declarationsInfo, property) => {
|
|
228
231
|
if (declarationsInfo.selectorInfo.ruleInfo || mediaInfo == mediaAllInfo) {
|
|
229
232
|
let info;
|
|
230
233
|
if (declarationsInfo.selectorInfo.ruleInfo) {
|
|
@@ -249,10 +252,10 @@ function computeCascade(mediaInfo, parentMediaInfo, mediaAllInfo, workStylesheet
|
|
|
249
252
|
}
|
|
250
253
|
}));
|
|
251
254
|
delete mediaInfo.elements;
|
|
252
|
-
mediaInfo.medias.forEach(childMediaInfo => computeCascade(childMediaInfo, [mediaInfo, ...parentMediaInfo], mediaAllInfo, workStylesheet));
|
|
255
|
+
mediaInfo.medias.forEach(childMediaInfo => computeCascade(childMediaInfo, [mediaInfo, ...parentMediaInfo], mediaAllInfo, workStylesheet, workStyleElement));
|
|
253
256
|
}
|
|
254
257
|
|
|
255
|
-
function getDeclarationsInfo(elementInfo, workStylesheet/*, element*/) {
|
|
258
|
+
function getDeclarationsInfo(elementInfo, workStylesheet, workStyleElement/*, element*/) {
|
|
256
259
|
const declarationsInfo = new Map();
|
|
257
260
|
const processedProperties = new Set();
|
|
258
261
|
elementInfo.forEach(selectorInfo => {
|
|
@@ -262,17 +265,17 @@ function getDeclarationsInfo(elementInfo, workStylesheet/*, element*/) {
|
|
|
262
265
|
} else {
|
|
263
266
|
declarations = selectorInfo.ruleInfo.ruleData.block.children;
|
|
264
267
|
}
|
|
265
|
-
processDeclarations(declarationsInfo, declarations, selectorInfo, processedProperties, workStylesheet);
|
|
268
|
+
processDeclarations(declarationsInfo, declarations, selectorInfo, processedProperties, workStylesheet, workStyleElement);
|
|
266
269
|
});
|
|
267
270
|
return declarationsInfo;
|
|
268
271
|
}
|
|
269
272
|
|
|
270
|
-
function processDeclarations(declarationsInfo, declarations, selectorInfo, processedProperties, workStylesheet) {
|
|
273
|
+
function processDeclarations(declarationsInfo, declarations, selectorInfo, processedProperties, workStylesheet, workStyleElement) {
|
|
271
274
|
for (let declaration = declarations.tail; declaration; declaration = declaration.prev) {
|
|
272
275
|
const declarationData = declaration.data;
|
|
273
276
|
const declarationText = cssTree.generate(declarationData);
|
|
274
277
|
if (declarationData.type == "Declaration" &&
|
|
275
|
-
(declarationText.match(REGEXP_VENDOR_IDENTIFIER) || !processedProperties.has(declarationData.property) || declarationData.important) && !invalidDeclaration(declarationText,
|
|
278
|
+
(declarationText.match(REGEXP_VENDOR_IDENTIFIER) || !processedProperties.has(declarationData.property) || declarationData.important) && !invalidDeclaration(declarationText, workStyleElement)) {
|
|
276
279
|
const declarationInfo = declarationsInfo.get(declarationData);
|
|
277
280
|
if (!declarationInfo || (declarationData.important && !declarationInfo.important)) {
|
|
278
281
|
declarationsInfo.set(declarationData, { selectorInfo, important: declarationData.important });
|
|
@@ -284,10 +287,10 @@ function processDeclarations(declarationsInfo, declarations, selectorInfo, proce
|
|
|
284
287
|
}
|
|
285
288
|
}
|
|
286
289
|
|
|
287
|
-
function invalidDeclaration(declarationText,
|
|
290
|
+
function invalidDeclaration(declarationText, workStyleElement) {
|
|
288
291
|
let invalidDeclaration;
|
|
289
|
-
|
|
290
|
-
if (
|
|
292
|
+
workStyleElement.style = declarationText;
|
|
293
|
+
if (!workStyleElement.style.length) {
|
|
291
294
|
if (!declarationText.match(REGEXP_VENDOR_IDENTIFIER)) {
|
|
292
295
|
invalidDeclaration = true;
|
|
293
296
|
}
|
package/package.json
CHANGED
package/single-file-core.js
CHANGED
|
@@ -1854,10 +1854,6 @@ class ProcessorHelper {
|
|
|
1854
1854
|
if (testValidURL(resourceURL)) {
|
|
1855
1855
|
let { content, indexResource, duplicate } = await batchRequest.addURL(resourceURL,
|
|
1856
1856
|
{ asBinary: true, expectedType, groupDuplicates: options.groupDuplicateImages && resourceElement.tagName == "IMG" && attributeName == "src" });
|
|
1857
|
-
if (resourceURL.includes("openbenchmarking.org/embed.php")) {
|
|
1858
|
-
debugger
|
|
1859
|
-
}
|
|
1860
|
-
|
|
1861
1857
|
if (originURL) {
|
|
1862
1858
|
if (content == util.EMPTY_RESOURCE) {
|
|
1863
1859
|
try {
|