"use client"; import { BloubAvatar } from "@/components/bloub-avatar"; import type { StateId } from "@/lib/bloub-official/states"; import { cn } from "@/lib/utils"; type GenerationPhase = | "idle" | "queued" | "processing" | "finalizing" | "failed" | "completed"; interface GenerationDotPlaceholderProps { className?: string; compact?: boolean; phase?: GenerationPhase; progress?: number | null; showProgress?: boolean; title?: string; viewportScale?: number; } const PHASE_TITLES: Record = { idle: "正在创建图片", queued: "等待开始生成", processing: "等待模型返回图片", finalizing: "正在保存生成结果", failed: "生成失败", completed: "生成完成", }; function clampProgress(value: number) { if (!Number.isFinite(value)) return 0; return Math.max(0, Math.min(100, Math.round(value))); } function getBloubState(phase: GenerationPhase): StateId { if (phase === "failed") return "alert"; if (phase === "completed") return "wink"; if (phase === "queued") return "thinking"; return "idle"; } export function GenerationDotPlaceholder({ className, compact = false, phase = "processing", progress, showProgress = true, title, }: GenerationDotPlaceholderProps) { const resolvedProgress = typeof progress === "number" && Number.isFinite(progress) ? clampProgress(progress) : null; const resolvedTitle = title || PHASE_TITLES[phase]; const playSequence = phase === "processing" || phase === "finalizing"; return (
{resolvedTitle}
{showProgress && phase !== "completed" ? (
{phase === "failed" ? "已停止" : resolvedProgress === null ? "等待结果,返回后自动展示" : "生成进度"} {resolvedProgress !== null ? {resolvedProgress}% : null}
{resolvedProgress !== null ?
: null}
) : null}
); }