Skip to content

Commit 771ffd5

Browse files
committed
fix: 修复样式继承
1 parent a739778 commit 771ffd5

File tree

4 files changed

+23
-27
lines changed

4 files changed

+23
-27
lines changed

__test__/index.spec.mjs.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Generated by [AVA](https://avajs.dev).
3131
getDom() {␊
3232
return <div className='cc'>␊
3333
34-
<span className='line1 txt' style="text-overflow:ellipsis;white-space:nowrap;overflow:hidden;color:#999;font-size:12px;line-height:1;flex-shrink:0px;display:inline-flex;background-color:#fff6f0;border-radius:8px;width:343px;height:166px;font-family:Source Han Sans CN;font-weight:500;flex-direction:column;align-items:flex-start;justify-content:center;gap:8px;padding-left:16px;padding-right:16px;padding-top:29px;padding-bottom:29px;position:relative;border-width:1px;border-style:solid;border-color:#999;top:3px;left:201px;z-index:12;">成员123: 4000+</span>␊
34+
<span className='line1 txt' style="text-overflow:ellipsis;white-space:nowrap;overflow:hidden;color:#999;font-size:12px;line-height:1;flex-shrink:0px;display:inline-flex;font-family:Source Han Sans CN;font-weight:500;">成员123: 4000+</span>␊
3535
3636
<div className='cnt_row4'>␊
3737
@@ -65,57 +65,57 @@ Generated by [AVA](https://avajs.dev).
6565
padding-bottom: "29px"␊
6666
}}>␊
6767
68-
<div className='cnt_row' style="border-radius:100px;background-color:#000000b3;display:flex;align-items:center;justify-content:center;flex-shrink:0px;gap:4px;height:18px;padding-left:4px;padding-right:8px;padding-top:8px;padding-bottom:8px;width:176px;font-family:Source Han Sans CN;font-weight:500;flex-direction:column;">␊
68+
<div className='cnt_row' style="border-radius:100px;background-color:#000000b3;display:flex;align-items:center;justify-content:center;flex-shrink:0px;gap:4px;height:18px;padding-left:4px;padding-right:8px;padding-top:8px;padding-bottom:8px;width:176px;font-family:Source Han Sans CN;font-weight:500;">␊
6969
7070
<>␊
7171
72-
<img className='icon' src='//img20.360buyimg.com/img/jfs/t1/166410/12/38783/3147/64f58062Fd7737e2b/5aaf0205cd1ce175.png' style="width:18px;height:18px;background-color:#fff6f0;border-radius:8px;font-family:Source Han Sans CN;font-weight:500;display:flex;flex-direction:column;align-items:flex-start;justify-content:center;flex-shrink:0px;gap:8px;padding-left:16px;padding-right:16px;padding-top:29px;padding-bottom:29px;"></img>␊
72+
<img className='icon' src='//img20.360buyimg.com/img/jfs/t1/166410/12/38783/3147/64f58062Fd7737e2b/5aaf0205cd1ce175.png' style="width:18px;height:18px;font-family:Source Han Sans CN;font-weight:500;"></img>␊
7373
7474
<>␊
7575
76-
<span className='line1 instruction' style="text-overflow:ellipsis;white-space:nowrap;overflow:hidden;color:#fff;font-size:12px;line-height:1;flex-shrink:0px;display:inline-flex;background-color:#fff6f0;border-radius:8px;width:343px;height:166px;font-family:Source Han Sans CN;font-weight:500;flex-direction:column;align-items:flex-start;justify-content:center;gap:8px;padding-left:16px;padding-right:16px;padding-top:29px;padding-bottom:29px;">超能芭比 5分钟前查看团购</span>␊
76+
<span className='line1 instruction' style="text-overflow:ellipsis;white-space:nowrap;overflow:hidden;color:#fff;font-size:12px;line-height:1;flex-shrink:0px;display:inline-flex;font-family:Source Han Sans CN;font-weight:500;">超能芭比 5分钟前查看团购</span>␊
7777
7878
</>␊
7979
8080
</>␊
8181
8282
</div>␊
8383
84-
<div className='cnt_row1' style="display:flex;align-items:center;justify-content:flex-start;gap:10px;position:relative;width:311px;height:50px;background-color:#fff6f0;border-radius:8px;font-family:Source Han Sans CN;font-weight:500;flex-direction:column;flex-shrink:0px;padding-left:16px;padding-right:16px;padding-top:29px;padding-bottom:29px;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;color:#fff;font-size:12px;line-height:1;">␊
84+
<div className='cnt_row1' style="display:flex;align-items:center;justify-content:flex-start;gap:10px;position:relative;width:311px;height:50px;font-family:Source Han Sans CN;font-weight:500;white-space:nowrap;color:#fff;font-size:12px;line-height:1;">␊
8585
86-
<img className='img' src='//img12.360buyimg.com/img/jfs/t1/100881/15/44805/18567/64f58062F1b45e0cb/caf065a7410087ce.png' style="width:50px;height:50px;background-color:#fff6f0;border-radius:8px;font-family:Source Han Sans CN;font-weight:500;display:flex;flex-direction:column;align-items:flex-start;justify-content:center;flex-shrink:0px;gap:8px;padding-left:16px;padding-right:16px;padding-top:29px;padding-bottom:29px;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;color:#fff;font-size:12px;line-height:1;position:relative;"></img>␊
86+
<img className='img' src='//img12.360buyimg.com/img/jfs/t1/100881/15/44805/18567/64f58062F1b45e0cb/caf065a7410087ce.png' style="width:50px;height:50px;font-family:Source Han Sans CN;font-weight:500;white-space:nowrap;color:#fff;font-size:12px;line-height:1;"></img>␊
8787
88-
<div className='cnt_col' style="display:flex;flex-direction:column;align-items:flex-start;justify-content:center;gap:8px;width:145px;height:50px;background-color:#fff6f0;border-radius:8px;font-family:Source Han Sans CN;font-weight:500;flex-shrink:0px;padding-left:16px;padding-right:16px;padding-top:29px;padding-bottom:29px;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;color:#fff;font-size:12px;line-height:1;position:relative;">␊
88+
<div className='cnt_col' style="display:flex;flex-direction:column;align-items:flex-start;justify-content:center;gap:8px;width:145px;height:50px;font-family:Source Han Sans CN;font-weight:500;white-space:nowrap;color:#fff;font-size:12px;line-height:1;">␊
8989
90-
<span className='line1 instruction1' style="text-overflow:ellipsis;white-space:nowrap;overflow:hidden;color:#000;font-size:16px;line-height:1;flex-shrink:0px;width:116px;display:inline-flex;background-color:#fff6f0;border-radius:8px;height:166px;font-family:Source Han Sans CN;font-weight:500;flex-direction:column;align-items:flex-start;justify-content:center;gap:8px;padding-left:16px;padding-right:16px;padding-top:29px;padding-bottom:29px;position:relative;">巴拉巴拉小魔仙</span>␊
90+
<span className='line1 instruction1' style="text-overflow:ellipsis;white-space:nowrap;overflow:hidden;color:#000;font-size:16px;line-height:1;flex-shrink:0px;width:116px;display:inline-flex;font-family:Source Han Sans CN;font-weight:500;">巴拉巴拉小魔仙</span>␊
9191
92-
<span className='line1 txt' style="text-overflow:ellipsis;white-space:nowrap;overflow:hidden;color:#999;font-size:12px;line-height:1;flex-shrink:0px;display:inline-flex;background-color:#fff6f0;border-radius:8px;width:343px;height:166px;font-family:Source Han Sans CN;font-weight:500;flex-direction:column;align-items:flex-start;justify-content:center;gap:8px;padding-left:16px;padding-right:16px;padding-top:29px;padding-bottom:29px;position:relative;">成员: 4000+</span>␊
92+
<span className='line1 txt' style="text-overflow:ellipsis;white-space:nowrap;overflow:hidden;color:#999;font-size:12px;line-height:1;flex-shrink:0px;display:inline-flex;font-family:Source Han Sans CN;font-weight:500;">成员: 4000+</span>␊
9393
9494
</div>␊
9595
96-
<div className='cnt_row2' style="border-width:1px;border-style:solid;border-color:#999;border-radius:12px;display:flex;align-items:flex-start;justify-content:space-between;flex-shrink:0px;gap:-94px;position:absolute;top:3px;left:201px;width:110px;height:23px;padding-left:8px;padding-right:8px;padding-top:4px;padding-bottom:4px;z-index:12;background-color:#fff6f0;font-family:Source Han Sans CN;font-weight:500;flex-direction:column;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;color:#fff;font-size:12px;line-height:1;">␊
96+
<div className='cnt_row2' style="border-width:1px;border-style:solid;border-color:#999;border-radius:12px;display:flex;align-items:flex-start;justify-content:space-between;flex-shrink:0px;gap:-94px;position:absolute;top:3px;left:201px;width:110px;height:23px;padding-left:8px;padding-right:8px;padding-top:4px;padding-bottom:4px;z-index:12;font-family:Source Han Sans CN;font-weight:500;white-space:nowrap;color:#fff;font-size:12px;line-height:1;">␊
9797
9898
{this.getDom()}␊
9999
100-
<img className='icon1' src='//img11.360buyimg.com/img/jfs/t1/175578/35/40256/1981/64f58062Fddaf1a21/f1111d9988a65ccc.png' style="width:15px;height:15px;background-color:#fff6f0;border-radius:8px;font-family:Source Han Sans CN;font-weight:500;display:flex;flex-direction:column;align-items:flex-start;justify-content:center;flex-shrink:0px;gap:8px;padding-left:16px;padding-right:16px;padding-top:29px;padding-bottom:29px;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;color:#fff;font-size:12px;line-height:1;position:relative;border-width:1px;border-style:solid;border-color:#999;top:3px;left:201px;z-index:12;"></img>␊
100+
<img className='icon1' src='//img11.360buyimg.com/img/jfs/t1/175578/35/40256/1981/64f58062Fddaf1a21/f1111d9988a65ccc.png' style="width:15px;height:15px;font-family:Source Han Sans CN;font-weight:500;white-space:nowrap;color:#fff;font-size:12px;line-height:1;"></img>␊
101101
102-
<span className='instruction2' style="color:#999;font-size:11px;line-height:1.36;text-align:center;flex-shrink:0px;overflow:hidden;background-color:#fff6f0;border-radius:8px;width:343px;height:166px;font-family:Source Han Sans CN;font-weight:500;display:flex;flex-direction:column;align-items:flex-start;justify-content:center;gap:8px;padding-left:16px;padding-right:16px;padding-top:29px;padding-bottom:29px;text-overflow:ellipsis;white-space:nowrap;position:relative;border-width:1px;border-style:solid;border-color:#999;top:3px;left:201px;z-index:12;">slslsl-jsj</span>␊
102+
<span className='instruction2' style="color:#999;font-size:11px;line-height:1.36;text-align:center;flex-shrink:0px;overflow:hidden;font-family:Source Han Sans CN;font-weight:500;white-space:nowrap;">slslsl-jsj</span>␊
103103
104-
<span className='txt1' style="color:#222;font-size:11px;line-height:1.36;text-align:center;flex-shrink:0px;background-color:#fff6f0;border-radius:8px;width:343px;height:166px;font-family:Source Han Sans CN;font-weight:500;display:flex;flex-direction:column;align-items:flex-start;justify-content:center;gap:8px;padding-left:16px;padding-right:16px;padding-top:29px;padding-bottom:29px;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;position:relative;border-width:1px;border-style:solid;border-color:#999;top:3px;left:201px;z-index:12;">复制</span>␊
104+
<span className='txt1' style="color:#222;font-size:11px;line-height:1.36;text-align:center;flex-shrink:0px;font-family:Source Han Sans CN;font-weight:500;white-space:nowrap;">复制</span>␊
105105
106106
</div>␊
107107
108108
</div>␊
109109
110-
<div className='cnt_row3' style="display:flex;align-items:center;justify-content:space-between;gap:-311px;width:311px;height:44px;background-color:#fff6f0;border-radius:8px;font-family:Source Han Sans CN;font-weight:500;flex-direction:column;flex-shrink:0px;padding-left:16px;padding-right:16px;padding-top:29px;padding-bottom:29px;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;color:#fff;font-size:12px;line-height:1;position:relative;border-width:1px;border-style:solid;border-color:#999;top:3px;left:201px;z-index:12;text-align:center;">␊
110+
<div className='cnt_row3' style="display:flex;align-items:center;justify-content:space-between;gap:-311px;width:311px;height:44px;font-family:Source Han Sans CN;font-weight:500;white-space:nowrap;color:#fff;font-size:12px;line-height:1;text-align:center;">␊
111111
112-
<span className='line2 txt2' style="color:#999;font-size:12px;line-height:1.83;flex-shrink:0px;width:290px;display:inline-flex;background-color:#fff6f0;border-radius:8px;height:166px;font-family:Source Han Sans CN;font-weight:500;flex-direction:column;align-items:flex-start;justify-content:center;gap:8px;padding-left:16px;padding-right:16px;padding-top:29px;padding-bottom:29px;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;position:relative;border-width:1px;border-style:solid;border-color:#999;top:3px;left:201px;z-index:12;text-align:center;">␊
112+
<span className='line2 txt2' style="color:#999;font-size:12px;line-height:1.83;flex-shrink:0px;width:290px;display:inline-flex;font-family:Source Han Sans CN;font-weight:500;white-space:nowrap;text-align:center;">␊
113113
114114
团长介绍:售前售后进群售前售后进群售前售后进群售前售后进群VXklsidohh...␊
115115
116116
</span>␊
117117
118-
<img className='img1' src='//img14.360buyimg.com/img/jfs/t1/206378/24/25778/195/64eca527F378f17a2/c1623681708609fd.png' style="width:6px;height:10px;background-color:#fff6f0;border-radius:8px;font-family:Source Han Sans CN;font-weight:500;display:flex;flex-direction:column;align-items:flex-start;justify-content:center;flex-shrink:0px;gap:8px;padding-left:16px;padding-right:16px;padding-top:29px;padding-bottom:29px;text-overflow:ellipsis;white-space:nowrap;overflow:hidden;color:#fff;font-size:12px;line-height:1;position:relative;border-width:1px;border-style:solid;border-color:#999;top:3px;left:201px;z-index:12;text-align:center;"></img>␊
118+
<img className='img1' src='//img14.360buyimg.com/img/jfs/t1/206378/24/25778/195/64eca527F378f17a2/c1623681708609fd.png' style="width:6px;height:10px;font-family:Source Han Sans CN;font-weight:500;white-space:nowrap;color:#fff;font-size:12px;line-height:1;text-align:center;"></img>␊
119119
120120
</div>␊
121121

__test__/index.spec.mjs.snap

-160 Bytes
Binary file not shown.

src/style_parser.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,16 @@ impl<'i> StyleParser<'i> {
163163
let has_property_index = final_properties
164164
.iter()
165165
.position(|property| property.property_id() == parent_declaration.property_id());
166+
let is_style_inheritable = is_style_inheritable(parent_declaration.property_id());
166167
if let Some(index) = has_property_index {
167-
let is_style_inheritable = is_style_inheritable(final_properties[index].property_id());
168-
if is_style_inheritable {
169-
final_properties[index] = parent_declaration.clone();
170-
} else {
171-
let value = final_properties[index].value_to_css_string(PrinterOptions::default());
168+
let value = final_properties[index].value_to_css_string(PrinterOptions::default());
172169
if let Ok(value) = value {
170+
// Todo "initial" "unset"
173171
if value.as_str() == "inherit" {
174172
final_properties[index] = parent_declaration.clone();
175173
}
176174
}
177-
}
178-
} else {
175+
} else if is_style_inheritable {
179176
final_properties.push(parent_declaration.clone());
180177
}
181178
}

src/utils.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use lightningcss::properties::PropertyId;
55
use once_cell::sync::Lazy;
66
use swc_ecma_ast::{JSXMemberExpr, JSXObject};
77

8-
static _INHERITABLE_STYLES: Lazy<HashSet<PropertyId<'static>>> = Lazy::new(|| {
8+
static INHERITABLE_STYLES: Lazy<HashSet<PropertyId<'static>>> = Lazy::new(|| {
99
let mut styles = HashSet::new();
1010
styles.insert(PropertyId::from("color"));
1111
styles.insert(PropertyId::from("font-size"));
@@ -90,9 +90,8 @@ pub fn create_qualname(str: &str) -> QualName {
9090
QualName::new(None, ns!(), LocalName::from(str))
9191
}
9292

93-
pub fn is_style_inheritable(_style: PropertyId<'_>) -> bool {
94-
// INHERITABLE_STYLES.contains(&style)
95-
false
93+
pub fn is_style_inheritable(style: PropertyId<'_>) -> bool {
94+
INHERITABLE_STYLES.contains(&style)
9695
}
9796

9897
pub fn is_starts_with_uppercase(str: &str) -> bool {

0 commit comments

Comments
 (0)