|
@@ -1073,18 +1073,18 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
|
|
|
|
|
static async processStylesheet(doc, stylesheetContent, cssRules, baseURI, options, batchRequest) {
|
|
static async processStylesheet(doc, stylesheetContent, cssRules, baseURI, options, batchRequest) {
|
|
|
const urlFunctions = getURLFunctions(cssRules);
|
|
const urlFunctions = getURLFunctions(cssRules);
|
|
|
- const styleResources = Promise.all(urlFunctions.style.map(urlFunction => processURLFunction(urlFunction)));
|
|
|
|
|
- const otherResources = Promise.all(urlFunctions.other.map(urlFunction => processURLFunction(urlFunction, true)));
|
|
|
|
|
- await Promise.all([styleResources, otherResources]);
|
|
|
|
|
|
|
+ await Promise.all([
|
|
|
|
|
+ Promise.all(urlFunctions.style.map(urlFunction => processURLFunction(urlFunction))),
|
|
|
|
|
+ Promise.all(urlFunctions.font.map(urlFunction => processURLFunction(urlFunction, true)))]);
|
|
|
return stylesheetContent;
|
|
return stylesheetContent;
|
|
|
|
|
|
|
|
- async function processURLFunction(urlFunction, processFont) {
|
|
|
|
|
|
|
+ async function processURLFunction(urlFunction, isFont) {
|
|
|
const originalResourceURL = DomUtil.matchURL(urlFunction);
|
|
const originalResourceURL = DomUtil.matchURL(urlFunction);
|
|
|
const resourceURL = DomUtil.normalizeURL(originalResourceURL);
|
|
const resourceURL = DomUtil.normalizeURL(originalResourceURL);
|
|
|
if (!DomUtil.testIgnoredPath(resourceURL)) {
|
|
if (!DomUtil.testIgnoredPath(resourceURL)) {
|
|
|
if (DomUtil.testValidURL(resourceURL, baseURI, options.url)) {
|
|
if (DomUtil.testValidURL(resourceURL, baseURI, options.url)) {
|
|
|
let { content, indexResource, duplicate } = await batchRequest.addURL(resourceURL);
|
|
let { content, indexResource, duplicate } = await batchRequest.addURL(resourceURL);
|
|
|
- const validResource = !processFont || content == EMPTY_DATA_URI || content.startsWith(PREFIX_DATA_URI_VND) || content.startsWith(PREFIX_DATA_URI_IMAGE_SVG) || await DOM.validFont(urlFunction);
|
|
|
|
|
|
|
+ const validResource = !isFont || content == EMPTY_DATA_URI || content.startsWith(PREFIX_DATA_URI_VND) || content.startsWith(PREFIX_DATA_URI_IMAGE_SVG) || await DOM.validFont(urlFunction);
|
|
|
if (!validResource) {
|
|
if (!validResource) {
|
|
|
content = EMPTY_DATA_URI;
|
|
content = EMPTY_DATA_URI;
|
|
|
}
|
|
}
|
|
@@ -1098,7 +1098,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
regExpUrlFunction = DomUtil.getRegExp(urlFunction);
|
|
regExpUrlFunction = DomUtil.getRegExp(urlFunction);
|
|
|
}
|
|
}
|
|
|
if (stylesheetContent.match(regExpUrlFunction)) {
|
|
if (stylesheetContent.match(regExpUrlFunction)) {
|
|
|
- if (duplicate && options.groupDuplicateImages && !processFont) {
|
|
|
|
|
|
|
+ if (duplicate && options.groupDuplicateImages && !isFont) {
|
|
|
stylesheetContent = stylesheetContent.replace(regExpUrlFunction, "var(" + SINGLE_FILE_VARIABLE_NAME_PREFIX + indexResource + ")");
|
|
stylesheetContent = stylesheetContent.replace(regExpUrlFunction, "var(" + SINGLE_FILE_VARIABLE_NAME_PREFIX + indexResource + ")");
|
|
|
DomUtil.insertVariable(doc, indexResource, content, options);
|
|
DomUtil.insertVariable(doc, indexResource, content, options);
|
|
|
} else {
|
|
} else {
|
|
@@ -1109,17 +1109,17 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function getURLFunctions(cssRules, urlFunctions = { style: [], other: [] }) {
|
|
|
|
|
|
|
+ function getURLFunctions(cssRules, urlFunctions = { style: [], font: [] }) {
|
|
|
Array.from(cssRules).forEach(cssRule => {
|
|
Array.from(cssRules).forEach(cssRule => {
|
|
|
if (cssRule.type == CSSRule.MEDIA_RULE) {
|
|
if (cssRule.type == CSSRule.MEDIA_RULE) {
|
|
|
getURLFunctions(cssRule.cssRules, urlFunctions);
|
|
getURLFunctions(cssRule.cssRules, urlFunctions);
|
|
|
- } else if (cssRule.type == CSSRule.STYLE_RULE) {
|
|
|
|
|
- getURLFunctionsRule(cssRule.cssText, urlFunctions.style);
|
|
|
|
|
|
|
+ } else if (cssRule.type == CSSRule.FONT_FACE_RULE) {
|
|
|
|
|
+ getURLFunctionsRule(cssRule.cssText, urlFunctions.font);
|
|
|
} else {
|
|
} else {
|
|
|
- getURLFunctionsRule(cssRule.cssText, urlFunctions.other);
|
|
|
|
|
|
|
+ getURLFunctionsRule(cssRule.cssText, urlFunctions.style);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- return { style: Array.from(urlFunctions.style), other: Array.from(urlFunctions.other) };
|
|
|
|
|
|
|
+ return { style: Array.from(urlFunctions.style), font: Array.from(urlFunctions.font) };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function getURLFunctionsRule(cssText, urlFunctions) {
|
|
function getURLFunctionsRule(cssText, urlFunctions) {
|