single-file-core 1.2.28 → 1.2.30

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.
@@ -443,10 +443,7 @@ class ProcessorHelperCommon {
443
443
  const key = this.getFontKey(ruleData);
444
444
  const fontInfo = fontsDetails.fonts.get(key);
445
445
  if (fontInfo) {
446
- const processed = await this.processFontFaceRule(ruleData, fontInfo, fonts, fontTests, stats);
447
- if (processed) {
448
- fontsDetails.fonts.delete(key);
449
- }
446
+ await this.processFontFaceRule(ruleData, fontInfo, fonts, fontTests, stats);
450
447
  } else {
451
448
  removedRules.push(cssRule);
452
449
  }
@@ -481,7 +478,12 @@ class ProcessorHelperCommon {
481
478
  if (src) {
482
479
  const fontSources = src.match(REGEXP_URL_FUNCTION);
483
480
  if (fontSources) {
484
- fontSources.forEach(source => fontInfo.unshift(source));
481
+ fontSources.forEach(source => {
482
+ if (fontInfo.includes(source)) {
483
+ fontInfo.splice(fontInfo.indexOf(source), 1);
484
+ }
485
+ fontInfo.unshift(source);
486
+ });
485
487
  }
486
488
  }
487
489
  }
@@ -557,9 +557,6 @@ function getProcessorHelperClass(utilInstance) {
557
557
  catch (error) {
558
558
  // ignored
559
559
  }
560
- return true;
561
- } else {
562
- return false;
563
560
  }
564
561
  }
565
562
  };
@@ -91,7 +91,9 @@ function getProcessorHelperClass(utilInstance) {
91
91
  }
92
92
 
93
93
  replaceStylesheets(doc, stylesheets, options, resources) {
94
- for (const [key, stylesheetInfo] of stylesheets) {
94
+ const entries = Array.from(stylesheets);
95
+ entries.reverse();
96
+ for (const [key, stylesheetInfo] of entries) {
95
97
  if (key.urlNode) {
96
98
  const name = "stylesheet_" + resources.stylesheets.size + ".css";
97
99
  if (!isDataURL(stylesheetInfo.url) && options.saveOriginalURLs) {
@@ -100,10 +102,7 @@ function getProcessorHelperClass(utilInstance) {
100
102
  key.urlNode.value = name;
101
103
  }
102
104
  resources.stylesheets.set(resources.stylesheets.size, { name, content: this.generateStylesheetContent(stylesheetInfo.stylesheet, options), url: stylesheetInfo.url });
103
- }
104
- }
105
- for (const [key, stylesheetInfo] of stylesheets) {
106
- if (key.element) {
105
+ } else {
107
106
  if (key.element.tagName.toUpperCase() == "LINK") {
108
107
  const linkElement = key.element;
109
108
  const name = "stylesheet_" + resources.stylesheets.size + ".css";
@@ -485,7 +484,6 @@ function getProcessorHelperClass(utilInstance) {
485
484
  catch (error) {
486
485
  // ignored
487
486
  }
488
- return true;
489
487
  }
490
488
  }
491
489
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.2.28",
3
+ "version": "1.2.30",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -80,7 +80,7 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
80
80
  const zipReader = new zip.ZipReader(blobReader);
81
81
  const entries = await zipReader.getEntries();
82
82
  const options = { password };
83
- let docContent, origDocContent, url, resources = [];
83
+ let docContent, origDocContent, url, resources = [], indexPages = [];
84
84
  await Promise.all(entries.map(async entry => {
85
85
  const { filename } = entry;
86
86
  let dataWriter, content, textContent, mimeType;
@@ -119,10 +119,19 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
119
119
  }
120
120
  }
121
121
  const name = entry.filename.match(/^([0-9_]+\/)?(.*)$/)[2];
122
- resources.push({ filename: entry.filename, name, url: entry.comment, content, mimeType, textContent, parentResources: [] });
122
+ const resourceInfo = { filename: entry.filename, name, url: entry.comment, content, mimeType, textContent, parentResources: [] };
123
+ if (filename.match(REGEXP_MATCH_INDEX)) {
124
+ indexPages.push(resourceInfo);
125
+ } else {
126
+ resources.push(resourceInfo);
127
+ }
123
128
  }));
124
129
  await zipReader.close();
125
- resources = resources.sort((resourceLeft, resourceRight) => resourceRight.filename.length - resourceLeft.filename.length);
130
+ resources.reverse();
131
+ resources.sort(sortByFilenameLength);
132
+ indexPages.sort(sortByFilenameLength);
133
+ resources.sort((resourceLeft, resourceRight) => resourceRight.textContent ? -1 : resourceLeft.textContent ? 1 : 0);
134
+ resources = resources.concat(...indexPages);
126
135
  for (const resource of resources) {
127
136
  let { textContent, mimeType, filename } = resource;
128
137
  if (textContent !== undefined) {
@@ -186,4 +195,8 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
186
195
  return string.replace(searchRegExp, replacement);
187
196
  }
188
197
  }
198
+
199
+ function sortByFilenameLength(resourceLeft, resourceRight) {
200
+ return resourceRight.filename.length - resourceLeft.filename.length;
201
+ }
189
202
  }