diff --git a/docs/reference/lint-rules.mdx b/docs/reference/lint-rules.mdx index 1bcc82db63..482d0712ae 100644 --- a/docs/reference/lint-rules.mdx +++ b/docs/reference/lint-rules.mdx @@ -590,7 +590,7 @@ Source: `packages/lint/src/rules/media.ts`. **Warning.** An element has `data-volume` gain and a GSAP tween on `volume`; tween values are absolute and replace the gain rather than scale it. -**Fix:** Write tween targets as absolute gains that already include the gain, or reset `data-volume` to 1 and let the tween carry the level. +**Fix:** Keep the level you set. Use an absolute gain for each level the tween should reach: for `data-volume="0.3"`, use `volume: 0.3` where it should reach that level, and keep `volume: 0` at endpoints intended to be silent. If `data-volume="0"`, the clip is authored silent: drop the volume tween to keep it silent, or deliberately set `data-volume="1"` and let the tween carry the level. If the level is in doubt, measure the rendered file with `hyperframes audio render.mp4` (replace `render.mp4` with your output file) before changing it. ### `base64_media_prohibited` diff --git a/packages/lint/src/rules/media.test.ts b/packages/lint/src/rules/media.test.ts index 039e43085d..e6befdd8f8 100644 --- a/packages/lint/src/rules/media.test.ts +++ b/packages/lint/src/rules/media.test.ts @@ -957,13 +957,42 @@ describe("audio_volume_tween_overrides_gain", () => { expect(finding?.severity).toBe("warning"); expect(finding?.elementId).toBe("bgm"); expect(finding?.message).toMatch(/5\.8 dB/); + expect(finding?.fixHint).toContain("`volume: 1.949845`"); }); - it("warns about an attenuation the tween overrides, not just a boost", async () => { + it.each([ + ["0.3", "0.3"], + ["1.95", "1.95"], + ["0.030000", "0.03"], + ["3e-2", "0.03"], + ])("preserves the authored gain %s in its advice", async (authored, gain) => { const res = await lintHyperframeHtml( - withScript(`data-volume="0.3"`, `tl.to("#bgm", { volume: 1 });`), + withScript(`data-volume="${authored}"`, `tl.to("#bgm", { volume: 1 });`), ); - expect(res.findings.some((f) => f.code === "audio_volume_tween_overrides_gain")).toBe(true); + const finding = res.findings.find((f) => f.code === "audio_volume_tween_overrides_gain"); + expect(finding?.severity).toBe("warning"); + expect(finding?.elementId).toBe("bgm"); + expect(finding?.fixHint).toContain(`\`volume: ${gain}\``); + expect(finding?.fixHint).toContain( + "measure the rendered file with `hyperframes audio render.mp4`", + ); + expect(finding?.fixHint).toContain("keep `volume: 0` at endpoints intended to be silent"); + expect(finding?.fixHint).not.toContain('data-volume="1"'); + expect(finding?.fixHint).not.toContain("`volume: 1`"); + }); + + it("names both deliberate choices for an authored silent clip", async () => { + const res = await lintHyperframeHtml( + withScript(`data-volume="0"`, `tl.fromTo("#bgm", { volume: 0 }, { volume: 1 });`), + ); + const finding = res.findings.find((f) => f.code === "audio_volume_tween_overrides_gain"); + expect(finding?.severity).toBe("warning"); + expect(finding?.message).toContain("(silence)"); + expect(finding?.fixHint).toContain('authored silent (`data-volume="0"`)'); + expect(finding?.fixHint).toContain("To keep it silent, drop the volume tween"); + expect(finding?.fixHint).toContain('to let the tween carry the level, set `data-volume="1"`'); + expect(finding?.fixHint).toContain("choose its absolute volume targets deliberately"); + expect(finding?.fixHint).toContain("hyperframes audio render.mp4"); }); it("stays quiet on the fade the docs recommend, which carries no data-volume", async () => { diff --git a/packages/lint/src/rules/media.ts b/packages/lint/src/rules/media.ts index 080b4f60f3..5c9af67546 100644 --- a/packages/lint/src/rules/media.ts +++ b/packages/lint/src/rules/media.ts @@ -927,7 +927,10 @@ function findVolumeTweenOverridesGainFindings(ctx: LintContext): HyperframeLintF message: `#${id} has data-volume="${volume}" (${db}) and a GSAP tween on \`volume\`. Tween values are absolute: they REPLACE this gain rather than scale it, so wherever the tween names a value the clip plays at that value, not at ${db}.`, elementId: id, fixHint: - "Write the tween's targets in the same absolute gain (e.g. `volume: 1.95`, not `volume: 1`), or reset data-volume to 1 and let the tween carry the level on its own.", + (volume === 0 + ? 'This clip is authored silent (`data-volume="0"`). To keep it silent, drop the volume tween; to let the tween carry the level, set `data-volume="1"` and choose its absolute volume targets deliberately. ' + : `Keep the level you set: use an absolute gain for each level the tween should reach. Use \`volume: ${volume}\` where it should reach this clip's authored level; keep \`volume: 0\` at endpoints intended to be silent. `) + + "If the level is in doubt, measure the rendered file with `hyperframes audio render.mp4` (replace render.mp4 with your output file) before changing it.", snippet: truncateSnippet(tag.raw), }); }