|
@@ -85,6 +85,7 @@ const SingleFileCore = (() => {
|
|
|
this.processor.insertFaviconLink();
|
|
this.processor.insertFaviconLink();
|
|
|
this.processor.resolveHrefs();
|
|
this.processor.resolveHrefs();
|
|
|
this.processor.insertSingleFileCommentNode();
|
|
this.processor.insertSingleFileCommentNode();
|
|
|
|
|
+ this.processor.replaceCanvasElements();
|
|
|
if (this.options.removeHiddenElements) {
|
|
if (this.options.removeHiddenElements) {
|
|
|
this.processor.removeHiddenElements();
|
|
this.processor.removeHiddenElements();
|
|
|
}
|
|
}
|
|
@@ -321,6 +322,30 @@ const SingleFileCore = (() => {
|
|
|
this.doc.documentElement.insertBefore(commentNode, this.doc.documentElement.firstChild);
|
|
this.doc.documentElement.insertBefore(commentNode, this.doc.documentElement.firstChild);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ replaceCanvasElements() {
|
|
|
|
|
+ if (this.options.canvasData) {
|
|
|
|
|
+ this.doc.querySelectorAll("canvas").forEach((canvasElement, indexCanvasElement) => {
|
|
|
|
|
+ const canvasData = this.options.canvasData[indexCanvasElement];
|
|
|
|
|
+ if (canvasData) {
|
|
|
|
|
+ const imgElement = this.doc.createElement("img");
|
|
|
|
|
+ imgElement.setAttribute("src", canvasData.dataURI);
|
|
|
|
|
+ Array.from(canvasElement.attributes).forEach(attribute => {
|
|
|
|
|
+ if (attribute.value) {
|
|
|
|
|
+ imgElement.setAttribute(attribute.name, attribute.value);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ if (!imgElement.width && canvasData.width) {
|
|
|
|
|
+ imgElement.style.pixelWidth = canvasData.width;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!imgElement.height && canvasData.height) {
|
|
|
|
|
+ imgElement.style.pixelHeight = canvasData.height;
|
|
|
|
|
+ }
|
|
|
|
|
+ canvasElement.parentElement.replaceChild(imgElement, canvasElement);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
async pageResources() {
|
|
async pageResources() {
|
|
|
await Promise.all([
|
|
await Promise.all([
|
|
|
DomProcessorHelper.processAttribute(this.doc.querySelectorAll("link[href][rel*=\"icon\"]"), "href", this.baseURI),
|
|
DomProcessorHelper.processAttribute(this.doc.querySelectorAll("link[href][rel*=\"icon\"]"), "href", this.baseURI),
|