single-file-core 1.0.57 → 1.0.59
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/package.json +1 -1
- package/single-file-core.js +41 -0
- package/single-file.js +10 -7
package/package.json
CHANGED
package/single-file-core.js
CHANGED
|
@@ -1075,6 +1075,7 @@ class Processor {
|
|
|
1075
1075
|
if (options.compressCSS) {
|
|
1076
1076
|
ProcessorHelper.removeSingleLineCssComments(stylesheet);
|
|
1077
1077
|
}
|
|
1078
|
+
ProcessorHelper.replacePseudoClassDefined(stylesheet);
|
|
1078
1079
|
stylesheetInfo.stylesheet = stylesheet;
|
|
1079
1080
|
} else {
|
|
1080
1081
|
stylesheets.delete(element);
|
|
@@ -1534,6 +1535,40 @@ class ProcessorHelper {
|
|
|
1534
1535
|
}
|
|
1535
1536
|
}
|
|
1536
1537
|
|
|
1538
|
+
static replacePseudoClassDefined(stylesheet) {
|
|
1539
|
+
const removedSelectors = [];
|
|
1540
|
+
if (stylesheet.children) {
|
|
1541
|
+
for (let cssRule = stylesheet.children.head; cssRule; cssRule = cssRule.next) {
|
|
1542
|
+
const ruleData = cssRule.data;
|
|
1543
|
+
if (ruleData.type == "Rule" && ruleData.prelude && ruleData.prelude.children) {
|
|
1544
|
+
for (let selector = ruleData.prelude.children.head; selector; selector = selector.next) {
|
|
1545
|
+
replacePseudoDefinedSelector(selector, ruleData.prelude);
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
}
|
|
1550
|
+
if (removedSelectors.length) {
|
|
1551
|
+
removedSelectors.forEach(({ parentSelector, selector }) => {
|
|
1552
|
+
if (parentSelector.data.children.size == 0 || !selector.prev || selector.prev.data.type == "Combinator" || selector.prev.data.type == "WhiteSpace") {
|
|
1553
|
+
parentSelector.data.children.replace(selector, cssTree.parse("*", { context: "selector" }).children.head);
|
|
1554
|
+
} else {
|
|
1555
|
+
parentSelector.data.children.remove(selector);
|
|
1556
|
+
}
|
|
1557
|
+
});
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
function replacePseudoDefinedSelector(selector, parentSelector) {
|
|
1561
|
+
if (selector.data.children) {
|
|
1562
|
+
for (let childSelector = selector.data.children.head; childSelector; childSelector = childSelector.next) {
|
|
1563
|
+
replacePseudoDefinedSelector(childSelector, selector);
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
if (selector.data.type == "PseudoClassSelector" && selector.data.name == "defined") {
|
|
1567
|
+
removedSelectors.push({ parentSelector, selector });
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1537
1572
|
static async resolveImportURLs(stylesheet, baseURI, options, workStylesheet, importedStyleSheets = new Set()) {
|
|
1538
1573
|
let importFound;
|
|
1539
1574
|
ProcessorHelper.resolveStylesheetURLs(stylesheet, baseURI, workStylesheet);
|
|
@@ -1560,6 +1595,9 @@ class ProcessorHelper {
|
|
|
1560
1595
|
if (mediaQueryListNode) {
|
|
1561
1596
|
content.data = wrapMediaQuery(content.data, cssTree.generate(mediaQueryListNode));
|
|
1562
1597
|
}
|
|
1598
|
+
|
|
1599
|
+
content.data = content.data.replace(/:defined/gi, "*");
|
|
1600
|
+
|
|
1563
1601
|
const importedStylesheet = cssTree.parse(content.data, { context: "stylesheet", parseCustomProperty: true });
|
|
1564
1602
|
const ancestorStyleSheets = new Set(importedStyleSheets);
|
|
1565
1603
|
ancestorStyleSheets.add(resourceURL);
|
|
@@ -1665,6 +1703,9 @@ class ProcessorHelper {
|
|
|
1665
1703
|
if (content.data && content.data.match(/^<!doctype /i)) {
|
|
1666
1704
|
content.data = "";
|
|
1667
1705
|
}
|
|
1706
|
+
|
|
1707
|
+
content.data = content.data.replace(/:defined/gi, "*");
|
|
1708
|
+
|
|
1668
1709
|
let stylesheet = cssTree.parse(content.data, { context: "stylesheet", parseCustomProperty: true });
|
|
1669
1710
|
const importFound = await ProcessorHelper.resolveImportURLs(stylesheet, resourceURL, options, workStylesheet);
|
|
1670
1711
|
if (importFound) {
|
package/single-file.js
CHANGED
|
@@ -55,10 +55,17 @@ async function getPageData(options = {}, initOptions, doc = globalThis.document,
|
|
|
55
55
|
helper.initDoc(doc);
|
|
56
56
|
const preInitializationPromises = [];
|
|
57
57
|
if (!options.saveRawPage) {
|
|
58
|
+
let lazyLoadPromise;
|
|
59
|
+
if (options.loadDeferredImages) {
|
|
60
|
+
lazyLoadPromise = processors.lazy.process(options);
|
|
61
|
+
if (options.loadDeferredImagesBeforeFrames) {
|
|
62
|
+
await lazyLoadPromise;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
58
65
|
if (!options.removeFrames && frames && globalThis.frames) {
|
|
59
66
|
let frameTreePromise;
|
|
60
67
|
if (options.loadDeferredImages) {
|
|
61
|
-
frameTreePromise = new Promise(resolve => globalThis.setTimeout(() => resolve(frames.getAsync(options)), options.loadDeferredImagesBeforeFrames ? 0 : options.loadDeferredImagesMaxIdleTime
|
|
68
|
+
frameTreePromise = new Promise(resolve => globalThis.setTimeout(() => resolve(frames.getAsync(options)), options.loadDeferredImagesBeforeFrames ? 0 : options.loadDeferredImagesMaxIdleTime));
|
|
62
69
|
} else {
|
|
63
70
|
frameTreePromise = frames.getAsync(options);
|
|
64
71
|
}
|
|
@@ -68,12 +75,8 @@ async function getPageData(options = {}, initOptions, doc = globalThis.document,
|
|
|
68
75
|
preInitializationPromises.push(frameTreePromise);
|
|
69
76
|
}
|
|
70
77
|
}
|
|
71
|
-
if (options.loadDeferredImages) {
|
|
72
|
-
|
|
73
|
-
await processors.lazy.process(options);
|
|
74
|
-
} else {
|
|
75
|
-
preInitializationPromises.push(processors.lazy.process(options));
|
|
76
|
-
}
|
|
78
|
+
if (options.loadDeferredImages && !options.loadDeferredImagesBeforeFrames) {
|
|
79
|
+
preInitializationPromises.push(lazyLoadPromise);
|
|
77
80
|
}
|
|
78
81
|
}
|
|
79
82
|
if (!options.loadDeferredImagesBeforeFrames) {
|