Skip to content

Commit 5721b91

Browse files
authored
Merge branch 'main' into fix/lint-tag-source-bounds
2 parents 84d6226 + fdf9ffa commit 5721b91

17 files changed

Lines changed: 215 additions & 19 deletions

File tree

‎packages/core/src/runtime/init.test.ts‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,6 +2344,53 @@ describe("initSandboxRuntimeModular", () => {
23442344
expect(video.style.visibility).toBe("hidden");
23452345
});
23462346

2347+
it("un-hides a later root-level video once active, even though it starts inactive and unstyled", () => {
2348+
// Root-level `[data-start]` children with no authored `position` start out
2349+
// `position: static` until `applyClipLayout` force-absolutizes them, so a
2350+
// visibility pass over the still-inactive second clip can observe `static`
2351+
// and cache it as in-flow before that forcing runs. The un-hide path used to
2352+
// re-derive that in-flow status rather than track whether it had actually
2353+
// applied `display:none`, so the corrected, no-longer-in-flow reading made
2354+
// it skip the removal and the clip stayed `display:none` for the rest of the
2355+
// render even once active.
2356+
const root = document.createElement("div");
2357+
root.setAttribute("data-composition-id", "main");
2358+
root.setAttribute("data-root", "true");
2359+
root.setAttribute("data-start", "0");
2360+
root.setAttribute("data-duration", "20");
2361+
root.setAttribute("data-width", "1920");
2362+
root.setAttribute("data-height", "1080");
2363+
document.body.appendChild(root);
2364+
2365+
const clipA = document.createElement("video");
2366+
clipA.id = "clip-a";
2367+
clipA.setAttribute("data-start", "0");
2368+
clipA.setAttribute("data-duration", "10");
2369+
root.appendChild(clipA);
2370+
2371+
const clipB = document.createElement("video");
2372+
clipB.id = "clip-b";
2373+
clipB.setAttribute("data-start", "10");
2374+
clipB.setAttribute("data-duration", "10");
2375+
root.appendChild(clipB);
2376+
2377+
window.__timelines = { main: createMockTimeline(20) };
2378+
2379+
initSandboxRuntimeModular();
2380+
2381+
const player = window.__player;
2382+
expect(player).toBeDefined();
2383+
2384+
// Evaluate the still-inactive second clip at least once before it becomes
2385+
// active — the shape that used to poison the cache.
2386+
player?.seek(0);
2387+
expect(clipB.style.visibility).toBe("hidden");
2388+
2389+
player?.seek(15);
2390+
expect(clipB.style.visibility).toBe("visible");
2391+
expect(clipB.style.display).not.toBe("none");
2392+
});
2393+
23472394
it("allocates color grading only for the active timed media", () => {
23482395
const getContextSpy = vi.spyOn(HTMLCanvasElement.prototype, "getContext").mockReturnValue(null);
23492396
const root = document.createElement("div");

‎packages/core/src/runtime/init.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2274,6 +2274,15 @@ export function initSandboxRuntimeModular(): void {
22742274
timedClipInFlow = new WeakMap<Element, boolean>();
22752275
timedClipIsLeaf = new WeakMap<Element, boolean>();
22762276
};
2277+
2278+
// Which elements carry a `display:none` the visibility pass itself applied, so
2279+
// the un-hide branch can undo exactly that instead of re-deriving
2280+
// `isTimedClipInFlow`. That derived answer can flip between the hide and the
2281+
// show pass for the SAME element — `applyClipLayout` force-absolutizes a
2282+
// root-level clip after an earlier pass already cached it as in-flow and hid
2283+
// it — and the corrected, no-longer-in-flow reading then skips the removal,
2284+
// stranding the clip hidden for the rest of the render.
2285+
const timedClipDisplayNoneApplied = new WeakSet<HTMLElement>();
22772286
const dataHiddenDisplayRestores = new WeakMap<HTMLElement, string>();
22782287
const dataHiddenDisplayNodes = new WeakSet<HTMLElement>();
22792288
// A data-hidden toggle on (or affecting) an audio element must re-schedule
@@ -2368,9 +2377,13 @@ export function initSandboxRuntimeModular(): void {
23682377
colorGradingRuntime?.setSourceVisibility(rawNode, isVisibleNow);
23692378
}
23702379
if (isVisibleNow) {
2371-
if (isTimedClipInFlow(rawNode)) rawNode.style.removeProperty("display");
2380+
if (timedClipDisplayNoneApplied.has(rawNode)) {
2381+
rawNode.style.removeProperty("display");
2382+
timedClipDisplayNoneApplied.delete(rawNode);
2383+
}
23722384
} else if (isTimedClipInFlow(rawNode) && isTimedClipLeaf(rawNode)) {
23732385
rawNode.style.display = "none";
2386+
timedClipDisplayNoneApplied.add(rawNode);
23742387
}
23752388
}
23762389
// Only when a `data-hidden` mutation actually moved something: the skips

‎packages/engine/src/services/screenshotService.test.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,23 @@ describe("video-frame injection respects ancestor visibility", () => {
518518
expect(seededImg.style.visibility).toBe("hidden");
519519
});
520520

521+
it("preserves display:none on an inactive in-flow video so its sibling keeps the same box", async () => {
522+
const { teardown, setup } = withGlobals(setupHostHiddenScenario({}));
523+
setup.video.style.display = "none";
524+
const seededImg = setup.document.createElement("img");
525+
seededImg.classList.add("__render_frame__");
526+
setup.video.parentNode?.insertBefore(seededImg, setup.video.nextSibling);
527+
528+
try {
529+
await syncVideoFrameVisibility(passthroughPage(), []);
530+
} finally {
531+
teardown();
532+
}
533+
534+
expect(setup.video.style.display).toBe("none");
535+
expect(seededImg.style.visibility).toBe("hidden");
536+
});
537+
521538
it("still injects when a plain [data-start] host is visibility:hidden (CSS-escapable)", async () => {
522539
// Regression guard for the style-9-prod symptom: a regular
523540
// `[data-start]` container whose GSAP timeline is shorter than its

‎packages/engine/src/services/screenshotService.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,6 @@ export async function syncVideoFrameVisibility(
901901
// cannot revive a stale frame when the sub-comp host lands in the
902902
// active layer's `show` set — same mask-defense reasoning as the
903903
// `isVisualAncestorHidden` branch in `injectVideoFramesBatch`.
904-
video.style.removeProperty("display");
905904
video.style.setProperty("visibility", "hidden", "important");
906905
video.style.setProperty("pointer-events", "none", "important");
907906
if (hasImg) {

‎packages/producer/src/services/coreRuntimeBrowser.test.ts‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,65 @@ describe("core runtime browser contract", () => {
148148
30_000,
149149
);
150150

151+
it("un-hides a later root-level video once active, even though it starts inactive and unstyled", async () => {
152+
// Root-level `[data-start]` children with no authored `position` start out
153+
// `position: static` until the runtime force-absolutizes them, so a
154+
// visibility pass over the still-inactive second clip can observe `static`
155+
// and cache it as in-flow before that forcing runs. That cached reading used
156+
// to poison the later un-hide check and leave the clip stuck `display:none`
157+
// for the rest of the render once it became active.
158+
const videoPage = await browser.newPage();
159+
try {
160+
await videoPage.setContent(`<!doctype html>
161+
<div
162+
data-composition-id="root"
163+
data-start="0"
164+
data-duration="20"
165+
data-width="320"
166+
data-height="240"
167+
>
168+
<video id="clip-a" data-start="0" data-duration="10" width="320" height="240" muted></video>
169+
<video id="clip-b" data-start="10" data-duration="10" width="320" height="240" muted></video>
170+
</div>`);
171+
await videoPage.addScriptTag({ content: readFileSync(RUNTIME_PATH, "utf8") });
172+
await videoPage.waitForFunction(
173+
() =>
174+
(window as unknown as { __playerReady?: boolean }).__playerReady === true &&
175+
(window as unknown as { __renderReady?: boolean }).__renderReady === true,
176+
);
177+
178+
const seekAndReadClipB = (seekTo: number) =>
179+
videoPage.evaluate((timeSeconds) => {
180+
const player = (
181+
window as unknown as { __player?: { renderSeek: (timeSeconds: number) => void } }
182+
).__player;
183+
if (!player) throw new Error("runtime player was not installed");
184+
player.renderSeek(timeSeconds);
185+
186+
const clip = document.getElementById("clip-b");
187+
if (!clip) throw new Error("clip-b was not found");
188+
const computed = window.getComputedStyle(clip);
189+
return {
190+
display: computed.display,
191+
visibility: computed.visibility,
192+
offsetWidth: clip.offsetWidth,
193+
};
194+
}, seekTo);
195+
196+
// Evaluate the still-inactive second clip at least once before it
197+
// becomes active — the shape that used to poison the cache.
198+
const beforeActive = await seekAndReadClipB(0);
199+
expect(beforeActive.visibility).toBe("hidden");
200+
201+
const afterActive = await seekAndReadClipB(15);
202+
expect(afterActive.visibility).toBe("visible");
203+
expect(afterActive.display).not.toBe("none");
204+
expect(afterActive.offsetWidth).toBeGreaterThan(0);
205+
} finally {
206+
await videoPage.close();
207+
}
208+
}, 30_000);
209+
151210
it("removes the control bridge during teardown", async () => {
152211
const result = await page.evaluate(async () => {
153212
const runtimeWindow = window as unknown as {

‎packages/producer/src/services/render/audioPadTrim.test.ts‎

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
*/
1515

1616
import { describe, expect, it, mock } from "bun:test";
17+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
18+
import { tmpdir } from "node:os";
19+
import { join } from "node:path";
1720
import {
1821
buildPadTrimAudioArgs,
1922
buildPadTrimAudioPlan,
@@ -306,7 +309,7 @@ describe("padOrTrimAudioToVideoFrameCount", () => {
306309
expect(captured.args).toHaveLength(1);
307310
});
308311

309-
it("attenuates the duration-normalized artifact from its measured AAC true peak", async () => {
312+
it("attenuates the duration-normalized artifact with AAC correction headroom", async () => {
310313
const calls: string[][] = [];
311314
const { input } = harness({
312315
video: { frameCount: 90, fpsNum: 30, fpsDen: 1 },
@@ -326,9 +329,59 @@ describe("padOrTrimAudioToVideoFrameCount", () => {
326329
expect(result.error).toBe("synthetic correction stop");
327330
expect(calls).toHaveLength(2);
328331
const correctionArgs = calls[1]!;
329-
expect(correctionArgs[correctionArgs.indexOf("-af") + 1]).toBe("volume=-2.500dB");
332+
expect(correctionArgs[correctionArgs.indexOf("-af") + 1]).toBe("volume=-3.000dB");
330333
expect(correctionArgs[correctionArgs.indexOf("-t") + 1]).toBe("3.000000");
331334
});
335+
336+
it("uses correction headroom to converge within three AAC passes", async () => {
337+
const dir = mkdtempSync(join(tmpdir(), "hf-aac-convergence-"));
338+
const corrections: number[] = [];
339+
let attenuationDb = 0;
340+
const { input } = harness({
341+
video: { frameCount: 90, fpsNum: 30, fpsDen: 1 },
342+
audio: { durationSeconds: 3 },
343+
});
344+
input.videoPath = join(dir, "video.mp4");
345+
input.audioPath = join(dir, "source.m4a");
346+
input.outputPath = join(dir, "normalized.m4a");
347+
input.probeAudioTruePeakDbfs = async () => attenuationDb * 0.4;
348+
input.runFfmpeg = async (args) => {
349+
const filter = args[args.indexOf("-af") + 1];
350+
if (filter?.startsWith("volume=")) {
351+
attenuationDb = Number(filter.slice("volume=".length, -2));
352+
corrections.push(attenuationDb);
353+
}
354+
writeFileSync(args.at(-1)!, "");
355+
return { success: true };
356+
};
357+
358+
try {
359+
const result = await padOrTrimAudioToVideoFrameCount(input);
360+
361+
expect(result.success, result.error).toBe(true);
362+
expect(corrections).toEqual([-1.5, -2.4, -2.94]);
363+
} finally {
364+
rmSync(dir, { recursive: true, force: true });
365+
}
366+
});
367+
368+
it("reports every measured peak and attenuation when correction is exhausted", async () => {
369+
const peaks = [0, -0.4, -0.6, -0.8];
370+
let probeIndex = 0;
371+
const { input } = harness({
372+
video: { frameCount: 90, fpsNum: 30, fpsDen: 1 },
373+
audio: { durationSeconds: 3 },
374+
});
375+
input.probeAudioTruePeakDbfs = async () => peaks[probeIndex++]!;
376+
377+
const result = await padOrTrimAudioToVideoFrameCount(input);
378+
379+
expect(result.success).toBe(false);
380+
expect(result.error).toContain("pass 0: 0.000 dBFS at 0.000 dB attenuation");
381+
expect(result.error).toContain("pass 1: -0.400 dBFS at -1.500 dB attenuation");
382+
expect(result.error).toContain("pass 2: -0.600 dBFS at -2.600 dB attenuation");
383+
expect(result.error).toContain("pass 3: -0.800 dBFS at -3.500 dB attenuation");
384+
});
332385
});
333386

334387
// ── Public-path path redaction ────────────────────────────────────────────

‎packages/producer/src/services/render/audioPadTrim.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const AUDIO_DURATION_TOLERANCE_SECONDS = 0.001;
4242

4343
/** Delivery headroom applied after every AAC encode in this stage. */
4444
export const AAC_DELIVERY_TRUE_PEAK_DBFS = -1;
45+
const AAC_TRUE_PEAK_CORRECTION_HEADROOM_DB = 0.5;
4546
const MAX_TRUE_PEAK_CORRECTION_PASSES = 3;
4647

4748
export interface ProbeVideoFrameInfo {
@@ -431,10 +432,15 @@ async function enforceAacTruePeak(
431432
try {
432433
scratchDir = mkdtempSync(join(dirname(input.audioPath), ".true-peak-"));
433434
const correctedPath = join(scratchDir, "audio.m4a");
435+
const correctionTargetDbfs = AAC_DELIVERY_TRUE_PEAK_DBFS - AAC_TRUE_PEAK_CORRECTION_HEADROOM_DB;
436+
const measurements: string[] = [];
434437
let attenuationDb = 0;
435438
let measuredPath = input.audioPath;
436439
for (let pass = 0; pass <= MAX_TRUE_PEAK_CORRECTION_PASSES; pass += 1) {
437440
const truePeakDbfs = await input.probeTruePeak(measuredPath, input.signal);
441+
measurements.push(
442+
`pass ${pass}: ${truePeakDbfs.toFixed(3)} dBFS at ${attenuationDb.toFixed(3)} dB attenuation`,
443+
);
438444
if (Number.isNaN(truePeakDbfs) || truePeakDbfs === Number.POSITIVE_INFINITY) {
439445
return { success: false, error: "audioPadTrim: FFmpeg reported an invalid true peak" };
440446
}
@@ -444,7 +450,9 @@ async function enforceAacTruePeak(
444450
}
445451
if (pass === MAX_TRUE_PEAK_CORRECTION_PASSES) break;
446452

447-
attenuationDb += AAC_DELIVERY_TRUE_PEAK_DBFS - truePeakDbfs;
453+
// Aim below the acceptance ceiling because this correction itself is
454+
// another lossy AAC encode and can regenerate content-dependent peaks.
455+
attenuationDb += correctionTargetDbfs - truePeakDbfs;
448456
const result = await input.runner(
449457
buildAacTruePeakCorrectionArgs(
450458
input.audioPath,
@@ -467,7 +475,7 @@ async function enforceAacTruePeak(
467475
}
468476
return {
469477
success: false,
470-
error: `audioPadTrim: AAC true peak remained above ${AAC_DELIVERY_TRUE_PEAK_DBFS} dBFS after ${MAX_TRUE_PEAK_CORRECTION_PASSES} correction passes`,
478+
error: `audioPadTrim: AAC true peak remained above ${AAC_DELIVERY_TRUE_PEAK_DBFS} dBFS after ${MAX_TRUE_PEAK_CORRECTION_PASSES} correction passes; ${measurements.join("; ")}`,
471479
};
472480
} catch (err) {
473481
return {

‎skills-manifest.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
"files": 2
1515
},
1616
"general-video": {
17-
"hash": "68910f1093ad15c2",
17+
"hash": "a7e50541d5f01d98",
1818
"files": 4
1919
},
2020
"hyperframes": {
2121
"hash": "e77a36c488b4f80c",
2222
"files": 17
2323
},
2424
"hyperframes-animation": {
25-
"hash": "4252b08a4905b5ba",
25+
"hash": "3947516ec450f3aa",
2626
"files": 121
2727
},
2828
"hyperframes-audio": {
@@ -34,7 +34,7 @@
3434
"files": 11
3535
},
3636
"hyperframes-core": {
37-
"hash": "e5b2b62d60995dbb",
37+
"hash": "e15156c04011c4eb",
3838
"files": 20
3939
},
4040
"hyperframes-creative": {

‎skills/general-video/sub-agents/frame-worker.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Frame worker — general-video delta
22

3-
> The shared law is the core contract above (the packet builder prepends `../hyperframes-core/references/frame-worker-core.md` to this file as `_role.md`) — read the two as one role. This file carries only what's specific to a general-video scene; you run N-up, **one scene each** — your dispatch carries exactly one packet. Tempted to add a generic GSAP / timeline rule here? Wrong home — it belongs in the core contract or `hyperframes-core`.
3+
> The shared law is the core contract above (the packet builder prepends `../../hyperframes-core/references/frame-worker-core.md` to this file as `_role.md`) — read the two as one role. This file carries only what's specific to a general-video scene; you run N-up, **one scene each** — your dispatch carries exactly one packet. Tempted to add a generic GSAP / timeline rule here? Wrong home — it belongs in the core contract or `hyperframes-core`.
44
55
## Your scene is invented, not captured
66

‎skills/hyperframes-animation/blueprints/titlecard-reveal.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ monochrome text-on-solid throughout.
5454

5555
- gentle fade-in + subtle scale-up settle (Benefits Scene 2) → `rules/scale-swap-transition.md` (restrained in/settle; cross-reference the fade ease in `techniques.md`)
5656
- single slide-up crossfade between two centered lines (Benefits Scene 3) → `rules/discrete-text-sequence.md` (one line hands off to the next; translate-up + crossfade)
57-
- diagonal pill-wipe reveal (Social_Proof Scene 2) → `rules/techniques.md` (clip-path reveal masks — the wipe)
57+
- diagonal pill-wipe reveal (Social_Proof Scene 2) → `../techniques.md` (clip-path reveal masks — the wipe)
5858
- icon stroke draw-on (Social_Proof Scene 2) → `rules/svg-path-draw.md`
5959
- "[N]+ teams" count-up (Social_Proof Scene 3, optional) → `rules/counting-dynamic-scale.md`
6060
- logo + tagline spring-settle-and-hold (Social_Proof Scene 3) → `rules/spring-pop-entrance.md` (single soft settle; intentionally one beat, not a chain)

0 commit comments

Comments
 (0)