Skip to content

OpenReel Video - Professional browser-based video editor. Open source CapCut alternative. 100% browser-based, no installation, no cloud uploads, no watermarks.

TypeScript

fix: address 6 user-reported editor issues

Augustus Otu08066c2eef5d
diff --git a/apps/web/src/components/editor/AssetsPanel.tsx b/apps/web/src/components/editor/AssetsPanel.tsx
index 29352d57..409c6619 100644
--- a/apps/web/src/components/editor/AssetsPanel.tsx
+++ b/apps/web/src/components/editor/AssetsPanel.tsx
@@ -499,7 +499,11 @@ export const AssetsPanel: React.FC = () => {
const file = new File([blob], `${preset.name}_${width}x${height}.png`, {
type: "image/png",
});
- await importMedia(file);
+ const result = await importMedia(file);
+ if (result.success && result.actionId) {
+ const { addClipToNewTrack } = useProjectStore.getState();
+ await addClipToNewTrack(result.actionId);
+ }
} catch (error) {
console.error("Failed to generate background:", error);
} finally {
diff --git a/apps/web/src/components/editor/InspectorPanel.tsx b/apps/web/src/components/editor/InspectorPanel.tsx
index 4d0a4e90..c4f9a284 100644
--- a/apps/web/src/components/editor/InspectorPanel.tsx
+++ b/apps/web/src/components/editor/InspectorPanel.tsx
@@ -45,6 +45,7 @@ import {
MotionPathSection,
ParticleEffectsSection,
AudioTextSyncPanel,
+ AlignmentSection,
} from "./inspector";
import {
getAudioBridgeEffects,
@@ -857,6 +858,22 @@ export const InspectorPanel: React.FC = () => {
</Section>
)}
+ {/* Alignment - Position element on canvas */}
+ {(clipType === "video" ||
+ clipType === "image" ||
+ clipType === "text" ||
+ clipType === "shape" ||
+ clipType === "svg" ||
+ clipType === "sticker") && (
+ <Section
+ title="Alignment"
+ sectionId="alignment"
+ defaultOpen={false}
+ >
+ <AlignmentSection clipId={clipId} />
+ </Section>
+ )}
+
{/* Blending - Layer compositing blend modes */}
{(clipType === "video" ||
clipType === "image" ||
diff --git a/apps/web/src/components/editor/Preview.tsx b/apps/web/src/components/editor/Preview.tsx
index 328aa5b0..9e50c29b 100644
--- a/apps/web/src/components/editor/Preview.tsx
+++ b/apps/web/src/components/editor/Preview.tsx
@@ -4859,6 +4859,21 @@ export const Preview: React.FC = () => {
<Move size={14} className="text-white" />
</div>
+ {/* Aspect ratio lock toggle */}
+ <button
+ className={`absolute -top-8 left-1/2 -translate-x-1/2 px-2 py-1 text-[10px] rounded pointer-events-auto transition-colors ${
+ lockAspectRatio
+ ? "bg-cyan-500 text-white"
+ : "bg-background-tertiary text-text-secondary border border-border hover:bg-background-elevated"
+ }`}
+ onClick={() => setLockAspectRatio(!lockAspectRatio)}
+ title={
+ lockAspectRatio ? "Unlock aspect ratio" : "Lock aspect ratio"
+ }
+ >
+ {lockAspectRatio ? "πŸ”’ Locked" : "πŸ”“ Free"}
+ </button>
+
{/* Corner resize handles */}
<div
className="absolute -left-2 -top-2 w-4 h-4 bg-white border-2 border-cyan-500 rounded-sm cursor-nw-resize pointer-events-auto hover:bg-cyan-500 hover:border-white transition-colors"
@@ -4920,6 +4935,21 @@ export const Preview: React.FC = () => {
<Move size={14} className="text-white" />
</div>
+ {/* Aspect ratio lock toggle */}
+ <button
+ className={`absolute -top-8 left-1/2 -translate-x-1/2 px-2 py-1 text-[10px] rounded pointer-events-auto transition-colors ${
+ lockAspectRatio
+ ? "bg-green-500 text-white"
+ : "bg-background-tertiary text-text-secondary border border-border hover:bg-background-elevated"
+ }`}
+ onClick={() => setLockAspectRatio(!lockAspectRatio)}
+ title={
+ lockAspectRatio ? "Unlock aspect ratio" : "Lock aspect ratio"
+ }
+ >
+ {lockAspectRatio ? "πŸ”’ Locked" : "πŸ”“ Free"}
+ </button>
+
{/* Corner resize handles */}
<div
className="absolute -left-2 -top-2 w-4 h-4 bg-white border-2 border-green-500 rounded-sm cursor-nw-resize pointer-events-auto hover:bg-green-500 hover:border-white transition-colors"
diff --git a/apps/web/src/components/editor/Timeline.tsx b/apps/web/src/components/editor/Timeline.tsx
index fc0d0a30..d2f587c7 100644
--- a/apps/web/src/components/editor/Timeline.tsx
+++ b/apps/web/src/components/editor/Timeline.tsx
@@ -21,6 +21,7 @@ import {
Trash2,
Plus,
ChevronDown as ChevronDownIcon,
+ Magnet,
} from "lucide-react";
import { useProjectStore } from "../../stores/project-store";
import { useTimelineStore } from "../../stores/timeline-store";
@@ -94,7 +95,7 @@ export const Timeline: React.FC = () => {
const [showLayersPanel, setShowLayersPanel] = useState(false);
- const { select, selectMultiple, clearSelection, getSelectedClipIds } =
+ const { select, selectMultiple, clearSelection, getSelectedClipIds, snapSettings, toggleSnap } =
useUIStore();
const selectedClipIds = getSelectedClipIds();
@@ -836,6 +837,21 @@ export const Timeline: React.FC = () => {
</div>
</PopoverContent>
</Popover>
+
+ <div className="w-px h-6 bg-border mx-1" />
+
+ <button
+ onClick={toggleSnap}
+ className={`flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg transition-colors ${
+ snapSettings.enabled
+ ? "bg-yellow-500/20 text-yellow-400 border border-yellow-500/30"
+ : "hover:bg-background-elevated text-text-muted hover:text-text-secondary"
+ }`}
+ title={snapSettings.enabled ? "Disable snapping" : "Enable snapping"}
+ >
+ <Magnet size={14} />
+ <span className="text-[10px] font-medium tracking-wide">SNAP</span>
+ </button>
</div>
<div className="font-mono text-primary text-sm font-bold tracking-wider bg-background-tertiary px-4 py-1.5 rounded-lg border border-primary/20 shadow-[0_0_12px_rgba(34,197,94,0.15)]">
@@ -941,6 +957,53 @@ export const Timeline: React.FC = () => {
}}
onMouseDown={handleBoxSelectionStart}
onMouseMove={handleBoxSelectionMove}
+ onDragOver={(e) => {
+ e.preventDefault();
+ e.dataTransfer.dropEffect = "copy";
+ }}
+ onDrop={(e) => {
+ e.preventDefault();
+ try {
+ const rawData = e.dataTransfer.getData("application/json");
+ if (!rawData) return;
+ const data = JSON.parse(rawData);
+ if (!data?.mediaId) return;
+
+ const rect = tracksRef.current?.getBoundingClientRect();
+ if (!rect) return;
+ const x = e.clientX - rect.left + (tracksRef.current?.scrollLeft ?? 0);
+ const rawTime = Math.max(0, x / pixelsPerSecond);
+
+ const allClips = project.timeline.tracks.flatMap(t => t.clips);
+ let snappedTime = rawTime;
+ if (snapSettings.enabled) {
+ const threshold = snapSettings.snapThreshold / pixelsPerSecond;
+ let bestDist = Infinity;
+ for (const clip of allClips) {
+ const clipEnd = clip.startTime + clip.duration;
+ const distToEnd = Math.abs(rawTime - clipEnd);
+ const distToStart = Math.abs(rawTime - clip.startTime);
+ if (distToEnd < threshold && distToEnd < bestDist) {
+ bestDist = distToEnd;
+ snappedTime = clipEnd;
+ }
+ if (distToStart < threshold && distToStart < bestDist) {
+ bestDist = distToStart;
+ snappedTime = clip.startTime;
+ }
+ }
+ if (snapSettings.snapToPlayhead) {
+ const distToPlayhead = Math.abs(rawTime - playheadPosition);
+ if (distToPlayhead < threshold && distToPlayhead < bestDist) {
+ snappedTime = playheadPosition;
+ }
+ }
+ }
+ handleDropMedia("", data.mediaId, snappedTime);
+ } catch {
+ // ignore
+ }
+ }}
>
<div
style={{ width: `${timelineDuration * pixelsPerSecond}px` }}
diff --git a/apps/web/src/components/editor/Toolbar.tsx b/apps/web/src/components/editor/Toolbar.tsx
index aad80633..4dec4941 100644
--- a/apps/web/src/components/editor/Toolbar.tsx
+++ b/apps/web/src/components/editor/Toolbar.tsx
@@ -25,6 +25,7 @@ import {
import { useProjectStore } from "../../stores/project-store";
import { useUIStore } from "../../stores/ui-store";
import { useThemeStore } from "../../stores/theme-store";
+import { useRouter } from "../../hooks/use-router";
import {
getExportEngine,
downloadBlob,
@@ -87,6 +88,7 @@ export const Toolbar: React.FC = () => {
togglePanel,
} = useUIStore();
const { mode: themeMode, toggleTheme } = useThemeStore();
+ const { navigate } = useRouter();
const [isExportOpen, setIsExportOpen] = useState(false);
const [isExportDialogOpen, setIsExportDialogOpen] = useState(false);
const [isRecorderOpen, setIsRecorderOpen] = useState(false);
@@ -759,81 +761,90 @@ export const Toolbar: React.FC = () => {
return (
<div className="h-16 border-b border-border flex items-center px-6 justify-between bg-background shrink-0 z-30 relative">
<div className="flex items-center gap-4">
- <div className="flex items-center gap-3">
- <div className="w-8 h-8 group">
- <svg
- viewBox="0 0 490 490"
- fill="none"
- xmlns="http://www.w3.org/2000/svg"
- className="w-full h-full text-primary group-hover:scale-110 transition-transform duration-300"
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <button
+ onClick={() => navigate("welcome")}
+ className="flex items-center gap-3 hover:opacity-80 transition-opacity"
+ title="Back to Home"
>
- <path
- d="M245 24.5C123.223 24.5 24.5 123.223 24.5 245s98.723 220.5 220.5 220.5 220.5-98.723 220.5-220.5S366.777 24.5 245 24.5Z"
- stroke="currentColor"
- strokeWidth="30.625"
- className="opacity-100"
- />
- <g className="origin-center group-hover:rotate-90 transition-transform duration-500 ease-out">
- <path
- d="M245 98v73.5"
- stroke="currentColor"
- strokeWidth="24.5"
- strokeLinecap="round"
- />
- <path
- d="M392 245h-73.5"
- stroke="currentColor"
- strokeWidth="24.5"
- strokeLinecap="round"
- />
- <path
- d="M245 392v-73.5"
- stroke="currentColor"
- strokeWidth="24.5"
- strokeLinecap="round"
- />
- <path
- d="M98 245h73.5"
- stroke="currentColor"
- strokeWidth="24.5"
- strokeLinecap="round"
- />
- <path
- d="m348.941 141.059-51.965 51.965"
- stroke="currentColor"
- strokeWidth="24.5"
- strokeLinecap="round"
- />
- <path
- d="m348.941 348.941-51.965-51.965"
- stroke="currentColor"
- strokeWidth="24.5"
- strokeLinecap="round"
- />
- <path
- d="m141.059 348.941 51.965-51.965"
- stroke="currentColor"
- strokeWidth="24.5"
- strokeLinecap="round"
- />
- <path
- d="m141.059 141.059 51.965 51.965"
- stroke="currentColor"
- strokeWidth="24.5"
- strokeLinecap="round"
- />
- </g>
- <path
- d="M294 245a49 49 0 0 1-49 49 49 49 0 0 1-49-49 49 49 0 0 1 98 0"
- fill="currentColor"
- className="group-hover:fill-white transition-colors duration-300"
- />
- </svg>
- </div>
- <span className="text-lg font-medium text-text-primary tracking-wide hidden lg:block">
- Open Reel
- </span>
- </div>
+ <div className="w-8 h-8 group">
+ <svg
+ viewBox="0 0 490 490"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+ className="w-full h-full text-primary group-hover:scale-110 transition-transform duration-300"
+ >
+ <path
+ d="M245 24.5C123.223 24.5 24.5 123.223 24.5 245s98.723 220.5 220.5 220.5 220.5-98.723 220.5-220.5S366.777 24.5 245 24.5Z"
+ stroke="currentColor"
+ strokeWidth="30.625"
+ className="opacity-100"
+ />
+ <g className="origin-center group-hover:rotate-90 transition-transform duration-500 ease-out">
+ <path
+ d="M245 98v73.5"
+ stroke="currentColor"
+ strokeWidth="24.5"
+ strokeLinecap="round"
+ />
+ <path
+ d="M392 245h-73.5"
+ stroke="currentColor"
+ strokeWidth="24.5"
+ strokeLinecap="round"
+ />
+ <path
+ d="M245 392v-73.5"
+ stroke="currentColor"
+ strokeWidth="24.5"
+ strokeLinecap="round"
+ />
+ <path
+ d="M98 245h73.5"
+ stroke="currentColor"
+ strokeWidth="24.5"
+ strokeLinecap="round"
+ />
+ <path
+ d="m348.941 141.059-51.965 51.965"
+ stroke="currentColor"
+ strokeWidth="24.5"
+ strokeLinecap="round"
+ />
+ <path
+ d="m348.941 348.941-51.965-51.965"
+ stroke="currentColor"
+ strokeWidth="24.5"
+ strokeLinecap="round"
+ />
+ <path
+ d="m141.059 348.941 51.965-51.965"
+ stroke="currentColor"
+ strokeWidth="24.5"
+ strokeLinecap="round"
+ />
+ <path
+ d="m141.059 141.059 51.965 51.965"
+ stroke="currentColor"
+ strokeWidth="24.5"
+ strokeLinecap="round"
+ />
+ </g>
+ <path
+ d="M294 245a49 49 0 0 1-49 49 49 49 0 0 1-49-49 49 49 0 0 1 98 0"
+ fill="currentColor"
+ className="group-hover:fill-white transition-colors duration-300"
+ />
+ </svg>
+ </div>
+ <span className="text-lg font-medium text-text-primary tracking-wide hidden lg:block">
+ Open Reel
+ </span>
+ </button>
+ </TooltipTrigger>
+ <TooltipContent>Back to Home</TooltipContent>
+ </Tooltip>
<div className="h-6 w-px bg-border hidden md:block" />
<ProjectSwitcher />
</div>
diff --git a/apps/web/src/components/editor/inspector/AlignmentSection.tsx b/apps/web/src/components/editor/inspector/AlignmentSection.tsx
new file mode 100644
index 00000000..fd61747a
--- /dev/null
+++ b/apps/web/src/components/editor/inspector/AlignmentSection.tsx
@@ -0,0 +1,115 @@
+import React, { useCallback } from "react";
+import {
+ AlignHorizontalJustifyStart,
+ AlignHorizontalJustifyCenter,
+ AlignHorizontalJustifyEnd,
+ AlignVerticalJustifyStart,
+ AlignVerticalJustifyCenter,
+ AlignVerticalJustifyEnd,
+} from "lucide-react";
+import { useProjectStore } from "../../../stores/project-store";
+
+interface AlignmentSectionProps {
+ clipId: string;
+}
+
+export const AlignmentSection: React.FC<AlignmentSectionProps> = ({
+ clipId,
+}) => {
+ const { updateClipTransform } = useProjectStore();
+
+ const findClipTransform = useCallback(() => {
+ const { project } = useProjectStore.getState();
+ for (const track of project.timeline.tracks) {
+ const clip = track.clips.find((c) => c.id === clipId);
+ if (clip) {
+ return clip.transform ?? { position: { x: 0.5, y: 0.5 } };
+ }
+ }
+ return { position: { x: 0.5, y: 0.5 } };
+ }, [clipId]);
+
+ const handleAlign = useCallback(
+ (axis: "x" | "y", value: number) => {
+ const current = findClipTransform();
+ const currentPos = current.position ?? { x: 0.5, y: 0.5 };
+ updateClipTransform(clipId, {
+ position: { ...currentPos, [axis]: value },
+ });
+ },
+ [clipId, updateClipTransform, findClipTransform],
+ );
+
+ const handleCenterBoth = useCallback(() => {
+ updateClipTransform(clipId, {
+ position: { x: 0.5, y: 0.5 },
+ });
+ }, [clipId, updateClipTransform]);
+
+ const buttonClass =
+ "p-2 rounded-md bg-background-tertiary border border-border hover:border-primary/50 hover:bg-primary/5 transition-all text-text-secondary hover:text-primary";
+
+ return (
+ <div className="space-y-3">
+ <div className="flex items-center gap-2">
+ <span className="text-[10px] text-text-muted w-16">Horizontal</span>
+ <div className="flex gap-1">
+ <button
+ className={buttonClass}
+ onClick={() => handleAlign("x", 0)}
+ title="Align Left"
+ >
+ <AlignHorizontalJustifyStart size={14} />
+ </button>
+ <button
+ className={buttonClass}
+ onClick={() => handleAlign("x", 0.5)}
+ title="Center Horizontally"
+ >
+ <AlignHorizontalJustifyCenter size={14} />
+ </button>
+ <button
+ className={buttonClass}
+ onClick={() => handleAlign("x", 1)}
+ title="Align Right"
+ >
+ <AlignHorizontalJustifyEnd size={14} />
+ </button>
+ </div>
+ </div>
+ <div className="flex items-center gap-2">
+ <span className="text-[10px] text-text-muted w-16">Vertical</span>
+ <div className="flex gap-1">
+ <button
+ className={buttonClass}
+ onClick={() => handleAlign("y", 0)}
+ title="Align Top"
+ >
+ <AlignVerticalJustifyStart size={14} />
+ </button>
+ <button
+ className={buttonClass}
+ onClick={() => handleAlign("y", 0.5)}
+ title="Center Vertically"
+ >
+ <AlignVerticalJustifyCenter size={14} />
+ </button>
+ <button
+ className={buttonClass}
+ onClick={() => handleAlign("y", 1)}
+ title="Align Bottom"
+ >
+ <AlignVerticalJustifyEnd size={14} />
+ </button>
+ </div>
+ </div>
+ <button
+ className="w-full py-1.5 text-[10px] rounded-md bg-background-tertiary border border-border hover:border-primary/50 hover:bg-primary/5 transition-all text-text-secondary hover:text-primary"
+ onClick={handleCenterBoth}
+ title="Center on Canvas"
+ >
+ Center on Canvas
+ </button>
+ </div>
+ );
+};
diff --git a/apps/web/src/components/editor/inspector/index.ts b/apps/web/src/components/editor/inspector/index.ts
index fd74ae9b..ca23c1b1 100644
--- a/apps/web/src/components/editor/inspector/index.ts
+++ b/apps/web/src/components/editor/inspector/index.ts
@@ -37,6 +37,7 @@ export { AudioTextSyncPanel } from "./AudioTextSyncPanel";
// Graphics & Shapes
export { ShapeSection } from "./ShapeSection";
export { SVGSection } from "./SVGSection";
+export { AlignmentSection } from "./AlignmentSection";
export { SVGImporter } from "./SVGImporter";
export { StickerPicker } from "./StickerPicker";
export { StickerPickerPanel } from "./StickerPickerPanel";
diff --git a/apps/web/src/components/editor/timeline/ClipComponent.tsx b/apps/web/src/components/editor/timeline/ClipComponent.tsx
index 465f3869..a8288e35 100644
--- a/apps/web/src/components/editor/timeline/ClipComponent.tsx
+++ b/apps/web/src/components/editor/timeline/ClipComponent.tsx
@@ -210,15 +210,16 @@ export const ClipComponent: React.FC<ClipComponentProps> = ({
const x = e.clientX - rect.left - dragOffset;
const rawTime = Math.max(0, x / pixelsPerSecond);
+ const dragSnapSettings = { ...snapSettings, snapToPlayhead: false };
const snapResult = calculateSnap(
rawTime,
clip.id,
allTracks,
playheadPosition,
- snapSettings,
+ dragSnapSettings,
pixelsPerSecond,
+ clip.duration,
);
-
const currentScrollTop = timelineRef.current?.scrollTop || 0;
const scrollDelta = currentScrollTop - dragStartRef.current.scrollTop;
const yDelta = (e.clientY - dragStartRef.current.mouseY) + scrollDelta;
@@ -247,7 +248,7 @@ export const ClipComponent: React.FC<ClipComponentProps> = ({
pendingDropRef.current = { time: snapResult.time, targetTrackId };
onMoveClip(clip.id, snapResult.time, undefined);
- onSnapIndicator(snapResult.snapped ? snapResult.time : null);
+ onSnapIndicator(snapResult.snapped && snapResult.snapPoint ? snapResult.snapPoint.time : null);
};
const handleMouseUp = () => {
diff --git a/apps/web/src/components/editor/timeline/ShapeClipComponent.tsx b/apps/web/src/components/editor/timeline/ShapeClipComponent.tsx
index 2e2d2f4f..86f9e690 100644
--- a/apps/web/src/components/editor/timeline/ShapeClipComponent.tsx
+++ b/apps/web/src/components/editor/timeline/ShapeClipComponent.tsx
@@ -3,6 +3,10 @@ import { Shapes, FileCode, Smile } from "lucide-react";
import type { ShapeClip, SVGClip, StickerClip } from "@openreel/core";
import { ContextMenu, ContextMenuTrigger } from "@openreel/ui";
import { GraphicsClipContextMenu } from "./GraphicsClipContextMenu";
+import { calculateSnap } from "./utils";
+import { useProjectStore } from "../../../stores/project-store";
+import { useTimelineStore } from "../../../stores/timeline-store";
+import { useUIStore } from "../../../stores/ui-store";
type GraphicClipUnion = ShapeClip | SVGClip | StickerClip;
@@ -27,6 +31,8 @@ export const ShapeClipComponent: React.FC<ShapeClipComponentProps> = ({
const [isDragging, setIsDragging] = useState(false);
const [dragOffset, setDragOffset] = useState(0);
const [isTrimming, setIsTrimming] = useState<"left" | "right" | null>(null);
+ const { snapSettings } = useUIStore();
+ const { playheadPosition } = useTimelineStore();
const trimStartRef = useRef<{
mouseX: number;
startTime: number;
@@ -83,10 +89,19 @@ export const ShapeClipComponent: React.FC<ShapeClipComponentProps> = ({
const rect = timelineElement.getBoundingClientRect();
const x = e.clientX - rect.left - dragOffset;
- const rawTime = x / pixelsPerSecond;
- const newStartTime = Math.max(0, rawTime);
-
- onMoveClip(shapeClip.id, newStartTime);
+ const rawTime = Math.max(0, x / pixelsPerSecond);
+ const allTracks = useProjectStore.getState().project.timeline.tracks;
+ const dragSnapSettings = { ...snapSettings, snapToPlayhead: false };
+ const snapResult = calculateSnap(
+ rawTime,
+ shapeClip.id,
+ allTracks,
+ playheadPosition,
+ dragSnapSettings,
+ pixelsPerSecond,
+ shapeClip.duration,
+ );
+ onMoveClip(shapeClip.id, snapResult.time);
};
const handleMouseUp = () => {
@@ -100,7 +115,7 @@ export const ShapeClipComponent: React.FC<ShapeClipComponentProps> = ({
window.removeEventListener("mousemove", handleMouseMove);
window.removeEventListener("mouseup", handleMouseUp);
};
- }, [isDragging, dragOffset, pixelsPerSecond, shapeClip.id, onMoveClip]);
+ }, [isDragging, dragOffset, pixelsPerSecond, shapeClip.id, shapeClip.duration, onMoveClip, snapSettings, playheadPosition]);
useEffect(() => {
if (!isTrimming) return;
diff --git a/apps/web/src/components/editor/timeline/TextClipComponent.tsx b/apps/web/src/components/editor/timeline/TextClipComponent.tsx
index 5c285e03..af1f5ec9 100644
--- a/apps/web/src/components/editor/timeline/TextClipComponent.tsx
+++ b/apps/web/src/components/editor/timeline/TextClipComponent.tsx
@@ -3,6 +3,10 @@ import { Type } from "lucide-react";
import type { TextClip } from "@openreel/core";
import { ContextMenu, ContextMenuTrigger } from "@openreel/ui";
import { GraphicsClipContextMenu } from "./GraphicsClipContextMenu";
+import { calculateSnap } from "./utils";
+import { useProjectStore } from "../../../stores/project-store";
+import { useTimelineStore } from "../../../stores/timeline-store";
+import { useUIStore } from "../../../stores/ui-store";
interface TextClipComponentProps {
textClip: TextClip;
@@ -25,6 +29,8 @@ export const TextClipComponent: React.FC<TextClipComponentProps> = ({
const [isTrimming, setIsTrimming] = useState<"left" | "right" | null>(null);
const [isDragging, setIsDragging] = useState(false);
const [dragOffset, setDragOffset] = useState(0);
+ const { snapSettings } = useUIStore();
+ const { playheadPosition } = useTimelineStore();
const trimStartRef = useRef<{
mouseX: number;
startTime: number;
@@ -69,8 +75,19 @@ export const TextClipComponent: React.FC<TextClipComponentProps> = ({
if (!rect) return;
const x = e.clientX - rect.left - dragOffset;
- const newTime = Math.max(0, x / pixelsPerSecond);
- onMoveClip(textClip.id, newTime);
+ const rawTime = Math.max(0, x / pixelsPerSecond);
+ const allTracks = useProjectStore.getState().project.timeline.tracks;
+ const dragSnapSettings = { ...snapSettings, snapToPlayhead: false };
+ const snapResult = calculateSnap(
+ rawTime,
+ textClip.id,
+ allTracks,
+ playheadPosition,
+ dragSnapSettings,
+ pixelsPerSecond,
+ textClip.duration,
+ );
+ onMoveClip(textClip.id, snapResult.time);
};
const handleMouseUp = () => {
@@ -84,7 +101,7 @@ export const TextClipComponent: React.FC<TextClipComponentProps> = ({
window.removeEventListener("mousemove", handleMouseMove);
window.removeEventListener("mouseup", handleMouseUp);
};
- }, [isDragging, textClip.id, pixelsPerSecond, dragOffset, onMoveClip]);
+ }, [isDragging, textClip.id, textClip.duration, pixelsPerSecond, dragOffset, onMoveClip, snapSettings, playheadPosition]);
const handleTrimStart = (e: React.MouseEvent, edge: "left" | "right") => {
if (e.button !== 0) return;
diff --git a/apps/web/src/components/editor/timeline/TrackLane.tsx b/apps/web/src/components/editor/timeline/TrackLane.tsx
index 19a244e7..19a01fd6 100644
--- a/apps/web/src/components/editor/timeline/TrackLane.tsx
+++ b/apps/web/src/components/editor/timeline/TrackLane.tsx
@@ -10,7 +10,9 @@ import { ClipComponent } from "./ClipComponent";
import { TextClipComponent } from "./TextClipComponent";
import { ShapeClipComponent } from "./ShapeClipComponent";
import { KeyframeTrack } from "./KeyframeTrack";
+import { calculateSnap } from "./utils";
import { useTimelineStore } from "../../../stores/timeline-store";
+import { useUIStore } from "../../../stores/ui-store";
type GraphicClipUnion = ShapeClip | SVGClip | StickerClip;
@@ -81,8 +83,9 @@ export const TrackLane: React.FC<TrackLaneProps> = ({
onKeyframeDelete,
selectedKeyframeIds = [],
}) => {
- const { isTrackExpanded } = useTimelineStore();
+ const { isTrackExpanded, playheadPosition } = useTimelineStore();
const isExpanded = isTrackExpanded(track.id);
+ const { snapSettings } = useUIStore();
const [isDragOver, setIsDragOver] = useState(false);
const [isResizing, setIsResizing] = useState(false);
const laneRef = useRef<HTMLDivElement>(null);
@@ -106,6 +109,7 @@ export const TrackLane: React.FC<TrackLaneProps> = ({
const handleDrop = useCallback(
(e: React.DragEvent) => {
e.preventDefault();
+ e.stopPropagation();
setIsDragOver(false);
try {
@@ -125,8 +129,16 @@ export const TrackLane: React.FC<TrackLaneProps> = ({
const rect = laneRef.current?.getBoundingClientRect();
if (rect) {
const x = e.clientX - rect.left + scrollX;
- const startTime = Math.max(0, x / pixelsPerSecond);
- onDropMedia(track.id, data.mediaId, startTime);
+ const rawTime = Math.max(0, x / pixelsPerSecond);
+ const snapResult = calculateSnap(
+ rawTime,
+ "",
+ allTracks,
+ playheadPosition,
+ snapSettings,
+ pixelsPerSecond,
+ );
+ onDropMedia(track.id, data.mediaId, snapResult.time);
}
} catch {
// Silently ignore parse errors
diff --git a/apps/web/src/components/editor/timeline/utils.ts b/apps/web/src/components/editor/timeline/utils.ts
index 53493984..d0236694 100644
--- a/apps/web/src/components/editor/timeline/utils.ts
+++ b/apps/web/src/components/editor/timeline/utils.ts
@@ -15,6 +15,7 @@ export const calculateSnap = (
playheadPosition: number,
snapSettings: SnapSettings,
pixelsPerSecond: number,
+ clipDuration?: number,
): SnapResult => {
if (!snapSettings.enabled) {
return { time: rawTime, snapped: false };
@@ -44,21 +45,68 @@ export const calculateSnap = (
const nearestGrid =
Math.round(rawTime / snapSettings.gridSize) * snapSettings.gridSize;
snapPoints.push({ time: nearestGrid, type: "grid" });
+ if (clipDuration) {
+ const endTime = rawTime + clipDuration;
+ const nearestEndGrid =
+ Math.round(endTime / snapSettings.gridSize) * snapSettings.gridSize;
+ snapPoints.push({ time: nearestEndGrid, type: "grid" });
+ }
}
+ const priorityOrder: Record<string, number> = {
+ "clip-start": 0,
+ "clip-end": 0,
+ "playhead": 1,
+ "grid": 2,
+ };
+
let closestPoint: SnapPoint | undefined;
let closestDistance = Infinity;
+ let closestPriority = Infinity;
+ let snapFromEnd = false;
for (const point of snapPoints) {
- const distance = Math.abs(point.time - rawTime);
- if (distance < thresholdSeconds && distance < closestDistance) {
- closestDistance = distance;
- closestPoint = point;
+ const pointPriority = priorityOrder[point.type] ?? 2;
+
+ const startDistance = Math.abs(point.time - rawTime);
+ if (startDistance < thresholdSeconds) {
+ const isBetter =
+ pointPriority < closestPriority ||
+ (pointPriority === closestPriority && startDistance < closestDistance);
+ if (isBetter) {
+ closestDistance = startDistance;
+ closestPriority = pointPriority;
+ closestPoint = point;
+ snapFromEnd = false;
+ }
+ }
+
+ if (clipDuration) {
+ const clipEndTime = rawTime + clipDuration;
+ const endDistance = Math.abs(point.time - clipEndTime);
+ if (endDistance < thresholdSeconds) {
+ const isBetter =
+ pointPriority < closestPriority ||
+ (pointPriority === closestPriority && endDistance < closestDistance);
+ if (isBetter) {
+ closestDistance = endDistance;
+ closestPriority = pointPriority;
+ closestPoint = point;
+ snapFromEnd = true;
+ }
+ }
}
}
if (closestPoint) {
- return { time: closestPoint.time, snapped: true, snapPoint: closestPoint };
+ const snappedTime = snapFromEnd
+ ? closestPoint.time - (clipDuration ?? 0)
+ : closestPoint.time;
+ return {
+ time: Math.max(0, snappedTime),
+ snapped: true,
+ snapPoint: { ...closestPoint, time: closestPoint.time },
+ };
}
return { time: rawTime, snapped: false };
diff --git a/apps/web/src/stores/ui-store.ts b/apps/web/src/stores/ui-store.ts
index 1b125e10..b6e962f5 100644
--- a/apps/web/src/stores/ui-store.ts
+++ b/apps/web/src/stores/ui-store.ts
@@ -172,7 +172,7 @@ const DEFAULT_SNAP_SETTINGS: SnapSettings = {
snapToPlayhead: true,
snapToMarkers: true,
gridSize: 1, // 1 second
- snapThreshold: 10, // 10 pixels
+ snapThreshold: 40,
};
const DEFAULT_PANELS: Record<PanelId, PanelState> = {
@@ -532,8 +532,14 @@ export const useUIStore = create<UIState>()(
}),
{
name: "openreel-ui-preferences",
- // Only persist user preferences, not transient state (selections, drag state, modals)
- // This prevents localStorage bloat and ensures clean state on new sessions
+ version: 1,
+ migrate: (persisted: unknown, version: number) => {
+ const state = persisted as Record<string, unknown>;
+ if (version === 0) {
+ state.snapSettings = DEFAULT_SNAP_SETTINGS;
+ }
+ return state;
+ },
partialize: (state) => ({
snapSettings: state.snapSettings,
panels: state.panels,
@@ -544,7 +550,6 @@ export const useUIStore = create<UIState>()(
showKeyframes: state.showKeyframes,
autoScroll: state.autoScroll,
skipWelcomeScreen: state.skipWelcomeScreen,
- // NOT persisted: selectedItems, isDragging, contextMenu, activeModal, showWelcomeScreen
}),
},
),
diff --git a/packages/core/src/export/export-engine.ts b/packages/core/src/export/export-engine.ts
index 8161c1ce..69cb027a 100644
--- a/packages/core/src/export/export-engine.ts
+++ b/packages/core/src/export/export-engine.ts
@@ -371,9 +371,9 @@ export class ExportEngine {
fullSettings.codec === "vp9" ||
fullSettings.codec === "av1" ||
fullSettings.codec === "h265";
- const microFlushInterval = isIntensiveCodec ? 5 : 10;
- const majorFlushInterval = 30;
- const cacheCleanInterval = 90;
+ const microFlushInterval = isIntensiveCodec ? 10 : 20;
+ const majorFlushInterval = 60;
+ const cacheCleanInterval = 180;
for (let frame = 0; frame < totalFrames; frame++) {
if (this.abortController.signal.aborted) {
@@ -421,7 +421,7 @@ export class ExportEngine {
}
if ((frame + 1) % majorFlushInterval === 0) {
- await new Promise((resolve) => setTimeout(resolve, 50));
+ await new Promise((resolve) => setTimeout(resolve, 10));
}
if ((frame + 1) % cacheCleanInterval === 0) {
@@ -432,7 +432,7 @@ export class ExportEngine {
} catch {
// MediaEngine may not be initialized
}
- await new Promise((resolve) => setTimeout(resolve, 100));
+ await new Promise((resolve) => setTimeout(resolve, 10));
}
yield this.createProgress(
@@ -662,7 +662,7 @@ export class ExportEngine {
});
let framesInFlight = 0;
- const MAX_FRAMES_IN_FLIGHT = writableStream ? 1 : 3;
+ const MAX_FRAMES_IN_FLIGHT = writableStream ? 4 : 8;
let frameProcessedResolve: (() => void) | null = null;
this.exportWorker = new Worker(
diff --git a/packages/core/src/export/export-worker.ts b/packages/core/src/export/export-worker.ts
index c620604f..46653a28 100644
--- a/packages/core/src/export/export-worker.ts
+++ b/packages/core/src/export/export-worker.ts
@@ -137,13 +137,11 @@ async function initialize(
}
}
- const isLongVideo = settings.width * settings.height > 1920 * 1080 || streamMode;
-
videoSource = new VideoSampleSource({
codec: videoCodec,
bitrate: QUALITY_MEDIUM,
keyFrameInterval: settings.keyframeInterval / settings.frameRate,
- hardwareAcceleration: isLongVideo ? "prefer-software" : "prefer-hardware",
+ hardwareAcceleration: "prefer-hardware",
});
audioSource = new AudioSampleSource({