fix(slideshow): presenter nav flash, slide-1 boundary, branch buttons

Three presenter-mode fixes from testing the airbnb deck: (1) navigation flash — seek to the exact target then play forward to repaint, instead of seeking backward (t-0.2) which painted the previous scene at boundaries; split hold into holdTarget (logical) and holdAt (target+nudge, clamped to slide.end). (2) slide-1 boundary — no-fragment slides rest at the slide midpoint, not slide.end. (3) presenter branch buttons — surface hotspots as buttons in the presenter console (the on-slide pill is lost in the letterboxed view). Also extract paintChrome() to dedupe the three chrome-render sites.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Vance Ingalls
2026-06-19 01:37:25 -07:00
co-authored by Claude Opus 4.8
parent 2e5e63c68e
commit 0f229fedc8
4 changed files with 87 additions and 58 deletions
@@ -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", () => {
@@ -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();
@@ -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)"),
);
}
}
@@ -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, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
const escAttr = (s: string) => esc(s).replace(/"/g, "&quot;");
const notes = opts.notes
? esc(opts.notes)
: `<span style="opacity:.4">No notes for this slide</span>`;
// 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
? `<div style="display:flex;flex-direction:column;gap:6px;">
<div style="font-size:12px;text-transform:uppercase;letter-spacing:.12em;opacity:.55;">Branches</div>
${opts.hotspots
.map(
(h) =>
`<button data-hotspot-id="${escAttr(h.id)}" data-hotspot-target="${escAttr(h.target)}" type="button" style="text-align:left;background:rgba(244,183,64,0.14);color:#f4b740;border:1px solid rgba(244,183,64,0.4);border-radius:8px;padding:8px 12px;font-size:15px;cursor:pointer;pointer-events:auto;font-family:inherit;">&#8627; ${esc(h.label)}</button>`,
)
.join("")}
</div>`
: "";
return `
<div data-hf-presenter style="position:absolute;left:0;right:0;bottom:0;height:32%;display:flex;background:#11151f;color:#fff;border-top:2px solid rgba(255,255,255,0.12);box-sizing:border-box;font-family:sans-serif;pointer-events:auto;">
<div data-hf-presenter-notes style="flex:1;min-width:0;padding:24px 36px;overflow-y:auto;font-size:21px;line-height:1.55;">${notes}</div>
<div style="width:380px;flex-shrink:0;border-left:1px solid rgba(255,255,255,0.12);padding:24px 28px;display:flex;flex-direction:column;gap:10px;">
<div style="font-size:12px;text-transform:uppercase;letter-spacing:.12em;opacity:.55;">Up next</div>
<div data-hf-presenter-next style="font-size:17px;opacity:.9;line-height:1.4;">${esc(opts.nextText)}</div>
${branches}
<div style="display:flex;gap:34px;margin-top:auto;">
<div><div style="font-size:11px;text-transform:uppercase;letter-spacing:.1em;opacity:.5;margin-bottom:3px;">Slide</div><div data-hf-presenter-counter style="font-size:23px;font-variant-numeric:tabular-nums;">${esc(opts.counterText)}</div></div>
<div><div style="font-size:11px;text-transform:uppercase;letter-spacing:.1em;opacity:.5;margin-bottom:3px;">Elapsed</div><div data-hf-presenter-elapsed style="font-size:23px;font-variant-numeric:tabular-nums;">${esc(opts.elapsedText)}</div></div>