single-file-core 1.3.20 → 1.3.22
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.
|
@@ -394,7 +394,7 @@ function getProcessorHelperClass(utilInstance) {
|
|
|
394
394
|
}
|
|
395
395
|
|
|
396
396
|
setMetaCSP(metaElement) {
|
|
397
|
-
metaElement.content = "default-src 'none'; connect-src 'self'
|
|
397
|
+
metaElement.content = "default-src 'none'; connect-src 'self' data: blob:; font-src 'self' data: blob:; img-src 'self' data: blob:; style-src 'self' 'unsafe-inline' data: blob:; frame-src 'self' data: blob:; media-src 'self' data: blob:; script-src 'self' 'unsafe-inline' data: blob:; object-src 'self' data: blob:;";
|
|
398
398
|
}
|
|
399
399
|
|
|
400
400
|
removeUnusedStylesheets() {
|
|
@@ -176,21 +176,27 @@ function testUsedFont(ruleData, familyName, declaredFonts, filteredUsedFonts) {
|
|
|
176
176
|
.filter(fontInfo => fontInfo.fontFamily == familyName && fontInfo.fontStyle == fontStyle)
|
|
177
177
|
.map(fontInfo => fontInfo.fontWeight.split(" "))
|
|
178
178
|
.sort((weight1, weight2) => Number.parseInt(weight1[0], 10) - Number.parseInt(weight2[0], 10));
|
|
179
|
-
let usedFontWeights = optionalUsedFonts
|
|
179
|
+
let usedFontWeights = optionalUsedFonts
|
|
180
|
+
.map(fontInfo => getUsedFontWeight(fontInfo, fontStyle, declaredFontsWeights))
|
|
181
|
+
.filter(fontWeight => fontWeight);
|
|
180
182
|
test = testFontweight(fontWeight, usedFontWeights);
|
|
181
183
|
if (!test) {
|
|
182
|
-
usedFontWeights = optionalUsedFonts
|
|
183
|
-
fontInfo
|
|
184
|
-
fontInfo[2] = "normal";
|
|
185
|
-
return getUsedFontWeight(fontInfo, fontStyle, declaredFontsWeights);
|
|
186
|
-
});
|
|
187
|
-
test = testFontweight(fontWeight, usedFontWeights);
|
|
188
|
-
if (!test) {
|
|
189
|
-
usedFontWeights = optionalUsedFonts.map(fontInfo => {
|
|
184
|
+
usedFontWeights = optionalUsedFonts
|
|
185
|
+
.map(fontInfo => {
|
|
190
186
|
fontInfo = Array.from(fontInfo);
|
|
191
|
-
fontInfo[2] =
|
|
187
|
+
fontInfo[2] = "normal";
|
|
192
188
|
return getUsedFontWeight(fontInfo, fontStyle, declaredFontsWeights);
|
|
193
|
-
})
|
|
189
|
+
})
|
|
190
|
+
.filter(fontWeight => fontWeight);
|
|
191
|
+
test = testFontweight(fontWeight, usedFontWeights);
|
|
192
|
+
if (!test) {
|
|
193
|
+
usedFontWeights = optionalUsedFonts
|
|
194
|
+
.map(fontInfo => {
|
|
195
|
+
fontInfo = Array.from(fontInfo);
|
|
196
|
+
fontInfo[2] = fontStyle = "normal";
|
|
197
|
+
return getUsedFontWeight(fontInfo, fontStyle, declaredFontsWeights);
|
|
198
|
+
})
|
|
199
|
+
.filter(fontWeight => fontWeight);
|
|
194
200
|
test = testFontweight(fontWeight, usedFontWeights);
|
|
195
201
|
}
|
|
196
202
|
}
|
|
@@ -205,12 +211,31 @@ function testUsedFont(ruleData, familyName, declaredFonts, filteredUsedFonts) {
|
|
|
205
211
|
|
|
206
212
|
function testFontweight(fontWeight, usedFontWeights) {
|
|
207
213
|
let test;
|
|
208
|
-
for (const
|
|
209
|
-
|
|
214
|
+
for (const fontWeightValue of fontWeight.split(",")) {
|
|
215
|
+
let { min: fontWeightMin, max: fontWeightMax } = parseFontWeight(fontWeightValue);
|
|
216
|
+
if (!fontWeightMax) {
|
|
217
|
+
fontWeightMax = 900;
|
|
218
|
+
}
|
|
219
|
+
test = test || usedFontWeights.find(usedFontWeight => {
|
|
220
|
+
let { min: usedFontWeightMin, max: usedFontWeightMax } = parseFontWeight(usedFontWeight);
|
|
221
|
+
if (!usedFontWeightMax) {
|
|
222
|
+
usedFontWeightMax = usedFontWeightMin;
|
|
223
|
+
}
|
|
224
|
+
return usedFontWeightMin >= fontWeightMin && usedFontWeightMax <= fontWeightMax;
|
|
225
|
+
});
|
|
210
226
|
}
|
|
211
227
|
return test;
|
|
212
228
|
}
|
|
213
229
|
|
|
230
|
+
function parseFontWeight(fontWeight) {
|
|
231
|
+
const fontWeightValues = fontWeight.split(" ");
|
|
232
|
+
const min = Number.parseInt(helper.getFontWeight(fontWeightValues[0]), 10);
|
|
233
|
+
const max = fontWeightValues[1] && Number.parseInt(helper.getFontWeight(fontWeightValues[1]), 10);
|
|
234
|
+
return {
|
|
235
|
+
min, max
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
214
239
|
function getDeclarationValue(declarations, propertyName) {
|
|
215
240
|
let property;
|
|
216
241
|
if (declarations) {
|
|
@@ -69,21 +69,23 @@ function processRules(cssRules, stats, removedRules = []) {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
function matchesMediaType(mediaText) {
|
|
72
|
-
const foundMediaTypes = helper.flatten(mediaQueryParser.parseMediaList(mediaText).map(node => getMediaTypes(node
|
|
73
|
-
return foundMediaTypes.find(mediaTypeInfo =>
|
|
74
|
-
|
|
72
|
+
const foundMediaTypes = helper.flatten(mediaQueryParser.parseMediaList(mediaText).map(node => getMediaTypes(node)));
|
|
73
|
+
return foundMediaTypes.find(mediaTypeInfo =>
|
|
74
|
+
(!mediaTypeInfo.not && (mediaTypeInfo.value == MEDIA_SCREEN || mediaTypeInfo.value == MEDIA_ALL)) ||
|
|
75
|
+
(mediaTypeInfo.not && (mediaTypeInfo.value != MEDIA_SCREEN && mediaTypeInfo.value != MEDIA_ALL)));
|
|
75
76
|
}
|
|
76
77
|
|
|
77
|
-
function getMediaTypes(parentNode,
|
|
78
|
+
function getMediaTypes(parentNode, mediaTypes = []) {
|
|
78
79
|
parentNode.nodes.map((node, indexNode) => {
|
|
79
80
|
if (node.type == "media-query") {
|
|
80
|
-
return getMediaTypes(node
|
|
81
|
+
return getMediaTypes(node);
|
|
81
82
|
} else {
|
|
82
83
|
if (node.type == "media-type") {
|
|
83
|
-
const nodeMediaType = {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
84
|
+
const nodeMediaType = {
|
|
85
|
+
not: Boolean(indexNode && parentNode.nodes[0].type == "keyword" && parentNode.nodes[0].value == "not"),
|
|
86
|
+
value: node.value
|
|
87
|
+
};
|
|
88
|
+
mediaTypes.push(nodeMediaType);
|
|
87
89
|
}
|
|
88
90
|
}
|
|
89
91
|
});
|
package/package.json
CHANGED
|
@@ -39,7 +39,7 @@ import {
|
|
|
39
39
|
|
|
40
40
|
const { Blob, fetch, TextEncoder, DOMParser } = globalThis;
|
|
41
41
|
|
|
42
|
-
const NO_COMPRESSION_EXTENSIONS = [".jpg", ".jpeg", ".png", ".pdf", ".woff2", ".mp4", ".mp3", ".ogg", ".webp", ".webm", ".avi", ".mpeg", ".ts", ".ogv"];
|
|
42
|
+
const NO_COMPRESSION_EXTENSIONS = [".jpg", ".jpeg", ".png", ".avi", ".apng", ".pdf", ".woff2", ".mp4", ".mp3", ".ogg", ".webp", ".webm", ".avi", ".mpeg", ".ts", ".ogv", ".heif", ".heic"];
|
|
43
43
|
const SCRIPT_PATH = "/lib/single-file-zip.min.js";
|
|
44
44
|
const EXTRA_DATA_TAGS = [
|
|
45
45
|
["<noscript>", "</noscript>"],
|
|
@@ -295,6 +295,9 @@ function getHTMLStartData(pageData, options) {
|
|
|
295
295
|
if (pageData.viewport) {
|
|
296
296
|
pageContent += "<meta name=viewport content=" + JSON.stringify(pageData.viewport) + ">";
|
|
297
297
|
}
|
|
298
|
+
if (options.insertMetaCSP) {
|
|
299
|
+
pageContent += "<meta http-equiv=content-security-policy content=\"default-src 'none'; connect-src 'self' data: blob:; font-src 'self' data: blob:; img-src 'self' data: blob:; style-src 'self' 'unsafe-inline' data: blob:; frame-src 'self' data: blob:; media-src 'self' data: blob:; script-src 'self' 'unsafe-inline' data: blob:; object-src 'self' data: blob:\">";
|
|
300
|
+
}
|
|
298
301
|
pageContent += "<style>@keyframes display-wait-message{0%{opacity:0}100%{opacity:1}};body{color:transparent};div{color:initial}</style>";
|
|
299
302
|
pageContent += "<body hidden>";
|
|
300
303
|
return pageContent;
|
package/single-file.js
CHANGED
|
@@ -115,6 +115,7 @@ async function getPageData(options = {}, initOptions, doc = globalThis.document,
|
|
|
115
115
|
preventAppendedData: options.preventAppendedData,
|
|
116
116
|
insertCanonicalLink: options.insertCanonicalLink,
|
|
117
117
|
insertMetaNoIndex: options.insertMetaNoIndex,
|
|
118
|
+
insertMetaCSP: options.insertMetaCSP,
|
|
118
119
|
password: options.password,
|
|
119
120
|
zipScript: options.zipScript
|
|
120
121
|
});
|