mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-15 22:08:03 +00:00
fix(studio): address review follow-ups
This commit is contained in:
@@ -59,12 +59,18 @@ export function extractBlocks(source: string, pattern: RegExp): ExtractedBlock[]
|
||||
}
|
||||
|
||||
export function findRootTag(source: string): OpenTag | null {
|
||||
const bodyMatch = source.match(/<body\b[^>]*>([\s\S]*?)<\/body>/i);
|
||||
const bodyContent = bodyMatch ? (bodyMatch[1] ?? source) : source;
|
||||
const bodyOpenMatch = /<body\b[^>]*>/i.exec(source);
|
||||
const bodyCloseMatch = /<\/body>/i.exec(source);
|
||||
const bodyStart = bodyOpenMatch ? bodyOpenMatch.index + bodyOpenMatch[0].length : 0;
|
||||
const bodyEnd =
|
||||
bodyOpenMatch && bodyCloseMatch && bodyCloseMatch.index > bodyStart
|
||||
? bodyCloseMatch.index
|
||||
: source.length;
|
||||
const bodyContent = bodyOpenMatch ? source.slice(bodyStart, bodyEnd) : source;
|
||||
const bodyTags = extractOpenTags(bodyContent);
|
||||
for (const tag of bodyTags) {
|
||||
if (["script", "style", "meta", "link", "title"].includes(tag.name)) continue;
|
||||
return tag;
|
||||
return { ...tag, index: tag.index + bodyStart };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -195,6 +195,35 @@ describe("anonymous timeline identity", () => {
|
||||
expect(new Set(elements.map((element) => element.key)).size).toBe(2);
|
||||
expect(elements.map((element) => element.selectorIndex)).toEqual([0, 1]);
|
||||
});
|
||||
|
||||
it("reads media metadata from owner-window media elements", () => {
|
||||
const doc = createDocument(`
|
||||
<div data-composition-id="main" data-start="0" data-duration="8">
|
||||
<div class="clip video-card" data-start="0" data-duration="3" data-track-index="0">
|
||||
<video src="/clip.mp4" data-source-duration="12"></video>
|
||||
</div>
|
||||
</div>
|
||||
`);
|
||||
const hostEl = doc.querySelector(".video-card");
|
||||
const video = hostEl?.querySelector("video");
|
||||
if (!hostEl || !video) throw new Error("missing video test fixture");
|
||||
Object.defineProperty(video, "defaultPlaybackRate", {
|
||||
value: 1.5,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
const element = createTimelineElementFromManifestClip({
|
||||
clip: createClip({ kind: "video", tagName: "div" }),
|
||||
fallbackIndex: 0,
|
||||
doc,
|
||||
hostEl,
|
||||
});
|
||||
|
||||
expect(element.tag).toBe("video");
|
||||
expect(element.src).toBe("/clip.mp4");
|
||||
expect(element.sourceDuration).toBe(12);
|
||||
expect(element.playbackRate).toBe(1.5);
|
||||
});
|
||||
});
|
||||
|
||||
describe("mergeTimelineElementsPreservingDowngrades", () => {
|
||||
|
||||
@@ -95,7 +95,9 @@ function applyMediaMetadataFromElement(entry: TimelineElement, el: Element): voi
|
||||
const src = mediaEl.getAttribute("src");
|
||||
if (src) entry.src = src;
|
||||
|
||||
if (!(mediaEl instanceof HTMLMediaElement)) return;
|
||||
const win = mediaEl.ownerDocument.defaultView ?? window;
|
||||
const MediaElementCtor = win.HTMLMediaElement ?? globalThis.HTMLMediaElement;
|
||||
if (typeof MediaElementCtor === "undefined" || !(mediaEl instanceof MediaElementCtor)) return;
|
||||
|
||||
const sourceDurationAttr =
|
||||
el.getAttribute("data-source-duration") ?? mediaEl.getAttribute("data-source-duration");
|
||||
|
||||
Reference in New Issue
Block a user