mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-23 11:29:54 +00:00
fix(lint): read a media window's start through the parser (#8133)
`mediaTimeWindow` parsed `data-start` with a raw `Number()`. A negative start, which `readClipTiming` clamps to zero, produced a window entirely before zero, so `mediaWindowsOverlap` reported no overlap and `video_audio_double_source` missed a real duplicate-audio error. Read the window through `readClipTiming`, the same contract parser the renderer uses, and keep returning null when the start or duration is unknown.
This commit is contained in:
@@ -496,6 +496,20 @@ describe("media rules", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("video_audio_double_source still fires when the video starts negative", async () => {
|
||||
const html = `
|
||||
<html><body>
|
||||
<div id="root" data-composition-id="c1" data-width="1920" data-height="1080">
|
||||
<video id="v" data-start="-5" data-duration="3" data-has-audio="true" src="clip.mp4" playsinline></video>
|
||||
<audio id="a" data-start="0" data-duration="2" src="clip.mp4"></audio>
|
||||
</div>
|
||||
<script>window.__timelines = window.__timelines || {}; window.__timelines["c1"] = gsap.timeline({ paused: true });</script>
|
||||
</body></html>`;
|
||||
const result = await lintHyperframeHtml(html);
|
||||
const codes = result.findings.map((f) => f.code);
|
||||
expect(codes).toContain("video_audio_double_source");
|
||||
});
|
||||
|
||||
it("video_audio_double_source suggests removing the <audio> first", async () => {
|
||||
const html = `
|
||||
<html><body>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import { Parser } from "htmlparser2";
|
||||
import { parse, type CallExpression, type Comment, type Program } from "acorn";
|
||||
import { base, recursive, simple } from "acorn-walk";
|
||||
import { readClipTiming } from "@hyperframes/parsers/composition-contract";
|
||||
|
||||
export type OpenTag = {
|
||||
raw: string;
|
||||
@@ -239,11 +240,12 @@ export function isAudibleVideoTag(tagSource: string): boolean {
|
||||
}
|
||||
|
||||
export function mediaTimeWindow(tagSource: string): { start: number; end: number } | null {
|
||||
const start = Number(readAttr(tagSource, "data-start"));
|
||||
const duration = Number(readAttr(tagSource, "data-duration"));
|
||||
if (!readAttr(tagSource, "data-start") || !readAttr(tagSource, "data-duration")) return null;
|
||||
if (!Number.isFinite(start) || !Number.isFinite(duration)) return null;
|
||||
return { start, end: start + duration };
|
||||
const timing = readClipTiming({
|
||||
getAttribute: (name) => readAttr(tagSource, name),
|
||||
});
|
||||
if (timing.start === null || timing.duration === null) return null;
|
||||
return { start: timing.start, end: timing.start + timing.duration };
|
||||
}
|
||||
|
||||
export function mediaWindowsOverlap(
|
||||
|
||||
Reference in New Issue
Block a user