Skip to content

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

feat(editor): integrate recording functionality and enhance tools sidebar with zoom and audio track selection

CristianOlivera18f38337cbb3d
diff --git a/app/(editor)/editor/page.tsx b/app/(editor)/editor/page.tsx
index 5feaf39..e1c38e4 100644
--- a/app/(editor)/editor/page.tsx
+++ b/app/(editor)/editor/page.tsx
@@ -1255,6 +1255,8 @@ export default function Editor() {
onToolChange={setActiveTool}
onVideoUpload={handleVideoUpload}
isUploading={isUploading}
+ selectedZoomFragmentId={selectedZoomFragmentId}
+ selectedAudioTrackId={selectedAudioTrackId}
/>
</div>
diff --git a/app/(editor)/layout.tsx b/app/(editor)/layout.tsx
index 1588d30..e8b63d0 100644
--- a/app/(editor)/layout.tsx
+++ b/app/(editor)/layout.tsx
@@ -1,13 +1,18 @@
"use client";
import { AuthProvider } from "@/hooks/useAuth";
+import { RecordingProvider } from "@/hooks/RecordingContext";
+import RecordingOverlay from "../components/ui/RecordingOverlay";
export default function EditorLayout({ children }: { children: React.ReactNode }) {
return (
<AuthProvider>
- <div className="min-h-screen bg-neutral-950">
- {children}
- </div>
+ <RecordingProvider>
+ <div className="min-h-screen bg-neutral-950">
+ {children}
+ </div>
+ <RecordingOverlay />
+ </RecordingProvider>
</AuthProvider>
);
}
diff --git a/app/components/ui/DemoVideo.tsx b/app/components/ui/DemoVideo.tsx
index c5a7f5f..a1db13d 100644
--- a/app/components/ui/DemoVideo.tsx
+++ b/app/components/ui/DemoVideo.tsx
@@ -1,10 +1,8 @@
"use client";
import React, { useEffect, useRef, useState } from "react";
-// Importamos AnimatePresence y motion de Framer Motion para la animación profesional
import { AnimatePresence, motion, Variants } from "framer-motion";
-// Lista de características extraídas de tu contexto
const features = [
"Grabación de pantalla",
"Zooms suaves",
@@ -18,11 +16,9 @@ const features = [
export default function DemoVideo() {
const videoRef = useRef<HTMLVideoElement>(null);
- // Estado para controlar qué característica se muestra
const [featureIndex, setFeatureIndex] = useState(0);
useEffect(() => {
- // Intersection Observer para play/pause del video (tu lógica existente)
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
@@ -40,19 +36,16 @@ export default function DemoVideo() {
observer.observe(videoRef.current);
}
- // Lógica para cambiar la característica cada 3 segundos
const featureInterval = setInterval(() => {
setFeatureIndex((prevIndex) => (prevIndex + 1) % features.length);
}, 3000);
return () => {
observer.disconnect();
- clearInterval(featureInterval); // Limpieza del intervalo
+ clearInterval(featureInterval);
};
}, []);
- // Definición de la animación (el "hack" profesional)
- // Agrega ": Variants" justo aquí
const tickerVariants: Variants = {
enter: {
y: 20,
diff --git a/app/components/ui/SidebarTool.tsx b/app/components/ui/SidebarTool.tsx
index 2718e75..92bb67d 100644
--- a/app/components/ui/SidebarTool.tsx
+++ b/app/components/ui/SidebarTool.tsx
@@ -1,7 +1,7 @@
"use client";
import { Icon } from "@iconify/react";
-import { ReactNode } from "react";
+import { ReactNode, forwardRef } from "react";
interface SidebarToolProps {
icon: string | ReactNode;
@@ -12,16 +12,18 @@ interface SidebarToolProps {
disabled?: boolean;
}
-export function SidebarTool({ icon, label, isActive, onClick, badge, disabled }: SidebarToolProps) {
- return (
- <button
- onClick={disabled ? undefined : onClick}
- disabled={disabled}
- className={`relative flex flex-col items-center gap-1.5 transition-all duration-200 group w-full
+export const SidebarTool = forwardRef<HTMLButtonElement, SidebarToolProps>(
+ ({ icon, label, isActive, onClick, badge, disabled }, ref) => {
+ return (
+ <button
+ ref={ref}
+ onClick={disabled ? undefined : onClick}
+ disabled={disabled}
+ className={`relative flex flex-col items-center gap-1.5 transition-all duration-200 group w-full
${disabled ? "opacity-40 cursor-not-allowed" : "cursor-pointer"}
${isActive ? "text-white" : "text-white/60 hover:text-white"}`
- }
- >
+ }
+ >
{badge && (
<div className="absolute -top-1 -right-0.5 z-10 px-1.5 py-0.5 bg-linear-to-r from-gray-500 to-gray-500 rounded-full border border-white/20 shadow-lg pointer-events-none">
<span className="text-[8px] font-bold text-white tracking-widest uppercase block drop-shadow-sm leading-none">
@@ -65,4 +67,6 @@ export function SidebarTool({ icon, label, isActive, onClick, badge, disabled }:
)}
</button>
);
-}
\ No newline at end of file
+});
+
+SidebarTool.displayName = "SidebarTool";
\ No newline at end of file
diff --git a/app/components/ui/editor/AudioFragmentTrackItem.tsx b/app/components/ui/editor/AudioFragmentTrackItem.tsx
index b2fd230..e6df777 100644
--- a/app/components/ui/editor/AudioFragmentTrackItem.tsx
+++ b/app/components/ui/editor/AudioFragmentTrackItem.tsx
@@ -5,6 +5,7 @@ import { motion, useMotionValue } from "framer-motion";
import type { AudioTrack, UploadedAudio } from "@/types/audio.types";
const MIN_FRAGMENT_DURATION = 0.1;
+const MIN_VISUAL_WIDTH_PX = 50;
interface AudioFragmentTrackItemProps {
track: AudioTrack;
@@ -50,17 +51,19 @@ export function AudioFragmentTrackItem({
const initialLeft = timeToPixels(track.startTime);
const initialWidth = timeToPixels(track.duration);
+
+ const visualWidth = Math.max(initialWidth, MIN_VISUAL_WIDTH_PX);
useEffect(() => {
if (!isDragging && !isResizing) {
fragmentX.set(initialLeft);
- fragmentWidth.set(initialWidth);
+ fragmentWidth.set(visualWidth);
}
- }, [initialLeft, initialWidth, isDragging, isResizing, fragmentX, fragmentWidth]);
+ }, [initialLeft, visualWidth, isDragging, isResizing, fragmentX, fragmentWidth]);
const boundaries = useMemo(() => {
const sorted = [...otherTracks]
- .filter(t => t.id !== track.id) // defensive: excluye el propio track
+ .filter(t => t.id !== track.id)
.sort((a, b) => a.startTime - b.startTime);
let minStart = 0;
@@ -184,7 +187,6 @@ export function AudioFragmentTrackItem({
}, [fragmentX, fragmentWidth, pixelsToTime, audio, videoDuration, onUpdate, onDragStateChange]);
const isInteracting = isDragging || isResizing !== null;
- const exceedsVideoDuration = track.startTime + track.duration > videoDuration;
const [isHovered, setIsHovered] = useState(false);
return (
diff --git a/app/components/ui/editor/Timeline.tsx b/app/components/ui/editor/Timeline.tsx
index f31bb56..ae9c20b 100644
--- a/app/components/ui/editor/Timeline.tsx
+++ b/app/components/ui/editor/Timeline.tsx
@@ -46,7 +46,6 @@ export function Timeline({
const [isDraggingZoomFragment, setIsDraggingZoomFragment] = useState(false);
const [isOverFragment, setIsOverFragment] = useState(false);
- // Use requestAnimationFrame for smooth scrubbing synced with display refresh
const pendingSeekRef = useRef<number | null>(null);
const rafIdRef = useRef<number | null>(null);
const isSeekingRef = useRef<boolean>(false);
@@ -54,10 +53,7 @@ export function Timeline({
const [ghostX, setGhostX] = useState(0);
const validDuration = Number.isFinite(videoDuration) && videoDuration > 0 ? videoDuration : 0;
- // Store pending trim values during drag to avoid excessive parent updates
const pendingTrimRef = useRef<{ start: number; end: number } | null>(null);
- // Trimmed duration for display
-
const TRACK_PADDING = 16;
@@ -80,10 +76,7 @@ export function Timeline({
useEffect(() => {
validDurationMotion.set(validDuration);
}, [validDuration, validDurationMotion]);
- const calculateDuration = useCallback(([start, end, cw, vd]: number[]) => {
- if (cw === 0 || vd === 0) return 0;
- return ((end - start) / cw) * vd;
- }, []);
+
const trimmedDurationLabel = useTransform(
[trimStartX, trimEndX, contentWidthMotion, validDurationMotion] as const,
([start, end, cw, vd]: number[]) => {
diff --git a/app/components/ui/editor/ToolsSidebar.tsx b/app/components/ui/editor/ToolsSidebar.tsx
index d60c169..c9f2ff7 100644
--- a/app/components/ui/editor/ToolsSidebar.tsx
+++ b/app/components/ui/editor/ToolsSidebar.tsx
@@ -3,13 +3,16 @@
import { Icon } from "@iconify/react";
import { SidebarTool } from "../SidebarTool";
import type { ToolsSidebarProps } from "@/types/tool-sidebar.types";
-import { useRef, useState } from "react";
+import { useRef, useState, useEffect } from "react";
import { TooltipAction } from "@/components/ui/tooltip-action";
+import { useRecording } from "@/hooks/RecordingContext";
interface ExtendedToolsSidebarProps extends ToolsSidebarProps {
onVideoUpload?: (file: File) => void;
isUploading?: boolean;
isCursorEnabled?: boolean;
+ selectedZoomFragmentId?: string | null;
+ selectedAudioTrackId?: string | null;
}
export function ToolsSidebar({
@@ -17,10 +20,28 @@ export function ToolsSidebar({
onToolChange,
onVideoUpload,
isUploading = false,
- isCursorEnabled = false
+ isCursorEnabled = false,
+ selectedZoomFragmentId,
+ selectedAudioTrackId,
}: ExtendedToolsSidebarProps) {
const fileInputRef = useRef<HTMLInputElement>(null);
+ const zoomToolRef = useRef<HTMLButtonElement>(null);
+ const audioToolRef = useRef<HTMLButtonElement>(null);
const [isDragging, setIsDragging] = useState(false);
+ const { startCountdown, isIdle, isRecording, isCountdown, isProcessing } = useRecording();
+ const [showMobileAlert, setShowMobileAlert] = useState(false);
+
+ useEffect(() => {
+ if (selectedZoomFragmentId && zoomToolRef.current) {
+ zoomToolRef.current.scrollIntoView({ behavior: 'smooth', block: 'center' });
+ }
+ }, [selectedZoomFragmentId]);
+
+ useEffect(() => {
+ if (selectedAudioTrackId && audioToolRef.current) {
+ audioToolRef.current.scrollIntoView({ behavior: 'smooth', block: 'center' });
+ }
+ }, [selectedAudioTrackId]);
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
@@ -60,20 +81,62 @@ export function ToolsSidebar({
}
};
+ const handleStartRecording = () => {
+ const isMobile = typeof window !== "undefined" &&
+ (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) || window.innerWidth < 768);
+
+ if (isMobile) {
+ setShowMobileAlert(true);
+ setTimeout(() => setShowMobileAlert(false), 5000);
+ } else {
+ startCountdown();
+ }
+ };
+
+ const getRecordButtonContent = () => {
+ if (isCountdown) {
+ return {
+ icon: "svg-spinners:ring-resize",
+ text: "Preparando...",
+ className: "text-orange-400"
+ };
+ }
+ if (isRecording) {
+ return {
+ icon: "fluent:record-20-filled",
+ text: "Grabando...",
+ className: "text-red-400 animate-pulse"
+ };
+ }
+ if (isProcessing) {
+ return {
+ icon: "svg-spinners:ring-resize",
+ text: "Procesando...",
+ className: "text-blue-400"
+ };
+ }
+ return {
+ icon: "fluent:screenshot-record-16-regular",
+ text: "Grabar",
+ className: "group-hover:text-red-400"
+ };
+ };
+
+ const recordButtonContent = getRecordButtonContent();
+
return (
<div className="relative shrink-0 bg-[#141417]" style={{ width: '90px' }}>
<div className="h-13 border-b border-white/10 w-full" />
<aside
- className="h-full absolute top-1/2 left-12 -translate-x-1/2 -translate-y-1/2 flex flex-col items-center justify-center gap-4 squircle-element border shadow-md shadow-white/20 border-white/10 z-40"
+ className="h-full absolute top-1/2 left-12 -translate-x-1/2 -translate-y-1/2 flex flex-col items-center justify-center gap-4 squircle-element border shadow-md shadow-white/20 border-white/10 z-40 max-h-150 3xl:max-h-[800px]"
style={{
height: 'calc(100% - 2rem)',
- maxHeight: '600px',
minWidth: '70px',
background: 'radial-gradient(circle at 50% 30%, #2a2a2a 0%, #131313 64%)',
}}
>
<div className="flex flex-col gap-4 w-full overflow-y-auto px-2 custom-scrollbar mask-y-from-85% mask-y-to-99%">
-
+
<div className="shrink-0 h-12" aria-hidden="true" />
<SidebarTool
@@ -88,16 +151,6 @@ export function ToolsSidebar({
isActive={activeTool === "mockup"}
onClick={() => onToolChange("mockup")}
/>
-
- <SidebarTool
- icon="solar:cursor-bold-duotone"
- label="Cursor"
- isActive={activeTool === "cursor"}
- onClick={() => onToolChange("cursor")}
- badge={!isCursorEnabled ? "Pronto" : undefined}
- disabled={!isCursorEnabled}
- />
-
<SidebarTool
label="Elementos"
isActive={activeTool === "elements"}
@@ -126,24 +179,64 @@ export function ToolsSidebar({
label="Audio"
isActive={activeTool === "audio"}
onClick={() => onToolChange("audio")}
+ ref={audioToolRef}
/>
<SidebarTool
icon="iconamoon:zoom-in-bold"
label="Zoom"
isActive={activeTool === "zoom"}
onClick={() => onToolChange("zoom")}
+ ref={zoomToolRef}
+ />
+ <SidebarTool
+ icon="solar:cursor-bold-duotone"
+ label="Cursor"
+ isActive={activeTool === "cursor"}
+ onClick={() => onToolChange("cursor")}
+ badge={!isCursorEnabled ? "Pronto" : undefined}
+ disabled={!isCursorEnabled}
/>
<div className="shrink-0 h-12" aria-hidden="true" />
</div>
-
+
<div
- className="w-full p-2 relative flex flex-col items-center shrink-0 group"
+ className="w-full p-2 relative flex flex-col items-center gap-1 shrink-0 group"
onDragOver={handleDragOver}
onDragLeave={handleDragLeave}
onDrop={handleDrop}
>
<div className="absolute -top-0.5 left-0 w-full border-t border-white/10" />
+
+ {showMobileAlert && (
+ <div className="absolute bottom-full mb-2 left-1/2 -translate-x-1/2 w-64 p-3 bg-red-500/10 border border-red-500/30 rounded-lg text-xs text-red-300 z-50">
+ La captura de pantalla no está soportada en móviles. Usa tu computadora.
+ </div>
+ )}
+
+ <TooltipAction label={isIdle ? "Grabar pantalla" : "Grabación en proceso..."}>
+ <button
+ onClick={handleStartRecording}
+ disabled={!isIdle}
+ 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"}`}>
+ {recordButtonContent.text}
+ </span>
+ </button>
+ </TooltipAction>
+
<TooltipAction label={isUploading ? "Subiendo video..." : "Subir video personalizado"}>
<button
onClick={handleUploadClick}
@@ -169,7 +262,7 @@ export function ToolsSidebar({
height="24"
/>
<span className="text-xs font-medium">
- {isDragging ? "Suelta aquí" : "Subir video"}
+ {isDragging ? "Suelta aquí" : "Subir"}
</span>
</>
)}
diff --git a/hooks/useScreenRecording.ts b/hooks/useScreenRecording.ts
index 3e3c062..12e62b6 100644
--- a/hooks/useScreenRecording.ts
+++ b/hooks/useScreenRecording.ts
@@ -1,7 +1,7 @@
"use client";
import { useState, useCallback, useRef, useEffect } from "react";
-import { useRouter } from "next/navigation";
+import { useRouter, usePathname } from "next/navigation";
import type { RecordingState, RecordingResult, VideoData } from "@/types";
// import type { CursorKeyframe, CursorRecordingData, CursorState } from "@/types/cursor.types";
// import { EMPTY_CURSOR_DATA, supportsCursorCapture } from "@/types/cursor.types";
@@ -218,6 +218,7 @@ export function useScreenRecording() {
const [recordingTime, setRecordingTime] = useState<number>(0);
const router = useRouter();
+ const pathname = usePathname();
const mediaRecorderRef = useRef<MediaRecorder | null>(null);
const streamRef = useRef<MediaStream | null>(null);
const chunksRef = useRef<Blob[]>([]);
@@ -380,7 +381,12 @@ export function useScreenRecording() {
try {
await saveVideoToIndexedDB(blob, duration, /* cursorData */);
- router.push("/editor");
+
+ if (pathname === "/editor") {
+ window.location.reload();
+ } else {
+ router.push("/editor");
+ }
} catch (error) {
console.error("Error al guardar video:", error);
setError("Error al procesar el video");
@@ -403,7 +409,7 @@ export function useScreenRecording() {
setState("idle");
restoreOriginals();
}
- }, [router, restoreOriginals]);
+ }, [router, pathname, restoreOriginals]);
const startCountdown = useCallback(async () => {
try {
diff --git a/lib/canvas.utils.ts b/lib/canvas.utils.ts
index 2b1221a..ef4bf99 100644
--- a/lib/canvas.utils.ts
+++ b/lib/canvas.utils.ts
@@ -347,16 +347,16 @@ export function getNearestCorner(e: React.MouseEvent<HTMLElement>, rotationDeg =
}
export function getCornerStyle(corner: Corner, offset = -10): React.CSSProperties {
- const base: React.CSSProperties = { position: "absolute", zIndex: 20 };
+ const base: React.CSSProperties = { position: "absolute", zIndex: 20, cursor: "grab" };
switch (corner) {
case "top-left":
- return { ...base, top: offset, left: offset, cursor: "nw-resize" };
+ return { ...base, top: offset, left: offset };
case "top-right":
- return { ...base, top: offset, right: offset, cursor: "ne-resize" };
+ return { ...base, top: offset, right: offset };
case "bottom-right":
- return { ...base, bottom: offset, right: offset, cursor: "se-resize" };
+ return { ...base, bottom: offset, right: offset };
case "bottom-left":
- return { ...base, bottom: offset, left: offset, cursor: "sw-resize" };
+ return { ...base, bottom: offset, left: offset };
}
}