Skip to content

Commit 318996a

Browse files
committed
feat: 增加暗黑模式的监听,优化产物体积
1 parent e7385d9 commit 318996a

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

__test__/fixure/style.bin

-712 Bytes
Binary file not shown.

__test__/index.spec.mjs.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ Generated by [AVA](https://avajs.dev).
88

99
> Snapshot 1
1010
11-
'{"fonts":[],"keyframes":[],"medias":[],"styles":[{"declarations":[[66,100],[69,"100px"],[67,"100px"],[68,"100px"]],"has_env":false,"media":0,"selector":["px"],"variables":{}}]}'
11+
'{"fonts":[],"keyframes":[],"medias":[],"styles":[{"declarations":[[66,100],[69,"100px"],[67,"100px"],[68,"100px"]],"media":0,"selector":["px"]}]}'

__test__/index.spec.mjs.snap

-23 Bytes
Binary file not shown.

src/json_writer.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,19 @@ impl JsonWriter {
116116
span: DUMMY_SP,
117117
elems: parse_style_values(rule_item.declarations.clone(), Platform::Harmony),
118118
})),
119-
}))),
120-
PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp {
119+
})))
120+
];
121+
if rule_item.has_env {
122+
lit_props.push(
123+
PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp {
124+
key: PropName::Ident(Ident::new("has_env".into(), DUMMY_SP)),
125+
value: Box::new(Expr::Lit(Lit::Bool(Bool { span: DUMMY_SP, value: rule_item.has_env }))),
126+
})))
127+
);
128+
}
129+
if rule_item.variables.len() > 0 {
130+
lit_props.push(
131+
PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp {
121132
key: PropName::Ident(Ident::new("variables".into(), DUMMY_SP)),
122133
value: Box::new(Expr::Object(ObjectLit {
123134
span: DUMMY_SP,
@@ -132,12 +143,9 @@ impl JsonWriter {
132143
})))
133144
}).collect::<Vec<PropOrSpread>>()
134145
}))
135-
}))),
136-
PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp {
137-
key: PropName::Ident(Ident::new("has_env".into(), DUMMY_SP)),
138-
value: Box::new(Expr::Lit(Lit::Bool(Bool { span: DUMMY_SP, value: rule_item.has_env }))),
139-
})))
140-
];
146+
})))
147+
);
148+
}
141149

142150
if pseudo_key.len() > 0 {
143151
let mut pseudo_enum = None;

src/style_propetries/style_media.rs

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub enum StyleMediaFeatureID {
2525
DeviceHeight = 7,
2626
DeviceAspectRatio = 8,
2727
Resolution = 9,
28+
PrefersColorScheme = 10,
2829
}
2930

3031
#[derive(Debug, Clone)]
@@ -383,6 +384,7 @@ impl StyleMedia {
383384
MediaFeatureId::DeviceHeight => return StyleMediaFeatureID::DeviceHeight,
384385
MediaFeatureId::DeviceAspectRatio => return StyleMediaFeatureID::DeviceAspectRatio,
385386
MediaFeatureId::Resolution => return StyleMediaFeatureID::Resolution,
387+
MediaFeatureId::PrefersColorScheme => return StyleMediaFeatureID::PrefersColorScheme,
386388
_ => return StyleMediaFeatureID::Invalid,
387389
},
388390
_ => return StyleMediaFeatureID::Invalid,

0 commit comments

Comments
 (0)