summaryrefslogtreecommitdiff
path: root/apps/web/src/timeline/placement/track-factory.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/web/src/timeline/placement/track-factory.ts')
-rw-r--r--apps/web/src/timeline/placement/track-factory.ts123
1 files changed, 123 insertions, 0 deletions
diff --git a/apps/web/src/timeline/placement/track-factory.ts b/apps/web/src/timeline/placement/track-factory.ts
new file mode 100644
index 00000000..9c69ea8c
--- /dev/null
+++ b/apps/web/src/timeline/placement/track-factory.ts
@@ -0,0 +1,123 @@
+import { DEFAULT_TRACK_NAMES } from "@/timeline/tracks";
+import type {
+ AudioTrack,
+ EffectTrack,
+ GraphicTrack,
+ TextTrack,
+ TrackType,
+ TimelineTrack,
+ VideoTrack,
+} from "@/timeline";
+
+export function buildEmptyTrack({
+ id,
+ type,
+ name,
+}: {
+ id: string;
+ type: "video";
+ name?: string;
+}): VideoTrack;
+export function buildEmptyTrack({
+ id,
+ type,
+ name,
+}: {
+ id: string;
+ type: "text";
+ name?: string;
+}): TextTrack;
+export function buildEmptyTrack({
+ id,
+ type,
+ name,
+}: {
+ id: string;
+ type: "audio";
+ name?: string;
+}): AudioTrack;
+export function buildEmptyTrack({
+ id,
+ type,
+ name,
+}: {
+ id: string;
+ type: "graphic";
+ name?: string;
+}): GraphicTrack;
+export function buildEmptyTrack({
+ id,
+ type,
+ name,
+}: {
+ id: string;
+ type: "effect";
+ name?: string;
+}): EffectTrack;
+
+export function buildEmptyTrack({
+ id,
+ type,
+ name,
+}: {
+ id: string;
+ type: TrackType;
+ name?: string;
+}): TimelineTrack;
+export function buildEmptyTrack({
+ id,
+ type,
+ name,
+}: {
+ id: string;
+ type: TrackType;
+ name?: string;
+}): TimelineTrack {
+ const trackName = name ?? DEFAULT_TRACK_NAMES[type];
+
+ switch (type) {
+ case "video":
+ return {
+ id,
+ name: trackName,
+ type: "video",
+ elements: [],
+ hidden: false,
+ muted: false,
+ };
+ case "text":
+ return {
+ id,
+ name: trackName,
+ type: "text",
+ elements: [],
+ hidden: false,
+ };
+ case "graphic":
+ return {
+ id,
+ name: trackName,
+ type: "graphic",
+ elements: [],
+ hidden: false,
+ };
+ case "audio":
+ return {
+ id,
+ name: trackName,
+ type: "audio",
+ elements: [],
+ muted: false,
+ };
+ case "effect":
+ return {
+ id,
+ name: trackName,
+ type: "effect",
+ elements: [],
+ hidden: false,
+ };
+ default:
+ throw new Error(`Unsupported track type: ${type}`);
+ }
+}