mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-23 17:57:38 +00:00
refactor(webui): extract shared Video/Image control bars and reuse in compare
Extract the video player's inline ControlBar into an exported viewers/video-control-bar.tsx (VideoControlBar + PlayerState + DisplayTranscode) and the image toolbar from file-viewer into an exported viewers/image-control-bar.tsx (ImageControlBar). video-player and file-viewer now consume the shared components with unchanged behavior. compare-control-bar composes the same two shared bars (video vs image active) with fan-out handlers, so the compare control bar can no longer drift from the single-file players (e.g. the time-format dropdown).
This commit is contained in:
@@ -1,38 +1,17 @@
|
||||
import { ImageControlBar } from '@/ui/components/viewers/image-control-bar'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/ui/components/ui/dropdown-menu'
|
||||
import { Slider } from '@/ui/components/ui/slider'
|
||||
import { cn } from '@/ui/lib/utils'
|
||||
import ProgressBar from '@/ui/components/viewers/progress-bar'
|
||||
import { formatTime, formatTimecode } from '@/ui/components/viewers/utils'
|
||||
import { useUiStore } from '@/ui/stores/ui'
|
||||
import type { MediaMetadata } from '@shumai/dtos'
|
||||
import {
|
||||
Download,
|
||||
Maximize,
|
||||
Minimize,
|
||||
Minus,
|
||||
Pause,
|
||||
Play,
|
||||
Plus,
|
||||
Repeat,
|
||||
Settings,
|
||||
Volume2,
|
||||
VolumeX,
|
||||
} from 'lucide-react'
|
||||
VideoControlBar,
|
||||
type DisplayTranscode,
|
||||
type PlayerState,
|
||||
} from '@/ui/components/viewers/video-control-bar'
|
||||
import type { AssetInfo } from '@shumai/dtos'
|
||||
import { Maximize, Minimize } from 'lucide-react'
|
||||
import type { PaneReportedState } from './types'
|
||||
|
||||
const PLAYBACK_RATES = [0.5, 1, 1.5, 2]
|
||||
|
||||
interface CompareControlBarProps {
|
||||
activeState: PaneReportedState | null
|
||||
activeAsset: AssetInfo | null
|
||||
previewUrl?: string
|
||||
metadata?: MediaMetadata
|
||||
startTimecode?: string | null
|
||||
isFullScreen: boolean
|
||||
onTogglePlay: () => void
|
||||
onToggleLoop: () => void
|
||||
@@ -50,9 +29,8 @@ interface CompareControlBarProps {
|
||||
|
||||
export function CompareControlBar({
|
||||
activeState,
|
||||
activeAsset,
|
||||
previewUrl,
|
||||
metadata,
|
||||
startTimecode,
|
||||
isFullScreen,
|
||||
onTogglePlay,
|
||||
onToggleLoop,
|
||||
@@ -67,230 +45,83 @@ export function CompareControlBar({
|
||||
onDownload,
|
||||
onToggleFullScreen,
|
||||
}: CompareControlBarProps) {
|
||||
const { videoTimeDisplayMode, setVideoTimeDisplayMode } = useUiStore()
|
||||
// Active side is a video: reuse the shared VideoControlBar.
|
||||
if (activeState?.kind === 'video' && activeState.video && activeAsset) {
|
||||
const v = activeState.video
|
||||
const duration = v.totalFrames / v.frameRate
|
||||
const currentTime = v.currentFrame / v.frameRate
|
||||
const state: PlayerState = {
|
||||
isPlaying: v.isPlaying,
|
||||
progress: duration > 0 ? (currentTime / duration) * 100 : 0,
|
||||
currentTime,
|
||||
duration,
|
||||
volume: v.volume,
|
||||
isMuted: v.isMuted,
|
||||
isLooping: v.isLooping,
|
||||
playbackRate: v.playbackRate,
|
||||
isFullScreen,
|
||||
showFrames: false,
|
||||
currentResolution: v.currentResolution,
|
||||
}
|
||||
|
||||
const fullscreenButton = (
|
||||
<button
|
||||
onClick={onToggleFullScreen}
|
||||
className="text-foreground transition-colors hover:text-primary"
|
||||
title="Fullscreen"
|
||||
>
|
||||
{isFullScreen ? <Minimize className="h-5 w-5" /> : <Maximize className="h-5 w-5" />}
|
||||
</button>
|
||||
)
|
||||
// The active-side asset carries the metadata used for timecode display and
|
||||
// preview scrubbing; ensure the preview url is present for the shared bar.
|
||||
const data =
|
||||
previewUrl && !activeAsset.media?.videoPreview
|
||||
? { ...activeAsset, media: { ...activeAsset.media, videoPreview: { url: previewUrl } } }
|
||||
: activeAsset
|
||||
|
||||
const zoomControls = (
|
||||
<div className="mr-auto flex items-center gap-1 rounded-md bg-muted/60 p-0.5">
|
||||
<button
|
||||
onClick={onZoomOut}
|
||||
className="rounded p-1.5 text-foreground transition-colors hover:bg-muted"
|
||||
title="Zoom Out"
|
||||
>
|
||||
<Minus size={16} />
|
||||
</button>
|
||||
<span className="w-12 text-center font-mono text-xs font-medium text-foreground select-none">
|
||||
{Math.round((activeState?.zoom ?? 1) * 100)}%
|
||||
</span>
|
||||
<button
|
||||
onClick={onZoomIn}
|
||||
className="rounded p-1.5 text-foreground transition-colors hover:bg-muted"
|
||||
title="Zoom In"
|
||||
>
|
||||
<Plus size={16} />
|
||||
</button>
|
||||
<button
|
||||
onClick={onFit}
|
||||
className="rounded px-2 py-1 text-xs font-medium text-foreground transition-colors hover:bg-muted"
|
||||
>
|
||||
Fit
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
|
||||
// Image (or unsupported) control bar
|
||||
if (!activeState || activeState.kind !== 'video' || !activeState.video) {
|
||||
return (
|
||||
<div className="relative z-10 flex items-center justify-end gap-2 border-t border-border bg-card px-4 py-3">
|
||||
{activeState?.kind === 'image' && zoomControls}
|
||||
{activeState?.kind === 'image' && (
|
||||
<button
|
||||
onClick={() => onDownload()}
|
||||
className="flex items-center gap-1.5 rounded bg-muted/60 px-3 py-1.5 text-xs font-medium text-foreground transition-colors hover:bg-muted"
|
||||
title="Download"
|
||||
>
|
||||
<Download size={14} />
|
||||
Download
|
||||
</button>
|
||||
)}
|
||||
{fullscreenButton}
|
||||
</div>
|
||||
<VideoControlBar
|
||||
state={state}
|
||||
zoom={activeState.zoom}
|
||||
isControlsVisible
|
||||
buffered={v.buffered}
|
||||
data={data}
|
||||
resolutions={v.resolutions as DisplayTranscode[]}
|
||||
togglePlay={onTogglePlay}
|
||||
toggleLoop={onToggleLoop}
|
||||
toggleMute={onToggleMute}
|
||||
handleVolumeChange={onVolumeChange}
|
||||
changePlaybackRate={onChangePlaybackRate}
|
||||
changeResolution={(res) => onChangeResolution(res.resolution)}
|
||||
handleDownload={(key) => onDownload(key)}
|
||||
toggleFullScreen={onToggleFullScreen}
|
||||
onZoomChange={(nz) => (nz >= activeState.zoom ? onZoomIn() : onZoomOut())}
|
||||
onZoomReset={onFit}
|
||||
frameRate={v.frameRate}
|
||||
totalFrames={v.totalFrames}
|
||||
currentFrame={v.currentFrame}
|
||||
seekToFrame={onSeek}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const video = activeState.video
|
||||
const displayTotalFrames = Math.max(0, video.totalFrames - 1)
|
||||
const displayString =
|
||||
videoTimeDisplayMode === 'frames'
|
||||
? `${video.currentFrame} / ${displayTotalFrames} fr`
|
||||
: videoTimeDisplayMode === 'standard'
|
||||
? `${formatTimecode(video.currentFrame, video.frameRate, 'standard')} / ${formatTime(video.totalFrames / video.frameRate)}`
|
||||
: `${formatTimecode(video.currentFrame, video.frameRate, videoTimeDisplayMode, startTimecode)} / ${formatTimecode(displayTotalFrames, video.frameRate, videoTimeDisplayMode, startTimecode)}`
|
||||
|
||||
const cycleTimeDisplay = () => {
|
||||
const modes: Array<'standard' | 'timecode' | 'frames'> = ['standard', 'timecode', 'frames']
|
||||
const idx = modes.indexOf(videoTimeDisplayMode as 'standard' | 'timecode' | 'frames')
|
||||
setVideoTimeDisplayMode(modes[(idx + 1) % modes.length])
|
||||
// Active side is an image: reuse the shared ImageControlBar.
|
||||
if (activeState?.kind === 'image') {
|
||||
return (
|
||||
<ImageControlBar
|
||||
zoom={activeState.zoom}
|
||||
onZoomIn={onZoomIn}
|
||||
onZoomOut={onZoomOut}
|
||||
onFit={onFit}
|
||||
onDownload={() => onDownload()}
|
||||
canDownload={!!activeAsset?.media?.original?.key}
|
||||
fullscreen={{ isFullScreen, onToggle: onToggleFullScreen }}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const previewResolutions = video.resolutions.filter((r) => !r.isRaw)
|
||||
|
||||
// Unsupported / not yet loaded: only expose fullscreen.
|
||||
return (
|
||||
<div className="relative z-10 flex flex-col gap-2 border-t border-border bg-card px-4 py-2">
|
||||
<ProgressBar
|
||||
totalFrames={video.totalFrames}
|
||||
currentFrame={video.currentFrame}
|
||||
fps={video.frameRate}
|
||||
previewUrl={previewUrl}
|
||||
onSeek={onSeek}
|
||||
buffered={video.buffered}
|
||||
metadata={metadata}
|
||||
/>
|
||||
<div className="flex items-center gap-3">
|
||||
<button
|
||||
onClick={onTogglePlay}
|
||||
className="text-foreground transition-colors hover:text-primary"
|
||||
title={video.isPlaying ? 'Pause' : 'Play'}
|
||||
>
|
||||
{video.isPlaying ? (
|
||||
<Pause className="h-6 w-6 fill-current" />
|
||||
) : (
|
||||
<Play className="h-6 w-6 fill-current" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={onToggleLoop}
|
||||
className={cn(
|
||||
'transition-colors hover:text-primary',
|
||||
video.isLooping ? 'text-primary' : 'text-foreground',
|
||||
)}
|
||||
title="Loop"
|
||||
>
|
||||
<Repeat className="h-5 w-5" />
|
||||
</button>
|
||||
|
||||
{/* Volume */}
|
||||
<div className="flex items-center gap-1.5">
|
||||
<button
|
||||
onClick={onToggleMute}
|
||||
className="text-foreground transition-colors hover:text-primary"
|
||||
title={video.isMuted ? 'Unmute' : 'Mute'}
|
||||
>
|
||||
{video.isMuted || video.volume === 0 ? (
|
||||
<VolumeX className="h-5 w-5" />
|
||||
) : (
|
||||
<Volume2 className="h-5 w-5" />
|
||||
)}
|
||||
</button>
|
||||
<Slider
|
||||
value={[video.isMuted ? 0 : video.volume]}
|
||||
max={1}
|
||||
step={0.05}
|
||||
onValueChange={(vals) => onVolumeChange(vals[0] ?? 0)}
|
||||
className="w-20"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button
|
||||
onClick={cycleTimeDisplay}
|
||||
className="font-mono text-xs font-medium text-foreground tabular-nums"
|
||||
title="Toggle time display"
|
||||
>
|
||||
{displayString}
|
||||
</button>
|
||||
|
||||
<div className="ml-auto flex items-center gap-3">
|
||||
{zoomControls}
|
||||
|
||||
{/* Playback rate */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger className="rounded border border-border px-2 py-0.5 text-sm font-semibold text-foreground transition-colors hover:bg-muted">
|
||||
{video.playbackRate}x
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="flex flex-col">
|
||||
{PLAYBACK_RATES.map((rate) => (
|
||||
<DropdownMenuItem
|
||||
key={rate}
|
||||
onClick={() => onChangePlaybackRate(rate)}
|
||||
className={cn(
|
||||
'px-2 py-1 text-xs',
|
||||
video.playbackRate === rate
|
||||
? 'bg-primary text-primary-foreground'
|
||||
: 'text-foreground',
|
||||
)}
|
||||
>
|
||||
{rate}x
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
{/* Resolution */}
|
||||
{previewResolutions.length > 0 && (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger className="flex items-center gap-1 rounded border border-border px-2 py-0.5 text-sm font-semibold text-foreground transition-colors hover:bg-muted">
|
||||
<Settings className="h-3.5 w-3.5" />
|
||||
<span>{video.currentResolution}</span>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuLabel>Quality</DropdownMenuLabel>
|
||||
{previewResolutions.map((res) => (
|
||||
<DropdownMenuItem
|
||||
key={res.resolution}
|
||||
onClick={() => onChangeResolution(res.resolution)}
|
||||
className={cn(
|
||||
'flex w-full items-center justify-between',
|
||||
video.currentResolution === res.resolution
|
||||
? 'font-medium text-primary'
|
||||
: 'text-foreground',
|
||||
)}
|
||||
>
|
||||
<span>{res.resolution}</span>
|
||||
<span className="pl-5 text-xs text-muted-foreground">
|
||||
{res.width}x{res.height}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)}
|
||||
|
||||
{/* Download */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger
|
||||
className="text-foreground transition-colors hover:text-primary"
|
||||
title="Download"
|
||||
>
|
||||
<Download className="h-5 w-5" />
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuLabel>Download</DropdownMenuLabel>
|
||||
{video.resolutions.map((res) => (
|
||||
<DropdownMenuItem
|
||||
key={res.resolution}
|
||||
onClick={() => onDownload(res.key)}
|
||||
className="flex w-full items-center justify-between px-3 py-2 text-sm text-foreground"
|
||||
>
|
||||
<span>{res.resolution}</span>
|
||||
<span className="text-xs text-muted-foreground">{res.isRaw ? 'RAW' : 'MP4'}</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
{fullscreenButton}
|
||||
</div>
|
||||
</div>
|
||||
<div className="relative z-10 flex items-center justify-end gap-2 border-t border-border bg-card px-4 py-3">
|
||||
<button
|
||||
onClick={onToggleFullScreen}
|
||||
className="text-foreground transition-colors hover:text-primary"
|
||||
title="Fullscreen"
|
||||
>
|
||||
{isFullScreen ? <Minimize className="h-5 w-5" /> : <Maximize className="h-5 w-5" />}
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -334,9 +334,8 @@ export function CompareViewer({
|
||||
|
||||
<CompareControlBar
|
||||
activeState={activeState}
|
||||
activeAsset={activeAsset ?? null}
|
||||
previewUrl={activePreviewUrl}
|
||||
metadata={activeAsset?.media?.metadata}
|
||||
startTimecode={activeAsset?.media?.metadata?.startTimecode}
|
||||
isFullScreen={isFullScreen}
|
||||
onTogglePlay={handleTogglePlay}
|
||||
onToggleLoop={handleToggleLoop}
|
||||
|
||||
@@ -2,12 +2,13 @@ import { useScreenSize } from '@/ui/hooks/useScreenSize'
|
||||
import { client } from '@/ui/api/client'
|
||||
import { getBestTranscode } from '@/ui/lib/media'
|
||||
import type { AssetInfo } from '@shumai/dtos'
|
||||
import { Check, Copy, Download, Minus, Plus } from 'lucide-react'
|
||||
import { Download } from 'lucide-react'
|
||||
import type { ReactNode, RefObject } from 'react'
|
||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import type Player from 'video.js/dist/types/player'
|
||||
import DrawingCanvas from './drawing-canvas'
|
||||
import VideoPlayer from './viewers/video-player'
|
||||
import { ImageControlBar } from './viewers/image-control-bar'
|
||||
|
||||
import { useAnnotationStore } from '@/ui/stores/annotation-store'
|
||||
import type { Annotation } from '@/ui/types'
|
||||
@@ -271,51 +272,17 @@ export function FileViewer({
|
||||
</div>
|
||||
</div>
|
||||
{/* Zoom Toolbar */}
|
||||
<div className="relative px-4 py-3 bg-card border-t border-gray-200 dark:border-gray-700 z-10 flex items-center justify-end gap-2 transition-colors duration-200">
|
||||
<div className="flex items-center gap-1 bg-gray-200/50 dark:bg-white/10 rounded-md p-0.5 mr-auto">
|
||||
<button
|
||||
onClick={() => handleZoom(0.8)}
|
||||
className="p-1.5 rounded hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors"
|
||||
title="Zoom Out"
|
||||
>
|
||||
<Minus size={16} />
|
||||
</button>
|
||||
<span className="w-12 text-center text-xs font-mono font-medium text-gray-900 dark:text-gray-100 select-none">
|
||||
{Math.round(zoom * 100)}%
|
||||
</span>
|
||||
<button
|
||||
onClick={() => handleZoom(1.2)}
|
||||
className="p-1.5 rounded hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors"
|
||||
title="Zoom In"
|
||||
>
|
||||
<Plus size={16} />
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
onClick={handleFit}
|
||||
className="text-xs font-medium px-3 py-1.5 rounded bg-gray-200/50 dark:bg-white/10 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors border border-transparent animate-in fade-in zoom-in-95 duration-200"
|
||||
>
|
||||
Fit
|
||||
</button>
|
||||
<button
|
||||
onClick={handleCopy}
|
||||
disabled={!bestUrl}
|
||||
className="flex items-center gap-1.5 text-xs font-medium px-3 py-1.5 rounded bg-gray-200/50 dark:bg-white/10 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors border border-transparent disabled:opacity-50 animate-in fade-in zoom-in-95 duration-200"
|
||||
title="Copy optimized image to clipboard"
|
||||
>
|
||||
{copied ? <Check size={14} className="text-green-500" /> : <Copy size={14} />}
|
||||
{copied ? 'Copied' : 'Copy'}
|
||||
</button>
|
||||
<button
|
||||
onClick={handleDownload}
|
||||
disabled={!file.media?.original?.key}
|
||||
className="flex items-center gap-1.5 text-xs font-medium px-3 py-1.5 rounded bg-gray-200/50 dark:bg-white/10 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors border border-transparent disabled:opacity-50 animate-in fade-in zoom-in-95 duration-200"
|
||||
title="Download original image"
|
||||
>
|
||||
<Download size={14} />
|
||||
Download
|
||||
</button>
|
||||
</div>
|
||||
<ImageControlBar
|
||||
zoom={zoom}
|
||||
onZoomIn={() => handleZoom(1.2)}
|
||||
onZoomOut={() => handleZoom(0.8)}
|
||||
onFit={handleFit}
|
||||
onDownload={handleDownload}
|
||||
canDownload={!!file.media?.original?.key}
|
||||
onCopy={handleCopy}
|
||||
copied={copied}
|
||||
canCopy={!!bestUrl}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
{isVideo && (
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
import { Check, Copy, Download, Maximize, Minimize, Minus, Plus } from 'lucide-react'
|
||||
|
||||
export interface ImageControlBarProps {
|
||||
zoom: number
|
||||
onZoomIn: () => void
|
||||
onZoomOut: () => void
|
||||
onFit: () => void
|
||||
onDownload: () => void
|
||||
canDownload: boolean
|
||||
onCopy?: () => void
|
||||
copied?: boolean
|
||||
canCopy?: boolean
|
||||
/** When provided, renders a fullscreen toggle (used by compare mode). */
|
||||
fullscreen?: { isFullScreen: boolean; onToggle: () => void }
|
||||
}
|
||||
|
||||
export function ImageControlBar({
|
||||
zoom,
|
||||
onZoomIn,
|
||||
onZoomOut,
|
||||
onFit,
|
||||
onDownload,
|
||||
canDownload,
|
||||
onCopy,
|
||||
copied = false,
|
||||
canCopy = true,
|
||||
fullscreen,
|
||||
}: ImageControlBarProps) {
|
||||
return (
|
||||
<div className="relative px-4 py-3 bg-card border-t border-gray-200 dark:border-gray-700 z-10 flex items-center justify-end gap-2 transition-colors duration-200">
|
||||
<div className="flex items-center gap-1 bg-gray-200/50 dark:bg-white/10 rounded-md p-0.5 mr-auto">
|
||||
<button
|
||||
onClick={onZoomOut}
|
||||
className="p-1.5 rounded hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors"
|
||||
title="Zoom Out"
|
||||
>
|
||||
<Minus size={16} />
|
||||
</button>
|
||||
<span className="w-12 text-center text-xs font-mono font-medium text-gray-900 dark:text-gray-100 select-none">
|
||||
{Math.round(zoom * 100)}%
|
||||
</span>
|
||||
<button
|
||||
onClick={onZoomIn}
|
||||
className="p-1.5 rounded hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors"
|
||||
title="Zoom In"
|
||||
>
|
||||
<Plus size={16} />
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
onClick={onFit}
|
||||
className="text-xs font-medium px-3 py-1.5 rounded bg-gray-200/50 dark:bg-white/10 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors border border-transparent animate-in fade-in zoom-in-95 duration-200"
|
||||
>
|
||||
Fit
|
||||
</button>
|
||||
{onCopy && (
|
||||
<button
|
||||
onClick={onCopy}
|
||||
disabled={!canCopy}
|
||||
className="flex items-center gap-1.5 text-xs font-medium px-3 py-1.5 rounded bg-gray-200/50 dark:bg-white/10 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors border border-transparent disabled:opacity-50 animate-in fade-in zoom-in-95 duration-200"
|
||||
title="Copy optimized image to clipboard"
|
||||
>
|
||||
{copied ? <Check size={14} className="text-green-500" /> : <Copy size={14} />}
|
||||
{copied ? 'Copied' : 'Copy'}
|
||||
</button>
|
||||
)}
|
||||
<button
|
||||
onClick={onDownload}
|
||||
disabled={!canDownload}
|
||||
className="flex items-center gap-1.5 text-xs font-medium px-3 py-1.5 rounded bg-gray-200/50 dark:bg-white/10 hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors border border-transparent disabled:opacity-50 animate-in fade-in zoom-in-95 duration-200"
|
||||
title="Download original image"
|
||||
>
|
||||
<Download size={14} />
|
||||
Download
|
||||
</button>
|
||||
{fullscreen && (
|
||||
<button
|
||||
onClick={fullscreen.onToggle}
|
||||
className="p-1.5 rounded hover:bg-gray-300 dark:hover:bg-gray-600 text-gray-700 dark:text-gray-200 transition-colors"
|
||||
title="Fullscreen"
|
||||
>
|
||||
{fullscreen.isFullScreen ? <Minimize size={16} /> : <Maximize size={16} />}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,361 @@
|
||||
import { cn } from '@/ui/lib/utils'
|
||||
import { useUiStore } from '@/ui/stores/ui'
|
||||
import type { AssetInfo, VideoTranscode } from '@shumai/dtos'
|
||||
import {
|
||||
Check,
|
||||
ChevronDown,
|
||||
Download,
|
||||
Maximize,
|
||||
Minimize,
|
||||
Minus,
|
||||
Pause,
|
||||
Play,
|
||||
Plus,
|
||||
Repeat,
|
||||
Settings,
|
||||
Volume2,
|
||||
VolumeX,
|
||||
} from 'lucide-react'
|
||||
import React from 'react'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuTrigger,
|
||||
} from '../ui/dropdown-menu'
|
||||
import { Slider } from '../ui/slider'
|
||||
import ProgressBar from './progress-bar'
|
||||
import { formatTime, formatTimecode } from './utils'
|
||||
|
||||
export interface PlayerState {
|
||||
isPlaying: boolean
|
||||
progress: number // 0 to 100
|
||||
currentTime: number
|
||||
duration: number
|
||||
volume: number
|
||||
isMuted: boolean
|
||||
isLooping: boolean
|
||||
playbackRate: number
|
||||
isFullScreen: boolean
|
||||
showFrames: boolean // Toggle between time (02:30) and frames (1234)
|
||||
currentResolution: string // 'Original' or '720p', '480p' etc.
|
||||
currentSrc?: string
|
||||
}
|
||||
|
||||
export type DisplayTranscode = VideoTranscode & { resolution: string }
|
||||
|
||||
export interface ControlBarProps {
|
||||
state: PlayerState
|
||||
zoom: number
|
||||
isControlsVisible: boolean
|
||||
buffered: number
|
||||
data: AssetInfo
|
||||
resolutions: DisplayTranscode[]
|
||||
togglePlay: () => void
|
||||
toggleLoop: () => void
|
||||
toggleMute: () => void
|
||||
handleVolumeChange: (newVolume: number) => void
|
||||
changePlaybackRate: (rate: number) => void
|
||||
changeResolution: (res: DisplayTranscode) => void
|
||||
handleDownload: (key: string) => void
|
||||
toggleFullScreen: () => void
|
||||
onZoomChange: (zoom: number) => void
|
||||
onZoomReset: () => void
|
||||
// Frame-accurate props
|
||||
frameRate: number
|
||||
totalFrames: number
|
||||
currentFrame: number
|
||||
seekToFrame: (frame: number) => Promise<void> | void
|
||||
}
|
||||
|
||||
export const VideoControlBar: React.FC<ControlBarProps> = ({
|
||||
state,
|
||||
zoom,
|
||||
isControlsVisible,
|
||||
buffered,
|
||||
data,
|
||||
resolutions,
|
||||
togglePlay,
|
||||
toggleLoop,
|
||||
toggleMute,
|
||||
handleVolumeChange,
|
||||
changePlaybackRate,
|
||||
changeResolution,
|
||||
handleDownload,
|
||||
toggleFullScreen,
|
||||
onZoomChange,
|
||||
onZoomReset,
|
||||
frameRate,
|
||||
totalFrames,
|
||||
currentFrame,
|
||||
seekToFrame,
|
||||
}) => {
|
||||
const { videoTimeDisplayMode, setVideoTimeDisplayMode } = useUiStore()
|
||||
|
||||
if (!data.media?.metadata) {
|
||||
return null
|
||||
}
|
||||
|
||||
const previewResolutions = resolutions.filter((r) => !r.isRaw)
|
||||
|
||||
const startTimecode = data.media?.metadata?.startTimecode
|
||||
const displayTotalFrames = Math.max(0, totalFrames - 1)
|
||||
const displayString =
|
||||
videoTimeDisplayMode === 'frames'
|
||||
? `${currentFrame} / ${displayTotalFrames} fr`
|
||||
: videoTimeDisplayMode === 'standard'
|
||||
? `${formatTimecode(currentFrame, frameRate, 'standard')} / ${formatTime(totalFrames / frameRate)}`
|
||||
: `${formatTimecode(currentFrame, frameRate, videoTimeDisplayMode, startTimecode)} / ${formatTimecode(displayTotalFrames, frameRate, videoTimeDisplayMode, startTimecode)}`
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'transition-all duration-300 ease-in-out z-20',
|
||||
state.isFullScreen
|
||||
? 'absolute bottom-0 left-0 right-0 px-4 py-4 bg-black/60 backdrop-blur-md text-white'
|
||||
: 'relative w-full bg-card border-t border-border px-4 py-3 z-10 transition-colors duration-200',
|
||||
isControlsVisible
|
||||
? 'opacity-100 translate-y-0'
|
||||
: 'opacity-0 translate-y-4 pointer-events-none',
|
||||
)}
|
||||
>
|
||||
{/* Progress Bar */}
|
||||
<div className="mb-4 px-1">
|
||||
<ProgressBar
|
||||
totalFrames={totalFrames}
|
||||
currentFrame={currentFrame}
|
||||
fps={frameRate}
|
||||
buffered={buffered}
|
||||
previewUrl={data.media.videoPreview?.url}
|
||||
onSeek={seekToFrame}
|
||||
metadata={{
|
||||
...data.media.metadata,
|
||||
frameRate: frameRate,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Lower Controls Row */}
|
||||
<div
|
||||
className={cn(
|
||||
'flex items-center justify-between',
|
||||
state.isFullScreen ? 'text-white/90' : 'text-foreground',
|
||||
)}
|
||||
>
|
||||
{/* Left Side: Play, Vol, Time */}
|
||||
<div className="flex items-center gap-4">
|
||||
<button
|
||||
onClick={togglePlay}
|
||||
className="hover:text-primary transition-colors"
|
||||
data-testid="play-toggle"
|
||||
data-playing={state.isPlaying}
|
||||
aria-label={state.isPlaying ? 'Pause' : 'Play'}
|
||||
>
|
||||
{state.isPlaying ? (
|
||||
<Pause className="w-6 h-6 fill-current" />
|
||||
) : (
|
||||
<Play className="w-6 h-6 fill-current" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={toggleLoop}
|
||||
className={cn(
|
||||
'transition-colors',
|
||||
state.isLooping ? 'text-primary' : 'text-muted-foreground',
|
||||
)}
|
||||
title="Loop"
|
||||
>
|
||||
<Repeat className="w-5 h-5" />
|
||||
</button>
|
||||
|
||||
<div className="flex items-center gap-3 group/vol">
|
||||
<button onClick={toggleMute} className="hover:text-primary">
|
||||
{state.isMuted || state.volume === 0 ? (
|
||||
<VolumeX className="w-6 h-6" />
|
||||
) : (
|
||||
<Volume2 className="w-6 h-6" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
<div className="w-0 overflow-hidden group-hover/vol:w-24 transition-all duration-300 ease-in-out">
|
||||
<div className="w-24 px-1">
|
||||
<Slider
|
||||
value={state.isMuted ? [0] : [state.volume]}
|
||||
onValueChange={(v) => handleVolumeChange(v[0])}
|
||||
max={1}
|
||||
step={0.05}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-1 text-sm font-medium tabular-nums select-none min-w-[100px]">
|
||||
<span className="text-muted-foreground font-mono" data-testid="time-readout">
|
||||
{displayString}
|
||||
</span>
|
||||
<DropdownMenu modal={false}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button className="h-6 w-6 inline-flex items-center justify-center rounded-md hover:bg-muted text-muted-foreground hover:text-foreground transition-colors cursor-pointer focus:outline-none">
|
||||
<ChevronDown className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start" className="w-40 z-30">
|
||||
<DropdownMenuLabel className="text-[10px] font-bold text-muted-foreground uppercase tracking-wider">
|
||||
Format
|
||||
</DropdownMenuLabel>
|
||||
<DropdownMenuItem
|
||||
onClick={() => setVideoTimeDisplayMode('standard')}
|
||||
className="flex items-center justify-between cursor-pointer text-xs"
|
||||
>
|
||||
<span>Standard Time</span>
|
||||
{videoTimeDisplayMode === 'standard' && (
|
||||
<Check className="h-3.5 w-3.5 text-primary" />
|
||||
)}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={() => setVideoTimeDisplayMode('frames')}
|
||||
className="flex items-center justify-between cursor-pointer text-xs"
|
||||
>
|
||||
<span>Frames</span>
|
||||
{videoTimeDisplayMode === 'frames' && (
|
||||
<Check className="h-3.5 w-3.5 text-primary" />
|
||||
)}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={() => setVideoTimeDisplayMode('timecode')}
|
||||
className="flex items-center justify-between cursor-pointer text-xs"
|
||||
>
|
||||
<span>Timecode</span>
|
||||
{videoTimeDisplayMode === 'timecode' && (
|
||||
<Check className="h-3.5 w-3.5 text-primary" />
|
||||
)}
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right Side: Zoom, Speed, Res, Download, Fullscreen */}
|
||||
<div className="relative flex items-center gap-3">
|
||||
{/* Zoom Controls */}
|
||||
<div className="flex items-center gap-1">
|
||||
<div className="flex items-center gap-1 bg-muted rounded-md p-0.5">
|
||||
<button
|
||||
onClick={() => onZoomChange(zoom * 0.8)}
|
||||
className="p-1 hover:text-primary rounded"
|
||||
>
|
||||
<Minus size={14} />
|
||||
</button>
|
||||
<span className="text-xs w-8 text-center tabular-nums">
|
||||
{Math.round(zoom * 100)}%
|
||||
</span>
|
||||
<button
|
||||
onClick={() => onZoomChange(zoom * 1.2)}
|
||||
className="p-1 hover:text-primary rounded"
|
||||
>
|
||||
<Plus size={14} />
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
onClick={onZoomReset}
|
||||
className="text-xs font-medium px-2 py-1 rounded bg-muted hover:text-primary transition-colors"
|
||||
>
|
||||
Fit
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Playback Rate */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button className="w-8 text-sm font-bold hover:text-primary">
|
||||
{state.playbackRate}x
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
{[0.5, 1, 1.5, 2].map((rate) => (
|
||||
<DropdownMenuItem
|
||||
key={rate}
|
||||
onClick={() => changePlaybackRate(rate)}
|
||||
className={cn(
|
||||
'rounded py-1 px-2 text-left text-xs',
|
||||
state.playbackRate === rate
|
||||
? 'bg-primary text-primary-foreground focus:bg-primary focus:text-primary-foreground'
|
||||
: 'text-foreground',
|
||||
)}
|
||||
>
|
||||
{rate}x
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
{/* Resolution Selector */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button className="flex items-center gap-1 rounded border border-border px-2 py-0.5 text-sm font-semibold hover:bg-muted transition-colors">
|
||||
<Settings className="h-3.5 w-3.5" />
|
||||
<span>{state.currentResolution}</span>
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuLabel>Quality</DropdownMenuLabel>
|
||||
{previewResolutions.map((res) => (
|
||||
<DropdownMenuItem
|
||||
key={res.resolution}
|
||||
onClick={() => changeResolution(res)}
|
||||
className={cn(
|
||||
'flex w-full items-center justify-between',
|
||||
state.currentResolution === res.resolution
|
||||
? 'text-primary font-medium'
|
||||
: 'text-foreground',
|
||||
)}
|
||||
>
|
||||
<span>{res.resolution}</span>
|
||||
<span className="pl-5 text-xs text-muted-foreground">
|
||||
{res.width}x{res.height}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
{/* Download */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button className="transition-colors hover:text-primary" title="Download">
|
||||
<Download className="h-5 w-5" />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuLabel>Download</DropdownMenuLabel>
|
||||
{resolutions.map((res) => (
|
||||
<DropdownMenuItem
|
||||
key={res.resolution}
|
||||
onClick={() => handleDownload(res.key ?? '')}
|
||||
className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground"
|
||||
>
|
||||
<span>{res.resolution}</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{res.isRaw ? data.name?.split('.').pop()?.toUpperCase() || 'RAW' : 'MP4'}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
{/* Fullscreen */}
|
||||
<button onClick={toggleFullScreen} className="transition-colors hover:text-primary">
|
||||
{state.isFullScreen ? (
|
||||
<Minimize className="h-6 w-6" />
|
||||
) : (
|
||||
<Maximize className="h-6 w-6" />
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,56 +1,17 @@
|
||||
import type { AssetInfo, VideoTranscode } from '@shumai/dtos'
|
||||
import type { AssetInfo } from '@shumai/dtos'
|
||||
import { client } from '@/ui/api/client'
|
||||
import { cn } from '@/ui/lib/utils'
|
||||
import {
|
||||
Check,
|
||||
ChevronDown,
|
||||
Download,
|
||||
Maximize,
|
||||
Minimize,
|
||||
Minus,
|
||||
Pause,
|
||||
Play,
|
||||
Plus,
|
||||
Repeat,
|
||||
Settings,
|
||||
Volume2,
|
||||
VolumeX,
|
||||
} from 'lucide-react'
|
||||
import { Play } from 'lucide-react'
|
||||
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import videojs from 'video.js'
|
||||
import type Player from 'video.js/dist/types/player'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuTrigger,
|
||||
} from '../ui/dropdown-menu'
|
||||
import { Slider } from '../ui/slider'
|
||||
import ProgressBar from './progress-bar'
|
||||
import { formatTimecode, formatTime } from './utils'
|
||||
import { useFramePlayer } from './use-frame-player'
|
||||
import { useUiStore } from '@/ui/stores/ui'
|
||||
import { VideoControlBar, type PlayerState, type DisplayTranscode } from './video-control-bar'
|
||||
|
||||
import type { Annotation } from '@/ui/types'
|
||||
import DrawingCanvas from '../drawing-canvas'
|
||||
import { useAnnotationStore } from '@/ui/stores/annotation-store'
|
||||
|
||||
export interface PlayerState {
|
||||
isPlaying: boolean
|
||||
progress: number // 0 to 100
|
||||
currentTime: number
|
||||
duration: number
|
||||
volume: number
|
||||
isMuted: boolean
|
||||
isLooping: boolean
|
||||
playbackRate: number
|
||||
isFullScreen: boolean
|
||||
showFrames: boolean // Toggle between time (02:30) and frames (1234)
|
||||
currentResolution: string // 'Original' or '720p', '480p' etc.
|
||||
currentSrc?: string
|
||||
}
|
||||
|
||||
interface VideoPlayerProps {
|
||||
data: AssetInfo
|
||||
playerRef?: React.RefObject<Player | null>
|
||||
@@ -63,323 +24,6 @@ interface VideoPlayerProps {
|
||||
children?: React.ReactNode
|
||||
}
|
||||
|
||||
type DisplayTranscode = VideoTranscode & { resolution: string }
|
||||
|
||||
interface ControlBarProps {
|
||||
state: PlayerState
|
||||
zoom: number
|
||||
isControlsVisible: boolean
|
||||
buffered: number
|
||||
data: AssetInfo
|
||||
resolutions: DisplayTranscode[]
|
||||
togglePlay: () => void
|
||||
toggleLoop: () => void
|
||||
toggleMute: () => void
|
||||
handleVolumeChange: (newVolume: number) => void
|
||||
changePlaybackRate: (rate: number) => void
|
||||
changeResolution: (res: DisplayTranscode) => void
|
||||
handleDownload: (key: string) => void
|
||||
toggleFullScreen: () => void
|
||||
onZoomChange: (zoom: number) => void
|
||||
onZoomReset: () => void
|
||||
// Frame-accurate props
|
||||
frameRate: number
|
||||
totalFrames: number
|
||||
currentFrame: number
|
||||
seekToFrame: (frame: number) => Promise<void>
|
||||
}
|
||||
|
||||
const ControlBar: React.FC<ControlBarProps> = ({
|
||||
state,
|
||||
zoom,
|
||||
isControlsVisible,
|
||||
buffered,
|
||||
data,
|
||||
resolutions,
|
||||
togglePlay,
|
||||
toggleLoop,
|
||||
toggleMute,
|
||||
handleVolumeChange,
|
||||
changePlaybackRate,
|
||||
changeResolution,
|
||||
handleDownload,
|
||||
toggleFullScreen,
|
||||
onZoomChange,
|
||||
onZoomReset,
|
||||
frameRate,
|
||||
totalFrames,
|
||||
currentFrame,
|
||||
seekToFrame,
|
||||
}) => {
|
||||
if (!data.media?.metadata) {
|
||||
return null
|
||||
}
|
||||
|
||||
const previewResolutions = resolutions.filter((r) => !r.isRaw)
|
||||
|
||||
const { videoTimeDisplayMode, setVideoTimeDisplayMode } = useUiStore()
|
||||
|
||||
const startTimecode = data.media?.metadata?.startTimecode
|
||||
const displayTotalFrames = Math.max(0, totalFrames - 1)
|
||||
const displayString =
|
||||
videoTimeDisplayMode === 'frames'
|
||||
? `${currentFrame} / ${displayTotalFrames} fr`
|
||||
: videoTimeDisplayMode === 'standard'
|
||||
? `${formatTimecode(currentFrame, frameRate, 'standard')} / ${formatTime(totalFrames / frameRate)}`
|
||||
: `${formatTimecode(currentFrame, frameRate, videoTimeDisplayMode, startTimecode)} / ${formatTimecode(displayTotalFrames, frameRate, videoTimeDisplayMode, startTimecode)}`
|
||||
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'transition-all duration-300 ease-in-out z-20',
|
||||
state.isFullScreen
|
||||
? 'absolute bottom-0 left-0 right-0 px-4 py-4 bg-black/60 backdrop-blur-md text-white'
|
||||
: 'relative w-full bg-card border-t border-border px-4 py-3 z-10 transition-colors duration-200',
|
||||
isControlsVisible
|
||||
? 'opacity-100 translate-y-0'
|
||||
: 'opacity-0 translate-y-4 pointer-events-none',
|
||||
)}
|
||||
>
|
||||
{/* Progress Bar */}
|
||||
<div className="mb-4 px-1">
|
||||
<ProgressBar
|
||||
totalFrames={totalFrames}
|
||||
currentFrame={currentFrame}
|
||||
fps={frameRate}
|
||||
buffered={buffered}
|
||||
previewUrl={data.media.videoPreview?.url}
|
||||
onSeek={seekToFrame}
|
||||
metadata={{
|
||||
...data.media.metadata,
|
||||
frameRate: frameRate,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Lower Controls Row */}
|
||||
<div
|
||||
className={cn(
|
||||
'flex items-center justify-between',
|
||||
state.isFullScreen ? 'text-white/90' : 'text-foreground',
|
||||
)}
|
||||
>
|
||||
{/* Left Side: Play, Vol, Time */}
|
||||
<div className="flex items-center gap-4">
|
||||
<button
|
||||
onClick={togglePlay}
|
||||
className="hover:text-primary transition-colors"
|
||||
data-testid="play-toggle"
|
||||
data-playing={state.isPlaying}
|
||||
aria-label={state.isPlaying ? 'Pause' : 'Play'}
|
||||
>
|
||||
{state.isPlaying ? (
|
||||
<Pause className="w-6 h-6 fill-current" />
|
||||
) : (
|
||||
<Play className="w-6 h-6 fill-current" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
<button
|
||||
onClick={toggleLoop}
|
||||
className={cn(
|
||||
'transition-colors',
|
||||
state.isLooping ? 'text-primary' : 'text-muted-foreground',
|
||||
)}
|
||||
title="Loop"
|
||||
>
|
||||
<Repeat className="w-5 h-5" />
|
||||
</button>
|
||||
|
||||
<div className="flex items-center gap-3 group/vol">
|
||||
<button onClick={toggleMute} className="hover:text-primary">
|
||||
{state.isMuted || state.volume === 0 ? (
|
||||
<VolumeX className="w-6 h-6" />
|
||||
) : (
|
||||
<Volume2 className="w-6 h-6" />
|
||||
)}
|
||||
</button>
|
||||
|
||||
<div className="w-0 overflow-hidden group-hover/vol:w-24 transition-all duration-300 ease-in-out">
|
||||
<div className="w-24 px-1">
|
||||
<Slider
|
||||
value={state.isMuted ? [0] : [state.volume]}
|
||||
onValueChange={(v) => handleVolumeChange(v[0])}
|
||||
max={1}
|
||||
step={0.05}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-1 text-sm font-medium tabular-nums select-none min-w-[100px]">
|
||||
<span className="text-muted-foreground font-mono" data-testid="time-readout">
|
||||
{displayString}
|
||||
</span>
|
||||
<DropdownMenu modal={false}>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button className="h-6 w-6 inline-flex items-center justify-center rounded-md hover:bg-muted text-muted-foreground hover:text-foreground transition-colors cursor-pointer focus:outline-none">
|
||||
<ChevronDown className="h-3.5 w-3.5" />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="start" className="w-40 z-30">
|
||||
<DropdownMenuLabel className="text-[10px] font-bold text-muted-foreground uppercase tracking-wider">
|
||||
Format
|
||||
</DropdownMenuLabel>
|
||||
<DropdownMenuItem
|
||||
onClick={() => setVideoTimeDisplayMode('standard')}
|
||||
className="flex items-center justify-between cursor-pointer text-xs"
|
||||
>
|
||||
<span>Standard Time</span>
|
||||
{videoTimeDisplayMode === 'standard' && (
|
||||
<Check className="h-3.5 w-3.5 text-primary" />
|
||||
)}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={() => setVideoTimeDisplayMode('frames')}
|
||||
className="flex items-center justify-between cursor-pointer text-xs"
|
||||
>
|
||||
<span>Frames</span>
|
||||
{videoTimeDisplayMode === 'frames' && (
|
||||
<Check className="h-3.5 w-3.5 text-primary" />
|
||||
)}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
onClick={() => setVideoTimeDisplayMode('timecode')}
|
||||
className="flex items-center justify-between cursor-pointer text-xs"
|
||||
>
|
||||
<span>Timecode</span>
|
||||
{videoTimeDisplayMode === 'timecode' && (
|
||||
<Check className="h-3.5 w-3.5 text-primary" />
|
||||
)}
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right Side: Zoom, Speed, Res, Download, Fullscreen */}
|
||||
<div className="relative flex items-center gap-3">
|
||||
{/* Zoom Controls */}
|
||||
<div className="flex items-center gap-1">
|
||||
<div className="flex items-center gap-1 bg-muted rounded-md p-0.5">
|
||||
<button
|
||||
onClick={() => onZoomChange(zoom * 0.8)}
|
||||
className="p-1 hover:text-primary rounded"
|
||||
>
|
||||
<Minus size={14} />
|
||||
</button>
|
||||
<span className="text-xs w-8 text-center tabular-nums">
|
||||
{Math.round(zoom * 100)}%
|
||||
</span>
|
||||
<button
|
||||
onClick={() => onZoomChange(zoom * 1.2)}
|
||||
className="p-1 hover:text-primary rounded"
|
||||
>
|
||||
<Plus size={14} />
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
onClick={onZoomReset}
|
||||
className="text-xs font-medium px-2 py-1 rounded bg-muted hover:text-primary transition-colors"
|
||||
>
|
||||
Fit
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Playback Rate */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button className="w-8 text-sm font-bold hover:text-primary">
|
||||
{state.playbackRate}x
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
{[0.5, 1, 1.5, 2].map((rate) => (
|
||||
<DropdownMenuItem
|
||||
key={rate}
|
||||
onClick={() => changePlaybackRate(rate)}
|
||||
className={cn(
|
||||
'rounded py-1 px-2 text-left text-xs',
|
||||
state.playbackRate === rate
|
||||
? 'bg-primary text-primary-foreground focus:bg-primary focus:text-primary-foreground'
|
||||
: 'text-foreground',
|
||||
)}
|
||||
>
|
||||
{rate}x
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
{/* Resolution Selector */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button className="flex items-center gap-1 rounded border border-border px-2 py-0.5 text-sm font-semibold hover:bg-muted transition-colors">
|
||||
<Settings className="h-3.5 w-3.5" />
|
||||
<span>{state.currentResolution}</span>
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuLabel>Quality</DropdownMenuLabel>
|
||||
{previewResolutions.map((res) => (
|
||||
<DropdownMenuItem
|
||||
key={res.resolution}
|
||||
onClick={() => changeResolution(res)}
|
||||
className={cn(
|
||||
'flex w-full items-center justify-between',
|
||||
state.currentResolution === res.resolution
|
||||
? 'text-primary font-medium'
|
||||
: 'text-foreground',
|
||||
)}
|
||||
>
|
||||
<span>{res.resolution}</span>
|
||||
<span className="pl-5 text-xs text-muted-foreground">
|
||||
{res.width}x{res.height}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
{/* Download */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button className="transition-colors hover:text-primary" title="Download">
|
||||
<Download className="h-5 w-5" />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuLabel>Download</DropdownMenuLabel>
|
||||
{resolutions.map((res) => (
|
||||
<DropdownMenuItem
|
||||
key={res.resolution}
|
||||
onClick={() => handleDownload(res.key ?? '')}
|
||||
className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground"
|
||||
>
|
||||
<span>{res.resolution}</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{res.isRaw ? data.name?.split('.').pop()?.toUpperCase() || 'RAW' : 'MP4'}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
{/* Fullscreen */}
|
||||
<button onClick={toggleFullScreen} className="transition-colors hover:text-primary">
|
||||
{state.isFullScreen ? (
|
||||
<Minimize className="h-6 w-6" />
|
||||
) : (
|
||||
<Maximize className="h-6 w-6" />
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const VideoPlayer: React.FC<VideoPlayerProps> = ({
|
||||
data,
|
||||
playerRef: passedPlayerRef,
|
||||
@@ -958,7 +602,7 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ControlBar
|
||||
<VideoControlBar
|
||||
state={controlBarState}
|
||||
zoom={zoom}
|
||||
isControlsVisible={isControlsVisible}
|
||||
|
||||
Reference in New Issue
Block a user