mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-03 04:38:33 +00:00
feat(core): declarative variable bindings — data-var-src, data-var-text, css custom props
This commit is contained in:
@@ -264,6 +264,18 @@ class CompositionImpl implements Composition {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Declarative bindings (data-var-src / data-var-text) are direct reads.
|
||||
for (const el of Array.from(
|
||||
this.parsed.document.querySelectorAll("[data-var-src], [data-var-text]"),
|
||||
)) {
|
||||
for (const attr of ["data-var-src", "data-var-text"]) {
|
||||
const id = el.getAttribute(attr)?.trim();
|
||||
if (id && !seen.has(id)) {
|
||||
seen.add(id);
|
||||
usedIds.push(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
this._variableUsageScanCache = freshCache;
|
||||
const declaredIds = this.getVariableDeclarations().map((d) => d.id);
|
||||
// The CSS compat channel counts as usage: a variable consumed only via
|
||||
|
||||
@@ -82,6 +82,22 @@ describe("getVariableUsage", () => {
|
||||
expect(usage.unusedDeclarations).toContain("accent");
|
||||
});
|
||||
|
||||
it("counts declarative data-var-src / data-var-text bindings as usage", async () => {
|
||||
const comp = await openComposition(`<!DOCTYPE html>
|
||||
<html data-composition-variables='${DECLS}'>
|
||||
<body>
|
||||
<div data-hf-id="hf-stage" data-hf-root data-duration="5">
|
||||
<img data-hf-id="hf-img" data-var-src="accent" src="x.jpg" />
|
||||
<h1 data-hf-id="hf-h" data-var-text="title">t</h1>
|
||||
</div>
|
||||
</body>
|
||||
</html>`);
|
||||
const usage = comp.getVariableUsage();
|
||||
expect(usage.usedIds).toEqual(expect.arrayContaining(["accent", "title"]));
|
||||
expect(usage.unusedDeclarations).toEqual(["orphan"]);
|
||||
expect(usage.scanIncomplete).toBe(false);
|
||||
});
|
||||
|
||||
it("handles compositions with no declarations and no scripts", async () => {
|
||||
const comp = await openComposition(
|
||||
`<!DOCTYPE html><html><body><div data-hf-id="hf-stage" data-hf-root data-duration="5"><p data-hf-id="hf-p">x</p></div></body></html>`,
|
||||
|
||||
Reference in New Issue
Block a user