Skip to content

Commit c225926

Browse files
author
wangzhongqiang
committed
feat: 将媒体查询下Resolution单位🙆统一
1 parent f3c7ab2 commit c225926

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/style_propetries/style_media.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ pub enum StyleMediaFeatureID {
2323
DeviceHeight = 7,
2424
DeviceAspectRatio = 8,
2525
Resolution = 9,
26-
Hover = 10
2726
}
2827

2928
#[derive(Debug, Clone)]
@@ -300,10 +299,12 @@ impl StyleMedia {
300299
return Some(MediaValueType::Number(*value as i64));
301300
},
302301
MediaFeatureValue::Resolution(value) => {
303-
return Some(MediaValueType::String(match value.to_css_string(PrinterOptions::default()){
304-
Ok(str) => {str},
305-
Err(_) => {"".to_string()},
306-
}));
302+
let num = match value {
303+
lightningcss::values::resolution::Resolution::Dpi(val) => *val/96.0,
304+
lightningcss::values::resolution::Resolution::Dpcm(val) => *val/37.7953,
305+
lightningcss::values::resolution::Resolution::Dppx(val) => *val,
306+
};
307+
return Some(MediaValueType::Float(num as f64));
307308
},
308309
MediaFeatureValue::Ratio(value) => {
309310
return Some(MediaValueType::Float((value.0/value.1) as f64));
@@ -330,7 +331,6 @@ impl StyleMedia {
330331
MediaFeatureId::DeviceHeight => {return StyleMediaFeatureID::DeviceHeight}
331332
MediaFeatureId::DeviceAspectRatio => {return StyleMediaFeatureID::DeviceAspectRatio}
332333
MediaFeatureId::Resolution => {return StyleMediaFeatureID::Resolution}
333-
MediaFeatureId::Hover => {return StyleMediaFeatureID::Hover}
334334
_ => {return StyleMediaFeatureID::Invalid}
335335
}
336336
},

0 commit comments

Comments
 (0)