diff --git a/calliope-web/src/lib/canvas/EntityNode.svelte b/calliope-web/src/lib/canvas/EntityNode.svelte index 28630597..9f382293 100644 --- a/calliope-web/src/lib/canvas/EntityNode.svelte +++ b/calliope-web/src/lib/canvas/EntityNode.svelte @@ -9,7 +9,10 @@ canvasNodeId: number; entityType: 'character' | 'location' | 'item' | 'scene'; title: string; + /** Poster image (env image / reference sheet) — shown while not playing. */ imagePath: string | null; + /** Clip path — when set the card becomes a playable video card. */ + videoPath: string | null; onOpen?: () => void; } @@ -30,23 +33,60 @@ let { data }: NodeProps = $props(); - const mediaSrc = $derived(assetUrl(data.imagePath)); + const posterSrc = $derived(assetUrl(data.imagePath)); + // '#t=0.1' media fragment: with preload="metadata" browsers paint nothing + // until playback, so the thumbnail sat black. The fragment seeks+paints + // the first frame without playing (same trick as ClipMonitor). + const videoSrc = $derived(data.videoPath ? assetUrl(data.videoPath) + '#t=0.1' : null); + let playing = $state(false); + + function togglePlay() { + playing = !playing; + }
data.onOpen?.()} - onkeydown={(e) => e.key === 'Enter' && data.onOpen?.()} + onclick={() => (videoSrc ? togglePlay() : data.onOpen?.())} + onkeydown={(e) => { + if (e.key !== 'Enter') return; + videoSrc ? togglePlay() : data.onOpen?.(); + }} >
{data.title} + {#if videoSrc && !playing} + + {/if}
- {#if mediaSrc} - + {#if playing && videoSrc} + + + {:else if videoSrc} + + + {:else if posterSrc} + {:else} {data.entityType} {/if} @@ -66,6 +106,9 @@ .entity-node:hover { border-color: #3a3a44; } + .entity-node.playing { + cursor: default; + } /* Svelte Flow marks the selected node wrapper with .selected */ :global(.svelte-flow__node.selected) .entity-node { border-color: var(--accent); @@ -90,6 +133,17 @@ text-overflow: ellipsis; white-space: nowrap; } + .play-badge { + display: inline-flex; + align-items: center; + justify-content: center; + width: 18px; + height: 18px; + border-radius: 50%; + background: color-mix(in srgb, var(--accent) 22%, transparent); + color: var(--text-primary); + flex-shrink: 0; + } .media { height: 132px; background: var(--bg-elevated); @@ -97,8 +151,8 @@ align-items: center; justify-content: center; } - .media :global(img), - .media :global(video) { + .media :global(.media-el), + .media-el { width: 100%; height: 100%; object-fit: cover; diff --git a/calliope-web/src/routes/canvas/[id]/+page.svelte b/calliope-web/src/routes/canvas/[id]/+page.svelte index 40051708..7318a118 100644 --- a/calliope-web/src/routes/canvas/[id]/+page.svelte +++ b/calliope-web/src/routes/canvas/[id]/+page.svelte @@ -81,30 +81,34 @@ })), ); - function imagePathFor( + function mediaFor( node: (typeof canvasNodes)[number], characters: Character[], locations: Location[], items: Item[], scenes: Scene[], - ): string | null { + ): { imagePath: string | null; videoPath: string | null } { if (node.entity_type === 'character') { const c = characters.find((x) => x.id === node.entity_id); - return c?.sheet_path ?? c?.portrait_path ?? null; + return { imagePath: c?.sheet_path ?? c?.portrait_path ?? null, videoPath: null }; } if (node.entity_type === 'location') { const l = locations.find((x) => x.id === node.entity_id); - return l?.reference_image_path ?? null; + return { imagePath: l?.reference_image_path ?? null, videoPath: null }; } if (node.entity_type === 'item') { const i = items.find((x) => x.id === node.entity_id); - return i?.reference_image_path ?? null; + return { imagePath: i?.reference_image_path ?? null, videoPath: null }; } if (node.entity_type === 'scene') { const s = scenes.find((x) => x.id === node.entity_id); - return s?.env_image_path ?? null; + // Project > Videos pattern: env image poster, clip fallback; only + // real video files count (guard mirrors QueueStage.previewPath). + const clip = + s?.video_path && /\.(mp4|webm)$/i.test(s.video_path) ? s.video_path : null; + return { imagePath: s?.env_image_path ?? null, videoPath: clip }; } - return null; + return { imagePath: null, videoPath: null }; } const nodeTypes = { entity: EntityNode }; @@ -140,18 +144,22 @@ const locations = $assetsQuery.data?.locations ?? []; const items = $assetsQuery.data?.items ?? []; const scenes = $scenesQuery.data?.scenes ?? []; - nodes = graph.nodes.map((n) => ({ - id: `cn-${n.id}`, - type: 'entity' as const, - position: { x: n.x, y: n.y }, - data: { - canvasNodeId: n.id, - entityType: n.entity_type as 'character' | 'location' | 'item' | 'scene', - title: n.title ?? 'Untitled', - imagePath: imagePathFor(n, characters, locations, items, scenes), - onOpen: () => openEntity(n.entity_type!, n.entity_id!), - }, - })); + nodes = graph.nodes.map((n) => { + const media = mediaFor(n, characters, locations, items, scenes); + return { + id: `cn-${n.id}`, + type: 'entity' as const, + position: { x: n.x, y: n.y }, + data: { + canvasNodeId: n.id, + entityType: n.entity_type as 'character' | 'location' | 'item' | 'scene', + title: n.title ?? 'Untitled', + imagePath: media.imagePath, + videoPath: media.videoPath, + onOpen: () => openEntity(n.entity_type!, n.entity_id!), + }, + }; + }); }); async function persistNodePosition(node: Node) { @@ -578,6 +586,53 @@ localStorage.setItem(CHAT_KEY, chatCollapsed ? '1' : '0'); } + // ---- draggable chat splitter --------------------------------------------- + + const CHAT_W_KEY = 'calliope.canvas.chatWidth'; + const CHAT_MIN_PX = 300; + + // Stored in px; capped against the live window so a resized window can + // never restore an oversize panel (max 30% of window width). + let chatWidth = $state(420); + let dragging = $state(false); + + function clampChatWidth(px: number): number { + const max = Math.max(CHAT_MIN_PX, Math.round(window.innerWidth * 0.3)); + return Math.min(Math.max(px, CHAT_MIN_PX), max); + } + + $effect(() => { + const raw = Number(localStorage.getItem(CHAT_W_KEY)); + if (Number.isFinite(raw) && raw > 0) chatWidth = clampChatWidth(raw); + // Keep the panel within the cap when the window shrinks. + const onResize = () => (chatWidth = clampChatWidth(chatWidth)); + window.addEventListener('resize', onResize); + return () => window.removeEventListener('resize', onResize); + }); + + function startDrag(e: MouseEvent) { + if (e.button !== 0) return; + e.preventDefault(); + dragging = true; + document.body.style.userSelect = 'none'; + document.body.style.cursor = 'col-resize'; + const startX = e.clientX; + const startWidth = chatWidth; + const onMove = (ev: MouseEvent) => { + chatWidth = clampChatWidth(startWidth + (startX - ev.clientX)); + }; + const onUp = () => { + dragging = false; + document.body.style.userSelect = ''; + document.body.style.cursor = ''; + localStorage.setItem(CHAT_W_KEY, String(Math.round(chatWidth))); + document.removeEventListener('mousemove', onMove); + document.removeEventListener('mouseup', onUp); + }; + document.addEventListener('mousemove', onMove); + document.addEventListener('mouseup', onUp); + } + // ---- title card --------------------------------------------------------- let titleDraft = $state(''); @@ -696,7 +751,25 @@ {#if !chatCollapsed} -