mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 23:24:21 +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 {
|
import {
|
||||||
DropdownMenu,
|
VideoControlBar,
|
||||||
DropdownMenuContent,
|
type DisplayTranscode,
|
||||||
DropdownMenuItem,
|
type PlayerState,
|
||||||
DropdownMenuLabel,
|
} from '@/ui/components/viewers/video-control-bar'
|
||||||
DropdownMenuTrigger,
|
import type { AssetInfo } from '@shumai/dtos'
|
||||||
} from '@/ui/components/ui/dropdown-menu'
|
import { Maximize, Minimize } from 'lucide-react'
|
||||||
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'
|
|
||||||
import type { PaneReportedState } from './types'
|
import type { PaneReportedState } from './types'
|
||||||
|
|
||||||
const PLAYBACK_RATES = [0.5, 1, 1.5, 2]
|
|
||||||
|
|
||||||
interface CompareControlBarProps {
|
interface CompareControlBarProps {
|
||||||
activeState: PaneReportedState | null
|
activeState: PaneReportedState | null
|
||||||
|
activeAsset: AssetInfo | null
|
||||||
previewUrl?: string
|
previewUrl?: string
|
||||||
metadata?: MediaMetadata
|
|
||||||
startTimecode?: string | null
|
|
||||||
isFullScreen: boolean
|
isFullScreen: boolean
|
||||||
onTogglePlay: () => void
|
onTogglePlay: () => void
|
||||||
onToggleLoop: () => void
|
onToggleLoop: () => void
|
||||||
@@ -50,9 +29,8 @@ interface CompareControlBarProps {
|
|||||||
|
|
||||||
export function CompareControlBar({
|
export function CompareControlBar({
|
||||||
activeState,
|
activeState,
|
||||||
|
activeAsset,
|
||||||
previewUrl,
|
previewUrl,
|
||||||
metadata,
|
|
||||||
startTimecode,
|
|
||||||
isFullScreen,
|
isFullScreen,
|
||||||
onTogglePlay,
|
onTogglePlay,
|
||||||
onToggleLoop,
|
onToggleLoop,
|
||||||
@@ -67,230 +45,83 @@ export function CompareControlBar({
|
|||||||
onDownload,
|
onDownload,
|
||||||
onToggleFullScreen,
|
onToggleFullScreen,
|
||||||
}: CompareControlBarProps) {
|
}: 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 = (
|
// The active-side asset carries the metadata used for timecode display and
|
||||||
<button
|
// preview scrubbing; ensure the preview url is present for the shared bar.
|
||||||
onClick={onToggleFullScreen}
|
const data =
|
||||||
className="text-foreground transition-colors hover:text-primary"
|
previewUrl && !activeAsset.media?.videoPreview
|
||||||
title="Fullscreen"
|
? { ...activeAsset, media: { ...activeAsset.media, videoPreview: { url: previewUrl } } }
|
||||||
>
|
: activeAsset
|
||||||
{isFullScreen ? <Minimize className="h-5 w-5" /> : <Maximize className="h-5 w-5" />}
|
|
||||||
</button>
|
|
||||||
)
|
|
||||||
|
|
||||||
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 (
|
return (
|
||||||
<div className="relative z-10 flex items-center justify-end gap-2 border-t border-border bg-card px-4 py-3">
|
<VideoControlBar
|
||||||
{activeState?.kind === 'image' && zoomControls}
|
state={state}
|
||||||
{activeState?.kind === 'image' && (
|
zoom={activeState.zoom}
|
||||||
<button
|
isControlsVisible
|
||||||
onClick={() => onDownload()}
|
buffered={v.buffered}
|
||||||
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"
|
data={data}
|
||||||
title="Download"
|
resolutions={v.resolutions as DisplayTranscode[]}
|
||||||
>
|
togglePlay={onTogglePlay}
|
||||||
<Download size={14} />
|
toggleLoop={onToggleLoop}
|
||||||
Download
|
toggleMute={onToggleMute}
|
||||||
</button>
|
handleVolumeChange={onVolumeChange}
|
||||||
)}
|
changePlaybackRate={onChangePlaybackRate}
|
||||||
{fullscreenButton}
|
changeResolution={(res) => onChangeResolution(res.resolution)}
|
||||||
</div>
|
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
|
// Active side is an image: reuse the shared ImageControlBar.
|
||||||
const displayTotalFrames = Math.max(0, video.totalFrames - 1)
|
if (activeState?.kind === 'image') {
|
||||||
const displayString =
|
return (
|
||||||
videoTimeDisplayMode === 'frames'
|
<ImageControlBar
|
||||||
? `${video.currentFrame} / ${displayTotalFrames} fr`
|
zoom={activeState.zoom}
|
||||||
: videoTimeDisplayMode === 'standard'
|
onZoomIn={onZoomIn}
|
||||||
? `${formatTimecode(video.currentFrame, video.frameRate, 'standard')} / ${formatTime(video.totalFrames / video.frameRate)}`
|
onZoomOut={onZoomOut}
|
||||||
: `${formatTimecode(video.currentFrame, video.frameRate, videoTimeDisplayMode, startTimecode)} / ${formatTimecode(displayTotalFrames, video.frameRate, videoTimeDisplayMode, startTimecode)}`
|
onFit={onFit}
|
||||||
|
onDownload={() => onDownload()}
|
||||||
const cycleTimeDisplay = () => {
|
canDownload={!!activeAsset?.media?.original?.key}
|
||||||
const modes: Array<'standard' | 'timecode' | 'frames'> = ['standard', 'timecode', 'frames']
|
fullscreen={{ isFullScreen, onToggle: onToggleFullScreen }}
|
||||||
const idx = modes.indexOf(videoTimeDisplayMode as 'standard' | 'timecode' | 'frames')
|
/>
|
||||||
setVideoTimeDisplayMode(modes[(idx + 1) % modes.length])
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const previewResolutions = video.resolutions.filter((r) => !r.isRaw)
|
// Unsupported / not yet loaded: only expose fullscreen.
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative z-10 flex flex-col gap-2 border-t border-border bg-card px-4 py-2">
|
<div className="relative z-10 flex items-center justify-end gap-2 border-t border-border bg-card px-4 py-3">
|
||||||
<ProgressBar
|
<button
|
||||||
totalFrames={video.totalFrames}
|
onClick={onToggleFullScreen}
|
||||||
currentFrame={video.currentFrame}
|
className="text-foreground transition-colors hover:text-primary"
|
||||||
fps={video.frameRate}
|
title="Fullscreen"
|
||||||
previewUrl={previewUrl}
|
>
|
||||||
onSeek={onSeek}
|
{isFullScreen ? <Minimize className="h-5 w-5" /> : <Maximize className="h-5 w-5" />}
|
||||||
buffered={video.buffered}
|
</button>
|
||||||
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>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -334,9 +334,8 @@ export function CompareViewer({
|
|||||||
|
|
||||||
<CompareControlBar
|
<CompareControlBar
|
||||||
activeState={activeState}
|
activeState={activeState}
|
||||||
|
activeAsset={activeAsset ?? null}
|
||||||
previewUrl={activePreviewUrl}
|
previewUrl={activePreviewUrl}
|
||||||
metadata={activeAsset?.media?.metadata}
|
|
||||||
startTimecode={activeAsset?.media?.metadata?.startTimecode}
|
|
||||||
isFullScreen={isFullScreen}
|
isFullScreen={isFullScreen}
|
||||||
onTogglePlay={handleTogglePlay}
|
onTogglePlay={handleTogglePlay}
|
||||||
onToggleLoop={handleToggleLoop}
|
onToggleLoop={handleToggleLoop}
|
||||||
|
|||||||
@@ -2,12 +2,13 @@ import { useScreenSize } from '@/ui/hooks/useScreenSize'
|
|||||||
import { client } from '@/ui/api/client'
|
import { client } from '@/ui/api/client'
|
||||||
import { getBestTranscode } from '@/ui/lib/media'
|
import { getBestTranscode } from '@/ui/lib/media'
|
||||||
import type { AssetInfo } from '@shumai/dtos'
|
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 type { ReactNode, RefObject } from 'react'
|
||||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||||
import type Player from 'video.js/dist/types/player'
|
import type Player from 'video.js/dist/types/player'
|
||||||
import DrawingCanvas from './drawing-canvas'
|
import DrawingCanvas from './drawing-canvas'
|
||||||
import VideoPlayer from './viewers/video-player'
|
import VideoPlayer from './viewers/video-player'
|
||||||
|
import { ImageControlBar } from './viewers/image-control-bar'
|
||||||
|
|
||||||
import { useAnnotationStore } from '@/ui/stores/annotation-store'
|
import { useAnnotationStore } from '@/ui/stores/annotation-store'
|
||||||
import type { Annotation } from '@/ui/types'
|
import type { Annotation } from '@/ui/types'
|
||||||
@@ -271,51 +272,17 @@ export function FileViewer({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/* Zoom Toolbar */}
|
{/* 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">
|
<ImageControlBar
|
||||||
<div className="flex items-center gap-1 bg-gray-200/50 dark:bg-white/10 rounded-md p-0.5 mr-auto">
|
zoom={zoom}
|
||||||
<button
|
onZoomIn={() => handleZoom(1.2)}
|
||||||
onClick={() => handleZoom(0.8)}
|
onZoomOut={() => 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"
|
onFit={handleFit}
|
||||||
title="Zoom Out"
|
onDownload={handleDownload}
|
||||||
>
|
canDownload={!!file.media?.original?.key}
|
||||||
<Minus size={16} />
|
onCopy={handleCopy}
|
||||||
</button>
|
copied={copied}
|
||||||
<span className="w-12 text-center text-xs font-mono font-medium text-gray-900 dark:text-gray-100 select-none">
|
canCopy={!!bestUrl}
|
||||||
{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>
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
{isVideo && (
|
{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 { client } from '@/ui/api/client'
|
||||||
import { cn } from '@/ui/lib/utils'
|
import { cn } from '@/ui/lib/utils'
|
||||||
import {
|
import { Play } from 'lucide-react'
|
||||||
Check,
|
|
||||||
ChevronDown,
|
|
||||||
Download,
|
|
||||||
Maximize,
|
|
||||||
Minimize,
|
|
||||||
Minus,
|
|
||||||
Pause,
|
|
||||||
Play,
|
|
||||||
Plus,
|
|
||||||
Repeat,
|
|
||||||
Settings,
|
|
||||||
Volume2,
|
|
||||||
VolumeX,
|
|
||||||
} from 'lucide-react'
|
|
||||||
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
import React, { useCallback, useEffect, useRef, useState } from 'react'
|
||||||
import videojs from 'video.js'
|
import videojs from 'video.js'
|
||||||
import type Player from 'video.js/dist/types/player'
|
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 { 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 type { Annotation } from '@/ui/types'
|
||||||
import DrawingCanvas from '../drawing-canvas'
|
import DrawingCanvas from '../drawing-canvas'
|
||||||
import { useAnnotationStore } from '@/ui/stores/annotation-store'
|
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 {
|
interface VideoPlayerProps {
|
||||||
data: AssetInfo
|
data: AssetInfo
|
||||||
playerRef?: React.RefObject<Player | null>
|
playerRef?: React.RefObject<Player | null>
|
||||||
@@ -63,323 +24,6 @@ interface VideoPlayerProps {
|
|||||||
children?: React.ReactNode
|
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> = ({
|
const VideoPlayer: React.FC<VideoPlayerProps> = ({
|
||||||
data,
|
data,
|
||||||
playerRef: passedPlayerRef,
|
playerRef: passedPlayerRef,
|
||||||
@@ -958,7 +602,7 @@ const VideoPlayer: React.FC<VideoPlayerProps> = ({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ControlBar
|
<VideoControlBar
|
||||||
state={controlBarState}
|
state={controlBarState}
|
||||||
zoom={zoom}
|
zoom={zoom}
|
||||||
isControlsVisible={isControlsVisible}
|
isControlsVisible={isControlsVisible}
|
||||||
|
|||||||
Reference in New Issue
Block a user