Write HTML. Render video. Built for agents.
JavaScript aiai-agentsanimationclaude-codeffmpegframeworkgsaphtmlhtml-to-videomcpmotion-graphicspuppeteerrenderingtypescriptvideo-editor
fix(player,studio): resolve root timeline from DOM instead of last key (#247)
Miguel Ángelf40447f2e8d5
diff --git a/packages/player/package.json b/packages/player/package.jsonindex 0385d2fa81..0f586460a5 100644--- a/packages/player/package.json+++ b/packages/player/package.json@@ -1,6 +1,6 @@{"name": "@hyperframes/player",- "version": "0.2.5",+ "version": "0.2.6","description": "Embeddable web component for HyperFrames compositions","repository": {"type": "git",@@ -11,13 +11,13 @@"dist"],"type": "module",- "main": "./src/hyperframes-player.ts",- "types": "./src/hyperframes-player.ts",+ "main": "./dist/hyperframes-player.js",+ "types": "./dist/hyperframes-player.d.ts","exports": {".": {- "types": "./src/hyperframes-player.ts",+ "types": "./dist/hyperframes-player.d.ts","script": "./dist/hyperframes-player.global.js",- "import": "./src/hyperframes-player.ts",+ "import": "./dist/hyperframes-player.js","require": "./dist/hyperframes-player.cjs"}},diff --git a/packages/player/src/hyperframes-player.ts b/packages/player/src/hyperframes-player.tsindex 53b5e54961..192323486b 100644--- a/packages/player/src/hyperframes-player.ts+++ b/packages/player/src/hyperframes-player.ts@@ -314,7 +314,16 @@ class HyperframesPlayer extends HTMLElement {if (win.__timelines) {const keys = Object.keys(win.__timelines);if (keys.length > 0) {- const tl = win.__timelines[keys[keys.length - 1]];+ // Resolve the root composition id from the DOM — the outermost+ // `[data-composition-id]` element is the master. Bundled previews+ // register the root composition alongside sub-compositions, and+ // without this lookup Object.keys() order would make a+ // sub-composition's duration hijack the overall video length.+ const rootId = this.iframe.contentDocument+ ?.querySelector("[data-composition-id]")+ ?.getAttribute("data-composition-id");+ const key = rootId && rootId in win.__timelines ? rootId : keys[keys.length - 1];+ const tl = win.__timelines[key];return { getDuration: () => tl.duration() };}}diff --git a/packages/studio/src/player/hooks/useTimelinePlayer.ts b/packages/studio/src/player/hooks/useTimelinePlayer.tsindex a32f680818..63a1474f52 100644--- a/packages/studio/src/player/hooks/useTimelinePlayer.ts+++ b/packages/studio/src/player/hooks/useTimelinePlayer.ts@@ -238,7 +238,17 @@ export function useTimelinePlayer() {if (win.__timelines) {const keys = Object.keys(win.__timelines);- if (keys.length > 0) return wrapTimeline(win.__timelines[keys[keys.length - 1]]);+ if (keys.length > 0) {+ // Resolve the root composition id from the DOM — the outermost+ // `[data-composition-id]` element is the master. Without this,+ // Object.keys() order would let a sub-composition's timeline+ // hijack play/pause/seek and the duration readout.+ const rootId = iframe?.contentDocument+ ?.querySelector("[data-composition-id]")+ ?.getAttribute("data-composition-id");+ const key = rootId && rootId in win.__timelines ? rootId : keys[keys.length - 1];+ return wrapTimeline(win.__timelines[key]);+ }}return null;