mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-07 18:26:17 +00:00
* fix(slideshow): address code-review findings #1580-1584
- player: bundle @hyperframes/core into the IIFE/global build (noExternal)
- player: resolve audience mode from ?mode=audience URL query, not just attr
- player: event-driven waitForScenes + loud failure when no slides resolve
- player: scope window keydown so Space/Backspace don't hijack the host page
- player: audience mirrors full position (branch + fragment) via syncTo
- player: next() reveals remaining fragments even at slide end; enterBranch ignores empty sequences
- core: harden extractScenes against null/non-object scene entries
- core: strict manifest validation; error on inverted ranges & empty hotspot targets; dedup fragments
- core/lint: accept data-end/timeline-derived scene durations (match runtime)
- core+studio: share ISLAND_TYPE + island regex from @hyperframes/core/slideshow
- studio: SlideList reflects manifest slide order; branch-slide authoring (notes/fragments/hotspots)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* feat(player): slideshow fullscreen + presenter-view rework
- fullscreen toggle in the nav chrome (button + 'F' key); standard Fullscreen
API on the <hyperframes-slideshow> element, icon reflects state
- presenter console: live slide on top, speaker-notes panel below, with the nav
controls shown in-view; Present button hides once presenting (harness)
- audience (viewer) window: chrome reduced to a fullscreen-only control, no nav
- fix: audience / back() / backToMain() mirror stayed frozen on the first frame —
a bare paused seek does not repaint some compositions. resumeSlide now plays a
brief render-nudge (RENDER_NUDGE) past the target so the composition paints,
then onTime pauses at the hold
- refactor: extract reusable buildNavCluster() + wireChromeButtons(); rework
buildPresenterLayout into the bottom notes panel
- example: airbnb-deck presenter-test.html harness (Present button + 'F')
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(player): slideshow no auto-progress + presenter slide fits/pins
- navigation jumps to a static frame instead of auto-playing the timeline:
playTo() seeks to the hold (+ a brief RENDER_NUDGE to repaint) rather than
sustaining playback, so slides hold until the user advances
- presenter view: pin the live slide to the top and confine the player to the
region above the notes panel, so the player CONTAINS the composition — the
full slide stays visible (letterboxed) at any width and re-fits on resize;
its bottom is no longer cut off by the notes panel
- tests: seek targets updated for the render-nudge offset
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* 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>
* fix(slideshow): stop presenter nav buttons flickering / dropping clicks
The presenter elapsed clock called render() every second, which rebuilt the
entire chrome (innerHTML) including the nav buttons — they flickered and any
click landing mid-rebuild was lost. The 1s tick now updates only the elapsed
text node; the nav buttons are rebuilt only on actual navigation.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(slideshow): CSP-safe nav hover, UUID editor ids, manifest version
Addresses review feedback on the split stack:
- CSP: replace the 8 inline onmouseover/onmouseout handlers on the nav
buttons with a [data-hf-nav-cluster] button:hover CSS rule (injected once
per document). No inline event handlers → works under strict CSP.
- IDs: studio sequence/hotspot id generation used Date.now() (sub-ms
collision on rapid clicks) — now crypto.randomUUID().
- Versioning: stamp version on the persisted manifest island (preserving an
existing one); add the optional version field + SLIDESHOW_MANIFEST_VERSION
to the core schema so future schema changes can migrate older islands.
These live on the review-fixes tip (consistent with the stack's fixup-on-tip
model); the touched code belongs to ss-player-b (#1590), ss-studio-a/b
(#1591/#1592), and ss-core (#1580).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* chore(ci): fix format + fallow gates for slideshow stack
- .prettierignore: exclude generated demo compositions (registry/examples/**/*.html)
from oxfmt — large video-pipeline output (GSAP/Three/WebGL), not hand-authored
source. Was failing 'Format' repo-wide (pre-existing on main via #1584).
- .fallowrc: exempt SlideshowPanel.tsx (health/complexity — section fan-out) and
the slideshowPanelHelpers.ts / SlideshowPanel.test.ts parallel-structure clones
(duplicates.ignore). File-level config, not inline comments — inline shifts line
numbers and breaks fallow's inherited-finding fingerprint (per existing rc note).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix(slideshow): address PR review + CodeQL findings
- CodeQL #638 (parseSlideshow): complete the regex metachar escape in
slideshowIslandRegex (was missing backslash); add JSDoc on the factory +
lastIndex caveat (reviewer 5a/16).
- CodeQL #639/#640 + review items 13/17: remove registry/examples/airbnb-deck/
presenter-test.html — a generated test harness (postMessage w/o origin check,
proto-pollution) that was scope-creep into a fix PR and a 3rd duplicate island.
Regenerate locally via the scratchpad script when testing.
- Review item 15 (docs drift in skills/slideshow/SKILL.md): lint resolves scenes
by data-composition-id only (not .clip[id]); fragments are valid INCLUSIVE of
[start,end], not 'strictly inside'.
IIFE bundles core confirmed (0 external @hyperframes/core refs in the slideshow
global build). format/lint/fallow green.
* feat(cli): add 'present' command — serve a deck in presenter mode
hyperframes present [dir] starts a lightweight HTTP server, wraps the
composition in <hyperframes-slideshow> with its island inlined, and opens
the browser. A real HTTP origin is required for presenter mode: present()
opens the audience window via window.open(?mode=audience) and the two sync
over BroadcastChannel — neither works from file://.
- New utils/compositionServer.ts factors the server scaffolding shared with
'play' (resolve runtime/player/slideshow bundles, inject runtime, asset
content-types, bind to a free port); play.ts now uses it too.
- Errors clearly if the deck has no slideshow island.
- .fallowrc: exempt the play/present command entrypoints (validation + server
wiring) and the per-command startup/logging block from the complexity /
duplication gates.
Verified end-to-end against registry/examples/airbnb-deck: server serves the
wrapper + assets, the component binds and renders (counter 1 / 11).
* fix(cli): present renders the deck (player sizing + self-driving serve)
Two bugs caused a black slide area:
- The <hyperframes-player> had no positioning, so its iframe collapsed to
zero size — the (absolutely-positioned) chrome showed but the composition
didn't. Add position:absolute; inset:0 (matches demo.html).
- The composition was served with the engine runtime injected, which leaves
its timelines engine-paused (blank). Slideshow decks self-drive their own
timelines (like demo.html / the standalone harness), so serve them raw.
Verified end-to-end on registry/examples/airbnb-deck: cover renders, Next
advances 1/11 -> 2/11 and slide 2 paints.
* fix(cli): present plays slideshow sound effects
The composition (in the player's sandboxed iframe) posts
{ type: 'hf-sfx', name } to the parent on nav, but the iframe is
autoplay-blocked — audio must play in the parent that owns the user gesture.
Add the parent-side hf-sfx handler (the 4 standard clips advance/fragment/
branch-enter/back, served from the deck's sfx/ under /composition/sfx/),
gesture-unlocked and mute-aware, in both presenter and audience windows.
Verified: sfx serve 200 (audio/mpeg) and Next delivers [advance, fragment]
to the parent handler.
* feat(examples): softer mellow slideshow sfx for airbnb-deck
Replace the aggressive percussive pops with gentle sine-tone cues (warm
pitches C5/G4/E5/F4, 12ms attack + exponential decay, lowpassed) — advance/
fragment/branch-enter/back. Much lighter; fragment is the most subtle.
* feat(examples): whoosh + sparkle slideshow sfx for airbnb-deck
Replace the sine-tone cues with airy, designed sounds:
- advance: a soft whoosh (band-limited pink noise, bell-shaped swell)
- back: that whoosh reversed and darkened
- fragment: a light sparkle (staggered high chime blips)
- branch-enter: whoosh + a trailing sparkle (magical entry)
* feat(examples): directional whoosh + richer branch-enter cue (airbnb-deck)
- Going backward a slide now plays the reverse whoosh (back), not advance —
the sfx logic detects nav direction by scene order instead of firing advance
for every scene change.
- branch-enter is now a more interesting magical cue: a faint whoosh + an
ascending C5-E5-G5-C6 chime arpeggio + a trailing sparkle.
Verified: next then prev fires [advance, fragment, back]; no page errors.
* fix(cli): harden present sfx handler + mute-hover affordance (R2 review)
Addresses Rames R2 items 19-21:
- 20: the present audio handler reintroduced the CodeQL classes removed with
presenter-test.html — add an origin check (same-origin composition iframe)
and an own-property guard so a 'name' like __proto__ can't resolve to and
mutate Object.prototype.
- 21: assetContentType used a bare index lookup (ext='__proto__' -> prototype);
guard with Object.hasOwn.
- 19: the CSP hover rule erased the speaker button's muted color; add a
higher-specificity [data-hf-muted] [data-hf-mute]:hover override.
Verified: hf-sfx origin matches location.origin (guard passes), advance/fragment
still fire, deck renders + advances. Items 14/18/22 deferred (minor, pre-existing).
* fix(slideshow): address remaining R2 items (14/18/22) + re-remove harness
- 14: resumeSlide now mirrors enterSlide — a no-fragment slide resumes at its
midpoint (visible-at-rest), not frame-0; fragmented slides still resume to the
saved fragment or slide.start. Added a dedicated test naming the heuristic.
- 18: fullscreenchange swaps only the fullscreen glyph + aria (hoisted SVGs to
module consts) instead of re-rendering the whole chrome.
- 22: .prettierignore lists the specific generated demo compositions instead of
blanket registry/examples/**/*.html, so hand-authored example HTML still formats.
- presenter-test.html: a stray 54a4460 git add -A had re-added the deleted
harness (reviving CodeQL #639/#640); remove it again.
106 slideshow tests pass; tsc/lint/fallow/format clean; deck still renders.
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
298 lines
12 KiB
TypeScript
298 lines
12 KiB
TypeScript
import { defineCommand } from "citty";
|
|
import type { Example } from "./_examples.js";
|
|
import { existsSync, readFileSync } from "node:fs";
|
|
|
|
export const examples: Example[] = [
|
|
["Present the current deck", "hyperframes present"],
|
|
["Present a specific project directory", "hyperframes present ./my-deck"],
|
|
["Use a custom port", "hyperframes present --port 8080"],
|
|
["Start without opening the browser", "hyperframes present --no-open"],
|
|
["Open with a specific browser", "hyperframes present --browser-path /usr/bin/chromium"],
|
|
];
|
|
import { resolve } from "node:path";
|
|
import * as clack from "@clack/prompts";
|
|
import { c } from "../ui/colors.js";
|
|
import { resolveProject } from "../utils/project.js";
|
|
import {
|
|
openBrowser,
|
|
parseRemoteDebuggingPort,
|
|
validateRemoteDebuggingPortDeps,
|
|
} from "../utils/openBrowser.js";
|
|
import {
|
|
resolvePlayerPath,
|
|
resolveSlideshowPath,
|
|
listenOnFreePort,
|
|
assetContentType,
|
|
} from "../utils/compositionServer.js";
|
|
|
|
export default defineCommand({
|
|
meta: {
|
|
name: "present",
|
|
description: "Serve a slideshow deck and open it in presenter mode (with audience sync)",
|
|
},
|
|
args: {
|
|
dir: { type: "positional", description: "Project directory", required: false },
|
|
port: { type: "string", description: "Port to run the present server on", default: "3004" },
|
|
open: { type: "boolean", default: true, description: "Open browser automatically" },
|
|
"browser-path": { type: "string", description: "Path to the browser executable to open" },
|
|
"user-data-dir": {
|
|
type: "string",
|
|
description: "Chromium-compatible user data directory (requires --browser-path)",
|
|
},
|
|
"remote-debugging-port": {
|
|
type: "string",
|
|
description: "Chromium remote debugging port (requires --browser-path and --user-data-dir)",
|
|
},
|
|
},
|
|
async run({ args }) {
|
|
const project = resolveProject(args.dir);
|
|
const startPort = parseInt(args.port ?? "3004", 10);
|
|
|
|
if (args["user-data-dir"] && !args["browser-path"]) {
|
|
clack.log.error("--user-data-dir requires --browser-path");
|
|
process.exitCode = 1;
|
|
return;
|
|
}
|
|
const depsError = validateRemoteDebuggingPortDeps({
|
|
browserPath: args["browser-path"] as string | undefined,
|
|
userDataDir: args["user-data-dir"] as string | undefined,
|
|
remoteDebuggingPort: args["remote-debugging-port"] as string | undefined,
|
|
});
|
|
if (depsError) {
|
|
clack.log.error(depsError);
|
|
process.exitCode = 1;
|
|
return;
|
|
}
|
|
let remoteDebuggingPort: number | undefined;
|
|
try {
|
|
remoteDebuggingPort = parseRemoteDebuggingPort(
|
|
args["remote-debugging-port"] as string | undefined,
|
|
);
|
|
} catch (err) {
|
|
clack.log.error((err as Error).message);
|
|
process.exitCode = 1;
|
|
return;
|
|
}
|
|
|
|
const playerPath = resolvePlayerPath();
|
|
const slideshowPath = resolveSlideshowPath();
|
|
if (!playerPath || !slideshowPath) {
|
|
clack.log.error(
|
|
"@hyperframes/player not found. Run `bun run --cwd packages/player build` first.",
|
|
);
|
|
process.exitCode = 1;
|
|
return;
|
|
}
|
|
|
|
// The deck must carry a slideshow island; the presenter view is meaningless
|
|
// without one. Extract it here so we can inline it into the wrapper page.
|
|
const indexHtml = readFileSync(project.indexPath, "utf-8");
|
|
const { slideshowIslandRegex } = await import("@hyperframes/core/slideshow");
|
|
const islandMatch = slideshowIslandRegex("i").exec(indexHtml);
|
|
if (!islandMatch?.[1]) {
|
|
clack.log.error(
|
|
`No slideshow island found in ${project.indexPath}. ` +
|
|
`Add a <script type="application/hyperframes-slideshow+json"> block — see /hyperframes (slideshow).`,
|
|
);
|
|
process.exitCode = 1;
|
|
return;
|
|
}
|
|
const islandJson = islandMatch[1].trim();
|
|
|
|
const { Hono } = await import("hono");
|
|
const { createAdaptorServer } = await import("@hono/node-server");
|
|
const { isSafePath } = await import("@hyperframes/core/studio-api");
|
|
|
|
const app = new Hono();
|
|
|
|
app.get("/player.js", (ctx) =>
|
|
ctx.body(readFileSync(playerPath, "utf-8"), 200, {
|
|
"Content-Type": "application/javascript",
|
|
"Cache-Control": "no-cache",
|
|
}),
|
|
);
|
|
app.get("/slideshow.js", (ctx) =>
|
|
ctx.body(readFileSync(slideshowPath, "utf-8"), 200, {
|
|
"Content-Type": "application/javascript",
|
|
"Cache-Control": "no-cache",
|
|
}),
|
|
);
|
|
// Serve composition files raw. Slideshow compositions self-drive their own
|
|
// timelines (no engine runtime injected) — the same model demo.html / the
|
|
// standalone harness use; injecting a runtime would leave the composition
|
|
// engine-paused and blank.
|
|
app.get("/composition/*", (ctx) => {
|
|
const reqPath = ctx.req.path.replace("/composition/", "");
|
|
const filePath = resolve(project.dir, reqPath);
|
|
// Security: canonicalizes symlinks + guards the trailing separator so neither
|
|
// an in-project symlink nor a sibling dir sharing the prefix can escape.
|
|
if (!isSafePath(project.dir, filePath)) return ctx.text("Forbidden", 403);
|
|
if (!existsSync(filePath)) return ctx.text("Not found", 404);
|
|
if (filePath.endsWith(".html")) return ctx.html(readFileSync(filePath, "utf-8"));
|
|
return ctx.body(readFileSync(filePath), 200, { "Content-Type": assetContentType(filePath) });
|
|
});
|
|
|
|
// Both the presenter window and the audience window (opened by present() with
|
|
// ?mode=audience) load this same page; the component reads the mode from the URL.
|
|
app.get("/", (ctx) => ctx.html(buildPresentPage(project.name, islandJson)));
|
|
|
|
clack.intro(c.bold("hyperframes present"));
|
|
const s = clack.spinner();
|
|
s.start("Starting presenter server...");
|
|
|
|
const server = createAdaptorServer({ fetch: app.fetch });
|
|
const actualPort = await listenOnFreePort(server, startPort);
|
|
|
|
const url = `http://localhost:${actualPort}`;
|
|
s.stop(c.success("Presenter server running"));
|
|
console.log();
|
|
if (actualPort !== startPort) {
|
|
console.log(` ${c.warn(`Port ${startPort} is in use, using ${actualPort} instead`)}`);
|
|
}
|
|
console.log(` ${c.dim("Deck")} ${c.accent(project.name)}`);
|
|
console.log(` ${c.dim("Present")} ${c.accent(url)}`);
|
|
console.log();
|
|
console.log(` ${c.dim("Click ▶ Present (or press P) to open the audience display.")}`);
|
|
console.log(` ${c.dim("Press Ctrl+C to stop")}`);
|
|
console.log();
|
|
|
|
if (args.open) {
|
|
void openBrowser(url, {
|
|
browserPath: args["browser-path"] as string | undefined,
|
|
userDataDir: args["user-data-dir"] as string | undefined,
|
|
remoteDebuggingPort,
|
|
});
|
|
}
|
|
|
|
return new Promise<void>(() => {});
|
|
},
|
|
});
|
|
|
|
function buildPresentPage(projectName: string, islandJson: string): string {
|
|
return `<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>${projectName} — Presenter</title>
|
|
<style>
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
html, body { height: 100%; background: #0a0a0a; overflow: hidden; }
|
|
hyperframes-slideshow { display: block; position: relative; width: 100vw; height: 100vh; }
|
|
hyperframes-player { position: absolute; inset: 0; }
|
|
#present-btn {
|
|
position: fixed; top: 18px; right: 18px; z-index: 99999;
|
|
font: 600 14px/1 system-ui, sans-serif; color: #0d1321;
|
|
background: #f4b740; border: none; border-radius: 999px;
|
|
padding: 11px 18px; cursor: pointer; box-shadow: 0 6px 20px rgba(0,0,0,.45);
|
|
}
|
|
#present-btn:hover { background: #ffcb5c; }
|
|
</style>
|
|
<script src="/player.js"></script>
|
|
<script src="/slideshow.js"></script>
|
|
</head>
|
|
<body>
|
|
<hyperframes-slideshow tabindex="0" sound>
|
|
<hyperframes-player src="/composition/index.html"></hyperframes-player>
|
|
<script type="application/hyperframes-slideshow+json">
|
|
${islandJson}
|
|
</script>
|
|
</hyperframes-slideshow>
|
|
<button id="present-btn" type="button">▶ Present</button>
|
|
<script>
|
|
(function () {
|
|
// The audience window loads this same page with ?mode=audience; it must not
|
|
// show the Present button or it would recurse opening windows.
|
|
var isAudience = new URLSearchParams(location.search).get("mode") === "audience";
|
|
var btn = document.getElementById("present-btn");
|
|
if (isAudience) { if (btn) btn.remove(); return; }
|
|
function present() {
|
|
var ss = document.querySelector("hyperframes-slideshow");
|
|
if (ss && typeof ss.present === "function") {
|
|
ss.present();
|
|
if (btn) btn.style.display = "none";
|
|
}
|
|
}
|
|
if (btn) btn.addEventListener("click", present);
|
|
// 'P' opens presenter mode (window.open needs a user gesture, so a key/click).
|
|
window.addEventListener("keydown", function (e) {
|
|
if ((e.key === "p" || e.key === "P") && !e.metaKey && !e.ctrlKey) present();
|
|
});
|
|
})();
|
|
</script>
|
|
<script>
|
|
// Sound effects play HERE, in the parent document. The composition runs in the
|
|
// player's iframe, which is autoplay-blocked without its own user gesture; the
|
|
// slideshow posts { type: "hf-sfx", name } to the parent on nav, and we play the
|
|
// matching clip from the deck's sfx/ folder (served under /composition/sfx/).
|
|
// Runs in both presenter and audience windows. Missing clips fail silently.
|
|
(function () {
|
|
var clips = {
|
|
advance: new Audio("/composition/sfx/advance.mp3"),
|
|
fragment: new Audio("/composition/sfx/fragment.mp3"),
|
|
"branch-enter": new Audio("/composition/sfx/branch-enter.mp3"),
|
|
back: new Audio("/composition/sfx/back.mp3"),
|
|
};
|
|
clips.advance.volume = 0.45;
|
|
clips.fragment.volume = 0.4;
|
|
clips["branch-enter"].volume = 0.4;
|
|
clips.back.volume = 0.4;
|
|
for (var k in clips) clips[k].preload = "auto";
|
|
|
|
// Mute state is owned by <hyperframes-slideshow sound>; mirror it.
|
|
var muted = false;
|
|
var ss = document.querySelector("hyperframes-slideshow");
|
|
if (ss) {
|
|
ss.addEventListener("hf-sound", function (e) {
|
|
muted = e.detail && e.detail.muted === true;
|
|
});
|
|
}
|
|
|
|
// Autoplay needs a user gesture — prime each clip (play muted, reset) on the
|
|
// first interaction so later plays are instant and allowed.
|
|
var unlocked = false;
|
|
function unlock() {
|
|
if (unlocked) return;
|
|
unlocked = true;
|
|
Object.keys(clips).forEach(function (name) {
|
|
var el = clips[name];
|
|
var v = el.volume;
|
|
el.volume = 0;
|
|
el.play()
|
|
.then(function () {
|
|
el.pause();
|
|
el.currentTime = 0;
|
|
el.volume = v;
|
|
})
|
|
.catch(function () {
|
|
el.volume = v;
|
|
});
|
|
});
|
|
}
|
|
window.addEventListener("keydown", unlock, true);
|
|
window.addEventListener("pointerdown", unlock, true);
|
|
window.addEventListener("click", unlock, true);
|
|
|
|
window.addEventListener("message", function (e) {
|
|
// Only accept cues from this origin (the composition iframe is same-origin).
|
|
if (e.origin !== location.origin) return;
|
|
var d = e.data;
|
|
if (!d || d.type !== "hf-sfx" || muted) return;
|
|
// Own-property guard: a malicious name like "__proto__" must not resolve to
|
|
// a prototype object (which would be truthy and then get mutated below).
|
|
if (!Object.prototype.hasOwnProperty.call(clips, d.name)) return;
|
|
var el = clips[d.name];
|
|
if (!el || !unlocked) return;
|
|
try {
|
|
el.currentTime = 0;
|
|
el.play().catch(function () {});
|
|
} catch (err) {
|
|
/* ignore */
|
|
}
|
|
});
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>`;
|
|
}
|