summaryrefslogtreecommitdiff
path: root/apps/web/src/timeline/drag-utils.ts
blob: ad8d8001e31679d00ed827b5819677028421620a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { BASE_TIMELINE_PIXELS_PER_SECOND } from "@/timeline/scale";
import { mediaTime, type MediaTime, TICKS_PER_SECOND } from "@/wasm";

export function getMouseTimeFromClientX({
	clientX,
	containerRect,
	zoomLevel,
	scrollLeft,
}: {
	clientX: number;
	containerRect: DOMRect;
	zoomLevel: number;
	scrollLeft: number;
}): MediaTime {
	const mouseX = clientX - containerRect.left + scrollLeft;
	const seconds = Math.max(
		0,
		mouseX / (BASE_TIMELINE_PIXELS_PER_SECOND * zoomLevel),
	);
	return mediaTime({
		ticks: Math.round(seconds * TICKS_PER_SECOND),
	});
}