|
|
@@ -18,7 +18,7 @@
|
|
|
* along with SingleFile. If not, see <http://www.gnu.org/licenses/>.
|
|
|
*/
|
|
|
|
|
|
-/* global fontFaceProxy, getComputedStyle, Node */
|
|
|
+/* global fontFaceProxy */
|
|
|
|
|
|
this.docHelper = this.docHelper || (() => {
|
|
|
|
|
|
@@ -67,6 +67,7 @@ this.docHelper = this.docHelper || (() => {
|
|
|
if (win) {
|
|
|
markHiddenCandidates(win, doc.body, markerRemovedContent, markerRemovedCandidate, ignoredTags);
|
|
|
markHiddenElements(win, doc.body, markerRemovedContent);
|
|
|
+ markBackdropBackground(doc, win, markerRemovedCandidate);
|
|
|
}
|
|
|
doc.querySelectorAll(("[" + markerRemovedCandidate + "]")).forEach(element => element.removeAttribute(markerRemovedCandidate));
|
|
|
}
|
|
|
@@ -80,22 +81,35 @@ this.docHelper = this.docHelper || (() => {
|
|
|
}
|
|
|
retrieveInputValues(doc, options);
|
|
|
return {
|
|
|
- canvasData: getCanvasData(doc),
|
|
|
+ canvasData: win && getCanvasData(doc, win),
|
|
|
fontsData: getFontsData(doc),
|
|
|
stylesheetContents: getStylesheetContents(doc),
|
|
|
responsiveImageData: getResponsiveImageData(doc, options),
|
|
|
- imageData: getImageData(doc, options),
|
|
|
+ imageData: win && getImageData(doc, win, options),
|
|
|
postersData: getPostersData(doc)
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+ function markBackdropBackground(doc, win, markerRemovedCandidate) {
|
|
|
+ const threshold = .95;
|
|
|
+ const elements = doc.elementsFromPoint(win.innerWidth / 2, win.innerHeight / 2);
|
|
|
+ if (elements.length > 1) {
|
|
|
+ const element = elements[0];
|
|
|
+ const style = win.getComputedStyle(element);
|
|
|
+ const fullScreen = (element.clientWidth >= win.innerWidth * threshold) && (element.clientWidth >= win.innerWidth * threshold) && (style && style.getPropertyValue("z-index") >= 999);
|
|
|
+ if (fullScreen) {
|
|
|
+ element.setAttribute(markerRemovedCandidate, "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
function markHiddenCandidates(win, element, markerRemovedContent, markerRemovedCandidate, ignoredTags) {
|
|
|
- const elements = Array.from(element.childNodes).filter(node => node.nodeType == Node.ELEMENT_NODE);
|
|
|
+ const elements = Array.from(element.childNodes).filter(node => node.nodeType == win.Node.ELEMENT_NODE);
|
|
|
elements.forEach(element => markHiddenCandidates(win, element, markerRemovedContent, markerRemovedCandidate, ignoredTags));
|
|
|
if (elements.length) {
|
|
|
const hiddenCandidate = !elements.find(element => element.getAttribute(markerRemovedCandidate) !== "");
|
|
|
if (hiddenCandidate) {
|
|
|
- if (hiddenElement(element, ignoredTags) && element instanceof win.HTMLElement) {
|
|
|
+ if (hiddenElement(win, element, ignoredTags) && element instanceof win.HTMLElement) {
|
|
|
element.setAttribute(markerRemovedCandidate, "");
|
|
|
elements.forEach(element => {
|
|
|
if (element instanceof win.HTMLElement) {
|
|
|
@@ -104,30 +118,30 @@ this.docHelper = this.docHelper || (() => {
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
- } else if (hiddenElement(element, ignoredTags)) {
|
|
|
+ } else if (hiddenElement(win, element, ignoredTags)) {
|
|
|
element.setAttribute(markerRemovedCandidate, "");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function markHiddenElements(win, element, markerRemovedContent) {
|
|
|
- const elements = Array.from(element.childNodes).filter(node => node.nodeType == Node.ELEMENT_NODE);
|
|
|
+ const elements = Array.from(element.childNodes).filter(node => node.nodeType == win.Node.ELEMENT_NODE);
|
|
|
elements.forEach(element => markHiddenElements(win, element, markerRemovedContent));
|
|
|
if (element.parentElement.getAttribute(REMOVED_CONTENT_ATTRIBUTE_NAME) != "") {
|
|
|
element.removeAttribute(REMOVED_CONTENT_ATTRIBUTE_NAME);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- function hiddenElement(element, ignoredTags) {
|
|
|
+ function hiddenElement(win, element, ignoredTags) {
|
|
|
const cacheElementsHidden = new Map();
|
|
|
- const hidden = testHiddenElement(element, ignoredTags, cacheElementsHidden);
|
|
|
+ const hidden = testHiddenElement(win, element, ignoredTags, cacheElementsHidden);
|
|
|
if (!hidden) {
|
|
|
let parentElement = element.parentElement;
|
|
|
if (parentElement) {
|
|
|
- let parentElementHidden = testHiddenElement(parentElement, ignoredTags, cacheElementsHidden);
|
|
|
+ let parentElementHidden = testHiddenElement(win, parentElement, ignoredTags, cacheElementsHidden);
|
|
|
while (parentElement && !parentElementHidden) {
|
|
|
parentElement = parentElement.parentElement;
|
|
|
if (parentElement) {
|
|
|
- parentElementHidden = testHiddenElement(parentElement, ignoredTags, cacheElementsHidden);
|
|
|
+ parentElementHidden = testHiddenElement(win, parentElement, ignoredTags, cacheElementsHidden);
|
|
|
}
|
|
|
}
|
|
|
return parentElementHidden;
|
|
|
@@ -136,7 +150,7 @@ this.docHelper = this.docHelper || (() => {
|
|
|
return hidden;
|
|
|
}
|
|
|
|
|
|
- function testHiddenElement(element, ignoredTags, cacheElementsHidden) {
|
|
|
+ function testHiddenElement(win, element, ignoredTags, cacheElementsHidden) {
|
|
|
let hidden = cacheElementsHidden.get(element);
|
|
|
if (hidden === undefined) {
|
|
|
if (!ignoredTags.includes(element.tagName)) {
|
|
|
@@ -145,7 +159,7 @@ this.docHelper = this.docHelper || (() => {
|
|
|
const elementStyle = element.style;
|
|
|
hidden = elementStyle && elementStyle.display == "none";
|
|
|
if (!hidden) {
|
|
|
- const style = getComputedStyle(element);
|
|
|
+ const style = win.getComputedStyle(element);
|
|
|
if (style) {
|
|
|
hidden = style.display == "none";
|
|
|
if (!hidden && (style.opacity == "0" || style.visibility == "hidden")) {
|
|
|
@@ -212,12 +226,12 @@ this.docHelper = this.docHelper || (() => {
|
|
|
return SHEET_ATTRIBUTE_NAME + (sessionId || "");
|
|
|
}
|
|
|
|
|
|
- function getCanvasData(doc) {
|
|
|
+ function getCanvasData(doc, win) {
|
|
|
if (doc) {
|
|
|
const canvasData = [];
|
|
|
doc.querySelectorAll("canvas").forEach(canvasElement => {
|
|
|
try {
|
|
|
- const size = getSize(canvasElement);
|
|
|
+ const size = getSize(win, canvasElement);
|
|
|
canvasData.push({ dataURI: canvasElement.toDataURL("image/png", ""), width: size.width, height: size.height });
|
|
|
} catch (error) {
|
|
|
canvasData.push(null);
|
|
|
@@ -249,12 +263,12 @@ this.docHelper = this.docHelper || (() => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- function getImageData(doc, options) {
|
|
|
+ function getImageData(doc, win, options) {
|
|
|
if (doc) {
|
|
|
const data = [];
|
|
|
doc.querySelectorAll("img[src]:not([srcset])").forEach((imageElement, imageElementIndex) => {
|
|
|
- const computedStyle = getComputedStyle(imageElement);
|
|
|
- let imageData = {}, size = getSize(imageElement);
|
|
|
+ const computedStyle = win.getComputedStyle(imageElement);
|
|
|
+ let imageData = {}, size = getSize(win, imageElement);
|
|
|
if (imageElement.src && size && (!computedStyle.getPropertyValue("background-image") || computedStyle.getPropertyValue("background-image") == "none")) {
|
|
|
imageElement.setAttribute(imagesAttributeName(options.sessionId), imageElementIndex);
|
|
|
imageData = size;
|
|
|
@@ -265,11 +279,11 @@ this.docHelper = this.docHelper || (() => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- function getSize(imageElement) {
|
|
|
+ function getSize(win, imageElement) {
|
|
|
const boxSizing = imageElement.style.getPropertyValue("box-sizing");
|
|
|
const boxSizingImportant = imageElement.style.getPropertyPriority("box-sizing");
|
|
|
imageElement.style.setProperty("box-sizing", "border-box", "important");
|
|
|
- const computedStyle = getComputedStyle(imageElement);
|
|
|
+ const computedStyle = win.getComputedStyle(imageElement);
|
|
|
const paddingLeft = getWidth("padding-left", computedStyle);
|
|
|
const paddingRight = getWidth("padding-right", computedStyle);
|
|
|
const paddingTop = getWidth("padding-top", computedStyle);
|