29 lines
651 B
TypeScript
29 lines
651 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;
|
||
|
|
|
||
|
|
switch (position) {
|
||
|
|
case 'at':
|
||
|
|
return {
|
||
|
|
start: currentTime,
|
||
|
|
end: Math.min(currentTime + clipDuration, duration),
|
||
|
|
};
|
||
|
|
case 'before':
|
||
|
|
return {
|
||
|
|
start: Math.max(currentTime - clipDuration, 0),
|
||
|
|
end: currentTime,
|
||
|
|
};
|
||
|
|
default: {
|
||
|
|
const _exhaustive: never = position;
|
||
|
|
void _exhaustive;
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|