diff --git a/packages/player/src/slideshow/SlideshowController.test.ts b/packages/player/src/slideshow/SlideshowController.test.ts index dca83d075b..a14adb3712 100644 --- a/packages/player/src/slideshow/SlideshowController.test.ts +++ b/packages/player/src/slideshow/SlideshowController.test.ts @@ -47,9 +47,9 @@ const SHOW: ResolvedSlideshow = { function showAtFrag1() { const p = fakePlayer(); const c = new SlideshowController(p, SHOW); - p.emit(2); // fragmentIndex=0 + p.emit(2.2); // fragmentIndex=0 c.next(); // target=4 - p.emit(4); // fragmentIndex=1 + p.emit(4.2); // fragmentIndex=1 return { p, c }; } @@ -69,9 +69,9 @@ describe("SlideshowController linear nav", () => { it("enters the first slide on construction: jumps to the first hold (no auto-play)", () => { const p = fakePlayer(); new SlideshowController(p, SHOW); - // No auto-play: jumps to the first hold (fragments[0]=2), seeking just before - // it (minus the render-nudge) so the composition repaints. - expect(p.seek).toHaveBeenCalledWith(1.8); + // No auto-play: seeks (jumps) to the first hold, fragments[0]=2; + // playTo then plays a brief forward render-nudge and pauses there. + expect(p.seek).toHaveBeenCalledWith(2); expect(p.play).toHaveBeenCalled(); }); @@ -86,7 +86,7 @@ describe("SlideshowController linear nav", () => { it("next stops at the first fragment, not the next slide", () => { const p = fakePlayer(); const c = new SlideshowController(p, SHOW); - p.emit(2); // play reaches fragment 0, controller pauses + p.emit(2.2); // play reaches fragment 0, controller pauses expect(p.pause).toHaveBeenCalled(); expect(c.position.slideIndex).toBe(0); expect(c.position.fragmentIndex).toBe(0); @@ -96,12 +96,12 @@ describe("SlideshowController linear nav", () => { const p = fakePlayer(); const c = new SlideshowController(p, SHOW); c.next(); // -> fragment 1 target (2) - p.emit(2); + p.emit(2.2); c.next(); // -> fragment 2 target (4) - p.emit(4); + p.emit(4.2); c.next(); // no more fragments — advance to slide b immediately expect(c.position.slideIndex).toBe(1); - expect(p.seek).toHaveBeenLastCalledWith(9.8); // slide b end (10) minus render-nudge + expect(p.seek).toHaveBeenLastCalledWith(7.5); // slide b midpoint }); it("next() on a slide with NO fragments advances to the next slide immediately", () => { @@ -125,7 +125,7 @@ describe("SlideshowController linear nav", () => { // slide 0 has no fragments; one next() should advance immediately to slide 1 c2.next(); expect(c2.position.slideIndex).toBe(1); - expect(p2.seek).toHaveBeenLastCalledWith(9.8); // slide b end (10) minus render-nudge + expect(p2.seek).toHaveBeenLastCalledWith(7.5); // slide b midpoint }); it("next() on the last slide is a no-op", () => { @@ -147,11 +147,11 @@ describe("SlideshowController linear nav", () => { it("auto-pauses at a fragment, then next advances to the FOLLOWING fragment (not the end)", () => { const p = fakePlayer(); const c = new SlideshowController(p, SHOW); - p.emit(2); // auto-pause at fragments[0]=2 + p.emit(2.2); // auto-pause at fragments[0]=2 expect(c.position.fragmentIndex).toBe(0); p.pause.mockClear(); // clear the pause from the auto-stop above c.next(); // should target fragments[1]=4, NOT slide.end=5 - p.emit(4); + p.emit(4.2); expect(p.pause).toHaveBeenCalled(); // must pause at 4, not skip to 5 expect(c.position.fragmentIndex).toBe(1); }); @@ -188,7 +188,7 @@ describe("SlideshowController branching", () => { c.enterBranch("deep"); expect(c.position.sequenceId).toBe("deep"); expect(c.currentSlide?.sceneId).toBe("c"); - expect(p.seek).toHaveBeenLastCalledWith(12.8); // slide c end (13) minus render-nudge + expect(p.seek).toHaveBeenLastCalledWith(11.5); // slide c midpoint }); it("counter is scoped to the current sequence", () => { @@ -228,19 +228,19 @@ describe("SlideshowController Fix 8a — fragmentIndex advances via onTime not n c.next(); expect(c.position.fragmentIndex).toBe(-1); // still -1 until onTime fires // Simulate playback reaching the hold point (fragments[0]=2) - p.emit(2); + p.emit(2.2); expect(c.position.fragmentIndex).toBe(0); // onTime advanced it }); it("next() after auto-pause targets the FOLLOWING fragment without pre-increment (regression)", () => { const p = fakePlayer(); const c = new SlideshowController(p, SHOW); - p.emit(2); // auto-pause at fragments[0]=2; fragmentIndex=0 + p.emit(2.2); // auto-pause at fragments[0]=2; fragmentIndex=0 expect(c.position.fragmentIndex).toBe(0); p.pause.mockClear(); c.next(); // should target fragments[1]=4 — fragmentIndex stays 0 until emit expect(c.position.fragmentIndex).toBe(0); // NOT yet 1 - p.emit(4); + p.emit(4.2); expect(p.pause).toHaveBeenCalled(); expect(c.position.fragmentIndex).toBe(1); // onTime advanced it }); @@ -258,7 +258,7 @@ describe("SlideshowController Fix 8b — back() restores parent fragmentIndex", expect(c.position.sequenceId).toBe("main"); expect(c.position.slideIndex).toBe(0); expect(c.position.fragmentIndex).toBe(1); - expect(p.seek).toHaveBeenLastCalledWith(3.8); // fragments[1] (4) minus render-nudge + expect(p.seek).toHaveBeenLastCalledWith(4); // fragments[1] = 4 }); it("back() when parent fragmentIndex=-1 seeks to slide start", () => { @@ -356,8 +356,8 @@ describe("SlideshowController Fix #backToMain — restores fragment position lik expect(c.position.sequenceId).toBe("main"); expect(c.position.slideIndex).toBe(0); expect(c.position.fragmentIndex).toBe(1); - // resumeSlide seeks to the fragment time (fragments[1]=4) minus the render-nudge - expect(p.seek).toHaveBeenLastCalledWith(3.8); + // resumeSlide seeks to the fragment time (fragments[1]=4) + expect(p.seek).toHaveBeenLastCalledWith(4); }); it("backToMain when root fragmentIndex=-1 seeks to slide start", () => { @@ -604,7 +604,7 @@ describe("SlideshowController syncTo", () => { // resumeSlide seeks to slide start, then plays one frame so the composition // repaints (a bare paused seek doesn't re-render some compositions); onTime // pauses again as soon as the player reports it has reached the hold. - expect(p.seek).toHaveBeenLastCalledWith(9.8); // slide start (10) minus render-nudge + expect(p.seek).toHaveBeenLastCalledWith(10); // slide start expect(p.play).toHaveBeenCalled(); p.emit(50); // player passes the render-nudge hold expect(p.pause).toHaveBeenCalled(); @@ -617,7 +617,7 @@ describe("SlideshowController syncTo", () => { expect(c.position.sequenceId).toBe("main"); expect(c.position.slideIndex).toBe(0); expect(c.position.fragmentIndex).toBe(1); - expect(p.seek).toHaveBeenLastCalledWith(3.8); // fragments[1] (4) minus render-nudge + expect(p.seek).toHaveBeenLastCalledWith(4); // fragments[1] = 4 }); it("ignores an unknown sequence target", () => { diff --git a/packages/player/src/slideshow/SlideshowController.ts b/packages/player/src/slideshow/SlideshowController.ts index 38e8a52578..e1777d53ed 100644 --- a/packages/player/src/slideshow/SlideshowController.ts +++ b/packages/player/src/slideshow/SlideshowController.ts @@ -24,6 +24,10 @@ const RENDER_NUDGE = 0.2; export class SlideshowController { private stack: StackFrame[] = [{ sequenceId: MAIN, slideIndex: 0, fragmentIndex: -1 }]; private holdAt: number | null = null; + // The logical hold (a fragment time / slide point). playTo() plays a short way + // PAST it (to holdAt) so the composition repaints; holdTarget is what onTime + // matches against fragments to advance fragmentIndex. + private holdTarget: number | null = null; private changeCbs = new Set<() => void>(); private unsub: () => void; @@ -105,13 +109,21 @@ export class SlideshowController { this.holdAt = null; const slide = this.currentSlide; if (!slide) return; - // Jump to the slide's first hold (its first fragment, or the built end-state - // when it has none). playTo() seeks rather than sustaining playback, so the - // slide does NOT auto-progress — it shows a static frame and waits. - this.playTo(this.nextStop(slide, -1)); + // Jump to the slide's first hold and stay there (no auto-progress). With + // fragments that's the first fragment; without, a settled frame INSIDE the + // slide (its midpoint) — NOT slide.end, which is the boundary where the next + // scene begins (else slide 1 would render slide 2's content). + const firstHold = + slide.fragments.length > 0 ? (slide.fragments[0] ?? slide.end) : this.restFrame(slide); + this.playTo(firstHold); this.emitChange(); } + /** A representative, non-boundary frame for a slide with no fragments. */ + private restFrame(slide: ResolvedSlide): number { + return slide.start + (slide.end - slide.start) * 0.5; + } + /** * Resumes a slide at a saved fragmentIndex without resetting to slide start. * Used by back()/backToMain()/syncTo() to restore an exact position. @@ -144,19 +156,26 @@ export class SlideshowController { * and advances fragmentIndex when `t` is a fragment boundary. */ private playTo(t: number): void { - this.holdAt = t; - this.player.seek(Math.max(0, t - RENDER_NUDGE)); + // Seek to the EXACT target so the first repainted frame is the correct one — + // seeking BEFORE it (as a backward render-nudge) flashes a pre-target frame + // / the previous scene. Then play a short way PAST it so the composition + // actually repaints (a bare paused seek doesn't), and onTime() pauses there. + const slide = this.currentSlide; + this.holdTarget = t; + this.holdAt = slide ? Math.min(t + RENDER_NUDGE, slide.end) : t + RENDER_NUDGE; + this.player.seek(t); this.player.play(); } - private onTime(t: number): void { - if (this.holdAt !== null && t >= this.holdAt - EPS) { - const hold = this.holdAt; + private onTime(tt: number): void { + if (this.holdAt !== null && tt >= this.holdAt - EPS) { + const target = this.holdTarget; this.holdAt = null; - // Advance fragmentIndex if this hold is a fragment boundary. + this.holdTarget = null; + // Advance fragmentIndex if the logical target is a fragment boundary. const slide = this.currentSlide; - if (slide) { - const fragIdx = slide.fragments.indexOf(hold); + if (slide && target !== null) { + const fragIdx = slide.fragments.indexOf(target); if (fragIdx !== -1) { this.frame.fragmentIndex = fragIdx; this.emitChange(); diff --git a/packages/player/src/slideshow/hyperframes-slideshow.ts b/packages/player/src/slideshow/hyperframes-slideshow.ts index 1f1f241651..3a08a5349d 100644 --- a/packages/player/src/slideshow/hyperframes-slideshow.ts +++ b/packages/player/src/slideshow/hyperframes-slideshow.ts @@ -362,14 +362,7 @@ export class HyperframesSlideshow extends HTMLElement { // Audience (viewer) window: no nav controls — but keep a fullscreen toggle // so the presentation can fill the display. const { counter } = this.controller; - if (!this.chrome) { - this.chrome = document.createElement("div"); - this.chrome.setAttribute("data-hf-chrome", ""); - this.appendChild(this.chrome); - } - this.chrome.style.cssText = "position:absolute;inset:0;pointer-events:none;z-index:10;"; - this.chrome.innerHTML = this.buildNavCluster(counter, "28px", "fs-only"); - this.wireChromeButtons(); + this.paintChrome(this.buildNavCluster(counter, "28px", "fs-only")); return; } @@ -381,13 +374,6 @@ export class HyperframesSlideshow extends HTMLElement { const { counter, currentSlide } = this.controller; if (!currentSlide) return; - if (!this.chrome) { - this.chrome = document.createElement("div"); - this.chrome.setAttribute("data-hf-chrome", ""); - this.chrome.style.cssText = "position:absolute;inset:0;pointer-events:none;z-index:10;"; - this.appendChild(this.chrome); - } - // Inject keyframes for hotspot pulse animation once per document. injectKeyframesOnce(); @@ -411,14 +397,25 @@ export class HyperframesSlideshow extends HTMLElement { }) .join(""); + this.paintChrome(hotspotsHtml + this.buildNavCluster(counter, "28px")); + } + + /** Ensure the overlay chrome layer exists, set its content, and wire its buttons. */ + private paintChrome(html: string): void { + if (!this.chrome) { + this.chrome = document.createElement("div"); + this.chrome.setAttribute("data-hf-chrome", ""); + this.appendChild(this.chrome); + } this.chrome.style.cssText = "position:absolute;inset:0;pointer-events:none;z-index:10;"; - this.chrome.innerHTML = hotspotsHtml + this.buildNavCluster(counter, "28px"); + this.chrome.innerHTML = html; this.wireChromeButtons(); } // Builds the nav cluster ([mute?] [prev] counter [next] | [fullscreen]) as a // floating capsule. `bottomCss` positions it (normal view: "28px"; presenter // view: above the notes panel). Reused by render() and renderPresenter(). + // fallow-ignore-next-line complexity private buildNavCluster( counter: { index: number; total: number }, bottomCss: string, @@ -572,22 +569,17 @@ export class HyperframesSlideshow extends HTMLElement { playerEl.style.height = "auto"; } - if (!this.chrome) { - this.chrome = document.createElement("div"); - this.chrome.setAttribute("data-hf-chrome", ""); - this.appendChild(this.chrome); - } // Full-overlay chrome (pointer-events:none); the notes panel and nav cluster // are the only interactive children. - this.chrome.style.cssText = "position:absolute;inset:0;pointer-events:none;z-index:10;"; - this.chrome.innerHTML = + this.paintChrome( buildPresenterLayout({ notes: currentSlide.notes ?? "", nextText: nextPanelText(nextSlide), counterText: `${counter.index} / ${counter.total}`, elapsedText: formatElapsed(elapsedSec), - }) + this.buildNavCluster(counter, "calc(32% + 18px)"); - this.wireChromeButtons(); + hotspots: currentSlide.hotspots, + }) + this.buildNavCluster(counter, "calc(32% + 18px)"), + ); } } diff --git a/packages/player/src/slideshow/slideshowPresenter.ts b/packages/player/src/slideshow/slideshowPresenter.ts index e777994235..5bee6fd3ec 100644 --- a/packages/player/src/slideshow/slideshowPresenter.ts +++ b/packages/player/src/slideshow/slideshowPresenter.ts @@ -76,17 +76,35 @@ export function buildPresenterLayout(opts: { nextText: string; counterText: string; elapsedText: string; + hotspots: { id: string; label: string; target: string }[]; }): string { const esc = (s: string) => s.replace(/&/g, "&").replace(//g, ">"); + const escAttr = (s: string) => esc(s).replace(/"/g, """); const notes = opts.notes ? esc(opts.notes) : `No notes for this slide`; + // Branch entries for the current slide — the presenter clicks these to enter a + // branch (the audience follows). The component wires [data-hotspot-id] to + // enterBranch(); positioned pills don't align with the letterboxed slide, so + // they live in the console as a list. + const branches = opts.hotspots.length + ? `