# ThemeEngine

**Kind:** Class

**Source:** [`atloria-monorepo/packages/theme-engine/src/lib/theme-engine.ts`](https://github.com/sherkety/atloria/blob/main/atloria-monorepo/packages/theme-engine/src/lib/theme-engine.ts#L25)

ThemeEngine - A framework-agnostic theming system for Atloria

Features:
- CSS Variables-based theming
- Dark/Light mode support
- localStorage persistence
- System preference detection
- SSR support (no flash of unstyled content)
- Cross-tab synchronization
- White-label support via custom tokens

## Methods

| Method | Signature | Returns |
|---|---|---|
| `setMode` | `setMode(mode: ThemeMode)` | `void` |
| `getMode` | `getMode()` | `ThemeMode` |
| `getEffectiveThemeMode` | `getEffectiveThemeMode()` | `'light' | 'dark'` |
| `enableDarkMode` | `enableDarkMode()` | `void` |
| `disableDarkMode` | `disableDarkMode()` | `void` |
| `toggleDarkMode` | `toggleDarkMode()` | `void` |
| `useSystemPreference` | `useSystemPreference()` | `void` |
| `getTheme` | `getTheme()` | `ThemeTokens` |
| `updateTheme` | `updateTheme(updates: Partial<ThemeTokens>)` | `void` |
| `subscribe` | `subscribe(listener: ThemeEventListener)` | `() => void` |
| `getSSRScript` | `getSSRScript(config: ThemeConfig)` | `string` |
| `destroy` | `destroy()` | `void` |

## Where it refuses work

- `ThemeEngine` stops the work with an early return when `!this.isClient`, in 7 places.
- `ThemeEngine` stops the work with an early return when `stored === 'light' || stored === 'dark' || stored === 'system'`.
- `ThemeEngine` stops the work with an early return when `!this.isClient || !this.config.enablePersistence`.
- `ThemeEngine` stops the work with an early return when `this.currentMode === mode`.
