Outputs
| File | Content |
|---|---|
| generated/theme-tokens.md | Theme Types and light/dark preset TS |
| generated/scss-api.md | _mixins、_functions、_vars full SCSS |
| generated/theme-ts-api.md | UITheme、loadTheme、helper etc. TS |
| generated/manifest.json | Sync time and output file list |
| references/theming-guide.md | Quick start, dark mode, custom themes, component tokens |
Run bun run sync-veltra-styles or bun run sync-skills to regenerate generated/。
Theme data flow (overview)
Themetype(theme/type.ts) describes a nested token tree such as colors, font sizes, borders, etc.UIThemeclass(theme/ui-theme.ts) holds athemeobject, flattens it into--u-*CSS variables and injects them into the document (built-in themes useinjectBuiltInThemes, custom ones userender())。loadTheme()(load-theme.ts) initializes on the browser side: registers light/dark by default, syncsuseConfigdocument size class; optionally pass in customUITheme。- SCSS consumption:
fn.use-var(...)、fn.component-var(...)generatesvar(--u-...), corresponding one-to-one with the injected variables.
BEM quick reference (@veltra/styles/mixins)
Under the premise of @use 'pkg:@veltra/styles/mixins' as m :
| Mixin | Generated class name example | Typical use |
|---|---|---|
@include m.b(name) |
.u-name |
Block root |
@include m.e(el) |
&__el(located within the block) |
Element |
@include m.m(mod) |
&--mod |
Modifier |
@include m.is(state) |
.is-state |
State class |
m.dark() etc. wrapped in generated/scss-api.md 's _mixins.scss to view the full text.
SCSS import trio
@use 'pkg:@veltra/styles/mixins' as m;
@use 'pkg:@veltra/styles/functions' as fn;
@use 'pkg:@veltra/styles/vars';
Consumer builds need Sass NodePackageImporterenabled (already configured in this repository's desktop / playground).
CSS variable helpers (functions)
fn.use-var(text-color, main)→var(--u-text-color-main)(the parameter is a token path fragment).fn.component-var(button, height)→ variables under the component namespace (for specific naming seeThemecorresponding block).
For complete signatures and edge cases, refer to generated/scss-api.md .
TypeScript theme API quick reference
| API | Purpose |
|---|---|
loadTheme(theme?) |
Inject theme; when no arguments are passed, use built-in light + dark presets |
setTheme('light' | 'dark' | 'auto') |
Switch data-theme or follow the system |
UITheme.new(partialTheme) / lightTheme.new(...) |
Derive a custom UITheme |
currentTheme |
ShallowRef<UITheme | undefined>from a preset, the currently active theme instance |
and @veltra/compositions interface
loadTheme internally uses useConfig to attach the global document size class to document.documentElement. Therefore @veltra/styles/theme at runtime depends on vue and @veltra/compositions;compositions packages must not export themeagain, to avoid circular dependencies (see root directory AGENTS.md package graph).
Further reading (legacy reference documentation)
and generated/ mirror each other: locate Sass, theme runtime, and build integration across repositories.
- references/source-discovery.md
- references/scss-foundation.md
- references/theme-runtime.md
- references/integration.md
Maintenance
- Authoritative source:
packages/styles/src/(SCSS partial andtheme/、load-theme.ts)。 - After changing tokens or theme logic, run
bun run sync-veltra-styles/sync-skills, and check whether the variable names in the desktop component SCSS are still aligned.