|
|
@@ -396,7 +396,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
constructor(options, batchRequest) {
|
|
|
this.options = options;
|
|
|
this.stats = new Stats(options);
|
|
|
- this.baseURI = Util.normalizeURL(options.baseURI || options.url);
|
|
|
+ this.baseURI = normalizeURL(options.baseURI || options.url);
|
|
|
this.batchRequest = batchRequest;
|
|
|
this.stylesheets = new Map();
|
|
|
this.styles = new Map();
|
|
|
@@ -445,7 +445,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
}
|
|
|
this.workStyleElement = this.doc.createElement("style");
|
|
|
this.doc.body.appendChild(this.workStyleElement);
|
|
|
- this.onEventAttributeNames = Util.getOnEventAttributeNames(this.doc);
|
|
|
+ this.onEventAttributeNames = getOnEventAttributeNames(this.doc);
|
|
|
}
|
|
|
|
|
|
finalize() {
|
|
|
@@ -839,7 +839,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
resolveHrefs() {
|
|
|
this.doc.querySelectorAll("a[href], area[href], link[href]").forEach(element => {
|
|
|
const href = element.getAttribute("href").trim();
|
|
|
- if (!Util.testIgnoredPath(href)) {
|
|
|
+ if (!testIgnoredPath(href)) {
|
|
|
let resolvedURL;
|
|
|
try {
|
|
|
resolvedURL = util.resolveURL(href, this.options.baseURI || this.options.url);
|
|
|
@@ -847,7 +847,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
// ignored
|
|
|
}
|
|
|
if (resolvedURL) {
|
|
|
- const url = Util.normalizeURL(this.options.url);
|
|
|
+ const url = normalizeURL(this.options.url);
|
|
|
if (resolvedURL.startsWith(url + "#") && !resolvedURL.startsWith(url + "#!") && !this.options.resolveFragmentIdentifierURLs) {
|
|
|
resolvedURL = resolvedURL.substring(url.length);
|
|
|
}
|
|
|
@@ -923,7 +923,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
}
|
|
|
let stylesheet;
|
|
|
try {
|
|
|
- stylesheet = cssTree.parse(Util.removeCssComments(stylesheetContent));
|
|
|
+ stylesheet = cssTree.parse(removeCssComments(stylesheetContent));
|
|
|
} catch (error) {
|
|
|
// ignored
|
|
|
}
|
|
|
@@ -1169,7 +1169,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
} catch (error) {
|
|
|
// ignored
|
|
|
}
|
|
|
- if (Util.testValidURL(resourceURL)) {
|
|
|
+ if (testValidURL(resourceURL)) {
|
|
|
this.stats.add("processed", "scripts", 1);
|
|
|
const content = await util.getContent(resourceURL, {
|
|
|
asBinary: true,
|
|
|
@@ -1178,7 +1178,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
maxResourceSizeEnabled: this.options.maxResourceSizeEnabled,
|
|
|
frameId: this.options.windowId
|
|
|
});
|
|
|
- content.data = Util.getUpdatedResourceContent(resourceURL, content, this.options);
|
|
|
+ content.data = getUpdatedResourceContent(resourceURL, content, this.options);
|
|
|
if (element.tagName == "SCRIPT") {
|
|
|
element.setAttribute("src", content.data);
|
|
|
if (element.getAttribute("async") == "" || element.getAttribute("async") == "async" || element.getAttribute(util.ASYNC_SCRIPT_ATTRIBUTE_NAME) == "") {
|
|
|
@@ -1404,55 +1404,55 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
static async evalTemplate(template = "", options, content, dontReplaceSlash) {
|
|
|
const date = options.saveDate;
|
|
|
const url = util.parseURL(options.saveUrl);
|
|
|
- template = await Util.evalTemplateVariable(template, "page-title", () => options.title || "No title", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "page-heading", () => options.info.heading || "No heading", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "page-language", () => options.info.lang || "No language", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "page-description", () => options.info.description || "No description", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "page-author", () => options.info.author || "No author", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "page-creator", () => options.info.creator || "No creator", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "page-publisher", () => options.info.publisher || "No publisher", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "datetime-iso", () => date.toISOString(), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "date-iso", () => date.toISOString().split("T")[0], dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "time-iso", () => date.toISOString().split("T")[1].split("Z")[0], dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "date-locale", () => date.toLocaleDateString(), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "time-locale", () => date.toLocaleTimeString(), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "day-locale", () => String(date.getDate()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "month-locale", () => String(date.getMonth() + 1).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "year-locale", () => String(date.getFullYear()), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "datetime-locale", () => date.toLocaleString(), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "datetime-utc", () => date.toUTCString(), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "day-utc", () => String(date.getUTCDate()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "month-utc", () => String(date.getUTCMonth() + 1).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "year-utc", () => String(date.getUTCFullYear()), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "hours-locale", () => String(date.getHours()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "minutes-locale", () => String(date.getMinutes()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "seconds-locale", () => String(date.getSeconds()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "hours-utc", () => String(date.getUTCHours()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "minutes-utc", () => String(date.getUTCMinutes()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "seconds-utc", () => String(date.getUTCSeconds()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "url-hash", () => url.hash.substring(1) || "No hash", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "url-host", () => url.host.replace(/\/$/, "") || "No host", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "url-hostname", () => url.hostname.replace(/\/$/, "") || "No hostname", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "url-href", () => decode(url.href) || "No href", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "url-referrer", () => decode(options.referrer) || "No referrer", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "url-password", () => url.password || "No password", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "url-pathname", () => decode(url.pathname).replace(/^\//, "").replace(/\/$/, "") || "No pathname", dontReplaceSlash === undefined ? true : dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "url-port", () => url.port || "No port", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "url-protocol", () => url.protocol || "No protocol", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "url-search", () => url.search.substring(1) || "No search", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "page-title", () => options.title || "No title", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "page-heading", () => options.info.heading || "No heading", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "page-language", () => options.info.lang || "No language", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "page-description", () => options.info.description || "No description", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "page-author", () => options.info.author || "No author", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "page-creator", () => options.info.creator || "No creator", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "page-publisher", () => options.info.publisher || "No publisher", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "datetime-iso", () => date.toISOString(), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "date-iso", () => date.toISOString().split("T")[0], dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "time-iso", () => date.toISOString().split("T")[1].split("Z")[0], dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "date-locale", () => date.toLocaleDateString(), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "time-locale", () => date.toLocaleTimeString(), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "day-locale", () => String(date.getDate()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "month-locale", () => String(date.getMonth() + 1).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "year-locale", () => String(date.getFullYear()), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "datetime-locale", () => date.toLocaleString(), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "datetime-utc", () => date.toUTCString(), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "day-utc", () => String(date.getUTCDate()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "month-utc", () => String(date.getUTCMonth() + 1).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "year-utc", () => String(date.getUTCFullYear()), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "hours-locale", () => String(date.getHours()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "minutes-locale", () => String(date.getMinutes()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "seconds-locale", () => String(date.getSeconds()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "hours-utc", () => String(date.getUTCHours()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "minutes-utc", () => String(date.getUTCMinutes()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "seconds-utc", () => String(date.getUTCSeconds()).padStart(2, "0"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "url-hash", () => url.hash.substring(1) || "No hash", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "url-host", () => url.host.replace(/\/$/, "") || "No host", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "url-hostname", () => url.hostname.replace(/\/$/, "") || "No hostname", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "url-href", () => decode(url.href) || "No href", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "url-referrer", () => decode(options.referrer) || "No referrer", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "url-password", () => url.password || "No password", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "url-pathname", () => decode(url.pathname).replace(/^\//, "").replace(/\/$/, "") || "No pathname", dontReplaceSlash === undefined ? true : dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "url-port", () => url.port || "No port", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "url-protocol", () => url.protocol || "No protocol", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "url-search", () => url.search.substring(1) || "No search", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
const params = url.search.substring(1).split("&").map(parameter => parameter.split("="));
|
|
|
for (const [name, value] of params) {
|
|
|
- template = await Util.evalTemplateVariable(template, "url-search-" + name, () => value || "", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "url-search-" + name, () => value || "", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
}
|
|
|
template = template.replace(/{\s*url-search-[^}\s]*\s*}/gi, "");
|
|
|
- template = await Util.evalTemplateVariable(template, "url-username", () => url.username || "No username", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "tab-id", () => String(options.tabId || "No tab id"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "tab-index", () => String(options.tabIndex || "No tab index"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "url-last-segment", () => decode(Util.getLastSegment(url, options.filenameReplacementCharacter)) || "No last segment", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "url-username", () => url.username || "No username", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "tab-id", () => String(options.tabId || "No tab id"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "tab-index", () => String(options.tabIndex || "No tab index"), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "url-last-segment", () => decode(getLastSegment(url, options.filenameReplacementCharacter)) || "No last segment", dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
if (content) {
|
|
|
- template = await Util.evalTemplateVariable(template, "digest-sha-256", async () => util.digest("SHA-256", content), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "digest-sha-384", async () => util.digest("SHA-384", content), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
- template = await Util.evalTemplateVariable(template, "digest-sha-512", async () => util.digest("SHA-512", content), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "digest-sha-256", async () => util.digest("SHA-256", content), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "digest-sha-384", async () => util.digest("SHA-384", content), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
+ template = await evalTemplateVariable(template, "digest-sha-512", async () => util.digest("SHA-512", content), dontReplaceSlash, options.filenameReplacementCharacter);
|
|
|
}
|
|
|
return template.trim();
|
|
|
|
|
|
@@ -1477,9 +1477,9 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
}
|
|
|
|
|
|
static processShortcutIcons(doc) {
|
|
|
- let shortcutIcon = Util.findShortcutIcon(Array.from(doc.querySelectorAll("link[href][rel=\"icon\"], link[href][rel=\"shortcut icon\"]")));
|
|
|
+ let shortcutIcon = findShortcutIcon(Array.from(doc.querySelectorAll("link[href][rel=\"icon\"], link[href][rel=\"shortcut icon\"]")));
|
|
|
if (!shortcutIcon) {
|
|
|
- shortcutIcon = Util.findShortcutIcon(Array.from(doc.querySelectorAll("link[href][rel*=\"icon\"]")));
|
|
|
+ shortcutIcon = findShortcutIcon(Array.from(doc.querySelectorAll("link[href][rel*=\"icon\"]")));
|
|
|
if (shortcutIcon) {
|
|
|
shortcutIcon.rel = "icon";
|
|
|
}
|
|
|
@@ -1506,19 +1506,19 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
|
|
|
static async resolveImportURLs(stylesheetContent, baseURI, options, workStylesheet, importedStyleSheets = new Set()) {
|
|
|
stylesheetContent = ProcessorHelper.resolveStylesheetURLs(stylesheetContent, baseURI);
|
|
|
- const imports = Util.getImportFunctions(stylesheetContent);
|
|
|
+ const imports = getImportFunctions(stylesheetContent);
|
|
|
await Promise.all(imports.map(async cssImport => {
|
|
|
- const match = Util.matchImport(cssImport);
|
|
|
+ const match = matchImport(cssImport);
|
|
|
if (match) {
|
|
|
- const regExpCssImport = Util.getRegExp(cssImport);
|
|
|
- let resourceURL = Util.normalizeURL(match.resourceURL);
|
|
|
- if (!Util.testIgnoredPath(resourceURL) && Util.testValidPath(resourceURL)) {
|
|
|
+ const regExpCssImport = getRegExp(cssImport);
|
|
|
+ let resourceURL = normalizeURL(match.resourceURL);
|
|
|
+ if (!testIgnoredPath(resourceURL) && testValidPath(resourceURL)) {
|
|
|
try {
|
|
|
resourceURL = util.resolveURL(match.resourceURL, baseURI);
|
|
|
} catch (error) {
|
|
|
// ignored
|
|
|
}
|
|
|
- if (Util.testValidURL(resourceURL) && !importedStyleSheets.has(resourceURL)) {
|
|
|
+ if (testValidURL(resourceURL) && !importedStyleSheets.has(resourceURL)) {
|
|
|
const content = await util.getContent(resourceURL, {
|
|
|
maxResourceSize: options.maxResourceSize,
|
|
|
maxResourceSizeEnabled: options.maxResourceSizeEnabled,
|
|
|
@@ -1526,12 +1526,12 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
frameId: options.windowId
|
|
|
});
|
|
|
resourceURL = content.resourceURL;
|
|
|
- content.data = Util.getUpdatedResourceContent(resourceURL, content, options);
|
|
|
- let importedStylesheetContent = Util.removeCssComments(content.data);
|
|
|
+ content.data = getUpdatedResourceContent(resourceURL, content, options);
|
|
|
+ let importedStylesheetContent = removeCssComments(content.data);
|
|
|
if (options.compressCSS) {
|
|
|
importedStylesheetContent = util.compressCSS(importedStylesheetContent);
|
|
|
}
|
|
|
- importedStylesheetContent = Util.wrapMediaQuery(importedStylesheetContent, match.media);
|
|
|
+ importedStylesheetContent = wrapMediaQuery(importedStylesheetContent, match.media);
|
|
|
if (stylesheetContent.includes(cssImport)) {
|
|
|
const ancestorStyleSheets = new Set(importedStyleSheets);
|
|
|
ancestorStyleSheets.add(resourceURL);
|
|
|
@@ -1555,12 +1555,12 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
}
|
|
|
|
|
|
static resolveStylesheetURLs(stylesheetContent, baseURI) {
|
|
|
- const urlFunctions = Util.getUrlFunctions(stylesheetContent, true);
|
|
|
+ const urlFunctions = getUrlFunctions(stylesheetContent, true);
|
|
|
urlFunctions.map(urlFunction => {
|
|
|
- const originalResourceURL = Util.matchURL(urlFunction);
|
|
|
- const resourceURL = Util.normalizeURL(originalResourceURL);
|
|
|
- if (!Util.testIgnoredPath(resourceURL)) {
|
|
|
- if (!resourceURL || Util.testValidPath(resourceURL)) {
|
|
|
+ const originalResourceURL = matchURL(urlFunction);
|
|
|
+ const resourceURL = normalizeURL(originalResourceURL);
|
|
|
+ if (!testIgnoredPath(resourceURL)) {
|
|
|
+ if (!resourceURL || testValidPath(resourceURL)) {
|
|
|
let resolvedURL;
|
|
|
if (!originalResourceURL.startsWith("#")) {
|
|
|
try {
|
|
|
@@ -1569,8 +1569,8 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
// ignored
|
|
|
}
|
|
|
}
|
|
|
- if (Util.testValidURL(resolvedURL) && resourceURL != resolvedURL && stylesheetContent.includes(urlFunction)) {
|
|
|
- stylesheetContent = stylesheetContent.replace(Util.getRegExp(urlFunction), originalResourceURL ? urlFunction.replace(originalResourceURL, resolvedURL) : "url(" + resolvedURL + ")");
|
|
|
+ if (testValidURL(resolvedURL) && resourceURL != resolvedURL && stylesheetContent.includes(urlFunction)) {
|
|
|
+ stylesheetContent = stylesheetContent.replace(getRegExp(urlFunction), originalResourceURL ? urlFunction.replace(originalResourceURL, resolvedURL) : "url(" + resolvedURL + ")");
|
|
|
}
|
|
|
} else {
|
|
|
let newUrlFunction;
|
|
|
@@ -1579,7 +1579,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
} else {
|
|
|
newUrlFunction = "url(" + EMPTY_DATA_URI + ")";
|
|
|
}
|
|
|
- stylesheetContent = stylesheetContent.replace(Util.getRegExp(urlFunction), newUrlFunction);
|
|
|
+ stylesheetContent = stylesheetContent.replace(getRegExp(urlFunction), newUrlFunction);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
@@ -1587,7 +1587,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
}
|
|
|
|
|
|
static async resolveLinkStylesheetURLs(resourceURL, baseURI, options, workStylesheet) {
|
|
|
- resourceURL = Util.normalizeURL(resourceURL);
|
|
|
+ resourceURL = normalizeURL(resourceURL);
|
|
|
if (resourceURL && resourceURL != baseURI && resourceURL != ABOUT_BLANK_URI) {
|
|
|
const content = await util.getContent(resourceURL, {
|
|
|
maxResourceSize: options.maxResourceSize,
|
|
|
@@ -1596,8 +1596,8 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
frameId: options.windowId
|
|
|
});
|
|
|
resourceURL = content.resourceURL;
|
|
|
- content.data = Util.getUpdatedResourceContent(content.resourceURL, content, options);
|
|
|
- let stylesheetContent = Util.removeCssComments(content.data);
|
|
|
+ content.data = getUpdatedResourceContent(content.resourceURL, content, options);
|
|
|
+ let stylesheetContent = removeCssComments(content.data);
|
|
|
if (options.compressCSS) {
|
|
|
stylesheetContent = util.compressCSS(stylesheetContent);
|
|
|
}
|
|
|
@@ -1629,12 +1629,12 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
async function processFontFaceRule(ruleData, fontURLs) {
|
|
|
await Promise.all(ruleData.block.children.toArray().map(async declaration => {
|
|
|
if (declaration.type == "Declaration" && declaration.value.children) {
|
|
|
- const urlFunctions = Util.getUrlFunctions(Util.getCSSValue(declaration.value), true);
|
|
|
+ const urlFunctions = getUrlFunctions(getCSSValue(declaration.value), true);
|
|
|
await Promise.all(urlFunctions.map(async urlFunction => {
|
|
|
- const originalResourceURL = Util.matchURL(urlFunction);
|
|
|
- const resourceURL = Util.normalizeURL(originalResourceURL);
|
|
|
- if (!Util.testIgnoredPath(resourceURL)) {
|
|
|
- if (Util.testValidURL(resourceURL)) {
|
|
|
+ const originalResourceURL = matchURL(urlFunction);
|
|
|
+ const resourceURL = normalizeURL(originalResourceURL);
|
|
|
+ if (!testIgnoredPath(resourceURL)) {
|
|
|
+ if (testValidURL(resourceURL)) {
|
|
|
let { content } = await batchRequest.addURL(resourceURL, true);
|
|
|
let resourceURLs = fontURLs.get(declaration);
|
|
|
if (!resourceURLs) {
|
|
|
@@ -1651,7 +1651,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
|
|
|
function replaceURLs(declaration, oldURL, newURL) {
|
|
|
declaration.value.children.forEach(token => {
|
|
|
- if (token.type == "Url" && util.removeQuotes(Util.getCSSValue(token.value)) == oldURL) {
|
|
|
+ if (token.type == "Url" && util.removeQuotes(getCSSValue(token.value)) == oldURL) {
|
|
|
token.value.value = newURL;
|
|
|
}
|
|
|
});
|
|
|
@@ -1662,12 +1662,12 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
static async processStyle(declarations, baseURI, options, cssVariables, batchRequest) {
|
|
|
await Promise.all(declarations.map(async declaration => {
|
|
|
if (declaration.type == "Declaration" && declaration.value.children) {
|
|
|
- const urlFunctions = Util.getUrlFunctions(Util.getCSSValue(declaration.value));
|
|
|
+ const urlFunctions = getUrlFunctions(getCSSValue(declaration.value));
|
|
|
await Promise.all(urlFunctions.map(async urlFunction => {
|
|
|
- const originalResourceURL = Util.matchURL(urlFunction);
|
|
|
- const resourceURL = Util.normalizeURL(originalResourceURL);
|
|
|
- if (!Util.testIgnoredPath(resourceURL)) {
|
|
|
- if (Util.testValidURL(resourceURL)) {
|
|
|
+ const originalResourceURL = matchURL(urlFunction);
|
|
|
+ const resourceURL = normalizeURL(originalResourceURL);
|
|
|
+ if (!testIgnoredPath(resourceURL)) {
|
|
|
+ if (testValidURL(resourceURL)) {
|
|
|
let { content, indexResource, duplicate } = await batchRequest.addURL(resourceURL, true, true);
|
|
|
let variableDefined;
|
|
|
const tokens = [];
|
|
|
@@ -1697,7 +1697,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
if (token.data.children) {
|
|
|
findURLToken(url, token.data.children, callback, depth + 1);
|
|
|
}
|
|
|
- if (token.data.type == "Url" && util.removeQuotes(Util.getCSSValue(token.data.value)) == url) {
|
|
|
+ if (token.data.type == "Url" && util.removeQuotes(getCSSValue(token.data.value)) == url) {
|
|
|
callback(token, children, depth == 0);
|
|
|
}
|
|
|
}
|
|
|
@@ -1708,16 +1708,16 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
await Promise.all(Array.from(resourceElements).map(async resourceElement => {
|
|
|
let resourceURL = resourceElement.getAttribute(attributeName);
|
|
|
if (resourceURL != null) {
|
|
|
- resourceURL = Util.normalizeURL(resourceURL);
|
|
|
- if (!Util.testIgnoredPath(resourceURL)) {
|
|
|
+ resourceURL = normalizeURL(resourceURL);
|
|
|
+ if (!testIgnoredPath(resourceURL)) {
|
|
|
resourceElement.setAttribute(attributeName, EMPTY_IMAGE);
|
|
|
- if (Util.testValidPath(resourceURL)) {
|
|
|
+ if (testValidPath(resourceURL)) {
|
|
|
try {
|
|
|
resourceURL = util.resolveURL(resourceURL, baseURI);
|
|
|
} catch (error) {
|
|
|
// ignored
|
|
|
}
|
|
|
- if (Util.testValidURL(resourceURL)) {
|
|
|
+ if (testValidURL(resourceURL)) {
|
|
|
let { content, indexResource, duplicate } = await batchRequest.addURL(resourceURL, true, resourceElement.tagName == "IMG" && attributeName == "src");
|
|
|
if (resourceElement.dataset.singleFileOriginURL) {
|
|
|
let originURL = resourceElement.dataset.singleFileOriginURL;
|
|
|
@@ -1775,15 +1775,15 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
attributeName = "href";
|
|
|
originalResourceURL = resourceElement.getAttribute(attributeName);
|
|
|
}
|
|
|
- let resourceURL = Util.normalizeURL(originalResourceURL);
|
|
|
- if (Util.testValidPath(resourceURL) && !Util.testIgnoredPath(resourceURL)) {
|
|
|
+ let resourceURL = normalizeURL(originalResourceURL);
|
|
|
+ if (testValidPath(resourceURL) && !testIgnoredPath(resourceURL)) {
|
|
|
resourceElement.setAttribute(attributeName, EMPTY_IMAGE);
|
|
|
try {
|
|
|
resourceURL = util.resolveURL(resourceURL, baseURI);
|
|
|
} catch (error) {
|
|
|
// ignored
|
|
|
}
|
|
|
- if (Util.testValidURL(resourceURL)) {
|
|
|
+ if (testValidURL(resourceURL)) {
|
|
|
const { content } = await batchRequest.addURL(resourceURL);
|
|
|
const hashMatch = originalResourceURL.match(REGEXP_URL_HASH);
|
|
|
if (hashMatch && hashMatch[0]) {
|
|
|
@@ -1811,15 +1811,15 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
await Promise.all(Array.from(resourceElements).map(async resourceElement => {
|
|
|
const srcset = util.parseSrcset(resourceElement.getAttribute(attributeName));
|
|
|
const srcsetValues = await Promise.all(srcset.map(async srcsetValue => {
|
|
|
- let resourceURL = Util.normalizeURL(srcsetValue.url);
|
|
|
- if (!Util.testIgnoredPath(resourceURL)) {
|
|
|
- if (Util.testValidPath(resourceURL)) {
|
|
|
+ let resourceURL = normalizeURL(srcsetValue.url);
|
|
|
+ if (!testIgnoredPath(resourceURL)) {
|
|
|
+ if (testValidPath(resourceURL)) {
|
|
|
try {
|
|
|
resourceURL = util.resolveURL(resourceURL, baseURI);
|
|
|
} catch (error) {
|
|
|
// ignored
|
|
|
}
|
|
|
- if (Util.testValidURL(resourceURL)) {
|
|
|
+ if (testValidURL(resourceURL)) {
|
|
|
const { content } = await batchRequest.addURL(resourceURL, true);
|
|
|
const forbiddenPrefixFound = PREFIXES_FORBIDDEN_DATA_URI.filter(prefixDataURI => content.startsWith(prefixDataURI)).length;
|
|
|
if (forbiddenPrefixFound) {
|
|
|
@@ -1886,160 +1886,158 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
const REGEXP_IMPORT_NO_QUOTES_FN = /@import\s*(.*?)\s*(.*?)(;|$|})/i;
|
|
|
const REGEXP_ESCAPE = /([{}()^$&.*?/+|[\\\\]|\]|-)/g;
|
|
|
|
|
|
- class Util {
|
|
|
- static getUpdatedResourceContent(resourceURL, content, options) {
|
|
|
- if (options.rootDocument && options.updatedResources[resourceURL]) {
|
|
|
- options.updatedResources[resourceURL].retrieved = true;
|
|
|
- return options.updatedResources[resourceURL].content;
|
|
|
- } else {
|
|
|
- return content.data || "";
|
|
|
- }
|
|
|
+ function getUpdatedResourceContent(resourceURL, content, options) {
|
|
|
+ if (options.rootDocument && options.updatedResources[resourceURL]) {
|
|
|
+ options.updatedResources[resourceURL].retrieved = true;
|
|
|
+ return options.updatedResources[resourceURL].content;
|
|
|
+ } else {
|
|
|
+ return content.data || "";
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- static normalizeURL(url) {
|
|
|
- if (!url || url.startsWith(DATA_URI_PREFIX)) {
|
|
|
- return url;
|
|
|
- } else {
|
|
|
- return url.split("#")[0];
|
|
|
- }
|
|
|
+ function normalizeURL(url) {
|
|
|
+ if (!url || url.startsWith(DATA_URI_PREFIX)) {
|
|
|
+ return url;
|
|
|
+ } else {
|
|
|
+ return url.split("#")[0];
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- static getCSSValue(value) {
|
|
|
- let result = "";
|
|
|
- try {
|
|
|
- result = cssTree.generate(value);
|
|
|
- } catch (error) {
|
|
|
- // ignored
|
|
|
- }
|
|
|
- return result;
|
|
|
+ function getCSSValue(value) {
|
|
|
+ let result = "";
|
|
|
+ try {
|
|
|
+ result = cssTree.generate(value);
|
|
|
+ } catch (error) {
|
|
|
+ // ignored
|
|
|
}
|
|
|
+ return result;
|
|
|
+ }
|
|
|
|
|
|
- static getOnEventAttributeNames(doc) {
|
|
|
- const element = doc.createElement("div");
|
|
|
- const attributeNames = [];
|
|
|
- for (const propertyName in element) {
|
|
|
- if (propertyName.startsWith("on")) {
|
|
|
- attributeNames.push(propertyName);
|
|
|
- }
|
|
|
+ function getOnEventAttributeNames(doc) {
|
|
|
+ const element = doc.createElement("div");
|
|
|
+ const attributeNames = [];
|
|
|
+ for (const propertyName in element) {
|
|
|
+ if (propertyName.startsWith("on")) {
|
|
|
+ attributeNames.push(propertyName);
|
|
|
}
|
|
|
- attributeNames.push("onunload");
|
|
|
- return attributeNames;
|
|
|
}
|
|
|
+ attributeNames.push("onunload");
|
|
|
+ return attributeNames;
|
|
|
+ }
|
|
|
|
|
|
- static async evalTemplateVariable(template, variableName, valueGetter, dontReplaceSlash, replacementCharacter) {
|
|
|
- let maxLength;
|
|
|
- if (template) {
|
|
|
- const regExpVariable = "{\\s*" + variableName.replace(/\W|_/g, "[$&]") + "\\s*}";
|
|
|
- let replaceRegExp = new RegExp(regExpVariable + "\\[\\d+\\]", "g");
|
|
|
- if (template.match(replaceRegExp)) {
|
|
|
- const matchedLength = template.match(replaceRegExp)[0];
|
|
|
- maxLength = Number(matchedLength.match(/\[(\d+)\]$/)[1]);
|
|
|
- if (isNaN(maxLength) || maxLength <= 0) {
|
|
|
- maxLength = null;
|
|
|
- }
|
|
|
- } else {
|
|
|
- replaceRegExp = new RegExp(regExpVariable, "g");
|
|
|
+ async function evalTemplateVariable(template, variableName, valueGetter, dontReplaceSlash, replacementCharacter) {
|
|
|
+ let maxLength;
|
|
|
+ if (template) {
|
|
|
+ const regExpVariable = "{\\s*" + variableName.replace(/\W|_/g, "[$&]") + "\\s*}";
|
|
|
+ let replaceRegExp = new RegExp(regExpVariable + "\\[\\d+\\]", "g");
|
|
|
+ if (template.match(replaceRegExp)) {
|
|
|
+ const matchedLength = template.match(replaceRegExp)[0];
|
|
|
+ maxLength = Number(matchedLength.match(/\[(\d+)\]$/)[1]);
|
|
|
+ if (isNaN(maxLength) || maxLength <= 0) {
|
|
|
+ maxLength = null;
|
|
|
}
|
|
|
- if (template.match(replaceRegExp)) {
|
|
|
- let value = await valueGetter();
|
|
|
- if (!dontReplaceSlash) {
|
|
|
- value = value.replace(/\/+/g, replacementCharacter);
|
|
|
- }
|
|
|
- if (maxLength) {
|
|
|
- value = await util.truncateText(value, maxLength);
|
|
|
- }
|
|
|
- return template.replace(replaceRegExp, value);
|
|
|
+ } else {
|
|
|
+ replaceRegExp = new RegExp(regExpVariable, "g");
|
|
|
+ }
|
|
|
+ if (template.match(replaceRegExp)) {
|
|
|
+ let value = await valueGetter();
|
|
|
+ if (!dontReplaceSlash) {
|
|
|
+ value = value.replace(/\/+/g, replacementCharacter);
|
|
|
+ }
|
|
|
+ if (maxLength) {
|
|
|
+ value = await util.truncateText(value, maxLength);
|
|
|
}
|
|
|
+ return template.replace(replaceRegExp, value);
|
|
|
}
|
|
|
- return template;
|
|
|
}
|
|
|
+ return template;
|
|
|
+ }
|
|
|
|
|
|
- static getLastSegment(url, replacementCharacter) {
|
|
|
- let lastSegmentMatch = url.pathname.match(/\/([^/]+)$/), lastSegment = lastSegmentMatch && lastSegmentMatch[0];
|
|
|
- if (!lastSegment) {
|
|
|
- lastSegmentMatch = url.href.match(/([^/]+)\/?$/);
|
|
|
- lastSegment = lastSegmentMatch && lastSegmentMatch[0];
|
|
|
- }
|
|
|
- if (!lastSegment) {
|
|
|
- lastSegmentMatch = lastSegment.match(/(.*)\.[^.]+$/);
|
|
|
- lastSegment = lastSegmentMatch && lastSegmentMatch[0];
|
|
|
- }
|
|
|
- if (!lastSegment) {
|
|
|
- lastSegment = url.hostname.replace(/\/+/g, replacementCharacter).replace(/\/$/, "");
|
|
|
- }
|
|
|
+ function getLastSegment(url, replacementCharacter) {
|
|
|
+ let lastSegmentMatch = url.pathname.match(/\/([^/]+)$/), lastSegment = lastSegmentMatch && lastSegmentMatch[0];
|
|
|
+ if (!lastSegment) {
|
|
|
+ lastSegmentMatch = url.href.match(/([^/]+)\/?$/);
|
|
|
+ lastSegment = lastSegmentMatch && lastSegmentMatch[0];
|
|
|
+ }
|
|
|
+ if (!lastSegment) {
|
|
|
lastSegmentMatch = lastSegment.match(/(.*)\.[^.]+$/);
|
|
|
- if (lastSegmentMatch && lastSegmentMatch[1]) {
|
|
|
- lastSegment = lastSegmentMatch[1];
|
|
|
- }
|
|
|
- lastSegment = lastSegment.replace(/\/$/, "").replace(/^\//, "");
|
|
|
- return lastSegment;
|
|
|
+ lastSegment = lastSegmentMatch && lastSegmentMatch[0];
|
|
|
}
|
|
|
-
|
|
|
- static getRegExp(string) {
|
|
|
- return new RegExp(string.replace(REGEXP_ESCAPE, "\\$1"), "gi");
|
|
|
+ if (!lastSegment) {
|
|
|
+ lastSegment = url.hostname.replace(/\/+/g, replacementCharacter).replace(/\/$/, "");
|
|
|
}
|
|
|
-
|
|
|
- static getUrlFunctions(stylesheetContent, unique) {
|
|
|
- const result = stylesheetContent.match(REGEXP_URL_FN) || [];
|
|
|
- if (unique) {
|
|
|
- return [...new Set(result)];
|
|
|
- } else {
|
|
|
- return result;
|
|
|
- }
|
|
|
+ lastSegmentMatch = lastSegment.match(/(.*)\.[^.]+$/);
|
|
|
+ if (lastSegmentMatch && lastSegmentMatch[1]) {
|
|
|
+ lastSegment = lastSegmentMatch[1];
|
|
|
}
|
|
|
+ lastSegment = lastSegment.replace(/\/$/, "").replace(/^\//, "");
|
|
|
+ return lastSegment;
|
|
|
+ }
|
|
|
|
|
|
- static getImportFunctions(stylesheetContent) {
|
|
|
- return stylesheetContent.match(REGEXP_IMPORT_FN) || [];
|
|
|
- }
|
|
|
+ function getRegExp(string) {
|
|
|
+ return new RegExp(string.replace(REGEXP_ESCAPE, "\\$1"), "gi");
|
|
|
+ }
|
|
|
|
|
|
- static findShortcutIcon(shortcutIcons) {
|
|
|
- shortcutIcons = shortcutIcons.filter(linkElement => linkElement.href != EMPTY_IMAGE);
|
|
|
- shortcutIcons.sort((linkElement1, linkElement2) => (parseInt(linkElement2.sizes, 10) || 16) - (parseInt(linkElement1.sizes, 10) || 16));
|
|
|
- return shortcutIcons[0];
|
|
|
+ function getUrlFunctions(stylesheetContent, unique) {
|
|
|
+ const result = stylesheetContent.match(REGEXP_URL_FN) || [];
|
|
|
+ if (unique) {
|
|
|
+ return [...new Set(result)];
|
|
|
+ } else {
|
|
|
+ return result;
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- static matchURL(stylesheetContent) {
|
|
|
- const match = stylesheetContent.match(REGEXP_URL_SIMPLE_QUOTES_FN) ||
|
|
|
- stylesheetContent.match(REGEXP_URL_DOUBLE_QUOTES_FN) ||
|
|
|
- stylesheetContent.match(REGEXP_URL_NO_QUOTES_FN);
|
|
|
- return match && match[1];
|
|
|
- }
|
|
|
+ function getImportFunctions(stylesheetContent) {
|
|
|
+ return stylesheetContent.match(REGEXP_IMPORT_FN) || [];
|
|
|
+ }
|
|
|
|
|
|
- static testIgnoredPath(resourceURL) {
|
|
|
- return resourceURL && (resourceURL.startsWith(DATA_URI_PREFIX) || resourceURL == ABOUT_BLANK_URI);
|
|
|
- }
|
|
|
+ function findShortcutIcon(shortcutIcons) {
|
|
|
+ shortcutIcons = shortcutIcons.filter(linkElement => linkElement.href != EMPTY_IMAGE);
|
|
|
+ shortcutIcons.sort((linkElement1, linkElement2) => (parseInt(linkElement2.sizes, 10) || 16) - (parseInt(linkElement1.sizes, 10) || 16));
|
|
|
+ return shortcutIcons[0];
|
|
|
+ }
|
|
|
|
|
|
- static testValidPath(resourceURL) {
|
|
|
- return resourceURL && !resourceURL.match(EMPTY_URL);
|
|
|
- }
|
|
|
+ function matchURL(stylesheetContent) {
|
|
|
+ const match = stylesheetContent.match(REGEXP_URL_SIMPLE_QUOTES_FN) ||
|
|
|
+ stylesheetContent.match(REGEXP_URL_DOUBLE_QUOTES_FN) ||
|
|
|
+ stylesheetContent.match(REGEXP_URL_NO_QUOTES_FN);
|
|
|
+ return match && match[1];
|
|
|
+ }
|
|
|
|
|
|
- static testValidURL(resourceURL) {
|
|
|
- return Util.testValidPath(resourceURL) && (resourceURL.match(HTTP_URI_PREFIX) || resourceURL.match(FILE_URI_PREFIX) || resourceURL.startsWith(BLOB_URI_PREFIX)) && resourceURL.match(NOT_EMPTY_URL);
|
|
|
- }
|
|
|
+ function testIgnoredPath(resourceURL) {
|
|
|
+ return resourceURL && (resourceURL.startsWith(DATA_URI_PREFIX) || resourceURL == ABOUT_BLANK_URI);
|
|
|
+ }
|
|
|
|
|
|
- static matchImport(stylesheetContent) {
|
|
|
- const match = stylesheetContent.match(REGEXP_IMPORT_URL_SIMPLE_QUOTES_FN) ||
|
|
|
- stylesheetContent.match(REGEXP_IMPORT_URL_DOUBLE_QUOTES_FN) ||
|
|
|
- stylesheetContent.match(REGEXP_IMPORT_URL_NO_QUOTES_FN) ||
|
|
|
- stylesheetContent.match(REGEXP_IMPORT_SIMPLE_QUOTES_FN) ||
|
|
|
- stylesheetContent.match(REGEXP_IMPORT_DOUBLE_QUOTES_FN) ||
|
|
|
- stylesheetContent.match(REGEXP_IMPORT_NO_QUOTES_FN);
|
|
|
- if (match) {
|
|
|
- const [, resourceURL, media] = match;
|
|
|
- return { resourceURL, media };
|
|
|
- }
|
|
|
- }
|
|
|
+ function testValidPath(resourceURL) {
|
|
|
+ return resourceURL && !resourceURL.match(EMPTY_URL);
|
|
|
+ }
|
|
|
|
|
|
- static removeCssComments(stylesheetContent) {
|
|
|
- return stylesheetContent.replace(/\/\*(.|\s)*?\*\//g, "");
|
|
|
+ function testValidURL(resourceURL) {
|
|
|
+ return testValidPath(resourceURL) && (resourceURL.match(HTTP_URI_PREFIX) || resourceURL.match(FILE_URI_PREFIX) || resourceURL.startsWith(BLOB_URI_PREFIX)) && resourceURL.match(NOT_EMPTY_URL);
|
|
|
+ }
|
|
|
+
|
|
|
+ function matchImport(stylesheetContent) {
|
|
|
+ const match = stylesheetContent.match(REGEXP_IMPORT_URL_SIMPLE_QUOTES_FN) ||
|
|
|
+ stylesheetContent.match(REGEXP_IMPORT_URL_DOUBLE_QUOTES_FN) ||
|
|
|
+ stylesheetContent.match(REGEXP_IMPORT_URL_NO_QUOTES_FN) ||
|
|
|
+ stylesheetContent.match(REGEXP_IMPORT_SIMPLE_QUOTES_FN) ||
|
|
|
+ stylesheetContent.match(REGEXP_IMPORT_DOUBLE_QUOTES_FN) ||
|
|
|
+ stylesheetContent.match(REGEXP_IMPORT_NO_QUOTES_FN);
|
|
|
+ if (match) {
|
|
|
+ const [, resourceURL, media] = match;
|
|
|
+ return { resourceURL, media };
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- static wrapMediaQuery(stylesheetContent, mediaQuery) {
|
|
|
- if (mediaQuery) {
|
|
|
- return "@media " + mediaQuery + "{ " + stylesheetContent + " }";
|
|
|
- } else {
|
|
|
- return stylesheetContent;
|
|
|
- }
|
|
|
+ function removeCssComments(stylesheetContent) {
|
|
|
+ return stylesheetContent.replace(/\/\*(.|\s)*?\*\//g, "");
|
|
|
+ }
|
|
|
+
|
|
|
+ function wrapMediaQuery(stylesheetContent, mediaQuery) {
|
|
|
+ if (mediaQuery) {
|
|
|
+ return "@media " + mediaQuery + "{ " + stylesheetContent + " }";
|
|
|
+ } else {
|
|
|
+ return stylesheetContent;
|
|
|
}
|
|
|
}
|
|
|
|