diff options
| author | Maze Winther <mazewinther@gmail.com> | 2026-04-22 14:36:51 +0200 |
|---|---|---|
| committer | Maze Winther <mazewinther@gmail.com> | 2026-04-22 14:36:51 +0200 |
| commit | f1b45b4328cff6a016720ce7b38b87ac2992dc2d (patch) | |
| tree | 16b816caa0ecf9f7ae680d7f440667ecd57b748d /apps/web/src/lib/commands/timeline/element/duplicate-elements.ts | |
| parent | 7428dc75cfef15481ad747806e81309a5a99e3a9 (diff) | |
| download | opencut-f1b45b4328cff6a016720ce7b38b87ac2992dc2d.tar.gz | |
chore: remove stale files
Diffstat (limited to 'apps/web/src/lib/commands/timeline/element/duplicate-elements.ts')
| -rw-r--r-- | apps/web/src/lib/commands/timeline/element/duplicate-elements.ts | 137 |
1 files changed, 0 insertions, 137 deletions
diff --git a/apps/web/src/lib/commands/timeline/element/duplicate-elements.ts b/apps/web/src/lib/commands/timeline/element/duplicate-elements.ts deleted file mode 100644 index c044a4e3..00000000 --- a/apps/web/src/lib/commands/timeline/element/duplicate-elements.ts +++ /dev/null @@ -1,137 +0,0 @@ -import { - Command, - createElementSelectionResult, - type CommandResult, -} from "@/lib/commands/base-command"; -import type { SceneTracks, TimelineElement } from "@/lib/timeline"; -import { generateUUID } from "@/utils/id"; -import { EditorCore } from "@/core"; -import { - applyPlacement, - resolveTrackPlacement, -} from "@/lib/timeline/placement"; -import { cloneAnimations } from "@/lib/animation"; - -interface DuplicateElementsParams { - elements: { trackId: string; elementId: string }[]; -} - -export class DuplicateElementsCommand extends Command { - private duplicatedElements: { trackId: string; elementId: string }[] = []; - private savedState: SceneTracks | null = null; - private elements: DuplicateElementsParams["elements"]; - - constructor({ elements }: DuplicateElementsParams) { - super(); - this.elements = elements; - } - - execute(): CommandResult | undefined { - const editor = EditorCore.getInstance(); - this.savedState = editor.scenes.getActiveScene().tracks; - this.duplicatedElements = []; - - let updatedTracks = this.savedState; - - for (const track of [ - ...this.savedState.overlay, - this.savedState.main, - ...this.savedState.audio, - ]) { - const elementsToDuplicate = this.elements.filter( - (elementEntry) => elementEntry.trackId === track.id, - ); - - if (elementsToDuplicate.length === 0) { - continue; - } - - const elementIdsToDuplicate = new Set( - elementsToDuplicate.map((element) => element.elementId), - ); - const newTrackElements: TimelineElement[] = []; - - for (const element of track.elements) { - if (!elementIdsToDuplicate.has(element.id)) { - continue; - } - - const newId = generateUUID(); - newTrackElements.push( - buildDuplicateElement({ - element, - id: newId, - startTime: element.startTime, - }), - ); - } - - const placementResult = resolveTrackPlacement({ - tracks: updatedTracks, - trackType: track.type, - timeSpans: [], - strategy: { type: "alwaysNew", position: "highest" }, - }); - if (!placementResult || placementResult.kind !== "newTrack") { - continue; - } - - const applied = applyPlacement({ - tracks: updatedTracks, - placementResult, - elements: newTrackElements, - }); - if (!applied) { - continue; - } - - updatedTracks = applied.updatedTracks; - - for (const element of newTrackElements) { - this.duplicatedElements.push({ - trackId: applied.targetTrackId, - elementId: element.id, - }); - } - } - - editor.timeline.updateTracks(updatedTracks); - - if (this.duplicatedElements.length > 0) { - return createElementSelectionResult(this.duplicatedElements); - } - return undefined; - } - - undo(): void { - if (this.savedState) { - const editor = EditorCore.getInstance(); - editor.timeline.updateTracks(this.savedState); - } - } - - getDuplicatedElements(): { trackId: string; elementId: string }[] { - return this.duplicatedElements; - } -} - -function buildDuplicateElement({ - element, - id, - startTime, -}: { - element: TimelineElement; - id: string; - startTime: number; -}): TimelineElement { - return { - ...element, - id, - name: `${element.name} (copy)`, - startTime, - animations: cloneAnimations({ - animations: element.animations, - shouldRegenerateKeyframeIds: true, - }), - }; -} |
