single-file-core 1.0.35 → 1.0.37

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.
@@ -142,10 +142,10 @@
142
142
  let singleFileComment = result && result.singleNodeValue;
143
143
  if (singleFileComment && isSingleFileComment(singleFileComment)) {
144
144
  const info = singleFileComment.textContent.split("\n");
145
- const [, , urlData, saveDate, ...infoData] = info;
145
+ const [, , urlData, ...optionalData] = info;
146
146
  const urlMatch = urlData.match(/^ url: (.*) $/);
147
147
  const url = urlMatch && urlMatch[1];
148
- if (url && saveDate) {
148
+ if (url) {
149
149
  let options;
150
150
  if (browser && browser.runtime && browser.runtime.sendMessage) {
151
151
  try {
@@ -157,7 +157,7 @@
157
157
  options = { displayInfobar: true };
158
158
  }
159
159
  if (options.displayInfobar) {
160
- await initInfobar(url, saveDate, infoData);
160
+ await initInfobar(url, optionalData);
161
161
  }
162
162
  }
163
163
  }
@@ -167,19 +167,26 @@
167
167
  return node.nodeType == Node.COMMENT_NODE && node.textContent.includes(SINGLEFILE_COMMENT);
168
168
  }
169
169
 
170
- async function initInfobar(url, saveDate, infoData) {
170
+ async function initInfobar(url, optionalData /* saveDate, infoData */) {
171
171
  let infobarElement = document.querySelector(INFOBAR_TAGNAME);
172
172
  if (!infobarElement) {
173
- saveDate = saveDate.split("saved date: ")[1];
174
- if (infoData && infoData.length > 1) {
175
- let content = infoData[0].split("info: ")[1].trim();
176
- for (let indexLine = 1; indexLine < infoData.length - 1; indexLine++) {
177
- content += "\n" + infoData[indexLine].trim();
173
+ let infoData = "";
174
+ if (optionalData.length) {
175
+ const saveDate = optionalData[0].split("saved date: ")[1];
176
+ if (saveDate) {
177
+ optionalData.shift();
178
+ }
179
+ if (optionalData.length > 1) {
180
+ let content = optionalData[0].split("info: ")[1].trim();
181
+ for (let indexLine = 1; indexLine < optionalData.length - 1; indexLine++) {
182
+ content += "\n" + optionalData[indexLine].trim();
183
+ }
184
+ infoData = content.trim();
185
+ } else {
186
+ infoData = saveDate;
178
187
  }
179
- infoData = content.trim();
180
- } else {
181
- infoData = saveDate;
182
188
  }
189
+ infoData = infoData || "No info";
183
190
  infobarElement = createElement(INFOBAR_TAGNAME, document.body);
184
191
  infobarElement.className = SINGLE_FILE_UI_ELEMENT_CLASS;
185
192
  const shadowRoot = await getShadowRoot(infobarElement);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.0.35",
3
+ "version": "1.0.37",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -117,31 +117,27 @@
117
117
  return function () {
118
118
  const image = new Image(...arguments);
119
119
  const result = new Image(...arguments);
120
- result.__defineSetter__("src", function (value) {
120
+ result.__defineSetter__("src", value => {
121
121
  image.src = value;
122
122
  dispatchEvent(new CustomEvent(LOAD_IMAGE_EVENT, { detail: image.src }));
123
123
  });
124
- result.__defineGetter__("src", function () {
125
- return image.src;
126
- });
127
- result.__defineSetter__("srcset", function (value) {
124
+ result.__defineGetter__("src", () => image.src);
125
+ result.__defineSetter__("srcset", value => {
128
126
  dispatchEvent(new CustomEvent(LOAD_IMAGE_EVENT));
129
127
  image.srcset = value;
130
128
  });
131
- result.__defineGetter__("srcset", function () {
132
- return image.srcset;
133
- });
129
+ result.__defineGetter__("srcset", () => image.srcset);
134
130
  result.__defineGetter__("height", () => image.height);
135
131
  result.__defineGetter__("width", () => image.width);
136
132
  result.__defineGetter__("naturalHeight", () => image.naturalHeight);
137
133
  result.__defineGetter__("naturalWidth", () => image.naturalWidth);
134
+ if (image.decode) {
135
+ result.__defineGetter__("decode", () => () => image.decode());
136
+ }
138
137
  image.onload = image.onloadend = image.onerror = event => {
139
138
  dispatchEvent(new CustomEvent(IMAGE_LOADED_EVENT, { detail: image.src }));
140
139
  result.dispatchEvent(new Event(event.type, event));
141
140
  };
142
- if (image.decode) {
143
- result.decode = () => image.decode();
144
- }
145
141
  return result;
146
142
  };
147
143
  });
@@ -69,10 +69,14 @@ export {
69
69
  async function process(options) {
70
70
  if (document.documentElement) {
71
71
  timeouts.clear();
72
- const maxScrollY = Math.max(document.documentElement.scrollHeight - (document.documentElement.clientHeight * 1.5), 0);
73
- const maxScrollX = Math.max(document.documentElement.scrollWidth - (document.documentElement.clientWidth * 1.5), 0);
74
- if (globalThis.scrollY <= maxScrollY && globalThis.scrollX <= maxScrollX) {
75
- return triggerLazyLoading(options);
72
+ const bodyHeight = (document.body && document.body.scrollHeight) || document.documentElement.scrollHeight;
73
+ const bodyWidth = (document.body && document.body.scrollWidth) || document.documentElement.scrollWidth;
74
+ if (bodyHeight > globalThis.innerHeight || bodyWidth > globalThis.innerWidth) {
75
+ const maxScrollY = Math.max(bodyHeight - (globalThis.innerHeight * 1.5), 0);
76
+ const maxScrollX = Math.max(bodyWidth - (globalThis.innerWidth * 1.5), 0);
77
+ if (globalThis.scrollY < maxScrollY || globalThis.scrollX < maxScrollX) {
78
+ return triggerLazyLoading(options);
79
+ }
76
80
  }
77
81
  }
78
82
  }
@@ -484,7 +484,7 @@ class Processor {
484
484
  const infobarContent = (this.options.infobarContent || "").replace(/\\n/g, "\n").replace(/\\t/g, "\t");
485
485
  const commentNode = this.doc.createComment("\n " + (this.options.useLegacyCommentHeader ? util.COMMENT_HEADER_LEGACY : util.COMMENT_HEADER) +
486
486
  " \n url: " + infobarURL +
487
- " \n saved date: " + infobarSaveDate +
487
+ (this.options.removeSavedDate ? " " : " \n saved date: " + infobarSaveDate) +
488
488
  (infobarContent ? " \n info: " + infobarContent : "") + "\n");
489
489
  this.doc.documentElement.insertBefore(commentNode, this.doc.documentElement.firstChild);
490
490
  }
@@ -367,7 +367,9 @@ function collectComments(content, comments) {
367
367
  */
368
368
 
369
369
  // const REGEXP_EMPTY_RULES = /[^};{/]+\{\}/g;
370
- const REGEXP_PRESERVE_STRING = /"([^\\"]|\\.|\\)*"/g;
370
+ const REGEXP_PRESERVE_STRING1 = /"([^\\"])*"/g;
371
+ const REGEXP_PRESERVE_STRING1_BIS = /"(\\.)*"/g;
372
+ const REGEXP_PRESERVE_STRING1_TER = /"(\\)*"/g;
371
373
  const REGEXP_PRESERVE_STRING2 = /'([^\\']|\\.|\\)*'/g;
372
374
  const REGEXP_MINIFY_ALPHA = /progid:DXImageTransform.Microsoft.Alpha\(Opacity=/gi;
373
375
  const REGEXP_PRESERVE_TOKEN1 = /\r\n/g;
@@ -444,7 +446,9 @@ function processString(content = "", options = defaultOptions) {
444
446
  content = collectComments(content, comments);
445
447
 
446
448
  // preserve strings so their content doesn't get accidentally minified
447
- preserveString(REGEXP_PRESERVE_STRING);
449
+ preserveString(REGEXP_PRESERVE_STRING1);
450
+ preserveString(REGEXP_PRESERVE_STRING1_BIS);
451
+ preserveString(REGEXP_PRESERVE_STRING1_TER);
448
452
  preserveString(REGEXP_PRESERVE_STRING2);
449
453
 
450
454
  function preserveString(pattern) {
@@ -562,8 +566,12 @@ function processString(content = "", options = defaultOptions) {
562
566
  // remove the spaces before the things that should not have spaces before them.
563
567
  // but, be careful not to turn 'p :link {...}' into 'p:link{...}'
564
568
  // swap out any pseudo-class colons with the token, and then swap back.
565
- pattern = REGEXP_REMOVE_SPACES;
566
- content = content.replace(pattern, token => token.replace(REGEXP_COLUMN, "___PSEUDOCLASSCOLON___"));
569
+ try {
570
+ pattern = REGEXP_REMOVE_SPACES;
571
+ content = content.replace(pattern, token => token.replace(REGEXP_COLUMN, "___PSEUDOCLASSCOLON___"));
572
+ } catch (_error) {
573
+ // ignored
574
+ }
567
575
 
568
576
  // remove spaces before the things that should not have spaces before them.
569
577
  content = content.replace(REGEXP_REMOVE_SPACES2, "$1");