Skip to content

Create professional demos and 3D mockups in seconds, directly in your browser

feat: enhance video editor functionality and UI

CristianOlivera1b06c435a5bf5
diff --git a/.gitignore b/.gitignore
index 4a26e60..4c18230 100644
--- a/.gitignore
+++ b/.gitignore
@@ -45,4 +45,5 @@ supabase-setup.sql
BACKEND_SPEC.md
BACKEND_TESTING.md
-/openvid-back
\ No newline at end of file
+/openvid-back
+/lib/video-canvas
\ No newline at end of file
diff --git a/app/[locale]/(editor)/editor/page.tsx b/app/[locale]/(editor)/editor/page.tsx
index bb1132a..2310497 100644
--- a/app/[locale]/(editor)/editor/page.tsx
+++ b/app/[locale]/(editor)/editor/page.tsx
@@ -36,7 +36,7 @@ import { MobileControlPanel } from "@/app/components/ui/editor/MobileControlPane
import { EditorTopBar } from "@/app/components/ui/editor/EditorTopBar";
import { VideoCanvas } from "@/app/components/ui/editor/VideoCanvas";
import { PlayerControls } from "@/app/components/ui/editor/PlayerControls";
-import { findValidFragmentPosition } from "@/app/components/ui/editor/ZoomFragmentTrackItem";
+import { canAddFragmentAt, findValidFragmentPosition } from "@/app/components/ui/editor/ZoomFragmentTrackItem";
import { LoadingSpinner } from "@/components/ui/LoadingSpinner";
import { TimelineSkeleton } from "@/app/components/ui/Skeleton";
import { AudioTrimModal } from "@/app/components/ui/editor/AudioTrimModal";
@@ -1796,6 +1796,8 @@ export default function Editor() {
trimStart: 0,
trimEnd: uploadedData.duration,
thumbnailUrl: libraryVideo.thumbnailUrl,
+ width: uploadedData.width,
+ height: uploadedData.height,
};
clipAudioStateRef.current.set(libraryVideo.id, libraryVideo.hasAudio !== false);
activeClipIdRef.current = newClip.id;
@@ -1826,24 +1828,28 @@ export default function Editor() {
// Handler to add video from library to the track (concatenate)
const handleAddVideoToTrack = useCallback(async (videoId: string, blob: Blob, duration: number) => {
- // Get video info from library
const libraryVideo = await import("@/lib/videos-library").then(m => m.getLibraryVideo(videoId));
if (!libraryVideo) return;
- // Cache the per-clip audio state (hasAudio defaults to true if undefined)
clipAudioStateRef.current.set(videoId, libraryVideo.hasAudio !== false);
- // Store blob in ref for multi-video playback
if (!videoBlobsRef.current.has(videoId)) {
videoBlobsRef.current.set(videoId, blob);
const blobUrl = URL.createObjectURL(blob);
videoUrlsRef.current.set(videoId, blobUrl);
}
- // Use functional update to always have the latest state
+ const { width: clipWidth, height: clipHeight } = await new Promise<{ width: number; height: number }>((resolve) => {
+ const probe = document.createElement('video');
+ probe.preload = 'metadata';
+ const probeUrl = videoUrlsRef.current.get(videoId)!;
+ probe.onloadedmetadata = () => resolve({ width: probe.videoWidth, height: probe.videoHeight });
+ probe.onerror = () => resolve({ width: 0, height: 0 });
+ probe.src = probeUrl;
+ });
+
setVideoClips(prevClips => {
const startTime = findNextClipPosition(prevClips);
-
const newClip: VideoTrackClip = {
id: crypto.randomUUID(),
libraryVideoId: videoId,
@@ -1853,8 +1859,9 @@ export default function Editor() {
trimStart: 0,
trimEnd: duration,
thumbnailUrl: libraryVideo.thumbnailUrl,
+ width: clipWidth || undefined,
+ height: clipHeight || undefined,
};
-
const updatedClips = [...prevClips, newClip];
setTimeout(() => {
@@ -1895,6 +1902,21 @@ export default function Editor() {
});
}, [clearHistory]);
+ const activeClipForDims = useMemo(
+ () => (videoClips.length > 0 ? getClipAtTime(videoClips, currentTime) : null),
+ [videoClips, currentTime]
+ );
+
+ const activeMediaAspect = useMemo(() => {
+ if (!activeClipForDims?.width || !activeClipForDims?.height) return null;
+ return activeClipForDims.width / activeClipForDims.height;
+ }, [activeClipForDims]);
+
+ const activeClipUrl = useMemo(() => {
+ if (!activeClipForDims) return videoUrl;
+ return videoUrlsRef.current.get(activeClipForDims.libraryVideoId) ?? videoUrl;
+ }, [activeClipForDims, videoUrl]);
+
// Handlers for video clip management
const handleSelectVideoClip = useCallback((clipId: string | null) => {
setSelectedVideoClipId(clipId);
@@ -2217,6 +2239,8 @@ export default function Editor() {
trimEnd: libraryVideo.duration,
thumbnailUrl: libraryVideo.thumbnailUrl,
hasCamera: 'cameraUrl' in videoToLoad && !!videoToLoad.cameraUrl,
+ width,
+ height,
};
activeClipIdRef.current = newClip.id;
@@ -2911,18 +2935,14 @@ export default function Editor() {
// Default duration for new zoom fragments
const DEFAULT_ZOOM_FRAGMENT_DURATION = 2;
- const handleAddZoomFragment = useCallback((startTime: number) => {
- // Find valid position avoiding overlaps - use ref to get latest fragments
+ const handleAddZoomFragment = useCallback((hintTime: number) => {
const validPosition = findValidFragmentPosition(
- startTime,
+ hintTime,
DEFAULT_ZOOM_FRAGMENT_DURATION,
zoomFragmentsRef.current,
videoDuration
);
-
- if (!validPosition) {
- return;
- }
+ if (!validPosition) return;
const newFragment = createZoomFragment(validPosition.startTime, validPosition.endTime);
setZoomFragments(prev => [...prev, newFragment].sort((a, b) => a.startTime - b.startTime));
@@ -2930,6 +2950,15 @@ export default function Editor() {
setActiveTool("zoom");
}, [videoDuration]);
+ const handleAddZoomFragmentAtRange = useCallback((startTime: number, endTime: number) => {
+ if (!canAddFragmentAt(startTime, endTime, zoomFragmentsRef.current)) return;
+
+ const newFragment = createZoomFragment(startTime, endTime);
+ setZoomFragments(prev => [...prev, newFragment].sort((a, b) => a.startTime - b.startTime));
+ setSelectedZoomFragmentId(newFragment.id);
+ setActiveTool("zoom");
+ }, []);
+
const handleUpdateZoomFragment = useCallback((fragmentId: string, updates: Partial<ZoomFragment>) => {
setZoomFragments(prev => prev.map(f =>
f.id === fragmentId ? { ...f, ...updates } : f
@@ -3343,6 +3372,8 @@ export default function Editor() {
onCameraConfigChange={handleCameraConfigChange}
onCameraClick={handleCameraClick}
onEnded={handleVideoEnded}
+ activeMediaAspect={activeMediaAspect}
+ activeClipUrl={activeClipUrl}
/>
{/* Video mode: Show player controls and timeline */}
@@ -3391,7 +3422,7 @@ export default function Editor() {
zoomFragments={zoomFragments}
selectedZoomFragmentId={selectedZoomFragmentId}
onSelectZoomFragment={handleSelectZoomFragment}
- onAddZoomFragment={handleAddZoomFragment}
+ onAddZoomFragment={handleAddZoomFragmentAtRange}
onUpdateZoomFragment={handleUpdateZoomFragment}
onActivateZoomTool={handleActivateZoomTool}
audioTracks={audioTracks}
diff --git a/app/components/ui/editor/Timeline.tsx b/app/components/ui/editor/Timeline.tsx
index 2e6589e..88a3845 100644
--- a/app/components/ui/editor/Timeline.tsx
+++ b/app/components/ui/editor/Timeline.tsx
@@ -25,20 +25,17 @@ export function Timeline({
onDragEnd,
trimRange,
onTrimChange,
- // Video clips props
videoClips = [],
selectedVideoClipId,
onSelectVideoClip,
onUpdateVideoClip,
onDeleteVideoClip,
- // Zoom props
zoomFragments = [],
selectedZoomFragmentId,
onSelectZoomFragment,
onAddZoomFragment,
onUpdateZoomFragment,
onActivateZoomTool,
- // Audio props
audioTracks = [],
uploadedAudios = [],
selectedAudioTrackId,
@@ -53,7 +50,6 @@ export function Timeline({
const [isDragging, setIsDragging] = useState(false);
const [isDraggingTrim, setIsDraggingTrim] = useState<'start' | 'end' | null>(null);
const [isDraggingZoomFragment, setIsDraggingZoomFragment] = useState(false);
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
const [isDraggingVideoClip, setIsDraggingVideoClip] = useState(false);
const [isOverFragment, setIsOverFragment] = useState(false);
@@ -62,9 +58,12 @@ export function Timeline({
const isSeekingRef = useRef<boolean>(false);
const [isHoveringZoomRow, setIsHoveringZoomRow] = useState(false);
const [ghostX, setGhostX] = useState(0);
+ const ghostRafRef = useRef<number | null>(null);
+ const pendingGhostXRef = useRef<number | null>(null);
+ const lastValidPositionRef = useRef<{ startTime: number; endTime: number } | null>(null);
+
const validDuration = useMemo(() => {
if (videoClips.length > 0) {
- // Total duration = end of last clip
const lastClipEnd = Math.max(...videoClips.map(c => c.startTime + (c.trimEnd - c.trimStart)));
return Number.isFinite(lastClipEnd) && lastClipEnd > 0 ? lastClipEnd : 0;
}
@@ -104,7 +103,6 @@ export function Timeline({
return `${prefix} · ${formatTime(secs)}`;
}
);
- // Calculate trim handle positions
const trimStartPosition = useMemo(() => {
if (validDuration === 0 || contentWidth === 0) return 0;
return (trimRange.start / validDuration) * contentWidth;
@@ -115,7 +113,6 @@ export function Timeline({
return (trimRange.end / validDuration) * contentWidth;
}, [trimRange.end, validDuration, contentWidth]);
- // Update trim motion values when positions change
useEffect(() => {
if (!isDraggingTrim) {
trimStartX.set(trimStartPosition);
@@ -150,7 +147,6 @@ export function Timeline({
}
}, [playheadPosition, isDragging, isDraggingPlayhead, playheadX]);
- // Cleanup RAF on unmount
useEffect(() => {
return () => {
if (rafIdRef.current) {
@@ -178,7 +174,6 @@ export function Timeline({
if (clickX >= 0 && contentWidth > 0) {
const percentage = Math.max(0, Math.min(1, clickX / contentWidth));
const newTime = percentage * validDuration;
- // Clamp to trim range
const clampedTime = Math.max(trimRange.start, Math.min(trimRange.end, newTime));
onSeek(clampedTime);
}
@@ -195,10 +190,8 @@ export function Timeline({
const newTime = (newX / contentWidth) * validDuration;
- // Store latest position for seek
pendingSeekRef.current = newTime;
- // Use requestAnimationFrame for smooth, display-synced seeking
if (!isSeekingRef.current) {
isSeekingRef.current = true;
rafIdRef.current = requestAnimationFrame(() => {
@@ -218,12 +211,10 @@ export function Timeline({
}, [onDragStart]);
const handleDragEnd = useCallback(() => {
- // Cancel any pending RAF
if (rafIdRef.current) {
cancelAnimationFrame(rafIdRef.current);
rafIdRef.current = null;
}
- // Always seek to final position on drag end (precise seek)
if (pendingSeekRef.current !== null) {
onSeek(pendingSeekRef.current);
pendingSeekRef.current = null;
@@ -233,14 +224,12 @@ export function Timeline({
onDragEnd?.();
}, [onDragEnd, onSeek]);
- // Trim handle drag handlers
const handleTrimStartDrag = useCallback((_: MouseEvent | TouchEvent | PointerEvent, info: PanInfo) => {
if (contentWidth === 0 || validDuration === 0) return;
const newX = Math.max(0, Math.min(trimEndX.get() - (MIN_TRIM_DURATION / validDuration) * contentWidth, trimStartX.get() + info.delta.x));
trimStartX.set(newX);
- // Store pending value without triggering parent update
const newStartTime = (newX / contentWidth) * validDuration;
pendingTrimRef.current = { start: Math.max(0, newStartTime), end: trimRange.end };
}, [contentWidth, validDuration, trimStartX, trimEndX, trimRange.end]);
@@ -251,7 +240,6 @@ export function Timeline({
const newX = Math.min(contentWidth, Math.max(trimStartX.get() + (MIN_TRIM_DURATION / validDuration) * contentWidth, trimEndX.get() + info.delta.x));
trimEndX.set(newX);
- // Store pending value without triggering parent update
const newEndTime = (newX / contentWidth) * validDuration;
pendingTrimRef.current = { start: trimRange.start, end: Math.min(validDuration, newEndTime) };
}, [contentWidth, validDuration, trimStartX, trimEndX, trimRange.start]);
@@ -264,11 +252,9 @@ export function Timeline({
const handleTrimDragEnd = useCallback(() => {
setIsDraggingTrim(null);
- // Apply pending trim change
if (pendingTrimRef.current) {
onTrimChange(pendingTrimRef.current);
- // Adjust playhead if needed
if (currentTime < pendingTrimRef.current.start) {
onSeek(pendingTrimRef.current.start);
} else if (currentTime > pendingTrimRef.current.end) {
@@ -279,7 +265,6 @@ export function Timeline({
}
}, [onTrimChange, currentTime, onSeek]);
- // Auto-scroll when playhead near edge
useEffect(() => {
if (!containerRef.current || isDragging) return;
const scrollableArea = containerRef.current.querySelector('[data-scrollable]') as HTMLDivElement;
@@ -318,13 +303,37 @@ export function Timeline({
([end, cw]: number[]) => cw - end
);
+ useEffect(() => {
+ return () => {
+ if (rafIdRef.current) cancelAnimationFrame(rafIdRef.current);
+ if (ghostRafRef.current) cancelAnimationFrame(ghostRafRef.current);
+ };
+ }, []);
+
+ const ghostState = useMemo(() => {
+ if (!isHoveringZoomRow || isDraggingZoomFragment || isOverFragment) return null;
+ if (contentWidth === 0 || validDuration === 0) return null;
+
+ const hoverTime = (ghostX / contentWidth) * validDuration;
+ const validPosition = findValidFragmentPosition(
+ hoverTime,
+ DEFAULT_ZOOM_FRAGMENT_DURATION,
+ zoomFragments,
+ validDuration
+ );
+ return { validPosition };
+ }, [isHoveringZoomRow, isDraggingZoomFragment, isOverFragment, ghostX, contentWidth, validDuration, zoomFragments]);
+
+ useEffect(() => {
+ lastValidPositionRef.current = ghostState?.validPosition ?? null;
+ }, [ghostState]);
+
return (
<div ref={containerRef} className="flex flex-col w-full pr-2">
<div className="h-38 shrink-0 bg-[#0D0D11] border-t border-white/10 flex flex-col font-mono text-[10px]">
<div className="flex-1 flex flex-col relative overflow-hidden">
<LabelSidebar audioTracksCount={audioTracks.length} />
- {/* Scrollable content */}
<div
ref={trackRef}
data-scrollable
@@ -338,7 +347,6 @@ export function Timeline({
minWidth: '100%'
}}
>
- {/* Playhead */}
<motion.div
className="absolute top-0 bottom-0 z-20 flex flex-col items-center cursor-ew-resize group select-none"
style={{ x: playheadX, translateX: "-50%" }}
@@ -365,7 +373,6 @@ export function Timeline({
<div className={`w-px flex-1 transition-all duration-150 ${isDragging ? 'bg-blue-200 w-[2px] shadow-[0_0_8px_rgba(147,197,253,0.5)] ease-out' : 'bg-blue-400 group-hover:bg-blue-300'}`} />
</motion.div>
- {/* Ruler */}
<div
className="h-[22px] border-b border-white/10 relative shrink-0 cursor-pointer bg-zinc-900/40 select-none overflow-hidden"
onClick={handleTrackClick}
@@ -397,15 +404,12 @@ export function Timeline({
</div>
</div>
- {/* Tracks */}
<div className="flex-1 flex flex-col" onClick={handleTrackClick}>
- {/* Video track */}
<div className="flex-1 flex items-center py-0.5 relative">
<div
className="h-full w-full rounded-md flex items-center relative bg-[#0a1510] border border-white/5"
>
- {/* Multi-video clips mode */}
{videoClips.length > 0 ? (
<>
{videoClips.map((clip) => (
@@ -428,7 +432,6 @@ export function Timeline({
</>
) : (
<>
- {/* Legacy single video mode */}
{trimRange.start > 0 && (
<motion.div
className="absolute left-0 top-0 bottom-0 bg-black/60 rounded-l-md z-10"
@@ -442,7 +445,6 @@ export function Timeline({
/>
)}
- {/* Active clip region */}
<motion.div
className="absolute top-0 bottom-0 rounded-md border border-[#34A853]/40 bg-[#182e20] overflow-hidden"
style={{ left: clipLeftMotion, width: clipWidthMotion }}
@@ -473,7 +475,6 @@ export function Timeline({
{trimmedDurationLabel}
</motion.span>
</motion.div>
- {/* Trim Start Handle */}
<motion.div
className="absolute top-0 bottom-0 w-3 cursor-ew-resize z-20 group/trim flex items-center justify-center"
style={{ x: trimStartX, translateX: "-50%" }}
@@ -494,7 +495,6 @@ export function Timeline({
<div className={`w-1.5 h-8 rounded-full transition-all ${isDraggingTrim === 'start' ? 'bg-[#4ade80] scale-110' : 'bg-[#34A853] group-hover/trim:bg-[#4ade80]'}`} aria-hidden="true" />
</motion.div>
- {/* Trim End Handle */}
<motion.div
className="absolute top-0 bottom-0 w-3 cursor-ew-resize z-20 group/trim flex items-center justify-center"
style={{ x: trimEndX, translateX: "-50%" }}
@@ -519,110 +519,63 @@ export function Timeline({
</div>
</div>
- {/* Zoom track */}
<div
className="flex-1 flex items-center relative"
onMouseMove={(e) => {
if (isDraggingZoomFragment) return;
const rect = e.currentTarget.getBoundingClientRect();
- setGhostX(e.clientX - rect.left);
+ pendingGhostXRef.current = e.clientX - rect.left;
+ if (ghostRafRef.current === null) {
+ ghostRafRef.current = requestAnimationFrame(() => {
+ if (pendingGhostXRef.current !== null) setGhostX(pendingGhostXRef.current);
+ ghostRafRef.current = null;
+ });
+ }
setIsHoveringZoomRow(true);
}}
onMouseLeave={() => setIsHoveringZoomRow(false)}
onClick={(e) => {
- // Don't add if dragging or clicking on a fragment
- if (isOverFragment || isDraggingZoomFragment || !onAddZoomFragment || validDuration === 0 || contentWidth === 0) return;
- const rect = e.currentTarget.getBoundingClientRect();
- const clickX = e.clientX - rect.left;
- const clickTime = (clickX / contentWidth) * validDuration;
-
- // Find valid position (avoiding overlaps)
- const validPosition = findValidFragmentPosition(
- clickTime,
- DEFAULT_ZOOM_FRAGMENT_DURATION,
- zoomFragments,
- validDuration
- );
+ e.stopPropagation();
+ if (isOverFragment || isDraggingZoomFragment || !onAddZoomFragment) return;
+ const validPosition = lastValidPositionRef.current;
if (validPosition) {
- onAddZoomFragment(validPosition.startTime);
+ onAddZoomFragment(validPosition.startTime, validPosition.endTime);
}
}}
>
<div className="h-full w-full flex items-center relative">
- {/* Dynamic zoom fragments with drag/resize */}
{zoomFragments.map((fragment) => (
- <ZoomFragmentTrackItem
- key={fragment.id}
- fragment={fragment}
- isSelected={fragment.id === selectedZoomFragmentId}
- contentWidth={contentWidth}
- videoDuration={validDuration}
- otherFragments={zoomFragments.filter(f => f.id !== fragment.id)}
- onSelect={() => {
- onSelectZoomFragment?.(fragment.id);
- onActivateZoomTool?.();
- }}
- onUpdate={(updates) => onUpdateZoomFragment?.(fragment.id, updates)}
- onDragStateChange={(dragging) => {
- setIsDraggingZoomFragment(dragging);
- if (dragging) {
- setIsOverFragment(true);
- setIsHoveringZoomRow(false);
- }
- }}
- onMouseEnter={() => setIsOverFragment(true)}
- onMouseLeave={() => setIsOverFragment(false)}
- />
+ <ZoomFragmentTrackItem key={fragment.id} fragment={fragment} isSelected={fragment.id === selectedZoomFragmentId} contentWidth={contentWidth} videoDuration={validDuration} otherFragments={zoomFragments.filter(f => f.id !== fragment.id)} onSelect={() => { onSelectZoomFragment?.(fragment.id); onActivateZoomTool?.(); }} onUpdate={(updates) => onUpdateZoomFragment?.(fragment.id, updates)} onDragStateChange={(dragging) => { setIsDraggingZoomFragment(dragging); if (dragging) { setIsOverFragment(true); setIsHoveringZoomRow(false); } }} onMouseEnter={() => setIsOverFragment(true)} onMouseLeave={() => setIsOverFragment(false)} />
))}
- {isHoveringZoomRow && !isDraggingZoomFragment && !isOverFragment && (() => {
- const hoverTime = (ghostX / contentWidth) * validDuration;
- const validPosition = findValidFragmentPosition(
- hoverTime,
- DEFAULT_ZOOM_FRAGMENT_DURATION,
- zoomFragments,
- validDuration
- );
-
- if (!validPosition) {
- return (
- <div
- className="absolute top-[10%] h-[80%] w-32 pointer-events-none"
- style={{ left: ghostX - 64 }}
- >
- <div className="w-full h-full rounded border border-dashed border-red-400/50 bg-red-500/10 flex flex-col items-center justify-center gap-0.5">
- <span className="text-[8px] font-mono text-red-400/60"> {t("noSpace")}</span>
- </div>
- </div>
- );
- }
-
- // Calculate ghost position based on valid position
- const ghostLeft = (validPosition.startTime / validDuration) * contentWidth;
- const ghostWidth = ((validPosition.endTime - validPosition.startTime) / validDuration) * contentWidth;
+ {ghostState?.validPosition && (
+ <motion.div
+ className="absolute top-[10%] h-[80%] pointer-events-none"
+ initial={false}
+ animate={{
+ left: (ghostState.validPosition.startTime / validDuration) * contentWidth,
+ width: ((ghostState.validPosition.endTime - ghostState.validPosition.startTime) / validDuration) * contentWidth,
+ }}
+ transition={{ duration: 0 }} // sin lag: WYSIWYG con el click
+ >
+ <div className="w-full h-full rounded border border-dashed border-blue-400/50 bg-blue-500/10 flex flex-col items-center justify-center gap-0.5">
+ <Icon icon="qlementine-icons:zoom-12" width="12" height="12" className="text-blue-400" aria-hidden="true" />
+ <span className="text-[8px] font-mono text-blue-400/60">+ Zoom</span>
+ </div>
+ </motion.div>
+ )}
- return (
- <motion.div
- className="absolute top-[10%] h-[80%] pointer-events-none"
- initial={false}
- animate={{
- left: ghostLeft,
- width: ghostWidth,
- }}
- transition={{ type: "spring", stiffness: 500, damping: 40 }}
- >
- <div className="w-full h-full rounded border border-dashed border-blue-400/50 bg-blue-500/10 flex flex-col items-center justify-center gap-0.5">
- <Icon icon="qlementine-icons:zoom-12" width="12" height="12" className="text-blue-400" aria-hidden="true" />
- <span className="text-[8px] font-mono text-blue-400/60">+ Zoom</span>
- </div>
- </motion.div>
- );
- })()}
+ {isHoveringZoomRow && !isDraggingZoomFragment && !isOverFragment && ghostState && !ghostState.validPosition && (
+ <div className="absolute top-[10%] h-[80%] w-32 pointer-events-none" style={{ left: ghostX - 64 }}>
+ <div className="w-full h-full rounded border border-dashed border-red-400/50 bg-red-500/10 flex flex-col items-center justify-center gap-0.5">
+ <span className="text-[8px] font-mono text-red-400/60"> {t("noSpace")}</span>
+ </div>
+ </div>
+ )}
</div>
</div>
- {/* Audio track - only show if there are audio tracks */}
{audioTracks.length > 0 && (
<div className="h-5 shrink-0 flex items-center relative">
<div className="h-full w-full flex items-center relative">
diff --git a/app/components/ui/editor/VideoCanvas.tsx b/app/components/ui/editor/VideoCanvas.tsx
index 0b8290f..2d26ef7 100644
--- a/app/components/ui/editor/VideoCanvas.tsx
+++ b/app/components/ui/editor/VideoCanvas.tsx
@@ -7,7 +7,7 @@ import type { ImageElement, SvgElement } from "@/types/canvas-elements.types";
import { getCameraLayout } from "@/types/camera.types";
import { ASPECT_RATIO_DIMENSIONS } from "@/types";
import { getWallpaperUrl } from "@/lib/wallpaper.utils";
-import { drawRoundedRect, drawRoundedRectBottomOnly, calculateScaledPadding, applyCanvasBackground, getAspectRatioStyle, getAspectRatioNumber, Corner, getCornerStyle, getNearestCorner, snapRotation } from "@/lib/canvas.utils";
+import { drawRoundedRect, drawRoundedRectBottomOnly, calculateScaledPadding, applyCanvasBackground, getAspectRatioStyle, getAspectRatioNumber, Corner, getCornerStyle, getNearestCorner, snapRotation, drawImageCover } from "@/lib/canvas.utils";
import { drawMockupToCanvas } from "@/lib/mockup-canvas.utils";
import { speedToTransitionMs, ZOOM_EASING, calculateZoomPhaseState, zoomLevelToFactor } from "@/types/zoom.types";
import type { ZoomFragment } from "@/types/zoom.types";
@@ -120,6 +120,8 @@ function VideoCanvasInner({
onMockupClick,
isRestoringProjectRef,
ref,
+ activeMediaAspect = null,
+ activeClipUrl = null,
}: VideoCanvasProps & { ref?: React.Ref<VideoCanvasHandle> }) {
const wallpaperUrl = getWallpaperUrl(selectedWallpaper);
@@ -268,15 +270,16 @@ function VideoCanvasInner({
}, [mockupId]);
useEffect(() => {
- if (videoRef.current && videoUrl) {
+ const targetUrl = activeClipUrl ?? videoUrl;
+ if (videoRef.current && targetUrl) {
// Always set src if video element has no src, src is empty, or we just changed mockup
const videoSrc = videoRef.current.src;
const needsSrc = !videoSrc || videoSrc === '' || videoSrc === window.location.href;
- const isNewUrl = videoUrl !== lastSetVideoUrlRef.current;
+ const isNewUrl = targetUrl !== lastSetVideoUrlRef.current;
if (needsSrc || isNewUrl) {
- videoRef.current.src = videoUrl;
- lastSetVideoUrlRef.current = videoUrl;
+ videoRef.current.src = targetUrl;
+ lastSetVideoUrlRef.current = targetUrl;
if (preservedVideoStateRef.current) {
const { time, playing } = preservedVideoStateRef.current;
@@ -290,12 +293,11 @@ function VideoCanvasInner({
}
}
}
- if (!videoUrl) {
+ if (!videoUrl && !activeClipUrl) {
lastSetVideoUrlRef.current = null;
}
- }, [videoUrl, videoRef, mockupId]);
+ }, [videoUrl, activeClipUrl, videoRef, mockupId]);
- // Preserve video state when mockup changes (detect unmount via cleanup)
// Preserve video state when mockup changes (detect unmount via cleanup)
useEffect(() => {
return () => {
@@ -309,9 +311,14 @@ function VideoCanvasInner({
}, [mockupId, videoUrl, videoRef]);
// Track the real intrinsic aspect ratio of the video so the "none"
- // mockup container can match the actual letterboxed contain-box.
useEffect(() => {
if (mediaType !== "video") return;
+
+ if (activeMediaAspect) {
+ setMediaAspect(activeMediaAspect);
+ return;
+ }
+
const video = videoRef.current;
if (!video) return;
const updateAspect = () => {
@@ -322,7 +329,7 @@ function VideoCanvasInner({
updateAspect();
video.addEventListener("loadedmetadata", updateAspect);
return () => video.removeEventListener("loadedmetadata", updateAspect);
- }, [mediaType, videoRef, videoUrl]);
+ }, [mediaType, videoRef, videoUrl, activeMediaAspect]);
// Same, for image mode.
useEffect(() => {
@@ -1220,8 +1227,9 @@ function VideoCanvasInner({
const scaledPaddingX = calculateScaledPadding(canvasWidth, paddingPercent);
const scaledPaddingY = calculateScaledPadding(canvasHeight, paddingPercent);
- const scaledRadius = roundedCorners * (canvasWidth / 896);
- const scaledShadowBlur = shadows * (canvasWidth / 896) * 0.8;
+ const canvasLongSide = Math.max(canvasWidth, canvasHeight);
+ const scaledRadius = roundedCorners * (canvasLongSide / 896);
+ const scaledShadowBlur = shadows * (canvasLongSide / 896) * 0.8;
ctx.setTransform(1, 0, 0, 1, 0, 0);
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
@@ -1243,9 +1251,9 @@ function VideoCanvasInner({
if (backgroundBlur > 0) {
c.filter = `blur(${backgroundBlur * 0.8}px)`;
const overflow = backgroundBlur * 2;
- c.drawImage(backgroundImage, -overflow, -overflow, canvasWidth + overflow * 2, canvasHeight + overflow * 2);
+ drawImageCover(c, backgroundImage, -overflow, -overflow, canvasWidth + overflow * 2, canvasHeight + overflow * 2);
} else {
- c.drawImage(backgroundImage, 0, 0, canvasWidth, canvasHeight);
+ drawImageCover(c, backgroundImage, 0, 0, canvasWidth, canvasHeight);
}
c.restore();
}
@@ -1329,7 +1337,7 @@ function VideoCanvasInner({
if (hasMockupLocal) {
const mBlur = SELF_SHADOWING_MOCKUPS.includes(mockupId) ? scaledShadowBlur : 0;
- const mr = drawMockupToCanvas(c, mockupId, mockupCfg, containerX, containerY, containerWidth, containerHeight, scaledRadius, mBlur, canvasWidth);
+ const mr = drawMockupToCanvas(c, mockupId, mockupCfg, containerX, containerY, containerWidth, containerHeight, scaledRadius, mBlur, canvasWidth, canvasHeight);
vX = mr.contentX;
vY = mr.contentY;
vW = mr.contentWidth;
@@ -1337,7 +1345,7 @@ function VideoCanvasInner({
vR = mockupId === "outline"
? scaledRadius * 1.6
: (mockupId === "iphone-slim" || mockupId === "glass-curve" || mockupId === "glass-full")
- ? scaledRadius * 6
+ ? scaledRadius * 2.5
: scaledRadius;
}
diff --git a/app/components/ui/editor/ZoomFragmentTrackItem.tsx b/app/components/ui/editor/ZoomFragmentTrackItem.tsx
index 7e0a010..097e6f9 100644
--- a/app/components/ui/editor/ZoomFragmentTrackItem.tsx
+++ b/app/components/ui/editor/ZoomFragmentTrackItem.tsx
@@ -178,8 +178,8 @@ export function ZoomFragmentTrackItem({
<motion.div
ref={containerRef}
className={`absolute h-[80%] top-[5%] rounded-md flex items-center border transition-shadow select-none ${isSelected || isInteracting
- ? 'bg-blue-500/30 border-blue-400/70 shadow-[0_0_10px_rgba(59,130,246,0.3)] z-10'
- : 'bg-blue-600/20 border-blue-500/35 hover:border-blue-500/60'
+ ? 'bg-blue-500/30 border-blue-400/70 shadow-[0_0_10px_rgba(59,130,246,0.3)] z-10'
+ : 'bg-blue-600/20 border-blue-500/35 hover:border-blue-500/60'
} ${isDragging ? 'cursor-grabbing' : 'cursor-grab'}`}
style={{
x: fragmentX,
@@ -230,9 +230,9 @@ export function ZoomFragmentTrackItem({
aria-valuenow={fragment.startTime}
tabIndex={0}
>
- <div className={`w-1 h-6 rounded rounded-md-full transition-all ${isResizing === 'start'
- ? 'bg-blue-300 scale-110'
- : 'bg-blue-400/60 group-hover/resize:bg-blue-300'
+ <div className={`w-1 h-6 rounded-full transition-all ${isResizing === 'start'
+ ? 'bg-blue-300 scale-110'
+ : 'bg-blue-400/60 group-hover/resize:bg-blue-300'
}`} />
</motion.div>
@@ -264,9 +264,9 @@ export function ZoomFragmentTrackItem({
aria-valuenow={fragment.endTime}
tabIndex={0}
>
- <div className={`w-1 h-6 rounded rounded-md-full transition-all ${isResizing === 'end'
- ? 'bg-blue-300 scale-110'
- : 'bg-blue-400/60 group-hover/resize:bg-blue-300'
+ <div className={`w-1 h-6 rounded-full transition-all ${isResizing === 'end'
+ ? 'bg-blue-300 scale-110'
+ : 'bg-blue-400/60 group-hover/resize:bg-blue-300'
}`} />
</motion.div>
</motion.div>
diff --git a/app/components/ui/editor/mockups/OutlineMockup.tsx b/app/components/ui/editor/mockups/OutlineMockup.tsx
index 5596fd2..e5c59c3 100644
--- a/app/components/ui/editor/mockups/OutlineMockup.tsx
+++ b/app/components/ui/editor/mockups/OutlineMockup.tsx
@@ -19,7 +19,7 @@ export function OutlineMockup({
const screenBg = isDark ? "#0a0a0a" : "#ffffff";
const frameColor = config.frameColor || (isDark ? "rgba(255, 255, 255, 0.2)" : "rgba(0, 0, 0, 0.15)");
- const offset = 12;
+ const offset = 8;
const innerRadius = cornerRadius * 2.5;
const outerRadius = innerRadius + offset;
diff --git a/lib/canvas.utils.ts b/lib/canvas.utils.ts
index 55e9faa..c11de3b 100644
--- a/lib/canvas.utils.ts
+++ b/lib/canvas.utils.ts
@@ -360,4 +360,33 @@ export function snapRotation(
return { angle: nearestSnap, snapped: true };
}
return { angle, snapped: false };
+}
+
+export function drawImageCover(
+ ctx: CanvasRenderingContext2D,
+ img: HTMLImageElement,
+ dx: number, dy: number, dWidth: number, dHeight: number
+) {
+ const imgW = img.naturalWidth || img.width;
+ const imgH = img.naturalHeight || img.height;
+ if (!imgW || !imgH || dWidth <= 0 || dHeight <= 0) return;
+
+ const imgAspect = imgW / imgH;
+ const destAspect = dWidth / dHeight;
+
+ let sx: number, sy: number, sWidth: number, sHeight: number;
+
+ if (imgAspect > destAspect) {
+ sHeight = imgH;
+ sWidth = imgH * destAspect;
+ sx = (imgW - sWidth) / 2;
+ sy = 0;
+ } else {
+ sWidth = imgW;
+ sHeight = imgW / destAspect;
+ sx = 0;
+ sy = (imgH - sHeight) / 2;
+ }
+
+ ctx.drawImage(img, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight);
}
\ No newline at end of file
diff --git a/lib/mockup-canvas.utils.ts b/lib/mockup-canvas.utils.ts
index a8cadc4..a12ba1f 100644
--- a/lib/mockup-canvas.utils.ts
+++ b/lib/mockup-canvas.utils.ts
@@ -38,17 +38,16 @@ export function drawMockupToCanvas(
ctx: CanvasRenderingContext2D,
mockupId: string,
config: MockupConfig,
- x: number,
- y: number,
- width: number,
- height: number,
+ x: number, y: number, width: number, height: number,
cornerRadius: number,
shadowBlur: number = 0,
- canvasWidth: number = 1920
+ canvasWidth: number = 1920,
+ canvasHeight: number = 1080
): MockupDrawResult {
// Important: all mockup calculations are done in a 1280x720 space to maintain proportions, then scaled to the actual canvas size. This ensures the mockup design stays consistent regardless of canvas size or export resolution.
- const scale = (canvasWidth / 1280) * 1.2;
+ const canvasLongSide = Math.max(canvasWidth, canvasHeight);
+ const scale = (canvasLongSide / 1280) * 1.2;
ctx.save();
ctx.scale(scale, scale);
diff --git a/lib/mockup-canvas/glass-curve.ts b/lib/mockup-canvas/glass-curve.ts
index 99c12d4..a3294f1 100644
--- a/lib/mockup-canvas/glass-curve.ts
+++ b/lib/mockup-canvas/glass-curve.ts
@@ -10,20 +10,21 @@ export function drawGlassCurveMockup(context: MockupCanvasContext): MockupDrawRe
const headerOpacity = config.headerOpacity ?? 10;
const headerScale = (config.headerScale || 100) / 100;
- const framePadding = 24 * headerScale;
+ // Valores corregidos para igualar al componente GlassCurveMockup (Preview)
+ const framePadding = 4 * headerScale;
const reflectionWidth = 16 * headerScale;
-
- const notchTop = 28 * headerScale;
- const notchWidth = 120 * headerScale;
- const notchHeight = 12 * headerScale;
- const contentPaddingTop = 90 * headerScale;
+ const notchTop = 16 * headerScale;
+ const notchWidth = 40 * headerScale;
+ const notchHeight = 4 * headerScale;
+ const contentPaddingTop = 32 * headerScale;
const screenBg = isDark ? "#0a0a0a" : "#ffffff";
const borderColor = isDark ? "rgba(255, 255, 255, 0.1)" : "rgba(255, 255, 255, 0.4)";
const reflectionColor = isDark ? "rgba(255, 255, 255, 0.05)" : "rgba(255, 255, 255, 0.2)";
const notchBg = isDark ? "rgba(255, 255, 255, 0.15)" : "rgba(0, 0, 0, 0.05)";
- const outerRadius = cornerRadius * 8;
+ // Radio exterior corregido (antes multiplicaba * 8, ahora * 2.5 igual que en CSS)
+ const outerRadius = cornerRadius * 2.5;
drawMockupShadow(ctx, x, y, width, height, outerRadius, shadowBlur);
@@ -31,11 +32,13 @@ export function drawGlassCurveMockup(context: MockupCanvasContext): MockupDrawRe
drawRoundedRectPath(ctx, x, y, width, height, outerRadius);
ctx.fillStyle = hexToRgba(frameColor, headerOpacity);
ctx.fill();
+
ctx.strokeStyle = borderColor;
- ctx.lineWidth = 6;
+ // Ancho del borde corregido (antes 6, ahora 3 igual que en CSS)
+ ctx.lineWidth = 3;
ctx.stroke();
-
ctx.clip();
+
const leftGradient = ctx.createLinearGradient(x, y, x + reflectionWidth, y);
leftGradient.addColorStop(0, reflectionColor);
leftGradient.addColorStop(1, "rgba(255, 255, 255, 0)");
@@ -47,13 +50,16 @@ export function drawGlassCurveMockup(context: MockupCanvasContext): MockupDrawRe
rightGradient.addColorStop(1, "rgba(255, 255, 255, 0)");
ctx.fillStyle = rightGradient;
ctx.fillRect(x + width - reflectionWidth, y, reflectionWidth, height);
+
ctx.restore();
const screenX = x + framePadding;
const screenY = y + framePadding;
const screenWidth = width - framePadding * 2;
const screenHeight = height - framePadding * 2;
- const innerRadius = Math.max(0, outerRadius - framePadding);
+
+ // Radio interior ajustado al CSS (antes se calculaba diferente, ahora es * 2.35)
+ const innerRadius = cornerRadius * 2.35;
ctx.save();
drawRoundedRectPath(ctx, screenX, screenY, screenWidth, screenHeight, innerRadius);
diff --git a/lib/mockup-canvas/outline.ts b/lib/mockup-canvas/outline.ts
index 6c0fbf0..fcf269e 100644
--- a/lib/mockup-canvas/outline.ts
+++ b/lib/mockup-canvas/outline.ts
@@ -6,11 +6,10 @@ export function drawOutlineMockup(context: MockupCanvasContext): MockupDrawResul
const isDark = config.darkMode;
const screenBg = isDark ? "#0a0a0a" : "#ffffff";
-
const frameColor = config.frameColor || (isDark ? "rgba(255, 255, 255, 0.2)" : "rgba(0, 0, 0, 0.15)");
- const offset = 12;
- const innerRadius = cornerRadius * 1.5;
+ const offset = 8;
+ const innerRadius = cornerRadius * 1.5;
const outerRadius = innerRadius + offset;
ctx.save();
diff --git a/public/images/metadata/preview-openvid.jpg b/public/images/metadata/preview-openvid.jpg
index 41c24f0..446feab 100644
Binary files a/public/images/metadata/preview-openvid.jpg and b/public/images/metadata/preview-openvid.jpg differ
diff --git a/types/editor.types.ts b/types/editor.types.ts
index 6b4f82d..c827fe3 100644
--- a/types/editor.types.ts
+++ b/types/editor.types.ts
@@ -124,4 +124,6 @@ export interface VideoCanvasProps {
isPlaying?: boolean;
onMockupClick?: (kind: "2d" | "3d") => void;
isRestoringProjectRef?: React.MutableRefObject<boolean>;
+ activeMediaAspect?: number | null;
+ activeClipUrl?: string | null;
}
\ No newline at end of file
diff --git a/types/timeline.types.ts b/types/timeline.types.ts
index 00d86e8..7038519 100644
--- a/types/timeline.types.ts
+++ b/types/timeline.types.ts
@@ -28,7 +28,7 @@ export interface TimelineProps {
zoomFragments?: ZoomFragment[];
selectedZoomFragmentId?: string | null;
onSelectZoomFragment?: (fragmentId: string | null) => void;
- onAddZoomFragment?: (startTime: number) => void;
+ onAddZoomFragment?: (startTime: number, endTime: number) => void;
onUpdateZoomFragment?: (fragmentId: string, updates: Partial<ZoomFragment>) => void;
onActivateZoomTool?: () => void;
// Audio props
diff --git a/types/video-track.types.ts b/types/video-track.types.ts
index 777cce8..b48f3cf 100644
--- a/types/video-track.types.ts
+++ b/types/video-track.types.ts
@@ -8,6 +8,8 @@ export interface VideoTrackClip {
trimEnd: number;
thumbnailUrl?: string;
hasCamera?: boolean;
+ width?: number;
+ height?: number;
}
export const MIN_CLIP_DURATION = 0.1;