The open source AI video agent: turns any coding agent into a video agent, with an editor to change anything it makes.
Studio: a page laid out at the canvas's size is not the film's first picture for "Original" (#220)
WEBGRSdfa9849e3d1b
diff --git a/.changeset/canvas-original-past-pages.md b/.changeset/canvas-original-past-pages.mdnew file mode 100644index 0000000..13e2f42--- /dev/null+++ b/.changeset/canvas-original-past-pages.md@@ -0,0 +1,5 @@+---+"openfilm": patch+---++Studio: a film whose first picture is a page laid out at the canvas's size (most pages an agent writes) shows its canvas as what it is (16:9) instead of "Original". "Original" is the shape of the first picture with a size of its own: a video, a still, or a page that sets its size.diff --git a/packages/openfilm/studio/ui/src/components/ProjectView.tsx b/packages/openfilm/studio/ui/src/components/ProjectView.tsxindex 5c5f8ac..9a9ecd0 100644--- a/packages/openfilm/studio/ui/src/components/ProjectView.tsx+++ b/packages/openfilm/studio/ui/src/components/ProjectView.tsx@@ -47,7 +47,7 @@ import { clipThumbId, overridesToken } from '@/lib/thumb-frame';import { useLoadedThumbs } from '@/lib/use-loaded-thumbs';import { droppedOverrides, overrideTarget, undoneFields, type DroppedEdits, type PersonEdit } from '@/lib/dropped-overrides';import { filmFrameBox, type FilmFrameId } from '@/lib/film-frame';-import { canvasFor, fitToCanvas } from '@/lib/canvas-fit';+import { canvasFor, firstPictureSize, fitToCanvas } from '@/lib/canvas-fit';import { factsOfProbe, mediaListingOf, resourceKindOf, srcHitsAsset, warmProjectMedia, type MediaListing, type MediaProxy, type MediaResult, type MediaSources, type WorkspaceResource } from '@/lib/workspace-resources';import { BrandLoadingScreen } from './BrandLoadingScreen';import { BrandLogo } from './BrandLogo';@@ -2244,14 +2244,8 @@ export function ProjectView({ projectId, onProject, onLeave }: {keeps the canvas's short side (canvasFor; a typed size is that size), and every picture on it is scaled by onefactor into the new canvas, centered, in the same edit (one undo). Laying the film out again for the new canvasis the agent's (the inspector gives the words) */- /* "Fit (original)": the shape of the film's first picture (the earliest on the film whose size the preview knows) */- const originalSize = React.useMemo(() => {- const sized = new Map(spans.filter((span) => span.w && span.h).map((span) => [span.id, { w: span.w!, h: span.h! }]));- const first = (film.film?.tracks ?? []).flatMap((track) => track.clips)- .filter((clip) => !clip.sound && filmSrcKind(clip.src) !== 'sound' && sized.has(clip.id))- .sort((a, b) => (a.at ?? 0) - (b.at ?? 0))[0];- return first ? sized.get(first.id) ?? null : null;- }, [spans, film.film]);+ /* "Fit (original)": the shape of the film's first picture (canvas-fit's firstPictureSize) */+ const originalSize = React.useMemo(() => firstPictureSize((film.film?.tracks ?? []).flatMap((track) => track.clips), spans), [spans, film.film]);/** The edit that makes the canvas `size`, the film fitted into it (see canvas-fit). */const canvasOps = React.useCallback((size: { w: number; h: number }): Op[] => {const own = new Map(spans.map((span) => [span.id, span.w && span.h ? { w: span.w, h: span.h } : null]));diff --git a/packages/openfilm/studio/ui/src/lib/canvas-fit.test.ts b/packages/openfilm/studio/ui/src/lib/canvas-fit.test.tsindex 308a551..677fa26 100644--- a/packages/openfilm/studio/ui/src/lib/canvas-fit.test.ts+++ b/packages/openfilm/studio/ui/src/lib/canvas-fit.test.ts@@ -1,6 +1,6 @@import { test } from 'node:test';import assert from 'node:assert/strict';-import { canvasFor, canvasSide, fitToCanvas, originalShape } from './canvas-fit.ts';+import { canvasFor, canvasSide, firstPictureSize, fitToCanvas, originalShape } from './canvas-fit.ts';const wide = { w: 1920, h: 1080 }, tall = { w: 1080, h: 1440 }, cinema = { w: 2538, h: 1080 };const boxOf = (out: ReturnType<typeof fitToCanvas>, id: string) => out.find((c) => c.id === id)?.box;@@ -59,6 +59,26 @@ test('a canvas side typed or dragged stays in reason: 16 to 8192 px, even, at moassert.equal(canvasSide(2, 40), 16);});+test('the first picture is the earliest one with a size of its own: a page laid out at the canvas\'s has none', () => {+ const clips = [+ { id: 'title', src: 'title.html', at: 0 },+ { id: 'bed', src: 'assets/bed.m4a', at: 0, sound: true },+ { id: 'shot', src: 'assets/shot.mp4', at: 5 },+ { id: 'card', src: 'card.html', at: 9 },+ ];+ const spans = [+ { id: 'title', w: 1920, h: 1080, reflows: true as const },+ { id: 'shot', w: 1080, h: 1920 },+ { id: 'card', w: 1200, h: 1200 },+ ];+ assert.deepEqual(firstPictureSize(clips, spans), { w: 1080, h: 1920 }, 'past the page that takes the canvas\'s size');+ /* a film of such pages has no Original: the canvas shows its own shape (16:9), not "Original" */+ assert.equal(firstPictureSize(clips.slice(0, 2), spans), null);+ assert.equal(originalShape(wide, firstPictureSize(clips.slice(0, 2), spans)).current, false);+ /* a page with its own size is a picture like any other */+ assert.deepEqual(firstPictureSize([clips[3]], spans), { w: 1200, h: 1200 });+});+test('Original is the first picture\'s shape, current when the stage has it', () => {assert.deepEqual(originalShape(wide, { w: 3840, h: 2160 }), { frame: '3840:2160', current: true });assert.deepEqual(originalShape(tall, { w: 1080, h: 1920 }), { frame: '1080:1920', current: false });diff --git a/packages/openfilm/studio/ui/src/lib/canvas-fit.ts b/packages/openfilm/studio/ui/src/lib/canvas-fit.tsindex 82a3863..158178c 100644--- a/packages/openfilm/studio/ui/src/lib/canvas-fit.ts+++ b/packages/openfilm/studio/ui/src/lib/canvas-fit.ts@@ -12,7 +12,7 @@*/import { pictureRect } from '../../../../src/film-doc.mjs';import { customFilmFrame, frameRatioOf, type FilmFrameId } from './film-frame.ts';-import type { FilmBox, FilmSrcKind } from './film.ts';+import { filmSrcKind, type FilmBox, type FilmSrcKind } from './film.ts';type Size = { w: number; h: number };@@ -90,6 +90,22 @@ export function fitToCanvas(clips: readonly CanvasClip[], from: Size, to: Size):/** Whether the stage has this ratio: its width within 2 px of it (a size made from a ratio is rounded to even px). */export const shaped = (stage: Size, ratio: number) => Math.abs(stage.w - stage.h * ratio) <= 2;+/**+ * The film's first picture's own size, which "Original" fits the canvas to: the earliest clip on the film with a+ * picture whose size the preview knows (`spans`). A page that sets no size of its own is passed over: it is laid out at+ * the canvas's size, so it has no shape of its own, and a film of such pages would always read as "Original".+ */+export function firstPictureSize(+ clips: readonly { id: string; src: string; at?: number | null; sound?: unknown }[],+ spans: readonly { id: string; w?: number; h?: number; reflows?: true }[],+): Size | null {+ const sized = new Map(spans.filter((span) => span.w && span.h && !span.reflows).map((span) => [span.id, { w: span.w!, h: span.h! }]));+ const first = clips+ .filter((clip) => !clip.sound && filmSrcKind(clip.src) !== 'sound' && sized.has(clip.id))+ .sort((a, b) => (a.at ?? 0) - (b.at ?? 0))[0];+ return first ? sized.get(first.id) ?? null : null;+}+/*** The canvas's "Original" shape: the first picture's own (`original`), when there is one and it is between 1:4 and* 4:1; and whether the stage has it now.