import {
CheckCircle,
ClosedCaptioning,
Eye,
EyeSlash,
ListBullets,
PersonSimpleRun,
Trash,
Waveform,
} from "@phosphor-icons/react";
import { useState } from "react";
import { formatTime, getSegmentStartTime } from "../lib/timeline.js";
import { LIVE_PORTRAIT_WEB_MODEL } from "../config/livePortrait.js";
import { probeLivePortraitWebEnvironment } from "../lib/livePortraitWeb.js";
import { normalizeVisualKeyframes } from "../lib/visualEffects.js";
import { HistoryPanel, MyVoicesPanel, VisualEffectsPanel, VoiceSynthesisPanel } from "./panels.jsx";
function CaptionContextPanel({
t,
captionSegments,
selectedCaptionSegment,
selectedSegmentId,
setSelectedSegmentId,
currentSegmentIndex,
captionTargetDuration,
updateCaptionSegmentText,
toggleCaptionSegmentHidden,
deleteCaptionSegment,
seekTo,
sourceAudioBlob,
generateCaptionsFromSourceAudio,
isGeneratingCaptions,
automaticCaptionProgress,
}) {
const selectedIndex = Math.max(
0,
captionSegments.findIndex((segment) => segment.id === selectedCaptionSegment?.id),
);
const selectedStart = captionSegments.length
? getSegmentStartTime(captionSegments, selectedIndex, captionTargetDuration)
: 0;
return (
{selectedCaptionSegment ? (
) : (
{t("noCaptionSegments")}
{t("captionEmptyHint", "选择时间线字幕片段后,这里会同步编辑。")}
)}
{!captionSegments.length ? (
) : null}
{t("captionList", "字幕列表")}
{captionSegments.length ? (
captionSegments.map((segment, index) => (
))
) : (
{t("noCaptionSegments")}
)}
);
}
function AudioClipContextPanel({ t, segment, updateAudioSegment, toggleAudioSegmentReverse, deleteAudioSegment, downloadBlob }) {
return (
);
}
function AvatarContextPanel({ t, hasVisual, visualType, audioBlob, audioDuration, captionSegments, selectedVoice, avatarJob, generateAvatarAcceptanceFrame }) {
const hasPortrait = hasVisual && visualType === "image";
const [probeState, setProbeState] = useState("idle");
const [probeResult, setProbeResult] = useState(null);
const [avatarQuality, setAvatarQuality] = useState("preview");
const runProbe = async () => {
setProbeState("running");
try {
setProbeResult(await probeLivePortraitWebEnvironment());
setProbeState("done");
} catch (error) {
setProbeResult({ readyForPorting: false, checks: [{ id: "runtime", state: "failed", detail: error instanceof Error ? error.message : String(error) }] });
setProbeState("done");
}
};
return (
{t("avatarKicker")}{t("avatarLipSyncTitle")}{t("avatarLipSyncDescription")}
{t("avatarPortrait")}{hasPortrait ? t("avatarCurrentPortrait") : t("avatarNeedsPortrait")}
{t("avatarAudio")}{audioBlob ? `${selectedVoice?.name ?? "AI"} · ${audioDuration.toFixed(1)}s` : t("avatarNeedsAudio")}
{t("avatarLipSyncSource")}{captionSegments.length ? `${captionSegments.length} ${t("captionSegmentsUnit")} · ${t("avatarCaptionSync")}` : t("avatarNeedsCaptions")}
{t("avatarModelSource")}{LIVE_PORTRAIT_WEB_MODEL.id}
{t("avatarGenerationNote")}
1{t("avatarStagePinned")}
2{t("avatarStageGrid")}
3{t("avatarStageAudio")}
{probeResult ? (
{probeResult.checks.map((check) =>
{check.detail}
)}
) : null}
{avatarJob?.running || avatarJob?.progress > 0 || avatarJob?.phase ? (
{avatarJob.phase || t("avatarGenerating")}{avatarJob.progress}%
) : null}
{t("avatarPortingStatus")}{t("avatarServiceHint")}
);
}
export function VoicePanel({
t,
activeTool,
status,
statusText,
voiceTab,
setVoiceTab,
script,
updateScript,
selectedVoiceId,
setSelectedVoiceId,
selectedVoice,
filteredVoices,
voiceFilter,
setVoiceFilter,
showVoiceFilter,
setShowVoiceFilter,
speed,
setSpeed,
volume,
setVolume,
progressPercent,
audioBlob,
generateVoiceover,
downloadBlob,
favoriteVoiceIds,
setFavoriteVoiceIds,
recordedVoices,
recordingState,
recordingElapsed,
startVoiceRecording,
stopVoiceRecording,
useRecordedVoice,
historyItems,
useHistoryItem,
setHistoryItems,
notify,
audioUrl,
audioRef,
audioSegments,
audioSegmentRefs,
sourceAudioRef,
musicRef,
sourceAudioUrl,
musicUrl,
captionSegments,
selectedCaptionSegment,
selectedSegmentId,
setSelectedSegmentId,
currentSegmentIndex,
captionTargetDuration,
updateCaptionSegmentText,
toggleCaptionSegmentHidden,
deleteCaptionSegment,
seekTo,
sourceAudioBlob,
sourceAudioLinked,
generateCaptionsFromSourceAudio,
isGeneratingCaptions,
automaticCaptionProgress,
avatarPanelOpen,
hasVisual,
visualType,
audioDuration,
avatarJob,
generateAvatarAcceptanceFrame,
selectedTrack,
selectedAudioSegment,
updateAudioSegment,
toggleAudioSegmentReverse,
deleteAudioSegment,
selectedVisualSegment,
visualLocalTime,
visualTimelineStart = 0,
updateSelectedVisualEffects,
remasterJob,
remasterQuality,
setRemasterQuality,
enhanceSelectedVisualFrame,
enhanceSelectedVisualClip,
clearSelectedVisualEnhancement,
selectedFilterId,
setSelectedFilterId,
trOption,
}) {
const isCaptionContext = activeTool === "caption";
const isAvatarContext = activeTool === "smart" && avatarPanelOpen;
const isAudioClipContext = selectedTrack === "audio" && Boolean(selectedAudioSegment);
const isVisualContext = selectedTrack === "image" && Boolean(selectedVisualSegment);
const title = isVisualContext ? t("imageTrack") : isAvatarContext ? t("avatarTitle") : isCaptionContext ? t("caption") : isAudioClipContext ? t("audioClipProperties") : t("aiVoice");
const panelStatusText = isCaptionContext
? captionSegments.length
? `${captionSegments.length} ${t("captionSegmentsUnit", "条字幕")}`
: t("noCaptionSegments")
: isVisualContext
? `${visualLocalTime.toFixed(2)}s · ${normalizeVisualKeyframes(selectedVisualSegment.keyframes).length} ${t("visualFrames")}`
: isAvatarContext
? t("avatarPortingStatus")
: isAudioClipContext
? `${formatTime(selectedAudioSegment.duration)} · ${selectedAudioSegment.start.toFixed(1)}s`
: statusText === "模型待命"
? t("modelReady")
: statusText;
return (
);
}