Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
fix: handle player loop and render exit (#617)
Miguel Ángel7affa4a4e919
diff --git a/.github/workflows/catalog-previews.yml b/.github/workflows/catalog-previews.ymlindex 5f25c2165c..7f73593e46 100644--- a/.github/workflows/catalog-previews.yml+++ b/.github/workflows/catalog-previews.yml@@ -44,7 +44,7 @@ jobs:run: |# Find which blocks/components changed in this PRBASE_SHA=${{ github.event.pull_request.base.sha }}- CHANGED_ITEMS=$(git diff --name-only "$BASE_SHA"...HEAD -- registry/blocks/ registry/components/ \+ CHANGED_ITEMS=$(git diff --name-only --diff-filter=ACMR "$BASE_SHA"...HEAD -- registry/blocks/ registry/components/ \| grep -E '^registry/(blocks|components)/' \| sed 's|^registry/[^/]*/\([^/]*\)/.*|\1|' \| sort -u)diff --git a/docs/catalog/blocks/goonvpn-youtube-spot.mdx b/docs/catalog/blocks/goonvpn-youtube-spot.mdxdeleted file mode 100644index 5e5481f13d..0000000000--- a/docs/catalog/blocks/goonvpn-youtube-spot.mdx+++ /dev/null@@ -1,53 +0,0 @@-----title: "GoonVPN YouTube Spot"-description: "Snappy Apple-style YouTube insert showing a phone finding and installing a fictional VPN app with sound effects."------# GoonVPN YouTube Spot--Snappy Apple-style YouTube insert showing a phone finding and installing a fictional VPN app with sound effects.--`app` `showcase` `youtube` `sfx`--Created by [Stronkter](https://x.com/Stronkter).--## Source Prompt--```text-📷HyperFrames by HeyGen make me a 7s video apple style bold font and styling a phone scrolling in a appstore clicking on a vpn app called goonVPN and installing it the app installs the phone snaps down and fades to a white backround make it snappy and pop its for a youtube video also add soundfx and make it 60fps and 1920x1080-```--<video className="w-full aspect-video rounded-xl object-cover bg-zinc-100 dark:bg-zinc-800" src="https://static.heygen.ai/hyperframes-oss/docs/images/catalog/blocks/goonvpn-youtube-spot.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/catalog/blocks/goonvpn-youtube-spot.png" autoPlay muted loop playsInline />--## Install--<CodeGroup>--```bash Terminal-npx hyperframes add goonvpn-youtube-spot-```--</CodeGroup>--## Details--| Property | Value |-| --- | --- |-| Type | Block |-| Dimensions | 1920×1080 |-| Duration | 7s |--## Files--| File | Target | Type |-| --- | --- | --- |-| `goonvpn-youtube-spot.html` | `compositions/goonvpn-youtube-spot.html` | hyperframes:composition |-| `assets/goonvpn-sfx.wav` | `assets/goonvpn-sfx.wav` | hyperframes:asset |--## Usage--After installing, add the block to your host composition:--```html-<div data-composition-id="goonvpn-youtube-spot" data-composition-src="compositions/goonvpn-youtube-spot.html" data-start="0" data-duration="7" data-track-index="1" data-width="1920" data-height="1080"></div>-```diff --git a/docs/catalog/blocks/vpn-youtube-spot.mdx b/docs/catalog/blocks/vpn-youtube-spot.mdxnew file mode 100644index 0000000000..d2d044b9e5--- /dev/null+++ b/docs/catalog/blocks/vpn-youtube-spot.mdx@@ -0,0 +1,53 @@+---+title: "VPN YouTube Spot"+description: "Snappy Apple-style YouTube insert showing a phone finding and installing a friendly VPN app with sound effects."+---++# VPN YouTube Spot++Snappy Apple-style YouTube insert showing a phone finding and installing a friendly VPN app with sound effects.++`app` `showcase` `youtube` `sfx`++Created by [Stronkter](https://x.com/Stronkter).++## Source Prompt++```text+HyperFrames by HeyGen make me a 7s video with Apple-style bold font and styling: a phone scrolling in an app store, clicking on a friendly VPN app called VPN, installing it, then snapping down and fading to a white background. Make it snappy and polished for a YouTube insert, with sound effects, 60fps, and 1920x1080.+```++<video className="w-full aspect-video rounded-xl object-cover bg-zinc-100 dark:bg-zinc-800" src="https://static.heygen.ai/hyperframes-oss/docs/images/catalog/blocks/vpn-youtube-spot.mp4" poster="https://static.heygen.ai/hyperframes-oss/docs/images/catalog/blocks/vpn-youtube-spot.png" autoPlay muted loop playsInline />++## Install++<CodeGroup>++```bash Terminal+npx hyperframes add vpn-youtube-spot+```++</CodeGroup>++## Details++| Property | Value |+| --- | --- |+| Type | Block |+| Dimensions | 1920×1080 |+| Duration | 7s |++## Files++| File | Target | Type |+| --- | --- | --- |+| `vpn-youtube-spot.html` | `compositions/vpn-youtube-spot.html` | hyperframes:composition |+| `assets/vpn-sfx.wav` | `assets/vpn-sfx.wav` | hyperframes:asset |++## Usage++After installing, add the block to your host composition:++```html+<div data-composition-id="vpn-youtube-spot" data-composition-src="compositions/vpn-youtube-spot.html" data-start="0" data-duration="7" data-track-index="1" data-width="1920" data-height="1080"></div>+```diff --git a/docs/docs.json b/docs/docs.jsonindex 6966619721..f341f19202 100644--- a/docs/docs.json+++ b/docs/docs.json@@ -144,7 +144,7 @@"pages": ["catalog/blocks/app-showcase","catalog/blocks/apple-money-count",- "catalog/blocks/goonvpn-youtube-spot",+ "catalog/blocks/vpn-youtube-spot","catalog/blocks/north-korea-locked-down","catalog/blocks/nyc-paris-flight","catalog/blocks/ui-3d-reveal"diff --git a/docs/public/catalog-index.json b/docs/public/catalog-index.jsonindex e33dadda7a..566197d417 100644--- a/docs/public/catalog-index.json+++ b/docs/public/catalog-index.json@@ -126,18 +126,18 @@"preview": "https://static.heygen.ai/hyperframes-oss/docs/images/catalog/blocks/glitch.png"},{- "name": "goonvpn-youtube-spot",+ "name": "vpn-youtube-spot","type": "block",- "title": "GoonVPN YouTube Spot",- "description": "Snappy Apple-style YouTube insert showing a phone finding and installing a fictional VPN app with sound effects.",+ "title": "VPN YouTube Spot",+ "description": "Snappy Apple-style YouTube insert showing a phone finding and installing a friendly VPN app with sound effects.","tags": ["app","showcase","youtube","sfx"],- "href": "/catalog/blocks/goonvpn-youtube-spot",- "preview": "https://static.heygen.ai/hyperframes-oss/docs/images/catalog/blocks/goonvpn-youtube-spot.png"+ "href": "/catalog/blocks/vpn-youtube-spot",+ "preview": "https://static.heygen.ai/hyperframes-oss/docs/images/catalog/blocks/vpn-youtube-spot.png"},{"name": "grain-overlay",diff --git a/packages/cli/src/commands/render.test.ts b/packages/cli/src/commands/render.test.tsindex 4b7ec4d87c..fbf4c2c12a 100644--- a/packages/cli/src/commands/render.test.ts+++ b/packages/cli/src/commands/render.test.ts@@ -47,6 +47,8 @@ describe("renderLocal browser GPU config", () => {}}vi.clearAllMocks();+ vi.useRealTimers();+ vi.restoreAllMocks();});it("passes an explicit software override for --no-browser-gpu even when env requests hardware", async () => {@@ -130,6 +132,31 @@ describe("renderLocal browser GPU config", () => {expect(producerState.createdJobs[0]?.variables).toBeUndefined();});++ it("can force the CLI process to exit after a successful local render", async () => {+ vi.useFakeTimers();+ const exit = vi+ .spyOn(process, "exit")+ .mockImplementation((code?: string | number | null): never => {+ throw new Error(`process.exit:${code ?? ""}`);+ });+ const { renderLocal } = await import("./render.js");++ await renderLocal("/tmp/project", "/tmp/out.mp4", {+ fps: 30,+ quality: "standard",+ format: "mp4",+ gpu: false,+ browserGpu: true,+ hdrMode: "auto",+ quiet: true,+ exitAfterComplete: true,+ });++ expect(exit).not.toHaveBeenCalled();+ expect(() => vi.advanceTimersByTime(100)).toThrow("process.exit:0");+ expect(exit).toHaveBeenCalledWith(0);+ });});describe("parseVariablesArg", () => {diff --git a/packages/cli/src/commands/render.ts b/packages/cli/src/commands/render.tsindex fb78ee1de2..009da0b7b3 100644--- a/packages/cli/src/commands/render.ts+++ b/packages/cli/src/commands/render.ts@@ -403,6 +403,7 @@ export default defineCommand({videoBitrate,quiet,variables,+ exitAfterComplete: true,});} else {await renderLocal(project.dir, outputPath, {@@ -418,6 +419,7 @@ export default defineCommand({quiet,browserPath,variables,+ exitAfterComplete: true,});}},@@ -436,6 +438,7 @@ interface RenderOptions {quiet: boolean;browserPath?: string;variables?: Record<string, unknown>;+ exitAfterComplete?: boolean;}export type VariablesParseError =@@ -748,6 +751,7 @@ async function renderDocker(});printRenderComplete(outputPath, elapsed, options.quiet);+ if (options.exitAfterComplete) scheduleRenderProcessExit();}export async function renderLocal(@@ -796,6 +800,27 @@ export async function renderLocal(const elapsed = Date.now() - startTime;trackRenderMetrics(job, elapsed, options, false);printRenderComplete(outputPath, elapsed, options.quiet);+ if (options.exitAfterComplete) scheduleRenderProcessExit();+}++type UnrefableTimer = {+ unref: () => void;+};++function isUnrefableTimer(+ timer: ReturnType<typeof setTimeout>,+): timer is ReturnType<typeof setTimeout> & UnrefableTimer {+ return (+ typeof timer === "object" &&+ timer !== null &&+ "unref" in timer &&+ typeof timer.unref === "function"+ );+}++function scheduleRenderProcessExit(): void {+ const timer = setTimeout(() => process.exit(0), 100);+ if (isUnrefableTimer(timer)) timer.unref();}function getMemorySnapshot() {diff --git a/packages/player/src/hyperframes-player.test.ts b/packages/player/src/hyperframes-player.test.tsindex 6b26891491..a30190fc89 100644--- a/packages/player/src/hyperframes-player.test.ts+++ b/packages/player/src/hyperframes-player.test.ts@@ -798,6 +798,89 @@ describe("HyperframesPlayer seek() sync path", () => {});});+describe("HyperframesPlayer loop end-state handling", () => {+ type PlayerInternal = HTMLElement & {+ iframe: HTMLIFrameElement;+ play: () => void;+ seek: (timeInSeconds: number) => void;+ loop: boolean;+ _duration: number;+ _paused: boolean;+ _onMessage: (event: MessageEvent) => void;+ };++ let player: PlayerInternal;+ let frameWindow: Window;++ beforeEach(async () => {+ await import("./hyperframes-player.js");+ player = document.createElement("hyperframes-player") as PlayerInternal;+ frameWindow = window;+ vi.spyOn(frameWindow, "postMessage").mockImplementation(() => undefined);+ Object.defineProperty(player.iframe, "contentWindow", {+ configurable: true,+ get: () => frameWindow,+ });+ document.body.appendChild(player);+ });++ afterEach(() => {+ player.remove();+ vi.restoreAllMocks();+ });++ it("wraps and keeps playing when a looping composition posts its final paused state", () => {+ const seek = vi.spyOn(player, "seek");+ const play = vi.spyOn(player, "play");+ player.loop = true;+ player._duration = 4;+ player._paused = false;++ player._onMessage(+ new MessageEvent("message", {+ source: frameWindow,+ data: {+ source: "hf-preview",+ type: "state",+ frame: 120,+ isPlaying: false,+ },+ }),+ );++ expect(seek).toHaveBeenCalledWith(0);+ expect(play).toHaveBeenCalled();+ expect(player._paused).toBe(false);+ });++ it("fires ended and stays paused when a non-looping composition posts its final paused state", () => {+ const seek = vi.spyOn(player, "seek");+ const play = vi.spyOn(player, "play");+ const ended = vi.fn();+ player.addEventListener("ended", ended);+ player.loop = false;+ player._duration = 4;+ player._paused = false;++ player._onMessage(+ new MessageEvent("message", {+ source: frameWindow,+ data: {+ source: "hf-preview",+ type: "state",+ frame: 120,+ isPlaying: false,+ },+ }),+ );++ expect(seek).not.toHaveBeenCalled();+ expect(play).not.toHaveBeenCalled();+ expect(ended).toHaveBeenCalledTimes(1);+ expect(player._paused).toBe(true);+ });+});+describe("HyperframesPlayer srcdoc attribute", () => {type PlayerInternal = HTMLElement & {iframe: HTMLIFrameElement;diff --git a/packages/player/src/hyperframes-player.ts b/packages/player/src/hyperframes-player.tsindex 63bc185464..0c180f7311 100644--- a/packages/player/src/hyperframes-player.ts+++ b/packages/player/src/hyperframes-player.ts@@ -429,7 +429,19 @@ class HyperframesPlayer extends HTMLElement {if (data.type === "state") {this._currentTime = (data.frame ?? 0) / DEFAULT_FPS;const wasPlaying = !this._paused;- this._paused = !data.isPlaying;+ const nextPaused = !data.isPlaying;+ const completedPlayback =+ this._duration > 0 && this._currentTime >= this._duration && (wasPlaying || data.isPlaying);++ if (completedPlayback && this.loop) {+ if (this._audioOwner === "parent") this._pauseParentMedia();+ this._paused = nextPaused;+ this.seek(0);+ this.play();+ return;+ }++ this._paused = nextPaused;// Under parent ownership the proxies are the audible output, so they// mirror the iframe's play/pause transitions (externally-driven pause@@ -456,16 +468,11 @@ class HyperframesPlayer extends HTMLElement {);}- if (this._currentTime >= this._duration && !this._paused) {+ if (completedPlayback) {if (this._audioOwner === "parent") this._pauseParentMedia();- if (this.loop) {- this.seek(0);- this.play();- } else {- this._paused = true;- this.controlsApi?.updatePlaying(false);- this.dispatchEvent(new Event("ended"));- }+ this._paused = true;+ this.controlsApi?.updatePlaying(false);+ this.dispatchEvent(new Event("ended"));}}diff --git a/registry/blocks/goonvpn-youtube-spot/registry-item.json b/registry/blocks/goonvpn-youtube-spot/registry-item.jsondeleted file mode 100644index 73f065ea0d..0000000000--- a/registry/blocks/goonvpn-youtube-spot/registry-item.json+++ /dev/null@@ -1,28 +0,0 @@-{- "$schema": "https://hyperframes.heygen.com/schema/registry-item.json",- "name": "goonvpn-youtube-spot",- "type": "hyperframes:block",- "title": "GoonVPN YouTube Spot",- "description": "Snappy Apple-style YouTube insert showing a phone finding and installing a fictional VPN app with sound effects.",- "tags": ["app", "showcase", "youtube", "sfx"],- "author": "Stronkter",- "authorUrl": "https://x.com/Stronkter",- "sourcePrompt": "\ud83d\udcf7HyperFrames by HeyGen make me a 7s video apple style bold font and styling a phone scrolling in a appstore clicking on a vpn app called goonVPN and installing it the app installs the phone snaps down and fades to a white backround make it snappy and pop its for a youtube video also add soundfx and make it 60fps and 1920x1080",- "dimensions": {- "width": 1920,- "height": 1080- },- "duration": 7,- "files": [- {- "path": "goonvpn-youtube-spot.html",- "target": "compositions/goonvpn-youtube-spot.html",- "type": "hyperframes:composition"- },- {- "path": "assets/goonvpn-sfx.wav",- "target": "assets/goonvpn-sfx.wav",- "type": "hyperframes:asset"- }- ]-}diff --git a/registry/blocks/goonvpn-youtube-spot/assets/goonvpn-sfx.wav b/registry/blocks/vpn-youtube-spot/assets/vpn-sfx.wavsimilarity index 100%rename from registry/blocks/goonvpn-youtube-spot/assets/goonvpn-sfx.wavrename to registry/blocks/vpn-youtube-spot/assets/vpn-sfx.wavdiff --git a/registry/blocks/vpn-youtube-spot/registry-item.json b/registry/blocks/vpn-youtube-spot/registry-item.jsonnew file mode 100644index 0000000000..22250b2d54--- /dev/null+++ b/registry/blocks/vpn-youtube-spot/registry-item.json@@ -0,0 +1,28 @@+{+ "$schema": "https://hyperframes.heygen.com/schema/registry-item.json",+ "name": "vpn-youtube-spot",+ "type": "hyperframes:block",+ "title": "VPN YouTube Spot",+ "description": "Snappy Apple-style YouTube insert showing a phone finding and installing a friendly VPN app with sound effects.",+ "tags": ["app", "showcase", "youtube", "sfx"],+ "author": "Stronkter",+ "authorUrl": "https://x.com/Stronkter",+ "sourcePrompt": "HyperFrames by HeyGen make me a 7s video with Apple-style bold font and styling: a phone scrolling in an app store, clicking on a friendly VPN app called VPN, installing it, then snapping down and fading to a white background. Make it snappy and polished for a YouTube insert, with sound effects, 60fps, and 1920x1080.",+ "dimensions": {+ "width": 1920,+ "height": 1080+ },+ "duration": 7,+ "files": [+ {+ "path": "vpn-youtube-spot.html",+ "target": "compositions/vpn-youtube-spot.html",+ "type": "hyperframes:composition"+ },+ {+ "path": "assets/vpn-sfx.wav",+ "target": "assets/vpn-sfx.wav",+ "type": "hyperframes:asset"+ }+ ]+}diff --git a/registry/blocks/goonvpn-youtube-spot/goonvpn-youtube-spot.html b/registry/blocks/vpn-youtube-spot/vpn-youtube-spot.htmlsimilarity index 95%rename from registry/blocks/goonvpn-youtube-spot/goonvpn-youtube-spot.htmlrename to registry/blocks/vpn-youtube-spot/vpn-youtube-spot.htmlindex 9d83844374..ca0cdf5c81 100644--- a/registry/blocks/goonvpn-youtube-spot/goonvpn-youtube-spot.html+++ b/registry/blocks/vpn-youtube-spot/vpn-youtube-spot.html@@ -292,13 +292,13 @@background: linear-gradient(135deg, #34c759, #ffd60a);}- .icon-goon {+ .icon-vpn {background:radial-gradient(circle at 72% 16%, rgba(255, 255, 255, 0.62) 0 12%, transparent 13%),linear-gradient(145deg, #101828 0%, #007aff 64%, #34c759 100%);}- .icon-goon::before {+ .icon-vpn::before {content: "";position: absolute;left: 21px;@@ -310,7 +310,7 @@clip-path: polygon(50% 0, 88% 13%, 88% 46%, 50% 100%, 12% 46%, 12% 13%);}- .icon-goon::after {+ .icon-vpn::after {content: "";position: absolute;left: 31px;@@ -371,7 +371,7 @@background: #ececf1;}- #goon-row {+ #vpn-row {position: relative;transform-origin: center;outline: 0 solid rgba(0, 122, 255, 0);@@ -635,7 +635,7 @@<body><divid="root"- data-composition-id="goonvpn-youtube-spot"+ data-composition-id="vpn-youtube-spot"data-start="0"data-duration="7"data-width="1920"@@ -646,17 +646,17 @@data-start="0"data-duration="7"data-track-index="1"- src="assets/goonvpn-sfx.wav"+ src="assets/vpn-sfx.wav"data-volume="0.95"></audio><div class="stage"><div class="headline" id="stageHeadline">- <span>SECURE</span>- <span class="blue">INSTANTLY</span>- <div class="sub">One tap, installed, ready.</div>+ <span>PRIVATE</span>+ <span class="blue">SIMPLY</span>+ <div class="sub">A calmer way to browse.</div></div>- <div class="ambient-word">VPN</div>+ <div class="ambient-word">SAFE</div><div class="ambient-line line-a"></div><div class="ambient-line line-b"></div><div class="snap-shadow"></div>@@ -672,7 +672,7 @@</div><div class="search-pill"><div class="search-icon"></div>- <div>vpn apps</div>+ <div>privacy apps</div></div><div class="screen-window" data-layout-allow-overflow><div class="scroll-content">@@ -721,11 +721,11 @@</div><div class="get-button">GET</div></div>- <div class="store-row" id="goon-row">- <div class="app-icon icon-goon"></div>+ <div class="store-row" id="vpn-row">+ <div class="app-icon icon-vpn"></div><div class="row-copy">- <div class="row-title">goonVPN</div>- <div class="row-sub">Fast private browsing</div>+ <div class="row-title">VPN</div>+ <div class="row-sub">Simple private browsing</div><div class="stars">4.9 ★★★★★</div></div><div class="get-button">GET</div>@@ -756,10 +756,10 @@<section class="detail-view"><div class="detail-card"><div class="detail-hero">- <div class="app-icon icon-goon detail-icon"></div>+ <div class="app-icon icon-vpn detail-icon"></div><div>- <div class="detail-title">goonVPN</div>- <div class="detail-sub">Private, fast VPN for everyday browsing.</div>+ <div class="detail-title">VPN</div>+ <div class="detail-sub">Friendly privacy for everyday browsing.</div><div class="install-button"><span class="install-label">GET</span><svg class="ring" viewBox="0 0 28 28" aria-hidden="true">@@ -796,7 +796,7 @@</div><div class="shield-status"><div class="check">✓</div>- <div>Installed</div>+ <div>Ready to browse</div></div></div></section>@@ -878,7 +878,7 @@1.25,).to(- "#goon-row",+ "#vpn-row",{scale: 1.035,outlineWidth: 3,@@ -888,15 +888,15 @@},1.72,)- .to("#goon-row", { scale: 1, duration: 0.22 }, 1.93)+ .to("#vpn-row", { scale: 1, duration: 0.22 }, 1.93).fromTo(".tap-dot",{ scale: 0.25, opacity: 0.95 },{ scale: 2.15, opacity: 0, duration: 0.42, ease: "power2.out" },2.02,)- .to("#goon-row .get-button", { scale: 0.82, duration: 0.1, ease: "power3.in" }, 2.04)- .to("#goon-row .get-button", { scale: 1, duration: 0.14, ease: "back.out(2)" }, 2.14);+ .to("#vpn-row .get-button", { scale: 0.82, duration: 0.1, ease: "power3.in" }, 2.04)+ .to("#vpn-row .get-button", { scale: 1, duration: 0.14, ease: "back.out(2)" }, 2.14);tl.fromTo(".detail-view",@@ -981,7 +981,7 @@.to(".speed-lines", { opacity: 0, duration: 0.2 }, 5.74).to(".white-wipe", { opacity: 1, duration: 0.42, ease: "power2.out" }, 5.86);- window.__timelines["goonvpn-youtube-spot"] = tl;+ window.__timelines["vpn-youtube-spot"] = tl;</script></body></html>diff --git a/registry/registry.json b/registry/registry.jsonindex f7709c68ab..d17726725f 100644--- a/registry/registry.json+++ b/registry/registry.json@@ -100,7 +100,7 @@"type": "hyperframes:block"},{- "name": "goonvpn-youtube-spot",+ "name": "vpn-youtube-spot","type": "hyperframes:block"},{