MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / parseCompositions

Function parseCompositions

packages/cli/src/commands/compositions.ts:48–106  ·  view source on GitHub ↗
(html: string, baseDir: string)

Source from the content-addressed store, hash-verified

46}
47
48function parseCompositions(html: string, baseDir: string): CompositionInfo[] {
49 const parser = new DOMParser();
50 const doc = parser.parseFromString(html, "text/html");
51
52 const compositionDivs = doc.querySelectorAll("[data-composition-id]");
53 const compositions: CompositionInfo[] = [];
54
55 compositionDivs.forEach((div) => {
56 const id = div.getAttribute("data-composition-id") ?? "unknown";
57 const width = parseInt(div.getAttribute("data-width") ?? "1920", 10);
58 const height = parseInt(div.getAttribute("data-height") ?? "1080", 10);
59 const compositionSrc = div.getAttribute("data-composition-src");
60
61 // If this references an external sub-composition, parse that file
62 if (compositionSrc) {
63 const subPath = resolve(baseDir, compositionSrc);
64 if (existsSync(subPath)) {
65 const subHtml = readFileSync(subPath, "utf-8");
66 const subInfo = parseSubComposition(subHtml, id, width, height);
67 compositions.push({ ...subInfo, source: compositionSrc });
68 return;
69 }
70 }
71
72 const timedChildren = div.querySelectorAll("[data-start]");
73 let maxEnd = 0;
74 let elementCount = 0;
75
76 timedChildren.forEach((el) => {
77 elementCount++;
78 const start = parseFloat(el.getAttribute("data-start") ?? "0");
79 const endAttr = el.getAttribute("data-end");
80 const durationAttr = el.getAttribute("data-duration");
81
82 let end: number;
83 if (endAttr) {
84 end = parseFloat(endAttr);
85 } else if (durationAttr) {
86 end = start + parseFloat(durationAttr);
87 } else {
88 end = start + 5;
89 }
90
91 if (end > maxEnd) {
92 maxEnd = end;
93 }
94 });
95
96 compositions.push({
97 id,
98 duration: maxEnd,
99 width,
100 height,
101 elementCount,
102 });
103 });
104
105 return compositions;

Callers 1

runFunction · 0.85

Calls 3

resolveFunction · 0.85
parseSubCompositionFunction · 0.85
getAttributeMethod · 0.65

Tested by

no test coverage detected