Skip to content

BaroCSS API Reference

BaroCSS provides a comprehensive API for real-time CSS generation and utility-first styling. This section covers all the core APIs, runtime systems, and configuration options.

🚀 Quick Start

typescript
import { BrowserRuntime } from 'barocss/runtime/browser';
import { createContext } from 'barocss';

// Initialize runtime
const runtime = new BrowserRuntime({
  config: {
    theme: {
      extend: {
        colors: {
          brand: '#3b82f6'
        }
      }
    }
  }
});

// Start watching DOM changes
runtime.observe(document.body, { scan: true });

📚 API Overview

Core APIs

Runtime APIs

Extension APIs

🎯 Main Entry Points

Browser Usage

typescript
// CDN
import { BrowserRuntime } from 'https://unpkg.com/barocss/dist/cdn/barocss.js';

// NPM
import { BrowserRuntime } from 'barocss/runtime/browser';

Server Usage

typescript
import { ServerRuntime } from 'barocss/runtime/server';
import { createContext, generateCss } from 'barocss';

Core Usage

typescript
import { 
  createContext, 
  parseClassToAst, 
  generateCss,
  IncrementalParser 
} from 'barocss';

🔧 Key Concepts

Context

The central configuration and theme management system that provides access to theme values, configuration options, and plugin functionality.

Engine

The core CSS generation system that parses class names, builds ASTs, and converts them to CSS rules.

Runtime

Environment-specific implementations that handle CSS injection (browser) or generation (server).

Plugins

Extensible system for adding custom utilities, variants, and theme extensions.

📖 API Categories

Core Functions

  • createContext(config) - Create a BaroCSS context
  • parseClassToAst(className, ctx) - Parse class to AST
  • generateCss(classList, ctx) - Generate CSS from classes
  • IncrementalParser - Efficient class processing

Runtime Classes

  • BrowserRuntime - Browser DOM integration
  • ServerRuntime - Server-side processing
  • ChangeDetector - DOM change monitoring

Plugin System

  • registerUtility() - Register custom utilities
  • registerModifier() - Register custom variants
  • Plugin interface - Plugin development

Configuration

  • Config interface - Configuration options
  • Theme interface - Theme structure
  • Theme extension and customization

🎨 Usage Patterns

Basic Styling

typescript
const runtime = new BrowserRuntime();
runtime.addClass('bg-blue-500 text-white p-4');

Custom Theme

typescript
const ctx = createContext({
  theme: {
    extend: {
      colors: {
        brand: {
          50: '#eff6ff',
          500: '#3b82f6',
          900: '#1e3a8a'
        }
      }
    }
  }
});

Plugin Development

typescript
const customPlugin = (ctx) => {
  ctx.extendTheme('colors', {
    'custom-blue': '#1e40af'
  });
};

Ready to dive deeper? Start with the Context API to understand how BaroCSS manages themes and configuration.

Released under the MIT License.