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 transform controls, guides, color swatches, and layer grouping
Augustus Otu302619b5d399
diff --git a/apps/image/src/components/editor/EditorInterface.tsx b/apps/image/src/components/editor/EditorInterface.tsxindex 5a486b78..4fcf1949 100644--- a/apps/image/src/components/editor/EditorInterface.tsx+++ b/apps/image/src/components/editor/EditorInterface.tsx@@ -5,13 +5,14 @@ import { Canvas } from './canvas/Canvas';import { Inspector } from './inspector/Inspector';import { LayerPanel } from './layers/LayerPanel';import { HistoryPanel } from './panels/HistoryPanel';+import { GuidePanel } from './panels/GuidePanel';import { PagesBar } from './pages/PagesBar';import { ExportDialog } from './ExportDialog';import { useUIStore } from '../../stores/ui-store';import { useProjectStore } from '../../stores/project-store';-import { Layers, History } from 'lucide-react';+import { Layers, History, Ruler } from 'lucide-react';-type BottomTab = 'layers' | 'history';+type BottomTab = 'layers' | 'history' | 'guides';export function EditorInterface() {const { isPanelCollapsed, isInspectorCollapsed, isExportDialogOpen, closeExportDialog } = useUIStore();@@ -62,6 +63,17 @@ export function EditorInterface() {<Layers size={14} />Layers</button>+ <button+ onClick={() => setBottomTab('guides')}+ className={`flex-1 flex items-center justify-center gap-1.5 px-3 py-2 text-xs font-medium transition-colors ${+ bottomTab === 'guides'+ ? 'text-foreground bg-background border-b-2 border-primary -mb-px'+ : 'text-muted-foreground hover:text-foreground hover:bg-accent'+ }`}+ >+ <Ruler size={14} />+ Guides+ </button><buttononClick={() => setBottomTab('history')}className={`flex-1 flex items-center justify-center gap-1.5 px-3 py-2 text-xs font-medium transition-colors ${@@ -75,7 +87,9 @@ export function EditorInterface() {</button></div><div className="flex-1 overflow-hidden">- {bottomTab === 'layers' ? <LayerPanel /> : <HistoryPanel />}+ {bottomTab === 'layers' && <LayerPanel />}+ {bottomTab === 'guides' && <GuidePanel />}+ {bottomTab === 'history' && <HistoryPanel />}</div></div></div>diff --git a/apps/image/src/components/editor/canvas/Canvas.tsx b/apps/image/src/components/editor/canvas/Canvas.tsxindex de7875ce..c881ddda 100644--- a/apps/image/src/components/editor/canvas/Canvas.tsx+++ b/apps/image/src/components/editor/canvas/Canvas.tsx@@ -580,6 +580,13 @@ function renderLayer(ctx.translate(transform.x, transform.y);ctx.rotate((transform.rotation * Math.PI) / 180);ctx.scale(transform.scaleX, transform.scaleY);++ const skewX = transform.skewX ?? 0;+ const skewY = transform.skewY ?? 0;+ if (skewX !== 0 || skewY !== 0) {+ ctx.transform(1, Math.tan(skewY * Math.PI / 180), Math.tan(skewX * Math.PI / 180), 1, 0, 0);+ }+ctx.globalAlpha = transform.opacity;ctx.globalCompositeOperation = BLEND_MODE_MAP[blendMode] ?? 'source-over';@@ -802,6 +809,17 @@ function renderImageLayer(function renderTextLayer(ctx: CanvasRenderingContext2D, layer: TextLayer) {const { style, content, transform } = layer;+ const flipH = layer.flipHorizontal ?? false;+ const flipV = layer.flipVertical ?? false;++ if (flipH || flipV) {+ ctx.save();+ ctx.translate(+ flipH ? transform.width : 0,+ flipV ? transform.height : 0+ );+ ctx.scale(flipH ? -1 : 1, flipV ? -1 : 1);+ }ctx.font = `${style.fontStyle} ${style.fontWeight} ${style.fontSize}px ${style.fontFamily}`;ctx.textAlign = style.textAlign as CanvasTextAlign;@@ -916,11 +934,26 @@ function renderTextLayer(ctx: CanvasRenderingContext2D, layer: TextLayer) {ctx.shadowOffsetX = 0;ctx.shadowOffsetY = 0;}++ if (flipH || flipV) {+ ctx.restore();+ }}function renderShapeLayer(ctx: CanvasRenderingContext2D, layer: ShapeLayer) {const { shapeType, shapeStyle, transform } = layer;const { width, height } = transform;+ const flipH = layer.flipHorizontal ?? false;+ const flipV = layer.flipVertical ?? false;++ if (flipH || flipV) {+ ctx.save();+ ctx.translate(+ flipH ? width : 0,+ flipV ? height : 0+ );+ ctx.scale(flipH ? -1 : 1, flipV ? -1 : 1);+ }ctx.beginPath();@@ -1122,4 +1155,8 @@ function renderShapeLayer(ctx: CanvasRenderingContext2D, layer: ShapeLayer) {ctx.stroke();ctx.setLineDash([]);}++ if (flipH || flipV) {+ ctx.restore();+ }}diff --git a/apps/image/src/components/editor/inspector/ColorHarmonySection.tsx b/apps/image/src/components/editor/inspector/ColorHarmonySection.tsxindex 93bdc2fa..186819a1 100644--- a/apps/image/src/components/editor/inspector/ColorHarmonySection.tsx+++ b/apps/image/src/components/editor/inspector/ColorHarmonySection.tsx@@ -2,6 +2,8 @@ import { useState } from 'react';import { getAllHarmonies, type HarmonyType } from '../../../utils/color-harmony';import { Palette, Copy, Check } from 'lucide-react';import { ColorPalettes, QuickColorSwatches } from '../../ui/ColorPalettes';+import { SavedColorsSection } from '../../ui/SavedColorsSection';+import { useColorStore } from '../../../stores/color-store';interface Props {baseColor: string;@@ -11,6 +13,7 @@ interface Props {export function ColorHarmonySection({ baseColor, onColorSelect }: Props) {const [copiedColor, setCopiedColor] = useState<string | null>(null);const [selectedHarmony, setSelectedHarmony] = useState<HarmonyType>('complementary');+ const { addRecentColor } = useColorStore();const isValidHex = /^#[0-9A-Fa-f]{6}$/.test(baseColor);if (!isValidHex) return null;@@ -18,6 +21,11 @@ export function ColorHarmonySection({ baseColor, onColorSelect }: Props) {const harmonies = getAllHarmonies(baseColor);const activeHarmony = harmonies.find((h) => h.type === selectedHarmony) ?? harmonies[0];+ const handleColorSelect = (color: string) => {+ addRecentColor(color);+ onColorSelect?.(color);+ };+const handleCopyColor = async (color: string) => {try {await navigator.clipboard.writeText(color);@@ -58,7 +66,7 @@ export function ColorHarmonySection({ baseColor, onColorSelect }: Props) {{activeHarmony.colors.map((color, index) => (<div key={index} className="flex-1 flex flex-col items-center gap-1"><button- onClick={() => onColorSelect?.(color)}+ onClick={() => handleColorSelect(color)}className="w-full aspect-square rounded-lg border border-border hover:ring-2 hover:ring-primary/50 transition-all cursor-pointer"style={{ backgroundColor: color }}title={`Click to apply ${color}`}@@ -85,8 +93,13 @@ export function ColorHarmonySection({ baseColor, onColorSelect }: Props) {{onColorSelect && (<>- <QuickColorSwatches onColorSelect={onColorSelect} selectedColor={baseColor} />- <ColorPalettes onColorSelect={onColorSelect} selectedColor={baseColor} />+ <SavedColorsSection+ onColorSelect={handleColorSelect}+ selectedColor={baseColor}+ currentColor={baseColor}+ />+ <QuickColorSwatches onColorSelect={handleColorSelect} selectedColor={baseColor} />+ <ColorPalettes onColorSelect={handleColorSelect} selectedColor={baseColor} /></>)}</div>diff --git a/apps/image/src/components/editor/inspector/ImageControlsSection.tsx b/apps/image/src/components/editor/inspector/ImageControlsSection.tsxindex a6c6a465..bb7646cd 100644--- a/apps/image/src/components/editor/inspector/ImageControlsSection.tsx+++ b/apps/image/src/components/editor/inspector/ImageControlsSection.tsx@@ -1,5 +1,4 @@-import { FlipHorizontal2, FlipVertical2, RotateCw, RotateCcw } from 'lucide-react';-import { useProjectStore } from '../../../stores/project-store';+import { Crop, ImageIcon } from 'lucide-react';import type { ImageLayer } from '../../../types/project';interface Props {@@ -7,79 +6,25 @@ interface Props {}export function ImageControlsSection({ layer }: Props) {- const { updateLayer, updateLayerTransform } = useProjectStore();-- const handleFlipHorizontal = () => {- updateLayer<ImageLayer>(layer.id, {- flipHorizontal: !layer.flipHorizontal,- });- };-- const handleFlipVertical = () => {- updateLayer<ImageLayer>(layer.id, {- flipVertical: !layer.flipVertical,- });- };-- const handleRotate = (degrees: number) => {- const currentRotation = layer.transform.rotation;- updateLayerTransform(layer.id, {- rotation: (currentRotation + degrees) % 360,- });- };-return (<div className="space-y-3"><h4 className="text-xs font-medium text-muted-foreground uppercase tracking-wide">- Transform+ Image</h4>- <div className="flex gap-2">- <button- onClick={handleFlipHorizontal}- className={`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg border transition-all ${- layer.flipHorizontal- ? 'bg-primary/20 border-primary text-primary'- : 'bg-secondary/50 border-border text-muted-foreground hover:text-foreground hover:bg-secondary'- }`}- title="Flip Horizontal"- >- <FlipHorizontal2 size={16} />- <span className="text-xs font-medium">Flip H</span>- </button>-- <button- onClick={handleFlipVertical}- className={`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg border transition-all ${- layer.flipVertical- ? 'bg-primary/20 border-primary text-primary'- : 'bg-secondary/50 border-border text-muted-foreground hover:text-foreground hover:bg-secondary'- }`}- title="Flip Vertical"- >- <FlipVertical2 size={16} />- <span className="text-xs font-medium">Flip V</span>- </button>- </div>-- <div className="flex gap-2">- <button- onClick={() => handleRotate(-90)}- className="flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg bg-secondary/50 border border-border text-muted-foreground hover:text-foreground hover:bg-secondary transition-all"- title="Rotate 90° Counter-clockwise"- >- <RotateCcw size={16} />- <span className="text-xs font-medium">-90°</span>- </button>-- <button- onClick={() => handleRotate(90)}- className="flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg bg-secondary/50 border border-border text-muted-foreground hover:text-foreground hover:bg-secondary transition-all"- title="Rotate 90° Clockwise"- >- <RotateCw size={16} />- <span className="text-xs font-medium">+90°</span>- </button>+ <div className="p-3 bg-secondary/30 rounded-lg">+ <div className="flex items-center gap-2 text-muted-foreground">+ <ImageIcon size={14} />+ <span className="text-[11px]">Source: {layer.sourceId ? 'Linked' : 'None'}</span>+ </div>+ {layer.cropRect && (+ <div className="flex items-center gap-2 text-muted-foreground mt-2">+ <Crop size={14} />+ <span className="text-[11px]">+ Cropped: {Math.round(layer.cropRect.width)} × {Math.round(layer.cropRect.height)}+ </span>+ </div>+ )}</div></div>);diff --git a/apps/image/src/components/editor/inspector/TransformSection.tsx b/apps/image/src/components/editor/inspector/TransformSection.tsxindex f57c63dc..9210a540 100644--- a/apps/image/src/components/editor/inspector/TransformSection.tsx+++ b/apps/image/src/components/editor/inspector/TransformSection.tsx@@ -1,3 +1,4 @@+import { FlipHorizontal2, FlipVertical2, RotateCw, RotateCcw } from 'lucide-react';import { useProjectStore } from '../../../stores/project-store';import type { Layer } from '../../../types/project';@@ -6,14 +7,30 @@ interface Props {}export function TransformSection({ layer }: Props) {- const { updateLayerTransform } = useProjectStore();+ const { updateLayer, updateLayerTransform } = useProjectStore();- const { x, y, width, height, rotation, opacity } = layer.transform;+ const { x, y, width, height, rotation, skewX, skewY, opacity } = layer.transform;+ const flipH = layer.flipHorizontal ?? false;+ const flipV = layer.flipVertical ?? false;const handleChange = (key: string, value: number) => {updateLayerTransform(layer.id, { [key]: value });};+ const handleFlipHorizontal = () => {+ updateLayer(layer.id, { flipHorizontal: !flipH });+ };++ const handleFlipVertical = () => {+ updateLayer(layer.id, { flipVertical: !flipV });+ };++ const handleRotate = (degrees: number) => {+ updateLayerTransform(layer.id, {+ rotation: (rotation + degrees) % 360,+ });+ };+return (<div className="space-y-3"><h4 className="text-xs font-medium text-muted-foreground uppercase tracking-wide">@@ -92,6 +109,79 @@ export function TransformSection({ layer }: Props) {</div></div></div>++ <div className="grid grid-cols-2 gap-2">+ <div>+ <label className="block text-[10px] text-muted-foreground mb-1">Skew X</label>+ <div className="flex items-center gap-1">+ <input+ type="number"+ value={Math.round(skewX ?? 0)}+ onChange={(e) => handleChange('skewX', Number(e.target.value))}+ className="flex-1 px-2 py-1.5 text-xs bg-background border border-input rounded-md focus:outline-none focus:ring-1 focus:ring-primary"+ min={-89}+ max={89}+ />+ <span className="text-xs text-muted-foreground">°</span>+ </div>+ </div>+ <div>+ <label className="block text-[10px] text-muted-foreground mb-1">Skew Y</label>+ <div className="flex items-center gap-1">+ <input+ type="number"+ value={Math.round(skewY ?? 0)}+ onChange={(e) => handleChange('skewY', Number(e.target.value))}+ className="flex-1 px-2 py-1.5 text-xs bg-background border border-input rounded-md focus:outline-none focus:ring-1 focus:ring-primary"+ min={-89}+ max={89}+ />+ <span className="text-xs text-muted-foreground">°</span>+ </div>+ </div>+ </div>++ <div className="grid grid-cols-4 gap-1.5">+ <button+ onClick={handleFlipHorizontal}+ className={`flex items-center justify-center gap-1 p-2 rounded-md border transition-all ${+ flipH+ ? 'bg-primary/20 border-primary text-primary'+ : 'bg-secondary/50 border-border text-muted-foreground hover:text-foreground hover:bg-secondary'+ }`}+ title="Flip Horizontal"+ >+ <FlipHorizontal2 size={14} />+ </button>++ <button+ onClick={handleFlipVertical}+ className={`flex items-center justify-center gap-1 p-2 rounded-md border transition-all ${+ flipV+ ? 'bg-primary/20 border-primary text-primary'+ : 'bg-secondary/50 border-border text-muted-foreground hover:text-foreground hover:bg-secondary'+ }`}+ title="Flip Vertical"+ >+ <FlipVertical2 size={14} />+ </button>++ <button+ onClick={() => handleRotate(-90)}+ className="flex items-center justify-center gap-1 p-2 rounded-md bg-secondary/50 border border-border text-muted-foreground hover:text-foreground hover:bg-secondary transition-all"+ title="Rotate 90° Counter-clockwise"+ >+ <RotateCcw size={14} />+ </button>++ <button+ onClick={() => handleRotate(90)}+ className="flex items-center justify-center gap-1 p-2 rounded-md bg-secondary/50 border border-border text-muted-foreground hover:text-foreground hover:bg-secondary transition-all"+ title="Rotate 90° Clockwise"+ >+ <RotateCw size={14} />+ </button>+ </div></div>);}diff --git a/apps/image/src/components/editor/layers/LayerPanel.tsx b/apps/image/src/components/editor/layers/LayerPanel.tsxindex 9670925e..0c341efa 100644--- a/apps/image/src/components/editor/layers/LayerPanel.tsx+++ b/apps/image/src/components/editor/layers/LayerPanel.tsx@@ -1,5 +1,5 @@import { useState, useRef, useEffect } from 'react';-import { Eye, EyeOff, Lock, Unlock, Trash2, Copy, ChevronUp, ChevronDown, ArrowUp, ArrowDown, ArrowUpToLine, ArrowDownToLine, Clipboard, ClipboardCopy, Scissors, Paintbrush, Search, X, Image, Type, Hexagon, Folder } from 'lucide-react';+import { Eye, EyeOff, Lock, Unlock, Trash2, Copy, ChevronUp, ChevronDown, ArrowUp, ArrowDown, ArrowUpToLine, ArrowDownToLine, Clipboard, ClipboardCopy, Scissors, Paintbrush, Search, X, Image, Type, Hexagon, Folder, FolderPlus, FolderOpen } from 'lucide-react';import { useProjectStore } from '../../../stores/project-store';import type { Layer, LayerType } from '../../../types/project';import {@@ -43,6 +43,8 @@ export function LayerPanel() {pasteLayers,copyLayerStyle,pasteLayerStyle,+ groupLayers,+ ungroupLayers,} = useProjectStore();const [searchQuery, setSearchQuery] = useState('');@@ -300,6 +302,21 @@ export function LayerPanel() {<ContextMenuShortcut>⌘D</ContextMenuShortcut></ContextMenuItem><ContextMenuSeparator />+ {selectedLayerIds.length > 1 && (+ <ContextMenuItem onClick={() => groupLayers(selectedLayerIds)}>+ <FolderPlus size={14} className="mr-2" />+ Group Selection+ <ContextMenuShortcut>⌘G</ContextMenuShortcut>+ </ContextMenuItem>+ )}+ {layer.type === 'group' && (+ <ContextMenuItem onClick={() => ungroupLayers(layer.id)}>+ <FolderOpen size={14} className="mr-2" />+ Ungroup+ <ContextMenuShortcut>⌘⇧G</ContextMenuShortcut>+ </ContextMenuItem>+ )}+ {(selectedLayerIds.length > 1 || layer.type === 'group') && <ContextMenuSeparator />}<ContextMenuItem onClick={() => { selectLayer(layer.id); copyLayerStyle(); }}><Paintbrush size={14} className="mr-2" />Copy Style@@ -361,8 +378,29 @@ export function LayerPanel() {)}</div>+ {selectedLayerIds.length > 1 && (+ <div className="p-2 border-t border-border">+ <button+ onClick={() => groupLayers(selectedLayerIds)}+ className="w-full flex items-center justify-center gap-1.5 px-3 py-2 rounded-md bg-primary text-primary-foreground text-xs font-medium hover:bg-primary/90 transition-colors"+ >+ <FolderPlus size={14} />+ Group {selectedLayerIds.length} Layers+ </button>+ </div>+ )}+{selectedLayerIds.length === 1 && (<div className="p-2 border-t border-border space-y-2">+ {project?.layers[selectedLayerIds[0]]?.type === 'group' && (+ <button+ onClick={() => ungroupLayers(selectedLayerIds[0])}+ className="w-full flex items-center justify-center gap-1.5 px-3 py-1.5 rounded-md bg-secondary text-secondary-foreground text-xs font-medium hover:bg-secondary/80 transition-colors mb-2"+ >+ <FolderOpen size={14} />+ Ungroup+ </button>+ )}<div className="flex items-center gap-2"><span className="text-[10px] text-muted-foreground w-12">Opacity</span><Sliderdiff --git a/apps/image/src/components/editor/panels/GuidePanel.tsx b/apps/image/src/components/editor/panels/GuidePanel.tsxnew file mode 100644index 00000000..728e6098--- /dev/null+++ b/apps/image/src/components/editor/panels/GuidePanel.tsx@@ -0,0 +1,290 @@+import { useState } from 'react';+import { Ruler, Plus, Trash2, X, ArrowRight, ArrowDown } from 'lucide-react';+import { useCanvasStore, type Guide } from '../../../stores/canvas-store';+import { useProjectStore } from '../../../stores/project-store';++export function GuidePanel() {+ const { guides, addGuide, removeGuide, updateGuide, clearGuides } = useCanvasStore();+ const { project, selectedArtboardId } = useProjectStore();+ const [editingGuideId, setEditingGuideId] = useState<string | null>(null);+ const [editingValue, setEditingValue] = useState('');+ const [showAddForm, setShowAddForm] = useState(false);+ const [newGuideType, setNewGuideType] = useState<'horizontal' | 'vertical'>('horizontal');+ const [newGuidePosition, setNewGuidePosition] = useState('');++ const artboard = project?.artboards.find((a) => a.id === selectedArtboardId);++ const horizontalGuides = guides.filter((g) => g.type === 'horizontal');+ const verticalGuides = guides.filter((g) => g.type === 'vertical');++ const handleAddGuide = () => {+ const position = parseFloat(newGuidePosition);+ if (!isNaN(position)) {+ addGuide(newGuideType, position);+ setNewGuidePosition('');+ setShowAddForm(false);+ }+ };++ const handleStartEdit = (guide: Guide) => {+ setEditingGuideId(guide.id);+ setEditingValue(guide.position.toString());+ };++ const handleFinishEdit = () => {+ if (editingGuideId) {+ const position = parseFloat(editingValue);+ if (!isNaN(position)) {+ updateGuide(editingGuideId, position);+ }+ }+ setEditingGuideId(null);+ setEditingValue('');+ };++ const handleAddCenterGuides = () => {+ if (artboard) {+ addGuide('horizontal', artboard.size.height / 2);+ addGuide('vertical', artboard.size.width / 2);+ }+ };++ const handleAddThirdsGuides = () => {+ if (artboard) {+ addGuide('horizontal', artboard.size.height / 3);+ addGuide('horizontal', (artboard.size.height * 2) / 3);+ addGuide('vertical', artboard.size.width / 3);+ addGuide('vertical', (artboard.size.width * 2) / 3);+ }+ };++ const handleAddEdgeGuides = () => {+ if (artboard) {+ const margin = Math.min(artboard.size.width, artboard.size.height) * 0.1;+ addGuide('horizontal', margin);+ addGuide('horizontal', artboard.size.height - margin);+ addGuide('vertical', margin);+ addGuide('vertical', artboard.size.width - margin);+ }+ };++ return (+ <div className="h-full flex flex-col">+ <div className="flex items-center justify-between px-3 py-2 border-b border-border">+ <div className="flex items-center gap-2">+ <Ruler size={14} className="text-muted-foreground" />+ <h3 className="text-xs font-medium text-foreground">Guides</h3>+ </div>+ <span className="text-[10px] text-muted-foreground">{guides.length}</span>+ </div>++ <div className="flex-1 overflow-y-auto">+ <div className="p-2 space-y-3">+ <div className="flex gap-1">+ <button+ onClick={() => setShowAddForm(true)}+ className="flex-1 flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-md bg-primary text-primary-foreground text-[10px] font-medium hover:bg-primary/90 transition-colors"+ >+ <Plus size={12} />+ Add Guide+ </button>+ {guides.length > 0 && (+ <button+ onClick={clearGuides}+ className="p-1.5 rounded-md bg-destructive/10 text-destructive hover:bg-destructive/20 transition-colors"+ title="Clear all guides"+ >+ <Trash2 size={14} />+ </button>+ )}+ </div>++ {showAddForm && (+ <div className="p-2 bg-secondary/50 rounded-lg space-y-2">+ <div className="flex gap-1">+ <button+ onClick={() => setNewGuideType('horizontal')}+ className={`flex-1 flex items-center justify-center gap-1 px-2 py-1.5 rounded text-[10px] transition-colors ${+ newGuideType === 'horizontal'+ ? 'bg-primary text-primary-foreground'+ : 'bg-background text-muted-foreground hover:text-foreground'+ }`}+ >+ <ArrowRight size={10} />+ Horizontal+ </button>+ <button+ onClick={() => setNewGuideType('vertical')}+ className={`flex-1 flex items-center justify-center gap-1 px-2 py-1.5 rounded text-[10px] transition-colors ${+ newGuideType === 'vertical'+ ? 'bg-primary text-primary-foreground'+ : 'bg-background text-muted-foreground hover:text-foreground'+ }`}+ >+ <ArrowDown size={10} />+ Vertical+ </button>+ </div>+ <div className="flex gap-1">+ <input+ type="number"+ value={newGuidePosition}+ onChange={(e) => setNewGuidePosition(e.target.value)}+ onKeyDown={(e) => {+ if (e.key === 'Enter') handleAddGuide();+ if (e.key === 'Escape') setShowAddForm(false);+ }}+ placeholder={newGuideType === 'horizontal' ? 'Y position...' : 'X position...'}+ className="flex-1 px-2 py-1 text-[10px] bg-background border border-input rounded focus:outline-none focus:ring-1 focus:ring-primary"+ autoFocus+ />+ <button+ onClick={handleAddGuide}+ className="px-2 py-1 rounded bg-primary text-primary-foreground text-[10px] hover:bg-primary/90 transition-colors"+ >+ Add+ </button>+ <button+ onClick={() => setShowAddForm(false)}+ className="p-1 rounded bg-secondary text-secondary-foreground hover:bg-secondary/80 transition-colors"+ >+ <X size={12} />+ </button>+ </div>+ </div>+ )}++ <div className="space-y-1">+ <span className="text-[10px] text-muted-foreground font-medium">Quick Presets</span>+ <div className="grid grid-cols-3 gap-1">+ <button+ onClick={handleAddCenterGuides}+ className="px-2 py-1.5 rounded bg-secondary/50 text-[9px] text-muted-foreground hover:text-foreground hover:bg-secondary transition-colors"+ >+ Center+ </button>+ <button+ onClick={handleAddThirdsGuides}+ className="px-2 py-1.5 rounded bg-secondary/50 text-[9px] text-muted-foreground hover:text-foreground hover:bg-secondary transition-colors"+ >+ Thirds+ </button>+ <button+ onClick={handleAddEdgeGuides}+ className="px-2 py-1.5 rounded bg-secondary/50 text-[9px] text-muted-foreground hover:text-foreground hover:bg-secondary transition-colors"+ >+ Margins+ </button>+ </div>+ </div>++ {horizontalGuides.length > 0 && (+ <div className="space-y-1">+ <div className="flex items-center gap-1.5">+ <ArrowRight size={10} className="text-blue-400" />+ <span className="text-[10px] text-muted-foreground">+ Horizontal ({horizontalGuides.length})+ </span>+ </div>+ <div className="space-y-0.5">+ {horizontalGuides.map((guide) => (+ <div+ key={guide.id}+ className="flex items-center gap-1 px-2 py-1 rounded bg-blue-500/10 group"+ >+ <span className="text-[10px] text-blue-400 w-4">Y</span>+ {editingGuideId === guide.id ? (+ <input+ type="number"+ value={editingValue}+ onChange={(e) => setEditingValue(e.target.value)}+ onBlur={handleFinishEdit}+ onKeyDown={(e) => {+ if (e.key === 'Enter') handleFinishEdit();+ if (e.key === 'Escape') setEditingGuideId(null);+ }}+ className="flex-1 px-1 py-0.5 text-[10px] bg-background border border-primary rounded focus:outline-none"+ autoFocus+ />+ ) : (+ <button+ onClick={() => handleStartEdit(guide)}+ className="flex-1 text-left text-[10px] text-foreground hover:text-primary transition-colors"+ >+ {Math.round(guide.position)}px+ </button>+ )}+ <button+ onClick={() => removeGuide(guide.id)}+ className="p-0.5 rounded opacity-0 group-hover:opacity-100 hover:bg-destructive/20 text-muted-foreground hover:text-destructive transition-all"+ >+ <X size={10} />+ </button>+ </div>+ ))}+ </div>+ </div>+ )}++ {verticalGuides.length > 0 && (+ <div className="space-y-1">+ <div className="flex items-center gap-1.5">+ <ArrowDown size={10} className="text-green-400" />+ <span className="text-[10px] text-muted-foreground">+ Vertical ({verticalGuides.length})+ </span>+ </div>+ <div className="space-y-0.5">+ {verticalGuides.map((guide) => (+ <div+ key={guide.id}+ className="flex items-center gap-1 px-2 py-1 rounded bg-green-500/10 group"+ >+ <span className="text-[10px] text-green-400 w-4">X</span>+ {editingGuideId === guide.id ? (+ <input+ type="number"+ value={editingValue}+ onChange={(e) => setEditingValue(e.target.value)}+ onBlur={handleFinishEdit}+ onKeyDown={(e) => {+ if (e.key === 'Enter') handleFinishEdit();+ if (e.key === 'Escape') setEditingGuideId(null);+ }}+ className="flex-1 px-1 py-0.5 text-[10px] bg-background border border-primary rounded focus:outline-none"+ autoFocus+ />+ ) : (+ <button+ onClick={() => handleStartEdit(guide)}+ className="flex-1 text-left text-[10px] text-foreground hover:text-primary transition-colors"+ >+ {Math.round(guide.position)}px+ </button>+ )}+ <button+ onClick={() => removeGuide(guide.id)}+ className="p-0.5 rounded opacity-0 group-hover:opacity-100 hover:bg-destructive/20 text-muted-foreground hover:text-destructive transition-all"+ >+ <X size={10} />+ </button>+ </div>+ ))}+ </div>+ </div>+ )}++ {guides.length === 0 && !showAddForm && (+ <div className="flex flex-col items-center justify-center py-6 text-center">+ <Ruler size={24} className="text-muted-foreground/40 mb-2" />+ <p className="text-[10px] text-muted-foreground">No guides yet</p>+ <p className="text-[9px] text-muted-foreground/60 mt-0.5">+ Click "Add Guide" or use presets+ </p>+ </div>+ )}+ </div>+ </div>+ </div>+ );+}diff --git a/apps/image/src/components/ui/SavedColorsSection.tsx b/apps/image/src/components/ui/SavedColorsSection.tsxnew file mode 100644index 00000000..e0086a4f--- /dev/null+++ b/apps/image/src/components/ui/SavedColorsSection.tsx@@ -0,0 +1,296 @@+import { useState } from 'react';+import { Collapsible, CollapsibleTrigger, CollapsibleContent } from '@openreel/ui';+import { ChevronDown, Plus, Trash2, X, Bookmark, History, FolderPlus, Pencil, Check } from 'lucide-react';+import { useColorStore, type CustomPalette } from '../../stores/color-store';++interface SavedColorsSectionProps {+ onColorSelect: (color: string) => void;+ selectedColor?: string;+ currentColor?: string;+}++export function SavedColorsSection({ onColorSelect, selectedColor, currentColor }: SavedColorsSectionProps) {+ const {+ recentColors,+ savedColors,+ customPalettes,+ saveColor,+ removeSavedColor,+ clearSavedColors,+ createPalette,+ updatePalette,+ addColorToPalette,+ removeColorFromPalette,+ deletePalette,+ } = useColorStore();++ const [isOpen, setIsOpen] = useState(true);+ const [editingPaletteId, setEditingPaletteId] = useState<string | null>(null);+ const [editingName, setEditingName] = useState('');+ const [showNewPaletteInput, setShowNewPaletteInput] = useState(false);+ const [newPaletteName, setNewPaletteName] = useState('');++ const handleSaveCurrentColor = () => {+ if (currentColor) {+ saveColor(currentColor);+ }+ };++ const handleCreatePalette = () => {+ if (newPaletteName.trim()) {+ createPalette(newPaletteName.trim());+ setNewPaletteName('');+ setShowNewPaletteInput(false);+ }+ };++ const handleStartEditPalette = (palette: CustomPalette) => {+ setEditingPaletteId(palette.id);+ setEditingName(palette.name);+ };++ const handleFinishEditPalette = () => {+ if (editingPaletteId && editingName.trim()) {+ updatePalette(editingPaletteId, { name: editingName.trim() });+ }+ setEditingPaletteId(null);+ setEditingName('');+ };++ const handleAddCurrentToPalette = (paletteId: string) => {+ if (currentColor) {+ addColorToPalette(paletteId, currentColor);+ }+ };++ return (+ <Collapsible open={isOpen} onOpenChange={setIsOpen}>+ <CollapsibleTrigger asChild>+ <button className="w-full flex items-center justify-between p-2 rounded-lg bg-secondary/50 hover:bg-secondary transition-colors">+ <div className="flex items-center gap-2">+ <Bookmark size={14} className="text-muted-foreground" />+ <span className="text-xs font-medium">Saved Colors</span>+ </div>+ <ChevronDown size={14} className={`text-muted-foreground transition-transform ${isOpen ? 'rotate-180' : ''}`} />+ </button>+ </CollapsibleTrigger>+ <CollapsibleContent>+ <div className="p-2 space-y-3 bg-background/50 rounded-b-lg border border-t-0 border-border">+ {recentColors.length > 0 && (+ <div className="space-y-1.5">+ <div className="flex items-center gap-1.5">+ <History size={12} className="text-muted-foreground" />+ <span className="text-[10px] text-muted-foreground">Recent</span>+ </div>+ <div className="grid grid-cols-6 gap-1">+ {recentColors.map((color, i) => (+ <button+ key={`${color}-${i}`}+ onClick={() => onColorSelect(color)}+ className={`w-full aspect-square rounded border transition-all hover:scale-110 ${+ selectedColor?.toLowerCase() === color.toLowerCase()+ ? 'border-primary ring-2 ring-primary/30'+ : 'border-border/50 hover:border-border'+ }`}+ style={{ backgroundColor: color }}+ title={color}+ />+ ))}+ </div>+ </div>+ )}++ <div className="space-y-1.5">+ <div className="flex items-center justify-between">+ <div className="flex items-center gap-1.5">+ <Bookmark size={12} className="text-muted-foreground" />+ <span className="text-[10px] text-muted-foreground">Saved</span>+ <span className="text-[9px] text-muted-foreground/60">({savedColors.length})</span>+ </div>+ <div className="flex items-center gap-1">+ {currentColor && (+ <button+ onClick={handleSaveCurrentColor}+ className="p-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground transition-colors"+ title="Save current color"+ >+ <Plus size={12} />+ </button>+ )}+ {savedColors.length > 0 && (+ <button+ onClick={clearSavedColors}+ className="p-1 rounded hover:bg-destructive/20 text-muted-foreground hover:text-destructive transition-colors"+ title="Clear all saved colors"+ >+ <Trash2 size={12} />+ </button>+ )}+ </div>+ </div>+ {savedColors.length > 0 ? (+ <div className="grid grid-cols-6 gap-1">+ {savedColors.map((color, i) => (+ <div key={`${color}-${i}`} className="relative group">+ <button+ onClick={() => onColorSelect(color)}+ className={`w-full aspect-square rounded border transition-all hover:scale-110 ${+ selectedColor?.toLowerCase() === color.toLowerCase()+ ? 'border-primary ring-2 ring-primary/30'+ : 'border-border/50 hover:border-border'+ }`}+ style={{ backgroundColor: color }}+ title={color}+ />+ <button+ onClick={() => removeSavedColor(color)}+ className="absolute -top-1 -right-1 w-3.5 h-3.5 rounded-full bg-destructive text-destructive-foreground opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center"+ title="Remove color"+ >+ <X size={8} />+ </button>+ </div>+ ))}+ </div>+ ) : (+ <p className="text-[10px] text-muted-foreground/60 text-center py-2">+ No saved colors yet+ </p>+ )}+ </div>++ <div className="space-y-2">+ <div className="flex items-center justify-between">+ <span className="text-[10px] text-muted-foreground">Custom Palettes</span>+ <button+ onClick={() => setShowNewPaletteInput(true)}+ className="p-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground transition-colors"+ title="Create new palette"+ >+ <FolderPlus size={12} />+ </button>+ </div>++ {showNewPaletteInput && (+ <div className="flex gap-1">+ <input+ type="text"+ value={newPaletteName}+ onChange={(e) => setNewPaletteName(e.target.value)}+ onKeyDown={(e) => {+ if (e.key === 'Enter') handleCreatePalette();+ if (e.key === 'Escape') setShowNewPaletteInput(false);+ }}+ placeholder="Palette name..."+ className="flex-1 px-2 py-1 text-[10px] bg-background border border-input rounded focus:outline-none focus:ring-1 focus:ring-primary"+ autoFocus+ />+ <button+ onClick={handleCreatePalette}+ className="p-1 rounded bg-primary text-primary-foreground hover:bg-primary/90 transition-colors"+ >+ <Check size={12} />+ </button>+ <button+ onClick={() => setShowNewPaletteInput(false)}+ className="p-1 rounded bg-secondary text-secondary-foreground hover:bg-secondary/80 transition-colors"+ >+ <X size={12} />+ </button>+ </div>+ )}++ {customPalettes.map((palette) => (+ <div key={palette.id} className="space-y-1 p-2 bg-secondary/30 rounded-lg">+ <div className="flex items-center justify-between">+ {editingPaletteId === palette.id ? (+ <div className="flex-1 flex gap-1 mr-1">+ <input+ type="text"+ value={editingName}+ onChange={(e) => setEditingName(e.target.value)}+ onKeyDown={(e) => {+ if (e.key === 'Enter') handleFinishEditPalette();+ if (e.key === 'Escape') setEditingPaletteId(null);+ }}+ className="flex-1 px-1.5 py-0.5 text-[10px] bg-background border border-input rounded focus:outline-none focus:ring-1 focus:ring-primary"+ autoFocus+ />+ <button+ onClick={handleFinishEditPalette}+ className="p-0.5 rounded bg-primary text-primary-foreground"+ >+ <Check size={10} />+ </button>+ </div>+ ) : (+ <span className="text-[10px] font-medium text-foreground">{palette.name}</span>+ )}+ <div className="flex items-center gap-0.5">+ {currentColor && (+ <button+ onClick={() => handleAddCurrentToPalette(palette.id)}+ className="p-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground transition-colors"+ title="Add current color"+ >+ <Plus size={10} />+ </button>+ )}+ <button+ onClick={() => handleStartEditPalette(palette)}+ className="p-1 rounded hover:bg-secondary text-muted-foreground hover:text-foreground transition-colors"+ title="Rename palette"+ >+ <Pencil size={10} />+ </button>+ <button+ onClick={() => deletePalette(palette.id)}+ className="p-1 rounded hover:bg-destructive/20 text-muted-foreground hover:text-destructive transition-colors"+ title="Delete palette"+ >+ <Trash2 size={10} />+ </button>+ </div>+ </div>+ {palette.colors.length > 0 ? (+ <div className="grid grid-cols-6 gap-1">+ {palette.colors.map((color, i) => (+ <div key={`${color}-${i}`} className="relative group">+ <button+ onClick={() => onColorSelect(color)}+ className={`w-full aspect-square rounded border transition-all hover:scale-110 ${+ selectedColor?.toLowerCase() === color.toLowerCase()+ ? 'border-primary ring-2 ring-primary/30'+ : 'border-border/50 hover:border-border'+ }`}+ style={{ backgroundColor: color }}+ title={color}+ />+ <button+ onClick={() => removeColorFromPalette(palette.id, color)}+ className="absolute -top-1 -right-1 w-3 h-3 rounded-full bg-destructive text-destructive-foreground opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center"+ >+ <X size={7} />+ </button>+ </div>+ ))}+ </div>+ ) : (+ <p className="text-[9px] text-muted-foreground/60 text-center py-1">+ Empty palette+ </p>+ )}+ </div>+ ))}++ {customPalettes.length === 0 && !showNewPaletteInput && (+ <p className="text-[10px] text-muted-foreground/60 text-center py-2">+ No custom palettes yet+ </p>+ )}+ </div>+ </div>+ </CollapsibleContent>+ </Collapsible>+ );+}diff --git a/apps/image/src/stores/color-store.ts b/apps/image/src/stores/color-store.tsnew file mode 100644index 00000000..210d5a46--- /dev/null+++ b/apps/image/src/stores/color-store.ts@@ -0,0 +1,118 @@+import { create } from 'zustand';+import { persist } from 'zustand/middleware';++export interface CustomPalette {+ id: string;+ name: string;+ colors: string[];+}++interface ColorState {+ recentColors: string[];+ savedColors: string[];+ customPalettes: CustomPalette[];+}++interface ColorActions {+ addRecentColor: (color: string) => void;+ saveColor: (color: string) => void;+ removeSavedColor: (color: string) => void;+ clearSavedColors: () => void;+ createPalette: (name: string, colors?: string[]) => string;+ updatePalette: (id: string, updates: Partial<Omit<CustomPalette, 'id'>>) => void;+ addColorToPalette: (paletteId: string, color: string) => void;+ removeColorFromPalette: (paletteId: string, color: string) => void;+ deletePalette: (id: string) => void;+}++const MAX_RECENT_COLORS = 12;+const MAX_SAVED_COLORS = 24;++const generateId = () => `palette_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;++export const useColorStore = create<ColorState & ColorActions>()(+ persist(+ (set) => ({+ recentColors: [],+ savedColors: [],+ customPalettes: [],++ addRecentColor: (color) => {+ const normalized = color.toLowerCase();+ set((state) => {+ const filtered = state.recentColors.filter((c) => c.toLowerCase() !== normalized);+ return {+ recentColors: [color, ...filtered].slice(0, MAX_RECENT_COLORS),+ };+ });+ },++ saveColor: (color) => {+ const normalized = color.toLowerCase();+ set((state) => {+ if (state.savedColors.some((c) => c.toLowerCase() === normalized)) {+ return state;+ }+ return {+ savedColors: [...state.savedColors, color].slice(-MAX_SAVED_COLORS),+ };+ });+ },++ removeSavedColor: (color) => {+ const normalized = color.toLowerCase();+ set((state) => ({+ savedColors: state.savedColors.filter((c) => c.toLowerCase() !== normalized),+ }));+ },++ clearSavedColors: () => set({ savedColors: [] }),++ createPalette: (name, colors = []) => {+ const id = generateId();+ set((state) => ({+ customPalettes: [...state.customPalettes, { id, name, colors }],+ }));+ return id;+ },++ updatePalette: (id, updates) => {+ set((state) => ({+ customPalettes: state.customPalettes.map((p) =>+ p.id === id ? { ...p, ...updates } : p+ ),+ }));+ },++ addColorToPalette: (paletteId, color) => {+ const normalized = color.toLowerCase();+ set((state) => ({+ customPalettes: state.customPalettes.map((p) => {+ if (p.id !== paletteId) return p;+ if (p.colors.some((c) => c.toLowerCase() === normalized)) return p;+ return { ...p, colors: [...p.colors, color] };+ }),+ }));+ },++ removeColorFromPalette: (paletteId, color) => {+ const normalized = color.toLowerCase();+ set((state) => ({+ customPalettes: state.customPalettes.map((p) => {+ if (p.id !== paletteId) return p;+ return { ...p, colors: p.colors.filter((c) => c.toLowerCase() !== normalized) };+ }),+ }));+ },++ deletePalette: (id) => {+ set((state) => ({+ customPalettes: state.customPalettes.filter((p) => p.id !== id),+ }));+ },+ }),+ {+ name: 'openreel-image-colors',+ }+ )+);diff --git a/apps/image/src/stores/project-store.ts b/apps/image/src/stores/project-store.tsindex 8cc5002a..4023cccc 100644--- a/apps/image/src/stores/project-store.ts+++ b/apps/image/src/stores/project-store.ts@@ -280,6 +280,8 @@ export const useProjectStore = create<ProjectState & ProjectActions>()(glow: DEFAULT_GLOW,filters: DEFAULT_FILTER,parentId: null,+ flipHorizontal: false,+ flipVertical: false,content,style: DEFAULT_TEXT_STYLE,autoSize: true,@@ -322,6 +324,8 @@ export const useProjectStore = create<ProjectState & ProjectActions>()(glow: DEFAULT_GLOW,filters: DEFAULT_FILTER,parentId: null,+ flipHorizontal: false,+ flipVertical: false,shapeType,shapeStyle: DEFAULT_SHAPE_STYLE,};@@ -374,6 +378,8 @@ export const useProjectStore = create<ProjectState & ProjectActions>()(glow: DEFAULT_GLOW,filters: DEFAULT_FILTER,parentId: null,+ flipHorizontal: false,+ flipVertical: false,shapeType: 'path',shapeStyle: {...DEFAULT_SHAPE_STYLE,@@ -414,6 +420,8 @@ export const useProjectStore = create<ProjectState & ProjectActions>()(glow: DEFAULT_GLOW,filters: DEFAULT_FILTER,parentId: null,+ flipHorizontal: false,+ flipVertical: false,childIds,expanded: true,};diff --git a/apps/image/src/types/project.ts b/apps/image/src/types/project.tsindex 2c6c31d3..9dffe8ab 100644--- a/apps/image/src/types/project.ts+++ b/apps/image/src/types/project.ts@@ -8,6 +8,8 @@ export interface Transform {rotation: number;scaleX: number;scaleY: number;+ skewX: number;+ skewY: number;opacity: number;}@@ -76,14 +78,14 @@ export interface BaseLayer {glow: Glow;filters: Filter;parentId: string | null;+ flipHorizontal: boolean;+ flipVertical: boolean;}export interface ImageLayer extends BaseLayer {type: 'image';sourceId: string;cropRect: { x: number; y: number; width: number; height: number } | null;- flipHorizontal: boolean;- flipVertical: boolean;}export type TextFillType = 'solid' | 'gradient';@@ -253,6 +255,8 @@ export const DEFAULT_TRANSFORM: Transform = {rotation: 0,scaleX: 1,scaleY: 1,+ skewX: 0,+ skewY: 0,opacity: 1,};