import { CheckCircle, ClosedCaptioning, Eye, EyeSlash, ImageSquare, Link, LinkBreak, ListBullets, PersonSimpleRun, Plus, Scissors, Sparkle, Trash, UploadSimple, Waveform, X, } from "@phosphor-icons/react"; import { useEffect, useRef, useState } from "react"; import { createPortal } from "react-dom"; import { formatTime, getSegmentStartTime } from "../lib/timeline.js"; import { LIVE_PORTRAIT_WEB_MODEL } from "../config/livePortrait.js"; import { probeLivePortraitWebEnvironment } from "../lib/livePortraitWeb.js"; import { getCaptionVoiceSegment } from "../lib/captionVoice.js"; import { findCaptionAudioLinkTarget } from "../lib/captionEditingActions.js"; import { normalizeVisualKeyframes } from "../lib/visualEffects.js"; import { MAX_SRT_FILE_BYTES, parseSrt } from "../lib/subtitles.js"; import { AiMusicGenerator, HistoryPanel, MyVoicesPanel, SmartVisionPanel, VisualEffectsPanel, VoiceSynthesisPanel } from "./panels.jsx"; function AutoEditReviewDialog({ t, autoEdit }) { const { review, job } = autoEdit || {}; if (!review?.open || typeof document === "undefined") return null; const complete = !job.running && review.captions.length > 0; return createPortal(
{t("smartAutoEdit")}

{t("autoEditReviewTitle")}

{review.error ? t("autoEditReviewFailed") : complete ? t("autoEditReviewReady") : job.phase}
01{t("autoEditCandidateTitle")}
{review.candidates.length} {t("autoEditFramesUnit")}

{t("autoEditCandidateHint")}

{review.candidates.length ?
{review.candidates.map((candidate, index) => (
{`${t("autoEditCandidateFrame")}#{String(index + 1).padStart(2, "0")}{candidate.aspectRatio}
{t("autoEditVisualChange")}{Math.round(candidate.difference * 100)}%
))}
:
{t("autoEditFindingScenes")}
}
02{t("autoEditModelResultTitle")}
{review.captions.length} {t("captionSegmentsUnit")}

{t("autoEditModelResultHint")}

{review.error ?
{t("autoEditReviewFailed")}{review.error}
: review.segments.length ?
{review.segments.map((segment) => { const segmentCaptions = review.captions.filter((caption) => caption.visualSegmentId === segment.id); const preview = review.candidates.find((candidate) => candidate.segmentId === segment.id); return
{preview ? : null}
{segment.name || `${t("autoEditClip")} ${(segment.index ?? 0) + 1}`}{review.candidates.filter((candidate) => candidate.segmentId === segment.id).length} {t("autoEditFramesUnit")}
{t(`autoEditSegmentStatus_${segment.status}`)}
{segment.error ?

{segment.error}

: segmentCaptions.length ? <>
{segmentCaptions.map((caption, index) => (
{String(index + 1).padStart(2, "0")}

{caption.text}

))}
{segment.status === "running" ?
{t("autoEditWindowProgress").replace("{current}", segment.windowIndex || 0).replace("{total}", segment.totalWindows || 0)}
: null} :
{segment.status === "running" ? : null}{segment.status === "running" && segment.totalWindows ? t("autoEditWindowProgress").replace("{current}", segment.windowIndex || 0).replace("{total}", segment.totalWindows) : t(`autoEditSegmentHint_${segment.status}`)}
}
; })}
:
{job.running ? job.phase : t("autoEditWaitingForModel")}
}
{complete ? t("autoEditReviewSummaryReady") : t("autoEditReviewSummaryRunning")}{t("autoEditReviewSummaryHint")}
, document.body, ); } function AutoEditPanel({ t, hasVisual, autoEdit }) { const availability = autoEdit?.support?.availability || "unknown"; const ready = availability === "available" || availability === "downloadable" || availability === "downloading"; const downloadProgress = Math.max(0, Math.min(100, Number(autoEdit?.support?.progress) || 0)); const isPreparingSupport = availability === "downloading" && Number.isFinite(autoEdit?.support?.progress); const supportActionLabel = availability === "downloading" ? `${t("autoEditDownloadingModel")}${downloadProgress ? ` ${downloadProgress}%` : ""}` : availability === "downloadable" ? t("autoEditDownloadModel") : t("autoEditCheckSupport"); return (<>
{t("autoEditCreateTitle")}{t("autoEditCreateDesc")}
{t("autoEditBrowserModel")}{t(`autoEditStatus_${availability}`)}

{t("autoEditPrivacyHint")}

{isPreparingSupport ? : null}
1

{t("autoEditStepScenes")}{t("autoEditStepScenesHint")}

2

{t("autoEditStepCaptions")}{t("autoEditStepCaptionsHint")}

3

{t("autoEditStepTimeline")}{t("autoEditStepTimelineHint")}

{autoEdit?.job?.running ?
{autoEdit.job.phase}{autoEdit.job.progress}%
: null}
); } function CaptionContextPanel({ t, captionSegments, selectedCaptionSegment, selectedSegmentId, setSelectedSegmentId, currentSegmentIndex, captionTargetDuration, updateCaptionSegmentText, toggleCaptionSegmentHidden, deleteCaptionSegment, seekTo, sourceAudioBlob, generateCaptionsFromSourceAudio, isGeneratingCaptions, automaticCaptionProgress, importCaptionSegments, addCaptionSegment, alignCaptionToAudio, linkCaptionAudio, unlinkCaptionAudio, audioSegments, }) { const srtInputRef = useRef(null); const focusNewCaptionRef = useRef(false); const [pendingSrt, setPendingSrt] = useState(null); const selectedIndex = Math.max( 0, captionSegments.findIndex((segment) => segment.id === selectedCaptionSegment?.id), ); const selectedStart = captionSegments.length ? getSegmentStartTime(captionSegments, selectedIndex, captionTargetDuration) : 0; const linkedAudioSegment = audioSegments.find((segment) => segment.id === selectedCaptionSegment?.audioSegmentId); const relinkTarget = findCaptionAudioLinkTarget(selectedCaptionSegment, audioSegments); useEffect(() => { if (!focusNewCaptionRef.current || !selectedCaptionSegment) return; focusNewCaptionRef.current = false; const frame = requestAnimationFrame(() => document.getElementById("caption-context-input")?.focus()); return () => cancelAnimationFrame(frame); }, [selectedCaptionSegment]); function handleAddCaption() { focusNewCaptionRef.current = true; addCaptionSegment(); } async function handleSrtFile(file) { if (!file) return; try { if (file.size > MAX_SRT_FILE_BYTES) throw new Error(t("srtFileTooLarge")); const result = parseSrt(await file.text()); if (!result.captions.length) throw new Error(t("srtNoValidCaptions")); if (captionSegments.length) setPendingSrt(result); else importCaptionSegments(result.captions, "replace", result.skipped); } catch (error) { window.alert(error instanceof Error ? error.message : t("srtImportFailed")); } } function applyPendingSrt(mode) { if (!pendingSrt) return; importCaptionSegments(pendingSrt.captions, mode, pendingSrt.skipped); setPendingSrt(null); } return (
{selectedCaptionSegment ? (