single-file-core 1.6.40 → 1.6.41

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.6.40",
3
+ "version": "1.6.41",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -24,7 +24,6 @@
24
24
  /* global URL */
25
25
 
26
26
  import {
27
- configure,
28
27
  TextReader,
29
28
  TextWriter,
30
29
  Uint8ArrayReader,
@@ -33,12 +32,11 @@ import {
33
32
  } from "./../../vendor/zip/zip.js";
34
33
  import {
35
34
  createArchive,
35
+ configureZipWorker,
36
36
  escapeHTML,
37
37
  PROCESS_OPTION_NAMES
38
38
  } from "./compression.js";
39
39
 
40
- const browser = globalThis.browser;
41
-
42
40
  const PAGES_PREFIX = "pages/";
43
41
  const PAGES_FILENAME = "sfz-pages.json";
44
42
  const MANIFEST_FILENAME = "manifest.json";
@@ -62,11 +60,7 @@ const SYMLINK_UNIX_MODE = 0o120777;
62
60
  export { createPagesArchive };
63
61
 
64
62
  async function createPagesArchive(pages, options) {
65
- if (browser && browser.runtime && browser.runtime.getURL) {
66
- configure({ workerURI: "/lib/single-file-z-worker.js", workerStartupTimeout: 2000 });
67
- } else {
68
- configure({ useWebWorkers: false });
69
- }
63
+ configureZipWorker(options);
70
64
  const manifest = {
71
65
  pages: pages.map((page, pageIndex) => ({
72
66
  path: getPagePath(pageIndex, options.createRootDirectory),
@@ -49,6 +49,8 @@ const COMPRESSIBLE_CONTENT_TYPES = ["application/javascript", "application/x-jav
49
49
  const TEXT_CONTENT_TYPE_PREFIX = "text/";
50
50
  const NO_COMPRESSION_EXTENSIONS = [".jpg", ".jpeg", ".png", ".apng", ".gif", ".webp", ".avif", ".heif", ".heic", ".jxl", ".pdf", ".woff", ".woff2", ".mp4", ".webm", ".avi", ".mpeg", ".mov", ".ts", ".ogv", ".mp3", ".ogg", ".oga", ".weba", ".m4a", ".aac", ".opus", ".flac"];
51
51
  const SCRIPT_PATH = "/lib/single-file-zip.min.js";
52
+ const DEFAULT_ZIP_WORKER_URI = "/lib/single-file-z-worker.js";
53
+ const ZIP_WORKER_STARTUP_TIMEOUT = 2000;
52
54
  const EXTRA_DATA_TAGS = [
53
55
  ["<script type=sfz-data>", "</script>"],
54
56
  ["<style type=sfz-data>", "</style>"],
@@ -128,25 +130,32 @@ const PROCESS_OPTION_NAMES = [
128
130
  "preventAppendedData",
129
131
  "selfExtractingArchive",
130
132
  "url",
131
- "zipScript"
133
+ "zipScript",
134
+ "zipWorkerURI"
132
135
  ];
133
136
 
134
137
  export {
135
138
  process,
136
139
  createArchive,
140
+ configureZipWorker,
137
141
  escapeHTML,
138
142
  PROCESS_OPTION_NAMES,
139
- DEFAULT_MAX_APPENDED_DATA_LENGTH
143
+ DEFAULT_MAX_APPENDED_DATA_LENGTH,
144
+ DEFAULT_ZIP_WORKER_URI
140
145
  };
141
146
 
147
+ function configureZipWorker(options) {
148
+ const configuration = browser && browser.runtime && browser.runtime.getURL
149
+ ? { workerURI: options.zipWorkerURI || DEFAULT_ZIP_WORKER_URI, workerStartupTimeout: ZIP_WORKER_STARTUP_TIMEOUT }
150
+ : { useWebWorkers: false };
151
+ configure(configuration);
152
+ return configuration;
153
+ }
154
+
142
155
  async function process(pageData, options, lastModDate = new Date()) {
143
156
  let script;
144
157
  const extensionContext = Boolean(browser && browser.runtime && browser.runtime.getURL);
145
- if (extensionContext) {
146
- configure({ workerURI: "/lib/single-file-z-worker.js" });
147
- } else {
148
- configure({ useWebWorkers: false });
149
- }
158
+ configureZipWorker(options);
150
159
  if (options.zipScript) {
151
160
  script = options.zipScript;
152
161
  } else if (extensionContext) {