mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-04 07:19:52 +00:00
* fix(producer): suppress GSAP call side effects during render seeks * fix(core): preserve GSAP root render nudge safely
33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
import type { RuntimeDeterministicAdapter, RuntimeTimelineLike } from "../types";
|
|
|
|
type GsapAdapterDeps = {
|
|
getTimeline: () => RuntimeTimelineLike | null;
|
|
};
|
|
|
|
export function createGsapAdapter(deps: GsapAdapterDeps): RuntimeDeterministicAdapter {
|
|
return {
|
|
name: "gsap",
|
|
discover: () => {},
|
|
seek: (ctx) => {
|
|
const timeline = deps.getTimeline();
|
|
if (!timeline) return;
|
|
timeline.pause();
|
|
const safeTime = Math.max(0, Number(ctx.time) || 0);
|
|
const suppressEvents = ctx.suppressEvents === true;
|
|
if (typeof timeline.totalTime === "function") {
|
|
// GSAP 3.x skips rendering when the new totalTime equals _tTime.
|
|
// Nudge first to force a dirty state, then seek to the exact time.
|
|
timeline.totalTime(safeTime + 0.001, true);
|
|
timeline.totalTime(safeTime, suppressEvents);
|
|
} else {
|
|
timeline.seek(safeTime, suppressEvents);
|
|
}
|
|
},
|
|
pause: () => {
|
|
const timeline = deps.getTimeline();
|
|
if (!timeline) return;
|
|
timeline.pause();
|
|
},
|
|
};
|
|
}
|