@space-man/react-theme-animation 2.1.0 → 2.3.0

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 (68) hide show
  1. package/README.md +72 -142
  2. package/dist/core/index.cjs +74 -0
  3. package/dist/core/index.cjs.map +1 -0
  4. package/dist/{esm/types/index.d.ts → core/index.d.cts} +26 -8
  5. package/dist/{cjs/types → core}/index.d.ts +26 -8
  6. package/dist/core/index.js +66 -0
  7. package/dist/core/index.js.map +1 -0
  8. package/dist/index.cjs +1756 -0
  9. package/dist/index.cjs.map +1 -0
  10. package/dist/index.d.cts +4 -0
  11. package/dist/index.d.ts +4 -0
  12. package/dist/index.js +1706 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/react/index.cjs +1742 -0
  15. package/dist/react/index.cjs.map +1 -0
  16. package/dist/react/index.d.cts +224 -0
  17. package/dist/react/index.d.ts +224 -0
  18. package/dist/react/index.js +1697 -0
  19. package/dist/react/index.js.map +1 -0
  20. package/dist/tanstack/index.cjs +34 -0
  21. package/dist/tanstack/index.cjs.map +1 -0
  22. package/dist/tanstack/index.d.cts +20 -0
  23. package/dist/tanstack/index.d.ts +20 -0
  24. package/dist/tanstack/index.js +27 -0
  25. package/dist/tanstack/index.js.map +1 -0
  26. package/package.json +66 -37
  27. package/dist/cjs/components/NextThemeProvider.d.ts +0 -81
  28. package/dist/cjs/components/NextThemeProvider.js +0 -223
  29. package/dist/cjs/components/SpacemanThemeProvider.d.ts +0 -57
  30. package/dist/cjs/components/SpacemanThemeProvider.js +0 -113
  31. package/dist/cjs/components/TanStackThemeProvider.d.ts +0 -68
  32. package/dist/cjs/components/TanStackThemeProvider.js +0 -183
  33. package/dist/cjs/components/ThemeSelector.d.ts +0 -3
  34. package/dist/cjs/components/ThemeSelector.js +0 -39
  35. package/dist/cjs/components/ThemeSwitcher.d.ts +0 -3
  36. package/dist/cjs/components/ThemeSwitcher.js +0 -81
  37. package/dist/cjs/components/ViteThemeProvider.d.ts +0 -61
  38. package/dist/cjs/components/ViteThemeProvider.js +0 -140
  39. package/dist/cjs/components/ui/select.d.ts +0 -15
  40. package/dist/cjs/components/ui/select.js +0 -83
  41. package/dist/cjs/hooks/use-theme-animation.d.ts +0 -2
  42. package/dist/cjs/hooks/use-theme-animation.js +0 -234
  43. package/dist/cjs/index.d.ts +0 -10
  44. package/dist/cjs/index.js +0 -30
  45. package/dist/cjs/types/index.js +0 -9
  46. package/dist/cjs/utils/animations.d.ts +0 -21
  47. package/dist/cjs/utils/animations.js +0 -189
  48. package/dist/esm/components/NextThemeProvider.d.ts +0 -81
  49. package/dist/esm/components/NextThemeProvider.js +0 -185
  50. package/dist/esm/components/SpacemanThemeProvider.d.ts +0 -57
  51. package/dist/esm/components/SpacemanThemeProvider.js +0 -108
  52. package/dist/esm/components/TanStackThemeProvider.d.ts +0 -68
  53. package/dist/esm/components/TanStackThemeProvider.js +0 -178
  54. package/dist/esm/components/ThemeSelector.d.ts +0 -3
  55. package/dist/esm/components/ThemeSelector.js +0 -35
  56. package/dist/esm/components/ThemeSwitcher.d.ts +0 -3
  57. package/dist/esm/components/ThemeSwitcher.js +0 -77
  58. package/dist/esm/components/ViteThemeProvider.d.ts +0 -61
  59. package/dist/esm/components/ViteThemeProvider.js +0 -135
  60. package/dist/esm/components/ui/select.d.ts +0 -15
  61. package/dist/esm/components/ui/select.js +0 -39
  62. package/dist/esm/hooks/use-theme-animation.d.ts +0 -2
  63. package/dist/esm/hooks/use-theme-animation.js +0 -230
  64. package/dist/esm/index.d.ts +0 -10
  65. package/dist/esm/index.js +0 -10
  66. package/dist/esm/types/index.js +0 -6
  67. package/dist/esm/utils/animations.d.ts +0 -21
  68. package/dist/esm/utils/animations.js +0 -177
@@ -1,81 +0,0 @@
1
- import React, { ReactNode } from 'react';
2
- import { Theme, ColorTheme, ThemeAnimationType } from '../types';
3
- /**
4
- * Context type for the Next Theme Provider
5
- */
6
- interface NextThemeContextType {
7
- ref: React.RefObject<HTMLButtonElement | null>;
8
- theme: Theme;
9
- colorTheme: ColorTheme;
10
- resolvedTheme: 'light' | 'dark';
11
- systemTheme: 'light' | 'dark';
12
- setTheme: (theme: Theme) => void;
13
- setColorTheme: (colorTheme: ColorTheme) => void;
14
- switchTheme: (theme: Theme, animationOff?: boolean) => Promise<void>;
15
- switchColorTheme: (colorTheme: string) => void;
16
- toggleTheme: (animationOff?: boolean) => Promise<void>;
17
- toggleLightTheme: (animationOff?: boolean) => Promise<void>;
18
- toggleDarkTheme: (animationOff?: boolean) => Promise<void>;
19
- toggleColorTheme: () => void;
20
- createColorThemeToggle: (targetColorTheme: string) => () => void;
21
- isColorThemeActive: (targetColorTheme: string) => boolean;
22
- switchThemeFromElement: (theme: Theme, element: HTMLButtonElement) => Promise<void>;
23
- }
24
- /**
25
- * Props for the Next Theme Provider
26
- */
27
- interface NextThemeProviderProps {
28
- children: ReactNode;
29
- themes?: Theme[];
30
- colorThemes?: ColorTheme[];
31
- defaultTheme?: Theme;
32
- defaultColorTheme?: ColorTheme;
33
- animationType?: ThemeAnimationType;
34
- duration?: number;
35
- storageKey?: string;
36
- colorStorageKey?: string;
37
- attribute?: 'class' | 'data-theme';
38
- globalClassName?: string;
39
- colorThemePrefix?: string;
40
- nonce?: string;
41
- disableAnimationOnInit?: boolean;
42
- disablePreHydrationScript?: boolean;
43
- }
44
- /**
45
- * Next Theme Provider - Next.js optimized theme management with animations
46
- *
47
- * This provider is specifically optimized for Next.js and SSR frameworks with
48
- * pre-hydration script injection to prevent flash of wrong theme.
49
- *
50
- * Features:
51
- * - Pre-hydration script for flash prevention (SSR apps)
52
- * - Animated theme transitions via View Transitions API
53
- * - Multi-dimensional theming (theme + colorTheme)
54
- * - System theme detection
55
- * - CSP support via nonce prop
56
- *
57
- * @param children - React children to wrap with theme context
58
- * @param themes - Available theme options
59
- * @param colorThemes - Available color theme options
60
- * @param defaultTheme - Default theme to use
61
- * @param defaultColorTheme - Default color theme to use
62
- * @param animationType - Animation type for theme transitions
63
- * @param duration - Animation duration in milliseconds
64
- * @param storageKey - LocalStorage key for theme preference
65
- * @param colorStorageKey - LocalStorage key for color theme preference
66
- * @param attribute - HTML attribute to use for theme ('class' or 'data-theme')
67
- * @param globalClassName - Class name for dark theme (when using 'class' attribute)
68
- * @param colorThemePrefix - Prefix for color theme classes
69
- * @param nonce - CSP nonce for inline script (SSR apps)
70
- * @param disableAnimationOnInit - Skip animation during initial hydration
71
- * @param disablePreHydrationScript - Disable flash prevention script (for SPAs without SSR)
72
- */
73
- export declare const NextThemeProvider: React.FC<NextThemeProviderProps>;
74
- /**
75
- * Hook to consume the Next Theme context
76
- *
77
- * @returns Theme context value with all theme state and methods
78
- * @throws Error if used outside of NextThemeProvider
79
- */
80
- export declare const useNextTheme: () => NextThemeContextType;
81
- export {};
@@ -1,223 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.useNextTheme = exports.NextThemeProvider = void 0;
37
- const jsx_runtime_1 = require("react/jsx-runtime");
38
- const react_1 = __importStar(require("react"));
39
- const use_theme_animation_1 = require("../hooks/use-theme-animation");
40
- const types_1 = require("../types");
41
- const NextThemeContext = (0, react_1.createContext)(undefined);
42
- /**
43
- * Pre-hydration script content generator
44
- * This script runs BEFORE React hydrates to prevent flash of wrong theme
45
- */
46
- const generatePreHydrationScript = (storageKey, colorStorageKey, defaultTheme, defaultColorTheme, attribute, globalClassName, colorThemePrefix) => {
47
- return `
48
- (function() {
49
- try {
50
- var theme = localStorage.getItem('${storageKey}') || '${defaultTheme}';
51
- var colorTheme = localStorage.getItem('${colorStorageKey}') || '${defaultColorTheme}';
52
- var resolved = theme === 'system'
53
- ? (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')
54
- : theme;
55
-
56
- if ('${attribute}' === 'class') {
57
- if (resolved === 'dark') {
58
- document.documentElement.classList.add('${globalClassName}');
59
- } else {
60
- document.documentElement.classList.remove('${globalClassName}');
61
- }
62
- } else {
63
- document.documentElement.setAttribute('data-theme', resolved);
64
- }
65
-
66
- document.documentElement.style.colorScheme = resolved;
67
- document.documentElement.classList.add('${colorThemePrefix}' + colorTheme);
68
- } catch (e) {
69
- console.warn('Theme pre-hydration script failed:', e);
70
- }
71
- })();
72
- `;
73
- };
74
- /**
75
- * Pre-hydration script component
76
- * Injects inline script before React hydration to prevent theme flash
77
- */
78
- const ThemePreHydrationScript = react_1.default.memo(({ storageKey, colorStorageKey, defaultTheme, defaultColorTheme, attribute, globalClassName, colorThemePrefix, nonce, }) => {
79
- const scriptContent = generatePreHydrationScript(storageKey, colorStorageKey, defaultTheme, defaultColorTheme, attribute, globalClassName, colorThemePrefix);
80
- return ((0, jsx_runtime_1.jsx)("script", { nonce: nonce, suppressHydrationWarning: true, dangerouslySetInnerHTML: { __html: scriptContent } }));
81
- });
82
- ThemePreHydrationScript.displayName = 'ThemePreHydrationScript';
83
- /**
84
- * Next Theme Provider - Next.js optimized theme management with animations
85
- *
86
- * This provider is specifically optimized for Next.js and SSR frameworks with
87
- * pre-hydration script injection to prevent flash of wrong theme.
88
- *
89
- * Features:
90
- * - Pre-hydration script for flash prevention (SSR apps)
91
- * - Animated theme transitions via View Transitions API
92
- * - Multi-dimensional theming (theme + colorTheme)
93
- * - System theme detection
94
- * - CSP support via nonce prop
95
- *
96
- * @param children - React children to wrap with theme context
97
- * @param themes - Available theme options
98
- * @param colorThemes - Available color theme options
99
- * @param defaultTheme - Default theme to use
100
- * @param defaultColorTheme - Default color theme to use
101
- * @param animationType - Animation type for theme transitions
102
- * @param duration - Animation duration in milliseconds
103
- * @param storageKey - LocalStorage key for theme preference
104
- * @param colorStorageKey - LocalStorage key for color theme preference
105
- * @param attribute - HTML attribute to use for theme ('class' or 'data-theme')
106
- * @param globalClassName - Class name for dark theme (when using 'class' attribute)
107
- * @param colorThemePrefix - Prefix for color theme classes
108
- * @param nonce - CSP nonce for inline script (SSR apps)
109
- * @param disableAnimationOnInit - Skip animation during initial hydration
110
- * @param disablePreHydrationScript - Disable flash prevention script (for SPAs without SSR)
111
- */
112
- const NextThemeProvider = ({ children, themes = ['light', 'dark', 'system'], colorThemes = ['default'], defaultTheme = 'system', defaultColorTheme = 'default', animationType = types_1.ThemeAnimationType.CIRCLE, duration = 750, storageKey = 'theme', colorStorageKey = 'color-theme', attribute = 'class', globalClassName = 'dark', colorThemePrefix = 'theme-', nonce, disableAnimationOnInit = true, disablePreHydrationScript = false, }) => {
113
- const [mounted, setMounted] = (0, react_1.useState)(false);
114
- const themeState = (0, use_theme_animation_1.useThemeAnimation)({
115
- themes,
116
- colorThemes,
117
- defaultTheme,
118
- defaultColorTheme,
119
- animationType,
120
- duration,
121
- storageKey,
122
- colorStorageKey,
123
- globalClassName: attribute === 'class' ? globalClassName : undefined,
124
- colorThemePrefix,
125
- });
126
- (0, react_1.useEffect)(() => {
127
- setMounted(true);
128
- }, []);
129
- const switchThemeWithHydrationAwareness = (0, react_1.useCallback)(async (theme, animationOff = false) => {
130
- if (!mounted && disableAnimationOnInit) {
131
- themeState.setTheme(theme);
132
- }
133
- else {
134
- await themeState.switchTheme(theme, animationOff);
135
- }
136
- }, [mounted, disableAnimationOnInit, themeState]);
137
- const switchThemeFromElement = (0, react_1.useCallback)(async (theme, element) => {
138
- if (!mounted && disableAnimationOnInit) {
139
- themeState.setTheme(theme);
140
- return;
141
- }
142
- if (themeState.ref.current) {
143
- const originalRef = themeState.ref.current;
144
- Object.defineProperty(themeState.ref, 'current', {
145
- value: element,
146
- writable: true,
147
- configurable: true,
148
- });
149
- await themeState.switchTheme(theme);
150
- Object.defineProperty(themeState.ref, 'current', {
151
- value: originalRef,
152
- writable: true,
153
- configurable: true,
154
- });
155
- }
156
- else {
157
- Object.defineProperty(themeState.ref, 'current', {
158
- value: element,
159
- writable: true,
160
- configurable: true,
161
- });
162
- await themeState.switchTheme(theme);
163
- }
164
- }, [mounted, disableAnimationOnInit, themeState]);
165
- const systemTheme = typeof window !== 'undefined' && window.matchMedia('(prefers-color-scheme: dark)').matches
166
- ? 'dark'
167
- : 'light';
168
- if (!mounted) {
169
- const loadingContextValue = {
170
- ref: { current: null },
171
- theme: defaultTheme,
172
- colorTheme: defaultColorTheme,
173
- resolvedTheme: defaultTheme === 'dark' ? 'dark' : 'light',
174
- systemTheme: 'light',
175
- setTheme: () => { },
176
- setColorTheme: () => { },
177
- switchTheme: async () => { },
178
- switchThemeFromElement: async () => { },
179
- switchColorTheme: () => { },
180
- toggleTheme: async () => { },
181
- toggleLightTheme: async () => { },
182
- toggleDarkTheme: async () => { },
183
- toggleColorTheme: () => { },
184
- createColorThemeToggle: () => () => { },
185
- isColorThemeActive: () => false,
186
- };
187
- return ((0, jsx_runtime_1.jsxs)(NextThemeContext.Provider, { value: loadingContextValue, children: [!disablePreHydrationScript && ((0, jsx_runtime_1.jsx)(ThemePreHydrationScript, { storageKey: storageKey, colorStorageKey: colorStorageKey, defaultTheme: defaultTheme, defaultColorTheme: defaultColorTheme, attribute: attribute, globalClassName: globalClassName, colorThemePrefix: colorThemePrefix, nonce: nonce })), children] }));
188
- }
189
- const contextValue = {
190
- ref: themeState.ref,
191
- theme: themeState.theme,
192
- colorTheme: themeState.colorTheme,
193
- resolvedTheme: themeState.resolvedTheme,
194
- systemTheme,
195
- setTheme: themeState.setTheme,
196
- setColorTheme: themeState.setColorTheme,
197
- switchTheme: switchThemeWithHydrationAwareness,
198
- switchThemeFromElement,
199
- switchColorTheme: themeState.switchColorTheme,
200
- toggleTheme: themeState.toggleTheme,
201
- toggleLightTheme: themeState.toggleLightTheme,
202
- toggleDarkTheme: themeState.toggleDarkTheme,
203
- toggleColorTheme: themeState.toggleColorTheme,
204
- createColorThemeToggle: themeState.createColorThemeToggle,
205
- isColorThemeActive: themeState.isColorThemeActive,
206
- };
207
- return ((0, jsx_runtime_1.jsxs)(NextThemeContext.Provider, { value: contextValue, children: [!disablePreHydrationScript && ((0, jsx_runtime_1.jsx)(ThemePreHydrationScript, { storageKey: storageKey, colorStorageKey: colorStorageKey, defaultTheme: defaultTheme, defaultColorTheme: defaultColorTheme, attribute: attribute, globalClassName: globalClassName, colorThemePrefix: colorThemePrefix, nonce: nonce })), children] }));
208
- };
209
- exports.NextThemeProvider = NextThemeProvider;
210
- /**
211
- * Hook to consume the Next Theme context
212
- *
213
- * @returns Theme context value with all theme state and methods
214
- * @throws Error if used outside of NextThemeProvider
215
- */
216
- const useNextTheme = () => {
217
- const context = (0, react_1.useContext)(NextThemeContext);
218
- if (context === undefined) {
219
- throw new Error('useNextTheme must be used within a NextThemeProvider');
220
- }
221
- return context;
222
- };
223
- exports.useNextTheme = useNextTheme;
@@ -1,57 +0,0 @@
1
- import React, { ReactNode } from 'react';
2
- import { Theme, ColorTheme, ThemeAnimationType } from '../types';
3
- /**
4
- * Context type for the Spaceman Theme Provider
5
- */
6
- interface SpacemanThemeContextType {
7
- ref: React.RefObject<HTMLButtonElement | null>;
8
- theme: Theme;
9
- colorTheme: ColorTheme;
10
- resolvedTheme: 'light' | 'dark';
11
- setTheme: (theme: Theme) => void;
12
- setColorTheme: (colorTheme: ColorTheme) => void;
13
- switchTheme: (theme: Theme) => Promise<void>;
14
- switchColorTheme: (colorTheme: string) => void;
15
- toggleTheme: () => Promise<void>;
16
- toggleLightTheme: () => Promise<void>;
17
- toggleDarkTheme: () => Promise<void>;
18
- toggleColorTheme: () => void;
19
- createColorThemeToggle: (targetColorTheme: string) => () => void;
20
- isColorThemeActive: (targetColorTheme: string) => boolean;
21
- switchThemeFromElement: (theme: Theme, element: HTMLButtonElement) => Promise<void>;
22
- }
23
- /**
24
- * Props for the Spaceman Theme Provider
25
- */
26
- interface SpacemanThemeProviderProps {
27
- children: ReactNode;
28
- themes?: Theme[];
29
- colorThemes?: ColorTheme[];
30
- defaultTheme?: Theme;
31
- defaultColorTheme?: ColorTheme;
32
- animationType?: ThemeAnimationType;
33
- duration?: number;
34
- }
35
- /**
36
- * Spaceman Theme Provider - Provides centralized theme state management
37
- *
38
- * This provider creates a single source of truth for theme state using the useThemeAnimation hook.
39
- * All theme-related components should consume from this context to ensure synchronization.
40
- *
41
- * @param children - React children to wrap with theme context
42
- * @param themes - Available theme options (default: ['light', 'dark', 'system'])
43
- * @param colorThemes - Available color theme options (default: ['default'])
44
- * @param defaultTheme - Default theme to use (default: 'system')
45
- * @param defaultColorTheme - Default color theme to use (default: 'default')
46
- * @param animationType - Animation type for theme transitions (default: CIRCLE)
47
- * @param duration - Animation duration in milliseconds (default: 750)
48
- */
49
- export declare const SpacemanThemeProvider: React.FC<SpacemanThemeProviderProps>;
50
- /**
51
- * Hook to consume the Spaceman Theme context
52
- *
53
- * @returns Theme context value with all theme state and methods
54
- * @throws Error if used outside of SpacemanThemeProvider
55
- */
56
- export declare const useSpacemanTheme: () => SpacemanThemeContextType;
57
- export {};
@@ -1,113 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useSpacemanTheme = exports.SpacemanThemeProvider = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const react_1 = require("react");
6
- const use_theme_animation_1 = require("../hooks/use-theme-animation");
7
- const types_1 = require("../types");
8
- const SpacemanThemeContext = (0, react_1.createContext)(undefined);
9
- /**
10
- * Spaceman Theme Provider - Provides centralized theme state management
11
- *
12
- * This provider creates a single source of truth for theme state using the useThemeAnimation hook.
13
- * All theme-related components should consume from this context to ensure synchronization.
14
- *
15
- * @param children - React children to wrap with theme context
16
- * @param themes - Available theme options (default: ['light', 'dark', 'system'])
17
- * @param colorThemes - Available color theme options (default: ['default'])
18
- * @param defaultTheme - Default theme to use (default: 'system')
19
- * @param defaultColorTheme - Default color theme to use (default: 'default')
20
- * @param animationType - Animation type for theme transitions (default: CIRCLE)
21
- * @param duration - Animation duration in milliseconds (default: 750)
22
- */
23
- const SpacemanThemeProvider = ({ children, themes = ['light', 'dark', 'system'], colorThemes = ['default'], defaultTheme = 'system', defaultColorTheme = 'default', animationType = types_1.ThemeAnimationType.CIRCLE, duration = 750, }) => {
24
- const [mounted, setMounted] = (0, react_1.useState)(false);
25
- const themeState = (0, use_theme_animation_1.useThemeAnimation)({
26
- themes,
27
- colorThemes,
28
- defaultTheme,
29
- defaultColorTheme,
30
- animationType,
31
- duration,
32
- });
33
- (0, react_1.useEffect)(() => {
34
- setMounted(true);
35
- }, []);
36
- const switchThemeFromElement = async (theme, element) => {
37
- if (themeState.ref.current) {
38
- const originalRef = themeState.ref.current;
39
- Object.defineProperty(themeState.ref, 'current', {
40
- value: element,
41
- writable: true,
42
- configurable: true,
43
- });
44
- await themeState.switchTheme(theme);
45
- Object.defineProperty(themeState.ref, 'current', {
46
- value: originalRef,
47
- writable: true,
48
- configurable: true,
49
- });
50
- }
51
- else {
52
- Object.defineProperty(themeState.ref, 'current', {
53
- value: element,
54
- writable: true,
55
- configurable: true,
56
- });
57
- await themeState.switchTheme(theme);
58
- }
59
- };
60
- if (!mounted) {
61
- const loadingContextValue = {
62
- ref: { current: null },
63
- theme: defaultTheme,
64
- colorTheme: defaultColorTheme,
65
- resolvedTheme: defaultTheme === 'dark' ? 'dark' : 'light',
66
- setTheme: () => { },
67
- setColorTheme: () => { },
68
- switchTheme: async () => { },
69
- switchThemeFromElement: async () => { },
70
- switchColorTheme: () => { },
71
- toggleTheme: async () => { },
72
- toggleLightTheme: async () => { },
73
- toggleDarkTheme: async () => { },
74
- toggleColorTheme: () => { },
75
- createColorThemeToggle: () => () => { },
76
- isColorThemeActive: () => false,
77
- };
78
- return ((0, jsx_runtime_1.jsx)(SpacemanThemeContext.Provider, { value: loadingContextValue, children: children }));
79
- }
80
- const contextValue = {
81
- ref: themeState.ref,
82
- theme: themeState.theme,
83
- colorTheme: themeState.colorTheme,
84
- resolvedTheme: themeState.resolvedTheme,
85
- setTheme: themeState.setTheme,
86
- setColorTheme: themeState.setColorTheme,
87
- switchTheme: themeState.switchTheme,
88
- switchThemeFromElement,
89
- switchColorTheme: themeState.switchColorTheme,
90
- toggleTheme: themeState.toggleTheme,
91
- toggleLightTheme: themeState.toggleLightTheme,
92
- toggleDarkTheme: themeState.toggleDarkTheme,
93
- toggleColorTheme: themeState.toggleColorTheme,
94
- createColorThemeToggle: themeState.createColorThemeToggle,
95
- isColorThemeActive: themeState.isColorThemeActive,
96
- };
97
- return ((0, jsx_runtime_1.jsx)(SpacemanThemeContext.Provider, { value: contextValue, children: children }));
98
- };
99
- exports.SpacemanThemeProvider = SpacemanThemeProvider;
100
- /**
101
- * Hook to consume the Spaceman Theme context
102
- *
103
- * @returns Theme context value with all theme state and methods
104
- * @throws Error if used outside of SpacemanThemeProvider
105
- */
106
- const useSpacemanTheme = () => {
107
- const context = (0, react_1.useContext)(SpacemanThemeContext);
108
- if (context === undefined) {
109
- throw new Error('useSpacemanTheme must be used within a SpacemanThemeProvider');
110
- }
111
- return context;
112
- };
113
- exports.useSpacemanTheme = useSpacemanTheme;
@@ -1,68 +0,0 @@
1
- import React, { ReactNode } from 'react';
2
- import { Theme, ColorTheme, ThemeAnimationType } from '../types';
3
- /**
4
- * Context type for the TanStack Start Theme Provider
5
- */
6
- interface TanStackThemeContextType {
7
- ref: React.RefObject<HTMLButtonElement | null>;
8
- theme: Theme;
9
- colorTheme: ColorTheme;
10
- resolvedTheme: 'light' | 'dark';
11
- systemTheme: 'light' | 'dark';
12
- isHydrated: boolean;
13
- setTheme: (theme: Theme) => void;
14
- setColorTheme: (colorTheme: ColorTheme) => void;
15
- switchTheme: (theme: Theme, animationOff?: boolean) => Promise<void>;
16
- switchColorTheme: (colorTheme: string) => void;
17
- toggleTheme: (animationOff?: boolean) => Promise<void>;
18
- toggleLightTheme: (animationOff?: boolean) => Promise<void>;
19
- toggleDarkTheme: (animationOff?: boolean) => Promise<void>;
20
- toggleColorTheme: () => void;
21
- createColorThemeToggle: (targetColorTheme: string) => () => void;
22
- isColorThemeActive: (targetColorTheme: string) => boolean;
23
- switchThemeFromElement: (theme: Theme, element: HTMLButtonElement) => Promise<void>;
24
- }
25
- /**
26
- * Props for the TanStack Start Theme Provider
27
- */
28
- interface TanStackThemeProviderProps {
29
- children: ReactNode;
30
- themes?: Theme[];
31
- colorThemes?: ColorTheme[];
32
- defaultTheme?: Theme;
33
- defaultColorTheme?: ColorTheme;
34
- animationType?: ThemeAnimationType;
35
- duration?: number;
36
- /** Storage key for theme preference */
37
- storageKey?: string;
38
- /** Storage key for color theme preference */
39
- colorStorageKey?: string;
40
- /** Class name for dark theme */
41
- globalClassName?: string;
42
- /** Prefix for color theme classes */
43
- colorThemePrefix?: string;
44
- }
45
- /**
46
- * TanStack Start Theme Provider - Optimized for TanStack Start Framework
47
- *
48
- * @param children - React children to wrap with theme context
49
- * @param themes - Available theme options
50
- * @param colorThemes - Available color theme options
51
- * @param defaultTheme - Default theme to use
52
- * @param defaultColorTheme - Default color theme to use
53
- * @param animationType - Animation type for theme transitions
54
- * @param duration - Animation duration in milliseconds
55
- * @param storageKey - LocalStorage key for theme preference
56
- * @param colorStorageKey - LocalStorage key for color theme preference
57
- * @param globalClassName - Class name for dark theme
58
- * @param colorThemePrefix - Prefix for color theme classes
59
- */
60
- export declare const TanStackThemeProvider: React.FC<TanStackThemeProviderProps>;
61
- /**
62
- * Hook to consume the TanStack Theme context
63
- *
64
- * @returns Theme context value with all theme state and methods
65
- * @throws Error if used outside of TanStackThemeProvider
66
- */
67
- export declare const useTanStackTheme: () => TanStackThemeContextType;
68
- export {};