@djangocfg/ui-tools 2.1.404 → 2.1.407

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 (52) hide show
  1. package/README.md +2 -1
  2. package/package.json +11 -9
  3. package/src/tools/AudioPlayer/lazy.tsx +13 -27
  4. package/src/tools/ImageViewer/components/ImageViewer.tsx +10 -2
  5. package/src/tools/VideoPlayer/README.md +87 -230
  6. package/src/tools/VideoPlayer/VideoPlayer.tsx +82 -0
  7. package/src/tools/VideoPlayer/canvas/canvas-dispatcher.tsx +34 -0
  8. package/src/tools/VideoPlayer/canvas/hls-canvas.tsx +38 -0
  9. package/src/tools/VideoPlayer/canvas/iframe-canvas.tsx +33 -0
  10. package/src/tools/VideoPlayer/canvas/index.ts +12 -0
  11. package/src/tools/VideoPlayer/canvas/jsx.d.ts +54 -0
  12. package/src/tools/VideoPlayer/canvas/native-canvas.tsx +38 -0
  13. package/src/tools/VideoPlayer/canvas/vimeo-canvas.tsx +39 -0
  14. package/src/tools/VideoPlayer/canvas/youtube-canvas.tsx +77 -0
  15. package/src/tools/VideoPlayer/index.ts +51 -65
  16. package/src/tools/VideoPlayer/lazy.tsx +11 -54
  17. package/src/tools/VideoPlayer/parts/controls-bar.tsx +35 -0
  18. package/src/tools/VideoPlayer/parts/fullscreen.tsx +19 -0
  19. package/src/tools/VideoPlayer/parts/index.ts +15 -0
  20. package/src/tools/VideoPlayer/parts/pip.tsx +19 -0
  21. package/src/tools/VideoPlayer/parts/play-button.tsx +19 -0
  22. package/src/tools/VideoPlayer/parts/playback-rate.tsx +31 -0
  23. package/src/tools/VideoPlayer/parts/poster.tsx +3 -0
  24. package/src/tools/VideoPlayer/parts/seek-bar.tsx +26 -0
  25. package/src/tools/VideoPlayer/parts/volume.tsx +32 -0
  26. package/src/tools/VideoPlayer/styles/video-player.css +141 -0
  27. package/src/tools/VideoPlayer/types.ts +82 -0
  28. package/src/tools/VideoPlayer/utils/parse-embed-url.ts +70 -0
  29. package/src/tools/VideoPlayer/utils/vimeo-id.ts +24 -0
  30. package/src/tools/VideoPlayer/utils/youtube-id.ts +64 -0
  31. package/src/tools/index.ts +35 -28
  32. package/src/tools/VideoPlayer/components/VideoControls.tsx +0 -138
  33. package/src/tools/VideoPlayer/components/VideoErrorFallback.tsx +0 -172
  34. package/src/tools/VideoPlayer/components/VideoPlayer.tsx +0 -201
  35. package/src/tools/VideoPlayer/components/index.ts +0 -14
  36. package/src/tools/VideoPlayer/context/VideoPlayerContext.tsx +0 -52
  37. package/src/tools/VideoPlayer/context/index.ts +0 -8
  38. package/src/tools/VideoPlayer/hooks/index.ts +0 -12
  39. package/src/tools/VideoPlayer/hooks/useVideoPlayerSettings.ts +0 -71
  40. package/src/tools/VideoPlayer/hooks/useVideoPositionCache.ts +0 -117
  41. package/src/tools/VideoPlayer/providers/NativeProvider.tsx +0 -284
  42. package/src/tools/VideoPlayer/providers/StreamProvider.tsx +0 -505
  43. package/src/tools/VideoPlayer/providers/VidstackProvider.tsx +0 -397
  44. package/src/tools/VideoPlayer/providers/index.ts +0 -8
  45. package/src/tools/VideoPlayer/types/index.ts +0 -38
  46. package/src/tools/VideoPlayer/types/player.ts +0 -116
  47. package/src/tools/VideoPlayer/types/provider.ts +0 -93
  48. package/src/tools/VideoPlayer/types/sources.ts +0 -97
  49. package/src/tools/VideoPlayer/utils/debug.ts +0 -14
  50. package/src/tools/VideoPlayer/utils/fileSource.ts +0 -78
  51. package/src/tools/VideoPlayer/utils/index.ts +0 -12
  52. package/src/tools/VideoPlayer/utils/resolvers.ts +0 -75
@@ -0,0 +1,32 @@
1
+ 'use client';
2
+
3
+ import { MediaMuteButton, MediaVolumeRange } from 'media-chrome/react';
4
+ import { cn } from '@djangocfg/ui-core/lib';
5
+ import type { ComponentProps } from 'react';
6
+
7
+ export interface VolumeProps {
8
+ readonly className?: string;
9
+ readonly iconOnly?: boolean;
10
+ readonly muteProps?: ComponentProps<typeof MediaMuteButton>;
11
+ readonly rangeProps?: ComponentProps<typeof MediaVolumeRange>;
12
+ }
13
+
14
+ export function Volume({ className, iconOnly, muteProps, rangeProps }: VolumeProps) {
15
+ return (
16
+ <div className={cn('flex items-center', className)}>
17
+ <MediaMuteButton
18
+ {...muteProps}
19
+ className={cn(
20
+ 'media-control-square h-8 w-8 rounded-md text-foreground hover:bg-foreground/10',
21
+ muteProps?.className,
22
+ )}
23
+ />
24
+ {!iconOnly && (
25
+ <MediaVolumeRange
26
+ {...rangeProps}
27
+ className={cn('h-8 w-20 text-foreground', rangeProps?.className)}
28
+ />
29
+ )}
30
+ </div>
31
+ );
32
+ }
@@ -0,0 +1,141 @@
1
+ /*
2
+ * media-chrome theme.
3
+ *
4
+ * The video canvas is ALWAYS a black surface, so the control chrome is
5
+ * themed against on-black contrast — icons/text stay light in both the
6
+ * light and dark app themes. Only the accent (progress bar / thumb) and
7
+ * the scrub-time popover follow semantic tokens, since the popover is a
8
+ * detached surface that should match the rest of the platform.
9
+ *
10
+ * media-chrome ships its own focus-ring + tooltip styles; we only override
11
+ * what's needed to match the rest of the platform.
12
+ */
13
+
14
+ media-controller {
15
+ /* On-black control chrome — fixed regardless of app theme. */
16
+ --video-on-canvas: rgb(245 245 245);
17
+
18
+ /* Surfaces */
19
+ --media-control-background: transparent;
20
+ --media-control-hover-background: rgb(255 255 255 / 0.14);
21
+ --media-control-padding: 0;
22
+
23
+ /* Foreground / accent */
24
+ --media-primary-color: var(--primary);
25
+ --media-secondary-color: rgb(255 255 255 / 0.6);
26
+ --media-text-color: var(--video-on-canvas);
27
+ --media-icon-color: var(--video-on-canvas);
28
+ --media-loading-icon-color: var(--video-on-canvas);
29
+
30
+ /* Range / progress bar — thin translucent rail, small accent thumb.
31
+ The range element keeps a tall hit-area; only the painted track is
32
+ 4px so it reads as a slim progress line over the video. */
33
+ --media-range-track-background: color-mix(in oklab, white 28%, transparent);
34
+ --media-range-track-border-radius: 9999px;
35
+ --media-range-track-height: 4px;
36
+ --media-range-track-pointer-background: color-mix(in oklab, white 40%, transparent);
37
+ --media-range-bar-color: var(--primary);
38
+ --media-range-thumb-background: var(--primary);
39
+ --media-range-thumb-border-radius: 9999px;
40
+ --media-range-thumb-width: 12px;
41
+ --media-range-thumb-height: 12px;
42
+ --media-range-thumb-opacity: 0;
43
+ --media-range-thumb-transition: opacity 0.15s ease;
44
+
45
+ /* Tooltip */
46
+ --media-tooltip-background: var(--popover);
47
+ --media-tooltip-color: var(--popover-foreground);
48
+ --media-tooltip-border-radius: 6px;
49
+
50
+ /* Font */
51
+ --media-font-family: inherit;
52
+ --media-font-size: 12px;
53
+
54
+ /* Layout */
55
+ display: block;
56
+ position: relative;
57
+ width: 100%;
58
+ }
59
+
60
+ /* Square icon buttons should size to the wrapper. */
61
+ media-controller .media-control-square::part(button) {
62
+ width: 100%;
63
+ height: 100%;
64
+ }
65
+
66
+ /*
67
+ * Control buttons / text — fixed on-black colours. The video canvas is
68
+ * always dark, so these never follow the app's light/dark theme.
69
+ */
70
+ .video-player__control {
71
+ color: var(--video-on-canvas, rgb(245 245 245));
72
+ border-radius: 0.375rem;
73
+ transition: background-color 0.15s ease;
74
+ }
75
+
76
+ .video-player__control:hover {
77
+ background-color: rgb(255 255 255 / 0.14);
78
+ }
79
+
80
+ .video-player__time {
81
+ color: rgb(255 255 255 / 0.72);
82
+ }
83
+
84
+ /* Hide the default control bar background — we paint our own gradient
85
+ scrim via the <ControlsBar> wrapper. */
86
+ media-control-bar {
87
+ background: transparent;
88
+ }
89
+
90
+ /*
91
+ * Auto-hide. media-chrome flags inactivity by setting `userinactive` on
92
+ * the <media-controller>; it only does so while playback is running, and
93
+ * removes it on mousemove / pause / focus. We fade the whole control bar
94
+ * (controls + gradient scrim) together with a smooth opacity transition.
95
+ */
96
+ .video-player__control-bar {
97
+ opacity: 1;
98
+ transition: opacity 0.3s ease-out;
99
+ }
100
+
101
+ media-controller[userinactive]:not([mediapaused]) .video-player__control-bar {
102
+ opacity: 0;
103
+ pointer-events: none;
104
+ }
105
+
106
+ /*
107
+ * Seek-bar hover preview. `<media-time-range>` exposes two slotted
108
+ * boxes: `preview-box` (a 120×109 thumbnail panel) and `current-box`
109
+ * (the scrub time label). With no `thumbnails` track wired up the
110
+ * preview-box has zero slotted content but still paints its default
111
+ * dark `rgb(31,31,31)` background — it shows as a stray empty
112
+ * rectangle floating over the video.
113
+ *
114
+ * Hide the empty preview-box entirely; keep `current-box` and style
115
+ * its time label as a compact popover chip.
116
+ */
117
+ media-time-range {
118
+ /* media-chrome's own preview/box vars — point them at our popover
119
+ surface so the scrub time chip matches the rest of the controls. */
120
+ --media-preview-background: var(--popover);
121
+ --media-preview-border-radius: 6px;
122
+ --media-text-color: var(--popover-foreground);
123
+ }
124
+
125
+ /* Reveal the accent thumb only while hovering / scrubbing the rail. */
126
+ media-time-range:hover {
127
+ --media-range-thumb-opacity: 1;
128
+ }
129
+
130
+ media-time-range::part(preview-box) {
131
+ display: none;
132
+ }
133
+
134
+ media-time-range::part(current-box) {
135
+ padding: 2px 6px;
136
+ border-radius: 6px;
137
+ background: var(--popover) !important;
138
+ color: var(--popover-foreground);
139
+ font-size: 11px;
140
+ box-shadow: 0 4px 12px color-mix(in oklab, var(--foreground) 18%, transparent);
141
+ }
@@ -0,0 +1,82 @@
1
+ /**
2
+ * VideoPlayer types — discriminated `VideoSource` union + props.
3
+ *
4
+ * The component is engine-agnostic at the API surface: callers either
5
+ * pass a structured `VideoSource` or a raw URL string (auto-parsed via
6
+ * `parseEmbedUrl`).
7
+ */
8
+
9
+ import type { ReactNode } from 'react';
10
+
11
+ export interface UrlSource {
12
+ readonly type: 'url';
13
+ readonly url: string;
14
+ readonly mimeType?: string;
15
+ readonly title?: string;
16
+ readonly poster?: string;
17
+ }
18
+
19
+ export interface YouTubeSource {
20
+ readonly type: 'youtube';
21
+ readonly videoId: string;
22
+ readonly startTime?: number;
23
+ readonly playlistId?: string;
24
+ readonly title?: string;
25
+ readonly poster?: string;
26
+ }
27
+
28
+ export interface VimeoSource {
29
+ readonly type: 'vimeo';
30
+ readonly videoId: string;
31
+ readonly startTime?: number;
32
+ readonly title?: string;
33
+ readonly poster?: string;
34
+ }
35
+
36
+ export interface HlsSource {
37
+ readonly type: 'hls';
38
+ readonly url: string;
39
+ readonly title?: string;
40
+ readonly poster?: string;
41
+ }
42
+
43
+ export interface IframeSource {
44
+ readonly type: 'iframe';
45
+ readonly url: string;
46
+ readonly title?: string;
47
+ readonly poster?: string;
48
+ readonly allow?: string;
49
+ }
50
+
51
+ export type VideoSource =
52
+ | UrlSource
53
+ | YouTubeSource
54
+ | VimeoSource
55
+ | HlsSource
56
+ | IframeSource;
57
+
58
+ export type AspectRatioValue = number | 'auto' | 'fill';
59
+
60
+ export interface VideoPlayerSettings {
61
+ readonly autoPlay?: boolean;
62
+ readonly muted?: boolean;
63
+ readonly loop?: boolean;
64
+ readonly playsInline?: boolean;
65
+ readonly crossOrigin?: '' | 'anonymous' | 'use-credentials';
66
+ readonly preload?: 'none' | 'metadata' | 'auto';
67
+ }
68
+
69
+ export interface VideoPlayerProps extends VideoPlayerSettings {
70
+ /**
71
+ * Structured source object — or a raw URL string that will be
72
+ * auto-classified via `parseEmbedUrl` (YouTube / Vimeo / HLS / MP4 / iframe).
73
+ */
74
+ readonly source: VideoSource | string;
75
+ /** Default `true`. When `false`, no built-in `<MediaControlBar>` is rendered. */
76
+ readonly controls?: boolean;
77
+ /** Default `16/9`. `'fill'` stretches to parent height; `'auto'` keeps intrinsic. */
78
+ readonly aspectRatio?: AspectRatioValue;
79
+ readonly className?: string;
80
+ /** Custom children replace the default control bar entirely. */
81
+ readonly children?: ReactNode;
82
+ }
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Smart URL classifier — maps an arbitrary string into a structured
3
+ * `VideoSource`.
4
+ *
5
+ * Order:
6
+ * 1. YouTube (youtube.com, youtu.be, shorts, embed)
7
+ * 2. Vimeo (vimeo.com, player.vimeo.com)
8
+ * 3. HLS (`.m3u8`)
9
+ * 4. Native (`.mp4`, `.webm`, `.mov`, `.mkv`, `.ogv`, `.m4v`)
10
+ * 5. Fallback — treat as iframe embed.
11
+ *
12
+ * Pure; no React, no DOM.
13
+ */
14
+
15
+ import type { VideoSource } from '../types';
16
+ import { extractYouTubeId, parseYouTubeStartTime } from './youtube-id';
17
+ import { extractVimeoId } from './vimeo-id';
18
+
19
+ const NATIVE_VIDEO_EXT = /\.(mp4|webm|mov|mkv|ogv|m4v)(\?.*)?$/i;
20
+ const HLS_EXT = /\.m3u8(\?.*)?$/i;
21
+
22
+ export function parseEmbedUrl(input: string): VideoSource {
23
+ const trimmed = input.trim();
24
+
25
+ // 1. YouTube.
26
+ const ytId = extractYouTubeId(trimmed);
27
+ if (ytId) {
28
+ let startTime: number | undefined;
29
+ let playlistId: string | undefined;
30
+ try {
31
+ const url = new URL(trimmed);
32
+ startTime = parseYouTubeStartTime(url.searchParams.get('t'));
33
+ const list = url.searchParams.get('list');
34
+ if (list && /^[\w-]+$/.test(list)) playlistId = list;
35
+ } catch {
36
+ /* ignore */
37
+ }
38
+ return {
39
+ type: 'youtube',
40
+ videoId: ytId,
41
+ ...(startTime !== undefined && { startTime }),
42
+ ...(playlistId && { playlistId }),
43
+ };
44
+ }
45
+
46
+ // 2. Vimeo.
47
+ const vimeoId = extractVimeoId(trimmed);
48
+ if (vimeoId) {
49
+ return { type: 'vimeo', videoId: vimeoId };
50
+ }
51
+
52
+ // 3. HLS.
53
+ if (HLS_EXT.test(trimmed)) {
54
+ return { type: 'hls', url: trimmed };
55
+ }
56
+
57
+ // 4. Native video file.
58
+ if (NATIVE_VIDEO_EXT.test(trimmed)) {
59
+ return { type: 'url', url: trimmed };
60
+ }
61
+
62
+ // 5. Fallback: blob: / data: / unknown http(s) URL — assume native <video>
63
+ // can handle blob/data, iframe for everything else.
64
+ if (/^(blob:|data:)/i.test(trimmed)) {
65
+ return { type: 'url', url: trimmed };
66
+ }
67
+
68
+ // Unknown URL — fall back to iframe so embeds still surface.
69
+ return { type: 'iframe', url: trimmed };
70
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Extract a Vimeo numeric `videoId` from a URL.
3
+ *
4
+ * Supports:
5
+ * - vimeo.com/123456789
6
+ * - vimeo.com/123456789/HASH
7
+ * - player.vimeo.com/video/123456789
8
+ *
9
+ * Returns `null` if the URL does not match.
10
+ */
11
+ export function extractVimeoId(input: string): string | null {
12
+ let url: URL;
13
+ try {
14
+ url = new URL(input);
15
+ } catch {
16
+ return null;
17
+ }
18
+ const host = url.hostname.replace(/^www\./, '');
19
+ if (host !== 'vimeo.com' && host !== 'player.vimeo.com') return null;
20
+
21
+ // /video/<id> on player.vimeo.com, /<id> on vimeo.com.
22
+ const match = url.pathname.match(/(?:^\/video\/|^\/)(\d+)/);
23
+ return match ? match[1] : null;
24
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Extract a YouTube `videoId` from a URL.
3
+ *
4
+ * Supports:
5
+ * - youtube.com/watch?v=ID
6
+ * - youtu.be/ID
7
+ * - youtube.com/shorts/ID
8
+ * - youtube.com/embed/ID
9
+ * - youtube.com/v/ID
10
+ * - m.youtube.com/* mirrors
11
+ *
12
+ * Returns `null` if the URL does not match.
13
+ */
14
+ export function extractYouTubeId(input: string): string | null {
15
+ let url: URL;
16
+ try {
17
+ url = new URL(input);
18
+ } catch {
19
+ return null;
20
+ }
21
+
22
+ const host = url.hostname.replace(/^www\.|^m\./, '');
23
+
24
+ if (host === 'youtu.be') {
25
+ const id = url.pathname.replace(/^\//, '').split('/')[0];
26
+ return isValidId(id) ? id : null;
27
+ }
28
+
29
+ if (host === 'youtube.com' || host === 'youtube-nocookie.com') {
30
+ if (url.pathname === '/watch') {
31
+ const v = url.searchParams.get('v');
32
+ return v && isValidId(v) ? v : null;
33
+ }
34
+ const m = url.pathname.match(/^\/(?:shorts|embed|v|live)\/([^/?#]+)/);
35
+ if (m) {
36
+ return isValidId(m[1]) ? m[1] : null;
37
+ }
38
+ }
39
+
40
+ return null;
41
+ }
42
+
43
+ /** Parse the YouTube `?t=` / `&t=` start-time param (`90`, `90s`, `1m30s`). */
44
+ export function parseYouTubeStartTime(input: string | null): number | undefined {
45
+ if (!input) return undefined;
46
+ // Pure seconds.
47
+ if (/^\d+s?$/.test(input)) {
48
+ const n = parseInt(input, 10);
49
+ return Number.isFinite(n) && n > 0 ? n : undefined;
50
+ }
51
+ // `1h2m3s` / `2m30s` / `45s`.
52
+ const match = input.match(/^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s?)?$/);
53
+ if (!match) return undefined;
54
+ const [, h, m, s] = match;
55
+ const total =
56
+ (h ? parseInt(h, 10) * 3600 : 0) +
57
+ (m ? parseInt(m, 10) * 60 : 0) +
58
+ (s ? parseInt(s, 10) : 0);
59
+ return total > 0 ? total : undefined;
60
+ }
61
+
62
+ function isValidId(id: string | undefined): id is string {
63
+ return !!id && /^[\w-]{6,}$/.test(id);
64
+ }
@@ -43,43 +43,50 @@ export * from './JsonForm/utils';
43
43
  export { default as OpenapiViewer } from './OpenapiViewer';
44
44
  export type { PlaygroundConfig, SchemaSource, PlaygroundProps } from './OpenapiViewer';
45
45
 
46
- // Export VideoPlayer
46
+ // Export VideoPlayer (media-chrome shell with provider-aware canvases)
47
47
  export {
48
48
  VideoPlayer,
49
- VideoControls,
50
- VidstackProvider,
51
- NativeProvider,
52
- StreamProvider,
53
- VideoPlayerProvider,
54
- useVideoPlayerContext,
55
- VideoErrorFallback,
56
- createVideoErrorFallback,
57
- resolvePlayerMode,
58
- resolveFileSource,
59
- isSimpleStreamSource,
60
- resolveStreamSource,
49
+ CanvasDispatcher,
50
+ NativeCanvas,
51
+ YouTubeCanvas,
52
+ VimeoCanvas,
53
+ HlsCanvas,
54
+ IframeCanvas,
55
+ PlayButton,
56
+ SeekBar,
57
+ Volume,
58
+ Fullscreen,
59
+ Pip,
60
+ PlaybackRate,
61
+ ControlsBar,
62
+ Poster,
63
+ parseEmbedUrl,
64
+ extractYouTubeId,
65
+ extractVimeoId,
61
66
  } from './VideoPlayer';
62
67
  export type {
63
- VideoSourceUnion,
68
+ VideoSource,
64
69
  UrlSource,
65
70
  YouTubeSource,
66
71
  VimeoSource,
67
- HLSSource,
68
- DASHSource,
69
- StreamSource,
70
- BlobSource,
71
- DataUrlSource,
72
- PlayerMode,
72
+ HlsSource,
73
+ IframeSource,
73
74
  AspectRatioValue,
74
75
  VideoPlayerProps,
75
- VideoPlayerRef,
76
- ErrorFallbackProps,
77
- ResolveFileSourceOptions,
78
- VideoPlayerContextValue,
79
- VideoPlayerProviderProps,
80
- SimpleStreamSource,
81
- VideoErrorFallbackProps,
82
- CreateVideoErrorFallbackOptions,
76
+ VideoPlayerSettings,
77
+ PlayButtonProps,
78
+ SeekBarProps,
79
+ VolumeProps,
80
+ FullscreenProps,
81
+ PipProps,
82
+ PlaybackRateProps,
83
+ ControlsBarProps,
84
+ CanvasDispatcherProps,
85
+ NativeCanvasProps,
86
+ YouTubeCanvasProps,
87
+ VimeoCanvasProps,
88
+ HlsCanvasProps,
89
+ IframeCanvasProps,
83
90
  } from './VideoPlayer';
84
91
 
85
92
  // AudioPlayer v6 — under construction (see @dev/@refactoring6-audioplayer/).
@@ -1,138 +0,0 @@
1
- /**
2
- * Custom Video Controls for Vidstack Player
3
- */
4
-
5
- 'use client';
6
-
7
- import { Maximize, Minimize, Pause, Play, Volume2, VolumeX } from 'lucide-react';
8
- import React from 'react';
9
-
10
- import { cn } from '@djangocfg/ui-core/lib';
11
- import { useMediaRemote, useMediaStore } from '@vidstack/react';
12
-
13
- import type { MediaPlayerInstance } from '@vidstack/react';
14
- interface VideoControlsProps {
15
- player: React.RefObject<MediaPlayerInstance | null>;
16
- className?: string;
17
- }
18
-
19
- export function VideoControls({ player, className }: VideoControlsProps) {
20
- const store = useMediaStore(player);
21
- const remote = useMediaRemote();
22
-
23
- const isPaused = store.paused;
24
- const isMuted = store.muted;
25
- const isFullscreen = store.fullscreen;
26
- const currentTime = store.currentTime;
27
- const duration = store.duration;
28
- const volume = store.volume;
29
-
30
- const formatTime = (seconds: number): string => {
31
- if (!seconds || seconds < 0) return '0:00';
32
- const minutes = Math.floor(seconds / 60);
33
- const secs = Math.floor(seconds % 60);
34
- return `${minutes}:${secs.toString().padStart(2, '0')}`;
35
- };
36
-
37
- const handleProgressClick = (e: React.MouseEvent<HTMLDivElement>) => {
38
- if (!duration) return;
39
- const rect = e.currentTarget.getBoundingClientRect();
40
- const clickX = e.clientX - rect.left;
41
- const percentage = clickX / rect.width;
42
- const newTime = percentage * duration;
43
- remote.seek(newTime);
44
- };
45
-
46
- const handleVolumeChange = (e: React.MouseEvent<HTMLDivElement>) => {
47
- const rect = e.currentTarget.getBoundingClientRect();
48
- const clickX = e.clientX - rect.left;
49
- const percentage = Math.max(0, Math.min(1, clickX / rect.width));
50
- remote.changeVolume(percentage);
51
- if (percentage > 0 && isMuted) {
52
- remote.toggleMuted();
53
- }
54
- };
55
-
56
- const progress = duration > 0 ? (currentTime / duration) * 100 : 0;
57
-
58
- return (
59
- <div
60
- className={cn(
61
- "absolute inset-0 flex flex-col justify-end transition-opacity duration-300",
62
- "bg-gradient-to-t from-black/80 via-black/20 to-transparent",
63
- "opacity-0 group-hover:opacity-100 focus-within:opacity-100",
64
- "pointer-events-none group-hover:pointer-events-auto",
65
- className
66
- )}
67
- >
68
- {/* Progress Bar */}
69
- <div className="px-4 pb-2 pointer-events-auto">
70
- <div
71
- className="h-1.5 bg-white/20 rounded-full cursor-pointer hover:h-2 transition-all group"
72
- onClick={handleProgressClick}
73
- >
74
- <div
75
- className="h-full bg-primary rounded-full transition-all relative group-hover:bg-primary/90"
76
- style={{ width: `${progress}%` }}
77
- >
78
- <div className="absolute right-0 top-1/2 -translate-y-1/2 w-3 h-3 bg-white rounded-full opacity-0 group-hover:opacity-100 transition-opacity" />
79
- </div>
80
- </div>
81
- </div>
82
-
83
- {/* Control Bar */}
84
- <div className="flex items-center gap-4 px-4 pb-4 pointer-events-auto">
85
- {/* Play/Pause */}
86
- <button
87
- onClick={() => remote.togglePaused()}
88
- className="text-white hover:text-primary transition-colors p-1.5 hover:bg-white/10 rounded-full"
89
- >
90
- {isPaused ? <Play className="h-6 w-6" /> : <Pause className="h-6 w-6" />}
91
- </button>
92
-
93
- {/* Time */}
94
- <div className="text-white text-sm font-medium">
95
- {formatTime(currentTime)} / {formatTime(duration)}
96
- </div>
97
-
98
- <div className="flex-1" />
99
-
100
- {/* Volume Control */}
101
- <div className="flex items-center gap-2 group/volume">
102
- <button
103
- onClick={() => remote.toggleMuted()}
104
- className="text-white hover:text-primary transition-colors p-1.5 hover:bg-white/10 rounded-full"
105
- >
106
- {isMuted || volume === 0 ? (
107
- <VolumeX className="h-5 w-5" />
108
- ) : (
109
- <Volume2 className="h-5 w-5" />
110
- )}
111
- </button>
112
-
113
- <div
114
- className="w-0 group-hover/volume:w-20 transition-all overflow-hidden"
115
- >
116
- <div
117
- className="h-1.5 bg-white/20 rounded-full cursor-pointer hover:h-2 transition-all"
118
- onClick={handleVolumeChange}
119
- >
120
- <div
121
- className="h-full bg-white rounded-full transition-all"
122
- style={{ width: `${volume * 100}%` }}
123
- />
124
- </div>
125
- </div>
126
- </div>
127
-
128
- {/* Fullscreen */}
129
- <button
130
- onClick={() => isFullscreen ? remote.exitFullscreen() : remote.enterFullscreen()}
131
- className="text-white hover:text-primary transition-colors p-1.5 hover:bg-white/10 rounded-full"
132
- >
133
- {isFullscreen ? <Minimize className="h-5 w-5" /> : <Maximize className="h-5 w-5" />}
134
- </button>
135
- </div>
136
- </div>
137
- );
138
- }