Skip to content

Commit 96fee2a

Browse files
authored
Merge pull request #177 from dev-five-git/fix-vite-plugin
Fix vite plugin, Apply css optimize
2 parents 49cd791 + 04e83bd commit 96fee2a

File tree

169 files changed

+2105
-1977
lines changed

Some content is hidden

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

169 files changed

+2105
-1977
lines changed

.changeset/fast-ravens-rescue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@devup-ui/vite-plugin": patch
3+
---
4+
5+
Fix css duplicate issue when exporting

.changeset/young-chairs-yawn.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+
Apply css optimize

Cargo.lock

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

apps/vite/src/App.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export default function App() {
1414
hello
1515
<Lib />
1616
</Box>
17+
<Text color="#777777"></Text>
18+
<Text color="#777"></Text>
19+
<Text color="#777"></Text>
1720
<Text typography="header">typo</Text>
1821
</div>
1922
)

benchmark/next-chakra-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"lint": "next lint"
1111
},
1212
"dependencies": {
13-
"@chakra-ui/react": "^3.15.0",
13+
"@chakra-ui/react": "^3.15.1",
1414
"@emotion/react": "^11.14.0",
1515
"next": "^15.2.4",
1616
"next-themes": "^0.4.6",

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ static GLOBAL_STYLE_SHEET: Lazy<Mutex<StyleSheet>> =
1313
#[wasm_bindgen]
1414
pub struct Output {
1515
code: String,
16-
styles: Vec<ExtractStyleValue>,
16+
styles: HashSet<ExtractStyleValue>,
1717
}
1818
#[wasm_bindgen]
1919
extern "C" {

libs/css/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ fn optimize_color(value: &str) -> String {
372372
format!("#{}", ret)
373373
}
374374

375-
fn optimize_value(value: &str) -> String {
375+
pub fn optimize_value(value: &str) -> String {
376376
let mut ret = value.trim().to_string();
377377
if ret.contains(",") {
378378
ret = F_SPACE_RE.replace_all(&ret, ",").trim().to_string();

libs/extractor/src/extract_style/mod.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
use crate::utils::convert_value;
21
use crate::StyleProperty;
2+
use crate::utils::convert_value;
33
use css::{
4-
css_to_classname, sheet_to_classname, sheet_to_variable_name, short_to_long, StyleSelector,
4+
StyleSelector, css_to_classname, optimize_value, sheet_to_classname, sheet_to_variable_name,
5+
short_to_long,
56
};
67
use once_cell::sync::Lazy;
78
use std::collections::HashSet;
89

9-
#[derive(Debug, PartialEq, Clone)]
10+
#[derive(Debug, PartialEq, Clone, Eq, Hash, Ord, PartialOrd)]
1011
pub struct ExtractStaticStyle {
1112
/// property
1213
property: String,
@@ -46,11 +47,11 @@ impl ExtractStaticStyle {
4647
/// create a new ExtractStaticStyle
4748
pub fn new(property: &str, value: &str, level: u8, selector: Option<StyleSelector>) -> Self {
4849
Self {
49-
value: if MAINTAIN_VALUE_PROPERTIES.contains(property) {
50+
value: optimize_value(&if MAINTAIN_VALUE_PROPERTIES.contains(property) {
5051
value.to_string()
5152
} else {
5253
convert_value(value)
53-
},
54+
}),
5455
property: short_to_long(property),
5556
level,
5657
selector,
@@ -65,11 +66,11 @@ impl ExtractStaticStyle {
6566
selector: Option<StyleSelector>,
6667
) -> Self {
6768
Self {
68-
value: if MAINTAIN_VALUE_PROPERTIES.contains(property) {
69+
value: optimize_value(&if MAINTAIN_VALUE_PROPERTIES.contains(property) {
6970
value.to_string()
7071
} else {
7172
convert_value(value)
72-
},
73+
}),
7374
property: property.to_string(),
7475
level,
7576
selector,
@@ -109,20 +110,19 @@ impl ExtractStyleProperty for ExtractStaticStyle {
109110
StyleProperty::ClassName(sheet_to_classname(
110111
self.property.as_str(),
111112
self.level,
112-
Some(
113-
if MAINTAIN_VALUE_PROPERTIES.contains(self.property.as_str()) {
113+
Some(&optimize_value(
114+
&if MAINTAIN_VALUE_PROPERTIES.contains(self.property.as_str()) {
114115
self.value.to_string()
115116
} else {
116117
convert_value(self.value.as_str())
117-
}
118-
.as_str(),
119-
),
118+
},
119+
)),
120120
s.as_deref(),
121121
self.style_order,
122122
))
123123
}
124124
}
125-
#[derive(Debug, PartialEq, Clone)]
125+
#[derive(Debug, PartialEq, Clone, Eq, Hash, Ord, PartialOrd)]
126126
pub struct ExtractCss {
127127
/// css code
128128
pub css: String,
@@ -135,7 +135,7 @@ impl ExtractStyleProperty for ExtractCss {
135135
}
136136
}
137137

138-
#[derive(Debug, PartialEq, Clone)]
138+
#[derive(Debug, PartialEq, Clone, Eq, Hash, Ord, PartialOrd)]
139139
pub struct ExtractDynamicStyle {
140140
/// property
141141
property: String,
@@ -207,7 +207,7 @@ impl ExtractStyleProperty for ExtractDynamicStyle {
207207
}
208208
}
209209
}
210-
#[derive(Debug, PartialEq, Clone)]
210+
#[derive(Debug, PartialEq, Clone, Eq, Hash, Ord, PartialOrd)]
211211
pub enum ExtractStyleValue {
212212
Static(ExtractStaticStyle),
213213
Typography(String),

0 commit comments

Comments
 (0)