@ordojs/core
Version:
Core compiler and runtime for OrdoJS framework
135 lines • 3.62 kB
TypeScript
/**
* @fileoverview CSS-in-JS Compiler for OrdoJS Framework
* Handles compilation of CSS-in-JS expressions to optimized CSS
*/
import { type ExpressionNode, type StyleBlockNode } from '../types/index.js';
/**
* CSS-in-JS compilation options
*/
export interface CSSInJSOptions {
/**
* Whether to generate scoped CSS
*/
scoped?: boolean;
/**
* Prefix for generated class names
*/
classPrefix?: string;
/**
* Whether to optimize generated CSS
*/
optimize?: boolean;
/**
* Whether to generate source maps
*/
generateSourceMaps?: boolean;
}
/**
* CSS-in-JS expression types
*/
export type CSSInJSExpression = CSSObjectExpression | CSSTemplateExpression | CSSFunctionExpression;
/**
* CSS object expression (e.g., { color: 'red', fontSize: '16px' })
*/
export interface CSSObjectExpression {
type: 'CSSObject';
properties: Array<{
key: string;
value: string | number | CSSObjectExpression;
computed?: boolean;
}>;
}
/**
* CSS template expression (e.g., css`color: red; font-size: 16px;`)
*/
export interface CSSTemplateExpression {
type: 'CSSTemplate';
template: string;
expressions: ExpressionNode[];
}
/**
* CSS function expression (e.g., styled.div`...` or css(...))
*/
export interface CSSFunctionExpression {
type: 'CSSFunction';
functionName: string;
arguments: (CSSInJSExpression | string)[];
}
/**
* CSS-in-JS compilation result
*/
export interface CSSInJSCompilationResult {
css: string;
className: string;
styleBlock: StyleBlockNode;
dependencies: string[];
}
/**
* CSS-in-JS Compiler for OrdoJS components
*/
export declare class OrdoJSCSSInJSCompiler {
private options;
private classCounter;
constructor(options?: Partial<CSSInJSOptions>);
/**
* Compile CSS-in-JS expression to CSS
*/
compile(expression: CSSInJSExpression, componentName?: string): CSSInJSCompilationResult;
/**
* Compile CSS-in-JS expression to CSS declarations
*/
private compileExpression;
/**
* Compile CSS object expression
*/
private compileCSSObject;
/**
* Compile CSS template expression
*/
private compileCSSTemplate;
/**
* Compile CSS function expression
*/
private compileCSSFunction;
/**
* Parse CSS declarations from a string
*/
private parseCSSDeclarations;
/**
* Convert camelCase to kebab-case for CSS properties
*/
private camelCaseToKebabCase;
/**
* Normalize CSS value (handle numbers, add units, etc.)
*/
private normalizeCSSValue;
/**
* Generate unique class name
*/
private generateClassName;
/**
* Extract dependencies from CSS-in-JS expression
*/
private extractDependencies;
/**
* Generate CSS string from StyleBlockNode
*/
private generateCSS;
/**
* Compile multiple CSS-in-JS expressions and merge them
*/
compileMultiple(expressions: CSSInJSExpression[], componentName?: string): CSSInJSCompilationResult;
/**
* Create CSS-in-JS expression from JavaScript object
*/
static createCSSObject(obj: Record<string, any>): CSSObjectExpression;
/**
* Create CSS template expression
*/
static createCSSTemplate(template: string, expressions?: ExpressionNode[]): CSSTemplateExpression;
/**
* Create CSS function expression
*/
static createCSSFunction(functionName: string, args: (CSSInJSExpression | string)[]): CSSFunctionExpression;
}
//# sourceMappingURL=css-in-js-compiler.d.ts.map