From fe0e02639a9a8b7840a4d324a0a87df8a0336634 Mon Sep 17 00:00:00 2001 From: Kevin Arthur Date: Thu, 29 Oct 2026 16:29:45 -0700 Subject: [PATCH 1/3] refactor(editor): split adjustment editor into adjustmentEditors/ modules (Batch B/B-11) Pure code motion: the 2,405-line AdjustmentEditor.tsx becomes a 15-line definition shell (same four named exports, dispatcher body verbatim, CSS import once) plus 24 modules under adjustmentEditors/ (every module <=400 lines; largest 322). LegacyAdjustmentEditor (807 lines) is split into a runtime hook (hooks and hueSaturationRange state stay in the base order) plus four plain phase renderers that keep the switch's case bodies verbatim; the nested LutEditor stays nested so its remount semantics are unchanged. HalftoneEditor (446 lines) becomes a hook, a shell with the S1-S5 JSX verbatim, and an unconditionally mounted advanced phase so the disclosure state lifetime is unchanged. BooleanRow, AdjustmentEditorProps, the family editors, the color converters, and the halftone options each get exactly one home; the original path re-exports the moved public names by name. Proof: refactor-verify --base master --dest .../adjustmentEditors exit 0 {ok:true, baseCount:24, presentCount:33, missing:[], missingExports:[]}; covering suite AdjustmentEditor.test.tsx + AdjustmentPanel.test.tsx 32/32 passed before and after (18/18 direct target, test untouched); direct recursive tsc substitute 22 projects exit 0 with 0 diagnostics; biome clean; audit-health passed; partition proof 2,405 = 50 import-region + 2,307 moved + 23 wrapper + 25 blank lines. Baseline: 0 added, 0 grown, exactly one removed, 945 -> 944; repo map regenerated from the staged tree. No visual surface changed; no e2e/visual/lockfile/manifest/dated-doc changes. (cherry picked from commit 42207fee2f17e2b27508f9845467673d80aebff2) --- .../AdjustmentLayer/AdjustmentEditor.tsx | 2400 +---------------- .../LegacyAdjustmentEditor.tsx | 32 + .../adjustmentEditors/blackAndWhite.tsx | 83 + .../adjustmentEditors/channelMixer.tsx | 89 + .../adjustmentEditors/controls.tsx | 25 + .../adjustmentEditors/curves.tsx | 133 + .../adjustmentEditors/duotone.tsx | 125 + .../halftone/ColorHalftoneEditor.tsx | 181 ++ .../halftone/HalftoneAdvancedPhase.tsx | 175 ++ .../halftone/HalftoneEditor.tsx | 258 ++ .../adjustmentEditors/halftone/options.ts | 12 + .../halftone/useHalftoneModel.ts | 100 + .../legacy/renderChannelCases.tsx | 322 +++ .../legacy/renderEffectCases.tsx | 125 + .../legacy/renderLuminanceCases.tsx | 193 ++ .../legacy/renderTonalCases.tsx | 233 ++ .../legacy/useLegacyEditorContext.ts | 55 + .../adjustmentEditors/levels.tsx | 95 + .../adjustmentEditors/managedColor.ts | 23 + .../adjustmentEditors/photoFilter.tsx | 52 + .../adjustmentEditors/posterize.tsx | 22 + .../adjustmentEditors/selectiveColor.tsx | 60 + .../adjustmentEditors/shadowHighlight.tsx | 71 + .../adjustmentEditors/tritone.tsx | 173 ++ .../adjustmentEditors/types.ts | 23 + remediation/B-11/GAP_ANALYSIS.md | 88 + remediation/B-11/RESEARCH.md | 263 ++ remediation/B-11/SEAM_SPEC.md | 400 +++ 28 files changed, 3416 insertions(+), 2395 deletions(-) create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/LegacyAdjustmentEditor.tsx create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/blackAndWhite.tsx create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/channelMixer.tsx create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/controls.tsx create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/curves.tsx create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/duotone.tsx create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/halftone/ColorHalftoneEditor.tsx create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/halftone/HalftoneAdvancedPhase.tsx create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/halftone/HalftoneEditor.tsx create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/halftone/options.ts create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/halftone/useHalftoneModel.ts create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/legacy/renderChannelCases.tsx create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/legacy/renderEffectCases.tsx create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/legacy/renderLuminanceCases.tsx create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/legacy/renderTonalCases.tsx create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/legacy/useLegacyEditorContext.ts create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/levels.tsx create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/managedColor.ts create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/photoFilter.tsx create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/posterize.tsx create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/selectiveColor.tsx create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/shadowHighlight.tsx create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/tritone.tsx create mode 100644 packages/editor/src/components/AdjustmentLayer/adjustmentEditors/types.ts create mode 100644 remediation/B-11/GAP_ANALYSIS.md create mode 100644 remediation/B-11/RESEARCH.md create mode 100644 remediation/B-11/SEAM_SPEC.md diff --git a/packages/editor/src/components/AdjustmentLayer/AdjustmentEditor.tsx b/packages/editor/src/components/AdjustmentLayer/AdjustmentEditor.tsx index 40354e4987..7160a96da8 100644 --- a/packages/editor/src/components/AdjustmentLayer/AdjustmentEditor.tsx +++ b/packages/editor/src/components/AdjustmentLayer/AdjustmentEditor.tsx @@ -1,98 +1,11 @@ -import { - autoContrastParams, - COLOR_HALFTONE_PRESETS, - type Color, - type CurvePoint, - compileCurve, - curveChannels, - DOC_PIXELS_PER_INCH, - HALFTONE_PRESETS, - isImageTreatmentKind, - isLutInputSpaceImplemented, - LUT_INPUT_SPACE_LABELS, - mixerRows, - parseLutFile, - serializeLutForDocument, - TRITONE_PRESETS, -} from '@varve/engine'; -import type { CoordSpace } from '@varve/engine/liveEffects'; -import type { Adjustment, AdjustmentNode, Document, ManagedColor } from '@varve/scene'; -import { rgbFromTuple } from '@varve/scene'; -import { denormalizeChannel, managedColorToRgba, normalizeChannel } from '@varve/shared'; -import { Button, FilePickerButton, Select, Switch } from '@varve/ui'; -import { ColorPicker } from '@varve/ui/components/ColorPicker'; -import { useCallback, useMemo, useState } from 'react'; -import { CurveEditor } from '../Inspector/controls/CurveEditor'; -import { DisclosureSection } from '../Inspector/controls/DisclosureSection'; -import { GradientMapAdjustmentSection } from '../Inspector/controls/GradientMapAdjustmentSection'; -import { HistogramWidget } from '../Inspector/controls/HistogramWidget'; -import { NumberField } from '../Inspector/controls/NumberField'; -import { RangeValueControl } from '../Inspector/controls/RangeValueControl'; -import { ColorBalanceAdjustmentEditor } from './ColorBalanceAdjustmentEditor'; +import { isImageTreatmentKind } from '@varve/engine'; +import { LegacyAdjustmentEditor } from './adjustmentEditors/LegacyAdjustmentEditor'; +import type { AdjustmentEditorProps } from './adjustmentEditors/types'; import { ImageTreatmentEditor } from './ImageTreatmentEditor'; -import { - BloomEditor, - CausticsEditor, - CrtEditor, - DitherEditor, - LensFlareEditor, - LightLeakEditor, - LightShaftsEditor, - PaletteSnapEditor, - RgbSplitEditor, - VhsEditor, -} from './LiveEffectEditors'; -import { SharpenEditor } from './SharpenEditor'; -import { SourceChannels } from './SourceChannels'; -import { SpatialEffectEditor } from './SpatialEffectEditors'; -import { ThresholdAdjustmentEditor } from './ThresholdAdjustmentEditor'; -import { SplitToneEditor, WhiteBalanceEditor } from './TonalColorEditors'; import './adjustment.css'; -export interface AdjustmentEditorProps { - adjustment: Adjustment; - onChange: (patch: Partial) => void; - onEditStart?: () => void; - onEditEnd?: () => void; - /** Document for palette import sources (document swatches). */ - doc?: Document; - /** - * Source histogram for the adjustment's scope targets. - * Computed asynchronously by useAdjustmentHistogram. - * Used by Levels (HistogramWidget) and Curves (background display). - */ - sourceHistogram?: import('@varve/engine').Histogram | null; - /** Human-readable stage represented by the histogram diagnostic. */ - histogramSourceLabel?: string; - histogramLoading?: boolean; - sourceImageData?: ImageData | null; - sourceCoordSpace?: CoordSpace | null; - detailScope?: AdjustmentNode; -} - -function BooleanRow({ - label, - checked, - onChange, - ariaLabel, -}: { - label: string; - checked: boolean; - onChange: (value: boolean) => void; - ariaLabel?: string; -}) { - return ( -
- onChange(event.target.checked)} - aria-label={ariaLabel ?? label} - /> -
- ); -} +export { curvePointsToCurvesPoints, curvesPointsToCurvePoints } from './adjustmentEditors/curves'; +export type { AdjustmentEditorProps } from './adjustmentEditors/types'; export function AdjustmentEditor(props: AdjustmentEditorProps) { if (isImageTreatmentKind(props.adjustment.kind)) { @@ -100,2306 +13,3 @@ export function AdjustmentEditor(props: AdjustmentEditorProps) { } return ; } - -function LegacyAdjustmentEditor({ - adjustment, - onChange, - onEditStart, - onEditEnd, - doc, - sourceHistogram, - histogramSourceLabel, - histogramLoading, - sourceImageData, - sourceCoordSpace, - detailScope, -}: AdjustmentEditorProps) { - const handleValue = useCallback( - (key: string) => (value: number) => { - onChange({ [key]: value } as Partial); - }, - [onChange], - ); - - const handleNumber = useCallback( - (key: string) => (e: React.ChangeEvent) => { - const v = Number.parseFloat(e.target.value); - if (!Number.isNaN(v)) { - onChange({ [key]: v } as Partial); - } - }, - [onChange], - ); - const [hueSaturationRange, setHueSaturationRange] = useState('master'); - - switch (adjustment.kind) { - case 'whiteBalance': - return ( - - ); - case 'splitTone': - return ; - case 'brightness': - return ( -
-
- Brightness - {adjustment.value} -
- -
- ); - - case 'contrast': - return ( -
-
- Contrast - {adjustment.value} -
- -
- ); - - case 'levels': - return ( - - ); - - case 'curves': - return ( - - ); - - case 'selectiveColor': - return ( - - ); - - case 'colorBalance': - return ( - - ); - - case 'exposure': - return ( -
-
- EV - {adjustment.value} -
- -
- Offset - -
-
- Gamma - -
-
- ); - - case 'temperature': - return ( -
-
- Temperature - {adjustment.value} -
- -
- ); - - case 'saturation': - return ( -
-
- Saturation - {adjustment.value} -
- -
- ); - - case 'hueSaturation': { - const ranges = adjustment.ranges as Record< - string, - { hue: number; saturation: number; lightness: number } - >; - const activeRange = hueSaturationRange; - const active = ranges[activeRange] ?? - ranges.master ?? { hue: 0, saturation: 0, lightness: 0 }; - const updateRange = (key: 'hue' | 'saturation' | 'lightness', value: number) => - onChange({ - ranges: { - ...ranges, - [activeRange]: { ...active, [key]: value }, - }, - } as Partial); - return ( -
- - onChange({ - interpolation: v as 'nearest' | 'trilinear' | 'tetrahedral', - } as unknown as Partial) - } - /> -
- -
- Input Space - -
- onChange(paramsToLevelsAdjustmentPatch(params))} - channel={histogramChannel} - onChannelChange={(channel) => - handleSelect('channel')(channel === 'luminance' ? 'rgb' : channel) - } - onDragStart={onEditStart} - onDragEnd={onEditEnd} - /> - - - ); -} - -// CurvesAdjustment.points ({input, output}, 0-255, document/render space) and -// CurveEditor's CurvePoint ({x, y}, 0-1, plot space) are the same tonal curve -// in two different unit systems — a straight linear scale, not a lossy or -// structural conversion. Order is preserved (not re-sorted) so a drag that -// moves one point doesn't reshuffle the others; CurveEditor already sorts by -// x internally for rendering/hit-testing. -export function curvesPointsToCurvePoints( - points: import('@varve/scene').CurvesPoint[], -): CurvePoint[] { - return points.map((p) => ({ - ...(p.id ? { id: p.id } : {}), - x: p.input / 255, - y: p.output / 255, - })); -} - -export function curvePointsToCurvesPoints( - points: CurvePoint[], -): import('@varve/scene').CurvesPoint[] { - return points.map((p) => ({ - ...(p.id ? { id: p.id } : {}), - input: Math.max(0, Math.min(1, p.x)) * 255, - output: Math.max(0, Math.min(1, p.y)) * 255, - })); -} - -function CurvesEditor({ - adjustment, - onChange, - onEditStart, - onEditEnd, - sourceHistogram, - histogramSourceLabel, - histogramLoading, - sourceImageData, -}: AdjustmentEditorProps) { - const adj = adjustment as import('@varve/scene').CurvesAdjustment; - const channels = curveChannels(adj); - const changeChannel = (channel: 'rgb' | 'red' | 'green' | 'blue') => - onChange({ - channel, - points: channels[channel] ?? [], - channelPoints: channels, - } as Partial); - const changePoints = (points: CurvePoint[]) => { - const authored = curvePointsToCurvesPoints(points); - onChange({ - points: authored, - channelPoints: { ...channels, [adj.channel]: authored }, - } as Partial); - }; - - return ( -
- {(histogramSourceLabel || histogramLoading) && ( -
- {histogramLoading ? 'Loading histogram…' : `Histogram: ${histogramSourceLabel}`} -
- )} - -
- onChange({ relative: value } as unknown as Partial)} - ariaLabel="Relative adjustment" - /> - {(['cyan', 'magenta', 'yellow', 'black'] as const).map((channel) => ( -
-
- {channel.charAt(0).toUpperCase() + channel.slice(1)} - {adj[channel]} -
- -
- ))} - - ); -} - -function ChannelMixerEditor({ adjustment, onChange }: AdjustmentEditorProps) { - const adj = adjustment as import('@varve/scene').ChannelMixerAdjustment; - const rows = mixerRows(adj), - active = adj.monochrome ? 'red' : adj.outputChannel, - row = rows[active]; - const patchRow = (key: keyof typeof row, value: number) => { - const updated = { ...row, [key]: value }; - onChange({ ...updated, rows: { ...rows, [active]: updated } } as Partial); - }; - return ( -
- ({ value: p.id, label: p.name }))} - onChange={handlePresetSelect} - /> -
-
- Method - -
- )} - {method === 'fm' && (adj.fmAlgorithm ?? 'blue-noise') === 'error-diffusion' && ( -

- Error diffusion is a full-frame algorithm. Newly created effects keep preview and export - identical; legacy documents that selected it show the blue-noise preview while exporting - with error diffusion. -

- )} - {method === 'am' && ( -
- Shape - -
-
-
- Frequency (LPI) - {adj.frequency} -
- -

- Period {periodPx.toFixed(2)} px at 96 ppi - {periodPx < 3 ? ' — increase export resolution to resolve this ruling.' : '.'} -

-
-
-
- Angle - {adj.angle}° -
- -
-
-
- Threshold - {adj.threshold ?? 128} -
- -
-
-
- Intensity - {Math.round((adj.intensity ?? 1) * 100)}% -
- - onChange({ intensity: value / 100 } as unknown as Partial) - } - /> -
-
-
- Softness - {Math.round((adj.softness ?? 0) * 100)}% -
- - onChange({ softness: value / 100 } as unknown as Partial) - } - /> -
- onChange({ invert: value } as unknown as Partial)} - ariaLabel="Invert halftone output" - /> - {isMonoChannel && ( - <> -
- Ink Color - { - const rgb = managedColorToRgba(c); - onChange({ - foregroundColor: [rgb[0], rgb[1], rgb[2]], - } as unknown as Partial); - }} - /> -
-
- Paper Color - { - const rgb = managedColorToRgba(c); - onChange({ - backgroundColor: [rgb[0], rgb[1], rgb[2]], - } as unknown as Partial); - }} - /> -
- - )} - {isMonoChannel && method === 'am' && ( -
- Alpha - -
- {(adj.blackGeneration ?? 'none') !== 'none' && ( -
-
- Black strength - {Math.round((adj.gcrStrength ?? 0.5) * 100)}% -
- - onChange({ gcrStrength: value / 100 } as unknown as Partial) - } - /> -
- )} -
-
- Total ink limit - {Math.round((adj.tacLimit ?? 1) * 100)}% -
- - onChange({ tacLimit: value / 100 } as unknown as Partial) - } - /> -
-
- Show ink - { - const value = Number(event.target.value); - if (event.target.value === '') { - const next = { ...channelAngles }; - delete next[ink]; - onChange({ channelAngles: next } as unknown as Partial); - } else { - setChannelAngle(ink)(value); - } - }} - /> - - setRegistrationOffset(ink, 0)(Number(event.target.value)) - } - /> - - setRegistrationOffset(ink, 1)(Number(event.target.value)) - } - /> -
- - ))} -

- CMYK is an uncalibrated process-screen preview, not an ICC separation. Per-channel - angles override the standard press angles (C 15°, M 75°, Y 0°, K 45°); offsets are - in document pixels. -

- - )} - {isMonoChannel && ( - <> -
-
- Dot gain - {Math.round((adj.dotGain ?? 0) * 100)}% -
- - onChange({ dotGain: value / 100 } as unknown as Partial) - } - /> -
-

- Dot gain expands midtone coverage as printed ink spreads, without changing the paper - or solid endpoints. -

- - )} - - )} - - ); -} - -function ColorHalftoneEditor({ - adjustment, - onChange, - onEditStart, - onEditEnd, -}: AdjustmentEditorProps) { - const adj = adjustment as import('@varve/engine').ColorHalftoneAdjustment; - const handleSelect = (key: string) => (value: string) => { - onChange({ [key]: value } as unknown as Partial); - }; - const handleValue = (key: string) => (value: number) => { - onChange({ [key]: value } as unknown as Partial); - }; - - const currentPresetId = useMemo(() => { - const match = COLOR_HALFTONE_PRESETS.find( - (p) => - p.params.screenSize === adj.screenSize && - p.params.angle === adj.angle && - p.params.dotShape === adj.dotShape && - p.params.mode === adj.mode, - ); - return match?.id ?? ''; - }, [adj]); - - const handlePresetSelect = (value: string) => { - const preset = COLOR_HALFTONE_PRESETS.find((p) => p.id === value); - if (preset) { - onChange({ - screenSize: preset.params.screenSize, - angle: preset.params.angle, - dotShape: preset.params.dotShape, - mode: preset.params.mode, - algorithmVersion: 2, - inkColor: preset.params.inkColor ? ([...preset.params.inkColor] as Color) : undefined, - } as unknown as Partial); - } - }; - - const isLegacy = adj.algorithmVersion === 1; - const periodPx = DOC_PIXELS_PER_INCH / Math.max(1, adj.screenSize); - - return ( -
- {isLegacy && ( - <> -
- Legacy screen - -
-

- This effect used a screen whose tone was inverted and whose mix double-counted black. - Updating keeps its settings and corrects the output. -

- - )} -
- Preset - -
-
- Dot Shape - - onChange({ - interpolation: value as 'smoothstep' | 'linear', - } as unknown as Partial) - } - /> -
-
- ); -} - -function BlackAndWhiteEditor({ - adjustment, - onChange, - onEditStart, - onEditEnd, -}: AdjustmentEditorProps) { - const adj = adjustment as import('@varve/scene').BlackAndWhiteAdjustment; - const channels: { key: keyof import('@varve/scene').BlackAndWhiteAdjustment; label: string }[] = [ - { key: 'reds', label: 'Reds' }, - { key: 'yellows', label: 'Yellows' }, - { key: 'greens', label: 'Greens' }, - { key: 'cyans', label: 'Cyans' }, - { key: 'blues', label: 'Blues' }, - { key: 'magentas', label: 'Magentas' }, - ]; - - return ( -
- {channels.map((ch) => ( -
-
- {ch.label} - {adj[ch.key] as number} -
- onChange({ [ch.key]: value } as unknown as Partial)} - /> -
- ))} -
-
- Brightness - {adj.brightness} -
- onChange({ brightness: value } as unknown as Partial)} - /> -
- - onChange({ preserveLuminosity: value } as unknown as Partial) - } - /> - - onChange({ - tintColor: value ? ([190, 170, 140, 255] as Color) : undefined, - } as unknown as Partial) - } - /> - {adj.tintColor && ( - - onChange({ tintColor: managedToColor(color) } as unknown as Partial) - } - onInteractionStart={onEditStart} - onInteractionEnd={onEditEnd} - /> - )} -
- ); -} - -function PosterizeEditor({ adjustment, onChange }: AdjustmentEditorProps) { - const adj = adjustment as import('@varve/scene').PosterizeAdjustment; - return ( -
-
- Levels - {adj.levels} -
- onChange({ levels: value } as unknown as Partial)} - /> -
- ); -} - -function TritoneEditor({ adjustment, onChange, onEditStart, onEditEnd }: AdjustmentEditorProps) { - const adj = adjustment as import('@varve/scene').TritoneAdjustment; - const handleColor = - (key: 'shadowColor' | 'midtoneColor' | 'highlightColor') => (c: ManagedColor) => { - onChange({ [key]: managedToColor(c) } as unknown as Partial); - }; - - const currentPresetId = useMemo(() => { - const match = TRITONE_PRESETS.find( - (p) => - p.shadowColor[0] === adj.shadowColor[0] && - p.shadowColor[1] === adj.shadowColor[1] && - p.shadowColor[2] === adj.shadowColor[2] && - p.midtoneColor[0] === adj.midtoneColor[0] && - p.midtoneColor[1] === adj.midtoneColor[1] && - p.midtoneColor[2] === adj.midtoneColor[2] && - p.highlightColor[0] === adj.highlightColor[0] && - p.highlightColor[1] === adj.highlightColor[1] && - p.highlightColor[2] === adj.highlightColor[2] && - Math.abs(p.shadowPoint - adj.shadowPoint) < 0.01 && - Math.abs(p.highlightPoint - adj.highlightPoint) < 0.01, - ); - return match?.id ?? ''; - }, [adj]); - - const handlePresetSelect = (value: string) => { - const preset = TRITONE_PRESETS.find((p) => p.id === value); - if (preset) { - onChange({ - shadowColor: [...preset.shadowColor] as Color, - midtoneColor: [...preset.midtoneColor] as Color, - highlightColor: [...preset.highlightColor] as Color, - shadowPoint: preset.shadowPoint, - highlightPoint: preset.highlightPoint, - } as unknown as Partial); - } - }; - - return ( -
-
- Preset - - onChange({ - interpolation: v as 'smoothstep' | 'linear', - } as unknown as Partial) - } - /> -
-
- ); -} diff --git a/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/LegacyAdjustmentEditor.tsx b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/LegacyAdjustmentEditor.tsx new file mode 100644 index 0000000000..f88866308e --- /dev/null +++ b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/LegacyAdjustmentEditor.tsx @@ -0,0 +1,32 @@ +import type { Adjustment } from '@varve/scene'; +import { renderChannelCases } from './legacy/renderChannelCases'; +import { renderEffectCases } from './legacy/renderEffectCases'; +import { renderLuminanceCases } from './legacy/renderLuminanceCases'; +import { renderTonalCases } from './legacy/renderTonalCases'; +import { useLegacyEditorContext } from './legacy/useLegacyEditorContext'; +import type { AdjustmentEditorProps } from './types'; + +export function LegacyAdjustmentEditor(props: AdjustmentEditorProps) { + const context = useLegacyEditorContext(props); + + const luminance = renderLuminanceCases(context); + if (luminance !== undefined) return luminance; + + const tonal = renderTonalCases(context); + if (tonal !== undefined) return tonal; + + const channel = renderChannelCases(context); + if (channel !== undefined) return channel; + + const effects = renderEffectCases(context); + if (effects !== undefined) return effects; + + const { adjustment } = props; + return ( +
+ + No editor for {(adjustment as Adjustment).kind} + +
+ ); +} diff --git a/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/blackAndWhite.tsx b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/blackAndWhite.tsx new file mode 100644 index 0000000000..1ec53b33e3 --- /dev/null +++ b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/blackAndWhite.tsx @@ -0,0 +1,83 @@ +import type { Color } from '@varve/engine'; +import type { Adjustment } from '@varve/scene'; +import { ColorPicker } from '@varve/ui/components/ColorPicker'; +import { RangeValueControl } from '../../Inspector/controls/RangeValueControl'; +import { BooleanRow } from './controls'; +import { colorToManaged, managedToColor } from './managedColor'; +import type { AdjustmentEditorProps } from './types'; + +export function BlackAndWhiteEditor({ + adjustment, + onChange, + onEditStart, + onEditEnd, +}: AdjustmentEditorProps) { + const adj = adjustment as import('@varve/scene').BlackAndWhiteAdjustment; + const channels: { key: keyof import('@varve/scene').BlackAndWhiteAdjustment; label: string }[] = [ + { key: 'reds', label: 'Reds' }, + { key: 'yellows', label: 'Yellows' }, + { key: 'greens', label: 'Greens' }, + { key: 'cyans', label: 'Cyans' }, + { key: 'blues', label: 'Blues' }, + { key: 'magentas', label: 'Magentas' }, + ]; + + return ( +
+ {channels.map((ch) => ( +
+
+ {ch.label} + {adj[ch.key] as number} +
+ onChange({ [ch.key]: value } as unknown as Partial)} + /> +
+ ))} +
+
+ Brightness + {adj.brightness} +
+ onChange({ brightness: value } as unknown as Partial)} + /> +
+ + onChange({ preserveLuminosity: value } as unknown as Partial) + } + /> + + onChange({ + tintColor: value ? ([190, 170, 140, 255] as Color) : undefined, + } as unknown as Partial) + } + /> + {adj.tintColor && ( + + onChange({ tintColor: managedToColor(color) } as unknown as Partial) + } + onInteractionStart={onEditStart} + onInteractionEnd={onEditEnd} + /> + )} +
+ ); +} diff --git a/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/channelMixer.tsx b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/channelMixer.tsx new file mode 100644 index 0000000000..7902ee8847 --- /dev/null +++ b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/channelMixer.tsx @@ -0,0 +1,89 @@ +import { mixerRows } from '@varve/engine'; +import type { Adjustment } from '@varve/scene'; +import { Button, Select } from '@varve/ui'; +import { NumberField } from '../../Inspector/controls/NumberField'; +import { BooleanRow } from './controls'; +import type { AdjustmentEditorProps } from './types'; + +export function ChannelMixerEditor({ adjustment, onChange }: AdjustmentEditorProps) { + const adj = adjustment as import('@varve/scene').ChannelMixerAdjustment; + const rows = mixerRows(adj), + active = adj.monochrome ? 'red' : adj.outputChannel, + row = rows[active]; + const patchRow = (key: keyof typeof row, value: number) => { + const updated = { ...row, [key]: value }; + onChange({ ...updated, rows: { ...rows, [active]: updated } } as Partial); + }; + return ( +
+ onChange({ algorithmVersion: Number(v) as 1 | 2 } as Partial)} + /> + + +

+ Sample upstream input to add a point on the current transfer. RGB uses the arithmetic mean + of the three encoded components. +

+ { + if (!sourceImageData || (channels[adj.channel]?.length ?? 0) >= 256) return; + const at = (y * sourceImageData.width + x) * 4; + if (sourceImageData.data[at + 3] === 0) return; + const c = { red: 0, green: 1, blue: 2 }; + let input = + adj.channel === 'rgb' + ? (sourceImageData.data[at]! + + sourceImageData.data[at + 1]! + + sourceImageData.data[at + 2]!) / + 3 + : sourceImageData.data[at + c[adj.channel]]!; + if (adj.channel !== 'rgb') { + input = + compileCurve( + curvesPointsToCurvePoints(channels.rgb ?? []), + adj.algorithmVersion === 2 ? 'pchip' : 'legacy', + )(input / 255) * 255; + } + const points = curvesPointsToCurvePoints(channels[adj.channel] ?? []); + const output = compileCurve( + points, + adj.algorithmVersion === 2 ? 'pchip' : 'legacy', + )(input / 255); + changePoints([...points, { id: crypto.randomUUID(), x: input / 255, y: output }]); + }} + /> +
+ ); +} diff --git a/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/duotone.tsx b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/duotone.tsx new file mode 100644 index 0000000000..61b4a8d3f3 --- /dev/null +++ b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/duotone.tsx @@ -0,0 +1,125 @@ +import type { Adjustment, ManagedColor } from '@varve/scene'; +import { Select } from '@varve/ui'; +import { ColorPicker } from '@varve/ui/components/ColorPicker'; +import { RangeValueControl } from '../../Inspector/controls/RangeValueControl'; +import { BooleanRow } from './controls'; +import { managedToColor } from './managedColor'; +import type { AdjustmentEditorProps } from './types'; + +export function DuotoneEditor({ + adjustment, + onChange, + onEditStart, + onEditEnd, +}: AdjustmentEditorProps) { + const adj = adjustment as import('@varve/scene').DuotoneAdjustment; + const handleColor = (key: 'shadowColor' | 'highlightColor') => (c: ManagedColor) => { + onChange({ [key]: managedToColor(c) } as unknown as Partial); + }; + + return ( +
+
+
+ Shadow Point + {adj.shadowPoint.toFixed(2)} +
+ onChange({ shadowPoint: value } as unknown as Partial)} + /> +
+
+
+ Highlight Point + {adj.highlightPoint.toFixed(2)} +
+ + onChange({ highlightPoint: value } as unknown as Partial) + } + /> +
+
+
+ Intensity + {adj.intensity.toFixed(2)} +
+ onChange({ intensity: value } as unknown as Partial)} + /> +
+
+ Shadow Color + +
+
+ Highlight Color + +
+ + onChange({ preserveLuminosity: value } as unknown as Partial) + } + /> +
+ Interpolation + ({ value: p.id, label: p.name }))} + onChange={handlePresetSelect} + /> +
+
+ Mode + +
+
+
+ Screen Size + {adj.screenSize} LPI +
+ +

+ Period {periodPx.toFixed(2)} px at 96 ppi. + {adj.mode === 'cmyk' + ? ' CMYK is an uncalibrated artistic separation, not an ICC process proof.' + : adj.mode === 'mono' + ? ' Mono screens ink over the source colours.' + : ''} +

+
+
+
+ Angle + {adj.angle}° +
+ +
+
+
+ Intensity + {Math.round(adj.intensity * 100)}% +
+ + onChange({ intensity: value / 100 } as unknown as Partial) + } + /> +
+ {adj.mode === 'mono' && ( + <> +
+ Ink Color +
+ + onChange({ inkColor: managedToColor(c) } as unknown as Partial) + } + onInteractionStart={onEditStart} + onInteractionEnd={onEditEnd} + /> + + )} +
+ ); +} diff --git a/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/halftone/HalftoneAdvancedPhase.tsx b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/halftone/HalftoneAdvancedPhase.tsx new file mode 100644 index 0000000000..d55367a879 --- /dev/null +++ b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/halftone/HalftoneAdvancedPhase.tsx @@ -0,0 +1,175 @@ +import type { Adjustment } from '@varve/scene'; +import { Select } from '@varve/ui'; +import { DisclosureSection } from '../../../Inspector/controls/DisclosureSection'; +import { RangeValueControl } from '../../../Inspector/controls/RangeValueControl'; +import type { HalftoneEditorModel } from './useHalftoneModel'; + +export function HalftoneAdvancedPhase({ model }: { model: HalftoneEditorModel }) { + const { + onChange, + adj, + handleSelect, + isCmyk, + channelAngles, + registrationOffset, + setChannelAngle, + setRegistrationOffset, + isMonoChannel, + } = model; + + return ( + <> + {(isMonoChannel || isCmyk) && ( + + {isCmyk && ( + <> +
+ Black + +
+ {(['c', 'm', 'y', 'k'] as const).map((ink) => ( +
+ {ink.toUpperCase()} angle / offset +
+ { + const value = Number(event.target.value); + if (event.target.value === '') { + const next = { ...channelAngles }; + delete next[ink]; + onChange({ channelAngles: next } as unknown as Partial); + } else { + setChannelAngle(ink)(value); + } + }} + /> + + setRegistrationOffset(ink, 0)(Number(event.target.value)) + } + /> + + setRegistrationOffset(ink, 1)(Number(event.target.value)) + } + /> +
+
+ ))} +

+ CMYK is an uncalibrated process-screen preview, not an ICC separation. Per-channel + angles override the standard press angles (C 15°, M 75°, Y 0°, K 45°); offsets are + in document pixels. +

+ + )} + {isMonoChannel && ( + <> +
+
+ Dot gain + {Math.round((adj.dotGain ?? 0) * 100)}% +
+ + onChange({ dotGain: value / 100 } as unknown as Partial) + } + /> +
+

+ Dot gain expands midtone coverage as printed ink spreads, without changing the paper + or solid endpoints. +

+ + )} +
+ )} + + ); +} diff --git a/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/halftone/HalftoneEditor.tsx b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/halftone/HalftoneEditor.tsx new file mode 100644 index 0000000000..bf5393eb3b --- /dev/null +++ b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/halftone/HalftoneEditor.tsx @@ -0,0 +1,258 @@ +import { HALFTONE_PRESETS } from '@varve/engine'; +import { type Adjustment, type ManagedColor, rgbFromTuple } from '@varve/scene'; +import { managedColorToRgba } from '@varve/shared'; +import { Select } from '@varve/ui'; +import { ColorPicker } from '@varve/ui/components/ColorPicker'; +import { RangeValueControl } from '../../../Inspector/controls/RangeValueControl'; +import { BooleanRow } from '../controls'; +import type { AdjustmentEditorProps } from '../types'; +import { HalftoneAdvancedPhase } from './HalftoneAdvancedPhase'; +import { HALFTONE_SHAPE_OPTIONS } from './options'; +import { useHalftoneModel } from './useHalftoneModel'; + +export function HalftoneEditor(props: AdjustmentEditorProps) { + const model = useHalftoneModel(props); + const { + onChange, + adj, + handleSelect, + handleValue, + method, + isCmyk, + isLegacy, + periodPx, + currentPresetId, + handlePresetSelect, + handleShapeChange, + fgColor, + bgColor, + isMonoChannel, + } = model; + + return ( +
+ {isLegacy && ( +
+ Legacy screen + +
+ )} + {isLegacy && ( +

+ This effect was created before the corrected screen contract. Updating keeps its settings + but renders the requested ruling and dot shape accurately. +

+ )} +
+ Preset + +
+ {method === 'fm' && ( +
+ Dither + +
+ )} +
+ Channel + +
+ )} + +
+ ); +} diff --git a/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/halftone/options.ts b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/halftone/options.ts new file mode 100644 index 0000000000..31629e9f88 --- /dev/null +++ b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/halftone/options.ts @@ -0,0 +1,12 @@ +export const HALFTONE_SHAPE_OPTIONS = [ + { value: 'round', label: 'Round' }, + { value: 'elliptical', label: 'Elliptical' }, + { value: 'square', label: 'Square' }, + { value: 'diamond', label: 'Diamond' }, + { value: 'line', label: 'Line' }, + { value: 'cross', label: 'Cross' }, + { value: 'circle', label: 'Ring' }, +]; +export function patternForShape(shape: string): string { + return shape === 'line' || shape === 'cross' || shape === 'circle' ? shape : 'dot'; +} diff --git a/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/halftone/useHalftoneModel.ts b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/halftone/useHalftoneModel.ts new file mode 100644 index 0000000000..e785e797e1 --- /dev/null +++ b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/halftone/useHalftoneModel.ts @@ -0,0 +1,100 @@ +import { DOC_PIXELS_PER_INCH, HALFTONE_PRESETS } from '@varve/engine'; +import type { Adjustment } from '@varve/scene'; +import { useMemo } from 'react'; +import type { AdjustmentEditorProps } from '../types'; +import { patternForShape } from './options'; + +export function useHalftoneModel({ adjustment, onChange }: AdjustmentEditorProps) { + const adj = adjustment as import('@varve/scene').HalftoneAdjustment; + const handleSelect = (key: string) => (value: string) => { + onChange({ [key]: value } as unknown as Partial); + }; + const handleValue = (key: string) => (value: number) => { + onChange({ [key]: value } as unknown as Partial); + }; + + const method = adj.method ?? 'am'; + const channel = adj.channel; + const isCmyk = channel === 'cmyk'; + const isLegacy = adj.algorithmVersion === 1; + const periodPx = DOC_PIXELS_PER_INCH / Math.max(1, adj.frequency); + const channelAngles = adj.channelAngles ?? {}; + const registrationOffset = adj.registrationOffset ?? {}; + + const currentPresetId = useMemo(() => { + const match = HALFTONE_PRESETS.find((p) => { + const preset = p.params; + return ( + preset.pattern === adj.pattern && + preset.frequency === adj.frequency && + preset.angle === adj.angle && + preset.dotShape === adj.dotShape && + preset.channel === adj.channel && + preset.method === adj.method && + (preset.fmAlgorithm ?? 'blue-noise') === (adj.fmAlgorithm ?? 'blue-noise') && + (preset.blackGeneration ?? 'none') === (adj.blackGeneration ?? 'none') + ); + }); + return match?.id ?? ''; + }, [adj]); + + const handlePresetSelect = (value: string) => { + const preset = HALFTONE_PRESETS.find((p) => p.id === value); + if (preset) { + // Presets are authored against the corrected screen contract. + const { pattern, ...rest } = preset.params; + onChange({ pattern, algorithmVersion: 2, ...rest } as unknown as Partial); + } + }; + + const handleShapeChange = (shape: string) => { + onChange({ + dotShape: shape, + pattern: patternForShape(shape), + } as unknown as Partial); + }; + + const setChannelAngle = (key: 'c' | 'm' | 'y' | 'k') => (value: number) => { + const next = { ...channelAngles }; + if (Number.isFinite(value)) next[key] = value; + else delete next[key]; + onChange({ channelAngles: next } as unknown as Partial); + }; + const setRegistrationOffset = (key: 'c' | 'm' | 'y' | 'k', axis: 0 | 1) => (value: number) => { + const current = registrationOffset[key] ?? [0, 0]; + const next = { + ...registrationOffset, + [key]: axis === 0 ? [value, current[1]] : [current[0], value], + }; + onChange({ registrationOffset: next } as unknown as Partial); + }; + + const fgColor = adj.foregroundColor ?? [0, 0, 0]; + const bgColor = adj.backgroundColor ?? [255, 255, 255]; + const isMonoChannel = !isCmyk; + + return { + adjustment, + onChange, + adj, + handleSelect, + handleValue, + method, + channel, + isCmyk, + isLegacy, + periodPx, + channelAngles, + registrationOffset, + currentPresetId, + handlePresetSelect, + handleShapeChange, + setChannelAngle, + setRegistrationOffset, + fgColor, + bgColor, + isMonoChannel, + }; +} + +export type HalftoneEditorModel = ReturnType; diff --git a/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/legacy/renderChannelCases.tsx b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/legacy/renderChannelCases.tsx new file mode 100644 index 0000000000..35e0cd84d0 --- /dev/null +++ b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/legacy/renderChannelCases.tsx @@ -0,0 +1,322 @@ +import { + isLutInputSpaceImplemented, + LUT_INPUT_SPACE_LABELS, + parseLutFile, + serializeLutForDocument, +} from '@varve/engine'; +import type { Adjustment } from '@varve/scene'; +import { FilePickerButton, Select } from '@varve/ui'; +import { useCallback, useState } from 'react'; +import { GradientMapAdjustmentSection } from '../../../Inspector/controls/GradientMapAdjustmentSection'; +import { RangeValueControl } from '../../../Inspector/controls/RangeValueControl'; +import { DitherEditor } from '../../LiveEffectEditors'; +import { SourceChannels } from '../../SourceChannels'; +import { ThresholdAdjustmentEditor } from '../../ThresholdAdjustmentEditor'; +import { BlackAndWhiteEditor } from '../blackAndWhite'; +import { ChannelMixerEditor } from '../channelMixer'; +import { BooleanRow } from '../controls'; +import { DuotoneEditor } from '../duotone'; +import { ColorHalftoneEditor } from '../halftone/ColorHalftoneEditor'; +import { HalftoneEditor } from '../halftone/HalftoneEditor'; +import { PhotoFilterEditor } from '../photoFilter'; +import { PosterizeEditor } from '../posterize'; +import { ShadowHighlightEditor } from '../shadowHighlight'; +import { TritoneEditor } from '../tritone'; +import type { AdjustmentEditorProps } from '../types'; +import type { LegacyEditorContext } from './useLegacyEditorContext'; + +export function renderChannelCases(context: LegacyEditorContext) { + const { + adjustment, + onChange, + onEditStart, + onEditEnd, + doc, + sourceHistogram, + histogramSourceLabel, + sourceImageData, + sourceCoordSpace, + } = context; + + function LutEditor({ adjustment, onChange }: AdjustmentEditorProps) { + const adj = adjustment as import('@varve/engine').LutAdjustment; + const declaredInputSpace = adj.inputSpace ?? 'sRGB'; + const [status, setStatus] = useState(null); + const [lutMeta, setLutMeta] = useState<{ name: string; format: string; size: number } | null>( + null, + ); + + const handleFile = useCallback( + (file: File | undefined) => { + if (!file) return; + void file + .text() + .then((text) => { + try { + const ext = file.name.split('.').pop()?.toLowerCase() ?? ''; + if (ext === 'cube' || ext === '3dl') { + const result = parseLutFile(file.name, text); + const json = serializeLutForDocument(result.transform); + onChange({ + lutJson: json, + originalFilename: file.name, + inputSpace: 'sRGB', + interpolation: 'tetrahedral', + intensity: 1, + linearize: false, + } as unknown as Partial); + const kind = result.transform.kind; + const size = + kind === 'shaper3d' ? result.transform.lut3d.size : result.transform.size; + setLutMeta({ + name: result.title ?? file.name, + format: result.format, + size, + }); + const warning = result.warnings?.[0] ? `; ${result.warnings[0]}` : ''; + setStatus( + `Imported ${result.format.toUpperCase()} (${kind === '1d' ? '1D' : '3D'} ${size}^${kind === '3d' ? '3' : '1'}${warning})`, + ); + } else { + setStatus(`Unsupported format: .${ext}`); + } + } catch (err) { + setStatus(`Parse error: ${err instanceof Error ? err.message : String(err)}`); + } + }) + .catch(() => setStatus('Failed to read file')); + }, + [onChange], + ); + + return ( +
+ handleFile(file)} + onReject={(rejections) => setStatus(rejections[0]?.reason ?? 'LUT file rejected.')} + /> + + {status && ( +
+ {status} +
+ )} + + {lutMeta && ( +
+ {lutMeta.name} + + {lutMeta.format.toUpperCase()} | {lutMeta.size}^ + {lutMeta.format === '3dl' || + (adj.lutJson && + (() => { + try { + return JSON.parse(adj.lutJson)?.kind === '3d'; + } catch { + return false; + } + })()) + ? '3' + : '1'} + +
+ )} + +
+
+ Intensity + {Math.round((adj.intensity ?? 1) * 100)}% +
+ + onChange({ + intensity: value / 100, + } as unknown as Partial) + } + /> +
+ +
+ Interpolation + { + const implemented = isLutInputSpaceImplemented( + k as import('@varve/engine').LutInputSpace, + ); + return { + value: k, + label: implemented ? v : `${v} (metadata only)`, + disabled: !implemented, + disabledReason: implemented + ? undefined + : 'No verified colour-space conversion is implemented for this label.', + }; + })} + onChange={(v) => onChange({ inputSpace: v } as unknown as Partial)} + /> +
+ + {!isLutInputSpaceImplemented(declaredInputSpace) && ( +
+ This saved LUT declares {LUT_INPUT_SPACE_LABELS[declaredInputSpace]}, but Varve does not + currently convert that colour space. The LUT is evaluated against sRGB values; choose + sRGB to make that assumption explicit. +
+ )} + + onChange({ linearize: value } as unknown as Partial)} + ariaLabel="Linearize before applying" + /> +
+ ); + } + + switch (adjustment.kind) { + case 'channelMixer': + return ( + <> + + + + ); + + case 'photoFilter': + return ( + + ); + + case 'shadowHighlight': + return ; + + case 'halftone': + return ; + + case 'gradientMap': { + const adj = adjustment as import('@varve/scene').GradientMapAdjustment; + return ( + onChange(patch as unknown as Partial)} + onEditStart={onEditStart} + onEditEnd={onEditEnd} + sourceHistogram={sourceHistogram} + /> + ); + } + + case 'tritone': + return ( + + ); + + case 'colorHalftone': + return ( + + ); + + case 'duotone': + return ( + + ); + + case 'blackAndWhite': + return ( + + ); + + case 'posterize': + return ; + + case 'threshold': + return ( + + ); + + case 'lut': + return ( + + ); + + case 'dither': + return ( + + ); + } + return undefined; +} diff --git a/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/legacy/renderEffectCases.tsx b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/legacy/renderEffectCases.tsx new file mode 100644 index 0000000000..6dc2e5ab54 --- /dev/null +++ b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/legacy/renderEffectCases.tsx @@ -0,0 +1,125 @@ +import { + BloomEditor, + CausticsEditor, + CrtEditor, + LensFlareEditor, + LightLeakEditor, + LightShaftsEditor, + PaletteSnapEditor, + RgbSplitEditor, + VhsEditor, +} from '../../LiveEffectEditors'; +import { SpatialEffectEditor } from '../../SpatialEffectEditors'; +import type { LegacyEditorContext } from './useLegacyEditorContext'; + +export function renderEffectCases(context: LegacyEditorContext) { + const { adjustment, onChange, doc, sourceImageData, sourceCoordSpace } = context; + + switch (adjustment.kind) { + case 'paletteSnap': + return ( + + ); + + case 'motionBlur': + case 'mosaic': + case 'surfaceSmooth': + case 'edgeInk': + return ; + + case 'bloom': + return ( + + ); + + case 'rgbSplit': + return ( + + ); + + case 'crt': + return ( + + ); + + case 'vhs': + return ( + + ); + + case 'lightShafts': + return ( + + ); + + case 'lensFlare': + return ( + + ); + + case 'lightLeak': + return ( + + ); + + case 'caustics': + return ( + + ); + } + return undefined; +} diff --git a/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/legacy/renderLuminanceCases.tsx b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/legacy/renderLuminanceCases.tsx new file mode 100644 index 0000000000..d18da7da5c --- /dev/null +++ b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/legacy/renderLuminanceCases.tsx @@ -0,0 +1,193 @@ +import { RangeValueControl } from '../../../Inspector/controls/RangeValueControl'; +import { ColorBalanceAdjustmentEditor } from '../../ColorBalanceAdjustmentEditor'; +import { SplitToneEditor, WhiteBalanceEditor } from '../../TonalColorEditors'; +import { CurvesEditor } from '../curves'; +import { LevelsEditor } from '../levels'; +import { SelectiveColorEditor } from '../selectiveColor'; +import type { LegacyEditorContext } from './useLegacyEditorContext'; + +export function renderLuminanceCases(context: LegacyEditorContext) { + const { + adjustment, + onChange, + onEditStart, + onEditEnd, + sourceHistogram, + histogramSourceLabel, + histogramLoading, + sourceImageData, + handleValue, + handleNumber, + } = context; + + switch (adjustment.kind) { + case 'whiteBalance': + return ( + + ); + case 'splitTone': + return ; + case 'brightness': + return ( +
+
+ Brightness + {adjustment.value} +
+ +
+ ); + + case 'contrast': + return ( +
+
+ Contrast + {adjustment.value} +
+ +
+ ); + + case 'levels': + return ( + + ); + + case 'curves': + return ( + + ); + + case 'selectiveColor': + return ( + + ); + + case 'colorBalance': + return ( + + ); + + case 'exposure': + return ( +
+
+ EV + {adjustment.value} +
+ +
+ Offset + +
+
+ Gamma + +
+
+ ); + + case 'temperature': + return ( +
+
+ Temperature + {adjustment.value} +
+ +
+ ); + + case 'saturation': + return ( +
+
+ Saturation + {adjustment.value} +
+ +
+ ); + } + return undefined; +} diff --git a/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/legacy/renderTonalCases.tsx b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/legacy/renderTonalCases.tsx new file mode 100644 index 0000000000..03196b7ed3 --- /dev/null +++ b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/legacy/renderTonalCases.tsx @@ -0,0 +1,233 @@ +import type { Adjustment } from '@varve/scene'; +import { Select } from '@varve/ui'; +import { RangeValueControl } from '../../../Inspector/controls/RangeValueControl'; +import { SharpenEditor } from '../../SharpenEditor'; +import type { LegacyEditorContext } from './useLegacyEditorContext'; + +export function renderTonalCases(context: LegacyEditorContext) { + const { + adjustment, + onChange, + doc, + detailScope, + handleValue, + hueSaturationRange, + setHueSaturationRange, + } = context; + + switch (adjustment.kind) { + case 'hueSaturation': { + const ranges = adjustment.ranges as Record< + string, + { hue: number; saturation: number; lightness: number } + >; + const activeRange = hueSaturationRange; + const active = ranges[activeRange] ?? + ranges.master ?? { hue: 0, saturation: 0, lightness: 0 }; + const updateRange = (key: 'hue' | 'saturation' | 'lightness', value: number) => + onChange({ + ranges: { + ...ranges, + [activeRange]: { ...active, [key]: value }, + }, + } as Partial); + return ( +
+ +
+ onChange(paramsToLevelsAdjustmentPatch(params))} + channel={histogramChannel} + onChannelChange={(channel) => + handleSelect('channel')(channel === 'luminance' ? 'rgb' : channel) + } + onDragStart={onEditStart} + onDragEnd={onEditEnd} + /> + + + ); +} diff --git a/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/managedColor.ts b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/managedColor.ts new file mode 100644 index 0000000000..856817ac0d --- /dev/null +++ b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/managedColor.ts @@ -0,0 +1,23 @@ +import type { Color } from '@varve/engine'; +import { type ManagedColor, rgbFromTuple } from '@varve/scene'; +import { denormalizeChannel, managedColorToRgba, normalizeChannel } from '@varve/shared'; + +export function colorToManaged(c: Color): ManagedColor { + return rgbFromTuple(c); +} +export function managedToColor(c: ManagedColor): Color { + // Engine adjustment colors are 0-255 tuples: normalize at the color's own + // bit depth first, so a uint16/float color cannot corrupt the parameter + // scale (a raw 32768 channel would be misread as byte 32768). + if (c.space === 'rgb') { + const bd = c.bitDepth ?? 'uint8'; + return [ + denormalizeChannel(normalizeChannel(c.r, bd), 'uint8'), + denormalizeChannel(normalizeChannel(c.g, bd), 'uint8'), + denormalizeChannel(normalizeChannel(c.b, bd), 'uint8'), + denormalizeChannel(normalizeChannel(c.a, bd), 'uint8'), + ] as Color; + } + const [r, g, b, a] = managedColorToRgba(c as Parameters[0]); + return [r, g, b, a] as Color; +} diff --git a/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/photoFilter.tsx b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/photoFilter.tsx new file mode 100644 index 0000000000..e5ab48c0dd --- /dev/null +++ b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/photoFilter.tsx @@ -0,0 +1,52 @@ +import type { Adjustment } from '@varve/scene'; +import { ColorPicker } from '@varve/ui/components/ColorPicker'; +import { RangeValueControl } from '../../Inspector/controls/RangeValueControl'; +import { BooleanRow } from './controls'; +import { colorToManaged, managedToColor } from './managedColor'; +import type { AdjustmentEditorProps } from './types'; + +export function PhotoFilterEditor({ + adjustment, + onChange, + onEditStart, + onEditEnd, +}: AdjustmentEditorProps) { + const adj = adjustment as import('@varve/scene').PhotoFilterAdjustment; + const handleValue = (key: string) => (value: number) => { + onChange({ [key]: value } as unknown as Partial); + }; + + return ( +
+
+ Density + +
+
+ Filter Color +
+ + onChange({ color: managedToColor(color) } as unknown as Partial) + } + onInteractionStart={onEditStart} + onInteractionEnd={onEditEnd} + /> + + onChange({ preserveLuminosity: value } as unknown as Partial) + } + /> +
+ ); +} diff --git a/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/posterize.tsx b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/posterize.tsx new file mode 100644 index 0000000000..e3807fe245 --- /dev/null +++ b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/posterize.tsx @@ -0,0 +1,22 @@ +import type { Adjustment } from '@varve/scene'; +import { RangeValueControl } from '../../Inspector/controls/RangeValueControl'; +import type { AdjustmentEditorProps } from './types'; + +export function PosterizeEditor({ adjustment, onChange }: AdjustmentEditorProps) { + const adj = adjustment as import('@varve/scene').PosterizeAdjustment; + return ( +
+
+ Levels + {adj.levels} +
+ onChange({ levels: value } as unknown as Partial)} + /> +
+ ); +} diff --git a/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/selectiveColor.tsx b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/selectiveColor.tsx new file mode 100644 index 0000000000..222f6ce525 --- /dev/null +++ b/packages/editor/src/components/AdjustmentLayer/adjustmentEditors/selectiveColor.tsx @@ -0,0 +1,60 @@ +import type { Adjustment } from '@varve/scene'; +import { Select } from '@varve/ui'; +import { RangeValueControl } from '../../Inspector/controls/RangeValueControl'; +import { BooleanRow } from './controls'; +import type { AdjustmentEditorProps } from './types'; + +export function SelectiveColorEditor({ adjustment, onChange }: AdjustmentEditorProps) { + const adj = adjustment as import('@varve/scene').SelectiveColorAdjustment; + const handleValue = (key: string) => (value: number) => { + onChange({ [key]: value } as unknown as Partial); + }; + const handleSelect = (key: string) => (value: string) => { + onChange({ [key]: value } as unknown as Partial); + }; + + return ( +
+
+ Color Range + ({ value: p.id, label: p.name }))} + onChange={handlePresetSelect} + /> +
+
+ Shadow Color +
+ +
+ Midtone Color +
+ +
+ Highlight Color +
+ +
+
+ Shadow Point + {Math.round(adj.shadowPoint * 100)}% +
+ + onChange({ + shadowPoint: value / 100, + } as unknown as Partial) + } + /> +
+
+
+ Highlight Point + {Math.round(adj.highlightPoint * 100)}% +
+ + onChange({ + highlightPoint: value / 100, + } as unknown as Partial) + } + /> +
+
+
+ Intensity + {Math.round(adj.intensity * 100)}% +
+ + onChange({ intensity: value / 100 } as unknown as Partial) + } + /> +
+ + onChange({ preserveLuminosity: value } as unknown as Partial) + } + /> +
+ Interpolation +