Skip to content

Commit 7078105

Browse files
committed
fix: Handlig importan in theme rules
1 parent 5217148 commit 7078105

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

src/index.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,40 +208,49 @@ function createThemeRule(className) {
208208
theme = theme[0];
209209
pseudo.shift();
210210
}
211+
let important = "";
212+
let importantSuffix = "";
213+
if (className.includes('!important')) {
214+
[className, important] = className.split("!");
215+
important = '!' + important;
216+
importantSuffix = parseValue(important);
217+
important = '!important';
218+
}
211219

212220
let res = className.split(':');
213-
if (res.length > 2) {
214-
console.log('pseudo names need to be added after theme');
215-
return;
216-
}
221+
// if (res.length > 2) {
222+
// console.log('pseudo names need to be added after theme');
223+
// return;
224+
// }
217225
let property = res[0];
218226
let suffix = parseValue(res[1]);
219227
let value = res[1].replace(/_/g, " ");
220228

229+
//TODO: set theme rule with pseudo and !important
221230
let rule = "";
222-
if (pseudo) {
223-
suffix += "\\@" + theme;
224-
for (let i = 0; i < pseudo.length; i++) {
225-
suffix += ":" + pseudo[0 + i];
226-
}
227-
rule = `.${property}\\:${suffix} { ${property}: ${value}; }`;
228-
}
229-
else {
231+
if (res.length > 2) {
232+
// suffix += "\\@" + theme;
233+
// for (let i = 0; i < res.length - 2; i++) {
234+
suffix += "\\:" + res[2] + importantSuffix + ":" + "\\@" + theme + ":" + res[2];
235+
// }
236+
rule = `.${property}\\:${suffix} { ${property}: ${value}${important}; }`;
237+
} else {
230238
rule = `.${property}\\:${suffix}\\@${theme} { ${property}: ${value}; }`;
231239
}
240+
232241
if (theme == 'dark' || theme == 'light') {
233242
// rule = `[theme="${theme}"] ${rule}`;
234243
// let reverseRule = `html:not([theme="${themes[1 - themes.indexOf(theme)]}"]) ${rule}`;
235-
let reverseRule = `${rule}`;
236-
tempStyleList.push(rule);
237-
themeCSS[theme].push(reverseRule);
244+
// let reverseRule = `${rule}`;
245+
// tempStyleList.push(rule);
246+
themeCSS[theme].push(rule);
238247
classNameList.set(classname, true);
239248
}
240249
}
241250

242251
function createThemeMedia() {
243-
let initial;
244252
if (themeCSS.dark.length) {
253+
let initial;
245254
initial = "@media (prefers-color-scheme: dark) {";
246255
for (let c of themeCSS.dark) {
247256
initial += c + "\n";
@@ -251,6 +260,7 @@ function createThemeMedia() {
251260
themeCSS.dark = [];
252261
}
253262
if (themeCSS.light.length) {
263+
let initial;
254264
initial = "@media (prefers-color-scheme: light) {";
255265
for (let c of themeCSS.light) {
256266
initial += c + "\n";

0 commit comments

Comments
 (0)