Skip to content

Commit 78dacc8

Browse files
fix(skills): accept durationless transition roots (#3683)
1 parent 776c291 commit 78dacc8

3 files changed

Lines changed: 82 additions & 10 deletions

File tree

‎skills/pr-to-video/scripts/transitions.mjs‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,18 @@ function extendFrameTail(hyperframesDir, frame, baseDuration, targetDuration, di
117117
let extended = 0;
118118
const rewritten = html.replace(/<([A-Za-z][\w:-]*)\b([^>]*)>/g, (tag, name, attrs) => {
119119
const durationMatch = attrs.match(/\bdata-duration="([\d.]+)"/);
120-
if (!durationMatch) return tag;
121-
const duration = Number(durationMatch[1]);
122-
if (!Number.isFinite(duration)) return tag;
123-
124120
const compositionMatch = attrs.match(/\bdata-composition-id="([^"]+)"/);
125121
if (compositionMatch?.[1] === compId && !foundRoot) {
126122
foundRoot = true;
127-
return tag.replace(/\bdata-duration="[\d.]+"/, `data-duration="${targetDuration}"`);
123+
return durationMatch
124+
? tag.replace(/\bdata-duration="[\d.]+"/, `data-duration="${targetDuration}"`)
125+
: tag.replace(/(\s*\/?>)$/, ` data-duration="${targetDuration}"$1`);
128126
}
129127

128+
if (!durationMatch) return tag;
129+
const duration = Number(durationMatch[1]);
130+
if (!Number.isFinite(duration)) return tag;
131+
130132
if (name.toLowerCase() === "audio") return tag;
131133
const startMatch = attrs.match(/\bdata-start="([\d.]+)"/);
132134
if (!startMatch) return tag;

‎skills/product-launch-video/scripts/transitions.mjs‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,18 @@ function extendFrameTail(hyperframesDir, frame, baseDuration, targetDuration, di
117117
let extended = 0;
118118
const rewritten = html.replace(/<([A-Za-z][\w:-]*)\b([^>]*)>/g, (tag, name, attrs) => {
119119
const durationMatch = attrs.match(/\bdata-duration="([\d.]+)"/);
120-
if (!durationMatch) return tag;
121-
const duration = Number(durationMatch[1]);
122-
if (!Number.isFinite(duration)) return tag;
123-
124120
const compositionMatch = attrs.match(/\bdata-composition-id="([^"]+)"/);
125121
if (compositionMatch?.[1] === compId && !foundRoot) {
126122
foundRoot = true;
127-
return tag.replace(/\bdata-duration="[\d.]+"/, `data-duration="${targetDuration}"`);
123+
return durationMatch
124+
? tag.replace(/\bdata-duration="[\d.]+"/, `data-duration="${targetDuration}"`)
125+
: tag.replace(/(\s*\/?>)$/, ` data-duration="${targetDuration}"$1`);
128126
}
129127

128+
if (!durationMatch) return tag;
129+
const duration = Number(durationMatch[1]);
130+
if (!Number.isFinite(duration)) return tag;
131+
130132
if (name.toLowerCase() === "audio") return tag;
131133
const startMatch = attrs.match(/\bdata-start="([\d.]+)"/);
132134
if (!startMatch) return tag;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import assert from "node:assert/strict";
2+
import { spawnSync } from "node:child_process";
3+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
4+
import { tmpdir } from "node:os";
5+
import { join } from "node:path";
6+
import test from "node:test";
7+
8+
const workflowScripts = [
9+
["product-launch-video", new URL("./transitions.mjs", import.meta.url).pathname],
10+
["pr-to-video", new URL("../../pr-to-video/scripts/transitions.mjs", import.meta.url).pathname],
11+
];
12+
13+
function runInject(script, rootId) {
14+
const project = mkdtempSync(join(tmpdir(), "hf-transition-root-"));
15+
const framesDir = join(project, "compositions", "frames");
16+
mkdirSync(framesDir, { recursive: true });
17+
writeFileSync(
18+
join(project, "STORYBOARD.md"),
19+
`---\nformat: 1920x1080\n---\n\n## Frame 1 — First\n\n- duration: 3s\n- transition_in: cut\n- src: compositions/frames/frame-01.html\n\n## Frame 2 — Second\n\n- duration: 3s\n- transition_in: crossfade 0.5s\n- src: compositions/frames/frame-02.html\n`,
20+
);
21+
writeFileSync(
22+
join(framesDir, "frame-01.html"),
23+
`<div data-composition-id="${rootId}" data-width="1920" data-height="1080"><div class="clip" data-start="0" data-duration="3"></div></div>`,
24+
);
25+
writeFileSync(
26+
join(framesDir, "frame-02.html"),
27+
'<div data-composition-id="frame-02" data-duration="3"></div>',
28+
);
29+
writeFileSync(
30+
join(project, "index.html"),
31+
`<div data-composition-id="main" data-duration="6">
32+
<div id="el-frame-01" data-start="0" data-duration="3" data-track-index="0"></div>
33+
<div id="el-frame-02" data-start="3" data-duration="3" data-track-index="0"></div>
34+
</div><script>window.__timelines = {}; window.__timelines["main"] = gsap.timeline({ paused: true });</script>`,
35+
);
36+
const result = spawnSync(
37+
process.execPath,
38+
[script, "inject", "--storyboard", join(project, "STORYBOARD.md"), "--hyperframes", project],
39+
{ encoding: "utf8" },
40+
);
41+
return {
42+
project,
43+
result,
44+
frameHtml: () => readFileSync(join(framesDir, "frame-01.html"), "utf8"),
45+
};
46+
}
47+
48+
for (const [workflow, script] of workflowScripts) {
49+
test(`${workflow} inserts duration on a valid durationless frame root`, () => {
50+
const fixture = runInject(script, "frame-01");
51+
try {
52+
assert.equal(fixture.result.status, 0, fixture.result.stderr);
53+
assert.match(fixture.frameHtml(), /data-composition-id="frame-01"[^>]*data-duration="3\.5"/);
54+
} finally {
55+
rmSync(fixture.project, { recursive: true, force: true });
56+
}
57+
});
58+
59+
test(`${workflow} still rejects a genuinely mismatched frame root`, () => {
60+
const fixture = runInject(script, "wrong-root");
61+
try {
62+
assert.notEqual(fixture.result.status, 0);
63+
assert.match(fixture.result.stderr, /has no data-composition-id="frame-01" root/);
64+
} finally {
65+
rmSync(fixture.project, { recursive: true, force: true });
66+
}
67+
});
68+
}

0 commit comments

Comments
 (0)