Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
fix(lint): back-to-back audio clips no longer count as overlapping after float rounding (#5837)
Miguel Ángeld1123299f8ad
diff --git a/packages/core/src/clipFacts.ts b/packages/core/src/clipFacts.tsindex 3006fee519..99cd215e86 100644--- a/packages/core/src/clipFacts.ts+++ b/packages/core/src/clipFacts.ts@@ -34,32 +34,13 @@ const roundTo3 = (n: number) => Math.round(n * 1000) / 1000;const num = (n: number) => String(roundTo3(n));-export const instantTolerance = (time: number) => 4 * Number.EPSILON * Math.max(1, Math.abs(time));--/** Float sums like 19.8 + 6.4 miss 26.2 by a rounding step; a few steps, scaled to the time, are one instant. */-export function sameInstant(a: number, b: number): boolean {- if (!Number.isFinite(a) || !Number.isFinite(b)) return a === b;- return Math.abs(a - b) <= instantTolerance(Math.max(Math.abs(a), Math.abs(b)));-}--const isBefore = (a: number, b: number) => a < b && !sameInstant(a, b);--/** For timeline lanes: a zero-length clip inside another still counts, so it gets a lane of its own. */-export function spansOverlap(aStart: number, aEnd: number, bStart: number, bEnd: number): boolean {- return isBefore(aStart, bEnd) && isBefore(bStart, aEnd);-}--export function spansShareTime(- aStart: number,- aEnd: number,- bStart: number,- bEnd: number,-): boolean {- return isBefore(Math.max(aStart, bStart), Math.min(aEnd, bEnd));-}--export const isInsideSpan = (time: number, start: number, end: number) =>- isBefore(start, time) && isBefore(time, end);+export {+ instantTolerance,+ isInsideSpan,+ sameInstant,+ spansOverlap,+ spansShareTime,+} from "@hyperframes/parsers/time-spans";export function formatClipLine(clip: ClipFact): string {const parts = [diff --git a/packages/lint/src/project.test.ts b/packages/lint/src/project.test.tsindex 02401c0ce3..78dd7a58cc 100644--- a/packages/lint/src/project.test.ts+++ b/packages/lint/src/project.test.ts@@ -1032,6 +1032,18 @@ describe("audio-aware project rules", () => {);expect(codes).not.toContain("duplicate_audio_track");});++ it("stays quiet for back-to-back clips whose start plus duration only rounds past the next start", async () => {+ // 21.03 + 0.1 is 21.130000000000003 in floating point.+ const clip = (id: string, start: string, duration: string) =>+ `<audio id="${id}" src="a.mp3" data-start="${start}" data-duration="${duration}" data-track-index="0"></audio>`;+ const codes = await codesFor(+ composition(+ clip("m1", "0", "21.03") + clip("m2", "21.03", "0.1") + clip("m3", "21.13", "5"),+ ),+ );+ expect(codes).not.toContain("duplicate_audio_track");+ });});describe("audio_file_without_element", () => {diff --git a/packages/lint/src/project.ts b/packages/lint/src/project.tsindex dc48a5429a..d4b19eb3a9 100644--- a/packages/lint/src/project.ts+++ b/packages/lint/src/project.ts@@ -3,6 +3,7 @@ import { createHash } from "node:crypto";import { existsSync, readFileSync, readdirSync } from "node:fs";import { dirname, extname, join, relative, resolve } from "node:path";import { rewriteAssetPath } from "@hyperframes/parsers/asset-paths";+import { spansOverlap } from "@hyperframes/parsers/time-spans";import { checkSubCompositionUsability } from "@hyperframes/parsers/sub-composition-validity";import { parseHTML } from "linkedom";import {@@ -584,7 +585,7 @@ function lintDuplicateAudioTracks(htmlSources: HtmlSource[]): HyperframeLintFindconst a = tracks[i]!;const b = tracks[j]!;if (a.trackIndex !== b.trackIndex) continue;- if (a.start < b.end && b.start < a.end) {+ if (spansOverlap(a.start, a.end, b.start, b.end)) {findings.push({code: "duplicate_audio_track",severity: "warning",diff --git a/packages/parsers/package-subpaths.json b/packages/parsers/package-subpaths.jsonindex 18f6449836..11ac5d3d6e 100644--- a/packages/parsers/package-subpaths.json+++ b/packages/parsers/package-subpaths.json@@ -128,6 +128,12 @@"types": "./dist/htmlAttributeSpans.d.ts","environments": ["browser", "bun", "node"]},+ "./time-spans": {+ "source": "./src/timeSpans.ts",+ "runtime": "./dist/timeSpans.js",+ "types": "./dist/timeSpans.d.ts",+ "environments": ["browser", "bun", "node"]+ },"./composition-duration": {"source": "./src/compositionDuration.ts","runtime": "./dist/compositionDuration.js",diff --git a/packages/parsers/package.json b/packages/parsers/package.jsonindex 7fdb312752..35b600a492 100644--- a/packages/parsers/package.json+++ b/packages/parsers/package.json@@ -136,6 +136,12 @@"import": "./src/htmlAttributeSpans.ts","types": "./src/htmlAttributeSpans.ts"},+ "./time-spans": {+ "bun": "./src/timeSpans.ts",+ "node": "./dist/timeSpans.js",+ "import": "./src/timeSpans.ts",+ "types": "./src/timeSpans.ts"+ },"./composition-duration": {"bun": "./src/compositionDuration.ts","node": "./dist/compositionDuration.js",@@ -227,6 +233,10 @@"import": "./dist/htmlAttributeSpans.js","types": "./dist/htmlAttributeSpans.d.ts"},+ "./time-spans": {+ "import": "./dist/timeSpans.js",+ "types": "./dist/timeSpans.d.ts"+ },"./composition-duration": {"import": "./dist/compositionDuration.js","types": "./dist/compositionDuration.d.ts"diff --git a/packages/parsers/src/timeSpans.ts b/packages/parsers/src/timeSpans.tsnew file mode 100644index 0000000000..4f2d4df6fa--- /dev/null+++ b/packages/parsers/src/timeSpans.ts@@ -0,0 +1,26 @@+export const instantTolerance = (time: number) => 4 * Number.EPSILON * Math.max(1, Math.abs(time));++/** Float sums like 19.8 + 6.4 miss 26.2 by a rounding step; a few steps, scaled to the time, are one instant. */+export function sameInstant(a: number, b: number): boolean {+ if (!Number.isFinite(a) || !Number.isFinite(b)) return a === b;+ return Math.abs(a - b) <= instantTolerance(Math.max(Math.abs(a), Math.abs(b)));+}++const isBefore = (a: number, b: number) => a < b && !sameInstant(a, b);++/** For timeline lanes: a zero-length clip inside another still counts, so it gets a lane of its own. */+export function spansOverlap(aStart: number, aEnd: number, bStart: number, bEnd: number): boolean {+ return isBefore(aStart, bEnd) && isBefore(bStart, aEnd);+}++export function spansShareTime(+ aStart: number,+ aEnd: number,+ bStart: number,+ bEnd: number,+): boolean {+ return isBefore(Math.max(aStart, bStart), Math.min(aEnd, bEnd));+}++export const isInsideSpan = (time: number, start: number, end: number) =>+ isBefore(start, time) && isBefore(time, end);diff --git a/packages/parsers/tsup.config.ts b/packages/parsers/tsup.config.tsindex ba477ed713..e8145a2f39 100644--- a/packages/parsers/tsup.config.ts+++ b/packages/parsers/tsup.config.ts@@ -23,6 +23,7 @@ export default defineConfig({ffBinaries: "src/ffBinaries.ts",assetResolution: "src/assetResolution.ts",htmlAttributeSpans: "src/htmlAttributeSpans.ts",+ timeSpans: "src/timeSpans.ts",},format: ["esm"],outDir: "dist",