|
@@ -149,13 +149,13 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
this.processor = new Processor(options, this.batchRequest);
|
|
this.processor = new Processor(options, this.batchRequest);
|
|
|
if (this.options.doc) {
|
|
if (this.options.doc) {
|
|
|
const docData = util.preProcessDoc(this.options.doc, this.options.win, this.options);
|
|
const docData = util.preProcessDoc(this.options.doc, this.options.win, this.options);
|
|
|
- this.options.canvasData = docData.canvasData;
|
|
|
|
|
- this.options.fontsData = docData.fontsData;
|
|
|
|
|
- this.options.stylesheetsData = docData.stylesheetsData;
|
|
|
|
|
- this.options.imagesData = docData.imagesData;
|
|
|
|
|
- this.options.postersData = docData.postersData;
|
|
|
|
|
|
|
+ this.options.canvases = docData.canvases;
|
|
|
|
|
+ this.options.fonts = docData.fonts;
|
|
|
|
|
+ this.options.stylesheets = docData.stylesheets;
|
|
|
|
|
+ this.options.images = docData.images;
|
|
|
|
|
+ this.options.posters = docData.posters;
|
|
|
this.options.usedFonts = docData.usedFonts;
|
|
this.options.usedFonts = docData.usedFonts;
|
|
|
- this.options.shadowRootsData = docData.shadowRootsData;
|
|
|
|
|
|
|
+ this.options.shadowRoots = docData.shadowRoots;
|
|
|
this.options.referrer = docData.referrer;
|
|
this.options.referrer = docData.referrer;
|
|
|
}
|
|
}
|
|
|
if (this.options.saveRawPage) {
|
|
if (this.options.saveRawPage) {
|
|
@@ -346,8 +346,8 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
this.maffMetaDataPromise = this.batchRequest.addURL(util.resolveURL("index.rdf", this.options.baseURI || this.options.url), false);
|
|
this.maffMetaDataPromise = this.batchRequest.addURL(util.resolveURL("index.rdf", this.options.baseURI || this.options.url), false);
|
|
|
}
|
|
}
|
|
|
this.maxResources = this.batchRequest.getMaxResources();
|
|
this.maxResources = this.batchRequest.getMaxResources();
|
|
|
- if (!this.options.saveRawPage && !this.options.removeFrames && this.options.framesData) {
|
|
|
|
|
- this.options.framesData.forEach(frameData => this.maxResources += frameData.maxResources || 0);
|
|
|
|
|
|
|
+ if (!this.options.saveRawPage && !this.options.removeFrames && this.options.frames) {
|
|
|
|
|
+ this.options.frames.forEach(frameData => this.maxResources += frameData.maxResources || 0);
|
|
|
}
|
|
}
|
|
|
this.stats.set("processed", "resources", this.maxResources);
|
|
this.stats.set("processed", "resources", this.maxResources);
|
|
|
}
|
|
}
|
|
@@ -474,21 +474,21 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
if (this.options.win) {
|
|
if (this.options.win) {
|
|
|
this.doc.body.querySelectorAll(":not(svg) title, meta, link[href][rel*=\"icon\"]").forEach(element => element instanceof this.options.win.HTMLElement && this.doc.head.appendChild(element));
|
|
this.doc.body.querySelectorAll(":not(svg) title, meta, link[href][rel*=\"icon\"]").forEach(element => element instanceof this.options.win.HTMLElement && this.doc.head.appendChild(element));
|
|
|
}
|
|
}
|
|
|
- if (this.options.imagesData && !this.options.saveRawPage) {
|
|
|
|
|
|
|
+ if (this.options.images && !this.options.saveRawPage) {
|
|
|
const dataAttributeName = util.IMAGE_ATTRIBUTE_NAME;
|
|
const dataAttributeName = util.IMAGE_ATTRIBUTE_NAME;
|
|
|
this.doc.querySelectorAll("img").forEach(imgElement => {
|
|
this.doc.querySelectorAll("img").forEach(imgElement => {
|
|
|
- const imgData = this.options.imagesData[Number(imgElement.getAttribute(dataAttributeName))];
|
|
|
|
|
- if (this.options.removeHiddenElements && imgData.size && !imgData.size.pxWidth && !imgData.size.pxHeight) {
|
|
|
|
|
|
|
+ const imageData = this.options.images[Number(imgElement.getAttribute(dataAttributeName))];
|
|
|
|
|
+ if (this.options.removeHiddenElements && imageData.size && !imageData.size.pxWidth && !imageData.size.pxHeight) {
|
|
|
imgElement.setAttribute("src", EMPTY_IMAGE);
|
|
imgElement.setAttribute("src", EMPTY_IMAGE);
|
|
|
- } else if (imgData.currentSrc) {
|
|
|
|
|
- imgElement.setAttribute("src", imgData.currentSrc);
|
|
|
|
|
|
|
+ } else if (imageData.currentSrc) {
|
|
|
|
|
+ imgElement.setAttribute("src", imageData.currentSrc);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
if (this.options.loadDeferredImages) {
|
|
if (this.options.loadDeferredImages) {
|
|
|
this.doc.querySelectorAll("img[data-src]").forEach(imgElement => {
|
|
this.doc.querySelectorAll("img[data-src]").forEach(imgElement => {
|
|
|
- const imgData = this.options.imagesData[Number(imgElement.getAttribute(dataAttributeName))];
|
|
|
|
|
|
|
+ const imageData = this.options.images[Number(imgElement.getAttribute(dataAttributeName))];
|
|
|
if ((!imgElement.getAttribute("src") || imgElement.getAttribute("src") == EMPTY_IMAGE) && imgElement.getAttribute("data-src")) {
|
|
if ((!imgElement.getAttribute("src") || imgElement.getAttribute("src") == EMPTY_IMAGE) && imgElement.getAttribute("data-src")) {
|
|
|
- imgData.src = imgElement.dataset.src;
|
|
|
|
|
|
|
+ imageData.src = imgElement.dataset.src;
|
|
|
imgElement.setAttribute("src", imgElement.dataset.src);
|
|
imgElement.setAttribute("src", imgElement.dataset.src);
|
|
|
imgElement.removeAttribute("data-src");
|
|
imgElement.removeAttribute("data-src");
|
|
|
}
|
|
}
|
|
@@ -504,10 +504,10 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
replaceStyleContents() {
|
|
replaceStyleContents() {
|
|
|
- if (this.options.stylesheetsData) {
|
|
|
|
|
|
|
+ if (this.options.stylesheets) {
|
|
|
this.doc.querySelectorAll("style").forEach((styleElement, styleIndex) => {
|
|
this.doc.querySelectorAll("style").forEach((styleElement, styleIndex) => {
|
|
|
- if (this.options.stylesheetsData[styleIndex]) {
|
|
|
|
|
- styleElement.textContent = this.options.stylesheetsData[styleIndex];
|
|
|
|
|
|
|
+ if (this.options.stylesheets[styleIndex]) {
|
|
|
|
|
+ styleElement.textContent = this.options.stylesheets[styleIndex];
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -553,7 +553,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
insertVideoPosters() {
|
|
insertVideoPosters() {
|
|
|
- if (this.options.postersData) {
|
|
|
|
|
|
|
+ if (this.options.posters) {
|
|
|
this.doc.querySelectorAll("video[src], video > source[src]").forEach(element => {
|
|
this.doc.querySelectorAll("video[src], video > source[src]").forEach(element => {
|
|
|
let videoElement;
|
|
let videoElement;
|
|
|
if (element.tagName == "VIDEO") {
|
|
if (element.tagName == "VIDEO") {
|
|
@@ -562,8 +562,8 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
videoElement = element.parentElement;
|
|
videoElement = element.parentElement;
|
|
|
}
|
|
}
|
|
|
const videoIndex = Number(element.getAttribute(util.POSTER_ATTRIBUTE_NAME));
|
|
const videoIndex = Number(element.getAttribute(util.POSTER_ATTRIBUTE_NAME));
|
|
|
- if (!videoElement.poster && this.options.postersData[videoIndex]) {
|
|
|
|
|
- videoElement.setAttribute("poster", this.options.postersData[videoIndex]);
|
|
|
|
|
|
|
+ if (!videoElement.poster && this.options.posters[videoIndex]) {
|
|
|
|
|
+ videoElement.setAttribute("poster", this.options.posters[videoIndex]);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -711,10 +711,10 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
replaceCanvasElements() {
|
|
replaceCanvasElements() {
|
|
|
- if (this.options.canvasData) {
|
|
|
|
|
|
|
+ if (this.options.canvases) {
|
|
|
this.doc.querySelectorAll("canvas").forEach(canvasElement => {
|
|
this.doc.querySelectorAll("canvas").forEach(canvasElement => {
|
|
|
const canvasIndex = Number(canvasElement.getAttribute(util.CANVAS_ATTRIBUTE_NAME));
|
|
const canvasIndex = Number(canvasElement.getAttribute(util.CANVAS_ATTRIBUTE_NAME));
|
|
|
- const canvasData = this.options.canvasData[canvasIndex];
|
|
|
|
|
|
|
+ const canvasData = this.options.canvases[canvasIndex];
|
|
|
if (canvasData) {
|
|
if (canvasData) {
|
|
|
ProcessorHelper.setBackgroundImage(canvasElement, "url(" + canvasData.dataURI + ")");
|
|
ProcessorHelper.setBackgroundImage(canvasElement, "url(" + canvasData.dataURI + ")");
|
|
|
this.stats.add("processed", "canvas", 1);
|
|
this.stats.add("processed", "canvas", 1);
|
|
@@ -724,17 +724,17 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
insertFonts() {
|
|
insertFonts() {
|
|
|
- if (this.options.fontsData && this.options.fontsData.length) {
|
|
|
|
|
|
|
+ if (this.options.fonts && this.options.fonts.length) {
|
|
|
let stylesheetContent = "";
|
|
let stylesheetContent = "";
|
|
|
- this.options.fontsData.forEach(fontStyles => {
|
|
|
|
|
- if (fontStyles["font-family"] && fontStyles.src) {
|
|
|
|
|
|
|
+ this.options.fonts.forEach(fontData => {
|
|
|
|
|
+ if (fontData["font-family"] && fontData.src) {
|
|
|
stylesheetContent += "@font-face{";
|
|
stylesheetContent += "@font-face{";
|
|
|
let stylesContent = "";
|
|
let stylesContent = "";
|
|
|
- Object.keys(fontStyles).forEach(fontStyle => {
|
|
|
|
|
|
|
+ Object.keys(fontData).forEach(fontStyle => {
|
|
|
if (stylesContent) {
|
|
if (stylesContent) {
|
|
|
stylesContent += ";";
|
|
stylesContent += ";";
|
|
|
}
|
|
}
|
|
|
- stylesContent += fontStyle + ":" + fontStyles[fontStyle];
|
|
|
|
|
|
|
+ stylesContent += fontStyle + ":" + fontData[fontStyle];
|
|
|
});
|
|
});
|
|
|
stylesheetContent += stylesContent + "}";
|
|
stylesheetContent += stylesContent + "}";
|
|
|
}
|
|
}
|
|
@@ -835,7 +835,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async resolveFrameURLs() {
|
|
async resolveFrameURLs() {
|
|
|
- if (!this.options.saveRawPage && this.options.framesData) {
|
|
|
|
|
|
|
+ if (!this.options.saveRawPage && this.options.frames) {
|
|
|
const frameElements = Array.from(this.doc.querySelectorAll("iframe, frame, object[type=\"text/html\"][data]"));
|
|
const frameElements = Array.from(this.doc.querySelectorAll("iframe, frame, object[type=\"text/html\"][data]"));
|
|
|
await Promise.all(frameElements.map(async frameElement => {
|
|
await Promise.all(frameElements.map(async frameElement => {
|
|
|
if (frameElement.tagName == "OBJECT") {
|
|
if (frameElement.tagName == "OBJECT") {
|
|
@@ -846,7 +846,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
}
|
|
}
|
|
|
const frameWindowId = frameElement.getAttribute(util.WIN_ID_ATTRIBUTE_NAME);
|
|
const frameWindowId = frameElement.getAttribute(util.WIN_ID_ATTRIBUTE_NAME);
|
|
|
if (frameWindowId) {
|
|
if (frameWindowId) {
|
|
|
- const frameData = this.options.framesData.find(frame => frame.windowId == frameWindowId);
|
|
|
|
|
|
|
+ const frameData = this.options.frames.find(frame => frame.windowId == frameWindowId);
|
|
|
if (frameData) {
|
|
if (frameData) {
|
|
|
await initializeProcessor(frameData, frameElement, frameWindowId, this.batchRequest, Object.create(this.options));
|
|
await initializeProcessor(frameData, frameElement, frameWindowId, this.batchRequest, Object.create(this.options));
|
|
|
}
|
|
}
|
|
@@ -863,13 +863,13 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
options.windowId = frameWindowId;
|
|
options.windowId = frameWindowId;
|
|
|
if (frameData.content) {
|
|
if (frameData.content) {
|
|
|
options.content = frameData.content;
|
|
options.content = frameData.content;
|
|
|
- options.postersData = frameData.postersData;
|
|
|
|
|
- options.canvasData = frameData.canvasData;
|
|
|
|
|
- options.stylesheetsData = frameData.stylesheetsData;
|
|
|
|
|
- options.fontsData = frameData.fontsData;
|
|
|
|
|
- options.imagesData = frameData.imagesData;
|
|
|
|
|
|
|
+ options.canvases = frameData.canvases;
|
|
|
|
|
+ options.fonts = frameData.fonts;
|
|
|
|
|
+ options.stylesheets = frameData.stylesheets;
|
|
|
|
|
+ options.images = frameData.images;
|
|
|
|
|
+ options.posters = frameData.posters;
|
|
|
options.usedFonts = frameData.usedFonts;
|
|
options.usedFonts = frameData.usedFonts;
|
|
|
- options.shadowRootsData = frameData.shadowRootsData;
|
|
|
|
|
|
|
+ options.shadowRoots = frameData.shadowRoots;
|
|
|
frameData.processor = new Runner(options);
|
|
frameData.processor = new Runner(options);
|
|
|
frameData.frameElement = frameElement;
|
|
frameData.frameElement = frameElement;
|
|
|
await frameData.processor.loadPage();
|
|
await frameData.processor.loadPage();
|
|
@@ -882,7 +882,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
insertShadowRootContents() {
|
|
insertShadowRootContents() {
|
|
|
const doc = this.doc;
|
|
const doc = this.doc;
|
|
|
const options = this.options;
|
|
const options = this.options;
|
|
|
- if (this.options.shadowRootsData && this.options.shadowRootsData.length) {
|
|
|
|
|
|
|
+ if (this.options.shadowRoots && this.options.shadowRoots.length) {
|
|
|
processElement(this.doc);
|
|
processElement(this.doc);
|
|
|
const scriptElement = doc.createElement("script");
|
|
const scriptElement = doc.createElement("script");
|
|
|
scriptElement.textContent = `(()=>{document.currentScript.remove();processNode(document);function processNode(node){debugger;node.querySelectorAll("template[${WC_ATTRIBUTE_NAME}]").forEach(element=>{const shadowRoot=element.parentElement.attachShadow({mode:"open"});shadowRoot.innerHTML=element.innerHTML;element.remove();processNode(shadowRoot)})}})()`;
|
|
scriptElement.textContent = `(()=>{document.currentScript.remove();processNode(document);function processNode(node){debugger;node.querySelectorAll("template[${WC_ATTRIBUTE_NAME}]").forEach(element=>{const shadowRoot=element.parentElement.attachShadow({mode:"open"});shadowRoot.innerHTML=element.innerHTML;element.remove();processNode(shadowRoot)})}})()`;
|
|
@@ -893,7 +893,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
const shadowRootElements = Array.from((element.querySelectorAll("[" + util.SHADOW_ROOT_ATTRIBUTE_NAME + "]")));
|
|
const shadowRootElements = Array.from((element.querySelectorAll("[" + util.SHADOW_ROOT_ATTRIBUTE_NAME + "]")));
|
|
|
shadowRootElements.forEach(element => {
|
|
shadowRootElements.forEach(element => {
|
|
|
const id = element.getAttribute(util.SHADOW_ROOT_ATTRIBUTE_NAME);
|
|
const id = element.getAttribute(util.SHADOW_ROOT_ATTRIBUTE_NAME);
|
|
|
- const shadowRootData = options.shadowRootsData[Number(id)];
|
|
|
|
|
|
|
+ const shadowRootData = options.shadowRoots[Number(id)];
|
|
|
if (shadowRootData) {
|
|
if (shadowRootData) {
|
|
|
const templateElement = doc.createElement("template");
|
|
const templateElement = doc.createElement("template");
|
|
|
templateElement.setAttribute(WC_ATTRIBUTE_NAME, "");
|
|
templateElement.setAttribute(WC_ATTRIBUTE_NAME, "");
|
|
@@ -1028,14 +1028,14 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async processFrames() {
|
|
async processFrames() {
|
|
|
- if (this.options.framesData) {
|
|
|
|
|
|
|
+ if (this.options.frames) {
|
|
|
const frameElements = Array.from(this.doc.querySelectorAll("iframe, frame, object[type=\"text/html\"][data]"));
|
|
const frameElements = Array.from(this.doc.querySelectorAll("iframe, frame, object[type=\"text/html\"][data]"));
|
|
|
await Promise.all(frameElements.map(async frameElement => {
|
|
await Promise.all(frameElements.map(async frameElement => {
|
|
|
const frameWindowId = frameElement.getAttribute(util.WIN_ID_ATTRIBUTE_NAME);
|
|
const frameWindowId = frameElement.getAttribute(util.WIN_ID_ATTRIBUTE_NAME);
|
|
|
if (frameWindowId) {
|
|
if (frameWindowId) {
|
|
|
- const frameData = this.options.framesData.find(frame => frame.windowId == frameWindowId);
|
|
|
|
|
|
|
+ const frameData = this.options.frames.find(frame => frame.windowId == frameWindowId);
|
|
|
if (frameData) {
|
|
if (frameData) {
|
|
|
- this.options.framesData = this.options.framesData.filter(frame => frame.windowId != frameWindowId);
|
|
|
|
|
|
|
+ this.options.frames = this.options.frames.filter(frame => frame.windowId != frameWindowId);
|
|
|
if (frameData.processor) {
|
|
if (frameData.processor) {
|
|
|
this.stats.add("processed", "frames", 1);
|
|
this.stats.add("processed", "frames", 1);
|
|
|
await frameData.processor.run();
|
|
await frameData.processor.run();
|
|
@@ -1570,19 +1570,19 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
static replaceImageSource(imgElement, variableName, options) {
|
|
static replaceImageSource(imgElement, variableName, options) {
|
|
|
const dataAttributeName = util.IMAGE_ATTRIBUTE_NAME;
|
|
const dataAttributeName = util.IMAGE_ATTRIBUTE_NAME;
|
|
|
if (imgElement.getAttribute(dataAttributeName) != null) {
|
|
if (imgElement.getAttribute(dataAttributeName) != null) {
|
|
|
- const imgData = options.imagesData[Number(imgElement.getAttribute(dataAttributeName))];
|
|
|
|
|
- if (imgData.replaceable) {
|
|
|
|
|
- imgElement.setAttribute("src", `${PREFIX_DATA_URI_IMAGE_SVG},<svg xmlns="http://www.w3.org/2000/svg" width="${imgData.size.pxWidth}" height="${imgData.size.pxHeight}"><rect fill-opacity="0"/></svg>`);
|
|
|
|
|
|
|
+ const imageData = options.images[Number(imgElement.getAttribute(dataAttributeName))];
|
|
|
|
|
+ if (imageData.replaceable) {
|
|
|
|
|
+ imgElement.setAttribute("src", `${PREFIX_DATA_URI_IMAGE_SVG},<svg xmlns="http://www.w3.org/2000/svg" width="${imageData.size.pxWidth}" height="${imageData.size.pxHeight}"><rect fill-opacity="0"/></svg>`);
|
|
|
const backgroundStyle = {};
|
|
const backgroundStyle = {};
|
|
|
- const backgroundSize = (imgData.objectFit == "content" || imgData.objectFit == "cover") && imgData.objectFit;
|
|
|
|
|
|
|
+ const backgroundSize = (imageData.objectFit == "content" || imageData.objectFit == "cover") && imageData.objectFit;
|
|
|
if (backgroundSize) {
|
|
if (backgroundSize) {
|
|
|
- backgroundStyle["background-size"] = imgData.objectFit;
|
|
|
|
|
|
|
+ backgroundStyle["background-size"] = imageData.objectFit;
|
|
|
}
|
|
}
|
|
|
- if (imgData.objectPosition) {
|
|
|
|
|
- backgroundStyle["background-position"] = imgData.objectPosition;
|
|
|
|
|
|
|
+ if (imageData.objectPosition) {
|
|
|
|
|
+ backgroundStyle["background-position"] = imageData.objectPosition;
|
|
|
}
|
|
}
|
|
|
- if (imgData.backgroundColor) {
|
|
|
|
|
- backgroundStyle["background-color"] = imgData.backgroundColor;
|
|
|
|
|
|
|
+ if (imageData.backgroundColor) {
|
|
|
|
|
+ backgroundStyle["background-color"] = imageData.backgroundColor;
|
|
|
}
|
|
}
|
|
|
ProcessorHelper.setBackgroundImage(imgElement, "var(" + variableName + ")", backgroundStyle);
|
|
ProcessorHelper.setBackgroundImage(imgElement, "var(" + variableName + ")", backgroundStyle);
|
|
|
imgElement.removeAttribute(dataAttributeName);
|
|
imgElement.removeAttribute(dataAttributeName);
|