@djangocfg/ui-nextjs 2.1.65 → 2.1.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -8
- package/src/blocks/SplitHero/SplitHeroMedia.tsx +2 -1
- package/src/stores/index.ts +8 -0
- package/src/stores/mediaCache.ts +464 -0
- package/src/tools/AudioPlayer/@refactoring/00-PLAN.md +148 -0
- package/src/tools/AudioPlayer/@refactoring/01-TYPES.md +301 -0
- package/src/tools/AudioPlayer/@refactoring/02-HOOKS.md +281 -0
- package/src/tools/AudioPlayer/@refactoring/03-CONTEXT.md +328 -0
- package/src/tools/AudioPlayer/@refactoring/04-COMPONENTS.md +251 -0
- package/src/tools/AudioPlayer/@refactoring/05-EFFECTS.md +427 -0
- package/src/tools/AudioPlayer/@refactoring/06-UTILS-AND-INDEX.md +193 -0
- package/src/tools/AudioPlayer/@refactoring/07-EXECUTION-CHECKLIST.md +146 -0
- package/src/tools/AudioPlayer/README.md +325 -0
- package/src/tools/AudioPlayer/components/AudioEqualizer.tsx +200 -0
- package/src/tools/AudioPlayer/components/AudioPlayer.tsx +231 -0
- package/src/tools/AudioPlayer/components/AudioShortcutsPopover.tsx +99 -0
- package/src/tools/AudioPlayer/components/ReactiveCover/AudioReactiveCover.tsx +147 -0
- package/src/tools/AudioPlayer/components/ReactiveCover/effects/GlowEffect.tsx +110 -0
- package/src/tools/AudioPlayer/components/ReactiveCover/effects/MeshEffect.tsx +58 -0
- package/src/tools/AudioPlayer/components/ReactiveCover/effects/OrbsEffect.tsx +45 -0
- package/src/tools/AudioPlayer/components/ReactiveCover/effects/SpotlightEffect.tsx +82 -0
- package/src/tools/AudioPlayer/components/ReactiveCover/effects/index.ts +8 -0
- package/src/tools/AudioPlayer/components/ReactiveCover/index.ts +6 -0
- package/src/tools/AudioPlayer/components/SimpleAudioPlayer.tsx +280 -0
- package/src/tools/AudioPlayer/components/VisualizationToggle.tsx +64 -0
- package/src/tools/AudioPlayer/components/index.ts +21 -0
- package/src/tools/AudioPlayer/context/AudioProvider.tsx +292 -0
- package/src/tools/AudioPlayer/context/index.ts +11 -0
- package/src/tools/AudioPlayer/context/selectors.ts +96 -0
- package/src/tools/AudioPlayer/effects/index.ts +412 -0
- package/src/tools/AudioPlayer/hooks/index.ts +29 -0
- package/src/tools/AudioPlayer/hooks/useAudioAnalysis.ts +110 -0
- package/src/tools/AudioPlayer/hooks/useAudioHotkeys.ts +149 -0
- package/src/tools/AudioPlayer/hooks/useSharedWebAudio.ts +106 -0
- package/src/tools/AudioPlayer/hooks/useVisualization.tsx +201 -0
- package/src/tools/AudioPlayer/index.ts +139 -0
- package/src/tools/AudioPlayer/types/audio.ts +107 -0
- package/src/tools/AudioPlayer/types/components.ts +98 -0
- package/src/tools/AudioPlayer/types/effects.ts +73 -0
- package/src/tools/AudioPlayer/types/index.ts +35 -0
- package/src/tools/AudioPlayer/utils/formatTime.ts +10 -0
- package/src/tools/AudioPlayer/utils/index.ts +5 -0
- package/src/tools/ImageViewer/@refactoring/00-PLAN.md +71 -0
- package/src/tools/ImageViewer/@refactoring/01-TYPES.md +121 -0
- package/src/tools/ImageViewer/@refactoring/02-UTILS.md +143 -0
- package/src/tools/ImageViewer/@refactoring/03-HOOKS.md +261 -0
- package/src/tools/ImageViewer/@refactoring/04-COMPONENTS.md +427 -0
- package/src/tools/ImageViewer/@refactoring/05-EXECUTION-CHECKLIST.md +126 -0
- package/src/tools/ImageViewer/README.md +174 -0
- package/src/tools/ImageViewer/components/ImageInfo.tsx +44 -0
- package/src/tools/ImageViewer/components/ImageToolbar.tsx +150 -0
- package/src/tools/ImageViewer/components/ImageViewer.tsx +235 -0
- package/src/tools/ImageViewer/components/index.ts +7 -0
- package/src/tools/ImageViewer/hooks/index.ts +9 -0
- package/src/tools/ImageViewer/hooks/useImageLoading.ts +153 -0
- package/src/tools/ImageViewer/hooks/useImageTransform.ts +101 -0
- package/src/tools/ImageViewer/index.ts +60 -0
- package/src/tools/ImageViewer/types.ts +75 -0
- package/src/tools/ImageViewer/utils/constants.ts +59 -0
- package/src/tools/ImageViewer/utils/index.ts +16 -0
- package/src/tools/ImageViewer/utils/lqip.ts +47 -0
- package/src/tools/VideoPlayer/@refactoring/00-PLAN.md +91 -0
- package/src/tools/VideoPlayer/@refactoring/01-TYPES.md +284 -0
- package/src/tools/VideoPlayer/@refactoring/02-UTILS.md +141 -0
- package/src/tools/VideoPlayer/@refactoring/03-HOOKS.md +178 -0
- package/src/tools/VideoPlayer/@refactoring/04-COMPONENTS.md +95 -0
- package/src/tools/VideoPlayer/@refactoring/05-EXECUTION-CHECKLIST.md +139 -0
- package/src/tools/VideoPlayer/README.md +212 -187
- package/src/tools/VideoPlayer/{VideoControls.tsx → components/VideoControls.tsx} +8 -9
- package/src/tools/VideoPlayer/components/VideoErrorFallback.tsx +174 -0
- package/src/tools/VideoPlayer/components/VideoPlayer.tsx +201 -0
- package/src/tools/VideoPlayer/components/index.ts +14 -0
- package/src/tools/VideoPlayer/context/VideoPlayerContext.tsx +52 -0
- package/src/tools/VideoPlayer/context/index.ts +8 -0
- package/src/tools/VideoPlayer/hooks/index.ts +9 -0
- package/src/tools/VideoPlayer/hooks/useVideoPositionCache.ts +109 -0
- package/src/tools/VideoPlayer/index.ts +70 -9
- package/src/tools/VideoPlayer/providers/NativeProvider.tsx +206 -0
- package/src/tools/VideoPlayer/providers/StreamProvider.tsx +401 -0
- package/src/tools/VideoPlayer/providers/VidstackProvider.tsx +332 -0
- package/src/tools/VideoPlayer/providers/index.ts +8 -0
- package/src/tools/VideoPlayer/types/index.ts +38 -0
- package/src/tools/VideoPlayer/types/player.ts +116 -0
- package/src/tools/VideoPlayer/types/provider.ts +93 -0
- package/src/tools/VideoPlayer/types/sources.ts +97 -0
- package/src/tools/VideoPlayer/utils/fileSource.ts +78 -0
- package/src/tools/VideoPlayer/utils/index.ts +11 -0
- package/src/tools/VideoPlayer/utils/resolvers.ts +75 -0
- package/src/tools/index.ts +92 -4
- package/src/tools/VideoPlayer/NativePlayer.tsx +0 -141
- package/src/tools/VideoPlayer/VideoPlayer.tsx +0 -231
- package/src/tools/VideoPlayer/types.ts +0 -118
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VidstackProvider - Full-featured video player using Vidstack
|
|
3
|
+
* Supports YouTube, Vimeo, HLS, DASH, and direct URLs
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
'use client';
|
|
7
|
+
|
|
8
|
+
// Import Vidstack base styles
|
|
9
|
+
import '@vidstack/react/player/styles/base.css';
|
|
10
|
+
import '@vidstack/react/player/styles/default/theme.css';
|
|
11
|
+
import '@vidstack/react/player/styles/default/layouts/video.css';
|
|
12
|
+
|
|
13
|
+
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
14
|
+
|
|
15
|
+
import { cn, generateOgImageUrl } from '@djangocfg/ui-core/lib';
|
|
16
|
+
import { MediaPlayer, MediaProvider, Poster } from '@vidstack/react';
|
|
17
|
+
import { defaultLayoutIcons, DefaultVideoLayout } from '@vidstack/react/player/layouts/default';
|
|
18
|
+
import { useVideoCache } from '../../../stores/mediaCache';
|
|
19
|
+
|
|
20
|
+
import type { MediaPlayerInstance } from '@vidstack/react';
|
|
21
|
+
import type { VidstackProviderProps, VideoPlayerRef, ErrorFallbackProps } from '../types';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Convert source to Vidstack-compatible format
|
|
25
|
+
*/
|
|
26
|
+
function getVidstackSrc(source: VidstackProviderProps['source']): string {
|
|
27
|
+
switch (source.type) {
|
|
28
|
+
case 'youtube':
|
|
29
|
+
return `youtube/${source.id}`;
|
|
30
|
+
case 'vimeo':
|
|
31
|
+
return `vimeo/${source.id}`;
|
|
32
|
+
case 'hls':
|
|
33
|
+
case 'dash':
|
|
34
|
+
case 'url':
|
|
35
|
+
return source.url;
|
|
36
|
+
default:
|
|
37
|
+
return '';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Default error fallback UI */
|
|
42
|
+
function DefaultErrorFallback({ error }: ErrorFallbackProps) {
|
|
43
|
+
return (
|
|
44
|
+
<div className="absolute inset-0 flex flex-col items-center justify-center gap-4 text-white bg-black">
|
|
45
|
+
<svg
|
|
46
|
+
className="w-16 h-16 text-muted-foreground"
|
|
47
|
+
fill="none"
|
|
48
|
+
stroke="currentColor"
|
|
49
|
+
viewBox="0 0 24 24"
|
|
50
|
+
>
|
|
51
|
+
<path
|
|
52
|
+
strokeLinecap="round"
|
|
53
|
+
strokeLinejoin="round"
|
|
54
|
+
strokeWidth={2}
|
|
55
|
+
d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"
|
|
56
|
+
/>
|
|
57
|
+
</svg>
|
|
58
|
+
<p className="text-lg">{error || 'Video cannot be played'}</p>
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const VidstackProvider = forwardRef<VideoPlayerRef, VidstackProviderProps>(
|
|
64
|
+
(
|
|
65
|
+
{
|
|
66
|
+
source,
|
|
67
|
+
aspectRatio = 16 / 9,
|
|
68
|
+
autoPlay = false,
|
|
69
|
+
muted = false,
|
|
70
|
+
loop = false,
|
|
71
|
+
playsInline = true,
|
|
72
|
+
controls = true,
|
|
73
|
+
className,
|
|
74
|
+
showInfo = false,
|
|
75
|
+
theme = 'default',
|
|
76
|
+
errorFallback,
|
|
77
|
+
onPlay,
|
|
78
|
+
onPause,
|
|
79
|
+
onEnded,
|
|
80
|
+
onError,
|
|
81
|
+
onLoadStart,
|
|
82
|
+
onCanPlay,
|
|
83
|
+
onTimeUpdate,
|
|
84
|
+
},
|
|
85
|
+
ref
|
|
86
|
+
) => {
|
|
87
|
+
const playerRef = useRef<MediaPlayerInstance | null>(null);
|
|
88
|
+
const [hasError, setHasError] = useState(false);
|
|
89
|
+
const [errorMessage, setErrorMessage] = useState<string>('Video cannot be played');
|
|
90
|
+
const lastSavedTimeRef = useRef<number>(0);
|
|
91
|
+
const hasRestoredPositionRef = useRef(false);
|
|
92
|
+
|
|
93
|
+
// Cache hooks
|
|
94
|
+
const {
|
|
95
|
+
getPosterUrl,
|
|
96
|
+
cachePosterUrl,
|
|
97
|
+
saveVideoPosition,
|
|
98
|
+
getVideoPosition,
|
|
99
|
+
} = useVideoCache();
|
|
100
|
+
|
|
101
|
+
// Get source key for position caching
|
|
102
|
+
const sourceKey = useMemo(() => {
|
|
103
|
+
switch (source.type) {
|
|
104
|
+
case 'youtube':
|
|
105
|
+
return `youtube:${source.id}`;
|
|
106
|
+
case 'vimeo':
|
|
107
|
+
return `vimeo:${source.id}`;
|
|
108
|
+
case 'hls':
|
|
109
|
+
case 'dash':
|
|
110
|
+
case 'url':
|
|
111
|
+
return `url:${source.url}`;
|
|
112
|
+
default:
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
}, [source]);
|
|
116
|
+
|
|
117
|
+
// Generate poster if not provided, with caching
|
|
118
|
+
const posterUrl = useMemo(() => {
|
|
119
|
+
if (source.poster) return source.poster;
|
|
120
|
+
if (!source.title) return undefined;
|
|
121
|
+
|
|
122
|
+
// Check cache first
|
|
123
|
+
const cached = getPosterUrl(source.title);
|
|
124
|
+
if (cached) return cached;
|
|
125
|
+
|
|
126
|
+
// Generate and cache
|
|
127
|
+
const url = generateOgImageUrl({ title: source.title });
|
|
128
|
+
cachePosterUrl(source.title, url);
|
|
129
|
+
return url;
|
|
130
|
+
}, [source.poster, source.title, getPosterUrl, cachePosterUrl]);
|
|
131
|
+
|
|
132
|
+
// Get Vidstack-compatible source URL
|
|
133
|
+
const vidstackSrc = useMemo(() => getVidstackSrc(source), [source]);
|
|
134
|
+
|
|
135
|
+
// Retry function
|
|
136
|
+
const retry = useCallback(() => {
|
|
137
|
+
setHasError(false);
|
|
138
|
+
setErrorMessage('Video cannot be played');
|
|
139
|
+
// Force reload by updating key would be needed, but for now just reset state
|
|
140
|
+
const player = playerRef.current;
|
|
141
|
+
if (player) {
|
|
142
|
+
player.currentTime = 0;
|
|
143
|
+
player.play();
|
|
144
|
+
}
|
|
145
|
+
}, []);
|
|
146
|
+
|
|
147
|
+
// Expose player methods via ref
|
|
148
|
+
useImperativeHandle(
|
|
149
|
+
ref,
|
|
150
|
+
() => {
|
|
151
|
+
const player = playerRef.current;
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
play: () => player?.play(),
|
|
155
|
+
pause: () => player?.pause(),
|
|
156
|
+
togglePlay: () => {
|
|
157
|
+
if (player) {
|
|
158
|
+
player.paused ? player.play() : player.pause();
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
seekTo: (time: number) => {
|
|
162
|
+
if (player) player.currentTime = time;
|
|
163
|
+
},
|
|
164
|
+
setVolume: (volume: number) => {
|
|
165
|
+
if (player) player.volume = Math.max(0, Math.min(1, volume));
|
|
166
|
+
},
|
|
167
|
+
toggleMute: () => {
|
|
168
|
+
if (player) player.muted = !player.muted;
|
|
169
|
+
},
|
|
170
|
+
enterFullscreen: () => player?.enterFullscreen(),
|
|
171
|
+
exitFullscreen: () => player?.exitFullscreen(),
|
|
172
|
+
get currentTime() {
|
|
173
|
+
return player?.currentTime ?? 0;
|
|
174
|
+
},
|
|
175
|
+
get duration() {
|
|
176
|
+
return player?.duration ?? 0;
|
|
177
|
+
},
|
|
178
|
+
get paused() {
|
|
179
|
+
return player?.paused ?? true;
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
},
|
|
183
|
+
[]
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
const handlePlay = () => onPlay?.();
|
|
187
|
+
|
|
188
|
+
const handlePause = useCallback(() => {
|
|
189
|
+
// Save position on pause
|
|
190
|
+
const player = playerRef.current;
|
|
191
|
+
if (sourceKey && player && player.currentTime > 0) {
|
|
192
|
+
saveVideoPosition(sourceKey, player.currentTime);
|
|
193
|
+
lastSavedTimeRef.current = player.currentTime;
|
|
194
|
+
}
|
|
195
|
+
onPause?.();
|
|
196
|
+
}, [sourceKey, saveVideoPosition, onPause]);
|
|
197
|
+
|
|
198
|
+
const handleEnded = () => onEnded?.();
|
|
199
|
+
|
|
200
|
+
const handleError = (detail: unknown) => {
|
|
201
|
+
const error = detail as { message?: string };
|
|
202
|
+
const msg = error?.message || 'Video playback error';
|
|
203
|
+
setHasError(true);
|
|
204
|
+
setErrorMessage(msg);
|
|
205
|
+
onError?.(msg);
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const handleLoadStart = () => onLoadStart?.();
|
|
209
|
+
|
|
210
|
+
const handleCanPlay = useCallback(() => {
|
|
211
|
+
setHasError(false);
|
|
212
|
+
|
|
213
|
+
// Restore position from cache (only once per source)
|
|
214
|
+
if (sourceKey && playerRef.current && !hasRestoredPositionRef.current) {
|
|
215
|
+
const cachedPosition = getVideoPosition(sourceKey);
|
|
216
|
+
if (cachedPosition && cachedPosition > 0) {
|
|
217
|
+
const duration = playerRef.current.duration;
|
|
218
|
+
// Only restore if position is valid (not at the end)
|
|
219
|
+
if (cachedPosition < duration - 1) {
|
|
220
|
+
playerRef.current.currentTime = cachedPosition;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
hasRestoredPositionRef.current = true;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
onCanPlay?.();
|
|
227
|
+
}, [sourceKey, getVideoPosition, onCanPlay]);
|
|
228
|
+
|
|
229
|
+
const handleTimeUpdate = useCallback(() => {
|
|
230
|
+
const player = playerRef.current;
|
|
231
|
+
if (!player) return;
|
|
232
|
+
|
|
233
|
+
// Save position every 5 seconds
|
|
234
|
+
if (sourceKey && player.currentTime > 0) {
|
|
235
|
+
const timeSinceLastSave = player.currentTime - lastSavedTimeRef.current;
|
|
236
|
+
if (timeSinceLastSave >= 5 || timeSinceLastSave < 0) {
|
|
237
|
+
saveVideoPosition(sourceKey, player.currentTime);
|
|
238
|
+
lastSavedTimeRef.current = player.currentTime;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
onTimeUpdate?.(player.currentTime, player.duration);
|
|
243
|
+
}, [sourceKey, saveVideoPosition, onTimeUpdate]);
|
|
244
|
+
|
|
245
|
+
// Reset position restoration flag when source changes
|
|
246
|
+
useEffect(() => {
|
|
247
|
+
hasRestoredPositionRef.current = false;
|
|
248
|
+
lastSavedTimeRef.current = 0;
|
|
249
|
+
}, [sourceKey]);
|
|
250
|
+
|
|
251
|
+
// Determine layout mode
|
|
252
|
+
const isFillMode = aspectRatio === 'fill';
|
|
253
|
+
const computedAspectRatio = aspectRatio === 'auto' || aspectRatio === 'fill' ? undefined : aspectRatio;
|
|
254
|
+
|
|
255
|
+
// Render error fallback
|
|
256
|
+
const renderErrorFallback = () => {
|
|
257
|
+
const fallbackProps: ErrorFallbackProps = { error: errorMessage, retry };
|
|
258
|
+
|
|
259
|
+
if (typeof errorFallback === 'function') {
|
|
260
|
+
return errorFallback(fallbackProps);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (errorFallback) {
|
|
264
|
+
return errorFallback;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return <DefaultErrorFallback {...fallbackProps} />;
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
// Container styles based on mode
|
|
271
|
+
const containerStyles = isFillMode
|
|
272
|
+
? { width: '100%', height: '100%' }
|
|
273
|
+
: { aspectRatio: computedAspectRatio };
|
|
274
|
+
|
|
275
|
+
return (
|
|
276
|
+
<div className={cn(isFillMode ? 'w-full h-full' : 'w-full', className)}>
|
|
277
|
+
<div
|
|
278
|
+
className={cn(
|
|
279
|
+
'relative w-full rounded-sm bg-black overflow-hidden',
|
|
280
|
+
isFillMode && 'h-full',
|
|
281
|
+
theme === 'minimal' && 'rounded-none',
|
|
282
|
+
theme === 'modern' && 'rounded-xl shadow-2xl'
|
|
283
|
+
)}
|
|
284
|
+
style={containerStyles}
|
|
285
|
+
>
|
|
286
|
+
{hasError ? (
|
|
287
|
+
renderErrorFallback()
|
|
288
|
+
) : (
|
|
289
|
+
<MediaPlayer
|
|
290
|
+
ref={playerRef}
|
|
291
|
+
title={source.title || 'Video'}
|
|
292
|
+
src={vidstackSrc}
|
|
293
|
+
autoPlay={autoPlay}
|
|
294
|
+
muted={muted}
|
|
295
|
+
loop={loop}
|
|
296
|
+
playsInline={playsInline}
|
|
297
|
+
onPlay={handlePlay}
|
|
298
|
+
onPause={handlePause}
|
|
299
|
+
onEnded={handleEnded}
|
|
300
|
+
onError={handleError}
|
|
301
|
+
onLoadStart={handleLoadStart}
|
|
302
|
+
onCanPlay={handleCanPlay}
|
|
303
|
+
onTimeUpdate={handleTimeUpdate}
|
|
304
|
+
className="w-full h-full"
|
|
305
|
+
>
|
|
306
|
+
<MediaProvider />
|
|
307
|
+
|
|
308
|
+
{posterUrl && (
|
|
309
|
+
<Poster
|
|
310
|
+
className="vds-poster"
|
|
311
|
+
src={posterUrl}
|
|
312
|
+
alt={source.title || 'Video poster'}
|
|
313
|
+
style={{ objectFit: 'cover' }}
|
|
314
|
+
/>
|
|
315
|
+
)}
|
|
316
|
+
|
|
317
|
+
{controls && <DefaultVideoLayout icons={defaultLayoutIcons} thumbnails={posterUrl} />}
|
|
318
|
+
</MediaPlayer>
|
|
319
|
+
)}
|
|
320
|
+
</div>
|
|
321
|
+
|
|
322
|
+
{showInfo && source.title && (
|
|
323
|
+
<div className="mt-4 space-y-2">
|
|
324
|
+
<h3 className="text-xl font-semibold text-foreground">{source.title}</h3>
|
|
325
|
+
</div>
|
|
326
|
+
)}
|
|
327
|
+
</div>
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
VidstackProvider.displayName = 'VidstackProvider';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VideoPlayer types - Public API
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Source types
|
|
6
|
+
export type {
|
|
7
|
+
UrlSource,
|
|
8
|
+
YouTubeSource,
|
|
9
|
+
VimeoSource,
|
|
10
|
+
HLSSource,
|
|
11
|
+
DASHSource,
|
|
12
|
+
StreamSource,
|
|
13
|
+
BlobSource,
|
|
14
|
+
DataUrlSource,
|
|
15
|
+
VideoSourceUnion,
|
|
16
|
+
} from './sources';
|
|
17
|
+
|
|
18
|
+
// Player types
|
|
19
|
+
export type {
|
|
20
|
+
PlayerMode,
|
|
21
|
+
AspectRatioValue,
|
|
22
|
+
CommonPlayerSettings,
|
|
23
|
+
CommonPlayerEvents,
|
|
24
|
+
ErrorFallbackProps,
|
|
25
|
+
VideoPlayerProps,
|
|
26
|
+
VideoPlayerRef,
|
|
27
|
+
} from './player';
|
|
28
|
+
|
|
29
|
+
// Provider types
|
|
30
|
+
export type {
|
|
31
|
+
VidstackProviderProps,
|
|
32
|
+
NativeProviderProps,
|
|
33
|
+
StreamProviderProps,
|
|
34
|
+
ResolveFileSourceOptions,
|
|
35
|
+
VideoPlayerContextValue,
|
|
36
|
+
VideoPlayerProviderProps,
|
|
37
|
+
SimpleStreamSource,
|
|
38
|
+
} from './provider';
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Player configuration types
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type React from 'react';
|
|
6
|
+
import type { VideoSourceUnion } from './sources';
|
|
7
|
+
|
|
8
|
+
// =============================================================================
|
|
9
|
+
// Player Mode
|
|
10
|
+
// =============================================================================
|
|
11
|
+
|
|
12
|
+
/** Player mode - determines which provider to use */
|
|
13
|
+
export type PlayerMode =
|
|
14
|
+
| 'auto' // Auto-select based on source type
|
|
15
|
+
| 'vidstack' // Force Vidstack (full-featured)
|
|
16
|
+
| 'native' // Force native HTML5 <video>
|
|
17
|
+
| 'streaming'; // Force streaming provider
|
|
18
|
+
|
|
19
|
+
// =============================================================================
|
|
20
|
+
// Player Props
|
|
21
|
+
// =============================================================================
|
|
22
|
+
|
|
23
|
+
/** Aspect ratio options */
|
|
24
|
+
export type AspectRatioValue = number | 'auto' | 'fill';
|
|
25
|
+
|
|
26
|
+
/** Common player settings */
|
|
27
|
+
export interface CommonPlayerSettings {
|
|
28
|
+
/** Auto-play video */
|
|
29
|
+
autoPlay?: boolean;
|
|
30
|
+
/** Mute video by default */
|
|
31
|
+
muted?: boolean;
|
|
32
|
+
/** Loop video */
|
|
33
|
+
loop?: boolean;
|
|
34
|
+
/** Play video inline on mobile */
|
|
35
|
+
playsInline?: boolean;
|
|
36
|
+
/** Show player controls */
|
|
37
|
+
controls?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Aspect ratio:
|
|
40
|
+
* - number (e.g. 16/9): Fixed aspect ratio
|
|
41
|
+
* - 'auto': Natural video aspect ratio
|
|
42
|
+
* - 'fill': Fill parent container (100% width & height)
|
|
43
|
+
*/
|
|
44
|
+
aspectRatio?: AspectRatioValue;
|
|
45
|
+
/** Preload strategy */
|
|
46
|
+
preload?: 'auto' | 'metadata' | 'none';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Common player events */
|
|
50
|
+
export interface CommonPlayerEvents {
|
|
51
|
+
onPlay?: () => void;
|
|
52
|
+
onPause?: () => void;
|
|
53
|
+
onEnded?: () => void;
|
|
54
|
+
onError?: (error: string) => void;
|
|
55
|
+
onLoadStart?: () => void;
|
|
56
|
+
onCanPlay?: () => void;
|
|
57
|
+
onTimeUpdate?: (currentTime: number, duration: number) => void;
|
|
58
|
+
/** Called when buffering progress changes (buffered seconds, total duration) */
|
|
59
|
+
onBufferProgress?: (buffered: number, duration: number) => void;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Error fallback render props */
|
|
63
|
+
export interface ErrorFallbackProps {
|
|
64
|
+
error: string;
|
|
65
|
+
retry?: () => void;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Main VideoPlayer props */
|
|
69
|
+
export interface VideoPlayerProps extends CommonPlayerSettings, CommonPlayerEvents {
|
|
70
|
+
/** Video source configuration */
|
|
71
|
+
source: VideoSourceUnion;
|
|
72
|
+
/** Player mode (default: 'auto') */
|
|
73
|
+
mode?: PlayerMode;
|
|
74
|
+
/** Player theme (Vidstack only) */
|
|
75
|
+
theme?: 'default' | 'minimal' | 'modern';
|
|
76
|
+
/** Show video info below player */
|
|
77
|
+
showInfo?: boolean;
|
|
78
|
+
/** Container className */
|
|
79
|
+
className?: string;
|
|
80
|
+
/** Video element className (native/streaming only) */
|
|
81
|
+
videoClassName?: string;
|
|
82
|
+
/** Disable right-click context menu */
|
|
83
|
+
disableContextMenu?: boolean;
|
|
84
|
+
/** Show loading spinner */
|
|
85
|
+
showPreloader?: boolean;
|
|
86
|
+
/** Preloader timeout in ms */
|
|
87
|
+
preloaderTimeout?: number;
|
|
88
|
+
/** Custom error fallback UI */
|
|
89
|
+
errorFallback?: React.ReactNode | ((props: ErrorFallbackProps) => React.ReactNode);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** VideoPlayer ref methods */
|
|
93
|
+
export interface VideoPlayerRef {
|
|
94
|
+
/** Play video */
|
|
95
|
+
play: () => Promise<void> | void;
|
|
96
|
+
/** Pause video */
|
|
97
|
+
pause: () => void;
|
|
98
|
+
/** Toggle play/pause */
|
|
99
|
+
togglePlay: () => void;
|
|
100
|
+
/** Seek to time in seconds */
|
|
101
|
+
seekTo: (time: number) => void;
|
|
102
|
+
/** Set volume (0-1) */
|
|
103
|
+
setVolume: (volume: number) => void;
|
|
104
|
+
/** Toggle mute */
|
|
105
|
+
toggleMute: () => void;
|
|
106
|
+
/** Enter fullscreen */
|
|
107
|
+
enterFullscreen: () => void;
|
|
108
|
+
/** Exit fullscreen */
|
|
109
|
+
exitFullscreen: () => void;
|
|
110
|
+
/** Current playback time in seconds */
|
|
111
|
+
readonly currentTime: number;
|
|
112
|
+
/** Video duration in seconds */
|
|
113
|
+
readonly duration: number;
|
|
114
|
+
/** Whether video is paused */
|
|
115
|
+
readonly paused: boolean;
|
|
116
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider-specific types
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type React from 'react';
|
|
6
|
+
import type { VideoSourceUnion, UrlSource, YouTubeSource, VimeoSource, HLSSource, DASHSource, StreamSource, BlobSource, DataUrlSource } from './sources';
|
|
7
|
+
import type { CommonPlayerSettings, CommonPlayerEvents, ErrorFallbackProps } from './player';
|
|
8
|
+
|
|
9
|
+
// =============================================================================
|
|
10
|
+
// Provider Props
|
|
11
|
+
// =============================================================================
|
|
12
|
+
|
|
13
|
+
/** Props passed to Vidstack provider */
|
|
14
|
+
export interface VidstackProviderProps extends CommonPlayerSettings, CommonPlayerEvents {
|
|
15
|
+
source: UrlSource | YouTubeSource | VimeoSource | HLSSource | DASHSource;
|
|
16
|
+
theme?: 'default' | 'minimal' | 'modern';
|
|
17
|
+
showInfo?: boolean;
|
|
18
|
+
className?: string;
|
|
19
|
+
errorFallback?: React.ReactNode | ((props: ErrorFallbackProps) => React.ReactNode);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Props passed to Native provider */
|
|
23
|
+
export interface NativeProviderProps extends CommonPlayerSettings, CommonPlayerEvents {
|
|
24
|
+
source: UrlSource | DataUrlSource;
|
|
25
|
+
className?: string;
|
|
26
|
+
videoClassName?: string;
|
|
27
|
+
disableContextMenu?: boolean;
|
|
28
|
+
showPreloader?: boolean;
|
|
29
|
+
preloaderTimeout?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Props passed to Stream provider */
|
|
33
|
+
export interface StreamProviderProps extends CommonPlayerSettings, CommonPlayerEvents {
|
|
34
|
+
source: StreamSource | BlobSource | DataUrlSource;
|
|
35
|
+
className?: string;
|
|
36
|
+
videoClassName?: string;
|
|
37
|
+
disableContextMenu?: boolean;
|
|
38
|
+
showPreloader?: boolean;
|
|
39
|
+
preloaderTimeout?: number;
|
|
40
|
+
errorFallback?: React.ReactNode | ((props: ErrorFallbackProps) => React.ReactNode);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// =============================================================================
|
|
44
|
+
// File Source Helper Types
|
|
45
|
+
// =============================================================================
|
|
46
|
+
|
|
47
|
+
/** Options for resolving file source */
|
|
48
|
+
export interface ResolveFileSourceOptions {
|
|
49
|
+
/** File content - can be data URL string or binary ArrayBuffer */
|
|
50
|
+
content: string | ArrayBuffer | null | undefined;
|
|
51
|
+
/** File path for streaming */
|
|
52
|
+
path: string;
|
|
53
|
+
/** MIME type of the file */
|
|
54
|
+
mimeType?: string;
|
|
55
|
+
/** Session ID for authenticated streaming */
|
|
56
|
+
sessionId?: string | null;
|
|
57
|
+
/** Load method hint - 'http_stream' enables streaming mode */
|
|
58
|
+
loadMethod?: 'http_stream' | 'rpc' | 'unspecified' | 'skip' | string;
|
|
59
|
+
/** Function to generate stream URL (required for streaming) */
|
|
60
|
+
getStreamUrl?: (sessionId: string, path: string) => string;
|
|
61
|
+
/** Optional title */
|
|
62
|
+
title?: string;
|
|
63
|
+
/** Optional poster */
|
|
64
|
+
poster?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// =============================================================================
|
|
68
|
+
// Context Types
|
|
69
|
+
// =============================================================================
|
|
70
|
+
|
|
71
|
+
export interface VideoPlayerContextValue {
|
|
72
|
+
/** Function to generate stream URL (for HTTP Range streaming) */
|
|
73
|
+
getStreamUrl?: (sessionId: string, path: string) => string;
|
|
74
|
+
/** Current session ID */
|
|
75
|
+
sessionId?: string | null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface VideoPlayerProviderProps extends VideoPlayerContextValue {
|
|
79
|
+
children: React.ReactNode;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Simplified stream source (uses context for getStreamUrl) */
|
|
83
|
+
export interface SimpleStreamSource {
|
|
84
|
+
type: 'stream';
|
|
85
|
+
/** File path on server */
|
|
86
|
+
path: string;
|
|
87
|
+
/** Session ID (optional, uses context if not provided) */
|
|
88
|
+
sessionId?: string;
|
|
89
|
+
/** MIME type for the video */
|
|
90
|
+
mimeType?: string;
|
|
91
|
+
title?: string;
|
|
92
|
+
poster?: string;
|
|
93
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Video source type definitions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// =============================================================================
|
|
6
|
+
// Source Types - Different ways to provide video content
|
|
7
|
+
// =============================================================================
|
|
8
|
+
|
|
9
|
+
/** Simple URL source (mp4, webm, etc.) */
|
|
10
|
+
export interface UrlSource {
|
|
11
|
+
type: 'url';
|
|
12
|
+
url: string;
|
|
13
|
+
title?: string;
|
|
14
|
+
poster?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** YouTube embed source */
|
|
18
|
+
export interface YouTubeSource {
|
|
19
|
+
type: 'youtube';
|
|
20
|
+
/** YouTube video ID (11 characters) */
|
|
21
|
+
id: string;
|
|
22
|
+
title?: string;
|
|
23
|
+
poster?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Vimeo embed source */
|
|
27
|
+
export interface VimeoSource {
|
|
28
|
+
type: 'vimeo';
|
|
29
|
+
/** Vimeo video ID */
|
|
30
|
+
id: string;
|
|
31
|
+
title?: string;
|
|
32
|
+
poster?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** HLS streaming source */
|
|
36
|
+
export interface HLSSource {
|
|
37
|
+
type: 'hls';
|
|
38
|
+
/** URL to .m3u8 manifest */
|
|
39
|
+
url: string;
|
|
40
|
+
title?: string;
|
|
41
|
+
poster?: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** DASH streaming source */
|
|
45
|
+
export interface DASHSource {
|
|
46
|
+
type: 'dash';
|
|
47
|
+
/** URL to .mpd manifest */
|
|
48
|
+
url: string;
|
|
49
|
+
title?: string;
|
|
50
|
+
poster?: string;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** HTTP Range streaming source (for large files with auth) */
|
|
54
|
+
export interface StreamSource {
|
|
55
|
+
type: 'stream';
|
|
56
|
+
/** Session ID for authorization */
|
|
57
|
+
sessionId: string;
|
|
58
|
+
/** File path on server */
|
|
59
|
+
path: string;
|
|
60
|
+
/** Function to generate stream URL */
|
|
61
|
+
getStreamUrl: (sessionId: string, path: string) => string;
|
|
62
|
+
/** MIME type for the video */
|
|
63
|
+
mimeType?: string;
|
|
64
|
+
title?: string;
|
|
65
|
+
poster?: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Binary data source (ArrayBuffer) */
|
|
69
|
+
export interface BlobSource {
|
|
70
|
+
type: 'blob';
|
|
71
|
+
/** Video data as ArrayBuffer */
|
|
72
|
+
data: ArrayBuffer;
|
|
73
|
+
/** MIME type (default: video/mp4) */
|
|
74
|
+
mimeType?: string;
|
|
75
|
+
title?: string;
|
|
76
|
+
poster?: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Base64 data URL source */
|
|
80
|
+
export interface DataUrlSource {
|
|
81
|
+
type: 'data-url';
|
|
82
|
+
/** Base64 encoded data URL */
|
|
83
|
+
data: string;
|
|
84
|
+
title?: string;
|
|
85
|
+
poster?: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Union of all source types */
|
|
89
|
+
export type VideoSourceUnion =
|
|
90
|
+
| UrlSource
|
|
91
|
+
| YouTubeSource
|
|
92
|
+
| VimeoSource
|
|
93
|
+
| HLSSource
|
|
94
|
+
| DASHSource
|
|
95
|
+
| StreamSource
|
|
96
|
+
| BlobSource
|
|
97
|
+
| DataUrlSource;
|