Files
aigc-home/calliope-web/src/lib/components/shell/AppShell.svelte
T
8b03291327 HEL-652: B 批导航壳层——60px 图标轨、顶栏与手机底栏
- 216px 文字侧栏改为 60px 图标轨:金色渐变 Logo、当前页金色指示条滑动、350ms 延迟悬停提示,底部连接/模型/设置/语言
- 顶栏:标题+副标题、项目范围胶囊(全部项目列表/最近项目)、Ctrl/⌘K 搜索、减少动态开关、任务托盘胶囊、本次连接胶囊(名称+延迟)
- ≤760px:隐藏图标轨,底部 项目/创作/生成/更多 四个标签,更多为底部抽屉(其余页面、搜索、减少动态、语言);删除「手机端暂不适配」拦截
- 新增 ShellPop(Esc/↑↓/Tab 循环/外部点击关闭、焦点归还)与 CommandPalette(复用 Modal)
- 减少动态:跟随系统设置,另可手动开启并持久化(data-reduce)
- .a-darkroom 背景接入 --page-glow;新增壳层尺寸 token 与 .a-kbd/.a-menu-* 公共类
- 生图/生视频顶栏去掉与全局胶囊重复的连接状态(参数栏仍显示所选连接与队列)
- 路由 URL 不变(/projects 仍重定向到项目总览 /)

Co-authored-by: multica-agent <github@multica.ai>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-30 09:26:36 +08:00

768 lines
19 KiB
Svelte
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script module lang="ts">
// Survives page changes so the rail indicator can slide from the last page.
let lastIndicatorY: number | null = null;
</script>
<script lang="ts">
import { onMount } from 'svelte';
import { createQuery } from '@tanstack/svelte-query';
import { toStore } from 'svelte/store';
import { page } from '$app/state';
import LanguageSwitcher from '$lib/components/LanguageSwitcher.svelte';
import Icon from '$lib/components/ui/Icon.svelte';
import Switch from '$lib/components/ui/Switch.svelte';
import { settings, jobsApi, comfy } from '$lib/api';
import { language, t } from '$lib/i18n.svelte';
import { reduceMotion, setReduceMotion } from '$lib/reduceMotion.svelte';
import CommandPalette from './CommandPalette.svelte';
import ProjectScope from './ProjectScope.svelte';
import QueueTray from './QueueTray.svelte';
import ShellPop from './ShellPop.svelte';
import { MORE_ITEMS, NAV_FOOT, NAV_MAIN, TABS, type NavId, type NavItem } from './nav';
/**
* 融合壳层 — HEL-649 §二: 60px icon rail (Logo, nav, connection + settings
* at the foot), a top bar with the project scope capsule, search (Ctrl/⌘K),
* queue and connection capsules, and at ≤760px a bottom tab bar
* (项目 / 创作 / 生成 / 更多) instead of the rail.
*/
interface Props {
active: NavId;
title: string;
subtitle?: string;
/** Page-level actions rendered in the top bar (chips / buttons). */
actions?: import('svelte').Snippet;
children?: import('svelte').Snippet;
}
let { active, title, subtitle, actions, children }: Props = $props();
const LANG_MARK: Record<string, string> = {
zh: '中',
en: 'EN',
de: 'DE',
es: 'ES',
fr: 'FR',
ja: '日',
ko: '한',
};
let paletteOpen = $state(false);
let moreOpen = $state(false);
// Real ComfyUI connections from settings — shown honestly without a
// fake "connected" claim; tested state lives on /connections (a6).
const settingsQuery = createQuery({
queryKey: ['settings'],
queryFn: settings.get,
staleTime: 60_000,
});
// Queue capsule / tray: the same image + video jobs the task page lists.
// Polled lightly; SSE-driven pages keep their own faster cadence.
const activeJobsQuery = createQuery({
queryKey: ['jobs', 'active-count'],
queryFn: () => jobsApi.list(),
refetchInterval: 8_000,
staleTime: 5_000,
});
const genJobs = $derived(
($activeJobsQuery.data ?? []).filter((j) => j.kind === 'image' || j.kind === 'video'),
);
const activeJobs = $derived(
genJobs.filter((j) => j.status === 'pending' || j.status === 'running').length,
);
// The ACTIVE ComfyUI connection (HEL-611). Its status dot comes from a
// real server-side probe (GET /system_stats from the workbench server,
// §3) — cyan only when that probe passes.
const activeEndpoint = $derived.by(() => {
const s = $settingsQuery.data;
if (!s) return null;
return s.comfyui_endpoints?.find((ep) => ep.id === s.comfyui_active_id) ?? null;
});
const comfyUrl = $derived.by(() => {
const raw = (activeEndpoint?.base_url ?? $settingsQuery.data?.comfyui_base_url ?? '').trim();
if (!raw) return '';
try {
const u = new URL(raw.includes('://') ? raw : `http://${raw}`);
return u.host;
} catch {
return raw;
}
});
const activeId = $derived(activeEndpoint?.id ?? null);
const probeQuery = createQuery(
toStore(() => ({
queryKey: ['comfy-probe', activeId],
queryFn: () => comfy.testEndpoint({ endpoint_id: activeId ?? undefined, timeout_sec: 5 }),
enabled: activeId != null,
staleTime: 60_000,
refetchInterval: 60_000,
retry: false,
})),
);
const probeState = $derived.by<'unset' | 'testing' | 'ok' | 'fail'>(() => {
if (!activeEndpoint) return 'unset';
if ($probeQuery.isPending) return 'testing';
if ($probeQuery.isError) return 'fail';
return $probeQuery.data?.ok ? 'ok' : 'fail';
});
const endpointName = $derived(activeEndpoint?.name?.trim() || 'ComfyUI');
const latencyMs = $derived(
probeState === 'ok' && $probeQuery.data?.elapsed_ms != null
? Math.round($probeQuery.data.elapsed_ms)
: null,
);
const connDetail = $derived.by(() => {
if (probeState === 'unset') return t('shell.comfyUnset');
const state = t(`shell.comfy_${probeState}`, { name: endpointName });
if (probeState === 'fail' && $probeQuery.data?.message) return `${state}:${$probeQuery.data.message}`;
return comfyUrl ? `${state} · ${comfyUrl}` : state;
});
const connDot = $derived(
probeState === 'ok' || probeState === 'testing' ? 'run' : probeState === 'fail' ? 'fail' : 'idle',
);
// 范围胶囊: the project a page belongs to, read from its URL.
const scopeProjectId = $derived.by(() => {
const m = page.url.pathname.match(/^\/(?:workbench|project)\/(\d+)/);
return m ? Number(m[1]) : null;
});
const moreActive = $derived(MORE_ITEMS.some((item) => item.id === active));
function isCurrent(item: NavItem) {
return item.id === active;
}
function openPalette() {
moreOpen = false;
paletteOpen = true;
}
function handleGlobalKeydown(event: KeyboardEvent) {
if ((event.ctrlKey || event.metaKey) && !event.altKey && event.key.toLowerCase() === 'k') {
event.preventDefault();
moreOpen = false;
paletteOpen = !paletteOpen;
}
}
// 当前页指示条:在图标之间滑动 (--d-pop),首次出现不做动画.
let rail = $state<HTMLElement | null>(null);
let indicatorY = $state<number | null>(null);
let indicatorInstant = $state(true);
function measureIndicator(): number | null {
const el = rail?.querySelector<HTMLElement>('.rail-btn[aria-current="page"]');
if (!el || !el.offsetHeight) return null;
return el.offsetTop + (el.offsetHeight - 20) / 2;
}
onMount(() => {
const target = measureIndicator();
if (target != null && lastIndicatorY != null && lastIndicatorY !== target) {
indicatorY = lastIndicatorY;
requestAnimationFrame(() =>
requestAnimationFrame(() => {
indicatorInstant = false;
indicatorY = target;
}),
);
} else {
indicatorY = target;
}
if (target != null) lastIndicatorY = target;
const onResize = () => {
indicatorInstant = true;
const y = measureIndicator();
if (y == null) return;
indicatorY = y;
lastIndicatorY = y;
};
window.addEventListener('resize', onResize);
return () => window.removeEventListener('resize', onResize);
});
</script>
<svelte:head>
<title>{title} · {t('shell.brand')}</title>
</svelte:head>
<svelte:window onkeydown={handleGlobalKeydown} />
{#snippet railLink(item: NavItem)}
<a
class="rail-btn"
href={item.href}
aria-current={isCurrent(item) ? 'page' : undefined}
aria-label={item.id === 'connections'
? `${t(item.labelKey)} · ${connDetail}`
: t(item.labelKey)}
>
<Icon name={item.icon} size={20} />
{#if item.id === 'tasks' && activeJobs > 0}
<span class="rail-dot run" aria-hidden="true"></span>
{:else if item.id === 'connections'}
<span class="rail-dot {connDot}" class:testing={probeState === 'testing'} aria-hidden="true"
></span>
{/if}
<span class="tip" aria-hidden="true">
{t(item.labelKey)}{#if item.id === 'connections'}<span class="tip-sub">{connDetail}</span>{/if}
</span>
</a>
{/snippet}
<div class="a-shell a-darkroom">
<div class="shell-frame">
<nav class="rail" aria-label={t('shell.navAria')} bind:this={rail}>
<a class="logo" href="/" aria-label={t('shell.brandHome')} title={t('shell.brand')}>
{t('shell.brandMark')}
</a>
<span
class="rail-ind"
class:on={indicatorY != null}
class:instant={indicatorInstant}
style:--y="{indicatorY ?? 0}px"
aria-hidden="true"
></span>
{#each NAV_MAIN as item (item.id)}
{@render railLink(item)}
{/each}
<div class="rail-spacer"></div>
{#each NAV_FOOT as item (item.id)}
{@render railLink(item)}
{/each}
<div class="rail-btn rail-lang">
<span class="lang-mark" aria-hidden="true">{LANG_MARK[language.current] ?? 'EN'}</span>
<LanguageSwitcher />
<span class="tip" aria-hidden="true">{t('common.language')}</span>
</div>
</nav>
<div class="main">
<header class="topbar">
<div class="crumb">
<h1>{title}</h1>
{#if subtitle}<p class="sub">{subtitle}</p>{/if}
</div>
<ProjectScope projectId={scopeProjectId} onProjectsList={page.url.pathname === '/'} />
<div class="grow"></div>
{#if actions}
<div class="topbar-actions">
{@render actions()}
</div>
{/if}
<div class="topbar-global">
<label
class="reduce hide-sm"
title={reduceMotion.system ? t('shell.reduceSystem') : t('shell.reduceHint')}
>
<Switch
checked={reduceMotion.system || reduceMotion.manual}
disabled={reduceMotion.system}
label={t('shell.reduceMotion')}
onchange={setReduceMotion}
/>
<span class="reduce-label">{t('shell.reduceMotion')}</span>
</label>
<button
type="button"
class="status-chip search-btn"
aria-haspopup="dialog"
aria-keyshortcuts="Control+K Meta+K"
aria-label={t('shell.searchTitle')}
title={t('shell.searchShortcut')}
onclick={openPalette}
>
<Icon name="search" size={14} />
<span class="search-label">{t('shell.searchPlaceholder')}</span>
<span class="a-kbd search-kbd">Ctrl K</span>
</button>
<QueueTray jobs={genJobs} />
<a class="status-chip conn-btn" href="/connections" title={connDetail} aria-label={connDetail}>
<span
class="status-chip-dot {connDot}"
class:testing={probeState === 'testing'}
aria-hidden="true"
></span>
<span class="conn-name">{probeState === 'unset' ? t('shell.comfyUnset') : endpointName}</span>
{#if latencyMs != null}<span class="conn-ms mono">· {latencyMs} ms</span>{/if}
</a>
</div>
</header>
<div class="body">
{@render children?.()}
</div>
<nav class="tabbar" aria-label={t('shell.tabAria')}>
{#each TABS as tab (tab.id)}
<a
class="tab"
href={tab.href}
aria-current={tab.covers.includes(active) ? 'page' : undefined}
>
<Icon name={tab.icon} size={20} />
<span>{t(tab.labelKey)}</span>
</a>
{/each}
<div class="tab-more">
<button
type="button"
class="tab"
aria-haspopup="dialog"
aria-expanded={moreOpen}
aria-current={moreActive ? 'page' : undefined}
onclick={() => (moreOpen = !moreOpen)}
>
<Icon name="queue" size={20} />
<span>{t('shell.tabMore')}</span>
{#if activeJobs > 0}<span class="rail-dot run tab-dot" aria-hidden="true"></span>{/if}
</button>
<ShellPop bind:open={moreOpen} label={t('shell.tabMore')}>
<div class="a-menu-group">{t('shell.morePages')}</div>
{#each MORE_ITEMS as item (item.id)}
<a
class="a-menu-item"
href={item.href}
aria-current={isCurrent(item) ? 'page' : undefined}
onclick={() => (moreOpen = false)}
>
<Icon name={item.icon} size={17} />
<span class="a-menu-label">{t(item.labelKey)}</span>
{#if item.id === 'tasks' && activeJobs > 0}
<span class="a-menu-meta">{t('shell.queueActive', { n: activeJobs })}</span>
{:else if item.id === 'connections'}
<span class="a-menu-meta">{connDetail}</span>
{/if}
</a>
{/each}
<div class="a-menu-group">{t('shell.moreTools')}</div>
<button type="button" class="a-menu-item" onclick={openPalette}>
<Icon name="search" size={17} />
<span class="a-menu-label">{t('shell.searchTitle')}</span>
</button>
<label
class="a-menu-item"
title={reduceMotion.system ? t('shell.reduceSystem') : t('shell.reduceHint')}
>
<Icon name="pause" size={17} />
<span class="a-menu-label">{t('shell.reduceMotion')}</span>
<Switch
checked={reduceMotion.system || reduceMotion.manual}
disabled={reduceMotion.system}
label={t('shell.reduceMotion')}
onchange={setReduceMotion}
/>
</label>
<div class="a-menu-item more-lang">
<span class="lang-mark" aria-hidden="true">{LANG_MARK[language.current] ?? 'EN'}</span>
<span class="a-menu-label">{t('common.language')}</span>
<LanguageSwitcher />
</div>
</ShellPop>
</div>
</nav>
</div>
</div>
</div>
<CommandPalette bind:open={paletteOpen} />
<style>
.a-shell {
position: fixed;
inset: 0;
}
.shell-frame {
height: 100%;
display: grid;
grid-template-columns: var(--rail-w) minmax(0, 1fr);
}
/* ---------------- 60px 图标轨 (§二) ---------------- */
.rail {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
gap: var(--sp-1);
padding: var(--sp-5) 0;
border-right: 1px solid var(--line);
box-sizing: border-box;
}
.logo {
width: 34px;
height: 34px;
flex-shrink: 0;
margin-bottom: var(--sp-5);
border-radius: var(--r-md);
display: grid;
place-items: center;
background: var(--accent-grad);
color: var(--accent-ink);
box-shadow: var(--btn-glow);
font-size: 16px;
font-weight: 700;
text-decoration: none;
transition: transform var(--d-press) var(--ease-out);
}
.logo:active {
transform: scale(var(--press-scale));
}
.rail-spacer {
flex: 1;
min-height: var(--sp-5);
}
.rail-btn {
position: relative;
flex-shrink: 0;
width: 40px;
height: 40px;
border-radius: var(--r-md);
display: grid;
place-items: center;
color: var(--text-3);
text-decoration: none;
transition:
color var(--d-state) ease,
background-color var(--d-state) ease,
transform var(--d-press) var(--ease-out);
}
a.rail-btn:active {
transform: scale(var(--press-scale));
}
.rail-btn[aria-current='page'] {
color: var(--text);
background: var(--bg-3);
}
.rail-ind {
position: absolute;
left: 0;
top: 0;
width: 3px;
height: 20px;
border-radius: 0 3px 3px 0;
background: var(--accent-grad);
box-shadow: 0 0 8px var(--accent-glow);
pointer-events: none;
opacity: 0;
transform: translateY(var(--y, 0));
transition:
transform var(--d-pop) var(--ease-out),
opacity var(--d-state) ease;
}
.rail-ind.on {
opacity: 1;
}
.rail-ind.instant {
transition: none;
}
:global(:root[data-reduce='1']) .rail-ind {
transition: opacity var(--d-state) ease;
}
/* Tooltip: 350ms 悬停延迟;键盘聚焦时立即出现。 */
.tip {
position: absolute;
left: 52px;
display: flex;
flex-direction: column;
white-space: nowrap;
pointer-events: none;
padding: var(--sp-1) var(--sp-3);
border-radius: var(--r-sm);
background: var(--bg-4);
box-shadow: var(--shadow-float);
color: var(--text);
font-size: var(--fs-aux);
line-height: 1.5;
opacity: 0;
transform: translateX(-4px);
transition:
opacity var(--d-pop) var(--ease-out),
transform var(--d-pop) var(--ease-out);
z-index: 70;
}
.tip-sub {
color: var(--text-3);
font-size: var(--fs-mini);
}
.rail-btn:focus-visible .tip,
.rail-lang:focus-within .tip {
opacity: 1;
transform: none;
}
@media (hover: hover) and (pointer: fine) {
.rail-btn:hover {
color: var(--text);
background: var(--bg-2);
}
.rail-btn[aria-current='page']:hover {
background: var(--bg-3);
}
.rail-btn:hover .tip {
opacity: 1;
transform: none;
transition-delay: 350ms;
}
}
/* 任务进行数 / 连接状态点 */
.rail-dot {
position: absolute;
top: 7px;
right: 7px;
width: 7px;
height: 7px;
border-radius: 50%;
background: var(--text-3);
box-shadow: 0 0 0 2px var(--bg);
}
.rail-dot.run {
background: var(--run);
}
.rail-dot.fail {
background: var(--err);
}
.rail-dot.testing,
.status-chip-dot.testing {
animation: shell-breathe 1.4s ease-in-out infinite;
}
@keyframes shell-breathe {
50% {
opacity: 0.35;
}
}
:global(:root[data-reduce='1']) .rail-dot.testing,
:global(:root[data-reduce='1']) .status-chip-dot.testing {
animation: none;
}
/* 语言:透明原生下拉叠在图标按钮上,保留键盘与读屏可用 */
.rail-lang {
cursor: pointer;
}
.lang-mark {
font-size: var(--fs-aux);
font-weight: 600;
color: inherit;
}
.rail-lang :global(.lang-switcher) {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
min-height: 0;
opacity: 0;
cursor: pointer;
}
.rail-lang:focus-within {
outline: 2px solid var(--accent);
outline-offset: 2px;
color: var(--text);
}
/* ---------------- 顶栏 (§二) ---------------- */
.main {
min-width: 0;
min-height: 0;
display: flex;
flex-direction: column;
}
.topbar {
position: relative;
z-index: 20;
display: flex;
align-items: center;
gap: var(--sp-4);
min-height: var(--topbar-h);
padding: var(--sp-2) var(--sp-7);
border-bottom: 1px solid var(--line);
box-sizing: border-box;
flex-shrink: 0;
}
.crumb {
min-width: 0;
flex-shrink: 1;
}
.crumb h1 {
margin: 0;
font-size: var(--fs-title);
font-weight: 600;
line-height: 1.35;
color: var(--text);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.sub {
margin: 0;
font-size: var(--fs-aux);
line-height: 1.5;
color: var(--text-3);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.grow {
flex: 1 1 0;
min-width: 0;
}
.topbar-actions,
.topbar-global {
display: flex;
align-items: center;
gap: var(--sp-3);
flex-shrink: 0;
}
.topbar-actions {
padding-right: var(--sp-4);
border-right: 1px solid var(--line);
}
.reduce {
display: inline-flex;
align-items: center;
gap: var(--sp-2);
font-size: var(--fs-aux);
color: var(--text-2);
white-space: nowrap;
cursor: pointer;
}
.search-btn {
min-width: 220px;
justify-content: space-between;
gap: var(--sp-3);
}
.search-label {
flex: 1;
text-align: left;
}
.conn-btn {
max-width: 240px;
}
.conn-name {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
}
.conn-ms {
flex-shrink: 0;
color: var(--text-3);
}
.body {
flex: 1;
min-height: 0;
overflow: auto;
}
/* ---------------- 底部标签栏(≤760px) ---------------- */
.tabbar {
display: none;
}
.tab-more {
position: relative;
display: grid;
}
.tab {
position: relative;
display: grid;
place-items: center;
align-content: center;
gap: 2px;
min-height: var(--tabbar-h);
border: 0;
background: transparent;
color: var(--text-3);
font-family: inherit;
font-size: var(--fs-mini);
text-decoration: none;
cursor: pointer;
transition: color var(--d-state) ease;
}
.tab[aria-current='page'] {
color: var(--accent);
}
.tab-dot {
top: 8px;
right: calc(50% - 16px);
}
.more-lang :global(.lang-switcher) {
min-height: 32px;
}
/* ---------------- 中屏(761–1179) ---------------- */
@media (max-width: 1179px) {
.topbar {
padding: var(--sp-2) var(--sp-6);
}
.search-btn {
min-width: 0;
}
.search-label,
.reduce-label {
display: none;
}
.conn-btn {
max-width: 180px;
}
}
/* ---------------- 窄屏(≤760) ---------------- */
@media (max-width: 760px) {
.shell-frame {
grid-template-columns: minmax(0, 1fr);
}
.rail {
display: none;
}
.topbar {
flex-wrap: wrap;
gap: var(--sp-3);
padding: var(--sp-2) var(--sp-5);
min-height: 48px;
}
.crumb {
flex: 1 1 0;
}
.grow,
.sub,
.hide-sm,
.search-kbd,
.conn-name,
.conn-ms {
display: none;
}
.search-btn,
.conn-btn {
width: 32px;
padding: 0;
justify-content: center;
}
.topbar-global {
gap: var(--sp-2);
}
.topbar-actions {
order: 10;
flex: 1 0 100%;
flex-wrap: wrap;
padding: 0 0 var(--sp-1);
border-right: 0;
}
.tabbar {
flex-shrink: 0;
display: grid;
grid-template-columns: repeat(4, 1fr);
padding-bottom: env(safe-area-inset-bottom);
border-top: 1px solid var(--line);
background: var(--bg-2);
}
}
</style>