@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
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
export { ThemeProvider } from './ThemeProvider';
|
|
8
8
|
export { ThemeErrorBoundary } from './ThemeErrorBoundary';
|
|
9
9
|
export { useTheme } from './useTheme';
|
|
10
|
+
export { useThemeTokens } from './useThemeTokens';
|
|
10
11
|
export { ThemeApplicator, getThemeApplicator, applyTheme } from './ThemeApplicator';
|
|
11
12
|
export type { ThemeErrorBoundaryProps } from './ThemeErrorBoundary';
|
|
12
13
|
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { useTheme } from './useTheme';
|
|
3
|
+
import type { Theme } from '../types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Standardized hook for accessing theme tokens in components
|
|
7
|
+
*
|
|
8
|
+
* Provides consistent access to theme values across all components
|
|
9
|
+
* using either CSS custom properties or theme object values.
|
|
10
|
+
*/
|
|
11
|
+
type ThemeTokens = {
|
|
12
|
+
theme: string;
|
|
13
|
+
activeTheme: Theme | null;
|
|
14
|
+
getToken: (tokenName: string, fallback?: string) => string;
|
|
15
|
+
getThemeValue: (path: string, fallback?: any) => any;
|
|
16
|
+
colors: {
|
|
17
|
+
primary: string;
|
|
18
|
+
secondary: string;
|
|
19
|
+
error: string;
|
|
20
|
+
success: string;
|
|
21
|
+
warning: string;
|
|
22
|
+
info: string;
|
|
23
|
+
light: string;
|
|
24
|
+
dark: string;
|
|
25
|
+
};
|
|
26
|
+
spacing: Record<string, string>;
|
|
27
|
+
borderRadius: Record<string, string>;
|
|
28
|
+
typography: {
|
|
29
|
+
fontFamily: Record<string, string>;
|
|
30
|
+
fontSize: Record<string, string>;
|
|
31
|
+
fontWeight: Record<string, string>;
|
|
32
|
+
};
|
|
33
|
+
shadows: Record<string, string>;
|
|
34
|
+
transitions: Record<string, string>;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export function useThemeTokens(): ThemeTokens {
|
|
38
|
+
const { theme, activeTheme } = useTheme();
|
|
39
|
+
|
|
40
|
+
// Helper function to get CSS variable value
|
|
41
|
+
const getToken = useCallback((tokenName: string, fallback?: string) => {
|
|
42
|
+
if (typeof window === 'undefined') return fallback || '';
|
|
43
|
+
|
|
44
|
+
const cssVarName = `--atomix-${tokenName}`;
|
|
45
|
+
const computedStyle = getComputedStyle(document.documentElement);
|
|
46
|
+
return computedStyle.getPropertyValue(cssVarName).trim() || fallback || '';
|
|
47
|
+
}, []);
|
|
48
|
+
|
|
49
|
+
// Helper function to get theme object value
|
|
50
|
+
const getThemeValue = useCallback((path: string, fallback?: any) => {
|
|
51
|
+
if (!activeTheme) return fallback;
|
|
52
|
+
|
|
53
|
+
// Navigate through nested theme object using dot notation
|
|
54
|
+
return path.split('.').reduce((obj, key) => obj?.[key], activeTheme) || fallback;
|
|
55
|
+
}, [activeTheme]);
|
|
56
|
+
|
|
57
|
+
// Return unified API for accessing theme values
|
|
58
|
+
return <ThemeTokens>{
|
|
59
|
+
theme,
|
|
60
|
+
activeTheme,
|
|
61
|
+
getToken,
|
|
62
|
+
getThemeValue,
|
|
63
|
+
// Commonly used tokens with fallbacks
|
|
64
|
+
colors: {
|
|
65
|
+
primary: getToken('primary', '#3b82f6'),
|
|
66
|
+
secondary: getToken('secondary', '#10b981'),
|
|
67
|
+
error: getToken('error', '#ef4444'),
|
|
68
|
+
success: getToken('success', '#22c55e'),
|
|
69
|
+
warning: getToken('warning', '#eab308'),
|
|
70
|
+
info: getToken('info', '#3b82f6'),
|
|
71
|
+
light: getToken('light', '#f9fafb'),
|
|
72
|
+
dark: getToken('dark', '#111827'),
|
|
73
|
+
},
|
|
74
|
+
spacing: {
|
|
75
|
+
1: getToken('spacing-1', '0.25rem'),
|
|
76
|
+
2: getToken('spacing-2', '0.5rem'),
|
|
77
|
+
3: getToken('spacing-3', '0.75rem'),
|
|
78
|
+
4: getToken('spacing-4', '1rem'),
|
|
79
|
+
5: getToken('spacing-5', '1.25rem'),
|
|
80
|
+
6: getToken('spacing-6', '1.5rem'),
|
|
81
|
+
8: getToken('spacing-8', '2rem'),
|
|
82
|
+
10: getToken('spacing-10', '2.5rem'),
|
|
83
|
+
12: getToken('spacing-12', '3rem'),
|
|
84
|
+
16: getToken('spacing-16', '4rem'),
|
|
85
|
+
20: getToken('spacing-20', '5rem'),
|
|
86
|
+
},
|
|
87
|
+
borderRadius: {
|
|
88
|
+
sm: getToken('border-radius-sm', '0.25rem'),
|
|
89
|
+
md: getToken('border-radius-md', '0.5rem'),
|
|
90
|
+
lg: getToken('border-radius-lg', '0.75rem'),
|
|
91
|
+
xl: getToken('border-radius-xl', '1rem'),
|
|
92
|
+
full: getToken('border-radius-full', '9999px'),
|
|
93
|
+
},
|
|
94
|
+
typography: {
|
|
95
|
+
fontFamily: {
|
|
96
|
+
sans: getToken('font-sans-serif', 'Inter, system-ui, sans-serif'),
|
|
97
|
+
serif: getToken('font-serif', 'Georgia, serif'),
|
|
98
|
+
mono: getToken('font-monospace', 'Fira Code, monospace'),
|
|
99
|
+
},
|
|
100
|
+
fontSize: {
|
|
101
|
+
xs: getToken('font-size-xs', '0.75rem'),
|
|
102
|
+
sm: getToken('font-size-sm', '0.875rem'),
|
|
103
|
+
md: getToken('font-size-md', '1rem'),
|
|
104
|
+
lg: getToken('font-size-lg', '1.125rem'),
|
|
105
|
+
xl: getToken('font-size-xl', '1.25rem'),
|
|
106
|
+
'2xl': getToken('font-size-2xl', '1.5rem'),
|
|
107
|
+
'3xl': getToken('font-size-3xl', '1.875rem'),
|
|
108
|
+
'4xl': getToken('font-size-4xl', '2.25rem'),
|
|
109
|
+
},
|
|
110
|
+
fontWeight: {
|
|
111
|
+
light: getToken('font-weight-light', '300'),
|
|
112
|
+
normal: getToken('font-weight-normal', '400'),
|
|
113
|
+
medium: getToken('font-weight-medium', '500'),
|
|
114
|
+
semibold: getToken('font-weight-semibold', '600'),
|
|
115
|
+
bold: getToken('font-weight-bold', '700'),
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
shadows: {
|
|
119
|
+
sm: getToken('box-shadow-sm', '0 1px 2px 0 rgba(0, 0, 0, 0.05)'),
|
|
120
|
+
md: getToken('box-shadow-md', '0 4px 6px -1px rgba(0, 0, 0, 0.1)'),
|
|
121
|
+
lg: getToken('box-shadow-lg', '0 10px 15px -3px rgba(0, 0, 0, 0.1)'),
|
|
122
|
+
xl: getToken('box-shadow-xl', '0 20px 25px -5px rgba(0, 0, 0, 0.1)'),
|
|
123
|
+
inset: getToken('box-shadow-inset', 'inset 0 2px 4px 0 rgba(0, 0, 0, 0.06)'),
|
|
124
|
+
},
|
|
125
|
+
transitions: {
|
|
126
|
+
fast: getToken('transition-fast', '150ms'),
|
|
127
|
+
base: getToken('transition-base', '200ms'),
|
|
128
|
+
slow: getToken('transition-slow', '300ms'),
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component Theming Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides consistent patterns for applying theme values to components
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { Theme } from '../types';
|
|
8
|
+
|
|
9
|
+
export interface ComponentThemeOptions {
|
|
10
|
+
component: string;
|
|
11
|
+
variant?: string;
|
|
12
|
+
size?: string;
|
|
13
|
+
theme: Theme;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Get a theme value for a specific component using CSS variables
|
|
18
|
+
* This ensures all components access theme values consistently
|
|
19
|
+
*/
|
|
20
|
+
export function getComponentThemeValue(
|
|
21
|
+
component: string,
|
|
22
|
+
property: string,
|
|
23
|
+
variant?: string,
|
|
24
|
+
size?: string
|
|
25
|
+
): string {
|
|
26
|
+
// Build CSS variable name following consistent pattern
|
|
27
|
+
const parts = ['atomix', component];
|
|
28
|
+
|
|
29
|
+
if (variant) {
|
|
30
|
+
parts.push(variant);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (size) {
|
|
34
|
+
parts.push(size);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
parts.push(property);
|
|
38
|
+
|
|
39
|
+
const cssVarName = `--${parts.join('-')}`;
|
|
40
|
+
const fallbackVarName = `--atomix-${property}`;
|
|
41
|
+
|
|
42
|
+
// Return CSS variable reference with fallback
|
|
43
|
+
return `var(${cssVarName}, var(${fallbackVarName}, initial))`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Generate component-specific CSS variables from theme
|
|
48
|
+
*/
|
|
49
|
+
export function generateComponentCSSVars(
|
|
50
|
+
component: string,
|
|
51
|
+
theme: Theme,
|
|
52
|
+
variant?: string,
|
|
53
|
+
size?: string
|
|
54
|
+
): Record<string, string> {
|
|
55
|
+
const vars: Record<string, string> = {};
|
|
56
|
+
|
|
57
|
+
// This is a simplified implementation - in a real system you'd have more
|
|
58
|
+
// sophisticated logic to extract component-specific values from the theme
|
|
59
|
+
const prefixParts = ['atomix', component];
|
|
60
|
+
|
|
61
|
+
if (variant) {
|
|
62
|
+
prefixParts.push(variant);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (size) {
|
|
66
|
+
prefixParts.push(size);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const prefix = prefixParts.join('-');
|
|
70
|
+
|
|
71
|
+
// Add common component properties
|
|
72
|
+
if (theme.palette) {
|
|
73
|
+
vars[`--${prefix}-color`] = theme.palette.primary?.main || '#7c3aed';
|
|
74
|
+
vars[`--${prefix}-color-hover`] = theme.palette.primary?.dark || '#5b21b6';
|
|
75
|
+
vars[`--${prefix}-color-active`] = theme.palette.primary?.main || '#7c3aed';
|
|
76
|
+
vars[`--${prefix}-color-disabled`] = theme.palette.text?.disabled || '#9ca3af';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (theme.typography) {
|
|
80
|
+
vars[`--${prefix}-font-family`] = theme.typography.fontFamily || 'Inter, sans-serif';
|
|
81
|
+
vars[`--${prefix}-font-size`] = theme.typography.fontSize ? `${theme.typography.fontSize}px` : '16px';
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (theme.spacing) {
|
|
85
|
+
const spacing = typeof theme.spacing === 'function' ? theme.spacing : (val: number) => val * 8;
|
|
86
|
+
vars[`--${prefix}-spacing-unit`] = `${spacing(1)}px`;
|
|
87
|
+
vars[`--${prefix}-spacing-sm`] = `${spacing(0.5)}px`;
|
|
88
|
+
vars[`--${prefix}-spacing-md`] = `${spacing(1)}px`;
|
|
89
|
+
vars[`--${prefix}-spacing-lg`] = `${spacing(2)}px`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return vars;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Apply consistent theme to component style object
|
|
97
|
+
*/
|
|
98
|
+
export function applyComponentTheme(
|
|
99
|
+
component: string,
|
|
100
|
+
style: React.CSSProperties = {},
|
|
101
|
+
variant?: string,
|
|
102
|
+
size?: string,
|
|
103
|
+
theme?: Theme
|
|
104
|
+
): React.CSSProperties {
|
|
105
|
+
// If no theme provided, return original style
|
|
106
|
+
if (!theme) {
|
|
107
|
+
return style;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Generate component-specific CSS variables
|
|
111
|
+
const componentVars = generateComponentCSSVars(component, theme, variant, size);
|
|
112
|
+
|
|
113
|
+
// Merge with existing style
|
|
114
|
+
return {
|
|
115
|
+
...componentVars,
|
|
116
|
+
...style,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Create a hook for consistent component theming
|
|
122
|
+
*/
|
|
123
|
+
export function useComponentTheme(
|
|
124
|
+
component: string,
|
|
125
|
+
variant?: string,
|
|
126
|
+
size?: string,
|
|
127
|
+
theme?: Theme
|
|
128
|
+
): (property: string) => string {
|
|
129
|
+
return (property: string) => {
|
|
130
|
+
return getComponentThemeValue(component, property, variant, size);
|
|
131
|
+
};
|
|
132
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Naming Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides consistent naming conventions across the theme system
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export interface NamingOptions {
|
|
8
|
+
prefix?: string;
|
|
9
|
+
component?: string;
|
|
10
|
+
variant?: string;
|
|
11
|
+
state?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Generate consistent CSS class names following BEM methodology
|
|
16
|
+
*/
|
|
17
|
+
export function generateClassName(block: string, element?: string, modifiers?: Record<string, boolean | string>): string {
|
|
18
|
+
let className = block;
|
|
19
|
+
|
|
20
|
+
if (element) {
|
|
21
|
+
className += `__${element}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (modifiers) {
|
|
25
|
+
Object.entries(modifiers).forEach(([key, value]) => {
|
|
26
|
+
if (value) {
|
|
27
|
+
className += `--${key}`;
|
|
28
|
+
if (typeof value === 'string' && value !== key) {
|
|
29
|
+
className += `-${value}`;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return className;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Generate consistent CSS variable names
|
|
40
|
+
*/
|
|
41
|
+
export function generateCSSVariableName(property: string, options: NamingOptions = {}): string {
|
|
42
|
+
const { prefix = 'atomix', component, variant, state } = options;
|
|
43
|
+
|
|
44
|
+
const parts = [prefix];
|
|
45
|
+
|
|
46
|
+
if (component) {
|
|
47
|
+
parts.push(component);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (variant) {
|
|
51
|
+
parts.push(variant);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (state) {
|
|
55
|
+
parts.push(state);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
parts.push(property);
|
|
59
|
+
|
|
60
|
+
return `--${parts.join('-')}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Normalize theme tokens to consistent naming convention
|
|
65
|
+
*/
|
|
66
|
+
export function normalizeThemeTokens(tokens: Record<string, any>): Record<string, any> {
|
|
67
|
+
const normalized: Record<string, any> = {};
|
|
68
|
+
|
|
69
|
+
for (const [key, value] of Object.entries(tokens)) {
|
|
70
|
+
if (typeof value === 'object' && value !== null) {
|
|
71
|
+
// Recursively normalize nested objects
|
|
72
|
+
normalized[key] = normalizeThemeTokens(value);
|
|
73
|
+
} else {
|
|
74
|
+
// Apply consistent naming transformation
|
|
75
|
+
normalized[key] = value;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return normalized;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Convert camelCase to kebab-case for CSS custom properties
|
|
84
|
+
*/
|
|
85
|
+
export function camelToKebab(str: string): string {
|
|
86
|
+
return str.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Convert theme property to CSS variable name
|
|
91
|
+
*/
|
|
92
|
+
export function themePropertyToCSSVar(propertyPath: string, prefix: string = 'atomix'): string {
|
|
93
|
+
// Convert nested property paths to kebab-case
|
|
94
|
+
const path = propertyPath
|
|
95
|
+
.split('.')
|
|
96
|
+
.map(part => camelToKebab(part))
|
|
97
|
+
.join('-');
|
|
98
|
+
|
|
99
|
+
return `--${prefix}-${path}`;
|
|
100
|
+
}
|
|
@@ -207,13 +207,13 @@ export function spacing(theme: Theme, ...values: number[]): string {
|
|
|
207
207
|
* @param fallback - Fallback value if path not found
|
|
208
208
|
* @returns Theme value or fallback
|
|
209
209
|
*/
|
|
210
|
-
export function getThemeValue<T =
|
|
210
|
+
export function getThemeValue<T = unknown>(theme: Theme, path: string, fallback?: T): T {
|
|
211
211
|
const keys = path.split('.');
|
|
212
|
-
let value:
|
|
212
|
+
let value: unknown = theme;
|
|
213
213
|
|
|
214
214
|
for (const key of keys) {
|
|
215
215
|
if (value && typeof value === 'object' && key in value) {
|
|
216
|
-
value = value[key];
|
|
216
|
+
value = (value as Record<string, unknown>)[key];
|
|
217
217
|
} else {
|
|
218
218
|
return fallback as T;
|
|
219
219
|
}
|
|
@@ -225,8 +225,8 @@ export function getThemeValue<T = any>(theme: Theme, path: string, fallback?: T)
|
|
|
225
225
|
/**
|
|
226
226
|
* Check if a theme is a JS theme (created with createTheme)
|
|
227
227
|
*/
|
|
228
|
-
export function isJSTheme(theme:
|
|
229
|
-
return
|
|
228
|
+
export function isJSTheme(theme: unknown): theme is Theme {
|
|
229
|
+
return typeof theme === 'object' && theme !== null && '__isJSTheme' in theme && theme.__isJSTheme === true;
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
// ============================================================================
|
|
@@ -265,7 +265,7 @@ export function breakpointBetween(
|
|
|
265
265
|
/**
|
|
266
266
|
* Get typography variant styles
|
|
267
267
|
*/
|
|
268
|
-
export function getTypography(theme: Theme, variant: keyof Theme['typography']):
|
|
268
|
+
export function getTypography(theme: Theme, variant: keyof Theme['typography']): Theme['typography'][keyof Theme['typography']] {
|
|
269
269
|
return theme.typography[variant] ?? {};
|
|
270
270
|
}
|
|
271
271
|
|
|
@@ -114,7 +114,7 @@ export function hasCustomization(props: {
|
|
|
114
114
|
* Create data attributes for debugging
|
|
115
115
|
*/
|
|
116
116
|
export function createDebugAttrs(componentName: string, variant?: string): Record<string, string> {
|
|
117
|
-
if (process.env
|
|
117
|
+
if (typeof process === 'undefined' || process.env?.NODE_ENV !== 'development') return {};
|
|
118
118
|
|
|
119
119
|
return {
|
|
120
120
|
'data-component': componentName,
|
|
@@ -34,7 +34,7 @@ export function isMemoryMonitoringAvailable(): boolean {
|
|
|
34
34
|
return (
|
|
35
35
|
typeof performance !== 'undefined' &&
|
|
36
36
|
'memory' in performance &&
|
|
37
|
-
process.env
|
|
37
|
+
(typeof process === 'undefined' || process.env?.NODE_ENV === 'development')
|
|
38
38
|
);
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -133,7 +133,7 @@ export function monitorMemoryUsage(
|
|
|
133
133
|
if (snapshot) {
|
|
134
134
|
if (callback) {
|
|
135
135
|
callback(snapshot);
|
|
136
|
-
} else if (process.env
|
|
136
|
+
} else if (typeof process !== 'undefined' && process.env?.NODE_ENV === 'development') {
|
|
137
137
|
console.log('[Memory Monitor]', {
|
|
138
138
|
used: formatBytes(snapshot.usedJSHeapSize),
|
|
139
139
|
total: formatBytes(snapshot.totalJSHeapSize),
|
|
@@ -175,7 +175,7 @@ export function trackComponentMemory(componentName: string) {
|
|
|
175
175
|
const after = getMemorySnapshot();
|
|
176
176
|
if (before && after) {
|
|
177
177
|
const leakInfo = detectMemoryLeak(before, after);
|
|
178
|
-
if (leakInfo.hasLeak && process.env
|
|
178
|
+
if (leakInfo.hasLeak && (typeof process === 'undefined' || process.env?.NODE_ENV === 'development')) {
|
|
179
179
|
console.warn(
|
|
180
180
|
`[Memory Monitor] Potential memory leak detected in ${componentName}:`,
|
|
181
181
|
leakInfo
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theme Naming Utility
|
|
3
|
+
*
|
|
4
|
+
* Provides consistent naming conventions for CSS classes, CSS variables,
|
|
5
|
+
* and JavaScript properties throughout the theme system.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export class ThemeNaming {
|
|
9
|
+
private static prefix = 'atomix';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Set the global prefix for all theme tokens
|
|
13
|
+
* @param newPrefix - New prefix to use
|
|
14
|
+
*/
|
|
15
|
+
static setPrefix(newPrefix: string): void {
|
|
16
|
+
this.prefix = newPrefix;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Get the current prefix
|
|
21
|
+
*/
|
|
22
|
+
static getPrefix(): string {
|
|
23
|
+
return this.prefix;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Convert camelCase to kebab-case for CSS variables
|
|
28
|
+
* @param str - String to convert
|
|
29
|
+
*/
|
|
30
|
+
static camelToKebab(str: string): string {
|
|
31
|
+
return str.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Convert kebab-case to camelCase for JavaScript properties
|
|
36
|
+
* @param str - String to convert
|
|
37
|
+
*/
|
|
38
|
+
static kebabToCamel(str: string): string {
|
|
39
|
+
return str.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Create a CSS variable name
|
|
44
|
+
* @param token - Token name in camelCase
|
|
45
|
+
*/
|
|
46
|
+
static cssVar(token: string): string {
|
|
47
|
+
return `--${this.prefix}-${this.camelToKebab(token)}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Create a BEM CSS class name
|
|
52
|
+
* @param block - Block name
|
|
53
|
+
* @param element - Element name (optional)
|
|
54
|
+
* @param modifier - Modifier name (optional)
|
|
55
|
+
*/
|
|
56
|
+
static bemClass(block: string, element?: string, modifier?: string): string {
|
|
57
|
+
let className = `c-${block}`;
|
|
58
|
+
|
|
59
|
+
if (element) {
|
|
60
|
+
className += `__${element}`;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (modifier) {
|
|
64
|
+
className += `--${modifier}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return className;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Create a variant class name
|
|
72
|
+
* @param component - Component name
|
|
73
|
+
* @param variant - Variant name
|
|
74
|
+
*/
|
|
75
|
+
static variantClass(component: string, variant: string): string {
|
|
76
|
+
return `c-${component}--${variant}`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Create a size class name
|
|
81
|
+
* @param component - Component name
|
|
82
|
+
* @param size - Size name
|
|
83
|
+
*/
|
|
84
|
+
static sizeClass(component: string, size: string): string {
|
|
85
|
+
return `c-${component}--${size}`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Create a state class name
|
|
90
|
+
* @param component - Component name
|
|
91
|
+
* @param state - State name
|
|
92
|
+
*/
|
|
93
|
+
static stateClass(component: string, state: string): string {
|
|
94
|
+
return `c-${component}--${state}`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Create a utility class name
|
|
99
|
+
* @param utility - Utility name
|
|
100
|
+
*/
|
|
101
|
+
static utilityClass(utility: string): string {
|
|
102
|
+
return `u-${utility}`;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Create a layout class name
|
|
107
|
+
* @param layout - Layout name
|
|
108
|
+
*/
|
|
109
|
+
static layoutClass(layout: string): string {
|
|
110
|
+
return `l-${layout}`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Create an object class name
|
|
115
|
+
* @param object - Object name
|
|
116
|
+
*/
|
|
117
|
+
static objectClass(object: string): string {
|
|
118
|
+
return `o-${object}`;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Export constants for common naming patterns
|
|
123
|
+
export const THEME_NAMING = {
|
|
124
|
+
PREFIX: 'atomix',
|
|
125
|
+
CSS_VAR: ThemeNaming.cssVar,
|
|
126
|
+
BEM_CLASS: ThemeNaming.bemClass,
|
|
127
|
+
VARIANT_CLASS: ThemeNaming.variantClass,
|
|
128
|
+
SIZE_CLASS: ThemeNaming.sizeClass,
|
|
129
|
+
STATE_CLASS: ThemeNaming.stateClass,
|
|
130
|
+
UTILITY_CLASS: ThemeNaming.utilityClass,
|
|
131
|
+
LAYOUT_CLASS: ThemeNaming.layoutClass,
|
|
132
|
+
OBJECT_CLASS: ThemeNaming.objectClass,
|
|
133
|
+
CAMEL_TO_KEBAB: ThemeNaming.camelToKebab,
|
|
134
|
+
KEBAB_TO_CAMEL: ThemeNaming.kebabToCamel,
|
|
135
|
+
};
|