single-file-core 1.2.10 → 1.2.12

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.
@@ -38,12 +38,15 @@ export {
38
38
 
39
39
  function process(stylesheets) {
40
40
  const stats = { processed: 0, discarded: 0 };
41
- stylesheets.forEach((stylesheetInfo, element) => {
41
+ stylesheets.forEach((stylesheetInfo, key) => {
42
42
  if (matchesMediaType(stylesheetInfo.mediaText || MEDIA_ALL, MEDIA_SCREEN) && stylesheetInfo.stylesheet.children) {
43
43
  const removedRules = processRules(stylesheetInfo.stylesheet.children, stats);
44
44
  removedRules.forEach(({ cssRules, cssRule }) => cssRules.remove(cssRule));
45
45
  } else {
46
- stylesheets.delete(element);
46
+ stylesheets.delete(key);
47
+ if (key.element) {
48
+ key.element.remove();
49
+ }
47
50
  }
48
51
  });
49
52
  return stats;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.2.10",
3
+ "version": "1.2.12",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -58,7 +58,7 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
58
58
  const REGEXP_MATCH_SCRIPT = /scripts\/[0-9]+\.js/;
59
59
  const REGEXP_MATCH_ROOT_INDEX = /^([0-9_]+\/)?index\.html$/;
60
60
  const REGEXP_MATCH_INDEX = /index\.html$/;
61
- const REGEXP_ESCAPE = /([{}()^$&.*?/+|[\\\\]|\]|-)/g;
61
+ const REGEXP_MATCH_FRAMES = /frames\//;
62
62
  const CHARSET_UTF8 = ";charset=utf-8";
63
63
  if (Array.isArray(content)) {
64
64
  content = new Blob([new Uint8Array(content)]);
@@ -87,7 +87,7 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
87
87
  mimeType = "text/javascript" + CHARSET_UTF8;
88
88
  }
89
89
  if (textContent !== undefined) {
90
- content = await getDataURI(textContent, mimeType);
90
+ content = noBlobURL ? await getDataURI(textContent, mimeType) : URL.createObjectURL(new Blob([textContent], { type: mimeType }));
91
91
  } else {
92
92
  content = "data:text/plain,";
93
93
  }
@@ -99,7 +99,7 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
99
99
  } else {
100
100
  mimeType = "application/octet-stream";
101
101
  }
102
- if (filename.match(/frames\//) || noBlobURL) {
102
+ if (filename.match(REGEXP_MATCH_FRAMES) || noBlobURL) {
103
103
  content = await entry.getData(new zip.Data64URIWriter(mimeType), options);
104
104
  } else {
105
105
  const blob = await entry.getData(new zip.BlobWriter(mimeType), options);
@@ -129,16 +129,19 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
129
129
  if (filename.startsWith(prefixPath) && filename != resourceFilename) {
130
130
  const relativeFilename = filename.substring(prefixPath.length);
131
131
  if (!relativeFilename.match(/manifest\.json$/)) {
132
- const searchRegExp = new RegExp(relativeFilename.replace(REGEXP_ESCAPE, "\\$1"), "g");
133
- const position = textContent.search(searchRegExp);
132
+ const position = textContent.indexOf(relativeFilename);
134
133
  if (position != -1) {
135
134
  parentResources.push(resourceFilename);
136
- textContent = textContent.replace(searchRegExp, content);
135
+ textContent = textContent.replaceAll(relativeFilename, content);
137
136
  }
138
137
  }
139
138
  }
140
139
  }));
141
- resource.content = await getDataURI(textContent, mimeType);
140
+ if (filename.match(REGEXP_MATCH_INDEX) || filename.match(REGEXP_MATCH_FRAMES) || noBlobURL) {
141
+ resource.content = await getDataURI(textContent, mimeType);
142
+ } else {
143
+ resource.content = URL.createObjectURL(new Blob([textContent], { type: mimeType }));
144
+ }
142
145
  resource.textContent = textContent;
143
146
  }
144
147
  if (filename.match(REGEXP_MATCH_INDEX)) {
@@ -158,7 +161,7 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
158
161
  const reader = new FileReader();
159
162
  reader.readAsDataURL(new Blob([textContent], { type: mimeType }));
160
163
  return new Promise((resolve, reject) => {
161
- reader.onload = () => resolve(reader.result);
164
+ reader.onload = () => resolve(reader.result.replace(CHARSET_UTF8, ""));
162
165
  reader.onerror = reject;
163
166
  });
164
167
  }
@@ -24,6 +24,9 @@
24
24
  import * as serializer from "./modules/html-serializer.js";
25
25
  import * as infobar from "./core/infobar.js";
26
26
  import { getInstance } from "./core/util.js";
27
+ import * as zip from "./vendor/zip/zip.js";
28
+ import { extract } from "./processors/compression/compression-extract.js";
29
+ import { display } from "./processors/compression/compression-display.js";
27
30
 
28
31
  const util = getInstance();
29
32
  const helper = {
@@ -42,6 +45,9 @@ const helper = {
42
45
  displayIcon(doc, useShadowRoot) {
43
46
  return infobar.displayIcon(doc, useShadowRoot);
44
47
  },
48
+ zip,
49
+ extract,
50
+ display,
45
51
  INFOBAR_TAGNAME: infobar.INFOBAR_TAGNAME
46
52
  };
47
53