summaryrefslogtreecommitdiff
path: root/apps/web/src/components/editor/panels/properties/hooks/use-element-playhead.ts
blob: 967156b30826a7142655ff56899fbe89c7cbc51d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { useEditor } from "@/editor/use-editor";
import { getElementLocalTime } from "@/animation";

export function useElementPlayhead({
	startTime,
	duration,
}: {
	startTime: number;
	duration: number;
}) {
	const playheadTime = useEditor((editor) => editor.playback.getCurrentTime());
	const localTime = getElementLocalTime({
		timelineTime: playheadTime,
		elementStartTime: startTime,
		elementDuration: duration,
	});
	const isPlayheadWithinElementRange =
		playheadTime >= startTime &&
		playheadTime <= startTime + duration;

	return { localTime, isPlayheadWithinElementRange };
}