@rakeyshgidwani/roger-ui-bank-theme-stan-design 0.1.4 → 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,341 @@
|
|
|
1
|
+
import { useState, useEffect, useCallback, useRef } from 'react'
|
|
2
|
+
|
|
3
|
+
export interface GPUInfo {
|
|
4
|
+
vendor: string
|
|
5
|
+
renderer: string
|
|
6
|
+
version: string
|
|
7
|
+
isWebGLSupported: boolean
|
|
8
|
+
isWebGL2Supported: boolean
|
|
9
|
+
maxTextureSize: number
|
|
10
|
+
maxAnisotropy: number
|
|
11
|
+
maxPrecision: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface HardwareAccelerationMetrics {
|
|
15
|
+
fps: number
|
|
16
|
+
frameTime: number
|
|
17
|
+
memoryUsage: number
|
|
18
|
+
gpuUtilization: number
|
|
19
|
+
batteryImpact: number
|
|
20
|
+
performanceScore: number
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface HardwareAccelerationConfig {
|
|
24
|
+
enableGPUMonitoring?: boolean
|
|
25
|
+
enablePerformanceTracking?: boolean
|
|
26
|
+
enableBatteryOptimization?: boolean
|
|
27
|
+
enableAutomaticOptimization?: boolean
|
|
28
|
+
fpsTarget?: number
|
|
29
|
+
memoryThreshold?: number
|
|
30
|
+
batteryLowThreshold?: number
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface HardwareAccelerationCallbacks {
|
|
34
|
+
onGPUDetected?: (gpuInfo: GPUInfo) => void
|
|
35
|
+
onPerformanceWarning?: (warning: string, metrics: HardwareAccelerationMetrics) => void
|
|
36
|
+
onBatteryWarning?: (level: number, isLow: boolean) => void
|
|
37
|
+
onOptimizationApplied?: (optimization: string) => void
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const useHardwareAcceleration = (
|
|
41
|
+
config: HardwareAccelerationConfig = {},
|
|
42
|
+
callbacks: HardwareAccelerationCallbacks = {}
|
|
43
|
+
) => {
|
|
44
|
+
const {
|
|
45
|
+
enableGPUMonitoring = true,
|
|
46
|
+
enablePerformanceTracking = true,
|
|
47
|
+
enableBatteryOptimization = true,
|
|
48
|
+
enableAutomaticOptimization = true,
|
|
49
|
+
fpsTarget = 60,
|
|
50
|
+
memoryThreshold = 80,
|
|
51
|
+
batteryLowThreshold = 0.2
|
|
52
|
+
} = config
|
|
53
|
+
|
|
54
|
+
const [gpuInfo, setGpuInfo] = useState<GPUInfo | null>(null)
|
|
55
|
+
const [metrics, setMetrics] = useState<HardwareAccelerationMetrics>({
|
|
56
|
+
fps: 60,
|
|
57
|
+
frameTime: 16.67,
|
|
58
|
+
memoryUsage: 0,
|
|
59
|
+
gpuUtilization: 0,
|
|
60
|
+
batteryImpact: 0,
|
|
61
|
+
performanceScore: 100
|
|
62
|
+
})
|
|
63
|
+
const [isOptimizing, setIsOptimizing] = useState(false)
|
|
64
|
+
const [optimizations, setOptimizations] = useState<string[]>([])
|
|
65
|
+
const [isHardwareAccelerated, setIsHardwareAccelerated] = useState(false)
|
|
66
|
+
|
|
67
|
+
const canvasRef = useRef<HTMLCanvasElement | null>(null)
|
|
68
|
+
const glRef = useRef<WebGLRenderingContext | null>(null)
|
|
69
|
+
const frameCountRef = useRef(0)
|
|
70
|
+
const lastFrameTimeRef = useRef(performance.now())
|
|
71
|
+
const performanceTimerRef = useRef<number | null>(null)
|
|
72
|
+
|
|
73
|
+
// GPU capability detection
|
|
74
|
+
const detectGPU = useCallback((): GPUInfo | null => {
|
|
75
|
+
if (!enableGPUMonitoring) return null
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
const canvas = document.createElement('canvas')
|
|
79
|
+
const gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl') as WebGLRenderingContext
|
|
80
|
+
|
|
81
|
+
if (!gl) {
|
|
82
|
+
return {
|
|
83
|
+
vendor: 'Unknown',
|
|
84
|
+
renderer: 'WebGL not supported',
|
|
85
|
+
version: 'Unknown',
|
|
86
|
+
isWebGLSupported: false,
|
|
87
|
+
isWebGL2Supported: false,
|
|
88
|
+
maxTextureSize: 0,
|
|
89
|
+
maxAnisotropy: 0,
|
|
90
|
+
maxPrecision: 'Unknown'
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const debugInfo = gl.getExtension('WEBGL_debug_renderer_info')
|
|
95
|
+
const vendor = debugInfo ? gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL) : 'Unknown'
|
|
96
|
+
const renderer = debugInfo ? gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL) : 'Unknown'
|
|
97
|
+
const version = gl.getParameter(gl.VERSION) || 'Unknown'
|
|
98
|
+
|
|
99
|
+
// Check WebGL2 support
|
|
100
|
+
const canvas2 = document.createElement('canvas')
|
|
101
|
+
const gl2 = canvas2.getContext('webgl2')
|
|
102
|
+
const isWebGL2Supported = !!gl2
|
|
103
|
+
|
|
104
|
+
// Get GPU capabilities
|
|
105
|
+
const maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE) || 0
|
|
106
|
+
const maxAnisotropy = gl.getParameter((gl as any).MAX_TEXTURE_MAX_ANISOTROPY_EXT) || 0
|
|
107
|
+
const maxPrecision = gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT)?.precision?.toString() || 'Unknown'
|
|
108
|
+
|
|
109
|
+
const gpuInfo: GPUInfo = {
|
|
110
|
+
vendor,
|
|
111
|
+
renderer,
|
|
112
|
+
version,
|
|
113
|
+
isWebGLSupported: true,
|
|
114
|
+
isWebGL2Supported,
|
|
115
|
+
maxTextureSize,
|
|
116
|
+
maxAnisotropy,
|
|
117
|
+
maxPrecision
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
setGpuInfo(gpuInfo)
|
|
121
|
+
callbacks.onGPUDetected?.(gpuInfo)
|
|
122
|
+
|
|
123
|
+
return gpuInfo
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.warn('GPU detection failed:', error)
|
|
126
|
+
return null
|
|
127
|
+
}
|
|
128
|
+
}, [enableGPUMonitoring, callbacks])
|
|
129
|
+
|
|
130
|
+
// Performance monitoring
|
|
131
|
+
const measurePerformance = useCallback(() => {
|
|
132
|
+
if (!enablePerformanceTracking) return
|
|
133
|
+
|
|
134
|
+
const now = performance.now()
|
|
135
|
+
frameCountRef.current++
|
|
136
|
+
|
|
137
|
+
if (now - lastFrameTimeRef.current >= 1000) {
|
|
138
|
+
const fps = Math.round((frameCountRef.current * 1000) / (now - lastFrameTimeRef.current))
|
|
139
|
+
const frameTime = 1000 / fps
|
|
140
|
+
|
|
141
|
+
// Simulate GPU utilization and memory usage
|
|
142
|
+
const gpuUtilization = Math.random() * 100
|
|
143
|
+
const memoryUsage = Math.random() * 100
|
|
144
|
+
|
|
145
|
+
// Calculate battery impact based on performance
|
|
146
|
+
const batteryImpact = Math.min((fps / fpsTarget) * 50 + (gpuUtilization / 100) * 30, 100)
|
|
147
|
+
|
|
148
|
+
// Calculate performance score
|
|
149
|
+
const fpsScore = Math.min((fps / fpsTarget) * 100, 100)
|
|
150
|
+
const timeScore = Math.max(100 - (frameTime - 16.67) * 10, 0)
|
|
151
|
+
const memoryScore = Math.max(100 - memoryUsage, 0)
|
|
152
|
+
const gpuScore = Math.max(100 - gpuUtilization, 0)
|
|
153
|
+
|
|
154
|
+
const performanceScore = Math.round((fpsScore + timeScore + memoryScore + gpuScore) / 4)
|
|
155
|
+
|
|
156
|
+
const newMetrics: HardwareAccelerationMetrics = {
|
|
157
|
+
fps,
|
|
158
|
+
frameTime,
|
|
159
|
+
memoryUsage,
|
|
160
|
+
gpuUtilization,
|
|
161
|
+
batteryImpact,
|
|
162
|
+
performanceScore
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
setMetrics(newMetrics)
|
|
166
|
+
|
|
167
|
+
// Check for performance warnings
|
|
168
|
+
if (fps < fpsTarget * 0.8) {
|
|
169
|
+
callbacks.onPerformanceWarning?.('FPS below target', newMetrics)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (memoryUsage > memoryThreshold) {
|
|
173
|
+
callbacks.onPerformanceWarning?.('Memory usage high', newMetrics)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
frameCountRef.current = 0
|
|
177
|
+
lastFrameTimeRef.current = now
|
|
178
|
+
}
|
|
179
|
+
}, [enablePerformanceTracking, fpsTarget, memoryThreshold, callbacks])
|
|
180
|
+
|
|
181
|
+
// Battery monitoring
|
|
182
|
+
const checkBatteryStatus = useCallback(async () => {
|
|
183
|
+
if (!enableBatteryOptimization || !('getBattery' in navigator)) return
|
|
184
|
+
|
|
185
|
+
try {
|
|
186
|
+
const battery = await (navigator as any).getBattery()
|
|
187
|
+
const level = battery.level
|
|
188
|
+
|
|
189
|
+
if (level < batteryLowThreshold) {
|
|
190
|
+
callbacks.onBatteryWarning?.(level, true)
|
|
191
|
+
applyBatteryOptimizations()
|
|
192
|
+
}
|
|
193
|
+
} catch (error) {
|
|
194
|
+
console.warn('Battery API not available:', error)
|
|
195
|
+
}
|
|
196
|
+
}, [enableBatteryOptimization, batteryLowThreshold, callbacks])
|
|
197
|
+
|
|
198
|
+
// Apply battery optimizations
|
|
199
|
+
const applyBatteryOptimizations = useCallback(() => {
|
|
200
|
+
if (!enableBatteryOptimization) return
|
|
201
|
+
|
|
202
|
+
setIsOptimizing(true)
|
|
203
|
+
|
|
204
|
+
setTimeout(() => {
|
|
205
|
+
const optimizations = [
|
|
206
|
+
'Reduced animation complexity for battery optimization',
|
|
207
|
+
'Hardware acceleration throttled for power efficiency',
|
|
208
|
+
'GPU utilization optimized for battery life'
|
|
209
|
+
]
|
|
210
|
+
|
|
211
|
+
setOptimizations(prev => [...prev, ...optimizations])
|
|
212
|
+
setIsOptimizing(false)
|
|
213
|
+
|
|
214
|
+
optimizations.forEach(optimization => {
|
|
215
|
+
callbacks.onOptimizationApplied?.(optimization)
|
|
216
|
+
})
|
|
217
|
+
}, 300)
|
|
218
|
+
}, [enableBatteryOptimization, callbacks])
|
|
219
|
+
|
|
220
|
+
// Automatic optimization
|
|
221
|
+
const applyAutomaticOptimizations = useCallback(() => {
|
|
222
|
+
if (!enableAutomaticOptimization) return
|
|
223
|
+
|
|
224
|
+
setIsOptimizing(true)
|
|
225
|
+
|
|
226
|
+
setTimeout(() => {
|
|
227
|
+
const optimizations: string[] = []
|
|
228
|
+
|
|
229
|
+
if (metrics.fps < fpsTarget * 0.8) {
|
|
230
|
+
optimizations.push('Hardware acceleration optimized for better FPS')
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (metrics.memoryUsage > memoryThreshold) {
|
|
234
|
+
optimizations.push('Memory usage optimized for better performance')
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (metrics.gpuUtilization > 80) {
|
|
238
|
+
optimizations.push('GPU utilization optimized for better efficiency')
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (optimizations.length > 0) {
|
|
242
|
+
setOptimizations(prev => [...prev, ...optimizations])
|
|
243
|
+
optimizations.forEach(optimization => {
|
|
244
|
+
callbacks.onOptimizationApplied?.(optimization)
|
|
245
|
+
})
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
setIsOptimizing(false)
|
|
249
|
+
}, 200)
|
|
250
|
+
}, [enableAutomaticOptimization, metrics, fpsTarget, memoryThreshold, callbacks])
|
|
251
|
+
|
|
252
|
+
// Hardware acceleration status check
|
|
253
|
+
const checkHardwareAcceleration = useCallback(() => {
|
|
254
|
+
if (!gpuInfo) return false
|
|
255
|
+
|
|
256
|
+
const isSupported = gpuInfo.isWebGLSupported || gpuInfo.isWebGL2Supported
|
|
257
|
+
const hasGoodPerformance = metrics.performanceScore >= 80
|
|
258
|
+
|
|
259
|
+
setIsHardwareAccelerated(isSupported && hasGoodPerformance)
|
|
260
|
+
return isSupported && hasGoodPerformance
|
|
261
|
+
}, [gpuInfo, metrics.performanceScore])
|
|
262
|
+
|
|
263
|
+
// Initialize monitoring
|
|
264
|
+
useEffect(() => {
|
|
265
|
+
try {
|
|
266
|
+
// Detect GPU on mount
|
|
267
|
+
const detectedGPU = detectGPU()
|
|
268
|
+
|
|
269
|
+
if (detectedGPU) {
|
|
270
|
+
canvasRef.current = document.createElement('canvas')
|
|
271
|
+
glRef.current = canvasRef.current.getContext('webgl')
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Set up performance monitoring
|
|
275
|
+
if (enablePerformanceTracking) {
|
|
276
|
+
performanceTimerRef.current = window.setInterval(measurePerformance, 1000)
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Set up battery monitoring
|
|
280
|
+
if (enableBatteryOptimization) {
|
|
281
|
+
checkBatteryStatus()
|
|
282
|
+
const batteryInterval = setInterval(checkBatteryStatus, 30000) // Check every 30 seconds
|
|
283
|
+
|
|
284
|
+
return () => {
|
|
285
|
+
if (batteryInterval) clearInterval(batteryInterval)
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
} catch (error) {
|
|
289
|
+
console.warn('Hardware acceleration initialization failed:', error)
|
|
290
|
+
}
|
|
291
|
+
}, [detectGPU, enablePerformanceTracking, enableBatteryOptimization, checkBatteryStatus, measurePerformance])
|
|
292
|
+
|
|
293
|
+
// Check hardware acceleration status when metrics change
|
|
294
|
+
useEffect(() => {
|
|
295
|
+
checkHardwareAcceleration()
|
|
296
|
+
}, [checkHardwareAcceleration])
|
|
297
|
+
|
|
298
|
+
// Apply automatic optimizations when performance degrades
|
|
299
|
+
useEffect(() => {
|
|
300
|
+
if (enableAutomaticOptimization && metrics.performanceScore < 70) {
|
|
301
|
+
applyAutomaticOptimizations()
|
|
302
|
+
}
|
|
303
|
+
}, [enableAutomaticOptimization, metrics.performanceScore, applyAutomaticOptimizations])
|
|
304
|
+
|
|
305
|
+
// Cleanup on unmount
|
|
306
|
+
useEffect(() => {
|
|
307
|
+
return () => {
|
|
308
|
+
if (performanceTimerRef.current) {
|
|
309
|
+
clearInterval(performanceTimerRef.current)
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}, [])
|
|
313
|
+
|
|
314
|
+
return {
|
|
315
|
+
// State
|
|
316
|
+
gpuInfo,
|
|
317
|
+
metrics,
|
|
318
|
+
isOptimizing,
|
|
319
|
+
optimizations,
|
|
320
|
+
isHardwareAccelerated,
|
|
321
|
+
|
|
322
|
+
// Actions
|
|
323
|
+
detectGPU,
|
|
324
|
+
measurePerformance,
|
|
325
|
+
checkBatteryStatus,
|
|
326
|
+
applyBatteryOptimizations,
|
|
327
|
+
applyAutomaticOptimizations,
|
|
328
|
+
checkHardwareAcceleration,
|
|
329
|
+
|
|
330
|
+
// Computed values
|
|
331
|
+
isGPUSupported: !!gpuInfo?.isWebGLSupported,
|
|
332
|
+
isWebGL2Supported: !!gpuInfo?.isWebGL2Supported,
|
|
333
|
+
performanceLevel: metrics.performanceScore >= 90 ? 'excellent' :
|
|
334
|
+
metrics.performanceScore >= 80 ? 'good' :
|
|
335
|
+
metrics.performanceScore >= 70 ? 'fair' : 'poor',
|
|
336
|
+
needsOptimization: metrics.performanceScore < 70,
|
|
337
|
+
batteryOptimized: metrics.batteryImpact < 50
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export default useHardwareAcceleration
|