import { type ReactNode } from "react"; import { Switch } from "@/components/ui/base/switch"; import { ImageSettingsTheme } from "@/components/image-settings-panel"; import { boolConfig, isSeedanceFastModel, isSeedanceVideoConfig, normalizeSeedanceDuration, normalizeSeedanceRatio, normalizeSeedanceResolution, seedanceRatioOptions } from "@/lib/seedance-video"; import { isVolcengineArkVideoProtocol } from "@/lib/model-protocols"; import { type CanvasTheme } from "@/lib/canvas-theme"; import { formatVideoResolutionLabel, isVideoResolutionMatch, normalizeVideoDuration, videoDimensionsForRatioAndResolution, videoResolutionComparisonKey, VIDEO_DURATION_MIN } from "@/lib/video-generation-options"; import { modelCapabilityConfigFor, resolveVideoRatioValue, resolveVideoResolutionValue, videoDurationOptions, type VideoCapabilityConfig } from "@/lib/model-capabilities"; import { modelOptionName, resolveModelChannel, resolveModelRequestConfig, type AiConfig } from "@/stores/use-config-store"; const sizeOptions = [ { value: "1280x720", label: "横屏", width: 1280, height: 720 }, { value: "720x1280", label: "竖屏", width: 720, height: 1280 }, { value: "1024x1024", label: "方形", width: 1024, height: 1024 }, { value: "1792x1024", label: "宽屏", width: 1792, height: 1024 }, { value: "1024x1792", label: "长图", width: 1024, height: 1792 }, { value: "auto", label: "auto", width: 0, height: 0 }, ]; type VideoSettingsPanelProps = { config: AiConfig; onConfigChange: (key: "vquality" | "size" | "videoSeconds" | "videoGenerateAudio" | "videoWatermark" | "videoArkPrivateAssetUpload", value: string) => void; theme: CanvasTheme; showTitle?: boolean; className?: string; }; export function VideoSettingsPanel({ config, onConfigChange, theme, showTitle = true, className = "w-[292px] space-y-3" }: VideoSettingsPanelProps) { const profile = modelCapabilityConfigFor(config, config.model).video!; const priceTiers = modelPriceTiers(config); if (resolveModelRequestConfig(config, config.model).interfaceType === "volcengine-jimeng-video") { return ; } if (isSeedanceVideoConfig(config)) { return ; } const seconds = normalizeVideoDuration(config.videoSeconds); const resolution = resolveVideoResolutionValue(profile, config.vquality); const ratio = resolveVideoRatioValue(profile, config.size); const dimensions = videoDimensionsForRatioAndResolution(ratio, resolution); const sizeSupported = profile.ratios.length > 0; const configuredResolutions = profile.resolutions.map((value) => ({ value, label: formatVideoResolutionLabel(value) })); const generateAudio = boolConfig(config.videoGenerateAudio, profile.generateAudio.default); const watermark = boolConfig(config.videoWatermark, profile.watermark.default); return (
event.stopPropagation()}> {showTitle ?
视频设置
: null} {configuredResolutions.length ?
{configuredResolutions.map((item) => ( onConfigChange("vquality", item.value)}> {item.label} ))}
: null} {sizeSupported ? {dimensions ?
×
: null}
{profile.ratios.map((value) => ( ))}
: null} !hasPriceTierForVideoSelection(priceTiers, resolution, value)} onChange={(value) => onConfigChange("videoSeconds", String(value))} /> {profile.generateAudio.supported || profile.watermark.supported ?
{profile.generateAudio.supported ? onConfigChange("videoGenerateAudio", String(checked))} /> : null}{profile.watermark.supported ? onConfigChange("videoWatermark", String(checked))} /> : null}
: null}
); } function JiMengVideoSettingsPanel({ config, profile, priceTiers, onConfigChange, theme, showTitle, className }: VideoSettingsPanelProps & { profile: VideoCapabilityConfig; priceTiers: ReturnType }) { const seconds = normalizeVideoDuration(config.videoSeconds); return (
event.stopPropagation()}> {showTitle ?
视频设置
: null}
{profile.ratios.map((value) => onConfigChange("size", value)}>{value})}
!hasPriceTierForVideoSelection(priceTiers, "*", value)} onChange={(value) => onConfigChange("videoSeconds", String(value))} />
); } function SeedanceVideoSettingsPanel({ config, profile, priceTiers, onConfigChange, theme, showTitle, className }: VideoSettingsPanelProps & { profile: VideoCapabilityConfig; priceTiers: ReturnType }) { const model = modelOptionName(config.model || config.videoModel); const resolution = normalizeSeedanceResolution(config.vquality, model); const ratio = normalizeSeedanceRatio(config.size); const duration = normalizeSeedanceDuration(config.videoSeconds); const generateAudio = boolConfig(config.videoGenerateAudio, profile.generateAudio.default); const watermark = boolConfig(config.videoWatermark, profile.watermark.default); const useArkPrivateAssets = boolConfig(config.videoArkPrivateAssetUpload, true); const isArkSeedance = isVolcengineArkVideoProtocol(resolveModelRequestConfig(config, config.model).interfaceType); return (
event.stopPropagation()}> {showTitle ?
视频设置
: null}
{profile.resolutions.map((value) => { const item = { value, label: value.toUpperCase() }; const disabled = (item.value === "1080p" && isSeedanceFastModel(model)) || !hasPriceTierForVideoSelection(priceTiers, item.value, duration); return ( onConfigChange("vquality", item.value)}> {item.label} ); })}
{isSeedanceFastModel(model) ?
fast 模型自动使用 720P
: null}
{profile.ratios.map((value) => { const item = { value, label: value }; return ( ); })}
!hasPriceTierForVideoSelection(priceTiers, resolution, value)} onChange={(value) => onConfigChange("videoSeconds", String(value))} />
{profile.generateAudio.supported ? onConfigChange("videoGenerateAudio", String(checked))} /> : null} {profile.watermark.supported ? onConfigChange("videoWatermark", String(checked))} /> : null}
{isArkSeedance ? (
onConfigChange("videoArkPrivateAssetUpload", String(checked))} />
) : null}
); } export function videoResolutionLabel(value: string) { return formatVideoResolutionLabel(value); } export function videoSizeLabel(value: string) { const ratio = normalizeSeedanceRatio(value); if (value === "adaptive" || value === "auto") return "自适应"; // The compact summary must mirror the selected value (for example 16:9), // while the settings panel can still use semantic labels such as 横屏. if (ratio === value) return ratio; const size = normalizeVideoSizeValue(value); return sizeOptions.find((item) => item.value === size)?.label || size; } export function videoSecondsLabel(value: string) { return `${normalizeVideoDuration(value)}s`; } export function normalizeVideoSizeValue(value: string) { if (value === "auto") return "auto"; if (/^\d+x\d+$/.test(value || "")) return value; return ["9:16", "2:3", "3:4"].includes(value) ? "720x1280" : "1280x720"; } function OptionPill({ selected, disabled = false, theme, onClick, children }: { selected: boolean; disabled?: boolean; theme: CanvasTheme; onClick: () => void; children: ReactNode }) { return ( ); } function SettingGroup({ title, color, children }: { title: string; color: string; children: ReactNode }) { return (
{title}
{children}
); } function DimensionValue({ prefix, value, theme }: { prefix: string; value: number; theme: CanvasTheme }) { return (
{prefix} {value}
); } function DurationInput({ value, min, max, theme, onChange }: { value: number; min: number; max?: number; theme: CanvasTheme; onChange: (value: number) => void }) { const commit = (input: HTMLInputElement) => { const next = Math.min(max || Number.POSITIVE_INFINITY, Math.max(min, Math.floor(Number(input.value) || value || min))); input.value = String(next); onChange(next); }; return ( ); } function VideoDurationControl({ profile, value, theme, disabled, onChange }: { profile: VideoCapabilityConfig; value: number; theme: CanvasTheme; disabled?: (value: number) => boolean; onChange: (value: number) => void }) { if (profile.duration.selection === "range") { const min = profile.duration.min || VIDEO_DURATION_MIN; const max = Math.max(min, profile.duration.max || min); const step = Math.max(1, profile.duration.step || 1); const normalized = normalizeDurationValue(value, profile.duration.default, min, max, step); return { if (!disabled?.(next)) onChange(next); }} />; } const options = videoDurationOptions(profile); return
{options.map((option) => onChange(option)}>{option}s)}
; } function modelPriceTiers(config: AiConfig) { const channel = resolveModelChannel(config, config.model); const cost = channel.modelCosts?.find((item) => item.model === modelOptionName(config.model)); return cost?.logicalPriceTiers || []; } function hasPriceTierForVideoSelection(tiers: ReturnType, resolution: string, seconds: number) { if (!tiers.length) return true; const normalizedResolution = normalizeTierResolution(resolution); return tiers.some((tier) => { const selector = tier.selector || {}; const tierResolution = selector.vquality || tier.resolution; const tierSeconds = selector.videoSeconds ? Number(selector.videoSeconds) : tier.videoSeconds; return (tierResolution === "*" || !tierResolution || normalizeTierResolution(tierResolution) === normalizedResolution) && (!tierSeconds || tierSeconds === seconds); }); } function normalizeTierResolution(value: string) { return videoResolutionComparisonKey(value); } function DurationRangeControl({ value, min, max, step, theme, onChange }: { value: number; min: number; max: number; step: number; theme: CanvasTheme; onChange: (value: number) => void }) { return
onChange(Number(event.target.value))} onMouseDown={(event) => event.stopPropagation()} />
{min}s {max}s
; } function normalizeDurationValue(value: number, fallback: number, min: number, max: number, step: number) { const candidate = Number.isFinite(value) ? value : fallback; const clamped = Math.min(max, Math.max(min, Math.floor(candidate))); const maxStep = Math.max(0, Math.floor((max - min) / step)); return min + Math.min(maxStep, Math.max(0, Math.round((clamped - min) / step))) * step; } function normalizedNumber(value: number) { return Number.isFinite(value) ? Math.floor(value) : 0; } function SizePreview({ width, height, color }: { width: number; height: number; color: string }) { if (!width || !height) return null; const longSide = Math.max(width, height); const previewWidth = Math.max(7, Math.round((width / longSide) * 16)); const previewHeight = Math.max(7, Math.round((height / longSide) * 16)); return ; } function ratioPreview(ratio: string) { if (ratio === "9:16") return { width: 9, height: 16 }; if (ratio === "1:1") return { width: 1, height: 1 }; if (ratio === "4:3") return { width: 4, height: 3 }; if (ratio === "3:4") return { width: 3, height: 4 }; if (ratio === "21:9") return { width: 21, height: 9 }; if (ratio === "adaptive") return { width: 0, height: 0 }; return { width: 16, height: 9 }; } function SwitchRow({ label, checked, theme, onChange }: { label: string; checked: boolean; theme: CanvasTheme; onChange: (checked: boolean) => void }) { return (
{label} event.stopPropagation()}>
); }