add support for css @import rules (#11)

This commit is contained in:
Whalefreezer
2026-04-01 12:00:00 +08:00
committed by yz-yu
parent fe59f07e9e
commit 68b97e40a2
4 changed files with 37 additions and 1 deletions

View File

@@ -21,13 +21,21 @@ function getCssRulesString(s: CSSStyleSheet): string | null {
try {
const rules = s.rules || s.cssRules;
return rules
? Array.from(rules).reduce((prev, cur) => (prev += cur.cssText), '')
? Array.from(rules).reduce((prev, cur) => prev + getCssRuleString(cur), '')
: null;
} catch (error) {
return null;
}
}
function getCssRuleString(rule: CSSRule): string {
return isCSSImportRule(rule) ? getCssRulesString(rule.styleSheet) || '' : rule.cssText;
}
function isCSSImportRule(rule: CSSRule): rule is CSSImportRule {
return 'styleSheet' in rule;
}
function extractOrigin(url: string): string {
let origin;
if (url.indexOf('//') > -1) {