single-file-core 1.2.17 → 1.2.19

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/util.js CHANGED
@@ -35,10 +35,37 @@ const DEFAULT_REPLACEMENT_CHARACTER = "_";
35
35
  const CONTENT_TYPE_EXTENSIONS = {
36
36
  "image/svg+xml": ".svg",
37
37
  "image/png": ".png",
38
- "image/jpeg": ".jpg",
39
38
  "image/gif": ".gif",
40
- "image/webp": ".webp"
39
+ "image/tiff": ".tiff",
40
+ "image/bmp": ".bmp",
41
+ "image/x-icon": ".ico",
42
+ "image/heif": ".heif",
43
+ "image/heic": ".heic",
44
+ "image/avif": ".avif",
45
+ "image/apng": ".apng",
46
+ "image/jpeg": ".jpg",
47
+ "image/webp": ".webp",
48
+ "audio/mpeg": ".mp3",
49
+ "audio/ogg": ".ogg",
50
+ "audio/wav": ".wav",
51
+ "audio/webm": ".webm",
52
+ "video/3gpp": ".3gp",
53
+ "video/3gpp2": ".3g2",
54
+ "video/mpeg": ".mpeg",
55
+ "video/quicktime": ".mov",
56
+ "video/x-msvideo": ".avi",
57
+ "video/webm": ".webm",
58
+ "video/ogg": ".ogv",
59
+ "video/mp4": ".mp4",
60
+ "video/mp2t": ".ts",
61
+ "font/otf": ".otf",
62
+ "font/ttf": ".ttf",
63
+ "font/woff": ".woff",
64
+ "font/woff2": ".woff2",
65
+ "application/vnd.ms-fontobject": ".eot",
66
+ "font/collection": ".ttc"
41
67
  };
68
+ const CONTENT_TYPE_OCTET_STREAM = "application/octet-stream";
42
69
 
43
70
  const URL = globalThis.URL;
44
71
  const DOMParser = globalThis.DOMParser;
@@ -265,8 +292,8 @@ function getInstance(utilOptions) {
265
292
  } catch (error) {
266
293
  // ignored
267
294
  }
268
- if (!contentType) {
269
- contentType = guessMIMEType(options.expectedType, buffer);
295
+ if (!contentType || (contentType == CONTENT_TYPE_OCTET_STREAM && options.asBinary)) {
296
+ contentType = guessMIMEType(options.expectedType, buffer, options.asBinary);
270
297
  }
271
298
  if (!charset && options.charset) {
272
299
  charset = options.charset;
@@ -346,7 +373,7 @@ async function getFetchResponse(resourceURL, options, data, charset, contentType
346
373
  return { data, resourceURL, charset, contentType };
347
374
  }
348
375
 
349
- function guessMIMEType(expectedType, buffer) {
376
+ function guessMIMEType(expectedType, buffer, asBinary) {
350
377
  if (expectedType == "image") {
351
378
  if (compareBytes([255, 255, 255, 255], [0, 0, 1, 0])) {
352
379
  return "image/x-icon";
@@ -394,6 +421,56 @@ function guessMIMEType(expectedType, buffer) {
394
421
  return "font/woff2";
395
422
  }
396
423
  }
424
+ if (expectedType == "video") {
425
+ if (compareBytes([0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255], [0, 0, 0, 0, 102, 116, 121, 112, 105, 115, 111, 109])) {
426
+ return "video/mp4";
427
+ }
428
+ if (compareBytes([255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255], [82, 73, 70, 70, 0, 0, 0, 0, 87, 65, 86, 69])) {
429
+ return "video/x-msvideo";
430
+ }
431
+ if (compareBytes([255, 255, 255, 255], [0, 0, 1, 179]) || compareBytes([255, 255, 255, 255], [0, 0, 1, 186])) {
432
+ return "video/mpeg";
433
+ }
434
+ if (compareBytes([255, 255, 255, 255], [79, 103, 103, 83])) {
435
+ return "video/ogg";
436
+ }
437
+ if (compareBytes([255], [71])) {
438
+ return "video/mp2t";
439
+ }
440
+ if (compareBytes([255, 255, 255, 255], [26, 69, 223, 163])) {
441
+ return "video/webm";
442
+ }
443
+ if (compareBytes([0, 0, 0, 0, 255, 255, 255, 255, 255, 255], [0, 0, 0, 0, 102, 116, 121, 112, 51, 103])) {
444
+ return "video/3gpp";
445
+ }
446
+ }
447
+ if (expectedType == "audio") {
448
+ if (compareBytes([255, 255], [255, 249]) || compareBytes([255, 255], [255, 254])) {
449
+ return "audio/aac";
450
+ }
451
+ if (compareBytes([255, 255, 255, 255], [77, 84, 104, 100])) {
452
+ return "audio/midi";
453
+ }
454
+ if (compareBytes([255, 255, 255, 255], [0, 0, 1, 179]) || compareBytes([255, 255, 255, 255], [0, 0, 1, 186])) {
455
+ return "audio/mpeg";
456
+ }
457
+ if (compareBytes([255, 255], [255, 251]) || compareBytes([255, 255], [255, 243]) || compareBytes([255, 255], [255, 242]) || compareBytes([255, 255, 255], [73, 68, 51])) {
458
+ return "audio/mpeg";
459
+ }
460
+ if (compareBytes([255, 255, 255, 255], [79, 103, 103, 83])) {
461
+ return "audio/ogg";
462
+ }
463
+ if (compareBytes([255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255], [82, 73, 70, 70, 0, 0, 0, 0, 87, 65, 86, 69])) {
464
+ return "audio/wav";
465
+ }
466
+ if (compareBytes([255, 255, 255, 255], [26, 69, 223, 163])) {
467
+ return "audio/webm";
468
+ }
469
+ if (compareBytes([0, 0, 0, 0, 255, 255, 255, 255, 255, 255], [0, 0, 0, 0, 102, 116, 121, 112, 51, 103])) {
470
+ return "audio/3gpp";
471
+ }
472
+ }
473
+ return asBinary ? CONTENT_TYPE_OCTET_STREAM : "";
397
474
 
398
475
  function compareBytes(mask, pattern) {
399
476
  let patternMatch = true, index = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.2.17",
3
+ "version": "1.2.19",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -52,7 +52,17 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
52
52
  "midi": "audio/midi",
53
53
  "opus": "audio/opus",
54
54
  "wav": "audio/wav",
55
- "weba": "audio/webm"
55
+ "weba": "audio/webm",
56
+ "heif": "image/heif",
57
+ "heic": "image/heic",
58
+ "avif": "image/avif",
59
+ "apng": "image/apng",
60
+ "mov": "video/quicktime",
61
+ "otf": "font/otf",
62
+ "ttf": "font/ttf",
63
+ "woff": "font/woff",
64
+ "woff2": "font/woff2",
65
+ "eot": "application/vnd.ms-fontobject"
56
66
  };
57
67
  const REGEXP_MATCH_STYLESHEET = /stylesheet_[0-9]+\.css/;
58
68
  const REGEXP_MATCH_SCRIPT = /scripts\/[0-9]+\.js/;
@@ -38,8 +38,7 @@ import {
38
38
  } from "./compression-display.js";
39
39
 
40
40
  const { Blob, fetch, TextEncoder, DOMParser } = globalThis;
41
-
42
- const NO_COMPRESSION_EXTENSIONS = [".jpg", ".jpeg", ".png", ".pdf", ".woff2", ".mp4", ".mp3", ".ogg", ".webp", ".webm"];
41
+ const NO_COMPRESSION_EXTENSIONS = [ ".jpg", ".jpeg", ".png", ".pdf", ".woff2", ".mp4", ".mp3", ".ogg", ".webp", ".webm", ".avi", ".mpeg", ".ts", ".ogv" ];
43
42
  const SCRIPT_PATH = "/lib/single-file-zip.min.js";
44
43
 
45
44
  const browser = globalThis.browser;