summaryrefslogtreecommitdiff
path: root/apps/web/src/types
diff options
context:
space:
mode:
authorMaze Winther <mazewinther@gmail.com>2025-07-06 22:51:11 +0200
committerMaze Winther <mazewinther@gmail.com>2025-07-06 22:51:11 +0200
commit6edd5b36cf7f09b8b146f57a880eb919c5fdad7f (patch)
treef41f166b71715010684b7e9769e557f6902aed02 /apps/web/src/types
parent40c7fbb4f86130c83fbd9029e83c5e7550e3219d (diff)
downloadopencut-6edd5b36cf7f09b8b146f57a880eb919c5fdad7f.tar.gz
feat: main track and ordering tracks
Diffstat (limited to 'apps/web/src/types')
-rw-r--r--apps/web/src/types/timeline.ts48
1 files changed, 47 insertions, 1 deletions
diff --git a/apps/web/src/types/timeline.ts b/apps/web/src/types/timeline.ts
index daada718..7079f091 100644
--- a/apps/web/src/types/timeline.ts
+++ b/apps/web/src/types/timeline.ts
@@ -1,5 +1,4 @@
import { MediaType } from "@/stores/media-store";
-import { TimelineTrack } from "@/stores/timeline-store";
export type TrackType = "media" | "text" | "audio";
@@ -77,3 +76,50 @@ export interface TextItemDragData {
}
export type DragData = MediaItemDragData | TextItemDragData;
+
+export interface TimelineTrack {
+ id: string;
+ name: string;
+ type: TrackType;
+ elements: TimelineElement[];
+ muted?: boolean;
+ isMain?: boolean;
+}
+
+export function sortTracksByOrder(tracks: TimelineTrack[]): TimelineTrack[] {
+ return [...tracks].sort((a, b) => {
+ // Audio tracks always go to bottom
+ if (a.type === "audio" && b.type !== "audio") return 1;
+ if (b.type === "audio" && a.type !== "audio") return -1;
+
+ // Main track goes above audio but below other tracks
+ if (a.isMain && !b.isMain && b.type !== "audio") return 1;
+ if (b.isMain && !a.isMain && a.type !== "audio") return -1;
+
+ // Within same category, maintain creation order
+ return 0;
+ });
+}
+
+export function getMainTrack(tracks: TimelineTrack[]): TimelineTrack | null {
+ return tracks.find((track) => track.isMain) || null;
+}
+
+export function ensureMainTrack(tracks: TimelineTrack[]): TimelineTrack[] {
+ const hasMainTrack = tracks.some((track) => track.isMain);
+
+ if (!hasMainTrack) {
+ // Create main track if it doesn't exist
+ const mainTrack: TimelineTrack = {
+ id: crypto.randomUUID(),
+ name: "Main Track",
+ type: "media",
+ elements: [],
+ muted: false,
+ isMain: true,
+ };
+ return [mainTrack, ...tracks];
+ }
+
+ return tracks;
+}