mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-15 15:30:00 -04:00
fix oversight in css rewriter
This commit is contained in:
parent
39d7529535
commit
635494f44f
1 changed files with 16 additions and 16 deletions
|
@ -9,32 +9,32 @@ export function unrewriteCss(css: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleCss(type: "rewrite" | "unrewrite", css: string, meta?: URLMeta) {
|
function handleCss(type: "rewrite" | "unrewrite", css: string, meta?: URLMeta) {
|
||||||
|
// regex from vk6 (https://github.com/ading2210)
|
||||||
const urlRegex = /url\(['"]?(.+?)['"]?\)/gm;
|
const urlRegex = /url\(['"]?(.+?)['"]?\)/gm;
|
||||||
const Atruleregex =
|
const Atruleregex =
|
||||||
/@import\s+(url\s*?\(.{0,9999}?\)|['"].{0,9999}?['"]|.{0,9999}?)($|\s|;)/gm;
|
/@import\s+(url\s*?\(.{0,9999}?\)|['"].{0,9999}?['"]|.{0,9999}?)($|\s|;)/gm;
|
||||||
css = new String(css).toString();
|
css = new String(css).toString();
|
||||||
css = css.replace(urlRegex, (match, url) => {
|
css = css.replace(urlRegex, (match, url) => {
|
||||||
const encodedUrl =
|
const encodedUrl =
|
||||||
type === "rewrite"
|
type === "rewrite" ? rewriteUrl(url, meta) : unrewriteUrl(url);
|
||||||
? rewriteUrl(url.trim(), meta)
|
|
||||||
: unrewriteUrl(url.trim());
|
|
||||||
|
|
||||||
return match.replace(url, encodedUrl);
|
return match.replace(url, encodedUrl);
|
||||||
});
|
});
|
||||||
css = css.replace(Atruleregex, (_, importStatement) => {
|
css = css.replace(Atruleregex, (match, importStatement) => {
|
||||||
return importStatement.replace(
|
return match.replace(
|
||||||
/^(url\(['"]?|['"]|)(.+?)(['"]|['"]?\)|)$/gm,
|
importStatement,
|
||||||
(match, firstQuote, url, endQuote) => {
|
importStatement.replace(
|
||||||
if (firstQuote.startsWith("url")) {
|
/^(url\(['"]?|['"]|)(.+?)(['"]|['"]?\)|)$/gm,
|
||||||
return match;
|
(match, firstQuote, url, endQuote) => {
|
||||||
}
|
if (firstQuote.startsWith("url")) {
|
||||||
const encodedUrl =
|
return match;
|
||||||
type === "rewrite"
|
}
|
||||||
? rewriteUrl(url.trim(), meta)
|
const encodedUrl =
|
||||||
: unrewriteUrl(url.trim());
|
type === "rewrite" ? rewriteUrl(url, meta) : unrewriteUrl(url);
|
||||||
|
|
||||||
return `${firstQuote}${encodedUrl}${endQuote}`;
|
return `${firstQuote}${encodedUrl}${endQuote}`;
|
||||||
}
|
}
|
||||||
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue