@shohojdhara/atomix 0.3.6 → 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.
- package/README.md +3 -3
- package/dist/charts.js +50 -142
- package/dist/charts.js.map +1 -1
- package/dist/core.js +179 -274
- package/dist/core.js.map +1 -1
- package/dist/forms.js +50 -142
- package/dist/forms.js.map +1 -1
- package/dist/heavy.js +179 -274
- package/dist/heavy.js.map +1 -1
- package/dist/index.d.ts +669 -703
- package/dist/index.esm.js +966 -1649
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1211 -1890
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/theme.d.ts +163 -334
- package/dist/theme.js +774 -1473
- package/dist/theme.js.map +1 -1
- package/package.json +1 -1
- package/src/components/AtomixGlass/AtomixGlass.tsx +128 -356
- package/src/components/AtomixGlass/AtomixGlassContainer.tsx +1 -1
- package/src/components/Button/Button.tsx +85 -167
- package/src/lib/composables/useAtomixGlass.ts +7 -7
- package/src/lib/config/loader.ts +2 -3
- package/src/lib/constants/components.ts +7 -0
- package/src/lib/hooks/usePerformanceMonitor.ts +1 -1
- package/src/lib/hooks/useThemeTokens.ts +105 -0
- package/src/lib/theme/config/configLoader.ts +60 -219
- package/src/lib/theme/config/loader.ts +15 -21
- package/src/lib/theme/constants/constants.ts +1 -1
- package/src/lib/theme/core/ThemeRegistry.ts +75 -279
- package/src/lib/theme/core/composeTheme.ts +14 -64
- package/src/lib/theme/core/createTheme.ts +54 -40
- package/src/lib/theme/core/createThemeObject.ts +2 -2
- package/src/lib/theme/core/index.ts +15 -1
- package/src/lib/theme/errors/errors.ts +1 -1
- package/src/lib/theme/generators/generateCSSNested.ts +130 -0
- package/src/lib/theme/generators/index.ts +6 -0
- package/src/lib/theme/index.ts +35 -10
- package/src/lib/theme/runtime/ThemeApplicator.ts +1 -1
- package/src/lib/theme/runtime/ThemeErrorBoundary.tsx +4 -4
- package/src/lib/theme/runtime/ThemeProvider.tsx +261 -554
- package/src/lib/theme/runtime/index.ts +1 -0
- package/src/lib/theme/runtime/useThemeTokens.ts +131 -0
- package/src/lib/theme/utils/componentTheming.ts +132 -0
- package/src/lib/theme/utils/naming.ts +100 -0
- package/src/lib/theme/utils/themeUtils.ts +6 -6
- package/src/lib/utils/componentUtils.ts +1 -1
- package/src/lib/utils/memoryMonitor.ts +3 -3
- package/src/lib/utils/themeNaming.ts +135 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS Variable Generator for Nested Tokens
|
|
3
|
+
*
|
|
4
|
+
* Generates CSS custom properties from nested token structures.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { DesignTokens } from '../tokens/tokens';
|
|
8
|
+
import { generateCSSVariables } from './generateCSS';
|
|
9
|
+
import { ThemeNaming } from '../../utils/themeNaming';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Options for CSS variable generation with nested support
|
|
13
|
+
*/
|
|
14
|
+
export interface GenerateNestedCSSVariablesOptions {
|
|
15
|
+
/** CSS selector for the variables (default: ':root') */
|
|
16
|
+
selector?: string;
|
|
17
|
+
/** Prefix for CSS variables (default: 'atomix') */
|
|
18
|
+
prefix?: string;
|
|
19
|
+
/** Separator for nested tokens (default: '-') */
|
|
20
|
+
separator?: string;
|
|
21
|
+
/** Whether to flatten nested objects (default: true) */
|
|
22
|
+
flatten?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Generate CSS variables from nested token structure
|
|
27
|
+
*
|
|
28
|
+
* Converts nested token object to CSS custom properties.
|
|
29
|
+
* Supports both nested objects and flat token structures.
|
|
30
|
+
*
|
|
31
|
+
* @param tokens - Design tokens object (can be nested)
|
|
32
|
+
* @param options - Generation options
|
|
33
|
+
* @returns CSS string with custom properties
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const tokens = {
|
|
38
|
+
* color: {
|
|
39
|
+
* primary: '#7c3aed',
|
|
40
|
+
* secondary: '#10b981',
|
|
41
|
+
* },
|
|
42
|
+
* spacing: {
|
|
43
|
+
* small: '0.5rem',
|
|
44
|
+
* medium: '1rem',
|
|
45
|
+
* },
|
|
46
|
+
* };
|
|
47
|
+
*
|
|
48
|
+
* const css = generateNestedCSSVariables(tokens);
|
|
49
|
+
* // Returns: ":root {
|
|
50
|
+
--atomix-color-primary: #7c3aed;
|
|
51
|
+
--atomix-color-secondary: #10b981;
|
|
52
|
+
--atomix-spacing-small: 0.5rem;
|
|
53
|
+
--atomix-spacing-medium: 1rem;
|
|
54
|
+
}"
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export function generateNestedCSSVariables(
|
|
58
|
+
tokens: DesignTokens,
|
|
59
|
+
options: GenerateNestedCSSVariablesOptions = {}
|
|
60
|
+
): string {
|
|
61
|
+
const {
|
|
62
|
+
selector = ':root',
|
|
63
|
+
prefix = 'atomix',
|
|
64
|
+
separator = '-',
|
|
65
|
+
flatten = true,
|
|
66
|
+
} = options;
|
|
67
|
+
|
|
68
|
+
// Flatten nested token structure
|
|
69
|
+
const flattened = flatten ? flattenTokens(tokens, separator) : tokens;
|
|
70
|
+
|
|
71
|
+
// Generate CSS variables using the original function
|
|
72
|
+
return generateCSSVariables(flattened, { selector, prefix });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Flatten nested token structure
|
|
77
|
+
*
|
|
78
|
+
* @param tokens - Token object (can be nested)
|
|
79
|
+
* @param separator - Separator for nested keys
|
|
80
|
+
* @returns Flattened token object
|
|
81
|
+
*/
|
|
82
|
+
function flattenTokens(tokens: DesignTokens, separator: string): DesignTokens {
|
|
83
|
+
const result: DesignTokens = {};
|
|
84
|
+
|
|
85
|
+
for (const [key, value] of Object.entries(tokens)) {
|
|
86
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
87
|
+
// Recursively flatten nested objects
|
|
88
|
+
const flattened = flattenTokens(value, separator);
|
|
89
|
+
|
|
90
|
+
// Combine keys with separator
|
|
91
|
+
for (const [nestedKey, nestedValue] of Object.entries(flattened)) {
|
|
92
|
+
const newKey = `${key}${separator}${nestedKey}`;
|
|
93
|
+
result[newKey] = nestedValue;
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
// Direct value
|
|
97
|
+
result[key] = value;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Generate CSS variables with custom selector for nested tokens
|
|
106
|
+
*
|
|
107
|
+
* @param tokens - Design tokens object
|
|
108
|
+
* @param selector - CSS selector (e.g., '[data-theme="dark"]')
|
|
109
|
+
* @param prefix - CSS variable prefix
|
|
110
|
+
* @param separator - Separator for nested keys
|
|
111
|
+
* @returns CSS string
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const css = generateNestedCSSVariablesForSelector(
|
|
116
|
+
* tokens,
|
|
117
|
+
* '[data-theme="dark"]',
|
|
118
|
+
* 'atomix',
|
|
119
|
+
* '-'
|
|
120
|
+
* );
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export function generateNestedCSSVariablesForSelector(
|
|
124
|
+
tokens: DesignTokens,
|
|
125
|
+
selector: string,
|
|
126
|
+
prefix: string = 'atomix',
|
|
127
|
+
separator: string = '-'
|
|
128
|
+
): string {
|
|
129
|
+
return generateNestedCSSVariables(tokens, { selector, prefix, separator });
|
|
130
|
+
}
|
|
@@ -10,6 +10,12 @@ export {
|
|
|
10
10
|
type GenerateCSSVariablesOptions,
|
|
11
11
|
} from './generateCSS';
|
|
12
12
|
|
|
13
|
+
export {
|
|
14
|
+
generateNestedCSSVariables,
|
|
15
|
+
generateNestedCSSVariablesForSelector,
|
|
16
|
+
type GenerateNestedCSSVariablesOptions,
|
|
17
|
+
} from './generateCSSNested';
|
|
18
|
+
|
|
13
19
|
export { generateCSSVariables as generateCSSVariablesFromTheme } from './generateCSSVariables';
|
|
14
20
|
|
|
15
21
|
export {
|
package/src/lib/theme/index.ts
CHANGED
|
@@ -31,8 +31,18 @@ export { createThemeObject } from './core';
|
|
|
31
31
|
// Theme composition
|
|
32
32
|
export { deepMerge, mergeTheme, extendTheme } from './core';
|
|
33
33
|
|
|
34
|
-
// Theme
|
|
35
|
-
export {
|
|
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';
|
|
36
46
|
|
|
37
47
|
// ============================================================================
|
|
38
48
|
// Theme Injection and Management
|
|
@@ -79,16 +89,32 @@ export {
|
|
|
79
89
|
} from './generators';
|
|
80
90
|
|
|
81
91
|
// ============================================================================
|
|
82
|
-
//
|
|
92
|
+
// Naming and Component Theming Utilities
|
|
83
93
|
// ============================================================================
|
|
84
94
|
|
|
85
|
-
export {
|
|
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';
|
|
86
111
|
|
|
87
112
|
// ============================================================================
|
|
88
|
-
//
|
|
113
|
+
// Injection Utilities
|
|
89
114
|
// ============================================================================
|
|
90
115
|
|
|
91
|
-
export {
|
|
116
|
+
export { injectCSS, removeCSS, isCSSInjected } from './utils/injectCSS';
|
|
117
|
+
|
|
92
118
|
|
|
93
119
|
// ============================================================================
|
|
94
120
|
// Config Loader
|
|
@@ -106,6 +132,7 @@ export {
|
|
|
106
132
|
// Core React components and hooks
|
|
107
133
|
export { ThemeProvider } from './runtime/ThemeProvider';
|
|
108
134
|
export { useTheme } from './runtime/useTheme';
|
|
135
|
+
export { useThemeTokens } from './runtime/useThemeTokens';
|
|
109
136
|
export { ThemeContext } from './runtime/ThemeContext';
|
|
110
137
|
export { ThemeErrorBoundary } from './runtime/ThemeErrorBoundary';
|
|
111
138
|
|
|
@@ -132,8 +159,6 @@ export {
|
|
|
132
159
|
|
|
133
160
|
// CSS variable utilities
|
|
134
161
|
export {
|
|
135
|
-
generateCSSVariableName,
|
|
136
|
-
generateComponentCSSVars,
|
|
137
162
|
mapSCSSTokensToCSSVars,
|
|
138
163
|
applyCSSVariables,
|
|
139
164
|
removeCSSVariables,
|
|
@@ -147,10 +172,10 @@ export {
|
|
|
147
172
|
// RTL Support
|
|
148
173
|
export { RTLManager } from './i18n/rtl';
|
|
149
174
|
|
|
175
|
+
|
|
150
176
|
// Types
|
|
151
177
|
export type {
|
|
152
178
|
Theme,
|
|
153
|
-
ThemeMetadata,
|
|
154
179
|
ThemeChangeEvent,
|
|
155
180
|
ThemeLoadOptions,
|
|
156
181
|
ThemeValidationResult,
|
|
@@ -168,4 +193,4 @@ export type {
|
|
|
168
193
|
CSSVariableNamingOptions,
|
|
169
194
|
} from './adapters/cssVariableMapper';
|
|
170
195
|
|
|
171
|
-
export type { RTLConfig } from './i18n/rtl';
|
|
196
|
+
export type { RTLConfig } from './i18n/rtl';
|
|
@@ -198,7 +198,7 @@ export function getThemeApplicator(): ThemeApplicator {
|
|
|
198
198
|
/**
|
|
199
199
|
* Apply theme using global applicator
|
|
200
200
|
*/
|
|
201
|
-
export function applyTheme(theme: Theme): void {
|
|
201
|
+
export function applyTheme(theme: Theme | DesignTokens): void {
|
|
202
202
|
getThemeApplicator().applyTheme(theme);
|
|
203
203
|
}
|
|
204
204
|
|
|
@@ -83,7 +83,7 @@ const DefaultFallback: React.FC<{ error: Error; errorInfo: ErrorInfo }> = ({ err
|
|
|
83
83
|
</pre>
|
|
84
84
|
</details>
|
|
85
85
|
)}
|
|
86
|
-
{process.env
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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) {
|