@barocss/server
v0.0.3
Published
[](https://www.npmjs.com/package/@barocss/server) [](https://opensource.org/licenses/MIT) [;
// Generate CSS for a single class
const css = runtime.generateCss('bg-blue-500 text-white p-4');
console.log(css);
// Output: .bg-blue-500 { background-color: #3b82f6; }
// .text-white { color: #ffffff; }
// .p-4 { padding: 1rem; }Batch Processing
import { ServerRuntime } from '@barocss/server';
const runtime = new ServerRuntime();
// Process multiple classes at once
const classes = [
'bg-blue-500',
'text-white',
'p-4',
'rounded-lg',
'shadow-md'
];
const results = runtime.generateCssForClasses(classes);
results.forEach(({ className, css }) => {
console.log(`${className}: ${css}`);
});🎯 How It Works
The server runtime provides server-side CSS generation:
- Class Parsing - Parses Tailwind classes using @barocss/kit
- CSS Generation - Generates CSS rules without browser dependencies
- Batch Processing - Efficiently processes multiple classes
- Static Output - Returns CSS strings ready for server use
import { ServerRuntime } from '@barocss/server';
const runtime = new ServerRuntime();
// Parse and generate CSS
const css = runtime.generateCss('bg-red-500 hover:bg-red-600 text-white p-4');
// Result:
// .bg-red-500 { background-color: #ef4444; }
// .hover\:bg-red-600:hover { background-color: #dc2626; }
// .text-white { color: #ffffff; }
// .p-4 { padding: 1rem; }🛠️ Usage Examples
Basic Server Usage
import { ServerRuntime } from '@barocss/server';
const runtime = new ServerRuntime({
theme: {
extend: {
colors: {
'brand': {
500: '#0ea5e9',
600: '#0284c7'
}
}
}
}
});
// Generate CSS for specific classes
const css = runtime.generateCss('bg-brand-500 text-white p-4');
console.log(css);Processing Multiple Classes
import { ServerRuntime } from '@barocss/server';
const runtime = new ServerRuntime();
// Process a list of classes
const classes = [
'bg-blue-500',
'text-white',
'p-4',
'rounded-lg',
'shadow-md'
];
const results = runtime.generateCssForClasses(classes);
results.forEach(({ className, css }) => {
console.log(`${className}: ${css}`);
});🔧 Configuration
Server Runtime Options
import { ServerRuntime } from '@barocss/server';
const runtime = new ServerRuntime({
theme: {
extend: {
colors: {
'brand': {
50: '#f0f9ff',
500: '#0ea5e9',
900: '#0c4a6e',
}
},
spacing: {
'18': '4.5rem',
'88': '22rem',
}
}
},
darkMode: 'class',
cssVarPrefix: '--baro-'
});Custom Theme Functions
const runtime = new ServerRuntime({
theme: {
spacing: (theme) => ({
...theme('spacing'),
'18': '4.5rem',
'88': '22rem',
}),
colors: (theme) => ({
...theme('colors'),
'brand': {
500: '#0ea5e9',
600: '#0284c7'
}
})
}
});🌐 API Reference
ServerRuntime
class ServerRuntime {
constructor(config?: Config)
// Parse a class name and return its AST
parseClass(className: string): AstNode[]
// Generate CSS for a single class
generateCss(className: string): string
// Generate CSS for multiple classes
generateCssForClasses(classes: string[]): Array<{
className: string;
css: string;
}>
}Usage Examples
import { ServerRuntime } from '@barocss/server';
const runtime = new ServerRuntime();
// Parse class to AST
const ast = runtime.parseClass('bg-blue-500 hover:bg-blue-600');
console.log(ast);
// Generate CSS for single class
const css = runtime.generateCss('bg-blue-500 text-white p-4');
console.log(css);
// Generate CSS for multiple classes
const results = runtime.generateCssForClasses([
'bg-blue-500',
'text-white',
'p-4'
]);
console.log(results);🚀 Performance Features
- Batch Processing - Efficiently processes multiple classes
- Memory Optimization - Optimized for server environments
- Static Generation - Perfect for build-time CSS generation
- No Browser Dependencies - Runs entirely in Node.js
🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development
# Clone repository
git clone https://github.com/easylogic/barocss.git
cd barocss
# Install dependencies
pnpm install
# Start development server
pnpm dev
# Run tests
pnpm test
# Build packages
pnpm build📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- Tailwind CSS - For the amazing utility-first approach and JIT inspiration
- UnoCSS - For ideas around on-demand, utility-first generation at runtime
@barocss/server - Server-side CSS generation and processing.
