# TSRX - AI/LLM Documentation ## Overview TSRX (TypeScript Ripple Extensions) is a **TypeScript language extension** for building declarative UIs. It compiles one `.tsrx` source file to **React**, **Solid**, or **Ripple**, with room for more runtime targets. TSRX is the source language; the target picks the runtime semantics. Think of TSRX as a spiritual successor to JSX: the same mental model of embedding UI directly in TypeScript, but with its own flavor. Control flow, scoped styles, and locals sit in the template as first-class syntax instead of being squeezed through expression slots, and the language stays aware of them all the way through to the compiled output. **Key characteristics:** - **One source, many targets**: `@tsrx/react`, `@tsrx/solid`, `@tsrx/ripple` - **Statement-based JSX**: JSX elements are statements, not expressions - **Declarative control flow**: `if`, `for`, `switch`, `try` inside templates - **Lexical template scoping**: declare locals next to the JSX that uses them - **Lazy prop destructuring**: `&{ ... }` and `&[ ... ]` preserve reactivity - **Scoped styles**: per-component ` } ``` **LLM DO:** - Use `component Name(props: Props) { ... }` for any UI building block. - Use `export component` for public components. - Keep the template, event handlers, and ` } ``` ### Escaping scope with `:global()` Wrap a selector in `:global(...)` to opt out of scoping — useful for global resets or targeting child-component DOM. Works on whole selectors, multiple selectors, or parts of a chain: - `:global(.class-name)` - `:global(.foo, .bar)` - `.scoped :global(.unscoped) .also-scoped` ### Style composition via `#style` Because scoped classes don't cross component boundaries, TSRX provides `#style.className` — a compile-time identifier that expands to a string containing both the scope hash and the class name. Pass it to a child, which applies it via its regular `class` attribute. ```tsrx component Badge({ className }: { className?: string }) { {'New'} } component App() { } ``` The class referenced via `#style` must appear as a standalone selector in the surrounding component's `` | | Escape scoping | `:global(.class)` | | Cross-component class | `` | | Dynamic element | `<@tag />` with a `Tracked` / stateful `tag` | ## Resources - **Website**: https://tsrx.dev - **Features**: https://tsrx.dev/features - **Getting Started**: https://tsrx.dev/getting-started - **Playground**: https://tsrx.dev/playground - **Source**: https://github.com/Ripple-TS/ripple/tree/main/packages/tsrx - **Ripple target (runtime APIs)**: https://www.ripple-ts.com/llms.txt This document is optimized for AI/LLM understanding of the TSRX language. For the most up-to-date information, visit https://tsrx.dev or the GitHub repository.