Skip to content

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 styling, zoom controls, rulers, and export enhancements

Augustus Otu3a627717acd6
diff --git a/apps/image/src/components/editor/ExportDialog.tsx b/apps/image/src/components/editor/ExportDialog.tsx
index 7378bab2..630a92d0 100644
--- a/apps/image/src/components/editor/ExportDialog.tsx
+++ b/apps/image/src/components/editor/ExportDialog.tsx
@@ -1,5 +1,5 @@
-import { useState, useMemo } from 'react';
-import { Download, FileImage, Loader2 } from 'lucide-react';
+import { useState, useMemo, useEffect } from 'react';
+import { Download, FileImage, Loader2, Link2, Link2Off, Printer } from 'lucide-react';
import { Dialog, DialogFooter } from '../ui/Dialog';
import { useProjectStore } from '../../stores/project-store';
import { useUIStore } from '../../stores/ui-store';
@@ -46,6 +46,15 @@ const SCALE_OPTIONS = [
{ value: 4, label: '4x' },
];
+const DPI_OPTIONS = [
+ { value: 72, label: '72 DPI', description: 'Screen' },
+ { value: 150, label: '150 DPI', description: 'Web print' },
+ { value: 300, label: '300 DPI', description: 'Print' },
+ { value: 600, label: '600 DPI', description: 'High quality' },
+];
+
+type SizeMode = 'scale' | 'custom' | 'dpi';
+
export function ExportDialog({ open, onClose }: ExportDialogProps) {
const { project, selectedArtboardId } = useProjectStore();
const { showNotification } = useUIStore();
@@ -53,6 +62,11 @@ export function ExportDialog({ open, onClose }: ExportDialogProps) {
const [format, setFormat] = useState<ExportFormat>('png');
const [quality, setQuality] = useState<ExportQuality>('high');
const [scale, setScale] = useState(1);
+ const [sizeMode, setSizeMode] = useState<SizeMode>('scale');
+ const [customWidth, setCustomWidth] = useState(0);
+ const [customHeight, setCustomHeight] = useState(0);
+ const [dpi, setDpi] = useState(72);
+ const [lockAspectRatio, setLockAspectRatio] = useState(true);
const [background, setBackground] = useState<'include' | 'transparent'>('include');
const [exportAll, setExportAll] = useState(false);
const [isExporting, setIsExporting] = useState(false);
@@ -62,13 +76,64 @@ export function ExportDialog({ open, onClose }: ExportDialogProps) {
const currentFormat = FORMATS.find((f) => f.id === format)!;
const artboard = project?.artboards.find((a) => a.id === selectedArtboardId);
+ const effectiveScale = useMemo(() => {
+ if (!artboard) return 1;
+ if (sizeMode === 'scale') return scale;
+ if (sizeMode === 'custom' && customWidth > 0) {
+ return customWidth / artboard.size.width;
+ }
+ if (sizeMode === 'dpi') {
+ return dpi / 72;
+ }
+ return 1;
+ }, [artboard, sizeMode, scale, customWidth, dpi]);
+
const dimensions = useMemo(() => {
if (!artboard) return null;
+ if (sizeMode === 'custom') {
+ return { width: customWidth || artboard.size.width, height: customHeight || artboard.size.height };
+ }
return {
- width: Math.round(artboard.size.width * scale),
- height: Math.round(artboard.size.height * scale),
+ width: Math.round(artboard.size.width * effectiveScale),
+ height: Math.round(artboard.size.height * effectiveScale),
};
- }, [artboard, scale]);
+ }, [artboard, sizeMode, effectiveScale, customWidth, customHeight]);
+
+ useEffect(() => {
+ if (artboard && customWidth === 0 && customHeight === 0) {
+ setCustomWidth(artboard.size.width);
+ setCustomHeight(artboard.size.height);
+ }
+ }, [artboard, customWidth, customHeight]);
+
+ const handleCustomWidthChange = (newWidth: number) => {
+ setCustomWidth(newWidth);
+ if (lockAspectRatio && artboard && newWidth > 0) {
+ const aspectRatio = artboard.size.width / artboard.size.height;
+ setCustomHeight(Math.round(newWidth / aspectRatio));
+ }
+ };
+
+ const handleCustomHeightChange = (newHeight: number) => {
+ setCustomHeight(newHeight);
+ if (lockAspectRatio && artboard && newHeight > 0) {
+ const aspectRatio = artboard.size.width / artboard.size.height;
+ setCustomWidth(Math.round(newHeight * aspectRatio));
+ }
+ };
+
+ const printDimensions = useMemo(() => {
+ if (!dimensions) return null;
+ const inches = {
+ width: (dimensions.width / dpi).toFixed(2),
+ height: (dimensions.height / dpi).toFixed(2),
+ };
+ const cm = {
+ width: ((dimensions.width / dpi) * 2.54).toFixed(2),
+ height: ((dimensions.height / dpi) * 2.54).toFixed(2),
+ };
+ return { inches, cm };
+ }, [dimensions, dpi]);
const estimatedSize = useMemo(() => {
if (!dimensions) return null;
@@ -93,7 +158,7 @@ export function ExportDialog({ open, onClose }: ExportDialogProps) {
const options: ExportOptions = {
format,
quality,
- scale,
+ scale: effectiveScale,
background: currentFormat.supportsTransparency ? background : 'include',
artboardIds: exportAll ? undefined : selectedArtboardId ? [selectedArtboardId] : undefined,
};
@@ -185,23 +250,124 @@ export function ExportDialog({ open, onClose }: ExportDialogProps) {
<div>
<label className="block text-xs font-medium text-muted-foreground uppercase tracking-wide mb-3">
- Scale
+ Size
</label>
- <div className="flex gap-2">
- {SCALE_OPTIONS.map((s) => (
+ <div className="flex gap-2 mb-3">
+ <button
+ onClick={() => setSizeMode('scale')}
+ className={`flex-1 px-3 py-2 rounded-lg border text-center text-sm font-medium transition-all ${
+ sizeMode === 'scale'
+ ? 'border-primary bg-primary/5 ring-1 ring-primary'
+ : 'border-border hover:border-muted-foreground/50 hover:bg-secondary/50'
+ }`}
+ >
+ Scale
+ </button>
+ <button
+ onClick={() => setSizeMode('custom')}
+ className={`flex-1 px-3 py-2 rounded-lg border text-center text-sm font-medium transition-all ${
+ sizeMode === 'custom'
+ ? 'border-primary bg-primary/5 ring-1 ring-primary'
+ : 'border-border hover:border-muted-foreground/50 hover:bg-secondary/50'
+ }`}
+ >
+ Custom
+ </button>
+ <button
+ onClick={() => setSizeMode('dpi')}
+ className={`flex-1 px-3 py-2 rounded-lg border text-center text-sm font-medium transition-all flex items-center justify-center gap-1.5 ${
+ sizeMode === 'dpi'
+ ? 'border-primary bg-primary/5 ring-1 ring-primary'
+ : 'border-border hover:border-muted-foreground/50 hover:bg-secondary/50'
+ }`}
+ >
+ <Printer size={14} />
+ Print
+ </button>
+ </div>
+
+ {sizeMode === 'scale' && (
+ <div className="flex gap-2">
+ {SCALE_OPTIONS.map((s) => (
+ <button
+ key={s.value}
+ onClick={() => setScale(s.value)}
+ className={`flex-1 px-3 py-2 rounded-lg border text-center text-sm font-medium transition-all ${
+ scale === s.value
+ ? 'border-primary bg-primary/5 ring-1 ring-primary'
+ : 'border-border hover:border-muted-foreground/50 hover:bg-secondary/50'
+ }`}
+ >
+ {s.label}
+ </button>
+ ))}
+ </div>
+ )}
+
+ {sizeMode === 'custom' && (
+ <div className="flex items-center gap-2">
+ <div className="flex-1">
+ <label className="block text-[10px] text-muted-foreground mb-1">Width (px)</label>
+ <input
+ type="number"
+ value={customWidth}
+ onChange={(e) => handleCustomWidthChange(Number(e.target.value))}
+ className="w-full px-3 py-2 text-sm bg-background border border-border rounded-lg focus:outline-none focus:ring-1 focus:ring-primary"
+ min={1}
+ max={16384}
+ />
+ </div>
<button
- key={s.value}
- onClick={() => setScale(s.value)}
- className={`flex-1 px-3 py-2 rounded-lg border text-center text-sm font-medium transition-all ${
- scale === s.value
- ? 'border-primary bg-primary/5 ring-1 ring-primary'
- : 'border-border hover:border-muted-foreground/50 hover:bg-secondary/50'
+ onClick={() => setLockAspectRatio(!lockAspectRatio)}
+ className={`mt-5 p-2 rounded-lg transition-colors ${
+ lockAspectRatio ? 'bg-primary text-primary-foreground' : 'bg-secondary text-muted-foreground hover:text-foreground'
}`}
+ title={lockAspectRatio ? 'Unlock aspect ratio' : 'Lock aspect ratio'}
>
- {s.label}
+ {lockAspectRatio ? <Link2 size={16} /> : <Link2Off size={16} />}
</button>
- ))}
- </div>
+ <div className="flex-1">
+ <label className="block text-[10px] text-muted-foreground mb-1">Height (px)</label>
+ <input
+ type="number"
+ value={customHeight}
+ onChange={(e) => handleCustomHeightChange(Number(e.target.value))}
+ className="w-full px-3 py-2 text-sm bg-background border border-border rounded-lg focus:outline-none focus:ring-1 focus:ring-primary"
+ min={1}
+ max={16384}
+ />
+ </div>
+ </div>
+ )}
+
+ {sizeMode === 'dpi' && (
+ <div className="space-y-3">
+ <div className="grid grid-cols-4 gap-2">
+ {DPI_OPTIONS.map((d) => (
+ <button
+ key={d.value}
+ onClick={() => setDpi(d.value)}
+ className={`px-2 py-2 rounded-lg border text-center transition-all ${
+ dpi === d.value
+ ? 'border-primary bg-primary/5 ring-1 ring-primary'
+ : 'border-border hover:border-muted-foreground/50 hover:bg-secondary/50'
+ }`}
+ >
+ <span className="block text-sm font-medium">{d.value}</span>
+ <span className="block text-[9px] text-muted-foreground">{d.description}</span>
+ </button>
+ ))}
+ </div>
+ {printDimensions && (
+ <div className="p-3 bg-secondary/30 rounded-lg text-xs text-muted-foreground">
+ <p>Print size at {dpi} DPI:</p>
+ <p className="font-medium text-foreground mt-1">
+ {printDimensions.inches.width}" × {printDimensions.inches.height}" ({printDimensions.cm.width} × {printDimensions.cm.height} cm)
+ </p>
+ </div>
+ )}
+ </div>
+ )}
</div>
{currentFormat.supportsTransparency && (
diff --git a/apps/image/src/components/editor/canvas/Canvas.tsx b/apps/image/src/components/editor/canvas/Canvas.tsx
index 7faca451..8bdccfa7 100644
--- a/apps/image/src/components/editor/canvas/Canvas.tsx
+++ b/apps/image/src/components/editor/canvas/Canvas.tsx
@@ -1,16 +1,20 @@
-import { useEffect, useRef, useCallback } from 'react';
+import { useEffect, useRef, useCallback, useState } from 'react';
import { useProjectStore } from '../../../stores/project-store';
import { useUIStore } from '../../../stores/ui-store';
import { useCanvasStore } from '../../../stores/canvas-store';
import { calculateSnap } from '../../../utils/snapping';
import type { Layer, ImageLayer, TextLayer, ShapeLayer } from '../../../types/project';
+import { Rulers } from './Rulers';
+
+const RULER_SIZE = 20;
export function Canvas() {
const containerRef = useRef<HTMLDivElement>(null);
const canvasRef = useRef<HTMLCanvasElement>(null);
+ const [containerSize, setContainerSize] = useState({ width: 0, height: 0 });
const { project, selectedLayerIds, selectedArtboardId, updateLayerTransform, selectLayer, deselectAllLayers, addPathLayer } = useProjectStore();
- const { zoom, panX, panY, setPan, activeTool, showGrid, gridSize, crop, snapToObjects, snapToGuides, snapToGrid, penSettings, drawing, startDrawing, addDrawingPoint, finishDrawing } = useUIStore();
+ 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 artboard = project?.artboards.find((a) => a.id === selectedArtboardId);
@@ -263,8 +267,17 @@ export function Canvas() {
}, [render]);
useEffect(() => {
- const handleResize = () => render();
+ const handleResize = () => {
+ render();
+ if (containerRef.current) {
+ setContainerSize({
+ width: containerRef.current.clientWidth,
+ height: containerRef.current.clientHeight,
+ });
+ }
+ };
window.addEventListener('resize', handleResize);
+ handleResize();
return () => window.removeEventListener('resize', handleResize);
}, [render]);
@@ -437,11 +450,17 @@ export function Canvas() {
return (
<div
ref={containerRef}
- className="flex-1 overflow-hidden cursor-crosshair"
+ className="flex-1 overflow-hidden cursor-crosshair relative"
style={{
cursor: activeTool === 'hand' ? 'grab' : activeTool === 'select' ? 'default' : 'crosshair',
}}
>
+ {showRulers && (
+ <Rulers
+ containerWidth={containerSize.width}
+ containerHeight={containerSize.height}
+ />
+ )}
<canvas
ref={canvasRef}
onMouseDown={handleMouseDown}
@@ -449,7 +468,13 @@ export function Canvas() {
onMouseUp={handleMouseUp}
onMouseLeave={handleMouseUp}
onWheel={handleWheel}
- className="w-full h-full"
+ className="absolute"
+ style={{
+ top: showRulers ? RULER_SIZE : 0,
+ left: showRulers ? RULER_SIZE : 0,
+ width: showRulers ? `calc(100% - ${RULER_SIZE}px)` : '100%',
+ height: showRulers ? `calc(100% - ${RULER_SIZE}px)` : '100%',
+ }}
/>
</div>
);
@@ -595,7 +620,6 @@ function renderImageLayer(
function renderTextLayer(ctx: CanvasRenderingContext2D, layer: TextLayer) {
const { style, content, transform } = layer;
- ctx.fillStyle = style.color;
ctx.font = `${style.fontStyle} ${style.fontWeight} ${style.fontSize}px ${style.fontFamily}`;
ctx.textAlign = style.textAlign as CanvasTextAlign;
ctx.textBaseline = 'top';
@@ -607,8 +631,48 @@ function renderTextLayer(ctx: CanvasRenderingContext2D, layer: TextLayer) {
if (style.textAlign === 'center') textX = transform.width / 2;
else if (style.textAlign === 'right') textX = transform.width;
+ if (style.backgroundColor) {
+ const padding = style.backgroundPadding ?? 8;
+ const radius = style.backgroundRadius ?? 4;
+ const textWidth = Math.max(...lines.map((line) => ctx.measureText(line).width));
+ const textHeight = lines.length * lineHeight;
+
+ let bgX = -padding;
+ if (style.textAlign === 'center') bgX = (transform.width - textWidth) / 2 - padding;
+ else if (style.textAlign === 'right') bgX = transform.width - textWidth - padding;
+
+ ctx.fillStyle = style.backgroundColor;
+ ctx.beginPath();
+ const bgW = textWidth + padding * 2;
+ const bgH = textHeight + padding * 2;
+ const bgY = -padding;
+ const r = Math.min(radius, bgW / 2, bgH / 2);
+ ctx.moveTo(bgX + r, bgY);
+ ctx.lineTo(bgX + bgW - r, bgY);
+ ctx.quadraticCurveTo(bgX + bgW, bgY, bgX + bgW, bgY + r);
+ ctx.lineTo(bgX + bgW, bgY + bgH - r);
+ ctx.quadraticCurveTo(bgX + bgW, bgY + bgH, bgX + bgW - r, bgY + bgH);
+ ctx.lineTo(bgX + r, bgY + bgH);
+ ctx.quadraticCurveTo(bgX, bgY + bgH, bgX, bgY + bgH - r);
+ ctx.lineTo(bgX, bgY + r);
+ ctx.quadraticCurveTo(bgX, bgY, bgX + r, bgY);
+ ctx.closePath();
+ ctx.fill();
+ }
+
lines.forEach((line, i) => {
- ctx.fillText(line, textX, i * lineHeight);
+ const y = i * lineHeight;
+
+ if (style.strokeColor && (style.strokeWidth ?? 0) > 0) {
+ ctx.strokeStyle = style.strokeColor;
+ ctx.lineWidth = style.strokeWidth ?? 1;
+ ctx.lineJoin = 'round';
+ ctx.miterLimit = 2;
+ ctx.strokeText(line, textX, y);
+ }
+
+ ctx.fillStyle = style.color;
+ ctx.fillText(line, textX, y);
});
}
diff --git a/apps/image/src/components/editor/canvas/Rulers.tsx b/apps/image/src/components/editor/canvas/Rulers.tsx
new file mode 100644
index 00000000..c06ba8a8
--- /dev/null
+++ b/apps/image/src/components/editor/canvas/Rulers.tsx
@@ -0,0 +1,205 @@
+import { useEffect, useRef } from 'react';
+import { useUIStore } from '../../../stores/ui-store';
+import { useProjectStore } from '../../../stores/project-store';
+
+const RULER_SIZE = 20;
+const RULER_BG = '#1f1f23';
+const RULER_TEXT = '#71717a';
+const RULER_TICK = '#3f3f46';
+const RULER_HIGHLIGHT = '#3b82f6';
+
+interface RulersProps {
+ containerWidth: number;
+ containerHeight: number;
+}
+
+export function Rulers({ containerWidth, containerHeight }: RulersProps) {
+ const horizontalRef = useRef<HTMLCanvasElement>(null);
+ const verticalRef = useRef<HTMLCanvasElement>(null);
+ const cornerRef = useRef<HTMLDivElement>(null);
+
+ const { zoom, panX, panY, showRulers } = useUIStore();
+ const { project, selectedArtboardId } = useProjectStore();
+
+ const artboard = project?.artboards.find((a) => a.id === selectedArtboardId);
+
+ useEffect(() => {
+ if (!showRulers || !artboard) return;
+
+ const hCanvas = horizontalRef.current;
+ const vCanvas = verticalRef.current;
+ if (!hCanvas || !vCanvas) return;
+
+ const hCtx = hCanvas.getContext('2d');
+ const vCtx = vCanvas.getContext('2d');
+ if (!hCtx || !vCtx) return;
+
+ hCanvas.width = containerWidth;
+ hCanvas.height = RULER_SIZE;
+ vCanvas.width = RULER_SIZE;
+ vCanvas.height = containerHeight;
+
+ const centerX = containerWidth / 2 + panX;
+ const centerY = containerHeight / 2 + panY;
+ const artboardX = centerX - (artboard.size.width * zoom) / 2;
+ const artboardY = centerY - (artboard.size.height * zoom) / 2;
+
+ renderHorizontalRuler(hCtx, containerWidth, artboardX, artboard.size.width, zoom);
+ renderVerticalRuler(vCtx, containerHeight, artboardY, artboard.size.height, zoom);
+ }, [containerWidth, containerHeight, zoom, panX, panY, showRulers, artboard]);
+
+ if (!showRulers) return null;
+
+ return (
+ <>
+ <div
+ ref={cornerRef}
+ className="absolute top-0 left-0 z-20"
+ style={{
+ width: RULER_SIZE,
+ height: RULER_SIZE,
+ backgroundColor: RULER_BG,
+ borderRight: `1px solid ${RULER_TICK}`,
+ borderBottom: `1px solid ${RULER_TICK}`,
+ }}
+ />
+ <canvas
+ ref={horizontalRef}
+ className="absolute top-0 z-10"
+ style={{
+ left: RULER_SIZE,
+ width: containerWidth - RULER_SIZE,
+ height: RULER_SIZE,
+ backgroundColor: RULER_BG,
+ }}
+ />
+ <canvas
+ ref={verticalRef}
+ className="absolute left-0 z-10"
+ style={{
+ top: RULER_SIZE,
+ width: RULER_SIZE,
+ height: containerHeight - RULER_SIZE,
+ backgroundColor: RULER_BG,
+ }}
+ />
+ </>
+ );
+}
+
+function getTickInterval(zoom: number): { major: number; minor: number } {
+ const baseUnit = 100;
+ const scaledUnit = baseUnit / zoom;
+
+ if (scaledUnit < 50) return { major: 50, minor: 10 };
+ if (scaledUnit < 100) return { major: 100, minor: 20 };
+ if (scaledUnit < 200) return { major: 100, minor: 25 };
+ if (scaledUnit < 500) return { major: 200, minor: 50 };
+ if (scaledUnit < 1000) return { major: 500, minor: 100 };
+ return { major: 1000, minor: 200 };
+}
+
+function renderHorizontalRuler(
+ ctx: CanvasRenderingContext2D,
+ width: number,
+ artboardX: number,
+ artboardWidth: number,
+ zoom: number
+) {
+ ctx.fillStyle = RULER_BG;
+ ctx.fillRect(0, 0, width, RULER_SIZE);
+
+ const { major, minor } = getTickInterval(zoom);
+
+ ctx.strokeStyle = RULER_TICK;
+ ctx.fillStyle = RULER_TEXT;
+ ctx.font = '9px Inter, system-ui, sans-serif';
+ ctx.textAlign = 'center';
+ ctx.textBaseline = 'top';
+
+ const startX = -Math.ceil(artboardX / (minor * zoom)) * minor;
+ const endX = artboardWidth + Math.ceil((width - artboardX - artboardWidth * zoom) / (minor * zoom)) * minor;
+
+ for (let i = startX; i <= endX; i += minor) {
+ const screenX = artboardX + i * zoom - RULER_SIZE;
+ if (screenX < 0 || screenX > width) continue;
+
+ const isMajor = i % major === 0;
+ const tickHeight = isMajor ? 12 : 6;
+
+ ctx.beginPath();
+ ctx.moveTo(screenX, RULER_SIZE);
+ ctx.lineTo(screenX, RULER_SIZE - tickHeight);
+ ctx.stroke();
+
+ if (isMajor) {
+ ctx.fillText(String(i), screenX, 2);
+ }
+ }
+
+ const artboardStart = artboardX - RULER_SIZE;
+ const artboardEnd = artboardX + artboardWidth * zoom - RULER_SIZE;
+
+ ctx.strokeStyle = RULER_HIGHLIGHT;
+ ctx.lineWidth = 2;
+ ctx.beginPath();
+ ctx.moveTo(Math.max(0, artboardStart), RULER_SIZE - 1);
+ ctx.lineTo(Math.min(width, artboardEnd), RULER_SIZE - 1);
+ ctx.stroke();
+ ctx.lineWidth = 1;
+}
+
+function renderVerticalRuler(
+ ctx: CanvasRenderingContext2D,
+ height: number,
+ artboardY: number,
+ artboardHeight: number,
+ zoom: number
+) {
+ ctx.fillStyle = RULER_BG;
+ ctx.fillRect(0, 0, RULER_SIZE, height);
+
+ const { major, minor } = getTickInterval(zoom);
+
+ ctx.strokeStyle = RULER_TICK;
+ ctx.fillStyle = RULER_TEXT;
+ ctx.font = '9px Inter, system-ui, sans-serif';
+ ctx.textAlign = 'right';
+ ctx.textBaseline = 'middle';
+
+ const startY = -Math.ceil(artboardY / (minor * zoom)) * minor;
+ const endY = artboardHeight + Math.ceil((height - artboardY - artboardHeight * zoom) / (minor * zoom)) * minor;
+
+ for (let i = startY; i <= endY; i += minor) {
+ const screenY = artboardY + i * zoom - RULER_SIZE;
+ if (screenY < 0 || screenY > height) continue;
+
+ const isMajor = i % major === 0;
+ const tickWidth = isMajor ? 12 : 6;
+
+ ctx.beginPath();
+ ctx.moveTo(RULER_SIZE, screenY);
+ ctx.lineTo(RULER_SIZE - tickWidth, screenY);
+ ctx.stroke();
+
+ if (isMajor) {
+ ctx.save();
+ ctx.translate(10, screenY);
+ ctx.rotate(-Math.PI / 2);
+ ctx.textAlign = 'center';
+ ctx.fillText(String(i), 0, 0);
+ ctx.restore();
+ }
+ }
+
+ const artboardStart = artboardY - RULER_SIZE;
+ const artboardEnd = artboardY + artboardHeight * zoom - RULER_SIZE;
+
+ ctx.strokeStyle = RULER_HIGHLIGHT;
+ ctx.lineWidth = 2;
+ ctx.beginPath();
+ ctx.moveTo(RULER_SIZE - 1, Math.max(0, artboardStart));
+ ctx.lineTo(RULER_SIZE - 1, Math.min(height, artboardEnd));
+ ctx.stroke();
+ ctx.lineWidth = 1;
+}
diff --git a/apps/image/src/components/editor/inspector/TextSection.tsx b/apps/image/src/components/editor/inspector/TextSection.tsx
index 6b9cdd72..160120be 100644
--- a/apps/image/src/components/editor/inspector/TextSection.tsx
+++ b/apps/image/src/components/editor/inspector/TextSection.tsx
@@ -1,7 +1,8 @@
import { useProjectStore } from '../../../stores/project-store';
import type { TextLayer, TextStyle } from '../../../types/project';
-import { AlignLeft, AlignCenter, AlignRight, Bold, Italic, Underline, CaseUpper, CaseLower, CaseSensitive } from 'lucide-react';
+import { AlignLeft, AlignCenter, AlignRight, Bold, Italic, Underline, CaseUpper, CaseLower, CaseSensitive, Strikethrough } from 'lucide-react';
import { FontPicker } from '../../ui/FontPicker';
+import { Slider } from '@openreel/ui';
interface Props {
layer: TextLayer;
@@ -40,6 +41,12 @@ export function TextSection({ layer }: Props) {
});
};
+ const toggleStrikethrough = () => {
+ handleStyleChange({
+ textDecoration: layer.style.textDecoration === 'line-through' ? 'none' : 'line-through',
+ });
+ };
+
const transformToUppercase = () => {
handleContentChange(layer.content.toUpperCase());
};
@@ -144,6 +151,17 @@ export function TextSection({ layer }: Props) {
>
<Underline size={14} />
</button>
+ <button
+ onClick={toggleStrikethrough}
+ className={`p-2 rounded-md transition-colors ${
+ layer.style.textDecoration === 'line-through'
+ ? 'bg-primary text-primary-foreground'
+ : 'bg-secondary text-secondary-foreground hover:bg-accent'
+ }`}
+ title="Strikethrough"
+ >
+ <Strikethrough size={14} />
+ </button>
<div className="w-px bg-border mx-1" />
@@ -248,6 +266,115 @@ export function TextSection({ layer }: Props) {
/>
</div>
</div>
+
+ <div className="space-y-2 p-3 bg-secondary/50 rounded-lg">
+ <div className="flex items-center justify-between">
+ <label className="text-xs font-medium">Text Stroke</label>
+ <button
+ onClick={() => handleStyleChange({ strokeColor: layer.style.strokeColor ? null : '#000000', strokeWidth: layer.style.strokeColor ? 0 : 2 })}
+ className={`px-2 py-1 text-[10px] rounded-md transition-colors ${
+ layer.style.strokeColor
+ ? 'bg-primary text-primary-foreground'
+ : 'bg-secondary text-secondary-foreground hover:bg-accent'
+ }`}
+ >
+ {layer.style.strokeColor ? 'On' : 'Off'}
+ </button>
+ </div>
+ {layer.style.strokeColor && (
+ <div className="space-y-2">
+ <div className="flex items-center gap-2">
+ <input
+ type="color"
+ value={layer.style.strokeColor}
+ onChange={(e) => handleStyleChange({ strokeColor: e.target.value })}
+ className="w-8 h-8 rounded border border-input cursor-pointer"
+ />
+ <input
+ type="text"
+ value={layer.style.strokeColor}
+ onChange={(e) => handleStyleChange({ strokeColor: 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 font-mono"
+ />
+ </div>
+ <div>
+ <div className="flex items-center justify-between mb-1">
+ <label className="text-[10px] text-muted-foreground">Width</label>
+ <span className="text-[10px] text-muted-foreground">{layer.style.strokeWidth ?? 0}px</span>
+ </div>
+ <Slider
+ value={[layer.style.strokeWidth ?? 0]}
+ onValueChange={([width]) => handleStyleChange({ strokeWidth: width })}
+ min={0}
+ max={10}
+ step={0.5}
+ />
+ </div>
+ </div>
+ )}
+ </div>
+
+ <div className="space-y-2 p-3 bg-secondary/50 rounded-lg">
+ <div className="flex items-center justify-between">
+ <label className="text-xs font-medium">Background</label>
+ <button
+ onClick={() => handleStyleChange({ backgroundColor: layer.style.backgroundColor ? null : '#000000' })}
+ className={`px-2 py-1 text-[10px] rounded-md transition-colors ${
+ layer.style.backgroundColor
+ ? 'bg-primary text-primary-foreground'
+ : 'bg-secondary text-secondary-foreground hover:bg-accent'
+ }`}
+ >
+ {layer.style.backgroundColor ? 'On' : 'Off'}
+ </button>
+ </div>
+ {layer.style.backgroundColor && (
+ <div className="space-y-2">
+ <div className="flex items-center gap-2">
+ <input
+ type="color"
+ value={layer.style.backgroundColor}
+ onChange={(e) => handleStyleChange({ backgroundColor: e.target.value })}
+ className="w-8 h-8 rounded border border-input cursor-pointer"
+ />
+ <input
+ type="text"
+ value={layer.style.backgroundColor}
+ onChange={(e) => handleStyleChange({ backgroundColor: 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 font-mono"
+ />
+ </div>
+ <div className="grid grid-cols-2 gap-2">
+ <div>
+ <div className="flex items-center justify-between mb-1">
+ <label className="text-[10px] text-muted-foreground">Padding</label>
+ <span className="text-[10px] text-muted-foreground">{layer.style.backgroundPadding ?? 8}px</span>
+ </div>
+ <Slider
+ value={[layer.style.backgroundPadding ?? 8]}
+ onValueChange={([padding]) => handleStyleChange({ backgroundPadding: padding })}
+ min={0}
+ max={32}
+ step={1}
+ />
+ </div>
+ <div>
+ <div className="flex items-center justify-between mb-1">
+ <label className="text-[10px] text-muted-foreground">Radius</label>
+ <span className="text-[10px] text-muted-foreground">{layer.style.backgroundRadius ?? 4}px</span>
+ </div>
+ <Slider
+ value={[layer.style.backgroundRadius ?? 4]}
+ onValueChange={([radius]) => handleStyleChange({ backgroundRadius: radius })}
+ min={0}
+ max={32}
+ step={1}
+ />
+ </div>
+ </div>
+ </div>
+ )}
+ </div>
</div>
);
}
diff --git a/apps/image/src/components/editor/toolbar/Toolbar.tsx b/apps/image/src/components/editor/toolbar/Toolbar.tsx
index 9a332304..b5fde7e4 100644
--- a/apps/image/src/components/editor/toolbar/Toolbar.tsx
+++ b/apps/image/src/components/editor/toolbar/Toolbar.tsx
@@ -17,6 +17,7 @@ import {
import { useUIStore, Tool } from '../../../stores/ui-store';
import { useProjectStore } from '../../../stores/project-store';
import { useHistoryStore } from '../../../stores/history-store';
+import { ZoomControl } from './ZoomControl';
const tools: { id: Tool; icon: React.ElementType; label: string; shortcut: string }[] = [
{ id: 'select', icon: MousePointer2, label: 'Select', shortcut: 'V' },
@@ -32,9 +33,6 @@ export function Toolbar() {
const {
activeTool,
setActiveTool,
- zoom,
- zoomIn,
- zoomOut,
togglePanelCollapsed,
toggleInspectorCollapsed,
setCurrentView,
@@ -135,25 +133,7 @@ export function Toolbar() {
<div className="w-px h-6 bg-border mx-1" />
- <div className="flex items-center gap-2">
- <button
- onClick={zoomOut}
- className="p-1.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors"
- title="Zoom out"
- >
- <span className="text-xs font-medium">-</span>
- </button>
- <span className="text-xs font-medium text-muted-foreground w-12 text-center">
- {Math.round(zoom * 100)}%
- </span>
- <button
- onClick={zoomIn}
- className="p-1.5 rounded text-muted-foreground hover:text-foreground hover:bg-accent transition-colors"
- title="Zoom in"
- >
- <span className="text-xs font-medium">+</span>
- </button>
- </div>
+ <ZoomControl />
<div className="w-px h-6 bg-border mx-1" />
diff --git a/apps/image/src/components/editor/toolbar/ZoomControl.tsx b/apps/image/src/components/editor/toolbar/ZoomControl.tsx
new file mode 100644
index 00000000..c73f9596
--- /dev/null
+++ b/apps/image/src/components/editor/toolbar/ZoomControl.tsx
@@ -0,0 +1,135 @@
+import { ChevronDown, Minus, Plus, Maximize2 } from 'lucide-react';
+import {
+ DropdownMenu,
+ DropdownMenuContent,
+ DropdownMenuItem,
+ DropdownMenuSeparator,
+ DropdownMenuTrigger,
+ Slider,
+} from '@openreel/ui';
+import { useUIStore } from '../../../stores/ui-store';
+import { useProjectStore } from '../../../stores/project-store';
+
+const ZOOM_PRESETS = [
+ { label: '25%', value: 0.25 },
+ { label: '50%', value: 0.5 },
+ { label: '75%', value: 0.75 },
+ { label: '100%', value: 1 },
+ { label: '150%', value: 1.5 },
+ { label: '200%', value: 2 },
+ { label: '400%', value: 4 },
+];
+
+export function ZoomControl() {
+ const { zoom, setZoom, zoomIn, zoomOut, resetView } = useUIStore();
+ const { project } = useProjectStore();
+
+ const handleZoomToFit = () => {
+ const artboard = project?.artboards.find((a) => a.id === project.activeArtboardId);
+ if (!artboard) {
+ resetView();
+ return;
+ }
+
+ const viewportWidth = window.innerWidth - 600;
+ const viewportHeight = window.innerHeight - 200;
+
+ const fitZoom = Math.min(
+ viewportWidth / artboard.size.width,
+ viewportHeight / artboard.size.height,
+ 1
+ );
+
+ setZoom(Math.max(0.1, Math.min(fitZoom * 0.9, 1)));
+ };
+
+ const handleZoomToFill = () => {
+ const artboard = project?.artboards.find((a) => a.id === project.activeArtboardId);
+ if (!artboard) {
+ resetView();
+ return;
+ }
+
+ const viewportWidth = window.innerWidth - 600;
+ const viewportHeight = window.innerHeight - 200;
+
+ const fillZoom = Math.max(
+ viewportWidth / artboard.size.width,
+ viewportHeight / artboard.size.height
+ );
+
+ setZoom(Math.min(fillZoom * 0.9, 4));
+ };
+
+ const handleSliderChange = (values: number[]) => {
+ const logValue = values[0];
+ const zoom = Math.pow(10, logValue);
+ setZoom(zoom);
+ };
+
+ const logZoom = Math.log10(zoom);
+
+ return (
+ <div className="flex items-center gap-1">
+ <button
+ onClick={zoomOut}
+ className="p-1.5 rounded-md text-muted-foreground hover:text-foreground hover:bg-accent transition-colors"
+ title="Zoom out (-)"
+ >
+ <Minus size={14} />
+ </button>
+
+ <div className="w-20 px-1">
+ <Slider
+ value={[logZoom]}
+ onValueChange={handleSliderChange}
+ min={Math.log10(0.1)}
+ max={Math.log10(8)}
+ step={0.01}
+ className="[&_[role=slider]]:h-3 [&_[role=slider]]:w-3"
+ />
+ </div>
+
+ <button
+ onClick={zoomIn}
+ className="p-1.5 rounded-md text-muted-foreground hover:text-foreground hover:bg-accent transition-colors"
+ title="Zoom in (+)"
+ >
+ <Plus size={14} />
+ </button>
+
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <button className="flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium text-muted-foreground hover:text-foreground hover:bg-accent transition-colors min-w-[52px] justify-center">
+ {Math.round(zoom * 100)}%
+ <ChevronDown size={12} />
+ </button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="center" className="min-w-[120px]">
+ {ZOOM_PRESETS.map((preset) => (
+ <DropdownMenuItem
+ key={preset.value}
+ onClick={() => setZoom(preset.value)}
+ className={zoom === preset.value ? 'bg-accent' : ''}
+ >
+ {preset.label}
+ </DropdownMenuItem>
+ ))}
+ <DropdownMenuSeparator />
+ <DropdownMenuItem onClick={handleZoomToFit}>
+ <Maximize2 size={14} className="mr-2" />
+ Fit to Canvas
+ </DropdownMenuItem>
+ <DropdownMenuItem onClick={handleZoomToFill}>
+ <Maximize2 size={14} className="mr-2" />
+ Fill View
+ </DropdownMenuItem>
+ <DropdownMenuSeparator />
+ <DropdownMenuItem onClick={resetView}>
+ Reset (100%)
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </div>
+ );
+}
diff --git a/apps/image/src/types/project.ts b/apps/image/src/types/project.ts
index 9abd6a1a..af52f535 100644
--- a/apps/image/src/types/project.ts
+++ b/apps/image/src/types/project.ts
@@ -88,7 +88,11 @@ export interface TextStyle {
lineHeight: number;
letterSpacing: number;
color: string;
+ strokeColor: string | null;
+ strokeWidth: number;
backgroundColor: string | null;
+ backgroundPadding: number;
+ backgroundRadius: number;
}
export interface TextLayer extends BaseLayer {
@@ -265,7 +269,11 @@ export const DEFAULT_TEXT_STYLE: TextStyle = {
lineHeight: 1.4,
letterSpacing: 0,
color: '#ffffff',
+ strokeColor: null,
+ strokeWidth: 0,
backgroundColor: null,
+ backgroundPadding: 8,
+ backgroundRadius: 4,
};
export const DEFAULT_SHAPE_STYLE: ShapeStyle = {