mirror of
https://github.com/OpenCut-app/OpenCut.git
synced 2026-07-13 21:52:53 +02:00
Add keyframe support for transform, opacity, and volume properties. Includes animation engine (interpolation, mutations, resolvers), timeline markers with selection/snapping, properties panel toggles, keyframe-aware renderer, and full undo/redo command support. Also refactor element command constructors to object params, extract timeline pixel math to pixel-utils.ts, and update cursor rules.
73 lines
1.7 KiB
TypeScript
73 lines
1.7 KiB
TypeScript
import type { EditorCore } from "@/core";
|
|
import type { SelectedKeyframeRef } from "@/types/animation";
|
|
|
|
type ElementRef = { trackId: string; elementId: string };
|
|
|
|
export class SelectionManager {
|
|
private selectedElements: ElementRef[] = [];
|
|
private selectedKeyframes: SelectedKeyframeRef[] = [];
|
|
private keyframeSelectionAnchor: SelectedKeyframeRef | null = null;
|
|
private listeners = new Set<() => void>();
|
|
|
|
constructor(editor: EditorCore) {
|
|
void editor;
|
|
}
|
|
|
|
getSelectedElements(): ElementRef[] {
|
|
return this.selectedElements;
|
|
}
|
|
|
|
getSelectedKeyframes(): SelectedKeyframeRef[] {
|
|
return this.selectedKeyframes;
|
|
}
|
|
|
|
getKeyframeSelectionAnchor(): SelectedKeyframeRef | null {
|
|
return this.keyframeSelectionAnchor;
|
|
}
|
|
|
|
setSelectedElements({ elements }: { elements: ElementRef[] }): void {
|
|
this.selectedElements = elements;
|
|
this.selectedKeyframes = [];
|
|
this.keyframeSelectionAnchor = null;
|
|
this.notify();
|
|
}
|
|
|
|
setSelectedKeyframes({
|
|
keyframes,
|
|
anchorKeyframe,
|
|
}: {
|
|
keyframes: SelectedKeyframeRef[];
|
|
anchorKeyframe?: SelectedKeyframeRef | null;
|
|
}): void {
|
|
this.selectedKeyframes = keyframes;
|
|
if (anchorKeyframe !== undefined) {
|
|
this.keyframeSelectionAnchor = anchorKeyframe;
|
|
} else if (keyframes.length === 0) {
|
|
this.keyframeSelectionAnchor = null;
|
|
}
|
|
this.notify();
|
|
}
|
|
|
|
clearSelection(): void {
|
|
this.selectedElements = [];
|
|
this.selectedKeyframes = [];
|
|
this.keyframeSelectionAnchor = null;
|
|
this.notify();
|
|
}
|
|
|
|
clearKeyframeSelection(): void {
|
|
this.selectedKeyframes = [];
|
|
this.keyframeSelectionAnchor = null;
|
|
this.notify();
|
|
}
|
|
|
|
subscribe(listener: () => void): () => void {
|
|
this.listeners.add(listener);
|
|
return () => this.listeners.delete(listener);
|
|
}
|
|
|
|
private notify(): void {
|
|
this.listeners.forEach((fn) => fn());
|
|
}
|
|
}
|