Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Fit preview handles to clip bounds

Bitti18669891b1fa
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 8ecd44d..c10ebf8 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -24,6 +24,7 @@ Changes since 0.3.2.
- Improved video playback, thumbnails and Back navigation.
- Video folders stack vertically beside video cards in grid view.
- The Timeline scene list browses video folders and videos, with Back as the first item inside each.
+- Timeline preview selection follows the clip's displayed bounds, with correct move and resize gestures for portrait projects.
- Clicking empty space in the video or music library clears the selection.
- Image edits preserve their sources and settings. Generator lists and inspector controls are more compact and consistently ordered.
- Corrected First/Last Frame prompts, cached VAE checks across restarts and fixed AppImage launcher permissions.
diff --git a/src/components/workspace/ProgramMonitor.test.tsx b/src/components/workspace/ProgramMonitor.test.tsx
index 7d06411..ff23690 100644
--- a/src/components/workspace/ProgramMonitor.test.tsx
+++ b/src/components/workspace/ProgramMonitor.test.tsx
@@ -334,6 +334,84 @@ describe("the program monitor", () => {
expect(screen.getByRole("button", { name: "Rotate clip" })).toBeTruthy();
});
+ it.each([[1080, 1350, 600], [1920, 1080, 270]])("fits selection to a %sx%s clip in a 4:5 project and moves and resizes it", (width, height, fittedHeight) => {
+ let panelWidth = 1000, panelHeight = 600;
+ vi.spyOn(HTMLElement.prototype, "clientWidth", "get").mockImplementation(function (this: HTMLElement) { return this.classList.contains("program-picture") ? panelWidth : 0; });
+ vi.spyOn(HTMLElement.prototype, "clientHeight", "get").mockImplementation(function (this: HTMLElement) { return this.classList.contains("program-picture") ? panelHeight : 0; });
+ let resized = () => {};
+ vi.stubGlobal("ResizeObserver", class { constructor(callback: () => void) { resized = callback; } observe() {} disconnect() {} });
+ const initial = project([clip()]);
+ initial.settings.aspectRatio = "4:5";
+ initial.assets[0] = { ...initial.assets[0], width, height };
+ const changed = vi.fn(), paused = vi.fn();
+ function Harness() {
+ const [config, setConfig] = useState(initial);
+ return <ProgramMonitor config={config} folderPath="C:/Project" playheadMs={3000} playing={false}
+ selectedClipId="clip-1" onSelectClip={() => {}} onSeek={() => {}} onPlayingChange={paused}
+ onTransformChange={(id, transform) => {
+ changed(id, transform);
+ setConfig((current) => ({ ...current, timeline: { tracks: current.timeline.tracks.map((track) => ({ ...track,
+ clips: track.clips.map((item) => item.id === id ? { ...item, transform } : item) })) } }));
+ }} />;
+ }
+ const { container } = render(<Harness />);
+ const picture = container.querySelector(".program-picture") as HTMLElement;
+ picture.getBoundingClientRect = () => ({ left: 20, top: 30, width: panelWidth, height: panelHeight }) as DOMRect;
+ fireEvent.click(picture);
+ const box = screen.getByRole("group", { name: "Transform Macro footage" });
+ expect(box.style.width).toBe("480px");
+ expect(box.style.height).toBe(`${fittedHeight}px`);
+ expect(box.style.left).toBe("260px");
+ expect(box.style.top).toBe(`${(600 - fittedHeight) / 2}px`);
+ const pointer = (target: Element, type: string, x: number, y: number) => {
+ const event = new Event(type, { bubbles: true });
+ Object.defineProperties(event, { pointerId: { value: 1 }, button: { value: 0 }, clientX: { value: x }, clientY: { value: y } });
+ fireEvent(target, event);
+ };
+ pointer(box, "pointerdown", 520, 330);
+ pointer(box, "pointermove", 568, 390);
+ pointer(box, "pointerup", 568, 390);
+ expect(paused).toHaveBeenCalledWith(false);
+ expect(changed).toHaveBeenLastCalledWith("clip-1", expect.objectContaining({ positionX: 10, positionY: 10, scale: 100 }));
+ expect(box.style.transform).toContain("translate(48px, 60px)");
+ const handle = screen.getByRole("button", { name: "Scale clip" });
+ pointer(handle, "pointerdown", 808, 390 + fittedHeight / 2);
+ pointer(handle, "pointermove", 928, 390 + fittedHeight * 0.75);
+ pointer(handle, "pointerup", 928, 390 + fittedHeight * 0.75);
+ expect(changed.mock.calls.at(-1)![1].scale).toBeCloseTo(150);
+ expect(box.style.transform).toContain("scale(1.5)");
+ const calls = changed.mock.calls.length;
+ pointer(box, "pointermove", 980, 800);
+ expect(changed).toHaveBeenCalledTimes(calls);
+ act(() => { panelWidth = 800; panelHeight = 400; resized(); });
+ expect(box.style.width).toBe("320px");
+ expect(box.style.height).toBe(`${fittedHeight * 2 / 3}px`);
+ expect(box.style.left).toBe("240px");
+ expect(box.style.transform).toContain("translate(32px, 40px)");
+ });
+
+ it("uses decoded clip dimensions when imported media has no saved size", async () => {
+ vi.spyOn(HTMLMediaElement.prototype, "pause").mockImplementation(() => undefined);
+ vi.spyOn(HTMLElement.prototype, "clientWidth", "get").mockReturnValue(1000);
+ vi.spyOn(HTMLElement.prototype, "clientHeight", "get").mockReturnValue(600);
+ vi.spyOn(PreviewSources.prototype, "url").mockResolvedValue("blob:clip");
+ const config = project([clip()]);
+ config.settings.aspectRatio = "4:5";
+ config.assets[0] = { ...config.assets[0], width: null, height: null };
+ const view = render(<ProgramMonitor config={config} folderPath="C:/Project" playheadMs={3000} playing={false}
+ selectedClipId="clip-1" onSelectClip={() => {}} onSeek={() => {}} onPlayingChange={() => {}} onTransformChange={() => {}} />);
+ await act(async () => {});
+ fireEvent.click(view.container.querySelector(".program-picture")!);
+ const box = screen.getByRole("group", { name: "Transform Macro footage" });
+ expect(box.style.height).toBe("600px");
+ const video = view.container.querySelector("video")!;
+ Object.defineProperties(video, { videoWidth: { value: 1920 }, videoHeight: { value: 1080 } });
+ fireEvent.loadedData(video);
+ expect(box.style.width).toBe("480px");
+ expect(box.style.height).toBe("270px");
+ expect(box.style.top).toBe("165px");
+ });
+
it("shows a gap as the empty frame it will be exported as, and says nothing about it", () => {
const { container } = monitor(project([clip()]), 9_000);
// No element for a clip that is not there, and no panel over the picture
diff --git a/src/components/workspace/ProgramMonitor.tsx b/src/components/workspace/ProgramMonitor.tsx
index ea911f1..2e32dde 100644
--- a/src/components/workspace/ProgramMonitor.tsx
+++ b/src/components/workspace/ProgramMonitor.tsx
@@ -4,7 +4,7 @@ import { clipPlaybackRate, clipSourceTimeMs } from "../../lib/clipTiming";
import { ProgramLayer } from "./ProgramLayer";
import { ProgramPicture } from "./ProgramPicture";
import { Film16 } from "../ui/icons";
-import { useCallback, useEffect, useMemo, useRef, useState } from "react";
+import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
import { clipFrameStyle, clipVisualSettings, outputDimensions, fitRect } from "../../lib/export";
import { isTauri } from "../../lib/persistence";
import type { ClipTransform, ProjectAsset, ProjectConfig, TimelineClip } from "../../lib/project";
@@ -151,17 +151,32 @@ export function ProgramMonitor({ config, folderPath, playheadMs, playing, rate =
const media = useMemo(() => new PreviewMedia(), [folderPath]);
const [composited, setComposited] = useState(false);
const [pictureSize, setPictureSize] = useState({ width: 0, height: 0 });
- useEffect(() => {
+ useLayoutEffect(() => {
const element = pictureRef.current;
- if (!element || !asset?.motion) return;
+ if (!element) return;
const measure = () => setPictureSize({ width: element.clientWidth, height: element.clientHeight });
measure();
if (typeof ResizeObserver === "undefined") return;
const observer = new ResizeObserver(measure); observer.observe(element);
return () => observer.disconnect();
- }, [Boolean(asset?.motion)]);
+ }, []);
+ const [decodedSize, setDecodedSize] = useState<{ key: string; width: number; height: number } | null>(null);
+ const playerKey = clip ? playerKeys.get(clip.id) ?? clip.id : null;
+ useEffect(() => {
+ if (!playerKey) return;
+ const measure = () => {
+ const element = media.get(playerKey);
+ const width = element instanceof HTMLVideoElement ? element.videoWidth : element instanceof HTMLImageElement ? element.naturalWidth : element?.width;
+ const height = element instanceof HTMLVideoElement ? element.videoHeight : element instanceof HTMLImageElement ? element.naturalHeight : element?.height;
+ if (width && height) setDecodedSize((current) => current?.key === playerKey && current.width === width && current.height === height ? current : { key: playerKey, width, height });
+ };
+ measure();
+ return media.subscribe(measure);
+ }, [media, playerKey]);
const dimensions = outputDimensions(config.settings.resolution, config.settings.aspectRatio);
const projectFit = fitRect(dimensions.width, dimensions.height, pictureSize.width || dimensions.width, pictureSize.height || dimensions.height);
+ const sourceSize = decodedSize?.key === playerKey ? decodedSize : asset;
+ const clipFit = fitRect(sourceSize?.width ?? dimensions.width, sourceSize?.height ?? dimensions.height, projectFit.width, projectFit.height);
const motionFit = asset?.motion ? fitRect(asset.motion.width, asset.motion.height, projectFit.width, projectFit.height) : projectFit;
const previewScale = Math.min(1, 1280 / Math.max(dimensions.width, dimensions.height));
useEffect(() => () => sources.dispose(), [sources]);
@@ -292,7 +307,7 @@ export function ProgramMonitor({ config, folderPath, playheadMs, playing, rate =
const hasClips = tracks.some((track) => track.clips.length > 0);
const beginTransform = (kind: TransformGesture["kind"], event: React.PointerEvent<HTMLElement>) => {
- if (!clip || !frameStyle || transformEditingDisabled || !onTransformChange) return;
+ if (event.button !== 0 || !clip || !frameStyle || transformEditingDisabled || !onTransformChange) return;
const bounds = pictureRef.current?.getBoundingClientRect();
if (!bounds || bounds.width <= 0 || bounds.height <= 0) return;
event.preventDefault();
@@ -300,8 +315,9 @@ export function ProgramMonitor({ config, folderPath, playheadMs, playing, rate =
event.currentTarget.setPointerCapture?.(event.pointerId);
onPlayingChange(false);
const initial = frameStyle.transform;
- const centerX = bounds.left + bounds.width / 2 + bounds.width * initial.positionX / 100;
- const centerY = bounds.top + bounds.height / 2 + bounds.height * initial.positionY / 100;
+ const frame = fitRect(dimensions.width, dimensions.height, bounds.width, bounds.height);
+ const centerX = bounds.left + frame.x + frame.width / 2 + frame.width * initial.positionX / 100;
+ const centerY = bounds.top + frame.y + frame.height / 2 + frame.height * initial.positionY / 100;
transformGesture.current = {
kind,
pointerId: event.pointerId,
@@ -312,8 +328,8 @@ export function ProgramMonitor({ config, folderPath, playheadMs, playing, rate =
startDistance: Math.max(1, Math.hypot(event.clientX - centerX, event.clientY - centerY)),
startAngle: angleAt(event.clientX, event.clientY, centerX, centerY),
initial,
- frameWidth: bounds.width,
- frameHeight: bounds.height,
+ frameWidth: frame.width,
+ frameHeight: frame.height,
captureTarget: event.currentTarget,
};
};
@@ -377,7 +393,7 @@ export function ProgramMonitor({ config, folderPath, playheadMs, playing, rate =
<ProgramPicture key={folderPath} media={media} playerKeys={playerKeys} layers={layers} playheadMs={playheadMs}
width={Math.round(dimensions.width * previewScale)} height={Math.round(dimensions.height * previewScale)}
background={config.settings.backgroundColor} onAvailable={setComposited} />
- <div className="program-media">{prepared.map(({ clip: layer, prepareAtMs, playerKey }) => {
+ <div className="program-media" style={{ left: projectFit.x, top: projectFit.y, width: projectFit.width, height: projectFit.height }}>{prepared.map(({ clip: layer, prepareAtMs, playerKey }) => {
const depth = layers.findIndex((visible) => visible.id === layer.id);
return <ProgramLayer
key={`${folderPath}:${playerKey}`}
@@ -406,13 +422,15 @@ export function ProgramMonitor({ config, folderPath, playheadMs, playing, rate =
</div>}
{clip && !asset?.motion && frameStyle && editingClipId === clip.id && onTransformChange && !transformEditingDisabled && <div
className="program-transform"
- style={{ transform: `translate(${frameStyle.transform.positionX}%, ${frameStyle.transform.positionY}%) scale(${frameStyle.transform.scale / 100}) rotate(${frameStyle.transform.rotation}deg)` }}
+ style={{ left: projectFit.x + clipFit.x, top: projectFit.y + clipFit.y, width: clipFit.width, height: clipFit.height,
+ transform: `translate(${frameStyle.transform.positionX / 100 * projectFit.width}px, ${frameStyle.transform.positionY / 100 * projectFit.height}px) scale(${frameStyle.transform.scale / 100}) rotate(${frameStyle.transform.rotation}deg)` }}
role="group"
aria-label={`Transform ${clip.label}`}
onPointerDown={(event) => beginTransform("move", event)}
onPointerMove={moveTransform}
onPointerUp={endTransform}
onPointerCancel={endTransform}
+ onLostPointerCapture={endTransform}
>
<button className="program-transform__rotate" type="button" aria-label="Rotate clip" data-tooltip="Drag to rotate" onPointerDown={(event) => beginTransform("rotate", event)} />
<button className="program-transform__scale program-transform__scale--br" type="button" aria-label="Scale clip" data-tooltip="Drag to scale" onPointerDown={(event) => beginTransform("scale", event)} />
diff --git a/src/styles/timeline.css b/src/styles/timeline.css
index bb41d73..8510430 100644
--- a/src/styles/timeline.css
+++ b/src/styles/timeline.css
@@ -494,7 +494,7 @@
.program-transform {
position: absolute;
z-index: 3;
- inset: 10px;
+ box-sizing: border-box;
border: 1px solid var(--accent-bright);
cursor: move;
touch-action: none;
@@ -1728,7 +1728,7 @@ button.transport-time:hover { background: var(--fill-subtle-hover); }
background: var(--panel);
}
-.program-media { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
+.program-media { position: absolute; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.program-composited-picture { position: absolute; inset: 0; pointer-events: none; }
.program-layer { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.program-picture > video, .program-picture > img, .program-keyed-picture { position: absolute; inset: 0; }