single-file-core 1.6.39 → 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/core/helper.js CHANGED
@@ -126,6 +126,8 @@ const COUNTER_STYLE_CHARACTERS = {
126
126
  "upper-roman": "IVXLCDM",
127
127
  "lower-greek": "αβγδεζηθικλμνξοπρστυφχψω"
128
128
  };
129
+ const REGEXP_INFINITE_FEATURE_VALUE = /(\(\s*[a-z-]+\s*(?::|<=?|>=?|=)\s*)(-?)infinity\s*\*\s*1([a-z%]+)/gi;
130
+ const MAX_FINITE_FEATURE_VALUE = "3.40282e38";
129
131
  const FULL_WIDTH_OFFSET = 0xFEE0;
130
132
  const FULL_WIDTH_SPACE = " ";
131
133
  const SINGLE_FILE_UI_ELEMENT_CLASS = "single-file-ui-element";
@@ -203,6 +205,7 @@ export {
203
205
  getElementCharacters,
204
206
  getPseudoElementCharacters,
205
207
  getMarkerCharacters,
208
+ normalizeSerializedCSSText,
206
209
  initDoc,
207
210
  preProcessDoc,
208
211
  postProcessDoc,
@@ -926,7 +929,7 @@ function getStylesheetsContent(styleSheets, adoptedStyleSheetsCache = new Map())
926
929
  let cssText = "";
927
930
  if (styleSheet && styleSheet.cssRules) {
928
931
  for (const cssRule of styleSheet.cssRules) {
929
- cssText += cssRule.cssText + "\n";
932
+ cssText += getSerializedCSSText(cssRule) + "\n";
930
933
  }
931
934
  }
932
935
  adoptedStyleSheetsCache.set(styleSheet, cssText);
@@ -1343,6 +1346,14 @@ function markLinkStylesheets(doc, markedElements) {
1343
1346
  return linkElements;
1344
1347
  }
1345
1348
 
1349
+ function getSerializedCSSText(cssRule) {
1350
+ return normalizeSerializedCSSText(cssRule.cssText);
1351
+ }
1352
+
1353
+ function normalizeSerializedCSSText(cssText) {
1354
+ return cssText.replace(REGEXP_INFINITE_FEATURE_VALUE, "$1$2" + MAX_FINITE_FEATURE_VALUE + "$3");
1355
+ }
1356
+
1346
1357
  function getStylesheetsData(doc, markedElements) {
1347
1358
  if (doc) {
1348
1359
  const contents = [];
@@ -1359,7 +1370,7 @@ function getStylesheetsData(doc, markedElements) {
1359
1370
  if (!stylesheet || textContentStylesheet != sheetStylesheet) {
1360
1371
  styleElement.setAttribute(STYLESHEET_ATTRIBUTE_NAME, styleIndex);
1361
1372
  markedElements.push(styleElement);
1362
- contents[styleIndex] = Array.from(styleElement.sheet.cssRules).map(cssRule => cssRule.cssText).join("\n");
1373
+ contents[styleIndex] = Array.from(styleElement.sheet.cssRules).map(getSerializedCSSText).join("\n");
1363
1374
  }
1364
1375
  }
1365
1376
  // eslint-disable-next-line no-unused-vars
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.6.39",
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) {