single-file-core 1.0.17 → 1.0.20

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.0.17",
3
+ "version": "1.0.20",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -125,7 +125,7 @@ function triggerLazyLoading(options) {
125
125
  clearAsyncTimeout("idleTimeout");
126
126
  await setIdleTimeout(Math.max(500, delay / 2));
127
127
  }
128
- }, delay);
128
+ }, delay, options.loadDeferredImageNativeTimeout);
129
129
  }
130
130
 
131
131
  function onResourceLoad(event) {
@@ -162,14 +162,14 @@ function triggerLazyLoading(options) {
162
162
  }
163
163
 
164
164
  async function deferLazyLoadEnd(observer, options, resolve) {
165
- await setAsyncTimeout("loadTimeout", () => lazyLoadEnd(observer, options, resolve), options.loadDeferredImagesMaxIdleTime);
165
+ await setAsyncTimeout("loadTimeout", () => lazyLoadEnd(observer, options, resolve), options.loadDeferredImagesMaxIdleTime, options.loadDeferredImageNativeTimeout);
166
166
  }
167
167
 
168
168
  async function deferForceLazyLoadEnd(observer, options, resolve) {
169
169
  await setAsyncTimeout("maxTimeout", async () => {
170
170
  await clearAsyncTimeout("loadTimeout");
171
171
  await lazyLoadEnd(observer, options, resolve);
172
- }, options.loadDeferredImagesMaxIdleTime * 10);
172
+ }, options.loadDeferredImagesMaxIdleTime * 10, options.loadDeferredImageNativeTimeout);
173
173
  }
174
174
 
175
175
  async function lazyLoadEnd(observer, options, resolve) {
@@ -178,12 +178,12 @@ async function lazyLoadEnd(observer, options, resolve) {
178
178
  await setAsyncTimeout("endTimeout", async () => {
179
179
  await clearAsyncTimeout("maxTimeout");
180
180
  resolve();
181
- }, options.loadDeferredImagesMaxIdleTime / 2);
181
+ }, options.loadDeferredImagesMaxIdleTime / 2, options.loadDeferredImageNativeTimeout);
182
182
  observer.disconnect();
183
183
  }
184
184
 
185
- async function setAsyncTimeout(type, callback, delay) {
186
- if (browser && browser.runtime && browser.runtime.sendMessage) {
185
+ async function setAsyncTimeout(type, callback, delay, forceNativeTimeout) {
186
+ if (browser && browser.runtime && browser.runtime.sendMessage && !forceNativeTimeout) {
187
187
  if (!timeouts.get(type) || !timeouts.get(type).pending) {
188
188
  const timeoutData = { callback, pending: true };
189
189
  timeouts.set(type, timeoutData);
@@ -1620,33 +1620,35 @@ class ProcessorHelper {
1620
1620
  const imports = getImportFunctions(stylesheet);
1621
1621
  await Promise.all(imports.map(async node => {
1622
1622
  const urlNode = cssTree.find(node, node => node.type == "Url") || cssTree.find(node, node => node.type == "String");
1623
- let resourceURL = normalizeURL(urlNode.value);
1624
- if (!testIgnoredPath(resourceURL) && testValidPath(resourceURL)) {
1625
- urlNode.value = util.EMPTY_RESOURCE;
1626
- try {
1627
- resourceURL = util.resolveURL(resourceURL, baseURI);
1628
- } catch (error) {
1629
- // ignored
1630
- }
1631
- if (testValidURL(resourceURL) && !importedStyleSheets.has(resourceURL)) {
1632
- const content = await getStylesheetContent(resourceURL);
1633
- resourceURL = content.resourceURL;
1634
- content.data = getUpdatedResourceContent(resourceURL, content, options);
1635
- if (content.data && content.data.match(/^<!doctype /i)) {
1636
- content.data = "";
1637
- }
1638
- const mediaQueryListNode = cssTree.find(node, node => node.type == "MediaQueryList");
1639
- if (mediaQueryListNode) {
1640
- content.data = wrapMediaQuery(content.data, cssTree.generate(mediaQueryListNode));
1623
+ if (urlNode) {
1624
+ let resourceURL = normalizeURL(urlNode.value);
1625
+ if (!testIgnoredPath(resourceURL) && testValidPath(resourceURL)) {
1626
+ urlNode.value = util.EMPTY_RESOURCE;
1627
+ try {
1628
+ resourceURL = util.resolveURL(resourceURL, baseURI);
1629
+ } catch (error) {
1630
+ // ignored
1641
1631
  }
1642
- const importedStylesheet = cssTree.parse(content.data, { context: "stylesheet", parseCustomProperty: true });
1643
- const ancestorStyleSheets = new Set(importedStyleSheets);
1644
- ancestorStyleSheets.add(resourceURL);
1645
- await ProcessorHelper.resolveImportURLs(importedStylesheet, resourceURL, options, workStylesheet, ancestorStyleSheets);
1646
- for (let keyName of Object.keys(importedStylesheet)) {
1647
- node[keyName] = importedStylesheet[keyName];
1632
+ if (testValidURL(resourceURL) && !importedStyleSheets.has(resourceURL)) {
1633
+ const content = await getStylesheetContent(resourceURL);
1634
+ resourceURL = content.resourceURL;
1635
+ content.data = getUpdatedResourceContent(resourceURL, content, options);
1636
+ if (content.data && content.data.match(/^<!doctype /i)) {
1637
+ content.data = "";
1638
+ }
1639
+ const mediaQueryListNode = cssTree.find(node, node => node.type == "MediaQueryList");
1640
+ if (mediaQueryListNode) {
1641
+ content.data = wrapMediaQuery(content.data, cssTree.generate(mediaQueryListNode));
1642
+ }
1643
+ const importedStylesheet = cssTree.parse(content.data, { context: "stylesheet", parseCustomProperty: true });
1644
+ const ancestorStyleSheets = new Set(importedStyleSheets);
1645
+ ancestorStyleSheets.add(resourceURL);
1646
+ await ProcessorHelper.resolveImportURLs(importedStylesheet, resourceURL, options, workStylesheet, ancestorStyleSheets);
1647
+ for (let keyName of Object.keys(importedStylesheet)) {
1648
+ node[keyName] = importedStylesheet[keyName];
1649
+ }
1650
+ importFound = true;
1648
1651
  }
1649
- importFound = true;
1650
1652
  }
1651
1653
  }
1652
1654
  }));
@@ -48,7 +48,7 @@ const SELECTED_CONTENT_ATTRIBUTE_NAME = "data-single-file-selected-content";
48
48
  const INVALID_ELEMENT_ATTRIBUTE_NAME = "data-single-file-invalid-element";
49
49
  const ASYNC_SCRIPT_ATTRIBUTE_NAME = "data-single-file-async-script";
50
50
  const FLOW_ELEMENTS_SELECTOR = "*:not(base):not(link):not(meta):not(noscript):not(script):not(style):not(template):not(title)";
51
- const KEPT_TAG_NAMES = ["NOSCRIPT", "DISABLED-NOSCRIPT", "META", "LINK", "STYLE", "TITLE", "TEMPLATE", "SOURCE", "OBJECT", "SCRIPT", "HEAD"];
51
+ const KEPT_TAG_NAMES = ["NOSCRIPT", "DISABLED-NOSCRIPT", "META", "LINK", "STYLE", "TITLE", "TEMPLATE", "SOURCE", "OBJECT", "SCRIPT", "HEAD", "BODY"];
52
52
  const REGEXP_SIMPLE_QUOTES_STRING = /^'(.*?)'$/;
53
53
  const REGEXP_DOUBLE_QUOTES_STRING = /^"(.*?)"$/;
54
54
  const FONT_WEIGHTS = {
package/single-file.js CHANGED
@@ -42,7 +42,9 @@ export {
42
42
  };
43
43
 
44
44
  function init(initOptions) {
45
- SingleFile = core.getClass(util.getInstance(initOptions), vendor.cssTree);
45
+ if (typeof SingleFile == "undefined") {
46
+ SingleFile = core.getClass(util.getInstance(initOptions), vendor.cssTree);
47
+ }
46
48
  }
47
49
 
48
50
  async function getPageData(options = {}, initOptions, doc = globalThis.document, win = globalThis) {