@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,513 @@
|
|
|
1
|
+
import { useState, useEffect, useCallback, useRef } from 'react'
|
|
2
|
+
|
|
3
|
+
export interface PerformanceConfig {
|
|
4
|
+
enableValidationThrottling: boolean
|
|
5
|
+
enableTouchEventOptimization: boolean
|
|
6
|
+
enableMemoryManagement: boolean
|
|
7
|
+
enableBatteryOptimization: boolean
|
|
8
|
+
validationThrottleDelay: number
|
|
9
|
+
touchEventThrottleDelay: number
|
|
10
|
+
memoryCleanupInterval: number
|
|
11
|
+
performanceMonitoringInterval: number
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface PerformanceCallbacks {
|
|
15
|
+
onPerformanceWarning?: (warning: string, metrics: PerformanceMetrics) => void
|
|
16
|
+
onMemoryWarning?: (usage: number, threshold: number) => void
|
|
17
|
+
onBatteryWarning?: (level: number, isLow: boolean) => void
|
|
18
|
+
onOptimizationApplied?: (type: string, success: boolean) => void
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface PerformanceMetrics {
|
|
22
|
+
validationCount: number
|
|
23
|
+
touchEventCount: number
|
|
24
|
+
memoryUsage: number
|
|
25
|
+
batteryLevel: number
|
|
26
|
+
isLowPowerMode: boolean
|
|
27
|
+
averageResponseTime: number
|
|
28
|
+
lastOptimization: number
|
|
29
|
+
optimizationScore: number
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface FormPerformanceState {
|
|
33
|
+
isOptimized: boolean
|
|
34
|
+
currentOptimizations: string[]
|
|
35
|
+
performanceMetrics: PerformanceMetrics
|
|
36
|
+
warnings: string[]
|
|
37
|
+
lastUpdate: number
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const useFormPerformance = (
|
|
41
|
+
callbacks: PerformanceCallbacks = {},
|
|
42
|
+
config: Partial<PerformanceConfig> = {}
|
|
43
|
+
) => {
|
|
44
|
+
const defaultConfig: PerformanceConfig = {
|
|
45
|
+
enableValidationThrottling: true,
|
|
46
|
+
enableTouchEventOptimization: true,
|
|
47
|
+
enableMemoryManagement: true,
|
|
48
|
+
enableBatteryOptimization: true,
|
|
49
|
+
validationThrottleDelay: 300,
|
|
50
|
+
touchEventThrottleDelay: 16, // ~60fps
|
|
51
|
+
memoryCleanupInterval: 30000, // 30 seconds
|
|
52
|
+
performanceMonitoringInterval: 5000, // 5 seconds
|
|
53
|
+
...config
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const [performanceState, setPerformanceState] = useState<FormPerformanceState>({
|
|
57
|
+
isOptimized: false,
|
|
58
|
+
currentOptimizations: [],
|
|
59
|
+
performanceMetrics: {
|
|
60
|
+
validationCount: 0,
|
|
61
|
+
touchEventCount: 0,
|
|
62
|
+
memoryUsage: 0,
|
|
63
|
+
batteryLevel: 1,
|
|
64
|
+
isLowPowerMode: false,
|
|
65
|
+
averageResponseTime: 0,
|
|
66
|
+
lastOptimization: 0,
|
|
67
|
+
optimizationScore: 0
|
|
68
|
+
},
|
|
69
|
+
warnings: [],
|
|
70
|
+
lastUpdate: Date.now()
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
const validationThrottleTimerRef = useRef<NodeJS.Timeout | null>(null)
|
|
74
|
+
const touchEventThrottleTimerRef = useRef<NodeJS.Timeout | null>(null)
|
|
75
|
+
const memoryCleanupTimerRef = useRef<NodeJS.Timeout | null>(null)
|
|
76
|
+
const performanceMonitorTimerRef = useRef<NodeJS.Timeout | null>(null)
|
|
77
|
+
const batteryLevelRef = useRef<number>(1)
|
|
78
|
+
const isLowPowerModeRef = useRef<boolean>(false)
|
|
79
|
+
|
|
80
|
+
// Check battery status
|
|
81
|
+
const checkBatteryStatus = useCallback(async () => {
|
|
82
|
+
if (!defaultConfig.enableBatteryOptimization || !('getBattery' in navigator)) return
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
const battery = await (navigator as any).getBattery()
|
|
86
|
+
batteryLevelRef.current = battery.level
|
|
87
|
+
isLowPowerModeRef.current = battery.level < 0.2
|
|
88
|
+
|
|
89
|
+
setPerformanceState(prev => ({
|
|
90
|
+
...prev,
|
|
91
|
+
performanceMetrics: {
|
|
92
|
+
...prev.performanceMetrics,
|
|
93
|
+
batteryLevel: battery.level,
|
|
94
|
+
isLowPowerMode: battery.level < 0.2
|
|
95
|
+
}
|
|
96
|
+
}))
|
|
97
|
+
|
|
98
|
+
if (battery.level < 0.2) {
|
|
99
|
+
callbacks.onBatteryWarning?.(battery.level, true)
|
|
100
|
+
}
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.warn('Battery API not supported:', error)
|
|
103
|
+
}
|
|
104
|
+
}, [defaultConfig.enableBatteryOptimization, callbacks])
|
|
105
|
+
|
|
106
|
+
// Check memory usage
|
|
107
|
+
const checkMemoryUsage = useCallback(() => {
|
|
108
|
+
if (!defaultConfig.enableMemoryManagement || !('memory' in performance)) return
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
const memory = (performance as any).memory
|
|
112
|
+
const usage = memory.usedJSHeapSize / memory.jsHeapSizeLimit
|
|
113
|
+
|
|
114
|
+
setPerformanceState(prev => ({
|
|
115
|
+
...prev,
|
|
116
|
+
performanceMetrics: {
|
|
117
|
+
...prev.performanceMetrics,
|
|
118
|
+
memoryUsage: usage
|
|
119
|
+
}
|
|
120
|
+
}))
|
|
121
|
+
|
|
122
|
+
if (usage > 0.8) {
|
|
123
|
+
callbacks.onMemoryWarning?.(usage, 0.8)
|
|
124
|
+
triggerMemoryCleanup()
|
|
125
|
+
}
|
|
126
|
+
} catch (error) {
|
|
127
|
+
console.warn('Memory API not supported:', error)
|
|
128
|
+
}
|
|
129
|
+
}, [defaultConfig.enableMemoryManagement, callbacks])
|
|
130
|
+
|
|
131
|
+
// Trigger memory cleanup
|
|
132
|
+
const triggerMemoryCleanup = useCallback(() => {
|
|
133
|
+
if (!defaultConfig.enableMemoryManagement) return
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
// Force garbage collection if available
|
|
137
|
+
if ('gc' in window) {
|
|
138
|
+
(window as any).gc()
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Clear any cached data
|
|
142
|
+
if ('caches' in window) {
|
|
143
|
+
caches.keys().then(names => {
|
|
144
|
+
names.forEach(name => {
|
|
145
|
+
if (name.includes('form-cache')) {
|
|
146
|
+
caches.delete(name)
|
|
147
|
+
}
|
|
148
|
+
})
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
setPerformanceState(prev => ({
|
|
153
|
+
...prev,
|
|
154
|
+
currentOptimizations: [...prev.currentOptimizations, 'memory-cleanup'],
|
|
155
|
+
lastUpdate: Date.now()
|
|
156
|
+
}))
|
|
157
|
+
|
|
158
|
+
callbacks.onOptimizationApplied?.('memory-cleanup', true)
|
|
159
|
+
} catch (error) {
|
|
160
|
+
console.warn('Memory cleanup failed:', error)
|
|
161
|
+
callbacks.onOptimizationApplied?.('memory-cleanup', false)
|
|
162
|
+
}
|
|
163
|
+
}, [defaultConfig.enableMemoryManagement, callbacks])
|
|
164
|
+
|
|
165
|
+
// Validation throttling
|
|
166
|
+
const throttledValidation = useCallback((
|
|
167
|
+
validationFunction: () => void,
|
|
168
|
+
delay?: number
|
|
169
|
+
) => {
|
|
170
|
+
if (!defaultConfig.enableValidationThrottling) {
|
|
171
|
+
validationFunction()
|
|
172
|
+
return
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const throttleDelay = delay || defaultConfig.validationThrottleDelay
|
|
176
|
+
|
|
177
|
+
if (validationThrottleTimerRef.current) {
|
|
178
|
+
clearTimeout(validationThrottleTimerRef.current)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
validationThrottleTimerRef.current = setTimeout(() => {
|
|
182
|
+
const startTime = performance.now()
|
|
183
|
+
validationFunction()
|
|
184
|
+
const endTime = performance.now()
|
|
185
|
+
const responseTime = endTime - startTime
|
|
186
|
+
|
|
187
|
+
setPerformanceState(prev => ({
|
|
188
|
+
...prev,
|
|
189
|
+
performanceMetrics: {
|
|
190
|
+
...prev.performanceMetrics,
|
|
191
|
+
validationCount: prev.performanceMetrics.validationCount + 1,
|
|
192
|
+
averageResponseTime: (prev.performanceMetrics.averageResponseTime * prev.performanceMetrics.validationCount + responseTime) / (prev.performanceMetrics.validationCount + 1)
|
|
193
|
+
}
|
|
194
|
+
}))
|
|
195
|
+
}, throttleDelay)
|
|
196
|
+
}, [defaultConfig.enableValidationThrottling, defaultConfig.validationThrottleDelay])
|
|
197
|
+
|
|
198
|
+
// Touch event optimization
|
|
199
|
+
const optimizedTouchEvent = useCallback((
|
|
200
|
+
touchFunction: () => void,
|
|
201
|
+
delay?: number
|
|
202
|
+
) => {
|
|
203
|
+
if (!defaultConfig.enableTouchEventOptimization) {
|
|
204
|
+
touchFunction()
|
|
205
|
+
return
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const throttleDelay = delay || defaultConfig.touchEventThrottleDelay
|
|
209
|
+
|
|
210
|
+
if (touchEventThrottleTimerRef.current) {
|
|
211
|
+
clearTimeout(touchEventThrottleTimerRef.current)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
touchEventThrottleTimerRef.current = setTimeout(() => {
|
|
215
|
+
touchFunction()
|
|
216
|
+
|
|
217
|
+
setPerformanceState(prev => ({
|
|
218
|
+
...prev,
|
|
219
|
+
performanceMetrics: {
|
|
220
|
+
...prev.performanceMetrics,
|
|
221
|
+
touchEventCount: prev.performanceMetrics.touchEventCount + 1
|
|
222
|
+
}
|
|
223
|
+
}))
|
|
224
|
+
}, throttleDelay)
|
|
225
|
+
}, [defaultConfig.enableTouchEventOptimization, defaultConfig.touchEventThrottleDelay])
|
|
226
|
+
|
|
227
|
+
// Calculate performance score
|
|
228
|
+
const calculatePerformanceScore = useCallback((): number => {
|
|
229
|
+
const { performanceMetrics } = performanceState
|
|
230
|
+
let score = 0
|
|
231
|
+
|
|
232
|
+
// Response time score (40% weight)
|
|
233
|
+
if (performanceMetrics.averageResponseTime < 50) {
|
|
234
|
+
score += 0.4
|
|
235
|
+
} else if (performanceMetrics.averageResponseTime < 100) {
|
|
236
|
+
score += 0.3
|
|
237
|
+
} else if (performanceMetrics.averageResponseTime < 200) {
|
|
238
|
+
score += 0.2
|
|
239
|
+
} else if (performanceMetrics.averageResponseTime < 500) {
|
|
240
|
+
score += 0.1
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Memory usage score (30% weight)
|
|
244
|
+
if (performanceMetrics.memoryUsage < 0.5) {
|
|
245
|
+
score += 0.3
|
|
246
|
+
} else if (performanceMetrics.memoryUsage < 0.7) {
|
|
247
|
+
score += 0.2
|
|
248
|
+
} else if (performanceMetrics.memoryUsage < 0.9) {
|
|
249
|
+
score += 0.1
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// Battery optimization score (20% weight)
|
|
253
|
+
if (!performanceMetrics.isLowPowerMode) {
|
|
254
|
+
score += 0.2
|
|
255
|
+
} else if (performanceMetrics.batteryLevel > 0.5) {
|
|
256
|
+
score += 0.1
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Event count score (10% weight)
|
|
260
|
+
if (performanceMetrics.touchEventCount < 100) {
|
|
261
|
+
score += 0.1
|
|
262
|
+
} else if (performanceMetrics.touchEventCount < 500) {
|
|
263
|
+
score += 0.05
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return Math.min(score, 1)
|
|
267
|
+
}, [performanceState.performanceMetrics])
|
|
268
|
+
|
|
269
|
+
// Apply performance optimizations
|
|
270
|
+
const applyOptimizations = useCallback(() => {
|
|
271
|
+
const optimizations: string[] = []
|
|
272
|
+
let success = true
|
|
273
|
+
|
|
274
|
+
try {
|
|
275
|
+
// Apply validation throttling
|
|
276
|
+
if (defaultConfig.enableValidationThrottling) {
|
|
277
|
+
optimizations.push('validation-throttling')
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Apply touch event optimization
|
|
281
|
+
if (defaultConfig.enableTouchEventOptimization) {
|
|
282
|
+
optimizations.push('touch-event-optimization')
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// Apply memory management
|
|
286
|
+
if (defaultConfig.enableMemoryManagement) {
|
|
287
|
+
triggerMemoryCleanup()
|
|
288
|
+
optimizations.push('memory-management')
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Apply battery optimization
|
|
292
|
+
if (defaultConfig.enableBatteryOptimization && isLowPowerModeRef.current) {
|
|
293
|
+
// Reduce update frequency in low power mode
|
|
294
|
+
if (performanceMonitorTimerRef.current) {
|
|
295
|
+
clearInterval(performanceMonitorTimerRef.current)
|
|
296
|
+
performanceMonitorTimerRef.current = setInterval(() => {
|
|
297
|
+
checkMemoryUsage()
|
|
298
|
+
}, defaultConfig.performanceMonitoringInterval * 2)
|
|
299
|
+
}
|
|
300
|
+
optimizations.push('battery-optimization')
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const optimizationScore = calculatePerformanceScore()
|
|
304
|
+
const isOptimized = optimizationScore >= 0.7
|
|
305
|
+
|
|
306
|
+
setPerformanceState(prev => ({
|
|
307
|
+
...prev,
|
|
308
|
+
isOptimized,
|
|
309
|
+
currentOptimizations: optimizations,
|
|
310
|
+
performanceMetrics: {
|
|
311
|
+
...prev.performanceMetrics,
|
|
312
|
+
optimizationScore,
|
|
313
|
+
lastOptimization: Date.now()
|
|
314
|
+
},
|
|
315
|
+
lastUpdate: Date.now()
|
|
316
|
+
}))
|
|
317
|
+
|
|
318
|
+
callbacks.onOptimizationApplied?.('performance', success)
|
|
319
|
+
} catch (error) {
|
|
320
|
+
console.error('Performance optimization failed:', error)
|
|
321
|
+
success = false
|
|
322
|
+
callbacks.onOptimizationApplied?.('performance', false)
|
|
323
|
+
}
|
|
324
|
+
}, [
|
|
325
|
+
defaultConfig,
|
|
326
|
+
triggerMemoryCleanup,
|
|
327
|
+
calculatePerformanceScore,
|
|
328
|
+
callbacks
|
|
329
|
+
])
|
|
330
|
+
|
|
331
|
+
// Monitor performance
|
|
332
|
+
const startPerformanceMonitoring = useCallback(() => {
|
|
333
|
+
if (performanceMonitorTimerRef.current) {
|
|
334
|
+
clearInterval(performanceMonitorTimerRef.current)
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
performanceMonitorTimerRef.current = setInterval(() => {
|
|
338
|
+
checkMemoryUsage()
|
|
339
|
+
checkBatteryStatus()
|
|
340
|
+
|
|
341
|
+
const score = calculatePerformanceScore()
|
|
342
|
+
if (score < 0.5) {
|
|
343
|
+
const warning = `Performance score is low: ${(score * 100).toFixed(1)}%`
|
|
344
|
+
setPerformanceState(prev => ({
|
|
345
|
+
...prev,
|
|
346
|
+
warnings: [...prev.warnings, warning]
|
|
347
|
+
}))
|
|
348
|
+
callbacks.onPerformanceWarning?.(warning, performanceState.performanceMetrics)
|
|
349
|
+
}
|
|
350
|
+
}, defaultConfig.performanceMonitoringInterval)
|
|
351
|
+
}, [
|
|
352
|
+
defaultConfig.performanceMonitoringInterval,
|
|
353
|
+
checkMemoryUsage,
|
|
354
|
+
checkBatteryStatus,
|
|
355
|
+
calculatePerformanceScore,
|
|
356
|
+
performanceState.performanceMetrics,
|
|
357
|
+
callbacks
|
|
358
|
+
])
|
|
359
|
+
|
|
360
|
+
// Stop performance monitoring
|
|
361
|
+
const stopPerformanceMonitoring = useCallback(() => {
|
|
362
|
+
if (performanceMonitorTimerRef.current) {
|
|
363
|
+
clearInterval(performanceMonitorTimerRef.current)
|
|
364
|
+
performanceMonitorTimerRef.current = null
|
|
365
|
+
}
|
|
366
|
+
}, [])
|
|
367
|
+
|
|
368
|
+
// Reset performance state
|
|
369
|
+
const resetPerformance = useCallback(() => {
|
|
370
|
+
setPerformanceState({
|
|
371
|
+
isOptimized: false,
|
|
372
|
+
currentOptimizations: [],
|
|
373
|
+
performanceMetrics: {
|
|
374
|
+
validationCount: 0,
|
|
375
|
+
touchEventCount: 0,
|
|
376
|
+
memoryUsage: 0,
|
|
377
|
+
batteryLevel: 1,
|
|
378
|
+
isLowPowerMode: false,
|
|
379
|
+
averageResponseTime: 0,
|
|
380
|
+
lastOptimization: 0,
|
|
381
|
+
optimizationScore: 0
|
|
382
|
+
},
|
|
383
|
+
warnings: [],
|
|
384
|
+
lastUpdate: Date.now()
|
|
385
|
+
})
|
|
386
|
+
}, [])
|
|
387
|
+
|
|
388
|
+
// Get performance report
|
|
389
|
+
const getPerformanceReport = useCallback(() => {
|
|
390
|
+
const { performanceMetrics, currentOptimizations, warnings } = performanceState
|
|
391
|
+
|
|
392
|
+
return {
|
|
393
|
+
metrics: performanceMetrics,
|
|
394
|
+
optimizations: currentOptimizations,
|
|
395
|
+
warnings,
|
|
396
|
+
recommendations: getPerformanceRecommendations()
|
|
397
|
+
}
|
|
398
|
+
}, [performanceState])
|
|
399
|
+
|
|
400
|
+
// Get performance recommendations
|
|
401
|
+
const getPerformanceRecommendations = useCallback(() => {
|
|
402
|
+
const { performanceMetrics } = performanceState
|
|
403
|
+
const recommendations: string[] = []
|
|
404
|
+
|
|
405
|
+
if (performanceMetrics.averageResponseTime > 200) {
|
|
406
|
+
recommendations.push('Consider increasing validation throttle delay')
|
|
407
|
+
recommendations.push('Optimize validation logic for better performance')
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
if (performanceMetrics.memoryUsage > 0.7) {
|
|
411
|
+
recommendations.push('Enable memory cleanup more frequently')
|
|
412
|
+
recommendations.push('Reduce cached data size')
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
if (performanceMetrics.isLowPowerMode) {
|
|
416
|
+
recommendations.push('Reduce update frequency in low power mode')
|
|
417
|
+
recommendations.push('Disable non-essential optimizations')
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
if (performanceMetrics.touchEventCount > 500) {
|
|
421
|
+
recommendations.push('Increase touch event throttle delay')
|
|
422
|
+
recommendations.push('Consider debouncing touch events')
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
return recommendations
|
|
426
|
+
}, [performanceState.performanceMetrics])
|
|
427
|
+
|
|
428
|
+
// Set up initial monitoring
|
|
429
|
+
useEffect(() => {
|
|
430
|
+
checkBatteryStatus()
|
|
431
|
+
checkMemoryUsage()
|
|
432
|
+
startPerformanceMonitoring()
|
|
433
|
+
|
|
434
|
+
return () => {
|
|
435
|
+
stopPerformanceMonitoring()
|
|
436
|
+
}
|
|
437
|
+
}, [checkBatteryStatus, checkMemoryUsage, startPerformanceMonitoring, stopPerformanceMonitoring])
|
|
438
|
+
|
|
439
|
+
// Set up memory cleanup interval
|
|
440
|
+
useEffect(() => {
|
|
441
|
+
if (defaultConfig.enableMemoryManagement) {
|
|
442
|
+
memoryCleanupTimerRef.current = setInterval(() => {
|
|
443
|
+
checkMemoryUsage()
|
|
444
|
+
}, defaultConfig.memoryCleanupInterval)
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
return () => {
|
|
448
|
+
if (memoryCleanupTimerRef.current) {
|
|
449
|
+
clearInterval(memoryCleanupTimerRef.current)
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
}, [defaultConfig.enableMemoryManagement, defaultConfig.memoryCleanupInterval, checkMemoryUsage])
|
|
453
|
+
|
|
454
|
+
// Clean up timers on unmount
|
|
455
|
+
useEffect(() => {
|
|
456
|
+
return () => {
|
|
457
|
+
if (validationThrottleTimerRef.current) {
|
|
458
|
+
clearTimeout(validationThrottleTimerRef.current)
|
|
459
|
+
}
|
|
460
|
+
if (touchEventThrottleTimerRef.current) {
|
|
461
|
+
clearTimeout(touchEventThrottleTimerRef.current)
|
|
462
|
+
}
|
|
463
|
+
if (memoryCleanupTimerRef.current) {
|
|
464
|
+
clearInterval(memoryCleanupTimerRef.current)
|
|
465
|
+
}
|
|
466
|
+
if (performanceMonitorTimerRef.current) {
|
|
467
|
+
clearInterval(performanceMonitorTimerRef.current)
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}, [])
|
|
471
|
+
|
|
472
|
+
return {
|
|
473
|
+
performanceState,
|
|
474
|
+
throttledValidation,
|
|
475
|
+
optimizedTouchEvent,
|
|
476
|
+
applyOptimizations,
|
|
477
|
+
startPerformanceMonitoring,
|
|
478
|
+
stopPerformanceMonitoring,
|
|
479
|
+
resetPerformance,
|
|
480
|
+
getPerformanceReport,
|
|
481
|
+
getPerformanceRecommendations,
|
|
482
|
+
checkMemoryUsage,
|
|
483
|
+
checkBatteryStatus
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
// Convenience hook for basic performance optimization
|
|
488
|
+
export const useBasicFormPerformance = () => {
|
|
489
|
+
return useFormPerformance({}, {
|
|
490
|
+
enableValidationThrottling: true,
|
|
491
|
+
enableTouchEventOptimization: false,
|
|
492
|
+
enableMemoryManagement: false,
|
|
493
|
+
enableBatteryOptimization: false,
|
|
494
|
+
validationThrottleDelay: 500,
|
|
495
|
+
touchEventThrottleDelay: 32,
|
|
496
|
+
memoryCleanupInterval: 60000,
|
|
497
|
+
performanceMonitoringInterval: 10000
|
|
498
|
+
})
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// Convenience hook for enhanced performance optimization
|
|
502
|
+
export const useEnhancedFormPerformance = () => {
|
|
503
|
+
return useFormPerformance({}, {
|
|
504
|
+
enableValidationThrottling: true,
|
|
505
|
+
enableTouchEventOptimization: true,
|
|
506
|
+
enableMemoryManagement: true,
|
|
507
|
+
enableBatteryOptimization: true,
|
|
508
|
+
validationThrottleDelay: 300,
|
|
509
|
+
touchEventThrottleDelay: 16,
|
|
510
|
+
memoryCleanupInterval: 30000,
|
|
511
|
+
performanceMonitoringInterval: 5000
|
|
512
|
+
})
|
|
513
|
+
}
|