single-file-core 1.0.21 → 1.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -101,9 +101,13 @@ function setSrc(srcData, imgElement, pictureElement) {
|
|
|
101
101
|
|
|
102
102
|
function getSourceSrc(sourceSrcSet) {
|
|
103
103
|
if (sourceSrcSet) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
104
|
+
try {
|
|
105
|
+
const srcset = srcsetParser.process(sourceSrcSet);
|
|
106
|
+
if (srcset.length) {
|
|
107
|
+
return (srcset.find(srcset => srcset.url)).url;
|
|
108
|
+
}
|
|
109
|
+
} catch (error) {
|
|
110
|
+
// ignored
|
|
107
111
|
}
|
|
108
112
|
}
|
|
109
113
|
}
|
|
@@ -145,7 +145,7 @@ function serializeAttribute(attribute, element, compressHTML) {
|
|
|
145
145
|
simpleQuotesValue = true;
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
|
-
const invalidUnquotedValue = !compressHTML ||
|
|
148
|
+
const invalidUnquotedValue = !compressHTML || value.match(/[ \t\n\f\r'"`=<>]/);
|
|
149
149
|
content += " ";
|
|
150
150
|
if (!attribute.namespace) {
|
|
151
151
|
content += name;
|
package/package.json
CHANGED
package/single-file-core.js
CHANGED
|
@@ -502,7 +502,7 @@ class Processor {
|
|
|
502
502
|
if (this.options.insertMetaCSP) {
|
|
503
503
|
const metaTag = this.doc.createElement("meta");
|
|
504
504
|
metaTag.httpEquiv = "content-security-policy";
|
|
505
|
-
metaTag.content = "default-src 'none'; font-src 'self' data:; img-src 'self' data:; style-src 'unsafe-inline'; media-src 'self' data:; script-src 'unsafe-inline' data:;";
|
|
505
|
+
metaTag.content = "default-src 'none'; font-src 'self' data:; img-src 'self' data:; style-src 'unsafe-inline'; media-src 'self' data:; script-src 'unsafe-inline' data:; object-src 'self' data:;";
|
|
506
506
|
this.doc.head.appendChild(metaTag);
|
|
507
507
|
}
|
|
508
508
|
if (this.options.insertMetaNoIndex) {
|
|
@@ -1854,6 +1854,10 @@ class ProcessorHelper {
|
|
|
1854
1854
|
if (testValidURL(resourceURL)) {
|
|
1855
1855
|
let { content, indexResource, duplicate } = await batchRequest.addURL(resourceURL,
|
|
1856
1856
|
{ asBinary: true, expectedType, groupDuplicates: options.groupDuplicateImages && resourceElement.tagName == "IMG" && attributeName == "src" });
|
|
1857
|
+
if (resourceURL.includes("openbenchmarking.org/embed.php")) {
|
|
1858
|
+
debugger
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1857
1861
|
if (originURL) {
|
|
1858
1862
|
if (content == util.EMPTY_RESOURCE) {
|
|
1859
1863
|
try {
|
package/single-file-helper.js
CHANGED
|
@@ -148,7 +148,7 @@ function preProcessDoc(doc, win, options) {
|
|
|
148
148
|
elementsInfo = getElementsInfo(win, doc, doc.documentElement, options);
|
|
149
149
|
if (options.moveStylesInHead) {
|
|
150
150
|
doc.querySelectorAll("body style, body ~ style").forEach(element => {
|
|
151
|
-
const computedStyle =
|
|
151
|
+
const computedStyle = getComputedStyle(win, element);
|
|
152
152
|
if (computedStyle && testHiddenElement(element, computedStyle)) {
|
|
153
153
|
element.setAttribute(STYLE_ATTRIBUTE_NAME, "");
|
|
154
154
|
elementsInfo.markedElements.push(element);
|
|
@@ -186,7 +186,7 @@ function getElementsInfo(win, doc, element, options, data = { usedFonts: new Map
|
|
|
186
186
|
elements.forEach(element => {
|
|
187
187
|
let elementHidden, elementKept, computedStyle;
|
|
188
188
|
if (!options.autoSaveExternalSave && (options.removeHiddenElements || options.removeUnusedFonts || options.compressHTML)) {
|
|
189
|
-
computedStyle =
|
|
189
|
+
computedStyle = getComputedStyle(win, element);
|
|
190
190
|
if (element instanceof win.HTMLElement) {
|
|
191
191
|
if (options.removeHiddenElements) {
|
|
192
192
|
elementKept = ((ascendantHidden || element.closest("html > head")) && KEPT_TAG_NAMES.includes(element.tagName)) || element.closest("details");
|
|
@@ -209,9 +209,9 @@ function getElementsInfo(win, doc, element, options, data = { usedFonts: new Map
|
|
|
209
209
|
}
|
|
210
210
|
if (options.removeUnusedFonts) {
|
|
211
211
|
getUsedFont(computedStyle, options, data.usedFonts);
|
|
212
|
-
getUsedFont(
|
|
213
|
-
getUsedFont(
|
|
214
|
-
getUsedFont(
|
|
212
|
+
getUsedFont(getComputedStyle(win, element, ":first-letter"), options, data.usedFonts);
|
|
213
|
+
getUsedFont(getComputedStyle(win, element, ":before"), options, data.usedFonts);
|
|
214
|
+
getUsedFont(getComputedStyle(win, element, ":after"), options, data.usedFonts);
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
}
|
|
@@ -269,11 +269,7 @@ function getResourcesInfo(win, doc, element, options, data, elementHidden, compu
|
|
|
269
269
|
element.setAttribute(IMAGE_ATTRIBUTE_NAME, data.images.length - 1);
|
|
270
270
|
data.markedElements.push(element);
|
|
271
271
|
element.removeAttribute(LAZY_SRC_ATTRIBUTE_NAME);
|
|
272
|
-
|
|
273
|
-
computedStyle = computedStyle || win.getComputedStyle(element);
|
|
274
|
-
} catch (error) {
|
|
275
|
-
// ignored
|
|
276
|
-
}
|
|
272
|
+
computedStyle = computedStyle || getComputedStyle(win, element);
|
|
277
273
|
if (computedStyle) {
|
|
278
274
|
imageData.size = getSize(win, element, computedStyle);
|
|
279
275
|
const boxShadow = computedStyle.getPropertyValue("box-shadow");
|
|
@@ -292,9 +288,9 @@ function getResourcesInfo(win, doc, element, options, data, elementHidden, compu
|
|
|
292
288
|
if (element.tagName == "VIDEO") {
|
|
293
289
|
const src = element.currentSrc;
|
|
294
290
|
if (src && !src.startsWith("blob:") && !src.startsWith("data:")) {
|
|
295
|
-
const
|
|
291
|
+
const computedStyle = getComputedStyle(win, element.parentNode);
|
|
296
292
|
data.videos.push({
|
|
297
|
-
positionParent,
|
|
293
|
+
positionParent: computedStyle && computedStyle.getPropertyValue("position"),
|
|
298
294
|
src,
|
|
299
295
|
size: {
|
|
300
296
|
pxWidth: element.clientWidth,
|
|
@@ -469,37 +465,39 @@ function getSize(win, imageElement, computedStyle) {
|
|
|
469
465
|
let pxHeight = imageElement.naturalHeight;
|
|
470
466
|
if (!pxWidth && !pxHeight) {
|
|
471
467
|
const noStyleAttribute = imageElement.getAttribute("style") == null;
|
|
472
|
-
computedStyle = computedStyle ||
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
468
|
+
computedStyle = computedStyle || getComputedStyle(win, imageElement);
|
|
469
|
+
if (computedStyle) {
|
|
470
|
+
let removeBorderWidth = false;
|
|
471
|
+
if (computedStyle.getPropertyValue("box-sizing") == "content-box") {
|
|
472
|
+
const boxSizingValue = imageElement.style.getPropertyValue("box-sizing");
|
|
473
|
+
const boxSizingPriority = imageElement.style.getPropertyPriority("box-sizing");
|
|
474
|
+
const clientWidth = imageElement.clientWidth;
|
|
475
|
+
imageElement.style.setProperty("box-sizing", "border-box", "important");
|
|
476
|
+
removeBorderWidth = imageElement.clientWidth != clientWidth;
|
|
477
|
+
if (boxSizingValue) {
|
|
478
|
+
imageElement.style.setProperty("box-sizing", boxSizingValue, boxSizingPriority);
|
|
479
|
+
} else {
|
|
480
|
+
imageElement.style.removeProperty("box-sizing");
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
let paddingLeft, paddingRight, paddingTop, paddingBottom, borderLeft, borderRight, borderTop, borderBottom;
|
|
484
|
+
paddingLeft = getWidth("padding-left", computedStyle);
|
|
485
|
+
paddingRight = getWidth("padding-right", computedStyle);
|
|
486
|
+
paddingTop = getWidth("padding-top", computedStyle);
|
|
487
|
+
paddingBottom = getWidth("padding-bottom", computedStyle);
|
|
488
|
+
if (removeBorderWidth) {
|
|
489
|
+
borderLeft = getWidth("border-left-width", computedStyle);
|
|
490
|
+
borderRight = getWidth("border-right-width", computedStyle);
|
|
491
|
+
borderTop = getWidth("border-top-width", computedStyle);
|
|
492
|
+
borderBottom = getWidth("border-bottom-width", computedStyle);
|
|
482
493
|
} else {
|
|
483
|
-
|
|
494
|
+
borderLeft = borderRight = borderTop = borderBottom = 0;
|
|
495
|
+
}
|
|
496
|
+
pxWidth = Math.max(0, imageElement.clientWidth - paddingLeft - paddingRight - borderLeft - borderRight);
|
|
497
|
+
pxHeight = Math.max(0, imageElement.clientHeight - paddingTop - paddingBottom - borderTop - borderBottom);
|
|
498
|
+
if (noStyleAttribute) {
|
|
499
|
+
imageElement.removeAttribute("style");
|
|
484
500
|
}
|
|
485
|
-
}
|
|
486
|
-
let paddingLeft, paddingRight, paddingTop, paddingBottom, borderLeft, borderRight, borderTop, borderBottom;
|
|
487
|
-
paddingLeft = getWidth("padding-left", computedStyle);
|
|
488
|
-
paddingRight = getWidth("padding-right", computedStyle);
|
|
489
|
-
paddingTop = getWidth("padding-top", computedStyle);
|
|
490
|
-
paddingBottom = getWidth("padding-bottom", computedStyle);
|
|
491
|
-
if (removeBorderWidth) {
|
|
492
|
-
borderLeft = getWidth("border-left-width", computedStyle);
|
|
493
|
-
borderRight = getWidth("border-right-width", computedStyle);
|
|
494
|
-
borderTop = getWidth("border-top-width", computedStyle);
|
|
495
|
-
borderBottom = getWidth("border-bottom-width", computedStyle);
|
|
496
|
-
} else {
|
|
497
|
-
borderLeft = borderRight = borderTop = borderBottom = 0;
|
|
498
|
-
}
|
|
499
|
-
pxWidth = Math.max(0, imageElement.clientWidth - paddingLeft - paddingRight - borderLeft - borderRight);
|
|
500
|
-
pxHeight = Math.max(0, imageElement.clientHeight - paddingTop - paddingBottom - borderTop - borderBottom);
|
|
501
|
-
if (noStyleAttribute) {
|
|
502
|
-
imageElement.removeAttribute("style");
|
|
503
501
|
}
|
|
504
502
|
}
|
|
505
503
|
return { pxWidth, pxHeight };
|
|
@@ -550,4 +548,12 @@ function getFontWeight(weight) {
|
|
|
550
548
|
|
|
551
549
|
function flatten(array) {
|
|
552
550
|
return array.flat ? array.flat() : array.reduce((a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []);
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
function getComputedStyle(win, element, pseudoElement) {
|
|
554
|
+
try {
|
|
555
|
+
return win.getComputedStyle(element, pseudoElement);
|
|
556
|
+
} catch (error) {
|
|
557
|
+
// ignored
|
|
558
|
+
}
|
|
553
559
|
}
|