single-file-core 1.5.73 → 1.5.75
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.
|
@@ -105,19 +105,19 @@ class ProcessorHelperCommon {
|
|
|
105
105
|
doc.querySelectorAll("svg").forEach(element => element.remove());
|
|
106
106
|
}
|
|
107
107
|
let resourcePromises = processAttributeArgs.map(([selector, attributeName, removeElementIfMissing, processDuplicates]) =>
|
|
108
|
-
this.processAttribute(doc.querySelectorAll(selector), attributeName, baseURI, options, "image", resources, removeElementIfMissing, batchRequest, styles, processDuplicates)
|
|
108
|
+
this.processAttribute(doc, doc.querySelectorAll(selector), attributeName, baseURI, options, "image", resources, removeElementIfMissing, batchRequest, styles, processDuplicates)
|
|
109
109
|
);
|
|
110
110
|
resourcePromises = resourcePromises.concat([
|
|
111
111
|
this.processXLinks(doc.querySelectorAll("use"), doc, baseURI, options, batchRequest, "xlink:href"),
|
|
112
112
|
this.processXLinks(doc.querySelectorAll("use"), doc, baseURI, options, batchRequest, "href"),
|
|
113
113
|
this.processSrcset(doc.querySelectorAll("img[srcset], source[srcset]"), baseURI, options, resources, batchRequest)
|
|
114
114
|
]);
|
|
115
|
-
resourcePromises.push(this.processAttribute(doc.querySelectorAll("object[data*=\".pdf\"]"), "data", baseURI, options, null, resources, false, batchRequest, styles));
|
|
116
|
-
resourcePromises.push(this.processAttribute(doc.querySelectorAll("embed[src*=\".pdf\"]"), "src", baseURI, options, null, resources, false, batchRequest, styles));
|
|
117
|
-
resourcePromises.push(this.processAttribute(doc.querySelectorAll("audio[src], audio > source[src]"), "src", baseURI, options, "audio", resources, false, batchRequest, styles));
|
|
118
|
-
resourcePromises.push(this.processAttribute(doc.querySelectorAll("video[src], video > source[src]"), "src", baseURI, options, "video", resources, false, batchRequest, styles));
|
|
119
|
-
resourcePromises.push(this.processAttribute(doc.querySelectorAll("audio track[src], video track[src]"), "src", baseURI, options, null, resources, false, batchRequest, styles));
|
|
120
|
-
resourcePromises.push(this.processAttribute(doc.querySelectorAll("model[src]"), "src", baseURI, options, null, resources, false, batchRequest, styles));
|
|
115
|
+
resourcePromises.push(this.processAttribute(doc, doc.querySelectorAll("object[data*=\".pdf\"]"), "data", baseURI, options, null, resources, false, batchRequest, styles));
|
|
116
|
+
resourcePromises.push(this.processAttribute(doc, doc.querySelectorAll("embed[src*=\".pdf\"]"), "src", baseURI, options, null, resources, false, batchRequest, styles));
|
|
117
|
+
resourcePromises.push(this.processAttribute(doc, doc.querySelectorAll("audio[src], audio > source[src]"), "src", baseURI, options, "audio", resources, false, batchRequest, styles));
|
|
118
|
+
resourcePromises.push(this.processAttribute(doc, doc.querySelectorAll("video[src], video > source[src]"), "src", baseURI, options, "video", resources, false, batchRequest, styles));
|
|
119
|
+
resourcePromises.push(this.processAttribute(doc, doc.querySelectorAll("audio track[src], video track[src]"), "src", baseURI, options, null, resources, false, batchRequest, styles));
|
|
120
|
+
resourcePromises.push(this.processAttribute(doc, doc.querySelectorAll("model[src]"), "src", baseURI, options, null, resources, false, batchRequest, styles));
|
|
121
121
|
await Promise.all(resourcePromises);
|
|
122
122
|
if (options.saveFavicon) {
|
|
123
123
|
this.processShortcutIcons(doc);
|
|
@@ -662,7 +662,7 @@ function getFontStretch(stretch) {
|
|
|
662
662
|
return FONT_STRETCHES[stretch] || stretch;
|
|
663
663
|
}
|
|
664
664
|
|
|
665
|
-
async function resizeImage(dataURI, { imageReductionFactor }) {
|
|
665
|
+
async function resizeImage(doc, dataURI, { imageReductionFactor }) {
|
|
666
666
|
if (dataURI) {
|
|
667
667
|
const contentType = dataURI.substring(5, dataURI.indexOf(";"));
|
|
668
668
|
if (contentType == "image/jpeg" ||
|
|
@@ -677,10 +677,26 @@ async function resizeImage(dataURI, { imageReductionFactor }) {
|
|
|
677
677
|
});
|
|
678
678
|
const width = image.naturalWidth / imageReductionFactor;
|
|
679
679
|
const height = image.naturalHeight / imageReductionFactor;
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
680
|
+
let blob;
|
|
681
|
+
try {
|
|
682
|
+
const canvas = new OffscreenCanvas(width, height);
|
|
683
|
+
const context = canvas.getContext("2d");
|
|
684
|
+
context.drawImage(image, 0, 0, width, height);
|
|
685
|
+
blob = await canvas.convertToBlob({ type: contentType });
|
|
686
|
+
} catch {
|
|
687
|
+
const canvas = doc.createElement("canvas");
|
|
688
|
+
canvas.width = width;
|
|
689
|
+
canvas.height = height;
|
|
690
|
+
const context = canvas.getContext("2d");
|
|
691
|
+
context.drawImage(image, 0, 0, width, height);
|
|
692
|
+
blob = await new Promise(resolve => canvas.toBlob(blob => {
|
|
693
|
+
if (blob) {
|
|
694
|
+
resolve(blob);
|
|
695
|
+
} else {
|
|
696
|
+
throw new Error("Canvas toBlob failed");
|
|
697
|
+
}
|
|
698
|
+
}, contentType));
|
|
699
|
+
}
|
|
684
700
|
if (blob.type == contentType) {
|
|
685
701
|
dataURI = await toDataURI(blob, contentType);
|
|
686
702
|
}
|
|
@@ -335,7 +335,7 @@ function getProcessorHelperClass(utilInstance) {
|
|
|
335
335
|
}));
|
|
336
336
|
}
|
|
337
337
|
|
|
338
|
-
async processAttribute(resourceElements, attributeName, baseURI, options, expectedType, resources, removeElementIfMissing, batchRequest, styles, processDuplicates) {
|
|
338
|
+
async processAttribute(doc, resourceElements, attributeName, baseURI, options, expectedType, resources, removeElementIfMissing, batchRequest, styles, processDuplicates) {
|
|
339
339
|
await Promise.all(Array.from(resourceElements).map(async resourceElement => {
|
|
340
340
|
let resourceURL = resourceElement.getAttribute(attributeName);
|
|
341
341
|
if (resourceURL != null) {
|
|
@@ -390,7 +390,7 @@ function getProcessorHelperClass(utilInstance) {
|
|
|
390
390
|
}
|
|
391
391
|
}
|
|
392
392
|
if (options.imageReductionFactor > 1) {
|
|
393
|
-
content = await resizeImage(content, options);
|
|
393
|
+
content = await resizeImage(doc, content, options);
|
|
394
394
|
}
|
|
395
395
|
if (removeElementIfMissing && this.testEmptyResource(content)) {
|
|
396
396
|
resourceElement.remove();
|
|
@@ -305,7 +305,7 @@ function getProcessorHelperClass(utilInstance) {
|
|
|
305
305
|
}));
|
|
306
306
|
}
|
|
307
307
|
|
|
308
|
-
async processAttribute(resourceElements, attributeName, baseURI, options, expectedType, resources, removeElementIfMissing, batchRequest) {
|
|
308
|
+
async processAttribute(doc, resourceElements, attributeName, baseURI, options, expectedType, resources, removeElementIfMissing, batchRequest) {
|
|
309
309
|
await Promise.all(Array.from(resourceElements).map(async resourceElement => {
|
|
310
310
|
let resourceURL = resourceElement.getAttribute(attributeName);
|
|
311
311
|
if (resourceURL != null) {
|
|
@@ -357,7 +357,7 @@ function getProcessorHelperClass(utilInstance) {
|
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
if (options.imageReductionFactor > 1) {
|
|
360
|
-
const dataURI = await resizeImage(await toDataURI(new Blob([content], { type: contentType }), charset), options);
|
|
360
|
+
const dataURI = await resizeImage(doc, await toDataURI(new Blob([content], { type: contentType }), charset), options);
|
|
361
361
|
content = (await util.getContent(dataURI, { asBinary: true })).data;
|
|
362
362
|
}
|
|
363
363
|
if (removeElementIfMissing && this.testEmptyResource(content)) {
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
import * as cssTree from "./../vendor/css-tree.js";
|
|
26
|
-
|
|
27
26
|
const UNMATCHABLE_PSEUDO_CLASSES = [
|
|
28
27
|
"active-view-transition",
|
|
29
28
|
"active-view-transition-type",
|
|
@@ -47,13 +46,42 @@ const UNMATCHABLE_PSEUDO_CLASSES = [
|
|
|
47
46
|
"stalled",
|
|
48
47
|
"volume-locked",
|
|
49
48
|
"after",
|
|
50
|
-
"before"
|
|
49
|
+
"before",
|
|
50
|
+
"visited",
|
|
51
|
+
"link",
|
|
52
|
+
"any-link",
|
|
53
|
+
"local-link",
|
|
54
|
+
"target",
|
|
55
|
+
"scope",
|
|
56
|
+
"hover",
|
|
57
|
+
"active",
|
|
58
|
+
"focus",
|
|
59
|
+
"focus-within",
|
|
60
|
+
"focus-visible",
|
|
61
|
+
"target-current",
|
|
62
|
+
"enabled",
|
|
63
|
+
"disabled",
|
|
64
|
+
"read-only",
|
|
65
|
+
"read-write",
|
|
66
|
+
"placeholder-shown",
|
|
67
|
+
"autofill",
|
|
68
|
+
"default",
|
|
69
|
+
"checked",
|
|
70
|
+
"indeterminate",
|
|
71
|
+
"blank",
|
|
72
|
+
"valid",
|
|
73
|
+
"invalid",
|
|
74
|
+
"in-range",
|
|
75
|
+
"out-of-range",
|
|
76
|
+
"required",
|
|
77
|
+
"optional",
|
|
78
|
+
"user-valid",
|
|
79
|
+
"user-invalid"
|
|
51
80
|
];
|
|
52
81
|
|
|
53
82
|
export {
|
|
54
83
|
sanitizeSelector,
|
|
55
84
|
};
|
|
56
|
-
|
|
57
85
|
/**
|
|
58
86
|
* Sanitize a selector AST into a QSA-safe selector string.
|
|
59
87
|
* Optional `ancestors` array may be provided to expand nesting selectors (`&`).
|
|
@@ -74,7 +102,6 @@ function sanitizeSelector(selector, ancestors, docContext) {
|
|
|
74
102
|
docContext.normalizedSelectorText.set(selector, normalized);
|
|
75
103
|
return normalized;
|
|
76
104
|
}
|
|
77
|
-
|
|
78
105
|
function normalizeSelectorNode(selector, ancestors) {
|
|
79
106
|
let current = selector.children.head;
|
|
80
107
|
while (current) {
|