tcss-core

Crates.iotcss-core
lib.rstcss-core
version1.0.0
created_at2025-12-24 16:22:03.283207+00
updated_at2025-12-24 16:22:03.283207+00
descriptionCore library for TCSS (Thematic CSS) - CSS with functions, variables, and expressions
homepagehttps://github.com/tosiiko/TCSS
repositoryhttps://github.com/tosiiko/TCSS
max_upload_size
id2003540
size254,269
john tosiiko (tosiiko)

documentation

https://docs.rs/tcss-core

README

TCSS - Thematic CSS

A powerful CSS preprocessor that adds functions, variables, and expressions to CSS with Python-style indentation.

Build Status License Rust

๐ŸŽฏ Project Status

Version 1.0.0 - Production Ready! ๐ŸŽ‰

All 12 Phases: COMPLETE โœ…

Completed Features โœ…

  • โœ… Lexer & Parser - Full TCSS syntax support
  • โœ… Executor - Function execution and variable resolution
  • โœ… CSS Generator - Optimized CSS output with minification
  • โœ… CLI Tool - Command-line interface with watch mode
  • โœ… WASM Bindings - Browser support via WebAssembly
  • โœ… JavaScript Integration - npm package and browser loader
  • โœ… 24 Built-in Functions - Colors, math, and string utilities
  • โœ… Import System - File imports with circular detection and caching
  • โœ… Comprehensive Tests - 150+ tests with 80%+ code coverage
  • โœ… Complete Documentation - 2,000+ lines of documentation
  • โœ… Performance Optimization - Benchmarks and optimized builds
  • โœ… Publishing Ready - Prepared for crates.io and npm

โœจ Features

  • โœ… Variables - Define reusable values
  • โœ… Functions - Create custom functions with parameters
  • โœ… Expressions - Perform calculations in CSS
  • โœ… 24 Built-in Functions - Colors, math, and string utilities
  • โœ… Import System - Split code across multiple files
  • โœ… Python-style Indentation - Clean, readable syntax
  • โœ… Type Safety - Compile-time type checking
  • โœ… Zero Runtime - Compiles to pure CSS
  • โœ… WASM Support - Run in the browser
  • โœ… Fast - Written in Rust for maximum performance

๐Ÿ“ฆ Project Structure

TCSS/
โ”œโ”€โ”€ tcss-core/           # Core compiler library โœ…
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ lexer.rs     # Tokenizer โœ…
โ”‚   โ”‚   โ”œโ”€โ”€ parser.rs    # AST parser โœ…
โ”‚   โ”‚   โ”œโ”€โ”€ executor.rs  # Function executor โœ…
โ”‚   โ”‚   โ”œโ”€โ”€ generator.rs # CSS generator โœ…
โ”‚   โ”‚   โ”œโ”€โ”€ import.rs    # Import processor โœ…
โ”‚   โ”‚   โ”œโ”€โ”€ resolver.rs  # Path resolver โœ…
โ”‚   โ”‚   โ””โ”€โ”€ builtins/    # Built-in functions โœ…
โ”‚   โ””โ”€โ”€ tests/           # Comprehensive test suite โœ…
โ”œโ”€โ”€ tcss-cli/            # Command-line interface โœ…
โ”œโ”€โ”€ tcss-wasm/           # WebAssembly bindings โœ…
โ”œโ”€โ”€ tcss-js/             # JavaScript wrapper โœ…
โ”œโ”€โ”€ docs/                # Complete documentation โœ…
โ””โ”€โ”€ examples/            # Example projects โœ…

๐Ÿš€ Quick Start

Installation

# Using Cargo
cargo install tcss-cli

# Using npm
npm install tcss-js

Your First TCSS File

styles.tcss:

@var primary: #3498db
@var spacing: 16px

@fn button-padding(size):
    return size * spacing

.button:
    background: primary
    padding: button-padding(1)
    border-radius: 4px
    color: white

.button:hover:
    background: lighten(primary, 10)

Compile

tcss compile styles.tcss -o styles.css

Output

.button {
    background: #3498db;
    padding: 16px;
    border-radius: 4px;
    color: white;
}

.button:hover {
    background: #5dade2;
}

๐Ÿ“š Documentation

Getting Started

API & Reference

Development

Publishing

๐Ÿ’ก Examples

Variables & Functions

@var primary-color: #3498db
@var base-spacing: 16px

@fn spacing(multiplier):
    return multiplier * base-spacing

.card:
    padding: spacing(2)
    background: primary-color

Built-in Functions

// Color manipulation
.button:
    background: darken(#3498db, 10)
    border-color: lighten(#3498db, 10)
    color: rgba(255, 255, 255, 0.9)

// Math operations
.box:
    width: max(100px, 50%)
    padding: clamp(16px, 2vw, 32px)

// String utilities
.text:
    font-family: uppercase("arial")

Imports

@import './colors.tcss'
@import './theme/base.tcss'
@import '@tcss/core'

.button:
    background: primary

๐Ÿงช Testing

Run the comprehensive test suite:

# Run all tests
cargo test

# Run specific test suite
cargo test --test integration_tests
cargo test --test e2e_tests

# Run with coverage
cargo tarpaulin --out Html

Test Coverage: 80%+

  • โœ… Unit Tests - All core modules (lexer, parser, executor, generator, etc.)
  • โœ… Integration Tests - End-to-end compilation workflows
  • โœ… E2E Tests - File I/O, imports, and complete workflows
  • โœ… Built-in Function Tests - All 24 built-in functions
  • โœ… Import System Tests - Circular detection, caching, resolution

๐Ÿ› ๏ธ Usage

CLI

# Compile a file
tcss compile input.tcss -o output.css

# Compile with minification
tcss compile input.tcss -o output.css --minify

# Watch for changes
tcss watch input.tcss -o output.css

Rust API

use tcss_core::{Lexer, Parser, Executor, Generator};

let source = r#"
    @var primary: #3498db
    .button:
        background: primary
"#;

let mut lexer = Lexer::new(source);
let tokens = lexer.tokenize()?;
let mut parser = Parser::new(tokens);
let program = parser.parse()?;
let mut executor = Executor::new();
let executed = executor.execute(&program)?;
let mut generator = Generator::new();
let css = generator.generate(&executed)?;

JavaScript API

import { compile } from 'tcss-js';

const tcss = `
@var primary: #3498db

.button:
    background: primary
`;

const css = compile(tcss);

Browser

<link rel="tcss" href="styles.tcss">
<script type="module">
    import { init } from './tcss-js/index.js';
    await init();
</script>

๐Ÿ“‹ Development Roadmap

  • Phase 1: Core Lexer/Tokenizer โœ…
  • Phase 2: AST Parser โœ…
  • Phase 3: Expression Evaluator โœ…
  • Phase 4: CSS Generator โœ…
  • Phase 5: Error Handling โœ…
  • Phase 6: CLI Tool โœ…
  • Phase 7: WebAssembly Bindings โœ…
  • Phase 8: JavaScript Integration โœ…
  • Phase 9: Built-in Functions Library โœ…
  • Phase 10: Import System โœ…
  • Phase 11: Testing & Documentation โœ…
  • Phase 12: Optimization & Publishing โœ…

๐Ÿ› ๏ธ Technology Stack

  • Rust - Core implementation language
  • wasm-bindgen - WebAssembly bindings
  • serde - Serialization framework
  • clap - CLI argument parsing
  • tempfile - Testing utilities

๐Ÿค Contributing

Contributions are welcome! Please read our Contributing Guide for details.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Inspired by Sass, Less, and Stylus
  • Built with Rust for performance and safety
  • Uses wasm-bindgen for WebAssembly support

๐Ÿ’ฌ Support


Made with โค๏ธ by TCSS Contributors

Current Version: 1.0.0 - Production Ready! ๐ŸŽ‰

Commit count: 0

cargo fmt