@therealtinhtute/baroiplayer 1.2.0 → 2.0.0-beta.1
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 +91 -73
- package/dist/components/icons/index.d.ts +36 -0
- package/dist/components/icons/index.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/ArrowLeftIcon.d.ts +4 -0
- package/dist/components/icons/svg-icons/ArrowLeftIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/ArrowRightIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/ArrowRightIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/AudioIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/AudioIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/BackwardIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/BackwardIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/CameraIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/CameraIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/CheckIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/CheckIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/EnablePiPIcon.d.ts +4 -0
- package/dist/components/icons/svg-icons/EnablePiPIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/ForwardIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/ForwardIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/FullscreenEnterIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/FullscreenEnterIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/FullscreenExitIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/FullscreenExitIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/LoadingIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/LoadingIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/PauseIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/PauseIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/PlayIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/PlayIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/PlaybackSpeedIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/PlaybackSpeedIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/QualityIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/QualityIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/SettingsIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/SettingsIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/SliderIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/SliderIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/SubtitleIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/SubtitleIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/SubtitleOffIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/SubtitleOffIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/UnPiPIcon.d.ts +4 -0
- package/dist/components/icons/svg-icons/UnPiPIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/VolumeMutedIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/VolumeMutedIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/VolumeOneIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/VolumeOneIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/VolumeThreeIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/VolumeThreeIcon.d.ts.map +1 -0
- package/dist/components/icons/svg-icons/VolumeTwoIcon.d.ts +5 -0
- package/dist/components/icons/svg-icons/VolumeTwoIcon.d.ts.map +1 -0
- package/dist/components/variants/gradient/gradient-audio.d.ts +13 -0
- package/dist/components/variants/gradient/gradient-audio.d.ts.map +1 -0
- package/dist/components/variants/gradient/gradient-controls.d.ts +4 -0
- package/dist/components/variants/gradient/gradient-controls.d.ts.map +1 -0
- package/dist/components/variants/gradient/gradient-glyphs.d.ts +30 -0
- package/dist/components/variants/gradient/gradient-glyphs.d.ts.map +1 -0
- package/dist/components/variants/gradient/gradient-video.d.ts +16 -0
- package/dist/components/variants/gradient/gradient-video.d.ts.map +1 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -112
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +786 -6271
- package/dist/index.mjs.map +1 -1
- package/dist/package.json +3 -0
- package/package.json +110 -108
- package/src/components/variants/gradient/gradient-audio.tsx +47 -0
- package/src/components/variants/gradient/gradient-controls.tsx +254 -0
- package/src/components/variants/gradient/gradient-glyphs.test.tsx +69 -0
- package/src/components/variants/gradient/gradient-glyphs.tsx +129 -0
- package/src/components/variants/gradient/gradient-skin.css +211 -0
- package/src/components/variants/gradient/gradient-video.tsx +70 -0
- package/src/index.ts +5 -198
- package/src/test/accessibility-utils.ts +0 -59
- package/dist/context/media.js +0 -2
- package/dist/context/media.js.map +0 -1
- package/dist/context/media.mjs +0 -15
- package/dist/context/media.mjs.map +0 -1
- package/dist/context/store.js +0 -2
- package/dist/context/store.js.map +0 -1
- package/dist/context/store.mjs +0 -5
- package/dist/context/store.mjs.map +0 -1
- package/dist/context-BYwDoSRX.js +0 -1172
- package/dist/context-BYwDoSRX.js.map +0 -1
- package/dist/context-eNS62_ac.cjs +0 -23
- package/dist/context-eNS62_ac.cjs.map +0 -1
- package/dist/core-events-B1iM2F46.cjs +0 -2
- package/dist/core-events-B1iM2F46.cjs.map +0 -1
- package/dist/core-events-DunPHKRE.js +0 -484
- package/dist/core-events-DunPHKRE.js.map +0 -1
- package/dist/core-plugins-By-4-kGs.cjs +0 -2
- package/dist/core-plugins-By-4-kGs.cjs.map +0 -1
- package/dist/core-plugins-DSBWcTuX.js +0 -821
- package/dist/core-plugins-DSBWcTuX.js.map +0 -1
- package/dist/core.js +0 -37
- package/dist/core.js.map +0 -1
- package/dist/core.mjs +0 -1233
- package/dist/core.mjs.map +0 -1
- package/dist/enhanced-components-B_l3cist.js +0 -1142
- package/dist/enhanced-components-B_l3cist.js.map +0 -1
- package/dist/enhanced-components-BspFs9OO.cjs +0 -2
- package/dist/enhanced-components-BspFs9OO.cjs.map +0 -1
- package/dist/hooks-BXwI8QG6.cjs +0 -4
- package/dist/hooks-BXwI8QG6.cjs.map +0 -1
- package/dist/hooks-Bpi-jDiO.js +0 -1816
- package/dist/hooks-Bpi-jDiO.js.map +0 -1
- package/dist/minimal-components-C4z900Ro.js +0 -1926
- package/dist/minimal-components-C4z900Ro.js.map +0 -1
- package/dist/minimal-components-v4qBp6jv.cjs +0 -2
- package/dist/minimal-components-v4qBp6jv.cjs.map +0 -1
- package/dist/minimal-components.css +0 -1
- package/dist/mona-loading.gif +0 -0
- package/dist/performance-monitor-C5k6FDXw.js +0 -301
- package/dist/performance-monitor-C5k6FDXw.js.map +0 -1
- package/dist/performance-monitor-lJmuUjQQ.cjs +0 -2
- package/dist/performance-monitor-lJmuUjQQ.cjs.map +0 -1
- package/dist/utils-CFOue_9K.cjs +0 -9
- package/dist/utils-CFOue_9K.cjs.map +0 -1
- package/dist/utils-Dzpl2ArK.js +0 -2844
- package/dist/utils-Dzpl2ArK.js.map +0 -1
- package/dist/utils.js +0 -2
- package/dist/utils.js.map +0 -1
- package/dist/utils.mjs +0 -11
- package/dist/utils.mjs.map +0 -1
- package/src/adapters/videojs-adapter.tsx +0 -470
- package/src/assets/mona-loading.gif +0 -0
- package/src/components/AnimateLoading.tsx +0 -107
- package/src/components/LoadingState.tsx +0 -239
- package/src/components/__tests__/media-player-accessibility.test.tsx +0 -510
- package/src/components/__tests__/media-player-react19.test.tsx +0 -457
- package/src/components/accessibility/keyboard-help-overlay.tsx +0 -207
- package/src/components/audio-player.tsx +0 -85
- package/src/components/basic/index.ts +0 -37
- package/src/components/enhanced/advanced-features.tsx +0 -311
- package/src/components/enhanced/debug-panel.tsx +0 -448
- package/src/components/enhanced/enhanced-controls.tsx +0 -597
- package/src/components/enhanced/enhanced-media-player.tsx +0 -566
- package/src/components/enhanced/error-handling.tsx +0 -338
- package/src/components/enhanced/index.ts +0 -39
- package/src/components/enhanced/media-player-enhanced.tsx +0 -383
- package/src/components/examples/basic-video-player.tsx +0 -50
- package/src/components/examples/custom-controls-example.tsx +0 -63
- package/src/components/examples/enhanced-controls-example.tsx +0 -100
- package/src/components/examples/enhanced-media-player-example.tsx +0 -302
- package/src/components/examples/loading-states-demo.tsx +0 -142
- package/src/components/examples/react-19-demo.tsx +0 -353
- package/src/components/examples/volume-orientation-demo.tsx +0 -106
- package/src/components/icon-demo.tsx +0 -196
- package/src/components/legacy.tsx +0 -87
- package/src/components/media-metadata-display.tsx +0 -99
- package/src/components/media-player-audio.tsx +0 -39
- package/src/components/media-player-controls.tsx +0 -223
- package/src/components/media-player-error.tsx +0 -163
- package/src/components/media-player-fullscreen.tsx +0 -109
- package/src/components/media-player-hls.tsx +0 -111
- package/src/components/media-player-loading.tsx +0 -76
- package/src/components/media-player-play.tsx +0 -75
- package/src/components/media-player-root.tsx +0 -338
- package/src/components/media-player-seek.tsx +0 -168
- package/src/components/media-player-time.tsx +0 -99
- package/src/components/media-player-tooltip.tsx +0 -58
- package/src/components/media-player-video.tsx +0 -54
- package/src/components/media-player-volume.tsx +0 -155
- package/src/components/media-player.tsx +0 -292
- package/src/components/media-suspense.tsx +0 -344
- package/src/components/player-settings-form.tsx +0 -158
- package/src/components/react-player-wrapper.tsx +0 -651
- package/src/components/simple-video-player.tsx +0 -62
- package/src/components/ui/blur-poster.tsx +0 -93
- package/src/components/ui/empty-state.tsx +0 -91
- package/src/components/ui/enhanced-seek-bar.tsx +0 -254
- package/src/components/ui/error-state.tsx +0 -124
- package/src/components/ui/fullscreen-button.tsx +0 -81
- package/src/components/ui/loading-skeleton.tsx +0 -107
- package/src/components/ui/media-resource-preloader.tsx +0 -458
- package/src/components/ui/offline-message.tsx +0 -98
- package/src/components/ui/play-button.tsx +0 -99
- package/src/components/ui/seek-bar.tsx +0 -191
- package/src/components/ui/time-display.tsx +0 -61
- package/src/components/ui/volume-control.tsx +0 -190
- package/src/components/unified/base-media-player.tsx +0 -252
- package/src/components/unified/media-player.tsx +0 -75
- package/src/components/variants/minimal/AccessibleMinimalPlayer.tsx +0 -587
- package/src/components/variants/minimal/EnhancedMinimalMediaPlayer.tsx +0 -573
- package/src/components/variants/minimal/MinimalControls.tsx +0 -124
- package/src/components/variants/minimal/MinimalLoading.tsx +0 -28
- package/src/components/variants/minimal/MinimalMediaPlayer.tsx +0 -318
- package/src/components/variants/minimal/MinimalOverlay.tsx +0 -58
- package/src/components/variants/minimal/MinimalPlayButton.tsx +0 -56
- package/src/components/variants/minimal/MinimalSeekBar.tsx +0 -140
- package/src/components/variants/minimal/MinimalVolumeControl.tsx +0 -75
- package/src/components/variants/minimal/SimpleMinimalPlayer.tsx +0 -206
- package/src/components/variants/minimal/components/CenterPlayButton.tsx +0 -22
- package/src/components/variants/minimal/components/ControlBar.tsx +0 -142
- package/src/components/variants/minimal/components/EnhancedSettingsMenu.tsx +0 -412
- package/src/components/variants/minimal/components/PlaybackControls.tsx +0 -46
- package/src/components/variants/minimal/components/RightControls.tsx +0 -164
- package/src/components/variants/minimal/components/SeekBar.tsx +0 -127
- package/src/components/variants/minimal/components/SettingsDropdown.tsx +0 -68
- package/src/components/variants/minimal/components/SubtitleDisplay.tsx +0 -21
- package/src/components/variants/minimal/components/TimeDisplay.tsx +0 -15
- package/src/components/variants/minimal/components/VideoElement.tsx +0 -33
- package/src/components/variants/minimal/components/VolumeControl.tsx +0 -220
- package/src/components/variants/minimal/index.ts +0 -23
- package/src/components/video-player.tsx +0 -100
- package/src/context/__tests__/media-store.test.ts +0 -509
- package/src/context/error-handling.ts +0 -398
- package/src/context/media-context.tsx +0 -254
- package/src/context/media-provider.tsx +0 -264
- package/src/context/media-store.ts +0 -387
- package/src/context/persistence.ts +0 -462
- package/src/core/events/event-system.ts +0 -448
- package/src/core/events/hooks.ts +0 -325
- package/src/core/events/index.ts +0 -22
- package/src/core/events/middleware.ts +0 -286
- package/src/core/index.ts +0 -22
- package/src/core/optimization/bundle-optimizer.tsx +0 -312
- package/src/core/performance/cicd.ts +0 -98
- package/src/core/performance/index.ts +0 -38
- package/src/core/performance/media-loading-optimizer.ts +0 -544
- package/src/core/performance/performance-budgets.ts +0 -437
- package/src/core/performance/performance-monitor.tsx +0 -488
- package/src/core/performance/performance-testing.ts +0 -461
- package/src/core/plugins/__tests__/registry.test.ts +0 -595
- package/src/core/plugins/base-plugin.ts +0 -225
- package/src/core/plugins/enhanced-plugin-system.ts +0 -435
- package/src/core/plugins/examples/analytics-plugin.ts +0 -241
- package/src/core/plugins/index.ts +0 -39
- package/src/core/plugins/registry.ts +0 -546
- package/src/core/plugins/types.ts +0 -169
- package/src/core/plugins/utils.ts +0 -317
- package/src/core/progressive-loading.tsx +0 -331
- package/src/core/providers/enhanced-hls-provider.ts +0 -307
- package/src/core/providers/lazy-provider.tsx +0 -14
- package/src/core/providers/service-provider.tsx +0 -164
- package/src/core/utils.tsx +0 -34
- package/src/features/media-session/media-session-manager.ts +0 -411
- package/src/features/picture-in-picture/pip-manager.ts +0 -428
- package/src/features/playlist/playlist-manager.ts +0 -626
- package/src/features/subtitles/subtitle-manager.ts +0 -435
- package/src/features/subtitles/subtitle-parser.ts +0 -284
- package/src/features/thumbnails/thumbnail-generator.ts +0 -528
- package/src/hooks/__tests__/currentTime-fix.test.ts +0 -149
- package/src/hooks/__tests__/use-media-player.test.ts +0 -712
- package/src/hooks/__tests__/use-media-state.test.tsx +0 -316
- package/src/hooks/accessibility/index.ts +0 -27
- package/src/hooks/accessibility/use-accessibility-preferences.ts +0 -190
- package/src/hooks/accessibility/use-focus-management.ts +0 -183
- package/src/hooks/accessibility/use-keyboard-shortcuts.ts +0 -152
- package/src/hooks/accessibility/use-screen-reader.ts +0 -212
- package/src/hooks/core/index.ts +0 -47
- package/src/hooks/legacy.ts +0 -21
- package/src/hooks/use-buffer-health.ts +0 -218
- package/src/hooks/use-enhanced-media-player.ts +0 -575
- package/src/hooks/use-focus-trap.tsx +0 -162
- package/src/hooks/use-intelligent-preloading.ts +0 -387
- package/src/hooks/use-keyboard-controls.ts +0 -115
- package/src/hooks/use-keyboard-shortcuts.ts +0 -255
- package/src/hooks/use-media-actions.ts +0 -184
- package/src/hooks/use-media-metadata.ts +0 -91
- package/src/hooks/use-media-optimistic.ts +0 -264
- package/src/hooks/use-media-player.ts +0 -343
- package/src/hooks/use-media-state.ts +0 -194
- package/src/hooks/use-memory-optimization.ts +0 -360
- package/src/hooks/use-network-status.ts +0 -124
- package/src/hooks/use-optimistic-controls.ts +0 -95
- package/src/hooks/use-optimized-media.ts +0 -283
- package/src/hooks/use-smart-preload.ts +0 -229
- package/src/hooks/use-touch-gestures.ts +0 -461
- package/src/hooks/useEnhancedSubtitles.ts +0 -258
- package/src/hooks/useKeyboardShortcuts.ts +0 -106
- package/src/hooks/useMediaControls.ts +0 -52
- package/src/hooks/useScreenshot.ts +0 -61
- package/src/hooks/useSubtitles.ts +0 -91
- package/src/hooks/useVideoPlayer.ts +0 -278
- package/src/icons/components/FullscreenIcon.tsx +0 -36
- package/src/icons/components/SettingsIcon.tsx +0 -37
- package/src/icons/components/animated/LoadingIcon.tsx +0 -27
- package/src/icons/components/animated/PlayPauseIcon.tsx +0 -42
- package/src/icons/components/media/PauseIcon.tsx +0 -38
- package/src/icons/components/media/PlayIcon.tsx +0 -37
- package/src/icons/components/volume/VolumeIcon.tsx +0 -38
- package/src/icons/components/volume/VolumeOffIcon.tsx +0 -38
- package/src/icons/index.ts +0 -56
- package/src/icons/provider.tsx +0 -58
- package/src/icons/types.ts +0 -60
- package/src/index-enhanced.ts +0 -35
- package/src/index-legacy.ts +0 -324
- package/src/index.css +0 -102
- package/src/lib/__tests__/async-utils.test.ts +0 -291
- package/src/lib/async-utils.ts +0 -194
- package/src/lib/deprecation.ts +0 -51
- package/src/lib/format-time.ts +0 -37
- package/src/lib/index.ts +0 -4
- package/src/lib/utils.ts +0 -6
- package/src/styles/globals.css +0 -462
- package/src/styles/minimal-player.css +0 -621
- package/src/styles/pixel-art.css +0 -41
- package/src/styles/videojs.css +0 -100
- package/src/types/events.ts +0 -47
- package/src/types/formats.ts +0 -79
- package/src/types/index.ts +0 -203
- package/src/types/videojs-plugins.d.ts +0 -14
|
@@ -1,316 +0,0 @@
|
|
|
1
|
-
import { act, renderHook } from '@testing-library/react'
|
|
2
|
-
import type { ReactNode } from 'react'
|
|
3
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
4
|
-
import { MediaProvider } from '../../context/media-provider'
|
|
5
|
-
import { useAdaptiveMediaState, useEnhancedMediaState, useMediaState } from '../use-media-state'
|
|
6
|
-
|
|
7
|
-
describe('useMediaState', () => {
|
|
8
|
-
describe('Basic State Management', () => {
|
|
9
|
-
it('should initialize with default state', () => {
|
|
10
|
-
const { result } = renderHook(() => useMediaState())
|
|
11
|
-
|
|
12
|
-
expect(result.current.state).toEqual({
|
|
13
|
-
isPlaying: false,
|
|
14
|
-
currentTime: 0,
|
|
15
|
-
duration: 0,
|
|
16
|
-
volume: 1,
|
|
17
|
-
isMuted: false,
|
|
18
|
-
isLoading: false,
|
|
19
|
-
isFullscreen: false,
|
|
20
|
-
error: null,
|
|
21
|
-
buffered: null
|
|
22
|
-
})
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
it('should provide state update functions', () => {
|
|
26
|
-
const { result } = renderHook(() => useMediaState())
|
|
27
|
-
|
|
28
|
-
expect(typeof result.current.updateState).toBe('function')
|
|
29
|
-
expect(typeof result.current.setPlaying).toBe('function')
|
|
30
|
-
expect(typeof result.current.setCurrentTime).toBe('function')
|
|
31
|
-
expect(typeof result.current.setDuration).toBe('function')
|
|
32
|
-
expect(typeof result.current.setVolume).toBe('function')
|
|
33
|
-
expect(typeof result.current.setMuted).toBe('function')
|
|
34
|
-
expect(typeof result.current.setLoading).toBe('function')
|
|
35
|
-
expect(typeof result.current.setFullscreen).toBe('function')
|
|
36
|
-
expect(typeof result.current.setError).toBe('function')
|
|
37
|
-
expect(typeof result.current.setBuffered).toBe('function')
|
|
38
|
-
})
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
describe('State Updates', () => {
|
|
42
|
-
it('should update playing state', () => {
|
|
43
|
-
const { result } = renderHook(() => useMediaState())
|
|
44
|
-
|
|
45
|
-
act(() => {
|
|
46
|
-
result.current.setPlaying(true)
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
expect(result.current.state.isPlaying).toBe(true)
|
|
50
|
-
|
|
51
|
-
act(() => {
|
|
52
|
-
result.current.setPlaying(false)
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
expect(result.current.state.isPlaying).toBe(false)
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
it('should update current time', () => {
|
|
59
|
-
const { result } = renderHook(() => useMediaState())
|
|
60
|
-
|
|
61
|
-
act(() => {
|
|
62
|
-
result.current.setCurrentTime(42)
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
expect(result.current.state.currentTime).toBe(42)
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
it('should update duration', () => {
|
|
69
|
-
const { result } = renderHook(() => useMediaState())
|
|
70
|
-
|
|
71
|
-
act(() => {
|
|
72
|
-
result.current.setDuration(120)
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
expect(result.current.state.duration).toBe(120)
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
it('should update and clamp volume', () => {
|
|
79
|
-
const { result } = renderHook(() => useMediaState())
|
|
80
|
-
|
|
81
|
-
// Normal volume
|
|
82
|
-
act(() => {
|
|
83
|
-
result.current.setVolume(0.5)
|
|
84
|
-
})
|
|
85
|
-
expect(result.current.state.volume).toBe(0.5)
|
|
86
|
-
|
|
87
|
-
// Volume above 1 should clamp to 1
|
|
88
|
-
act(() => {
|
|
89
|
-
result.current.setVolume(1.5)
|
|
90
|
-
})
|
|
91
|
-
expect(result.current.state.volume).toBe(1)
|
|
92
|
-
|
|
93
|
-
// Volume below 0 should clamp to 0
|
|
94
|
-
act(() => {
|
|
95
|
-
result.current.setVolume(-0.5)
|
|
96
|
-
})
|
|
97
|
-
expect(result.current.state.volume).toBe(0)
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
it('should update muted state', () => {
|
|
101
|
-
const { result } = renderHook(() => useMediaState())
|
|
102
|
-
|
|
103
|
-
act(() => {
|
|
104
|
-
result.current.setMuted(true)
|
|
105
|
-
})
|
|
106
|
-
expect(result.current.state.isMuted).toBe(true)
|
|
107
|
-
|
|
108
|
-
act(() => {
|
|
109
|
-
result.current.setMuted(false)
|
|
110
|
-
})
|
|
111
|
-
expect(result.current.state.isMuted).toBe(false)
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
it('should update loading state', () => {
|
|
115
|
-
const { result } = renderHook(() => useMediaState())
|
|
116
|
-
|
|
117
|
-
act(() => {
|
|
118
|
-
result.current.setLoading(true)
|
|
119
|
-
})
|
|
120
|
-
expect(result.current.state.isLoading).toBe(true)
|
|
121
|
-
|
|
122
|
-
act(() => {
|
|
123
|
-
result.current.setLoading(false)
|
|
124
|
-
})
|
|
125
|
-
expect(result.current.state.isLoading).toBe(false)
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
it('should update fullscreen state', () => {
|
|
129
|
-
const { result } = renderHook(() => useMediaState())
|
|
130
|
-
|
|
131
|
-
act(() => {
|
|
132
|
-
result.current.setFullscreen(true)
|
|
133
|
-
})
|
|
134
|
-
expect(result.current.state.isFullscreen).toBe(true)
|
|
135
|
-
|
|
136
|
-
act(() => {
|
|
137
|
-
result.current.setFullscreen(false)
|
|
138
|
-
})
|
|
139
|
-
expect(result.current.state.isFullscreen).toBe(false)
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
it('should update error state', () => {
|
|
143
|
-
const { result } = renderHook(() => useMediaState())
|
|
144
|
-
|
|
145
|
-
act(() => {
|
|
146
|
-
result.current.setError('Network error')
|
|
147
|
-
})
|
|
148
|
-
expect(result.current.state.error).toBe('Network error')
|
|
149
|
-
|
|
150
|
-
act(() => {
|
|
151
|
-
result.current.setError(null)
|
|
152
|
-
})
|
|
153
|
-
expect(result.current.state.error).toBeNull()
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
it('should update buffered state', () => {
|
|
157
|
-
const { result } = renderHook(() => useMediaState())
|
|
158
|
-
const mockBuffered = {
|
|
159
|
-
length: 1,
|
|
160
|
-
start: () => 0,
|
|
161
|
-
end: () => 50
|
|
162
|
-
} as TimeRanges
|
|
163
|
-
|
|
164
|
-
act(() => {
|
|
165
|
-
result.current.setBuffered(mockBuffered)
|
|
166
|
-
})
|
|
167
|
-
expect(result.current.state.buffered).toBe(mockBuffered)
|
|
168
|
-
|
|
169
|
-
act(() => {
|
|
170
|
-
result.current.setBuffered(null)
|
|
171
|
-
})
|
|
172
|
-
expect(result.current.state.buffered).toBeNull()
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
it('should batch update multiple state properties', () => {
|
|
176
|
-
const { result } = renderHook(() => useMediaState())
|
|
177
|
-
|
|
178
|
-
act(() => {
|
|
179
|
-
result.current.updateState({
|
|
180
|
-
isPlaying: true,
|
|
181
|
-
currentTime: 30,
|
|
182
|
-
volume: 0.8,
|
|
183
|
-
isMuted: false
|
|
184
|
-
})
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
expect(result.current.state).toMatchObject({
|
|
188
|
-
isPlaying: true,
|
|
189
|
-
currentTime: 30,
|
|
190
|
-
volume: 0.8,
|
|
191
|
-
isMuted: false
|
|
192
|
-
})
|
|
193
|
-
})
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
describe('State Immutability', () => {
|
|
197
|
-
it('should not mutate previous state', () => {
|
|
198
|
-
const { result } = renderHook(() => useMediaState())
|
|
199
|
-
|
|
200
|
-
const previousState = result.current.state
|
|
201
|
-
|
|
202
|
-
act(() => {
|
|
203
|
-
result.current.setPlaying(true)
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
expect(previousState.isPlaying).toBe(false)
|
|
207
|
-
expect(result.current.state.isPlaying).toBe(true)
|
|
208
|
-
expect(result.current.state).not.toBe(previousState)
|
|
209
|
-
})
|
|
210
|
-
})
|
|
211
|
-
})
|
|
212
|
-
|
|
213
|
-
describe('useEnhancedMediaState', () => {
|
|
214
|
-
const wrapper = ({ children }: { children: ReactNode }) => (
|
|
215
|
-
<MediaProvider>{children}</MediaProvider>
|
|
216
|
-
)
|
|
217
|
-
|
|
218
|
-
it('should provide enhanced state with MediaProvider', () => {
|
|
219
|
-
const { result } = renderHook(() => useEnhancedMediaState(), { wrapper })
|
|
220
|
-
|
|
221
|
-
expect(result.current).toBeDefined()
|
|
222
|
-
expect(result.current.state).toBeDefined()
|
|
223
|
-
expect(result.current.actions).toBeDefined()
|
|
224
|
-
})
|
|
225
|
-
|
|
226
|
-
it('should fall back to legacy state if store is not enhanced', () => {
|
|
227
|
-
// Test fallback behavior when not in enhanced store context
|
|
228
|
-
const { result } = renderHook(() => useEnhancedMediaState(), { wrapper })
|
|
229
|
-
|
|
230
|
-
expect(result.current.state).toBeDefined()
|
|
231
|
-
})
|
|
232
|
-
|
|
233
|
-
it('should provide optimistic state values', () => {
|
|
234
|
-
const { result } = renderHook(() => useEnhancedMediaState(), { wrapper })
|
|
235
|
-
|
|
236
|
-
expect(result.current).toHaveProperty('state')
|
|
237
|
-
expect(result.current).toHaveProperty('actualState')
|
|
238
|
-
})
|
|
239
|
-
|
|
240
|
-
it('should provide computed values', () => {
|
|
241
|
-
const { result } = renderHook(() => useEnhancedMediaState(), { wrapper })
|
|
242
|
-
|
|
243
|
-
expect(result.current).toHaveProperty('progress')
|
|
244
|
-
expect(result.current).toHaveProperty('formattedTime')
|
|
245
|
-
expect(result.current).toHaveProperty('formattedDuration')
|
|
246
|
-
})
|
|
247
|
-
|
|
248
|
-
it('should provide action state for loading/error handling', () => {
|
|
249
|
-
const { result } = renderHook(() => useEnhancedMediaState(), { wrapper })
|
|
250
|
-
|
|
251
|
-
expect(result.current).toHaveProperty('isActionLoading')
|
|
252
|
-
expect(result.current).toHaveProperty('actionError')
|
|
253
|
-
expect(result.current).toHaveProperty('retryLastAction')
|
|
254
|
-
})
|
|
255
|
-
|
|
256
|
-
it('should provide legacy compatibility methods', () => {
|
|
257
|
-
const { result } = renderHook(() => useEnhancedMediaState(), { wrapper })
|
|
258
|
-
|
|
259
|
-
expect(typeof result.current.updateState).toBe('function')
|
|
260
|
-
expect(typeof result.current.setPlaying).toBe('function')
|
|
261
|
-
expect(typeof result.current.setCurrentTime).toBe('function')
|
|
262
|
-
expect(typeof result.current.setDuration).toBe('function')
|
|
263
|
-
expect(typeof result.current.setVolume).toBe('function')
|
|
264
|
-
expect(typeof result.current.setMuted).toBe('function')
|
|
265
|
-
})
|
|
266
|
-
|
|
267
|
-
it('should map legacy updates to new actions', () => {
|
|
268
|
-
const { result } = renderHook(() => useEnhancedMediaState(), { wrapper })
|
|
269
|
-
|
|
270
|
-
// Should not throw
|
|
271
|
-
act(() => {
|
|
272
|
-
result.current.updateState({
|
|
273
|
-
isPlaying: true,
|
|
274
|
-
volume: 0.5,
|
|
275
|
-
isMuted: false
|
|
276
|
-
})
|
|
277
|
-
})
|
|
278
|
-
|
|
279
|
-
expect(result.current.actions).toBeDefined()
|
|
280
|
-
})
|
|
281
|
-
})
|
|
282
|
-
|
|
283
|
-
describe('useAdaptiveMediaState', () => {
|
|
284
|
-
it('should use enhanced state when MediaProvider is available', () => {
|
|
285
|
-
const wrapper = ({ children }: { children: ReactNode }) => (
|
|
286
|
-
<MediaProvider>{children}</MediaProvider>
|
|
287
|
-
)
|
|
288
|
-
|
|
289
|
-
const { result } = renderHook(() => useAdaptiveMediaState(), { wrapper })
|
|
290
|
-
|
|
291
|
-
// Should have enhanced features
|
|
292
|
-
expect(result.current).toHaveProperty('actions')
|
|
293
|
-
expect(result.current).toHaveProperty('isActionLoading')
|
|
294
|
-
})
|
|
295
|
-
|
|
296
|
-
it('should fall back to legacy state without MediaProvider', () => {
|
|
297
|
-
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
298
|
-
|
|
299
|
-
const { result } = renderHook(() => useAdaptiveMediaState())
|
|
300
|
-
|
|
301
|
-
expect(result.current.state).toBeDefined()
|
|
302
|
-
|
|
303
|
-
consoleWarnSpy.mockRestore()
|
|
304
|
-
})
|
|
305
|
-
|
|
306
|
-
it('should handle context errors gracefully', () => {
|
|
307
|
-
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
308
|
-
|
|
309
|
-
// Should not throw
|
|
310
|
-
const { result } = renderHook(() => useAdaptiveMediaState())
|
|
311
|
-
|
|
312
|
-
expect(result.current).toBeDefined()
|
|
313
|
-
|
|
314
|
-
consoleWarnSpy.mockRestore()
|
|
315
|
-
})
|
|
316
|
-
})
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export {
|
|
2
|
-
useKeyboardShortcuts,
|
|
3
|
-
createMediaKeyboardShortcuts,
|
|
4
|
-
type KeyboardShortcut,
|
|
5
|
-
type UseKeyboardShortcutsOptions
|
|
6
|
-
} from "./use-keyboard-shortcuts"
|
|
7
|
-
|
|
8
|
-
export {
|
|
9
|
-
useFocusManagement,
|
|
10
|
-
useMediaPlayerFocus,
|
|
11
|
-
type FocusOptions,
|
|
12
|
-
type UseFocusManagementOptions
|
|
13
|
-
} from "./use-focus-management"
|
|
14
|
-
|
|
15
|
-
export {
|
|
16
|
-
useScreenReader,
|
|
17
|
-
useMediaScreenReader,
|
|
18
|
-
type AnnouncementPriority,
|
|
19
|
-
type UseScreenReaderOptions
|
|
20
|
-
} from "./use-screen-reader"
|
|
21
|
-
|
|
22
|
-
export {
|
|
23
|
-
useAccessibilityPreferences,
|
|
24
|
-
useAccessibilityStyles,
|
|
25
|
-
useFocusVisible,
|
|
26
|
-
type AccessibilityPreferences
|
|
27
|
-
} from "./use-accessibility-preferences"
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from "react"
|
|
2
|
-
|
|
3
|
-
export interface AccessibilityPreferences {
|
|
4
|
-
prefersReducedMotion: boolean
|
|
5
|
-
prefersHighContrast: boolean
|
|
6
|
-
prefersColorScheme: "light" | "dark" | "no-preference"
|
|
7
|
-
prefersReducedTransparency: boolean
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function useAccessibilityPreferences(): AccessibilityPreferences {
|
|
11
|
-
const [preferences, setPreferences] = useState<AccessibilityPreferences>({
|
|
12
|
-
prefersReducedMotion: false,
|
|
13
|
-
prefersHighContrast: false,
|
|
14
|
-
prefersColorScheme: "no-preference",
|
|
15
|
-
prefersReducedTransparency: false
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
const updatePreferences = useCallback(() => {
|
|
19
|
-
if (typeof window === "undefined") return
|
|
20
|
-
|
|
21
|
-
const prefersReducedMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches
|
|
22
|
-
const prefersHighContrast = window.matchMedia("(prefers-contrast: high)").matches
|
|
23
|
-
const prefersReducedTransparency = window.matchMedia(
|
|
24
|
-
"(prefers-reduced-transparency: reduce)"
|
|
25
|
-
).matches
|
|
26
|
-
|
|
27
|
-
let prefersColorScheme: "light" | "dark" | "no-preference" = "no-preference"
|
|
28
|
-
if (window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
|
29
|
-
prefersColorScheme = "dark"
|
|
30
|
-
} else if (window.matchMedia("(prefers-color-scheme: light)").matches) {
|
|
31
|
-
prefersColorScheme = "light"
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
setPreferences({
|
|
35
|
-
prefersReducedMotion,
|
|
36
|
-
prefersHighContrast,
|
|
37
|
-
prefersColorScheme,
|
|
38
|
-
prefersReducedTransparency
|
|
39
|
-
})
|
|
40
|
-
}, [])
|
|
41
|
-
|
|
42
|
-
useEffect(() => {
|
|
43
|
-
if (typeof window === "undefined") return
|
|
44
|
-
|
|
45
|
-
// Initial check
|
|
46
|
-
updatePreferences()
|
|
47
|
-
|
|
48
|
-
// Set up media query listeners
|
|
49
|
-
const mediaQueries = [
|
|
50
|
-
window.matchMedia("(prefers-reduced-motion: reduce)"),
|
|
51
|
-
window.matchMedia("(prefers-contrast: high)"),
|
|
52
|
-
window.matchMedia("(prefers-color-scheme: dark)"),
|
|
53
|
-
window.matchMedia("(prefers-color-scheme: light)"),
|
|
54
|
-
window.matchMedia("(prefers-reduced-transparency: reduce)")
|
|
55
|
-
]
|
|
56
|
-
|
|
57
|
-
// Add listeners
|
|
58
|
-
mediaQueries.forEach((mq) => {
|
|
59
|
-
mq.addEventListener("change", updatePreferences)
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
// Cleanup
|
|
63
|
-
return () => {
|
|
64
|
-
mediaQueries.forEach((mq) => {
|
|
65
|
-
mq.removeEventListener("change", updatePreferences)
|
|
66
|
-
})
|
|
67
|
-
}
|
|
68
|
-
}, [updatePreferences])
|
|
69
|
-
|
|
70
|
-
return preferences
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Hook for applying accessibility styles
|
|
74
|
-
export function useAccessibilityStyles() {
|
|
75
|
-
const preferences = useAccessibilityPreferences()
|
|
76
|
-
|
|
77
|
-
// Generate CSS custom properties based on preferences
|
|
78
|
-
const cssVariables = useCallback(() => {
|
|
79
|
-
const vars: Record<string, string> = {}
|
|
80
|
-
|
|
81
|
-
if (preferences.prefersHighContrast) {
|
|
82
|
-
vars["--media-contrast"] = "high"
|
|
83
|
-
vars["--media-bg-opacity"] = "1"
|
|
84
|
-
vars["--media-border-width"] = "2px"
|
|
85
|
-
vars["--media-focus-outline-width"] = "3px"
|
|
86
|
-
} else {
|
|
87
|
-
vars["--media-contrast"] = "normal"
|
|
88
|
-
vars["--media-bg-opacity"] = "0.8"
|
|
89
|
-
vars["--media-border-width"] = "1px"
|
|
90
|
-
vars["--media-focus-outline-width"] = "2px"
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (preferences.prefersReducedMotion) {
|
|
94
|
-
vars["--media-transition-duration"] = "0ms"
|
|
95
|
-
vars["--media-animation-duration"] = "0ms"
|
|
96
|
-
vars["--media-motion"] = "none"
|
|
97
|
-
} else {
|
|
98
|
-
vars["--media-transition-duration"] = "200ms"
|
|
99
|
-
vars["--media-animation-duration"] = "300ms"
|
|
100
|
-
vars["--media-motion"] = "auto"
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (preferences.prefersReducedTransparency) {
|
|
104
|
-
vars["--media-backdrop-blur"] = "0px"
|
|
105
|
-
vars["--media-bg-opacity"] = "1"
|
|
106
|
-
} else {
|
|
107
|
-
vars["--media-backdrop-blur"] = "10px"
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return vars
|
|
111
|
-
}, [preferences])
|
|
112
|
-
|
|
113
|
-
// Apply styles to document
|
|
114
|
-
const applyStyles = useCallback(() => {
|
|
115
|
-
if (typeof document === "undefined") return
|
|
116
|
-
|
|
117
|
-
const vars = cssVariables()
|
|
118
|
-
Object.entries(vars).forEach(([property, value]) => {
|
|
119
|
-
document.documentElement.style.setProperty(property, value)
|
|
120
|
-
})
|
|
121
|
-
}, [cssVariables])
|
|
122
|
-
|
|
123
|
-
useEffect(() => {
|
|
124
|
-
applyStyles()
|
|
125
|
-
}, [applyStyles])
|
|
126
|
-
|
|
127
|
-
return {
|
|
128
|
-
preferences,
|
|
129
|
-
cssVariables: cssVariables(),
|
|
130
|
-
applyStyles
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Hook for managing focus visibility
|
|
135
|
-
export function useFocusVisible() {
|
|
136
|
-
const [isFocusVisible, setIsFocusVisible] = useState(false)
|
|
137
|
-
|
|
138
|
-
useEffect(() => {
|
|
139
|
-
if (typeof window === "undefined") return
|
|
140
|
-
|
|
141
|
-
let hadKeyboardEvent = true
|
|
142
|
-
let keyboardThrottleTimeoutID: NodeJS.Timeout | undefined
|
|
143
|
-
|
|
144
|
-
const handleKeyDown = (e: KeyboardEvent) => {
|
|
145
|
-
if (e.metaKey || e.altKey || e.ctrlKey) {
|
|
146
|
-
return
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
hadKeyboardEvent = true
|
|
150
|
-
setIsFocusVisible(true)
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
const handlePointerDown = () => {
|
|
154
|
-
hadKeyboardEvent = false
|
|
155
|
-
setIsFocusVisible(false)
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const handleFocus = (e: FocusEvent) => {
|
|
159
|
-
if (hadKeyboardEvent || (e.target as HTMLElement)?.matches(":focus-visible")) {
|
|
160
|
-
setIsFocusVisible(true)
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
const handleBlur = () => {
|
|
165
|
-
setIsFocusVisible(false)
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
document.addEventListener("keydown", handleKeyDown, true)
|
|
169
|
-
document.addEventListener("mousedown", handlePointerDown, true)
|
|
170
|
-
document.addEventListener("pointerdown", handlePointerDown, true)
|
|
171
|
-
document.addEventListener("touchstart", handlePointerDown, true)
|
|
172
|
-
document.addEventListener("focus", handleFocus, true)
|
|
173
|
-
document.addEventListener("blur", handleBlur, true)
|
|
174
|
-
|
|
175
|
-
return () => {
|
|
176
|
-
document.removeEventListener("keydown", handleKeyDown, true)
|
|
177
|
-
document.removeEventListener("mousedown", handlePointerDown, true)
|
|
178
|
-
document.removeEventListener("pointerdown", handlePointerDown, true)
|
|
179
|
-
document.removeEventListener("touchstart", handlePointerDown, true)
|
|
180
|
-
document.removeEventListener("focus", handleFocus, true)
|
|
181
|
-
document.removeEventListener("blur", handleBlur, true)
|
|
182
|
-
|
|
183
|
-
if (keyboardThrottleTimeoutID) {
|
|
184
|
-
clearTimeout(keyboardThrottleTimeoutID)
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}, [])
|
|
188
|
-
|
|
189
|
-
return isFocusVisible
|
|
190
|
-
}
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useRef } from "react"
|
|
2
|
-
|
|
3
|
-
export interface FocusOptions {
|
|
4
|
-
preventScroll?: boolean
|
|
5
|
-
restoreFocus?: boolean
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface UseFocusManagementOptions {
|
|
9
|
-
restoreFocus?: boolean
|
|
10
|
-
initialFocus?: string | HTMLElement | (() => HTMLElement | null)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function useFocusManagement({
|
|
14
|
-
restoreFocus = true,
|
|
15
|
-
initialFocus
|
|
16
|
-
}: UseFocusManagementOptions = {}) {
|
|
17
|
-
const previousFocusRef = useRef<HTMLElement | null>(null)
|
|
18
|
-
const containerRef = useRef<HTMLElement | null>(null)
|
|
19
|
-
|
|
20
|
-
// Store the previously focused element
|
|
21
|
-
const storePreviousFocus = useCallback(() => {
|
|
22
|
-
previousFocusRef.current = document.activeElement as HTMLElement
|
|
23
|
-
}, [])
|
|
24
|
-
|
|
25
|
-
// Restore focus to the previously focused element
|
|
26
|
-
const restorePreviousFocus = useCallback(
|
|
27
|
-
(options: FocusOptions = {}) => {
|
|
28
|
-
if (previousFocusRef.current && restoreFocus) {
|
|
29
|
-
previousFocusRef.current.focus({
|
|
30
|
-
preventScroll: options.preventScroll
|
|
31
|
-
})
|
|
32
|
-
previousFocusRef.current = null
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
[restoreFocus]
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
// Focus an element by selector or element
|
|
39
|
-
const focusElement = useCallback(
|
|
40
|
-
(target: string | HTMLElement | (() => HTMLElement | null), options: FocusOptions = {}) => {
|
|
41
|
-
let element: HTMLElement | null = null
|
|
42
|
-
|
|
43
|
-
if (typeof target === "string") {
|
|
44
|
-
element =
|
|
45
|
-
(containerRef.current?.querySelector(target) as HTMLElement) ||
|
|
46
|
-
(document.querySelector(target) as HTMLElement)
|
|
47
|
-
} else if (typeof target === "function") {
|
|
48
|
-
element = target()
|
|
49
|
-
} else {
|
|
50
|
-
element = target
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (element) {
|
|
54
|
-
element.focus({
|
|
55
|
-
preventScroll: options.preventScroll
|
|
56
|
-
})
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
[]
|
|
60
|
-
)
|
|
61
|
-
|
|
62
|
-
// Get all focusable elements within a container
|
|
63
|
-
const getFocusableElements = useCallback((container?: HTMLElement) => {
|
|
64
|
-
const root = container || containerRef.current || document
|
|
65
|
-
const focusableSelectors = [
|
|
66
|
-
"button:not([disabled])",
|
|
67
|
-
"input:not([disabled])",
|
|
68
|
-
"textarea:not([disabled])",
|
|
69
|
-
"select:not([disabled])",
|
|
70
|
-
"a[href]",
|
|
71
|
-
'[tabindex]:not([tabindex="-1"])',
|
|
72
|
-
"audio[controls]",
|
|
73
|
-
"video[controls]",
|
|
74
|
-
'[contenteditable]:not([contenteditable="false"])'
|
|
75
|
-
].join(", ")
|
|
76
|
-
|
|
77
|
-
return Array.from(root.querySelectorAll(focusableSelectors)) as HTMLElement[]
|
|
78
|
-
}, [])
|
|
79
|
-
|
|
80
|
-
// Create a focus trap within the container
|
|
81
|
-
const createFocusTrap = useCallback(() => {
|
|
82
|
-
const handleKeyDown = (event: KeyboardEvent) => {
|
|
83
|
-
if (event.key !== "Tab") return
|
|
84
|
-
|
|
85
|
-
const focusableElements = getFocusableElements()
|
|
86
|
-
if (focusableElements.length === 0) return
|
|
87
|
-
|
|
88
|
-
const firstFocusable = focusableElements[0]
|
|
89
|
-
const lastFocusable = focusableElements[focusableElements.length - 1]
|
|
90
|
-
|
|
91
|
-
if (event.shiftKey) {
|
|
92
|
-
// Shift + Tab
|
|
93
|
-
if (document.activeElement === firstFocusable) {
|
|
94
|
-
event.preventDefault()
|
|
95
|
-
lastFocusable?.focus()
|
|
96
|
-
}
|
|
97
|
-
} else {
|
|
98
|
-
// Tab
|
|
99
|
-
if (document.activeElement === lastFocusable) {
|
|
100
|
-
event.preventDefault()
|
|
101
|
-
firstFocusable?.focus()
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
document.addEventListener("keydown", handleKeyDown)
|
|
107
|
-
return () => document.removeEventListener("keydown", handleKeyDown)
|
|
108
|
-
}, [getFocusableElements])
|
|
109
|
-
|
|
110
|
-
// Navigate to next/previous focusable element
|
|
111
|
-
const navigateFocus = useCallback(
|
|
112
|
-
(direction: "next" | "previous") => {
|
|
113
|
-
const focusableElements = getFocusableElements()
|
|
114
|
-
const currentIndex = focusableElements.indexOf(document.activeElement as HTMLElement)
|
|
115
|
-
|
|
116
|
-
let nextIndex: number
|
|
117
|
-
if (direction === "next") {
|
|
118
|
-
nextIndex = currentIndex + 1 >= focusableElements.length ? 0 : currentIndex + 1
|
|
119
|
-
} else {
|
|
120
|
-
nextIndex = currentIndex - 1 < 0 ? focusableElements.length - 1 : currentIndex - 1
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
focusableElements[nextIndex]?.focus()
|
|
124
|
-
},
|
|
125
|
-
[getFocusableElements]
|
|
126
|
-
)
|
|
127
|
-
|
|
128
|
-
// Initialize focus on mount
|
|
129
|
-
useEffect(() => {
|
|
130
|
-
if (initialFocus) {
|
|
131
|
-
const timer = setTimeout(() => {
|
|
132
|
-
focusElement(initialFocus)
|
|
133
|
-
}, 0)
|
|
134
|
-
return () => clearTimeout(timer)
|
|
135
|
-
}
|
|
136
|
-
}, [initialFocus, focusElement])
|
|
137
|
-
|
|
138
|
-
return {
|
|
139
|
-
containerRef,
|
|
140
|
-
storePreviousFocus,
|
|
141
|
-
restorePreviousFocus,
|
|
142
|
-
focusElement,
|
|
143
|
-
getFocusableElements,
|
|
144
|
-
createFocusTrap,
|
|
145
|
-
navigateFocus
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// Hook for managing focus within media player controls
|
|
150
|
-
export function useMediaPlayerFocus() {
|
|
151
|
-
const focusManager = useFocusManagement({
|
|
152
|
-
restoreFocus: true,
|
|
153
|
-
initialFocus: '[data-media-control="play-pause"]'
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
// Focus on play/pause button
|
|
157
|
-
const focusPlayPause = useCallback(() => {
|
|
158
|
-
focusManager.focusElement('[data-media-control="play-pause"]')
|
|
159
|
-
}, [focusManager])
|
|
160
|
-
|
|
161
|
-
// Focus on seek bar
|
|
162
|
-
const focusSeekBar = useCallback(() => {
|
|
163
|
-
focusManager.focusElement('[data-media-control="seek-bar"]')
|
|
164
|
-
}, [focusManager])
|
|
165
|
-
|
|
166
|
-
// Focus on volume control
|
|
167
|
-
const focusVolumeControl = useCallback(() => {
|
|
168
|
-
focusManager.focusElement('[data-media-control="volume"]')
|
|
169
|
-
}, [focusManager])
|
|
170
|
-
|
|
171
|
-
// Focus on settings button
|
|
172
|
-
const focusSettings = useCallback(() => {
|
|
173
|
-
focusManager.focusElement('[data-media-control="settings"]')
|
|
174
|
-
}, [focusManager])
|
|
175
|
-
|
|
176
|
-
return {
|
|
177
|
-
...focusManager,
|
|
178
|
-
focusPlayPause,
|
|
179
|
-
focusSeekBar,
|
|
180
|
-
focusVolumeControl,
|
|
181
|
-
focusSettings
|
|
182
|
-
}
|
|
183
|
-
}
|