Skip to content

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

feat: add new HeroEditorPreview components and utilities

CristianOlivera14af81926143f
diff --git a/app/[locale]/(home)/page.tsx b/app/[locale]/(home)/page.tsx
index b4960be..94c1898 100644
--- a/app/[locale]/(home)/page.tsx
+++ b/app/[locale]/(home)/page.tsx
@@ -1,5 +1,4 @@
import Hero from "@/app/components/ui/home/Hero";
-import InteractiveRecordingSteps from "@/app/components/ui/home/RecordingSteps";
import {
StructuredData,
generateWebAppSchema,
@@ -8,13 +7,13 @@ import {
} from "@/app/components/seo/StructuredData";
import type { Metadata } from "next";
import DonationCard from "@/app/components/ui/home/DonationCard";
-import VideoHero from "@/app/components/ui/home/VideoHero";
import BannerCTA from "@/app/components/ui/home/BannerCTA";
import FeaturesGrid from "@/app/components/ui/home/Featuresgrid";
import FeaturesShowcase from "@/app/components/ui/home/FeaturesShowcase";
import SocialReactions from "@/app/components/ui/home/SocialReactions";
import { buildPageMetadata } from "@/lib/seo";
import { setRequestLocale } from "next-intl/server";
+import HeroEditorPreview from "@/app/components/ui/home/HeroEditorPreview";
type Props = {
params: Promise<{ locale: string }>;
@@ -118,7 +117,7 @@ export default async function Home({ params }: Props) {
<div className="max-w-6xl mx-auto px-6 text-center relative z-10">
<Hero />
</div>
- <VideoHero />
+ <HeroEditorPreview />
</section>
<div className="absolute inset-x-0 bottom-0 h-40 bg-linear-to-t from-[#0a0a0a] to-transparent pointer-events-none z-20" />
</div>
diff --git a/app/[locale]/layout.tsx b/app/[locale]/layout.tsx
index ff49df6..ba1eb4b 100644
--- a/app/[locale]/layout.tsx
+++ b/app/[locale]/layout.tsx
@@ -158,6 +158,7 @@ export default async function LocaleLayout({
donation: messages.donation,
notFound: messages.notFound,
tour: messages.tour,
+ heroPreview: messages.heroPreview
};
const isProduction = process.env.NODE_ENV === "production";
diff --git a/app/components/ui/editor/ControlPanel.tsx b/app/components/ui/editor/ControlPanel.tsx
index 1e652c6..f9b3f25 100644
--- a/app/components/ui/editor/ControlPanel.tsx
+++ b/app/components/ui/editor/ControlPanel.tsx
@@ -20,8 +20,8 @@ import { useMockup3dContext } from "@/app/contexts/Mockup3dContext";
const BackgroundColorEditor = lazy(() => import("../BackgroundColorEditor").then(mod => ({ default: mod.BackgroundColorEditor })));
const ZoomFragmentEditor = lazy(() => import("./ZoomFragmentEditor").then(mod => ({ default: mod.ZoomFragmentEditor })));
const ZoomGlobalConfig = lazy(() => import("./ZoomGlobalConfig").then(mod => ({ default: mod.ZoomGlobalConfig })));
-const OptionsGrid = lazy(() => import("../WalpaperSections").then(mod => ({ default: mod.OptionsGrid })));
-const WallpaperCatalogGrid = lazy(() => import("../WalpaperSections").then(mod => ({ default: mod.WallpaperCatalogGrid })));
+const OptionsGrid = lazy(() => import("../WallpaperSections").then(mod => ({ default: mod.OptionsGrid })));
+const WallpaperCatalogGrid = lazy(() => import("../WallpaperSections").then(mod => ({ default: mod.WallpaperCatalogGrid })));
const MockupMenu = lazy(() => import("./MockupMenu").then(mod => ({ default: mod.MockupMenu })));
const AudioMenu = lazy(() => import("./AudioMenu").then(mod => ({ default: mod.AudioMenu })));
const VideosMenu = lazy(() => import("./VideosMenu").then(mod => ({ default: mod.VideosMenu })));
@@ -219,38 +219,44 @@ export function ControlPanel({
</Suspense>
)}
- <SliderControl
- icon="mdi:blur"
- label={t("screenshot.sliders.blur")}
- value={backgroundBlur}
- min={0}
- max={30}
- onChange={onBackgroundBlurChange}
- />
- <SliderControl
- icon="mdi:arrow-expand-all"
- label={t("screenshot.sliders.padding")}
- value={padding}
- min={0}
- max={30}
- onChange={onPaddingChange}
- />
- <SliderControl
- icon="mdi:border-radius"
- label={t("screenshot.sliders.rounded")}
- value={roundedCorners}
- min={0}
- max={30}
- onChange={onRoundedCornersChange}
- />
- <SliderControl
- icon="material-symbols:shadow"
- label={t("screenshot.sliders.shadows")}
- value={shadows}
- min={0}
- max={30}
- onChange={onShadowsChange}
- />
+ <div className="flex flex-col gap-4 mt-2">
+ <div className="text-[11px] uppercase tracking-widest text-white/70 font-bold flex items-center gap-1.5">
+ <span>{t("screenshot.settings")}</span>
+ </div>
+
+ <SliderControl
+ icon="mdi:blur"
+ label={t("screenshot.sliders.blur")}
+ value={backgroundBlur}
+ min={0}
+ max={30}
+ onChange={onBackgroundBlurChange}
+ />
+ <SliderControl
+ icon="mdi:arrow-expand-all"
+ label={t("screenshot.sliders.padding")}
+ value={padding}
+ min={0}
+ max={30}
+ onChange={onPaddingChange}
+ />
+ <SliderControl
+ icon="mdi:border-radius"
+ label={t("screenshot.sliders.rounded")}
+ value={roundedCorners}
+ min={0}
+ max={30}
+ onChange={onRoundedCornersChange}
+ />
+ <SliderControl
+ icon="material-symbols:shadow"
+ label={t("screenshot.sliders.shadows")}
+ value={shadows}
+ min={0}
+ max={30}
+ onChange={onShadowsChange}
+ />
+ </div>
</div>
</>
)}
diff --git a/app/components/ui/editor/VideoClipTrackItem.tsx b/app/components/ui/editor/VideoClipTrackItem.tsx
index 6009433..5eab330 100644
--- a/app/components/ui/editor/VideoClipTrackItem.tsx
+++ b/app/components/ui/editor/VideoClipTrackItem.tsx
@@ -62,8 +62,6 @@ export function VideoClipTrackItem({
const initialLeft = timeToPixels(clip.startTime);
const initialWidth = timeToPixels(clipDuration);
- const clipEndTime = clip.startTime + clipDuration;
-
const progressWidth = useTransform(
playheadX,
(px) => {
diff --git a/app/components/ui/home/Hero.tsx b/app/components/ui/home/Hero.tsx
index 63e9e1e..be02bf2 100644
--- a/app/components/ui/home/Hero.tsx
+++ b/app/components/ui/home/Hero.tsx
@@ -140,7 +140,6 @@ export default function Hero({ onVideoUpload, onPhotoUpload }: HeroProps) {
<div className="animate-reveal [animation-delay:300ms] flex flex-col sm:flex-row items-center justify-center gap-3 mb-2">
<div className="flex flex-col items-center gap-2 w-full sm:w-72">
- {/* AÑADIDO: id="tour-video-upload" */}
<div
id="tour-video-upload"
onDragOver={handleVideoDragOver}
@@ -194,7 +193,6 @@ export default function Hero({ onVideoUpload, onPhotoUpload }: HeroProps) {
</div>
<div className="flex flex-col items-center gap-2 w-full sm:w-72">
- {/* AÑADIDO: id="tour-photo-upload" */}
<div
id="tour-photo-upload"
onDragOver={handlePhotoDragOver}
diff --git a/app/components/ui/home/HeroEditorPreview.tsx b/app/components/ui/home/HeroEditorPreview.tsx
new file mode 100644
index 0000000..fd3e1fd
--- /dev/null
+++ b/app/components/ui/home/HeroEditorPreview.tsx
@@ -0,0 +1,786 @@
+"use client";
+
+import { useEffect, useMemo, useRef, useState, useCallback } from "react";
+import { Icon } from "@iconify/react";
+import { motion, AnimatePresence } from "framer-motion";
+import { useTranslations } from "next-intl";
+import { calculateSmoothZoom } from "@/lib/canvas.utils";
+import { zoomLevelToFactor, type ZoomFragment } from "@/types/zoom.types";
+import { formatTime } from "@/lib";
+import {
+ ACCENT,
+ BackgroundCategory,
+ CLIP_MIN_DURATION,
+ DRAG_CLAMP_PCT,
+ DRAG_EASE_FACTOR,
+ DRIFT_AMPLITUDE_X,
+ DRIFT_AMPLITUDE_Y,
+ HERO_GRADIENTS,
+ HERO_WALLPAPERS,
+ PANEL_BORDER,
+ SLIDER_MAX,
+ TFunc,
+ THUMB,
+ THUMB_COLS,
+ THUMB_STEP,
+ TILT_MAX_DEG,
+ ZOOM_FRAGMENT_DURATIONS,
+ clamp,
+ getInitialZoomFragments,
+ hashSeed,
+ organicDrift,
+} from "@/lib/editor-preview-hero.utils";
+import { BackgroundPanel, DraggableRange, MiniSidebar, TimelineClipContent, ZoomFragmentRangeItem } from "@/components/ui/HeroEditorPreviewComponents";
+
+function EditorCanvas({
+ videoRef,
+ videoTransform,
+ transformOrigin,
+ onLoadedMetadata,
+ backgroundUrl,
+ zoomScale,
+ focusPoint,
+ pulseKey,
+ roundedPx,
+ paddingPct,
+ backgroundBlurPx,
+ dynamicShadow,
+ dragOffset,
+ onDragOffsetChange,
+ onDragRelease,
+}: {
+ videoRef: React.RefObject<HTMLVideoElement | null>;
+ videoTransform: string;
+ transformOrigin: string;
+ onLoadedMetadata: () => void;
+ backgroundUrl: string | undefined;
+ zoomScale: number;
+ focusPoint: { x: number; y: number };
+ pulseKey: string | null;
+ roundedPx: number;
+ paddingPct: number;
+ backgroundBlurPx: number;
+ dynamicShadow: string;
+ dragOffset: { x: number; y: number };
+ onDragOffsetChange: (next: { x: number; y: number }) => void;
+ onDragRelease: () => void;
+}) {
+ const isZoomActive = zoomScale > 1.03;
+ const inverseScale = 1 / zoomScale;
+
+ const frameRef = useRef<HTMLDivElement>(null);
+ const dragStateRef = useRef<{
+ startX: number;
+ startY: number;
+ originX: number;
+ originY: number;
+ } | null>(null);
+ const [isDragging, setIsDragging] = useState(false);
+
+ const handleFramePointerDown = useCallback(
+ (e: React.PointerEvent) => {
+ if (e.button !== undefined && e.button !== 0) return;
+ const frame = frameRef.current;
+ if (!frame) return;
+ e.preventDefault();
+
+ dragStateRef.current = {
+ startX: e.clientX,
+ startY: e.clientY,
+ originX: dragOffset.x,
+ originY: dragOffset.y,
+ };
+ setIsDragging(true);
+
+ const handleMove = (ev: PointerEvent) => {
+ const drag = dragStateRef.current;
+ const rect = frame.getBoundingClientRect();
+ if (!drag || rect.width <= 0 || rect.height <= 0) return;
+
+ const deltaXPct = ((ev.clientX - drag.startX) / rect.width) * 100;
+ const deltaYPct = ((ev.clientY - drag.startY) / rect.height) * 100;
+
+ onDragOffsetChange({
+ x: clamp(drag.originX + deltaXPct, -DRAG_CLAMP_PCT, DRAG_CLAMP_PCT),
+ y: clamp(drag.originY + deltaYPct, -DRAG_CLAMP_PCT, DRAG_CLAMP_PCT),
+ });
+ };
+
+ const handleUp = () => {
+ dragStateRef.current = null;
+ setIsDragging(false);
+ onDragRelease();
+ window.removeEventListener("pointermove", handleMove);
+ window.removeEventListener("pointerup", handleUp);
+ };
+
+ window.addEventListener("pointermove", handleMove);
+ window.addEventListener("pointerup", handleUp);
+ },
+ [dragOffset, onDragOffsetChange, onDragRelease]
+ );
+
+ return (
+ <div className="flex-1 relative flex items-center justify-center overflow-hidden bg-[#0B0B0D] squircle-element-camera">
+ <AnimatePresence mode="sync">
+ {backgroundUrl && (
+ <motion.div
+ key={backgroundUrl}
+ className="absolute inset-0 bg-cover bg-center"
+ style={{
+ backgroundImage: `url('${backgroundUrl}')`,
+ filter: `blur(${backgroundBlurPx}px)`,
+ transform: "scale(1.15)",
+ }}
+ initial={{ opacity: 0 }}
+ animate={{ opacity: 1 }}
+ exit={{ opacity: 0 }}
+ transition={{ duration: 0.9 }}
+ />
+ )}
+ </AnimatePresence>
+ <div className="absolute inset-0 bg-black/10" />
+ <div
+ ref={frameRef}
+ onPointerDown={handleFramePointerDown}
+ className={`relative w-[78%] sm:w-[80%] aspect-video cursor-move touch-none select-none transition-opacity ${isDragging ? "opacity-95" : ""
+ }`}
+ style={{ perspective: "900px" }}
+ >
+ <div
+ className="absolute inset-0"
+ style={{
+ transform: videoTransform,
+ transformOrigin: transformOrigin,
+ willChange: "transform",
+ }}
+ >
+ <div
+ className="absolute overflow-hidden bg-black squircle-corner"
+ style={{
+ inset: `${paddingPct}%`,
+ borderRadius: `${roundedPx}px`,
+ boxShadow: dynamicShadow,
+ }}
+ >
+ <video
+ ref={videoRef}
+ autoPlay
+ loop
+ muted
+ playsInline
+ preload="metadata"
+ poster="/images/pages/demo-hero-poster.webp"
+ onLoadedMetadata={onLoadedMetadata}
+ draggable={false}
+ onDragStart={(e) => e.preventDefault()}
+ className="block w-full h-full object-cover pointer-events-none"
+ >
+ <source src="/videos/hero/demo-preview-editor.mp4" type="video/mp4" />
+ </video>
+ <AnimatePresence>
+ {isZoomActive && focusPoint && (
+ <motion.div
+ key="focus-cursor"
+ className="absolute z-10 pointer-events-none"
+ style={{
+ left: `${focusPoint.x}%`,
+ top: `${focusPoint.y}%`,
+ translateX: "-50%",
+ translateY: "-50%",
+ transition: "left 90ms ease-out, top 90ms ease-out",
+ }}
+ initial={{ opacity: 0, scale: 1.4 * inverseScale }}
+ animate={{ opacity: 0.9, scale: inverseScale }}
+ exit={{ opacity: 0, scale: 1.4 * inverseScale }}
+ transition={{ duration: 0.35, ease: [0.22, 1, 0.36, 1] }}
+ >
+ <div className="w-6 h-6 rounded-full border border-white/70" />
+ <div className="absolute inset-0 m-auto w-1 h-1 rounded-full bg-white" />
+ </motion.div>
+ )}
+ </AnimatePresence>
+ <AnimatePresence>
+ {pulseKey && focusPoint && (
+ <motion.div
+ key={pulseKey}
+ className="absolute z-[9] pointer-events-none rounded-full border border-white/50"
+ style={{
+ left: `${focusPoint.x}%`,
+ top: `${focusPoint.y}%`,
+ translateX: "-50%",
+ translateY: "-50%",
+ width: 24,
+ height: 24,
+ }}
+ initial={{ opacity: 0.55, scale: 0.4 * inverseScale }}
+ animate={{ opacity: 0, scale: 2.4 * inverseScale }}
+ transition={{ duration: 0.55, ease: "easeOut" }}
+ />
+ )}
+ </AnimatePresence>
+ </div>
+ </div>
+ <AnimatePresence>
+ {isZoomActive && (
+ <motion.div
+ initial={{ opacity: 0, y: -4 }}
+ animate={{ opacity: 1, y: 0 }}
+ exit={{ opacity: 0, y: -4 }}
+ className="absolute top-2.5 right-2.5 z-50 flex items-center gap-1 px-2 py-1 rounded-full bg-black/60 backdrop-blur-sm shadow-sm"
+ >
+ <Icon icon="iconamoon:zoom-in-bold" width={11} className="text-white" />
+ <span className="text-[10px] font-mono text-white">{zoomScale.toFixed(2)}×</span>
+ </motion.div>
+ )}
+ </AnimatePresence>
+ </div>
+ </div>
+ );
+}
+
+function EditorTimeline({
+ t,
+ duration,
+ currentTime,
+ fragments,
+ onFragmentChange,
+ clipRange,
+ onClipChange,
+ trackRef,
+ onSeek,
+}: {
+ t: TFunc;
+ duration: number;
+ currentTime: number;
+ fragments: ZoomFragment[];
+ onFragmentChange: (id: string, next: { start: number; end: number }) => void;
+ clipRange: { start: number; end: number };
+ onClipChange: (next: { start: number; end: number }) => void;
+ trackRef: React.RefObject<HTMLDivElement | null>;
+ onSeek: (time: number) => void;
+}) {
+ const [selectedId, setSelectedId] = useState<string | null>(null);
+ const videoLabel = t("timeline.video");
+ const zoomLabel = t("timeline.zoom");
+
+ const handleToggleSelect = useCallback((id: string) => {
+ setSelectedId((prev) => (prev === id ? null : id));
+ }, []);
+
+ const playheadPct = duration > 0 ? (currentTime / duration) * 100 : 0;
+ const clipProgress =
+ clipRange.end > clipRange.start
+ ? clamp((currentTime - clipRange.start) / (clipRange.end - clipRange.start), 0, 1)
+ : 0;
+
+ const handleSeekPointerDown = useCallback(
+ (e: React.PointerEvent) => {
+ const track = trackRef.current;
+ if (!track || duration <= 0) return;
+ e.preventDefault();
+
+ const seekFromClientX = (clientX: number) => {
+ const rect = track.getBoundingClientRect();
+ if (rect.width <= 0) return;
+ onSeek(clamp((clientX - rect.left) / rect.width, 0, 1) * duration);
+ };
+
+ seekFromClientX(e.clientX);
+ const handleMove = (ev: PointerEvent) => seekFromClientX(ev.clientX);
+ const handleUp = () => {
+ window.removeEventListener("pointermove", handleMove);
+ window.removeEventListener("pointerup", handleUp);
+ };
+ window.addEventListener("pointermove", handleMove);
+ window.addEventListener("pointerup", handleUp);
+ },
+ [duration, trackRef, onSeek]
+ );
+
+ return (
+ <div className={`hidden sm:flex h-[140px] shrink-0 border-t ${PANEL_BORDER} bg-white`}>
+ <div className={`w-10 shrink-0 border-r ${PANEL_BORDER} flex flex-col bg-zinc-50/50`}>
+ <div className="h-4 border-b border-black/5" />
+ <div className="flex-1 flex items-center px-2 border-b border-black/3">
+ <span className="text-[7px] uppercase font-semibold tracking-wider text-zinc-400">{videoLabel}</span>
+ </div>
+ <div className="flex-1 flex items-center px-2">
+ <span className="text-[7px] uppercase font-semibold tracking-wider text-zinc-400">{zoomLabel}</span>
+ </div>
+ </div>
+
+ <div className="flex-1 relative">
+ <div className="relative h-full w-full bg-black/2 overflow-visible">
+ <div ref={trackRef} onPointerDown={handleSeekPointerDown} className="absolute left-1 right-1 inset-y-0 cursor-ew-resize flex flex-col" >
+ <div className="relative h-4 border-b border-black/6 shrink-0">
+ {[0, 0.25, 0.5, 0.75, 1].map((f) => (
+ <span
+ key={f}
+ className="absolute top-0 flex items-center h-full text-[8px] font-mono text-black/30"
+ style={{
+ left: `${f * 100}%`,
+ transform: f === 0 ? "none" : f === 1 ? "translateX(-100%)" : "translateX(-50%)",
+ }}
+ >
+ {formatTime(f * duration)}
+ </span>
+ ))}
+ </div>
+
+ <div className="flex-1 relative border-b border-black/3">
+ <div className="absolute inset-x-0 inset-y-2">
+ <DraggableRange
+ start={clipRange.start}
+ end={clipRange.end}
+ duration={duration}
+ trackRef={trackRef}
+ minDuration={CLIP_MIN_DURATION}
+ onChange={onClipChange}
+ onClick={() => setSelectedId((prev) => (prev === "main-clip" ? null : "main-clip"))}
+ handleClassName="bg-emerald-500 group-hover/range:bg-emerald-600/80"
+ >
+ <TimelineClipContent
+ label="demo-hero.mp4"
+ duration={clipRange.end - clipRange.start}
+ progress={clipProgress}
+ isSelected={selectedId === "main-clip"}
+ />
+ </DraggableRange>
+ </div>
+ </div>
+
+ <div className="flex-1 relative">
+ <div className="absolute inset-x-0 inset-y-2">
+ {duration > 0 &&
+ fragments.map((f) => (
+ <ZoomFragmentRangeItem
+ key={f.id}
+ fragment={f}
+ duration={duration}
+ trackRef={trackRef}
+ zoomLabel={zoomLabel}
+ isSelected={selectedId === f.id}
+ onChange={onFragmentChange}
+ onToggle={handleToggleSelect}
+ />
+ ))}
+ </div>
+ </div>
+
+ <div
+ className="absolute top-0 bottom-0 w-px z-30 pointer-events-none"
+ style={{ left: `${playheadPct}%`, background: ACCENT }}
+ >
+ <div
+ className="absolute -top-px -translate-x-1/2 w-2.5 h-2.5"
+ style={{
+ background: ACCENT,
+ clipPath: "polygon(0% 0%, 100% 0%, 100% 60%, 50% 100%, 0% 60%)",
+ }}
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+}
+
+function TransportBar({
+ t,
+ isPlaying,
+ currentTime,
+ duration,
+ onTogglePlay,
+ onSkip,
+}: {
+ t: TFunc;
+ isPlaying: boolean;
+ currentTime: number;
+ duration: number;
+ onTogglePlay: () => void;
+ onSkip: (delta: number) => void;
+}) {
+ return (
+ <div className={`hidden sm:flex h-11 shrink-0 border-t ${PANEL_BORDER} bg-white items-center justify-between px-3`}>
+ <div className="hidden sm:flex items-center gap-2.5" aria-hidden="true">
+ <Icon icon="mingcute:scissors-fill" width={13} className="text-black/30 cursor-pointer hover:text-black/50 transition-colors" />
+ <div className="h-3.5 w-px bg-black/8" />
+
+ <div className="flex items-center gap-1.5">
+ <Icon icon="mdi:magnify-minus-outline" width={14} className="text-black/30 cursor-pointer hover:text-black/50 transition-colors" />
+ <div className="w-12 h-0.5 bg-black/8 rounded-full relative group cursor-pointer flex items-center">
+ <div className="absolute inset-y-0 left-0 rounded-full bg-black/30" style={{ width: "55%" }} />
+ <div
+ className="absolute w-2 h-2 bg-white rounded-full border border-black/10 shadow-sm transition-transform group-hover:scale-110 pointer-events-none"
+ style={{ left: "calc(55% - 4px)" }}
+ />
+ </div>
+ <Icon icon="mdi:magnify-plus-outline" width={14} className="text-black/30 cursor-pointer hover:text-black/50 transition-colors" />
+ <span className="text-[10px] font-mono text-black/40 min-w-[16px] text-left select-none ml-0.5">
+ 1×
+ </span>
+ </div>
+
+ <div className="h-3.5 w-px bg-black/8" />
+ <Icon icon="lucide:maximize" width={13} className="text-black/30 cursor-pointer hover:text-black/50 transition-colors" />
+ </div>
+
+ <div className="flex items-center gap-3">
+ <span className="text-[10px] font-mono text-black/40 tabular-nums">{formatTime(currentTime)}</span>
+ <div className="flex items-center gap-2">
+ <button onClick={() => onSkip(-5)} aria-label={t("transport.rewind")} className="text-black/40 hover:text-black transition-colors">
+ <Icon icon="mdi:rewind-5" width={17} />
+ </button>
+ <button
+ onClick={onTogglePlay}
+ aria-label={t(isPlaying ? "transport.pause" : "transport.play")}
+ className="w-7 h-7 flex items-center justify-center rounded-full bg-black/5 hover:bg-black/10 text-black transition-colors"
+ >
+ <Icon icon={isPlaying ? "mdi:pause" : "mdi:play"} width={15} />
+ </button>
+ <button onClick={() => onSkip(5)} aria-label={t("transport.forward")} className="text-black/40 hover:text-black transition-colors">
+ <Icon icon="mdi:fast-forward-5" width={17} />
+ </button>
+ </div>
+ <span className="text-[10px] font-mono text-black/40 tabular-nums">{formatTime(duration)}</span>
+ </div>
+ <div className="hidden sm:flex items-center gap-2" aria-hidden="true">
+ <div className="flex items-center justify-between px-2 py-1 w-22 rounded-md border border-black/10 text-[10px] text-black/60 cursor-pointer hover:bg-black/3 active:bg-black/6 transition-colors select-none">
+ <div className="flex items-center gap-1.5 min-w-0">
+ <Icon icon="material-symbols:gradient-outline" width={11} className="shrink-0" />
+ <span className="truncate font-medium">{t("transport.mask")}</span>
+ </div>
+ <Icon icon="lucide:chevron-down" width={11} className="shrink-0 text-black/35 group-hover:text-black/50" />
+ </div>
+ <div className="flex items-center justify-between px-2 py-1 w-22 rounded-md border border-black/10 text-[10px] text-black/60 cursor-pointer hover:bg-black/3 active:bg-black/6 transition-colors select-none">
+ <div className="flex items-center gap-1.5 min-w-0">
+ <Icon icon="mdi:crop" width={11} className="shrink-0" />
+ <span className="truncate font-medium">{t("transport.crop")}</span>
+ </div>
+ <Icon icon="lucide:chevron-down" width={11} className="shrink-0 text-black/35 group-hover:text-black/50" />
+ </div>
+
+ <div className="flex items-center justify-between px-2 py-1 w-22 rounded-md border border-black/10 text-[10px] text-black/60 cursor-pointer hover:bg-black/3 active:bg-black/6 transition-colors select-none">
+ <div className="flex items-center gap-1.5 min-w-0">
+ <Icon icon="mynaui:layout" width={11} className="shrink-0" />
+ <span className="truncate font-medium">{t("transport.auto")}</span>
+ </div>
+ <Icon icon="lucide:chevron-down" width={11} className="shrink-0 text-black/35 group-hover:text-black/50" />
+ </div>
+ </div>
+ </div>
+ );
+}
+
+export default function HeroEditorPreview() {
+ const t = useTranslations("heroPreview");
+
+ const videoRef = useRef<HTMLVideoElement>(null);
+ const trackRef = useRef<HTMLDivElement>(null);
+ const rafRef = useRef<number | null>(null);
+ const dragEaseRafRef = useRef<number | null>(null);
+ const initializedTimelineRef = useRef(false);
+
+ const [duration, setDuration] = useState(0);
+ const [currentTime, setCurrentTime] = useState(0);
+ const [isPlaying, setIsPlaying] = useState(true);
+
+ const [backgroundCategory, setBackgroundCategory] = useState<BackgroundCategory>("wallpaper");
+ const [activeSwatch, setActiveSwatch] = useState(0);
+ const [activeGradient, setActiveGradient] = useState(0);
+
+ const [clipRange, setClipRange] = useState<{ start: number; end: number }>({ start: 0, end: 0 });
+ const [fragments, setFragments] = useState<ZoomFragment[]>([]);
+
+ const [blurPercent, setBlurPercent] = useState(0);
+ const [paddingPercent, setPaddingPercent] = useState(0);
+ const [roundedPercent, setRoundedPercent] = useState(30);
+ const [shadowPercent, setShadowPercent] = useState(9);
+ const [dragOffset, setDragOffset] = useState({ x: 0, y: 0 });
+ const userSelectedBackgroundRef = useRef(false);
+
+ useEffect(() => {
+ const tick = () => {
+ const v = videoRef.current;
+ if (v) setCurrentTime(v.currentTime);
+ rafRef.current = requestAnimationFrame(tick);
+ };
+ rafRef.current = requestAnimationFrame(tick);
+ return () => {
+ if (rafRef.current) cancelAnimationFrame(rafRef.current);
+ };
+ }, []);
+
+ const cancelDragEase = useCallback(() => {
+ if (dragEaseRafRef.current !== null) {
+ cancelAnimationFrame(dragEaseRafRef.current);
+ dragEaseRafRef.current = null;
+ }
+ }, []);
+
+ const handleDragOffsetChange = useCallback(
+ (next: { x: number; y: number }) => {
+ cancelDragEase();
+ setDragOffset(next);
+ },
+ [cancelDragEase]
+ );
+
+ const handleDragRelease = useCallback(() => {
+ cancelDragEase();
+ const step = () => {
+ setDragOffset((prev) => {
+ const nx = prev.x * DRAG_EASE_FACTOR;
+ const ny = prev.y * DRAG_EASE_FACTOR;
+ if (Math.abs(nx) < 0.05 && Math.abs(ny) < 0.05) {
+ dragEaseRafRef.current = null;
+ return { x: 0, y: 0 };
+ }
+ dragEaseRafRef.current = requestAnimationFrame(step);
+ return { x: nx, y: ny };
+ });
+ };
+ dragEaseRafRef.current = requestAnimationFrame(step);
+ }, [cancelDragEase]);
+
+ useEffect(() => cancelDragEase, [cancelDragEase]);
+
+ const handleLoadedMetadata = useCallback(() => {
+ const v = videoRef.current;
+ if (v && Number.isFinite(v.duration)) setDuration(v.duration);
+ }, []);
+
+ useEffect(() => {
+ const v = videoRef.current;
+ if (v && v.readyState >= 1 && Number.isFinite(v.duration)) {
+ setDuration(v.duration);
+ }
+ }, []);
+
+ useEffect(() => {
+ if (duration <= 0 || initializedTimelineRef.current) return;
+ initializedTimelineRef.current = true;
+
+ setClipRange({ start: 0, end: Math.max(CLIP_MIN_DURATION, duration) });
+
+ setFragments(getInitialZoomFragments(duration, ZOOM_FRAGMENT_DURATIONS));
+ }, [duration]);
+
+ const handleFragmentChange = useCallback((id: string, next: { start: number; end: number }) => {
+ setFragments((prev) => prev.map((f) => (f.id === id ? { ...f, startTime: next.start, endTime: next.end } : f)));
+ }, []);
+
+ useEffect(() => {
+ if (HERO_WALLPAPERS.length === 0) return;
+ const id = setInterval(() => {
+ if (userSelectedBackgroundRef.current) return;
+ setActiveSwatch((prev) => (prev + 1) % HERO_WALLPAPERS.length);
+ }, 2600);
+ return () => clearInterval(id);
+ }, []);
+
+ const handleSelectWallpaper = useCallback((index: number) => {
+ userSelectedBackgroundRef.current = true;
+ setBackgroundCategory("wallpaper");
+ setActiveSwatch(index);
+ }, []);
+
+ const handleSelectGradient = useCallback((index: number) => {
+ userSelectedBackgroundRef.current = true;
+ setBackgroundCategory("gradient");
+ setActiveGradient(index);
+ }, []);
+
+ const handleSeek = useCallback(
+ (time: number) => {
+ const clamped = clamp(time, 0, duration || 0);
+ if (videoRef.current) videoRef.current.currentTime = clamped;
+ setCurrentTime(clamped);
+ },
+ [duration]
+ );
+
+ const togglePlay = useCallback(() => {
+ const v = videoRef.current;
+ if (!v) return;
+ if (v.paused) {
+ v.play().catch(() => undefined);
+ setIsPlaying(true);
+ } else {
+ v.pause();
+ setIsPlaying(false);
+ }
+ }, []);
+
+ const skip = useCallback((delta: number) => {
+ const v = videoRef.current;
+ if (!v || !Number.isFinite(v.duration)) return;
+ const clamped = Math.max(0, Math.min(v.duration, v.currentTime + delta));
+ v.currentTime = clamped;
+ setCurrentTime(clamped);
+ }, []);
+
+ const smoothZoom = useMemo(() => calculateSmoothZoom(currentTime, fragments), [currentTime, fragments]);
+
+ const activeFragment = useMemo(
+ () => fragments.find((f) => currentTime >= f.startTime && currentTime <= f.endTime) ?? null,
+ [fragments, currentTime]
+ );
+
+ const lastEndedFragment = useMemo(
+ () => fragments.filter((f) => f.endTime < currentTime).sort((a, b) => b.endTime - a.endTime)[0] ?? null,
+ [fragments, currentTime]
+ );
+
+ const holdStrength = useMemo(() => {
+ const frag = activeFragment ?? lastEndedFragment;
+ if (!frag) return 0;
+ const targetScale = zoomLevelToFactor(frag.zoomLevel);
+ if (targetScale <= 1) return 0;
+ return clamp((smoothZoom.scale - 1) / (targetScale - 1), 0, 1);
+ }, [activeFragment, lastEndedFragment, smoothZoom.scale]);
+
+ const drift = useMemo(() => {
+ const frag = activeFragment ?? lastEndedFragment;
+ if (!frag || holdStrength <= 0) return { x: 0, y: 0 };
+ return organicDrift(currentTime, hashSeed(frag.id));
+ }, [activeFragment, lastEndedFragment, holdStrength, currentTime]);
+
+ const effectiveFocusX = clamp(smoothZoom.focusX + drift.x * DRIFT_AMPLITUDE_X * holdStrength, 6, 94);
+ const effectiveFocusY = clamp(smoothZoom.focusY + drift.y * DRIFT_AMPLITUDE_Y * holdStrength, 6, 94);
+
+ const tiltX = -drift.y * TILT_MAX_DEG * holdStrength;
+ const tiltY = drift.x * TILT_MAX_DEG * holdStrength;
+
+ const translateX = (50 - effectiveFocusX) * holdStrength + dragOffset.x;
+ const translateY = (50 - effectiveFocusY) * holdStrength + dragOffset.y;
+
+ const videoTransform = `translate(${translateX.toFixed(3)}%, ${translateY.toFixed(3)}%) scale(${smoothZoom.scale.toFixed(
+ 3
+ )}) rotateX(${tiltX.toFixed(3)}deg) rotateY(${tiltY.toFixed(3)}deg)`;
+
+ const transformOrigin = `${effectiveFocusX.toFixed(2)}% ${effectiveFocusY.toFixed(2)}%`;
+
+ const roundedPx = (roundedPercent / SLIDER_MAX) * 32;
+ const paddingPct = (paddingPercent / SLIDER_MAX) * 12;
+ const backgroundBlurPx = (blurPercent / SLIDER_MAX) * 40;
+ const shadowT = shadowPercent / SLIDER_MAX;
+ const shadowY = 8 + shadowT * 22;
+ const shadowBlur = 15 + shadowT * 70;
+ const shadowOpacity = 0.15 + shadowT * 0.35;
+ const dynamicShadow = `0 ${shadowY}px ${shadowBlur}px rgba(0,0,0,${shadowOpacity.toFixed(2)})`;
+
+ const cursorTarget = useMemo(() => {
+ const currentIndex = backgroundCategory === "wallpaper" ? activeSwatch : activeGradient;
+ const col = currentIndex % THUMB_COLS;
+ const row = Math.floor(currentIndex / THUMB_COLS);
+ return { x: col * THUMB_STEP + THUMB / 2, y: row * THUMB_STEP + THUMB / 2 };
+ }, [backgroundCategory, activeSwatch, activeGradient]);
+
+ const backgroundUrl =
+ backgroundCategory === "wallpaper" ? HERO_WALLPAPERS[activeSwatch]?.fullUrl : HERO_GRADIENTS[activeGradient]?.fullUrl;
+
+ return (
+ <section className="relative w-full overflow-visible flex justify-center animate-fade-in-up">
+ {/* Capa de Gradientes de Fondo */}
+ <div className="pointer-events-none absolute top-0 left-1/2 -translate-x-1/2 w-screen min-w-[140vw] md:min-w-0 max-w-480 h-full -z-10 overflow-visible flex justify-center">
+ <div
+ className="absolute inset-0 -top-28 bottom-64 w-full h-full mix-blend-hard-light blur-[80px] md:blur-[120px] transform-gpu will-change-transform"
+ style={{
+ background:
+ "linear-gradient(rgba(0,0,0,0) 0%, rgba(0,138,255,0.1) 20%, rgb(255,255,255) 45%, rgb(247,164,66) 75%, rgb(233,66,247) 100%)",
+ }}
+ />
+ <div
+ className="absolute inset-0 -top-28 bottom-64 w-full h-full mix-blend-soft-light blur-[80px] md:blur-[120px] transform-gpu will-change-transform"
+ style={{
+ background:
+ "linear-gradient(rgba(0,0,0,0) 0%, rgba(0,138,255,0.2) 35%, rgb(255,255,255) 70%, rgb(247,164,66) 80%, rgb(233,66,247) 100%)",
+ }}
+ />
+ </div>
+
+ <div className="relative px-4 w-full">
+ <div className="relative mx-auto max-w-7xl">
+ <div className="relative mt-4 h-fit w-full md:mt-12">
+ <div className="relative -mx-4 flex max-w-screen justify-center py-8 sm:p-8 delay-[800ms] duration-1000 will-change-transform starting:translate-y-16 starting:opacity-0 starting:blur-xs">
+ <div className="relative w-full max-w-[calc(100vw-48px)] lg:w-7xl lg:min-w-200">
+ <div
+ aria-hidden="true"
+ className="absolute -inset-6 squircle-element-xl blur-3xl -z-10 bg-linear-to-b from-cyan-500/15 via-fuchsia-500/10 to-transparent"
+ />
+ <div className="relative w-full p-0 sm:p-3 squircle-element-2xl sm:border sm:border-black/10 bg-white shadow-[0_0_0_1px_rgba(0,0,0,0.04),0_30px_120px_rgba(0,0,0,0.18)]">
+ <div className="relative w-full h-[400px] sm:h-[576px] lg:h-[656px] overflow-hidden squircle-element-xl border border-black/10 bg-[#FAFAFB] flex">
+ <div className="absolute inset-x-0 top-0 h-px bg-linear-to-r from-transparent via-black/10 to-transparent z-20 pointer-events-none" />
+ <MiniSidebar t={t} />
+ <BackgroundPanel
+ t={t}
+ category={backgroundCategory}
+ activeSwatch={activeSwatch}
+ cursorTarget={cursorTarget}
+ onSelectWallpaper={handleSelectWallpaper}
+ activeGradient={activeGradient}
+ onSelectGradient={handleSelectGradient}
+ blurPercent={blurPercent}
+ onBlurChange={setBlurPercent}
+ paddingPercent={paddingPercent}
+ onPaddingChange={setPaddingPercent}
+ roundedPercent={roundedPercent}
+ onRoundedChange={setRoundedPercent}
+ shadowPercent={shadowPercent}
+ onShadowChange={setShadowPercent}
+ />
+ <div className="flex-1 flex flex-col min-w-0">
+ <EditorCanvas
+ videoRef={videoRef}
+ videoTransform={videoTransform}
+ transformOrigin={transformOrigin}
+ onLoadedMetadata={handleLoadedMetadata}
+ backgroundUrl={backgroundUrl}
+ zoomScale={smoothZoom.scale}
+ focusPoint={{ x: effectiveFocusX, y: effectiveFocusY }}
+ pulseKey={
+ activeFragment
+ ? `${activeFragment.id}-${activeFragment.startTime}`
+ : null
+ }
+ roundedPx={roundedPx}
+ paddingPct={paddingPct}
+ backgroundBlurPx={backgroundBlurPx}
+ dynamicShadow={dynamicShadow}
+ dragOffset={dragOffset}
+ onDragOffsetChange={handleDragOffsetChange}
+ onDragRelease={handleDragRelease}
+ />
+ <TransportBar
+ t={t}
+ isPlaying={isPlaying}
+ currentTime={currentTime}
+ duration={duration}
+ onTogglePlay={togglePlay}
+ onSkip={skip}
+ />
+ <EditorTimeline
+ t={t}
+ duration={duration}
+ currentTime={currentTime}
+ fragments={fragments}
+ onFragmentChange={handleFragmentChange}
+ clipRange={clipRange}
+ onClipChange={setClipRange}
+ trackRef={trackRef}
+ onSeek={handleSeek}
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </section>
+ );
+}
\ No newline at end of file
diff --git a/app/globals.css b/app/globals.css
index 4bc253f..f0d4096 100644
--- a/app/globals.css
+++ b/app/globals.css
@@ -175,6 +175,10 @@
border-radius: 70px;
}
+ .squircle-corner {
+ corner-shape: squircle;
+ }
+
@keyframes badge-blink {
0%,
diff --git a/components/ui/HeroEditorPreviewComponents.tsx b/components/ui/HeroEditorPreviewComponents.tsx
new file mode 100644
index 0000000..04d23b9
--- /dev/null
+++ b/components/ui/HeroEditorPreviewComponents.tsx
@@ -0,0 +1,566 @@
+"use client";
+
+import { memo, useRef, useCallback } from "react";
+import { Icon } from "@iconify/react";
+import { motion } from "framer-motion";
+import Image from "next/image";
+import { zoomLevelToFactor, type ZoomFragment } from "@/types/zoom.types";
+import { ElementsIcon } from "@/components/ui/ElementsIcon";
+import { formatTime } from "@/lib";
+import {
+ ACCENT,
+ BackgroundCategory,
+ DragMode,
+ HERO_GRADIENTS,
+ HERO_WALLPAPERS,
+ PANEL_BORDER,
+ SIDEBAR_TOOLS,
+ SLIDER_MAX,
+ TFunc,
+ THUMB,
+ ZOOM_MIN_DURATION,
+ clamp,
+} from "@/lib/editor-preview-hero.utils";
+
+export const DraggableRange = memo(function DraggableRange({
+ start,
+ end,
+ duration,
+ trackRef,
+ minDuration = 0.3,
+ onChange,
+ onClick,
+ className,
+ handleClassName,
+ children,
+}: {
+ start: number;
+ end: number;
+ duration: number;
+ trackRef: React.RefObject<HTMLDivElement | null>;
+ minDuration?: number;
+ onChange: (next: { start: number; end: number }) => void;
+ onClick?: () => void;
+ className?: string;
+ handleClassName?: string;
+ children?: React.ReactNode;
+}) {
+ const dragState = useRef<{
+ mode: DragMode;
+ startX: number;
+ initialStart: number;
+ initialEnd: number;
+ hasMoved: boolean;
+ } | null>(null);
+
+ const startDrag = useCallback(
+ (mode: DragMode) => (e: React.PointerEvent) => {
+ e.stopPropagation();
+ dragState.current = {
+ mode,
+ startX: e.clientX,
+ initialStart: start,
+ initialEnd: end,
+ hasMoved: false,
+ };
+
+ const handleMove = (ev: PointerEvent) => {
+ const drag = dragState.current;
+ const track = trackRef.current;
+ if (!drag || !track || duration <= 0) return;
+
+ const width = track.getBoundingClientRect().width;
+ if (width <= 0) return;
+
+ const deltaPx = ev.clientX - drag.startX;
+ if (Math.abs(deltaPx) > 3) drag.hasMoved = true;
+
+ const deltaSec = (deltaPx / width) * duration;
+ let nextStart = drag.initialStart;
+ let nextEnd = drag.initialEnd;
+
+ if (drag.mode === "move") {
+ const span = drag.initialEnd - drag.initialStart;
+ nextStart = Math.max(0, Math.min(duration - span, drag.initialStart + deltaSec));
+ nextEnd = nextStart + span;
+ } else if (drag.mode === "resize-left") {
+ nextStart = Math.max(0, Math.min(drag.initialEnd - minDuration, drag.initialStart + deltaSec));
+ } else {
+ nextEnd = Math.min(duration, Math.max(drag.initialStart + minDuration, drag.initialEnd + deltaSec));
+ }
+ onChange({ start: nextStart, end: nextEnd });
+ };
+
+ const handleUp = () => {
+ if (dragState.current && !dragState.current.hasMoved && onClick) {
+ onClick();
+ }
+ dragState.current = null;
+ window.removeEventListener("pointermove", handleMove);
+ window.removeEventListener("pointerup", handleUp);
+ };
+
+ window.addEventListener("pointermove", handleMove);
+ window.addEventListener("pointerup", handleUp);
+ },
+ [start, end, duration, minDuration, onChange, onClick, trackRef]
+ );
+
+ if (duration <= 0) return null;
+
+ const left = (start / duration) * 100;
+ const width = ((end - start) / duration) * 100;
+
+ return (
+ <div
+ className={`group/range absolute top-0 h-full cursor-grab touch-none select-none active:cursor-grabbing ${className ?? ""}`}
+ style={{ left: `${left}%`, width: `${width}%` }}
+ onPointerDown={startDrag("move")}
+ >
+ {children}
+ <div
+ className="absolute -left-1 top-0 bottom-0 z-20 flex w-3 cursor-ew-resize items-center justify-center"
+ onPointerDown={startDrag("resize-left")}
+ >
+ <div
+ className={`h-6 w-1.5 rounded-full shadow-sm transition-colors ${handleClassName ?? "bg-black/0 opacity-0 group-hover/range:bg-black/40 group-hover/range:opacity-100"
+ }`}
+ />
+ </div>
+ <div
+ className="absolute -right-1 top-0 bottom-0 z-20 flex w-3 cursor-ew-resize items-center justify-center"
+ onPointerDown={startDrag("resize-right")}
+ >
+ <div
+ className={`h-6 w-1.5 rounded-full shadow-sm transition-colors ${handleClassName ?? "bg-black/0 opacity-0 group-hover/range:bg-black/40 group-hover/range:opacity-100"
+ }`}
+ />
+ </div>
+ </div>
+ );
+});
+
+export const TimelineClipContent = memo(function TimelineClipContent({
+ label,
+ duration,
+ progress,
+ isSelected,
+}: {
+ label: string;
+ duration: number;
+ progress: number;
+ isSelected?: boolean;
+}) {
+ return (
+ <div
+ className={`group/clip relative h-full w-full overflow-hidden rounded-md border transition-all ${isSelected
+ ? "border-emerald-400 ring-1 ring-emerald-400 shadow-[0_0_12px_rgba(52,211,153,0.4)] bg-emerald-500/25"
+ : "border-emerald-600/35 hover:border-emerald-500/60 bg-emerald-500/10"
+ }`}
+ >
+ <div className="absolute inset-0 flex">
+ {Array.from({ length: 12 }).map((_, i) => (
+ <div key={i} className="h-full flex-1 border-r border-emerald-600/10 last:border-r-0" />
+ ))}
+ </div>
+ <div
+ className="absolute inset-y-0 left-px z-[1] border-r-2 border-emerald-400 pointer-events-none"
+ style={{
+ width: `${progress * 100}%`,
+ background: "linear-gradient(180deg, rgba(16, 187, 130, 0.66) 0%, rgba(133, 227, 197, 0.28) 100%)",
+ }}
+ />
+ <div className="relative z-10 flex h-full min-w-0 items-center justify-center gap-1.5 px-2 pointer-events-none">
+ <Icon icon="solar:videocamera-record-bold" width={10} className="shrink-0 text-emerald-700" />
+ <span className="truncate text-[9px] font-medium text-emerald-800">{label}</span>
+ <span className="shrink-0 font-mono text-[8px] text-emerald-700/70">{formatTime(duration)}</span>
+ </div>
+ </div>
+ );
+});
+
+export const TimelineZoomContent = memo(function TimelineZoomContent({
+ zoomLevel,
+ duration,
+ isSelected,
+ zoomLabel,
+}: {
+ zoomLevel: number;
+ duration: number;
+ isSelected?: boolean;
+ zoomLabel: string;
+}) {
+ return (
+ <div
+ className={`flex h-full w-full flex-col items-center justify-center gap-0 rounded-md border transition-all pointer-events-none ${isSelected
+ ? "border-blue-400 ring-1 ring-blue-400 shadow-[0_0_12px_rgba(59,130,246,0.45)] bg-blue-500/30"
+ : "border-blue-500/35 hover:border-blue-500/60 bg-blue-600/15"
+ }`}
+ >
+ <span className={`flex items-center gap-1 text-[9px] leading-tight ${isSelected ? "text-blue-800 font-semibold" : "text-blue-700"}`}>
+ <Icon icon="iconamoon:zoom-in-bold" width={9} className={isSelected ? "text-blue-300" : "text-blue-600"} />
+ {zoomLabel}
+ </span>
+ <span className={`font-mono text-[8px] leading-tight ${isSelected ? "text-blue-900" : "text-blue-700/70"}`}>
+ {zoomLevelToFactor(zoomLevel).toFixed(1)}× · {duration.toFixed(1)}s
+ </span>
+ </div>
+ );
+});
+
+export const ZoomFragmentRangeItem = memo(function ZoomFragmentRangeItem({
+ fragment,
+ duration,
+ trackRef,
+ zoomLabel,
+ isSelected,
+ onChange,
+ onToggle,
+}: {
+ fragment: ZoomFragment;
+ duration: number;
+ trackRef: React.RefObject<HTMLDivElement | null>;
+ zoomLabel: string;
+ isSelected: boolean;
+ onChange: (id: string, next: { start: number; end: number }) => void;
+ onToggle: (id: string) => void;
+}) {
+ const handleChange = useCallback(
+ (next: { start: number; end: number }) => onChange(fragment.id, next),
+ [onChange, fragment.id]
+ );
+ const handleClick = useCallback(() => onToggle(fragment.id), [onToggle, fragment.id]);
+
+ return (
+ <DraggableRange
+ start={fragment.startTime}
+ end={fragment.endTime}
+ duration={duration}
+ trackRef={trackRef}
+ minDuration={ZOOM_MIN_DURATION}
+ onChange={handleChange}
+ onClick={handleClick}
+ handleClassName="bg-blue-500/70 group-hover/range:bg-blue-400"
+ >
+ <TimelineZoomContent
+ zoomLevel={fragment.zoomLevel}
+ duration={fragment.endTime - fragment.startTime}
+ isSelected={isSelected}
+ zoomLabel={zoomLabel}
+ />
+ </DraggableRange>
+ );
+});
+
+export const MiniSidebar = memo(function MiniSidebar({ t }: { t: TFunc }) {
+ return (
+ <aside
+ className={`hidden sm:flex flex-col items-center gap-1.5 w-[72px] shrink-0 border-r ${PANEL_BORDER} bg-white py-4`}
+ aria-hidden="true"
+ >
+ {SIDEBAR_TOOLS.map((tool, i) => {
+ const active = i === 0;
+ return (
+ <div key={tool.id} className="relative">
+ <div
+ className={`w-11 h-11 rounded-2xl flex items-center justify-center transition-colors ${active ? "bg-[#EAF6FF]" : "hover:bg-black/[0.04]"
+ }`}
+ >
+ {tool.icon ? (
+ <Icon icon={tool.icon} width={19} style={{ color: active ? ACCENT : "rgba(0,0,0,0.4)" }} />
+ ) : (
+ <ElementsIcon className="w-[19px] h-[19px] text-gray-400" />
+ )}
+ </div>
+ {tool.badge === "new" && (
+ <span className="absolute -top-0.5 -right-0.5 px-[3px] py-[1px] rounded-full bg-amber-700 text-[6px] font-semibold text-white leading-tight">
+ NEW
+ </span>
+ )}
+ </div>
+ );
+ })}
+ <div className="flex-1" />
+ <div className={`w-full px-2 pt-3 border-t ${PANEL_BORDER} flex flex-col gap-1.5`}>
+ <div className="w-full flex flex-col items-center gap-1 py-2 rounded-xl text-black/40">
+ <Icon icon="fluent:screenshot-record-16-regular" width={20} />
+ <span className="text-[9px] font-medium">{t("sidebar.record")}</span>
+ </div>
+ <div className="w-full flex flex-col items-center gap-1 py-2 rounded-xl border border-dashed border-black/10 text-black/40">
+ <Icon icon="mage:video-upload" width={20} />
+ <span className="text-[9px] font-medium">{t("sidebar.upload")}</span>
+ </div>
+ </div>
+ </aside>
+ );
+});
+
+export const MiniSlider = memo(function MiniSlider({
+ icon,
+ label,
+ value,
+ max = SLIDER_MAX,
+ onChange,
+}: {
+ icon: string;
+ label: string;
+ value: number;
+ max?: number;
+ onChange?: (value: number) => void;
+}) {
+ const trackRef = useRef<HTMLDivElement>(null);
+ const isDraggingRef = useRef(false);
+ const fillPercent = max > 0 ? clamp((value / max) * 100, 0, 100) : 0;
+
+ const updateFromClientX = useCallback(
+ (clientX: number) => {
+ const track = trackRef.current;
+ if (!track) return;
+ const rect = track.getBoundingClientRect();
+ if (rect.width <= 0) return;
+ onChange?.(clamp(((clientX - rect.left) / rect.width) * max, 0, max));
+ },
+ [onChange, max]
+ );
+
+ const handlePointerDown = useCallback(
+ (e: React.PointerEvent) => {
+ if (!onChange) return;
+ e.preventDefault();
+ isDraggingRef.current = true;
+ updateFromClientX(e.clientX);
+ const handleMove = (ev: PointerEvent) => {
+ if (isDraggingRef.current) updateFromClientX(ev.clientX);
+ };
+ const handleUp = () => {
+ isDraggingRef.current = false;
+ window.removeEventListener("pointermove", handleMove);
+ window.removeEventListener("pointerup", handleUp);
+ };
+ window.addEventListener("pointermove", handleMove);
+ window.addEventListener("pointerup", handleUp);
+ },
+ [onChange, updateFromClientX]
+ );
+
+ return (
+ <div
+ ref={trackRef}
+ onPointerDown={handlePointerDown}
+ className={`relative flex h-[28px] w-full items-center overflow-hidden rounded-lg border border-black/6 bg-black/[0.035] ${onChange ? "cursor-pointer touch-none select-none" : ""
+ }`}
+ >
+ <div
+ className="absolute bottom-0 left-0 top-0 bg-black/10 transition-[width] duration-150 ease-out"
+ style={{ width: `${fillPercent}%` }}
+ />
+ <div
+ className="absolute top-[5px] bottom-[5px] z-20 w-[2px] rounded-full shadow-sm transition-[left] duration-150 ease-out"
+ style={{ left: `calc(${fillPercent}% - 1px)`, background: ACCENT }}
+ />
+ <div className="pointer-events-none absolute inset-0 z-10 flex items-center justify-between px-2.5">
+ <div className="flex items-center gap-1.5 text-[10px] font-medium text-black/55">
+ <Icon icon={icon} width={12} />
+ <span>{label}</span>
+ </div>
+ <span className="text-[9px] font-mono text-black/40">{Math.round(value)}</span>
+ </div>
+ </div>
+ );
+});
+
+export const SwatchGrid = memo(function SwatchGrid({
+ label,
+ items,
+ activeIndex,
+ isActiveCategory,
+ cursorTarget,
+ onSelect,
+}: {
+ label: string;
+ items: { index: number | string; previewUrl: string }[];
+ activeIndex: number;
+ isActiveCategory: boolean;
+ cursorTarget?: { x: number; y: number };
+ onSelect: (index: number) => void;
+}) {
+ if (items.length === 0) return null;
+
+ return (
+ <div>
+ <div className="flex items-center gap-1.5 text-[10px] uppercase tracking-widest text-black/35 font-bold mb-2">
+ <Icon icon="solar:gallery-wide-linear" width={11} />
+ <span>{label}</span>
+ </div>
+ <div className="relative grid grid-cols-5 lg:grid-cols-6 gap-2 w-max">
+ {items.map((item, i) => (
+ <div
+ key={item.index}
+ role="button"
+ tabIndex={0}
+ onClick={() => onSelect(i)}
+ onKeyDown={(e) => {
+ if (e.key === "Enter" || e.key === " ") onSelect(i);
+ }}
+ className="rounded-lg overflow-hidden bg-cover bg-center transition-shadow cursor-pointer"
+ style={{
+ width: THUMB,
+ height: THUMB,
+ backgroundImage: `url('${item.previewUrl}')`,
+ boxShadow:
+ isActiveCategory && i === activeIndex
+ ? `0 0 0 2px white, 0 0 0 3.5px ${ACCENT}`
+ : "0 0 0 1px rgba(0,0,0,0.08)",
+ }}
+ />
+ ))}
+ {cursorTarget && (
+ <motion.div
+ className="absolute pointer-events-none z-10 w-[60px] h-[60px] min-w-[60px] min-h-[60px]"
+ initial={false}
+ animate={{ left: cursorTarget.x, top: cursorTarget.y + 10 }}
+ transition={{ duration: 0.7, ease: [0.65, 0, 0.35, 1] }}
+ style={{ translateX: "-50%", translateY: "-50%" }}
+ >
+ <Image
+ src="/svg/pointinghand.svg"
+ alt="Pointer"
+ width={60}
+ height={60}
+ className="drop-shadow-md max-w-none"
+ />
+ </motion.div>
+ )}
+ </div>
+ </div>
+ );
+});
+
+export const BackgroundPanel = memo(function BackgroundPanel({
+ t,
+ category,
+ activeSwatch,
+ cursorTarget,
+ onSelectWallpaper,
+ activeGradient,
+ onSelectGradient,
+ blurPercent,
+ onBlurChange,
+ paddingPercent,
+ onPaddingChange,
+ roundedPercent,
+ onRoundedChange,
+ shadowPercent,
+ onShadowChange,
+}: {
+ t: TFunc;
+ category: BackgroundCategory;
+ activeSwatch: number;
+ cursorTarget: { x: number; y: number };
+ onSelectWallpaper: (index: number) => void;
+ activeGradient: number;
+ onSelectGradient: (index: number) => void;
+ blurPercent: number;
+ onBlurChange: (p: number) => void;
+ paddingPercent: number;
+ onPaddingChange: (p: number) => void;
+ roundedPercent: number;
+ onRoundedChange: (p: number) => void;
+ shadowPercent: number;
+ onShadowChange: (p: number) => void;
+}) {
+ return (
+ <div className={`hidden md:flex flex-col w-64 lg:w-72 shrink-0 border-r ${PANEL_BORDER} bg-white overflow-hidden`}>
+ <header className={`flex items-center justify-between h-12 px-3 border-b ${PANEL_BORDER} shrink-0`}>
+ <div className="flex items-center gap-1.5">
+ <Image src="/svg/logo-openvid.svg" alt="" width={22} height={22} />
+ <Image src="/svg/openvid-dark.svg" alt="Openvid" width={58} height={40} />
+ </div>
+ <Icon icon="lucide:sidebar-close" width={16} className="text-black/30" />
+ </header>
+ <div className="flex-1 overflow-y-none custom-scrollbar">
+ <div className="p-4 pb-2">
+ <div className="flex items-center gap-2 text-black/80 font-medium text-[13px] mb-3">
+ <Icon icon="solar:gallery-wide-linear" width={16} style={{ color: ACCENT }} />
+ <span>{t("background.title")}</span>
+ </div>
+ <div className="flex bg-black/[0.04] rounded-lg p-0.5 text-[11px] font-medium">
+ <div className="flex-1 text-center py-1.5 rounded-md bg-white shadow-sm text-black">{t("background.tabWallpaper")}</div>
+ <div className="flex-1 text-center py-1.5 text-black/40">{t("background.tabColor")}</div>
+ </div>
+ </div>
+ <div className="px-4 pb-4 flex flex-col gap-4">
+ <div>
+ <div className="text-[10px] uppercase tracking-widest text-black/35 font-bold mb-2">{t("background.options")}</div>
+ <div className="flex flex-wrap gap-2">
+ <div
+ className="size-9 rounded-lg border border-black/10 shrink-0 hover:cursor-pointer bg-zinc-100 hover:bg-black/5 transition-colors"
+ style={{
+ backgroundImage:
+ "linear-gradient(45deg, #d1d5db 25%, transparent 25%), linear-gradient(-45deg, #d1d5db 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #d1d5db 75%), linear-gradient(-45deg, transparent 75%, #d1d5db 75%)",
+ backgroundSize: "14px 14px",
+ backgroundPosition: "0 0, 0 7px, 7px -7px, -7px 0",
+ }}
+ />
+
+ <div className="size-9 rounded-lg border border-dashed border-black/15 flex items-center justify-center bg-black/2 cursor-pointer hover:bg-black/5 transition-colors shrink-0">
+ <Icon icon="material-symbols:upload-rounded" width={18} className="text-black/40" />
+ </div>
+
+ <div className="size-9 rounded-lg border border-black/10 flex items-center justify-center bg-black/2 cursor-pointer hover:bg-black/5 transition-colors shrink-0">
+ <Icon icon="ri:unsplash-fill" width={18} className="text-black/40" />
+ </div>
+ </div>
+ </div>
+
+ <SwatchGrid
+ label={t("background.desktopLabel")}
+ items={HERO_WALLPAPERS}
+ activeIndex={activeSwatch}
+ isActiveCategory={category === "wallpaper"}
+ cursorTarget={category === "wallpaper" ? cursorTarget : undefined}
+ onSelect={onSelectWallpaper}
+ />
+ <SwatchGrid
+ label={t("background.gradientsLabel")}
+ items={HERO_GRADIENTS}
+ activeIndex={activeGradient}
+ isActiveCategory={category === "gradient"}
+ cursorTarget={category === "gradient" ? cursorTarget : undefined}
+ onSelect={onSelectGradient}
+ />
+
+ <div className="text-[10px] text-black/35 flex items-center justify-center gap-1">
+ <Icon icon="lucide:chevron-down" width={10} />
+ <span>{t("background.showMore")}</span>
+ </div>
+
+ <div>
+ <div className="text-[10px] uppercase tracking-widest text-black/35 font-bold mb-2">{t("background.settings")}</div>
+ <div className="flex flex-col gap-2">
+ <MiniSlider icon="mdi:blur" label={t("background.blur")} value={blurPercent} onChange={onBlurChange} />
+ <MiniSlider
+ icon="mdi:arrow-expand-all"
+ label={t("background.padding")}
+ value={paddingPercent}
+ onChange={onPaddingChange}
+ />
+ <MiniSlider
+ icon="mdi:border-radius"
+ label={t("background.rounded")}
+ value={roundedPercent}
+ onChange={onRoundedChange}
+ />
+ <MiniSlider
+ icon="material-symbols:shadow"
+ label={t("background.shadow")}
+ value={shadowPercent}
+ onChange={onShadowChange}
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ );
+});
\ No newline at end of file
diff --git a/lib/editor-preview-hero.utils.ts b/lib/editor-preview-hero.utils.ts
new file mode 100644
index 0000000..df40409
--- /dev/null
+++ b/lib/editor-preview-hero.utils.ts
@@ -0,0 +1,109 @@
+import { ZoomFragment } from "@/types";
+import { WALLPAPER_CATEGORIES } from "./wallpaper.catalog";
+import { useTranslations } from "next-intl";
+
+export const ACCENT = "#009CF2";
+export const PANEL_BORDER = "border-black/8";
+
+export type SidebarTool = { id: string; icon?: string; badge?: "new" };
+
+export const SIDEBAR_TOOLS: SidebarTool[] = [
+ { id: "background", icon: "solar:gallery-wide-linear" },
+ { id: "mockup", icon: "hugeicons:ai-browser", badge: "new" },
+ { id: "motion", icon: "mage:box-3d", badge: "new" },
+ { id: "zoom", icon: "iconamoon:zoom-in-bold" },
+ { id: "videos", icon: "solar:video-library-outline" },
+ { id: "elements" },
+ { id: "audio", icon: "mdi:volume-high" },
+];
+
+export const HERO_WALLPAPER_CATEGORY =
+ WALLPAPER_CATEGORIES.find((c) => c.id === "desktop" && c.items.length > 0) ??
+ WALLPAPER_CATEGORIES.find((c) => c.items.length > 0);
+
+export const HERO_WALLPAPERS = (HERO_WALLPAPER_CATEGORY?.items ?? []).slice(0, 12);
+
+export const HERO_GRADIENT_CATEGORY = WALLPAPER_CATEGORIES.find(
+ (c) => c.id === "gradient" && c.items.length > 0
+);
+
+export const HERO_GRADIENTS = (HERO_GRADIENT_CATEGORY?.items ?? []).slice(0, 12);
+
+export const THUMB = 36;
+export const THUMB_GAP = 8;
+export const THUMB_STEP = THUMB + THUMB_GAP;
+export const THUMB_COLS = 6;
+
+export const ZOOM_MIN_DURATION = 0.6;
+export const CLIP_MIN_DURATION = 1.5;
+export const SLIDER_MAX = 30;
+
+export function getInitialZoomFragments(
+ duration: number,
+ durations: { z1: number; z2: number }
+): ZoomFragment[] {
+ if (duration <= 0) return [];
+ const dur1 = Math.min(durations.z1, duration * 0.4);
+ const dur2 = Math.min(durations.z2, duration * 0.3);
+ const f1Start = Math.min(duration * 0.1, Math.max(0, duration - dur1));
+ const f2Start = Math.min(
+ Math.max(f1Start + dur1, duration * 0.8),
+ Math.max(0, duration - dur2)
+ );
+ return [
+ {
+ id: "z1",
+ startTime: f1Start,
+ endTime: Math.min(duration, f1Start + dur1),
+ zoomLevel: 4,
+ speed: 5,
+ focusX: 20,
+ focusY: 20,
+ },
+ {
+ id: "z2",
+ startTime: f2Start,
+ endTime: Math.min(duration, f2Start + dur2),
+ zoomLevel: 4.5,
+ speed: 5,
+ focusX: 90,
+ focusY: 90,
+ },
+ ];
+}
+
+export function formatTime(seconds: number): string {
+ if (!Number.isFinite(seconds) || seconds < 0) seconds = 0;
+ const m = Math.floor(seconds / 60);
+ const s = Math.floor(seconds % 60);
+ return `${m}:${s.toString().padStart(2, "0")}`;
+}
+
+export const DRIFT_AMPLITUDE_X = 3.2;
+export const DRIFT_AMPLITUDE_Y = 2.4;
+export const TILT_MAX_DEG = 1.6;
+
+export function hashSeed(id: string): number {
+ let h = 0;
+ for (let i = 0; i < id.length; i++) h = (h * 31 + id.charCodeAt(i)) >>> 0;
+ return ((h % 1000) / 1000) * Math.PI * 2;
+}
+
+export function organicDrift(t: number, seed: number): { x: number; y: number } {
+ const x = Math.sin(t * 0.55 + seed) * 0.65 + Math.sin(t * 0.21 + seed * 2.3) * 0.35;
+ const y = Math.cos(t * 0.47 + seed * 1.6) * 0.65 + Math.cos(t * 0.19 + seed * 0.8) * 0.35;
+ return { x, y };
+}
+
+export function clamp(value: number, min: number, max: number): number {
+ return Math.min(max, Math.max(min, value));
+}
+
+export type DragMode = "move" | "resize-left" | "resize-right";
+
+export type BackgroundCategory = "wallpaper" | "gradient";
+export type TFunc = ReturnType<typeof useTranslations>;
+
+export const DRAG_CLAMP_PCT = 16;
+export const DRAG_EASE_FACTOR = 0.86;
+export const ZOOM_FRAGMENT_DURATIONS = { z1: 3.2, z2: 1.6 };
\ No newline at end of file
diff --git a/proxy.ts b/proxy.ts
index 61d6255..30568e1 100644
--- a/proxy.ts
+++ b/proxy.ts
@@ -87,6 +87,6 @@ function forwardWithRefreshedRequest(
export const config = {
matcher: [
- "/((?!api|ffmpeg|models|hdri|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt|site.webmanifest|.*\\.(?:svg|png|jpg|jpeg|gif|webp|mp4|avif|webm|wasm|js|glb|gltf|webmanifest|json)$).*)",
+ "/((?!api|ffmpeg|models|hdri|_next/static|_next/image|sitemap.xml|robots.txt|site.webmanifest|.*\\.(?:svg|png|jpg|jpeg|gif|webp|mp4|avif|webm|wasm|js|glb|gltf|webmanifest|json|ico)$).*)",
],
};
diff --git a/public/videos/hero/demo-preview-editor.mp4 b/public/videos/hero/demo-preview-editor.mp4
new file mode 100644
index 0000000..2dcabd6
Binary files /dev/null and b/public/videos/hero/demo-preview-editor.mp4 differ