Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

Merge PR #184: resolve crop control conflicts

Siddharthd182854270c0
diff --cc src/components/video-editor/CropControl.tsx
index 078b6e530,fc1489447..07e769d63
--- a/src/components/video-editor/CropControl.tsx
+++ b/src/components/video-editor/CropControl.tsx
@@@ -10,226 -10,243 +10,243 @@@ interface CropRegion
}
interface CropControlProps {
- videoElement: HTMLVideoElement | null;
- cropRegion: CropRegion;
- onCropChange: (region: CropRegion) => void;
- aspectRatio: AspectRatio;
+ videoElement: HTMLVideoElement | null;
+ cropRegion: CropRegion;
+ onCropChange: (region: CropRegion) => void;
+ aspectRatio: AspectRatio;
}
- type DragHandle = "top" | "right" | "bottom" | "left" | null;
-type DragHandle = 'top' | 'right' | 'bottom' | 'left' | 'move' | null;
++type DragHandle = "top" | "right" | "bottom" | "left" | "move" | null;
export function CropControl({ videoElement, cropRegion, onCropChange }: CropControlProps) {
- const canvasRef = useRef<HTMLCanvasElement>(null);
- const containerRef = useRef<HTMLDivElement>(null);
- const [isDragging, setIsDragging] = useState<DragHandle>(null);
- const [dragStart, setDragStart] = useState({ x: 0, y: 0 });
- const [initialCrop, setInitialCrop] = useState<CropRegion>(cropRegion);
-
- useEffect(() => {
- if (!videoElement || !canvasRef.current) return;
-
- const canvas = canvasRef.current;
- const ctx = canvas.getContext('2d', { alpha: false });
- if (!ctx) return;
-
- canvas.width = videoElement.videoWidth || 1920;
- canvas.height = videoElement.videoHeight || 1080;
-
- const draw = () => {
- if (videoElement.readyState >= 2) {
- ctx.clearRect(0, 0, canvas.width, canvas.height);
- ctx.drawImage(videoElement, 0, 0, canvas.width, canvas.height);
- }
- requestAnimationFrame(draw);
- };
-
- const rafId = requestAnimationFrame(draw);
- return () => cancelAnimationFrame(rafId);
- }, [videoElement]);
-
- const getContainerRect = () => {
- return containerRef.current?.getBoundingClientRect() || { width: 0, height: 0, left: 0, top: 0 };
- };
-
- const handlePointerDown = (e: React.PointerEvent, handle: DragHandle) => {
- e.stopPropagation();
- e.preventDefault();
- setIsDragging(handle);
- const rect = getContainerRect();
- setDragStart({
- x: (e.clientX - rect.left) / rect.width,
- y: (e.clientY - rect.top) / rect.height,
- });
- setInitialCrop(cropRegion);
-
- e.currentTarget.setPointerCapture(e.pointerId);
- };
-
- const handlePointerMove = (e: React.PointerEvent) => {
- if (!isDragging) return;
-
- const rect = getContainerRect();
- const currentX = (e.clientX - rect.left) / rect.width;
- const currentY = (e.clientY - rect.top) / rect.height;
- const deltaX = currentX - dragStart.x;
- const deltaY = currentY - dragStart.y;
-
- let newCrop = { ...initialCrop };
-
- switch (isDragging) {
- case 'top': {
- const newY = Math.max(0, initialCrop.y + deltaY);
- const bottom = initialCrop.y + initialCrop.height;
- newCrop.y = Math.min(newY, bottom - 0.1);
- newCrop.height = bottom - newCrop.y;
- break;
- }
- case 'bottom':
- newCrop.height = Math.max(0.1, Math.min(initialCrop.height + deltaY, 1 - initialCrop.y));
- break;
- case 'left': {
- const newX = Math.max(0, initialCrop.x + deltaX);
- const right = initialCrop.x + initialCrop.width;
- newCrop.x = Math.min(newX, right - 0.1);
- newCrop.width = right - newCrop.x;
- break;
- }
- case 'right':
- newCrop.width = Math.max(0.1, Math.min(initialCrop.width + deltaX, 1 - initialCrop.x));
- break;
- case 'move': {
- const newX = Math.max(0, Math.min(initialCrop.x + deltaX, 1 - initialCrop.width));
- const newY = Math.max(0, Math.min(initialCrop.y + deltaY, 1 - initialCrop.height));
- newCrop.x = newX;
- newCrop.y = newY;
- break;
- }
- }
-
- onCropChange(newCrop);
- };
-
- const handlePointerUp = (e: React.PointerEvent) => {
- if (isDragging) {
- try {
- e.currentTarget.releasePointerCapture(e.pointerId);
- } catch {
- }
- }
- setIsDragging(null);
- };
-
- const cropPixelX = cropRegion.x * 100;
- const cropPixelY = cropRegion.y * 100;
- const cropPixelWidth = cropRegion.width * 100;
- const cropPixelHeight = cropRegion.height * 100;
- const videoAspectRatio = videoElement ? videoElement.videoWidth / videoElement.videoHeight : 16/9;
- const isVideoPortrait = videoAspectRatio < 1;
- const maxContainerWidth = isVideoPortrait ? '40vw' : '75vw';
- const maxContainerHeight = '75vh';
-
- return (
- <div className="w-full p-8">
- <div
- ref={containerRef}
- className="relative w-full bg-black rounded-lg overflow-visible cursor-default select-none shadow-2xl"
- style={{
- aspectRatio: videoAspectRatio,
- maxWidth: maxContainerWidth,
- maxHeight: maxContainerHeight,
- margin: '0 auto',
- }}
- onPointerMove={handlePointerMove}
- onPointerUp={handlePointerUp}
- onPointerLeave={handlePointerUp}
- >
- <canvas
- ref={canvasRef}
- className="w-full h-full rounded-lg"
- style={{ imageRendering: 'auto' }}
- />
-
- <div className="absolute inset-0 pointer-events-none" style={{ transition: 'none' }}>
- <svg width="100%" height="100%" className="absolute inset-0" style={{ transition: 'none' }}>
- <defs>
- <mask id="cropMask">
- <rect width="100%" height="100%" fill="white" />
- <rect
- x={`${cropPixelX}%`}
- y={`${cropPixelY}%`}
- width={`${cropPixelWidth}%`}
- height={`${cropPixelHeight}%`}
- fill="black"
- style={{ transition: 'none' }}
- />
- </mask>
- </defs>
- <rect
- width="100%"
- height="100%"
- fill="black"
- fillOpacity="0.6"
- mask="url(#cropMask)"
- style={{ transition: 'none' }}
- />
- </svg>
- </div>
-
- <div
- className="absolute z-10 pointer-events-auto cursor-move"
- style={{
- left: `${cropPixelX}%`,
- top: `${cropPixelY}%`,
- width: `${cropPixelWidth}%`,
- height: `${cropPixelHeight}%`,
- transition: 'none',
- }}
- onPointerDown={(e) => handlePointerDown(e, 'move')}
- />
-
- <div
- className={cn(
- "absolute h-[3px] cursor-ns-resize z-20 pointer-events-auto bg-[#34B27B]"
- )}
- style={{
- left: `${cropPixelX}%`,
- top: `${cropPixelY}%`,
- width: `${cropPixelWidth}%`,
- transform: 'translateY(-50%)',
- willChange: 'transform',
- transition: 'none',
- }}
- onPointerDown={(e) => handlePointerDown(e, 'top')}
- />
-
- <div
- className={cn(
- "absolute h-[3px] cursor-ns-resize z-20 pointer-events-auto bg-[#34B27B]"
- )}
- style={{
- left: `${cropPixelX}%`,
- top: `${cropPixelY + cropPixelHeight}%`,
- width: `${cropPixelWidth}%`,
- transform: 'translateY(-50%)',
- willChange: 'transform',
- transition: 'none',
- }}
- onPointerDown={(e) => handlePointerDown(e, 'bottom')}
- />
-
- <div
- className={cn(
- "absolute w-[3px] cursor-ew-resize z-20 pointer-events-auto bg-[#34B27B]"
- )}
- style={{
- left: `${cropPixelX}%`,
- top: `${cropPixelY}%`,
- height: `${cropPixelHeight}%`,
- transform: 'translateX(-50%)',
- willChange: 'transform',
- transition: 'none',
- }}
- onPointerDown={(e) => handlePointerDown(e, 'left')}
- />
-
- <div
- className={cn(
- "absolute w-[3px] cursor-ew-resize z-20 pointer-events-auto bg-[#34B27B]"
- )}
- style={{
- left: `${cropPixelX + cropPixelWidth}%`,
- top: `${cropPixelY}%`,
- height: `${cropPixelHeight}%`,
- transform: 'translateX(-50%)',
- willChange: 'transform',
- transition: 'none',
- }}
- onPointerDown={(e) => handlePointerDown(e, 'right')}
- />
- </div>
- </div>
- );
+ const canvasRef = useRef<HTMLCanvasElement>(null);
+ const containerRef = useRef<HTMLDivElement>(null);
+ const [isDragging, setIsDragging] = useState<DragHandle>(null);
+ const [dragStart, setDragStart] = useState({ x: 0, y: 0 });
+ const [initialCrop, setInitialCrop] = useState<CropRegion>(cropRegion);
+
+ useEffect(() => {
+ if (!videoElement || !canvasRef.current) return;
+
+ const canvas = canvasRef.current;
+ const ctx = canvas.getContext("2d", { alpha: false });
+ if (!ctx) return;
+
+ canvas.width = videoElement.videoWidth || 1920;
+ canvas.height = videoElement.videoHeight || 1080;
+
+ const draw = () => {
+ if (videoElement.readyState >= 2) {
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
+ ctx.drawImage(videoElement, 0, 0, canvas.width, canvas.height);
+ }
+ requestAnimationFrame(draw);
+ };
+
+ const rafId = requestAnimationFrame(draw);
+ return () => cancelAnimationFrame(rafId);
+ }, [videoElement]);
+
+ const getContainerRect = () => {
+ return (
+ containerRef.current?.getBoundingClientRect() || { width: 0, height: 0, left: 0, top: 0 }
+ );
+ };
+
+ const handlePointerDown = (e: React.PointerEvent, handle: DragHandle) => {
+ e.stopPropagation();
+ e.preventDefault();
+ setIsDragging(handle);
+ const rect = getContainerRect();
+ setDragStart({
+ x: (e.clientX - rect.left) / rect.width,
+ y: (e.clientY - rect.top) / rect.height,
+ });
+ setInitialCrop(cropRegion);
+
+ e.currentTarget.setPointerCapture(e.pointerId);
+ };
+
+ const handlePointerMove = (e: React.PointerEvent) => {
+ if (!isDragging) return;
+
+ const rect = getContainerRect();
+ const currentX = (e.clientX - rect.left) / rect.width;
+ const currentY = (e.clientY - rect.top) / rect.height;
+ const deltaX = currentX - dragStart.x;
+ const deltaY = currentY - dragStart.y;
+
+ let newCrop = { ...initialCrop };
+
+ switch (isDragging) {
+ case "top": {
+ const newY = Math.max(0, initialCrop.y + deltaY);
+ const bottom = initialCrop.y + initialCrop.height;
+ newCrop.y = Math.min(newY, bottom - 0.1);
+ newCrop.height = bottom - newCrop.y;
+ break;
+ }
+ case "bottom":
+ newCrop.height = Math.max(0.1, Math.min(initialCrop.height + deltaY, 1 - initialCrop.y));
+ break;
+ case "left": {
+ const newX = Math.max(0, initialCrop.x + deltaX);
+ const right = initialCrop.x + initialCrop.width;
+ newCrop.x = Math.min(newX, right - 0.1);
+ newCrop.width = right - newCrop.x;
+ break;
+ }
+ case "right":
+ newCrop.width = Math.max(0.1, Math.min(initialCrop.width + deltaX, 1 - initialCrop.x));
+ break;
++ case "move": {
++ newCrop.x = Math.max(0, Math.min(initialCrop.x + deltaX, 1 - initialCrop.width));
++ newCrop.y = Math.max(0, Math.min(initialCrop.y + deltaY, 1 - initialCrop.height));
++ break;
++ }
+ }
+
+ onCropChange(newCrop);
+ };
+
+ const handlePointerUp = (e: React.PointerEvent) => {
+ if (isDragging) {
+ try {
+ e.currentTarget.releasePointerCapture(e.pointerId);
+ } catch {
+ // Pointer may already be released; ignore.
+ }
+ }
+ setIsDragging(null);
+ };
+
+ const cropPixelX = cropRegion.x * 100;
+ const cropPixelY = cropRegion.y * 100;
+ const cropPixelWidth = cropRegion.width * 100;
+ const cropPixelHeight = cropRegion.height * 100;
+ const videoAspectRatio = videoElement
+ ? videoElement.videoWidth / videoElement.videoHeight
+ : 16 / 9;
+ const isVideoPortrait = videoAspectRatio < 1;
+ const maxContainerWidth = isVideoPortrait ? "40vw" : "75vw";
+ const maxContainerHeight = "75vh";
+
+ return (
+ <div className="w-full p-8">
+ <div
+ ref={containerRef}
+ className="relative w-full bg-black rounded-lg overflow-visible cursor-default select-none shadow-2xl"
+ style={{
+ aspectRatio: videoAspectRatio,
+ maxWidth: maxContainerWidth,
+ maxHeight: maxContainerHeight,
+ margin: "0 auto",
+ }}
+ onPointerMove={handlePointerMove}
+ onPointerUp={handlePointerUp}
+ onPointerLeave={handlePointerUp}
+ >
+ <canvas
+ ref={canvasRef}
+ className="w-full h-full rounded-lg"
+ style={{ imageRendering: "auto" }}
+ />
+
+ <div className="absolute inset-0 pointer-events-none" style={{ transition: "none" }}>
+ <svg
+ width="100%"
+ height="100%"
+ className="absolute inset-0"
+ style={{ transition: "none" }}
+ >
+ <defs>
+ <mask id="cropMask">
+ <rect width="100%" height="100%" fill="white" />
+ <rect
+ x={`${cropPixelX}%`}
+ y={`${cropPixelY}%`}
+ width={`${cropPixelWidth}%`}
+ height={`${cropPixelHeight}%`}
+ fill="black"
+ style={{ transition: "none" }}
+ />
+ </mask>
+ </defs>
+ <rect
+ width="100%"
+ height="100%"
+ fill="black"
+ fillOpacity="0.6"
+ mask="url(#cropMask)"
+ style={{ transition: "none" }}
+ />
+ </svg>
+ </div>
+
++ <div
++ className="absolute z-10 pointer-events-auto cursor-move"
++ style={{
++ left: `${cropPixelX}%`,
++ top: `${cropPixelY}%`,
++ width: `${cropPixelWidth}%`,
++ height: `${cropPixelHeight}%`,
++ transition: "none",
++ }}
++ onPointerDown={(e) => handlePointerDown(e, "move")}
++ />
++
+ <div
+ className={cn("absolute h-[3px] cursor-ns-resize z-20 pointer-events-auto bg-[#34B27B]")}
+ style={{
+ left: `${cropPixelX}%`,
+ top: `${cropPixelY}%`,
+ width: `${cropPixelWidth}%`,
+ transform: "translateY(-50%)",
+ willChange: "transform",
+ transition: "none",
+ }}
+ onPointerDown={(e) => handlePointerDown(e, "top")}
+ />
+
+ <div
+ className={cn("absolute h-[3px] cursor-ns-resize z-20 pointer-events-auto bg-[#34B27B]")}
+ style={{
+ left: `${cropPixelX}%`,
+ top: `${cropPixelY + cropPixelHeight}%`,
+ width: `${cropPixelWidth}%`,
+ transform: "translateY(-50%)",
+ willChange: "transform",
+ transition: "none",
+ }}
+ onPointerDown={(e) => handlePointerDown(e, "bottom")}
+ />
+
+ <div
+ className={cn("absolute w-[3px] cursor-ew-resize z-20 pointer-events-auto bg-[#34B27B]")}
+ style={{
+ left: `${cropPixelX}%`,
+ top: `${cropPixelY}%`,
+ height: `${cropPixelHeight}%`,
+ transform: "translateX(-50%)",
+ willChange: "transform",
+ transition: "none",
+ }}
+ onPointerDown={(e) => handlePointerDown(e, "left")}
+ />
+
+ <div
+ className={cn("absolute w-[3px] cursor-ew-resize z-20 pointer-events-auto bg-[#34B27B]")}
+ style={{
+ left: `${cropPixelX + cropPixelWidth}%`,
+ top: `${cropPixelY}%`,
+ height: `${cropPixelHeight}%`,
+ transform: "translateX(-50%)",
+ willChange: "transform",
+ transition: "none",
+ }}
+ onPointerDown={(e) => handlePointerDown(e, "right")}
+ />
+ </div>
+ </div>
+ );
}
diff --cc src/components/video-editor/SettingsPanel.tsx
index dfe3f5011,46b17b960..70c38c4c6
--- a/src/components/video-editor/SettingsPanel.tsx
+++ b/src/components/video-editor/SettingsPanel.tsx
@@@ -1,28 -1,6 +1,30 @@@
-import { cn } from "@/lib/utils";
-import { useEffect, useRef } from "react";
-import { getAssetPath } from "@/lib/assetPath";
+import Block from "@uiw/react-color-block";
+import {
+ Bug,
+ Crop,
+ Download,
+ Film,
+ FolderOpen,
+ Image,
++ Lock,
+ Palette,
+ Save,
+ Sparkles,
+ Star,
+ Trash2,
++ Unlock,
+ Upload,
+ X,
+} from "lucide-react";
- import { useEffect, useRef, useState } from "react";
++import { useCallback, useEffect, useRef, useState } from "react";
+import { toast } from "sonner";
+import {
+ Accordion,
+ AccordionContent,
+ AccordionItem,
+ AccordionTrigger,
+} from "@/components/ui/accordion";
+import { Button } from "@/components/ui/button";
import { Slider } from "@/components/ui/slider";
import { Switch } from "@/components/ui/switch";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
@@@ -133,807 -102,834 +135,987 @@@ interface SettingsPanelProps
export default SettingsPanel;
const ZOOM_DEPTH_OPTIONS: Array<{ depth: ZoomDepth; label: string }> = [
- { depth: 1, label: "1.25×" },
- { depth: 2, label: "1.5×" },
- { depth: 3, label: "1.8×" },
- { depth: 4, label: "2.2×" },
- { depth: 5, label: "3.5×" },
- { depth: 6, label: "5×" },
+ { depth: 1, label: "1.25×" },
+ { depth: 2, label: "1.5×" },
+ { depth: 3, label: "1.8×" },
+ { depth: 4, label: "2.2×" },
+ { depth: 5, label: "3.5×" },
+ { depth: 6, label: "5×" },
];
-export function SettingsPanel({
- selected,
- onWallpaperChange,
- selectedZoomDepth,
- onZoomDepthChange,
- selectedZoomId,
- onZoomDelete,
- selectedTrimId,
- onTrimDelete,
- shadowIntensity = 0,
- onShadowChange,
- showBlur,
- onBlurChange,
- motionBlurEnabled = false,
- onMotionBlurChange,
- borderRadius = 0,
- onBorderRadiusChange,
- padding = 50,
- onPaddingChange,
- cropRegion,
- onCropChange,
- aspectRatio,
- videoElement,
- exportQuality = 'good',
- onExportQualityChange,
- exportFormat = 'mp4',
- onExportFormatChange,
- gifFrameRate = 15,
- onGifFrameRateChange,
- gifLoop = true,
- onGifLoopChange,
- gifSizePreset = 'medium',
- onGifSizePresetChange,
- gifOutputDimensions = { width: 1280, height: 720 },
- onSaveProject,
- onLoadProject,
- onExport,
- selectedAnnotationId,
- annotationRegions = [],
- onAnnotationContentChange,
- onAnnotationTypeChange,
- onAnnotationStyleChange,
- onAnnotationFigureDataChange,
- onAnnotationDelete,
- selectedSpeedId,
- selectedSpeedValue,
- onSpeedChange,
- onSpeedDelete,
+export function SettingsPanel({
+ selected,
+ onWallpaperChange,
+ selectedZoomDepth,
+ onZoomDepthChange,
+ selectedZoomId,
+ onZoomDelete,
+ selectedTrimId,
+ onTrimDelete,
+ shadowIntensity = 0,
+ onShadowChange,
+ onShadowCommit,
+ showBlur,
+ onBlurChange,
+ motionBlurEnabled = false,
+ onMotionBlurChange,
+ borderRadius = 0,
+ onBorderRadiusChange,
+ onBorderRadiusCommit,
+ padding = 50,
+ onPaddingChange,
+ onPaddingCommit,
+ cropRegion,
+ onCropChange,
+ aspectRatio,
+ videoElement,
+ exportQuality = "good",
+ onExportQualityChange,
+ exportFormat = "mp4",
+ onExportFormatChange,
+ gifFrameRate = 15,
+ onGifFrameRateChange,
+ gifLoop = true,
+ onGifLoopChange,
+ gifSizePreset = "medium",
+ onGifSizePresetChange,
+ gifOutputDimensions = { width: 1280, height: 720 },
+ onSaveProject,
+ onLoadProject,
+ onExport,
+ selectedAnnotationId,
+ annotationRegions = [],
+ onAnnotationContentChange,
+ onAnnotationTypeChange,
+ onAnnotationStyleChange,
+ onAnnotationFigureDataChange,
+ onAnnotationDelete,
+ selectedSpeedId,
+ selectedSpeedValue,
+ onSpeedChange,
+ onSpeedDelete,
}: SettingsPanelProps) {
- const [wallpaperPaths, setWallpaperPaths] = useState<string[]>([]);
- const [customImages, setCustomImages] = useState<string[]>([]);
- const fileInputRef = useRef<HTMLInputElement>(null);
-
- useEffect(() => {
- let mounted = true
- ;(async () => {
- try {
- const resolved = await Promise.all(WALLPAPER_RELATIVE.map(p => getAssetPath(p)))
- if (mounted) setWallpaperPaths(resolved)
- } catch (err) {
- if (mounted) setWallpaperPaths(WALLPAPER_RELATIVE.map(p => `/${p}`))
- }
- })()
- return () => { mounted = false }
- }, [])
- const colorPalette = [
- '#FF0000', '#FFD700', '#00FF00', '#FFFFFF', '#0000FF', '#FF6B00',
- '#9B59B6', '#E91E63', '#00BCD4', '#FF5722', '#8BC34A', '#FFC107',
- '#34B27B', '#000000', '#607D8B', '#795548',
- ];
-
- const [selectedColor, setSelectedColor] = useState('#ADADAD');
- const [gradient, setGradient] = useState<string>(GRADIENTS[0]);
- const [showCropDropdown, setShowCropDropdown] = useState(false);
- const [cropAspectLocked, setCropAspectLocked] = useState(false);
- const [cropAspectRatio, setCropAspectRatio] = useState<string>('');
-
- const videoWidth = videoElement?.videoWidth || 1920;
- const videoHeight = videoElement?.videoHeight || 1080;
-
- const handleCropNumericChange = useCallback((field: 'x' | 'y' | 'width' | 'height', pixelValue: number) => {
- if (!cropRegion || !onCropChange) return;
- const norm = { ...cropRegion };
- const maxW = videoWidth;
- const maxH = videoHeight;
-
- switch (field) {
- case 'x':
- norm.x = Math.max(0, Math.min(pixelValue / maxW, 1 - norm.width));
- break;
- case 'y':
- norm.y = Math.max(0, Math.min(pixelValue / maxH, 1 - norm.height));
- break;
- case 'width': {
- const newW = Math.max(0.05, Math.min(pixelValue / maxW, 1 - norm.x));
- if (cropAspectLocked && norm.width > 0 && norm.height > 0) {
- const ratio = norm.width / norm.height;
- const newH = newW / ratio;
- if (norm.y + newH <= 1) {
- norm.width = newW;
- norm.height = newH;
- }
- } else {
- norm.width = newW;
- }
- break;
- }
- case 'height': {
- const newH = Math.max(0.05, Math.min(pixelValue / maxH, 1 - norm.y));
- if (cropAspectLocked && norm.width > 0 && norm.height > 0) {
- const ratio = norm.width / norm.height;
- const newW = newH * ratio;
- if (norm.x + newW <= 1) {
- norm.height = newH;
- norm.width = newW;
- }
- } else {
- norm.height = newH;
- }
- break;
- }
- }
- onCropChange(norm);
- }, [cropRegion, onCropChange, videoWidth, videoHeight, cropAspectLocked]);
-
- const applyCropAspectPreset = useCallback((preset: string) => {
- if (!cropRegion || !onCropChange) return;
- setCropAspectRatio(preset);
- if (preset === '') {
- setCropAspectLocked(false);
- return;
- }
- const [wStr, hStr] = preset.split(':');
- const targetRatio = Number(wStr) / Number(hStr);
- const norm = { ...cropRegion };
- // Keep the current width, adjust height to match ratio
- const newH = (norm.width * videoWidth) / (targetRatio * videoHeight);
- if (norm.y + newH <= 1 && newH >= 0.05) {
- norm.height = newH;
- } else {
- // Keep height, adjust width
- const newW = (norm.height * videoHeight * targetRatio) / videoWidth;
- if (norm.x + newW <= 1 && newW >= 0.05) {
- norm.width = newW;
- }
- }
- onCropChange(norm);
- setCropAspectLocked(true);
- }, [cropRegion, onCropChange, videoWidth, videoHeight]);
-
- const zoomEnabled = Boolean(selectedZoomDepth);
- const trimEnabled = Boolean(selectedTrimId);
-
- const handleDeleteClick = () => {
- if (selectedZoomId && onZoomDelete) {
- onZoomDelete(selectedZoomId);
- }
- };
-
- const handleTrimDeleteClick = () => {
- if (selectedTrimId && onTrimDelete) {
- onTrimDelete(selectedTrimId);
- }
- };
-
- const handleImageUpload = (event: React.ChangeEvent<HTMLInputElement>) => {
- const files = event.target.files;
- if (!files || files.length === 0) return;
-
- const file = files[0];
-
- // Validate file type - only allow JPG/JPEG
- const validTypes = ['image/jpeg', 'image/jpg'];
- if (!validTypes.includes(file.type)) {
- toast.error('Invalid file type', {
- description: 'Please upload a JPG or JPEG image file.',
- });
- event.target.value = '';
- return;
- }
-
- const reader = new FileReader();
-
- reader.onload = (e) => {
- const dataUrl = e.target?.result as string;
- if (dataUrl) {
- setCustomImages(prev => [...prev, dataUrl]);
- onWallpaperChange(dataUrl);
- toast.success('Custom image uploaded successfully!');
- }
- };
-
- reader.onerror = () => {
- toast.error('Failed to upload image', {
- description: 'There was an error reading the file.',
- });
- };
-
- reader.readAsDataURL(file);
- // Reset input so the same file can be selected again
- event.target.value = '';
- };
-
- const handleRemoveCustomImage = (imageUrl: string, event: React.MouseEvent) => {
- event.stopPropagation();
- setCustomImages(prev => prev.filter(img => img !== imageUrl));
- // If the removed image was selected, clear selection
- if (selected === imageUrl) {
- onWallpaperChange(wallpaperPaths[0] || WALLPAPER_RELATIVE[0]);
- }
- };
-
- // Find selected annotation
- const selectedAnnotation = selectedAnnotationId
- ? annotationRegions.find(a => a.id === selectedAnnotationId)
- : null;
-
- // If an annotation is selected, show annotation settings instead
- if (selectedAnnotation && onAnnotationContentChange && onAnnotationTypeChange && onAnnotationStyleChange && onAnnotationDelete) {
- return (
- <AnnotationSettingsPanel
- annotation={selectedAnnotation}
- onContentChange={(content) => onAnnotationContentChange(selectedAnnotation.id, content)}
- onTypeChange={(type) => onAnnotationTypeChange(selectedAnnotation.id, type)}
- onStyleChange={(style) => onAnnotationStyleChange(selectedAnnotation.id, style)}
- onFigureDataChange={onAnnotationFigureDataChange ? (figureData) => onAnnotationFigureDataChange(selectedAnnotation.id, figureData) : undefined}
- onDelete={() => onAnnotationDelete(selectedAnnotation.id)}
- />
- );
- }
-
- return (
- <div className="flex-[2] min-w-0 bg-[#09090b] border border-white/5 rounded-2xl flex flex-col shadow-xl h-full overflow-hidden">
- <div className="flex-1 overflow-y-auto custom-scrollbar p-4 pb-0">
- <div className="mb-4">
- <div className="flex items-center justify-between mb-3">
- <span className="text-sm font-medium text-slate-200">Zoom Level</span>
- <div className="flex items-center gap-2">
- {zoomEnabled && selectedZoomDepth && (
- <span className="text-[10px] uppercase tracking-wider font-medium text-[#34B27B] bg-[#34B27B]/10 px-2 py-0.5 rounded-full">
- {ZOOM_DEPTH_OPTIONS.find(o => o.depth === selectedZoomDepth)?.label}
- </span>
- )}
- <KeyboardShortcutsHelp />
- </div>
- </div>
- <div className="grid grid-cols-6 gap-1.5">
- {ZOOM_DEPTH_OPTIONS.map((option) => {
- const isActive = selectedZoomDepth === option.depth;
- return (
- <Button
- key={option.depth}
- type="button"
- disabled={!zoomEnabled}
- onClick={() => onZoomDepthChange?.(option.depth)}
- className={cn(
- "h-auto w-full rounded-lg border px-1 py-2 text-center shadow-sm transition-all",
- "duration-200 ease-out",
- zoomEnabled ? "opacity-100 cursor-pointer" : "opacity-40 cursor-not-allowed",
- isActive
- ? "border-[#34B27B] bg-[#34B27B] text-white shadow-[#34B27B]/20"
- : "border-white/5 bg-white/5 text-slate-400 hover:bg-white/10 hover:border-white/10 hover:text-slate-200"
- )}
- >
- <span className="text-xs font-semibold">{option.label}</span>
- </Button>
- );
- })}
- </div>
- {!zoomEnabled && (
- <p className="text-[10px] text-slate-500 mt-2 text-center">Select a zoom region to adjust</p>
- )}
- {zoomEnabled && (
- <Button
- onClick={handleDeleteClick}
- variant="destructive"
- size="sm"
- className="mt-2 w-full gap-2 bg-red-500/10 text-red-400 border border-red-500/20 hover:bg-red-500/20 hover:border-red-500/30 transition-all h-8 text-xs"
- >
- <Trash2 className="w-3 h-3" />
- Delete Zoom
- </Button>
- )}
- </div>
-
- {trimEnabled && (
- <div className="mb-4">
- <Button
- onClick={handleTrimDeleteClick}
- variant="destructive"
- size="sm"
- className="w-full gap-2 bg-red-500/10 text-red-400 border border-red-500/20 hover:bg-red-500/20 hover:border-red-500/30 transition-all h-8 text-xs"
- >
- <Trash2 className="w-3 h-3" />
- Delete Trim Region
- </Button>
- </div>
- )}
-
- <div className="mb-4">
- <div className="flex items-center justify-between mb-3">
- <span className="text-sm font-medium text-slate-200">Playback Speed</span>
- {selectedSpeedId && selectedSpeedValue && (
- <span className="text-[10px] uppercase tracking-wider font-medium text-[#d97706] bg-[#d97706]/10 px-2 py-0.5 rounded-full">
- {SPEED_OPTIONS.find(o => o.speed === selectedSpeedValue)?.label ?? `${selectedSpeedValue}×`}
- </span>
- )}
- </div>
- <div className="grid grid-cols-7 gap-1.5">
- {SPEED_OPTIONS.map((option) => {
- const isActive = selectedSpeedValue === option.speed;
- return (
- <Button
- key={option.speed}
- type="button"
- disabled={!selectedSpeedId}
- onClick={() => onSpeedChange?.(option.speed)}
- className={cn(
- "h-auto w-full rounded-lg border px-1 py-2 text-center shadow-sm transition-all",
- "duration-200 ease-out",
- selectedSpeedId ? "opacity-100 cursor-pointer" : "opacity-40 cursor-not-allowed",
- isActive
- ? "border-[#d97706] bg-[#d97706] text-white shadow-[#d97706]/20"
- : "border-white/5 bg-white/5 text-slate-400 hover:bg-white/10 hover:border-white/10 hover:text-slate-200"
- )}
- >
- <span className="text-xs font-semibold">{option.label}</span>
- </Button>
- );
- })}
- </div>
- {!selectedSpeedId && (
- <p className="text-[10px] text-slate-500 mt-2 text-center">Select a speed region to adjust</p>
- )}
- {selectedSpeedId && (
- <Button
- onClick={() => selectedSpeedId && onSpeedDelete?.(selectedSpeedId)}
- variant="destructive"
- size="sm"
- className="mt-2 w-full gap-2 bg-red-500/10 text-red-400 border border-red-500/20 hover:bg-red-500/20 hover:border-red-500/30 transition-all h-8 text-xs"
- >
- <Trash2 className="w-3 h-3" />
- Delete Speed Region
- </Button>
- )}
- </div>
-
- <Accordion type="multiple" defaultValue={["effects", "background"]} className="space-y-1">
- <AccordionItem value="effects" className="border-white/5 rounded-xl bg-white/[0.02] px-3">
- <AccordionTrigger className="py-2.5 hover:no-underline">
- <div className="flex items-center gap-2">
- <Sparkles className="w-4 h-4 text-[#34B27B]" />
- <span className="text-xs font-medium">Video Effects</span>
- </div>
- </AccordionTrigger>
- <AccordionContent className="pb-3">
- <div className="grid grid-cols-2 gap-2 mb-3">
- <div className="flex items-center justify-between p-2 rounded-lg bg-white/5 border border-white/5">
- <div className="text-[10px] font-medium text-slate-300">Motion Blur</div>
- <Switch
- checked={motionBlurEnabled}
- onCheckedChange={onMotionBlurChange}
- className="data-[state=checked]:bg-[#34B27B] scale-90"
- />
- </div>
- <div className="flex items-center justify-between p-2 rounded-lg bg-white/5 border border-white/5">
- <div className="text-[10px] font-medium text-slate-300">Blur BG</div>
- <Switch
- checked={showBlur}
- onCheckedChange={onBlurChange}
- className="data-[state=checked]:bg-[#34B27B] scale-90"
- />
- </div>
- </div>
-
- <div className="grid grid-cols-2 gap-2">
- <div className="p-2 rounded-lg bg-white/5 border border-white/5">
- <div className="flex items-center justify-between mb-1">
- <div className="text-[10px] font-medium text-slate-300">Shadow</div>
- <span className="text-[10px] text-slate-500 font-mono">{Math.round(shadowIntensity * 100)}%</span>
- </div>
- <Slider
- value={[shadowIntensity]}
- onValueChange={(values) => onShadowChange?.(values[0])}
- min={0}
- max={1}
- step={0.01}
- className="w-full [&_[role=slider]]:bg-[#34B27B] [&_[role=slider]]:border-[#34B27B] [&_[role=slider]]:h-3 [&_[role=slider]]:w-3"
- />
- </div>
- <div className="p-2 rounded-lg bg-white/5 border border-white/5">
- <div className="flex items-center justify-between mb-1">
- <div className="text-[10px] font-medium text-slate-300">Roundness</div>
- <span className="text-[10px] text-slate-500 font-mono">{borderRadius}px</span>
- </div>
- <Slider
- value={[borderRadius]}
- onValueChange={(values) => onBorderRadiusChange?.(values[0])}
- min={0}
- max={16}
- step={0.5}
- className="w-full [&_[role=slider]]:bg-[#34B27B] [&_[role=slider]]:border-[#34B27B] [&_[role=slider]]:h-3 [&_[role=slider]]:w-3"
- />
- </div>
- <div className="p-2 rounded-lg bg-white/5 border border-white/5">
- <div className="flex items-center justify-between mb-1">
- <div className="text-[10px] font-medium text-slate-300">Padding</div>
- <span className="text-[10px] text-slate-500 font-mono">{padding}%</span>
- </div>
- <Slider
- value={[padding]}
- onValueChange={(values) => onPaddingChange?.(values[0])}
- min={0}
- max={100}
- step={1}
- className="w-full [&_[role=slider]]:bg-[#34B27B] [&_[role=slider]]:border-[#34B27B] [&_[role=slider]]:h-3 [&_[role=slider]]:w-3"
- />
- </div>
- </div>
-
- <Button
- onClick={() => setShowCropDropdown(!showCropDropdown)}
- variant="outline"
- className="w-full mt-2 gap-1.5 bg-white/5 text-slate-200 border-white/10 hover:bg-white/10 hover:border-white/20 hover:text-white text-[10px] h-8 transition-all"
- >
- <Crop className="w-3 h-3" />
- Crop Video
- </Button>
- </AccordionContent>
- </AccordionItem>
-
- <AccordionItem value="background" className="border-white/5 rounded-xl bg-white/[0.02] px-3">
- <AccordionTrigger className="py-2.5 hover:no-underline">
- <div className="flex items-center gap-2">
- <Palette className="w-4 h-4 text-[#34B27B]" />
- <span className="text-xs font-medium">Background</span>
- </div>
- </AccordionTrigger>
- <AccordionContent className="pb-3">
- <Tabs defaultValue="image" className="w-full">
- <TabsList className="mb-2 bg-white/5 border border-white/5 p-0.5 w-full grid grid-cols-3 h-7 rounded-lg">
- <TabsTrigger value="image" className="data-[state=active]:bg-[#34B27B] data-[state=active]:text-white text-slate-400 text-[10px] py-1 rounded-md transition-all">Image</TabsTrigger>
- <TabsTrigger value="color" className="data-[state=active]:bg-[#34B27B] data-[state=active]:text-white text-slate-400 text-[10px] py-1 rounded-md transition-all">Color</TabsTrigger>
- <TabsTrigger value="gradient" className="data-[state=active]:bg-[#34B27B] data-[state=active]:text-white text-slate-400 text-[10px] py-1 rounded-md transition-all">Gradient</TabsTrigger>
- </TabsList>
-
- <div className="max-h-[min(200px,25vh)] overflow-y-auto custom-scrollbar">
- <TabsContent value="image" className="mt-0 space-y-2">
- <input
- type="file"
- ref={fileInputRef}
- onChange={handleImageUpload}
- accept=".jpg,.jpeg,image/jpeg"
- className="hidden"
- />
- <Button
- onClick={() => fileInputRef.current?.click()}
- variant="outline"
- className="w-full gap-2 bg-white/5 text-slate-200 border-white/10 hover:bg-[#34B27B] hover:text-white hover:border-[#34B27B] transition-all h-7 text-[10px]"
- >
- <Upload className="w-3 h-3" />
- Upload Custom
- </Button>
-
- <div className="grid grid-cols-7 gap-1.5">
- {customImages.map((imageUrl, idx) => {
- const isSelected = selected === imageUrl;
- return (
- <div
- key={`custom-${idx}`}
- className={cn(
- "aspect-square w-9 h-9 rounded-md border-2 overflow-hidden cursor-pointer transition-all duration-200 relative group shadow-sm",
- isSelected
- ? "border-[#34B27B] ring-1 ring-[#34B27B]/30"
- : "border-white/10 hover:border-[#34B27B]/40 opacity-80 hover:opacity-100 bg-white/5"
- )}
- style={{ backgroundImage: `url(${imageUrl})`, backgroundSize: "cover", backgroundPosition: "center" }}
- onClick={() => onWallpaperChange(imageUrl)}
- role="button"
- >
- <button
- onClick={(e) => handleRemoveCustomImage(imageUrl, e)}
- className="absolute top-0.5 right-0.5 w-3 h-3 bg-red-500/90 hover:bg-red-500 rounded-full flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity z-10"
- >
- <X className="w-2 h-2 text-white" />
- </button>
- </div>
- );
- })}
-
- {(wallpaperPaths.length > 0 ? wallpaperPaths : WALLPAPER_RELATIVE.map(p => `/${p}`)).map((path) => {
- const isSelected = (() => {
- if (!selected) return false;
- if (selected === path) return true;
- try {
- const clean = (s: string) => s.replace(/^file:\/\//, '').replace(/^\//, '')
- if (clean(selected).endsWith(clean(path))) return true;
- if (clean(path).endsWith(clean(selected))) return true;
- } catch {}
- return false;
- })();
- return (
- <div
- key={path}
- className={cn(
- "aspect-square w-9 h-9 rounded-md border-2 overflow-hidden cursor-pointer transition-all duration-200 shadow-sm",
- isSelected
- ? "border-[#34B27B] ring-1 ring-[#34B27B]/30"
- : "border-white/10 hover:border-[#34B27B]/40 opacity-80 hover:opacity-100 bg-white/5"
- )}
- style={{ backgroundImage: `url(${path})`, backgroundSize: "cover", backgroundPosition: "center" }}
- onClick={() => onWallpaperChange(path)}
- role="button"
- />
- )
- })}
- </div>
- </TabsContent>
-
- <TabsContent value="color" className="mt-0">
- <div className="p-1">
- <Block
- color={selectedColor}
- colors={colorPalette}
- onChange={(color) => {
- setSelectedColor(color.hex);
- onWallpaperChange(color.hex);
- }}
- style={{
- width: '100%',
- borderRadius: '8px',
- }}
- />
- </div>
- </TabsContent>
-
- <TabsContent value="gradient" className="mt-0">
- <div className="grid grid-cols-7 gap-1.5">
- {GRADIENTS.map((g, idx) => (
- <div
- key={g}
- className={cn(
- "aspect-square w-9 h-9 rounded-md border-2 overflow-hidden cursor-pointer transition-all duration-200 shadow-sm",
- gradient === g
- ? "border-[#34B27B] ring-1 ring-[#34B27B]/30"
- : "border-white/10 hover:border-[#34B27B]/40 opacity-80 hover:opacity-100 bg-white/5"
- )}
- style={{ background: g }}
- aria-label={`Gradient ${idx + 1}`}
- onClick={() => { setGradient(g); onWallpaperChange(g); }}
- role="button"
- />
- ))}
- </div>
- </TabsContent>
- </div>
- </Tabs>
- </AccordionContent>
- </AccordionItem>
- </Accordion>
- </div>
-
- {showCropDropdown && cropRegion && onCropChange && (
- <>
- <div
- className="fixed inset-0 bg-black/80 backdrop-blur-sm z-50 animate-in fade-in duration-200"
- onClick={() => setShowCropDropdown(false)}
- />
- <div className="fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 z-[60] bg-[#09090b] rounded-2xl shadow-2xl border border-white/10 p-8 w-[90vw] max-w-5xl max-h-[90vh] overflow-auto animate-in zoom-in-95 duration-200">
- <div className="flex items-center justify-between mb-6">
- <div>
- <span className="text-xl font-bold text-slate-200">Crop Video</span>
- <p className="text-sm text-slate-400 mt-2">Drag on each side to adjust the crop area</p>
- </div>
- <Button
- variant="ghost"
- size="icon"
- onClick={() => setShowCropDropdown(false)}
- className="hover:bg-white/10 text-slate-400 hover:text-white"
- >
- <X className="w-5 h-5" />
- </Button>
- </div>
- <CropControl
- videoElement={videoElement || null}
- cropRegion={cropRegion}
- onCropChange={onCropChange}
- aspectRatio={aspectRatio}
- />
- <div className="mt-6 space-y-4">
- <div className="flex flex-wrap items-end gap-3">
- {[
- { label: 'X', field: 'x' as const, max: videoWidth },
- { label: 'Y', field: 'y' as const, max: videoHeight },
- { label: 'W', field: 'width' as const, max: videoWidth },
- { label: 'H', field: 'height' as const, max: videoHeight },
- ].map(({ label, field, max }) => (
- <div key={field} className="flex flex-col gap-1">
- <label className="text-[10px] font-medium text-slate-400 uppercase tracking-wider">{label}</label>
- <input
- type="number"
- min={0}
- max={max}
- value={Math.round((cropRegion as Record<string, number>)[field] * (field === 'x' || field === 'width' ? videoWidth : videoHeight))}
- onChange={(e) => handleCropNumericChange(field, Number(e.target.value))}
- className="w-[90px] h-8 rounded-md border border-white/10 bg-white/5 px-2 text-xs text-slate-200 outline-none focus:border-[#34B27B]/50 focus:ring-1 focus:ring-[#34B27B]/30 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"
- />
- </div>
- ))}
-
- <div className="flex flex-col gap-1">
- <label className="text-[10px] font-medium text-slate-400 uppercase tracking-wider">Ratio</label>
- <div className="flex items-center gap-1.5">
- <select
- value={cropAspectRatio}
- onChange={(e) => applyCropAspectPreset(e.target.value)}
- className="h-8 rounded-md border border-white/10 bg-[#1a1a1f] px-2 text-xs text-slate-200 outline-none focus:border-[#34B27B]/50 cursor-pointer"
- >
- <option value="" className="bg-[#1a1a1f] text-slate-200">Free</option>
- <option value="16:9" className="bg-[#1a1a1f] text-slate-200">16:9</option>
- <option value="9:16" className="bg-[#1a1a1f] text-slate-200">9:16</option>
- <option value="4:3" className="bg-[#1a1a1f] text-slate-200">4:3</option>
- <option value="3:4" className="bg-[#1a1a1f] text-slate-200">3:4</option>
- <option value="1:1" className="bg-[#1a1a1f] text-slate-200">1:1</option>
- <option value="21:9" className="bg-[#1a1a1f] text-slate-200">21:9</option>
- </select>
- <button
- onClick={() => setCropAspectLocked(!cropAspectLocked)}
- className={cn(
- "h-8 w-8 flex items-center justify-center rounded-md border transition-all",
- cropAspectLocked
- ? "border-[#34B27B]/50 bg-[#34B27B]/10 text-[#34B27B]"
- : "border-white/10 bg-white/5 text-slate-400 hover:text-slate-200"
- )}
- title={cropAspectLocked ? "Unlock aspect ratio" : "Lock aspect ratio"}
- >
- {cropAspectLocked ? <Lock className="w-3.5 h-3.5" /> : <Unlock className="w-3.5 h-3.5" />}
- </button>
- </div>
- </div>
-
- <p className="text-[10px] text-slate-500 self-center ml-2">
- {videoWidth} × {videoHeight}px
- </p>
- </div>
-
- <div className="flex justify-end">
- <Button
- onClick={() => setShowCropDropdown(false)}
- size="lg"
- className="bg-[#34B27B] hover:bg-[#34B27B]/90 text-white"
- >
- Done
- </Button>
- </div>
- </div>
- </div>
- </>
- )}
-
- <div className="flex-shrink-0 p-4 pt-3 border-t border-white/5 bg-[#09090b]">
- <div className="flex items-center gap-2 mb-3">
- <button
- onClick={() => onExportFormatChange?.('mp4')}
- className={cn(
- "flex-1 flex items-center justify-center gap-1.5 py-2 rounded-lg border transition-all text-xs font-medium",
- exportFormat === 'mp4'
- ? "bg-[#34B27B]/10 border-[#34B27B]/50 text-white"
- : "bg-white/5 border-white/10 text-slate-400 hover:bg-white/10 hover:text-slate-200"
- )}
- >
- <Film className="w-3.5 h-3.5" />
- MP4
- </button>
- <button
- onClick={() => onExportFormatChange?.('gif')}
- className={cn(
- "flex-1 flex items-center justify-center gap-1.5 py-2 rounded-lg border transition-all text-xs font-medium",
- exportFormat === 'gif'
- ? "bg-[#34B27B]/10 border-[#34B27B]/50 text-white"
- : "bg-white/5 border-white/10 text-slate-400 hover:bg-white/10 hover:text-slate-200"
- )}
- >
- <Image className="w-3.5 h-3.5" />
- GIF
- </button>
- </div>
-
- {exportFormat === 'mp4' && (
- <div className="mb-3 bg-white/5 border border-white/5 p-0.5 w-full grid grid-cols-3 h-7 rounded-lg">
- <button
- onClick={() => onExportQualityChange?.('medium')}
- className={cn(
- "rounded-md transition-all text-[10px] font-medium",
- exportQuality === 'medium' ? "bg-white text-black" : "text-slate-400 hover:text-slate-200"
- )}
- >
- Low
- </button>
- <button
- onClick={() => onExportQualityChange?.('good')}
- className={cn(
- "rounded-md transition-all text-[10px] font-medium",
- exportQuality === 'good' ? "bg-white text-black" : "text-slate-400 hover:text-slate-200"
- )}
- >
- Medium
- </button>
- <button
- onClick={() => onExportQualityChange?.('source')}
- className={cn(
- "rounded-md transition-all text-[10px] font-medium",
- exportQuality === 'source' ? "bg-white text-black" : "text-slate-400 hover:text-slate-200"
- )}
- >
- High
- </button>
- </div>
- )}
-
- {exportFormat === 'gif' && (
- <div className="mb-3 space-y-2">
- <div className="flex items-center gap-2">
- <div className="flex-1 bg-white/5 border border-white/5 p-0.5 grid grid-cols-4 h-7 rounded-lg">
- {GIF_FRAME_RATES.map((rate) => (
- <button
- key={rate.value}
- onClick={() => onGifFrameRateChange?.(rate.value)}
- className={cn(
- "rounded-md transition-all text-[10px] font-medium",
- gifFrameRate === rate.value ? "bg-white text-black" : "text-slate-400 hover:text-slate-200"
- )}
- >
- {rate.value}
- </button>
- ))}
- </div>
- <div className="flex-1 bg-white/5 border border-white/5 p-0.5 grid grid-cols-3 h-7 rounded-lg">
- {Object.entries(GIF_SIZE_PRESETS).map(([key, _preset]) => (
- <button
- key={key}
- onClick={() => onGifSizePresetChange?.(key as GifSizePreset)}
- className={cn(
- "rounded-md transition-all text-[10px] font-medium",
- gifSizePreset === key ? "bg-white text-black" : "text-slate-400 hover:text-slate-200"
- )}
- >
- {key === 'original' ? 'Orig' : key.charAt(0).toUpperCase() + key.slice(1, 3)}
- </button>
- ))}
- </div>
- </div>
- <div className="flex items-center justify-between">
- <span className="text-[10px] text-slate-500">{gifOutputDimensions.width} × {gifOutputDimensions.height}px</span>
- <div className="flex items-center gap-2">
- <span className="text-[10px] text-slate-400">Loop</span>
- <Switch
- checked={gifLoop}
- onCheckedChange={onGifLoopChange}
- className="data-[state=checked]:bg-[#34B27B] scale-75"
- />
- </div>
- </div>
- </div>
- )}
-
- <div className="grid grid-cols-2 gap-2 mb-2">
- <Button
- type="button"
- variant="outline"
- onClick={onLoadProject}
- className="h-8 text-[10px] font-medium gap-1.5 bg-white/5 border-white/10 text-slate-300 hover:bg-white/10"
- >
- <FolderOpen className="w-3.5 h-3.5" />
- Load Project
- </Button>
- <Button
- type="button"
- variant="outline"
- onClick={onSaveProject}
- className="h-8 text-[10px] font-medium gap-1.5 bg-white/5 border-white/10 text-slate-300 hover:bg-white/10"
- >
- <Save className="w-3.5 h-3.5" />
- Save Project
- </Button>
- </div>
-
- <Button
- type="button"
- size="lg"
- onClick={onExport}
- className="w-full py-5 text-sm font-semibold flex items-center justify-center gap-2 bg-[#34B27B] text-white rounded-xl shadow-lg shadow-[#34B27B]/20 hover:bg-[#34B27B]/90 hover:scale-[1.02] active:scale-[0.98] transition-all duration-200"
- >
- <Download className="w-4 h-4" />
- Export {exportFormat === 'gif' ? 'GIF' : 'Video'}
- </Button>
-
- <div className="flex gap-2 mt-3">
- <button
- type="button"
- onClick={() => {
- window.electronAPI?.openExternalUrl('https://github.com/siddharthvaddem/openscreen/issues/new/choose');
- }}
- className="flex-1 flex items-center justify-center gap-1.5 text-[10px] text-slate-500 hover:text-slate-300 py-1.5 transition-colors"
- >
- <Bug className="w-3 h-3 text-[#34B27B]" />
- Report Bug
- </button>
- <button
- type="button"
- onClick={() => {
- window.electronAPI?.openExternalUrl('https://github.com/siddharthvaddem/openscreen');
- }}
- className="flex-1 flex items-center justify-center gap-1.5 text-[10px] text-slate-500 hover:text-slate-300 py-1.5 transition-colors"
- >
- <Star className="w-3 h-3 text-yellow-400" />
- Star on GitHub
- </button>
- </div>
- </div>
- </div>
- );
+ const [wallpaperPaths, setWallpaperPaths] = useState<string[]>([]);
+ const [customImages, setCustomImages] = useState<string[]>([]);
+ const fileInputRef = useRef<HTMLInputElement>(null);
+
+ useEffect(() => {
+ let mounted = true;
+ (async () => {
+ try {
+ const resolved = await Promise.all(WALLPAPER_RELATIVE.map((p) => getAssetPath(p)));
+ if (mounted) setWallpaperPaths(resolved);
+ } catch (_err) {
+ if (mounted) setWallpaperPaths(WALLPAPER_RELATIVE.map((p) => `/${p}`));
+ }
+ })();
+ return () => {
+ mounted = false;
+ };
+ }, []);
+ const colorPalette = [
+ "#FF0000",
+ "#FFD700",
+ "#00FF00",
+ "#FFFFFF",
+ "#0000FF",
+ "#FF6B00",
+ "#9B59B6",
+ "#E91E63",
+ "#00BCD4",
+ "#FF5722",
+ "#8BC34A",
+ "#FFC107",
+ "#34B27B",
+ "#000000",
+ "#607D8B",
+ "#795548",
+ ];
+
+ const [selectedColor, setSelectedColor] = useState("#ADADAD");
+ const [gradient, setGradient] = useState<string>(GRADIENTS[0]);
+ const [showCropModal, setShowCropModal] = useState(false);
+ const cropSnapshotRef = useRef<CropRegion | null>(null);
++ const [cropAspectLocked, setCropAspectLocked] = useState(false);
++ const [cropAspectRatio, setCropAspectRatio] = useState("");
++
++ const videoWidth = videoElement?.videoWidth || 1920;
++ const videoHeight = videoElement?.videoHeight || 1080;
++
++ const handleCropNumericChange = useCallback(
++ (field: "x" | "y" | "width" | "height", pixelValue: number) => {
++ if (!cropRegion || !onCropChange) return;
++
++ const next = { ...cropRegion };
++ switch (field) {
++ case "x":
++ next.x = Math.max(0, Math.min(pixelValue / videoWidth, 1 - next.width));
++ break;
++ case "y":
++ next.y = Math.max(0, Math.min(pixelValue / videoHeight, 1 - next.height));
++ break;
++ case "width": {
++ const newWidth = Math.max(0.05, Math.min(pixelValue / videoWidth, 1 - next.x));
++ if (cropAspectLocked && next.width > 0 && next.height > 0) {
++ const ratio = next.width / next.height;
++ const newHeight = newWidth / ratio;
++ if (next.y + newHeight <= 1) {
++ next.width = newWidth;
++ next.height = newHeight;
++ }
++ } else {
++ next.width = newWidth;
++ }
++ break;
++ }
++ case "height": {
++ const newHeight = Math.max(0.05, Math.min(pixelValue / videoHeight, 1 - next.y));
++ if (cropAspectLocked && next.width > 0 && next.height > 0) {
++ const ratio = next.width / next.height;
++ const newWidth = newHeight * ratio;
++ if (next.x + newWidth <= 1) {
++ next.height = newHeight;
++ next.width = newWidth;
++ }
++ } else {
++ next.height = newHeight;
++ }
++ break;
++ }
++ }
++
++ onCropChange(next);
++ },
++ [cropRegion, onCropChange, videoWidth, videoHeight, cropAspectLocked],
++ );
++
++ const applyCropAspectPreset = useCallback(
++ (preset: string) => {
++ if (!cropRegion || !onCropChange) return;
++
++ setCropAspectRatio(preset);
++ if (preset === "") {
++ setCropAspectLocked(false);
++ return;
++ }
++
++ const [wStr, hStr] = preset.split(":");
++ const targetRatio = Number(wStr) / Number(hStr);
++ const next = { ...cropRegion };
++
++ const nextHeight = (next.width * videoWidth) / (targetRatio * videoHeight);
++ if (next.y + nextHeight <= 1 && nextHeight >= 0.05) {
++ next.height = nextHeight;
++ } else {
++ const nextWidth = (next.height * videoHeight * targetRatio) / videoWidth;
++ if (next.x + nextWidth <= 1 && nextWidth >= 0.05) {
++ next.width = nextWidth;
++ }
++ }
++
++ onCropChange(next);
++ setCropAspectLocked(true);
++ },
++ [cropRegion, onCropChange, videoWidth, videoHeight],
++ );
++
++ const getCropPixelValue = useCallback(
++ (field: "x" | "y" | "width" | "height"): number => {
++ if (!cropRegion) return 0;
++ switch (field) {
++ case "x":
++ return Math.round(cropRegion.x * videoWidth);
++ case "y":
++ return Math.round(cropRegion.y * videoHeight);
++ case "width":
++ return Math.round(cropRegion.width * videoWidth);
++ case "height":
++ return Math.round(cropRegion.height * videoHeight);
++ }
++ },
++ [cropRegion, videoWidth, videoHeight],
++ );
+
+ const zoomEnabled = Boolean(selectedZoomDepth);
+ const trimEnabled = Boolean(selectedTrimId);
+
+ const handleDeleteClick = () => {
+ if (selectedZoomId && onZoomDelete) {
+ onZoomDelete(selectedZoomId);
+ }
+ };
+
+ const handleTrimDeleteClick = () => {
+ if (selectedTrimId && onTrimDelete) {
+ onTrimDelete(selectedTrimId);
+ }
+ };
+
+ const handleImageUpload = (event: React.ChangeEvent<HTMLInputElement>) => {
+ const files = event.target.files;
+ if (!files || files.length === 0) return;
+
+ const file = files[0];
+
+ // Validate file type - only allow JPG/JPEG
+ const validTypes = ["image/jpeg", "image/jpg"];
+ if (!validTypes.includes(file.type)) {
+ toast.error("Invalid file type", {
+ description: "Please upload a JPG or JPEG image file.",
+ });
+ event.target.value = "";
+ return;
+ }
+
+ const reader = new FileReader();
+
+ reader.onload = (e) => {
+ const dataUrl = e.target?.result as string;
+ if (dataUrl) {
+ setCustomImages((prev) => [...prev, dataUrl]);
+ onWallpaperChange(dataUrl);
+ toast.success("Custom image uploaded successfully!");
+ }
+ };
+
+ reader.onerror = () => {
+ toast.error("Failed to upload image", {
+ description: "There was an error reading the file.",
+ });
+ };
+
+ reader.readAsDataURL(file);
+ // Reset input so the same file can be selected again
+ event.target.value = "";
+ };
+
+ const handleRemoveCustomImage = (imageUrl: string, event: React.MouseEvent) => {
+ event.stopPropagation();
+ setCustomImages((prev) => prev.filter((img) => img !== imageUrl));
+ // If the removed image was selected, clear selection
+ if (selected === imageUrl) {
+ onWallpaperChange(wallpaperPaths[0] || WALLPAPER_RELATIVE[0]);
+ }
+ };
+
+ const handleCropToggle = () => {
+ if (!showCropModal && cropRegion) {
+ cropSnapshotRef.current = { ...cropRegion };
+ }
+ setShowCropModal(!showCropModal);
+ };
+
+ const handleCropCancel = () => {
+ if (cropSnapshotRef.current && onCropChange) {
+ onCropChange(cropSnapshotRef.current);
+ }
+ setShowCropModal(false);
+ };
+
+ // Find selected annotation
+ const selectedAnnotation = selectedAnnotationId
+ ? annotationRegions.find((a) => a.id === selectedAnnotationId)
+ : null;
+
+ // If an annotation is selected, show annotation settings instead
+ if (
+ selectedAnnotation &&
+ onAnnotationContentChange &&
+ onAnnotationTypeChange &&
+ onAnnotationStyleChange &&
+ onAnnotationDelete
+ ) {
+ return (
+ <AnnotationSettingsPanel
+ annotation={selectedAnnotation}
+ onContentChange={(content) => onAnnotationContentChange(selectedAnnotation.id, content)}
+ onTypeChange={(type) => onAnnotationTypeChange(selectedAnnotation.id, type)}
+ onStyleChange={(style) => onAnnotationStyleChange(selectedAnnotation.id, style)}
+ onFigureDataChange={
+ onAnnotationFigureDataChange
+ ? (figureData) => onAnnotationFigureDataChange(selectedAnnotation.id, figureData)
+ : undefined
+ }
+ onDelete={() => onAnnotationDelete(selectedAnnotation.id)}
+ />
+ );
+ }
+
+ return (
+ <div className="flex-[2] min-w-0 bg-[#09090b] border border-white/5 rounded-2xl flex flex-col shadow-xl h-full overflow-hidden">
+ <div className="flex-1 overflow-y-auto custom-scrollbar p-4 pb-0">
+ <div className="mb-4">
+ <div className="flex items-center justify-between mb-3">
+ <span className="text-sm font-medium text-slate-200">Zoom Level</span>
+ <div className="flex items-center gap-2">
+ {zoomEnabled && selectedZoomDepth && (
+ <span className="text-[10px] uppercase tracking-wider font-medium text-[#34B27B] bg-[#34B27B]/10 px-2 py-0.5 rounded-full">
+ {ZOOM_DEPTH_OPTIONS.find((o) => o.depth === selectedZoomDepth)?.label}
+ </span>
+ )}
+ <KeyboardShortcutsHelp />
+ </div>
+ </div>
+ <div className="grid grid-cols-6 gap-1.5">
+ {ZOOM_DEPTH_OPTIONS.map((option) => {
+ const isActive = selectedZoomDepth === option.depth;
+ return (
+ <Button
+ key={option.depth}
+ type="button"
+ disabled={!zoomEnabled}
+ onClick={() => onZoomDepthChange?.(option.depth)}
+ className={cn(
+ "h-auto w-full rounded-lg border px-1 py-2 text-center shadow-sm transition-all",
+ "duration-200 ease-out",
+ zoomEnabled ? "opacity-100 cursor-pointer" : "opacity-40 cursor-not-allowed",
+ isActive
+ ? "border-[#34B27B] bg-[#34B27B] text-white shadow-[#34B27B]/20"
+ : "border-white/5 bg-white/5 text-slate-400 hover:bg-white/10 hover:border-white/10 hover:text-slate-200",
+ )}
+ >
+ <span className="text-xs font-semibold">{option.label}</span>
+ </Button>
+ );
+ })}
+ </div>
+ {!zoomEnabled && (
+ <p className="text-[10px] text-slate-500 mt-2 text-center">
+ Select a zoom region to adjust
+ </p>
+ )}
+ {zoomEnabled && (
+ <Button
+ onClick={handleDeleteClick}
+ variant="destructive"
+ size="sm"
+ className="mt-2 w-full gap-2 bg-red-500/10 text-red-400 border border-red-500/20 hover:bg-red-500/20 hover:border-red-500/30 transition-all h-8 text-xs"
+ >
+ <Trash2 className="w-3 h-3" />
+ Delete Zoom
+ </Button>
+ )}
+ </div>
+
+ {trimEnabled && (
+ <div className="mb-4">
+ <Button
+ onClick={handleTrimDeleteClick}
+ variant="destructive"
+ size="sm"
+ className="w-full gap-2 bg-red-500/10 text-red-400 border border-red-500/20 hover:bg-red-500/20 hover:border-red-500/30 transition-all h-8 text-xs"
+ >
+ <Trash2 className="w-3 h-3" />
+ Delete Trim Region
+ </Button>
+ </div>
+ )}
+
+ <div className="mb-4">
+ <div className="flex items-center justify-between mb-3">
+ <span className="text-sm font-medium text-slate-200">Playback Speed</span>
+ {selectedSpeedId && selectedSpeedValue && (
+ <span className="text-[10px] uppercase tracking-wider font-medium text-[#d97706] bg-[#d97706]/10 px-2 py-0.5 rounded-full">
+ {SPEED_OPTIONS.find((o) => o.speed === selectedSpeedValue)?.label ??
+ `${selectedSpeedValue}×`}
+ </span>
+ )}
+ </div>
+ <div className="grid grid-cols-7 gap-1.5">
+ {SPEED_OPTIONS.map((option) => {
+ const isActive = selectedSpeedValue === option.speed;
+ return (
+ <Button
+ key={option.speed}
+ type="button"
+ disabled={!selectedSpeedId}
+ onClick={() => onSpeedChange?.(option.speed)}
+ className={cn(
+ "h-auto w-full rounded-lg border px-1 py-2 text-center shadow-sm transition-all",
+ "duration-200 ease-out",
+ selectedSpeedId
+ ? "opacity-100 cursor-pointer"
+ : "opacity-40 cursor-not-allowed",
+ isActive
+ ? "border-[#d97706] bg-[#d97706] text-white shadow-[#d97706]/20"
+ : "border-white/5 bg-white/5 text-slate-400 hover:bg-white/10 hover:border-white/10 hover:text-slate-200",
+ )}
+ >
+ <span className="text-xs font-semibold">{option.label}</span>
+ </Button>
+ );
+ })}
+ </div>
+ {!selectedSpeedId && (
+ <p className="text-[10px] text-slate-500 mt-2 text-center">
+ Select a speed region to adjust
+ </p>
+ )}
+ {selectedSpeedId && (
+ <Button
+ onClick={() => selectedSpeedId && onSpeedDelete?.(selectedSpeedId)}
+ variant="destructive"
+ size="sm"
+ className="mt-2 w-full gap-2 bg-red-500/10 text-red-400 border border-red-500/20 hover:bg-red-500/20 hover:border-red-500/30 transition-all h-8 text-xs"
+ >
+ <Trash2 className="w-3 h-3" />
+ Delete Speed Region
+ </Button>
+ )}
+ </div>
+
+ <Accordion type="multiple" defaultValue={["effects", "background"]} className="space-y-1">
+ <AccordionItem value="effects" className="border-white/5 rounded-xl bg-white/[0.02] px-3">
+ <AccordionTrigger className="py-2.5 hover:no-underline">
+ <div className="flex items-center gap-2">
+ <Sparkles className="w-4 h-4 text-[#34B27B]" />
+ <span className="text-xs font-medium">Video Effects</span>
+ </div>
+ </AccordionTrigger>
+ <AccordionContent className="pb-3">
+ <div className="grid grid-cols-2 gap-2 mb-3">
+ <div className="flex items-center justify-between p-2 rounded-lg bg-white/5 border border-white/5">
+ <div className="text-[10px] font-medium text-slate-300">Motion Blur</div>
+ <Switch
+ checked={motionBlurEnabled}
+ onCheckedChange={onMotionBlurChange}
+ className="data-[state=checked]:bg-[#34B27B] scale-90"
+ />
+ </div>
+ <div className="flex items-center justify-between p-2 rounded-lg bg-white/5 border border-white/5">
+ <div className="text-[10px] font-medium text-slate-300">Blur BG</div>
+ <Switch
+ checked={showBlur}
+ onCheckedChange={onBlurChange}
+ className="data-[state=checked]:bg-[#34B27B] scale-90"
+ />
+ </div>
+ </div>
+
+ <div className="grid grid-cols-2 gap-2">
+ <div className="p-2 rounded-lg bg-white/5 border border-white/5">
+ <div className="flex items-center justify-between mb-1">
+ <div className="text-[10px] font-medium text-slate-300">Shadow</div>
+ <span className="text-[10px] text-slate-500 font-mono">
+ {Math.round(shadowIntensity * 100)}%
+ </span>
+ </div>
+ <Slider
+ value={[shadowIntensity]}
+ onValueChange={(values) => onShadowChange?.(values[0])}
+ onValueCommit={() => onShadowCommit?.()}
+ min={0}
+ max={1}
+ step={0.01}
+ className="w-full [&_[role=slider]]:bg-[#34B27B] [&_[role=slider]]:border-[#34B27B] [&_[role=slider]]:h-3 [&_[role=slider]]:w-3"
+ />
+ </div>
+ <div className="p-2 rounded-lg bg-white/5 border border-white/5">
+ <div className="flex items-center justify-between mb-1">
+ <div className="text-[10px] font-medium text-slate-300">Roundness</div>
+ <span className="text-[10px] text-slate-500 font-mono">{borderRadius}px</span>
+ </div>
+ <Slider
+ value={[borderRadius]}
+ onValueChange={(values) => onBorderRadiusChange?.(values[0])}
+ onValueCommit={() => onBorderRadiusCommit?.()}
+ min={0}
+ max={16}
+ step={0.5}
+ className="w-full [&_[role=slider]]:bg-[#34B27B] [&_[role=slider]]:border-[#34B27B] [&_[role=slider]]:h-3 [&_[role=slider]]:w-3"
+ />
+ </div>
+ <div className="p-2 rounded-lg bg-white/5 border border-white/5">
+ <div className="flex items-center justify-between mb-1">
+ <div className="text-[10px] font-medium text-slate-300">Padding</div>
+ <span className="text-[10px] text-slate-500 font-mono">{padding}%</span>
+ </div>
+ <Slider
+ value={[padding]}
+ onValueChange={(values) => onPaddingChange?.(values[0])}
+ onValueCommit={() => onPaddingCommit?.()}
+ min={0}
+ max={100}
+ step={1}
+ className="w-full [&_[role=slider]]:bg-[#34B27B] [&_[role=slider]]:border-[#34B27B] [&_[role=slider]]:h-3 [&_[role=slider]]:w-3"
+ />
+ </div>
+ </div>
+
+ <Button
+ onClick={handleCropToggle}
+ variant="outline"
+ className="w-full mt-2 gap-1.5 bg-white/5 text-slate-200 border-white/10 hover:bg-white/10 hover:border-white/20 hover:text-white text-[10px] h-8 transition-all"
+ >
+ <Crop className="w-3 h-3" />
+ Crop Video
+ </Button>
+ </AccordionContent>
+ </AccordionItem>
+
+ <AccordionItem
+ value="background"
+ className="border-white/5 rounded-xl bg-white/[0.02] px-3"
+ >
+ <AccordionTrigger className="py-2.5 hover:no-underline">
+ <div className="flex items-center gap-2">
+ <Palette className="w-4 h-4 text-[#34B27B]" />
+ <span className="text-xs font-medium">Background</span>
+ </div>
+ </AccordionTrigger>
+ <AccordionContent className="pb-3">
+ <Tabs defaultValue="image" className="w-full">
+ <TabsList className="mb-2 bg-white/5 border border-white/5 p-0.5 w-full grid grid-cols-3 h-7 rounded-lg">
+ <TabsTrigger
+ value="image"
+ className="data-[state=active]:bg-[#34B27B] data-[state=active]:text-white text-slate-400 text-[10px] py-1 rounded-md transition-all"
+ >
+ Image
+ </TabsTrigger>
+ <TabsTrigger
+ value="color"
+ className="data-[state=active]:bg-[#34B27B] data-[state=active]:text-white text-slate-400 text-[10px] py-1 rounded-md transition-all"
+ >
+ Color
+ </TabsTrigger>
+ <TabsTrigger
+ value="gradient"
+ className="data-[state=active]:bg-[#34B27B] data-[state=active]:text-white text-slate-400 text-[10px] py-1 rounded-md transition-all"
+ >
+ Gradient
+ </TabsTrigger>
+ </TabsList>
+
+ <div className="max-h-[min(200px,25vh)] overflow-y-auto custom-scrollbar">
+ <TabsContent value="image" className="mt-0 space-y-2">
+ <input
+ type="file"
+ ref={fileInputRef}
+ onChange={handleImageUpload}
+ accept=".jpg,.jpeg,image/jpeg"
+ className="hidden"
+ />
+ <Button
+ onClick={() => fileInputRef.current?.click()}
+ variant="outline"
+ className="w-full gap-2 bg-white/5 text-slate-200 border-white/10 hover:bg-[#34B27B] hover:text-white hover:border-[#34B27B] transition-all h-7 text-[10px]"
+ >
+ <Upload className="w-3 h-3" />
+ Upload Custom
+ </Button>
+
+ <div className="grid grid-cols-7 gap-1.5">
+ {customImages.map((imageUrl, idx) => {
+ const isSelected = selected === imageUrl;
+ return (
+ <div
+ key={`custom-${idx}`}
+ className={cn(
+ "aspect-square w-9 h-9 rounded-md border-2 overflow-hidden cursor-pointer transition-all duration-200 relative group shadow-sm",
+ isSelected
+ ? "border-[#34B27B] ring-1 ring-[#34B27B]/30"
+ : "border-white/10 hover:border-[#34B27B]/40 opacity-80 hover:opacity-100 bg-white/5",
+ )}
+ style={{
+ backgroundImage: `url(${imageUrl})`,
+ backgroundSize: "cover",
+ backgroundPosition: "center",
+ }}
+ onClick={() => onWallpaperChange(imageUrl)}
+ role="button"
+ >
+ <button
+ onClick={(e) => handleRemoveCustomImage(imageUrl, e)}
+ className="absolute top-0.5 right-0.5 w-3 h-3 bg-red-500/90 hover:bg-red-500 rounded-full flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity z-10"
+ >
+ <X className="w-2 h-2 text-white" />
+ </button>
+ </div>
+ );
+ })}
+
+ {(wallpaperPaths.length > 0
+ ? wallpaperPaths
+ : WALLPAPER_RELATIVE.map((p) => `/${p}`)
+ ).map((path) => {
+ const isSelected = (() => {
+ if (!selected) return false;
+ if (selected === path) return true;
+ try {
+ const clean = (s: string) =>
+ s.replace(/^file:\/\//, "").replace(/^\//, "");
+ if (clean(selected).endsWith(clean(path))) return true;
+ if (clean(path).endsWith(clean(selected))) return true;
+ } catch {
+ // Best-effort comparison; fallback to strict match.
+ }
+ return false;
+ })();
+ return (
+ <div
+ key={path}
+ className={cn(
+ "aspect-square w-9 h-9 rounded-md border-2 overflow-hidden cursor-pointer transition-all duration-200 shadow-sm",
+ isSelected
+ ? "border-[#34B27B] ring-1 ring-[#34B27B]/30"
+ : "border-white/10 hover:border-[#34B27B]/40 opacity-80 hover:opacity-100 bg-white/5",
+ )}
+ style={{
+ backgroundImage: `url(${path})`,
+ backgroundSize: "cover",
+ backgroundPosition: "center",
+ }}
+ onClick={() => onWallpaperChange(path)}
+ role="button"
+ />
+ );
+ })}
+ </div>
+ </TabsContent>
+
+ <TabsContent value="color" className="mt-0">
+ <div className="p-1">
+ <Block
+ color={selectedColor}
+ colors={colorPalette}
+ onChange={(color) => {
+ setSelectedColor(color.hex);
+ onWallpaperChange(color.hex);
+ }}
+ style={{
+ width: "100%",
+ borderRadius: "8px",
+ }}
+ />
+ </div>
+ </TabsContent>
+
+ <TabsContent value="gradient" className="mt-0">
+ <div className="grid grid-cols-7 gap-1.5">
+ {GRADIENTS.map((g, idx) => (
+ <div
+ key={g}
+ className={cn(
+ "aspect-square w-9 h-9 rounded-md border-2 overflow-hidden cursor-pointer transition-all duration-200 shadow-sm",
+ gradient === g
+ ? "border-[#34B27B] ring-1 ring-[#34B27B]/30"
+ : "border-white/10 hover:border-[#34B27B]/40 opacity-80 hover:opacity-100 bg-white/5",
+ )}
+ style={{ background: g }}
+ aria-label={`Gradient ${idx + 1}`}
+ onClick={() => {
+ setGradient(g);
+ onWallpaperChange(g);
+ }}
+ role="button"
+ />
+ ))}
+ </div>
+ </TabsContent>
+ </div>
+ </Tabs>
+ </AccordionContent>
+ </AccordionItem>
+ </Accordion>
+ </div>
+
+ {showCropModal && cropRegion && onCropChange && (
+ <>
+ <div
+ className="fixed inset-0 bg-black/80 backdrop-blur-sm z-50 animate-in fade-in duration-200"
+ onClick={handleCropCancel}
+ />
+ <div className="fixed top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 z-[60] bg-[#09090b] rounded-2xl shadow-2xl border border-white/10 p-8 w-[90vw] max-w-5xl max-h-[90vh] overflow-auto animate-in zoom-in-95 duration-200">
+ <div className="flex items-center justify-between mb-6">
+ <div>
+ <span className="text-xl font-bold text-slate-200">Crop Video</span>
+ <p className="text-sm text-slate-400 mt-2">
+ Drag on each side to adjust the crop area
+ </p>
+ </div>
+ <Button
+ variant="ghost"
+ size="icon"
+ onClick={handleCropCancel}
+ className="hover:bg-white/10 text-slate-400 hover:text-white"
+ >
+ <X className="w-5 h-5" />
+ </Button>
+ </div>
+ <CropControl
+ videoElement={videoElement || null}
+ cropRegion={cropRegion}
+ onCropChange={onCropChange}
+ aspectRatio={aspectRatio}
+ />
- <div className="mt-6 flex justify-end">
- <Button
- onClick={() => setShowCropModal(false)}
- size="lg"
- className="bg-[#34B27B] hover:bg-[#34B27B]/90 text-white"
- >
- Done
- </Button>
++ <div className="mt-6 space-y-4">
++ <div className="flex flex-wrap items-end gap-3">
++ {[
++ { label: "X", field: "x" as const, max: videoWidth },
++ { label: "Y", field: "y" as const, max: videoHeight },
++ { label: "W", field: "width" as const, max: videoWidth },
++ { label: "H", field: "height" as const, max: videoHeight },
++ ].map(({ label, field, max }) => (
++ <div key={field} className="flex flex-col gap-1">
++ <label className="text-[10px] font-medium text-slate-400 uppercase tracking-wider">
++ {label}
++ </label>
++ <input
++ type="number"
++ min={0}
++ max={max}
++ value={getCropPixelValue(field)}
++ onChange={(e) => handleCropNumericChange(field, Number(e.target.value))}
++ className="w-[90px] h-8 rounded-md border border-white/10 bg-white/5 px-2 text-xs text-slate-200 outline-none focus:border-[#34B27B]/50 focus:ring-1 focus:ring-[#34B27B]/30 [appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none"
++ />
++ </div>
++ ))}
++
++ <div className="flex flex-col gap-1">
++ <label className="text-[10px] font-medium text-slate-400 uppercase tracking-wider">
++ Ratio
++ </label>
++ <div className="flex items-center gap-1.5">
++ <select
++ value={cropAspectRatio}
++ onChange={(e) => applyCropAspectPreset(e.target.value)}
++ className="h-8 rounded-md border border-white/10 bg-[#1a1a1f] px-2 text-xs text-slate-200 outline-none focus:border-[#34B27B]/50 cursor-pointer"
++ >
++ <option value="" className="bg-[#1a1a1f] text-slate-200">
++ Free
++ </option>
++ <option value="16:9" className="bg-[#1a1a1f] text-slate-200">
++ 16:9
++ </option>
++ <option value="9:16" className="bg-[#1a1a1f] text-slate-200">
++ 9:16
++ </option>
++ <option value="4:3" className="bg-[#1a1a1f] text-slate-200">
++ 4:3
++ </option>
++ <option value="3:4" className="bg-[#1a1a1f] text-slate-200">
++ 3:4
++ </option>
++ <option value="1:1" className="bg-[#1a1a1f] text-slate-200">
++ 1:1
++ </option>
++ <option value="21:9" className="bg-[#1a1a1f] text-slate-200">
++ 21:9
++ </option>
++ </select>
++ <button
++ type="button"
++ onClick={() => setCropAspectLocked((prev) => !prev)}
++ className={cn(
++ "h-8 w-8 flex items-center justify-center rounded-md border transition-all",
++ cropAspectLocked
++ ? "border-[#34B27B]/50 bg-[#34B27B]/10 text-[#34B27B]"
++ : "border-white/10 bg-white/5 text-slate-400 hover:text-slate-200",
++ )}
++ title={cropAspectLocked ? "Unlock aspect ratio" : "Lock aspect ratio"}
++ >
++ {cropAspectLocked ? (
++ <Lock className="w-3.5 h-3.5" />
++ ) : (
++ <Unlock className="w-3.5 h-3.5" />
++ )}
++ </button>
++ </div>
++ </div>
++
++ <p className="text-[10px] text-slate-500 self-center ml-2">
++ {videoWidth} × {videoHeight}px
++ </p>
++ </div>
++
++ <div className="flex justify-end">
++ <Button
++ onClick={() => setShowCropModal(false)}
++ size="lg"
++ className="bg-[#34B27B] hover:bg-[#34B27B]/90 text-white"
++ >
++ Done
++ </Button>
++ </div>
+ </div>
+ </div>
+ </>
+ )}
+
+ <div className="flex-shrink-0 p-4 pt-3 border-t border-white/5 bg-[#09090b]">
+ <div className="flex items-center gap-2 mb-3">
+ <button
+ onClick={() => onExportFormatChange?.("mp4")}
+ className={cn(
+ "flex-1 flex items-center justify-center gap-1.5 py-2 rounded-lg border transition-all text-xs font-medium",
+ exportFormat === "mp4"
+ ? "bg-[#34B27B]/10 border-[#34B27B]/50 text-white"
+ : "bg-white/5 border-white/10 text-slate-400 hover:bg-white/10 hover:text-slate-200",
+ )}
+ >
+ <Film className="w-3.5 h-3.5" />
+ MP4
+ </button>
+ <button
+ onClick={() => onExportFormatChange?.("gif")}
+ className={cn(
+ "flex-1 flex items-center justify-center gap-1.5 py-2 rounded-lg border transition-all text-xs font-medium",
+ exportFormat === "gif"
+ ? "bg-[#34B27B]/10 border-[#34B27B]/50 text-white"
+ : "bg-white/5 border-white/10 text-slate-400 hover:bg-white/10 hover:text-slate-200",
+ )}
+ >
+ <Image className="w-3.5 h-3.5" />
+ GIF
+ </button>
+ </div>
+
+ {exportFormat === "mp4" && (
+ <div className="mb-3 bg-white/5 border border-white/5 p-0.5 w-full grid grid-cols-3 h-7 rounded-lg">
+ <button
+ onClick={() => onExportQualityChange?.("medium")}
+ className={cn(
+ "rounded-md transition-all text-[10px] font-medium",
+ exportQuality === "medium"
+ ? "bg-white text-black"
+ : "text-slate-400 hover:text-slate-200",
+ )}
+ >
+ Low
+ </button>
+ <button
+ onClick={() => onExportQualityChange?.("good")}
+ className={cn(
+ "rounded-md transition-all text-[10px] font-medium",
+ exportQuality === "good"
+ ? "bg-white text-black"
+ : "text-slate-400 hover:text-slate-200",
+ )}
+ >
+ Medium
+ </button>
+ <button
+ onClick={() => onExportQualityChange?.("source")}
+ className={cn(
+ "rounded-md transition-all text-[10px] font-medium",
+ exportQuality === "source"
+ ? "bg-white text-black"
+ : "text-slate-400 hover:text-slate-200",
+ )}
+ >
+ High
+ </button>
+ </div>
+ )}
+
+ {exportFormat === "gif" && (
+ <div className="mb-3 space-y-2">
+ <div className="flex items-center gap-2">
+ <div className="flex-1 bg-white/5 border border-white/5 p-0.5 grid grid-cols-4 h-7 rounded-lg">
+ {GIF_FRAME_RATES.map((rate) => (
+ <button
+ key={rate.value}
+ onClick={() => onGifFrameRateChange?.(rate.value)}
+ className={cn(
+ "rounded-md transition-all text-[10px] font-medium",
+ gifFrameRate === rate.value
+ ? "bg-white text-black"
+ : "text-slate-400 hover:text-slate-200",
+ )}
+ >
+ {rate.value}
+ </button>
+ ))}
+ </div>
+ <div className="flex-1 bg-white/5 border border-white/5 p-0.5 grid grid-cols-3 h-7 rounded-lg">
+ {Object.entries(GIF_SIZE_PRESETS).map(([key, _preset]) => (
+ <button
+ key={key}
+ onClick={() => onGifSizePresetChange?.(key as GifSizePreset)}
+ className={cn(
+ "rounded-md transition-all text-[10px] font-medium",
+ gifSizePreset === key
+ ? "bg-white text-black"
+ : "text-slate-400 hover:text-slate-200",
+ )}
+ >
+ {key === "original" ? "Orig" : key.charAt(0).toUpperCase() + key.slice(1, 3)}
+ </button>
+ ))}
+ </div>
+ </div>
+ <div className="flex items-center justify-between">
+ <span className="text-[10px] text-slate-500">
+ {gifOutputDimensions.width} × {gifOutputDimensions.height}px
+ </span>
+ <div className="flex items-center gap-2">
+ <span className="text-[10px] text-slate-400">Loop</span>
+ <Switch
+ checked={gifLoop}
+ onCheckedChange={onGifLoopChange}
+ className="data-[state=checked]:bg-[#34B27B] scale-75"
+ />
+ </div>
+ </div>
+ </div>
+ )}
+
+ <div className="grid grid-cols-2 gap-2 mb-2">
+ <Button
+ type="button"
+ variant="outline"
+ onClick={onLoadProject}
+ className="h-8 text-[10px] font-medium gap-1.5 bg-white/5 border-white/10 text-slate-300 hover:bg-white/10"
+ >
+ <FolderOpen className="w-3.5 h-3.5" />
+ Load Project
+ </Button>
+ <Button
+ type="button"
+ variant="outline"
+ onClick={onSaveProject}
+ className="h-8 text-[10px] font-medium gap-1.5 bg-white/5 border-white/10 text-slate-300 hover:bg-white/10"
+ >
+ <Save className="w-3.5 h-3.5" />
+ Save Project
+ </Button>
+ </div>
+
+ <Button
+ type="button"
+ size="lg"
+ onClick={onExport}
+ className="w-full py-5 text-sm font-semibold flex items-center justify-center gap-2 bg-[#34B27B] text-white rounded-xl shadow-lg shadow-[#34B27B]/20 hover:bg-[#34B27B]/90 hover:scale-[1.02] active:scale-[0.98] transition-all duration-200"
+ >
+ <Download className="w-4 h-4" />
+ Export {exportFormat === "gif" ? "GIF" : "Video"}
+ </Button>
+
+ <div className="flex gap-2 mt-3">
+ <button
+ type="button"
+ onClick={() => {
+ window.electronAPI?.openExternalUrl(
+ "https://github.com/siddharthvaddem/openscreen/issues/new/choose",
+ );
+ }}
+ className="flex-1 flex items-center justify-center gap-1.5 text-[10px] text-slate-500 hover:text-slate-300 py-1.5 transition-colors"
+ >
+ <Bug className="w-3 h-3 text-[#34B27B]" />
+ Report Bug
+ </button>
+ <button
+ type="button"
+ onClick={() => {
+ window.electronAPI?.openExternalUrl("https://github.com/siddharthvaddem/openscreen");
+ }}
+ className="flex-1 flex items-center justify-center gap-1.5 text-[10px] text-slate-500 hover:text-slate-300 py-1.5 transition-colors"
+ >
+ <Star className="w-3 h-3 text-yellow-400" />
+ Star on GitHub
+ </button>
+ </div>
+ </div>
+ </div>
+ );
}