single-file-core 1.5.21 → 1.5.23

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.
package/core/index.js CHANGED
@@ -1122,8 +1122,6 @@ class Processor {
1122
1122
  // ignored
1123
1123
  }
1124
1124
  if (resolvedURL) {
1125
- const url = normalizeURL(this.options.url);
1126
- resolvedURL = resolvedURL.substring(url.length);
1127
1125
  try {
1128
1126
  element.setAttribute("href", resolvedURL);
1129
1127
  } catch (error) {
@@ -44,6 +44,7 @@ const SINGLE_FILE_VARIABLE_MAX_SIZE = 512 * 1024;
44
44
  const EMPTY_URL_SOURCE = /^url\(["']?data:[^,]*,?["']?\)/;
45
45
  const LOCAL_SOURCE = "local(";
46
46
  const FONT_MAX_LOAD_DELAY = 5000;
47
+ const DUPLICATE_STYLESHEET_ATTRIBUTE_NAME = "data-sf-duplicate-stylesheet-ref";
47
48
 
48
49
  let util;
49
50
 
@@ -115,6 +116,16 @@ function getProcessorHelperClass(utilInstance) {
115
116
  const styleSheetRefIndex = options.inlineStylesheetsRefs.get(styleElement);
116
117
  if (styleSheetRefIndex === undefined) {
117
118
  styleElement.textContent = this.generateStylesheetContent(stylesheetInfo.stylesheet, options);
119
+ } else if (options.groupDuplicateStylesheets) {
120
+ if (!doc.querySelector("style[" + DUPLICATE_STYLESHEET_ATTRIBUTE_NAME + "=\"" + styleSheetRefIndex + "\"]")) {
121
+ const styleElement = doc.createElement("style");
122
+ styleElement.textContent = options.inlineStylesheets.get(styleSheetRefIndex);
123
+ styleElement.setAttribute("media", "not all");
124
+ styleElement.setAttribute(DUPLICATE_STYLESHEET_ATTRIBUTE_NAME, styleSheetRefIndex);
125
+ doc.head.appendChild(styleElement);
126
+ }
127
+ styleElement.textContent = "/* */";
128
+ styleElement.setAttribute("onload", "this.textContent=document.querySelector('style[" + DUPLICATE_STYLESHEET_ATTRIBUTE_NAME + "=\"" + styleSheetRefIndex + "\"]').textContent;this.removeAttribute(\"onload\")");
118
129
  } else {
119
130
  styleElement.textContent = options.inlineStylesheets.get(styleSheetRefIndex);
120
131
  }
@@ -125,6 +136,11 @@ function getProcessorHelperClass(utilInstance) {
125
136
  styleElement.remove();
126
137
  }
127
138
  });
139
+ if (options.groupDuplicateStylesheets) {
140
+ const scriptElement = doc.createElement("script");
141
+ scriptElement.textContent = "document.currentScript.remove();addEventListener(\"load\",()=>document.querySelectorAll(\"style[" + DUPLICATE_STYLESHEET_ATTRIBUTE_NAME + "]\").forEach(e=>e.remove()))";
142
+ doc.body.appendChild(scriptElement);
143
+ }
128
144
  doc.querySelectorAll("link[rel*=stylesheet]").forEach(linkElement => {
129
145
  const stylesheetInfo = stylesheets.get(linkElement);
130
146
  if (stylesheetInfo) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.5.21",
3
+ "version": "1.5.23",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",