Skip to content

Commit 3cbebcf

Browse files
fix(theme-generator): missing :root content (#860)
Co-authored-by: liweijie0812 <674416404@qq.com>
1 parent 3c314fa commit 3cbebcf

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

  • packages/theme-generator/src/common/utils

packages/theme-generator/src/common/utils/index.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,25 @@ export function downloadFile(blob, fileName) {
8888
export function parseRootCss(cssText) {
8989
if (!cssText) return { rootContent: '', restContent: '' };
9090

91-
const rootBlockMatch = cssText.match(/:root\s*\{([^}]*)\}/);
91+
// 匹配以 :root 开头的选择器组(允许逗号分隔的多个选择器,且包含 :root),后接 { ... } 块
92+
const rootBlockReg = /(?:^|[\s;}])((?:[^{};]*?:root[^{};]*)\s*\{([^}]*)\})/g;
93+
94+
const rootContents = [];
95+
let restContent = cssText;
96+
let match;
97+
while ((match = rootBlockReg.exec(cssText)) !== null) {
98+
rootContents.push(match[2].trim());
99+
restContent = restContent.replace(match[1], '');
100+
}
92101

93-
if (!rootBlockMatch) {
102+
if (rootContents.length === 0) {
94103
return { rootContent: '', restContent: cssText.trim() };
95104
}
96105

97-
const rootContent = rootBlockMatch[1].trim();
98-
const restContent = cssText.replace(rootBlockMatch[0], '').trim();
99-
100-
return { rootContent, restContent };
106+
return {
107+
rootContent: rootContents.join('\n').trim(),
108+
restContent: restContent.trim(),
109+
};
101110
}
102111

103112
/**

0 commit comments

Comments
 (0)