single-file-core 1.5.100 → 1.5.102
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.
- package/core/lib/processor-helper-common.js +2 -1
- package/core/lib/processor-helper-inline.js +2 -3
- package/core/lib/processor-helper.js +2 -3
- package/modules/template-formatter.js +6 -1
- package/package.json +1 -1
- package/processors/compression/compression-extract.js +15 -1
- package/vendor/html-srcset-parser.js +31 -11
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
getFontWeight,
|
|
27
27
|
getDataURI
|
|
28
28
|
} from "./../helper.js";
|
|
29
|
+
import { serialize as serializeSrcset } from "./../../vendor/html-srcset-parser.js";
|
|
29
30
|
|
|
30
31
|
const DATA_URI_PREFIX = "data:";
|
|
31
32
|
const ABOUT_BLANK_URI = "about:blank";
|
|
@@ -244,7 +245,7 @@ class ProcessorHelperCommon {
|
|
|
244
245
|
return "";
|
|
245
246
|
}
|
|
246
247
|
} else {
|
|
247
|
-
return
|
|
248
|
+
return serializeSrcset([Object.assign({}, srcsetValue, { url: resourceURL })]);
|
|
248
249
|
}
|
|
249
250
|
}));
|
|
250
251
|
resourceElement.setAttribute("srcset", srcsetValues.join(", "));
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
import * as cssTree from "./../../vendor/css-tree.js";
|
|
25
|
+
import { serialize as serializeSrcset } from "./../../vendor/html-srcset-parser.js";
|
|
25
26
|
|
|
26
27
|
const JSON = globalThis.JSON;
|
|
27
28
|
const FontFace = globalThis.FontFace;
|
|
@@ -454,9 +455,7 @@ function getProcessorHelperClass(utilInstance) {
|
|
|
454
455
|
if (forbiddenPrefixFound) {
|
|
455
456
|
return "";
|
|
456
457
|
}
|
|
457
|
-
return
|
|
458
|
-
srcsetValue.h ? " " + srcsetValue.h + "h" :
|
|
459
|
-
srcsetValue.d ? " " + srcsetValue.d + "x" : "");
|
|
458
|
+
return serializeSrcset([Object.assign({}, srcsetValue, { url: content })]);
|
|
460
459
|
}
|
|
461
460
|
|
|
462
461
|
testEmptyResource(resource) {
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
import * as cssTree from "./../../vendor/css-tree.js";
|
|
25
|
+
import { serialize as serializeSrcset } from "./../../vendor/html-srcset-parser.js";
|
|
25
26
|
|
|
26
27
|
const JSON = globalThis.JSON;
|
|
27
28
|
const FontFace = globalThis.FontFace;
|
|
@@ -390,9 +391,7 @@ function getProcessorHelperClass(utilInstance) {
|
|
|
390
391
|
const { content, indexResource, extension, contentType } = await batchRequest.addURL(resourceURL, { asBinary: true, expectedType: "image" });
|
|
391
392
|
const name = "images/" + indexResource + extension;
|
|
392
393
|
resources.images.set(indexResource, { name, content, extension, contentType, url: resourceURL });
|
|
393
|
-
return
|
|
394
|
-
srcsetValue.h ? " " + srcsetValue.h + "h" :
|
|
395
|
-
srcsetValue.d ? " " + srcsetValue.d + "x" : "");
|
|
394
|
+
return serializeSrcset([Object.assign({}, srcsetValue, { url: name })]);
|
|
396
395
|
}
|
|
397
396
|
|
|
398
397
|
testEmptyResource(resource) {
|
|
@@ -16890,7 +16890,12 @@ async function formatFilename(content, doc, options) {
|
|
|
16890
16890
|
filename = "Unnamed page";
|
|
16891
16891
|
}
|
|
16892
16892
|
if (filename.startsWith(".")) {
|
|
16893
|
-
|
|
16893
|
+
const nameWithoutExtension = filename.replace(/\.[^.]{3,4}$/, "");
|
|
16894
|
+
if (/^\.*$/.test(nameWithoutExtension)) {
|
|
16895
|
+
filename = "Unnamed page" + filename;
|
|
16896
|
+
} else {
|
|
16897
|
+
filename = filenameReplacementCharacter + filename;
|
|
16898
|
+
}
|
|
16894
16899
|
}
|
|
16895
16900
|
return filename.trim();
|
|
16896
16901
|
}
|
package/package.json
CHANGED
|
@@ -27,7 +27,7 @@ export {
|
|
|
27
27
|
extract
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
async function extract(content, { password, prompt = () => { }, zipOptions = { useWebWorkers: true }, noBlobURL, entries, pagePath = "", excludedPaths } = {}) {
|
|
30
|
+
async function extract(content, { password, prompt = () => { }, zipOptions = { useWebWorkers: true }, noBlobURL, entries, pagePath = "", excludedPaths, aliases } = {}) {
|
|
31
31
|
const KNOWN_MIMETYPES = {
|
|
32
32
|
"gif": "image/gif",
|
|
33
33
|
"jpg": "image/jpeg",
|
|
@@ -89,6 +89,20 @@ async function extract(content, { password, prompt = () => { }, zipOptions = { u
|
|
|
89
89
|
zipReader = new zip.ZipReader(reader);
|
|
90
90
|
entries = await zipReader.getEntries();
|
|
91
91
|
}
|
|
92
|
+
if (aliases) {
|
|
93
|
+
const allEntries = entries;
|
|
94
|
+
entries = entries.map(entry => {
|
|
95
|
+
const canonicalFilename = aliases[entry.filename];
|
|
96
|
+
const canonicalEntry = canonicalFilename && allEntries.find(otherEntry => otherEntry.filename == canonicalFilename);
|
|
97
|
+
return canonicalEntry ? {
|
|
98
|
+
filename: entry.filename,
|
|
99
|
+
comment: canonicalEntry.comment,
|
|
100
|
+
encrypted: canonicalEntry.encrypted,
|
|
101
|
+
uncompressedSize: canonicalEntry.uncompressedSize,
|
|
102
|
+
getData: (writer, options) => canonicalEntry.getData(writer, options)
|
|
103
|
+
} : entry;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
92
106
|
if (pagePath) {
|
|
93
107
|
entries = entries.filter(entry => entry.filename.startsWith(pagePath));
|
|
94
108
|
} else if (excludedPaths) {
|
|
@@ -41,7 +41,8 @@
|
|
|
41
41
|
*/
|
|
42
42
|
|
|
43
43
|
export {
|
|
44
|
-
process
|
|
44
|
+
process,
|
|
45
|
+
serialize
|
|
45
46
|
};
|
|
46
47
|
|
|
47
48
|
// 1. Let input be the value passed to this algorithm.
|
|
@@ -286,7 +287,7 @@ function process(input) {
|
|
|
286
287
|
if (regexNonNegativeInteger.test(value) && (lastChar === "w")) {
|
|
287
288
|
|
|
288
289
|
// If width and density are not both absent, then let error be yes.
|
|
289
|
-
if (w || d) { pError = true; }
|
|
290
|
+
if (w || d !== undefined) { pError = true; }
|
|
290
291
|
|
|
291
292
|
// Apply the rules for parsing non-negative integers to the descriptor.
|
|
292
293
|
// If the result is zero, let error be yes.
|
|
@@ -298,8 +299,8 @@ function process(input) {
|
|
|
298
299
|
} else if (regexFloatingPoint.test(value) && (lastChar === "x")) {
|
|
299
300
|
|
|
300
301
|
// If width, density and future-compat-h are not all absent, then let error
|
|
301
|
-
// be yes.
|
|
302
|
-
if (w || d || h) { pError = true; }
|
|
302
|
+
// be yes. (d is compared with undefined: the spec allows a density of zero.)
|
|
303
|
+
if (w || d !== undefined || h) { pError = true; }
|
|
303
304
|
|
|
304
305
|
// Apply the rules for parsing floating-point number values to the descriptor.
|
|
305
306
|
// If the result is less than zero, let error be yes. Otherwise, let density
|
|
@@ -311,7 +312,7 @@ function process(input) {
|
|
|
311
312
|
} else if (regexNonNegativeInteger.test(value) && (lastChar === "h")) {
|
|
312
313
|
|
|
313
314
|
// If height and density are not both absent, then let error be yes.
|
|
314
|
-
if (h || d) { pError = true; }
|
|
315
|
+
if (h || d !== undefined) { pError = true; }
|
|
315
316
|
|
|
316
317
|
// Apply the rules for parsing non-negative integers to the descriptor.
|
|
317
318
|
// If the result is zero, let error be yes. Otherwise, let future-compat-h
|
|
@@ -325,15 +326,34 @@ function process(input) {
|
|
|
325
326
|
// 15. If error is still no, then append a new image source to candidates whose
|
|
326
327
|
// URL is url, associated with a width width if not absent and a pixel
|
|
327
328
|
// density density if not absent. Otherwise, there is a parse error.
|
|
328
|
-
|
|
329
|
-
|
|
329
|
+
candidate.url = url;
|
|
330
|
+
if (pError) {
|
|
331
|
+
// (The spec drops the candidate on a parse error. This parser is used to rewrite srcset
|
|
332
|
+
// attributes rather than to select an image, so the descriptors are kept verbatim
|
|
333
|
+
// instead: dropping the candidate would lose the URL from the rewritten attribute.)
|
|
334
|
+
candidate.descriptors = descriptors.slice();
|
|
335
|
+
} else {
|
|
330
336
|
if (w) { candidate.w = w; }
|
|
331
|
-
if (d) { candidate.d = d; }
|
|
337
|
+
if (d !== undefined) { candidate.d = d; }
|
|
332
338
|
if (h) { candidate.h = h; }
|
|
333
|
-
candidates.push(candidate);
|
|
334
|
-
} else if (console && console.log) { // eslint-disable-line no-console
|
|
335
|
-
console.log("Invalid srcset descriptor found in \"" + input + "\" at \"" + desc + "\"."); // eslint-disable-line no-console
|
|
336
339
|
}
|
|
340
|
+
candidates.push(candidate);
|
|
337
341
|
} // (close parseDescriptors fn)
|
|
338
342
|
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function serialize(srcset) {
|
|
346
|
+
return srcset.map(function (candidate) {
|
|
347
|
+
const descriptors = candidate.descriptors ? candidate.descriptors.slice() : [];
|
|
348
|
+
if (candidate.w) {
|
|
349
|
+
descriptors.push(candidate.w + "w");
|
|
350
|
+
}
|
|
351
|
+
if (candidate.h) {
|
|
352
|
+
descriptors.push(candidate.h + "h");
|
|
353
|
+
}
|
|
354
|
+
if (candidate.d !== undefined) {
|
|
355
|
+
descriptors.push(candidate.d + "x");
|
|
356
|
+
}
|
|
357
|
+
return [candidate.url].concat(descriptors).join(" ");
|
|
358
|
+
}).join(", ");
|
|
339
359
|
}
|