css2xr 🎨🕶️
css2xr is a lightweight, pure Rust HTML/CSS layout engine designed for WebXR. It parses HTML/CSS strings and calculates layout (Flexbox, Grid), styles, and animations, outputting a JSON structure ready to be rendered in 3D space (e.g., via Three.js or A-Frame).
✨ Features
- Layout Engine:
- Flexbox:
row,column,justify-content,align-items,flex-grow,gap - CSS Grid:
grid-template-columns/rows(fr, px),grid-column/row,gap - Box Model:
margin,padding,width,height,position(absolute/relative)
- Flexbox:
- Styling:
- Colors (hex, rgba, names),
opacity,border-radius - 3D Transforms:
translate3d,rotate3d,scale3d
- Colors (hex, rgba, names),
- Animation:
- Full
@keyframessupport - Properties:
opacity,transform,background-color
- Full
- Interaction:
- Event binding (
onclick,onmouseenter, etc.) - Cursor states
- Event binding (
- Portable:
- Compiles to WebAssembly (WASM)
- No DOM dependency (Runs in Web Worker)
🚀 Usage
1. Build WASM
2. JavaScript Integration
import init from './pkg/css2xr.js';
3. Output Format (JSON)
The engine outputs a flat array of elements with calculated geometry:
📄 License
This project is licensed under the Mozilla Public License 2.0 (MPL-2.0). See the LICENSE file for details.