Skip to content

Commit c90b039

Browse files
authored
Merge pull request #279 from dev-five-git/update-syntax
Update syntax
2 parents f3deb96 + 1b8225d commit c90b039

File tree

90 files changed

+962
-612
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+962
-612
lines changed

.changeset/dull-paws-worry.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+
Fix global css rerender issue without components

.changeset/open-results-taste.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 css comment syntax

.changeset/plain-corners-lose.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+
Optimize css selector

.changeset/red-webs-draw.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+
Optimize creating css

Cargo.lock

Lines changed: 42 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/devup-ui-wasm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ css = { path = "../../libs/css" }
2727
console_error_panic_hook = { version = "0.1.7", optional = true }
2828
once_cell = "1.21.3"
2929
js-sys = "0.3.77"
30-
serde_json = "1.0.141"
30+
serde_json = "1.0.142"
3131
serde-wasm-bindgen = "0.6.5"
3232

3333
[dev-dependencies]

bindings/devup-ui-wasm/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub struct Output {
1717
code: String,
1818
styles: HashSet<ExtractStyleValue>,
1919
map: Option<String>,
20+
default_collected: bool,
2021
}
2122
#[wasm_bindgen]
2223
extern "C" {
@@ -130,7 +131,7 @@ impl Output {
130131
}
131132
}
132133

133-
if !collected {
134+
if !collected && !self.default_collected {
134135
return None;
135136
}
136137

@@ -183,7 +184,6 @@ pub fn code_extract(
183184
css_file: &str,
184185
) -> Result<Output, JsValue> {
185186
let mut sheet = GLOBAL_STYLE_SHEET.lock().unwrap();
186-
sheet.rm_global_css(filename);
187187

188188
match extract(
189189
filename,
@@ -197,6 +197,7 @@ pub fn code_extract(
197197
code: output.code,
198198
styles: output.styles,
199199
map: output.map,
200+
default_collected: sheet.rm_global_css(filename),
200201
}),
201202
Err(error) => Err(JsValue::from_str(error.to_string().as_str())),
202203
}

libs/css/src/constant.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ pub(super) static ZERO_PERCENT_FUNCTION: phf::Set<&str> = phf_set! {
119119
};
120120

121121
pub(super) static F_SPACE_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"\s*,\s*").unwrap());
122+
123+
pub(super) static CSS_COMMENT_RE: Lazy<Regex> =
124+
Lazy::new(|| Regex::new(r"/\*[\s\S]*?\*/").unwrap());
125+
122126
pub(super) static F_DOT_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"(\b|,)0\.(\d+)").unwrap());
123127
pub(super) static DOT_ZERO_RE: Lazy<Regex> =
124128
Lazy::new(|| Regex::new(r"(\b|,)-?0\.0+([^\d])").unwrap());

libs/css/src/lib.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod constant;
33
pub mod debug;
44
pub mod is_special_property;
55
pub mod optimize_value;
6-
pub mod property_type;
6+
pub mod rm_css_comment;
77
mod selector_separator;
88
pub mod style_selector;
99
pub mod utils;
@@ -15,7 +15,7 @@ use crate::constant::{COLOR_HASH, F_SPACE_RE, GLOBAL_STYLE_PROPERTY, ZERO_RE};
1515
use crate::debug::is_debug;
1616
use crate::optimize_value::optimize_value;
1717
use crate::style_selector::StyleSelector;
18-
use crate::utils::{to_camel_case, to_kebab_case};
18+
use crate::utils::to_kebab_case;
1919

2020
pub fn merge_selector(class_name: &str, selector: Option<&StyleSelector>) -> String {
2121
if let Some(selector) = selector {
@@ -39,10 +39,25 @@ pub fn disassemble_property(property: &str) -> Vec<String> {
3939
GLOBAL_STYLE_PROPERTY
4040
.get(property)
4141
.map(|v| match v.len() {
42-
1 => vec![to_camel_case(v[0])],
43-
_ => v.iter().map(|v| to_camel_case(v)).collect(),
42+
1 => vec![v[0].to_string()],
43+
_ => v.iter().map(|v| v.to_string()).collect(),
44+
})
45+
.unwrap_or_else(|| {
46+
vec![if (property.starts_with("Webkit")
47+
&& property.len() > 6
48+
&& property.chars().nth(6).unwrap().is_uppercase())
49+
|| (property.starts_with("Moz")
50+
&& property.len() > 3
51+
&& property.chars().nth(3).unwrap().is_uppercase())
52+
|| (property.starts_with("ms")
53+
&& property.len() > 2
54+
&& property.chars().nth(2).unwrap().is_uppercase())
55+
{
56+
format!("-{}", to_kebab_case(property))
57+
} else {
58+
to_kebab_case(property)
59+
}]
4460
})
45-
.unwrap_or_else(|| vec![property.to_string()])
4661
}
4762

4863
pub fn keyframes_to_keyframes_name(keyframes: &str) -> String {
@@ -424,7 +439,7 @@ mod tests {
424439
".cls::placeholder"
425440
);
426441
assert_eq!(
427-
merge_selector("cls", Some(&"themeDark".into())),
442+
merge_selector("cls", Some(&"theme-dark".into())),
428443
":root[data-theme=dark] .cls"
429444
);
430445
assert_eq!(
@@ -447,7 +462,7 @@ mod tests {
447462
);
448463

449464
assert_eq!(
450-
merge_selector("cls", Some(&["themeDark", "hover"].into()),),
465+
merge_selector("cls", Some(&["theme-dark", "hover"].into()),),
451466
":root[data-theme=dark] .cls:hover"
452467
);
453468
assert_eq!(

0 commit comments

Comments
 (0)