mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-07 10:06:21 +00:00
## Summary - Run `oxfmt .` across the entire codebase to establish formatted baseline - 299 files changed — mechanical formatting only, no logic changes - Double quotes, semicolons, 2-space indent, trailing commas, 100 print width Part 3/4 of [VA-851](https://linear.app/heygen/issue/VA-851/pre-migration-configure-eslint-prettier-and-conventional-commits) ## Test plan - [x] `pnpm format:check` — all 426 files pass - [x] `pnpm -r typecheck` — all packages pass - [x] `pnpm build` — all packages build - [x] All 348 tests pass
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import type { FrameAdapter } from "./types";
|
|
|
|
export interface GSAPTimelineLike {
|
|
// Base timeline span excluding repeats.
|
|
duration: () => number;
|
|
// Full span including repeats/yoyo when available.
|
|
totalDuration?: () => number;
|
|
seek: (timeInSeconds: number, suppressEvents?: boolean) => unknown;
|
|
pause?: () => unknown;
|
|
}
|
|
|
|
export interface CreateGSAPFrameAdapterOptions {
|
|
id?: string;
|
|
fps: number;
|
|
timeline: GSAPTimelineLike;
|
|
}
|
|
|
|
export function createGSAPFrameAdapter(options: CreateGSAPFrameAdapterOptions): FrameAdapter {
|
|
const { fps, timeline } = options;
|
|
const adapterId = options.id ?? "gsap";
|
|
|
|
const getDurationSeconds = (): number => {
|
|
const totalDuration =
|
|
typeof timeline.totalDuration === "function" ? timeline.totalDuration() : timeline.duration();
|
|
return Number.isFinite(totalDuration) && totalDuration > 0 ? totalDuration : 0;
|
|
};
|
|
|
|
return {
|
|
id: adapterId,
|
|
init: () => {
|
|
timeline.pause?.();
|
|
},
|
|
getDurationFrames: () => {
|
|
const durationSeconds = getDurationSeconds();
|
|
return Math.max(0, Math.ceil(durationSeconds * fps));
|
|
},
|
|
seekFrame: (frame: number) => {
|
|
const clampedFrame = Number.isFinite(frame) ? Math.max(0, frame) : 0;
|
|
const targetSeconds = clampedFrame / fps;
|
|
timeline.pause?.();
|
|
timeline.seek(targetSeconds, false);
|
|
},
|
|
};
|
|
}
|