single-file-core 1.5.22 → 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.
|
@@ -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) {
|