OpenReel Video - Professional browser-based video editor. Open source CapCut alternative. 100% browser-based, no installation, no cloud uploads, no watermarks.
TypeScript
feat(image): integrate Phase 4-6 adjustments into editor
Augustus Otufd72d01cbdc2
diff --git a/apps/image/src/components/editor/canvas/Canvas.tsx b/apps/image/src/components/editor/canvas/Canvas.tsxindex 63de1ca8..443070f1 100644--- a/apps/image/src/components/editor/canvas/Canvas.tsx+++ b/apps/image/src/components/editor/canvas/Canvas.tsx@@ -6,6 +6,7 @@ import { calculateSnap } from '../../../utils/snapping';import type { Layer, ImageLayer, TextLayer, ShapeLayer, GroupLayer } from '../../../types/project';import { Rulers } from './Rulers';import { ContextMenu, type ContextMenuPosition, type ContextMenuType } from './ContextMenu';+import { hasActiveAdjustments, applyAllAdjustments, type LayerAdjustments } from '../../../utils/apply-adjustments';const RULER_SIZE = 20;const HANDLE_SIZE = 8;@@ -1691,6 +1692,21 @@ function renderImageLayerInternal(const flipH = layer.flipHorizontal ?? false;const flipV = layer.flipVertical ?? false;+ const adjustments: LayerAdjustments = {+ levels: layer.levels,+ curves: layer.curves,+ colorBalance: layer.colorBalance,+ selectiveColor: layer.selectiveColor,+ blackWhite: layer.blackWhite,+ photoFilter: layer.photoFilter,+ channelMixer: layer.channelMixer,+ gradientMap: layer.gradientMap,+ posterize: layer.posterize,+ threshold: layer.threshold,+ };++ const needsAdjustments = hasActiveAdjustments(adjustments);+if (flipH || flipV) {ctx.save();ctx.translate(@@ -1700,60 +1716,87 @@ function renderImageLayerInternal(ctx.scale(flipH ? -1 : 1, flipV ? -1 : 1);}- {- const { filters } = layer;- const filterParts: string[] = [];+ const { filters } = layer;+ const filterParts: string[] = [];- let effectiveBrightness = filters.brightness;- if (filters.exposure !== 0) {- effectiveBrightness = effectiveBrightness * (1 + filters.exposure / 100);- }- if (filters.highlights > 0) {- effectiveBrightness = effectiveBrightness * (1 + filters.highlights / 200);- }- if (filters.shadows > 0) {- effectiveBrightness = effectiveBrightness * (1 + filters.shadows / 300);- }- if (effectiveBrightness !== 100) {- filterParts.push(`brightness(${Math.round(effectiveBrightness)}%)`);- }+ let effectiveBrightness = filters.brightness;+ if (filters.exposure !== 0) {+ effectiveBrightness = effectiveBrightness * (1 + filters.exposure / 100);+ }+ if (filters.highlights > 0) {+ effectiveBrightness = effectiveBrightness * (1 + filters.highlights / 200);+ }+ if (filters.shadows > 0) {+ effectiveBrightness = effectiveBrightness * (1 + filters.shadows / 300);+ }+ if (effectiveBrightness !== 100) {+ filterParts.push(`brightness(${Math.round(effectiveBrightness)}%)`);+ }- let effectiveContrast = filters.contrast;- if (filters.clarity !== 0) {- effectiveContrast = effectiveContrast * (1 + filters.clarity / 150);- }- if (filters.highlights < 0) {- effectiveContrast = effectiveContrast * (1 + filters.highlights / 400);- }- if (filters.shadows < 0) {- effectiveContrast = effectiveContrast * (1 + filters.shadows / 400);- }- if (effectiveContrast !== 100) {- filterParts.push(`contrast(${Math.round(effectiveContrast)}%)`);- }+ let effectiveContrast = filters.contrast;+ if (filters.clarity !== 0) {+ effectiveContrast = effectiveContrast * (1 + filters.clarity / 150);+ }+ if (filters.highlights < 0) {+ effectiveContrast = effectiveContrast * (1 + filters.highlights / 400);+ }+ if (filters.shadows < 0) {+ effectiveContrast = effectiveContrast * (1 + filters.shadows / 400);+ }+ if (effectiveContrast !== 100) {+ filterParts.push(`contrast(${Math.round(effectiveContrast)}%)`);+ }- let effectiveSaturation = filters.saturation;- if (filters.vibrance !== 0) {- effectiveSaturation = effectiveSaturation * (1 + filters.vibrance / 150);- }- if (effectiveSaturation !== 100) {- filterParts.push(`saturate(${Math.round(effectiveSaturation)}%)`);- }+ let effectiveSaturation = filters.saturation;+ if (filters.vibrance !== 0) {+ effectiveSaturation = effectiveSaturation * (1 + filters.vibrance / 150);+ }+ if (effectiveSaturation !== 100) {+ filterParts.push(`saturate(${Math.round(effectiveSaturation)}%)`);+ }- if (filters.hue !== 0) {- filterParts.push(`hue-rotate(${filters.hue}deg)`);- }- if (filters.sepia > 0) {- filterParts.push(`sepia(${filters.sepia}%)`);- }- if (filters.invert > 0) {- filterParts.push(`invert(${filters.invert}%)`);- }+ if (filters.hue !== 0) {+ filterParts.push(`hue-rotate(${filters.hue}deg)`);+ }+ if (filters.sepia > 0) {+ filterParts.push(`sepia(${filters.sepia}%)`);+ }+ if (filters.invert > 0) {+ filterParts.push(`invert(${filters.invert}%)`);+ }- if (filters.blur > 0 && filters.blurType === 'gaussian') {- filterParts.push(`blur(${filters.blur}px)`);- }+ if (filters.blur > 0 && filters.blurType === 'gaussian') {+ filterParts.push(`blur(${filters.blur}px)`);+ }+ const width = Math.ceil(layer.transform.width);+ const height = Math.ceil(layer.transform.height);++ if (needsAdjustments && typeof OffscreenCanvas !== 'undefined' && width > 0 && height > 0) {+ const tempCanvas = new OffscreenCanvas(width, height);+ const tempCtx = tempCanvas.getContext('2d');+ if (tempCtx) {+ if (filterParts.length > 0) {+ tempCtx.filter = filterParts.join(' ');+ }++ if (filters.blur > 0 && filters.blurType === 'motion') {+ applyMotionBlur(tempCtx, img, width, height, filters.blur, filters.blurAngle);+ } else if (filters.blur > 0 && filters.blurType === 'radial') {+ applyRadialBlur(tempCtx, img, width, height, filters.blur);+ } else {+ tempCtx.drawImage(img, 0, 0, width, height);+ }++ tempCtx.filter = 'none';++ let imageData = tempCtx.getImageData(0, 0, width, height);+ imageData = applyAllAdjustments(imageData, adjustments);+ tempCtx.putImageData(imageData, 0, 0);++ ctx.drawImage(tempCanvas, 0, 0, layer.transform.width, layer.transform.height);+ }+ } else {if (filterParts.length > 0) {ctx.filter = filterParts.join(' ');}diff --git a/apps/image/src/components/editor/inspector/BlackWhiteSection.tsx b/apps/image/src/components/editor/inspector/BlackWhiteSection.tsxnew file mode 100644index 00000000..0096e441--- /dev/null+++ b/apps/image/src/components/editor/inspector/BlackWhiteSection.tsx@@ -0,0 +1,226 @@+import { useState } from 'react';+import { useProjectStore } from '../../../stores/project-store';+import type { Layer } from '../../../types/project';+import type { BlackWhiteAdjustment } from '../../../types/adjustments';+import { DEFAULT_BLACK_WHITE } from '../../../types/adjustments';+import { BLACK_WHITE_PRESETS } from '../../../adjustments/black-white';+import { SunMoon, RotateCcw } from 'lucide-react';++interface Props {+ layer: Layer;+}++const COLOR_SLIDERS: { key: keyof BlackWhiteAdjustment; label: string; color: string }[] = [+ { key: 'reds', label: 'Reds', color: 'bg-red-500' },+ { key: 'yellows', label: 'Yellows', color: 'bg-yellow-500' },+ { key: 'greens', label: 'Greens', color: 'bg-green-500' },+ { key: 'cyans', label: 'Cyans', color: 'bg-cyan-500' },+ { key: 'blues', label: 'Blues', color: 'bg-blue-500' },+ { key: 'magentas', label: 'Magentas', color: 'bg-pink-500' },+];++const PRESET_OPTIONS = [+ { id: 'default', label: 'Default' },+ { id: 'highContrast', label: 'High Contrast' },+ { id: 'infrared', label: 'Infrared' },+ { id: 'maximumBlack', label: 'Maximum Black' },+ { id: 'maximumWhite', label: 'Maximum White' },+ { id: 'neutralDensity', label: 'Neutral Density' },+ { id: 'redFilter', label: 'Red Filter' },+ { id: 'yellowFilter', label: 'Yellow Filter' },+ { id: 'greenFilter', label: 'Green Filter' },+ { id: 'blueFilter', label: 'Blue Filter' },+] as const;++function ChannelSlider({ label, color, value, onChange }: { label: string; color: string; value: number; onChange: (v: number) => void }) {+ const percentage = ((value + 200) / 400) * 100;++ return (+ <div className="space-y-1">+ <div className="flex items-center justify-between">+ <div className="flex items-center gap-1.5">+ <span className={`w-2 h-2 rounded-full ${color}`} />+ <span className="text-[10px] text-muted-foreground">{label}</span>+ </div>+ <span className="text-[10px] font-mono text-muted-foreground">{value}%</span>+ </div>+ <input+ type="range"+ value={value}+ min={-200}+ max={200}+ onChange={(e) => onChange(Number(e.target.value))}+ className="w-full h-1.5 appearance-none bg-secondary rounded-full cursor-pointer+ [&::-webkit-slider-thumb]:appearance-none+ [&::-webkit-slider-thumb]:w-2.5+ [&::-webkit-slider-thumb]:h-2.5+ [&::-webkit-slider-thumb]:rounded-full+ [&::-webkit-slider-thumb]:bg-primary+ [&::-webkit-slider-thumb]:shadow-sm+ [&::-webkit-slider-thumb]:cursor-pointer"+ style={{+ background: `linear-gradient(to right, hsl(var(--secondary)) 0%, hsl(var(--primary)) ${percentage}%, hsl(var(--secondary)) ${percentage}%, hsl(var(--secondary)) 100%)`+ }}+ />+ </div>+ );+}++export function BlackWhiteSection({ layer }: Props) {+ const { updateLayer } = useProjectStore();+ const [isExpanded, setIsExpanded] = useState(false);++ const blackWhite = layer.blackWhite;++ const handleValueChange = (key: keyof BlackWhiteAdjustment, value: number | boolean) => {+ updateLayer(layer.id, {+ blackWhite: {+ ...blackWhite,+ [key]: value,+ },+ });+ };++ const handlePresetChange = (presetId: string) => {+ const preset = BLACK_WHITE_PRESETS[presetId as keyof typeof BLACK_WHITE_PRESETS];+ if (preset) {+ updateLayer(layer.id, {+ blackWhite: {+ ...blackWhite,+ ...preset,+ },+ });+ }+ };++ const handleEnabledChange = (enabled: boolean) => {+ updateLayer(layer.id, {+ blackWhite: {+ ...blackWhite,+ enabled,+ },+ });+ };++ const resetBlackWhite = () => {+ updateLayer(layer.id, {+ blackWhite: { ...DEFAULT_BLACK_WHITE },+ });+ };++ return (+ <div className="border-b border-border">+ <button+ onClick={() => setIsExpanded(!isExpanded)}+ className="w-full flex items-center justify-between px-3 py-2 hover:bg-secondary/50 transition-colors"+ >+ <div className="flex items-center gap-2">+ <SunMoon size={14} className="text-muted-foreground" />+ <span className="text-xs font-medium">Black & White</span>+ {blackWhite.enabled && (+ <span className="w-1.5 h-1.5 rounded-full bg-primary" />+ )}+ </div>+ <input+ type="checkbox"+ checked={blackWhite.enabled}+ onChange={(e) => {+ e.stopPropagation();+ handleEnabledChange(e.target.checked);+ }}+ className="w-3.5 h-3.5 rounded border-border"+ />+ </button>++ {isExpanded && (+ <div className="px-3 pb-3 space-y-3">+ <div className="flex items-center justify-between">+ <select+ value=""+ onChange={(e) => handlePresetChange(e.target.value)}+ className="text-[10px] bg-secondary border-none rounded px-2 py-1 text-foreground"+ >+ <option value="">Preset</option>+ {PRESET_OPTIONS.map((preset) => (+ <option key={preset.id} value={preset.id}>{preset.label}</option>+ ))}+ </select>+ <button+ onClick={resetBlackWhite}+ className="p-1 text-muted-foreground hover:text-foreground rounded hover:bg-secondary transition-colors"+ title="Reset"+ >+ <RotateCcw size={12} />+ </button>+ </div>++ <div className="space-y-2">+ {COLOR_SLIDERS.map(({ key, label, color }) => (+ <ChannelSlider+ key={key}+ label={label}+ color={color}+ value={blackWhite[key] as number}+ onChange={(v) => handleValueChange(key, v)}+ />+ ))}+ </div>++ <div className="space-y-2 pt-2 border-t border-border/50">+ <label className="flex items-center gap-2 text-[10px] text-muted-foreground">+ <input+ type="checkbox"+ checked={blackWhite.tintEnabled}+ onChange={(e) => handleValueChange('tintEnabled', e.target.checked)}+ className="w-3 h-3 rounded border-border"+ />+ Tint+ </label>+ {blackWhite.tintEnabled && (+ <div className="space-y-2 pl-5">+ <div className="space-y-1">+ <div className="flex items-center justify-between">+ <span className="text-[10px] text-muted-foreground">Hue</span>+ <span className="text-[10px] font-mono text-muted-foreground">{blackWhite.tintHue}°</span>+ </div>+ <input+ type="range"+ value={blackWhite.tintHue}+ min={0}+ max={360}+ onChange={(e) => handleValueChange('tintHue', Number(e.target.value))}+ className="w-full h-1.5 appearance-none rounded-full cursor-pointer"+ style={{+ background: `linear-gradient(to right, hsl(0, 70%, 50%), hsl(60, 70%, 50%), hsl(120, 70%, 50%), hsl(180, 70%, 50%), hsl(240, 70%, 50%), hsl(300, 70%, 50%), hsl(360, 70%, 50%))`+ }}+ />+ </div>+ <div className="space-y-1">+ <div className="flex items-center justify-between">+ <span className="text-[10px] text-muted-foreground">Saturation</span>+ <span className="text-[10px] font-mono text-muted-foreground">{blackWhite.tintSaturation}%</span>+ </div>+ <input+ type="range"+ value={blackWhite.tintSaturation}+ min={0}+ max={100}+ onChange={(e) => handleValueChange('tintSaturation', Number(e.target.value))}+ className="w-full h-1.5 appearance-none bg-secondary rounded-full cursor-pointer+ [&::-webkit-slider-thumb]:appearance-none+ [&::-webkit-slider-thumb]:w-2.5+ [&::-webkit-slider-thumb]:h-2.5+ [&::-webkit-slider-thumb]:rounded-full+ [&::-webkit-slider-thumb]:bg-primary+ [&::-webkit-slider-thumb]:shadow-sm+ [&::-webkit-slider-thumb]:cursor-pointer"+ />+ </div>+ </div>+ )}+ </div>+ </div>+ )}+ </div>+ );+}diff --git a/apps/image/src/components/editor/inspector/ChannelMixerSection.tsx b/apps/image/src/components/editor/inspector/ChannelMixerSection.tsxnew file mode 100644index 00000000..fffa5fba--- /dev/null+++ b/apps/image/src/components/editor/inspector/ChannelMixerSection.tsx@@ -0,0 +1,170 @@+import { useState } from 'react';+import { useProjectStore } from '../../../stores/project-store';+import type { Layer } from '../../../types/project';+import type { ChannelMixerAdjustment, ChannelMixerChannel } from '../../../types/adjustments';+import { DEFAULT_CHANNEL_MIXER } from '../../../types/adjustments';+import { Blend, RotateCcw } from 'lucide-react';++interface Props {+ layer: Layer;+}++type OutputChannel = 'red' | 'green' | 'blue';++const CHANNEL_COLORS: Record<OutputChannel, string> = {+ red: 'bg-red-500',+ green: 'bg-green-500',+ blue: 'bg-blue-500',+};++function ChannelSlider({ label, color, value, onChange }: { label: string; color: string; value: number; onChange: (v: number) => void }) {+ const percentage = ((value + 200) / 400) * 100;++ return (+ <div className="space-y-1">+ <div className="flex items-center justify-between">+ <div className="flex items-center gap-1.5">+ <span className={`w-2 h-2 rounded-full ${color}`} />+ <span className="text-[10px] text-muted-foreground">{label}</span>+ </div>+ <span className="text-[10px] font-mono text-muted-foreground">{value}%</span>+ </div>+ <input+ type="range"+ value={value}+ min={-200}+ max={200}+ onChange={(e) => onChange(Number(e.target.value))}+ className="w-full h-1.5 appearance-none bg-secondary rounded-full cursor-pointer+ [&::-webkit-slider-thumb]:appearance-none+ [&::-webkit-slider-thumb]:w-2.5+ [&::-webkit-slider-thumb]:h-2.5+ [&::-webkit-slider-thumb]:rounded-full+ [&::-webkit-slider-thumb]:bg-primary+ [&::-webkit-slider-thumb]:shadow-sm+ [&::-webkit-slider-thumb]:cursor-pointer"+ style={{+ background: `linear-gradient(to right, hsl(var(--secondary)) 0%, hsl(var(--primary)) ${percentage}%, hsl(var(--secondary)) ${percentage}%, hsl(var(--secondary)) 100%)`+ }}+ />+ </div>+ );+}++export function ChannelMixerSection({ layer }: Props) {+ const { updateLayer } = useProjectStore();+ const [activeChannel, setActiveChannel] = useState<OutputChannel>('red');+ const [isExpanded, setIsExpanded] = useState(false);++ const channelMixer = layer.channelMixer;+ const currentChannel = channelMixer[activeChannel];++ const handleValueChange = (key: keyof ChannelMixerChannel, value: number) => {+ updateLayer(layer.id, {+ channelMixer: {+ ...channelMixer,+ [activeChannel]: {+ ...currentChannel,+ [key]: value,+ },+ } as ChannelMixerAdjustment,+ });+ };++ const handleMonochromeChange = (monochrome: boolean) => {+ updateLayer(layer.id, {+ channelMixer: {+ ...channelMixer,+ monochrome,+ } as ChannelMixerAdjustment,+ });+ };++ const handleEnabledChange = (enabled: boolean) => {+ updateLayer(layer.id, {+ channelMixer: {+ ...channelMixer,+ enabled,+ } as ChannelMixerAdjustment,+ });+ };++ const resetChannelMixer = () => {+ updateLayer(layer.id, {+ channelMixer: { ...DEFAULT_CHANNEL_MIXER },+ });+ };++ return (+ <div className="border-b border-border">+ <button+ onClick={() => setIsExpanded(!isExpanded)}+ className="w-full flex items-center justify-between px-3 py-2 hover:bg-secondary/50 transition-colors"+ >+ <div className="flex items-center gap-2">+ <Blend size={14} className="text-muted-foreground" />+ <span className="text-xs font-medium">Channel Mixer</span>+ {channelMixer.enabled && (+ <span className="w-1.5 h-1.5 rounded-full bg-primary" />+ )}+ </div>+ <input+ type="checkbox"+ checked={channelMixer.enabled}+ onChange={(e) => {+ e.stopPropagation();+ handleEnabledChange(e.target.checked);+ }}+ className="w-3.5 h-3.5 rounded border-border"+ />+ </button>++ {isExpanded && (+ <div className="px-3 pb-3 space-y-3">+ <div className="flex items-center justify-between">+ <div className="flex gap-1">+ {(['red', 'green', 'blue'] as OutputChannel[]).map((channel) => (+ <button+ key={channel}+ onClick={() => setActiveChannel(channel)}+ className={`px-2 py-1 text-[10px] rounded transition-colors ${+ activeChannel === channel+ ? 'bg-secondary text-foreground'+ : 'text-muted-foreground hover:text-foreground'+ }`}+ >+ <span className={`inline-block w-2 h-2 rounded-full mr-1 ${CHANNEL_COLORS[channel]}`} />+ {channel.charAt(0).toUpperCase() + channel.slice(1)}+ </button>+ ))}+ </div>+ <button+ onClick={resetChannelMixer}+ className="p-1 text-muted-foreground hover:text-foreground rounded hover:bg-secondary transition-colors"+ title="Reset"+ >+ <RotateCcw size={12} />+ </button>+ </div>++ <div className="space-y-2">+ <ChannelSlider label="Red" color="bg-red-500" value={currentChannel.red} onChange={(v) => handleValueChange('red', v)} />+ <ChannelSlider label="Green" color="bg-green-500" value={currentChannel.green} onChange={(v) => handleValueChange('green', v)} />+ <ChannelSlider label="Blue" color="bg-blue-500" value={currentChannel.blue} onChange={(v) => handleValueChange('blue', v)} />+ <ChannelSlider label="Constant" color="bg-gray-500" value={currentChannel.constant} onChange={(v) => handleValueChange('constant', v)} />+ </div>++ <label className="flex items-center gap-2 text-[10px] text-muted-foreground pt-1 border-t border-border/50">+ <input+ type="checkbox"+ checked={channelMixer.monochrome}+ onChange={(e) => handleMonochromeChange(e.target.checked)}+ className="w-3 h-3 rounded border-border"+ />+ Monochrome+ </label>+ </div>+ )}+ </div>+ );+}diff --git a/apps/image/src/components/editor/inspector/GradientMapSection.tsx b/apps/image/src/components/editor/inspector/GradientMapSection.tsxnew file mode 100644index 00000000..8558d019--- /dev/null+++ b/apps/image/src/components/editor/inspector/GradientMapSection.tsx@@ -0,0 +1,202 @@+import { useState } from 'react';+import { useProjectStore } from '../../../stores/project-store';+import type { Layer } from '../../../types/project';+import type { GradientMapStop } from '../../../types/adjustments';+import { DEFAULT_GRADIENT_MAP } from '../../../types/adjustments';+import { Paintbrush, RotateCcw, Plus, X } from 'lucide-react';++interface Props {+ layer: Layer;+}++const GRADIENT_PRESETS = [+ { name: 'B&W', stops: [{ position: 0, color: '#000000' }, { position: 1, color: '#ffffff' }] },+ { name: 'Sepia', stops: [{ position: 0, color: '#2b1810' }, { position: 0.5, color: '#8b5a2b' }, { position: 1, color: '#f5deb3' }] },+ { name: 'Duotone Blue', stops: [{ position: 0, color: '#001133' }, { position: 1, color: '#66ccff' }] },+ { name: 'Duotone Orange', stops: [{ position: 0, color: '#331100' }, { position: 1, color: '#ff9900' }] },+ { name: 'Sunset', stops: [{ position: 0, color: '#1a0533' }, { position: 0.5, color: '#ff6b35' }, { position: 1, color: '#f7c59f' }] },+];++export function GradientMapSection({ layer }: Props) {+ const { updateLayer } = useProjectStore();+ const [isExpanded, setIsExpanded] = useState(false);++ const gradientMap = layer.gradientMap;++ const handleStopChange = (index: number, updates: Partial<GradientMapStop>) => {+ const newStops = [...gradientMap.stops];+ newStops[index] = { ...newStops[index], ...updates };+ updateLayer(layer.id, {+ gradientMap: { ...gradientMap, stops: newStops },+ });+ };++ const addStop = () => {+ const newStops = [...gradientMap.stops, { position: 0.5, color: '#808080' }];+ newStops.sort((a, b) => a.position - b.position);+ updateLayer(layer.id, {+ gradientMap: { ...gradientMap, stops: newStops },+ });+ };++ const removeStop = (index: number) => {+ if (gradientMap.stops.length <= 2) return;+ const newStops = gradientMap.stops.filter((_, i) => i !== index);+ updateLayer(layer.id, {+ gradientMap: { ...gradientMap, stops: newStops },+ });+ };++ const handleReverseChange = (reverse: boolean) => {+ updateLayer(layer.id, {+ gradientMap: { ...gradientMap, reverse },+ });+ };++ const handleDitherChange = (dither: boolean) => {+ updateLayer(layer.id, {+ gradientMap: { ...gradientMap, dither },+ });+ };++ const handleEnabledChange = (enabled: boolean) => {+ updateLayer(layer.id, {+ gradientMap: { ...gradientMap, enabled },+ });+ };++ const applyPreset = (preset: typeof GRADIENT_PRESETS[0]) => {+ updateLayer(layer.id, {+ gradientMap: { ...gradientMap, stops: preset.stops },+ });+ };++ const resetGradientMap = () => {+ updateLayer(layer.id, {+ gradientMap: { ...DEFAULT_GRADIENT_MAP },+ });+ };++ const gradientStyle = `linear-gradient(to right, ${gradientMap.stops+ .map((s) => `${s.color} ${s.position * 100}%`)+ .join(', ')})`;++ return (+ <div className="border-b border-border">+ <button+ onClick={() => setIsExpanded(!isExpanded)}+ className="w-full flex items-center justify-between px-3 py-2 hover:bg-secondary/50 transition-colors"+ >+ <div className="flex items-center gap-2">+ <Paintbrush size={14} className="text-muted-foreground" />+ <span className="text-xs font-medium">Gradient Map</span>+ {gradientMap.enabled && (+ <span className="w-1.5 h-1.5 rounded-full bg-primary" />+ )}+ </div>+ <input+ type="checkbox"+ checked={gradientMap.enabled}+ onChange={(e) => {+ e.stopPropagation();+ handleEnabledChange(e.target.checked);+ }}+ className="w-3.5 h-3.5 rounded border-border"+ />+ </button>++ {isExpanded && (+ <div className="px-3 pb-3 space-y-3">+ <div className="flex items-center justify-between">+ <div className="flex gap-1 flex-wrap">+ {GRADIENT_PRESETS.map((preset) => (+ <button+ key={preset.name}+ onClick={() => applyPreset(preset)}+ className="px-2 py-1 text-[9px] bg-secondary/50 hover:bg-secondary rounded text-muted-foreground hover:text-foreground transition-colors"+ >+ {preset.name}+ </button>+ ))}+ </div>+ <button+ onClick={resetGradientMap}+ className="p-1 text-muted-foreground hover:text-foreground rounded hover:bg-secondary transition-colors"+ title="Reset"+ >+ <RotateCcw size={12} />+ </button>+ </div>++ <div+ className="h-6 rounded border border-border"+ style={{ background: gradientStyle }}+ />++ <div className="space-y-2">+ {gradientMap.stops.map((stop, index) => (+ <div key={index} className="flex items-center gap-2">+ <input+ type="color"+ value={stop.color}+ onChange={(e) => handleStopChange(index, { color: e.target.value })}+ className="w-6 h-6 rounded border-none cursor-pointer"+ />+ <input+ type="range"+ value={stop.position * 100}+ min={0}+ max={100}+ onChange={(e) => handleStopChange(index, { position: Number(e.target.value) / 100 })}+ className="flex-1 h-1.5 appearance-none bg-secondary rounded-full cursor-pointer+ [&::-webkit-slider-thumb]:appearance-none+ [&::-webkit-slider-thumb]:w-2.5+ [&::-webkit-slider-thumb]:h-2.5+ [&::-webkit-slider-thumb]:rounded-full+ [&::-webkit-slider-thumb]:bg-primary"+ />+ <span className="text-[10px] font-mono text-muted-foreground w-8">{Math.round(stop.position * 100)}%</span>+ {gradientMap.stops.length > 2 && (+ <button+ onClick={() => removeStop(index)}+ className="p-0.5 text-muted-foreground hover:text-destructive rounded hover:bg-secondary transition-colors"+ >+ <X size={10} />+ </button>+ )}+ </div>+ ))}+ </div>++ <button+ onClick={addStop}+ className="flex items-center gap-1 text-[10px] text-muted-foreground hover:text-foreground transition-colors"+ >+ <Plus size={10} /> Add Stop+ </button>++ <div className="flex gap-4 pt-1 border-t border-border/50">+ <label className="flex items-center gap-2 text-[10px] text-muted-foreground">+ <input+ type="checkbox"+ checked={gradientMap.reverse}+ onChange={(e) => handleReverseChange(e.target.checked)}+ className="w-3 h-3 rounded border-border"+ />+ Reverse+ </label>+ <label className="flex items-center gap-2 text-[10px] text-muted-foreground">+ <input+ type="checkbox"+ checked={gradientMap.dither}+ onChange={(e) => handleDitherChange(e.target.checked)}+ className="w-3 h-3 rounded border-border"+ />+ Dither+ </label>+ </div>+ </div>+ )}+ </div>+ );+}diff --git a/apps/image/src/components/editor/inspector/Inspector.tsx b/apps/image/src/components/editor/inspector/Inspector.tsxindex de67093d..7868af27 100644--- a/apps/image/src/components/editor/inspector/Inspector.tsx+++ b/apps/image/src/components/editor/inspector/Inspector.tsx@@ -20,6 +20,13 @@ const ShapeSection = lazy(() => import('./ShapeSection').then(m => ({ default: mconst LevelsSection = lazy(() => import('./LevelsSection').then(m => ({ default: m.LevelsSection })));const CurvesSection = lazy(() => import('./CurvesSection').then(m => ({ default: m.CurvesSection })));const ColorBalanceSection = lazy(() => import('./ColorBalanceSection').then(m => ({ default: m.ColorBalanceSection })));+const SelectiveColorSection = lazy(() => import('./SelectiveColorSection').then(m => ({ default: m.SelectiveColorSection })));+const BlackWhiteSection = lazy(() => import('./BlackWhiteSection').then(m => ({ default: m.BlackWhiteSection })));+const PhotoFilterSection = lazy(() => import('./PhotoFilterSection').then(m => ({ default: m.PhotoFilterSection })));+const ChannelMixerSection = lazy(() => import('./ChannelMixerSection').then(m => ({ default: m.ChannelMixerSection })));+const GradientMapSection = lazy(() => import('./GradientMapSection').then(m => ({ default: m.GradientMapSection })));+const PosterizeSection = lazy(() => import('./PosterizeSection').then(m => ({ default: m.PosterizeSection })));+const ThresholdSection = lazy(() => import('./ThresholdSection').then(m => ({ default: m.ThresholdSection })));const MaskSection = lazy(() => import('./MaskSection').then(m => ({ default: m.MaskSection })));const SelectionToolsPanel = lazy(() => import('./SelectionToolsPanel').then(m => ({ default: m.SelectionToolsPanel })));const EraserToolPanel = lazy(() => import('./EraserToolPanel').then(m => ({ default: m.EraserToolPanel })));@@ -147,6 +154,13 @@ function InspectorContent() {<LevelsSection layer={singleLayer} /><CurvesSection layer={singleLayer} /><ColorBalanceSection layer={singleLayer} />+ <SelectiveColorSection layer={singleLayer} />+ <BlackWhiteSection layer={singleLayer} />+ <PhotoFilterSection layer={singleLayer} />+ <ChannelMixerSection layer={singleLayer} />+ <GradientMapSection layer={singleLayer} />+ <PosterizeSection layer={singleLayer} />+ <ThresholdSection layer={singleLayer} /></Suspense>)}diff --git a/apps/image/src/components/editor/inspector/PhotoFilterSection.tsx b/apps/image/src/components/editor/inspector/PhotoFilterSection.tsxnew file mode 100644index 00000000..19a50718--- /dev/null+++ b/apps/image/src/components/editor/inspector/PhotoFilterSection.tsx@@ -0,0 +1,179 @@+import { useState } from 'react';+import { useProjectStore } from '../../../stores/project-store';+import type { Layer } from '../../../types/project';+import type { PhotoFilterAdjustment } from '../../../types/adjustments';+import { DEFAULT_PHOTO_FILTER } from '../../../types/adjustments';+import { PHOTO_FILTER_COLORS } from '../../../adjustments/photo-filter';+import { SunDim, RotateCcw } from 'lucide-react';++interface Props {+ layer: Layer;+}++const FILTER_OPTIONS = [+ { id: 'warming-85', label: 'Warming (85)', group: 'Warming' },+ { id: 'warming-81', label: 'Warming (81)', group: 'Warming' },+ { id: 'cooling-80', label: 'Cooling (80)', group: 'Cooling' },+ { id: 'cooling-82', label: 'Cooling (82)', group: 'Cooling' },+ { id: 'custom', label: 'Custom Color', group: 'Custom' },+] as const;++type FilterType = typeof FILTER_OPTIONS[number]['id'];++export function PhotoFilterSection({ layer }: Props) {+ const { updateLayer } = useProjectStore();+ const [isExpanded, setIsExpanded] = useState(false);++ const photoFilter = layer.photoFilter;++ const handleFilterChange = (filter: FilterType) => {+ const color = filter === 'custom' ? photoFilter.color : (PHOTO_FILTER_COLORS[filter as keyof typeof PHOTO_FILTER_COLORS] ?? photoFilter.color);+ updateLayer(layer.id, {+ photoFilter: {+ ...photoFilter,+ filter,+ color,+ },+ });+ };++ const handleDensityChange = (density: number) => {+ updateLayer(layer.id, {+ photoFilter: {+ ...photoFilter,+ density,+ },+ });+ };++ const handleColorChange = (color: string) => {+ updateLayer(layer.id, {+ photoFilter: {+ ...photoFilter,+ filter: 'custom',+ color,+ } as PhotoFilterAdjustment,+ });+ };++ const handlePreserveLuminosityChange = (preserveLuminosity: boolean) => {+ updateLayer(layer.id, {+ photoFilter: {+ ...photoFilter,+ preserveLuminosity,+ },+ });+ };++ const handleEnabledChange = (enabled: boolean) => {+ updateLayer(layer.id, {+ photoFilter: {+ ...photoFilter,+ enabled,+ },+ });+ };++ const resetPhotoFilter = () => {+ updateLayer(layer.id, {+ photoFilter: { ...DEFAULT_PHOTO_FILTER },+ });+ };++ const densityPercentage = photoFilter.density;++ return (+ <div className="border-b border-border">+ <button+ onClick={() => setIsExpanded(!isExpanded)}+ className="w-full flex items-center justify-between px-3 py-2 hover:bg-secondary/50 transition-colors"+ >+ <div className="flex items-center gap-2">+ <SunDim size={14} className="text-muted-foreground" />+ <span className="text-xs font-medium">Photo Filter</span>+ {photoFilter.enabled && (+ <span className="w-1.5 h-1.5 rounded-full bg-primary" />+ )}+ </div>+ <input+ type="checkbox"+ checked={photoFilter.enabled}+ onChange={(e) => {+ e.stopPropagation();+ handleEnabledChange(e.target.checked);+ }}+ className="w-3.5 h-3.5 rounded border-border"+ />+ </button>++ {isExpanded && (+ <div className="px-3 pb-3 space-y-3">+ <div className="flex items-center justify-between">+ <select+ value={photoFilter.filter}+ onChange={(e) => handleFilterChange(e.target.value as FilterType)}+ className="text-[10px] bg-secondary border-none rounded px-2 py-1 text-foreground flex-1"+ >+ {FILTER_OPTIONS.map((option) => (+ <option key={option.id} value={option.id}>{option.label}</option>+ ))}+ </select>+ <button+ onClick={resetPhotoFilter}+ className="p-1 ml-2 text-muted-foreground hover:text-foreground rounded hover:bg-secondary transition-colors"+ title="Reset"+ >+ <RotateCcw size={12} />+ </button>+ </div>++ <div className="flex items-center gap-2">+ <span className="text-[10px] text-muted-foreground">Color</span>+ <input+ type="color"+ value={photoFilter.color}+ onChange={(e) => handleColorChange(e.target.value)}+ className="w-6 h-6 rounded border-none cursor-pointer"+ />+ <span className="text-[10px] font-mono text-muted-foreground">{photoFilter.color}</span>+ </div>++ <div className="space-y-1">+ <div className="flex items-center justify-between">+ <span className="text-[10px] text-muted-foreground">Density</span>+ <span className="text-[10px] font-mono text-muted-foreground">{photoFilter.density}%</span>+ </div>+ <input+ type="range"+ value={photoFilter.density}+ min={0}+ max={100}+ onChange={(e) => handleDensityChange(Number(e.target.value))}+ className="w-full h-1.5 appearance-none bg-secondary rounded-full cursor-pointer+ [&::-webkit-slider-thumb]:appearance-none+ [&::-webkit-slider-thumb]:w-2.5+ [&::-webkit-slider-thumb]:h-2.5+ [&::-webkit-slider-thumb]:rounded-full+ [&::-webkit-slider-thumb]:bg-primary+ [&::-webkit-slider-thumb]:shadow-sm+ [&::-webkit-slider-thumb]:cursor-pointer"+ style={{+ background: `linear-gradient(to right, hsl(var(--primary)) 0%, hsl(var(--primary)) ${densityPercentage}%, hsl(var(--secondary)) ${densityPercentage}%, hsl(var(--secondary)) 100%)`+ }}+ />+ </div>++ <label className="flex items-center gap-2 text-[10px] text-muted-foreground">+ <input+ type="checkbox"+ checked={photoFilter.preserveLuminosity}+ onChange={(e) => handlePreserveLuminosityChange(e.target.checked)}+ className="w-3 h-3 rounded border-border"+ />+ Preserve Luminosity+ </label>+ </div>+ )}+ </div>+ );+}diff --git a/apps/image/src/components/editor/inspector/PosterizeSection.tsx b/apps/image/src/components/editor/inspector/PosterizeSection.tsxnew file mode 100644index 00000000..c5ee38f2--- /dev/null+++ b/apps/image/src/components/editor/inspector/PosterizeSection.tsx@@ -0,0 +1,104 @@+import { useState } from 'react';+import { useProjectStore } from '../../../stores/project-store';+import type { Layer } from '../../../types/project';+import { DEFAULT_POSTERIZE } from '../../../types/adjustments';+import { Layers, RotateCcw } from 'lucide-react';++interface Props {+ layer: Layer;+}++export function PosterizeSection({ layer }: Props) {+ const { updateLayer } = useProjectStore();+ const [isExpanded, setIsExpanded] = useState(false);++ const posterize = layer.posterize;++ const handleLevelsChange = (levels: number) => {+ updateLayer(layer.id, {+ posterize: { ...posterize, levels },+ });+ };++ const handleEnabledChange = (enabled: boolean) => {+ updateLayer(layer.id, {+ posterize: { ...posterize, enabled },+ });+ };++ const resetPosterize = () => {+ updateLayer(layer.id, {+ posterize: { ...DEFAULT_POSTERIZE },+ });+ };++ const percentage = ((posterize.levels - 2) / 253) * 100;++ return (+ <div className="border-b border-border">+ <button+ onClick={() => setIsExpanded(!isExpanded)}+ className="w-full flex items-center justify-between px-3 py-2 hover:bg-secondary/50 transition-colors"+ >+ <div className="flex items-center gap-2">+ <Layers size={14} className="text-muted-foreground" />+ <span className="text-xs font-medium">Posterize</span>+ {posterize.enabled && (+ <span className="w-1.5 h-1.5 rounded-full bg-primary" />+ )}+ </div>+ <input+ type="checkbox"+ checked={posterize.enabled}+ onChange={(e) => {+ e.stopPropagation();+ handleEnabledChange(e.target.checked);+ }}+ className="w-3.5 h-3.5 rounded border-border"+ />+ </button>++ {isExpanded && (+ <div className="px-3 pb-3 space-y-3">+ <div className="flex items-center justify-between">+ <span className="text-[10px] text-muted-foreground">Levels</span>+ <div className="flex items-center gap-2">+ <span className="text-[10px] font-mono text-muted-foreground">{posterize.levels}</span>+ <button+ onClick={resetPosterize}+ className="p-1 text-muted-foreground hover:text-foreground rounded hover:bg-secondary transition-colors"+ title="Reset"+ >+ <RotateCcw size={12} />+ </button>+ </div>+ </div>++ <input+ type="range"+ value={posterize.levels}+ min={2}+ max={255}+ onChange={(e) => handleLevelsChange(Number(e.target.value))}+ className="w-full h-1.5 appearance-none bg-secondary rounded-full cursor-pointer+ [&::-webkit-slider-thumb]:appearance-none+ [&::-webkit-slider-thumb]:w-2.5+ [&::-webkit-slider-thumb]:h-2.5+ [&::-webkit-slider-thumb]:rounded-full+ [&::-webkit-slider-thumb]:bg-primary+ [&::-webkit-slider-thumb]:shadow-sm+ [&::-webkit-slider-thumb]:cursor-pointer"+ style={{+ background: `linear-gradient(to right, hsl(var(--primary)) 0%, hsl(var(--primary)) ${percentage}%, hsl(var(--secondary)) ${percentage}%, hsl(var(--secondary)) 100%)`+ }}+ />++ <div className="flex justify-between text-[9px] text-muted-foreground">+ <span>2</span>+ <span>255</span>+ </div>+ </div>+ )}+ </div>+ );+}diff --git a/apps/image/src/components/editor/inspector/SelectiveColorSection.tsx b/apps/image/src/components/editor/inspector/SelectiveColorSection.tsxnew file mode 100644index 00000000..9c456f8d--- /dev/null+++ b/apps/image/src/components/editor/inspector/SelectiveColorSection.tsx@@ -0,0 +1,175 @@+import { useState } from 'react';+import { useProjectStore } from '../../../stores/project-store';+import type { Layer } from '../../../types/project';+import type { SelectiveColorValues, SelectiveColorAdjustment } from '../../../types/adjustments';+import { DEFAULT_SELECTIVE_COLOR } from '../../../types/adjustments';+import { Palette, RotateCcw } from 'lucide-react';++interface Props {+ layer: Layer;+}++type ColorRange = 'reds' | 'yellows' | 'greens' | 'cyans' | 'blues' | 'magentas' | 'whites' | 'neutrals' | 'blacks';++const COLOR_RANGES: { id: ColorRange; label: string; color: string }[] = [+ { id: 'reds', label: 'Reds', color: 'bg-red-500' },+ { id: 'yellows', label: 'Yellows', color: 'bg-yellow-500' },+ { id: 'greens', label: 'Greens', color: 'bg-green-500' },+ { id: 'cyans', label: 'Cyans', color: 'bg-cyan-500' },+ { id: 'blues', label: 'Blues', color: 'bg-blue-500' },+ { id: 'magentas', label: 'Magentas', color: 'bg-pink-500' },+ { id: 'whites', label: 'Whites', color: 'bg-white border border-border' },+ { id: 'neutrals', label: 'Neutrals', color: 'bg-gray-500' },+ { id: 'blacks', label: 'Blacks', color: 'bg-gray-900' },+];++function ColorSlider({ label, value, onChange }: { label: string; value: number; onChange: (v: number) => void }) {+ const percentage = ((value + 100) / 200) * 100;++ return (+ <div className="space-y-1">+ <div className="flex items-center justify-between">+ <span className="text-[10px] text-muted-foreground">{label}</span>+ <span className="text-[10px] font-mono text-muted-foreground">{value}%</span>+ </div>+ <input+ type="range"+ value={value}+ min={-100}+ max={100}+ onChange={(e) => onChange(Number(e.target.value))}+ className="w-full h-1.5 appearance-none bg-secondary rounded-full cursor-pointer+ [&::-webkit-slider-thumb]:appearance-none+ [&::-webkit-slider-thumb]:w-2.5+ [&::-webkit-slider-thumb]:h-2.5+ [&::-webkit-slider-thumb]:rounded-full+ [&::-webkit-slider-thumb]:bg-primary+ [&::-webkit-slider-thumb]:shadow-sm+ [&::-webkit-slider-thumb]:cursor-pointer"+ style={{+ background: `linear-gradient(to right, hsl(var(--secondary)) 0%, hsl(var(--secondary)) 50%, hsl(var(--primary)) 50%, hsl(var(--primary)) ${percentage}%, hsl(var(--secondary)) ${percentage}%, hsl(var(--secondary)) 100%)`+ }}+ />+ </div>+ );+}++export function SelectiveColorSection({ layer }: Props) {+ const { updateLayer } = useProjectStore();+ const [activeRange, setActiveRange] = useState<ColorRange>('reds');+ const [isExpanded, setIsExpanded] = useState(false);++ const selectiveColor = layer.selectiveColor;+ const currentRange = selectiveColor[activeRange];++ const handleValueChange = (key: keyof SelectiveColorValues, value: number) => {+ updateLayer(layer.id, {+ selectiveColor: {+ ...selectiveColor,+ [activeRange]: {+ ...currentRange,+ [key]: value,+ },+ } as SelectiveColorAdjustment,+ });+ };++ const handleMethodChange = (method: 'relative' | 'absolute') => {+ updateLayer(layer.id, {+ selectiveColor: {+ ...selectiveColor,+ method,+ } as SelectiveColorAdjustment,+ });+ };++ const handleEnabledChange = (enabled: boolean) => {+ updateLayer(layer.id, {+ selectiveColor: {+ ...selectiveColor,+ enabled,+ } as SelectiveColorAdjustment,+ });+ };++ const resetSelectiveColor = () => {+ updateLayer(layer.id, {+ selectiveColor: { ...DEFAULT_SELECTIVE_COLOR },+ });+ };++ return (+ <div className="border-b border-border">+ <button+ onClick={() => setIsExpanded(!isExpanded)}+ className="w-full flex items-center justify-between px-3 py-2 hover:bg-secondary/50 transition-colors"+ >+ <div className="flex items-center gap-2">+ <Palette size={14} className="text-muted-foreground" />+ <span className="text-xs font-medium">Selective Color</span>+ {selectiveColor.enabled && (+ <span className="w-1.5 h-1.5 rounded-full bg-primary" />+ )}+ </div>+ <input+ type="checkbox"+ checked={selectiveColor.enabled}+ onChange={(e) => {+ e.stopPropagation();+ handleEnabledChange(e.target.checked);+ }}+ className="w-3.5 h-3.5 rounded border-border"+ />+ </button>++ {isExpanded && (+ <div className="px-3 pb-3 space-y-3">+ <div className="flex items-center justify-between">+ <div className="flex flex-wrap gap-1">+ {COLOR_RANGES.map((range) => (+ <button+ key={range.id}+ onClick={() => setActiveRange(range.id)}+ className={`w-5 h-5 rounded transition-all ${range.color} ${+ activeRange === range.id ? 'ring-2 ring-primary ring-offset-1 ring-offset-background' : ''+ }`}+ title={range.label}+ />+ ))}+ </div>+ <button+ onClick={resetSelectiveColor}+ className="p-1 text-muted-foreground hover:text-foreground rounded hover:bg-secondary transition-colors"+ title="Reset"+ >+ <RotateCcw size={12} />+ </button>+ </div>++ <div className="space-y-2">+ <ColorSlider label="Cyan" value={currentRange.cyan} onChange={(v) => handleValueChange('cyan', v)} />+ <ColorSlider label="Magenta" value={currentRange.magenta} onChange={(v) => handleValueChange('magenta', v)} />+ <ColorSlider label="Yellow" value={currentRange.yellow} onChange={(v) => handleValueChange('yellow', v)} />+ <ColorSlider label="Black" value={currentRange.black} onChange={(v) => handleValueChange('black', v)} />+ </div>++ <div className="flex gap-1 pt-1">+ {(['relative', 'absolute'] as const).map((method) => (+ <button+ key={method}+ onClick={() => handleMethodChange(method)}+ className={`flex-1 px-2 py-1 text-[10px] rounded transition-colors ${+ selectiveColor.method === method+ ? 'bg-secondary text-foreground'+ : 'text-muted-foreground hover:text-foreground'+ }`}+ >+ {method.charAt(0).toUpperCase() + method.slice(1)}+ </button>+ ))}+ </div>+ </div>+ )}+ </div>+ );+}diff --git a/apps/image/src/components/editor/inspector/ThresholdSection.tsx b/apps/image/src/components/editor/inspector/ThresholdSection.tsxnew file mode 100644index 00000000..ccdee269--- /dev/null+++ b/apps/image/src/components/editor/inspector/ThresholdSection.tsx@@ -0,0 +1,108 @@+import { useState } from 'react';+import { useProjectStore } from '../../../stores/project-store';+import type { Layer } from '../../../types/project';+import { DEFAULT_THRESHOLD } from '../../../types/adjustments';+import { Binary, RotateCcw } from 'lucide-react';++interface Props {+ layer: Layer;+}++export function ThresholdSection({ layer }: Props) {+ const { updateLayer } = useProjectStore();+ const [isExpanded, setIsExpanded] = useState(false);++ const threshold = layer.threshold;++ const handleLevelChange = (level: number) => {+ updateLayer(layer.id, {+ threshold: { ...threshold, level },+ });+ };++ const handleEnabledChange = (enabled: boolean) => {+ updateLayer(layer.id, {+ threshold: { ...threshold, enabled },+ });+ };++ const resetThreshold = () => {+ updateLayer(layer.id, {+ threshold: { ...DEFAULT_THRESHOLD },+ });+ };++ const percentage = (threshold.level / 255) * 100;++ return (+ <div className="border-b border-border">+ <button+ onClick={() => setIsExpanded(!isExpanded)}+ className="w-full flex items-center justify-between px-3 py-2 hover:bg-secondary/50 transition-colors"+ >+ <div className="flex items-center gap-2">+ <Binary size={14} className="text-muted-foreground" />+ <span className="text-xs font-medium">Threshold</span>+ {threshold.enabled && (+ <span className="w-1.5 h-1.5 rounded-full bg-primary" />+ )}+ </div>+ <input+ type="checkbox"+ checked={threshold.enabled}+ onChange={(e) => {+ e.stopPropagation();+ handleEnabledChange(e.target.checked);+ }}+ className="w-3.5 h-3.5 rounded border-border"+ />+ </button>++ {isExpanded && (+ <div className="px-3 pb-3 space-y-3">+ <div className="flex items-center justify-between">+ <span className="text-[10px] text-muted-foreground">Threshold Level</span>+ <div className="flex items-center gap-2">+ <span className="text-[10px] font-mono text-muted-foreground">{threshold.level}</span>+ <button+ onClick={resetThreshold}+ className="p-1 text-muted-foreground hover:text-foreground rounded hover:bg-secondary transition-colors"+ title="Reset"+ >+ <RotateCcw size={12} />+ </button>+ </div>+ </div>++ <input+ type="range"+ value={threshold.level}+ min={0}+ max={255}+ onChange={(e) => handleLevelChange(Number(e.target.value))}+ className="w-full h-1.5 appearance-none bg-secondary rounded-full cursor-pointer+ [&::-webkit-slider-thumb]:appearance-none+ [&::-webkit-slider-thumb]:w-2.5+ [&::-webkit-slider-thumb]:h-2.5+ [&::-webkit-slider-thumb]:rounded-full+ [&::-webkit-slider-thumb]:bg-primary+ [&::-webkit-slider-thumb]:shadow-sm+ [&::-webkit-slider-thumb]:cursor-pointer"+ style={{+ background: `linear-gradient(to right, #000000 0%, #000000 ${percentage}%, #ffffff ${percentage}%, #ffffff 100%)`+ }}+ />++ <div className="flex justify-between text-[9px] text-muted-foreground">+ <span>0 (Black)</span>+ <span>255 (White)</span>+ </div>++ <p className="text-[9px] text-muted-foreground">+ Pixels below the threshold become black, above become white.+ </p>+ </div>+ )}+ </div>+ );+}diff --git a/apps/image/src/stores/project-store.ts b/apps/image/src/stores/project-store.tsindex 79647034..9fcd4278 100644--- a/apps/image/src/stores/project-store.ts+++ b/apps/image/src/stores/project-store.ts@@ -23,6 +23,13 @@ import {DEFAULT_LEVELS,DEFAULT_CURVES,DEFAULT_COLOR_BALANCE,+ DEFAULT_SELECTIVE_COLOR,+ DEFAULT_BLACK_WHITE,+ DEFAULT_PHOTO_FILTER,+ DEFAULT_CHANNEL_MIXER,+ DEFAULT_GRADIENT_MAP,+ DEFAULT_POSTERIZE,+ DEFAULT_THRESHOLD,CanvasSize,CanvasBackground,} from '../types/project';@@ -249,6 +256,13 @@ export const useProjectStore = create<ProjectState & ProjectActions>()(levels: { ...DEFAULT_LEVELS },curves: { ...DEFAULT_CURVES },colorBalance: { ...DEFAULT_COLOR_BALANCE },+ selectiveColor: { ...DEFAULT_SELECTIVE_COLOR },+ blackWhite: { ...DEFAULT_BLACK_WHITE },+ photoFilter: { ...DEFAULT_PHOTO_FILTER },+ channelMixer: { ...DEFAULT_CHANNEL_MIXER },+ gradientMap: { ...DEFAULT_GRADIENT_MAP },+ posterize: { ...DEFAULT_POSTERIZE },+ threshold: { ...DEFAULT_THRESHOLD },};state.project.layers[id] = layer;artboard.layerIds.unshift(id);@@ -298,6 +312,13 @@ export const useProjectStore = create<ProjectState & ProjectActions>()(levels: { ...DEFAULT_LEVELS },curves: { ...DEFAULT_CURVES },colorBalance: { ...DEFAULT_COLOR_BALANCE },+ selectiveColor: { ...DEFAULT_SELECTIVE_COLOR },+ blackWhite: { ...DEFAULT_BLACK_WHITE },+ photoFilter: { ...DEFAULT_PHOTO_FILTER },+ channelMixer: { ...DEFAULT_CHANNEL_MIXER },+ gradientMap: { ...DEFAULT_GRADIENT_MAP },+ posterize: { ...DEFAULT_POSTERIZE },+ threshold: { ...DEFAULT_THRESHOLD },};state.project.layers[id] = layer;artboard.layerIds.unshift(id);@@ -346,6 +367,13 @@ export const useProjectStore = create<ProjectState & ProjectActions>()(levels: { ...DEFAULT_LEVELS },curves: { ...DEFAULT_CURVES },colorBalance: { ...DEFAULT_COLOR_BALANCE },+ selectiveColor: { ...DEFAULT_SELECTIVE_COLOR },+ blackWhite: { ...DEFAULT_BLACK_WHITE },+ photoFilter: { ...DEFAULT_PHOTO_FILTER },+ channelMixer: { ...DEFAULT_CHANNEL_MIXER },+ gradientMap: { ...DEFAULT_GRADIENT_MAP },+ posterize: { ...DEFAULT_POSTERIZE },+ threshold: { ...DEFAULT_THRESHOLD },};state.project.layers[id] = layer;artboard.layerIds.unshift(id);@@ -411,6 +439,13 @@ export const useProjectStore = create<ProjectState & ProjectActions>()(levels: { ...DEFAULT_LEVELS },curves: { ...DEFAULT_CURVES },colorBalance: { ...DEFAULT_COLOR_BALANCE },+ selectiveColor: { ...DEFAULT_SELECTIVE_COLOR },+ blackWhite: { ...DEFAULT_BLACK_WHITE },+ photoFilter: { ...DEFAULT_PHOTO_FILTER },+ channelMixer: { ...DEFAULT_CHANNEL_MIXER },+ gradientMap: { ...DEFAULT_GRADIENT_MAP },+ posterize: { ...DEFAULT_POSTERIZE },+ threshold: { ...DEFAULT_THRESHOLD },};state.project.layers[id] = layer;artboard.layerIds.unshift(id);@@ -484,6 +519,13 @@ export const useProjectStore = create<ProjectState & ProjectActions>()(levels: { ...DEFAULT_LEVELS },curves: { ...DEFAULT_CURVES },colorBalance: { ...DEFAULT_COLOR_BALANCE },+ selectiveColor: { ...DEFAULT_SELECTIVE_COLOR },+ blackWhite: { ...DEFAULT_BLACK_WHITE },+ photoFilter: { ...DEFAULT_PHOTO_FILTER },+ channelMixer: { ...DEFAULT_CHANNEL_MIXER },+ gradientMap: { ...DEFAULT_GRADIENT_MAP },+ posterize: { ...DEFAULT_POSTERIZE },+ threshold: { ...DEFAULT_THRESHOLD },};state.project.layers[id] = layer;diff --git a/apps/image/src/types/project.ts b/apps/image/src/types/project.tsindex 44693561..d1d8514d 100644--- a/apps/image/src/types/project.ts+++ b/apps/image/src/types/project.ts@@ -3,6 +3,13 @@ import type {LevelsAdjustment,CurvesAdjustment,ColorBalanceAdjustment,+ SelectiveColorAdjustment,+ BlackWhiteAdjustment,+ PhotoFilterAdjustment,+ ChannelMixerAdjustment,+ GradientMapAdjustment,+ PosterizeAdjustment,+ ThresholdAdjustment,} from './adjustments';export type LayerType = 'image' | 'text' | 'shape' | 'group';@@ -97,6 +104,13 @@ export interface BaseLayer {levels: LevelsAdjustment;curves: CurvesAdjustment;colorBalance: ColorBalanceAdjustment;+ selectiveColor: SelectiveColorAdjustment;+ blackWhite: BlackWhiteAdjustment;+ photoFilter: PhotoFilterAdjustment;+ channelMixer: ChannelMixerAdjustment;+ gradientMap: GradientMapAdjustment;+ posterize: PosterizeAdjustment;+ threshold: ThresholdAdjustment;}export interface ImageLayer extends BaseLayer {@@ -312,7 +326,18 @@ export const DEFAULT_INNER_SHADOW: InnerShadow = {};export { DEFAULT_LAYER_MASK } from './mask';-export { DEFAULT_LEVELS, DEFAULT_CURVES, DEFAULT_COLOR_BALANCE } from './adjustments';+export {+ DEFAULT_LEVELS,+ DEFAULT_CURVES,+ DEFAULT_COLOR_BALANCE,+ DEFAULT_SELECTIVE_COLOR,+ DEFAULT_BLACK_WHITE,+ DEFAULT_PHOTO_FILTER,+ DEFAULT_CHANNEL_MIXER,+ DEFAULT_GRADIENT_MAP,+ DEFAULT_POSTERIZE,+ DEFAULT_THRESHOLD,+} from './adjustments';export const DEFAULT_FILTER: Filter = {brightness: 100,diff --git a/apps/image/src/utils/apply-adjustments.ts b/apps/image/src/utils/apply-adjustments.tsnew file mode 100644index 00000000..ab54b768--- /dev/null+++ b/apps/image/src/utils/apply-adjustments.ts@@ -0,0 +1,143 @@+import type {+ LevelsAdjustment,+ CurvesAdjustment,+ ColorBalanceAdjustment,+ SelectiveColorAdjustment,+ BlackWhiteAdjustment,+ PhotoFilterAdjustment,+ ChannelMixerAdjustment,+ GradientMapAdjustment,+ PosterizeAdjustment,+ ThresholdAdjustment,+} from '../types/adjustments';++import {+ applyLevelsToImageData,+ applyCurvesToImageData,+ applyColorBalanceToImageData,+ applyBlackWhiteToImageData,+ applyGradientMapToImageData,+ applyPosterizeToImageData,+ applyThresholdToImageData,+} from '../types/adjustments';++import { applySelectiveColor } from '../adjustments/selective-color';+import { applyPhotoFilter } from '../adjustments/photo-filter';+import { applyChannelMixer } from '../adjustments/channel-mixer';++export interface LayerAdjustments {+ levels: LevelsAdjustment;+ curves: CurvesAdjustment;+ colorBalance: ColorBalanceAdjustment;+ selectiveColor: SelectiveColorAdjustment;+ blackWhite: BlackWhiteAdjustment;+ photoFilter: PhotoFilterAdjustment;+ channelMixer: ChannelMixerAdjustment;+ gradientMap: GradientMapAdjustment;+ posterize: PosterizeAdjustment;+ threshold: ThresholdAdjustment;+}++export function hasActiveAdjustments(adjustments: LayerAdjustments): boolean {+ return (+ adjustments.levels.enabled ||+ adjustments.curves.enabled ||+ adjustments.colorBalance.enabled ||+ adjustments.selectiveColor.enabled ||+ adjustments.blackWhite.enabled ||+ adjustments.photoFilter.enabled ||+ adjustments.channelMixer.enabled ||+ adjustments.gradientMap.enabled ||+ adjustments.posterize.enabled ||+ adjustments.threshold.enabled+ );+}++export function applyAllAdjustments(+ imageData: ImageData,+ adjustments: LayerAdjustments+): ImageData {+ let result = imageData;++ if (adjustments.levels.enabled) {+ result = applyLevelsToImageData(result, adjustments.levels);+ }++ if (adjustments.curves.enabled) {+ result = applyCurvesToImageData(result, adjustments.curves);+ }++ if (adjustments.colorBalance.enabled) {+ result = applyColorBalanceToImageData(result, adjustments.colorBalance);+ }++ if (adjustments.selectiveColor.enabled) {+ result = applySelectiveColor(result, {+ reds: adjustments.selectiveColor.reds,+ yellows: adjustments.selectiveColor.yellows,+ greens: adjustments.selectiveColor.greens,+ cyans: adjustments.selectiveColor.cyans,+ blues: adjustments.selectiveColor.blues,+ magentas: adjustments.selectiveColor.magentas,+ whites: adjustments.selectiveColor.whites,+ neutrals: adjustments.selectiveColor.neutrals,+ blacks: adjustments.selectiveColor.blacks,+ method: adjustments.selectiveColor.method,+ });+ }++ if (adjustments.photoFilter.enabled) {+ result = applyPhotoFilter(result, {+ filter: adjustments.photoFilter.filter,+ color: adjustments.photoFilter.color,+ density: adjustments.photoFilter.density,+ preserveLuminosity: adjustments.photoFilter.preserveLuminosity,+ });+ }++ if (adjustments.channelMixer.enabled) {+ result = applyChannelMixer(result, {+ red: {+ red: adjustments.channelMixer.red.red,+ green: adjustments.channelMixer.red.green,+ blue: adjustments.channelMixer.red.blue,+ constant: adjustments.channelMixer.red.constant,+ },+ green: {+ red: adjustments.channelMixer.green.red,+ green: adjustments.channelMixer.green.green,+ blue: adjustments.channelMixer.green.blue,+ constant: adjustments.channelMixer.green.constant,+ },+ blue: {+ red: adjustments.channelMixer.blue.red,+ green: adjustments.channelMixer.blue.green,+ blue: adjustments.channelMixer.blue.blue,+ constant: adjustments.channelMixer.blue.constant,+ },+ monochrome: adjustments.channelMixer.monochrome,+ monoRed: 40,+ monoGreen: 40,+ monoBlue: 20,+ monoConstant: 0,+ });+ }++ if (adjustments.blackWhite.enabled) {+ result = applyBlackWhiteToImageData(result, adjustments.blackWhite);+ }++ if (adjustments.gradientMap.enabled) {+ result = applyGradientMapToImageData(result, adjustments.gradientMap);+ }++ if (adjustments.posterize.enabled) {+ result = applyPosterizeToImageData(result, adjustments.posterize);+ }++ if (adjustments.threshold.enabled) {+ result = applyThresholdToImageData(result, adjustments.threshold);+ }++ return result;+}