Skip to content

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

feat: enhance video editing features with speed control and UI improvements

CristianOlivera1aae79dbd53df
diff --git a/app/components/ui/editor/AudioFragmentTrackItem.tsx b/app/components/ui/editor/AudioFragmentTrackItem.tsx
index f1aab88..d2080fe 100644
--- a/app/components/ui/editor/AudioFragmentTrackItem.tsx
+++ b/app/components/ui/editor/AudioFragmentTrackItem.tsx
@@ -1,5 +1,4 @@
"use client";
-
import { useState, useRef, useCallback, useMemo, useEffect } from "react";
import { motion, useMotionValue } from "framer-motion";
import { AudioFragmentTrackItemProps, MIN_FRAGMENT_DURATION, MIN_VISUAL_WIDTH_PX } from "@/types/audio.types";
@@ -10,17 +9,18 @@ export function AudioFragmentTrackItem({
isSelected,
contentWidth,
videoDuration,
+ contentDuration,
otherTracks,
onSelect,
onUpdate,
onDragStateChange,
onMouseEnter,
onMouseLeave,
+ speed = 1,
}: AudioFragmentTrackItemProps) {
const [isDragging, setIsDragging] = useState(false);
const [isResizing, setIsResizing] = useState<'start' | 'end' | null>(null);
const containerRef = useRef<HTMLDivElement>(null);
-
const fragmentX = useMotionValue(0);
const fragmentWidth = useMotionValue(0);
@@ -34,7 +34,6 @@ export function AudioFragmentTrackItem({
const initialLeft = timeToPixels(track.startTime);
const initialWidth = timeToPixels(track.duration);
-
const visualWidth = Math.max(initialWidth, MIN_VISUAL_WIDTH_PX);
useEffect(() => {
@@ -50,7 +49,7 @@ export function AudioFragmentTrackItem({
.sort((a, b) => a.startTime - b.startTime);
let minStart = 0;
- let maxEnd = videoDuration;
+ let maxEnd = contentDuration ?? videoDuration;
for (const other of sorted) {
const otherEnd = other.startTime + other.duration;
@@ -64,21 +63,16 @@ export function AudioFragmentTrackItem({
break;
}
}
-
return { minStart, maxEnd };
- }, [otherTracks, track.id, track.startTime, track.duration, videoDuration]);
+ }, [otherTracks, track.id, track.startTime, track.duration, videoDuration, contentDuration]);
- // ── Drag (mover fragmento completo) ──────────────────────────────
const handleDrag = useCallback((_e: MouseEvent | TouchEvent | PointerEvent, info: { delta: { x: number } }) => {
if (contentWidth === 0 || videoDuration === 0) return;
-
const currentX = fragmentX.get();
let newX = currentX + info.delta.x;
-
const minX = timeToPixels(boundaries.minStart);
const maxX = timeToPixels(boundaries.maxEnd - track.duration);
newX = Math.max(minX, Math.min(maxX, newX));
-
fragmentX.set(newX);
}, [contentWidth, videoDuration, fragmentX, track.duration, boundaries, timeToPixels]);
@@ -90,23 +84,20 @@ export function AudioFragmentTrackItem({
const handleDragEnd = useCallback(() => {
setIsDragging(false);
onDragStateChange?.(false);
-
const newStartTime = pixelsToTime(fragmentX.get());
onUpdate({
- startTime: Math.max(0, Math.min(videoDuration - track.duration, newStartTime)),
+ startTime: Math.max(0, Math.min((contentDuration ?? videoDuration) - track.duration, newStartTime)),
});
- }, [fragmentX, pixelsToTime, track.duration, videoDuration, onUpdate, onDragStateChange]);
+ }, [fragmentX, pixelsToTime, track.duration, videoDuration, contentDuration, onUpdate, onDragStateChange]);
const handleResizeStartDrag = useCallback((_e: MouseEvent | TouchEvent | PointerEvent, info: { delta: { x: number } }) => {
if (contentWidth === 0 || videoDuration === 0) return;
-
const currentX = fragmentX.get();
const currentWidth = fragmentWidth.get();
-
let newX = currentX + info.delta.x;
let newWidth = currentWidth - info.delta.x;
-
const minWidth = timeToPixels(MIN_FRAGMENT_DURATION);
+
if (newWidth < minWidth) {
newWidth = minWidth;
newX = currentX + currentWidth - minWidth;
@@ -126,28 +117,24 @@ export function AudioFragmentTrackItem({
newWidth = maxWidth;
}
}
-
fragmentX.set(newX);
fragmentWidth.set(newWidth);
}, [contentWidth, videoDuration, fragmentX, fragmentWidth, boundaries, timeToPixels, audio]);
const handleResizeEndDrag = useCallback((_e: MouseEvent | TouchEvent | PointerEvent, info: { delta: { x: number } }) => {
if (contentWidth === 0 || videoDuration === 0) return;
-
const currentX = fragmentX.get();
const currentWidth = fragmentWidth.get();
let newWidth = currentWidth + info.delta.x;
-
const minWidth = timeToPixels(MIN_FRAGMENT_DURATION);
+
newWidth = Math.max(minWidth, newWidth);
-
const maxWidth = timeToPixels(boundaries.maxEnd) - currentX;
newWidth = Math.min(newWidth, maxWidth);
if (audio) {
newWidth = Math.min(newWidth, timeToPixels(audio.duration));
}
-
fragmentWidth.set(newWidth);
}, [contentWidth, videoDuration, fragmentWidth, fragmentX, boundaries, timeToPixels, audio]);
@@ -159,80 +146,116 @@ export function AudioFragmentTrackItem({
const handleResizeEnd = useCallback(() => {
setIsResizing(null);
onDragStateChange?.(false);
-
const newStartTime = pixelsToTime(fragmentX.get());
const newDuration = pixelsToTime(fragmentWidth.get());
-
+
onUpdate({
startTime: Math.max(0, newStartTime),
- duration: Math.min(audio?.duration ?? videoDuration, newDuration),
+ duration: Math.min(audio?.duration ?? contentDuration ?? videoDuration, newDuration),
});
- }, [fragmentX, fragmentWidth, pixelsToTime, audio, videoDuration, onUpdate, onDragStateChange]);
+ }, [fragmentX, fragmentWidth, pixelsToTime, audio, videoDuration, contentDuration, onUpdate, onDragStateChange]);
const isInteracting = isDragging || isResizing !== null;
- const [isHovered, setIsHovered] = useState(false);
return (
<motion.div
ref={containerRef}
- className={`absolute top-1/2 -translate-y-1/2 h-1.5 rounded-full cursor-grab active:cursor-grabbing transition-colors ${isSelected
- ? 'bg-white shadow-[0_0_15px_rgba(255,255,255,0.5)] z-10'
- : 'bg-white/20 backdrop-blur-sm border border-white/10 hover:bg-white/30'
- } ${isInteracting ? 'z-10' : 'z-0'}`}
- style={{ x: fragmentX, width: fragmentWidth }}
+ className={`absolute h-[90%] top-[5%] rounded-md flex items-center border transition-shadow select-none
+ ${isSelected || isInteracting
+ ? 'bg-violet-500/30 border-violet-400/70 shadow-[0_0_10px_rgba(139,92,246,0.3)] z-10'
+ : 'bg-violet-600/20 border-violet-500/35 hover:border-violet-500/60'
+ } ${isDragging ? 'cursor-grabbing' : 'cursor-grab'}`}
+ style={{
+ x: fragmentX,
+ width: fragmentWidth,
+ background: isSelected || isInteracting
+ ? 'linear-gradient(180deg, rgba(139, 92, 246, 0.5) 0%, rgba(109, 40, 217, 0.4) 100%)'
+ : 'linear-gradient(180deg, rgba(124, 58, 237, 0.2) 0%, rgba(91, 33, 182, 0.15) 100%)',
+ boxShadow: isSelected || isInteracting
+ ? 'inset 0 1px 0 rgba(255,255,255,0.3), 0 0 10px rgba(139,92,246,0.3)'
+ : 'inset 0 1px 0 rgba(255,255,255,0.1)'
+ }}
drag="x"
- dragConstraints={{ left: 0, right: contentWidth }}
+ dragConstraints={{ left: 0, right: contentWidth / speed }}
dragElastic={0}
dragMomentum={false}
onDrag={handleDrag}
onDragStart={handleDragStart}
onDragEnd={handleDragEnd}
- onHoverStart={() => setIsHovered(true)}
- onHoverEnd={() => setIsHovered(false)}
- onClick={(e) => { e.stopPropagation(); onSelect(); }}
+ onClick={(e) => {
+ e.stopPropagation();
+ onSelect();
+ }}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
+ whileTap={{ scale: 0.98 }}
+ role="slider"
+ aria-valuemin={0}
+ aria-valuemax={contentDuration ?? videoDuration}
+ aria-valuenow={track.startTime}
+ aria-label={`Audio fragment ${(track.duration / speed).toFixed(1)}s`}
+ tabIndex={0}
>
- <div className="absolute inset-0 flex items-center justify-center pointer-events-none">
- <div className={`flex items-center gap-[1.5px] px-1.5 h-full ${isSelected ? 'bg-white' : ''}`}>
- <div className={`w-[1.5px] h-2 rounded-full ${isSelected ? 'bg-sky-400' : 'bg-white/60'}`} />
- <div className={`w-[1.5px] h-3 rounded-full ${isSelected ? 'bg-sky-400' : 'bg-white/60'}`} />
- <div className={`w-[1.5px] h-1.5 rounded-full ${isSelected ? 'bg-sky-400' : 'bg-white/60'}`} />
- </div>
- </div>
-
<motion.div
- className="absolute left-0 top-1/2 -translate-y-1/2 w-2 h-3 cursor-ew-resize z-20 flex items-center justify-center"
- animate={{ opacity: isHovered || isResizing === 'start' ? 1 : 0 }}
- transition={{ duration: 0.15 }}
+ className="absolute left-0 top-0 bottom-0 w-2 cursor-ew-resize z-20 group/resize flex items-center justify-center"
drag="x"
dragConstraints={{ left: 0, right: 0 }}
dragElastic={0}
dragMomentum={false}
onDrag={handleResizeStartDrag}
- onDragStart={(e) => { e.stopPropagation(); handleResizeStart('start'); }}
+ onDragStart={() => handleResizeStart('start')}
onDragEnd={handleResizeEnd}
onClick={(e) => e.stopPropagation()}
+ role="slider"
+ aria-label="Resize start"
+ aria-valuemin={0}
+ aria-valuemax={contentDuration ?? videoDuration}
+ aria-valuenow={track.startTime}
+ tabIndex={0}
>
- <div className="w-1 h-4 bg-white rounded-full shadow-sm border border-gray-200" />
+ <div
+ className={`w-1 h-6 rounded-full transition-all ${
+ isResizing === 'start'
+ ? 'bg-violet-300 scale-110'
+ : 'bg-violet-400/60 group-hover/resize:bg-violet-300'
+ }`}
+ />
</motion.div>
+ <div className="flex-1 flex flex-col items-center justify-center pointer-events-none overflow-hidden px-2">
+ <span className={`text-[11px] truncate ${isSelected || isInteracting ? 'text-violet-200' : 'text-violet-300/70'}`}>
+ Audio
+ </span>
+ <span className={`text-[9px] truncate ${isSelected || isInteracting ? 'text-violet-300/70' : 'text-violet-400/45'}`}>
+ {(track.duration / speed).toFixed(1)}s
+ </span>
+ </div>
+
<motion.div
- className="absolute right-0 top-1/2 -translate-y-1/2 w-2 h-3 cursor-ew-resize z-20 flex items-center justify-center"
- animate={{ opacity: isHovered || isResizing === 'end' ? 1 : 0 }}
- transition={{ duration: 0.15 }}
+ className="absolute right-0 top-0 bottom-0 w-2 cursor-ew-resize z-20 group/resize flex items-center justify-center"
drag="x"
dragConstraints={{ left: 0, right: 0 }}
dragElastic={0}
dragMomentum={false}
onDrag={handleResizeEndDrag}
- onDragStart={(e) => { e.stopPropagation(); handleResizeStart('end'); }}
+ onDragStart={() => handleResizeStart('end')}
onDragEnd={handleResizeEnd}
onClick={(e) => e.stopPropagation()}
+ role="slider"
+ aria-label="Resize end"
+ aria-valuemin={0}
+ aria-valuemax={contentDuration ?? videoDuration}
+ aria-valuenow={track.startTime + track.duration}
+ tabIndex={0}
>
- <div className="w-1 h-4 bg-white rounded-full shadow-sm border border-gray-200" />
+ <div
+ className={`w-1 h-6 rounded-full transition-all ${
+ isResizing === 'end'
+ ? 'bg-violet-300 scale-110'
+ : 'bg-violet-400/60 group-hover/resize:bg-violet-300'
+ }`}
+ />
</motion.div>
</motion.div>
-
);
}
\ No newline at end of file
diff --git a/app/components/ui/editor/ControlPanel.tsx b/app/components/ui/editor/ControlPanel.tsx
index 4909f79..e4a6908 100644
--- a/app/components/ui/editor/ControlPanel.tsx
+++ b/app/components/ui/editor/ControlPanel.tsx
@@ -133,6 +133,8 @@ export function ControlPanel({
onDeleteImageProject,
onUploadImageToHistory,
mediaType = "video",
+ globalSpeed = 1,
+ onGlobalSpeedChange,
}: ExtendedControlPanelProps) {
const t = useTranslations("controlPanel");
@@ -153,7 +155,7 @@ export function ControlPanel({
<TooltipAction label={t("header.close")} side="right">
<motion.button
onClick={onTogglePanel}
- className="p-2 rounded-lg text-white/60 hover:text-white hover:bg-white/5 transition-all duration-200"
+ className="p-2 rounded-lg text-white/70 hover:text-white hover:bg-white/5 transition-all duration-200"
whileHover={{ scale: 1.1 }}
whileTap={{ scale: 0.9 }}
aria-label={t("header.close")}
@@ -200,7 +202,7 @@ export function ControlPanel({
<Suspense fallback={<WallpaperSkeleton />}>
<div className="flex flex-col gap-5">
<div>
- <div className="text-[10px] uppercase tracking-widest text-white/60 font-bold mb-2 flex items-center gap-1.5">
+ <div className="text-[11px] uppercase tracking-widest text-white/70 font-bold mb-2 flex items-center gap-1.5">
<span>{t("screenshot.options")}</span>
</div>
<OptionsGrid
@@ -322,6 +324,8 @@ export function ControlPanel({
refreshTrigger={videosLibraryRefresh}
isUploading={isVideoUploading}
onVideoAudioToggle={onVideoAudioToggle}
+ globalSpeed={globalSpeed}
+ onGlobalSpeedChange={onGlobalSpeedChange}
/>
</Suspense>
)}
diff --git a/app/components/ui/editor/PlayerControls.tsx b/app/components/ui/editor/PlayerControls.tsx
index 7943f43..741ae74 100644
--- a/app/components/ui/editor/PlayerControls.tsx
+++ b/app/components/ui/editor/PlayerControls.tsx
@@ -171,7 +171,7 @@ export function PlayerControls({
</button>
</TooltipAction>
- <span className="text-[10px] font-mono text-zinc-500 min-w-5" aria-live="polite" aria-atomic="true">
+ <span className="text-[11px] font-mono text-zinc-500 min-w-5" aria-live="polite" aria-atomic="true">
{Math.round(zoomLevel)}×
</span>
</div>
diff --git a/app/components/ui/editor/Timeline.tsx b/app/components/ui/editor/Timeline.tsx
index 88a3845..e4df839 100644
--- a/app/components/ui/editor/Timeline.tsx
+++ b/app/components/ui/editor/Timeline.tsx
@@ -1,5 +1,4 @@
"use client";
-
import { useRef, useMemo, useCallback, useEffect, useState } from "react";
import { motion, useMotionValue, useTransform, animate, PanInfo } from "framer-motion";
import { formatTime, getZoomMultiplier } from "@/lib/video.utils";
@@ -41,9 +40,11 @@ export function Timeline({
selectedAudioTrackId,
onSelectAudioTrack,
onUpdateAudioTrack,
+ globalSpeed = 1,
+ isPlaying = false,
+ onZoomChange,
}: TimelineProps) {
const t = useTranslations("timeline");
-
const trackRef = useRef<HTMLDivElement>(null);
const containerRef = useRef<HTMLDivElement>(null);
const [trackWidth, setTrackWidth] = useState(0);
@@ -52,7 +53,6 @@ export function Timeline({
const [isDraggingZoomFragment, setIsDraggingZoomFragment] = useState(false);
const [isDraggingVideoClip, setIsDraggingVideoClip] = useState(false);
const [isOverFragment, setIsOverFragment] = useState(false);
-
const pendingSeekRef = useRef<number | null>(null);
const rafIdRef = useRef<number | null>(null);
const isSeekingRef = useRef<boolean>(false);
@@ -70,8 +70,10 @@ export function Timeline({
return Number.isFinite(videoDuration) && videoDuration > 0 ? videoDuration : 0;
}, [videoDuration, videoClips]);
+ const speed = globalSpeed && globalSpeed > 0 ? globalSpeed : 1;
+ const scaledDuration = validDuration * speed;
+ const outputDuration = validDuration / speed;
const pendingTrimRef = useRef<{ start: number; end: number } | null>(null);
-
const TRACK_PADDING = 0;
const contentWidth = useMemo(() => {
@@ -80,16 +82,23 @@ export function Timeline({
return availableWidth * getZoomMultiplier(zoomLevel);
}, [trackWidth, zoomLevel]);
+ const timelineWidth = useMemo(() => {
+ return speed > 0 ? contentWidth / speed : contentWidth;
+ }, [contentWidth, speed]);
+
const playheadX = useMotionValue(0);
const trimStartX = useMotionValue(0);
const trimEndX = useMotionValue(0);
const contentWidthMotion = useMotionValue(0);
+ const timelineWidthMotion = useMotionValue(0);
const validDurationMotion = useMotionValue(0);
useEffect(() => {
contentWidthMotion.set(contentWidth);
}, [contentWidth, contentWidthMotion]);
-
+ useEffect(() => {
+ timelineWidthMotion.set(timelineWidth);
+ }, [timelineWidth, timelineWidthMotion]);
useEffect(() => {
validDurationMotion.set(validDuration);
}, [validDuration, validDurationMotion]);
@@ -103,15 +112,16 @@ export function Timeline({
return `${prefix} · ${formatTime(secs)}`;
}
);
+
const trimStartPosition = useMemo(() => {
- if (validDuration === 0 || contentWidth === 0) return 0;
- return (trimRange.start / validDuration) * contentWidth;
- }, [trimRange.start, validDuration, contentWidth]);
+ if (scaledDuration === 0 || contentWidth === 0) return 0;
+ return (trimRange.start / scaledDuration) * contentWidth;
+ }, [trimRange.start, scaledDuration, contentWidth]);
const trimEndPosition = useMemo(() => {
- if (validDuration === 0 || contentWidth === 0) return contentWidth;
- return (trimRange.end / validDuration) * contentWidth;
- }, [trimRange.end, validDuration, contentWidth]);
+ if (scaledDuration === 0 || contentWidth === 0) return contentWidth;
+ return (trimRange.end / scaledDuration) * contentWidth;
+ }, [trimRange.end, scaledDuration, contentWidth]);
useEffect(() => {
if (!isDraggingTrim) {
@@ -121,9 +131,9 @@ export function Timeline({
}, [trimStartPosition, trimEndPosition, isDraggingTrim, trimStartX, trimEndX]);
const playheadPosition = useMemo(() => {
- if (validDuration === 0 || contentWidth === 0) return 0;
- return (currentTime / validDuration) * contentWidth;
- }, [currentTime, validDuration, contentWidth]);
+ if (scaledDuration === 0 || contentWidth === 0) return 0;
+ return (currentTime / scaledDuration) * contentWidth;
+ }, [currentTime, scaledDuration, contentWidth]);
useEffect(() => {
const updateTrackWidth = () => {
@@ -131,7 +141,6 @@ export function Timeline({
setTrackWidth(containerRef.current.clientWidth - 12 - TIMELINE_LABEL_WIDTH - 5);
}
};
-
updateTrackWidth();
window.addEventListener("resize", updateTrackWidth);
return () => window.removeEventListener("resize", updateTrackWidth);
@@ -139,11 +148,7 @@ export function Timeline({
useEffect(() => {
if (!isDragging && !isDraggingPlayhead) {
- animate(playheadX, playheadPosition, {
- type: "tween",
- duration: 0.05,
- ease: "linear"
- });
+ animate(playheadX, playheadPosition, { type: "tween", duration: 0.05, ease: "linear" });
}
}, [playheadPosition, isDragging, isDraggingPlayhead, playheadX]);
@@ -156,42 +161,37 @@ export function Timeline({
}, []);
const timeMarkers = useMemo(() => {
- if (validDuration === 0) return [];
- const baseInterval = validDuration / 6;
+ if (outputDuration === 0 || validDuration === 0) return [];
+ const baseInterval = outputDuration / 6;
const adjustedInterval = baseInterval / Math.sqrt(getZoomMultiplier(zoomLevel));
- const markerCount = Math.ceil(validDuration / adjustedInterval) + 1;
+ const markerCount = Math.ceil(outputDuration / adjustedInterval) + 1;
return Array.from({ length: Math.min(markerCount, 50) }, (_, i) => ({
time: adjustedInterval * i,
position: (adjustedInterval * i / validDuration) * contentWidth
- })).filter(m => m.time <= validDuration);
- }, [validDuration, zoomLevel, contentWidth]);
+ })).filter(m => m.time <= outputDuration);
+ }, [outputDuration, validDuration, zoomLevel, contentWidth]);
const handleTrackClick = useCallback((e: React.MouseEvent<HTMLDivElement>) => {
if (isDragging || isDraggingTrim) return;
const rect = e.currentTarget.getBoundingClientRect();
const scrollLeft = e.currentTarget.scrollLeft;
const clickX = e.clientX - rect.left + scrollLeft;
- if (clickX >= 0 && contentWidth > 0) {
- const percentage = Math.max(0, Math.min(1, clickX / contentWidth));
- const newTime = percentage * validDuration;
- const clampedTime = Math.max(trimRange.start, Math.min(trimRange.end, newTime));
+ if (clickX >= 0 && contentWidth > 0 && scaledDuration > 0) {
+ const rawTime = (clickX / contentWidth) * scaledDuration;
+ const boundedTime = Math.max(0, Math.min(validDuration, rawTime));
+ const clampedTime = Math.max(trimRange.start, Math.min(trimRange.end, boundedTime));
onSeek(clampedTime);
}
- }, [contentWidth, validDuration, onSeek, isDragging, isDraggingTrim, trimRange]);
+ }, [contentWidth, scaledDuration, validDuration, onSeek, isDragging, isDraggingTrim, trimRange]);
const handleDrag = useCallback((_: MouseEvent | TouchEvent | PointerEvent, info: PanInfo) => {
- if (contentWidth === 0 || validDuration === 0) return;
-
- const maxX = videoClips.length > 0 ? contentWidth : trimEndPosition;
+ if (contentWidth === 0 || scaledDuration === 0) return;
+ const maxX = videoClips.length > 0 ? timelineWidth : trimEndPosition;
const minX = videoClips.length > 0 ? 0 : trimStartPosition;
-
const newX = Math.max(minX, Math.min(maxX, playheadX.get() + info.delta.x));
playheadX.set(newX);
-
- const newTime = (newX / contentWidth) * validDuration;
-
+ const newTime = (newX / contentWidth) * scaledDuration;
pendingSeekRef.current = newTime;
-
if (!isSeekingRef.current) {
isSeekingRef.current = true;
rafIdRef.current = requestAnimationFrame(() => {
@@ -201,7 +201,7 @@ export function Timeline({
isSeekingRef.current = false;
});
}
- }, [contentWidth, validDuration, onSeek, playheadX, trimStartPosition, trimEndPosition, videoClips]);
+ }, [contentWidth, scaledDuration, timelineWidth, onSeek, playheadX, trimStartPosition, trimEndPosition, videoClips]);
const handleDragStart = useCallback(() => {
setIsDragging(true);
@@ -225,24 +225,29 @@ export function Timeline({
}, [onDragEnd, onSeek]);
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));
+ if (contentWidth === 0 || scaledDuration === 0) return;
+ const newX = Math.max(0, Math.min(
+ trimEndX.get() - (MIN_TRIM_DURATION / scaledDuration) * contentWidth,
+ trimStartX.get() + info.delta.x
+ ));
trimStartX.set(newX);
-
- const newStartTime = (newX / contentWidth) * validDuration;
+ const newStartTime = (newX / contentWidth) * scaledDuration;
pendingTrimRef.current = { start: Math.max(0, newStartTime), end: trimRange.end };
- }, [contentWidth, validDuration, trimStartX, trimEndX, trimRange.end]);
+ }, [contentWidth, scaledDuration, trimStartX, trimEndX, trimRange.end]);
const handleTrimEndDrag = useCallback((_: MouseEvent | TouchEvent | PointerEvent, info: PanInfo) => {
- if (contentWidth === 0 || validDuration === 0) return;
-
- const newX = Math.min(contentWidth, Math.max(trimStartX.get() + (MIN_TRIM_DURATION / validDuration) * contentWidth, trimEndX.get() + info.delta.x));
+ if (contentWidth === 0 || scaledDuration === 0) return;
+ const newX = Math.min(
+ timelineWidth,
+ Math.max(
+ trimStartX.get() + (MIN_TRIM_DURATION / scaledDuration) * contentWidth,
+ trimEndX.get() + info.delta.x
+ )
+ );
trimEndX.set(newX);
-
- const newEndTime = (newX / contentWidth) * validDuration;
+ const newEndTime = (newX / contentWidth) * scaledDuration;
pendingTrimRef.current = { start: trimRange.start, end: Math.min(validDuration, newEndTime) };
- }, [contentWidth, validDuration, trimStartX, trimEndX, trimRange.start]);
+ }, [contentWidth, scaledDuration, timelineWidth, validDuration, trimStartX, trimEndX, trimRange.start]);
const handleTrimDragStart = useCallback((handle: 'start' | 'end') => {
setIsDraggingTrim(handle);
@@ -251,33 +256,54 @@ export function Timeline({
const handleTrimDragEnd = useCallback(() => {
setIsDraggingTrim(null);
-
if (pendingTrimRef.current) {
onTrimChange(pendingTrimRef.current);
-
if (currentTime < pendingTrimRef.current.start) {
onSeek(pendingTrimRef.current.start);
} else if (currentTime > pendingTrimRef.current.end) {
onSeek(pendingTrimRef.current.end);
}
-
pendingTrimRef.current = null;
}
}, [onTrimChange, currentTime, onSeek]);
useEffect(() => {
- if (!containerRef.current || isDragging) return;
- const scrollableArea = containerRef.current.querySelector('[data-scrollable]') as HTMLDivElement;
- if (!scrollableArea) return;
- const visibleWidth = scrollableArea.clientWidth;
- const scrollLeft = scrollableArea.scrollLeft;
- const margin = 100;
+ const scrollEl = trackRef.current;
+ if (!scrollEl) return;
+ if (isDragging || isDraggingTrim || isDraggingPlayhead) return;
+ const visibleWidth = scrollEl.clientWidth;
+ const scrollLeft = scrollEl.scrollLeft;
+ const margin = 120;
if (playheadPosition < scrollLeft + margin) {
- scrollableArea.scrollTo({ left: Math.max(0, playheadPosition - margin), behavior: 'smooth' });
+ scrollEl.scrollTo({ left: Math.max(0, playheadPosition - margin), behavior: isPlaying ? 'auto' : 'smooth' });
} else if (playheadPosition > scrollLeft + visibleWidth - margin) {
- scrollableArea.scrollTo({ left: playheadPosition - visibleWidth + margin, behavior: 'smooth' });
+ scrollEl.scrollTo({ left: playheadPosition - visibleWidth + margin, behavior: isPlaying ? 'auto' : 'smooth' });
}
- }, [playheadPosition, isDragging]);
+ }, [playheadPosition, isDragging, isDraggingTrim, isDraggingPlayhead, isPlaying]);
+
+ useEffect(() => {
+ const scrollEl = trackRef.current;
+ const isEdgeDragActive = isDragging || isDraggingTrim !== null;
+ if (!scrollEl || !isEdgeDragActive) return;
+ const EDGE_ZONE = 60;
+ const MAX_PAN_SPEED = 16;
+ let rafId: number;
+ const tick = () => {
+ const activeX = isDraggingTrim === 'start' ? trimStartX.get() : isDraggingTrim === 'end' ? trimEndX.get() : playheadX.get();
+ const visibleWidth = scrollEl.clientWidth;
+ const scrollLeft = scrollEl.scrollLeft;
+ if (activeX < scrollLeft + EDGE_ZONE) {
+ const intensity = Math.min(1, (scrollLeft + EDGE_ZONE - activeX) / EDGE_ZONE);
+ scrollEl.scrollLeft = Math.max(0, scrollLeft - MAX_PAN_SPEED * intensity);
+ } else if (activeX > scrollLeft + visibleWidth - EDGE_ZONE) {
+ const intensity = Math.min(1, (activeX - (scrollLeft + visibleWidth - EDGE_ZONE)) / EDGE_ZONE);
+ scrollEl.scrollLeft = scrollLeft + MAX_PAN_SPEED * intensity;
+ }
+ rafId = requestAnimationFrame(tick);
+ };
+ rafId = requestAnimationFrame(tick);
+ return () => cancelAnimationFrame(rafId);
+ }, [isDragging, isDraggingTrim, playheadX, trimStartX, trimEndX]);
const calculateProgressWidth = useCallback(([px, start, end]: number[]) => {
const width = end - start;
@@ -296,11 +322,12 @@ export function Timeline({
[trimStartX, trimEndX] as const,
([start, end]: number[]) => Math.max(end - start, 20)
);
+
const trimOverlayLeftWidth = useTransform(trimStartX, (x) => x);
const trimOverlayRightLeft = useTransform(trimEndX, (x) => x);
const trimOverlayRightWidth = useTransform(
- [trimEndX, contentWidthMotion] as const,
- ([end, cw]: number[]) => cw - end
+ [trimEndX, timelineWidthMotion] as const,
+ ([end, tw]: number[]) => tw - end
);
useEffect(() => {
@@ -312,9 +339,8 @@ export function Timeline({
const ghostState = useMemo(() => {
if (!isHoveringZoomRow || isDraggingZoomFragment || isOverFragment) return null;
- if (contentWidth === 0 || validDuration === 0) return null;
-
- const hoverTime = (ghostX / contentWidth) * validDuration;
+ if (contentWidth === 0 || scaledDuration === 0) return null;
+ const hoverTime = (ghostX / contentWidth) * scaledDuration;
const validPosition = findValidFragmentPosition(
hoverTime,
DEFAULT_ZOOM_FRAGMENT_DURATION,
@@ -322,7 +348,7 @@ export function Timeline({
validDuration
);
return { validPosition };
- }, [isHoveringZoomRow, isDraggingZoomFragment, isOverFragment, ghostX, contentWidth, validDuration, zoomFragments]);
+ }, [isHoveringZoomRow, isDraggingZoomFragment, isOverFragment, ghostX, contentWidth, scaledDuration, validDuration, zoomFragments]);
useEffect(() => {
lastValidPositionRef.current = ghostState?.validPosition ?? null;
@@ -330,22 +356,18 @@ export function Timeline({
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="h-38 shrink-0 bg-[#0D0D11] border-t border-white/10 flex flex-col font-mono text-[11px]">
<div className="flex-1 flex flex-col relative overflow-hidden">
-
<LabelSidebar audioTracksCount={audioTracks.length} />
+
<div
ref={trackRef}
- data-scrollable
- className="flex-1 flex flex-col overflow-x-auto overflow-y-hidden custom-scrollbar pl-14 pr-2"
- style={{ scrollBehavior: 'smooth' }}
+ className={`flex-1 flex flex-col overflow-x-auto custom-scrollbar pl-14 pr-2 ${audioTracks.length > 0 ? "overflow-y-auto no-scrollbar" : "overflow-y-hidden"
+ }`}
>
<div
- className="relative flex flex-col h-full"
- style={{
- width: contentWidth > 0 ? contentWidth : '100%',
- minWidth: '100%'
- }}
+ className="relative flex flex-col min-h-full h-max pb-1"
+ style={{ width: timelineWidth > 0 ? timelineWidth : '100%', minWidth: '100%' }}
>
<motion.div
className="absolute top-0 bottom-0 z-20 flex flex-col items-center cursor-ew-resize group select-none"
@@ -359,7 +381,7 @@ export function Timeline({
drag="x"
dragConstraints={{
left: videoClips.length > 0 ? 0 : trimStartPosition,
- right: videoClips.length > 0 ? contentWidth : trimEndPosition
+ right: videoClips.length > 0 ? timelineWidth : trimEndPosition
}}
dragElastic={0}
dragMomentum={false}
@@ -367,10 +389,19 @@ export function Timeline({
onDragStart={handleDragStart}
onDragEnd={handleDragEnd}
>
- <div className={`w-3.5 h-3.5 mt-0.75 shrink-0 transition-all duration-150 origin-top ${isDragging ? 'bg-blue-200 scale-135 shadow-[0_0_15px_rgba(147,197,253,0.9)] ease-out' : 'bg-blue-400 shadow-[0_0_8px_rgba(96,165,250,0.4)] group-hover:bg-blue-300 group-hover:scale-110 ease-in-out'}`}
+ <div
+ className={`w-3.5 h-3.5 mt-0.75 shrink-0 transition-all duration-150 origin-top ${isDragging
+ ? 'bg-blue-200 scale-135 shadow-[0_0_15px_rgba(147,197,253,0.9)] ease-out'
+ : 'bg-blue-400 shadow-[0_0_8px_rgba(96,165,250,0.4)] group-hover:bg-blue-300 group-hover:scale-110 ease-in-out'
+ }`}
style={{ clipPath: 'polygon(0% 0%, 100% 0%, 100% 60%, 50% 100%, 0% 60%)' }}
/>
- <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'}`} />
+ <div
+ className={`w-px h-full 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>
<div
@@ -386,12 +417,11 @@ export function Timeline({
backgroundRepeat: 'repeat-x'
}}
/>
-
<div className="absolute inset-0 pointer-events-none">
{validDuration > 0 && timeMarkers.map((marker, i) => (
<span
key={i}
- className="absolute top-1 select-none text-[10px] leading-none text-zinc-500 font-mono"
+ className="absolute top-1 select-none text-[11px] leading-none text-zinc-500 font-mono"
style={{
left: marker.position,
transform: i === 0 ? 'translateX(0)' : i === timeMarkers.length - 1 ? 'translateX(-100%)' : 'translateX(-50%)',
@@ -404,12 +434,10 @@ export function Timeline({
</div>
</div>
- <div className="flex-1 flex flex-col" onClick={handleTrackClick}>
+ <div className="flex-1 flex flex-col min-h-max" onClick={handleTrackClick}>
- <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"
- >
+ <div className="flex-1 min-h-[55px] shrink-0 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">
{videoClips.length > 0 ? (
<>
{videoClips.map((clip) => (
@@ -418,7 +446,8 @@ export function Timeline({
clip={clip}
isSelected={selectedVideoClipId === clip.id}
contentWidth={contentWidth}
- totalDuration={validDuration}
+ totalDuration={scaledDuration}
+ speed={speed}
otherClips={videoClips.filter(c => c.id !== clip.id)}
currentTime={currentTime}
playheadX={playheadX}
@@ -433,18 +462,11 @@ export function Timeline({
) : (
<>
{trimRange.start > 0 && (
- <motion.div
- className="absolute left-0 top-0 bottom-0 bg-black/60 rounded-l-md z-10"
- style={{ width: trimOverlayLeftWidth }}
- />
+ <motion.div className="absolute left-0 top-0 bottom-0 bg-black/60 rounded-l-md z-10" style={{ width: trimOverlayLeftWidth }} />
)}
{trimRange.end < validDuration && (
- <motion.div
- className="absolute right-0 top-0 bottom-0 bg-black/60 rounded-r-md z-10"
- style={{ left: trimOverlayRightLeft, width: trimOverlayRightWidth }}
- />
+ <motion.div className="absolute right-0 top-0 bottom-0 bg-black/60 rounded-r-md z-10" style={{ left: trimOverlayRightLeft, width: trimOverlayRightWidth }} />
)}
-
<motion.div
className="absolute top-0 bottom-0 rounded-md border border-[#34A853]/40 bg-[#182e20] overflow-hidden"
style={{ left: clipLeftMotion, width: clipWidthMotion }}
@@ -471,7 +493,9 @@ export function Timeline({
boxShadow: 'inset 0 1px 0 rgba(255,255,255,0.2)'
}}
/>
- <motion.span className="flex items-center justify-center gap-2 text-emerald-400 text-[11px] font-medium ml-3 relative z-10 drop-shadow-sm h-full">
+ <motion.span
+ className="flex items-center justify-center gap-2 text-emerald-400 text-[11px] font-medium ml-3 relative z-10 drop-shadow-sm h-full"
+ >
{trimmedDurationLabel}
</motion.span>
</motion.div>
@@ -485,7 +509,7 @@ export function Timeline({
aria-valuenow={trimRange.start}
tabIndex={0}
drag="x"
- dragConstraints={{ left: 0, right: contentWidth }}
+ dragConstraints={{ left: 0, right: timelineWidth }}
dragElastic={0}
dragMomentum={false}
onDrag={handleTrimStartDrag}
@@ -494,7 +518,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>
-
<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%" }}
@@ -505,7 +528,7 @@ export function Timeline({
aria-valuenow={trimRange.end}
tabIndex={0}
drag="x"
- dragConstraints={{ left: 0, right: contentWidth }}
+ dragConstraints={{ left: 0, right: timelineWidth }}
dragElastic={0}
dragMomentum={false}
onDrag={handleTrimEndDrag}
@@ -520,7 +543,7 @@ export function Timeline({
</div>
<div
- className="flex-1 flex items-center relative"
+ className="h-[55px] shrink-0 w-full flex items-center relative"
onMouseMove={(e) => {
if (isDraggingZoomFragment) return;
const rect = e.currentTarget.getBoundingClientRect();
@@ -537,7 +560,6 @@ export function Timeline({
onClick={(e) => {
e.stopPropagation();
if (isOverFragment || isDraggingZoomFragment || !onAddZoomFragment) return;
-
const validPosition = lastValidPositionRef.current;
if (validPosition) {
onAddZoomFragment(validPosition.startTime, validPosition.endTime);
@@ -546,18 +568,40 @@ export function Timeline({
>
<div className="h-full w-full flex items-center relative">
{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={scaledDuration}
+ contentDuration={validDuration}
+ speed={speed}
+ 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)}
+ />
))}
-
{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,
+ left: (ghostState.validPosition.startTime / scaledDuration) * contentWidth,
+ width: ((ghostState.validPosition.endTime - ghostState.validPosition.startTime) / scaledDuration) * contentWidth,
}}
- transition={{ duration: 0 }} // sin lag: WYSIWYG con el click
+ transition={{ duration: 0 }}
>
<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" />
@@ -565,9 +609,11 @@ export function Timeline({
</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="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>
@@ -577,7 +623,7 @@ export function Timeline({
</div>
{audioTracks.length > 0 && (
- <div className="h-5 shrink-0 flex items-center relative">
+ <div className="h-[55px] shrink-0 w-full flex items-center relative">
<div className="h-full w-full flex items-center relative">
{audioTracks.map((track) => {
const audio = uploadedAudios?.find(a => a.id === track.audioId);
@@ -588,7 +634,9 @@ export function Timeline({
audio={audio}
isSelected={track.id === selectedAudioTrackId}
contentWidth={contentWidth}
- videoDuration={validDuration}
+ videoDuration={scaledDuration}
+ contentDuration={validDuration}
+ speed={speed}
otherTracks={audioTracks.filter(t => t.id !== track.id)}
onSelect={() => onSelectAudioTrack?.(track.id)}
onUpdate={(updates) => onUpdateAudioTrack?.(track.id, updates)}
@@ -598,6 +646,7 @@ export function Timeline({
</div>
</div>
)}
+
</div>
</div>
</div>
diff --git a/app/components/ui/editor/ToolsSidebar.tsx b/app/components/ui/editor/ToolsSidebar.tsx
index 9465df4..4d851ae 100644
--- a/app/components/ui/editor/ToolsSidebar.tsx
+++ b/app/components/ui/editor/ToolsSidebar.tsx
@@ -286,7 +286,7 @@ export function ToolsSidebar({
isActive={activeTool === "video"}
onClick={() => onToolChange("video")}
ref={videosToolRef}
- badgeCount={activeTool !== "video" ? newVideosCount : undefined}
+ badgeCount={newVideosCount}
popover={{
title: t("popovers.videos.title"),
description: t("popovers.videos.description"),
@@ -403,7 +403,7 @@ export function ToolsSidebar({
className={`w-full flex flex-col items-center text-center justify-center gap-1.5 p-2 rounded-xl cursor-pointer transition-all group border-2 border-transparent disabled:cursor-not-allowed ${!isIdle ? "opacity-70" : "hover:bg-red-500/10"}`}
>
<Icon icon={recordButtonContent.icon} width="24" height="24" className={`transition-colors ${recordButtonContent.className}`} />
- <span className={`text-xs font-medium transition-colors ${!isIdle ? recordButtonContent.className : "text-white/60 group-hover:text-red-400"}`}>
+ <span className={`text-xs font-medium transition-colors ${!isIdle ? recordButtonContent.className : "text-white/70 group-hover:text-red-400"}`}>
{recordButtonContent.text}
</span>
</button>
@@ -413,7 +413,7 @@ export function ToolsSidebar({
<button
onClick={handleUploadClick}
disabled={isUploading}
- className={`w-full flex flex-col items-center text-center justify-center gap-1.5 p-2 rounded-xl cursor-pointer transition-all group disabled:opacity-50 disabled:cursor-not-allowed border-2 ${isDragging ? "bg-blue-500/20 text-blue-400 border-dashed border-blue-400/50 scale-105" : "border-transparent text-white/60 hover:bg-blue-500/20 hover:text-blue-400"}`}
+ className={`w-full flex flex-col items-center text-center justify-center gap-1.5 p-2 rounded-xl cursor-pointer transition-all group disabled:opacity-50 disabled:cursor-not-allowed border-2 ${isDragging ? "bg-blue-500/20 text-blue-400 border-dashed border-blue-400/50 scale-105" : "border-transparent text-white/70 hover:bg-blue-500/20 hover:text-blue-400"}`}
aria-label={isUploading ? t("upload.buttonUploading") : t("upload.button")}
>
{isUploading ? (
@@ -463,9 +463,9 @@ export function ToolsSidebar({
width="24"
aria-hidden="true"
height="24"
- className={`transition-colors ${isCapturing ? "text-cyan-400" : "text-white/60 group-hover:text-cyan-400"}`}
+ className={`transition-colors ${isCapturing ? "text-cyan-400" : "text-white/70 group-hover:text-cyan-400"}`}
/>
- <span className={`text-xs font-medium transition-colors ${isCapturing ? "text-cyan-400" : "text-white/60 group-hover:text-cyan-400"}`}>
+ <span className={`text-xs font-medium transition-colors ${isCapturing ? "text-cyan-400" : "text-white/70 group-hover:text-cyan-400"}`}>
{isCapturing ? t("photo.capturing") : t("photo.capture")}
</span>
</button>
@@ -475,7 +475,7 @@ export function ToolsSidebar({
<button
onClick={handleImageUploadClick}
disabled={isUploading}
- className={`w-full flex flex-col items-center text-center justify-center gap-1.5 p-2 rounded-xl cursor-pointer transition-all group disabled:opacity-50 disabled:cursor-not-allowed border-2 ${isImageDragging ? "bg-blue-500/20 text-blue-400 border-dashed border-blue-400/50 scale-105" : "border-transparent text-white/60 hover:bg-blue-500/20 hover:text-blue-400"}`}
+ className={`w-full flex flex-col items-center text-center justify-center gap-1.5 p-2 rounded-xl cursor-pointer transition-all group disabled:opacity-50 disabled:cursor-not-allowed border-2 ${isImageDragging ? "bg-blue-500/20 text-blue-400 border-dashed border-blue-400/50 scale-105" : "border-transparent text-white/70 hover:bg-blue-500/20 hover:text-blue-400"}`}
>
{isUploading ? (
<>
diff --git a/app/components/ui/editor/VideoCanvas.tsx b/app/components/ui/editor/VideoCanvas.tsx
index eadabda..196e416 100644
--- a/app/components/ui/editor/VideoCanvas.tsx
+++ b/app/components/ui/editor/VideoCanvas.tsx
@@ -4,7 +4,6 @@ import { useRef, useEffect, useImperativeHandle, useMemo, useState, useCallback,
import dynamic from "next/dynamic";
import type { VideoCanvasHandle, VideoCanvasProps, VideoThumbnail } from "@/types";
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, drawImageCover, getMockupOuterRadius } from "@/lib/canvas.utils";
@@ -123,6 +122,7 @@ function VideoCanvasInner({
ref,
activeMediaAspect = null,
activeClipUrl = null,
+ onPaddingChange,
}: VideoCanvasProps & { ref?: React.Ref<VideoCanvasHandle> }) {
const wallpaperUrl = getWallpaperUrl(selectedWallpaper);
@@ -157,6 +157,17 @@ function VideoCanvasInner({
// Ctrl+scroll zoom badge state for image phone overlay
const [imagePhoneZoomVisible, setImagePhoneZoomVisible] = useState(false);
const imagePhoneZoomTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
+ const paddingWheelRafRef = useRef<number | null>(null);
+ const pendingPaddingRef = useRef<number | null>(null);
+
+ useEffect(() => {
+ return () => {
+ if (paddingWheelRafRef.current !== null) {
+ cancelAnimationFrame(paddingWheelRafRef.current);
+ }
+ };
+ }, []);
+
// Ref for the non-passive Ctrl+scroll wheel handler (React's onWheel is always passive).
// Updated each render so the closure always has the latest state values.
const ctrlScrollWheelRef = useRef<((e: WheelEvent) => void) | null>(null);
@@ -347,14 +358,13 @@ function VideoCanvasInner({
return () => img.removeEventListener("load", updateAspect);
}, [mediaType, imageRef, imageUrl]);
- // Dispose Three.js WebGL resources when component unmounts
-
// Dispose Three.js WebGL resources when component unmounts
useEffect(() => {
return () => {
disposePerspective3D();
};
}, []);
+
const [isDraggingVideo, setIsDraggingVideo] = useState(false);
const [isDraggingRotation, setIsDraggingRotation] = useState(false);
const [videoHoverCorner, setVideoHoverCorner] = useState<Corner | null>("top-right");
@@ -375,14 +385,39 @@ function VideoCanvasInner({
const [contentInsets, setContentInsets] = useState({ top: 0, bottom: 0, left: 0, right: 0 });
ctrlScrollWheelRef.current = (e: WheelEvent) => {
- if (!e.ctrlKey || !imagePhoneActive) return;
- e.preventDefault();
- e.stopImmediatePropagation();
- const next = Math.max(0.3, Math.min(3, imagePhoneScale * (e.deltaY < 0 ? 1.05 : 0.95)));
- setImagePhoneScale(next);
- setImagePhoneZoomVisible(true);
- if (imagePhoneZoomTimerRef.current) clearTimeout(imagePhoneZoomTimerRef.current);
- imagePhoneZoomTimerRef.current = setTimeout(() => setImagePhoneZoomVisible(false), 1200);
+ if (!e.ctrlKey) return;
+
+ if (imagePhoneActive) {
+ e.preventDefault();
+ e.stopImmediatePropagation();
+ const next = Math.max(0.3, Math.min(3, imagePhoneScale * (e.deltaY < 0 ? 1.05 : 0.95)));
+ setImagePhoneScale(next);
+ setImagePhoneZoomVisible(true);
+ if (imagePhoneZoomTimerRef.current) clearTimeout(imagePhoneZoomTimerRef.current);
+ imagePhoneZoomTimerRef.current = setTimeout(() => setImagePhoneZoomVisible(false), 1200);
+ return;
+ }
+
+ if (mediaType === "video" && onPaddingChange) {
+ e.preventDefault();
+ e.stopImmediatePropagation();
+
+ const PADDING_MIN = 0;
+ const PADDING_MAX = 30;
+ const base = pendingPaddingRef.current ?? padding;
+ const step = Math.min(1.5, Math.max(0.15, Math.abs(e.deltaY) * 0.015));
+ const next = Math.max(PADDING_MIN, Math.min(PADDING_MAX, base + (e.deltaY < 0 ? step : -step)));
+
+ pendingPaddingRef.current = next;
+ if (paddingWheelRafRef.current === null) {
+ paddingWheelRafRef.current = requestAnimationFrame(() => {
+ if (pendingPaddingRef.current !== null) {
+ onPaddingChange(pendingPaddingRef.current);
+ }
+ paddingWheelRafRef.current = null;
+ });
+ }
+ }
};
useEffect(() => {
diff --git a/app/components/ui/editor/VideoClipTrackItem.tsx b/app/components/ui/editor/VideoClipTrackItem.tsx
index e73f2ec..8966c4d 100644
--- a/app/components/ui/editor/VideoClipTrackItem.tsx
+++ b/app/components/ui/editor/VideoClipTrackItem.tsx
@@ -21,6 +21,7 @@ interface VideoClipTrackItemProps {
onDragStateChange?: (isDragging: boolean) => void;
zoomLevel: number;
playheadX: MotionValue<number>;
+ speed?: number;
}
export function VideoClipTrackItem({
@@ -36,6 +37,7 @@ export function VideoClipTrackItem({
onDragStateChange,
zoomLevel,
playheadX,
+ speed = 1,
}: VideoClipTrackItemProps) {
const [isDragging, setIsDragging] = useState(false);
const [isResizing, setIsResizing] = useState<'start' | 'end' | null>(null);
@@ -62,7 +64,6 @@ export function VideoClipTrackItem({
const clipEndTime = clip.startTime + clipDuration;
- // Calculate progress within this clip (0 to clipWidth)
const progressWidth = useTransform(
playheadX,
(px) => {
@@ -81,7 +82,6 @@ export function VideoClipTrackItem({
}
}, [initialLeft, initialWidth, isDragging, isResizing, clipX, clipWidth]);
- // Calculate boundaries based on other clips
const boundaries = useMemo(() => {
const sorted = [...otherClips]
.filter(c => c.id !== clip.id)
@@ -106,7 +106,6 @@ export function VideoClipTrackItem({
return { minStart, maxEnd };
}, [otherClips, clip.id, clip.startTime, clipDuration]);
- // Drag handler
const handleDrag = useCallback((_e: MouseEvent | TouchEvent | PointerEvent, info: { delta: { x: number } }) => {
if (contentWidth === 0 || totalDuration === 0) return;
@@ -135,7 +134,6 @@ export function VideoClipTrackItem({
});
}, [clipX, pixelsToTime, onUpdate, onDragStateChange]);
- // Resize handlers
const handleResizeStartDrag = useCallback((_e: MouseEvent | TouchEvent | PointerEvent, info: { delta: { x: number } }) => {
if (contentWidth === 0 || totalDuration === 0) return;
@@ -171,7 +169,6 @@ export function VideoClipTrackItem({
const minWidth = timeToPixels(MIN_CLIP_DURATION);
newWidth = Math.max(minWidth, newWidth);
- // Limit by boundary with other clips (if there's a next clip)
if (Number.isFinite(boundaries.maxEnd)) {
const maxWidthByBoundary = timeToPixels(boundaries.maxEnd) - currentX;
newWidth = Math.min(newWidth, maxWidthByBoundary);
@@ -196,7 +193,6 @@ export function VideoClipTrackItem({
const newStartTime = pixelsToTime(clipX.get());
const newDuration = pixelsToTime(clipWidth.get());
- // Calculate new trim values
const trimDelta = newStartTime - clip.startTime;
const newTrimStart = Math.max(0, clip.trimStart + trimDelta);
const newTrimEnd = Math.min(clip.duration, newTrimStart + newDuration);
@@ -210,7 +206,6 @@ export function VideoClipTrackItem({
const isInteracting = isDragging || isResizing !== null;
- // Format duration for display
const formatDuration = (seconds: number): string => {
const mins = Math.floor(seconds / 60);
const secs = Math.floor(seconds % 60);
@@ -220,18 +215,20 @@ export function VideoClipTrackItem({
return (
<motion.div
ref={containerRef}
- className={`absolute top-0 bottom-0 rounded-md cursor-grab active:cursor-grabbing overflow-hidden group ${isSelected
- ? 'ring-[1.5px] ring-[#4ade80] shadow-[0_0_12px_rgba(74,222,128,0.3)] z-10'
- : ''
+ className={`absolute top-0 bottom-0 rounded-md cursor-grab active:cursor-grabbing overflow-hidden group transition-all duration-200 ${isSelected ? 'ring-[1.5px] ring-[#4ade80] shadow-[0_0_12px_rgba(74,222,128,0.3)] z-10' : ''
} ${isInteracting ? 'z-10' : 'z-0'}`}
style={{
x: clipX,
width: clipWidth,
- border: '1px solid rgba(52, 168, 83, 0.4)',
- background: '#182e20',
+ border: isSelected
+ ? '1px solid rgba(74, 222, 128, 0.8)'
+ : isHovered
+ ? '1px solid rgba(52, 168, 83, 0.65)'
+ : '1px solid rgba(52, 168, 83, 0.4)',
+ background: isHovered ? '#1c3525' : '#182e20',
}}
drag="x"
- dragConstraints={{ left: 0, right: contentWidth }}
+ dragConstraints={{ left: 0, right: contentWidth / speed }}
dragElastic={0}
dragMomentum={false}
onDrag={handleDrag}
@@ -269,11 +266,13 @@ export function VideoClipTrackItem({
/>
<div className="absolute inset-0 flex items-center justify-center pointer-events-none z-10">
- <span className="flex items-center gap-2 text-emerald-400 text-[11px] font-medium drop-shadow-sm">
+ <span className={`flex items-center gap-2 text-[11px] font-medium drop-shadow-sm transition-colors duration-200 ${isHovered ? 'text-emerald-300' : 'text-emerald-400'
+ }`}>
<Icon icon="solar:videocamera-record-bold" width="12" className="opacity-70" />
<span className="truncate max-w-30">{clip.name}</span>
- <span className="text-emerald-400/60 font-mono text-[10px]">
- {formatDuration(clipDuration)}
+ <span className={`font-mono text-[11px] transition-colors duration-200 ${isHovered ? 'text-emerald-300/80' : 'text-emerald-400/60'
+ }`}>
+ {formatDuration(clipDuration / speed)}
</span>
</span>
</div>
diff --git a/app/components/ui/editor/VideosMenu.tsx b/app/components/ui/editor/VideosMenu.tsx
index dc1f7b2..da883bb 100644
--- a/app/components/ui/editor/VideosMenu.tsx
+++ b/app/components/ui/editor/VideosMenu.tsx
@@ -14,6 +14,7 @@ import {
getLibraryVideoInfoList,
} from "@/lib/videos-library";
import { LibraryVideoInfo } from "@/types";
+import { TickSliderControl } from "@/components/ui/TickSliderControl";
interface VideosMenuProps {
onAddToTrack?: (videoId: string, blob: Blob, duration: number) => void;
@@ -24,6 +25,8 @@ interface VideosMenuProps {
refreshTrigger?: number;
isUploading?: boolean;
onVideoAudioToggle?: (videoId: string, hasAudio: boolean) => void;
+ onGlobalSpeedChange?: (speed: number) => void;
+ globalSpeed?: number;
}
export function VideosMenu({
@@ -35,6 +38,8 @@ export function VideosMenu({
refreshTrigger,
isUploading = false,
onVideoAudioToggle,
+ onGlobalSpeedChange,
+ globalSpeed = 1,
}: VideosMenuProps) {
const t = useTranslations("videosMenu");
const [videos, setVideos] = useState<LibraryVideoInfo[]>([]);
@@ -176,6 +181,19 @@ export function VideosMenu({
<span>{t("title")}</span>
</div>
+ <div className="bg-[#09090B] border border-white/5 squircle-element p-3 shrink-0 mb-1">
+ <TickSliderControl
+ label={t("speed")}
+ value={globalSpeed}
+ min={0.5}
+ max={3}
+ step={0.1}
+ tickStep={0.5}
+ suffix="x"
+ onChange={(val) => onGlobalSpeedChange?.(val)}
+ />
+ </div>
+
<div className="flex-1 overflow-y-auto custom-scrollbar -mx-1 px-1">
{isLoading ? (
<div className="flex items-center justify-center py-8" role="status">
@@ -244,11 +262,10 @@ export function VideosMenu({
initial={{ opacity: 0, y: 10 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, x: -20, scale: 0.95 }}
- className={`group bg-[#09090B] border squircle-element overflow-hidden transition-colors ${
- videosInTrackIds.includes(video.id)
- ? "border-blue-500/50 bg-blue-500/5"
- : "border-white/5 hover:border-white/10"
- }`}
+ className={`group bg-[#09090B] border squircle-element overflow-hidden transition-colors ${videosInTrackIds.includes(video.id)
+ ? "border-blue-500/50 bg-blue-500/5"
+ : "border-white/5 hover:border-white/10"
+ }`}
>
<div className="flex gap-3 p-2.5 items-center">
<div
@@ -270,9 +287,8 @@ export function VideosMenu({
{formatVideoDuration(video.duration)}
</div>
<div
- className={`absolute inset-0 flex items-center justify-center transition-all ${
- videosInTrackIds.includes(video.id) ? "bg-blue-500/10 opacity-100" : "bg-black/60 opacity-0 group-hover:opacity-100"
- }`}
+ className={`absolute inset-0 flex items-center justify-center transition-all ${videosInTrackIds.includes(video.id) ? "bg-blue-500/10 opacity-100" : "bg-black/60 opacity-0 group-hover:opacity-100"
+ }`}
>
{addingId === video.id ? (
<Icon icon="svg-spinners:ring-resize" width="20" className="text-white" />
@@ -296,9 +312,9 @@ export function VideosMenu({
{video.fileName}
</p>
<div className="flex items-center gap-2 mt-0.5">
- <span className="text-[10px] text-white/40">{formatFileSize(video.fileSize)}</span>
- <span className="text-[10px] text-white/30">•</span>
- <span className="text-[10px] text-white/40">
+ <span className="text-[11px] text-white/40">{formatFileSize(video.fileSize)}</span>
+ <span className="text-[11px] text-white/30">•</span>
+ <span className="text-[11px] text-white/40">
{video.width}×{video.height}
</span>
</div>
@@ -309,13 +325,12 @@ export function VideosMenu({
<button
onClick={() => handleToggleAudio(video.id, video.hasAudio)}
disabled={video.originalHasAudio === false}
- className={`p-1.5 rounded-md transition-colors ${
- video.originalHasAudio === false
- ? "text-white/10 cursor-not-allowed"
- : video.hasAudio === false
+ className={`p-1.5 rounded-md transition-colors ${video.originalHasAudio === false
+ ? "text-white/10 cursor-not-allowed"
+ : video.hasAudio === false
? "text-red-400 bg-red-500/10"
: "text-white/40 hover:text-white hover:bg-white/5"
- }`}
+ }`}
>
<Icon
icon={video.hasAudio === false ? "solar:volume-cross-outline" : "solar:volume-loud-outline"}
@@ -345,7 +360,7 @@ export function VideosMenu({
)}
</div>
- <div className="text-[10px] text-white/25 text-center pt-2 border-t border-white/5 shrink-0">
+ <div className="text-[11px] text-white/25 text-center pt-2 border-t border-white/5 shrink-0">
{t("footer")}
</div>
</div>
diff --git a/app/components/ui/editor/ZoomFragmentEditor.tsx b/app/components/ui/editor/ZoomFragmentEditor.tsx
index 594ebf1..787fc88 100644
--- a/app/components/ui/editor/ZoomFragmentEditor.tsx
+++ b/app/components/ui/editor/ZoomFragmentEditor.tsx
@@ -84,7 +84,7 @@ export function ZoomFragmentEditor({
onBack={onBack}
/>
<TooltipAction label={t("deleteTooltip")}>
- <button onClick={onDelete} className="ml-auto flex items-center gap-1.5 text-[10px] text-red-400/70 hover:text-red-400 px-2 py-1 rounded-md transition-colors shrink-0">
+ <button onClick={onDelete} className="ml-auto flex items-center gap-1.5 text-[11px] text-red-400/70 hover:text-red-400 px-2 py-1 rounded-md transition-colors shrink-0">
<Icon icon="ph:trash-bold" width="12" />
{t("actions.delete")}
</button>
@@ -95,20 +95,20 @@ export function ZoomFragmentEditor({
{/* Focus point preview */}
<div>
- <div className="flex items-center gap-2 text-xs mb-2 text-white/60">
+ <div className="flex items-center gap-2 text-xs mb-2 text-white/70">
<Icon icon="material-symbols:center-focus-strong-outline" width="16" />
<span>{movementEnabled ? t("focusPoints.multiple") : t("focusPoints.single")}</span>
{movementEnabled && (
<div className="ml-auto flex gap-1">
<button
onClick={() => setEditingPoint('start')}
- className={`px-2 py-0.5 rounded text-[10px] font-mono transition-colors ${editingPoint === 'start' ? 'bg-blue-500/30 text-blue-300 border border-blue-500/50' : 'bg-white/5 text-white/40 hover:bg-white/10'}`}
+ className={`px-2 py-0.5 rounded text-[11px] font-mono transition-colors ${editingPoint === 'start' ? 'bg-blue-500/30 text-blue-300 border border-blue-500/50' : 'bg-white/5 text-white/40 hover:bg-white/10'}`}
>
{t("focusPoints.start")}
</button>
<button
onClick={() => setEditingPoint('end')}
- className={`px-2 py-0.5 rounded text-[10px] font-mono transition-colors ${editingPoint === 'end' ? 'bg-emerald-500/30 text-emerald-300 border border-emerald-500/50' : 'bg-white/5 text-white/40 hover:bg-white/10'}`}
+ className={`px-2 py-0.5 rounded text-[11px] font-mono transition-colors ${editingPoint === 'end' ? 'bg-emerald-500/30 text-emerald-300 border border-emerald-500/50' : 'bg-white/5 text-white/40 hover:bg-white/10'}`}
>
{t("focusPoints.end")}
</button>
@@ -185,10 +185,10 @@ export function ZoomFragmentEditor({
<div className="space-y-3 p-3 bg-white/3 border border-white/8 squircle-element">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
- <Icon icon="mdi:vector-line" width="16" className="text-white/50" />
+ <Icon icon="mdi:vector-line" width="16" className="text-white/60" />
<div>
<p className="text-xs font-medium text-white/80">{t("movement.title")}</p>
- <p className="text-[10px] text-white/40">{t("movement.subtitle")}</p>
+ <p className="text-[11px] text-white/40">{t("movement.subtitle")}</p>
</div>
</div>
<button onClick={handleToggleMovement} className={`relative w-11 h-6 rounded-full transition-colors ${movementEnabled ? 'bg-emerald-500' : 'bg-white/15'}`}>
@@ -240,11 +240,11 @@ export function ZoomFragmentEditor({
return holdDuration > 0.1 ? (
<div className="space-y-3 p-3 bg-[#0A0A0A] border border-[#262626] rounded-xl group transition-all">
<div className="flex items-center justify-between">
- <div className="flex items-center gap-2 text-[11px] font-medium text-white/50">
+ <div className="flex items-center gap-2 text-[11px] font-medium text-white/60">
<span>{t("movement.timeline.title")}</span>
</div>
<div className="flex items-center gap-2">
- <span className="text-[10px] font-mono text-emerald-400/80 bg-emerald-500/5 px-1.5 py-0.5 rounded border border-emerald-500/10">
+ <span className="text-[11px] font-mono text-emerald-400/80 bg-emerald-500/5 px-1.5 py-0.5 rounded border border-emerald-500/10">
{t("movement.timeline.active", { seconds: (endOffset - startOffset).toFixed(1) })}
</span>
</div>
@@ -280,11 +280,11 @@ export function ZoomFragmentEditor({
<div className="flex gap-4 text-[9px] font-mono text-white/30">
<span className="flex items-center gap-1.5">
<span className="text-emerald-500/50">{t("movement.timeline.startLabel")}</span>
- <span className="text-white/60">{startOffset.toFixed(1)}s</span>
+ <span className="text-white/70">{startOffset.toFixed(1)}s</span>
</span>
<span className="flex items-center gap-1.5">
<span className="text-emerald-500/50">{t("movement.timeline.endLabel")}</span>
- <span className="text-white/60">{endOffset.toFixed(1)}s</span>
+ <span className="text-white/70">{endOffset.toFixed(1)}s</span>
</span>
</div>
</div>
@@ -304,10 +304,10 @@ export function ZoomFragmentEditor({
<div className="space-y-3 p-3 bg-white/3 border border-white/8 squircle-element">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
- <Icon icon="mdi:cube-outline" width="16" className="text-white/50" />
+ <Icon icon="mdi:cube-outline" width="16" className="text-white/60" />
<div>
<p className="text-xs font-medium text-white/80">{tCommon("effect3d.title")}</p>
- <p className="text-[10px] text-white/40">{tCommon("effect3d.subtitle")}</p>
+ <p className="text-[11px] text-white/40">{tCommon("effect3d.subtitle")}</p>
</div>
</div>
<button onClick={handleToggle3D} className={`relative w-11 h-6 rounded-full transition-colors ${fragment.enable3D ? 'bg-gray-400' : 'bg-white/15'}`}>
@@ -319,7 +319,7 @@ export function ZoomFragmentEditor({
<div className="space-y-3 pt-3 border-t border-gray-500/20">
<SliderControl icon="mdi:brightness-6" label={tCommon("effect3d.intensity")} value={fragment.perspective3DIntensity ?? 50} min={0} max={100} step={5} onChange={(value) => onUpdate({ perspective3DIntensity: value })} suffix="%" />
<div className="space-y-2">
- <div className="flex items-center gap-2 text-xs text-white/50">
+ <div className="flex items-center gap-2 text-xs text-white/60">
<span>{tCommon("effect3d.direction")}</span>
</div>
<div
@@ -365,19 +365,19 @@ export function ZoomFragmentEditor({
<div className="h-px bg-white/10" />
<div className="space-y-2">
- <div className="flex items-center justify-between text-[10px]">
+ <div className="flex items-center justify-between text-[11px]">
<span className="text-white/35">{t("info.fragmentDuration")}</span>
<span className="font-mono text-white/55 bg-white/10 px-2 py-0.5 rounded">
{formatZoomTime(fragment.startTime)} - {formatZoomTime(fragment.endTime)}
</span>
</div>
- <div className="flex items-center justify-between text-[10px]">
+ <div className="flex items-center justify-between text-[11px]">
<span className="text-white/35">{t("info.zoomFactor")}</span>
<span className="font-mono text-white/55 bg-white/10 px-2 py-0.5 rounded">
{zoomLevelToFactor(fragment.zoomLevel).toFixed(1)}×
</span>
</div>
- <div className="flex items-center justify-between text-[10px]">
+ <div className="flex items-center justify-between text-[11px]">
<span className="text-white/35">{t("info.transitionDuration")}</span>
<span className="font-mono text-white/55 bg-white/10 px-2 py-0.5 rounded">
{(speedToTransitionMs(fragment.speed) / 1000).toFixed(1)}s
diff --git a/app/components/ui/editor/ZoomFragmentTrackItem.tsx b/app/components/ui/editor/ZoomFragmentTrackItem.tsx
index 097e6f9..057daae 100644
--- a/app/components/ui/editor/ZoomFragmentTrackItem.tsx
+++ b/app/components/ui/editor/ZoomFragmentTrackItem.tsx
@@ -5,7 +5,6 @@ import { motion, useMotionValue } from "framer-motion";
import type { ZoomFragment } from "@/types/zoom.types";
import { zoomLevelToFactor } from "@/types/zoom.types";
-// Minimum fragment duration in seconds
const MIN_FRAGMENT_DURATION = 0.5;
interface ZoomFragmentTrackItemProps {
@@ -13,12 +12,14 @@ interface ZoomFragmentTrackItemProps {
isSelected: boolean;
contentWidth: number;
videoDuration: number;
+ contentDuration?: number;
otherFragments: ZoomFragment[];
onSelect: () => void;
onUpdate: (updates: Partial<ZoomFragment>) => void;
onDragStateChange?: (isDragging: boolean) => void;
onMouseEnter?: () => void;
onMouseLeave?: () => void;
+ speed?: number;
}
export function ZoomFragmentTrackItem({
@@ -26,12 +27,14 @@ export function ZoomFragmentTrackItem({
isSelected,
contentWidth,
videoDuration,
+ contentDuration,
otherFragments,
onSelect,
onUpdate,
onDragStateChange,
onMouseEnter,
onMouseLeave,
+ speed = 1,
}: ZoomFragmentTrackItemProps) {
const [isDragging, setIsDragging] = useState(false);
const [isResizing, setIsResizing] = useState<'start' | 'end' | null>(null);
@@ -62,7 +65,7 @@ export function ZoomFragmentTrackItem({
const sorted = [...otherFragments].sort((a, b) => a.startTime - b.startTime);
let minStart = 0;
- let maxEnd = videoDuration;
+ let maxEnd = contentDuration ?? videoDuration;
for (const other of sorted) {
if (other.endTime <= fragment.startTime) {
@@ -75,7 +78,8 @@ export function ZoomFragmentTrackItem({
}
return { minStart, maxEnd };
- }, [otherFragments, fragment.startTime, fragment.endTime, videoDuration]);
+ }, [otherFragments, fragment.startTime, fragment.endTime, videoDuration, contentDuration]);
+
const handleDrag = useCallback((e: MouseEvent | TouchEvent | PointerEvent, info: { delta: { x: number } }) => {
if (contentWidth === 0 || videoDuration === 0) return;
@@ -106,9 +110,9 @@ export function ZoomFragmentTrackItem({
onUpdate({
startTime: Math.max(0, newStartTime),
- endTime: Math.min(videoDuration, newStartTime + duration),
+ endTime: Math.min(contentDuration ?? videoDuration, newStartTime + duration),
});
- }, [fragmentX, pixelsToTime, fragment, videoDuration, onUpdate, onDragStateChange]);
+ }, [fragmentX, pixelsToTime, fragment, videoDuration, contentDuration, onUpdate, onDragStateChange]);
const handleResizeStartDrag = useCallback((e: MouseEvent | TouchEvent | PointerEvent, info: { delta: { x: number } }) => {
if (contentWidth === 0 || videoDuration === 0) return;
@@ -167,9 +171,9 @@ export function ZoomFragmentTrackItem({
onUpdate({
startTime: Math.max(0, newStartTime),
- endTime: Math.min(videoDuration, newEndTime),
+ endTime: Math.min(contentDuration ?? videoDuration, newEndTime),
});
- }, [fragmentX, fragmentWidth, pixelsToTime, videoDuration, onUpdate, onDragStateChange]);
+ }, [fragmentX, fragmentWidth, pixelsToTime, videoDuration, contentDuration, onUpdate, onDragStateChange]);
const duration = fragment.endTime - fragment.startTime;
const isInteracting = isDragging || isResizing !== null;
@@ -177,7 +181,7 @@ export function ZoomFragmentTrackItem({
return (
<motion.div
ref={containerRef}
- className={`absolute h-[80%] top-[5%] rounded-md flex items-center border transition-shadow select-none ${isSelected || isInteracting
+ className={`absolute h-[90%] 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'
} ${isDragging ? 'cursor-grabbing' : 'cursor-grab'}`}
@@ -192,7 +196,7 @@ export function ZoomFragmentTrackItem({
: 'inset 0 1px 0 rgba(255,255,255,0.1)'
}}
drag="x"
- dragConstraints={{ left: 0, right: contentWidth }}
+ dragConstraints={{ left: 0, right: contentWidth / speed }}
dragElastic={0}
dragMomentum={false}
onDrag={handleDrag}
@@ -207,9 +211,9 @@ export function ZoomFragmentTrackItem({
whileTap={{ scale: 0.98 }}
role="slider"
aria-valuemin={0}
- aria-valuemax={videoDuration}
+ aria-valuemax={contentDuration ?? videoDuration}
aria-valuenow={fragment.startTime}
- aria-label={`Zoom fragment ${zoomLevelToFactor(fragment.zoomLevel).toFixed(1)}x, ${duration.toFixed(1)}s`}
+ aria-label={`Zoom fragment ${zoomLevelToFactor(fragment.zoomLevel).toFixed(1)}x, ${(duration / speed).toFixed(1)}s`}
tabIndex={0}
>
{/* Resize handle - Start */}
@@ -226,7 +230,7 @@ export function ZoomFragmentTrackItem({
role="slider"
aria-label="Resize start"
aria-valuemin={0}
- aria-valuemax={videoDuration}
+ aria-valuemax={contentDuration ?? videoDuration}
aria-valuenow={fragment.startTime}
tabIndex={0}
>
@@ -238,11 +242,11 @@ export function ZoomFragmentTrackItem({
{/* Content */}
<div className="flex-1 flex flex-col items-center justify-center pointer-events-none overflow-hidden px-2">
- <span className={`text-[10px] truncate ${isSelected || isInteracting ? 'text-blue-200' : 'text-blue-300/70'}`}>
+ <span className={`text-[11px] truncate ${isSelected || isInteracting ? 'text-blue-200' : 'text-blue-300/70'}`}>
Zoom
</span>
<span className={`text-[9px] truncate ${isSelected || isInteracting ? 'text-blue-300/70' : 'text-blue-400/45'}`}>
- {zoomLevelToFactor(fragment.zoomLevel).toFixed(1)}× · {duration.toFixed(1)}s
+ {zoomLevelToFactor(fragment.zoomLevel).toFixed(1)}× · {(duration / speed).toFixed(1)}s
</span>
</div>
@@ -260,7 +264,7 @@ export function ZoomFragmentTrackItem({
role="slider"
aria-label="Resize end"
aria-valuemin={0}
- aria-valuemax={videoDuration}
+ aria-valuemax={contentDuration ?? videoDuration}
aria-valuenow={fragment.endTime}
tabIndex={0}
>
@@ -273,7 +277,6 @@ export function ZoomFragmentTrackItem({
);
}
-// Helper function to check if a time range overlaps with existing fragments
export function canAddFragmentAt(
startTime: number,
endTime: number,
@@ -289,7 +292,6 @@ export function canAddFragmentAt(
return true;
}
-// Find all available gaps in the timeline
function findAllGaps(
existingFragments: ZoomFragment[],
videoDuration: number,
@@ -325,7 +327,6 @@ function findAllGaps(
return gaps;
}
-// Find valid position for new fragment (avoiding overlaps)
export function findValidFragmentPosition(
clickTime: number,
defaultDuration: number,
@@ -335,7 +336,7 @@ export function findValidFragmentPosition(
const gaps = findAllGaps(existingFragments, videoDuration, defaultDuration);
if (gaps.length === 0) {
- return null; // No space available
+ return null;
}
for (const gap of gaps) {