# @mana/shared-theme Unified theme system for all Mana web applications. Provides a consistent theming experience with HSL-based colors, multiple theme variants, and light/dark mode support. ## Features - **4 Theme Variants**: Lume (Gold), Nature (Green), Stone (Blue Gray), Ocean (Blue) - **3 Theme Modes**: Light, Dark, System (auto-detect) - **HSL-based Colors**: 18 semantic color tokens for flexible theming - **App-specific Primary Colors**: Each app can override the primary color - **Svelte 5 Runes**: Modern reactive state management - **localStorage Persistence**: Theme preferences are saved per app - **System Preference Detection**: Automatically follows OS dark mode setting ## Installation ```bash pnpm add @mana/shared-theme ``` ## Quick Start ### 1. Create a theme store for your app ```typescript // src/lib/stores/theme.ts import { createThemeStore } from '@mana/shared-theme'; export const theme = createThemeStore({ appId: 'myapp', defaultVariant: 'lume', primaryColor: { light: '47 95% 58%', // Gold dark: '47 95% 58%', }, }); ``` ### 2. Initialize in your layout ```svelte {@render children()} ``` ### 3. Import theme CSS ```css /* src/app.css */ @import '@mana/shared-tailwind/themes.css'; @tailwind base; @tailwind components; @tailwind utilities; ``` ## API Reference ### `createThemeStore(config)` Creates a theme store instance for your app. #### Config Options | Option | Type | Default | Description | |--------|------|---------|-------------| | `appId` | `string` | required | Unique app identifier for localStorage | | `defaultMode` | `'light' \| 'dark' \| 'system'` | `'system'` | Default theme mode | | `defaultVariant` | `ThemeVariant` | `'lume'` | Default theme variant | | `primaryColor` | `{ light: HSLValue; dark: HSLValue }` | - | App-specific primary color override | #### Store Properties | Property | Type | Description | |----------|------|-------------| | `mode` | `ThemeMode` | Current mode (light/dark/system) | | `variant` | `ThemeVariant` | Current variant (lume/nature/stone/ocean) | | `effectiveMode` | `'light' \| 'dark'` | Resolved mode (accounts for system preference) | | `isDark` | `boolean` | Whether dark mode is active | | `variants` | `ThemeVariant[]` | All available variants | #### Store Methods | Method | Description | |--------|-------------| | `initialize()` | Initialize theme, returns cleanup function | | `setMode(mode)` | Set theme mode | | `setVariant(variant)` | Set theme variant | | `toggleMode()` | Toggle between light and dark | | `cycleMode()` | Cycle through light → dark → system | ## Theme Variants ### Lume (Gold) ✨ - Primary: `hsl(47 95% 58%)` - #f8d62b - Warm, energetic feel - Best for: Creative apps, productivity tools ### Nature (Green) 🌿 - Primary: `hsl(122 39% 49%)` - #4CAF50 - Calm, organic feel - Best for: Health apps, environmental themes ### Stone (Blue Gray) 🪨 - Primary: `hsl(200 18% 46%)` - #607D8B - Professional, neutral feel - Best for: Business apps, enterprise tools ### Ocean (Blue) 🌊 - Primary: `hsl(199 98% 45%)` - #039BE5 - Fresh, trustworthy feel - Best for: Tech apps, communication tools ## Color Tokens The theme system provides 18 semantic color tokens: ```css /* Primary */ --color-primary --color-primary-foreground /* Secondary */ --color-secondary --color-secondary-foreground /* Backgrounds */ --color-background --color-foreground /* Surfaces */ --color-surface --color-surface-hover --color-surface-elevated /* Muted */ --color-muted --color-muted-foreground /* Borders */ --color-border --color-border-strong /* Semantic */ --color-error --color-success --color-warning /* Form */ --color-input --color-ring ``` ## Usage with Tailwind The `@mana/shared-tailwind` preset maps all CSS variables to Tailwind classes: ```html
Main text
Secondary text