single-file-core 1.2.27 → 1.2.29

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.
@@ -105,12 +105,12 @@ class ProcessorHelperCommon {
105
105
  this.processXLinks(doc.querySelectorAll("use"), doc, baseURI, options, batchRequest),
106
106
  this.processSrcset(doc.querySelectorAll("img[srcset], source[srcset]"), baseURI, options, resources, batchRequest)
107
107
  ]);
108
- resourcePromises.push(this.processAttribute(doc.querySelectorAll("object[data*=\".pdf\"]"), "data", baseURI, options, null, resources, batchRequest, styles));
109
- resourcePromises.push(this.processAttribute(doc.querySelectorAll("embed[src*=\".pdf\"]"), "src", baseURI, options, null, resources, batchRequest, styles));
110
- resourcePromises.push(this.processAttribute(doc.querySelectorAll("audio[src], audio > source[src]"), "src", baseURI, options, "audio", resources, batchRequest, styles));
111
- resourcePromises.push(this.processAttribute(doc.querySelectorAll("video[src], video > source[src]"), "src", baseURI, options, "video", resources, batchRequest, styles));
112
- resourcePromises.push(this.processAttribute(doc.querySelectorAll("audio track[src], video track[src]"), "src", baseURI, options, null, resources, batchRequest, styles));
113
- resourcePromises.push(this.processAttribute(doc.querySelectorAll("model[src]"), "src", baseURI, options, null, resources, batchRequest, styles));
108
+ resourcePromises.push(this.processAttribute(doc.querySelectorAll("object[data*=\".pdf\"]"), "data", baseURI, options, null, resources, false, batchRequest, styles));
109
+ resourcePromises.push(this.processAttribute(doc.querySelectorAll("embed[src*=\".pdf\"]"), "src", baseURI, options, null, resources, false, batchRequest, styles));
110
+ resourcePromises.push(this.processAttribute(doc.querySelectorAll("audio[src], audio > source[src]"), "src", baseURI, options, "audio", resources, false, batchRequest, styles));
111
+ resourcePromises.push(this.processAttribute(doc.querySelectorAll("video[src], video > source[src]"), "src", baseURI, options, "video", resources, false, batchRequest, styles));
112
+ resourcePromises.push(this.processAttribute(doc.querySelectorAll("audio track[src], video track[src]"), "src", baseURI, options, null, resources, false, batchRequest, styles));
113
+ resourcePromises.push(this.processAttribute(doc.querySelectorAll("model[src]"), "src", baseURI, options, null, resources, false, batchRequest, styles));
114
114
  await Promise.all(resourcePromises);
115
115
  if (options.saveFavicon) {
116
116
  this.processShortcutIcons(doc);
@@ -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
  };
@@ -485,7 +485,6 @@ function getProcessorHelperClass(utilInstance) {
485
485
  catch (error) {
486
486
  // ignored
487
487
  }
488
- return true;
489
488
  }
490
489
  }
491
490
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.2.27",
3
+ "version": "1.2.29",
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,18 @@ 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.sort(sortByFilenameLength);
131
+ indexPages.sort(sortByFilenameLength);
132
+ resources.sort((resourceLeft, resourceRight) => resourceRight.textContent ? -1 : resourceLeft.textContent ? 1 : 0);
133
+ resources = resources.concat(...indexPages);
126
134
  for (const resource of resources) {
127
135
  let { textContent, mimeType, filename } = resource;
128
136
  if (textContent !== undefined) {
@@ -186,4 +194,8 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
186
194
  return string.replace(searchRegExp, replacement);
187
195
  }
188
196
  }
197
+
198
+ function sortByFilenameLength(resourceLeft, resourceRight) {
199
+ return resourceRight.filename.length - resourceLeft.filename.length;
200
+ }
189
201
  }