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

Function handleSetCompositionMetadata

packages/sdk/src/engine/mutate.ts:750–800  ·  view source on GitHub ↗
(
  parsed: ParsedDocument,
  op: { width?: number; height?: number; duration?: number },
)

Source from the content-addressed store, hash-verified

748
749// fallow-ignore-next-line complexity
750function handleSetCompositionMetadata(
751 parsed: ParsedDocument,
752 op: { width?: number; height?: number; duration?: number },
753): MutationResult {
754 const result: MutationResult = { forward: [], inverse: [] };
755 const root = findRoot(parsed.document);
756 if (!root) return result;
757
758 // The runtime treats data-width/data-height as a FORCED override of inline
759 // style when present (core/runtime/init.ts applyCompositionSizing). So:
760 // style is always written; the data-* attribute is updated only when the
761 // composition already carries it — otherwise a style-only write would be
762 // clobbered on load. Absent attributes stay absent (keeps inverses exact).
763 if (op.width !== undefined) {
764 const styles = getElementStyles(root);
765 const oldAttr = root.getAttribute("data-width");
766 const oldWidth = oldAttr ?? styles["width"] ?? null;
767 const newVal = `${op.width}px`;
768 setElementStyles(root, { width: newVal });
769 if (oldAttr !== null) root.setAttribute("data-width", String(op.width));
770 const path = metaPath("width");
771 const p = scalarChange(path, oldWidth !== null ? parseFloat(oldWidth) : null, op.width);
772 result.forward.push(p.forward);
773 result.inverse.push(p.inverse);
774 }
775
776 if (op.height !== undefined) {
777 const styles = getElementStyles(root);
778 const oldAttr = root.getAttribute("data-height");
779 const oldHeight = oldAttr ?? styles["height"] ?? null;
780 const newVal = `${op.height}px`;
781 setElementStyles(root, { height: newVal });
782 if (oldAttr !== null) root.setAttribute("data-height", String(op.height));
783 const path = metaPath("height");
784 const p = scalarChange(path, oldHeight !== null ? parseFloat(oldHeight) : null, op.height);
785 result.forward.push(p.forward);
786 result.inverse.push(p.inverse);
787 }
788
789 if (op.duration !== undefined) {
790 const oldDur = root.getAttribute("data-duration");
791 const oldVal = oldDur !== null ? parseFloat(oldDur) : null;
792 root.setAttribute("data-duration", String(op.duration));
793 const path = metaPath("duration");
794 const p = scalarChange(path, oldVal, op.duration);
795 result.forward.push(p.forward);
796 result.inverse.push(p.inverse);
797 }
798
799 return result;
800}
801
802// ─── Variable JSON model helpers ─────────────────────────────────────────────
803// readVariableDefault / writeVariableDefault now live in ./variableModel.ts,

Callers 1

applyOpFunction · 0.85

Calls 7

findRootFunction · 0.85
getElementStylesFunction · 0.85
setElementStylesFunction · 0.85
metaPathFunction · 0.85
scalarChangeFunction · 0.85
getAttributeMethod · 0.65
setAttributeMethod · 0.65

Tested by

no test coverage detected