Skip to content

armgit / hypit

Public Imported from GitHub
0

Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.

fix(timeline): preflight exact authored frame boundaries

kashorin5885c00b702b
diff --git a/packages/timeline-author/src/surface.ts b/packages/timeline-author/src/surface.ts
index 57feccd7..d1b3544f 100644
--- a/packages/timeline-author/src/surface.ts
+++ b/packages/timeline-author/src/surface.ts
@@ -7,10 +7,12 @@ import {
resolveTemporalContext,
} from "@hypit/hypit/temporal/markup";
import { timelineTypes } from "@hypit/hypit/timeline";
+import type { Clock } from "@hypit/hypit/timeline";
import { compileTimelineAuthorFragment } from "./fragment.js";
import { timelineAuthorTypes } from "./manifest.js";
-import type { TimelineAuthorDeclaration } from "./types.js";
+import { constructionDuration } from "./program.js";
+import type { ConstructionDurationSpec, TimelineAuthorDeclaration } from "./types.js";
function reference(
element: StructuredElement,
@@ -83,6 +85,21 @@ export const decodeTimelineAuthorSurface: StructuredSurfaceHandler = ({ element,
}
const plan = compileTimelineAuthorFragment({ id, end, declarations });
+ const staticClock = clock.record?.value.kind === "inline"
+ ? clock.record.value.value as unknown as Clock
+ : undefined;
+ if (staticClock !== undefined) {
+ for (const item of plan.inlineInputs) {
+ if (!sameType(item.type, timelineAuthorTypes.duration)) continue;
+ try {
+ constructionDuration(staticClock, (item.value as ConstructionDurationSpec).duration);
+ } catch (error) {
+ if (!(error instanceof Error)) throw error;
+ const { numerator, denominator } = staticClock.frameRate;
+ throw new Error(`Timeline ${id} at ${numerator}/${denominator} fps: ${error.message}`);
+ }
+ }
+ }
const authoredRange = (item: (typeof plan.inlineInputs)[number]) => {
if (item.author?.declarationId === undefined) return element.range;
const child = element.children.find((candidate) => candidate.kind === "element"
diff --git a/packages/timeline-author/test/surface.test.ts b/packages/timeline-author/test/surface.test.ts
index 6c9e12b3..573b45a1 100644
--- a/packages/timeline-author/test/surface.test.ts
+++ b/packages/timeline-author/test/surface.test.ts
@@ -18,6 +18,19 @@ const absoluteReferences = new Map([
["answer-end", { path: "answer-end", type: temporalTypes.instant, ref: { kind: "record" as const, id: "answer-end" } }],
]);
+function clockReference(numerator: number, denominator = 1) {
+ return {
+ path: "clock",
+ type: timelineTypes.clock,
+ ref: { kind: "record" as const, id: "clock" },
+ record: {
+ id: "clock",
+ type: timelineTypes.clock,
+ value: { kind: "inline" as const, value: { frameRate: { numerator, denominator } } },
+ },
+ };
+}
+
test("Timeline Surface publishes its range and every named Instant or Window", async () => {
const source = `<time:Timeline id="film" clock={clock} end="latest(speech.end,outro.end)">
<time:Window id="outro" from="private-cue" for="3s"/>
@@ -56,6 +69,48 @@ test("Timeline Window requires exactly two of from, until and for", () => {
}), /exactly two/);
});
+test("Timeline Surface rejects every static duration literal between frame boundaries", () => {
+ for (const source of [
+ '<time:Timeline id="film" clock={clock} end="4.25s"/>',
+ '<time:Timeline id="film" clock={clock} end="3s"><time:Window id="tail" from="start" for="250ms"/></time:Timeline>',
+ '<time:Timeline id="film" clock={clock} end="3s"><time:Instant id="cue" at="start+250ms"/></time:Timeline>',
+ ]) {
+ const element = parseStructuredElement({ name: "timeline.svml", text: source }, 0).element;
+ assert.throws(() => decodeTimelineAuthorSurface({
+ sourceName: "timeline.svml", element,
+ resolveReference: () => clockReference(30),
+ resolveAsset: async () => { throw new Error("unused"); },
+ }), /Timeline film at 30\/1 fps: Timeline construction duration must resolve to a non-negative exact frame extent/);
+ }
+});
+
+test("Timeline Surface accepts exact static frame boundaries at rational rates", async () => {
+ const source = `<time:Timeline id="film" clock={clock} end="1001ms">
+ <time:Window id="tail" until="end" for="1001ms"/>
+ </time:Timeline>`;
+ const element = parseStructuredElement({ name: "timeline.svml", text: source }, 0).element;
+ const output = await decodeTimelineAuthorSurface({
+ sourceName: "timeline.svml", element,
+ resolveReference: () => clockReference(30_000, 1_001),
+ resolveAsset: async () => { throw new Error("unused"); },
+ });
+ assert.equal(output.exports?.includes("film.timeline"), true);
+ assert.equal(output.exports?.includes("film.tail"), true);
+});
+
+test("Timeline Surface defers frame-boundary validation for runtime Clock values", async () => {
+ const source = '<time:Timeline id="film" clock={clock} end="4.25s"/>';
+ const element = parseStructuredElement({ name: "timeline.svml", text: source }, 0).element;
+ const output = await decodeTimelineAuthorSurface({
+ sourceName: "timeline.svml", element,
+ resolveReference: () => ({
+ path: "clock", type: timelineTypes.clock, ref: { kind: "component-output", component: "runtime-clock", output: "clock" },
+ }),
+ resolveAsset: async () => { throw new Error("unused"); },
+ });
+ assert.equal(output.exports?.includes("film.timeline"), true);
+});
+
test("standalone Window publishes one reusable value and its boundaries", async () => {
const element = parseStructuredElement({ name: "timeline.svml", text:
'<time:Window id="reveal-band" timeline={film.timeline} from={reveal} until={answer-end}/>' }, 0).element;