mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-14 15:00:01 -04:00
bug fixes
Co-authored-by: Avad3 <Avad3@users.noreply.github.com>
This commit is contained in:
parent
a39a2657c6
commit
47b59945a9
23 changed files with 385 additions and 327 deletions
35
src/shared/rewriters/css.ts
Normal file
35
src/shared/rewriters/css.ts
Normal file
|
@ -0,0 +1,35 @@
|
|||
// This CSS rewriter uses code from Meteor
|
||||
// You can find the original source code at https://github.com/MeteorProxy/Meteor
|
||||
|
||||
import { encodeUrl } from "./url";
|
||||
|
||||
export function rewriteCss(css: string, origin?: URL) {
|
||||
const regex =
|
||||
/(@import\s+(?!url\())?\s*url\(\s*(['"]?)([^'")]+)\2\s*\)|@import\s+(['"])([^'"]+)\4/g
|
||||
|
||||
return css.replace(
|
||||
regex,
|
||||
(
|
||||
match,
|
||||
importStatement,
|
||||
urlQuote,
|
||||
urlContent,
|
||||
importQuote,
|
||||
importContent
|
||||
) => {
|
||||
const url = urlContent || importContent
|
||||
const encodedUrl = encodeUrl(url.trim(), origin)
|
||||
|
||||
if (importStatement) {
|
||||
return `@import url(${urlQuote}${encodedUrl}${urlQuote})`
|
||||
}
|
||||
|
||||
if (importQuote) {
|
||||
return `@import ${importQuote}${encodedUrl}${importQuote}`
|
||||
}
|
||||
|
||||
return `url(${urlQuote}${encodedUrl}${urlQuote})`
|
||||
}
|
||||
)
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue