@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,565 @@
|
|
|
1
|
+
import { useState, useEffect, useCallback, useRef } from 'react'
|
|
2
|
+
|
|
3
|
+
export interface InputType {
|
|
4
|
+
type: 'text' | 'email' | 'password' | 'number' | 'tel' | 'url' | 'search' | 'date' | 'time' | 'datetime-local' | 'month' | 'week'
|
|
5
|
+
pattern?: RegExp
|
|
6
|
+
autocomplete?: string
|
|
7
|
+
inputMode?: 'none' | 'text' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal' | 'search'
|
|
8
|
+
keyboardType?: 'default' | 'email' | 'numeric' | 'phone' | 'url'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface SemanticConfig {
|
|
12
|
+
enableAutoDetection: boolean
|
|
13
|
+
enableKeyboardOptimization: boolean
|
|
14
|
+
enableAutocomplete: boolean
|
|
15
|
+
enableTouchOptimization: boolean
|
|
16
|
+
enableAccessibility: boolean
|
|
17
|
+
enablePerformanceMonitoring: boolean
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface SemanticCallbacks {
|
|
21
|
+
onInputTypeDetected?: (inputType: InputType) => void
|
|
22
|
+
onKeyboardOptimization?: (optimized: boolean) => void
|
|
23
|
+
onAutocompleteEnhanced?: (enhanced: boolean) => void
|
|
24
|
+
onTouchOptimized?: (optimized: boolean) => void
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface SemanticInputState {
|
|
28
|
+
detectedType: InputType | null
|
|
29
|
+
isOptimized: boolean
|
|
30
|
+
keyboardOptimized: boolean
|
|
31
|
+
autocompleteEnhanced: boolean
|
|
32
|
+
touchOptimized: boolean
|
|
33
|
+
performanceMetrics: {
|
|
34
|
+
detectionTime: number
|
|
35
|
+
optimizationTime: number
|
|
36
|
+
lastOptimization: number
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const useSemanticInput = (
|
|
41
|
+
initialType: InputType,
|
|
42
|
+
callbacks: SemanticCallbacks = {},
|
|
43
|
+
config: Partial<SemanticConfig> = {}
|
|
44
|
+
) => {
|
|
45
|
+
const defaultConfig: SemanticConfig = {
|
|
46
|
+
enableAutoDetection: true,
|
|
47
|
+
enableKeyboardOptimization: true,
|
|
48
|
+
enableAutocomplete: true,
|
|
49
|
+
enableTouchOptimization: true,
|
|
50
|
+
enableAccessibility: true,
|
|
51
|
+
enablePerformanceMonitoring: true,
|
|
52
|
+
...config
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const [semanticState, setSemanticState] = useState<SemanticInputState>({
|
|
56
|
+
detectedType: null,
|
|
57
|
+
isOptimized: false,
|
|
58
|
+
keyboardOptimized: false,
|
|
59
|
+
autocompleteEnhanced: false,
|
|
60
|
+
touchOptimized: false,
|
|
61
|
+
performanceMetrics: {
|
|
62
|
+
detectionTime: 0,
|
|
63
|
+
optimizationTime: 0,
|
|
64
|
+
lastOptimization: 0
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
const inputRef = useRef<HTMLInputElement | null>(null)
|
|
69
|
+
const optimizationTimerRef = useRef<NodeJS.Timeout | null>(null)
|
|
70
|
+
|
|
71
|
+
// Detect input type based on content and context
|
|
72
|
+
const detectInputType = useCallback((value: string, name: string, placeholder?: string): InputType => {
|
|
73
|
+
const startTime = performance.now()
|
|
74
|
+
|
|
75
|
+
let detectedType: InputType = { ...initialType }
|
|
76
|
+
|
|
77
|
+
// Auto-detect based on field name
|
|
78
|
+
if (defaultConfig.enableAutoDetection) {
|
|
79
|
+
const fieldName = name.toLowerCase()
|
|
80
|
+
const fieldValue = value.toLowerCase()
|
|
81
|
+
|
|
82
|
+
// Email detection
|
|
83
|
+
if (fieldName.includes('email') || fieldName.includes('mail') || fieldValue.includes('@')) {
|
|
84
|
+
detectedType = {
|
|
85
|
+
type: 'email',
|
|
86
|
+
autocomplete: 'email',
|
|
87
|
+
inputMode: 'email',
|
|
88
|
+
keyboardType: 'email'
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Phone detection
|
|
92
|
+
else if (fieldName.includes('phone') || fieldName.includes('tel') || fieldName.includes('mobile')) {
|
|
93
|
+
detectedType = {
|
|
94
|
+
type: 'tel',
|
|
95
|
+
autocomplete: 'tel',
|
|
96
|
+
inputMode: 'tel',
|
|
97
|
+
keyboardType: 'phone'
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// URL detection
|
|
101
|
+
else if (fieldName.includes('url') || fieldName.includes('website') || fieldName.includes('link')) {
|
|
102
|
+
detectedType = {
|
|
103
|
+
type: 'url',
|
|
104
|
+
autocomplete: 'url',
|
|
105
|
+
inputMode: 'url',
|
|
106
|
+
keyboardType: 'url'
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// Search detection
|
|
110
|
+
else if (fieldName.includes('search') || fieldName.includes('query')) {
|
|
111
|
+
detectedType = {
|
|
112
|
+
type: 'search',
|
|
113
|
+
autocomplete: 'off',
|
|
114
|
+
inputMode: 'search',
|
|
115
|
+
keyboardType: 'default'
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// Number detection
|
|
119
|
+
else if (fieldName.includes('number') || fieldName.includes('amount') || fieldName.includes('price') || fieldName.includes('quantity')) {
|
|
120
|
+
detectedType = {
|
|
121
|
+
type: 'number',
|
|
122
|
+
autocomplete: 'off',
|
|
123
|
+
inputMode: 'numeric',
|
|
124
|
+
keyboardType: 'numeric'
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Date detection
|
|
128
|
+
else if (fieldName.includes('date') || fieldName.includes('birth') || fieldName.includes('anniversary')) {
|
|
129
|
+
detectedType = {
|
|
130
|
+
type: 'date',
|
|
131
|
+
autocomplete: 'bday',
|
|
132
|
+
inputMode: 'none',
|
|
133
|
+
keyboardType: 'default'
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// Password detection
|
|
137
|
+
else if (fieldName.includes('password') || fieldName.includes('pass') || fieldName.includes('secret')) {
|
|
138
|
+
detectedType = {
|
|
139
|
+
type: 'password',
|
|
140
|
+
autocomplete: 'current-password',
|
|
141
|
+
inputMode: 'text',
|
|
142
|
+
keyboardType: 'default'
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Auto-detect based on placeholder text
|
|
148
|
+
if (placeholder && defaultConfig.enableAutoDetection) {
|
|
149
|
+
const placeholderLower = placeholder.toLowerCase()
|
|
150
|
+
|
|
151
|
+
if (placeholderLower.includes('@') || placeholderLower.includes('email')) {
|
|
152
|
+
detectedType = {
|
|
153
|
+
type: 'email',
|
|
154
|
+
autocomplete: 'email',
|
|
155
|
+
inputMode: 'email',
|
|
156
|
+
keyboardType: 'email'
|
|
157
|
+
}
|
|
158
|
+
} else if (placeholderLower.includes('http') || placeholderLower.includes('www')) {
|
|
159
|
+
detectedType = {
|
|
160
|
+
type: 'url',
|
|
161
|
+
autocomplete: 'url',
|
|
162
|
+
inputMode: 'url',
|
|
163
|
+
keyboardType: 'url'
|
|
164
|
+
}
|
|
165
|
+
} else if (placeholderLower.includes('search') || placeholderLower.includes('find')) {
|
|
166
|
+
detectedType = {
|
|
167
|
+
type: 'search',
|
|
168
|
+
autocomplete: 'off',
|
|
169
|
+
inputMode: 'search',
|
|
170
|
+
keyboardType: 'default'
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Auto-detect based on value pattern
|
|
176
|
+
if (value && defaultConfig.enableAutoDetection) {
|
|
177
|
+
// Email pattern
|
|
178
|
+
if (/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) {
|
|
179
|
+
detectedType = {
|
|
180
|
+
type: 'email',
|
|
181
|
+
autocomplete: 'email',
|
|
182
|
+
inputMode: 'email',
|
|
183
|
+
keyboardType: 'email'
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// Phone pattern
|
|
187
|
+
else if (/^[\+]?[0-9\s\-\(\)]{7,}$/.test(value)) {
|
|
188
|
+
detectedType = {
|
|
189
|
+
type: 'tel',
|
|
190
|
+
autocomplete: 'tel',
|
|
191
|
+
inputMode: 'tel',
|
|
192
|
+
keyboardType: 'phone'
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
// URL pattern
|
|
196
|
+
else if (/^https?:\/\/.+/.test(value)) {
|
|
197
|
+
detectedType = {
|
|
198
|
+
type: 'url',
|
|
199
|
+
autocomplete: 'url',
|
|
200
|
+
inputMode: 'url',
|
|
201
|
+
keyboardType: 'url'
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
// Number pattern
|
|
205
|
+
else if (/^[0-9]+(\.[0-9]+)?$/.test(value)) {
|
|
206
|
+
detectedType = {
|
|
207
|
+
type: 'number',
|
|
208
|
+
autocomplete: 'off',
|
|
209
|
+
inputMode: 'numeric',
|
|
210
|
+
keyboardType: 'numeric'
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const endTime = performance.now()
|
|
216
|
+
const detectionTime = endTime - startTime
|
|
217
|
+
|
|
218
|
+
setSemanticState(prev => ({
|
|
219
|
+
...prev,
|
|
220
|
+
detectedType,
|
|
221
|
+
performanceMetrics: {
|
|
222
|
+
...prev.performanceMetrics,
|
|
223
|
+
detectionTime
|
|
224
|
+
}
|
|
225
|
+
}))
|
|
226
|
+
|
|
227
|
+
callbacks.onInputTypeDetected?.(detectedType)
|
|
228
|
+
return detectedType
|
|
229
|
+
}, [initialType, defaultConfig.enableAutoDetection, callbacks])
|
|
230
|
+
|
|
231
|
+
// Optimize keyboard for mobile devices
|
|
232
|
+
const optimizeKeyboard = useCallback((inputType: InputType) => {
|
|
233
|
+
if (!defaultConfig.enableKeyboardOptimization) return false
|
|
234
|
+
|
|
235
|
+
const startTime = performance.now()
|
|
236
|
+
let optimized = false
|
|
237
|
+
|
|
238
|
+
if (inputRef.current) {
|
|
239
|
+
const input = inputRef.current
|
|
240
|
+
|
|
241
|
+
// Set input mode for better mobile keyboard
|
|
242
|
+
if (inputType.inputMode) {
|
|
243
|
+
input.setAttribute('inputmode', inputType.inputMode)
|
|
244
|
+
optimized = true
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Set autocomplete for better UX
|
|
248
|
+
if (inputType.autocomplete && defaultConfig.enableAutocomplete) {
|
|
249
|
+
input.setAttribute('autocomplete', inputType.autocomplete)
|
|
250
|
+
optimized = true
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Set pattern for validation
|
|
254
|
+
if (inputType.pattern) {
|
|
255
|
+
input.setAttribute('pattern', inputType.pattern.source)
|
|
256
|
+
optimized = true
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Add mobile-specific attributes
|
|
260
|
+
if (inputType.type === 'tel') {
|
|
261
|
+
input.setAttribute('data-mobile-keyboard', 'phone')
|
|
262
|
+
optimized = true
|
|
263
|
+
} else if (inputType.type === 'email') {
|
|
264
|
+
input.setAttribute('data-mobile-keyboard', 'email')
|
|
265
|
+
optimized = true
|
|
266
|
+
} else if (inputType.type === 'number') {
|
|
267
|
+
input.setAttribute('data-mobile-keyboard', 'numeric')
|
|
268
|
+
optimized = true
|
|
269
|
+
} else if (inputType.type === 'url') {
|
|
270
|
+
input.setAttribute('data-mobile-keyboard', 'url')
|
|
271
|
+
optimized = true
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
const endTime = performance.now()
|
|
276
|
+
const optimizationTime = endTime - startTime
|
|
277
|
+
|
|
278
|
+
setSemanticState(prev => ({
|
|
279
|
+
...prev,
|
|
280
|
+
keyboardOptimized: optimized,
|
|
281
|
+
performanceMetrics: {
|
|
282
|
+
...prev.performanceMetrics,
|
|
283
|
+
optimizationTime,
|
|
284
|
+
lastOptimization: Date.now()
|
|
285
|
+
}
|
|
286
|
+
}))
|
|
287
|
+
|
|
288
|
+
callbacks.onKeyboardOptimization?.(optimized)
|
|
289
|
+
return optimized
|
|
290
|
+
}, [defaultConfig.enableKeyboardOptimization, defaultConfig.enableAutocomplete, callbacks])
|
|
291
|
+
|
|
292
|
+
// Enhance autocomplete functionality
|
|
293
|
+
const enhanceAutocomplete = useCallback((inputType: InputType) => {
|
|
294
|
+
if (!defaultConfig.enableAutocomplete) return false
|
|
295
|
+
|
|
296
|
+
let enhanced = false
|
|
297
|
+
|
|
298
|
+
if (inputRef.current) {
|
|
299
|
+
const input = inputRef.current
|
|
300
|
+
|
|
301
|
+
// Set appropriate autocomplete values
|
|
302
|
+
switch (inputType.type) {
|
|
303
|
+
case 'email':
|
|
304
|
+
input.setAttribute('autocomplete', 'email')
|
|
305
|
+
enhanced = true
|
|
306
|
+
break
|
|
307
|
+
case 'tel':
|
|
308
|
+
input.setAttribute('autocomplete', 'tel')
|
|
309
|
+
enhanced = true
|
|
310
|
+
break
|
|
311
|
+
case 'url':
|
|
312
|
+
input.setAttribute('autocomplete', 'url')
|
|
313
|
+
enhanced = true
|
|
314
|
+
break
|
|
315
|
+
case 'password':
|
|
316
|
+
input.setAttribute('autocomplete', 'current-password')
|
|
317
|
+
enhanced = true
|
|
318
|
+
break
|
|
319
|
+
case 'date':
|
|
320
|
+
input.setAttribute('autocomplete', 'bday')
|
|
321
|
+
enhanced = true
|
|
322
|
+
break
|
|
323
|
+
case 'search':
|
|
324
|
+
input.setAttribute('autocomplete', 'off')
|
|
325
|
+
enhanced = true
|
|
326
|
+
break
|
|
327
|
+
case 'number':
|
|
328
|
+
input.setAttribute('autocomplete', 'off')
|
|
329
|
+
enhanced = true
|
|
330
|
+
break
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// Add data attributes for custom autocomplete
|
|
334
|
+
if (inputType.type === 'email') {
|
|
335
|
+
input.setAttribute('data-autocomplete-type', 'email')
|
|
336
|
+
input.setAttribute('data-suggestions', 'email-domains')
|
|
337
|
+
} else if (inputType.type === 'tel') {
|
|
338
|
+
input.setAttribute('data-autocomplete-type', 'phone')
|
|
339
|
+
input.setAttribute('data-suggestions', 'phone-formats')
|
|
340
|
+
} else if (inputType.type === 'url') {
|
|
341
|
+
input.setAttribute('data-autocomplete-type', 'url')
|
|
342
|
+
input.setAttribute('data-suggestions', 'common-urls')
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
setSemanticState(prev => ({
|
|
347
|
+
...prev,
|
|
348
|
+
autocompleteEnhanced: enhanced
|
|
349
|
+
}))
|
|
350
|
+
|
|
351
|
+
callbacks.onAutocompleteEnhanced?.(enhanced)
|
|
352
|
+
return enhanced
|
|
353
|
+
}, [defaultConfig.enableAutocomplete, callbacks])
|
|
354
|
+
|
|
355
|
+
// Optimize touch interactions
|
|
356
|
+
const optimizeTouch = useCallback((inputType: InputType) => {
|
|
357
|
+
if (!defaultConfig.enableTouchOptimization) return false
|
|
358
|
+
|
|
359
|
+
let optimized = false
|
|
360
|
+
|
|
361
|
+
if (inputRef.current) {
|
|
362
|
+
const input = inputRef.current
|
|
363
|
+
|
|
364
|
+
// Add touch-friendly attributes
|
|
365
|
+
input.setAttribute('data-touch-optimized', 'true')
|
|
366
|
+
|
|
367
|
+
// Set appropriate touch action
|
|
368
|
+
if (inputType.type === 'search') {
|
|
369
|
+
input.style.touchAction = 'manipulation'
|
|
370
|
+
optimized = true
|
|
371
|
+
} else if (inputType.type === 'number') {
|
|
372
|
+
input.style.touchAction = 'manipulation'
|
|
373
|
+
optimized = true
|
|
374
|
+
} else {
|
|
375
|
+
input.style.touchAction = 'auto'
|
|
376
|
+
optimized = true
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// Add touch feedback classes
|
|
380
|
+
input.classList.add('touch-input')
|
|
381
|
+
input.classList.add('touch-target')
|
|
382
|
+
|
|
383
|
+
// Set minimum touch target size
|
|
384
|
+
input.style.minHeight = '44px'
|
|
385
|
+
input.style.minWidth = '44px'
|
|
386
|
+
|
|
387
|
+
optimized = true
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
setSemanticState(prev => ({
|
|
391
|
+
...prev,
|
|
392
|
+
touchOptimized: optimized
|
|
393
|
+
}))
|
|
394
|
+
|
|
395
|
+
callbacks.onTouchOptimized?.(optimized)
|
|
396
|
+
return optimized
|
|
397
|
+
}, [defaultConfig.enableTouchOptimization, callbacks])
|
|
398
|
+
|
|
399
|
+
// Apply all optimizations
|
|
400
|
+
const applyOptimizations = useCallback((inputType: InputType) => {
|
|
401
|
+
const keyboardOptimized = optimizeKeyboard(inputType)
|
|
402
|
+
const autocompleteEnhanced = enhanceAutocomplete(inputType)
|
|
403
|
+
const touchOptimized = optimizeTouch(inputType)
|
|
404
|
+
|
|
405
|
+
const isOptimized = keyboardOptimized || autocompleteEnhanced || touchOptimized
|
|
406
|
+
|
|
407
|
+
setSemanticState(prev => ({
|
|
408
|
+
...prev,
|
|
409
|
+
isOptimized
|
|
410
|
+
}))
|
|
411
|
+
|
|
412
|
+
return isOptimized
|
|
413
|
+
}, [optimizeKeyboard, enhanceAutocomplete, optimizeTouch])
|
|
414
|
+
|
|
415
|
+
// Handle input changes with optimization
|
|
416
|
+
const handleInputChange = useCallback((
|
|
417
|
+
value: string,
|
|
418
|
+
name: string,
|
|
419
|
+
placeholder?: string
|
|
420
|
+
) => {
|
|
421
|
+
const detectedType = detectInputType(value, name, placeholder)
|
|
422
|
+
|
|
423
|
+
// Apply optimizations with debouncing
|
|
424
|
+
if (optimizationTimerRef.current) {
|
|
425
|
+
clearTimeout(optimizationTimerRef.current)
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
optimizationTimerRef.current = setTimeout(() => {
|
|
429
|
+
applyOptimizations(detectedType)
|
|
430
|
+
}, 100)
|
|
431
|
+
}, [detectInputType, applyOptimizations])
|
|
432
|
+
|
|
433
|
+
// Get optimized input attributes
|
|
434
|
+
const getOptimizedAttributes = useCallback((inputType: InputType) => {
|
|
435
|
+
const attributes: Record<string, string> = {
|
|
436
|
+
type: inputType.type,
|
|
437
|
+
'data-semantic-optimized': 'true'
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
if (inputType.inputMode) {
|
|
441
|
+
attributes.inputmode = inputType.inputMode
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
if (inputType.autocomplete) {
|
|
445
|
+
attributes.autocomplete = inputType.autocomplete
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
if (inputType.pattern) {
|
|
449
|
+
attributes.pattern = inputType.pattern.source
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// Add mobile-specific attributes
|
|
453
|
+
if (inputType.keyboardType) {
|
|
454
|
+
attributes['data-mobile-keyboard'] = inputType.keyboardType
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
return attributes
|
|
458
|
+
}, [])
|
|
459
|
+
|
|
460
|
+
// Get CSS classes for semantic optimization
|
|
461
|
+
const getSemanticClasses = useCallback(() => {
|
|
462
|
+
const { detectedType, isOptimized, keyboardOptimized, autocompleteEnhanced, touchOptimized } = semanticState
|
|
463
|
+
|
|
464
|
+
const classes = ['semantic-input']
|
|
465
|
+
|
|
466
|
+
if (detectedType) {
|
|
467
|
+
classes.push(`input-type-${detectedType.type}`)
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
if (isOptimized) {
|
|
471
|
+
classes.push('input-optimized')
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
if (keyboardOptimized) {
|
|
475
|
+
classes.push('keyboard-optimized')
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
if (autocompleteEnhanced) {
|
|
479
|
+
classes.push('autocomplete-enhanced')
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
if (touchOptimized) {
|
|
483
|
+
classes.push('touch-optimized')
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
return classes.join(' ')
|
|
487
|
+
}, [semanticState])
|
|
488
|
+
|
|
489
|
+
// Reset optimizations
|
|
490
|
+
const resetOptimizations = useCallback(() => {
|
|
491
|
+
if (inputRef.current) {
|
|
492
|
+
const input = inputRef.current
|
|
493
|
+
|
|
494
|
+
// Remove custom attributes
|
|
495
|
+
input.removeAttribute('data-mobile-keyboard')
|
|
496
|
+
input.removeAttribute('data-autocomplete-type')
|
|
497
|
+
input.removeAttribute('data-suggestions')
|
|
498
|
+
input.removeAttribute('data-touch-optimized')
|
|
499
|
+
input.removeAttribute('data-semantic-optimized')
|
|
500
|
+
|
|
501
|
+
// Remove custom styles
|
|
502
|
+
input.style.touchAction = ''
|
|
503
|
+
input.style.minHeight = ''
|
|
504
|
+
input.style.minWidth = ''
|
|
505
|
+
|
|
506
|
+
// Remove custom classes
|
|
507
|
+
input.classList.remove('touch-input', 'touch-target')
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
setSemanticState(prev => ({
|
|
511
|
+
...prev,
|
|
512
|
+
isOptimized: false,
|
|
513
|
+
keyboardOptimized: false,
|
|
514
|
+
autocompleteEnhanced: false,
|
|
515
|
+
touchOptimized: false
|
|
516
|
+
}))
|
|
517
|
+
}, [])
|
|
518
|
+
|
|
519
|
+
// Clean up timer on unmount
|
|
520
|
+
useEffect(() => {
|
|
521
|
+
return () => {
|
|
522
|
+
if (optimizationTimerRef.current) {
|
|
523
|
+
clearTimeout(optimizationTimerRef.current)
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}, [])
|
|
527
|
+
|
|
528
|
+
return {
|
|
529
|
+
semanticState,
|
|
530
|
+
detectInputType,
|
|
531
|
+
optimizeKeyboard,
|
|
532
|
+
enhanceAutocomplete,
|
|
533
|
+
optimizeTouch,
|
|
534
|
+
applyOptimizations,
|
|
535
|
+
handleInputChange,
|
|
536
|
+
getOptimizedAttributes,
|
|
537
|
+
getSemanticClasses,
|
|
538
|
+
resetOptimizations,
|
|
539
|
+
inputRef
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// Convenience hook for basic semantic input
|
|
544
|
+
export const useBasicSemanticInput = (initialType: InputType) => {
|
|
545
|
+
return useSemanticInput(initialType, {}, {
|
|
546
|
+
enableAutoDetection: true,
|
|
547
|
+
enableKeyboardOptimization: false,
|
|
548
|
+
enableAutocomplete: false,
|
|
549
|
+
enableTouchOptimization: false,
|
|
550
|
+
enableAccessibility: true,
|
|
551
|
+
enablePerformanceMonitoring: false
|
|
552
|
+
})
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// Convenience hook for enhanced semantic input
|
|
556
|
+
export const useEnhancedSemanticInput = (initialType: InputType) => {
|
|
557
|
+
return useSemanticInput(initialType, {}, {
|
|
558
|
+
enableAutoDetection: true,
|
|
559
|
+
enableKeyboardOptimization: true,
|
|
560
|
+
enableAutocomplete: true,
|
|
561
|
+
enableTouchOptimization: true,
|
|
562
|
+
enableAccessibility: true,
|
|
563
|
+
enablePerformanceMonitoring: true
|
|
564
|
+
})
|
|
565
|
+
}
|