Skip to content

The VS Code of video editing, built for agents.

TypeScript

Implement timeline minimization feature and enhance rendering logic

konstantin-paulus9fc15a3297dc
diff --git a/apps/web/src/components/engine/timeline/render/playhead.ts b/apps/web/src/components/engine/timeline/render/playhead.ts
index 2ccd7a45..1bc6bfb2 100644
--- a/apps/web/src/components/engine/timeline/render/playhead.ts
+++ b/apps/web/src/components/engine/timeline/render/playhead.ts
@@ -9,6 +9,13 @@ import { RULER_HEIGHT } from "../config";
import type { EngineWorld } from "../../api/world";
import type { TimelineContext } from "../world";
+// Rounded-rect knob shown while the timeline is minimized
+const PILL_TOP = 8;
+const PILL_HEIGHT = 19;
+const PILL_PADDING_X = 4;
+const PILL_RADIUS = 9;
+const PILL_CHAR_WIDTH = 6;
+
// Critically-damped spring state for gradient width
const GRADIENT_PX_PER_VELOCITY = 25;
const GRADIENT_RESPONSE_TIME = 0.15;
@@ -33,6 +40,12 @@ export function renderPlayhead(world: EngineWorld, timeline: TimelineContext) {
ctx.translate(-(scrollX * resolution), 0);
ctx.translate(x, 0);
+ if (timeline.minimized) {
+ renderMinimizedPlayhead(timeline, currentTime);
+ ctx.restore();
+ return;
+ }
+
// Draw knob
{
ctx.save();
@@ -112,3 +125,39 @@ export function renderPlayhead(world: EngineWorld, timeline: TimelineContext) {
ctx.restore();
}
+
+function renderMinimizedPlayhead(timeline: TimelineContext, currentTime: number) {
+ const ctx = timeline.ctx!;
+
+ const label = `${Math.round(currentTime)}`;
+
+ ctx.font = '400 10px JetBrains Mono';
+ ctx.textAlign = 'center';
+ ctx.textBaseline = 'middle';
+
+ const width = label.length * PILL_CHAR_WIDTH + PILL_PADDING_X * 2;
+
+ ctx.beginPath();
+ ctx.moveTo(0, PILL_TOP + PILL_HEIGHT);
+ ctx.lineTo(0, RULER_HEIGHT);
+
+ ctx.strokeStyle = timeline.colors.border.input;
+ ctx.lineWidth = 4;
+ ctx.stroke();
+
+ ctx.strokeStyle = timeline.colors.border.ring;
+ ctx.lineWidth = 2;
+ ctx.stroke();
+
+ ctx.beginPath();
+ ctx.roundRect(-width / 2, PILL_TOP, width, PILL_HEIGHT, PILL_RADIUS);
+
+ ctx.fillStyle = timeline.colors.border.ring;
+ ctx.strokeStyle = timeline.colors.border.darker;
+ ctx.lineWidth = 1;
+ ctx.fill();
+ ctx.stroke();
+
+ ctx.fillStyle = 'white';
+ ctx.fillText(label, 0, PILL_TOP + PILL_HEIGHT / 2 + 0.5);
+}
diff --git a/apps/web/src/components/engine/timeline/timeline.ts b/apps/web/src/components/engine/timeline/timeline.ts
index ce4f1958..90a708fd 100644
--- a/apps/web/src/components/engine/timeline/timeline.ts
+++ b/apps/web/src/components/engine/timeline/timeline.ts
@@ -91,20 +91,25 @@ export function createTimeline() {
timeline.cursor = 'default';
- renderBackground(world, timeline);
-
- ctx.save();
- ctx.beginPath();
- ctx.rect(0, RULER_HEIGHT, canvas.width, canvas.height);
- ctx.clip();
- renderLayers(world, timeline);
- renderMarquee(world, timeline);
- ctx.restore();
+ if (!timeline.minimized) {
+ renderBackground(world, timeline);
+
+ ctx.save();
+ ctx.beginPath();
+ ctx.rect(0, RULER_HEIGHT, canvas.width, canvas.height);
+ ctx.clip();
+ renderLayers(world, timeline);
+ renderMarquee(world, timeline);
+ ctx.restore();
+ }
renderRuler(world, timeline);
renderWorkarea(world, timeline);
renderPlayhead(world, timeline);
- renderSnapPoints(world, timeline);
+
+ if (!timeline.minimized) {
+ renderSnapPoints(world, timeline);
+ }
cursor.set(canvas, timeline.cursor);
} catch (e) {
@@ -226,6 +231,10 @@ export function createTimeline() {
const clientToTime = (clientX: number) => (clientToFrame(clientX) / world.frameRate);
+ const setMinimized = (minimized: boolean) => {
+ timeline.minimized = minimized;
+ }
+
const attachCanvas = () => {
const canvas = document.getElementById('timeline-canvas') as HTMLCanvasElement;
assert(canvas, 'Timeline canvas must be defined');
@@ -289,5 +298,6 @@ export function createTimeline() {
scroll,
clientToTime,
clientToFrame,
+ setMinimized,
};
}
diff --git a/apps/web/src/components/engine/timeline/world.ts b/apps/web/src/components/engine/timeline/world.ts
index 331b368c..594805dc 100644
--- a/apps/web/src/components/engine/timeline/world.ts
+++ b/apps/web/src/components/engine/timeline/world.ts
@@ -27,6 +27,7 @@ export function createTimelineContext() {
currentLayerTop: 0,
currentLayerHeight: DEFAULT_CLIP_HEIGHT,
cursor: 'default' as CursorType,
+ minimized: false,
canvas: null as HTMLCanvasElement | null,
ctx: null as CanvasRenderingContext2D | null,
layout: new DOMRect(),
diff --git a/apps/web/src/components/sidebar-left/project-menu/view-menu.tsx b/apps/web/src/components/sidebar-left/project-menu/view-menu.tsx
index cce815af..26bda6fb 100644
--- a/apps/web/src/components/sidebar-left/project-menu/view-menu.tsx
+++ b/apps/web/src/components/sidebar-left/project-menu/view-menu.tsx
@@ -53,7 +53,7 @@ export function ViewMenu() {
<DropdownMenuItem onSelect={layout.toggleUI}>
Toggle UI
</DropdownMenuItem>
- <DropdownMenuItem onSelect={layout.toggleTimeline}>
+ <DropdownMenuItem onSelect={layout.toggleTimelineMinimized}>
Toggle timeline
</DropdownMenuItem>
</DropdownMenuGroup>
diff --git a/apps/web/src/components/timeline/layers/layers.tsx b/apps/web/src/components/timeline/layers/layers.tsx
index 5df4e340..c42a29ee 100644
--- a/apps/web/src/components/timeline/layers/layers.tsx
+++ b/apps/web/src/components/timeline/layers/layers.tsx
@@ -23,6 +23,7 @@ import { Tooltip, TooltipContent, TooltipPortal, TooltipTrigger } from '@/compon
import { DEFAULT_CLIP_HEIGHT, RULER_HEIGHT } from '@/components/engine/timeline/config';
import { useTimeline } from '@/context/timeline';
import { useEngine } from '@/context/engine';
+import { useLayout } from '@/context/layout';
import { togglePlayback, splitAtPlayhead, setComponent, clearComponent } from '@/components/engine';
import { useECS } from '@/context/ecs';
import { store } from '@/init';
@@ -40,6 +41,7 @@ export function Layers() {
const timeline = useTimeline();
const { world } = useEngine();
const { now, playing, looping } = useECS();
+ const { timelineMinimized, toggleTimelineMinimized } = useLayout();
const c = world.components;
const timelineIndex = world.timelineIndex;
@@ -92,6 +94,15 @@ export function Layers() {
clearComponent(world, c.Selected, false);
}
+ const handleHeaderDoubleClick = (e: MouseEvent) => {
+ if ((e.target as HTMLElement).closest('button')) return;
+ toggleTimelineMinimized();
+ }
+
+ createEffect(() => {
+ timeline.setMinimized(timelineMinimized());
+ });
+
onMount(timeline.mount);
onCleanup(timeline.unmount);
@@ -103,7 +114,10 @@ export function Layers() {
style={{ 'grid-template-rows': `${RULER_HEIGHT}px 1fr` }}
data-timeline-layers-container
>
- <div class="w-full z-10 flex flex-row gap-1 pl-2 pr-3 items-center text-muted-foreground">
+ <div
+ class="w-full z-10 flex flex-row gap-1 pl-2 pr-3 items-center text-muted-foreground select-none"
+ on:dblclick={handleHeaderDoubleClick}
+ >
<Tooltip placement="top">
<TooltipTrigger<typeof Button>
as={(triggerProps) => (
@@ -136,110 +150,112 @@ export function Layers() {
</TooltipContent>
</TooltipPortal>
</Tooltip>
- <Tooltip placement="top">
- <TooltipTrigger<typeof Button>
- as={(triggerProps) => (
- <Button {...triggerProps} variant="ghost" size="icon" onClick={() => splitAtPlayhead(world)}>
- <Icon name="split" class="size-6" />
- </Button>
- )}
- />
- <TooltipPortal>
- <TooltipContent shortcut="⌘B">Split at playhead</TooltipContent>
- </TooltipPortal>
- </Tooltip>
- <DropdownMenu>
+ <Show when={!timelineMinimized()}>
<Tooltip placement="top">
- <TooltipTrigger<typeof DropdownMenuTrigger>
- as={(triggerProps: object) => (
- <DropdownMenuTrigger<typeof Button>
- {...triggerProps}
- as={(buttonProps) => (
- <Button {...buttonProps} variant="ghost" size="icon">
- <Icon name="more-three-dots" class="size-6" />
- </Button>
- )}
- />
+ <TooltipTrigger<typeof Button>
+ as={(triggerProps) => (
+ <Button {...triggerProps} variant="ghost" size="icon" onClick={() => splitAtPlayhead(world)}>
+ <Icon name="split" class="size-6" />
+ </Button>
)}
/>
<TooltipPortal>
- <TooltipContent>More options</TooltipContent>
+ <TooltipContent shortcut="⌘B">Split at playhead</TooltipContent>
</TooltipPortal>
</Tooltip>
- <DropdownMenuPortal>
- <DropdownMenuContent class="w-[180px]">
- <DropdownMenuSub>
- <DropdownMenuSubTrigger>Layer height</DropdownMenuSubTrigger>
- <DropdownMenuPortal>
- <DropdownMenuSubContent class="w-[140px]">
- <DropdownMenuCheckboxItem
- onSelect={() => handleCommonClipHeightChange(28)}
- checked={commonLayerHeight() === 28}
- >
- Tight
- <span class="text-xxs text-muted-foreground ml-auto">28</span>
- </DropdownMenuCheckboxItem>
- <DropdownMenuCheckboxItem
- onSelect={() => handleCommonClipHeightChange(32)}
- checked={commonLayerHeight() === 32}
- >
- Snug
- <span class="text-xxs text-muted-foreground ml-auto">32</span>
- </DropdownMenuCheckboxItem>
- <DropdownMenuCheckboxItem
- onSelect={() => handleCommonClipHeightChange(40)}
- checked={commonLayerHeight() === 40}
- >
- Normal
- <span class="text-xxs text-muted-foreground ml-auto">40</span>
- </DropdownMenuCheckboxItem>
- <DropdownMenuCheckboxItem
- onSelect={() => handleCommonClipHeightChange(64)}
- checked={commonLayerHeight() === 64}
- >
- Relaxed
- <span class="text-xxs text-muted-foreground ml-auto">64</span>
- </DropdownMenuCheckboxItem>
- <DropdownMenuCheckboxItem
- onSelect={() => handleCommonClipHeightChange(116)}
- checked={commonLayerHeight() === 116}
- >
- Loose
- <span class="text-xxs text-muted-foreground ml-auto">116</span>
- </DropdownMenuCheckboxItem>
- </DropdownMenuSubContent>
- </DropdownMenuPortal>
- </DropdownMenuSub>
- <DropdownMenuSeparator />
- <DropdownMenuSub>
- <DropdownMenuSubTrigger>Time format</DropdownMenuSubTrigger>
- <DropdownMenuPortal>
- <DropdownMenuSubContent class="w-[200px]">
- <DropdownMenuRadioGroup
- value={timeFormat()}
- onChange={(value) => setTimeFormat(value as TimeFormat)}
- >
- <Index each={TIME_FORMAT_OPTIONS}>
- {(option) => (
- <DropdownMenuRadioItem value={option().value}>
- {option().label}
- <span class="text-xxs text-muted-foreground ml-auto">
- {option().example}
- </span>
- </DropdownMenuRadioItem>
- )}
- </Index>
- </DropdownMenuRadioGroup>
- </DropdownMenuSubContent>
- </DropdownMenuPortal>
- </DropdownMenuSub>
- <DropdownMenuSeparator />
- <DropdownMenuItem onSelect={addAdjustmentLayer}>
- Add adjustment layer
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenuPortal>
- </DropdownMenu>
+ <DropdownMenu>
+ <Tooltip placement="top">
+ <TooltipTrigger<typeof DropdownMenuTrigger>
+ as={(triggerProps: object) => (
+ <DropdownMenuTrigger<typeof Button>
+ {...triggerProps}
+ as={(buttonProps) => (
+ <Button {...buttonProps} variant="ghost" size="icon">
+ <Icon name="more-three-dots" class="size-6" />
+ </Button>
+ )}
+ />
+ )}
+ />
+ <TooltipPortal>
+ <TooltipContent>More options</TooltipContent>
+ </TooltipPortal>
+ </Tooltip>
+ <DropdownMenuPortal>
+ <DropdownMenuContent class="w-[180px]">
+ <DropdownMenuSub>
+ <DropdownMenuSubTrigger>Layer height</DropdownMenuSubTrigger>
+ <DropdownMenuPortal>
+ <DropdownMenuSubContent class="w-[140px]">
+ <DropdownMenuCheckboxItem
+ onSelect={() => handleCommonClipHeightChange(28)}
+ checked={commonLayerHeight() === 28}
+ >
+ Tight
+ <span class="text-xxs text-muted-foreground ml-auto">28</span>
+ </DropdownMenuCheckboxItem>
+ <DropdownMenuCheckboxItem
+ onSelect={() => handleCommonClipHeightChange(32)}
+ checked={commonLayerHeight() === 32}
+ >
+ Snug
+ <span class="text-xxs text-muted-foreground ml-auto">32</span>
+ </DropdownMenuCheckboxItem>
+ <DropdownMenuCheckboxItem
+ onSelect={() => handleCommonClipHeightChange(40)}
+ checked={commonLayerHeight() === 40}
+ >
+ Normal
+ <span class="text-xxs text-muted-foreground ml-auto">40</span>
+ </DropdownMenuCheckboxItem>
+ <DropdownMenuCheckboxItem
+ onSelect={() => handleCommonClipHeightChange(64)}
+ checked={commonLayerHeight() === 64}
+ >
+ Relaxed
+ <span class="text-xxs text-muted-foreground ml-auto">64</span>
+ </DropdownMenuCheckboxItem>
+ <DropdownMenuCheckboxItem
+ onSelect={() => handleCommonClipHeightChange(116)}
+ checked={commonLayerHeight() === 116}
+ >
+ Loose
+ <span class="text-xxs text-muted-foreground ml-auto">116</span>
+ </DropdownMenuCheckboxItem>
+ </DropdownMenuSubContent>
+ </DropdownMenuPortal>
+ </DropdownMenuSub>
+ <DropdownMenuSeparator />
+ <DropdownMenuSub>
+ <DropdownMenuSubTrigger>Time format</DropdownMenuSubTrigger>
+ <DropdownMenuPortal>
+ <DropdownMenuSubContent class="w-[200px]">
+ <DropdownMenuRadioGroup
+ value={timeFormat()}
+ onChange={(value) => setTimeFormat(value as TimeFormat)}
+ >
+ <Index each={TIME_FORMAT_OPTIONS}>
+ {(option) => (
+ <DropdownMenuRadioItem value={option().value}>
+ {option().label}
+ <span class="text-xxs text-muted-foreground ml-auto">
+ {option().example}
+ </span>
+ </DropdownMenuRadioItem>
+ )}
+ </Index>
+ </DropdownMenuRadioGroup>
+ </DropdownMenuSubContent>
+ </DropdownMenuPortal>
+ </DropdownMenuSub>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem onSelect={addAdjustmentLayer}>
+ Add adjustment layer
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenuPortal>
+ </DropdownMenu>
+ </Show>
<span class="text-xs font-mono font-thin ml-auto select-none">
{clock()}
</span>
diff --git a/apps/web/src/context/layout.tsx b/apps/web/src/context/layout.tsx
index d5fd6d6b..d5288bbd 100644
--- a/apps/web/src/context/layout.tsx
+++ b/apps/web/src/context/layout.tsx
@@ -10,10 +10,12 @@ import { store } from '@/init';
type LayoutContextValue = {
sidebarsVisible: Accessor<boolean>;
timelineVisible: Accessor<boolean>;
+ timelineMinimized: Accessor<boolean>;
timelineHeight: Accessor<number>;
setTimelineHeight(height: number): void;
toggleUI(): void;
toggleTimeline(): void;
+ toggleTimelineMinimized(): void;
};
const LayoutContext = createContext<LayoutContextValue>();
@@ -32,6 +34,9 @@ export function LayoutProvider(props: { children: JSX.Element }) {
const [timelineHeight, setTimelineHeight] = createStoredSignal(
store.define<number>('layout.timelineHeight', DEFAULT_TIMELINE_HEIGHT),
);
+ const [timelineMinimized, setTimelineMinimized] = createStoredSignal(
+ store.define<boolean>('layout.timelineMinimized', false),
+ );
const timelineVisible = () => sidebarsVisible() && timelinePreferred();
@@ -43,15 +48,21 @@ export function LayoutProvider(props: { children: JSX.Element }) {
setTimelinePreferred(!timelinePreferred());
};
+ const toggleTimelineMinimized = () => {
+ setTimelineMinimized(!timelineMinimized());
+ };
+
return (
<LayoutContext.Provider
value={{
sidebarsVisible,
timelineVisible,
+ timelineMinimized,
timelineHeight,
setTimelineHeight,
toggleUI,
toggleTimeline,
+ toggleTimelineMinimized,
}}>
{props.children}
</LayoutContext.Provider>
diff --git a/apps/web/src/pages/editor.tsx b/apps/web/src/pages/editor.tsx
index b6695fef..58d748ba 100644
--- a/apps/web/src/pages/editor.tsx
+++ b/apps/web/src/pages/editor.tsx
@@ -9,19 +9,22 @@ import { Soundboard, Inspector } from "@/components/sidebar-right";
import { FloatingProjectHeader, SidebarLeft } from "@/components/sidebar-left";
import { useLayout, MIN_TIMELINE_HEIGHT } from "@/context/layout";
import { useEditorApi } from "@/context/editor-api";
+import { RULER_HEIGHT } from "@/components/engine/timeline/config";
const MIN_CANVAS_HEIGHT = 200;
export function EditorPage() {
- const { sidebarsVisible, timelineVisible, timelineHeight, setTimelineHeight } = useLayout();
+ const { sidebarsVisible, timelineVisible, timelineMinimized, timelineHeight, setTimelineHeight } = useLayout();
const { isDesktop, isFullscreen } = useEditorApi();
const [resizing, setResizing] = createSignal(false);
const timelineStyles = createMemo(() => {
if (!timelineVisible()) return;
+ const height = timelineMinimized() ? RULER_HEIGHT : timelineHeight();
+
return {
- 'grid-template-rows': `1fr 1px ${timelineHeight()}px`,
+ 'grid-template-rows': `1fr 1px ${height}px`,
};
});
@@ -76,15 +79,17 @@ export function EditorPage() {
</Show>
<Show when={timelineVisible()}>
<div class="col-span-full bg-border-strong relative">
- <div
- class="absolute left-0 right-0 -top-px h-[3px] z-10 cursor-ns-resize group"
- onPointerDown={handleResizeStart}
- >
+ <Show when={!timelineMinimized()}>
<div
- class="absolute left-0 right-0 top-px h-px transition-colors group-hover:bg-primary"
- classList={{ 'bg-primary': resizing() }}
- />
- </div>
+ class="absolute left-0 right-0 -top-px h-[3px] z-10 cursor-ns-resize group"
+ onPointerDown={handleResizeStart}
+ >
+ <div
+ class="absolute left-0 right-0 top-px h-px transition-colors group-hover:bg-primary"
+ classList={{ 'bg-primary': resizing() }}
+ />
+ </div>
+ </Show>
</div>
</Show>
<Show when={timelineVisible()}>
@@ -96,7 +101,9 @@ export function EditorPage() {
</Show>
<Show when={timelineVisible()}>
<div class="bg-border-strong" />
- <Soundboard />
+ <Show when={!timelineMinimized()}>
+ <Soundboard />
+ </Show>
</Show>
<Show when={!sidebarsVisible()}>
<FloatingProjectHeader />