@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,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ImageViewer utilities - Public API
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export { createLQIP } from './lqip';
|
|
6
|
+
export {
|
|
7
|
+
MAX_IMAGE_SIZE,
|
|
8
|
+
WARNING_IMAGE_SIZE,
|
|
9
|
+
PROGRESSIVE_LOADING_THRESHOLD,
|
|
10
|
+
LQIP_SIZE,
|
|
11
|
+
LQIP_QUALITY,
|
|
12
|
+
MIN_ZOOM,
|
|
13
|
+
MAX_ZOOM,
|
|
14
|
+
ZOOM_PRESETS,
|
|
15
|
+
DEFAULT_TRANSFORM,
|
|
16
|
+
} from './constants';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LQIP (Low-Quality Image Placeholder) generator
|
|
3
|
+
*
|
|
4
|
+
* Creates a tiny blurred preview image for progressive loading.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { LQIP_SIZE, LQIP_QUALITY } from './constants';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Create a low-quality image placeholder from source URL
|
|
11
|
+
*
|
|
12
|
+
* @param imageSrc - Full quality image URL
|
|
13
|
+
* @returns Data URL of tiny preview, or null on error
|
|
14
|
+
*/
|
|
15
|
+
export async function createLQIP(imageSrc: string): Promise<string | null> {
|
|
16
|
+
try {
|
|
17
|
+
// Load the full image
|
|
18
|
+
const img = new Image();
|
|
19
|
+
img.crossOrigin = 'anonymous';
|
|
20
|
+
|
|
21
|
+
await new Promise<void>((resolve, reject) => {
|
|
22
|
+
img.onload = () => resolve();
|
|
23
|
+
img.onerror = () => reject(new Error('Failed to load image for LQIP'));
|
|
24
|
+
img.src = imageSrc;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Calculate aspect ratio preserving dimensions
|
|
28
|
+
const aspect = img.naturalWidth / img.naturalHeight;
|
|
29
|
+
const width = aspect >= 1 ? LQIP_SIZE : Math.round(LQIP_SIZE * aspect);
|
|
30
|
+
const height = aspect >= 1 ? Math.round(LQIP_SIZE / aspect) : LQIP_SIZE;
|
|
31
|
+
|
|
32
|
+
// Create canvas for downscaling
|
|
33
|
+
const canvas = document.createElement('canvas');
|
|
34
|
+
canvas.width = width;
|
|
35
|
+
canvas.height = height;
|
|
36
|
+
const ctx = canvas.getContext('2d');
|
|
37
|
+
if (!ctx) return null;
|
|
38
|
+
|
|
39
|
+
// Draw scaled down image
|
|
40
|
+
ctx.drawImage(img, 0, 0, width, height);
|
|
41
|
+
|
|
42
|
+
// Return as data URL (very small, ~1-2KB)
|
|
43
|
+
return canvas.toDataURL('image/jpeg', LQIP_QUALITY);
|
|
44
|
+
} catch {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# VideoPlayer Refactoring Plan
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The VideoPlayer is already reasonably well-organized with a `providers/` subfolder. This refactoring focuses on incremental improvements rather than major restructuring.
|
|
6
|
+
|
|
7
|
+
**Total: 2,024 lines across 10 files**
|
|
8
|
+
|
|
9
|
+
## Current Structure (Before)
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
VideoPlayer/
|
|
13
|
+
├── index.ts (68 lines) # Public exports
|
|
14
|
+
├── types.ts (369 lines) # All types + helper functions ⚠️
|
|
15
|
+
├── VideoPlayer.tsx (202 lines) # Main orchestrator
|
|
16
|
+
├── VideoPlayerContext.tsx (125 lines) # Streaming context
|
|
17
|
+
├── VideoControls.tsx (139 lines) # Vidstack controls
|
|
18
|
+
├── VideoErrorFallback.tsx (174 lines) # Error UI
|
|
19
|
+
├── README.md
|
|
20
|
+
└── providers/
|
|
21
|
+
├── index.ts (8 lines)
|
|
22
|
+
├── VidstackProvider.tsx (332 lines) # YouTube/Vimeo/HLS/DASH
|
|
23
|
+
├── NativeProvider.tsx (206 lines) # HTML5 <video>
|
|
24
|
+
└── StreamProvider.tsx (401 lines) # HTTP Range + Blob ⚠️
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**Issues Identified:**
|
|
28
|
+
1. `types.ts` (369 lines) - Contains types AND helper functions
|
|
29
|
+
2. `StreamProvider.tsx` (401 lines) - Largest file, multiple concerns
|
|
30
|
+
3. Position caching logic duplicated in VidstackProvider & StreamProvider
|
|
31
|
+
4. No dedicated hooks/ folder
|
|
32
|
+
|
|
33
|
+
## Target Structure (After)
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
VideoPlayer/
|
|
37
|
+
├── index.ts # Public API
|
|
38
|
+
├── README.md
|
|
39
|
+
├── types/
|
|
40
|
+
│ ├── index.ts # Re-exports all types
|
|
41
|
+
│ ├── sources.ts # Source type definitions
|
|
42
|
+
│ ├── player.ts # Player props and config types
|
|
43
|
+
│ └── provider.ts # Provider-specific types
|
|
44
|
+
├── hooks/
|
|
45
|
+
│ ├── index.ts
|
|
46
|
+
│ └── useVideoPositionCache.ts # Extracted caching logic
|
|
47
|
+
├── utils/
|
|
48
|
+
│ ├── index.ts
|
|
49
|
+
│ ├── resolvers.ts # resolvePlayerMode, resolveFileSource
|
|
50
|
+
│ └── stream.ts # Stream URL generation helpers
|
|
51
|
+
├── components/
|
|
52
|
+
│ ├── index.ts
|
|
53
|
+
│ ├── VideoPlayer.tsx # Main component
|
|
54
|
+
│ ├── VideoControls.tsx # Vidstack controls
|
|
55
|
+
│ └── VideoErrorFallback.tsx # Error UI
|
|
56
|
+
├── context/
|
|
57
|
+
│ ├── index.ts
|
|
58
|
+
│ └── VideoPlayerContext.tsx
|
|
59
|
+
└── providers/
|
|
60
|
+
├── index.ts
|
|
61
|
+
├── VidstackProvider.tsx
|
|
62
|
+
├── NativeProvider.tsx
|
|
63
|
+
└── StreamProvider.tsx
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Benefits
|
|
67
|
+
|
|
68
|
+
1. **DRY Principle** - Extract duplicated position caching logic
|
|
69
|
+
2. **Separation of Concerns** - Types split by domain
|
|
70
|
+
3. **Consistent Structure** - Matches AudioPlayer/ImageViewer patterns
|
|
71
|
+
4. **Maintainability** - Easier to find and modify specific functionality
|
|
72
|
+
5. **Testability** - Hooks and utils can be unit tested
|
|
73
|
+
|
|
74
|
+
## Execution Phases
|
|
75
|
+
|
|
76
|
+
| Phase | Description | Files |
|
|
77
|
+
|-------|-------------|-------|
|
|
78
|
+
| 1 | Create folder structure | types/, hooks/, utils/, components/, context/ |
|
|
79
|
+
| 2 | Split types | sources.ts, player.ts, provider.ts |
|
|
80
|
+
| 3 | Extract utils | resolvers.ts, stream.ts |
|
|
81
|
+
| 4 | Extract hooks | useVideoPositionCache.ts |
|
|
82
|
+
| 5 | Move components | VideoPlayer.tsx, VideoControls.tsx, VideoErrorFallback.tsx |
|
|
83
|
+
| 6 | Move context | VideoPlayerContext.tsx |
|
|
84
|
+
| 7 | Update exports | index.ts |
|
|
85
|
+
| 8 | Cleanup and verify | Delete old files, run pnpm check |
|
|
86
|
+
|
|
87
|
+
## Risk Assessment
|
|
88
|
+
|
|
89
|
+
- **Low Risk**: Incremental changes, no logic modifications
|
|
90
|
+
- **Testing**: Run `pnpm check` after each phase
|
|
91
|
+
- **Providers**: Already well-organized, minimal changes needed
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
# Phase 1: Types Split
|
|
2
|
+
|
|
3
|
+
## Goal
|
|
4
|
+
|
|
5
|
+
Split the 369-line `types.ts` into domain-specific files and move helper functions to utils.
|
|
6
|
+
|
|
7
|
+
## Current Structure
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
// types.ts (369 lines)
|
|
11
|
+
// Contains:
|
|
12
|
+
// 1. Source types (UrlSource, YouTubeSource, VimeoSource, HLSSource, etc.)
|
|
13
|
+
// 2. Player types (PlayerMode, AspectRatioValue, VideoPlayerProps, etc.)
|
|
14
|
+
// 3. Provider types (VidstackProviderProps, NativeProviderProps, etc.)
|
|
15
|
+
// 4. Helper functions (resolvePlayerMode, resolveFileSource, isSimpleStreamSource)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Target Files
|
|
19
|
+
|
|
20
|
+
### types/sources.ts (~120 lines)
|
|
21
|
+
|
|
22
|
+
All source type definitions:
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
/**
|
|
26
|
+
* Video source type definitions
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
// URL source (direct video URL)
|
|
30
|
+
export interface UrlSource {
|
|
31
|
+
type: 'url';
|
|
32
|
+
url: string;
|
|
33
|
+
mimeType?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// YouTube embed
|
|
37
|
+
export interface YouTubeSource {
|
|
38
|
+
type: 'youtube';
|
|
39
|
+
videoId: string;
|
|
40
|
+
startTime?: number;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Vimeo embed
|
|
44
|
+
export interface VimeoSource {
|
|
45
|
+
type: 'vimeo';
|
|
46
|
+
videoId: string;
|
|
47
|
+
startTime?: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// HLS streaming
|
|
51
|
+
export interface HLSSource {
|
|
52
|
+
type: 'hls';
|
|
53
|
+
url: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// DASH streaming
|
|
57
|
+
export interface DASHSource {
|
|
58
|
+
type: 'dash';
|
|
59
|
+
url: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// HTTP Range streaming with auth
|
|
63
|
+
export interface StreamSource {
|
|
64
|
+
type: 'stream';
|
|
65
|
+
streamKey: string;
|
|
66
|
+
fileName: string;
|
|
67
|
+
fileSize?: number;
|
|
68
|
+
mimeType?: string;
|
|
69
|
+
getStreamUrl: (streamKey: string) => Promise<string>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Simple stream (resolved via context)
|
|
73
|
+
export interface SimpleStreamSource {
|
|
74
|
+
type: 'stream';
|
|
75
|
+
streamKey: string;
|
|
76
|
+
fileName: string;
|
|
77
|
+
fileSize?: number;
|
|
78
|
+
mimeType?: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Blob (ArrayBuffer)
|
|
82
|
+
export interface BlobSource {
|
|
83
|
+
type: 'blob';
|
|
84
|
+
data: ArrayBuffer;
|
|
85
|
+
mimeType?: string;
|
|
86
|
+
fileName?: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Data URL (base64)
|
|
90
|
+
export interface DataUrlSource {
|
|
91
|
+
type: 'data-url';
|
|
92
|
+
dataUrl: string;
|
|
93
|
+
mimeType?: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Union of all sources
|
|
97
|
+
export type VideoSourceUnion =
|
|
98
|
+
| UrlSource
|
|
99
|
+
| YouTubeSource
|
|
100
|
+
| VimeoSource
|
|
101
|
+
| HLSSource
|
|
102
|
+
| DASHSource
|
|
103
|
+
| StreamSource
|
|
104
|
+
| BlobSource
|
|
105
|
+
| DataUrlSource;
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### types/player.ts (~100 lines)
|
|
109
|
+
|
|
110
|
+
Player configuration and main component types:
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
/**
|
|
114
|
+
* Player configuration types
|
|
115
|
+
*/
|
|
116
|
+
|
|
117
|
+
import type { ReactNode, CSSProperties } from 'react';
|
|
118
|
+
import type { VideoSourceUnion } from './sources';
|
|
119
|
+
|
|
120
|
+
// Player mode
|
|
121
|
+
export type PlayerMode = 'auto' | 'vidstack' | 'native' | 'streaming';
|
|
122
|
+
|
|
123
|
+
// Aspect ratio
|
|
124
|
+
export type AspectRatioValue = number | 'auto' | 'fill';
|
|
125
|
+
|
|
126
|
+
// Common settings
|
|
127
|
+
export interface CommonPlayerSettings {
|
|
128
|
+
autoPlay?: boolean;
|
|
129
|
+
muted?: boolean;
|
|
130
|
+
loop?: boolean;
|
|
131
|
+
playsInline?: boolean;
|
|
132
|
+
controls?: boolean;
|
|
133
|
+
preload?: 'none' | 'metadata' | 'auto';
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Common events
|
|
137
|
+
export interface CommonPlayerEvents {
|
|
138
|
+
onPlay?: () => void;
|
|
139
|
+
onPause?: () => void;
|
|
140
|
+
onEnded?: () => void;
|
|
141
|
+
onTimeUpdate?: (currentTime: number) => void;
|
|
142
|
+
onError?: (error: Error) => void;
|
|
143
|
+
onLoadStart?: () => void;
|
|
144
|
+
onCanPlay?: () => void;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Error fallback props
|
|
148
|
+
export interface ErrorFallbackProps {
|
|
149
|
+
error: Error | null;
|
|
150
|
+
source: VideoSourceUnion;
|
|
151
|
+
retry?: () => void;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Main component props
|
|
155
|
+
export interface VideoPlayerProps extends CommonPlayerSettings, CommonPlayerEvents {
|
|
156
|
+
source: VideoSourceUnion;
|
|
157
|
+
mode?: PlayerMode;
|
|
158
|
+
aspectRatio?: AspectRatioValue;
|
|
159
|
+
poster?: string;
|
|
160
|
+
className?: string;
|
|
161
|
+
style?: CSSProperties;
|
|
162
|
+
errorFallback?: (props: ErrorFallbackProps) => ReactNode;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Ref API
|
|
166
|
+
export interface VideoPlayerRef {
|
|
167
|
+
play: () => Promise<void>;
|
|
168
|
+
pause: () => void;
|
|
169
|
+
seek: (time: number) => void;
|
|
170
|
+
setVolume: (volume: number) => void;
|
|
171
|
+
setMuted: (muted: boolean) => void;
|
|
172
|
+
requestFullscreen: () => Promise<void>;
|
|
173
|
+
exitFullscreen: () => Promise<void>;
|
|
174
|
+
readonly currentTime: number;
|
|
175
|
+
readonly duration: number;
|
|
176
|
+
readonly paused: boolean;
|
|
177
|
+
readonly muted: boolean;
|
|
178
|
+
readonly volume: number;
|
|
179
|
+
readonly isFullscreen: boolean;
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### types/provider.ts (~80 lines)
|
|
184
|
+
|
|
185
|
+
Provider-specific types:
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
/**
|
|
189
|
+
* Provider-specific types
|
|
190
|
+
*/
|
|
191
|
+
|
|
192
|
+
import type { ReactNode } from 'react';
|
|
193
|
+
import type { VideoSourceUnion, StreamSource, BlobSource, DataUrlSource } from './sources';
|
|
194
|
+
import type { CommonPlayerSettings, CommonPlayerEvents, AspectRatioValue, ErrorFallbackProps } from './player';
|
|
195
|
+
|
|
196
|
+
// Vidstack provider props
|
|
197
|
+
export interface VidstackProviderProps extends CommonPlayerSettings, CommonPlayerEvents {
|
|
198
|
+
source: VideoSourceUnion;
|
|
199
|
+
aspectRatio?: AspectRatioValue;
|
|
200
|
+
poster?: string;
|
|
201
|
+
className?: string;
|
|
202
|
+
errorFallback?: (props: ErrorFallbackProps) => ReactNode;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Native provider props
|
|
206
|
+
export interface NativeProviderProps extends CommonPlayerSettings, CommonPlayerEvents {
|
|
207
|
+
source: VideoSourceUnion;
|
|
208
|
+
aspectRatio?: AspectRatioValue;
|
|
209
|
+
poster?: string;
|
|
210
|
+
className?: string;
|
|
211
|
+
disableContextMenu?: boolean;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Stream provider props
|
|
215
|
+
export interface StreamProviderProps extends CommonPlayerSettings, CommonPlayerEvents {
|
|
216
|
+
source: StreamSource | BlobSource | DataUrlSource;
|
|
217
|
+
aspectRatio?: AspectRatioValue;
|
|
218
|
+
poster?: string;
|
|
219
|
+
className?: string;
|
|
220
|
+
errorFallback?: (props: ErrorFallbackProps) => ReactNode;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// File source resolution options
|
|
224
|
+
export interface ResolveFileSourceOptions {
|
|
225
|
+
fileName: string;
|
|
226
|
+
content: string | ArrayBuffer;
|
|
227
|
+
mimeType?: string;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Context value
|
|
231
|
+
export interface VideoPlayerContextValue {
|
|
232
|
+
getStreamUrl?: (streamKey: string) => Promise<string>;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export interface VideoPlayerProviderProps {
|
|
236
|
+
getStreamUrl: (streamKey: string) => Promise<string>;
|
|
237
|
+
children: ReactNode;
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### types/index.ts
|
|
242
|
+
|
|
243
|
+
Re-export all types:
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
/**
|
|
247
|
+
* VideoPlayer types - Public API
|
|
248
|
+
*/
|
|
249
|
+
|
|
250
|
+
// Source types
|
|
251
|
+
export type {
|
|
252
|
+
UrlSource,
|
|
253
|
+
YouTubeSource,
|
|
254
|
+
VimeoSource,
|
|
255
|
+
HLSSource,
|
|
256
|
+
DASHSource,
|
|
257
|
+
StreamSource,
|
|
258
|
+
SimpleStreamSource,
|
|
259
|
+
BlobSource,
|
|
260
|
+
DataUrlSource,
|
|
261
|
+
VideoSourceUnion,
|
|
262
|
+
} from './sources';
|
|
263
|
+
|
|
264
|
+
// Player types
|
|
265
|
+
export type {
|
|
266
|
+
PlayerMode,
|
|
267
|
+
AspectRatioValue,
|
|
268
|
+
CommonPlayerSettings,
|
|
269
|
+
CommonPlayerEvents,
|
|
270
|
+
ErrorFallbackProps,
|
|
271
|
+
VideoPlayerProps,
|
|
272
|
+
VideoPlayerRef,
|
|
273
|
+
} from './player';
|
|
274
|
+
|
|
275
|
+
// Provider types
|
|
276
|
+
export type {
|
|
277
|
+
VidstackProviderProps,
|
|
278
|
+
NativeProviderProps,
|
|
279
|
+
StreamProviderProps,
|
|
280
|
+
ResolveFileSourceOptions,
|
|
281
|
+
VideoPlayerContextValue,
|
|
282
|
+
VideoPlayerProviderProps,
|
|
283
|
+
} from './provider';
|
|
284
|
+
```
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# Phase 2: Utils Extraction
|
|
2
|
+
|
|
3
|
+
## Goal
|
|
4
|
+
|
|
5
|
+
Extract helper functions from types.ts into dedicated utils files.
|
|
6
|
+
|
|
7
|
+
## Files to Create
|
|
8
|
+
|
|
9
|
+
### utils/resolvers.ts
|
|
10
|
+
|
|
11
|
+
Player mode and source resolution:
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
/**
|
|
15
|
+
* Video source and player mode resolvers
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import type { VideoSourceUnion, PlayerMode, SimpleStreamSource, StreamSource } from '../types';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Determine the appropriate player mode for a given source
|
|
22
|
+
*/
|
|
23
|
+
export function resolvePlayerMode(source: VideoSourceUnion): PlayerMode {
|
|
24
|
+
switch (source.type) {
|
|
25
|
+
case 'youtube':
|
|
26
|
+
case 'vimeo':
|
|
27
|
+
case 'hls':
|
|
28
|
+
case 'dash':
|
|
29
|
+
return 'vidstack';
|
|
30
|
+
case 'stream':
|
|
31
|
+
case 'blob':
|
|
32
|
+
case 'data-url':
|
|
33
|
+
return 'streaming';
|
|
34
|
+
case 'url':
|
|
35
|
+
default:
|
|
36
|
+
return 'native';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Check if source is a simple stream (needs context resolution)
|
|
42
|
+
*/
|
|
43
|
+
export function isSimpleStreamSource(
|
|
44
|
+
source: VideoSourceUnion
|
|
45
|
+
): source is SimpleStreamSource {
|
|
46
|
+
return (
|
|
47
|
+
source.type === 'stream' &&
|
|
48
|
+
!('getStreamUrl' in source)
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Resolve simple stream source with context getStreamUrl
|
|
54
|
+
*/
|
|
55
|
+
export function resolveStreamSource(
|
|
56
|
+
source: SimpleStreamSource,
|
|
57
|
+
getStreamUrl: (streamKey: string) => Promise<string>
|
|
58
|
+
): StreamSource {
|
|
59
|
+
return {
|
|
60
|
+
...source,
|
|
61
|
+
getStreamUrl,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### utils/fileSource.ts
|
|
67
|
+
|
|
68
|
+
File content to source conversion:
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
/**
|
|
72
|
+
* File source resolution utilities
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
import type { VideoSourceUnion, ResolveFileSourceOptions } from '../types';
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Convert file content to appropriate VideoSource
|
|
79
|
+
*/
|
|
80
|
+
export function resolveFileSource(options: ResolveFileSourceOptions): VideoSourceUnion {
|
|
81
|
+
const { fileName, content, mimeType } = options;
|
|
82
|
+
|
|
83
|
+
// Data URL string
|
|
84
|
+
if (typeof content === 'string' && content.startsWith('data:')) {
|
|
85
|
+
return {
|
|
86
|
+
type: 'data-url',
|
|
87
|
+
dataUrl: content,
|
|
88
|
+
mimeType,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Regular URL string
|
|
93
|
+
if (typeof content === 'string') {
|
|
94
|
+
return {
|
|
95
|
+
type: 'url',
|
|
96
|
+
url: content,
|
|
97
|
+
mimeType,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// ArrayBuffer -> Blob source
|
|
102
|
+
return {
|
|
103
|
+
type: 'blob',
|
|
104
|
+
data: content,
|
|
105
|
+
mimeType: mimeType || guessMimeType(fileName),
|
|
106
|
+
fileName,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Guess MIME type from file extension
|
|
112
|
+
*/
|
|
113
|
+
function guessMimeType(fileName: string): string {
|
|
114
|
+
const ext = fileName.split('.').pop()?.toLowerCase();
|
|
115
|
+
const mimeTypes: Record<string, string> = {
|
|
116
|
+
mp4: 'video/mp4',
|
|
117
|
+
webm: 'video/webm',
|
|
118
|
+
ogg: 'video/ogg',
|
|
119
|
+
mov: 'video/quicktime',
|
|
120
|
+
avi: 'video/x-msvideo',
|
|
121
|
+
mkv: 'video/x-matroska',
|
|
122
|
+
};
|
|
123
|
+
return mimeTypes[ext || ''] || 'video/mp4';
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### utils/index.ts
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
/**
|
|
131
|
+
* VideoPlayer utilities - Public API
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
export {
|
|
135
|
+
resolvePlayerMode,
|
|
136
|
+
isSimpleStreamSource,
|
|
137
|
+
resolveStreamSource,
|
|
138
|
+
} from './resolvers';
|
|
139
|
+
|
|
140
|
+
export { resolveFileSource } from './fileSource';
|
|
141
|
+
```
|