@therealtinhtute/baroiplayer 1.2.1 → 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 (302) hide show
  1. package/README.md +90 -71
  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 +1 -41
  64. package/dist/index.js.map +1 -1
  65. package/dist/index.mjs +750 -5640
  66. package/dist/index.mjs.map +1 -1
  67. package/dist/package.json +3 -0
  68. package/package.json +110 -114
  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 -1
  78. package/dist/context/media.mjs +0 -3
  79. package/dist/context/store.js +0 -1
  80. package/dist/context/store.mjs +0 -3
  81. package/dist/context-Bzd5QCKM.cjs +0 -7
  82. package/dist/context-Bzd5QCKM.cjs.map +0 -1
  83. package/dist/context-DD_SH4tT.js +0 -1053
  84. package/dist/context-DD_SH4tT.js.map +0 -1
  85. package/dist/core-events-BRnLMB7s.cjs +0 -2
  86. package/dist/core-events-BRnLMB7s.cjs.map +0 -1
  87. package/dist/core-events-v_mKdj5p.js +0 -417
  88. package/dist/core-events-v_mKdj5p.js.map +0 -1
  89. package/dist/core-plugins-CMBv-yVh.cjs +0 -2
  90. package/dist/core-plugins-CMBv-yVh.cjs.map +0 -1
  91. package/dist/core-plugins-CqCxLkbd.js +0 -754
  92. package/dist/core-plugins-CqCxLkbd.js.map +0 -1
  93. package/dist/core.js +0 -15
  94. package/dist/core.js.map +0 -1
  95. package/dist/core.mjs +0 -960
  96. package/dist/core.mjs.map +0 -1
  97. package/dist/enhanced-components-BwjBqSA1.js +0 -2858
  98. package/dist/enhanced-components-BwjBqSA1.js.map +0 -1
  99. package/dist/enhanced-components-C-ka-XLp.cjs +0 -2
  100. package/dist/enhanced-components-C-ka-XLp.cjs.map +0 -1
  101. package/dist/hooks-B-IIWPJr.js +0 -1842
  102. package/dist/hooks-B-IIWPJr.js.map +0 -1
  103. package/dist/hooks-DcHzmBwA.cjs +0 -4
  104. package/dist/hooks-DcHzmBwA.cjs.map +0 -1
  105. package/dist/minimal-components-BYsMQde5.js +0 -1610
  106. package/dist/minimal-components-BYsMQde5.js.map +0 -1
  107. package/dist/minimal-components-CsxQbDp7.cjs +0 -2
  108. package/dist/minimal-components-CsxQbDp7.cjs.map +0 -1
  109. package/dist/minimal-components.css +0 -1
  110. package/dist/mona-loading.gif +0 -0
  111. package/dist/performance-monitor-DCSijLJg.js +0 -312
  112. package/dist/performance-monitor-DCSijLJg.js.map +0 -1
  113. package/dist/performance-monitor-wNFKmqMr.cjs +0 -2
  114. package/dist/performance-monitor-wNFKmqMr.cjs.map +0 -1
  115. package/dist/rolldown-runtime-BmowowmI.js +0 -14
  116. package/dist/rolldown-runtime-mLOUI7ql.cjs +0 -1
  117. package/dist/utils-D2gQ7c2R.js +0 -64
  118. package/dist/utils-D2gQ7c2R.js.map +0 -1
  119. package/dist/utils-DJaAwiZ9.cjs +0 -2
  120. package/dist/utils-DJaAwiZ9.cjs.map +0 -1
  121. package/dist/utils.js +0 -1
  122. package/dist/utils.mjs +0 -3
  123. package/src/adapters/videojs-adapter.tsx +0 -470
  124. package/src/assets/mona-loading.gif +0 -0
  125. package/src/components/AnimateLoading.tsx +0 -111
  126. package/src/components/LoadingState.tsx +0 -239
  127. package/src/components/__tests__/media-player-accessibility.test.tsx +0 -510
  128. package/src/components/__tests__/media-player-react19.test.tsx +0 -457
  129. package/src/components/accessibility/keyboard-help-overlay.tsx +0 -207
  130. package/src/components/audio-player.tsx +0 -85
  131. package/src/components/basic/index.ts +0 -37
  132. package/src/components/enhanced/advanced-features.tsx +0 -311
  133. package/src/components/enhanced/debug-panel.tsx +0 -448
  134. package/src/components/enhanced/enhanced-controls.tsx +0 -597
  135. package/src/components/enhanced/enhanced-media-player.tsx +0 -566
  136. package/src/components/enhanced/error-handling.tsx +0 -338
  137. package/src/components/enhanced/index.ts +0 -39
  138. package/src/components/enhanced/media-player-enhanced.tsx +0 -383
  139. package/src/components/examples/basic-video-player.tsx +0 -50
  140. package/src/components/examples/custom-controls-example.tsx +0 -63
  141. package/src/components/examples/enhanced-controls-example.tsx +0 -100
  142. package/src/components/examples/enhanced-media-player-example.tsx +0 -302
  143. package/src/components/examples/loading-states-demo.tsx +0 -141
  144. package/src/components/examples/react-19-demo.tsx +0 -349
  145. package/src/components/examples/volume-orientation-demo.tsx +0 -105
  146. package/src/components/icon-demo.tsx +0 -196
  147. package/src/components/legacy.tsx +0 -87
  148. package/src/components/media-metadata-display.tsx +0 -99
  149. package/src/components/media-player-audio.tsx +0 -39
  150. package/src/components/media-player-controls.tsx +0 -223
  151. package/src/components/media-player-error.tsx +0 -163
  152. package/src/components/media-player-fullscreen.tsx +0 -109
  153. package/src/components/media-player-hls.tsx +0 -111
  154. package/src/components/media-player-loading.tsx +0 -76
  155. package/src/components/media-player-play.tsx +0 -75
  156. package/src/components/media-player-root.tsx +0 -338
  157. package/src/components/media-player-seek.tsx +0 -168
  158. package/src/components/media-player-time.tsx +0 -99
  159. package/src/components/media-player-tooltip.tsx +0 -58
  160. package/src/components/media-player-video.tsx +0 -54
  161. package/src/components/media-player-volume.tsx +0 -155
  162. package/src/components/media-player.tsx +0 -292
  163. package/src/components/media-suspense.tsx +0 -344
  164. package/src/components/player-settings-form.tsx +0 -158
  165. package/src/components/react-player-wrapper.tsx +0 -651
  166. package/src/components/simple-video-player.tsx +0 -62
  167. package/src/components/ui/blur-poster.tsx +0 -96
  168. package/src/components/ui/empty-state.tsx +0 -91
  169. package/src/components/ui/enhanced-seek-bar.tsx +0 -254
  170. package/src/components/ui/error-state.tsx +0 -124
  171. package/src/components/ui/fullscreen-button.tsx +0 -81
  172. package/src/components/ui/loading-skeleton.tsx +0 -107
  173. package/src/components/ui/media-resource-preloader.tsx +0 -458
  174. package/src/components/ui/offline-message.tsx +0 -98
  175. package/src/components/ui/play-button.tsx +0 -99
  176. package/src/components/ui/seek-bar.tsx +0 -191
  177. package/src/components/ui/time-display.tsx +0 -61
  178. package/src/components/ui/volume-control.tsx +0 -190
  179. package/src/components/unified/base-media-player.tsx +0 -252
  180. package/src/components/unified/media-player.tsx +0 -75
  181. package/src/components/variants/minimal/AccessibleMinimalPlayer.tsx +0 -587
  182. package/src/components/variants/minimal/EnhancedMinimalMediaPlayer.tsx +0 -573
  183. package/src/components/variants/minimal/MinimalControls.tsx +0 -124
  184. package/src/components/variants/minimal/MinimalLoading.tsx +0 -28
  185. package/src/components/variants/minimal/MinimalMediaPlayer.tsx +0 -318
  186. package/src/components/variants/minimal/MinimalOverlay.tsx +0 -58
  187. package/src/components/variants/minimal/MinimalPlayButton.tsx +0 -56
  188. package/src/components/variants/minimal/MinimalSeekBar.tsx +0 -140
  189. package/src/components/variants/minimal/MinimalVolumeControl.tsx +0 -75
  190. package/src/components/variants/minimal/SimpleMinimalPlayer.tsx +0 -206
  191. package/src/components/variants/minimal/components/CenterPlayButton.tsx +0 -22
  192. package/src/components/variants/minimal/components/ControlBar.tsx +0 -142
  193. package/src/components/variants/minimal/components/EnhancedSettingsMenu.tsx +0 -412
  194. package/src/components/variants/minimal/components/PlaybackControls.tsx +0 -46
  195. package/src/components/variants/minimal/components/RightControls.tsx +0 -164
  196. package/src/components/variants/minimal/components/SeekBar.tsx +0 -127
  197. package/src/components/variants/minimal/components/SettingsDropdown.tsx +0 -68
  198. package/src/components/variants/minimal/components/SubtitleDisplay.tsx +0 -21
  199. package/src/components/variants/minimal/components/TimeDisplay.tsx +0 -15
  200. package/src/components/variants/minimal/components/VideoElement.tsx +0 -35
  201. package/src/components/variants/minimal/components/VolumeControl.tsx +0 -220
  202. package/src/components/variants/minimal/index.ts +0 -23
  203. package/src/components/video-player.tsx +0 -100
  204. package/src/context/__tests__/media-store.test.ts +0 -509
  205. package/src/context/error-handling.ts +0 -398
  206. package/src/context/media-context.tsx +0 -254
  207. package/src/context/media-provider.tsx +0 -264
  208. package/src/context/media-store.ts +0 -387
  209. package/src/context/persistence.ts +0 -462
  210. package/src/core/events/event-system.ts +0 -448
  211. package/src/core/events/hooks.ts +0 -325
  212. package/src/core/events/index.ts +0 -22
  213. package/src/core/events/middleware.ts +0 -286
  214. package/src/core/index.ts +0 -22
  215. package/src/core/optimization/bundle-optimizer.tsx +0 -312
  216. package/src/core/performance/cicd.ts +0 -98
  217. package/src/core/performance/index.ts +0 -38
  218. package/src/core/performance/media-loading-optimizer.ts +0 -545
  219. package/src/core/performance/performance-budgets.ts +0 -437
  220. package/src/core/performance/performance-monitor.tsx +0 -488
  221. package/src/core/performance/performance-testing.ts +0 -461
  222. package/src/core/plugins/__tests__/registry.test.ts +0 -595
  223. package/src/core/plugins/base-plugin.ts +0 -225
  224. package/src/core/plugins/enhanced-plugin-system.ts +0 -435
  225. package/src/core/plugins/examples/analytics-plugin.ts +0 -241
  226. package/src/core/plugins/index.ts +0 -39
  227. package/src/core/plugins/registry.ts +0 -546
  228. package/src/core/plugins/types.ts +0 -169
  229. package/src/core/plugins/utils.ts +0 -317
  230. package/src/core/progressive-loading.tsx +0 -331
  231. package/src/core/providers/enhanced-hls-provider.ts +0 -307
  232. package/src/core/providers/lazy-provider.tsx +0 -14
  233. package/src/core/providers/service-provider.tsx +0 -164
  234. package/src/core/utils.tsx +0 -34
  235. package/src/features/media-session/media-session-manager.ts +0 -411
  236. package/src/features/picture-in-picture/pip-manager.ts +0 -428
  237. package/src/features/playlist/playlist-manager.ts +0 -626
  238. package/src/features/subtitles/subtitle-manager.ts +0 -435
  239. package/src/features/subtitles/subtitle-parser.ts +0 -284
  240. package/src/features/thumbnails/thumbnail-generator.ts +0 -528
  241. package/src/hooks/__tests__/currentTime-fix.test.ts +0 -149
  242. package/src/hooks/__tests__/use-media-player.test.ts +0 -712
  243. package/src/hooks/__tests__/use-media-state.test.tsx +0 -316
  244. package/src/hooks/accessibility/index.ts +0 -27
  245. package/src/hooks/accessibility/use-accessibility-preferences.ts +0 -190
  246. package/src/hooks/accessibility/use-focus-management.ts +0 -183
  247. package/src/hooks/accessibility/use-keyboard-shortcuts.ts +0 -152
  248. package/src/hooks/accessibility/use-screen-reader.ts +0 -212
  249. package/src/hooks/core/index.ts +0 -47
  250. package/src/hooks/legacy.ts +0 -21
  251. package/src/hooks/use-buffer-health.ts +0 -218
  252. package/src/hooks/use-enhanced-media-player.ts +0 -575
  253. package/src/hooks/use-focus-trap.tsx +0 -162
  254. package/src/hooks/use-intelligent-preloading.ts +0 -387
  255. package/src/hooks/use-keyboard-controls.ts +0 -115
  256. package/src/hooks/use-keyboard-shortcuts.ts +0 -255
  257. package/src/hooks/use-media-actions.ts +0 -184
  258. package/src/hooks/use-media-metadata.ts +0 -91
  259. package/src/hooks/use-media-optimistic.ts +0 -264
  260. package/src/hooks/use-media-player.ts +0 -343
  261. package/src/hooks/use-media-state.ts +0 -194
  262. package/src/hooks/use-memory-optimization.ts +0 -360
  263. package/src/hooks/use-network-status.ts +0 -124
  264. package/src/hooks/use-optimistic-controls.ts +0 -95
  265. package/src/hooks/use-optimized-media.ts +0 -283
  266. package/src/hooks/use-smart-preload.ts +0 -229
  267. package/src/hooks/use-touch-gestures.ts +0 -461
  268. package/src/hooks/useEnhancedSubtitles.ts +0 -258
  269. package/src/hooks/useKeyboardShortcuts.ts +0 -106
  270. package/src/hooks/useMediaControls.ts +0 -52
  271. package/src/hooks/useScreenshot.ts +0 -77
  272. package/src/hooks/useSubtitles.ts +0 -91
  273. package/src/hooks/useVideoPlayer.ts +0 -278
  274. package/src/icons/components/FullscreenIcon.tsx +0 -36
  275. package/src/icons/components/SettingsIcon.tsx +0 -37
  276. package/src/icons/components/animated/LoadingIcon.tsx +0 -27
  277. package/src/icons/components/animated/PlayPauseIcon.tsx +0 -42
  278. package/src/icons/components/media/PauseIcon.tsx +0 -38
  279. package/src/icons/components/media/PlayIcon.tsx +0 -37
  280. package/src/icons/components/volume/VolumeIcon.tsx +0 -38
  281. package/src/icons/components/volume/VolumeOffIcon.tsx +0 -38
  282. package/src/icons/index.ts +0 -56
  283. package/src/icons/provider.tsx +0 -58
  284. package/src/icons/types.ts +0 -60
  285. package/src/index-enhanced.ts +0 -35
  286. package/src/index-legacy.ts +0 -324
  287. package/src/index.css +0 -102
  288. package/src/lib/__tests__/async-utils.test.ts +0 -291
  289. package/src/lib/async-utils.ts +0 -194
  290. package/src/lib/deprecation.ts +0 -51
  291. package/src/lib/format-time.ts +0 -37
  292. package/src/lib/index.ts +0 -4
  293. package/src/lib/utils.ts +0 -6
  294. package/src/styles/globals.css +0 -462
  295. package/src/styles/minimal-player.css +0 -621
  296. package/src/styles/pixel-art.css +0 -41
  297. package/src/styles/videojs.css +0 -100
  298. package/src/types/assets.d.ts +0 -29
  299. package/src/types/events.ts +0 -47
  300. package/src/types/formats.ts +0 -79
  301. package/src/types/index.ts +0 -203
  302. package/src/types/videojs-plugins.d.ts +0 -14
@@ -1,626 +0,0 @@
1
- export interface PlaylistItem {
2
- id: string
3
- title: string
4
- src: string
5
- duration?: number
6
- thumbnail?: string
7
- metadata?: {
8
- artist?: string
9
- album?: string
10
- genre?: string
11
- year?: number
12
- description?: string
13
- tags?: string[]
14
- }
15
- subtitles?: SubtitleTrack[]
16
- chapters?: ChapterMarker[]
17
- }
18
-
19
- export interface SubtitleTrack {
20
- id: string
21
- label: string
22
- language: string
23
- src: string
24
- format: "vtt" | "srt"
25
- default?: boolean
26
- }
27
-
28
- export interface ChapterMarker {
29
- id: string
30
- title: string
31
- startTime: number
32
- endTime?: number
33
- thumbnail?: string
34
- }
35
-
36
- export interface PlaylistConfig {
37
- shuffle?: boolean
38
- repeat?: "none" | "one" | "all"
39
- autoplay?: boolean
40
- crossfade?: number
41
- gapless?: boolean
42
- }
43
-
44
- export interface PlaylistEventData {
45
- playlist?: PlaylistItem[]
46
- currentItem?: PlaylistItem
47
- currentIndex?: number
48
- previousItem?: PlaylistItem
49
- nextItem?: PlaylistItem
50
- }
51
-
52
- export type PlaylistEvent =
53
- | "itemAdded"
54
- | "itemRemoved"
55
- | "itemChanged"
56
- | "playlistChanged"
57
- | "currentItemChanged"
58
- | "configChanged"
59
- | "shuffleChanged"
60
- | "repeatChanged"
61
-
62
- export class PlaylistManager {
63
- private items: PlaylistItem[] = []
64
- private currentIndex: number = -1
65
- private originalOrder: PlaylistItem[] = []
66
- private config: PlaylistConfig = {
67
- shuffle: false,
68
- repeat: "none",
69
- autoplay: true,
70
- crossfade: 0,
71
- gapless: false
72
- }
73
- private eventListeners: Map<PlaylistEvent, Set<Function>> = new Map()
74
- private history: number[] = []
75
- private historyIndex: number = -1
76
-
77
- constructor(config?: Partial<PlaylistConfig>) {
78
- if (config) {
79
- this.updateConfig(config)
80
- }
81
- }
82
-
83
- /**
84
- * Add item(s) to playlist
85
- */
86
- add(items: PlaylistItem | PlaylistItem[], index?: number): void {
87
- const itemsToAdd = Array.isArray(items) ? items : [items]
88
-
89
- if (index !== undefined && index >= 0 && index <= this.items.length) {
90
- this.items.splice(index, 0, ...itemsToAdd)
91
- this.originalOrder.splice(index, 0, ...itemsToAdd)
92
-
93
- // Adjust current index if needed
94
- if (index <= this.currentIndex) {
95
- this.currentIndex += itemsToAdd.length
96
- }
97
- } else {
98
- this.items.push(...itemsToAdd)
99
- this.originalOrder.push(...itemsToAdd)
100
- }
101
-
102
- // If this is the first item and no current item is set
103
- if (this.currentIndex === -1 && this.items.length > 0) {
104
- this.currentIndex = 0
105
- this.addToHistory(0)
106
- }
107
-
108
- itemsToAdd.forEach((item) => {
109
- this.emit("itemAdded", { currentItem: item, playlist: this.items })
110
- })
111
-
112
- this.emit("playlistChanged", { playlist: this.items })
113
- }
114
-
115
- /**
116
- * Remove item(s) from playlist
117
- */
118
- remove(indices: number | number[]): PlaylistItem[] {
119
- const indicesToRemove = Array.isArray(indices) ? indices.sort((a, b) => b - a) : [indices]
120
- const removedItems: PlaylistItem[] = []
121
-
122
- indicesToRemove.forEach((index) => {
123
- if (index >= 0 && index < this.items.length) {
124
- const [removedItem] = this.items.splice(index, 1)
125
- if (removedItem) {
126
- const originalIndex = this.originalOrder.findIndex((item) => item.id === removedItem.id)
127
- if (originalIndex >= 0) {
128
- this.originalOrder.splice(originalIndex, 1)
129
- }
130
-
131
- removedItems.push(removedItem)
132
- }
133
-
134
- // Adjust current index
135
- if (index < this.currentIndex) {
136
- this.currentIndex--
137
- } else if (index === this.currentIndex) {
138
- // If we removed the current item, stay at the same index
139
- // (which now points to the next item)
140
- if (this.currentIndex >= this.items.length) {
141
- this.currentIndex = this.items.length - 1
142
- }
143
- }
144
-
145
- this.emit("itemRemoved", { currentItem: removedItem, playlist: this.items })
146
- }
147
- })
148
-
149
- // Update current index bounds
150
- if (this.items.length === 0) {
151
- this.currentIndex = -1
152
- this.clearHistory()
153
- } else if (this.currentIndex >= this.items.length) {
154
- this.currentIndex = this.items.length - 1
155
- }
156
-
157
- this.emit("playlistChanged", { playlist: this.items })
158
- return removedItems
159
- }
160
-
161
- /**
162
- * Move item to new position
163
- */
164
- move(fromIndex: number, toIndex: number): boolean {
165
- if (
166
- fromIndex < 0 ||
167
- fromIndex >= this.items.length ||
168
- toIndex < 0 ||
169
- toIndex >= this.items.length ||
170
- fromIndex === toIndex
171
- ) {
172
- return false
173
- }
174
-
175
- const [movedItem] = this.items.splice(fromIndex, 1)
176
- if (!movedItem) return false
177
- this.items.splice(toIndex, 0, movedItem)
178
-
179
- // Update current index
180
- if (fromIndex === this.currentIndex) {
181
- this.currentIndex = toIndex
182
- } else if (fromIndex < this.currentIndex && toIndex >= this.currentIndex) {
183
- this.currentIndex--
184
- } else if (fromIndex > this.currentIndex && toIndex <= this.currentIndex) {
185
- this.currentIndex++
186
- }
187
-
188
- this.emit("playlistChanged", { playlist: this.items })
189
- return true
190
- }
191
-
192
- /**
193
- * Clear all items
194
- */
195
- clear(): void {
196
- this.items = []
197
- this.originalOrder = []
198
- this.currentIndex = -1
199
- this.clearHistory()
200
- this.emit("playlistChanged", { playlist: this.items })
201
- }
202
-
203
- /**
204
- * Get current item
205
- */
206
- getCurrentItem(): PlaylistItem | null {
207
- return this.currentIndex >= 0 && this.currentIndex < this.items.length
208
- ? this.items[this.currentIndex] || null
209
- : null
210
- }
211
-
212
- /**
213
- * Get current index
214
- */
215
- getCurrentIndex(): number {
216
- return this.currentIndex
217
- }
218
-
219
- /**
220
- * Set current item by index
221
- */
222
- setCurrentIndex(index: number): boolean {
223
- if (index >= 0 && index < this.items.length) {
224
- const previousIndex = this.currentIndex
225
- this.currentIndex = index
226
- this.addToHistory(index)
227
-
228
- this.emit("currentItemChanged", {
229
- currentItem: this.items[index],
230
- currentIndex: index,
231
- previousItem: previousIndex >= 0 ? this.items[previousIndex] || undefined : undefined
232
- })
233
- return true
234
- }
235
- return false
236
- }
237
-
238
- /**
239
- * Set current item by ID
240
- */
241
- setCurrentById(id: string): boolean {
242
- const index = this.items.findIndex((item) => item.id === id)
243
- return index >= 0 ? this.setCurrentIndex(index) : false
244
- }
245
-
246
- /**
247
- * Get next item
248
- */
249
- getNext(): PlaylistItem | null {
250
- const nextIndex = this.getNextIndex()
251
- return nextIndex >= 0 && nextIndex < this.items.length ? this.items[nextIndex] || null : null
252
- }
253
-
254
- /**
255
- * Get previous item
256
- */
257
- getPrevious(): PlaylistItem | null {
258
- const prevIndex = this.getPreviousIndex()
259
- return prevIndex >= 0 && prevIndex < this.items.length ? this.items[prevIndex] || null : null
260
- }
261
-
262
- /**
263
- * Move to next item
264
- */
265
- next(): boolean {
266
- const nextIndex = this.getNextIndex()
267
- return nextIndex >= 0 ? this.setCurrentIndex(nextIndex) : false
268
- }
269
-
270
- /**
271
- * Move to previous item
272
- */
273
- previous(): boolean {
274
- // Check history first for better navigation
275
- if (this.historyIndex > 0) {
276
- this.historyIndex--
277
- const histIndex = this.history[this.historyIndex]
278
- if (histIndex !== undefined && histIndex >= 0 && histIndex < this.items.length) {
279
- this.currentIndex = histIndex
280
- this.emit("currentItemChanged", {
281
- currentItem: this.items[this.currentIndex],
282
- currentIndex: this.currentIndex
283
- })
284
- return true
285
- }
286
- }
287
-
288
- const prevIndex = this.getPreviousIndex()
289
- return prevIndex >= 0 ? this.setCurrentIndex(prevIndex) : false
290
- }
291
-
292
- /**
293
- * Get all items
294
- */
295
- getItems(): PlaylistItem[] {
296
- return [...this.items]
297
- }
298
-
299
- /**
300
- * Get item by index
301
- */
302
- getItem(index: number): PlaylistItem | null {
303
- return index >= 0 && index < this.items.length ? this.items[index] || null : null
304
- }
305
-
306
- /**
307
- * Get item by ID
308
- */
309
- getItemById(id: string): PlaylistItem | null {
310
- return this.items.find((item) => item.id === id) || null
311
- }
312
-
313
- /**
314
- * Find item index by ID
315
- */
316
- findIndex(id: string): number {
317
- return this.items.findIndex((item) => item.id === id)
318
- }
319
-
320
- /**
321
- * Get playlist length
322
- */
323
- length(): number {
324
- return this.items.length
325
- }
326
-
327
- /**
328
- * Check if playlist is empty
329
- */
330
- isEmpty(): boolean {
331
- return this.items.length === 0
332
- }
333
-
334
- /**
335
- * Toggle shuffle mode
336
- */
337
- toggleShuffle(): boolean {
338
- this.config.shuffle = !this.config.shuffle
339
-
340
- if (this.config.shuffle) {
341
- this.shufflePlaylist()
342
- } else {
343
- this.unshufflePlaylist()
344
- }
345
-
346
- this.emit("shuffleChanged", { playlist: this.items })
347
- this.emit("configChanged", { playlist: this.items })
348
- return this.config.shuffle
349
- }
350
-
351
- /**
352
- * Set repeat mode
353
- */
354
- setRepeat(mode: "none" | "one" | "all"): void {
355
- this.config.repeat = mode
356
- this.emit("repeatChanged", { playlist: this.items })
357
- this.emit("configChanged", { playlist: this.items })
358
- }
359
-
360
- /**
361
- * Update configuration
362
- */
363
- updateConfig(config: Partial<PlaylistConfig>): void {
364
- this.config = { ...this.config, ...config }
365
- this.emit("configChanged", { playlist: this.items })
366
- }
367
-
368
- /**
369
- * Get configuration
370
- */
371
- getConfig(): PlaylistConfig {
372
- return { ...this.config }
373
- }
374
-
375
- /**
376
- * Add event listener
377
- */
378
- addEventListener(event: PlaylistEvent, callback: Function): () => void {
379
- if (!this.eventListeners.has(event)) {
380
- this.eventListeners.set(event, new Set())
381
- }
382
-
383
- this.eventListeners.get(event)!.add(callback)
384
-
385
- return () => {
386
- const listeners = this.eventListeners.get(event)
387
- if (listeners) {
388
- listeners.delete(callback)
389
- }
390
- }
391
- }
392
-
393
- /**
394
- * Get next index based on current configuration
395
- */
396
- private getNextIndex(): number {
397
- if (this.items.length === 0) return -1
398
-
399
- if (this.config.repeat === "one") {
400
- return this.currentIndex
401
- }
402
-
403
- if (this.currentIndex < this.items.length - 1) {
404
- return this.currentIndex + 1
405
- }
406
-
407
- if (this.config.repeat === "all") {
408
- return 0
409
- }
410
-
411
- return -1
412
- }
413
-
414
- /**
415
- * Get previous index
416
- */
417
- private getPreviousIndex(): number {
418
- if (this.items.length === 0) return -1
419
-
420
- if (this.config.repeat === "one") {
421
- return this.currentIndex
422
- }
423
-
424
- if (this.currentIndex > 0) {
425
- return this.currentIndex - 1
426
- }
427
-
428
- if (this.config.repeat === "all") {
429
- return this.items.length - 1
430
- }
431
-
432
- return -1
433
- }
434
-
435
- /**
436
- * Shuffle playlist
437
- */
438
- private shufflePlaylist(): void {
439
- if (this.items.length <= 1) return
440
-
441
- const currentItem = this.getCurrentItem()
442
-
443
- // Fisher-Yates shuffle
444
- for (let i = this.items.length - 1; i > 0; i--) {
445
- const j = Math.floor(Math.random() * (i + 1))
446
- const temp = this.items[i]
447
- if (temp && this.items[j]) {
448
- this.items[i] = this.items[j]
449
- this.items[j] = temp
450
- }
451
- }
452
-
453
- // Move current item to the beginning if it exists
454
- if (currentItem) {
455
- const currentItemIndex = this.items.findIndex((item) => item.id === currentItem.id)
456
- if (currentItemIndex > 0) {
457
- const temp = this.items[0]
458
- if (temp && this.items[currentItemIndex]) {
459
- this.items[0] = this.items[currentItemIndex]
460
- this.items[currentItemIndex] = temp
461
- }
462
- }
463
- this.currentIndex = 0
464
- }
465
- }
466
-
467
- /**
468
- * Restore original order
469
- */
470
- private unshufflePlaylist(): void {
471
- const currentItem = this.getCurrentItem()
472
- this.items = [...this.originalOrder]
473
-
474
- if (currentItem) {
475
- this.currentIndex = this.items.findIndex((item) => item.id === currentItem.id)
476
- }
477
- }
478
-
479
- /**
480
- * Add to history
481
- */
482
- private addToHistory(index: number): void {
483
- // Remove any future history items
484
- this.history = this.history.slice(0, this.historyIndex + 1)
485
-
486
- // Add new index
487
- this.history.push(index)
488
- this.historyIndex = this.history.length - 1
489
-
490
- // Limit history size
491
- const maxHistory = 50
492
- if (this.history.length > maxHistory) {
493
- this.history = this.history.slice(-maxHistory)
494
- this.historyIndex = this.history.length - 1
495
- }
496
- }
497
-
498
- /**
499
- * Clear history
500
- */
501
- private clearHistory(): void {
502
- this.history = []
503
- this.historyIndex = -1
504
- }
505
-
506
- /**
507
- * Emit events
508
- */
509
- private emit(event: PlaylistEvent, data?: PlaylistEventData): void {
510
- const listeners = this.eventListeners.get(event)
511
- if (listeners) {
512
- listeners.forEach((callback) => {
513
- try {
514
- callback(data)
515
- } catch (error) {
516
- console.error(`Error in playlist event listener for ${event}:`, error)
517
- }
518
- })
519
- }
520
- }
521
-
522
- /**
523
- * Export playlist as JSON
524
- */
525
- export(): string {
526
- return JSON.stringify(
527
- {
528
- items: this.items,
529
- currentIndex: this.currentIndex,
530
- config: this.config
531
- },
532
- null,
533
- 2
534
- )
535
- }
536
-
537
- /**
538
- * Import playlist from JSON
539
- */
540
- import(jsonData: string): boolean {
541
- try {
542
- const data = JSON.parse(jsonData)
543
-
544
- if (data.items && Array.isArray(data.items)) {
545
- this.clear()
546
- this.add(data.items)
547
-
548
- if (typeof data.currentIndex === "number") {
549
- this.setCurrentIndex(data.currentIndex)
550
- }
551
-
552
- if (data.config) {
553
- this.updateConfig(data.config)
554
- }
555
-
556
- return true
557
- }
558
- } catch (error) {
559
- console.error("Failed to import playlist:", error)
560
- }
561
-
562
- return false
563
- }
564
-
565
- /**
566
- * Create a new playlist from URLs
567
- */
568
- static fromUrls(urls: string[], titleExtractor?: (url: string) => string): PlaylistManager {
569
- const playlist = new PlaylistManager()
570
- const items: PlaylistItem[] = urls.map((url, index) => ({
571
- id: `item-${Date.now()}-${index}`,
572
- title: titleExtractor ? titleExtractor(url) : `Media ${index + 1}`,
573
- src: url
574
- }))
575
-
576
- playlist.add(items)
577
- return playlist
578
- }
579
-
580
- /**
581
- * Cleanup resources
582
- */
583
- destroy(): void {
584
- this.clear()
585
- this.eventListeners.clear()
586
- this.clearHistory()
587
- }
588
- }
589
-
590
- // Utility functions for playlist management
591
- export const playlistUtils = {
592
- /**
593
- * Extract title from URL
594
- */
595
- extractTitleFromUrl(url: string): string {
596
- try {
597
- const urlObj = new URL(url)
598
- const pathname = urlObj.pathname
599
- const filename = pathname.split("/").pop() || "Media"
600
-
601
- // Remove file extension
602
- return filename.split(".")[0] || "Media"
603
- } catch {
604
- return "Media"
605
- }
606
- },
607
-
608
- /**
609
- * Generate unique ID
610
- */
611
- generateId(): string {
612
- return `playlist-item-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`
613
- },
614
-
615
- /**
616
- * Validate playlist item
617
- */
618
- validateItem(item: any): item is PlaylistItem {
619
- return (
620
- typeof item === "object" &&
621
- typeof item.id === "string" &&
622
- typeof item.title === "string" &&
623
- typeof item.src === "string"
624
- )
625
- }
626
- }