Files
aigc-home/calliope-web/src/lib/components/video/ClipMonitor.svelte
T
happymy be0f5b6046 feat(i18n): 全量中英双语字典与组件接入
- en.ts 934 键无重复,zh.ts 全量镜像
- 补齐 assets/buildScene/queue 缺失键,修正 promptPreview.sceneMeta/shotMeta 占位符
- i18n.svelte.ts 修复 \ 响应式语言状态
- 修复 QueueStage/ToastHost 局部变量遮蔽 t()
2026-09-12 13:00:19 +08:00

279 lines
5.8 KiB
Svelte

<script lang="ts">
/**
* ClipMonitor — 16:9 hero preview for a scene clip.
* Letterboxes video; shows slate / progress / error when no preview.
*/
import { assetUrl } from '$lib/api';
import SafeMedia from '$lib/components/SafeMedia.svelte';
import Button from '$lib/components/ui/Button.svelte';
import Icon from '$lib/components/ui/Icon.svelte';
import ProgressBar from '$lib/components/ui/ProgressBar.svelte';
import Spinner from '$lib/components/ui/Spinner.svelte';
import { t } from '$lib/i18n.svelte';
interface Progress {
progress?: number;
message?: string;
}
interface Props {
previewPath: string | null;
status: string;
heading: string;
orderIndex: number;
/** Display label, e.g. '#3.2' — shown on the slate + id strip instead of the plain index. */
label?: string;
/** Secondary id line, e.g. 'clip 512'. */
idLabel?: string;
sceneId?: number;
progress?: Progress | null;
error?: string;
errorLong?: boolean;
}
let {
previewPath,
status,
heading,
orderIndex,
label,
idLabel,
sceneId,
progress = null,
error = '',
errorLong = false,
}: Props = $props();
let errorOpen = $state(false);
// '#t=0.1' media fragment: with preload="metadata" browsers paint NOTHING
// until playback, so every clip preview sat black ("no picture, but sound").
// The fragment makes the browser seek+paint a first frame without playing.
const previewUrl = $derived(previewPath ? assetUrl(previewPath) + '#t=0.1' : null);
$effect(() => {
void previewPath;
void error;
errorOpen = false;
});
</script>
<div class="monitor">
<div class="frame">
{#if previewUrl}
<SafeMedia class="media" src={previewUrl} kind="video" label={t('clipMonitor.videoUnavailable')} />
{:else}
<div class="empty">
<span class="slate">{label ?? `#${orderIndex}`}</span>
{#if idLabel}
<p class="sid">{idLabel}</p>
{:else if sceneId != null}
<p class="sid">{t('clipMonitor.sceneId', { id: sceneId })}</p>
{/if}
<p class="title">{heading || t('clipMonitor.untitled')}</p>
{#if status === 'pending' || status === 'running'}
<div class="busy" aria-busy="true">
<div class="busy-head">
<Spinner size="sm" />
<span>{status === 'running' ? t('clipMonitor.generating') : t('clipMonitor.queued')}</span>
</div>
{#if status === 'running'}
<ProgressBar
size="sm"
value={progress?.progress ?? 0}
indeterminate={progress == null}
label={progress?.message}
/>
{/if}
</div>
{:else if status === 'failed'}
<div class="fail">
<p class="err" class:open={errorOpen}>{error || t('clipMonitor.generationFailed')}</p>
{#if errorLong}
<Button variant="ghost" size="sm" onclick={() => (errorOpen = !errorOpen)}>
{errorOpen ? t('clipMonitor.hideDetails') : t('clipMonitor.showDetails')}
</Button>
{/if}
</div>
{:else}
<p class="hint">{t('clipMonitor.noRenderHint')}</p>
{/if}
</div>
{/if}
</div>
<div class="ids">
<span>{label ?? `#${orderIndex}`}</span>
{#if idLabel}
<span class="ids-db">{idLabel}</span>
{:else if sceneId != null}
<span class="ids-db">{t('clipMonitor.id', { id: sceneId })}</span>
{/if}
</div>
{#if previewUrl}
<div class="foot">
<a class="dl" href={previewUrl} download>
<Icon name="download" size={14} /> {t('clipMonitor.downloadClip')}
</a>
</div>
{/if}
</div>
<style>
.monitor {
display: flex;
flex-direction: column;
width: 100%;
height: 100%;
min-height: 0;
}
.frame {
flex: 1;
min-height: 0;
width: 100%;
height: 100%;
background:
radial-gradient(ellipse at center, rgba(139, 92, 246, 0.08), transparent 55%),
#050508;
border: 1px solid var(--border);
border-radius: var(--radius-md);
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
}
.frame :global(.media) {
width: 100%;
height: 100%;
object-fit: contain;
background: #000;
border: none;
border-radius: 0;
min-height: 0;
}
.empty {
padding: 24px;
text-align: center;
max-width: 42ch;
}
.slate {
display: inline-block;
font-family: var(--font-mono);
font-size: 22px;
font-weight: 700;
color: var(--accent);
margin-bottom: 6px;
}
.sid {
margin: 0 0 8px;
font-family: var(--font-mono);
font-size: 11px;
font-weight: 600;
letter-spacing: 0.04em;
color: var(--text-muted);
}
.title {
margin: 0 0 8px;
font-size: 14px;
font-weight: 600;
color: var(--text-primary);
}
.hint {
margin: 0;
font-size: 13px;
color: var(--text-muted);
line-height: 1.45;
}
.busy {
margin-top: 12px;
display: flex;
flex-direction: column;
gap: 8px;
text-align: left;
}
.busy-head {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
font-size: 13px;
font-weight: 600;
color: var(--warning);
}
.fail {
margin-top: 8px;
display: flex;
flex-direction: column;
align-items: center;
gap: 4px;
}
.err {
margin: 0;
font-size: 13px;
font-weight: 600;
color: var(--error);
display: -webkit-box;
-webkit-line-clamp: 3;
line-clamp: 3;
-webkit-box-orient: vertical;
overflow: hidden;
word-break: break-word;
white-space: pre-wrap;
}
.err.open {
display: block;
overflow: visible;
max-height: 160px;
overflow-y: auto;
}
.ids {
display: flex;
align-items: center;
gap: 10px;
padding: 6px 2px 0;
font-family: var(--font-mono);
font-size: 12px;
font-weight: 700;
color: var(--accent);
flex-shrink: 0;
}
.ids-db {
font-weight: 600;
color: var(--text-muted);
}
.foot {
display: flex;
justify-content: flex-end;
padding-top: 8px;
flex-shrink: 0;
}
.dl {
display: inline-flex;
align-items: center;
gap: 6px;
font-size: 12px;
font-weight: 600;
color: var(--text-secondary);
text-decoration: none;
}
.dl:hover {
color: var(--accent);
}
</style>