feat(canvas): playable scene video cards + draggable chat panel width cap 30%
This commit is contained in:
@@ -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<EntityNode> = $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;
|
||||
}
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="entity-node"
|
||||
class:playing
|
||||
role="button"
|
||||
tabindex="0"
|
||||
onclick={() => 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?.();
|
||||
}}
|
||||
>
|
||||
<header>
|
||||
<Icon name={iconFor(data.entityType)} size={14} />
|
||||
<span class="title" title={data.title}>{data.title}</span>
|
||||
{#if videoSrc && !playing}
|
||||
<span class="play-badge" aria-hidden="true">
|
||||
<Icon name="play" size={10} />
|
||||
</span>
|
||||
{/if}
|
||||
</header>
|
||||
<div class="media">
|
||||
{#if mediaSrc}
|
||||
<SafeMedia src={mediaSrc} alt={data.title} kind="image" controls={false} />
|
||||
{#if playing && videoSrc}
|
||||
<!-- svelte-ignore a11y_media_has_caption -->
|
||||
<video
|
||||
class="media-el"
|
||||
src={videoSrc}
|
||||
autoplay
|
||||
controls
|
||||
playsinline
|
||||
onended={() => (playing = false)}
|
||||
></video>
|
||||
{:else if videoSrc}
|
||||
<!-- svelte-ignore a11y_media_has_caption -->
|
||||
<video
|
||||
class="media-el"
|
||||
src={videoSrc}
|
||||
muted
|
||||
playsinline
|
||||
preload="metadata"
|
||||
></video>
|
||||
{:else if posterSrc}
|
||||
<SafeMedia class="media-el" src={posterSrc} alt={data.title} kind="image" controls={false} />
|
||||
{:else}
|
||||
<span class="placeholder">{data.entityType}</span>
|
||||
{/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;
|
||||
|
||||
@@ -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 @@
|
||||
</main>
|
||||
|
||||
{#if !chatCollapsed}
|
||||
<aside class="chat-panel">
|
||||
<button
|
||||
type="button"
|
||||
class="chat-splitter"
|
||||
class:dragging
|
||||
aria-label={`Resize chat panel (drag or arrow keys), currently ${Math.round(chatWidth)} pixels`}
|
||||
onmousedown={startDrag}
|
||||
onkeydown={(e) => {
|
||||
if (e.key === 'ArrowLeft') {
|
||||
e.preventDefault();
|
||||
chatWidth = clampChatWidth(chatWidth + 24);
|
||||
localStorage.setItem(CHAT_W_KEY, String(Math.round(chatWidth)));
|
||||
} else if (e.key === 'ArrowRight') {
|
||||
e.preventDefault();
|
||||
chatWidth = clampChatWidth(chatWidth - 24);
|
||||
localStorage.setItem(CHAT_W_KEY, String(Math.round(chatWidth)));
|
||||
}
|
||||
}}
|
||||
></button>
|
||||
<aside class="chat-panel" style:width="{chatWidth}px">
|
||||
<header class="chat-head">
|
||||
<div class="chat-title-block">
|
||||
{#if activeSession}
|
||||
@@ -844,13 +917,37 @@
|
||||
color: var(--text-primary);
|
||||
}
|
||||
.chat-panel {
|
||||
width: 420px;
|
||||
flex-shrink: 0;
|
||||
border-left: 1px solid var(--border);
|
||||
background: var(--bg-surface);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
min-width: 0;
|
||||
}
|
||||
.chat-splitter {
|
||||
width: 7px;
|
||||
flex-shrink: 0;
|
||||
padding: 0;
|
||||
border: none;
|
||||
background: transparent;
|
||||
cursor: col-resize;
|
||||
margin-left: -3px;
|
||||
margin-right: -3px;
|
||||
z-index: 6;
|
||||
position: relative;
|
||||
transition: background 0.12s;
|
||||
}
|
||||
.chat-splitter:hover,
|
||||
.chat-splitter.dragging,
|
||||
.chat-splitter:focus-visible {
|
||||
background: color-mix(in srgb, var(--accent) 45%, transparent);
|
||||
outline: none;
|
||||
}
|
||||
.chat-splitter.dragging {
|
||||
/* Svelte Flow's pane captures pointer events while dragging near the
|
||||
graph edge — suppress text selection app-wide during the drag. */
|
||||
cursor: col-resize;
|
||||
}
|
||||
.chat-head {
|
||||
display: flex;
|
||||
|
||||
Reference in New Issue
Block a user