@svadmin/core 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.ts +2 -2
- package/src/theme.svelte.ts +45 -1
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -24,8 +24,8 @@ export { useLive } from './live';
|
|
|
24
24
|
export { toast } from './toast.svelte';
|
|
25
25
|
export { t, setLocale, getLocale, getAvailableLocales, addTranslations } from './i18n.svelte';
|
|
26
26
|
export { audit, setAuditHandler } from './audit';
|
|
27
|
-
export { getTheme, setTheme, toggleTheme, getResolvedTheme } from './theme.svelte';
|
|
28
|
-
export type { ThemeMode } from './theme.svelte';
|
|
27
|
+
export { getTheme, setTheme, toggleTheme, getResolvedTheme, getColorTheme, setColorTheme, colorThemes } from './theme.svelte';
|
|
28
|
+
export type { ThemeMode, ColorTheme } from './theme.svelte';
|
|
29
29
|
|
|
30
30
|
export type {
|
|
31
31
|
DataProvider, AuthProvider, NotificationProvider, MutationMode,
|
package/src/theme.svelte.ts
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
|
-
// Theme — dark/light/system mode management (Svelte 5 runes)
|
|
1
|
+
// Theme — dark/light/system mode + color theme management (Svelte 5 runes)
|
|
2
2
|
|
|
3
3
|
export type ThemeMode = 'light' | 'dark' | 'system';
|
|
4
|
+
export type ColorTheme = 'blue' | 'green' | 'rose' | 'orange' | 'violet' | 'zinc';
|
|
4
5
|
|
|
5
6
|
const STORAGE_KEY = 'svadmin-theme';
|
|
7
|
+
const COLOR_STORAGE_KEY = 'svadmin-color-theme';
|
|
8
|
+
|
|
9
|
+
// ── Color themes (display metadata) ──────────────────────
|
|
10
|
+
export const colorThemes: { id: ColorTheme; label: string; color: string }[] = [
|
|
11
|
+
{ id: 'blue', label: 'Blue', color: '#3b82f6' },
|
|
12
|
+
{ id: 'green', label: 'Green', color: '#22c55e' },
|
|
13
|
+
{ id: 'rose', label: 'Rose', color: '#f43f5e' },
|
|
14
|
+
{ id: 'orange', label: 'Orange', color: '#f97316' },
|
|
15
|
+
{ id: 'violet', label: 'Violet', color: '#8b5cf6' },
|
|
16
|
+
{ id: 'zinc', label: 'Zinc', color: '#71717a' },
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
// ── Dark/Light mode ──────────────────────────────────────
|
|
6
20
|
|
|
7
21
|
function getStoredTheme(): ThemeMode {
|
|
8
22
|
if (typeof localStorage === 'undefined') return 'system';
|
|
@@ -54,3 +68,33 @@ export function toggleTheme(): void {
|
|
|
54
68
|
export function getResolvedTheme(): 'light' | 'dark' {
|
|
55
69
|
return mode === 'system' ? getSystemPreference() : mode;
|
|
56
70
|
}
|
|
71
|
+
|
|
72
|
+
// ── Color theme ──────────────────────────────────────────
|
|
73
|
+
|
|
74
|
+
function getStoredColorTheme(): ColorTheme {
|
|
75
|
+
if (typeof localStorage === 'undefined') return 'blue';
|
|
76
|
+
return (localStorage.getItem(COLOR_STORAGE_KEY) as ColorTheme) ?? 'blue';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let colorTheme = $state<ColorTheme>(getStoredColorTheme());
|
|
80
|
+
|
|
81
|
+
function applyColorTheme(ct: ColorTheme): void {
|
|
82
|
+
if (typeof document !== 'undefined') {
|
|
83
|
+
document.documentElement.setAttribute('data-theme', ct);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Apply on init
|
|
88
|
+
applyColorTheme(colorTheme);
|
|
89
|
+
|
|
90
|
+
export function getColorTheme(): ColorTheme {
|
|
91
|
+
return colorTheme;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function setColorTheme(ct: ColorTheme): void {
|
|
95
|
+
colorTheme = ct;
|
|
96
|
+
if (typeof localStorage !== 'undefined') {
|
|
97
|
+
localStorage.setItem(COLOR_STORAGE_KEY, ct);
|
|
98
|
+
}
|
|
99
|
+
applyColorTheme(ct);
|
|
100
|
+
}
|