@datametria/vue-components 1.1.2 → 1.2.0
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/README.md +657 -472
- package/dist/index.es.js +1916 -675
- package/dist/index.umd.js +74 -1
- package/dist/vue-components.css +1 -1
- package/package.json +98 -98
- package/src/components/DatametriaAlert.vue +137 -123
- package/src/components/DatametriaBadge.vue +98 -90
- package/src/components/DatametriaButton.vue +165 -157
- package/src/components/DatametriaChip.vue +149 -149
- package/src/components/DatametriaMenu.vue +620 -0
- package/src/components/DatametriaNavbar.vue +252 -227
- package/src/components/DatametriaSkeleton.vue +240 -0
- package/src/components/DatametriaSlider.vue +408 -0
- package/src/components/DatametriaTimePicker.vue +286 -0
- package/src/components/DatametriaToast.vue +176 -163
- package/src/components/DatametriaTooltip.vue +409 -0
- package/src/components/__tests__/DatametriaAlert.test.js +36 -0
- package/src/components/__tests__/DatametriaBadge.test.js +30 -0
- package/src/components/__tests__/DatametriaButton.test.js +31 -0
- package/src/components/__tests__/DatametriaChip.test.js +39 -0
- package/src/components/__tests__/DatametriaNavbar.test.js +49 -0
- package/src/components/__tests__/DatametriaToast.test.js +49 -0
- package/src/composables/useAccessibilityScale.ts +95 -0
- package/src/composables/useBreakpoints.ts +83 -0
- package/src/composables/useHapticFeedback.ts +440 -0
- package/src/composables/useRipple.ts +219 -0
- package/src/index.ts +61 -52
- package/src/stories/Variants.stories.js +96 -0
- package/src/styles/design-tokens.css +623 -31
- package/ACCESSIBILITY.md +0 -78
- package/DESIGN-SYSTEM.md +0 -70
- package/PROGRESS.md +0 -327
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { ref, computed, watch, onMounted } from 'vue'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Composable para controle de escalabilidade de acessibilidade
|
|
5
|
+
* Implementa escala controlada entre 0.8x e 2.0x conforme WCAG 2.1
|
|
6
|
+
*/
|
|
7
|
+
export function useAccessibilityScale() {
|
|
8
|
+
const scale = ref(1.0)
|
|
9
|
+
const STORAGE_KEY = 'datametria-accessibility-scale'
|
|
10
|
+
const MIN_SCALE = 0.8
|
|
11
|
+
const MAX_SCALE = 2.0
|
|
12
|
+
|
|
13
|
+
// Computed para escala clampada
|
|
14
|
+
const clampedScale = computed(() =>
|
|
15
|
+
Math.max(MIN_SCALE, Math.min(MAX_SCALE, scale.value))
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
// Computed para classe CSS
|
|
19
|
+
const scaleClass = computed(() => {
|
|
20
|
+
const s = clampedScale.value
|
|
21
|
+
if (s <= 0.9) return 'scale-small'
|
|
22
|
+
if (s >= 1.1) return 'scale-large'
|
|
23
|
+
return 'scale-normal'
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
// Aplicar escala ao documento
|
|
27
|
+
const applyScale = (newScale: number) => {
|
|
28
|
+
const finalScale = Math.max(MIN_SCALE, Math.min(MAX_SCALE, newScale))
|
|
29
|
+
document.documentElement.style.setProperty('--user-scale', finalScale.toString())
|
|
30
|
+
scale.value = finalScale
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Salvar no localStorage
|
|
34
|
+
const saveScale = (scaleValue: number) => {
|
|
35
|
+
try {
|
|
36
|
+
localStorage.setItem(STORAGE_KEY, scaleValue.toString())
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.warn('Failed to save accessibility scale:', error)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Carregar do localStorage
|
|
43
|
+
const loadScale = (): number => {
|
|
44
|
+
try {
|
|
45
|
+
const saved = localStorage.getItem(STORAGE_KEY)
|
|
46
|
+
return saved ? parseFloat(saved) : 1.0
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.warn('Failed to load accessibility scale:', error)
|
|
49
|
+
return 1.0
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Definir escala
|
|
54
|
+
const setScale = (newScale: number) => {
|
|
55
|
+
applyScale(newScale)
|
|
56
|
+
saveScale(clampedScale.value)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Incrementar escala
|
|
60
|
+
const increaseScale = () => {
|
|
61
|
+
setScale(scale.value + 0.1)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Decrementar escala
|
|
65
|
+
const decreaseScale = () => {
|
|
66
|
+
setScale(scale.value - 0.1)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Reset para padrão
|
|
70
|
+
const resetScale = () => {
|
|
71
|
+
setScale(1.0)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Watch para mudanças na escala
|
|
75
|
+
watch(scale, (newScale) => {
|
|
76
|
+
applyScale(newScale)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
// Inicializar na montagem
|
|
80
|
+
onMounted(() => {
|
|
81
|
+
const savedScale = loadScale()
|
|
82
|
+
applyScale(savedScale)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
scale: clampedScale,
|
|
87
|
+
scaleClass,
|
|
88
|
+
setScale,
|
|
89
|
+
increaseScale,
|
|
90
|
+
decreaseScale,
|
|
91
|
+
resetScale,
|
|
92
|
+
minScale: MIN_SCALE,
|
|
93
|
+
maxScale: MAX_SCALE
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ref, onMounted, onUnmounted } from 'vue'
|
|
2
|
+
|
|
3
|
+
export const breakpoints = {
|
|
4
|
+
xs: 475,
|
|
5
|
+
sm: 640,
|
|
6
|
+
md: 768,
|
|
7
|
+
lg: 1024,
|
|
8
|
+
xl: 1280,
|
|
9
|
+
'2xl': 1536
|
|
10
|
+
} as const
|
|
11
|
+
|
|
12
|
+
export type Breakpoint = keyof typeof breakpoints
|
|
13
|
+
|
|
14
|
+
export function useBreakpoints() {
|
|
15
|
+
const windowWidth = ref(0)
|
|
16
|
+
|
|
17
|
+
const updateWidth = () => {
|
|
18
|
+
windowWidth.value = window.innerWidth
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const isGreaterOrEqual = (breakpoint: Breakpoint) => {
|
|
22
|
+
return windowWidth.value >= breakpoints[breakpoint]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const isLessOrEqual = (breakpoint: Breakpoint) => {
|
|
26
|
+
return windowWidth.value <= breakpoints[breakpoint]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const isBetween = (min: Breakpoint, max: Breakpoint) => {
|
|
30
|
+
return windowWidth.value >= breakpoints[min] && windowWidth.value <= breakpoints[max]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const getCurrentBreakpoint = (): Breakpoint => {
|
|
34
|
+
const width = windowWidth.value
|
|
35
|
+
|
|
36
|
+
if (width >= breakpoints['2xl']) return '2xl'
|
|
37
|
+
if (width >= breakpoints.xl) return 'xl'
|
|
38
|
+
if (width >= breakpoints.lg) return 'lg'
|
|
39
|
+
if (width >= breakpoints.md) return 'md'
|
|
40
|
+
if (width >= breakpoints.sm) return 'sm'
|
|
41
|
+
return 'xs'
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Reactive breakpoint checks
|
|
45
|
+
const isXs = () => windowWidth.value < breakpoints.sm
|
|
46
|
+
const isSm = () => isGreaterOrEqual('sm') && windowWidth.value < breakpoints.md
|
|
47
|
+
const isMd = () => isGreaterOrEqual('md') && windowWidth.value < breakpoints.lg
|
|
48
|
+
const isLg = () => isGreaterOrEqual('lg') && windowWidth.value < breakpoints.xl
|
|
49
|
+
const isXl = () => isGreaterOrEqual('xl') && windowWidth.value < breakpoints['2xl']
|
|
50
|
+
const is2xl = () => isGreaterOrEqual('2xl')
|
|
51
|
+
|
|
52
|
+
// Mobile/tablet/desktop helpers
|
|
53
|
+
const isMobile = () => windowWidth.value < breakpoints.md
|
|
54
|
+
const isTablet = () => isBetween('md', 'lg')
|
|
55
|
+
const isDesktop = () => isGreaterOrEqual('lg')
|
|
56
|
+
|
|
57
|
+
onMounted(() => {
|
|
58
|
+
updateWidth()
|
|
59
|
+
window.addEventListener('resize', updateWidth)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
onUnmounted(() => {
|
|
63
|
+
window.removeEventListener('resize', updateWidth)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
windowWidth,
|
|
68
|
+
breakpoints,
|
|
69
|
+
isGreaterOrEqual,
|
|
70
|
+
isLessOrEqual,
|
|
71
|
+
isBetween,
|
|
72
|
+
getCurrentBreakpoint,
|
|
73
|
+
isXs,
|
|
74
|
+
isSm,
|
|
75
|
+
isMd,
|
|
76
|
+
isLg,
|
|
77
|
+
isXl,
|
|
78
|
+
is2xl,
|
|
79
|
+
isMobile,
|
|
80
|
+
isTablet,
|
|
81
|
+
isDesktop
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
import { ref, computed } from 'vue'
|
|
2
|
+
|
|
3
|
+
type HapticType = 'light' | 'medium' | 'heavy' | 'selection' | 'impact' | 'notification'
|
|
4
|
+
type NotificationType = 'success' | 'warning' | 'error'
|
|
5
|
+
|
|
6
|
+
interface HapticOptions {
|
|
7
|
+
enabled?: boolean
|
|
8
|
+
fallbackToVisual?: boolean
|
|
9
|
+
visualDuration?: number
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Composable para feedback háptico e visual
|
|
14
|
+
* Suporta dispositivos iOS/Android com fallback visual
|
|
15
|
+
*/
|
|
16
|
+
export function useHapticFeedback(options: HapticOptions = {}) {
|
|
17
|
+
const {
|
|
18
|
+
enabled = true,
|
|
19
|
+
fallbackToVisual = true,
|
|
20
|
+
visualDuration = 150
|
|
21
|
+
} = options
|
|
22
|
+
|
|
23
|
+
const isSupported = ref(false)
|
|
24
|
+
const isEnabled = ref(enabled)
|
|
25
|
+
const activeVisualFeedback = ref<string | null>(null)
|
|
26
|
+
|
|
27
|
+
// Detectar suporte a haptic feedback
|
|
28
|
+
const detectHapticSupport = () => {
|
|
29
|
+
// Haptic Feedback API (iOS/Android)
|
|
30
|
+
if ('hapticFeedback' in navigator && (navigator as any).hapticFeedback) {
|
|
31
|
+
return true
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Web Vibration API
|
|
35
|
+
if ('vibrate' in navigator && typeof (navigator as any).vibrate === 'function') {
|
|
36
|
+
return true
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return false
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Executar vibração nativa
|
|
43
|
+
const executeNativeVibration = (pattern: number | number[]) => {
|
|
44
|
+
if (!('vibrate' in navigator) || typeof (navigator as any).vibrate !== 'function') return false
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
return (navigator as any).vibrate(pattern)
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.warn('Haptic feedback failed:', error)
|
|
50
|
+
return false
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Feedback visual como fallback
|
|
55
|
+
const executeVisualFeedback = (type: HapticType, element?: HTMLElement) => {
|
|
56
|
+
if (!fallbackToVisual) return
|
|
57
|
+
|
|
58
|
+
const feedbackId = `visual-${Date.now()}`
|
|
59
|
+
activeVisualFeedback.value = feedbackId
|
|
60
|
+
|
|
61
|
+
// Aplicar efeito visual ao elemento
|
|
62
|
+
if (element) {
|
|
63
|
+
const originalTransform = element.style.transform
|
|
64
|
+
const originalTransition = element.style.transition
|
|
65
|
+
|
|
66
|
+
element.style.transition = 'transform 75ms ease-out'
|
|
67
|
+
|
|
68
|
+
switch (type) {
|
|
69
|
+
case 'light':
|
|
70
|
+
element.style.transform = 'scale(0.98)'
|
|
71
|
+
break
|
|
72
|
+
case 'medium':
|
|
73
|
+
element.style.transform = 'scale(0.95)'
|
|
74
|
+
break
|
|
75
|
+
case 'heavy':
|
|
76
|
+
element.style.transform = 'scale(0.92)'
|
|
77
|
+
break
|
|
78
|
+
case 'selection':
|
|
79
|
+
element.style.transform = 'scale(1.02)'
|
|
80
|
+
break
|
|
81
|
+
default:
|
|
82
|
+
element.style.transform = 'scale(0.97)'
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
setTimeout(() => {
|
|
86
|
+
element.style.transform = originalTransform
|
|
87
|
+
setTimeout(() => {
|
|
88
|
+
element.style.transition = originalTransition
|
|
89
|
+
if (activeVisualFeedback.value === feedbackId) {
|
|
90
|
+
activeVisualFeedback.value = null
|
|
91
|
+
}
|
|
92
|
+
}, 75)
|
|
93
|
+
}, 75)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Limpar feedback visual após duração
|
|
97
|
+
setTimeout(() => {
|
|
98
|
+
if (activeVisualFeedback.value === feedbackId) {
|
|
99
|
+
activeVisualFeedback.value = null
|
|
100
|
+
}
|
|
101
|
+
}, visualDuration)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Feedback leve (toque suave)
|
|
105
|
+
const light = (element?: HTMLElement) => {
|
|
106
|
+
if (!isEnabled.value) return
|
|
107
|
+
|
|
108
|
+
let success = false
|
|
109
|
+
|
|
110
|
+
if (isSupported.value) {
|
|
111
|
+
success = executeNativeVibration(10)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (!success && fallbackToVisual) {
|
|
115
|
+
executeVisualFeedback('light', element)
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Feedback médio (toque moderado)
|
|
120
|
+
const medium = (element?: HTMLElement) => {
|
|
121
|
+
if (!isEnabled.value) return
|
|
122
|
+
|
|
123
|
+
let success = false
|
|
124
|
+
|
|
125
|
+
if (isSupported.value) {
|
|
126
|
+
success = executeNativeVibration(20)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (!success && fallbackToVisual) {
|
|
130
|
+
executeVisualFeedback('medium', element)
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Feedback pesado (toque forte)
|
|
135
|
+
const heavy = (element?: HTMLElement) => {
|
|
136
|
+
if (!isEnabled.value) return
|
|
137
|
+
|
|
138
|
+
let success = false
|
|
139
|
+
|
|
140
|
+
if (isSupported.value) {
|
|
141
|
+
success = executeNativeVibration(40)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (!success && fallbackToVisual) {
|
|
145
|
+
executeVisualFeedback('heavy', element)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Feedback de seleção
|
|
150
|
+
const selection = (element?: HTMLElement) => {
|
|
151
|
+
if (!isEnabled.value) return
|
|
152
|
+
|
|
153
|
+
let success = false
|
|
154
|
+
|
|
155
|
+
if (isSupported.value) {
|
|
156
|
+
success = executeNativeVibration(5)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (!success && fallbackToVisual) {
|
|
160
|
+
executeVisualFeedback('selection', element)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Feedback de impacto
|
|
165
|
+
const impact = (intensity: 'light' | 'medium' | 'heavy' = 'medium', element?: HTMLElement) => {
|
|
166
|
+
switch (intensity) {
|
|
167
|
+
case 'light':
|
|
168
|
+
light(element)
|
|
169
|
+
break
|
|
170
|
+
case 'medium':
|
|
171
|
+
medium(element)
|
|
172
|
+
break
|
|
173
|
+
case 'heavy':
|
|
174
|
+
heavy(element)
|
|
175
|
+
break
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Feedback de notificação
|
|
180
|
+
const notification = (type: NotificationType, element?: HTMLElement) => {
|
|
181
|
+
if (!isEnabled.value) return
|
|
182
|
+
|
|
183
|
+
let pattern: number[]
|
|
184
|
+
|
|
185
|
+
switch (type) {
|
|
186
|
+
case 'success':
|
|
187
|
+
pattern = [10, 50, 10]
|
|
188
|
+
break
|
|
189
|
+
case 'warning':
|
|
190
|
+
pattern = [20, 100, 20, 100, 20]
|
|
191
|
+
break
|
|
192
|
+
case 'error':
|
|
193
|
+
pattern = [50, 100, 50, 100, 50]
|
|
194
|
+
break
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
let success = false
|
|
198
|
+
|
|
199
|
+
if (isSupported.value) {
|
|
200
|
+
success = executeNativeVibration(pattern)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (!success && fallbackToVisual) {
|
|
204
|
+
executeVisualFeedback('notification', element)
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Padrão customizado
|
|
209
|
+
const custom = (pattern: number | number[], element?: HTMLElement) => {
|
|
210
|
+
if (!isEnabled.value) return
|
|
211
|
+
|
|
212
|
+
let success = false
|
|
213
|
+
|
|
214
|
+
if (isSupported.value) {
|
|
215
|
+
success = executeNativeVibration(pattern)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (!success && fallbackToVisual) {
|
|
219
|
+
executeVisualFeedback('medium', element)
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Habilitar/desabilitar feedback
|
|
224
|
+
const enable = () => {
|
|
225
|
+
isEnabled.value = true
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const disable = () => {
|
|
229
|
+
isEnabled.value = false
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const toggle = () => {
|
|
233
|
+
isEnabled.value = !isEnabled.value
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Computed
|
|
237
|
+
const canVibrate = computed(() => isSupported.value && isEnabled.value)
|
|
238
|
+
const hasVisualFeedback = computed(() => activeVisualFeedback.value !== null)
|
|
239
|
+
|
|
240
|
+
// Método principal para feedback háptico
|
|
241
|
+
const triggerHaptic = (type: HapticType | NotificationType = 'light') => {
|
|
242
|
+
if (!isEnabled.value) return false
|
|
243
|
+
|
|
244
|
+
// Tentar haptic feedback nativo primeiro
|
|
245
|
+
if ('hapticFeedback' in navigator && (navigator as any).hapticFeedback) {
|
|
246
|
+
try {
|
|
247
|
+
return (navigator as any).hapticFeedback.impact(type)
|
|
248
|
+
} catch (error) {
|
|
249
|
+
console.warn('Haptic feedback failed:', error)
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Fallback para vibration API
|
|
254
|
+
if ('vibrate' in navigator && typeof (navigator as any).vibrate === 'function') {
|
|
255
|
+
let pattern: number | number[]
|
|
256
|
+
|
|
257
|
+
switch (type) {
|
|
258
|
+
case 'light':
|
|
259
|
+
pattern = 10
|
|
260
|
+
break
|
|
261
|
+
case 'medium':
|
|
262
|
+
pattern = 20
|
|
263
|
+
break
|
|
264
|
+
case 'heavy':
|
|
265
|
+
pattern = 30
|
|
266
|
+
break
|
|
267
|
+
case 'success':
|
|
268
|
+
pattern = [10, 50, 10]
|
|
269
|
+
break
|
|
270
|
+
case 'warning':
|
|
271
|
+
pattern = [20, 100, 20]
|
|
272
|
+
break
|
|
273
|
+
case 'error':
|
|
274
|
+
pattern = [50, 100, 50, 100, 50]
|
|
275
|
+
break
|
|
276
|
+
default:
|
|
277
|
+
pattern = 10
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
try {
|
|
281
|
+
return (navigator as any).vibrate(pattern)
|
|
282
|
+
} catch (error) {
|
|
283
|
+
console.warn('Vibration failed:', error)
|
|
284
|
+
return false
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return false
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Injetar CSS para animações visuais
|
|
292
|
+
const injectVisualCSS = () => {
|
|
293
|
+
const styleId = 'haptic-keyframes'
|
|
294
|
+
|
|
295
|
+
if (document.getElementById(styleId)) return
|
|
296
|
+
|
|
297
|
+
const style = document.createElement('style')
|
|
298
|
+
style.id = styleId
|
|
299
|
+
style.textContent = `
|
|
300
|
+
@keyframes haptic-pulse-light {
|
|
301
|
+
0% { transform: scale(1); }
|
|
302
|
+
50% { transform: scale(0.98); }
|
|
303
|
+
100% { transform: scale(1); }
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
@keyframes haptic-pulse-medium {
|
|
307
|
+
0% { transform: scale(1); }
|
|
308
|
+
50% { transform: scale(0.95); }
|
|
309
|
+
100% { transform: scale(1); }
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
@keyframes haptic-pulse-heavy {
|
|
313
|
+
0% { transform: scale(1); }
|
|
314
|
+
50% { transform: scale(0.92); }
|
|
315
|
+
100% { transform: scale(1); }
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
@keyframes haptic-success {
|
|
319
|
+
0% { transform: scale(1); filter: brightness(1); }
|
|
320
|
+
50% { transform: scale(1.02); filter: brightness(1.1); }
|
|
321
|
+
100% { transform: scale(1); filter: brightness(1); }
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
@keyframes haptic-error {
|
|
325
|
+
0% { transform: translateX(0); }
|
|
326
|
+
25% { transform: translateX(-2px); }
|
|
327
|
+
75% { transform: translateX(2px); }
|
|
328
|
+
100% { transform: translateX(0); }
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
@media (prefers-reduced-motion: reduce) {
|
|
332
|
+
@keyframes haptic-pulse-light,
|
|
333
|
+
@keyframes haptic-pulse-medium,
|
|
334
|
+
@keyframes haptic-pulse-heavy,
|
|
335
|
+
@keyframes haptic-success,
|
|
336
|
+
@keyframes haptic-error {
|
|
337
|
+
0%, 100% { transform: none; filter: none; }
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
`
|
|
341
|
+
|
|
342
|
+
document.head.appendChild(style)
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// Feedback visual
|
|
346
|
+
const triggerVisualFeedback = (element: HTMLElement | null, type: HapticType | NotificationType) => {
|
|
347
|
+
if (!element) return
|
|
348
|
+
|
|
349
|
+
injectVisualCSS()
|
|
350
|
+
|
|
351
|
+
const originalAnimation = element.style.animation
|
|
352
|
+
let animation: string
|
|
353
|
+
let duration: number
|
|
354
|
+
|
|
355
|
+
switch (type) {
|
|
356
|
+
case 'light':
|
|
357
|
+
animation = 'haptic-pulse-light 0.15s ease-out'
|
|
358
|
+
duration = 150
|
|
359
|
+
break
|
|
360
|
+
case 'medium':
|
|
361
|
+
animation = 'haptic-pulse-medium 0.2s ease-out'
|
|
362
|
+
duration = 200
|
|
363
|
+
break
|
|
364
|
+
case 'heavy':
|
|
365
|
+
animation = 'haptic-pulse-heavy 0.25s ease-out'
|
|
366
|
+
duration = 250
|
|
367
|
+
break
|
|
368
|
+
case 'success':
|
|
369
|
+
animation = 'haptic-success 0.3s ease-out'
|
|
370
|
+
duration = 300
|
|
371
|
+
break
|
|
372
|
+
case 'warning':
|
|
373
|
+
animation = 'haptic-pulse-medium 0.2s ease-out'
|
|
374
|
+
duration = 200
|
|
375
|
+
break
|
|
376
|
+
case 'error':
|
|
377
|
+
animation = 'haptic-error 0.4s ease-out'
|
|
378
|
+
duration = 400
|
|
379
|
+
break
|
|
380
|
+
default:
|
|
381
|
+
animation = 'haptic-pulse-light 0.15s ease-out'
|
|
382
|
+
duration = 150
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
element.style.animation = animation
|
|
386
|
+
|
|
387
|
+
setTimeout(() => {
|
|
388
|
+
element.style.animation = originalAnimation
|
|
389
|
+
}, duration)
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// Feedback combinado (háptico + visual)
|
|
393
|
+
const feedback = (element: HTMLElement | null, type: HapticType | NotificationType) => {
|
|
394
|
+
const hapticResult = triggerHaptic(type)
|
|
395
|
+
triggerVisualFeedback(element, type)
|
|
396
|
+
return hapticResult
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// Verificar suporte (método público)
|
|
400
|
+
const checkSupport = () => {
|
|
401
|
+
const hasSupport = detectHapticSupport()
|
|
402
|
+
isSupported.value = hasSupport
|
|
403
|
+
return hasSupport
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// Inicializar detecção de suporte
|
|
407
|
+
checkSupport()
|
|
408
|
+
|
|
409
|
+
return {
|
|
410
|
+
// Estado
|
|
411
|
+
isSupported,
|
|
412
|
+
isEnabled,
|
|
413
|
+
canVibrate,
|
|
414
|
+
hasVisualFeedback,
|
|
415
|
+
activeVisualFeedback,
|
|
416
|
+
|
|
417
|
+
// Métodos principais (compatíveis com testes)
|
|
418
|
+
triggerHaptic,
|
|
419
|
+
triggerVisualFeedback,
|
|
420
|
+
feedback,
|
|
421
|
+
checkSupport,
|
|
422
|
+
|
|
423
|
+
// Métodos de feedback específicos
|
|
424
|
+
light,
|
|
425
|
+
medium,
|
|
426
|
+
heavy,
|
|
427
|
+
selection,
|
|
428
|
+
impact,
|
|
429
|
+
notification,
|
|
430
|
+
custom,
|
|
431
|
+
|
|
432
|
+
// Controles
|
|
433
|
+
enable,
|
|
434
|
+
disable,
|
|
435
|
+
toggle,
|
|
436
|
+
|
|
437
|
+
// Utilitários
|
|
438
|
+
detectHapticSupport
|
|
439
|
+
}
|
|
440
|
+
}
|