# AsterUI (@fierst/ui) 1.0.2 > Code-owned TSX components for Aster. This single-file manual contains installation, theming, integration and the public API for every registry item. # AsterUI AsterUI (`@fierst/ui`) is a source registry for Aster applications. Installing a registry item copies TypeScript, TSX and CSS into your project. Import the named exports from those local files. You can edit, test and version them with the rest of your application. ## Install and render your first component Start in the root of an Aster project using Node.js 20.19 or later, `@fierst/aster@^1.2.0`, and the Aster Vite plugin. With Vite+ installed, run the following commands. You can also use `npx @fierst/ui` in place of `vp dlx @fierst/ui`. ```sh vp dlx @fierst/ui init vp add @lucide/icons vp dlx @fierst/ui add button ``` In `src/main.tsx`, mount a button into the starter page's `#app` element. ```tsx import { render } from '@fierst/aster'; import { Button } from './ui/button'; import { initTheme, setTheme } from './ui/theme'; initTheme(); render( , document.getElementById('app')!, ); ``` Run your project's development server (`vp dev` in the starter). Components import the shared stylesheet automatically. Import `./ui/theme.css` yourself on pages that use only the tokens or controller. ## Documentation - [Component and API reference](https://github.com/fierstdev/ui/blob/v1.0.2/docs/components.md) lists every registry item, companion export, prop type, callback, dependency and source file. - [Theme cookbook](https://github.com/fierstdev/ui/blob/v1.0.2/docs/themes.md) covers presets, light/dark/system switching, saved preferences, custom palettes and accessible styling. - [Integration guide](https://github.com/fierstdev/ui/blob/v1.0.2/docs/integration.md) covers CLI flags, code-owned updates, programmatic installation, state, forms, overlays, charts, AI workflows and all eight generator flows. - [Design guide](https://github.com/fierstdev/ui/blob/v1.0.2/DESIGN.md) describes the visual system. - [Single-file reference for language models](https://github.com/fierstdev/ui/blob/v1.0.2/llms.txt) combines the guides and API contracts in one text file. The showcase build serves it at `/llms.txt`. - [Release history](https://github.com/fierstdev/ui/blob/v1.0.2/CHANGELOG.md) records changes to installed components. [Explore the showcase](https://ui.fierst.dev). ## Working on the registry Install dependencies with `pnpm install --frozen-lockfile`. Edit component source under `src/ui` and item metadata in `registry.json`. Run `npm run build:registry` to refresh the static manifests and `npm run build:docs` to refresh the API reference and single-file guide. Run `npm run check`, `npm test`, `npm run build` and `npm run test:browser` before release. The browser suite uses Playwright Chromium. # Themes ## Choose a starting theme Call `initTheme()` once in the browser entry before mounting. Its defaults are system mode, blue preset, medium radius and comfortable density. CSS works before JavaScript runs. For a specific first paint, render the corresponding attributes on the document root, for example ``. If your server knows the user's preferences, use the same values on both sides. The controller stores state in a module-level signal, so keep per-request preferences in the rendered HTML during SSR. | Preset | Seed hue | Seed chroma | | ------- | -------: | ----------: | | zinc | 285 | 0.006 | | blue | 255 | 0.20 | | emerald | 158 | 0.16 | | violet | 285 | 0.20 | | rose | 16 | 0.20 | | amber | 55 | 0.18 | `THEME_PRESETS` supplies each preset's id, display label, hue and swatch for a picker. The zinc preset has explicit monochrome primary roles. Use a chromatic preset as the base for a custom accent. ## Switch and remember preferences ```tsx import { THEME_PRESETS, initTheme, setTheme, themeState } from './ui/theme'; initTheme({ preset: 'emerald' }); // A saved preference takes precedence. export function* ThemePicker() { for (;;) { const current = themeState(); yield (
); } } ``` `system` follows the OS via `prefers-color-scheme`, including later OS changes. Explicit light and dark modes override it. `setTheme(patch)` merges fields, updates the signal and root attributes, and writes the entire configuration to local storage under `aster-ui-theme`. `setTheme(patch, false)` applies a temporary change. The next persisted change saves the then-current configuration. Use `themeState()` for reactive reads and `themeState.peek()` for snapshots. Apply changes through `setTheme` so the DOM and storage stay in sync. `initTheme(defaults)` merges current state, supplied defaults, then saved values and returns the result. Storage access and JSON parse failures are tolerated. To restore factory settings and remember them, call `setTheme({ mode: 'system', preset: 'blue', radius: 'md', density: 'comfortable', customHue: undefined })`. ## Build a custom theme For a user-selected accent, supply a numeric hue in degrees. Clearing `customHue` restores the preset seed. Radius options are `none`, `sm`, `md`, and `lg` (control radii 0, 6, 8 and 12 px). Density options are `compact` (0.9) and `comfortable` (1). Coarse pointers use dedicated control sizes. ```ts setTheme({ preset: 'blue', customHue: 205, radius: 'lg', density: 'compact' }); ``` For a named brand, add an application stylesheet after the theme import. The library defines its defaults in CSS cascade layers. Keep your brand rules unlayered. Put the seed on the root where the derived tokens are computed. Give your brand its own attribute, leaving the typed preset field available to the controller. ```css :root[data-brand='lagoon'] { --aster-seed-hue: 205; --aster-seed-chroma: 0.14; --aster-neutral-tint: 0.006; --aster-font-sans: system-ui, sans-serif; } ``` ```ts setTheme({ preset: 'blue', customHue: undefined }); document.documentElement.dataset.brand = 'lagoon'; // Return to the selected built-in preset: delete document.documentElement.dataset.brand; ``` Persist the application-owned brand separately if users can select it. A controller-set custom hue is an inline CSS property and takes precedence over stylesheet seeds. To add a preset to your owned copy itself, extend `ThemePreset`, add its id/label/hue/swatch to `THEME_PRESETS`, and add its `:root[data-aster-preset='…']` seed rules in `theme.css`. Use semantic roles in app CSS, for example `background: var(--aster-surface)` and `color: var(--aster-on-surface)`. The seed drives OKLCH-derived roles where supported. The stylesheet also defines static sRGB fallbacks. For an exact brand color across browsers override the semantic roles directly, including hover, foreground, subtle fill/ink, border and focus ring. Provide dark values for both explicit dark mode and system dark mode. Verify contrast, focus, disabled controls and chart labels under each mode. Individual components can also define local styling; edit their owned source for exceptions. The shared stylesheet defines global box sizing, body colors and typography, modal scroll locking and popover surfaces. It adjusts borders for increased contrast, transition durations for reduced motion, and touch control sizes for coarse pointers. The component reference includes the full token inventory. # Integrating AsterUI ## Install, inspect and update owned files | Command or option | Behavior | | ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------ | | `vp dlx @fierst/ui list` | List slugs, descriptions and direct registry dependencies. | | `vp dlx @fierst/ui init` | Install the shared theme controller, CSS and Lucide icon helper. | | `vp dlx @fierst/ui add dialog toast` | Resolve both items and their transitive registry dependencies once, then copy their files. You can use add without init. | | `--dir src/controls` | Change the destination from `src/ui`. Use the same directory for related items so sibling imports resolve. | | `--registry ./public/r` | Read index.json and item manifests from a local directory. The default registry ships in the npm package. | | `--registry https://ui.fierst.dev/r` | Read manifests from an HTTP(S) base URL. | | `--force` | Replace existing target files, including resolved dependencies. Without this flag existing files are skipped. | Run the npm dependency command printed by the installer. Registry dependencies are other source items, while package dependencies such as `@lucide/icons` belong in the consuming project. Use a versioned invocation such as `npx @fierst/ui@1.0.2 add dialog` for reproducible installs from the bundled registry. To update edited components, install the new version into a separate directory, compare the files and merge the changes you want. Include theme and icon dependencies in that comparison. The Node API is available after installing `@fierst/ui` as a development dependency. Both functions return promises. ```js import { addComponents, listRegistryItems } from '@fierst/ui/bin/aster-ui.mjs'; const items = await listRegistryItems(); const result = await addComponents(['dialog', 'toast'], process.cwd(), { uiDir: 'src/ui', force: false, }); console.log(items.length, result.resolved, result.dependencies, result.copied, result.skipped); ``` Pass a registry path or URL to `listRegistryItems(source)` or use `{ registry: source }` with `addComponents`. The index lists each item's name, type, title, description, dependency arrays and file targets. Each item manifest includes the source content and SHA-256 digest for each file. The installer checks supplied digests and resolves dependencies before copying. If resolution fails, check the slug and registry base; for a checksum error rebuild or replace the inconsistent manifest. ## Render and update components Use TSX with the Aster Vite plugin and `jsxImportSource: "@fierst/aster"`. Render components as JSX, including components implemented as generator functions. Aster supplies their context. In the reference, `View` denotes renderable content, `?` marks an optional prop, and destructuring defaults show the value used when omitted. Each contract names its callbacks and their payloads. Some wrap native events; others deliver the next value directly. For a controlled switch, keep the value in the parent. For a standalone switch, pass `defaultChecked` for the initial value and optionally observe changes with `onChange`. ```tsx import { signal } from '@fierst/aster'; import { Switch } from './ui/switch'; export function* Preferences() { const enabled = signal(true); for (;;) { yield (