|
@@ -82,7 +82,6 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
{ action: "replaceStyleContents" },
|
|
{ action: "replaceStyleContents" },
|
|
|
{ option: "selected", action: "removeUnselectedElements" },
|
|
{ option: "selected", action: "removeUnselectedElements" },
|
|
|
{ option: "removeVideoSrc", action: "insertVideoPosters" },
|
|
{ option: "removeVideoSrc", action: "insertVideoPosters" },
|
|
|
- { option: "removeAlternativeImages", action: "removeAlternativeImages" },
|
|
|
|
|
{ option: "removeFrames", action: "removeFrames" },
|
|
{ option: "removeFrames", action: "removeFrames" },
|
|
|
{ option: "removeImports", action: "removeImports" },
|
|
{ option: "removeImports", action: "removeImports" },
|
|
|
{ option: "removeScripts", action: "removeScripts" },
|
|
{ option: "removeScripts", action: "removeScripts" },
|
|
@@ -115,7 +114,6 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
]
|
|
]
|
|
|
}, {
|
|
}, {
|
|
|
sequential: [
|
|
sequential: [
|
|
|
- { option: "lazyLoadImages", action: "lazyLoadImages" },
|
|
|
|
|
{ option: "removeAlternativeImages", action: "removeAlternativeImages" },
|
|
{ option: "removeAlternativeImages", action: "removeAlternativeImages" },
|
|
|
{ option: "removeAlternativeFonts", action: "removeAlternativeFonts" },
|
|
{ option: "removeAlternativeFonts", action: "removeAlternativeFonts" },
|
|
|
{ option: "compressCSS", action: "compressCSS" }
|
|
{ option: "compressCSS", action: "compressCSS" }
|
|
@@ -282,7 +280,6 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
// ------------
|
|
// ------------
|
|
|
const EMPTY_DATA_URI = "data:base64,";
|
|
const EMPTY_DATA_URI = "data:base64,";
|
|
|
const EMPTY_IMAGE = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
|
|
const EMPTY_IMAGE = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
|
|
|
- const GROUPED_IMG_ATTRIBUTE_NAME = "data-sf-img";
|
|
|
|
|
|
|
|
|
|
class DOMProcessor {
|
|
class DOMProcessor {
|
|
|
constructor(options, batchRequest) {
|
|
constructor(options, batchRequest) {
|
|
@@ -375,10 +372,6 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- lazyLoadImages() {
|
|
|
|
|
- DOM.lazyLoad(this.doc, GROUPED_IMG_ATTRIBUTE_NAME);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
removeDiscardedResources() {
|
|
removeDiscardedResources() {
|
|
|
const objectElements = this.doc.querySelectorAll("applet, meta[http-equiv=refresh], object[data]:not([type=\"image/svg+xml\"]):not([type=\"image/svg-xml\"]):not([type=\"text/html\"]), embed[src]:not([src*=\".svg\"])");
|
|
const objectElements = this.doc.querySelectorAll("applet, meta[http-equiv=refresh], object[data]:not([type=\"image/svg+xml\"]):not([type=\"image/svg-xml\"]):not([type=\"text/html\"]), embed[src]:not([src*=\".svg\"])");
|
|
|
this.stats.set("discarded", "objects", objectElements.length);
|
|
this.stats.set("discarded", "objects", objectElements.length);
|
|
@@ -446,7 +439,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
const imgData = this.options.imageData[Number(imgElement.getAttribute(dataAttributeName))];
|
|
const imgData = this.options.imageData[Number(imgElement.getAttribute(dataAttributeName))];
|
|
|
if (imgData.src) {
|
|
if (imgData.src) {
|
|
|
imgElement.setAttribute("src", imgData.src);
|
|
imgElement.setAttribute("src", imgData.src);
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -533,7 +526,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
|
|
|
|
|
removeAlternativeImages() {
|
|
removeAlternativeImages() {
|
|
|
DOM.removeAlternativeImages(this.doc, this.options);
|
|
DOM.removeAlternativeImages(this.doc, this.options);
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
postRemoveAlternativeFonts() {
|
|
postRemoveAlternativeFonts() {
|
|
|
DOM.minifyFonts(this.doc, true);
|
|
DOM.minifyFonts(this.doc, true);
|
|
@@ -658,11 +651,6 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
if (!this.options.removeVideoSrc) {
|
|
if (!this.options.removeVideoSrc) {
|
|
|
resourcePromises.push(DomProcessorHelper.processAttribute(this.doc, this.doc.querySelectorAll("video[src], video > source[src]"), "src", PREFIX_DATA_URI_VIDEO, this.baseURI, this.batchRequest, this.options));
|
|
resourcePromises.push(DomProcessorHelper.processAttribute(this.doc, this.doc.querySelectorAll("video[src], video > source[src]"), "src", PREFIX_DATA_URI_VIDEO, this.baseURI, this.batchRequest, this.options));
|
|
|
}
|
|
}
|
|
|
- if (this.options.lazyLoadImages) {
|
|
|
|
|
- const imageSelectors = DOM.lazyLoaderImageSelectors();
|
|
|
|
|
- Object.keys(imageSelectors.src).forEach(selector => resourcePromises.push(DomProcessorHelper.processAttribute(this.doc, this.doc.querySelectorAll(selector), imageSelectors.src[selector], PREFIX_DATA_URI_IMAGE, this.baseURI, this.batchRequest, this.options)));
|
|
|
|
|
- Object.keys(imageSelectors.srcset).forEach(selector => resourcePromises.push(DomProcessorHelper.processSrcset(this.doc, this.doc.querySelectorAll(selector), imageSelectors.srcset[selector], PREFIX_DATA_URI_IMAGE, this.baseURI, this.batchRequest)));
|
|
|
|
|
- }
|
|
|
|
|
await resourcePromises;
|
|
await resourcePromises;
|
|
|
if (this.options.removeAlternativeImages) {
|
|
if (this.options.removeAlternativeImages) {
|
|
|
const shortcutIcons = Array.from(this.doc.querySelectorAll("link[href][rel=\"icon\"], link[href][rel=\"shortcut icon\"]"));
|
|
const shortcutIcons = Array.from(this.doc.querySelectorAll("link[href][rel=\"icon\"], link[href][rel=\"shortcut icon\"]"));
|
|
@@ -1315,23 +1303,20 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
const imgData = options.imageData[Number(imgElement.getAttribute(dataAttributeName))];
|
|
const imgData = options.imageData[Number(imgElement.getAttribute(dataAttributeName))];
|
|
|
if (imgData.replaceable) {
|
|
if (imgData.replaceable) {
|
|
|
imgElement.setAttribute("src", `data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="${imgData.size.pxWidth}" height="${imgData.size.pxHeight}"><rect fill-opacity="0"/></svg>`);
|
|
imgElement.setAttribute("src", `data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="${imgData.size.pxWidth}" height="${imgData.size.pxHeight}"><rect fill-opacity="0"/></svg>`);
|
|
|
- if (options.lazyLoadImages) {
|
|
|
|
|
- imgElement.setAttribute(GROUPED_IMG_ATTRIBUTE_NAME, "");
|
|
|
|
|
- }
|
|
|
|
|
- const backgroundStyle = {};
|
|
|
|
|
- const backgroundSize = (imgData.objectFit == "content" || imgData.objectFit == "cover") && imgData.objectFit;
|
|
|
|
|
- if (backgroundSize) {
|
|
|
|
|
- backgroundStyle["background-size"] = imgData.objectFit;
|
|
|
|
|
- }
|
|
|
|
|
- if (imgData.objectPosition) {
|
|
|
|
|
- backgroundStyle["background-position"] = imgData.objectPosition;
|
|
|
|
|
|
|
+ const backgroundStyle = {};
|
|
|
|
|
+ const backgroundSize = (imgData.objectFit == "content" || imgData.objectFit == "cover") && imgData.objectFit;
|
|
|
|
|
+ if (backgroundSize) {
|
|
|
|
|
+ backgroundStyle["background-size"] = imgData.objectFit;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (imgData.objectPosition) {
|
|
|
|
|
+ backgroundStyle["background-position"] = imgData.objectPosition;
|
|
|
|
|
+ }
|
|
|
|
|
+ DomProcessorHelper.setBackgroundImage(imgElement, "var(" + variableName + ")", backgroundStyle);
|
|
|
|
|
+ imgElement.removeAttribute(dataAttributeName);
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
- DomProcessorHelper.setBackgroundImage(imgElement, "var(" + variableName + ")", backgroundStyle);
|
|
|
|
|
- imgElement.removeAttribute(dataAttributeName);
|
|
|
|
|
- return true;
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|