33 lines
725 B
TypeScript
33 lines
725 B
TypeScript
export type QuickClipPosition = 'at' | 'before';
|
|
|
|
export function computeQuickClipRange(
|
|
currentTime: number,
|
|
duration: number,
|
|
position: QuickClipPosition,
|
|
clipDuration = 10,
|
|
): { start: number; end: number } | null {
|
|
if (duration === 0) return null;
|
|
|
|
let start: number;
|
|
let end: number;
|
|
|
|
switch (position) {
|
|
case 'at':
|
|
start = currentTime;
|
|
end = Math.min(currentTime + clipDuration, duration);
|
|
break;
|
|
case 'before':
|
|
start = Math.max(currentTime - clipDuration, 0);
|
|
end = currentTime;
|
|
break;
|
|
default: {
|
|
const _exhaustive: never = position;
|
|
void _exhaustive;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
if (start >= end) return null;
|
|
return { start, end };
|
|
}
|