"use client"; import { type ReactNode } from "react"; import { Settings2 } from "lucide-react"; import { Button, Popover } from "antd"; import { canvasThemes } from "@/lib/canvas-theme"; import { useThemeStore } from "@/stores/use-theme-store"; import type { AiConfig } from "@/stores/use-config-store"; import { CanvasImageSettingsTheme } from "./canvas-image-settings-popover"; const resolutionOptions = [ { value: "720", label: "720p" }, { value: "480", label: "480p" }, ]; 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 }, ]; const secondOptions = [6, 10, 12, 16, 20]; type CanvasVideoSettingsPopoverProps = { config: AiConfig; onConfigChange: (key: keyof AiConfig, value: string) => void; buttonClassName?: string; placement?: "topLeft" | "top" | "topRight" | "bottomLeft" | "bottom" | "bottomRight"; }; export function CanvasVideoSettingsPopover({ config, onConfigChange, buttonClassName, placement = "topLeft" }: CanvasVideoSettingsPopoverProps) { const theme = canvasThemes[useThemeStore((state) => state.theme)]; const seconds = config.videoSeconds || "6"; const size = normalizeVideoSize(config.size); const dimensions = readSizeDimensions(size); const resolution = normalizeVideoResolution(config.vquality); const updateDimension = (key: "width" | "height", value: number | null) => { const next = Math.max(1, Math.floor(value || dimensions[key] || 720)); onConfigChange("size", `${key === "width" ? next : dimensions.width}x${key === "height" ? next : dimensions.height}`); }; return ( document.body} content={
event.stopPropagation()}>
视频设置
{resolutionOptions.map((item) => ( onConfigChange("vquality", item.value)}> {item.label} ))}
onConfigChange("vquality", value)} />
updateDimension("width", value)} /> ↔ updateDimension("height", value)} />
{sizeOptions.map((item) => ( ))}
{secondOptions.map((value) => ( onConfigChange("videoSeconds", String(value))}> {value}s ))} onConfigChange("videoSeconds", event.target.value)} onMouseDown={(event) => event.stopPropagation()} />
} >
); } function OptionPill({ selected, theme, onClick, children }: { selected: boolean; theme: (typeof canvasThemes)[keyof typeof canvasThemes]; onClick: () => void; children: ReactNode }) { return ( ); } function SettingGroup({ title, color, children }: { title: string; color: string; children: ReactNode }) { return (
{title}
{children}
); } function ResolutionInput({ value, theme, onChange }: { value: string; theme: (typeof canvasThemes)[keyof typeof canvasThemes]; onChange: (value: string) => void }) { return ( ); } function DimensionInput({ prefix, value, theme, onChange }: { prefix: string; value: number; theme: (typeof canvasThemes)[keyof typeof canvasThemes]; onChange: (value: number | null) => void }) { return ( ); } function SizePreview({ width, height, color }: { width: number; height: number; color: string }) { const longSide = Math.max(width, height); const previewWidth = Math.max(12, Math.round((width / longSide) * 34)); const previewHeight = Math.max(12, Math.round((height / longSide) * 34)); return ; } function normalizeVideoSize(value: string) { if (/^\d+x\d+$/.test(value || "")) return value; return ["9:16", "2:3", "3:4"].includes(value) ? "720x1280" : "1280x720"; } function normalizeVideoResolution(value: string) { if (value === "480p" || value === "low") return "480"; if (value === "720p" || value === "auto" || value === "high" || value === "medium") return "720"; return value.replace(/p$/i, "") || "720"; } function readSizeDimensions(size: string) { const match = size.match(/^(\d+)x(\d+)$/); return { width: Number(match?.[1]) || 1280, height: Number(match?.[2]) || 720 }; } function sizeLabel(value: string) { return ({ "720x1280": "竖屏", "1280x720": "横屏", "1024x1024": "方形", "1792x1024": "宽屏", "1024x1792": "长图" } as Record)[value] || value; }