@rakeyshgidwani/roger-ui-bank-theme-stan-design 0.1.4 → 0.1.6
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,384 @@
|
|
|
1
|
+
import { useState, useEffect, useCallback, useRef } from 'react'
|
|
2
|
+
|
|
3
|
+
export interface BatteryAnimationConfig {
|
|
4
|
+
enableBatteryMonitoring?: boolean
|
|
5
|
+
enablePerformanceThrottling?: boolean
|
|
6
|
+
enableReducedMotion?: boolean
|
|
7
|
+
enableUserPreferences?: boolean
|
|
8
|
+
enableAutomaticOptimization?: boolean
|
|
9
|
+
lowBatteryThreshold?: number
|
|
10
|
+
criticalBatteryThreshold?: number
|
|
11
|
+
performanceThrottleThreshold?: number
|
|
12
|
+
animationComplexityLevels?: 'low' | 'medium' | 'high'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface BatteryAnimationState {
|
|
16
|
+
batteryLevel: number
|
|
17
|
+
isLowBattery: boolean
|
|
18
|
+
isCriticalBattery: boolean
|
|
19
|
+
isCharging: boolean
|
|
20
|
+
performanceScore: number
|
|
21
|
+
shouldThrottle: boolean
|
|
22
|
+
throttleLevel: 'none' | 'light' | 'moderate' | 'aggressive'
|
|
23
|
+
reducedMotion: boolean
|
|
24
|
+
userPreference: 'performance' | 'balanced' | 'battery' | 'accessibility'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface BatteryAnimationCallbacks {
|
|
28
|
+
onBatteryLevelChange?: (level: number, isLow: boolean) => void
|
|
29
|
+
onPerformanceWarning?: (score: number, shouldThrottle: boolean) => void
|
|
30
|
+
onAnimationThrottled?: (level: string, reason: string) => void
|
|
31
|
+
onUserPreferenceChange?: (preference: string) => void
|
|
32
|
+
onReducedMotionChange?: (enabled: boolean) => void
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const useBatteryAnimations = (
|
|
36
|
+
config: BatteryAnimationConfig = {},
|
|
37
|
+
callbacks: BatteryAnimationCallbacks = {}
|
|
38
|
+
) => {
|
|
39
|
+
const {
|
|
40
|
+
enableBatteryMonitoring = true,
|
|
41
|
+
enablePerformanceThrottling = true,
|
|
42
|
+
enableReducedMotion = true,
|
|
43
|
+
enableUserPreferences = true,
|
|
44
|
+
enableAutomaticOptimization = true,
|
|
45
|
+
lowBatteryThreshold = 0.2,
|
|
46
|
+
criticalBatteryThreshold = 0.1,
|
|
47
|
+
performanceThrottleThreshold = 70
|
|
48
|
+
} = config
|
|
49
|
+
|
|
50
|
+
const [state, setState] = useState<BatteryAnimationState>({
|
|
51
|
+
batteryLevel: 1,
|
|
52
|
+
isLowBattery: false,
|
|
53
|
+
isCriticalBattery: false,
|
|
54
|
+
isCharging: false,
|
|
55
|
+
performanceScore: 100,
|
|
56
|
+
shouldThrottle: false,
|
|
57
|
+
throttleLevel: 'none',
|
|
58
|
+
reducedMotion: false,
|
|
59
|
+
userPreference: 'balanced'
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const [isOptimizing, setIsOptimizing] = useState(false)
|
|
63
|
+
const [optimizations, setOptimizations] = useState<string[]>([])
|
|
64
|
+
const batteryRef = useRef<any>(null)
|
|
65
|
+
const performanceTimerRef = useRef<number | null>(null)
|
|
66
|
+
const batteryCheckIntervalRef = useRef<number | null>(null)
|
|
67
|
+
|
|
68
|
+
// Battery level detection
|
|
69
|
+
const getBatteryStatus = useCallback(async (): Promise<void> => {
|
|
70
|
+
if (!enableBatteryMonitoring || !('getBattery' in navigator)) return
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
const battery = await (navigator as any).getBattery()
|
|
74
|
+
batteryRef.current = battery
|
|
75
|
+
|
|
76
|
+
const batteryLevel = battery.level
|
|
77
|
+
const isCharging = battery.charging
|
|
78
|
+
const isLowBattery = batteryLevel <= lowBatteryThreshold
|
|
79
|
+
const isCriticalBattery = batteryLevel <= criticalBatteryThreshold
|
|
80
|
+
|
|
81
|
+
setState(prev => ({
|
|
82
|
+
...prev,
|
|
83
|
+
batteryLevel,
|
|
84
|
+
isLowBattery,
|
|
85
|
+
isCriticalBattery,
|
|
86
|
+
isCharging
|
|
87
|
+
}))
|
|
88
|
+
|
|
89
|
+
callbacks.onBatteryLevelChange?.(batteryLevel, isLowBattery)
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.warn('Battery API not available:', error)
|
|
92
|
+
}
|
|
93
|
+
}, [enableBatteryMonitoring, lowBatteryThreshold, criticalBatteryThreshold, callbacks])
|
|
94
|
+
|
|
95
|
+
// Performance monitoring
|
|
96
|
+
const measurePerformance = useCallback(() => {
|
|
97
|
+
if (!enablePerformanceThrottling) return
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
// Simulate performance measurement
|
|
101
|
+
const performanceScore = Math.random() * 100
|
|
102
|
+
const shouldThrottle = performanceScore < performanceThrottleThreshold
|
|
103
|
+
|
|
104
|
+
setState(prev => ({
|
|
105
|
+
...prev,
|
|
106
|
+
performanceScore,
|
|
107
|
+
shouldThrottle
|
|
108
|
+
}))
|
|
109
|
+
|
|
110
|
+
if (shouldThrottle) {
|
|
111
|
+
callbacks.onPerformanceWarning?.(performanceScore, shouldThrottle)
|
|
112
|
+
}
|
|
113
|
+
} catch (error) {
|
|
114
|
+
console.warn('Performance measurement failed:', error)
|
|
115
|
+
}
|
|
116
|
+
}, [enablePerformanceThrottling, performanceThrottleThreshold, callbacks])
|
|
117
|
+
|
|
118
|
+
// Reduced motion detection
|
|
119
|
+
const checkReducedMotion = useCallback(() => {
|
|
120
|
+
if (!enableReducedMotion) return
|
|
121
|
+
|
|
122
|
+
try {
|
|
123
|
+
const reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches
|
|
124
|
+
|
|
125
|
+
setState(prev => ({
|
|
126
|
+
...prev,
|
|
127
|
+
reducedMotion
|
|
128
|
+
}))
|
|
129
|
+
|
|
130
|
+
callbacks.onReducedMotionChange?.(reducedMotion)
|
|
131
|
+
} catch (error) {
|
|
132
|
+
console.warn('Reduced motion detection failed:', error)
|
|
133
|
+
}
|
|
134
|
+
}, [enableReducedMotion, callbacks])
|
|
135
|
+
|
|
136
|
+
// Animation throttling based on battery and performance
|
|
137
|
+
const applyAnimationThrottling = useCallback(() => {
|
|
138
|
+
if (!enablePerformanceThrottling) return
|
|
139
|
+
|
|
140
|
+
setIsOptimizing(true)
|
|
141
|
+
|
|
142
|
+
setTimeout(() => {
|
|
143
|
+
let throttleLevel: 'none' | 'light' | 'moderate' | 'aggressive' = 'none'
|
|
144
|
+
let optimizations: string[] = []
|
|
145
|
+
|
|
146
|
+
// Battery-based throttling
|
|
147
|
+
if (state.isCriticalBattery) {
|
|
148
|
+
throttleLevel = 'aggressive'
|
|
149
|
+
optimizations.push('Critical battery: Maximum animation throttling applied')
|
|
150
|
+
optimizations.push('All non-essential animations disabled')
|
|
151
|
+
optimizations.push('Only essential UI transitions enabled')
|
|
152
|
+
} else if (state.isLowBattery) {
|
|
153
|
+
throttleLevel = 'moderate'
|
|
154
|
+
optimizations.push('Low battery: Enhanced animation throttling applied')
|
|
155
|
+
optimizations.push('Animation complexity reduced by 60%')
|
|
156
|
+
optimizations.push('Performance optimizations enabled')
|
|
157
|
+
} else if (state.batteryLevel < 0.5) {
|
|
158
|
+
throttleLevel = 'light'
|
|
159
|
+
optimizations.push('Medium battery: Light animation throttling applied')
|
|
160
|
+
optimizations.push('Animation complexity reduced by 30%')
|
|
161
|
+
optimizations.push('Battery optimization enabled')
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Performance-based throttling
|
|
165
|
+
if (state.shouldThrottle) {
|
|
166
|
+
if (throttleLevel === 'none') throttleLevel = 'light'
|
|
167
|
+
optimizations.push('Performance-based throttling applied')
|
|
168
|
+
optimizations.push('Animation frame rate optimized')
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Reduced motion support
|
|
172
|
+
if (state.reducedMotion) {
|
|
173
|
+
if (throttleLevel === 'none') throttleLevel = 'light'
|
|
174
|
+
optimizations.push('Reduced motion preference respected')
|
|
175
|
+
optimizations.push('Animation duration minimized')
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// User preference consideration
|
|
179
|
+
if (state.userPreference === 'battery') {
|
|
180
|
+
if (throttleLevel === 'none') throttleLevel = 'light'
|
|
181
|
+
optimizations.push('User preference: Battery optimization enabled')
|
|
182
|
+
} else if (state.userPreference === 'accessibility') {
|
|
183
|
+
if (throttleLevel === 'none') throttleLevel = 'light'
|
|
184
|
+
optimizations.push('User preference: Accessibility optimization enabled')
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
setState(prev => ({
|
|
188
|
+
...prev,
|
|
189
|
+
throttleLevel
|
|
190
|
+
}))
|
|
191
|
+
|
|
192
|
+
setOptimizations(prev => [...prev, ...optimizations])
|
|
193
|
+
setIsOptimizing(false)
|
|
194
|
+
|
|
195
|
+
callbacks.onAnimationThrottled?.(throttleLevel, 'Battery and performance optimization')
|
|
196
|
+
|
|
197
|
+
optimizations.forEach(optimization => {
|
|
198
|
+
console.log('Animation optimization:', optimization)
|
|
199
|
+
})
|
|
200
|
+
}, 300)
|
|
201
|
+
}, [enablePerformanceThrottling, state, callbacks])
|
|
202
|
+
|
|
203
|
+
// Get animation recommendations
|
|
204
|
+
const getAnimationRecommendations = useCallback(() => {
|
|
205
|
+
const recommendations = []
|
|
206
|
+
|
|
207
|
+
if (state.isCriticalBattery) {
|
|
208
|
+
recommendations.push('Critical battery: Disable all animations except essential transitions')
|
|
209
|
+
recommendations.push('Use static UI elements instead of animated ones')
|
|
210
|
+
recommendations.push('Minimize DOM updates and reflows')
|
|
211
|
+
} else if (state.isLowBattery) {
|
|
212
|
+
recommendations.push('Low battery: Reduce animation complexity significantly')
|
|
213
|
+
recommendations.push('Use simple transforms instead of complex animations')
|
|
214
|
+
recommendations.push('Limit animation duration to under 300ms')
|
|
215
|
+
} else if (state.batteryLevel < 0.5) {
|
|
216
|
+
recommendations.push('Medium battery: Consider light animation optimization')
|
|
217
|
+
recommendations.push('Use CSS transforms instead of JavaScript animations')
|
|
218
|
+
recommendations.push('Implement animation pausing when not in viewport')
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (state.shouldThrottle) {
|
|
222
|
+
recommendations.push('Performance issue: Reduce animation frame rate')
|
|
223
|
+
recommendations.push('Use requestAnimationFrame for smooth animations')
|
|
224
|
+
recommendations.push('Implement animation debouncing')
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
if (state.reducedMotion) {
|
|
228
|
+
recommendations.push('Accessibility: Respect reduced motion preference')
|
|
229
|
+
recommendations.push('Provide alternative non-animated experiences')
|
|
230
|
+
recommendations.push('Use subtle transitions instead of animations')
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return recommendations
|
|
234
|
+
}, [state])
|
|
235
|
+
|
|
236
|
+
// Get optimal animation settings
|
|
237
|
+
const getOptimalAnimationSettings = useCallback(() => {
|
|
238
|
+
const settings = {
|
|
239
|
+
duration: 300,
|
|
240
|
+
easing: 'ease-out',
|
|
241
|
+
shouldAnimate: true,
|
|
242
|
+
complexity: 'medium',
|
|
243
|
+
frameRate: 60
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
switch (state.throttleLevel) {
|
|
247
|
+
case 'aggressive':
|
|
248
|
+
settings.duration = 150
|
|
249
|
+
settings.easing = 'linear'
|
|
250
|
+
settings.shouldAnimate = false
|
|
251
|
+
settings.complexity = 'minimal'
|
|
252
|
+
settings.frameRate = 30
|
|
253
|
+
break
|
|
254
|
+
case 'moderate':
|
|
255
|
+
settings.duration = 200
|
|
256
|
+
settings.easing = 'ease-out'
|
|
257
|
+
settings.shouldAnimate = true
|
|
258
|
+
settings.complexity = 'low'
|
|
259
|
+
settings.frameRate = 45
|
|
260
|
+
break
|
|
261
|
+
case 'light':
|
|
262
|
+
settings.duration = 250
|
|
263
|
+
settings.easing = 'ease-out'
|
|
264
|
+
settings.shouldAnimate = true
|
|
265
|
+
settings.complexity = 'medium'
|
|
266
|
+
settings.frameRate = 50
|
|
267
|
+
break
|
|
268
|
+
default:
|
|
269
|
+
settings.duration = 300
|
|
270
|
+
settings.easing = 'ease-out'
|
|
271
|
+
settings.shouldAnimate = true
|
|
272
|
+
settings.complexity = 'high'
|
|
273
|
+
settings.frameRate = 60
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Override for reduced motion
|
|
277
|
+
if (state.reducedMotion) {
|
|
278
|
+
settings.duration = 100
|
|
279
|
+
settings.easing = 'linear'
|
|
280
|
+
settings.complexity = 'minimal'
|
|
281
|
+
settings.frameRate = 30
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
return settings
|
|
285
|
+
}, [state.throttleLevel, state.reducedMotion])
|
|
286
|
+
|
|
287
|
+
// Update user preferences
|
|
288
|
+
const updateUserPreference = useCallback((preference: string) => {
|
|
289
|
+
if (!enableUserPreferences) return
|
|
290
|
+
|
|
291
|
+
setState(prev => ({
|
|
292
|
+
...prev,
|
|
293
|
+
userPreference: preference as any
|
|
294
|
+
}))
|
|
295
|
+
|
|
296
|
+
callbacks.onUserPreferenceChange?.(preference)
|
|
297
|
+
|
|
298
|
+
// Apply optimizations based on new preference
|
|
299
|
+
setTimeout(() => {
|
|
300
|
+
applyAnimationThrottling()
|
|
301
|
+
}, 100)
|
|
302
|
+
}, [enableUserPreferences, callbacks, applyAnimationThrottling])
|
|
303
|
+
|
|
304
|
+
// Initialize monitoring
|
|
305
|
+
useEffect(() => {
|
|
306
|
+
try {
|
|
307
|
+
// Get initial battery status
|
|
308
|
+
if (enableBatteryMonitoring) {
|
|
309
|
+
getBatteryStatus()
|
|
310
|
+
batteryCheckIntervalRef.current = window.setInterval(getBatteryStatus, 10000)
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// Set up performance monitoring
|
|
314
|
+
if (enablePerformanceThrottling) {
|
|
315
|
+
performanceTimerRef.current = window.setInterval(measurePerformance, 5000)
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// Check reduced motion preference
|
|
319
|
+
if (enableReducedMotion) {
|
|
320
|
+
checkReducedMotion()
|
|
321
|
+
|
|
322
|
+
// Listen for preference changes
|
|
323
|
+
const mediaQuery = window.matchMedia('(prefers-reduced-motion: reduce)')
|
|
324
|
+
const handleChange = () => checkReducedMotion()
|
|
325
|
+
mediaQuery.addEventListener('change', handleChange)
|
|
326
|
+
|
|
327
|
+
return () => mediaQuery.removeEventListener('change', handleChange)
|
|
328
|
+
}
|
|
329
|
+
} catch (error) {
|
|
330
|
+
console.warn('Battery animation initialization failed:', error)
|
|
331
|
+
}
|
|
332
|
+
}, [enableBatteryMonitoring, enablePerformanceThrottling, enableReducedMotion, getBatteryStatus, measurePerformance, checkReducedMotion])
|
|
333
|
+
|
|
334
|
+
// Apply throttling when state changes
|
|
335
|
+
useEffect(() => {
|
|
336
|
+
if (enableAutomaticOptimization) {
|
|
337
|
+
applyAnimationThrottling()
|
|
338
|
+
}
|
|
339
|
+
}, [enableAutomaticOptimization, applyAnimationThrottling])
|
|
340
|
+
|
|
341
|
+
// Cleanup on unmount
|
|
342
|
+
useEffect(() => {
|
|
343
|
+
return () => {
|
|
344
|
+
if (performanceTimerRef.current) {
|
|
345
|
+
clearInterval(performanceTimerRef.current)
|
|
346
|
+
}
|
|
347
|
+
if (batteryCheckIntervalRef.current) {
|
|
348
|
+
clearInterval(batteryCheckIntervalRef.current)
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}, [])
|
|
352
|
+
|
|
353
|
+
return {
|
|
354
|
+
// State
|
|
355
|
+
state,
|
|
356
|
+
isOptimizing,
|
|
357
|
+
optimizations,
|
|
358
|
+
|
|
359
|
+
// Actions
|
|
360
|
+
getBatteryStatus,
|
|
361
|
+
measurePerformance,
|
|
362
|
+
checkReducedMotion,
|
|
363
|
+
applyAnimationThrottling,
|
|
364
|
+
updateUserPreference,
|
|
365
|
+
|
|
366
|
+
// Computed values
|
|
367
|
+
batteryPercentage: Math.round(state.batteryLevel * 100),
|
|
368
|
+
shouldDisableAnimations: state.throttleLevel === 'aggressive' || state.reducedMotion,
|
|
369
|
+
animationSettings: getOptimalAnimationSettings(),
|
|
370
|
+
recommendations: getAnimationRecommendations(),
|
|
371
|
+
|
|
372
|
+
// Utility functions
|
|
373
|
+
isAnimationOptimized: () => state.throttleLevel !== 'none',
|
|
374
|
+
getBatteryHealth: () => {
|
|
375
|
+
if (state.batteryLevel >= 0.8) return 'excellent'
|
|
376
|
+
if (state.batteryLevel >= 0.6) return 'good'
|
|
377
|
+
if (state.batteryLevel >= 0.4) return 'fair'
|
|
378
|
+
if (state.batteryLevel >= 0.2) return 'poor'
|
|
379
|
+
return 'critical'
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export default useBatteryAnimations
|