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/cyan-houses-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@devup-ui/wasm": patch
---

Add grid, minify css
9 changes: 9 additions & 0 deletions .changeset/mean-zebras-raise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@devup-ui/webpack-plugin": patch
"@devup-ui/wasm": patch
"@devup-ui/next-plugin": patch
"@devup-ui/vite-plugin": patch
"@devup-ui/react": patch
---

Update package
13 changes: 8 additions & 5 deletions bindings/devup-ui-wasm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"name": "@devup-ui/wasm",
"version": "0.1.4",
"scripts": {
"build": "wasm-pack build --target nodejs --out-dir ./pkg --out-name index",
"test": "wasm-pack test --node"
},
"sideEffects": false,
"main": "./pkg/index.js",
"module": "./pkg/index.js",
"keywords": [
"react",
"css-in-js",
Expand All @@ -22,9 +29,5 @@
"types": "./pkg/index.d.ts"
}
},
"types": "./pkg/index.d.ts",
"scripts": {
"build": "wasm-pack build --target nodejs --out-dir ./pkg --out-name index",
"test": "wasm-pack test --node"
}
"types": "./pkg/index.d.ts"
}
9 changes: 9 additions & 0 deletions libs/css/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ pub fn sheet_to_classname(
})
}

pub fn css_to_classname(css: &str) -> String {
let mut map = GLOBAL_CLASS_MAP.lock().unwrap();
map.get(css).map(|v| format!("d{}", v)).unwrap_or_else(|| {
let len = map.len();
map.insert(css.to_string(), len as i32);
format!("d{}", map.len() - 1)
})
}

pub fn sheet_to_variable_name(property: &str, level: u8, selector: Option<&str>) -> String {
let key = format!("{}-{}-{}", property, level, selector.unwrap_or(""));
let mut map = GLOBAL_CLASS_MAP.lock().unwrap();
Expand Down
23 changes: 23 additions & 0 deletions libs/extractor/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub enum ExportVariableKind {
VStack,
Center,
Image,
Grid,
}

impl ExportVariableKind {
Expand All @@ -20,6 +21,7 @@ impl ExportVariableKind {
match self {
ExportVariableKind::Center
| ExportVariableKind::VStack
| ExportVariableKind::Grid
| ExportVariableKind::Flex
| ExportVariableKind::Box => Ok("div"),
ExportVariableKind::Text => Ok("span"),
Expand Down Expand Up @@ -82,6 +84,12 @@ impl ExportVariableKind {
}),
]
}
ExportVariableKind::Grid => vec![Static(ExtractStaticStyle {
value: "grid".to_string(),
property: "display".to_string(),
level: 0,
selector: None,
})],
}
}
}
Expand All @@ -99,6 +107,7 @@ impl TryFrom<String> for ExportVariableKind {
"Flex" => Ok(ExportVariableKind::Flex),
"VStack" => Ok(ExportVariableKind::VStack),
"Center" => Ok(ExportVariableKind::Center),
"Grid" => Ok(ExportVariableKind::Grid),
_ => Err(()),
}
}
Expand Down Expand Up @@ -142,6 +151,10 @@ mod tests {
ExportVariableKind::try_from("Center".to_string()),
Ok(ExportVariableKind::Center)
);
assert_eq!(
ExportVariableKind::try_from("Grid".to_string()),
Ok(ExportVariableKind::Grid)
);
assert!(ExportVariableKind::try_from("css".to_string()).is_err());
assert!(ExportVariableKind::try_from("foo".to_string()).is_err());
}
Expand All @@ -156,6 +169,7 @@ mod tests {
assert_eq!(ExportVariableKind::Flex.to_tag(), Ok("div"));
assert_eq!(ExportVariableKind::VStack.to_tag(), Ok("div"));
assert_eq!(ExportVariableKind::Center.to_tag(), Ok("div"));
assert_eq!(ExportVariableKind::Grid.to_tag(), Ok("div"));
}

#[test]
Expand Down Expand Up @@ -214,5 +228,14 @@ mod tests {
})
]
);
assert_eq!(
ExportVariableKind::Grid.extract(),
vec![Static(ExtractStaticStyle {
value: "grid".to_string(),
property: "display".to_string(),
level: 0,
selector: None,
})]
);
}
}
10 changes: 2 additions & 8 deletions libs/extractor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ use oxc_codegen::Codegen;

use crate::utils::convert_value;
use crate::visit::DevupVisitor;
use css::{sheet_to_classname, sheet_to_variable_name};
use css::{css_to_classname, sheet_to_classname, sheet_to_variable_name};
use oxc_allocator::Allocator;
use oxc_ast::ast::Expression;
use oxc_ast::VisitMut;
use oxc_parser::{Parser, ParserReturn};
use oxc_span::SourceType;
use std::error::Error;
use std::hash::{DefaultHasher, Hasher};

/// result of extracting style properties from props
#[derive(Debug)]
Expand Down Expand Up @@ -109,9 +108,7 @@ pub struct ExtractCss {
impl ExtractStyleProperty for ExtractCss {
/// hashing css code to class name
fn extract(&self) -> StyleProperty {
let mut hasher = DefaultHasher::new();
hasher.write(self.css.as_bytes());
StyleProperty::ClassName(format!("d{}", hasher.finish()))
StyleProperty::ClassName(css_to_classname(self.css.as_str()))
}
}

Expand Down Expand Up @@ -234,7 +231,6 @@ mod tests {
use css::reset_class_map;
use insta::assert_debug_snapshot;
use serial_test::serial;
use std::hash::{DefaultHasher, Hasher};

#[test]
#[serial]
Expand Down Expand Up @@ -842,8 +838,6 @@ mod tests {
#[test]
#[serial]
fn extract_static_css_class_name_props() {
let mut hasher = DefaultHasher::new();
hasher.write("background-color: red;".as_bytes());
reset_class_map();
assert_debug_snapshot!(extract(
"test.tsx",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ ExtractOutput {
},
),
],
code: "import \"@devup-ui/core/devup-ui.css\";\nimport { css } from \"@devup-ui/core\";\n<Box className={css`d10128267434031712411`} />;\n",
code: "import \"@devup-ui/core/devup-ui.css\";\nimport { css } from \"@devup-ui/core\";\n<Box className={css`d0`} />;\n",
}
13 changes: 8 additions & 5 deletions packages/next-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"name": "@devup-ui/next-plugin",
"version": "0.1.6",
"type": "module",
"dependencies": {
"@devup-ui/webpack-plugin": "workspace:*",
"next": "^15.1"
},
"version": "0.1.6",
"scripts": {
"lint": "eslint",
"build": "tsc && vite build"
},
"sideEffects": false,
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"exports": {
".": {
"import": "./dist/index.js",
Expand All @@ -20,6 +19,10 @@
"dist"
],
"types": "./dist/index.d.ts",
"dependencies": {
"@devup-ui/webpack-plugin": "workspace:*",
"next": "^15.1"
},
"devDependencies": {
"vite": "^6.0.7",
"vite-plugin-dts": "^4.4.0",
Expand Down
11 changes: 7 additions & 4 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
"name": "@devup-ui/react",
"version": "0.1.1",
"type": "module",
"dependencies": {
"react": "^19.0",
"csstype": "^3.1"
},
"scripts": {
"lint": "eslint",
"build": "vite build"
},
"sideEffects": false,
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"exports": {
".": {
"import": "./dist/index.js",
Expand All @@ -20,6 +19,10 @@
"dist"
],
"types": "./dist/index.d.ts",
"dependencies": {
"react": "^19.0",
"csstype": "^3.1"
},
"devDependencies": {
"vite": "^6.0.7",
"vite-plugin-dts": "^4.4.0",
Expand Down
19 changes: 11 additions & 8 deletions packages/vite-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
"lint": "eslint",
"build": "tsc && vite build"
},
"dependencies": {
"@devup-ui/wasm": "workspace:*"
},
"devDependencies": {
"vite-plugin-dts": "^4.5.0",
"typescript": "^5.7.2"
},
"sideEffects": false,
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
Expand All @@ -22,7 +19,13 @@
"files": [
"dist"
],
"types": "./dist/index.d.ts",
"dependencies": {
"@devup-ui/wasm": "workspace:*"
},
"devDependencies": {
"vite-plugin-dts": "^4.5.0",
"typescript": "^5.7.2"
},
"peerDependencies": {
"vite": "*"
}
Expand Down
11 changes: 7 additions & 4 deletions packages/webpack-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
"lint": "eslint",
"build": "tsc && vite build"
},
"dependencies": {
"@devup-ui/wasm": "workspace:*"
},
"sideEffects": false,
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
Expand All @@ -22,7 +23,9 @@
"files": [
"dist"
],
"types": "./dist/index.d.ts",
"dependencies": {
"@devup-ui/wasm": "workspace:*"
},
"devDependencies": {
"vite": "^6.0.7",
"@types/webpack": "^5.28.5",
Expand Down
Loading