@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.
Files changed (305) hide show
  1. package/README.md +91 -73
  2. package/dist/components/icons/index.d.ts +36 -0
  3. package/dist/components/icons/index.d.ts.map +1 -0
  4. package/dist/components/icons/svg-icons/ArrowLeftIcon.d.ts +4 -0
  5. package/dist/components/icons/svg-icons/ArrowLeftIcon.d.ts.map +1 -0
  6. package/dist/components/icons/svg-icons/ArrowRightIcon.d.ts +5 -0
  7. package/dist/components/icons/svg-icons/ArrowRightIcon.d.ts.map +1 -0
  8. package/dist/components/icons/svg-icons/AudioIcon.d.ts +5 -0
  9. package/dist/components/icons/svg-icons/AudioIcon.d.ts.map +1 -0
  10. package/dist/components/icons/svg-icons/BackwardIcon.d.ts +5 -0
  11. package/dist/components/icons/svg-icons/BackwardIcon.d.ts.map +1 -0
  12. package/dist/components/icons/svg-icons/CameraIcon.d.ts +5 -0
  13. package/dist/components/icons/svg-icons/CameraIcon.d.ts.map +1 -0
  14. package/dist/components/icons/svg-icons/CheckIcon.d.ts +5 -0
  15. package/dist/components/icons/svg-icons/CheckIcon.d.ts.map +1 -0
  16. package/dist/components/icons/svg-icons/EnablePiPIcon.d.ts +4 -0
  17. package/dist/components/icons/svg-icons/EnablePiPIcon.d.ts.map +1 -0
  18. package/dist/components/icons/svg-icons/ForwardIcon.d.ts +5 -0
  19. package/dist/components/icons/svg-icons/ForwardIcon.d.ts.map +1 -0
  20. package/dist/components/icons/svg-icons/FullscreenEnterIcon.d.ts +5 -0
  21. package/dist/components/icons/svg-icons/FullscreenEnterIcon.d.ts.map +1 -0
  22. package/dist/components/icons/svg-icons/FullscreenExitIcon.d.ts +5 -0
  23. package/dist/components/icons/svg-icons/FullscreenExitIcon.d.ts.map +1 -0
  24. package/dist/components/icons/svg-icons/LoadingIcon.d.ts +5 -0
  25. package/dist/components/icons/svg-icons/LoadingIcon.d.ts.map +1 -0
  26. package/dist/components/icons/svg-icons/PauseIcon.d.ts +5 -0
  27. package/dist/components/icons/svg-icons/PauseIcon.d.ts.map +1 -0
  28. package/dist/components/icons/svg-icons/PlayIcon.d.ts +5 -0
  29. package/dist/components/icons/svg-icons/PlayIcon.d.ts.map +1 -0
  30. package/dist/components/icons/svg-icons/PlaybackSpeedIcon.d.ts +5 -0
  31. package/dist/components/icons/svg-icons/PlaybackSpeedIcon.d.ts.map +1 -0
  32. package/dist/components/icons/svg-icons/QualityIcon.d.ts +5 -0
  33. package/dist/components/icons/svg-icons/QualityIcon.d.ts.map +1 -0
  34. package/dist/components/icons/svg-icons/SettingsIcon.d.ts +5 -0
  35. package/dist/components/icons/svg-icons/SettingsIcon.d.ts.map +1 -0
  36. package/dist/components/icons/svg-icons/SliderIcon.d.ts +5 -0
  37. package/dist/components/icons/svg-icons/SliderIcon.d.ts.map +1 -0
  38. package/dist/components/icons/svg-icons/SubtitleIcon.d.ts +5 -0
  39. package/dist/components/icons/svg-icons/SubtitleIcon.d.ts.map +1 -0
  40. package/dist/components/icons/svg-icons/SubtitleOffIcon.d.ts +5 -0
  41. package/dist/components/icons/svg-icons/SubtitleOffIcon.d.ts.map +1 -0
  42. package/dist/components/icons/svg-icons/UnPiPIcon.d.ts +4 -0
  43. package/dist/components/icons/svg-icons/UnPiPIcon.d.ts.map +1 -0
  44. package/dist/components/icons/svg-icons/VolumeMutedIcon.d.ts +5 -0
  45. package/dist/components/icons/svg-icons/VolumeMutedIcon.d.ts.map +1 -0
  46. package/dist/components/icons/svg-icons/VolumeOneIcon.d.ts +5 -0
  47. package/dist/components/icons/svg-icons/VolumeOneIcon.d.ts.map +1 -0
  48. package/dist/components/icons/svg-icons/VolumeThreeIcon.d.ts +5 -0
  49. package/dist/components/icons/svg-icons/VolumeThreeIcon.d.ts.map +1 -0
  50. package/dist/components/icons/svg-icons/VolumeTwoIcon.d.ts +5 -0
  51. package/dist/components/icons/svg-icons/VolumeTwoIcon.d.ts.map +1 -0
  52. package/dist/components/variants/gradient/gradient-audio.d.ts +13 -0
  53. package/dist/components/variants/gradient/gradient-audio.d.ts.map +1 -0
  54. package/dist/components/variants/gradient/gradient-controls.d.ts +4 -0
  55. package/dist/components/variants/gradient/gradient-controls.d.ts.map +1 -0
  56. package/dist/components/variants/gradient/gradient-glyphs.d.ts +30 -0
  57. package/dist/components/variants/gradient/gradient-glyphs.d.ts.map +1 -0
  58. package/dist/components/variants/gradient/gradient-video.d.ts +16 -0
  59. package/dist/components/variants/gradient/gradient-video.d.ts.map +1 -0
  60. package/dist/index.css +1 -1
  61. package/dist/index.d.ts +5 -0
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js +2 -112
  64. package/dist/index.js.map +1 -1
  65. package/dist/index.mjs +786 -6271
  66. package/dist/index.mjs.map +1 -1
  67. package/dist/package.json +3 -0
  68. package/package.json +110 -108
  69. package/src/components/variants/gradient/gradient-audio.tsx +47 -0
  70. package/src/components/variants/gradient/gradient-controls.tsx +254 -0
  71. package/src/components/variants/gradient/gradient-glyphs.test.tsx +69 -0
  72. package/src/components/variants/gradient/gradient-glyphs.tsx +129 -0
  73. package/src/components/variants/gradient/gradient-skin.css +211 -0
  74. package/src/components/variants/gradient/gradient-video.tsx +70 -0
  75. package/src/index.ts +5 -198
  76. package/src/test/accessibility-utils.ts +0 -59
  77. package/dist/context/media.js +0 -2
  78. package/dist/context/media.js.map +0 -1
  79. package/dist/context/media.mjs +0 -15
  80. package/dist/context/media.mjs.map +0 -1
  81. package/dist/context/store.js +0 -2
  82. package/dist/context/store.js.map +0 -1
  83. package/dist/context/store.mjs +0 -5
  84. package/dist/context/store.mjs.map +0 -1
  85. package/dist/context-BYwDoSRX.js +0 -1172
  86. package/dist/context-BYwDoSRX.js.map +0 -1
  87. package/dist/context-eNS62_ac.cjs +0 -23
  88. package/dist/context-eNS62_ac.cjs.map +0 -1
  89. package/dist/core-events-B1iM2F46.cjs +0 -2
  90. package/dist/core-events-B1iM2F46.cjs.map +0 -1
  91. package/dist/core-events-DunPHKRE.js +0 -484
  92. package/dist/core-events-DunPHKRE.js.map +0 -1
  93. package/dist/core-plugins-By-4-kGs.cjs +0 -2
  94. package/dist/core-plugins-By-4-kGs.cjs.map +0 -1
  95. package/dist/core-plugins-DSBWcTuX.js +0 -821
  96. package/dist/core-plugins-DSBWcTuX.js.map +0 -1
  97. package/dist/core.js +0 -37
  98. package/dist/core.js.map +0 -1
  99. package/dist/core.mjs +0 -1233
  100. package/dist/core.mjs.map +0 -1
  101. package/dist/enhanced-components-B_l3cist.js +0 -1142
  102. package/dist/enhanced-components-B_l3cist.js.map +0 -1
  103. package/dist/enhanced-components-BspFs9OO.cjs +0 -2
  104. package/dist/enhanced-components-BspFs9OO.cjs.map +0 -1
  105. package/dist/hooks-BXwI8QG6.cjs +0 -4
  106. package/dist/hooks-BXwI8QG6.cjs.map +0 -1
  107. package/dist/hooks-Bpi-jDiO.js +0 -1816
  108. package/dist/hooks-Bpi-jDiO.js.map +0 -1
  109. package/dist/minimal-components-C4z900Ro.js +0 -1926
  110. package/dist/minimal-components-C4z900Ro.js.map +0 -1
  111. package/dist/minimal-components-v4qBp6jv.cjs +0 -2
  112. package/dist/minimal-components-v4qBp6jv.cjs.map +0 -1
  113. package/dist/minimal-components.css +0 -1
  114. package/dist/mona-loading.gif +0 -0
  115. package/dist/performance-monitor-C5k6FDXw.js +0 -301
  116. package/dist/performance-monitor-C5k6FDXw.js.map +0 -1
  117. package/dist/performance-monitor-lJmuUjQQ.cjs +0 -2
  118. package/dist/performance-monitor-lJmuUjQQ.cjs.map +0 -1
  119. package/dist/utils-CFOue_9K.cjs +0 -9
  120. package/dist/utils-CFOue_9K.cjs.map +0 -1
  121. package/dist/utils-Dzpl2ArK.js +0 -2844
  122. package/dist/utils-Dzpl2ArK.js.map +0 -1
  123. package/dist/utils.js +0 -2
  124. package/dist/utils.js.map +0 -1
  125. package/dist/utils.mjs +0 -11
  126. package/dist/utils.mjs.map +0 -1
  127. package/src/adapters/videojs-adapter.tsx +0 -470
  128. package/src/assets/mona-loading.gif +0 -0
  129. package/src/components/AnimateLoading.tsx +0 -107
  130. package/src/components/LoadingState.tsx +0 -239
  131. package/src/components/__tests__/media-player-accessibility.test.tsx +0 -510
  132. package/src/components/__tests__/media-player-react19.test.tsx +0 -457
  133. package/src/components/accessibility/keyboard-help-overlay.tsx +0 -207
  134. package/src/components/audio-player.tsx +0 -85
  135. package/src/components/basic/index.ts +0 -37
  136. package/src/components/enhanced/advanced-features.tsx +0 -311
  137. package/src/components/enhanced/debug-panel.tsx +0 -448
  138. package/src/components/enhanced/enhanced-controls.tsx +0 -597
  139. package/src/components/enhanced/enhanced-media-player.tsx +0 -566
  140. package/src/components/enhanced/error-handling.tsx +0 -338
  141. package/src/components/enhanced/index.ts +0 -39
  142. package/src/components/enhanced/media-player-enhanced.tsx +0 -383
  143. package/src/components/examples/basic-video-player.tsx +0 -50
  144. package/src/components/examples/custom-controls-example.tsx +0 -63
  145. package/src/components/examples/enhanced-controls-example.tsx +0 -100
  146. package/src/components/examples/enhanced-media-player-example.tsx +0 -302
  147. package/src/components/examples/loading-states-demo.tsx +0 -142
  148. package/src/components/examples/react-19-demo.tsx +0 -353
  149. package/src/components/examples/volume-orientation-demo.tsx +0 -106
  150. package/src/components/icon-demo.tsx +0 -196
  151. package/src/components/legacy.tsx +0 -87
  152. package/src/components/media-metadata-display.tsx +0 -99
  153. package/src/components/media-player-audio.tsx +0 -39
  154. package/src/components/media-player-controls.tsx +0 -223
  155. package/src/components/media-player-error.tsx +0 -163
  156. package/src/components/media-player-fullscreen.tsx +0 -109
  157. package/src/components/media-player-hls.tsx +0 -111
  158. package/src/components/media-player-loading.tsx +0 -76
  159. package/src/components/media-player-play.tsx +0 -75
  160. package/src/components/media-player-root.tsx +0 -338
  161. package/src/components/media-player-seek.tsx +0 -168
  162. package/src/components/media-player-time.tsx +0 -99
  163. package/src/components/media-player-tooltip.tsx +0 -58
  164. package/src/components/media-player-video.tsx +0 -54
  165. package/src/components/media-player-volume.tsx +0 -155
  166. package/src/components/media-player.tsx +0 -292
  167. package/src/components/media-suspense.tsx +0 -344
  168. package/src/components/player-settings-form.tsx +0 -158
  169. package/src/components/react-player-wrapper.tsx +0 -651
  170. package/src/components/simple-video-player.tsx +0 -62
  171. package/src/components/ui/blur-poster.tsx +0 -93
  172. package/src/components/ui/empty-state.tsx +0 -91
  173. package/src/components/ui/enhanced-seek-bar.tsx +0 -254
  174. package/src/components/ui/error-state.tsx +0 -124
  175. package/src/components/ui/fullscreen-button.tsx +0 -81
  176. package/src/components/ui/loading-skeleton.tsx +0 -107
  177. package/src/components/ui/media-resource-preloader.tsx +0 -458
  178. package/src/components/ui/offline-message.tsx +0 -98
  179. package/src/components/ui/play-button.tsx +0 -99
  180. package/src/components/ui/seek-bar.tsx +0 -191
  181. package/src/components/ui/time-display.tsx +0 -61
  182. package/src/components/ui/volume-control.tsx +0 -190
  183. package/src/components/unified/base-media-player.tsx +0 -252
  184. package/src/components/unified/media-player.tsx +0 -75
  185. package/src/components/variants/minimal/AccessibleMinimalPlayer.tsx +0 -587
  186. package/src/components/variants/minimal/EnhancedMinimalMediaPlayer.tsx +0 -573
  187. package/src/components/variants/minimal/MinimalControls.tsx +0 -124
  188. package/src/components/variants/minimal/MinimalLoading.tsx +0 -28
  189. package/src/components/variants/minimal/MinimalMediaPlayer.tsx +0 -318
  190. package/src/components/variants/minimal/MinimalOverlay.tsx +0 -58
  191. package/src/components/variants/minimal/MinimalPlayButton.tsx +0 -56
  192. package/src/components/variants/minimal/MinimalSeekBar.tsx +0 -140
  193. package/src/components/variants/minimal/MinimalVolumeControl.tsx +0 -75
  194. package/src/components/variants/minimal/SimpleMinimalPlayer.tsx +0 -206
  195. package/src/components/variants/minimal/components/CenterPlayButton.tsx +0 -22
  196. package/src/components/variants/minimal/components/ControlBar.tsx +0 -142
  197. package/src/components/variants/minimal/components/EnhancedSettingsMenu.tsx +0 -412
  198. package/src/components/variants/minimal/components/PlaybackControls.tsx +0 -46
  199. package/src/components/variants/minimal/components/RightControls.tsx +0 -164
  200. package/src/components/variants/minimal/components/SeekBar.tsx +0 -127
  201. package/src/components/variants/minimal/components/SettingsDropdown.tsx +0 -68
  202. package/src/components/variants/minimal/components/SubtitleDisplay.tsx +0 -21
  203. package/src/components/variants/minimal/components/TimeDisplay.tsx +0 -15
  204. package/src/components/variants/minimal/components/VideoElement.tsx +0 -33
  205. package/src/components/variants/minimal/components/VolumeControl.tsx +0 -220
  206. package/src/components/variants/minimal/index.ts +0 -23
  207. package/src/components/video-player.tsx +0 -100
  208. package/src/context/__tests__/media-store.test.ts +0 -509
  209. package/src/context/error-handling.ts +0 -398
  210. package/src/context/media-context.tsx +0 -254
  211. package/src/context/media-provider.tsx +0 -264
  212. package/src/context/media-store.ts +0 -387
  213. package/src/context/persistence.ts +0 -462
  214. package/src/core/events/event-system.ts +0 -448
  215. package/src/core/events/hooks.ts +0 -325
  216. package/src/core/events/index.ts +0 -22
  217. package/src/core/events/middleware.ts +0 -286
  218. package/src/core/index.ts +0 -22
  219. package/src/core/optimization/bundle-optimizer.tsx +0 -312
  220. package/src/core/performance/cicd.ts +0 -98
  221. package/src/core/performance/index.ts +0 -38
  222. package/src/core/performance/media-loading-optimizer.ts +0 -544
  223. package/src/core/performance/performance-budgets.ts +0 -437
  224. package/src/core/performance/performance-monitor.tsx +0 -488
  225. package/src/core/performance/performance-testing.ts +0 -461
  226. package/src/core/plugins/__tests__/registry.test.ts +0 -595
  227. package/src/core/plugins/base-plugin.ts +0 -225
  228. package/src/core/plugins/enhanced-plugin-system.ts +0 -435
  229. package/src/core/plugins/examples/analytics-plugin.ts +0 -241
  230. package/src/core/plugins/index.ts +0 -39
  231. package/src/core/plugins/registry.ts +0 -546
  232. package/src/core/plugins/types.ts +0 -169
  233. package/src/core/plugins/utils.ts +0 -317
  234. package/src/core/progressive-loading.tsx +0 -331
  235. package/src/core/providers/enhanced-hls-provider.ts +0 -307
  236. package/src/core/providers/lazy-provider.tsx +0 -14
  237. package/src/core/providers/service-provider.tsx +0 -164
  238. package/src/core/utils.tsx +0 -34
  239. package/src/features/media-session/media-session-manager.ts +0 -411
  240. package/src/features/picture-in-picture/pip-manager.ts +0 -428
  241. package/src/features/playlist/playlist-manager.ts +0 -626
  242. package/src/features/subtitles/subtitle-manager.ts +0 -435
  243. package/src/features/subtitles/subtitle-parser.ts +0 -284
  244. package/src/features/thumbnails/thumbnail-generator.ts +0 -528
  245. package/src/hooks/__tests__/currentTime-fix.test.ts +0 -149
  246. package/src/hooks/__tests__/use-media-player.test.ts +0 -712
  247. package/src/hooks/__tests__/use-media-state.test.tsx +0 -316
  248. package/src/hooks/accessibility/index.ts +0 -27
  249. package/src/hooks/accessibility/use-accessibility-preferences.ts +0 -190
  250. package/src/hooks/accessibility/use-focus-management.ts +0 -183
  251. package/src/hooks/accessibility/use-keyboard-shortcuts.ts +0 -152
  252. package/src/hooks/accessibility/use-screen-reader.ts +0 -212
  253. package/src/hooks/core/index.ts +0 -47
  254. package/src/hooks/legacy.ts +0 -21
  255. package/src/hooks/use-buffer-health.ts +0 -218
  256. package/src/hooks/use-enhanced-media-player.ts +0 -575
  257. package/src/hooks/use-focus-trap.tsx +0 -162
  258. package/src/hooks/use-intelligent-preloading.ts +0 -387
  259. package/src/hooks/use-keyboard-controls.ts +0 -115
  260. package/src/hooks/use-keyboard-shortcuts.ts +0 -255
  261. package/src/hooks/use-media-actions.ts +0 -184
  262. package/src/hooks/use-media-metadata.ts +0 -91
  263. package/src/hooks/use-media-optimistic.ts +0 -264
  264. package/src/hooks/use-media-player.ts +0 -343
  265. package/src/hooks/use-media-state.ts +0 -194
  266. package/src/hooks/use-memory-optimization.ts +0 -360
  267. package/src/hooks/use-network-status.ts +0 -124
  268. package/src/hooks/use-optimistic-controls.ts +0 -95
  269. package/src/hooks/use-optimized-media.ts +0 -283
  270. package/src/hooks/use-smart-preload.ts +0 -229
  271. package/src/hooks/use-touch-gestures.ts +0 -461
  272. package/src/hooks/useEnhancedSubtitles.ts +0 -258
  273. package/src/hooks/useKeyboardShortcuts.ts +0 -106
  274. package/src/hooks/useMediaControls.ts +0 -52
  275. package/src/hooks/useScreenshot.ts +0 -61
  276. package/src/hooks/useSubtitles.ts +0 -91
  277. package/src/hooks/useVideoPlayer.ts +0 -278
  278. package/src/icons/components/FullscreenIcon.tsx +0 -36
  279. package/src/icons/components/SettingsIcon.tsx +0 -37
  280. package/src/icons/components/animated/LoadingIcon.tsx +0 -27
  281. package/src/icons/components/animated/PlayPauseIcon.tsx +0 -42
  282. package/src/icons/components/media/PauseIcon.tsx +0 -38
  283. package/src/icons/components/media/PlayIcon.tsx +0 -37
  284. package/src/icons/components/volume/VolumeIcon.tsx +0 -38
  285. package/src/icons/components/volume/VolumeOffIcon.tsx +0 -38
  286. package/src/icons/index.ts +0 -56
  287. package/src/icons/provider.tsx +0 -58
  288. package/src/icons/types.ts +0 -60
  289. package/src/index-enhanced.ts +0 -35
  290. package/src/index-legacy.ts +0 -324
  291. package/src/index.css +0 -102
  292. package/src/lib/__tests__/async-utils.test.ts +0 -291
  293. package/src/lib/async-utils.ts +0 -194
  294. package/src/lib/deprecation.ts +0 -51
  295. package/src/lib/format-time.ts +0 -37
  296. package/src/lib/index.ts +0 -4
  297. package/src/lib/utils.ts +0 -6
  298. package/src/styles/globals.css +0 -462
  299. package/src/styles/minimal-player.css +0 -621
  300. package/src/styles/pixel-art.css +0 -41
  301. package/src/styles/videojs.css +0 -100
  302. package/src/types/events.ts +0 -47
  303. package/src/types/formats.ts +0 -79
  304. package/src/types/index.ts +0 -203
  305. package/src/types/videojs-plugins.d.ts +0 -14
@@ -1,587 +0,0 @@
1
- "use client"
2
-
3
- import React, { useCallback, useEffect, useRef, useState } from "react"
4
- import {
5
- createMediaKeyboardShortcuts,
6
- useAccessibilityStyles,
7
- useFocusVisible,
8
- useKeyboardShortcuts,
9
- useMediaPlayerFocus,
10
- useMediaScreenReader
11
- } from "../../../hooks/accessibility"
12
- import { cn } from "../../../lib/utils"
13
- import { KeyboardHelpOverlay } from "../../accessibility/keyboard-help-overlay"
14
- import type { IconSet } from "../../icons"
15
- import { defaultMinimalIcons } from "../../icons"
16
- import { MediaPlayerRoot } from "../../media-player-root"
17
- import { MediaPlayerVideo } from "../../media-player-video"
18
- import { MinimalControls } from "./MinimalControls"
19
- import { MinimalLoading } from "./MinimalLoading"
20
- import { MinimalOverlay } from "./MinimalOverlay"
21
-
22
- /**
23
- * Safely sets currentTime on a video element, ensuring the value is finite
24
- */
25
- function safeSetCurrentTime(video: HTMLVideoElement, time: number): boolean {
26
- if (!Number.isFinite(time)) {
27
- console.warn(`Attempted to set non-finite currentTime: ${time}`)
28
- return false
29
- }
30
-
31
- if (time < 0) {
32
- console.warn(`Attempted to set negative currentTime: ${time}`)
33
- return false
34
- }
35
-
36
- try {
37
- video.currentTime = time
38
- return true
39
- } catch (error) {
40
- console.error(`Failed to set currentTime to ${time}:`, error)
41
- return false
42
- }
43
- }
44
-
45
- export interface AccessibleMinimalPlayerProps {
46
- src: string | string[]
47
- poster?: string
48
- autoPlay?: boolean
49
- muted?: boolean
50
- loop?: boolean
51
- autoHideControls?: boolean
52
- hideDelay?: number
53
- theme?: "dark" | "light" | "transparent"
54
- customIcons?: IconSet
55
- showCenterPlayButton?: boolean
56
- showLoadingSpinner?: boolean
57
- className?: string
58
- onPlay?: () => void
59
- onPause?: () => void
60
- onEnded?: () => void
61
- onTimeUpdate?: (currentTime: number) => void
62
- onVolumeChange?: (volume: number) => void
63
- onSeek?: (time: number) => void
64
- onError?: (error: Error) => void
65
- watermark?: {
66
- src: string
67
- position?: "top-left" | "top-right" | "bottom-left" | "bottom-right"
68
- opacity?: number
69
- size?: "small" | "medium" | "large"
70
- }
71
- qualities?: Array<{
72
- src: string
73
- quality: string
74
- default?: boolean
75
- }>
76
- showQualitySelector?: boolean
77
- showSpeedControl?: boolean
78
- thumbnails?: string
79
- // Accessibility props
80
- enableKeyboardShortcuts?: boolean
81
- showKeyboardHelpButton?: boolean
82
- ariaLabel?: string
83
- ariaDescribedBy?: string
84
- }
85
-
86
- export function AccessibleMinimalPlayer({
87
- src,
88
- poster,
89
- autoPlay = false,
90
- muted = false,
91
- loop = false,
92
- autoHideControls = true,
93
- hideDelay = 2500,
94
- theme = "dark",
95
- customIcons,
96
- showCenterPlayButton = true,
97
- showLoadingSpinner = true,
98
- className,
99
- onPlay,
100
- onPause,
101
- onEnded,
102
- onTimeUpdate,
103
- onVolumeChange,
104
- onSeek,
105
- onError,
106
- watermark,
107
- qualities,
108
- showQualitySelector = false,
109
- showSpeedControl = false,
110
- thumbnails,
111
- enableKeyboardShortcuts = true,
112
- showKeyboardHelpButton = true,
113
- ariaLabel = "Media player",
114
- ariaDescribedBy
115
- }: AccessibleMinimalPlayerProps) {
116
- // Existing state
117
- const [controlsVisible, setControlsVisible] = useState(true)
118
- const [isPlaying, setIsPlaying] = useState(false)
119
- const [isLoading, setIsLoading] = useState(false)
120
- const [error, setError] = useState<string | null>(null)
121
- const [volume, setVolume] = useState(1)
122
- const [isMuted, setIsMuted] = useState(muted)
123
- const [currentTime, setCurrentTime] = useState(0)
124
- const [duration, setDuration] = useState(0)
125
- const [isFullscreen, setIsFullscreen] = useState(false)
126
-
127
- // Accessibility state
128
- const [showKeyboardHelp, setShowKeyboardHelp] = useState(false)
129
-
130
- // Refs
131
- const hideTimeoutRef = useRef<NodeJS.Timeout | null>(null)
132
- const containerRef = useRef<HTMLDivElement | null>(null)
133
- const videoRef = useRef<HTMLVideoElement | null>(null)
134
- const [isHovered, setIsHovered] = useState(false)
135
- const [userInteracting, setUserInteracting] = useState(false)
136
-
137
- // Accessibility hooks
138
- const { applyStyles, preferences } = useAccessibilityStyles()
139
- const focusManager = useMediaPlayerFocus()
140
- const screenReader = useMediaScreenReader()
141
- const isFocusVisible = useFocusVisible()
142
-
143
- // Merge default icons with custom icons
144
- const icons = { ...defaultMinimalIcons, ...customIcons }
145
-
146
- // Media control functions
147
- const togglePlayPause = useCallback(() => {
148
- if (!videoRef.current) return
149
-
150
- if (isPlaying) {
151
- videoRef.current.pause()
152
- } else {
153
- videoRef.current.play()
154
- }
155
- }, [isPlaying])
156
-
157
- const seekForward = useCallback(
158
- (seconds = 10) => {
159
- if (!videoRef.current) return
160
-
161
- const validDuration = Number.isFinite(duration) && duration > 0 ? duration : Number.isFinite(videoRef.current.duration) ? videoRef.current.duration : 0
162
- if (validDuration === 0) {
163
- console.warn("Cannot seek forward: duration is not available")
164
- return
165
- }
166
-
167
- const currentTime = Number.isFinite(videoRef.current.currentTime) ? videoRef.current.currentTime : 0
168
- const newTime = Math.min(currentTime + seconds, validDuration)
169
- if (safeSetCurrentTime(videoRef.current, newTime)) {
170
- screenReader.announceTime(newTime, validDuration)
171
- }
172
- },
173
- [duration, screenReader]
174
- )
175
-
176
- const seekBackward = useCallback(
177
- (seconds = 10) => {
178
- if (!videoRef.current) return
179
-
180
- const currentTime = Number.isFinite(videoRef.current.currentTime) ? videoRef.current.currentTime : 0
181
- const newTime = Math.max(currentTime - seconds, 0)
182
- if (safeSetCurrentTime(videoRef.current, newTime)) {
183
- screenReader.announceTime(newTime, duration)
184
- }
185
- },
186
- [duration, screenReader]
187
- )
188
-
189
- const volumeUp = useCallback(() => {
190
- if (!videoRef.current) return
191
-
192
- const newVolume = Math.min(volume + 0.1, 1)
193
- setVolume(newVolume)
194
- videoRef.current.volume = newVolume
195
- if (isMuted) {
196
- setIsMuted(false)
197
- videoRef.current.muted = false
198
- }
199
- screenReader.announceVolume(newVolume, false)
200
- }, [volume, isMuted, screenReader])
201
-
202
- const volumeDown = useCallback(() => {
203
- if (!videoRef.current) return
204
-
205
- const newVolume = Math.max(volume - 0.1, 0)
206
- setVolume(newVolume)
207
- videoRef.current.volume = newVolume
208
- if (isMuted) {
209
- setIsMuted(false)
210
- videoRef.current.muted = false
211
- }
212
- screenReader.announceVolume(newVolume, false)
213
- }, [volume, isMuted, screenReader])
214
-
215
- const toggleMute = useCallback(() => {
216
- if (!videoRef.current) return
217
-
218
- const newMuted = !isMuted
219
- setIsMuted(newMuted)
220
- videoRef.current.muted = newMuted
221
- screenReader.announceVolume(volume, newMuted)
222
- }, [isMuted, volume, screenReader])
223
-
224
- const toggleFullscreen = useCallback(async () => {
225
- if (!containerRef.current) return
226
-
227
- try {
228
- if (!isFullscreen) {
229
- if (containerRef.current.requestFullscreen) {
230
- await containerRef.current.requestFullscreen()
231
- }
232
- } else {
233
- if (document.exitFullscreen) {
234
- await document.exitFullscreen()
235
- }
236
- }
237
- } catch (error) {
238
- console.error("Fullscreen toggle failed:", error)
239
- }
240
- }, [isFullscreen])
241
-
242
- const showHelp = useCallback(() => {
243
- setShowKeyboardHelp(true)
244
- }, [])
245
-
246
- // Create keyboard shortcuts
247
- const keyboardShortcuts = createMediaKeyboardShortcuts({
248
- play: () => videoRef.current?.play(),
249
- pause: () => videoRef.current?.pause(),
250
- togglePlayPause,
251
- seekForward,
252
- seekBackward,
253
- volumeUp,
254
- volumeDown,
255
- toggleMute,
256
- toggleFullscreen,
257
- showHelp: showKeyboardHelpButton ? showHelp : undefined
258
- })
259
-
260
- // Enable keyboard shortcuts
261
- const { shortcuts } = useKeyboardShortcuts({
262
- shortcuts: enableKeyboardShortcuts ? keyboardShortcuts : [],
263
- enabled: enableKeyboardShortcuts,
264
- target: containerRef.current
265
- })
266
-
267
- // Auto-hide controls logic
268
- const resetHideTimer = useCallback(() => {
269
- if (!autoHideControls) return
270
-
271
- if (hideTimeoutRef.current) {
272
- clearTimeout(hideTimeoutRef.current)
273
- }
274
- setControlsVisible(true)
275
-
276
- if (!userInteracting && isPlaying && !preferences.prefersReducedMotion) {
277
- hideTimeoutRef.current = setTimeout(() => {
278
- setControlsVisible(false)
279
- }, hideDelay)
280
- }
281
- }, [autoHideControls, userInteracting, isPlaying, hideDelay, preferences.prefersReducedMotion])
282
-
283
- // Handle mouse movement
284
- const handleMouseMove = useCallback(() => {
285
- resetHideTimer()
286
- }, [resetHideTimer])
287
-
288
- // Handle mouse enter/leave
289
- const handleMouseEnter = useCallback(() => {
290
- setIsHovered(true)
291
- setControlsVisible(true)
292
- if (hideTimeoutRef.current) {
293
- clearTimeout(hideTimeoutRef.current)
294
- }
295
- }, [])
296
-
297
- const handleMouseLeave = useCallback(() => {
298
- setIsHovered(false)
299
- if (isPlaying && autoHideControls && !userInteracting) {
300
- hideTimeoutRef.current = setTimeout(() => {
301
- setControlsVisible(false)
302
- }, 500)
303
- }
304
- }, [isPlaying, autoHideControls, userInteracting])
305
-
306
- // Handle user interaction
307
- const handleUserInteractionStart = useCallback(() => {
308
- setUserInteracting(true)
309
- setControlsVisible(true)
310
- if (hideTimeoutRef.current) {
311
- clearTimeout(hideTimeoutRef.current)
312
- }
313
- }, [])
314
-
315
- const handleUserInteractionEnd = useCallback(() => {
316
- setUserInteracting(false)
317
- resetHideTimer()
318
- }, [resetHideTimer])
319
-
320
- // Video event handlers
321
- const handlePlayStateChange = useCallback(
322
- (playing: boolean) => {
323
- setIsPlaying(playing)
324
- screenReader.announcePlaybackState(playing)
325
-
326
- if (playing) {
327
- onPlay?.()
328
- resetHideTimer()
329
- } else {
330
- onPause?.()
331
- setControlsVisible(true)
332
- if (hideTimeoutRef.current) {
333
- clearTimeout(hideTimeoutRef.current)
334
- }
335
- }
336
- },
337
- [onPlay, onPause, resetHideTimer, screenReader]
338
- )
339
-
340
- const handleTimeUpdate = useCallback(
341
- (time: number) => {
342
- setCurrentTime(time)
343
- onTimeUpdate?.(time)
344
- },
345
- [onTimeUpdate]
346
- )
347
-
348
- const handleLoadedMetadata = useCallback((event: React.SyntheticEvent<HTMLVideoElement>) => {
349
- const video = event.currentTarget
350
- setDuration(video.duration)
351
- setIsLoading(false)
352
- }, [])
353
-
354
- const handleLoadStart = useCallback(() => {
355
- setIsLoading(true)
356
- setError(null)
357
- screenReader.announceLoading(true)
358
- }, [screenReader])
359
-
360
- const handleLoadedData = useCallback(() => {
361
- setIsLoading(false)
362
- screenReader.announceLoading(false)
363
- }, [screenReader])
364
-
365
- const handleError = useCallback(
366
- (e: Error) => {
367
- setIsLoading(false)
368
- setError(e.message || "An error occurred")
369
- screenReader.announceError(e.message || "An error occurred")
370
- onError?.(e)
371
- },
372
- [onError, screenReader]
373
- )
374
-
375
- const handleVolumeChange = useCallback(
376
- (event: React.SyntheticEvent<HTMLVideoElement>) => {
377
- const video = event.currentTarget
378
- const newVolume = video.volume
379
- const newMuted = video.muted
380
-
381
- setVolume(newVolume)
382
- setIsMuted(newMuted)
383
- onVolumeChange?.(newVolume)
384
- },
385
- [onVolumeChange]
386
- )
387
-
388
- // Fullscreen change handler
389
- useEffect(() => {
390
- const handleFullscreenChange = () => {
391
- const isCurrentlyFullscreen = !!document.fullscreenElement
392
- setIsFullscreen(isCurrentlyFullscreen)
393
- screenReader.announceFullscreen(isCurrentlyFullscreen)
394
- }
395
-
396
- document.addEventListener("fullscreenchange", handleFullscreenChange)
397
- return () => {
398
- document.removeEventListener("fullscreenchange", handleFullscreenChange)
399
- }
400
- }, [screenReader])
401
-
402
- // Cleanup on unmount
403
- useEffect(() => {
404
- return () => {
405
- if (hideTimeoutRef.current) {
406
- clearTimeout(hideTimeoutRef.current)
407
- }
408
- }
409
- }, [])
410
-
411
- // Determine video source
412
- const videoSrc =
413
- qualities && qualities.length > 0
414
- ? qualities.find((q) => q.default)?.src ||
415
- qualities[0]?.src ||
416
- (typeof src === "string" ? src : src[0])
417
- : typeof src === "string"
418
- ? src
419
- : src[0]
420
-
421
- return (
422
- <>
423
- <div
424
- ref={containerRef}
425
- className={cn(
426
- "accessible-minimal-player theme-minimal relative overflow-hidden rounded-lg bg-black",
427
- `theme-minimal-${theme}`,
428
- isFocusVisible && "focus-visible-enabled",
429
- className
430
- )}
431
- data-theme={theme}
432
- onMouseMove={handleMouseMove}
433
- onMouseEnter={handleMouseEnter}
434
- onMouseLeave={handleMouseLeave}
435
- role="application"
436
- aria-label={ariaLabel}
437
- aria-describedby={ariaDescribedBy}
438
- tabIndex={0}
439
- data-testid="media-player">
440
- <MediaPlayerRoot className="relative h-full w-full">
441
- <MediaPlayerVideo
442
- src={videoSrc}
443
- poster={poster}
444
- autoPlay={autoPlay}
445
- muted={muted}
446
- loop={loop}
447
- onPlay={() => handlePlayStateChange(true)}
448
- onPause={() => handlePlayStateChange(false)}
449
- onEnded={onEnded}
450
- onTimeUpdate={(e) => handleTimeUpdate(e.currentTarget.currentTime)}
451
- onLoadStart={handleLoadStart}
452
- onLoadedData={handleLoadedData}
453
- onLoadedMetadata={handleLoadedMetadata}
454
- onError={(e) => handleError(new Error("Video loading failed"))}
455
- onVolumeChange={handleVolumeChange}
456
- className="h-full w-full object-contain"
457
- aria-hidden="true"
458
- />
459
-
460
- {watermark && (
461
- <div
462
- className={cn("pointer-events-none absolute z-10", {
463
- "top-4 left-4": watermark.position === "top-left",
464
- "top-4 right-4": watermark.position === "top-right",
465
- "bottom-4 left-4": watermark.position === "bottom-left",
466
- "right-4 bottom-4": watermark.position === "bottom-right"
467
- })}
468
- style={{ opacity: watermark.opacity || 0.7 }}
469
- aria-hidden="true">
470
- <img
471
- src={watermark.src}
472
- alt=""
473
- className={cn("h-auto", {
474
- "w-12": watermark.size === "small",
475
- "w-16": watermark.size === "medium",
476
- "w-24": watermark.size === "large"
477
- })}
478
- />
479
- </div>
480
- )}
481
-
482
- <MinimalOverlay
483
- visible={showCenterPlayButton && (!isPlaying || isLoading)}
484
- showCenterButton={showCenterPlayButton}
485
- isPlaying={isPlaying}
486
- icons={icons}
487
- onPlayPause={togglePlayPause}
488
- />
489
-
490
- <MinimalControls
491
- visible={controlsVisible || !autoHideControls || isHovered}
492
- isPlaying={isPlaying}
493
- icons={icons}
494
- qualities={qualities}
495
- showQualitySelector={showQualitySelector}
496
- showSpeedControl={showSpeedControl}
497
- thumbnails={thumbnails}
498
- onUserInteractionStart={handleUserInteractionStart}
499
- onUserInteractionEnd={handleUserInteractionEnd}
500
- onSeek={(time) => {
501
- if (videoRef.current) {
502
- const validDuration = Number.isFinite(duration) && duration > 0 ? duration : Number.isFinite(videoRef.current.duration) ? videoRef.current.duration : 0
503
- if (validDuration === 0) {
504
- console.warn("Cannot seek: duration is not available")
505
- return
506
- }
507
- const clampedTime = Math.max(0, Math.min(time, validDuration))
508
- if (safeSetCurrentTime(videoRef.current, clampedTime)) {
509
- onSeek?.(clampedTime)
510
- }
511
- }
512
- }}
513
- />
514
-
515
- {showLoadingSpinner && isLoading && <MinimalLoading />}
516
- </MediaPlayerRoot>
517
- </div>
518
-
519
- {/* Keyboard Help Overlay */}
520
- <KeyboardHelpOverlay
521
- isOpen={showKeyboardHelp}
522
- onClose={() => setShowKeyboardHelp(false)}
523
- shortcuts={shortcuts}
524
- />
525
-
526
- {/* Screen reader only status region */}
527
- <div
528
- id={`${ariaDescribedBy || "media-player"}-status`}
529
- className="sr-only"
530
- aria-live="polite"
531
- aria-atomic="true">
532
- {isLoading && "Loading media"}
533
- {error && `Error: ${error}`}
534
- {!isLoading && !error && (isPlaying ? "Playing" : "Paused")}
535
- </div>
536
-
537
- <style suppressHydrationWarning>{`
538
- .accessible-minimal-player {
539
- /* Accessibility-specific styles */
540
- --media-focus-outline: var(--media-focus-outline-width, 2px) solid #3b82f6;
541
- --media-transition: ${preferences.prefersReducedMotion ? "none" : "var(--media-transition-duration, 200ms)"};
542
- }
543
-
544
- .accessible-minimal-player:focus-visible {
545
- outline: var(--media-focus-outline);
546
- outline-offset: 2px;
547
- }
548
-
549
- .accessible-minimal-player .focus-visible-enabled button:focus-visible,
550
- .accessible-minimal-player .focus-visible-enabled [role="slider"]:focus-visible {
551
- outline: var(--media-focus-outline);
552
- outline-offset: 2px;
553
- }
554
-
555
- /* High contrast mode support */
556
- @media (prefers-contrast: high) {
557
- .accessible-minimal-player {
558
- --media-bg-opacity: 1;
559
- --media-border-width: 2px;
560
- }
561
- }
562
-
563
- /* Reduced motion support */
564
- @media (prefers-reduced-motion: reduce) {
565
- .accessible-minimal-player * {
566
- animation-duration: 0.01ms !important;
567
- animation-iteration-count: 1 !important;
568
- transition-duration: 0.01ms !important;
569
- }
570
- }
571
-
572
- /* Screen reader only class */
573
- .sr-only {
574
- position: absolute;
575
- width: 1px;
576
- height: 1px;
577
- padding: 0;
578
- margin: -1px;
579
- overflow: hidden;
580
- clip: rect(0, 0, 0, 0);
581
- white-space: nowrap;
582
- border: 0;
583
- }
584
- `}</style>
585
- </>
586
- )
587
- }