summaryrefslogtreecommitdiff
path: root/apps/web/src/constants/timeline-constants.ts
diff options
context:
space:
mode:
authorMaze Winther <mazewinther@gmail.com>2025-07-10 20:35:15 +0200
committerMaze Winther <mazewinther@gmail.com>2025-07-10 20:35:15 +0200
commit055a6af0551302ebfd482183eb3d682baaf9ebdd (patch)
tree3bbc0fb593a6343c40df854ee10523aedc7ea5a0 /apps/web/src/constants/timeline-constants.ts
parent1376bee16db8933cc65b803fb53306b5c561d808 (diff)
downloadopencut-055a6af0551302ebfd482183eb3d682baaf9ebdd.tar.gz
refactor: move constants to src/constants
Diffstat (limited to 'apps/web/src/constants/timeline-constants.ts')
-rw-r--r--apps/web/src/constants/timeline-constants.ts78
1 files changed, 78 insertions, 0 deletions
diff --git a/apps/web/src/constants/timeline-constants.ts b/apps/web/src/constants/timeline-constants.ts
new file mode 100644
index 00000000..26cd865c
--- /dev/null
+++ b/apps/web/src/constants/timeline-constants.ts
@@ -0,0 +1,78 @@
+import type { TrackType } from "@/types/timeline";
+
+// Track color definitions
+export const TRACK_COLORS: Record<
+ TrackType,
+ { solid: string; background: string; border: string }
+> = {
+ media: {
+ solid: "bg-blue-500",
+ background: "bg-blue-500/20",
+ border: "border-white/80",
+ },
+ text: {
+ solid: "bg-[#9C4937]",
+ background: "bg-[#9C4937]",
+ border: "border-white/80",
+ },
+ audio: {
+ solid: "bg-green-500",
+ background: "bg-green-500/20",
+ border: "border-white/80",
+ },
+} as const;
+
+// Utility functions
+export function getTrackColors(type: TrackType) {
+ return TRACK_COLORS[type];
+}
+
+export function getTrackElementClasses(type: TrackType) {
+ const colors = getTrackColors(type);
+ return `${colors.background} ${colors.border}`;
+}
+
+// Track height definitions
+export const TRACK_HEIGHTS: Record<TrackType, number> = {
+ media: 65,
+ text: 25,
+ audio: 50,
+} as const;
+
+// Utility function for track heights
+export function getTrackHeight(type: TrackType): number {
+ return TRACK_HEIGHTS[type];
+}
+
+// Calculate cumulative height up to (but not including) a track index
+export function getCumulativeHeightBefore(
+ tracks: Array<{ type: TrackType }>,
+ trackIndex: number
+): number {
+ const GAP = 4; // 4px gap between tracks (equivalent to Tailwind's gap-1)
+ return tracks
+ .slice(0, trackIndex)
+ .reduce((sum, track) => sum + getTrackHeight(track.type) + GAP, 0);
+}
+
+// Calculate total height of all tracks
+export function getTotalTracksHeight(
+ tracks: Array<{ type: TrackType }>
+): number {
+ const GAP = 4; // 4px gap between tracks (equivalent to Tailwind's gap-1)
+ const tracksHeight = tracks.reduce(
+ (sum, track) => sum + getTrackHeight(track.type),
+ 0
+ );
+ const gapsHeight = Math.max(0, tracks.length - 1) * GAP; // n-1 gaps for n tracks
+ return tracksHeight + gapsHeight;
+}
+
+// Other timeline constants
+export const TIMELINE_CONSTANTS = {
+ ELEMENT_MIN_WIDTH: 80,
+ PIXELS_PER_SECOND: 50,
+ TRACK_HEIGHT: 60, // Default fallback
+ DEFAULT_TEXT_DURATION: 5,
+ ZOOM_LEVELS: [0.25, 0.5, 1, 1.5, 2, 3, 4],
+} as const;