single-file-core 1.0.50 → 1.0.52

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.
@@ -143,7 +143,7 @@
143
143
  if (singleFileComment && isSingleFileComment(singleFileComment)) {
144
144
  const info = singleFileComment.textContent.split("\n");
145
145
  const [, , urlData, ...optionalData] = info;
146
- const urlMatch = urlData.match(/^ url: (.*) $/);
146
+ const urlMatch = urlData.match(/^ url: (.*) ?$/);
147
147
  const url = urlMatch && urlMatch[1];
148
148
  if (url) {
149
149
  let options;
@@ -115,7 +115,7 @@ function getMatchedElementsRules(doc, cssRules, mediaInfo, sheetIndex, styles, m
115
115
  const selectors = ruleData.prelude.children.toArray();
116
116
  const selectorsText = ruleData.prelude.children.toArray().map(selector => cssTree.generate(selector));
117
117
  const ruleInfo = { ruleData, mediaInfo, ruleIndex, sheetIndex, matchedSelectors: new Set(), declarations: new Set(), selectors, selectorsText };
118
- if (!invalidSelector(selectorsText.join(","), workStylesheet)) {
118
+ if (!invalidSelector(selectorsText.join(","), workStylesheet) || selectorsText.find(selectorText => selectorText.includes("|"))) {
119
119
  for (let selector = ruleData.prelude.children.head, selectorIndex = 0; selector; selector = selector.next, selectorIndex++) {
120
120
  const selectorText = selectorsText[selectorIndex];
121
121
  const selectorInfo = { selector, selectorText, ruleInfo };
@@ -174,6 +174,10 @@ function getMatchedElementsSelector(doc, selectorInfo, styles, matchedElementsCa
174
174
  }
175
175
 
176
176
  function getFilteredSelector(selector, selectorText) {
177
+ const namespaceSeparatorIndex = selectorText.lastIndexOf("|");
178
+ if (namespaceSeparatorIndex > -1) {
179
+ return selectorText.substring(namespaceSeparatorIndex + 1);
180
+ }
177
181
  const removedSelectors = [];
178
182
  selector = { data: cssTree.parse(cssTree.generate(selector.data), { context: "selector" }) };
179
183
  filterPseudoClasses(selector);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.0.50",
3
+ "version": "1.0.52",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -226,6 +226,7 @@ function initResponse(message) {
226
226
  frameData.content = messageFrameData.content;
227
227
  frameData.baseURI = messageFrameData.baseURI;
228
228
  frameData.title = messageFrameData.title;
229
+ frameData.url = messageFrameData.url;
229
230
  frameData.canvases = messageFrameData.canvases;
230
231
  frameData.fonts = messageFrameData.fonts;
231
232
  frameData.stylesheets = messageFrameData.stylesheets;
@@ -392,6 +393,7 @@ function getFrameData(document, globalThis, windowId, options) {
392
393
  windowId,
393
394
  content,
394
395
  baseURI,
396
+ url: document.location.href,
395
397
  title: document.title,
396
398
  canvases: docData.canvases,
397
399
  fonts: docData.fonts,
@@ -317,6 +317,7 @@
317
317
  return new FontFace(...arguments);
318
318
  };
319
319
  globalThis.FontFace.prototype = FontFace.prototype;
320
+ globalThis.FontFace.toString = function () { return "function FontFace() { [native code] }"; };
320
321
  const deleteFont = document.fonts.delete;
321
322
  document.fonts.delete = function (fontFace) {
322
323
  getDetailObject(fontFace.family).then(detail => dispatchEvent(new CustomEvent(DELETE_FONT_EVENT, { detail })));
@@ -1798,7 +1798,15 @@ class ProcessorHelper {
1798
1798
  if (removeElementIfMissing && content == util.EMPTY_RESOURCE) {
1799
1799
  resourceElement.remove();
1800
1800
  } else if (content !== util.EMPTY_RESOURCE) {
1801
- const forbiddenPrefixFound = PREFIXES_FORBIDDEN_DATA_URI.filter(prefixDataURI => content.startsWith(prefixDataURI)).length;
1801
+ let forbiddenPrefixFound = PREFIXES_FORBIDDEN_DATA_URI.filter(prefixDataURI => content.startsWith(prefixDataURI)).length;
1802
+ if (forbiddenPrefixFound) {
1803
+ forbiddenPrefixFound = await new Promise((resolve) => {
1804
+ const element = options.doc.createElement(resourceElement.tagName);
1805
+ element.setAttribute(attributeName, content);
1806
+ element.onload = () => resolve();
1807
+ element.onerror = () => resolve(true);
1808
+ });
1809
+ }
1802
1810
  if (!forbiddenPrefixFound) {
1803
1811
  const isSVG = content.startsWith(PREFIX_DATA_URI_IMAGE_SVG);
1804
1812
  const maxSizeDuplicateImages = options.maxSizeDuplicateImages || SINGLE_FILE_VARIABLE_MAX_SIZE;
package/single-file.js CHANGED
@@ -55,20 +55,30 @@ async function getPageData(options = {}, initOptions, doc = globalThis.document,
55
55
  helper.initDoc(doc);
56
56
  const preInitializationPromises = [];
57
57
  if (!options.saveRawPage) {
58
- if (!options.removeFrames && frames && globalThis.frames && globalThis.frames.length) {
58
+ if (options.loadDeferredImages) {
59
+ if (options.loadDeferredImagesBeforeFrames) {
60
+ await processors.lazy.process(options);
61
+ } else {
62
+ preInitializationPromises.push(processors.lazy.process(options));
63
+ }
64
+ }
65
+ if (!options.removeFrames && frames && globalThis.frames) {
59
66
  let frameTreePromise;
60
67
  if (options.loadDeferredImages) {
61
- frameTreePromise = new Promise(resolve => globalThis.setTimeout(() => resolve(frames.getAsync(options)), options.loadDeferredImagesMaxIdleTime - frames.TIMEOUT_INIT_REQUEST_MESSAGE));
68
+ frameTreePromise = new Promise(resolve => globalThis.setTimeout(() => resolve(frames.getAsync(options)), options.loadDeferredImagesBeforeFrames ? 0 : options.loadDeferredImagesMaxIdleTime / 2));
62
69
  } else {
63
70
  frameTreePromise = frames.getAsync(options);
64
71
  }
65
- preInitializationPromises.push(frameTreePromise);
66
- }
67
- if (options.loadDeferredImages) {
68
- preInitializationPromises.push(processors.lazy.process(options));
72
+ if (options.loadDeferredImagesBeforeFrames) {
73
+ options.frames = await frameTreePromise;
74
+ } else {
75
+ preInitializationPromises.push(frameTreePromise);
76
+ }
69
77
  }
70
78
  }
71
- [options.frames] = await Promise.all(preInitializationPromises);
79
+ if (!options.loadDeferredImagesBeforeFrames) {
80
+ [,options.frames] = await Promise.all(preInitializationPromises);
81
+ }
72
82
  framesSessionId = options.frames && options.frames.sessionId;
73
83
  }
74
84
  options.doc = doc;