Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dull-paws-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@devup-ui/wasm": patch
---

Fix global css rerender issue without components
5 changes: 5 additions & 0 deletions .changeset/open-results-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@devup-ui/wasm": patch
---

Support css comment syntax
5 changes: 5 additions & 0 deletions .changeset/plain-corners-lose.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@devup-ui/wasm": patch
---

Optimize css selector
5 changes: 5 additions & 0 deletions .changeset/red-webs-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@devup-ui/wasm": patch
---

Optimize creating css
84 changes: 42 additions & 42 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bindings/devup-ui-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ css = { path = "../../libs/css" }
console_error_panic_hook = { version = "0.1.7", optional = true }
once_cell = "1.21.3"
js-sys = "0.3.77"
serde_json = "1.0.141"
serde_json = "1.0.142"
serde-wasm-bindgen = "0.6.5"

[dev-dependencies]
Expand Down
5 changes: 3 additions & 2 deletions bindings/devup-ui-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct Output {
code: String,
styles: HashSet<ExtractStyleValue>,
map: Option<String>,
default_collected: bool,
}
#[wasm_bindgen]
extern "C" {
Expand Down Expand Up @@ -130,7 +131,7 @@ impl Output {
}
}

if !collected {
if !collected && !self.default_collected {
return None;
}

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

match extract(
filename,
Expand All @@ -197,6 +197,7 @@ pub fn code_extract(
code: output.code,
styles: output.styles,
map: output.map,
default_collected: sheet.rm_global_css(filename),
}),
Err(error) => Err(JsValue::from_str(error.to_string().as_str())),
}
Expand Down
4 changes: 4 additions & 0 deletions libs/css/src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ pub(super) static ZERO_PERCENT_FUNCTION: phf::Set<&str> = phf_set! {
};

pub(super) static F_SPACE_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"\s*,\s*").unwrap());

pub(super) static CSS_COMMENT_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"/\*[\s\S]*?\*/").unwrap());

pub(super) static F_DOT_RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"(\b|,)0\.(\d+)").unwrap());
pub(super) static DOT_ZERO_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"(\b|,)-?0\.0+([^\d])").unwrap());
Expand Down
29 changes: 22 additions & 7 deletions libs/css/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod constant;
pub mod debug;
pub mod is_special_property;
pub mod optimize_value;
pub mod property_type;
pub mod rm_css_comment;
mod selector_separator;
pub mod style_selector;
pub mod utils;
Expand All @@ -15,7 +15,7 @@ use crate::constant::{COLOR_HASH, F_SPACE_RE, GLOBAL_STYLE_PROPERTY, ZERO_RE};
use crate::debug::is_debug;
use crate::optimize_value::optimize_value;
use crate::style_selector::StyleSelector;
use crate::utils::{to_camel_case, to_kebab_case};
use crate::utils::to_kebab_case;

pub fn merge_selector(class_name: &str, selector: Option<&StyleSelector>) -> String {
if let Some(selector) = selector {
Expand All @@ -39,10 +39,25 @@ pub fn disassemble_property(property: &str) -> Vec<String> {
GLOBAL_STYLE_PROPERTY
.get(property)
.map(|v| match v.len() {
1 => vec![to_camel_case(v[0])],
_ => v.iter().map(|v| to_camel_case(v)).collect(),
1 => vec![v[0].to_string()],
_ => v.iter().map(|v| v.to_string()).collect(),
})
.unwrap_or_else(|| {
vec![if (property.starts_with("Webkit")
&& property.len() > 6
&& property.chars().nth(6).unwrap().is_uppercase())
|| (property.starts_with("Moz")
&& property.len() > 3
&& property.chars().nth(3).unwrap().is_uppercase())
|| (property.starts_with("ms")
&& property.len() > 2
&& property.chars().nth(2).unwrap().is_uppercase())
{
format!("-{}", to_kebab_case(property))
} else {
to_kebab_case(property)
}]
})
.unwrap_or_else(|| vec![property.to_string()])
}

pub fn keyframes_to_keyframes_name(keyframes: &str) -> String {
Expand Down Expand Up @@ -424,7 +439,7 @@ mod tests {
".cls::placeholder"
);
assert_eq!(
merge_selector("cls", Some(&"themeDark".into())),
merge_selector("cls", Some(&"theme-dark".into())),
":root[data-theme=dark] .cls"
);
assert_eq!(
Expand All @@ -447,7 +462,7 @@ mod tests {
);

assert_eq!(
merge_selector("cls", Some(&["themeDark", "hover"].into()),),
merge_selector("cls", Some(&["theme-dark", "hover"].into()),),
":root[data-theme=dark] .cls:hover"
);
assert_eq!(
Expand Down
Loading