OpenReel Video - Professional browser-based video editor. Open source CapCut alternative. 100% browser-based, no installation, no cloud uploads, no watermarks.
TypeScript
feat: enable click-to-select SVG/graphics from the preview player
copilot-swe-agent[bot]f462fa082050
diff --git a/apps/web/src/components/editor/Preview.tsx b/apps/web/src/components/editor/Preview.tsxindex 5a6de8d1..621bcd6f 100644--- a/apps/web/src/components/editor/Preview.tsx+++ b/apps/web/src/components/editor/Preview.tsx@@ -378,6 +378,7 @@ export const Preview: React.FC = () => {const exportState = useUIStore((state) => state.exportState);const motionPathMode = useUIStore((state) => state.motionPathMode);const motionPathClipId = useUIStore((state) => state.motionPathClipId);+ const select = useUIStore((state) => state.select);const {playheadPosition,@@ -3829,6 +3830,12 @@ export const Preview: React.FC = () => {const activeShapeClip = selectedShapeClip;+ const [hoveredGraphicClipId, setHoveredGraphicClipId] = useState<string | null>(null);++ const activeGraphicClips = useMemo(() => {+ return getActiveShapeClips(allShapeClips, playheadPosition);+ }, [allShapeClips, playheadPosition]);+const shapeClipBounds = useMemo(() => {if (!selectedShapeClip || !canvasRef.current || !overlayRef.current)return null;@@ -3888,6 +3895,65 @@ export const Preview: React.FC = () => {};}, [selectedShapeClip, settings.width, settings.height, canvasSize]);+ const getGraphicClipDisplayBounds = useCallback(+ (clip: ShapeClip | SVGClip | StickerClip) => {+ if (!canvasRef.current || !overlayRef.current) return null;++ const canvas = canvasRef.current;+ const overlay = overlayRef.current;+ const overlayRect = overlay.getBoundingClientRect();+ const canvasRect = canvas.getBoundingClientRect();++ const { transform } = clip;+ const shapeSize = 200;++ const canvasWidth = settings.width;+ const canvasHeight = settings.height;++ const canvasAspect = canvasWidth / canvasHeight;+ const elementAspect = canvasRect.width / canvasRect.height;++ let actualWidth: number;+ let actualHeight: number;+ let letterboxOffsetX = 0;+ let letterboxOffsetY = 0;++ if (elementAspect > canvasAspect) {+ actualHeight = canvasRect.height;+ actualWidth = actualHeight * canvasAspect;+ letterboxOffsetX = (canvasRect.width - actualWidth) / 2;+ } else {+ actualWidth = canvasRect.width;+ actualHeight = actualWidth / canvasAspect;+ letterboxOffsetY = (canvasRect.height - actualHeight) / 2;+ }++ const displayScale = actualWidth / canvasWidth;++ const shapeWidth = shapeSize * transform.scale.x * displayScale;+ const shapeHeight = shapeSize * transform.scale.y * displayScale;++ const posX = transform.position.x * canvasWidth * displayScale;+ const posY = transform.position.y * canvasHeight * displayScale;++ const canvasOffsetX = canvasRect.left - overlayRect.left + letterboxOffsetX;+ const canvasOffsetY = canvasRect.top - overlayRect.top + letterboxOffsetY;++ const centerX = canvasOffsetX + posX;+ const centerY = canvasOffsetY + posY;++ return {+ x: centerX - shapeWidth / 2,+ y: centerY - shapeHeight / 2,+ width: shapeWidth,+ height: shapeHeight,+ centerX,+ centerY,+ };+ },+ [settings.width, settings.height],+ );+const selectedSubtitleId = useMemo(() => {const subtitleSelection = selectedItems.find((item) => item.type === "subtitle",@@ -4153,6 +4219,68 @@ export const Preview: React.FC = () => {[activeShapeClip],);+ const handleGraphicsMouseMove = useCallback(+ (e: React.MouseEvent) => {+ if (interactionMode !== "none") {+ setHoveredGraphicClipId(null);+ return;+ }++ if (!overlayRef.current) return;+ const overlayRect = overlayRef.current.getBoundingClientRect();+ const mouseX = e.clientX - overlayRect.left;+ const mouseY = e.clientY - overlayRect.top;++ for (let i = activeGraphicClips.length - 1; i >= 0; i--) {+ const clip = activeGraphicClips[i];+ const bounds = getGraphicClipDisplayBounds(clip);+ if (!bounds) continue;++ if (+ mouseX >= bounds.x &&+ mouseX <= bounds.x + bounds.width &&+ mouseY >= bounds.y &&+ mouseY <= bounds.y + bounds.height+ ) {+ setHoveredGraphicClipId(clip.id);+ return;+ }+ }++ setHoveredGraphicClipId(null);+ },+ [interactionMode, activeGraphicClips, getGraphicClipDisplayBounds],+ );++ const handleGraphicsClick = useCallback(+ (e: React.MouseEvent) => {+ if (interactionMode !== "none") return;++ if (!overlayRef.current) return;+ const overlayRect = overlayRef.current.getBoundingClientRect();+ const clickX = e.clientX - overlayRect.left;+ const clickY = e.clientY - overlayRect.top;++ for (let i = activeGraphicClips.length - 1; i >= 0; i--) {+ const clip = activeGraphicClips[i];+ const bounds = getGraphicClipDisplayBounds(clip);+ if (!bounds) continue;++ if (+ clickX >= bounds.x &&+ clickX <= bounds.x + bounds.width &&+ clickY >= bounds.y &&+ clickY <= bounds.y + bounds.height+ ) {+ select({ type: "shape-clip", id: clip.id });+ e.stopPropagation();+ return;+ }+ }+ },+ [interactionMode, activeGraphicClips, getGraphicClipDisplayBounds, select],+ );+const handleMouseMove = useCallback((e: React.MouseEvent) => {if (interactionMode === "none" || !interactionStartRef.current) return;@@ -4698,6 +4826,9 @@ export const Preview: React.FC = () => {maxWidth: `${800 * zoomLevel}px`,}}+ onMouseMove={!isPlaying ? handleGraphicsMouseMove : undefined}+ onClick={!isPlaying ? handleGraphicsClick : undefined}+ onMouseLeave={() => setHoveredGraphicClipId(null)}><canvasref={canvasRef}@@ -4705,7 +4836,7 @@ export const Preview: React.FC = () => {height={settings.height}className="w-full h-full object-contain bg-black"style={{- cursor: "default",+ cursor: hoveredGraphicClipId && !isPlaying ? "pointer" : "default",}}/>@@ -5031,6 +5162,32 @@ export const Preview: React.FC = () => {</div></div>)}++ {/* Graphic Clip Hover Indicators */}+ {!cropMode && !isPlaying &&+ activeGraphicClips.map((clip) => {+ if (clip.id === selectedShapeClipId) return null;+ if (clip.id !== hoveredGraphicClipId) return null;+ const bounds = getGraphicClipDisplayBounds(clip);+ if (!bounds) return null;+ return (+ <div+ key={clip.id}+ className="absolute pointer-events-none z-10"+ style={{+ left: bounds.x,+ top: bounds.y,+ width: bounds.width,+ height: bounds.height,+ }}+ >+ <div className="absolute inset-0 border-2 border-dashed border-white/80 rounded-sm" />+ <div className="absolute -top-6 left-1/2 -translate-x-1/2 px-2 py-0.5 bg-black/70 rounded text-[10px] text-white whitespace-nowrap">+ Click to select+ </div>+ </div>+ );+ })}</div></div>