summaryrefslogtreecommitdiff
path: root/apps/web/src/lib/timeline/placement/insert-index.ts
diff options
context:
space:
mode:
authorMaze Winther <mazewinther@gmail.com>2026-04-20 11:31:17 +0200
committerMaze Winther <mazewinther@gmail.com>2026-04-20 11:31:17 +0200
commit3e89d2998588f8e35c524e523ba2ee853f0f6475 (patch)
tree57221f96c1259b3b07e3ddf8c1adefc502b9d8eb /apps/web/src/lib/timeline/placement/insert-index.ts
parent729d10592f4e802f91c555c309ff3ba4b119f843 (diff)
downloadopencut-3e89d2998588f8e35c524e523ba2ee853f0f6475.tar.gz
refactor: restructure files to their domains, new preview overlay system, and dep graph
Diffstat (limited to 'apps/web/src/lib/timeline/placement/insert-index.ts')
-rw-r--r--apps/web/src/lib/timeline/placement/insert-index.ts88
1 files changed, 0 insertions, 88 deletions
diff --git a/apps/web/src/lib/timeline/placement/insert-index.ts b/apps/web/src/lib/timeline/placement/insert-index.ts
deleted file mode 100644
index 04fa5a4a..00000000
--- a/apps/web/src/lib/timeline/placement/insert-index.ts
+++ /dev/null
@@ -1,88 +0,0 @@
-import type { SceneTracks, TrackType } from "@/lib/timeline";
-
-export function getDefaultInsertIndexForTrack({
- tracks,
- trackType,
-}: {
- tracks: SceneTracks;
- trackType: TrackType;
-}): number {
- if (trackType === "audio") {
- return tracks.overlay.length + 1 + tracks.audio.length;
- }
-
- if (trackType === "effect") {
- return 0;
- }
-
- return tracks.overlay.length;
-}
-
-export function getHighestInsertIndexForTrack({
- tracks,
- trackType,
-}: {
- tracks: SceneTracks;
- trackType: TrackType;
-}): number {
- if (trackType === "audio") {
- return tracks.overlay.length + 1;
- }
-
- return 0;
-}
-
-export function resolvePreferredNewTrackPlacement({
- tracks,
- trackType,
- preferredIndex,
- direction,
-}: {
- tracks: SceneTracks;
- trackType: TrackType;
- preferredIndex: number;
- direction: "above" | "below";
-}): { insertIndex: number; insertPosition: "above" | "below" | null } {
- const trackCount = tracks.overlay.length + 1 + tracks.audio.length;
- if (trackCount === 0) {
- return {
- insertIndex: 0,
- insertPosition: trackType === "audio" ? "below" : null,
- };
- }
-
- const safePreferredIndex = Math.min(
- Math.max(preferredIndex, 0),
- trackCount - 1,
- );
- const mainTrackIndex = tracks.overlay.length;
-
- if (trackType === "audio") {
- if (safePreferredIndex <= mainTrackIndex) {
- return {
- insertIndex: mainTrackIndex + 1,
- insertPosition: "below",
- };
- }
-
- return {
- insertIndex:
- direction === "above" ? safePreferredIndex : safePreferredIndex + 1,
- insertPosition: direction,
- };
- }
-
- const insertIndex =
- direction === "above" ? safePreferredIndex : safePreferredIndex + 1;
- if (mainTrackIndex >= 0 && insertIndex > mainTrackIndex) {
- return {
- insertIndex: mainTrackIndex,
- insertPosition: "above",
- };
- }
-
- return {
- insertIndex,
- insertPosition: direction,
- };
-}