Skip to content

Commit 2b14dc2

Browse files
authored
Merge pull request #13 from NervJS/fix/negative-unit
fix: 修复px数值单位匹配丢失了负数和小数匹配错误问题
2 parents e6b4f90 + 8981589 commit 2b14dc2

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

__test__/index.spec.mjs.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ Generated by [AVA](https://avajs.dev).
241241
_flexShrink: 0,␊
242242
_fontSize: convertNumber2PX(12),␊
243243
_margin: {␊
244-
top: convertNumber2PX(12),␊
244+
top: convertNumber2PX(-12),␊
245245
right: convertNumber2PX(10),␊
246246
bottom: convertNumber2PX(12),␊
247247
left: convertNumber2PX(32)␊
@@ -566,7 +566,7 @@ Generated by [AVA](https://avajs.dev).
566566
_fontWeight: 500,␊
567567
_height: convertNumber2PX(800),␊
568568
_margin: {␊
569-
top: convertNumber2PX(12),␊
569+
top: convertNumber2PX(-12),␊
570570
right: convertNumber2PX(10),␊
571571
bottom: convertNumber2PX(12),␊
572572
left: convertNumber2PX(32)␊
@@ -644,7 +644,7 @@ Generated by [AVA](https://avajs.dev).
644644
_flexShrink: 0,␊
645645
_fontSize: convertNumber2PX(12),␊
646646
_margin: {␊
647-
top: convertNumber2PX(12),␊
647+
top: convertNumber2PX(-12),␊
648648
right: convertNumber2PX(10),␊
649649
bottom: convertNumber2PX(12),␊
650650
left: convertNumber2PX(32)␊

__test__/index.spec.mjs.snap

1 Byte
Binary file not shown.

src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub fn prefix_style_key(s: &str) -> String {
6767

6868
pub fn convert_px_to_units(input: String) -> Expr {
6969
// 定义匹配 '16px' 的正则表达式
70-
let re = Regex::new(r"(\d+)px").unwrap();
70+
let re = Regex::new(r"(-?(\d+(\.\d*)?|\.\d+))px").unwrap();
7171
// 使用正则表达式进行匹配
7272
if let Some(captures) = re.captures(&input) {
7373
// 提取匹配到的数字部分

0 commit comments

Comments
 (0)