Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
fix(cli): bound timeline bars for negative media starts (#5239)
Abdullah M. Nazif83b2f5608f55
diff --git a/packages/cli/src/timeline/describeProject.test.ts b/packages/cli/src/timeline/describeProject.test.tsindex 94538fd178..16d1d24c9f 100644--- a/packages/cli/src/timeline/describeProject.test.ts+++ b/packages/cli/src/timeline/describeProject.test.ts@@ -391,6 +391,80 @@ describe("absolute main-timeline time", () => {expect(rows.find((r) => r.id === "nested")).toMatchObject({ absStart: 2, absEnd: 4 });});+ it.each([+ {+ basis: "global",+ start: -1,+ duration: 3,+ absoluteStart: -1,+ absoluteEnd: 2,+ expectedBar: "█".repeat(16) + " ".repeat(24),+ },+ {+ basis: "local",+ start: -2,+ duration: 3,+ absoluteStart: -1,+ absoluteEnd: 2,+ expectedBar: "█".repeat(16) + " ".repeat(24),+ },+ {+ basis: "global",+ start: -0.001,+ duration: 1.001,+ absoluteStart: -0.001,+ absoluteEnd: 1,+ expectedBar: "█".repeat(8) + " ".repeat(32),+ },+ {+ basis: "global",+ start: -2,+ duration: 10,+ absoluteStart: -2,+ absoluteEnd: 8,+ expectedBar: "█".repeat(40),+ },+ {+ basis: "global",+ start: 0,+ duration: 3,+ absoluteStart: 0,+ absoluteEnd: 3,+ expectedBar: "█".repeat(24) + " ".repeat(16),+ },+ {+ basis: "global",+ start: 1,+ duration: 3,+ absoluteStart: 1,+ absoluteEnd: 4,+ expectedBar: " ".repeat(8) + "█".repeat(24) + " ".repeat(8),+ },+ ])(+ "prints a bounded bar for $basis media at $start without changing timing",+ async ({ basis, start, duration, absoluteStart, absoluteEnd, expectedBar }) => {+ dir = tempDir("hf-timeline-bar-");+ mkdirSync(join(dir, "compositions"));+ writeFileSync(+ join(dir, "index.html"),+ '<div data-composition-id="main" data-duration="5"><div id="host" data-composition-src="compositions/scene.html" data-start="1" data-duration="3"></div></div>',+ );+ writeFileSync(+ join(dir, "compositions", "scene.html"),+ `<div data-composition-id="scene"><audio id="voice" data-start="${start}" data-duration="${duration}" data-hf-media-start-basis="${basis}"></audio></div>`,+ );+ const timeline = await describeProject(join(dir, "index.html"));+ const voice = allRows(timeline).find((row) => row.id === "voice");+ expect(voice).toMatchObject({ absStart: absoluteStart, absEnd: absoluteEnd });++ const output = formatTimeline(timeline);+ const line = output.split("\n").find((line) => line.includes("#voice voice"));+ expect(line).toContain(`|${expectedBar}|`);+ expect(line).toContain(`voice ${absoluteStart}-${absoluteEnd}s`);+ expect(voice).toMatchObject({ absStart: absoluteStart, absEnd: absoluteEnd });+ },+ );+it("resolves a media start given as an expression like any other clip, not as a literal", async () => {dir = tempDir("hf-timeline-expr-");mkdirSync(join(dir, "compositions"));diff --git a/packages/cli/src/timeline/formatTimeline.ts b/packages/cli/src/timeline/formatTimeline.tsindex 2b8b0862c4..99481dac0f 100644--- a/packages/cli/src/timeline/formatTimeline.ts+++ b/packages/cli/src/timeline/formatTimeline.ts@@ -6,7 +6,7 @@ const n = (v: number) => String(Math.round(v * 1000) / 1000);function bar(row: TimelineRow, total: number): string {if (total <= 0) return " ".repeat(BAR_WIDTH);const known = row.durationAuthored || row.duration > 0;- const from = Math.min(BAR_WIDTH - 1, Math.floor((row.absStart / total) * BAR_WIDTH));+ const from = Math.max(0, Math.min(BAR_WIDTH - 1, Math.floor((row.absStart / total) * BAR_WIDTH)));const to = known ? (row.absEnd / total) * BAR_WIDTH : BAR_WIDTH;const width = Math.max(1, Math.min(BAR_WIDTH, Math.ceil(to)) - from);const fill = known ? "█" : "░";