mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-03 04:38:33 +00:00
Merge pull request #792 from func25/fix/layer-range-seek
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolveTimelineSelectionSeekTime } from "./studioHelpers";
|
||||
|
||||
describe("resolveTimelineSelectionSeekTime", () => {
|
||||
it("keeps the current time when it is already inside the clip range", () => {
|
||||
expect(resolveTimelineSelectionSeekTime(3, { start: 0, duration: 5 })).toBe(3);
|
||||
});
|
||||
|
||||
it("clamps to the clip start when current time is before the clip", () => {
|
||||
expect(resolveTimelineSelectionSeekTime(1, { start: 4, duration: 3 })).toBe(4);
|
||||
});
|
||||
|
||||
it("clamps to the clip end when current time is after the clip", () => {
|
||||
expect(resolveTimelineSelectionSeekTime(10, { start: 4, duration: 3 })).toBe(7);
|
||||
});
|
||||
|
||||
it("falls back to the clip start for invalid current time", () => {
|
||||
expect(resolveTimelineSelectionSeekTime(Number.NaN, { start: 2, duration: 5 })).toBe(2);
|
||||
});
|
||||
});
|
||||
@@ -158,6 +158,20 @@ export function findMatchingTimelineElementId(
|
||||
return null;
|
||||
}
|
||||
|
||||
export function resolveTimelineSelectionSeekTime(
|
||||
currentTime: number,
|
||||
element: Pick<TimelineElement, "start" | "duration"> | null | undefined,
|
||||
): number | null {
|
||||
if (!element) return null;
|
||||
if (!Number.isFinite(element.start) || !Number.isFinite(element.duration)) return null;
|
||||
|
||||
const start = Math.max(0, element.start);
|
||||
const end = Math.max(start, start + Math.max(0, element.duration));
|
||||
const time = Number.isFinite(currentTime) ? currentTime : start;
|
||||
|
||||
return clampNumber(time, start, end);
|
||||
}
|
||||
|
||||
export function clampNumber(value: number, min: number, max: number): number {
|
||||
if (max < min) return min;
|
||||
return Math.min(Math.max(value, min), max);
|
||||
|
||||
Reference in New Issue
Block a user