@shohojdhara/atomix 0.3.5 → 0.3.7

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 (182) hide show
  1. package/README.md +101 -199
  2. package/atomix.config.ts +241 -0
  3. package/dist/atomix.css +260 -179
  4. package/dist/atomix.css.map +1 -1
  5. package/dist/atomix.min.css +250 -179
  6. package/dist/atomix.min.css.map +1 -1
  7. package/dist/charts.js +69 -166
  8. package/dist/charts.js.map +1 -1
  9. package/dist/core.js +184 -263
  10. package/dist/core.js.map +1 -1
  11. package/dist/forms.js +55 -131
  12. package/dist/forms.js.map +1 -1
  13. package/dist/heavy.js +184 -263
  14. package/dist/heavy.js.map +1 -1
  15. package/dist/index.d.ts +1831 -1657
  16. package/dist/index.esm.js +4497 -4318
  17. package/dist/index.esm.js.map +1 -1
  18. package/dist/index.js +4510 -4328
  19. package/dist/index.js.map +1 -1
  20. package/dist/index.min.js +1 -1
  21. package/dist/index.min.js.map +1 -1
  22. package/dist/theme.d.ts +1431 -1472
  23. package/dist/theme.js +4175 -4138
  24. package/dist/theme.js.map +1 -1
  25. package/package.json +6 -20
  26. package/src/components/Accordion/Accordion.stories.tsx +50 -17
  27. package/src/components/AtomixGlass/AtomixGlass.tsx +128 -322
  28. package/src/components/AtomixGlass/AtomixGlassContainer.tsx +12 -5
  29. package/src/components/AtomixGlass/stories/AtomixGlass.stories.tsx +1 -32
  30. package/src/components/AtomixGlass/stories/Examples.stories.tsx +2 -2
  31. package/src/components/AtomixGlass/stories/shared-components.tsx +0 -31
  32. package/src/components/Avatar/Avatar.stories.tsx +7 -0
  33. package/src/components/Badge/Badge.stories.tsx +91 -13
  34. package/src/components/Block/Block.stories.tsx +7 -23
  35. package/src/components/Breadcrumb/Breadcrumb.stories.tsx +7 -0
  36. package/src/components/Button/Button.stories.tsx +141 -22
  37. package/src/components/Button/Button.tsx +85 -167
  38. package/src/components/Button/ButtonGroup.stories.tsx +315 -0
  39. package/src/components/Button/ButtonGroup.tsx +67 -0
  40. package/src/components/Button/index.ts +2 -0
  41. package/src/components/Callout/Callout.stories.tsx +8 -6
  42. package/src/components/Card/Card.stories.tsx +82 -28
  43. package/src/components/Chart/AnimatedChart.tsx +0 -1
  44. package/src/components/Chart/AreaChart.tsx +0 -1
  45. package/src/components/Chart/BarChart.tsx +0 -1
  46. package/src/components/Chart/BubbleChart.tsx +0 -1
  47. package/src/components/Chart/CandlestickChart.tsx +0 -1
  48. package/src/components/Chart/Chart.stories.tsx +5 -7
  49. package/src/components/Chart/Chart.tsx +0 -16
  50. package/src/components/Chart/ChartRenderer.tsx +1 -1
  51. package/src/components/Chart/DonutChart.tsx +0 -1
  52. package/src/components/Chart/FunnelChart.tsx +0 -1
  53. package/src/components/Chart/GaugeChart.tsx +0 -1
  54. package/src/components/Chart/HeatmapChart.tsx +0 -1
  55. package/src/components/Chart/LineChart.tsx +0 -1
  56. package/src/components/Chart/MultiAxisChart.tsx +0 -1
  57. package/src/components/Chart/PieChart.tsx +0 -1
  58. package/src/components/Chart/RadarChart.tsx +0 -1
  59. package/src/components/Chart/ScatterChart.tsx +0 -1
  60. package/src/components/Chart/WaterfallChart.tsx +0 -1
  61. package/src/components/ColorModeToggle/ColorModeToggle.stories.tsx +7 -0
  62. package/src/components/DataTable/DataTable.stories.tsx +23 -16
  63. package/src/components/DatePicker/DatePicker.stories.tsx +27 -19
  64. package/src/components/Dropdown/Dropdown.stories.tsx +11 -19
  65. package/src/components/EdgePanel/EdgePanel.stories.tsx +1 -0
  66. package/src/components/Footer/Footer.stories.tsx +8 -6
  67. package/src/components/Footer/FooterLink.tsx +9 -2
  68. package/src/components/Form/Checkbox.stories.tsx +7 -0
  69. package/src/components/Form/Form.stories.tsx +7 -0
  70. package/src/components/Form/FormGroup.stories.tsx +9 -1
  71. package/src/components/Form/Input.stories.tsx +69 -16
  72. package/src/components/Form/Radio.stories.tsx +9 -1
  73. package/src/components/Form/Select.stories.tsx +9 -1
  74. package/src/components/Form/Textarea.stories.tsx +10 -2
  75. package/src/components/Hero/Hero.stories.tsx +7 -0
  76. package/src/components/List/List.stories.tsx +7 -0
  77. package/src/components/Messages/Messages.stories.tsx +8 -7
  78. package/src/components/Modal/Modal.stories.tsx +17 -6
  79. package/src/components/Navigation/Menu/Menu.stories.tsx +7 -0
  80. package/src/components/Navigation/Nav/Nav.stories.tsx +7 -0
  81. package/src/components/Navigation/Navbar/Navbar.stories.tsx +1 -0
  82. package/src/components/Navigation/SideMenu/SideMenu.stories.tsx +1 -1
  83. package/src/components/Pagination/Pagination.stories.tsx +188 -111
  84. package/src/components/Pagination/Pagination.tsx +83 -3
  85. package/src/components/PhotoViewer/PhotoViewer.stories.tsx +10 -5
  86. package/src/components/Popover/Popover.stories.tsx +191 -115
  87. package/src/components/ProductReview/ProductReview.stories.tsx +80 -58
  88. package/src/components/Progress/Progress.stories.tsx +79 -49
  89. package/src/components/Rating/Rating.stories.tsx +109 -84
  90. package/src/components/River/River.stories.tsx +194 -114
  91. package/src/components/SectionIntro/SectionIntro.stories.tsx +19 -9
  92. package/src/components/Slider/Slider.stories.tsx +7 -0
  93. package/src/components/Spinner/Spinner.stories.tsx +15 -11
  94. package/src/components/Steps/Steps.stories.tsx +132 -98
  95. package/src/components/Tabs/Tabs.stories.tsx +163 -112
  96. package/src/components/Testimonial/Testimonial.stories.tsx +114 -68
  97. package/src/components/Todo/Todo.stories.tsx +38 -12
  98. package/src/components/Toggle/Toggle.stories.tsx +61 -28
  99. package/src/components/Tooltip/Tooltip.stories.tsx +318 -200
  100. package/src/components/Upload/Upload.stories.tsx +122 -84
  101. package/src/components/VideoPlayer/VideoPlayer.stories.tsx +7 -24
  102. package/src/components/index.ts +1 -0
  103. package/src/lib/composables/useAtomixGlass.ts +9 -10
  104. package/src/lib/composables/useNavbar.ts +0 -10
  105. package/src/lib/config/loader.ts +4 -4
  106. package/src/lib/constants/components.ts +17 -0
  107. package/src/lib/hooks/useComponentCustomization.ts +1 -1
  108. package/src/lib/hooks/usePerformanceMonitor.ts +1 -1
  109. package/src/lib/hooks/useThemeTokens.ts +105 -0
  110. package/src/lib/theme/README.md +174 -0
  111. package/src/lib/theme/adapters/index.ts +31 -0
  112. package/src/lib/theme/adapters/themeAdapter.ts +287 -0
  113. package/src/lib/theme/config/__tests__/configLoader.test.ts +207 -0
  114. package/src/lib/theme/config/configLoader.ts +95 -0
  115. package/src/lib/theme/config/loader.ts +37 -54
  116. package/src/lib/theme/config/types.ts +2 -2
  117. package/src/lib/theme/config/validator.ts +15 -91
  118. package/src/lib/theme/{constants.ts → constants/constants.ts} +1 -19
  119. package/src/lib/theme/constants/index.ts +8 -0
  120. package/src/lib/theme/core/ThemeRegistry.ts +75 -266
  121. package/src/lib/theme/core/__tests__/createTheme.test.ts +132 -0
  122. package/src/lib/theme/core/composeTheme.ts +105 -0
  123. package/src/lib/theme/core/createTheme.ts +108 -0
  124. package/src/lib/theme/{createTheme.ts → core/createThemeObject.ts} +12 -8
  125. package/src/lib/theme/core/index.ts +19 -19
  126. package/src/lib/theme/devtools/Comparator.tsx +346 -22
  127. package/src/lib/theme/devtools/IMPROVEMENTS.md +139 -38
  128. package/src/lib/theme/devtools/Inspector.tsx +335 -51
  129. package/src/lib/theme/devtools/LiveEditor.tsx +478 -107
  130. package/src/lib/theme/devtools/Preview.tsx +471 -221
  131. package/src/lib/theme/{core → devtools}/ThemeValidator.ts +1 -1
  132. package/src/lib/theme/devtools/index.ts +14 -4
  133. package/src/lib/theme/devtools/useHistory.ts +130 -0
  134. package/src/lib/theme/{errors.ts → errors/errors.ts} +1 -1
  135. package/src/lib/theme/errors/index.ts +12 -0
  136. package/src/lib/theme/generators/cssFile.ts +79 -0
  137. package/src/lib/theme/generators/generateCSS.ts +89 -0
  138. package/src/lib/theme/generators/generateCSSNested.ts +130 -0
  139. package/src/lib/theme/{generateCSSVariables.ts → generators/generateCSSVariables.ts} +3 -13
  140. package/src/lib/theme/generators/index.ts +25 -0
  141. package/src/lib/theme/i18n/rtl.ts +5 -6
  142. package/src/lib/theme/index.ts +149 -19
  143. package/src/lib/theme/runtime/ThemeApplicator.ts +53 -112
  144. package/src/lib/theme/{ThemeContext.tsx → runtime/ThemeContext.tsx} +1 -1
  145. package/src/lib/theme/runtime/ThemeErrorBoundary.tsx +5 -5
  146. package/src/lib/theme/runtime/ThemeProvider.tsx +266 -282
  147. package/src/lib/theme/runtime/index.ts +2 -2
  148. package/src/lib/theme/runtime/useTheme.ts +1 -2
  149. package/src/lib/theme/runtime/useThemeTokens.ts +131 -0
  150. package/src/lib/theme/test/testTheme.ts +385 -0
  151. package/src/lib/theme/tokens/index.ts +12 -0
  152. package/src/lib/theme/tokens/tokens.ts +721 -0
  153. package/src/lib/theme/types.ts +6 -42
  154. package/src/lib/theme/utils/componentTheming.ts +132 -0
  155. package/src/lib/theme/{utils.ts → utils/domUtils.ts} +2 -2
  156. package/src/lib/theme/utils/index.ts +11 -0
  157. package/src/lib/theme/utils/injectCSS.ts +90 -0
  158. package/src/lib/theme/utils/naming.ts +100 -0
  159. package/src/lib/theme/utils/themeHelpers.ts +78 -0
  160. package/src/lib/theme/{themeUtils.ts → utils/themeUtils.ts} +7 -7
  161. package/src/lib/theme-tools.ts +7 -8
  162. package/src/lib/types/components.ts +40 -130
  163. package/src/lib/utils/componentUtils.ts +2 -2
  164. package/src/lib/utils/memoryMonitor.ts +3 -3
  165. package/src/lib/utils/themeNaming.ts +135 -0
  166. package/src/styles/01-settings/_settings.design-tokens.scss +4 -1
  167. package/src/styles/02-tools/_tools.button.scss +66 -79
  168. package/src/styles/06-components/_components.atomix-glass.scss +13 -3
  169. package/src/styles/06-components/_components.pagination.scss +88 -0
  170. package/scripts/sync-theme-config.js +0 -309
  171. package/src/lib/theme/composeTheme.ts +0 -370
  172. package/src/lib/theme/core/ThemeCache.ts +0 -283
  173. package/src/lib/theme/core/ThemeEngine.test.ts +0 -146
  174. package/src/lib/theme/core/ThemeEngine.ts +0 -665
  175. package/src/lib/theme/createThemeFromConfig.ts +0 -132
  176. package/src/lib/theme/devtools/CLI.ts +0 -364
  177. package/src/lib/theme/runtime/ThemeManager.test.ts +0 -192
  178. package/src/lib/theme/runtime/ThemeManager.ts +0 -446
  179. package/src/styles/03-generic/_generated-root.css +0 -26
  180. package/src/themes/README.md +0 -442
  181. package/src/themes/themes.config.js +0 -68
  182. /package/src/lib/theme/{cssVariableMapper.ts → adapters/cssVariableMapper.ts} +0 -0
@@ -1,33 +1,164 @@
1
1
  /**
2
2
  * Theme System Exports
3
3
  *
4
- * Central export point for all theme-related functionality
4
+ * Unified theme system - handles both DesignTokens and Theme objects.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { createTheme, injectTheme } from '@shohojdhara/atomix/theme';
9
+ *
10
+ * // Using DesignTokens (recommended - flat structure)
11
+ * const css = createTheme({ 'primary': '#7AFFD7', 'spacing-4': '1rem' });
12
+ * injectTheme(css);
13
+ *
14
+ * // Or use with ThemeProvider
15
+ * import { ThemeProvider } from '@shohojdhara/atomix/theme';
16
+ * const tokens = { 'primary': '#7c3aed' };
17
+ * <ThemeProvider defaultTheme={tokens}>...</ThemeProvider>
18
+ * ```
19
+ */
20
+
21
+ // ============================================================================
22
+ // Core Theme Functions
23
+ // ============================================================================
24
+
25
+ // Unified createTheme (handles both DesignTokens and Theme objects)
26
+ export { createTheme } from './core';
27
+
28
+ // Theme object creation
29
+ export { createThemeObject } from './core';
30
+
31
+ // Theme composition
32
+ export { deepMerge, mergeTheme, extendTheme } from './core';
33
+
34
+ // Simplified Theme Registry
35
+ export {
36
+ createThemeRegistry,
37
+ registerTheme,
38
+ unregisterTheme,
39
+ hasTheme,
40
+ getTheme,
41
+ getAllThemes,
42
+ getThemeIds,
43
+ clearThemes,
44
+ getThemeCount,
45
+ } from './core';
46
+
47
+ // ============================================================================
48
+ // Theme Injection and Management
49
+ // ============================================================================
50
+
51
+ import { injectCSS, removeCSS, isCSSInjected } from './utils/injectCSS';
52
+ import { saveCSSFile, saveCSSFileSync } from './generators/cssFile';
53
+
54
+ /**
55
+ * Inject theme CSS into DOM
56
+ */
57
+ export function injectTheme(css: string, id: string = 'atomix-theme'): void {
58
+ injectCSS(css, id);
59
+ }
60
+
61
+ /**
62
+ * Remove theme from DOM
63
+ */
64
+ export function removeTheme(id: string = 'atomix-theme'): void {
65
+ removeCSS(id);
66
+ }
67
+
68
+ /**
69
+ * Save theme to CSS file
5
70
  */
71
+ export async function saveTheme(css: string, filePath: string): Promise<void> {
72
+ await saveCSSFile(css, filePath);
73
+ }
74
+
75
+ // ============================================================================
76
+ // Token Utilities
77
+ // ============================================================================
78
+
79
+ export { createTokens, defaultTokens, type DesignTokens } from './tokens';
80
+
81
+ // ============================================================================
82
+ // CSS Generation
83
+ // ============================================================================
84
+
85
+ export {
86
+ generateCSSVariables,
87
+ generateCSSVariablesForSelector,
88
+ type GenerateCSSVariablesOptions,
89
+ } from './generators';
6
90
 
7
- // Core theme system
91
+ // ============================================================================
92
+ // Naming and Component Theming Utilities
93
+ // ============================================================================
94
+
95
+ export {
96
+ generateClassName,
97
+ generateCSSVariableName,
98
+ normalizeThemeTokens,
99
+ camelToKebab,
100
+ themePropertyToCSSVar,
101
+ type NamingOptions,
102
+ } from './utils/naming';
103
+
104
+ export {
105
+ getComponentThemeValue,
106
+ generateComponentCSSVars,
107
+ applyComponentTheme,
108
+ useComponentTheme,
109
+ type ComponentThemeOptions,
110
+ } from './utils/componentTheming';
111
+
112
+ // ============================================================================
113
+ // Injection Utilities
114
+ // ============================================================================
115
+
116
+ export { injectCSS, removeCSS, isCSSInjected } from './utils/injectCSS';
117
+
118
+
119
+ // ============================================================================
120
+ // Config Loader
121
+ // ============================================================================
122
+
123
+ export {
124
+ loadThemeFromConfig,
125
+ loadThemeFromConfigSync,
126
+ } from './config/configLoader';
127
+
128
+ // ============================================================================
129
+ // React Integration
130
+ // ============================================================================
131
+
132
+ // Core React components and hooks
8
133
  export { ThemeProvider } from './runtime/ThemeProvider';
9
134
  export { useTheme } from './runtime/useTheme';
10
- export { ThemeContext } from './ThemeContext';
11
- export { ThemeManager } from './runtime/ThemeManager';
135
+ export { useThemeTokens } from './runtime/useThemeTokens';
136
+ export { ThemeContext } from './runtime/ThemeContext';
12
137
  export { ThemeErrorBoundary } from './runtime/ThemeErrorBoundary';
13
138
 
14
- // Theme creation
15
- export { createTheme } from './createTheme';
16
- export { createThemeFromConfig } from './createThemeFromConfig';
17
-
18
- // Theme utilities
19
- export { quickTheme, createDarkVariant, validateTheme, themeToCSS, exportTheme, importTheme } from '../theme-tools';
139
+ // Theme application
140
+ export { ThemeApplicator, getThemeApplicator, applyTheme } from './runtime/ThemeApplicator';
20
141
 
21
142
  // DevTools (for development and debugging)
22
143
  export * from './devtools';
23
144
 
24
- // Theme application
25
- export { ThemeApplicator, getThemeApplicator, applyTheme, removeTheme } from './runtime/ThemeApplicator';
145
+ // Theme adapter (converts between Theme and DesignTokens)
146
+ export {
147
+ themeToDesignTokens,
148
+ designTokensToCSSVars,
149
+ createDesignTokensFromTheme,
150
+ designTokensToTheme,
151
+ } from './adapters';
152
+
153
+ // Theme helpers (utilities for working with themes and DesignTokens)
154
+ export {
155
+ getDesignTokensFromTheme,
156
+ isDesignTokens,
157
+ isThemeObject,
158
+ } from './utils/themeHelpers';
26
159
 
27
160
  // CSS variable utilities
28
161
  export {
29
- generateCSSVariableName,
30
- generateComponentCSSVars,
31
162
  mapSCSSTokensToCSSVars,
32
163
  applyCSSVariables,
33
164
  removeCSSVariables,
@@ -36,16 +167,15 @@ export {
36
167
  mergeCSSVars,
37
168
  isValidCSSVariableName,
38
169
  extractComponentName,
39
- } from './cssVariableMapper';
170
+ } from './adapters/cssVariableMapper';
40
171
 
41
172
  // RTL Support
42
173
  export { RTLManager } from './i18n/rtl';
43
174
 
175
+
44
176
  // Types
45
177
  export type {
46
178
  Theme,
47
- ThemeMetadata,
48
- ThemeManagerConfig,
49
179
  ThemeChangeEvent,
50
180
  ThemeLoadOptions,
51
181
  ThemeValidationResult,
@@ -61,6 +191,6 @@ export type { ThemeErrorBoundaryProps } from './runtime/ThemeErrorBoundary';
61
191
  export type {
62
192
  CSSVariableConfig,
63
193
  CSSVariableNamingOptions,
64
- } from './cssVariableMapper';
194
+ } from './adapters/cssVariableMapper';
65
195
 
66
- export type { RTLConfig } from './i18n/rtl';
196
+ export type { RTLConfig } from './i18n/rtl';
@@ -3,17 +3,23 @@
3
3
  *
4
4
  * Applies theme configurations to the DOM, including CSS variables,
5
5
  * component overrides, typography, spacing, and color palettes.
6
+ *
7
+ * Uses the unified theme system for CSS generation and injection.
6
8
  */
7
9
 
8
- import { applyCSSVariables, removeCSSVariables } from '../cssVariableMapper';
9
10
  import type { Theme, ThemeComponentOverrides, ComponentThemeOverride } from '../types';
11
+ import type { DesignTokens } from '../tokens/tokens';
12
+ import { createTheme } from '../core/createTheme';
13
+ import { injectCSS, removeCSS } from '../utils/injectCSS';
10
14
 
11
15
  /**
12
16
  * Theme applicator class for runtime theme application
17
+ *
18
+ * Uses the unified theme system for efficient CSS variable generation and injection.
13
19
  */
14
20
  export class ThemeApplicator {
15
- private appliedVars: Set<string> = new Set();
16
21
  private root: HTMLElement;
22
+ private styleId: string = 'atomix-theme-applicator';
17
23
 
18
24
  constructor(root: HTMLElement = document.documentElement) {
19
25
  this.root = root;
@@ -21,129 +27,71 @@ export class ThemeApplicator {
21
27
 
22
28
  /**
23
29
  * Apply a complete theme configuration
30
+ *
31
+ * Uses the unified theme system to convert Theme to DesignTokens and inject CSS.
32
+ * Automatically respects atomix.config.ts when using DesignTokens.
24
33
  */
25
- applyTheme(theme: Theme): void {
34
+ applyTheme(theme: Theme | DesignTokens): void {
26
35
  // Clear previously applied variables
27
36
  this.clearAppliedVars();
28
37
 
29
- // Apply global CSS variables
30
- if (theme.cssVars) {
31
- this.applyGlobalCSSVars(theme.cssVars);
32
- }
33
-
34
- // Apply typography system
35
- if (theme.typography) {
36
- this.applyTypography(theme.typography);
37
- }
38
-
39
- // Apply spacing system
40
- if (theme.spacing) {
41
- this.applySpacing(theme.spacing);
42
- }
43
-
44
- // Apply color palette
45
- if (theme.palette) {
46
- this.applyPalette(theme.palette);
38
+ // Check if it's DesignTokens
39
+ if (this.isDesignTokens(theme)) {
40
+ // Direct DesignTokens - use unified theme system (with config support)
41
+ this.applyDesignTokens(theme);
42
+ } else {
43
+ // Theme object - use createTheme which handles Theme objects
44
+ // createTheme automatically converts Theme to DesignTokens internally
45
+ const css = createTheme(theme, {
46
+ selector: ':root',
47
+ prefix: 'atomix',
48
+ });
49
+ injectCSS(css, this.styleId);
47
50
  }
48
51
 
49
- // Apply component overrides
50
- if ((theme as any).components) {
52
+ // Apply component overrides (only for Theme objects)
53
+ if (!this.isDesignTokens(theme) && (theme as any).components) {
51
54
  this.applyComponentOverrides((theme as any).components);
52
55
  }
53
56
  }
54
57
 
55
58
  /**
56
- * Apply global CSS variables
59
+ * Apply DesignTokens using unified theme system
60
+ *
61
+ * Uses createTheme() which automatically loads from atomix.config.ts
62
+ * if no tokens are provided, ensuring config is always respected.
57
63
  */
58
- private applyGlobalCSSVars(vars: Record<string, string | number>): void {
59
- Object.entries(vars).forEach(([key, value]) => {
60
- this.root.style.setProperty(key, String(value));
61
- this.appliedVars.add(key);
64
+ private applyDesignTokens(tokens: Partial<DesignTokens>): void {
65
+ // Use createTheme() which handles config loading automatically
66
+ // If tokens is empty, it will load from config
67
+ const css = createTheme(tokens, {
68
+ selector: ':root',
69
+ prefix: 'atomix', // Can be overridden by config
62
70
  });
63
- }
64
-
65
- /**
66
- * Apply typography system
67
- */
68
- private applyTypography(typography: Theme['typography']): void {
69
- if (!typography) return;
70
-
71
- const vars: Record<string, string | number> = {};
72
-
73
- if (typography.fontFamily) {
74
- vars['--atomix-font-family'] = typography.fontFamily;
75
- }
76
-
77
- if (typography.fontSize) {
78
- Object.entries(typography.fontSize).forEach(([key, value]) => {
79
- if (typeof value === 'string' || typeof value === 'number') {
80
- vars[`--atomix-font-size-${key}`] = value;
81
- }
82
- });
83
- }
84
-
85
- if (typography.fontWeight) {
86
- Object.entries(typography.fontWeight).forEach(([key, value]) => {
87
- if (typeof value === 'string' || typeof value === 'number') {
88
- vars[`--atomix-font-weight-${key}`] = value;
89
- }
90
- });
91
- }
92
71
 
93
- if (typography.lineHeight) {
94
- Object.entries(typography.lineHeight).forEach(([key, value]) => {
95
- if (typeof value === 'string' || typeof value === 'number') {
96
- vars[`--atomix-line-height-${key}`] = value;
97
- }
98
- });
99
- }
100
-
101
- this.applyGlobalCSSVars(vars);
72
+ // Inject CSS into DOM
73
+ injectCSS(css, this.styleId);
102
74
  }
103
75
 
104
76
  /**
105
- * Apply spacing system
77
+ * Check if object is DesignTokens
106
78
  */
107
- private applySpacing(spacing: any): void {
108
- const vars: Record<string, string | number> = {};
109
-
110
- // Handle spacing function or object
111
- if (typeof spacing === 'function') {
112
- // If spacing is a function, we can't iterate it directly
113
- // Just skip for now as it's a special case
114
- return;
115
- }
116
-
117
- if (typeof spacing === 'object' && spacing !== null) {
118
- Object.entries(spacing).forEach(([key, value]) => {
119
- if (typeof value === 'string' || typeof value === 'number') {
120
- vars[`--atomix-space-${key}`] = value;
121
- }
122
- });
123
- }
124
-
125
- this.applyGlobalCSSVars(vars);
79
+ private isDesignTokens(obj: Theme | DesignTokens): obj is DesignTokens {
80
+ // DesignTokens is a flat object with string keys, no nested structures
81
+ return obj !== null &&
82
+ typeof obj === 'object' &&
83
+ !('palette' in obj) &&
84
+ !('typography' in obj) &&
85
+ !('__isJSTheme' in obj);
126
86
  }
127
87
 
128
88
  /**
129
- * Apply color palette
89
+ * Apply global CSS variables (for component overrides)
130
90
  */
131
- private applyPalette(palette: Theme['palette']): void {
132
- if (!palette) return;
133
-
134
- const vars: Record<string, string | number> = {};
135
-
136
- Object.entries(palette).forEach(([colorName, colorScale]) => {
137
- if (colorScale && typeof colorScale === 'object') {
138
- Object.entries(colorScale).forEach(([shade, value]) => {
139
- if (value && (typeof value === 'string' || typeof value === 'number')) {
140
- vars[`--atomix-color-${colorName}-${shade}`] = value;
141
- }
142
- });
143
- }
91
+ private applyGlobalCSSVars(vars: Record<string, string | number>): void {
92
+ Object.entries(vars).forEach(([key, value]) => {
93
+ this.root.style.setProperty(key, String(value));
144
94
  });
145
-
146
- this.applyGlobalCSSVars(vars);
147
95
  }
148
96
 
149
97
  /**
@@ -213,15 +161,7 @@ export class ThemeApplicator {
213
161
  * Clear all applied CSS variables
214
162
  */
215
163
  private clearAppliedVars(): void {
216
- removeCSSVariables(Array.from(this.appliedVars), this.root);
217
- this.appliedVars.clear();
218
- }
219
-
220
- /**
221
- * Get all currently applied variables
222
- */
223
- getAppliedVars(): string[] {
224
- return Array.from(this.appliedVars);
164
+ removeCSS(this.styleId);
225
165
  }
226
166
 
227
167
  /**
@@ -229,6 +169,7 @@ export class ThemeApplicator {
229
169
  */
230
170
  removeTheme(): void {
231
171
  this.clearAppliedVars();
172
+ removeCSS(this.styleId);
232
173
  }
233
174
 
234
175
  /**
@@ -257,7 +198,7 @@ export function getThemeApplicator(): ThemeApplicator {
257
198
  /**
258
199
  * Apply theme using global applicator
259
200
  */
260
- export function applyTheme(theme: Theme): void {
201
+ export function applyTheme(theme: Theme | DesignTokens): void {
261
202
  getThemeApplicator().applyTheme(theme);
262
203
  }
263
204
 
@@ -5,7 +5,7 @@
5
5
  */
6
6
 
7
7
  import { createContext } from 'react';
8
- import type { ThemeContextValue } from './types';
8
+ import type { ThemeContextValue } from '../types';
9
9
 
10
10
  /**
11
11
  * Theme context with default values
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  import React, { Component, type ReactNode, type ErrorInfo } from 'react';
9
- import { ThemeError, ThemeErrorCode, getLogger } from '../errors';
9
+ import { ThemeError, ThemeErrorCode, getLogger } from '../errors/errors';
10
10
 
11
11
  /**
12
12
  * Error boundary state
@@ -83,7 +83,7 @@ const DefaultFallback: React.FC<{ error: Error; errorInfo: ErrorInfo }> = ({ err
83
83
  </pre>
84
84
  </details>
85
85
  )}
86
- {process.env.NODE_ENV === 'development' && errorInfo && (
86
+ {(typeof process === 'undefined' || process.env?.NODE_ENV === 'development') && errorInfo && (
87
87
  <details style={{ marginTop: '1rem' }}>
88
88
  <summary style={{ cursor: 'pointer', fontWeight: 'bold' }}>
89
89
  Stack Trace (Development Only)
@@ -148,7 +148,7 @@ export class ThemeErrorBoundary extends Component<
148
148
  };
149
149
  }
150
150
 
151
- override componentDidCatch(error: Error, errorInfo: ErrorInfo): void {
151
+ componentDidCatch(error: Error, errorInfo: ErrorInfo): void {
152
152
  // Log error
153
153
  const themeError = error instanceof ThemeError
154
154
  ? error
@@ -187,7 +187,7 @@ export class ThemeErrorBoundary extends Component<
187
187
  }
188
188
  }
189
189
 
190
- override componentDidUpdate(prevProps: ThemeErrorBoundaryProps): void {
190
+ componentDidUpdate(prevProps: ThemeErrorBoundaryProps): void {
191
191
  // Reset error if resetOnPropsChange is true and children changed
192
192
  if (
193
193
  this.props.resetOnPropsChange &&
@@ -202,7 +202,7 @@ export class ThemeErrorBoundary extends Component<
202
202
  }
203
203
  }
204
204
 
205
- override render(): ReactNode {
205
+ render(): ReactNode {
206
206
  if (this.state.hasError && this.state.error && this.state.errorInfo) {
207
207
  // Use custom fallback if provided
208
208
  if (this.props.fallback) {