Skip to content

Commit 946e38f

Browse files
author
mayintao3
committed
feat: background-postion支持百分比
1 parent be8d170 commit 946e38f

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/style_propetries/unit.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub fn generate_expr_by_length_value(length_value: &LengthValue, platform: Platf
145145

146146
pub fn generate_expr_with_css_input(input: String, platform: Platform) -> Expr {
147147
// 定义匹配 '16px' 的正则表达式
148-
let re = Regex::new(r"(-?(?P<num>\d+(\.\d*)?|\.\d+))(?P<unit>(px|vw|vh|pX|PX|Px)?)").unwrap();
148+
let re = Regex::new(r"(-?(?P<num>\d+(\.\d*)?|\.\d+))(?P<unit>(%|px|vw|vh|pX|PX|Px)?)").unwrap();
149149
let bytes = input.as_bytes();
150150
// 使用正则表达式进行匹配
151151
if let Ok(caps) = re.captures(bytes) {
@@ -171,6 +171,9 @@ pub fn generate_expr_with_css_input(input: String, platform: Platform) -> Expr {
171171
"pX" | "PX" | "Px" => {
172172
return generate_expr_lit_str!(format!("{}px", number))
173173
},
174+
"%" => {
175+
return generate_expr_lit_str!(format!("{}%", number))
176+
}
174177
_ => {
175178
// 如果没有单位,则认为是纯数字,返回 Expr::Num
176179
return generate_expr_lit_num!(number);

0 commit comments

Comments
 (0)