single-file-core 1.3.9 → 1.3.11

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
@@ -498,16 +498,18 @@ function getStylesheetsData(doc) {
498
498
  const contents = [];
499
499
  doc.querySelectorAll("style").forEach((styleElement, styleIndex) => {
500
500
  try {
501
- const tempStyleElement = doc.createElement("style");
502
- tempStyleElement.textContent = styleElement.textContent;
503
- doc.body.appendChild(tempStyleElement);
504
- const stylesheet = tempStyleElement.sheet;
505
- tempStyleElement.remove();
506
- const textContentStylesheet = Array.from(stylesheet.cssRules).map(cssRule => cssRule.cssText).join("\n");
507
- const sheetStylesheet = Array.from(styleElement.sheet.cssRules).map(cssRule => cssRule.cssText).join("\n");
508
- if (!stylesheet || textContentStylesheet != sheetStylesheet) {
509
- styleElement.setAttribute(STYLESHEET_ATTRIBUTE_NAME, styleIndex);
510
- contents[styleIndex] = Array.from(styleElement.sheet.cssRules).map(cssRule => cssRule.cssText).join("\n");
501
+ if (!styleElement.sheet.disabled) {
502
+ const tempStyleElement = doc.createElement("style");
503
+ tempStyleElement.textContent = styleElement.textContent;
504
+ doc.body.appendChild(tempStyleElement);
505
+ const stylesheet = tempStyleElement.sheet;
506
+ tempStyleElement.remove();
507
+ const textContentStylesheet = Array.from(stylesheet.cssRules).map(cssRule => cssRule.cssText).join("\n");
508
+ const sheetStylesheet = Array.from(styleElement.sheet.cssRules).map(cssRule => cssRule.cssText).join("\n");
509
+ if (!stylesheet || textContentStylesheet != sheetStylesheet) {
510
+ styleElement.setAttribute(STYLESHEET_ATTRIBUTE_NAME, styleIndex);
511
+ contents[styleIndex] = Array.from(styleElement.sheet.cssRules).map(cssRule => cssRule.cssText).join("\n");
512
+ }
511
513
  }
512
514
  } catch (error) {
513
515
  // ignored
package/core/index.js CHANGED
@@ -860,7 +860,7 @@ class Processor {
860
860
  replacedAttributeValue.forEach(element => {
861
861
  const relValue = element
862
862
  .getAttribute("rel")
863
- .replace(/(preconnect|prerender|dns-prefetch|preload|prefetch|manifest)/g, "")
863
+ .replace(/(preconnect|prerender|dns-prefetch|preload|prefetch|manifest|modulepreload)/g, "")
864
864
  .trim();
865
865
  if (relValue.length) {
866
866
  element.setAttribute("rel", relValue);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.3.9",
3
+ "version": "1.3.11",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -81,20 +81,20 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
81
81
  const zipReader = new zip.ZipReader(blobReader);
82
82
  const entries = await zipReader.getEntries();
83
83
  const options = { password };
84
- let docContent, origDocContent, url, resources = [], indexPages = [];
84
+ let docContent, origDocContent, url, resources = [], indexPages = [], textResources = [];
85
85
  await Promise.all(entries.map(async entry => {
86
86
  const { filename } = entry;
87
87
  let dataWriter, content, textContent, mimeType;
88
88
  const resourceInfo = {};
89
- if (filename.match(REGEXP_MATCH_INDEX)) {
90
- indexPages.push(resourceInfo);
91
- } else {
92
- resources.push(resourceInfo);
93
- }
94
89
  if (!options.password && entry.encrypted) {
95
90
  options.password = prompt("Please enter the password to view the page");
96
91
  }
97
92
  if (filename.match(REGEXP_MATCH_INDEX) || filename.match(REGEXP_MATCH_STYLESHEET) || filename.match(REGEXP_MATCH_SCRIPT)) {
93
+ if (filename.match(REGEXP_MATCH_INDEX)) {
94
+ indexPages.push(resourceInfo);
95
+ } else {
96
+ textResources.push(resourceInfo);
97
+ }
98
98
  dataWriter = new zip.TextWriter();
99
99
  textContent = await entry.getData(dataWriter, options);
100
100
  if (filename.match(REGEXP_MATCH_INDEX)) {
@@ -112,6 +112,7 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
112
112
  }
113
113
  }
114
114
  } else {
115
+ resources.push(resourceInfo);
115
116
  const extension = filename.match(/\.([^.]+)/);
116
117
  if (extension && extension[1] && KNOWN_MIMETYPES[extension[1]]) {
117
118
  mimeType = KNOWN_MIMETYPES[extension[1]];
@@ -137,8 +138,9 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
137
138
  });
138
139
  }));
139
140
  await zipReader.close();
140
- indexPages.sort(sortByFilenameLength);
141
- resources = resources.concat(...indexPages);
141
+ indexPages.sort(sortByFilenameLengthDec);
142
+ textResources.sort(sortByFilenameLengthInc);
143
+ resources = resources.concat(...textResources).concat(...indexPages);
142
144
  for (const resource of resources) {
143
145
  let { textContent, mimeType, filename } = resource;
144
146
  if (textContent !== undefined) {
@@ -203,7 +205,21 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
203
205
  }
204
206
  }
205
207
 
206
- function sortByFilenameLength(resourceLeft, resourceRight) {
207
- return resourceRight.filename.length - resourceLeft.filename.length;
208
+ function sortByFilenameLengthDec(resourceLeft, resourceRight) {
209
+ const lengthDifference = resourceRight.filename.length - resourceLeft.filename.length;
210
+ if (lengthDifference) {
211
+ return lengthDifference;
212
+ } else {
213
+ return resourceRight.filename.localeCompare(resourceLeft.filename);
214
+ }
215
+ }
216
+
217
+ function sortByFilenameLengthInc(resourceLeft, resourceRight) {
218
+ const lengthDifference = resourceLeft.filename.length - resourceRight.filename.length;
219
+ if (lengthDifference) {
220
+ return lengthDifference;
221
+ } else {
222
+ return resourceLeft.filename.localeCompare(resourceRight.filename);
223
+ }
208
224
  }
209
225
  }