@shellui/core 0.4.1 → 0.5.0-alpha.1

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.
Files changed (142) hide show
  1. package/README.md +2 -2
  2. package/package.json +15 -3
  3. package/schemas/curated-themes.json +4035 -0
  4. package/schemas/shellui.config.schema.json +961 -0
  5. package/schemas/shellui.theme.schema.json +187 -0
  6. package/src/app.tsx +4 -1
  7. package/src/components/ContentView.tsx +144 -9
  8. package/src/components/LoadingOverlay.tsx +1 -1
  9. package/src/components/ui/alert-dialog.tsx +1 -1
  10. package/src/components/ui/dialog.tsx +23 -5
  11. package/src/components/ui/drawer.tsx +282 -42
  12. package/src/components/ui/dropdown-menu.tsx +7 -2
  13. package/src/components/ui/input.tsx +21 -0
  14. package/src/components/ui/separator.tsx +23 -0
  15. package/src/components/ui/sheet.tsx +220 -0
  16. package/src/components/ui/sidebar.tsx +785 -221
  17. package/src/components/ui/skeleton.tsx +13 -0
  18. package/src/constants/urls.ts +1 -0
  19. package/src/features/admin/utils.ts +2 -45
  20. package/src/features/alertDialog/DialogContext.tsx +1 -1
  21. package/src/features/auth/components/LoginButton.tsx +25 -18
  22. package/src/features/auth/components/LoginPreferencesControls.tsx +124 -0
  23. package/src/features/auth/components/LoginView.tsx +131 -49
  24. package/src/features/config/types.ts +64 -82
  25. package/src/features/drawer/DrawerContext.tsx +55 -19
  26. package/src/features/layouts/AppLayout.tsx +3 -3
  27. package/src/features/layouts/OverlayShell.tsx +376 -77
  28. package/src/features/layouts/appbar/AppBarLayout.tsx +501 -88
  29. package/src/features/layouts/branding/AppBrandIcon.tsx +95 -0
  30. package/src/features/layouts/branding/resolveThemeAsset.spec.ts +33 -0
  31. package/src/features/layouts/branding/resolveThemeAsset.ts +33 -0
  32. package/src/features/layouts/chrome/CollapsedDesktopTitlebar.tsx +49 -0
  33. package/src/features/layouts/chrome/ContentDragOverlay.tsx +19 -0
  34. package/src/features/layouts/chrome/DesktopBackButton.tsx +71 -0
  35. package/src/features/layouts/chrome/DesktopChrome.tsx +28 -0
  36. package/src/features/layouts/chrome/DesktopForwardButton.tsx +59 -0
  37. package/src/features/layouts/chrome/DesktopHistoryButtons.tsx +16 -0
  38. package/src/features/layouts/chrome/constants.ts +11 -0
  39. package/src/features/layouts/chrome/goDesktopBack.spec.ts +218 -0
  40. package/src/features/layouts/chrome/goDesktopBack.ts +106 -0
  41. package/src/features/layouts/chrome/index.ts +26 -0
  42. package/src/features/layouts/chrome/runtime.ts +45 -0
  43. package/src/features/layouts/findMatchingNavigationItem.spec.ts +55 -0
  44. package/src/features/layouts/fullscreen/FullscreenLayout.tsx +17 -1
  45. package/src/features/layouts/isFrameForAppUrl.spec.ts +33 -0
  46. package/src/features/layouts/sidebar/NavigationContent.tsx +70 -34
  47. package/src/features/layouts/sidebar/SidebarIcons.tsx +41 -42
  48. package/src/features/layouts/sidebar/SidebarInner.tsx +142 -24
  49. package/src/features/layouts/sidebar/SidebarLayout.tsx +100 -37
  50. package/src/features/layouts/sidebar/sidebarUtils.ts +0 -7
  51. package/src/features/layouts/sidebar/types.ts +3 -3
  52. package/src/features/layouts/utils.ts +73 -5
  53. package/src/features/layouts/windows/WindowsLayout.tsx +173 -61
  54. package/src/features/modal/ModalContext.tsx +21 -8
  55. package/src/features/overlays/OverlayDrawerPendingBar.tsx +26 -0
  56. package/src/features/overlays/OverlayDynamicDemoView.tsx +108 -0
  57. package/src/features/overlays/OverlayPendingSpinner.tsx +18 -0
  58. package/src/features/overlays/ResponsiveModal.tsx +483 -0
  59. package/src/features/overlays/overlaySize.spec.ts +71 -0
  60. package/src/features/overlays/overlaySize.ts +228 -0
  61. package/src/features/overlays/useOverlayReportedSize.ts +130 -0
  62. package/src/features/settings/SettingsProvider.tsx +66 -46
  63. package/src/features/settings/SettingsView.tsx +42 -47
  64. package/src/features/settings/components/Appearance.tsx +305 -55
  65. package/src/features/settings/components/develop/DrawerTestButtons.tsx +18 -0
  66. package/src/features/settings/components/develop/ModalTestButtons.tsx +23 -0
  67. package/src/features/settings/utils/getResolvedAppearanceForSettings.ts +11 -5
  68. package/src/features/theme/applyTheme.ts +143 -0
  69. package/src/features/theme/color.ts +83 -0
  70. package/src/features/theme/curated/amber-minimal.json +86 -0
  71. package/src/features/theme/curated/amethyst-haze.json +86 -0
  72. package/src/features/theme/curated/astro-vista.json +86 -0
  73. package/src/features/theme/curated/bold-tech.json +86 -0
  74. package/src/features/theme/curated/bubblegum.json +86 -0
  75. package/src/features/theme/curated/caffeine.json +83 -0
  76. package/src/features/theme/curated/candyland.json +86 -0
  77. package/src/features/theme/curated/catppuccin.json +86 -0
  78. package/src/features/theme/curated/claude.json +86 -0
  79. package/src/features/theme/curated/claymorphism.json +86 -0
  80. package/src/features/theme/curated/clean-slate.json +86 -0
  81. package/src/features/theme/curated/cosmic-night.json +86 -0
  82. package/src/features/theme/curated/cyberpunk.json +86 -0
  83. package/src/features/theme/curated/darkmatter.json +86 -0
  84. package/src/features/theme/curated/doom-64.json +86 -0
  85. package/src/features/theme/curated/elegant-luxury.json +86 -0
  86. package/src/features/theme/curated/graphite.json +86 -0
  87. package/src/features/theme/curated/index.ts +260 -0
  88. package/src/features/theme/curated/kodama-grove.json +86 -0
  89. package/src/features/theme/curated/light-green.json +87 -0
  90. package/src/features/theme/curated/midnight-bloom.json +86 -0
  91. package/src/features/theme/curated/mocha-mousse.json +86 -0
  92. package/src/features/theme/curated/modern-minimal.json +86 -0
  93. package/src/features/theme/curated/mono.json +84 -0
  94. package/src/features/theme/curated/nature.json +86 -0
  95. package/src/features/theme/curated/neo-brutalism.json +86 -0
  96. package/src/features/theme/curated/northern-lights.json +86 -0
  97. package/src/features/theme/curated/notebook.json +87 -0
  98. package/src/features/theme/curated/ocean-breeze.json +86 -0
  99. package/src/features/theme/curated/pastel-dreams.json +86 -0
  100. package/src/features/theme/curated/perpetuity.json +86 -0
  101. package/src/features/theme/curated/quantum-rose.json +86 -0
  102. package/src/features/theme/curated/retro-arcade.json +86 -0
  103. package/src/features/theme/curated/sage-garden.json +86 -0
  104. package/src/features/theme/curated/shadcn.json +83 -0
  105. package/src/features/theme/curated/shellui.json +82 -0
  106. package/src/features/theme/curated/soft-pop.json +86 -0
  107. package/src/features/theme/curated/solar-dusk.json +86 -0
  108. package/src/features/theme/curated/starry-night.json +86 -0
  109. package/src/features/theme/curated/sunset-horizon.json +86 -0
  110. package/src/features/theme/curated/supabase.json +85 -0
  111. package/src/features/theme/curated/t3-chat.json +83 -0
  112. package/src/features/theme/curated/tangerine.json +86 -0
  113. package/src/features/theme/curated/twitter.json +86 -0
  114. package/src/features/theme/curated/vercel.json +86 -0
  115. package/src/features/theme/curated/vintage-paper.json +86 -0
  116. package/src/features/theme/curated/violet-bloom.json +87 -0
  117. package/src/features/theme/curated/zen-inspired.json +87 -0
  118. package/src/features/theme/index.ts +76 -0
  119. package/src/features/theme/normalize.ts +159 -0
  120. package/src/features/theme/registry.ts +50 -0
  121. package/src/features/theme/resolveConfig.ts +182 -0
  122. package/src/features/theme/safeApplyTheme.ts +147 -0
  123. package/src/features/theme/themes.spec.ts +276 -0
  124. package/src/features/theme/themes.ts +82 -558
  125. package/src/features/theme/tokenKeys.ts +60 -0
  126. package/src/features/theme/types.ts +170 -0
  127. package/src/features/theme/useTheme.tsx +48 -50
  128. package/src/hooks/use-mobile.tsx +19 -0
  129. package/src/i18n/translations/en/common.json +41 -0
  130. package/src/i18n/translations/en/settings.json +10 -2
  131. package/src/i18n/translations/fr/common.json +41 -0
  132. package/src/i18n/translations/fr/settings.json +10 -2
  133. package/src/index.css +372 -128
  134. package/src/index.ts +71 -0
  135. package/src/lib/z-index.ts +4 -1
  136. package/src/routes/components/IndexRoute.tsx +12 -2
  137. package/src/routes/components/NavigationItemRoute.tsx +1 -10
  138. package/src/routes/hooks/useNavigationItems.ts +29 -44
  139. package/src/routes/routes.tsx +58 -27
  140. package/tailwind.config.js +27 -27
  141. package/src/features/layouts/sidebar/BottomNavItem.tsx +0 -88
  142. package/src/features/layouts/sidebar/MobileBottomNav.tsx +0 -168
@@ -0,0 +1,50 @@
1
+ import { defaultTheme, themes as curatedThemes } from './curated';
2
+ import type { ThemeDefinition } from './types';
3
+
4
+ /**
5
+ * Registry of themes available to the running shell (from resolved config).
6
+ * Curated themes remain importable via `themes` / `defaultTheme` from `@shellui/core`.
7
+ */
8
+ const themeRegistry = new Map<string, ThemeDefinition>();
9
+
10
+ /**
11
+ * Register a custom theme (overrides same name).
12
+ */
13
+ export function registerTheme(theme: ThemeDefinition): void {
14
+ themeRegistry.set(theme.name, theme);
15
+ }
16
+
17
+ /**
18
+ * Replace the set of available themes (used after config resolution).
19
+ */
20
+ export function setAvailableThemes(themeList: ThemeDefinition[]): void {
21
+ themeRegistry.clear();
22
+ for (const theme of themeList) {
23
+ themeRegistry.set(theme.name, theme);
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Get a theme by name from the registry, falling back to curated built-ins.
29
+ */
30
+ export function getTheme(name: string): ThemeDefinition | undefined {
31
+ return themeRegistry.get(name) ?? curatedThemes[name];
32
+ }
33
+
34
+ /**
35
+ * Themes currently available in the app (registry only).
36
+ * Empty until config themes are registered.
37
+ */
38
+ export function getAllThemes(): ThemeDefinition[] {
39
+ if (themeRegistry.size === 0) {
40
+ return [defaultTheme];
41
+ }
42
+ return Array.from(themeRegistry.values());
43
+ }
44
+
45
+ /**
46
+ * Clear registry (tests).
47
+ */
48
+ export function clearThemeRegistry(): void {
49
+ themeRegistry.clear();
50
+ }
@@ -0,0 +1,182 @@
1
+ import { defaultTheme, themes as curatedThemes } from './curated';
2
+ import { normalizeTheme } from './normalize';
3
+ import type { ThemeDefinition, ThemeInput, ThemeRef, ThemesConfig } from './types';
4
+
5
+ export interface ResolveThemeConfigInput {
6
+ /** Single theme shorthand (name, path marker, or object). */
7
+ theme?: ThemeRef;
8
+ /** Multiple themes: array or map. */
9
+ themes?: ThemesConfig;
10
+ /** Preferred active theme id (takes precedence over defaultTheme). */
11
+ activeTheme?: string;
12
+ /** Legacy alias for activeTheme. */
13
+ defaultTheme?: string;
14
+ /**
15
+ * Themes already loaded from `themesDir` by the CLI (complete definitions).
16
+ * Keys are theme names.
17
+ */
18
+ themesFromDir?: Record<string, ThemeDefinition>;
19
+ /**
20
+ * Lookup for path-like refs that were preloaded by the CLI.
21
+ * Key is the original path string from config.
22
+ */
23
+ pathThemes?: Record<string, ThemeDefinition>;
24
+ }
25
+
26
+ export interface ResolvedThemeConfig {
27
+ /** Available themes for the app (selector + registry). */
28
+ themes: ThemeDefinition[];
29
+ /** Active / default theme name. */
30
+ activeTheme: string;
31
+ /** Same as activeTheme (legacy field written back into config). */
32
+ defaultTheme: string;
33
+ }
34
+
35
+ function isPathRef(value: string): boolean {
36
+ return (
37
+ value.includes('/') ||
38
+ value.includes('\\') ||
39
+ value.endsWith('.json') ||
40
+ value.startsWith('.') ||
41
+ value.startsWith('~')
42
+ );
43
+ }
44
+
45
+ function resolveStringRef(
46
+ ref: string,
47
+ builtins: Record<string, ThemeDefinition>,
48
+ themesFromDir: Record<string, ThemeDefinition>,
49
+ pathThemes: Record<string, ThemeDefinition>,
50
+ mapKey?: string,
51
+ ): ThemeDefinition {
52
+ if (pathThemes[ref]) {
53
+ const loaded = pathThemes[ref];
54
+ return mapKey && loaded.name !== mapKey ? { ...loaded, name: mapKey } : loaded;
55
+ }
56
+
57
+ if (isPathRef(ref)) {
58
+ throw new Error(
59
+ `Theme path "${ref}" was not loaded. Use themesDir or ensure the CLI resolved this path.`,
60
+ );
61
+ }
62
+
63
+ const fromDir = themesFromDir[ref];
64
+ if (fromDir) {
65
+ return mapKey && fromDir.name !== mapKey ? { ...fromDir, name: mapKey } : fromDir;
66
+ }
67
+
68
+ const builtin = builtins[ref];
69
+ if (builtin) {
70
+ return mapKey && builtin.name !== mapKey ? { ...builtin, name: mapKey } : builtin;
71
+ }
72
+
73
+ throw new Error(
74
+ `Unknown theme "${ref}". Use a built-in name (${Object.keys(builtins).slice(0, 8).join(', ')}, …), a theme object, or a themesDir entry.`,
75
+ );
76
+ }
77
+
78
+ function resolveRef(
79
+ ref: ThemeRef,
80
+ builtins: Record<string, ThemeDefinition>,
81
+ themesFromDir: Record<string, ThemeDefinition>,
82
+ pathThemes: Record<string, ThemeDefinition>,
83
+ mapKey?: string,
84
+ ): ThemeDefinition {
85
+ if (typeof ref === 'string') {
86
+ return resolveStringRef(ref, builtins, themesFromDir, pathThemes, mapKey);
87
+ }
88
+ return normalizeTheme(ref as ThemeInput, {
89
+ name: mapKey,
90
+ base: defaultTheme,
91
+ });
92
+ }
93
+
94
+ function entriesFromThemesConfig(themes: ThemesConfig): Array<{ key?: string; ref: ThemeRef }> {
95
+ if (Array.isArray(themes)) {
96
+ return themes.map((ref) => ({ ref }));
97
+ }
98
+ return Object.entries(themes).map(([key, ref]) => ({ key, ref }));
99
+ }
100
+
101
+ /**
102
+ * Resolve flexible theme config into a concrete theme list + active name.
103
+ * Browser-safe (no filesystem). Path refs must be preloaded via `pathThemes` / `themesFromDir`.
104
+ */
105
+ export function resolveThemeConfig(
106
+ input: ResolveThemeConfigInput,
107
+ builtins: Record<string, ThemeDefinition> = curatedThemes,
108
+ ): ResolvedThemeConfig {
109
+ const themesFromDir = input.themesFromDir ?? {};
110
+ const pathThemes = input.pathThemes ?? {};
111
+ const resolved: ThemeDefinition[] = [];
112
+ const seen = new Set<string>();
113
+
114
+ const add = (theme: ThemeDefinition) => {
115
+ if (seen.has(theme.name)) {
116
+ // Later entries override (e.g. custom overrides of a built-in name)
117
+ const idx = resolved.findIndex((t) => t.name === theme.name);
118
+ if (idx >= 0) resolved[idx] = theme;
119
+ return;
120
+ }
121
+ seen.add(theme.name);
122
+ resolved.push(theme);
123
+ };
124
+
125
+ if (input.themes !== undefined && input.themes !== null) {
126
+ for (const { key, ref } of entriesFromThemesConfig(input.themes)) {
127
+ add(resolveRef(ref, builtins, themesFromDir, pathThemes, key));
128
+ }
129
+ } else if (input.theme !== undefined && input.theme !== null) {
130
+ add(resolveRef(input.theme, builtins, themesFromDir, pathThemes));
131
+ } else if (Object.keys(themesFromDir).length > 0) {
132
+ for (const theme of Object.values(themesFromDir)) {
133
+ add(theme);
134
+ }
135
+ } else if (input.activeTheme || input.defaultTheme) {
136
+ const name = (input.activeTheme || input.defaultTheme) as string;
137
+ add(
138
+ resolveStringRef(name === 'default' ? 'shellui' : name, builtins, themesFromDir, pathThemes),
139
+ );
140
+ } else {
141
+ add(builtins.shellui ?? builtins.default ?? defaultTheme);
142
+ }
143
+
144
+ // Ensure default always exists as fallback when referenced
145
+ if (!seen.has('default') && builtins.default) {
146
+ // Don't auto-add to available list unless it was requested — only for getTheme fallbacks.
147
+ }
148
+
149
+ let preferred =
150
+ input.activeTheme?.trim() ||
151
+ input.defaultTheme?.trim() ||
152
+ (typeof input.theme === 'string' && !isPathRef(input.theme) ? input.theme.trim() : '') ||
153
+ (typeof input.theme === 'object' && input.theme && 'name' in input.theme
154
+ ? String((input.theme as ThemeDefinition).name || '')
155
+ : '') ||
156
+ resolved[0]?.name ||
157
+ 'shellui';
158
+
159
+ // Legacy init used theme: "default" — alias to official Shellui theme
160
+ if (preferred === 'default') preferred = 'shellui';
161
+
162
+ let activeTheme = preferred;
163
+ if (!resolved.some((t) => t.name === activeTheme)) {
164
+ // Active theme not in list — try to resolve and add it
165
+ try {
166
+ const extra = resolveStringRef(activeTheme, builtins, themesFromDir, pathThemes);
167
+ add(extra);
168
+ } catch {
169
+ activeTheme = resolved[0]?.name ?? 'default';
170
+ if (!resolved.length) {
171
+ add(defaultTheme);
172
+ activeTheme = defaultTheme.name;
173
+ }
174
+ }
175
+ }
176
+
177
+ return {
178
+ themes: resolved,
179
+ activeTheme,
180
+ defaultTheme: activeTheme,
181
+ };
182
+ }
@@ -0,0 +1,147 @@
1
+ import { applyTheme } from './applyTheme';
2
+ import type { ThemeDefinition } from './types';
3
+
4
+ const SWITCHING_CLASS = 'shellui-theme-switching';
5
+ /** Keep transitions locked briefly after apply so rapid paints stay snap-clean. */
6
+ const UNLOCK_MS = 180;
7
+
8
+ let unlockTimer: ReturnType<typeof setTimeout> | null = null;
9
+ let pending: { theme: ThemeDefinition; isDark: boolean } | null = null;
10
+ let flushScheduled = false;
11
+ let switchGeneration = 0;
12
+ let lastAppliedKey: string | null = null;
13
+ const idleWaiters = new Set<() => void>();
14
+
15
+ function applyDarkClass(isDark: boolean): void {
16
+ const root = document.documentElement;
17
+ if (isDark) {
18
+ root.classList.add('dark');
19
+ } else {
20
+ root.classList.remove('dark');
21
+ }
22
+ }
23
+
24
+ function themeApplyKey(theme: ThemeDefinition, isDark: boolean): string {
25
+ return `${theme.name}:${isDark ? 'dark' : 'light'}`;
26
+ }
27
+
28
+ function notifyIdle(): void {
29
+ if (idleWaiters.size === 0) return;
30
+ const waiters = [...idleWaiters];
31
+ idleWaiters.clear();
32
+ for (const resolve of waiters) {
33
+ resolve();
34
+ }
35
+ }
36
+
37
+ function beginSwitchLock(): void {
38
+ document.documentElement.classList.add(SWITCHING_CLASS);
39
+ if (unlockTimer !== null) {
40
+ clearTimeout(unlockTimer);
41
+ unlockTimer = null;
42
+ }
43
+ }
44
+
45
+ function endSwitchLockSoon(): void {
46
+ if (unlockTimer !== null) {
47
+ clearTimeout(unlockTimer);
48
+ }
49
+ const generation = switchGeneration;
50
+ unlockTimer = setTimeout(() => {
51
+ // A newer switch started while we were waiting — let that cycle unlock.
52
+ if (generation !== switchGeneration) return;
53
+ document.documentElement.classList.remove(SWITCHING_CLASS);
54
+ unlockTimer = null;
55
+ notifyIdle();
56
+ }, UNLOCK_MS);
57
+ }
58
+
59
+ function flushPending(): void {
60
+ flushScheduled = false;
61
+ const next = pending;
62
+ pending = null;
63
+ if (!next || typeof document === 'undefined') {
64
+ endSwitchLockSoon();
65
+ return;
66
+ }
67
+
68
+ const key = themeApplyKey(next.theme, next.isDark);
69
+ // Skip no-op reapplies (e.g. iframe settings echo) that cause light/dark bouncing.
70
+ if (key === lastAppliedKey) {
71
+ endSwitchLockSoon();
72
+ return;
73
+ }
74
+
75
+ switchGeneration += 1;
76
+ beginSwitchLock();
77
+ applyDarkClass(next.isDark);
78
+ applyTheme(next.theme, next.isDark);
79
+ lastAppliedKey = key;
80
+ // Force style recalc so the locked frame commits without CSS transitions.
81
+ void document.documentElement.offsetHeight;
82
+ endSwitchLockSoon();
83
+ }
84
+
85
+ /**
86
+ * True while a theme switch is in flight (queued, applying, or unlock grace).
87
+ */
88
+ export function isThemeSwitchInFlight(): boolean {
89
+ if (typeof document === 'undefined') return false;
90
+ return (
91
+ pending !== null ||
92
+ flushScheduled ||
93
+ unlockTimer !== null ||
94
+ document.documentElement.classList.contains(SWITCHING_CLASS)
95
+ );
96
+ }
97
+
98
+ /**
99
+ * Resolves when the current theme switch (if any) has fully settled.
100
+ */
101
+ export function waitForThemeSwitchIdle(): Promise<void> {
102
+ if (!isThemeSwitchInFlight()) {
103
+ return Promise.resolve();
104
+ }
105
+ return new Promise((resolve) => {
106
+ idleWaiters.add(resolve);
107
+ });
108
+ }
109
+
110
+ /**
111
+ * Apply theme + light/dark class safely for rapid switching.
112
+ * Coalesces to the latest request within the same turn and temporarily
113
+ * disables CSS color transitions so the UI snaps instead of morphing.
114
+ */
115
+ export function scheduleSafeThemeApply(theme: ThemeDefinition, isDark: boolean): void {
116
+ if (typeof document === 'undefined') {
117
+ return;
118
+ }
119
+
120
+ pending = { theme, isDark };
121
+ beginSwitchLock();
122
+
123
+ if (flushScheduled) {
124
+ return;
125
+ }
126
+
127
+ flushScheduled = true;
128
+ queueMicrotask(flushPending);
129
+ }
130
+
131
+ /**
132
+ * Synchronous safe apply (e.g. tests). Still uses the transition lock.
133
+ */
134
+ export function applyThemeSafely(theme: ThemeDefinition, isDark: boolean): void {
135
+ if (typeof document === 'undefined') {
136
+ return;
137
+ }
138
+ pending = null;
139
+ flushScheduled = false;
140
+ switchGeneration += 1;
141
+ beginSwitchLock();
142
+ applyDarkClass(isDark);
143
+ applyTheme(theme, isDark);
144
+ lastAppliedKey = themeApplyKey(theme, isDark);
145
+ void document.documentElement.offsetHeight;
146
+ endSwitchLockSoon();
147
+ }
@@ -0,0 +1,276 @@
1
+ import { describe, expect, it, beforeEach } from 'vitest';
2
+ import { hexToHsl, toCssVarValue, isHexColor } from './color';
3
+ import { normalizeTheme, toThemeJson } from './normalize';
4
+ import { resolveThemeConfig } from './resolveConfig';
5
+ import { clearThemeRegistry, getAllThemes, setAvailableThemes, getTheme } from './registry';
6
+ import {
7
+ defaultTheme,
8
+ themes,
9
+ themeNames,
10
+ curatedThemes,
11
+ THEME_SCHEMA_VERSION,
12
+ shelluiTheme,
13
+ claudeTheme,
14
+ } from './themes';
15
+
16
+ describe('hexToHsl / toCssVarValue', () => {
17
+ it('keeps hex as a full CSS color', () => {
18
+ expect(toCssVarValue('#FFFFFF')).toBe('#FFFFFF');
19
+ expect(toCssVarValue('000000')).toBe('#000000');
20
+ expect(isHexColor('#22C55E')).toBe(true);
21
+ });
22
+
23
+ it('wraps legacy HSL channels and passes OKLCH through', () => {
24
+ expect(toCssVarValue('142 71% 45%')).toBe('hsl(142 71% 45%)');
25
+ expect(toCssVarValue('oklch(0.7 0.15 145)')).toBe('oklch(0.7 0.15 145)');
26
+ expect(toCssVarValue('0.5rem')).toBe('0.5rem');
27
+ });
28
+
29
+ it('still converts hex to HSL channels via hexToHsl helper', () => {
30
+ expect(hexToHsl('#FFFFFF')).toBe('0 0% 100%');
31
+ });
32
+ });
33
+
34
+ describe('normalizeTheme', () => {
35
+ it('merges partial light/dark onto the default theme', () => {
36
+ const theme = normalizeTheme({
37
+ name: 'brand',
38
+ label: 'Brand',
39
+ light: { primary: 'oklch(0.5 0.1 40)' },
40
+ dark: { primary: 'oklch(0.6 0.1 40)' },
41
+ });
42
+ expect(theme.name).toBe('brand');
43
+ expect(theme.displayName).toBe('Brand');
44
+ expect(theme.colors.light.primary).toBe('oklch(0.5 0.1 40)');
45
+ expect(theme.colors.light.background).toBe(defaultTheme.colors.light.background);
46
+ });
47
+
48
+ it('accepts CSS-variable kebab-case token keys', () => {
49
+ const theme = normalizeTheme({
50
+ name: 'kebab',
51
+ label: 'Kebab',
52
+ light: {
53
+ 'primary-foreground': 'oklch(1 0 0)',
54
+ sidebar: 'oklch(0.9 0 0)',
55
+ },
56
+ dark: {
57
+ 'primary-foreground': 'oklch(0 0 0)',
58
+ sidebar: 'oklch(0.2 0 0)',
59
+ },
60
+ });
61
+ expect(theme.colors.light.primaryForeground).toBe('oklch(1 0 0)');
62
+ expect(theme.colors.light.sidebarBackground).toBe('oklch(0.9 0 0)');
63
+ });
64
+
65
+ it('round-trips through toThemeJson', () => {
66
+ const json = toThemeJson(defaultTheme);
67
+ expect(json.version).toBe(THEME_SCHEMA_VERSION);
68
+ expect(json.name).toBe('shellui');
69
+ expect(json.label).toBe('Shellui');
70
+ const again = normalizeTheme(json);
71
+ expect(again.colors.light.primary).toBe(defaultTheme.colors.light.primary);
72
+ });
73
+ });
74
+
75
+ describe('resolveThemeConfig', () => {
76
+ it('resolves a single built-in theme by name', () => {
77
+ const resolved = resolveThemeConfig({ theme: 'claude' });
78
+ expect(resolved.themes).toHaveLength(1);
79
+ expect(resolved.themes[0].name).toBe('claude');
80
+ expect(resolved.activeTheme).toBe('claude');
81
+ });
82
+
83
+ it('resolves the curated themes', () => {
84
+ const resolved = resolveThemeConfig({
85
+ themes: [
86
+ 'shellui',
87
+ 'claude',
88
+ 'light-green',
89
+ 'zen-inspired',
90
+ 'astro-vista',
91
+ 'shadcn',
92
+ 'amber-minimal',
93
+ 'amethyst-haze',
94
+ 'bold-tech',
95
+ 'bubblegum',
96
+ 'caffeine',
97
+ 'candyland',
98
+ 'catppuccin',
99
+ 'claymorphism',
100
+ 'clean-slate',
101
+ 'cosmic-night',
102
+ 'cyberpunk',
103
+ 'darkmatter',
104
+ 'doom-64',
105
+ 'elegant-luxury',
106
+ 'graphite',
107
+ 'kodama-grove',
108
+ 'midnight-bloom',
109
+ 'mocha-mousse',
110
+ 'modern-minimal',
111
+ 'mono',
112
+ 'nature',
113
+ 'neo-brutalism',
114
+ 'northern-lights',
115
+ 'notebook',
116
+ 'ocean-breeze',
117
+ 'pastel-dreams',
118
+ 'perpetuity',
119
+ 'quantum-rose',
120
+ 'retro-arcade',
121
+ 'sage-garden',
122
+ 'soft-pop',
123
+ 'solar-dusk',
124
+ 'starry-night',
125
+ 'sunset-horizon',
126
+ 'supabase',
127
+ 't3-chat',
128
+ 'tangerine',
129
+ 'twitter',
130
+ 'vercel',
131
+ 'vintage-paper',
132
+ 'violet-bloom',
133
+ ],
134
+ activeTheme: 'shellui',
135
+ });
136
+ expect(resolved.themes.map((t) => t.name)).toEqual([
137
+ 'shellui',
138
+ 'claude',
139
+ 'light-green',
140
+ 'zen-inspired',
141
+ 'astro-vista',
142
+ 'shadcn',
143
+ 'amber-minimal',
144
+ 'amethyst-haze',
145
+ 'bold-tech',
146
+ 'bubblegum',
147
+ 'caffeine',
148
+ 'candyland',
149
+ 'catppuccin',
150
+ 'claymorphism',
151
+ 'clean-slate',
152
+ 'cosmic-night',
153
+ 'cyberpunk',
154
+ 'darkmatter',
155
+ 'doom-64',
156
+ 'elegant-luxury',
157
+ 'graphite',
158
+ 'kodama-grove',
159
+ 'midnight-bloom',
160
+ 'mocha-mousse',
161
+ 'modern-minimal',
162
+ 'mono',
163
+ 'nature',
164
+ 'neo-brutalism',
165
+ 'northern-lights',
166
+ 'notebook',
167
+ 'ocean-breeze',
168
+ 'pastel-dreams',
169
+ 'perpetuity',
170
+ 'quantum-rose',
171
+ 'retro-arcade',
172
+ 'sage-garden',
173
+ 'soft-pop',
174
+ 'solar-dusk',
175
+ 'starry-night',
176
+ 'sunset-horizon',
177
+ 'supabase',
178
+ 't3-chat',
179
+ 'tangerine',
180
+ 'twitter',
181
+ 'vercel',
182
+ 'vintage-paper',
183
+ 'violet-bloom',
184
+ ]);
185
+ expect(resolved.activeTheme).toBe('shellui');
186
+ });
187
+
188
+ it('defaults to the official Shellui theme', () => {
189
+ const resolved = resolveThemeConfig({});
190
+ expect(resolved.themes).toHaveLength(1);
191
+ expect(resolved.activeTheme).toBe('shellui');
192
+ expect(resolved.themes[0].name).toBe('shellui');
193
+ });
194
+
195
+ it('aliases default to shellui', () => {
196
+ const resolved = resolveThemeConfig({ theme: 'default' });
197
+ expect(resolved.themes[0].name).toBe('shellui');
198
+ });
199
+ });
200
+
201
+ describe('registry', () => {
202
+ beforeEach(() => {
203
+ clearThemeRegistry();
204
+ });
205
+
206
+ it('exposes only configured available themes', () => {
207
+ setAvailableThemes([themes.claude, themes.shellui]);
208
+ expect(getAllThemes().map((t) => t.name)).toEqual(['claude', 'shellui']);
209
+ expect(getTheme('claude')?.name).toBe('claude');
210
+ });
211
+ });
212
+
213
+ describe('curated themes', () => {
214
+ it('exports shellui as defaultTheme plus curated themes', () => {
215
+ expect(defaultTheme.name).toBe('shellui');
216
+ expect(shelluiTheme).toBe(defaultTheme);
217
+ expect(claudeTheme.name).toBe('claude');
218
+ expect(themeNames).toEqual([
219
+ 'shellui',
220
+ 'claude',
221
+ 'light-green',
222
+ 'zen-inspired',
223
+ 'astro-vista',
224
+ 'shadcn',
225
+ 'amber-minimal',
226
+ 'amethyst-haze',
227
+ 'bold-tech',
228
+ 'bubblegum',
229
+ 'caffeine',
230
+ 'candyland',
231
+ 'catppuccin',
232
+ 'claymorphism',
233
+ 'clean-slate',
234
+ 'cosmic-night',
235
+ 'cyberpunk',
236
+ 'darkmatter',
237
+ 'doom-64',
238
+ 'elegant-luxury',
239
+ 'graphite',
240
+ 'kodama-grove',
241
+ 'midnight-bloom',
242
+ 'mocha-mousse',
243
+ 'modern-minimal',
244
+ 'mono',
245
+ 'nature',
246
+ 'neo-brutalism',
247
+ 'northern-lights',
248
+ 'notebook',
249
+ 'ocean-breeze',
250
+ 'pastel-dreams',
251
+ 'perpetuity',
252
+ 'quantum-rose',
253
+ 'retro-arcade',
254
+ 'sage-garden',
255
+ 'soft-pop',
256
+ 'solar-dusk',
257
+ 'starry-night',
258
+ 'sunset-horizon',
259
+ 'supabase',
260
+ 't3-chat',
261
+ 'tangerine',
262
+ 'twitter',
263
+ 'vercel',
264
+ 'vintage-paper',
265
+ 'violet-bloom',
266
+ ]);
267
+ expect(curatedThemes).toHaveLength(47);
268
+ });
269
+
270
+ it('every curated theme uses OKLCH color values', () => {
271
+ for (const theme of curatedThemes) {
272
+ expect(theme.colors.light.primary.startsWith('oklch(')).toBe(true);
273
+ expect(theme.colors.dark.primary.startsWith('oklch(')).toBe(true);
274
+ }
275
+ });
276
+ });