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

Function handleRemoveElement

packages/sdk/src/engine/mutate.ts:593–631  ·  view source on GitHub ↗
(parsed: ParsedDocument, ids: HfId[])

Source from the content-addressed store, hash-verified

591}
592
593function handleRemoveElement(parsed: ParsedDocument, ids: HfId[]): MutationResult {
594 const result: MutationResult = { forward: [], inverse: [] };
595 const origScript = getGsapScript(parsed.document);
596 let currentScript = origScript;
597
598 for (const id of ids) {
599 const el = resolveScoped(parsed.document, id);
600 if (!el) continue;
601 const parentEl = el.parentElement;
602 const parentId = parentEl?.getAttribute("data-hf-id") ?? null;
603 const siblingIndex = getSiblingIndex(el);
604 const html = el.outerHTML;
605
606 // Collect all bare hf-ids in the subtree BEFORE removal so GSAP cascade
607 // removes animations targeting any sub-composition element, not just the host.
608 const subtreeIds = collectSubtreeHfIds(el);
609
610 el.remove();
611
612 const path = elementPath(id);
613 result.forward.push(patchRemove(path));
614 result.inverse.push(patchAdd(path, { html, parentId, siblingIndex }));
615
616 if (currentScript) {
617 for (const subtreeId of subtreeIds) {
618 currentScript = cascadeRemoveAnimations(currentScript, subtreeId);
619 }
620 }
621 }
622
623 if (origScript && currentScript && currentScript !== origScript) {
624 setGsapScript(parsed.document, currentScript);
625 const gsapResult = gsapScriptChange(origScript, currentScript);
626 result.forward.push(...gsapResult.forward);
627 result.inverse.push(...gsapResult.inverse);
628 }
629
630 return result;
631}
632
633// ─── addElement handler ───────────────────────────────────────────────────────
634

Callers 1

applyOpFunction · 0.85

Calls 11

getGsapScriptFunction · 0.85
resolveScopedFunction · 0.85
getSiblingIndexFunction · 0.85
collectSubtreeHfIdsFunction · 0.85
elementPathFunction · 0.85
patchRemoveFunction · 0.85
patchAddFunction · 0.85
cascadeRemoveAnimationsFunction · 0.85
setGsapScriptFunction · 0.85
gsapScriptChangeFunction · 0.85
getAttributeMethod · 0.65

Tested by

no test coverage detected