|
|
@@ -28,9 +28,9 @@ this.docHelper = this.docHelper || (() => {
|
|
|
preProcessDoc,
|
|
|
postProcessDoc,
|
|
|
serialize,
|
|
|
- WIN_ID_ATTRIBUTE_NAME,
|
|
|
- PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME,
|
|
|
- REMOVED_CONTENT_ATTRIBUTE_NAME
|
|
|
+ windowIdAttributeName,
|
|
|
+ preservedSpaceAttributeName,
|
|
|
+ removedContentAttributeName
|
|
|
};
|
|
|
|
|
|
function preProcessDoc(doc, win, options) {
|
|
|
@@ -46,7 +46,7 @@ this.docHelper = this.docHelper || (() => {
|
|
|
doc.querySelectorAll("html > body *:not(style):not(script):not(link):not(frame):not(iframe):not(object)").forEach(element => {
|
|
|
const style = win.getComputedStyle(element);
|
|
|
if (element instanceof win.HTMLElement && style && (element.hidden || style.display == "none" || ((style.opacity === 0 || style.visibility == "hidden") && !element.clientWidth && !element.clientHeight)) && !element.querySelector("iframe, frame, object[type=\"text/html\"][data]")) {
|
|
|
- element.setAttribute(REMOVED_CONTENT_ATTRIBUTE_NAME, "");
|
|
|
+ element.setAttribute(removedContentAttributeName(), "");
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
@@ -54,7 +54,7 @@ this.docHelper = this.docHelper || (() => {
|
|
|
doc.querySelectorAll("*").forEach(element => {
|
|
|
const style = win.getComputedStyle(element);
|
|
|
if (style && style.whiteSpace.startsWith("pre")) {
|
|
|
- element.setAttribute(PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME, "");
|
|
|
+ element.setAttribute(preservedSpaceAttributeName(), "");
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
@@ -72,12 +72,24 @@ this.docHelper = this.docHelper || (() => {
|
|
|
});
|
|
|
doc.head.querySelectorAll("*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)").forEach(element => element.removeAttribute("hidden"));
|
|
|
if (options.removeHiddenElements) {
|
|
|
- doc.querySelectorAll("[" + REMOVED_CONTENT_ATTRIBUTE_NAME + "]").forEach(element => element.removeAttribute(REMOVED_CONTENT_ATTRIBUTE_NAME));
|
|
|
+ doc.querySelectorAll("[" + removedContentAttributeName() + "]").forEach(element => element.removeAttribute(removedContentAttributeName()));
|
|
|
}
|
|
|
if (options.compressHTML) {
|
|
|
- doc.querySelectorAll("[" + PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME + "]").forEach(element => element.removeAttribute(PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME));
|
|
|
+ doc.querySelectorAll("[" + preservedSpaceAttributeName() + "]").forEach(element => element.removeAttribute(preservedSpaceAttributeName()));
|
|
|
}
|
|
|
- doc.querySelectorAll("[" + WIN_ID_ATTRIBUTE_NAME + "]").forEach(element => element.removeAttribute(WIN_ID_ATTRIBUTE_NAME));
|
|
|
+ doc.querySelectorAll("[" + windowIdAttributeName() + "]").forEach(element => element.removeAttribute(windowIdAttributeName()));
|
|
|
+ }
|
|
|
+
|
|
|
+ function preservedSpaceAttributeName() {
|
|
|
+ return PRESERVED_SPACE_ELEMENT_ATTRIBUTE_NAME;
|
|
|
+ }
|
|
|
+
|
|
|
+ function removedContentAttributeName() {
|
|
|
+ return REMOVED_CONTENT_ATTRIBUTE_NAME;
|
|
|
+ }
|
|
|
+
|
|
|
+ function windowIdAttributeName() {
|
|
|
+ return WIN_ID_ATTRIBUTE_NAME;
|
|
|
}
|
|
|
|
|
|
function getCanvasData(doc) {
|