Skip to content

Commit e21e64f

Browse files
fix(registry): caption-highlight clears a short word's highlight when the word ends (#7735)
* fix(registry): caption-highlight clears a short word's highlight when the word ends On a word shorter than 0.05 s the 0.15 s fade-in outlived the fade-out, so a frame inside that tail lit the highlight again until the phrase ended. * fix(registry): leave the generated caption-highlight catalog files to the generator
1 parent 35d1451 commit e21e64f

3 files changed

Lines changed: 43 additions & 2 deletions

File tree

‎packages/cli/src/registry/captionLastGroup.chromium.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,42 @@ describe.runIf(executablePath)("caption-highlight last group in Chromium", () =>
6969
expect(await lastGroupVisibleAt(LAST_WORD_END_S - 0.05)).toBe(true);
7070
});
7171
});
72+
73+
describe.runIf(executablePath)("caption-highlight short word in Chromium", () => {
74+
let browser: Browser;
75+
76+
beforeAll(async () => {
77+
browser = await puppeteer.launch({ executablePath, args: ["--no-sandbox"] });
78+
});
79+
80+
afterAll(async () => {
81+
await browser?.close();
82+
});
83+
84+
function componentWithShortWord(): string {
85+
const demoWord = '{ text: "great", start: 0.3, end: 0.55 }';
86+
if (!componentHtml.includes(demoWord)) throw new Error("the demo's second word changed");
87+
return componentHtml
88+
.replace(demoWord, '{ text: "great", start: 0.3, end: 0.34 }')
89+
.replace(/<script src="https:[^"]*gsap[^"]*"><\/script>/, `<script>${gsapScript}</script>`);
90+
}
91+
92+
// fails without the fix: a frame inside the 0.01 s tail relit the pill until the phrase ended.
93+
it("clears a 0.04 s word's highlight once the word is over", async () => {
94+
const page = await browser.newPage();
95+
try {
96+
await page.setContent(componentWithShortWord());
97+
const opacity = await page.evaluate(() => {
98+
const timeline = (
99+
window as unknown as { __timelines: Record<string, { seek(t: number): void }> }
100+
).__timelines["caption-highlight"];
101+
for (const time of [0, 0.3, 0.333, 0.367, 0.4, 0.433, 0.445, 0.467, 0.5])
102+
timeline!.seek(time);
103+
return Number(getComputedStyle(document.getElementById("hl-bg-1")!).opacity);
104+
});
105+
expect(opacity).toBe(0);
106+
} finally {
107+
await page.close();
108+
}
109+
});
110+
});

‎registry/components/caption-highlight/caption-highlight.html‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@
235235
var bgEl = document.getElementById("hl-bg-" + wi);
236236
var wordEl = document.getElementById("hl-w-" + wi);
237237

238-
tl.to(bgEl, { opacity: 1, scaleX: 1, duration: 0.15, ease: "power2.out" }, w.start);
238+
var fadeIn = Math.min(0.15, w.end - w.start);
239+
tl.to(bgEl, { opacity: 1, scaleX: 1, duration: fadeIn, ease: "power2.out" }, w.start);
239240
tl.to(
240241
wordEl,
241242
{ filter: "brightness(1.05)", duration: 0.08, ease: "power2.out" },

‎registry/components/caption-highlight/demo.html‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@
232232
var bgEl = document.getElementById("hl-bg-" + wi);
233233
var wordEl = document.getElementById("hl-w-" + wi);
234234

235-
tl.to(bgEl, { opacity: 1, scaleX: 1, duration: 0.15, ease: "power2.out" }, w.start);
235+
var fadeIn = Math.min(0.15, w.end - w.start);
236+
tl.to(bgEl, { opacity: 1, scaleX: 1, duration: fadeIn, ease: "power2.out" }, w.start);
236237
tl.to(
237238
wordEl,
238239
{ filter: "brightness(1.05)", duration: 0.08, ease: "power2.out" },

0 commit comments

Comments
 (0)