1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
import type { TrackType } from "@/lib/timeline";
import {
KEYFRAME_LANE_HEIGHT_PX,
TIMELINE_TRACK_GAP_PX,
TIMELINE_TRACK_HEIGHTS_PX,
} from "./layout";
export function getTrackHeight({ type }: { type: TrackType }): number {
return TIMELINE_TRACK_HEIGHTS_PX[type];
}
export function getExpandedTrackHeight({
type,
expandedLaneCount,
}: {
type: TrackType;
expandedLaneCount: number;
}): number {
return (
TIMELINE_TRACK_HEIGHTS_PX[type] +
expandedLaneCount * KEYFRAME_LANE_HEIGHT_PX
);
}
export function getCumulativeHeightBefore({
tracks,
trackIndex,
getExtraHeight,
}: {
tracks: Array<{ type: TrackType }>;
trackIndex: number;
getExtraHeight?: (trackIndex: number) => number;
}): number {
return tracks
.slice(0, trackIndex)
.reduce(
(sum, track, i) =>
sum +
getTrackHeight({ type: track.type }) +
(getExtraHeight?.(i) ?? 0) +
TIMELINE_TRACK_GAP_PX,
0,
);
}
export function getTotalTracksHeight({
tracks,
getExtraHeight,
}: {
tracks: Array<{ type: TrackType }>;
getExtraHeight?: (trackIndex: number) => number;
}): number {
const tracksHeight = tracks.reduce(
(sum, track, i) =>
sum + getTrackHeight({ type: track.type }) + (getExtraHeight?.(i) ?? 0),
0,
);
const gapsHeight = Math.max(0, tracks.length - 1) * TIMELINE_TRACK_GAP_PX;
return tracksHeight + gapsHeight;
}
|