Skip to content

Commit 68246b2

Browse files
committed
feat: 支持 style 属性中写 lognhand 样式
1 parent 7e112f6 commit 68246b2

File tree

6 files changed

+326
-50
lines changed

6 files changed

+326
-50
lines changed

__test__/fixure/mod.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export default class Mod extends React.Component {
5353
<span className='line1 instruction1'>巴拉巴拉小魔仙</span>
5454
<span className='line1 txt'>成员: 4000+</span>
5555
</div>
56-
<div className='cnt_row2'>
56+
<div className='cnt_row2' style={{"border-top-left-radius": "1000px"}}>
5757
{ this.getDom() }
5858
<img
5959
className='icon1'

__test__/index.spec.mjs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ Generated by [AVA](https://avajs.dev).
355355
alignItems: "flex-start",␊
356356
borderColor: "#999",␊
357357
borderRadius: {␊
358-
topLeft: "12px",␊
358+
topLeft: "1000px",␊
359359
topRight: "12px",␊
360360
bottomLeft: "12px",␊
361361
bottomRight: "12px"␊

__test__/index.spec.mjs.snap

3 Bytes
Binary file not shown.

src/style_parser.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ impl ToObjectExpr for TextDecoration {
7373
impl From<&str> for TextDecoration {
7474
fn from(value: &str) -> Self {
7575
TextDecoration {
76-
kind: if value == "" { "None".to_string() } else { value.to_string()},
76+
kind: if value == "" {
77+
"None".to_string()
78+
} else {
79+
value.to_string()
80+
},
7781
color: "black".to_string(),
7882
}
7983
}
@@ -89,7 +93,10 @@ pub struct BorderRadius {
8993

9094
impl BorderRadius {
9195
pub fn is_zero(&self) -> bool {
92-
self.top_left == "0" && self.top_right == "0" && self.bottom_left == "0" && self.bottom_right == "0"
96+
self.top_left == "0"
97+
&& self.top_right == "0"
98+
&& self.bottom_left == "0"
99+
&& self.bottom_right == "0"
93100
}
94101

95102
pub fn set_top_left(&mut self, top_left: &str) {
@@ -272,7 +279,6 @@ impl From<&str> for MarginPadding {
272279
margin_padding
273280
}
274281
}
275-
276282

277283
#[derive(Debug, Clone)]
278284
pub enum StyleValueType {
@@ -297,7 +303,11 @@ impl Display for StyleValueType {
297303
)
298304
}
299305
StyleValueType::MarginPadding(value) => {
300-
write!(f, "{} {} {} {}", value.top, value.right, value.bottom, value.left)
306+
write!(
307+
f,
308+
"{} {} {} {}",
309+
value.top, value.right, value.bottom, value.left
310+
)
301311
}
302312
}
303313
}
@@ -538,7 +548,10 @@ impl<'i> StyleParser<'i> {
538548
if padding.is_zero() {
539549
style_value.remove("padding");
540550
} else {
541-
style_value.insert("padding".to_string(), StyleValueType::MarginPadding(padding));
551+
style_value.insert(
552+
"padding".to_string(),
553+
StyleValueType::MarginPadding(padding),
554+
);
542555
}
543556

544557
let mut border_radius = match border_radius {
@@ -569,7 +582,6 @@ impl<'i> StyleParser<'i> {
569582
StyleValueType::BorderRadius(border_radius),
570583
);
571584
}
572-
573585
}
574586

575587
pub fn calc(&self) -> StyleData {

src/utils.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,12 @@ pub fn to_camel_case(s: &str, is_first: bool) -> String {
3939
}
4040
result
4141
}
42+
43+
pub fn delete_items<T>(items: &mut Vec<T>, indexs: Vec<usize>) {
44+
let mut indexs = indexs;
45+
indexs.sort();
46+
indexs.reverse();
47+
for index in indexs {
48+
items.remove(index);
49+
}
50+
}

0 commit comments

Comments
 (0)