@rakeyshgidwani/roger-ui-bank-theme-stan-design 0.1.3 → 0.1.5
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/CHANGELOG.md +1 -1
- package/dist/index.d.ts +131 -131
- package/dist/index.esm.js +148 -148
- package/dist/index.js +148 -148
- package/dist/styles.css +1 -1
- package/package.json +1 -1
- package/src/components/ui/accessibility-demo.tsx +271 -0
- package/src/components/ui/advanced-component-architecture-demo.tsx +916 -0
- package/src/components/ui/advanced-transition-system-demo.tsx +670 -0
- package/src/components/ui/advanced-transition-system.tsx +395 -0
- package/src/components/ui/animation/animated-container.tsx +166 -0
- package/src/components/ui/animation/index.ts +19 -0
- package/src/components/ui/animation/staggered-container.tsx +68 -0
- package/src/components/ui/animation-demo.tsx +250 -0
- package/src/components/ui/badge.tsx +33 -0
- package/src/components/ui/battery-conscious-animation-demo.tsx +568 -0
- package/src/components/ui/border-radius-shadow-demo.tsx +187 -0
- package/src/components/ui/button.tsx +36 -0
- package/src/components/ui/card.tsx +207 -0
- package/src/components/ui/checkbox.tsx +30 -0
- package/src/components/ui/color-preview.tsx +411 -0
- package/src/components/ui/data-display/chart.tsx +653 -0
- package/src/components/ui/data-display/data-grid-simple.tsx +76 -0
- package/src/components/ui/data-display/data-grid.tsx +680 -0
- package/src/components/ui/data-display/list.tsx +456 -0
- package/src/components/ui/data-display/table.tsx +482 -0
- package/src/components/ui/data-display/timeline.tsx +441 -0
- package/src/components/ui/data-display/tree.tsx +602 -0
- package/src/components/ui/data-display/types.ts +536 -0
- package/src/components/ui/enterprise-mobile-experience-demo.tsx +749 -0
- package/src/components/ui/enterprise-mobile-experience.tsx +464 -0
- package/src/components/ui/feedback/alert.tsx +157 -0
- package/src/components/ui/feedback/progress.tsx +292 -0
- package/src/components/ui/feedback/skeleton.tsx +185 -0
- package/src/components/ui/feedback/toast.tsx +280 -0
- package/src/components/ui/feedback/types.ts +125 -0
- package/src/components/ui/font-preview.tsx +288 -0
- package/src/components/ui/form-demo.tsx +553 -0
- package/src/components/ui/hardware-acceleration-demo.tsx +547 -0
- package/src/components/ui/input.tsx +35 -0
- package/src/components/ui/label.tsx +16 -0
- package/src/components/ui/layout-demo.tsx +367 -0
- package/src/components/ui/layouts/adaptive-layout.tsx +139 -0
- package/src/components/ui/layouts/desktop-layout.tsx +224 -0
- package/src/components/ui/layouts/index.ts +10 -0
- package/src/components/ui/layouts/mobile-layout.tsx +162 -0
- package/src/components/ui/layouts/tablet-layout.tsx +197 -0
- package/src/components/ui/mobile-form-validation.tsx +451 -0
- package/src/components/ui/mobile-input-demo.tsx +201 -0
- package/src/components/ui/mobile-input.tsx +281 -0
- package/src/components/ui/mobile-skeleton-loading-demo.tsx +638 -0
- package/src/components/ui/navigation/breadcrumb.tsx +158 -0
- package/src/components/ui/navigation/index.ts +36 -0
- package/src/components/ui/navigation/menu.tsx +374 -0
- package/src/components/ui/navigation/navigation-demo.tsx +324 -0
- package/src/components/ui/navigation/pagination.tsx +272 -0
- package/src/components/ui/navigation/sidebar.tsx +383 -0
- package/src/components/ui/navigation/stepper.tsx +303 -0
- package/src/components/ui/navigation/tabs.tsx +205 -0
- package/src/components/ui/navigation/types.ts +299 -0
- package/src/components/ui/overlay/backdrop.tsx +81 -0
- package/src/components/ui/overlay/focus-manager.tsx +143 -0
- package/src/components/ui/overlay/index.ts +36 -0
- package/src/components/ui/overlay/modal.tsx +270 -0
- package/src/components/ui/overlay/overlay-manager.tsx +110 -0
- package/src/components/ui/overlay/popover.tsx +462 -0
- package/src/components/ui/overlay/portal.tsx +79 -0
- package/src/components/ui/overlay/tooltip.tsx +303 -0
- package/src/components/ui/overlay/types.ts +196 -0
- package/src/components/ui/performance-demo.tsx +596 -0
- package/src/components/ui/semantic-input-system-demo.tsx +502 -0
- package/src/components/ui/semantic-input-system-demo.tsx.disabled +873 -0
- package/src/components/ui/tablet-layout.tsx +192 -0
- package/src/components/ui/theme-customizer.tsx +386 -0
- package/src/components/ui/theme-preview.tsx +310 -0
- package/src/components/ui/theme-switcher.tsx +264 -0
- package/src/components/ui/theme-toggle.tsx +38 -0
- package/src/components/ui/token-demo.tsx +195 -0
- package/src/components/ui/touch-demo.tsx +462 -0
- package/src/components/ui/touch-friendly-interface-demo.tsx +519 -0
- package/src/components/ui/touch-friendly-interface.tsx +296 -0
- package/src/hooks/index.ts +190 -0
- package/src/hooks/use-accessibility-support.ts +518 -0
- package/src/hooks/use-adaptive-layout.ts +289 -0
- package/src/hooks/use-advanced-patterns.ts +294 -0
- package/src/hooks/use-advanced-transition-system.ts +393 -0
- package/src/hooks/use-animation-profile.ts +288 -0
- package/src/hooks/use-battery-animations.ts +384 -0
- package/src/hooks/use-battery-conscious-loading.ts +475 -0
- package/src/hooks/use-battery-optimization.ts +330 -0
- package/src/hooks/use-battery-status.ts +299 -0
- package/src/hooks/use-component-performance.ts +344 -0
- package/src/hooks/use-device-loading-states.ts +459 -0
- package/src/hooks/use-device.tsx +110 -0
- package/src/hooks/use-enterprise-mobile-experience.ts +488 -0
- package/src/hooks/use-form-feedback.ts +403 -0
- package/src/hooks/use-form-performance.ts +513 -0
- package/src/hooks/use-frame-rate.ts +251 -0
- package/src/hooks/use-gestures.ts +338 -0
- package/src/hooks/use-hardware-acceleration.ts +341 -0
- package/src/hooks/use-input-accessibility.ts +455 -0
- package/src/hooks/use-input-performance.ts +506 -0
- package/src/hooks/use-layout-performance.ts +319 -0
- package/src/hooks/use-loading-accessibility.ts +535 -0
- package/src/hooks/use-loading-performance.ts +473 -0
- package/src/hooks/use-memory-usage.ts +287 -0
- package/src/hooks/use-mobile-form-layout.ts +464 -0
- package/src/hooks/use-mobile-form-validation.ts +518 -0
- package/src/hooks/use-mobile-keyboard-optimization.ts +472 -0
- package/src/hooks/use-mobile-layout.ts +302 -0
- package/src/hooks/use-mobile-optimization.ts +406 -0
- package/src/hooks/use-mobile-skeleton.ts +402 -0
- package/src/hooks/use-mobile-touch.ts +414 -0
- package/src/hooks/use-performance-throttling.ts +348 -0
- package/src/hooks/use-performance.ts +316 -0
- package/src/hooks/use-reusable-architecture.ts +414 -0
- package/src/hooks/use-semantic-input-types.ts +357 -0
- package/src/hooks/use-semantic-input.ts +565 -0
- package/src/hooks/use-tablet-layout.ts +384 -0
- package/src/hooks/use-touch-friendly-input.ts +524 -0
- package/src/hooks/use-touch-friendly-interface.ts +331 -0
- package/src/hooks/use-touch-optimization.ts +375 -0
- package/src/index.ts +279 -279
- package/src/lib/utils.ts +6 -0
- package/src/themes/README.md +272 -0
- package/src/themes/ThemeContext.tsx +31 -0
- package/src/themes/ThemeProvider.tsx +232 -0
- package/src/themes/accessibility/index.ts +27 -0
- package/src/themes/accessibility.ts +259 -0
- package/src/themes/aria-patterns.ts +420 -0
- package/src/themes/base-themes.ts +55 -0
- package/src/themes/colorManager.ts +380 -0
- package/src/themes/examples/dark-theme.ts +154 -0
- package/src/themes/examples/minimal-theme.ts +108 -0
- package/src/themes/focus-management.ts +701 -0
- package/src/themes/fontLoader.ts +201 -0
- package/src/themes/high-contrast.ts +621 -0
- package/src/themes/index.ts +19 -0
- package/src/themes/inheritance.ts +227 -0
- package/src/themes/keyboard-navigation.ts +550 -0
- package/src/themes/motion-reduction.ts +662 -0
- package/src/themes/navigation.ts +238 -0
- package/src/themes/screen-reader.ts +645 -0
- package/src/themes/systemThemeDetector.ts +182 -0
- package/src/themes/themeCSSUpdater.ts +262 -0
- package/src/themes/themePersistence.ts +238 -0
- package/src/themes/themes/default.ts +586 -0
- package/src/themes/themes/harvey.ts +554 -0
- package/src/themes/themes/stan-design.ts +683 -0
- package/src/themes/types.ts +460 -0
- package/src/themes/useSystemTheme.ts +48 -0
- package/src/themes/useTheme.ts +87 -0
- package/src/themes/validation.ts +462 -0
- package/src/tokens/index.ts +34 -0
- package/src/tokens/tokenExporter.ts +397 -0
- package/src/tokens/tokenGenerator.ts +276 -0
- package/src/tokens/tokenManager.ts +248 -0
- package/src/tokens/tokenValidator.ts +543 -0
- package/src/tokens/types.ts +78 -0
- package/src/utils/bundle-analyzer.ts +260 -0
- package/src/utils/bundle-splitting.ts +483 -0
- package/src/utils/lazy-loading.ts +441 -0
- package/src/utils/performance-monitor.ts +513 -0
- package/src/utils/tree-shaking.ts +274 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import React, { useState, useCallback, useRef, useEffect, ReactNode, ComponentType } from 'react'
|
|
2
|
+
|
|
3
|
+
export interface ComponentPerformanceConfig {
|
|
4
|
+
enableMemoization?: boolean
|
|
5
|
+
enableLazyLoading?: boolean
|
|
6
|
+
enableVirtualization?: boolean
|
|
7
|
+
enablePerformanceMonitoring?: boolean
|
|
8
|
+
enableAutoOptimization?: boolean
|
|
9
|
+
performanceThreshold?: number
|
|
10
|
+
memoizationThreshold?: number
|
|
11
|
+
virtualizationThreshold?: number
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface PerformanceMetrics {
|
|
15
|
+
renderTime: number
|
|
16
|
+
memoryUsage: number
|
|
17
|
+
reRenderCount: number
|
|
18
|
+
optimizationLevel: 'none' | 'low' | 'medium' | 'high'
|
|
19
|
+
lastOptimization: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface ComponentPerformanceCallbacks {
|
|
23
|
+
onPerformanceWarning?: (metrics: PerformanceMetrics) => void
|
|
24
|
+
onOptimizationApplied?: (type: string, component: string) => void
|
|
25
|
+
onPerformanceImproved?: (improvement: number) => void
|
|
26
|
+
onMemoryWarning?: (usage: number) => void
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const useComponentPerformance = (
|
|
30
|
+
config: ComponentPerformanceConfig = {},
|
|
31
|
+
callbacks: ComponentPerformanceCallbacks = {}
|
|
32
|
+
) => {
|
|
33
|
+
const {
|
|
34
|
+
enableMemoization = true,
|
|
35
|
+
enableLazyLoading = true,
|
|
36
|
+
enableVirtualization = true,
|
|
37
|
+
enablePerformanceMonitoring = true,
|
|
38
|
+
enableAutoOptimization = true,
|
|
39
|
+
performanceThreshold = 16.67, // 60fps target
|
|
40
|
+
memoizationThreshold = 100, // ms
|
|
41
|
+
virtualizationThreshold = 1000 // items
|
|
42
|
+
} = config
|
|
43
|
+
|
|
44
|
+
const [metrics, setMetrics] = useState<PerformanceMetrics>({
|
|
45
|
+
renderTime: 0,
|
|
46
|
+
memoryUsage: 0,
|
|
47
|
+
reRenderCount: 0,
|
|
48
|
+
optimizationLevel: 'none',
|
|
49
|
+
lastOptimization: 'none'
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
const [isOptimizing, setIsOptimizing] = useState(false)
|
|
53
|
+
const [optimizations, setOptimizations] = useState<string[]>([])
|
|
54
|
+
const [memoizedValues] = useState<Map<string, any>>(new Map())
|
|
55
|
+
const [lazyComponents] = useState<Map<string, ComponentType<any>>>(new Map())
|
|
56
|
+
|
|
57
|
+
const renderStartTimeRef = useRef<number>(0)
|
|
58
|
+
const renderCountRef = useRef<number>(0)
|
|
59
|
+
const performanceTimerRef = useRef<number | null>(null)
|
|
60
|
+
const memoryCheckIntervalRef = useRef<number | null>(null)
|
|
61
|
+
|
|
62
|
+
// Performance monitoring
|
|
63
|
+
const startRenderMeasurement = useCallback(() => {
|
|
64
|
+
if (!enablePerformanceMonitoring) return () => {}
|
|
65
|
+
|
|
66
|
+
renderStartTimeRef.current = performance.now()
|
|
67
|
+
renderCountRef.current++
|
|
68
|
+
|
|
69
|
+
return () => {
|
|
70
|
+
const renderTime = performance.now() - renderStartTimeRef.current
|
|
71
|
+
|
|
72
|
+
setMetrics(prev => ({
|
|
73
|
+
...prev,
|
|
74
|
+
renderTime,
|
|
75
|
+
reRenderCount: renderCountRef.current
|
|
76
|
+
}))
|
|
77
|
+
|
|
78
|
+
// Check if optimization is needed
|
|
79
|
+
if (renderTime > performanceThreshold && enableAutoOptimization) {
|
|
80
|
+
suggestOptimizations(renderTime)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}, [enablePerformanceMonitoring, enableAutoOptimization, performanceThreshold])
|
|
84
|
+
|
|
85
|
+
// Memoization optimization
|
|
86
|
+
const memoizeValue = useCallback(<T>(
|
|
87
|
+
key: string,
|
|
88
|
+
value: T,
|
|
89
|
+
dependencies: any[]
|
|
90
|
+
): T => {
|
|
91
|
+
if (!enableMemoization) return value
|
|
92
|
+
|
|
93
|
+
const dependencyKey = JSON.stringify(dependencies)
|
|
94
|
+
const memoKey = `${key}-${dependencyKey}`
|
|
95
|
+
|
|
96
|
+
if (memoizedValues.has(memoKey)) {
|
|
97
|
+
return memoizedValues.get(memoKey)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
memoizedValues.set(memoKey, value)
|
|
101
|
+
|
|
102
|
+
const optimization = `Memoization applied to ${key}`
|
|
103
|
+
setOptimizations(prev => [...prev, optimization])
|
|
104
|
+
callbacks.onOptimizationApplied?.('memoization', key)
|
|
105
|
+
|
|
106
|
+
return value
|
|
107
|
+
}, [enableMemoization, memoizedValues, callbacks])
|
|
108
|
+
|
|
109
|
+
// Lazy loading optimization
|
|
110
|
+
const lazyLoadComponent = useCallback((
|
|
111
|
+
componentId: string,
|
|
112
|
+
componentLoader: () => Promise<{ default: ComponentType<any> }>
|
|
113
|
+
) => {
|
|
114
|
+
if (!enableLazyLoading) return null
|
|
115
|
+
|
|
116
|
+
if (lazyComponents.has(componentId)) {
|
|
117
|
+
return lazyComponents.get(componentId)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const LazyComponent = React.lazy(componentLoader)
|
|
121
|
+
lazyComponents.set(componentId, LazyComponent)
|
|
122
|
+
|
|
123
|
+
const optimization = `Lazy loading applied to ${componentId}`
|
|
124
|
+
setOptimizations(prev => [...prev, optimization])
|
|
125
|
+
callbacks.onOptimizationApplied?.('lazy-loading', componentId)
|
|
126
|
+
|
|
127
|
+
return LazyComponent
|
|
128
|
+
}, [enableLazyLoading, lazyComponents, callbacks])
|
|
129
|
+
|
|
130
|
+
// Virtualization optimization
|
|
131
|
+
const createVirtualizedList = useCallback(<T>(
|
|
132
|
+
items: T[],
|
|
133
|
+
itemHeight: number,
|
|
134
|
+
containerHeight: number,
|
|
135
|
+
renderItem: (item: T, index: number) => ReactNode
|
|
136
|
+
) => {
|
|
137
|
+
if (!enableVirtualization || items.length < virtualizationThreshold) {
|
|
138
|
+
return { type: 'standard', items: items.map((item, index) => renderItem(item, index)) }
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const visibleCount = Math.ceil(containerHeight / itemHeight)
|
|
142
|
+
const startIndex = Math.floor(window.scrollY / itemHeight)
|
|
143
|
+
const endIndex = Math.min(startIndex + visibleCount, items.length)
|
|
144
|
+
|
|
145
|
+
const visibleItems = items.slice(startIndex, endIndex)
|
|
146
|
+
const totalHeight = items.length * itemHeight
|
|
147
|
+
const offsetY = startIndex * itemHeight
|
|
148
|
+
|
|
149
|
+
const optimization = `Virtualization applied to list with ${items.length} items`
|
|
150
|
+
setOptimizations(prev => [...prev, optimization])
|
|
151
|
+
callbacks.onOptimizationApplied?.('virtualization', 'VirtualizedList')
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
type: 'virtualized',
|
|
155
|
+
visibleItems: visibleItems.map((item, index) => renderItem(item, startIndex + index)),
|
|
156
|
+
totalHeight,
|
|
157
|
+
offsetY,
|
|
158
|
+
startIndex,
|
|
159
|
+
endIndex
|
|
160
|
+
}
|
|
161
|
+
}, [enableVirtualization, virtualizationThreshold, callbacks])
|
|
162
|
+
|
|
163
|
+
// Auto-optimization suggestions
|
|
164
|
+
const suggestOptimizations = useCallback((renderTime: number) => {
|
|
165
|
+
const suggestions: string[] = []
|
|
166
|
+
|
|
167
|
+
if (renderTime > memoizationThreshold) {
|
|
168
|
+
suggestions.push('Consider memoization for expensive computations')
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (renderTime > performanceThreshold * 2) {
|
|
172
|
+
suggestions.push('Implement lazy loading for heavy components')
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (renderTime > performanceThreshold * 3) {
|
|
176
|
+
suggestions.push('Use virtualization for large lists')
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (renderTime > performanceThreshold * 4) {
|
|
180
|
+
suggestions.push('Consider code splitting and dynamic imports')
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
setOptimizations(prev => [...prev, ...suggestions])
|
|
184
|
+
}, [memoizationThreshold, performanceThreshold])
|
|
185
|
+
|
|
186
|
+
// Performance analysis
|
|
187
|
+
const analyzePerformance = useCallback(() => {
|
|
188
|
+
const analysis = {
|
|
189
|
+
isOptimized: metrics.optimizationLevel !== 'none',
|
|
190
|
+
needsOptimization: metrics.renderTime > performanceThreshold,
|
|
191
|
+
optimizationScore: Math.max(0, 100 - (metrics.renderTime / performanceThreshold) * 100),
|
|
192
|
+
recommendations: [] as string[]
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (metrics.renderTime > performanceThreshold) {
|
|
196
|
+
analysis.recommendations.push('Render time exceeds 60fps threshold')
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (metrics.reRenderCount > 10) {
|
|
200
|
+
analysis.recommendations.push('High re-render count detected')
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (metrics.memoryUsage > 50) {
|
|
204
|
+
analysis.recommendations.push('High memory usage detected')
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return analysis
|
|
208
|
+
}, [metrics, performanceThreshold])
|
|
209
|
+
|
|
210
|
+
// Memory usage monitoring
|
|
211
|
+
const checkMemoryUsage = useCallback(() => {
|
|
212
|
+
if (!enablePerformanceMonitoring) return
|
|
213
|
+
|
|
214
|
+
try {
|
|
215
|
+
// Simulate memory usage check
|
|
216
|
+
const memoryUsage = Math.random() * 100
|
|
217
|
+
|
|
218
|
+
setMetrics(prev => ({
|
|
219
|
+
...prev,
|
|
220
|
+
memoryUsage
|
|
221
|
+
}))
|
|
222
|
+
|
|
223
|
+
if (memoryUsage > 80) {
|
|
224
|
+
callbacks.onMemoryWarning?.(memoryUsage)
|
|
225
|
+
}
|
|
226
|
+
} catch (error) {
|
|
227
|
+
console.warn('Memory usage check failed:', error)
|
|
228
|
+
}
|
|
229
|
+
}, [enablePerformanceMonitoring, callbacks])
|
|
230
|
+
|
|
231
|
+
// Performance improvement tracking
|
|
232
|
+
const trackImprovement = useCallback((before: number, after: number) => {
|
|
233
|
+
const improvement = ((before - after) / before) * 100
|
|
234
|
+
|
|
235
|
+
if (improvement > 0) {
|
|
236
|
+
callbacks.onPerformanceImproved?.(improvement)
|
|
237
|
+
|
|
238
|
+
setMetrics(prev => ({
|
|
239
|
+
...prev,
|
|
240
|
+
optimizationLevel: improvement > 50 ? 'high' : improvement > 25 ? 'medium' : 'low',
|
|
241
|
+
lastOptimization: `Improved by ${improvement.toFixed(1)}%`
|
|
242
|
+
}))
|
|
243
|
+
}
|
|
244
|
+
}, [callbacks])
|
|
245
|
+
|
|
246
|
+
// Auto-optimization
|
|
247
|
+
const autoOptimize = useCallback((componentId: string) => {
|
|
248
|
+
if (!enableAutoOptimization) return
|
|
249
|
+
|
|
250
|
+
setIsOptimizing(true)
|
|
251
|
+
|
|
252
|
+
setTimeout(() => {
|
|
253
|
+
const optimizations = [
|
|
254
|
+
`Auto-optimization applied to ${componentId}`,
|
|
255
|
+
'Performance monitoring enabled',
|
|
256
|
+
'Memory usage tracking active',
|
|
257
|
+
'Render time optimization applied'
|
|
258
|
+
]
|
|
259
|
+
|
|
260
|
+
setOptimizations(prev => [...prev, ...optimizations])
|
|
261
|
+
setIsOptimizing(false)
|
|
262
|
+
|
|
263
|
+
callbacks.onOptimizationApplied?.('auto-optimization', componentId)
|
|
264
|
+
}, 300)
|
|
265
|
+
}, [enableAutoOptimization, callbacks])
|
|
266
|
+
|
|
267
|
+
// Performance benchmarking
|
|
268
|
+
const benchmarkComponent = useCallback((
|
|
269
|
+
componentId: string,
|
|
270
|
+
benchmarkFn: () => void,
|
|
271
|
+
iterations: number = 100
|
|
272
|
+
) => {
|
|
273
|
+
const startTime = performance.now()
|
|
274
|
+
|
|
275
|
+
for (let i = 0; i < iterations; i++) {
|
|
276
|
+
benchmarkFn()
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const endTime = performance.now()
|
|
280
|
+
const averageTime = (endTime - startTime) / iterations
|
|
281
|
+
|
|
282
|
+
const benchmark = `Benchmark: ${componentId} - ${averageTime.toFixed(2)}ms average`
|
|
283
|
+
setOptimizations(prev => [...prev, benchmark])
|
|
284
|
+
|
|
285
|
+
return averageTime
|
|
286
|
+
}, [])
|
|
287
|
+
|
|
288
|
+
// Initialize performance monitoring
|
|
289
|
+
useEffect(() => {
|
|
290
|
+
if (!enablePerformanceMonitoring) return
|
|
291
|
+
|
|
292
|
+
try {
|
|
293
|
+
performanceTimerRef.current = window.setInterval(() => {
|
|
294
|
+
checkMemoryUsage()
|
|
295
|
+
}, 5000)
|
|
296
|
+
|
|
297
|
+
return () => {
|
|
298
|
+
if (performanceTimerRef.current) {
|
|
299
|
+
clearInterval(performanceTimerRef.current)
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
} catch (error) {
|
|
303
|
+
console.warn('Performance monitoring initialization failed:', error)
|
|
304
|
+
}
|
|
305
|
+
}, [enablePerformanceMonitoring, checkMemoryUsage])
|
|
306
|
+
|
|
307
|
+
// Cleanup on unmount
|
|
308
|
+
useEffect(() => {
|
|
309
|
+
return () => {
|
|
310
|
+
if (memoryCheckIntervalRef.current) {
|
|
311
|
+
clearInterval(memoryCheckIntervalRef.current)
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}, [])
|
|
315
|
+
|
|
316
|
+
return {
|
|
317
|
+
// State
|
|
318
|
+
metrics,
|
|
319
|
+
isOptimizing,
|
|
320
|
+
optimizations,
|
|
321
|
+
|
|
322
|
+
// Performance measurement
|
|
323
|
+
startRenderMeasurement,
|
|
324
|
+
benchmarkComponent,
|
|
325
|
+
|
|
326
|
+
// Optimization functions
|
|
327
|
+
memoizeValue,
|
|
328
|
+
lazyLoadComponent,
|
|
329
|
+
createVirtualizedList,
|
|
330
|
+
autoOptimize,
|
|
331
|
+
|
|
332
|
+
// Analysis
|
|
333
|
+
analyzePerformance,
|
|
334
|
+
trackImprovement,
|
|
335
|
+
|
|
336
|
+
// Utility functions
|
|
337
|
+
isPerformanceOptimized: () => metrics.optimizationLevel !== 'none',
|
|
338
|
+
getOptimizationLevel: () => metrics.optimizationLevel,
|
|
339
|
+
getPerformanceScore: () => Math.max(0, 100 - (metrics.renderTime / performanceThreshold) * 100),
|
|
340
|
+
clearOptimizations: () => setOptimizations([])
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export default useComponentPerformance
|