single-file-core 1.0.23 → 1.0.25

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.
@@ -36,7 +36,9 @@ class MatchedRules {
36
36
  this.mediaAllInfo = createMediaInfo(MEDIA_ALL);
37
37
  const matchedElementsCache = new Map();
38
38
  let sheetIndex = 0;
39
- const workStyleElement = doc.createElement("style");
39
+ const workStyleSheet = doc.createElement("style");
40
+ doc.body.appendChild(workStyleSheet);
41
+ const workStyleElement = doc.createElement("span");
40
42
  doc.body.appendChild(workStyleElement);
41
43
  stylesheets.forEach(stylesheetInfo => {
42
44
  if (!stylesheetInfo.scoped) {
@@ -45,9 +47,9 @@ class MatchedRules {
45
47
  if (stylesheetInfo.mediaText && stylesheetInfo.mediaText != MEDIA_ALL) {
46
48
  const mediaInfo = createMediaInfo(stylesheetInfo.mediaText);
47
49
  this.mediaAllInfo.medias.set("style-" + sheetIndex + "-" + stylesheetInfo.mediaText, mediaInfo);
48
- getMatchedElementsRules(doc, cssRules, mediaInfo, sheetIndex, styles, matchedElementsCache, workStyleElement);
50
+ getMatchedElementsRules(doc, cssRules, mediaInfo, sheetIndex, styles, matchedElementsCache, workStyleSheet);
49
51
  } else {
50
- getMatchedElementsRules(doc, cssRules, this.mediaAllInfo, sheetIndex, styles, matchedElementsCache, workStyleElement);
52
+ getMatchedElementsRules(doc, cssRules, this.mediaAllInfo, sheetIndex, styles, matchedElementsCache, workStyleSheet);
51
53
  }
52
54
  }
53
55
  }
@@ -64,7 +66,8 @@ class MatchedRules {
64
66
  startTime = Date.now();
65
67
  log(" -- STARTED computeCascade");
66
68
  }
67
- computeCascade(this.mediaAllInfo, [], this.mediaAllInfo, workStyleElement);
69
+ computeCascade(this.mediaAllInfo, [], this.mediaAllInfo, workStyleSheet, workStyleElement);
70
+ workStyleSheet.remove();
68
71
  workStyleElement.remove();
69
72
  if (DEBUG) {
70
73
  log(" -- ENDED computeCascade", Date.now() - startTime);
@@ -222,9 +225,9 @@ function addRule(element, selectorInfo, styles) {
222
225
  elementInfo.push(selectorInfo);
223
226
  }
224
227
 
225
- function computeCascade(mediaInfo, parentMediaInfo, mediaAllInfo, workStylesheet) {
228
+ function computeCascade(mediaInfo, parentMediaInfo, mediaAllInfo, workStylesheet, workStyleElement) {
226
229
  mediaInfo.elements.forEach((elementInfo/*, element*/) =>
227
- getDeclarationsInfo(elementInfo, workStylesheet/*, element*/).forEach((declarationsInfo, property) => {
230
+ getDeclarationsInfo(elementInfo, workStylesheet, workStyleElement/*, element*/).forEach((declarationsInfo, property) => {
228
231
  if (declarationsInfo.selectorInfo.ruleInfo || mediaInfo == mediaAllInfo) {
229
232
  let info;
230
233
  if (declarationsInfo.selectorInfo.ruleInfo) {
@@ -249,10 +252,10 @@ function computeCascade(mediaInfo, parentMediaInfo, mediaAllInfo, workStylesheet
249
252
  }
250
253
  }));
251
254
  delete mediaInfo.elements;
252
- mediaInfo.medias.forEach(childMediaInfo => computeCascade(childMediaInfo, [mediaInfo, ...parentMediaInfo], mediaAllInfo, workStylesheet));
255
+ mediaInfo.medias.forEach(childMediaInfo => computeCascade(childMediaInfo, [mediaInfo, ...parentMediaInfo], mediaAllInfo, workStylesheet, workStyleElement));
253
256
  }
254
257
 
255
- function getDeclarationsInfo(elementInfo, workStylesheet/*, element*/) {
258
+ function getDeclarationsInfo(elementInfo, workStylesheet, workStyleElement/*, element*/) {
256
259
  const declarationsInfo = new Map();
257
260
  const processedProperties = new Set();
258
261
  elementInfo.forEach(selectorInfo => {
@@ -262,17 +265,17 @@ function getDeclarationsInfo(elementInfo, workStylesheet/*, element*/) {
262
265
  } else {
263
266
  declarations = selectorInfo.ruleInfo.ruleData.block.children;
264
267
  }
265
- processDeclarations(declarationsInfo, declarations, selectorInfo, processedProperties, workStylesheet);
268
+ processDeclarations(declarationsInfo, declarations, selectorInfo, processedProperties, workStylesheet, workStyleElement);
266
269
  });
267
270
  return declarationsInfo;
268
271
  }
269
272
 
270
- function processDeclarations(declarationsInfo, declarations, selectorInfo, processedProperties, workStylesheet) {
273
+ function processDeclarations(declarationsInfo, declarations, selectorInfo, processedProperties, workStylesheet, workStyleElement) {
271
274
  for (let declaration = declarations.tail; declaration; declaration = declaration.prev) {
272
275
  const declarationData = declaration.data;
273
276
  const declarationText = cssTree.generate(declarationData);
274
277
  if (declarationData.type == "Declaration" &&
275
- (declarationText.match(REGEXP_VENDOR_IDENTIFIER) || !processedProperties.has(declarationData.property) || declarationData.important) && !invalidDeclaration(declarationText, workStylesheet)) {
278
+ (declarationText.match(REGEXP_VENDOR_IDENTIFIER) || !processedProperties.has(declarationData.property) || declarationData.important) && !invalidDeclaration(declarationText, workStyleElement)) {
276
279
  const declarationInfo = declarationsInfo.get(declarationData);
277
280
  if (!declarationInfo || (declarationData.important && !declarationInfo.important)) {
278
281
  declarationsInfo.set(declarationData, { selectorInfo, important: declarationData.important });
@@ -284,10 +287,10 @@ function processDeclarations(declarationsInfo, declarations, selectorInfo, proce
284
287
  }
285
288
  }
286
289
 
287
- function invalidDeclaration(declarationText, workStylesheet) {
290
+ function invalidDeclaration(declarationText, workStyleElement) {
288
291
  let invalidDeclaration;
289
- workStylesheet.textContent = "single-file-declaration { " + declarationText + "}";
290
- if (workStylesheet.sheet && !workStylesheet.sheet.cssRules[0].style.length) {
292
+ workStyleElement.style = declarationText;
293
+ if (!workStyleElement.style.length) {
291
294
  if (!declarationText.match(REGEXP_VENDOR_IDENTIFIER)) {
292
295
  invalidDeclaration = true;
293
296
  }
@@ -94,7 +94,7 @@ function serializeTextNode(textNode) {
94
94
  parentTagName = parentNode.tagName.toLowerCase();
95
95
  }
96
96
  if (!parentTagName || TEXT_NODE_TAGS.includes(parentTagName)) {
97
- if (parentTagName == "script") {
97
+ if (parentTagName == "script" || parentTagName == "style") {
98
98
  return textNode.textContent.replace(/<\//gi, "<\\/").replace(/\/>/gi, "\\/>");
99
99
  }
100
100
  return textNode.textContent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -533,7 +533,7 @@ class Processor {
533
533
  if (!this.options.backgroundSave) {
534
534
  filename = filename.replace(/\//g, replacementCharacter);
535
535
  }
536
- if (!this.options.saveToGDrive && !this.options.saveToGitHub && !this.options.saveWithCompanion && !this.options.saveWithWebDAV &&
536
+ if (!this.options.keepFilename &&
537
537
  ((this.options.filenameMaxLengthUnit == "bytes" && util.getContentSize(filename) > this.options.filenameMaxLength) || (filename.length > this.options.filenameMaxLength))) {
538
538
  const extensionMatch = filename.match(/(\.[^.]{3,4})$/);
539
539
  const extension = extensionMatch && extensionMatch[0] && extensionMatch[0].length > 1 ? extensionMatch[0] : "";
@@ -1854,10 +1854,6 @@ class ProcessorHelper {
1854
1854
  if (testValidURL(resourceURL)) {
1855
1855
  let { content, indexResource, duplicate } = await batchRequest.addURL(resourceURL,
1856
1856
  { asBinary: true, expectedType, groupDuplicates: options.groupDuplicateImages && resourceElement.tagName == "IMG" && attributeName == "src" });
1857
- if (resourceURL.includes("openbenchmarking.org/embed.php")) {
1858
- debugger
1859
- }
1860
-
1861
1857
  if (originURL) {
1862
1858
  if (content == util.EMPTY_RESOURCE) {
1863
1859
  try {