OpenReel Video - Professional browser-based video editor. Open source CapCut alternative. 100% browser-based, no installation, no cloud uploads, no watermarks.
TypeScript
feat(image): add text presets, blend modes, flip rendering, marquee selection, and copy/paste styles
Augustus Otu6db0c0009b7f
diff --git a/apps/image/src/components/editor/canvas/Canvas.tsx b/apps/image/src/components/editor/canvas/Canvas.tsxindex d30fceeb..7d80fd32 100644--- a/apps/image/src/components/editor/canvas/Canvas.tsx+++ b/apps/image/src/components/editor/canvas/Canvas.tsx@@ -13,9 +13,9 @@ export function Canvas() {const canvasRef = useRef<HTMLCanvasElement>(null);const [containerSize, setContainerSize] = useState({ width: 0, height: 0 });- const { project, selectedLayerIds, selectedArtboardId, updateLayerTransform, selectLayer, deselectAllLayers, addPathLayer } = useProjectStore();+ const { project, selectedLayerIds, selectedArtboardId, updateLayerTransform, selectLayer, selectLayers, deselectAllLayers, addPathLayer } = useProjectStore();const { zoom, panX, panY, setPan, activeTool, showGrid, showRulers, gridSize, crop, snapToObjects, snapToGuides, snapToGrid, penSettings, drawing, startDrawing, addDrawingPoint, finishDrawing } = useUIStore();- const { setCanvasRef, setContainerRef, startDrag, updateDrag, endDrag, isDragging, dragMode, dragCurrentX, dragCurrentY, guides, smartGuides, setSmartGuides, clearSmartGuides } = useCanvasStore();+ const { setCanvasRef, setContainerRef, startDrag, updateDrag, endDrag, isDragging, dragMode, dragCurrentX, dragCurrentY, guides, smartGuides, setSmartGuides, clearSmartGuides, isMarqueeSelecting, marqueeRect, startMarqueeSelect, updateMarqueeSelect, endMarqueeSelect } = useCanvasStore();const artboard = project?.artboards.find((a) => a.id === selectedArtboardId);@@ -179,6 +179,23 @@ export function Canvas() {ctx.restore();}+ if (isMarqueeSelecting && marqueeRect) {+ ctx.save();+ ctx.fillStyle = 'rgba(34, 197, 94, 0.1)';+ ctx.strokeStyle = '#22c55e';+ ctx.lineWidth = 1;+ ctx.setLineDash([4, 4]);++ const mx = artboardX + marqueeRect.x * zoom;+ const my = artboardY + marqueeRect.y * zoom;+ const mw = marqueeRect.width * zoom;+ const mh = marqueeRect.height * zoom;++ ctx.fillRect(mx, my, mw, mh);+ ctx.strokeRect(mx, my, mw, mh);+ ctx.restore();+ }+if (crop.isActive && crop.layerId && crop.cropRect) {const cropLayer = project.layers[crop.layerId];if (cropLayer) {@@ -260,7 +277,7 @@ export function Canvas() {}ctx.restore();- }, [artboard, project, zoom, panX, panY, selectedLayerIds, showGrid, gridSize, crop, smartGuides, drawing, penSettings]);+ }, [artboard, project, zoom, panX, panY, selectedLayerIds, showGrid, gridSize, crop, smartGuides, drawing, penSettings, isMarqueeSelecting, marqueeRect]);useEffect(() => {render();@@ -354,10 +371,12 @@ export function Canvas() {startDrag('move', e.clientX, e.clientY);} else {deselectAllLayers();+ startMarqueeSelect(x, y);+ startDrag('marquee', e.clientX, e.clientY);}}},- [activeTool, screenToCanvas, findLayerAtPoint, selectLayer, deselectAllLayers, startDrag, selectedLayerIds, startDrawing]+ [activeTool, screenToCanvas, findLayerAtPoint, selectLayer, deselectAllLayers, startDrag, selectedLayerIds, startDrawing, startMarqueeSelect]);const handleMouseMove = useCallback(@@ -373,6 +392,13 @@ export function Canvas() {updateDrag(e.clientX, e.clientY);+ if (dragMode === 'marquee') {+ const { x, y } = screenToCanvas(e.clientX, e.clientY);+ updateMarqueeSelect(x, y);+ render();+ return;+ }+if (dragMode === 'pan') {const dx = e.clientX - dragCurrentX;const dy = e.clientY - dragCurrentY;@@ -417,7 +443,38 @@ export function Canvas() {}}},- [isDragging, dragMode, dragCurrentX, dragCurrentY, panX, panY, setPan, zoom, selectedLayerIds, project, updateLayerTransform, updateDrag, artboard, guides, snapToObjects, snapToGuides, snapToGrid, gridSize, setSmartGuides, drawing.isDrawing, screenToCanvas, addDrawingPoint, render]+ [isDragging, dragMode, dragCurrentX, dragCurrentY, panX, panY, setPan, zoom, selectedLayerIds, project, updateLayerTransform, updateDrag, artboard, guides, snapToObjects, snapToGuides, snapToGrid, gridSize, setSmartGuides, drawing.isDrawing, screenToCanvas, addDrawingPoint, render, updateMarqueeSelect]+ );++ const findLayersInRect = useCallback(+ (rect: { x: number; y: number; width: number; height: number }): string[] => {+ if (!artboard || !project) return [];++ const found: string[] = [];+ for (const layerId of artboard.layerIds) {+ const layer = project.layers[layerId];+ if (!layer || !layer.visible || layer.locked) continue;++ const { transform } = layer;+ const layerLeft = transform.x;+ const layerRight = transform.x + transform.width;+ const layerTop = transform.y;+ const layerBottom = transform.y + transform.height;++ const rectLeft = rect.x;+ const rectRight = rect.x + rect.width;+ const rectTop = rect.y;+ const rectBottom = rect.y + rect.height;++ const intersects = !(layerRight < rectLeft || layerLeft > rectRight || layerBottom < rectTop || layerTop > rectBottom);++ if (intersects) {+ found.push(layerId);+ }+ }+ return found;+ },+ [artboard, project]);const handleMouseUp = useCallback(() => {@@ -430,9 +487,22 @@ export function Canvas() {return;}+ if (dragMode === 'marquee') {+ const rect = endMarqueeSelect();+ if (rect && rect.width > 5 && rect.height > 5) {+ const layerIds = findLayersInRect(rect);+ if (layerIds.length > 0) {+ selectLayers(layerIds);+ }+ }+ endDrag();+ render();+ return;+ }+endDrag();clearSmartGuides();- }, [endDrag, clearSmartGuides, drawing.isDrawing, finishDrawing, addPathLayer, penSettings, render]);+ }, [endDrag, clearSmartGuides, drawing.isDrawing, finishDrawing, addPathLayer, penSettings, render, dragMode, endMarqueeSelect, findLayersInRect, selectLayers]);const handleWheel = useCallback((e: React.WheelEvent) => {@@ -480,6 +550,21 @@ export function Canvas() {);}+const BLEND_MODE_MAP: Record<string, GlobalCompositeOperation> = {+ 'normal': 'source-over',+ 'multiply': 'multiply',+ 'screen': 'screen',+ 'overlay': 'overlay',+ 'darken': 'darken',+ 'lighten': 'lighten',+ 'color-dodge': 'color-dodge',+ 'color-burn': 'color-burn',+ 'hard-light': 'hard-light',+ 'soft-light': 'soft-light',+ 'difference': 'difference',+ 'exclusion': 'exclusion',+};+function renderLayer(ctx: CanvasRenderingContext2D,layer: Layer,@@ -488,12 +573,14 @@ function renderLayer(const { transform } = layer;const shadow = layer.shadow ?? { enabled: false, color: 'rgba(0, 0, 0, 0.5)', blur: 10, offsetX: 0, offsetY: 4 };const glow = layer.glow ?? { enabled: false, color: '#ffffff', blur: 20, intensity: 1 };+ const blendMode = layer.blendMode?.mode ?? 'normal';ctx.save();ctx.translate(transform.x, transform.y);ctx.rotate((transform.rotation * Math.PI) / 180);ctx.scale(transform.scaleX, transform.scaleY);ctx.globalAlpha = transform.opacity;+ ctx.globalCompositeOperation = BLEND_MODE_MAP[blendMode] ?? 'source-over';if (glow.enabled && glow.blur > 0) {ctx.save();@@ -607,6 +694,18 @@ function renderImageLayer(return;}+ const flipH = layer.flipHorizontal ?? false;+ const flipV = layer.flipVertical ?? false;++ if (flipH || flipV) {+ ctx.save();+ ctx.translate(+ flipH ? layer.transform.width : 0,+ flipV ? layer.transform.height : 0+ );+ ctx.scale(flipH ? -1 : 1, flipV ? -1 : 1);+ }+const img = new window.Image();img.src = asset.dataUrl ?? asset.blobUrl ?? '';if (img.complete) {@@ -650,6 +749,10 @@ function renderImageLayer(ctx.filter = 'none';}++ if (flipH || flipV) {+ ctx.restore();+ }}function renderTextLayer(ctx: CanvasRenderingContext2D, layer: TextLayer) {diff --git a/apps/image/src/components/editor/inspector/TextSection.tsx b/apps/image/src/components/editor/inspector/TextSection.tsxindex 97dcf7b9..9f4f0e30 100644--- a/apps/image/src/components/editor/inspector/TextSection.tsx+++ b/apps/image/src/components/editor/inspector/TextSection.tsx@@ -1,6 +1,6 @@import { useProjectStore } from '../../../stores/project-store';import type { TextLayer, TextStyle, TextFillType, Gradient } from '../../../types/project';-import { AlignLeft, AlignCenter, AlignRight, Bold, Italic, Underline, CaseUpper, CaseLower, CaseSensitive, Strikethrough } from 'lucide-react';+import { AlignLeft, AlignCenter, AlignRight, Bold, Italic, Underline, CaseUpper, CaseLower, CaseSensitive, Strikethrough, Type } from 'lucide-react';import { FontPicker } from '../../ui/FontPicker';import { GradientPicker } from '../../ui/GradientPicker';import { Slider, Switch } from '@openreel/ui';@@ -11,6 +11,55 @@ interface Props {const FONT_SIZES = [8, 10, 12, 14, 16, 18, 20, 24, 28, 32, 36, 40, 48, 56, 64, 72, 96, 128];+interface TextPreset {+ id: string;+ name: string;+ style: Partial<TextStyle>;+}++const TEXT_PRESETS: TextPreset[] = [+ {+ id: 'heading-1',+ name: 'Heading 1',+ style: { fontSize: 72, fontWeight: 700, lineHeight: 1.1 },+ },+ {+ id: 'heading-2',+ name: 'Heading 2',+ style: { fontSize: 48, fontWeight: 700, lineHeight: 1.2 },+ },+ {+ id: 'heading-3',+ name: 'Heading 3',+ style: { fontSize: 36, fontWeight: 600, lineHeight: 1.2 },+ },+ {+ id: 'subheading',+ name: 'Subheading',+ style: { fontSize: 24, fontWeight: 500, lineHeight: 1.3 },+ },+ {+ id: 'body',+ name: 'Body',+ style: { fontSize: 16, fontWeight: 400, lineHeight: 1.5 },+ },+ {+ id: 'body-large',+ name: 'Body Large',+ style: { fontSize: 18, fontWeight: 400, lineHeight: 1.6 },+ },+ {+ id: 'caption',+ name: 'Caption',+ style: { fontSize: 12, fontWeight: 400, lineHeight: 1.4, color: '#a3a3a3' },+ },+ {+ id: 'quote',+ name: 'Quote',+ style: { fontSize: 24, fontWeight: 400, fontStyle: 'italic' as const, lineHeight: 1.5 },+ },+];+export function TextSection({ layer }: Props) {const { updateLayer } = useProjectStore();@@ -63,12 +112,34 @@ export function TextSection({ layer }: Props) {handleContentChange(capitalized);};+ const applyPreset = (preset: TextPreset) => {+ handleStyleChange(preset.style);+ };+return (<div className="space-y-4"><h4 className="text-xs font-medium text-muted-foreground uppercase tracking-wide">Text</h4>+ <div>+ <div className="flex items-center gap-2 mb-2">+ <Type size={14} className="text-muted-foreground" />+ <label className="text-[10px] text-muted-foreground">Text Presets</label>+ </div>+ <div className="flex flex-wrap gap-1.5">+ {TEXT_PRESETS.map((preset) => (+ <button+ key={preset.id}+ onClick={() => applyPreset(preset)}+ className="px-2.5 py-1.5 text-[10px] rounded-md bg-secondary text-secondary-foreground hover:bg-accent transition-colors"+ >+ {preset.name}+ </button>+ ))}+ </div>+ </div>+<div><label className="block text-[10px] text-muted-foreground mb-1">Content</label><textareadiff --git a/apps/image/src/components/editor/layers/LayerPanel.tsx b/apps/image/src/components/editor/layers/LayerPanel.tsxindex 1d210234..6f309d54 100644--- a/apps/image/src/components/editor/layers/LayerPanel.tsx+++ b/apps/image/src/components/editor/layers/LayerPanel.tsx@@ -1,4 +1,4 @@-import { Eye, EyeOff, Lock, Unlock, Trash2, Copy, ChevronUp, ChevronDown, ArrowUp, ArrowDown, ArrowUpToLine, ArrowDownToLine, Clipboard, ClipboardCopy, Scissors } from 'lucide-react';+import { Eye, EyeOff, Lock, Unlock, Trash2, Copy, ChevronUp, ChevronDown, ArrowUp, ArrowDown, ArrowUpToLine, ArrowDownToLine, Clipboard, ClipboardCopy, Scissors, Paintbrush } from 'lucide-react';import { useProjectStore } from '../../../stores/project-store';import type { Layer } from '../../../types/project';import {@@ -16,6 +16,7 @@ export function LayerPanel() {project,selectedLayerIds,selectedArtboardId,+ copiedStyle,selectLayer,updateLayer,removeLayer,@@ -27,6 +28,8 @@ export function LayerPanel() {copyLayers,cutLayers,pasteLayers,+ copyLayerStyle,+ pasteLayerStyle,} = useProjectStore();const artboard = project?.artboards.find((a) => a.id === selectedArtboardId);@@ -173,6 +176,15 @@ export function LayerPanel() {<ContextMenuShortcut>⌘D</ContextMenuShortcut></ContextMenuItem><ContextMenuSeparator />+ <ContextMenuItem onClick={() => { selectLayer(layer.id); copyLayerStyle(); }}>+ <Paintbrush size={14} className="mr-2" />+ Copy Style+ </ContextMenuItem>+ <ContextMenuItem onClick={pasteLayerStyle} disabled={!copiedStyle}>+ <Paintbrush size={14} className="mr-2" />+ Paste Style+ </ContextMenuItem>+ <ContextMenuSeparator /><ContextMenuItem onClick={() => moveLayerToTop(layer.id)}><ArrowUpToLine size={14} className="mr-2" />Bring to Frontdiff --git a/apps/image/src/stores/project-store.ts b/apps/image/src/stores/project-store.tsindex 6f6a2f31..2bcaa627 100644--- a/apps/image/src/stores/project-store.ts+++ b/apps/image/src/stores/project-store.ts@@ -23,11 +23,20 @@ import {CanvasBackground,} from '../types/project';+interface LayerStyle {+ blendMode: Layer['blendMode'];+ shadow: Layer['shadow'];+ stroke: Layer['stroke'];+ glow: Layer['glow'];+ filters: Layer['filters'];+}+interface ProjectState {project: Project | null;selectedLayerIds: string[];selectedArtboardId: string | null;copiedLayers: Layer[];+ copiedStyle: LayerStyle | null;isDirty: boolean;}@@ -70,6 +79,9 @@ interface ProjectActions {cutLayers: () => void;pasteLayers: () => void;+ copyLayerStyle: () => void;+ pasteLayerStyle: () => void;+groupLayers: (layerIds: string[]) => string | null;ungroupLayers: (groupId: string) => void;@@ -89,6 +101,7 @@ export const useProjectStore = create<ProjectState & ProjectActions>()(selectedLayerIds: [],selectedArtboardId: null,copiedLayers: [],+ copiedStyle: null,isDirty: false,createProject: (name, size, background) => {@@ -701,6 +714,46 @@ export const useProjectStore = create<ProjectState & ProjectActions>()(});},+ copyLayerStyle: () => {+ const { project, selectedLayerIds } = get();+ if (project && selectedLayerIds.length === 1) {+ const layer = project.layers[selectedLayerIds[0]];+ if (layer) {+ set({+ copiedStyle: {+ blendMode: JSON.parse(JSON.stringify(layer.blendMode)),+ shadow: JSON.parse(JSON.stringify(layer.shadow)),+ stroke: JSON.parse(JSON.stringify(layer.stroke)),+ glow: JSON.parse(JSON.stringify(layer.glow)),+ filters: JSON.parse(JSON.stringify(layer.filters)),+ },+ });+ }+ }+ },++ pasteLayerStyle: () => {+ const { copiedStyle, selectedLayerIds } = get();+ if (copiedStyle && selectedLayerIds.length > 0) {+ set((state) => {+ if (state.project) {+ selectedLayerIds.forEach((layerId) => {+ const layer = state.project!.layers[layerId];+ if (layer) {+ layer.blendMode = JSON.parse(JSON.stringify(copiedStyle.blendMode));+ layer.shadow = JSON.parse(JSON.stringify(copiedStyle.shadow));+ layer.stroke = JSON.parse(JSON.stringify(copiedStyle.stroke));+ layer.glow = JSON.parse(JSON.stringify(copiedStyle.glow));+ layer.filters = JSON.parse(JSON.stringify(copiedStyle.filters));+ }+ });+ state.project.updatedAt = Date.now();+ state.isDirty = true;+ }+ });+ }+ },+markDirty: () => set({ isDirty: true }),markClean: () => set({ isDirty: false }),}))