Files
shumai/packages/webui/components/compare/compare-control-bar.tsx
T
yiling d3c1c641b4 fix(webui): show control bar in single-file fullscreen; theme the overlay
The single-file player fullscreened the inner video-area element, which
is not an ancestor of the control bar, so the bar was never visible in
fullscreen. Fullscreen the player root instead so the floating control
bar is included and the existing show-on-move / hide-after-idle logic
works (YouTube-style).

Also make the control-bar colors theme-aware in all cases. The fullscreen
floating overlay now uses bg-card/90 + backdrop-blur + foreground text
instead of a hardcoded dark overlay, so it follows the app light/dark
theme. The former themedChrome prop is renamed to floatOverlayInFullScreen
(default true = single-file floating overlay; compare passes false to keep
its bar in-flow).
2026-07-04 12:48:15 +08:00

129 lines
3.9 KiB
TypeScript

import { ImageControlBar } from '@/ui/components/viewers/image-control-bar'
import {
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'
interface CompareControlBarProps {
activeState: PaneReportedState | null
activeAsset: AssetInfo | null
previewUrl?: string
isFullScreen: boolean
onTogglePlay: () => void
onToggleLoop: () => void
onSeek: (frame: number) => void
onVolumeChange: (volume: number) => void
onToggleMute: () => void
onChangePlaybackRate: (rate: number) => void
onChangeResolution: (resolution: string) => void
onZoomIn: () => void
onZoomOut: () => void
onFit: () => void
onDownload: (key?: string) => void
onToggleFullScreen: () => void
}
export function CompareControlBar({
activeState,
activeAsset,
previewUrl,
isFullScreen,
onTogglePlay,
onToggleLoop,
onSeek,
onVolumeChange,
onToggleMute,
onChangePlaybackRate,
onChangeResolution,
onZoomIn,
onZoomOut,
onFit,
onDownload,
onToggleFullScreen,
}: CompareControlBarProps) {
// 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,
}
// 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
return (
<VideoControlBar
state={state}
zoom={activeState.zoom}
isControlsVisible
floatOverlayInFullScreen={false}
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}
/>
)
}
// 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 }}
/>
)
}
// Unsupported / not yet loaded: only expose fullscreen.
return (
<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>
)
}