@shohojdhara/atomix 0.3.4 → 0.3.6

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 (237) hide show
  1. package/README.md +101 -199
  2. package/atomix.config.ts +241 -0
  3. package/dist/atomix.css +269 -189
  4. package/dist/atomix.css.map +1 -0
  5. package/dist/atomix.min.css +15179 -11
  6. package/dist/atomix.min.css.map +1 -0
  7. package/dist/charts.d.ts +1929 -0
  8. package/dist/charts.js +6477 -0
  9. package/dist/charts.js.map +1 -0
  10. package/dist/core.d.ts +1289 -0
  11. package/dist/core.js +3373 -0
  12. package/dist/core.js.map +1 -0
  13. package/dist/forms.d.ts +1085 -0
  14. package/dist/forms.js +2466 -0
  15. package/dist/forms.js.map +1 -0
  16. package/dist/heavy.d.ts +636 -0
  17. package/dist/heavy.js +4566 -0
  18. package/dist/heavy.js.map +1 -0
  19. package/dist/index.d.ts +5171 -4792
  20. package/dist/index.esm.js +6098 -4563
  21. package/dist/index.esm.js.map +1 -1
  22. package/dist/index.js +6291 -4747
  23. package/dist/index.js.map +1 -1
  24. package/dist/index.min.js +1 -1
  25. package/dist/index.min.js.map +1 -1
  26. package/dist/layout.d.ts +300 -0
  27. package/dist/layout.js +336 -0
  28. package/dist/layout.js.map +1 -0
  29. package/dist/theme.d.ts +2122 -0
  30. package/dist/theme.js +6084 -0
  31. package/dist/theme.js.map +1 -0
  32. package/package.json +59 -27
  33. package/scripts/atomix-cli.js +544 -16
  34. package/scripts/cli/__tests__/cli-commands.test.js +204 -0
  35. package/scripts/cli/__tests__/utils.test.js +201 -0
  36. package/scripts/cli/__tests__/vitest.config.js +26 -0
  37. package/scripts/cli/interactive-init.js +1 -1
  38. package/scripts/cli/token-manager.js +32 -7
  39. package/scripts/cli/utils.js +347 -0
  40. package/src/components/Accordion/Accordion.stories.tsx +50 -17
  41. package/src/components/Accordion/Accordion.tsx +5 -54
  42. package/src/components/Accordion/index.ts +1 -1
  43. package/src/components/AtomixGlass/AtomixGlass.tsx +65 -31
  44. package/src/components/AtomixGlass/AtomixGlassContainer.tsx +11 -4
  45. package/src/components/AtomixGlass/stories/AtomixGlass.stories.tsx +1 -32
  46. package/src/components/AtomixGlass/stories/Examples.stories.tsx +2 -2
  47. package/src/components/AtomixGlass/stories/shared-components.tsx +0 -31
  48. package/src/components/Avatar/Avatar.stories.tsx +7 -0
  49. package/src/components/Avatar/Avatar.tsx +3 -3
  50. package/src/components/Badge/Badge.stories.tsx +91 -13
  51. package/src/components/Badge/Badge.tsx +3 -3
  52. package/src/components/Block/Block.stories.tsx +7 -23
  53. package/src/components/Breadcrumb/Breadcrumb.stories.tsx +7 -0
  54. package/src/components/Breadcrumb/Breadcrumb.tsx +3 -3
  55. package/src/components/Button/Button.stories.tsx +141 -22
  56. package/src/components/Button/ButtonGroup.stories.tsx +315 -0
  57. package/src/components/Button/ButtonGroup.tsx +67 -0
  58. package/src/components/Button/index.ts +2 -0
  59. package/src/components/Callout/Callout.stories.tsx +8 -6
  60. package/src/components/Card/Card.stories.tsx +82 -28
  61. package/src/components/Card/ElevationCard.tsx +1 -1
  62. package/src/components/Chart/AnimatedChart.tsx +19 -18
  63. package/src/components/Chart/AreaChart.tsx +5 -2
  64. package/src/components/Chart/BarChart.tsx +1 -1
  65. package/src/components/Chart/BubbleChart.tsx +6 -6
  66. package/src/components/Chart/CandlestickChart.tsx +0 -1
  67. package/src/components/Chart/Chart.stories.tsx +5 -7
  68. package/src/components/Chart/Chart.tsx +0 -16
  69. package/src/components/Chart/ChartRenderer.tsx +1 -1
  70. package/src/components/Chart/ChartToolbar.tsx +1 -0
  71. package/src/components/Chart/DonutChart.tsx +0 -1
  72. package/src/components/Chart/FunnelChart.tsx +1 -2
  73. package/src/components/Chart/GaugeChart.tsx +0 -1
  74. package/src/components/Chart/HeatmapChart.tsx +0 -1
  75. package/src/components/Chart/LineChart.tsx +0 -1
  76. package/src/components/Chart/MultiAxisChart.tsx +0 -1
  77. package/src/components/Chart/PieChart.tsx +0 -1
  78. package/src/components/Chart/RadarChart.tsx +19 -13
  79. package/src/components/Chart/ScatterChart.tsx +3 -4
  80. package/src/components/Chart/TreemapChart.tsx +2 -1
  81. package/src/components/Chart/WaterfallChart.tsx +0 -2
  82. package/src/components/Chart/types.ts +12 -2
  83. package/src/components/Chart/utils.ts +4 -3
  84. package/src/components/ColorModeToggle/ColorModeToggle.stories.tsx +7 -0
  85. package/src/components/DataTable/DataTable.stories.tsx +23 -16
  86. package/src/components/DataTable/DataTable.tsx +3 -3
  87. package/src/components/DatePicker/DatePicker.stories.tsx +27 -19
  88. package/src/components/Dropdown/Dropdown.stories.tsx +11 -19
  89. package/src/components/Dropdown/Dropdown.tsx +12 -9
  90. package/src/components/EdgePanel/EdgePanel.stories.tsx +1 -0
  91. package/src/components/Footer/Footer.stories.tsx +8 -6
  92. package/src/components/Footer/FooterLink.tsx +9 -2
  93. package/src/components/Footer/FooterSection.tsx +3 -3
  94. package/src/components/Form/Checkbox.stories.tsx +7 -0
  95. package/src/components/Form/Checkbox.tsx +3 -3
  96. package/src/components/Form/Form.stories.tsx +7 -0
  97. package/src/components/Form/FormGroup.stories.tsx +9 -1
  98. package/src/components/Form/Input.stories.tsx +69 -16
  99. package/src/components/Form/Input.tsx +4 -2
  100. package/src/components/Form/Radio.stories.tsx +9 -1
  101. package/src/components/Form/Radio.tsx +3 -3
  102. package/src/components/Form/Select.stories.tsx +9 -1
  103. package/src/components/Form/Select.tsx +3 -3
  104. package/src/components/Form/Textarea.stories.tsx +10 -2
  105. package/src/components/Form/Textarea.tsx +4 -2
  106. package/src/components/Hero/Hero.stories.tsx +7 -0
  107. package/src/components/List/List.stories.tsx +10 -3
  108. package/src/components/List/List.tsx +3 -3
  109. package/src/components/List/ListGroup.tsx +3 -1
  110. package/src/components/Messages/Messages.stories.tsx +8 -7
  111. package/src/components/Modal/Modal.stories.tsx +17 -6
  112. package/src/components/Modal/Modal.tsx +3 -3
  113. package/src/components/Navigation/Menu/MegaMenu.tsx +9 -3
  114. package/src/components/Navigation/Menu/Menu.stories.tsx +7 -0
  115. package/src/components/Navigation/Menu/Menu.tsx +9 -3
  116. package/src/components/Navigation/Nav/Nav.stories.tsx +7 -0
  117. package/src/components/Navigation/Navbar/Navbar.stories.tsx +1 -0
  118. package/src/components/Navigation/SideMenu/SideMenu.stories.tsx +1 -1
  119. package/src/components/Pagination/Pagination.stories.tsx +188 -111
  120. package/src/components/Pagination/Pagination.tsx +88 -7
  121. package/src/components/PhotoViewer/PhotoViewer.stories.tsx +10 -5
  122. package/src/components/PhotoViewer/PhotoViewerImage.tsx +2 -2
  123. package/src/components/Popover/Popover.stories.tsx +191 -115
  124. package/src/components/Popover/Popover.tsx +4 -4
  125. package/src/components/ProductReview/ProductReview.stories.tsx +80 -58
  126. package/src/components/Progress/Progress.stories.tsx +79 -49
  127. package/src/components/Progress/Progress.tsx +6 -2
  128. package/src/components/Rating/Rating.stories.tsx +109 -84
  129. package/src/components/Rating/Rating.tsx +5 -2
  130. package/src/components/River/River.stories.tsx +194 -114
  131. package/src/components/SectionIntro/SectionIntro.stories.tsx +19 -9
  132. package/src/components/Slider/Slider.stories.tsx +7 -0
  133. package/src/components/Slider/Slider.tsx +10 -9
  134. package/src/components/Spinner/Spinner.stories.tsx +15 -11
  135. package/src/components/Spinner/Spinner.tsx +3 -3
  136. package/src/components/Steps/Steps.stories.tsx +132 -98
  137. package/src/components/Tabs/Tabs.stories.tsx +163 -112
  138. package/src/components/Tabs/Tabs.tsx +3 -3
  139. package/src/components/Testimonial/Testimonial.stories.tsx +114 -68
  140. package/src/components/Todo/Todo.stories.tsx +38 -12
  141. package/src/components/Toggle/Toggle.stories.tsx +61 -28
  142. package/src/components/Tooltip/Tooltip.stories.tsx +318 -200
  143. package/src/components/Tooltip/Tooltip.tsx +3 -3
  144. package/src/components/Upload/Upload.stories.tsx +122 -84
  145. package/src/components/VideoPlayer/VideoPlayer.stories.tsx +7 -24
  146. package/src/components/index.ts +6 -2
  147. package/src/layouts/MasonryGrid/MasonryGrid.tsx +2 -2
  148. package/src/lib/composables/useAtomixGlass.ts +2 -3
  149. package/src/lib/composables/useChartPerformance.ts +102 -78
  150. package/src/lib/composables/useChartScale.ts +10 -0
  151. package/src/lib/composables/useHero.ts +9 -2
  152. package/src/lib/composables/useHeroBackgroundSlider.ts +5 -3
  153. package/src/lib/composables/useNavbar.ts +0 -10
  154. package/src/lib/composables/useSideMenu.ts +1 -0
  155. package/src/lib/composables/useVideoPlayer.ts +3 -2
  156. package/src/lib/config/loader.ts +57 -14
  157. package/src/lib/constants/components.ts +10 -0
  158. package/src/lib/hooks/index.ts +0 -1
  159. package/src/lib/hooks/useComponentCustomization.ts +11 -15
  160. package/src/lib/hooks/usePerformanceMonitor.ts +149 -0
  161. package/src/lib/patterns/index.ts +2 -2
  162. package/src/lib/patterns/slots.tsx +2 -2
  163. package/src/lib/theme/README.md +174 -0
  164. package/src/lib/theme/adapters/index.ts +31 -0
  165. package/src/lib/theme/adapters/themeAdapter.ts +287 -0
  166. package/src/lib/theme/config/__tests__/configLoader.test.ts +207 -0
  167. package/src/lib/theme/config/configLoader.ts +254 -0
  168. package/src/lib/theme/config/loader.ts +37 -48
  169. package/src/lib/theme/config/types.ts +2 -2
  170. package/src/lib/theme/config/validator.ts +15 -91
  171. package/src/lib/theme/{constants.ts → constants/constants.ts} +0 -18
  172. package/src/lib/theme/constants/index.ts +8 -0
  173. package/src/lib/theme/core/ThemeRegistry.ts +19 -6
  174. package/src/lib/theme/core/__tests__/createTheme.test.ts +132 -0
  175. package/src/lib/theme/core/composeTheme.ts +155 -0
  176. package/src/lib/theme/core/createTheme.ts +94 -0
  177. package/src/lib/theme/{createTheme.ts → core/createThemeObject.ts} +10 -6
  178. package/src/lib/theme/core/index.ts +5 -19
  179. package/src/lib/theme/devtools/Comparator.tsx +346 -22
  180. package/src/lib/theme/devtools/IMPROVEMENTS.md +139 -38
  181. package/src/lib/theme/devtools/Inspector.tsx +335 -51
  182. package/src/lib/theme/devtools/LiveEditor.tsx +489 -112
  183. package/src/lib/theme/devtools/Preview.tsx +471 -221
  184. package/src/lib/theme/{core → devtools}/ThemeValidator.ts +6 -3
  185. package/src/lib/theme/devtools/index.ts +14 -4
  186. package/src/lib/theme/devtools/useHistory.ts +130 -0
  187. package/src/lib/theme/errors/index.ts +12 -0
  188. package/src/lib/theme/generators/cssFile.ts +79 -0
  189. package/src/lib/theme/generators/generateCSS.ts +89 -0
  190. package/src/lib/theme/{generateCSSVariables.ts → generators/generateCSSVariables.ts} +4 -14
  191. package/src/lib/theme/generators/index.ts +19 -0
  192. package/src/lib/theme/i18n/rtl.ts +7 -7
  193. package/src/lib/theme/index.ts +120 -15
  194. package/src/lib/theme/runtime/ThemeApplicator.ts +53 -95
  195. package/src/lib/theme/{ThemeContext.tsx → runtime/ThemeContext.tsx} +1 -1
  196. package/src/lib/theme/runtime/ThemeErrorBoundary.tsx +4 -4
  197. package/src/lib/theme/runtime/ThemeProvider.tsx +456 -179
  198. package/src/lib/theme/runtime/index.ts +1 -2
  199. package/src/lib/theme/runtime/useTheme.ts +1 -2
  200. package/src/lib/theme/test/testTheme.ts +385 -0
  201. package/src/lib/theme/tokens/index.ts +12 -0
  202. package/src/lib/theme/tokens/tokens.ts +721 -0
  203. package/src/lib/theme/types.ts +6 -42
  204. package/src/lib/theme/{utils.ts → utils/domUtils.ts} +2 -2
  205. package/src/lib/theme/utils/index.ts +11 -0
  206. package/src/lib/theme/utils/injectCSS.ts +90 -0
  207. package/src/lib/theme/utils/themeHelpers.ts +78 -0
  208. package/src/lib/theme/{themeUtils.ts → utils/themeUtils.ts} +1 -1
  209. package/src/lib/theme-tools.ts +8 -9
  210. package/src/lib/types/components.ts +93 -34
  211. package/src/lib/types/partProps.ts +0 -16
  212. package/src/lib/utils/componentUtils.ts +1 -1
  213. package/src/lib/utils/fontPreloader.ts +148 -0
  214. package/src/lib/utils/index.ts +11 -0
  215. package/src/lib/utils/memoryMonitor.ts +189 -0
  216. package/src/styles/01-settings/_settings.design-tokens.scss +4 -1
  217. package/src/styles/01-settings/_settings.fonts.scss +2 -5
  218. package/src/styles/02-tools/_tools.button.scss +66 -79
  219. package/src/styles/06-components/_components.atomix-glass.scss +13 -3
  220. package/src/styles/06-components/_components.navbar.scss +0 -6
  221. package/src/styles/06-components/_components.pagination.scss +88 -0
  222. package/scripts/build-themes.js +0 -208
  223. package/scripts/sync-theme-config.js +0 -309
  224. package/src/components/AtomixGlass/atomixGLass.old.tsx +0 -1263
  225. package/src/lib/theme/composeTheme.ts +0 -370
  226. package/src/lib/theme/core/ThemeCache.ts +0 -283
  227. package/src/lib/theme/core/ThemeEngine.test.ts +0 -146
  228. package/src/lib/theme/core/ThemeEngine.ts +0 -657
  229. package/src/lib/theme/createThemeFromConfig.ts +0 -132
  230. package/src/lib/theme/devtools/CLI.ts +0 -364
  231. package/src/lib/theme/runtime/ThemeManager.test.ts +0 -192
  232. package/src/lib/theme/runtime/ThemeManager.ts +0 -442
  233. package/src/styles/03-generic/_generated-root.css +0 -5
  234. package/src/themes/README.md +0 -442
  235. package/src/themes/themes.config.js +0 -35
  236. /package/src/lib/theme/{cssVariableMapper.ts → adapters/cssVariableMapper.ts} +0 -0
  237. /package/src/lib/theme/{errors.ts → errors/errors.ts} +0 -0
@@ -1,442 +0,0 @@
1
- /**
2
- * Theme Manager
3
- *
4
- * Core theme management class for the Atomix Design System.
5
- * Rewritten to use the new ThemeEngine architecture.
6
- * Handles theme loading, switching, persistence, and events.
7
- * Supports both CSS-based themes and JavaScript-based themes.
8
- */
9
-
10
- import type {
11
- ThemeManagerConfig,
12
- ThemeMetadata,
13
- ThemeChangeEvent,
14
- ThemeLoadOptions,
15
- ThemeEventListeners,
16
- ThemeChangeCallback,
17
- ThemeLoadCallback,
18
- ThemeErrorCallback,
19
- StorageAdapter,
20
- Theme,
21
- } from '../types';
22
-
23
- import {
24
- isBrowser,
25
- isServer,
26
- createLocalStorageAdapter,
27
- } from '../utils';
28
-
29
- import { ThemeEngine, type ThemeEngineConfig } from '../core/ThemeEngine';
30
- import { loadThemeConfig } from '../config/loader';
31
- import { isJSTheme } from '../themeUtils';
32
- import { RTLManager, type RTLConfig } from '../i18n/rtl';
33
- import { ThemeError, ThemeErrorCode, getLogger } from '../errors';
34
- import {
35
- DEFAULT_STORAGE_KEY,
36
- DEFAULT_DATA_ATTRIBUTE,
37
- DEFAULT_BASE_PATH,
38
- } from '../constants';
39
-
40
- /**
41
- * Default configuration values
42
- */
43
- const DEFAULT_CONFIG: Partial<ThemeManagerConfig> = {
44
- basePath: DEFAULT_BASE_PATH,
45
- cdnPath: null,
46
- lazy: true,
47
- storageKey: DEFAULT_STORAGE_KEY,
48
- dataAttribute: DEFAULT_DATA_ATTRIBUTE,
49
- enablePersistence: true,
50
- useMinified: false,
51
- preload: [],
52
- };
53
-
54
- /**
55
- * ThemeManager class
56
- *
57
- * Manages theme loading, switching, and persistence for Atomix Design System.
58
- * Uses the new ThemeEngine architecture for unified CSS/JS theme support.
59
- *
60
- * @example
61
- * ```typescript
62
- * const themeManager = new ThemeManager({
63
- * // No defaultTheme - uses built-in styles
64
- * });
65
- *
66
- * await themeManager.setTheme('my-custom-theme');
67
- * ```
68
- */
69
- export class ThemeManager {
70
- private engine: ThemeEngine;
71
- private config: Required<Omit<ThemeManagerConfig, 'onThemeChange' | 'onError' | 'cdnPath' | 'defaultTheme'>> & {
72
- defaultTheme?: string | Theme;
73
- cdnPath: string | null;
74
- onThemeChange?: (theme: string | Theme) => void;
75
- onError?: (error: Error, themeName: string) => void;
76
- };
77
-
78
- private currentTheme: string | null = null;
79
- private activeTheme: Theme | null = null;
80
- private eventListeners: ThemeEventListeners = {
81
- themeChange: [],
82
- themeLoad: [],
83
- themeError: [],
84
- };
85
- private storageAdapter: StorageAdapter;
86
- private initialized: boolean = false;
87
- private rtlManager?: RTLManager;
88
- private logger = getLogger();
89
-
90
- /**
91
- * Create a new ThemeManager instance
92
- *
93
- * @param config - Theme manager configuration
94
- */
95
- constructor(config: ThemeManagerConfig) {
96
- // Merge with defaults
97
- this.config = {
98
- ...DEFAULT_CONFIG,
99
- ...config,
100
- themes: config.themes || {},
101
- defaultTheme: config.defaultTheme,
102
- } as Required<Omit<ThemeManagerConfig, 'onThemeChange' | 'onError' | 'cdnPath' | 'defaultTheme'>> & {
103
- defaultTheme?: string | Theme;
104
- cdnPath: string | null;
105
- onThemeChange?: (theme: string | Theme) => void;
106
- onError?: (error: Error, themeName: string) => void;
107
- };
108
-
109
- // Initialize storage adapter
110
- this.storageAdapter = createLocalStorageAdapter();
111
-
112
- // Create theme engine
113
- const engineConfig: ThemeEngineConfig = {
114
- basePath: this.config.basePath,
115
- cdnPath: this.config.cdnPath,
116
- useMinified: this.config.useMinified,
117
- dataAttribute: this.config.dataAttribute,
118
- enableCache: true,
119
- };
120
-
121
- this.engine = new ThemeEngine(engineConfig);
122
-
123
- // Initialize RTL manager if configured
124
- if (config.rtl) {
125
- this.rtlManager = new RTLManager(config.rtl);
126
- }
127
-
128
- // Set up engine event listeners
129
- this.engine.on('change', (event) => {
130
- this.currentTheme = event.currentTheme;
131
- this.activeTheme = event.themeObject || null;
132
- this.emitThemeChange(event);
133
- });
134
-
135
- this.engine.on('load', (themeId) => {
136
- this.emitThemeLoad(themeId);
137
- });
138
-
139
- this.engine.on('error', (error, themeId) => {
140
- this.emitThemeError(error, themeId);
141
- });
142
-
143
- // Initialize theme manager
144
- this.initialize();
145
- }
146
-
147
- /**
148
- * Initialize the theme manager
149
- */
150
- private initialize(): void {
151
- if (this.initialized || isServer()) {
152
- return;
153
- }
154
-
155
- // Initialize engine
156
- this.engine.initialize().then(() => {
157
- // Register themes from config if provided
158
- // This allows themes to be passed via ThemeManager config
159
- // even if theme.config.ts fails to load
160
- if (this.config.themes && Object.keys(this.config.themes).length > 0) {
161
- const registry = this.engine.getRegistry();
162
- for (const [themeId, metadata] of Object.entries(this.config.themes)) {
163
- // Only register if not already registered (from theme.config.ts)
164
- if (!registry.has(themeId)) {
165
- // Convert ThemeMetadata to CSSThemeDefinition
166
- registry.register(themeId, {
167
- type: 'css',
168
- name: metadata.name,
169
- class: metadata.class || themeId,
170
- description: metadata.description,
171
- author: metadata.author,
172
- version: metadata.version,
173
- tags: metadata.tags,
174
- supportsDarkMode: metadata.supportsDarkMode,
175
- status: metadata.status,
176
- a11y: metadata.a11y,
177
- color: metadata.color,
178
- features: metadata.features,
179
- dependencies: metadata.dependencies,
180
- });
181
- }
182
- }
183
- }
184
-
185
- // Load default theme only if specified
186
- const defaultTheme = this.getDefaultTheme();
187
- if (defaultTheme) {
188
- // Check if theme exists in registry before attempting to load
189
- const themeId = typeof defaultTheme === 'string' ? defaultTheme : (defaultTheme.name || '');
190
- if (this.engine.getRegistry().has(themeId)) {
191
- this.setTheme(defaultTheme, { removePrevious: false, fallbackOnError: true }).catch((error) => {
192
- // Only log error once, don't spam console
193
- if (error instanceof Error && !error.message.includes('previously failed')) {
194
- this.logger.warn(`Failed to load default theme "${themeId}"`, {
195
- themeId,
196
- error: error.message,
197
- });
198
- }
199
- });
200
- } else {
201
- // Theme not in registry, log warning but don't try to load
202
- this.logger.warn(`Default theme "${themeId}" not found in registry. Using built-in styles.`, {
203
- themeId,
204
- });
205
- }
206
- }
207
- // If no default theme, use built-in styles (no theme CSS loaded)
208
- });
209
-
210
- this.initialized = true;
211
- }
212
-
213
- /**
214
- * Get default theme
215
- */
216
- private getDefaultTheme(): string | Theme | null {
217
- // Check storage first
218
- if (this.config.enablePersistence && this.storageAdapter.isAvailable()) {
219
- const stored = this.storageAdapter.getItem(this.config.storageKey);
220
- if (stored) {
221
- try {
222
- // Try to parse as theme name
223
- if (this.engine.getRegistry().has(stored)) {
224
- return stored;
225
- }
226
- } catch {
227
- // Ignore parse errors
228
- }
229
- }
230
- }
231
-
232
- // Use config default
233
- return this.config.defaultTheme || null;
234
- }
235
-
236
- /**
237
- * Set theme
238
- */
239
- async setTheme(theme: string | Theme, options?: ThemeLoadOptions): Promise<void> {
240
- await this.engine.setTheme(theme, options);
241
-
242
- // Persist to storage
243
- if (this.config.enablePersistence && this.storageAdapter.isAvailable()) {
244
- const themeId = typeof theme === 'string' ? theme : (theme.name || 'js-theme');
245
- this.storageAdapter.setItem(this.config.storageKey, themeId);
246
- }
247
-
248
- // Call config callback
249
- if (this.config.onThemeChange) {
250
- this.config.onThemeChange(theme);
251
- }
252
- }
253
-
254
- /**
255
- * Get current theme
256
- */
257
- getTheme(): string {
258
- return this.currentTheme || (typeof this.config.defaultTheme === 'string' ? this.config.defaultTheme : '');
259
- }
260
-
261
- /**
262
- * Get active theme object (for JS themes)
263
- */
264
- getActiveTheme(): Theme | null {
265
- return this.activeTheme || this.engine.getActiveTheme();
266
- }
267
-
268
- /**
269
- * Get available themes
270
- */
271
- getAvailableThemes(): ThemeMetadata[] {
272
- return this.engine.getRegistry().getAllMetadata();
273
- }
274
-
275
- /**
276
- * Check if theme is loaded
277
- */
278
- isThemeLoaded(themeName: string): boolean {
279
- return this.engine.isThemeLoaded(themeName);
280
- }
281
-
282
- /**
283
- * Preload theme
284
- */
285
- async preloadTheme(themeName: string): Promise<void> {
286
- await this.engine.preloadTheme(themeName);
287
- }
288
-
289
- /**
290
- * Add event listener
291
- */
292
- on(event: 'themeChange', callback: ThemeChangeCallback): void;
293
- on(event: 'themeLoad', callback: ThemeLoadCallback): void;
294
- on(event: 'themeError', callback: ThemeErrorCallback): void;
295
- on(event: ThemeManagerEvent, callback: ThemeChangeCallback | ThemeLoadCallback | ThemeErrorCallback): void {
296
- if (event === 'themeChange') {
297
- this.eventListeners.themeChange.push(callback as ThemeChangeCallback);
298
- } else if (event === 'themeLoad') {
299
- this.eventListeners.themeLoad.push(callback as ThemeLoadCallback);
300
- } else if (event === 'themeError') {
301
- this.eventListeners.themeError.push(callback as ThemeErrorCallback);
302
- }
303
- }
304
-
305
- /**
306
- * Remove event listener
307
- */
308
- off(event: 'themeChange', callback: ThemeChangeCallback): void;
309
- off(event: 'themeLoad', callback: ThemeLoadCallback): void;
310
- off(event: 'themeError', callback: ThemeErrorCallback): void;
311
- off(event: ThemeManagerEvent, callback: ThemeChangeCallback | ThemeLoadCallback | ThemeErrorCallback): void {
312
- if (event === 'themeChange') {
313
- this.eventListeners.themeChange = this.eventListeners.themeChange.filter(cb => cb !== callback);
314
- } else if (event === 'themeLoad') {
315
- this.eventListeners.themeLoad = this.eventListeners.themeLoad.filter(cb => cb !== callback);
316
- } else if (event === 'themeError') {
317
- this.eventListeners.themeError = this.eventListeners.themeError.filter(cb => cb !== callback);
318
- }
319
- }
320
-
321
- /**
322
- * Emit theme change event
323
- */
324
- private emitThemeChange(event: ThemeChangeEvent): void {
325
- for (const callback of this.eventListeners.themeChange) {
326
- try {
327
- callback(event);
328
- } catch (error) {
329
- this.logger.error(
330
- 'Error in theme change callback',
331
- error instanceof Error ? error : new Error(String(error)),
332
- { event }
333
- );
334
- }
335
- }
336
- }
337
-
338
- /**
339
- * Emit theme load event
340
- */
341
- private emitThemeLoad(themeName: string): void {
342
- for (const callback of this.eventListeners.themeLoad) {
343
- try {
344
- callback(themeName);
345
- } catch (error) {
346
- this.logger.error(
347
- 'Error in theme load callback',
348
- error instanceof Error ? error : new Error(String(error)),
349
- { themeName }
350
- );
351
- }
352
- }
353
- }
354
-
355
- /**
356
- * Emit theme error event
357
- */
358
- private emitThemeError(error: Error, themeName: string): void {
359
- const themeError = error instanceof ThemeError
360
- ? error
361
- : new ThemeError(
362
- error.message,
363
- ThemeErrorCode.THEME_LOAD_FAILED,
364
- { themeName, originalError: error.message }
365
- );
366
-
367
- if (this.config.onError) {
368
- try {
369
- this.config.onError(error, themeName);
370
- } catch (err) {
371
- this.logger.error(
372
- 'Error in onError callback',
373
- err instanceof Error ? err : new Error(String(err)),
374
- { themeName }
375
- );
376
- }
377
- }
378
-
379
- for (const callback of this.eventListeners.themeError) {
380
- try {
381
- callback(error, themeName);
382
- } catch (err) {
383
- this.logger.error(
384
- 'Error in theme error callback',
385
- err instanceof Error ? err : new Error(String(err)),
386
- { themeName }
387
- );
388
- }
389
- }
390
- }
391
-
392
- /**
393
- * Get engine instance (for advanced usage)
394
- */
395
- getEngine(): ThemeEngine {
396
- return this.engine;
397
- }
398
-
399
- /**
400
- * Get RTL manager
401
- */
402
- getRTLManager(): RTLManager | undefined {
403
- return this.rtlManager;
404
- }
405
-
406
- /**
407
- * Set RTL direction
408
- */
409
- setDirection(direction: 'ltr' | 'rtl'): void {
410
- this.rtlManager?.setDirection(direction);
411
- }
412
-
413
- /**
414
- * Get current direction
415
- */
416
- getDirection(): 'ltr' | 'rtl' {
417
- return this.rtlManager?.getDirection() || 'ltr';
418
- }
419
-
420
- /**
421
- * Destroy theme manager
422
- */
423
- destroy(): void {
424
- // Remove all listeners
425
- this.eventListeners = {
426
- themeChange: [],
427
- themeLoad: [],
428
- themeError: [],
429
- };
430
-
431
- // Destroy RTL manager
432
- this.rtlManager?.destroy();
433
-
434
- // Clear engine listeners
435
- this.initialized = false;
436
- }
437
- }
438
-
439
- /**
440
- * Theme manager event type
441
- */
442
- type ThemeManagerEvent = 'themeChange' | 'themeLoad' | 'themeError';
@@ -1,5 +0,0 @@
1
- /* AUTO-GENERATED - DO NOT EDIT MANUALLY */
2
-
3
- :root {
4
- --atomix-colors-primary-main: #3b82f6;
5
- }