diff --git a/apps/web/src/components/editor/preview-panel.tsx b/apps/web/src/components/editor/preview-panel.tsx index b68e5aa..e19b4de 100644 --- a/apps/web/src/components/editor/preview-panel.tsx +++ b/apps/web/src/components/editor/preview-panel.tsx @@ -9,7 +9,7 @@ import { useMediaStore, type MediaItem } from "@/stores/media-store"; import { usePlaybackStore } from "@/stores/playback-store"; import { VideoPlayer } from "@/components/ui/video-player"; import { Button } from "@/components/ui/button"; -import { Play, Pause, Volume2, VolumeX } from "lucide-react"; +import { Play, Pause, Volume2, VolumeX, Plus } from "lucide-react"; import { useState, useRef, useEffect } from "react"; interface ActiveClip { @@ -21,8 +21,7 @@ interface ActiveClip { export function PreviewPanel() { const { tracks } = useTimelineStore(); const { mediaItems } = useMediaStore(); - const { isPlaying, toggle, currentTime, muted, toggleMute, volume } = - usePlaybackStore(); + const { currentTime, muted, toggleMute, volume } = usePlaybackStore(); const [canvasSize, setCanvasSize] = useState({ width: 1920, height: 1080 }); const previewRef = useRef(null); const containerRef = useRef(null); @@ -37,18 +36,44 @@ export function PreviewPanel() { if (!containerRef.current) return; const container = containerRef.current.getBoundingClientRect(); + const computedStyle = getComputedStyle(containerRef.current); + + // Get padding values + const paddingTop = parseFloat(computedStyle.paddingTop); + const paddingBottom = parseFloat(computedStyle.paddingBottom); + const paddingLeft = parseFloat(computedStyle.paddingLeft); + const paddingRight = parseFloat(computedStyle.paddingRight); + + // Get gap value (gap-4 = 1rem = 16px) + const gap = parseFloat(computedStyle.gap) || 16; + + // Get toolbar height if it exists + const toolbar = containerRef.current.querySelector("[data-toolbar]"); + const toolbarHeight = toolbar + ? toolbar.getBoundingClientRect().height + : 0; + + // Calculate available space after accounting for padding, gap, and toolbar + const availableWidth = container.width - paddingLeft - paddingRight; + const availableHeight = + container.height - + paddingTop - + paddingBottom - + toolbarHeight - + (toolbarHeight > 0 ? gap : 0); + const targetRatio = canvasSize.width / canvasSize.height; - const containerRatio = container.width / container.height; + const containerRatio = availableWidth / availableHeight; let width, height; if (containerRatio > targetRatio) { // Container is wider - constrain by height - height = container.height; + height = availableHeight; width = height * targetRatio; } else { // Container is taller - constrain by width - width = container.width; + width = availableWidth; height = width / targetRatio; } @@ -206,21 +231,12 @@ export function PreviewPanel() { )} {muted || volume === 0 ? "Unmute" : "Mute"} - - {/* Preview Area */}
renderClip(clipData, index)) )}
+ +
); } + +function PreviewToolbar() { + const { isPlaying, toggle } = usePlaybackStore(); + + return ( +
+ +
+ ); +}