mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-10 22:20:14 +00:00
feat(studio): route GSAP keyframe add through SDK (§3.5 PR2) (#1470)
Co-authored-by: Miguel Ángel <miguel07alm@protonmail.com>
This commit is contained in:
co-authored by
Miguel Ángel
parent
592f7c775d
commit
7ca4490328
@@ -269,6 +269,14 @@ describe("T6c — keyframe write ops", () => {
|
||||
expect((result.match(/"50%"/g) ?? []).length).toBe(1);
|
||||
});
|
||||
|
||||
it("addKeyframeToScript merges a new property into an existing keyframe, preserving siblings", () => {
|
||||
// 50% already holds { opacity: 0.7 }; adding x must NOT drop opacity.
|
||||
const result = addKeyframeToScript(SCRIPT_D, "#box-to-200-visual", 50, { x: 100 });
|
||||
expect(result).toContain("opacity: 0.7");
|
||||
expect(result).toContain("x: 100");
|
||||
expect((result.match(/"50%"/g) ?? []).length).toBe(1);
|
||||
});
|
||||
|
||||
it("removeKeyframeFromScript removes the target percentage", () => {
|
||||
// Remove 50% from 0%/50%/100% → leaves 0%/100% (no collapse in T6c)
|
||||
const result = removeKeyframeFromScript(SCRIPT_D, "#box-to-200-visual", 50);
|
||||
|
||||
@@ -774,7 +774,17 @@ export function addKeyframeToScript(
|
||||
// Emit exactly one overwrite per changed node, plus one insert for a new key.
|
||||
const ms = new MagicString(src);
|
||||
if (existing) {
|
||||
ms.overwrite(existing.prop.value.start, existing.prop.value.end, recordToCode(targetRecord));
|
||||
// Merge into the existing keyframe at this percentage, preserving sibling
|
||||
// properties — overwrite only the given keys. (A whole-value overwrite here
|
||||
// would silently drop other properties already keyframed at this percent.)
|
||||
if (existing.prop.value?.type === "ObjectExpression") {
|
||||
for (const [k, v] of Object.entries(properties)) {
|
||||
upsertProp(ms, existing.prop.value, k, v);
|
||||
}
|
||||
if (ease !== undefined) upsertProp(ms, existing.prop.value, "ease", ease);
|
||||
} else {
|
||||
ms.overwrite(existing.prop.value.start, existing.prop.value.end, recordToCode(targetRecord));
|
||||
}
|
||||
} else {
|
||||
insertNewKeyframe(ms, kfNode, percentage, `${percentage}%`, recordToCode(targetRecord));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user