Skip to content

Commit bf47284

Browse files
committed
Add borderRadius expend
Add print media query
1 parent a5db0c1 commit bf47284

18 files changed

+376
-72
lines changed

.changeset/friendly-knives-mix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@devup-ui/react": patch
3+
---
4+
5+
Add borderTopRadius, borderBottomRadius, borderLeftRadius, borderRightRadius, \_print

.changeset/strong-ants-brake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@devup-ui/wasm": patch
3+
---
4+
5+
Support @media

.changeset/sweet-seals-begin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@devup-ui/wasm": patch
3+
---
4+
5+
Add special props

libs/css/src/lib.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::StyleSelector::{Dual, Postfix, Prefix};
1+
use crate::StyleSelector::{Dual, Media, Postfix, Prefix};
22
use once_cell::sync::Lazy;
33
use regex::Regex;
44
use serde::{Deserialize, Serialize};
@@ -22,6 +22,7 @@ static SELECTOR_ORDER_MAP: Lazy<HashMap<String, u8>> = Lazy::new(|| {
2222
pub enum StyleSelector {
2323
Postfix(String),
2424
Prefix(String),
25+
Media(String),
2526
Dual(String, String),
2627
}
2728

@@ -34,6 +35,9 @@ impl PartialOrd for StyleSelector {
3435
impl Ord for StyleSelector {
3536
fn cmp(&self, other: &Self) -> Ordering {
3637
match (self, other) {
38+
(Media(a), Media(b)) => a.cmp(b),
39+
(Media(_), _) => Ordering::Less,
40+
(_, Media(_)) => Ordering::Greater,
3741
(Postfix(a), Postfix(b)) => SELECTOR_ORDER_MAP
3842
.get(a)
3943
.unwrap_or(&0)
@@ -56,6 +60,8 @@ impl Ord for StyleSelector {
5660

5761
impl From<&str> for StyleSelector {
5862
fn from(value: &str) -> Self {
63+
println!("value: {}", value);
64+
println!("value: {}", value == "print");
5965
if let Some(s) = value.strip_prefix("group") {
6066
Dual("*[role=group]".to_string(), to_kebab_case(s))
6167
} else if let Some(s) = value.strip_prefix("theme") {
@@ -65,6 +71,8 @@ impl From<&str> for StyleSelector {
6571
s.chars().next().unwrap().to_ascii_lowercase(),
6672
&s[1..]
6773
))
74+
} else if value == "print" {
75+
Media("print".to_string())
6876
} else {
6977
Postfix(to_kebab_case(value))
7078
}
@@ -80,6 +88,7 @@ impl Display for StyleSelector {
8088
Postfix(value) => format!("-{}", value),
8189
Prefix(value) => format!("-{}-", value),
8290
Dual(prefix, postfix) => format!("-{}-{}", prefix, postfix),
91+
Media(value) => format!("@{}", value),
8392
}
8493
)
8594
}
@@ -97,6 +106,7 @@ pub fn merge_selector(class_name: &str, selector: Option<&StyleSelector>) -> Str
97106
SelectorSeparator::Single => format!("{}:{} .{}", prefix, postfix, class_name),
98107
SelectorSeparator::Double => format!("{}::{} .{}", prefix, postfix, class_name),
99108
},
109+
Media(_) => format!(".{}", class_name),
100110
}
101111
} else {
102112
format!(".{}", class_name)
@@ -203,6 +213,22 @@ static GLOBAL_STYLE_PROPERTY: Lazy<HashMap<&str, PropertyType>> = Lazy::new(|| {
203213
("px", ["padding-left", "padding-right"]),
204214
("py", ["padding-top", "padding-bottom"]),
205215
("boxSize", ["width", "height"]),
216+
(
217+
"borderBottomRadius",
218+
["border-bottom-left-radius", "border-bottom-right-radius"],
219+
),
220+
(
221+
"borderTopRadius",
222+
["border-top-left-radius", "border-top-right-radius"],
223+
),
224+
(
225+
"borderLeftRadius",
226+
["border-top-left-radius", "border-bottom-left-radius"],
227+
),
228+
(
229+
"borderRightRadius",
230+
["border-top-right-radius", "border-bottom-right-radius"],
231+
),
206232
] {
207233
map.insert(key, value.into());
208234
}
@@ -266,7 +292,7 @@ pub fn convert_property(property: &str) -> PropertyType {
266292
.unwrap_or_else(|| to_kebab_case(property).into())
267293
}
268294

269-
pub fn sort_to_long(property: &str) -> String {
295+
pub fn short_to_long(property: &str) -> String {
270296
GLOBAL_STYLE_PROPERTY
271297
.get(property)
272298
.map(|v| match v {

libs/extractor/src/extract_style/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::utils::convert_value;
22
use crate::StyleProperty;
33
use css::{
4-
css_to_classname, sheet_to_classname, sheet_to_variable_name, sort_to_long, StyleSelector,
4+
css_to_classname, sheet_to_classname, sheet_to_variable_name, short_to_long, StyleSelector,
55
};
66
use once_cell::sync::Lazy;
77
use std::collections::HashSet;
@@ -41,7 +41,7 @@ impl ExtractStaticStyle {
4141
} else {
4242
convert_value(value)
4343
},
44-
property: sort_to_long(property),
44+
property: short_to_long(property),
4545
level,
4646
selector,
4747
basic: false,
@@ -145,7 +145,7 @@ impl ExtractDynamicStyle {
145145
selector: Option<StyleSelector>,
146146
) -> Self {
147147
Self {
148-
property: sort_to_long(property),
148+
property: short_to_long(property),
149149
level,
150150
identifier: identifier.to_string(),
151151
selector,

libs/extractor/src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,32 @@ mod tests {
623623
"test.tsx",
624624
r#"import { Box } from "@devup-ui/core";
625625
<Box margin={a === b ? null : undefined} />;
626+
"#,
627+
ExtractOption {
628+
package: "@devup-ui/core".to_string(),
629+
css_file: None
630+
}
631+
)
632+
.unwrap());
633+
634+
reset_class_map();
635+
assert_debug_snapshot!(extract(
636+
"test.tsx",
637+
r#"import { Box } from "@devup-ui/core";
638+
<Box margin={a === b ? 1 : undefined} />;
639+
"#,
640+
ExtractOption {
641+
package: "@devup-ui/core".to_string(),
642+
css_file: None
643+
}
644+
)
645+
.unwrap());
646+
647+
reset_class_map();
648+
assert_debug_snapshot!(extract(
649+
"test.tsx",
650+
r#"import { Box } from "@devup-ui/core";
651+
<Box margin={a === b ? undefined : 2} />;
626652
"#,
627653
ExtractOption {
628654
package: "@devup-ui/core".to_string(),
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
source: libs/extractor/src/lib.rs
3+
expression: "extract(\"test.tsx\",\nr#\"import { Box } from \"@devup-ui/core\";\n<Box margin={a === b ? 1 : undefined} />;\n\"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap()"
4+
---
5+
ExtractOutput {
6+
styles: [
7+
Static(
8+
ExtractStaticStyle {
9+
property: "margin",
10+
value: "4px",
11+
level: 0,
12+
selector: None,
13+
basic: false,
14+
},
15+
),
16+
],
17+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className={a === b ? \"d0\" : \"\"} />;\n",
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
source: libs/extractor/src/lib.rs
3+
expression: "extract(\"test.tsx\",\nr#\"import { Box } from \"@devup-ui/core\";\n<Box margin={a === b ? undefined : 2} />;\n\"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap()"
4+
---
5+
ExtractOutput {
6+
styles: [
7+
Static(
8+
ExtractStaticStyle {
9+
property: "margin",
10+
value: "8px",
11+
level: 0,
12+
selector: None,
13+
basic: false,
14+
},
15+
),
16+
],
17+
code: "import \"@devup-ui/core/devup-ui.css\";\n<div className={a === b ? \"\" : \"d0\"} />;\n",
18+
}

libs/extractor/src/utils.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ static SPECIAL_PROPERTIES: Lazy<HashSet<&str>> = Lazy::new(|| {
4444
"tabIndex",
4545
"maxLength",
4646
"minLength",
47+
"disabled",
48+
"readOnly",
49+
"autoFocus",
50+
"required",
4751
] {
4852
set.insert(prop);
4953
}

libs/extractor/src/visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::style_extractor::{
66
extract_style_from_expression, extract_style_from_jsx_attr, ExtractResult,
77
};
88
use crate::{ExtractStyleProp, ExtractStyleValue, StyleProperty};
9-
use css::sort_to_long;
9+
use css::short_to_long;
1010
use oxc_allocator::{Allocator, CloneIn};
1111
use oxc_ast::ast::ImportDeclarationSpecifier::ImportSpecifier;
1212
use oxc_ast::ast::JSXAttributeItem::Attribute;
@@ -262,7 +262,7 @@ impl<'a> VisitMut<'a> for DevupVisitor<'a> {
262262
let mut rm = false;
263263
if let Attribute(ref mut attr) = &mut attr {
264264
if let Identifier(name) = &attr.name {
265-
let name = sort_to_long(name.name.as_str());
265+
let name = short_to_long(name.name.as_str());
266266
if duplicate_set.contains(&name) {
267267
continue;
268268
}

0 commit comments

Comments
 (0)