mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
fix(lint): derive the root duration with the parser's timing reader (#8032)
* fix(lint): derive the root duration with the parser's timing reader `deriveDurationFromClips` read `data-start` with a raw `Number()`, so a clip authored at `data-start="-2"` produced an end of `-1`. `resolveCompositionDuration` only counts positive ends, so the clip vanished from the derivation and the composition was reported as having no duration source at all — a hard error that blocks strict renders, even though the parser clamps the same start to zero and renders the clip for its full length. Read the start through `readClipTiming`, the same contract parser the renderer uses, and keep the media-duration default for untimed images. * fix(lint): derive the root duration with the parser's timing reader `deriveDurationFromClips` read `data-start` with a raw `Number()`, so a clip authored at `data-start="-2"` produced a negative end and vanished from the derivation. Read the start through `readClipTiming`, which clamps it to zero, and keep `readAuthoredDurationSeconds` for the authored length so a valid `data-end` still backs an unparseable `data-duration`.
This commit is contained in:
@@ -1978,6 +1978,32 @@ ${Array.from({ length: 10 }, (_, i) => ` <div class="clip" data-start="${i}"
|
||||
expect(derived?.message).toContain("2 clip(s) whose length is only known at runtime");
|
||||
});
|
||||
|
||||
it("falls back to a valid data-end when data-duration is not numeric", async () => {
|
||||
const html = `<html><body>
|
||||
<div data-composition-id="main" data-start="0" data-width="1920" data-height="1080">
|
||||
<div class="clip" data-start="0" data-duration="abc" data-end="4"></div>
|
||||
</div>
|
||||
</body></html>`;
|
||||
const result = await lintHyperframeHtml(html);
|
||||
expect(find(result.findings)).toBeUndefined();
|
||||
expect(
|
||||
result.findings.find((f) => f.code === "root_composition_duration_derived")?.message,
|
||||
).toContain("at least 4s");
|
||||
});
|
||||
|
||||
it("derives from a negative start like the parser does", async () => {
|
||||
const html = `<html><body>
|
||||
<div data-composition-id="main" data-start="0" data-width="1920" data-height="1080">
|
||||
<div class="clip" data-start="-2" data-duration="1"></div>
|
||||
</div>
|
||||
</body></html>`;
|
||||
const result = await lintHyperframeHtml(html);
|
||||
expect(find(result.findings)).toBeUndefined();
|
||||
expect(
|
||||
result.findings.find((f) => f.code === "root_composition_duration_derived")?.message,
|
||||
).toContain("at least 1s");
|
||||
});
|
||||
|
||||
it("does not count a clip whose data-end is before its start", async () => {
|
||||
const html = `<html><body>
|
||||
<div data-composition-id="main" data-start="0" data-width="1920" data-height="1080">
|
||||
|
||||
@@ -1975,15 +1975,15 @@ function deriveDurationFromClips(tags: OpenTag[], rootTag: OpenTag) {
|
||||
const clipEnds: Array<number | null> = [];
|
||||
for (const tag of tags) {
|
||||
if (tag === rootTag) continue;
|
||||
const startRaw = readAttr(tag.raw, "data-start");
|
||||
if (startRaw === null) continue;
|
||||
const start = Number(startRaw);
|
||||
// A reference start ("intro+2") is resolved by the runtime; here it is a clip of unknown end.
|
||||
if (!Number.isFinite(start)) {
|
||||
const getAttr = (name: string) => readAttr(tag.raw, name);
|
||||
if (getAttr("data-start") === null) continue;
|
||||
const timing = readTagTiming(tag.raw);
|
||||
// A reference start is resolved by the runtime; here it is a clip of unknown end.
|
||||
if (timing.start === null) {
|
||||
clipEnds.push(null);
|
||||
continue;
|
||||
}
|
||||
const getAttr = (name: string) => readAttr(tag.raw, name);
|
||||
const start = timing.start;
|
||||
const authored = readAuthoredDurationSeconds(getAttr, start);
|
||||
if (CLIP_MEDIA_TAGS.has(tag.name)) {
|
||||
const { seconds } = resolveMediaDuration({
|
||||
|
||||
Reference in New Issue
Block a user