"use strict";
/*
* video-recap 审片台 — simple, uncluttered views:
* 1. 成片 (Video list + clean native video player + 解说词 / 镜头)
* 2. 素材库 (Audio/image previews, clean visual style cards, sample videos)
*/
const KIND_LABEL = {
bgm: "配乐",
sfx: "音效",
voice: "音色",
font: "字体",
image: "图形",
subtitle_style: "字幕样式",
packaging: "画面包装",
production_reference: "剪辑参考",
};
const CATEGORY_LABEL = {
"urban-suspense": "都市悬疑",
"ancient-emotional": "古风情感",
"high-energy": "燃系竞技",
"warm-narrative": "温情叙事",
whoosh: "转场呼啸",
impact: "情绪重音",
riser: "蓄力抬升",
accent: "节奏提示",
"steady-narrator": "沉稳叙事",
"crisp-female": "清亮女声",
"cinematic-male": "电影感男声",
"news-brief": "资讯播报",
portrait: "竖屏 9:16",
landscape: "横屏 16:9",
reference: "剪辑参考",
};
const PROVIDER_LABEL = {
"mimo-tts": "MiMo 语音",
"fish-audio": "Fish Audio",
"index-tts": "IndexTTS",
};
const catLabel = (raw, fallback = "默认分类") =>
(raw && (CATEGORY_LABEL[raw] || raw)) || fallback;
const empty = (title, text) =>
`
${esc(title)}
${esc(text)}
`;
const notice = (text) =>
`${icon("alert")}${esc(text)}
`;
/* ============================================================ 1. 成片 */
function renderRunItem(run, activePath) {
const active = run.path === activePath;
const dur = Number.isFinite(run.duration) ? clock(run.duration) : "";
const err = run.blockers > 0 || Boolean(run.state_error);
return `
${err ? '' : ""}${esc(run.title || run.name)}
${dur ? `${esc(dur)}` : ""}
`;
}
function renderRunRail(O, activePath) {
const all = topRuns(O);
const ready = all.filter((r) => r.has_video);
const drafts = all.filter((r) => !r.has_video);
if (!ready.length && !drafts.length) {
return `暂无成片
`;
}
// When finished videos exist, show them cleanly and tuck unfinished work dirs into a quiet fold.
const mainList = (ready.length ? ready : drafts).map((r) => renderRunItem(r, activePath)).join("");
const draftOpen = drafts.some((r) => r.path === activePath) ? " open" : "";
const draftHtml =
ready.length && drafts.length
? `
未完成草稿(${drafts.length})
${drafts.map((r) => renderRunItem(r, activePath)).join("")}
`
: "";
return `${mainList}${draftHtml}
`;
}
function hasNarrationContent(R) {
const V = R.views.narration;
return V.status === "ok" && V.segments && V.segments.length > 0;
}
function hasCutContent(R) {
const V = R.views.cut;
return (V.status === "ok" && V.clips && V.clips.length > 0) || Boolean(R.storyboards && R.storyboards.length > 0);
}
function pickPanelTab(R, requested) {
const hasNarr = hasNarrationContent(R) || R.views.narration.status === "unparseable";
const hasCut = hasCutContent(R) || R.views.cut.status === "unparseable";
if (requested === "cut" && hasCut) return "cut";
if (requested === "narration" && hasNarr) return "narration";
if (hasNarr) return "narration";
if (hasCut) return "cut";
return "narration";
}
function renderVideoStage(R) {
const finalMedia = R.views.film.video;
const cutMedia = R.views.cut.video;
const hasFinal = Boolean(finalMedia && finalMedia.path);
const hasCut = Boolean(cutMedia && cutMedia.path);
const activeMedia = hasFinal ? finalMedia : hasCut ? cutMedia : null;
if (!activeMedia) {
const msg =
finalMedia && finalMedia.note
? finalMedia.note
: R.next_pause
? `当前进度:${R.next_pause.hint}`
: "该目录尚未生成可播放的视频文件。";
return ``;
}
return ``;
}
function renderScriptList(R) {
const V = R.views.narration;
if (V.status === "unparseable") return `${notice(`解说词文件无法读取:${V.error}`)}
`;
if (!V.segments || !V.segments.length) {
return `${empty("暂无解说词", R.audio_mode === "source-mix" ? "本片为纯原声剪辑,不包含旁白解说。" : "尚未生成解说词。")}
`;
}
return `${V.segments
.map(
(seg) => `
${clock(seg.start)}
${esc(seg.text)}
`
)
.join("")}
`;
}
function cleanClipReason(raw) {
if (!raw) return "";
const tokens = String(raw)
.split(/\s*\|\s*|\s+·\s+/)
.map((s) => s.trim())
.filter(Boolean);
const cleaned = tokens
.filter((s) => !/^(?:[a-zA-Z]?\d+|cold_open|setup|turn|climax|payoff|hook|bridge|ending|escalation|aftermath)$/i.test(s))
.filter((s) => !/^(?:POV|视角|入点|出点|in|out)\s*[:=:]/i.test(s))
.map((s) => s.replace(/^[a-zA-Z0-9_-]+\s*:\s*/, "").trim())
.filter(Boolean);
return (cleaned.length ? cleaned : tokens).join(" · ");
}
function renderShotList(R) {
const V = R.views.cut;
const storyboards = R.storyboards || [];
const sbHtml = storyboards.length
? `
画面缩略一览
${storyboards
.map(
(sb) => `
`
)
.join("")}
`
: "";
if (V.status === "unparseable") return `${notice(`剪辑镜头文件无法读取:${V.error}`)}
${sbHtml}`;
if (V.status !== "ok" || !V.clips || !V.clips.length) {
return sbHtml || `${empty("整段原片", "本片保留原视频完整连续画面,未做拆镜剪辑。")}
`;
}
const rows = V.clips
.map((clip, idx) => {
const text = cleanClipReason(clip.reason);
const order = String(idx + 1).padStart(2, "0");
return `
${order}
${clock(clip.output_start)} – ${clock(clip.output_end)}
${text ? `
${esc(text)}
` : ""}
`;
})
.join("");
return `${rows}
${sbHtml}`;
}
function renderSidePanel(R, activeTab) {
const hasNarr = hasNarrationContent(R) || R.views.narration.status === "unparseable";
const hasCut = hasCutContent(R) || R.views.cut.status === "unparseable";
if (hasNarr && hasCut) {
const tab = activeTab === "cut" ? "cut" : "narration";
const head = ``;
return `${head}${tab === "cut" ? renderShotList(R) : renderScriptList(R)}
`;
}
if (hasCut && !hasNarr) {
return `镜头
${renderShotList(R)}
`;
}
return `解说词
${renderScriptList(R)}
`;
}
function collectRunError(R) {
if (R.state_error) return R.state_error;
const failedQc = (R.qc || []).filter((c) => c.level === "error");
if (failedQc.length) {
const details = failedQc
.flatMap((c) => {
const blockers = (c.findings || []).filter((f) => f && f.blocking !== false);
return blockers.length ? blockers.map((f) => f.message) : [c.text];
})
.filter(Boolean);
return details.join(";") || "成片存在未通过的检查项";
}
return "";
}
function renderPromoCopy(R) {
const promo = R.views.film && R.views.film.promo_copy;
if (!promo || typeof promo !== "object" || promo.status === "missing" || promo.status === "unparseable") {
return "";
}
const coreAngle = typeof promo.core_angle === "string" ? promo.core_angle.trim() : "";
const payoffTs = typeof promo.payoff_timestamp === "number" && Number.isFinite(promo.payoff_timestamp)
? promo.payoff_timestamp
: null;
const titles = Array.isArray(promo.titles) ? promo.titles : [];
const cover = promo.cover && typeof promo.cover === "object"
? promo.cover
: typeof promo.cover === "string" && promo.cover.trim()
? { text: promo.cover.trim() }
: null;
const desc = typeof promo.description === "string" ? promo.description.trim() : "";
const tags = Array.isArray(promo.tags) ? promo.tags.filter((t) => typeof t === "string" && t.trim()) : [];
const titleItems = titles
.map((item) => {
if (typeof item === "string" && item.trim()) {
return `${esc(item.trim())}
`;
}
if (item && typeof item === "object") {
const text = String(item.text || item.title || "").trim();
const label = String(item.label || item.type || item.platform || "").trim();
if (!text) return "";
return `${label ? `${esc(label)}` : ""}${esc(text)}
`;
}
return "";
})
.filter(Boolean);
let coverHtml = "";
if (cover) {
const coverLines = [cover.top_line, cover.bottom_line, cover.text]
.filter((s) => typeof s === "string" && s.trim())
.map((s) => esc(s.trim()));
const coverTs = typeof cover.timestamp === "number" && Number.isFinite(cover.timestamp) ? cover.timestamp : null;
const coverReason = typeof cover.frame_reason === "string" && cover.frame_reason.trim() ? esc(cover.frame_reason.trim()) : "";
const metaBits = [
coverTs !== null ? `封面帧 ${clock(coverTs)}` : "",
coverReason,
].filter(Boolean);
if (coverLines.length || metaBits.length) {
coverHtml = `
封面方案
${coverLines.length ? `
${coverLines.join(" / ")}
` : ""}
${metaBits.length ? `
${metaBits.join(" · ")}
` : ""}
`;
}
}
if (!coreAngle && payoffTs === null && !titleItems.length && !coverHtml && !desc && !tags.length) {
return "";
}
return `
宣发文案
${payoffTs !== null ? `` : ""}
${coreAngle ? `${esc(coreAngle)}
` : ""}
${titleItems.length ? `备选标题
${titleItems.join("")}
` : ""}
${coverHtml}
${desc ? `` : ""}
${tags.length ? `${tags.map((t) => `#${esc(t.trim().replace(/^#+/, ""))}`).join("")}
` : ""}
`;
}
function viewStudio(O, R, route) {
const activeTab = pickPanelTab(R, route.view);
const hasFinal = Boolean(R.views.film.video && R.views.film.video.path);
const hasCut = Boolean(R.views.cut.video && R.views.cut.video.path);
const switcher =
hasFinal && hasCut
? `
`
: "";
const errorBanner = collectRunError(R);
const promoCard = renderPromoCopy(R);
return `
${esc(R.title || R.name)}
${switcher}
${errorBanner ? notice(errorBanner) : ""}
${renderVideoStage(R)}
${renderSidePanel(R, activeTab)}
${promoCard}
`;
}
/* =========================================================== 2. 素材库 */
const boxCss = (b) => `left:${b.left}%;top:${b.top}%;width:${b.width}%;height:${b.height}%`;
function renderMiniPreview(tpl) {
const P = tpl.preview;
if (!P) return "";
const ratio = `aspect-ratio:${num(P.canvas.width)} / ${num(P.canvas.height)}`;
if (P.type === "subtitle_style") {
const L = P.line;
const lineCss = [
`bottom:${L.bottom ?? 4}%`,
L.font_size ? `font-size:${L.font_size}cqw` : "",
L.color ? `--line-c:${L.color}` : "",
]
.filter(Boolean)
.join(";");
return `
${P.band ? `` : ""}
${L.font_size ? `${esc(L.text)}` : ""}
`;
}
const studioVp =
P.studio && P.studio.viewport
? `主画面视窗`
: "";
const layers = (P.layers || [])
.map((layer) =>
layer.box
? layer.media
? `
`
: `${esc(layer.name)}`
: ""
)
.join("");
const cls = P.studio ? `mini studio-mini ${P.studio.backdrop === "blurred_frame" ? "blurred" : ""}` : "mini pkg";
return `${studioVp}${layers}
`;
}
function renderFilterChips(libPath, tabKey, groups, activeCat) {
if (groups.length <= 1) return "";
const allChip = `全部${groups.reduce((n, g) => n + g.items.length, 0)}`;
const chips = groups
.map(
(g) =>
`${esc(g.label)}${g.items.length}`
)
.join("");
return `${allChip}${chips}
`;
}
function groupItems(items, keyFn, labelFn) {
const map = new Map();
for (const item of items) {
const key = keyFn(item) || "default";
if (!map.has(key)) map.set(key, { key, label: labelFn(key, item), items: [] });
map.get(key).items.push(item);
}
return Array.from(map.values());
}
function renderGroupedSections(groups, activeCat, cardFn, gridClass = "res-grid") {
const shown = activeCat ? groups.filter((g) => g.key === activeCat) : groups;
if (!shown.length) return empty("暂无匹配条目", "切换上方分类查看其他素材。");
if (shown.length === 1 && groups.length === 1) {
return `${shown[0].items.map(cardFn).join("")}
`;
}
return `${shown
.map(
(g) => `
${esc(g.label)}
${g.items.length}
${g.items.map(cardFn).join("")}
`
)
.join("")}
`;
}
function renderAudioPreview(res) {
const mediaFile = (res.files || []).find((f) => f.media && f.media.path && f.media.kind === "audio");
if (!mediaFile) return "";
return ``;
}
function renderBgmCard(res) {
const vocalBadge =
res.has_vocal === false
? '纯音乐'
: res.has_vocal === true
? '含人声'
: `${esc(catLabel(res.category, "配乐"))}`;
const dur = res.measured && Number.isFinite(res.measured.duration_sec) ? clock(res.measured.duration_sec) : "";
const bpm = Number.isFinite(res.bpm) ? `${Math.round(res.bpm)} BPM` : "";
const lufs =
res.measured && Number.isFinite(res.measured.lufs_i) ? `${res.measured.lufs_i.toFixed(1)} LUFS` : "";
const metaParts = [dur, bpm, lufs].filter(Boolean).join(" · ");
const chips = [...(res.moods || []), ...(res.scene_fit || []), ...(res.tags || [])].slice(0, 4);
return `
${esc(res.title)}
${vocalBadge}
${metaParts ? `${esc(metaParts)}
` : ""}
${chips.length ? `${chips.map((c) => `${esc(c)}`).join("")}
` : ""}
${res.notes ? `${esc(res.notes)}
` : ""}
${renderAudioPreview(res)}
`;
}
function renderSfxCard(res) {
const peak = Number.isFinite(res.peak_offset_ms) ? `瞬态峰值 ${Math.round(res.peak_offset_ms)}ms` : "";
const dur =
res.measured && Number.isFinite(res.measured.duration_sec) ? `${res.measured.duration_sec.toFixed(2)}s` : "";
const metaParts = [res.tone, dur, peak].filter(Boolean).join(" · ");
const chips = [...(res.scene_fit || []), ...(res.tags || [])].slice(0, 3);
return `
${esc(res.title)}
${esc(catLabel(res.category, "音效"))}
${metaParts ? `${esc(metaParts)}
` : ""}
${chips.length ? `${chips.map((c) => `${esc(c)}`).join("")}
` : ""}
${res.notes ? `${esc(res.notes)}
` : ""}
${renderAudioPreview(res)}
`;
}
function renderVoiceCard(res) {
const provider = res.voice && res.voice.provider ? PROVIDER_LABEL[res.voice.provider] || res.voice.provider : "语音合成";
const speed = Number.isFinite(res.recommended_speed) ? `推荐 ${res.recommended_speed}x` : "";
const metaParts = [provider, res.persona || res.gender, speed].filter(Boolean).join(" · ");
const chips = [...(res.scene_fit || []), ...(res.tags || [])].slice(0, 4);
const audio = renderAudioPreview(res);
return `
${esc(res.title)}
${esc(catLabel(res.category, "解说音色"))}
${metaParts ? `${esc(metaParts)}
` : ""}
${chips.length ? `${chips.map((c) => `${esc(c)}`).join("")}
` : ""}
${res.notes ? `${esc(res.notes)}
` : ""}
${audio || '云端预置音色(无需本地参考音频)
'}
`;
}
function renderAssetCard(res) {
const mediaFile = (res.files || []).find((f) => f.media && f.media.path);
let preview = "";
if (mediaFile && mediaFile.media.kind === "image") {
const src = mediaUrl(mediaFile.media.path);
preview = ``;
}
const chips = (res.tags || []).slice(0, 4);
return `
${esc(res.title)}
${esc(KIND_LABEL[res.kind] || res.kind)}
${chips.length ? `${chips.map((c) => `${esc(c)}`).join("")}
` : ""}
${res.notes ? `${esc(res.notes)}
` : ""}
${preview}
`;
}
function renderTemplateCard(tpl) {
const mini = renderMiniPreview(tpl);
const canvasText = tpl.canvas ? `${tpl.canvas.width}×${tpl.canvas.height}` : "";
const summary = [
canvasText,
...(tpl.rows || []).slice(0, 3).map((r) => `${r.label} ${r.value}${r.unit ? r.unit : ""}`),
]
.filter(Boolean)
.join(" · ");
return `
${mini ? `${mini}
` : ""}
${esc(tpl.title || tpl.id)}
${esc(KIND_LABEL[tpl.kind] || tpl.kind)}
${summary ? `
${esc(summary)}
` : ""}
${tpl.notes ? `
${esc(tpl.notes)}
` : ""}
`;
}
function renderSampleCard(sample) {
if (!sample.file || !sample.file.path) {
return `
${esc(sample.title)}
参考样片
${sample.demonstrates && sample.demonstrates.length ? `参考点:${esc(sample.demonstrates.join("、"))}
` : ""}
`;
}
return `
${esc(sample.title)}
参考样片
${sample.demonstrates && sample.demonstrates.length ? `
${sample.demonstrates.map((d) => `${esc(d)}`).join("")}
` : ""}
${sample.not_reusable ? `
边界说明:${esc(sample.not_reusable)}
` : ""}
`;
}
function renderEpisodeRow(ep) {
const dur = Number.isFinite(ep.duration_sec) ? clock(ep.duration_sec) : "";
const stats = [dur, ep.resolution].filter(Boolean).join(" · ");
const badge = ep.ep_no ? `E${String(ep.ep_no).padStart(2, "0")}` : "单集";
return `
${esc(badge)}
${esc(ep.episode_title)}
${stats ? `${esc(stats)}` : ""}
${esc(ep.synopsis)}
`;
}
function renderSeriesCard(series) {
const tags = [series.era, series.genre, `${series.episode_count} 集`].filter(Boolean);
const chars = (series.characters || []).slice(0, 6);
return `
${esc(series.title)}
${tags.map((t) => `${esc(t)}`).join("")}
${series.synopsis ? `
${esc(series.synopsis)}
` : ""}
${chars.length ? `
主要人物:${chars.map((c) => `${esc(c)}`).join("")}
` : ""}
${series.episodes.map(renderEpisodeRow).join("")}
`;
}
function renderMaterialsView(L, activeCat) {
const M = L.materials || { series: [], standalone: [] };
const groups = [];
for (const s of M.series || []) {
groups.push({ key: s.series_id, label: s.title, items: s.episodes, series: s });
}
if (M.standalone && M.standalone.length) {
groups.push({ key: "standalone", label: "单集原片", items: M.standalone, standalone: true });
}
const chips = renderFilterChips(L.path, "materials", groups, activeCat);
const shown = activeCat ? groups.filter((g) => g.key === activeCat) : groups;
const cards = shown
.map((g) =>
g.series
? renderSeriesCard(g.series)
: `
单集原片
${g.items.map(renderEpisodeRow).join("")}
`
)
.join("");
return `${chips}${cards}
`;
}
function renderStylesView(L, activeCat, targetId) {
const publicVisuals = (L.resources || []).filter(
(r) =>
(r.kind === "font" || r.kind === "image") &&
(r.visibility !== "internal" || r.id === targetId)
);
const portraitTpls = (L.templates || []).filter(
(t) => t.kind !== "production_reference" && t.canvas && t.canvas.height > t.canvas.width
);
const landscapeTpls = (L.templates || []).filter(
(t) => t.kind !== "production_reference" && (!t.canvas || t.canvas.width >= t.canvas.height)
);
const refTpls = (L.templates || []).filter((t) => t.kind === "production_reference");
const samples = L.samples || [];
const groups = [];
if (portraitTpls.length) groups.push({ key: "portrait", label: "竖屏样式 9:16", items: portraitTpls, type: "tpl" });
if (landscapeTpls.length) groups.push({ key: "landscape", label: "横屏样式 16:9", items: landscapeTpls, type: "tpl" });
if (refTpls.length) groups.push({ key: "reference", label: "剪辑方法参考", items: refTpls, type: "tpl" });
if (samples.length) groups.push({ key: "samples", label: "参考样片", items: samples, type: "sample" });
if (publicVisuals.length) groups.push({ key: "assets", label: "字体与图形资产", items: publicVisuals, type: "asset" });
const chips = renderFilterChips(L.path, "styles", groups, activeCat);
const shown = activeCat ? groups.filter((g) => g.key === activeCat) : groups;
const html = shown
.map((g) => {
const inner =
g.type === "sample"
? `${g.items.map(renderSampleCard).join("")}
`
: g.type === "asset"
? `${g.items.map(renderAssetCard).join("")}
`
: `${g.items.map(renderTemplateCard).join("")}
`;
return `
${esc(g.label)}
${g.items.length}
${inner}
`;
})
.join("");
return `${chips}${html}
`;
}
function resolveLibraryTab(L, sections, route) {
const targetId = route.q.get("id") || "";
const available = new Set(sections.map((s) => s.key));
if (targetId) {
const res = (L.resources || []).find((r) => r.id === targetId);
if (res) {
if ((res.kind === "bgm" || res.kind === "sfx" || res.kind === "voice") && available.has(res.kind)) {
return res.kind;
}
if (available.has("styles")) return "styles";
}
if ((L.templates || []).some((t) => t.ref === targetId) && available.has("styles")) return "styles";
if ((L.samples || []).some((s) => s.id === targetId) && available.has("styles")) return "styles";
const M = L.materials || { series: [], standalone: [] };
const inMat =
(M.standalone || []).some((e) => e.material_id === targetId) ||
(M.series || []).some((s) => (s.episodes || []).some((e) => e.material_id === targetId));
if (inMat && available.has("materials")) return "materials";
}
if (route.view === "templates" || route.view === "samples") {
if (available.has("styles")) return "styles";
}
if (route.view === "resources") {
for (const k of ["bgm", "sfx", "voice", "styles"]) {
if (available.has(k)) return k;
}
}
return available.has(route.view) ? route.view : sections[0].key;
}
function viewLibrary(O, L, route) {
const targetId = route.q.get("id") || "";
const activeCat = route.q.get("cat") || "";
const matCount = L.materials && L.materials.total_count ? L.materials.total_count : 0;
const bgmList = (L.resources || []).filter((r) => r.kind === "bgm" && (r.visibility !== "internal" || r.id === targetId));
const sfxList = (L.resources || []).filter((r) => r.kind === "sfx" && (r.visibility !== "internal" || r.id === targetId));
const voiceList = (L.resources || []).filter((r) => r.kind === "voice" && (r.visibility !== "internal" || r.id === targetId));
const visualAssets = (L.resources || []).filter(
(r) => (r.kind === "font" || r.kind === "image") && (r.visibility !== "internal" || r.id === targetId)
);
const styleCount = (L.templates || []).length + (L.samples || []).length + visualAssets.length;
const sections = [];
if (matCount > 0) sections.push({ key: "materials", label: "原片剧目", count: matCount });
if (bgmList.length) sections.push({ key: "bgm", label: "配乐", count: bgmList.length });
if (sfxList.length) sections.push({ key: "sfx", label: "音效", count: sfxList.length });
if (voiceList.length) sections.push({ key: "voice", label: "音色", count: voiceList.length });
if (styleCount > 0) sections.push({ key: "styles", label: "样式与样片", count: styleCount });
if (!sections.length) {
return `${empty("素材库为空", "尚未添加原片、配乐、音效、音色或样式模板。")}
`;
}
const active = resolveLibraryTab(L, sections, route);
const switcher =
sections.length > 1
? ``
: "";
let body = "";
if (active === "materials") {
body = renderMaterialsView(L, activeCat);
} else if (active === "bgm") {
const groups = groupItems(bgmList, (r) => r.category || "bgm", (k) => catLabel(k, "精选配乐"));
body = `${renderFilterChips(L.path, "bgm", groups, activeCat)}${renderGroupedSections(groups, activeCat, renderBgmCard)}`;
} else if (active === "sfx") {
const groups = groupItems(sfxList, (r) => r.category || "sfx", (k) => catLabel(k, "通用音效"));
body = `${renderFilterChips(L.path, "sfx", groups, activeCat)}${renderGroupedSections(groups, activeCat, renderSfxCard, "sfx-grid")}`;
} else if (active === "voice") {
const groups = groupItems(voiceList, (r) => r.category || "voice", (k) => catLabel(k, "解说音色"));
body = `${renderFilterChips(L.path, "voice", groups, activeCat)}${renderGroupedSections(groups, activeCat, renderVoiceCard)}`;
} else {
body = renderStylesView(L, activeCat, targetId);
}
return `
${esc(L.name)}
${switcher}
${L.error ? notice(`library.json ${L.error}`) : ""}
${body}
`;
}