Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Overlay animated controls on export preview

Bitti658fda814b84
diff --git a/src/components/workspace/ExportView.test.tsx b/src/components/workspace/ExportView.test.tsx
index c253239..8d46415 100644
--- a/src/components/workspace/ExportView.test.tsx
+++ b/src/components/workspace/ExportView.test.tsx
@@ -1,6 +1,6 @@
// @vitest-environment jsdom
-import { cleanup, render, screen, within } from "@testing-library/react";
+import { act, cleanup, fireEvent, render, screen, within } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import audioFixture from "../../../fixtures/project-v1-audio-mix.json";
import externalFixture from "../../../fixtures/project-v1-external-media.json";
@@ -59,7 +59,7 @@ describe("the export view where nothing can encode", () => {
it("states the real duration of the planned file", () => {
render(<ExportView config={project([clip("a", 0, 2_000), clip("b", 2_000, 1_000)])} folderPath="/tmp/project" />);
- expect(screen.getByText("00:03.000")).toBeTruthy();
+ expect(within(screen.getByText("Duration").parentElement!).getByText("00:03.000")).toBeTruthy();
expect(screen.getByText("72 frames at 24 fps")).toBeTruthy();
/* The frame size is named where it is CHOSEN — in the resolution select —
rather than repeated in a summary row beside it. */
@@ -103,7 +103,8 @@ describe("the export view where nothing can encode", () => {
describe("the shape of the export screen", () => {
it("names its two panels after what they hold", () => {
const { container } = render(<ExportView config={project([clip("a", 0, 2_000)])} folderPath="/tmp/project" />);
- expect(screen.getByRole("heading", { name: "Video" })).toBeTruthy();
+ expect(screen.queryByRole("heading", { name: "Video" })).toBeNull();
+ expect(screen.getByRole("region", { name: "Video preview" })).toBeTruthy();
expect(screen.getByRole("heading", { name: "Settings" })).toBeTruthy();
expect(screen.queryByRole("heading", { name: "Preview" })).toBeNull();
expect(screen.queryByRole("heading", { name: "Export Settings" })).toBeNull();
@@ -132,6 +133,24 @@ describe("the shape of the export screen", () => {
expect(stage.style.aspectRatio).toBe("1920 / 1080");
});
+ it("embeds playback controls over the video and hides them when the pointer rests", () => {
+ vi.useFakeTimers();
+ try {
+ const { container } = render(<ExportView config={project([clip("a", 0, 2_000)])} folderPath="/tmp/project" />);
+ const stage = container.querySelector(".export-stage") as HTMLElement;
+ const controls = screen.getByRole("group", { name: "Video playback controls" });
+ expect(stage.contains(controls)).toBe(true);
+ expect(stage.classList.contains("export-stage--controls-visible")).toBe(false);
+
+ fireEvent.pointerMove(stage);
+ expect(stage.classList.contains("export-stage--controls-visible")).toBe(true);
+ act(() => vi.advanceTimersByTime(1_800));
+ expect(stage.classList.contains("export-stage--controls-visible")).toBe(false);
+ } finally {
+ vi.useRealTimers();
+ }
+ });
+
it("says nothing about a finished export until there is one", () => {
const { container } = render(<ExportView config={project([clip("a", 0, 2_000)])} folderPath="/tmp/project" />);
expect(container.querySelector(".export-toast")).toBeNull();
@@ -153,7 +172,7 @@ describe("the export view on media the project does not contain", () => {
const reasons = screen.getByRole("alert").textContent ?? "";
expect(reasons).not.toMatch(/not in this project/i);
expect(reasons).not.toMatch(/no file recorded/i);
- expect(screen.getByText("00:12.000")).toBeTruthy();
+ expect(within(screen.getByText("Duration").parentElement!).getByText("00:12.000")).toBeTruthy();
expect(screen.getByText("360 frames at 30 fps")).toBeTruthy();
});
});
diff --git a/src/components/workspace/ExportView.tsx b/src/components/workspace/ExportView.tsx
index abe27ef..7d570fb 100644
--- a/src/components/workspace/ExportView.tsx
+++ b/src/components/workspace/ExportView.tsx
@@ -46,6 +46,9 @@ const describe = (reason: unknown) => (reason instanceof Error ? reason.message
/** How long the Saved notification stays up before it takes itself away. */
const SAVED_NOTICE_MS = 4_000;
+/** A moving pointer reveals the transport; once it rests, the picture gets the
+ * full frame again. Long enough to cross the controls without racing them. */
+const PLAYER_CONTROLS_IDLE_MS = 1_800;
/* What the finished run left OUT of the soundtrack. Everything else an export
used to report on the page — path, size, codec, compositor — is gone: the
@@ -76,7 +79,9 @@ export function ExportView({ config, folderPath }: { config: ProjectConfig; fold
const [previewTimeMs, setPreviewTimeMs] = useState(0);
const [playing, setPlaying] = useState(false);
const [fullscreen, setFullscreen] = useState(false);
+ const [controlsVisible, setControlsVisible] = useState(false);
const stageRef = useRef<HTMLDivElement>(null);
+ const controlsTimerRef = useRef<number | null>(null);
const [progress, setProgress] = useState<ExportProgress | null>(null);
/* The finished run says one word, in the middle of the header, and stops
@@ -95,6 +100,23 @@ export function ExportView({ config, folderPath }: { config: ProjectConfig; fold
See ProgramMonitor. */
const seek = useCallback((ms: number) => setPreviewTimeMs(ms), []);
const changePlaying = useCallback((value: boolean) => setPlaying(value), []);
+ const clearControlsTimer = useCallback(() => {
+ if (controlsTimerRef.current === null) return;
+ window.clearTimeout(controlsTimerRef.current);
+ controlsTimerRef.current = null;
+ }, []);
+ const hideControlsAfterIdle = useCallback(() => {
+ clearControlsTimer();
+ controlsTimerRef.current = window.setTimeout(() => {
+ controlsTimerRef.current = null;
+ if (stageRef.current?.contains(document.activeElement)) return;
+ setControlsVisible(false);
+ }, PLAYER_CONTROLS_IDLE_MS);
+ }, [clearControlsTimer]);
+ const revealControls = useCallback(() => {
+ setControlsVisible(true);
+ hideControlsAfterIdle();
+ }, [hideControlsAfterIdle]);
/* Switching tabs unmounts this view, and an export that kept running would
finish and write a file with nothing on screen to say so. Leaving stops it
@@ -103,6 +125,8 @@ export function ExportView({ config, folderPath }: { config: ProjectConfig; fold
cancelRef.current = true;
}, []);
+ useEffect(() => () => clearControlsTimer(), [clearControlsTimer]);
+
useEffect(() => {
let live = true;
void probeCompositor().then((found) => {
@@ -145,10 +169,13 @@ export function ExportView({ config, folderPath }: { config: ProjectConfig; fold
the window chrome both end it without asking this component — so the
button reads the document rather than remembering what it did. */
useEffect(() => {
- const sync = () => setFullscreen(document.fullscreenElement === stageRef.current);
+ const sync = () => {
+ setFullscreen(document.fullscreenElement === stageRef.current);
+ revealControls();
+ };
document.addEventListener("fullscreenchange", sync);
return () => document.removeEventListener("fullscreenchange", sync);
- }, []);
+ }, [revealControls]);
/* The notification takes itself away. Re-armed on every run, and cleared on
the way out so a saved export that is left behind does not fire into an
@@ -297,8 +324,7 @@ export function ExportView({ config, folderPath }: { config: ProjectConfig; fold
</header>
<div className="export-layout">
- <section className="export-preview" aria-labelledby="export-preview-heading">
- <h2 id="export-preview-heading">Video</h2>
+ <section className="export-preview" aria-label="Video preview">
{/* The same player the timeline uses, on the same cut: it decodes the
real files and plays them with their sound, rather than decoding one
still frame per scrub. What the export will contain is what this
@@ -310,9 +336,23 @@ export function ExportView({ config, folderPath }: { config: ProjectConfig; fold
shrink it back — the export writes one frame size for the whole
file, and this shows that size the whole time. */}
<div
- className="export-stage"
+ className={`export-stage${controlsVisible ? " export-stage--controls-visible" : ""}`}
ref={stageRef}
style={{ aspectRatio: `${plan.width} / ${plan.height}`, "--frame-aspect": plan.width / plan.height } as React.CSSProperties}
+ onPointerEnter={revealControls}
+ onPointerMove={revealControls}
+ onPointerDown={revealControls}
+ onPointerLeave={() => {
+ clearControlsTimer();
+ if (!stageRef.current?.contains(document.activeElement)) setControlsVisible(false);
+ }}
+ onFocusCapture={() => {
+ clearControlsTimer();
+ setControlsVisible(true);
+ }}
+ onBlurCapture={(event) => {
+ if (!event.currentTarget.contains(event.relatedTarget as Node | null)) hideControlsAfterIdle();
+ }}
>
<ProgramMonitor
config={config}
@@ -322,48 +362,49 @@ export function ExportView({ config, folderPath }: { config: ProjectConfig; fold
onSeek={seek}
onPlayingChange={changePlaying}
/>
- </div>
- <div className="export-transport">
- <button
- type="button"
- onClick={() => step(-1000)}
- disabled={plan.frameCount === 0}
- aria-label="Back one second"
- title="Back one second"
- ><SkipBack size={16} aria-hidden="true" /></button>
- <button
- type="button"
- className="export-transport__play"
- onClick={() => setPlaying((value) => !value)}
- disabled={plan.frameCount === 0}
- aria-label={playing ? "Pause" : "Play"}
- title={plan.frameCount === 0 ? "There is nothing on the timeline to play" : playing ? "Pause" : "Play"}
- >{playing ? <Pause size={16} fill="currentColor" aria-hidden="true" /> : <Play size={16} fill="currentColor" aria-hidden="true" />}</button>
- <button
- type="button"
- onClick={() => step(1000)}
- disabled={plan.frameCount === 0}
- aria-label="Forward one second"
- title="Forward one second"
- ><SkipForward size={16} aria-hidden="true" /></button>
- <input
- id="export-scrub"
- type="range"
- min={0}
- max={Math.max(0, plan.durationMs - 1)}
- step={Math.max(1, Math.round(1000 / plan.frameRate))}
- value={previewTimeMs}
- disabled={plan.frameCount === 0}
- aria-label="Playhead"
- onChange={(event) => { setPlaying(false); setPreviewTimeMs(Number(event.target.value)); }}
- />
- <output htmlFor="export-scrub">{formatDuration(previewTimeMs)}</output>
- <button
- type="button"
- onClick={toggleFullscreen}
- aria-label={fullscreen ? "Leave fullscreen" : "Watch fullscreen"}
- title={fullscreen ? "Leave fullscreen" : "Watch fullscreen"}
- >{fullscreen ? <Minimize size={16} aria-hidden="true" /> : <Maximize size={16} aria-hidden="true" />}</button>
+ <div className="export-transport" role="group" aria-label="Video playback controls">
+ <button
+ type="button"
+ onClick={() => step(-1000)}
+ disabled={plan.frameCount === 0}
+ aria-label="Back one second"
+ title="Back one second"
+ ><SkipBack size={18} aria-hidden="true" /></button>
+ <button
+ type="button"
+ className="export-transport__play"
+ onClick={() => setPlaying((value) => !value)}
+ disabled={plan.frameCount === 0}
+ aria-label={playing ? "Pause" : "Play"}
+ title={plan.frameCount === 0 ? "There is nothing on the timeline to play" : playing ? "Pause" : "Play"}
+ >{playing ? <Pause size={20} fill="currentColor" aria-hidden="true" /> : <Play size={20} fill="currentColor" aria-hidden="true" />}</button>
+ <button
+ type="button"
+ onClick={() => step(1000)}
+ disabled={plan.frameCount === 0}
+ aria-label="Forward one second"
+ title="Forward one second"
+ ><SkipForward size={18} aria-hidden="true" /></button>
+ <input
+ id="export-scrub"
+ type="range"
+ min={0}
+ max={Math.max(0, plan.durationMs - 1)}
+ step={Math.max(1, Math.round(1000 / plan.frameRate))}
+ value={previewTimeMs}
+ style={{ "--scrub-progress": `${plan.durationMs > 1 ? previewTimeMs / (plan.durationMs - 1) * 100 : 0}%` } as React.CSSProperties}
+ disabled={plan.frameCount === 0}
+ aria-label="Playhead"
+ onChange={(event) => { setPlaying(false); setPreviewTimeMs(Number(event.target.value)); }}
+ />
+ <output htmlFor="export-scrub"><span>{formatDuration(previewTimeMs)}</span><i aria-hidden="true">/</i><span>{formatDuration(plan.durationMs)}</span></output>
+ <button
+ type="button"
+ onClick={toggleFullscreen}
+ aria-label={fullscreen ? "Leave fullscreen" : "Watch fullscreen"}
+ title={fullscreen ? "Leave fullscreen" : "Watch fullscreen"}
+ >{fullscreen ? <Minimize size={19} aria-hidden="true" /> : <Maximize size={19} aria-hidden="true" />}</button>
+ </div>
</div>
{/* The one thing left to say under the picture: that there is no
picture. The frame-by-frame caption that used to live here named a
diff --git a/src/styles/export.css b/src/styles/export.css
index ea95349..52a8564 100644
--- a/src/styles/export.css
+++ b/src/styles/export.css
@@ -146,7 +146,7 @@
position: relative;
width: 100%;
max-width: calc(68vh * var(--frame-aspect, 1.7778));
- margin: 0 auto var(--space-3);
+ margin: 0 auto;
display: grid;
place-items: center;
overflow: hidden;
@@ -159,6 +159,10 @@
background: var(--stage-bg);
}
+.export-stage:not(.export-stage--controls-visible):not(:focus-within) {
+ cursor: none;
+}
+
/* The player fills the stage; the letterboxing inside it is the project's own
frame shape, painted in the project's own background colour. */
.export-stage .program-picture {
@@ -175,6 +179,10 @@
background: var(--stage-bg);
}
+.export-stage:fullscreen .export-transport {
+ padding: 56px max(var(--space-5), env(safe-area-inset-right)) max(var(--space-5), env(safe-area-inset-bottom)) max(var(--space-5), env(safe-area-inset-left));
+}
+
.export-stage__note {
max-width: 46ch;
margin: 0;
@@ -210,13 +218,33 @@
line-height: var(--leading-normal);
}
-/* Play, step, scrub, fullscreen — one row, and the scrub takes whatever the
- buttons leave. */
+/* A translucent playback surface over the picture. Pointer movement reveals
+ it; keyboard focus keeps it present independently of the idle timer. */
.export-transport {
- min-height: var(--control-sm);
+ position: absolute;
+ z-index: 5;
+ inset: auto 0 0;
+ min-height: 76px;
display: flex;
align-items: center;
- gap: var(--space-2);
+ gap: var(--space-1);
+ padding: 30px var(--space-3) var(--space-3);
+ color: var(--on-stage);
+ background: linear-gradient(to bottom, transparent, color-mix(in srgb, var(--stage-bg) 82%, transparent));
+ opacity: 0;
+ visibility: hidden;
+ transform: translateY(12px);
+ pointer-events: none;
+ transition: opacity 0.22s ease, transform 0.22s cubic-bezier(0.22, 1, 0.36, 1), visibility 0s linear 0.22s;
+}
+
+.export-stage--controls-visible .export-transport,
+.export-stage:focus-within .export-transport {
+ opacity: 1;
+ visibility: visible;
+ transform: translateY(0);
+ pointer-events: auto;
+ transition-delay: 0s;
}
.export-transport button {
@@ -226,54 +254,118 @@
display: grid;
place-items: center;
padding: 0;
- border: 1px solid var(--line-strong);
- border-radius: var(--radius-sm);
- color: var(--text-secondary);
- background: var(--panel-2);
+ border: 0;
+ border-radius: 50%;
+ color: var(--on-stage);
+ background: transparent;
cursor: pointer;
- transition: 0.14s ease;
+ filter: drop-shadow(0 1px 2px color-mix(in srgb, var(--stage-bg) 55%, transparent));
+ transition: color 0.14s ease, background-color 0.14s ease, transform 0.14s ease;
}
.export-transport button:hover:not(:disabled) {
- border-color: var(--line-hover);
- color: var(--text-primary);
- background: var(--panel-3);
+ color: var(--on-stage);
+ background: color-mix(in srgb, var(--on-stage) 16%, transparent);
+ transform: scale(1.06);
+}
+
+.export-transport button:focus-visible {
+ outline: 2px solid var(--on-stage);
+ outline-offset: 1px;
}
.export-transport button:disabled {
cursor: not-allowed;
- color: var(--text-faint);
- opacity: 0.7;
+ opacity: 0.42;
}
.export-transport__play:not(:disabled) {
- border-color: var(--accent);
- color: var(--on-accent);
- background: var(--accent);
+ color: var(--on-stage);
}
.export-transport__play:hover:not(:disabled) {
- border-color: var(--accent-bright);
- color: var(--on-accent);
- background: var(--accent-bright);
+ color: var(--on-stage);
+ background: color-mix(in srgb, var(--on-stage) 20%, transparent);
}
.export-transport input[type="range"] {
+ --scrub-progress: 0%;
flex: 1 1 auto;
min-width: 0;
- height: var(--control-sm);
- margin: 0 var(--space-1);
- accent-color: var(--accent-bright);
+ height: 24px;
+ margin: 0 var(--space-2);
+ appearance: none;
+ border: 0;
+ outline: 0;
+ background: transparent;
cursor: pointer;
}
+.export-transport input[type="range"]::-webkit-slider-runnable-track {
+ height: 4px;
+ border-radius: var(--radius-pill);
+ background: linear-gradient(to right, var(--accent-bright) 0 var(--scrub-progress), color-mix(in srgb, var(--on-stage) 38%, transparent) var(--scrub-progress) 100%);
+}
+
+.export-transport input[type="range"]::-webkit-slider-thumb {
+ width: 14px;
+ height: 14px;
+ margin-top: -5px;
+ appearance: none;
+ border: 2px solid var(--on-stage);
+ border-radius: 50%;
+ background: var(--accent-bright);
+ box-shadow: 0 1px 4px color-mix(in srgb, var(--stage-bg) 55%, transparent);
+}
+
+.export-transport input[type="range"]::-moz-range-track {
+ height: 4px;
+ border-radius: var(--radius-pill);
+ background: color-mix(in srgb, var(--on-stage) 38%, transparent);
+}
+
+.export-transport input[type="range"]::-moz-range-progress {
+ height: 4px;
+ border-radius: var(--radius-pill);
+ background: var(--accent-bright);
+}
+
+.export-transport input[type="range"]::-moz-range-thumb {
+ width: 11px;
+ height: 11px;
+ border: 2px solid var(--on-stage);
+ border-radius: 50%;
+ background: var(--accent-bright);
+ box-shadow: 0 1px 4px color-mix(in srgb, var(--stage-bg) 55%, transparent);
+}
+
+.export-transport input[type="range"]:focus-visible::-webkit-slider-thumb {
+ box-shadow: 0 0 0 3px color-mix(in srgb, var(--on-stage) 35%, transparent), 0 1px 4px color-mix(in srgb, var(--stage-bg) 55%, transparent);
+}
+
.export-transport output {
flex: 0 0 auto;
- min-width: 8ch;
- color: var(--text-secondary);
+ min-width: 17ch;
+ display: flex;
+ justify-content: center;
+ gap: var(--space-1);
+ color: var(--on-stage);
font-family: var(--font-mono);
font-size: var(--text-2xs);
- text-align: right;
+ text-align: center;
+ text-shadow: 0 1px 2px var(--stage-bg);
+}
+
+.export-transport output i {
+ color: color-mix(in srgb, var(--on-stage) 55%, transparent);
+ font-style: normal;
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .export-transport,
+ .export-transport button {
+ transition: none;
+ }
}
/* --- Settings -------------------------------------------------------------- */