mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-11 14:50:02 +00:00
fix(sdk): align template script traversal
This commit is contained in:
@@ -70,25 +70,36 @@ function buildAnimationIdMap(document: Document): Map<string, string[]> {
|
||||
const map = new Map<string, string[]>();
|
||||
for (const script of getGsapScripts(document)) {
|
||||
for (const { id, selector } of parseLocatedCached(script)) {
|
||||
if (!selector) continue;
|
||||
let matches: Element[] = [];
|
||||
try {
|
||||
matches = querySelectorAllDeep(document, selector);
|
||||
} catch {
|
||||
continue; // selector not valid for querySelectorAll — skip
|
||||
}
|
||||
for (const el of matches) {
|
||||
const hfId = el.getAttribute("data-hf-id");
|
||||
if (!hfId) continue;
|
||||
const list = map.get(hfId);
|
||||
if (list) list.push(id);
|
||||
else map.set(hfId, [id]);
|
||||
}
|
||||
appendAnimationIdsForSelector(map, document, id, selector);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
function appendAnimationIdsForSelector(
|
||||
map: Map<string, string[]>,
|
||||
document: Document,
|
||||
animationId: string,
|
||||
selector: string,
|
||||
): void {
|
||||
if (!selector) return;
|
||||
|
||||
let matches: Element[];
|
||||
try {
|
||||
matches = querySelectorAllDeep(document, selector);
|
||||
} catch {
|
||||
return; // selector not valid for querySelectorAll — skip
|
||||
}
|
||||
|
||||
for (const el of matches) {
|
||||
const hfId = el.getAttribute("data-hf-id");
|
||||
if (!hfId) continue;
|
||||
const list = map.get(hfId);
|
||||
if (list) list.push(animationId);
|
||||
else map.set(hfId, [animationId]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Every GSAP tween id `parseLocatedCached` finds in the script, with no DOM
|
||||
* matching at all — the same id space the server-side script ops
|
||||
|
||||
Reference in New Issue
Block a user