|
@@ -83,6 +83,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
{ option: "insertFaviconLink", action: "insertFaviconLink" },
|
|
{ option: "insertFaviconLink", action: "insertFaviconLink" },
|
|
|
{ action: "resolveHrefs" },
|
|
{ action: "resolveHrefs" },
|
|
|
{ action: "replaceCanvasElements" },
|
|
{ action: "replaceCanvasElements" },
|
|
|
|
|
+ { action: "insertFonts" },
|
|
|
{ option: "removeHiddenElements", action: "removeHiddenElements" }
|
|
{ option: "removeHiddenElements", action: "removeHiddenElements" }
|
|
|
],
|
|
],
|
|
|
async: [
|
|
async: [
|
|
@@ -133,6 +134,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
if (this.options.doc) {
|
|
if (this.options.doc) {
|
|
|
const docData = DOM.preProcessDoc(this.options.doc, this.options.win, this.options);
|
|
const docData = DOM.preProcessDoc(this.options.doc, this.options.win, this.options);
|
|
|
this.options.canvasData = docData.canvasData;
|
|
this.options.canvasData = docData.canvasData;
|
|
|
|
|
+ this.options.fontsData = docData.fontsData;
|
|
|
this.options.stylesheetContents = docData.stylesheetContents;
|
|
this.options.stylesheetContents = docData.stylesheetContents;
|
|
|
this.options.imageData = docData.imageData;
|
|
this.options.imageData = docData.imageData;
|
|
|
}
|
|
}
|
|
@@ -614,6 +616,34 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ insertFonts() {
|
|
|
|
|
+ if (this.options.fontsData && this.options.fontsData.length) {
|
|
|
|
|
+ let stylesheetContent = "";
|
|
|
|
|
+ this.options.fontsData.forEach(fontData => {
|
|
|
|
|
+ const [name, url, details] = fontData;
|
|
|
|
|
+ if (name && url) {
|
|
|
|
|
+ stylesheetContent += "@font-face{";
|
|
|
|
|
+ let propertiesContent = "";
|
|
|
|
|
+ Object.keys(details).forEach(detail => {
|
|
|
|
|
+ propertiesContent += detail + ":" + details[detail];
|
|
|
|
|
+ propertiesContent += ";";
|
|
|
|
|
+ });
|
|
|
|
|
+ propertiesContent += "font-family:\"" + name + "\";";
|
|
|
|
|
+ propertiesContent += "src:" + url;
|
|
|
|
|
+ stylesheetContent += propertiesContent + "}";
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ const styleElement = this.doc.createElement("style");
|
|
|
|
|
+ styleElement.textContent = stylesheetContent;
|
|
|
|
|
+ const existingStyleElement = this.doc.querySelector("style");
|
|
|
|
|
+ if (existingStyleElement) {
|
|
|
|
|
+ existingStyleElement.parentElement.insertBefore(styleElement, existingStyleElement);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.doc.head.insertBefore(styleElement, this.doc.head.firstChild);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
replaceStyleContents() {
|
|
replaceStyleContents() {
|
|
|
if (this.options.stylesheetContents) {
|
|
if (this.options.stylesheetContents) {
|
|
|
this.doc.querySelectorAll("style").forEach((styleElement, styleIndex) => {
|
|
this.doc.querySelectorAll("style").forEach((styleElement, styleIndex) => {
|