@flairjs/core
v0.0.2
Published
Core module for flairjs
Maintainers
Readme
@flairjs/core
The core transformation engine for Flair, built with Rust for maximum performance.
Overview
This package contains the core logic for transforming JSX files with Flair styles. It uses:
- OXC for fast AST parsing and manipulation
- Lightning CSS for CSS parsing, transformation, and optimization
- NAPI-RS for Node.js bindings
Installation
npm install @flairjs/coreYou normally won't have to install this manually, it will be included with the bundler package.
API
transformCode(code, filePath, options, cssPreprocessor?)
Transforms JSX/TSX code containing Flair styles.
Parameters:
code: string- The source code to transformfilePath: string- Path to the file being transformedoptions: TransformOptions- Transformation optionscssPreprocessor?: (css: string) => string- Optional CSS preprocessor function
Returns: TransformOutput | null
TransformOptions
interface TransformOptions {
cssOutDir: string // Output directory for generated CSS
classNameList?: Array<string> // List of class names to process
useTheme?: boolean // Enable theme processing
theme?: Theme // Theme configuration
appendTimestampToCssFile?: boolean // Add timestamp to CSS filename
}TransformOutput
interface TransformOutput {
code: string // Transformed JavaScript/TypeScript code
sourcemap?: string // Source map (if generated)
css: string // Extracted CSS
logs: Array<LogEntry> // Build logs and warnings
generatedCssName?: string // Name of generated CSS file
}Theme Interface
interface Theme {
breakpoints: Record<string, string>
prefix?: string
}Platform Support
This package includes native binaries for:
- Windows (x64, x86, ARM64)
- macOS (x64, ARM64)
- Linux (x64, ARM64, ARMv7, musl variants)
- FreeBSD (x64)
- Android (ARM64, ARMv7)
- WebAssembly (WASI)
Development
Building from Source
# Install Rust and Node.js dependencies
pnpm install
# Build the native module in debug mode
pnpm run build:debug
# Or prod build
pnpm run build
# Run tests
pnpm testArchitecture
The core is structured as follows:
src/lib.rs- Main entry point and NAPI bindingssrc/transform.rs- Core transformation logicsrc/parse_css.rs- CSS parsing and processingsrc/style_tag.rs-<Style>tag handlingsrc/flair_property.rs-.flairproperty processingsrc/update_attribute.rs- Class name injection
License
MIT
