|
|
@@ -25,7 +25,6 @@ this.docHelper = this.docHelper || (() => {
|
|
|
const REMOVED_CONTENT_ATTRIBUTE_NAME = "data-single-file-removed-content";
|
|
|
const PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME = "data-single-file-preserved-space-element";
|
|
|
const WIN_ID_ATTRIBUTE_NAME = "data-frame-tree-win-id";
|
|
|
- const RESPONSIVE_IMAGE_ATTRIBUTE_NAME = "data-single-file-responsive-image";
|
|
|
const IMAGE_ATTRIBUTE_NAME = "data-single-file-image";
|
|
|
const INPUT_VALUE_ATTRIBUTE_NAME = "data-single-file-value";
|
|
|
const SHEET_ATTRIBUTE_NAME = "data-single-file-sheet";
|
|
|
@@ -47,7 +46,6 @@ this.docHelper = this.docHelper || (() => {
|
|
|
windowIdAttributeName,
|
|
|
preservedSpaceAttributeName,
|
|
|
removedContentAttributeName,
|
|
|
- responsiveImagesAttributeName,
|
|
|
imagesAttributeName,
|
|
|
inputValueAttributeName,
|
|
|
sheetAttributeName
|
|
|
@@ -102,7 +100,6 @@ this.docHelper = this.docHelper || (() => {
|
|
|
canvasData,
|
|
|
fontsData: getFontsData(doc),
|
|
|
stylesheetContents: getStylesheetContents(doc),
|
|
|
- responsiveImageData: getResponsiveImageData(doc, options),
|
|
|
imageData,
|
|
|
postersData: getPostersData(doc),
|
|
|
usedFonts
|
|
|
@@ -211,15 +208,10 @@ this.docHelper = this.docHelper || (() => {
|
|
|
if (options.compressHTML) {
|
|
|
doc.querySelectorAll("[" + preservedSpaceAttributeName(options.sessionId) + "]").forEach(element => element.removeAttribute(preservedSpaceAttributeName(options.sessionId)));
|
|
|
}
|
|
|
- doc.querySelectorAll("[" + responsiveImagesAttributeName(options.sessionId) + "]").forEach(element => element.removeAttribute(responsiveImagesAttributeName(options.sessionId)));
|
|
|
doc.querySelectorAll("[" + imagesAttributeName(options.sessionId) + "]").forEach(element => element.removeAttribute(imagesAttributeName(options.sessionId)));
|
|
|
doc.querySelectorAll("[" + inputValueAttributeName(options.sessionId) + "]").forEach(element => element.removeAttribute(inputValueAttributeName(options.sessionId)));
|
|
|
}
|
|
|
|
|
|
- function responsiveImagesAttributeName(sessionId) {
|
|
|
- return RESPONSIVE_IMAGE_ATTRIBUTE_NAME + (sessionId ? "-" + sessionId : "");
|
|
|
- }
|
|
|
-
|
|
|
function imagesAttributeName(sessionId) {
|
|
|
return IMAGE_ATTRIBUTE_NAME + (sessionId || "");
|
|
|
}
|
|
|
@@ -287,12 +279,12 @@ this.docHelper = this.docHelper || (() => {
|
|
|
doc.querySelectorAll("img").forEach((imageElement, imageElementIndex) => {
|
|
|
imageElement.setAttribute(imagesAttributeName(options.sessionId), imageElementIndex);
|
|
|
const imageData = {
|
|
|
- src: imageElement.currentSrc || imageElement.src
|
|
|
+ currentSrc: (options.lazyLoadImages && imageElement.dataset.lazySrc) || imageElement.currentSrc
|
|
|
};
|
|
|
+ delete imageElement.dataset.lazySrc;
|
|
|
const computedStyle = win.getComputedStyle(imageElement);
|
|
|
if (computedStyle) {
|
|
|
imageData.size = getSize(win, imageElement);
|
|
|
- imageData.empty = imageElement.naturalWidth <= 1 && imageElement.naturalHeight <= 1;
|
|
|
if ((!computedStyle.getPropertyValue("background-image") || computedStyle.getPropertyValue("background-image") == "none") && imageData.size.pxWidth > 1 && imageData.size.pxHeight > 1) {
|
|
|
imageData.replaceable = true;
|
|
|
imageData.backgroundColor = computedStyle.getPropertyValue("background-color");
|
|
|
@@ -335,44 +327,6 @@ this.docHelper = this.docHelper || (() => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- function getResponsiveImageData(doc, options) {
|
|
|
- if (doc) {
|
|
|
- const data = [];
|
|
|
- doc.querySelectorAll("picture, img[srcset]").forEach((element, elementIndex) => {
|
|
|
- const tagName = element.tagName.toLowerCase();
|
|
|
- let imageData = {}, imageElement;
|
|
|
- element.setAttribute(responsiveImagesAttributeName(options.sessionId), elementIndex);
|
|
|
- if (tagName == "picture") {
|
|
|
- const sources = Array.from(element.querySelectorAll("source")).map(sourceElement => (
|
|
|
- { src: sourceElement.src, srcset: sourceElement.srcset }
|
|
|
- ));
|
|
|
- imageElement = element.querySelector("img");
|
|
|
- imageData.sources = sources;
|
|
|
- }
|
|
|
- if (tagName == "img") {
|
|
|
- imageElement = element;
|
|
|
- }
|
|
|
- if (imageElement) {
|
|
|
- let naturalWidth = imageElement.naturalWidth, naturalHeight = imageElement.naturalHeight;
|
|
|
- if (naturalWidth <= 1 && naturalHeight <= 1) {
|
|
|
- const imgElement = doc.createElement("img");
|
|
|
- imgElement.src = imageElement.src;
|
|
|
- doc.body.appendChild(imgElement);
|
|
|
- naturalWidth = imgElement.width;
|
|
|
- naturalHeight = imgElement.height;
|
|
|
- imgElement.remove();
|
|
|
- }
|
|
|
- if (naturalWidth > 1 && naturalHeight > 1) {
|
|
|
- imageData.src = (!imageElement.currentSrc.startsWith("data:") && imageElement.currentSrc) || (!imageElement.src.startsWith("data:") && imageElement.src);
|
|
|
- imageData.srcset = imageElement.srcset;
|
|
|
- }
|
|
|
- }
|
|
|
- data.push(imageData);
|
|
|
- });
|
|
|
- return data;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
function getPostersData(doc) {
|
|
|
if (doc) {
|
|
|
const postersData = [];
|